From 67b9d0b3f64a32309adcb8fb106cd62403e3736a Mon Sep 17 00:00:00 2001 From: Peter Molnar Date: Wed, 27 Mar 2013 11:51:25 +0000 Subject: [PATCH] precache comments done, tests done; separated admin part for commands added --- readme.txt | 5 +-- wp-ffpc-admin.css | 60 +++++++++++++++++++++++++++++++++ wp-ffpc-class.php | 85 ++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 132 insertions(+), 18 deletions(-) diff --git a/readme.txt b/readme.txt index f3a9e1d..e8802ea 100644 --- a/readme.txt +++ b/readme.txt @@ -26,6 +26,7 @@ Supports PHP Memcached, PHP Memcache and APC as storage engines, subdomain and d * pingback HTTP header preservation * (optional) talkative log for troubleshooting * multiple memcached upstream support +* possibility of precaching ( requires permalinks ) Many thanks for supporters, testers & bug reporters: [Eric Gilette](http://www.ericgillette.com/ "Eric Gilette"); [doconeill](http://wordpress.org/support/profile/doconeill "doconeill"); [Mark Costlow](mailto:cheeks@swcp.com "Mark Costlow"). @@ -87,8 +88,8 @@ Please post feature requests to [WP-FFPC feature request topic](http://wordpress = 1.1 = *under development* -* added validate caching "noob" method: HTML comment option for cache engine & generation before closing "body" tag -* pre-cache possibility +* HTML comment option for displaying cache info before closing "body" tag ( a.k.a make sure it works "noob" method ) +* precache engine * bugfix for status check ( there were situations where the status was not updated correctly ) = 1.0 = diff --git a/wp-ffpc-admin.css b/wp-ffpc-admin.css index 2b06d3d..8132817 100644 --- a/wp-ffpc-admin.css +++ b/wp-ffpc-admin.css @@ -132,3 +132,63 @@ background-image: linear-gradient(to top,#ececec,#f9f9f9); outline: none; } + + +.button-warning { + display: inline-block; + text-decoration: none; + font-size: 12px; + line-height: 23px; + height: 24px; + margin: 0; + padding: 0 10px 1px; + cursor: pointer; + border-width: 1px; + border-style: solid; + -webkit-border-radius: 3px; + -webkit-appearance: none; + border-radius: 3px; + white-space: nowrap; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + background: #f3f3f3; + background-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#f4f4f4)); + background-image: -webkit-linear-gradient(top, #fefefe, #f4f4f4); + background-image: -moz-linear-gradient(top, #fefefe, #f4f4f4); + background-image: -o-linear-gradient(top, #fefefe, #f4f4f4); + background-image: linear-gradient(to bottom, #fefefe, #f4f4f4); + border-color: #bbb; + color: #900; + text-shadow: 0 1px 0 #fff; +} + +.button-warning:hover, +.button-warning:focus { + background: #f3f3f3; + background-image: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#f3f3f3)); + background-image: -webkit-linear-gradient(top, #fff, #f3f3f3); + background-image: -moz-linear-gradient(top, #fff, #f3f3f3); + background-image: -ms-linear-gradient(top, #fff, #f3f3f3); + background-image: -o-linear-gradient(top, #fff, #f3f3f3); + background-image: linear-gradient(to bottom, #fff, #f3f3f3); + border-color: #900; + color: #a00; + -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.2); + box-shadow: 1px 1px 1px rgba(0,0,0,.2); +} + +.button-warning:active { + background: #eee; + background-image: -webkit-gradient(linear, left top, left bottom, from(#f4f4f4), to(#fefefe)); + background-image: -webkit-linear-gradient(top, #f4f4f4, #fefefe); + background-image: -moz-linear-gradient(top, #f4f4f4, #fefefe); + background-image: -ms-linear-gradient(top, #f4f4f4, #fefefe); + background-image: -o-linear-gradient(top, #f4f4f4, #fefefe); + background-image: linear-gradient(to bottom, #f4f4f4, #fefefe); + border-color: #900; + color: #a00; + text-shadow: 0 -1px 0 #fff; + -webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); + box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); +} diff --git a/wp-ffpc-class.php b/wp-ffpc-class.php index 85d2dfd..3030681 100644 --- a/wp-ffpc-class.php +++ b/wp-ffpc-class.php @@ -224,6 +224,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { @@ -266,13 +267,6 @@ if ( ! class_exists( 'WP_FFPC' ) ) {

plugin_constant ) ?>

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

- - shell_function == false ) ? 'disabled="disabled"' : '' ; ?> - class="button-primary" type="submit" name="button_precache ?>" id="button_precache ?>" value="plugin_constant ) ?>" /> - - - -

+ +
+ + + +
+ plugin_constant ); ?> +
+
+ 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 ); ?> + + + +
+
+ plugin_constant); ?> +
+
+
+
+ plugin_constant ); ?> +
+
+ +
+
+ plugin_constant ); ?> +
+
+
+
+ plugin_constant ); ?> +
+
+ +
+
+ plugin_constant ); ?> +
+
+
+
network ) { + /* list all blogs */ $blog_list = get_blog_list( 0, 'all' ); foreach ($blog_list as $blog) { + /* get permalinks for this blog */ $this->precache_list_permalinks ( $links, $blog['blog_id'] ); } } else { + /* no network, better */ $this->precache_list_permalinks ( $links, false ); } + /* temporary php file, will destroy itself after finish in order to clean up */ $tmpfile = tempnam(sys_get_temp_dir(), 'wp-ffpc'); + /* double check if we do have any links to pre-cache */ if ( !empty ( $links ) ) : + /* this is the precacher php worker file: logs the links, their generation time and the generated content size + * writes the logfile and destroys itself afterwards + */ $out .= ''; file_put_contents ( $tmpfile, $out ); + /* call the precache worker file in the background */ $shellfunction = $this->shell_function; $shellfunction( 'php '. $tmpfile .' >'. $this->precache_logfile .' 2>&1 &' ); @@ -827,25 +873,29 @@ if ( ! class_exists( 'WP_FFPC' ) ) { * */ private function precache_list_permalinks ( &$links, $site = false ) { + /* $post will be populated when running throught the posts */ global $post; include_once ( ABSPATH . "wp-load.php" ); + /* if a site id was provided, save current blog and change to the other site */ if ( $site !== false ) { $current_blog = get_current_blog_id(); switch_to_blog( $site ); } + /* get all published posts */ $args = array ( 'post_type' => 'any', 'posts_per_page' => -1, 'post_status' => 'publish', ); - $posts = new WP_Query( $args ); + /* get all the posts, one by one */ while ( $posts->have_posts() ) { $posts->the_post(); + /* get the permalink for currently selected post */ switch ($post->post_type) { case 'revision': case 'nav_menu_item': @@ -864,12 +914,15 @@ if ( ! class_exists( 'WP_FFPC' ) ) { break; } + /* collect permalinks */ $links[] = $permalink; } + /* just in case, reset $post */ wp_reset_postdata(); + /* switch back to original site if we navigated away */ if ( $site !== false ) { switch_to_blog( $current_blog ); }