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
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* checks for SSL connection
*/
if ( ! function_exists ( 'replace_if_ssl' ) ) {
function replace_if_ssl ( $string ) {
if ( isset($_SERVER['HTTPS']) && ( ( strtolower($_SERVER['HTTPS']) == 'on' ) || ( $_SERVER['HTTPS'] == '1' ) ) )
return str_replace ( 'http://' , 'https://' , $string );
else
return $string;
}
}
/* fix */
if ( ! defined( 'WP_PLUGIN_URL_' ) )
{
if ( defined( 'WP_PLUGIN_URL' ) )
define( 'WP_PLUGIN_URL_' , replace_if_ssl ( WP_PLUGIN_URL ) );
else
define( 'WP_PLUGIN_URL_', replace_if_ssl ( get_option( 'siteurl' ) ) . '/wp-content/plugins' );
}
if ( ! defined( 'WP_PLUGIN_DIR' ) )
define( 'WP_PLUGIN_DIR', ABSPATH . 'wp-content/plugins' );
/* constants */
define ( 'WP_FFPC_PARAM' , 'wp-ffpc' );
define ( 'WP_FFPC_OPTION_GROUP' , 'wp-ffpcparams' );
define ( 'WP_FFPC_OPTIONS_PAGE' , 'wp-ffpcoptions' );
define ( 'WP_FFPC_URL' , WP_PLUGIN_URL_ . '/' . WP_FFPC_PARAM );
define ( 'WP_FFPC_DIR' , WP_PLUGIN_DIR . '/' . WP_FFPC_PARAM );
define ( 'WP_FFPC_CONF_DIR' , WP_PLUGIN_DIR . '/' . WP_FFPC_PARAM .'/config' );
define ( 'WP_FFPC_ACACHE_MAIN_FILE' , ABSPATH . 'wp-content/advanced-cache.php' );
define ( 'WP_FFPC_ACACHE_INC_FILE' , WP_FFPC_DIR. '/advanced-cache.php' );
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' );
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')) {
/**
* main class
*
*/
class 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 */
var $memcached = NULL;
var $memcached_string = '';
/* 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 */
$this->get_options();
/* check is backend is available */
$alive = wp_ffpc_init( $this->options );
/* don't register hooks if backend is dead */
if (!$alive)
{
/* init inactivation hooks */
add_action('switch_theme', array( $this , 'invalidate'), 0);
add_action('edit_post', array( $this , 'invalidate'), 0);
add_action('publish_post', array( $this , 'invalidate'), 0);
add_action('delete_post', array( $this , 'invalidate'), 0);
/* Capture and register if a redirect is sent back from WP, so the cache
can cache (or ignore) it. Redirects were source of problems for blogs
with more than one host name (eg. domain.com and www.domain.com) comined
with the use of Hyper Cache.*/
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 . '/' . WP_FFPC_PARAM .'.admin.css', false, '0.1');
}
/* on activation */
register_activation_hook(__FILE__ , array( $this , 'activate') );
/* on deactivation */
register_deactivation_hook(__FILE__ , array( $this , 'deactivate') );
/* 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 )
add_action('network_admin_menu', array( $this , 'admin_init') );
/* not network, will be in simple admin menu */
else
add_action('admin_menu', array( $this , 'admin_init') );
}
/**
* activation hook: save default settings in order to eliminate bugs.
*
*/
function activate ( ) {
/* register options for first time */
add_site_option( WP_FFPC_PARAM, $this->options , '' , 'yes');
$this->save_settings( true );
}
/**
* init function for admin section
*
*/
function admin_init () {
/* save parameter updates, if there are any */
if ( isset($_POST[WP_FFPC_PARAM . '-save']) )
{
$this->save_settings ();
$this->status = 1;
header( "Location: ". $this->settingslink ."&saved=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' ) );
}
/**
* settings panel at admin section
*
*/
function admin_panel ( ) {
/**
* security
*/
if( ! function_exists( 'current_user_can' ) || ! current_user_can( 'manage_options' ) ){
die( );
}
/**
* if options were saved
*/
if ($_GET['saved']=='true' || $this->status == 1) : ?>
Backend status: ', WP_FFPC_PARAM );
$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 ) ? 'down' : 'up & running' ;
echo $server_status ." \n";
}
?>
input field with $current set as active
*
*/
function cache_type ( $current , $returntext = false ) {
$e = array (
'apc' => 'use APC as store',
'memcache' => 'use memcached server with Memcache extension',
'memcached' => 'use memcached server with Memcached extension',
);
$this->print_select_options ( $e , $current , $returntext );
}
/**
* see if we are using network-wide setup or not
*
*/
function check_for_network( ) {
$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';
}
}
/**
* deactivation hook: clear advanced-cache config file
*
*/
function deactivate ( ) {
//if (@file_exists (WP_FFPC_ACACHE_MAIN_FILE))
// @unlink (WP_FFPC_ACACHE_MAIN_FILE);
$this->save_settings( false, true );
//$this->generate_config ( true );
}
/**
* invalidate cache
*
* @param $post_id
* id of post to be removed from cache entries
*/
function invalidate ( $post_id ) {
wp_ffpc_clear ( $post_id );
}
/**
* generates invalidation method select box
*
* @param $current
* the active or required size's identifier
*
* @param $returntext
* boolean: is true, the description will be returned of $current size
*
* @return
* prints either description of $current
* or option list for a