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