home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / url_generating.lib.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  6.4 KB  |  223 lines

  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 10229 2007-03-30 09:12:05Z cybot_tm $
  7.  */
  8.  
  9. /**
  10.  * Generates text with hidden inputs.
  11.  *
  12.  * @see     PMA_generate_common_url()
  13.  * @param   string   optional database name
  14.  * @param   string   optional table name
  15.  * @param   int      indenting level
  16.  *
  17.  * @return  string   string with input fields
  18.  *
  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
  25.  *
  26.  * @access  public
  27.  *
  28.  * @author  nijel
  29.  */
  30. function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
  31. {
  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;
  42.         }
  43.         if (strlen($table)) {
  44.             $params['table'] = $table;
  45.         }
  46.     }
  47.  
  48.     if (! empty($GLOBALS['server'])
  49.     &&  $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
  50.         $params['server'] = $GLOBALS['server'];
  51.     }
  52.     if (empty($_COOKIE['pma_lang'])
  53.     && ! empty($GLOBALS['lang'])) {
  54.         $params['lang'] = $GLOBALS['lang'];
  55.     }
  56.     if (empty($_COOKIE['pma_charset'])
  57.     && ! empty($GLOBALS['convcharset'])) {
  58.         $params['convcharset'] = $GLOBALS['convcharset'];
  59.     }
  60.     if (empty($_COOKIE['pma_collation_connection'])
  61.     && ! empty($GLOBALS['collation_connection'])) {
  62.         $params['collation_connection'] = $GLOBALS['collation_connection'];
  63.     }
  64.  
  65.     $params['token'] = $_SESSION[' PMA_token '];
  66.  
  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.  
  79.     $spaces = str_repeat('    ', $indent);
  80.  
  81.     $return = '';
  82.     foreach ($params as $key => $val) {
  83.         $return .= $spaces . '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />' . "\n";
  84.     }
  85.  
  86.     return $return;
  87. }
  88.  
  89. /**
  90.  * Generates text with URL parameters.
  91.  *
  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&table=rights
  97.  * // with cookies disabled:
  98.  * // script.php?server=1&lang=en-utf-8&db=mysql&table=rights
  99.  *
  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&db=mysql&table=rights
  107.  * // with cookies disabled:
  108.  * // script.php?server=1&lang=en-utf-8&myparam=myvalue&db=mysql&table=rights
  109.  *
  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&lang=en-utf-8
  116.  * </code>
  117.  *
  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 '&' for deviding
  122.  *                   multiple URL parameters from each other
  123.  *
  124.  * @return  string   string with URL parameters
  125.  *
  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
  132.  *
  133.  * @access  public
  134.  *
  135.  * @author  nijel
  136.  */
  137. function PMA_generate_common_url ($db = '', $table = '', $delim = '&')
  138. {
  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;
  147.         }
  148.         if (strlen($table)) {
  149.             $params['table'] = $table;
  150.         }
  151.         $questionmark = '';
  152.     }
  153.  
  154.     // use seperators defined by php, but prefer ';'
  155.     // as recommended by W3C
  156.     $separator = PMA_get_arg_separator();
  157.  
  158.     // check wether to htmlentity the separator or not
  159.     if ($delim === '&') {
  160.         $delim = htmlentities($separator);
  161.     } else {
  162.         $delim = $separator;
  163.     }
  164.  
  165.     if (isset($GLOBALS['server'])
  166.       && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
  167.         $params['server'] = $GLOBALS['server'];
  168.     }
  169.  
  170.     if (empty($_COOKIE['pma_lang'])
  171.       && ! empty($GLOBALS['lang'])) {
  172.         $params['lang'] = $GLOBALS['lang'];
  173.     }
  174.     if (empty($_COOKIE['pma_charset'])
  175.       && ! empty($GLOBALS['convcharset'])) {
  176.         $params['convcharset'] = $GLOBALS['convcharset'];
  177.     }
  178.     if (empty($_COOKIE['pma_collation_connection'])
  179.       && ! empty($GLOBALS['collation_connection'])) {
  180.         $params['collation_connection'] = $GLOBALS['collation_connection'];
  181.     }
  182.  
  183.     $params['token'] = $_SESSION[' PMA_token '];
  184.  
  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);
  190.         }
  191.     }
  192.  
  193.     if (empty($param_strings)) {
  194.         return '';
  195.     }
  196.  
  197.     return $questionmark . implode($delim, $param_strings);
  198. }
  199.  
  200. /**
  201.  * Returns url separator
  202.  *
  203.  * @return  string   character used for separating url parts
  204.  *
  205.  * @access  public
  206.  *
  207.  * @author  nijel
  208.  */
  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 '&';
  219.     }
  220. }
  221.  
  222. ?>
  223.