[ 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/ -> plugin_interface.lib.php (source)

   1  <?php
   2  /* $Id: plugin_interface.lib.php 9131 2006-06-25 11:42:18Z lem9 $ */
   3  // vim: expandtab sw=4 ts=4 sts=4:
   4  
   5  /**
   6   * Generic plugin interface.
   7   */
   8  
   9  /**
  10   * array PMA_getPlugins(string $plugins_dir, mixed $plugin_param)
  11   *
  12   * Reads all plugin information from directory $plugins_dir.
  13   *
  14   * @uses    ksort()
  15   * @uses    opendir()
  16   * @uses    readdir()
  17   * @uses    is_file()
  18   * @uses    eregi()
  19   * @param   string  $plugins_dir    directrory with plugins
  20   * @param   mixed   $plugin_param   parameter to plugin by which they can decide whether they can work
  21   * @return  array                   list of plugins
  22   */
  23  function PMA_getPlugins($plugins_dir, $plugin_param)
  24  {
  25      /* Scan for plugins */
  26      $plugin_list = array();
  27      if ($handle = @opendir($plugins_dir)) {
  28          $is_first = 0;
  29          while ($file = @readdir($handle)) {
  30              if (is_file($plugins_dir . $file) && eregi('\.php$', $file)) {
  31                  include $plugins_dir . $file;
  32              }
  33          }
  34      }
  35      ksort($plugin_list);
  36      return $plugin_list;
  37  }
  38  
  39  /**
  40   * string PMA_getString(string $name)
  41   *
  42   * returns locale string for $name or $name if no locale is found
  43   *
  44   * @uses    $GLOBALS
  45   * @param   string  $name   for local string
  46   * @return  string          locale string for $name
  47   */
  48  function PMA_getString($name)
  49  {
  50      return isset($GLOBALS[$name]) ? $GLOBALS[$name] : $name;
  51  }
  52  
  53  /**
  54   * string PMA_pluginCheckboxCheck(string $section, string $opt)
  55   *
  56   * returns html input tag option 'checked' if plugin $opt should be set by config or request
  57   *
  58   * @uses    $_REQUEST
  59   * @uses    $GLOBALS['cfg']
  60   * @uses    $GLOBALS['timeout_passed']
  61   * @param   string  $section    name of config section in
  62   *                              $GLOBALS['cfg'][$section] for plugin
  63   * @param   string  $opt        name of option
  64   * @return  string              hmtl input tag option 'checked'
  65   */
  66  function PMA_pluginCheckboxCheck($section, $opt)
  67  {
  68      if ((isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) ||
  69          (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt])) {
  70          return ' checked="checked"';
  71      }
  72      return '';
  73  }
  74  
  75  /**
  76   * string PMA_pluginGetDefault(string $section, string $opt)
  77   *
  78   * returns default value for option $opt
  79   *
  80   * @uses    htmlspecialchars()
  81   * @uses    $_REQUEST
  82   * @uses    $GLOBALS['cfg']
  83   * @uses    $GLOBALS['timeout_passed']
  84   * @param   string  $section    name of config section in
  85   *                              $GLOBALS['cfg'][$section] for plugin
  86   * @param   string  $opt        name of option
  87   * @return  string              default value for option $opt
  88   */
  89  function PMA_pluginGetDefault($section, $opt)
  90  {
  91      if (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) {
  92          return htmlspecialchars($_REQUEST[$opt]);
  93      } elseif (isset($GLOBALS['cfg'][$section][$opt])) {
  94          $matches = array();
  95          /* Possibly replace localised texts */
  96          if (preg_match_all('/(str[A-Z][A-Za-z0-9]*)/', $GLOBALS['cfg'][$section][$opt], $matches)) {
  97              $val = $GLOBALS['cfg'][$section][$opt];
  98              foreach($matches[0] as $match) {
  99                  if (isset($GLOBALS[$match])) {
 100                      $val = str_replace($match, $GLOBALS[$match], $val);
 101                  }
 102              }
 103              return htmlspecialchars($val);
 104          } else {
 105              return htmlspecialchars($GLOBALS['cfg'][$section][$opt]);
 106          }
 107      }
 108      return '';
 109  }
 110  
 111  /**
 112   * string PMA_pluginIsActive(string $section, string $opt, string $val)
 113   *
 114   * returns html input tag option 'checked' if option $opt should be set by config or request
 115   *
 116   * @uses    $_REQUEST
 117   * @uses    $GLOBALS['cfg']
 118   * @uses    $GLOBALS['timeout_passed']
 119   * @param   string  $section    name of config section in
 120   *                              $GLOBALS['cfg'][$section] for plugin
 121   * @param   string  $opt        name of option
 122   * @param   string  $val        value of option to check against
 123   * @return  string              html input tag option 'checked'
 124   */
 125  function PMA_pluginIsActive($section, $opt, $val)
 126  {
 127      if ( ! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt])) {
 128          if ($_REQUEST[$opt] == $val) {
 129              return ' checked="checked"';
 130          }
 131      } elseif (isset($GLOBALS['cfg'][$section][$opt]) &&  $GLOBALS['cfg'][$section][$opt] == $val) {
 132          return ' checked="checked"';
 133      }
 134      return '';
 135  }
 136  
 137  /**
 138   * string PMA_pluginGetChoice(string $section, string $name, array &$list, string $cfgname)
 139   *
 140   * returns html radio form element for plugin choice
 141   *
 142   * @uses    PMA_pluginIsActive()
 143   * @uses    PMA_getString()
 144   * @param   string  $section    name of config section in
 145   *                              $GLOBALS['cfg'][$section] for plugin
 146   * @param   string  $name       name of radio element
 147   * @param   array   &$list      array with plugin configuration defined in plugin file
 148   * @param   string  $cfgname    name of config value, if none same as $name
 149   * @return  string              html input radio tag
 150   */
 151  function PMA_pluginGetChoice($section, $name, &$list, $cfgname = NULL)
 152  {
 153      if (!isset($cfgname)) {
 154          $cfgname = $name;
 155      }
 156      $ret = '';
 157      foreach ($list as $plugin_name => $val) {
 158          $ret .= '<!-- ' . $plugin_name . ' -->' . "\n";
 159          $ret .= '<input type="radio" name="' . $name . '" value="' . $plugin_name . '"'
 160              . ' id="radio_plugin_' . $plugin_name . '"'
 161              . ' onclick="if(this.checked) { hide_them_all();';
 162          if (isset($val['force_file'])) {
 163              $ret .= 'document.getElementById(\'checkbox_dump_asfile\').checked = true;';
 164          }
 165          $ret .= ' document.getElementById(\'' . $plugin_name . '_options\').style.display = \'block\'; };'
 166                  .' return true"'
 167              . PMA_pluginIsActive($section, $cfgname, $plugin_name) . '/>' . "\n";
 168          $ret .= '<label for="radio_plugin_' . $plugin_name . '">'
 169              . PMA_getString($val['text']) . '</label>' . "\n";
 170          $ret .= '<br /><br />' . "\n";
 171      }
 172      return $ret;
 173  }
 174  
 175  /**
 176   * string PMA_pluginGetOneOption(string $section, string $plugin_name, string $id, array &$opt)
 177   *
 178   * returns single option in a table row
 179   *
 180   * @uses    PMA_getString()
 181   * @uses    PMA_pluginCheckboxCheck()
 182   * @uses    PMA_pluginGetDefault()
 183   * @param   string  $section        name of config section in
 184   *                                  $GLOBALS['cfg'][$section] for plugin
 185   * @param   string  $plugin_name    unique plugin name
 186   * @param   string  $id             option id
 187   * @param   array   &$opt           plugin option details
 188   * @return  string                  table row with option
 189   */
 190  function PMA_pluginGetOneOption($section, $plugin_name, $id, &$opt)
 191  {
 192      $ret = "\n";
 193      if ($opt['type'] == 'bool') {
 194          $ret .= '<div class="formelementrow">' . "\n";
 195          $ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $opt['name'] . '"'
 196              . ' value="something" id="checkbox_' . $plugin_name . '_' . $opt['name'] . '"'
 197              . ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $opt['name']);
 198          if (isset($opt['force'])) {
 199              /* Same code is also few lines lower, update both if needed */
 200              $ret .= ' onclick="if (!this.checked &amp;&amp; '
 201                  . '(!document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\') '
 202                  . '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\').checked)) '
 203                  . 'return false; else return true;"';
 204          }
 205          $ret .= ' />';
 206          $ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
 207              . PMA_getString($opt['text']) . '</label>';
 208          $ret .= '</div>' . "\n";
 209      } elseif ($opt['type'] == 'text') {
 210          $ret .= '<div class="formelementrow">' . "\n";
 211          $ret .= '<label for="text_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
 212              . PMA_getString($opt['text']) . '</label>';
 213          $ret .= '<input type="text" name="' . $plugin_name . '_' . $opt['name'] . '"'
 214              . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"'
 215              . ' id="text_' . $plugin_name . '_' . $opt['name'] . '"'
 216              . (isset($opt['size']) ? ' size="' . $opt['size'] . '"' : '' )
 217              . (isset($opt['len']) ? ' maxlength="' . $opt['len'] . '"' : '' ) . ' />';
 218          $ret .= '</div>' . "\n";
 219      } elseif ($opt['type'] == 'message_only') {
 220          $ret .= '<div class="formelementrow">' . "\n";
 221          $ret .= '<label for="text_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
 222              . PMA_getString($opt['text']) . '</label>';
 223          $ret .= '</div>' . "\n";
 224      } elseif ($opt['type'] == 'select') {
 225          $ret .= '<div class="formelementrow">' . "\n";
 226          $ret .= '<label for="select_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
 227              . PMA_getString($opt['text']) . '</label>';
 228          $ret .= '<select name="' . $plugin_name . '_' . $opt['name'] . '"'
 229              . ' id="select_' . $plugin_name . '_' . $opt['name'] . '">';
 230          $default = PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']);
 231          foreach($opt['values'] as $key => $val) {
 232              $ret .= '<option name="' . $key . '"';
 233              if ($key == $default) {
 234                  $ret .= ' selected="selected"';
 235              }
 236              $ret .= '>' . PMA_getString($val) . '</option>';
 237          }
 238          $ret .= '</select>';
 239          $ret .= '</div>' . "\n";
 240      } elseif ($opt['type'] == 'hidden') {
 241          $ret .= '<input type="hidden" name="' . $plugin_name . '_' . $opt['name'] . '"'
 242              . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"' . ' />';
 243      } elseif ($opt['type'] == 'bgroup') {
 244          $ret .= '<fieldset><legend>';
 245          /* No checkbox without name */
 246          if (!empty($opt['name'])) {
 247              $ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $opt['name'] . '"'
 248                  . ' value="something" id="checkbox_' . $plugin_name . '_' . $opt['name'] . '"'
 249                  . ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $opt['name']);
 250              if (isset($opt['force'])) {
 251                  /* Same code is also few lines higher, update both if needed */
 252                  $ret .= ' onclick="if (!this.checked &amp;&amp; '
 253                      . '(!document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\') '
 254                      . '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\').checked)) '
 255                      . 'return false; else return true;"';
 256              }
 257              $ret .= ' />';
 258              $ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
 259                  . PMA_getString($opt['text']) . '</label>';
 260          } else {
 261              $ret .= PMA_getString($opt['text']);
 262          }
 263          $ret .= '</legend>';
 264      } elseif ($opt['type'] == 'egroup') {
 265          $ret .= '</fieldset>';
 266      } else {
 267          /* This should be seen only by plugin writers, so I do not thing this
 268           * needs translation. */
 269          $ret .= 'UNKNOWN OPTION ' . $opt['type'] . ' IN IMPORT PLUGIN ' . $plugin_name . '!';
 270      }
 271      if (isset($opt['doc'])) {
 272          $ret .= PMA_showMySQLDocu($opt['doc'][0], $opt['doc'][1]);
 273      }
 274      $ret .= "\n";
 275      return $ret;
 276  }
 277  
 278  /**
 279   * string PMA_pluginGetOptions(string $section, array &$list)
 280   *
 281   * return html fieldset with editable options for plugin
 282   *
 283   * @uses    PMA_getString()
 284   * @uses    PMA_pluginGetOneOption()
 285   * @param   string  $section    name of config section in $GLOBALS['cfg'][$section]
 286   * @param   array   &$list      array with plugin configuration defined in plugin file
 287   * @return  string              html fieldset with plugin options
 288   */
 289  function PMA_pluginGetOptions($section, &$list)
 290  {
 291      $ret = '';
 292      // Options for plugins that support them
 293      foreach ($list as $plugin_name => $val) {
 294          $ret .= '<fieldset id="' . $plugin_name . '_options" class="options">';
 295          $ret .= '<legend>' . PMA_getString($val['options_text']) . '</legend>';
 296          $count = 0;
 297          if (isset($val['options']) && count($val['options']) > 0) {
 298              foreach ($val['options'] as $id => $opt) {
 299                  if ($opt['type'] != 'hidden') $count++;
 300                  $ret .= PMA_pluginGetOneOption($section, $plugin_name, $id, $opt);
 301              }
 302          }
 303          if ($count == 0) {
 304              $ret .= $GLOBALS['strNoOptions'];
 305          }
 306          $ret .= '</fieldset>';
 307      }
 308      return $ret;
 309  }
 310  
 311  /**
 312   * string PMA_pluginGetJavascript(array &$list)
 313   *
 314   * return html/javascript code which is needed for handling plugin stuff
 315   *
 316   * @param   array   &$list      array with plugin configuration defined in plugin file
 317   * @return  string              html fieldset with plugin options
 318   */
 319  function PMA_pluginGetJavascript(&$list) {
 320      $ret = '
 321      <script type="text/javascript" language="javascript">
 322      //<![CDATA[
 323      function hide_them_all() {
 324          ';
 325      foreach ($list as $plugin_name => $val) {
 326          $ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "none";' . "\n";
 327      }
 328      $ret .= '
 329      }
 330  
 331      function init_options() {
 332          hide_them_all();
 333          ';
 334      foreach ($list as $plugin_name => $val) {
 335          $ret .= 'if (document.getElementById("radio_plugin_' . $plugin_name . '").checked) {' . "\n";
 336          if (isset($val['force_file'])) {
 337              $ret .= 'document.getElementById(\'checkbox_dump_asfile\').checked = true;' . "\n";
 338          }
 339          $ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "block";' . "\n";
 340          $ret .= ' } else ' . "\n";
 341      }
 342      $ret .= '
 343          {
 344              ;
 345          }
 346      }
 347  
 348      function match_file(fname) {
 349          farr = fname.toLowerCase().split(".");
 350          if (farr.length != 0) {
 351              len = farr.length
 352              if (farr[len - 1] == "gz" || farr[len - 1] == "bz2" || farr[len -1] == "zip") len--;
 353              switch (farr[len - 1]) {
 354                  ';
 355      foreach ($list as $plugin_name => $val) {
 356          $ret .= 'case "' . $val['extension'] . '" :';
 357          $ret .= 'document.getElementById("radio_plugin_' . $plugin_name . '").checked = true;';
 358          $ret .= 'init_options();';
 359          $ret .= 'break;' . "\n";
 360      }
 361      $ret .='
 362              }
 363          }
 364      }
 365      //]]>
 366      </script>
 367      ';
 368      return $ret;
 369  }
 370  ?>


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