Plugin Directory

Changeset 2229752


Ignore:
Timestamp:
01/18/2020 11:37:53 PM (5 years ago)
Author:
radgeek
Message:

2020.0118 / roll up Github improvements to present.

Location:
feedwordpress/trunk
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified feedwordpress/trunk/admin-ui.php

    r1553712 r2229752  
    11<?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') ?> &raquo;" /></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__);
     15require_once("${dir}/feedwordpressadminpage.class.php");
     16require_once("${dir}/feedwordpresssettingsui.class.php");
    73917
    74018function fwp_update_set_results_message ($delta, $joiner = ';') {
     
    76240</p>
    76341</div>
    764 <?php
    765 }
    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 <?php
    773 }
    774 
    775 function fwp_option_box_closer () {
    776 ?>
    777     </div> <!-- class="inside" -->
    778     </div> <!-- class="stuffbox" -->
    77942<?php
    78043}
     
    962225}
    963226
    964 class FeedWordPressSettingsUI {
    965     static function is_admin () {
    966         global $fwp_path;
    967 
    968         $admin_page = false; // Innocent until proven guilty
    969         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 boxes
    982         wp_enqueue_script('admin-forms'); // for checkbox selection
    983 
    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         <?php
    1018     } /* 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     <?php
    1044     } /* 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         <?php
    1067     } /* FeedWordPressSettingsUI::magic_input_tip_js () */
    1068 } /* class FeedWordPressSettingsUI */
    1069 
    1070227function fwp_insert_new_user ($newuser_name) {
    1071228    global $wpdb;
     
    1091248} /* fwp_insert_new_user () */
    1092249
    1093 /**
    1094  * fwp_add_meta_box
    1095  *
    1096  * This function is no longer necessary, since no versions of WordPress that FWP
    1097  * still supports lack add_meta_box(). But I've left it in place for the time
    1098  * 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 bug
    1108 ?>
    1109     <div style="display: none">
    1110     <div id="tags-input"></div> <!-- avoid JS error from WP 2.5 bug -->
    1111     </div>
    1112 <?php
    1113     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 
    1120250function fwp_syndication_manage_page_links_table_rows ($links, $page, $visible = 'Y') {
    1121251
     252    $fwp_syndicated_sources_columns = array(__('Name'), __('Feed'), __('Updated'));
     253   
    1122254    $subscribed = ('Y' == strtoupper($visible));
    1123255    if ($subscribed or (count($links) > 0)) :
     
    1127259    <tr>
    1128260    <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>
    1136261<?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
    1137270        $alt_row = true;
    1138271        if (count($links) > 0):
     
    1150283                // Prep: get last error timestamp, if any
    1151284                $fileSizeLines = array();
     285                $feed_type = $sLink->get_feed_type();               
    1152286                if (is_null($sLink->setting('update/error'))) :
    1153287                    $errorsSince = '';
    1154288                    if (!is_null($sLink->setting('link/item count'))) :
    1155289                        $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;
    1157291                    endif;
    1158292
     
    1256390    </td>
    1257391                <?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>
    1259393                <?php else: ?>
    1260394    <td class="feed-missing"><p><strong>no feed assigned</strong></p></td>
     
    1264398    <input type="submit" class="button" name="update_uri[<?php print esc_html($link->link_rss); ?>]" value="<?php _e('Update Now'); ?>" />
    1265399    </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    ?>
    1270406    </td>
    1271407    </tr>
  • TabularUnified feedwordpress/trunk/diagnostics-page.php

    r1551908 r2229752  
    1616
    1717    function display () {
    18         global $wpdb, $wp_db_version, $fwp_path;
    19         global $fwp_post;
    20 
    2118        if (FeedWordPress::needs_upgrade()) :
    2219            fwp_upgrade_page();
     
    2825
    2926        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);
    3229        endif;
    3330
     
    6259            <div class="metabox-holder">
    6360            <?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);
    6562            ?>
    6663            </div> <!-- class="metabox-holder" -->
  • TabularUnified feedwordpress/trunk/feeds-page.php

    r1729270 r2229752  
    162162                );
    163163            } /* 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">&#8212; PAUSE or RESUME UPDATES &#8212;</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
    164175        } );
    165176
     
    187198
    188199        <tr>
    189         <th scope="row">Updates:</th>
     200        <th scope="row">Update Method:</th>
    190201        <td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');">
    191202        <option value="shutdown"<?php echo ($automatic_updates=='shutdown')?' selected="selected"':''; ?>>automatically check for updates after pages load</option>
     
    199210        // or to wget. If everything fails or shell_exec() isn't available, then just make
    200211        // up something for the sake of example.
     212        $curlOrWgetPath = NULL;
     213
    201214        $shellExecAvailable = (is_callable('shell_exec') && false === stripos(ini_get('disable_functions'), 'shell_exec'));     
    202215
    203216        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');
    218231       
    219232        ?>If you want to use a cron job,
     
    268281       
    269282        <?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
    271302        <tr>
    272303        <th scope="row"><?php print __('Update scheduling:') ?></th>
     
    507538
    508539            $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';
    514541            $params['hide_empty'] = false;
    515542            $results = get_categories($params);
     
    12161243        endif;
    12171244       
     1245        if (isset($post['update_pause'])) :
     1246            $this->update_setting('update/pause', $post['update_pause']);
     1247        endif;
     1248
    12181249        if (isset($post['fetch_timeout'])) :
    12191250            if (isset($post['fetch_timeout_default']) and $post['fetch_timeout_default']=='yes') :
  • TabularUnified feedwordpress/trunk/feedwordpress.php

    r1749912 r2229752  
    44Plugin URI: http://feedwordpress.radgeek.com/
    55Description: simple and flexible Atom/RSS syndication for WordPress
    6 Version: 2017.1020
     6Version: 2020.0118
    77Author: C. Johnson
    88Author URI: https://feedwordpress.radgeek.com/contact/
     
    1212/**
    1313 * @package FeedWordPress
    14  * @version 2017.1020
     14 * @version 2020.0118
    1515 */
    1616
    17 # This uses code derived from:
     17# This plugin uses code derived from:
    1818# - wp-rss-aggregate.php by Kellan Elliot-McCrea <kellan@protest.net>
    1919# - SimplePie feed parser by Ryan Parman, Geoffrey Sneddon, Ryan McCue, et al.
     
    2121# - Ultra-Liberal Feed Finder by Mark Pilgrim <mark@diveintomark.org>
    2222# - 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
    2326# 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
     32define ('FEEDWORDPRESS_VERSION', '2020.0118');
    3633define ('FEEDWORDPRESS_AUTHOR_CONTACT', 'http://feedwordpress.radgeek.com/contact');
    3734
     
    4239define('FEEDWORDPRESS_BLEG_PAYPAL', '22PAJZZCK5Z3W');
    4340
    44 define('FEEDWORDPRESS_BOILERPLATE_DEFAULT_HOOK_ORDER', 11000); // at the tail end of the filtering process
    45 
    4641// Defaults
    4742define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
    4843define ('DEFAULT_UPDATE_PERIOD', 60); // value in minutes
     44define ('FEEDWORDPRESS_DEFAULT_CHECKIN_INTERVAL', DEFAULT_UPDATE_PERIOD/10);
    4945
    5046if (isset($_REQUEST['feedwordpress_debug'])) :
     
    6763define ('FEEDWORDPRESS_FRESHNESS_INTERVAL', 10*60); // Every ten minutes
    6864
    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
     65define('FEEDWORDPRESS_BOILERPLATE_DEFAULT_HOOK_ORDER', 11000); // at the tail end of the filtering process
    7266
    7367if (FEEDWORDPRESS_DEBUG) :
     
    9286endif;
    9387
    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####################################################################################
    9691
    9792// Dependencies: modules packaged with WordPress core
     
    130125$dir = dirname(__FILE__);
    131126require_once("${dir}/externals/myphp/myphp.class.php");
     127require_once("${dir}/feedwordpressadminpage.class.php");
     128require_once("${dir}/feedwordpresssettingsui.class.php");
     129require_once("${dir}/feedwordpressdiagnostic.class.php");
    132130require_once("${dir}/admin-ui.php");
     131require_once("${dir}/template-functions.php");
    133132require_once("${dir}/feedwordpresssyndicationpage.class.php");
    134133require_once("${dir}/compatability.php"); // Legacy API
     
    147146require_once("${dir}/feedwordpresslocalpost.class.php");
    148147
    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.
     157global $fwp_post;
     158
    150159if (is_array($_POST)) :
    151160    $fwp_post = $_POST;
    152     if (get_magic_quotes_gpc()) :
    153         $fwp_post = stripslashes_deep($fwp_post);
    154     endif;
     161else:
     162    $fwp_post = null;
    155163endif;
    156164
     
    167175    $fwp_path = 'feedwordpress';
    168176endif;
     177
     178####################################################################################
     179## FEEDWORDPRESS: INITIALIZE OBJECT AND FILTERS ####################################
     180####################################################################################
    169181
    170182$feedwordpress = new FeedWordPress;
     
    282294    add_action('all_admin_notices', array($feedwordpress, 'all_admin_notices'));
    283295
     296    // Use our the cache settings that we want.
     297    add_filter('wp_feed_cache_transient_lifetime', array('FeedWordPress', 'cache_lifetime'));
     298
     299
    284300else :
    285301    # Hook in the menus, which will just point to the upgrade interface
     
    287303endif; // if (!FeedWordPress::needs_upgrade())
    288304
     305register_deactivation_hook(__FILE__, 'feedwordpress_deactivate');
     306function feedwordpress_deactivate () {
     307    wp_clear_scheduled_hook('fwp_scheduled_update_checkin');
     308} /* feedwordpress_deactivate () */
     309
    289310################################################################################
    290311## LOGGING FUNCTIONS: log status updates to error_log if you want it ###########
    291312################################################################################
    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 filter
    299         $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 */
    341313
    342314function debug_out_human_readable_bytes ($quantity) {
     
    352324
    353325function debug_out_feedwordpress_footer () {
    354     if (FeedWordPress::diagnostic_on('memory_usage')) :
     326    if (FeedWordPressDiagnostic::is_on('memory_usage')) :
    355327        if (function_exists('memory_get_usage')) :
    356328            FeedWordPress::diagnostic ('memory_usage', "Memory: Current usage: ".debug_out_human_readable_bytes(memory_get_usage()));
     
    361333    endif;
    362334} /* 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 post
    370  * given by ID number, was syndicated by FeedWordPress. Useful for templates
    371  * to determine whether or not to retrieve syndication-related meta-data in
    372  * 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 otherwise
    376  */
    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 subdomains
    386     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 elements
    391     $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 permalink
    480  * 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 of
    482  * an article for most purposes, but want to retrieve a URL for the local
    483  * 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_permalink
    492  *
    493  * @since 2010.0217
    494  */
    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 filled
    499     // 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_filters
    512  *
    513  * @since 2010.0217
    514  */
    515 function the_local_permalink ($id = NULL) {
    516     print apply_filters('the_permalink', get_local_permalink($id));
    517 } /* function the_local_permalink() */
    518335
    519336################################################################################
     
    863680        add_filter('user_can_richedit', array($feedwordpress, 'user_can_richedit'), 1000, 1);
    864681
    865         if (FeedWordPress::diagnostic_on('syndicated_posts:static_meta_data')) :
     682        if (FeedWordPressDiagnostic::is_on('syndicated_posts:static_meta_data')) :
    866683            $inspectPostMeta = new InspectPostMeta;
    867684        endif;
     
    883700
    884701        $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]);
    886703
    887704        if (is_syndicated($post->ID)) :
     
    11881005        $this->feedurls  = array();
    11891006        $links = FeedWordPress::syndicated_links();
     1007
    11901008        if ($links): foreach ($links as $link):
    11911009            $id = intval($link->link_id);
     
    11991017        endforeach; endif;
    12001018
     1019        // System-related event hooks
     1020        add_filter('cron_schedules', array($this, 'cron_schedules'), 10, 1);
     1021
     1022        // FeedWordPress-related event hooks
    12011023        add_filter('feedwordpress_update_complete', array($this, 'process_retirements'), 1000, 1);
    1202 
     1024       
    12031025        $this->httpauth = new FeedWordPressHTTPAuthenticator;
    12041026    } /* FeedWordPress::__construct () */
     
    14911313            // This should never happen.
    14921314            else :
    1493                 FeedWordPress::critical_bug('FeedWordPress::stale::last', $last, __LINE__, __FILE__);
     1315                FeedWordPressDiagnostic::critical_bug('FeedWordPress::stale::last', $last, __LINE__, __FILE__);
    14941316            endif;
    14951317
     
    17141536            wp_enqueue_style('dashboard');
    17151537            wp_enqueue_style('feedwordpress-elements');
    1716 
    1717             /*if (function_exists('wp_admin_css')) :
    1718                 wp_admin_css('css/dashboard');
    1719             endif;*/
    17201538        endif;
    17211539
     
    17661584    } /* FeedWordPress::wp_loaded () */
    17671585   
     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
    17681607    public function fwp_feeds () {
    17691608        $feeds = array();
     
    24972336
    24982337    # 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 debugging
    2521             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 () */
    25332338
    25342339    static function diagnostic ($level, $out, $persist = NULL, $since = NULL, $mostRecent = NULL) {
     
    25402345        $diagnostic_nesting = count(explode(":", $level));
    25412346
    2542         if (self::diagnostic_on($level)) :
     2347        if (FeedWordPressDiagnostic::is_on($level)) :
    25432348            foreach ($output as $method) :
    25442349                switch ($method) :
     
    27732578    } /* FeedWordPress::path () */
    27742579
    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    // -------------------------------------------------------------------
    27782587    static function param ($key, $type = 'REQUEST', $default = NULL) {
    27792588        return MyPHP::param($key, $default, $type);
     
    27832592        return MyPHP::post($key, $default);
    27842593    } /* 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 () */
    27852610
    27862611} /* class FeedWordPress */
  • TabularUnified feedwordpress/trunk/feedwordpress_parser.class.php

    r641309 r2229752  
    22class FeedWordPress_Parser extends SimplePie_Parser {
    33    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
    417        xml_parser_free($xml);
    518               
     
    1326    }
    1427   
    15     function parse (&$data, $encoding) {
     28    public function parse (&$data, $encoding) {
    1629        $data = apply_filters('feedwordpress_parser_parse', $data, $encoding, $this);
    1730       
     
    96109            if (!$parseResults and $endOfJunk > 0) :
    97110                // 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);
    100113                $this->reset_parser($xml);
    101114           
    102                 $parseResults = xml_parse($xml, $newData, true);
     115                $parseResults = xml_parse($xml, $data, true);
    103116            endif;
    104117           
    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) {
    121131                $this->error_code = xml_get_error_code($xml);
    122132                $this->error_string = xml_error_string($this->error_code);
    123                 ///*DBG*/ echo "WOOGA WOOGA"; var_dump($this->error_string); die;
    124133                $return = false;
    125134            }
     
    241250        return true;
    242251    } /* 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'     => '&#34;',
     271            'amp'      => '&#38;',
     272            'lt'       => '&#60;',
     273            'gt'       => '&#62;',
     274            'OElig'    => '&#338;',
     275            'oelig'    => '&#339;',
     276            'Scaron'   => '&#352;',
     277            'scaron'   => '&#353;',
     278            'Yuml'     => '&#376;',
     279            'circ'     => '&#710;',
     280            'tilde'    => '&#732;',
     281            'ensp'     => '&#8194;',
     282            'emsp'     => '&#8195;',
     283            'thinsp'   => '&#8201;',
     284            'zwnj'     => '&#8204;',
     285            'zwj'      => '&#8205;',
     286            'lrm'      => '&#8206;',
     287            'rlm'      => '&#8207;',
     288            'ndash'    => '&#8211;',
     289            'mdash'    => '&#8212;',
     290            'lsquo'    => '&#8216;',
     291            'rsquo'    => '&#8217;',
     292            'sbquo'    => '&#8218;',
     293            'ldquo'    => '&#8220;',
     294            'rdquo'    => '&#8221;',
     295            'bdquo'    => '&#8222;',
     296            'dagger'   => '&#8224;',
     297            'Dagger'   => '&#8225;',
     298            'permil'   => '&#8240;',
     299            'lsaquo'   => '&#8249;',
     300            'rsaquo'   => '&#8250;',
     301            'euro'     => '&#8364;',
     302            'fnof'     => '&#402;',
     303            'Alpha'    => '&#913;',
     304            'Beta'     => '&#914;',
     305            'Gamma'    => '&#915;',
     306            'Delta'    => '&#916;',
     307            'Epsilon'  => '&#917;',
     308            'Zeta'     => '&#918;',
     309            'Eta'      => '&#919;',
     310            'Theta'    => '&#920;',
     311            'Iota'     => '&#921;',
     312            'Kappa'    => '&#922;',
     313            'Lambda'   => '&#923;',
     314            'Mu'       => '&#924;',
     315            'Nu'       => '&#925;',
     316            'Xi'       => '&#926;',
     317            'Omicron'  => '&#927;',
     318            'Pi'       => '&#928;',
     319            'Rho'      => '&#929;',
     320            'Sigma'    => '&#931;',
     321            'Tau'      => '&#932;',
     322            'Upsilon'  => '&#933;',
     323            'Phi'      => '&#934;',
     324            'Chi'      => '&#935;',
     325            'Psi'      => '&#936;',
     326            'Omega'    => '&#937;',
     327            'alpha'    => '&#945;',
     328            'beta'     => '&#946;',
     329            'gamma'    => '&#947;',
     330            'delta'    => '&#948;',
     331            'epsilon'  => '&#949;',
     332            'zeta'     => '&#950;',
     333            'eta'      => '&#951;',
     334            'theta'    => '&#952;',
     335            'iota'     => '&#953;',
     336            'kappa'    => '&#954;',
     337            'lambda'   => '&#955;',
     338            'mu'       => '&#956;',
     339            'nu'       => '&#957;',
     340            'xi'       => '&#958;',
     341            'omicron'  => '&#959;',
     342            'pi'       => '&#960;',
     343            'rho'      => '&#961;',
     344            'sigmaf'   => '&#962;',
     345            'sigma'    => '&#963;',
     346            'tau'      => '&#964;',
     347            'upsilon'  => '&#965;',
     348            'phi'      => '&#966;',
     349            'chi'      => '&#967;',
     350            'psi'      => '&#968;',
     351            'omega'    => '&#969;',
     352            'thetasym' => '&#977;',
     353            'upsih'    => '&#978;',
     354            'piv'      => '&#982;',
     355            'bull'     => '&#8226;',
     356            'hellip'   => '&#8230;',
     357            'prime'    => '&#8242;',
     358            'Prime'    => '&#8243;',
     359            'oline'    => '&#8254;',
     360            'frasl'    => '&#8260;',
     361            'weierp'   => '&#8472;',
     362            'image'    => '&#8465;',
     363            'real'     => '&#8476;',
     364            'trade'    => '&#8482;',
     365            'alefsym'  => '&#8501;',
     366            'larr'     => '&#8592;',
     367            'uarr'     => '&#8593;',
     368            'rarr'     => '&#8594;',
     369            'darr'     => '&#8595;',
     370            'harr'     => '&#8596;',
     371            'crarr'    => '&#8629;',
     372            'lArr'     => '&#8656;',
     373            'uArr'     => '&#8657;',
     374            'rArr'     => '&#8658;',
     375            'dArr'     => '&#8659;',
     376            'hArr'     => '&#8660;',
     377            'forall'   => '&#8704;',
     378            'part'     => '&#8706;',
     379            'exist'    => '&#8707;',
     380            'empty'    => '&#8709;',
     381            'nabla'    => '&#8711;',
     382            'isin'     => '&#8712;',
     383            'notin'    => '&#8713;',
     384            'ni'       => '&#8715;',
     385            'prod'     => '&#8719;',
     386            'sum'      => '&#8721;',
     387            'minus'    => '&#8722;',
     388            'lowast'   => '&#8727;',
     389            'radic'    => '&#8730;',
     390            'prop'     => '&#8733;',
     391            'infin'    => '&#8734;',
     392            'ang'      => '&#8736;',
     393            'and'      => '&#8743;',
     394            'or'       => '&#8744;',
     395            'cap'      => '&#8745;',
     396            'cup'      => '&#8746;',
     397            'int'      => '&#8747;',
     398            'there4'   => '&#8756;',
     399            'sim'      => '&#8764;',
     400            'cong'     => '&#8773;',
     401            'asymp'    => '&#8776;',
     402            'ne'       => '&#8800;',
     403            'equiv'    => '&#8801;',
     404            'le'       => '&#8804;',
     405            'ge'       => '&#8805;',
     406            'sub'      => '&#8834;',
     407            'sup'      => '&#8835;',
     408            'nsub'     => '&#8836;',
     409            'sube'     => '&#8838;',
     410            'supe'     => '&#8839;',
     411            'oplus'    => '&#8853;',
     412            'otimes'   => '&#8855;',
     413            'perp'     => '&#8869;',
     414            'sdot'     => '&#8901;',
     415            'lceil'    => '&#8968;',
     416            'rceil'    => '&#8969;',
     417            'lfloor'   => '&#8970;',
     418            'rfloor'   => '&#8971;',
     419            'lang'     => '&#9001;',
     420            'rang'     => '&#9002;',
     421            'loz'      => '&#9674;',
     422            'spades'   => '&#9824;',
     423            'clubs'    => '&#9827;',
     424            'hearts'   => '&#9829;',
     425            'diams'    => '&#9830;',
     426            'nbsp'     => '&#160;',
     427            'iexcl'    => '&#161;',
     428            'cent'     => '&#162;',
     429            'pound'    => '&#163;',
     430            'curren'   => '&#164;',
     431            'yen'      => '&#165;',
     432            'brvbar'   => '&#166;',
     433            'sect'     => '&#167;',
     434            'uml'      => '&#168;',
     435            'copy'     => '&#169;',
     436            'ordf'     => '&#170;',
     437            'laquo'    => '&#171;',
     438            'not'      => '&#172;',
     439            'shy'      => '&#173;',
     440            'reg'      => '&#174;',
     441            'macr'     => '&#175;',
     442            'deg'      => '&#176;',
     443            'plusmn'   => '&#177;',
     444            'sup2'     => '&#178;',
     445            'sup3'     => '&#179;',
     446            'acute'    => '&#180;',
     447            'micro'    => '&#181;',
     448            'para'     => '&#182;',
     449            'middot'   => '&#183;',
     450            'cedil'    => '&#184;',
     451            'sup1'     => '&#185;',
     452            'ordm'     => '&#186;',
     453            'raquo'    => '&#187;',
     454            'frac14'   => '&#188;',
     455            'frac12'   => '&#189;',
     456            'frac34'   => '&#190;',
     457            'iquest'   => '&#191;',
     458            'Agrave'   => '&#192;',
     459            'Aacute'   => '&#193;',
     460            'Acirc'    => '&#194;',
     461            'Atilde'   => '&#195;',
     462            'Auml'     => '&#196;',
     463            'Aring'    => '&#197;',
     464            'AElig'    => '&#198;',
     465            'Ccedil'   => '&#199;',
     466            'Egrave'   => '&#200;',
     467            'Eacute'   => '&#201;',
     468            'Ecirc'    => '&#202;',
     469            'Euml'     => '&#203;',
     470            'Igrave'   => '&#204;',
     471            'Iacute'   => '&#205;',
     472            'Icirc'    => '&#206;',
     473            'Iuml'     => '&#207;',
     474            'ETH'      => '&#208;',
     475            'Ntilde'   => '&#209;',
     476            'Ograve'   => '&#210;',
     477            'Oacute'   => '&#211;',
     478            'Ocirc'    => '&#212;',
     479            'Otilde'   => '&#213;',
     480            'Ouml'     => '&#214;',
     481            'times'    => '&#215;',
     482            'Oslash'   => '&#216;',
     483            'Ugrave'   => '&#217;',
     484            'Uacute'   => '&#218;',
     485            'Ucirc'    => '&#219;',
     486            'Uuml'     => '&#220;',
     487            'Yacute'   => '&#221;',
     488            'THORN'    => '&#222;',
     489            'szlig'    => '&#223;',
     490            'agrave'   => '&#224;',
     491            'aacute'   => '&#225;',
     492            'acirc'    => '&#226;',
     493            'atilde'   => '&#227;',
     494            'auml'     => '&#228;',
     495            'aring'    => '&#229;',
     496            'aelig'    => '&#230;',
     497            'ccedil'   => '&#231;',
     498            'egrave'   => '&#232;',
     499            'eacute'   => '&#233;',
     500            'ecirc'    => '&#234;',
     501            'euml'     => '&#235;',
     502            'igrave'   => '&#236;',
     503            'iacute'   => '&#237;',
     504            'icirc'    => '&#238;',
     505            'iuml'     => '&#239;',
     506            'eth'      => '&#240;',
     507            'ntilde'   => '&#241;',
     508            'ograve'   => '&#242;',
     509            'oacute'   => '&#243;',
     510            'ocirc'    => '&#244;',
     511            'otilde'   => '&#245;',
     512            'ouml'     => '&#246;',
     513            'divide'   => '&#247;',
     514            'oslash'   => '&#248;',
     515            'ugrave'   => '&#249;',
     516            'uacute'   => '&#250;',
     517            'ucirc'    => '&#251;',
     518            'uuml'     => '&#252;',
     519            'yacute'   => '&#253;',
     520            'thorn'    => '&#254;',
     521            'yuml'     => '&#255;'
     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  
    1818   
    1919    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 () */
    2226   
    2327    public function meta ($what, $params = array()) {
     
    3236        ));
    3337   
     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
    3444        // This is a little weird, just bear with me here.
    3545        $results = array();
     
    153163
    154164    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);
    156173    }
    157174   
    158175    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);
    160184    }
    161185
    162186    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);
    164193    }
    165194   
    166195    public function get_categories () {
     196        if (is_null($this->post) or !is_object($this->post)) :
     197            return array();
     198        endif;
     199
    167200        $terms = wp_get_object_terms(
    168201            $this->post->ID,
  • TabularUnified feedwordpress/trunk/feedwordpresssyndicationpage.class.php

    r1749912 r2229752  
    140140                    endforeach;
    141141                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__);
    143143                endif;
    144144            elseif (!is_null(MyPHP::post('update_uri'))) :
     
    147147                    $targets = array($targets);
    148148                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;
    153154                endif;
    154155                $update_set = $targets;
     
    440441            <div class="metabox-holder">       
    441442            <?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);
    443444            ?>
    444445            </div> <!-- class="metabox-holder" -->
     
    455456
    456457    function dashboard_box ($page, $box = NULL) {
    457         global $fwp_path;
    458 
    459458        $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
    460459        $sources = $this->sources('*');
     
    478477        // Hey ho, let's go...
    479478        ?>
    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>
    481480
    482481        <p class="info" style="margin-bottom: 0px; border-bottom: 1px dotted black;">Managed by <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>
     
    537536          <?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); ?>
    538537          <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>
    540539          </form>
    541540        </div> <!-- id="add-single-uri" -->
     
    547546   
    548547    function syndicated_sources_box ($page, $box = NULL) {
    549         global $fwp_path;
    550548
    551549        $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
     
    603601          <input type="hidden" name="action" value="feedfinder" />
    604602          <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>
    606604          <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>
    608606          </li>
    609607          </ul>
     
    11991197
    12001198function fwp_switchfeed_page () {
    1201     global $wpdb, $wp_db_version;
     1199    global $wpdb;
    12021200    global $fwp_post, $fwp_path;
    12031201
  • TabularUnified feedwordpress/trunk/performance-page.php

    r1551908 r2229752  
    1313
    1414    function display () {
    15         global $wpdb, $wp_db_version, $fwp_path;
    16         global $fwp_post;
    17 
    1815        if (FeedWordPress::needs_upgrade()) :
    1916            fwp_upgrade_page();
     
    2522
    2623        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);
    2926        endif;
    3027
     
    5653            <div class="metabox-holder">
    5754            <?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);
    5956            ?>
    6057            </div> <!-- class="metabox-holder" -->
  • TabularUnified feedwordpress/trunk/readme.txt

    r1749912 r2229752  
    11=== FeedWordPress ===
    22Contributors: C. Johnson
    3 Donate link: http://feedwordpress.radgeek.com/
     3Donate link: http://feedwordpress.radgeek.com/donate/
    44Tags: syndication, aggregation, feed, atom, rss
    55Requires at least: 4.5
    6 Tested up to: 4.8.2
    7 Stable tag: 2017.1020
     6Tested up to: 5.3.2
     7Stable tag: 2020.0118
     8License: GPLv2 or later
     9License URI: https://www.gnu.org/licenses/gpl-2.0.html
    810
    911FeedWordPress syndicates content from feeds you choose into your WordPress weblog.
     
    2123FeedWordPress 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.
    2224
    23   [WordPress]: http://wordpress.org/
    24   [WordPress MU]: http://mu.wordpress.org/
     25  [WordPress]: https://wordpress.org/
    2526  [4.5]: http://codex.wordpress.org/Version_4.5
    2627
     
    2930To use FeedWordPress, you will need:
    3031
    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).
    3233
    3334*   the ability to install new plugins on your site using either WordPress's Plugins Repository, SFTP, FTP or shell access to your web host
     
    19201921== License ==
    19211922
    1922 The FeedWordPress plugin is copyright © 2005-2017 by Charles Johnson. It uses
    1923 code derived or translated from:
     1923The FeedWordPress plugin is copyright © 2005-2017 by Charles Johnson. It uses code derived or translated from:
    19241924
    19251925-   [wp-rss-aggregate.php][] by [Kellan Elliot-McCrea](kellan@protest.net)
     
    19311931according to the terms of the [GNU General Public License][].
    19321932
    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.
     1933This 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
     1935This 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.
    19411936
    19421937  [wp-rss-aggregate.php]: http://laughingmeme.org/archives/002203.html
  • TabularUnified feedwordpress/trunk/syndicatedlink.class.php

    r1553712 r2229752  
    129129    } /* SyndicatedLink::live_posts () */
    130130
     131    protected function pause_updates () {
     132        return ('yes'==$this->setting("update/pause", "update_pause", 'no'));
     133    } /* SyndicatedLink::pause_updates () */
     134
    131135    public function poll ($crash_ts = NULL) {
    132136        global $wpdb;
     
    211215                endif;
    212216            endif;
     217
     218            $this->update_setting('link/feed_type', $this->simplepie->get_type());
    213219
    214220            $this->merge_settings($channel, 'feed/');
     
    276282            if (is_array($posts)) :
    277283                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;
    285298                        endif;
    286299
    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;                 
    295302                endforeach;
    296303            endif;
     
    300307                // <http://tools.ietf.org/html/draft-snell-atompub-tombstones-18>
    301308                $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) :
    303310                    foreach ($tombstones as $tombstone) :
    304311                        $ref = NULL;
     
    741748    } /* SyndicatedLink::is_non_incremental () */
    742749
     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   
    743786    public function uri ($params = array()) {
    744787        $params = wp_parse_args($params, array(
  • TabularUnified feedwordpress/trunk/syndicatedpost.class.php

    r1749912 r2229752  
    12291229
    12301230        if ($this->filtered()) : // This should never happen.
    1231             FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
     1231            FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
    12321232        endif;
    12331233
     
    12451245            if ($q->have_posts()) :
    12461246                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;
    12481250                endwhile;
    12491251            endif;
     
    13061308                    endif;
    13071309
    1308                     if ($updated and FeedWordPress::diagnostic_on('feed_items:freshness:reasons')) :
     1310                    if ($updated and FeedWordPressDiagnostic::is_on('feed_items:freshness:reasons')) :
    13091311                        // In the absence of definitive
    13101312                        // timestamp information, we
     
    14521454    function wp_id () {
    14531455        if ($this->filtered()) : // This should never happen.
    1454             FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
     1456            FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
    14551457        endif;
    14561458
     
    14611463    }
    14621464
     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     */
    14631608    public function store () {
    14641609        global $wpdb;
    14651610
    14661611        if ($this->filtered()) : // This should never happen.
    1467             FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
     1612            FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
    14681613        endif;
    14691614
    14701615        $freshness = $this->freshness();
    14711616        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();
    15771622        endif;
    15781623
     
    17871832    } /* function SyndicatedPost::insert_post () */
    17881833
     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     */
    17891840    function insert_new () {
    17901841        $this->insert_post(/*update=*/ false, 1);
    17911842    } /* SyndicatedPost::insert_new() */
    17921843
     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     */
    17931850    function update_existing () {
    17941851        $this->insert_post(/*update=*/ true, 2);
     
    19351992$ns::_wp_id
    19361993EOM;
    1937             FeedWordPress::noncritical_bug(
     1994            FeedWordPressDiagnostic::noncritical_bug(
    19381995                /*message=*/ $mesg,
    19391996                /*var =*/ array(
     
    21432200
    21442201        $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        }
    21522210
    21532211        $email = (isset($a['email']) ? $a['email'] : NULL);
     
    22532311                    $userdata = array();
    22542312
    2255                     // WordPress 3 is going to pitch a fit if we attempt to register
    2256                     // more than one user account with an empty e-mail address, so we
    2257                     // 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.)
    22582316                    if (strlen($email) == 0 or FeedWordPress::is_null_email($email)) :
    22592317                        $url = parse_url($hostUrl);
     
    22692327                    $userdata['user_url'] = $authorUrl;
    22702328                    $userdata['nickname'] = $author;
     2329
    22712330                    $parts = preg_split('/\s+/', trim($author), 2);
    22722331                    if (isset($parts[0])) : $userdata['first_name'] = $parts[0]; endif;
    22732332                    if (isset($parts[1])) : $userdata['last_name'] = $parts[1]; endif;
     2333
    22742334                    $userdata['display_name'] = $author;
    22752335                    $userdata['role'] = 'contributor';
    22762336
    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 {
    22782340                        $id = wp_insert_user($userdata);
    22792341                        if (is_wp_error($id)) :
     
    22862348                                break;
    22872349                            case 'user_nicename_too_long' :
    2288                                 // Add a limited 50 caracters user_nicename based on user_login
     2350                                // Add a limited 50 characters user_nicename based on user_login
    22892351                                                $userdata['user_nicename'] = mb_substr( $userdata['user_login'], 0, 50 );
    22902352                                break;
    22912353                            case 'existing_user_email' :
    2292                                 // No disassemble!
     2354                                // Disassemble email for username, host
    22932355                                $parts = explode('@', $userdata['user_email'], 2);
    22942356
     
    23022364                        endif;
    23032365                    } 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
    23042374                elseif (is_numeric($unfamiliar_author) and get_userdata((int) $unfamiliar_author)) :
    23052375                    $id = (int) $unfamiliar_author;
  • TabularUnified feedwordpress/trunk/syndicatedpostterm.class.php

    r1413324 r2229752  
    182182           
    183183                // If debug mode is ON, this will halt us here.
    184                 FeedWordPress::noncritical_bug(
     184                FeedWordPressDiagnostic::noncritical_bug(
    185185                    'term insertion problem', array(
    186186                        'term' => $this->term,
    187187                        'result' => $aTerm,
    188                         'post' => $post,
     188                        'post' => $this->post,
    189189                        'this' => $this
    190190                    ), __LINE__, __FILE__
Note: See TracChangeset for help on using the changeset viewer.