1<?php 2class repo_indexmenu_plugin { 3 /** 4 * Send a zipped theme 5 * 6 * @author Samuele Tognini <samuele@netsons.org> 7 */ 8 9 function send_theme ($file) { 10 require_once(DOKU_PLUGIN.'indexmenu/syntax/indexmenu.php'); 11 $idxm=new syntax_plugin_indexmenu_indexmenu(); 12 //clean the file name 13 $file=cleanID($file); 14 //check config 15 if(!$idxm->getConf('be_repo') || empty($file)) return false; 16 $repodir=INDEXMENU_IMG_ABSDIR."/repository"; 17 $zipfile=$repodir."/$file.zip"; 18 $localtheme=INDEXMENU_IMG_ABSDIR."/$file/"; 19 //theme does not exists 20 if (!file_exists($localtheme)) return false; 21 if (!io_mkdir_p($repodir)) return false; 22 $lm=@filemtime($zipfile); 23 //no cached zip or older than 1 day 24 if ($lm < time()-(60*60*24)) { 25 //create the zip 26 require_once(DOKU_PLUGIN."indexmenu/inc/pclzip.lib.php"); 27 @unlink($zipfile); 28 $zip=new PclZip($zipfile); 29 $status=$zip->add($localtheme,PCLZIP_OPT_REMOVE_ALL_PATH); 30 //error 31 if ($status == 0) return false; 32 } 33 $len = (int) filesize($zipfile); 34 //don't send large zips 35 if ($len > 2*1024*1024) return false; 36 //headers 37 header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0'); 38 header('Pragma: public'); 39 header('Content-Type: application/zip'); 40 header('Content-Disposition: attachment; filename="'.basename($zipfile).'";'); 41 header("Content-Transfer-Encoding: binary"); 42 //send zip 43 $fp=@fopen($zipfile, 'rb'); 44 if ($fp) { 45 $ct=@fread($fp, $len); 46 print $ct; 47 } 48 @fclose($fp); 49 return true; 50 } 51} 52