Changeset 1155
- Timestamp:
- 01/07/06 15:15:26 (3 years ago)
- Location:
- trunk/rss
- Files:
-
- 1 added
- 3 modified
- 1 copied
-
admin/markallasread.php (added)
-
extlib/rss_dbcache.inc (copied) (copied from branches/no-magpie-cache/extlib/rss_dbcache.inc)
-
extlib/rss_fetch.inc (modified) (3 diffs)
-
schema.php (modified) (5 diffs)
-
util.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/rss/extlib/rss_fetch.inc
r402 r1155 29 29 30 30 require_once( MAGPIE_DIR . 'rss_parse.inc' ); 31 require_once( MAGPIE_DIR . 'rss_ cache.inc' );31 require_once( MAGPIE_DIR . 'rss_dbcache.inc' ); //sameer: changed to use db 32 32 33 33 // for including 3rd party libraries … … 131 131 // 4. if remote fails, return stale object, or error 132 132 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 ); 134 135 135 136 if (MAGPIE_DEBUG and $cache->ERROR) { … … 145 146 // store parsed XML by desired output encoding 146 147 // 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; 148 151 149 152 if (!$cache->ERROR) { -
trunk/rss/schema.php
r1091 r1155 117 117 } 118 118 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; 119 171 case 'i.author': 120 172 case 'author': … … 147 199 // enclosure for an item 148 200 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))'); 149 226 if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 150 227 $updated++; … … 174 251 descr varchar(255) default NULL, 175 252 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, 176 257 icon varchar(255) default NULL, 177 258 position int(11) NOT NULL default '0', 178 259 mode int(16) NOT NULL default '1', 179 PRIMARY KEY (id) 260 PRIMARY KEY (id), 261 KEY url (url) 180 262 ) TYPE=MyISAM; 181 263 _SQL_ … … 333 415 id bigint(16) NOT NULL auto_increment, 334 416 cid bigint(11) NOT NULL default '0', 417 md5sum varchar(32) default NULL, 418 guid text default NULL, 335 419 added datetime NOT NULL default '0000-00-00 00:00:00', 336 420 title varchar(255) default NULL, … … 343 427 PRIMARY KEY (id), 344 428 KEY url (url), 429 KEY guid(guid(10)), 345 430 KEY cid (cid) 346 431 ) TYPE=MyISAM; -
trunk/rss/util.php
r1151 r1155 158 158 return array (magpie_error(), array ()); 159 159 } 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 162 162 } 163 163 … … 175 175 if(!isset($item)) 176 176 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 180 179 $title = array_key_exists('title', $item) ? strip_tags($item['title']) : ""; 181 180 //$title = str_replace('& ', '& ', $title); 181 182 183 $description = ""; 182 184 // item content, if any 183 185 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']; 185 187 } 186 188 elseif (array_key_exists('description', $item)) { 187 $description = kses($item['description'], $kses_allowed);189 $description = $item['description']; 188 190 } 189 191 elseif (array_key_exists('atom_content', $item)) { 190 $description = kses($item['atom_content'], $kses_allowed);192 $description = $item['atom_content']; 191 193 } 192 194 elseif (array_key_exists('summary', $item)) { 193 $description = kses($item['summary'], $kses_allowed);195 $description = $item['summary']; 194 196 } 195 197 else { … … 197 199 } 198 200 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']; 202 209 } 203 210 204 211 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 207 223 208 224 // link … … 272 288 continue; 273 289 } 290 274 291 $dbtitle = rss_real_escape_string($title); 275 292 if (strlen($dbtitle) >= 255) { 276 293 $dbtitle=substr($dbtitle,0,254); 277 294 } 278 // check wether we already have this item279 $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);282 295 283 296 if ($cDate > 0) { … … 287 300 } 288 301 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)); 293 335 294 336 $sql = "insert into ".getTable("item") 295 337 ." (cid, added, title, url, enclosure," 296 ." description, author, unread, pubdate ) "338 ." description, author, unread, pubdate, md5sum, guid) " 297 339 ." values ("."$cid, now(), '$dbtitle', " 298 340 ." '$url', '".rss_real_escape_string($enclosure)."', '" 299 341 .rss_real_escape_string($description)."', '" 300 342 .rss_real_escape_string($author)."', " 301 ."$mode, $sec )";343 ."$mode, $sec, '$md5sum', '$guid')"; 302 344 303 345 rss_query($sql); 304 305 346 306 347 $newIid = rss_insert_id(); 307 348 $updatedIds[] = $newIid; 308 /*309 * Ticket #26: Add hook to modify the item just after it310 * has been inserted into the database311 */312 349 rss_plugin_hook('rss.plugins.items.newiid',array($newIid,$item,$cid)); 313 350 } 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 328 352 } 329 353 } … … 557 581 static $ret; 558 582 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 } 566 590 } 567 591 return $ret; 568 592 569 593 } 570 594 $dummy = getPath();
