Changeset 2229752
- Timestamp:
- 01/18/2020 11:37:53 PM (5 years ago)
- Location:
- feedwordpress/trunk
- Files:
-
- 4 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified feedwordpress/trunk/admin-ui.php ¶
r1553712 r2229752 1 1 <?php 2 class FeedWordPressAdminPage { 3 protected $context; 4 protected $updated = false; 5 protected $mesg = NULL; 6 7 var $link = NULL; 8 var $dispatch = NULL; 9 var $filename = NULL; 10 var $pagenames = array(); 11 12 /** 13 * Construct the admin page object. 14 * 15 * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings 16 */ 17 public function __construct( $page = 'feedwordpressadmin', $link = NULL ) { 18 $this->link = $link; 19 20 // Set meta-box context name 21 $this->context = $page; 22 if ($this->for_feed_settings()) : 23 $this->context .= 'forfeed'; 24 endif; 25 } /* FeedWordPressAdminPage constructor */ 26 27 public function pageslug () { 28 $slug = preg_replace('/FeedWordPress(.*)Page/', '$1', get_class($this)); 29 return strtolower($slug); 30 } 31 32 public function pagename ($context = NULL) { 33 if (is_null($context)) : 34 $context = 'default'; 35 endif; 36 37 if (isset($this->pagenames[$context])) : 38 $name = $this->pagenames[$context]; 39 elseif (isset($tis->pagenames['default'])) : 40 $name = $this->pagenames['default']; 41 else : 42 $name = $this->pageslug(); 43 endif; 44 return __($name); 45 } /* FeedWordPressAdminPage::pagename () */ 46 47 public function accept_POST ($post) { 48 if ($this->for_feed_settings() and $this->update_requested_in($post)) : 49 $this->update_feed(); 50 elseif ($this->save_requested_in($post)) : // User mashed Save Changes 51 $this->save_settings($post); 52 endif; 53 do_action($this->dispatch.'_post', $post, $this); 54 } 55 56 public function update_feed () { 57 global $feedwordpress; 58 59 add_action('feedwordpress_check_feed', 'update_feeds_mention'); 60 add_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3); 61 62 $link = $this->link; 63 64 print '<div class="updated">'; 65 print "<ul>"; 66 $uri = $this->link->uri(); 67 $displayUrl = $uri; 68 69 // check for effects of an effective-url filter 70 $effectiveUrl = $link->uri(array('fetch' => true)); 71 if ($uri != $effectiveUrl) : $displayUrl .= ' | ' . $effectiveUrl; endif; 72 73 $delta = $feedwordpress->update($uri); 74 print "</ul>"; 75 76 if (!is_null($delta)) : 77 echo "<p><strong>Update complete.</strong>".fwp_update_set_results_message($delta)."</p>"; 78 echo "\n"; flush(); 79 else : 80 $effectiveUrl = esc_html($effectiveUrl); 81 echo "<p><strong>Error:</strong> There was a problem updating <a href=\"$effectiveUrl\">$displayUrl</a></p>\n"; 82 endif; 83 print "</div>\n"; 84 remove_action('feedwordpress_check_feed', 'update_feeds_mention'); 85 remove_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3); 86 } 87 88 public function save_settings ($post) { 89 do_action($this->dispatch.'_save', $post, $this); 90 91 if ($this->for_feed_settings()) : 92 // Save settings 93 $this->link->save_settings(/*reload=*/ true); 94 $this->updated = true; 95 96 // Reset, reload 97 $link_id = $this->link->id; 98 unset($this->link); 99 $this->link = new SyndicatedLink($link_id); 100 else : 101 $this->updated = true; 102 endif; 103 } /* FeedWordPressAdminPage::save_settings () */ 104 105 public function for_feed_settings () { return (is_object($this->link) and method_exists($this->link, 'found') and $this->link->found()); } 106 public function for_default_settings () { return !$this->for_feed_settings(); } 107 108 public function setting ($names, $fallback_value = NULL, $params = array()) { 109 if (!is_array($params)) : 110 $params = array('default' => $params); 111 endif; 112 $params = shortcode_atts(array( 113 'default' => 'default', 114 'fallback' => true, 115 ), $params); 116 117 if (is_string($names)) : 118 $feed_name = $names; 119 $global_name = 'feedwordpress_'.preg_replace('![\s/]+!', '_', $names); 120 else : 121 $feed_name = $names['feed']; 122 $global_name = 'feedwordpress_'.$names['global']; 123 endif; 124 125 if ($this->for_feed_settings()) : // Check feed-specific setting first; fall back to global 126 if (!$params['fallback']) : $global_name = NULL; endif; 127 $ret = $this->link->setting($feed_name, $global_name, $fallback_value, $params['default']); 128 else : // Check global setting 129 $ret = get_option($global_name, $fallback_value); 130 endif; 131 return $ret; 132 } 133 134 public function update_setting ($names, $value, $default = 'default') { 135 if (is_string($names)) : 136 $feed_name = $names; 137 $global_name = 'feedwordpress_'.preg_replace('![\s/]+!', '_', $names); 138 else : 139 $feed_name = $names['feed']; 140 $global_name = 'feedwordpress_'.$names['global']; 141 endif; 142 143 if ($this->for_feed_settings()) : // Update feed-specific setting 144 $this->link->update_setting($feed_name, $value, $default); 145 else : // Update global setting 146 update_option($global_name, $value); 147 endif; 148 } /* FeedWordPressAdminPage::update_setting () */ 149 150 public function save_requested_in ($post) { 151 return (isset($post['save']) or isset($post['submit'])); 152 } 153 public function update_requested_in ($post) { 154 return (isset($post['update']) and (strlen($post['update']) > 0)); 155 } 156 157 public function submitted_link_id () { 158 global $fwp_post; 159 160 // Presume global unless we get a specific link ID 161 $link_id = NULL; 162 163 $submit_buttons = array( 164 'save', 165 'submit', 166 'fix_mismatch', 167 'feedfinder', 168 ); 169 foreach ($submit_buttons as $field) : 170 if (isset($fwp_post[$field])) : 171 $link_id = MyPHP::request('save_link_id'); 172 endif; 173 endforeach; 174 175 if (is_null($link_id) and isset($_REQUEST['link_id'])) : 176 $link_id = MyPHP::request('link_id'); 177 endif; 178 179 return $link_id; 180 } /* FeedWordPressAdminPage::submitted_link_id() */ 181 182 public function submitted_link () { 183 $link_id = $this->submitted_link_id(); 184 if (is_numeric($link_id) and $link_id) : 185 $link = new SyndicatedLink($link_id); 186 else : 187 $link = NULL; 188 endif; 189 return $link; 190 } /* FeedWordPressAdminPage::submitted_link () */ 191 192 public function stamp_link_id ($field = null) { 193 if (is_null($field)) : $field = 'save_link_id'; endif; 194 ?> 195 <input type="hidden" name="<?php print esc_attr($field); ?>" value="<?php print ($this->for_feed_settings() ? $this->link->id : '*'); ?>" /> 196 <?php 197 } /* FeedWordPressAdminPage::stamp_link_id () */ 198 199 public function these_posts_phrase () { 200 if ($this->for_feed_settings()) : 201 $phrase = __('posts from this feed'); 202 else : 203 $phrase = __('syndicated posts'); 204 endif; 205 return $phrase; 206 } /* FeedWordPressAdminPage::these_posts_phrase() */ 207 208 /** 209 * Provides a uniquely identifying name for the interface context for 210 * use with add_meta_box() and do_meta_boxes(), 211 * 212 * @return string the context name 213 * 214 * @see add_meta_box() 215 * @see do_meta_boxes() 216 */ 217 public function meta_box_context () { 218 return $this->context; 219 } /* FeedWordPressAdminPage::meta_box_context () */ 220 221 /** 222 * Outputs JavaScript to fix AJAX toggles settings. 223 * 224 * @uses FeedWordPressAdminPage::meta_box_context() 225 */ 226 public function fix_toggles () { 227 FeedWordPressSettingsUI::fix_toggles_js($this->meta_box_context()); 228 } /* FeedWordPressAdminPage::fix_toggles() */ 229 230 public function ajax_interface_js () { 231 ?> 232 function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) { 233 if (typeof(visibleStyle)=='undefined') visibleStyle = 'block'; 234 235 var rollup=document.getElementById(item); 236 if (rollup) { 237 if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) { 238 jQuery('#'+disappear).hide(); 239 jQuery('#'+appear).show(600); 240 } else { 241 jQuery('#'+appear).hide(); 242 jQuery('#'+disappear).show(600); 243 } 244 } 245 } 246 <?php 247 } /* FeedWordPressAdminPage::ajax_interface_js () */ 248 249 public function admin_page_href ($page, $params = array(), $link = NULL) { 250 global $fwp_path; 251 252 // Merge in the page's filename 253 $params = array_merge($params, array('page' => $fwp_path.'/'.$page)); 254 255 // If there is a link ID provided, then merge that in too. 256 if (!is_null($link)) : 257 $link_id = NULL; 258 if (is_object($link)) : 259 if (method_exists($link, 'found')) : 260 // Is this a SyndicatedLink object? 261 if ($link->found()) : 262 $link_id = $link->link->link_id; 263 endif; 264 else : 265 // Is this a wp_links table record? 266 $link_id = $link->link_id; 267 endif; 268 else : 269 // Is this just a numeric ID? 270 $link_id = $link; 271 endif; 272 273 if (!is_null($link_id)) : 274 $params = array_merge($params, array('link_id' => $link_id)); 275 endif; 276 endif; 277 278 return MyPHP::url(admin_url('admin.php'), $params); 279 } /* FeedWordPressAdminPage::admin_page_href () */ 280 281 public function display_feed_settings_page_links ($params = array()) { 282 global $fwp_path; 283 284 $params = wp_parse_args($params, array( 285 'before' => '', 286 'between' => ' | ', 287 'after' => '', 288 'long' => false, 289 'subscription' => $this->link, 290 )); 291 $sub = $params['subscription']; 292 293 $links = array( 294 "Feed" => array('page' => 'feeds-page.php', 'long' => 'Feeds & Updates'), 295 "Posts" => array('page' => 'posts-page.php', 'long' => 'Posts & Links'), 296 "Authors" => array('page' => 'authors-page.php', 'long' => 'Authors'), 297 'Categories' => array('page' => 'categories-page.php', 'long' => 'Categories & Tags'), 298 ); 299 300 $link_id = NULL; 301 if (is_object($sub)) : 302 if (method_exists($sub, 'found')) : 303 if ($sub->found()) : 304 $link_id = $sub->link->link_id; 305 endif; 306 else : 307 $link_id = $sub->link_id; 308 endif; 309 endif; 310 311 print $params['before']; $first = true; 312 foreach ($links as $label => $link) : 313 if (!$first) : print $params['between']; endif; 314 315 if (isset($link['url'])) : MyPHP::url($link['url'], array("link_id" => $link_id)); 316 else : $url = $this->admin_page_href($link['page'], array(), $sub); 317 endif; 318 $url = esc_html($url); 319 320 if ($link['page']==basename($this->filename)) : 321 print "<strong>"; 322 else : 323 print "<a href=\"${url}\">"; 324 endif; 325 326 if ($params['long']) : print esc_html(__($link['long'])); 327 else : print esc_html(__($label)); 328 endif; 329 330 if ($link['page']==basename($this->filename)) : 331 print "</strong>"; 332 else : 333 print "</a>"; 334 endif; 335 336 $first = false; 337 endforeach; 338 print $params['after']; 339 } /* FeedWordPressAdminPage::display_feed_settings_page_links */ 340 341 public function display_feed_select_dropdown() { 342 $links = FeedWordPress::syndicated_links(); 343 344 ?> 345 <div id="fwpfs-container"><ul class="subsubsub"> 346 <li><select name="link_id" class="fwpfs" style="max-width: 20.0em;"> 347 <option value="*"<?php if ($this->for_default_settings()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option> 348 <?php if ($links) : foreach ($links as $ddlink) : ?> 349 <option value="<?php print (int) $ddlink->link_id; ?>"<?php if (!is_null($this->link) and ($this->link->id==$ddlink->link_id)) : ?> selected="selected"<?php endif; ?>><?php print esc_html($ddlink->link_name); ?></option> 350 <?php endforeach; endif; ?> 351 </select> 352 <input id="fwpfs-button" class="button" type="submit" name="go" value="<?php _e('Go') ?> »" /></li> 353 354 <?php 355 $this->display_feed_settings_page_links(array( 356 'before' => '<li>', 357 'between' => "</li>\n<li>", 358 'after' => '</li>', 359 'subscription' => $this->link, 360 )); 361 362 if ($this->for_feed_settings()) : 363 ?> 364 <li><input class="button" type="submit" name="update" value="Update Now" /></li> 365 <?php 366 endif; 367 ?> 368 </ul> 369 </div> 370 <?php 371 } /* FeedWordPressAdminPage::display_feed_select_dropdown() */ 372 373 public function display_sheet_header ($pagename = 'Syndication', $all = false) { 374 global $fwp_path; 375 ?> 376 <div class="icon32"><img src="<?php print esc_html( plugins_url( '/'.$fwp_path.'/feedwordpress.png') ); ?>" alt="" /></div> 377 <h2><?php print esc_html(__($pagename.($all ? '' : ' Settings'))); ?><?php if ($this->for_feed_settings()) : ?>: <?php echo esc_html($this->link->name(/*from feed=*/ false)); ?><?php endif; ?></h2> 378 <?php 379 } 380 381 public function display_update_notice_if_updated ($pagename = 'Syndication', $mesg = NULL) { 382 if (!is_null($mesg)) : 383 $this->mesg = $mesg; 384 endif; 385 386 if ($this->updated) : 387 if ($this->updated === true) : 388 $this->mesg = $pagename . ' settings updated.'; 389 else : 390 $this->mesg = $this->updated; 391 endif; 392 endif; 393 394 if (!is_null($this->mesg)) : 395 ?> 396 <div class="updated"> 397 <p><?php print esc_html($this->mesg); ?></p> 398 </div> 399 <?php 400 endif; 401 } /* FeedWordPressAdminPage::display_update_notice_if_updated() */ 402 403 public function display_settings_scope_message () { 404 if ($this->for_feed_settings()) : 405 ?> 406 <p>These settings only affect posts syndicated from 407 <strong><?php echo esc_html($this->link->link->link_name); ?></strong>.</p> 408 <?php 409 else : 410 ?> 411 <p>These settings affect posts syndicated from any feed unless they are overridden 412 by settings for that specific feed.</p> 413 <?php 414 endif; 415 } /* FeedWordPressAdminPage::display_settings_scope_message () */ 416 417 /*static*/ function has_link () { return true; } 418 419 public function form_action ($filename = NULL) { 420 global $fwp_path; 421 422 if (is_null($filename)) : 423 $filename = basename($this->filename); 424 endif; 425 return $this->admin_page_href($filename); 426 } /* FeedWordPressAdminPage::form_action () */ 427 428 public function update_message () { 429 return $this->mesg; 430 } 431 432 public function display () { 433 global $fwp_post; 434 435 if (FeedWordPress::needs_upgrade()) : 436 fwp_upgrade_page(); 437 return; 438 endif; 439 440 FeedWordPressCompatibility::validate_http_request(/*action=*/ $this->dispatch, /*capability=*/ 'manage_links'); 441 442 //////////////////////////////////////////////// 443 // Process POST request, if any //////////////// 444 //////////////////////////////////////////////// 445 if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') : 446 $this->accept_POST($fwp_post); 447 else : 448 $this->updated = false; 449 endif; 450 451 //////////////////////////////////////////////// 452 // Prepare settings page /////////////////////// 453 //////////////////////////////////////////////// 454 455 $this->display_update_notice_if_updated( 456 $this->pagename('settings-update'), 457 $this->update_message() 458 ); 459 460 $this->open_sheet($this->pagename('open-sheet')); 461 ?> 462 <div id="post-body"> 463 <?php 464 foreach ($this->boxes_by_methods as $method => $row) : 465 if (is_array($row)) : 466 $id = $row['id']; 467 $title = $row['title']; 468 else : 469 $id = 'feedwordpress_'.$method; 470 $title = $row; 471 endif; 472 473 add_meta_box( 474 /*id=*/ $id, 475 /*title=*/ $title, 476 /*callback=*/ array($this, $method), 477 /*page=*/ $this->meta_box_context(), 478 /*context=*/ $this->meta_box_context() 479 ); 480 endforeach; 481 do_action($this->dispatch.'_meta_boxes', $this); 482 ?> 483 <div class="metabox-holder"> 484 <?php 485 fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this); 486 ?> 487 </div> <!-- class="metabox-holder" --> 488 </div> <!-- id="post-body" --> 489 <?php $this->close_sheet(); ?> 490 <?php 491 } 492 493 public function open_sheet ($header) { 494 // Set up prepatory AJAX stuff 495 ?> 496 <script type="text/javascript"> 497 <?php 498 $this->ajax_interface_js(); 499 ?> 500 </script> 501 502 <?php 503 add_action( 504 FeedWordPressCompatibility::bottom_script_hook($this->filename), 505 /*callback=*/ array($this, 'fix_toggles'), 506 /*priority=*/ 10000 507 ); 508 FeedWordPressSettingsUI::ajax_nonce_fields(); 509 510 ?> 511 <div class="wrap feedwordpress-admin" id="feedwordpress-admin-<?php print $this->pageslug(); ?>"> 512 <?php 513 if (!is_null($header)) : 514 $this->display_sheet_header($header); 515 endif; 516 517 if (!is_null($this->dispatch)) : 518 ?> 519 <form action="<?php print $this->form_action(); ?>" method="post"> 520 <div><?php 521 FeedWordPressCompatibility::stamp_nonce($this->dispatch); 522 $this->stamp_link_id(); 523 ?></div> 524 <?php 525 endif; 526 527 if ($this->has_link()) : 528 $this->display_settings_scope_message(); 529 endif; 530 531 ?><div class="tablenav"><?php 532 if (!is_null($this->dispatch)) : 533 ?><div class="alignright"><?php 534 $this->save_button(); 535 ?></div><?php 536 endif; 537 538 if ($this->has_link()) : 539 $this->display_feed_select_dropdown(); 540 endif; 541 ?> 542 </div> 543 544 <div id="poststuff"> 545 <?php 546 } /* FeedWordPressAdminPage::open_sheet () */ 547 548 public function close_sheet () { 549 ?> 550 551 </div> <!-- id="poststuff" --> 552 <?php 553 if (!is_null($this->dispatch)) : 554 $this->save_button(); 555 print "</form>\n"; 556 endif; 557 ?> 558 </div> <!-- class="wrap" --> 559 560 <?php 561 } /* FeedWordPressAdminPage::close_sheet () */ 562 563 public function setting_radio_control ($localName, $globalName, $options, $params = array()) { 564 global $fwp_path; 565 566 if (isset($params['filename'])) : $filename = $params['filename']; 567 else : $filename = basename($this->filename); 568 endif; 569 570 if (isset($params['site-wide-url'])) : $href = $params['site-wide-url']; 571 else : $href = $this->admin_page_href($filename); 572 endif; 573 574 if (isset($params['setting-default'])) : $settingDefault = $params['setting-default']; 575 else : $settingDefault = NULL; 576 endif; 577 578 if (isset($params['global-setting-default'])) : $globalSettingDefault = $params['global-setting-default']; 579 else : $globalSettingDefault = $settingDefault; 580 endif; 581 582 $globalSetting = get_option('feedwordpress_'.$globalName, $globalSettingDefault); 583 if ($this->for_feed_settings()) : 584 $setting = $this->link->setting($localName, NULL, $settingDefault); 585 else : 586 $setting = $globalSetting; 587 endif; 588 589 if (isset($params['offer-site-wide'])) : $offerSiteWide = $params['offer-site-wide']; 590 else : $offerSiteWide = $this->for_feed_settings(); 591 endif; 592 593 // This allows us to provide an alternative set of human-readable 594 // labels for each potential value. For use in Currently: line. 595 if (isset($params['labels'])) : $labels = $params['labels']; 596 elseif (is_callable($options)) : $labels = NULL; 597 else : $labels = $options; 598 endif; 599 600 if (isset($params['input-name'])) : $inputName = $params['input-name']; 601 else : $inputName = $globalName; 602 endif; 603 604 if (isset($params['default-input-id'])) : $defaultInputId = $params['default-input-id']; 605 else : $defaultInputId = NULL; 606 endif; 607 608 if (isset($params['default-input-id-no'])) : $defaultInputIdNo = $params['default-input-id-no']; 609 elseif (!is_null($defaultInputId)) : $defaultInputIdNo = $defaultInputId.'-no'; 610 else : $defaultInputIdNo = NULL; 611 endif; 612 613 // This allows us to either include the site-default setting as 614 // one of the options within the radio box, or else as a simple 615 // yes/no toggle that controls whether or not to check another 616 // set of inputs. 617 if (isset($params['default-input-name'])) : $defaultInputName = $params['default-input-name']; 618 else : $defaultInputName = $inputName; 619 endif; 620 621 if ($defaultInputName != $inputName) : 622 $defaultInputValue = 'yes'; 623 else : 624 $defaultInputValue = ( 625 isset($params['default-input-value']) 626 ? $params['default-input-value'] 627 : 'site-default' 628 ); 629 endif; 630 631 $settingDefaulted = (is_null($setting) or ($settingDefault === $setting)); 632 633 if (!is_callable($options)) : 634 $checked = array(); 635 if ($settingDefaulted) : 636 $checked[$defaultInputValue] = ' checked="checked"'; 637 endif; 638 639 foreach ($options as $value => $label) : 640 if ($setting == $value) : 641 $checked[$value] = ' checked="checked"'; 642 else : 643 $checked[$value] = ''; 644 endif; 645 endforeach; 646 endif; 647 648 $defaulted = array(); 649 if ($defaultInputName != $inputName) : 650 $defaulted['yes'] = ($settingDefaulted ? ' checked="checked"' : ''); 651 $defaulted['no'] = ($settingDefaulted ? '' : ' checked="checked"'); 652 else : 653 $defaulted['yes'] = (isset($checked[$defaultInputValue]) ? $checked[$defaultInputValue] : ''); 654 endif; 655 656 if (isset($params['defaulted'])) : 657 $defaulted['yes'] = ($params['defaulted'] ? ' checked="checked"' : ''); 658 $defaulted['no'] = ($params['defaulted'] ? '' : ' checked="checked"'); 659 endif; 660 661 if ($offerSiteWide) : 662 ?> 663 <table class="twofer"> 664 <tbody> 665 <tr><td class="equals first inactive"> 666 <ul class="options"> 667 <li><label><input type="radio" 668 name="<?php print $defaultInputName; ?>" 669 value="<?php print $defaultInputValue; ?>" 670 <?php if (!is_null($defaultInputId)) : ?>id="<?php print $defaultInputId; ?>" <?php endif; ?> 671 <?php print $defaulted['yes']; ?> /> 672 Use the site-wide setting</label> 673 <span class="current-setting">Currently: 674 <strong><?php if (is_callable($labels)) : 675 print call_user_func($labels, $globalSetting, $defaulted, $params); 676 elseif (is_null($labels)) : 677 print $globalSetting; 678 else : 679 print $labels[$globalSetting]; 680 endif; ?></strong> (<a href="<?php print $href; ?>">change</a>)</span></li> 681 </ul></td> 682 683 <td class="equals second inactive"> 684 <?php if ($defaultInputName != $inputName) : ?> 685 <ul class="options"> 686 <li><label><input type="radio" 687 name="<?php print $defaultInputName; ?>" 688 value="no" 689 <?php if (!is_null($defaultInputIdNo)) : ?>id="<?php print $defaultInputIdNo; ?>" <?php endif; ?> 690 <?php print $defaulted['no']; ?> /> 691 <?php _e('Do something different with this feed.'); ?></label> 692 <?php endif; 693 endif; 694 695 // Let's spit out the controls here. 696 if (is_callable($options)) : 697 // Method call to print out options list 698 call_user_func($options, $setting, $defaulted, $params); 699 else : 700 ?> 701 <ul class="options"> 702 <?php foreach ($options as $value => $label) : ?> 703 <li><label><input type="radio" name="<?php print $inputName; ?>" 704 value="<?php print $value; ?>" 705 <?php print $checked[$value]; ?> /> 706 <?php print $label; ?></label></li> 707 <?php endforeach; ?> 708 </ul> <!-- class="options" --> 709 <?php 710 endif; 711 712 if ($offerSiteWide) : 713 if ($defaultInputName != $inputName) : 714 // Close the <li> and <ul class="options"> we opened above 715 ?> 716 </li> 717 </ul> <!-- class="options" --> 718 <?php 719 endif; 720 721 // Close off the twofer table that we opened up above. 722 ?> 723 </td></tr> 724 </tbody> 725 </table> 726 <?php 727 endif; 728 } /* FeedWordPressAdminPage::setting_radio_control () */ 729 730 public function save_button ($caption = NULL) { 731 if (is_null($caption)) : $caption = __('Save Changes'); endif; 732 ?> 733 <p class="submit"> 734 <input class="button-primary" type="submit" name="save" value="<?php print $caption; ?>" /> 735 </p> 736 <?php 737 } 738 } /* class FeedWordPressAdminPage */ 2 /** 3 * admin-ui.php: This is kind of a junk pile of utility functions mostly created to smooth 4 * out interactions to make things show up, or behave correctly, within the WordPress admin 5 * settings interface. Major chunks of this code that deal with making it easy for FWP, 6 * add-on modules, etc. to create new settings panels have since been hived off into class 7 * FeedWordPressAdminPage. Many of the functions that remain here were created to handle 8 * compatibility across multiple, sometimes very old, versions of WordPress, many of which 9 * are no longer supported anymore. It's likely that some of these functions will be 10 * re-evaluated, re-organized, deprecated, or clipped out in the next few versions. 11 * -cj 2017-10-27 12 */ 13 14 $dir = dirname(__FILE__); 15 require_once("${dir}/feedwordpressadminpage.class.php"); 16 require_once("${dir}/feedwordpresssettingsui.class.php"); 739 17 740 18 function fwp_update_set_results_message ($delta, $joiner = ';') { … … 762 40 </p> 763 41 </div> 764 <?php765 }766 767 function fwp_option_box_opener ($legend, $id, $class = "stuffbox") {768 ?>769 <div id="<?php print $id; ?>" class="<?php print $class; ?>">770 <h3><?php print htmlspecialchars($legend); ?></h3>771 <div class="inside">772 <?php773 }774 775 function fwp_option_box_closer () {776 ?>777 </div> <!-- class="inside" -->778 </div> <!-- class="stuffbox" -->779 42 <?php 780 43 } … … 962 225 } 963 226 964 class FeedWordPressSettingsUI {965 static function is_admin () {966 global $fwp_path;967 968 $admin_page = false; // Innocent until proven guilty969 if (isset($_REQUEST['page'])) :970 $admin_page = (971 is_admin()972 and preg_match("|^{$fwp_path}/|", $_REQUEST['page'])973 );974 endif;975 return $admin_page;976 }977 978 static function admin_scripts () {979 global $fwp_path;980 981 wp_enqueue_script('post'); // for magic tag and category boxes982 wp_enqueue_script('admin-forms'); // for checkbox selection983 984 wp_register_script('feedwordpress-elements', plugins_url('/' . $fwp_path . '/feedwordpress-elements.js') );985 wp_enqueue_script('feedwordpress-elements');986 }987 988 static function admin_styles () {989 ?>990 <style type="text/css">991 #feedwordpress-admin-feeds .link-rss-params-remove .x, .feedwordpress-admin .remove-it .x {992 background: url(<?php print admin_url('images/xit.gif') ?>) no-repeat scroll 0 0 transparent;993 }994 995 #feedwordpress-admin-feeds .link-rss-params-remove:hover .x, .feedwordpress-admin .remove-it:hover .x {996 background: url(<?php print admin_url('images/xit.gif') ?>) no-repeat scroll -10px 0 transparent;997 }998 999 .fwpfs {1000 background-image: url(<?php print admin_url('images/fav.png'); ?>);1001 background-repeat: repeat-x;1002 background-position: left center;1003 background-attachment: scroll;1004 }1005 .fwpfs.slide-down {1006 background-image:url(<?php print admin_url('images/fav-top.png'); ?>);1007 background-position:0 top;1008 background-repeat:repeat-x;1009 }1010 1011 .update-results {1012 max-width: 100%;1013 overflow: auto;1014 }1015 1016 </style>1017 <?php1018 } /* FeedWordPressSettingsUI::admin_styles () */1019 1020 static function ajax_nonce_fields () {1021 if (function_exists('wp_nonce_field')) :1022 echo "<form style='display: none' method='get' action=''>\n<p>\n";1023 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );1024 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );1025 echo "</p>\n</form>\n";1026 endif;1027 } /* FeedWordPressSettingsUI::ajax_nonce_fields () */1028 1029 static function fix_toggles_js ($context) {1030 ?>1031 <script type="text/javascript">1032 jQuery(document).ready( function($) {1033 // In case someone got here first...1034 $('.postbox h3, .postbox .handlediv').unbind('click');1035 $('.postbox h3 a').unbind('click');1036 $('.hide-postbox-tog').unbind('click');1037 $('.columns-prefs input[type="radio"]').unbind('click');1038 $('.meta-box-sortables').sortable('destroy');1039 1040 postboxes.add_postbox_toggles('<?php print $context; ?>');1041 } );1042 </script>1043 <?php1044 } /* FeedWordPressSettingsUI::fix_toggles_js () */1045 1046 static function magic_input_tip_js ($id) {1047 if (!preg_match('/^[.#]/', $id)) :1048 $id = '#'.$id;1049 endif;1050 ?>1051 <script type="text/javascript">1052 jQuery(document).ready( function () {1053 var inputBox = jQuery("<?php print $id; ?>");1054 var boxEl = inputBox.get(0);1055 if (boxEl.value==boxEl.defaultValue) { inputBox.addClass('form-input-tip'); }1056 inputBox.focus(function() {1057 if ( this.value == this.defaultValue )1058 jQuery(this).val( '' ).removeClass( 'form-input-tip' );1059 });1060 inputBox.blur(function() {1061 if ( this.value == '' )1062 jQuery(this).val( this.defaultValue ).addClass( 'form-input-tip' );1063 });1064 } );1065 </script>1066 <?php1067 } /* FeedWordPressSettingsUI::magic_input_tip_js () */1068 } /* class FeedWordPressSettingsUI */1069 1070 227 function fwp_insert_new_user ($newuser_name) { 1071 228 global $wpdb; … … 1091 248 } /* fwp_insert_new_user () */ 1092 249 1093 /**1094 * fwp_add_meta_box1095 *1096 * This function is no longer necessary, since no versions of WordPress that FWP1097 * still supports lack add_meta_box(). But I've left it in place for the time1098 * being for add-on modules that may have used it in setting up their UI.1099 */1100 function fwp_add_meta_box ($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args = null) {1101 return add_meta_box($id, $title, $callback, $page, $context, $priority, $callback_args);1102 } /* function fwp_add_meta_box () */1103 1104 function fwp_do_meta_boxes($page, $context, $object) {1105 $ret = do_meta_boxes($page, $context, $object);1106 1107 // Avoid JavaScript error from WordPress 2.5 bug1108 ?>1109 <div style="display: none">1110 <div id="tags-input"></div> <!-- avoid JS error from WP 2.5 bug -->1111 </div>1112 <?php1113 return $ret;1114 } /* function fwp_do_meta_boxes() */1115 1116 function fwp_remove_meta_box($id, $page, $context) {1117 return remove_meta_box($id, $page, $context);1118 } /* function fwp_remove_meta_box() */1119 1120 250 function fwp_syndication_manage_page_links_table_rows ($links, $page, $visible = 'Y') { 1121 251 252 $fwp_syndicated_sources_columns = array(__('Name'), __('Feed'), __('Updated')); 253 1122 254 $subscribed = ('Y' == strtoupper($visible)); 1123 255 if ($subscribed or (count($links) > 0)) : … … 1127 259 <tr> 1128 260 <th class="check-column" scope="col"><input type="checkbox" /></th> 1129 <th scope="col"><?php _e('Name'); ?></th>1130 <th scope="col"><?php _e('Feed'); ?></th>1131 <th scope="col"><?php _e('Updated'); ?></th>1132 </tr>1133 </thead>1134 1135 <tbody>1136 261 <?php 262 foreach ($fwp_syndicated_sources_columns as $col) : 263 print "\t<th scope='col'>${col}</th>\n"; 264 endforeach; 265 print "</tr>\n"; 266 print "</thead>\n"; 267 print "\n"; 268 print "<tbody>\n"; 269 1137 270 $alt_row = true; 1138 271 if (count($links) > 0): … … 1150 283 // Prep: get last error timestamp, if any 1151 284 $fileSizeLines = array(); 285 $feed_type = $sLink->get_feed_type(); 1152 286 if (is_null($sLink->setting('update/error'))) : 1153 287 $errorsSince = ''; 1154 288 if (!is_null($sLink->setting('link/item count'))) : 1155 289 $N = $sLink->setting('link/item count'); 1156 $fileSizeLines[] = sprintf((($N==1) ? __('%d item') : __('%d items')), $N) ;290 $fileSizeLines[] = sprintf((($N==1) ? __('%d item') : __('%d items')), $N) . ", " . $feed_type; 1157 291 endif; 1158 292 … … 1256 390 </td> 1257 391 <?php if (strlen($link->link_rss) > 0): ?> 1258 <td>< a href="<?php echo esc_html($link->link_rss); ?>"><?php echo esc_html(feedwordpress_display_url($link->link_rss, 32)); ?></a></td>392 <td><div><a href="<?php echo esc_html($link->link_rss); ?>"><?php echo esc_html(feedwordpress_display_url($link->link_rss, 32)); ?></a></div></td> 1259 393 <?php else: ?> 1260 394 <td class="feed-missing"><p><strong>no feed assigned</strong></p></td> … … 1264 398 <input type="submit" class="button" name="update_uri[<?php print esc_html($link->link_rss); ?>]" value="<?php _e('Update Now'); ?>" /> 1265 399 </div> 1266 <?php print $lastUpdated; ?> 1267 <?php print $fileSize; ?> 1268 <?php print $errorsSince; ?> 1269 <?php print $nextUpdate; ?> 400 <?php 401 print $lastUpdated; 402 print $fileSize; 403 print $errorsSince; 404 print $nextUpdate; 405 ?> 1270 406 </td> 1271 407 </tr> -
TabularUnified feedwordpress/trunk/diagnostics-page.php ¶
r1551908 r2229752 16 16 17 17 function display () { 18 global $wpdb, $wp_db_version, $fwp_path;19 global $fwp_post;20 21 18 if (FeedWordPress::needs_upgrade()) : 22 19 fwp_upgrade_page(); … … 28 25 29 26 if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') : 30 $this->accept_POST($ fwp_post);31 do_action('feedwordpress_admin_page_diagnostics_save', $ fwp_post, $this);27 $this->accept_POST($_POST); 28 do_action('feedwordpress_admin_page_diagnostics_save', $_POST, $this); 32 29 endif; 33 30 … … 62 59 <div class="metabox-holder"> 63 60 <?php 64 fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);61 do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this); 65 62 ?> 66 63 </div> <!-- class="metabox-holder" --> -
TabularUnified feedwordpress/trunk/feeds-page.php ¶
r1729270 r2229752 162 162 ); 163 163 } /* for */ 164 165 // Let's make the interface for the PAUSE/RESUME a bit better 166 jQuery('<tr id="reveal-pause-resume"><th></th><td><button id="pause-resume-reveal-button">— PAUSE or RESUME UPDATES —</button></td></tr>').insertBefore('#pause-resume'); 167 jQuery('#pause-resume').hide(); 168 jQuery('#pause-resume-reveal-button').click(function(ev) { 169 ev.preventDefault(); 170 171 jQuery('#pause-resume').toggle(); 172 return false; 173 }); 174 164 175 } ); 165 176 … … 187 198 188 199 <tr> 189 <th scope="row">Update s:</th>200 <th scope="row">Update Method:</th> 190 201 <td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');"> 191 202 <option value="shutdown"<?php echo ($automatic_updates=='shutdown')?' selected="selected"':''; ?>>automatically check for updates after pages load</option> … … 199 210 // or to wget. If everything fails or shell_exec() isn't available, then just make 200 211 // up something for the sake of example. 212 $curlOrWgetPath = NULL; 213 201 214 $shellExecAvailable = (is_callable('shell_exec') && false === stripos(ini_get('disable_functions'), 'shell_exec')); 202 215 203 216 if ($shellExecAvailable) : 204 $ path = `which curl`; $opts = '--silent %s';205 endif; 206 207 if ($shellExecAvailable and (is_null($ path) or strlen(trim($path))==0)) :208 $ path = `which wget`; $opts = '-q -O - %s';209 endif; 210 211 if (is_null($ path) or strlen(trim($path))==0) :212 $ path = '/usr/bin/curl'; $opts = '--silent %s';213 endif; 214 215 $ path = preg_replace('/\n+$/', '', $path);216 217 $cmdline = $ path . ' ' . sprintf($opts, get_bloginfo('url').'?update_feedwordpress=1');217 $curlOrWgetPath = `which curl`; $opts = '--silent %s'; 218 endif; 219 220 if ($shellExecAvailable and (is_null($curlOrWgetPath) or strlen(trim($curlOrWgetPath))==0)) : 221 $curlOrWgetPath = `which wget`; $opts = '-q -O - %s'; 222 endif; 223 224 if (is_null($curlOrWgetPath) or strlen(trim($curlOrWgetPath))==0) : 225 $curlOrWgetPath = '/usr/bin/curl'; $opts = '--silent %s'; 226 endif; 227 228 $curlOrWgetPath = preg_replace('/\n+$/', '', $curlOrWgetPath); 229 230 $cmdline = $curlOrWgetPath . ' ' . sprintf($opts, get_bloginfo('url').'?update_feedwordpress=1'); 218 231 219 232 ?>If you want to use a cron job, … … 268 281 269 282 <?php endif; ?> 270 283 284 <tr id="pause-resume"> 285 <th scope="row"><?php print __('Pause/Resume:'); ?></th> 286 <td><?php 287 $this->setting_radio_control( 288 'update/pause', 'update_pause', 289 /*options=*/ array( 290 'no' => '<strong>UPDATE:</strong> import new posts as normal', 291 'yes' => '<strong>PAUSE:</strong> do not import new posts until I unpause updates', 292 ), 293 /*params=*/ array( 294 'setting-default' => NULL, 295 'global-setting-default' => 'no', 296 'default-input-value' => 'default', 297 ) 298 ); 299 ?></td> 300 </tr> 301 271 302 <tr> 272 303 <th scope="row"><?php print __('Update scheduling:') ?></th> … … 507 538 508 539 $params = array(); 509 if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_USES_ARGS_TAXONOMY)) : 510 $params['taxonomy'] = 'link_category'; 511 else : 512 $params['type'] = 'link'; 513 endif; 540 $params['taxonomy'] = 'link_category'; 514 541 $params['hide_empty'] = false; 515 542 $results = get_categories($params); … … 1216 1243 endif; 1217 1244 1245 if (isset($post['update_pause'])) : 1246 $this->update_setting('update/pause', $post['update_pause']); 1247 endif; 1248 1218 1249 if (isset($post['fetch_timeout'])) : 1219 1250 if (isset($post['fetch_timeout_default']) and $post['fetch_timeout_default']=='yes') : -
TabularUnified feedwordpress/trunk/feedwordpress.php ¶
r1749912 r2229752 4 4 Plugin URI: http://feedwordpress.radgeek.com/ 5 5 Description: simple and flexible Atom/RSS syndication for WordPress 6 Version: 20 17.10206 Version: 2020.0118 7 7 Author: C. Johnson 8 8 Author URI: https://feedwordpress.radgeek.com/contact/ … … 12 12 /** 13 13 * @package FeedWordPress 14 * @version 20 17.102014 * @version 2020.0118 15 15 */ 16 16 17 # This uses code derived from:17 # This plugin uses code derived from: 18 18 # - wp-rss-aggregate.php by Kellan Elliot-McCrea <kellan@protest.net> 19 19 # - SimplePie feed parser by Ryan Parman, Geoffrey Sneddon, Ryan McCue, et al. … … 21 21 # - Ultra-Liberal Feed Finder by Mark Pilgrim <mark@diveintomark.org> 22 22 # - WordPress Blog Tool and Publishing Platform <http://wordpress.org/> 23 # - Github contributors @Flynsarmy, @BandonRandon, @david-robinson-practiceweb, 24 # @daidais, @thegreatmichael, @stedaniels, @alexiskulash, @quassy, @zoul0813, 25 # @timmmmyboy, @vobornik, and @inanimatt 23 26 # according to the terms of the GNU General Public License. 24 # 25 # INSTALLATION: see readme.txt or <http://feedwordpress.radgeek.com/install> 26 # 27 # USAGE: once FeedWordPress is installed, you manage just about everything from 28 # the WordPress Dashboard, under the Syndication menu. To keep fresh content 29 # coming in as it becomes available, you'll have to either check for updates 30 # manually, or set up one of the automatically-scheduled update methods. See 31 # <http://feedwordpress.radgeek.com/wiki/quick-start/> for some details. 32 33 # -- Don't change these unless you know what you're doing... 34 35 define ('FEEDWORDPRESS_VERSION', '2017.1020'); 27 28 #################################################################################### 29 ## CONSTANTS & DEFAULTS ############################################################ 30 #################################################################################### 31 32 define ('FEEDWORDPRESS_VERSION', '2020.0118'); 36 33 define ('FEEDWORDPRESS_AUTHOR_CONTACT', 'http://feedwordpress.radgeek.com/contact'); 37 34 … … 42 39 define('FEEDWORDPRESS_BLEG_PAYPAL', '22PAJZZCK5Z3W'); 43 40 44 define('FEEDWORDPRESS_BOILERPLATE_DEFAULT_HOOK_ORDER', 11000); // at the tail end of the filtering process45 46 41 // Defaults 47 42 define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors'); 48 43 define ('DEFAULT_UPDATE_PERIOD', 60); // value in minutes 44 define ('FEEDWORDPRESS_DEFAULT_CHECKIN_INTERVAL', DEFAULT_UPDATE_PERIOD/10); 49 45 50 46 if (isset($_REQUEST['feedwordpress_debug'])) : … … 67 63 define ('FEEDWORDPRESS_FRESHNESS_INTERVAL', 10*60); // Every ten minutes 68 64 69 define ('FWP_SCHEMA_HAS_USERMETA', 2966); 70 define ('FWP_SCHEMA_USES_ARGS_TAXONOMY', 12694); // Revision # for using $args['taxonomy'] to get link categories 71 define ('FWP_SCHEMA_30', 12694); // Database schema # for WP 3.0 65 define('FEEDWORDPRESS_BOILERPLATE_DEFAULT_HOOK_ORDER', 11000); // at the tail end of the filtering process 72 66 73 67 if (FEEDWORDPRESS_DEBUG) : … … 92 86 endif; 93 87 94 // Use our the cache settings that we want. 95 add_filter('wp_feed_cache_transient_lifetime', array('FeedWordPress', 'cache_lifetime')); 88 #################################################################################### 89 ## CORE DEPENDENCIES & PLUGIN MODULES ############################################## 90 #################################################################################### 96 91 97 92 // Dependencies: modules packaged with WordPress core … … 130 125 $dir = dirname(__FILE__); 131 126 require_once("${dir}/externals/myphp/myphp.class.php"); 127 require_once("${dir}/feedwordpressadminpage.class.php"); 128 require_once("${dir}/feedwordpresssettingsui.class.php"); 129 require_once("${dir}/feedwordpressdiagnostic.class.php"); 132 130 require_once("${dir}/admin-ui.php"); 131 require_once("${dir}/template-functions.php"); 133 132 require_once("${dir}/feedwordpresssyndicationpage.class.php"); 134 133 require_once("${dir}/compatability.php"); // Legacy API … … 147 146 require_once("${dir}/feedwordpresslocalpost.class.php"); 148 147 149 // Magic quotes are just about the stupidest thing ever. 148 #################################################################################### 149 ## GLOBAL PARAMETERS ############################################################### 150 #################################################################################### 151 152 // $fwp_post used to be a global variable used to make it easier to cope 153 // with the frustrating sometime presence of "Magic Quotes" in earlier 154 // versions of PHP (<http://php.net/manual/en/security.magicquotes.php>). 155 // Magic quotes were DEPRECATED as of PHP 5.3.0, and REMOVED as of PHP 156 // 5.4.0, so for the time being $fwp_post just gets a copy of $_POST. 157 global $fwp_post; 158 150 159 if (is_array($_POST)) : 151 160 $fwp_post = $_POST; 152 if (get_magic_quotes_gpc()) : 153 $fwp_post = stripslashes_deep($fwp_post); 154 endif; 161 else: 162 $fwp_post = null; 155 163 endif; 156 164 … … 167 175 $fwp_path = 'feedwordpress'; 168 176 endif; 177 178 #################################################################################### 179 ## FEEDWORDPRESS: INITIALIZE OBJECT AND FILTERS #################################### 180 #################################################################################### 169 181 170 182 $feedwordpress = new FeedWordPress; … … 282 294 add_action('all_admin_notices', array($feedwordpress, 'all_admin_notices')); 283 295 296 // Use our the cache settings that we want. 297 add_filter('wp_feed_cache_transient_lifetime', array('FeedWordPress', 'cache_lifetime')); 298 299 284 300 else : 285 301 # Hook in the menus, which will just point to the upgrade interface … … 287 303 endif; // if (!FeedWordPress::needs_upgrade()) 288 304 305 register_deactivation_hook(__FILE__, 'feedwordpress_deactivate'); 306 function feedwordpress_deactivate () { 307 wp_clear_scheduled_hook('fwp_scheduled_update_checkin'); 308 } /* feedwordpress_deactivate () */ 309 289 310 ################################################################################ 290 311 ## LOGGING FUNCTIONS: log status updates to error_log if you want it ########### 291 312 ################################################################################ 292 293 class FeedWordPressDiagnostic {294 public static function feed_error ($error, $old, $link) {295 $wpError = $error['object'];296 $url = $link->uri();297 298 // check for effects of an effective-url filter299 $effectiveUrl = $link->uri(array('fetch' => true));300 if ($url != $effectiveUrl) : $url .= ' | ' . $effectiveUrl; endif;301 302 $mesgs = $wpError->get_error_messages();303 foreach ($mesgs as $mesg) :304 $mesg = esc_html($mesg);305 FeedWordPress::diagnostic(306 'updated_feeds:errors',307 "Feed Error: [${url}] update returned error: $mesg"308 );309 310 $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2);311 $span = ($error['ts'] - $error['since']);312 313 if ($span >= ($hours * 60 * 60)) :314 $since = date('r', $error['since']);315 $mostRecent = date('r', $error['ts']);316 FeedWordPress::diagnostic(317 'updated_feeds:errors:persistent',318 "Feed Update Error: [${url}] returning errors"319 ." since ${since}:<br/><code>$mesg</code>",320 $url, $error['since'], $error['ts']321 );322 endif;323 endforeach;324 }325 326 function admin_emails ($id = '') {327 $users = get_users_of_blog($id);328 $recipients = array();329 foreach ($users as $user) :330 $user_id = (isset($user->user_id) ? $user->user_id : $user->ID);331 $dude = new WP_User($user_id);332 if ($dude->has_cap('administrator')) :333 if ($dude->user_email) :334 $recipients[] = $dude->user_email;335 endif;336 endif;337 endforeach;338 return $recipients;339 }340 } /* class FeedWordPressDiagnostic */341 313 342 314 function debug_out_human_readable_bytes ($quantity) { … … 352 324 353 325 function debug_out_feedwordpress_footer () { 354 if (FeedWordPress ::diagnostic_on('memory_usage')) :326 if (FeedWordPressDiagnostic::is_on('memory_usage')) : 355 327 if (function_exists('memory_get_usage')) : 356 328 FeedWordPress::diagnostic ('memory_usage', "Memory: Current usage: ".debug_out_human_readable_bytes(memory_get_usage())); … … 361 333 endif; 362 334 } /* debug_out_feedwordpress_footer() */ 363 364 ################################################################################365 ## TEMPLATE API: functions to make your templates syndication-aware ############366 ################################################################################367 368 /**369 * is_syndicated: Tests whether the current post in a Loop context, or a post370 * given by ID number, was syndicated by FeedWordPress. Useful for templates371 * to determine whether or not to retrieve syndication-related meta-data in372 * displaying a post.373 *374 * @param int $id The post to check for syndicated status. Defaults to the current post in a Loop context.375 * @return bool TRUE if the post's meta-data indicates it was syndicated; FALSE otherwise376 */377 function is_syndicated ($id = NULL) {378 $p = new FeedWordPressLocalPost($id);379 return $p->is_syndicated();380 } /* function is_syndicated() */381 382 function feedwordpress_display_url ($url, $before = 60, $after = 0) {383 $bits = parse_url($url);384 385 // Strip out crufty subdomains386 if (isset($bits['host'])) :387 $bits['host'] = preg_replace('/^www[0-9]*\./i', '', $bits['host']);388 endif;389 390 // Reassemble bit-by-bit with minimum of crufty elements391 $url = (isset($bits['user'])?$bits['user'].'@':'')392 .(isset($bits['host'])?$bits['host']:'')393 .(isset($bits['path'])?$bits['path']:'')394 .(isset($uri_bits['port'])?':'.$uri_bits['port']:'')395 .(isset($bits['query'])?'?'.$bits['query']:'');396 397 if (strlen($url) > ($before+$after)) :398 $url = substr($url, 0, $before).'.'.substr($url, 0 - $after, $after);399 endif;400 401 return $url;402 } /* feedwordpress_display_url () */403 404 function get_syndication_source_property ($original, $id, $local, $remote = NULL) {405 $p = new FeedWordPressLocalPost($id);406 return $p->meta($local, array("unproxy" => $original, "unproxied setting" => $remote));407 } /* function get_syndication_source_property () */408 409 function get_syndication_source_link ($original = NULL, $id = NULL) {410 $p = new FeedWordPressLocalPost($id);411 return $p->syndication_source_link($original);412 } /* function get_syndication_source_link() */413 414 function the_syndication_source_link ($original = NULL, $id = NULL) {415 echo get_syndication_source_link($original, $id);416 } /* function the_syndication_source_link() */417 418 function get_syndication_source ($original = NULL, $id = NULL) {419 $p = new FeedWordPressLocalPost($id);420 return $p->syndication_source($original);421 } /* function get_syndication_source() */422 423 function the_syndication_source ($original = NULL, $id = NULL) {424 echo get_syndication_source($original, $id);425 } /* function the_syndication_source () */426 427 function get_syndication_feed ($original = NULL, $id = NULL) {428 $p = new FeedWordPressLocalPost($id);429 return $p->syndication_feed($original);430 } /* function get_syndication_feed() */431 432 function the_syndication_feed ($original = NULL, $id = NULL) {433 echo get_syndication_feed($original, $id);434 } /* function the_syndication_feed() */435 436 function get_syndication_feed_guid ($original = NULL, $id = NULL) {437 $p = new FeedWordPressLocalPost($id);438 return $p->syndication_feed_guid($original);439 } /* function get_syndication_feed_guid () */440 441 function the_syndication_feed_guid ($original = NULL, $id = NULL) {442 echo get_syndication_feed_guid($original, $id);443 } /* function the_syndication_feed_guid () */444 445 function get_syndication_feed_id ($id = NULL) {446 $p = new FeedWordPressLocalPost($id);447 return $p->feed_id();448 } /* function get_syndication_feed_id () */449 450 function the_syndication_feed_id ($id = NULL) {451 echo get_syndication_feed_id($id);452 } /* function the_syndication_feed_id () */453 454 function get_syndication_feed_object ($id = NULL) {455 $p = new FeedWordPressLocalPost($id);456 return $p->feed();457 } /* function get_syndication_feed_object() */458 459 function get_feed_meta ($key, $id = NULL) {460 $ret = NULL;461 462 $link = get_syndication_feed_object($id);463 if (is_object($link) and isset($link->settings[$key])) :464 $ret = $link->settings[$key];465 endif;466 return $ret;467 } /* function get_feed_meta() */468 469 function get_syndication_permalink ($id = NULL) {470 $p = new FeedWordPressLocalPost($id);471 return $p->syndication_permalink();472 } /* function get_syndication_permalink () */473 474 function the_syndication_permalink ($id = NULL) {475 echo get_syndication_permalink($id);476 } /* function the_syndication_permalink () */477 478 /**479 * get_local_permalink: returns a string containing the internal permalink480 * for a post (whether syndicated or not) on your local WordPress installation.481 * This may be useful if you want permalinks to point to the original source of482 * an article for most purposes, but want to retrieve a URL for the local483 * representation of the post for one or two limited purposes (for example,484 * linking to a comments page on your local aggregator site).485 *486 * @param $id The numerical ID of the post to get the permalink for. If empty,487 * defaults to the current post in a Loop context.488 * @return string The URL of the local permalink for this post.489 *490 * @uses get_permalink()491 * @global $feedwordpress_the_original_permalink492 *493 * @since 2010.0217494 */495 function get_local_permalink ($id = NULL) {496 global $feedwordpress_the_original_permalink;497 498 // get permalink, and thus activate filter and force global to be filled499 // with original URL.500 $url = get_permalink($id);501 return $feedwordpress_the_original_permalink;502 } /* get_local_permalink() */503 504 /**505 * the_original_permalink: displays the contents of get_original_permalink()506 *507 * @param $id The numerical ID of the post to get the permalink for. If empty,508 * defaults to the current post in a Loop context.509 *510 * @uses get_local_permalinks()511 * @uses apply_filters512 *513 * @since 2010.0217514 */515 function the_local_permalink ($id = NULL) {516 print apply_filters('the_permalink', get_local_permalink($id));517 } /* function the_local_permalink() */518 335 519 336 ################################################################################ … … 863 680 add_filter('user_can_richedit', array($feedwordpress, 'user_can_richedit'), 1000, 1); 864 681 865 if (FeedWordPress ::diagnostic_on('syndicated_posts:static_meta_data')) :682 if (FeedWordPressDiagnostic::is_on('syndicated_posts:static_meta_data')) : 866 683 $inspectPostMeta = new InspectPostMeta; 867 684 endif; … … 883 700 884 701 $frozen_values = get_post_custom_values('_syndication_freeze_updates', $post->ID); 885 $frozen_post = ( count($frozen_values) > 0 and 'yes' == $frozen_values[0]);702 $frozen_post = ($frozen_values !== null and count($frozen_values) > 0 and 'yes' == $frozen_values[0]); 886 703 887 704 if (is_syndicated($post->ID)) : … … 1188 1005 $this->feedurls = array(); 1189 1006 $links = FeedWordPress::syndicated_links(); 1007 1190 1008 if ($links): foreach ($links as $link): 1191 1009 $id = intval($link->link_id); … … 1199 1017 endforeach; endif; 1200 1018 1019 // System-related event hooks 1020 add_filter('cron_schedules', array($this, 'cron_schedules'), 10, 1); 1021 1022 // FeedWordPress-related event hooks 1201 1023 add_filter('feedwordpress_update_complete', array($this, 'process_retirements'), 1000, 1); 1202 1024 1203 1025 $this->httpauth = new FeedWordPressHTTPAuthenticator; 1204 1026 } /* FeedWordPress::__construct () */ … … 1491 1313 // This should never happen. 1492 1314 else : 1493 FeedWordPress ::critical_bug('FeedWordPress::stale::last', $last, __LINE__, __FILE__);1315 FeedWordPressDiagnostic::critical_bug('FeedWordPress::stale::last', $last, __LINE__, __FILE__); 1494 1316 endif; 1495 1317 … … 1714 1536 wp_enqueue_style('dashboard'); 1715 1537 wp_enqueue_style('feedwordpress-elements'); 1716 1717 /*if (function_exists('wp_admin_css')) :1718 wp_admin_css('css/dashboard');1719 endif;*/1720 1538 endif; 1721 1539 … … 1766 1584 } /* FeedWordPress::wp_loaded () */ 1767 1585 1586 /** 1587 * FeedWordPress::cron_schedules(): Filter hook to add WP-Cron schedules 1588 * that plugins like FeedWordPress can use to carry out scheduled events. 1589 * 1590 * @param array $schedules An associative array containing the current set of cron schedules (hourly, daily, etc.) 1591 * @return array The same array, with a new entry ('fwp_checkin_interval') added to the list. 1592 * 1593 * @since 2017.1021 1594 */ 1595 public function cron_schedules ($schedules) { 1596 $interval = FEEDWORDPRESS_DEFAULT_CHECKIN_INTERVAL*60 /*sec/min*/; 1597 1598 // add 'fwp_checkin_interval' to the existing set 1599 $schedules['fwp_checkin_interval'] = array( 1600 'interval' => $interval, 1601 'display' => 'FeedWordPress update schedule check-in', 1602 ); 1603 1604 return $schedules; 1605 } /* FeedWordPress::cron_schedules () */ 1606 1768 1607 public function fwp_feeds () { 1769 1608 $feeds = array(); … … 2497 2336 2498 2337 # Internal debugging functions 2499 static function critical_bug ($varname, $var, $line, $file = NULL) {2500 global $wp_version;2501 2502 if (!is_null($file)) :2503 $location = "line # ${line} of ".basename($file);2504 else :2505 $location = "line # ${line}";2506 endif;2507 2508 print '<p><strong>Critical error:</strong> There may be a bug in FeedWordPress. Please <a href="'.FEEDWORDPRESS_AUTHOR_CONTACT.'">contact the author</a> and paste the following information into your e-mail:</p>';2509 print "\n<plaintext>";2510 print "Triggered at ${location}\n";2511 print "FeedWordPress: ".FEEDWORDPRESS_VERSION."\n";2512 print "WordPress: {$wp_version}\n";2513 print "PHP: ".phpversion()."\n";2514 print "Error data: ";2515 print $varname.": "; var_dump($var); echo "\n";2516 die;2517 } /* FeedWordPress::critical_bug () */2518 2519 static function noncritical_bug ($varname, $var, $line, $file = NULL) {2520 if (FEEDWORDPRESS_DEBUG) : // halt only when we are doing debugging2521 FeedWordPress::critical_bug($varname, $var, $line, $file);2522 endif;2523 } /* FeedWordPress::noncritical_bug () */2524 2525 static function val ($v, $no_newlines = false) {2526 return MyPHP::val($v, $no_newlines);2527 } /* FeedWordPress::val () */2528 2529 static function diagnostic_on ($level) {2530 $show = get_option('feedwordpress_diagnostics_show', array());2531 return (in_array($level, $show));2532 } /* FeedWordPress::diagnostic_on () */2533 2338 2534 2339 static function diagnostic ($level, $out, $persist = NULL, $since = NULL, $mostRecent = NULL) { … … 2540 2345 $diagnostic_nesting = count(explode(":", $level)); 2541 2346 2542 if ( self::diagnostic_on($level)) :2347 if (FeedWordPressDiagnostic::is_on($level)) : 2543 2348 foreach ($output as $method) : 2544 2349 switch ($method) : … … 2773 2578 } /* FeedWordPress::path () */ 2774 2579 2775 // These are superceded by MyPHP::param/post/get/request, but kept 2776 // here for backward compatibility. 2777 2580 // -- DEPRCATED UTILITY FUNCTIONS ------------------------------------- 2581 // These are superceded by later code re-organization, (for example 2582 // MyPHP::param/post/get/request, or FeedWordPressDiagnostic methods), 2583 // but for the last several versions have been kept here for backward 2584 // compatibility with add-ons, older code, etc. Maybe someday they 2585 // will go away. 2586 // ------------------------------------------------------------------- 2778 2587 static function param ($key, $type = 'REQUEST', $default = NULL) { 2779 2588 return MyPHP::param($key, $default, $type); … … 2783 2592 return MyPHP::post($key, $default); 2784 2593 } /* FeedWordPress::post () */ 2594 2595 static function val ($v, $no_newlines = false) { 2596 return MyPHP::val($v, $no_newlines); 2597 } /* FeedWordPress::val () */ 2598 2599 static function critical_bug ($varname, $var, $line, $file = NULL) { 2600 FeedWordPressDiagnostic::critical_bug($varname, $var, $line, $file); 2601 } /* FeedWordPress::critical_bug () */ 2602 2603 static function noncritical_bug ($varname, $var, $line, $file = NULL) { 2604 FeedWordPressDiagnostic::noncritical_bug($varname, $var, $line, $file); 2605 } /* FeedWordPress::noncritical_bug () */ 2606 2607 static function diagnostic_on ($level) { 2608 return FeedWordPressDiagnostic::is_on($level); 2609 } /* FeedWordPress::diagnostic_on () */ 2785 2610 2786 2611 } /* class FeedWordPress */ -
TabularUnified feedwordpress/trunk/feedwordpress_parser.class.php ¶
r641309 r2229752 2 2 class FeedWordPress_Parser extends SimplePie_Parser { 3 3 function reset_parser (&$xml) { 4 // reset members 5 $this->namespace = array(''); 6 $this->element = array(''); 7 $this->xml_base = array(''); 8 $this->xml_base_explicit = array(false); 9 $this->xml_lang = array(''); 10 $this->data = array(); 11 $this->datas = array(array()); 12 $this->current_xhtml_construct = -1; 13 $this->xmlns_stack = array(); 14 $this->xmlns_current = array(); 15 16 // reset libxml parser 4 17 xml_parser_free($xml); 5 18 … … 13 26 } 14 27 15 function parse (&$data, $encoding) {28 public function parse (&$data, $encoding) { 16 29 $data = apply_filters('feedwordpress_parser_parse', $data, $encoding, $this); 17 30 … … 96 109 if (!$parseResults and $endOfJunk > 0) : 97 110 // There is some junk before the feed prolog. Try to get rid of it. 98 $ newData = substr($data, $endOfJunk);99 $ newData = trim($newData);111 $data = substr($data, $endOfJunk); 112 $data = trim($data); 100 113 $this->reset_parser($xml); 101 114 102 $parseResults = xml_parse($xml, $ newData, true);115 $parseResults = xml_parse($xml, $data, true); 103 116 endif; 104 117 105 if (!$parseResults) 106 { 107 if (class_exists('DOMDocument')) : 108 libxml_use_internal_errors(true); 109 $doc = new DOMDocument; 110 $doc->loadHTML('<html>'.$data.'</html>'); 111 ///*DBG*/ echo "<plaintext>"; 112 ///*DBG*/ $dd = $doc->getElementsByTagName('html'); 113 ///*DBG*/ for ($i = 0; $i < $dd->length; $i++) : 114 ///*DBG*/ var_dump($dd->item($i)->nodeName); 115 ///*DBG*/ endfor; 116 ///*DBG*/ var_dump($doc); 117 libxml_use_internal_errors(false); 118 ///*DBG*/ die; 119 endif; 120 118 $badEntity = (xml_get_error_code($xml) == 26); 119 if (!$parseResults and $badEntity) : 120 // There was an entity that libxml couldn't understand. 121 // Chances are, it was a stray HTML entity. So let's try 122 // converting all the named HTML entities to numeric XML 123 // entities and starting over. 124 $data = $this->html_convert_entities($data); 125 $this->reset_parser($xml); 126 127 $parseResults = xml_parse($xml, $data, true); 128 endif; 129 130 if (!$parseResults) { 121 131 $this->error_code = xml_get_error_code($xml); 122 132 $this->error_string = xml_error_string($this->error_code); 123 ///*DBG*/ echo "WOOGA WOOGA"; var_dump($this->error_string); die;124 133 $return = false; 125 134 } … … 241 250 return true; 242 251 } /* FeedWordPress_Parser::start_xmlns() */ 243 } 244 252 253 /* html_convert_entities($string) -- convert named HTML entities to 254 * XML-compatible numeric entities. Adapted from code by @inanimatt: 255 * https://gist.github.com/inanimatt/879249 256 */ 257 public function html_convert_entities($string) { 258 return preg_replace_callback('/&([a-zA-Z][a-zA-Z0-9]+);/S', 259 array($this, 'convert_entity'), $string); 260 } 261 262 /* Swap HTML named entity with its numeric equivalent. If the entity 263 * isn't in the lookup table, this function returns a blank, which 264 * destroys the character in the output - this is probably the 265 * desired behaviour when producing XML. Adapted from code by @inanimatt: 266 * https://gist.github.com/inanimatt/879249 267 */ 268 public function convert_entity($matches) { 269 static $table = array( 270 'quot' => '"', 271 'amp' => '&', 272 'lt' => '<', 273 'gt' => '>', 274 'OElig' => 'Œ', 275 'oelig' => 'œ', 276 'Scaron' => 'Š', 277 'scaron' => 'š', 278 'Yuml' => 'Ÿ', 279 'circ' => 'ˆ', 280 'tilde' => '˜', 281 'ensp' => ' ', 282 'emsp' => ' ', 283 'thinsp' => ' ', 284 'zwnj' => '‌', 285 'zwj' => '‍', 286 'lrm' => '‎', 287 'rlm' => '‏', 288 'ndash' => '–', 289 'mdash' => '—', 290 'lsquo' => '‘', 291 'rsquo' => '’', 292 'sbquo' => '‚', 293 'ldquo' => '“', 294 'rdquo' => '”', 295 'bdquo' => '„', 296 'dagger' => '†', 297 'Dagger' => '‡', 298 'permil' => '‰', 299 'lsaquo' => '‹', 300 'rsaquo' => '›', 301 'euro' => '€', 302 'fnof' => 'ƒ', 303 'Alpha' => 'Α', 304 'Beta' => 'Β', 305 'Gamma' => 'Γ', 306 'Delta' => 'Δ', 307 'Epsilon' => 'Ε', 308 'Zeta' => 'Ζ', 309 'Eta' => 'Η', 310 'Theta' => 'Θ', 311 'Iota' => 'Ι', 312 'Kappa' => 'Κ', 313 'Lambda' => 'Λ', 314 'Mu' => 'Μ', 315 'Nu' => 'Ν', 316 'Xi' => 'Ξ', 317 'Omicron' => 'Ο', 318 'Pi' => 'Π', 319 'Rho' => 'Ρ', 320 'Sigma' => 'Σ', 321 'Tau' => 'Τ', 322 'Upsilon' => 'Υ', 323 'Phi' => 'Φ', 324 'Chi' => 'Χ', 325 'Psi' => 'Ψ', 326 'Omega' => 'Ω', 327 'alpha' => 'α', 328 'beta' => 'β', 329 'gamma' => 'γ', 330 'delta' => 'δ', 331 'epsilon' => 'ε', 332 'zeta' => 'ζ', 333 'eta' => 'η', 334 'theta' => 'θ', 335 'iota' => 'ι', 336 'kappa' => 'κ', 337 'lambda' => 'λ', 338 'mu' => 'μ', 339 'nu' => 'ν', 340 'xi' => 'ξ', 341 'omicron' => 'ο', 342 'pi' => 'π', 343 'rho' => 'ρ', 344 'sigmaf' => 'ς', 345 'sigma' => 'σ', 346 'tau' => 'τ', 347 'upsilon' => 'υ', 348 'phi' => 'φ', 349 'chi' => 'χ', 350 'psi' => 'ψ', 351 'omega' => 'ω', 352 'thetasym' => 'ϑ', 353 'upsih' => 'ϒ', 354 'piv' => 'ϖ', 355 'bull' => '•', 356 'hellip' => '…', 357 'prime' => '′', 358 'Prime' => '″', 359 'oline' => '‾', 360 'frasl' => '⁄', 361 'weierp' => '℘', 362 'image' => 'ℑ', 363 'real' => 'ℜ', 364 'trade' => '™', 365 'alefsym' => 'ℵ', 366 'larr' => '←', 367 'uarr' => '↑', 368 'rarr' => '→', 369 'darr' => '↓', 370 'harr' => '↔', 371 'crarr' => '↵', 372 'lArr' => '⇐', 373 'uArr' => '⇑', 374 'rArr' => '⇒', 375 'dArr' => '⇓', 376 'hArr' => '⇔', 377 'forall' => '∀', 378 'part' => '∂', 379 'exist' => '∃', 380 'empty' => '∅', 381 'nabla' => '∇', 382 'isin' => '∈', 383 'notin' => '∉', 384 'ni' => '∋', 385 'prod' => '∏', 386 'sum' => '∑', 387 'minus' => '−', 388 'lowast' => '∗', 389 'radic' => '√', 390 'prop' => '∝', 391 'infin' => '∞', 392 'ang' => '∠', 393 'and' => '∧', 394 'or' => '∨', 395 'cap' => '∩', 396 'cup' => '∪', 397 'int' => '∫', 398 'there4' => '∴', 399 'sim' => '∼', 400 'cong' => '≅', 401 'asymp' => '≈', 402 'ne' => '≠', 403 'equiv' => '≡', 404 'le' => '≤', 405 'ge' => '≥', 406 'sub' => '⊂', 407 'sup' => '⊃', 408 'nsub' => '⊄', 409 'sube' => '⊆', 410 'supe' => '⊇', 411 'oplus' => '⊕', 412 'otimes' => '⊗', 413 'perp' => '⊥', 414 'sdot' => '⋅', 415 'lceil' => '⌈', 416 'rceil' => '⌉', 417 'lfloor' => '⌊', 418 'rfloor' => '⌋', 419 'lang' => '〈', 420 'rang' => '〉', 421 'loz' => '◊', 422 'spades' => '♠', 423 'clubs' => '♣', 424 'hearts' => '♥', 425 'diams' => '♦', 426 'nbsp' => ' ', 427 'iexcl' => '¡', 428 'cent' => '¢', 429 'pound' => '£', 430 'curren' => '¤', 431 'yen' => '¥', 432 'brvbar' => '¦', 433 'sect' => '§', 434 'uml' => '¨', 435 'copy' => '©', 436 'ordf' => 'ª', 437 'laquo' => '«', 438 'not' => '¬', 439 'shy' => '­', 440 'reg' => '®', 441 'macr' => '¯', 442 'deg' => '°', 443 'plusmn' => '±', 444 'sup2' => '²', 445 'sup3' => '³', 446 'acute' => '´', 447 'micro' => 'µ', 448 'para' => '¶', 449 'middot' => '·', 450 'cedil' => '¸', 451 'sup1' => '¹', 452 'ordm' => 'º', 453 'raquo' => '»', 454 'frac14' => '¼', 455 'frac12' => '½', 456 'frac34' => '¾', 457 'iquest' => '¿', 458 'Agrave' => 'À', 459 'Aacute' => 'Á', 460 'Acirc' => 'Â', 461 'Atilde' => 'Ã', 462 'Auml' => 'Ä', 463 'Aring' => 'Å', 464 'AElig' => 'Æ', 465 'Ccedil' => 'Ç', 466 'Egrave' => 'È', 467 'Eacute' => 'É', 468 'Ecirc' => 'Ê', 469 'Euml' => 'Ë', 470 'Igrave' => 'Ì', 471 'Iacute' => 'Í', 472 'Icirc' => 'Î', 473 'Iuml' => 'Ï', 474 'ETH' => 'Ð', 475 'Ntilde' => 'Ñ', 476 'Ograve' => 'Ò', 477 'Oacute' => 'Ó', 478 'Ocirc' => 'Ô', 479 'Otilde' => 'Õ', 480 'Ouml' => 'Ö', 481 'times' => '×', 482 'Oslash' => 'Ø', 483 'Ugrave' => 'Ù', 484 'Uacute' => 'Ú', 485 'Ucirc' => 'Û', 486 'Uuml' => 'Ü', 487 'Yacute' => 'Ý', 488 'THORN' => 'Þ', 489 'szlig' => 'ß', 490 'agrave' => 'à', 491 'aacute' => 'á', 492 'acirc' => 'â', 493 'atilde' => 'ã', 494 'auml' => 'ä', 495 'aring' => 'å', 496 'aelig' => 'æ', 497 'ccedil' => 'ç', 498 'egrave' => 'è', 499 'eacute' => 'é', 500 'ecirc' => 'ê', 501 'euml' => 'ë', 502 'igrave' => 'ì', 503 'iacute' => 'í', 504 'icirc' => 'î', 505 'iuml' => 'ï', 506 'eth' => 'ð', 507 'ntilde' => 'ñ', 508 'ograve' => 'ò', 509 'oacute' => 'ó', 510 'ocirc' => 'ô', 511 'otilde' => 'õ', 512 'ouml' => 'ö', 513 'divide' => '÷', 514 'oslash' => 'ø', 515 'ugrave' => 'ù', 516 'uacute' => 'ú', 517 'ucirc' => 'û', 518 'uuml' => 'ü', 519 'yacute' => 'ý', 520 'thorn' => 'þ', 521 'yuml' => 'ÿ' 522 ); 523 // Entity not found? Destroy it. 524 return isset($table[$matches[1]]) ? $table[$matches[1]] : ''; 525 } /* FeedWordPress_Parser::convert_entity() */ 526 527 } /* class FeedWordPress_Parser */ 528 529 -
TabularUnified feedwordpress/trunk/feedwordpresslocalpost.class.php ¶
r1729270 r2229752 18 18 19 19 public function id () { 20 return $this->post->ID; 21 } 20 if (is_null($this->post) or !is_object($this->post)) : 21 return NULL; 22 else : 23 return $this->post->ID; 24 endif; 25 } /* FeedWordPressLocalPost::id () */ 22 26 23 27 public function meta ($what, $params = array()) { … … 32 36 )); 33 37 38 // If we got put through the_content without a current 39 // $post object set, then bail out immediately. 40 if (is_null($this->post) or !is_object($this->post)) : 41 return $params['default']; 42 endif; 43 34 44 // This is a little weird, just bear with me here. 35 45 $results = array(); … … 153 163 154 164 public function content () { 155 return apply_filters('the_content', $this->post->post_content, $this->post->ID); 165 if (is_null($this->post) or !is_object($this->post)) : 166 $post_content = NULL; 167 $post_id = NULL; 168 else : 169 $post_content = $this->post->post_content; 170 $post_id = $this->post->ID; 171 endif; 172 return apply_filters('the_content', $post_content, $post_id); 156 173 } 157 174 158 175 public function title () { 159 return apply_filters('the_title', $this->post->post_title, $this->post->ID); 176 if (is_null($this->post) or !is_object($this->post)) : 177 $post_title = NULL; 178 $post_id = NULL; 179 else : 180 $post_title = $this->post->post_title; 181 $post_id = $this->post->ID; 182 endif; 183 return apply_filters('the_title', $post_title, $post_id); 160 184 } 161 185 162 186 public function guid () { 163 return apply_filters('get_the_guid', $this->post->guid); 187 if (is_null($this->post) or !is_object($this->post)) : 188 $post_guid = NULL; 189 else : 190 $post_guid = $this->post->guid; 191 endif; 192 return apply_filters('get_the_guid', $post_guid); 164 193 } 165 194 166 195 public function get_categories () { 196 if (is_null($this->post) or !is_object($this->post)) : 197 return array(); 198 endif; 199 167 200 $terms = wp_get_object_terms( 168 201 $this->post->ID, -
TabularUnified feedwordpress/trunk/feedwordpresssyndicationpage.class.php ¶
r1749912 r2229752 140 140 endforeach; 141 141 else : // This should never happen 142 FeedWordPress ::critical_bug('fwp_syndication_manage_page::targets', $targets, __LINE__, __FILE__);142 FeedWordPressDiagnostic::critical_bug('fwp_syndication_manage_page::targets', $targets, __LINE__, __FILE__); 143 143 endif; 144 144 elseif (!is_null(MyPHP::post('update_uri'))) : … … 147 147 $targets = array($targets); 148 148 endif; 149 150 $first = each($targets); 151 if (!is_numeric($first['key'])) : // URLs in keys 152 $targets = array_keys($targets); 149 150 $targets_keys = array_keys($targets); 151 $first_key = reset($targets_keys); 152 if (!is_numeric($first_key)) : // URLs in keys 153 $targets = $targets_keys; 153 154 endif; 154 155 $update_set = $targets; … … 440 441 <div class="metabox-holder"> 441 442 <?php 442 fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);443 do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this); 443 444 ?> 444 445 </div> <!-- class="metabox-holder" --> … … 455 456 456 457 function dashboard_box ($page, $box = NULL) { 457 global $fwp_path;458 459 458 $links = FeedWordPress::syndicated_links(array("hide_invisible" => false)); 460 459 $sources = $this->sources('*'); … … 478 477 // Hey ho, let's go... 479 478 ?> 480 <div style="float: left; background: #F5F5F5; padding-top: 5px; padding-right: 5px;"><a href="<?php print $this->form_action(); ?>"><img src="<?php print esc_ html(plugins_url( "/${fwp_path}/feedwordpress.png") ); ?>" alt="" /></a></div>479 <div style="float: left; background: #F5F5F5; padding-top: 5px; padding-right: 5px;"><a href="<?php print $this->form_action(); ?>"><img src="<?php print esc_url(plugins_url( "feedwordpress.png", __FILE__ ) ); ?>" alt="" /></a></div> 481 480 482 481 <p class="info" style="margin-bottom: 0px; border-bottom: 1px dotted black;">Managed by <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a> … … 537 536 <?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); ?> 538 537 <input type="hidden" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" /> 539 <input style="vertical-align: middle;" type="image" src="<?php print plugins_url('/'.$fwp_path .'/plus.png'); ?>" alt="<?php print FWP_SYNDICATE_NEW; ?>" /></div>538 <input style="vertical-align: middle;" type="image" src="<?php print esc_url(plugins_url('plus.png', __FILE__)); ?>" alt="<?php print FWP_SYNDICATE_NEW; ?>" /></div> 540 539 </form> 541 540 </div> <!-- id="add-single-uri" --> … … 547 546 548 547 function syndicated_sources_box ($page, $box = NULL) { 549 global $fwp_path;550 548 551 549 $links = FeedWordPress::syndicated_links(array("hide_invisible" => false)); … … 603 601 <input type="hidden" name="action" value="feedfinder" /> 604 602 <input type="submit" class="button-secondary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" /> 605 <div style="text-align: right; margin-right: 2.0em"><a id="turn-on-multiple-sources" href="#add-multiple-uri"><img style="vertical-align: middle" src="<?php print plugins_url('/' . $fwp_path . '/down.png'); ?>" alt="" /> add multiple</a>603 <div style="text-align: right; margin-right: 2.0em"><a id="turn-on-multiple-sources" href="#add-multiple-uri"><img style="vertical-align: middle" src="<?php print esc_url(plugins_url('down.png', __FILE__)); ?>" alt="" /> add multiple</a> 606 604 <span class="screen-reader-text"> or </span> 607 <a id="turn-on-opml-upload" href="#upload-opml"><img src="<?php print plugins_url('/' . $fwp_path . '/plus.png'); ?>" alt="" style="vertical-align: middle" /> import source list</a></div>605 <a id="turn-on-opml-upload" href="#upload-opml"><img src="<?php print esc_url(plugins_url('plus.png', __FILE__)); ?>" alt="" style="vertical-align: middle" /> import source list</a></div> 608 606 </li> 609 607 </ul> … … 1199 1197 1200 1198 function fwp_switchfeed_page () { 1201 global $wpdb , $wp_db_version;1199 global $wpdb; 1202 1200 global $fwp_post, $fwp_path; 1203 1201 -
TabularUnified feedwordpress/trunk/performance-page.php ¶
r1551908 r2229752 13 13 14 14 function display () { 15 global $wpdb, $wp_db_version, $fwp_path;16 global $fwp_post;17 18 15 if (FeedWordPress::needs_upgrade()) : 19 16 fwp_upgrade_page(); … … 25 22 26 23 if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') : 27 $this->accept_POST($ fwp_post);28 do_action('feedwordpress_admin_page_performance_save', $ fwp_post, $this);24 $this->accept_POST($_POST); 25 do_action('feedwordpress_admin_page_performance_save', $_POST, $this); 29 26 endif; 30 27 … … 56 53 <div class="metabox-holder"> 57 54 <?php 58 fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);55 do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this); 59 56 ?> 60 57 </div> <!-- class="metabox-holder" --> -
TabularUnified feedwordpress/trunk/readme.txt ¶
r1749912 r2229752 1 1 === FeedWordPress === 2 2 Contributors: C. Johnson 3 Donate link: http://feedwordpress.radgeek.com/ 3 Donate link: http://feedwordpress.radgeek.com/donate/ 4 4 Tags: syndication, aggregation, feed, atom, rss 5 5 Requires at least: 4.5 6 Tested up to: 4.8.2 7 Stable tag: 2017.1020 6 Tested up to: 5.3.2 7 Stable tag: 2020.0118 8 License: GPLv2 or later 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 8 10 9 11 FeedWordPress syndicates content from feeds you choose into your WordPress weblog. … … 21 23 FeedWordPress is designed with flexibility, ease of use, and ease of configuration in mind. You'll need a working installation of WordPress (version [4.5][] or later), and it helps to have SFTP or FTP access to your web host. The ability to create cron jobs on your web host is helpful but not required. 22 24 23 [WordPress]: http://wordpress.org/ 24 [WordPress MU]: http://mu.wordpress.org/ 25 [WordPress]: https://wordpress.org/ 25 26 [4.5]: http://codex.wordpress.org/Version_4.5 26 27 … … 29 30 To use FeedWordPress, you will need: 30 31 31 * an installed and configured copy of [WordPress] [](version 4.5 or later).32 * an installed and configured copy of [WordPress](https://wordpress.org/) (version 4.5 or later). 32 33 33 34 * the ability to install new plugins on your site using either WordPress's Plugins Repository, SFTP, FTP or shell access to your web host … … 1920 1921 == License == 1921 1922 1922 The FeedWordPress plugin is copyright © 2005-2017 by Charles Johnson. It uses 1923 code derived or translated from: 1923 The FeedWordPress plugin is copyright © 2005-2017 by Charles Johnson. It uses code derived or translated from: 1924 1924 1925 1925 - [wp-rss-aggregate.php][] by [Kellan Elliot-McCrea](kellan@protest.net) … … 1931 1931 according to the terms of the [GNU General Public License][]. 1932 1932 1933 This program is free software; you can redistribute it and/or modify it under 1934 the terms of the [GNU General Public License][] as published by the Free 1935 Software Foundation; either version 2 of the License, or (at your option) any 1936 later version. 1937 1938 This program is distributed in the hope that it will be useful, but WITHOUT ANY 1939 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 1940 PARTICULAR PURPOSE. See the GNU General Public License for more details. 1933 This program is free software; you can redistribute it and/or modify it under the terms of the [GNU General Public License][] as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 1934 1935 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 1941 1936 1942 1937 [wp-rss-aggregate.php]: http://laughingmeme.org/archives/002203.html -
TabularUnified feedwordpress/trunk/syndicatedlink.class.php ¶
r1553712 r2229752 129 129 } /* SyndicatedLink::live_posts () */ 130 130 131 protected function pause_updates () { 132 return ('yes'==$this->setting("update/pause", "update_pause", 'no')); 133 } /* SyndicatedLink::pause_updates () */ 134 131 135 public function poll ($crash_ts = NULL) { 132 136 global $wpdb; … … 211 215 endif; 212 216 endif; 217 218 $this->update_setting('link/feed_type', $this->simplepie->get_type()); 213 219 214 220 $this->merge_settings($channel, 'feed/'); … … 276 282 if (is_array($posts)) : 277 283 foreach ($posts as $key => $item) : 278 $post = new SyndicatedPost($item, $this); 279 280 if (!$resume or !in_array(trim($post->guid()), $processed)) : 281 $processed[] = $post->guid(); 282 if (!$post->filtered()) : 283 $new = $post->store(); 284 if ( $new !== false ) $new_count[$new]++; 284 if (!$this->pause_updates()) : 285 $post = new SyndicatedPost($item, $this); 286 287 if (!$resume or !in_array(trim($post->guid()), $processed)) : 288 $processed[] = $post->guid(); 289 if (!$post->filtered()) : 290 $new = $post->store(); 291 if ( $new !== false ) $new_count[$new]++; 292 endif; 293 294 if (!is_null($crash_ts) and (time() > $crash_ts)) : 295 $crashed = true; 296 break; 297 endif; 285 298 endif; 286 299 287 if (!is_null($crash_ts) and (time() > $crash_ts)) : 288 $crashed = true; 289 break; 290 endif; 291 endif; 292 293 unset($post); 294 300 unset($post); 301 endif; 295 302 endforeach; 296 303 endif; … … 300 307 // <http://tools.ietf.org/html/draft-snell-atompub-tombstones-18> 301 308 $tombstones = $this->simplepie->get_feed_tags('http://purl.org/atompub/tombstones/1.0', 'deleted-entry'); 302 if ( count($tombstones) > 0) :309 if (!is_null($tombstones) && count($tombstones) > 0) : 303 310 foreach ($tombstones as $tombstone) : 304 311 $ref = NULL; … … 741 748 } /* SyndicatedLink::is_non_incremental () */ 742 749 750 public function get_feed_type () { 751 $type_code = $this->setting('link/feed_type'); 752 753 // list derived from: <http://simplepie.org/api/class-SimplePie.html>, retrieved 2020/01/18 754 $bitmasks = array( 755 SIMPLEPIE_TYPE_RSS_090 => 'RSS 0.90', 756 SIMPLEPIE_TYPE_RSS_091_NETSCAPE => 'RSS 0.91 (Netscape)', 757 SIMPLEPIE_TYPE_RSS_091_USERLAND => 'RSS 0.91 (Userland)', 758 SIMPLEPIE_TYPE_RSS_091 => 'RSS 0.91', 759 SIMPLEPIE_TYPE_RSS_092 => 'RSS 0.92', 760 SIMPLEPIE_TYPE_RSS_093 => 'RSS 0.93', 761 SIMPLEPIE_TYPE_RSS_094 => 'RSS 0.94', 762 SIMPLEPIE_TYPE_RSS_10 => 'RSS 1.0', 763 SIMPLEPIE_TYPE_RSS_20 => 'RSS 2.0.x', 764 SIMPLEPIE_TYPE_RSS_RDF => 'RDF-based RSS', 765 SIMPLEPIE_TYPE_RSS_SYNDICATION => 'Non-RDF-based RSS', 766 SIMPLEPIE_TYPE_RSS_ALL => 'Any version of RSS', 767 SIMPLEPIE_TYPE_ATOM_03 => 'Atom 0.3', 768 SIMPLEPIE_TYPE_ATOM_10 => 'Atom 1.0', 769 SIMPLEPIE_TYPE_ATOM_ALL => 'Atom (any version)', 770 SIMPLEPIE_TYPE_ALL => 'Supported Feed (unspecified format)', 771 ); 772 773 $type = "Unknown or unsupported format"; 774 foreach ($bitmasks as $format_flag => $format_string) : 775 if (is_numeric($format_flag)) : // Guard against failure of constants to be defined. 776 if ($type_code & $format_flag) : 777 $type = $format_string; 778 break; // foreach 779 endif; 780 endif; 781 endforeach; 782 783 return $type; 784 } /* SyndicatedLink::get_feed_type () */ 785 743 786 public function uri ($params = array()) { 744 787 $params = wp_parse_args($params, array( -
TabularUnified feedwordpress/trunk/syndicatedpost.class.php ¶
r1749912 r2229752 1229 1229 1230 1230 if ($this->filtered()) : // This should never happen. 1231 FeedWordPress ::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);1231 FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__); 1232 1232 endif; 1233 1233 … … 1245 1245 if ($q->have_posts()) : 1246 1246 while ($q->have_posts()) : $q->the_post(); 1247 $old_post = $q->post; 1247 if (get_post_type($q->post->ID) == $this->post['post_type']): 1248 $old_post = $q->post; 1249 endif; 1248 1250 endwhile; 1249 1251 endif; … … 1306 1308 endif; 1307 1309 1308 if ($updated and FeedWordPress ::diagnostic_on('feed_items:freshness:reasons')) :1310 if ($updated and FeedWordPressDiagnostic::is_on('feed_items:freshness:reasons')) : 1309 1311 // In the absence of definitive 1310 1312 // timestamp information, we … … 1452 1454 function wp_id () { 1453 1455 if ($this->filtered()) : // This should never happen. 1454 FeedWordPress ::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);1456 FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__); 1455 1457 endif; 1456 1458 … … 1461 1463 } 1462 1464 1465 /** 1466 * SyndicatedPost::secure_author_id(). Look up, or create, a numeric ID 1467 * for the author of the incoming post. 1468 * 1469 * side effect: int|NULL stored in $this->post['post_author'] 1470 * side effect: IF no valid author is found, NULL stored in $this->post 1471 * side effect: diagnostic output in case item is rejected with NULL author 1472 * 1473 * @used-by SyndicatedPost::store 1474 * 1475 * @uses SyndicatedPost::post 1476 * @uses SyndicatedPost::author_id 1477 * @uses SyndicatedLink::setting 1478 * @uses FeedWordPress::diagnostic 1479 */ 1480 protected function secure_author_id () { 1481 # -- Look up, or create, numeric ID for author 1482 $this->post['post_author'] = $this->author_id ( 1483 $this->link->setting('unfamiliar author', 'unfamiliar_author', 'create') 1484 ); 1485 1486 if (is_null($this->post['post_author'])) : 1487 FeedWordPress::diagnostic('feed_items:rejected', 'Filtered out item ['.$this->guid().'] without syndication: no author available'); 1488 $this->post = NULL; 1489 endif; 1490 } /* SyndicatedPost::secure_author_id() */ 1491 1492 /** 1493 * SyndicatedPost::secure_term_ids(). Look up, or create, numeric IDs 1494 * for the terms (categories, tags, etc.) assigned to the incoming post, 1495 * whether by global settings, feed settings, or by the tags on the feed. 1496 * 1497 * side effect: array of term ids stored in $this->post['tax_input'] 1498 * side effect: IF settings or filters determine post should be filtered out, 1499 * NULL stored in $this->post 1500 * 1501 * @used-by SyndicatedPost::store 1502 * 1503 * @uses apply_filters 1504 * @uses SyndicatedLink::setting 1505 * @uses SyndicatedPost::category_ids 1506 * @uses SyndicatedPost::preset_terms 1507 * @uses SyndicatedPost::post 1508 */ 1509 protected function secure_term_ids () { 1510 $mapping = apply_filters('syndicated_post_terms_mapping', array( 1511 'category' => array('abbr' => 'cats', 'unfamiliar' => 'category', 'domain' => array('category', 'post_tag')), 1512 'post_tag' => array('abbr' => 'tags', 'unfamiliar' => 'post_tag', 'domain' => array('post_tag')), 1513 ), $this); 1514 1515 $termSet = array(); $valid = null; 1516 foreach ($this->feed_terms as $what => $anTerms) : 1517 // Default to using the inclusive procedures (for cats) rather than exclusive (for inline tags) 1518 $taxes = (isset($mapping[$what]) ? $mapping[$what] : $mapping['category']); 1519 $unfamiliar = $taxes['unfamiliar']; 1520 1521 if (!is_null($this->post)) : // Not filtered out yet 1522 # -- Look up, or create, numeric ID for categories 1523 $taxonomies = $this->link->setting("match/".$taxes['abbr'], 'match_'.$taxes['abbr'], $taxes['domain']); 1524 1525 // Eliminate dummy variables 1526 $taxonomies = array_filter($taxonomies, 'remove_dummy_zero'); 1527 1528 // Allow FWP add-on filters to control the taxonomies we use to search for a term 1529 $taxonomies = apply_filters("syndicated_post_terms_match", $taxonomies, $what, $this); 1530 $taxonomies = apply_filters("syndicated_post_terms_match_${what}", $taxonomies, $this); 1531 1532 // Allow FWP add-on filters to control with greater precision what happens on unmatched 1533 $unmatched = apply_filters("syndicated_post_terms_unfamiliar", 1534 $this->link->setting( 1535 "unfamiliar {$unfamiliar}", 1536 "unfamiliar_{$unfamiliar}", 1537 'create:'.$unfamiliar 1538 ), 1539 $what, 1540 $this 1541 ); 1542 1543 $terms = $this->category_ids ( 1544 $anTerms, 1545 $unmatched, 1546 /*taxonomies=*/ $taxonomies, 1547 array( 1548 'singleton' => false, // I don't like surprises 1549 'filters' => true, 1550 ) 1551 ); 1552 1553 if (is_null($terms) or is_null($termSet)) : 1554 // filtered out -- no matches 1555 else : 1556 $valid = true; 1557 1558 // filter mode off, or at least one match 1559 foreach ($terms as $tax => $term_ids) : 1560 if (!isset($termSet[$tax])) : 1561 $termSet[$tax] = array(); 1562 endif; 1563 $termSet[$tax] = array_merge($termSet[$tax], $term_ids); 1564 endforeach; 1565 endif; 1566 endif; 1567 endforeach; 1568 1569 if (is_null($valid)) : // Plonked 1570 $this->post = NULL; 1571 else : // We can proceed 1572 $this->post['tax_input'] = array(); 1573 foreach ($termSet as $tax => $term_ids) : 1574 if (!isset($this->post['tax_input'][$tax])) : 1575 $this->post['tax_input'][$tax] = array(); 1576 endif; 1577 $this->post['tax_input'][$tax] = array_merge( 1578 $this->post['tax_input'][$tax], 1579 $term_ids 1580 ); 1581 endforeach; 1582 1583 // Now let's add on the feed and global presets 1584 foreach ($this->preset_terms as $tax => $term_ids) : 1585 if (!isset($this->post['tax_input'][$tax])) : 1586 $this->post['tax_input'][$tax] = array(); 1587 endif; 1588 1589 $this->post['tax_input'][$tax] = array_merge ( 1590 $this->post['tax_input'][$tax], 1591 $this->category_ids ( 1592 /*terms=*/ $term_ids, 1593 /*unfamiliar=*/ 'create:'.$tax, // These are presets; for those added in a tagbox editor, the tag may not yet exist 1594 /*taxonomies=*/ array($tax), 1595 array( 1596 'singleton' => true, 1597 )) 1598 ); 1599 endforeach; 1600 endif; 1601 } /* SyndicatedPost::secure_term_ids() */ 1602 1603 /** 1604 * SyndicatedPost::store 1605 * 1606 * @uses SyndicatedPost::secure_author_id 1607 */ 1463 1608 public function store () { 1464 1609 global $wpdb; 1465 1610 1466 1611 if ($this->filtered()) : // This should never happen. 1467 FeedWordPress ::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);1612 FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__); 1468 1613 endif; 1469 1614 1470 1615 $freshness = $this->freshness(); 1471 1616 if ($this->has_fresh_content()) : 1472 # -- Look up, or create, numeric ID for author 1473 $this->post['post_author'] = $this->author_id ( 1474 $this->link->setting('unfamiliar author', 'unfamiliar_author', 'create') 1475 ); 1476 1477 if (is_null($this->post['post_author'])) : 1478 FeedWordPress::diagnostic('feed_items:rejected', 'Filtered out item ['.$this->guid().'] without syndication: no author available'); 1479 $this->post = NULL; 1480 endif; 1481 endif; 1482 1483 // We have to check again in case post has been filtered during 1484 // the author_id lookup 1485 if ($this->has_fresh_content()) : 1486 $mapping = apply_filters('syndicated_post_terms_mapping', array( 1487 'category' => array('abbr' => 'cats', 'unfamiliar' => 'category', 'domain' => array('category', 'post_tag')), 1488 'post_tag' => array('abbr' => 'tags', 'unfamiliar' => 'post_tag', 'domain' => array('post_tag')), 1489 ), $this); 1490 1491 $termSet = array(); $valid = null; 1492 foreach ($this->feed_terms as $what => $anTerms) : 1493 // Default to using the inclusive procedures (for cats) rather than exclusive (for inline tags) 1494 $taxes = (isset($mapping[$what]) ? $mapping[$what] : $mapping['category']); 1495 $unfamiliar = $taxes['unfamiliar']; 1496 1497 if (!is_null($this->post)) : // Not filtered out yet 1498 # -- Look up, or create, numeric ID for categories 1499 $taxonomies = $this->link->setting("match/".$taxes['abbr'], 'match_'.$taxes['abbr'], $taxes['domain']); 1500 1501 // Eliminate dummy variables 1502 $taxonomies = array_filter($taxonomies, 'remove_dummy_zero'); 1503 1504 // Allow FWP add-on filters to control the taxonomies we use to search for a term 1505 $taxonomies = apply_filters("syndicated_post_terms_match", $taxonomies, $what, $this); 1506 $taxonomies = apply_filters("syndicated_post_terms_match_${what}", $taxonomies, $this); 1507 1508 // Allow FWP add-on filters to control with greater precision what happens on unmatched 1509 $unmatched = apply_filters("syndicated_post_terms_unfamiliar", 1510 $this->link->setting( 1511 "unfamiliar {$unfamiliar}", 1512 "unfamiliar_{$unfamiliar}", 1513 'create:'.$unfamiliar 1514 ), 1515 $what, 1516 $this 1517 ); 1518 1519 $terms = $this->category_ids ( 1520 $anTerms, 1521 $unmatched, 1522 /*taxonomies=*/ $taxonomies, 1523 array( 1524 'singleton' => false, // I don't like surprises 1525 'filters' => true, 1526 ) 1527 ); 1528 1529 if (is_null($terms) or is_null($termSet)) : 1530 // filtered out -- no matches 1531 else : 1532 $valid = true; 1533 1534 // filter mode off, or at least one match 1535 foreach ($terms as $tax => $term_ids) : 1536 if (!isset($termSet[$tax])) : 1537 $termSet[$tax] = array(); 1538 endif; 1539 $termSet[$tax] = array_merge($termSet[$tax], $term_ids); 1540 endforeach; 1541 endif; 1542 endif; 1543 endforeach; 1544 1545 if (is_null($valid)) : // Plonked 1546 $this->post = NULL; 1547 else : // We can proceed 1548 $this->post['tax_input'] = array(); 1549 foreach ($termSet as $tax => $term_ids) : 1550 if (!isset($this->post['tax_input'][$tax])) : 1551 $this->post['tax_input'][$tax] = array(); 1552 endif; 1553 $this->post['tax_input'][$tax] = array_merge( 1554 $this->post['tax_input'][$tax], 1555 $term_ids 1556 ); 1557 endforeach; 1558 1559 // Now let's add on the feed and global presets 1560 foreach ($this->preset_terms as $tax => $term_ids) : 1561 if (!isset($this->post['tax_input'][$tax])) : 1562 $this->post['tax_input'][$tax] = array(); 1563 endif; 1564 1565 $this->post['tax_input'][$tax] = array_merge ( 1566 $this->post['tax_input'][$tax], 1567 $this->category_ids ( 1568 /*terms=*/ $term_ids, 1569 /*unfamiliar=*/ 'create:'.$tax, // These are presets; for those added in a tagbox editor, the tag may not yet exist 1570 /*taxonomies=*/ array($tax), 1571 array( 1572 'singleton' => true, 1573 )) 1574 ); 1575 endforeach; 1576 endif; 1617 $this->secure_author_id(); 1618 endif; 1619 1620 if ($this->has_fresh_content()) : // Was this filtered during author_id lookup? 1621 $this->secure_term_ids(); 1577 1622 endif; 1578 1623 … … 1787 1832 } /* function SyndicatedPost::insert_post () */ 1788 1833 1834 /** 1835 * SyndicatedPost::insert_new(). Uses the data collected in this post object to insert 1836 * a new post into the wp_posts table. 1837 * 1838 * @uses SyndicatedPost::insert_post 1839 */ 1789 1840 function insert_new () { 1790 1841 $this->insert_post(/*update=*/ false, 1); 1791 1842 } /* SyndicatedPost::insert_new() */ 1792 1843 1844 /** 1845 * SyndicatedPost::insert_new(). Uses the data collected in this post object to update 1846 * an existing post in the wp_posts table. 1847 * 1848 * @uses SyndicatedPost::insert_post 1849 */ 1793 1850 function update_existing () { 1794 1851 $this->insert_post(/*update=*/ true, 2); … … 1935 1992 $ns::_wp_id 1936 1993 EOM; 1937 FeedWordPress ::noncritical_bug(1994 FeedWordPressDiagnostic::noncritical_bug( 1938 1995 /*message=*/ $mesg, 1939 1996 /*var =*/ array( … … 2143 2200 2144 2201 $author = NULL; 2145 while (is_null($author) and ($candidate = each($candidates))) : 2146 if (!is_null($candidate['value']) 2147 and (strlen(trim($candidate['value'])) > 0) 2148 and !in_array(strtolower(trim($candidate['value'])), $forbidden)) : 2149 $author = $candidate['value']; 2150 endif; 2151 endwhile; 2202 foreach ($candidates as $candidate) { 2203 if (!is_null($candidate) 2204 and (strlen(trim($candidate)) > 0) 2205 and !in_array(strtolower(trim($candidate)), $forbidden)) : 2206 $author = $candidate; 2207 break; 2208 endif; 2209 } 2152 2210 2153 2211 $email = (isset($a['email']) ? $a['email'] : NULL); … … 2253 2311 $userdata = array(); 2254 2312 2255 // WordPress 3 is going to pitch a fit if we attempt to register2256 // more than one user account with an empty e-mail address, so we2257 // need *something* here. Ugh.2313 #-- we need *something* for the email here or WordPress 2314 #-- is liable to pitch a fit. So, make something up if 2315 #-- necessary. (Ugh.) 2258 2316 if (strlen($email) == 0 or FeedWordPress::is_null_email($email)) : 2259 2317 $url = parse_url($hostUrl); … … 2269 2327 $userdata['user_url'] = $authorUrl; 2270 2328 $userdata['nickname'] = $author; 2329 2271 2330 $parts = preg_split('/\s+/', trim($author), 2); 2272 2331 if (isset($parts[0])) : $userdata['first_name'] = $parts[0]; endif; 2273 2332 if (isset($parts[1])) : $userdata['last_name'] = $parts[1]; endif; 2333 2274 2334 $userdata['display_name'] = $author; 2275 2335 $userdata['role'] = 'contributor'; 2276 2336 2277 do { // Keep trying until you get it right. Or until PHP crashes, I guess. 2337 #-- loop. Keep trying to add the user until you get it 2338 #-- right. Or until PHP crashes, I guess. 2339 do { 2278 2340 $id = wp_insert_user($userdata); 2279 2341 if (is_wp_error($id)) : … … 2286 2348 break; 2287 2349 case 'user_nicename_too_long' : 2288 // Add a limited 50 c aracters user_nicename based on user_login2350 // Add a limited 50 characters user_nicename based on user_login 2289 2351 $userdata['user_nicename'] = mb_substr( $userdata['user_login'], 0, 50 ); 2290 2352 break; 2291 2353 case 'existing_user_email' : 2292 // No disassemble!2354 // Disassemble email for username, host 2293 2355 $parts = explode('@', $userdata['user_email'], 2); 2294 2356 … … 2302 2364 endif; 2303 2365 } while (is_wp_error($id)); 2366 2367 // $id should now contain the numeric ID of a newly minted 2368 // user account. Let's mark them as having been generated 2369 // by FeedWordPress in the usermeta table, as per the 2370 // suggestion of @boonebgorges, in case we need to process, 2371 // winnow, filter, or merge syndicated author accounts, &c. 2372 add_user_meta($id, 'feedwordpress_generated', 1); 2373 2304 2374 elseif (is_numeric($unfamiliar_author) and get_userdata((int) $unfamiliar_author)) : 2305 2375 $id = (int) $unfamiliar_author; -
TabularUnified feedwordpress/trunk/syndicatedpostterm.class.php ¶
r1413324 r2229752 182 182 183 183 // If debug mode is ON, this will halt us here. 184 FeedWordPress ::noncritical_bug(184 FeedWordPressDiagnostic::noncritical_bug( 185 185 'term insertion problem', array( 186 186 'term' => $this->term, 187 187 'result' => $aTerm, 188 'post' => $ post,188 'post' => $this->post, 189 189 'this' => $this 190 190 ), __LINE__, __FILE__
Note: See TracChangeset
for help on using the changeset viewer.