Changeset 1155 for trunk/rss/util.php

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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();