diff --git a/wp-ffpc-acache.php b/wp-ffpc-acache.php index a28a418..c3c56a7 100644 --- a/wp-ffpc-acache.php +++ b/wp-ffpc-acache.php @@ -141,7 +141,8 @@ if ( array_key_exists( "HTTP_IF_MODIFIED_SINCE" , $_SERVER ) && !empty( $wp_ffpc /*** SERVING CACHED PAGE ***/ /* if we reach this point it means data was found & correct, serve it */ -if ( isset( $wp_ffpc_values['meta']['mime'] )) header('Content-Type: ' . $wp_ffpc_values['meta']['mime']); +if (!empty ( $wp_ffpc_values['meta']['mime'] ) ) + header('Content-Type: ' . $wp_ffpc_values['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'); @@ -326,4 +327,4 @@ function wp_ffpc_callback( $buffer ) { } /*** END GENERATING CACHE ENTRY ***/ -?> +?> \ No newline at end of file diff --git a/wp-ffpc-backend.php b/wp-ffpc-backend.php index f665527..f6b9970 100644 --- a/wp-ffpc-backend.php +++ b/wp-ffpc-backend.php @@ -25,10 +25,15 @@ if (!class_exists('WP_FFPC_Backend')) { /** * + * @var string $plugin_constant Namespace of the plugin * @var mixed $connection Backend object storage variable - * @var array $config Configuration settings array - * @var boolean $alive Backend aliveness indicator - * @var mixed $status Backend server status storage + * @var boolean $alive Alive flag of backend connection + * @var boolean $network WordPress Network flag + * @var array $options Configuration settings array + * @var array $status Backends status storage + * @var array $cookies Logged in cookies to search for + * @var array $urimap Map to render key with + * @var object $utilities Utilities singleton * */ class WP_FFPC_Backend { @@ -51,17 +56,30 @@ if (!class_exists('WP_FFPC_Backend')) { * constructor * * @param mixed $config Configuration options + * @param boolean $network WordPress Network indicator flah * */ public function __construct( $config, $network = false ) { + /* no config, nothing is going to work */ + if ( empty ( $this->options ) ) { + return false; + //die ( __translate__ ( 'WP-FFPC Backend class received empty configuration array, the plugin will not work this way', $this->plugin_constant ) ); + } + + /* set config */ $this->options = $config; + + /* set network flag */ $this->network = $network; + /* these are the list of the cookies to look for when looking for logged in user */ $this->cookies = array ( 'comment_author_' , 'wordpressuser_' , 'wp-postpass_', 'wordpress_logged_in_' ); + /* make utilities singleton */ $this->utilities = WP_Plugins_Utilities_v1::Utility(); + /* map the key with the predefined schemes */ $ruser = isset ( $_SERVER['REMOTE_USER'] ) ? $_SERVER['REMOTE_USER'] : ''; $ruri = isset ( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : ''; $rhost = isset ( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; @@ -75,23 +93,19 @@ if (!class_exists('WP_FFPC_Backend')) { '$cookie_PHPSESSID' => $scookie, ); - /* no config, nothing is going to work */ - if ( empty ( $this->options ) ) { - return false; - } - /* split hosts entry to servers */ $this->set_servers(); /* call backend initiator based on cache type */ $init = $this->proxy( 'init' ); + /* info level */ $this->log ( __translate__('init starting', $this->plugin_constant )); $this->$init(); } - /*********************** PUBLIC FUNCTIONS ***********************/ + /*********************** PUBLIC / PROXY FUNCTIONS ***********************/ /** * build key to make requests with @@ -166,7 +180,9 @@ if (!class_exists('WP_FFPC_Backend')) { /** * public get function, transparent proxy to internal function based on backend * - * @param string $key Cache key to invalidate, false mean full flush + * @param string $post_id ID of post to invalidate + * @param boolean $force Force flush cache + * */ public function clear ( $post_id = false, $force = false ) { @@ -396,6 +412,8 @@ if (!class_exists('WP_FFPC_Backend')) { /** * log wrapper to include options * + * @var mixed $message Message to log + * @var int $log_level Log level */ private function log ( $message, $log_level = LOG_WARNING ) { if ( !isset ( $this->options['log'] ) || $this->options['log'] != 1 ) @@ -763,4 +781,4 @@ if (!class_exists('WP_FFPC_Backend')) { } -?> +?> \ No newline at end of file diff --git a/wp-ffpc-class.php b/wp-ffpc-class.php index 48f9413..3a30ce0 100644 --- a/wp-ffpc-class.php +++ b/wp-ffpc-class.php @@ -18,15 +18,17 @@ if ( ! class_exists( 'WP_FFPC' ) ) { /** * main wp-ffpc class * - * @var string $acache_config Configuration storage file location - * @var string $acache_worker The advanced cache worker file location - * @var string $acache The WordPress standard advanced cache location - * @var array $select_cache_type Possible cache types array - * @var array $select_invalidation_method Possible invalidation methods array - * @var string $nginx_sample Nginx example config file location - * @var array $select_cache_type Cache types string array - * @var array $select_invalidation_method Invalidation methods string array - * + * @var string $acache_worker advanced cache "worker" file, bundled with the plugin + * @var string $acache WordPress advanced-cache.php file location + * @var string $nginx_sample nginx sample config file, bundled with the plugin + * @var string $acache_backend backend driver file, bundled with the plugin + * @var string $button_flush flush button identifier + * @var string $button_precache precache button identifier + * @var string $global_option global options identifier + * @var string $precache_logfile Precache log file location + * @var string $precache_phpfile Precache PHP worker location + * @var array $shell_possibilities List of possible precache worker callers + [TODO] finish list of vars */ class WP_FFPC extends WP_Plugins_Abstract_v2 { const host_separator = ','; @@ -58,18 +60,15 @@ if ( ! class_exists( 'WP_FFPC' ) ) { private $acache_backend = ''; private $button_flush; private $button_precache; - protected $select_cache_type = array (); - protected $select_invalidation_method = array (); - protected $select_schedules = array(); - protected $valid_cache_type = array (); - protected $list_uri_vars = array(); + private $select_cache_type = array (); + private $select_invalidation_method = array (); + private $select_schedules = array(); + private $valid_cache_type = array (); + private $list_uri_vars = array(); private $shell_function = false; private $shell_possibilities = array (); private $backend = NULL; private $scheduled = false; - private $errors = array(); - private $warnings = array(); - private $notices = array(); /** * init hook function runs before admin panel hook, themeing and options read @@ -95,18 +94,9 @@ if ( ! class_exists( 'WP_FFPC' ) ) { $this->precache_phpfile = sys_get_temp_dir() . '/' . self::precache_php; /* search for a system function */ $this->shell_possibilities = array ( 'shell_exec', 'exec', 'system', 'passthru' ); - //$this->shell_possibilities = array ( 'shell_exec' ); + /* get disabled functions list */ $disabled_functions = array_map('trim', explode(',', ini_get('disable_functions') ) ); - $this->notices = array ( - ); - - $this->warnings = array ( - ); - - $this->errors = array ( - ); - foreach ( $this->shell_possibilities as $possible ) { if ( function_exists ($possible) && ! ( ini_get('safe_mode') || in_array( $possible, $disabled_functions ) ) ) { /* set shell function */ @@ -127,7 +117,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { 'memcache' => __( 'PHP Memcache' , $this->plugin_constant ), 'memcached' => __( 'PHP Memcached' , $this->plugin_constant ), ); - + /* check for required functions / classes for the cache types */ $this->valid_cache_type = array ( 'apc' => function_exists( 'apc_sma_info' ) ? true : false, 'memcache' => class_exists ( 'Memcache') ? true : false, @@ -141,6 +131,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { 2 => __( 'modified post and all taxonomies' , $this->plugin_constant ), ); + /* map of possible key masks */ $this->list_uri_vars = array ( '$scheme' => __('The HTTP scheme (i.e. http, https).', $this->plugin_constant ), '$host' => __('Host in the header of request or name of the server processing the request if the Host header is not available.', $this->plugin_constant ), @@ -153,18 +144,19 @@ if ( ! class_exists( 'WP_FFPC' ) ) { //'' => __('', $this->plugin_constant ), ); + /* get current wp_cron schedules */ $wp_schedules = wp_get_schedules(); + /* add 'null' to switch off timed precache */ $schedules['null'] = __( 'do not use timed precache' ); foreach ( $wp_schedules as $interval=>$details ) { $schedules[ $interval ] = $details['display']; } - $this->select_schedules = $schedules; } /** - * additional init, steps that needs the plugin options + * additional init, steps that needs the plugin options * */ public function plugin_setup () { @@ -221,6 +213,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { /** * uninstall hook function, to be extended + * [TODO] static abstraction is not allowed in PHP; how to do this? */ static public function plugin_uninstall( $delete_options = true ) { /* delete advanced-cache.php file */ @@ -240,17 +233,22 @@ if ( ! class_exists( 'WP_FFPC' ) ) { /* save parameter updates, if there are any */ if ( isset( $_POST[ $this->button_flush ] ) ) { + /* remove precache log entry */ $this->_delete_option( self::precache_log ); + /* remove precache timestamp entry */ $this->_delete_option( self::precache_timestamp ); + /* remove precache logfile */ if ( @file_exists ( $this->precache_logfile ) ) { unlink ( $this->precache_logfile ); } + /* remove precache PHP worker */ if ( @file_exists ( $this->precache_phpfile ) ) { unlink ( $this->precache_phpfile ); } + /* flush backend */ $this->backend->clear( false, true ); $this->status = 3; header( "Location: ". $this->settings_link . self::slug_flush ); @@ -259,10 +257,12 @@ if ( ! class_exists( 'WP_FFPC' ) ) { /* save parameter updates, if there are any */ if ( isset( $_POST[ $this->button_precache ] ) ) { + /* is no shell function is possible, fail */ if ( $this->shell_function == false ) { $this->status = 5; header( "Location: ". $this->settings_link . self::slug_precache_disabled ); } + /* otherwise start full precache */ else { $this->precache_message = $this->precache_coldrun(); $this->status = 4; @@ -272,7 +272,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { } /** - * + * admin help panel */ public function plugin_admin_help($contextual_help, $screen_id ) { @@ -318,42 +318,43 @@ if ( ! class_exists( 'WP_FFPC' ) ) { plugin_donation_form(); /** * if options were saved, display saved message */ - if ( ! empty( $this->broadcast_message ) ) : ?> + if ( ! empty( $this->broadcast_message ) ) { ?>
broadcast_message; ?>
- status == 1) : ?> + if (isset($_GET[ self::key_save ]) && $_GET[ self::key_save ]=='true' || $this->status == 1) { ?>

plugin_constant ) ?>

- status == 2) : ?> + if (isset($_GET[ self::key_delete ]) && $_GET[ self::key_delete ]=='true' || $this->status == 2) { ?>

plugin_constant ) ?>

- status == 3) : ?> + if (isset($_GET[ self::key_flush ]) && $_GET[ self::key_flush ]=='true' || $this->status == 3) { ?>

plugin_constant ); ?>

- status == 4) : ?> + if ( ( isset($_GET[ self::key_precache ]) && $_GET[ self::key_precache ]=='true' ) || $this->status == 4) { ?>

plugin_constant ) ?>

- plugin_name ; _e( ' settings', $this->plugin_constant ) ; ?> - +

plugin_constant ); ?>

- + global_saved ) : ?> + if ( ! $this->global_saved ) { ?>

plugin_constant); ?>

plugin_constant ) ?>

- + acache ) ) : ?> + if ( ! file_exists ( $this->acache ) ) { ?>

plugin_constant); ?>

