Let's again obey TextareaRows (bug #1465906).
[phpmyadmin/crack.git] / libraries / url_generating.lib.php
blob118be3cde4dd4049d5f708d980cebc90227404e8
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * URL/hidden inputs generating.
8 */
11 /**
12 * Generates text with hidden inputs.
14 * @see PMA_generate_common_url()
15 * @param string optional database name
16 * @param string optional table name
17 * @param int indenting level
19 * @return string string with input fields
21 * @global string the current language
22 * @global string the current conversion charset
23 * @global string the current connection collation
24 * @global string the current server
25 * @global array the configuration array
26 * @global boolean whether recoding is allowed or not
28 * @access public
30 * @author nijel
32 function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
34 if (is_array($db)) {
35 $params =& $db;
36 $_indent = empty($table) ? $indent : $table;
37 $_skip = empty($indent) ? $skip : $indent;
38 $indent =& $_indent;
39 $skip =& $_skip;
40 } else {
41 $params = array();
42 if (isset($db) && strlen($db)) {
43 $params['db'] = $db;
45 if (isset($table) && strlen($table)) {
46 $params['table'] = $table;
50 if (! empty($GLOBALS['server'])
51 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
52 $params['server'] = $GLOBALS['server'];
54 if (empty($_COOKIE['pma_lang'])
55 && ! empty($GLOBALS['lang'])) {
56 $params['lang'] = $GLOBALS['lang'];
58 if (empty($_COOKIE['pma_charset'])
59 && ! empty($GLOBALS['convcharset'])) {
60 $params['convcharset'] = $GLOBALS['convcharset'];
62 if (empty($_COOKIE['pma_collation_connection'])
63 && ! empty($GLOBALS['collation_connection'])) {
64 $params['collation_connection'] = $GLOBALS['collation_connection'];
67 $params['token'] = $_SESSION[' PMA_token '];
69 if (! is_array($skip)) {
70 if (isset($params[$skip])) {
71 unset($params[$skip]);
73 } else {
74 foreach ($skip as $skipping) {
75 if (isset($params[$skipping])) {
76 unset($params[$skipping]);
81 $spaces = str_repeat(' ', $indent);
83 $return = '';
84 foreach ($params as $key => $val) {
85 $return .= $spaces . '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />' . "\n";
88 return $return;
91 /**
92 * Generates text with URL parameters.
94 * <code>
95 * // note the ?
96 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
97 * // produces with cookies enabled:
98 * // script.php?db=mysql&amp;table=rights
99 * // with cookies disabled:
100 * // script.php?server=1&amp;lang=en-utf-8&amp;db=mysql&amp;table=rights
102 * $params['myparam'] = 'myvalue';
103 * $params['db'] = 'mysql';
104 * $params['table'] = 'rights';
105 * // note the missing ?
106 * echo 'script.php' . PMA_generate_common_url($params);
107 * // produces with cookies enabled:
108 * // script.php?myparam=myvalue&amp;db=mysql&amp;table=rights
109 * // with cookies disabled:
110 * // script.php?server=1&amp;lang=en-utf-8&amp;myparam=myvalue&amp;db=mysql&amp;table=rights
112 * // note the missing ?
113 * echo 'script.php' . PMA_generate_common_url();
114 * // produces with cookies enabled:
115 * // script.php
116 * // with cookies disabled:
117 * // script.php?server=1&amp;lang=en-utf-8
118 * </code>
120 * @param mixed assoc. array with url params or optional string with database name
121 * if first param is an array there is also an ? prefixed to the url
122 * @param string optional table name only if first param is array
123 * @param string character to use instead of '&amp;' for deviding
124 * multiple URL parameters from each other
126 * @return string string with URL parameters
128 * @global string the current language
129 * @global string the current conversion charset
130 * @global string the current connection collation
131 * @global string the current server
132 * @global array the configuration array
133 * @global boolean whether recoding is allowed or not
135 * @access public
137 * @author nijel
139 function PMA_generate_common_url ($db = '', $table = '', $delim = '&amp;')
141 if (is_array($db)) {
142 $params =& $db;
143 $delim = empty($table) ? $delim : $table;
144 $questionmark = '?';
145 } else {
146 $params = array();
147 if (isset($db) && strlen($db)) {
148 $params['db'] = $db;
150 if (isset($table) && strlen($table)) {
151 $params['table'] = $table;
153 $questionmark = '';
156 // use seperators defined by php, but prefer ';'
157 // as recommended by W3C
158 $separator = PMA_get_arg_separator();
160 // check wether to htmlentity the separator or not
161 if ($delim === '&amp;') {
162 $delim = htmlentities($separator);
163 } else {
164 $delim = $separator;
167 if (isset($GLOBALS['server'])
168 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
169 $params['server'] = $GLOBALS['server'];
172 if (empty($_COOKIE['pma_lang'])
173 && ! empty($GLOBALS['lang'])) {
174 $params['lang'] = $GLOBALS['lang'];
176 if (empty($_COOKIE['pma_charset'])
177 && ! empty($GLOBALS['convcharset'])) {
178 $params['convcharset'] = $GLOBALS['convcharset'];
180 if (empty($_COOKIE['pma_collation_connection'])
181 && ! empty($GLOBALS['collation_connection'])) {
182 $params['collation_connection'] = $GLOBALS['collation_connection'];
185 $params['token'] = $_SESSION[' PMA_token '];
187 $param_strings = array();
188 foreach ($params as $key => $val) {
189 $param_strings[] = urlencode($key) . '=' . urlencode($val);
192 if (empty($param_strings)) {
193 return '';
196 return $questionmark . implode($delim, $param_strings);
200 * Returns url separator
202 * @return string character used for separating url parts
204 * @access public
206 * @author nijel
208 function PMA_get_arg_separator() {
209 // use seperators defined by php, but prefer ';'
210 // as recommended by W3C
211 $php_arg_separator_input = ini_get('arg_separator.input');
212 if (strpos($php_arg_separator_input, ';') !== false) {
213 return ';';
214 } elseif (strlen($php_arg_separator_input) > 0) {
215 return $php_arg_separator_input{0};
216 } else {
217 return '&';