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

820 lines 32.8 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 'update/.*',
86 'feed/.*',
87 'link/.*',
88 );
89
90 function display () {
91 global $wpdb;
92 global $fwp_post;
93 global $post_source;
94
95 if (FeedWordPress::needs_upgrade()) :
96 fwp_upgrade_page();
97 return;
98 endif;
99
100 // Allow overriding of normal source for FeedFinder, which may
101 // be called from multiple points.
102 if (isset($post_source) and !is_null($post_source)) :
103 $source = $post_source;
104 else :
105 $source = get_class($this);
106 endif;
107
108 // If this is a POST, validate source and user credentials
109 FeedWordPressCompatibility::validate_http_request(/*action=*/ $source, /*capability=*/ 'manage_links');
110
111 if (isset($_REQUEST['feedfinder'])
112 or (isset($_REQUEST['action']) and $_REQUEST['action']=='feedfinder')
113 or (isset($_REQUEST['action']) and $_REQUEST['action']==FWP_SYNDICATE_NEW)) :
114 return $this->display_feedfinder(); // re-route to Feed Finder page
115 else :
116 if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
117 $this->accept_POST($fwp_post);
118 do_action('feedwordpress_admin_page_feeds_save', $GLOBALS['fwp_post'], $this);
119 endif;
120
121 ////////////////////////////////////////////////
122 // Prepare settings page ///////////////////////
123 ////////////////////////////////////////////////
124
125 $this->ajax_interface_js();
126 $this->display_update_notice_if_updated('Syndicated feed');
127 $this->open_sheet('Feed and Update');
128 ?>
129 <div id="post-body">
130 <?php
131 ////////////////////////////////////////////////
132 // Display settings boxes //////////////////////
133 ////////////////////////////////////////////////
134
135 $boxes_by_methods = array(
136 'feed_information_box' => __('Feed Information'),
137 'global_feeds_box' => __('Update Scheduling'),
138 'updated_posts_box' => __('Updated Posts'),
139 'posts_box' => __('Syndicated Posts, Links, Comments & Pings'),
140 'authors_box' => __('Syndicated Authors'),
141 'categories_box' => __('Categories'.FEEDWORDPRESS_AND_TAGS),
142 'custom_settings_box' => __('Custom Feed Settings (for use in templates)'),
143 );
144 if ($this->for_default_settings()) :
145 unset($boxes_by_methods['custom_settings_box']);
146 endif;
147
148 foreach ($boxes_by_methods as $method => $row) :
149 if (is_array($row)) :
150 $id = $row['id'];
151 $title = $row['title'];
152 else :
153 $id = 'feedwordpress_'.$method;
154 $title = $row;
155 endif;
156
157 fwp_add_meta_box(
158 /*id=*/ $id,
159 /*title=*/ $title,
160 /*callback=*/ array(get_class($this), $method),
161 /*page=*/ $this->meta_box_context(),
162 /*context=*/ $this->meta_box_context()
163 );
164 endforeach;
165 do_action('feedwordpress_admin_page_feeds_meta_boxes', $this);
166 ?>
167 <div class="metabox-holder">
168 <?php
169 fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
170 ?>
171 </div> <!-- class="metabox-holder" -->
172 </div> <!-- id="post-body" -->
173 <?php $this->close_sheet(); ?>
174
175 <script type="text/javascript">
176 var els = ['name', 'description', 'url'];
177 for (var i = 0; i < els.length; i++) {
178 contextual_appearance(
179 /*item=*/ 'basics-hardcode-'+els[i],
180 /*appear=*/ 'basics-'+els[i]+'-view',
181 /*disappear=*/ 'basics-'+els[i]+'-edit',
182 /*value=*/ 'no',
183 /*visibleStyle=*/ 'block',
184 /*checkbox=*/ true
185 );
186 } /* for */
187 </script>
188 <?php
189 endif;
190 return false; // Don't continue
191 } /* FeedWordPressFeedsPage::display() */
192
193 /*static*/ function updated_posts_box ($page, $box = NULL) {
194 ?>
195 <table class="edit-form">
196 <?php $page->updatedPosts->display(); ?>
197 </table>
198 <?php
199 } /* FeedWordPressFeedsPage::updated_posts_box() */
200
201 /*static*/ function global_feeds_box ($page, $box = NULL) {
202 global $wpdb;
203
204 $defaultUpdateWindow = get_option('feedwordpress_update_window');
205 if (!is_numeric($defaultUpdateWindow)) :
206 $defaultUpdateWindow = DEFAULT_UPDATE_PERIOD;
207 else :
208 $defaultUpdateWindow = (int) $defaultUpdateWindow;
209 endif;
210 ?>
211
212 <table class="edit-form">
213 <?php
214 if ($page->for_default_settings()) :
215 $automatic_updates = get_option('feedwordpress_automatic_updates');
216 $update_time_limit = (int) get_option('feedwordpress_update_time_limit');
217 ?>
218
219 <tr>
220 <th scope="row">Updates:</th>
221 <td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');">
222 <option value="shutdown"<?php echo ($automatic_updates=='shutdown')?' selected="selected"':''; ?>>automatically check for updates after pages load</option>
223 <option value="init"<?php echo ($automatic_updates=='init')?' selected="selected"':''; ?>>automatically check for updates before pages load</option>
224 <option value="no"<?php echo (!$automatic_updates)?' selected="selected"':''; ?>>cron job or manual updates</option>
225 </select>
226 <div id="cron-job-explanation" class="setting-description">
227 <p>If you want to use a cron job,
228 you can perform scheduled updates by sending regularly-scheduled
229 requests to <a href="<?php bloginfo('home'); ?>?update_feedwordpress=1"><code><?php bloginfo('home') ?>?update_feedwordpress=1</code></a>
230 For example, inserting the following line in your crontab:</p>
231 <pre style="font-size: 0.80em"><code>*/10 * * * * /usr/bin/curl --silent <?php bloginfo('home'); ?>?update_feedwordpress=1</code></pre>
232 <p class="setting-description">will check in every 10 minutes
233 and check for updates on any feeds that are ready to be polled for updates.</p>
234 </div>
235 </td>
236 </tr>
237
238 <tr>
239 <th scope="row"><?php print __('Update scheduling:') ?></th>
240 <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>
241 <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>
242 <div class="setting-description">
243 <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>
244 <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>
245 </div></td>
246 </tr>
247
248 <tr>
249 <th scope="row"><?php print __('Time limit on updates'); ?>:</th>
250 <td><select id="time-limit" name="update_time_limit" size="1" onchange="contextual_appearance('time-limit', 'time-limit-box', null, 'yes');">
251 <option value="no"<?php echo ($update_time_limit>0)?'':' selected="selected"'; ?>>no time limit on updates</option>
252 <option value="yes"<?php echo ($update_time_limit>0)?' selected="selected"':''; ?>>limit updates to no more than...</option>
253 </select>
254 <span id="time-limit-box"><label><input type="text" name="time_limit_seconds" value="<?php print $update_time_limit; ?>" size="5" /> seconds</label></span>
255 </tr>
256
257 <?php else :
258 $useDefaultUpdateWindow = !(isset($page->link->settings['update/window']));
259
260 $updateWindow = (isset($page->link->settings['update/window']) ? $page->link->settings['update/window'] : null);
261 if (!is_numeric($updateWindow)) :
262 $updateWindow = 60;
263 else :
264 $updateWindow = (int) $updateWindow;
265 endif;
266
267 ?>
268
269 <tr>
270 <th scope="row"><?php _e('Last update') ?>:</th>
271 <td><?php
272 if (isset($page->link->settings['update/last'])) :
273 echo fwp_time_elapsed($page->link->settings['update/last'])." ";
274 else :
275 echo " none yet";
276 endif;
277 ?></td></tr>
278
279 <tr><th><?php _e('Next update') ?>:</th>
280 <td><?php
281 $holdem = (isset($page->link->settings['update/hold']) ? $page->link->settings['update/hold'] : 'scheduled');
282 ?>
283 <select name="update_schedule">
284 <option value="scheduled"<?php echo ($holdem=='scheduled')?' selected="selected"':''; ?>>update on schedule <?php
285 echo " (";
286 if (isset($page->link->settings['update/ttl']) and is_numeric($page->link->settings['update/ttl'])) :
287 if (isset($page->link->settings['update/timed']) and $page->link->settings['update/timed']=='automatically') :
288 echo 'next: ';
289 $next = $page->link->settings['update/last'] + ((int) $page->link->settings['update/ttl'] * 60);
290 if (strftime('%x', time()) != strftime('%x', $next)) :
291 echo strftime('%x', $next)." ";
292 endif;
293 echo strftime('%X', $page->link->settings['update/last']+((int) $page->link->settings['update/ttl']*60));
294 else :
295 echo "every ".$page->link->settings['update/ttl']." minute".(($page->link->settings['update/ttl']!=1)?"s":"");
296 endif;
297 else:
298 echo "next scheduled update";
299 endif;
300 echo ")";
301 ?></option>
302 <option value="next"<?php echo ($holdem=='next')?' selected="selected"':''; ?>>update ASAP</option>
303 <option value="ping"<?php echo ($holdem=='ping')?' selected="selected"':''; ?>>update only when pinged</option>
304 </select></td></tr>
305
306 <tr>
307 <th scope="row"><?php print __('Update scheduling:') ?></th>
308 <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>
309 <ul>
310 <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>
311 <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>
312 </ul>
313
314 <div class="setting-description">
315 <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>
316 <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>
317 </div></td>
318 </tr>
319 <?php endif; ?>
320
321
322 </table>
323 <script type="text/javascript">
324 contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');
325 contextual_appearance('time-limit', 'time-limit-box', null, 'yes');
326 </script>
327 <?php
328 } /* FeedWordPressFeedsPage::global_feeds_box() */
329
330 function feed_information_box ($page, $box = NULL) {
331 global $wpdb;
332 if ($page->for_feed_settings()) :
333 $info['name'] = wp_specialchars($page->link->link->link_name, 1);
334 $info['description'] = wp_specialchars($page->link->link->link_description, 'both');
335 $info['url'] = wp_specialchars($page->link->link->link_url, 1);
336 $rss_url = $page->link->link->link_rss;
337
338 $hardcode['name'] = $page->link->hardcode('name');
339 $hardcode['description'] = $page->link->hardcode('description');
340 $hardcode['url'] = $page->link->hardcode('url');
341 else :
342 $cat_id = FeedWordPress::link_category_id();
343 if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_21)) :
344 $results = get_categories(array(
345 "type" => 'link',
346 "hide_empty" => false,
347 ));
348
349 // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
350 $found_link_category_id = false;
351 foreach ($results as $row) :
352 // Normalize case
353 if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
354
355 if ($row->cat_id == $cat_id) : $found_link_category_id = true; endif;
356 endforeach;
357
358 if (!$found_link_category_id) : $results[] = get_category($cat_id); endif;
359 else :
360 $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY 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 wp_specialchars($rss_url, 'both'); ?>"><?php echo wp_specialchars($rss_url, 'both'); ?></a>
387 (<a href="<?php echo FEEDVALIDATOR_URI; ?>?url=<?php echo urlencode($rss_url); ?>"
388 title="Check feed &lt;<?php echo wp_specialchars($rss_url, 'both'); ?>&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: ".wp_specialchars($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 FeedWordPressSettingsUI::instead_of_posts_box($page->link->id);
473 } /* FeedWordPressFeedsPage::posts_box() */
474
475 function authors_box ($page, $box = NULL) {
476 FeedWordPressSettingsUI::instead_of_authors_box($page->link->id);
477 } /* FeedWordPressFeedsPage::authors_box() */
478
479 function categories_box ($page, $box = NULL) {
480 FeedWordPressSettingsUI::instead_of_categories_box($page->link->id);
481 } /* FeedWordPressFeedsPage::categories_box() */
482
483 function custom_settings_box ($page, $box = NULL) {
484 ?>
485 <p class="setting-description">These custom settings are special fields for the <strong>feed</strong> you are
486 syndicating, to be retrieved in templates using the <code>get_feed_meta()</code> function. They do not create
487 custom fields on syndicated <strong>posts</strong>. If you want to create custom fields that are applied to each
488 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>
489
490 <div id="postcustomstuff">
491 <table id="meta-list" cellpadding="3">
492 <tr>
493 <th>Key</th>
494 <th>Value</th>
495 <th>Action</th>
496 </tr>
497
498 <?php
499 $i = 0;
500 foreach ($page->link->settings as $key => $value) :
501 if (!preg_match("\007^((".implode(')|(', $page->special_settings)."))$\007i", $key)) :
502 ?>
503 <tr style="vertical-align:top">
504 <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo wp_specialchars($key, 'both'); ?>" />
505 <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo wp_specialchars($key, 'both'); ?>" /></th>
506 <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?>-value" name="notes[<?php echo $i; ?>][value]"><?php echo wp_specialchars($value, 'both'); ?></textarea></td>
507 <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
508 <option value="update">save changes</option>
509 <option value="delete">delete this setting</option>
510 </select></td>
511 </tr>
512 <?php
513 $i++;
514 endif;
515 endforeach;
516 ?>
517 <tr>
518 <th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?>][key1]" value="" /></th>
519 <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea></td>
520 <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td>
521 </tr>
522 </table>
523 </div> <!-- id="postcustomstuff" -->
524 <?php
525 }
526
527 function display_feedfinder () {
528 global $wpdb;
529
530 $lookup = (isset($_REQUEST['lookup']) ? $_REQUEST['lookup'] : NULL);
531
532 if ($this->for_feed_settings()) : // Existing feed?
533 if (is_null($lookup)) : $lookup = $this->link->link->link_url; endif;
534 $name = wp_specialchars($this->link->link->link_name, 'both');
535 else: // Or a new subscription to add?
536 $name = "Subscribe to <code>".wp_specialchars(feedwordpress_display_url($lookup))."</code>";
537 endif;
538 ?>
539 <style type="text/css">
540 form.fieldset {
541 clear: both;
542 }
543 .feed-sample {
544 float: right;
545 background-color: #D0D0D0;
546 color: black;
547 width: 45%;
548 font-size: 70%;
549 border-left: 1px dotted #A0A0A0;
550 margin-left: 1.0em;
551 }
552 .feed-sample p, .feed-sample h3 {
553 padding-left: 0.5em;
554 padding-right: 0.5em;
555 }
556 .feed-sample .feed-problem {
557 background-color: #ffd0d0;
558 border-bottom: 1px dotted black;
559 padding-bottom: 0.5em;
560 margin-bottom: 0.5em;
561 }
562 </style>
563
564 <div class="wrap">
565 <h2>Feed Finder: <?php echo $name; ?></h2>
566
567 <?php
568 $f =& new FeedFinder($lookup);
569 $feeds = $f->find();
570 if (count($feeds) > 0):
571 foreach ($feeds as $key => $f):
572 $rss = @fetch_rss($f);
573 if ($rss):
574 $feed_title = isset($rss->channel['title'])?$rss->channel['title']:$rss->channel['link'];
575 $feed_link = isset($rss->channel['link'])?$rss->channel['link']:'';
576 $feed_type = ($rss->feed_type ? $rss->feed_type : 'Unknown');
577 else :
578 // Give us some sucky defaults
579 $feed_title = feedwordpress_display_url($lookup);
580 $feed_link = $lookup;
581 $feed_type = 'Unknown';
582 endif;
583 ?>
584 <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/syndication.php" method="post">
585 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_switchfeed'); ?></div>
586 <fieldset>
587 <legend><?php echo $feed_type; ?> <?php echo $rss->feed_version; ?> feed</legend>
588
589 <?php
590 $this->stamp_link_id();
591
592 // No feed specified = add new feed; we
593 // need to pass along a starting title
594 // and homepage URL for the new Link.
595 if (!$this->for_feed_settings()):
596 ?>
597 <input type="hidden" name="feed_title" value="<?php echo wp_specialchars($feed_title, 'both'); ?>" />
598 <input type="hidden" name="feed_link" value="<?php echo wp_specialchars($feed_link, 'both'); ?>" />
599 <?php
600 endif;
601 ?>
602
603 <input type="hidden" name="feed" value="<?php echo wp_specialchars($f, 'both'); ?>" />
604 <input type="hidden" name="action" value="switchfeed" />
605
606 <div>
607 <div class="feed-sample">
608
609 <?php
610 if (count($rss->items) > 0):
611 // Prepare to display Sample Item
612 $link =& new MagpieMockLink($rss, $f);
613 $post =& new SyndicatedPost($rss->items[0], $link);
614 ?>
615 <h3>Sample Item</h3>
616 <ul>
617 <li><strong>Title:</strong> <a href="<?php echo $post->post['meta']['syndication_permalink']; ?>"><?php echo $post->post['post_title']; ?></a></li>
618 <li><strong>Date:</strong> <?php print date('d-M-y g:i:s a', $post->published()); ?></li>
619 </ul>
620 <div class="entry">
621 <?php print $post->post['post_content']; ?>
622 </div>
623 <?php
624 else:
625 if (magpie_error()) :
626 print '<div class="feed-problem">';
627 print "<h3>Problem:</h3>\n";
628 print "<p>FeedWordPress encountered the following error
629 when trying to retrieve this feed:</p>";
630 print '<p style="margin: 1.0em 3.0em"><code>'.magpie_error().'</code></p>';
631 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>";
632 print "</div>";
633 endif;
634 ?>
635 <h3>No Items</h3>
636 <p>FeedWordPress found no posts on this feed.</p>
637 <?php
638 endif;
639 ?>
640 </div>
641
642 <div>
643 <h3>Feed Information</h3>
644 <ul>
645 <li><strong>Homepage:</strong> <a href="<?php echo $feed_link; ?>"><?php echo is_null($feed_title)?'<em>Unknown</em>':$feed_title; ?></a></li>
646 <li><strong>Feed URL:</strong> <a href="<?php echo wp_specialchars($f, 'both'); ?>"><?php echo wp_specialchars($f, 'both'); ?></a> (<a title="Check feed &lt;<?php echo wp_specialchars($f, 'both'); ?>&gt; for validity" href="http://feedvalidator.org/check.cgi?url=<?php echo urlencode($f); ?>">validate</a>)</li>
647 <li><strong>Encoding:</strong> <?php echo isset($rss->encoding)?wp_specialchars($rss->encoding, 'both'):"<em>Unknown</em>"; ?></li>
648 <li><strong>Description:</strong> <?php echo isset($rss->channel['description'])?wp_specialchars($rss->channel['description'], 'both'):"<em>Unknown</em>"; ?></li>
649 </ul>
650 <div class="submit"><input type="submit" name="Use" value="&laquo; Use this feed" /></div>
651 <div class="submit"><input type="submit" name="Cancel" value="&laquo; Cancel" /></div>
652 </div>
653 </div>
654 </fieldset>
655 </form>
656 <?php
657 endforeach;
658 else:
659 print "<p><strong>".__('Error').":</strong> ".__("FeedWordPress couldn't find any feeds at").' <code><a href="'.htmlspecialchars($lookup).'">'.htmlspecialchars($lookup).'</a></code>';
660 print ". ".__('Try another URL').".</p>";
661
662 // Diagnostics
663 print "<div class=\"updated\" style=\"margin-left: 3.0em; margin-right: 3.0em;\">\n";
664 print "<h3>".__('Diagnostic information')."</h3>\n";
665 if (!is_null($f->error()) and strlen($f->error()) > 0) :
666 print "<h4>".__('HTTP request failure')."</h4>\n";
667 print "<p>".$f->error()."</p>\n";
668 else :
669 print "<h4>".__('HTTP request completed')."</h4>\n";
670 print "<p><strong>Status ".$f->status().":</strong> ".$this->HTTPStatusMessages[(int) $f->status()]."</p>\n";
671 endif;
672
673 // Do some more diagnostics if the API for it is available.
674 if (function_exists('_wp_http_get_object')) :
675 $httpObject = _wp_http_get_object();
676 $transports = $httpObject->_getTransport();
677
678 print "<h4>".__('HTTP Transports available').":</h4>\n";
679 print "<ol>\n";
680 print "<li>".implode("</li>\n<li>", array_map('get_class', $transports))."</li>\n";
681 print "</ol>\n";
682 print "</div>\n";
683 endif;
684
685 endif;
686 ?>
687 </div>
688
689 <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
690 <div><?php
691 FeedWordPressCompatibility::stamp_nonce(get_class($this));
692 ?></div>
693 <div class="wrap">
694 <h2>Use another feed</h2>
695 <div><label>Feed:</label>
696 <input type="text" name="lookup" id="use-another-feed" value="URI" />
697 <?php FeedWordPressSettingsUI::magic_input_tip_js('use-another-feed'); ?>
698 <?php $this->stamp_link_id('link_id'); ?>
699 <input type="hidden" name="action" value="feedfinder" /></div>
700 <div class="submit"><input type="submit" value="Use this feed &raquo;" /></div>
701 </div>
702 </form>
703 <?php
704 return false; // Don't continue
705 } /* WordPressFeedsPage::display_feedfinder() */
706
707 function accept_POST ($post) {
708 global $wpdb;
709
710 // User mashed a Save Changes button
711 if (isset($post['save']) or isset($post['submit'])) :
712
713 if ($this->for_feed_settings()) :
714 $alter = array ();
715
716 // custom feed settings first
717 foreach ($post['notes'] as $mn) :
718 $mn['key0'] = trim($mn['key0']);
719 $mn['key1'] = trim($mn['key1']);
720 if (preg_match("\007^(("
721 .implode(')|(',$this->special_settings)
722 ."))$\007i",
723 $mn['key1'])) :
724 $mn['key1'] = 'user/'.$mn['key1'];
725 endif;
726
727 if (strlen($mn['key0']) > 0) :
728 unset($this->link->settings[$mn['key0']]); // out with the old
729 endif;
730
731 if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) :
732 $this->link->settings[$mn['key1']] = $mn['value']; // in with the new
733 endif;
734 endforeach;
735
736 // now stuff through the web form
737 // hardcoded feed info
738
739 foreach (array('name', 'description', 'url') as $what) :
740 // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
741 $this->link->settings["hardcode {$what}"] = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
742 if (FeedWordPress::affirmative($this->link->settings, "hardcode {$what}")) :
743 $alter[] = "link_{$what} = '".$wpdb->escape($post['link'.$what])."'";
744 endif;
745 endforeach;
746
747 // Update scheduling
748 if (isset($post['update_schedule'])) :
749 $this->link->settings['update/hold'] = $post['update_schedule'];
750 endif;
751
752 if (isset($post['use_default_update_window']) and strtolower($post['use_default_update_window'])=='yes') :
753 unset($this->link->settings['update/window']);
754 elseif (isset($post['update_window'])):
755 if ((int) $post['update_window'] > 0) :
756 $this->link->settings['update/window'] = (int) $post['update_window'];
757 endif;
758 endif;
759
760 else :
761 // Global
762 update_option('feedwordpress_cat_id', $post['syndication_category']);
763
764 if (!isset($post['automatic_updates']) or !in_array($post['automatic_updates'], array('init', 'shutdown'))) :
765 $automatic_updates = false;
766 else :
767 $automatic_updates = $post['automatic_updates'];
768 endif;
769 update_option('feedwordpress_automatic_updates', $automatic_updates);
770
771 if (isset($post['update_window'])):
772 if ((int) $post['update_window'] > 0) :
773 update_option('feedwordpress_update_window', (int) $post['update_window']);
774 endif;
775 endif;
776
777 update_option('feedwordpress_update_time_limit', ($post['update_time_limit']=='yes')?(int) $post['time_limit_seconds']:0);
778
779 foreach (array('name', 'description', 'url') as $what) :
780 // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
781 $hardcode = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
782 update_option("feedwordpress_hardcode_{$what}", $hardcode);
783 endforeach;
784
785 $this->updated = true;
786 endif;
787 $this->updatedPosts->accept_POST($post);
788
789 if ($this->for_feed_settings()) :
790 $alter[] = "link_notes = '".$wpdb->escape($this->link->settings_to_notes())."'";
791
792 $alter_set = implode(", ", $alter);
793
794 // issue update query
795 $result = $wpdb->query("
796 UPDATE $wpdb->links
797 SET $alter_set
798 WHERE link_id='{$this->link->id}'
799 ");
800 $this->updated = true;
801
802 // reload link information from DB
803 if (function_exists('clean_bookmark_cache')) :
804 clean_bookmark_cache($this->link->id);
805 endif;
806 $this->link = new SyndicatedLink($this->link->id);
807 endif;
808
809 // Probably a "Go" button for the drop-down
810 else :
811 $this->updated = false;
812 endif;
813 } /* WordPressFeedsPage::accept_POST() */
814
815 } /* class FeedWordPressFeedsPage */
816
817 $feedsPage = new FeedWordPressFeedsPage;
818 $feedsPage->display();
819
820