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_info.class.php | 129 +++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 lib/plugins/plugin/classes/ap_info.class.php (limited to 'lib/plugins/plugin/classes/ap_info.class.php') diff --git a/lib/plugins/plugin/classes/ap_info.class.php b/lib/plugins/plugin/classes/ap_info.class.php new file mode 100644 index 000000000..dd1765f6c --- /dev/null +++ b/lib/plugins/plugin/classes/ap_info.class.php @@ -0,0 +1,129 @@ +manager->plugin) { return; } + + $component_list = $this->get_plugin_components($this->manager->plugin); + usort($component_list, array($this,'component_sort')); + + foreach ($component_list as $component) { + if ($obj = & plugin_load($component['type'],$component['name']) === NULL) continue; + + $this->details[] = array_merge($obj->getInfo(), array('type' => $component['type'])); + unset($obj); + } + + // review details to simplify things + foreach($this->details as $info) { + foreach($info as $item => $value) { + if (!isset($this->plugin_info[$item])) { $this->plugin_info[$item] = $value; continue; } + if ($this->plugin_info[$item] != $value) $this->plugin_info[$item] = ''; + } + } + } + + function html() { + + // output the standard menu stuff + parent::html(); + + // sanity check + if (!$this->manager->plugin) { return; } + + ptln('
'); + ptln("

".$this->manager->getLang('plugin')." {$this->manager->plugin}

"); + + // collect pertinent information from the log + $installed = $this->plugin_readlog($this->manager->plugin, 'installed'); + $source = $this->plugin_readlog($this->manager->plugin, 'url'); + $updated = $this->plugin_readlog($this->manager->plugin, 'updated'); + if (strrpos($updated, "\n") !== false) $updated = substr($updated, strrpos($updated, "\n")+1); + + ptln("
",2); + ptln("
".$this->manager->getLang('source').'
'.($source ? $source : $this->manager->getLang('unknown'))."
",4); + ptln("
".$this->manager->getLang('installed').'
'.($installed ? $installed : $this->manager->getLang('unknown'))."
",4); + if ($updated) ptln("
".$this->manager->getLang('lastupdate').'
'.$updated."
",4); + ptln("
",2); + + if (count($this->details) == 0) { + ptln("

".$this->manager->getLang('noinfo')."

",2); + } else { + + ptln("
",2); + if ($this->plugin_info['name']) ptln("
".$this->manager->getLang('name')."
".$this->out($this->plugin_info['name'])."
",4); + if ($this->plugin_info['date']) ptln("
".$this->manager->getLang('date')."
".$this->out($this->plugin_info['date'])."
",4); + if ($this->plugin_info['type']) ptln("
".$this->manager->getLang('type')."
".$this->out($this->plugin_info['type'])."
",4); + if ($this->plugin_info['desc']) ptln("
".$this->manager->getLang('desc')."
".$this->out($this->plugin_info['desc'])."
",4); + if ($this->plugin_info['author']) ptln("
".$this->manager->getLang('author')."
".$this->manager->email($this->plugin_info['email'], $this->plugin_info['author'])."
",4); + if ($this->plugin_info['url']) ptln("
".$this->manager->getLang('www')."
".$this->manager->external_link($this->plugin_info['url'], '', 'urlextern')."
",4); + ptln("
",2); + + if (count($this->details) > 1) { + ptln("

".$this->manager->getLang('components')."

",2); + ptln("
",2); + + foreach ($this->details as $info) { + + ptln("
",4); + ptln("
".$this->manager->getLang('name')."
".$this->out($info['name'])."
",6); + if (!$this->plugin_info['date']) ptln("
".$this->manager->getLang('date')."
".$this->out($info['date'])."
",6); + if (!$this->plugin_info['type']) ptln("
".$this->manager->getLang('type')."
".$this->out($info['type'])."
",6); + if (!$this->plugin_info['desc']) ptln("
".$this->manager->getLang('desc')."
".$this->out($info['desc'])."
",6); + if (!$this->plugin_info['author']) ptln("
".$this->manager->getLang('author')."
".$this->manager->email($info['email'], $info['author'])."
",6); + if (!$this->plugin_info['url']) ptln("
".$this->manager->getLang('www')."
".$this->manager->external_link($info['url'], '', 'urlextern')."
",6); + ptln("
",4); + + } + ptln("
",2); + } + } + ptln("
"); + } + + // simple output filter, make html entities safe and convert new lines to
+ function out($text) { + return str_replace("\n",'
',htmlspecialchars($text)); + } + + + /** + * return a list (name & type) of all the component plugins that make up this plugin + * + * @todo can this move to pluginutils? + */ + function get_plugin_components($plugin) { + + global $plugin_types; + + $components = array(); + $path = DOKU_PLUGIN.plugin_directory($plugin).'/'; + + foreach ($plugin_types as $type) { + if (@file_exists($path.$type.'.php')) { $components[] = array('name'=>$plugin, 'type'=>$type); continue; } + + if ($dh = @opendir($path.$type.'/')) { + while (false !== ($cp = readdir($dh))) { + if ($cp == '.' || $cp == '..' || strtolower(substr($cp,-4)) != '.php') continue; + $components[] = array('name'=>$plugin.'_'.substr($cp, 0, -4), 'type'=>$type); + } + closedir($dh); + } + } + return $components; + } + + /** + * usort callback to sort plugin components + */ + function component_sort($a, $b) { + if ($a['name'] == $b['name']) return 0; + return ($a['name'] < $b['name']) ? -1 : 1; + } +} -- cgit v1.2.3