PluginProbe
FeedWordPress / 2022.0222
FeedWordPress v2022.0222
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
← All changes | feeds-page.php +955 -413 2009.1111 → 2022.0222 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2 require_once(dirname(__FILE__) . '/admin-ui.php');
3 3 require_once(dirname(__FILE__) . '/magpiemocklink.class.php');
4 4 require_once(dirname(__FILE__) . '/feedfinder.class.php');
5 +require_once(dirname(__FILE__) . '/updatedpostscontrol.class.php');
5 6
6 7 class FeedWordPressFeedsPage extends FeedWordPressAdminPage {
7 8 var $HTTPStatusMessages = array (
8 9 200 => 'OK. FeedWordPress had no problems retrieving the content at this URL but the content does not seem to be a feed, and does not seem to include links to any feeds.',
@@ -43,179 +44,198 @@
43 44 503 => 'Service Unavailable. The server is currently unable to handle the request due to a temporary overloading or maintenance of the server that hosts this URL. This is probably a temporary condition and you should try again later to see if the issue has been resolved.',
44 45 504 => 'Gateway Timeout',
45 46 505 => 'HTTP Version Not Supported',
46 47 );
48 + var $updatedPosts = NULL;
47 49
48 - /**
49 - * Constructs the Feeds page object
50 - *
51 - * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings
52 - */
53 - function FeedWordPressFeedsPage ($link = -1) {
54 - if (is_numeric($link) and -1 == $link) :
55 - $link = FeedWordPressAdminPage::submitted_link();
56 - endif;
57 -
58 - FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpressfeeds', $link);
59 -
60 - $this->dispatch = get_class($this);
61 - $this->filename = __FILE__;
62 - } /* FeedWordPressFeedsPage constructor */
63 -
64 50 var $special_settings = array ( /* Regular expression syntax is OK here */
65 51 'cats',
66 52 'cat_split',
53 + 'fetch timeout',
54 + 'freeze updates',
67 55 'hardcode name',
68 56 'hardcode url',
69 57 'hardcode description',
70 58 'hardcode categories', /* Deprecated */
71 - 'post status',
72 59 'comment status',
60 + 'terms',
61 + 'map authors',
62 + 'munge permalink',
73 63 'ping status',
64 + 'post status',
65 + 'postmeta',
66 + 'query parameters',
67 + 'resolve relative',
68 + 'syndicated post type',
69 + 'tags',
74 70 'unfamiliar author',
75 71 'unfamliar categories', /* Deprecated */
76 72 'unfamiliar category',
77 - 'map authors',
78 - 'tags',
79 - 'postmeta',
73 + 'unfamiliar post_tag',
74 + 'add/.*',
80 75 'update/.*',
81 76 'feed/.*',
82 77 'link/.*',
78 + 'match/.*',
83 79 );
84 80
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 + public function __construct( $link = -1 ) {
87 + if (is_numeric($link) and -1 == $link) :
88 + $link = $this->submitted_link();
89 + endif;
90 +
91 + parent::__construct('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 +
85 105 function display () {
86 - global $wpdb;
87 - global $fwp_post;
106 +
88 107 global $post_source;
89 -
90 - if (FeedWordPress::needs_upgrade()) :
91 - fwp_upgrade_page();
92 - return;
93 - endif;
94 108
109 + $this->boxes_by_methods = array(
110 + 'feed_information_box' => __('Feed Information'),
111 + 'global_feeds_box' => __('Update Scheduling'),
112 + 'updated_posts_box' => __('Updated Posts'),
113 + 'custom_settings_box' => __('Custom Feed Settings (for use in templates)'),
114 + 'advanced_settings_box' => __('Advanced Settings'),
115 + );
116 + if ($this->for_default_settings()) :
117 + unset($this->boxes_by_methods['custom_settings_box']);
118 + endif;
119 +
95 120 // Allow overriding of normal source for FeedFinder, which may
96 121 // be called from multiple points.
97 122 if (isset($post_source) and !is_null($post_source)) :
98 123 $source = $post_source;
99 124 else :
100 - $source = get_class($this);
125 + $source = $this->dispatch;
101 126 endif;
102 127
103 - // If this is a POST, validate source and user credentials
104 - FeedWordPressCompatibility::validate_http_request(/*action=*/ $source, /*capability=*/ 'manage_links');
128 + $feedfinder = FeedWordPress::param( 'feedfinder' );
129 + $action = FeedWordPress::param( 'action' );
130 + if ( $feedfinder || in_array( $action, array( 'feedfinder', FWP_SYNDICATE_NEW ) ) ) :
105 131
106 - if (isset($_REQUEST['feedfinder'])
107 - or (isset($_REQUEST['action']) and $_REQUEST['action']=='feedfinder')
108 - or (isset($_REQUEST['action']) and $_REQUEST['action']==FWP_SYNDICATE_NEW)) :
132 + // If this is a POST, validate source and user credentials
133 + FeedWordPressCompatibility::validate_http_request(/*action=*/ $source, /*capability=*/ 'manage_links');
134 +
109 135 return $this->display_feedfinder(); // re-route to Feed Finder page
110 - else :
111 - if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
112 - $this->accept_POST($fwp_post);
113 - do_action('feedwordpress_admin_page_feeds_save', $GLOBALS['fwp_post'], $this);
114 - endif;
115 -
116 - ////////////////////////////////////////////////
117 - // Prepare settings page ///////////////////////
118 - ////////////////////////////////////////////////
119 -
120 - $this->ajax_interface_js();
121 - $this->display_update_notice_if_updated('Syndicated feed');
122 - $this->open_sheet('Feed and Update');
123 - ?>
124 - <div id="post-body">
125 - <?php
126 - ////////////////////////////////////////////////
127 - // Display settings boxes //////////////////////
128 - ////////////////////////////////////////////////
129 -
130 - $boxes_by_methods = array(
131 - 'feed_information_box' => __('Feed Information'),
132 - 'global_feeds_box' => __('Update Scheduling'),
133 - 'posts_box' => __('Syndicated Posts, Links, Comments & Pings'),
134 - 'authors_box' => __('Syndicated Authors'),
135 - 'categories_box' => __('Categories'.FEEDWORDPRESS_AND_TAGS),
136 - 'custom_settings_box' => __('Custom Feed Settings (for use in templates)'),
137 - );
138 - if ($this->for_default_settings()) :
139 - unset($boxes_by_methods['custom_settings_box']);
140 - endif;
141 -
142 - foreach ($boxes_by_methods as $method => $row) :
143 - if (is_array($row)) :
144 - $id = $row['id'];
145 - $title = $row['title'];
146 - else :
147 - $id = 'feedwordpress_'.$method;
148 - $title = $row;
149 - endif;
150 -
151 - fwp_add_meta_box(
152 - /*id=*/ $id,
153 - /*title=*/ $title,
154 - /*callback=*/ array(get_class($this), $method),
155 - /*page=*/ $this->meta_box_context(),
156 - /*context=*/ $this->meta_box_context()
157 - );
158 - endforeach;
159 - do_action('feedwordpress_admin_page_feeds_meta_boxes', $this);
160 - ?>
161 - <div class="metabox-holder">
162 - <?php
163 - fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
164 - ?>
165 - </div> <!-- class="metabox-holder" -->
166 - </div> <!-- id="post-body" -->
167 - <?php $this->close_sheet(); ?>
136 + endif;
168 137
169 - <script type="text/javascript">
170 - var els = ['name', 'description', 'url'];
171 - for (var i = 0; i < els.length; i++) {
172 - contextual_appearance(
173 - /*item=*/ 'basics-hardcode-'+els[i],
174 - /*appear=*/ 'basics-'+els[i]+'-view',
175 - /*disappear=*/ 'basics-'+els[i]+'-edit',
176 - /*value=*/ 'no',
177 - /*visibleStyle=*/ 'block',
178 - /*checkbox=*/ true
179 - );
180 - } /* for */
181 - </script>
182 - <?php
183 - endif;
138 + parent::display();
184 139 return false; // Don't continue
185 140 } /* FeedWordPressFeedsPage::display() */
186 141
187 - /*static*/ function global_feeds_box ($page, $box = NULL) {
188 - global $wpdb;
142 + function ajax_interface_js () {
143 + parent::ajax_interface_js();
144 + ?>
189 145
190 - $defaultUpdateWindow = get_option('feedwordpress_update_window');
191 - if (!is_numeric($defaultUpdateWindow)) :
192 - $defaultUpdateWindow = DEFAULT_UPDATE_PERIOD;
193 - else :
194 - $defaultUpdateWindow = (int) $defaultUpdateWindow;
195 - endif;
146 + jQuery(document).ready( function () {
147 + contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');
148 + contextual_appearance('time-limit', 'time-limit-box', null, 'yes');
149 + contextual_appearance('use-default-update-window-no', 'update-scheduling-note', null, null, 'block', true);
150 + jQuery('#use-default-update-window-yes, #use-default-update-window-no').click( function () {
151 + contextual_appearance('use-default-update-window-no', 'update-scheduling-note', null, null, 'block', true);
152 + } );
153 +
154 + var els = ['name', 'description', 'url'];
155 + for (var i = 0; i < els.length; i++) {
156 + contextual_appearance(
157 + /*item=*/ 'basics-hardcode-'+els[i],
158 + /*appear=*/ 'basics-'+els[i]+'-view',
159 + /*disappear=*/ 'basics-'+els[i]+'-edit',
160 + /*value=*/ 'no',
161 + /*visibleStyle=*/ 'block',
162 + /*checkbox=*/ true
163 + );
164 + } /* for */
165 +
166 + // Let's make the interface for the PAUSE/RESUME a bit better
167 + jQuery('<tr id="reveal-pause-resume"><th></th><td><button id="pause-resume-reveal-button">&#8212; PAUSE or RESUME UPDATES &#8212;</button></td></tr>').insertBefore('#pause-resume');
168 + jQuery('#pause-resume').hide();
169 + jQuery('#pause-resume-reveal-button').click(function(ev) {
170 + ev.preventDefault();
171 +
172 + jQuery('#pause-resume').toggle();
173 + return false;
174 + });
175 +
176 + } );
177 +
178 + <?php
179 + }
180 +
181 + /*static*/ function updated_posts_box ($page, $box = NULL) {
196 182 ?>
197 -
198 183 <table class="edit-form">
184 + <?php $page->updatedPosts->display(); ?>
185 + </table>
199 186 <?php
200 - if ($page->for_default_settings()) :
201 - $automatic_updates = get_option('feedwordpress_automatic_updates');
202 - $update_time_limit = (int) get_option('feedwordpress_update_time_limit');
187 + } /* FeedWordPressFeedsPage::updated_posts_box() */
188 +
189 + /*static*/ function global_feeds_box ($page, $box = NULL) {
190 + global $feedwordpress;
191 + $automatic_updates = $feedwordpress->automatic_update_hook(array('setting only' => true));
192 + $update_time_limit = (int) get_option('feedwordpress_update_time_limit');
193 +
194 + // Hey, ho, let's go...
203 195 ?>
204 196
197 + <table class="edit-form">
198 + <?php if ($page->for_default_settings()) : ?>
199 +
205 200 <tr>
206 - <th scope="row">Updates:</th>
201 + <th scope="row">Update Method:</th>
207 202 <td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');">
208 - <option value="shutdown"<?php echo ($automatic_updates=='shutdown')?' selected="selected"':''; ?>>automatically check for updates after pages load</option>
209 - <option value="init"<?php echo ($automatic_updates=='init')?' selected="selected"':''; ?>>automatically check for updates before pages load</option>
210 - <option value="no"<?php echo (!$automatic_updates)?' selected="selected"':''; ?>>cron job or manual updates</option>
203 + <option value="shutdown"<?php fwp_selected_flag( $automatic_updates=='shutdown' ); ?>>automatically check for updates after pages load</option>
204 + <option value="init"<?php fwp_selected_flag( $automatic_updates=='init' ); ?>>automatically check for updates before pages load</option>
205 + <option value="no"<?php fwp_selected_flag( !$automatic_updates ); ?>>cron job or manual updates</option>
211 206 </select>
212 207 <div id="cron-job-explanation" class="setting-description">
213 - <p>If you want to use a cron job,
208 + <p><?php
209 + // Do we have shell_exec() available from here, or is it disabled for security reasons?
210 + // If it's available, use it to execute `which` to try to get a realistic path to curl,
211 + // or to wget. If everything fails or shell_exec() isn't available, then just make
212 + // up something for the sake of example.
213 + $curlOrWgetPath = NULL;
214 +
215 + $shellExecAvailable = (is_callable('shell_exec') && false === stripos(ini_get('disable_functions'), 'shell_exec'));
216 +
217 + if ($shellExecAvailable) :
218 + $curlOrWgetPath = `which curl`; $opts = '--silent %s';
219 + endif;
220 +
221 + if ($shellExecAvailable and (is_null($curlOrWgetPath) or strlen(trim($curlOrWgetPath))==0)) :
222 + $curlOrWgetPath = `which wget`; $opts = '-q -O - %s';
223 + endif;
224 +
225 + if (is_null($curlOrWgetPath) or strlen(trim($curlOrWgetPath))==0) :
226 + $curlOrWgetPath = '/usr/bin/curl'; $opts = '--silent %s';
227 + endif;
228 +
229 + $curlOrWgetPath = preg_replace('/\n+$/', '', $curlOrWgetPath);
230 +
231 + $cmdline = $curlOrWgetPath . ' ' . sprintf($opts, get_bloginfo('url').'?update_feedwordpress=1');
232 +
233 + ?>If you want to use a cron job,
214 234 you can perform scheduled updates by sending regularly-scheduled
215 - requests to <a href="<?php bloginfo('home'); ?>?update_feedwordpress=1"><code><?php bloginfo('home') ?>?update_feedwordpress=1</code></a>
235 + requests to <a href="<?php bloginfo('url'); ?>?update_feedwordpress=1"><code><?php bloginfo('url'); ?>?update_feedwordpress=1</code></a>
216 236 For example, inserting the following line in your crontab:</p>
217 - <pre style="font-size: 0.80em"><code>*/10 * * * * /usr/bin/curl --silent <?php bloginfo('home'); ?>?update_feedwordpress=1</code></pre>
237 + <pre style="font-size: 0.80em"><code>*/10 * * * * <?php print esc_html($cmdline); ?></code></pre>
218 238 <p class="setting-description">will check in every 10 minutes
219 239 and check for updates on any feeds that are ready to be polled for updates.</p>
220 240 </div>
221 241 </td>
@@ -220,39 +240,10 @@
220 240 </div>
221 241 </td>
222 242 </tr>
223 243
224 - <tr>
225 - <th scope="row"><?php print __('Update scheduling:') ?></th>
226 - <td><p style="margin-top:0px">How long should FeedWordPress wait between updates before it considers a feed ready to be polled for updates again?</p>
227 - <p style="font-style: italic; margin-left: 2.0em"><label>Wait <input type="text" name="update_window" value="<?php print $defaultUpdateWindow; ?>" size="4" /> minutes between polling.</label></p>
228 - <div class="setting-description">
229 - <p<?php if ($defaultUpdateWindow<50) : ?> style="color: white; background-color: #703030; padding: 1.0em;"<?php endif; ?>><strong>Recommendation.</strong> Unless you are positive that you have the webmaster's permission, you generally should not set FeedWordPress to poll feeds more frequently than once every 60 minutes. Many webmasters consider more frequent automated polling to be abusive, and may complain to your web host, or ban your IP address, as retaliation for hammering their servers too hard.</p>
230 - <p><strong>Note.</strong> This is a default setting that FeedWordPress uses to schedule updates when the feed does not provide any scheduling requests. If a feed does provide update scheduling information (through elements such as <code>&lt;rss:ttl&gt;</code> or <code>&lt;sy:updateFrequency&gt;</code>), FeedWordPress will respect the feed's request.</p>
231 - </div></td>
232 - </tr>
233 -
234 - <tr>
235 - <th scope="row"><?php print __('Time limit on updates'); ?>:</th>
236 - <td><select id="time-limit" name="update_time_limit" size="1" onchange="contextual_appearance('time-limit', 'time-limit-box', null, 'yes');">
237 - <option value="no"<?php echo ($update_time_limit>0)?'':' selected="selected"'; ?>>no time limit on updates</option>
238 - <option value="yes"<?php echo ($update_time_limit>0)?' selected="selected"':''; ?>>limit updates to no more than...</option>
239 - </select>
240 - <span id="time-limit-box"><label><input type="text" name="time_limit_seconds" value="<?php print $update_time_limit; ?>" size="5" /> seconds</label></span>
241 - </tr>
244 + <?php else : /* Feed-specific settings */ ?>
242 245
243 - <?php else :
244 - $useDefaultUpdateWindow = !(isset($page->link->settings['update/window']));
245 -
246 - $updateWindow = (isset($page->link->settings['update/window']) ? $page->link->settings['update/window'] : null);
247 - if (!is_numeric($updateWindow)) :
248 - $updateWindow = 60;
249 - else :
250 - $updateWindow = (int) $updateWindow;
251 - endif;
252 -
253 - ?>
254 -
255 246 <tr>
256 247 <th scope="row"><?php _e('Last update') ?>:</th>
257 248 <td><?php
258 249 if (isset($page->link->settings['update/last'])) :
@@ -287,39 +278,262 @@
287 278 ?></option>
288 279 <option value="next"<?php echo ($holdem=='next')?' selected="selected"':''; ?>>update ASAP</option>
289 280 <option value="ping"<?php echo ($holdem=='ping')?' selected="selected"':''; ?>>update only when pinged</option>
290 281 </select></td></tr>
282 +
283 + <?php endif; ?>
291 284
285 + <tr id="pause-resume">
286 + <th scope="row"><?php print __('Pause/Resume:'); ?></th>
287 + <td><?php
288 + $this->setting_radio_control(
289 + 'update/pause', 'update_pause',
290 + /*options=*/ array(
291 + 'no' => '<strong>UPDATE:</strong> import new posts as normal',
292 + 'yes' => '<strong>PAUSE:</strong> do not import new posts until I unpause updates',
293 + ),
294 + /*params=*/ array(
295 + 'setting-default' => NULL,
296 + 'global-setting-default' => 'no',
297 + 'default-input-value' => 'default',
298 + )
299 + );
300 + ?></td>
301 + </tr>
302 +
292 303 <tr>
293 304 <th scope="row"><?php print __('Update scheduling:') ?></th>
294 305 <td><p style="margin-top:0px">How long should FeedWordPress wait between updates before it considers this feed ready to be polled for updates again?</p>
295 - <ul>
296 - <li><label><input type="radio" name="use_default_update_window" value="Yes" <?php if ($useDefaultUpdateWindow) : ?>checked="checked"<?php endif; ?> /> Use site-wide setting (currently <?php print $defaultUpdateWindow; ?> minutes)</li>
297 - <li><label><input type="radio" name="use_default_update_window" value="No" <?php if (!$useDefaultUpdateWindow) : ?>checked="checked"<?php endif; ?> /> Wait <input type="text" name="update_window" value="<?php print $updateWindow; ?>" size="4" /> minutes between polling.</label></li>
298 - </ul>
306 + <?php
307 +
308 + $this->setting_radio_control(
309 + 'update/window', 'update_window',
310 + array($this, 'update_window_edit_box'),
311 + array(
312 + 'global-setting-default' => DEFAULT_UPDATE_PERIOD,
313 + 'default-input-name' => 'use_default_update_window',
314 + 'default-input-id' => 'use-default-update-window-yes',
315 + 'default-input-id-no' => 'use-default-update-window-no',
316 + 'labels' => array($this, 'update_window_currently'),
317 + )
318 + );
319 + ?></td>
320 + </tr>
321 +
322 + <tr>
323 + <th scope="row"><?php print __('Minimum Interval:'); ?></th>
324 + <td><p style="margin-top:0px">Some feeds include standard elements that
325 + request a specific update schedule. If the interval requested by the
326 + feed provider is <em>longer</em> than FeedWordPress's normal scheduling,
327 + FeedWordPress will always respect their request to slow down. But what
328 + should it do if the update interval is <em>shorter</em> than the schedule set above?</p>
329 + <?php
330 + $this->setting_radio_control(
331 + 'update/minimum', 'update_minimum',
332 + /*options=*/ array(
333 + 'no' => 'Speed up and accept the interval from the feed provider',
334 + 'yes' => 'Keep pace and use the longer scheduling from FeedWordPress',
335 + ),
336 + /*params=*/ array(
337 + 'setting-default' => NULL,
338 + 'global-setting-default' => 'no',
339 + 'default-input-value' => 'default',
340 + )
341 + );
342 + ?>
343 + </td>
344 + </tr>
299 345
300 - <div class="setting-description">
301 - <p<?php if ($updateWindow<50) : ?> style="color: white; background-color: #703030; padding: 1.0em;"<?php endif; ?>><strong>Recommendation.</strong> Unless you are positive that you have the webmaster's permission, you generally should not set FeedWordPress to poll feeds more frequently than once every 60 minutes. Many webmasters consider more frequent automated polling to be abusive, and may complain to your web host, or ban your IP address, as retaliation for hammering their servers too hard.</p>
302 - <p><strong>Note.</strong> This is a default setting that FeedWordPress uses to schedule updates when the feed does not provide any scheduling requests. If this feed does provide update scheduling information (through elements such as <code>&lt;rss:ttl&gt;</code> or <code>&lt;sy:updateFrequency&gt;</code>), FeedWordPress will respect the feed's request.</p>
303 - </div></td>
346 + <?php if ($this->for_default_settings()) : ?>
347 +
348 + <tr>
349 + <th scope="row"><?php print __('Time limit on updates'); ?>:</th>
350 + <td><select id="time-limit" name="update_time_limit" size="1" onchange="contextual_appearance('time-limit', 'time-limit-box', null, 'yes');">
351 + <option value="no"<?php fwp_selected_flag($update_time_limit<=0); ?>>no time limit on updates</option>
352 + <option value="yes"<?php fwp_selected_flag($update_time_limit>0); ?>>limit updates to no more than...</option>
353 + </select>
354 + <span id="time-limit-box"><label><input type="text" name="time_limit_seconds" value="<?php print esc_attr($update_time_limit); ?>" size="5" /> seconds</label></span>
304 355 </tr>
356 +
305 357 <?php endif; ?>
358 +
359 + </table>
360 +
361 + <?php
362 + } /* FeedWordPressFeedsPage::global_feeds_box() */
306 363
364 + function update_window_edit_box ($updateWindow, $defaulted, $params) {
365 + if (!is_numeric($updateWindow)) :
366 + $updateWindow = DEFAULT_UPDATE_PERIOD;
367 + endif;
368 + ?>
369 + <p>Wait <input type="text" name="update_window" value="<?php print esc_attr($updateWindow); ?>" size="4" /> minutes between polling.</p>
370 + <div class="setting-description" id="update-scheduling-note">
371 + <p<?php if ($updateWindow<50) : ?> style="color: white; background-color: #703030; padding: 1.0em;"<?php endif; ?>><strong>Recommendation.</strong> Unless you are positive that you have the webmaster's permission, you generally should not set FeedWordPress to poll feeds more frequently than once every 60 minutes. Many webmasters consider more frequent automated polling to be abusive, and may complain to your web host, or ban your IP address, as retaliation for hammering their servers too hard.</p>
372 + <p><strong>Note.</strong> This is a default setting that FeedWordPress uses to schedule updates when the feed does not provide any scheduling requests. If this feed does provide update scheduling information (through elements such as <code>&lt;rss:ttl&gt;</code> or <code>&lt;sy:updateFrequency&gt;</code>), FeedWordPress will respect the feed's request.</p>
373 + </div>
374 + <?php
375 + } /* FeedWordPressFeedsPage::update_window_edit_box () */
376 +
377 + function update_window_currently ($updateWindow, $defaulted, $params) {
378 + $updateWindow = (int) $updateWindow;
379 + if (1==$updateWindow) :
380 + $caption = 'wait %d minute between polling';
381 + else :
382 + $caption = 'wait %d minutes between polling';
383 + endif;
384 + return sprintf(__($caption), $updateWindow);
385 + } /* FeedWordPressFeedsPage::update_window_currently () */
386 +
387 + function fetch_timeout_setting ($setting, $defaulted, $params) {
388 + $timeout = intval($this->setting('fetch timeout', FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT));
307 389
308 -</table>
309 -<script type="text/javascript">
310 -contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');
311 -contextual_appearance('time-limit', 'time-limit-box', null, 'yes');
312 -</script>
313 -<?php
314 - } /* FeedWordPressFeedsPage::global_feeds_box() */
390 + if ($this->for_feed_settings()) :
391 + $article = 'this';
392 + else :
393 + $article = 'a';
394 + endif;
395 + ?>
396 + <p>Wait no more than
397 + than <input name="fetch_timeout" type="number" min="0" size="3" value="<?php print esc_attr($timeout); ?>" />
398 + second(s) when trying to fetch <?php print esc_html($article); ?> feed to check for updates.</p>
399 + <p>If <?php print esc_html($article); ?> source's web server does not respond before time runs
400 + out, FeedWordPress will skip over the source and try again during
401 + the next update cycle.</p>
402 + <?php
403 + }
404 + function fetch_timeout_setting_value ($setting, $defaulted, $params) {
405 + print number_format(intval($setting)) . " " . (($setting==1) ? "second" : "seconds");
406 + }
407 +
408 + function advanced_settings_box ($page, $box = NULL) {
409 + ?>
410 + <table class="edit-form">
411 + <tr>
412 + <th>Fetch Timeout:</th>
413 + <td>
414 + <?php
415 + $this->setting_radio_control(
416 + 'fetch timeout', 'fetch_timeout',
417 + array($this, 'fetch_timeout_setting'),
418 + array(
419 + 'global-setting-default' => FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT,
420 + 'input-name' => 'fetch_timeout',
421 + 'default-input-name' => 'fetch_timeout_default',
422 + 'labels' => array($this, 'fetch_timeout_setting_value'),
423 + )
424 + );
425 + ?>
426 + </td>
427 + </tr>
428 + <tr>
429 + <th>Feed Update Type:</th>
430 + <td><?php
431 + $this->setting_radio_control('update_incremental', 'update_incremental',
432 + /*options=*/ array(
433 + 'incremental' => '**Incremental.** When items no longer appear on the feed, keep them in the WordPress posts table.',
434 + 'complete' => '**Complete.** When items no longer appear on the feed, they are obsolete; retire them from the WordPress posts table.',
435 + ),
436 + /*params=*/ array(
437 + 'setting-default' => NULL,
438 + 'global-setting-default' => 'incremental',
439 + 'default-input-value' => 'default',
440 + )
441 + ); ?></td>
442 + </tr>
443 + <tr>
444 + <th>Allow Feeds to Delete Posts:</th>
445 + <td><?php
446 + $this->setting_radio_control('tombstones', 'tombstones',
447 + /*options=*/ array(
448 + 'yes' => 'Yes. If a feed indicates that one of its posts has been deleted, delete the local copy syndicated to this website.',
449 + 'no' => 'No. Even if a feed indicates that one of its posts has been deleted, retain the local copy on this website.',
450 + ),
451 + /*params=*/ array(
452 + 'setting-default' => NULL,
453 + 'global-setting-default' => 'yes',
454 + 'default-input-value' => 'default',
455 + )
456 + ); ?></td>
457 + </tr>
458 + </table>
459 + <?php
460 + } /* FeedWordPressFeedsPage::advanced_settings_box () */
461 +
462 + function display_authentication_credentials_box ($params = array()) {
463 + static $count = 0;
315 464
465 + $params = wp_parse_args($params, array(
466 + 'username' => NULL,
467 + 'password' => NULL,
468 + 'method' => '-',
469 + ));
470 +
471 + // Equivalents
472 + if (is_null($params['method'])) : $params['method'] = '-'; endif;
473 +
474 + $count++;
475 + $slug = ($count > 1 ? '-'.$count : '');
476 +
477 + global $feedwordpress;
478 + $authMethods = apply_filters(
479 + 'feedwordpress_http_auth_methods',
480 + $feedwordpress->httpauth->methods_available()
481 + );
482 +
483 + $linkRssAuthId = sanitize_html_class('link-rss-authentication' . $slug);
484 + $linkRssCredentialsId = sanitize_html_class('link-rss-authentication-credentials' . $slug);
485 + $linkRssAuthMethodId = sanitize_html_class('link-rss-authentication-method' . $slug );
486 +
487 + if (count($authMethods) > 1) : /* More than '-' */
488 + ?>
489 + <div class="link-rss-authentication" id="<?php print esc_attr($linkRssAuthId); ?>">
490 + <table>
491 + <tbody>
492 + <tr class="link-rss-authentication-credentials" id="<?php print esc_attr($linkRssCredentialsId); ?>">
493 + <td><label>user: <input type="text" name="link_rss_username"
494 + value="<?php print esc_attr($params['username']); ?>" size="16"
495 + placeholder="username to access this feed" /></label></td>
496 + <td><label>pass: <input type="text" name="link_rss_password"
497 + value="<?php print esc_attr($params['password']); ?>" size="16"
498 + placeholder="password to access this feed" /></label></td>
499 + <td class="link-rss-authentication-method" id="<?php print esc_attr($linkRssAuthMethodId); ?>"><label>method: <select class="link-rss-auth-method" id="link-rss-auth-method" name="link_rss_auth_method" size="1">
500 +<?php foreach ($authMethods as $value => $label) : ?>
501 + <option value="<?php print esc_attr($value); ?>"<?php
502 + fwp_selected_flag($value == $params['method']);
503 + ?>><?php print esc_html($label); ?></option>
504 +<?php endforeach; ?>
505 + </select></label></td>
506 + </tr>
507 + </tbody>
508 + </table>
509 + </div>
510 +
511 + <script type="text/javascript">
512 + jQuery('<td><a class="add-remove remove-it" id="link-rss-userpass-remove<?php print esc_attr($slug); ?>" href="#"><span class="x">(X)</span> Remove</a></td>')
513 + .appendTo('#<?php print esc_attr($linkRssCredentialsId); ?>')
514 + .click( feedAuthenticationMethodUnPress );
515 + jQuery('#link-rss-auth-method<?php print esc_attr($slug); ?>').change( feedAuthenticationMethod );
516 + feedAuthenticationMethod({
517 + init: true,
518 + node: jQuery('#<?php print esc_attr($linkRssAuthId); ?>') });
519 + </script>
520 +
521 + <?php
522 + endif;
523 + }
524 +
316 525 function feed_information_box ($page, $box = NULL) {
317 526 global $wpdb;
527 + $link_rss_params = maybe_unserialize($page->setting('query parameters', ''));
528 + if (!is_array($link_rss_params)) :
529 + $link_rss_params = array();
530 + endif;
531 +
318 532 if ($page->for_feed_settings()) :
319 - $info['name'] = wp_specialchars($page->link->link->link_name, 1);
320 - $info['description'] = wp_specialchars($page->link->link->link_description, 'both');
321 - $info['url'] = wp_specialchars($page->link->link->link_url, 1);
533 + $info['name'] = esc_html($page->link->link->link_name);
534 + $info['description'] = esc_html($page->link->link->link_description);
535 + $info['url'] = esc_html($page->link->link->link_url);
322 536 $rss_url = $page->link->link->link_rss;
323 537
324 538 $hardcode['name'] = $page->link->hardcode('name');
325 539 $hardcode['description'] = $page->link->hardcode('description');
@@ -325,26 +539,25 @@
325 539 $hardcode['description'] = $page->link->hardcode('description');
326 540 $hardcode['url'] = $page->link->hardcode('url');
327 541 else :
328 542 $cat_id = FeedWordPress::link_category_id();
329 - if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_21)) :
330 - $results = get_categories(array(
331 - "type" => 'link',
332 - "hide_empty" => false,
333 - ));
543 +
544 + $params = array();
545 + $params['taxonomy'] = 'link_category';
546 + $params['hide_empty'] = false;
547 + $results = get_categories($params);
334 548
335 - // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
336 - $found_link_category_id = false;
337 - foreach ($results as $row) :
338 - // Normalize case
339 - if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
549 + // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
550 + $found_link_category_id = false;
551 + foreach ($results as $row) :
552 + // Normalize case
553 + if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
340 554
341 - if ($row->cat_id == $cat_id) : $found_link_category_id = true; endif;
342 - endforeach;
343 -
344 - if (!$found_link_category_id) : $results[] = get_category($cat_id); endif;
345 - else :
346 - $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
555 + if ($row->cat_id == $cat_id) : $found_link_category_id = true; endif;
556 + endforeach;
557 +
558 + if (!$found_link_category_id) :
559 + $results[] = get_category($cat_id);
347 560 endif;
348 561
349 562 $info = array();
350 563 $rss_url = null;
@@ -353,17 +566,34 @@
353 566 $hardcode['description'] = get_option('feedwordpress_hardcode_description');
354 567 $hardcode['url'] = get_option('feedwordpress_hardcode_url');
355 568 endif;
356 569
570 + $hideAuth = false;
571 +
572 + $username = $this->setting('http username', NULL);
573 +
574 + if (is_null($username)) :
575 + $username = '';
576 + $hideAuth = true;
577 + endif;
578 +
579 + $password = $this->setting('http password', NULL);
580 + if (is_null($password)) :
581 + $password = '';
582 + endif;
583 +
584 + $auth = $this->setting('http auth method', NULL);
585 +
586 + global $feedwordpress;
587 +
588 + if (is_null($auth) or (strlen($auth)==0)) :
589 + $auth = '-';
590 + $hideAuth = true;
591 + endif;
592 +
357 593 // Hey ho, let's go
594 +
358 595 ?>
359 - <style type="text/css">
360 - table.edit-form { width: 100%; }
361 - table.edit-form th { width: 25%; vertical-align: top; text-align: right; padding: 0.5em; }
362 - table.edit-form td { width: 75%; vertical-align: top; padding: 0.5em; }
363 - table.edit-form td ul.options { margin: 0; padding: 0; list-style: none; }
364 - </style>
365 -
366 596 <table class="edit-form">
367 597
368 598 <?php if ($page->for_feed_settings()) : ?>
369 599
@@ -368,14 +598,82 @@
368 598 <?php if ($page->for_feed_settings()) : ?>
369 599
370 600 <tr>
371 601 <th scope="row"><?php _e('Feed URL:') ?></th>
372 - <td><a href="<?php echo wp_specialchars($rss_url, 'both'); ?>"><?php echo wp_specialchars($rss_url, 'both'); ?></a>
602 + <td><a href="<?php echo esc_html($rss_url); ?>"><?php echo esc_html($rss_url); ?></a>
373 603 (<a href="<?php echo FEEDVALIDATOR_URI; ?>?url=<?php echo urlencode($rss_url); ?>"
374 - title="Check feed &lt;<?php echo wp_specialchars($rss_url, 'both'); ?>&gt; for validity">validate</a>)
375 - <input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" /></td>
604 + title="Check feed &lt;<?php echo esc_html($rss_url); ?>&gt; for validity">validate</a>)
605 + <input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" />
606 +
607 + <?php $this->display_authentication_credentials_box(array(
608 + 'username' => $username,
609 + 'password' => $password,
610 + 'method' => $auth,
611 + )); ?>
612 +
613 + <table id="link-rss-params">
614 + <tbody>
615 + <?php
616 + $link_rss_params['new'] = array('', '');
617 + $i = 0;
618 + foreach ($link_rss_params as $index => $pair) :
619 + ?>
620 + <tr class="link-rss-params-row" id="link-rss-params-<?php print esc_attr($index); ?>">
621 + <td><label>Parameter: <input type="text" class="link_params_key"
622 + name="link_rss_params_key[<?php print esc_attr($index); ?>]" value="<?php print esc_html($pair[0]); ?>"
623 + size="5" style="width: 5em" placeholder="name" /></label></td>
624 + <td class="link-rss-params-value-cell"><label class="link_params_value_label">= <input type="text" class="link_params_value"
625 + name="link_rss_params_value[<?php print esc_attr($index); ?>]" value="<?php print esc_html($pair[1]); ?>"
626 + size="8" placeholder="value" /></label></td>
376 627 </tr>
628 + <?php
629 + $i++;
630 + endforeach;
631 + ?>
632 + </tbody>
633 + </table>
634 +
635 + <div><input type="hidden" id="link-rss-params-num" name="link_rss_params_num" value="<?php print esc_attr($i); ?>" /></div>
636 +
637 + <script type="text/javascript">
638 + function linkParamsRowRemove (element) {
639 + jQuery(element).closest('tr').fadeOut('slow', function () {
640 + jQuery(this).remove();
641 + } );
642 + }
377 643
644 + 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');
645 +
646 + jQuery('#link-rss-params-new').hide();
647 + jQuery('<a class="add-remove" id="link-rss-params-add" href="#">+ Add a query parameter</a>').insertAfter('#link-rss-params');
648 + jQuery('#link-rss-params-add').click( function () {
649 + var next = jQuery('#link-rss-params-num').val();
650 + var newRow = jQuery('#link-rss-params-new').clone().attr('id', 'link-rss-params-'+next);
651 + newRow.find('.link_params_key').attr('name', 'link_rss_params_key['+next+']');
652 + newRow.find('.link_params_value').attr('name', 'link_rss_params_value['+next+']');
653 +
654 + newRow.find('.link-rss-params-remove').click( function () {
655 + linkParamsRowRemove(this);
656 + return false;
657 + } );
658 +
659 + newRow.appendTo('#link-rss-params');
660 + newRow.show();
661 +
662 + // Update counter for next row.
663 + next++;
664 + jQuery('#link-rss-params-num').val(next);
665 +
666 + return false;
667 + } );
668 + jQuery('.link-rss-params-remove').click( function () {
669 + linkParamsRowRemove(this);
670 + return false;
671 + } );
672 + </script>
673 + </td>
674 + </tr>
675 +
378 676 <?php
379 677 $rows = array(
380 678 "name" => __('Link Name'),
381 679 "description" => __('Short Description'),
@@ -381,28 +679,32 @@
381 679 "description" => __('Short Description'),
382 680 "url" => __('Homepage'),
383 681 );
384 682 foreach ($rows as $what => $label) :
683 + $hardcode_name = sanitize_html_class( sprintf( 'hardcode_%s', $what ) );
684 + $hardcode_id = sanitize_html_class( sprintf( 'basics-hardcode-%s', $what ) );
685 + $hardcode_view_id = sanitize_html_class( sprintf( 'basics-%s-view', $what ) );
686 + $hardcode_edit_id = sanitize_html_class( sprintf( 'basics-%s-edit', $what ) );
385 687 ?>
386 688 <tr>
387 - <th scope="row"><?php print $label ?></th>
689 + <th scope="row"><?php print esc_html( $label ); ?></th>
388 690 <td>
389 - <div id="basics-<?php print $what; ?>-edit"><input type="text" name="link<?php print $what; ?>"
390 - value="<?php echo $info[$what]; ?>" style="width: 95%" /></div>
391 - <div id="basics-<?php print $what; ?>-view">
392 - <?php if ($what=='url') : ?><a href="<?php print $info[$what]; ?>"><?php else : ?><strong><?php endif; ?>
393 - <?php print (strlen(trim($info[$what])) > 0) ? $info[$what] : '(none provided)'; ?>
691 + <div id="<?php print esc_attr( $hardcode_edit_id ); ?>"><input type="text" name="link<?php print esc_attr($what); ?>"
692 + value="<?php echo esc_attr($info[$what]); ?>" style="width: 95%" /></div>
693 + <div id="<?php print esc_attr( $hardcode_view_id ); ?>">
694 + <?php if ($what=='url') : ?><a href="<?php print esc_url( $info[$what] ); ?>"><?php else : ?><strong><?php endif; ?>
695 + <?php print ( strlen( trim( $info[$what] ) ) > 0 ) ? esc_attr( $info[$what] ) : '(none provided)'; ?>
394 696 <?php if ($what=='url') : ?></a><?php else : ?></strong><?php endif; ?></div>
395 697
396 698 <div>
397 - <label><input id="basics-hardcode-<?php print $what; ?>"
398 - type="radio" name="hardcode_<?php print $what; ?>" value="no"
699 + <label><input id="<?php print esc_attr($hardcode_id); ?>"
700 + type="radio" name="<?php print esc_attr($hardcode_name); ?>" value="no"
399 701 <?php echo (($hardcode[$what]=='yes')?'':' checked="checked"');?>
400 - onchange="contextual_appearance('basics-hardcode-<?php print $what; ?>', 'basics-<?php print $what; ?>-view', 'basics-<?php print $what; ?>-edit', 'no', 'block', /*checkbox=*/ true)"
702 + onchange="contextual_appearance('basics-hardcode-<?php print esc_attr($what); ?>', '<?php print esc_attr($hardcode_view_id ); ?>', '<?php print esc_attr( $hardcode_edit_id ); ?>', 'no', 'block', /*checkbox=*/ true)"
401 703 /> Update automatically from feed</label>
402 - <label><input type="radio" name="hardcode_<?php print $what; ?>" value="yes"
704 + <label><input type="radio" name="<?php print esc_attr($hardcode_name); ?>" value="yes"
403 705 <?php echo (($hardcode[$what]!='yes')?'':' checked="checked"');?>
404 - onchange="contextual_appearance('basics-hardcode-<?php print $what; ?>', 'basics-<?php print $what; ?>-view', 'basics-<?php print $what; ?>-edit', 'no', 'block', /*checkbox=*/ true)"
706 + onchange="contextual_appearance('<?php print esc_attr($hardcode_id); ?>', '<?php print esc_attr($hardcode_view_id); ?>', '<?php print esc_attr($hardcode_edit_id); ?>', 'no', 'block', /*checkbox=*/ true)"
405 707 /> Edit manually</label>
406 708 </div>
407 709 </td>
408 710 </tr>
@@ -423,9 +725,9 @@
423 725 echo "\n\t<option value=\"$row->cat_id\"";
424 726 if ($row->cat_id == $cat_id) :
425 727 echo " selected='selected'";
426 728 endif;
427 - echo ">$row->cat_id: ".wp_specialchars($row->cat_name);
729 + echo ">$row->cat_id: ".esc_html($row->cat_name);
428 730 echo "</option>\n";
429 731 endforeach;
430 732 ?></select></p>
431 733 <p class="setting-description">FeedWordPress will syndicate the
@@ -453,26 +755,15 @@
453 755 </table>
454 756 <?php
455 757 } /* FeedWordPressFeedsPage::feed_information_box() */
456 758
457 - function posts_box ($page, $box = NULL) {
458 - FeedWordPressSettingsUI::instead_of_posts_box($page->link->id);
459 - } /* FeedWordPressFeedsPage::posts_box() */
460 -
461 - function authors_box ($page, $box = NULL) {
462 - FeedWordPressSettingsUI::instead_of_authors_box($page->link->id);
463 - } /* FeedWordPressFeedsPage::authors_box() */
464 -
465 - function categories_box ($page, $box = NULL) {
466 - FeedWordPressSettingsUI::instead_of_categories_box($page->link->id);
467 - } /* FeedWordPressFeedsPage::categories_box() */
468 -
469 759 function custom_settings_box ($page, $box = NULL) {
760 + $postsSettings = $this->admin_page_href('posts-page.php', array(), $page->link);
470 761 ?>
471 762 <p class="setting-description">These custom settings are special fields for the <strong>feed</strong> you are
472 763 syndicating, to be retrieved in templates using the <code>get_feed_meta()</code> function. They do not create
473 764 custom fields on syndicated <strong>posts</strong>. If you want to create custom fields that are applied to each
474 - individual post from this feed, set up the settings in <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/posts-page.php&amp;link_id=<?php print $page->link->id; ?>">Syndicated Posts</a>.</p>
765 + individual post from this feed, set up the settings in <a href="<?php print esc_url($postsSettings); ?>">Syndicated Posts</a>.</p>
475 766
476 767 <div id="postcustomstuff">
477 768 <table id="meta-list" cellpadding="3">
478 769 <tr>
@@ -486,12 +777,12 @@
486 777 foreach ($page->link->settings as $key => $value) :
487 778 if (!preg_match("\007^((".implode(')|(', $page->special_settings)."))$\007i", $key)) :
488 779 ?>
489 780 <tr style="vertical-align:top">
490 - <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo wp_specialchars($key, 'both'); ?>" />
491 - <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo wp_specialchars($key, 'both'); ?>" /></th>
492 - <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?>-value" name="notes[<?php echo $i; ?>][value]"><?php echo wp_specialchars($value, 'both'); ?></textarea></td>
493 - <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
781 + <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo esc_attr($i); ?>][key0]" value="<?php echo esc_html($key); ?>" />
782 + <input id="notes-<?php echo esc_attr($i); ?>-key" name="notes[<?php echo esc_attr($i); ?>][key1]" value="<?php echo esc_html($key); ?>" /></th>
783 + <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo esc_attr($i); ?>-value" name="notes[<?php echo esc_attr($i); ?>][value]"><?php echo esc_html($value); ?></textarea></td>
784 + <td width="10%"><select name="notes[<?php echo esc_attr($i); ?>][action]">
494 785 <option value="update">save changes</option>
495 786 <option value="delete">delete this setting</option>
496 787 </select></td>
497 788 </tr>
@@ -500,11 +791,11 @@
500 791 endif;
501 792 endforeach;
502 793 ?>
503 794 <tr>
504 - <th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?>][key1]" value="" /></th>
505 - <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea></td>
506 - <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td>
795 + <th scope="row"><input type="text" size="10" name="notes[<?php echo esc_attr( $i ); ?>][key1]" value="" /></th>
796 + <td><textarea name="notes[<?php echo esc_attr( $i ); ?>][value]" rows="2" cols="40"></textarea></td>
797 + <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo esc_attr( $i ); ?>][action]" value="update" /></td>
507 798 </tr>
508 799 </table>
509 800 </div> <!-- id="postcustomstuff" -->
510 801 <?php
@@ -509,71 +800,171 @@
509 800 </div> <!-- id="postcustomstuff" -->
510 801 <?php
511 802 }
512 803
804 + function url_for_401 ($err) {
805 + $ret = NULL;
806 + if (is_wp_error($err)) :
807 + if ($err->get_error_code()=='http_request_failed') :
808 + $data = $err->get_error_data('http_request_failed');
809 +
810 + if (is_array($data) and isset($data['status'])) :
811 + if (401==$data['status']) :
812 + $ret = $data['uri'];
813 + endif;
814 + endif;
815 + endif;
816 + endif;
817 + return $ret;
818 + }
819 +
513 820 function display_feedfinder () {
514 821 global $wpdb;
515 822
516 - $lookup = (isset($_REQUEST['lookup']) ? $_REQUEST['lookup'] : NULL);
823 + $lookup = FeedWordPress::param( 'lookup' );
824 +
825 + $auth = FeedWordPress::param( 'link_rss_auth_method' );
826 + $username = FeedWordPress::param( 'link_rss_username' );
827 + $password = FeedWordPress::param( 'link_rss_password' );
828 + $credentials = array(
829 + "authentication" => $auth,
830 + "username" => $username,
831 + "password" => $password,
832 + );
517 833
834 + $feeds = array(); $feedSwitch = false; $current = null;
518 835 if ($this->for_feed_settings()) : // Existing feed?
519 - if (is_null($lookup)) : $lookup = $this->link->link->link_url; endif;
520 - $name = wp_specialchars($this->link->link->link_name, 'both');
836 + $feedSwitch = true;
837 + if (is_null($lookup)) :
838 + // Switch Feed without a specific feed yet suggested
839 + // Go to the human-readable homepage to look for
840 + // auto-detection links
841 +
842 + $lookup = $this->link->link->link_url;
843 + $auth = $this->link->setting('http auth method');
844 + $username = $this->link->setting('http username');
845 + $password = $this->link->setting('http password');
846 +
847 + // Guarantee that you at least have the option to
848 + // stick with what works.
849 + $current = $this->link->link->link_rss;
850 + $feeds[] = $current;
851 + endif;
852 + $name = $this->link->link->link_name;
521 853 else: // Or a new subscription to add?
522 - $name = "Subscribe to <code>".wp_specialchars(feedwordpress_display_url($lookup))."</code>";
854 + $name = "Subscribe to ".feedwordpress_display_url($lookup);
523 855 endif;
524 856 ?>
525 - <style type="text/css">
526 - form.fieldset {
527 - clear: both;
528 - }
529 - .feed-sample {
530 - float: right;
531 - background-color: #D0D0D0;
532 - color: black;
533 - width: 45%;
534 - font-size: 70%;
535 - border-left: 1px dotted #A0A0A0;
536 - margin-left: 1.0em;
537 - }
538 - .feed-sample p, .feed-sample h3 {
539 - padding-left: 0.5em;
540 - padding-right: 0.5em;
541 - }
542 - .feed-sample .feed-problem {
543 - background-color: #ffd0d0;
544 - border-bottom: 1px dotted black;
545 - padding-bottom: 0.5em;
546 - margin-bottom: 0.5em;
547 - }
548 - </style>
857 + <div class="wrap" id="feed-finder">
858 + <h2>Feed Finder: <?php echo esc_html($name); ?></h2>
549 859
550 - <div class="wrap">
551 - <h2>Feed Finder: <?php echo $name; ?></h2>
860 + <?php
861 + if ($feedSwitch) :
862 + $this->display_alt_feed_box($lookup);
863 + endif;
552 864
553 - <?php
554 - $f =& new FeedFinder($lookup);
555 - $feeds = $f->find();
865 + $finder = array();
866 + if (!is_null($current)) :
867 + $finder[$current] = new FeedFinder($current);
868 + endif;
869 + $finder[$lookup] = new FeedFinder($lookup);
870 +
871 + foreach ($finder as $url => $ff) :
872 + $feeds = array_merge($feeds, $ff->find(
873 + /*url=*/ NULL,
874 + /*params=*/ $credentials));
875 + endforeach;
876 +
877 + $feeds = array_values( // Renumber from 0..(N-1)
878 + $feeds
879 + );
880 +
881 + // Allow for some simple FeedFinder results filtering
882 + $feeds = apply_filters(
883 + 'feedwordpress_feedfinder_results',
884 + $feeds,
885 + array(
886 + "url" => $lookup,
887 + "auth" => $auth,
888 + "username" => $username,
889 + "password" => $password,
890 + "finder" => $finder,
891 + ),
892 + $this
893 + );
894 +
556 895 if (count($feeds) > 0):
896 + if ($feedSwitch) :
897 + ?>
898 + <h3>Feeds Found</h3>
899 + <?php
900 + endif;
901 +
902 + if (count($feeds) > 1) :
903 + $option_template = 'Option %d: ';
904 + $form_class = 'multi';
905 + ?>
906 + <p><strong>This web page provides at least <?php print count($feeds); ?> different feeds.</strong> These feeds may provide the same information
907 + in different formats, or may track different items. (You can check the Feed Information and the
908 + Sample Item for each feed to get an idea of what the feed provides.) Please select the feed that you'd like to subscribe to.</p>
909 + <?php
910 + else :
911 + $option_template = '';
912 + $form_class = '';
913 + endif;
914 +
915 + global $fwp_credentials;
916 +
557 917 foreach ($feeds as $key => $f):
558 - $rss = @fetch_rss($f);
559 - if ($rss):
560 - $feed_title = isset($rss->channel['title'])?$rss->channel['title']:$rss->channel['link'];
561 - $feed_link = isset($rss->channel['link'])?$rss->channel['link']:'';
918 + $ofc = $fwp_credentials;
919 + $fwp_credentials = $credentials; // Set
920 + $pie = FeedWordPress::fetch($f, array("cache" => false));
921 + $fwp_credentials = $ofc; // Re-Set
922 +
923 + $rss = (is_wp_error($pie) ? $pie : new MagpieFromSimplePie($pie));
924 +
925 + if ($this->url_for_401($pie)) :
926 + $this->display_alt_feed_box($lookup, array(
927 + "err" => $pie,
928 + "auth" => $auth,
929 + "username" => $username,
930 + "password" => $password
931 + ));
932 + continue;
933 + endif;
934 +
935 + if ($rss and !is_wp_error($rss)):
936 + $feed_link = (isset($rss->channel['link'])?$rss->channel['link']:'');
937 + $feed_title = (isset($rss->channel['title'])?$rss->channel['title']:$feed_link);
562 938 $feed_type = ($rss->feed_type ? $rss->feed_type : 'Unknown');
939 + $feed_version_template = '%.1f';
940 + $feed_version = $rss->feed_version;
563 941 else :
564 942 // Give us some sucky defaults
565 943 $feed_title = feedwordpress_display_url($lookup);
566 944 $feed_link = $lookup;
567 945 $feed_type = 'Unknown';
946 + $feed_version_template = '';
947 + $feed_version = '';
568 948 endif;
569 949 ?>
570 - <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/syndication.php" method="post">
571 - <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_switchfeed'); ?></div>
572 - <fieldset>
573 - <legend><?php echo $feed_type; ?> <?php echo $rss->feed_version; ?> feed</legend>
950 + <form <?php print fwp_form_class_attr($form_class); ?> action="<?php print esc_url( $this->form_action( 'syndication.php' ) ); ?>" method="post">
951 + <div class="inside"><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_switchfeed'); ?>
574 952
575 953 <?php
954 + $classes = array('feed-found'); $currentFeed = '';
955 + if (!is_null($current) and $current==$f) :
956 + $classes[] = 'current';
957 + $currentFeed = ' (currently subscribed)';
958 + endif;
959 + if ($key%2) :
960 + $classes[] = 'alt';
961 + endif;
962 + ?>
963 + <fieldset class="<?php print implode(" ", $classes); ?>">
964 + <legend><?php print esc_html( sprintf( $option_template, ( $key + 1 ) ) ); print esc_html($feed_type) . " "; print esc_html( sprintf( $feed_version_template, $feed_version ) ); ?> feed<?php print esc_html( $currentFeed ); ?></legend>
965 +
966 + <?php
576 967 $this->stamp_link_id();
577 968
578 969 // No feed specified = add new feed; we
579 970 // need to pass along a starting title
@@ -579,42 +970,44 @@
579 970 // need to pass along a starting title
580 971 // and homepage URL for the new Link.
581 972 if (!$this->for_feed_settings()):
582 973 ?>
583 - <input type="hidden" name="feed_title" value="<?php echo wp_specialchars($feed_title, 'both'); ?>" />
584 - <input type="hidden" name="feed_link" value="<?php echo wp_specialchars($feed_link, 'both'); ?>" />
974 + <input type="hidden" name="feed_title" value="<?php echo esc_html($feed_title); ?>" />
975 + <input type="hidden" name="feed_link" value="<?php echo esc_html($feed_link); ?>" />
585 976 <?php
586 977 endif;
587 978 ?>
588 979
589 - <input type="hidden" name="feed" value="<?php echo wp_specialchars($f, 'both'); ?>" />
980 + <input type="hidden" name="feed" value="<?php echo esc_html($f); ?>" />
590 981 <input type="hidden" name="action" value="switchfeed" />
591 982
592 983 <div>
593 984 <div class="feed-sample">
594 -
595 985 <?php
596 - if (count($rss->items) > 0):
986 + $link = null;
987 + $post = null;
988 + if (!is_wp_error($rss) and count($rss->items) > 0):
597 989 // Prepare to display Sample Item
598 - $link =& new MagpieMockLink($rss, $f);
599 - $post =& new SyndicatedPost($rss->items[0], $link);
990 + $link = new MagpieMockLink(array('simplepie' => $pie, 'magpie' => $rss), $f);
991 + $post = new SyndicatedPost(array('simplepie' => $rss->originals[0], 'magpie' => $rss->items[0]), $link);
600 992 ?>
601 993 <h3>Sample Item</h3>
602 994 <ul>
603 - <li><strong>Title:</strong> <a href="<?php echo $post->post['meta']['syndication_permalink']; ?>"><?php echo $post->post['post_title']; ?></a></li>
995 + <li><strong>Title:</strong> <a href="<?php echo esc_url( $post->post['meta']['syndication_permalink'] ); ?>"><?php echo esc_html( $post->post['post_title'] ); ?></a></li>
604 996 <li><strong>Date:</strong> <?php print date('d-M-y g:i:s a', $post->published()); ?></li>
605 997 </ul>
606 998 <div class="entry">
607 - <?php print $post->post['post_content']; ?>
999 + <?php print wp_kses( $post->post['post_content'], 'post' ); ?>
608 1000 </div>
609 1001 <?php
1002 + do_action('feedwordpress_feed_finder_sample_item', $f, $post, $link);
610 1003 else:
611 - if (magpie_error()) :
1004 + if (is_wp_error($rss)) :
612 1005 print '<div class="feed-problem">';
613 1006 print "<h3>Problem:</h3>\n";
614 1007 print "<p>FeedWordPress encountered the following error
615 1008 when trying to retrieve this feed:</p>";
616 - print '<p style="margin: 1.0em 3.0em"><code>'.magpie_error().'</code></p>';
1009 + print '<p style="margin: 1.0em 3.0em"><code>'.$rss->get_error_message().'</code></p>';
617 1010 print "<p>If you think this is a temporary problem, you can still force FeedWordPress to add the subscription. FeedWordPress will not be able to find any syndicated posts until this problem is resolved.</p>";
618 1011 print "</div>";
619 1012 endif;
620 1013 ?>
@@ -627,172 +1020,321 @@
627 1020
628 1021 <div>
629 1022 <h3>Feed Information</h3>
630 1023 <ul>
631 - <li><strong>Homepage:</strong> <a href="<?php echo $feed_link; ?>"><?php echo is_null($feed_title)?'<em>Unknown</em>':$feed_title; ?></a></li>
632 - <li><strong>Feed URL:</strong> <a href="<?php echo wp_specialchars($f, 'both'); ?>"><?php echo wp_specialchars($f, 'both'); ?></a> (<a title="Check feed &lt;<?php echo wp_specialchars($f, 'both'); ?>&gt; for validity" href="http://feedvalidator.org/check.cgi?url=<?php echo urlencode($f); ?>">validate</a>)</li>
633 - <li><strong>Encoding:</strong> <?php echo isset($rss->encoding)?wp_specialchars($rss->encoding, 'both'):"<em>Unknown</em>"; ?></li>
634 - <li><strong>Description:</strong> <?php echo isset($rss->channel['description'])?wp_specialchars($rss->channel['description'], 'both'):"<em>Unknown</em>"; ?></li>
1024 + <li><strong>Homepage:</strong> <a href="<?php echo esc_url( $feed_link ); ?>"><?php echo is_null($feed_title)?'<em>Unknown</em>': esc_html( $feed_title ); ?></a></li>
1025 + <li><strong>Feed URL:</strong> <a title="<?php echo esc_html( $f ); ?>" href="<?php echo esc_url( $f ); ?>"><?php echo esc_html( feedwordpress_display_url($f, 40, 10) ); ?></a> (<a title="Check feed &lt;<?php echo esc_html( $f ); ?>&gt; for validity" href="http://feedvalidator.org/check.cgi?url=<?php echo urlencode( $f ); ?>">validate</a>)</li>
1026 + <li><strong>Encoding:</strong> <?php echo isset($rss->encoding) ? esc_html($rss->encoding) : "<em>Unknown</em>"; ?></li>
1027 + <li><strong>Description:</strong> <?php echo isset($rss->channel['description']) ? esc_html($rss->channel['description']) : "<em>Unknown</em>"; ?></li>
635 1028 </ul>
636 - <div class="submit"><input type="submit" name="Use" value="&laquo; Use this feed" /></div>
637 - <div class="submit"><input type="submit" name="Cancel" value="&laquo; Cancel" /></div>
1029 + <?php $this->display_authentication_credentials_box(array(
1030 + 'username' => $username,
1031 + 'password' => $password,
1032 + 'method' => $auth,
1033 + )); ?>
1034 + <?php do_action('feedwordpress_feedfinder_form', $f, $post, $link, $this->for_feed_settings()); ?>
1035 + <div class="submit"><input type="submit" class="button-primary" name="Use" value="&laquo; Use this feed" />
1036 + <input type="submit" class="button" name="Cancel" value="× Cancel" /></div>
638 1037 </div>
639 1038 </div>
640 1039 </fieldset>
1040 + </div> <!-- class="inside" -->
641 1041 </form>
642 1042 <?php
1043 + unset($link);
1044 + unset($post);
643 1045 endforeach;
644 1046 else:
645 - print "<p><strong>".__('Error').":</strong> ".__("FeedWordPress couldn't find any feeds at").' <code><a href="'.htmlspecialchars($lookup).'">'.htmlspecialchars($lookup).'</a></code>';
646 - print ". ".__('Try another URL').".</p>";
1047 + foreach ($finder as $url => $ff) :
1048 + $url = esc_html($url);
1049 + print "<h3>Searched for feeds at ${url}</h3>\n";
1050 + print "<p><strong>".__('Error').":</strong> ".__("FeedWordPress couldn't find any feeds at").' <code><a href="'.htmlspecialchars($lookup).'">'.htmlspecialchars($lookup).'</a></code>';
1051 + print ". ".__('Try another URL').".</p>";
647 1052
648 - // Diagnostics
649 - print "<div class=\"updated\" style=\"margin-left: 3.0em; margin-right: 3.0em;\">\n";
650 - print "<h3>".__('Diagnostic information')."</h3>\n";
651 - if (!is_null($f->error()) and strlen($f->error()) > 0) :
652 - print "<h4>".__('HTTP request failure')."</h4>\n";
653 - print "<p>".$f->error()."</p>\n";
654 - else :
655 - print "<h4>".__('HTTP request completed')."</h4>\n";
656 - print "<p><strong>Status ".$f->status().":</strong> ".$this->HTTPStatusMessages[(int) $f->status()]."</p>\n";
657 - endif;
1053 + // Diagnostics
1054 + print "<div class=\"updated\" style=\"margin-left: 3.0em; margin-right: 3.0em;\">\n";
1055 + print "<h3>".__('Diagnostic information')."</h3>\n";
1056 + if (!is_null($ff->error()) and strlen($ff->error()) > 0) :
1057 + print "<h4>".__('HTTP request failure')."</h4>\n";
1058 + print "<p>".$ff->error()."</p>\n";
1059 + else :
1060 + print "<h4>".__('HTTP request completed')."</h4>\n";
1061 + print "<p><strong>Status ".$ff->status().":</strong> ".$this->HTTPStatusMessages[(int) $ff->status()]."</p>\n";
1062 + endif;
658 1063
659 - // Do some more diagnostics if the API for it is available.
660 - if (function_exists('_wp_http_get_object')) :
661 - $httpObject = _wp_http_get_object();
662 - $transports = $httpObject->_getTransport();
1064 + // Do some more diagnostics if the API for it is available.
1065 + if (function_exists('_wp_http_get_object')) :
1066 + $httpObject = _wp_http_get_object();
1067 +
1068 + if (is_callable(array($httpObject, '_getTransport'))) :
1069 + $transports = $httpObject->_getTransport();
1070 +
1071 + print "<h4>".__('HTTP Transports available').":</h4>\n";
1072 + print "<ol>\n";
1073 + print "<li>".implode("</li>\n<li>", array_map('get_class', $transports))."</li>\n";
1074 + print "</ol>\n";
1075 + elseif (is_callable(array($httpObject, '_get_first_available_transport'))) :
1076 + $transport = $httpObject->_get_first_available_transport(
1077 + array(),
1078 + $url
1079 + );
1080 +
1081 + print "<h4>".__("HTTP Transport").":</h4>\n";
1082 + print "<ol>\n";
1083 + print "<li>".MyPHP::val($transport)."</li>\n";
1084 + print "</ol>\n";
1085 + endif;
1086 +
1087 + print "</div>\n";
1088 + endif;
1089 + endforeach;
1090 + endif;
1091 +
1092 + if (!$feedSwitch) :
1093 + $this->display_alt_feed_box($lookup, /*alt=*/ true);
1094 + endif;
1095 + ?>
1096 + </div> <!-- class="wrap" -->
1097 + <?php
1098 + return false; // Don't continue
1099 + } /* FeedWordPressFeedsPage::display_feedfinder() */
663 1100
664 - print "<h4>".__('HTTP Transports available').":</h4>\n";
665 - print "<ol>\n";
666 - print "<li>".implode("</li>\n<li>", array_map('get_class', $transports))."</li>\n";
667 - print "</ol>\n";
668 - print "</div>\n";
669 - endif;
1101 + function display_alt_feed_box ($lookup, $params = false) {
670 1102
1103 + if (is_bool($params)) :
1104 + $params = array("alt" => $params);
671 1105 endif;
672 - ?>
673 - </div>
674 -
675 - <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
676 - <div><?php
677 - FeedWordPressCompatibility::stamp_nonce(get_class($this));
678 - ?></div>
679 - <div class="wrap">
680 - <h2>Use another feed</h2>
681 - <div><label>Feed:</label>
682 - <input type="text" name="lookup" id="use-another-feed" value="URI" />
1106 +
1107 + $params = wp_parse_args($params, array( // Defaults
1108 + "alt" => false,
1109 + "err" => NULL,
1110 + "auth" => NULL,
1111 + "password" => NULL,
1112 + "username" => NULL,
1113 + ));
1114 + $alt = $params['alt'];
1115 +
1116 + ?>
1117 + <form action="<?php print esc_url( $this->form_action('syndication.php') ); ?>" method="post">
1118 + <div class="inside"><?php
1119 + FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds');
1120 + ?>
1121 + <fieldset class="alt"
1122 + <?php if (!$alt): ?>style="margin: 1.0em 3.0em; font-size: smaller;"<?php endif; ?>>
1123 + <legend><?php if ($alt) : ?>Alternative feeds<?php else: ?>Find feeds<?php endif; ?></legend>
1124 + <?php if ($alt) : ?><h3>Use a different feed</h3><?php endif; ?>
1125 + <?php if (is_wp_error($params['err'])) :
1126 + ?>
1127 + <p><em><strong>401 Not Authorized.</strong> This URL may require
1128 + a username and password to access it.</em> You may want to add login
1129 + credentials below and check it again.</p>
1130 + <?php
1131 + endif;
1132 + ?>
1133 + <div><label>Address:
1134 + <input type="text" name="lookup" id="use-another-feed"
1135 + placeholder="URL"
1136 + <?php if (is_null($lookup)) : ?>
1137 + value="URL"
1138 + <?php else : ?>
1139 + value="<?php print esc_html($lookup); ?>"
1140 + <?php endif; ?>
1141 + size="64" style="max-width: 80%" /></label>
1142 + <?php if (is_null($lookup)) : ?>
683 1143 <?php FeedWordPressSettingsUI::magic_input_tip_js('use-another-feed'); ?>
1144 + <?php endif; ?>
1145 +
684 1146 <?php $this->stamp_link_id('link_id'); ?>
685 - <input type="hidden" name="action" value="feedfinder" /></div>
686 - <div class="submit"><input type="submit" value="Use this feed &raquo;" /></div>
687 - </div>
688 - </form>
1147 + <input type="hidden" name="action" value="feedfinder" />
1148 + <input type="submit" class="button<?php if ($alt): ?>-primary<?php endif; ?>" value="Check &raquo;" /></div>
1149 +
1150 + <?php $this->display_authentication_credentials_box(array(
1151 + 'username' => $params['username'],
1152 + 'password' => $params['password'],
1153 + 'method' => $params['auth'],
1154 + )); ?>
1155 +
1156 + <p>This can be the address of a feed, or of a website. FeedWordPress
1157 + will try to automatically detect any feeds associated with a
1158 + website.</p>
1159 + </div> <!-- class="inside" -->
1160 + </fieldset></form>
1161 +
689 1162 <?php
690 - return false; // Don't continue
691 - } /* WordPressFeedsPage::display_feedfinder() */
1163 + } /* FeedWordPressFeedsPage::display_alt_feed_box() */
1164 +
1165 + function save_settings () {
1166 + if ($this->for_feed_settings()) :
692 1167
693 - function accept_POST ($post) {
694 - global $wpdb;
695 -
696 - // User mashed a Save Changes button
697 - if (isset($post['save']) or isset($post['submit'])) :
698 - if ($this->for_feed_settings()) :
699 - $alter = array ();
700 -
701 - // custom feed settings first
702 - foreach ($post['notes'] as $mn) :
703 - $mn['key0'] = trim($mn['key0']);
704 - $mn['key1'] = trim($mn['key1']);
705 - if (preg_match("\007^(("
706 - .implode(')|(',$this->special_settings)
707 - ."))$\007i",
708 - $mn['key1'])) :
709 - $mn['key1'] = 'user/'.$mn['key1'];
710 - endif;
1168 + $params_key = FeedWordPress::post( 'link_rss_params_key', array() );
711 1169
712 - if (strlen($mn['key0']) > 0) :
713 - unset($this->link->settings[$mn['key0']]); // out with the old
1170 + if ( is_array( $params_key ) && count($params_key) > 0 ) :
1171 +
1172 + $params_values = FeedWordPress::post( 'link_rss_params_value', array() );
1173 +
1174 + $qp = array();
1175 + foreach ( $params_key as $index => $key ) :
1176 + if (strlen($key) > 0) :
1177 +
1178 + if ( isset( $params_values[ $index ] ) ) :
1179 +
1180 + $params_value = $params_values[ $index ];
1181 + if ( strlen($params_value) > 0 ) :
1182 + $qp[] = array( $key, $params_value );
1183 + endif;
1184 + endif;
714 1185 endif;
715 -
716 - if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) :
717 - $this->link->settings[$mn['key1']] = $mn['value']; // in with the new
718 - endif;
719 1186 endforeach;
720 -
721 - // now stuff through the web form
722 - // hardcoded feed info
723 -
724 - foreach (array('name', 'description', 'url') as $what) :
725 - // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
726 - $this->link->settings["hardcode {$what}"] = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
727 - if (FeedWordPress::affirmative($this->link->settings, "hardcode {$what}")) :
728 - $alter[] = "link_{$what} = '".$wpdb->escape($post['link'.$what])."'";
729 - endif;
730 - endforeach;
731 -
732 - // Update scheduling
733 - if (isset($post['update_schedule'])) :
734 - $this->link->settings['update/hold'] = $post['update_schedule'];
1187 + $this->update_setting('query parameters', serialize($qp));
1188 +
1189 + endif;
1190 +
1191 + // custom feed settings first
1192 + $param_notes = FeedWordPress::post( 'notes', array() );
1193 + foreach ( $param_notes as $mn ) :
1194 + $mn['key0'] = ( isset($mn['key0']) ? trim($mn['key0']) : null );
1195 + $mn['key1'] = trim($mn['key1']);
1196 + if (preg_match("\007^(("
1197 + .implode(')|(',$this->special_settings)
1198 + ."))$\007i",
1199 + $mn['key1'])) :
1200 + $mn['key1'] = 'user/'.$mn['key1'];
735 1201 endif;
736 1202
737 - if (isset($post['use_default_update_window']) and strtolower($post['use_default_update_window'])=='yes') :
738 - unset($this->link->settings['update/window']);
739 - elseif (isset($post['update_window'])):
740 - if ((int) $post['update_window'] > 0) :
741 - $this->link->settings['update/window'] = (int) $post['update_window'];
742 - endif;
1203 + if (strlen($mn['key0']) > 0) :
1204 + unset($this->link->settings[$mn['key0']]); // out with the old
743 1205 endif;
744 1206
745 - $alter[] = "link_notes = '".$wpdb->escape($this->link->settings_to_notes())."'";
1207 + if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) :
1208 + $this->link->settings[$mn['key1']] = $mn['value']; // in with the new
1209 + endif;
1210 + endforeach;
1211 +
1212 + // now stuff through the web form
1213 + // hardcoded feed info
1214 +
1215 + foreach (array('name', 'description', 'url') as $what) :
1216 + // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
1217 + $this->link->settings["hardcode {$what}"] = FeedWordPress::post( "hardcode_{$what}", 'yes' );
1218 + if (FeedWordPress::affirmative($this->link->settings, "hardcode {$what}")) :
1219 + $this->link->link->{'link_'.$what} = FeedWordPress::post( 'link' . $what );
1220 + endif;
1221 + endforeach;
746 1222
747 - $alter_set = implode(", ", $alter);
1223 + // Update scheduling
1224 + $update_schedule = FeedWordPress::post( 'update_schedule' );
1225 + if ( ! is_null( $update_schedule ) ) :
1226 + $this->link->settings['update/hold'] = $update_schedule;
1227 + endif;
748 1228
749 - // issue update query
750 - $result = $wpdb->query("
751 - UPDATE $wpdb->links
752 - SET $alter_set
753 - WHERE link_id='{$this->link->id}'
754 - ");
755 - $this->updated = true;
1229 + $use_default_update_window = FeedWordPress::post( 'use_default_update_window' );
1230 + $update_window = FeedWordPress::post( 'update_window' );
1231 + if ( FeedWordPress::affirmative( $use_default_update_window ) ) :
1232 + unset($this->link->settings['update/window']);
1233 + elseif ( ! is_null( $update_window ) ) :
1234 + $update_window = intval( $update_window );
1235 + if ( $update_window > 0 ) :
1236 + $this->link->settings['update/window'] = $update_window;
1237 + endif;
1238 + endif;
1239 +
1240 + else :
1241 + // Global
1242 + update_option('feedwordpress_cat_id', FeedWordPress::post( 'syndication_category' ) );
1243 +
1244 + $automatic_updates = FeedWordPress::post( 'automatic_updates' );
1245 + if ( ! in_array( $automatic_updates, array( 'init', 'shutdown' ) ) ) :
1246 + $automatic_updates = null;
1247 + endif;
1248 + update_option('feedwordpress_automatic_updates', $automatic_updates);
756 1249
757 - // reload link information from DB
758 - if (function_exists('clean_bookmark_cache')) :
759 - clean_bookmark_cache($this->link->id);
1250 + $update_window = FeedWordPress::post( 'update_window' );
1251 + if ( ! is_null( $update_window ) ) :
1252 + $update_window = intval( $update_window );
1253 + if ( $update_window > 0 ) :
1254 + update_option( 'feedwordpress_update_window', $update_window );
760 1255 endif;
761 - $this->link = new SyndicatedLink($this->link->id);
762 - else :
763 - // Global
764 - update_option('feedwordpress_cat_id', $post['syndication_category']);
765 -
766 - if (!isset($post['automatic_updates']) or !in_array($post['automatic_updates'], array('init', 'shutdown'))) :
767 - $automatic_updates = false;
768 - else :
769 - $automatic_updates = $post['automatic_updates'];
770 - endif;
771 - update_option('feedwordpress_automatic_updates', $automatic_updates);
1256 + endif;
772 1257
773 - if (isset($post['update_window'])):
774 - if ((int) $post['update_window'] > 0) :
775 - update_option('feedwordpress_update_window', (int) $post['update_window']);
776 - endif;
777 - endif;
1258 + $update_time_limit = FeedWordPress::post( 'update_time_limit' );
1259 + $time_limit_seconds = 0;
1260 + if ( FeedWordPress::affirmative( $update_time_limit ) ) :
1261 + $time_limit_seconds = intval( FeedWordPress::post( 'time_limit_seconds' ) );
1262 + endif;
1263 + update_option( 'feedwordpress_update_time_limit', $time_limit_seconds );
778 1264
779 - update_option('feedwordpress_update_time_limit', ($post['update_time_limit']=='yes')?(int) $post['time_limit_seconds']:0);
1265 + foreach (array('name', 'description', 'url') as $what) :
1266 + // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
1267 + $hardcode = FeedWordPress::post( "hardcode_{$what}", 'yes' );
1268 + update_option( "feedwordpress_hardcode_{$what}", $hardcode );
1269 + endforeach;
1270 +
1271 + endif;
780 1272
781 - foreach (array('name', 'description', 'url') as $what) :
782 - // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
783 - $hardcode = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
784 - update_option("feedwordpress_hardcode_{$what}", $hardcode);
785 - endforeach;
786 -
787 - $this->updated = true;
1273 + $update_pause = FeedWordPress::post( 'update_pause' );
1274 + if ( ! is_null( $update_pause ) ) :
1275 + $this->update_setting( 'update/pause', $update_pause );
1276 + endif;
1277 +
1278 + $fetch_timeout = FeedWordPress::post( 'fetch_timeout' );
1279 + if ( ! is_null( $fetch_timeout ) ) :
1280 + $fetch_timeout_default = FeedWordPress::post( 'fetch_timeout_default' );
1281 + if ( FeedWordPress::affirmative( $fetch_timeout_default ) ) :
1282 + $fetch_timeout = null;
788 1283 endif;
789 1284
790 - // Probably a "Go" button for the drop-down
791 - else :
792 - $this->updated = false;
1285 + if ( is_int( $fetch_timeout ) ) :
1286 + $fetch_timeout = intval( $fetch_timeout );
1287 + endif;
1288 + $this->update_setting( 'fetch timeout', $fetch_timeout );
793 1289 endif;
794 - } /* WordPressFeedsPage::accept_POST() */
1290 +
1291 + $update_incremental = FeedWordPress::post( 'update_incremental' );
1292 + if ( ! is_null( $update_incremental ) ) :
1293 + $this->update_setting( 'update_incremental', $update_incremental );
1294 + endif;
1295 +
1296 + $tombstones = FeedWordPress::post( 'tombstones' );
1297 + if ( ! is_null( $tombstones ) ) :
1298 + $this->update_setting('tombstones', $tombstones );
1299 + endif;
1300 +
1301 + $update_minimum = FeedWordPress::post( 'update_minimum' );
1302 + if ( ! is_null( $update_minimum ) ) :
1303 + $this->update_setting( 'update/minimum', $update_minimum );
1304 + endif;
1305 +
1306 + $link_rss_auth_method = FeedWordPress::post( 'link_rss_auth_method' );
1307 + if (
1308 + ! $link_rss_auth_method
1309 + || '-' == $link_rss_auth_method
1310 + ) :
1311 + $link_rss_auth_method = null;
1312 + endif;
1313 + $this->update_setting( 'http auth method', $link_rss_auth_method );
1314 +
1315 + $link_rss_username = FeedWordPress::post( 'link_rss_username' );
1316 + if (
1317 + ! $link_rss_username
1318 + || is_null( $link_rss_auth_method )
1319 + ) :
1320 + $link_rss_username = null;
1321 + endif;
1322 + $this->update_setting( 'http username', $link_rss_username );
1323 +
1324 + $link_rss_password = FeedWordPress::post( 'link_rss_password' );
1325 + if (
1326 + strlen( $link_rss_password ) == 0
1327 + || is_null( $link_rss_auth_method )
1328 + ) :
1329 + $link_rss_password = null;
1330 + endif;
1331 + $this->update_setting( 'http password', $link_rss_password );
1332 +
1333 + $this->updatedPosts->accept_POST();
1334 +
1335 + parent::save_settings();
1336 + } /* FeedWordPressFeedsPage::save_settings() */
795 1337
796 1338 } /* class FeedWordPressFeedsPage */
797 1339
798 1340 $feedsPage = new FeedWordPressFeedsPage;