Permalink
Browse files

Filters / allow filters to alter syndication feed URI, either in gene…

…ral or only on the actual fetching -- support for paging traversal plugins etc.
  • Loading branch information...
radgeek committed Jul 18, 2014
1 parent 076efb5 commit 0ac2a55ad24bc47911701de963833c7b8f2b68c2
Showing with 86 additions and 12 deletions.
  1. +8 −2 admin-ui.php
  2. +3 −3 categories-page.php
  3. +4 −2 feedwordpie.class.php
  4. +6 −2 feedwordpress.php
  5. +65 −3 syndicatedlink.class.php
View
@@ -62,15 +62,21 @@ function update_feed () {
print '<div class="updated">';
print "<ul>";
$uri = $this->link->uri();
+ $displayUrl = $uri;
+
+ // check for effects of an effective-url filter
+ $effectiveUrl = $link->uri(array('fetch' => true));
+ if ($uri != $effectiveUrl) : $displayUrl .= ' | ' . $effectiveUrl; endif;
+
$delta = $feedwordpress->update($uri);
print "</ul>";
if (!is_null($delta)) :
echo "<p><strong>Update complete.</strong>".fwp_update_set_results_message($delta)."</p>";
echo "\n"; flush();
else :
- $uri = esc_html($uri);
- echo "<p><strong>Error:</strong> There was a problem updating <a href=\"$uri\">$uri</a></p>\n";
+ $effectiveUrl = esc_html($effectiveUrl);
+ echo "<p><strong>Error:</strong> There was a problem updating <a href=\"$effectiveUrl\">$displayUrl</a></p>\n";
endif;
print "</div>\n";
remove_action('feedwordpress_check_feed', 'update_feeds_mention');
View
@@ -380,7 +380,7 @@ function term_setting_map () {
function categories_box ($page, $box = NULL) {
$link = $page->link;
$dummy = null;
- $syndicatedpost = new SyndicatedPost(null, $dummy);
+ $syndicatedlink = new SyndicatedLink($dummy);
if ($this->for_feed_settings()) :
$post_type = $link->setting('syndicated post type', 'syndicated_post_type', 'post');
@@ -442,15 +442,15 @@ function categories_box ($page, $box = NULL) {
<?php
endif;
- $dogs = $syndicatedpost->category_ids($cats, /*unfamiliar=*/ NULL, /*taxonomies=*/ array($tax));
+ $dogs = $syndicatedlink->category_ids($cats, /*unfamiliar=*/ NULL, /*taxonomies=*/ array($tax));
if ($taxonomy->hierarchical) : // Use a category-style checkbox
fwp_category_box($dogs, 'all '.$page->these_posts_phrase(), /*tags=*/ array(), /*params=*/ array('taxonomy' => $tax));
else : // Use a tag-style edit box
fwp_tags_box($cats, 'all '.$page->these_posts_phrase(), /*params=*/ array('taxonomy' => $tax));
endif;
- $globalDogs = $syndicatedpost->category_ids($globalCats, /*unfamiliar=*/ 'create:'.$tax, /*taxonomies=*/ array($tax));
+ $globalDogs = $syndicatedlink->category_ids($globalCats, /*unfamiliar=*/ 'create:'.$tax, /*taxonomies=*/ array($tax));
$siteWideHref = $this->admin_page_href(basename(__FILE__));
View
@@ -10,7 +10,7 @@ function set_feed_url ($url) {
// Get URL with relevant parameters attached.
// Credentials will be handled further down.
- $new_url = $url->uri(array('add_params' => true));
+ $new_url = $url->uri(array('add_params' => true, 'fetch' => true));
// Store for reference.
$this->subscription = $url->id();
@@ -43,10 +43,12 @@ function get_type () {
}
function get_feed_tags ($namespace, $tag) {
+ $tags = parent::get_feed_tags($namespace, $tag);
+
// Allow filters to filter SimplePie handling
return apply_filters(
'feedwordpie_get_feed_tags',
- parent::get_feed_tags($namespace, $tag),
+ $tags,
$namespace,
$tag,
$this
View
@@ -3,7 +3,7 @@
Plugin Name: FeedWordPress
Plugin URI: http://feedwordpress.radgeek.com/
Description: simple and flexible Atom/RSS syndication for WordPress
-Version: 2014.0630
+Version: 2014.0715
Author: Charles Johnson
Author URI: http://radgeek.com/
License: GPL
@@ -239,6 +239,10 @@ class FeedWordPressDiagnostic {
function feed_error ($error, $old, $link) {
$wpError = $error['object'];
$url = $link->uri();
+
+ // check for effects of an effective-url filter
+ $effectiveUrl = $link->uri(array('fetch' => true));
+ if ($url != $effectiveUrl) : $url .= ' | ' . $effectiveUrl; endif;
$mesgs = $wpError->get_error_messages();
foreach ($mesgs as $mesg) :
@@ -851,7 +855,6 @@ function feedwordpress_post_edit_controls () {
function feedwordpress_save_post_edit_controls ( $post_id ) {
global $post;
-
if (!isset($_POST['feedwordpress_noncename']) or !wp_verify_nonce($_POST['feedwordpress_noncename'], plugin_basename(__FILE__))) :
return $post_id;
endif;
@@ -874,6 +877,7 @@ function feedwordpress_save_post_edit_controls ( $post_id ) {
// OK, we're golden. Now let's save some data.
if (isset($_POST['freeze_updates'])) :
+
update_post_meta($post_id, '_syndication_freeze_updates', $_POST['freeze_updates']);
$ret = $_POST['freeze_updates'];
View
@@ -40,7 +40,7 @@ class SyndicatedLink {
var $id = null;
var $link = null;
var $settings = array ();
- var $simplepie = null;
+ public $simplepie = null;
var $magpie = null;
function SyndicatedLink ($link) {
@@ -128,7 +128,7 @@ function live_posts () {
function poll ($crash_ts = NULL) {
global $wpdb;
- $url = $this->uri(array('add_params' => true));
+ $url = $this->uri(array('add_params' => true, 'fetch' => true));
FeedWordPress::diagnostic('updated_feeds', 'Polling feed ['.$url.']');
$this->fetch();
@@ -717,9 +717,12 @@ function is_non_incremental () {
function uri ($params = array()) {
$params = wp_parse_args($params, array(
'add_params' => false,
+ 'fetch' => false,
));
- $uri = (is_object($this->link) ? $this->link->link_rss : NULL);
+ $link_rss = (is_object($this->link) ? $this->link->link_rss : NULL);
+
+ $uri = $link_rss;
if (!is_null($uri) and strlen($uri) > 0 and $params['add_params']) :
$qp = maybe_unserialize($this->setting('query parameters', array()));
@@ -740,6 +743,10 @@ function uri ($params = array()) {
endif;
endif;
+ // Do we have any filters that apply here?
+ $uri = apply_filters('syndicated_link_uri', $uri, $link_rss, $qp, $params, $this);
+
+ // Return the filtered link URI.
return $uri;
} /* SyndicatedLink::uri () */
@@ -834,6 +841,7 @@ function guid () {
// If we can get it live from the feed, do so.
if (is_object($this->simplepie)) :
$search = array(
+ array('', 'id'),
array(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'),
array(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'),
array(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'),
@@ -854,6 +862,60 @@ function guid () {
return $ret;
}
+ function links ($params = array()) {
+ $params = wp_parse_args($params, array(
+ "rel" => NULL,
+ ));
+
+ $fLinks = array();
+ $search = array(
+ array('', 'link'),
+ array(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'),
+ array(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'),
+ );
+
+ foreach ($search as $pair) :
+ if ($link_tags = $this->simplepie->get_feed_tags($pair[0], $pair[1])) :
+ $fLinks = array_merge($fLinks, $link_tags);
+ endif;
+ if ($link_tags = $this->simplepie->get_channel_tags($pair[0], $pair[1])) :
+ $fLinks = array_merge($fLinks, $link_tags);
+ endif;
+ endforeach;
+
+ $ret = array();
+ foreach ($fLinks as $link) :
+ $filter = false;
+ if (!is_null($params['rel'])) :
+ $filter = true;
+
+ if (isset($link['attribs'])) :
+ // Get a list of NSes from the search
+ foreach ($search as $pair) :
+ $ns = $pair[0];
+
+ if (isset($link['attribs'][$ns])
+ and isset($link['attribs'][$ns]['rel'])
+ ) :
+ $rel = strtolower(trim($link['attribs'][$ns]['rel']));
+ $fRel = strtolower(trim($params['rel']));
+
+ if ($rel == $fRel) :
+ $filter = false;
+ endif;
+ endif;
+ endforeach;
+ endif;
+ endif;
+
+ if (!$filter) :
+ $ret[] = $link;
+ endif;
+ endforeach;
+
+ return $ret;
+ }
+
function ttl ($return_element = false) {
if (is_object($this->magpie)) :
$channel = $this->magpie->channel;

0 comments on commit 0ac2a55

Please sign in to comment.