| @@ -32,10 +32,10 @@ | ||
| 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,9 +42,11 @@ | ||
| 42 | 42 | var $settings = array (); |
| 43 | 43 | public $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,26 +53,24 @@ | ||
| 51 | 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 () */ | |
| 62 | + } /* SyndicatedLink::SyndicatedLink () */ | |
| 63 | 63 | |
| 64 | - public function found () { | |
| 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 | 71 | |
| 72 | - public function stale () { | |
| 72 | + function stale () { | |
| 73 | 73 | global $feedwordpress; |
| 74 | 74 | |
| 75 | 75 | $stale = true; |
| 76 | 76 | if ($this->setting('update/hold')=='ping') : |
| @@ -76,11 +76,11 @@ | ||
| 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,12 +106,11 @@ | ||
| 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')) : |
| @@ -123,15 +122,11 @@ | ||
| 123 | 122 | else : |
| 124 | 123 | $ret = $this->simplepie; |
| 125 | 124 | endif; |
| 126 | 125 | return $ret; |
| 127 | - } /* SyndicatedLink::live_posts () */ | |
| 126 | + } | |
| 128 | 127 | |
| 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) { | |
| 128 | + function poll ($crash_ts = NULL) { | |
| 134 | 129 | global $wpdb; |
| 135 | 130 | |
| 136 | 131 | $url = $this->uri(array('add_params' => true, 'fetch' => true)); |
| 137 | 132 | FeedWordPress::diagnostic('updated_feeds', 'Polling feed ['.$url.']'); |
| @@ -161,9 +156,9 @@ | ||
| 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 |
| @@ -172,9 +167,9 @@ | ||
| 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); |
| @@ -182,31 +177,30 @@ | ||
| 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'])) : | |
| 194 | + if (!$this->hardcode('url') and isset($channel['link'])) : | |
| 201 | 195 | $update[] = "link_url = '".esc_sql($channel['link'])."'"; |
| 202 | 196 | endif; |
| 203 | 197 | |
| 204 | - if ( ! $this->hardcode('name') and isset($channel['title'])) : | |
| 198 | + if (!$this->hardcode('name') and isset($channel['title'])) : | |
| 205 | 199 | $update[] = "link_name = '".esc_sql($channel['title'])."'"; |
| 206 | 200 | endif; |
| 207 | 201 | |
| 208 | - if ( ! $this->hardcode('description')) : | |
| 202 | + if (!$this->hardcode('description')) : | |
| 209 | 203 | if (isset($channel['tagline'])) : |
| 210 | 204 | $update[] = "link_description = '".esc_sql($channel['tagline'])."'"; |
| 211 | 205 | elseif (isset($channel['description'])) : |
| 212 | 206 | $update[] = "link_description = '".esc_sql($channel['description'])."'"; |
| @@ -212,16 +206,31 @@ | ||
| 212 | 206 | $update[] = "link_description = '".esc_sql($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); | |
| 222 | 214 | |
| 223 | - if ( ! $this->setting('update/hold') != 'ping') : | |
| 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 | + )); | |
| 231 | + | |
| 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'); |
| @@ -241,9 +250,9 @@ | ||
| 241 | 250 | # -- Add new posts from feed and update any updated posts |
| 242 | 251 | $crashed = false; |
| 243 | 252 | |
| 244 | 253 | $posts = $this->live_posts(); |
| 245 | - | |
| 254 | + | |
| 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. |
| @@ -261,26 +270,23 @@ | ||
| 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')) : |
| @@ -286,9 +292,9 @@ | ||
| 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]) |
| @@ -316,12 +322,12 @@ | ||
| 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,22 +332,16 @@ | ||
| 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())."'"; | |
| 336 | + $update_set = "link_notes = '".esc_sql($this->settings_to_notes())."'"; | |
| 331 | 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 | |
| @@ -357,43 +357,11 @@ | ||
| 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, |
| @@ -410,9 +378,9 @@ | ||
| 410 | 378 | endforeach; |
| 411 | 379 | endif; |
| 412 | 380 | |
| 413 | 381 | return $delta; |
| 414 | - } /* SyndicatedLink::process_retirements () */ | |
| 382 | + } | |
| 415 | 383 | |
| 416 | 384 | /** |
| 417 | 385 | * Updates the URL for the feed syndicated by this link. |
| 418 | 386 | * |
| @@ -418,9 +386,9 @@ | ||
| 418 | 386 | * |
| 419 | 387 | * @param string $url The new feed URL to use for this source. |
| 420 | 388 | * @return bool TRUE on success, FALSE on failure. |
| 421 | 389 | */ |
| 422 | - public function set_uri ($url) { | |
| 390 | + function set_uri ($url) { | |
| 423 | 391 | global $wpdb; |
| 424 | 392 | |
| 425 | 393 | if ($this->found()) : |
| 426 | 394 | // Update link_rss |
| @@ -437,9 +405,9 @@ | ||
| 437 | 405 | endif; |
| 438 | 406 | return $ret; |
| 439 | 407 | } /* SyndicatedLink::set_uri () */ |
| 440 | 408 | |
| 441 | - public function deactivate () { | |
| 409 | + function deactivate () { | |
| 442 | 410 | global $wpdb; |
| 443 | 411 | |
| 444 | 412 | $wpdb->query($wpdb->prepare(" |
| 445 | 413 | UPDATE $wpdb->links SET link_visible = 'N' WHERE link_id = %d |
| @@ -445,20 +413,9 @@ | ||
| 445 | 413 | UPDATE $wpdb->links SET link_visible = 'N' WHERE link_id = %d |
| 446 | 414 | ", (int) $this->id)); |
| 447 | 415 | } /* SyndicatedLink::deactivate () */ |
| 448 | 416 | |
| 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 () { | |
| 417 | + function delete () { | |
| 461 | 418 | global $wpdb; |
| 462 | 419 | |
| 463 | 420 | $wpdb->query($wpdb->prepare(" |
| 464 | 421 | DELETE FROM $wpdb->postmeta WHERE meta_key='syndication_feed_id' |
| @@ -471,18 +428,9 @@ | ||
| 471 | 428 | |
| 472 | 429 | $this->id = NULL; |
| 473 | 430 | } /* SyndicatedLink::delete () */ |
| 474 | 431 | |
| 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 () { | |
| 432 | + function nuke () { | |
| 485 | 433 | global $wpdb; |
| 486 | 434 | |
| 487 | 435 | // Make a list of the items syndicated from this feed... |
| 488 | 436 | $post_ids = $wpdb->get_col($wpdb->prepare(" |
| @@ -505,9 +453,9 @@ | ||
| 505 | 453 | |
| 506 | 454 | $this->delete(); |
| 507 | 455 | } /* SyndicatedLink::nuke () */ |
| 508 | 456 | |
| 509 | - public function map_name_to_new_user ($name, $newuser_name) { | |
| 457 | + function map_name_to_new_user ($name, $newuser_name) { | |
| 510 | 458 | global $wpdb; |
| 511 | 459 | |
| 512 | 460 | if (strlen($newuser_name) > 0) : |
| 513 | 461 | $newuser_id = fwp_insert_new_user($newuser_name); |
| @@ -526,13 +474,13 @@ | ||
| 526 | 474 | // TODO: Add some error reporting |
| 527 | 475 | endif; |
| 528 | 476 | } /* SyndicatedLink::map_name_to_new_user () */ |
| 529 | 477 | |
| 530 | - protected function imploded_settings () { | |
| 478 | + function imploded_settings () { | |
| 531 | 479 | return array('cats', 'tags', 'match/cats', 'match/tags', 'match/filter'); |
| 532 | - } /* SyndicatedLink::imploded_settings () */ | |
| 480 | + } | |
| 533 | 481 | |
| 534 | - protected function get_settings_from_notes () { | |
| 482 | + function get_settings_from_notes () { | |
| 535 | 483 | // Read off feed settings from link_notes |
| 536 | 484 | $notes = explode("\n", $this->link->link_notes); |
| 537 | 485 | foreach ($notes as $note): |
| 538 | 486 | $pair = explode(": ", $note, 2); |
| @@ -537,9 +485,9 @@ | ||
| 537 | 485 | foreach ($notes as $note): |
| 538 | 486 | $pair = explode(": ", $note, 2); |
| 539 | 487 | $key = (isset($pair[0]) ? $pair[0] : null); |
| 540 | 488 | $value = (isset($pair[1]) ? $pair[1] : null); |
| 541 | - if ( !is_null($key) and !is_null($value)) : | |
| 489 | + if (!is_null($key) and !is_null($value)) : | |
| 542 | 490 | // Unescape and trim() off the whitespace. |
| 543 | 491 | // Thanks to Ray Lischner for pointing out the |
| 544 | 492 | // need to trim off whitespace. |
| 545 | 493 | $this->settings[$key] = stripcslashes (trim($value)); |
| @@ -568,9 +516,9 @@ | ||
| 568 | 516 | |
| 569 | 517 | // Set this up automagically for del.icio.us |
| 570 | 518 | $bits = parse_url($this->link->link_rss); |
| 571 | 519 | $tagspacers = array('del.icio.us', 'feeds.delicious.com'); |
| 572 | - if ( !isset($this->settings['cat_split']) and in_array($bits['host'], $tagspacers)) : | |
| 520 | + if (!isset($this->settings['cat_split']) and in_array($bits['host'], $tagspacers)) : | |
| 573 | 521 | $this->settings['cat_split'] = '\s'; // Whitespace separates multiple tags in del.icio.us RSS feeds |
| 574 | 522 | endif; |
| 575 | 523 | |
| 576 | 524 | // Simple lists |
| @@ -586,9 +534,9 @@ | ||
| 586 | 534 | if (isset($this->settings['terms'])) : |
| 587 | 535 | // Look for new format |
| 588 | 536 | $this->settings['terms'] = maybe_unserialize($this->settings['terms']); |
| 589 | 537 | |
| 590 | - if ( !is_array($this->settings['terms'])) : | |
| 538 | + if (!is_array($this->settings['terms'])) : | |
| 591 | 539 | // Deal with old format instead. Ugh. |
| 592 | 540 | |
| 593 | 541 | // Split on two *or more* consecutive breaks |
| 594 | 542 | // because in the old format, a taxonomy |
| @@ -617,10 +565,9 @@ | ||
| 617 | 565 | if (isset($this->settings['map authors'])) : |
| 618 | 566 | $author_rules = explode("\n\n", $this->settings['map authors']); |
| 619 | 567 | $ma = array(); |
| 620 | 568 | foreach ($author_rules as $rule) : |
| 621 | - $parts = array_pad(explode("\n", $rule), 3, ''); | |
| 622 | - list($rule_type, $author_name, $author_action) = $parts; | |
| 569 | + list($rule_type, $author_name, $author_action) = explode("\n", $rule); | |
| 623 | 570 | |
| 624 | 571 | // Normalize for case and whitespace |
| 625 | 572 | $rule_type = strtolower(trim($rule_type)); |
| 626 | 573 | $author_name = strtolower(trim($author_name)); |
| @@ -632,9 +579,9 @@ | ||
| 632 | 579 | endif; |
| 633 | 580 | |
| 634 | 581 | } /* SyndicatedLink::get_settings_from_notes () */ |
| 635 | 582 | |
| 636 | - protected function settings_to_notes () { | |
| 583 | + function settings_to_notes () { | |
| 637 | 584 | $to_notes = $this->settings; |
| 638 | 585 | |
| 639 | 586 | unset($to_notes['link/id']); // Magic setting; don't save |
| 640 | 587 | unset($to_notes['link/uri']); // Magic setting; don't save |
| @@ -678,9 +625,9 @@ | ||
| 678 | 625 | endforeach; |
| 679 | 626 | return $notes; |
| 680 | 627 | } /* SyndicatedLink::settings_to_notes () */ |
| 681 | 628 | |
| 682 | - public function save_settings ($reload = false) { | |
| 629 | + function save_settings ($reload = false) { | |
| 683 | 630 | global $wpdb; |
| 684 | 631 | |
| 685 | 632 | // Save channel-level meta-data |
| 686 | 633 | foreach (array('link_name', 'link_description', 'link_url') as $what) : |
| @@ -698,13 +645,8 @@ | ||
| 698 | 645 | SET $update_set |
| 699 | 646 | WHERE link_id='$this->id' |
| 700 | 647 | "); |
| 701 | 648 | |
| 702 | - if ( $result === false ) | |
| 703 | - { | |
| 704 | - error_log("query failed: " . $wpdb->last_error); | |
| 705 | - } | |
| 706 | - | |
| 707 | 649 | if ($reload) : |
| 708 | 650 | // force reload of link information from DB |
| 709 | 651 | if (function_exists('clean_bookmark_cache')) : |
| 710 | 652 | clean_bookmark_cache($this->id); |
| @@ -715,137 +657,79 @@ | ||
| 715 | 657 | /** |
| 716 | 658 | * Retrieves the value of a setting, allowing for a global setting to be |
| 717 | 659 | * used as a fallback, or a constant value, or both. |
| 718 | 660 | * |
| 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!! | |
| 661 | + * @param string $name The link setting key | |
| 662 | + * @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. | |
| 663 | + * @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. | |
| 664 | + * @return bool TRUE on success, FALSE on failure. | |
| 728 | 665 | */ |
| 729 | - public function setting( $name, $fallback_global = NULL, $fallback_value = NULL, $default = 'default' ) { | |
| 666 | + function setting ($name, $fallback_global = NULL, $fallback_value = NULL, $default = 'default') { | |
| 730 | 667 | $ret = NULL; |
| 731 | - if ( isset( $this->settings[ $name ] ) ) : | |
| 732 | - $ret = $this->settings[ $name ]; | |
| 668 | + if (isset($this->settings[$name])) : | |
| 669 | + $ret = $this->settings[$name]; | |
| 733 | 670 | endif; |
| 734 | 671 | |
| 735 | 672 | $no_value = ( |
| 736 | - is_null( $ret ) | |
| 737 | - or ( is_string( $ret ) and strtolower( $ret ) == $default ) | |
| 673 | + is_null($ret) | |
| 674 | + or (is_string($ret) and strtolower($ret)==$default) | |
| 738 | 675 | ); |
| 739 | 676 | |
| 740 | - if ( $no_value and ! is_null( $fallback_global ) ) : | |
| 677 | + if ($no_value and !is_null($fallback_global)) : | |
| 741 | 678 | // Avoid duplication of this correction |
| 742 | - $fallback_global = preg_replace( '/^feedwordpress_/', '', $fallback_global ); | |
| 679 | + $fallback_global = preg_replace('/^feedwordpress_/', '', $fallback_global); | |
| 743 | 680 | |
| 744 | 681 | // 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; | |
| 682 | + if ( is_array($fallback_global) && sizeof($fallback_global) ) | |
| 683 | + $fallback_global = reset($fallback_global); | |
| 748 | 684 | |
| 749 | - if ( ! empty( $fallback_global ) ) : | |
| 750 | - $ret = get_option( 'feedwordpress_' . $fallback_global, /*default=*/ NULL ); | |
| 751 | - endif; | |
| 685 | + if ( !empty($fallback_global) ) | |
| 686 | + $ret = get_option('feedwordpress_'.$fallback_global, /*default=*/ NULL); | |
| 752 | 687 | endif; |
| 753 | 688 | |
| 754 | 689 | $no_value = ( |
| 755 | - is_null( $ret ) | |
| 756 | - or ( is_string( $ret ) and strtolower( $ret ) == $default ) | |
| 690 | + is_null($ret) | |
| 691 | + or (is_string($ret) and strtolower($ret)==$default) | |
| 757 | 692 | ); |
| 758 | 693 | |
| 759 | - if ( $no_value and ! is_null( $fallback_value ) ) : | |
| 694 | + if ($no_value and !is_null($fallback_value)) : | |
| 760 | 695 | $ret = $fallback_value; |
| 761 | 696 | endif; |
| 762 | 697 | return $ret; |
| 763 | - } /* SyndicatedLink::setting() */ | |
| 698 | + } /* SyndicatedLink::setting () */ | |
| 764 | 699 | |
| 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 ); | |
| 700 | + function merge_settings ($data, $prefix, $separator = '/') { | |
| 701 | + $dd = $this->flatten_array($data, $prefix, $separator); | |
| 702 | + $this->settings = array_merge($this->settings, $dd); | |
| 777 | 703 | } /* SyndicatedLink::merge_settings () */ |
| 778 | 704 | |
| 779 | - public function update_setting( $name, $value, $default = 'default' ) { | |
| 780 | - if ( !is_null( $value ) and $value != $default ) : | |
| 781 | - $this->settings[ $name ] = $value; | |
| 705 | + function update_setting ($name, $value, $default = 'default') { | |
| 706 | + if (!is_null($value) and $value != $default) : | |
| 707 | + $this->settings[$name] = $value; | |
| 782 | 708 | else : // Zap it. |
| 783 | - unset( $this->settings[ $name ] ); | |
| 709 | + unset($this->settings[$name]); | |
| 784 | 710 | endif; |
| 785 | 711 | } /* SyndicatedLink::update_setting () */ |
| 786 | 712 | |
| 787 | - public function is_non_incremental () { | |
| 713 | + function is_non_incremental () { | |
| 788 | 714 | return ('complete'==$this->setting('update_incremental', 'update_incremental', 'incremental')); |
| 789 | 715 | } /* SyndicatedLink::is_non_incremental () */ |
| 790 | 716 | |
| 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()) { | |
| 717 | + function uri ($params = array()) { | |
| 828 | 718 | $params = wp_parse_args($params, array( |
| 829 | 719 | 'add_params' => false, |
| 830 | 720 | 'fetch' => false, |
| 831 | 721 | )); |
| 832 | 722 | |
| 833 | - // Initialize $qp (= array for added query parameters, if any) | |
| 834 | - $qp = array(); | |
| 723 | + $link_rss = (is_object($this->link) ? $this->link->link_rss : NULL); | |
| 835 | 724 | |
| 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 | 725 | $uri = $link_rss; |
| 841 | - if ( !is_null($uri) and strlen($uri) > 0 and $params['add_params']) : | |
| 726 | + if (!is_null($uri) and strlen($uri) > 0 and $params['add_params']) : | |
| 842 | 727 | $qp = maybe_unserialize($this->setting('query parameters', array())); |
| 843 | 728 | |
| 844 | 729 | // For high-tech HTTP feed request kung fu |
| 845 | 730 | $qp = apply_filters('syndicated_feed_parameters', $qp, $uri, $this); |
| 846 | 731 | |
| 847 | - // $qp is an array of key-value pairs stored as arrays of format [$key, $value] | |
| 848 | 732 | $q = array(); |
| 849 | 733 | if (is_array($qp) and count($qp) > 0) : |
| 850 | 734 | foreach ($qp as $pair) : |
| 851 | 735 | $q[] = urlencode($pair[0]).'='.urlencode($pair[1]); |
| @@ -861,34 +745,30 @@ | ||
| 861 | 745 | |
| 862 | 746 | // Do we have any filters that apply here? |
| 863 | 747 | $uri = apply_filters('syndicated_link_uri', $uri, $link_rss, $qp, $params, $this); |
| 864 | 748 | |
| 865 | - // Return the filtered link URI. | |
| 749 | + // Return the filtered link URI. | |
| 866 | 750 | return $uri; |
| 867 | 751 | } /* SyndicatedLink::uri () */ |
| 868 | 752 | |
| 869 | - public function username () { | |
| 753 | + function username () { | |
| 870 | 754 | return $this->setting('http username', 'http_username', NULL); |
| 871 | 755 | } /* SyndicatedLink::username () */ |
| 872 | 756 | |
| 873 | - public function password () { | |
| 757 | + function password () { | |
| 874 | 758 | return $this->setting('http password', 'http_password', NULL); |
| 875 | 759 | } /* SyndicatedLink::password () */ |
| 876 | 760 | |
| 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 | - | |
| 761 | + function authentication_method () { | |
| 762 | + $auth = $this->setting('http auth method', NULL); | |
| 763 | + if (('-' == $auth) or (strlen($auth)==0)) : | |
| 764 | + $auth = NULL; | |
| 765 | + endif; | |
| 886 | 766 | return $auth; |
| 887 | 767 | } /* SyndicatedLink::authentication_method () */ |
| 888 | - | |
| 768 | + | |
| 889 | 769 | var $postmeta = array(); |
| 890 | - public function postmeta ($params = array()) { | |
| 770 | + function postmeta ($params = array()) { | |
| 891 | 771 | $params = wp_parse_args($params, /*defaults=*/ array( |
| 892 | 772 | "field" => NULL, |
| 893 | 773 | "parsed" => false, |
| 894 | 774 | "force" => false, |
| @@ -899,9 +779,9 @@ | ||
| 899 | 779 | $default_custom_settings = get_option('feedwordpress_custom_settings'); |
| 900 | 780 | if ($default_custom_settings and !is_array($default_custom_settings)) : |
| 901 | 781 | $default_custom_settings = unserialize($default_custom_settings); |
| 902 | 782 | endif; |
| 903 | - if ( !is_array($default_custom_settings)) : | |
| 783 | + if (!is_array($default_custom_settings)) : | |
| 904 | 784 | $default_custom_settings = array(); |
| 905 | 785 | endif; |
| 906 | 786 | |
| 907 | 787 | // Next, get the settings for this particular feed. |
| @@ -908,9 +788,9 @@ | ||
| 908 | 788 | $custom_settings = $this->setting('postmeta', NULL, NULL); |
| 909 | 789 | if ($custom_settings and !is_array($custom_settings)) : |
| 910 | 790 | $custom_settings = unserialize($custom_settings); |
| 911 | 791 | endif; |
| 912 | - if ( !is_array($custom_settings)) : | |
| 792 | + if (!is_array($custom_settings)) : | |
| 913 | 793 | $custom_settings = array(); |
| 914 | 794 | endif; |
| 915 | 795 | |
| 916 | 796 | $this->postmeta[/*parsed=*/ false] = array_merge($default_custom_settings, $custom_settings); |
| @@ -917,15 +797,15 @@ | ||
| 917 | 797 | $this->postmeta[/*parsed=*/ true] = array(); |
| 918 | 798 | |
| 919 | 799 | // Now, run through and parse them all. |
| 920 | 800 | foreach ($this->postmeta[/*parsed=*/ false] as $key => $meta) : |
| 921 | - $meta = apply_filters("syndicated_link_post_meta_{$key}_pre", $meta, $this); | |
| 801 | + $meta = apply_filters("syndicated_link_post_meta_${key}_pre", $meta, $this); | |
| 922 | 802 | $this->postmeta[/*parsed=*/ false][$key] = $meta; |
| 923 | 803 | $this->postmeta[/*parsed=*/ true][$key] = new FeedWordPressParsedPostMeta($meta); |
| 924 | 804 | endforeach; |
| 925 | 805 | endif; |
| 926 | 806 | |
| 927 | - $ret = $this->postmeta[!! $params['parsed']]; | |
| 807 | + $ret = $this->postmeta[!!$params['parsed']]; | |
| 928 | 808 | if (is_string($params['field'])) : |
| 929 | 809 | $ret = $ret[$params['field']]; |
| 930 | 810 | endif; |
| 931 | 811 | return $ret; |
| @@ -930,18 +810,17 @@ | ||
| 930 | 810 | endif; |
| 931 | 811 | return $ret; |
| 932 | 812 | } /* SyndicatedLink::postmeta () */ |
| 933 | 813 | |
| 934 | - public function property_cascade ($fromFeed, $link_field, $setting, $method) { | |
| 814 | + function property_cascade ($fromFeed, $link_field, $setting, $method) { | |
| 935 | 815 | $value = NULL; |
| 936 | 816 | if ($fromFeed) : |
| 937 | 817 | $value = $this->setting($setting, NULL, NULL, NULL); |
| 938 | 818 | |
| 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! | |
| 819 | + $s = $this->simplepie; | |
| 820 | + $callable = (is_object($s) and method_exists($s, $method)); | |
| 821 | + if (is_null($value) and $callable) : | |
| 822 | + $fallback = $s->{$method}(); | |
| 944 | 823 | endif; |
| 945 | 824 | else : |
| 946 | 825 | $value = $this->link->{$link_field}; |
| 947 | 826 | endif; |
| @@ -947,17 +826,17 @@ | ||
| 947 | 826 | endif; |
| 948 | 827 | return $value; |
| 949 | 828 | } /* SyndicatedLink::property_cascade () */ |
| 950 | 829 | |
| 951 | - public function homepage ($fromFeed = true) { | |
| 830 | + function homepage ($fromFeed = true) { | |
| 952 | 831 | return $this->property_cascade($fromFeed, 'link_url', 'feed/link', 'get_link'); |
| 953 | 832 | } /* SyndicatedLink::homepage () */ |
| 954 | 833 | |
| 955 | - public function name ($fromFeed = true) { | |
| 834 | + function name ($fromFeed = true) { | |
| 956 | 835 | return $this->property_cascade($fromFeed, 'link_name', 'feed/title', 'get_title'); |
| 957 | 836 | } /* SyndicatedLink::name () */ |
| 958 | 837 | |
| 959 | - public function guid () { | |
| 838 | + function guid () { | |
| 960 | 839 | $ret = $this->setting('feed/id', NULL, $this->uri()); |
| 961 | 840 | |
| 962 | 841 | // If we can get it live from the feed, do so. |
| 963 | 842 | if (is_object($this->simplepie)) : |
| @@ -982,13 +861,13 @@ | ||
| 982 | 861 | endif; |
| 983 | 862 | return $ret; |
| 984 | 863 | } |
| 985 | 864 | |
| 986 | - public function links ($params = array()) { | |
| 865 | + function links ($params = array()) { | |
| 987 | 866 | $params = wp_parse_args($params, array( |
| 988 | 867 | "rel" => NULL, |
| 989 | 868 | )); |
| 990 | - | |
| 869 | + | |
| 991 | 870 | $fLinks = array(); |
| 992 | 871 | $search = array( |
| 993 | 872 | array('', 'link'), |
| 994 | 873 | array(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'), |
| @@ -993,9 +872,9 @@ | ||
| 993 | 872 | array('', 'link'), |
| 994 | 873 | array(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'), |
| 995 | 874 | array(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'), |
| 996 | 875 | ); |
| 997 | - | |
| 876 | + | |
| 998 | 877 | foreach ($search as $pair) : |
| 999 | 878 | if ($link_tags = $this->simplepie->get_feed_tags($pair[0], $pair[1])) : |
| 1000 | 879 | $fLinks = array_merge($fLinks, $link_tags); |
| 1001 | 880 | endif; |
| @@ -1002,13 +881,13 @@ | ||
| 1002 | 881 | if ($link_tags = $this->simplepie->get_channel_tags($pair[0], $pair[1])) : |
| 1003 | 882 | $fLinks = array_merge($fLinks, $link_tags); |
| 1004 | 883 | endif; |
| 1005 | 884 | endforeach; |
| 1006 | - | |
| 885 | + | |
| 1007 | 886 | $ret = array(); |
| 1008 | 887 | foreach ($fLinks as $link) : |
| 1009 | 888 | $filter = false; |
| 1010 | - if ( !is_null($params['rel'])) : | |
| 889 | + if (!is_null($params['rel'])) : | |
| 1011 | 890 | $filter = true; |
| 1012 | 891 | |
| 1013 | 892 | if (isset($link['attribs'])) : |
| 1014 | 893 | // Get a list of NSes from the search |
| @@ -1013,15 +892,15 @@ | ||
| 1013 | 892 | if (isset($link['attribs'])) : |
| 1014 | 893 | // Get a list of NSes from the search |
| 1015 | 894 | foreach ($search as $pair) : |
| 1016 | 895 | $ns = $pair[0]; |
| 1017 | - | |
| 896 | + | |
| 1018 | 897 | if (isset($link['attribs'][$ns]) |
| 1019 | 898 | and isset($link['attribs'][$ns]['rel']) |
| 1020 | 899 | ) : |
| 1021 | 900 | $rel = strtolower(trim($link['attribs'][$ns]['rel'])); |
| 1022 | 901 | $fRel = strtolower(trim($params['rel'])); |
| 1023 | - | |
| 902 | + | |
| 1024 | 903 | if ($rel == $fRel) : |
| 1025 | 904 | $filter = false; |
| 1026 | 905 | endif; |
| 1027 | 906 | endif; |
| @@ -1027,10 +906,10 @@ | ||
| 1027 | 906 | endif; |
| 1028 | 907 | endforeach; |
| 1029 | 908 | endif; |
| 1030 | 909 | endif; |
| 1031 | - | |
| 1032 | - if ( ! $filter) : | |
| 910 | + | |
| 911 | + if (!$filter) : | |
| 1033 | 912 | $ret[] = $link; |
| 1034 | 913 | endif; |
| 1035 | 914 | endforeach; |
| 1036 | 915 | |
| @@ -1035,10 +914,10 @@ | ||
| 1035 | 914 | endforeach; |
| 1036 | 915 | |
| 1037 | 916 | return $ret; |
| 1038 | 917 | } |
| 1039 | - | |
| 1040 | - public function ttl ($return_element = false) { | |
| 918 | + | |
| 919 | + function ttl ($return_element = false) { | |
| 1041 | 920 | if (is_object($this->magpie)) : |
| 1042 | 921 | $channel = $this->magpie->channel; |
| 1043 | 922 | else : |
| 1044 | 923 | $channel = array(); |
| @@ -1063,9 +942,9 @@ | ||
| 1063 | 942 | // "sy:updatePeriod: Describes the period over which the |
| 1064 | 943 | // channel format is updated. Acceptable values are: |
| 1065 | 944 | // hourly, daily, weekly, monthly, yearly. If omitted, |
| 1066 | 945 | // daily is assumed." <http://web.resource.org/rss/1.0/modules/syndication/> |
| 1067 | - if (isset($channel['sy']['updateperiod'])) : $period = trim($channel['sy']['updateperiod']); | |
| 946 | + if (isset($channel['sy']['updateperiod'])) : $period = $channel['sy']['updateperiod']; | |
| 1068 | 947 | else : $period = 'daily'; |
| 1069 | 948 | endif; |
| 1070 | 949 | |
| 1071 | 950 | // "sy:updateFrequency: Used to describe the frequency |
| @@ -1076,18 +955,10 @@ | ||
| 1076 | 955 | if (isset($channel['sy']['updatefrequency'])) : $freq = (int) $channel['sy']['updatefrequency']; |
| 1077 | 956 | else : $freq = 1; |
| 1078 | 957 | endif; |
| 1079 | 958 | |
| 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 | - | |
| 1087 | 959 | $xml = 'sy:updateFrequency'; |
| 1088 | - $ret = (int) ($mins / $freq); | |
| 1089 | - | |
| 960 | + $ret = (int) ($period_minutes[$period] / $freq); | |
| 1090 | 961 | else : |
| 1091 | 962 | $xml = NULL; |
| 1092 | 963 | $ret = NULL; |
| 1093 | 964 | endif; |
| @@ -1098,88 +969,69 @@ | ||
| 1098 | 969 | if ($min > $ret) : |
| 1099 | 970 | $ret = NULL; |
| 1100 | 971 | endif; |
| 1101 | 972 | endif; |
| 1102 | - return ( $return_element ? array( $ret, $xml ) : $ret ); | |
| 973 | + return ($return_element ? array($ret, $xml) : $ret); | |
| 1103 | 974 | } /* SyndicatedLink::ttl() */ |
| 1104 | 975 | |
| 1105 | - /** | |
| 1106 | - * Sets the automatic time interval for | |
| 1107 | - * | |
| 1108 | - * @return | |
| 1109 | - */ | |
| 1110 | - public function automatic_ttl() { | |
| 976 | + function automatic_ttl () { | |
| 1111 | 977 | // 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 ) ) : | |
| 978 | + $updateWindow = $this->setting('update/window', 'update_window', DEFAULT_UPDATE_PERIOD); | |
| 979 | + if (!is_numeric($updateWindow) or ($updateWindow < 1)) : | |
| 1114 | 980 | $updateWindow = DEFAULT_UPDATE_PERIOD; |
| 1115 | 981 | endif; |
| 1116 | 982 | |
| 1117 | 983 | // We get a fudge of 1/3 of window from elsewhere. We'll do some more |
| 1118 | 984 | // 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() */ | |
| 985 | + $fudgedInterval = $updateWindow+rand(-($updateWindow/6), 5*($updateWindow/12)); | |
| 986 | + return apply_filters('syndicated_feed_automatic_ttl', $fudgedInterval, $this); | |
| 987 | + } /* SyndicatedLink::automatic_ttl () */ | |
| 1122 | 988 | |
| 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; | |
| 989 | + // SyndicatedLink::flatten_array (): flatten an array. Useful for | |
| 990 | + // hierarchical and namespaced elements. | |
| 991 | + // | |
| 992 | + // Given an array which may contain array or object elements in it, | |
| 993 | + // return a "flattened" array: a one-dimensional array of scalars | |
| 994 | + // containing each of the scalar elements contained within the array | |
| 995 | + // structure. Thus, for example, if $a['b']['c']['d'] == 'e', then the | |
| 996 | + // returned array for FeedWordPress::flatten_array($a) will contain a key | |
| 997 | + // $a['feed/b/c/d'] with value 'e'. | |
| 998 | + function flatten_array ($arr, $prefix = 'feed/', $separator = '/') { | |
| 999 | + $ret = array (); | |
| 1000 | + if (is_array($arr)) : | |
| 1001 | + foreach ($arr as $key => $value) : | |
| 1002 | + if (is_scalar($value)) : | |
| 1003 | + $ret[$prefix.$key] = $value; | |
| 1145 | 1004 | else : |
| 1146 | - $ret = array_merge( $ret, $this->flatten_array( $value, $prefix.$key.$separator, $separator ) ); | |
| 1005 | + $ret = array_merge($ret, $this->flatten_array($value, $prefix.$key.$separator, $separator)); | |
| 1147 | 1006 | endif; |
| 1148 | 1007 | endforeach; |
| 1149 | 1008 | endif; |
| 1150 | 1009 | return $ret; |
| 1151 | - } /* SyndicatedLink::flatten_array() */ | |
| 1010 | + } /* SyndicatedLink::flatten_array () */ | |
| 1152 | 1011 | |
| 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) | |
| 1012 | + function hardcode ($what) { | |
| 1013 | + | |
| 1014 | + $ret = $this->setting('hardcode '.$what, 'hardcode_'.$what, NULL); | |
| 1015 | + | |
| 1016 | + if ('yes' == $ret) : | |
| 1017 | + $ret = true; | |
| 1018 | + else : | |
| 1019 | + $ret = false; | |
| 1020 | + endif; | |
| 1021 | + return $ret; | |
| 1163 | 1022 | } /* SyndicatedLink::hardcode () */ |
| 1164 | 1023 | |
| 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 ); | |
| 1024 | + function syndicated_status ($what, $default, $fallback = true) { | |
| 1025 | + global $wpdb; | |
| 1177 | 1026 | |
| 1178 | - return esc_sql( trim( strtolower( $ret ) ) ); | |
| 1027 | + $g_set = ($fallback ? 'syndicated_' . $what . '_status' : NULL); | |
| 1028 | + $ret = $this->setting($what.' status', $g_set, $default); | |
| 1029 | + | |
| 1030 | + return esc_sql(trim(strtolower($ret))); | |
| 1179 | 1031 | } /* SyndicatedLink:syndicated_status () */ |
| 1180 | 1032 | |
| 1181 | - public function taxonomies () { | |
| 1033 | + function taxonomies () { | |
| 1182 | 1034 | $post_type = $this->setting('syndicated post type', 'syndicated_post_type', 'post'); |
| 1183 | 1035 | return get_object_taxonomies(array('object_type' => $post_type), 'names'); |
| 1184 | 1036 | } /* SyndicatedLink::taxonomies () */ |
| 1185 | 1037 | |
| @@ -1191,9 +1043,9 @@ | ||
| 1191 | 1043 | * @param string $unfamiliar_category |
| 1192 | 1044 | * @param array|null $taxonomies |
| 1193 | 1045 | * @return array |
| 1194 | 1046 | */ |
| 1195 | - public function category_ids ($post, $cats, $unfamiliar_category = 'create', $taxonomies = NULL, $params = array()) { | |
| 1047 | + function category_ids ($post, $cats, $unfamiliar_category = 'create', $taxonomies = NULL, $params = array()) { | |
| 1196 | 1048 | $singleton = (isset($params['singleton']) ? $params['singleton'] : true); |
| 1197 | 1049 | $allowFilters = (isset($params['filters']) ? $params['filters'] : false); |
| 1198 | 1050 | |
| 1199 | 1051 | $catTax = 'category'; |
| @@ -1224,9 +1076,9 @@ | ||
| 1224 | 1076 | |
| 1225 | 1077 | if ($oTerm->is_familiar()) : |
| 1226 | 1078 | |
| 1227 | 1079 | $tax = $oTerm->taxonomy(); |
| 1228 | - if ( !isset($terms[$tax])) : | |
| 1080 | + if (!isset($terms[$tax])) : | |
| 1229 | 1081 | $terms[$tax] = array(); |
| 1230 | 1082 | endif; |
| 1231 | 1083 | $terms[$tax][] = $oTerm->id(); |
| 1232 | 1084 | |
| @@ -1244,10 +1096,10 @@ | ||
| 1244 | 1096 | $tax = $ref[2]; |
| 1245 | 1097 | endif; |
| 1246 | 1098 | |
| 1247 | 1099 | $inserted = $oTerm->insert($tax); |
| 1248 | - if ( !is_null($inserted)) : | |
| 1249 | - if ( !isset($terms[$tax])) : | |
| 1100 | + if (!is_null($inserted)) : | |
| 1101 | + if (!isset($terms[$tax])) : | |
| 1250 | 1102 | $terms[$tax] = array(); |
| 1251 | 1103 | endif; |
| 1252 | 1104 | $terms[$tax][] = $inserted; |
| 1253 | 1105 | else : |
| @@ -1288,6 +1140,6 @@ | ||
| 1288 | 1140 | 'Category: MAPPED term names '.json_encode($cats).' to IDs: '.json_encode($terms) |
| 1289 | 1141 | ); |
| 1290 | 1142 | return $terms; |
| 1291 | 1143 | } /* SyndicatedLink::category_ids () */ |
| 1292 | -} /* class SyndicatedLink */ | |
| 1144 | +} // class SyndicatedLink | |
| 1293 | 1145 | |