version 0.6.1

git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/tags/0.6.1@677998 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
cadeyrn 2013-03-08 11:19:34 +00:00
parent 35fca7f41a
commit 6d7e23401c
5 changed files with 346 additions and 120 deletions

View file

@ -11,6 +11,14 @@ if ( !WP_CACHE )
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 */
@ -216,6 +224,7 @@ function wp_ffpc_callback($buffer) {
/* 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;

View file

@ -1,142 +1,161 @@
=== WP-FFPC ===
Contributors: cadeyrn
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC
Tags: cache, APC, memcached, full page cache
Tags: cache, APC, memcache, memcached, page cache, full page cache, nginx
Requires at least: 3.0
Tested up to: 3.5.1
Stable tag: 0.4.3
Stable tag: 0.6.1
Fast Full Page Cache, backend can be memcached or APC
Store WordPress pages in memcached and serve them with nginx - unbeatable speed!
== Description ==
WP-FFPC is a full page cache plugin for WordPress. It can use APC or a memcached server as backend.
The naming stands for Fast Full Page Cache.
PHP has two extension for communication with a memcached server, named Memcache and Memcached. The plugin can utilize both, however, the recommended is memcached.
WP-FFPC is a full page cache plugin for WordPress. Supports memcached server or APC as backend and both widely available PHP memcached modules, Memcache and Memcached as well.
= Features: =
* exclude possibility of home, feeds, archieves, pages, singles
* exclude possibilities: of home, feeds, archieves, pages, singles
* possibility to enable caching for logged-in users
* use APC or memcached as backend
* APC or memcached server storage
* 404 caching
* redirects caching
* Last Modified HTTP header compatibility with 304 responses
* shortlink HTTP header preservation
* pingback HTTP header preservation(1)
* fallback to no caching if any error or problem occurs
* syslog & debug settings available
* syslog & debug settings for troubleshooting
* supports multiple memcached backends
* Wordpress Network compatible(2)
* Wordpress Network compatible (2)
* nginx compatible(3)
(1) pingback hostname will always be generated from the accessed domain, otherwise speed would get highly compromised
(2) If enabled as network-wide plugin in a WordPress Network, the configuration will only be available for network admins at the network admin panel, will be system-wide and will be applied for every blog.
(2) Plugin is capable of either Network wide or per site settings, meaning if not network-wide enabled, settings could vary from site to site, plugin could be turned off and on without interfering other sites.
(3) nginx compatility means that if used with PHP Memcache or PHP Memcached extension, the created memcached entries can be read and served directly from nginx, making the cache insanely fast.
(3) nginx compatility means that if used with PHP Memcache or PHP Memcached extension, the created memcached entries can be read and served directly from nginx.
If used with APC, this feature is not available (no APC module for nginx).
Short nginx example configuration is generated on the plugin settings page, under `nginx` tab.
NOTE: some features ( most of additional HTTP headers for example ) will not be available with this solution! ( yet )
Short nginx example configuration is generated on the plugin settings page, under `nginx` tab according to the settings of the plugin.
NOTE: some features ( most of additional HTTP headers for example, like pingback, shortlink, etc. ) will not be available with this solution! ( yet )
Parts are based on [Hyper Cache](http://wordpress.org/extend/plugins/hyper-cache "Hyper Cache") plugin by Satollo (info@satollo.net).
== Installation ==
1. Upload contents of `wp-ffpc.zip` to the `/wp-content/plugins/` directory
2. Enable WordPress cache by adding `define('WP_CACHE',true);` in wp-config.php
3. Activate the plugin through the `Plugins` menu in WordPress (please use network wide activation if used in a WordPress Network)
4. Fine tune the settings in `Settings` -> `wp-ffpc` menu in WordPress.
For WordPress Network, please visit the Network Admin panel, the options will be available under Network Admin Settings page, in WP-FFPC menu entry.
3. Activate the plugin through the `Plugins` menu in WordPress ( site or Network wide )
4. Check the settings in `Settings` ( site or Network Admin, depending on activation wideness ) -> `WP-FFPC` menu in WordPress.
5. Save the settings. THIS STEP IS MANDATORY: without saving the settings, there will be no activated caching!
== Frequently Asked Questions ==
= How to install memcache PHP extension? =
On most of the distributions, php5-memcached or php5-mecache is available as package.
On most of the distributions, php5-memcached or php5-memcache is available as package.
You can use PECL alternatively: `pecl install memcached`.
It's recommended to use memcached.
It's recommended to use Memcached instead of Memcache.
= How to use the plugin on Amazon Linux? =
You have to remove the default yum package, named `php-pecl-memcache` and install `Memcache` or `Memcached` through PECL.
== Changelog ==
= 0.5 =
2013.03.04
= 0.6.1 =
*2013.03.08*
* refactored & corrected backend status check for memcached driver
= 0.6 =
*2013.03.08*
* true WordPress Network support:
* if enabled network-wide, settings will be the same for every site
* if enabled only per site settings could vary from site to site and cache could be active or disabled on a per site basis without interfering other sites
* delete options button to help solving problems
= 0.5.1 =
*2013.03.07*
* settings link for plugins page
* readme cleanup
* setting link URL repair & cleanup
= 0.5 =
*2013.03.06*
WARNING, MAJOR CHANGES!
* long-running %3C really fixed ( version 0.4.3 was dead end ) by the help of Mark Costlow <cheeks@swcp.com>
* UI cleanup, introducing tabbed interface
* default values bug ( causing %3C bug ) really fixed by the help of Mark Costlow <cheeks@swcp.com>
* UI cleanup, new tabbed layout
* WP-FFPC options moved from global menu to under Settings in both Site and Network Admin interfaces
* added 'persistent' checkbox for memcached connections
* added support for multiple memcached servers, feature request from ivan.buttinoni ( ivanbuttinoni @ WordPress.org forum )
* case-sensitive string checks replaced with case-insensitives, contribution of Mark Costlow <cheeks@swcp.com>
* refactored settings saving mechanism
* additional syslog informations
* additional comments on the code
* lots of minor fixes and code cleanup
* donation link on the top
= 0.4.3 =
2013.03.03
*2013.03.03*
* long-running %3C bug fixed by the help of Mark Costlow <cheeks@swcp.com>, many thanks for it. It was cause by a bad check in the default values set-up: is_numeric applies for string numbers as well, which was unknown to me, and cause some of the values to be 0 where they should have been something different.
= 0.4.2 =
2012.12.07
*2012.12.07*
* added optional sync protocoll option: replace all http->https or https->http depending on request protocol
* binary mode is working correctly with memcached extension
* added warning message for memcache extension in binary mode
KNOWN ISSUES
**KNOWN ISSUES**
There are major problems with the "memcache" driver, the source is yet unkown. The situation is that there's no response from the memcached server using this driver; please avoid using it!
= 0.4.1 =
2012.08.16
*2012.08.16*
* storage key extended with scheme ( http; https; etc. ), the miss caused problems when https request server CSS and JS files via http.
= 0.4 =
2012.08.06
*2012.08.06*
* tested against new WordPress versions
* added lines to "memcached" storage to be able to work with nginx as well
* added lines to "memcached" to use binary protocol ( tested with PHP Memcached version 2.0.1 )
KNOWN ISSUES
**KNOWN ISSUES**
* "memcache" extension fails in binary mode; the reason is under investigation
= 0.3.2 =
2012.02.27
*2012.02.27*
* apc_cache_info replaced with apc_sma_info, makes plugin faster
= 0.3 =
2012.02.21
*2012.02.21*
* added syslog debug messages possibility
* bugfix: removed (accidently used) short_open_tags
= 0.2.3 =
2012.02.21
*2012.02.21*
* nginx-sample.conf file added, nginx config is created from here
= 0.2.2 =
2012.02.21
*2012.02.21*
* memcache types bugfix, reported in forum, thanks!
= 0.2.1 =
2012.02.21
*2012.02.21*
* bugfix, duplicated inclusion could emerge, fix added, thanks for Géza Kuti for reporting!
= 0.2 =
2012.02.19
*2012.02.19*
* added APC compression option ( requires PHP ZLIB ). Useful is output pages are large. Compression is on lowest level, therefore size/CPU load is more or less optimal.
= 0.1 =
2012.02.16
*2012.02.16*
* first public release

View file

@ -13,7 +13,7 @@ global $wp_nmc_redirect;
if (!defined('WP_FFPC_PARAM'))
define ( 'WP_FFPC_PARAM' , 'wp-ffpc' );
/* log level */
define ('WP_FFPC_LOG_LEVEL' , LOG_INFO);
define ('WP_FFPC_LOG_LEVEL' , LOG_WARNING );
/* define log ending message */
define ('WP_FFPC_LOG_TYPE_MSG' , '; cache type: '. $wp_ffpc_config['cache_type'] );
@ -56,17 +56,20 @@ function wp_ffpc_init( $wp_ffpc_config ) {
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->addServer( $server['host'] , $server['port'], $wp_ffpc_config['persistent'] );
wp_ffpc_log ( "server " . $server_id . " added, persistent mode: " . $wp_ffpc_config['persistent'] );
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 */
@ -74,36 +77,65 @@ function wp_ffpc_init( $wp_ffpc_config ) {
/* 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 );
$wp_ffpc_serverlist = $wp_ffpc_backend->getServerList();
if ( empty ( $wp_ffpc_serverlist ) )
$wp_ffpc_backend->addServers( $wp_ffpc_config['servers'] );
wp_ffpc_log ( "servers added, persistent mode: " . $wp_ffpc_config['persistent'] );
}
$wp_ffpc_backend_report = $wp_ffpc_backend->getStats();
foreach ( $wp_ffpc_config['servers'] as $server_id => $server ) {
$wp_ffpc_backend_status[$server_id] = false;
if ( array_key_exists( $server_id, $wp_ffpc_backend_report ) && $wp_ffpc_backend_report[ $server_id ]['pid'] != -1 ) {
$wp_ffpc_backend_status[$server_id] = 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:
return false;
break;
}
return $wp_ffpc_backend_status;
return ( empty ( $wp_ffpc_backend_status ) ? false : $wp_ffpc_backend_status );
}
/**

View file

@ -1,7 +1,7 @@
<?php
/*
Plugin Name: WP-FFPC
Version: 0.5
Version: 0.6.1
Plugin URI: http://petermolnar.eu/wordpress/wp-ffpc
Description: Fast Full Page Cache, backend can be memcached or APC
Author: Peter Molnar
@ -9,7 +9,7 @@ Author URI: http://petermolnar.eu/
License: GPL2
*/
/* Copyright 2010-2011 Peter Molnar (email : hello@petermolnar.eu )
/* Copyright 2010-2013 Peter Molnar (email : hello@petermolnar.eu )
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
@ -63,7 +63,15 @@ define ( 'WP_FFPC_ACACHE_COMMON_FILE' , WP_FFPC_DIR. '/wp-ffpc-common.php' );
define ( 'WP_FFPC_CONFIG_VAR' , '$wp_ffpc_config' );
define ( 'WP_FFPC_SERVER_LIST_SEPARATOR' , ',' );
define ( 'WP_FFPC_SERVER_SEPARATOR', ':' );
define ( 'WP_FFPC_DONATION_LINK', 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC' );
define ( 'WP_FFPC_FILE' , plugin_basename(__FILE__) );
define ( 'WP_FFPC_PLUGIN' , 'wp-ffpc/wp-ffpc.php' );
define ( 'WP_FFPC_VERSION' , '0.6.1' );
if ( ! function_exists( 'is_plugin_active_for_network' ) )
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
/* get the common functions */
include_once (WP_FFPC_DIR .'/wp-ffpc-common.php');
if (!class_exists('WPFFPC')) {
@ -76,6 +84,10 @@ if (!class_exists('WPFFPC')) {
/* for options array */
var $options = array();
/* stores options for all sites & all data */
var $all_options = array();
/* key for current options array */
var $options_key = '';
/* for default options array */
var $defaults = array();
/* memcached server object */
@ -85,13 +97,19 @@ if (!class_exists('WPFFPC')) {
/* status, 0 = nothing happened*/
var $status = 0;
/* stores information if plugin is network active or not */
var $network = false;
var $settingslink = '';
/**
* constructor
*
*/
function __construct() {
/* set settings page link */
$this->settingslink = 'options-general.php?page=' . WP_FFPC_OPTIONS_PAGE;
/* check if plugin is network-activated */
$this->check_for_network();
/* register options */
@ -101,7 +119,7 @@ if (!class_exists('WPFFPC')) {
$alive = wp_ffpc_init( $this->options );
/* don't register hooks if backend is dead */
if ($alive)
if (!$alive)
{
/* init inactivation hooks */
add_action('switch_theme', array( $this , 'invalidate'), 0);
@ -116,11 +134,17 @@ if (!class_exists('WPFFPC')) {
add_filter('redirect_canonical', array( $this , 'redirect_canonical') , 10, 2);
}
$plugin = plugin_basename( __FILE__ );
if ( $this->network )
add_filter( "network_admin_plugin_action_links_$plugin", array( $this, 'settings_link' ) );
else
add_filter( "plugin_action_links_$plugin", array( $this, 'settings_link' ) );
/* add admin styling */
if( is_admin() )
{
wp_enqueue_script ( "jquery-ui-tabs" );
wp_enqueue_style( WP_FFPC_PARAM . '.admin.css' , WP_FFPC_URL . '/css/'. WP_FFPC_PARAM .'.admin.css', false, '0.1');
wp_enqueue_style( WP_FFPC_PARAM . '.admin.css' , WP_FFPC_URL . '/' . WP_FFPC_PARAM .'.admin.css', false, '0.1');
}
/* on activation */
@ -132,7 +156,6 @@ if (!class_exists('WPFFPC')) {
/* on uninstall */
register_uninstall_hook(__FILE__ , array( $this , 'uninstall') );
/* init plugin in the admin section */
/* if multisite, admin page will be on network admin section */
if ( $this->network )
@ -140,6 +163,13 @@ if (!class_exists('WPFFPC')) {
/* not network, will be in simple admin menu */
else
add_action('admin_menu', array( $this , 'admin_init') );
if ( $this->all_options['version'] < WP_FFPC_VERSION ) {
$this->save_settings ();
if ( @file_exists( WP_FFPC_ACACHE_MAIN_FILE )) {
$this->generate_config();
}
}
}
/**
@ -147,6 +177,10 @@ if (!class_exists('WPFFPC')) {
*
*/
function activate ( ) {
/* register options for first time */
add_site_option( WP_FFPC_PARAM, $this->options , '' , 'yes');
$this->save_settings( true );
}
@ -155,19 +189,30 @@ if (!class_exists('WPFFPC')) {
*
*/
function admin_init () {
/* register options */
add_site_option( WP_FFPC_PARAM, $this->options , '' , 'no');
/* save parameter updates, if there are any */
if ( isset($_POST[WP_FFPC_PARAM . '-save']) )
{
$this->save_settings ();
$this->status = 1;
header("Location: admin.php?page=" . WP_FFPC_OPTIONS_PAGE . "&saved=true");
header( "Location: ". $this->settingslink ."&saved=true" );
}
add_submenu_page('settings.php', 'Edit WP-FFPC options', __('WP-FFPC', WP_FFPC_PARAM ), 10, WP_FFPC_OPTIONS_PAGE , array ( $this , 'admin_panel' ) );
//add_menu_page('Edit WP-FFPC options', __('WP-FFPC', WP_FFPC_PARAM ), 10, WP_FFPC_OPTIONS_PAGE , array ( $this , 'admin_panel' ) );
/* save parameter updates, if there are any */
if ( isset($_POST[WP_FFPC_PARAM . '-delete']) )
{
$this->delete_options();
$this->status = 2;
header( "Location: ". $this->settingslink ."&deleted=true" );
}
if ( $this->network )
$optionspage = 'settings.php';
else
$optionspage = 'options-general.php';
/* we use settings menu, no need for highest level menu */
add_submenu_page( $optionspage, 'Edit WP-FFPC options', __('WP-FFPC', WP_FFPC_PARAM ), 10, WP_FFPC_OPTIONS_PAGE , array ( $this , 'admin_panel' ) );
}
/**
@ -190,6 +235,13 @@ if (!class_exists('WPFFPC')) {
<div id='setting-error-settings_updated' class='updated settings-error'><p><strong>Settings saved.</strong></p></div>
<?php endif;
/**
* if options were saved
*/
if ($_GET['deleted']=='true' || $this->status == 2) : ?>
<div id='setting-error-options_deleted' class='error'><p><strong>Plugin options deleted.</strong></p></div>
<?php endif;
/**
* the admin panel itself
*/
@ -203,27 +255,36 @@ if (!class_exists('WPFFPC')) {
<div class="wrap">
<h4>This plugin helped your business? <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC">Buy me a coffee for having it :)</a></h4>
<h4>This plugin helped your business? <a href="<?php echo WP_FFPC_DONATION_LINK; ?>">Buy me a coffee for having it, please :)</a></h4>
<?php if ( !WP_CACHE ) : ?>
<div class="updated settings-error"><p><strong><?php _e("WARNING: WP_CACHE is disabled, plugin will not work that way. Please add define( 'WP_CACHE', true ); into the beginning of wp-config.php", WP_FFPC_PARAM); ?></strong></p></div>
<div class="error"><p><strong><?php _e("WARNING: WP_CACHE is disabled, plugin will not work that way. Please add define( 'WP_CACHE', true ); into the beginning of wp-config.php", WP_FFPC_PARAM); ?></strong></p></div>
<?php endif; ?>
<?php if ( !class_exists('Memcache') && !class_exists('Memcached') ) : ?>
<div class="updated settings-error"><p><strong><?php _e('No PHP memcached extension was found. To use memcached, you need PHP Memcache or PHP Memcached extension.', WP_FFPC_PARAM); ?></strong></p></div>
<?php if ( ! file_exists ( WP_FFPC_ACACHE_MAIN_FILE ) ): ?>
<div class="error"><p><strong><?php _e("WARNING: advanced cache file is yet to be generated, please save settings!", WP_FFPC_PARAM); ?></strong></p></div>
<?php endif; ?>
<?php if ( $this->options['cache_type'] == 'memcached' && !class_exists('Memcached') ) : ?>
<div class="error"><p><strong><?php _e('ERROR: Memcached cache backend activated but no PHP memcached extension was found.', WP_FFPC_PARAM); ?></strong></p></div>
<?php endif; ?>
<?php if ( $this->options['cache_type'] == 'memcache' && !class_exists('Memcache') ) : ?>
<div class="error"><p><strong><?php _e('ERROR: Memcache cache backend activated but no PHP memcache extension was found.', WP_FFPC_PARAM); ?></strong></p></div>
<?php endif; ?>
<?php
/* get the current runtime configuration for memcache in PHP */
$memcached_settings = ini_get_all( 'memcache' );
$memcached_protocol = strtolower($memcached_settings['memcache.protocol']['local_value']);
?>
<?php if ( $this->options['cache_type'] == 'memcached' && $memcached_protocol == 'binary' ) : ?>
<div class="updated settings-error"><p><strong><?php _e('WARNING: Memcache extension is configured to use binary mode. This is very buggy and the plugin will most probably not work. Please consider to change either to ascii mode or to Mecached extension.', WP_FFPC_PARAM); ?></strong></p></div>
<?php if ( $this->options['cache_type'] == 'memcache' && $memcached_protocol == 'binary' ) : ?>
<div class="error"><p><strong><?php _e('WARNING: Memcache extension is configured to use binary mode. This is very buggy and the plugin will most probably not work. Please consider to change either to ascii mode or to Mecached extension.', WP_FFPC_PARAM); ?></strong></p></div>
<?php endif; ?>
<?php if ( $this->options['cache_type'] == 'memcached' || $this->options['cache_type'] == 'memcache' ) : ?>
<div class="updated settings-error">
<div class="updated">
<p><strong>
<?php
_e ( 'Driver: ' , WP_FFPC_PARAM);
@ -233,11 +294,16 @@ if (!class_exists('WPFFPC')) {
<p>
<?php
_e( '<strong>Backend status:</strong><br />', WP_FFPC_PARAM );
$init = wp_ffpc_init( $this->options);
$init = wp_ffpc_init( $this->options );
/* we need to go through all servers */
foreach ( $this->options['servers'] as $server_string => $server ) {
echo $server['host'] . ":" . $server['port'] ." => ";
$server_status = ( empty($init) || $init[$server_string] == 0 ) ? '<span class="error-msg">down</span>' : '<span class="ok-msg">up & running</span>' ;
echo $server_status ."<br />\n";
if ( is_array($init) && $init[$server_string] === false )
_e ( '<span class="error-msg">down</span><br />', WP_FFPC_PARAM );
elseif ( is_array($init) && $init[$server_string] === true )
_e ( '<span class="ok-msg">up & running</span><br />', WP_FFPC_PARAM );
else
_e ( '<span class="error-msg">unknown, please try re-saving settings!</span><br />', WP_FFPC_PARAM );
}
?>
</p>
@ -475,7 +541,10 @@ if (!class_exists('WPFFPC')) {
<pre><?php echo $nginx; ?></pre>
</fieldset>
<p class="clearcolumns"><input class="button-primary" type="submit" name="<?php echo WP_FFPC_PARAM; ?>-save" id="<?php echo WP_FFPC_PARAM; ?>-save" value="Save Changes" /></p>
<p class="clearcolumns">
<input class="button-primary" type="submit" name="<?php echo WP_FFPC_PARAM; ?>-save" id="<?php echo WP_FFPC_PARAM; ?>-save" value="Save Changes" />
<input class="button-secondary" style="float: right" type="submit" name="<?php echo WP_FFPC_PARAM; ?>-delete" id="<?php echo WP_FFPC_PARAM; ?>-delete" value="Delete options from DB" />
</p>
</form>
<?php
@ -512,12 +581,19 @@ if (!class_exists('WPFFPC')) {
*
*/
function check_for_network( ) {
if ( is_multisite() ) {
$plugins = get_site_option( 'active_sitewide_plugins');
if ( isset($plugins['wp-ffpc/wp-ffpc.php']) ) {
$this->network = true;
}
$this->options_key = $_SERVER['HTTP_HOST'];
if ( is_plugin_active_for_network ( WP_FFPC_PLUGIN ) )
{
/* set active for network */
$this->network = true;
/* replace settings link */
$this->settingslink = str_replace( 'options-general.php' , 'settings.php' , $this->settingslink );
/* set options key */
$this->options_key = 'network';
}
}
/**
@ -525,12 +601,26 @@ if (!class_exists('WPFFPC')) {
*
*/
function deactivate ( ) {
if (@file_exists (WP_FFPC_ACACHE_MAIN_FILE))
@unlink (WP_FFPC_ACACHE_MAIN_FILE);
//if (@file_exists (WP_FFPC_ACACHE_MAIN_FILE))
// @unlink (WP_FFPC_ACACHE_MAIN_FILE);
$this->save_settings( false, true );
//$this->generate_config ( true );
}
/**
* delete options from database
*
*/
function delete_options () {
delete_site_option( WP_FFPC_PARAM );
wp_ffpc_log ( "plugin options deleted ");
}
/**
* invalidate cache
*
* @param $post_id
* id of post to be removed from cache entries
*/
function invalidate ( $post_id ) {
wp_ffpc_clear ( $post_id );
@ -561,10 +651,13 @@ if (!class_exists('WPFFPC')) {
}
/**
* generates main advanced-cache system-wide config file
* generates main advanced-cache config file
*
* @param $delete_current
* deletes current config settings on deactivation
*
*/
function generate_config() {
function generate_config( ) {
$acache = WP_FFPC_ACACHE_MAIN_FILE;
/* is file currently exists, delete it*/
@ -575,10 +668,15 @@ if (!class_exists('WPFFPC')) {
if ( @file_exists( $acache ))
return false;
/* if no config left, don't create empty config */
if ( empty ( $this->all_options ) )
return false;
//if ( is_plugin_active_for_network ( WP_FFPC_PLUGIN ) && !is_plugin_active ( WP_FFPC_PLUGIN ) )
// return false;
$string = '<?php'. "\n" . 'global '. WP_FFPC_CONFIG_VAR .";\n";
$string .= WP_FFPC_CONFIG_VAR .' = ' .var_export( $this->options , true ) . ';';
$string .= WP_FFPC_CONFIG_VAR .' = ' .var_export( $this->all_options , true ) . ';';
$string .= "\n\ninclude_once ('" . WP_FFPC_ACACHE_COMMON_FILE . "');\ninclude_once ('" . WP_FFPC_ACACHE_INC_FILE . "');\n";
file_put_contents($acache, $string);
@ -599,7 +697,7 @@ if (!class_exists('WPFFPC')) {
'prefix_data' =>'data-',
'charset' => 'utf-8',
'pingback_status'=> false,
'debug' => true,
'debug' => false,
'syslog' => false,
'cache_type' => 'memcached',
'cache_loggedin' => false,
@ -619,9 +717,29 @@ if (!class_exists('WPFFPC')) {
$this->defaults = $defaults;
$this->options = get_site_option( WP_FFPC_PARAM , $defaults, false );
/* maps saved options and defaults */
//$this->options = get_site_option( WP_FFPC_PARAM , $defaults, false );
$this->split_hosts();
$this->all_options = get_site_option( WP_FFPC_PARAM );
if ( ! empty ( $this->all_options[ $this->options_key ] ) )
$this->options = array_merge ( $defaults, $this->all_options[ $this->options_key ] );
else
$this->options = $defaults;
/* check for version number, if none, we're upgrading from 0.5, therefore we need to copy the settings and remove them after
this will run once only at all
*/
if ( empty ( $this->all_options['version'] ) )
{
foreach ( array_keys( $defaults ) as $key ) {
if ( isset ( $this->all_options[$key] ) )
{
$this->options[$key] = $this->all_options[$key];
unset ( $this->all_options[$key] );
}
}
}
}
@ -675,6 +793,13 @@ if (!class_exists('WPFFPC')) {
/**
* function to be able to store redirects
*
* @param $redirect_url
* url of required wordpress redirect
*
* @param $requested_url
* currently unused
*
*/
function redirect_canonical($redirect_url, $requested_url) {
global $wp_nmc_redirect;
@ -685,43 +810,46 @@ if (!class_exists('WPFFPC')) {
/**
* save settings function
*
* @param firstrun
* boolean: true if the function is called on plugin activation
*
*/
function save_settings ( $firstrun = false ) {
function save_settings ( $firstrun = false, $delete_current = false ) {
$defaults = $this->defaults;
if ( $delete_current )
unset ( $this->all_options[ $this->options_key ] );
else
$this->update_settings( $firstrun );
foreach ( $defaults as $key => $default )
{
if (!empty($_POST[$key]))
{
$update = $_POST[$key];
if ( strlen( $update ) !=0 && !is_numeric($update) )
$update = stripslashes($update);
}
elseif ( ( empty( $_POST[$name] ) && is_bool ( $default ) ) || is_int( $default ) )
{
$update = 0;
}
else
{
$update = $this->options[$key];
}
$this->all_options['version'] = WP_FFPC_VERSION;
$options[$key] = $update;
}
$this->options = $options;
$this->split_hosts();
update_site_option( WP_FFPC_PARAM , $this->options );
/* save options */
update_site_option( WP_FFPC_PARAM , $this->all_options );
/* invalidate cache, this is neccessary */
$this->invalidate('system_flush');
/* if it's not for the first run, generate the config file */
if ( ! $firstrun )
$this->generate_config();
$this->generate_config( );
}
/**
*
*
*/
function settings_link ( $links ) {
$settings_link = '<a href="' . $this->settingslink . '">' . __( 'Settings', WP_FFPC_PARAM ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}
/**
* splits config parameter "hosts" into an array of server string, host and port
* to be used in later config
*
*/
function split_hosts ( ) {
$servers = explode( WP_FFPC_SERVER_LIST_SEPARATOR , $this->options['hosts']);
@ -750,8 +878,46 @@ if (!class_exists('WPFFPC')) {
*/
function uninstall ( ) {
delete_site_option( WP_FFPC_PARAM );
wp_ffpc_log ( "plugin uninstalled ");
}
function update_settings ( $firstrun = false ) {
$options = $this->defaults;
/* only try to update defaults if it's not first run and $_POST is not empty */
if ( !$firstrun && !empty ( $_POST ) )
{
foreach ( $options as $key => $default )
{
/* $_POST element is available */
if (!empty($_POST[$key]))
{
$update = $_POST[$key];
/* get rid of slashed */
if ( strlen( $update ) !=0 &&!is_numeric($update) )
$update = stripslashes($update);
$options[$key] = $update;
}
/* empty $_POST element: when HTML form posted, empty checkboxes a 0 values will not be
part of the $_POST array, thus we need to check if this is the situation by
checking the types of the elements, since a missing value could mean update from 1 to 0
*/
elseif ( empty( $_POST[$key] ) && ( is_bool ( $default ) || is_int( $default ) ) )
{
$options[$key] = 0;
}
}
}
$this->options = $options;
/* set up server array from hosts config var */
$this->split_hosts();
$this->all_options[ $this->options_key ] = $this->options;
}
}
}