[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libraries/ -> url_generating.lib.php (source)

   1  <?php
   2  /* $Id: url_generating.lib.php 9712 2006-11-17 09:32:19Z nijel $ */
   3  // vim: expandtab sw=4 ts=4 sts=4:
   4  
   5  
   6  /**
   7   * URL/hidden inputs generating.
   8   */
   9  
  10  
  11  /**
  12   * Generates text with hidden inputs.
  13   *
  14   * @see     PMA_generate_common_url()
  15   * @param   string   optional database name
  16   * @param   string   optional table name
  17   * @param   int      indenting level
  18   *
  19   * @return  string   string with input fields
  20   *
  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
  27   *
  28   * @access  public
  29   *
  30   * @author  nijel
  31   */
  32  function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $skip = array())
  33  {
  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;
  44          }
  45          if (isset($table) && strlen($table)) {
  46              $params['table'] = $table;
  47          }
  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  
  67      $params['token'] = $_SESSION[' PMA_token '];
  68  
  69      if (! is_array($skip)) {
  70          if (isset($params[$skip])) {
  71              unset($params[$skip]);
  72          }
  73      } else {
  74          foreach ($skip as $skipping) {
  75              if (isset($params[$skipping])) {
  76                  unset($params[$skipping]);
  77              }
  78          }
  79      }
  80  
  81      $spaces = str_repeat('    ', $indent);
  82  
  83      $return = '';
  84      foreach ($params as $key => $val) {
  85          $return .= $spaces . '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />' . "\n";
  86      }
  87  
  88      return $return;
  89  }
  90  
  91  /**
  92   * Generates text with URL parameters.
  93   *
  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
 101   *
 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
 111   *
 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>
 119   *
 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
 125   *
 126   * @return  string   string with URL parameters
 127   *
 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
 134   *
 135   * @access  public
 136   *
 137   * @author  nijel
 138   */
 139  function PMA_generate_common_url ($db = '', $table = '', $delim = '&amp;')
 140  {
 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;
 149          }
 150          if (isset($table) && strlen($table)) {
 151              $params['table'] = $table;
 152          }
 153          $questionmark = '';
 154      }
 155  
 156      // use seperators defined by php, but prefer ';'
 157      // as recommended by W3C
 158      $separator = PMA_get_arg_separator();
 159  
 160      // check wether to htmlentity the separator or not
 161      if ($delim === '&amp;') {
 162          $delim = htmlentities($separator);
 163      } else {
 164          $delim = $separator;
 165      }
 166  
 167      if (isset($GLOBALS['server'])
 168        && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']) {
 169          $params['server'] = $GLOBALS['server'];
 170      }
 171  
 172      if (empty($_COOKIE['pma_lang'])
 173        && ! empty($GLOBALS['lang'])) {
 174          $params['lang'] = $GLOBALS['lang'];
 175      }
 176      if (empty($_COOKIE['pma_charset'])
 177        && ! empty($GLOBALS['convcharset'])) {
 178          $params['convcharset'] = $GLOBALS['convcharset'];
 179      }
 180      if (empty($_COOKIE['pma_collation_connection'])
 181        && ! empty($GLOBALS['collation_connection'])) {
 182          $params['collation_connection'] = $GLOBALS['collation_connection'];
 183      }
 184  
 185      $params['token'] = $_SESSION[' PMA_token '];
 186  
 187      $param_strings = array();
 188      foreach ($params as $key => $val) {
 189          /* We ignore arrays as we don't use them! */
 190          if (!is_array($val)) {
 191              $param_strings[] = urlencode($key) . '=' . urlencode($val);
 192          }
 193      }
 194  
 195      if (empty($param_strings)) {
 196          return '';
 197      }
 198  
 199      return $questionmark . implode($delim, $param_strings);
 200  }
 201  
 202  /**
 203   * Returns url separator
 204   *
 205   * @return  string   character used for separating url parts
 206   *
 207   * @access  public
 208   *
 209   * @author  nijel
 210   */
 211  function PMA_get_arg_separator() {
 212      // use seperators defined by php, but prefer ';'
 213      // as recommended by W3C
 214      $php_arg_separator_input = ini_get('arg_separator.input');
 215      if (strpos($php_arg_separator_input, ';') !== false) {
 216          return ';';
 217      } elseif (strlen($php_arg_separator_input) > 0) {
 218          return $php_arg_separator_input{0};
 219      } else {
 220          return '&';
 221      }
 222  }
 223  
 224  ?>


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics