| @@ -24,9 +24,9 @@ | ||
| 24 | 24 | # Values have linebreak characters escaped with C-style |
| 25 | 25 | # backslashes (so, for example, a newline becomes "\n"). |
| 26 | 26 | # |
| 27 | 27 | # The value of `cats` is used as a newline-separated list of |
| 28 | -# default categories for any post coming from a particular feed. | |
| 28 | +# default categories for any post coming from a particular feed. | |
| 29 | 29 | # (In the example above, any posts from this feed will be placed |
| 30 | 30 | # in the "computers" and "web" categories--*in addition to* any |
| 31 | 31 | # categories that may already be applied to the posts.) |
| 32 | 32 | # |
| @@ -32,55 +32,55 @@ | ||
| 32 | 32 | # |
| 33 | 33 | # Values of keys in link_notes are accessible from templates using |
| 34 | 34 | # the function `get_feed_meta($key)` if this plugin is activated. |
| 35 | 35 | |
| 36 | -require_once dirname( __FILE__ ) . '/magpiefromsimplepie.class.php'; | |
| 37 | -require_once dirname( __FILE__ ) . '/feedwordpressparsedpostmeta.class.php'; | |
| 36 | +require_once(dirname(__FILE__).'/magpiefromsimplepie.class.php'); | |
| 37 | +require_once(dirname(__FILE__).'/feedwordpressparsedpostmeta.class.php'); | |
| 38 | 38 | |
| 39 | 39 | class SyndicatedLink { |
| 40 | 40 | var $id = null; |
| 41 | 41 | var $link = null; |
| 42 | 42 | var $settings = array (); |
| 43 | - public $simplepie = null; | |
| 43 | + var $simplepie = null; | |
| 44 | 44 | var $magpie = null; |
| 45 | 45 | |
| 46 | - public function __construct( $link ) { | |
| 46 | + function SyndicatedLink ($link) { | |
| 47 | + global $wpdb; | |
| 48 | + | |
| 47 | 49 | if (is_object($link)) : |
| 48 | 50 | $this->link = $link; |
| 49 | 51 | $this->id = $link->link_id; |
| 50 | 52 | else : |
| 51 | - $this->id = $link; | |
| 53 | + $this->id = $link; | |
| 52 | 54 | $this->link = get_bookmark($link); |
| 53 | 55 | endif; |
| 54 | 56 | |
| 55 | - if (is_object($this->link)) : | |
| 56 | - if (strlen($this->link->link_rss) > 0) : | |
| 57 | - $this->get_settings_from_notes(); | |
| 58 | - endif; | |
| 57 | + if (strlen($this->link->link_rss) > 0) : | |
| 58 | + $this->get_settings_from_notes(); | |
| 59 | 59 | endif; |
| 60 | - | |
| 60 | + | |
| 61 | 61 | add_filter('feedwordpress_update_complete', array($this, 'process_retirements'), 1000, 1); |
| 62 | - } /* SyndicatedLink::__construct () */ | |
| 63 | - | |
| 64 | - public function found () { | |
| 62 | + } /* SyndicatedLink::SyndicatedLink () */ | |
| 63 | + | |
| 64 | + function found () { | |
| 65 | 65 | return is_object($this->link) and !is_wp_error($this->link); |
| 66 | 66 | } /* SyndicatedLink::found () */ |
| 67 | 67 | |
| 68 | - public function id () { | |
| 68 | + function id () { | |
| 69 | 69 | return (is_object($this->link) ? $this->link->link_id : NULL); |
| 70 | 70 | } |
| 71 | - | |
| 72 | - public function stale () { | |
| 71 | + | |
| 72 | + function stale () { | |
| 73 | 73 | global $feedwordpress; |
| 74 | - | |
| 74 | + | |
| 75 | 75 | $stale = true; |
| 76 | 76 | if ($this->setting('update/hold')=='ping') : |
| 77 | 77 | $stale = false; // don't update on any timed updates; pings only |
| 78 | 78 | elseif ($this->setting('update/hold')=='next') : |
| 79 | 79 | $stale = true; // update on the next timed update |
| 80 | - elseif ( ! $this->setting('update/last') ) : | |
| 80 | + elseif ( !$this->setting('update/last') ) : | |
| 81 | 81 | $stale = true; // initial update |
| 82 | - elseif ( !empty($feedwordpress) and $feedwordpress->force_update_all()) : | |
| 82 | + elseif ($feedwordpress->force_update_all()) : | |
| 83 | 83 | $stale = true; // forced general updating |
| 84 | 84 | else : |
| 85 | 85 | $after = ( |
| 86 | 86 | (int) $this->setting('update/last') |
| @@ -91,9 +91,9 @@ | ||
| 91 | 91 | endif; |
| 92 | 92 | return $stale; |
| 93 | 93 | } /* SyndicatedLink::stale () */ |
| 94 | 94 | |
| 95 | - public function fetch () { | |
| 95 | + function fetch () { | |
| 96 | 96 | $timeout = $this->setting('fetch timeout', 'feedwordpress_fetch_timeout', FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT); |
| 97 | 97 | |
| 98 | 98 | $this->simplepie = apply_filters( |
| 99 | 99 | 'syndicated_feed', |
| @@ -106,15 +106,14 @@ | ||
| 106 | 106 | $this->magpie = $this->simplepie; |
| 107 | 107 | else : |
| 108 | 108 | $this->magpie = new MagpieFromSimplePie($this->simplepie, NULL); |
| 109 | 109 | endif; |
| 110 | - } /* SyndicatedLink::fetch () */ | |
| 111 | - | |
| 112 | - public function live_posts () { | |
| 113 | - if ( !is_object($this->simplepie)) : | |
| 110 | + } | |
| 111 | + function live_posts () { | |
| 112 | + if (!is_object($this->simplepie)) : | |
| 114 | 113 | $this->fetch(); |
| 115 | 114 | endif; |
| 116 | - | |
| 115 | + | |
| 117 | 116 | if (is_object($this->simplepie) and method_exists($this->simplepie, 'get_items')) : |
| 118 | 117 | $ret = apply_filters( |
| 119 | 118 | 'syndicated_feed_items', |
| 120 | 119 | $this->simplepie->get_items(), |
| @@ -123,18 +122,14 @@ | ||
| 123 | 122 | else : |
| 124 | 123 | $ret = $this->simplepie; |
| 125 | 124 | endif; |
| 126 | 125 | return $ret; |
| 127 | - } /* SyndicatedLink::live_posts () */ | |
| 128 | - | |
| 129 | - protected function pause_updates () { | |
| 130 | - return ('yes'==$this->setting("update/pause", "update_pause", 'no')); | |
| 131 | - } /* SyndicatedLink::pause_updates () */ | |
| 132 | - | |
| 133 | - public function poll ($crash_ts = NULL) { | |
| 126 | + } | |
| 127 | + | |
| 128 | + function poll ($crash_ts = NULL) { | |
| 134 | 129 | global $wpdb; |
| 135 | 130 | |
| 136 | - $url = $this->uri(array('add_params' => true, 'fetch' => true)); | |
| 131 | + $url = $this->uri(array('add_params' => true)); | |
| 137 | 132 | FeedWordPress::diagnostic('updated_feeds', 'Polling feed ['.$url.']'); |
| 138 | 133 | |
| 139 | 134 | $this->fetch(); |
| 140 | 135 | |
| @@ -161,12 +156,12 @@ | ||
| 161 | 156 | if (is_string($oldError)) : |
| 162 | 157 | $oldError = unserialize($oldError); |
| 163 | 158 | endif; |
| 164 | 159 | |
| 165 | - if ( !is_null($oldError)) : | |
| 160 | + if (!is_null($oldError)) : | |
| 166 | 161 | // Copy over the in-error-since timestamp |
| 167 | 162 | $theError['since'] = $oldError['since']; |
| 168 | - | |
| 163 | + | |
| 169 | 164 | // If this is a repeat error, then we should |
| 170 | 165 | // take a step back before we try to fetch it |
| 171 | 166 | // again. |
| 172 | 167 | $this->update_setting('update/last', time(), NULL); |
| @@ -172,65 +167,79 @@ | ||
| 172 | 167 | $this->update_setting('update/last', time(), NULL); |
| 173 | 168 | $ttl = $this->automatic_ttl(); |
| 174 | 169 | $ttl = apply_filters('syndicated_feed_ttl', $ttl, $this); |
| 175 | 170 | $ttl = apply_filters('syndicated_feed_ttl_from_error', $ttl, $this); |
| 176 | - $this->update_setting('update/ttl', $ttl); | |
| 171 | + $this->update_setting('update/ttl', $ttl, $this); | |
| 177 | 172 | $this->update_setting('update/timed', 'automatically'); |
| 178 | 173 | endif; |
| 179 | - | |
| 174 | + | |
| 180 | 175 | do_action('syndicated_feed_error', $theError, $oldError, $this); |
| 181 | - | |
| 176 | + | |
| 182 | 177 | $this->update_setting('update/error', serialize($theError)); |
| 183 | 178 | $this->save_settings(/*reload=*/ true); |
| 184 | 179 | |
| 185 | 180 | elseif (is_object($this->simplepie)) : |
| 186 | - | |
| 187 | 181 | // Success; clear out error setting, if any. |
| 188 | 182 | $this->update_setting('update/error', NULL); |
| 189 | 183 | |
| 190 | - $new_count = array('new' => 0, 'updated' => 0, 'stored' => 0); | |
| 184 | + $new_count = array('new' => 0, 'updated' => 0); | |
| 191 | 185 | |
| 192 | 186 | # -- Update Link metadata live from feed |
| 193 | 187 | $channel = $this->magpie->channel; |
| 194 | 188 | |
| 195 | - if ( !isset($channel['id'])) : | |
| 189 | + if (!isset($channel['id'])) : | |
| 196 | 190 | $channel['id'] = $this->link->link_rss; |
| 197 | 191 | endif; |
| 198 | - | |
| 192 | + | |
| 199 | 193 | $update = array(); |
| 200 | - if ( ! $this->hardcode('url') and isset($channel['link'])) : | |
| 201 | - $update[] = "link_url = '".esc_sql($channel['link'])."'"; | |
| 194 | + if (!$this->hardcode('url') and isset($channel['link'])) : | |
| 195 | + $update[] = "link_url = '".$wpdb->escape($channel['link'])."'"; | |
| 202 | 196 | endif; |
| 203 | - | |
| 204 | - if ( ! $this->hardcode('name') and isset($channel['title'])) : | |
| 205 | - $update[] = "link_name = '".esc_sql($channel['title'])."'"; | |
| 197 | + | |
| 198 | + if (!$this->hardcode('name') and isset($channel['title'])) : | |
| 199 | + $update[] = "link_name = '".$wpdb->escape($channel['title'])."'"; | |
| 206 | 200 | endif; |
| 207 | - | |
| 208 | - if ( ! $this->hardcode('description')) : | |
| 201 | + | |
| 202 | + if (!$this->hardcode('description')) : | |
| 209 | 203 | if (isset($channel['tagline'])) : |
| 210 | - $update[] = "link_description = '".esc_sql($channel['tagline'])."'"; | |
| 204 | + $update[] = "link_description = '".$wpdb->escape($channel['tagline'])."'"; | |
| 211 | 205 | elseif (isset($channel['description'])) : |
| 212 | - $update[] = "link_description = '".esc_sql($channel['description'])."'"; | |
| 206 | + $update[] = "link_description = '".$wpdb->escape($channel['description'])."'"; | |
| 213 | 207 | endif; |
| 214 | 208 | endif; |
| 215 | 209 | |
| 216 | - $this->update_setting('link/feed_type', $this->simplepie->get_type()); | |
| 217 | - | |
| 218 | 210 | $this->merge_settings($channel, 'feed/'); |
| 219 | 211 | |
| 220 | 212 | $this->update_setting('update/last', time()); |
| 221 | - $this->do_update_ttl(); | |
| 213 | + list($ttl, $xml) = $this->ttl(/*return element=*/ true); | |
| 214 | + | |
| 215 | + if (!is_null($ttl)) : | |
| 216 | + $this->update_setting('update/ttl', $ttl); | |
| 217 | + $this->update_setting('update/xml', $xml); | |
| 218 | + $this->update_setting('update/timed', 'feed'); | |
| 219 | + else : | |
| 220 | + $ttl = $this->automatic_ttl(); | |
| 221 | + $this->update_setting('update/ttl', $ttl); | |
| 222 | + $this->update_setting('update/xml', NULL); | |
| 223 | + $this->update_setting('update/timed', 'automatically'); | |
| 224 | + endif; | |
| 225 | + $this->update_setting('update/fudge', rand(0, ($ttl/3))*60); | |
| 226 | + $this->update_setting('update/ttl', apply_filters( | |
| 227 | + 'syndicated_feed_ttl', | |
| 228 | + $this->setting('update/ttl'), | |
| 229 | + $this | |
| 230 | + )); | |
| 222 | 231 | |
| 223 | - if ( ! $this->setting('update/hold') != 'ping') : | |
| 232 | + if (!$this->setting('update/hold') != 'ping') : | |
| 224 | 233 | $this->update_setting('update/hold', 'scheduled'); |
| 225 | 234 | endif; |
| 226 | 235 | |
| 227 | 236 | $this->update_setting('update/unfinished', 'yes'); |
| 228 | 237 | |
| 229 | - $update[] = "link_notes = '".esc_sql($this->settings_to_notes())."'"; | |
| 238 | + $update[] = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'"; | |
| 230 | 239 | |
| 231 | 240 | $update_set = implode(',', $update); |
| 232 | - | |
| 241 | + | |
| 233 | 242 | // Update the properties of the link from the feed information |
| 234 | 243 | $result = $wpdb->query(" |
| 235 | 244 | UPDATE $wpdb->links |
| 236 | 245 | SET $update_set |
| @@ -246,9 +255,9 @@ | ||
| 246 | 255 | $this->magpie->originals = $posts; |
| 247 | 256 | |
| 248 | 257 | // If this is a complete feed, rather than an incremental feed, we |
| 249 | 258 | // need to prepare to mark everything for presumptive retirement. |
| 250 | - if ($this->is_non_incremental()) : | |
| 259 | + if ($this->is_incremental()) : | |
| 251 | 260 | $q = new WP_Query(array( |
| 252 | 261 | 'fields' => '_synfrom', |
| 253 | 262 | 'post_status__not' => 'fwpretired', |
| 254 | 263 | 'ignore_sticky_posts' => true, |
| @@ -258,37 +267,34 @@ | ||
| 258 | 267 | foreach ($q->posts as $p) : |
| 259 | 268 | update_post_meta($p->ID, '_feedwordpress_retire_me_'.$this->id, '1'); |
| 260 | 269 | endforeach; |
| 261 | 270 | endif; |
| 262 | - | |
| 271 | + | |
| 263 | 272 | if (is_array($posts)) : |
| 264 | 273 | foreach ($posts as $key => $item) : |
| 265 | - if ( ! $this->pause_updates()) : | |
| 266 | - $post = new SyndicatedPost($item, $this); | |
| 274 | + $post = new SyndicatedPost($item, $this); | |
| 267 | 275 | |
| 268 | - if ( ! $resume or !in_array(trim($post->guid()), $processed)) : | |
| 269 | - $processed[] = $post->guid(); | |
| 270 | - if ( ! $post->filtered()) : | |
| 271 | - $new = $post->store(); | |
| 272 | - if ( $new !== false ) $new_count[$new]++; | |
| 273 | - endif; | |
| 276 | + if (!$resume or !in_array(trim($post->guid()), $processed)) : | |
| 277 | + $processed[] = $post->guid(); | |
| 278 | + if (!$post->filtered()) : | |
| 279 | + $new = $post->store(); | |
| 280 | + if ( $new !== false ) $new_count[$new]++; | |
| 281 | + endif; | |
| 274 | 282 | |
| 275 | - if ( !is_null($crash_ts) and (time() > $crash_ts)) : | |
| 276 | - $crashed = true; | |
| 277 | - break; | |
| 278 | - endif; | |
| 283 | + if (!is_null($crash_ts) and (time() > $crash_ts)) : | |
| 284 | + $crashed = true; | |
| 285 | + break; | |
| 279 | 286 | endif; |
| 280 | - | |
| 281 | - unset($post); | |
| 282 | 287 | endif; |
| 288 | + unset($post); | |
| 283 | 289 | endforeach; |
| 284 | 290 | endif; |
| 285 | - | |
| 291 | + | |
| 286 | 292 | if ('yes'==$this->setting('tombstones', 'tombstones', 'yes')) : |
| 287 | 293 | // Check for use of Atom tombstones. Spec: |
| 288 | 294 | // <http://tools.ietf.org/html/draft-snell-atompub-tombstones-18> |
| 289 | 295 | $tombstones = $this->simplepie->get_feed_tags('http://purl.org/atompub/tombstones/1.0', 'deleted-entry'); |
| 290 | - if ( !is_null($tombstones) && count($tombstones) > 0) : | |
| 296 | + if (count($tombstones) > 0) : | |
| 291 | 297 | foreach ($tombstones as $tombstone) : |
| 292 | 298 | $ref = NULL; |
| 293 | 299 | foreach (array('', 'http://purl.org/atompub/tombstones/1.0') as $ns) : |
| 294 | 300 | if (isset($tombstone['attribs'][$ns]) |
| @@ -295,9 +301,9 @@ | ||
| 295 | 301 | and isset($tombstone['attribs'][$ns]['ref'])) : |
| 296 | 302 | $ref = $tombstone['attribs'][$ns]['ref']; |
| 297 | 303 | endif; |
| 298 | 304 | endforeach; |
| 299 | - | |
| 305 | + | |
| 300 | 306 | $q = new WP_Query(array( |
| 301 | 307 | 'ignore_sticky_posts' => true, |
| 302 | 308 | 'guid' => $ref, |
| 303 | 309 | 'meta_key' => 'syndication_feed_id', |
| @@ -302,9 +308,9 @@ | ||
| 302 | 308 | 'guid' => $ref, |
| 303 | 309 | 'meta_key' => 'syndication_feed_id', |
| 304 | 310 | 'meta_value' => $this->id, // Only allow a feed to tombstone its own entries. |
| 305 | 311 | )); |
| 306 | - | |
| 312 | + | |
| 307 | 313 | foreach ($q->posts as $p) : |
| 308 | 314 | $old_status = $p->post_status; |
| 309 | 315 | FeedWordPress::diagnostic('syndicated_posts', 'Retiring existing post # '.$p->ID.' "'.$p->post_title.'" due to Atom tombstone element in feed.'); |
| 310 | 316 | set_post_field('post_status', 'fwpretired', $p->ID); |
| @@ -309,19 +315,19 @@ | ||
| 309 | 315 | FeedWordPress::diagnostic('syndicated_posts', 'Retiring existing post # '.$p->ID.' "'.$p->post_title.'" due to Atom tombstone element in feed.'); |
| 310 | 316 | set_post_field('post_status', 'fwpretired', $p->ID); |
| 311 | 317 | wp_transition_post_status('fwpretired', $old_status, $p); |
| 312 | 318 | endforeach; |
| 313 | - | |
| 319 | + | |
| 314 | 320 | endforeach; |
| 315 | 321 | endif; |
| 316 | 322 | endif; |
| 317 | - | |
| 323 | + | |
| 318 | 324 | $suffix = ($crashed ? 'crashed' : 'completed'); |
| 319 | 325 | do_action('update_syndicated_feed_items', $this->id, $this); |
| 320 | - do_action("update_syndicated_feed_items_{$suffix}", $this->id, $this); | |
| 326 | + do_action("update_syndicated_feed_items_${suffix}", $this->id, $this); | |
| 321 | 327 | |
| 322 | 328 | $this->update_setting('update/processed', $processed); |
| 323 | - if ( ! $crashed) : | |
| 329 | + if (!$crashed) : | |
| 324 | 330 | $this->update_setting('update/unfinished', 'no'); |
| 325 | 331 | endif; |
| 326 | 332 | $this->update_setting('link/item count', count($posts)); |
| 327 | 333 | |
| @@ -326,29 +332,23 @@ | ||
| 326 | 332 | $this->update_setting('link/item count', count($posts)); |
| 327 | 333 | |
| 328 | 334 | // Copy back any changes to feed settings made in the |
| 329 | 335 | // course of updating (e.g. new author rules) |
| 330 | - $update_set = "link_notes = '" . esc_sql($this->settings_to_notes())."'"; | |
| 331 | - | |
| 336 | + $update_set = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'"; | |
| 337 | + | |
| 332 | 338 | // Update the properties of the link from the feed information |
| 333 | 339 | $result = $wpdb->query(" |
| 334 | - UPDATE {$wpdb->links} | |
| 335 | - SET {$update_set} | |
| 336 | - WHERE link_id='{$this->id}' | |
| 340 | + UPDATE $wpdb->links | |
| 341 | + SET $update_set | |
| 342 | + WHERE link_id='$this->id' | |
| 337 | 343 | "); |
| 338 | - if ( FALSE === $result ) : | |
| 339 | - FeedWordPress::diagnostic( | |
| 340 | - 'SyndicatedLink/poll', | |
| 341 | - 'Database update failed', | |
| 342 | - ); | |
| 343 | - endif; | |
| 344 | - | |
| 344 | + | |
| 345 | 345 | do_action("update_syndicated_feed_completed", $this->id, $this); |
| 346 | 346 | endif; |
| 347 | - | |
| 347 | + | |
| 348 | 348 | // All done; let's clean up. |
| 349 | 349 | $this->magpie = NULL; |
| 350 | - | |
| 350 | + | |
| 351 | 351 | // Avoid circular-reference memory leak in PHP < 5.3. |
| 352 | 352 | // Cf. <http://simplepie.org/wiki/faq/i_m_getting_memory_leaks> |
| 353 | 353 | if (method_exists($this->simplepie, '__destruct')) : |
| 354 | 354 | $this->simplepie->__destruct(); |
| @@ -353,47 +353,15 @@ | ||
| 353 | 353 | if (method_exists($this->simplepie, '__destruct')) : |
| 354 | 354 | $this->simplepie->__destruct(); |
| 355 | 355 | endif; |
| 356 | 356 | $this->simplepie = NULL; |
| 357 | - | |
| 357 | + | |
| 358 | 358 | return $new_count; |
| 359 | 359 | } /* SyndicatedLink::poll() */ |
| 360 | 360 | |
| 361 | - /** | |
| 362 | - * Update the time to live of this link. | |
| 363 | - */ | |
| 364 | - public function do_update_ttl(): void { | |
| 365 | - // Get ttl and xml elements, return them if available | |
| 366 | - list( $ttl, $xml ) = $this->ttl( /*return element=*/ true); | |
| 361 | + function process_retirements ($delta) { | |
| 362 | + global $post; | |
| 367 | 363 | |
| 368 | - // Check if ttl is not null | |
| 369 | - if ( !is_null( $ttl ) ) { | |
| 370 | - $this->update_setting( 'update/ttl', $ttl ); | |
| 371 | - $this->update_setting( 'update/xml', $xml ); | |
| 372 | - $this->update_setting( 'update/timed', 'feed' ); | |
| 373 | - } else { | |
| 374 | - // Fallback to automatic ttl if null | |
| 375 | - $ttl = $this->automatic_ttl(); | |
| 376 | - $this->update_setting( 'update/ttl', $ttl ); | |
| 377 | - $this->update_setting( 'update/xml', null ); // Explicit null | |
| 378 | - $this->update_setting( 'update/timed', 'automatically' ); | |
| 379 | - } | |
| 380 | - | |
| 381 | - // Adding a random fudge value (ensure it works across versions) | |
| 382 | - $this->update_setting( 'update/fudge', rand( 0, (int) ( $ttl / 3 ) ) * 60 ); | |
| 383 | - | |
| 384 | - // Apply filter to ttl (should be compatible with all PHP 8.x versions) | |
| 385 | - $this->update_setting( | |
| 386 | - 'update/ttl', | |
| 387 | - apply_filters( | |
| 388 | - 'syndicated_feed_ttl', | |
| 389 | - $this->setting( 'update/ttl' ), | |
| 390 | - $this | |
| 391 | - ) | |
| 392 | - ); | |
| 393 | - } /* SyndicatedLink::do_update_ttl () */ | |
| 394 | - | |
| 395 | - public function process_retirements ($delta) { | |
| 396 | 364 | $q = new WP_Query(array( |
| 397 | 365 | 'fields' => '_synfrom', |
| 398 | 366 | 'post_status__not' => 'fwpretired', |
| 399 | 367 | 'ignore_sticky_posts' => true, |
| @@ -408,12 +376,11 @@ | ||
| 408 | 376 | wp_transition_post_status('fwpretired', $old_status, $p); |
| 409 | 377 | delete_post_meta($p->ID, '_feedwordpress_retire_me_'.$this->id); |
| 410 | 378 | endforeach; |
| 411 | 379 | endif; |
| 412 | - | |
| 413 | 380 | return $delta; |
| 414 | - } /* SyndicatedLink::process_retirements () */ | |
| 415 | - | |
| 381 | + } | |
| 382 | + | |
| 416 | 383 | /** |
| 417 | 384 | * Updates the URL for the feed syndicated by this link. |
| 418 | 385 | * |
| 419 | 386 | * @param string $url The new feed URL to use for this source. |
| @@ -418,9 +385,9 @@ | ||
| 418 | 385 | * |
| 419 | 386 | * @param string $url The new feed URL to use for this source. |
| 420 | 387 | * @return bool TRUE on success, FALSE on failure. |
| 421 | 388 | */ |
| 422 | - public function set_uri ($url) { | |
| 389 | + function set_uri ($url) { | |
| 423 | 390 | global $wpdb; |
| 424 | 391 | |
| 425 | 392 | if ($this->found()) : |
| 426 | 393 | // Update link_rss |
| @@ -426,12 +393,12 @@ | ||
| 426 | 393 | // Update link_rss |
| 427 | 394 | $result = $wpdb->query(" |
| 428 | 395 | UPDATE $wpdb->links |
| 429 | 396 | SET |
| 430 | - link_rss = '".esc_sql($url)."' | |
| 431 | - WHERE link_id = '".esc_sql($this->id)."' | |
| 397 | + link_rss = '".$wpdb->escape($url)."' | |
| 398 | + WHERE link_id = '".$wpdb->escape($this->id)."' | |
| 432 | 399 | "); |
| 433 | - | |
| 400 | + | |
| 434 | 401 | $ret = ($result ? true : false); |
| 435 | 402 | else : |
| 436 | 403 | $ret = false; |
| 437 | 404 | endif; |
| @@ -436,55 +403,35 @@ | ||
| 436 | 403 | $ret = false; |
| 437 | 404 | endif; |
| 438 | 405 | return $ret; |
| 439 | 406 | } /* SyndicatedLink::set_uri () */ |
| 440 | - | |
| 441 | - public function deactivate () { | |
| 407 | + | |
| 408 | + function deactivate () { | |
| 442 | 409 | global $wpdb; |
| 443 | - | |
| 410 | + | |
| 444 | 411 | $wpdb->query($wpdb->prepare(" |
| 445 | 412 | UPDATE $wpdb->links SET link_visible = 'N' WHERE link_id = %d |
| 446 | 413 | ", (int) $this->id)); |
| 447 | 414 | } /* SyndicatedLink::deactivate () */ |
| 448 | - | |
| 449 | - /** | |
| 450 | - * SyndicatedLink::delete() deletes a subscription from the WordPress links | |
| 451 | - * table. Any posts that were syndicated through that subscription will still | |
| 452 | - * be present in the wp_posts table; but postmeta fields that refer to the | |
| 453 | - * syndication feed's numeric id (which will no longer be valid) will be | |
| 454 | - * deleted. For most purposes, the posts remaining will be treated as if they | |
| 455 | - * were locally authored posts rather than syndicated posts. | |
| 456 | - * | |
| 457 | - * @global $wpdb | |
| 458 | - * @uses wpdb::query | |
| 459 | - */ | |
| 460 | - public function delete () { | |
| 415 | + | |
| 416 | + function delete () { | |
| 461 | 417 | global $wpdb; |
| 462 | - | |
| 418 | + | |
| 463 | 419 | $wpdb->query($wpdb->prepare(" |
| 464 | 420 | DELETE FROM $wpdb->postmeta WHERE meta_key='syndication_feed_id' |
| 465 | 421 | AND meta_value = '%s' |
| 466 | 422 | ", $this->id)); |
| 467 | - | |
| 423 | + | |
| 468 | 424 | $wpdb->query($wpdb->prepare(" |
| 469 | 425 | DELETE FROM $wpdb->links WHERE link_id = %d |
| 470 | 426 | ", (int) $this->id)); |
| 471 | - | |
| 427 | + | |
| 472 | 428 | $this->id = NULL; |
| 473 | 429 | } /* SyndicatedLink::delete () */ |
| 474 | - | |
| 475 | - /** | |
| 476 | - * SyndicatedLink::nuke() deletes a subscription AND all of the | |
| 477 | - * posts syndicated through that subscription. | |
| 478 | - * | |
| 479 | - * @global $wpdb | |
| 480 | - * @uses wpdb::get_col | |
| 481 | - * @uses wp_delete_post | |
| 482 | - * @uses SyndicatedLink::delete | |
| 483 | - */ | |
| 484 | - public function nuke () { | |
| 430 | + | |
| 431 | + function nuke () { | |
| 485 | 432 | global $wpdb; |
| 486 | - | |
| 433 | + | |
| 487 | 434 | // Make a list of the items syndicated from this feed... |
| 488 | 435 | $post_ids = $wpdb->get_col($wpdb->prepare(" |
| 489 | 436 | SELECT post_id FROM $wpdb->postmeta |
| 490 | 437 | WHERE meta_key = 'syndication_feed_id' |
| @@ -489,9 +436,9 @@ | ||
| 489 | 436 | SELECT post_id FROM $wpdb->postmeta |
| 490 | 437 | WHERE meta_key = 'syndication_feed_id' |
| 491 | 438 | AND meta_value = '%s' |
| 492 | 439 | ", $this->id)); |
| 493 | - | |
| 440 | + | |
| 494 | 441 | // ... and kill them all |
| 495 | 442 | if (count($post_ids) > 0) : |
| 496 | 443 | foreach ($post_ids as $post_id) : |
| 497 | 444 | // Force scrubbing of deleted post |
| @@ -501,13 +448,13 @@ | ||
| 501 | 448 | /*force_delete=*/ true |
| 502 | 449 | ); |
| 503 | 450 | endforeach; |
| 504 | 451 | endif; |
| 505 | - | |
| 452 | + | |
| 506 | 453 | $this->delete(); |
| 507 | 454 | } /* SyndicatedLink::nuke () */ |
| 508 | - | |
| 509 | - public function map_name_to_new_user ($name, $newuser_name) { | |
| 455 | + | |
| 456 | + function map_name_to_new_user ($name, $newuser_name) { | |
| 510 | 457 | global $wpdb; |
| 511 | 458 | |
| 512 | 459 | if (strlen($newuser_name) > 0) : |
| 513 | 460 | $newuser_id = fwp_insert_new_user($newuser_name); |
| @@ -526,13 +473,13 @@ | ||
| 526 | 473 | // TODO: Add some error reporting |
| 527 | 474 | endif; |
| 528 | 475 | } /* SyndicatedLink::map_name_to_new_user () */ |
| 529 | 476 | |
| 530 | - protected function imploded_settings () { | |
| 477 | + function imploded_settings () { | |
| 531 | 478 | return array('cats', 'tags', 'match/cats', 'match/tags', 'match/filter'); |
| 532 | - } /* SyndicatedLink::imploded_settings () */ | |
| 533 | - | |
| 534 | - protected function get_settings_from_notes () { | |
| 479 | + } | |
| 480 | + | |
| 481 | + function get_settings_from_notes () { | |
| 535 | 482 | // Read off feed settings from link_notes |
| 536 | 483 | $notes = explode("\n", $this->link->link_notes); |
| 537 | 484 | foreach ($notes as $note): |
| 538 | 485 | $pair = explode(": ", $note, 2); |
| @@ -537,9 +484,9 @@ | ||
| 537 | 484 | foreach ($notes as $note): |
| 538 | 485 | $pair = explode(": ", $note, 2); |
| 539 | 486 | $key = (isset($pair[0]) ? $pair[0] : null); |
| 540 | 487 | $value = (isset($pair[1]) ? $pair[1] : null); |
| 541 | - if ( !is_null($key) and !is_null($value)) : | |
| 488 | + if (!is_null($key) and !is_null($value)) : | |
| 542 | 489 | // Unescape and trim() off the whitespace. |
| 543 | 490 | // Thanks to Ray Lischner for pointing out the |
| 544 | 491 | // need to trim off whitespace. |
| 545 | 492 | $this->settings[$key] = stripcslashes (trim($value)); |
| @@ -549,9 +496,9 @@ | ||
| 549 | 496 | // "Magic" feed settings |
| 550 | 497 | $this->settings['link/uri'] = $this->link->link_rss; |
| 551 | 498 | $this->settings['link/name'] = $this->link->link_name; |
| 552 | 499 | $this->settings['link/id'] = $this->link->link_id; |
| 553 | - | |
| 500 | + | |
| 554 | 501 | // `hardcode categories` and `unfamiliar categories` are |
| 555 | 502 | // deprecated in favor of `unfamiliar category` |
| 556 | 503 | if ( |
| 557 | 504 | isset($this->settings['unfamiliar categories']) |
| @@ -568,9 +515,9 @@ | ||
| 568 | 515 | |
| 569 | 516 | // Set this up automagically for del.icio.us |
| 570 | 517 | $bits = parse_url($this->link->link_rss); |
| 571 | 518 | $tagspacers = array('del.icio.us', 'feeds.delicious.com'); |
| 572 | - if ( !isset($this->settings['cat_split']) and in_array($bits['host'], $tagspacers)) : | |
| 519 | + if (!isset($this->settings['cat_split']) and in_array($bits['host'], $tagspacers)) : | |
| 573 | 520 | $this->settings['cat_split'] = '\s'; // Whitespace separates multiple tags in del.icio.us RSS feeds |
| 574 | 521 | endif; |
| 575 | 522 | |
| 576 | 523 | // Simple lists |
| @@ -585,10 +532,10 @@ | ||
| 585 | 532 | |
| 586 | 533 | if (isset($this->settings['terms'])) : |
| 587 | 534 | // Look for new format |
| 588 | 535 | $this->settings['terms'] = maybe_unserialize($this->settings['terms']); |
| 589 | - | |
| 590 | - if ( !is_array($this->settings['terms'])) : | |
| 536 | + | |
| 537 | + if (!is_array($this->settings['terms'])) : | |
| 591 | 538 | // Deal with old format instead. Ugh. |
| 592 | 539 | |
| 593 | 540 | // Split on two *or more* consecutive breaks |
| 594 | 541 | // because in the old format, a taxonomy |
| @@ -617,16 +564,15 @@ | ||
| 617 | 564 | if (isset($this->settings['map authors'])) : |
| 618 | 565 | $author_rules = explode("\n\n", $this->settings['map authors']); |
| 619 | 566 | $ma = array(); |
| 620 | 567 | foreach ($author_rules as $rule) : |
| 621 | - $parts = array_pad(explode("\n", $rule), 3, ''); | |
| 622 | - list($rule_type, $author_name, $author_action) = $parts; | |
| 623 | - | |
| 568 | + list($rule_type, $author_name, $author_action) = explode("\n", $rule); | |
| 569 | + | |
| 624 | 570 | // Normalize for case and whitespace |
| 625 | 571 | $rule_type = strtolower(trim($rule_type)); |
| 626 | 572 | $author_name = strtolower(trim($author_name)); |
| 627 | 573 | $author_action = strtolower(trim($author_action)); |
| 628 | - | |
| 574 | + | |
| 629 | 575 | $ma[$rule_type][$author_name] = $author_action; |
| 630 | 576 | endforeach; |
| 631 | 577 | $this->settings['map authors'] = $ma; |
| 632 | 578 | endif; |
| @@ -631,10 +577,10 @@ | ||
| 631 | 577 | $this->settings['map authors'] = $ma; |
| 632 | 578 | endif; |
| 633 | 579 | |
| 634 | 580 | } /* SyndicatedLink::get_settings_from_notes () */ |
| 635 | - | |
| 636 | - protected function settings_to_notes () { | |
| 581 | + | |
| 582 | + function settings_to_notes () { | |
| 637 | 583 | $to_notes = $this->settings; |
| 638 | 584 | |
| 639 | 585 | unset($to_notes['link/id']); // Magic setting; don't save |
| 640 | 586 | unset($to_notes['link/uri']); // Magic setting; don't save |
| @@ -654,14 +600,14 @@ | ||
| 654 | 600 | $to_notes[$what] |
| 655 | 601 | ); |
| 656 | 602 | endif; |
| 657 | 603 | endforeach; |
| 658 | - | |
| 604 | + | |
| 659 | 605 | if (isset($to_notes['terms']) and is_array($to_notes['terms'])) : |
| 660 | 606 | // Serialize it. |
| 661 | 607 | $to_notes['terms'] = serialize($to_notes['terms']); |
| 662 | 608 | endif; |
| 663 | - | |
| 609 | + | |
| 664 | 610 | // Collapse the author mapping rule structure back into a flat string |
| 665 | 611 | if (isset($to_notes['map authors'])) : |
| 666 | 612 | $ma = array(); |
| 667 | 613 | foreach ($to_notes['map authors'] as $rule_type => $author_rules) : |
| @@ -678,18 +624,18 @@ | ||
| 678 | 624 | endforeach; |
| 679 | 625 | return $notes; |
| 680 | 626 | } /* SyndicatedLink::settings_to_notes () */ |
| 681 | 627 | |
| 682 | - public function save_settings ($reload = false) { | |
| 628 | + function save_settings ($reload = false) { | |
| 683 | 629 | global $wpdb; |
| 684 | 630 | |
| 685 | 631 | // Save channel-level meta-data |
| 686 | 632 | foreach (array('link_name', 'link_description', 'link_url') as $what) : |
| 687 | - $alter[] = "{$what} = '".esc_sql($this->link->{$what})."'"; | |
| 633 | + $alter[] = "{$what} = '".$wpdb->escape($this->link->{$what})."'"; | |
| 688 | 634 | endforeach; |
| 689 | 635 | |
| 690 | 636 | // Save settings to the notes field |
| 691 | - $alter[] = "link_notes = '".esc_sql($this->settings_to_notes())."'"; | |
| 637 | + $alter[] = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'"; | |
| 692 | 638 | |
| 693 | 639 | // Update the properties of the link from settings changes, etc. |
| 694 | 640 | $update_set = implode(", ", $alter); |
| 695 | 641 | |
| @@ -697,14 +643,9 @@ | ||
| 697 | 643 | UPDATE $wpdb->links |
| 698 | 644 | SET $update_set |
| 699 | 645 | WHERE link_id='$this->id' |
| 700 | 646 | "); |
| 701 | - | |
| 702 | - if ( $result === false ) | |
| 703 | - { | |
| 704 | - error_log("query failed: " . $wpdb->last_error); | |
| 705 | - } | |
| 706 | - | |
| 647 | + | |
| 707 | 648 | if ($reload) : |
| 708 | 649 | // force reload of link information from DB |
| 709 | 650 | if (function_exists('clean_bookmark_cache')) : |
| 710 | 651 | clean_bookmark_cache($this->id); |
| @@ -715,180 +656,106 @@ | ||
| 715 | 656 | /** |
| 716 | 657 | * Retrieves the value of a setting, allowing for a global setting to be |
| 717 | 658 | * used as a fallback, or a constant value, or both. |
| 718 | 659 | * |
| 719 | - * @param string $name The link setting key. | |
| 720 | - * @param mixed $fallback_global If the link setting is nonexistent or | |
| 721 | - * marked as a use-default value, fall back | |
| 722 | - * to the value of this global setting. | |
| 723 | - * @param mixed $fallback_value If the link setting and the global setting are | |
| 724 | - * nonexistent or marked as ause-default value, | |
| 725 | - * fall back to this constant value. | |
| 726 | - * | |
| 727 | - * @return mixed|null Should *not* return a boolean!! | |
| 660 | + * @param string $name The link setting key | |
| 661 | + * @param mixed $fallback_global If the link setting is nonexistent or marked as a use-default value, fall back to the value of this global setting. | |
| 662 | + * @param mixed $fallback_value If the link setting and the global setting are nonexistent or marked as a use-default value, fall back to this constant value. | |
| 663 | + * @return bool TRUE on success, FALSE on failure. | |
| 728 | 664 | */ |
| 729 | - public function setting( $name, $fallback_global = NULL, $fallback_value = NULL, $default = 'default' ) { | |
| 665 | + function setting ($name, $fallback_global = NULL, $fallback_value = NULL, $default = 'default') { | |
| 730 | 666 | $ret = NULL; |
| 731 | - if ( isset( $this->settings[ $name ] ) ) : | |
| 732 | - $ret = $this->settings[ $name ]; | |
| 667 | + if (isset($this->settings[$name])) : | |
| 668 | + $ret = $this->settings[$name]; | |
| 733 | 669 | endif; |
| 734 | - | |
| 670 | + | |
| 735 | 671 | $no_value = ( |
| 736 | - is_null( $ret ) | |
| 737 | - or ( is_string( $ret ) and strtolower( $ret ) == $default ) | |
| 672 | + is_null($ret) | |
| 673 | + or (is_string($ret) and strtolower($ret)==$default) | |
| 738 | 674 | ); |
| 739 | 675 | |
| 740 | - if ( $no_value and ! is_null( $fallback_global ) ) : | |
| 676 | + if ($no_value and !is_null($fallback_global)) : | |
| 741 | 677 | // Avoid duplication of this correction |
| 742 | - $fallback_global = preg_replace( '/^feedwordpress_/', '', $fallback_global ); | |
| 743 | - | |
| 744 | - // Occasionally we'll get an array back. Convert it to a string | |
| 745 | - if ( is_array( $fallback_global ) && sizeof( $fallback_global ) ) : | |
| 746 | - $fallback_global = reset( $fallback_global ); | |
| 747 | - endif; | |
| 748 | - | |
| 749 | - if ( ! empty( $fallback_global ) ) : | |
| 750 | - $ret = get_option( 'feedwordpress_' . $fallback_global, /*default=*/ NULL ); | |
| 751 | - endif; | |
| 678 | + $fallback_global = preg_replace('/^feedwordpress_/', '', $fallback_global); | |
| 679 | + | |
| 680 | + $ret = get_option('feedwordpress_'.$fallback_global, /*default=*/ NULL); | |
| 752 | 681 | endif; |
| 753 | 682 | |
| 754 | 683 | $no_value = ( |
| 755 | - is_null( $ret ) | |
| 756 | - or ( is_string( $ret ) and strtolower( $ret ) == $default ) | |
| 684 | + is_null($ret) | |
| 685 | + or (is_string($ret) and strtolower($ret)==$default) | |
| 757 | 686 | ); |
| 758 | 687 | |
| 759 | - if ( $no_value and ! is_null( $fallback_value ) ) : | |
| 688 | + if ($no_value and !is_null($fallback_value)) : | |
| 760 | 689 | $ret = $fallback_value; |
| 761 | 690 | endif; |
| 762 | 691 | return $ret; |
| 763 | - } /* SyndicatedLink::setting() */ | |
| 692 | + } /* SyndicatedLink::setting () */ | |
| 764 | 693 | |
| 765 | - /** | |
| 766 | - * Merge current settings with array of additional data. | |
| 767 | - * | |
| 768 | - * @param array $data Settings to merge with. | |
| 769 | - * @param string $prefix Hierarchical prefix (e.g. "feed/" as in "feed/a/b/c"). | |
| 770 | - * @param string $separator Hierarchy separator (e.g., '/'). | |
| 771 | - * | |
| 772 | - * @see SyndicatedLink::flatten_array() | |
| 773 | - */ | |
| 774 | - public function merge_settings( $data, $prefix, $separator = '/' ) { | |
| 775 | - $dd = $this->flatten_array( $data, $prefix, $separator ); | |
| 776 | - $this->settings = array_merge( $this->settings, $dd ); | |
| 694 | + function merge_settings ($data, $prefix, $separator = '/') { | |
| 695 | + $dd = $this->flatten_array($data, $prefix, $separator); | |
| 696 | + $this->settings = array_merge($this->settings, $dd); | |
| 777 | 697 | } /* SyndicatedLink::merge_settings () */ |
| 778 | - | |
| 779 | - public function update_setting( $name, $value, $default = 'default' ) { | |
| 780 | - if ( !is_null( $value ) and $value != $default ) : | |
| 781 | - $this->settings[ $name ] = $value; | |
| 698 | + | |
| 699 | + function update_setting ($name, $value, $default = 'default') { | |
| 700 | + if (!is_null($value) and $value != $default) : | |
| 701 | + $this->settings[$name] = $value; | |
| 782 | 702 | else : // Zap it. |
| 783 | - unset( $this->settings[ $name ] ); | |
| 703 | + unset($this->settings[$name]); | |
| 784 | 704 | endif; |
| 785 | 705 | } /* SyndicatedLink::update_setting () */ |
| 786 | - | |
| 787 | - public function is_non_incremental () { | |
| 706 | + | |
| 707 | + function is_incremental () { | |
| 788 | 708 | return ('complete'==$this->setting('update_incremental', 'update_incremental', 'incremental')); |
| 789 | - } /* SyndicatedLink::is_non_incremental () */ | |
| 790 | - | |
| 791 | - public function get_feed_type () { | |
| 792 | - $type_code = $this->setting('link/feed_type'); | |
| 793 | - | |
| 794 | - // list derived from: <http://simplepie.org/api/class-SimplePie.html>, retrieved 2020/01/18 | |
| 795 | - $bitmasks = array( | |
| 796 | - SIMPLEPIE_TYPE_RSS_090 => 'RSS 0.90', | |
| 797 | - SIMPLEPIE_TYPE_RSS_091_NETSCAPE => 'RSS 0.91 (Netscape)', | |
| 798 | - SIMPLEPIE_TYPE_RSS_091_USERLAND => 'RSS 0.91 (Userland)', | |
| 799 | - SIMPLEPIE_TYPE_RSS_091 => 'RSS 0.91', | |
| 800 | - SIMPLEPIE_TYPE_RSS_092 => 'RSS 0.92', | |
| 801 | - SIMPLEPIE_TYPE_RSS_093 => 'RSS 0.93', | |
| 802 | - SIMPLEPIE_TYPE_RSS_094 => 'RSS 0.94', | |
| 803 | - SIMPLEPIE_TYPE_RSS_10 => 'RSS 1.0', | |
| 804 | - SIMPLEPIE_TYPE_RSS_20 => 'RSS 2.0.x', | |
| 805 | - SIMPLEPIE_TYPE_RSS_RDF => 'RDF-based RSS', | |
| 806 | - SIMPLEPIE_TYPE_RSS_SYNDICATION => 'Non-RDF-based RSS', | |
| 807 | - SIMPLEPIE_TYPE_RSS_ALL => 'Any version of RSS', | |
| 808 | - SIMPLEPIE_TYPE_ATOM_03 => 'Atom 0.3', | |
| 809 | - SIMPLEPIE_TYPE_ATOM_10 => 'Atom 1.0', | |
| 810 | - SIMPLEPIE_TYPE_ATOM_ALL => 'Atom (any version)', | |
| 811 | - SIMPLEPIE_TYPE_ALL => 'Supported Feed (unspecified format)', | |
| 812 | - ); | |
| 813 | - | |
| 814 | - $type = "Unknown or unsupported format"; | |
| 815 | - foreach ($bitmasks as $format_flag => $format_string) : | |
| 816 | - if (is_numeric($format_flag)) : // Guard against failure of constants to be defined. | |
| 817 | - if ($type_code & $format_flag) : | |
| 818 | - $type = $format_string; | |
| 819 | - break; // foreach | |
| 820 | - endif; | |
| 821 | - endif; | |
| 822 | - endforeach; | |
| 823 | - | |
| 824 | - return $type; | |
| 825 | - } /* SyndicatedLink::get_feed_type () */ | |
| 826 | - | |
| 827 | - public function uri ($params = array()) { | |
| 709 | + } /* SyndicatedLink::is_incremental () */ | |
| 710 | + | |
| 711 | + function uri ($params = array()) { | |
| 828 | 712 | $params = wp_parse_args($params, array( |
| 829 | 713 | 'add_params' => false, |
| 830 | - 'fetch' => false, | |
| 831 | 714 | )); |
| 832 | - | |
| 833 | - // Initialize $qp (= array for added query parameters, if any) | |
| 834 | - $qp = array(); | |
| 835 | - | |
| 836 | - $link_rss = (is_object($this->link) ? $this->link->link_rss : NULL); | |
| 837 | - | |
| 838 | - // $link_rss stores the URI for the subscription as stored in the feed's record. | |
| 839 | - // $uri stores the effective URI of the request including any/all added query parameters | |
| 840 | - $uri = $link_rss; | |
| 841 | - if ( !is_null($uri) and strlen($uri) > 0 and $params['add_params']) : | |
| 715 | + | |
| 716 | + $uri = (is_object($this->link) ? $this->link->link_rss : NULL); | |
| 717 | + if (!is_null($uri) and strlen($uri) > 0 and $params['add_params']) : | |
| 842 | 718 | $qp = maybe_unserialize($this->setting('query parameters', array())); |
| 843 | - | |
| 719 | + | |
| 844 | 720 | // For high-tech HTTP feed request kung fu |
| 845 | 721 | $qp = apply_filters('syndicated_feed_parameters', $qp, $uri, $this); |
| 846 | - | |
| 847 | - // $qp is an array of key-value pairs stored as arrays of format [$key, $value] | |
| 722 | + | |
| 848 | 723 | $q = array(); |
| 849 | 724 | if (is_array($qp) and count($qp) > 0) : |
| 850 | 725 | foreach ($qp as $pair) : |
| 851 | 726 | $q[] = urlencode($pair[0]).'='.urlencode($pair[1]); |
| 852 | 727 | endforeach; |
| 853 | - | |
| 728 | + | |
| 854 | 729 | // Are we appending to a URI that already has params? |
| 855 | 730 | $sep = ((strpos($uri, "?")===false) ? '?' : '&'); |
| 856 | - | |
| 731 | + | |
| 857 | 732 | // Tack it on |
| 858 | 733 | $uri .= $sep . implode("&", $q); |
| 859 | - endif; | |
| 734 | + endif; | |
| 860 | 735 | endif; |
| 861 | - | |
| 862 | - // Do we have any filters that apply here? | |
| 863 | - $uri = apply_filters('syndicated_link_uri', $uri, $link_rss, $qp, $params, $this); | |
| 864 | - | |
| 865 | - // Return the filtered link URI. | |
| 736 | + | |
| 866 | 737 | return $uri; |
| 867 | 738 | } /* SyndicatedLink::uri () */ |
| 868 | 739 | |
| 869 | - public function username () { | |
| 740 | + function username () { | |
| 870 | 741 | return $this->setting('http username', 'http_username', NULL); |
| 871 | 742 | } /* SyndicatedLink::username () */ |
| 872 | - | |
| 873 | - public function password () { | |
| 743 | + | |
| 744 | + function password () { | |
| 874 | 745 | return $this->setting('http password', 'http_password', NULL); |
| 875 | 746 | } /* SyndicatedLink::password () */ |
| 876 | - | |
| 877 | - public function authentication_method () { | |
| 878 | - // Retrieve the authentication method from settings | |
| 879 | - $auth = $this->setting( 'http auth method', null ); | |
| 880 | - | |
| 881 | - // If the value is '-' or empty, treat it as NULL | |
| 882 | - if ( '-' === $auth || empty( $auth ) ) { | |
| 883 | - $auth = null; | |
| 884 | - } | |
| 885 | - | |
| 747 | + | |
| 748 | + function authentication_method () { | |
| 749 | + $auth = $this->setting('http auth method', NULL); | |
| 750 | + if (('-' == $auth) or (strlen($auth)==0)) : | |
| 751 | + $auth = NULL; | |
| 752 | + endif; | |
| 886 | 753 | return $auth; |
| 887 | 754 | } /* SyndicatedLink::authentication_method () */ |
| 888 | - | |
| 889 | - var $postmeta = array(); | |
| 890 | - public function postmeta ($params = array()) { | |
| 755 | + | |
| 756 | + var $postmeta = array(); | |
| 757 | + function postmeta ($params = array()) { | |
| 891 | 758 | $params = wp_parse_args($params, /*defaults=*/ array( |
| 892 | 759 | "field" => NULL, |
| 893 | 760 | "parsed" => false, |
| 894 | 761 | "force" => false, |
| @@ -899,49 +766,48 @@ | ||
| 899 | 766 | $default_custom_settings = get_option('feedwordpress_custom_settings'); |
| 900 | 767 | if ($default_custom_settings and !is_array($default_custom_settings)) : |
| 901 | 768 | $default_custom_settings = unserialize($default_custom_settings); |
| 902 | 769 | endif; |
| 903 | - if ( !is_array($default_custom_settings)) : | |
| 770 | + if (!is_array($default_custom_settings)) : | |
| 904 | 771 | $default_custom_settings = array(); |
| 905 | 772 | endif; |
| 906 | - | |
| 773 | + | |
| 907 | 774 | // Next, get the settings for this particular feed. |
| 908 | 775 | $custom_settings = $this->setting('postmeta', NULL, NULL); |
| 909 | 776 | if ($custom_settings and !is_array($custom_settings)) : |
| 910 | 777 | $custom_settings = unserialize($custom_settings); |
| 911 | 778 | endif; |
| 912 | - if ( !is_array($custom_settings)) : | |
| 779 | + if (!is_array($custom_settings)) : | |
| 913 | 780 | $custom_settings = array(); |
| 914 | 781 | endif; |
| 915 | - | |
| 782 | + | |
| 916 | 783 | $this->postmeta[/*parsed=*/ false] = array_merge($default_custom_settings, $custom_settings); |
| 917 | 784 | $this->postmeta[/*parsed=*/ true] = array(); |
| 918 | - | |
| 785 | + | |
| 919 | 786 | // Now, run through and parse them all. |
| 920 | 787 | foreach ($this->postmeta[/*parsed=*/ false] as $key => $meta) : |
| 921 | - $meta = apply_filters("syndicated_link_post_meta_{$key}_pre", $meta, $this); | |
| 788 | + $meta = apply_filters("syndicated_link_post_meta_${key}_pre", $meta, $this); | |
| 922 | 789 | $this->postmeta[/*parsed=*/ false][$key] = $meta; |
| 923 | 790 | $this->postmeta[/*parsed=*/ true][$key] = new FeedWordPressParsedPostMeta($meta); |
| 924 | 791 | endforeach; |
| 925 | 792 | endif; |
| 926 | 793 | |
| 927 | - $ret = $this->postmeta[!! $params['parsed']]; | |
| 794 | + $ret = $this->postmeta[!!$params['parsed']]; | |
| 928 | 795 | if (is_string($params['field'])) : |
| 929 | 796 | $ret = $ret[$params['field']]; |
| 930 | 797 | endif; |
| 931 | 798 | return $ret; |
| 932 | 799 | } /* SyndicatedLink::postmeta () */ |
| 933 | - | |
| 934 | - public function property_cascade ($fromFeed, $link_field, $setting, $method) { | |
| 800 | + | |
| 801 | + function property_cascade ($fromFeed, $link_field, $setting, $method) { | |
| 935 | 802 | $value = NULL; |
| 936 | 803 | if ($fromFeed) : |
| 937 | 804 | $value = $this->setting($setting, NULL, NULL, NULL); |
| 938 | - | |
| 939 | - $simp_pie = $this->simplepie; | |
| 940 | - $callable = ( is_object( $simp_pie ) and method_exists( $simp_pie, $method ) ); | |
| 941 | - if ( is_null( $value ) and $callable ) : | |
| 942 | -// $fallback = $s->{$method}(); // what is fallback supposed to be here? (gwyneth 20230816) | |
| 943 | - $value = $simp_pie->{$method}(); // makes more sense this way! | |
| 805 | + | |
| 806 | + $s = $this->simplepie; | |
| 807 | + $callable = (is_object($s) and method_exists($s, $method)); | |
| 808 | + if (is_null($value) and $callable) : | |
| 809 | + $fallback = $s->{$method}(); | |
| 944 | 810 | endif; |
| 945 | 811 | else : |
| 946 | 812 | $value = $this->link->{$link_field}; |
| 947 | 813 | endif; |
| @@ -946,24 +812,23 @@ | ||
| 946 | 812 | $value = $this->link->{$link_field}; |
| 947 | 813 | endif; |
| 948 | 814 | return $value; |
| 949 | 815 | } /* SyndicatedLink::property_cascade () */ |
| 950 | - | |
| 951 | - public function homepage ($fromFeed = true) { | |
| 816 | + | |
| 817 | + function homepage ($fromFeed = true) { | |
| 952 | 818 | return $this->property_cascade($fromFeed, 'link_url', 'feed/link', 'get_link'); |
| 953 | 819 | } /* SyndicatedLink::homepage () */ |
| 954 | 820 | |
| 955 | - public function name ($fromFeed = true) { | |
| 821 | + function name ($fromFeed = true) { | |
| 956 | 822 | return $this->property_cascade($fromFeed, 'link_name', 'feed/title', 'get_title'); |
| 957 | 823 | } /* SyndicatedLink::name () */ |
| 958 | 824 | |
| 959 | - public function guid () { | |
| 825 | + function guid () { | |
| 960 | 826 | $ret = $this->setting('feed/id', NULL, $this->uri()); |
| 961 | - | |
| 827 | + | |
| 962 | 828 | // If we can get it live from the feed, do so. |
| 963 | 829 | if (is_object($this->simplepie)) : |
| 964 | 830 | $search = array( |
| 965 | - array('', 'id'), | |
| 966 | 831 | array(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'), |
| 967 | 832 | array(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'), |
| 968 | 833 | array(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'), |
| 969 | 834 | array(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'), |
| @@ -968,9 +833,9 @@ | ||
| 968 | 833 | array(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'), |
| 969 | 834 | array(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'), |
| 970 | 835 | array(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'), |
| 971 | 836 | ); |
| 972 | - | |
| 837 | + | |
| 973 | 838 | foreach ($search as $pair) : |
| 974 | 839 | if ($id_tags = $this->simplepie->get_feed_tags($pair[0], $pair[1])) : |
| 975 | 840 | $ret = $id_tags[0]['data']; |
| 976 | 841 | break; |
| @@ -982,63 +847,9 @@ | ||
| 982 | 847 | endif; |
| 983 | 848 | return $ret; |
| 984 | 849 | } |
| 985 | 850 | |
| 986 | - public function links ($params = array()) { | |
| 987 | - $params = wp_parse_args($params, array( | |
| 988 | - "rel" => NULL, | |
| 989 | - )); | |
| 990 | - | |
| 991 | - $fLinks = array(); | |
| 992 | - $search = array( | |
| 993 | - array('', 'link'), | |
| 994 | - array(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'), | |
| 995 | - array(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'), | |
| 996 | - ); | |
| 997 | - | |
| 998 | - foreach ($search as $pair) : | |
| 999 | - if ($link_tags = $this->simplepie->get_feed_tags($pair[0], $pair[1])) : | |
| 1000 | - $fLinks = array_merge($fLinks, $link_tags); | |
| 1001 | - endif; | |
| 1002 | - if ($link_tags = $this->simplepie->get_channel_tags($pair[0], $pair[1])) : | |
| 1003 | - $fLinks = array_merge($fLinks, $link_tags); | |
| 1004 | - endif; | |
| 1005 | - endforeach; | |
| 1006 | - | |
| 1007 | - $ret = array(); | |
| 1008 | - foreach ($fLinks as $link) : | |
| 1009 | - $filter = false; | |
| 1010 | - if ( !is_null($params['rel'])) : | |
| 1011 | - $filter = true; | |
| 1012 | - | |
| 1013 | - if (isset($link['attribs'])) : | |
| 1014 | - // Get a list of NSes from the search | |
| 1015 | - foreach ($search as $pair) : | |
| 1016 | - $ns = $pair[0]; | |
| 1017 | - | |
| 1018 | - if (isset($link['attribs'][$ns]) | |
| 1019 | - and isset($link['attribs'][$ns]['rel']) | |
| 1020 | - ) : | |
| 1021 | - $rel = strtolower(trim($link['attribs'][$ns]['rel'])); | |
| 1022 | - $fRel = strtolower(trim($params['rel'])); | |
| 1023 | - | |
| 1024 | - if ($rel == $fRel) : | |
| 1025 | - $filter = false; | |
| 1026 | - endif; | |
| 1027 | - endif; | |
| 1028 | - endforeach; | |
| 1029 | - endif; | |
| 1030 | - endif; | |
| 1031 | - | |
| 1032 | - if ( ! $filter) : | |
| 1033 | - $ret[] = $link; | |
| 1034 | - endif; | |
| 1035 | - endforeach; | |
| 1036 | - | |
| 1037 | - return $ret; | |
| 1038 | - } | |
| 1039 | - | |
| 1040 | - public function ttl ($return_element = false) { | |
| 851 | + function ttl ($return_element = false) { | |
| 1041 | 852 | if (is_object($this->magpie)) : |
| 1042 | 853 | $channel = $this->magpie->channel; |
| 1043 | 854 | else : |
| 1044 | 855 | $channel = array(); |
| @@ -1047,9 +858,9 @@ | ||
| 1047 | 858 | if (isset($channel['ttl'])) : |
| 1048 | 859 | // "ttl stands for time to live. It's a number of |
| 1049 | 860 | // minutes that indicates how long a channel can be |
| 1050 | 861 | // cached before refreshing from the source." |
| 1051 | - // <http://blogs.law.harvard.edu/tech/rss#ltttlgtSubelementOfLtchannelgt> | |
| 862 | + // <http://blogs.law.harvard.edu/tech/rss#ltttlgtSubelementOfLtchannelgt> | |
| 1052 | 863 | $xml = 'rss:ttl'; |
| 1053 | 864 | $ret = $channel['ttl']; |
| 1054 | 865 | elseif (isset($channel['sy']['updatefrequency']) or isset($channel['sy']['updateperiod'])) : |
| 1055 | 866 | $period_minutes = array ( |
| @@ -1063,13 +874,13 @@ | ||
| 1063 | 874 | // "sy:updatePeriod: Describes the period over which the |
| 1064 | 875 | // channel format is updated. Acceptable values are: |
| 1065 | 876 | // hourly, daily, weekly, monthly, yearly. If omitted, |
| 1066 | 877 | // daily is assumed." <http://web.resource.org/rss/1.0/modules/syndication/> |
| 1067 | - if (isset($channel['sy']['updateperiod'])) : $period = trim($channel['sy']['updateperiod']); | |
| 878 | + if (isset($channel['sy']['updateperiod'])) : $period = $channel['sy']['updateperiod']; | |
| 1068 | 879 | else : $period = 'daily'; |
| 1069 | 880 | endif; |
| 1070 | - | |
| 1071 | - // "sy:updateFrequency: Used to describe the frequency | |
| 881 | + | |
| 882 | + // "sy:updateFrequency: Used to describe the frequency | |
| 1072 | 883 | // of updates in relation to the update period. A |
| 1073 | 884 | // positive integer indicates how many times in that |
| 1074 | 885 | // period the channel is updated. ... If omitted a value |
| 1075 | 886 | // of 1 is assumed." <http://web.resource.org/rss/1.0/modules/syndication/> |
| @@ -1075,219 +886,86 @@ | ||
| 1075 | 886 | // of 1 is assumed." <http://web.resource.org/rss/1.0/modules/syndication/> |
| 1076 | 887 | if (isset($channel['sy']['updatefrequency'])) : $freq = (int) $channel['sy']['updatefrequency']; |
| 1077 | 888 | else : $freq = 1; |
| 1078 | 889 | endif; |
| 1079 | - | |
| 1080 | - // normalize the period name... | |
| 1081 | - $period = strtolower(trim($period)); | |
| 1082 | - | |
| 1083 | - // do we recognize the alphanumeric period name? if not, then guess | |
| 1084 | - // a responsible default, e.g. roughly hourly | |
| 1085 | - $mins = (isset($period_minutes[$period]) ? $period_minutes[$period] : 67); | |
| 1086 | - | |
| 890 | + | |
| 1087 | 891 | $xml = 'sy:updateFrequency'; |
| 1088 | - $ret = (int) ($mins / $freq); | |
| 1089 | - | |
| 892 | + $ret = (int) ($period_minutes[$period] / $freq); | |
| 1090 | 893 | else : |
| 1091 | 894 | $xml = NULL; |
| 1092 | 895 | $ret = NULL; |
| 1093 | 896 | endif; |
| 1094 | - | |
| 897 | + | |
| 1095 | 898 | if ('yes'==$this->setting('update/minimum', 'update_minimum', 'no')) : |
| 1096 | 899 | $min = (int) $this->setting('update/window', 'update_window', DEFAULT_UPDATE_PERIOD); |
| 1097 | - | |
| 900 | + | |
| 1098 | 901 | if ($min > $ret) : |
| 1099 | 902 | $ret = NULL; |
| 1100 | 903 | endif; |
| 1101 | 904 | endif; |
| 1102 | - return ( $return_element ? array( $ret, $xml ) : $ret ); | |
| 905 | + return ($return_element ? array($ret, $xml) : $ret); | |
| 1103 | 906 | } /* SyndicatedLink::ttl() */ |
| 1104 | 907 | |
| 1105 | - /** | |
| 1106 | - * Sets the automatic time interval for | |
| 1107 | - * | |
| 1108 | - * @return | |
| 1109 | - */ | |
| 1110 | - public function automatic_ttl() { | |
| 908 | + function automatic_ttl () { | |
| 1111 | 909 | // spread out over a time interval for staggered updates |
| 1112 | - $updateWindow = $this->setting( 'update/window', 'update_window', DEFAULT_UPDATE_PERIOD ); | |
| 1113 | - if ( ! is_numeric( $updateWindow ) or ( $updateWindow < 1 ) ) : | |
| 910 | + $updateWindow = $this->setting('update/window', 'update_window', DEFAULT_UPDATE_PERIOD); | |
| 911 | + if (!is_numeric($updateWindow) or ($updateWindow < 1)) : | |
| 1114 | 912 | $updateWindow = DEFAULT_UPDATE_PERIOD; |
| 1115 | 913 | endif; |
| 1116 | 914 | |
| 1117 | 915 | // We get a fudge of 1/3 of window from elsewhere. We'll do some more |
| 1118 | 916 | // fudging here. |
| 1119 | - $fudgedInterval = $updateWindow + rand( - ( $updateWindow / 6 ), 5 * ( $updateWindow / 12 ) ); | |
| 1120 | - return apply_filters( 'syndicated_feed_automatic_ttl', $fudgedInterval, $this ); | |
| 1121 | - } /* SyndicatedLink::automatic_ttl() */ | |
| 917 | + $fudgedInterval = $updateWindow+rand(-($updateWindow/6), 5*($updateWindow/12)); | |
| 918 | + return apply_filters('syndicated_feed_automatic_ttl', $fudgedInterval, $this); | |
| 919 | + } /* SyndicatedLink::automatic_ttl () */ | |
| 1122 | 920 | |
| 1123 | - /** | |
| 1124 | - * SyndicatedLink::flatten_array (): flatten an array. Useful for | |
| 1125 | - * hierarchical and namespaced elements. | |
| 1126 | - * | |
| 1127 | - * Given an array which may contain array or object elements in it, | |
| 1128 | - * return a "flattened" array: a one-dimensional array of scalars | |
| 1129 | - * containing each of the scalar elements contained within the array | |
| 1130 | - * structure. Thus, for example, if $a['b']['c']['d'] == 'e', then the | |
| 1131 | - * returned array for FeedWordPress::flatten_array($a) will contain a key | |
| 1132 | - * $a['feed/b/c/d'] with value 'e'. | |
| 1133 | - * | |
| 1134 | - * @param array $arr Array to flatten. | |
| 1135 | - * @param string $prefix Hierarchical prefix (e.g. "feed/" as in "feed/a/b/c"). | |
| 1136 | - * @param string $separator Hierarchy separator (e.g., '/'). | |
| 1137 | - * @return array Flattened one-dimensional array. | |
| 1138 | - */ | |
| 1139 | - public function flatten_array( $arr, $prefix = 'feed/', $separator = '/' ) { | |
| 1140 | - $ret = array(); | |
| 1141 | - if ( is_array( $arr ) ) : | |
| 1142 | - foreach ( $arr as $key => $value ) : | |
| 1143 | - if ( is_scalar( $value ) ) : | |
| 1144 | - $ret[ $prefix.$key ] = $value; | |
| 921 | + // SyndicatedLink::flatten_array (): flatten an array. Useful for | |
| 922 | + // hierarchical and namespaced elements. | |
| 923 | + // | |
| 924 | + // Given an array which may contain array or object elements in it, | |
| 925 | + // return a "flattened" array: a one-dimensional array of scalars | |
| 926 | + // containing each of the scalar elements contained within the array | |
| 927 | + // structure. Thus, for example, if $a['b']['c']['d'] == 'e', then the | |
| 928 | + // returned array for FeedWordPress::flatten_array($a) will contain a key | |
| 929 | + // $a['feed/b/c/d'] with value 'e'. | |
| 930 | + function flatten_array ($arr, $prefix = 'feed/', $separator = '/') { | |
| 931 | + $ret = array (); | |
| 932 | + if (is_array($arr)) : | |
| 933 | + foreach ($arr as $key => $value) : | |
| 934 | + if (is_scalar($value)) : | |
| 935 | + $ret[$prefix.$key] = $value; | |
| 1145 | 936 | else : |
| 1146 | - $ret = array_merge( $ret, $this->flatten_array( $value, $prefix.$key.$separator, $separator ) ); | |
| 937 | + $ret = array_merge($ret, $this->flatten_array($value, $prefix.$key.$separator, $separator)); | |
| 1147 | 938 | endif; |
| 1148 | 939 | endforeach; |
| 1149 | 940 | endif; |
| 1150 | 941 | return $ret; |
| 1151 | - } /* SyndicatedLink::flatten_array() */ | |
| 942 | + } /* SyndicatedLink::flatten_array () */ | |
| 1152 | 943 | |
| 1153 | - /** | |
| 1154 | - * Check if a setting is hardcoded or not. | |
| 1155 | - * | |
| 1156 | - * @param string $what The setting we're checking for. | |
| 1157 | - * | |
| 1158 | - * @return bool True if the setting's value is 'yes', false otherwise. | |
| 1159 | - */ | |
| 1160 | - public function hardcode( $what ) { | |
| 1161 | - return 'yes' == $this->setting( 'hardcode ' . $what, 'hardcode_' . $what, NULL ); | |
| 1162 | - // Simplified logic. (gwyneth 20230920) | |
| 944 | + function hardcode ($what) { | |
| 945 | + | |
| 946 | + $ret = $this->setting('hardcode '.$what, 'hardcode_'.$what, NULL); | |
| 947 | + | |
| 948 | + if ('yes' == $ret) : | |
| 949 | + $ret = true; | |
| 950 | + else : | |
| 951 | + $ret = false; | |
| 952 | + endif; | |
| 953 | + return $ret; | |
| 1163 | 954 | } /* SyndicatedLink::hardcode () */ |
| 1164 | 955 | |
| 1165 | - /** | |
| 1166 | - * Returns the syndicated status for one item. | |
| 1167 | - * | |
| 1168 | - * @param string $what Item's name. | |
| 1169 | - * @param mixed $default Default value for this item. | |
| 1170 | - * @param boolean $fallback If true, falls back to global setting. | |
| 1171 | - * | |
| 1172 | - * @return string SQL-ready escaped status. | |
| 1173 | - */ | |
| 1174 | - public function syndicated_status( $what, $default, $fallback = true ) { | |
| 1175 | - $g_set = ( $fallback ? 'syndicated_' . $what . '_status' : NULL ); | |
| 1176 | - $ret = $this->setting( $what . ' status', $g_set, $default ); | |
| 956 | + function syndicated_status ($what, $default, $fallback = true) { | |
| 957 | + global $wpdb; | |
| 1177 | 958 | |
| 1178 | - return esc_sql( trim( strtolower( $ret ) ) ); | |
| 959 | + $g_set = ($fallback ? 'syndicated_' . $what . '_status' : NULL); | |
| 960 | + $ret = $this->setting($what.' status', $g_set, $default); | |
| 961 | + | |
| 962 | + return $wpdb->escape(trim(strtolower($ret))); | |
| 1179 | 963 | } /* SyndicatedLink:syndicated_status () */ |
| 1180 | - | |
| 1181 | - public function taxonomies () { | |
| 964 | + | |
| 965 | + function taxonomies () { | |
| 1182 | 966 | $post_type = $this->setting('syndicated post type', 'syndicated_post_type', 'post'); |
| 1183 | 967 | return get_object_taxonomies(array('object_type' => $post_type), 'names'); |
| 1184 | 968 | } /* SyndicatedLink::taxonomies () */ |
| 1185 | - | |
| 1186 | - /** | |
| 1187 | - * category_ids: look up (and create) category ids from a list of | |
| 1188 | - * categories | |
| 1189 | - * | |
| 1190 | - * @param array $cats | |
| 1191 | - * @param string $unfamiliar_category | |
| 1192 | - * @param array|null $taxonomies | |
| 1193 | - * @return array | |
| 1194 | - */ | |
| 1195 | - public function category_ids ($post, $cats, $unfamiliar_category = 'create', $taxonomies = NULL, $params = array()) { | |
| 1196 | - $singleton = (isset($params['singleton']) ? $params['singleton'] : true); | |
| 1197 | - $allowFilters = (isset($params['filters']) ? $params['filters'] : false); | |
| 1198 | - | |
| 1199 | - $catTax = 'category'; | |
| 1200 | - | |
| 1201 | - if (is_null($taxonomies)) : | |
| 1202 | - $taxonomies = array('category'); | |
| 1203 | - endif; | |
| 1204 | - | |
| 1205 | - // We need to normalize whitespace because (1) trailing | |
| 1206 | - // whitespace can cause PHP and MySQL not to see eye to eye on | |
| 1207 | - // VARCHAR comparisons for some versions of MySQL (cf. | |
| 1208 | - // <http://dev.mysql.com/doc/mysql/en/char.html>), and (2) | |
| 1209 | - // because I doubt most people want to make a semantic | |
| 1210 | - // distinction between 'Computers' and 'Computers ' | |
| 1211 | - $cats = array_map('trim', $cats); | |
| 1212 | - | |
| 1213 | - $terms = array(); | |
| 1214 | - foreach ($taxonomies as $tax) : | |
| 1215 | - $terms[$tax] = array(); | |
| 1216 | - endforeach; | |
| 1217 | - | |
| 1218 | - foreach ($cats as $cat_name) : | |
| 1219 | - if (strlen(trim($cat_name)) < 1) : | |
| 1220 | - continue; | |
| 1221 | - endif; | |
| 1222 | - | |
| 1223 | - $oTerm = new SyndicatedPostTerm($cat_name, $taxonomies, $post); | |
| 1224 | - | |
| 1225 | - if ($oTerm->is_familiar()) : | |
| 1226 | - | |
| 1227 | - $tax = $oTerm->taxonomy(); | |
| 1228 | - if ( !isset($terms[$tax])) : | |
| 1229 | - $terms[$tax] = array(); | |
| 1230 | - endif; | |
| 1231 | - $terms[$tax][] = $oTerm->id(); | |
| 1232 | - | |
| 1233 | - else : | |
| 1234 | - | |
| 1235 | - if ('tag'==$unfamiliar_category) : | |
| 1236 | - $unfamiliar_category = 'create:post_tag'; | |
| 1237 | - endif; | |
| 1238 | - | |
| 1239 | - if (preg_match('/^create(:(.*))?$/i', $unfamiliar_category, $ref)) : | |
| 1240 | - $tax = $catTax; // Default | |
| 1241 | - | |
| 1242 | - if (isset($ref[2]) | |
| 1243 | - and strlen($ref[2]) > 2) : | |
| 1244 | - $tax = $ref[2]; | |
| 1245 | - endif; | |
| 1246 | - | |
| 1247 | - $inserted = $oTerm->insert($tax); | |
| 1248 | - if ( !is_null($inserted)) : | |
| 1249 | - if ( !isset($terms[$tax])) : | |
| 1250 | - $terms[$tax] = array(); | |
| 1251 | - endif; | |
| 1252 | - $terms[$tax][] = $inserted; | |
| 1253 | - else : | |
| 1254 | - | |
| 1255 | - endif; // !is_null($inserted) | |
| 1256 | - endif; // preg_match(...) | |
| 1257 | - | |
| 1258 | - endif; /* ($oTerm->is_familiar()) */ | |
| 1259 | - endforeach; | |
| 1260 | - | |
| 1261 | - $filtersOn = $allowFilters; | |
| 1262 | - if ($allowFilters) : | |
| 1263 | - $filters = array_filter( | |
| 1264 | - $this->setting('match/filter', 'match_filter', array()), | |
| 1265 | - 'remove_dummy_zero' | |
| 1266 | - ); | |
| 1267 | - $filtersOn = ($filtersOn and is_array($filters) and (count($filters) > 0)); | |
| 1268 | - endif; | |
| 1269 | - | |
| 1270 | - // Check for filter conditions | |
| 1271 | - foreach ($terms as $tax => $term_ids) : | |
| 1272 | - if ($filtersOn | |
| 1273 | - and (count($term_ids)==0) | |
| 1274 | - and in_array($tax, $filters)) : | |
| 1275 | - $terms = NULL; // Drop the post | |
| 1276 | - break; | |
| 1277 | - else : | |
| 1278 | - $terms[$tax] = array_unique($term_ids); | |
| 1279 | - endif; | |
| 1280 | - endforeach; | |
| 1281 | - | |
| 1282 | - if ($singleton and count($terms)==1) : // If we only searched one, just return the term IDs | |
| 1283 | - $terms = end($terms); | |
| 1284 | - endif; | |
| 1285 | - | |
| 1286 | - FeedWordPress::diagnostic( | |
| 1287 | - 'syndicated_posts:categories', | |
| 1288 | - 'Category: MAPPED term names '.json_encode($cats).' to IDs: '.json_encode($terms) | |
| 1289 | - ); | |
| 1290 | - return $terms; | |
| 1291 | - } /* SyndicatedLink::category_ids () */ | |
| 1292 | -} /* class SyndicatedLink */ | |
| 969 | + | |
| 970 | +} // class SyndicatedLink | |
| 1293 | 971 | |