PluginProbe
FeedWordPress / 2011.1019
FeedWordPress v2011.1019
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 / feedwordpresssyndicationpage.class.php

feedwordpresssyndicationpage.class.php in FeedWordPress 2011.1019, at feedwordpresssyndicationpage.class.php

1,173 lines 42.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once(dirname(__FILE__) . '/admin-ui.php');
3 require_once(dirname(__FILE__) . '/feedfinder.class.php');
4
5 ################################################################################
6 ## ADMIN MENU ADD-ONS: implement Dashboard management pages ####################
7 ################################################################################
8
9 define('FWP_UPDATE_CHECKED', 'Update Checked');
10 define('FWP_UNSUB_CHECKED', 'Unsubscribe');
11 define('FWP_DELETE_CHECKED', 'Delete');
12 define('FWP_RESUB_CHECKED', 'Re-subscribe');
13 define('FWP_SYNDICATE_NEW', 'Add →');
14 define('FWP_UNSUB_FULL', 'Unsubscribe from selected feeds →');
15 define('FWP_CANCEL_BUTTON', '× Cancel');
16 define('FWP_CHECK_FOR_UPDATES', 'Update');
17
18 class FeedWordPressSyndicationPage extends FeedWordPressAdminPage {
19 function FeedWordPressSyndicationPage ($filename = NULL) {
20 FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresssyndication', /*link=*/ NULL);
21
22 // No over-arching form element
23 $this->dispatch = NULL;
24 if (is_null($filename)) :
25 $this->filename = __FILE__;
26 else :
27 $this->filename = $filename;
28 endif;
29 } /* FeedWordPressSyndicationPage constructor */
30
31 function has_link () { return false; }
32
33 var $_sources = NULL;
34
35 function sources ($visibility = 'Y') {
36 if (is_null($this->_sources)) :
37 $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
38 $this->_sources = array("Y" => array(), "N" => array());
39 foreach ($links as $link) :
40 $this->_sources[$link->link_visible][] = $link;
41 endforeach;
42 endif;
43 $ret = (
44 array_key_exists($visibility, $this->_sources)
45 ? $this->_sources[$visibility]
46 : $this->_sources
47 );
48 return $ret;
49 } /* FeedWordPressSyndicationPage::sources() */
50
51 function visibility_toggle () {
52 $sources = $this->sources('*');
53
54 $defaultVisibility = 'Y';
55 if ((count($this->sources('N')) > 0)
56 and (count($this->sources('Y'))==0)) :
57 $defaultVisibility = 'N';
58 endif;
59
60 $visibility = (
61 isset($_REQUEST['visibility'])
62 ? $_REQUEST['visibility']
63 : $defaultVisibility
64 );
65
66 return $visibility;
67 } /* FeedWordPressSyndicationPage::visibility_toggle() */
68
69 function show_inactive () {
70 return ($this->visibility_toggle() == 'N');
71 }
72
73 function updates_requested () {
74 global $wpdb;
75
76 if (isset($_POST['update']) or isset($_POST['action']) or isset($_POST['update_uri'])) :
77 // Only do things with side-effects for HTTP POST or command line
78 $fwp_update_invoke = 'post';
79 else :
80 $fwp_update_invoke = 'get';
81 endif;
82
83 $update_set = array();
84 if ($fwp_update_invoke != 'get') :
85 if (is_array(FeedWordPress::post('link_ids'))
86 and (FeedWordPress::post('action')==FWP_UPDATE_CHECKED)) :
87 $targets = $wpdb->get_results("
88 SELECT * FROM $wpdb->links
89 WHERE link_id IN (".implode(",",$_POST['link_ids']).")
90 ");
91 if (is_array($targets)) :
92 foreach ($targets as $target) :
93 $update_set[] = $target->link_rss;
94 endforeach;
95 else : // This should never happen
96 FeedWordPress::critical_bug('fwp_syndication_manage_page::targets', $targets, __LINE__, __FILE__);
97 endif;
98 elseif (!is_null(FeedWordPress::post('update_uri'))) :
99 $targets = FeedWordPress::post('update_uri');
100 if (!is_array($targets)) :
101 $targets = array($targets);
102 endif;
103
104 $first = each($targets);
105 if (!is_numeric($first['key'])) : // URLs in keys
106 $targets = array_keys($targets);
107 endif;
108 $update_set = $targets;
109 endif;
110 endif;
111 return $update_set;
112 }
113
114 function accept_multiadd () {
115 global $fwp_post;
116
117 if (isset($fwp_post['cancel']) and $fwp_post['cancel']==__(FWP_CANCEL_BUTTON)) :
118 return true; // Continue ....
119 endif;
120
121 // If this is a POST, validate source and user credentials
122 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
123
124 $in = (isset($fwp_post['multilookup']) ? $fwp_post['multilookup'] : '')
125 .(isset($fwp_post['opml_lookup']) ? $fwp_post['opml_lookup'] : '');
126 if (isset($fwp_post['confirm']) and $fwp_post['confirm']=='multiadd') :
127 $chex = $fwp_post['multilookup'];
128 $added = array(); $errors = array();
129 foreach ($chex as $feed) :
130 if (isset($feed['add']) and $feed['add']=='yes') :
131 // Then, add in the URL.
132 $link_id = FeedWordPress::syndicate_link(
133 $feed['title'],
134 $feed['link'],
135 $feed['url']
136 );
137 if ($link_id and !is_wp_error($link_id)):
138 $added[] = $link_id;
139 else :
140 $errors[] = array($feed['url'], $link_id);
141 endif;
142 endif;
143 endforeach;
144
145 print "<div class='updated'>\n";
146 print "<p>Added ".count($added)." new syndicated sources.</p>";
147 if (count($errors) > 0) :
148 print "<p>FeedWordPress encountered errors trying to add the following sources:</p>
149 <ul>\n";
150 foreach ($errors as $err) :
151 $url = $err[0];
152 $short = esc_html(feedwordpress_display_url($url));
153 $url = esc_html($url);
154 $wp = $err[1];
155 if (is_wp_error($err[1])) :
156 $error = $err[1];
157 $mesg = " (<code>".$error->get_error_messages()."</code>)";
158 else :
159 $mesg = '';
160 endif;
161 print "<li><a href='$url'>$short</a>$mesg</li>\n";
162 endforeach;
163 print "</ul>\n";
164 endif;
165 print "</div>\n";
166
167 elseif (is_array($in) or strlen($in) > 0) :
168 add_meta_box(
169 /*id=*/ 'feedwordpress_multiadd_box',
170 /*title=*/ __('Add Feeds'),
171 /*callback=*/ array($this, 'multiadd_box'),
172 /*page=*/ $this->meta_box_context(),
173 /*context =*/ $this->meta_box_context()
174 );
175 endif;
176 return true; // Continue...
177 }
178
179 function display_multiadd_line ($line) {
180 $short_feed = esc_html(feedwordpress_display_url($line['feed']));
181 $feed = esc_html($line['feed']);
182 $link = esc_html($line['link']);
183 $title = esc_html($line['title']);
184 $checked = $line['checked'];
185 $i = esc_html($line['i']);
186
187 print "<li><label><input type='checkbox' name='multilookup[$i][add]' value='yes' $checked />
188 $title</label> &middot; <a href='$feed'>$short_feed</a>";
189
190 if (isset($line['extra'])) :
191 print " &middot; ".esc_html($line['extra']);
192 endif;
193
194 print "<input type='hidden' name='multilookup[$i][url]' value='$feed' />
195 <input type='hidden' name='multilookup[$i][link]' value='$link' />
196 <input type='hidden' name='multilookup[$i][title]' value='$title' />
197 </li>\n";
198
199 flush();
200 }
201
202 function multiadd_box ($page, $box = NULL) {
203 global $fwp_post;
204
205 $localData = NULL;
206
207 if (isset($_FILES['opml_upload']['name']) and
208 (strlen($_FILES['opml_upload']['name']) > 0)) :
209 $in = 'tag:localhost';
210
211 /*FIXME: check whether $_FILES['opml_upload']['error'] === UPLOAD_ERR_OK or not...*/
212 $localData = file_get_contents($_FILES['opml_upload']['tmp_name']);
213 $merge_all = true;
214 elseif (isset($fwp_post['multilookup'])) :
215 $in = $fwp_post['multilookup'];
216 $merge_all = false;
217 elseif (isset($fwp_post['opml_lookup'])) :
218 $in = $fwp_post['opml_lookup'];
219 $merge_all = true;
220 else :
221 $in = '';
222 $merge_all = false;
223 endif;
224
225 if (strlen($in) > 0) :
226 $lines = preg_split(
227 "/\s+/",
228 $in,
229 /*no limit soldier*/ -1,
230 PREG_SPLIT_NO_EMPTY
231 );
232
233 $i = 0;
234 ?>
235 <form id="multiadd-form" action="<?php print $this->form_action(); ?>" method="post">
236 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
237 <input type="hidden" name="multiadd" value="<?php print FWP_SYNDICATE_NEW; ?>" />
238 <input type="hidden" name="confirm" value="multiadd" />
239
240 <input type="hidden" name="multiadd" value="<?php print FWP_SYNDICATE_NEW; ?>" />
241 <input type="hidden" name="confirm" value="multiadd" /></div>
242
243 <div id="multiadd-status">
244 <p><img src="<?php print esc_url ( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
245 Looking up feed information...</p>
246 </div>
247
248 <div id="multiadd-buttons">
249 <input type="submit" class="button" name="cancel" value="<?php _e(FWP_CANCEL_BUTTON); ?>" />
250 <input type="submit" class="button-primary" value="<?php print _e('Subscribe to selected sources →'); ?>" />
251 </div>
252
253 <p><?php _e('Here are the feeds that FeedWordPress has discovered from the addresses that you provided. To opt out of a subscription, unmark the checkbox next to the feed.'); ?></p>
254
255 <?php
256 print "<ul id=\"multiadd-list\">\n"; flush();
257 foreach ($lines as $line) :
258 $url = trim($line);
259 if (strlen($url) > 0) :
260 // First, use FeedFinder to check the URL.
261 if (is_null($localData)) :
262 $finder = new FeedFinder($url, /*verify=*/ false, /*fallbacks=*/ 1);
263 else :
264 $finder = new FeedFinder('tag:localhost', /*verify=*/ false, /*fallbacks=*/ 1);
265 $finder->upload_data($localData);
266 endif;
267
268 $feeds = array_values(
269 array_unique(
270 $finder->find()
271 )
272 );
273
274 $found = false;
275 if (count($feeds) > 0) :
276 foreach ($feeds as $feed) :
277 $pie = FeedWordPress::fetch($feed);
278 if (!is_wp_error($pie)) :
279 $found = true;
280
281 $short_feed = esc_html(feedwordpress_display_url($feed));
282 $feed = esc_html($feed);
283 $title = esc_html($pie->get_title());
284 $checked = ' checked="checked"';
285 $link = esc_html($pie->get_link());
286
287 $this->display_multiadd_line(array(
288 'feed' => $feed,
289 'title' => $pie->get_title(),
290 'link' => $pie->get_link(),
291 'checked' => ' checked="checked"',
292 'i' => $i,
293 ));
294
295 $i++; // Increment field counter
296
297 if (!$merge_all) : // Break out after first find
298 break;
299 endif;
300 endif;
301 endforeach;
302 endif;
303
304 if (!$found) :
305 $this->display_multiadd_line(array(
306 'feed' => $url,
307 'title' => feedwordpress_display_url($url),
308 'extra' => " [FeedWordPress couldn't detect any feeds for this URL.]",
309 'link' => NULL,
310 'checked' => '',
311 'i' => $i,
312 ));
313 $i++; // Increment field counter
314 endif;
315 endif;
316 endforeach;
317 print "</ul>\n";
318 ?>
319 </form>
320
321 <script type="text/javascript">
322 jQuery(document).ready( function () {
323 // Hide it now that we're done.
324 jQuery('#multiadd-status').fadeOut(500 /*ms*/);
325 } );
326 </script>
327 <?php
328 endif;
329
330 $this->_sources = NULL; // Force reload of sources list
331 return true; // Continue
332 }
333
334 function display () {
335 global $wpdb;
336 global $fwp_post;
337
338 if (FeedWordPress::needs_upgrade()) :
339 fwp_upgrade_page();
340 return;
341 endif;
342
343 ?>
344 <?php
345 $cont = true;
346 $dispatcher = array(
347 "feedfinder" => 'fwp_feedfinder_page',
348 FWP_SYNDICATE_NEW => 'fwp_feedfinder_page',
349 "switchfeed" => 'fwp_switchfeed_page',
350 FWP_UNSUB_CHECKED => 'multidelete_page',
351 FWP_DELETE_CHECKED => 'multidelete_page',
352 'Unsubscribe' => 'multidelete_page',
353 FWP_RESUB_CHECKED => 'multiundelete_page',
354 );
355 if (isset($_REQUEST['action']) and isset($dispatcher[$_REQUEST['action']])) :
356 $method = $dispatcher[$_REQUEST['action']];
357 if (method_exists($this, $method)) :
358 $cont = $this->{$method}();
359 else :
360 $cont = call_user_func($method);
361 endif;
362 elseif (isset($fwp_post['multiadd']) and $fwp_post['multiadd']==FWP_SYNDICATE_NEW) :
363 $cont = $this->accept_multiadd($fwp_post);
364 endif;
365
366 if ($cont):
367 $links = $this->sources('Y');
368 $potential_updates = (!$this->show_inactive() and (count($this->sources('Y')) > 0));
369
370 $this->open_sheet('Syndicated Sites');
371 ?>
372 <div id="post-body">
373 <?php
374 if ($potential_updates
375 or (count($this->updates_requested()) > 0)) :
376 add_meta_box(
377 /*id=*/ 'feedwordpress_update_box',
378 /*title=*/ __('Update feeds now'),
379 /*callback=*/ 'fwp_syndication_manage_page_update_box',
380 /*page=*/ $this->meta_box_context(),
381 /*context =*/ $this->meta_box_context()
382 );
383 endif;
384 add_meta_box(
385 /*id=*/ 'feedwordpress_feeds_box',
386 /*title=*/ __('Syndicated sources'),
387 /*callback=*/ array(&$this, 'syndicated_sources_box'),
388 /*page=*/ $this->meta_box_context(),
389 /*context =*/ $this->meta_box_context()
390 );
391
392 do_action('feedwordpress_admin_page_syndication_meta_boxes', $this);
393 ?>
394 <div class="metabox-holder">
395 <?php
396 fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
397 ?>
398 </div> <!-- class="metabox-holder" -->
399 </div> <!-- id="post-body" -->
400
401 <?php $this->close_sheet(/*dispatch=*/ NULL); ?>
402
403 <div style="display: none">
404 <div id="tags-input"></div> <!-- avoid JS error from WP 2.5 bug -->
405 </div>
406 <?php
407 endif;
408 } /* FeedWordPressSyndicationPage::display () */
409
410 function dashboard_box ($page, $box = NULL) {
411 global $fwp_path;
412
413 $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
414 $sources = $this->sources('*');
415
416 $visibility = 'Y';
417 $hrefPrefix = $this->form_action();
418 $activeHref = $hrefPrefix.'&visibility=Y';
419 $inactiveHref = $hrefPrefix.'&visibility=N';
420
421 $lastUpdate = get_option('feedwordpress_last_update_all', NULL);
422 $automatic_updates = get_option('feedwordpress_automatic_updates', NULL);
423
424 if ('init'==$automatic_updates) :
425 $update_setting = 'automatically before page loads';
426 elseif ('shutdown'==$automatic_updates) :
427 $update_setting = 'automatically after page loads';
428 else :
429 $update_setting = 'using a cron job or manual check-ins';
430 endif;
431
432 // Hey ho, let's go...
433 ?>
434 <p class="info" style="margin-bottom: 0px; border-bottom: 1px dotted black;">Managed by <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>
435 <?php print FEEDWORDPRESS_VERSION; ?>.</p>
436 <?php if (FEEDWORDPRESS_BLEG) : ?>
437 <div style="float: left; background: white; margin-top: 5px; margin-right: 5px;"><a href="<?php print $this->form_action(); ?>"><img src="<?php print esc_html(WP_PLUGIN_URL.'/'.$GLOBALS['fwp_path'].'/feedwordpress.png'); ?>" alt="" /></a></div>
438 <p class="info" style="margin-top: 0px; font-style: italic; font-size: 75%; color: #666;">If you find this tool useful for your daily work, you can
439 contribute to ongoing support and development with
440 <a href="http://feedwordpress.radgeek.com/donate/">a modest donation</a>.</p>
441 <br style="clear: left;" />
442 <?php endif; ?>
443
444 <div class="feedwordpress-actions">
445 <h4>Updates</h4>
446 <ul class="options">
447 <li><strong>Scheduled:</strong> <?php print $update_setting; ?>
448 (<a href="<?php print $this->form_action('feeds-page.php'); ?>">change setting</a>)</li>
449
450 <li><?php if (!is_null($lastUpdate)) : ?>
451 <strong>Last checked:</strong> <?php print fwp_time_elapsed($lastUpdate); ?>
452 <?php else : ?>
453 <strong>Last checked:</strong> none yet
454 <?php endif; ?> </li>
455
456 </ul>
457 </div>
458
459 <div class="feedwordpress-stats">
460 <h4>Subscriptions</h4>
461 <table>
462 <tbody>
463 <tr class="first">
464 <td class="first b b-active"><a href="<?php print esc_html($activeHref); ?>"><?php print count($sources['Y']); ?></a></td>
465 <td class="t active"><a href="<?php print esc_html($activeHref); ?>">Active</a></td>
466 </tr>
467
468 <tr>
469 <td class="b b-inactive"><a href="<?php print esc_html($inactiveHref); ?>"><?php print count($sources['N']); ?></a></td>
470 <td class="t inactive"><a href="<?php print esc_html($inactiveHref); ?>">Inactive</a></td>
471 </tr>
472 </table>
473 </div>
474
475 <div id="add-single-uri">
476 <?php if (count($sources['Y']) > 0) : ?>
477 <form id="check-for-updates" action="<?php print $this->form_action(); ?>" method="POST">
478 <div class="container"><input type="submit" class="button-primary" name"update" value="<?php print FWP_CHECK_FOR_UPDATES; ?>" />
479 <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
480 <input type="hidden" name="update_uri" value="*" /></div>
481 </form>
482 <?php endif; ?>
483
484 <form id="syndicated-links" action="<?php print $hrefPrefix; ?>&amp;visibility=<?php print $visibility; ?>" method="post">
485 <div class="container"><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
486 <label for="add-uri">Add:
487 <input type="text" name="lookup" id="add-uri" placeholder="Source URL"
488 value="Source URL" style="width: 55%;" /></label>
489
490 <?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); ?>
491
492 <input style="vertical-align: middle;" type="image" src="<?php print WP_PLUGIN_URL.'/'.$fwp_path; ?>/plus.png" alt="<?php print FWP_SYNDICATE_NEW; ?>" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
493 </form>
494 </div> <!-- id="add-single-uri" -->
495
496 <br style="clear: both;" />
497
498 <?php
499 } /* FeedWordPressSyndicationPage::dashboard_box () */
500
501 function syndicated_sources_box ($page, $box = NULL) {
502 global $fwp_path;
503
504 $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
505 $sources = $this->sources('*');
506
507 $visibility = $this->visibility_toggle();
508 $showInactive = $this->show_inactive();
509
510 $hrefPrefix = $this->form_action();
511 ?>
512 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
513 <div class="tablenav">
514
515 <div id="add-multiple-uri" class="hide-if-js">
516 <form action="<?php print $hrefPrefix; ?>&amp;visibility=<?php print $visibility; ?>" method="post">
517 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
518 <h4>Add Multiple Sources</h4>
519 <div>Enter one feed or website URL per line. If a URL links to a website which provides multiple feeds, FeedWordPress will use the first one listed.</div>
520 <div><textarea name="multilookup" rows="8" cols="60"
521 style="vertical-align: top"></textarea></div>
522 <div style="border-top: 1px dotted black; padding-top: 10px">
523 <div class="alignright"><input type="submit" class="button-primary" name="multiadd" value="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
524 <div class="alignleft"><input type="button" class="button-secondary" name="action" value="<?php print FWP_CANCEL_BUTTON; ?>" id="turn-off-multiple-sources" /></div>
525 </div>
526 </form>
527 </div> <!-- id="add-multiple-uri" -->
528
529 <div id="upload-opml" style="float: right" class="hide-if-js">
530 <h4>Import source list</h4>
531 <p>You can import a list of sources in OPML format, either by providing
532 a URL for the OPML document, or by uploading a copy from your
533 computer.</p>
534
535 <form enctype="multipart/form-data" action="<?php print $hrefPrefix; ?>&amp;visibility=<?php print $visibility; ?>" method="post">
536 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?><input type="hidden" name="MAX_FILE_SIZE" value="100000" /></div>
537 <div style="clear: both"><label for="opml-lookup" style="float: left; width: 8.0em; margin-top: 5px;">From URL:</label> <input type="text" id="opml-lookup" name="opml_lookup" value="OPML document" /></div>
538 <div style="clear: both"><label for="opml-upload" style="float: left; width: 8.0em; margin-top: 5px;">From file:</label> <input type="file" id="opml-upload" name="opml_upload" /></div>
539
540 <div style="border-top: 1px dotted black; padding-top: 10px">
541 <div class="alignright"><input type="submit" class="button-primary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
542 <div class="alignleft"><input type="button" class="button-secondary" name="action" value="<?php print FWP_CANCEL_BUTTON; ?>" id="turn-off-opml-upload" /></div>
543 </div>
544 </form>
545 </div> <!-- id="upload-opml" -->
546
547 <div id="add-single-uri" class="alignright">
548 <form id="syndicated-links" action="<?php print $hrefPrefix; ?>&amp;visibility=<?php print $visibility; ?>" method="post">
549 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
550 <ul class="subsubsub">
551 <li><label for="add-uri">New source:</label>
552 <input type="text" name="lookup" id="add-uri" value="Website or feed URI" />
553
554 <?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); FeedWordPressSettingsUI::magic_input_tip_js('opml-lookup'); ?>
555
556 <input type="hidden" name="action" value="feedfinder" />
557 <input type="submit" class="button-secondary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" />
558 <div style="text-align: right; margin-right: 2.0em"><a id="turn-on-multiple-sources" href="#add-multiple-uri"><img style="vertical-align: middle" src="<?php print WP_PLUGIN_URL.'/'.$fwp_path; ?>/down.png" alt="" /> add multiple</a>
559 <span class="screen-reader-text"> or </span>
560 <a id="turn-on-opml-upload" href="#upload-opml"><img src="<?php print WP_PLUGIN_URL.'/'.$fwp_path; ?>/plus.png" alt="" style="vertical-align: middle" /> import source list</a></div>
561 </li>
562 </ul>
563 </form>
564 </div> <!-- class="alignright" -->
565
566 <div class="alignleft">
567 <?php
568 if (count($sources[$visibility]) > 0) :
569 fwp_syndication_manage_page_links_subsubsub($sources, $showInactive);
570 endif;
571 ?>
572 </div> <!-- class="alignleft" -->
573
574 </div> <!-- class="tablenav" -->
575
576 <form id="syndicated-links" action="<?php print $hrefPrefix; ?>&amp;visibility=<?php print $visibility; ?>" method="post">
577 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
578
579 <?php if ($showInactive) : ?>
580 <div style="clear: right" class="alignright">
581 <p style="font-size: smaller; font-style: italic">FeedWordPress used to syndicate
582 posts from these sources, but you have unsubscribed from them.</p>
583 </div>
584 <?php
585 endif;
586 ?>
587
588 <?php
589 if (count($sources[$visibility]) > 0) :
590 $this->display_button_bar($showInactive);
591 else :
592 ?>
593 <?php fwp_syndication_manage_page_links_subsubsub($sources, $showInactive); ?>
594 <?php
595 endif;
596
597 fwp_syndication_manage_page_links_table_rows($sources[$visibility], $this, $visibility);
598 $this->display_button_bar($showInactive);
599 ?>
600 </form>
601 <?php
602 } /* FeedWordPressSyndicationPage::syndicated_sources_box() */
603
604 function display_button_bar ($showInactive) {
605 ?>
606 <div style="clear: left" class="alignleft">
607 <?php if ($showInactive) : ?>
608 <input class="button-secondary" type="submit" name="action" value="<?php print FWP_RESUB_CHECKED; ?>" />
609 <input class="button-secondary" type="submit" name="action" value="<?php print FWP_DELETE_CHECKED; ?>" />
610 <?php else : ?>
611 <input class="button-secondary" type="submit" name="action" value="<?php print FWP_UPDATE_CHECKED; ?>" />
612 <input class="button-secondary delete" type="submit" name="action" value="<?php print FWP_UNSUB_CHECKED; ?>" />
613 <?php endif ; ?>
614 </div> <!-- class="alignleft" -->
615
616 <br class="clear" />
617 <?php
618 }
619
620 function bleg_thanks ($page, $box = NULL) {
621 ?>
622 <div class="donation-thanks">
623 <h4>Thank you!</h4>
624 <p><strong>Thank you</strong> for your contribution to <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a> development.
625 Your generous gifts make ongoing support and development for
626 FeedWordPress possible.</p>
627 <p>If you have any questions about FeedWordPress, or if there
628 is anything I can do to help make FeedWordPress more useful for
629 you, please <a href="http://feedwordpress.radgeek.com/contact">contact me</a>
630 and let me know what you're thinking about.</p>
631 <p class="signature">&#8212;<a href="http://radgeek.com/">Charles Johnson</a>, Developer, <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>.</p>
632 </div>
633 <?php
634 } /* FeedWordPressSyndicationPage::bleg_thanks () */
635
636 function bleg_box ($page, $box = NULL) {
637 ?>
638 <div class="donation-form">
639 <h4>Keep FeedWordPress improving</h4>
640 <form action="https://www.paypal.com/cgi-bin/webscr" accept-charset="UTF-8" method="post"><div>
641 <p><a href="http://feedwordpress.radgeek.com/">FeedWordPress</a> makes syndication
642 simple and empowers you to stream content from all over the web into your
643 WordPress hub. That's got to be worth a few lattes. If you're finding FWP useful,
644 <a href="http://feedwordpress.radgeek.com/donate/">a modest gift</a>
645 is the best way to support steady progress on development, enhancements,
646 support, and documentation.</p>
647 <div class="donate">
648 <input type="hidden" name="business" value="commerce@radgeek.com" />
649 <input type="hidden" name="cmd" value="_xclick" />
650 <input type="hidden" name="item_name" value="FeedWordPress donation" />
651 <input type="hidden" name="no_shipping" value="1" />
652 <input type="hidden" name="return" value="<?php print admin_url('admin.php'); ?>?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename($this->filename); ?>&amp;paid=yes" />
653 <input type="hidden" name="currency_code" value="USD" />
654 <input type="hidden" name="notify_url" value="http://feedwordpress.radgeek.com/ipn/donation" />
655 <input type="hidden" name="custom" value="1" />
656 <input type="image" name="submit" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" alt="Donate through PayPal" />
657 </div>
658 </div></form>
659
660 <p>You can make a gift online (or
661 <a href="http://feedwordpress.radgeek.com/donation">set up an automatic
662 regular donation</a>) using an existing PayPal account or any major credit card.</p>
663
664 <div class="sod-off">
665 <form style="text-align: center" action="<?php print $this->form_action(); ?>" method="POST"><div>
666 <input class="button" type="submit" name="maybe_later" value="Maybe Later" />
667 <input class="button" type="submit" name="go_away" value="Dismiss" />
668 </div></form>
669 </div>
670 </div> <!-- class="donation-form" -->
671 <?php
672 } /* FeedWordPressSyndicationPage::bleg_box () */
673
674 /**
675 * Override the default display of a save-settings button and replace
676 * it with nothing.
677 */
678 function interstitial () {
679 /* NOOP */
680 } /* FeedWordPressSyndicationPage::interstitial() */
681
682 function multidelete_page () {
683 global $wpdb;
684 global $fwp_post;
685
686 // If this is a POST, validate source and user credentials
687 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
688
689 if (isset($fwp_post['submit']) and $fwp_post['submit']==FWP_CANCEL_BUTTON) :
690 return true; // Continue without further ado.
691 endif;
692
693 $link_ids = (isset($_REQUEST['link_ids']) ? $_REQUEST['link_ids'] : array());
694 if (isset($_REQUEST['link_id'])) : array_push($link_ids, $_REQUEST['link_id']); endif;
695
696 if (isset($GLOBALS['fwp_post']['confirm']) and $GLOBALS['fwp_post']['confirm']=='Delete'):
697 if (isset($GLOBALS['fwp_post']['link_action']) and is_array($GLOBALS['fwp_post']['link_action'])) :
698 $actions = $GLOBALS['fwp_post']['link_action'];
699 else :
700 $actions = array();
701 endif;
702
703 $do_it = array(
704 'hide' => array(),
705 'nuke' => array(),
706 'delete' => array(),
707 );
708
709 foreach ($actions as $link_id => $what) :
710 $do_it[$what][] = $link_id;
711 endforeach;
712
713 $alter = array();
714 if (count($do_it['hide']) > 0) :
715 $hidem = "(".implode(', ', $do_it['hide']).")";
716 $alter[] = "
717 UPDATE $wpdb->links
718 SET link_visible = 'N'
719 WHERE link_id IN {$hidem}
720 ";
721 endif;
722
723 if (count($do_it['nuke']) > 0) :
724 $nukem = "(".implode(', ', $do_it['nuke']).")";
725
726 // Make a list of the items syndicated from this feed...
727 $post_ids = $wpdb->get_col("
728 SELECT post_id FROM $wpdb->postmeta
729 WHERE meta_key = 'syndication_feed_id'
730 AND meta_value IN {$nukem}
731 ");
732
733 // ... and kill them all
734 if (count($post_ids) > 0) :
735 foreach ($post_ids as $post_id) :
736 if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_29)) :
737 // Force scrubbing of deleted post
738 // rather than sending to Trashcan
739 wp_delete_post(
740 /*postid=*/ $post_id,
741 /*force_delete=*/ true
742 );
743 else :
744 wp_delete_post($post_id);
745 endif;
746 endforeach;
747 endif;
748
749 $alter[] = "
750 DELETE FROM $wpdb->links
751 WHERE link_id IN {$nukem}
752 ";
753 endif;
754
755 if (count($do_it['delete']) > 0) :
756 $deletem = "(".implode(', ', $do_it['delete']).")";
757
758 // Make the items syndicated from this feed appear to be locally-authored
759 $alter[] = "
760 DELETE FROM $wpdb->postmeta
761 WHERE meta_key = 'syndication_feed_id'
762 AND meta_value IN {$deletem}
763 ";
764
765 // ... and delete the links themselves.
766 $alter[] = "
767 DELETE FROM $wpdb->links
768 WHERE link_id IN {$deletem}
769 ";
770 endif;
771
772 $errs = array(); $success = array ();
773 foreach ($alter as $sql) :
774 $result = $wpdb->query($sql);
775 if (!$result):
776 $errs[] = mysql_error();
777 endif;
778 endforeach;
779
780 if (count($alter) > 0) :
781 echo "<div class=\"updated\">\n";
782 if (count($errs) > 0) :
783 echo "There were some problems processing your ";
784 echo "unsubscribe request. [SQL: ".implode('; ', $errs)."]";
785 else :
786 echo "Your unsubscribe request(s) have been processed.";
787 endif;
788 echo "</div>\n";
789 endif;
790
791 return true; // Continue on to Syndicated Sites listing
792 else :
793 $targets = $wpdb->get_results("
794 SELECT * FROM $wpdb->links
795 WHERE link_id IN (".implode(",",$link_ids).")
796 ");
797 ?>
798 <form action="<?php print $this->form_action(); ?>" method="post">
799 <div class="wrap">
800 <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
801 <input type="hidden" name="action" value="Unsubscribe" />
802 <input type="hidden" name="confirm" value="Delete" />
803
804 <h2>Unsubscribe from Syndicated Links:</h2>
805 <?php foreach ($targets as $link) :
806 $subscribed = ('Y' == strtoupper($link->link_visible));
807 $link_url = esc_html($link->link_url);
808 $link_name = esc_html($link->link_name);
809 $link_description = esc_html($link->link_description);
810 $link_rss = esc_html($link->link_rss);
811 ?>
812 <fieldset>
813 <legend><?php echo $link_name; ?></legend>
814 <table class="editform" width="100%" cellspacing="2" cellpadding="5">
815 <tr><th scope="row" width="20%"><?php _e('Feed URI:') ?></th>
816 <td width="80%"><a href="<?php echo $link_rss; ?>"><?php echo $link_rss; ?></a></td></tr>
817 <tr><th scope="row" width="20%"><?php _e('Short description:') ?></th>
818 <td width="80%"><?php echo $link_description; ?></span></td></tr>
819 <tr><th width="20%" scope="row"><?php _e('Homepage:') ?></th>
820 <td width="80%"><a href="<?php echo $link_url; ?>"><?php echo $link_url; ?></a></td></tr>
821 <tr style="vertical-align:top"><th width="20%" scope="row">Subscription <?php _e('Options') ?>:</th>
822 <td width="80%"><ul style="margin:0; padding: 0; list-style: none">
823 <?php if ($subscribed) : ?>
824 <li><input type="radio" id="hide-<?php echo $link->link_id; ?>"
825 name="link_action[<?php echo $link->link_id; ?>]" value="hide" checked="checked" />
826 <label for="hide-<?php echo $link->link_id; ?>">Turn off the subscription for this
827 syndicated link<br/><span style="font-size:smaller">(Keep the feed information
828 and all the posts from this feed in the database, but don't syndicate any
829 new posts from the feed.)</span></label></li>
830 <?php endif; ?>
831 <li><input type="radio" id="nuke-<?php echo $link->link_id; ?>"<?php if (!$subscribed) : ?> checked="checked"<?php endif; ?>
832 name="link_action[<?php echo $link->link_id; ?>]" value="nuke" />
833 <label for="nuke-<?php echo $link->link_id; ?>">Delete this syndicated link and all the
834 posts that were syndicated from it</label></li>
835 <li><input type="radio" id="delete-<?php echo $link->link_id; ?>"
836 name="link_action[<?php echo $link->link_id; ?>]" value="delete" />
837 <label for="delete-<?php echo $link->link_id; ?>">Delete this syndicated link, but
838 <em>keep</em> posts that were syndicated from it (as if they were authored
839 locally).</label></li>
840 <li><input type="radio" id="nothing-<?php echo $link->link_id; ?>"
841 name="link_action[<?php echo $link->link_id; ?>]" value="nothing" />
842 <label for="nothing-<?php echo $link->link_id; ?>">Keep this feed as it is. I changed
843 my mind.</label></li>
844 </ul>
845 </table>
846 </fieldset>
847 <?php endforeach; ?>
848
849 <div class="submit">
850 <input type="submit" name="submit" value="<?php _e(FWP_CANCEL_BUTTON); ?>" />
851 <input class="delete" type="submit" name="submit" value="<?php _e(FWP_UNSUB_FULL) ?>" />
852 </div>
853 </div>
854 <?php
855 return false; // Don't continue on to Syndicated Sites listing
856 endif;
857 } /* FeedWordPressSyndicationPage::multidelete_page() */
858
859 function multiundelete_page () {
860 global $wpdb;
861
862 // If this is a POST, validate source and user credentials
863 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
864
865 $link_ids = (isset($_REQUEST['link_ids']) ? $_REQUEST['link_ids'] : array());
866 if (isset($_REQUEST['link_id'])) : array_push($link_ids, $_REQUEST['link_id']); endif;
867
868 if (isset($GLOBALS['fwp_post']['confirm']) and $GLOBALS['fwp_post']['confirm']=='Undelete'):
869 if (isset($GLOBALS['fwp_post']['link_action']) and is_array($GLOBALS['fwp_post']['link_action'])) :
870 $actions = $GLOBALS['fwp_post']['link_action'];
871 else :
872 $actions = array();
873 endif;
874
875 $do_it = array(
876 'unhide' => array(),
877 );
878
879 foreach ($actions as $link_id => $what) :
880 $do_it[$what][] = $link_id;
881 endforeach;
882
883 $alter = array();
884 if (count($do_it['unhide']) > 0) :
885 $unhiddem = "(".implode(', ', $do_it['unhide']).")";
886 $alter[] = "
887 UPDATE $wpdb->links
888 SET link_visible = 'Y'
889 WHERE link_id IN {$unhiddem}
890 ";
891 endif;
892
893 $errs = array(); $success = array ();
894 foreach ($alter as $sql) :
895 $result = $wpdb->query($sql);
896 if (!$result):
897 $errs[] = mysql_error();
898 endif;
899 endforeach;
900
901 if (count($alter) > 0) :
902 echo "<div class=\"updated\">\n";
903 if (count($errs) > 0) :
904 echo "There were some problems processing your ";
905 echo "re-subscribe request. [SQL: ".implode('; ', $errs)."]";
906 else :
907 echo "Your re-subscribe request(s) have been processed.";
908 endif;
909 echo "</div>\n";
910 endif;
911
912 return true; // Continue on to Syndicated Sites listing
913 else :
914 $targets = $wpdb->get_results("
915 SELECT * FROM $wpdb->links
916 WHERE link_id IN (".implode(",",$link_ids).")
917 ");
918 ?>
919 <form action="<?php print $this->form_action(); ?>" method="post">
920 <div class="wrap">
921 <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
922 <input type="hidden" name="action" value="<?php print FWP_RESUB_CHECKED; ?>" />
923 <input type="hidden" name="confirm" value="Undelete" />
924
925 <h2>Re-subscribe to Syndicated Links:</h2>
926 <?php
927 foreach ($targets as $link) :
928 $subscribed = ('Y' == strtoupper($link->link_visible));
929 $link_url = esc_html($link->link_url);
930 $link_name = esc_html($link->link_name);
931 $link_description = esc_html($link->link_description);
932 $link_rss = esc_html($link->link_rss);
933
934 if (!$subscribed) :
935 ?>
936 <fieldset>
937 <legend><?php echo $link_name; ?></legend>
938 <table class="editform" width="100%" cellspacing="2" cellpadding="5">
939 <tr><th scope="row" width="20%"><?php _e('Feed URI:') ?></th>
940 <td width="80%"><a href="<?php echo $link_rss; ?>"><?php echo $link_rss; ?></a></td></tr>
941 <tr><th scope="row" width="20%"><?php _e('Short description:') ?></th>
942 <td width="80%"><?php echo $link_description; ?></span></td></tr>
943 <tr><th width="20%" scope="row"><?php _e('Homepage:') ?></th>
944 <td width="80%"><a href="<?php echo $link_url; ?>"><?php echo $link_url; ?></a></td></tr>
945 <tr style="vertical-align:top"><th width="20%" scope="row">Subscription <?php _e('Options') ?>:</th>
946 <td width="80%"><ul style="margin:0; padding: 0; list-style: none">
947 <li><input type="radio" id="unhide-<?php echo $link->link_id; ?>"
948 name="link_action[<?php echo $link->link_id; ?>]" value="unhide" checked="checked" />
949 <label for="unhide-<?php echo $link->link_id; ?>">Turn back on the subscription
950 for this syndication source.</label></li>
951 <li><input type="radio" id="nothing-<?php echo $link->link_id; ?>"
952 name="link_action[<?php echo $link->link_id; ?>]" value="nothing" />
953 <label for="nothing-<?php echo $link->link_id; ?>">Leave this feed as it is.
954 I changed my mind.</label></li>
955 </ul>
956 </table>
957 </fieldset>
958 <?php
959 endif;
960 endforeach;
961 ?>
962
963 <div class="submit">
964 <input class="button-primary delete" type="submit" name="submit" value="<?php _e('Re-subscribe to selected feeds &raquo;') ?>" />
965 </div>
966 </div>
967 <?php
968 return false; // Don't continue on to Syndicated Sites listing
969 endif;
970 } /* FeedWordPressSyndicationPage::multiundelete_page() */
971
972
973
974 } /* class FeedWordPressSyndicationPage */
975
976 function fwp_dashboard_update_if_requested ($object) {
977 global $wpdb;
978
979 $update_set = $object->updates_requested();
980
981 if (count($update_set) > 0) :
982 shuffle($update_set); // randomize order for load balancing purposes...
983
984 $feedwordpress = new FeedWordPress;
985 add_action('feedwordpress_check_feed', 'update_feeds_mention');
986 add_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3);
987
988 $crash_ts = $feedwordpress->crash_ts();
989
990 echo "<div class=\"update-results\">\n";
991 echo "<ul>\n";
992 $tdelta = NULL;
993 foreach ($update_set as $uri) :
994 if (!is_null($crash_ts) and (time() > $crash_ts)) :
995 echo "<li><p><strong>Further updates postponed:</strong> update time limit of ".$crash_dt." second".(($crash_dt==1)?"":"s")." exceeded.</p></li>";
996 break;
997 endif;
998
999 if ($uri == '*') : $uri = NULL; endif;
1000 $delta = $feedwordpress->update($uri, $crash_ts);
1001 if (!is_null($delta)) :
1002 if (is_null($tdelta)) :
1003 $tdelta = $delta;
1004 else :
1005 $tdelta['new'] += $delta['new'];
1006 $tdelta['updated'] += $delta['updated'];
1007 endif;
1008 else :
1009 $display_uri = esc_html(feedwordpress_display_url($uri));
1010 $uri = esc_html($uri);
1011 echo "<li><p><strong>Error:</strong> There was a problem updating <code><a href=\"$uri\">${display_uri}</a></code></p></li>\n";
1012 endif;
1013 endforeach;
1014 echo "</ul>\n";
1015
1016 if (!is_null($tdelta)) :
1017 $mesg = array();
1018 if (isset($delta['new'])) : $mesg[] = ' '.$tdelta['new'].' new posts were syndicated'; endif;
1019 if (isset($delta['updated'])) : $mesg[] = ' '.$tdelta['updated'].' existing posts were updated'; endif;
1020 echo "<p>Update complete.".implode(' and', $mesg)."</p>";
1021 echo "\n"; flush();
1022 endif;
1023 echo "</div> <!-- class=\"updated\" -->\n";
1024 endif;
1025 }
1026
1027 define('FEEDWORDPRESS_BLEG_MAYBE_LATER_OFFSET', (60 /*sec/min*/ * 60 /*min/hour*/ * 24 /*hour/day*/ * 31 /*days*/));
1028 define('FEEDWORDPRESS_BLEG_ALREADY_PAID_OFFSET', (60 /*sec/min*/ * 60 /*min/hour*/ * 24 /*hour/day*/ * 183 /*days*/));
1029 function fwp_syndication_manage_page_update_box ($object = NULL, $box = NULL) {
1030 $bleg_box_hidden = null;
1031 if (isset($_POST['maybe_later'])) :
1032 $bleg_box_hidden = time() + FEEDWORDPRESS_BLEG_MAYBE_LATER_OFFSET;
1033 elseif (isset($_REQUEST['paid']) and $_REQUEST['paid']) :
1034 $bleg_box_hidden = time() + FEEDWORDPRESS_BLEG_ALREADY_PAID_OFFSET;
1035 elseif (isset($_POST['go_away'])) :
1036 $bleg_box_hidden = 'permanent';
1037 endif;
1038
1039 if (!is_null($bleg_box_hidden)) :
1040 update_option('feedwordpress_bleg_box_hidden', $bleg_box_hidden);
1041 else :
1042 $bleg_box_hidden = get_option('feedwordpress_bleg_box_hidden');
1043 endif;
1044 ?>
1045 <?php
1046 $bleg_box_ready = (FEEDWORDPRESS_BLEG and (
1047 !$bleg_box_hidden
1048 or (is_numeric($bleg_box_hidden) and $bleg_box_hidden < time())
1049 ));
1050
1051 if (isset($_REQUEST['paid']) and $_REQUEST['paid']) :
1052 $object->bleg_thanks($subject, $box);
1053 elseif ($bleg_box_ready) :
1054 $object->bleg_box($object, $box);
1055 endif;
1056 ?>
1057
1058 <form
1059 action="<?php print $object->form_action(); ?>"
1060 method="POST"
1061 class="update-form<?php if ($bleg_box_ready) : ?> with-donation<?php endif; ?>"
1062 >
1063 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
1064 <p>Check currently scheduled feeds for new and updated posts.</p>
1065
1066 <?php
1067 fwp_dashboard_update_if_requested($object);
1068
1069 if (!get_option('feedwordpress_automatic_updates')) :
1070 ?>
1071 <p class="heads-up"><strong>Note:</strong> Automatic updates are currently turned
1072 <strong>off</strong>. New posts from your feeds will not be syndicated
1073 until you manually check for them here. You can turn on automatic
1074 updates under <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?>/feeds-page.php">Feed &amp; Update Settings<a></a>.</p>
1075 <?php
1076 endif;
1077 ?>
1078
1079 <div class="submit"><?php if ($object->show_inactive()) : ?>
1080 <?php foreach ($object->updates_requested() as $req) : ?>
1081 <input type="hidden" name="update_uri[]" value="<?php print esc_html($req); ?>" />
1082 <?php endforeach; ?>
1083 <?php else : ?>
1084 <input type="hidden" name="update_uri" value="*" />
1085 <?php endif; ?>
1086 <input class="button-primary" type="submit" name="update" value="<?php _e(FWP_CHECK_FOR_UPDATES); ?>" /></div>
1087
1088 <br style="clear: both" />
1089 </form>
1090 <?php
1091 } /* function fwp_syndication_manage_page_update_box () */
1092
1093 function fwp_feedfinder_page () {
1094 global $post_source, $fwp_post, $syndicationPage;
1095
1096 if (isset($fwp_post['opml_lookup']) or isset($_FILES['opml_upload'])) :
1097 $syndicationPage->accept_multiadd();
1098 return true;
1099 else :
1100 $post_source = 'feedwordpress_feeds';
1101
1102 // With action=feedfinder, this goes directly to the feedfinder page
1103 include_once(dirname(__FILE__) . '/feeds-page.php');
1104 return false;
1105 endif;
1106 } /* function fwp_feedfinder_page () */
1107
1108 function fwp_switchfeed_page () {
1109 global $wpdb, $wp_db_version;
1110 global $fwp_post;
1111
1112 // If this is a POST, validate source and user credentials
1113 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_switchfeed', /*capability=*/ 'manage_links');
1114
1115 $changed = false;
1116 if (!isset($fwp_post['Cancel'])):
1117 if (isset($fwp_post['save_link_id']) and ($fwp_post['save_link_id']=='*')) :
1118 $changed = true;
1119 $link_id = FeedWordPress::syndicate_link($fwp_post['feed_title'], $fwp_post['feed_link'], $fwp_post['feed']);
1120 if ($link_id):
1121 $existingLink = new SyndicatedLink($link_id);
1122
1123 ?>
1124 <div class="updated"><p><a href="<?php print $fwp_post['feed_link']; ?>"><?php print esc_html($fwp_post['feed_title']); ?></a>
1125 has been added as a contributing site, using the feed at
1126 &lt;<a href="<?php print $fwp_post['feed']; ?>"><?php print esc_html($fwp_post['feed']); ?></a>&gt;.
1127 | <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/feeds-page.php&amp;link_id=<?php print $link_id; ?>">Configure settings</a>.</p></div>
1128 <?php else: ?>
1129 <div class="updated"><p>There was a problem adding the feed. [SQL: <?php echo esc_html(mysql_error()); ?>]</p></div>
1130 <?php endif;
1131 elseif (isset($fwp_post['save_link_id'])):
1132 $existingLink = new SyndicatedLink($fwp_post['save_link_id']);
1133 $changed = $existingLink->set_uri($fwp_post['feed']);
1134
1135 if ($changed):
1136 $home = $existingLink->homepage(/*from feed=*/ false);
1137 $name = $existingLink->name(/*from feed=*/ false);
1138 ?>
1139 <div class="updated"><p>Feed for <a href="<?php echo esc_html($home); ?>"><?php echo esc_html($name); ?></a>
1140 updated to &lt;<a href="<?php echo esc_html($fwp_post['feed']); ?>"><?php echo esc_html($fwp_post['feed']); ?></a>&gt;.</p></div>
1141 <?php
1142 endif;
1143 endif;
1144 endif;
1145
1146 if (isset($existingLink)) :
1147 $auth = FeedWordPress::post('link_rss_auth_method');
1148 if (!is_null($auth) and $auth != '-') :
1149 $existingLink->update_setting('http auth method', $auth);
1150 $existingLink->update_setting('http username',
1151 FeedWordPress::post('link_rss_username')
1152 );
1153 $existingLink->update_setting('http password',
1154 FeedWordPress::post('link_rss_password')
1155 );
1156 else :
1157 $existingLink->update_setting('http auth method', NULL);
1158 $existingLink->update_setting('http username', NULL);
1159 $existingLink->update_setting('http password', NULL);
1160 endif;
1161 do_action('feedwordpress_admin_switchfeed', $fwp_post['feed'], $existingLink);
1162 $existingLink->save_settings(/*reload=*/ true);
1163 endif;
1164
1165 if (!$changed) :
1166 ?>
1167 <div class="updated"><p>Nothing was changed.</p></div>
1168 <?php
1169 endif;
1170 return true; // Continue
1171 }
1172
1173