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