PluginProbe
FeedWordPress / 2010.0531
FeedWordPress v2010.0531
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.0531, at feeds-page.php

833 lines 33.0 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 = get_class($this);
63 $this->filename = __FILE__;
64 $this->updatedPosts = new UpdatedPostsControl($this);
65 } /* FeedWordPressFeedsPage constructor */
66
67 var $special_settings = array ( /* Regular expression syntax is OK here */
68 'cats',
69 'cat_split',
70 'hardcode name',
71 'hardcode url',
72 'hardcode description',
73 'hardcode categories', /* Deprecated */
74 'post status',
75 'comment status',
76 'ping status',
77 'unfamiliar author',
78 'unfamliar categories', /* Deprecated */
79 'unfamiliar category',
80 'map authors',
81 'tags',
82 'postmeta',
83 'resolve relative',
84 'freeze updates',
85 'munge permalink',
86 'update/.*',
87 'feed/.*',
88 'link/.*',
89 );
90
91 function display () {
92 global $wpdb;
93 global $fwp_post;
94 global $post_source;
95
96 if (FeedWordPress::needs_upgrade()) :
97 fwp_upgrade_page();
98 return;
99 endif;
100
101 // Allow overriding of normal source for FeedFinder, which may
102 // be called from multiple points.
103 if (isset($post_source) and !is_null($post_source)) :
104 $source = $post_source;
105 else :
106 $source = get_class($this);
107 endif;
108
109 // If this is a POST, validate source and user credentials
110 FeedWordPressCompatibility::validate_http_request(/*action=*/ $source, /*capability=*/ 'manage_links');
111
112 if (isset($_REQUEST['feedfinder'])
113 or (isset($_REQUEST['action']) and $_REQUEST['action']=='feedfinder')
114 or (isset($_REQUEST['action']) and $_REQUEST['action']==FWP_SYNDICATE_NEW)) :
115 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(); ?>
175
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;
191 return false; // Don't continue
192 } /* FeedWordPressFeedsPage::display() */
193
194 /*static*/ function updated_posts_box ($page, $box = NULL) {
195 ?>
196 <table class="edit-form">
197 <?php $page->updatedPosts->display(); ?>
198 </table>
199 <?php
200 } /* FeedWordPressFeedsPage::updated_posts_box() */
201
202 /*static*/ function global_feeds_box ($page, $box = NULL) {
203 global $wpdb;
204
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;
211 ?>
212
213 <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 ?>
219
220 <tr>
221 <th scope="row">Updates:</th>
222 <td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');">
223 <option value="shutdown"<?php echo ($automatic_updates=='shutdown')?' selected="selected"':''; ?>>automatically check for updates after pages load</option>
224 <option value="init"<?php echo ($automatic_updates=='init')?' selected="selected"':''; ?>>automatically check for updates before pages load</option>
225 <option value="no"<?php echo (!$automatic_updates)?' selected="selected"':''; ?>>cron job or manual updates</option>
226 </select>
227 <div id="cron-job-explanation" class="setting-description">
228 <p>If you want to use a cron job,
229 you can perform scheduled updates by sending regularly-scheduled
230 requests to <a href="<?php bloginfo('home'); ?>?update_feedwordpress=1"><code><?php bloginfo('url') ?>?update_feedwordpress=1</code></a>
231 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('url'); ?>?update_feedwordpress=1</code></pre>
233 <p class="setting-description">will check in every 10 minutes
234 and check for updates on any feeds that are ready to be polled for updates.</p>
235 </div>
236 </td>
237 </tr>
238
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>
257
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 <tr>
271 <th scope="row"><?php _e('Last update') ?>:</th>
272 <td><?php
273 if (isset($page->link->settings['update/last'])) :
274 echo fwp_time_elapsed($page->link->settings['update/last'])." ";
275 else :
276 echo " none yet";
277 endif;
278 ?></td></tr>
279
280 <tr><th><?php _e('Next update') ?>:</th>
281 <td><?php
282 $holdem = (isset($page->link->settings['update/hold']) ? $page->link->settings['update/hold'] : 'scheduled');
283 ?>
284 <select name="update_schedule">
285 <option value="scheduled"<?php echo ($holdem=='scheduled')?' selected="selected"':''; ?>>update on schedule <?php
286 echo " (";
287 if (isset($page->link->settings['update/ttl']) and is_numeric($page->link->settings['update/ttl'])) :
288 if (isset($page->link->settings['update/timed']) and $page->link->settings['update/timed']=='automatically') :
289 echo 'next: ';
290 $next = $page->link->settings['update/last'] + ((int) $page->link->settings['update/ttl'] * 60);
291 if (strftime('%x', time()) != strftime('%x', $next)) :
292 echo strftime('%x', $next)." ";
293 endif;
294 echo strftime('%X', $page->link->settings['update/last']+((int) $page->link->settings['update/ttl']*60));
295 else :
296 echo "every ".$page->link->settings['update/ttl']." minute".(($page->link->settings['update/ttl']!=1)?"s":"");
297 endif;
298 else:
299 echo "next scheduled update";
300 endif;
301 echo ")";
302 ?></option>
303 <option value="next"<?php echo ($holdem=='next')?' selected="selected"':''; ?>>update ASAP</option>
304 <option value="ping"<?php echo ($holdem=='ping')?' selected="selected"':''; ?>>update only when pinged</option>
305 </select></td></tr>
306
307 <tr>
308 <th scope="row"><?php print __('Update scheduling:') ?></th>
309 <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>
314
315 <div class="setting-description">
316 <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 <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>
319 </tr>
320 <?php endif; ?>
321
322
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
331 function feed_information_box ($page, $box = NULL) {
332 global $wpdb;
333 if ($page->for_feed_settings()) :
334 $info['name'] = esc_html($page->link->link->link_name);
335 $info['description'] = esc_html($page->link->link->link_description);
336 $info['url'] = esc_html($page->link->link->link_url);
337 $rss_url = $page->link->link->link_rss;
338
339 $hardcode['name'] = $page->link->hardcode('name');
340 $hardcode['description'] = $page->link->hardcode('description');
341 $hardcode['url'] = $page->link->hardcode('url');
342 else :
343 $cat_id = FeedWordPress::link_category_id();
344
345 $results = get_categories(array(
346 "taxonomy" => 'link_category',
347 "hide_empty" => false,
348 ));
349
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;
355
356 if ($row->cat_id == $cat_id) : $found_link_category_id = true; endif;
357 endforeach;
358
359 if (!$found_link_category_id) :
360 $results[] = get_category($cat_id);
361 endif;
362
363 $info = array();
364 $rss_url = null;
365
366 $hardcode['name'] = get_option('feedwordpress_hardcode_name');
367 $hardcode['description'] = get_option('feedwordpress_hardcode_description');
368 $hardcode['url'] = get_option('feedwordpress_hardcode_url');
369 endif;
370
371 // Hey ho, let's go
372 ?>
373 <style type="text/css">
374 table.edit-form { width: 100%; }
375 table.edit-form th { width: 25%; vertical-align: top; text-align: right; padding: 0.5em; }
376 table.edit-form td { width: 75%; vertical-align: top; padding: 0.5em; }
377 table.edit-form td ul.options { margin: 0; padding: 0; list-style: none; }
378 </style>
379
380 <table class="edit-form">
381
382 <?php if ($page->for_feed_settings()) : ?>
383
384 <tr>
385 <th scope="row"><?php _e('Feed URL:') ?></th>
386 <td><a href="<?php echo esc_html($rss_url); ?>"><?php echo esc_html($rss_url); ?></a>
387 (<a href="<?php echo FEEDVALIDATOR_URI; ?>?url=<?php echo urlencode($rss_url); ?>"
388 title="Check feed &lt;<?php echo esc_html($rss_url); ?>&gt; for validity">validate</a>)
389 <input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" /></td>
390 </tr>
391
392 <?php
393 $rows = array(
394 "name" => __('Link Name'),
395 "description" => __('Short Description'),
396 "url" => __('Homepage'),
397 );
398 foreach ($rows as $what => $label) :
399 ?>
400 <tr>
401 <th scope="row"><?php print $label ?></th>
402 <td>
403 <div id="basics-<?php print $what; ?>-edit"><input type="text" name="link<?php print $what; ?>"
404 value="<?php echo $info[$what]; ?>" style="width: 95%" /></div>
405 <div id="basics-<?php print $what; ?>-view">
406 <?php if ($what=='url') : ?><a href="<?php print $info[$what]; ?>"><?php else : ?><strong><?php endif; ?>
407 <?php print (strlen(trim($info[$what])) > 0) ? $info[$what] : '(none provided)'; ?>
408 <?php if ($what=='url') : ?></a><?php else : ?></strong><?php endif; ?></div>
409
410 <div>
411 <label><input id="basics-hardcode-<?php print $what; ?>"
412 type="radio" name="hardcode_<?php print $what; ?>" value="no"
413 <?php echo (($hardcode[$what]=='yes')?'':' checked="checked"');?>
414 onchange="contextual_appearance('basics-hardcode-<?php print $what; ?>', 'basics-<?php print $what; ?>-view', 'basics-<?php print $what; ?>-edit', 'no', 'block', /*checkbox=*/ true)"
415 /> Update automatically from feed</label>
416 <label><input type="radio" name="hardcode_<?php print $what; ?>" value="yes"
417 <?php echo (($hardcode[$what]!='yes')?'':' checked="checked"');?>
418 onchange="contextual_appearance('basics-hardcode-<?php print $what; ?>', 'basics-<?php print $what; ?>-view', 'basics-<?php print $what; ?>-edit', 'no', 'block', /*checkbox=*/ true)"
419 /> Edit manually</label>
420 </div>
421 </td>
422 </tr>
423 <?php
424 endforeach;
425 ?>
426
427 <?php else : ?>
428
429 <tr>
430 <th scope="row">Syndicated Link category:</th>
431 <td><p><select name="syndication_category" size="1">
432 <?php
433 foreach ($results as $row) :
434 // Normalize case
435 if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
436
437 echo "\n\t<option value=\"$row->cat_id\"";
438 if ($row->cat_id == $cat_id) :
439 echo " selected='selected'";
440 endif;
441 echo ">$row->cat_id: ".esc_html($row->cat_name);
442 echo "</option>\n";
443 endforeach;
444 ?></select></p>
445 <p class="setting-description">FeedWordPress will syndicate the
446 links placed under this link category.</p>
447 </td>
448 </tr>
449
450 <tr>
451 <th scope="row">Link Names:</th>
452 <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>
453 </tr>
454
455 <tr>
456 <th scope="row">Short descriptions:</th>
457 <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>
458 </tr>
459
460 <tr>
461 <th scope="row">Homepages:</th>
462 <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>
463 </tr>
464
465 <?php endif; ?>
466
467 </table>
468 <?php
469 } /* FeedWordPressFeedsPage::feed_information_box() */
470
471 function posts_box ($page, $box = NULL) {
472 $id = (isset($page->link) ? $page->link->id : NULL);
473 FeedWordPressSettingsUI::instead_of_posts_box($id);
474 } /* FeedWordPressFeedsPage::posts_box() */
475
476 function authors_box ($page, $box = NULL) {
477 $id = (isset($page->link) ? $page->link->id : NULL);
478 FeedWordPressSettingsUI::instead_of_authors_box($id);
479 } /* FeedWordPressFeedsPage::authors_box() */
480
481 function categories_box ($page, $box = NULL) {
482 $id = (isset($page->link) ? $page->link->id : NULL);
483 FeedWordPressSettingsUI::instead_of_categories_box($id);
484 } /* FeedWordPressFeedsPage::categories_box() */
485
486 function custom_settings_box ($page, $box = NULL) {
487 ?>
488 <p class="setting-description">These custom settings are special fields for the <strong>feed</strong> you are
489 syndicating, to be retrieved in templates using the <code>get_feed_meta()</code> function. They do not create
490 custom fields on syndicated <strong>posts</strong>. If you want to create custom fields that are applied to each
491 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>
492
493 <div id="postcustomstuff">
494 <table id="meta-list" cellpadding="3">
495 <tr>
496 <th>Key</th>
497 <th>Value</th>
498 <th>Action</th>
499 </tr>
500
501 <?php
502 $i = 0;
503 foreach ($page->link->settings as $key => $value) :
504 if (!preg_match("\007^((".implode(')|(', $page->special_settings)."))$\007i", $key)) :
505 ?>
506 <tr style="vertical-align:top">
507 <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo esc_html($key); ?>" />
508 <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo esc_html($key); ?>" /></th>
509 <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>
510 <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
511 <option value="update">save changes</option>
512 <option value="delete">delete this setting</option>
513 </select></td>
514 </tr>
515 <?php
516 $i++;
517 endif;
518 endforeach;
519 ?>
520 <tr>
521 <th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?>][key1]" value="" /></th>
522 <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea></td>
523 <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td>
524 </tr>
525 </table>
526 </div> <!-- id="postcustomstuff" -->
527 <?php
528 }
529
530 function display_feedfinder () {
531 global $wpdb;
532
533 $lookup = (isset($_REQUEST['lookup']) ? $_REQUEST['lookup'] : NULL);
534
535 if ($this->for_feed_settings()) : // Existing feed?
536 if (is_null($lookup)) : $lookup = $this->link->link->link_url; endif;
537 $name = esc_html($this->link->link->link_name);
538 else: // Or a new subscription to add?
539 $name = "Subscribe to <code>".esc_html(feedwordpress_display_url($lookup))."</code>";
540 endif;
541 ?>
542 <style type="text/css">
543 form.fieldset {
544 clear: both;
545 }
546 .feed-sample {
547 float: right;
548 background-color: #D0D0D0;
549 color: black;
550 width: 45%;
551 font-size: 70%;
552 border-left: 1px dotted #A0A0A0;
553 margin-left: 1.0em;
554 }
555 .feed-sample p, .feed-sample h3 {
556 padding-left: 0.5em;
557 padding-right: 0.5em;
558 }
559 .feed-sample .feed-problem {
560 background-color: #ffd0d0;
561 border-bottom: 1px dotted black;
562 padding-bottom: 0.5em;
563 margin-bottom: 0.5em;
564 }
565 </style>
566
567 <div class="wrap">
568 <h2>Feed Finder: <?php echo $name; ?></h2>
569
570 <?php
571 $f = new FeedFinder($lookup);
572 $feeds = $f->find();
573 if (count($feeds) > 0):
574 foreach ($feeds as $key => $f):
575 $pie = FeedWordPress::fetch($f);
576 $rss = (is_wp_error($pie) ? $pie : new MagpieFromSimplePie($pie));
577
578 if ($rss and !is_wp_error($rss)):
579 $feed_title = isset($rss->channel['title'])?$rss->channel['title']:$rss->channel['link'];
580 $feed_link = isset($rss->channel['link'])?$rss->channel['link']:'';
581 $feed_type = ($rss->feed_type ? $rss->feed_type : 'Unknown');
582 $feed_version = $rss->feed_version;
583 else :
584 // Give us some sucky defaults
585 $feed_title = feedwordpress_display_url($lookup);
586 $feed_link = $lookup;
587 $feed_type = 'Unknown';
588 $feed_version = '';
589 endif;
590 ?>
591 <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/syndication.php" method="post">
592 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_switchfeed'); ?></div>
593 <fieldset>
594 <legend><?php echo $feed_type; ?> <?php echo $feed_version; ?> feed</legend>
595
596 <?php
597 $this->stamp_link_id();
598
599 // No feed specified = add new feed; we
600 // need to pass along a starting title
601 // and homepage URL for the new Link.
602 if (!$this->for_feed_settings()):
603 ?>
604 <input type="hidden" name="feed_title" value="<?php echo esc_html($feed_title); ?>" />
605 <input type="hidden" name="feed_link" value="<?php echo esc_html($feed_link); ?>" />
606 <?php
607 endif;
608 ?>
609
610 <input type="hidden" name="feed" value="<?php echo esc_html($f); ?>" />
611 <input type="hidden" name="action" value="switchfeed" />
612
613 <div>
614 <div class="feed-sample">
615 <?php
616 $link = NULL;
617 $post = NULL;
618 if (!is_wp_error($rss) and count($rss->items) > 0):
619 // Prepare to display Sample Item
620 $link = new MagpieMockLink(array('simplepie' => $pie, 'magpie' => $rss), $f);
621 $post = new SyndicatedPost(array('simplepie' => $rss->originals[0], 'magpie' => $rss->items[0]), $link);
622 ?>
623 <h3>Sample Item</h3>
624 <ul>
625 <li><strong>Title:</strong> <a href="<?php echo $post->post['meta']['syndication_permalink']; ?>"><?php echo $post->post['post_title']; ?></a></li>
626 <li><strong>Date:</strong> <?php print date('d-M-y g:i:s a', $post->published()); ?></li>
627 </ul>
628 <div class="entry">
629 <?php print $post->post['post_content']; ?>
630 </div>
631 <?php
632 do_action('feedwordpress_feed_finder_sample_item', $f, $post, $link);
633 else:
634 if (is_wp_error($rss)) :
635 print '<div class="feed-problem">';
636 print "<h3>Problem:</h3>\n";
637 print "<p>FeedWordPress encountered the following error
638 when trying to retrieve this feed:</p>";
639 print '<p style="margin: 1.0em 3.0em"><code>'.$rss->get_error_message().'</code></p>';
640 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>";
641 print "</div>";
642 endif;
643 ?>
644 <h3>No Items</h3>
645 <p>FeedWordPress found no posts on this feed.</p>
646 <?php
647 endif;
648 ?>
649 </div>
650
651 <div>
652 <h3>Feed Information</h3>
653 <ul>
654 <li><strong>Homepage:</strong> <a href="<?php echo $feed_link; ?>"><?php echo is_null($feed_title)?'<em>Unknown</em>':$feed_title; ?></a></li>
655 <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>
656 <li><strong>Encoding:</strong> <?php echo isset($rss->encoding)?esc_html($rss->encoding):"<em>Unknown</em>"; ?></li>
657 <li><strong>Description:</strong> <?php echo isset($rss->channel['description'])?esc_html($rss->channel['description']):"<em>Unknown</em>"; ?></li>
658 </ul>
659 <?php do_action('feedwordpress_feedfinder_form', $f, $post, $link, $this->for_feed_settings()); ?>
660 <div class="submit"><input type="submit" name="Use" value="&laquo; Use this feed" /></div>
661 <div class="submit"><input type="submit" name="Cancel" value="&laquo; Cancel" /></div>
662 </div>
663 </div>
664 </fieldset>
665 </form>
666 <?php
667 unset($link);
668 unset($post);
669 endforeach;
670 else:
671 print "<p><strong>".__('Error').":</strong> ".__("FeedWordPress couldn't find any feeds at").' <code><a href="'.htmlspecialchars($lookup).'">'.htmlspecialchars($lookup).'</a></code>';
672 print ". ".__('Try another URL').".</p>";
673
674 // Diagnostics
675 print "<div class=\"updated\" style=\"margin-left: 3.0em; margin-right: 3.0em;\">\n";
676 print "<h3>".__('Diagnostic information')."</h3>\n";
677 if (!is_null($f->error()) and strlen($f->error()) > 0) :
678 print "<h4>".__('HTTP request failure')."</h4>\n";
679 print "<p>".$f->error()."</p>\n";
680 else :
681 print "<h4>".__('HTTP request completed')."</h4>\n";
682 print "<p><strong>Status ".$f->status().":</strong> ".$this->HTTPStatusMessages[(int) $f->status()]."</p>\n";
683 endif;
684
685 // Do some more diagnostics if the API for it is available.
686 if (function_exists('_wp_http_get_object')) :
687 $httpObject = _wp_http_get_object();
688 $transports = $httpObject->_getTransport();
689
690 print "<h4>".__('HTTP Transports available').":</h4>\n";
691 print "<ol>\n";
692 print "<li>".implode("</li>\n<li>", array_map('get_class', $transports))."</li>\n";
693 print "</ol>\n";
694 print "</div>\n";
695 endif;
696
697 endif;
698 ?>
699 </div>
700
701 <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
702 <div><?php
703 FeedWordPressCompatibility::stamp_nonce(get_class($this));
704 ?></div>
705 <div class="wrap">
706 <h2>Use another feed</h2>
707 <div><label>Feed:</label>
708 <input type="text" name="lookup" id="use-another-feed" value="URI" />
709 <?php FeedWordPressSettingsUI::magic_input_tip_js('use-another-feed'); ?>
710 <?php $this->stamp_link_id('link_id'); ?>
711 <input type="hidden" name="action" value="feedfinder" /></div>
712 <div class="submit"><input type="submit" value="Use this feed &raquo;" /></div>
713 </div>
714 </form>
715 <?php
716 return false; // Don't continue
717 } /* WordPressFeedsPage::display_feedfinder() */
718
719 function accept_POST ($post) {
720 global $wpdb;
721
722 // User mashed a Save Changes button
723 if (isset($post['save']) or isset($post['submit'])) :
724
725 if ($this->for_feed_settings()) :
726 $alter = array ();
727
728 // custom feed settings first
729 foreach ($post['notes'] as $mn) :
730 $mn['key0'] = trim($mn['key0']);
731 $mn['key1'] = trim($mn['key1']);
732 if (preg_match("\007^(("
733 .implode(')|(',$this->special_settings)
734 ."))$\007i",
735 $mn['key1'])) :
736 $mn['key1'] = 'user/'.$mn['key1'];
737 endif;
738
739 if (strlen($mn['key0']) > 0) :
740 unset($this->link->settings[$mn['key0']]); // out with the old
741 endif;
742
743 if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) :
744 $this->link->settings[$mn['key1']] = $mn['value']; // in with the new
745 endif;
746 endforeach;
747
748 // now stuff through the web form
749 // hardcoded feed info
750
751 foreach (array('name', 'description', 'url') as $what) :
752 // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
753 $this->link->settings["hardcode {$what}"] = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
754 if (FeedWordPress::affirmative($this->link->settings, "hardcode {$what}")) :
755 $this->link->link->{'link_'.$what} = $post['link'.$what];
756 endif;
757 endforeach;
758
759 // Update scheduling
760 if (isset($post['update_schedule'])) :
761 $this->link->settings['update/hold'] = $post['update_schedule'];
762 endif;
763
764 if (isset($post['use_default_update_window']) and strtolower($post['use_default_update_window'])=='yes') :
765 unset($this->link->settings['update/window']);
766 elseif (isset($post['update_window'])):
767 if ((int) $post['update_window'] > 0) :
768 $this->link->settings['update/window'] = (int) $post['update_window'];
769 endif;
770 endif;
771
772 else :
773 // Global
774 update_option('feedwordpress_cat_id', $post['syndication_category']);
775
776 if (!isset($post['automatic_updates']) or !in_array($post['automatic_updates'], array('init', 'shutdown'))) :
777 $automatic_updates = false;
778 else :
779 $automatic_updates = $post['automatic_updates'];
780 endif;
781 update_option('feedwordpress_automatic_updates', $automatic_updates);
782
783 if (isset($post['update_window'])):
784 if ((int) $post['update_window'] > 0) :
785 update_option('feedwordpress_update_window', (int) $post['update_window']);
786 endif;
787 endif;
788
789 update_option('feedwordpress_update_time_limit', ($post['update_time_limit']=='yes')?(int) $post['time_limit_seconds']:0);
790
791 foreach (array('name', 'description', 'url') as $what) :
792 // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
793 $hardcode = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
794 update_option("feedwordpress_hardcode_{$what}", $hardcode);
795 endforeach;
796
797 $this->updated = true;
798 endif;
799 $this->updatedPosts->accept_POST($post);
800
801 if ($this->for_feed_settings()) :
802 // Save changes to channel-level meta-data
803 //$alter_set = implode(", ", $alter);
804
805 // issue update query
806 //$result = $wpdb->query("
807 //UPDATE $wpdb->links
808 //SET $alter_set
809 //WHERE link_id='{$this->link->id}'
810 //");
811
812 // Save settings
813 $this->link->save_settings(/*reload=*/ true);
814
815 $this->updated = true;
816
817 // Reset, reload
818 $link_id = $this->link->id; unset($this->link);
819 $this->link = new SyndicatedLink($link_id);
820 endif;
821
822 // Probably a "Go" button for the drop-down
823 else :
824 $this->updated = false;
825 endif;
826 } /* WordPressFeedsPage::accept_POST() */
827
828 } /* class FeedWordPressFeedsPage */
829
830 $feedsPage = new FeedWordPressFeedsPage;
831 $feedsPage->display();
832
833