Permalink
Browse files

Fixer up -- deal with everything more systematically, take advantage …

…of new filter hooks provided by FWP 2016.0330 and later.
  • Loading branch information...
Charles Johnson
Charles Johnson committed Mar 30, 2016
1 parent 36eb416 commit 91d6d657cbd3115c969386c3a659d8608d14f700
Showing with 50 additions and 27 deletions.
  1. +50 −27 fwp-preserve-taxonomy-catcher.php
@@ -3,34 +3,42 @@
Plugin Name: FWP+: Preserve Taxonomy (Catcher)
Plugin URI: http://projects.radgeek.com/
Description: install on feed consumer to preserve WordPress taxonomies across FeedWordPress-based syndication
Version: 2011.1109
Version: 2016.0330
Author: Charles Johnson
Author URI: http://radgeek.com/
License: GPL
*/
class FWPPreserveTaxonomyCatcher {
var $feed_terms;
function __construct () {
add_filter('syndicated_item_categories', array($this, 'syndicated_item_categories'), 10, 2);
add_filter('syndicated_item_tags', array($this, 'syndicated_item_tags'), 10, 2);
}
private $feed_terms;
public function __construct () {
add_filter('syndicated_item_feed_terms', array($this, 'syndicated_item_categories'), 10, 2);
add_filter('syndicated_post_terms_mapping', array($this, 'syndicated_post_terms_mapping'), 10, 2);
add_filter('syndicated_post_terms_match', array($this, 'syndicated_post_terms_match'), 10, 3);
add_filter('syndicated_post_terms_unfamiliar', array($this, 'syndicated_post_terms_unfamiliar'), 10, 3);
} /* FWPPreserveTaxonomyCatcher::__construct() */
function syndicated_item_categories ($cats, $post) {
public function syndicated_item_categories ($cats, $post) {
// OK, let's start from scratch.
$cats = array();
$this->feed_terms = array();
$post_cats = $post->entry->get_categories();
if (is_array($post_cats)) : foreach ($post_cats as $cat) :
// When our pitcher is on the mound, taxonomy is indicated by
// an HTTP GET parameter in category/@scheme or category/@domain
//
// If a taxonomy is *not* indicated, or if the taxonomy does not
// exist over here, then we toss these into a bin called '*'
// which can hold just any old term and is processed using
// standard-style inclusive search rules.
$cat_scheme = $cat->get_scheme();
$cat_tax = 'category';
$cat_tax = '*';
if (preg_match(':[?&]taxonomy=([^&]+)(&|$):i', $cat_scheme, $ref)) :
$cat_tax = $ref[1];
if (taxonomy_exists($ref[1])) :
$cat_tax = $ref[1];
endif;
endif;
$cat_name = $cat->get_term();
@@ -56,27 +64,42 @@ function syndicated_item_categories ($cats, $post) {
endif;
endforeach; endif;
if (isset($this->feed_terms['category'])) :
// Replace, don't add, because normally category includes all the
// category elements.
$cats = $this->feed_terms['category'];
if (count($this->feed_terms['*'])) :
if (!isset($this->feed_terms['post_tag'])) :
$this->feed_terms['post_tag'] = array();
endif;
$this->feed_terms['post_tag'] = array_merge($this->feed_terms['post_tag'], $post->inline_tags());
endif;
// Once it's passed back, we take it off the pile.
unset($this->feed_terms['category']);
return $this->feed_terms;
} /* FWPPreserveTaxonomyCatcher::syndicated_item_feed_terms () */
public function syndicated_post_terms_match ($taxonomies, $what, $post) {
if ($what != '*') :
// Stay in your lane.
$taxonomies = array($what);
endif;
return $cats;
} /* FWPPreserveTaxonomyCatcher::syndicated_item_categories () */
return $taxonomies;
} /* FWPPreserveTaxonomyCatcher::syndicated_post_terms_match() */
function syndicated_item_tags ($tags, $post) {
if (isset($this->feed_terms['post_tag'])) :
$tags = array_merge($tags, $this->feed_terms['post_tag']);
unset($this->feed_terms['post_tag']);
public function syndicated_post_terms_mapping ($map, $post) {
$map['*'] = $map['category'];
return $map;
} /* FWPPreserveTaxonomyCatcher::syndicated_post_term_mapping() */
public function syndicated_post_terms_unfamiliar ($unfamiliar, $what, $post) {
if (preg_match('/^create(:(.*))?$/i', $unfamiliar, $ref)) :
if ($what != '*') :
// Stay in your lane.
$unfamiliar = 'create:' . $what;
endif;
endif;
return $tags;
} /* FWPPreserveTaxonomyCatcher::syndicated_item_tags () */
}
return $unfamiliar;
} /* FWPPreserveTaxonomyCatcher::syndicated_post_terms_unfamiliar () */
} /* FWPPreserveTaxonomyCatcher */
$fwpPTC = new FWPPreserveTaxonomyCatcher;

0 comments on commit 91d6d65

Please sign in to comment.