PluginProbe
FeedWordPress / 2010.0528
FeedWordPress v2010.0528
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 +72 -44 2009.11122010.0528 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');
@@ -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');
@@ -368,11 +383,11 @@
368 383 <?php if ($page->for_feed_settings()) : ?>
369 384
370 385 <tr>
371 386 <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>
387 + <td><a href="<?php echo esc_html($rss_url); ?>"><?php echo esc_html($rss_url); ?></a>
373 388 (<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>)
389 + title="Check feed &lt;<?php echo esc_html($rss_url); ?>&gt; for validity">validate</a>)
375 390 <input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" /></td>
376 391 </tr>
377 392
378 393 <?php
@@ -423,9 +438,9 @@
423 438 echo "\n\t<option value=\"$row->cat_id\"";
424 439 if ($row->cat_id == $cat_id) :
425 440 echo " selected='selected'";
426 441 endif;
427 - echo ">$row->cat_id: ".wp_specialchars($row->cat_name);
442 + echo ">$row->cat_id: ".esc_html($row->cat_name);
428 443 echo "</option>\n";
429 444 endforeach;
430 445 ?></select></p>
431 446 <p class="setting-description">FeedWordPress will syndicate the
@@ -486,11 +501,11 @@
486 501 foreach ($page->link->settings as $key => $value) :
487 502 if (!preg_match("\007^((".implode(')|(', $page->special_settings)."))$\007i", $key)) :
488 503 ?>
489 504 <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>
505 + <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo esc_html($key); ?>" />
506 + <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo esc_html($key); ?>" /></th>
507 + <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 508 <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
494 509 <option value="update">save changes</option>
495 510 <option value="delete">delete this setting</option>
496 511 </select></td>
@@ -516,11 +531,11 @@
516 531 $lookup = (isset($_REQUEST['lookup']) ? $_REQUEST['lookup'] : NULL);
517 532
518 533 if ($this->for_feed_settings()) : // Existing feed?
519 534 if (is_null($lookup)) : $lookup = $this->link->link->link_url; endif;
520 - $name = wp_specialchars($this->link->link->link_name, 'both');
535 + $name = esc_html($this->link->link->link_name);
521 536 else: // Or a new subscription to add?
522 - $name = "Subscribe to <code>".wp_specialchars(feedwordpress_display_url($lookup))."</code>";
537 + $name = "Subscribe to <code>".esc_html(feedwordpress_display_url($lookup))."</code>";
523 538 endif;
524 539 ?>
525 540 <style type="text/css">
526 541 form.fieldset {
@@ -550,14 +565,16 @@
550 565 <div class="wrap">
551 566 <h2>Feed Finder: <?php echo $name; ?></h2>
552 567
553 568 <?php
554 - $f =& new FeedFinder($lookup);
569 + $f = new FeedFinder($lookup);
555 570 $feeds = $f->find();
556 571 if (count($feeds) > 0):
557 572 foreach ($feeds as $key => $f):
558 - $rss = @fetch_rss($f);
559 - if ($rss):
573 + $pie = FeedWordPress::fetch($f);
574 + $rss = (is_wp_error($pie) ? $pie : new MagpieFromSimplePie($pie));
575 +
576 + if ($rss and !is_wp_error($rss)):
560 577 $feed_title = isset($rss->channel['title'])?$rss->channel['title']:$rss->channel['link'];
561 578 $feed_link = isset($rss->channel['link'])?$rss->channel['link']:'';
562 579 $feed_type = ($rss->feed_type ? $rss->feed_type : 'Unknown');
563 580 else :
@@ -579,25 +596,26 @@
579 596 // need to pass along a starting title
580 597 // and homepage URL for the new Link.
581 598 if (!$this->for_feed_settings()):
582 599 ?>
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'); ?>" />
600 + <input type="hidden" name="feed_title" value="<?php echo esc_html($feed_title); ?>" />
601 + <input type="hidden" name="feed_link" value="<?php echo esc_html($feed_link); ?>" />
585 602 <?php
586 603 endif;
587 604 ?>
588 605
589 - <input type="hidden" name="feed" value="<?php echo wp_specialchars($f, 'both'); ?>" />
606 + <input type="hidden" name="feed" value="<?php echo esc_html($f); ?>" />
590 607 <input type="hidden" name="action" value="switchfeed" />
591 608
592 609 <div>
593 610 <div class="feed-sample">
594 -
595 611 <?php
596 - if (count($rss->items) > 0):
612 + $link = NULL;
613 + $post = NULL;
614 + if (!is_wp_error($rss) and count($rss->items) > 0):
597 615 // Prepare to display Sample Item
598 - $link =& new MagpieMockLink($rss, $f);
599 - $post =& new SyndicatedPost($rss->items[0], $link);
616 + $link = new MagpieMockLink(array('simplepie' => $pie, 'magpie' => $rss), $f);
617 + $post = new SyndicatedPost(array('simplepie' => $rss->originals[0], 'magpie' => $rss->items[0]), $link);
600 618 ?>
601 619 <h3>Sample Item</h3>
602 620 <ul>
603 621 <li><strong>Title:</strong> <a href="<?php echo $post->post['meta']['syndication_permalink']; ?>"><?php echo $post->post['post_title']; ?></a></li>
@@ -606,15 +624,16 @@
606 624 <div class="entry">
607 625 <?php print $post->post['post_content']; ?>
608 626 </div>
609 627 <?php
628 + do_action('feedwordpress_feed_finder_sample_item', $f, $post, $link);
610 629 else:
611 - if (magpie_error()) :
630 + if (is_wp_error($rss)) :
612 631 print '<div class="feed-problem">';
613 632 print "<h3>Problem:</h3>\n";
614 633 print "<p>FeedWordPress encountered the following error
615 634 when trying to retrieve this feed:</p>";
616 - print '<p style="margin: 1.0em 3.0em"><code>'.magpie_error().'</code></p>';
635 + print '<p style="margin: 1.0em 3.0em"><code>'.$rss->get_error_message().'</code></p>';
617 636 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 637 print "</div>";
619 638 endif;
620 639 ?>
@@ -628,12 +647,13 @@
628 647 <div>
629 648 <h3>Feed Information</h3>
630 649 <ul>
631 650 <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>
651 + <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>
652 + <li><strong>Encoding:</strong> <?php echo isset($rss->encoding)?esc_html($rss->encoding):"<em>Unknown</em>"; ?></li>
653 + <li><strong>Description:</strong> <?php echo isset($rss->channel['description'])?esc_html($rss->channel['description']):"<em>Unknown</em>"; ?></li>
635 654 </ul>
655 + <?php do_action('feedwordpress_feedfinder_form', $f, $post, $link, $this->for_feed_settings()); ?>
636 656 <div class="submit"><input type="submit" name="Use" value="&laquo; Use this feed" /></div>
637 657 <div class="submit"><input type="submit" name="Cancel" value="&laquo; Cancel" /></div>
638 658 </div>
639 659 </div>
@@ -639,8 +659,10 @@
639 659 </div>
640 660 </fieldset>
641 661 </form>
642 662 <?php
663 + unset($link);
664 + unset($post);
643 665 endforeach;
644 666 else:
645 667 print "<p><strong>".__('Error').":</strong> ".__("FeedWordPress couldn't find any feeds at").' <code><a href="'.htmlspecialchars($lookup).'">'.htmlspecialchars($lookup).'</a></code>';
646 668 print ". ".__('Try another URL').".</p>";
@@ -694,8 +716,9 @@
694 716 global $wpdb;
695 717
696 718 // User mashed a Save Changes button
697 719 if (isset($post['save']) or isset($post['submit'])) :
720 +
698 721 if ($this->for_feed_settings()) :
699 722 $alter = array ();
700 723
701 724 // custom feed settings first
@@ -724,9 +747,9 @@
724 747 foreach (array('name', 'description', 'url') as $what) :
725 748 // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
726 749 $this->link->settings["hardcode {$what}"] = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
727 750 if (FeedWordPress::affirmative($this->link->settings, "hardcode {$what}")) :
728 - $alter[] = "link_{$what} = '".$wpdb->escape($post['link'.$what])."'";
751 + $this->link->link->{'link_'.$what} = $post['link'.$what];
729 752 endif;
730 753 endforeach;
731 754
732 755 // Update scheduling
@@ -741,25 +764,8 @@
741 764 $this->link->settings['update/window'] = (int) $post['update_window'];
742 765 endif;
743 766 endif;
744 767
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 768 else :
763 769 // Global
764 770 update_option('feedwordpress_cat_id', $post['syndication_category']);
765 771
@@ -784,8 +790,30 @@
784 790 update_option("feedwordpress_hardcode_{$what}", $hardcode);
785 791 endforeach;
786 792
787 793 $this->updated = true;
794 + endif;
795 + $this->updatedPosts->accept_POST($post);
796 +
797 + if ($this->for_feed_settings()) :
798 + // Save changes to channel-level meta-data
799 + //$alter_set = implode(", ", $alter);
800 +
801 + // issue update query
802 + //$result = $wpdb->query("
803 + //UPDATE $wpdb->links
804 + //SET $alter_set
805 + //WHERE link_id='{$this->link->id}'
806 + //");
807 +
808 + // Save settings
809 + $this->link->save_settings(/*reload=*/ true);
810 +
811 + $this->updated = true;
812 +
813 + // Reset, reload
814 + $link_id = $this->link->id; unset($this->link);
815 + $this->link = new SyndicatedLink($link_id);
788 816 endif;
789 817
790 818 // Probably a "Go" button for the drop-down
791 819 else :