Swekey information
[phpmyadmin/crack.git] / libraries / url_generating.lib.php
blobf93e74c70b527df0ec1158fd4de343e422aeccc2
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * URL/hidden inputs generating.
6 * @version $Id$
7 */
9 /**
10 * Generates text with hidden inputs.
12 * @see PMA_generate_common_url()
13 * @uses PMA_getHiddenFields
14 * @param string optional database name
15 * (can also be an array of parameters)
16 * @param string optional table name
17 * @param int indenting level
18 * @param string do not generate a hidden field for this parameter
19 * (can be an array of strings)
21 * @return string string with input fields
23 * @global string the current language
24 * @global string the current conversion charset
25 * @global string the current connection collation
26 * @global string the current server
27 * @global array the configuration array
28 * @global boolean whether recoding is allowed or not
30 * @access public
32 * @author nijel
34 function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
36 if (is_array($db)) {
37 $params =& $db;
38 $_indent = empty($table) ? $indent : $table;
39 $_skip = empty($indent) ? $skip : $indent;
40 $indent =& $_indent;
41 $skip =& $_skip;
42 } else {
43 $params = array();
44 if (strlen($db)) {
45 $params['db'] = $db;
47 if (strlen($table)) {
48 $params['table'] = $table;
52 if (! empty($GLOBALS['server'])
53 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
54 $params['server'] = $GLOBALS['server'];
56 if (empty($_COOKIE['pma_lang'])
57 && ! empty($GLOBALS['lang'])) {
58 $params['lang'] = $GLOBALS['lang'];
60 if (empty($_COOKIE['pma_charset'])
61 && ! empty($GLOBALS['convcharset'])) {
62 $params['convcharset'] = $GLOBALS['convcharset'];
64 if (empty($_COOKIE['pma_collation_connection'])
65 && ! empty($GLOBALS['collation_connection'])) {
66 $params['collation_connection'] = $GLOBALS['collation_connection'];
69 $params['token'] = $_SESSION[' PMA_token '];
71 if (! is_array($skip)) {
72 if (isset($params[$skip])) {
73 unset($params[$skip]);
75 } else {
76 foreach ($skip as $skipping) {
77 if (isset($params[$skipping])) {
78 unset($params[$skipping]);
83 return PMA_getHiddenFields($params);
86 /**
87 * create hidden form fields from array with name => value
89 * <code>
90 * $values = array(
91 * 'aaa' => aaa,
92 * 'bbb' => array(
93 * 'bbb_0',
94 * 'bbb_1',
95 * ),
96 * 'ccc' => array(
97 * 'a' => 'ccc_a',
98 * 'b' => 'ccc_b',
99 * ),
100 * );
101 * echo PMA_getHiddenFields($values);
103 * // produces:
104 * <input type="hidden" name="aaa" Value="aaa" />
105 * <input type="hidden" name="bbb[0]" Value="bbb_0" />
106 * <input type="hidden" name="bbb[1]" Value="bbb_1" />
107 * <input type="hidden" name="ccc[a]" Value="ccc_a" />
108 * <input type="hidden" name="ccc[b]" Value="ccc_b" />
109 * </code>
111 * @param array $values
112 * @param string $pre
113 * @return string form fields of type hidden
115 function PMA_getHiddenFields($values, $pre = '')
117 $fields = '';
119 foreach ($values as $name => $value) {
120 if (! empty($pre)) {
121 $name = $pre. '[' . $name . ']';
124 if (is_array($value)) {
125 $fields .= PMA_getHiddenFields($value, $name);
126 } else {
127 // do not generate an ending "\n" because
128 // PMA_generate_common_hidden_inputs() is sometimes called
129 // from a JS document.write()
130 $fields .= '<input type="hidden" name="' . htmlspecialchars($name)
131 . '" value="' . htmlspecialchars($value) . '" />';
135 return $fields;
139 * Generates text with URL parameters.
141 * <code>
142 * // OLD derepecated style
143 * // note the ?
144 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
145 * // produces with cookies enabled:
146 * // script.php?db=mysql&amp;table=rights
147 * // with cookies disabled:
148 * // script.php?server=1&amp;lang=en-utf-8&amp;db=mysql&amp;table=rights
150 * // NEW style
151 * $params['myparam'] = 'myvalue';
152 * $params['db'] = 'mysql';
153 * $params['table'] = 'rights';
154 * // note the missing ?
155 * echo 'script.php' . PMA_generate_common_url($params);
156 * // produces with cookies enabled:
157 * // script.php?myparam=myvalue&amp;db=mysql&amp;table=rights
158 * // with cookies disabled:
159 * // script.php?server=1&amp;lang=en-utf-8&amp;myparam=myvalue&amp;db=mysql&amp;table=rights
161 * // note the missing ?
162 * echo 'script.php' . PMA_generate_common_url();
163 * // produces with cookies enabled:
164 * // script.php
165 * // with cookies disabled:
166 * // script.php?server=1&amp;lang=en-utf-8
167 * </code>
169 * @uses $GLOBALS['server']
170 * @uses $GLOBALS['cfg']['ServerDefault']
171 * @uses $_COOKIE['pma_lang']
172 * @uses $GLOBALS['lang']
173 * @uses $_COOKIE['pma_charset']
174 * @uses $GLOBALS['convcharset']
175 * @uses $_COOKIE['pma_collation_connection']
176 * @uses $GLOBALS['collation_connection']
177 * @uses $_SESSION[' PMA_token ']
178 * @uses PMA_get_arg_separator()
179 * @uses is_array()
180 * @uses strlen()
181 * @uses htmlentities()
182 * @uses urlencode()
183 * @uses implode()
184 * @param mixed assoc. array with url params or optional string with database name
185 * if first param is an array there is also an ? prefixed to the url
186 * @param string optional table name only if first param is array
187 * @param string character to use instead of '&amp;' for deviding
188 * multiple URL parameters from each other
189 * @return string string with URL parameters
190 * @access public
191 * @author nijel
193 function PMA_generate_common_url()
195 $args = func_get_args();
197 if (isset($args[0]) && is_array($args[0])) {
198 // new style
199 $params = $args[0];
201 if (isset($args[1])) {
202 $encode = $args[1];
203 } else {
204 $encode = 'html';
207 if (isset($args[2])) {
208 $questionmark = $args[2];
209 } else {
210 $questionmark = '?';
212 } else {
213 // old style
215 if (PMA_isValid($args[0])) {
216 $params['db'] = $args[0];
219 if (PMA_isValid($args[1])) {
220 $params['table'] = $args[1];
223 if (isset($args[2]) && $args[2] !== '&amp;') {
224 $encode = 'text';
225 } else {
226 $encode = 'html';
229 $questionmark = '';
232 $separator = PMA_get_arg_separator();
234 if (isset($GLOBALS['server'])
235 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
236 $params['server'] = $GLOBALS['server'];
239 if (empty($_COOKIE['pma_lang'])
240 && ! empty($GLOBALS['lang'])) {
241 $params['lang'] = $GLOBALS['lang'];
243 if (empty($_COOKIE['pma_charset'])
244 && ! empty($GLOBALS['convcharset'])) {
245 $params['convcharset'] = $GLOBALS['convcharset'];
247 if (empty($_COOKIE['pma_collation_connection'])
248 && ! empty($GLOBALS['collation_connection'])) {
249 $params['collation_connection'] = $GLOBALS['collation_connection'];
252 if (isset($_SESSION[' PMA_token '])) {
253 $params['token'] = $_SESSION[' PMA_token '];
256 if (empty($params)) {
257 return '';
260 $query = $questionmark . http_build_query($params, null, $separator);
262 if ($encode === 'html') {
263 $query = htmlspecialchars($query);
266 return $query;
270 * Returns url separator
272 * extracted from arg_separator.input as set in php.ini
273 * we do not use arg_separator.output to avoid problems with &amp; and &
275 * @uses ini_get()
276 * @uses strpos()
277 * @uses strlen()
278 * @param string whether to encode separator or not, currently 'none' or 'html'
279 * @return string character used for separating url parts usally ; or &
280 * @access public
281 * @author nijel
283 function PMA_get_arg_separator($encode = 'none')
285 static $separator = null;
287 if (null === $separator) {
288 // use seperators defined by php, but prefer ';'
289 // as recommended by W3C
290 $php_arg_separator_input = ini_get('arg_separator.input');
291 if (strpos($php_arg_separator_input, ';') !== false) {
292 $separator = ';';
293 } elseif (strlen($php_arg_separator_input) > 0) {
294 $separator = $php_arg_separator_input{0};
295 } else {
296 $separator = '&';
300 switch ($encode) {
301 case 'html':
302 return htmlentities($separator);
303 break;
304 case 'text' :
305 case 'none' :
306 default :
307 return $separator;