PluginProbe
FeedWordPress / 2010.0903
FeedWordPress v2010.0903
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
feedwordpress / feeds-page.php

feeds-page.php in FeedWordPress 2010.0903, at feeds-page.php

817 lines 31.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once(dirname(__FILE__) . '/admin-ui.php');
3 require_once(dirname(__FILE__) . '/magpiemocklink.class.php');
4 require_once(dirname(__FILE__) . '/feedfinder.class.php');
5 require_once(dirname(__FILE__) . '/updatedpostscontrol.class.php');
6
7 class FeedWordPressFeedsPage extends FeedWordPressAdminPage {
8 var $HTTPStatusMessages = array (
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.',
10 201 => 'Created',
11 202 => 'Accepted',
12 203 => 'Non-Authoritative information',
13 204 => 'No Content',
14 205 => 'Reset Content',
15 206 => 'Partial Content',
16 300 => 'Multiple Choices',
17 301 => 'Moved Permanently',
18 302 => 'Found',
19 303 => 'See Other',
20 304 => 'Not Modified',
21 305 => 'Use Proxy',
22 307 => 'Temporary Redirect',
23 400 => 'Bad Request',
24 401 => 'Unauthorized. This URL probably needs a username and password for you to access it.',
25 402 => 'Payment Required',
26 403 => 'Forbidden. The URL is not made available for the machine that FeedWordPress is running on.',
27 404 => 'Not Found. There is nothing at this URL. Have you checked the address for typos?',
28 405 => 'Method Not Allowed',
29 406 => 'Not Acceptable',
30 407 => 'Proxy Authentication Required',
31 408 => 'Request Timeout',
32 409 => 'Conflict',
33 410 => 'Gone. This URL is no longer available on this server and no forwarding address is known.',
34 411 => 'Length Required',
35 412 => 'Precondition Failed',
36 413 => 'Request Entity Too Large',
37 414 => 'Request URI Too Long',
38 415 => 'Unsupported Media Type',
39 416 => 'Requested Range Not Satisfiable',
40 417 => 'Expectation Failed',
41 500 => 'Internal Server Error. Something unexpected went wrong with the configuration of the server that hosts this URL. You might try again later to see if this issue has been resolved.',
42 501 => 'Not Implemented',
43 502 => 'Bad Gateway',
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.',
45 504 => 'Gateway Timeout',
46 505 => 'HTTP Version Not Supported',
47 );
48 var $updatedPosts = NULL;
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 = 'feedwordpress_admin_page_feeds';
63 $this->pagenames = array(
64 'default' => 'Feeds',
65 'settings-update' => 'Syndicated feed',
66 'open-sheet' => 'Feed and Update',
67 );
68 $this->filename = __FILE__;
69 $this->updatedPosts = new UpdatedPostsControl($this);
70 } /* FeedWordPressFeedsPage constructor */
71
72 var $special_settings = array ( /* Regular expression syntax is OK here */
73 'cats',
74 'cat_split',
75 'freeze updates',
76 'hardcode name',
77 'hardcode url',
78 'hardcode description',
79 'hardcode categories', /* Deprecated */
80 'comment status',
81 'terms',
82 'map authors',
83 'munge permalink',
84 'ping status',
85 'post status',
86 'postmeta',
87 'resolve relative',
88 'syndicated post type',
89 'tags',
90 'unfamiliar author',
91 'unfamliar categories', /* Deprecated */
92 'unfamiliar category',
93 'unfamiliar post_tag',
94 'update/.*',
95 'feed/.*',
96 'link/.*',
97 'match/.*',
98 );
99
100 function display () {
101 global $fwp_post;
102 global $post_source;
103
104 $this->boxes_by_methods = array(
105 'feed_information_box' => __('Feed Information'),
106 'global_feeds_box' => __('Update Scheduling'),
107 'updated_posts_box' => __('Updated Posts'),
108 'custom_settings_box' => __('Custom Feed Settings (for use in templates)'),
109 );
110 if ($this->for_default_settings()) :
111 unset($this->boxes_by_methods['custom_settings_box']);
112 endif;
113
114 // Allow overriding of normal source for FeedFinder, which may
115 // be called from multiple points.
116 if (isset($post_source) and !is_null($post_source)) :
117 $source = $post_source;
118 else :
119 $source = $this->dispatch;
120 endif;
121
122 if (isset($_REQUEST['feedfinder'])
123 or (isset($_REQUEST['action']) and $_REQUEST['action']=='feedfinder')
124 or (isset($_REQUEST['action']) and $_REQUEST['action']==FWP_SYNDICATE_NEW)) :
125 // If this is a POST, validate source and user credentials
126 FeedWordPressCompatibility::validate_http_request(/*action=*/ $source, /*capability=*/ 'manage_links');
127
128 return $this->display_feedfinder(); // re-route to Feed Finder page
129 endif;
130
131 parent::display();
132 return false; // Don't continue
133 } /* FeedWordPressFeedsPage::display() */
134
135 function ajax_interface_js () {
136 FeedWordPressAdminPage::ajax_interface_js();
137 ?>
138
139 jQuery(document).ready( function () {
140 contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');
141 contextual_appearance('time-limit', 'time-limit-box', null, 'yes');
142 contextual_appearance('use-default-update-window-no', 'update-scheduling-note', null, null, 'block', true);
143 jQuery('#use-default-update-window-yes, #use-default-update-window-no').click( function () {
144 contextual_appearance('use-default-update-window-no', 'update-scheduling-note', null, null, 'block', true);
145 } );
146
147 var els = ['name', 'description', 'url'];
148 for (var i = 0; i < els.length; i++) {
149 contextual_appearance(
150 /*item=*/ 'basics-hardcode-'+els[i],
151 /*appear=*/ 'basics-'+els[i]+'-view',
152 /*disappear=*/ 'basics-'+els[i]+'-edit',
153 /*value=*/ 'no',
154 /*visibleStyle=*/ 'block',
155 /*checkbox=*/ true
156 );
157 } /* for */
158 } );
159
160 <?php
161 }
162
163 /*static*/ function updated_posts_box ($page, $box = NULL) {
164 ?>
165 <table class="edit-form">
166 <?php $page->updatedPosts->display(); ?>
167 </table>
168 <?php
169 } /* FeedWordPressFeedsPage::updated_posts_box() */
170
171 /*static*/ function global_feeds_box ($page, $box = NULL) {
172 $automatic_updates = get_option('feedwordpress_automatic_updates');
173 $update_time_limit = (int) get_option('feedwordpress_update_time_limit');
174
175 // Hey, ho, let's go...
176 ?>
177
178 <table class="edit-form">
179 <?php if ($page->for_default_settings()) : ?>
180
181 <tr>
182 <th scope="row">Updates:</th>
183 <td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');">
184 <option value="shutdown"<?php echo ($automatic_updates=='shutdown')?' selected="selected"':''; ?>>automatically check for updates after pages load</option>
185 <option value="init"<?php echo ($automatic_updates=='init')?' selected="selected"':''; ?>>automatically check for updates before pages load</option>
186 <option value="no"<?php echo (!$automatic_updates)?' selected="selected"':''; ?>>cron job or manual updates</option>
187 </select>
188 <div id="cron-job-explanation" class="setting-description">
189 <p>If you want to use a cron job,
190 you can perform scheduled updates by sending regularly-scheduled
191 requests to <a href="<?php bloginfo('home'); ?>?update_feedwordpress=1"><code><?php bloginfo('url') ?>?update_feedwordpress=1</code></a>
192 For example, inserting the following line in your crontab:</p>
193 <pre style="font-size: 0.80em"><code>*/10 * * * * /usr/bin/curl --silent <?php bloginfo('url'); ?>?update_feedwordpress=1</code></pre>
194 <p class="setting-description">will check in every 10 minutes
195 and check for updates on any feeds that are ready to be polled for updates.</p>
196 </div>
197 </td>
198 </tr>
199
200 <?php else : /* Feed-specific settings */ ?>
201
202 <tr>
203 <th scope="row"><?php _e('Last update') ?>:</th>
204 <td><?php
205 if (isset($page->link->settings['update/last'])) :
206 echo fwp_time_elapsed($page->link->settings['update/last'])." ";
207 else :
208 echo " none yet";
209 endif;
210 ?></td></tr>
211
212 <tr><th><?php _e('Next update') ?>:</th>
213 <td><?php
214 $holdem = (isset($page->link->settings['update/hold']) ? $page->link->settings['update/hold'] : 'scheduled');
215 ?>
216 <select name="update_schedule">
217 <option value="scheduled"<?php echo ($holdem=='scheduled')?' selected="selected"':''; ?>>update on schedule <?php
218 echo " (";
219 if (isset($page->link->settings['update/ttl']) and is_numeric($page->link->settings['update/ttl'])) :
220 if (isset($page->link->settings['update/timed']) and $page->link->settings['update/timed']=='automatically') :
221 echo 'next: ';
222 $next = $page->link->settings['update/last'] + ((int) $page->link->settings['update/ttl'] * 60);
223 if (strftime('%x', time()) != strftime('%x', $next)) :
224 echo strftime('%x', $next)." ";
225 endif;
226 echo strftime('%X', $page->link->settings['update/last']+((int) $page->link->settings['update/ttl']*60));
227 else :
228 echo "every ".$page->link->settings['update/ttl']." minute".(($page->link->settings['update/ttl']!=1)?"s":"");
229 endif;
230 else:
231 echo "next scheduled update";
232 endif;
233 echo ")";
234 ?></option>
235 <option value="next"<?php echo ($holdem=='next')?' selected="selected"':''; ?>>update ASAP</option>
236 <option value="ping"<?php echo ($holdem=='ping')?' selected="selected"':''; ?>>update only when pinged</option>
237 </select></td></tr>
238
239 <?php endif; ?>
240
241 <tr>
242 <th scope="row"><?php print __('Update scheduling:') ?></th>
243 <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>
244 <?php
245
246 $this->setting_radio_control(
247 'update/window', 'update_window',
248 array(&$this, 'update_window_edit_box'),
249 array(
250 'global-setting-default' => DEFAULT_UPDATE_PERIOD,
251 'default-input-name' => 'use_default_update_window',
252 'default-input-id' => 'use-default-update-window-yes',
253 'default-input-id-no' => 'use-default-update-window-no',
254 'labels' => array(&$this, 'update_window_currently'),
255 )
256 );
257 ?></td>
258 </tr>
259
260 <?php if ($this->for_default_settings()) : ?>
261
262 <tr>
263 <th scope="row"><?php print __('Time limit on updates'); ?>:</th>
264 <td><select id="time-limit" name="update_time_limit" size="1" onchange="contextual_appearance('time-limit', 'time-limit-box', null, 'yes');">
265 <option value="no"<?php echo ($update_time_limit>0)?'':' selected="selected"'; ?>>no time limit on updates</option>
266 <option value="yes"<?php echo ($update_time_limit>0)?' selected="selected"':''; ?>>limit updates to no more than...</option>
267 </select>
268 <span id="time-limit-box"><label><input type="text" name="time_limit_seconds" value="<?php print $update_time_limit; ?>" size="5" /> seconds</label></span>
269 </tr>
270
271 <?php endif; ?>
272
273 </table>
274
275 <?php
276 } /* FeedWordPressFeedsPage::global_feeds_box() */
277
278 function update_window_edit_box ($updateWindow, $defaulted, $params) {
279 if (!is_numeric($updateWindow)) :
280 $updateWindow = DEFAULT_UPDATE_PERIOD;
281 endif;
282 ?>
283 <p>Wait <input type="text" name="update_window" value="<?php print $updateWindow; ?>" size="4" /> minutes between polling.</p>
284 <div class="setting-description" id="update-scheduling-note">
285 <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>
286 <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>
287 </div>
288 <?php
289 } /* FeedWordPressFeedsPage::update_window_edit_box () */
290
291 function update_window_currently ($updateWindow, $defaulted, $params) {
292 $updateWindow = (int) $updateWindow;
293 if (1==$updateWindow) :
294 $caption = 'wait %d minute between polling';
295 else :
296 $caption = 'wait %d minutes between polling';
297 endif;
298 return sprintf(__($caption), $updateWindow);
299 } /* FeedWordPressFeedsPage::update_window_currently () */
300
301 function feed_information_box ($page, $box = NULL) {
302 global $wpdb;
303 if ($page->for_feed_settings()) :
304 $info['name'] = esc_html($page->link->link->link_name);
305 $info['description'] = esc_html($page->link->link->link_description);
306 $info['url'] = esc_html($page->link->link->link_url);
307 $rss_url = $page->link->link->link_rss;
308
309 $hardcode['name'] = $page->link->hardcode('name');
310 $hardcode['description'] = $page->link->hardcode('description');
311 $hardcode['url'] = $page->link->hardcode('url');
312 else :
313 $cat_id = FeedWordPress::link_category_id();
314
315 $params = array();
316 if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_USES_ARGS_TAXONOMY)) :
317 $params['taxonomy'] = 'link_category';
318 else :
319 $params['type'] = 'link';
320 endif;
321 $params['hide_empty'] = false;
322 $results = get_categories($params);
323
324 // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
325 $found_link_category_id = false;
326 foreach ($results as $row) :
327 // Normalize case
328 if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
329
330 if ($row->cat_id == $cat_id) : $found_link_category_id = true; endif;
331 endforeach;
332
333 if (!$found_link_category_id) :
334 $results[] = get_category($cat_id);
335 endif;
336
337 $info = array();
338 $rss_url = null;
339
340 $hardcode['name'] = get_option('feedwordpress_hardcode_name');
341 $hardcode['description'] = get_option('feedwordpress_hardcode_description');
342 $hardcode['url'] = get_option('feedwordpress_hardcode_url');
343 endif;
344
345 // Hey ho, let's go
346 ?>
347 <table class="edit-form">
348
349 <?php if ($page->for_feed_settings()) : ?>
350
351 <tr>
352 <th scope="row"><?php _e('Feed URL:') ?></th>
353 <td><a href="<?php echo esc_html($rss_url); ?>"><?php echo esc_html($rss_url); ?></a>
354 (<a href="<?php echo FEEDVALIDATOR_URI; ?>?url=<?php echo urlencode($rss_url); ?>"
355 title="Check feed &lt;<?php echo esc_html($rss_url); ?>&gt; for validity">validate</a>)
356 <input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" /></td>
357 </tr>
358
359 <?php
360 $rows = array(
361 "name" => __('Link Name'),
362 "description" => __('Short Description'),
363 "url" => __('Homepage'),
364 );
365 foreach ($rows as $what => $label) :
366 ?>
367 <tr>
368 <th scope="row"><?php print $label ?></th>
369 <td>
370 <div id="basics-<?php print $what; ?>-edit"><input type="text" name="link<?php print $what; ?>"
371 value="<?php echo $info[$what]; ?>" style="width: 95%" /></div>
372 <div id="basics-<?php print $what; ?>-view">
373 <?php if ($what=='url') : ?><a href="<?php print $info[$what]; ?>"><?php else : ?><strong><?php endif; ?>
374 <?php print (strlen(trim($info[$what])) > 0) ? $info[$what] : '(none provided)'; ?>
375 <?php if ($what=='url') : ?></a><?php else : ?></strong><?php endif; ?></div>
376
377 <div>
378 <label><input id="basics-hardcode-<?php print $what; ?>"
379 type="radio" name="hardcode_<?php print $what; ?>" value="no"
380 <?php echo (($hardcode[$what]=='yes')?'':' checked="checked"');?>
381 onchange="contextual_appearance('basics-hardcode-<?php print $what; ?>', 'basics-<?php print $what; ?>-view', 'basics-<?php print $what; ?>-edit', 'no', 'block', /*checkbox=*/ true)"
382 /> Update automatically from feed</label>
383 <label><input type="radio" name="hardcode_<?php print $what; ?>" value="yes"
384 <?php echo (($hardcode[$what]!='yes')?'':' checked="checked"');?>
385 onchange="contextual_appearance('basics-hardcode-<?php print $what; ?>', 'basics-<?php print $what; ?>-view', 'basics-<?php print $what; ?>-edit', 'no', 'block', /*checkbox=*/ true)"
386 /> Edit manually</label>
387 </div>
388 </td>
389 </tr>
390 <?php
391 endforeach;
392 ?>
393
394 <?php else : ?>
395
396 <tr>
397 <th scope="row">Syndicated Link category:</th>
398 <td><p><select name="syndication_category" size="1">
399 <?php
400 foreach ($results as $row) :
401 // Normalize case
402 if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
403
404 echo "\n\t<option value=\"$row->cat_id\"";
405 if ($row->cat_id == $cat_id) :
406 echo " selected='selected'";
407 endif;
408 echo ">$row->cat_id: ".esc_html($row->cat_name);
409 echo "</option>\n";
410 endforeach;
411 ?></select></p>
412 <p class="setting-description">FeedWordPress will syndicate the
413 links placed under this link category.</p>
414 </td>
415 </tr>
416
417 <tr>
418 <th scope="row">Link Names:</th>
419 <td><label><input type="checkbox" name="hardcode_name" value="no"<?php echo (($hardcode['name']=='yes')?'':' checked="checked"');?>/> Update contributor titles automatically when the feed title changes</label></td>
420 </tr>
421
422 <tr>
423 <th scope="row">Short descriptions:</th>
424 <td><label><input type="checkbox" name="hardcode_description" value="no"<?php echo (($hardcode['description']=='yes')?'':' checked="checked"');?>/> Update contributor descriptions automatically when the feed tagline changes</label></td>
425 </tr>
426
427 <tr>
428 <th scope="row">Homepages:</th>
429 <td><label><input type="checkbox" name="hardcode_url" value="no"<?php echo (($hardcode['url']=='yes')?'':' checked="checked"');?>/> Update contributor homepages automatically when the feed link changes</label></td>
430 </tr>
431
432 <?php endif; ?>
433
434 </table>
435 <?php
436 } /* FeedWordPressFeedsPage::feed_information_box() */
437
438 function custom_settings_box ($page, $box = NULL) {
439 ?>
440 <p class="setting-description">These custom settings are special fields for the <strong>feed</strong> you are
441 syndicating, to be retrieved in templates using the <code>get_feed_meta()</code> function. They do not create
442 custom fields on syndicated <strong>posts</strong>. If you want to create custom fields that are applied to each
443 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>
444
445 <div id="postcustomstuff">
446 <table id="meta-list" cellpadding="3">
447 <tr>
448 <th>Key</th>
449 <th>Value</th>
450 <th>Action</th>
451 </tr>
452
453 <?php
454 $i = 0;
455 foreach ($page->link->settings as $key => $value) :
456 if (!preg_match("\007^((".implode(')|(', $page->special_settings)."))$\007i", $key)) :
457 ?>
458 <tr style="vertical-align:top">
459 <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo esc_html($key); ?>" />
460 <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo esc_html($key); ?>" /></th>
461 <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?>-value" name="notes[<?php echo $i; ?>][value]"><?php echo esc_html($value); ?></textarea></td>
462 <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
463 <option value="update">save changes</option>
464 <option value="delete">delete this setting</option>
465 </select></td>
466 </tr>
467 <?php
468 $i++;
469 endif;
470 endforeach;
471 ?>
472 <tr>
473 <th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?>][key1]" value="" /></th>
474 <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea></td>
475 <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td>
476 </tr>
477 </table>
478 </div> <!-- id="postcustomstuff" -->
479 <?php
480 }
481
482 function display_feedfinder () {
483 global $wpdb;
484
485 $lookup = (isset($_REQUEST['lookup']) ? $_REQUEST['lookup'] : NULL);
486
487 $feeds = array(); $feedSwitch = false; $current = null;
488 if ($this->for_feed_settings()) : // Existing feed?
489 $feedSwitch = true;
490 if (is_null($lookup)) :
491 // Switch Feed without a specific feed yet suggested
492 // Go to the human-readable homepage to look for
493 // auto-detection links
494 $lookup = $this->link->link->link_url;
495
496 // Guarantee that you at least have the option to
497 // stick with what works.
498 $current = $this->link->link->link_rss;
499 $feeds[] = $current;
500 endif;
501 $name = esc_html($this->link->link->link_name);
502 else: // Or a new subscription to add?
503 $name = "Subscribe to <code>".esc_html(feedwordpress_display_url($lookup))."</code>";
504 endif;
505 ?>
506 <div class="wrap" id="feed-finder">
507 <h2>Feed Finder: <?php echo $name; ?></h2>
508
509 <?php
510 if ($feedSwitch) :
511 $this->display_alt_feed_box($lookup);
512 endif;
513
514 $finder = array();
515 if (!is_null($current)) :
516 $finder[$current] = new FeedFinder($current);
517 endif;
518 $finder[$lookup] = new FeedFinder($lookup);
519
520 foreach ($finder as $url => $ff) :
521 $feeds = array_merge($feeds, $ff->find());
522 endforeach;
523
524 $feeds = array_values( // Renumber from 0..(N-1)
525 array_unique( // Eliminate duplicates
526 $feeds
527 )
528 );
529
530 if (count($feeds) > 0):
531 if ($feedSwitch) :
532 ?>
533 <h3>Feeds Found</h3>
534 <?php
535 endif;
536
537 if (count($feeds) > 1) :
538 $option_template = 'Option %d: ';
539 $form_class = ' class="multi"';
540 ?>
541 <p><strong>This web page provides at least <?php print count($feeds); ?> different feeds.</strong> These feeds may provide the same information
542 in different formats, or may track different items. (You can check the Feed Information and the
543 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>
544 <?php
545 else :
546 $option_template = '';
547 $form_class = '';
548 endif;
549
550 foreach ($feeds as $key => $f):
551 $pie = FeedWordPress::fetch($f);
552 $rss = (is_wp_error($pie) ? $pie : new MagpieFromSimplePie($pie));
553
554 if ($rss and !is_wp_error($rss)):
555 $feed_link = (isset($rss->channel['link'])?$rss->channel['link']:'');
556 $feed_title = (isset($rss->channel['title'])?$rss->channel['title']:$feed_link);
557 $feed_type = ($rss->feed_type ? $rss->feed_type : 'Unknown');
558 $feed_version_template = '%.1f';
559 $feed_version = $rss->feed_version;
560 else :
561 // Give us some sucky defaults
562 $feed_title = feedwordpress_display_url($lookup);
563 $feed_link = $lookup;
564 $feed_type = 'Unknown';
565 $feed_version_template = '';
566 $feed_version = '';
567 endif;
568 ?>
569 <form<?php print $form_class; ?> action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/syndication.php" method="post">
570 <div class="inside"><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_switchfeed'); ?>
571
572 <?php
573 $classes = array('feed-found'); $currentFeed = '';
574 if (!is_null($current) and $current==$f) :
575 $classes[] = 'current';
576 $currentFeed = ' (currently subscribed)';
577 endif;
578 if ($key%2) :
579 $classes[] = 'alt';
580 endif;
581 ?>
582 <fieldset class="<?php print implode(" ", $classes); ?>">
583 <legend><?php printf($option_template, ($key+1)); print $feed_type." "; printf($feed_version_template, $feed_version); ?> feed<?php print $currentFeed; ?></legend>
584
585 <?php
586 $this->stamp_link_id();
587
588 // No feed specified = add new feed; we
589 // need to pass along a starting title
590 // and homepage URL for the new Link.
591 if (!$this->for_feed_settings()):
592 ?>
593 <input type="hidden" name="feed_title" value="<?php echo esc_html($feed_title); ?>" />
594 <input type="hidden" name="feed_link" value="<?php echo esc_html($feed_link); ?>" />
595 <?php
596 endif;
597 ?>
598
599 <input type="hidden" name="feed" value="<?php echo esc_html($f); ?>" />
600 <input type="hidden" name="action" value="switchfeed" />
601
602 <div>
603 <div class="feed-sample">
604 <?php
605 $link = NULL;
606 $post = NULL;
607 if (!is_wp_error($rss) and count($rss->items) > 0):
608 // Prepare to display Sample Item
609 $link = new MagpieMockLink(array('simplepie' => $pie, 'magpie' => $rss), $f);
610 $post = new SyndicatedPost(array('simplepie' => $rss->originals[0], 'magpie' => $rss->items[0]), $link);
611 ?>
612 <h3>Sample Item</h3>
613 <ul>
614 <li><strong>Title:</strong> <a href="<?php echo $post->post['meta']['syndication_permalink']; ?>"><?php echo $post->post['post_title']; ?></a></li>
615 <li><strong>Date:</strong> <?php print date('d-M-y g:i:s a', $post->published()); ?></li>
616 </ul>
617 <div class="entry">
618 <?php print $post->post['post_content']; ?>
619 </div>
620 <?php
621 do_action('feedwordpress_feed_finder_sample_item', $f, $post, $link);
622 else:
623 if (is_wp_error($rss)) :
624 print '<div class="feed-problem">';
625 print "<h3>Problem:</h3>\n";
626 print "<p>FeedWordPress encountered the following error
627 when trying to retrieve this feed:</p>";
628 print '<p style="margin: 1.0em 3.0em"><code>'.$rss->get_error_message().'</code></p>';
629 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>";
630 print "</div>";
631 endif;
632 ?>
633 <h3>No Items</h3>
634 <p>FeedWordPress found no posts on this feed.</p>
635 <?php
636 endif;
637 ?>
638 </div>
639
640 <div>
641 <h3>Feed Information</h3>
642 <ul>
643 <li><strong>Homepage:</strong> <a href="<?php echo $feed_link; ?>"><?php echo is_null($feed_title)?'<em>Unknown</em>':$feed_title; ?></a></li>
644 <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>
645 <li><strong>Encoding:</strong> <?php echo isset($rss->encoding)?esc_html($rss->encoding):"<em>Unknown</em>"; ?></li>
646 <li><strong>Description:</strong> <?php echo isset($rss->channel['description'])?esc_html($rss->channel['description']):"<em>Unknown</em>"; ?></li>
647 </ul>
648 <?php do_action('feedwordpress_feedfinder_form', $f, $post, $link, $this->for_feed_settings()); ?>
649 <div class="submit"><input type="submit" class="button-primary" name="Use" value="&laquo; Use this feed" />
650 <input type="submit" class="button" name="Cancel" value="× Cancel" /></div>
651 </div>
652 </div>
653 </fieldset>
654 </div> <!-- class="inside" -->
655 </form>
656 <?php
657 unset($link);
658 unset($post);
659 endforeach;
660 else:
661 foreach ($finder as $url => $ff) :
662 $url = esc_html($url);
663 print "<h3>Searched for feeds at ${url}</h3>\n";
664 print "<p><strong>".__('Error').":</strong> ".__("FeedWordPress couldn't find any feeds at").' <code><a href="'.htmlspecialchars($lookup).'">'.htmlspecialchars($lookup).'</a></code>';
665 print ". ".__('Try another URL').".</p>";
666
667 // Diagnostics
668 print "<div class=\"updated\" style=\"margin-left: 3.0em; margin-right: 3.0em;\">\n";
669 print "<h3>".__('Diagnostic information')."</h3>\n";
670 if (!is_null($ff->error()) and strlen($ff->error()) > 0) :
671 print "<h4>".__('HTTP request failure')."</h4>\n";
672 print "<p>".$ff->error()."</p>\n";
673 else :
674 print "<h4>".__('HTTP request completed')."</h4>\n";
675 print "<p><strong>Status ".$ff->status().":</strong> ".$this->HTTPStatusMessages[(int) $ff->status()]."</p>\n";
676 endif;
677
678 // Do some more diagnostics if the API for it is available.
679 if (function_exists('_wp_http_get_object')) :
680 $httpObject = _wp_http_get_object();
681 $transports = $httpObject->_getTransport();
682
683 print "<h4>".__('HTTP Transports available').":</h4>\n";
684 print "<ol>\n";
685 print "<li>".implode("</li>\n<li>", array_map('get_class', $transports))."</li>\n";
686 print "</ol>\n";
687 print "</div>\n";
688 endif;
689 endforeach;
690 endif;
691
692 if (!$feedSwitch) :
693 $this->display_alt_feed_box($lookup, /*alt=*/ true);
694 endif;
695 ?>
696 </div> <!-- class="wrap" -->
697 <?php
698 return false; // Don't continue
699 } /* FeedWordPressFeedsPage::display_feedfinder() */
700
701 function display_alt_feed_box ($lookup, $alt = false) {
702 global $fwp_post;
703 ?>
704 <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
705 <div class="inside"><?php
706 FeedWordPressCompatibility::stamp_nonce($this->dispatch);
707 ?>
708 <fieldset class="alt"
709 <?php if (!$alt): ?>style="margin: 1.0em 3.0em; font-size: smaller;"<?php endif; ?>>
710 <legend><?php if ($alt) : ?>Alternative feeds<?php else: ?>Find feeds<?php endif; ?></legend>
711 <?php if ($alt) : ?><h3>Use a different feed</h3><?php endif; ?>
712 <div><label>Address:
713 <input type="text" name="lookup" id="use-another-feed"
714 placeholder="URL"
715 <?php if (is_null($lookup)) : ?>
716 value="URL"
717 <?php else : ?>
718 value="<?php print esc_html($lookup); ?>"
719 <?php endif; ?>
720 size="64" style="max-width: 80%" /></label>
721 <?php if (is_null($lookup)) : ?>
722 <?php FeedWordPressSettingsUI::magic_input_tip_js('use-another-feed'); ?>
723 <?php endif; ?>
724 <?php $this->stamp_link_id('link_id'); ?>
725 <input type="hidden" name="action" value="feedfinder" />
726 <input type="submit" class="button<?php if ($alt): ?>-primary<?php endif; ?>" value="Check &raquo;" /></div>
727 <p>This can be the address of a feed, or of a website. FeedWordPress
728 will try to automatically detect any feeds associated with a
729 website.</p>
730 </div> <!-- class="inside" -->
731 </fieldset></form>
732
733 <?php
734 } /* FeedWordPressFeedsPage::display_alt_feed_box() */
735
736 function save_settings ($post) {
737 if ($this->for_feed_settings()) :
738 // custom feed settings first
739 foreach ($post['notes'] as $mn) :
740 $mn['key0'] = (isset($mn['key0']) ? trim($mn['key0']) : NULL);
741 $mn['key1'] = trim($mn['key1']);
742 if (preg_match("\007^(("
743 .implode(')|(',$this->special_settings)
744 ."))$\007i",
745 $mn['key1'])) :
746 $mn['key1'] = 'user/'.$mn['key1'];
747 endif;
748
749 if (strlen($mn['key0']) > 0) :
750 unset($this->link->settings[$mn['key0']]); // out with the old
751 endif;
752
753 if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) :
754 $this->link->settings[$mn['key1']] = $mn['value']; // in with the new
755 endif;
756 endforeach;
757
758 // now stuff through the web form
759 // hardcoded feed info
760
761 foreach (array('name', 'description', 'url') as $what) :
762 // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
763 $this->link->settings["hardcode {$what}"] = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
764 if (FeedWordPress::affirmative($this->link->settings, "hardcode {$what}")) :
765 $this->link->link->{'link_'.$what} = $post['link'.$what];
766 endif;
767 endforeach;
768
769 // Update scheduling
770 if (isset($post['update_schedule'])) :
771 $this->link->settings['update/hold'] = $post['update_schedule'];
772 endif;
773
774 if (isset($post['use_default_update_window']) and strtolower($post['use_default_update_window'])=='yes') :
775 unset($this->link->settings['update/window']);
776 elseif (isset($post['update_window'])):
777 if ((int) $post['update_window'] > 0) :
778 $this->link->settings['update/window'] = (int) $post['update_window'];
779 endif;
780 endif;
781
782 else :
783 // Global
784 update_option('feedwordpress_cat_id', $post['syndication_category']);
785
786 if (!isset($post['automatic_updates']) or !in_array($post['automatic_updates'], array('init', 'shutdown'))) :
787 $automatic_updates = false;
788 else :
789 $automatic_updates = $post['automatic_updates'];
790 endif;
791 update_option('feedwordpress_automatic_updates', $automatic_updates);
792
793 if (isset($post['update_window'])):
794 if ((int) $post['update_window'] > 0) :
795 update_option('feedwordpress_update_window', (int) $post['update_window']);
796 endif;
797 endif;
798
799 update_option('feedwordpress_update_time_limit', ($post['update_time_limit']=='yes')?(int) $post['time_limit_seconds']:0);
800
801 foreach (array('name', 'description', 'url') as $what) :
802 // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
803 $hardcode = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
804 update_option("feedwordpress_hardcode_{$what}", $hardcode);
805 endforeach;
806 endif;
807
808 $this->updatedPosts->accept_POST($post);
809 parent::save_settings($post);
810 } /* FeedWordPressFeedsPage::save_settings() */
811
812 } /* class FeedWordPressFeedsPage */
813
814 $feedsPage = new FeedWordPressFeedsPage;
815 $feedsPage->display();
816
817