diff --git a/gzip.php b/gzip.php index 68375b8..b287e4c 100644 --- a/gzip.php +++ b/gzip.php @@ -269,61 +269,14 @@ public function onExtensionAfterSave($context, $table, $isNew, $data = []) $table->store(); } - $options = json_decode(json_encode($data['params']['gzip']), JSON_OBJECT_AS_ARRAY); - - $php_config = []; - $attributes = []; - - foreach ($options['instantloading'] as $key => $value) { - - switch ($key) { - - case 'filters': - - $attributes[] = $key . '="' . htmlspecialchars(json_encode(array_filter(preg_split('#\s+#s', $value, -1, PREG_SPLIT_NO_EMPTY), function ($value) { - return $value !== ''; - })), ENT_QUOTES) . '"'; - break; - - case 'trigger': - case 'intensity': - case 'filter-type': - case 'allow-query-string': - case 'allow-external-links': - - if (!empty($value)) { - - $attributes[] = $key . '="' . $value . '"'; - } - - break; - } - } + $this->cleanCache(); - $php_config['instantloading'] = $attributes; - $php_config['headers'] = $this->updateSecurityHeaders($options); + $options = json_decode(json_encode($data['params']['gzip']), JSON_OBJECT_AS_ARRAY); - $this->cleanCache(); // $this->updateSecurityHeaders($options); $this->updateManifest($options); $this->updateServiceWorker($options); - - - $path = JPATH_SITE . '/cache/z/app/' . $_SERVER['SERVER_NAME'] . '/'; - - if (!is_dir($path)) { - - $old_mask = umask(); - - umask(022); - mkdir($path, 0755, true); - umask($old_mask); - } - - file_put_contents($path . 'config.php', 'updateConfig($options); } return true; @@ -348,6 +301,11 @@ public function onAfterInitialise() $this->updateServiceWorker($this->options); } + if (!is_file(JPATH_SITE . '/cache/z/app/' . $_SERVER['SERVER_NAME'] . '/config.php')) { + + $this->updateConfig($this->options); + } + if (is_file($file)) { $this->worker_id = file_get_contents(JPATH_SITE . '/cache/z/app/' . $_SERVER['SERVER_NAME'] . '/worker_version'); @@ -1140,6 +1098,57 @@ protected function updateSecurityHeaders($options) return $headers; } + protected function updateConfig($options) { + + $path = JPATH_SITE . '/cache/z/app/' . $_SERVER['SERVER_NAME'] . '/'; + + if (!is_dir($path)) { + + $old_mask = umask(); + + umask(022); + mkdir($path, 0755, true); + umask($old_mask); + } + + + $php_config = []; + $attributes = []; + + foreach ($options['instantloading'] as $key => $value) { + + switch ($key) { + + case 'filters': + + $attributes[] = $key . '="' . htmlspecialchars(json_encode(array_filter(preg_split('#\s+#s', $value, -1, PREG_SPLIT_NO_EMPTY), function ($value) { + return $value !== ''; + })), ENT_QUOTES) . '"'; + break; + + case 'trigger': + case 'intensity': + case 'filter-type': + case 'allow-query-string': + case 'allow-external-links': + + if (!empty($value)) { + + $attributes[] = $key . '="' . $value . '"'; + } + + break; + } + } + + $php_config['instantloading'] = $attributes; + $php_config['headers'] = $this->updateSecurityHeaders($options); + + file_put_contents($path . 'config.php', '