From b6620a53e538526dd221ee41e5b46437b816b6b3 Mon Sep 17 00:00:00 2001 From: OrdinalM Date: Wed, 30 Oct 2019 16:18:52 +0000 Subject: [PATCH 1/2] Fix name of parameter to onConfigLoaded(); change filename for empty url param to onRequestUrl() to "index" to avoid generating hidden dot file in cache --- PicoZCache.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PicoZCache.php b/PicoZCache.php index 71e9a7d..71fd1a6 100644 --- a/PicoZCache.php +++ b/PicoZCache.php @@ -20,7 +20,7 @@ class PicoZCache extends AbstractPicoPlugin private $cacheXHTML = false; private $cacheFileName; - public function onConfigLoaded(array &$settings) + public function onConfigLoaded(array &$config) { if (isset($config['cache_dir'])) { @@ -45,12 +45,13 @@ public function onConfigLoaded(array &$settings) public function onRequestUrl(&$url) { //replace any character except numbers and digits with a '-' to form valid file names - $this->cacheFileName = $this->cacheDir . preg_replace('/[^A-Za-z0-9_\-]/', '_', $url) . '.html'; + $this->cacheFileName = $this->cacheDir . (empty($url) ? 'index' : preg_replace('/[^A-Za-z0-9_\-]/', '_', $url)) . '.html'; //if a cached file exists and the cacheTime is not expired, load the file and exit if ($this->doCache && file_exists($this->cacheFileName) && (time() - filemtime($this->cacheFileName)) < $this->cacheTime) { header("Expires: " . gmdate("D, d M Y H:i:s", $this->cacheTime + filemtime($this->cacheFileName)) . " GMT"); ($this->cacheXHTML) ? header('Content-Type: application/xhtml+xml') : header('Content-Type: text/html'); + error_log($this->cacheFileName); die(readfile($this->cacheFileName)); } } From 51383afabfff340d797cb1c799fc3d2fd6d6c013 Mon Sep 17 00:00:00 2001 From: OrdinalM Date: Wed, 30 Oct 2019 16:19:56 +0000 Subject: [PATCH 2/2] remove rogue error_log() --- PicoZCache.php | 1 - 1 file changed, 1 deletion(-) diff --git a/PicoZCache.php b/PicoZCache.php index 71fd1a6..90c5991 100644 --- a/PicoZCache.php +++ b/PicoZCache.php @@ -51,7 +51,6 @@ public function onRequestUrl(&$url) if ($this->doCache && file_exists($this->cacheFileName) && (time() - filemtime($this->cacheFileName)) < $this->cacheTime) { header("Expires: " . gmdate("D, d M Y H:i:s", $this->cacheTime + filemtime($this->cacheFileName)) . " GMT"); ($this->cacheXHTML) ? header('Content-Type: application/xhtml+xml') : header('Content-Type: text/html'); - error_log($this->cacheFileName); die(readfile($this->cacheFileName)); } }