2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Static methods for URL/hidden inputs generating
8 namespace PMA\libraries
;
11 * Static methods for URL/hidden inputs generating
18 * Generates text with hidden inputs.
20 * @param string|array $db optional database name
21 * (can also be an array of parameters)
22 * @param string $table optional table name
23 * @param int $indent indenting level
24 * @param string|array $skip do not generate a hidden field for this parameter
25 * (can be an array of strings)
27 * @see URL::getCommon()
29 * @return string string with input fields
33 public static function getHiddenInputs($db = '', $table = '',
34 $indent = 0, $skip = array()
38 $_indent = empty($table) ?
$indent : $table;
39 $_skip = empty($indent) ?
$skip : $indent;
44 if (strlen($db) > 0) {
47 if (strlen($table) > 0) {
48 $params['table'] = $table;
52 if (! empty($GLOBALS['server'])
53 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
55 $params['server'] = $GLOBALS['server'];
57 if (empty($_COOKIE['pma_lang']) && ! empty($GLOBALS['lang'])) {
58 $params['lang'] = $GLOBALS['lang'];
60 if (empty($_COOKIE['pma_collation_connection'])
61 && ! empty($GLOBALS['collation_connection'])
63 $params['collation_connection'] = $GLOBALS['collation_connection'];
66 $params['token'] = $_SESSION[' PMA_token '];
68 if (! is_array($skip)) {
69 if (isset($params[$skip])) {
70 unset($params[$skip]);
73 foreach ($skip as $skipping) {
74 if (isset($params[$skipping])) {
75 unset($params[$skipping]);
80 return URL
::getHiddenFields($params);
84 * create hidden form fields from array with name => value
98 * echo URL::getHiddenFields($values);
101 * <input type="hidden" name="aaa" Value="aaa" />
102 * <input type="hidden" name="bbb[0]" Value="bbb_0" />
103 * <input type="hidden" name="bbb[1]" Value="bbb_1" />
104 * <input type="hidden" name="ccc[a]" Value="ccc_a" />
105 * <input type="hidden" name="ccc[b]" Value="ccc_b" />
108 * @param array $values hidden values
109 * @param string $pre prefix
111 * @return string form fields of type hidden
113 public static function getHiddenFields($values, $pre = '')
117 foreach ($values as $name => $value) {
119 $name = $pre . '[' . $name . ']';
122 if (is_array($value)) {
123 $fields .= URL
::getHiddenFields($value, $name);
125 // do not generate an ending "\n" because
126 // URL::getHiddenInputs() is sometimes called
127 // from a JS document.write()
128 $fields .= '<input type="hidden" name="' . htmlspecialchars($name)
129 . '" value="' . htmlspecialchars($value) . '" />';
137 * Generates text with URL parameters.
140 * $params['myparam'] = 'myvalue';
141 * $params['db'] = 'mysql';
142 * $params['table'] = 'rights';
143 * // note the missing ?
144 * echo 'script.php' . URL::getCommon($params);
145 * // produces with cookies enabled:
146 * // script.php?myparam=myvalue&db=mysql&table=rights
147 * // with cookies disabled:
148 * // script.php?server=1&lang=en&myparam=myvalue&db=mysql
149 * // &table=rights
151 * // note the missing ?
152 * echo 'script.php' . URL::getCommon();
153 * // produces with cookies enabled:
155 * // with cookies disabled:
156 * // script.php?server=1&lang=en
159 * @param mixed $params optional, Contains an associative array with url params
160 * @param string $divider optional character to use instead of '?'
162 * @return string string with URL parameters
165 public static function getCommon($params = array(), $divider = '?')
167 return htmlspecialchars(
168 URL
::getCommonRaw($params, $divider)
173 * Generates text with URL parameters.
176 * $params['myparam'] = 'myvalue';
177 * $params['db'] = 'mysql';
178 * $params['table'] = 'rights';
179 * // note the missing ?
180 * echo 'script.php' . URL::getCommon($params);
181 * // produces with cookies enabled:
182 * // script.php?myparam=myvalue&db=mysql&table=rights
183 * // with cookies disabled:
184 * // script.php?server=1&lang=en&myparam=myvalue&db=mysql
185 * // &table=rights
187 * // note the missing ?
188 * echo 'script.php' . URL::getCommon();
189 * // produces with cookies enabled:
191 * // with cookies disabled:
192 * // script.php?server=1&lang=en
195 * @param mixed $params optional, Contains an associative array with url params
196 * @param string $divider optional character to use instead of '?'
198 * @return string string with URL parameters
201 public static function getCommonRaw($params = array(), $divider = '?')
203 $separator = URL
::getArgSeparator();
205 // avoid overwriting when creating navi panel links to servers
206 if (isset($GLOBALS['server'])
207 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
208 && ! isset($params['server'])
209 && ! defined('PMA_SETUP')
211 $params['server'] = $GLOBALS['server'];
214 if (empty($_COOKIE['pma_lang']) && ! empty($GLOBALS['lang'])) {
215 $params['lang'] = $GLOBALS['lang'];
217 if (empty($_COOKIE['pma_collation_connection'])
218 && ! empty($GLOBALS['collation_connection'])
220 $params['collation_connection'] = $GLOBALS['collation_connection'];
223 return $divider . http_build_query($params, null, $separator);
227 * Returns url separator
229 * extracted from arg_separator.input as set in php.ini
230 * we do not use arg_separator.output to avoid problems with & and &
232 * @param string $encode whether to encode separator or not,
233 * currently 'none' or 'html'
235 * @return string character used for separating url parts usually ; or &
238 public static function getArgSeparator($encode = 'none')
240 static $separator = null;
241 static $html_separator = null;
243 if (null === $separator) {
244 // use separators defined by php, but prefer ';'
245 // as recommended by W3C
246 // (see https://www.w3.org/TR/1999/REC-html401-19991224/appendix
247 // /notes.html#h-B.2.2)
248 $arg_separator = ini_get('arg_separator.input');
249 if (mb_strpos($arg_separator, ';') !== false) {
251 } elseif (strlen($arg_separator) > 0) {
252 $separator = $arg_separator{0};
256 $html_separator = htmlentities($separator);
261 return $html_separator;