From ae41532d7fa312951a06aa53477053d5e2985bff Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 8 Sep 2005 02:08:43 +0200 Subject: plugin manager update darcs-hash:20050908000843-50fdc-671b676257b1869e805235459925778a60e7d6f7.gz --- lib/plugins/plugin/admin.php | 249 ++++++++++++++++++++++++------------------- 1 file changed, 137 insertions(+), 112 deletions(-) (limited to 'lib/plugins/plugin/admin.php') diff --git a/lib/plugins/plugin/admin.php b/lib/plugins/plugin/admin.php index 39c5a41fe..091d41698 100644 --- a/lib/plugins/plugin/admin.php +++ b/lib/plugins/plugin/admin.php @@ -14,10 +14,6 @@ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'admin.php'); - - // language stuff here for now ... move to language files when complete - -// global $lang; //--------------------------[ GLOBALS ]------------------------------------------------ // note: probably should be dokuwiki wide globals, where they can be accessed by pluginutils.php @@ -47,7 +43,7 @@ class admin_plugin_plugin extends DokuWiki_Admin_Plugin { global $conf; $this->disabled = (!isset($conf['pluginmanager']) || ($conf['pluginmanager'] == 0)); } - + /** * return some info */ @@ -68,6 +64,7 @@ class admin_plugin_plugin extends DokuWiki_Admin_Plugin { * return prompt for admin menu */ function getMenuText($language) { + if (!$this->disabled) return parent::getMenuText($language); @@ -89,6 +86,9 @@ class admin_plugin_plugin extends DokuWiki_Admin_Plugin { if ($this->disabled) return; + // enable direct access to language strings + $this->setupLocale(); + $this->plugin = $_REQUEST['plugin']; $this->cmd = $_REQUEST['fn']; if (is_array($this->cmd)) $this->cmd = key($this->cmd); @@ -107,7 +107,7 @@ class admin_plugin_plugin extends DokuWiki_Admin_Plugin { $class = "ap_".$this->cmd; if (!class_exists($class)) $class = 'ap_manage'; - $this->handler = & new $class($this, $plugin); + $this->handler = & new $class($this, $this->plugin); $this->msg = $this->handler->process(); } @@ -121,7 +121,7 @@ class admin_plugin_plugin extends DokuWiki_Admin_Plugin { // enable direct access to language strings $this->setupLocale(); - if ($this->handler === NULL) $this->handler = & new ap_manage(); + if ($this->handler === NULL) $this->handler = & new ap_manage($this, $this->plugin); if (!$this->plugin_list) sort($this->plugin_list = plugin_list()); ptln('
'); @@ -148,18 +148,8 @@ class ap_manage { return ''; } - function html() { - - print $this->manager->plugin_locale_xhtml('admin_plugin'); - - // FIXME, these probably shouldn't be here any more! - if (!$this->manager->msg) $this->manager->msg = ' '; - ptln("

{$manager->msg}

"); - - if ($this->manager->error) { - ptln("

".str_replace("\n","
",$this->manager->error)."

"); - } - + function html() { + print $this->manager->locale_xhtml('admin_plugin'); $this->html_menu(); } @@ -207,17 +197,17 @@ class ap_manage { $new = (in_array($plugin, $this->downloaded)) ? ' class="new"' : ''; ptln('
'); + ptln('

'.$plugin.'

'); ptln('
'); ptln(' '.$plugin.''); - ptln('

'.$plugin.'

'); ptln(' '); ptln(' '); ptln(' '); - $this->html_button('delete', false, 6); - $this->html_button('update', !$this->plugin_readlog($plugin, 'url'), 6); - $this->html_button('settings', !@file_exists(DOKU_PLUGIN.$plugin.'/settings.php'), 6); $this->html_button('info', false, 6); + $this->html_button('settings', !@file_exists(DOKU_PLUGIN.$plugin.'/settings.php'), 6); + $this->html_button('update', !$this->plugin_readlog($plugin, 'url'), 6); + $this->html_button('delete', false, 6); ptln('
'); ptln('
'); @@ -267,6 +257,72 @@ class ap_manage { return (!$this->manager->error); } + function download($url, $overwrite=false) { + global $lang; + + // check the url + if (!preg_match("/[^\/]*$/", $url, $matches = array()) || !$matches[0]) { + $this->manager->error = $this->lang['error_badurl']."\n"; + return false; + } + + $file = $matches[0]; + $folder = "p".md5($file.date('r')); // tmp folder name - will be empty (should really make sure it doesn't already exist) + $tmp = DOKU_PLUGIN."tmp/$folder"; + + if (!ap_mkdir($tmp)) { + $this->manager->error = $this->lang['error_dir_create']."\n"; + return false; + } + + if (!io_download($url, "$tmp/$file")) { + $this->manager->error = sprintf($this->lang['error_download'],$url)."\n"; + } + + if (!$this->manager->error && !ap_decompress("$tmp/$file", $tmp)) { + $this->manager->error = sprintf($this->lang['error_decompress'],$file)."\n"; + } + + // search tmp/$folder for the folder(s) that has been created + // move that folder(s) to lib/plugins/ + if (!$this->manager->error) { + if ($dh = @opendir("$tmp/")) { + while (false !== ($f = readdir($dh))) { + if ($f == '.' || $f == '..' || $f == 'tmp') continue; + if (!is_dir("$tmp/$f")) continue; + + // check to make sure we aren't overwriting anything + if (!$overwrite && @file_exists(DOKU_PLUGIN."/$f")) { + // remember our settings, ask the user to confirm overwrite, FIXME + continue; + } + + $instruction = @file_exists(DOKU_PLUGIN."/$f") ? 'update' : 'install'; + + if (ap_copy("$tmp/$f", DOKU_PLUGIN.$f)) { + $this->downloaded[] = $f; + $this->plugin_writelog($f, $instruction, array($url)); + } else { + $this->manager->error .= sprintf($lang['error_copy']."\n", $f); + } + } + closedir($dh); + } else { + $this->manager->error = $this->lang['error']."\n"; + } + } + + // cleanup + if ($folder && is_dir(DOKU_PLUGIN."tmp/$folder")) ap_delete(DOKU_PLUGIN."tmp/$folder"); + + if (!$this->manager->error) { + $this->refresh(); + return true; + } + + return false; + } + // log function plugin_writelog($plugin, $cmd, $data) { @@ -283,7 +339,7 @@ class ap_manage { case 'update' : $date = date('r'); - if (!$fp = @fopen($file, 'w+')) return; + if (!$fp = @fopen($file, 'a')) return; fwrite($fp, "updated=$date\n"); fclose($fp); break; @@ -329,6 +385,7 @@ class ap_manage { ptln('
'); } + } class ap_download extends ap_manage { @@ -336,56 +393,10 @@ class ap_manage { var $overwrite = false; function process() { - global $lang, $conf; + global $lang; $plugin_url = $_REQUEST['url']; - if (!preg_match("/[^\/]*$/", $plugin_url, $matches = array()) || !$matches[0]) { - $this->manager->error = $this->lang['error_badurl'].'\n'; - return ''; - } - - $file = $matches[0]; - $folder = "p".md5($file.date('r')); // tmp folder name - will be empty (should really make sure it doesn't already exist) - $tmp = DOKU_PLUGIN."tmp/$folder"; - - if (!$this->manager->error && !ap_mkdir($tmp)) { - $this->manager->error = $this->lang['error_dir_create'].'\n'; - $folder = ''; - } - - if (!$this->manager->error && !io_download($plugin_url, "$tmp/$file")) { - $this->manager->error = sprintf($this->lang['error_download'],$url)."\n"; - } - - ap_decompress("$tmp/$file", $tmp); - - // search tmp/$folder for the folder(s) that has been created - // move that folder(s) to lib/plugins/ - if ($dh = @opendir("$tmp/")) { - while (false !== ($f = readdir($dh))) { - if ($f == '.' || $f == '..' || $f == 'tmp') continue; - if (!is_dir("$tmp/$f")) continue; - - // check to make sure we aren't overwriting anything - if (file_exists(DOKU_PLUGIN."/$f")) { - // remember our settings, ask the user to confirm overwrite, FIXME - continue; - } - - ap_copy("$tmp/$f", DOKU_PLUGIN.$f); - $this->downloaded[] = $f; - $this->plugin_writelog($f, 'install', array($plugin_url)); - } - closedir($dh); - } - - // cleanup - if ($folder && is_dir(DOKU_PLUGIN."tmp/$folder")) ap_delete(DOKU_PLUGIN."tmp/$folder"); - - if (!$this->manager->error) { - $this->refresh(); - } - + $this->download($plugin_url, $this->overwrite); return ''; } @@ -396,7 +407,7 @@ class ap_manage { ptln('

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