acache , $this->plugin_constant ) ?>

- + options['cache_type'] == 'memcached' && !class_exists('Memcached') ) : ?> + if ( $this->options['cache_type'] == 'memcached' && !class_exists('Memcached') ) { ?>

plugin_constant); ?>

- + options['cache_type'] == 'memcache' && !class_exists('Memcache') ) : ?> + if ( $this->options['cache_type'] == 'memcache' && !class_exists('Memcache') ) { ?>

plugin_constant); ?>

- + options['cache_type'] == 'memcache' ) { - $memcache_settings = ini_get_all( 'memcache' ); - if ( !empty ( $memcache_settings ) && $this->options['cache_type'] == 'memcache' ) - { - $memcache_protocol = strtolower($memcache_settings['memcache.protocol']['local_value']); - if ( $memcached_protocol == 'binary' ) : - ?> + $memcache_protocol = strtolower($memcache_settings['memcache.protocol']['local_value']); + if ( $memcached_protocol == 'binary' ) { ?>

Please consider to change either to ASCII mode or to Memcached extension.', $this->plugin_constant ); ?>

- + } ?>

plugin_constant); echo $this->options['cache_type']; ?>

options['cache_type'], 'memcache') ) : - ?>

Backend status:
', $this->plugin_constant ); + /* only display backend status if memcache-like extension is running */ + if ( strstr ( $this->options['cache_type'], 'memcache') ) { + ?>

