Changeset 1880


Ignore:
Timestamp:
02/16/2011 10:29:14 AM (15 months ago)
Author:
Xiping.Wang
Message:

[trunk] upgrade wordpress plugin feedwordpress to 2011.0211.2

Location:
trunk/blogs/wp-content/plugins/feedwordpress
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/blogs/wp-content/plugins/feedwordpress/admin-ui.php

    r1874 r1880  
    33        var $context; 
    44        var $updated = false; 
     5        var $mesg = NULL; 
     6 
    57        var $link = NULL; 
    68        var $dispatch = NULL; 
     
    4446 
    4547        function accept_POST ($post) { 
    46                 if ($this->save_requested_in($post)) : // User mashed Save Changes 
     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 
    4751                        $this->save_settings($post); 
    4852                endif; 
    49                 do_action($this->dispatch.'_post', $post, $this);                
     53                do_action($this->dispatch.'_post', &$post, &$this);              
     54        } 
     55 
     56        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                print '<div class="updated">'; 
     63                print "<ul>"; 
     64                $uri = $this->link->uri(); 
     65                $delta = $feedwordpress->update($uri); 
     66                print "</ul>"; 
     67 
     68                if (!is_null($delta)) : 
     69                        $mesg = array(); 
     70                        if (isset($delta['new'])) : $mesg[] = ' '.$delta['new'].' new posts were syndicated'; endif; 
     71                        if (isset($delta['updated'])) : $mesg[] = ' '.$delta['updated'].' existing posts were updated'; endif; 
     72                        echo "<p><strong>Update complete.</strong>".implode(' and', $mesg)."</p>"; 
     73                        echo "\n"; flush(); 
     74                else : 
     75                        $uri = esc_html($uri); 
     76                        echo "<p><strong>Error:</strong> There was a problem updating <a href=\"$uri\">$uri</a></p>\n"; 
     77                endif; 
     78                print "</div>\n"; 
     79                remove_action('feedwordpress_check_feed', 'update_feeds_mention'); 
     80                remove_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3); 
    5081        } 
    5182 
    5283        function save_settings ($post) { 
     84                do_action($this->dispatch.'_save', &$post, &$this); 
     85 
    5386                if ($this->for_feed_settings()) : 
    5487                        // Save settings 
     
    6396                        $this->updated = true; 
    6497                endif; 
    65                 do_action($this->dispatch.'_save', $post, $this); 
    6698        } /* FeedWordPressAdminPage::save_settings () */ 
    6799 
    68100        function for_feed_settings () { return (is_object($this->link) and method_exists($this->link, 'found') and $this->link->found()); } 
    69101        function for_default_settings () { return !$this->for_feed_settings(); } 
     102 
     103        function setting ($names, $fallback_value = NULL, $params = array()) { 
     104                if (!is_array($params)) : 
     105                        $params = array('default' => $params); 
     106                endif; 
     107                $params = shortcode_atts(array( 
     108                'default' => 'default', 
     109                'fallback' => true, 
     110                ), $params); 
     111 
     112                if (is_string($names)) : 
     113                        $feed_name = $names; 
     114                        $global_name = 'feedwordpress_'.preg_replace('![\s/]+!', '_', $names); 
     115                else : 
     116                        $feed_name = $names['feed']; 
     117                        $global_name = 'feedwordpress_'.$names['global']; 
     118                endif; 
     119 
     120                if ($this->for_feed_settings()) : // Check feed-specific setting first; fall back to global 
     121                        if (!$params['fallback']) : $global_name = NULL; endif;  
     122                        $ret = $this->link->setting($feed_name, $global_name, $fallback_value, $params['default']); 
     123                else : // Check global setting 
     124                        $ret = get_option($global_name, $fallback_value); 
     125                endif; 
     126                return $ret; 
     127        } 
    70128 
    71129        function update_setting ($names, $value, $default = 'default') { 
     
    88146                return (isset($post['save']) or isset($post['submit'])); 
    89147        } 
    90  
     148        function update_requested_in ($post) { 
     149                return (isset($post['update']) and (strlen($post['update']) > 0)); 
     150        } 
     151         
    91152        /*static*/ function submitted_link_id () { 
    92153                global $fwp_post; 
     
    263324                <?php endforeach; endif; ?> 
    264325                </select> 
    265                 <input class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" /></li> 
     326                <input id="fwpfs-button" class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" /></li> 
    266327 
    267328                <?php 
     
    272333                        'subscription' => $this->link, 
    273334                )); 
    274                 ?> 
    275                 </ul> 
     335                 
     336                if ($this->for_feed_settings()) : 
     337                ?> 
     338                <li><input class="button" type="submit" name="update" value="Update Now" /></li> 
     339                <?php 
     340                endif; 
     341                ?> 
     342                </ul>            
    276343                </div> 
    277344                <?php 
     
    286353 
    287354        function display_update_notice_if_updated ($pagename = 'Syndication', $mesg = NULL) { 
     355                if (!is_null($mesg)) : 
     356                        $this->mesg = $mesg; 
     357                endif; 
     358 
    288359                if ($this->updated) : 
    289360                        if ($this->updated === true) : 
    290                                 $mesg = $pagename . ' settings updated.'; 
     361                                $this->mesg = $pagename . ' settings updated.'; 
    291362                        else : 
    292                                 $mesg = $this->updated; 
     363                                $this->mesg = $this->updated; 
    293364                        endif; 
    294365                endif; 
    295366                 
    296                 if (!is_null($mesg)) : 
     367                if (!is_null($this->mesg)) : 
    297368                        ?> 
    298369                        <div class="updated"> 
    299                         <p><?php print esc_html($mesg); ?></p> 
     370                        <p><?php print esc_html($this->mesg); ?></p> 
    300371                        </div> 
    301372                        <?php 
     
    329400 
    330401        function update_message () { 
    331                 return NULL; 
     402                return $this->mesg; 
    332403        } 
    333404 
     
    494565                // labels for each potential value. For use in Currently: line. 
    495566                if (isset($params['labels'])) : $labels = $params['labels']; 
     567                elseif (is_callable($options)) : $labels = NULL; 
    496568                else : $labels = $options; 
    497569                endif; 
     
    573645                        <strong><?php if (is_callable($labels)) : 
    574646                                print call_user_func($labels, $globalSetting, $defaulted, $params); 
     647                        elseif (is_null($labels)) : 
     648                                print $globalSetting; 
    575649                        else : 
    576650                                print $labels[$globalSetting]; 
     
    677751        $desc = "<p style=\"font-size:smaller;font-style:bold;margin:0\">Tag $object as...</p>"; 
    678752 
     753        if (isset($params['textarea_name'])) : 
     754                $textAreaName = $params['textarea_name']; 
     755        else : 
     756                $textAreaName = "tax_input[$tax_name]"; 
     757        endif; 
    679758        print $desc; 
    680759        $helps = __('Separate tags with commas.'); 
     
    685764                <div class="nojs-tags hide-if-js"> 
    686765                <p><?php _e('Add or remove tags'); ?></p> 
    687                 <textarea name="<?php echo "tax_input[$tax_name]"; ?>" class="the-tags" id="tax-input[<?php echo $tax_name; ?>]"><?php echo esc_attr(implode(",", $tags)); ?></textarea></div> 
     766                <textarea name="<?php echo esc_html($textAreaName); ?>" class="the-tags" id="tax-input[<?php echo $tax_name; ?>]"><?php echo esc_attr(implode(",", $tags)); ?></textarea></div> 
    688767         
    689768                <div class="ajaxtag hide-if-no-js"> 
     
    806885        $ret = array(); 
    807886 
    808         $users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY display_name"); 
     887        $users = get_users_of_blog(); 
    809888        if (is_array($users)) : 
    810889                foreach ($users as $user) : 
     
    849928                ?> 
    850929                <style type="text/css"> 
     930                #feedwordpress-admin-feeds .link-rss-params-remove .x, .feedwordpress-admin .remove-it .x { 
     931                        background: url(<?php print admin_url('images/xit.gif') ?>) no-repeat scroll 0 0 transparent; 
     932                } 
     933 
     934                #feedwordpress-admin-feeds .link-rss-params-remove:hover .x, .feedwordpress-admin .remove-it:hover .x { 
     935                        background: url(<?php print admin_url('images/xit.gif') ?>) no-repeat scroll -10px 0 transparent; 
     936                } 
     937 
    851938                .fwpfs { 
    852939                        background-image: url(<?php print admin_url('images/fav.png'); ?>); 
     
    891978         
    892979        function magic_input_tip_js ($id) { 
     980                        if (!preg_match('/^[.#]/', $id)) : 
     981                                $id = '#'.$id; 
     982                        endif; 
    893983                ?> 
    894984                        <script type="text/javascript"> 
    895985                        jQuery(document).ready( function () { 
    896                                 var inputBox = jQuery("#<?php print $id; ?>"); 
     986                                var inputBox = jQuery("<?php print $id; ?>"); 
    897987                                var boxEl = inputBox.get(0); 
    898988                                if (boxEl.value==boxEl.defaultValue) { inputBox.addClass('form-input-tip'); } 
     
    10701160                                <?php endif; ?> 
    10711161 
    1072         <td><?php print $lastUpdated; ?> 
     1162        <td><div style="float: right; padding-left: 10px"> 
     1163        <input type="submit" class="button" name="update_uri[<?php print esc_html($link->link_rss); ?>]" value="<?php _e('Update Now'); ?>" /> 
     1164        </div> 
     1165        <?php print $lastUpdated; ?> 
    10731166        <?php print $errorsSince; ?> 
    10741167        <?php print $nextUpdate; ?> 
  • trunk/blogs/wp-content/plugins/feedwordpress/authors-page.php

    r1874 r1880  
    66        var $rule_count = 0; 
    77         
    8         function FeedWordPressAuthorsPage ($link) { 
     8        function FeedWordPressAuthorsPage ($link = -1) { 
     9                if (is_numeric($link) and -1 == $link) : 
     10                        $link = FeedWordPressAdminPage::submitted_link(); 
     11                endif; 
     12 
    913                FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpressauthors', $link); 
    1014                $this->refresh_author_list(); 
    1115                $this->dispatch = 'feedwordpress_author_settings'; 
    1216                $this->filename = __FILE__; 
     17 
     18                $this->pagenames = array( 
     19                        'default' => 'Authors', 
     20                        'settings-update' => 'Syndicated Authors', 
     21                        'open-sheet' => 'Syndicated Author', 
     22                ); 
    1323        } 
    1424         
     
    2232 
    2333                if ($page->for_feed_settings()) : 
    24                         $key = $link->setting('unfamiliar author', NULL, 'site-default'); 
     34                        $key = $this->link->setting('unfamiliar author', NULL, 'site-default'); 
    2535                        $unfamiliar['site-default'] = ''; 
    2636                else : 
     
    3545                ?> 
    3646<table class="form-table"> 
    37 <tbody> 
    38 <tr> 
    39   <th>New authors</th> 
    40   <td><span>Authors who haven't been syndicated before</span> 
    41   <select style="max-width: 27.0em" id="unfamiliar-author" name="unfamiliar_author" onchange="contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');"> 
    42 <?php if ($page->for_feed_settings()) : ?> 
    43     <option value="site-default"<?php print $unfamiliar['site-default']; ?>>are handled according to the default for all feeds</option> 
    44 <?php endif; ?> 
    45     <option value="create"<?php print $unfamiliar['create']; ?>>will have a new author account created for them</option> 
    46     <?php foreach ($page->authorlist as $author_id => $author_name) : ?> 
    47       <option value="<?php echo $author_id; ?>"<?php print (isset($unfamiliar[$author_id]) ? $unfamiliar[$author_id] : ''); ?>>will have their posts attributed to <?php echo $author_name; ?></option> 
     47<?php 
     48if ($page->for_feed_settings()) : 
     49        $map = $this->link->setting('map authors', NULL, array()); 
     50?> 
     51<tr><th>Matching authors</th> 
     52<td><p>How should FeedWordPress attribute posts from this feed to WordPress 
     53authors?</p> 
     54<ul class="settings"> 
     55<li><p><input type="radio" name="author_rules_name[all]" value="*" 
     56<?php if (isset($map['name']['*'])) : $author_action = $map['name']['*']; ?> 
     57        checked="checked" 
     58<?php else : $author_action = NULL; ?> 
     59<?php endif; ?> 
     60        /> All posts syndicated 
     61from this feed <select class="author-rules" id="author-rules-all" 
     62name="author_rules_action[all]" onchange="contextual_appearance('author-rules-all', 'author-rules-all-newuser', 'author-rules-all-default', 'newuser', 'inline');"> 
     63    <?php foreach ($page->authorlist as $local_author_id => $local_author_name) : ?> 
     64    <option value="<?php echo $local_author_id; ?>"<?php if ($local_author_id==$author_action) : echo ' selected="selected"'; endif; ?>>are assigned to <?php echo $local_author_name; ?></option> 
    4865    <?php endforeach; ?> 
    49     <option value="newuser">will have their posts attributed to a new user...</option> 
    50     <option value="filter"<?php print $unfamiliar['filter'] ?>>get filtered out</option> 
     66    <option value="newuser">will be assigned to a new user...</option> 
     67    <option value="filter"<?php if ('filter'==$author_action) : echo ' selected="selected"'; endif; ?>>get filtered out</option> 
    5168  </select> 
    52  
    53   <span id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></span></p> 
    54   </td> 
    55 </tr> 
    56  
    57 <?php 
    58 if ($page->for_feed_settings()) : 
     69  <span class="author-rules-newuser" id="author-rules-all-newuser">named 
     70  <input type="text" name="author_rules_newuser[all]" value="" /></span></p></li> 
     71<li><p><input type="radio" name="author_rules_name[all]" value="" 
     72<?php if (!isset($map['name']['*'])) : ?> 
     73        checked="checked" 
     74<?php endif; ?> 
     75/> Attribute posts to authors based on automatic mapping rules. (Blank out a 
     76name to delete the rule. Fill in a new name at the bottom to create a new rule.)</p> 
     77 
     78<table style="width: 100%"> 
     79<?php 
     80        if (isset($this->link->settings['map authors'])) : 
    5981?> 
    60 <tr><th>Syndicated authors</th> 
    61 <td>For attributing posts by specific authors. Blank out a name to delete the rule. Fill in a new name at the bottom to create a new rule.</p> 
    62 <table style="width: 100%"> 
    63 <?php 
    64         if (isset($link->settings['map authors'])) : 
    65 ?> 
    6682<?php 
    6783                $page->rule_count=0; 
    68                 foreach ($link->settings['map authors'] as $author_rules) : 
     84                foreach ($this->link->settings['map authors'] as $author_rules) : 
    6985                        foreach ($author_rules as $author_name => $author_action) : 
    70                                 $page->rule_count++;  
     86                                if ($author_name != '*') : 
     87                                        $page->rule_count++;  
    7188?> 
    7289<tr> 
    7390<th style="text-align: left; width: 15.0em">Posts by <input type="text" name="author_rules_name[]" value="<?php echo htmlspecialchars($author_name); ?>" size="11" /></th> 
    7491  <td> 
    75   <select id="author-rules-<?php echo $page->rule_count; ?>" name="author_rules_action[]" onchange="contextual_appearance('author-rules-<?php echo $page->rule_count; ?>', 'author-rules-<?php echo $page->rule_count; ?>-newuser', 'author-rules-<?php echo $page->rule_count; ?>-default', 'newuser', 'inline');"> 
     92  <select class="author-rules" id="author-rules-<?php echo $page->rule_count; ?>" name="author_rules_action[]" onchange="contextual_appearance('author-rules-<?php echo $page->rule_count; ?>', 'author-rules-<?php echo $page->rule_count; ?>-newuser', 'author-rules-<?php echo $page->rule_count; ?>-default', 'newuser', 'inline');"> 
    7693    <?php foreach ($page->authorlist as $local_author_id => $local_author_name) : ?> 
    7794    <option value="<?php echo $local_author_id; ?>"<?php if ($local_author_id==$author_action) : echo ' selected="selected"'; endif; ?>>are assigned to <?php echo $local_author_name; ?></option> 
     
    8198  </select> 
    8299   
    83   <span id="author-rules-<?php echo $page->rule_count; ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span> 
     100  <span class="author-rules-newuser" id="author-rules-<?php echo $page->rule_count; ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></span> 
    84101  </td> 
    85102</tr> 
    86 <?php                   endforeach; 
     103<?php 
     104                                endif; 
     105                        endforeach; 
    87106                endforeach; 
    88107        endif; 
     
    103122   </td> 
    104123</tr> 
    105 </table> 
     124 
     125<tr> 
     126<th style="text-align: left; width: 15.0em">Unmatched authors</th> 
     127<td> 
     128<span>Authors who haven't been syndicated before</span> 
     129  <select style="max-width: 27.0em" id="unfamiliar-author" name="unfamiliar_author" onchange="contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');"> 
     130<?php if ($page->for_feed_settings()) : ?> 
     131    <option value="site-default"<?php print $unfamiliar['site-default']; ?>>are handled according to the default for all feeds</option> 
     132<?php endif; ?> 
     133    <option value="create"<?php print $unfamiliar['create']; ?>>will have a new author account created for them</option> 
     134    <?php foreach ($page->authorlist as $author_id => $author_name) : ?> 
     135      <option value="<?php echo $author_id; ?>"<?php print (isset($unfamiliar[$author_id]) ? $unfamiliar[$author_id] : ''); ?>>will have their posts attributed to <?php echo $author_name; ?></option> 
     136    <?php endforeach; ?> 
     137    <option value="newuser">will have their posts attributed to a user named ...</option> 
     138    <option value="filter"<?php print $unfamiliar['filter'] ?>>get filtered out</option> 
     139  </select> 
     140 
     141  <span id="unfamiliar-author-newuser"><input type="text" name="unfamiliar_author_newuser" value="" /></span></p> 
     142</td> 
     143</tr> 
     144</table></li> 
     145</ul> 
     146 
    106147</td> 
    107148</tr> 
     
    156197                <?php 
    157198        } /* FeedWordPressAuthorsPage::fix_authors_box () */ 
    158 } /* class FeedWordPressAuthorsPage */ 
    159  
    160 function fwp_authors_page () { 
    161         global $wpdb, $wp_db_version; 
    162  
    163         if (FeedWordPress::needs_upgrade()) : 
    164                 fwp_upgrade_page(); 
    165                 return; 
    166         endif; 
    167  
    168         FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_author_settings', /*capability=*/ 'manage_links'); 
    169  
    170         $link = FeedWordPressAdminPage::submitted_link(); 
    171         $authorsPage = new FeedWordPressAuthorsPage($link); 
    172  
    173         $mesg = null; 
    174         $updated_link = false; 
    175  
    176         if (isset($GLOBALS['fwp_post']['fix_mismatch'])) : 
    177                 if ('newuser'==$GLOBALS['fwp_post']['fix_mismatch_to']) : 
    178                         $newuser_name = trim($GLOBALS['fwp_post']['fix_mismatch_to_newuser']); 
    179                         $fix_mismatch_to_id = fwp_insert_new_user($newuser_name); 
     199 
     200        function display () { 
     201                $this->boxes_by_methods = array( 
     202                'syndicated_authors_box' => __('Syndicated Authors'), 
     203                'fix_authors_box' => __('Reassign Authors'), 
     204                ); 
     205                if ($this->for_default_settings()) : 
     206                        unset($this->boxes_by_methods['fix_authors_box']); 
     207                endif; 
     208 
     209                parent::display(); 
     210                ?> 
     211<script type="text/javascript"> 
     212        contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline'); 
     213</script> 
     214 
     215<?php           if ($this->for_feed_settings()) : ?> 
     216<script type="text/javascript"> 
     217        jQuery('.author-rules').each ( function () { 
     218                contextual_appearance(this.id, this.id+'-newuser', this.id+'-default', 'newuser', 'inline'); 
     219        } ); 
     220 
     221        contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline'); 
     222        contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline'); 
     223</script> 
     224<?php           else : ?> 
     225<script type="text/javascript"> 
     226        contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true); 
     227</script> 
     228<?php           endif; 
     229        } /* FeedWordPressAuthorsPage::display () */ 
     230 
     231        function accept_POST ($post) { 
     232                if (isset($post['fix_mismatch']) and (strlen($post['fix_mismatch']) > 0)) : 
     233                        $this->fix_mismatch($post); 
    180234                else : 
    181                         $fix_mismatch_to_id = $GLOBALS['fwp_post']['fix_mismatch_to']; 
    182                 endif; 
    183                 $fix_mismatch_from_id = (int) $GLOBALS['fwp_post']['fix_mismatch_from']; 
    184                 if (is_numeric($fix_mismatch_from_id)) : 
    185                         // Make a list of all the items by this author syndicated from this feed... 
     235                        parent::accept_POST($post); 
     236                endif; 
     237        } 
     238 
     239        function fix_mismatch ($post) { 
     240                global $wpdb; 
     241 
     242                if ('newuser'==$post['fix_mismatch_to']) : 
     243                        $newuser_name = trim($post['fix_mismatch_to_newuser']); 
     244                        $to = fwp_insert_new_user($newuser_name); 
     245                else : 
     246                        $to = $post['fix_mismatch_to']; 
     247                endif; 
     248 
     249                $from = (int) $post['fix_mismatch_from']; 
     250                if (is_numeric($from)) : 
     251                        // Make a list of all the items by this author 
     252                        // syndicated from this feed... 
    186253                        $post_ids = $wpdb->get_col(" 
    187254                        SELECT {$wpdb->posts}.id 
     
    189256                        WHERE ({$wpdb->posts}.id = {$wpdb->postmeta}.post_id) 
    190257                        AND {$wpdb->postmeta}.meta_key = 'syndication_feed_id' 
    191                         AND {$wpdb->postmeta}.meta_value = '{$link->id}' 
    192                         AND {$wpdb->posts}.post_author = '{$fix_mismatch_from_id}' 
     258                        AND {$wpdb->postmeta}.meta_value = '{$this->link->id}' 
     259                        AND {$wpdb->posts}.post_author = '{$from}' 
    193260                        "); 
    194261                         
    195262                        if (count($post_ids) > 0) : 
     263                                $N = count($post_ids); 
     264                                $posts = 'post'.(($N==1) ? '' : 's'); 
     265 
    196266                                // Re-assign them all to the correct author 
    197                                 if (is_numeric($fix_mismatch_to_id)) : // re-assign to a particular user 
     267                                if (is_numeric($to)) : // re-assign to a particular user 
    198268                                        $post_set = "(".implode(",", $post_ids).")"; 
    199269                                         
     
    203273                                        $wpdb->query(" 
    204274                                        UPDATE {$wpdb->posts} 
    205                                         SET post_author='{$fix_mismatch_to_id}' 
     275                                        SET post_author='{$to}' 
    206276                                        WHERE ({$wpdb->posts}.id IN $post_set 
    207277                                        $parent_in_clause) 
    208278                                        "); 
    209                                         $mesg = "Re-assigned ".count($post_ids)." post".((count($post_ids)==1)?'':'s')."."; 
     279                                        $this->mesg = sprintf(__("Re-assigned %d ${posts}."), $N); 
    210280 
    211281                                // ... and kill them all 
    212                                 elseif ($fix_mismatch_to_id=='filter') : 
     282                                elseif ('filter'==$to) : 
    213283                                        foreach ($post_ids as $post_id) : 
    214284                                                wp_delete_post($post_id); 
    215                                         endforeach;                                              
    216                                         $mesg = "Deleted ".count($post_ids)." post".((count($post_ids)==1)?'':'s')."."; 
     285                                        endforeach; 
     286                         
     287                                        $this->mesg = sprintf(__("Deleted %d ${posts}."), $N); 
    217288                                endif; 
    218289                        else : 
    219                                 $mesg = "Couldn't find any posts that matched your criteria."; 
    220                         endif; 
    221                 endif; 
    222                 $updated_link = false; 
    223         elseif (isset($GLOBALS['fwp_post']['save'])) : 
    224                 if (is_object($link) and $link->found()) : 
     290                                $this->mesg = __("Couldn't find any posts that matched your criteria."); 
     291                        endif; 
     292                endif; 
     293                $this->updated = false; 
     294        } 
     295 
     296        function save_settings ($post) { 
     297 
     298                if ($this->for_feed_settings()) : 
    225299                        $alter = array (); 
    226300 
    227301                        // Unfamiliar author rule 
    228                         if (isset($GLOBALS['fwp_post']["unfamiliar_author"])) : 
    229                                 if ('site-default'==$GLOBALS['fwp_post']["unfamiliar_author"]) : 
    230                                         unset($link->settings["unfamiliar author"]); 
    231                                 elseif ('newuser'==$GLOBALS['fwp_post']["unfamiliar_author"]) : 
    232                                         $newuser_name = trim($GLOBALS['fwp_post']["unfamiliar_author_newuser"]); 
    233                                         $link->map_name_to_new_user(/*name=*/ NULL, $newuser_name); 
     302                        if (isset($post["unfamiliar_author"])) : 
     303                                if ('newuser'==$post['unfamiliar_author']) : 
     304                                        $new_name = trim($post["unfamiliar_author_newuser"]); 
     305                                        $this->link->map_name_to_new_user(/*name=*/ NULL, $new_name); 
    234306                                else : 
    235                                         $link->settings["unfamiliar author"] = $GLOBALS['fwp_post']["unfamiliar_author"]; 
     307                                        $this->link->update_setting( 
     308                                                "unfamiliar author", 
     309                                                $post['unfamiliar_author'], 
     310                                                'site-default' 
     311                                        ); 
    236312                                endif; 
    237313                        endif; 
    238314                         
    239315                        // Handle author mapping rules 
    240                         if (isset($GLOBALS['fwp_post']['author_rules_name']) and isset($GLOBALS['fwp_post']['author_rules_action'])) : 
    241                                 unset($link->settings['map authors']); 
    242                                 foreach ($GLOBALS['fwp_post']['author_rules_name'] as $key => $name) : 
     316                        if (isset($post['author_rules_name']) 
     317                        and isset($post['author_rules_action'])) : 
     318                                if (isset($post['author_rules_name']['all'])) : 
     319                                        if (strlen($post['author_rules_name']['all']) > 0) : 
     320                                                $post['author_rules_name'] = array( 
     321                                                        'all' => $post['author_rules_name']['all'], 
     322                                                ); 
     323                                                 
     324                                                // Erase all the rest. 
     325                                        endif; 
     326                                endif; 
     327                                 
     328                                unset($this->link->settings['map authors']); 
     329                                foreach ($post['author_rules_name'] as $key => $name) : 
    243330                                        // Normalize for case and whitespace 
    244331                                        $name = strtolower(trim($name)); 
    245                                         $author_action = strtolower(trim($GLOBALS['fwp_post']['author_rules_action'][$key])); 
     332                                        $author_action = strtolower(trim($post['author_rules_action'][$key])); 
    246333                                         
    247334                                        if (strlen($name) > 0) : 
    248335                                                if ('newuser' == $author_action) : 
    249                                                         $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]); 
    250                                                         $link->map_name_to_new_user($name, $newuser_name); 
     336                                                        $new_name = trim($post['author_rules_newuser'][$key]); 
     337                                                        $this->link->map_name_to_new_user($name, $new_name); 
    251338                                                else : 
    252                                                         $link->settings['map authors']['name'][$name] = $author_action; 
     339                                                        $this->link->settings['map authors']['name'][$name] = $author_action; 
    253340                                                endif; 
    254341                                        endif; 
     
    256343                        endif; 
    257344 
    258                         if (isset($GLOBALS['fwp_post']['add_author_rule_name']) and isset($GLOBALS['fwp_post']['add_author_rule_action'])) : 
    259                                 $name = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_name'])); 
    260                                 $author_action = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_action'])); 
     345                        if (isset($post['add_author_rule_name']) 
     346                        and isset($post['add_author_rule_action'])) : 
     347                                $name = strtolower(trim($post['add_author_rule_name'])); 
     348                                $author_action = strtolower(trim($post['add_author_rule_action'])); 
     349                                 
    261350                                if (strlen($name) > 0) : 
    262351                                        if ('newuser' == $author_action) : 
    263                                                 $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']); 
    264                                                 $link->map_name_to_new_user($name, $newuser_name); 
     352                                                $new_name = trim($post['add_author_rule_newuser']); 
     353                                                $this->link->map_name_to_new_user($name, $new_name); 
    265354                                        else : 
    266                                                 $link->settings['map authors']['name'][$name] = $author_action; 
     355                                                $this->link->settings['map authors']['name'][$name] = $author_action; 
    267356                                        endif; 
    268357                                endif; 
    269358                        endif; 
    270                          
    271                         // Save settings 
    272                         $link->save_settings(/*reload=*/ true); 
    273                         $updated_link = true; 
    274                          
    275                         // Reset, reload 
    276                         $link_id = $link->id; 
    277                         unset($link); 
    278                         $link = new SyndicatedLink($link_id); 
    279359                else : 
    280                         if ('newuser'==$GLOBALS['fwp_post']['unfamiliar_author']) : 
    281                                 $newuser_name = trim($GLOBALS['fwp_post']['unfamiliar_author_newuser']); 
    282                                 $newuser_id = fwp_insert_new_user($newuser_name); 
    283                                 if (is_numeric($newuser_id)) : 
    284                                         update_option('feedwordpress_unfamiliar_author', $newuser_id); 
     360                        if ('newuser'==$post['unfamiliar_author']) : 
     361                                $new_name = trim($post['unfamiliar_author_newuser']); 
     362                                $new_id = fwp_insert_new_user($new_name); 
     363                                if (is_numeric($new_id)) : 
     364                                        update_option('feedwordpress_unfamiliar_author', $new_id); 
    285365                                else : 
    286366                                        // TODO: Add some error detection and reporting 
     367                                        // Put WP_Error stuff into $this->mesg ? 
    287368                                endif; 
    288369                        else : 
    289                                 update_option('feedwordpress_unfamiliar_author', $GLOBALS['fwp_post']['unfamiliar_author']); 
    290                         endif; 
    291  
    292                         if (isset($GLOBALS['fwp_post']['match_author_by_email']) and $GLOBALS['fwp_post']['match_author_by_email']=='yes') : 
    293                                 update_option('feedwordpress_do_not_match_author_by_email', 'no'); 
    294                         else : 
    295                                 update_option('feedwordpress_do_not_match_author_by_email', 'yes'); 
    296                         endif; 
    297  
    298                         if (isset($GLOBALS['fwp_post']['null_emails'])) : 
    299                                 update_option('feedwordpress_null_email_set', $GLOBALS['fwp_post']['null_emails']); 
    300                         endif; 
    301                          
    302                         $updated_link = true; 
    303                 endif; 
    304  
    305                 do_action('feedwordpress_admin_page_authors_save', $GLOBALS['fwp_post'], $authorsPage); 
    306                 $authorsPage->refresh_author_list(); 
    307         else : 
    308                 $updated_link = false; 
    309         endif; 
    310          
    311         //////////////////////////////////////////////// 
    312         // Prepare settings page /////////////////////// 
    313         //////////////////////////////////////////////// 
    314  
    315         if ($updated_link) : 
    316 ?> 
    317 <div class="updated"><p>Syndicated author settings updated.</p></div> 
    318 <?php elseif (!is_null($mesg)) : ?> 
    319 <div class="updated"><p><?php print esc_html($mesg); ?></p></div> 
    320 <?php endif; 
    321  
    322         if (function_exists('add_meta_box')) : 
    323                 add_action( 
    324                         FeedWordPressCompatibility::bottom_script_hook(__FILE__), 
    325                         /*callback=*/ array($authorsPage, 'fix_toggles'), 
    326                         /*priority=*/ 10000 
    327                 ); 
    328                 FeedWordPressSettingsUI::ajax_nonce_fields(); 
    329         endif; 
    330  
    331         $authorsPage->open_sheet('Syndicated Author'); 
    332         ?> 
    333         <div id="post-body"> 
    334         <?php 
    335         //////////////////////////////////////////////// 
    336         // Display settings boxes ////////////////////// 
    337         //////////////////////////////////////////////// 
    338  
    339         $boxes_by_methods = array( 
    340                 'syndicated_authors_box' => __('Syndicated Authors'), 
    341                 'fix_authors_box' => __('Reassign Authors'), 
    342         ); 
    343         if ($authorsPage->for_default_settings()) : 
    344                 unset($boxes_by_methods['fix_authors_box']); 
    345         endif; 
    346  
    347         foreach ($boxes_by_methods as $method => $row) : 
    348                 if (is_array($row)) : 
    349                         $id = $row['id']; 
    350                         $title = $row['title']; 
    351                 else : 
    352                         $id = 'feedwordpress_'.$method; 
    353                         $title = $row; 
    354                 endif; 
    355  
    356                 add_meta_box( 
    357                         /*id=*/ $id, 
    358                         /*title=*/ $title, 
    359                         /*callback=*/ array('FeedWordPressAuthorsPage', $method), 
    360                         /*page=*/ $authorsPage->meta_box_context(), 
    361                         /*context=*/ $authorsPage->meta_box_context() 
    362                 ); 
    363         endforeach; 
    364         do_action('feedwordpress_admin_page_authors_meta_boxes', $authorsPage); 
    365 ?> 
    366         <div class="metabox-holder"> 
    367 <?php 
    368         fwp_do_meta_boxes($authorsPage->meta_box_context(), $authorsPage->meta_box_context(), $authorsPage); 
    369 ?> 
    370         </div> <!-- class="metabox-holder" --> 
    371 </div> <!-- id="post-body" --> 
    372 <?php $authorsPage->close_sheet(); ?> 
    373  
    374 <script type="text/javascript"> 
    375         contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline'); 
    376 <?php if (is_object($link) and $link->found()) : ?> 
    377 <?php   for ($j=1; $j<=$authorsPage->rule_count; $j++) : ?> 
    378         contextual_appearance('author-rules-<?php echo $j; ?>', 'author-rules-<?php echo $j; ?>-newuser', 'author-rules-<?php echo $j; ?>-default', 'newuser', 'inline'); 
    379 <?php   endfor; ?> 
    380         contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline'); 
    381         contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline'); 
    382 <?php else : ?> 
    383         contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true); 
    384 <?php endif; ?> 
    385 </script> 
    386 <?php 
    387 } /* function fwp_authors_page () */ 
    388  
    389         fwp_authors_page(); 
    390  
     370                                update_option('feedwordpress_unfamiliar_author', $post['unfamiliar_author']); 
     371                        endif; 
     372 
     373                        update_option('feedwordpress_do_not_match_author_by_email', 
     374                                (isset($post['match_author_by_email']) 
     375                                 and 'yes'==$post['match_author_by_email']) 
     376                                ? 'no' 
     377                                : 'yes' 
     378                        ); 
     379 
     380                        if (isset($post['null_emails'])) : 
     381                                update_option('feedwordpress_null_email_set', $post['null_emails']); 
     382                        endif; 
     383                endif; 
     384 
     385                parent::save_settings($post); 
     386                $this->refresh_author_list(); 
     387        } 
     388} /* class FeedWordPressAuthorsPage */ 
     389 
     390        $authorsPage = new FeedWordPressAuthorsPage; 
     391        $authorsPage->display(); 
     392 
  • trunk/blogs/wp-content/plugins/feedwordpress/categories-page.php

    r1874 r1880  
    458458                        <h4>Site-wide <?php print $taxonomy->labels->name; ?></h4> 
    459459                        <?php if (count($globalCats) > 0) : ?> 
    460                         <ul class="current-setting"> 
    461                         <?php 
    462                         foreach ($globalDogs as $dog) : 
    463                         ?> 
    464                         <li><?php $cat = get_term($dog, $tax); print $cat->name; ?></li> 
    465                         <?php endforeach; ?> 
    466                         </ul> 
    467                         </div> 
    468                         <p> 
     460                          <ul class="current-setting"> 
     461                          <?php foreach ($globalDogs as $dog) : ?> 
     462                            <li><?php $cat = get_term($dog, $tax); print $cat->name; ?></li> 
     463                          <?php endforeach; ?> 
     464                          </ul> 
     465                          </div> 
     466                          <p> 
    469467                        <?php else : ?> 
    470                         <p>Site-wide settings may also assign categories to syndicated 
     468                          <p>Site-wide settings may also assign categories to syndicated 
    471469                        posts. 
    472470                        <?php endif; ?> 
     
    477475                        <ul class="settings"> 
    478476                        <li><p><label><input type="radio" name="add_global[<?php print $tax; ?>]" value="yes" <?php print $checked['yes']; ?> /> Yes. Place <?php print $page->these_posts_phrase(); ?> under all these categories.</label></p></li> 
    479                         <li><p><label><input type="radio" name="add_global[<?php print $tax; ?>]" value="no" <?php print $checked['no']; ?> /> No. Only use the categories I set up on the left. Do not ise the global defaults for <?php print $page->these_posts_phrase(); ?></label></p></li> 
     477                        <li><p><label><input type="radio" name="add_global[<?php print $tax; ?>]" value="no" <?php print $checked['no']; ?> /> No. Only use the categories I set up on the left. Do not use the global defaults for <?php print $page->these_posts_phrase(); ?></label></p></li> 
    480478                        </ul> 
    481479                        </td> 
  • trunk/blogs/wp-content/plugins/feedwordpress/compatability.php

    r1874 r1880  
    55 
    66class FeedWordPressCompatibility { 
    7         // version testing based on database schema version 
     7 
     8        /** 
     9         * FeedWordPressCompatibility::test_version: test version of WordPress 
     10         * based on the database schema version. 
     11         * 
     12         * @param int $floor The minimum version necessary 
     13         * @param mixed $ceiling The first version that is too high. If omitted 
     14         *      or NULL, no version is too high. 
     15         * @return bool TRUE if within the range of versions, FALSE if too low 
     16         *      or too high. 
     17         */ 
    818        /*static*/ function test_version ($floor, $ceiling = null) { 
    919                global $wp_db_version; 
     
    2030                global $wpdb; 
    2131 
    22                 $name = $wpdb->escape($name); 
    23  
    2432                // WordPress 2.3+ term/taxonomy API 
    2533                $term = wp_insert_term($name, 'link_category'); 
    26                 $cat_id = $term['term_id']; 
    27                  
     34 
     35                // OK: returned array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id) 
     36                if (!is_wp_error($term)) : 
     37                        $cat_id = $term['term_id']; 
     38 
     39                // Error: term with this name already exists. Well, let's use that then. 
     40                elseif ($term->get_error_code() == 'term_exists') : 
     41                        // Already-existing term ID is returned in data field 
     42                        $cat_id = $term->get_error_data('term_exists'); 
     43 
     44                // Error: another kind of error, harder to recover from. Return WP_Error. 
     45                else : 
     46                        $cat_id = $term; 
     47                endif; 
     48         
    2849                // Return newly-created category ID 
    2950                return $cat_id; 
     
    121142                return __checked_selected_helper( $disabled, $current, $echo, 'disabled' ); 
    122143        } 
     144} /* if */ 
     145 
     146// Compat 
     147 
     148if (!function_exists('set_post_field')) { 
     149 
     150        /** 
     151         * Update data from a post field based on Post ID 
     152         * 
     153         * Examples of the post field will be, 'post_type', 'post_status', 'post_content', etc. 
     154         * 
     155         * The context values are based off of the taxonomy filter functions and 
     156         * supported values are found within those functions. 
     157         * 
     158         * @uses sanitize_post_field() 
     159         * 
     160         * @param string $field Post field name 
     161         * @param mixed $value New value for post field 
     162         * @param id $post Post ID 
     163         * @return bool Result of UPDATE query 
     164         * 
     165         * Included under terms of GPL from WordPress Ticket #10946 <http://core.trac.wordpress.org/attachment/ticket/10946/post.php.diff> 
     166         */ 
     167        function set_post_field ($field, $value, $post_id) { 
     168                global $wpdb;  
     169 
     170                $post_id = absint($post_id); 
     171                // sigh ... when FWP is active, I need to avoid avoid_kses_munge 
     172                // $value = sanitize_post_field($field, $value, $post_id, 'db');  
     173                return $wpdb->update($wpdb->posts, array($field => $value), array('ID' => $post_id)); 
     174        } /* function set_post_field () */ 
     175 
    123176} /* if */ 
    124177 
     
    141194        endif; 
    142195         
    143         $walker = new FeedWordPress_Walker_Category_Checklist; 
     196        $walker = new FeedWordPress_Walker_Category_Checklist($params); 
    144197        $walker->set_prefix($prefix); 
    145198        $walker->set_taxonomy($taxonomy);  
  • trunk/blogs/wp-content/plugins/feedwordpress/diagnostics-page.php

    r1874 r1880  
    4040                <?php 
    4141                $boxes_by_methods = array( 
    42                         'diagnostics_box' => __('Diagnostics'), 
     42                        'info_box' => __('Diagnostic Information'), 
     43                        'diagnostics_box' => __('Display Diagnostics'), 
    4344                        'updates_box' => __('Updates'), 
    4445                ); 
     
    8384                        update_option('feedwordpress_diagnostics_show', $post['diagnostics_show']); 
    8485 
     86                        if ($post['diagnostics_show'] 
     87                        and in_array('updated_feeds:errors:persistent', $post['diagnostics_show'])) : 
     88                                update_option('feedwordpress_diagnostics_persistent_errors_hours', (int) $post['diagnostics_persistent_error_hours']); 
     89                        else : 
     90                                delete_option('feedwordpress_diagnostics_persistent_errors_hours'); 
     91                        endif; 
     92                         
     93                        if (in_array('email', $post['diagnostics_output'])) : 
     94                                $ded = $post['diagnostics_email_destination']; 
     95                                if ('mailto'==$ded) : 
     96                                        $ded .= ':'.$post['diagnostics_email_destination_address']; 
     97                                endif; 
     98 
     99                                update_option('feedwordpress_diagnostics_email_destination', $ded); 
     100                        else : 
     101                                delete_option('feedwordpress_diagnostics_email_destination'); 
     102                        endif; 
     103                         
    85104                        $this->updated = true; // Default update message 
    86105                endif; 
    87106        } /* FeedWordPressDiagnosticsPage::accept_POST () */ 
    88107 
    89         /*static*/ function diagnostics_box ($page, $box = NULL) { 
     108        function info_box ($page, $box = NULL) { 
     109                        $link_category_id = FeedWordPress::link_category_id(); 
     110                ?> 
     111                <table class="edit-form narrow"> 
     112                <thead style="display: none"> 
     113                <th scope="col">Topic</th> 
     114                <th scope="col">Information</th> 
     115                </thead> 
     116 
     117                <tbody> 
     118                <tr> 
     119                <th scope="row">Version:</th> 
     120                <td>You are using FeedWordPress version <strong><?php print FEEDWORDPRESS_VERSION; ?></strong>.</td> 
     121                </tr> 
     122 
     123                <tr> 
     124                <th scope="row">Link Category:</th> 
     125                <td><?php if (!is_wp_error($link_category_id)) : 
     126                        $term = get_term($link_category_id, 'link_category'); 
     127                ?><p>Syndicated feeds are 
     128                kept in link category #<?php print $term->term_id; ?>, <strong><?php print $term->name; ?></strong>.</p> 
     129                <?php else : ?> 
     130                <p><strong>FeedWordPress has been unable to set up a valid Link Category 
     131                for syndicated feeds.</strong> Attempting to set one up returned an 
     132                <code><?php $link_category_id->get_error_code(); ?></code> error with this 
     133                additional data:</p> 
     134                <table> 
     135                <tbody> 
     136                <tr> 
     137                <th scope="row">Message:</th> 
     138                <td><?php print $link_category_id->get_error_message(); ?></td> 
     139                </tr> 
     140                <?php $data = $link_category_id->get_error_data(); if (!empty($data)) : ?> 
     141                <tr> 
     142                <th scope="row">Auxiliary Data:</th> 
     143                <td><pre><?php print esc_html(FeedWordPress::val($link_category_id->get_error_data())); ?></pre></td> 
     144                </tr> 
     145                <?php endif; ?> 
     146                </table> 
     147                <?php endif; ?></td> 
     148                </tr> 
     149                </table> 
     150 
     151                <?php 
     152        } /* FeedWordPressDiagnosticsPage::info_box () */ 
     153         
     154        function diagnostics_box ($page, $box = NULL) { 
    90155                $settings = array(); 
    91156                $settings['debug'] = (get_option('feedwordpress_debug')=='yes'); 
    92157 
    93158                $diagnostics_output = get_option('feedwordpress_diagnostics_output', array()); 
     159                 
     160                $users = fwp_author_list(); 
     161 
     162                $ded = get_option('feedwordpress_diagnostics_email_destination', 'admins'); 
     163 
     164                if (preg_match('/^mailto:(.*)$/', $ded, $ref)) : 
     165                        $ded_addy = $ref[1]; 
     166                else : 
     167                        $ded_addy = NULL; 
     168                endif; 
    94169                 
    95170                // Hey ho, let's go... 
     
    117192<li><input type="checkbox" name="diagnostics_output[]" value="echo" <?php print (in_array('echo', $diagnostics_output) ? ' checked="checked"' : ''); ?> /> Echo in web browser as they are issued</label></li> 
    118193<li><input type="checkbox" name="diagnostics_output[]" value="echo_in_cronjob" <?php print (in_array('echo_in_cronjob', $diagnostics_output) ? ' checked="checked"' : ''); ?> /> Echo to output when they are issued during an update cron job</label></li> 
    119 <li><input type="checkbox" name="diagnostics_output[]" value="email" <?php print (in_array('email', $diagnostics_output) ? ' checked="checked"' : ''); ?> /> Send a daily email digest to the site administrator</label></li> 
     194<li><input type="checkbox" name="diagnostics_output[]" value="email" <?php print (in_array('email', $diagnostics_output) ? ' checked="checked"' : ''); ?> /> Send a daily email digest to:</label> <select name="diagnostics_email_destination" id="diagnostics-email-destination" size="1"> 
     195<option value="admins"<?php if ('admins'==$ded) : ?> selected="selected"<?php endif; ?>>the site administrators</option> 
     196<?php foreach ($users as $id => $name) : ?> 
     197<option value="user:<?php print (int) $id; ?>"<?php if (sprintf('user:%d', (int) $id)==$ded) : ?> selected="selected"<?php endif; ?>><?php print esc_html($name); ?></option> 
     198<?php endforeach; ?> 
     199<option value="mailto"<?php if (!is_null($ded_addy)) : ?> selected="selected"<?php endif; ?>>another e-mail address...</option> 
     200</select> 
     201<input type="email" id="diagnostics-email-destination-address" name="diagnostics_email_destination_address" value="<?php print $ded_addy; ?>" placeholder="email address" /></li> 
    120202</ul></td> 
    121203</tr> 
    122204</table> 
     205 
     206<script type="text/javascript"> 
     207        contextual_appearance( 
     208                'diagnostics-email-destination', 
     209                'diagnostics-email-destination-address', 
     210                'diagnostics-email-destination-default', 
     211                'mailto', 
     212                'inline' 
     213        ); 
     214        jQuery('#diagnostics-email-destination').change ( function () { 
     215                contextual_appearance( 
     216                        'diagnostics-email-destination', 
     217                        'diagnostics-email-destination-address', 
     218                        'diagnostics-email-destination-default', 
     219                        'mailto', 
     220                        'inline' 
     221                ); 
     222        } );     
     223</script> 
    123224                <?php 
    124225        } /* FeedWordPressDiagnosticsPage::diagnostics_box () */ 
    125226         
    126227        /*static*/ function updates_box ($page, $box = NULL) { 
    127                 $checked = array( 
    128                         'updated_feeds' => '', 'updated_feeds:errors' => '', 
    129                         'updated_feeds:errors:persistent' => '', 
    130                         "syndicated_posts" => '', 'syndicated_posts:meta_data' => '', 
    131                         'feed_items' => '', 
    132                         'memory_usage' => '', 
    133                 ); 
     228                $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2); 
     229                $fields = apply_filters('feedwordpress_diagnostics', array( 
     230                        'Update Diagnostics' => array( 
     231                                'updated_feeds' => 'as each feed checked for updates', 
     232                                'updated_feeds:errors:persistent' => 'when attempts to update a feed have resulted in errors</label> <label>for at least <input type="number" min="1" max="360" step="1" name="diagnostics_persistent_error_hours" value="'.$hours.'" /> hours', 
     233                                'updated_feeds:errors' => 'any time FeedWordPress encounters any errors while checking a feed for updates', 
     234                                'syndicated_posts' => 'as each syndicated post is added to the database', 
     235                                'feed_items' => 'as each syndicated item is considered on the feed', 
     236                                'memory_usage' => 'indicating how much memory was used', 
     237                        ), 
     238                        'Syndicated Post Details' => array( 
     239                                'syndicated_posts:meta_data' => 'as syndication meta-data is added on the post', 
     240                        ), 
     241                ), $page); 
     242                 
     243                foreach ($fields as $section => $items) : 
     244                        foreach ($items as $key => $label) : 
     245                                $checked[$key] = ''; 
     246                        endforeach; 
     247                endforeach; 
    134248 
    135249                $diagnostics_show = get_option('feedwordpress_diagnostics_show', array()); 
     
    141255                ?> 
    142256<table class="edit-form"> 
    143 <tr> 
    144 <th scope="row">Update diagnostics:</th> 
    145 <td><p>Show a diagnostic message...</p> 
    146 <ul class="options"> 
    147 <li><label><input type="checkbox" name="diagnostics_show[]" value="updated_feeds" <?php print $checked['updated_feeds']; ?> /> as each feed checked for updates</label></li> 
    148 <li><label><input type="checkbox" name="diagnostics_show[]" value="updated_feeds:errors:persistent" <?php print $checked['updated_feeds:errors:persistent'] ?> /> when FeedWordPress encounters repeated errors while checking a feed for updates</label></li> 
    149 <li><label><input type="checkbox" name="diagnostics_show[]" value="updated_feeds:errors" <?php print $checked['updated_feeds:errors']; ?> /> any time FeedWordPress encounters any errors while checking a feed for updates</label></li> 
    150 <li><label><input type="checkbox" name="diagnostics_show[]" value="syndicated_posts" <?php print $checked['syndicated_posts']; ?> /> as each syndicated post is added to the database</label></li> 
    151 <li><label><input type="checkbox" name="diagnostics_show[]" value="feed_items" <?php print $checked['feed_items']; ?> /> as each syndicated item is considered on the feed</label></li> 
    152 <li><label><input type="checkbox" name="diagnostics_show[]" value="memory_usage" <?php print $checked['memory_usage']; ?> /> indicating how much memory was used</label></li> 
    153 </ul></td> 
    154 </tr> 
    155 <tr> 
    156 <th>Syndicated post details:</th> 
    157 <td><p>Show a diagnostic message...</p> 
    158 <ul class="options"> 
    159 <li><label><input type="checkbox" name="diagnostics_show[]" value="syndicated_posts:meta_data" <?php print $checked['syndicated_posts:meta_data']; ?> /> as syndication meta-data is added on the post</label></li> 
    160 </ul></td> 
    161 </tr> 
     257        <?php foreach ($fields as $section => $ul) : ?> 
     258          <tr> 
     259          <th scope="row"><?php print esc_html($section); ?>:</th> 
     260          <td><p>Show a diagnostic message...</p> 
     261          <ul class="options"> 
     262          <?php foreach ($ul as $key => $label) : ?> 
     263            <li><label><input 
     264                type="checkbox" name="diagnostics_show[]" 
     265                value="<?php print esc_html($key); ?>" 
     266                <?php print $checked[$key]; ?> /> 
     267            <?php print $label; ?></label></li> 
     268          <?php endforeach; ?> 
     269          </ul></td> 
     270          </tr> 
     271        <?php endforeach; ?> 
    162272</table> 
    163273                <?php 
  • trunk/blogs/wp-content/plugins/feedwordpress/feedfinder.class.php

    r1874 r1880  
    166166                        $client = wp_remote_request($this->uri, array( 
    167167                                'headers' => $headers, 
    168                                 'timeout' => FEEDWORDPRESS_FETCH_TIME_OUT, 
     168                                'timeout' => FeedWordPress::fetch_timeout(), 
    169169                        )); 
    170170 
  • trunk/blogs/wp-content/plugins/feedwordpress/feeds-page.php

    r1874 r1880  
    4848        var $updatedPosts = NULL; 
    4949 
    50         /** 
    51          * Constructs the Feeds page object 
    52          * 
    53          * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings 
    54          */ 
    55         function FeedWordPressFeedsPage ($link = -1) { 
    56                 if (is_numeric($link) and -1 == $link) : 
    57                         $link = FeedWordPressAdminPage::submitted_link(); 
    58                 endif; 
    59  
    60                 FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpressfeeds', $link); 
    61  
    62                 $this->dispatch = 'feedwordpress_admin_page_feeds'; 
    63                 $this->pagenames = array( 
    64                         'default' => 'Feeds', 
    65                         'settings-update' => 'Syndicated feed', 
    66                         'open-sheet' => 'Feed and Update', 
    67                 ); 
    68                 $this->filename = __FILE__; 
    69                 $this->updatedPosts = new UpdatedPostsControl($this); 
    70         } /* FeedWordPressFeedsPage constructor */ 
    71  
    7250        var $special_settings = array ( /* Regular expression syntax is OK here */ 
    7351                'cats', 
    7452                'cat_split', 
     53                'fetch timeout', 
    7554                'freeze updates', 
    7655                'hardcode name', 
     
    8564                'post status', 
    8665                'postmeta', 
     66                'query parameters', 
    8767                'resolve relative', 
    8868                'syndicated post type', 
     
    9272                'unfamiliar category', 
    9373                'unfamiliar post_tag', 
     74                'add/.*', 
    9475                'update/.*', 
    9576                'feed/.*', 
     
    9879        ); 
    9980 
     81        /** 
     82         * Constructs the Feeds page object 
     83         * 
     84         * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings 
     85         */ 
     86        function FeedWordPressFeedsPage ($link = -1) { 
     87                if (is_numeric($link) and -1 == $link) : 
     88                        $link = FeedWordPressAdminPage::submitted_link(); 
     89                endif; 
     90 
     91                FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpressfeeds', $link); 
     92 
     93                $this->dispatch = 'feedwordpress_admin_page_feeds'; 
     94                $this->pagenames = array( 
     95                        'default' => 'Feeds', 
     96                        'settings-update' => 'Syndicated feed', 
     97                        'open-sheet' => 'Feed and Update', 
     98                ); 
     99                $this->filename = __FILE__; 
     100                $this->updatedPosts = new UpdatedPostsControl($this); 
     101                 
     102                $this->special_settings = apply_filters('syndicated_feed_special_settings', $this->special_settings, $this); 
     103        } /* FeedWordPressFeedsPage constructor */ 
     104 
    100105        function display () { 
    101106                global $fwp_post; 
     
    107112                        'updated_posts_box' => __('Updated Posts'), 
    108113                        'custom_settings_box' => __('Custom Feed Settings (for use in templates)'), 
     114                        'fetch_settings_box' => __('Settings for Fetching Feeds (Advanced)'), 
    109115                ); 
    110116                if ($this->for_default_settings()) : 
     
    299305        } /* FeedWordPressFeedsPage::update_window_currently () */ 
    300306         
     307        function fetch_timeout_setting ($setting, $defaulted, $params) { 
     308                $timeout = intval($this->setting('fetch timeout', FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT)); 
     309 
     310                if ($this->for_feed_settings()) : 
     311                        $article = 'this'; 
     312                else : 
     313                        $article = 'a'; 
     314                endif; 
     315                ?> 
     316                <p>Wait no more than 
     317                than <input name="fetch_timeout" type="number" min="0" size="3" value="<?php print $timeout; ?>" /> 
     318                second(s) when trying to fetch <?php print $article; ?> feed to check for updates.</p> 
     319                <p>If <?php print $article; ?> source's web server does not respond before time runs 
     320                out, FeedWordPress will skip over the source and try again during 
     321                the next update cycle.</p> 
     322                <?php 
     323        } 
     324        function fetch_timeout_setting_value ($setting, $defaulted, $params) { 
     325                print number_format(intval($setting)) . " " . (($setting==1) ? "second" : "seconds"); 
     326        } 
     327         
     328        function fetch_settings_box ($page, $box = NULL) { 
     329                $this->setting_radio_control( 
     330                        'fetch timeout', 'fetch_timeout', 
     331                        array(&$this, 'fetch_timeout_setting'), 
     332                        array( 
     333                                'global-setting-default' => FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT, 
     334                                'input-name' => 'fetch_timeout', 
     335                                'default-input-name' => 'fetch_timeout_default', 
     336                                'labels' => array(&$this, 'fetch_timeout_setting_value'), 
     337                        ) 
     338                ); 
     339        } /* FeedWordPressFeedsPage::fetch_settings_box () */ 
     340         
    301341        function feed_information_box ($page, $box = NULL) { 
    302342                global $wpdb; 
     343                $link_rss_params = maybe_unserialize($page->setting('query parameters', '')); 
     344                if (!is_array($link_rss_params)) : 
     345                        $link_rss_params = array(); 
     346                endif; 
     347                 
    303348                if ($page->for_feed_settings()) : 
    304349                        $info['name'] = esc_html($page->link->link->link_name); 
     
    354399                (<a href="<?php echo FEEDVALIDATOR_URI; ?>?url=<?php echo urlencode($rss_url); ?>" 
    355400                title="Check feed &lt;<?php echo esc_html($rss_url); ?>&gt; for validity">validate</a>) 
    356                 <input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" /></td> 
     401                <input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" /> 
     402                 
     403                <table id="link-rss-params"> 
     404                <tbody> 
     405                <?php 
     406                $link_rss_params['new'] = array('', ''); 
     407                $i = 0; 
     408                foreach ($link_rss_params as $index => $pair) : 
     409                ?> 
     410                <tr class="link-rss-params-row" id="link-rss-params-<?php print $index; ?>"> 
     411                <td><label>Parameter: <input type="text" class="link_params_key" 
     412                name="link_rss_params_key[<?php print $index; ?>]" value="<?php print esc_html($pair[0]); ?>" 
     413                size="5" style="width: 5em" placeholder="name" /></label></td> 
     414                <td class="link-rss-params-value-cell"><label class="link_params_value_label">= <input type="text" class="link_params_value" 
     415                name="link_rss_params_value[<?php print $index; ?>]" value="<?php print esc_html($pair[1]); ?>" 
     416                size="8" placeholder="value" /></label></td> 
     417                </tr> 
     418                <?php 
     419                        $i++; 
     420                endforeach; 
     421                ?> 
     422                </tbody> 
     423                </table> 
     424                 
     425                <div><input type="hidden" id="link-rss-params-num" name="link_rss_params_num" value="<?php print $i; ?>" /></div> 
     426                 
     427                <script type="text/javascript"> 
     428                function linkParamsRowRemove (element) { 
     429                        jQuery(element).closest('tr').fadeOut('slow', function () { 
     430                                jQuery(this).remove(); 
     431                        } ); 
     432                } 
     433 
     434                jQuery('<td><a href="#" class="add-remove link-rss-params-remove"><span class="x">(X)</span> Remove</a></td>').insertAfter('.link-rss-params-value-cell'); 
     435 
     436                jQuery('#link-rss-params-new').hide(); 
     437                jQuery('<a  class="add-remove" id="link-rss-params-add" href="#">+ Add a query parameter</a>').insertAfter('#link-rss-params'); 
     438                jQuery('#link-rss-params-add').click( function () { 
     439                        var next = jQuery('#link-rss-params-num').val(); 
     440                        var newRow = jQuery('#link-rss-params-new').clone().attr('id', 'link-rss-params-'+next); 
     441                        newRow.find('.link_params_key').attr('name', 'link_rss_params_key['+next+']'); 
     442                        newRow.find('.link_params_value').attr('name', 'link_rss_params_value['+next+']'); 
     443                         
     444                        newRow.find('.link-rss-params-remove').click( function () { 
     445                                linkParamsRowRemove(this); 
     446                                return false; 
     447                        } ); 
     448 
     449                        newRow.appendTo('#link-rss-params'); 
     450                        newRow.show(); 
     451                         
     452                        // Update counter for next row. 
     453                        next++; 
     454                        jQuery('#link-rss-params-num').val(next); 
     455 
     456                        return false; 
     457                } ); 
     458                jQuery('.link-rss-params-remove').click( function () { 
     459                        linkParamsRowRemove(this); 
     460                        return false; 
     461                } ); 
     462                </script> 
     463                </td> 
    357464                </tr> 
    358465 
     
    736843        function save_settings ($post) { 
    737844                if ($this->for_feed_settings()) : 
     845                        if (isset($post['link_rss_params_key'])) : 
     846                                $qp = array(); 
     847                                foreach ($post['link_rss_params_key'] as $index => $key) : 
     848                                        if (strlen($key) > 0) : 
     849                                                if (isset($post['link_rss_params_value'][$index]) 
     850                                                and strlen($post['link_rss_params_value'][$index])) : 
     851                                                        $value = $post['link_rss_params_value'][$index]; 
     852                                                        $qp[] = array($key, $value); 
     853                                                endif; 
     854                                        endif; 
     855                                endforeach; 
     856                                $this->update_setting('query parameters', serialize($qp)); 
     857                        endif; 
     858                         
    738859                        // custom feed settings first 
    739860                        foreach ($post['notes'] as $mn) : 
     
    804925                                update_option("feedwordpress_hardcode_{$what}", $hardcode); 
    805926                        endforeach; 
     927                         
     928                endif; 
     929                 
     930                if (isset($post['fetch_timeout'])) : 
     931                        if (isset($post['fetch_timeout_default']) and $post['fetch_timeout_default']=='yes') : 
     932                                $timeout = NULL; 
     933                        else : 
     934                                $timeout = $post['fetch_timeout']; 
     935                        endif; 
     936 
     937                        if (is_int($timeout)) : 
     938                                $timeout = intval($timeout); 
     939                        endif; 
     940                        $this->update_setting('fetch timeout', $timeout); 
    806941                endif; 
    807942                 
  • trunk/blogs/wp-content/plugins/feedwordpress/feedtime.class.php

    r1874 r1880  
    104104                                # zulu time, aka GMT 
    105105                        else : 
    106                                 $tz_mod = $match[12]; 
    107                                 $tz_hour = $match[13]; 
    108                                 $tz_min = $match[14]; 
     106                                $tz_mod = (isset($match[12]) ? $match[12] : NULL); 
     107                                $tz_hour = (isset($match[13]) ? $match[13] : NULL); 
     108                                $tz_min = (isset($match[14]) ? $match[14] : NULL); 
    109109 
    110110                                # zero out the variables 
    111                                 if ( ! $tz_hour ) { $tz_hour = 0; } 
    112                                 if ( ! $tz_min ) { $tz_min = 0; } 
     111                                if ( is_null($tz_hour) ) : 
     112                                        $offset = (int) get_option('gmt_offset'); 
     113                                        $tz_hour = abs($offset); 
     114                                        $tz_mod = ((abs($offset) != $offset) ? '-' : '+'); 
     115                                endif; 
     116                                if ( is_null($tz_min) ) : $tz_min = 0; endif; 
    113117                 
    114118                                $offset_secs = (($tz_hour*60)+$tz_min)*60; 
  • trunk/blogs/wp-content/plugins/feedwordpress/feedwordpress-elements.css

    r1874 r1880  
    380380} 
    381381 
     382#feedwordpress-admin-feeds .add-remove, .feedwordpress-admin .remove-it { 
     383        padding-left: 1.5em; 
     384        font-size: 0.80em; 
     385        text-transform: uppercase; 
     386        text-decoration: none !important; 
     387        vertical-align: middle; 
     388} 
     389 
     390#feedwordpress-admin-feeds .link-rss-params-row { vertical-align: middle; } 
     391#feedwordpress-admin-feeds .link-rss-params-remove, .feedwordpress-admin .remove-it { 
     392        display: block; 
     393        padding-left: 0em !important; 
     394        margin-top: 7px; 
     395        color: #777; 
     396} 
     397 
     398#feedwordpress-admin-feeds .link-rss-params-remove:hover, .feedwordpress-admin .remove-it:hover { 
     399        color: #aa3030; 
     400} 
     401 
     402#feedwordpress-admin-feeds .link-rss-params-remove .x, .feedwordpress-admin .remove-it .x { 
     403        cursor: pointer; 
     404        display: block; 
     405        float: left; 
     406        width: 10px; height: 10px; 
     407        margin-right: 2px; 
     408        overflow: hidden; 
     409        text-indent: -9999px; 
     410} 
     411 
     412 
     413#feedwordpress-admin-feeds #link-rss-params td { width: auto !important; } 
     414 
  • trunk/blogs/wp-content/plugins/feedwordpress/feedwordpress-elements.js

    r1874 r1880  
    449449                function () { this.form.submit(); } 
    450450        ); 
    451         $('#fwpfs-container .button').css( 'display', 'none' ); 
     451        $('#fwpfs-button').css( 'display', 'none' ); 
    452452         
    453453        $('table.twofer td.active input[type="radio"], table.twofer td.inactive input[type="radio"]').each( function () { 
  • trunk/blogs/wp-content/plugins/feedwordpress/feedwordpress-walker-category-checklist.class.php

    r1874 r1880  
    1313class FeedWordPress_Walker_Category_Checklist extends Walker_Category_Checklist { 
    1414        var $prefix = ''; var $taxonomy = 'category'; 
    15         function FeedWordPress_Walker_Category_Checklist () { 
     15        var $checkbox_name = NULL; 
     16        function FeedWordPress_Walker_Category_Checklist ($params = array()) { 
    1617                $this->set_taxonomy('category'); 
     18                 
     19                if (isset($params['checkbox_name'])) : 
     20                        $this->checkbox_name = $params['checkbox_name']; 
     21                endif; 
    1722        } 
    1823         
     
    3035                endif;  
    3136 
    32                 if ($taxonomy=='category') : 
     37                if (!is_null($this->checkbox_name)) : 
     38                        $name = $this->checkbox_name; 
     39                elseif ($taxonomy=='category') : 
    3340                        $name = 'post_category'; 
    3441                else : 
  • trunk/blogs/wp-content/plugins/feedwordpress/feedwordpress.php

    r1874 r1880  
    44Plugin URI: http://feedwordpress.radgeek.com/ 
    55Description: simple and flexible Atom/RSS syndication for WordPress 
    6 Version: 2010.0905 
     6Version: 2011.0211.2 
    77Author: Charles Johnson 
    88Author URI: http://radgeek.com/ 
     
    1212/** 
    1313 * @package FeedWordPress 
    14  * @version 2010.0905 
     14 * @version 2011.0211.2 
    1515 */ 
    1616 
     
    3535# -- Don't change these unless you know what you're doing... 
    3636 
    37 define ('FEEDWORDPRESS_VERSION', '2010.0905'); 
     37define ('FEEDWORDPRESS_VERSION', '2011.0211.2'); 
    3838define ('FEEDWORDPRESS_AUTHOR_CONTACT', 'http://radgeek.com/contact'); 
    3939 
     
    8787        define('FEEDWORDPRESS_CACHE_AGE', 1); 
    8888        define('FEEDWORDPRESS_CACHE_LIFETIME', 1); 
    89         define('FEEDWORDPRESS_FETCH_TIME_OUT', 60); 
     89        define('FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT', 60); 
    9090else : 
    9191        // Hold onto data all day for conditional GET purposes, 
     
    9393        define('FEEDWORDPRESS_CACHE_LIFETIME', 24*60*60); 
    9494        define('FEEDWORDPRESS_CACHE_AGE', 1*60); 
    95         define('FEEDWORDPRESS_FETCH_TIME_OUT', 10); 
     95        define('FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT', 20); 
    9696endif; 
    9797 
     
    106106require_once(ABSPATH . WPINC . '/class-feed.php'); 
    107107 
    108 require_once (ABSPATH . WPINC . '/registration.php'); // for wp_insert_user 
     108if (!function_exists('wp_insert_user')) : 
     109        require_once (ABSPATH . WPINC . '/registration.php'); // for wp_insert_user 
     110endif; 
    109111 
    110112require_once(dirname(__FILE__) . '/admin-ui.php'); 
     
    119121// Magic quotes are just about the stupidest thing ever. 
    120122if (is_array($_POST)) : 
    121         $fwp_post = stripslashes_deep($_POST); 
     123        $fwp_post = $_POST; 
     124        if (get_magic_quotes_gpc()) : 
     125                $fwp_post = stripslashes_deep($fwp_post); 
     126        endif; 
    122127endif; 
    123128 
     
    254259                                "Feed Error: [${url}] update returned error: $mesg" 
    255260                        ); 
    256                         if ($error['ts'] > $error['since']) : 
     261                         
     262                        $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2); 
     263                        $span = ($error['ts'] - $error['since']); 
     264 
     265                        if ($span >= ($hours * 60 * 60)) : 
    257266                                $since = date('r', $error['since']); 
    258267                                $mostRecent = date('r', $error['ts']); 
     
    271280                $recipients = array(); 
    272281                foreach ($users as $user) : 
    273                         $dude = new WP_User($user->user_id); 
     282                        $user_id = (isset($user->user_id) ? $user->user_id : $user->ID); 
     283                        $dude = new WP_User($user_id); 
    274284                        if ($dude->has_cap('administrator')) : 
    275285                                if ($dude->user_email) : 
     
    671681 
    672682function fwp_add_pages () { 
    673         global $fwp_path; 
    674  
    675         add_menu_page('Syndicated Sites', 'Syndication', 'manage_links', $fwp_path.'/syndication.php', NULL, WP_PLUGIN_URL.'/'.$fwp_path.'/feedwordpress-tiny.png'); 
    676         do_action('feedwordpress_admin_menu_pre_feeds'); 
    677         add_submenu_page($fwp_path.'/syndication.php', 'Syndicated Feeds & Updates', 'Feeds & Updates', 'manage_options', $fwp_path.'/feeds-page.php'); 
    678         do_action('feedwordpress_admin_menu_pre_posts'); 
    679         add_submenu_page($fwp_path.'/syndication.php', 'Syndicated Posts & Links', 'Posts & Links', 'manage_options', $fwp_path.'/posts-page.php'); 
    680         do_action('feedwordpress_admin_menu_pre_authors'); 
    681         add_submenu_page($fwp_path.'/syndication.php', 'Syndicated Authors', 'Authors', 'manage_options', $fwp_path.'/authors-page.php'); 
    682         do_action('feedwordpress_admin_menu_pre_categories'); 
    683         add_submenu_page($fwp_path.'/syndication.php', 'Categories'.FEEDWORDPRESS_AND_TAGS, 'Categories'.FEEDWORDPRESS_AND_TAGS, 'manage_options', $fwp_path.'/categories-page.php'); 
    684         do_action('feedwordpress_admin_menu_pre_performance'); 
    685         add_submenu_page($fwp_path.'/syndication.php', 'FeedWordPress Performance', 'Performance', 'manage_options', $fwp_path.'/performance-page.php'); 
    686         do_action('feedwordpress_admin_menu_pre_diagnostics'); 
    687         add_submenu_page($fwp_path.'/syndication.php', 'FeedWordPress Diagnostics', 'Diagnostics', 'manage_options', $fwp_path.'/diagnostics-page.php'); 
     683        $menu_cap = FeedWordPress::menu_cap(); 
     684        $settings_cap = FeedWordPress::menu_cap(/*sub=*/ true); 
     685        $syndicationMenu = FeedWordPress::path('syndication.php'); 
     686         
     687        add_menu_page( 
     688                'Syndicated Sites', 'Syndication', 
     689                $menu_cap, 
     690                $syndicationMenu, 
     691                NULL, 
     692                WP_PLUGIN_URL.'/'.FeedWordPress::path('feedwordpress-tiny.png') 
     693        ); 
     694 
     695        do_action('feedwordpress_admin_menu_pre_feeds', $menu_cap, $settings_cap); 
     696        add_submenu_page( 
     697                $syndicationMenu, 'Syndicated Feeds & Updates', 'Feeds & Updates', 
     698                $settings_cap, FeedWordPress::path('feeds-page.php') 
     699        ); 
     700 
     701        do_action('feedwordpress_admin_menu_pre_posts', $menu_cap, $settings_cap); 
     702        add_submenu_page( 
     703                $syndicationMenu, 'Syndicated Posts & Links', 'Posts & Links', 
     704                $settings_cap, FeedWordPress::path('posts-page.php') 
     705        ); 
     706 
     707        do_action('feedwordpress_admin_menu_pre_authors', $menu_cap, $settings_cap); 
     708        add_submenu_page( 
     709                $syndicationMenu, 'Syndicated Authors', 'Authors', 
     710                $settings_cap, FeedWordPress::path('authors-page.php') 
     711        ); 
     712 
     713        do_action('feedwordpress_admin_menu_pre_categories', $menu_cap, $settings_cap); 
     714        add_submenu_page( 
     715                $syndicationMenu, 'Categories'.FEEDWORDPRESS_AND_TAGS, 'Categories'.FEEDWORDPRESS_AND_TAGS, 
     716                $settings_cap, FeedWordPress::path('categories-page.php') 
     717        ); 
     718 
     719        do_action('feedwordpress_admin_menu_pre_performance', $menu_cap, $settings_cap); 
     720        add_submenu_page( 
     721                $syndicationMenu, 'FeedWordPress Performance', 'Performance', 
     722                $settings_cap, FeedWordPress::path('performance-page.php') 
     723        ); 
     724 
     725        do_action('feedwordpress_admin_menu_pre_diagnostics', $menu_cap, $settings_cap); 
     726        add_submenu_page( 
     727                $syndicationMenu, 'FeedWordPress Diagnostics', 'Diagnostics', 
     728                $settings_cap, FeedWordPress::path('diagnostics-page.php') 
     729        ); 
    688730} /* function fwp_add_pages () */ 
    689731 
     
    940982 
    941983                if (is_null($crash_ts)) : 
    942                         $crash_dt = (int) get_option('feedwordpress_update_time_limit'); 
    943                         if ($crash_dt > 0) : 
    944                                 $crash_ts = time() + $crash_dt; 
    945                         else : 
    946                                 $crash_ts = NULL; 
    947                         endif; 
     984                        $crash_ts = $this->crash_ts(); 
    948985                endif; 
    949986 
     
    9911028        } 
    9921029 
     1030        function crash_ts ($default = NULL) { 
     1031                $crash_dt = (int) get_option('feedwordpress_update_time_limit', 0); 
     1032                if ($crash_dt > 0) : 
     1033                        $crash_ts = time() + $crash_dt; 
     1034                else : 
     1035                        $crash_ts = $default; 
     1036                endif; 
     1037                return $crash_ts; 
     1038        } 
     1039         
    9931040        function stale () { 
    9941041                if (get_option('feedwordpress_automatic_updates')) : 
     
    10281075         
    10291076        function dashboard_setup () { 
    1030                 // Get the stylesheet 
    1031                 wp_enqueue_style('feedwordpress-elements'); 
    1032  
    1033                 $widget_id = 'feedwordpress_dashboard'; 
    1034                 $widget_name = __('Syndicated Sources'); 
    1035                 $column = 'side'; 
    1036                 $priority = 'core'; 
    1037  
    1038                 // I would love to use wp_add_dashboard_widget() here and save 
    1039                 // myself some trouble. But WP 3 does not yet have any way to 
    1040                 // push a dashboard widget onto the side, or to give it a default 
    1041                 // location. 
    1042                 add_meta_box( 
    1043                         /*id=*/ $widget_id, 
    1044                         /*title=*/ $widget_name, 
    1045                         /*callback=*/ array(&$this, 'dashboard'), 
    1046                         /*page=*/ 'dashboard', 
    1047                         /*context=*/ $column, 
    1048                         /*priority=*/ $priority 
    1049                 ); 
    1050                 /*control_callback= array(&$this, 'dashboard_control') */ 
    1051                  
    1052                 // This is kind of rude, I know, but the dashboard widget isn't 
    1053                 // worth much if users don't know that it exists, and I don't 
    1054                 // know of any better way to reorder the boxen. 
    1055                 // 
    1056                 // Gleefully ripped off of codex.wordpress.org/Dashboard_Widgets_API 
    1057                  
    1058                 // Globalize the metaboxes array, this holds all the widgets for wp-admin 
    1059                 global $wp_meta_boxes; 
    1060  
    1061                 // Get the regular dashboard widgets array  
    1062                 // (which has our new widget already but at the end) 
    1063  
    1064                 $normal_dashboard = $wp_meta_boxes['dashboard'][$column][$priority]; 
    1065          
    1066                 // Backup and delete our new dashbaord widget from the end of the array 
    1067                 if (isset($normal_dashboard[$widget_id])) : 
    1068                         $backup = array(); 
    1069                         $backup[$widget_id] = $normal_dashboard[$widget_id]; 
    1070                         unset($normal_dashboard[$widget_id]); 
    1071  
    1072                         // Merge the two arrays together so our widget is at the 
    1073                         // beginning 
    1074                         $sorted_dashboard = array_merge($backup, $normal_dashboard); 
    1075  
    1076                         // Save the sorted array back into the original metaboxes  
    1077                         $wp_meta_boxes['dashboard'][$column][$priority] = $sorted_dashboard; 
     1077                $see_it = FeedWordPress::menu_cap(); 
     1078                 
     1079                if (current_user_can($see_it)) : 
     1080                        // Get the stylesheet 
     1081                        wp_enqueue_style('feedwordpress-elements'); 
     1082         
     1083                        $widget_id = 'feedwordpress_dashboard'; 
     1084                        $widget_name = __('Syndicated Sources'); 
     1085                        $column = 'side'; 
     1086                        $priority = 'core'; 
     1087         
     1088                        // I would love to use wp_add_dashboard_widget() here and save 
     1089                        // myself some trouble. But WP 3 does not yet have any way to 
     1090                        // push a dashboard widget onto the side, or to give it a default 
     1091                        // location. 
     1092                        add_meta_box( 
     1093                                /*id=*/ $widget_id, 
     1094                                /*title=*/ $widget_name, 
     1095                                /*callback=*/ array(&$this, 'dashboard'), 
     1096                                /*page=*/ 'dashboard', 
     1097                                /*context=*/ $column, 
     1098                                /*priority=*/ $priority 
     1099                        ); 
     1100                        /*control_callback= array(&$this, 'dashboard_control') */ 
     1101                         
     1102                        // This is kind of rude, I know, but the dashboard widget isn't 
     1103                        // worth much if users don't know that it exists, and I don't 
     1104                        // know of any better way to reorder the boxen. 
     1105                        // 
     1106                        // Gleefully ripped off of codex.wordpress.org/Dashboard_Widgets_API 
     1107                         
     1108                        // Globalize the metaboxes array, this holds all the widgets for wp-admin 
     1109                        global $wp_meta_boxes; 
     1110         
     1111                        // Get the regular dashboard widgets array  
     1112                        // (which has our new widget already but at the end) 
     1113         
     1114                        $normal_dashboard = $wp_meta_boxes['dashboard'][$column][$priority]; 
     1115                 
     1116                        // Backup and delete our new dashbaord widget from the end of the array 
     1117                        if (isset($normal_dashboard[$widget_id])) : 
     1118                                $backup = array(); 
     1119                                $backup[$widget_id] = $normal_dashboard[$widget_id]; 
     1120                                unset($normal_dashboard[$widget_id]); 
     1121         
     1122                                // Merge the two arrays together so our widget is at the 
     1123                                // beginning 
     1124                                $sorted_dashboard = array_merge($backup, $normal_dashboard); 
     1125         
     1126                                // Save the sorted array back into the original metaboxes  
     1127                                $wp_meta_boxes['dashboard'][$column][$priority] = $sorted_dashboard; 
     1128                        endif; 
    10781129                endif; 
    10791130        } /* FeedWordPress::dashboard_setup () */ 
     
    11711222                // Get the category ID# 
    11721223                $cat_id = FeedWordPress::link_category_id(); 
    1173                  
     1224                if (!is_wp_error($cat_id)) : 
     1225                        $link_category = array($cat_id); 
     1226                else : 
     1227                        $link_category = array(); 
     1228                endif; 
     1229 
    11741230                // WordPress gets cranky if there's no homepage URI 
    11751231                if (!is_string($uri) or strlen($uri)<1) : $uri = $rss; endif; 
     
    11811237                "link_name" => $name, 
    11821238                "link_url" => $uri, 
    1183                 "link_category" => array($cat_id), 
     1239                "link_category" => $link_category, 
    11841240                "link_visible" => 'Y', // reactivate if inactivated 
    11851241                )); 
     
    12441300        function syndicated_links ($args = array()) { 
    12451301                $contributors = FeedWordPress::link_category_id(); 
    1246                 $links = get_bookmarks(array_merge( 
    1247                         array("category" => $contributors), 
    1248                         $args 
    1249                 )); 
     1302                if (!is_wp_error($contributors)) : 
     1303                        $links = get_bookmarks(array_merge( 
     1304                                array("category" => $contributors), 
     1305                                $args 
     1306                        )); 
     1307                else : 
     1308                        $links = array(); 
     1309                endif; 
    12501310                return $links; 
    12511311        } // function FeedWordPress::syndicated_links() 
     
    12741334                if (!$cat_id) : 
    12751335                        $cat_id = FeedWordPressCompatibility::insert_link_category(DEFAULT_SYNDICATION_CATEGORY); 
    1276  
    1277                         // Stamp it 
    1278                         update_option('feedwordpress_cat_id', $cat_id); 
     1336                        if (!is_wp_error($cat_id)) : 
     1337                                // Stamp it 
     1338                                update_option('feedwordpress_cat_id', $cat_id); 
     1339                        endif; 
    12791340                endif; 
    12801341 
     
    14051466        } 
    14061467 
    1407         /*static*/ function fetch ($url, $force_feed = true) { 
    1408                 $feed = new SimplePie(); 
     1468        /*static*/ function fetch_timeout () { 
     1469                return apply_filters( 
     1470                        'feedwordpress_fetch_timeout', 
     1471                        intval(get_option('feedwordpress_fetch_timeout', FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT)) 
     1472                ); 
     1473        } 
     1474         
     1475        /*static*/ function fetch ($url, $params = array()) { 
     1476                $force_feed = true; // Default 
     1477 
     1478                // Allow user to change default feed-fetch timeout with a global setting. Props Erigami Scholey-Fuller <http://www.piepalace.ca/blog/2010/11/feedwordpress-broke-my-heart.html>                 'timeout' =>  
     1479                $timeout = FeedWordPress::fetch_timeout(); 
     1480                 
     1481                if (!is_array($params)) : 
     1482                        $force_feed = $params; 
     1483                else : // Parameter array 
     1484                        $args = shortcode_atts(array( 
     1485                        'force_feed' => $force_feed, 
     1486                        'timeout' => $timeout 
     1487                        ), $params); 
     1488                         
     1489                        extract($args); 
     1490                endif; 
     1491                $timeout = intval($timeout); 
     1492                 
     1493                $pie_class = apply_filters('feedwordpress_simplepie_class', 'SimplePie'); 
     1494                $cache_class = apply_filters('feedwordpress_cache_class', 'WP_Feed_Cache'); 
     1495                $file_class = apply_filters('feedwordpress_file_class', 'FeedWordPress_File'); 
     1496                $parser_class = apply_filters('feedwordpress_parser_class', 'FeedWordPress_Parser'); 
     1497 
     1498                $sniffer_class = apply_filters('feedwordpress_sniffer_class', 'FeedWordPress_Content_Type_Sniffer'); 
     1499 
     1500                $feed = new $pie_class; 
    14091501                $feed->set_feed_url($url); 
    1410                 $feed->set_cache_class('WP_Feed_Cache'); 
    1411                 $feed->set_file_class('WP_SimplePie_File'); 
    1412                 $feed->set_content_type_sniffer_class('FeedWordPress_Content_Type_Sniffer'); 
    1413                 $feed->set_file_class('FeedWordPress_File'); 
    1414                 $feed->set_parser_class('FeedWordPress_Parser'); 
     1502                $feed->set_cache_class($cache_class); 
     1503                $feed->set_timeout($timeout); 
     1504                 
     1505                //$feed->set_file_class('WP_SimplePie_File'); 
     1506                $feed->set_content_type_sniffer_class($sniffer_class); 
     1507                $feed->set_file_class($file_class); 
     1508                $feed->set_parser_class($parser_class); 
    14151509                $feed->force_feed($force_feed); 
    14161510                $feed->set_cache_duration(FeedWordPress::cache_duration()); 
     
    15691663        function email_diagnostic_log () { 
    15701664                $dlog = get_option('feedwordpress_diagnostics_log', array()); 
    1571  
    1572                 $recipients = get_option('feedwordpress_diagnostics_log_recipients', NULL); 
    1573                 if (is_null($recipients)) : 
    1574                         $recipients = FeedWordPressDiagnostic::admin_emails(); 
    1575                 endif; 
    15761665                 
    15771666                if (isset($dlog['schedule']) and isset($dlog['schedule']['last'])) : 
     
    16371726 
    16381727EOMAIL; 
     1728 
     1729                                        $ded = get_option('feedwordpress_diagnostics_email_destination', 'admins'); 
     1730 
     1731                                        // e-mail address 
     1732                                        if (preg_match('/^mailto:(.*)$/', $ded, $ref)) : 
     1733                                                $recipients = array($ref[1]); 
     1734                                                 
     1735                                        // userid 
     1736                                        elseif (preg_match('/^user:(.*)$/', $ded, $ref)) : 
     1737                                                $userdata = get_userdata((int) $ref[1]); 
     1738                                                $recipients = array($userdata->user_email); 
     1739                                         
     1740                                        // admins 
     1741                                        else : 
     1742                                                $recipients = FeedWordPressDiagnostic::admin_emails(); 
     1743                                        endif; 
     1744 
    16391745                                        foreach ($recipients as $email) :                                                
    16401746                                                add_filter('wp_mail_content_type', array('FeedWordPress', 'allow_html_mail')); 
     
    16531759                else : 
    16541760                        $dlog['schedule'] = array( 
    1655                                 'freq' =>24 /*hr*/ * 60 /*min*/ * 60 /*s*/, 
     1761                                'freq' => 24 /*hr*/ * 60 /*min*/ * 60 /*s*/, 
    16561762                                'last' => time(), 
    16571763                        ); 
     
    16801786                return $prefix; 
    16811787        } /* FeedWordPress::log_prefix () */ 
     1788         
     1789        function menu_cap ($sub = false) { 
     1790                if ($sub) : 
     1791                        $cap = apply_filters('feedwordpress_menu_settings_capacity', 'manage_options'); 
     1792                else : 
     1793                        $cap = apply_filters('feedwordpress_menu_main_capacity', 'manage_links'); 
     1794                endif; 
     1795                return $cap; 
     1796        } /* FeedWordPress::menu_cap () */ 
     1797         
     1798        function path ($filename = '') { 
     1799                global $fwp_path; 
     1800                 
     1801                $path = $fwp_path; 
     1802                if (strlen($filename) > 0) : 
     1803                        $path .= '/'.$filename; 
     1804                endif; 
     1805                return $path; 
     1806        } 
     1807         
     1808        function param ($key, $type = 'REQUEST', $default = NULL) { 
     1809                $where = '_'.strtoupper($type); 
     1810                $ret = $default; 
     1811                if (isset($GLOBALS[$where]) and is_array($GLOBALS[$where])) : 
     1812                        if (isset($GLOBALS[$where][$key])) : 
     1813                                $ret = $GLOBALS[$where][$key]; 
     1814                                if (get_magic_quotes_gpc()) : 
     1815                                        $ret = stripslashes_deep($ret); 
     1816                                endif; 
     1817                        endif; 
     1818                endif; 
     1819                return $ret; 
     1820        } 
     1821        function post ($key, $default = NULL) { 
     1822                return FeedWordPress::param($key, 'POST'); 
     1823        } 
    16821824} // class FeedWordPress 
    16831825 
  • trunk/blogs/wp-content/plugins/feedwordpress/feedwordpresssyndicationpage.class.php

    r1874 r1880  
    7575 
    7676                if (isset($_POST['update']) or isset($_POST['action']) or isset($_POST['update_uri'])) : 
    77                          // Only do things with side-effects for HTTP POST or command line 
    78                          $fwp_update_invoke = 'post'; 
     77                        // Only do things with side-effects for HTTP POST or command line 
     78                        $fwp_update_invoke = 'post'; 
    7979                else : 
    8080                        $fwp_update_invoke = 'get'; 
     
    8383                $update_set = array(); 
    8484                if ($fwp_update_invoke != 'get') : 
    85                         if (isset($_POST['link_ids']) and is_array($_POST['link_ids']) and ($_POST['action']==FWP_UPDATE_CHECKED)) : 
     85                        if (is_array(FeedWordPress::post('link_ids')) 
     86                        and (FeedWordPress::post('action')==FWP_UPDATE_CHECKED)) : 
    8687                                $targets = $wpdb->get_results(" 
    8788                                SELECT * FROM $wpdb->links 
     
    9596                                        FeedWordPress::critical_bug('fwp_syndication_manage_page::targets', $targets, __LINE__); 
    9697                                endif; 
    97                         elseif (isset($_POST['update_uri'])) : 
    98                                 $targets = $_POST['update_uri']; 
     98                        elseif (!is_null(FeedWordPress::post('update_uri'))) : 
     99                                $targets = FeedWordPress::post('update_uri'); 
    99100                                if (!is_array($targets)) : 
    100101                                        $targets = array($targets); 
     102                                endif; 
     103                                 
     104                                $first = each($targets); 
     105                                if (!is_numeric($first['key'])) : // URLs in keys 
     106                                        $targets = array_keys($targets); 
    101107                                endif; 
    102108                                $update_set = $targets; 
     
    578584                ?> 
    579585 
    580                 <?php   if (count($sources[$visibility]) > 0) : ?> 
    581                         <div style="clear: left" class="alignleft"> 
    582                         <?php if ($showInactive) : ?> 
    583                         <input class="button-secondary" type="submit" name="action" value="<?php print FWP_RESUB_CHECKED; ?>" /> 
    584                         <input class="button-secondary" type="submit" name="action" value="<?php print FWP_DELETE_CHECKED; ?>" /> 
    585                         <?php else : ?> 
    586                         <input class="button-secondary" type="submit" name="action" value="<?php print FWP_UPDATE_CHECKED; ?>" /> 
    587                         <input class="button-secondary delete" type="submit" name="action" value="<?php print FWP_UNSUB_CHECKED; ?>" /> 
    588                         <?php endif ; ?> 
    589                         </div> <!-- class="alignleft" --> 
    590                  
    591                 <?php   else : ?> 
     586                <?php 
     587                if (count($sources[$visibility]) > 0) : 
     588                        $this->display_button_bar($showInactive); 
     589                else : 
     590                ?> 
    592591                        <?php fwp_syndication_manage_page_links_subsubsub($sources, $showInactive); ?> 
    593                 <?php   endif; ?> 
    594          
    595                 <br class="clear" /> 
    596          
    597592                <?php 
     593                endif; 
     594                 
    598595                fwp_syndication_manage_page_links_table_rows($sources[$visibility], $this, $visibility); 
     596                $this->display_button_bar($showInactive); 
    599597                ?> 
    600598                </form> 
    601599                <?php 
    602600        } /* FeedWordPressSyndicationPage::syndicated_sources_box() */ 
     601         
     602        function display_button_bar ($showInactive) { 
     603                ?> 
     604                <div style="clear: left" class="alignleft"> 
     605                <?php if ($showInactive) : ?> 
     606                <input class="button-secondary" type="submit" name="action" value="<?php print FWP_RESUB_CHECKED; ?>" /> 
     607                <input class="button-secondary" type="submit" name="action" value="<?php print FWP_DELETE_CHECKED; ?>" /> 
     608                <?php else : ?> 
     609                <input class="button-secondary" type="submit" name="action" value="<?php print FWP_UPDATE_CHECKED; ?>" /> 
     610                <input class="button-secondary delete" type="submit" name="action" value="<?php print FWP_UNSUB_CHECKED; ?>" /> 
     611                <?php endif ; ?> 
     612                </div> <!-- class="alignleft" --> 
     613                 
     614                <br class="clear" /> 
     615                <?php 
     616        } 
    603617         
    604618        function bleg_thanks ($page, $box = NULL) { 
     
    970984                add_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3); 
    971985 
    972                 $crash_dt = (int) get_option('feedwordpress_update_time_limit'); 
    973                 if ($crash_dt > 0) : 
    974                         $crash_ts = time() + $crash_dt; 
    975                 else : 
    976                         $crash_ts = NULL; 
    977                 endif; 
     986                $crash_ts = $feedwordpress->crash_ts(); 
    978987 
    979988                echo "<div class=\"update-results\">\n"; 
     
    9961005                                endif; 
    9971006                        else : 
    998                                 echo "<li><p><strong>Error:</strong> There was a problem updating <a href=\"$uri\">$uri</a></p></li>\n"; 
     1007                                $display_uri = esc_html(feedwordpress_display_url($uri)); 
     1008                                $uri = esc_html($uri); 
     1009                                echo "<li><p><strong>Error:</strong> There was a problem updating <code><a href=\"$uri\">${display_uri}</a></code></p></li>\n"; 
    9991010                        endif; 
    10001011                endforeach; 
  • trunk/blogs/wp-content/plugins/feedwordpress/magpiefromsimplepie.class.php

    r1874 r1880  
    5959         * 
    6060         * @param SimplePie $pie The feed to convert to MagpieRSS format. 
    61          * 
     61         * @param mixed $item 
     62         * 
     63         * @uses SimplePie::get_items 
     64         * @uses MagpieFromSimplePie::processFeedData 
    6265         * @uses MagpieFromSimplePie::processItemData 
    6366         * @uses MagpieFromSimplePie::normalize  
    64          */ 
    65         function MagpieFromSimplePie ($pie) { 
     67         * @uses MagpieFromSimplePie::is_atom 
     68         */ 
     69        function MagpieFromSimplePie ($pie, $item = true) { 
    6670                $this->pie = $pie; 
    67                 $this->originals = $this->pie->get_items(); 
    68  
    69                 $this->channel = $this->processFeedData($this->pie->data); 
    70                 foreach ($this->originals as $key => $item) : 
    71                         $this->items[$key] = $this->processItemData($item->data); 
    72                 endforeach; 
     71 
     72                // item in {NULL, true} = process channel data 
     73                if (!is_a($item, 'SimplePie_Item')) : 
     74                        $this->originals = $this->pie->get_items(); 
     75 
     76                        $this->channel = $this->processFeedData($this->pie->data); 
     77                else : 
     78                        $this->originals = array($item); 
     79                        $this->channel = NULL; 
     80                endif; 
     81 
     82                // item in {true, SimplePie_Item} = process item data 
     83                if (!is_null($item)) : 
     84                        foreach ($this->originals as $key => $item) : 
     85                                $this->items[$key] = $this->processItemData($item->data); 
     86                        endforeach; 
     87                else : 
     88                        $this->items = NULL; 
     89                endif; 
    7390 
    7491                $this->normalize(); 
     
    8198         
    8299        /** 
    83          * MagpieFromSimplePie::get_item: returns a MagpieRSS format array 
    84          * which is equivalent to the SimplePie_Item object from which this 
     100         * MagpieFromSimplePie::get_items: returns an array of MagpieRSS format arrays 
     101         * equivalent to the SimplePie_Item objects in the SimplePie object from which this 
    85102         * object was constructed. 
    86103         *  
    87          * @return array A MagpieRSS format array representing this feed item. 
     104         * @return array An array of MagpieRSS-format arrays representing the items on this feed 
    88105         */ 
    89106        function get_items () { 
    90107                return $this->items; 
    91         } /* MagpieFromSimplePie::get_item */ 
    92          
     108        } /* MagpieFromSimplePie::get_items () */ 
     109         
     110        /** 
     111         * MagpieFromSimplePie::get_item: returns a single MagpieRSS format array equivalent 
     112         * to a SimplePie_Item object from which this object was constructed. 
     113         * 
     114         * @return array A MagpieRSS-format array representing an item on this feed 
     115         */ 
     116        function get_item () { 
     117                if (is_array($this->items)) : 
     118                        $ret = reset($this->items); 
     119                else : 
     120                        $ret = NULL; 
     121                endif; 
     122                return $ret; 
     123        } /* MagpieFromSimplePie::get_item () */ 
     124 
    93125        /** 
    94126        * MagpieFromSimplePie::processFeedData 
     
    355387         */ 
    356388        function normalize () { 
    357                 // Normalize channel data 
    358                 if ( $this->is_atom() ) : 
    359                         // Atom 1.0 elements <=> Atom 0.3 elements (Thanks, o brilliant wordsmiths of the Atom 1.0 standard!) 
    360                         if ($this->feed_version() < 1.0) : 
    361                                 $this->normalize_element($this->channel, 'tagline', $this->channel, 'subtitle'); 
    362                                 $this->normalize_element($this->channel, 'copyright', $this->channel, 'rights'); 
    363                                 $this->normalize_element($this->channel, 'modified', $this->channel, 'updated'); 
    364                         else : 
    365                                 $this->normalize_element($this->channel, 'subtitle', $this->channel, 'tagline'); 
    366                                 $this->normalize_element($this->channel, 'rights', $this->channel, 'copyright'); 
    367                                 $this->normalize_element($this->channel, 'updated', $this->channel, 'modified'); 
     389                if (!is_null($this->channel)) : 
     390                        // Normalize channel data 
     391                        if ( $this->is_atom() ) : 
     392                                // Atom 1.0 elements <=> Atom 0.3 elements (Thanks, o brilliant wordsmiths of the Atom 1.0 standard!) 
     393                                if ($this->feed_version() < 1.0) : 
     394                                        $this->normalize_element($this->channel, 'tagline', $this->channel, 'subtitle'); 
     395                                        $this->normalize_element($this->channel, 'copyright', $this->channel, 'rights'); 
     396                                        $this->normalize_element($this->channel, 'modified', $this->channel, 'updated'); 
     397                                else : 
     398                                        $this->normalize_element($this->channel, 'subtitle', $this->channel, 'tagline'); 
     399                                        $this->normalize_element($this->channel, 'rights', $this->channel, 'copyright'); 
     400                                        $this->normalize_element($this->channel, 'updated', $this->channel, 'modified'); 
     401                                endif; 
     402                                $this->normalize_element($this->channel, 'author', $this->channel['dc'], 'creator', 'normalize_atom_person'); 
     403                                $this->normalize_element($this->channel, 'contributor', $this->channel['dc'], 'contributor', 'normalize_atom_person'); 
     404         
     405                                // Atom elements to RSS elements 
     406                                $this->normalize_element($this->channel, 'subtitle', $this->channel, 'description'); 
     407                 
     408                                if ( isset($this->channel['logo']) ) : 
     409                                        $this->normalize_element($this->channel, 'logo', $this->image, 'url'); 
     410                                        $this->normalize_element($this->channel, 'link', $this->image, 'link'); 
     411                                        $this->normalize_element($this->channel, 'title', $this->image, 'title'); 
     412                                endif; 
     413 
     414                        elseif ( $this->is_rss() ) : 
     415                                // Normalize image element from where stupid MagpieRSS puts it 
     416                                //$this->normalize_element($this->channel, 'image_title', $this->image, 'title'); 
     417                                //$this->normalize_element($this->channel, 'image_link', $this->image, 'link'); 
     418                                //$this->normalize_element($this->channel, 'image_url', $this->image, 'url'); 
     419 
     420                                // ... and, gag, textInput 
     421                                //$this->normalize_element($this->channel, 'textinput_title', $this->textinput, 'title'); 
     422                                //$this->normalize_element($this->channel, 'textinput_link', $this->textinput, 'link'); 
     423                                //$this->normalize_element($this->channel, 'textinput_name', $this->textinput, 'name'); 
     424                                //$this->normalize_element($this->channel, 'textinput_description', $this->textinput, 'description'); 
     425                         
     426                                // RSS elements to Atom elements 
     427                                $this->normalize_element($this->channel, 'description', $this->channel, 'tagline'); // Atom 0.3 
     428                                $this->normalize_element($this->channel, 'description', $this->channel, 'subtitle'); // Atom 1.0 (yay wordsmithing!) 
     429                                $this->normalize_element($this->image, 'url', $this->channel, 'logo'); 
    368430                        endif; 
    369                         $this->normalize_element($this->channel, 'author', $this->channel['dc'], 'creator', 'normalize_atom_person'); 
    370                         $this->normalize_element($this->channel, 'contributor', $this->channel['dc'], 'contributor', 'normalize_atom_person'); 
    371          
    372                         // Atom elements to RSS elements 
    373                         $this->normalize_element($this->channel, 'subtitle', $this->channel, 'description'); 
    374                  
    375                         if ( isset($this->channel['logo']) ) : 
    376                                 $this->normalize_element($this->channel, 'logo', $this->image, 'url'); 
    377                                 $this->normalize_element($this->channel, 'link', $this->image, 'link'); 
    378                                 $this->normalize_element($this->channel, 'title', $this->image, 'title'); 
    379                         endif; 
    380  
    381                 elseif ( $this->is_rss() ) : 
    382                         // Normalize image element from where stupid MagpieRSS puts it 
    383                         //$this->normalize_element($this->channel, 'image_title', $this->image, 'title'); 
    384                         //$this->normalize_element($this->channel, 'image_link', $this->image, 'link'); 
    385                         //$this->normalize_element($this->channel, 'image_url', $this->image, 'url'); 
    386  
    387                         // ... and, gag, textInput 
    388                         //$this->normalize_element($this->channel, 'textinput_title', $this->textinput, 'title'); 
    389                         //$this->normalize_element($this->channel, 'textinput_link', $this->textinput, 'link'); 
    390                         //$this->normalize_element($this->channel, 'textinput_name', $this->textinput, 'name'); 
    391                         //$this->normalize_element($this->channel, 'textinput_description', $this->textinput, 'description'); 
     431                endif; 
     432 
     433                if (!is_null($this->items)) : 
     434                        // Now loop through and normalize item data 
     435                        for ( $i = 0; $i < count($this->items); $i++) : 
     436                                $item = $this->items[$i]; 
    392437                         
    393                         // RSS elements to Atom elements 
    394                         $this->normalize_element($this->channel, 'description', $this->channel, 'tagline'); // Atom 0.3 
    395                         $this->normalize_element($this->channel, 'description', $this->channel, 'subtitle'); // Atom 1.0 (yay wordsmithing!) 
    396                         $this->normalize_element($this->image, 'url', $this->channel, 'logo'); 
    397                 endif; 
    398                  
    399                 // Now loop through and normalize item data 
    400                 for ( $i = 0; $i < count($this->items); $i++) : 
    401                         $item = $this->items[$i]; 
    402                          
    403                         // if atom populate rss fields and normalize 0.3 and 1.0 feeds 
    404                         if ( $this->is_atom() ) : 
    405                                 // Atom 1.0 elements <=> Atom 0.3 elements 
    406                                 if ($this->feed_version() < 1.0) : 
    407                                         $this->normalize_element($item, 'modified', $item, 'updated'); 
    408                                         $this->normalize_element($item, 'issued', $item, 'published'); 
    409                                 else : 
    410                                         $this->normalize_element($item, 'updated', $item, 'modified'); 
    411                                         $this->normalize_element($item, 'published', $item, 'issued'); 
    412                                 endif; 
    413  
    414                                 $this->normalize_author_inheritance($item, $this->originals[$i]); 
    415          
    416                                 // Atom elements to RSS elements 
    417                                 $this->normalize_element($item, 'author', $item['dc'], 'creator', 'normalize_atom_person'); 
    418                                 $this->normalize_element($item, 'contributor', $item['dc'], 'contributor', 'normalize_atom_person'); 
    419                                 $this->normalize_element($item, 'summary', $item, 'description'); 
    420                                 $this->normalize_element($item, 'atom_content', $item['content'], 'encoded'); 
    421                                 $this->normalize_element($item, 'link_enclosure', $item, 'enclosure', 'normalize_enclosure'); 
    422  
    423                                 // Categories 
    424                                 if ( isset($item['category#']) ) : // Atom 1.0 categories to dc:subject and RSS 2.0 categories 
    425                                         $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category'); 
    426                                 elseif ( isset($item['dc']['subject#']) ) : // dc:subject to Atom 1.0 and RSS 2.0 categories 
    427                                         $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject'); 
    428                                 endif; 
    429  
    430                                 // Normalized item timestamp 
    431                                 $item_date = (isset($item['published']) ) ? $item['published'] : $item['updated']; 
    432                         elseif ( $this->is_rss() ) : 
    433                                 // RSS elements to Atom elements 
    434                                 $this->normalize_element($item, 'description', $item, 'summary'); 
    435                                 $this->normalize_element($item, 'enclosure', $item, 'link_enclosure', 'normalize_enclosure'); 
     438                                // if atom populate rss fields and normalize 0.3 and 1.0 feeds 
     439                                if ( $this->is_atom() ) : 
     440                                        // Atom 1.0 elements <=> Atom 0.3 elements 
     441                                        if ($this->feed_version() < 1.0) : 
     442                                                $this->normalize_element($item, 'modified', $item, 'updated'); 
     443                                                $this->normalize_element($item, 'issued', $item, 'published'); 
     444                                        else : 
     445                                                $this->normalize_element($item, 'updated', $item, 'modified'); 
     446                                                $this->normalize_element($item, 'published', $item, 'issued'); 
     447                                        endif; 
     448 
     449                                        $this->normalize_author_inheritance($item, $this->originals[$i]); 
     450         
     451                                        // Atom elements to RSS elements 
     452                                        $this->normalize_element($item, 'author', $item['dc'], 'creator', 'normalize_atom_person'); 
     453                                        $this->normalize_element($item, 'contributor', $item['dc'], 'contributor', 'normalize_atom_person'); 
     454                                        $this->normalize_element($item, 'summary', $item, 'description'); 
     455                                        $this->normalize_element($item, 'atom_content', $item['content'], 'encoded'); 
     456                                        $this->normalize_element($item, 'link_enclosure', $item, 'enclosure', 'normalize_enclosure'); 
     457 
     458                                        // Categories 
     459                                        if ( isset($item['category#']) ) : // Atom 1.0 categories to dc:subject and RSS 2.0 categories 
     460                                                $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category'); 
     461                                        elseif ( isset($item['dc']['subject#']) ) : // dc:subject to Atom 1.0 and RSS 2.0 categories 
     462                                                $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject'); 
     463                                        endif; 
     464 
     465                                        // Normalized item timestamp 
     466                                        $item_date = (isset($item['published']) ) ? $item['published'] : $item['updated']; 
     467                                elseif ( $this->is_rss() ) : 
     468                                        // RSS elements to Atom elements 
     469                                        $this->normalize_element($item, 'description', $item, 'summary'); 
     470                                        $this->normalize_element($item, 'enclosure', $item, 'link_enclosure', 'normalize_enclosure'); 
    436471                                 
    437                                 // Categories 
    438                                 if ( isset($item['category#']) ) : // RSS 2.0 categories to dc:subject and Atom 1.0 categories 
    439                                         $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category'); 
    440                                 elseif ( isset($item['dc']['subject#']) ) : // dc:subject to Atom 1.0 and RSS 2.0 categories 
    441                                         $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject'); 
    442                                 endif; 
    443          
    444                                 // Normalized item timestamp 
    445                                 if (isset($item['pubdate'])) : 
    446                                         $item_date = $item['pubdate']; 
    447                                 elseif (isset($item['dc']['date'])) : 
    448                                         $item_date = $item['dc']['date']; 
    449                                 else : 
    450                                         $item_date = null; 
    451                                 endif; 
    452                         endif; 
    453  
    454                         if ( $item_date ) : 
    455                                 $date_timestamp = new FeedTime($item_date); 
    456          
    457                                 if (!$date_timestamp->failed()) : 
    458                                         $item['date_timestamp'] = $date_timestamp->timestamp(); 
    459                                 endif; 
    460                         endif; 
    461  
    462                         $this->items[$i] = $item; 
    463                 endfor; 
     472                                        // Categories 
     473                                        if ( isset($item['category#']) ) : // RSS 2.0 categories to dc:subject and Atom 1.0 categories 
     474                                                $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category'); 
     475                                        elseif ( isset($item['dc']['subject#']) ) : // dc:subject to Atom 1.0 and RSS 2.0 categories 
     476                                                $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject'); 
     477                                        endif; 
     478         
     479                                        // Normalized item timestamp 
     480                                        if (isset($item['pubdate'])) : 
     481                                                $item_date = $item['pubdate']; 
     482                                        elseif (isset($item['dc']['date'])) : 
     483                                                $item_date = $item['dc']['date']; 
     484                                        else : 
     485                                                $item_date = null; 
     486                                        endif; 
     487                                endif; 
     488 
     489                                if ( $item_date ) : 
     490                                        $date_timestamp = new FeedTime($item_date); 
     491         
     492                                        if (!$date_timestamp->failed()) : 
     493                                                $item['date_timestamp'] = $date_timestamp->timestamp(); 
     494                                        endif; 
     495                                endif; 
     496 
     497                                $this->items[$i] = $item; 
     498                        endfor; 
     499                endif; 
    464500        } /* MagpieFromSimplePie::normalize() */ 
    465501 
  • trunk/blogs/wp-content/plugins/feedwordpress/readme.txt

    r1874 r1880  
    44Tags: syndication, aggregation, feed, atom, rss 
    55Requires at least: 3.0 
    6 Tested up to: 3.0.1 
    7 Stable tag: 2010.0905 
     6Tested up to: 3.0.5 
     7Stable tag: 2011.0211.2 
    88 
    99FeedWordPress syndicates content from feeds you choose into your WordPress weblog.  
  • trunk/blogs/wp-content/plugins/feedwordpress/syndicatedlink.class.php

    r1874 r1880  
    113113 
    114114                        if (isset($this->settings['terms'])) : 
    115                                 $this->settings['terms'] = explode(FEEDWORDPRESS_CAT_SEPARATOR.FEEDWORDPRESS_CAT_SEPARATOR, $this->settings['terms']); 
    116                                 $terms = array(); 
    117                                 foreach ($this->settings['terms'] as $line) : 
    118                                         $line = explode(FEEDWORDPRESS_CAT_SEPARATOR, $line); 
    119                                         $tax = array_shift($line); 
    120                                         $terms[$tax] = $line; 
    121                                 endforeach; 
    122                                 $this->settings['terms'] = $terms; 
     115                                // Look for new format 
     116                                $this->settings['terms'] = maybe_unserialize($this->settings['terms']); 
     117                                 
     118                                if (!is_array($this->settings['terms'])) : 
     119                                        // Deal with old format instead. Ugh. 
     120 
     121                                        // Split on two *or more* consecutive breaks 
     122                                        // because in the old format, a taxonomy 
     123                                        // without any associated terms would 
     124                                        // produce tax_name#1\n\n\ntax_name#2\nterm, 
     125                                        // and the naive split on the first \n\n 
     126                                        // would screw up the tax_name#2 list. 
     127                                        // 
     128                                        // Props to David Morris for pointing this 
     129                                        // out. 
     130 
     131                                        $this->settings['terms'] = preg_split( 
     132                                                "/".FEEDWORDPRESS_CAT_SEPARATOR."{2,}/", 
     133                                                $this->settings['terms'] 
     134                                        ); 
     135                                        $terms = array(); 
     136                                        foreach ($this->settings['terms'] as $line) : 
     137                                                $line = explode(FEEDWORDPRESS_CAT_SEPARATOR, $line); 
     138                                                $tax = array_shift($line); 
     139                                                $terms[$tax] = $line; 
     140                                        endforeach; 
     141                                        $this->settings['terms'] = $terms; 
     142                                endif; 
    123143                        endif; 
    124144                         
     
    164184                global $wpdb; 
    165185 
    166                 FeedWordPress::diagnostic('updated_feeds', 'Polling feed ['.$this->link->link_rss.']'); 
     186                $url = $this->uri(array('add_params' => true)); 
     187                FeedWordPress::diagnostic('updated_feeds', 'Polling feed ['.$url.']'); 
     188 
     189                $timeout = $this->setting('fetch timeout', 'feedwordpress_fetch_timeout', FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT); 
    167190 
    168191                $this->simplepie = apply_filters( 
    169192                        'syndicated_feed', 
    170                         FeedWordPress::fetch($this->link->link_rss), 
     193                        FeedWordPress::fetch($url, array('timeout' => $timeout)), 
    171194                        $this 
    172195                ); 
     
    176199                        $this->magpie = $this->simplepie; 
    177200                else : 
    178                         $this->magpie = new MagpieFromSimplePie($this->simplepie); 
     201                        $this->magpie = new MagpieFromSimplePie($this->simplepie, NULL); 
    179202                endif; 
    180203 
     
    289312                        $posts = apply_filters( 
    290313                                'syndicated_feed_items', 
    291                                 $this->magpie->originals, 
    292                                 $this 
     314                                $this->simplepie->get_items(), 
     315                                &$this 
    293316                        ); 
     317 
     318                        $this->magpie->originals = $posts; 
     319 
    294320                        if (is_array($posts)) : 
    295                                 foreach ($posts as $key => $original) : 
    296                                         $item = $this->magpie->items[$key]; 
    297                                         $post = new SyndicatedPost(array( 
    298                                                 'simplepie' => $original, 
    299                                                 'magpie' => $item, 
    300                                         ), $this); 
     321                                foreach ($posts as $key => $item) : 
     322                                        $post = new SyndicatedPost($item, $this); 
    301323 
    302324                                        if (!$resume or !in_array(trim($post->guid()), $processed)) : 
     
    471493                 
    472494                if (isset($to_notes['terms']) and is_array($to_notes['terms'])) : 
    473                         $tt = array(); 
    474                         foreach ($to_notes['terms'] as $tax => $terms) : 
    475                                 $tt[] = $tax.FEEDWORDPRESS_CAT_SEPARATOR.implode(FEEDWORDPRESS_CAT_SEPARATOR, $terms); 
    476                         endforeach; 
    477                         $to_notes['terms'] = implode(FEEDWORDPRESS_CAT_SEPARATOR.FEEDWORDPRESS_CAT_SEPARATOR, $tt); 
     495                        // Serialize it. 
     496                        $to_notes['terms'] = serialize($to_notes['terms']); 
    478497                endif; 
    479498                 
     
    533552         * @return bool TRUE on success, FALSE on failure. 
    534553         */ 
    535         function setting ($name, $fallback_global = NULL, $fallback_value = NULL) { 
     554        function setting ($name, $fallback_global = NULL, $fallback_value = NULL, $default = 'default') { 
    536555                $ret = NULL; 
    537556                if (isset($this->settings[$name])) : 
     
    541560                $no_value = ( 
    542561                        is_null($ret) 
    543                         or (is_string($ret) and strtolower($ret)=='default') 
     562                        or (is_string($ret) and strtolower($ret)==$default) 
    544563                ); 
    545564 
    546565                if ($no_value and !is_null($fallback_global)) : 
     566                        // Avoid duplication of this correction 
     567                        $fallback_global = preg_replace('/^feedwordpress_/', '', $fallback_global); 
     568                         
    547569                        $ret = get_option('feedwordpress_'.$fallback_global, /*default=*/ NULL); 
    548570                endif; 
     
    550572                $no_value = ( 
    551573                        is_null($ret) 
    552                         or (is_string($ret) and strtolower($ret)=='default') 
     574                        or (is_string($ret) and strtolower($ret)==$default) 
    553575                ); 
    554576 
     
    567589        } /* SyndicatedLink::update_setting () */ 
    568590         
    569         function uri () { 
    570                 return (is_object($this->link) ? $this->link->link_rss : NULL); 
     591        function uri ($params = array()) { 
     592                $params = shortcode_atts(array( 
     593                'add_params' => false, 
     594                ), $params); 
     595                 
     596                $uri = (is_object($this->link) ? $this->link->link_rss : NULL); 
     597                if (!is_null($uri) and strlen($uri) > 0 and $params['add_params']) : 
     598                        $qp = maybe_unserialize($this->setting('query parameters', array())); 
     599                         
     600                        // For high-tech HTTP feed request kung fu 
     601                        $qp = apply_filters('syndicated_feed_parameters', $qp, $uri, $this); 
     602                         
     603                        $q = array(); 
     604                        if (is_array($qp) and count($qp) > 0) : 
     605                                foreach ($qp as $pair) : 
     606                                        $q[] = urlencode($pair[0]).'='.urlencode($pair[1]); 
     607                                endforeach; 
     608                                 
     609                                // Are we appending to a URI that already has params? 
     610                                $sep = ((strpos('?', $uri)===false) ? '?' : '&'); 
     611                                 
     612                                // Tack it on 
     613                                $uri .= $sep . implode("&", $q); 
     614                        endif; 
     615                endif; 
     616                 
     617                return $uri; 
    571618        } /* SyndicatedLink::uri () */ 
    572619 
  • trunk/blogs/wp-content/plugins/feedwordpress/syndicatedpost.class.php

    r1874 r1880  
    2525        var $post = array (); 
    2626 
     27        var $named = array (); 
     28        var $preset_terms = array (); 
     29        var $feed_terms = array (); 
     30         
    2731        var $_freshness = null; 
    2832        var $_wp_id = null; 
     
    3741         * @param SyndicatedLink $source The feed it was syndicated from. 
    3842         */ 
    39         function SyndicatedPost ($item, $source) { 
     43        function SyndicatedPost ($item, &$source) { 
    4044                global $wpdb; 
    4145 
     
    4650                        $this->item = $item['magpie']; 
    4751                        $item = $item['magpie']; 
     52                elseif (is_a($item, 'SimplePie_Item')) : 
     53                        $this->entry = $item; 
     54                         
     55                        // convert to Magpie for compat purposes 
     56                        $mp = new MagpieFromSimplePie($source->simplepie, $this->entry); 
     57                        $this->item = $mp->get_item(); 
     58                         
     59                        // done with conversion object 
     60                        $mp = NULL; unset($mp); 
    4861                else : 
    4962                        $this->item = $item; 
    5063                endif; 
    5164 
    52                 $this->link = $source; 
     65                $this->link =& $source; 
    5366                $this->feed = $source->magpie; 
    5467                $this->feedmeta = $source->settings; 
     
    95108                ); 
    96109                $this->item = $changed; 
    97  
     110                 
    98111                # Filters can halt further processing by returning NULL 
    99112                if (is_null($this->item)) : 
     
    110123                        ); 
    111124 
    112                         $this->post['named']['author'] = apply_filters( 
     125                        $this->named['author'] = apply_filters( 
    113126                                'syndicated_item_author', 
    114127                                $this->author(), $this 
     
    127140                                $this->post['post_excerpt'] = $excerpt; 
    128141                        endif; 
    129                          
    130                         $this->post['epoch']['issued'] = apply_filters('syndicated_item_published', $this->published(), $this); 
    131                         $this->post['epoch']['created'] = apply_filters('syndicated_item_created', $this->created(), $this); 
    132                         $this->post['epoch']['modified'] = apply_filters('syndicated_item_updated', $this->updated(), $this); 
    133142 
    134143                        // Dealing with timestamps in WordPress is so fucking fucked. 
    135144                        $offset = (int) get_option('gmt_offset') * 60 * 60; 
    136                         $this->post['post_date'] = gmdate('Y-m-d H:i:s', apply_filters('syndicated_item_published', $this->published(/*fallback=*/ true, /*default=*/ -1), $this) + $offset); 
    137                         $this->post['post_modified'] = gmdate('Y-m-d H:i:s', apply_filters('syndicated_item_updated', $this->updated(/*fallback=*/ true, /*default=*/ -1), $this) + $offset); 
    138                         $this->post['post_date_gmt'] = gmdate('Y-m-d H:i:s', apply_filters('syndicated_item_published', $this->published(/*fallback=*/ true, /*default=*/ -1), $this)); 
    139                         $this->post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', apply_filters('syndicated_item_updated', $this->updated(/*fallback=*/ true, /*default=*/ -1), $this)); 
     145                        $post_date_gmt = $this->published(array('default' => -1)); 
     146                        $post_modified_gmt = $this->updated(array('default' => -1)); 
     147 
     148                        $this->post['post_date_gmt'] = gmdate('Y-m-d H:i:s', $post_date_gmt); 
     149                        $this->post['post_date'] = gmdate('Y-m-d H:i:s', $post_date_gmt + $offset); 
     150                        $this->post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $post_modified_gmt); 
     151                        $this->post['post_modified'] = gmdate('Y-m-d H:i:s', $post_modified_gmt + $offset); 
    140152 
    141153                        // Use feed-level preferences or the global default. 
     
    292304                                $cats = array_merge($cats, $fc); 
    293305                        endif; 
    294                         $this->post['pretax']['category'] = $cats; 
     306                        $this->preset_terms['category'] = $cats; 
    295307                         
    296308                        // Now add categories from the post, if we have 'em 
     
    317329                        endforeach; endif; 
    318330 
    319                         $this->post['taxed']['category'] = apply_filters('syndicated_item_categories', $cats, $this); 
     331                        $this->feed_terms['category'] = apply_filters('syndicated_item_categories', $cats, $this); 
    320332                         
    321333                        // Tags: start with default tags, if any 
     
    330342                                $tags = array_merge($tags, $ft); 
    331343                        endif; 
    332                         $this->post['pretax']['post_tag'] = $tags; 
     344                        $this->preset_terms['post_tag'] = $tags; 
    333345                         
    334346                        // Scan post for /a[@rel='tag'] and use as tags if present 
    335347                        $tags = $this->inline_tags(); 
    336                         $this->post['taxed']['post_tag'] = apply_filters('syndicated_item_tags', $tags, $this); 
     348                        $this->feed_terms['post_tag'] = apply_filters('syndicated_item_tags', $tags, $this); 
    337349                         
    338350                        $taxonomies = $this->link->taxonomies(); 
     
    358370 
    359371                                        // That's all, folks. 
    360                                         $this->post['pretax'][$tax] = $terms; 
     372                                        $this->preset_terms[$tax] = $terms; 
    361373                                endif; 
    362374                        endforeach; 
     
    628640        } 
    629641 
    630         function created () { 
     642        function created ($params = array()) { 
     643                $unfiltered = false; $default = NULL; 
     644                extract($params); 
     645                 
    631646                $date = ''; 
    632647                if (isset($this->item['dc']['created'])) : 
     
    638653                endif; 
    639654 
    640                 $epoch = new FeedTime($date); 
    641                 return $epoch->timestamp(); 
     655                $time = new FeedTime($date); 
     656                $ts = $time->timestamp(); 
     657                if (!$unfiltered) : 
     658                        apply_filters('syndicated_item_created', $ts, $this); 
     659                endif; 
     660                return $ts; 
    642661        } /* SyndicatedPost::created() */ 
    643662 
    644         function published ($fallback = true, $default = NULL) { 
     663        function published ($params = array(), $default = NULL) { 
     664                $fallback = true; $unfiltered = false; 
     665                if (!is_array($params)) : // Old style 
     666                        $fallback = $params; 
     667                else : // New style 
     668                        extract($params); 
     669                endif; 
     670                 
    645671                $date = ''; 
    646                 $epoch = null; 
     672                $ts = null; 
    647673 
    648674                # RSS is a fucking mess. Figure out whether we have a date in 
     
    664690                if (strlen($date) > 0) : 
    665691                        $time = new FeedTime($date); 
    666                         $epoch = $time->timestamp(); 
     692                        $ts = $time->timestamp(); 
    667693                elseif ($fallback) :                                            // Fall back to <updated> / <modified> if present 
    668                         $epoch = $this->updated(/*fallback=*/ false, /*default=*/ $default); 
     694                        $ts = $this->updated(/*fallback=*/ false, /*default=*/ $default); 
    669695                endif; 
    670696                 
    671697                # If everything failed, then default to the current time. 
    672                 if (is_null($epoch)) : 
     698                if (is_null($ts)) : 
    673699                        if (-1 == $default) : 
    674                                 $epoch = time(); 
     700                                $ts = time(); 
    675701                        else : 
    676                                 $epoch = $default; 
    677                         endif; 
    678                 endif; 
    679                  
    680                 return $epoch; 
     702                                $ts = $default; 
     703                        endif; 
     704                endif; 
     705                 
     706                if (!$unfiltered) : 
     707                        $ts = apply_filters('syndicated_item_published', $ts, $this); 
     708                endif; 
     709                return $ts; 
    681710        } /* SyndicatedPost::published() */ 
    682711 
    683         function updated ($fallback = true, $default = -1) { 
     712        function updated ($params = array(), $default = -1) { 
     713                $fallback = true; $unfiltered = false; 
     714                if (!is_array($params)) : // Old style 
     715                        $fallback = $params; 
     716                else : // New style 
     717                        extract($params); 
     718                endif; 
     719 
    684720                $date = ''; 
    685                 $epoch = null; 
     721                $ts = null; 
    686722 
    687723                # As far as I know, only dcterms and Atom have reliable ways to 
     
    694730                elseif (isset($this->item['modified'])):                        // Atom 0.3 
    695731                        $date = $this->item['modified']; 
    696                 elseif (isset($this->item['updated'])):                         // Atom 1.0 
     732                elseif (isset($this->item['updated'])):                 // Atom 1.0 
    697733                        $date = $this->item['updated']; 
    698734                endif; 
     
    700736                if (strlen($date) > 0) : 
    701737                        $time = new FeedTime($date); 
    702                         $epoch = $time->timestamp(); 
     738                        $ts = $time->timestamp(); 
    703739                elseif ($fallback) :                                            // Fall back to issued / dc:date 
    704                         $epoch = $this->published(/*fallback=*/ false, /*default=*/ $default); 
     740                        $ts = $this->published(/*fallback=*/ false, /*default=*/ $default); 
    705741                endif; 
    706742                 
    707743                # If everything failed, then default to the current time. 
    708                 if (is_null($epoch)) : 
     744                if (is_null($ts)) : 
    709745                        if (-1 == $default) : 
    710                                 $epoch = time(); 
     746                                $ts = time(); 
    711747                        else : 
    712                                 $epoch = $default; 
    713                         endif; 
    714                 endif; 
    715  
    716                 return $epoch; 
     748                                $ts = $default; 
     749                        endif; 
     750                endif; 
     751 
     752                if (!$unfiltered) : 
     753                        apply_filters('syndicated_item_updated', $ts, $this); 
     754                endif; 
     755                return $ts; 
    717756        } /* SyndicatedPost::updated() */ 
    718757 
     
    725764                if (isset($this->item['id'])):                  // Atom 0.3 / 1.0 
    726765                        $guid = $this->item['id']; 
    727                 elseif (isset($this->item['atom']['id'])) :     // Namespaced Atom 
     766                elseif (isset($this->item['atom']['id'])) :             // Namespaced Atom 
    728767                        $guid = $this->item['atom']['id']; 
    729                 elseif (isset($this->item['guid'])) :           // RSS 2.0 
     768                elseif (isset($this->item['guid'])) :                   // RSS 2.0 
    730769                        $guid = $this->item['guid']; 
    731                 elseif (isset($this->item['dc']['identifier'])) :// yeah, right 
     770                elseif (isset($this->item['dc']['identifier'])) :       // yeah, right 
    732771                        $guid = $this->item['dc']['identifier']; 
    733                 else : 
     772                endif; 
     773                 
     774                // Un-set or too long to use as-is. Generate a tag: URI. 
     775                if (is_null($guid) or strlen($guid) > 250) : 
     776                        // In case we need to check this again 
     777                        $original_guid = $guid; 
     778                         
    734779                        // The feed does not seem to have provided us with a 
    735                         // unique identifier, so we'll have to cobble together 
    736                         // a tag: URI that might work for us. The base of the 
    737                         // URI will be the host name of the feed source ... 
     780                        // usable unique identifier, so we'll have to cobble 
     781                        // together a tag: URI that might work for us. The base 
     782                        // of the URI will be the host name of the feed source ... 
    738783                        $bits = parse_url($this->link->uri()); 
    739784                        $guid = 'tag:'.$bits['host']; 
    740785 
     786                        // Some ill-mannered feeds (for example, certain feeds 
     787                        // coming from Google Calendar) have extraordinarily long 
     788                        // guids -- so long that they exceed the 255 character 
     789                        // width of the WordPress guid field. But if the string 
     790                        // gets clipped by MySQL, uniqueness tests will fail 
     791                        // forever after and the post will be endlessly 
     792                        // reduplicated. So, instead, Guids Of A Certain Length 
     793                        // are hashed down into a nice, manageable tag: URI. 
     794                        if (!is_null($original_guid)) : 
     795                                $guid .= ',2010-12-03:id.'.md5($original_guid); 
     796                         
    741797                        // If we have a date of creation, then we can use that 
    742798                        // to uniquely identify the item. (On the other hand, if 
     
    744800                        // generate dates of creation, she probably also was 
    745801                        // conscientious enough to generate unique identifiers.) 
    746                         if (!is_null($this->created())) : 
     802                        elseif (!is_null($this->created())) : 
    747803                                $guid .= '://post.'.date('YmdHis', $this->created()); 
    748804                         
     
    11561212 
    11571213                        if (!$result) : 
     1214                                $this->_wp_id = NULL; 
    11581215                                $this->_freshness = 2; // New content 
    11591216                        else: 
    1160                                 $stored_update_hashes = get_post_custom_values('syndication_item_hash', $result->id); 
    1161                                 if (count($stored_update_hashes) > 0) : 
    1162                                         $stored_update_hash = $stored_update_hashes[0]; 
    1163                                         $update_hash_changed = ($stored_update_hash != $this->update_hash()); 
    1164                                 else : 
    1165                                         $update_hash_changed = true; // Can't find syndication meta-data 
    1166                                 endif; 
    1167  
    11681217                                preg_match('/([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+):([0-9]+)/', $result->post_modified_gmt, $backref); 
    11691218 
     
    11711220                                $updated_ts = $this->updated(/*fallback=*/ true, /*default=*/ NULL); 
    11721221                                 
    1173                                 $frozen_values = get_post_custom_values('_syndication_freeze_updates', $result->id); 
    1174                                 $frozen_post = (count($frozen_values) > 0 and 'yes' == $frozen_values[0]); 
    1175                                 $frozen_feed = ('yes' == $this->link->setting('freeze updates', 'freeze_updates', NULL)); 
    1176  
    11771222                                // Check timestamps... 
    11781223                                $updated = ( 
     
    11811226                                ); 
    11821227                                 
    1183                          
    1184                                 // Or the hash... 
    1185                                 $updated = ($updated or $update_hash_changed); 
     1228                                if (!$updated) : 
     1229                                        // Or the hash... 
     1230                                        $stored_update_hashes = get_post_custom_values('syndication_item_hash', $result->id); 
     1231                                        if (count($stored_update_hashes) > 0) : 
     1232                                                $stored_update_hash = $stored_update_hashes[0]; 
     1233                                                $updated = ($stored_update_hash != $this->update_hash()); 
     1234                                        else : 
     1235                                                $updated = true; // Can't find syndication meta-data 
     1236                                        endif; 
     1237                                endif; 
    11861238                                 
    1187                                 // But only if the post is not frozen. 
    1188                                 $updated = ( 
    1189                                         $updated 
    1190                                         and !$frozen_post 
    1191                                         and !$frozen_feed 
    1192                                 );  
     1239                                $frozen = false; 
     1240                                if ($updated) : // Ignore if the post is frozen 
     1241                                        $frozen = ('yes' == $this->link->setting('freeze updates', 'freeze_updates', NULL)); 
     1242                                        if (!$frozen) : 
     1243                                                $frozen_values = get_post_custom_values('_syndication_freeze_updates', $result->id); 
     1244                                                $frozen = (count($frozen_values) > 0 and 'yes' == $frozen_values[0]); 
     1245                                        endif; 
     1246                                endif; 
     1247                                $updated = ($updated and !$frozen); 
    11931248 
    11941249                                if ($updated) : 
     
    12541309         
    12551310                                        $terms = $this->category_ids ( 
    1256                                                 $this->post['taxed'][$what], 
     1311                                                $this->feed_terms[$what], 
    12571312                                                $this->link->setting("unfamiliar {$what}", "unfamiliar_{$what}", 'create:'.$what), 
    12581313                                                /*taxonomies=*/ $taxonomies, 
     
    12941349 
    12951350                                // Now let's add on the feed and global presets 
    1296                                 foreach ($this->post['pretax'] as $tax => $term_ids) : 
     1351                                foreach ($this->preset_terms as $tax => $term_ids) : 
    12971352                                        if (!isset($this->post['tax_input'][$tax])) : 
    12981353                                                $this->post['tax_input'][$tax] = array(); 
     
    13141369                 
    13151370                if (!$this->filtered() and $freshness > 0) : 
    1316                         unset($this->post['named']); 
     1371                        // Filter some individual fields 
     1372                         
     1373                        // Allow filters to set post slug. Props niska. 
     1374                        $post_name = apply_filters('syndicated_post_slug', NULL, $this); 
     1375                        if (!empty($post_name)) : 
     1376                                $this->post['post_name'] = $post_name; 
     1377                        endif; 
     1378                         
    13171379                        $this->post = apply_filters('syndicated_post', $this->post, $this); 
    1318  
     1380                         
    13191381                        // Allow for feed-specific syndicated_post filters. 
    13201382                        $this->post = apply_filters( 
     
    13331395                ); 
    13341396 
    1335                 if (!$this->filtered() and $freshness == 2) : 
    1336                         // The item has not yet been added. So let's add it. 
    1337                         FeedWordPress::diagnostic('syndicated_posts', 'Inserting new post "'.$this->post['post_title'].'"'); 
    1338  
    1339                         $this->insert_new(); 
    1340                         do_action('post_syndicated_item', $this->wp_id(), $this); 
    1341  
    1342                         $ret = 'new'; 
    1343                 elseif (!$this->filtered() and $freshness == 1) : 
    1344                         FeedWordPress::diagnostic('syndicated_posts', 'Updating existing post # '.$this->wp_id().', "'.$this->post['post_title'].'"'); 
    1345  
    1346                         $this->post['ID'] = $this->wp_id(); 
    1347                         $this->update_existing(); 
    1348                         do_action('update_syndicated_item', $this->wp_id(), $this); 
    1349  
    1350                         $ret = 'updated';                        
    1351                 else : 
    1352                         $ret = false; 
     1397                $retval = array(1 => 'updated', 2 => 'new'); 
     1398                 
     1399                $ret = false; 
     1400                if (!$this->filtered() and isset($retval[$freshness])) :                         
     1401                        $diag = array( 
     1402                                1 => 'Updating existing post # '.$this->wp_id().', "'.$this->post['post_title'].'"', 
     1403                                2 => 'Inserting new post "'.$this->post['post_title'].'"', 
     1404                        ); 
     1405                        FeedWordPress::diagnostic('syndicated_posts', $diag[$freshness]); 
     1406 
     1407                        $this->insert_post(/*update=*/ ($freshness == 1)); 
     1408                         
     1409                        $hook = array(  1 => 'update_syndicated_item', 2 => 'post_syndicated_item' ); 
     1410                        do_action($hook[$freshness], $this->wp_id(), $this); 
     1411 
     1412                        $ret = $retval[$freshness]; 
    13531413                endif; 
    13541414 
     
    13971457                        /*arguments=*/ 3 
    13981458                        ); 
    1399  
     1459                         
     1460                        // WP3 appears to override whatever you give it for 
     1461                        // post_modified. Ugh. 
     1462                        add_action( 
     1463                        /*hook=*/ 'transition_post_status', 
     1464                        /*callback=*/ array(&$this, 'fix_post_modified_ts'), 
     1465                        /*priority=*/ -10000, /* very early */ 
     1466                        /*arguments=*/ 3 
     1467                        ); 
     1468 
     1469                        if ($update) : 
     1470                                $this->post['ID'] = $this->wp_id(); 
     1471                                $dbpost['ID'] = $this->post['ID']; 
     1472                        endif; 
    14001473                        $this->_wp_id = wp_insert_post($dbpost); 
    14011474 
     
    14061479                        /*arguments=*/ 3 
    14071480                        ); 
    1408          
     1481 
     1482                        remove_action( 
     1483                        /*hook=*/ 'transition_post_status', 
     1484                        /*callback=*/ array(&$this, 'fix_post_modified_ts'), 
     1485                        /*priority=*/ -10000, /* very early */ 
     1486                        /*arguments=*/ 3 
     1487                        ); 
     1488 
    14091489                        // Turn off ridiculous fucking kludges #1 and #2 
    14101490                        remove_action('_wp_put_post_revision', array($this, 'fix_revision_meta')); 
     
    15741654         
    15751655        /** 
     1656         * SyndicatedPost::fix_post_modified_ts() -- We would like to set 
     1657         * post_modified and post_modified_gmt to reflect the value of 
     1658         * <atom:updated> or equivalent elements on the feed. Unfortunately, 
     1659         * wp_insert_post() refuses to acknowledge explicitly-set post_modified 
     1660         * fields and overwrites them, either with the post_date (if new) or the 
     1661         * current timestamp (if updated). 
     1662         * 
     1663         * So, wp_insert_post() is not going to do the last-modified assignments 
     1664         * for us. If you want something done right.... 
     1665         * 
     1666         * @param string $new_status Unused action parameter. 
     1667         * @param string $old_status Unused action parameter. 
     1668         * @param object $post The database record for the post just inserted. 
     1669         */ 
     1670        function fix_post_modified_ts ($new_status, $old_status, $post) { 
     1671                global $wpdb; 
     1672                $wpdb->update( $wpdb->posts, /*data=*/ array( 
     1673                'post_modified' => $this->post['post_modified'], 
     1674                'post_modified_gmt' => $this->post['post_modified_gmt'], 
     1675                ), /*where=*/ array('ID' => $post->ID) ); 
     1676        } /* SyndicatedPost::fix_post_modified_ts () */ 
     1677         
     1678        /** 
    15761679         * SyndicatedPost::add_rss_meta: adds interesting meta-data to each entry 
    15771680         * using the space for custom keys. The set of keys and values to add is 
     
    16241727        } /* SyndicatedPost::add_rss_meta () */ 
    16251728 
    1626         // SyndicatedPost::author_id (): get the ID for an author name from 
    1627         // the feed. Create the author if necessary. 
     1729        /** 
     1730         * SyndicatedPost::author_id (): get the ID for an author name from 
     1731         * the feed. Create the author if necessary. 
     1732         * 
     1733         * @param string $unfamiliar_author 
     1734         * 
     1735         * @return NULL|int The numeric ID of the author to attribute the post to 
     1736         *      NULL if the post should be filtered out. 
     1737         */ 
    16281738        function author_id ($unfamiliar_author = 'create') { 
    16291739                global $wpdb; 
    16301740 
    1631                 $a = $this->author(); 
    1632                 $author = $a['name']; 
     1741                $a = $this->named['author']; 
     1742                 
     1743                $source = $this->source(); 
     1744                $forbidden = apply_filters('feedwordpress_forbidden_author_names', 
     1745                        array('admin', 'administrator', 'www', 'root')); 
     1746                 
     1747                $candidates = array(); 
     1748                $candidates[] = $a['name']; 
     1749                if (!is_null($source)) : $candidates[] = $source['title']; endif; 
     1750                $candidates[] = $this->link->name(/*fromFeed=*/ true); 
     1751                $candidates[] = $this->link->name(/*fromFeed=*/ false); 
     1752                if (strlen($this->link->homepage()) > 0) : $candidates[] = feedwordpress_display_url($this->link->homepage()); endif; 
     1753                $candidates[] = feedwordpress_display_url($this->link->uri()); 
     1754                $candidates[] = 'unknown author'; 
     1755                 
     1756                $author = NULL; 
     1757                while (is_null($author) and ($candidate = each($candidates))) : 
     1758                        if (!is_null($candidate['value']) 
     1759                        and (strlen(trim($candidate['value'])) > 0) 
     1760                        and !in_array(strtolower(trim($candidate['value'])), $forbidden)) : 
     1761                                $author = $candidate['value']; 
     1762                        endif; 
     1763                endwhile; 
     1764                 
    16331765                $email = (isset($a['email']) ? $a['email'] : NULL); 
    16341766                $authorUrl = (isset($a['uri']) ? $a['uri'] : NULL); 
    16351767 
     1768                 
    16361769                $hostUrl = $this->link->homepage(); 
    16371770                if (is_null($hostUrl) or (strlen($hostUrl) < 0)) : 
     
    16801813 
    16811814                // Check for an existing author rule.... 
    1682                 if (isset($this->link->settings['map authors']['name'][strtolower(trim($author))])) : 
     1815                if (isset($this->link->settings['map authors']['name']['*'])) : 
     1816                        $author_rule = $this->link->settings['map authors']['name']['*']; 
     1817                elseif (isset($this->link->settings['map authors']['name'][strtolower(trim($author))])) : 
    16831818                        $author_rule = $this->link->settings['map authors']['name'][strtolower(trim($author))]; 
    16841819                else : 
     
    17451880                                        $userdata['user_url'] = $authorUrl; 
    17461881                                        $userdata['display_name'] = $author; 
     1882                                        $userdata['role'] = 'contributor'; 
    17471883                                         
    17481884                                        do { // Keep trying until you get it right. Or until PHP crashes, I guess. 
     
    17791915                if ($id) : 
    17801916                        $this->link->settings['map authors']['name'][strtolower(trim($author))] = $id; 
     1917                         
     1918                        // Multisite: Check whether the author has been recorded 
     1919                        // on *this* blog before. If not, put her down as a 
     1920                        // Contributor for *this* blog. 
     1921                        $user = new WP_User((int) $id); 
     1922                        if (empty($user->roles)) : 
     1923                                $user->add_role('contributor'); 
     1924                        endif; 
    17811925                endif; 
    17821926                return $id;      
  • trunk/blogs/wp-content/plugins/feedwordpress/updatedpostscontrol.class.php

    r1874 r1880  
    22class UpdatedPostsControl { 
    33        var $page; 
    4         function UpdatedPostsControl ($page) { 
     4        function UpdatedPostsControl (&$page) { 
    55                $this->page =& $page; 
    66        } /* UpdatedPostsControl constructor */ 
Note: See TracChangeset for help on using the changeset viewer.