'); if ($this->manager->error) { - ptln('

'.$this->manager->error.'

'); + ptln('

'.str_replace("\n","
",$this->manager->error).'

'); } else if (count($this->downloaded) == 1) { ptln('

'.sprintf($this->lang['downloaded'],$this->downloaded[0]).'

'); } else if (count($this->downloaded)) { // more than one plugin in the download @@ -418,12 +429,17 @@ class ap_manage { function process() { - $deleted = $this->manager->plugin; - ap_delete(DOKU_PLUGIN.$deleted); - $this->plugin = ''; - + ap_delete(DOKU_PLUGIN.$this->manager->plugin); $this->refresh(); - return "Plugin $deleted deleted"; + } + + function html() { + parent::html(); + + ptln('
'); + ptln('

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

'); + ptln('

'.sprintf($this->lang['deleted'],$this->plugin).'

'); + ptln('
'); } } @@ -465,43 +481,46 @@ class ap_manage { if (!$this->manager->plugin) { return; } ptln('
'); - ptln("

Plugin: {$this->manager->plugin}

"); + 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 = substr(strrchr("\n".$this->plugin_readlog($this->manager->plugin, 'updated'), '\n'), 1); + $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("
".$this->manager->getLang('source').'
'.($source ? $source : $this->manager->getLang('unknown'))."
",4); ptln("
",2); if (count($this->details) == 0) { - ptln("

