2.11.11.3 release
[phpmyadmin/arisferyanto.git] / libraries / url_generating.lib.php
blob2b137aa5a812cfc9a1a1216d56e3c1ba4cf2a92c
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 * @param string optional database name
14 * @param string optional table name
15 * @param int indenting level
17 * @return string string with input fields
19 * @global string the current language
20 * @global string the current conversion charset
21 * @global string the current connection collation
22 * @global string the current server
23 * @global array the configuration array
24 * @global boolean whether recoding is allowed or not
26 * @access public
28 * @author nijel
30 function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
32 if (is_array($db)) {
33 $params =& $db;
34 $_indent = empty($table) ? $indent : $table;
35 $_skip = empty($indent) ? $skip : $indent;
36 $indent =& $_indent;
37 $skip =& $_skip;
38 } else {
39 $params = array();
40 if (strlen($db)) {
41 $params['db'] = $db;
43 if (strlen($table)) {
44 $params['table'] = $table;
48 if (! empty($GLOBALS['server'])
49 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
50 $params['server'] = $GLOBALS['server'];
52 if (empty($_COOKIE['pma_lang'])
53 && ! empty($GLOBALS['lang'])) {
54 $params['lang'] = $GLOBALS['lang'];
56 if (empty($_COOKIE['pma_charset'])
57 && ! empty($GLOBALS['convcharset'])) {
58 $params['convcharset'] = $GLOBALS['convcharset'];
60 if (empty($_COOKIE['pma_collation_connection'])
61 && ! empty($GLOBALS['collation_connection'])) {
62 $params['collation_connection'] = $GLOBALS['collation_connection'];
65 $params['token'] = $_SESSION[' PMA_token '];
67 if (! is_array($skip)) {
68 if (isset($params[$skip])) {
69 unset($params[$skip]);
71 } else {
72 foreach ($skip as $skipping) {
73 if (isset($params[$skipping])) {
74 unset($params[$skipping]);
79 $spaces = str_repeat(' ', $indent);
81 $return = '';
82 foreach ($params as $key => $val) {
83 $return .= $spaces . '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />' . "\n";
86 return $return;
89 /**
90 * Generates text with URL parameters.
92 * <code>
93 * // note the ?
94 * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
95 * // produces with cookies enabled:
96 * // script.php?db=mysql&amp;table=rights
97 * // with cookies disabled:
98 * // script.php?server=1&amp;lang=en-utf-8&amp;db=mysql&amp;table=rights
100 * $params['myparam'] = 'myvalue';
101 * $params['db'] = 'mysql';
102 * $params['table'] = 'rights';
103 * // note the missing ?
104 * echo 'script.php' . PMA_generate_common_url($params);
105 * // produces with cookies enabled:
106 * // script.php?myparam=myvalue&amp;db=mysql&amp;table=rights
107 * // with cookies disabled:
108 * // script.php?server=1&amp;lang=en-utf-8&amp;myparam=myvalue&amp;db=mysql&amp;table=rights
110 * // note the missing ?
111 * echo 'script.php' . PMA_generate_common_url();
112 * // produces with cookies enabled:
113 * // script.php
114 * // with cookies disabled:
115 * // script.php?server=1&amp;lang=en-utf-8
116 * </code>
118 * @param mixed assoc. array with url params or optional string with database name
119 * if first param is an array there is also an ? prefixed to the url
120 * @param string optional table name only if first param is array
121 * @param string character to use instead of '&amp;' for deviding
122 * multiple URL parameters from each other
124 * @return string string with URL parameters
126 * @global string the current language
127 * @global string the current conversion charset
128 * @global string the current connection collation
129 * @global string the current server
130 * @global array the configuration array
131 * @global boolean whether recoding is allowed or not
133 * @access public
135 * @author nijel
137 function PMA_generate_common_url ($db = '', $table = '', $delim = '&amp;')
139 if (is_array($db)) {
140 $params =& $db;
141 $delim = empty($table) ? $delim : $table;
142 $questionmark = '?';
143 } else {
144 $params = array();
145 if (strlen($db)) {
146 $params['db'] = $db;
148 if (strlen($table)) {
149 $params['table'] = $table;
151 $questionmark = '';
154 // use seperators defined by php, but prefer ';'
155 // as recommended by W3C
156 $separator = PMA_get_arg_separator();
158 // check wether to htmlentity the separator or not
159 if ($delim === '&amp;') {
160 $delim = htmlentities($separator);
161 } else {
162 $delim = $separator;
165 if (isset($GLOBALS['server'])
166 && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
167 $params['server'] = $GLOBALS['server'];
170 if (empty($_COOKIE['pma_lang'])
171 && ! empty($GLOBALS['lang'])) {
172 $params['lang'] = $GLOBALS['lang'];
174 if (empty($_COOKIE['pma_charset'])
175 && ! empty($GLOBALS['convcharset'])) {
176 $params['convcharset'] = $GLOBALS['convcharset'];
178 if (empty($_COOKIE['pma_collation_connection'])
179 && ! empty($GLOBALS['collation_connection'])) {
180 $params['collation_connection'] = $GLOBALS['collation_connection'];
183 $params['token'] = $_SESSION[' PMA_token '];
185 $param_strings = array();
186 foreach ($params as $key => $val) {
187 /* We ignore arrays as we don't use them! */
188 if (!is_array($val)) {
189 $param_strings[] = urlencode($key) . '=' . urlencode($val);
193 if (empty($param_strings)) {
194 return '';
197 return $questionmark . implode($delim, $param_strings);
201 * Returns url separator
203 * @return string character used for separating url parts
205 * @access public
207 * @author nijel
209 function PMA_get_arg_separator() {
210 // use seperators defined by php, but prefer ';'
211 // as recommended by W3C
212 $php_arg_separator_input = ini_get('arg_separator.input');
213 if (strpos($php_arg_separator_input, ';') !== false) {
214 return ';';
215 } elseif (strlen($php_arg_separator_input) > 0) {
216 return $php_arg_separator_input{0};
217 } else {
218 return '&';