Backend status:
', $this->plugin_constant ); - /* we need to go through all servers */ - $servers = $this->backend->status(); - foreach ( $servers as $server_string => $status ) { - echo $server_string ." => "; + /* we need to go through all servers */ + $servers = $this->backend->status(); + foreach ( $servers as $server_string => $status ) { + echo $server_string ." => "; - if ( $status == 0 ) - _e ( 'down
', $this->plugin_constant ); - elseif ( ( $this->options['cache_type'] == 'memcache' && $status > 0 ) || $status == 1 ) - _e ( 'up & running
', $this->plugin_constant ); - else - _e ( 'unknown, please try re-saving settings!
', $this->plugin_constant ); - } + if ( $status == 0 ) + _e ( 'down
', $this->plugin_constant ); + elseif ( ( $this->options['cache_type'] == 'memcache' && $status > 0 ) || $status == 1 ) + _e ( 'up & running
', $this->plugin_constant ); + else + _e ( 'unknown, please try re-saving settings!
', $this->plugin_constant ); + } - ?>

+ ?>

@@ -703,11 +699,12 @@ if ( ! class_exists( 'WP_FFPC' ) ) { plugin_constant ); ?>
- status == 5 || $this->shell_function == false ) : ?> + status == 5 || $this->shell_function == false ) { ?> Since precaching may take a very long time, it's done through a background CLI process in order not to run out of max execution time of PHP. Please enable one of the following functions if you whish to use precaching: " , $this->plugin_constant ) ?>shell_possibilities ); ?> - + - +
The plugin tries to visit links of taxonomy terms without the taxonomy name as well. This may generate 404 hits, please be prepared for these in your logfiles if you plan to pre-cache.', $this->plugin_constant); ?> @@ -1003,15 +1000,16 @@ if ( ! class_exists( 'WP_FFPC' ) ) { if ( file_exists ( $this->precache_phpfile )) { $return = true; } - // TODO: cross-platform process check; this is *nix only - //else { - // /* otherwise try to check if precache is running; */ - // $shellfunction = $this->shell_function; - // $running = $shellfunction( "ps aux | grep \"". $this->precache_phpfile ."\" | grep -v grep | awk '{print $2}'" ); - // if ( is_int( $running ) && $running != 0 ) { - // $return = true; - // } - //} + /* + [TODO] cross-platform process check; this is *nix only + else { + $shellfunction = $this->shell_function; + $running = $shellfunction( "ps aux | grep \"". $this->precache_phpfile ."\" | grep -v grep | awk '{print $2}'" ); + if ( is_int( $running ) && $running != 0 ) { + $return = true; + } + } + */ return $return; } @@ -1105,7 +1103,6 @@ if ( ! class_exists( 'WP_FFPC' ) ) { } - //$this->taxonomy_links ( $links ); $this->backend->taxonomy_links ( $links ); /* just in case, reset $post */ @@ -1118,9 +1115,10 @@ if ( ! class_exists( 'WP_FFPC' ) ) { } /** + * [TODO] this function will be used with error coded log messages * display predefined message based on code * - */ + * private function message ( $code, $type, $echo = true ) { switch ( $type ) { case 'notice': @@ -1138,9 +1136,9 @@ if ( ! class_exists( 'WP_FFPC' ) ) { if ( $echo ) echo $r; else return $r; - } + }*/ } } -?> +?> \ No newline at end of file diff --git a/wp-ffpc.php b/wp-ffpc.php index 3d1ea9e..166ad84 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -53,5 +53,4 @@ $wp_ffpc_defaults = array ( $wp_ffpc = new WP_FFPC ( 'wp-ffpc', '1.2', 'WP-FFPC', $wp_ffpc_defaults, 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC' ); - -?> +?> \ No newline at end of file