Assembla home | Assembla project page
 

Changeset 130

Show
Ignore:
Timestamp:
03/06/08 03:03:21 (9 months ago)
Author:
tobias382
Message:

* Added support for global and per-feed filters by URL, title, and body to the FeedTicker? plugin (thanks Slynderdale)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Plugin/FeedTicker.php

    r104 r130  
    2727 
    2828    /** 
     29    * Filter feed title data 
     30    * 
     31    * @see run() 
     32    * @var array 
     33    */ 
     34    protected $filterTitle = null; 
     35 
     36    /** 
     37    * Filter feed url data 
     38    * 
     39    * @see run() 
     40    * @var array 
     41    */ 
     42    protected $filterUrl = null; 
     43 
     44    /** 
     45    * Filter article title data 
     46    * 
     47    * @see run() 
     48    * @var array 
     49    */ 
     50    protected $filterArticle = null; 
     51 
     52    /** 
    2953    * Cache of the last update to check for new entries 
    3054    * 
     
    6589    * @return void 
    6690    */ 
    67     public function init() 
    68     { 
     91        public function init() 
     92        { 
     93        // Global Feed Title, Feed URL and Article Title Filters 
     94        $globalTitle = trim($this->getPluginIni('filter_title')); 
     95                $globalUrl = trim($this->getPluginIni('filter_url')); 
     96        $globalArticle = trim($this->getPluginIni('filter_article')); 
     97         
    6998        $i = 0; 
    7099        $this->feeds = array(); 
    71100        do { 
     101                // Feed and Chan data 
    72102            $feed = $this->getPluginIni('feed' . $i); 
    73             $chans = $this->getPluginIni('chans' . $i); 
     103            $chans = $this->getPluginIni('chans' . $i);       
     104            // Feed Title, Feed URL and Article Title Filter Data 
     105            $filterTitle = $this->getPluginIni('filter_title' . $i); 
     106            $filterUrl = $this->getPluginIni('filter_url' . $i); 
     107            $filterArticle = $this->getPluginIni('filter_article' . $i); 
     108                       
    74109            if (!empty($feed) && !empty($chans)) { 
    75110                $this->feeds[] = array($feed, preg_split('#[\s\r\n,]+#', $chans)); 
     111                // Feed Title, Feed URL and Article Title Filters 
     112                $this->filterTitle[] = trim(trim(implode('|', array($globalTitle, $filterTitle)), '|')); 
     113                $this->filterUrl[] = trim(trim(implode('|', array($globalUrl, $filterUrl)), '|')); 
     114                $this->filterArticle[] = trim(trim(implode('|', array($globalArticle, $filterArticle)), '|')); 
    76115            } 
    77116        } while (++$i < 10); 
     
    188227            $articles = array_reverse($articles); 
    189228            foreach ($articles as $article) { 
    190                 if (!isset ($this->cache[$id]) 
    191                     || array_search($article, $this->cache[$id]) === false) { 
     229                if ((!isset ($this->cache[$id]) 
     230                    || array_search($article, $this->cache[$id]) === false) && 
     231                    $this->filterCheck($id, $article[0], $article[1], $article[3])) { 
    192232                    // Decode and trim article title 
    193233                    $article[0] = $this->decode($article[0], 40); 
     
    204244    } 
    205245 
     246    // Checks the given feed Title and URL as well as article title against the feed filters 
     247    protected function filterCheck($id, $title, $url, $article) { 
     248          // Feed Title, Feed URL and Article Title Filters 
     249        $filterTitle = $this->filterTitle[$id]; 
     250        $filterUrl = $this->filterUrl[$id];     
     251        $filterArticle = $this->filterArticle[$id];    
     252         
     253        // Check against the filters if any are set 
     254          if (($filterTitle && preg_match('/'.$filterTitle.'/im', $title, $match)) || 
     255              ($filterUrl && preg_match('/'.$filterUrl.'/im', $url, $match)) || 
     256              ($filterArticle && preg_match('/'.$filterArticle.'/im', $article, $match))) { 
     257              return false; 
     258          } 
     259          return true; 
     260    } 
     261     
    206262    /** 
    207263    * Transliterates a UTF-8 string into corresponding ASCII characters and 
  • trunk/Phergie/phergie.ini

    r129 r130  
    134134;----------------------------------------------------------------------------- 
    135135 
    136 ; feedticker.feed0 : 
    137 ;    a double quote-enclosed comma-delimited list of feed URLs; this setting 
    138 ;    may be repeated with a different number (i.e. feed1, feed2, etc.) 
    139 feedticker.feed0 = "" 
    140  
    141 ; feedticker.chans0 : 
    142 ;    a comma- or space-delimited list of channels where the feedN should be 
    143 ;    syndicated 
    144 feedticker.chans0 = "" 
    145  
    146136; feedticker.delay : 
    147137;    the frequency, in seconds, at which the feeds are checked for new data; 
     
    157147feedticker.format = "" 
    158148 
     149;# Feed Ticker: Filter Settings # 
     150; feedticker.filter_title: 
     151;    a double quote-enclosed regex string filter; this is the global filter 
     152;    setting used to filter the feed title of all the feeds 
     153feedticker.filter_title = "" 
     154 
     155; feedticker.filter_url : 
     156;    a double quote-enclosed regex string filter; this is the global filter 
     157;    setting used to filter the feed url of all the feeds 
     158feedticker.filter_url = "" 
     159 
     160; feedticker.filter_article: 
     161;    a double quote-enclosed regex string filter; this is the global filter 
     162;    setting used to filter the article title of all the feeds 
     163feedticker.filter_article = "" 
     164 
     165; feedticker.feed0 : 
     166;    a double quote-enclosed comma-delimited list of feed URLs; this setting 
     167;    may be repeated with a different number (i.e. feed1, feed2, etc.) 
     168feedticker.feed0 = "" 
     169 
     170; feedticker.chans0 : 
     171;    a comma- or space-delimited list of channels where the feedN should be 
     172;    syndicated 
     173feedticker.chans0 = "" 
     174 
     175; feedticker.filter_title0 : 
     176;    a double quote-enclosed regex string filter; this setting allows you to 
     177;    filter each feed title independently and  may be repeated with a different 
     178;    number. (i.e. filter_title1, filter_title2, etc.) 
     179feedticker.filter_title0 = "" 
     180 
     181; feedticker.filter_url0 : 
     182;    a double quote-enclosed regex string filter; this setting allows you to 
     183;    filter each feed url independently and  may be repeated with a different 
     184;    number. (i.e. filter_url1, filter_url2, etc.) 
     185feedticker.filter_url0 = "" 
     186 
     187; feedticker.filter_article0 : 
     188;    a double quote-enclosed regex string filter; this setting allows you to 
     189;    filter each article title independently and  may be repeated with a  
     190;    different number. (i.e. filter_article1, filter_article2, etc.) 
     191feedticker.filter_article0 = "" 
     192 
    159193;----------------------------------------------------------------------------- 
    160194; Karma