This plugin returned no information, it may be invalid.

",2); + ptln("

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

",2); } else { ptln("
",2); - if ($this->plugin_info['name']) ptln("
Name
".$this->out($this->plugin_info['name'])."
",4); - if ($this->plugin_info['type']) ptln("
Type
".$this->out($this->plugin_info['type'])."
",4); - if ($this->plugin_info['desc']) ptln("
Description
".$this->out($this->plugin_info['desc'])."
",4); - if ($this->plugin_info['author']) ptln("
Author
".$this->manager->plugin_email($this->plugin_info['email'], $this->plugin_info['author'])."
",4); - if ($this->plugin_info['url']) ptln("
Web
".$this->manager->plugin_link($this->plugin_info['url'], '', 'urlextern')."
",4); + 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("

Components

",2); + ptln("

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

",2); ptln("
",2); foreach ($this->details as $info) { ptln("
",4); - if (!$this->plugin_info['name']) ptln("
Name
".$this->out($info['name'])."
",6); - if (!$this->plugin_info['type']) ptln("
Type
".$this->out($info['type'])."
",6); - if (!$this->plugin_info['desc']) ptln("
Description
".$this->out($info['desc'])."
",6); - if (!$this->plugin_info['author']) ptln("
Author
".$this->manager->plugin_email($info['email'], $info['author'])."
",6); - if (!$this->plugin_info['url']) ptln("
Web
".$this->manager->plugin_link($info['url'], '', 'urlextern')."
",6); + 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); } @@ -521,6 +540,16 @@ class ap_manage { //--------------[ to do ]--------------------------------------- class ap_update extends ap_manage { + var $overwrite = true; + + function process() { + global $lang; + + $plugin_url = $this->plugin_readlog($this->plugin, 'url'); + $this->download($plugin_url, $this->overwrite); + return ''; + } + function html() { parent::html(); @@ -528,20 +557,19 @@ class ap_manage { ptln('

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

'); if ($this->manager->error) { - ptln('

'.$this->manager->error.'

'); + ptln('

'.str_replace("\n","
", $this->manager->error).'

'); } else if (count($this->downloaded) == 1) { - ptln('

'.sprintf($this->lang['downloaded'],$this->downloaded[0]).'

'); + ptln('

'.sprintf($this->lang['updated'],$this->downloaded[0]).'

'); } else if (count($this->downloaded)) { // more than one plugin in the download - ptln('

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

'); + ptln('

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

'); ptln('
    '); foreach ($this->downloaded as $plugin) { ptln('
  • '.$plugin.'
  • ',2); } ptln('
'); } else { // none found in download - ptln('

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

'); + ptln('

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

'); } - ptln('

Under Construction

'); ptln('
'); } } @@ -559,33 +587,30 @@ class ap_manage { // decompression library doesn't like target folders ending in "/" if (substr($target, -1) == "/") $target = substr($target, 0, -1); + $ext = substr($file, strrpos($file,'.')+1); - // .tar, .tar.bz, .tar.gz - if (preg_match("/\.tar(\.bz2?|\.gz)?$/", $file)) { + // .tar, .tar.bz, .tar.gz, .tgz + if (in_array($ext, array('tar','bz','bz2','gz','tgz'))) { require_once(DOKU_PLUGIN."plugin/inc/tarlib.class.php"); $tar = new CompTar($file, COMPRESS_DETECT); $ok = $tar->Extract(FULL_ARCHIVE, $target, '', 0777); - // sort something out for handling tar error messages meaningfully - if ($ok<0) ptln("

tar error:".$tar->TarErrorStr($ok)."

"); + // FIXME sort something out for handling tar error messages meaningfully return ($ok<0?false:true); - } - - if (substr($file, -4) == ".zip") { - + + } else if ($ext == 'zip') { + require_once(DOKU_PLUGIN."plugin/inc/zip.lib.php"); $zip = new zip(); $ok = $zip->Extract($file, $target); - // sort something out for handling zip error messages meaningfully - if ($ok==-1) ptln("

zip error:

"); + // FIXME sort something out for handling zip error messages meaningfully return ($ok==-1?false:true); - } - - if (substr($file, -4) == ".rar") { + + } else if ($ext == "rar") { // not yet supported -- fix me return false; } @@ -660,7 +685,7 @@ class ap_manage { $path = DOKU_PLUGIN.$plugin.'/'; foreach ($common_plugin_types as $type) { - if (file_exists($path.$type.'.php')) { $components[] = array('name'=>$plugin, 'type'=>$type); continue; } + if (file_exists($path.$type.'.php')) { $components[] = array('name'=>$plugin, 'type'=>$type); continue; } if ($dh = @opendir($path.$type.'/')) { while (false !== ($cp = readdir($dh))) { -- cgit v1.2.3