'Ahmet Sacan', 'email' => 'ahmet@ceng.metu.edu.tr', 'date' => '2007-02-07', 'name' => 'Distribute plugin', 'desc' => 'helps distribute your plugins', 'url' => 'http://www.ceng.metu.edu.tr/~ahmet', ); } function register(&$contr){ $contr->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_act', array()); } function handle_act(&$e, $param){ if($e->data != 'distribute') return; $e->preventDefault(); $e->data = 'show'; $list = $this->getConf('plugins'); $list = explode(',',$list); $p = $_GET['plugin']; if(!in_array($p, $list)){ msg('sorry, distribution of ['.$p.'] plugin is not allowed.',-1); return; } if(!is_dir(DOKU_PLUGIN.$p)){ msg('['.$p.'] plugin directory does not exist.',-1); return; } if(file_exists(DOKU_INC.'inc/ZipLib.class.php')){ require_once DOKU_INC.'inc/ZipLib.class.php'; $zip = new ZipLib; } elseif(file_exists(DOKU_PLUGIN.'plugin/inc/zip.lib.php')){//older dokuwiki version require_once DOKU_PLUGIN.'plugin/inc/zip.lib.php'; $zip = new zip; } else{ msg('Please make sure the dependency Plugin Manager plugin is installed, and that plugin/inc/zip.lib.php or ZipLib.class.php file exists.'); return; } require_once dirname(__FILE__).'/helper.funcs.util.php'; $files = getFilesInDir(DOKU_PLUGIN.$p, true,'f','',true); $lastupdate = my_filemtime(DOKU_PLUGIN.$p, true); global $conf; $cachefile = "$conf[cachedir]/distribute/$p.zip"; if(my_filemtime($cachefile) < $lastupdate){ $zip->add_dir($p); foreach($files as $f){ $zip->add_file(file_get_contents(DOKU_PLUGIN.$p.'/'.$f),"$p/$f"); } echo($zip->get_file()); io_makeFileDir($cachefile); file_put_contents($cachefile, $zip->get_file()); } if(!is_file($cachefile)){ msg("Sorry, but zip file creation has failed.",-1); return; } header("Content-Type: application/octet-stream"); header("Content-Disposition: filename=\"$p".'_'.date('Ymd',$lastupdate).".zip\""); header("Content-Length: ".(string)(filesize($cachefile))); readfile($cachefile); die(); } } //Setup VIM: ex: et ts=4 enc=utf-8 :