You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
1.9 KiB

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