1<?php 2if(!defined('DOKU_INC')) die(); 3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 4require_once(DOKU_PLUGIN.'action.php'); 5 6class action_plugin_distribute extends DokuWiki_Action_Plugin { 7 function getInfo(){ 8 return array( 9 'author' => 'Ahmet Sacan', 10 'email' => 'ahmet@ceng.metu.edu.tr', 11 'date' => '2007-02-07', 12 'name' => 'Distribute plugin', 13 'desc' => 'helps distribute your plugins', 14 'url' => 'http://www.ceng.metu.edu.tr/~ahmet', 15 ); 16 } 17 18 function register(&$contr){ 19 $contr->register_hook('ACTION_ACT_PREPROCESS', 20 'BEFORE', 21 $this, 22 'handle_act', 23 array()); 24 } 25 function handle_act(&$e, $param){ 26 if($e->data != 'distribute') return; 27 $e->preventDefault(); 28 $e->data = 'show'; 29 $list = $this->getConf('plugins'); 30 $list = explode(',',$list); 31 $p = $_GET['plugin']; 32 if(!in_array($p, $list)){ 33 msg('sorry, distribution of ['.$p.'] plugin is not allowed.',-1); 34 return; 35 } 36 if(!is_dir(DOKU_PLUGIN.$p)){ 37 msg('['.$p.'] plugin directory does not exist.',-1); 38 return; 39 } 40 if(file_exists(DOKU_INC.'inc/ZipLib.class.php')){ 41 require_once DOKU_INC.'inc/ZipLib.class.php'; 42 $zip = new ZipLib; 43 } 44 elseif(file_exists(DOKU_PLUGIN.'plugin/inc/zip.lib.php')){//older dokuwiki version 45 require_once DOKU_PLUGIN.'plugin/inc/zip.lib.php'; 46 $zip = new zip; 47 } 48 else{ 49 msg('Please make sure the dependency Plugin Manager plugin is installed, and that plugin/inc/zip.lib.php or ZipLib.class.php file exists.'); 50 return; 51 } 52 require_once dirname(__FILE__).'/helper.funcs.util.php'; 53 $files = getFilesInDir(DOKU_PLUGIN.$p, true,'f','',true); 54 $lastupdate = my_filemtime(DOKU_PLUGIN.$p, true); 55 global $conf; 56 $cachefile = "$conf[cachedir]/distribute/$p.zip"; 57 if(my_filemtime($cachefile) < $lastupdate){ 58 $zip->add_dir($p); 59 foreach($files as $f){ 60 $zip->add_file(file_get_contents(DOKU_PLUGIN.$p.'/'.$f),"$p/$f"); 61 } 62 echo($zip->get_file()); 63 io_makeFileDir($cachefile); 64 file_put_contents($cachefile, $zip->get_file()); 65 } 66 if(!is_file($cachefile)){ 67 msg("Sorry, but zip file creation has failed.",-1); 68 return; 69 } 70 header("Content-Type: application/octet-stream"); 71 header("Content-Disposition: filename=\"$p".'_'.date('Ymd',$lastupdate).".zip\""); 72 header("Content-Length: ".(string)(filesize($cachefile))); 73 readfile($cachefile); 74 die(); 75 } 76} 77 78//Setup VIM: ex: et ts=4 enc=utf-8 : 79