PluginProbe
FeedWordPress / 2014.0805
FeedWordPress v2014.0805
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 | syndicatedpost.class.php +597 -710 trunk2014.0805 View file →
@@ -1,8 +1,7 @@
1 1 <?php
2 -require_once dirname(__FILE__) . '/feedtime.class.php';
3 -require_once dirname(__FILE__) . '/syndicatedpostterm.class.php';
4 -require_once dirname(__FILE__) . '/syndicatedpostxpathquery.class.php';
2 +require_once(dirname(__FILE__).'/feedtime.class.php');
3 +require_once(dirname(__FILE__).'/syndicatedpostterm.class.php');
5 4
6 5 /**
7 6 * class SyndicatedPost: FeedWordPress uses to manage the conversion of
8 7 * incoming items from the feed parser into posts for the WordPress
@@ -11,27 +10,25 @@
11 10 * as some utility methods for extracting useful data from many
12 11 * different feed formats, which may be useful to FeedWordPress users
13 12 * who make use of feed data in PHP add-ons and filters.
14 13 *
15 - * @version 2017.1018
14 + * @version 2013.0525
16 15 */
17 16 class SyndicatedPost {
18 - /** @var MagpieRSS|null MagpieRSS representation. */
19 - var $item = null;
20 - /** @var SimplePie_Item|null SimplePie_Item representation. */
21 - var $entry = null;
17 + var $item = null; // MagpieRSS representation
18 + var $entry = null; // SimplePie_Item representation
22 19
23 20 var $link = null;
24 21 var $feed = null;
25 22 var $feedmeta = null;
26 23
27 - var $xmlns = array();
24 + var $xmlns = array ();
28 25
29 - var $post = array();
26 + var $post = array ();
30 27
31 - var $named = array();
32 - var $preset_terms = array();
33 - var $feed_terms = array();
28 + var $named = array ();
29 + var $preset_terms = array ();
30 + var $feed_terms = array ();
34 31
35 32 var $_freshness = null;
36 33 var $_wp_id = null;
37 34 var $_wp_post = null;
@@ -44,57 +41,74 @@
44 41 *
45 42 * @param array $item The item syndicated from the feed.
46 43 * @param SyndicatedLink $source The feed it was syndicated from.
47 44 */
48 - public function __construct( $item, $source ) {
49 - if ( empty( $item ) and empty( $source ) )
45 + function SyndicatedPost ($item, &$source) {
46 + global $wpdb;
47 +
48 + if ( empty($item) && empty($source) )
50 49 return;
51 50
52 - if ( is_array( $item )
53 - and isset( $item['simplepie'] )
54 - and isset( $item['magpie'] ) ) :
51 + if (is_array($item)
52 + and isset($item['simplepie'])
53 + and isset($item['magpie'])) :
55 54 $this->entry = $item['simplepie'];
56 55 $this->item = $item['magpie'];
57 56 $item = $item['magpie'];
58 - elseif ( is_a( $item, 'SimplePie_Item' ) ) :
57 + elseif (is_a($item, 'SimplePie_Item')) :
59 58 $this->entry = $item;
60 59
61 60 // convert to Magpie for compat purposes
62 - $mpie = new MagpieFromSimplePie( $source->simplepie, $this->entry );
63 - $this->item = $mpie->get_item();
61 + $mp = new MagpieFromSimplePie($source->simplepie, $this->entry);
62 + $this->item = $mp->get_item();
64 63
65 64 // done with conversion object
66 - $mpie = NULL; unset( $mpie );
65 + $mp = NULL; unset($mp);
67 66 else :
68 67 $this->item = $item;
69 68 endif;
70 69
71 - $this->link = $source;
70 + $this->link =& $source;
72 71 $this->feed = $source->magpie;
73 72 $this->feedmeta = $source->settings;
74 73
75 - FeedWordPress::diagnostic( 'feed_items', 'Considering item [' . $this->guid() . '] "' . $this->entry->get_title().'"');
74 + FeedWordPress::diagnostic('feed_items', 'Considering item ['.$this->guid().'] "'.$this->entry->get_title().'"');
76 75
77 76 # Dealing with namespaces can get so fucking fucked.
78 77 $this->xmlns['forward'] = $source->magpie->_XMLNS_FAMILIAR;
79 78 $this->xmlns['reverse'] = array();
80 - foreach ( $this->xmlns['forward'] as $url => $ns ) :
81 - if ( ! isset( $this->xmlns['reverse'][ $ns ] ) ) :
82 - $this->xmlns['reverse'][ $ns ] = array();
79 + foreach ($this->xmlns['forward'] as $url => $ns) :
80 + if (!isset($this->xmlns['reverse'][$ns])) :
81 + $this->xmlns['reverse'][$ns] = array();
83 82 endif;
84 - $this->xmlns['reverse'][ $ns ][] = $url;
83 + $this->xmlns['reverse'][$ns][] = $url;
85 84 endforeach;
86 85
87 86 // Fucking SimplePie.
88 87 $this->xmlns['reverse']['rss'][] = '';
89 88
89 + # These globals were originally an ugly kludge around a bug in
90 + # apply_filters from WordPress 1.5. The bug was fixed in 1.5.1,
91 + # and I sure hope at this point that nobody writing filters for
92 + # FeedWordPress is still relying on them.
93 + #
94 + # Anyway, I hereby declare them DEPRECATED as of 8 February
95 + # 2010. I'll probably remove the globals within 1-2 releases in
96 + # the interests of code hygiene and memory usage. If you
97 + # currently use them in your filters, I advise you switch off to
98 + # accessing the public members SyndicatedPost::feed and
99 + # SyndicatedPost::feedmeta.
100 +
101 + global $fwp_channel, $fwp_feedmeta;
102 + $fwp_channel = $this->feed; $fwp_feedmeta = $this->feedmeta;
103 +
90 104 // Trigger global syndicated_item filter.
91 - $changed = apply_filters( 'syndicated_item', $this->item, $this );
105 + $changed = apply_filters('syndicated_item', $this->item, $this);
92 106 $this->item = $changed;
93 107
94 108 // Allow for feed-specific syndicated_item filters.
95 109 $changed = apply_filters(
96 - "syndicated_item_" . $source->uri(),
110 + "syndicated_item_".$source->uri(),
97 111 $this->item,
98 112 $this
99 113 );
100 114 $this->item = $changed;
@@ -99,12 +113,11 @@
99 113 );
100 114 $this->item = $changed;
101 115
102 116 # Filters can halt further processing by returning NULL
103 - if ( is_null( $this->item ) ) :
117 + if (is_null($this->item)) :
104 118 $this->post = NULL;
105 119 else :
106 -
107 120 # Note that nothing is run through esc_sql() here.
108 121 # That's deliberate. The escaping is done at the point
109 122 # of insertion, not here, to avoid double-escaping and
110 123 # to avoid screwing with syndicated_post filters
@@ -110,78 +123,71 @@
110 123 # to avoid screwing with syndicated_post filters
111 124
112 125 $this->post['post_title'] = apply_filters(
113 126 'syndicated_item_title',
114 - $this->entry->get_title(),
115 - $this
127 + $this->entry->get_title(), $this
116 128 );
117 129
118 130 $this->named['author'] = apply_filters(
119 131 'syndicated_item_author',
120 - $this->author(),
121 - $this
132 + $this->author(), $this
122 133 );
123 134 // This just gives us an alphanumeric name for the author.
124 135 // We look up (or create) the numeric ID for the author
125 136 // in SyndicatedPost::add().
126 -
137 +
127 138 $this->post['post_content'] = apply_filters(
128 139 'syndicated_item_content',
129 - $this->content(),
130 - $this
140 + $this->content(), $this
131 141 );
132 -
133 - $excerpt = apply_filters( 'syndicated_item_excerpt', $this->excerpt(), $this );
134 -
135 - if ( !empty( $excerpt ) ):
142 +
143 + $excerpt = apply_filters('syndicated_item_excerpt', $this->excerpt(), $this);
144 + if (!empty($excerpt)):
136 145 $this->post['post_excerpt'] = $excerpt;
137 146 endif;
138 147
139 148 // Dealing with timestamps in WordPress is so fucking fucked.
140 - $offset = (int) get_option( 'gmt_offset' ) * 60 * 60;
141 - $post_date_gmt = $this->published( array( 'default' => -1 ) );
142 - $post_modified_gmt = $this->updated( array( 'default' => -1 ) );
149 + $offset = (int) get_option('gmt_offset') * 60 * 60;
150 + $post_date_gmt = $this->published(array('default' => -1));
151 + $post_modified_gmt = $this->updated(array('default' => -1));
143 152
144 - $this->post['post_date_gmt'] = gmdate( 'Y-m-d H:i:s', $post_date_gmt );
145 - $this->post['post_date'] = gmdate( 'Y-m-d H:i:s', $post_date_gmt + $offset );
146 - $this->post['post_modified_gmt'] = gmdate( 'Y-m-d H:i:s', $post_modified_gmt );
147 - $this->post['post_modified'] = gmdate( 'Y-m-d H:i:s', $post_modified_gmt + $offset );
153 + $this->post['post_date_gmt'] = gmdate('Y-m-d H:i:s', $post_date_gmt);
154 + $this->post['post_date'] = gmdate('Y-m-d H:i:s', $post_date_gmt + $offset);
155 + $this->post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $post_modified_gmt);
156 + $this->post['post_modified'] = gmdate('Y-m-d H:i:s', $post_modified_gmt + $offset);
148 157
149 158 // Use feed-level preferences or the global default.
150 - $this->post['post_status'] = $this->link->syndicated_status( 'post', 'publish' );
151 - $this->post['comment_status'] = $this->link->syndicated_status( 'comment', 'closed' );
152 - $this->post['ping_status'] = $this->link->syndicated_status( 'ping', 'closed' );
159 + $this->post['post_status'] = $this->link->syndicated_status('post', 'publish');
160 + $this->post['comment_status'] = $this->link->syndicated_status('comment', 'closed');
161 + $this->post['ping_status'] = $this->link->syndicated_status('ping', 'closed');
153 162
154 163 // Unique ID (hopefully a unique tag: URI); failing that, the permalink
155 - $this->post['guid'] = apply_filters( 'syndicated_item_guid', $this->guid(), $this );
164 + $this->post['guid'] = apply_filters('syndicated_item_guid', $this->guid(), $this);
156 165
157 166 // User-supplied custom settings to apply to each post.
158 167 // Do first so that FWP-generated custom settings will
159 168 // overwrite if necessary; thus preventing any munging.
160 - $postMetaIn = $this->link->postmeta( array( "parsed" => true ) );
169 + $postMetaIn = $this->link->postmeta(array("parsed" => true));
161 170 $postMetaOut = array();
162 171
163 - foreach ( $postMetaIn as $key => $meta ) :
164 - $postMetaOut[ $key ] = $meta->do_substitutions( $this );
172 + foreach ($postMetaIn as $key => $meta) :
173 + $postMetaOut[$key] = $meta->do_substitutions($this);
165 174 endforeach;
166 175
167 - foreach ( $postMetaOut as $key => $values ) :
168 - if ( is_null( $values ) ) { // have chosen to replace value with empty string
169 - $values = [ '' ];
170 - }
171 - $this->post['meta'][ $key ] = array();
172 - foreach ( $values as $value ) :
173 - $this->post['meta'][ $key ][] = apply_filters( "syndicated_post_meta_{$key}", $value, $this );
176 + foreach ($postMetaOut as $key => $values) :
177 + $this->post['meta'][$key] = array();
178 + foreach ($values as $value) :
179 + $this->post['meta'][$key][] = apply_filters("syndicated_post_meta_{$key}", $value, $this);
174 180 endforeach;
175 181 endforeach;
176 182
177 183 // RSS 2.0 / Atom 1.0 enclosure support
178 184 $enclosures = $this->entry->get_enclosures();
179 - if ( is_array( $enclosures ) ) : foreach ( $enclosures as $enclosure ) :
185 + if (is_array($enclosures)) : foreach ($enclosures as $enclosure) :
180 186 $this->post['meta']['enclosure'][] =
181 - apply_filters( 'syndicated_item_enclosure_url', $enclosure->get_link(), $this ) . "\n".
182 - apply_filters( 'syndicated_item_enclosure_length', $enclosure->get_length(), $this ) . "\n".
183 - apply_filters( 'syndicated_item_enclosure_type', $enclosure->get_type(), $this );
187 + apply_filters('syndicated_item_enclosure_url', $enclosure->get_link(), $this)."\n".
188 + apply_filters('syndicated_item_enclosure_length', $enclosure->get_length(), $this)."\n".
189 + apply_filters('syndicated_item_enclosure_type', $enclosure->get_type(), $this);
184 190 endforeach; endif;
185 191
186 192 // In case you want to point back to the blog this was
187 193 // syndicated from.
@@ -203,18 +209,18 @@
203 209 );
204 210
205 211 // Make use of atom:source data, if present in an aggregated feed
206 212 $entry_source = $this->source();
207 - if ( ! is_null( $entry_source ) ) :
208 - foreach ( $entry_source as $what => $value ) :
209 - if ( ! is_null( $value ) ) :
210 - if ( 'title' == $what ) : $key = 'syndication_source';
211 - elseif ( 'feed' == $what ) : $key = 'syndication_feed';
212 - else : $key = "syndication_source_{$what}";
213 + if (!is_null($entry_source)) :
214 + foreach ($entry_source as $what => $value) :
215 + if (!is_null($value)) :
216 + if ($what=='title') : $key = 'syndication_source';
217 + elseif ($what=='feed') : $key = 'syndication_feed';
218 + else : $key = "syndication_source_${what}";
213 219 endif;
214 220
215 - $sourcemeta["{$key}_original"] = apply_filters(
216 - 'syndicated_item_original_source_' . $what,
221 + $sourcemeta["${key}_original"] = apply_filters(
222 + 'syndicated_item_original_source_'.$what,
217 223 $value,
218 224 $this
219 225 );
220 226 endif;
@@ -220,11 +226,11 @@
220 226 endif;
221 227 endforeach;
222 228 endif;
223 229
224 - foreach ( $sourcemeta as $meta_key => $value ) :
225 - if ( !is_null( $value ) ) :
226 - $this->post['meta'][ $meta_key ] = $value;
230 + foreach ($sourcemeta as $meta_key => $value) :
231 + if (!is_null($value)) :
232 + $this->post['meta'][$meta_key] = $value;
227 233 endif;
228 234 endforeach;
229 235
230 236 // Store information on human-readable and machine-readable comment URIs
@@ -229,47 +235,121 @@
229 235
230 236 // Store information on human-readable and machine-readable comment URIs
231 237
232 238 // Human-readable comment URI
233 - $commentLink = apply_filters( 'syndicated_item_comments', $this->comment_link(), $this );
234 - if ( ! is_null( $commentLink) ) : $this->post['meta']['rss:comments'] = $commentLink; endif;
239 + $commentLink = apply_filters('syndicated_item_comments', $this->comment_link(), $this);
240 + if (!is_null($commentLink)) : $this->post['meta']['rss:comments'] = $commentLink; endif;
235 241
236 242 // Machine-readable content feed URI
237 - $commentFeed = apply_filters( 'syndicated_item_commentrss', $this->comment_feed(), $this );
238 - if ( ! is_null( $commentFeed ) ) : $this->post['meta']['wfw:commentRSS'] = $commentFeed; endif;
243 + $commentFeed = apply_filters('syndicated_item_commentrss', $this->comment_feed(), $this);
244 + if (!is_null($commentFeed)) : $this->post['meta']['wfw:commentRSS'] = $commentFeed; endif;
239 245 // Yeah, yeah, now I know that it's supposed to be
240 246 // wfw:commentRss. Oh well. Path dependence, sucka.
241 247
242 248 // Store information to identify the feed that this came from
243 - if ( isset( $this->feedmeta['link/uri'] ) ) :
249 + if (isset($this->feedmeta['link/uri'])) :
244 250 $this->post['meta']['syndication_feed'] = $this->feedmeta['link/uri'];
245 251 endif;
246 - if ( isset( $this->feedmeta['link/id'] ) ) :
252 + if (isset($this->feedmeta['link/id'])) :
247 253 $this->post['meta']['syndication_feed_id'] = $this->feedmeta['link/id'];
248 254 endif;
249 255
250 - if ( isset( $this->item['source_link_self'] ) ) :
256 + if (isset($this->item['source_link_self'])) :
251 257 $this->post['meta']['syndication_feed_original'] = $this->item['source_link_self'];
252 258 endif;
253 259
254 260 // In case you want to know the external permalink...
255 - $this->post['meta']['syndication_permalink'] = apply_filters( 'syndicated_item_link', $this->permalink() );
261 + $this->post['meta']['syndication_permalink'] = apply_filters('syndicated_item_link', $this->permalink());
256 262
257 263 // Store a hash of the post content for checking whether something needs to be updated
258 264 $this->post['meta']['syndication_item_hash'] = $this->update_hash();
259 265
260 - // Categories, Tags, and other Terms: from settings assignments (global settings, subscription settings),
261 - // and from feed assignments (item metadata, post content)
262 - $this->preset_terms = apply_filters( 'syndicated_item_preset_terms', $this->get_terms_from_settings(), $this );
263 - $this->feed_terms = apply_filters( 'syndicated_item_feed_terms', $this->get_terms_from_feeds(), $this );
266 + // Categories: start with default categories, if any.
267 + $cats = array();
268 + if ('no' != $this->link->setting('add/category', NULL, 'yes')) :
269 + $fc = get_option("feedwordpress_syndication_cats");
270 + if ($fc) :
271 + $cats = array_merge($cats, explode("\n", $fc));
272 + endif;
273 + endif;
264 274
265 - $this->post['post_type'] = apply_filters(
266 - 'syndicated_post_type',
267 - $this->link->setting( 'syndicated post type', 'syndicated_post_type', 'post' ),
268 - $this
269 - );
275 + $fc = $this->link->setting('cats', NULL, array());
276 + if (is_array($fc)) :
277 + $cats = array_merge($cats, $fc);
278 + endif;
279 + $this->preset_terms['category'] = $cats;
280 +
281 + // Now add categories from the post, if we have 'em
282 + $cats = array();
283 + $post_cats = $this->entry->get_categories();
284 + if (is_array($post_cats)) : foreach ($post_cats as $cat) :
285 + $cat_name = $cat->get_term();
286 + if (!$cat_name) : $cat_name = $cat->get_label(); endif;
287 +
288 + if ($this->link->setting('cat_split', NULL, NULL)) :
289 + $pcre = "\007".$this->feedmeta['cat_split']."\007";
290 + $cats = array_merge(
291 + $cats,
292 + preg_split(
293 + $pcre,
294 + $cat_name,
295 + -1 /*=no limit*/,
296 + PREG_SPLIT_NO_EMPTY
297 + )
298 + );
299 + else :
300 + $cats[] = $cat_name;
301 + endif;
302 + endforeach; endif;
303 +
304 + $this->feed_terms['category'] = apply_filters('syndicated_item_categories', $cats, $this);
305 +
306 + // Tags: start with default tags, if any
307 + $tags = array();
308 + if ('no' != $this->link->setting('add/post_tag', NULL, 'yes')) :
309 + $ft = get_option("feedwordpress_syndication_tags", NULL);
310 + $tags = (is_null($ft) ? array() : explode(FEEDWORDPRESS_CAT_SEPARATOR, $ft));
311 + endif;
312 +
313 + $ft = $this->link->setting('tags', NULL, array());
314 + if (is_array($ft)) :
315 + $tags = array_merge($tags, $ft);
316 + endif;
317 + $this->preset_terms['post_tag'] = $tags;
318 +
319 + // Scan post for /a[@rel='tag'] and use as tags if present
320 + $tags = $this->inline_tags();
321 + $this->feed_terms['post_tag'] = apply_filters('syndicated_item_tags', $tags, $this);
322 +
323 + $taxonomies = $this->link->taxonomies();
324 + $feedTerms = $this->link->setting('terms', NULL, array());
325 + $globalTerms = get_option('feedwordpress_syndication_terms', array());
326 +
327 + $specials = array('category' => 'cats', 'post_tag' => 'tags');
328 + foreach ($taxonomies as $tax) :
329 + if (!isset($specials[$tax])) :
330 + $terms = array();
331 +
332 + // See if we should get the globals
333 + if ('no' != $this->link->setting("add/$tax", NULL, 'yes')) :
334 + if (isset($globalTerms[$tax])) :
335 + $terms = $globalTerms[$tax];
336 + endif;
337 + endif;
338 +
339 + // Now merge in the locals
340 + if (isset($feedTerms[$tax])) :
341 + $terms = array_merge($terms, $feedTerms[$tax]);
342 + endif;
343 +
344 + // That's all, folks.
345 + $this->preset_terms[$tax] = $terms;
346 + endif;
347 + endforeach;
348 +
349 + $this->post['post_type'] = apply_filters('syndicated_post_type', $this->link->setting('syndicated post type', 'syndicated_post_type', 'post'), $this);
270 350 endif;
271 - } /* SyndicatedPost::__construct() */
351 + } /* SyndicatedPost::SyndicatedPost() */
272 352
273 353 #####################################
274 354 #### EXTRACT DATA FROM FEED ITEM ####
275 355 #####################################
@@ -298,29 +378,100 @@
298 378 * @param string $path
299 379 * @returns array of string values representing contents of matching
300 380 * elements or attributes
301 381 */
302 - public function query ($path) {
303 - $xq = new SyndicatedPostXPathQuery(array("path" => $path));
382 + function query ($path) {
383 + $urlHash = array();
304 384
305 - $feedChannel = array_merge(
306 - $this->get_feed_root_element(),
307 - $this->get_feed_channel_elements()
308 - );
385 + // Allow {url} notation for namespaces. URLs will contain : and /, so...
386 + preg_match_all('/{([^}]+)}/', $path, $match, PREG_SET_ORDER);
387 + foreach ($match as $ref) :
388 + $urlHash[md5($ref[1])] = $ref[1];
389 + endforeach;
309 390
310 - $matches = $xq->match(array(
311 - "type" => $this->link->simplepie->get_type(),
312 - "xmlns" => $this->xmlns,
313 - "map" => array(
314 - "/" => array($this->entry->data),
315 - "item" => array($this->entry->data),
316 - "feed" => $feedChannel,
317 - "channel" => $feedChannel
318 - ),
319 - "context" => $this->entry->data,
320 - "parent" => $feedChannel,
321 - ));
391 + foreach ($urlHash as $hash => $url) :
392 + $path = str_replace('{'.$url.'}', '{#'.$hash.'}', $path);
393 + endforeach;
322 394
395 + $path = explode('/', $path);
396 + foreach ($path as $index => $node) :
397 + if (preg_match('/{#([^}]+)}/', $node, $ref)) :
398 + if (isset($urlHash[$ref[1]])) :
399 + $path[$index] = str_replace(
400 + '{#'.$ref[1].'}',
401 + '{'.$urlHash[$ref[1]].'}',
402 + $node
403 + );
404 + endif;
405 + endif;
406 + endforeach;
407 +
408 + // Start out with a get_item_tags query.
409 + $node = '';
410 + while (strlen($node)==0 and !is_null($node)) :
411 + $node = array_shift($path);
412 + endwhile;
413 +
414 + switch ($node) :
415 + case 'feed' :
416 + case 'channel' :
417 + $node = array_shift($path);
418 + $data = $this->get_feed_root_element();
419 + $data = array_merge($data, $this->get_feed_channel_elements());
420 + break;
421 + case 'item' :
422 + $node = array_shift($path);
423 + default :
424 + $data = array($this->entry->data);
425 + $method = NULL;
426 + endswitch;
427 +
428 + while (!is_null($node)) :
429 + if (strlen($node) > 0) :
430 + $matches = array();
431 +
432 + list($axis, $element) = $this->xpath_name_and_axis($node);
433 +
434 + foreach ($data as $datum) :
435 + if (!is_string($datum) and isset($datum[$axis])) :
436 + foreach ($datum[$axis] as $ns => $elements) :
437 + if (isset($elements[$element])) :
438 + // Potential match.
439 + // Check namespace.
440 + if (is_string($elements[$element])) : // Attribute
441 + $addenda = array($elements[$element]);
442 + $contexts = array($datum);
443 + else : // Element
444 + $addenda = $elements[$element];
445 + $contexts = $elements[$element];
446 + endif;
447 +
448 + foreach ($addenda as $index => $addendum) :
449 + $context = $contexts[$index];
450 +
451 + $namespaces = $this->xpath_possible_namespaces($node, $context);
452 + if (in_array($ns, $namespaces)) :
453 + $matches[] = $addendum;
454 + endif;
455 + endforeach;
456 + endif;
457 + endforeach;
458 + endif;
459 + endforeach;
460 +
461 + $data = $matches;
462 + endif;
463 + $node = array_shift($path);
464 + endwhile;
465 +
466 + $matches = array();
467 + foreach ($data as $datum) :
468 + if (is_string($datum)) :
469 + $matches[] = $datum;
470 + elseif (isset($datum['data'])) :
471 + $matches[] = $datum['data'];
472 + endif;
473 + endforeach;
323 474 return $matches;
324 475 } /* SyndicatedPost::query() */
325 476
326 477 function get_feed_root_element () {
@@ -343,9 +494,9 @@
343 494
344 495 $matches = array();
345 496 foreach ($rss as $ns) :
346 497 $data = $this->link->simplepie->get_feed_tags($ns, 'channel');
347 - if ( !is_null($data)) :
498 + if (!is_null($data)) :
348 499 $matches = array_merge($matches, $data);
349 500 endif;
350 501 endforeach;
351 502 return $matches;
@@ -350,24 +501,101 @@
350 501 endforeach;
351 502 return $matches;
352 503 } /* SyndicatedPost::get_feed_channel_elements() */
353 504
354 - public function get_categories ($params = array()) {
505 + function xpath_default_namespace () {
506 + // Get the default namespace.
507 + $type = $this->link->simplepie->get_type();
508 + if ($type & SIMPLEPIE_TYPE_ATOM_10) :
509 + $defaultNS = SIMPLEPIE_NAMESPACE_ATOM_10;
510 + elseif ($type & SIMPLEPIE_TYPE_ATOM_03) :
511 + $defaultNS = SIMPLEPIE_NAMESPACE_ATOM_03;
512 + elseif ($type & SIMPLEPIE_TYPE_RSS_090) :
513 + $defaultNS = SIMPLEPIE_NAMESPACE_RSS_090;
514 + elseif ($type & SIMPLEPIE_TYPE_RSS_10) :
515 + $defaultNS = SIMPLEPIE_NAMESPACE_RSS_10;
516 + elseif ($type & SIMPLEPIE_TYPE_RSS_20) :
517 + $defaultNS = SIMPLEPIE_NAMESPACE_RSS_20;
518 + else :
519 + $defaultNS = SIMPLEPIE_NAMESPACE_RSS_20;
520 + endif;
521 + return $defaultNS;
522 + } /* SyndicatedPost::xpath_default_namespace() */
523 +
524 + function xpath_name_and_axis ($node) {
525 + $ns = NULL; $element = NULL;
526 +
527 + if (substr($node, 0, 1)=='@') :
528 + $axis = 'attribs'; $node = substr($node, 1);
529 + else :
530 + $axis = 'child';
531 + endif;
532 +
533 + if (preg_match('/^{([^}]*)}(.*)$/', $node, $ref)) :
534 + $element = $ref[2];
535 + elseif (strpos($node, ':') !== FALSE) :
536 + list($xmlns, $element) = explode(':', $node, 2);
537 + else :
538 + $element = $node;
539 + endif;
540 + return array($axis, $element);
541 + } /* SyndicatedPost::xpath_local_name () */
542 +
543 + function xpath_possible_namespaces ($node, $datum = array()) {
544 + $ns = NULL; $element = NULL;
545 +
546 + if (substr($node, 0, 1)=='@') :
547 + $attr = '@'; $node = substr($node, 1);
548 + else :
549 + $attr = '';
550 + endif;
551 +
552 + if (preg_match('/^{([^}]*)}(.*)$/', $node, $ref)) :
553 + $ns = array($ref[1]);
554 + elseif (strpos($node, ':') !== FALSE) :
555 + list($xmlns, $element) = explode(':', $node, 2);
556 +
557 + if (isset($this->xmlns['reverse'][$xmlns])) :
558 + $ns = $this->xmlns['reverse'][$xmlns];
559 + else :
560 + $ns = array($xmlns);
561 + endif;
562 +
563 + // Fucking SimplePie. For attributes in default xmlns.
564 + $defaultNS = $this->xpath_default_namespace();
565 + if (isset($this->xmlns['forward'][$defaultNS])
566 + and ($xmlns==$this->xmlns['forward'][$defaultNS])) :
567 + $ns[] = '';
568 + endif;
569 +
570 + if (isset($datum['xmlns'])) :
571 + if (isset($datum['xmlns'][$xmlns])) :
572 + $ns[] = $datum['xmlns'][$xmlns];
573 + endif;
574 + endif;
575 + else :
576 + // Often in SimplePie, the default namespace gets stored
577 + // as an empty string rather than a URL.
578 + $ns = array($this->xpath_default_namespace(), '');
579 + endif;
580 + return array_unique($ns);
581 + } /* SyndicatedPost::xpath_possible_namespaces() */
582 +
583 + function get_categories ($params = array()) {
355 584 return $this->entry->get_categories();
356 585 }
357 -
358 - public function title ($params = array()) {
586 +
587 + function title ($params = array()) {
359 588 return $this->entry->get_title();
360 589 } /* SyndicatedPost::title () */
361 -
362 - public function content ($params = array())
363 - {
590 +
591 + function content ($params = array()) {
364 592 $params = wp_parse_args($params, array(
365 - "full only" => false,
593 + "full only" => false,
366 594 ));
367 -
595 +
368 596 $content = NULL;
369 -
597 +
370 598 // FIXME: This is one of the main places in the code still using
371 599 // the outmoded SimplePie - to - Magpie construction. We could
372 600 // replace using SimplePie_Item::get_tags() here. (Or if really
373 601 // ambitious we could attempt to just use
@@ -372,9 +600,9 @@
372 600 // replace using SimplePie_Item::get_tags() here. (Or if really
373 601 // ambitious we could attempt to just use
374 602 // SimplePie_Item::get_content() with content-only set to TRUE
375 603 // and some sanitization in effect. -CJ 1jul14
376 -
604 +
377 605 // atom:content, standard method of providing full HTML content
378 606 // in Atom feeds.
379 607 if (isset($this->item['atom_content'])) :
380 608 $content = $this->item['atom_content'];
@@ -379,9 +607,9 @@
379 607 if (isset($this->item['atom_content'])) :
380 608 $content = $this->item['atom_content'];
381 609 elseif (isset($this->item['atom']['atom_content'])) :
382 610 $content = $this->item['atom']['atom_content'];
383 -
611 +
384 612 // Some exotics: back in the day, before widespread convergence
385 613 // on content:encoding, some RSS feeds took advantage of XML
386 614 // namespaces to use an inline xhtml:body or xhtml:div element
387 615 // for full-content HTML. (E.g. Sam Ruby's feed, IIRC.)
@@ -388,18 +616,18 @@
388 616 elseif (isset($this->item['xhtml']['body'])) :
389 617 $content = $this->item['xhtml']['body'];
390 618 elseif (isset($this->item['xhtml']['div'])) :
391 619 $content = $this->item['xhtml']['div'];
392 -
620 +
393 621 // content:encoded, most common method of providing full HTML in
394 622 // RSS 2.0 feeds.
395 623 elseif (isset($this->item['content']['encoded']) and $this->item['content']['encoded']):
396 624 $content = $this->item['content']['encoded'];
397 -
625 +
398 626 // Fall back on elements that sometimes may contain full HTML
399 627 // but sometimes not.
400 - elseif ( ! $params['full only']) :
401 -
628 + elseif (!$params['full only']) :
629 +
402 630 // description element is sometimes used for full HTML
403 631 // sometimes for summary text in RSS. (By the letter of
404 632 // the standard, it should just be for summary text.)
405 633 if (isset($this->item['description'])) :
@@ -404,15 +632,14 @@
404 632 // the standard, it should just be for summary text.)
405 633 if (isset($this->item['description'])) :
406 634 $content = $this->item['description'];
407 635 endif;
408 -
636 +
409 637 endif;
410 -
411 638 return $content;
412 639 } /* SyndicatedPost::content() */
413 640
414 - public function excerpt () {
641 + function excerpt () {
415 642 # Identify and sanitize excerpt: atom:summary, or rss:description
416 643 $excerpt = $this->entry->get_description();
417 644
418 645 # Many RSS feeds use rss:description, inadvisably, to
@@ -421,43 +648,32 @@
421 648 # content for the excerpt.
422 649 $content = $this->content();
423 650
424 651 // Ignore whitespace, case, and tag cruft.
425 - $theExcerpt = preg_replace('/\s+/', '', strtolower(strip_tags(html_entity_decode($excerpt))));
426 - $theContent = preg_replace('/\s+/', '', strtolower(strip_tags(html_entity_decode($content))));
652 + $theExcerpt = preg_replace('/\s+/', '', strtolower(strip_tags($excerpt)));
653 + $theContent = preg_replace('/\s+/', '', strtolower(strip_tags($content)));
654 +
427 655 if ( empty($excerpt) or $theExcerpt == $theContent ) :
428 656 # If content is available, generate an excerpt.
429 657 if ( strlen(trim($content)) > 0 ) :
430 658 $excerpt = strip_tags($content);
431 659 if (strlen($excerpt) > 255) :
432 - if (is_object($this->link) and is_object($this->link->simplepie)) :
433 - $encoding = $this->link->simplepie->get_encoding();
434 - else :
435 - $encoding = get_option('blog_charset', 'utf8');
436 - endif;
437 - $excerpt = mb_substr($excerpt,0,252,$encoding).'...';
660 + $excerpt = substr($excerpt,0,252).'...';
438 661 endif;
439 662 endif;
440 663 endif;
441 -
442 664 return $excerpt;
443 665 } /* SyndicatedPost::excerpt() */
444 666
445 - /**
446 - * SyndicatedPost::permalink: returns the permalink for the post, as provided by the
447 - * source feed.
448 - *
449 - * @return string The URL of the original permalink for this syndicated post
450 - */
451 - public function permalink () {
667 + function permalink () {
452 668 // Handles explicit <link> elements and also RSS 2.0 cases with
453 669 // <guid isPermaLink="true">, etc. Hooray!
454 670 $permalink = $this->entry->get_link();
455 671 return $permalink;
456 - } /* SyndicatedPost::permalink () */
672 + }
457 673
458 - public function created ($params = array()) {
459 - $unfiltered = false; // $default = NULL; // seems to be unused on this function (gwyneth 20230916)
674 + function created ($params = array()) {
675 + $unfiltered = false; $default = NULL;
460 676 extract($params);
461 677
462 678 $date = '';
463 679 if (isset($this->item['dc']['created'])) :
@@ -468,18 +684,18 @@
468 684 $date = $this->item['created'];
469 685 endif;
470 686
471 687 $time = new FeedTime($date);
472 - $tstamp = $time->timestamp();
473 - if ( ! $unfiltered) :
474 - apply_filters('syndicated_item_created', $tstamp, $this);
688 + $ts = $time->timestamp();
689 + if (!$unfiltered) :
690 + apply_filters('syndicated_item_created', $ts, $this);
475 691 endif;
476 - return $tstamp;
692 + return $ts;
477 693 } /* SyndicatedPost::created() */
478 694
479 - public function published ($params = array(), $default = NULL) {
695 + function published ($params = array(), $default = NULL) {
480 696 $fallback = true; $unfiltered = false;
481 - if ( !is_array($params)) : // Old style
697 + if (!is_array($params)) : // Old style
482 698 $fallback = $params;
483 699 else : // New style
484 700 extract($params);
485 701 endif;
@@ -484,9 +700,9 @@
484 700 extract($params);
485 701 endif;
486 702
487 703 $date = '';
488 - $tstamp = null;
704 + $ts = null;
489 705
490 706 # RSS is a fucking mess. Figure out whether we have a date in
491 707 # <dc:date>, <issued>, <pubDate>, etc., and get it into Unix
492 708 # epoch format for reformatting. If we can't find anything,
@@ -504,31 +720,31 @@
504 720 endif;
505 721
506 722 if (strlen($date) > 0) :
507 723 $time = new FeedTime($date);
508 - $tstamp = $time->timestamp();
724 + $ts = $time->timestamp();
509 725 elseif ($fallback) : // Fall back to <updated> / <modified> if present
510 - $tstamp = $this->updated(/*fallback=*/ false, /*default=*/ $default);
726 + $ts = $this->updated(/*fallback=*/ false, /*default=*/ $default);
511 727 endif;
512 728
513 729 # If everything failed, then default to the current time.
514 - if (is_null($tstamp)) :
730 + if (is_null($ts)) :
515 731 if (-1 == $default) :
516 - $tstamp = time();
732 + $ts = time();
517 733 else :
518 - $tstamp = $default;
734 + $ts = $default;
519 735 endif;
520 736 endif;
521 737
522 - if ( ! $unfiltered) :
523 - $tstamp = apply_filters('syndicated_item_published', $tstamp, $this);
738 + if (!$unfiltered) :
739 + $ts = apply_filters('syndicated_item_published', $ts, $this);
524 740 endif;
525 - return $tstamp;
741 + return $ts;
526 742 } /* SyndicatedPost::published() */
527 743
528 - public function updated ($params = array(), $default = -1) {
744 + function updated ($params = array(), $default = -1) {
529 745 $fallback = true; $unfiltered = false;
530 - if ( !is_array($params)) : // Old style
746 + if (!is_array($params)) : // Old style
531 747 $fallback = $params;
532 748 else : // New style
533 749 extract($params);
534 750 endif;
@@ -533,9 +749,9 @@
533 749 extract($params);
534 750 endif;
535 751
536 752 $date = '';
537 - $tstamp = null;
753 + $ts = null;
538 754
539 755 # As far as I know, only dcterms and Atom have reliable ways to
540 756 # specify when something was *modified* last. If neither is
541 757 # available, then we'll try to get the time of publication.
@@ -550,26 +766,26 @@
550 766 endif;
551 767
552 768 if (strlen($date) > 0) :
553 769 $time = new FeedTime($date);
554 - $tstamp = $time->timestamp();
770 + $ts = $time->timestamp();
555 771 elseif ($fallback) : // Fall back to issued / dc:date
556 - $tstamp = $this->published(/*fallback=*/ false, /*default=*/ $default);
772 + $ts = $this->published(/*fallback=*/ false, /*default=*/ $default);
557 773 endif;
558 774
559 775 # If everything failed, then default to the current time.
560 - if (is_null($tstamp)) :
776 + if (is_null($ts)) :
561 777 if (-1 == $default) :
562 - $tstamp = time();
778 + $ts = time();
563 779 else :
564 - $tstamp = $default;
780 + $ts = $default;
565 781 endif;
566 782 endif;
567 783
568 - if ( ! $unfiltered) :
569 - $tstamp = apply_filters('syndicated_item_updated', $tstamp, $this);
784 + if (!$unfiltered) :
785 + apply_filters('syndicated_item_updated', $ts, $this);
570 786 endif;
571 - return $tstamp;
787 + return $ts;
572 788 } /* SyndicatedPost::updated() */
573 789
574 790 var $_hashes = array();
575 791 function stored_hashes ($id = NULL) {
@@ -576,9 +792,9 @@
576 792 if (is_null($id)) :
577 793 $id = $this->wp_id();
578 794 endif;
579 795
580 - if ( !isset($this->_hashes[$id])) :
796 + if (!isset($this->_hashes[$id])) :
581 797 $this->_hashes[$id] = get_post_custom_values(
582 798 'syndication_item_hash', $id
583 799 );
584 800 if (is_null($this->_hashes[$id])) :
@@ -603,27 +819,11 @@
603 819
604 820 return $hash;
605 821 } /* SyndicatedPost::update_hash() */
606 822
607 - /**
608 - * SyndicatedPost::normalize_guid_prefix(): generates a normalized URL
609 - * prefix (including scheme, authority, full path, and the beginning of
610 - * a query string) for creating guids that conform to WordPress's
611 - * internal constraints on the URL space for valid guids. To create a
612 - * normalized guid, just concatenate a valid URL query parameter value
613 - * to the returned URL.
614 - *
615 - * @return string The URL prefix generated.
616 - *
617 - * @uses trailingslashit()
618 - * @uses home_url()
619 - * @uses apply_filters()
620 - */
621 823 static function normalize_guid_prefix () {
622 - $scheme = 'http';
623 - $url = trailingslashit(home_url(/*path=*/ '', $scheme));
624 - return apply_filters('syndicated_item_guid_normalized_prefix', $url . '?guid=', $scheme);
625 - } /* SyndicatedPost::normalize_guid_prefix() */
824 + return trailingslashit(get_bloginfo('url')).'?guid=';
825 + }
626 826
627 827 static function normalize_guid ($guid) {
628 828 $guid = trim($guid);
629 829 if (preg_match('/^[0-9a-z]{32}$/i', $guid)) : // MD5
@@ -631,30 +831,12 @@
631 831 elseif ((strlen(esc_url($guid)) == 0) or (esc_url($guid) != $guid)) :
632 832 $guid = SyndicatedPost::normalize_guid_prefix().md5($guid);
633 833 endif;
634 834 $guid = trim($guid);
635 -
636 835 return $guid;
637 836 } /* SyndicatedPost::normalize_guid() */
638 837
639 - static function alternative_guid_prefix () {
640 - $scheme = 'https';
641 - $url = trailingslashit(home_url(/*path=*/ '', $scheme));
642 - return apply_filters('syndicated_item_guid_normalized_prefix', $url . '?guid=', $scheme);
643 - }
644 - static function alternative_guid ($guid) {
645 - $guid = trim($guid);
646 - if (preg_match('/^[0-9a-z]{32}$/i', $guid)) : // MD5
647 - $guid = SyndicatedPost::alternative_guid_prefix().strtolower($guid);
648 - elseif ((strlen(esc_url($guid)) == 0) or (esc_url($guid) != $guid)) :
649 - $guid = SyndicatedPost::alternative_guid_prefix().md5($guid);
650 - endif;
651 - $guid = trim($guid);
652 -
653 - return $guid;
654 - } /* SyndicatedPost::normalize_guid() */
655 -
656 - public function guid () {
838 + function guid () {
657 839 $guid = null;
658 840 if (isset($this->item['id'])): // Atom 0.3 / 1.0
659 841 $guid = $this->item['id'];
660 842 elseif (isset($this->item['atom']['id'])) : // Namespaced Atom
@@ -684,9 +866,9 @@
684 866 // gets clipped by MySQL, uniqueness tests will fail
685 867 // forever after and the post will be endlessly
686 868 // reduplicated. So, instead, Guids Of A Certain Length
687 869 // are hashed down into a nice, manageable tag: URI.
688 - if ( !is_null($original_guid)) :
870 + if (!is_null($original_guid)) :
689 871 $guid .= ',2010-12-03:id.'.md5($original_guid);
690 872
691 873 // If we have a date of creation, then we can use that
692 874 // to uniquely identify the item. (On the other hand, if
@@ -692,9 +874,9 @@
692 874 // to uniquely identify the item. (On the other hand, if
693 875 // the feed producer was consicentious enough to
694 876 // generate dates of creation, she probably also was
695 877 // conscientious enough to generate unique identifiers.)
696 - elseif ( !is_null($this->created())) :
878 + elseif (!is_null($this->created())) :
697 879 $guid .= '://post.'.date('YmdHis', $this->created());
698 880
699 881 // Otherwise, use both the URI of the item, *and* the
700 882 // item's title. We have to use both because titles are
@@ -705,19 +887,19 @@
705 887 // this is about the best we can do.
706 888 else :
707 889 $link = $this->permalink();
708 890 if (is_null($link)) : $link = $this->link->uri(); endif;
709 - $guid .= '://'.md5($link.'/'.$this->title());
891 + $guid .= '://'.md5($link.'/'.$this->item['title']);
710 892 endif;
711 893 endif;
712 894 return $guid;
713 895 } /* SyndicatedPost::guid() */
714 896
715 - public function author () {
897 + function author () {
716 898 $author = array ();
717 899
718 900 $aa = $this->entry->get_authors();
719 - if (is_countable($aa) and count($aa) > 0) :
901 + if (count($aa) > 0) :
720 902 $a = reset($aa);
721 903
722 904 $author = array(
723 905 'name' => $a->get_name(),
@@ -745,9 +927,9 @@
745 927 // e-mail address, but lots of people don't use
746 928 // it that way. So let's make of it what we can.
747 929 $author = parse_email_with_realname($this->item['author']);
748 930
749 - if ( !isset($author['name'])) :
931 + if (!isset($author['name'])) :
750 932 if (isset($author['email'])) :
751 933 $author['name'] = $author['email'];
752 934 else :
753 935 $author['name'] = $this->feed->channel['title'];
@@ -755,9 +937,9 @@
755 937 endif;
756 938 endif;
757 939 endif;
758 940
759 - if ( !isset($author['name']) or is_null($author['name'])) :
941 + if (!isset($author['name']) or is_null($author['name'])) :
760 942 // Nothing found. Try some crappy defaults.
761 943 if ($this->link->name()) :
762 944 $author['name'] = $this->link->name();
763 945 else :
@@ -789,121 +971,8 @@
789 971 return $author;
790 972 } /* SyndicatedPost::author() */
791 973
792 974 /**
793 - * SyndicatedPost::get_terms_from_settings(): Return an array of terms to associate with the incoming
794 - * post based on the Categories, Tags, and other terms associated with each new post by the user's
795 - * settings (global and feed-specific).
796 - *
797 - * @since 2016.0331
798 - * @return array of lists, each element has the taxonomy for a key ('category', 'post_tag', etc.),
799 - * and a list of term codes (either alphanumeric names, or ID numbers encoded in a format that
800 - * SyndicatedLink::category_ids() can understand) within that taxonomy
801 - *
802 - */
803 - public function get_terms_from_settings () {
804 - // Categories: start with default categories, if any.
805 - $cats = array();
806 - if ('no' != $this->link->setting('add/category', NULL, 'yes')) :
807 - $fc = get_option("feedwordpress_syndication_cats");
808 - if ($fc) :
809 - $cats = array_merge($cats, explode("\n", $fc));
810 - endif;
811 - endif;
812 -
813 - $fc = $this->link->setting('cats',NULL, array());
814 - if (is_array($fc)) :
815 - $cats = array_merge($cats, $fc);
816 - endif;
817 - $preset_terms['category'] = $cats;
818 -
819 - // Tags: start with default tags, if any
820 - $tags = array();
821 - if ('no' != $this->link->setting('add/post_tag', NULL, 'yes')) :
822 - $ft = get_option("feedwordpress_syndication_tags", NULL);
823 - $tags = (is_null($ft) ? array() : explode(FEEDWORDPRESS_CAT_SEPARATOR, $ft));
824 - endif;
825 -
826 - $ft = $this->link->setting('tags', NULL, array());
827 - if (is_array($ft)) :
828 - $tags = array_merge($tags, $ft);
829 - endif;
830 - $preset_terms['post_tag'] = $tags;
831 -
832 - $taxonomies = $this->link->taxonomies();
833 - $feedTerms = $this->link->setting('terms', NULL, array());
834 - $globalTerms = get_option('feedwordpress_syndication_terms', array());
835 - $specials = array('category' => 'cats', 'post_tag' => 'tags');
836 -
837 - foreach ($taxonomies as $tax) :
838 - // category and tag settings have already previously been handled
839 - // but if this is from another taxonomy, then...
840 - if ( !isset($specials[$tax])) :
841 - $terms = array();
842 -
843 - // See if we should get the globals
844 - if ('no' != $this->link->setting("add/$tax", NULL, 'yes')) :
845 - if (isset($globalTerms[$tax])) :
846 - $terms = $globalTerms[$tax];
847 - endif;
848 - endif;
849 -
850 - // Now merge in the locals
851 - if (isset($feedTerms[$tax])) :
852 - $terms = array_merge($terms, $feedTerms[$tax]);
853 - endif;
854 -
855 - // That's all, folks.
856 - $preset_terms[$tax] = $terms;
857 - endif;
858 - endforeach;
859 -
860 - return $preset_terms;
861 - } /* SyndicatedPost::get_terms_from_settings () */
862 -
863 - /**
864 - * SyndicatedPost::get_terms_from_feeds(): Return an array of terms to associate with the incoming
865 - * post based on the contents of the subscribed feed (atom:category and rss:category elements, dc:subject
866 - * elements, tags embedded using microformats in the post content, etc.)
867 - *
868 - * @since 2016.0331
869 - * @return array of lists, each element has the taxonomy for a key ('category', 'post_tag', etc.),
870 - * and a list of alphanumeric term names
871 - */
872 - public function get_terms_from_feeds () {
873 - // Now add categories from the post, if we have 'em
874 - $cats = array();
875 - $post_cats = $this->entry->get_categories();
876 - if (is_array($post_cats)) : foreach ($post_cats as $cat) :
877 - $cat_name = $cat->get_term();
878 - if ( ! $cat_name) : $cat_name = $cat->get_label(); endif;
879 -
880 - if ($this->link->setting('cat_split', NULL, NULL)) :
881 - $pcre = "\007".$this->feedmeta['cat_split']."\007";
882 - $cats = array_merge(
883 - $cats,
884 - preg_split(
885 - $pcre,
886 - $cat_name,
887 - -1 /*=no limit*/,
888 - PREG_SPLIT_NO_EMPTY
889 - )
890 - );
891 - else :
892 - $cats[] = $cat_name;
893 - endif;
894 - endforeach; endif;
895 -
896 - $feed_terms['category'] = apply_filters('syndicated_item_categories', $cats, $this);
897 -
898 - // Scan post for /a[@rel='tag'] and use as tags if present
899 - $tags = $this->inline_tags();
900 - $feed_terms['post_tag'] = apply_filters('syndicated_item_tags', $tags, $this);
901 -
902 - return $feed_terms;
903 - } /* SyndicatedPost::get_terms_from_feeds () */
904 -
905 - /**
906 975 * SyndicatedPost::inline_tags: Return a list of all the tags embedded
907 976 * in post content using the a[@rel="tag"] microformat.
908 977 *
909 978 * @since 2010.0630
@@ -913,9 +982,9 @@
913 982 $tags = array();
914 983 $content = $this->content();
915 984 $pattern = FeedWordPressHTML::tagWithAttributeRegex('a', 'rel', 'tag');
916 985 preg_match_all($pattern, $content, $refs, PREG_SET_ORDER);
917 - if (is_countable($refs) and count($refs) > 0) :
986 + if (count($refs) > 0) :
918 987 foreach ($refs as $ref) :
919 988 $tag = FeedWordPressHTML::tagWithAttributeMatch($ref);
920 989 $tags[] = $tag['content'];
921 990 endforeach;
@@ -985,21 +1054,21 @@
985 1054 * that will be returned to only those with a MIME type which
986 1055 * matches this regular expression.
987 1056 * @return array
988 1057 */
989 - function enclosures( $type = '/.*/' ) {
1058 + function enclosures ($type = '/.*/') {
990 1059 $enclosures = array();
991 1060
992 - if ( isset( $this->item['enclosure#'] ) ) :
1061 + if (isset($this->item['enclosure#'])) :
993 1062 // Loop through enclosure, enclosure#2, enclosure#3, ....
994 - for ( $i = 1; $i <= $this->item['enclosure#']; $i++ ) :
995 - $eid = ( ( $i > 1 ) ? "#{$i}" : "" ); // this was set as #{$id} — was that a typo? (gwyneth 20230919)
1063 + for ($i = 1; $i <= $this->item['enclosure#']; $i++) :
1064 + $eid = (($i > 1) ? "#{$id}" : "");
996 1065
997 1066 // Does it match the type we want?
998 - if ( preg_match($type, $this->item["enclosure{$eid}@type"] ) ) :
1067 + if (preg_match($type, $this->item["enclosure{$eid}@type"])) :
999 1068 $enclosures[] = array(
1000 - "url" => $this->item["enclosure{$eid}@url"],
1001 - "type" => $this->item["enclosure{$eid}@type"],
1069 + "url" => $this->item["enclosure{$eid}@url"],
1070 + "type" => $this->item["enclosure{$eid}@type"],
1002 1071 "length" => $this->item["enclosure{$eid}@length"],
1003 1072 );
1004 1073 endif;
1005 1074 endfor;
@@ -1028,9 +1097,9 @@
1028 1097 $ret['id'] = $id_tags[0]['data'];
1029 1098 endif;
1030 1099 endif;
1031 1100
1032 - if ( !is_null($what) and is_scalar($what)) :
1101 + if (!is_null($what) and is_scalar($what)) :
1033 1102 $ret = $ret[$what];
1034 1103 endif;
1035 1104 return $ret;
1036 1105 }
@@ -1143,9 +1212,8 @@
1143 1212
1144 1213 function resolve_single_relative_uri ($refs) {
1145 1214 $tag = FeedWordPressHTML::attributeMatch($refs);
1146 1215 $url = SimplePie_Misc::absolutize_url($tag['value'], $this->_base);
1147 -
1148 1216 return $tag['prefix'] . $url . $tag['suffix'];
1149 1217 } /* function SyndicatedPost::resolve_single_relative_uri() */
1150 1218
1151 1219 static function resolve_relative_uris ($content, $obj) {
@@ -1164,19 +1232,13 @@
1164 1232
1165 1233 foreach ($obj->uri_attrs as $pair) :
1166 1234 list($tag, $attr) = $pair;
1167 1235 $pattern = FeedWordPressHTML::attributeRegex($tag, $attr);
1168 -
1169 - // FIXME: Encountered issue while testing an extremely long (= 88827 characters) item
1170 - // Relying on preg_replace_callback() here can cause a PHP seg fault on my development
1171 - // server. preg_match_all() causes a similar problem. Apparently this is a PCRE issue
1172 - // Cf. discussion of similar issue <https://bugs.php.net/bug.php?id=65009>
1173 1236 $content = preg_replace_callback (
1174 1237 $pattern,
1175 1238 array($obj, 'resolve_single_relative_uri'),
1176 1239 $content
1177 1240 );
1178 -
1179 1241 endforeach;
1180 1242 endif;
1181 1243
1182 1244 return $content;
@@ -1235,11 +1297,12 @@
1235 1297 * 1 = post already syndicated, but needs to be updated to latest
1236 1298 * 2 = post has not yet been syndicated; needs to be created
1237 1299 */
1238 1300 function freshness ($format = 'number') {
1301 + global $wpdb;
1239 1302
1240 1303 if ($this->filtered()) : // This should never happen.
1241 - FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1304 + FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1242 1305 endif;
1243 1306
1244 1307 if (is_null($this->_freshness)) : // Not yet checked and cached.
1245 1308 $guid = $this->post['guid'];
@@ -1247,17 +1310,15 @@
1247 1310
1248 1311 $q = new WP_Query(array(
1249 1312 'fields' => '_synfresh', // id, guid, post_modified_gmt
1250 1313 'ignore_sticky_posts' => true,
1251 - 'guid' => $eguid, // it's always better to use the escaped version, right? (gwyneth 20230915)
1314 + 'guid' => $guid,
1252 1315 ));
1253 1316
1254 1317 $old_post = NULL;
1255 1318 if ($q->have_posts()) :
1256 1319 while ($q->have_posts()) : $q->the_post();
1257 - if (get_post_type($q->post->ID) == $this->post['post_type']):
1258 - $old_post = $q->post;
1259 - endif;
1320 + $old_post = $q->post;
1260 1321 endwhile;
1261 1322 endif;
1262 1323
1263 1324 if (is_null($old_post)) : // No post with this guid
@@ -1268,23 +1329,23 @@
1268 1329 // Presume there is nothing new until we find
1269 1330 // something new.
1270 1331 $updated = false;
1271 1332 $live = false;
1272 -
1333 +
1273 1334 // Pull the list of existing revisions to get
1274 1335 // timestamps.
1275 1336 $revisions = wp_get_post_revisions($old_post->ID);
1276 1337 foreach ($revisions as $rev) :
1277 - $revisions_ts[] = mysql2date('G', $rev->post_modified_gmt);
1338 + $revisions_ts[] = mysql2date('G', $rev->post_modified_gmt);
1278 1339 endforeach;
1279 1340
1280 1341 $revisions_ts[] = mysql2date('G', $old_post->post_modified_gmt);
1281 1342 $last_rev_ts = end($revisions_ts);
1282 1343 $updated_ts = $this->updated(/*fallback=*/ true, /*default=*/ NULL);
1283 -
1344 +
1284 1345 // If we have an explicit updated timestamp,
1285 1346 // check that against existing stamps.
1286 - if ( !is_null($updated_ts)) :
1347 + if (!is_null($updated_ts)) :
1287 1348 $updated = !in_array($updated_ts, $revisions_ts);
1288 1349
1289 1350 // If this a newer revision, make it go
1290 1351 // live. If an older one, just record
@@ -1292,9 +1353,9 @@
1292 1353 $live = ($updated and ($updated_ts > $last_rev_ts));
1293 1354 endif;
1294 1355
1295 1356 // This is a revision we haven't seen before, judging by the date.
1296 -
1357 +
1297 1358 $updatedReason = NULL;
1298 1359 if ($updated) :
1299 1360 $updatedReason = preg_replace(
1300 1361 "/\s+/", " ",
@@ -1310,15 +1371,15 @@
1310 1371 else :
1311 1372 // Or the hash...
1312 1373 $hash = $this->update_hash();
1313 1374 $seen = $this->stored_hashes($old_post->ID);
1314 - if (is_countable($seen) and count($seen) > 0) :
1375 + if (count($seen) > 0) :
1315 1376 $updated = !in_array($hash, $seen); // Not seen yet?
1316 1377 else :
1317 1378 $updated = true; // Can't find syndication meta-data
1318 1379 endif;
1319 1380
1320 - if ($updated and FeedWordPressDiagnostic::is_on('feed_items:freshness:reasons')) :
1381 + if ($updated and FeedWordPress::diagnostic_on('feed_items:freshness:reasons')) :
1321 1382 // In the absence of definitive
1322 1383 // timestamp information, we
1323 1384 // just have to assume that a
1324 1385 // hash we haven't seen before
@@ -1336,11 +1397,11 @@
1336 1397
1337 1398 $frozen = false;
1338 1399 if ($updated) : // Ignore if the post is frozen
1339 1400 $frozen = ('yes' == $this->link->setting('freeze updates', 'freeze_updates', NULL));
1340 - if ( ! $frozen) :
1341 - $frozen_value = get_post_meta($old_post->ID, '_syndication_freeze_updates', /*single=*/ true);
1342 - $frozen = ( !is_null($frozen_value) and ('yes' == $frozen_value));
1401 + if (!$frozen) :
1402 + $frozen_values = get_post_custom_values('_syndication_freeze_updates', $old_post->ID);
1403 + $frozen = (count($frozen_values) > 0 and 'yes' == $frozen_values[0]);
1343 1404
1344 1405 if ($frozen) :
1345 1406 $updatedReason = ' IS BLOCKED FROM BEING UPDATED BY A UPDATE LOCK ON THIS POST, EVEN THOUGH IT '.$updatedReason;
1346 1407 endif;
@@ -1347,13 +1408,13 @@
1347 1408 else :
1348 1409 $updatedReason = ' IS BLOCKED FROM BEING UPDATED BY A FEEDWORDPRESS UPDATE LOCK, EVEN THOUGH IT '.$updatedReason;
1349 1410 endif;
1350 1411 endif;
1351 - $live = ($live and ! $frozen);
1412 + $live = ($live and !$frozen);
1352 1413
1353 1414 if ($updated) :
1354 1415 FeedWordPress::diagnostic('feed_items:freshness', 'Item ['.$guid.'] "'.$this->entry->get_title().'" is an update of an existing post.');
1355 - if ( !is_null($updatedReason)) :
1416 + if (!is_null($updatedReason)) :
1356 1417 $updatedReason = preg_replace('/\s+/', ' ', $updatedReason);
1357 1418 FeedWordPress::diagnostic('feed_items:freshness:reasons', 'Item ['.$guid.'] "'.$this->entry->get_title().'" '.$updatedReason);
1358 1419 endif;
1359 1420
@@ -1374,9 +1435,9 @@
1374 1435 $this->_wp_id = $old_post->ID;
1375 1436 endif;
1376 1437 endif;
1377 1438 endif;
1378 -
1439 +
1379 1440 switch ($format) :
1380 1441 case 'status' :
1381 1442 switch ($this->_freshness) :
1382 1443 case -1:
@@ -1397,17 +1458,17 @@
1397 1458 case 'number' :
1398 1459 default :
1399 1460 $ret = $this->_freshness;
1400 1461 endswitch;
1401 -
1402 -
1462 +
1463 +
1403 1464 return $ret;
1404 1465 } /* SyndicatedPost::freshness () */
1405 -
1466 +
1406 1467 function has_fresh_content () {
1407 1468 return ( ! $this->filtered() and $this->freshness() != 0 );
1408 1469 } /* SyndicatedPost::has_fresh_content () */
1409 -
1470 +
1410 1471 function this_revision_needs_original_post ($freshness = NULL) {
1411 1472 if (is_null($freshness)) :
1412 1473 $freshness = $this->freshness();
1413 1474 endif;
@@ -1412,9 +1473,9 @@
1412 1473 $freshness = $this->freshness();
1413 1474 endif;
1414 1475 return ( $freshness >= 2 );
1415 1476 }
1416 -
1477 +
1417 1478 function this_revision_is_current ($freshness = NULL) {
1418 1479 if (is_null($freshness)) :
1419 1480 $freshness = $this->freshness();
1420 1481 endif;
@@ -1419,13 +1480,13 @@
1419 1480 $freshness = $this->freshness();
1420 1481 endif;
1421 1482 return ( $freshness >= 1 );
1422 1483 } /* SyndicatedPost::this_revision_is_current () */
1423 -
1484 +
1424 1485 function fresh_content_is_update () {
1425 1486 return ($this->freshness() < 2);
1426 1487 } /* SyndicatedPost::fresh_content_is_update () */
1427 -
1488 +
1428 1489 function fresh_storage_diagnostic () {
1429 1490 $ret = NULL;
1430 1491 switch ($this->freshness()) :
1431 1492 case -1 :
@@ -1436,13 +1497,13 @@
1436 1497 break;
1437 1498 case 2 :
1438 1499 default :
1439 1500 $ret = 'Inserting new post "'.$this->post['post_title'].'"';
1440 - break;
1501 + break;
1441 1502 endswitch;
1442 1503 return $ret;
1443 1504 } /* SyndicatedPost::fresh_storage_diagnostic() */
1444 -
1505 +
1445 1506 function fresh_storage_hook () {
1446 1507 $ret = NULL;
1447 1508 switch ($this->freshness()) :
1448 1509 case -1 :
@@ -1455,9 +1516,9 @@
1455 1516 break;
1456 1517 endswitch;
1457 1518 return $ret;
1458 1519 } /* SyndicatedPost::fresh_storage_hook () */
1459 -
1520 +
1460 1521 #################################################
1461 1522 #### INTERNAL STORAGE AND MANAGEMENT METHODS ####
1462 1523 #################################################
1463 1524
@@ -1462,9 +1523,9 @@
1462 1523 #################################################
1463 1524
1464 1525 function wp_id () {
1465 1526 if ($this->filtered()) : // This should never happen.
1466 - FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1527 + FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1467 1528 endif;
1468 1529
1469 1530 if (is_null($this->_wp_id) and is_null($this->_freshness)) :
1470 1531 $fresh = $this->freshness(); // sets WP DB id in the process
@@ -1471,165 +1532,105 @@
1471 1532 endif;
1472 1533 return $this->_wp_id;
1473 1534 }
1474 1535
1475 - /**
1476 - * SyndicatedPost::secure_author_id(). Look up, or create, a numeric ID
1477 - * for the author of the incoming post.
1478 - *
1479 - * side effect: int|NULL stored in $this->post['post_author']
1480 - * side effect: IF no valid author is found, NULL stored in $this->post
1481 - * side effect: diagnostic output in case item is rejected with NULL author
1482 - *
1483 - * @used-by SyndicatedPost::store
1484 - *
1485 - * @uses SyndicatedPost::post
1486 - * @uses SyndicatedPost::author_id
1487 - * @uses SyndicatedLink::setting
1488 - * @uses FeedWordPress::diagnostic
1489 - */
1490 - protected function secure_author_id () {
1491 - # -- Look up, or create, numeric ID for author
1492 - $this->post['post_author'] = $this->author_id (
1493 - $this->link->setting('unfamiliar author', 'unfamiliar_author', 'create')
1494 - );
1536 + function store () {
1537 + global $wpdb;
1495 1538
1496 - if (is_null($this->post['post_author'])) :
1497 - FeedWordPress::diagnostic('feed_items:rejected', 'Filtered out item ['.$this->guid().'] without syndication: no author available');
1498 - $this->post = NULL;
1539 + if ($this->filtered()) : // This should never happen.
1540 + FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1499 1541 endif;
1500 - } /* SyndicatedPost::secure_author_id() */
1501 1542
1502 - /**
1503 - * SyndicatedPost::secure_term_ids(). Look up, or create, numeric IDs
1504 - * for the terms (categories, tags, etc.) assigned to the incoming post,
1505 - * whether by global settings, feed settings, or by the tags on the feed.
1506 - *
1507 - * side effect: array of term ids stored in $this->post['tax_input']
1508 - * side effect: IF settings or filters determine post should be filtered out,
1509 - * NULL stored in $this->post
1510 - *
1511 - * @used-by SyndicatedPost::store
1512 - *
1513 - * @uses apply_filters
1514 - * @uses SyndicatedLink::setting
1515 - * @uses SyndicatedPost::category_ids
1516 - * @uses SyndicatedPost::preset_terms
1517 - * @uses SyndicatedPost::post
1518 - */
1519 - protected function secure_term_ids () {
1520 - $mapping = apply_filters('syndicated_post_terms_mapping', array(
1521 - 'category' => array('abbr' => 'cats', 'unfamiliar' => 'category', 'domain' => array('category', 'post_tag')),
1522 - 'post_tag' => array('abbr' => 'tags', 'unfamiliar' => 'post_tag', 'domain' => array('post_tag')),
1523 - ), $this);
1543 + $freshness = $this->freshness();
1544 + if ($this->has_fresh_content()) :
1545 + # -- Look up, or create, numeric ID for author
1546 + $this->post['post_author'] = $this->author_id (
1547 + $this->link->setting('unfamiliar author', 'unfamiliar_author', 'create')
1548 + );
1524 1549
1525 - $termSet = array(); $valid = null;
1526 - foreach ($this->feed_terms as $what => $anTerms) :
1527 - // Default to using the inclusive procedures (for cats) rather than exclusive (for inline tags)
1528 - $taxes = (isset($mapping[$what]) ? $mapping[$what] : $mapping['category']);
1529 - $unfamiliar = $taxes['unfamiliar'];
1550 + if (is_null($this->post['post_author'])) :
1551 + FeedWordPress::diagnostic('feed_items:rejected', 'Filtered out item ['.$this->guid().'] without syndication: no author available');
1552 + $this->post = NULL;
1553 + endif;
1554 + endif;
1530 1555
1531 - if ( !is_null($this->post)) : // Not filtered out yet
1532 - # -- Look up, or create, numeric ID for categories
1533 - $taxonomies = $this->link->setting("match/".$taxes['abbr'], 'match_'.$taxes['abbr'], $taxes['domain']);
1556 + // We have to check again in case post has been filtered during
1557 + // the author_id lookup
1558 + if ($this->has_fresh_content()) :
1559 + $consider = array(
1560 + 'category' => array('abbr' => 'cats', 'domain' => array('category', 'post_tag')),
1561 + 'post_tag' => array('abbr' => 'tags', 'domain' => array('post_tag')),
1562 + );
1534 1563
1535 - // Eliminate dummy variables
1536 - $taxonomies = array_filter( $taxonomies, 'remove_dummy_zero' );
1564 + $termSet = array(); $valid = null;
1565 + foreach ($consider as $what => $taxes) :
1566 + if (!is_null($this->post)) : // Not filtered out yet
1567 + # -- Look up, or create, numeric ID for categories
1568 + $taxonomies = $this->link->setting("match/".$taxes['abbr'], 'match_'.$taxes['abbr'], $taxes['domain']);
1537 1569
1538 - // Allow FWP add-on filters to control the taxonomies we use to search for a term
1539 - $taxonomies = apply_filters("syndicated_post_terms_match", $taxonomies, $what, $this);
1540 - $taxonomies = apply_filters("syndicated_post_terms_match_{$what}", $taxonomies, $this);
1570 + // Eliminate dummy variables
1571 + $taxonomies = array_filter($taxonomies, 'remove_dummy_zero');
1541 1572
1542 - // Allow FWP add-on filters to control with greater precision what happens on unmatched
1543 - $unmatched = apply_filters("syndicated_post_terms_unfamiliar",
1544 - $this->link->setting(
1545 - "unfamiliar {$unfamiliar}",
1546 - "unfamiliar_{$unfamiliar}",
1547 - 'create:'.$unfamiliar
1548 - ),
1549 - $what,
1550 - $this
1551 - );
1573 + $terms = $this->category_ids (
1574 + $this->feed_terms[$what],
1575 + $this->link->setting("unfamiliar {$what}", "unfamiliar_{$what}", 'create:'.$what),
1576 + /*taxonomies=*/ $taxonomies,
1577 + array(
1578 + 'singleton' => false, // I don't like surprises
1579 + 'filters' => true,
1580 + )
1581 + );
1552 1582
1553 - $terms = $this->category_ids (
1554 - $anTerms,
1555 - $unmatched,
1556 - /*taxonomies=*/ $taxonomies,
1557 - array(
1558 - 'singleton' => false, // I don't like surprises
1559 - 'filters' => true,
1560 - )
1561 - );
1583 + if (is_null($terms) or is_null($termSet)) :
1584 + // filtered out -- no matches
1585 + else :
1586 + $valid = true;
1562 1587
1563 - if (is_null($terms) or is_null($termSet)) :
1564 - // filtered out -- no matches
1565 - else :
1566 - $valid = true;
1567 -
1568 - // filter mode off, or at least one match
1569 - foreach ($terms as $tax => $term_ids) :
1570 - if ( !isset($termSet[$tax])) :
1571 - $termSet[$tax] = array();
1572 - endif;
1573 - $termSet[$tax] = array_merge($termSet[$tax], $term_ids);
1574 - endforeach;
1588 + // filter mode off, or at least one match
1589 + foreach ($terms as $tax => $term_ids) :
1590 + if (!isset($termSet[$tax])) :
1591 + $termSet[$tax] = array();
1592 + endif;
1593 + $termSet[$tax] = array_merge($termSet[$tax], $term_ids);
1594 + endforeach;
1595 + endif;
1575 1596 endif;
1576 - endif;
1577 - endforeach;
1578 -
1579 - if (is_null($valid)) : // Plonked
1580 - $this->post = NULL;
1581 - else : // We can proceed
1582 - $this->post['tax_input'] = array();
1583 - foreach ($termSet as $tax => $term_ids) :
1584 - if ( !isset($this->post['tax_input'][$tax])) :
1585 - $this->post['tax_input'][$tax] = array();
1586 - endif;
1587 - $this->post['tax_input'][$tax] = array_merge(
1588 - $this->post['tax_input'][$tax],
1589 - $term_ids
1590 - );
1591 1597 endforeach;
1592 1598
1593 - // Now let's add on the feed and global presets
1594 - foreach ($this->preset_terms as $tax => $term_ids) :
1595 - if ( !isset($this->post['tax_input'][$tax])) :
1596 - $this->post['tax_input'][$tax] = array();
1597 - endif;
1599 + if (is_null($valid)) : // Plonked
1600 + $this->post = NULL;
1601 + else : // We can proceed
1602 + $this->post['tax_input'] = array();
1603 + foreach ($termSet as $tax => $term_ids) :
1604 + if (!isset($this->post['tax_input'][$tax])) :
1605 + $this->post['tax_input'][$tax] = array();
1606 + endif;
1607 + $this->post['tax_input'][$tax] = array_merge(
1608 + $this->post['tax_input'][$tax],
1609 + $term_ids
1610 + );
1611 + endforeach;
1598 1612
1599 - $this->post['tax_input'][$tax] = array_merge (
1600 - $this->post['tax_input'][$tax],
1601 - $this->category_ids (
1602 - /*terms=*/ $term_ids,
1603 - /*unfamiliar=*/ 'create:'.$tax, // These are presets; for those added in a tagbox editor, the tag may not yet exist
1604 - /*taxonomies=*/ array($tax),
1605 - array(
1606 - 'singleton' => true,
1607 - ))
1608 - );
1609 - endforeach;
1610 - endif;
1611 - } /* SyndicatedPost::secure_term_ids() */
1613 + // Now let's add on the feed and global presets
1614 + foreach ($this->preset_terms as $tax => $term_ids) :
1615 + if (!isset($this->post['tax_input'][$tax])) :
1616 + $this->post['tax_input'][$tax] = array();
1617 + endif;
1612 1618
1613 - /**
1614 - * SyndicatedPost::store
1615 - *
1616 - * @uses SyndicatedPost::secure_author_id
1617 - */
1618 - public function store () {
1619 - if ($this->filtered()) : // This should never happen.
1620 - FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1619 + $this->post['tax_input'][$tax] = array_merge (
1620 + $this->post['tax_input'][$tax],
1621 + $this->category_ids (
1622 + /*terms=*/ $term_ids,
1623 + /*unfamiliar=*/ 'create:'.$tax, // These are presets; for those added in a tagbox editor, the tag may not yet exist
1624 + /*taxonomies=*/ array($tax),
1625 + array(
1626 + 'singleton' => true,
1627 + ))
1628 + );
1629 + endforeach;
1630 + endif;
1621 1631 endif;
1622 1632
1623 - $freshness = $this->freshness(); // see above: this sets WP DB id in the process (gwyneth 20230919)
1624 - if ($this->has_fresh_content()) :
1625 - $this->secure_author_id();
1626 - endif;
1627 -
1628 - if ($this->has_fresh_content()) : // Was this filtered during author_id lookup?
1629 - $this->secure_term_ids();
1630 - endif;
1631 -
1632 1633 // We have to check again in case the post has been filtered
1633 1634 // during the category/tags/taxonomy terms lookup
1634 1635 if ($this->has_fresh_content()) :
1635 1636 // Filter some individual fields
@@ -1640,9 +1641,9 @@
1640 1641 $post_name = (is_null($this->_wp_post) ? NULL : $this->_wp_post->post_name);
1641 1642
1642 1643 // Allow filters to set post slug. Props niska.
1643 1644 $post_name = apply_filters('syndicated_post_slug', $post_name, $this);
1644 - if ( !empty($post_name)) :
1645 + if (!empty($post_name)) :
1645 1646 $this->post['post_name'] = $post_name;
1646 1647 endif;
1647 1648
1648 1649 $this->post = apply_filters('syndicated_post', $this->post, $this);
@@ -1661,29 +1662,29 @@
1661 1662 /*callback=*/ array($this, 'add_rss_meta'),
1662 1663 /*priority=*/ -10000, /* very early */
1663 1664 /*arguments=*/ 3
1664 1665 );
1665 -
1666 +
1666 1667 $ret = false;
1667 1668 if ($this->has_fresh_content()) :
1668 1669 $diag = $this->fresh_storage_diagnostic();
1669 - if ( !is_null($diag)) :
1670 + if (!is_null($diag)) :
1670 1671 FeedWordPress::diagnostic('syndicated_posts', $diag);
1671 1672 endif;
1672 -
1673 +
1673 1674 $this->insert_post(/*update=*/ $this->fresh_content_is_update(), $this->freshness());
1674 1675
1675 1676 $hook = $this->fresh_storage_hook();
1676 - if ( !is_null($hook)) :
1677 + if (!is_null($hook)) :
1677 1678 do_action($hook, $this->wp_id(), $this);
1678 1679 endif;
1679 -
1680 +
1680 1681 $ret = $this->freshness('status');
1681 1682 endif;
1682 1683
1683 1684 // If this is a legit, non-filtered post, tag it as found on the
1684 1685 // feed regardless of fresh or stale status
1685 - if ( ! $this->filtered()) :
1686 + if (!$this->filtered()) :
1686 1687 $key = '_feedwordpress_retire_me_' . $this->link->id;
1687 1688 delete_post_meta($this->wp_id(), $key);
1688 1689
1689 1690 $status = get_post_field('post_status', $this->wp_id());
@@ -1709,13 +1710,13 @@
1709 1710 return $ret;
1710 1711 } /* function SyndicatedPost::store () */
1711 1712
1712 1713 function insert_post ($update = false, $freshness = 2) {
1714 + global $wpdb;
1715 +
1713 1716 $dbpost = $this->normalize_post(/*new=*/ true);
1714 1717
1715 - $ret = null;
1716 -
1717 - if ( !is_null($dbpost)) :
1718 + if (!is_null($dbpost)) :
1718 1719 $dbpost['post_pingback'] = false; // Tell WP 2.1 and 2.2 not to process for pingbacks
1719 1720
1720 1721 // This is a ridiculous fucking kludge necessitated by WordPress 2.6 munging authorship meta-data
1721 1722 add_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
@@ -1769,45 +1770,38 @@
1769 1770 // the basic post record before we do anything else.
1770 1771 if ($this->this_revision_needs_original_post()) :
1771 1772 // *sigh*, for handling inconsistent slash expectations < 3.6
1772 1773 $sdbpost = $this->db_sanitize_post($dbpost);
1773 -
1774 +
1774 1775 // Go ahead and insert the first post record to
1775 1776 // anchor the revision history.
1776 -
1777 1777 $this->_wp_id = wp_insert_post($sdbpost, /*return wp_error=*/ true);
1778 -
1778 +
1779 1779 $dbpost['ID'] = $this->_wp_id;
1780 1780 endif;
1781 +
1782 + // Now that we've made sure the original exists, insert
1783 + // this version here as a revision.
1784 + $revision_id = _wp_put_post_revision($dbpost, /*autosave=*/ false);
1781 1785
1782 - // Sanity check: if the attempt to insert post
1783 - // returned an error, then feeding that error
1784 - // object in to _wp_put_post_revision() would
1785 - // cause a fatal error. Better to break out.
1786 - if ( !is_wp_error($this->_wp_id)) :
1787 - // Now that we've made sure the original exists, insert
1788 - // this version here as a revision.
1789 - $revision_id = _wp_put_post_revision($dbpost, /*autosave=*/ false);
1786 + if (!$this->this_revision_needs_original_post()) :
1787 +
1788 + if ($this->this_revision_is_current()) :
1790 1789
1791 - if ( ! $this->this_revision_needs_original_post()) :
1790 + wp_restore_post_revision($revision_id);
1792 1791
1793 - if ($this->this_revision_is_current()) :
1792 + else :
1794 1793
1795 - wp_restore_post_revision($revision_id);
1796 -
1797 - else :
1798 -
1799 - // If we do not activate this revision, then the
1800 - // add_rss_meta will not be called, which is
1801 - // more or less as it should be, but that means
1802 - // we have to actively record this revision's
1803 - // update hash from here.
1804 - $postId = $this->post['ID'];
1805 - $key = 'syndication_item_hash';
1806 - $hash = $this->update_hash();
1807 - FeedWordPress::diagnostic('syndicated_posts:meta_data', "Adding post meta-datum to post [$postId]: [$key] = ".FeedWordPress::val($hash, /*no newlines=*/ true));
1808 - add_post_meta( $postId, $key, $hash, /*unique=*/ false );
1809 - endif;
1794 + // If we do not activate this revision, then the
1795 + // add_rss_meta will not be called, which is
1796 + // more or less as it should be, but that means
1797 + // we have to actively record this revision's
1798 + // update hash from here.
1799 + $postId = $this->post['ID'];
1800 + $key = 'syndication_item_hash';
1801 + $hash = $this->update_hash();
1802 + FeedWordPress::diagnostic('syndicated_posts:meta_data', "Adding post meta-datum to post [$postId]: [$key] = ".FeedWordPress::val($hash, /*no newlines=*/ true));
1803 + add_post_meta( $postId, $key, $hash, /*unique=*/ false );
1810 1804 endif;
1811 1805 endif;
1812 1806
1813 1807 remove_action(
@@ -1830,30 +1824,15 @@
1830 1824 add_filter('content_save_pre', $filter);
1831 1825 endforeach;
1832 1826
1833 1827 $this->validate_post_id($dbpost, $update, array(__CLASS__, __FUNCTION__));
1834 -
1835 - $ret = $this->_wp_id;
1836 1828 endif;
1837 - return $ret;
1838 1829 } /* function SyndicatedPost::insert_post () */
1839 1830
1840 - /**
1841 - * SyndicatedPost::insert_new(). Uses the data collected in this post object to insert
1842 - * a new post into the wp_posts table.
1843 - *
1844 - * @uses SyndicatedPost::insert_post
1845 - */
1846 1831 function insert_new () {
1847 1832 $this->insert_post(/*update=*/ false, 1);
1848 1833 } /* SyndicatedPost::insert_new() */
1849 1834
1850 - /**
1851 - * SyndicatedPost::insert_new(). Uses the data collected in this post object to update
1852 - * an existing post in the wp_posts table.
1853 - *
1854 - * @uses SyndicatedPost::insert_post
1855 - */
1856 1835 function update_existing () {
1857 1836 $this->insert_post(/*update=*/ true, 2);
1858 1837 } /* SyndicatedPost::update_existing() */
1859 1838
@@ -1859,12 +1838,14 @@
1859 1838
1860 1839 /**
1861 1840 * SyndicatedPost::normalize_post()
1862 1841 *
1863 - * @param bool $new If true, this post is to be inserted anew. If false, it is an update of an existing post. (Unused)
1842 + * @param bool $new If true, this post is to be inserted anew. If false, it is an update of an existing post.
1864 1843 * @return array A normalized representation of the post ready to be inserted into the database or sent to the WordPress API functions
1865 1844 */
1866 - function normalize_post( $new = true ) {
1845 + function normalize_post ($new = true) {
1846 + global $wpdb;
1847 +
1867 1848 $out = $this->post;
1868 1849
1869 1850 $fullPost = $out['post_title'].$out['post_content'];
1870 1851 $fullPost .= (isset($out['post_excerpt']) ? $out['post_excerpt'] : '');
@@ -1890,50 +1871,15 @@
1890 1871
1891 1872 return $out;
1892 1873 }
1893 1874
1894 - public function db_sanitize_post_check_encoding ($out) {
1895 - // Check encoding recursively: every string field needs to be checked
1896 - // for character encoding issues. This is a bit problematic because we
1897 - // *should* be using DB_CHARSET, but DB_CHARSET sometimes has values
1898 - // that work for MySQL but not for PHP mb_check_encoding. So instead
1899 - // we must rely on WordPress setting blog_charset and hope that the user
1900 - // has got their database encoding set up to roughly match
1901 - $charset = get_option('blog_charset', 'utf8');
1902 -
1903 - foreach ($out as $key => $value) :
1904 - if (is_string($value)) :
1905 -
1906 - if ( !function_exists('mb_check_encoding') or mb_check_encoding($value, $charset)) :
1907 - $out[$key] = $value;
1908 - else :
1909 - $fromCharset = mb_detect_encoding($value, mb_detect_order(), /*strict=*/ true);
1910 - $out[$key] = mb_convert_encoding($value, $charset, $fromCharset);
1911 - endif;
1912 -
1913 - elseif (is_array($value)) :
1914 - $out[$key] = $this->db_sanitize_post_check_encoding($value);
1915 -
1916 - else :
1917 - $out[$key] = $value;
1918 - endif;
1919 -
1920 - endforeach;
1921 -
1922 - return $out;
1923 - } /* SyndicatedPost::db_sanitize_post_check_encoding () */
1924 -
1925 1875 function db_sanitize_post ($out) {
1926 - global $wp_db_version;
1927 -
1928 - $out = $this->db_sanitize_post_check_encoding($out);
1929 -
1930 - // < 3.6. Core API, including `wp_insert_post()`, expects
1931 - // properly slashed data. If `wp_slash()` exists, then
1932 - // this is after the big change-over in how data slashing
1933 - // was handled.
1934 - if ( !function_exists('wp_slash')) :
1935 -
1876 + // < 3.6. Core API, including wp_insert_post(), will expect
1877 + // properly slashed data. If wp_slash() exists, then this is
1878 + // after the big change-over, and wp_insert_post() etc. will
1879 + // expect *un*-slashed data.
1880 + if (!function_exists('wp_slash')) :
1881 +
1936 1882 foreach ($out as $key => $value) :
1937 1883 if (is_string($value)) :
1938 1884 $out[$key] = esc_sql($value);
1939 1885 else :
@@ -1940,27 +1886,13 @@
1940 1886 $out[$key] = $value;
1941 1887 endif;
1942 1888 endforeach;
1943 1889
1944 - // For revisions [@23416,@23554), core API expects
1945 - // unslashed data. Cf. <https://core.trac.wordpress.org/browser/trunk/wp-includes/post.php?rev=23416>
1946 - // NOOP for those revisions.
1947 -
1948 - // In revisions @23554 to present, `wp_insert_post()`
1949 - // expects slashed data once again.
1950 - // Cf. <https://core.trac.wordpress.org/changeset/23554/trunk/wp-includes/post.php?contextall=1>
1951 - // But at least now we can use the wp_slash API function to do that.
1952 - // Hooray.
1953 -
1954 - elseif ($wp_db_version >= 23524) :
1955 -
1956 - $out = wp_slash($out);
1957 -
1958 1890 endif;
1959 1891
1960 1892 return $out;
1961 1893 }
1962 -
1894 +
1963 1895 /**
1964 1896 * SyndicatedPost::validate_post_id()
1965 1897 *
1966 1898 * @param array $dbpost An array representing the post we attempted to insert or update
@@ -1970,9 +1902,9 @@
1970 1902 if (is_array($ns)) : $ns = implode('::', $ns);
1971 1903 else : $ns = (string) $ns; endif;
1972 1904
1973 1905 // This should never happen.
1974 - if ( !is_numeric($this->_wp_id) or ($this->_wp_id == 0)) :
1906 + if (!is_numeric($this->_wp_id) or ($this->_wp_id == 0)) :
1975 1907 $verb = ($is_update ? 'update existing' : 'insert new');
1976 1908 $guid = $this->guid();
1977 1909 $url = $this->permalink();
1978 1910 $feed = $this->link->uri(array('add_params' => true));
@@ -1981,9 +1913,9 @@
1981 1913 // notice if we are in debug mode.
1982 1914 $mesg = "Failed to $verb item [$guid]. WordPress API returned no valid post ID.\n"
1983 1915 ."\t\tID = ".serialize($this->_wp_id)."\n"
1984 1916 ."\t\tURL = ".MyPHP::val($url)
1985 - ."\t\tFeed = ".MyPHP::val($feed);
1917 + ."\t\tFeed = ".MyPHP::val($feed);
1986 1918
1987 1919 FeedWordPress::diagnostic('updated_feeds:errors', "WordPress API error: $mesg");
1988 1920 FeedWordPress::diagnostic('feed_items:rejected', $mesg);
1989 1921
@@ -1994,9 +1926,9 @@
1994 1926 from the feed at $feed
1995 1927
1996 1928 $ns::_wp_id
1997 1929 EOM;
1998 - FeedWordPressDiagnostic::noncritical_bug(
1930 + FeedWordPress::noncritical_bug(
1999 1931 /*message=*/ $mesg,
2000 1932 /*var =*/ array(
2001 1933 "\$this->_wp_id" => $this->_wp_id,
2002 1934 "\$dbpost" => $dbpost,
@@ -2022,22 +1954,24 @@
2022 1954 * by _wp_put_post_revision.
2023 1955 *
2024 1956 * @param int $revision_id The revision ID to fix up meta-data
2025 1957 */
2026 - function fix_revision_meta( $revision_id ) {
2027 - $post_author = (int) $this->post['post_author']; // is this a global? And if it is, where is it defined? (gwyneth 20230919)
1958 + function fix_revision_meta ($revision_id) {
1959 + global $wpdb;
2028 1960
1961 + $post_author = (int) $this->post['post_author'];
1962 +
2029 1963 $revision_id = (int) $revision_id;
2030 -
1964 +
2031 1965 // Let's fix the author.
2032 - set_post_field( 'post_author', $this->post['post_author'], $revision_id );
2033 -
1966 + set_post_field('post_author', $this->post['post_author'], $revision_id);
1967 +
2034 1968 // Let's fix the GUID to a dummy URL with the update hash.
2035 - set_post_field( 'guid', 'http://feedwordpress.radgeek.com/?rev=' . $this->update_hash(), $revision_id );
1969 + set_post_field('guid', 'http://feedwordpress.radgeek.com/?rev='.$this->update_hash(), $revision_id);
2036 1970
2037 1971 // Let's fire an event for add-ons and filters
2038 - do_action( 'syndicated_post_fix_revision_meta', $revision_id, $this );
2039 -
1972 + do_action('syndicated_post_fix_revision_meta', $revision_id, $this);
1973 +
2040 1974 } /* SyndicatedPost::fix_revision_meta () */
2041 1975
2042 1976 /**
2043 1977 * SyndicatedPost::add_terms() -- if FeedWordPress is processing an
@@ -2125,9 +2059,9 @@
2125 2059 * @param string $new_status Unused action parameter.
2126 2060 * @param string $old_status Unused action parameter.
2127 2061 * @param object $post The database record for the post just inserted.
2128 2062 */
2129 - function add_rss_meta($new_status, $old_status, $post) {
2063 + function add_rss_meta ($new_status, $old_status, $post) {
2130 2064 global $wpdb;
2131 2065 if ($new_status!='inherit') : // Bail if we are creating a revision.
2132 2066 FeedWordPress::diagnostic('syndicated_posts:meta_data', 'Adding post meta-data: {'.implode(", ", array_keys($this->post['meta'])).'}');
2133 2067
@@ -2153,19 +2087,14 @@
2153 2087 WHERE post_id='$postId' AND meta_key='$eKey'
2154 2088 ");
2155 2089
2156 2090 // Allow for either a single value or an array
2157 - if ( !is_array($values)) $values = array($values);
2091 + if (!is_array($values)) $values = array($values);
2158 2092 foreach ( $values as $value ) :
2159 2093 FeedWordPress::diagnostic('syndicated_posts:meta_data', "Adding post meta-datum to post [$postId]: [$key] = ".MyPHP::val($value, /*no newlines=*/ true));
2160 2094 add_post_meta($postId, $key, $value, /*unique=*/ false);
2161 2095 endforeach;
2162 2096 endforeach;
2163 -
2164 - if ( $result === false)
2165 - {
2166 - error_log( "delete query failed: " . $wpdb->last_error );
2167 - }
2168 2097 endif;
2169 2098 endif;
2170 2099 } /* SyndicatedPost::add_rss_meta () */
2171 2100
@@ -2194,9 +2123,9 @@
2194 2123 // as last resort
2195 2124
2196 2125 $candidates = array();
2197 2126 $candidates[] = $a['name'];
2198 - if ( !is_null($source)) : $candidates[] = $source['title']; endif;
2127 + if (!is_null($source)) : $candidates[] = $source['title']; endif;
2199 2128 $candidates[] = $this->link->name(/*fromFeed=*/ true);
2200 2129 $candidates[] = $this->link->name(/*fromFeed=*/ false);
2201 2130 if (strlen($this->link->homepage()) > 0) : $candidates[] = feedwordpress_display_url($this->link->homepage()); endif;
2202 2131 $candidates[] = feedwordpress_display_url($this->link->uri());
@@ -2205,16 +2134,15 @@
2205 2134 // Pick the first one that works from the list, screening against empty
2206 2135 // or forbidden names.
2207 2136
2208 2137 $author = NULL;
2209 - foreach ($candidates as $candidate) {
2210 - if ( !is_null($candidate)
2211 - and (strlen(trim($candidate)) > 0)
2212 - and !in_array(strtolower(trim($candidate)), $forbidden)) :
2213 - $author = $candidate;
2214 - break;
2138 + while (is_null($author) and ($candidate = each($candidates))) :
2139 + if (!is_null($candidate['value'])
2140 + and (strlen(trim($candidate['value'])) > 0)
2141 + and !in_array(strtolower(trim($candidate['value'])), $forbidden)) :
2142 + $author = $candidate['value'];
2215 2143 endif;
2216 - }
2144 + endwhile;
2217 2145
2218 2146 $email = (isset($a['email']) ? $a['email'] : NULL);
2219 2147 $authorUrl = (isset($a['uri']) ? $a['uri'] : NULL);
2220 2148
@@ -2257,9 +2185,9 @@
2257 2185
2258 2186 $nice_author = sanitize_title($author);
2259 2187 $nice_author = apply_filters('pre_user_nicename', $nice_author);
2260 2188
2261 - $reg_author = esc_sql(preg_quote($author ?: "(unknown)"));
2189 + $reg_author = esc_sql(preg_quote($author));
2262 2190 $author = esc_sql($author);
2263 2191 $email = esc_sql($email);
2264 2192 $test_email = esc_sql($test_email);
2265 2193 $authorUrl = esc_sql($authorUrl);
@@ -2273,11 +2201,9 @@
2273 2201 $author_rule = NULL;
2274 2202 endif;
2275 2203
2276 2204 // User name is mapped to a particular author. If that author ID exists, use it.
2277 - // Note: get_userdata() is a pluggable function, so it might not be available yet;
2278 - // check if it exists before using it, or WP will throw a fatal error. (gwyneth 20220223)
2279 - if (is_numeric($author_rule) and function_exists('get_userdata') and get_userdata((int) $author_rule)) :
2205 + if (is_numeric($author_rule) and get_userdata((int) $author_rule)) :
2280 2206 $id = (int) $author_rule;
2281 2207
2282 2208 // User name is filtered out
2283 2209 elseif ('filter' == $author_rule) :
@@ -2318,11 +2244,11 @@
2318 2244 if (is_null($id)) :
2319 2245 if ($unfamiliar_author === 'create') :
2320 2246 $userdata = array();
2321 2247
2322 - #-- we need *something* for the email here or WordPress
2323 - #-- is liable to pitch a fit. So, make something up if
2324 - #-- necessary. (Ugh.)
2248 + // WordPress 3 is going to pitch a fit if we attempt to register
2249 + // more than one user account with an empty e-mail address, so we
2250 + // need *something* here. Ugh.
2325 2251 if (strlen($email) == 0 or FeedWordPress::is_null_email($email)) :
2326 2252 $url = parse_url($hostUrl);
2327 2253 $email = $nice_author.'@'.$url['host'];
2328 2254 endif;
@@ -2334,20 +2260,15 @@
2334 2260 $userdata['user_pass'] = substr(md5(uniqid(microtime())), 0, 6); // just something random to lock it up
2335 2261 $userdata['user_email'] = $email;
2336 2262 $userdata['user_url'] = $authorUrl;
2337 2263 $userdata['nickname'] = $author;
2338 -
2339 2264 $parts = preg_split('/\s+/', trim($author), 2);
2340 2265 if (isset($parts[0])) : $userdata['first_name'] = $parts[0]; endif;
2341 2266 if (isset($parts[1])) : $userdata['last_name'] = $parts[1]; endif;
2342 -
2343 2267 $userdata['display_name'] = $author;
2344 2268 $userdata['role'] = 'contributor';
2345 2269
2346 - #-- loop. Keep trying to add the user until you get it
2347 - #-- right. Or until PHP crashes, I guess.
2348 - $insanity = 0;
2349 - do {
2270 + do { // Keep trying until you get it right. Or until PHP crashes, I guess.
2350 2271 $id = wp_insert_user($userdata);
2351 2272 if (is_wp_error($id)) :
2352 2273 $codes = $id->get_error_code();
2353 2274 switch ($codes) :
@@ -2352,23 +2273,13 @@
2352 2273 $codes = $id->get_error_code();
2353 2274 switch ($codes) :
2354 2275 case 'empty_user_login' :
2355 2276 case 'existing_user_login' :
2356 - case 'invalid_username' :
2357 2277 // Add a random disambiguator
2358 2278 $userdata['user_login'] .= substr(md5(uniqid(microtime())), 0, 6);
2359 2279 break;
2360 - case 'user_login_too_long' :
2361 - // Limit length to 53 characters; if we end up needing a random disambiguator,
2362 - // we should still have space to add it.
2363 - $userdata['user_login'] = mb_substr( $userdata['user_login'], 0, 53 );
2364 - break;
2365 - case 'user_nicename_too_long' :
2366 - // Add a limited 50 characters user_nicename based on user_login
2367 - $userdata['user_nicename'] = mb_substr( $userdata['user_login'], 0, 50 );
2368 - break;
2369 2280 case 'existing_user_email' :
2370 - // Disassemble email for username, host
2281 + // No disassemble!
2371 2282 $parts = explode('@', $userdata['user_email'], 2);
2372 2283
2373 2284 // Add a random disambiguator as a gmail-style username extension
2374 2285 $parts[0] .= '+'.substr(md5(uniqid(microtime())), 0, 6);
@@ -2375,39 +2286,14 @@
2375 2286
2376 2287 // Reassemble
2377 2288 $userdata['user_email'] = $parts[0].'@'.$parts[1];
2378 2289 break;
2379 - default :
2380 - if ( $insanity > 10 ) :
2381 - // Try some settings that are unlikely to cause complaint...
2382 - $url = parse_url($hostUrl);
2383 -
2384 - $userdata['user_login'] = substr(md5(uniqid(microtime())), 0, 6);
2385 - $userdata['user_nicename'] = $userdata['user_login'];
2386 - $userdata['user_email'] = 'noreply@' . $url['host'];
2387 - elseif ( $insanity > 50 ) :
2388 - // Stop doing the same thing and expecting a different result
2389 - break;
2390 - endif;
2391 2290 endswitch;
2392 2291 endif;
2393 - $insanity = $insanity + 1;
2394 2292 } while (is_wp_error($id));
2395 -
2396 - // $id should now contain the numeric ID of a newly minted
2397 - // user account. Let's mark them as having been generated
2398 - // by FeedWordPress in the usermeta table, as per the
2399 - // suggestion of @boonebgorges, in case we need to process,
2400 - // winnow, filter, or merge syndicated author accounts, &c.
2401 - if ( !is_wp_error($id)) :
2402 - add_user_meta($id, 'feedwordpress_generated', 1);
2403 - else :
2404 - $id = null;
2405 - endif;
2406 - // also see comment above regarding get_userdata(). (gwyneth 20220223)
2407 - elseif ( is_numeric( $unfamiliar_author ) and function_exists( 'get_userdata ') and get_userdata((int) $unfamiliar_author ) ) :
2293 + elseif (is_numeric($unfamiliar_author) and get_userdata((int) $unfamiliar_author)) :
2408 2294 $id = (int) $unfamiliar_author;
2409 - elseif ( $unfamiliar_author === 'default' ) :
2295 + elseif ($unfamiliar_author === 'default') :
2410 2296 $id = 1;
2411 2297 endif;
2412 2298 endif;
2413 2299 endif;
@@ -2439,4 +2325,5 @@
2439 2325 return $this->link->category_ids($this, $cats, $unfamiliar_category, $taxonomies, $params);
2440 2326 } /* SyndicatedPost::category_ids () */
2441 2327
2442 2328 } /* class SyndicatedPost */
2329 +