PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/xampp/phpMyAdmin/libraries/url_generating.lib.php

https://github.com/edmondscommerce/XAMPP-Magento-Demo-Site
PHP | 321 lines | 147 code | 29 blank | 145 comment | 49 complexity | 561af5444579baa69e3498a5635e20f1 MD5 | raw file
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * URL/hidden inputs generating.
  5. *
  6. * @version $Id: url_generating.lib.php 11935 2008-11-21 17:57:32Z lem9 $
  7. */
  8. /**
  9. * Generates text with hidden inputs.
  10. *
  11. * @see PMA_generate_common_url()
  12. * @uses PMA_getHiddenFields
  13. * @param string optional database name
  14. * (can also be an array of parameters)
  15. * @param string optional table name
  16. * @param int indenting level
  17. * @param string do not generate a hidden field for this parameter
  18. * (can be an array of strings)
  19. *
  20. * @return string string with input fields
  21. *
  22. * @global string the current language
  23. * @global string the current conversion charset
  24. * @global string the current connection collation
  25. * @global string the current server
  26. * @global array the configuration array
  27. * @global boolean whether recoding is allowed or not
  28. *
  29. * @access public
  30. *
  31. * @author nijel
  32. */
  33. function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
  34. {
  35. if (is_array($db)) {
  36. $params =& $db;
  37. $_indent = empty($table) ? $indent : $table;
  38. $_skip = empty($indent) ? $skip : $indent;
  39. $indent =& $_indent;
  40. $skip =& $_skip;
  41. } else {
  42. $params = array();
  43. if (strlen($db)) {
  44. $params['db'] = $db;
  45. }
  46. if (strlen($table)) {
  47. $params['table'] = $table;
  48. }
  49. }
  50. if (! empty($GLOBALS['server'])
  51. && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
  52. $params['server'] = $GLOBALS['server'];
  53. }
  54. if (empty($_COOKIE['pma_lang'])
  55. && ! empty($GLOBALS['lang'])) {
  56. $params['lang'] = $GLOBALS['lang'];
  57. }
  58. if (empty($_COOKIE['pma_charset'])
  59. && ! empty($GLOBALS['convcharset'])) {
  60. $params['convcharset'] = $GLOBALS['convcharset'];
  61. }
  62. if (empty($_COOKIE['pma_collation_connection'])
  63. && ! empty($GLOBALS['collation_connection'])) {
  64. $params['collation_connection'] = $GLOBALS['collation_connection'];
  65. }
  66. $params['token'] = $_SESSION[' PMA_token '];
  67. if (! is_array($skip)) {
  68. if (isset($params[$skip])) {
  69. unset($params[$skip]);
  70. }
  71. } else {
  72. foreach ($skip as $skipping) {
  73. if (isset($params[$skipping])) {
  74. unset($params[$skipping]);
  75. }
  76. }
  77. }
  78. return PMA_getHiddenFields($params);
  79. }
  80. /**
  81. * create hidden form fields from array with name => value
  82. *
  83. * <code>
  84. * $values = array(
  85. * 'aaa' => aaa,
  86. * 'bbb' => array(
  87. * 'bbb_0',
  88. * 'bbb_1',
  89. * ),
  90. * 'ccc' => array(
  91. * 'a' => 'ccc_a',
  92. * 'b' => 'ccc_b',
  93. * ),
  94. * );
  95. * echo PMA_getHiddenFields($values);
  96. *
  97. * // produces:
  98. * <input type="hidden" name="aaa" Value="aaa" />
  99. * <input type="hidden" name="bbb[0]" Value="bbb_0" />
  100. * <input type="hidden" name="bbb[1]" Value="bbb_1" />
  101. * <input type="hidden" name="ccc[a]" Value="ccc_a" />
  102. * <input type="hidden" name="ccc[b]" Value="ccc_b" />
  103. * </code>
  104. *
  105. * @param array $values
  106. * @param string $pre
  107. * @return string form fields of type hidden
  108. */
  109. function PMA_getHiddenFields($values, $pre = '')
  110. {
  111. $fields = '';
  112. foreach ($values as $name => $value) {
  113. if (! empty($pre)) {
  114. $name = $pre. '[' . $name . ']';
  115. }
  116. if (is_array($value)) {
  117. $fields .= PMA_getHiddenFields($value, $name);
  118. } else {
  119. // do not generate an ending "\n" because
  120. // PMA_generate_common_hidden_inputs() is sometimes called
  121. // from a JS document.write()
  122. $fields .= '<input type="hidden" name="' . htmlspecialchars($name)
  123. . '" value="' . htmlspecialchars($value) . '" />';
  124. }
  125. }
  126. return $fields;
  127. }
  128. /**
  129. * Generates text with URL parameters.
  130. *
  131. * <code>
  132. * // OLD derepecated style
  133. * // note the ?
  134. * echo 'script.php?' . PMA_generate_common_url('mysql', 'rights');
  135. * // produces with cookies enabled:
  136. * // script.php?db=mysql&amp;table=rights
  137. * // with cookies disabled:
  138. * // script.php?server=1&amp;lang=en-utf-8&amp;db=mysql&amp;table=rights
  139. *
  140. * // NEW style
  141. * $params['myparam'] = 'myvalue';
  142. * $params['db'] = 'mysql';
  143. * $params['table'] = 'rights';
  144. * // note the missing ?
  145. * echo 'script.php' . PMA_generate_common_url($params);
  146. * // produces with cookies enabled:
  147. * // script.php?myparam=myvalue&amp;db=mysql&amp;table=rights
  148. * // with cookies disabled:
  149. * // script.php?server=1&amp;lang=en-utf-8&amp;myparam=myvalue&amp;db=mysql&amp;table=rights
  150. *
  151. * // note the missing ?
  152. * echo 'script.php' . PMA_generate_common_url();
  153. * // produces with cookies enabled:
  154. * // script.php
  155. * // with cookies disabled:
  156. * // script.php?server=1&amp;lang=en-utf-8
  157. * </code>
  158. *
  159. * @uses $GLOBALS['server']
  160. * @uses $GLOBALS['cfg']['ServerDefault']
  161. * @uses $_COOKIE['pma_lang']
  162. * @uses $GLOBALS['lang']
  163. * @uses $_COOKIE['pma_charset']
  164. * @uses $GLOBALS['convcharset']
  165. * @uses $_COOKIE['pma_collation_connection']
  166. * @uses $GLOBALS['collation_connection']
  167. * @uses $_SESSION[' PMA_token ']
  168. * @uses PMA_get_arg_separator()
  169. * @uses is_array()
  170. * @uses strlen()
  171. * @uses htmlentities()
  172. * @uses urlencode()
  173. * @uses implode()
  174. * @param mixed assoc. array with url params or optional string with database name
  175. * if first param is an array there is also an ? prefixed to the url
  176. *
  177. * @param string - if first param is array: 'html' to use htmlspecialchars()
  178. * on the resulting URL (for a normal URL displayed in HTML)
  179. * or something else to avoid using htmlspecialchars() (for
  180. * a URL sent via a header); if not set,'html' is assumed
  181. * - if first param is not array: optional table name
  182. *
  183. * @param string - if first param is array: optional character to
  184. * use instead of '?'
  185. * - if first param is not array: optional character to use
  186. * instead of '&amp;' for dividing URL parameters
  187. * @return string string with URL parameters
  188. * @access public
  189. * @author nijel
  190. */
  191. function PMA_generate_common_url()
  192. {
  193. $args = func_get_args();
  194. if (isset($args[0]) && is_array($args[0])) {
  195. // new style
  196. $params = $args[0];
  197. if (isset($args[1])) {
  198. $encode = $args[1];
  199. } else {
  200. $encode = 'html';
  201. }
  202. if (isset($args[2])) {
  203. $questionmark = $args[2];
  204. } else {
  205. $questionmark = '?';
  206. }
  207. } else {
  208. // old style
  209. if (PMA_isValid($args[0])) {
  210. $params['db'] = $args[0];
  211. }
  212. if (PMA_isValid($args[1])) {
  213. $params['table'] = $args[1];
  214. }
  215. if (isset($args[2]) && $args[2] !== '&amp;') {
  216. $encode = 'text';
  217. } else {
  218. $encode = 'html';
  219. }
  220. $questionmark = '';
  221. }
  222. $separator = PMA_get_arg_separator();
  223. if (isset($GLOBALS['server'])
  224. && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
  225. // avoid overwriting when creating navi panel links to servers
  226. && ! isset($params['server'])) {
  227. $params['server'] = $GLOBALS['server'];
  228. }
  229. if (empty($_COOKIE['pma_lang'])
  230. && ! empty($GLOBALS['lang'])) {
  231. $params['lang'] = $GLOBALS['lang'];
  232. }
  233. if (empty($_COOKIE['pma_charset'])
  234. && ! empty($GLOBALS['convcharset'])) {
  235. $params['convcharset'] = $GLOBALS['convcharset'];
  236. }
  237. if (empty($_COOKIE['pma_collation_connection'])
  238. && ! empty($GLOBALS['collation_connection'])) {
  239. $params['collation_connection'] = $GLOBALS['collation_connection'];
  240. }
  241. if (isset($_SESSION[' PMA_token '])) {
  242. $params['token'] = $_SESSION[' PMA_token '];
  243. }
  244. if (empty($params)) {
  245. return '';
  246. }
  247. $query = $questionmark . http_build_query($params, null, $separator);
  248. if ($encode === 'html') {
  249. $query = htmlspecialchars($query);
  250. }
  251. return $query;
  252. }
  253. /**
  254. * Returns url separator
  255. *
  256. * extracted from arg_separator.input as set in php.ini
  257. * we do not use arg_separator.output to avoid problems with &amp; and &
  258. *
  259. * @uses ini_get()
  260. * @uses strpos()
  261. * @uses strlen()
  262. * @param string whether to encode separator or not, currently 'none' or 'html'
  263. * @return string character used for separating url parts usally ; or &
  264. * @access public
  265. * @author nijel
  266. */
  267. function PMA_get_arg_separator($encode = 'none')
  268. {
  269. static $separator = null;
  270. if (null === $separator) {
  271. // use seperators defined by php, but prefer ';'
  272. // as recommended by W3C
  273. $php_arg_separator_input = ini_get('arg_separator.input');
  274. if (strpos($php_arg_separator_input, ';') !== false) {
  275. $separator = ';';
  276. } elseif (strlen($php_arg_separator_input) > 0) {
  277. $separator = $php_arg_separator_input{0};
  278. } else {
  279. $separator = '&';
  280. }
  281. }
  282. switch ($encode) {
  283. case 'html':
  284. return htmlentities($separator);
  285. break;
  286. case 'text' :
  287. case 'none' :
  288. default :
  289. return $separator;
  290. }
  291. }
  292. ?>