PluginProbe
FeedWordPress / 2009.1111
FeedWordPress v2009.1111
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 2009.1111, at feeds-page.php

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