-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathe_module.php
101 lines (78 loc) · 2.86 KB
/
e_module.php
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/*
*
*/
if (!defined('e107_INIT')) { exit; }
if(!e107::isInstalled('static_cache'))
{
return '';
}
//full caching system STAR
//DO NOT LOAD PLUGIN AND LIBS IN ADMIN AREA
//#issue #2
if ( defset('e_ADMIN_AREA') === true ) {
return '';
}
//get plugin configuration
$sc_prefs = e107::getPlugConfig('static_cache')->getPref();
define('ST_CACHE_ENABLED',intval($sc_prefs['sc_enabled']));
define('ST_CACHE_EXPIRATION',intval($sc_prefs['sc_expiration']));
//also minify content?
define('ST_CACHE_MIN_ENABLED',intval($sc_prefs['sc_minification']));
//gzip compression enabled?
define('ST_CACHE_GZIP_ENABLED',intval($sc_prefs['sc_gzip_server']));
//pages excluded from cache
define('ST_CACHE_EXCLUDE_PAGES',$sc_prefs['sc_exclude_list']);
//path to save cache
define('ST_CACHE_SAVE_PATH',str_replace('/', DIRECTORY_SEPARATOR,e_ROOT.$e107->getFolder('web').$sc_prefs['sc_cache_path']));
//cache file extension
define('ST_CACHE_FILE_EXT',$sc_prefs['sc_cache_file_ext']);
$aPageExcluded = explode(',', ST_CACHE_EXCLUDE_PAGES );
$sCurrentPage = basename($_SERVER['SCRIPT_FILENAME']); //add ,'.php' to remove extension...
//check if current page is excluded from cache and exit immediately
if( in_array($sCurrentPage, $aPageExcluded ) ){
return '';
}
global $e_event,$e107cache,$ns;
// $e_event->register("newspost", "pingit");
// $e_event->register("newsupd", "pingit"); // Disable these for now, until admin functions written
//phpFastCache inside plugin
require(e_PLUGIN.'static_cache/libs/phpfastcache/src/autoload.php');
//require(e_PLUGIN.'static_cache/libs/phpwee/phpwee.php');
use phpFastCache\CacheManager;
use phpFastCache\Core\phpFastCache;
// Setup File Path on your config files
CacheManager::setDefaultConfig([
"path" => ST_CACHE_SAVE_PATH,
"cacheFileExtension" => ST_CACHE_FILE_EXT,
"itemDetailedDate" => false
]);
//instantiate class
$oStaticCache = CacheManager::getInstance('files');
//get config object
$aScConfig = $oStaticCache->getConfig();
$keyword_webpage = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING'];
$keyword_webpage_nu = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$keyword_webpage_md5 = md5($keyword_webpage);
// try to get from Cache first.
$resultsItem = $oStaticCache->getItem($keyword_webpage_md5);
$resultsItemCnt = $resultsItem->get();
if(!is_null($resultsItemCnt) &&
(ST_CACHE_ENABLED===1 && !USER)){
if(ST_CACHE_GZIP_ENABLED===1){
//21/05/2018 14:17:53 - RF
//mod_pagespeed on!
$unzipped_string = gzdecode( $resultsItemCnt );
echo $unzipped_string;
}else{
echo $resultsItemCnt;
}
//file_put_contents(dirname(__FILE__).e_WEB_ABS."cache/test.txt",$unzipped_string);
echo "\n<!-- File generated from cache ".$resultsItem->getExpirationDate()->format('Y-m-d H:i:s')." -->";
exit;
}
//cache ONLY when user is NOT LOGGED!
if( (ST_CACHE_ENABLED===1 && !USER) ){
ob_start();
}
?>