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 if (! is_array($skip)) {
67 if (isset($params[$skip])) {
68 unset($params[$skip]);
71 foreach ($skip as $skipping) {
72 if (isset($params[$skipping])) {
73 unset($params[$skipping]);
78 return URL
::getHiddenFields($params);
82 * create hidden form fields from array with name => value
96 * echo URL::getHiddenFields($values);
99 * <input type="hidden" name="aaa" Value="aaa" />
100 * <input type="hidden" name="bbb[0]" Value="bbb_0" />
101 * <input type="hidden" name="bbb[1]" Value="bbb_1" />
102 * <input type="hidden" name="ccc[a]" Value="ccc_a" />
103 * <input type="hidden" name="ccc[b]" Value="ccc_b" />
106 * @param array $values hidden values
107 * @param string $pre prefix
109 * @return string form fields of type hidden
111 public static function getHiddenFields($values, $pre = '')
115 /* Always include token in plain forms */
117 $values['token'] = $_SESSION[' PMA_token '];
120 foreach ($values as $name => $value) {
122 $name = $pre . '[' . $name . ']';
125 if (is_array($value)) {
126 $fields .= URL
::getHiddenFields($value, $name);
128 // do not generate an ending "\n" because
129 // URL::getHiddenInputs() is sometimes called
130 // from a JS document.write()
131 $fields .= '<input type="hidden" name="' . htmlspecialchars($name)
132 . '" value="' . htmlspecialchars($value) . '" />';
140 * Generates text with URL parameters.
143 * $params['myparam'] = 'myvalue';
144 * $params['db'] = 'mysql';
145 * $params['table'] = 'rights';
146 * // note the missing ?
147 * echo 'script.php' . URL::getCommon($params);
148 * // produces with cookies enabled:
149 * // script.php?myparam=myvalue&db=mysql&table=rights
150 * // with cookies disabled:
151 * // script.php?server=1&lang=en&myparam=myvalue&db=mysql
152 * // &table=rights
154 * // note the missing ?
155 * echo 'script.php' . URL::getCommon();
156 * // produces with cookies enabled:
158 * // with cookies disabled:
159 * // script.php?server=1&lang=en
162 * @param mixed $params optional, Contains an associative array with url params
163 * @param string $divider optional character to use instead of '?'
165 * @return string string with URL parameters
168 public static function getCommon($params = array(), $divider = '?')
170 return htmlspecialchars(
171 URL
::getCommonRaw($params, $divider)
176 * Generates text with URL parameters.
179 * $params['myparam'] = 'myvalue';
180 * $params['db'] = 'mysql';
181 * $params['table'] = 'rights';
182 * // note the missing ?
183 * echo 'script.php' . URL::getCommon($params);
184 * // produces with cookies enabled:
185 * // script.php?myparam=myvalue&db=mysql&table=rights
186 * // with cookies disabled:
187 * // script.php?server=1&lang=en&myparam=myvalue&db=mysql
188 * // &table=rights
190 * // note the missing ?
191 * echo 'script.php' . URL::getCommon();
192 * // produces with cookies enabled:
194 * // with cookies disabled:
195 * // script.php?server=1&lang=en
198 * @param mixed $params optional, Contains an associative array with url params
199 * @param string $divider optional character to use instead of '?'
201 * @return string string with URL parameters
204 public static function getCommonRaw($params = array(), $divider = '?')
206 $separator = URL
::getArgSeparator();
208 // avoid overwriting when creating navi panel links to servers
209 if (isset($GLOBALS['server'])
210 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
211 && ! isset($params['server'])
212 && ! defined('PMA_SETUP')
214 $params['server'] = $GLOBALS['server'];
217 if (empty($_COOKIE['pma_lang']) && ! empty($GLOBALS['lang'])) {
218 $params['lang'] = $GLOBALS['lang'];
220 if (empty($_COOKIE['pma_collation_connection'])
221 && ! empty($GLOBALS['collation_connection'])
223 $params['collation_connection'] = $GLOBALS['collation_connection'];
226 if (isset($_SESSION[' PMA_token '])) {
227 $params['token'] = $_SESSION[' PMA_token '];
230 $query = http_build_query($params, null, $separator);
232 if ($divider != '?' ||
strlen($query) > 0) {
233 return $divider . $query;
240 * Returns url separator
242 * extracted from arg_separator.input as set in php.ini
243 * we do not use arg_separator.output to avoid problems with & and &
245 * @param string $encode whether to encode separator or not,
246 * currently 'none' or 'html'
248 * @return string character used for separating url parts usually ; or &
251 public static function getArgSeparator($encode = 'none')
253 static $separator = null;
254 static $html_separator = null;
256 if (null === $separator) {
257 // use separators defined by php, but prefer ';'
258 // as recommended by W3C
259 // (see https://www.w3.org/TR/1999/REC-html401-19991224/appendix
260 // /notes.html#h-B.2.2)
261 $arg_separator = ini_get('arg_separator.input');
262 if (mb_strpos($arg_separator, ';') !== false) {
264 } elseif (strlen($arg_separator) > 0) {
265 $separator = $arg_separator{0};
269 $html_separator = htmlentities($separator);
274 return $html_separator;