Plugin Directory

Changeset 360755


Ignore:
Timestamp:
03/16/2011 02:26:34 PM (15 years ago)
Author:
rukbat
Message:

Upgrade to version 1.3

Location:
nginx-manager/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • nginx-manager/trunk/nginx-manager.php

    r336473 r360755  
    22/*
    33Plugin Name: NGINX Manager
    4 Plugin URI: http://www.contactlab.com/
     4Plugin URI: http://wordpress.org/extend/plugins/nginx-manager/
    55Description: Manage Nginx cache
    66Author: Simone Fumagalli & Marco Zanzottera
    7 Version: 1.2.2
     7Version: 1.3
    88Author URI: http://www.iliveinperego.com
    99Network: true
     
    4444    class nginxmLoader {
    4545       
    46         var $version            = '1.2.2'; // Plugin version
    47         var $db_version         = '1.2'; // DB version, change it to show the upgrade page
     46        var $version            = '1.3'; // Plugin version
     47        var $db_version         = '1.3'; // DB version, change it to show the upgrade page
    4848        var $minium_WP          = '3.0';
    4949        var $options            = null;
     
    118118            add_action( 'wpmu_new_blog', array(&$this, 'update_new_blog_options'), 10, 1 );
    119119           
     120            /* Purge when a post is moved to the Trash, @since Nginx Manager 1.3 */
     121            add_action( 'transition_post_status', array(&$nginxmNginx, 'purge_on_post_moved_to_trash'), 20, 3 );
     122           
    120123           
    121124            /* Integrations with other plugins */
  • nginx-manager/trunk/nginxmNginx.php

    r336473 r360755  
    6969            global $blog_id;
    7070           
    71             // Retrieves post ID.
    72             $_comment = get_comment( $_comment_id );
    73             $_post_id = $_comment->comment_post_ID;
    74            
    75             $this->log( "* * * * *" );
    76             $this->log( "* Blog :: ".addslashes( get_bloginfo('name') )." ($blog_id)." );
    77             $this->log( "* Post :: ".get_the_title($_post_id)." ($_post_id)." );
    78             $this->log( "* Comment :: $_comment_id." );
    79            
    80             switch ( current_filter() ) {
    81                 case 'comment_post':
    82                     $this->log( "* New comment ($_comment_id) saved in the database. Let's purge the post ($_post_id)." );
    83                     break;
    84                 case 'wp_set_comment_status':
    85                     $this->log( "* Comment ($_comment_id) set to status '$_comment_status'. Let's purge the post ($_post_id)." );
    86                     break;
    87             }
    88            
    89             $this->log( "* * * * *" );
    90            
    91             // Calls purgePost().
    92             $this->purgePost( $_post_id );
     71            if ( $_comment_status != 'delete' ) {
     72               
     73                // Retrieves post ID.
     74                $_comment = get_comment( $_comment_id );
     75                $_post_id = $_comment->comment_post_ID;
     76               
     77                $this->log( "* * * * *" );
     78                $this->log( "* Blog :: ".addslashes( get_bloginfo('name') )." ($blog_id)." );
     79                $this->log( "* Post :: ".get_the_title($_post_id)." ($_post_id)." );
     80                $this->log( "* Comment :: $_comment_id." );
     81               
     82                switch ( current_filter() ) {
     83                    case 'comment_post':
     84                        $this->log( "* New comment ($_comment_id) saved in the database. Let's purge the post ($_post_id)." );
     85                        break;
     86                    case 'wp_set_comment_status':
     87                        $this->log( "* Comment ($_comment_id) set to status '$_comment_status'. Let's purge the post ($_post_id)." );
     88                        break;
     89                }
     90               
     91                $this->log( "* * * * *" );
     92               
     93                // Calls purgePost().
     94                $this->purgePost( $_post_id );
     95               
     96            }
    9397           
    9498        }
     
    149153                    }
    150154                } else {
    151                     $this->log( "No personal urls available" );
     155                    $this->log( "- ".__( "No personal urls available", "nginxm" ) );
    152156                }
    153157            }
     
    259263        }
    260264       
    261        
     265        /**
     266         * Purge the URL, if 'feed' then purge related feed page also.
     267         * Used in the external script to purge the homepage.
     268         *
     269         * @param $url
     270         * @param $feed
     271         * @return unknown_type
     272         */
    262273        function purgeUrl($url, $feed = true) {
    263274           
     
    384395        }
    385396       
     397        /**
     398         * Purge URLs when a post is moved to the Trash.
     399         * Hooked by 'transition_post_status'.
     400         *
     401         * @param $new_status
     402         * @param $old_status
     403         * @param $post
     404         * @return Boolean
     405         *
     406         * @since Nginx Manager 1.3
     407         */
     408        function purge_on_post_moved_to_trash( $new_status, $old_status, $post ) {
     409           
     410            global $nginxm, $blog_id;
     411           
     412            if ($new_status == 'trash') {
     413               
     414                $this->log( "# # # # #" );
     415                $this->log( "# Post '$post->post_title' (id $post->ID) moved to the trash." );
     416                $this->log( "# # # # #" );
     417               
     418                $this->log( "Function purge_on_post_moved_to_trash (post id $post->ID) BEGIN ===" );
     419               
     420                if ($nginxm->options['automatically_purge_all_on_delete']) {
     421                   
     422                    // Let's purge all the blog
     423                    $this->_purge_them_all();
     424                   
     425                } else {
     426                   
     427                    /* Homepage */
     428                    if ( $nginxm->options['automatically_purge_homepage'] == 1 ) {
     429                        $this->_purge_homepage();
     430                    }
     431                   
     432                    /* Personal URLs */
     433                    if ( $nginxm->options['automatically_purge_purls'] == 1 ) {
     434                        $this->_purge_personal_urls();
     435                    }
     436                   
     437                    // Purge archives and custom taxa by options
     438                    $this->_purge_by_options( $post->ID, $blog_id, false, $nginxm->options['automatically_purge_archives_on_delete'], $nginxm->options['automatically_purge_customtaxa_on_delete'] );
     439                   
     440                }
     441               
     442                $this->log( "Function purge_on_post_moved_to_trash (post id $post->ID) END ===" );
     443               
     444            }
     445           
     446            return true;
     447           
     448        }
     449       
     450        /**
     451         * Purge blog homepage
     452         *
     453         * @return Boolean
     454         * @since Nginx Manager 1.3
     455         */
     456        private function _purge_homepage() {
     457           
     458            $homepage_url = trailingslashit( get_option( 'siteurl' ) );
     459           
     460            $this->log( sprintf( __( "Purging homepage '%s'", "nginxm" ), $homepage_url ) );
     461            $this->purgeUrl( $homepage_url );
     462           
     463            return true;
     464           
     465        }
     466       
     467        /**
     468         * Purge the personal URLs
     469         *
     470         * @return Boolean
     471         * @since Nginx Manager 1.3
     472         */
     473        private function _purge_personal_urls() {
     474           
     475            global $nginxm;
     476           
     477            $this->log( __( "Purging personal urls", "nginxm" ) );
     478           
     479            if (isset($nginxm->options['purgeable_url']['urls'])) {
     480               
     481                foreach ($nginxm->options['purgeable_url']['urls'] as $u) {
     482                    $this->purgeUrl($u, false);
     483                }
     484               
     485            } else {
     486                $this->log( "- ".__( "No personal urls available", "nginxm" ) );
     487            }
     488           
     489            return true;
     490           
     491        }
     492       
     493        /**
     494         * Purge the categories archives post-related
     495         *
     496         * @param $_post_id
     497         * @return Boolean
     498         * @since Nginx Manager 1.3
     499         */
     500        private function _purge_post_categories( $_post_id ) {
     501           
     502            $this->log( __( "Purging category archives", "nginxm" ) );
     503           
     504            if ( $categories = wp_get_post_categories( $_post_id ) ) {
     505                foreach ( $categories as $category_id ) {
     506                    $this->log( sprintf( __( "Purging category '%d'", "nginxm" ), $category_id ) );
     507                    $this->purgeUrl( get_category_link( $category_id ) );
     508                }
     509            }
     510           
     511            return true;
     512           
     513        }
     514       
     515        /**
     516         * Purge the post tags archives post-related
     517         *
     518         * @param $_post_id
     519         * @return Boolean
     520         * @since Nginx Manager 1.3
     521         */
     522        private function _purge_post_tags( $_post_id ) {
     523           
     524            $this->log( __( "Purging tags archives", "nginxm" ) );
     525           
     526            if ( $tags = get_the_tags( $_post_id ) ) {
     527                foreach ( $tags as $tag ) {
     528                    $this->log( sprintf( __( "Purging tag '%s' (id %d)", "nginxm" ), $tag->name, $tag->term_id ) );
     529                    $this->purgeUrl( get_tag_link( $tag->term_id ) );
     530                }
     531            }
     532           
     533            return true;
     534           
     535        }
     536       
     537        /**
     538         * Purge the custom taxonomies terms post-related
     539         *
     540         * @param $_post_id
     541         * @return Boolean
     542         * @since Nginx Manager 1.3
     543         */
     544        private function _purge_post_custom_taxa( $_post_id ) {
     545           
     546            $this->log( __( "Purging post custom taxonomies related", "nginxm" ) );
     547           
     548            if ( $custom_taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) ) ) {
     549               
     550                foreach ( $custom_taxonomies as $taxon ) {
     551                    $this->log( sprintf( "+ ".__( "Purging custom taxonomy '%s'", "nginxm" ), $taxon ) );
     552                   
     553                    // Extra check to get rid of the standard taxonomies
     554                    if ( !in_array( $taxon, array( 'category', 'post_tag', 'link_category' ) ) ) {
     555                       
     556                        if ( $terms = get_the_terms( $_post_id, $taxon ) ) {
     557                            foreach ( $terms as $term ) {
     558                                $this->purgeUrl( get_term_link( $term, $taxon ) );
     559                            }
     560                        }
     561                       
     562                    } else {
     563                        $this->log( sprintf( "- ".__( "Your built-in taxonomy '%s' has param '_builtin' set to false.", "nginxm" ), $taxon ), "WARNING" );
     564                    }
     565                }
     566               
     567            } else {
     568                $this->log( "- ".__( "No custom taxonomies", "nginxm" ) );
     569            }
     570           
     571            return true;
     572           
     573        }
     574       
     575        /**
     576         * Purge all the categories archives URL
     577         *
     578         * @return Boolean
     579         * @since Nginx Manager 1.3
     580         */
     581        private function _purge_all_categories() {
     582           
     583            $this->log( __( "Purging all categories", "nginxm" ) );
     584           
     585            if ( $_categories = get_categories() ) {
     586               
     587                foreach ( $_categories as $c ) {
     588                    $this->log( sprintf( __( "Purging category '%s' (id %d)", "nginxm" ), $c->name, $c->term_id ) );
     589                    $this->purgeUrl( get_category_link( $c->term_id ) );
     590                }
     591               
     592            } else {
     593                $this->log( __( "No categories archives", "nginxm" ) );
     594            }
     595           
     596            return true;
     597           
     598        }
     599       
     600        /**
     601         * Purge all the post tags archives URL
     602         *
     603         * @return Boolean
     604         * @since Nginx Manager 1.3
     605         */
     606        private function _purge_all_posttags() {
     607           
     608            $this->log( __( "Purging all tags", "nginxm" ) );
     609           
     610            if ( $_posttags = get_tags() ) {
     611               
     612                foreach ( $_posttags as $t ) {
     613                    $this->log( sprintf( __( "Purging tag '%s' (id %d)", "nginxm" ), $t->name, $t->term_id ) );
     614                    $this->purgeUrl( get_tag_link( $t->term_id ) );
     615                }
     616               
     617            } else {
     618                $this->log( __( "No tags archives", "nginxm" ) );
     619            }
     620           
     621            return true;
     622           
     623        }
     624       
     625        /**
     626         * Purge all the custom taxonomies terms URL
     627         *
     628         * @return Boolean
     629         * @since Nginx Manager 1.3
     630         */
     631        private function _purge_all_customtaxa() {
     632           
     633            $this->log( __( "Purging all custom taxonomies", "nginxm" ) );
     634           
     635            if ( $custom_taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) ) ) {
     636               
     637                foreach ( $custom_taxonomies as $taxon ) {
     638                    $this->log( sprintf( "+ ".__( "Purging custom taxonomy '%s'", "nginxm" ), $taxon ) );
     639                   
     640                    // Extra check to get rid of the standard taxonomies
     641                    if ( !in_array( $taxon, array( 'category', 'post_tag', 'link_category' ) ) ) {
     642                       
     643                        if ( $terms = get_terms( $taxon ) ) {
     644                            foreach ( $terms as $term ) {
     645                                $this->purgeUrl( get_term_link( $term, $taxon ) );
     646                            }
     647                        }
     648                       
     649                    } else {
     650                        $this->log( sprintf( "- ".__( "Your built-in taxonomy '%s' has param '_builtin' set to false.", "nginxm" ), $taxon ), "WARNING" );
     651                    }
     652                }
     653               
     654            } else {
     655                $this->log( "- ".__( "No custom taxonomies", "nginxm" ) );
     656            }
     657           
     658            return true;
     659           
     660        }
     661       
     662        /**
     663         * Purge all the taxonomies: categories, post tags and custom taxonomies
     664         *
     665         * @return Boolean
     666         * @since Nginx Manager 1.3
     667         */
     668        private function _purge_all_taxonomies() {
     669           
     670            $this->_purge_all_categories();
     671            $this->_purge_all_posttags();
     672            $this->_purge_all_customtaxa();
     673           
     674            return true;
     675        }
     676       
     677        /**
     678         * Purge all posts, pages and custom post types.
     679         *
     680         * @return Boolean
     681         * @since Nginx Manager 1.3
     682         */
     683        private function _purge_all_posts() {
     684           
     685            $this->log( __( "Purging all posts, pages and custom post types.", "nginxm" ) );
     686           
     687            $args = array(
     688                'numberposts'     => 0,
     689                'post_type'       => 'any',
     690                'post_status'     => 'publish' );
     691           
     692            if ( $_posts = get_posts($args) ) {
     693               
     694                foreach ( $_posts as $p ) {
     695                    $this->log( sprintf(  "+ ".__( "Purging post id '%d' (post type '%s')", "nginxm" ), $p->ID, $p->post_type ) );
     696                    $this->purgeUrl( get_permalink( $p->ID ) );
     697                }
     698               
     699            } else {
     700                $this->log( "- ".__( "No posts", "nginxm" ) );
     701            }
     702           
     703            return true;
     704           
     705        }
     706       
     707       
     708        /**
     709         * Purge all date-based archives: daily, monthly and yearly.
     710         *
     711         * @return Boolean
     712         * @since Nginx Manager 1.3
     713         */
     714        private function _purge_all_date_archives() {
     715           
     716            $this->log( __( "Purging all date-based archives.", "nginxm" ) );
     717           
     718            $this->_purge_all_daily_archives();
     719           
     720            $this->_purge_all_monthly_archives();
     721           
     722            $this->_purge_all_yearly_archives();
     723           
     724            return true;
     725           
     726        }
     727       
     728        /**
     729         * Purge all daily archives
     730         * @since Nginx Manager 1.3
     731         */
     732        private function _purge_all_daily_archives() {
     733           
     734            global $wpdb;
     735           
     736            $this->log( __( "Purging all daily archives.", "nginxm" ) );
     737           
     738            /* Daily archives */
     739            $_query_daily_archives = $wpdb->prepare(
     740                "SELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month', DAYOFMONTH(post_date) AS 'dayofmonth', count(ID) as posts
     741                FROM $wpdb->posts
     742                WHERE post_type = 'post' AND post_status = 'publish'
     743                GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date)
     744                ORDER BY post_date DESC"
     745            );
     746           
     747            if ( $_daily_archives = $wpdb->get_results( $_query_daily_archives ) ) {
     748               
     749                foreach( $_daily_archives as $_da ) {
     750                    $this->log( sprintf(  "+ ".__( "Purging daily archive '%s/%s/%s'", "nginxm" ), $_da->year, $_da->month, $_da->dayofmonth ) );
     751                    $this->purgeUrl( get_day_link( $_da->year, $_da->month, $_da->dayofmonth ) );
     752                }
     753               
     754            } else {
     755                $this->log( "- ".__( "No daily archives", "nginxm" ) );
     756            }
     757           
     758        }
     759       
     760        /**
     761         * Purge all monthly archives
     762         * @since Nginx Manager 1.3
     763         */
     764        private function _purge_all_monthly_archives() {
     765           
     766            global $wpdb;
     767           
     768            $this->log( __( "Purging all monthly archives.", "nginxm" ) );
     769           
     770            /* Monthly archives */
     771            $_query_monthly_archives = $wpdb->prepare(
     772                "SELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month', count(ID) as posts
     773                FROM $wpdb->posts
     774                WHERE post_type = 'post' AND post_status = 'publish'
     775                GROUP BY YEAR(post_date), MONTH(post_date)
     776                ORDER BY post_date DESC"
     777            );
     778           
     779            if ( $_monthly_archives = $wpdb->get_results( $_query_monthly_archives ) ) {
     780               
     781                foreach( $_monthly_archives as $_ma ) {
     782                    $this->log( sprintf(  "+ ".__( "Purging monthly archive '%s/%s'", "nginxm" ), $_ma->year, $_ma->month ) );
     783                    $this->purgeUrl( get_month_link( $_ma->year, $_ma->month ) );
     784                }
     785               
     786            } else {
     787                $this->log( "- ".__( "No monthly archives", "nginxm" ) );
     788            }
     789           
     790        }
     791       
     792        /**
     793         * Purge all yearly archives
     794         * @since Nginx Manager 1.3
     795         */
     796        private function _purge_all_yearly_archives() {
     797           
     798            global $wpdb;
     799           
     800            $this->log( __( "Purging all yearly archives.", "nginxm" ) );
     801           
     802            /* Yearly archives */
     803            $_query_yearly_archives = $wpdb->prepare(
     804                "SELECT YEAR(post_date) AS 'year', count(ID) as posts
     805                FROM $wpdb->posts
     806                WHERE post_type = 'post' AND post_status = 'publish'
     807                GROUP BY YEAR(post_date)
     808                ORDER BY post_date DESC"
     809            );
     810           
     811            if ( $_yearly_archives = $wpdb->get_results( $_query_yearly_archives ) ) {
     812               
     813                foreach( $_yearly_archives as $_ya ) {
     814                    $this->log( sprintf(  "+ ".__( "Purging yearly archive '%s'", "nginxm" ), $_ya->year ) );
     815                    $this->purgeUrl( get_year_link( $_ya->year ) );
     816                }
     817               
     818            } else {
     819                $this->log( "- ".__( "No yearly archives", "nginxm" ) );
     820            }
     821           
     822        }
     823       
     824        /**
     825         * Purge all the blog: homepage, personal urls, posts/pages/custom post types, taxonomies, date-based archives.
     826         *
     827         * @return Boolean
     828         * @since Nginx Manager 1.3
     829         */
     830        private function _purge_them_all() {
     831           
     832            $this->log( __( "LET'S PURGE ALL THE BLOG.", "nginxm" ) );
     833           
     834            $this->_purge_homepage();
     835           
     836            $this->_purge_personal_urls();
     837           
     838            // posts, pages, custom post types
     839            $this->_purge_all_posts();
     840           
     841            // categories, post tags, custom taxonomies
     842            $this->_purge_all_taxonomies();
     843           
     844            // daily, monthly and yearly archives
     845            $this->_purge_all_date_archives();
     846           
     847            return true;
     848           
     849        }
     850       
    386851    }
    387852   
  • nginx-manager/trunk/readme.txt

    r336473 r360755  
    33Tags: cache, nginx, purge, performance
    44Requires at least: 3.0
    5 Tested up to: 3.0.4
     5Tested up to: 3.1
    66Stable tag: trunk
    77
     
    6363== Changelog ==
    6464
     65= 1.3 (2011 03 16) =
     66* NEW : Purge when a post is moved to the trash: you can choose between purge by options or purge all the blog
     67* BUG : Fixed purge of comments: do not purge when status is set to 'delete'
     68
    6569= 1.2.2 (2011 01 24) =
    6670* BUG : Fixed purge when comments are approved/trashed/etc
Note: See TracChangeset for help on using the changeset viewer.