all repos — wp-ffpc @ 12c3ae4599acd345b4fa2eeed553727712aaaba6

files cleanup for 1.0

git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@684137 b8457f37-d9ea-0310-8a92-e5e31aec5664
cadeyrn cadeyrn@b8457f37-d9ea-0310-8a92-e5e31aec5664
Tue, 19 Mar 2013 10:19:25 +0000
commit

12c3ae4599acd345b4fa2eeed553727712aaaba6

parent

fa71c7a216e39221a8050d5dc35f99e9eb4d3599

4 files changed, 0 insertions(+), 723 deletions(-)

jump to
D advanced-cache.php

@@ -1,295 +0,0 @@

-<?php -/** - * part of WordPress plugin WP-FFPC - */ - -/* check for WP cache enabled*/ -if ( !WP_CACHE ) - return false; - -/* check for config */ -if (!isset($wp_ffpc_config)) - return false; - -/* check if config is network active or active for this very site */ -if (!empty ( $wp_ffpc_config['network'] ) ) - $wp_ffpc_config = $wp_ffpc_config['network']; -elseif ( !empty ( $wp_ffpc_config[ $_SERVER['HTTP_HOST' ] ] ) ) - $wp_ffpc_config = $wp_ffpc_config[ $_SERVER['HTTP_HOST' ] ]; -else - return false; - -/* request uri */ -$wp_ffpc_uri = $_SERVER['REQUEST_URI']; -/* query string */ -$wp_ffpc_qs = stripos($wp_ffpc_uri, '?'); - -/* no cache for uri with query strings, things usually go bad that way */ -if ($wp_ffpc_qs !== false) - return false; - -/* no cache for post request (comments, plugins and so on) */ -if ($_SERVER["REQUEST_METHOD"] == 'POST') - return false; - -/** - * Try to avoid enabling the cache if sessions are managed - * with request parameters and a session is active - */ -if (defined('SID') && SID != '') - return false; - -/* no cache for pages starting with /wp- like WP admin */ -if (stripos($wp_ffpc_uri, '/wp-') !== false) - return false; - -/* no cache for robots.txt */ -if ( stripos($wp_ffpc_uri, 'robots.txt') ) - return false; - -/* multisite files can be too large for memcached */ -if (function_exists('is_multisite') && is_multisite() && stripos($wp_ffpc_uri, '/files/') ) - return false; - - -/* no cache for logged in users */ -if (!$wp_ffpc_config['cache_loggedin']) { - foreach ($_COOKIE as $n=>$v) { - // test cookie makes to cache not work!!! - if ($n == 'wordpress_test_cookie') continue; - // wp 2.5 and wp 2.3 have different cookie prefix, skip cache if a post password cookie is present, also - if ( (substr($n, 0, 14) == 'wordpressuser_' || substr($n, 0, 10) == 'wordpress_' || substr($n, 0, 12) == 'wp-postpass_') && !$wp_ffpc_config['cache_loggedin'] ) { - return false; - } - } -} - -global $wp_ffpc_backend_status; -$wp_ffpc_backend_status = wp_ffpc_init( ); - -/* check alive status of backend */ -if ( !$wp_ffpc_backend_status ) - return false; - -/* use the full accessed URL string as key, same will be generated by nginx as well - we need a data and a meta key: data is string only with content, meta is not used in nginx */ -global $wp_ffpc_data_key_protocol; -$wp_ffpc_data_key_protocol = empty ( $_SERVER['HTTPS'] ) ? 'http://' : 'https://'; - -global $wp_ffpc_data_key; -$wp_ffpc_data_key = $wp_ffpc_config['prefix_data'] . $wp_ffpc_data_key_protocol . $_SERVER['HTTP_HOST'] . $wp_ffpc_uri; -global $wp_ffpc_meta_key; -$wp_ffpc_meta_key = $wp_ffpc_config['prefix_meta'] . $wp_ffpc_data_key_protocol . $_SERVER['HTTP_HOST'] . $wp_ffpc_uri; - -/* search for valid meta entry */ -global $wp_ffpc_meta; -$wp_ffpc_meta = wp_ffpc_get ( $wp_ffpc_meta_key ); - -/* meta is corrupted or empty */ -if ( !$wp_ffpc_meta ) { - wp_ffpc_start(); - return; -} - -/* search for valid data entry */ -global $wp_ffpc_data; -$uncompress = ( isset($wp_ffpc_meta['compressed']) ) ? $wp_ffpc_meta['compressed'] : false; -$wp_ffpc_data = wp_ffpc_get ( $wp_ffpc_data_key , $uncompress ); - -/* data is corrupted or empty */ -if ( !$wp_ffpc_data ) { - wp_ffpc_start(); - return; -} - -/* 404 status cache */ -if ($wp_ffpc_meta['status'] == 404) { - header("HTTP/1.1 404 Not Found"); - flush(); - die(); -} - -/* server redirect cache */ -if ($wp_ffpc_meta['redirect_location']) { - header('Location: ' . $wp_ffpc_meta['redirect_location']); - flush(); - die(); -} - -/* page is already cached on client side (chrome likes to do this, anyway, it's quite efficient) */ -if (array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER) && !empty($wp_ffpc_meta['lastmodified']) ) { - $if_modified_since = strtotime(preg_replace('/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"])); - /* check is cache is still valid */ - if ( $if_modified_since >= $wp_ffpc_meta['lastmodified'] ) { - header("HTTP/1.0 304 Not Modified"); - flush(); - die(); - } -} - -/* data found & correct, serve it */ -header('Content-Type: ' . $wp_ffpc_meta['mime']); -/* don't allow browser caching of page */ -header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0'); -header('Pragma: no-cache'); -/* expire at this very moment */ -header('Expires: ' . gmdate("D, d M Y H:i:s", time() ) . " GMT"); - -/* if shortlinks were set */ -if (!empty ( $wp_ffpc_meta['shortlink'] ) ) - header('Link:<'. $wp_ffpc_meta['shortlink'] .'>; rel=shortlink'); - -/* if last modifications were set (for posts & pages) */ -if ( !empty($wp_ffpc_meta['lastmodified']) ) - header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $wp_ffpc_meta['lastmodified'] ). " GMT"); - -/* only set when not multisite, fallback to HTTP HOST */ -$wp_ffpc_pingback_url = (empty( $wp_ffpc_config['url'] )) ? $_SERVER['HTTP_HOST'] : $wp_ffpc_config['url']; - -/* pingback additional header */ -if ($wp_ffpc_config['pingback_status']) - header('X-Pingback: ' . $wp_ffpc_pingback_url . '/xmlrpc.php' ); - -/* for debugging */ -if ($wp_ffpc_config['debug']) - header('X-Cache-Engine: WP-FFPC with ' . $wp_ffpc_config['cache_type']); - -/* HTML data */ -echo $wp_ffpc_data; -flush(); -die(); - -/** - * FUNCTIONS - */ - -/** - * starts caching - * - */ -function wp_ffpc_start( ) { - ob_start('wp_ffpc_callback'); -} - -/** - * write cache function, called when page generation ended - */ -function wp_ffpc_callback($buffer) { - global $wp_ffpc_config; - global $wp_ffpc_data; - global $wp_ffpc_meta; - global $wp_ffpc_redirect; - global $wp_ffpc_meta_key; - global $wp_ffpc_data_key; - - /* no is_home = error */ - if (!function_exists('is_home')) - return $buffer; - - /* no <body> close tag = not HTML, don't cache */ - if (stripos($buffer, '</body>') === false) - return $buffer; - - /* reset meta to solve conflicts */ - $wp_ffpc_meta = array(); - - /* WP is sending a redirect */ - if ($wp_ffpc_redirect) { - $wp_ffpc_meta['redirect_location'] = $wp_ffpc_redirect; - wp_ffpc_write(); - return $buffer; - } - - /* trim unneeded whitespace from beginning / ending of buffer */ - $buffer = trim($buffer); - - /* Can be a trackback or other things without a body. - We do not cache them, WP needs to get those calls. */ - if (strlen($buffer) == 0) - return ''; - - if ( is_home() ) - $wp_ffpc_meta['type'] = 'home'; - elseif (is_feed() ) - $wp_ffpc_meta['type'] = 'feed'; - elseif ( is_archive() ) - $wp_ffpc_meta['type'] = 'archive'; - elseif ( is_single() ) - $wp_ffpc_meta['type'] = 'single'; - else if ( is_page() ) - $wp_ffpc_meta['type'] = 'page'; - else - $wp_ffpc_meta['type'] = 'unknown'; - - /* check if caching is disabled for page type */ - $nocache_key = 'nocache_'. $wp_ffpc_meta['type']; - - /* don't cache if prevented by rule, also, log it */ - if ( $wp_ffpc_config[$nocache_key] == 1 ) { - wp_ffpc_log ( "not caching, prevented by settings for no-cache: " . $nocache_key ); - return $buffer; - } - - if ( is_404() ) - $wp_ffpc_meta['status'] = 404; - - /* feed is xml, all others forced to be HTML */ - if ( is_feed() ) - $wp_ffpc_meta['mime'] = 'text/xml;charset='; - else - $wp_ffpc_meta['mime'] = 'text/html;charset='; - - /* set mimetype */ - $wp_ffpc_meta['mime'] = $wp_ffpc_meta['mime'] . $wp_ffpc_config['charset']; - - /* get shortlink, if possible */ - if (function_exists('wp_get_shortlink')) - { - $shortlink = wp_get_shortlink( ); - if (!empty ( $shortlink ) ) - $wp_ffpc_meta['shortlink'] = $shortlink; - } - - /* try if post is available - if made with archieve, last listed post can make this go bad - */ - global $post; - if ( !empty($post) && ( $wp_ffpc_meta['type'] == 'single' || $wp_ffpc_meta['type'] == 'page' ) && !empty ( $post->post_modified_gmt ) ) - { - /* get last modification data */ - $wp_ffpc_meta['lastmodified'] = strtotime ( $post->post_modified_gmt ); - } - - /* APC compression */ - $compress = ( ($wp_ffpc_config['cache_type'] == 'apc') && $wp_ffpc_config['apc_compress'] ) ? true : false; - $wp_ffpc_meta['compressed'] = $compress; - - /* sync all http and https requests if enabled */ - if ( !empty($wp_ffpc_config['sync_protocols']) ) - { - if ( !empty( $_SERVER['HTTPS'] ) ) - { - $sync_from = 'http://' . $_SERVER['SERVER_NAME']; - $sync_to = 'https://' . $_SERVER['SERVER_NAME']; - } - else - { - $sync_from = 'https://' . $_SERVER['SERVER_NAME']; - $sync_to = 'http://' . $_SERVER['SERVER_NAME']; - } - - $buffer = str_replace ( $sync_from, $sync_to, $buffer ); - } - - /* set meta */ - wp_ffpc_set ( $wp_ffpc_meta_key, $wp_ffpc_meta ); - wp_ffpc_set ( $wp_ffpc_data_key, $buffer, $compress ); - - /* vital for nginx, make no problem at other places */ - header("HTTP/1.1 200 OK"); - - /* echoes HTML out */ - return $buffer; -} - -?>
D nginx-sample.conf

@@ -1,52 +0,0 @@

-http { - ... - upstream memcached-servers { -MEMCACHED_SERVERS - } - ... - server { - ... - - # try to get result from memcached - location @memcached { - default_type text/html; - set $memcached_key DATAPREFIX$scheme://$host$request_uri; - set $memcached_request 1; - - # exceptions - # avoid cache serve of POST requests - if ($request_method = POST ) { - set $memcached_request 0; - } - # avoid cache serve of wp-admin-like pages, starting with "wp-" - if ( $uri ~ "/wp-" ) { - set $memcached_request 0; - } - # avoid cache for logged in users - if ($http_cookie ~* "comment_author_|wordpressuser_|wp-postpass_" ) { - set $memcached_request 0; - } - - if ( $memcached_request = 1) { - memcached_pass memcached-servers; - error_page 404 = @rewrites; - } - - if ( $memcached_request = 0) { - rewrite ^ /index.php$request_uri last; - } - } - - ## rewrite rules - location @rewrites { - rewrite ^ /index.php$request_uri last; - } - - location / { - try_files $uri $uri/ @memcached; - } - - ... - } -} -...
D wp-ffpc-common.php

@@ -1,302 +0,0 @@

-<?php -/** - * part of WordPress plugin WP-FFPC - */ - -/** - * function to test if selected backend is available & alive - */ -global $wp_ffpc_backend; -global $wp_nmc_redirect; - -/* wp ffpc prefic */ -if (!defined('WP_FFPC_PARAM')) - define ( 'WP_FFPC_PARAM' , 'wp-ffpc' ); -/* log level */ -define ('WP_FFPC_LOG_LEVEL' , LOG_WARNING ); -/* define log ending message */ -define ('WP_FFPC_LOG_TYPE_MSG' , '; cache type: '. $wp_ffpc_config['cache_type'] ); - - -/* safety rules if file has been already included */ -if ( function_exists('wp_ffpc_init') || function_exists('wp_ffpc_clear') || function_exists('wp_ffpc_set') || function_exists('wp_ffpc_get') ) - return false; - -/** - * init and backend alive check function - * - * @param $type [optional] if set, alive will be tested against this - * if false, backend will be globally initiated - * when set, backend will not become global, just tested if alive - */ -function wp_ffpc_init( $wp_ffpc_config ) { - global $wp_ffpc_backend; - $wp_ffpc_backend_status = false; - - if ( empty ( $wp_ffpc_config )) - global $wp_ffpc_config; - - /* verify selected storage is available */ - switch ( $wp_ffpc_config['cache_type'] ) - { - /* in case of apc */ - case 'apc': - /* verify apc functions exist, apc ext is loaded */ - if (!function_exists('apc_sma_info')) - return false; - /* verify apc is working */ - if ( !apc_sma_info() ) - return false; - $wp_ffpc_backend_status = true; - break; - - /* in case of Memcache */ - case 'memcache': - /* Memcache class does not exist, Memcache extension is not available */ - if (!class_exists('Memcache')) - return false; - if ( $wp_ffpc_backend == NULL ) - $wp_ffpc_backend = new Memcache(); - - foreach ( $wp_ffpc_config['servers'] as $server_id => $server ) { - $wp_ffpc_backend_status[$server_id] = $wp_ffpc_backend->connect( $server['host'] , $server['port'] ); - - $wp_ffpc_config['persistent'] = ( $wp_ffpc_config['persistent'] == '1' ) ? true : false; - if ( $wp_ffpc_backend_status[$server_id] ) - { - $wp_ffpc_backend_status[$server_id] = true; - $wp_ffpc_backend->addServer( $server['host'] , $server['port'], $wp_ffpc_config['persistent'] ); - wp_ffpc_log ( "server " . $server_id . " added, persistent mode: " . $wp_ffpc_config['persistent'] ); - } - } - return $wp_ffpc_backend_status; - break; - - /* in case of Memcached */ - case 'memcached': - /* Memcached class does not exist, Memcached extension is not available */ - if (!class_exists('Memcached')) - return false; - /* check is there's no backend connection yet */ - if ( $wp_ffpc_backend == NULL ) - { - /* persistent backend needs an identifier */ - if ( $wp_ffpc_config['persistent'] == '1' ) - $wp_ffpc_backend = new Memcached( WP_FFPC_PARAM ); - else - $wp_ffpc_backend = new Memcached(); - - /* use binary and not compressed format, good for nginx and still fast */ - $wp_ffpc_backend->setOption( Memcached::OPT_COMPRESSION , false ); - $wp_ffpc_backend->setOption( Memcached::OPT_BINARY_PROTOCOL , true ); - } - - /* check if we already have list of servers, only add server if it's not already connected */ - $wp_ffpc_serverlist = $wp_ffpc_backend->getServerList(); - - /* create check array if backend servers are already connected */ - if ( !empty ( $wp_ffpc_serverlist ) ) - foreach ( $wp_ffpc_serverlist as $server ) - $wp_ffpc_serverlist_[ $server['host'] . ":" . $server['port'] ] = true; - - /* reset all configured server status to unknown */ - foreach ( $wp_ffpc_config['servers'] as $server_id => $server ) - $wp_ffpc_backend_status[$server_id] = -1; - - /* if there's no server to add, don't add them */ - if ( empty ( $wp_ffpc_config['servers'] ) ) - { - wp_ffpc_log ( "not adding empty set of servers, please check your settings!" ); - } - else - { - foreach ( $wp_ffpc_config['servers'] as $server_id => $server ) { - if (!@array_key_exists($server_id , $wp_ffpc_serverlist_ )) - { - $wp_ffpc_backend->addServer( $server['host'], $server['port'] ); - wp_ffpc_log ( "server ". $server_id ." added, persistent mode: " . $wp_ffpc_config['persistent'] ); - } - } - } - - /* server status will be calculated by getting server stats */ - $wp_ffpc_backend_report = $wp_ffpc_backend->getStats(); - foreach ( $wp_ffpc_backend_report as $server_id => $server ) { - $wp_ffpc_backend_status[$server_id] = false; - /* if server uptime is not empty, it's most probably up & running */ - if ( !empty($server['uptime']) ) - $wp_ffpc_backend_status[$server_id] = true; - } - - break; - - /* cache type is invalid */ - default: - break; - } - - return ( empty ( $wp_ffpc_backend_status ) ? false : $wp_ffpc_backend_status ); -} - -/** - * clear cache element or flush cache - * - * @param $post_id [optional] : if registered with invalidation hook, post_id will be passed - */ -function wp_ffpc_clear ( $post_id = false ) { - global $wp_ffpc_config; - global $post; - - $post_only = ( $post_id === 'system_flush' ) ? false : $wp_ffpc_config['invalidation_method']; - - /* post invalidation enabled */ - if ( $post_only ) - { - $path = substr ( get_permalink($post_id) , 7 ); - if (empty($path)) - return false; - $wp_ffpc_data_key_protocol = empty ( $_SERVER['HTTPS'] ) ? 'http://' : 'https://'; - $meta = $wp_ffpc_config['prefix-meta'] . $wp_ffpc_data_key_protocol . $path; - $data = $wp_ffpc_config['prefix-data'] . $wp_ffpc_data_key_protocol . $path; - } - - switch ($wp_ffpc_config['cache_type']) - { - /* in case of apc */ - case 'apc': - if ( $post_only ) - { - apc_delete ( $meta ); - wp_ffpc_log ( ' clearing key: "'. $meta . '"' ); - apc_delete ( $data ); - wp_ffpc_log ( ' clearing key: "'. $data . '"' ); - } - else - { - apc_clear_cache('user'); - wp_ffpc_log ( ' flushing user cache' ); - apc_clear_cache('system'); - wp_ffpc_log ( ' flushing system cache' ); - } - break; - - /* in case of Memcache */ - case 'memcache': - case 'memcached': - global $wp_ffpc_backend; - if ( $post_only ) - { - $wp_ffpc_backend->delete( $meta ); - wp_ffpc_log ( ' clearing key: "'. $meta . '"' ); - $wp_ffpc_backend->delete( $data ); - wp_ffpc_log ( ' clearing key: "'. $data . '"' ); - } - else - { - $wp_ffpc_backend->flush(); - wp_ffpc_log ( ' flushing cache' ); - } - break; - - /* cache type is invalid */ - default: - return false; - } - return true; -} - -/** - * sets a key-value pair in backend - * - * @param &$key store key, passed by reference for speed - * @param &$data store value, passed by reference for speed - * - */ -function wp_ffpc_set ( &$key, &$data, $compress = false ) { - global $wp_ffpc_config; - global $wp_ffpc_backend; - - $exp = $wp_ffpc_config['user_logged_in'] ? $wp_ffpc_config['expire_member'] : $wp_ffpc_config['expire_visitor']; - - /* syslog */ - if ($wp_ffpc_config['syslog']) - { - if ( @is_array( $data ) ) - $string = serialize($data); - else //if ( @is_string( $data ) || @ ) - $string = $data; - - $size = @strlen($string); - wp_ffpc_log ( ' set key: "'. $key . '", size: '. $size . ' byte(s)' ); - } - - switch ($wp_ffpc_config['cache_type']) - { - case 'apc': - /* use apc_store to overwrite data is existed */ - if ( $compress ) - $data = gzdeflate ( $data , 1 ); - return apc_store( $key , $data , $exp ); - break; - case 'memcache': - if ( $wp_ffpc_backend != NULL ) - /* false to disable compression, vital for nginx */ - $wp_ffpc_backend->set ( $key, $data , false, $exp ); - else - return false; - break; - case 'memcached': - if ( $wp_ffpc_backend != NULL ) - $wp_ffpc_backend->set ( $key, $data , $exp ); - else - return false; - break; - } -} - -/** - * gets cached element by key - * - * @param &$key: key of needed cache element - * - */ -function wp_ffpc_get( &$key , $uncompress = false ) { - global $wp_ffpc_config; - global $wp_ffpc_backend; - - /* syslog */ - wp_ffpc_log ( ' get key: "'.$key . '"' ); - - switch ($wp_ffpc_config['cache_type']) - { - case 'apc': - $value = apc_fetch($key); - if ( $uncompress ) - $value = gzinflate ( $value ); - return $value; - case 'memcache': - case 'memcached': - if ( $wp_ffpc_backend != NULL ) - return $wp_ffpc_backend->get($key); - else - return false; - default: - return false; - } -} - - -/** - * handles log messages - * - * @param $string log messagr - */ -function wp_ffpc_log ( $string ) { - global $wp_ffpc_config; - - /* syslog */ - if ($wp_ffpc_config['syslog'] && function_exists('syslog') ) - syslog( WP_FFPC_LOG_LEVEL , WP_FFPC_PARAM .": " . $string . WP_FFPC_LOG_TYPE_MSG ); - -} -?>
D wp-ffpc.admin.css

@@ -1,74 +0,0 @@

-.wp-ffpc-panel dt { - margin-top: 2em; - font-weight:bold; -} - -.wp-ffpc-panel fieldset { - display:block; - margin: 0; - padding: 0 1em 0 1em; - border: 1px solid #ccc; -} - -.wp-ffpc-panel legend { - display: none; - visibility: hidden; -} - -.wp-ffpc-panel .default { - display:block; - padding-left: 1em; - font-size:90%; - color:#666; -} - -.wp-ffpc-panel .description { - display:block; -} - -.wp-ffpc-panel .tabs { - padding:0; - margin: 0; - list-style-type: none; -} - -.wp-ffpc-panel .tabs li { - border-style: solid; - border-width: 1px 1px 1px 1px; - border-color: #ccc; - border-bottom-color: #ccc; - line-height: 120%; - display: inline-block; - padding: 0.5em 2em 0.5em 2em; - text-decoration: none; - margin-bottom: -1px; - -webkit-border-top-left-radius: 3px; - -webkit-border-top-right-radius: 3px; - border-top-left-radius: 3px; - border-top-right-radius: 3px; - background: #f1f1f1; - background-image: -webkit-gradient(linear,left bottom,left top,from(#ececec),to(#f9f9f9)); - background-image: -webkit-linear-gradient(bottom,#ececec,#f9f9f9); - background-image: -moz-linear-gradient(bottom,#ececec,#f9f9f9); - background-image: -o-linear-gradient(bottom,#ececec,#f9f9f9); - background-image: linear-gradient(to top,#ececec,#f9f9f9); -} - -.wp-ffpc-panel .tabs li a { - outline: none; - text-decoration: none; - font-size: 120%; -} - -.wp-ffpc-panel .tabs li.ui-state-active { - background: #fff; - border-bottom-color: #fff; -} - -.error-msg { - color: #990000; -} - -.ok-msg { - color: #009900; -}