aboutsummaryrefslogtreecommitdiff
path: root/mod/dokuwiki/vendors/dokuwiki/lib/plugins/indexmenu/inc/repo.class.php
blob: 04dc75675487ac3a4eb4012aadd353ef49862f8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
class repo_indexmenu_plugin {
  /**
   * Send a zipped theme
   *
   * @author Samuele Tognini <samuele@netsons.org>
   */

  function send_theme ($file) {
    require_once(DOKU_PLUGIN.'indexmenu/syntax/indexmenu.php');
    $idxm=new syntax_plugin_indexmenu_indexmenu();
    //clean the file name
    $file=cleanID($file);
    //check config
    if(!$idxm->getConf('be_repo') || empty($file)) return false;
    $repodir=INDEXMENU_IMG_ABSDIR."/repository";
    $zipfile=$repodir."/$file.zip";
    $localtheme=INDEXMENU_IMG_ABSDIR."/$file/";
    //theme does not exists
    if (!file_exists($localtheme)) return false;
    if (!io_mkdir_p($repodir)) return false;
    $lm=@filemtime($zipfile);
    //no cached zip or older than 1 day
    if ($lm < time()-(60*60*24)) {
      //create the zip
      require_once(DOKU_PLUGIN."indexmenu/inc/pclzip.lib.php");
      @unlink($zipfile);
      $zip=new PclZip($zipfile);
      $status=$zip->add($localtheme,PCLZIP_OPT_REMOVE_ALL_PATH);
      //error
      if ($status == 0) return false;
    }
    $len = (int) filesize($zipfile);
    //don't send large zips
    if ($len > 2*1024*1024) return false;
    //headers
    header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename="'.basename($zipfile).'";');
    header("Content-Transfer-Encoding: binary");
    //send zip
    $fp=@fopen($zipfile, 'rb');
    if ($fp) {
      $ct=@fread($fp, $len);
      print $ct;
    }
    @fclose($fp);
    return true;
  }
}