all repos — wp-ffpc @ 8a738ded441221ded55d104f2de724ef3abe41ed

0.5 maybe final: lot's of comments, names of contributors, minor fixes

git-svn-id: http://plugins.svn.wordpress.org/wp-ffpc/trunk@677000 b8457f37-d9ea-0310-8a92-e5e31aec5664
cadeyrn cadeyrn@b8457f37-d9ea-0310-8a92-e5e31aec5664
Wed, 06 Mar 2013 18:31:28 +0000
commit

8a738ded441221ded55d104f2de724ef3abe41ed

parent

22a2e94b2e08b57d8ac618eb1a90092088ddb183

4 files changed, 74 insertions(+), 31 deletions(-)

jump to
M advanced-cache.phpadvanced-cache.php

@@ -216,6 +216,7 @@

/* 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;
M readme.txtreadme.txt

@@ -44,8 +44,8 @@ == 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. +4. Check 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. +5. Save the settings. THIS STEP IS MANDATORY: without saving the settings, there will be no activated caching! == Frequently Asked Questions ==

@@ -64,14 +64,15 @@ 2013.03.04

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 work logic = 0.4.3 = 2013.03.03
M wp-ffpc-common.phpwp-ffpc-common.php

@@ -13,7 +13,7 @@ /* wp ffpc prefic */

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_INFO ); /* define log ending message */ define ('WP_FFPC_LOG_TYPE_MSG' , '; cache type: '. $wp_ffpc_config['cache_type'] );

@@ -103,7 +103,8 @@ /* cache type is invalid */

default: return false; } - return $wp_ffpc_backend_status; + + return ( empty ( $wp_ffpc_backend_status ) ? false : $wp_ffpc_backend_status ); } /**
M wp-ffpc.phpwp-ffpc.php

@@ -9,7 +9,9 @@ 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 ) + + Many thanks to contributor Mark Costlow <cheeks@swcp.com> 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,6 +65,7 @@ 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' ); include_once (WP_FFPC_DIR .'/wp-ffpc-common.php');

@@ -85,6 +88,7 @@

/* status, 0 = nothing happened*/ var $status = 0; + /* stores information if plugin is network active or not */ var $network = false; /**

@@ -101,7 +105,7 @@ /* check is backend is available */

$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);

@@ -147,6 +151,10 @@ * 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 ); }

@@ -155,9 +163,6 @@ * init function for admin section

* */ 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']) ) {

@@ -166,8 +171,8 @@ $this->status = 1;

header("Location: admin.php?page=" . WP_FFPC_OPTIONS_PAGE . "&saved=true"); } + /* we use settings menu, no need for highest level menu */ 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' ) ); } /**

@@ -203,17 +208,23 @@ </script>

<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> <?php endif; ?> + <?php if ( ! file_exists ( WP_FFPC_ACACHE_MAIN_FILE ) ): ?> + <div class="updated settings-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 ( !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 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']); ?>

@@ -234,6 +245,7 @@ <p>

<?php _e( '<strong>Backend status:</strong><br />', 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 ) ? '<span class="error-msg">down</span>' : '<span class="ok-msg">up & running</span>' ;

@@ -531,6 +543,9 @@ }

/** * invalidate cache + * + * @param $post_id + * id of post to be removed from cache entries */ function invalidate ( $post_id ) { wp_ffpc_clear ( $post_id );

@@ -619,9 +634,8 @@ );

$this->defaults = $defaults; + /* maps saved options and defaults */ $this->options = get_site_option( WP_FFPC_PARAM , $defaults, false ); - - $this->split_hosts(); }

@@ -675,6 +689,13 @@ }

/** * 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 +706,62 @@

/** * save settings function * + * @param firstrun + * boolean: true if the function is called on plugin activation + * */ function save_settings ( $firstrun = false ) { - $defaults = $this->defaults; + $options = $this->defaults; - foreach ( $defaults as $key => $default ) + /* only try to update defaults if it's not first run and $_POST is not empty */ + if ( !$firstrun && !empty ( $_POST ) ) { - if (!empty($_POST[$key])) + foreach ( $options as $key => $default ) { - $update = $_POST[$key]; - if ( strlen( $update ) !=0 && !is_numeric($update) ) - $update = stripslashes($update); + /* $_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; + } } - elseif ( empty( $_POST[$name] ) && ( is_bool ( $default ) || is_int( $default ) ) ) - { - $update = 0; - } - else - { - $update = $this->options[$key]; - } - - $options[$key] = $update; } $this->options = $options; + + /* set up server array from hosts config var */ $this->split_hosts(); + /* save options */ update_site_option( WP_FFPC_PARAM , $this->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(); } + /** + * 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']);