[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/plugin/classes/ -> ap_manage.class.php (source)

   1  <?php
   2  
   3  class ap_manage {
   4  
   5      var $manager = null;
   6      var $lang = array();
   7      var $plugin = '';
   8      var $downloaded = array();
   9  
  10      function ap_manage(&$manager, $plugin) {
  11          $this->manager = & $manager;
  12          $this->plugin = $plugin;
  13          $this->lang = & $manager->lang;
  14      }
  15  
  16      function process() {
  17          return '';
  18      }
  19  
  20      function html() {
  21          print $this->manager->locale_xhtml('admin_plugin');
  22          $this->html_menu();
  23      }
  24  
  25      // build our standard menu
  26      function html_menu($listPlugins = true) {
  27          global $ID;
  28  
  29          ptln('<div class="pm_menu">');
  30  
  31          ptln('<div class="common">');
  32          ptln('  <h2>'.$this->lang['download'].'</h2>');
  33          ptln('  <form action="'.wl($ID).'" method="post">');
  34          ptln('    <fieldset class="hidden">',4);
  35          ptln('      <input type="hidden" name="do"   value="admin" />');
  36          ptln('      <input type="hidden" name="page" value="plugin" />');
  37          formSecurityToken();
  38          ptln('    </fieldset>');
  39          ptln('    <fieldset>');
  40          ptln('      <legend>'.$this->lang['download'].'</legend>');
  41          ptln('      <label for="dw__url">'.$this->lang['url'].'<input name="url" id="dw__url" class="edit" type="text" maxlength="200" /></label>');
  42          ptln('      <input type="submit" class="button" name="fn[download]" value="'.$this->lang['btn_download'].'" />');
  43          ptln('    </fieldset>');
  44          ptln('  </form>');
  45          ptln('</div>');
  46  
  47          if ($listPlugins) {
  48              ptln('<h2>'.$this->lang['manage'].'</h2>');
  49  
  50              ptln('<form action="'.wl($ID).'" method="post" class="plugins">');
  51  
  52              ptln('  <fieldset class="hidden">');
  53              ptln('    <input type="hidden" name="do"     value="admin" />');
  54              ptln('    <input type="hidden" name="page"   value="plugin" />');
  55              formSecurityToken();
  56              ptln('  </fieldset>');
  57  
  58              $this->html_pluginlist();
  59  
  60              ptln('  <fieldset class="buttons">');
  61              ptln('    <input type="submit" class="button" name="fn[enable]" value="'.$this->lang['btn_enable'].'" />');
  62              ptln('  </fieldset>');
  63  
  64              //            ptln('  </div>');
  65              ptln('</form>');
  66          }
  67  
  68          ptln('</div>');
  69      }
  70  
  71      function html_pluginlist() {
  72          global $plugin_protected;
  73  
  74          foreach ($this->manager->plugin_list as $plugin) {
  75  
  76              $disabled = plugin_isdisabled($plugin);
  77              $protected = in_array($plugin,$plugin_protected);
  78  
  79              $checked = ($disabled) ? '' : ' checked="checked"';
  80              $check_disabled = ($protected) ? ' disabled="disabled"' : '';
  81  
  82              // determine display class(es)
  83              $class = array();
  84              if (in_array($plugin, $this->downloaded)) $class[] = 'new';
  85              if ($disabled) $class[] = 'disabled';
  86              if ($protected) $class[] = 'protected';
  87  
  88              $class = count($class) ? ' class="'.join(' ', $class).'"' : '';
  89  
  90              ptln('    <fieldset'.$class.'>');
  91              ptln('      <legend>'.$plugin.'</legend>');
  92              ptln('      <input type="checkbox" class="enable" name="enabled[]" id="dw__p_'.$plugin.'" value="'.$plugin.'"'.$checked.$check_disabled.' />');
  93              ptln('      <h3 class="legend"><label for="dw__p_'.$plugin.'">'.$plugin.'</label></h3>');
  94  
  95              $this->html_button($plugin, 'info', false, 6);
  96              if (in_array('settings', $this->manager->functions)) {
  97                  $this->html_button($plugin, 'settings', !@file_exists(DOKU_PLUGIN.$plugin.'/settings.php'), 6);
  98              }
  99              $this->html_button($plugin, 'update', !$this->plugin_readlog($plugin, 'url'), 6);
 100              $this->html_button($plugin, 'delete', $protected, 6);
 101  
 102              ptln('    </fieldset>');
 103          }
 104      }
 105  
 106      function html_button($plugin, $btn, $disabled=false, $indent=0) {
 107          $disabled = ($disabled) ? 'disabled="disabled"' : '';
 108          ptln('<input type="submit" class="button" '.$disabled.' name="fn['.$btn.']['.$plugin.']" value="'.$this->lang['btn_'.$btn].'" />',$indent);
 109      }
 110  
 111      /**
 112       *  Refresh plugin list
 113       */
 114      function refresh() {
 115          global $config_cascade;
 116  
 117          // expire dokuwiki caches
 118          // touching local.php expires wiki page, JS and CSS caches
 119          @touch(reset($config_cascade['main']['local']));
 120  
 121          // update latest plugin date - FIXME
 122          global $ID;
 123          send_redirect(wl($ID,array('do'=>'admin','page'=>'plugin'),true, '&'));
 124      }
 125  
 126      /**
 127       * Write a log entry to the given target directory
 128       */
 129      function plugin_writelog($target, $cmd, $data) {
 130  
 131          $file = $target.'/manager.dat';
 132  
 133          switch ($cmd) {
 134              case 'install' :
 135                  $url = $data[0];
 136                  $date = date('r');
 137                  if (!$fp = @fopen($file, 'w')) return;
 138                  fwrite($fp, "installed=$date\nurl=$url\n");
 139                  fclose($fp);
 140                  break;
 141  
 142              case 'update' :
 143                  $url = $data[0];
 144                  $date = date('r');
 145                  if (!$fp = @fopen($file, 'r+')) return;
 146                  $buffer = "";
 147                  while (($line = fgets($fp)) !== false) {
 148                      $urlFound = strpos($line,"url");
 149                      if($urlFound !== false) $line="url=$url\n";
 150                      $buffer .= $line;
 151                  }
 152                  $buffer .= "updated=$date\n";
 153                  fseek($fp, 0);
 154                  fwrite($fp, $buffer);
 155                  fclose($fp);
 156                  break;
 157          }
 158      }
 159  
 160      function plugin_readlog($plugin, $field) {
 161          static $log = array();
 162          $file = DOKU_PLUGIN.plugin_directory($plugin).'/manager.dat';
 163  
 164          if (!isset($log[$plugin])) {
 165              $tmp = @file_get_contents($file);
 166              if (!$tmp) return '';
 167              $log[$plugin] = & $tmp;
 168          }
 169  
 170          if ($field == 'ALL') {
 171              return $log[$plugin];
 172          }
 173  
 174          $match = array();
 175          if (preg_match_all('/'.$field.'=(.*)$/m',$log[$plugin], $match))
 176              return implode("\n", $match[1]);
 177  
 178          return '';
 179      }
 180  
 181      /**
 182       * delete, with recursive sub-directory support
 183       */
 184      function dir_delete($path) {
 185          if (!is_string($path) || $path == "") return false;
 186  
 187          if (is_dir($path) && !is_link($path)) {
 188              if (!$dh = @opendir($path)) return false;
 189  
 190              while ($f = readdir($dh)) {
 191                  if ($f == '..' || $f == '.') continue;
 192                  $this->dir_delete("$path/$f");
 193              }
 194  
 195              closedir($dh);
 196              return @rmdir($path);
 197          }
 198          return @unlink($path);
 199      }
 200  
 201  
 202  }


Generated: Sun Jan 19 03:00:05 2014 Cross-referenced by PHPXref 0.7