+
+
+
+ plugin_donation_form();
+ /**
+ * if options were saved, display saved message
+ */
+ if ( ! empty( $this->broadcast_message ) ) : ?>
+
broadcast_message; ?>
+ status == 1) : ?>
+
+ status == 2) : ?>
+
+ status == 3) : ?>
+
+
+
+
plugin_name ; _e( ' settings', $this->plugin_constant ) ; ?>
+
+
+
+
+
+ global_saved ) : ?>
+
plugin_constant); ?>
plugin_constant ) ?>
+
+
+ acache ) ) : ?>
+
plugin_constant); ?>
acache , $this->plugin_constant ) ?>
+
+
+ options['cache_type'] == 'memcached' && !class_exists('Memcached') ) : ?>
+
+
+
+ options['cache_type'] == 'memcache' && !class_exists('Memcache') ) : ?>
+
+
+
+ options['cache_type'] == 'memcache' )
+ {
+ $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 );
+
+ /* 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 ( $status == 1 )
+ _e ( 'up & running
', $this->plugin_constant );
+ else
+ _e ( 'unknown, please try re-saving settings!
', $this->plugin_constant );
+ }
+
+ ?>
+
+
+
+ button_flush ] ) ) {
+ $this->backend->clear();
+ $this->status = 3;
+ header( "Location: ". $this->settings_link . self::slug_flush );
+ }
+ }
+
+ /**
+ * extending options_save
+ *
+ */
+ public function plugin_hook_options_save( $activating ) {
+
+ /* flush the cache when news options are saved, not needed on activation */
+ if ( !$activating )
+ $this->backend->clear();
+
+ /* create the to-be-included configuration for advanced-cache.php */
+ $this->update_global_config();
+
+ /* create advanced cache file, needed only once or on activation, because there could be lefover advanced-cache.php from different plugins */
+ if ( !$activating )
+ $this->deploy_acache();
+
+ }
+
+ /**
+ * read hook; needs to be implemented
+ */
+ public function plugin_hook_options_read( &$options ) {
+ /* read the global options, network compatibility */
+ $this->global_config = get_site_option( $this->global_option );
+
+ /* check if current site present in global config */
+ if ( !empty ( $this->global_config[ $this->global_config_key ] ) )
+ $this->global_saved = true;
+
+ $this->global_config[ $this->global_config_key ] = $options;
+ }
+
+ /**
+ * options delete hook; needs to be implemented
+ */
+ public function plugin_hook_options_delete( ) {
+ delete_site_option ( $this->global_option );
+ }
+
+ /**
+ * need to do migrations from previous versions of the plugin
+ *
+ */
+ public function plugin_hook_options_migrate( &$options ) {
+
+ if ( $options['version'] != $this->plugin_version || !isset ( $options['version'] ) ) {
+
+ /* cleanup possible leftover files from previous versions */
+ $check = array ( 'advanced-cache.php', 'nginx-sample.conf', 'wp-ffpc.admin.css', 'wp-ffpc-common.php' );
+ foreach ( $check as $fname ) {
+ $fname = $this->plugin_dir . $fname;
+ if ( file_exists ( $fname ) )
+ unlink ( $fname );
+ }
+
+ /* updating from version 0.4.x */
+ if ( !empty ( $options['host'] ) ) {
+ $options['hosts'] = $options['host'] . ':' . $options['port'];
+ }
+ /* migrating from version 0.6.x */
+ elseif ( is_array ( $options ) && array_key_exists ( $this->global_config_key , $options ) ) {
+ $options = $options[ $this->global_config_key ];
+ }
+ /* migrating from something, drop previous config */
+ else {
+ $options = array();
+ }
+ /* renamed options */
+ $options['log'] = $options['syslog'];
+ $options['response_header'] = $options['debug'];
+ }
+ }
+
+ /**
+ * advanced-cache.php creator function
+ *
+ */
+ private function deploy_acache( ) {
+
+ /* in case advanced-cache.php was already there, remove it */
+ if ( @file_exists( $this->acache ))
+ unlink ($this->acache);
+
+ /* is deletion was unsuccessful, die, we have no rights to do that, fail */
+ if ( @file_exists( $this->acache ))
+ return false;
+
+ /* if no active site left no need for advanced cache :( */
+ if ( empty ( $this->global_config ) )
+ return false;
+
+ /* add the required includes and generate the needed code */
+ $string[] = "global_config, true ) . ';' ;
+ $string[] = "include_once ('" . $this->acache_backend . "');";
+ $string[] = "include_once ('" . $this->acache_worker . "');";
+ $string[] = "?>";
+
+ /* write the file and start caching from this point */
+ return file_put_contents( $this->acache, join( "\n" , $string ) );
+ }
+
+ /**
+ * function to generate working example from the nginx sample file
+ *
+ * @return string nginx config file
+ *
+ */
+ private function nginx_example () {
+ /* read the sample file */
+ $nginx = file_get_contents ( $this->nginx_sample );
+
+ /* this part is not used when the cache is turned on for logged in users */
+ $loggedin = '# avoid cache for logged in users
+ if ($http_cookie ~* "comment_author_|wordpressuser_|wp-postpass_" ) {
+ set $memcached_request 0;
+ }';
+
+ /* replace the data prefix with the configured one */
+ $nginx = str_replace ( 'DATAPREFIX' , $this->options['prefix_data'] , $nginx );
+
+ /* set upstream servers from configured servers, best to get from the actual backend */
+ $servers = $this->backend->get_servers();
+ foreach ( array_keys( $servers ) as $server ) {
+ $nginx_servers .= " server ". $server .";\n";
+ }
+ $nginx = str_replace ( 'MEMCACHED_SERVERS' , $nginx_servers , $nginx );
+
+ /* add logged in cache, if valid */
+ if ( ! $this->options['cache_loggedin'])
+ $nginx = str_replace ( 'LOGGEDIN_EXCEPTION' , $loggedin , $nginx );
+ else
+ $nginx = str_replace ( 'LOGGEDIN_EXCEPTION' , '' , $nginx );
+
+ return $nginx;
+ }
+
+ /**
+ * function to update global configuration
+ *
+ * @param boolean $remove_site Bool to remove or add current config to global
+ *
+ */
+ private function update_global_config ( $remove_site = false ) {
+
+ /* remove or add current config to global config */
+ if ( $remove_site ) {
+ unset ( $this->global_config[ $this->global_config_key ] );
+ }
+ else {
+ $this->global_config[ $this->global_config_key ] = $this->options;
+ }
+
+ /* deploy advanced-cache.php */
+ $this->deploy_acache ();
+
+ /* save options to database */
+ update_site_option( $this->global_option , $this->global_config );
+ }
+
+ }
+}
+
+?>
diff --git a/wp-ffpc-nginx-sample.conf b/wp-ffpc-nginx-sample.conf
new file mode 100644
index 0000000..b9f7e87
--- /dev/null
+++ b/wp-ffpc-nginx-sample.conf
@@ -0,0 +1,51 @@
+http {
+ ...
+ upstream memcached-servers {
+MEMCACHED_SERVERS
+ }
+ ...
+ server {
+ ...
+
+ # try to get result from memcached
+ location @memcached {
+ default_type text/html;
+ set $memcached_key DATAPREFIX$scheme://$host$request_uri;
+ set $memcached_request 1;
+
+ # exceptions
+ # avoid cache serve of POST requests
+ if ($request_method = POST ) {
+ set $memcached_request 0;
+ }
+
+ # avoid cache serve of wp-admin-like pages, starting with "wp-"
+ if ( $uri ~ "/wp-" ) {
+ set $memcached_request 0;
+ }
+
+ LOGGEDIN_EXCEPTION
+
+ if ( $memcached_request = 1) {
+ memcached_pass memcached-servers;
+ error_page 404 = @rewrites;
+ }
+
+ if ( $memcached_request = 0) {
+ rewrite ^ /index.php$request_uri last;
+ }
+ }
+
+ ## rewrite rules
+ location @rewrites {
+ rewrite ^ /index.php$request_uri last;
+ }
+
+ location / {
+ try_files $uri $uri/ @memcached;
+ }
+
+ ...
+ }
+}
+...