[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/config/settings/ -> extra.class.php (source)

   1  <?php
   2  /**
   3   * additional setting classes specific to these settings
   4   *
   5   * @author    Chris Smith <chris@jalakai.co.uk>
   6   */
   7  
   8  if (!class_exists('setting_sepchar')) {
   9      /**
  10       * Class setting_sepchar
  11       */
  12      class setting_sepchar extends setting_multichoice {
  13  
  14          /**
  15           * @param string $key
  16           * @param array|null $param array with metadata of setting
  17           */
  18          function __construct($key,$param=null) {
  19              $str = '_-.';
  20              for ($i=0;$i<strlen($str);$i++) $this->_choices[] = $str{$i};
  21  
  22              // call foundation class constructor
  23              parent::__construct($key,$param);
  24          }
  25      }
  26  }
  27  
  28  if (!class_exists('setting_savedir')) {
  29      /**
  30       * Class setting_savedir
  31       */
  32      class setting_savedir extends setting_string {
  33  
  34          /**
  35           * update changed setting with user provided value $input
  36           * - if changed value fails error check, save it to $this->_input (to allow echoing later)
  37           * - if changed value passes error check, set $this->_local to the new value
  38           *
  39           * @param  mixed   $input   the new value
  40           * @return boolean          true if changed, false otherwise (also on error)
  41           */
  42          function update($input) {
  43              if ($this->is_protected()) return false;
  44  
  45              $value = is_null($this->_local) ? $this->_default : $this->_local;
  46              if ($value == $input) return false;
  47  
  48              if (!init_path($input)) {
  49                  $this->_error = true;
  50                  $this->_input = $input;
  51                  return false;
  52              }
  53  
  54              $this->_local = $input;
  55              return true;
  56          }
  57      }
  58  }
  59  
  60  if (!class_exists('setting_authtype')) {
  61      /**
  62       * Class setting_authtype
  63       */
  64      class setting_authtype extends setting_multichoice {
  65  
  66          /**
  67           * Receives current values for the setting $key
  68           *
  69           * @param mixed $default   default setting value
  70           * @param mixed $local     local setting value
  71           * @param mixed $protected protected setting value
  72           */
  73          function initialize($default,$local,$protected) {
  74              /** @var $plugin_controller Doku_Plugin_Controller */
  75              global $plugin_controller;
  76  
  77              // retrieve auth types provided by plugins
  78              foreach ($plugin_controller->getList('auth') as $plugin) {
  79                  $this->_choices[] = $plugin;
  80              }
  81  
  82              parent::initialize($default,$local,$protected);
  83          }
  84  
  85          /**
  86           * update changed setting with user provided value $input
  87           * - if changed value fails error check, save it to $this->_input (to allow echoing later)
  88           * - if changed value passes error check, set $this->_local to the new value
  89           *
  90           * @param  mixed   $input   the new value
  91           * @return boolean          true if changed, false otherwise (also on error)
  92           */
  93          function update($input) {
  94              /** @var $plugin_controller Doku_Plugin_Controller */
  95              global $plugin_controller;
  96  
  97              // is an update possible/requested?
  98              $local = $this->_local;                       // save this, parent::update() may change it
  99              if (!parent::update($input)) return false;    // nothing changed or an error caught by parent
 100              $this->_local = $local;                       // restore original, more error checking to come
 101  
 102              // attempt to load the plugin
 103              $auth_plugin = $plugin_controller->load('auth', $input);
 104  
 105              // @TODO: throw an error in plugin controller instead of returning null
 106              if (is_null($auth_plugin)) {
 107                  $this->_error = true;
 108                  msg('Cannot load Auth Plugin "' . $input . '"', -1);
 109                  return false;
 110              }
 111  
 112              // verify proper instantiation (is this really a plugin?) @TODO use instanceof? implement interface?
 113              if (is_object($auth_plugin) && !method_exists($auth_plugin, 'getPluginName')) {
 114                  $this->_error = true;
 115                  msg('Cannot create Auth Plugin "' . $input . '"', -1);
 116                  return false;
 117              }
 118  
 119              // did we change the auth type? logout
 120              global $conf;
 121              if($conf['authtype'] != $input) {
 122                  msg('Authentication system changed. Please re-login.');
 123                  auth_logoff();
 124              }
 125  
 126              $this->_local = $input;
 127              return true;
 128          }
 129      }
 130  }
 131  
 132  if (!class_exists('setting_im_convert')) {
 133      /**
 134       * Class setting_im_convert
 135       */
 136      class setting_im_convert extends setting_string {
 137  
 138          /**
 139           * update changed setting with user provided value $input
 140           * - if changed value fails error check, save it to $this->_input (to allow echoing later)
 141           * - if changed value passes error check, set $this->_local to the new value
 142           *
 143           * @param  mixed   $input   the new value
 144           * @return boolean          true if changed, false otherwise (also on error)
 145           */
 146          function update($input) {
 147              if ($this->is_protected()) return false;
 148  
 149              $input = trim($input);
 150  
 151              $value = is_null($this->_local) ? $this->_default : $this->_local;
 152              if ($value == $input) return false;
 153  
 154              if ($input && !file_exists($input)) {
 155                  $this->_error = true;
 156                  $this->_input = $input;
 157                  return false;
 158              }
 159  
 160              $this->_local = $input;
 161              return true;
 162          }
 163      }
 164  }
 165  
 166  if (!class_exists('setting_disableactions')) {
 167      /**
 168       * Class setting_disableactions
 169       */
 170      class setting_disableactions extends setting_multicheckbox {
 171  
 172          /**
 173           * Build html for label and input of setting
 174           *
 175           * @param admin_plugin_config $plugin object of config plugin
 176           * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
 177           * @return array with content array(string $label_html, string $input_html)
 178           */
 179          function html(admin_plugin_config $plugin, $echo=false) {
 180              global $lang;
 181  
 182              // make some language adjustments (there must be a better way)
 183              // transfer some DokuWiki language strings to the plugin
 184              $plugin->addLang($this->_key.'_revisions', $lang['btn_revs']);
 185              foreach ($this->_choices as $choice) {
 186                if (isset($lang['btn_'.$choice])) $plugin->addLang($this->_key.'_'.$choice, $lang['btn_'.$choice]);
 187              }
 188  
 189              return parent::html($plugin, $echo);
 190          }
 191      }
 192  }
 193  
 194  if (!class_exists('setting_compression')) {
 195      /**
 196       * Class setting_compression
 197       */
 198      class setting_compression extends setting_multichoice {
 199  
 200          var $_choices = array('0');      // 0 = no compression, always supported
 201  
 202          /**
 203           * Receives current values for the setting $key
 204           *
 205           * @param mixed $default   default setting value
 206           * @param mixed $local     local setting value
 207           * @param mixed $protected protected setting value
 208           */
 209          function initialize($default,$local,$protected) {
 210  
 211              // populate _choices with the compression methods supported by this php installation
 212              if (function_exists('gzopen')) $this->_choices[] = 'gz';
 213              if (function_exists('bzopen')) $this->_choices[] = 'bz2';
 214  
 215              parent::initialize($default,$local,$protected);
 216          }
 217      }
 218  }
 219  
 220  if (!class_exists('setting_license')) {
 221      /**
 222       * Class setting_license
 223       */
 224      class setting_license extends setting_multichoice {
 225  
 226          var $_choices = array('');      // none choosen
 227  
 228          /**
 229           * Receives current values for the setting $key
 230           *
 231           * @param mixed $default   default setting value
 232           * @param mixed $local     local setting value
 233           * @param mixed $protected protected setting value
 234           */
 235          function initialize($default,$local,$protected) {
 236              global $license;
 237  
 238              foreach($license as $key => $data){
 239                  $this->_choices[] = $key;
 240                  $this->lang[$this->_key.'_o_'.$key] = $data['name']; // stored in setting
 241              }
 242  
 243              parent::initialize($default,$local,$protected);
 244          }
 245      }
 246  }
 247  
 248  
 249  if (!class_exists('setting_renderer')) {
 250      /**
 251       * Class setting_renderer
 252       */
 253      class setting_renderer extends setting_multichoice {
 254          var $_prompts = array();
 255          var $_format = null;
 256  
 257          /**
 258           * Receives current values for the setting $key
 259           *
 260           * @param mixed $default   default setting value
 261           * @param mixed $local     local setting value
 262           * @param mixed $protected protected setting value
 263           */
 264          function initialize($default,$local,$protected) {
 265              $format = $this->_format;
 266  
 267              foreach (plugin_list('renderer') as $plugin) {
 268                  $renderer = plugin_load('renderer',$plugin);
 269                  if (method_exists($renderer,'canRender') && $renderer->canRender($format)) {
 270                      $this->_choices[] = $plugin;
 271  
 272                      $info = $renderer->getInfo();
 273                      $this->_prompts[$plugin] = $info['name'];
 274                  }
 275              }
 276  
 277              parent::initialize($default,$local,$protected);
 278          }
 279  
 280          /**
 281           * Build html for label and input of setting
 282           *
 283           * @param admin_plugin_config $plugin object of config plugin
 284           * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
 285           * @return array with content array(string $label_html, string $input_html)
 286           */
 287          function html(admin_plugin_config $plugin, $echo=false) {
 288  
 289              // make some language adjustments (there must be a better way)
 290              // transfer some plugin names to the config plugin
 291              foreach($this->_choices as $choice) {
 292                  if(!$plugin->getLang($this->_key . '_o_' . $choice)) {
 293                      if(!isset($this->_prompts[$choice])) {
 294                          $plugin->addLang(
 295                              $this->_key . '_o_' . $choice,
 296                              sprintf($plugin->getLang('renderer__core'), $choice)
 297                          );
 298                      } else {
 299                          $plugin->addLang(
 300                              $this->_key . '_o_' . $choice,
 301                              sprintf($plugin->getLang('renderer__plugin'), $this->_prompts[$choice])
 302                          );
 303                      }
 304                  }
 305              }
 306              return parent::html($plugin, $echo);
 307          }
 308      }
 309  }