@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * @var string The path to the current $cachedir directory. |
| 25 | 25 | */ |
| 26 | 26 | private $cachedir = null; |
| 27 | - private $cacheDB = null; |
|
| 27 | + private $cacheDB = null; |
|
| 28 | 28 | private $cacheTime = null; |
| 29 | 29 | |
| 30 | 30 | public function __construct() |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | // Set our default cachedir. |
| 37 | 37 | $this->setCachedir(); |
| 38 | 38 | |
| 39 | - $database = $this->cachedir.'/'.'SQLite3Cache.db3'; |
|
| 39 | + $database = $this->cachedir . '/' . 'SQLite3Cache.db3'; |
|
| 40 | 40 | |
| 41 | 41 | $this->cacheDB = new SQLite3($database); |
| 42 | 42 | $this->cacheDB->busyTimeout(1000); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $this->cacheDB->exec('CREATE TABLE cache (key text unique, value blob, ttl int);'); |
| 45 | 45 | $this->cacheDB->exec('CREATE INDEX ttls ON cache(ttl);'); |
| 46 | 46 | } |
| 47 | - $this->cacheTime = time(); |
|
| 47 | + $this->cacheTime = time(); |
|
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | |
@@ -66,12 +66,12 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function getData($key, $ttl = null) |
| 68 | 68 | { |
| 69 | - $ttl = time(); |
|
| 70 | - $query = 'SELECT value FROM cache WHERE key = \''.$this->cacheDB->escapeString($key).'\' AND ttl >= '.$ttl.' LIMIT 1'; |
|
| 69 | + $ttl = time(); |
|
| 70 | + $query = 'SELECT value FROM cache WHERE key = \'' . $this->cacheDB->escapeString($key) . '\' AND ttl >= ' . $ttl . ' LIMIT 1'; |
|
| 71 | 71 | $result = $this->cacheDB->query($query); |
| 72 | 72 | |
| 73 | 73 | $value = null; |
| 74 | - while($res = $result->fetchArray(SQLITE3_ASSOC)) { |
|
| 74 | + while ($res = $result->fetchArray(SQLITE3_ASSOC)) { |
|
| 75 | 75 | $value = $res['value']; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | public function putData($key, $value, $ttl = null) |
| 85 | 85 | { |
| 86 | 86 | |
| 87 | - $ttl = $this->cacheTime + $ttl; |
|
| 88 | - $query = 'REPLACE INTO cache VALUES (\''.$this->cacheDB->escapeString($key).'\', \''.$this->cacheDB->escapeString($value).'\', '.$this->cacheDB->escapeString($ttl).');'; |
|
| 89 | - $result = $this->cacheDB->exec($query); |
|
| 87 | + $ttl = $this->cacheTime + $ttl; |
|
| 88 | + $query = 'REPLACE INTO cache VALUES (\'' . $this->cacheDB->escapeString($key) . '\', \'' . $this->cacheDB->escapeString($value) . '\', ' . $this->cacheDB->escapeString($ttl) . ');'; |
|
| 89 | + $result = $this->cacheDB->exec($query); |
|
| 90 | 90 | |
| 91 | 91 | return $result; |
| 92 | 92 | } |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | public function cleanCache($type = '') |
| 98 | 98 | { |
| 99 | 99 | |
| 100 | - $query = 'DELETE FROM cache;'; |
|
| 101 | - $result = $this->cacheDB->exec($query); |
|
| 100 | + $query = 'DELETE FROM cache;'; |
|
| 101 | + $result = $this->cacheDB->exec($query); |
|
| 102 | 102 | |
| 103 | 103 | return $result; |
| 104 | 104 | |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | - * {@inheritDoc} |
|
| 42 | - */ |
|
| 41 | + * {@inheritDoc} |
|
| 42 | + */ |
|
| 43 | 43 | public function connect() |
| 44 | 44 | { |
| 45 | 45 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | public function cacheSettings(array &$config_vars) |
| 117 | 117 | { |
| 118 | - global $context, $txt; |
|
| 118 | + global $context, $txt; |
|
| 119 | 119 | |
| 120 | 120 | $config_vars[] = $txt['cache_sqlite_settings']; |
| 121 | 121 | $config_vars[] = array('cachedir_sqlite', $txt['cachedir_sqlite'], 'file', 'text', 36, 'cache_sqlite_cachedir'); |
@@ -139,13 +139,13 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function setCachedir($dir = null) |
| 141 | 141 | { |
| 142 | - global $cachedir_sqlite; |
|
| 142 | + global $cachedir_sqlite; |
|
| 143 | 143 | |
| 144 | - // If its invalid, use SMF's. |
|
| 145 | - if (is_null($dir) || !is_writable($dir)) |
|
| 146 | - $this->cachedir = $cachedir_sqlite; |
|
| 147 | - else |
|
| 148 | - $this->cachedir = $dir; |
|
| 144 | + // If its invalid, use SMF's. |
|
| 145 | + if (is_null($dir) || !is_writable($dir)) |
|
| 146 | + $this->cachedir = $cachedir_sqlite; |
|
| 147 | + else |
|
| 148 | + $this->cachedir = $dir; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | } |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * SQLite Cache API class |
@@ -61,8 +62,9 @@ discard block |
||
| 61 | 62 | { |
| 62 | 63 | $supported = class_exists("SQLite3") && is_writable($this->cachedir); |
| 63 | 64 | |
| 64 | - if ($test) |
|
| 65 | - return $supported; |
|
| 65 | + if ($test) { |
|
| 66 | + return $supported; |
|
| 67 | + } |
|
| 66 | 68 | |
| 67 | 69 | return parent::isSupported() && $supported; |
| 68 | 70 | } |
@@ -120,8 +122,9 @@ discard block |
||
| 120 | 122 | $config_vars[] = $txt['cache_sqlite_settings']; |
| 121 | 123 | $config_vars[] = array('cachedir_sqlite', $txt['cachedir_sqlite'], 'file', 'text', 36, 'cache_sqlite_cachedir'); |
| 122 | 124 | |
| 123 | - if (!isset($context['settings_post_javascript'])) |
|
| 124 | - $context['settings_post_javascript'] = ''; |
|
| 125 | + if (!isset($context['settings_post_javascript'])) { |
|
| 126 | + $context['settings_post_javascript'] = ''; |
|
| 127 | + } |
|
| 125 | 128 | |
| 126 | 129 | $context['settings_post_javascript'] .= ' |
| 127 | 130 | $("#cache_accelerator").change(function (e) { |
@@ -142,10 +145,11 @@ discard block |
||
| 142 | 145 | global $cachedir_sqlite; |
| 143 | 146 | |
| 144 | 147 | // If its invalid, use SMF's. |
| 145 | - if (is_null($dir) || !is_writable($dir)) |
|
| 146 | - $this->cachedir = $cachedir_sqlite; |
|
| 147 | - else |
|
| 148 | - $this->cachedir = $dir; |
|
| 148 | + if (is_null($dir) || !is_writable($dir)) { |
|
| 149 | + $this->cachedir = $cachedir_sqlite; |
|
| 150 | + } else { |
|
| 151 | + $this->cachedir = $dir; |
|
| 152 | + } |
|
| 149 | 153 | } |
| 150 | 154 | |
| 151 | 155 | } |