From 0ef95f3d2c295b225c3d3e09786d7e28abcdfe95 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 25 Jul 2009 17:21:05 +0200 Subject: restructured plugin manager Ignore-this: 4007248aa01f09990612c844c8a83900 This patch moves the different classes of the plugin manager into their own files and moves formerly global utility functions into the appropriate class scopes. darcs-hash:20090725152105-7ad00-89801e811b7eb0d0db25a825d6065aed8ef95c33.gz --- lib/plugins/plugin/classes/ap_manage.class.php | 203 +++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 lib/plugins/plugin/classes/ap_manage.class.php (limited to 'lib/plugins/plugin/classes/ap_manage.class.php') diff --git a/lib/plugins/plugin/classes/ap_manage.class.php b/lib/plugins/plugin/classes/ap_manage.class.php new file mode 100644 index 000000000..aea04f487 --- /dev/null +++ b/lib/plugins/plugin/classes/ap_manage.class.php @@ -0,0 +1,203 @@ +manager = & $manager; + $this->plugin = $plugin; + $this->lang = & $manager->lang; + } + + function process() { + return ''; + } + + function html() { + print $this->manager->locale_xhtml('admin_plugin'); + $this->html_menu(); + } + + // build our standard menu + function html_menu($listPlugins = true) { + global $ID; + + ptln('
'); + + ptln('
'); + ptln('

'.$this->lang['download'].'

'); + ptln('
'); + ptln(' '); + ptln('
'); + ptln(' '.$this->lang['download'].''); + ptln(' '); + ptln(' '); + ptln('
'); + ptln('
'); + ptln('
'); + + if ($listPlugins) { + ptln('

'.$this->lang['manage'].'

'); + + ptln('
'); + + ptln(' '); + + $this->html_pluginlist(); + + ptln('
'); + ptln(' '); + ptln('
'); + + // ptln('
'); + ptln(''); + } + + ptln(''); + } + + function html_pluginlist() { + global $ID; + global $plugin_protected; + + foreach ($this->manager->plugin_list as $plugin) { + + $disabled = plugin_isdisabled($plugin); + $protected = in_array($plugin,$plugin_protected); + + $checked = ($disabled) ? '' : ' checked="checked"'; + $check_disabled = ($protected) ? ' disabled="disabled"' : ''; + + // determine display class(es) + $class = array(); + if (in_array($plugin, $this->downloaded)) $class[] = 'new'; + if ($disabled) $class[] = 'disabled'; + if ($protected) $class[] = 'protected'; + + $class = count($class) ? ' class="'.join(' ', $class).'"' : ''; + + ptln(' '); + ptln(' '.$plugin.''); + ptln(' '); + ptln('

'.$plugin.'

'); + + $this->html_button($plugin, 'info', false, 6); + if (in_array('settings', $this->manager->functions)) { + $this->html_button($plugin, 'settings', !@file_exists(DOKU_PLUGIN.$plugin.'/settings.php'), 6); + } + $this->html_button($plugin, 'update', !$this->plugin_readlog($plugin, 'url'), 6); + $this->html_button($plugin, 'delete', $protected, 6); + + ptln(' '); + } + } + + function html_button($plugin, $btn, $disabled=false, $indent=0) { + $disabled = ($disabled) ? 'disabled="disabled"' : ''; + ptln('',$indent); + } + + /** + * Refresh plugin list + */ + function refresh() { + global $MSG,$config_cascade; + + //are there any undisplayed messages? keep them in session for display + if (isset($MSG) && count($MSG)){ + //reopen session, store data and close session again + @session_start(); + $_SESSION[DOKU_COOKIE]['msg'] = $MSG; + session_write_close(); + } + + // expire dokuwiki caches + // touching local.php expires wiki page, JS and CSS caches + @touch(reset($config_cascade['main']['local'])); + + // update latest plugin date - FIXME + header('Location: '.wl($ID).'?do=admin&page=plugin'); + exit(); + } + + // log + function plugin_writelog($plugin, $cmd, $data) { + + $file = DOKU_PLUGIN.$plugin.'/manager.dat'; + + switch ($cmd) { + case 'install' : + $url = $data[0]; + $date = date('r'); + if (!$fp = @fopen($file, 'w')) return; + fwrite($fp, "installed=$date\nurl=$url\n"); + fclose($fp); + break; + + case 'update' : + $date = date('r'); + if (!$fp = @fopen($file, 'a')) return; + fwrite($fp, "updated=$date\n"); + fclose($fp); + break; + } + } + + function plugin_readlog($plugin, $field) { + static $log = array(); + $file = DOKU_PLUGIN.plugin_directory($plugin).'/manager.dat'; + + if (!isset($log[$plugin])) { + $tmp = @file_get_contents($file); + if (!$tmp) return ''; + $log[$plugin] = & $tmp; + } + + if ($field == 'ALL') { + return $log[$plugin]; + } + + $match = array(); + if (preg_match_all('/'.$field.'=(.*)$/m',$log[$plugin], $match)) + return implode("\n", $match[1]); + + return ''; + } + + /** + * delete, with recursive sub-directory support + */ + function dir_delete($path) { + if (!is_string($path) || $path == "") return false; + + if (is_dir($path)) { + if (!$dh = @opendir($path)) return false; + + while ($f = readdir($dh)) { + if ($f == '..' || $f == '.') continue; + $this->dir_delete("$path/$f"); + } + + closedir($dh); + return @rmdir($path); + } else { + return @unlink($path); + } + + return false; + } + + +} -- cgit v1.2.3