PluginProbe
FeedWordPress / 2022.0204
FeedWordPress v2022.0204
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 2022.0204, at feeds-page.php

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