advanced-cache.php
8 years ago
deprecated-litespeed-cache-tags.class.php
8 years ago
litespeed-cache-activation.class.php
8 years ago
litespeed-cache-api.class.php
8 years ago
litespeed-cache-cdn.class.php
8 years ago
litespeed-cache-config.class.php
8 years ago
litespeed-cache-control.class.php
8 years ago
litespeed-cache-crawler.class.php
8 years ago
litespeed-cache-esi.class.php
8 years ago
litespeed-cache-gui.class.php
8 years ago
litespeed-cache-log.class.php
8 years ago
litespeed-cache-optimize.class.php
8 years ago
litespeed-cache-purge.class.php
8 years ago
litespeed-cache-router.class.php
8 years ago
litespeed-cache-tag.class.php
8 years ago
litespeed-cache-task.class.php
8 years ago
litespeed-cache-utility.class.php
8 years ago
litespeed-cache-vary.class.php
8 years ago
litespeed-cache.class.php
8 years ago
litespeed.autoload.php
8 years ago
litespeed-cache-api.class.php
516 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * The plugin API class. |
| 5 | * |
| 6 | * @since 1.1.3 |
| 7 | * @since 1.4 Moved into /inc |
| 8 | * @package LiteSpeed_Cache |
| 9 | * @subpackage LiteSpeed_Cache/inc |
| 10 | * @author LiteSpeed Technologies <info@litespeedtech.com> |
| 11 | */ |
| 12 | class LiteSpeed_Cache_API |
| 13 | { |
| 14 | const VERSION = LiteSpeed_Cache::PLUGIN_VERSION ; |
| 15 | |
| 16 | const TYPE_FEED = LiteSpeed_Cache_Tag::TYPE_FEED ; |
| 17 | const TYPE_FRONTPAGE = LiteSpeed_Cache_Tag::TYPE_FRONTPAGE ; |
| 18 | const TYPE_HOME = LiteSpeed_Cache_Tag::TYPE_HOME ; |
| 19 | const TYPE_PAGES = LiteSpeed_Cache_Tag::TYPE_PAGES ; |
| 20 | const TYPE_PAGES_WITH_RECENT_POSTS = LiteSpeed_Cache_Tag::TYPE_PAGES_WITH_RECENT_POSTS ; |
| 21 | const TYPE_ERROR = LiteSpeed_Cache_Tag::TYPE_ERROR ; |
| 22 | const TYPE_POST = LiteSpeed_Cache_Tag::TYPE_POST ; |
| 23 | const TYPE_ARCHIVE_POSTTYPE = LiteSpeed_Cache_Tag::TYPE_ARCHIVE_POSTTYPE ; |
| 24 | const TYPE_ARCHIVE_TERM = LiteSpeed_Cache_Tag::TYPE_ARCHIVE_TERM ; |
| 25 | const TYPE_AUTHOR = LiteSpeed_Cache_Tag::TYPE_AUTHOR ; |
| 26 | const TYPE_ARCHIVE_DATE = LiteSpeed_Cache_Tag::TYPE_ARCHIVE_DATE ; |
| 27 | const TYPE_BLOG = LiteSpeed_Cache_Tag::TYPE_BLOG ; |
| 28 | const TYPE_LOGIN = LiteSpeed_Cache_Tag::TYPE_LOGIN ; |
| 29 | const TYPE_URL = LiteSpeed_Cache_Tag::TYPE_URL ; |
| 30 | const TYPE_WIDGET = LiteSpeed_Cache_Tag::TYPE_WIDGET ; |
| 31 | |
| 32 | const PARAM_NAME = LiteSpeed_Cache_ESI::PARAM_NAME ; |
| 33 | const WIDGET_OPID_ESIENABLE = LiteSpeed_Cache_ESI::WIDGET_OPID_ESIENABLE ; |
| 34 | const WIDGET_OPID_TTL = LiteSpeed_Cache_ESI::WIDGET_OPID_TTL ; |
| 35 | |
| 36 | const VAL_OFF = LiteSpeed_Cache_Config::VAL_OFF ; |
| 37 | const VAL_ON = LiteSpeed_Cache_Config::VAL_ON ; |
| 38 | const VAL_ON2 = LiteSpeed_Cache_Config::VAL_ON2 ; |
| 39 | |
| 40 | /** |
| 41 | * Start a to-be-removed html wrapper |
| 42 | * |
| 43 | * @since 1.4 |
| 44 | * @access public |
| 45 | */ |
| 46 | public static function clean_wrapper_begin( $counter = false ) |
| 47 | { |
| 48 | return LiteSpeed_Cache_GUI::clean_wrapper_begin( $counter ) ; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * End a to-be-removed html wrapper |
| 53 | * |
| 54 | * @since 1.4 |
| 55 | * @access public |
| 56 | */ |
| 57 | public static function clean_wrapper_end( $counter = false ) |
| 58 | { |
| 59 | return LiteSpeed_Cache_GUI::clean_wrapper_end( $counter ) ; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Compare version |
| 64 | * |
| 65 | * @since 1.3 |
| 66 | * @access public |
| 67 | */ |
| 68 | public static function v( $v ) |
| 69 | { |
| 70 | return version_compare( self::VERSION, $v, '>=' ) ; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Set mobile |
| 75 | * |
| 76 | * @since 1.1.3 |
| 77 | * @access public |
| 78 | */ |
| 79 | public static function set_mobile() |
| 80 | { |
| 81 | LiteSpeed_Cache_Control::set_mobile() ; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Set cache status to not cacheable |
| 86 | * |
| 87 | * @since 1.1.3 |
| 88 | * @access public |
| 89 | */ |
| 90 | public static function set_cache_private() |
| 91 | { |
| 92 | LiteSpeed_Cache_Control::set_private() ; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Set cache status to no vary |
| 97 | * |
| 98 | * @since 1.2.0 |
| 99 | * @access public |
| 100 | */ |
| 101 | public static function set_cache_no_vary() |
| 102 | { |
| 103 | LiteSpeed_Cache_Control::set_no_vary() ; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Set cache status to not cacheable |
| 108 | * |
| 109 | * @since 1.1.3 |
| 110 | * @access public |
| 111 | */ |
| 112 | public static function set_nocache( $reason = false ) |
| 113 | { |
| 114 | LiteSpeed_Cache_Control::set_nocache( $reason ?: 'api' ) ; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Get current not cacheable status |
| 119 | * |
| 120 | * @since 1.1.3 |
| 121 | * @access public |
| 122 | */ |
| 123 | public static function not_cacheable() |
| 124 | { |
| 125 | return ! LiteSpeed_Cache_Control::is_cacheable() ; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Set cache control ttl to use frontpage ttl |
| 130 | * |
| 131 | * @since 1.1.3 |
| 132 | * @access public |
| 133 | */ |
| 134 | public static function set_use_frontpage_ttl() |
| 135 | { |
| 136 | LiteSpeed_Cache_Control::set_custom_ttl(self::config(LiteSpeed_Cache_Config::OPID_FRONT_PAGE_TTL)) ; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Set cache control ttl |
| 141 | * |
| 142 | * @since 1.1.5 |
| 143 | * @access public |
| 144 | */ |
| 145 | public static function set_ttl( $val ) |
| 146 | { |
| 147 | LiteSpeed_Cache_Control::set_custom_ttl( $val ) ; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Get current cache control ttl |
| 152 | * |
| 153 | * @since 1.1.5 |
| 154 | * @access public |
| 155 | */ |
| 156 | public static function get_ttl() |
| 157 | { |
| 158 | return LiteSpeed_Cache_Control::get_ttl() ; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Add public tag to cache |
| 163 | * |
| 164 | * @since 1.1.3 |
| 165 | * @access public |
| 166 | */ |
| 167 | public static function tag_add($tags) |
| 168 | { |
| 169 | LiteSpeed_Cache_Tag::add($tags) ; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Add public tag to cache |
| 174 | * |
| 175 | * @since 1.6.3 |
| 176 | * @access public |
| 177 | */ |
| 178 | public static function add_private( $tags ) |
| 179 | { |
| 180 | LiteSpeed_Cache_Tag::add_private( $tags ) ; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Add vary |
| 185 | * |
| 186 | * @since 1.1.3 |
| 187 | * @access public |
| 188 | */ |
| 189 | public static function vary_add($vary) |
| 190 | { |
| 191 | LiteSpeed_Cache_Vary::add($vary) ; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Purge all action |
| 196 | * |
| 197 | * @since 1.1.3 |
| 198 | * @access public |
| 199 | */ |
| 200 | public static function purge_all() |
| 201 | { |
| 202 | LiteSpeed_Cache_Purge::purge_all() ; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Purge all private |
| 207 | * |
| 208 | * @since 1.6.3 |
| 209 | * @access public |
| 210 | */ |
| 211 | public static function purge_private_all() |
| 212 | { |
| 213 | LiteSpeed_Cache_Purge::add_private( '*' ) ; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Purge private tag |
| 218 | * |
| 219 | * @since 1.6.3 |
| 220 | * @access public |
| 221 | */ |
| 222 | public static function purge_private( $tags ) |
| 223 | { |
| 224 | LiteSpeed_Cache_Purge::add_private( $tags ) ; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Purge single action |
| 229 | * |
| 230 | * @since 1.3 |
| 231 | * @access public |
| 232 | * @param int $pid The ID of a post |
| 233 | */ |
| 234 | public static function purge_post( $pid ) |
| 235 | { |
| 236 | LiteSpeed_Cache_Purge::purge_post( $pid ) ; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Add purge tags |
| 241 | * |
| 242 | * @since 1.1.3 |
| 243 | * @access public |
| 244 | */ |
| 245 | public static function purge($tags) |
| 246 | { |
| 247 | LiteSpeed_Cache_Purge::add($tags) ; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Build a switch div html snippet |
| 252 | * |
| 253 | * @since 1.1.3 |
| 254 | * @access public |
| 255 | * @param string $id |
| 256 | * @param boolean $return Return the html or echo it |
| 257 | */ |
| 258 | public static function build_switch( $id, $checked = null, $return = false ) |
| 259 | { |
| 260 | return LiteSpeed_Cache_Admin_Display::get_instance()->build_switch( $id, $checked, $return ) ; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Filter the value for checkbox via input and id (enabled/disabled) |
| 265 | * |
| 266 | * @since 1.1.6 |
| 267 | * @access public |
| 268 | * @param int $input The whole input array |
| 269 | * @param string $id The ID of the option |
| 270 | * @return bool Filtered value |
| 271 | */ |
| 272 | public static function parse_onoff( $input, $id ) |
| 273 | { |
| 274 | return LiteSpeed_Cache_Admin_Settings::parse_onoff( $input, $id ) ; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | /** |
| 279 | * Hook cacheable check to cache control |
| 280 | * |
| 281 | * @since 1.1.3 |
| 282 | * @access public |
| 283 | */ |
| 284 | public static function hook_control($hook) |
| 285 | { |
| 286 | add_action('litespeed_cache_api_control', $hook) ; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Hook tag appending to tag |
| 291 | * |
| 292 | * @since 1.1.3 |
| 293 | * @access public |
| 294 | */ |
| 295 | public static function hook_tag($hook) |
| 296 | { |
| 297 | add_action('litespeed_cache_api_tag', $hook) ; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Hook vary appending to vary |
| 302 | * |
| 303 | * NOTE: This will add vary to rewrite rule |
| 304 | * |
| 305 | * @since 1.1.3 |
| 306 | * @access public |
| 307 | */ |
| 308 | public static function hook_vary($hook) |
| 309 | { |
| 310 | add_action('litespeed_cache_api_vary', $hook) ; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Hook vary tags to vary finialization |
| 315 | * |
| 316 | * @since 1.7.2 |
| 317 | * @access public |
| 318 | */ |
| 319 | public static function hook_vary_finalize( $hook ) |
| 320 | { |
| 321 | add_filter( 'litespeed_vary', $hook ) ; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Hook purge tags appending to purge |
| 326 | * |
| 327 | * @since 1.1.3 |
| 328 | * @access public |
| 329 | */ |
| 330 | public static function hook_purge($hook) |
| 331 | { |
| 332 | add_action('litespeed_cache_api_purge', $hook) ; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Hook purge post action to purge |
| 337 | * |
| 338 | * @since 1.1.3 |
| 339 | * @access public |
| 340 | */ |
| 341 | public static function hook_purge_post($hook) |
| 342 | { |
| 343 | add_action('litespeed_cache_api_purge_post', $hook) ; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Hook not ESI template |
| 348 | * |
| 349 | * @since 1.1.3 |
| 350 | * @access public |
| 351 | */ |
| 352 | public static function hook_tpl_not_esi($hook) |
| 353 | { |
| 354 | add_action('litespeed_cache_is_not_esi_template', $hook) ; |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Hook ESI template block |
| 359 | * |
| 360 | * @since 1.1.3 |
| 361 | * @access public |
| 362 | */ |
| 363 | public static function hook_tpl_esi($block, $hook) |
| 364 | { |
| 365 | add_action('litespeed_cache_load_esi_block-' . $block, $hook) ; |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Hook ESI params |
| 370 | * |
| 371 | * @since 1.1.3 |
| 372 | * @access public |
| 373 | */ |
| 374 | public static function hook_esi_param($block, $hook) |
| 375 | { |
| 376 | add_filter('litespeed_cache_sub_esi_params-' . $block, $hook) ; |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Hook setting tab |
| 381 | * |
| 382 | * @since 1.1.3 |
| 383 | * @access public |
| 384 | */ |
| 385 | public static function hook_setting_tab($hook, $priority = 10, $args = 1) |
| 386 | { |
| 387 | add_filter('litespeed_cache_add_config_tab', $hook, $priority, $args) ; |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Hook setting saving |
| 392 | * |
| 393 | * @since 1.1.3 |
| 394 | * @access public |
| 395 | */ |
| 396 | public static function hook_setting_save($hook, $priority = 10, $args = 1) |
| 397 | { |
| 398 | add_filter('litespeed_cache_save_options', $hook, $priority, $args) ; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Hook widget default settings value |
| 403 | * |
| 404 | * @since 1.1.3 |
| 405 | * @access public |
| 406 | */ |
| 407 | public static function hook_widget_default_options($hook, $priority = 10, $args = 1) |
| 408 | { |
| 409 | add_filter('litespeed_cache_widget_default_options', $hook, $priority, $args) ; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Hook get options value |
| 414 | * |
| 415 | * @since 1.1.3 |
| 416 | * @access public |
| 417 | */ |
| 418 | public static function hook_get_options($hook) |
| 419 | { |
| 420 | add_filter('litespeed_cache_get_options', $hook) ; |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * Generate ESI block url |
| 425 | * |
| 426 | * @since 1.1.3 |
| 427 | * @access public |
| 428 | * @param string $control Cache control tag |
| 429 | */ |
| 430 | public static function esi_url( $block_id, $wrapper, $params = array(), $control = 'default', $silence = false ) |
| 431 | { |
| 432 | if ( $control === 'default' ) { |
| 433 | $control = 'private,no-vary' ; |
| 434 | } |
| 435 | return LiteSpeed_Cache_ESI::sub_esi_block( $block_id, $wrapper, $params, $control, $silence ) ; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Log debug info |
| 440 | * |
| 441 | * @since 1.1.3 |
| 442 | * @access public |
| 443 | */ |
| 444 | public static function debug( $info, $backtrace_limit = false ) |
| 445 | { |
| 446 | LiteSpeed_Cache_Log::debug( $info, $backtrace_limit ) ; |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Log debug info ( advanced mode ) |
| 451 | * |
| 452 | * @since 1.6.6.1 |
| 453 | * @access public |
| 454 | */ |
| 455 | public static function debug2( $info, $backtrace_limit = false ) |
| 456 | { |
| 457 | LiteSpeed_Cache_Log::debug2( $info, $backtrace_limit ) ; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Get ESI enable setting value |
| 462 | * |
| 463 | * @since 1.2.0 |
| 464 | * @access public |
| 465 | */ |
| 466 | public static function esi_enabled() |
| 467 | { |
| 468 | return LiteSpeed_Cache_Router::esi_enabled() ; |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * Get cache enable setting value |
| 473 | * |
| 474 | * @since 1.3 |
| 475 | * @access public |
| 476 | */ |
| 477 | public static function cache_enabled() |
| 478 | { |
| 479 | return defined( 'LITESPEED_ON' ) ; |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Get cfg setting value |
| 484 | * |
| 485 | * @since 1.1.3 |
| 486 | * @access public |
| 487 | */ |
| 488 | public static function config($id) |
| 489 | { |
| 490 | return LiteSpeed_Cache::config($id) ; |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * register 3rd party detect hooks |
| 495 | * |
| 496 | * @since 1.1.3 |
| 497 | * @access public |
| 498 | */ |
| 499 | public static function register($cls) |
| 500 | { |
| 501 | add_action('litespeed_cache_api_load_thirdparty', $cls . '::detect') ; |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Hook to litespeed init |
| 506 | * |
| 507 | * @since 1.6.6 |
| 508 | * @access public |
| 509 | */ |
| 510 | public static function hook_init( $hook ) |
| 511 | { |
| 512 | add_action('litespeed_init', $hook) ; |
| 513 | } |
| 514 | |
| 515 | } |
| 516 |