version 0.6 alpha
git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@677505 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
parent
5ca0120085
commit
e054f5870b
4 changed files with 107 additions and 57 deletions
|
@ -11,6 +11,14 @@ if ( !WP_CACHE )
|
||||||
if (!isset($wp_ffpc_config))
|
if (!isset($wp_ffpc_config))
|
||||||
return false;
|
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 */
|
/* request uri */
|
||||||
$wp_ffpc_uri = $_SERVER['REQUEST_URI'];
|
$wp_ffpc_uri = $_SERVER['REQUEST_URI'];
|
||||||
/* query string */
|
/* query string */
|
||||||
|
|
11
readme.txt
11
readme.txt
|
@ -23,12 +23,12 @@ WP-FFPC is a full page cache plugin for WordPress. Supports memcached server or
|
||||||
* fallback to no caching if any error or problem occurs
|
* fallback to no caching if any error or problem occurs
|
||||||
* syslog & debug settings for troubleshooting
|
* syslog & debug settings for troubleshooting
|
||||||
* supports multiple memcached backends
|
* supports multiple memcached backends
|
||||||
* Wordpress Network compatible(2)
|
* Wordpress Network compatible (2)
|
||||||
* nginx compatible(3)
|
* nginx compatible(3)
|
||||||
|
|
||||||
(1) pingback hostname will always be generated from the accessed domain, otherwise speed would get highly compromised
|
(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.
|
(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).
|
If used with APC, this feature is not available (no APC module for nginx).
|
||||||
|
@ -56,6 +56,13 @@ You have to remove the default yum package, named `php-pecl-memcache` and instal
|
||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
= 0.6 =
|
||||||
|
*development branch*
|
||||||
|
|
||||||
|
* 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
|
||||||
|
|
||||||
= 0.5.1 =
|
= 0.5.1 =
|
||||||
*2013.03.07*
|
*2013.03.07*
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ global $wp_nmc_redirect;
|
||||||
if (!defined('WP_FFPC_PARAM'))
|
if (!defined('WP_FFPC_PARAM'))
|
||||||
define ( 'WP_FFPC_PARAM' , 'wp-ffpc' );
|
define ( 'WP_FFPC_PARAM' , 'wp-ffpc' );
|
||||||
/* log level */
|
/* log level */
|
||||||
define ('WP_FFPC_LOG_LEVEL' , LOG_INFO );
|
define ('WP_FFPC_LOG_LEVEL' , LOG_WARNING );
|
||||||
/* define log ending message */
|
/* define log ending message */
|
||||||
define ('WP_FFPC_LOG_TYPE_MSG' , '; cache type: '. $wp_ffpc_config['cache_type'] );
|
define ('WP_FFPC_LOG_TYPE_MSG' , '; cache type: '. $wp_ffpc_config['cache_type'] );
|
||||||
|
|
||||||
|
|
143
wp-ffpc.php
143
wp-ffpc.php
|
@ -67,6 +67,10 @@ define ( 'WP_FFPC_SERVER_LIST_SEPARATOR' , ',' );
|
||||||
define ( 'WP_FFPC_SERVER_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_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_FILE' , plugin_basename(__FILE__) );
|
||||||
|
define ( 'WP_FFPC_PLUGIN' , 'wp-ffpc/wp-ffpc.php' );
|
||||||
|
|
||||||
|
if ( ! function_exists( 'is_plugin_active_for_network' ) )
|
||||||
|
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||||
|
|
||||||
/* get the common functions */
|
/* get the common functions */
|
||||||
include_once (WP_FFPC_DIR .'/wp-ffpc-common.php');
|
include_once (WP_FFPC_DIR .'/wp-ffpc-common.php');
|
||||||
|
@ -81,6 +85,10 @@ if (!class_exists('WPFFPC')) {
|
||||||
|
|
||||||
/* for options array */
|
/* for options array */
|
||||||
var $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 */
|
/* for default options array */
|
||||||
var $defaults = array();
|
var $defaults = array();
|
||||||
/* memcached server object */
|
/* memcached server object */
|
||||||
|
@ -265,7 +273,7 @@ if (!class_exists('WPFFPC')) {
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php
|
||||||
_e( '<strong>Backend status:</strong><br />', WP_FFPC_PARAM );
|
_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 */
|
/* we need to go through all servers */
|
||||||
foreach ( $this->options['servers'] as $server_string => $server ) {
|
foreach ( $this->options['servers'] as $server_string => $server ) {
|
||||||
echo $server['host'] . ":" . $server['port'] ." => ";
|
echo $server['host'] . ":" . $server['port'] ." => ";
|
||||||
|
@ -545,17 +553,19 @@ if (!class_exists('WPFFPC')) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function check_for_network( ) {
|
function check_for_network( ) {
|
||||||
if ( is_multisite() )
|
|
||||||
|
$this->options_key = $_SERVER['HTTP_HOST'];
|
||||||
|
|
||||||
|
if ( is_plugin_active_for_network ( WP_FFPC_PLUGIN ) )
|
||||||
{
|
{
|
||||||
$plugins = get_site_option( 'active_sitewide_plugins');
|
/* set active for network */
|
||||||
/* see if plugins is active */
|
$this->network = true;
|
||||||
if ( isset($plugins['wp-ffpc/wp-ffpc.php']) )
|
/* replace settings link */
|
||||||
{
|
$this->settingslink = str_replace( 'options-general.php' , 'settings.php' , $this->settingslink );
|
||||||
$this->network = true;
|
/* set options key */
|
||||||
/* replace settings link */
|
$this->options_key = 'network';
|
||||||
$this->settingslink = str_replace( 'options-general.php' , 'settings.php' , $this->settingslink );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -563,8 +573,10 @@ if (!class_exists('WPFFPC')) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function deactivate ( ) {
|
function deactivate ( ) {
|
||||||
if (@file_exists (WP_FFPC_ACACHE_MAIN_FILE))
|
//if (@file_exists (WP_FFPC_ACACHE_MAIN_FILE))
|
||||||
@unlink (WP_FFPC_ACACHE_MAIN_FILE);
|
// @unlink (WP_FFPC_ACACHE_MAIN_FILE);
|
||||||
|
$this->save_settings( false, true );
|
||||||
|
//$this->generate_config ( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -602,10 +614,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;
|
$acache = WP_FFPC_ACACHE_MAIN_FILE;
|
||||||
/* is file currently exists, delete it*/
|
/* is file currently exists, delete it*/
|
||||||
|
@ -616,10 +631,15 @@ if (!class_exists('WPFFPC')) {
|
||||||
if ( @file_exists( $acache ))
|
if ( @file_exists( $acache ))
|
||||||
return false;
|
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 = '<?php'. "\n" . 'global '. WP_FFPC_CONFIG_VAR .";\n";
|
||||||
|
$string .= WP_FFPC_CONFIG_VAR .' = ' .var_export( $this->all_options , true ) . ';';
|
||||||
$string .= WP_FFPC_CONFIG_VAR .' = ' .var_export( $this->options , true ) . ';';
|
|
||||||
|
|
||||||
$string .= "\n\ninclude_once ('" . WP_FFPC_ACACHE_COMMON_FILE . "');\ninclude_once ('" . WP_FFPC_ACACHE_INC_FILE . "');\n";
|
$string .= "\n\ninclude_once ('" . WP_FFPC_ACACHE_COMMON_FILE . "');\ninclude_once ('" . WP_FFPC_ACACHE_INC_FILE . "');\n";
|
||||||
|
|
||||||
file_put_contents($acache, $string);
|
file_put_contents($acache, $string);
|
||||||
|
@ -661,7 +681,14 @@ if (!class_exists('WPFFPC')) {
|
||||||
$this->defaults = $defaults;
|
$this->defaults = $defaults;
|
||||||
|
|
||||||
/* maps saved options and defaults */
|
/* maps saved options and defaults */
|
||||||
$this->options = get_site_option( WP_FFPC_PARAM , $defaults, false );
|
//$this->options = get_site_option( WP_FFPC_PARAM , $defaults, false );
|
||||||
|
|
||||||
|
$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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,54 +763,25 @@ if (!class_exists('WPFFPC')) {
|
||||||
* boolean: true if the function is called on plugin activation
|
* boolean: true if the function is called on plugin activation
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function save_settings ( $firstrun = false ) {
|
function save_settings ( $firstrun = false, $delete_current = false ) {
|
||||||
|
|
||||||
$options = $this->defaults;
|
if ( $delete_current )
|
||||||
|
unset ( $this->all_options[ $this->options_key ] );
|
||||||
/* only try to update defaults if it's not first run and $_POST is not empty */
|
else
|
||||||
if ( !$firstrun && !empty ( $_POST ) )
|
$this->update_settings( $firstrun );
|
||||||
{
|
|
||||||
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();
|
|
||||||
|
|
||||||
/* save options */
|
/* save options */
|
||||||
update_site_option( WP_FFPC_PARAM , $this->options );
|
update_site_option( WP_FFPC_PARAM , $this->all_options );
|
||||||
|
|
||||||
/* invalidate cache, this is neccessary */
|
/* invalidate cache, this is neccessary */
|
||||||
$this->invalidate('system_flush');
|
$this->invalidate('system_flush');
|
||||||
|
|
||||||
/* if it's not for the first run, generate the config file */
|
/* if it's not for the first run, generate the config file */
|
||||||
if ( ! $firstrun )
|
if ( ! $firstrun )
|
||||||
$this->generate_config();
|
$this->generate_config( );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -830,6 +828,43 @@ if (!class_exists('WPFFPC')) {
|
||||||
wp_ffpc_log ( "plugin uninstalled ");
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue