PluginProbe
FeedWordPress / 2013.0504
FeedWordPress v2013.0504
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 2013.0504, at feedwordpresssyndicationpage.class.php

1,182 lines 42.4 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(MyPHP::post('link_ids'))
86 and (MyPHP::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(MyPHP::post('update_uri'))) :
99 $targets = MyPHP::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 $cont = true;
344 $dispatcher = array(
345 "feedfinder" => 'fwp_feedfinder_page',
346 FWP_SYNDICATE_NEW => 'fwp_feedfinder_page',
347 "switchfeed" => 'fwp_switchfeed_page',
348 FWP_UNSUB_CHECKED => 'multidelete_page',
349 FWP_DELETE_CHECKED => 'multidelete_page',
350 'Unsubscribe' => 'multidelete_page',
351 FWP_RESUB_CHECKED => 'multiundelete_page',
352 );
353
354 $act = MyPHP::request('action');
355 if (isset($dispatcher[$act])) :
356 $method = $dispatcher[$act];
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 <div style="float: left; background: #F5F5F5; padding-top: 5px; padding-right: 5px;"><a href="<?php print $this->form_action(); ?>"><img src="<?php print esc_html(WP_PLUGIN_URL."/${fwp_path}/feedwordpress.png"); ?>" alt="" /></a></div>
435
436 <p class="info" style="margin-bottom: 0px; border-bottom: 1px dotted black;">Managed by <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>
437 <?php print FEEDWORDPRESS_VERSION; ?>.</p>
438 <?php if (FEEDWORDPRESS_BLEG) : ?>
439 <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
440 contribute to ongoing support and development with
441 <a href="http://feedwordpress.radgeek.com/donate/">a modest donation</a>.</p>
442 <br style="clear: left;" />
443 <?php endif; ?>
444
445 <div class="feedwordpress-actions">
446 <h4>Updates</h4>
447 <ul class="options">
448 <li><strong>Scheduled:</strong> <?php print $update_setting; ?>
449 (<a href="<?php print $this->form_action('feeds-page.php'); ?>">change setting</a>)</li>
450
451 <li><?php if (!is_null($lastUpdate)) : ?>
452 <strong>Last checked:</strong> <?php print fwp_time_elapsed($lastUpdate); ?>
453 <?php else : ?>
454 <strong>Last checked:</strong> none yet
455 <?php endif; ?> </li>
456
457 </ul>
458 </div>
459
460 <div class="feedwordpress-stats">
461 <h4>Subscriptions</h4>
462 <table>
463 <tbody>
464 <tr class="first">
465 <td class="first b b-active"><a href="<?php print esc_html($activeHref); ?>"><?php print count($sources['Y']); ?></a></td>
466 <td class="t active"><a href="<?php print esc_html($activeHref); ?>">Active</a></td>
467 </tr>
468
469 <tr>
470 <td class="b b-inactive"><a href="<?php print esc_html($inactiveHref); ?>"><?php print count($sources['N']); ?></a></td>
471 <td class="t inactive"><a href="<?php print esc_html($inactiveHref); ?>">Inactive</a></td>
472 </tr>
473 </table>
474 </div>
475
476 <div id="add-single-uri">
477 <?php if (count($sources['Y']) > 0) : ?>
478 <form id="check-for-updates" action="<?php print $this->form_action(); ?>" method="POST">
479 <div class="container"><input type="submit" class="button-primary" name"update" value="<?php print FWP_CHECK_FOR_UPDATES; ?>" />
480 <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
481 <input type="hidden" name="update_uri" value="*" /></div>
482 </form>
483 <?php endif; ?>
484
485 <form id="syndicated-links" action="<?php print $hrefPrefix; ?>&amp;visibility=<?php print $visibility; ?>" method="post">
486 <div class="container"><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
487 <label for="add-uri">Add:
488 <input type="text" name="lookup" id="add-uri" placeholder="Source URL"
489 value="Source URL" style="width: 55%;" /></label>
490
491 <?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); ?>
492 <input type="hidden" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" />
493 <input style="vertical-align: middle;" type="image" src="<?php print WP_PLUGIN_URL.'/'.$fwp_path; ?>/plus.png" alt="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
494 </form>
495 </div> <!-- id="add-single-uri" -->
496
497 <br style="clear: both;" />
498
499 <?php
500 } /* FeedWordPressSyndicationPage::dashboard_box () */
501
502 function syndicated_sources_box ($page, $box = NULL) {
503 global $fwp_path;
504
505 $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
506 $sources = $this->sources('*');
507
508 $visibility = $this->visibility_toggle();
509 $showInactive = $this->show_inactive();
510
511 $hrefPrefix = $this->form_action();
512 ?>
513 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
514 <div class="tablenav">
515
516 <div id="add-multiple-uri" class="hide-if-js">
517 <form action="<?php print $hrefPrefix; ?>&amp;visibility=<?php print $visibility; ?>" method="post">
518 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
519 <h4>Add Multiple Sources</h4>
520 <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>
521 <div><textarea name="multilookup" rows="8" cols="60"
522 style="vertical-align: top"></textarea></div>
523 <div style="border-top: 1px dotted black; padding-top: 10px">
524 <div class="alignright"><input type="submit" class="button-primary" name="multiadd" value="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
525 <div class="alignleft"><input type="button" class="button-secondary" name="action" value="<?php print FWP_CANCEL_BUTTON; ?>" id="turn-off-multiple-sources" /></div>
526 </div>
527 </form>
528 </div> <!-- id="add-multiple-uri" -->
529
530 <div id="upload-opml" style="float: right" class="hide-if-js">
531 <h4>Import source list</h4>
532 <p>You can import a list of sources in OPML format, either by providing
533 a URL for the OPML document, or by uploading a copy from your
534 computer.</p>
535
536 <form enctype="multipart/form-data" action="<?php print $hrefPrefix; ?>&amp;visibility=<?php print $visibility; ?>" method="post">
537 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?><input type="hidden" name="MAX_FILE_SIZE" value="100000" /></div>
538 <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>
539 <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>
540
541 <div style="border-top: 1px dotted black; padding-top: 10px">
542 <div class="alignright"><input type="submit" class="button-primary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
543 <div class="alignleft"><input type="button" class="button-secondary" name="action" value="<?php print FWP_CANCEL_BUTTON; ?>" id="turn-off-opml-upload" /></div>
544 </div>
545 </form>
546 </div> <!-- id="upload-opml" -->
547
548 <div id="add-single-uri" class="alignright">
549 <form id="syndicated-links" action="<?php print $hrefPrefix; ?>&amp;visibility=<?php print $visibility; ?>" method="post">
550 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
551 <ul class="subsubsub">
552 <li><label for="add-uri">New source:</label>
553 <input type="text" name="lookup" id="add-uri" value="Website or feed URI" />
554
555 <?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); FeedWordPressSettingsUI::magic_input_tip_js('opml-lookup'); ?>
556
557 <input type="hidden" name="action" value="feedfinder" />
558 <input type="submit" class="button-secondary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" />
559 <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>
560 <span class="screen-reader-text"> or </span>
561 <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>
562 </li>
563 </ul>
564 </form>
565 </div> <!-- class="alignright" -->
566
567 <div class="alignleft">
568 <?php
569 if (count($sources[$visibility]) > 0) :
570 $this->manage_page_links_subsubsub($sources, $showInactive);
571 endif;
572 ?>
573 </div> <!-- class="alignleft" -->
574
575 </div> <!-- class="tablenav" -->
576
577 <form id="syndicated-links" action="<?php print $hrefPrefix; ?>&amp;visibility=<?php print $visibility; ?>" method="post">
578 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
579
580 <?php if ($showInactive) : ?>
581 <div style="clear: right" class="alignright">
582 <p style="font-size: smaller; font-style: italic">FeedWordPress used to syndicate
583 posts from these sources, but you have unsubscribed from them.</p>
584 </div>
585 <?php
586 endif;
587 ?>
588
589 <?php
590 if (count($sources[$visibility]) > 0) :
591 $this->display_button_bar($showInactive);
592 else :
593 $this->manage_page_links_subsubsub($sources, $showInactive);
594 endif;
595
596 fwp_syndication_manage_page_links_table_rows($sources[$visibility], $this, $visibility);
597 $this->display_button_bar($showInactive);
598 ?>
599 </form>
600 <?php
601 } /* FeedWordPressSyndicationPage::syndicated_sources_box() */
602
603 function manage_page_links_subsubsub ($sources, $showInactive) {
604 $hrefPrefix = $this->admin_page_href("syndication.php");
605 ?>
606 <ul class="subsubsub">
607 <li><a <?php if (!$showInactive) : ?>class="current" <?php endif; ?>href="<?php print $hrefPrefix; ?>&amp;visibility=Y">Subscribed
608 <span class="count">(<?php print count($sources['Y']); ?>)</span></a></li>
609 <?php if ($showInactive or (count($sources['N']) > 0)) : ?>
610 <li><a <?php if ($showInactive) : ?>class="current" <?php endif; ?>href="<?php print $hrefPrefix; ?>&amp;visibility=N">Inactive</a>
611 <span class="count">(<?php print count($sources['N']); ?>)</span></a></li>
612 <?php endif; ?>
613
614 </ul> <!-- class="subsubsub" -->
615 <?php
616 }
617
618 function display_button_bar ($showInactive) {
619 ?>
620 <div style="clear: left" class="alignleft">
621 <?php if ($showInactive) : ?>
622 <input class="button-secondary" type="submit" name="action" value="<?php print FWP_RESUB_CHECKED; ?>" />
623 <input class="button-secondary" type="submit" name="action" value="<?php print FWP_DELETE_CHECKED; ?>" />
624 <?php else : ?>
625 <input class="button-secondary" type="submit" name="action" value="<?php print FWP_UPDATE_CHECKED; ?>" />
626 <input class="button-secondary delete" type="submit" name="action" value="<?php print FWP_UNSUB_CHECKED; ?>" />
627 <?php endif ; ?>
628 </div> <!-- class="alignleft" -->
629
630 <br class="clear" />
631 <?php
632 }
633
634 function bleg_thanks ($page, $box = NULL) {
635 ?>
636 <div class="donation-thanks">
637 <h4>Thank you!</h4>
638 <p><strong>Thank you</strong> for your contribution to <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a> development.
639 Your generous gifts make ongoing support and development for
640 FeedWordPress possible.</p>
641 <p>If you have any questions about FeedWordPress, or if there
642 is anything I can do to help make FeedWordPress more useful for
643 you, please <a href="http://feedwordpress.radgeek.com/contact">contact me</a>
644 and let me know what you're thinking about.</p>
645 <p class="signature">&#8212;<a href="http://radgeek.com/">Charles Johnson</a>, Developer, <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>.</p>
646 </div>
647 <?php
648 } /* FeedWordPressSyndicationPage::bleg_thanks () */
649
650 function bleg_box ($page, $box = NULL) {
651 ?>
652 <div class="donation-form">
653 <h4>Keep FeedWordPress improving</h4>
654 <form action="https://www.paypal.com/cgi-bin/webscr" accept-charset="UTF-8" method="post"><div>
655 <p><a href="http://feedwordpress.radgeek.com/">FeedWordPress</a> makes syndication
656 simple and empowers you to stream content from all over the web into your
657 WordPress hub. That's got to be worth a few lattes. If you're finding FWP useful,
658 <a href="http://feedwordpress.radgeek.com/donate/">a modest gift</a>
659 is the best way to support steady progress on development, enhancements,
660 support, and documentation.</p>
661 <div class="donate">
662 <input type="hidden" name="business" value="commerce@radgeek.com" />
663 <input type="hidden" name="cmd" value="_xclick" />
664 <input type="hidden" name="item_name" value="FeedWordPress donation" />
665 <input type="hidden" name="no_shipping" value="1" />
666 <input type="hidden" name="return" value="<?php print esc_attr($this->admin_page_href(basename($this->filename), array('paid' => 'yes'))); ?>" />
667 <input type="hidden" name="currency_code" value="USD" />
668 <input type="hidden" name="notify_url" value="http://feedwordpress.radgeek.com/ipn/donation" />
669 <input type="hidden" name="custom" value="1" />
670 <input type="image" name="submit" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" alt="Donate through PayPal" />
671 </div>
672 </div></form>
673
674 <p>You can make a gift online (or
675 <a href="http://feedwordpress.radgeek.com/donation">set up an automatic
676 regular donation</a>) using an existing PayPal account or any major credit card.</p>
677
678 <div class="sod-off">
679 <form style="text-align: center" action="<?php print $this->form_action(); ?>" method="POST"><div>
680 <input class="button" type="submit" name="maybe_later" value="Maybe Later" />
681 <input class="button" type="submit" name="go_away" value="Dismiss" />
682 </div></form>
683 </div>
684 </div> <!-- class="donation-form" -->
685 <?php
686 } /* FeedWordPressSyndicationPage::bleg_box () */
687
688 /**
689 * Override the default display of a save-settings button and replace
690 * it with nothing.
691 */
692 function interstitial () {
693 /* NOOP */
694 } /* FeedWordPressSyndicationPage::interstitial() */
695
696 function multidelete_page () {
697 global $wpdb;
698
699 // If this is a POST, validate source and user credentials
700 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
701
702 if (MyPHP::post('submit')==FWP_CANCEL_BUTTON) :
703 return true; // Continue without further ado.
704 endif;
705
706 $link_ids = (isset($_REQUEST['link_ids']) ? $_REQUEST['link_ids'] : array());
707 if (isset($_REQUEST['link_id'])) : array_push($link_ids, $_REQUEST['link_id']); endif;
708
709 if (MyPHP::post('confirm')=='Delete'):
710 if ( is_array(MyPHP::post('link_action')) ) :
711 $actions = MyPHP::post('link_action');
712 else :
713 $actions = array();
714 endif;
715
716 $do_it = array(
717 'hide' => array(),
718 'nuke' => array(),
719 'delete' => array(),
720 );
721
722 foreach ($actions as $link_id => $what) :
723 $do_it[$what][] = $link_id;
724 endforeach;
725
726 $alter = array();
727 if (count($do_it['hide']) > 0) :
728 $hidem = "(".implode(', ', $do_it['hide']).")";
729 $alter[] = "
730 UPDATE $wpdb->links
731 SET link_visible = 'N'
732 WHERE link_id IN {$hidem}
733 ";
734 endif;
735
736 if (count($do_it['nuke']) > 0) :
737 $nukem = "(".implode(', ', $do_it['nuke']).")";
738
739 // Make a list of the items syndicated from this feed...
740 $post_ids = $wpdb->get_col("
741 SELECT post_id FROM $wpdb->postmeta
742 WHERE meta_key = 'syndication_feed_id'
743 AND meta_value IN {$nukem}
744 ");
745
746 // ... and kill them all
747 if (count($post_ids) > 0) :
748 foreach ($post_ids as $post_id) :
749 // Force scrubbing of deleted post
750 // rather than sending to Trashcan
751 wp_delete_post(
752 /*postid=*/ $post_id,
753 /*force_delete=*/ true
754 );
755 endforeach;
756 endif;
757
758 $alter[] = "
759 DELETE FROM $wpdb->links
760 WHERE link_id IN {$nukem}
761 ";
762 endif;
763
764 if (count($do_it['delete']) > 0) :
765 $deletem = "(".implode(', ', $do_it['delete']).")";
766
767 // Make the items syndicated from this feed appear to be locally-authored
768 $alter[] = "
769 DELETE FROM $wpdb->postmeta
770 WHERE meta_key = 'syndication_feed_id'
771 AND meta_value IN {$deletem}
772 ";
773
774 // ... and delete the links themselves.
775 $alter[] = "
776 DELETE FROM $wpdb->links
777 WHERE link_id IN {$deletem}
778 ";
779 endif;
780
781 $errs = array(); $success = array ();
782 foreach ($alter as $sql) :
783 $result = $wpdb->query($sql);
784 if (!$result):
785 $errs[] = mysql_error();
786 endif;
787 endforeach;
788
789 if (count($alter) > 0) :
790 echo "<div class=\"updated\">\n";
791 if (count($errs) > 0) :
792 echo "There were some problems processing your ";
793 echo "unsubscribe request. [SQL: ".implode('; ', $errs)."]";
794 else :
795 echo "Your unsubscribe request(s) have been processed.";
796 endif;
797 echo "</div>\n";
798 endif;
799
800 return true; // Continue on to Syndicated Sites listing
801 else :
802 $targets = $wpdb->get_results("
803 SELECT * FROM $wpdb->links
804 WHERE link_id IN (".implode(",",$link_ids).")
805 ");
806 ?>
807 <form action="<?php print $this->form_action(); ?>" method="post">
808 <div class="wrap">
809 <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
810 <input type="hidden" name="action" value="Unsubscribe" />
811 <input type="hidden" name="confirm" value="Delete" />
812
813 <h2>Unsubscribe from Syndicated Links:</h2>
814 <?php foreach ($targets as $link) :
815 $subscribed = ('Y' == strtoupper($link->link_visible));
816 $link_url = esc_html($link->link_url);
817 $link_name = esc_html($link->link_name);
818 $link_description = esc_html($link->link_description);
819 $link_rss = esc_html($link->link_rss);
820 ?>
821 <fieldset>
822 <legend><?php echo $link_name; ?></legend>
823 <table class="editform" width="100%" cellspacing="2" cellpadding="5">
824 <tr><th scope="row" width="20%"><?php _e('Feed URI:') ?></th>
825 <td width="80%"><a href="<?php echo $link_rss; ?>"><?php echo $link_rss; ?></a></td></tr>
826 <tr><th scope="row" width="20%"><?php _e('Short description:') ?></th>
827 <td width="80%"><?php echo $link_description; ?></span></td></tr>
828 <tr><th width="20%" scope="row"><?php _e('Homepage:') ?></th>
829 <td width="80%"><a href="<?php echo $link_url; ?>"><?php echo $link_url; ?></a></td></tr>
830 <tr style="vertical-align:top"><th width="20%" scope="row">Subscription <?php _e('Options') ?>:</th>
831 <td width="80%"><ul style="margin:0; padding: 0; list-style: none">
832 <?php if ($subscribed) : ?>
833 <li><input type="radio" id="hide-<?php echo $link->link_id; ?>"
834 name="link_action[<?php echo $link->link_id; ?>]" value="hide" checked="checked" />
835 <label for="hide-<?php echo $link->link_id; ?>">Turn off the subscription for this
836 syndicated link<br/><span style="font-size:smaller">(Keep the feed information
837 and all the posts from this feed in the database, but don't syndicate any
838 new posts from the feed.)</span></label></li>
839 <?php endif; ?>
840 <li><input type="radio" id="nuke-<?php echo $link->link_id; ?>"<?php if (!$subscribed) : ?> checked="checked"<?php endif; ?>
841 name="link_action[<?php echo $link->link_id; ?>]" value="nuke" />
842 <label for="nuke-<?php echo $link->link_id; ?>">Delete this syndicated link and all the
843 posts that were syndicated from it</label></li>
844 <li><input type="radio" id="delete-<?php echo $link->link_id; ?>"
845 name="link_action[<?php echo $link->link_id; ?>]" value="delete" />
846 <label for="delete-<?php echo $link->link_id; ?>">Delete this syndicated link, but
847 <em>keep</em> posts that were syndicated from it (as if they were authored
848 locally).</label></li>
849 <li><input type="radio" id="nothing-<?php echo $link->link_id; ?>"
850 name="link_action[<?php echo $link->link_id; ?>]" value="nothing" />
851 <label for="nothing-<?php echo $link->link_id; ?>">Keep this feed as it is. I changed
852 my mind.</label></li>
853 </ul>
854 </table>
855 </fieldset>
856 <?php endforeach; ?>
857
858 <div class="submit">
859 <input type="submit" name="submit" value="<?php _e(FWP_CANCEL_BUTTON); ?>" />
860 <input class="delete" type="submit" name="submit" value="<?php _e(FWP_UNSUB_FULL) ?>" />
861 </div>
862 </div>
863 <?php
864 return false; // Don't continue on to Syndicated Sites listing
865 endif;
866 } /* FeedWordPressSyndicationPage::multidelete_page() */
867
868 function multiundelete_page () {
869 global $wpdb;
870
871 // If this is a POST, validate source and user credentials
872 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
873
874 $link_ids = (isset($_REQUEST['link_ids']) ? $_REQUEST['link_ids'] : array());
875 if (isset($_REQUEST['link_id'])) : array_push($link_ids, $_REQUEST['link_id']); endif;
876
877 if (MyPHP::post('confirm')=='Undelete'):
878 if ( is_array(MyPHP::post('link_action')) ) :
879 $actions = MyPHP::post('link_action');
880 else :
881 $actions = array();
882 endif;
883
884 $do_it = array(
885 'unhide' => array(),
886 );
887
888 foreach ($actions as $link_id => $what) :
889 $do_it[$what][] = $link_id;
890 endforeach;
891
892 $alter = array();
893 if (count($do_it['unhide']) > 0) :
894 $unhiddem = "(".implode(', ', $do_it['unhide']).")";
895 $alter[] = "
896 UPDATE $wpdb->links
897 SET link_visible = 'Y'
898 WHERE link_id IN {$unhiddem}
899 ";
900 endif;
901
902 $errs = array(); $success = array ();
903 foreach ($alter as $sql) :
904 $result = $wpdb->query($sql);
905 if (!$result):
906 $errs[] = mysql_error();
907 endif;
908 endforeach;
909
910 if (count($alter) > 0) :
911 echo "<div class=\"updated\">\n";
912 if (count($errs) > 0) :
913 echo "There were some problems processing your ";
914 echo "re-subscribe request. [SQL: ".implode('; ', $errs)."]";
915 else :
916 echo "Your re-subscribe request(s) have been processed.";
917 endif;
918 echo "</div>\n";
919 endif;
920
921 return true; // Continue on to Syndicated Sites listing
922 else :
923 $targets = $wpdb->get_results("
924 SELECT * FROM $wpdb->links
925 WHERE link_id IN (".implode(",",$link_ids).")
926 ");
927 ?>
928 <form action="<?php print $this->form_action(); ?>" method="post">
929 <div class="wrap">
930 <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
931 <input type="hidden" name="action" value="<?php print FWP_RESUB_CHECKED; ?>" />
932 <input type="hidden" name="confirm" value="Undelete" />
933
934 <h2>Re-subscribe to Syndicated Links:</h2>
935 <?php
936 foreach ($targets as $link) :
937 $subscribed = ('Y' == strtoupper($link->link_visible));
938 $link_url = esc_html($link->link_url);
939 $link_name = esc_html($link->link_name);
940 $link_description = esc_html($link->link_description);
941 $link_rss = esc_html($link->link_rss);
942
943 if (!$subscribed) :
944 ?>
945 <fieldset>
946 <legend><?php echo $link_name; ?></legend>
947 <table class="editform" width="100%" cellspacing="2" cellpadding="5">
948 <tr><th scope="row" width="20%"><?php _e('Feed URI:') ?></th>
949 <td width="80%"><a href="<?php echo $link_rss; ?>"><?php echo $link_rss; ?></a></td></tr>
950 <tr><th scope="row" width="20%"><?php _e('Short description:') ?></th>
951 <td width="80%"><?php echo $link_description; ?></span></td></tr>
952 <tr><th width="20%" scope="row"><?php _e('Homepage:') ?></th>
953 <td width="80%"><a href="<?php echo $link_url; ?>"><?php echo $link_url; ?></a></td></tr>
954 <tr style="vertical-align:top"><th width="20%" scope="row">Subscription <?php _e('Options') ?>:</th>
955 <td width="80%"><ul style="margin:0; padding: 0; list-style: none">
956 <li><input type="radio" id="unhide-<?php echo $link->link_id; ?>"
957 name="link_action[<?php echo $link->link_id; ?>]" value="unhide" checked="checked" />
958 <label for="unhide-<?php echo $link->link_id; ?>">Turn back on the subscription
959 for this syndication source.</label></li>
960 <li><input type="radio" id="nothing-<?php echo $link->link_id; ?>"
961 name="link_action[<?php echo $link->link_id; ?>]" value="nothing" />
962 <label for="nothing-<?php echo $link->link_id; ?>">Leave this feed as it is.
963 I changed my mind.</label></li>
964 </ul>
965 </table>
966 </fieldset>
967 <?php
968 endif;
969 endforeach;
970 ?>
971
972 <div class="submit">
973 <input class="button-primary delete" type="submit" name="submit" value="<?php _e('Re-subscribe to selected feeds &raquo;') ?>" />
974 </div>
975 </div>
976 <?php
977 return false; // Don't continue on to Syndicated Sites listing
978 endif;
979 } /* FeedWordPressSyndicationPage::multiundelete_page() */
980
981
982
983 } /* class FeedWordPressSyndicationPage */
984
985 function fwp_dashboard_update_if_requested ($object) {
986 global $wpdb;
987
988 $update_set = $object->updates_requested();
989
990 if (count($update_set) > 0) :
991 shuffle($update_set); // randomize order for load balancing purposes...
992
993 $feedwordpress = new FeedWordPress;
994 add_action('feedwordpress_check_feed', 'update_feeds_mention');
995 add_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3);
996
997 $crash_ts = $feedwordpress->crash_ts();
998
999 echo "<div class=\"update-results\">\n";
1000 echo "<ul>\n";
1001 $tdelta = NULL;
1002 foreach ($update_set as $uri) :
1003 if (!is_null($crash_ts) and (time() > $crash_ts)) :
1004 echo "<li><p><strong>Further updates postponed:</strong> update time limit of ".$crash_dt." second".(($crash_dt==1)?"":"s")." exceeded.</p></li>";
1005 break;
1006 endif;
1007
1008 if ($uri == '*') : $uri = NULL; endif;
1009 $delta = $feedwordpress->update($uri, $crash_ts);
1010 if (!is_null($delta)) :
1011 if (is_null($tdelta)) :
1012 $tdelta = $delta;
1013 else :
1014 $tdelta['new'] += $delta['new'];
1015 $tdelta['updated'] += $delta['updated'];
1016 endif;
1017 else :
1018 $display_uri = esc_html(feedwordpress_display_url($uri));
1019 $uri = esc_html($uri);
1020 echo "<li><p><strong>Error:</strong> There was a problem updating <code><a href=\"$uri\">${display_uri}</a></code></p></li>\n";
1021 endif;
1022 endforeach;
1023 echo "</ul>\n";
1024
1025 if (!is_null($tdelta)) :
1026 $mesg = array();
1027 if (isset($delta['new'])) : $mesg[] = ' '.$tdelta['new'].' new posts were syndicated'; endif;
1028 if (isset($delta['updated'])) : $mesg[] = ' '.$tdelta['updated'].' existing posts were updated'; endif;
1029 echo "<p>Update complete.".implode(' and', $mesg)."</p>";
1030 echo "\n"; flush();
1031 endif;
1032 echo "</div> <!-- class=\"updated\" -->\n";
1033 endif;
1034 }
1035
1036 define('FEEDWORDPRESS_BLEG_MAYBE_LATER_OFFSET', (60 /*sec/min*/ * 60 /*min/hour*/ * 24 /*hour/day*/ * 31 /*days*/));
1037 define('FEEDWORDPRESS_BLEG_ALREADY_PAID_OFFSET', (60 /*sec/min*/ * 60 /*min/hour*/ * 24 /*hour/day*/ * 183 /*days*/));
1038 function fwp_syndication_manage_page_update_box ($object = NULL, $box = NULL) {
1039 $bleg_box_hidden = null;
1040 if (isset($_POST['maybe_later'])) :
1041 $bleg_box_hidden = time() + FEEDWORDPRESS_BLEG_MAYBE_LATER_OFFSET;
1042 elseif (isset($_REQUEST['paid']) and $_REQUEST['paid']) :
1043 $bleg_box_hidden = time() + FEEDWORDPRESS_BLEG_ALREADY_PAID_OFFSET;
1044 elseif (isset($_POST['go_away'])) :
1045 $bleg_box_hidden = 'permanent';
1046 endif;
1047
1048 if (!is_null($bleg_box_hidden)) :
1049 update_option('feedwordpress_bleg_box_hidden', $bleg_box_hidden);
1050 else :
1051 $bleg_box_hidden = get_option('feedwordpress_bleg_box_hidden');
1052 endif;
1053 ?>
1054 <?php
1055 $bleg_box_ready = (FEEDWORDPRESS_BLEG and (
1056 !$bleg_box_hidden
1057 or (is_numeric($bleg_box_hidden) and $bleg_box_hidden < time())
1058 ));
1059
1060 if (isset($_REQUEST['paid']) and $_REQUEST['paid']) :
1061 $object->bleg_thanks($subject, $box);
1062 elseif ($bleg_box_ready) :
1063 $object->bleg_box($object, $box);
1064 endif;
1065 ?>
1066
1067 <form
1068 action="<?php print $object->form_action(); ?>"
1069 method="POST"
1070 class="update-form<?php if ($bleg_box_ready) : ?> with-donation<?php endif; ?>"
1071 >
1072 <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
1073 <p>Check currently scheduled feeds for new and updated posts.</p>
1074
1075 <?php
1076 fwp_dashboard_update_if_requested($object);
1077
1078 if (!get_option('feedwordpress_automatic_updates')) :
1079 ?>
1080 <p class="heads-up"><strong>Note:</strong> Automatic updates are currently turned
1081 <strong>off</strong>. New posts from your feeds will not be syndicated
1082 until you manually check for them here. You can turn on automatic
1083 updates under <a href="<?php print $object->admin_page_href('feeds-page.php'); ?>">Feed &amp; Update Settings<a></a>.</p>
1084 <?php
1085 endif;
1086 ?>
1087
1088 <div class="submit"><?php if ($object->show_inactive()) : ?>
1089 <?php foreach ($object->updates_requested() as $req) : ?>
1090 <input type="hidden" name="update_uri[]" value="<?php print esc_html($req); ?>" />
1091 <?php endforeach; ?>
1092 <?php else : ?>
1093 <input type="hidden" name="update_uri" value="*" />
1094 <?php endif; ?>
1095 <input class="button-primary" type="submit" name="update" value="<?php _e(FWP_CHECK_FOR_UPDATES); ?>" /></div>
1096
1097 <br style="clear: both" />
1098 </form>
1099 <?php
1100 } /* function fwp_syndication_manage_page_update_box () */
1101
1102 function fwp_feedfinder_page () {
1103 global $post_source, $fwp_post, $syndicationPage;
1104
1105 if (isset($fwp_post['opml_lookup']) or isset($_FILES['opml_upload'])) :
1106 $syndicationPage->accept_multiadd();
1107 return true;
1108 else :
1109 $post_source = 'feedwordpress_feeds';
1110
1111 // With action=feedfinder, this goes directly to the feedfinder page
1112 include_once(dirname(__FILE__) . '/feeds-page.php');
1113 return false;
1114 endif;
1115 } /* function fwp_feedfinder_page () */
1116
1117 function fwp_switchfeed_page () {
1118 global $wpdb, $wp_db_version;
1119 global $fwp_post, $fwp_path;
1120
1121 // If this is a POST, validate source and user credentials
1122 FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_switchfeed', /*capability=*/ 'manage_links');
1123
1124 $changed = false;
1125 if (!isset($fwp_post['Cancel'])):
1126 if (isset($fwp_post['save_link_id']) and ($fwp_post['save_link_id']=='*')) :
1127 $changed = true;
1128 $link_id = FeedWordPress::syndicate_link($fwp_post['feed_title'], $fwp_post['feed_link'], $fwp_post['feed']);
1129 if ($link_id):
1130 $existingLink = new SyndicatedLink($link_id);
1131
1132 ?>
1133 <div class="updated"><p><a href="<?php print $fwp_post['feed_link']; ?>"><?php print esc_html($fwp_post['feed_title']); ?></a>
1134 has been added as a contributing site, using the feed at
1135 &lt;<a href="<?php print $fwp_post['feed']; ?>"><?php print esc_html($fwp_post['feed']); ?></a>&gt;.
1136 | <a href="admin.php?page=<?php print $fwp_path; ?>/feeds-page.php&amp;link_id=<?php print $link_id; ?>">Configure settings</a>.</p></div>
1137 <?php else: ?>
1138 <div class="updated"><p>There was a problem adding the feed. [SQL: <?php echo esc_html(mysql_error()); ?>]</p></div>
1139 <?php endif;
1140 elseif (isset($fwp_post['save_link_id'])):
1141 $existingLink = new SyndicatedLink($fwp_post['save_link_id']);
1142 $changed = $existingLink->set_uri($fwp_post['feed']);
1143
1144 if ($changed):
1145 $home = $existingLink->homepage(/*from feed=*/ false);
1146 $name = $existingLink->name(/*from feed=*/ false);
1147 ?>
1148 <div class="updated"><p>Feed for <a href="<?php echo esc_html($home); ?>"><?php echo esc_html($name); ?></a>
1149 updated to &lt;<a href="<?php echo esc_html($fwp_post['feed']); ?>"><?php echo esc_html($fwp_post['feed']); ?></a>&gt;.</p></div>
1150 <?php
1151 endif;
1152 endif;
1153 endif;
1154
1155 if (isset($existingLink)) :
1156 $auth = MyPHP::post('link_rss_auth_method');
1157 if (!is_null($auth) and (strlen($auth) > 0) and ($auth != '-')) :
1158 $existingLink->update_setting('http auth method', $auth);
1159 $existingLink->update_setting('http username',
1160 MyPHP::post('link_rss_username')
1161 );
1162 $existingLink->update_setting('http password',
1163 MyPHP::post('link_rss_password')
1164 );
1165 else :
1166 $existingLink->update_setting('http auth method', NULL);
1167 $existingLink->update_setting('http username', NULL);
1168 $existingLink->update_setting('http password', NULL);
1169 endif;
1170 do_action('feedwordpress_admin_switchfeed', $fwp_post['feed'], $existingLink);
1171 $existingLink->save_settings(/*reload=*/ true);
1172 endif;
1173
1174 if (!$changed) :
1175 ?>
1176 <div class="updated"><p>Nothing was changed.</p></div>
1177 <?php
1178 endif;
1179 return true; // Continue
1180 }
1181
1182