Changeset 1155

Show
Ignore:
Timestamp:
01/07/06 15:15:26 (3 years ago)
Author:
sdcosta
Message:

Important: Please see these important notes before svn'ing up
past this changeset.

This merges the no-magpie-cache branch back into the trunk.
svn merge -r 1114:1154 http://svn.gregarius.net/svn/branches/no-magpie-cache

Location:
trunk/rss
Files:
1 added
3 modified
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/rss/extlib/rss_fetch.inc

    r402 r1155  
    2929 
    3030require_once( MAGPIE_DIR . 'rss_parse.inc' ); 
    31 require_once( MAGPIE_DIR . 'rss_cache.inc' ); 
     31require_once( MAGPIE_DIR . 'rss_dbcache.inc' ); //sameer: changed to use db 
    3232 
    3333// for including 3rd party libraries 
     
    131131        // 4. if remote fails, return stale object, or error 
    132132         
    133         $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE ); 
     133    // sameer: changed to use db 
     134        $cache = new RSSdbCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE ); 
    134135         
    135136        if (MAGPIE_DEBUG and $cache->ERROR) { 
     
    145146        // store parsed XML by desired output encoding 
    146147        // as character munging happens at parse time 
    147         $cache_key       = $url . MAGPIE_OUTPUT_ENCODING; 
     148        //$cache_key       = $url . MAGPIE_OUTPUT_ENCODING; 
     149    // sameer: removed the encoding from the key 
     150        $cache_key       = $url; 
    148151         
    149152        if (!$cache->ERROR) { 
  • trunk/rss/schema.php

    r1091 r1155  
    117117            } 
    118118        break; 
     119        case 'c.daterefreshed': 
     120        case 'daterefreshed': 
     121            // date feed was last refreshed, added in 0.5.3 
     122            rss_query('alter table ' .getTable('channels') .' add column daterefreshed datetime null'); 
     123            if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
     124                $updated++; 
     125                rss_error("updated schema for table " . getTable('channels'), RSS_ERROR_NOTICE); 
     126            } else { 
     127                rss_error("Failed updating schema for table " . getTable('channels') 
     128                .": " . rss_sql_error_message(), RSS_ERROR_ERROR 
     129                ); 
     130            } 
     131        // break; - fallthrough allowed on purpose because these are added at the same time 
     132        case 'c.refreshinterval': 
     133        case 'refreshinterval': 
     134            // refresh interval of a feed (in minutes), added in 0.5.3 
     135            rss_query('alter table ' .getTable('channels') .' add column refreshinterval int(16) not null default 60'); 
     136            if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
     137                $updated++; 
     138                rss_error("updated schema for table " . getTable('channels'), RSS_ERROR_NOTICE); 
     139            } else { 
     140                rss_error("Failed updating schema for table " . getTable('channels') 
     141                .": " . rss_sql_error_message(), RSS_ERROR_ERROR 
     142                ); 
     143            } 
     144        // break; - fallthrough allowed on purpose because these are added at the same time 
     145        case 'c.etag': 
     146        case 'etag': 
     147            // etag of the feed, (from HTTP header) added in 0.5.3 
     148            rss_query('alter table ' .getTable('channels') .' add column etag varchar(255) default null'); 
     149            if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
     150                $updated++; 
     151                rss_error("updated schema for table " . getTable('channels'), RSS_ERROR_NOTICE); 
     152            } else { 
     153                rss_error("Failed updating schema for table " . getTable('channels') 
     154                .": " . rss_sql_error_message(), RSS_ERROR_ERROR 
     155                ); 
     156            } 
     157        // break; - fallthrough allowed on purpose because these are added at the same time 
     158        case 'c.lastmodified': 
     159        case 'lastmodified': 
     160            // last modified code returned by the feed (from HTTP header), added in 0.5.3 
     161            rss_query('alter table ' .getTable('channels') .' add column lastmodified varchar(255) default null'); 
     162            if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
     163                $updated++; 
     164                rss_error("updated schema for table " . getTable('channels'), RSS_ERROR_NOTICE); 
     165            } else { 
     166                rss_error("Failed updating schema for table " . getTable('channels') 
     167                .": " . rss_sql_error_message(), RSS_ERROR_ERROR 
     168                ); 
     169            } 
     170        break; 
    119171        case 'i.author': 
    120172        case 'author': 
     
    147199            // enclosure for an item 
    148200            rss_query('alter table ' . getTable('item') . ' add column enclosure varchar(255) null'); 
     201            if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
     202                $updated++; 
     203                rss_error('updated schema for table ' . getTable('item'), RSS_ERROR_NOTICE); 
     204            } else { 
     205                rss_error('Failed updating schema for table ' . getTable('item') . ': ' 
     206                    . rss_sql_error_message(), RSS_ERROR_ERROR); 
     207            } 
     208        break; 
     209        case 'i.md5sum': 
     210        case 'md5sum': 
     211            // md5check on an item - added in 0.5.3 
     212            rss_query('alter table ' . getTable('item') . ' add column md5sum varchar(32) null'); 
     213            if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
     214                $updated++; 
     215                rss_error('updated schema for table ' . getTable('item'), RSS_ERROR_NOTICE); 
     216            } else { 
     217                rss_error('Failed updating schema for table ' . getTable('item') . ': ' 
     218                    . rss_sql_error_message(), RSS_ERROR_ERROR); 
     219            } 
     220        // break; - fallthrough allowed on purpose because these are added at the same time 
     221        case 'i.guid': 
     222        case 'guid': 
     223            // guid of an item - added in 0.5.3 
     224            rss_query('alter table ' . getTable('item') . ' add column guid text null'); 
     225            rss_query('alter table ' . getTable('item') . ' add index `guid` (`guid`(10))'); 
    149226            if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    150227                $updated++; 
     
    174251            descr varchar(255) default NULL, 
    175252            dateadded datetime default NULL, 
     253            daterefreshed datetime default NULL, 
     254            refreshinterval int(16) NOT NULL default '60', 
     255            etag varchar(255) default NULL, 
     256            lastmodified varchar(255) default NULL, 
    176257            icon varchar(255) default NULL, 
    177258            position int(11) NOT NULL default '0', 
    178259            mode int(16) NOT NULL default '1', 
    179             PRIMARY KEY  (id) 
     260            PRIMARY KEY  (id), 
     261            KEY url (url) 
    180262        ) TYPE=MyISAM;     
    181263_SQL_ 
     
    333415          id bigint(16) NOT NULL auto_increment, 
    334416          cid bigint(11) NOT NULL default '0', 
     417          md5sum varchar(32) default NULL, 
     418          guid text default NULL, 
    335419          added datetime NOT NULL default '0000-00-00 00:00:00', 
    336420          title varchar(255) default NULL, 
     
    343427          PRIMARY KEY  (id), 
    344428          KEY url (url), 
     429          KEY guid(guid(10)), 
    345430          KEY cid (cid) 
    346431        ) TYPE=MyISAM;     
  • trunk/rss/util.php

    r1151 r1155  
    158158            return array (magpie_error(), array ()); 
    159159        } 
    160         elseif (!$rss) { 
    161             continue; 
     160        elseif (!$rss || !($rss->rss_origin & MAGPIE_FEED_ORIGIN_HTTP_200) ) { 
     161            continue; // no need to do anything if we do not get a 200 OK from the feed 
    162162        } 
    163163 
     
    175175            if(!isset($item)) 
    176176                continue; 
    177             // item title: strip out html tags, shouldn't supposed 
    178             // to have any, should it? 
    179             //$title = strip_tags($item['title']); 
     177 
     178            // item title: strip out html tags 
    180179            $title = array_key_exists('title', $item) ? strip_tags($item['title']) : ""; 
    181180            //$title = str_replace('& ', '& ', $title); 
     181 
     182 
     183            $description = ""; 
    182184            // item content, if any 
    183185            if (array_key_exists('content', $item) && is_array($item['content']) && array_key_exists('encoded', $item['content'])) { 
    184                 $description = kses($item['content']['encoded'], $kses_allowed); 
     186                $description = $item['content']['encoded']; 
    185187            } 
    186188            elseif (array_key_exists('description', $item)) { 
    187                 $description = kses($item['description'], $kses_allowed); 
     189                $description = $item['description']; 
    188190            } 
    189191            elseif (array_key_exists('atom_content', $item)) { 
    190                 $description = kses($item['atom_content'], $kses_allowed); 
     192                $description = $item['atom_content']; 
    191193            } 
    192194            elseif (array_key_exists('summary', $item)) { 
    193                 $description = kses($item['summary'], $kses_allowed); 
     195                $description = $item['summary']; 
    194196            } 
    195197            else { 
     
    197199            } 
    198200 
    199             if ($description != "" && $baseUrl != "") { 
    200                 //$description = make_abs($description, $baseUrl); 
    201                 $description = relative_to_absolute($description, $baseUrl); 
     201            $md5sum = ""; 
     202            $guid = ""; 
     203 
     204            if(array_key_exists('guid', $item) && $item['guid'] != "") { 
     205                $guid = $item['guid']; 
     206            } 
     207            elseif(array_key_exists('id', $item) && $item['id'] != "") { 
     208                $guid = $item['id']; 
    202209            } 
    203210 
    204211            if ($description != "") { 
    205                 $description = rss_plugin_hook('rss.plugins.import.description', $description); 
    206             } 
     212                $md5sum = md5($description); 
     213                $description = kses($description, $kses_allowed); // strip out tags 
     214 
     215                if ($baseUrl != "") { 
     216                    $description = relative_to_absolute($description, $baseUrl); 
     217                } 
     218            } 
     219 
     220            // Now let plugins modify the description 
     221            $description = rss_plugin_hook('rss.plugins.import.description', $description); 
     222 
    207223 
    208224            // link 
     
    272288                continue; 
    273289            } 
     290 
    274291            $dbtitle = rss_real_escape_string($title); 
    275292            if (strlen($dbtitle) >= 255) { 
    276293                $dbtitle=substr($dbtitle,0,254); 
    277294            } 
    278             // check wether we already have this item 
    279             $sql = "select id,length(description),unread from ".getTable("item")." where cid=$cid and url='$url' and title='$dbtitle'"; 
    280             $subres = rss_query($sql); 
    281             list ($indb, $dbdesc_len, $state) = rss_fetch_row($subres); 
    282295 
    283296            if ($cDate > 0) { 
     
    287300            } 
    288301 
    289             if ($indb == "") { 
    290  
    291                 list ($cid, $dbtitle, $url, $description) 
    292                 = rss_plugin_hook('rss.plugins.items.new', array ($cid, $dbtitle, $url, $description)); 
     302            // check whether we already have this item 
     303            if ($guid) { 
     304                $sql = "select id,unread, md5sum, guid, pubdate from ".getTable("item") 
     305                       ." where cid=$cid and guid='$guid'"; 
     306            } else { 
     307                $sql = "select id,unread, md5sum, guid, pubdate from ".getTable("item") 
     308                       ." where cid=$cid and url='$url' and title='$dbtitle'" 
     309                       ." and (pubdate is NULL OR pubdate=$sec)"; 
     310            } 
     311            $subres = rss_query($sql); 
     312            list ($indb, $state, $dbmd5sum, $dbGuid, $dbPubDate) = rss_fetch_row($subres); 
     313 
     314            if ($indb && !($state & RSS_MODE_DELETED_STATE) && $md5sum != $dbmd5sum) { 
     315                // the md5sums do not match. 
     316                if(getConfig('rss.input.allowupdates')) { // Are we allowed update items in the db? 
     317                    list ($cid, $indb, $description) = 
     318                        rss_plugin_hook('rss.plugins.items.updated', array ($cid, $indb, $description)); 
     319 
     320                    $sql = "update ".getTable("item") 
     321                           ." set "." description='".rss_real_escape_string($description)."', " 
     322                           ." unread = unread | ".RSS_MODE_UNREAD_STATE 
     323                           .", md5sum='$md5sum'" . " where cid=$cid and id=$indb"; 
     324 
     325                    rss_query($sql); 
     326                    $updatedIds[] = $indb; 
     327                    continue; 
     328                } 
     329            } 
     330 
     331            if ($indb == "") { // This must be new item then. In you go. 
     332 
     333                list ($cid, $dbtitle, $url, $description) = 
     334                    rss_plugin_hook('rss.plugins.items.new', array ($cid, $dbtitle, $url, $description)); 
    293335 
    294336                $sql = "insert into ".getTable("item") 
    295337                       ." (cid, added, title, url, enclosure," 
    296                        ." description, author, unread, pubdate) " 
     338                       ." description, author, unread, pubdate, md5sum, guid) " 
    297339                       ." values ("."$cid, now(), '$dbtitle', " 
    298340                       ." '$url', '".rss_real_escape_string($enclosure)."', '" 
    299341                       .rss_real_escape_string($description)."', '" 
    300342                       .rss_real_escape_string($author)."', " 
    301                        ."$mode, $sec)"; 
     343                       ."$mode, $sec, '$md5sum', '$guid')"; 
    302344 
    303345                rss_query($sql); 
    304  
    305346 
    306347                $newIid = rss_insert_id(); 
    307348                $updatedIds[] = $newIid; 
    308                 /* 
    309                  * Ticket #26: Add hook to modify the item just after it  
    310                  * has been inserted into the database 
    311                  */ 
    312349                rss_plugin_hook('rss.plugins.items.newiid',array($newIid,$item,$cid)); 
    313350            } 
    314             elseif (!($state & RSS_MODE_DELETED_STATE) && 
    315                     getConfig('rss.input.allowupdates') && 
    316                     strlen($description) > $dbdesc_len) { 
    317  
    318                 list ($cid, $indb, $description) = 
    319                     rss_plugin_hook('rss.plugins.items.updated', array ($cid, $indb, $description)); 
    320  
    321                 $sql = "update ".getTable("item") 
    322                        ." set "." description='".rss_real_escape_string($description)."', " 
    323                        ." unread = unread | ".RSS_MODE_UNREAD_STATE." where cid=$cid and id=$indb"; 
    324  
    325                 rss_query($sql); 
    326                 $updatedIds[] = $indb; 
    327             } 
     351 
    328352        } 
    329353    } 
     
    557581    static $ret; 
    558582    if ($ret === NULL) { 
    559         $ret = dirname($_SERVER['PHP_SELF']); 
    560         if (defined('RSS_FILE_LOCATION') && eregi(RSS_FILE_LOCATION."\$", $ret)) { 
    561               $ret = substr($ret, 0, strlen($ret) - strlen(RSS_FILE_LOCATION)); 
    562         } 
    563         if (substr($ret, -1) != "/") { 
    564               $ret .= "/"; 
    565         } 
     583        $ret = dirname($_SERVER['PHP_SELF']); 
     584        if (defined('RSS_FILE_LOCATION') && eregi(RSS_FILE_LOCATION."\$", $ret)) { 
     585            $ret = substr($ret, 0, strlen($ret) - strlen(RSS_FILE_LOCATION)); 
     586        } 
     587        if (substr($ret, -1) != "/") { 
     588            $ret .= "/"; 
     589        } 
    566590    } 
    567591    return $ret; 
    568      
     592 
    569593} 
    570594$dummy = getPath();