PluginProbe
FeedWordPress / 2021.0713
FeedWordPress v2021.0713
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 2021.0713, at feeds-page.php

1,314 lines 47.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 echo ($automatic_updates=='shutdown')?' selected="selected"':''; ?>>automatically check for updates after pages load</option>
203 <option value="init"<?php echo ($automatic_updates=='init')?' selected="selected"':''; ?>>automatically check for updates before pages load</option>
204 <option value="no"<?php echo (!$automatic_updates)?' selected="selected"':''; ?>>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 echo ($update_time_limit>0)?'':' selected="selected"'; ?>>no time limit on updates</option>
351 <option value="yes"<?php echo ($update_time_limit>0)?' selected="selected"':''; ?>>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 $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 $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 $timeout; ?>" />
397 second(s) when trying to fetch <?php print $article; ?> feed to check for updates.</p>
398 <p>If <?php print $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 if (count($authMethods) > 1) : /* More than '-' */
483 ?>
484 <div class="link-rss-authentication" id="link-rss-authentication<?php print $slug; ?>">
485 <table>
486 <tbody>
487 <tr class="link-rss-authentication-credentials" id="link-rss-authentication-credentials<?php print $slug; ?>">
488 <td><label>user: <input type="text" name="link_rss_username"
489 value="<?php print esc_attr($params['username']); ?>" size="16"
490 placeholder="username to access this feed" /></label></td>
491 <td><label>pass: <input type="text" name="link_rss_password"
492 value="<?php print esc_attr($params['password']); ?>" size="16"
493 placeholder="password to access this feed" /></label></td>
494 <td class="link-rss-authentication-method" id="link-rss-authentication-method<?php print $slug; ?>"><label>method: <select class="link-rss-auth-method" id="link-rss-auth-method" name="link_rss_auth_method" size="1">
495 <?php foreach ($authMethods as $value => $label) : ?>
496 <option value="<?php print esc_attr($value); ?>"<?php
497 if ($value == $params['method']) : ?> selected="selected"<?php
498 endif; ?>><?php print esc_html($label); ?></option>
499 <?php endforeach; ?>
500 </select></label></td>
501 </tr>
502 </tbody>
503 </table>
504 </div>
505
506 <script type="text/javascript">
507 jQuery('<td><a class="add-remove remove-it" id="link-rss-userpass-remove<?php print $slug; ?>" href="#"><span class="x">(X)</span> Remove</a></td>')
508 .appendTo('#link-rss-authentication-credentials<?php print $slug; ?>')
509 .click( feedAuthenticationMethodUnPress );
510 jQuery('#link-rss-auth-method<?php print $slug; ?>').change( feedAuthenticationMethod );
511 feedAuthenticationMethod({
512 init: true,
513 node: jQuery('#link-rss-authentication<?php print $slug; ?>') });
514 </script>
515
516 <?php
517 endif;
518 }
519
520 function feed_information_box ($page, $box = NULL) {
521 global $wpdb;
522 $link_rss_params = maybe_unserialize($page->setting('query parameters', ''));
523 if (!is_array($link_rss_params)) :
524 $link_rss_params = array();
525 endif;
526
527 if ($page->for_feed_settings()) :
528 $info['name'] = esc_html($page->link->link->link_name);
529 $info['description'] = esc_html($page->link->link->link_description);
530 $info['url'] = esc_html($page->link->link->link_url);
531 $rss_url = $page->link->link->link_rss;
532
533 $hardcode['name'] = $page->link->hardcode('name');
534 $hardcode['description'] = $page->link->hardcode('description');
535 $hardcode['url'] = $page->link->hardcode('url');
536 else :
537 $cat_id = FeedWordPress::link_category_id();
538
539 $params = array();
540 $params['taxonomy'] = 'link_category';
541 $params['hide_empty'] = false;
542 $results = get_categories($params);
543
544 // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
545 $found_link_category_id = false;
546 foreach ($results as $row) :
547 // Normalize case
548 if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
549
550 if ($row->cat_id == $cat_id) : $found_link_category_id = true; endif;
551 endforeach;
552
553 if (!$found_link_category_id) :
554 $results[] = get_category($cat_id);
555 endif;
556
557 $info = array();
558 $rss_url = null;
559
560 $hardcode['name'] = get_option('feedwordpress_hardcode_name');
561 $hardcode['description'] = get_option('feedwordpress_hardcode_description');
562 $hardcode['url'] = get_option('feedwordpress_hardcode_url');
563 endif;
564
565 $hideAuth = false;
566
567 $username = $this->setting('http username', NULL);
568
569 if (is_null($username)) :
570 $username = '';
571 $hideAuth = true;
572 endif;
573
574 $password = $this->setting('http password', NULL);
575 if (is_null($password)) :
576 $password = '';
577 endif;
578
579 $auth = $this->setting('http auth method', NULL);
580
581 global $feedwordpress;
582
583 if (is_null($auth) or (strlen($auth)==0)) :
584 $auth = '-';
585 $hideAuth = true;
586 endif;
587
588 // Hey ho, let's go
589
590 ?>
591 <table class="edit-form">
592
593 <?php if ($page->for_feed_settings()) : ?>
594
595 <tr>
596 <th scope="row"><?php _e('Feed URL:') ?></th>
597 <td><a href="<?php echo esc_html($rss_url); ?>"><?php echo esc_html($rss_url); ?></a>
598 (<a href="<?php echo FEEDVALIDATOR_URI; ?>?url=<?php echo urlencode($rss_url); ?>"
599 title="Check feed &lt;<?php echo esc_html($rss_url); ?>&gt; for validity">validate</a>)
600 <input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" />
601
602 <?php $this->display_authentication_credentials_box(array(
603 'username' => $username,
604 'password' => $password,
605 'method' => $auth,
606 )); ?>
607
608 <table id="link-rss-params">
609 <tbody>
610 <?php
611 $link_rss_params['new'] = array('', '');
612 $i = 0;
613 foreach ($link_rss_params as $index => $pair) :
614 ?>
615 <tr class="link-rss-params-row" id="link-rss-params-<?php print $index; ?>">
616 <td><label>Parameter: <input type="text" class="link_params_key"
617 name="link_rss_params_key[<?php print $index; ?>]" value="<?php print esc_html($pair[0]); ?>"
618 size="5" style="width: 5em" placeholder="name" /></label></td>
619 <td class="link-rss-params-value-cell"><label class="link_params_value_label">= <input type="text" class="link_params_value"
620 name="link_rss_params_value[<?php print $index; ?>]" value="<?php print esc_html($pair[1]); ?>"
621 size="8" placeholder="value" /></label></td>
622 </tr>
623 <?php
624 $i++;
625 endforeach;
626 ?>
627 </tbody>
628 </table>
629
630 <div><input type="hidden" id="link-rss-params-num" name="link_rss_params_num" value="<?php print $i; ?>" /></div>
631
632 <script type="text/javascript">
633 function linkParamsRowRemove (element) {
634 jQuery(element).closest('tr').fadeOut('slow', function () {
635 jQuery(this).remove();
636 } );
637 }
638
639 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');
640
641 jQuery('#link-rss-params-new').hide();
642 jQuery('<a class="add-remove" id="link-rss-params-add" href="#">+ Add a query parameter</a>').insertAfter('#link-rss-params');
643 jQuery('#link-rss-params-add').click( function () {
644 var next = jQuery('#link-rss-params-num').val();
645 var newRow = jQuery('#link-rss-params-new').clone().attr('id', 'link-rss-params-'+next);
646 newRow.find('.link_params_key').attr('name', 'link_rss_params_key['+next+']');
647 newRow.find('.link_params_value').attr('name', 'link_rss_params_value['+next+']');
648
649 newRow.find('.link-rss-params-remove').click( function () {
650 linkParamsRowRemove(this);
651 return false;
652 } );
653
654 newRow.appendTo('#link-rss-params');
655 newRow.show();
656
657 // Update counter for next row.
658 next++;
659 jQuery('#link-rss-params-num').val(next);
660
661 return false;
662 } );
663 jQuery('.link-rss-params-remove').click( function () {
664 linkParamsRowRemove(this);
665 return false;
666 } );
667 </script>
668 </td>
669 </tr>
670
671 <?php
672 $rows = array(
673 "name" => __('Link Name'),
674 "description" => __('Short Description'),
675 "url" => __('Homepage'),
676 );
677 foreach ($rows as $what => $label) :
678 ?>
679 <tr>
680 <th scope="row"><?php print $label ?></th>
681 <td>
682 <div id="basics-<?php print $what; ?>-edit"><input type="text" name="link<?php print $what; ?>"
683 value="<?php echo $info[$what]; ?>" style="width: 95%" /></div>
684 <div id="basics-<?php print $what; ?>-view">
685 <?php if ($what=='url') : ?><a href="<?php print $info[$what]; ?>"><?php else : ?><strong><?php endif; ?>
686 <?php print (strlen(trim($info[$what])) > 0) ? $info[$what] : '(none provided)'; ?>
687 <?php if ($what=='url') : ?></a><?php else : ?></strong><?php endif; ?></div>
688
689 <div>
690 <label><input id="basics-hardcode-<?php print $what; ?>"
691 type="radio" name="hardcode_<?php print $what; ?>" value="no"
692 <?php echo (($hardcode[$what]=='yes')?'':' checked="checked"');?>
693 onchange="contextual_appearance('basics-hardcode-<?php print $what; ?>', 'basics-<?php print $what; ?>-view', 'basics-<?php print $what; ?>-edit', 'no', 'block', /*checkbox=*/ true)"
694 /> Update automatically from feed</label>
695 <label><input type="radio" name="hardcode_<?php print $what; ?>" value="yes"
696 <?php echo (($hardcode[$what]!='yes')?'':' checked="checked"');?>
697 onchange="contextual_appearance('basics-hardcode-<?php print $what; ?>', 'basics-<?php print $what; ?>-view', 'basics-<?php print $what; ?>-edit', 'no', 'block', /*checkbox=*/ true)"
698 /> Edit manually</label>
699 </div>
700 </td>
701 </tr>
702 <?php
703 endforeach;
704 ?>
705
706 <?php else : ?>
707
708 <tr>
709 <th scope="row">Syndicated Link category:</th>
710 <td><p><select name="syndication_category" size="1">
711 <?php
712 foreach ($results as $row) :
713 // Normalize case
714 if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
715
716 echo "\n\t<option value=\"$row->cat_id\"";
717 if ($row->cat_id == $cat_id) :
718 echo " selected='selected'";
719 endif;
720 echo ">$row->cat_id: ".esc_html($row->cat_name);
721 echo "</option>\n";
722 endforeach;
723 ?></select></p>
724 <p class="setting-description">FeedWordPress will syndicate the
725 links placed under this link category.</p>
726 </td>
727 </tr>
728
729 <tr>
730 <th scope="row">Link Names:</th>
731 <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>
732 </tr>
733
734 <tr>
735 <th scope="row">Short descriptions:</th>
736 <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>
737 </tr>
738
739 <tr>
740 <th scope="row">Homepages:</th>
741 <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>
742 </tr>
743
744 <?php endif; ?>
745
746 </table>
747 <?php
748 } /* FeedWordPressFeedsPage::feed_information_box() */
749
750 function custom_settings_box ($page, $box = NULL) {
751 $postsSettings = $this->admin_page_href('posts-page.php', array(), $page->link);
752 ?>
753 <p class="setting-description">These custom settings are special fields for the <strong>feed</strong> you are
754 syndicating, to be retrieved in templates using the <code>get_feed_meta()</code> function. They do not create
755 custom fields on syndicated <strong>posts</strong>. If you want to create custom fields that are applied to each
756 individual post from this feed, set up the settings in <a href="<?php print $postsSettings; ?>">Syndicated Posts</a>.</p>
757
758 <div id="postcustomstuff">
759 <table id="meta-list" cellpadding="3">
760 <tr>
761 <th>Key</th>
762 <th>Value</th>
763 <th>Action</th>
764 </tr>
765
766 <?php
767 $i = 0;
768 foreach ($page->link->settings as $key => $value) :
769 if (!preg_match("\007^((".implode(')|(', $page->special_settings)."))$\007i", $key)) :
770 ?>
771 <tr style="vertical-align:top">
772 <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo esc_html($key); ?>" />
773 <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo esc_html($key); ?>" /></th>
774 <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?>-value" name="notes[<?php echo $i; ?>][value]"><?php echo esc_html($value); ?></textarea></td>
775 <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
776 <option value="update">save changes</option>
777 <option value="delete">delete this setting</option>
778 </select></td>
779 </tr>
780 <?php
781 $i++;
782 endif;
783 endforeach;
784 ?>
785 <tr>
786 <th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?>][key1]" value="" /></th>
787 <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea></td>
788 <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td>
789 </tr>
790 </table>
791 </div> <!-- id="postcustomstuff" -->
792 <?php
793 }
794
795 function url_for_401 ($err) {
796 $ret = NULL;
797 if (is_wp_error($err)) :
798 if ($err->get_error_code()=='http_request_failed') :
799 $data = $err->get_error_data('http_request_failed');
800
801 if (is_array($data) and isset($data['status'])) :
802 if (401==$data['status']) :
803 $ret = $data['uri'];
804 endif;
805 endif;
806 endif;
807 endif;
808 return $ret;
809 }
810
811 function display_feedfinder () {
812 global $wpdb;
813
814 $lookup = (isset($_REQUEST['lookup']) ? $_REQUEST['lookup'] : NULL);
815
816 $auth = MyPHP::request('link_rss_auth_method');
817 $username = MyPHP::request('link_rss_username');
818 $password = MyPHP::request('link_rss_password');
819 $credentials = array(
820 "authentication" => $auth,
821 "username" => $username,
822 "password" => $password,
823 );
824
825 $feeds = array(); $feedSwitch = false; $current = null;
826 if ($this->for_feed_settings()) : // Existing feed?
827 $feedSwitch = true;
828 if (is_null($lookup)) :
829 // Switch Feed without a specific feed yet suggested
830 // Go to the human-readable homepage to look for
831 // auto-detection links
832
833 $lookup = $this->link->link->link_url;
834 $auth = $this->link->setting('http auth method');
835 $username = $this->link->setting('http username');
836 $password = $this->link->setting('http password');
837
838 // Guarantee that you at least have the option to
839 // stick with what works.
840 $current = $this->link->link->link_rss;
841 $feeds[] = $current;
842 endif;
843 $name = esc_html($this->link->link->link_name);
844 else: // Or a new subscription to add?
845 $name = "Subscribe to <code>".esc_html(feedwordpress_display_url($lookup))."</code>";
846 endif;
847 ?>
848 <div class="wrap" id="feed-finder">
849 <h2>Feed Finder: <?php echo $name; ?></h2>
850
851 <?php
852 if ($feedSwitch) :
853 $this->display_alt_feed_box($lookup);
854 endif;
855
856 $finder = array();
857 if (!is_null($current)) :
858 $finder[$current] = new FeedFinder($current);
859 endif;
860 $finder[$lookup] = new FeedFinder($lookup);
861
862 foreach ($finder as $url => $ff) :
863 $feeds = array_merge($feeds, $ff->find(
864 /*url=*/ NULL,
865 /*params=*/ $credentials));
866 endforeach;
867
868 $feeds = array_values( // Renumber from 0..(N-1)
869 $feeds
870 );
871
872 // Allow for some simple FeedFinder results filtering
873 $feeds = apply_filters(
874 'feedwordpress_feedfinder_results',
875 $feeds,
876 array(
877 "url" => $lookup,
878 "auth" => $auth,
879 "username" => $username,
880 "password" => $password,
881 "finder" => $finder,
882 ),
883 $this
884 );
885
886 if (count($feeds) > 0):
887 if ($feedSwitch) :
888 ?>
889 <h3>Feeds Found</h3>
890 <?php
891 endif;
892
893 if (count($feeds) > 1) :
894 $option_template = 'Option %d: ';
895 $form_class = ' class="multi"';
896 ?>
897 <p><strong>This web page provides at least <?php print count($feeds); ?> different feeds.</strong> These feeds may provide the same information
898 in different formats, or may track different items. (You can check the Feed Information and the
899 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>
900 <?php
901 else :
902 $option_template = '';
903 $form_class = '';
904 endif;
905
906 global $fwp_credentials;
907
908 foreach ($feeds as $key => $f):
909 $ofc = $fwp_credentials;
910 $fwp_credentials = $credentials; // Set
911 $pie = FeedWordPress::fetch($f, array("cache" => false));
912 $fwp_credentials = $ofc; // Re-Set
913
914 $rss = (is_wp_error($pie) ? $pie : new MagpieFromSimplePie($pie));
915
916 if ($this->url_for_401($pie)) :
917 $this->display_alt_feed_box($lookup, array(
918 "err" => $pie,
919 "auth" => $auth,
920 "username" => $username,
921 "password" => $password
922 ));
923 continue;
924 endif;
925
926 if ($rss and !is_wp_error($rss)):
927 $feed_link = (isset($rss->channel['link'])?$rss->channel['link']:'');
928 $feed_title = (isset($rss->channel['title'])?$rss->channel['title']:$feed_link);
929 $feed_type = ($rss->feed_type ? $rss->feed_type : 'Unknown');
930 $feed_version_template = '%.1f';
931 $feed_version = $rss->feed_version;
932 else :
933 // Give us some sucky defaults
934 $feed_title = feedwordpress_display_url($lookup);
935 $feed_link = $lookup;
936 $feed_type = 'Unknown';
937 $feed_version_template = '';
938 $feed_version = '';
939 endif;
940 ?>
941 <form<?php print $form_class; ?> action="<?php print $this->form_action('syndication.php'); ?>" method="post">
942 <div class="inside"><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_switchfeed'); ?>
943
944 <?php
945 $classes = array('feed-found'); $currentFeed = '';
946 if (!is_null($current) and $current==$f) :
947 $classes[] = 'current';
948 $currentFeed = ' (currently subscribed)';
949 endif;
950 if ($key%2) :
951 $classes[] = 'alt';
952 endif;
953 ?>
954 <fieldset class="<?php print implode(" ", $classes); ?>">
955 <legend><?php printf($option_template, ($key+1)); print $feed_type." "; printf($feed_version_template, $feed_version); ?> feed<?php print $currentFeed; ?></legend>
956
957 <?php
958 $this->stamp_link_id();
959
960 // No feed specified = add new feed; we
961 // need to pass along a starting title
962 // and homepage URL for the new Link.
963 if (!$this->for_feed_settings()):
964 ?>
965 <input type="hidden" name="feed_title" value="<?php echo esc_html($feed_title); ?>" />
966 <input type="hidden" name="feed_link" value="<?php echo esc_html($feed_link); ?>" />
967 <?php
968 endif;
969 ?>
970
971 <input type="hidden" name="feed" value="<?php echo esc_html($f); ?>" />
972 <input type="hidden" name="action" value="switchfeed" />
973
974 <div>
975 <div class="feed-sample">
976 <?php
977 $link = NULL;
978 $post = NULL;
979 if (!is_wp_error($rss) and count($rss->items) > 0):
980 // Prepare to display Sample Item
981 $link = new MagpieMockLink(array('simplepie' => $pie, 'magpie' => $rss), $f);
982 $post = new SyndicatedPost(array('simplepie' => $rss->originals[0], 'magpie' => $rss->items[0]), $link);
983 ?>
984 <h3>Sample Item</h3>
985 <ul>
986 <li><strong>Title:</strong> <a href="<?php echo $post->post['meta']['syndication_permalink']; ?>"><?php echo $post->post['post_title']; ?></a></li>
987 <li><strong>Date:</strong> <?php print date('d-M-y g:i:s a', $post->published()); ?></li>
988 </ul>
989 <div class="entry">
990 <?php print $post->post['post_content']; ?>
991 </div>
992 <?php
993 do_action('feedwordpress_feed_finder_sample_item', $f, $post, $link);
994 else:
995 if (is_wp_error($rss)) :
996 print '<div class="feed-problem">';
997 print "<h3>Problem:</h3>\n";
998 print "<p>FeedWordPress encountered the following error
999 when trying to retrieve this feed:</p>";
1000 print '<p style="margin: 1.0em 3.0em"><code>'.$rss->get_error_message().'</code></p>';
1001 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>";
1002 print "</div>";
1003 endif;
1004 ?>
1005 <h3>No Items</h3>
1006 <p>FeedWordPress found no posts on this feed.</p>
1007 <?php
1008 endif;
1009 ?>
1010 </div>
1011
1012 <div>
1013 <h3>Feed Information</h3>
1014 <ul>
1015 <li><strong>Homepage:</strong> <a href="<?php echo $feed_link; ?>"><?php echo is_null($feed_title)?'<em>Unknown</em>':$feed_title; ?></a></li>
1016 <li><strong>Feed URL:</strong> <a title="<?php echo esc_html($f); ?>" href="<?php echo esc_html($f); ?>"><?php echo esc_html(feedwordpress_display_url($f, 40, 10)); ?></a> (<a title="Check feed &lt;<?php echo esc_html($f); ?>&gt; for validity" href="http://feedvalidator.org/check.cgi?url=<?php echo urlencode($f); ?>">validate</a>)</li>
1017 <li><strong>Encoding:</strong> <?php echo isset($rss->encoding)?esc_html($rss->encoding):"<em>Unknown</em>"; ?></li>
1018 <li><strong>Description:</strong> <?php echo isset($rss->channel['description'])?esc_html($rss->channel['description']):"<em>Unknown</em>"; ?></li>
1019 </ul>
1020 <?php $this->display_authentication_credentials_box(array(
1021 'username' => $username,
1022 'password' => $password,
1023 'method' => $auth,
1024 )); ?>
1025 <?php do_action('feedwordpress_feedfinder_form', $f, $post, $link, $this->for_feed_settings()); ?>
1026 <div class="submit"><input type="submit" class="button-primary" name="Use" value="&laquo; Use this feed" />
1027 <input type="submit" class="button" name="Cancel" value="× Cancel" /></div>
1028 </div>
1029 </div>
1030 </fieldset>
1031 </div> <!-- class="inside" -->
1032 </form>
1033 <?php
1034 unset($link);
1035 unset($post);
1036 endforeach;
1037 else:
1038 foreach ($finder as $url => $ff) :
1039 $url = esc_html($url);
1040 print "<h3>Searched for feeds at ${url}</h3>\n";
1041 print "<p><strong>".__('Error').":</strong> ".__("FeedWordPress couldn't find any feeds at").' <code><a href="'.htmlspecialchars($lookup).'">'.htmlspecialchars($lookup).'</a></code>';
1042 print ". ".__('Try another URL').".</p>";
1043
1044 // Diagnostics
1045 print "<div class=\"updated\" style=\"margin-left: 3.0em; margin-right: 3.0em;\">\n";
1046 print "<h3>".__('Diagnostic information')."</h3>\n";
1047 if (!is_null($ff->error()) and strlen($ff->error()) > 0) :
1048 print "<h4>".__('HTTP request failure')."</h4>\n";
1049 print "<p>".$ff->error()."</p>\n";
1050 else :
1051 print "<h4>".__('HTTP request completed')."</h4>\n";
1052 print "<p><strong>Status ".$ff->status().":</strong> ".$this->HTTPStatusMessages[(int) $ff->status()]."</p>\n";
1053 endif;
1054
1055 // Do some more diagnostics if the API for it is available.
1056 if (function_exists('_wp_http_get_object')) :
1057 $httpObject = _wp_http_get_object();
1058
1059 if (is_callable(array($httpObject, '_getTransport'))) :
1060 $transports = $httpObject->_getTransport();
1061
1062 print "<h4>".__('HTTP Transports available').":</h4>\n";
1063 print "<ol>\n";
1064 print "<li>".implode("</li>\n<li>", array_map('get_class', $transports))."</li>\n";
1065 print "</ol>\n";
1066 elseif (is_callable(array($httpObject, '_get_first_available_transport'))) :
1067 $transport = $httpObject->_get_first_available_transport(
1068 array(),
1069 $url
1070 );
1071
1072 print "<h4>".__("HTTP Transport").":</h4>\n";
1073 print "<ol>\n";
1074 print "<li>".MyPHP::val($transport)."</li>\n";
1075 print "</ol>\n";
1076 endif;
1077
1078 print "</div>\n";
1079 endif;
1080 endforeach;
1081 endif;
1082
1083 if (!$feedSwitch) :
1084 $this->display_alt_feed_box($lookup, /*alt=*/ true);
1085 endif;
1086 ?>
1087 </div> <!-- class="wrap" -->
1088 <?php
1089 return false; // Don't continue
1090 } /* FeedWordPressFeedsPage::display_feedfinder() */
1091
1092 function display_alt_feed_box ($lookup, $params = false) {
1093 global $fwp_post;
1094
1095 if (is_bool($params)) :
1096 $params = array("alt" => $params);
1097 endif;
1098
1099 $params = wp_parse_args($params, array( // Defaults
1100 "alt" => false,
1101 "err" => NULL,
1102 "auth" => NULL,
1103 "password" => NULL,
1104 "username" => NULL,
1105 ));
1106 $alt = $params['alt'];
1107
1108 ?>
1109 <form action="<?php print $this->form_action('syndication.php'); ?>" method="post">
1110 <div class="inside"><?php
1111 FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds');
1112 ?>
1113 <fieldset class="alt"
1114 <?php if (!$alt): ?>style="margin: 1.0em 3.0em; font-size: smaller;"<?php endif; ?>>
1115 <legend><?php if ($alt) : ?>Alternative feeds<?php else: ?>Find feeds<?php endif; ?></legend>
1116 <?php if ($alt) : ?><h3>Use a different feed</h3><?php endif; ?>
1117 <?php if (is_wp_error($params['err'])) :
1118 ?>
1119 <p><em><strong>401 Not Authorized.</strong> This URL may require
1120 a username and password to access it.</em> You may want to add login
1121 credentials below and check it again.</p>
1122 <?php
1123 endif;
1124 ?>
1125 <div><label>Address:
1126 <input type="text" name="lookup" id="use-another-feed"
1127 placeholder="URL"
1128 <?php if (is_null($lookup)) : ?>
1129 value="URL"
1130 <?php else : ?>
1131 value="<?php print esc_html($lookup); ?>"
1132 <?php endif; ?>
1133 size="64" style="max-width: 80%" /></label>
1134 <?php if (is_null($lookup)) : ?>
1135 <?php FeedWordPressSettingsUI::magic_input_tip_js('use-another-feed'); ?>
1136 <?php endif; ?>
1137
1138 <?php $this->stamp_link_id('link_id'); ?>
1139 <input type="hidden" name="action" value="feedfinder" />
1140 <input type="submit" class="button<?php if ($alt): ?>-primary<?php endif; ?>" value="Check &raquo;" /></div>
1141
1142 <?php $this->display_authentication_credentials_box(array(
1143 'username' => $params['username'],
1144 'password' => $params['password'],
1145 'method' => $params['auth'],
1146 )); ?>
1147
1148 <p>This can be the address of a feed, or of a website. FeedWordPress
1149 will try to automatically detect any feeds associated with a
1150 website.</p>
1151 </div> <!-- class="inside" -->
1152 </fieldset></form>
1153
1154 <?php
1155 } /* FeedWordPressFeedsPage::display_alt_feed_box() */
1156
1157 function save_settings ($post) {
1158 if ($this->for_feed_settings()) :
1159
1160 if (isset($post['link_rss_params_key'])) :
1161 $qp = array();
1162 foreach ($post['link_rss_params_key'] as $index => $key) :
1163 if (strlen($key) > 0) :
1164 if (isset($post['link_rss_params_value'][$index])
1165 and strlen($post['link_rss_params_value'][$index])) :
1166 $value = $post['link_rss_params_value'][$index];
1167 $qp[] = array($key, $value);
1168 endif;
1169 endif;
1170 endforeach;
1171 $this->update_setting('query parameters', serialize($qp));
1172 endif;
1173
1174 // custom feed settings first
1175 foreach ($post['notes'] as $mn) :
1176 $mn['key0'] = (isset($mn['key0']) ? trim($mn['key0']) : NULL);
1177 $mn['key1'] = trim($mn['key1']);
1178 if (preg_match("\007^(("
1179 .implode(')|(',$this->special_settings)
1180 ."))$\007i",
1181 $mn['key1'])) :
1182 $mn['key1'] = 'user/'.$mn['key1'];
1183 endif;
1184
1185 if (strlen($mn['key0']) > 0) :
1186 unset($this->link->settings[$mn['key0']]); // out with the old
1187 endif;
1188
1189 if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) :
1190 $this->link->settings[$mn['key1']] = $mn['value']; // in with the new
1191 endif;
1192 endforeach;
1193
1194 // now stuff through the web form
1195 // hardcoded feed info
1196
1197 foreach (array('name', 'description', 'url') as $what) :
1198 // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
1199 $this->link->settings["hardcode {$what}"] = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
1200 if (FeedWordPress::affirmative($this->link->settings, "hardcode {$what}")) :
1201 $this->link->link->{'link_'.$what} = $post['link'.$what];
1202 endif;
1203 endforeach;
1204
1205 // Update scheduling
1206 if (isset($post['update_schedule'])) :
1207 $this->link->settings['update/hold'] = $post['update_schedule'];
1208 endif;
1209
1210 if (isset($post['use_default_update_window']) and strtolower($post['use_default_update_window'])=='yes') :
1211 unset($this->link->settings['update/window']);
1212 elseif (isset($post['update_window'])):
1213 if ((int) $post['update_window'] > 0) :
1214 $this->link->settings['update/window'] = (int) $post['update_window'];
1215 endif;
1216 endif;
1217
1218 else :
1219 // Global
1220 update_option('feedwordpress_cat_id', $post['syndication_category']);
1221
1222 if (!isset($post['automatic_updates']) or !in_array($post['automatic_updates'], array('init', 'shutdown'))) :
1223 $automatic_updates = NULL;
1224 else :
1225 $automatic_updates = $post['automatic_updates'];
1226 endif;
1227 update_option('feedwordpress_automatic_updates', $automatic_updates);
1228
1229 if (isset($post['update_window'])):
1230 if ((int) $post['update_window'] > 0) :
1231 update_option('feedwordpress_update_window', (int) $post['update_window']);
1232 endif;
1233 endif;
1234
1235 update_option('feedwordpress_update_time_limit', ($post['update_time_limit']=='yes')?(int) $post['time_limit_seconds']:0);
1236
1237 foreach (array('name', 'description', 'url') as $what) :
1238 // We have a checkbox for "No," so if it's unchecked, mark as "Yes."
1239 $hardcode = (isset($post["hardcode_{$what}"]) ? $post["hardcode_{$what}"] : 'yes');
1240 update_option("feedwordpress_hardcode_{$what}", $hardcode);
1241 endforeach;
1242
1243 endif;
1244
1245 if (isset($post['update_pause'])) :
1246 $this->update_setting('update/pause', $post['update_pause']);
1247 endif;
1248
1249 if (isset($post['fetch_timeout'])) :
1250 if (isset($post['fetch_timeout_default']) and $post['fetch_timeout_default']=='yes') :
1251 $timeout = NULL;
1252 else :
1253 $timeout = $post['fetch_timeout'];
1254 endif;
1255
1256 if (is_int($timeout)) :
1257 $timeout = intval($timeout);
1258 endif;
1259 $this->update_setting('fetch timeout', $timeout);
1260 endif;
1261
1262 if (isset($post['update_incremental'])) :
1263 $this->update_setting('update_incremental', $post['update_incremental']);
1264 endif;
1265
1266 if (isset($post['tombstones'])) :
1267 $this->update_setting('tombstones', $post['tombstones']);
1268 endif;
1269
1270 if (isset($post['update_minimum'])) :
1271 $this->update_setting('update/minimum', $post['update_minimum']);
1272 endif;
1273
1274 if (
1275 isset($post['link_rss_auth_method'])
1276 and $post['link_rss_auth_method']
1277 and ('-' != $post['link_rss_auth_method'])
1278 ) :
1279 $this->update_setting('http auth method', $post['link_rss_auth_method']);
1280 else :
1281 $this->update_setting('http auth method', NULL);
1282 endif;
1283
1284 if (
1285 isset($post['link_rss_username'])
1286 and (strlen($post['link_rss_username']) > 0)
1287 and ('-' != $post['link_rss_auth_method'])
1288 ) :
1289 $this->update_setting('http username', $post['link_rss_username']);
1290 else :
1291 $this->update_setting('http username', NULL);
1292 endif;
1293
1294 if (
1295 isset($post['link_rss_password'])
1296 and (strlen($post['link_rss_password']) > 0)
1297 and ('-' != $post['link_rss_auth_method'])
1298 ) :
1299 $this->update_setting('http password', $post['link_rss_password']);
1300 else :
1301 $this->update_setting('http password', NULL);
1302 endif;
1303
1304 $this->updatedPosts->accept_POST($post);
1305
1306 parent::save_settings($post);
1307 } /* FeedWordPressFeedsPage::save_settings() */
1308
1309 } /* class FeedWordPressFeedsPage */
1310
1311 $feedsPage = new FeedWordPressFeedsPage;
1312 $feedsPage->display();
1313
1314