Plugin Directory

Changeset 1113226


Ignore:
Timestamp:
03/15/2015 04:29:21 PM (10 years ago)
Author:
mlazarov
Message:

Versin 3.0.0 - using dom html parser if available

Location:
plugins/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • plugins/trunk/plugins.php

    r888150 r1113226  
    55Plugin URI: http://marto.lazarov.org/plugins/plugins
    66Description: List wordpress contributor plugins and their stats
    7 Version: 2.1.4
     7Version: 3.0.0
    88Author: mlazarov
    99Author URI: http://marto.lazarov.org/
     
    8383                }
    8484                if($settings['updated'] > (time()-600)) continue;
     85
    8586                $url = 'http://profiles.wordpress.org/'.$settings['author'].'/';
    8687                $html = file_get_contents($url);
    87                
    88                 preg_match_all('#<h3>\s+<a href="//wordpress.org/plugins/([^/]+)/">([^<]+)</a>\s+</h3>\s+<p class="downloads">([0-9,]+) downloads</p>#ismU',$html,$matches,PREG_SET_ORDER);
     88           
     89                if(class_exists('DOMDocument') && class_exists('DOMXPath')){
     90                    $this->parseUsingDom($html,$id);
     91                }else{
     92                    $this->parseUsingPreg($html,$id);
     93                }               
    8994
    90                 $this->settings[$id]['plugins'] = array();
    91                 foreach($matches as $k=>$m){
    92                         $this->settings[$id]['plugins'][$m[1]]['name'] = $m[2];
    93                         $this->settings[$id]['plugins'][$m[1]]['downloads'] = $m[3];
    94                 }
    9595                uasort($this->settings[$id]['plugins'],'dlsort');
    9696                $this->settings[$id]['updated'] = time();
    9797            }
    9898            $this->save_settings($this->settings);
     99        }
     100        function parseUsingPreg($html,$id){
     101            preg_match_all('#<h3>\s+<a href="//wordpress.org/plugins/([^/]+)/">([^<]+)</a>\s+</h3>\s+<p class="downloads">([0-9,]+) downloads</p>#ismU',
     102                    $html,$matches,PREG_SET_ORDER);
     103
     104            $this->settings[$id]['plugins'] = array();
     105            foreach($matches as $k=>$m){
     106                $this->settings[$id]['plugins'][$m[1]]['name'] = $m[2];
     107                $this->settings[$id]['plugins'][$m[1]]['downloads'] = $m[3];
     108            }
     109       
     110
     111        }
     112        function parseUsingDom($html,$id){
     113            $dom = new DOMDocument;
     114            $dom->loadHTML($html);
     115            $xpath = new DOMXPath($dom);
     116
     117            $nlist = $xpath->query("//div[@class='plugin-info-container']");
     118            foreach($nlist as $im=>$div){
     119                    if($div->hasChildNodes()){
     120                        $nodes = $div->childNodes;
     121                        //$html = $div->c14n();
     122
     123                        $href = $nodes->item(1)->childNodes->item(1)->getAttribute('href');
     124                        preg_match('#wordpress.org/plugins/([^/]+)#',$href,$m);
     125                        $slug = $m[1];
     126                        $name = trim($nodes->item(1)->textContent);
     127                        $dls = trim($nodes->item(3)->textContent);
     128                       
     129                        $this->settings[$id]['plugins'][$slug]['name'] = $name;
     130                        $this->settings[$id]['plugins'][$slug]['downloads'] = $dls;
     131
     132                    }
     133            }
    99134        }
    100135    }
  • plugins/trunk/readme.txt

    r888149 r1113226  
    2626
    2727== Changelog ==
     28= 3.0.0 =
     29* Adding new html parser method (using dom if available)
    2830
    2931= 2.1.4 =
    30 * Fixin wordpress user profile url and html parsing
     32* Fixing wordpress user profile url and html parsing
    3133
    3234= 2.1.2 =
Note: See TracChangeset for help on using the changeset viewer.