PluginProbe
FeedWordPress / 2010.0602
FeedWordPress v2010.0602
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 | feeds-page.php +102 -91 2009.11112010.0602 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2 require_once(dirname(__FILE__) . '/admin-ui.php');
3 3 require_once(dirname(__FILE__) . '/magpiemocklink.class.php');
4 4 require_once(dirname(__FILE__) . '/feedfinder.class.php');
5 +require_once(dirname(__FILE__) . '/updatedpostscontrol.class.php');
5 6
6 7 class FeedWordPressFeedsPage extends FeedWordPressAdminPage {
7 8 var $HTTPStatusMessages = array (
8 9 200 => 'OK. FeedWordPress had no problems retrieving the content at this URL but the content does not seem to be a feed, and does not seem to include links to any feeds.',
@@ -43,8 +44,9 @@
43 44 503 => 'Service Unavailable. The server is currently unable to handle the request due to a temporary overloading or maintenance of the server that hosts this URL. This is probably a temporary condition and you should try again later to see if the issue has been resolved.',
44 45 504 => 'Gateway Timeout',
45 46 505 => 'HTTP Version Not Supported',
46 47 );
48 + var $updatedPosts = NULL;
47 49
48 50 /**
49 51 * Constructs the Feeds page object
50 52 *
@@ -58,8 +60,9 @@
58 60 FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpressfeeds', $link);
59 61
60 62 $this->dispatch = get_class($this);
61 63 $this->filename = __FILE__;
64 + $this->updatedPosts = new UpdatedPostsControl($this);
62 65 } /* FeedWordPressFeedsPage constructor */
63 66
64 67 var $special_settings = array ( /* Regular expression syntax is OK here */
65 68 'cats',
@@ -76,8 +79,11 @@
76 79 'unfamiliar category',
77 80 'map authors',
78 81 'tags',
79 82 'postmeta',
83 + 'resolve relative',
84 + 'freeze updates',
85 + 'munge permalink',
80 86 'update/.*',
81 87 'feed/.*',
82 88 'link/.*',
83 89 );
@@ -129,8 +135,9 @@
129 135
130 136 $boxes_by_methods = array(
131 137 'feed_information_box' => __('Feed Information'),
132 138 'global_feeds_box' => __('Update Scheduling'),
139 + 'updated_posts_box' => __('Updated Posts'),
133 140 'posts_box' => __('Syndicated Posts, Links, Comments & Pings'),
134 141 'authors_box' => __('Syndicated Authors'),
135 142 'categories_box' => __('Categories'.FEEDWORDPRESS_AND_TAGS),
136 143 'custom_settings_box' => __('Custom Feed Settings (for use in templates)'),
@@ -183,8 +190,16 @@
183 190 endif;
184 191 return false; // Don't continue
185 192 } /* FeedWordPressFeedsPage::display() */
186 193
194 + /*static*/ function updated_posts_box ($page, $box = NULL) {
195 + ?>
196 + <table class="edit-form">
197 + <?php $page->updatedPosts->display(); ?>
198 + </table>
199 + <?php
200 + } /* FeedWordPressFeedsPage::updated_posts_box() */
201 +
187 202 /*static*/ function global_feeds_box ($page, $box = NULL) {
188 203 global $wpdb;
189 204
190 205 $defaultUpdateWindow = get_option('feedwordpress_update_window');
@@ -211,11 +226,11 @@
211 226 </select>
212 227 <div id="cron-job-explanation" class="setting-description">
213 228 <p>If you want to use a cron job,
214 229 you can perform scheduled updates by sending regularly-scheduled
215 - requests to <a href="<?php bloginfo('home'); ?>?update_feedwordpress=1"><code><?php bloginfo('home') ?>?update_feedwordpress=1</code></a>
230 + requests to <a href="<?php bloginfo('home'); ?>?update_feedwordpress=1"><code><?php bloginfo('url') ?>?update_feedwordpress=1</code></a>
216 231 For example, inserting the following line in your crontab:</p>
217 - <pre style="font-size: 0.80em"><code>*/10 * * * * /usr/bin/curl --silent <?php bloginfo('home'); ?>?update_feedwordpress=1</code></pre>
232 + <pre style="font-size: 0.80em"><code>*/10 * * * * /usr/bin/curl --silent <?php bloginfo('url'); ?>?update_feedwordpress=1</code></pre>
218 233 <p class="setting-description">will check in every 10 minutes
219 234 and check for updates on any feeds that are ready to be polled for updates.</p>
220 235 </div>
221 236 </td>
@@ -315,11 +330,11 @@
315 330
316 331 function feed_information_box ($page, $box = NULL) {
317 332 global $wpdb;
318 333 if ($page->for_feed_settings()) :
319 - $info['name'] = wp_specialchars($page->link->link->link_name, 1);
320 - $info['description'] = wp_specialchars($page->link->link->link_description, 'both');
321 - $info['url'] = wp_specialchars($page->link->link->link_url, 1);
334 + $info['name'] = esc_html($page->link->link->link_name);
335 + $info['description'] = esc_html($page->link->link->link_description);
336 + $info['url'] = esc_html($page->link->link->link_url);
322 337 $rss_url = $page->link->link->link_rss;
323 338
324 339 $hardcode['name'] = $page->link->hardcode('name');
325 340 $hardcode['description'] = $page->link->hardcode('description');
@@ -325,26 +340,29 @@
325 340 $hardcode['description'] = $page->link->hardcode('description');
326 341 $hardcode['url'] = $page->link->hardcode('url');
327 342 else :
328 343 $cat_id = FeedWordPress::link_category_id();
329 - if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_21)) :
330 - $results = get_categories(array(
331 - "type" => 'link',
332 - "hide_empty" => false,
333 - ));
344 +
345 + $params = array();
346 + if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_USES_ARGS_TAXONOMY)) :
347 + $params['taxonomy'] = 'link_category';
348 + else :
349 + $params['type'] = 'link';
350 + endif;
351 + $params['hide_empty'] = false;
352 + $results = get_categories($params);
334 353
335 - // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
336 - $found_link_category_id = false;
337 - foreach ($results as $row) :
338 - // Normalize case
339 - if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
354 + // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
355 + $found_link_category_id = false;
356 + foreach ($results as $row) :
357 + // Normalize case
358 + if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
340 359
341 - if ($row->cat_id == $cat_id) : $found_link_category_id = true; endif;
342 - endforeach;
343 -
344 - if (!$found_link_category_id) : $results[] = get_category($cat_id); endif;
345 - else :
346 - $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
360 + if ($row->cat_id == $cat_id) : $found_link_category_id = true; endif;
361 + endforeach;
362 +
363 + if (!$found_link_category_id) :
364 + $results[] = get_category($cat_id);
347 365 endif;
348 366
349 367 $info = array();
350 368 $rss_url = null;
@@ -368,11 +386,11 @@
368 386 <?php if ($page->for_feed_settings()) : ?>
369 387
370 388 <tr>
371 389 <th scope="row"><?php _e('Feed URL:') ?></th>
372 - <td><a href="<?php echo wp_specialchars($rss_url, 'both'); ?>"><?php echo wp_specialchars($rss_url, 'both'); ?></a>
390 + <td><a href="<?php echo esc_html($rss_url); ?>"><?php echo esc_html($rss_url); ?></a>
373 391 (<a href="<?php echo FEEDVALIDATOR_URI; ?>?url=<?php echo urlencode($rss_url); ?>"
374 - title="Check feed &lt;<?php echo wp_specialchars($rss_url, 'both'); ?>&gt; for validity">validate</a>)
392 + title="Check feed &lt;<?php echo esc_html($rss_url); ?>&gt; for validity">validate</a>)
375 393 <input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" /></td>
376 394 </tr>
377 395
378 396 <?php
@@ -423,9 +441,9 @@
423 441 echo "\n\t<option value=\"$row->cat_id\"";
424 442 if ($row->cat_id == $cat_id) :
425 443 echo " selected='selected'";
426 444 endif;
427 - echo ">$row->cat_id: ".wp_specialchars($row->cat_name);
445 + echo ">$row->cat_id: ".esc_html($row->cat_name);
428 446 echo "</option>\n";
429 447 endforeach;
430 448 ?></select></p>
431 449 <p class="setting-description">FeedWordPress will syndicate the
@@ -454,17 +472,20 @@
454 472 <?php
455 473 } /* FeedWordPressFeedsPage::feed_information_box() */
456 474
457 475 function posts_box ($page, $box = NULL) {
458 - FeedWordPressSettingsUI::instead_of_posts_box($page->link->id);
476 + $id = (isset($page->link) ? $page->link->id : NULL);
477 + FeedWordPressSettingsUI::instead_of_posts_box($id);
459 478 } /* FeedWordPressFeedsPage::posts_box() */
460 479
461 480 function authors_box ($page, $box = NULL) {
462 - FeedWordPressSettingsUI::instead_of_authors_box($page->link->id);
481 + $id = (isset($page->link) ? $page->link->id : NULL);
482 + FeedWordPressSettingsUI::instead_of_authors_box($id);
463 483 } /* FeedWordPressFeedsPage::authors_box() */
464 484
465 485 function categories_box ($page, $box = NULL) {
466 - FeedWordPressSettingsUI::instead_of_categories_box($page->link->id);
486 + $id = (isset($page->link) ? $page->link->id : NULL);
487 + FeedWordPressSettingsUI::instead_of_categories_box($id);
467 488 } /* FeedWordPressFeedsPage::categories_box() */
468 489
469 490 function custom_settings_box ($page, $box = NULL) {
470 491 ?>
@@ -486,11 +507,11 @@
486 507 foreach ($page->link->settings as $key => $value) :
487 508 if (!preg_match("\007^((".implode(')|(', $page->special_settings)."))$\007i", $key)) :
488 509 ?>
489 510 <tr style="vertical-align:top">
490 - <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo wp_specialchars($key, 'both'); ?>" />
491 - <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo wp_specialchars($key, 'both'); ?>" /></th>
492 - <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?>-value" name="notes[<?php echo $i; ?>][value]"><?php echo wp_specialchars($value, 'both'); ?></textarea></td>
511 + <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo esc_html($key); ?>" />
512 + <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo esc_html($key); ?>" /></th>
513 + <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?>-value" name="notes[<?php echo $i; ?>][value]"><?php echo esc_html($value); ?></textarea></td>
493 514 <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
494 515 <option value="update">save changes</option>
495 516 <option value="delete">delete this setting</option>
496 517 </select></td>
@@ -516,62 +537,41 @@
516 537 $lookup = (isset($_REQUEST['lookup']) ? $_REQUEST['lookup'] : NULL);
517 538
518 539 if ($this->for_feed_settings()) : // Existing feed?
519 540 if (is_null($lookup)) : $lookup = $this->link->link->link_url; endif;
520 - $name = wp_specialchars($this->link->link->link_name, 'both');
541 + $name = esc_html($this->link->link->link_name);
521 542 else: // Or a new subscription to add?
522 - $name = "Subscribe to <code>".wp_specialchars(feedwordpress_display_url($lookup))."</code>";
543 + $name = "Subscribe to <code>".esc_html(feedwordpress_display_url($lookup))."</code>";
523 544 endif;
524 545 ?>
525 - <style type="text/css">
526 - form.fieldset {
527 - clear: both;
528 - }
529 - .feed-sample {
530 - float: right;
531 - background-color: #D0D0D0;
532 - color: black;
533 - width: 45%;
534 - font-size: 70%;
535 - border-left: 1px dotted #A0A0A0;
536 - margin-left: 1.0em;
537 - }
538 - .feed-sample p, .feed-sample h3 {
539 - padding-left: 0.5em;
540 - padding-right: 0.5em;
541 - }
542 - .feed-sample .feed-problem {
543 - background-color: #ffd0d0;
544 - border-bottom: 1px dotted black;
545 - padding-bottom: 0.5em;
546 - margin-bottom: 0.5em;
547 - }
548 - </style>
549 -
550 546 <div class="wrap">
551 547 <h2>Feed Finder: <?php echo $name; ?></h2>
552 548
553 549 <?php
554 - $f =& new FeedFinder($lookup);
550 + $f = new FeedFinder($lookup);
555 551 $feeds = $f->find();
556 552 if (count($feeds) > 0):
557 553 foreach ($feeds as $key => $f):
558 - $rss = @fetch_rss($f);
559 - if ($rss):
554 + $pie = FeedWordPress::fetch($f);
555 + $rss = (is_wp_error($pie) ? $pie : new MagpieFromSimplePie($pie));
556 +
557 + if ($rss and !is_wp_error($rss)):
560 558 $feed_title = isset($rss->channel['title'])?$rss->channel['title']:$rss->channel['link'];
561 559 $feed_link = isset($rss->channel['link'])?$rss->channel['link']:'';
562 560 $feed_type = ($rss->feed_type ? $rss->feed_type : 'Unknown');
561 + $feed_version = $rss->feed_version;
563 562 else :
564 563 // Give us some sucky defaults
565 564 $feed_title = feedwordpress_display_url($lookup);
566 565 $feed_link = $lookup;
567 566 $feed_type = 'Unknown';
567 + $feed_version = '';
568 568 endif;
569 569 ?>
570 570 <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/syndication.php" method="post">
571 571 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_switchfeed'); ?></div>
572 572 <fieldset>
573 - <legend><?php echo $feed_type; ?> <?php echo $rss->feed_version; ?> feed</legend>
573 + <legend><?php echo $feed_type; ?> <?php echo $feed_version; ?> feed</legend>
574 574
575 575 <?php
576 576 $this->stamp_link_id();
577 577
@@ -579,25 +579,26 @@
579 579 // need to pass along a starting title
580 580 // and homepage URL for the new Link.
581 581 if (!$this->for_feed_settings()):
582 582 ?>
583 - <input type="hidden" name="feed_title" value="<?php echo wp_specialchars($feed_title, 'both'); ?>" />
584 - <input type="hidden" name="feed_link" value="<?php echo wp_specialchars($feed_link, 'both'); ?>" />
583 + <input type="hidden" name="feed_title" value="<?php echo esc_html($feed_title); ?>" />
584 + <input type="hidden" name="feed_link" value="<?php echo esc_html($feed_link); ?>" />
585 585 <?php
586 586 endif;
587 587 ?>
588 588
589 - <input type="hidden" name="feed" value="<?php echo wp_specialchars($f, 'both'); ?>" />
589 + <input type="hidden" name="feed" value="<?php echo esc_html($f); ?>" />
590 590 <input type="hidden" name="action" value="switchfeed" />
591 591
592 592 <div>
593 593 <div class="feed-sample">
594 -
595 594 <?php
596 - if (count($rss->items) > 0):
595 + $link = NULL;
596 + $post = NULL;
597 + if (!is_wp_error($rss) and count($rss->items) > 0):
597 598 // Prepare to display Sample Item
598 - $link =& new MagpieMockLink($rss, $f);
599 - $post =& new SyndicatedPost($rss->items[0], $link);
599 + $link = new MagpieMockLink(array('simplepie' => $pie, 'magpie' => $rss), $f);
600 + $post = new SyndicatedPost(array('simplepie' => $rss->originals[0], 'magpie' => $rss->items[0]), $link);
600 601 ?>
601 602 <h3>Sample Item</h3>
602 603 <ul>
603 604 <li><strong>Title:</strong> <a href="<?php echo $post->post['meta']['syndication_permalink']; ?>"><?php echo $post->post['post_title']; ?></a></li>
@@ -606,15 +607,16 @@
606 607 <div class="entry">
607 608 <?php print $post->post['post_content']; ?>
608 609 </div>
609 610 <?php
611 + do_action('feedwordpress_feed_finder_sample_item', $f, $post, $link);
610 612 else:
611 - if (magpie_error()) :
613 + if (is_wp_error($rss)) :
612 614 print '<div class="feed-problem">';
613 615 print "<h3>Problem:</h3>\n";
614 616 print "<p>FeedWordPress encountered the following error
615 617 when trying to retrieve this feed:</p>";
616 - print '<p style="margin: 1.0em 3.0em"><code>'.magpie_error().'</code></p>';
618 + print '<p style="margin: 1.0em 3.0em"><code>'.$rss->get_error_message().'</code></p>';
617 619 print "<p>If you think this is a temporary problem, you can still force FeedWordPress to add the subscription. FeedWordPress will not be able to find any syndicated posts until this problem is resolved.</p>";
618 620 print "</div>";
619 621 endif;
620 622 ?>
@@ -628,12 +630,13 @@
628 630 <div>
629 631 <h3>Feed Information</h3>
630 632 <ul>
631 633 <li><strong>Homepage:</strong> <a href="<?php echo $feed_link; ?>"><?php echo is_null($feed_title)?'<em>Unknown</em>':$feed_title; ?></a></li>
632 - <li><strong>Feed URL:</strong> <a href="<?php echo wp_specialchars($f, 'both'); ?>"><?php echo wp_specialchars($f, 'both'); ?></a> (<a title="Check feed &lt;<?php echo wp_specialchars($f, 'both'); ?>&gt; for validity" href="http://feedvalidator.org/check.cgi?url=<?php echo urlencode($f); ?>">validate</a>)</li>
633 - <li><strong>Encoding:</strong> <?php echo isset($rss->encoding)?wp_specialchars($rss->encoding, 'both'):"<em>Unknown</em>"; ?></li>
634 - <li><strong>Description:</strong> <?php echo isset($rss->channel['description'])?wp_specialchars($rss->channel['description'], 'both'):"<em>Unknown</em>"; ?></li>
634 + <li><strong>Feed URL:</strong> <a href="<?php echo esc_html($f); ?>"><?php echo esc_html($f); ?></a> (<a title="Check feed &lt;<?php echo esc_html($f); ?>&gt; for validity" href="http://feedvalidator.org/check.cgi?url=<?php echo urlencode($f); ?>">validate</a>)</li>
635 + <li><strong>Encoding:</strong> <?php echo isset($rss->encoding)?esc_html($rss->encoding):"<em>Unknown</em>"; ?></li>
636 + <li><strong>Description:</strong> <?php echo isset($rss->channel['description'])?esc_html($rss->channel['description']):"<em>Unknown</em>"; ?></li>
635 637 </ul>
638 + <?php do_action('feedwordpress_feedfinder_form', $f, $post, $link, $this->for_feed_settings()); ?>
636 639 <div class="submit"><input type="submit" name="Use" value="&laquo; Use this feed" /></div>
637 640 <div class="submit"><input type="submit" name="Cancel" value="&laquo; Cancel" /></div>
638 641 </div>
639 642 </div>
@@ -639,8 +642,10 @@
639 642 </div>
640 643 </fieldset>
641 644 </form>
642 645 <?php
646 + unset($link);
647 + unset($post);
643 648 endforeach;
644 649 else:
645 650 print "<p><strong>".__('Error').":</strong> ".__("FeedWordPress couldn't find any feeds at").' <code><a href="'.htmlspecialchars($lookup).'">'.htmlspecialchars($lookup).'</a></code>';
646 651 print ". ".__('Try another URL').".</p>";
@@ -694,8 +699,9 @@
694 699 global $wpdb;
695 700
696 701 // User mashed a Save Changes button
697 702 if (isset($post['save']) or isset($post['submit'])) :
703 +
698 704 if ($this->for_feed_settings()) :
699 705 $alter = array ();
700 706
701 707 // custom feed settings first
@@ -724,9 +730,9 @@
724 730 foreach (array('name', 'description', 'url') as $what) :
725 731 // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
726 732 $this->link->settings["hardcode {$what}"] = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
727 733 if (FeedWordPress::affirmative($this->link->settings, "hardcode {$what}")) :
728 - $alter[] = "link_{$what} = '".$wpdb->escape($post['link'.$what])."'";
734 + $this->link->link->{'link_'.$what} = $post['link'.$what];
729 735 endif;
730 736 endforeach;
731 737
732 738 // Update scheduling
@@ -741,25 +747,8 @@
741 747 $this->link->settings['update/window'] = (int) $post['update_window'];
742 748 endif;
743 749 endif;
744 750
745 - $alter[] = "link_notes = '".$wpdb->escape($this->link->settings_to_notes())."'";
746 -
747 - $alter_set = implode(", ", $alter);
748 -
749 - // issue update query
750 - $result = $wpdb->query("
751 - UPDATE $wpdb->links
752 - SET $alter_set
753 - WHERE link_id='{$this->link->id}'
754 - ");
755 - $this->updated = true;
756 -
757 - // reload link information from DB
758 - if (function_exists('clean_bookmark_cache')) :
759 - clean_bookmark_cache($this->link->id);
760 - endif;
761 - $this->link = new SyndicatedLink($this->link->id);
762 751 else :
763 752 // Global
764 753 update_option('feedwordpress_cat_id', $post['syndication_category']);
765 754
@@ -784,8 +773,30 @@
784 773 update_option("feedwordpress_hardcode_{$what}", $hardcode);
785 774 endforeach;
786 775
787 776 $this->updated = true;
777 + endif;
778 + $this->updatedPosts->accept_POST($post);
779 +
780 + if ($this->for_feed_settings()) :
781 + // Save changes to channel-level meta-data
782 + //$alter_set = implode(", ", $alter);
783 +
784 + // issue update query
785 + //$result = $wpdb->query("
786 + //UPDATE $wpdb->links
787 + //SET $alter_set
788 + //WHERE link_id='{$this->link->id}'
789 + //");
790 +
791 + // Save settings
792 + $this->link->save_settings(/*reload=*/ true);
793 +
794 + $this->updated = true;
795 +
796 + // Reset, reload
797 + $link_id = $this->link->id; unset($this->link);
798 + $this->link = new SyndicatedLink($link_id);
788 799 endif;
789 800
790 801 // Probably a "Go" button for the drop-down
791 802 else :