| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: FeedWordPress |
| 4 | 4 | Plugin URI: http://projects.radgeek.com/feedwordpress |
| 5 | 5 | Description: simple and flexible Atom/RSS syndication for WordPress |
| 6 | -Version: 2009.0612 | |
| 6 | +Version: 2009.0618 | |
| 7 | 7 | Author: Charles Johnson |
| 8 | 8 | Author URI: http://radgeek.com/ |
| 9 | 9 | License: GPL |
| 10 | 10 | */ |
| @@ -212,10 +212,10 @@ | ||
| 212 | 212 | FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_fix_magpie', /*capability=*/ 'edit_files'); |
| 213 | 213 | |
| 214 | 214 | $back_to = $_SERVER['REQUEST_URI']; |
| 215 | 215 | if (isset($_POST['ignore'])) : |
| 216 | - // kill error message by telling it to expect whatever we've got | |
| 217 | - update_option('feedwordpress_expected_magpie', FeedWordPress::magpie_version()); | |
| 216 | + // kill error message by telling it we ignored the upgrade request for this version | |
| 217 | + update_option('feedwordpress_magpie_ignored_upgrade_to', EXPECTED_MAGPIE_VERSION); | |
| 218 | 218 | $ret = 'ignored'; |
| 219 | 219 | elseif (isset($_POST['upgrade'])) : |
| 220 | 220 | $source = dirname(__FILE__)."/MagpieRSS-upgrade/rss.php"; |
| 221 | 221 | $destination = ABSPATH . WPINC . '/rss.php'; |
| @@ -506,9 +506,9 @@ | ||
| 506 | 506 | <?php |
| 507 | 507 | endif; |
| 508 | 508 | } /* function fwp_check_debug () */ |
| 509 | 509 | |
| 510 | -define('DEFAULT_EXPECTED_MAGPIE_VERSION', '0.85'); | |
| 510 | +define('EXPECTED_MAGPIE_VERSION', '2009.0618'); | |
| 511 | 511 | function fwp_check_magpie () { |
| 512 | 512 | if (isset($_REQUEST['feedwordpress_magpie_fix'])) : |
| 513 | 513 | if ($_REQUEST['feedwordpress_magpie_fix']=='ignored') : |
| 514 | 514 | ?> |
| @@ -552,19 +552,11 @@ | ||
| 552 | 552 | <?php |
| 553 | 553 | endif; |
| 554 | 554 | else : |
| 555 | 555 | $magpie_version = FeedWordPress::magpie_version(); |
| 556 | - | |
| 557 | - $exp = get_option('feedwordpress_expected_magpie'); | |
| 558 | - if ($exp) : $expected = array($exp, DEFAULT_EXPECTED_MAGPIE_VERSION); | |
| 559 | - else : $expected = array(DEFAULT_EXPECTED_MAGPIE_VERSION); | |
| 560 | - endif; | |
| 561 | 556 | |
| 562 | - if (in_array($magpie_version, $expected)) : | |
| 563 | - if ($magpie_version != $exp) : | |
| 564 | - update_option('feedwordpress_expected_magpie', $magpie_version); | |
| 565 | - endif; | |
| 566 | - else : | |
| 557 | + $ignored = get_option('feedwordpress_magpie_ignored_upgrade_to'); | |
| 558 | + if (EXPECTED_MAGPIE_VERSION != $magpie_version and EXPECTED_MAGPIE_VERSION != $ignored) : | |
| 567 | 559 | if (current_user_can('edit_files')) : |
| 568 | 560 | $youAre = 'you are'; |
| 569 | 561 | $itIsRecommendedThatYou = 'It is <strong>strongly recommended</strong> that you'; |
| 570 | 562 | else : |
| @@ -573,9 +565,13 @@ | ||
| 573 | 565 | endif; |
| 574 | 566 | print '<div class="error">'; |
| 575 | 567 | ?> |
| 576 | 568 | <p style="font-style: italic"><strong>FeedWordPress has detected that <?php print $youAre; ?> currently using a version of |
| 577 | -MagpieRSS other than the upgraded version that ships with FeedWordPress.</strong></p> | |
| 569 | +MagpieRSS other than the upgraded version that ships with this version of FeedWordPress.</strong></p> | |
| 570 | +<ul> | |
| 571 | +<li><strong>Currently running:</strong> MagpieRSS <?php print $magpie_version; ?></li> | |
| 572 | +<li><strong>Version included with FeedWordPress <?php print FEEDWORDPRESS_VERSION; ?>:</strong> MagpieRSS <?php print EXPECTED_MAGPIE_VERSION; ?></li> | |
| 573 | +</ul> | |
| 578 | 574 | <p><?php print $itIsRecommendedThatYou; ?> install the upgraded |
| 579 | 575 | version of MagpieRSS supplied with FeedWordPress. The version of |
| 580 | 576 | MagpieRSS that ships with WordPress is very old and buggy, and |
| 581 | 577 | encounters a number of errors when trying to parse modern Atom |
| @@ -1256,9 +1252,9 @@ | ||
| 1256 | 1252 | if (!is_array($default_custom_settings)) : |
| 1257 | 1253 | $default_custom_settings = array(); |
| 1258 | 1254 | endif; |
| 1259 | 1255 | |
| 1260 | - $custom_settings = $this->link->settings['postmeta']; | |
| 1256 | + $custom_settings = (isset($this->link->settings['postmeta']) ? $this->link->settings['postmeta'] : null); | |
| 1261 | 1257 | if ($custom_settings) : |
| 1262 | 1258 | $custom_settings = unserialize($custom_settings); |
| 1263 | 1259 | endif; |
| 1264 | 1260 | if (!is_array($custom_settings)) : |
| @@ -1321,10 +1317,10 @@ | ||
| 1321 | 1317 | // Store a hash of the post content for checking whether something needs to be updated |
| 1322 | 1318 | $this->post['meta']['syndication_item_hash'] = $this->update_hash(); |
| 1323 | 1319 | |
| 1324 | 1320 | // Feed-by-feed options for author and category creation |
| 1325 | - $this->post['named']['unfamiliar']['author'] = $this->feedmeta['unfamiliar author']; | |
| 1326 | - $this->post['named']['unfamiliar']['category'] = $this->feedmeta['unfamiliar category']; | |
| 1321 | + $this->post['named']['unfamiliar']['author'] = (isset($this->feedmeta['unfamiliar author']) ? $this->feedmeta['unfamiliar author'] : null); | |
| 1322 | + $this->post['named']['unfamiliar']['category'] = (isset($this->feedmeta['unfamiliar category']) ? $this->feedmeta['unfamiliar category'] : null); | |
| 1327 | 1323 | |
| 1328 | 1324 | // Categories: start with default categories, if any |
| 1329 | 1325 | $fc = get_option("feedwordpress_syndication_cats"); |
| 1330 | 1326 | if ($fc) : |
| @@ -1332,9 +1328,9 @@ | ||
| 1332 | 1328 | else : |
| 1333 | 1329 | $this->post['named']['preset/category'] = array(); |
| 1334 | 1330 | endif; |
| 1335 | 1331 | |
| 1336 | - if (is_array($this->feedmeta['cats'])) : | |
| 1332 | + if (isset($this->feedmeta['cats']) and is_array($this->feedmeta['cats'])) : | |
| 1337 | 1333 | $this->post['named']['preset/category'] = array_merge($this->post['named']['preset/category'], $this->feedmeta['cats']); |
| 1338 | 1334 | endif; |
| 1339 | 1335 | |
| 1340 | 1336 | // Now add categories from the post, if we have 'em |
| @@ -1361,9 +1357,9 @@ | ||
| 1361 | 1357 | else : |
| 1362 | 1358 | $this->post['tags_input'] = array(); |
| 1363 | 1359 | endif; |
| 1364 | 1360 | |
| 1365 | - if (is_array($this->feedmeta['tags'])) : | |
| 1361 | + if (isset($this->feedmeta['tags']) and is_array($this->feedmeta['tags'])) : | |
| 1366 | 1362 | $this->post['tags_input'] = array_merge($this->post['tags_input'], $this->feedmeta['tags']); |
| 1367 | 1363 | endif; |
| 1368 | 1364 | |
| 1369 | 1365 | endif; |
| @@ -2358,178 +2354,8 @@ | ||
| 2358 | 2354 | |
| 2359 | 2355 | return array('flerror' => false, 'message' => "Thanks for the ping.".implode(' and', $mesg)); |
| 2360 | 2356 | endif; |
| 2361 | 2357 | } |
| 2362 | - | |
| 2363 | -################################################################################ | |
| 2364 | -## class FeedFinder: find likely feeds using autodetection and/or guesswork #### | |
| 2365 | -################################################################################ | |
| 2366 | - | |
| 2367 | -class FeedFinder { | |
| 2368 | - var $uri = NULL; | |
| 2369 | - var $_cache_uri = NULL; | |
| 2370 | - | |
| 2371 | - var $verify = FALSE; | |
| 2372 | - | |
| 2373 | - var $_data = NULL; | |
| 2374 | - var $_error = NULL; | |
| 2375 | - var $_head = NULL; | |
| 2376 | - | |
| 2377 | - # -- Recognition patterns | |
| 2378 | - var $_feed_types = array( | |
| 2379 | - 'application/rss+xml', | |
| 2380 | - 'text/xml', | |
| 2381 | - 'application/atom+xml', | |
| 2382 | - 'application/x.atom+xml', | |
| 2383 | - 'application/x-atom+xml' | |
| 2384 | - ); | |
| 2385 | - var $_feed_markers = array('\\<feed', '\\<rss', 'xmlns="http://purl.org/rss/1.0'); | |
| 2386 | - var $_html_markers = array('\\<html'); | |
| 2387 | - var $_obvious_feed_url = array('[./]rss', '[./]rdf', '[./]atom', '[./]feed', '\.xml'); | |
| 2388 | - var $_maybe_feed_url = array ('rss', 'rdf', 'atom', 'feed', 'xml'); | |
| 2389 | - | |
| 2390 | - function FeedFinder ($uri = NULL, $verify = TRUE) { | |
| 2391 | - $this->uri = $uri; $this->verify = $verify; | |
| 2392 | - } /* FeedFinder::FeedFinder () */ | |
| 2393 | - | |
| 2394 | - function find ($uri = NULL) { | |
| 2395 | - $ret = array (); | |
| 2396 | - if (!is_null($this->data($uri))) { | |
| 2397 | - if ($this->is_feed($uri)) { | |
| 2398 | - $ret = array($this->uri); | |
| 2399 | - } else { | |
| 2400 | - // Assume that we have HTML or XHTML (even if we don't, who's it gonna hurt?) | |
| 2401 | - // Autodiscovery is the preferred method | |
| 2402 | - $href = $this->_link_rel_feeds(); | |
| 2403 | - | |
| 2404 | - // ... but we'll also take the little orange buttons | |
| 2405 | - $href = array_merge($href, $this->_a_href_feeds(TRUE)); | |
| 2406 | - | |
| 2407 | - // If all that failed, look harder | |
| 2408 | - if (count($href) == 0) $href = $this->_a_href_feeds(FALSE); | |
| 2409 | - | |
| 2410 | - // Our search may turn up duplicate URIs. We only need to do any given URI once. | |
| 2411 | - // Props to Camilo <http://projects.radgeek.com/2008/12/14/feedwordpress-20081214/#comment-20090122160414> | |
| 2412 | - $href = array_unique($href); | |
| 2413 | - | |
| 2414 | - // Verify feeds and resolve relative URIs | |
| 2415 | - foreach ($href as $u) { | |
| 2416 | - $the_uri = Relative_URI::resolve($u, $this->uri); | |
| 2417 | - if ($this->verify) { | |
| 2418 | - $feed =& new FeedFinder($the_uri); | |
| 2419 | - if ($feed->is_feed()) $ret[] = $the_uri; | |
| 2420 | - $feed = NULL; | |
| 2421 | - } else { | |
| 2422 | - $ret[] = $the_uri; | |
| 2423 | - } | |
| 2424 | - } /* foreach */ | |
| 2425 | - } /* if */ | |
| 2426 | - } /* if */ | |
| 2427 | - return array_unique($ret); | |
| 2428 | - } /* FeedFinder::find () */ | |
| 2429 | - | |
| 2430 | - function data ($uri = NULL) { | |
| 2431 | - $this->_get($uri); | |
| 2432 | - return $this->_data; | |
| 2433 | - } | |
| 2434 | - | |
| 2435 | - function error () { | |
| 2436 | - return $this->_error; | |
| 2437 | - } | |
| 2438 | - | |
| 2439 | - function is_feed ($uri = NULL) { | |
| 2440 | - $data = $this->data($uri); | |
| 2441 | - | |
| 2442 | - return ( | |
| 2443 | - preg_match ( | |
| 2444 | - "\007(".implode('|',$this->_feed_markers).")\007i", | |
| 2445 | - $data | |
| 2446 | - ) and !preg_match ( | |
| 2447 | - "\007(".implode('|',$this->_html_markers).")\007i", | |
| 2448 | - $data | |
| 2449 | - ) | |
| 2450 | - ); | |
| 2451 | - } /* FeedFinder::is_feed () */ | |
| 2452 | - | |
| 2453 | - # --- Private methods --- | |
| 2454 | - function _get ($uri = NULL) { | |
| 2455 | - if ($uri) $this->uri = $uri; | |
| 2456 | - | |
| 2457 | - // Is the result not yet cached? | |
| 2458 | - if ($this->_cache_uri !== $this->uri) : | |
| 2459 | - $headers['Connection'] = 'close'; | |
| 2460 | - $headers['Accept'] = 'application/atom+xml application/rdf+xml application/rss+xml application/xml text/html */*'; | |
| 2461 | - $headers['User-Agent'] = 'feedfinder/1.2 (compatible; PHP FeedFinder) +http://projects.radgeek.com/feedwordpress'; | |
| 2462 | - | |
| 2463 | - // Use function provided by MagpieRSS package | |
| 2464 | - $client = _fetch_remote_file($this->uri, $headers); | |
| 2465 | - if (isset($client->error)) : | |
| 2466 | - $this->_error = $client->error; | |
| 2467 | - else : | |
| 2468 | - $this->_error = NULL; | |
| 2469 | - endif; | |
| 2470 | - $this->_data = $client->results; | |
| 2471 | - | |
| 2472 | - // Kilroy was here | |
| 2473 | - $this->_cache_uri = $this->uri; | |
| 2474 | - endif; | |
| 2475 | - } /* FeedFinder::_get () */ | |
| 2476 | - | |
| 2477 | - function _link_rel_feeds () { | |
| 2478 | - $links = $this->_tags('link'); | |
| 2479 | - $link_count = count($links); | |
| 2480 | - | |
| 2481 | - // now figure out which one points to the RSS file | |
| 2482 | - $href = array (); | |
| 2483 | - for ($n=0; $n<$link_count; $n++) { | |
| 2484 | - if (strtolower($links[$n]['rel']) == 'alternate') { | |
| 2485 | - if (in_array(strtolower($links[$n]['type']), $this->_feed_types)) { | |
| 2486 | - $href[] = $links[$n]['href']; | |
| 2487 | - } /* if */ | |
| 2488 | - } /* if */ | |
| 2489 | - } /* for */ | |
| 2490 | - return $href; | |
| 2491 | - } | |
| 2492 | - | |
| 2493 | - function _a_href_feeds ($obvious = TRUE) { | |
| 2494 | - $pattern = ($obvious ? $this->_obvious_feed_url : $this->_maybe_feed_url); | |
| 2495 | - | |
| 2496 | - $links = $this->_tags('a'); | |
| 2497 | - $link_count = count($links); | |
| 2498 | - | |
| 2499 | - // now figure out which one points to the RSS file | |
| 2500 | - $href = array (); | |
| 2501 | - for ($n=0; $n<$link_count; $n++) { | |
| 2502 | - if (preg_match("\007(".implode('|',$pattern).")\007i", $links[$n]['href'])) { | |
| 2503 | - $href[] = $links[$n]['href']; | |
| 2504 | - } /* if */ | |
| 2505 | - } /* for */ | |
| 2506 | - return $href; | |
| 2507 | - } | |
| 2508 | - | |
| 2509 | - function _tags ($tag) { | |
| 2510 | - $html = $this->data(); | |
| 2511 | - | |
| 2512 | - // search through the HTML, save all <link> tags | |
| 2513 | - // and store each link's attributes in an associative array | |
| 2514 | - preg_match_all('/<'.$tag.'\s+(.*?)\s*\/?>/si', $html, $matches); | |
| 2515 | - $links = $matches[1]; | |
| 2516 | - $ret = array(); | |
| 2517 | - $link_count = count($links); | |
| 2518 | - for ($n=0; $n<$link_count; $n++) { | |
| 2519 | - $attributes = preg_split('/\s+/s', $links[$n]); | |
| 2520 | - foreach($attributes as $attribute) { | |
| 2521 | - $att = preg_split('/\s*=\s*/s', $attribute, 2); | |
| 2522 | - if (isset($att[1])) { | |
| 2523 | - $att[1] = preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1]); | |
| 2524 | - $final_link[strtolower($att[0])] = $att[1]; | |
| 2525 | - } /* if */ | |
| 2526 | - } /* foreach */ | |
| 2527 | - $ret[$n] = $final_link; | |
| 2528 | - } /* for */ | |
| 2529 | - return $ret; | |
| 2530 | - } | |
| 2531 | -} /* class FeedFinder */ | |
| 2532 | 2358 | |
| 2533 | 2359 | # Relative URI static class: PHP class for resolving relative URLs |
| 2534 | 2360 | # |
| 2535 | 2361 | # This class is derived (under the terms of the GPL) from URL Class 0.3 by |