Yoshi2889 /
SMF2.1
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Simple Machines Forum (SMF) |
||
| 5 | * |
||
| 6 | * @package SMF |
||
| 7 | * @author Simple Machines http://www.simplemachines.org |
||
| 8 | * @copyright 2017 Simple Machines and individual contributors |
||
| 9 | * @license http://www.simplemachines.org/about/smf/license.php BSD |
||
| 10 | * |
||
| 11 | * @version 2.1 Beta 4 |
||
| 12 | */ |
||
| 13 | |||
| 14 | if (!defined('SMF')) |
||
| 15 | die('Hacking attempt...'); |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Interface cache_api_interface |
||
| 19 | */ |
||
| 20 | interface cache_api_interface |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Checks whether we can use the cache method performed by this API. |
||
| 24 | * |
||
| 25 | * @access public |
||
| 26 | * @param boolean $test Test if this is supported or enabled. |
||
| 27 | * @return boolean Whether or not the cache is supported |
||
| 28 | */ |
||
| 29 | public function isSupported($test = false); |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Connects to the cache method. This defines our $key. If this fails, we return false, otherwise we return true. |
||
| 33 | * |
||
| 34 | * @access public |
||
| 35 | * @return boolean Whether or not the cache method was connected to. |
||
| 36 | */ |
||
| 37 | public function connect(); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Overrides the default prefix. If left alone, this will use the default key defined in the class. |
||
| 41 | * |
||
| 42 | * @access public |
||
| 43 | * @param string $key The key to use |
||
| 44 | * @return boolean If this was successful or not. |
||
| 45 | */ |
||
| 46 | public function setPrefix($key = ''); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Gets the prefix as defined from set or the default. |
||
| 50 | * |
||
| 51 | * @access public |
||
| 52 | * @return string the value of $key. |
||
| 53 | */ |
||
| 54 | public function getPrefix(); |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Sets a default Time To Live, if this isn't specified we let the class define it. |
||
| 58 | * |
||
| 59 | * @access public |
||
| 60 | * @param int $ttl The default TTL |
||
| 61 | * @return boolean If this was successful or not. |
||
| 62 | */ |
||
| 63 | public function setDefaultTTL($ttl = 120); |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Gets the TTL as defined from set or the default. |
||
| 67 | * |
||
| 68 | * @access public |
||
| 69 | * @return string the value of $ttl. |
||
| 70 | */ |
||
| 71 | public function getDefaultTTL(); |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Gets data from the cache. |
||
| 75 | * |
||
| 76 | * @access public |
||
| 77 | * @param string $key The key to use, the prefix is applied to the key name. |
||
| 78 | * @param string $ttl Overrides the default TTL. |
||
| 79 | * @return mixed The result from the cache, if there is no data or it is invalid, we return null. |
||
| 80 | */ |
||
| 81 | public function getData($key, $ttl = null); |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Saves to data the cache. |
||
| 85 | * |
||
| 86 | * @access public |
||
| 87 | * @param string $key The key to use, the prefix is applied to the key name. |
||
| 88 | * @param mixed $value The data we wish to save. |
||
| 89 | * @param string $ttl Overrides the default TTL. |
||
| 90 | * @return bool Whether or not we could save this to the cache. |
||
| 91 | */ |
||
| 92 | public function putData($key, $value, $ttl = null); |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Clean out the cache. |
||
| 96 | * |
||
| 97 | * @param string $type If supported, the type of cache to clear, blank/data or user. |
||
| 98 | * @return bool Whether or not we could clean the cache. |
||
| 99 | */ |
||
| 100 | public function cleanCache($type = ''); |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Invalidate all cached data. |
||
| 104 | * |
||
| 105 | * @return bool Whether or not we could invalidate the cache. |
||
| 106 | */ |
||
| 107 | public function invalidateCache(); |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Closes connections to the cache method. |
||
| 111 | * |
||
| 112 | * @access public |
||
| 113 | * @return bool Whether or not we could close connections. |
||
| 114 | */ |
||
| 115 | public function quit(); |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Specify custom settings that the cache API supports. |
||
| 119 | * |
||
| 120 | * @access public |
||
| 121 | * @param array $config_vars Additional config_vars, see ManageSettings.php for usage. |
||
| 122 | * @return void No return is needed. |
||
| 123 | */ |
||
| 124 | public function cacheSettings(array &$config_vars); |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Gets the latest version of SMF this is compatible with. |
||
| 128 | * |
||
| 129 | * @access public |
||
| 130 | * @return string the value of $key. |
||
| 131 | */ |
||
| 132 | public function getCompatibleVersion(); |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Gets the min version that we support. |
||
| 136 | * |
||
| 137 | * @access public |
||
| 138 | * @return string the value of $key. |
||
| 139 | */ |
||
| 140 | public function getMiniumnVersion(); |
||
| 141 | } |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Class cache_api |
||
| 145 | */ |
||
| 146 | abstract class cache_api implements cache_api_interface |
||
| 147 | { |
||
| 148 | /** |
||
| 149 | * @var string The last version of SMF that this was tested on. Helps protect against API changes. |
||
| 150 | */ |
||
| 151 | protected $version_compatible = 'SMF 2.1 Beta 4'; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var string The minimum SMF version that this will work with |
||
| 155 | */ |
||
| 156 | protected $min_smf_version = 'SMF 2.1 Beta 4'; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var string The prefix for all keys. |
||
| 160 | */ |
||
| 161 | protected $prefix = ''; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var int The default TTL. |
||
| 165 | */ |
||
| 166 | protected $ttl = 120; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Does basic setup of a cache method when we create the object but before we call connect. |
||
| 170 | * |
||
| 171 | * @access public |
||
| 172 | * @return void No return is needed. |
||
| 173 | */ |
||
| 174 | public function __construct() |
||
| 175 | { |
||
| 176 | $this->setPrefix(''); |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * {@inheritDoc} |
||
| 181 | */ |
||
| 182 | public function isSupported($test = false) |
||
| 183 | { |
||
| 184 | global $cache_enable; |
||
| 185 | |||
| 186 | if ($test) |
||
| 187 | return true; |
||
| 188 | return !empty($cache_enable); |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * {@inheritDoc} |
||
| 193 | */ |
||
| 194 | public function connect() |
||
| 195 | { |
||
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * {@inheritDoc} |
||
| 200 | */ |
||
| 201 | public function setPrefix($prefix = '') |
||
| 202 | { |
||
| 203 | global $boardurl, $cachedir; |
||
| 204 | |||
| 205 | // Set the default if no prefix was specified. |
||
| 206 | if (empty($prefix)) |
||
| 207 | $this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-'; |
||
| 208 | else |
||
| 209 | $this->prefix = $prefix; |
||
| 210 | |||
| 211 | return true; |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * {@inheritDoc} |
||
| 216 | */ |
||
| 217 | public function getPrefix() |
||
| 218 | { |
||
| 219 | return $this->prefix; |
||
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
| 223 | * {@inheritDoc} |
||
| 224 | */ |
||
| 225 | public function setDefaultTTL($ttl = 120) |
||
| 226 | { |
||
| 227 | $this->ttl = $ttl; |
||
| 228 | |||
| 229 | return true; |
||
| 230 | } |
||
| 231 | |||
| 232 | /** |
||
| 233 | * {@inheritDoc} |
||
| 234 | */ |
||
| 235 | public function getDefaultTTL() |
||
| 236 | { |
||
| 237 | return $this->ttl; |
||
| 238 | } |
||
| 239 | |||
| 240 | /** |
||
| 241 | * {@inheritDoc} |
||
| 242 | */ |
||
| 243 | public function getData($key, $ttl = null) |
||
| 244 | { |
||
| 245 | } |
||
| 246 | |||
| 247 | /** |
||
| 248 | * {@inheritDoc} |
||
| 249 | */ |
||
| 250 | public function putData($key, $value, $ttl = null) |
||
| 251 | { |
||
| 252 | } |
||
| 253 | |||
| 254 | /** |
||
| 255 | * {@inheritDoc} |
||
| 256 | */ |
||
| 257 | public function cleanCache($type = '') |
||
| 258 | { |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Invalidate all cached data. |
||
| 263 | * |
||
| 264 | * @return bool Whether or not we could invalidate the cache. |
||
| 265 | */ |
||
| 266 | public function invalidateCache() |
||
| 267 | { |
||
| 268 | global $cachedir; |
||
| 269 | |||
| 270 | // Invalidate cache, to be sure! |
||
| 271 | // ... as long as index.php can be modified, anyway. |
||
| 272 | if (is_writable($cachedir . '/' . 'index.php')) |
||
| 273 | @touch($cachedir . '/' . 'index.php'); |
||
|
0 ignored issues
–
show
|
|||
| 274 | |||
| 275 | return true; |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * {@inheritDoc} |
||
| 280 | */ |
||
| 281 | public function quit() |
||
| 282 | { |
||
| 283 | } |
||
| 284 | |||
| 285 | /** |
||
| 286 | * {@inheritDoc} |
||
| 287 | */ |
||
| 288 | public function cacheSettings(array &$config_vars) |
||
| 289 | { |
||
| 290 | } |
||
| 291 | |||
| 292 | /** |
||
| 293 | * {@inheritDoc} |
||
| 294 | */ |
||
| 295 | public function getCompatibleVersion() |
||
| 296 | { |
||
| 297 | return $this->version_compatible; |
||
| 298 | } |
||
| 299 | |||
| 300 | /** |
||
| 301 | * {@inheritDoc} |
||
| 302 | */ |
||
| 303 | public function getMiniumnVersion() |
||
| 304 | { |
||
| 305 | return $this->min_smf_version; |
||
| 306 | } |
||
| 307 | } |
||
| 308 | |||
| 309 | ?> |
If you suppress an error, we recommend checking for the error condition explicitly: