1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8function wikiplugin_dynamicvariables_info() 9{ 10 return [ 11 'name' => tra('List of dynamic variables'), 12 'documentation' => 'PluginDynamicvariables', 13 'description' => tra('Show dynamic variables and their values.'), 14 'prefs' => [ 'wikiplugin_dynamicvariables' ], 15 'iconname' => 'code', 16 'introduced' => 15, 17 'params' => [ 18 'layout' => [ 19 'required' => false, 20 'name' => tra('Layout'), 21 'description' => tra('Set to table to show results in a table (not shown in a table by default)'), 22 'since' => '15.0', 23 'filter' => 'alpha', 24 'default' => '', 25 'options' => [ 26 ['text' => '', 'value' => ''], 27 ['text' => tra('Table'), 'value' => 'table'] 28 ] 29 ], 30 'linesep' => [ 31 'required' => false, 32 'name' => tra('Separator'), 33 'description' => tra('String to use between elements of the list if table layout is not used'), 34 'since' => '15.0', 35 'filter' => 'xss', 36 'default' => ', ', 37 ], 38/* 39 'sort' => array( 40 'required' => false, 41 'name' => tra('Sort order'), 42 'description' => tra('Set to sort in ascending or descending order (unsorted by default'), 43 'default' => '', 44 'options' => array( 45 array('text' => '', 'value' => ''), 46 array('text' => tra('Ascending'), 'value' => 'asc'), 47 array('text' => tra('Descending'), 'value' => 'desc') 48 ) 49 ), 50*/ 51 ] 52 ]; 53} 54 55function wikiplugin_dynamicvariables($data, $params) 56{ 57 global $prefs; 58 $tikilib = TikiLib::lib('tiki'); 59 60 $layout = isset($params['layout']) ? $params['layout'] : ''; 61 $linesep = isset($params['linesep']) ? $params['linesep'] : ''; 62 63 if (! isset($linesep)) { 64 $linesep = '<br>'; 65 } 66 if (! isset($max)) { 67 $numRows = -1; 68 } else { 69 $numRows = (int) $max; 70 } 71 72 $filter = ''; 73 $bindvars = []; 74 75 $pre = ''; 76 $post = ''; 77 $oparens = '('; 78 $cparens = ')'; 79 if (isset($layout) && $layout == 'table') { 80 $pre = '<table class=\'table table-striped table-hover\' id=\'' . $tikilib->now . '\'><tr>' 81 . '<th>' . tra('Parsed result') . '</th>' 82 . '<th>' . tra('Syntax') . '</th>' 83 . '<th>' . tra('Value per database') . '</th>' 84 . '</tr><tr><td>'; 85 $linesep = '</td></tr><tr><td>'; 86 $sep = '</td><td>'; 87 $post = '</td></tr></table>'; 88 $oparens = ''; 89 $cparens = ''; 90 } 91 92 $query = 'SELECT * FROM `tiki_dynamic_variables` ' . $filter ; 93 94 $result = $tikilib->query($query, $bindvars, $numRows); 95 $ret = []; 96 $tag = ''; 97 if ($prefs['wiki_dynvar_style'] == 'single') { 98 $tag = '%'; 99 } elseif ($prefs['wiki_dynvar_style'] == 'double') { 100 $tag = '%%'; 101 } 102 while ($row = $result->fetchRow()) { 103 $res = $tag . $row['name'] . $tag . $sep . ' ' . $oparens . '~np~' . $tag . $row['name'] . $tag . '~/np~' 104 . $cparens . ' ' . $sep . $row['data'] ; 105 $ret[] = $res; 106 } 107 108 return $pre . implode($linesep, $ret) . $post; 109} 110