WordPress.org

Plugin Directory

Changeset 604128


Ignore:
Timestamp:
09/26/12 12:55:14 (19 months ago)
Author:
japh
Message:

Optimised loading of HTML parsing library

Location:
favorite-plugins/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • favorite-plugins/trunk/favorite-plugins.php

    r604027 r604128  
    44Plugin URI: http://japh.wordpress.com/plugins/favorite-plugins 
    55Description: Quickly and easily access and install your favorited plugins from WordPress.org, right from your dashboard. 
    6 Version: 0.2 
     6Version: 0.3 
    77Author: Japh 
    88Author URI: http://japh.wordpress.com 
     
    3636 * @copyright 2012 Japh 
    3737 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt GPL2 
    38  * @version 0.2 
     38 * @version 0.3 
    3939 * @link http://japh.wordpress.com/plugins/favorite-plugins 
    4040 * @since 0.1 
     
    6262 * @copyright 2012 Japh 
    6363 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt GPL2 
    64  * @version 0.2 
     64 * @version 0.3 
    6565 * @since 0.1 
    6666 */ 
    6767class Japh_Favorite_Plugins { 
    6868 
    69     public $version = '0.2'; 
     69    public $version = '0.3'; 
    7070    public $username = null; 
    7171    public $favorite_plugins = null; 
     
    8888 
    8989        add_action( 'init', array( &$this, 'textdomain' ) ); 
    90         add_action( 'admin_init', array( &$this, 'load_libraries' ) ); 
    9190        add_filter( 'install_plugins_tabs', array( &$this, 'add_favorites_tab' ) ); 
    9291        add_action( 'install_plugins_favorites', array( &$this, 'do_favorites_tab' ) ); 
     
    9493        $this->username = get_option( 'jfp_favorite_user' ); 
    9594        $this->favorite_plugins = get_transient( 'jfp_favourite_plugins' ); 
    96  
    97     } 
    98  
    99     /** 
    100      * Loads any 3rd-party libraries the plugin utilises 
    101      * 
    102      * This function will load in any libraries used by the plugin, currently: 
    103      *  + PHP Simple HTML DOM Parser 
    104      * 
    105      * @since 0.1 
    106      */ 
    107     function load_libraries() { 
    108  
    109         /** Require the PHP Simple HTML DOM Parser library */ 
    110         require( JFP_PLUGIN_DIR . 'lib' . DIRECTORY_SEPARATOR . 'simple_html_dom.php' ); 
    11195 
    11296    } 
     
    244228            $favorite_plugins = array(); 
    245229 
    246             $doc = str_get_html( $body ); 
    247  
    248             foreach ( $doc->find( 'div.main-plugins' ) as $section ) { 
    249  
    250                 $header = $section->find( 'h4' ); 
    251  
    252                 foreach ( $header as $head ) { 
    253  
    254                     if ( strpos( strtolower( $head->innertext ), strtolower( "favorite plugins" ) ) !== false ) { 
    255  
    256                         $favorites_list = $head->next_sibling(); 
    257  
    258                         foreach ( $favorites_list->children() as $favorite ) { 
    259                             if ( ! empty( $favorite->plaintext ) ) { 
    260  
    261                                 $a = $favorite->find( 'a' ); 
    262  
    263                                 foreach ( $a as $link ) { 
    264  
    265                                     $new_favorite = array(); 
    266                                     $new_favorite['name'] = $link->innertext; 
    267                                     $new_favorite['url'] = $link->href; 
    268                                     $slug = explode( '/', $link->href ); 
    269                                     $new_favorite['slug'] = $slug[count( $slug ) - 2]; 
    270  
    271                                     $favorite_plugins[$new_favorite['slug']] = $new_favorite; 
    272  
     230            if ( ! empty( $body ) ) { 
     231                /** Require the PHP Simple HTML DOM Parser library */ 
     232                require( JFP_PLUGIN_DIR . 'lib' . DIRECTORY_SEPARATOR . 'simple_html_dom.php' ); 
     233 
     234                $doc = str_get_html( $body ); 
     235 
     236                foreach ( $doc->find( 'div.main-plugins' ) as $section ) { 
     237 
     238                    $header = $section->find( 'h4' ); 
     239 
     240                    foreach ( $header as $head ) { 
     241 
     242                        if ( strpos( strtolower( $head->innertext ), strtolower( "favorite plugins" ) ) !== false ) { 
     243 
     244                            $favorites_list = $head->next_sibling(); 
     245 
     246                            foreach ( $favorites_list->children() as $favorite ) { 
     247                                if ( ! empty( $favorite->plaintext ) ) { 
     248 
     249                                    $a = $favorite->find( 'a' ); 
     250 
     251                                    foreach ( $a as $link ) { 
     252 
     253                                        $new_favorite = array(); 
     254                                        $new_favorite['name'] = $link->innertext; 
     255                                        $new_favorite['url'] = $link->href; 
     256                                        $slug = explode( '/', $link->href ); 
     257                                        $new_favorite['slug'] = $slug[count( $slug ) - 2]; 
     258 
     259                                        $favorite_plugins[$new_favorite['slug']] = $new_favorite; 
     260 
     261                                    } 
    273262                                } 
    274263                            } 
  • favorite-plugins/trunk/readme.txt

    r604027 r604128  
    44Requires at least: 3.4 
    55Tested up to: 3.4.2 
    6 Stable tag: 0.2 
     6Stable tag: 0.3 
    77License: GPLv2 or later 
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    4242== Changelog == 
    4343 
     44= 0.3 = 
     45* The HTML parsing library is now loaded in a more conservative location, so it's only loaded when needed 
     46 
    4447= 0.2 = 
    4548* Implemented caching with transients 
Note: See TracChangeset for help on using the changeset viewer.