PluginProbe
FeedWordPress / 2009.0612
FeedWordPress v2009.0612
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
← All changes | feedwordpress.php +185 -11 2009.06132009.0612 View file →
@@ -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.0613
6 +Version: 2009.0612
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 we ignored the upgrade request for this version
217 - update_option('feedwordpress_magpie_ignored_upgrade_to', EXPECTED_MAGPIE_VERSION);
216 + // kill error message by telling it to expect whatever we've got
217 + update_option('feedwordpress_expected_magpie', FeedWordPress::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('EXPECTED_MAGPIE_VERSION', '2009.0613');
510 +define('DEFAULT_EXPECTED_MAGPIE_VERSION', '0.85');
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,11 +552,19 @@
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;
556 561
557 - $ignored = get_option('feedwordpress_magpie_ignored_upgrade_to');
558 - if (EXPECTED_MAGPIE_VERSION != $magpie_version and EXPECTED_MAGPIE_VERSION != $ignored) :
562 + if (in_array($magpie_version, $expected)) :
563 + if ($magpie_version != $exp) :
564 + update_option('feedwordpress_expected_magpie', $magpie_version);
565 + endif;
566 + else :
559 567 if (current_user_can('edit_files')) :
560 568 $youAre = 'you are';
561 569 $itIsRecommendedThatYou = 'It is <strong>strongly recommended</strong> that you';
562 570 else :
@@ -565,13 +573,9 @@
565 573 endif;
566 574 print '<div class="error">';
567 575 ?>
568 576 <p style="font-style: italic"><strong>FeedWordPress has detected that <?php print $youAre; ?> currently using a version of
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>
577 +MagpieRSS other than the upgraded version that ships with FeedWordPress.</strong></p>
574 578 <p><?php print $itIsRecommendedThatYou; ?> install the upgraded
575 579 version of MagpieRSS supplied with FeedWordPress. The version of
576 580 MagpieRSS that ships with WordPress is very old and buggy, and
577 581 encounters a number of errors when trying to parse modern Atom
@@ -2354,8 +2358,178 @@
2354 2358
2355 2359 return array('flerror' => false, 'message' => "Thanks for the ping.".implode(' and', $mesg));
2356 2360 endif;
2357 2361 }
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 */
2358 2532
2359 2533 # Relative URI static class: PHP class for resolving relative URLs
2360 2534 #
2361 2535 # This class is derived (under the terms of the GPL) from URL Class 0.3 by