PluginProbe
FeedWordPress / 2010.0602
FeedWordPress v2010.0602
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
← All changes | syndication.php +678 -2 trunk2010.0602 View file →
@@ -1,5 +1,681 @@
1 1 <?php
2 - require_once dirname(__FILE__) . '/feedwordpresssyndicationpage.class.php';
2 +require_once(dirname(__FILE__) . '/admin-ui.php');
3 3
4 - $syndicationPage = new FeedWordPressSyndicationPage( __FILE__ );
4 +################################################################################
5 +## ADMIN MENU ADD-ONS: implement Dashboard management pages ####################
6 +################################################################################
7 +
8 +define('FWP_UPDATE_CHECKED', 'Update Checked');
9 +define('FWP_UNSUB_CHECKED', 'Unsubscribe');
10 +define('FWP_SYNDICATE_NEW', 'Syndicate ...');
11 +
12 +class FeedWordPressSyndicationPage extends FeedWordPressAdminPage {
13 + function FeedWordPressSyndicationPage () {
14 + FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresssyndication', /*link=*/ NULL);
15 +
16 + // No over-arching form element
17 + $this->dispatch = NULL;
18 + $this->filename = __FILE__;
19 + } /* FeedWordPressSyndicationPage constructor */
20 +
21 + function has_link () { return false; }
22 +
23 + function display () {
24 + global $wpdb;
25 +
26 + if (FeedWordPress::needs_upgrade()) :
27 + fwp_upgrade_page();
28 + return;
29 + endif;
30 +
31 + ?>
32 + <?php $cont = true;
33 + if (isset($_REQUEST['action'])):
34 + if ($_REQUEST['action'] == 'feedfinder' or $_REQUEST['action']==FWP_SYNDICATE_NEW) : $cont = fwp_feedfinder_page();
35 + elseif ($_REQUEST['action'] == 'switchfeed') : $cont = fwp_switchfeed_page();
36 + elseif ($_REQUEST['action'] == FWP_UNSUB_CHECKED or $_REQUEST['action'] == 'Unsubscribe') : $cont = fwp_multidelete_page();
37 + endif;
38 + endif;
39 +
40 + if ($cont):
41 + ?>
42 + <style type="text/css">
43 + .heads-up {
44 + background-color: #d0d0d0;
45 + color: black;
46 + padding: 1.0em;
47 + margin: 0.5em 4.0em !important;
48 + }
49 + .update-form.with-donation {
50 + margin-right: 50%;
51 + min-height: 255px;
52 + }
53 + .donation-form, .donation-thanks {
54 + background-color: #ffffcc;
55 + text-align: left;
56 + padding: 0.5em 0.5em;
57 + border-left: thin dashed #777777;
58 + font-size: 70%;
59 + position: absolute;
60 + top: 0; bottom: 0; right: 0; left: auto;
61 + width: 50%;
62 + }
63 + .donation-thanks {
64 + background-color: #ccffcc;
65 + }
66 + .donation-thanks .signature {
67 + text-align: right;
68 + font-style: italic;
69 + }
70 + .donation-form h4, .donation-thanks h4 {
71 + font-size: 10px;
72 + text-align: center;
73 + border-bottom: 1px solid #777777;
74 + margin: 0px;
75 + }
76 + .donation-form .donate {
77 + text-align: center;
78 + }
79 + .donation-form .sod-off {
80 + padding-top: 0.5em;
81 + margin-top: 0.5em;
82 + border-top: thin solid #777777;
83 + }
84 + </style>
85 + <?php
86 + $links = FeedWordPress::syndicated_links();
87 + $this->open_sheet('Syndicated Sites');
88 + ?>
89 + <div id="post-body">
90 + <?php
91 + if ($links) :
92 + fwp_add_meta_box(
93 + /*id=*/ 'feedwordpress_update_box',
94 + /*title=*/ __('Update feeds now'),
95 + /*callback=*/ 'fwp_syndication_manage_page_update_box',
96 + /*page=*/ $this->meta_box_context(),
97 + /*context =*/ $this->meta_box_context()
98 + );
99 + endif;
100 + fwp_add_meta_box(
101 + /*id=*/ 'feedwordpress_feeds_box',
102 + /*title=*/ __('Syndicated sources'),
103 + /*callback=*/ 'fwp_syndication_manage_page_links_box',
104 + /*page=*/ $this->meta_box_context(),
105 + /*context =*/ $this->meta_box_context()
106 + );
107 + if (FeedWordPressCompatibility::test_version(0, FWP_SCHEMA_25)) :
108 + fwp_add_meta_box(
109 + /*id=*/ 'feedwordpress_add_feed_box',
110 + /*title=*/ 'Add a new syndicated source',
111 + /*callback=*/ 'fwp_syndication_manage_page_add_feed_box',
112 + /*page=*/ $this->meta_box_context(),
113 + /*context=*/ $this->meta_box_context()
114 + );
115 + endif;
116 +
117 + do_action('feedwordpress_admin_page_syndication_meta_boxes', $this);
118 + ?>
119 + <div class="metabox-holder">
120 + <?php
121 + fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
122 + ?>
123 + </div> <!-- class="metabox-holder" -->
124 + </div> <!-- id="post-body" -->
125 +
126 + <?php $this->close_sheet(/*dispatch=*/ NULL); ?>
127 +
128 + <div style="display: none">
129 + <div id="tags-input"></div> <!-- avoid JS error from WP 2.5 bug -->
130 + </div>
131 + <?php
132 + endif;
133 + } /* FeedWordPressSyndicationPage::display () */
134 +
135 + function bleg_thanks ($page, $box = NULL) {
136 + ?>
137 + <div class="donation-thanks">
138 + <h4>Thank you!</h4>
139 + <p><strong>Thank you</strong> for your contribution to <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a> development.
140 + Your generous gifts make ongoing support and development for
141 + FeedWordPress possible.</p>
142 + <p>If you have any questions about FeedWordPress, or if there
143 + is anything I can do to help make FeedWordPress more useful for
144 + you, please <a href="http://feedwordpress.radgeek.com/contact">contact me</a>
145 + and let me know what you're thinking about.</p>
146 + <p class="signature">&#8212;<a href="http://radgeek.com/">Charles Johnson</a>, Developer, <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>.</p>
147 + </div>
148 + <?php
149 + } /* FeedWordPressSyndicationPage::bleg_thanks () */
150 +
151 + function bleg_box ($page, $box = NULL) {
152 + ?>
153 +<div class="donation-form">
154 +<h4>Keep FeedWordPress improving</h4>
155 +<form action="https://www.paypal.com/cgi-bin/webscr" accept-charset="UTF-8" method="post"><div>
156 +<p><a href="http://feedwordpress.radgeek.com/">FeedWordPress</a> makes syndication
157 +simple and empowers you to stream content from all over the web into your
158 +WordPress hub. That's got to be worth a few lattes. If you're finding FWP useful,
159 +<a href="http://feedwordpress.radgeek.com/donation/">a modest gift</a>
160 +is the best way to support steady progress on development, enhancements,
161 +support, and documentation.</p>
162 +<div class="donate">
163 +<input type="hidden" name="business" value="commerce@radgeek.com" />
164 +<input type="hidden" name="cmd" value="_xclick" />
165 +<input type="hidden" name="item_name" value="FeedWordPress donation" />
166 +<input type="hidden" name="no_shipping" value="1" />
167 +<input type="hidden" name="return" value="<?php bloginfo('url'); ?>/wp-admin/admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>&amp;paid=yes" />
168 +<input type="hidden" name="currency_code" value="USD" />
169 +<input type="hidden" name="notify_url" value="http://feedwordpress.radgeek.com/ipn/donation" />
170 +<input type="hidden" name="custom" value="1" />
171 +<input type="image" name="submit" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" alt="Donate through PayPal" />
172 +</div>
173 +</div></form>
174 +
175 +<p>You can make a gift online (or
176 +<a href="http://feedwordpress.radgeek.com/donation">set up an automatic
177 +regular donation</a>) using an existing PayPal account or any major credit card.</p>
178 +
179 +<div class="sod-off">
180 +<form style="text-align: center" action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>" method="POST"><div>
181 +<input class="button-primary" type="submit" name="maybe_later" value="Maybe Later" />
182 +<input class="button-secondary" type="submit" name="go_away" value="Dismiss" />
183 +</div></form>
184 +</div>
185 +</div> <!-- class="donation-form" -->
186 + <?php
187 + } /* FeedWordPressSyndicationPage::bleg_box () */
188 +
189 + /**
190 + * Override the default display of a save-settings button and replace
191 + * it with nothing.
192 + */
193 + function interstitial () {
194 + /* NOOP */
195 + } /* FeedWordPressSyndicationPage::interstitial() */
196 +} /* class FeedWordPressSyndicationPage */
197 +
198 +function fwp_dashboard_update_if_requested () {
199 + global $wpdb;
200 +
201 + if (isset($_POST['update']) or isset($_POST['action']) or isset($_POST['update_uri'])) :
202 + $fwp_update_invoke = 'post';
203 + else :
204 + $fwp_update_invoke = 'get';
205 + endif;
206 +
207 + $update_set = array();
208 + if (isset($_POST['link_ids']) and is_array($_POST['link_ids']) and ($_POST['action']==FWP_UPDATE_CHECKED)) :
209 + $targets = $wpdb->get_results("
210 + SELECT * FROM $wpdb->links
211 + WHERE link_id IN (".implode(",",$_POST['link_ids']).")
212 + ");
213 + if (is_array($targets)) :
214 + foreach ($targets as $target) :
215 + $update_set[] = $target->link_rss;
216 + endforeach;
217 + else : // This should never happen
218 + FeedWordPress::critical_bug('fwp_syndication_manage_page::targets', $targets, __LINE__);
219 + endif;
220 + elseif (isset($_POST['update_uri'])) :
221 + $update_set[] = $_POST['update_uri'];
222 + endif;
223 +
224 + shuffle($update_set); // randomize order for load balancing purposes...
225 + if ($fwp_update_invoke != 'get' and count($update_set) > 0) : // Only do things with side-effects for HTTP POST or command line
226 + $feedwordpress = new FeedWordPress;
227 + add_action('feedwordpress_check_feed', 'update_feeds_mention');
228 + add_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3);
229 +
230 + $crash_dt = (int) get_option('feedwordpress_update_time_limit');
231 + if ($crash_dt > 0) :
232 + $crash_ts = time() + $crash_dt;
233 + else :
234 + $crash_ts = NULL;
235 + endif;
236 +
237 + if (fwp_test_wp_version(FWP_SCHEMA_25)) :
238 + echo "<div class=\"youare\">\n";
239 + else :
240 + echo "<div class=\"updated\">\n";
241 + endif;
242 + echo "<ul>\n";
243 + $tdelta = NULL;
244 + foreach ($update_set as $uri) :
245 + if (!is_null($crash_ts) and (time() > $crash_ts)) :
246 + echo "<li><p><strong>Further updates postponed:</strong> update time limit of ".$crash_dt." second".(($crash_dt==1)?"":"s")." exceeded.</p></li>";
247 + break;
248 + endif;
249 +
250 + if ($uri == '*') : $uri = NULL; endif;
251 + $delta = $feedwordpress->update($uri, $crash_ts);
252 + if (!is_null($delta)) :
253 + if (is_null($tdelta)) :
254 + $tdelta = $delta;
255 + else :
256 + $tdelta['new'] += $delta['new'];
257 + $tdelta['updated'] += $delta['updated'];
258 + endif;
259 + else :
260 + echo "<li><p><strong>Error:</strong> There was a problem updating <a href=\"$uri\">$uri</a></p></li>\n";
261 + endif;
262 + endforeach;
263 + echo "</ul>\n";
264 +
265 + if (!is_null($tdelta)) :
266 + $mesg = array();
267 + if (isset($delta['new'])) : $mesg[] = ' '.$tdelta['new'].' new posts were syndicated'; endif;
268 + if (isset($delta['updated'])) : $mesg[] = ' '.$tdelta['updated'].' existing posts were updated'; endif;
269 + echo "<p>Update complete.".implode(' and', $mesg)."</p>";
270 + echo "\n"; flush();
271 + endif;
272 + echo "</div> <!-- class=\"updated\" -->\n";
273 + endif;
274 +}
275 +
276 +function fwp_syndication_manage_page_add_feed_box ($object = NULL, $box = NULL) {
277 + ?>
278 + <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>" method="post">
279 + <div>
280 + <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
281 + <label for="add-uri">Website or feed:</label>
282 + <input type="text" name="lookup" id="add-uri" value="URI" size="64" />
283 + <input type="hidden" name="action" value="feedfinder" />
284 + </div>
285 + <div class="submit"><input type="submit" value="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
286 + </form>
287 + <?php
288 +}
289 +
290 +define('FEEDWORDPRESS_BLEG_MAYBE_LATER_OFFSET', (60 /*sec/min*/ * 60 /*min/hour*/ * 24 /*hour/day*/ * 31 /*days*/));
291 +define('FEEDWORDPRESS_BLEG_ALREADY_PAID_OFFSET', (60 /*sec/min*/ * 60 /*min/hour*/ * 24 /*hour/day*/ * 183 /*days*/));
292 +function fwp_syndication_manage_page_update_box ($object = NULL, $box = NULL) {
293 + $bleg_box_hidden = null;
294 + if (isset($_POST['maybe_later'])) :
295 + $bleg_box_hidden = time() + FEEDWORDPRESS_BLEG_MAYBE_LATER_OFFSET;
296 + elseif (isset($_REQUEST['paid']) and $_REQUEST['paid']) :
297 + $bleg_box_hidden = time() + FEEDWORDPRESS_BLEG_ALREADY_PAID_OFFSET;
298 + elseif (isset($_POST['go_away'])) :
299 + $bleg_box_hidden = 'permanent';
300 + endif;
301 +
302 + if (!is_null($bleg_box_hidden)) :
303 + update_option('feedwordpress_bleg_box_hidden', $bleg_box_hidden);
304 + else :
305 + $bleg_box_hidden = get_option('feedwordpress_bleg_box_hidden');
306 + endif;
307 +?>
308 + <?php
309 + $bleg_box_ready = (!$bleg_box_hidden or (is_numeric($bleg_box_hidden) and $bleg_box_hidden < time()));
310 + if (isset($_REQUEST['paid']) and $_REQUEST['paid']) :
311 + $object->bleg_thanks($subject, $box);
312 + elseif ($bleg_box_ready) :
313 + $object->bleg_box($object, $box);
314 + endif;
315 + ?>
316 +
317 + <form
318 + action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>"
319 + method="POST"
320 + class="update-form<?php if ($bleg_box_ready) : ?> with-donation<?php endif; ?>"
321 + >
322 + <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
323 + <p>Check currently scheduled feeds for new and updated posts.</p>
324 +
325 + <?php
326 + fwp_dashboard_update_if_requested();
327 +
328 + if (!get_option('feedwordpress_automatic_updates')) :
329 + ?>
330 + <p class="heads-up"><strong>Note:</strong> Automatic updates are currently turned
331 + <strong>off</strong>. New posts from your feeds will not be syndicated
332 + until you manually check for them here. You can turn on automatic
333 + updates under <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?>/feeds-page.php">Feed &amp; Update Settings<a></a>.</p>
334 + <?php
335 + endif;
336 + ?>
337 +
338 + <div class="submit"><input type="hidden" name="update_uri" value="*" /><input class="button-primary" type="submit" name="update" value="Update" /></div>
339 +
340 + <br style="clear: both" />
341 + </form>
342 +<?php
343 +} /* function fwp_syndication_manage_page_update_box () */
344 +
345 +function fwp_syndication_manage_page_links_box ($object = NULL, $box = NULL) {
346 + $links = FeedWordPress::syndicated_links();
347 +?>
348 + <form id="syndicated-links" action="admin.php?page=<?php print $GLOBALS['fwp_path']; ?>/<?php echo basename(__FILE__); ?>" method="post">
349 + <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
350 +
351 +<?php $alt_row = true; ?>
352 +
353 + <?php if (fwp_test_wp_version(FWP_SCHEMA_25)) : ?>
354 + <div class="tablenav">
355 + <div class="alignright">
356 + <label for="add-uri">Add new source:</label>
357 + <input type="text" name="lookup" id="add-uri" value="Website or feed URI" />
358 + <?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); ?>
359 +
360 + <input type="hidden" name="action" value="feedfinder" />
361 + <input type="submit" class="button-secondary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
362 +
363 +<?php if (count($links) > 0) : ?>
364 + <div class="alignleft">
365 + <input class="button-secondary" type="submit" name="action" value="<?php print FWP_UPDATE_CHECKED; ?>" />
366 + <input class="button-secondary delete" type="submit" class="delete" name="action" value="<?php print FWP_UNSUB_CHECKED; ?>" />
367 + </div>
368 +<?php endif; ?>
369 +
370 + <br class="clear" />
371 + </div>
372 + <br class="clear" />
373 +
374 + <table class="widefat">
375 + <?php else : ?>
376 + <table width="100%" cellpadding="3" cellspacing="3">
377 + <?php endif; ?>
378 +<thead>
379 +<tr>
380 +<th class="check-column" scope="col"><?php if (fwp_test_wp_version(FWP_SCHEMA_25)) : ?>
381 +<input type="checkbox" <?php if (fwp_test_wp_version(FWP_SCHEMA_25, FWP_SCHEMA_26)) : ?>onclick="checkAll(document.getElementById('syndicated-links'));"<?php endif; ?> />
382 +<?php endif; ?></th>
383 +<th scope="col"><?php _e('Name'); ?></th>
384 +<th scope="col"><?php _e('Feed'); ?></th>
385 +<th scope="col"><?php _e('Updated'); ?></th>
386 +</tr>
387 +</thead>
388 +
389 +<tbody>
390 +<?php if (count($links) > 0): foreach ($links as $link):
391 + $alt_row = !$alt_row; ?>
392 +<tr<?php echo ($alt_row?' class="alternate"':''); ?>>
393 +<th class="check-column" scope="row"><input type="checkbox" name="link_ids[]" value="<?php echo $link->link_id; ?>" /></th>
394 +<?php
395 + if (strlen($link->link_rss) > 0):
396 + $caption=__('Switch Feed');
397 + else :
398 + $caption=__('Find Feed');
399 + endif;
400 +?>
401 +<td>
402 +<strong><a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/feeds-page.php&amp;link_id=<?php echo $link->link_id; ?>"><?php echo esc_html($link->link_name); ?></a></strong>
403 +<div class="row-actions"><div><strong>Settings &gt;</strong>
404 +<a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/feeds-page.php&amp;link_id=<?php echo $link->link_id; ?>"><?php _e('Feed'); ?></a>
405 +| <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/posts-page.php&amp;link_id=<?php echo $link->link_id; ?>"><?php _e('Posts'); ?></a>
406 +| <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/authors-page.php&amp;link_id=<?php echo $link->link_id; ?>"><?php _e('Authors'); ?></a>
407 +| <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/categories-page.php&amp;link_id=<?php echo $link->link_id; ?>"><?php print htmlspecialchars(__('Categories'.FEEDWORDPRESS_AND_TAGS)); ?></a></div>
408 +<div><strong>Actions &gt;</strong>
409 +<a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link->link_id; ?>&amp;action=feedfinder"><?php echo $caption; ?></a>
410 +| <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link->link_id; ?>&amp;action=Unsubscribe"><?php _e('Unsubscribe'); ?></a>
411 +| <a href="<?php echo esc_html($link->link_url); ?>"><?php _e('View')?></a></div>
412 +</div>
413 +</td>
414 + <?php if (strlen($link->link_rss) > 0): ?>
415 + <td><a href="<?php echo esc_html($link->link_rss); ?>"><?php echo esc_html(feedwordpress_display_url($link->link_rss, 32)); ?></a></td>
416 + <?php else: ?>
417 + <td style="background-color:#FFFFD0"><p><strong>no
418 + feed assigned</strong></p></td>
419 + <?php endif; ?>
420 +
421 + <td><?php
422 + $sLink = new SyndicatedLink($link->link_id);
423 + if (isset($sLink->settings['update/last'])) :
424 + print fwp_time_elapsed($sLink->settings['update/last']);
425 + else :
426 + _e('None yet');
427 + endif;
428 +
429 + print "<div style='font-style:italic;size:0.9em'>Ready for next update ";
430 + if (isset($sLink->settings['update/ttl']) and is_numeric($sLink->settings['update/ttl'])) :
431 + if (isset($sLink->settings['update/timed']) and $sLink->settings['update/timed']=='automatically') :
432 + $next = $sLink->settings['update/last'] + ((int) $sLink->settings['update/ttl'] * 60);
433 + print fwp_time_elapsed($next);
434 + if (FEEDWORDPRESS_DEBUG) : print " [".(($next-time())/60)." minutes]"; endif;
435 + else :
436 + echo "every ".$sLink->settings['update/ttl']." minute".(($sLink->settings['update/ttl']!=1)?"s":"");
437 + endif;
438 + else:
439 + echo "as soon as possible";
440 + endif;
441 + unset($sLink);
442 + print "</div>";
443 +?>
444 + </td>
445 + </tr>
446 +<?php
447 + endforeach;
448 + else :
449 +?>
450 +<tr><td colspan="<?php print $span+2; ?>"><p>There are no websites currently listed for syndication.</p></td></tr>
451 +<?php
452 + endif;
453 +?>
454 +</tbody>
455 +</table>
456 +
457 +<?php if (count($links) > 0 and fwp_test_wp_version(0, FWP_SCHEMA_25)) : ?>
458 +<br/><hr/>
459 +<div class="submit"><input type="submit" class="delete" name="action" value="<?php print FWP_UNSUB_CHECKED; ?>" />
460 +<input type="submit" name="action" value="<?php print FWP_UPDATE_CHECKED; ?>" /></div>
461 +<?php endif; ?>
462 +
463 + </form>
464 +<?php
465 +} /* function fwp_syndication_manage_page_links_box() */
466 +
467 +function fwp_feedfinder_page () {
468 + global $post_source;
469 +
470 + $post_source = 'feedwordpress_feeds';
471 +
472 + // With action=feedfinder, this goes directly to the feedfinder page
473 + include_once(dirname(__FILE__) . '/feeds-page.php');
474 + return false;
475 +} /* function fwp_feedfinder_page () */
476 +
477 +function fwp_switchfeed_page () {
478 + global $wpdb, $wp_db_version;
479 + global $fwp_post;
480 +
481 + // If this is a POST, validate source and user credentials
482 + FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_switchfeed', /*capability=*/ 'manage_links');
483 +
484 + $changed = false;
485 + if (!isset($fwp_post['Cancel'])):
486 + if (isset($fwp_post['save_link_id']) and ($fwp_post['save_link_id']=='*')) :
487 + $changed = true;
488 + $link_id = FeedWordPress::syndicate_link($fwp_post['feed_title'], $fwp_post['feed_link'], $fwp_post['feed']);
489 + if ($link_id):
490 + $existingLink = new SyndicatedLink($link_id);
491 + ?>
492 +<div class="updated"><p><a href="<?php print $fwp_post['feed_link']; ?>"><?php print esc_html($fwp_post['feed_title']); ?></a>
493 +has been added as a contributing site, using the feed at
494 +&lt;<a href="<?php print $fwp_post['feed']; ?>"><?php print esc_html($fwp_post['feed']); ?></a>&gt;.
495 +| <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>
496 +<?php else: ?>
497 +<div class="updated"><p>There was a problem adding the feed. [SQL: <?php echo esc_html(mysql_error()); ?>]</p></div>
498 +<?php endif;
499 + elseif (isset($fwp_post['save_link_id'])):
500 + $existingLink = new SyndicatedLink($fwp_post['save_link_id']);
501 + $changed = $existingLink->set_uri($fwp_post['feed']);
502 +
503 + if ($changed):
504 + $home = $existingLink->homepage(/*from feed=*/ false);
505 + $name = $existingLink->name(/*from feed=*/ false);
506 + ?>
507 +<div class="updated"><p>Feed for <a href="<?php echo esc_html($home); ?>"><?php echo esc_html($name); ?></a>
508 +updated to &lt;<a href="<?php echo esc_html($fwp_post['feed']); ?>"><?php echo esc_html($fwp_post['feed']); ?></a>&gt;.</p></div>
509 + <?php
510 + endif;
511 + endif;
512 + endif;
513 +
514 + if (isset($existingLink)) :
515 + do_action('feedwordpress_admin_switchfeed', $fwp_post['feed'], $existingLink);
516 + endif;
517 +
518 + if (!$changed) :
519 + ?>
520 +<div class="updated"><p>Nothing was changed.</p></div>
521 + <?php
522 + endif;
523 + return true; // Continue
524 +}
525 +
526 +function fwp_multidelete_page () {
527 + global $wpdb;
528 +
529 + // If this is a POST, validate source and user credentials
530 + FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
531 +
532 + $link_ids = (isset($_REQUEST['link_ids']) ? $_REQUEST['link_ids'] : array());
533 + if (isset($_REQUEST['link_id'])) : array_push($link_ids, $_REQUEST['link_id']); endif;
534 +
535 + if (isset($GLOBALS['fwp_post']['confirm']) and $GLOBALS['fwp_post']['confirm']=='Delete'):
536 + if (isset($GLOBALS['fwp_post']['link_action']) and is_array($GLOBALS['fwp_post']['link_action'])) :
537 + $actions = $GLOBALS['fwp_post']['link_action'];
538 + else :
539 + $actions = array();
540 + endif;
541 +
542 + foreach ($actions as $link_id => $what) :
543 + $do_it[$what][] = $link_id;
544 + endforeach;
545 +
546 + $alter = array();
547 + if (count($do_it['hide']) > 0) :
548 + $hidem = "(".implode(', ', $do_it['hide']).")";
549 + $alter[] = "
550 + UPDATE $wpdb->links
551 + SET link_visible = 'N'
552 + WHERE link_id IN {$hidem}
553 + ";
554 + endif;
555 +
556 + if (count($do_it['nuke']) > 0) :
557 + $nukem = "(".implode(', ', $do_it['nuke']).")";
558 +
559 + // Make a list of the items syndicated from this feed...
560 + $post_ids = $wpdb->get_col("
561 + SELECT post_id FROM $wpdb->postmeta
562 + WHERE meta_key = 'syndication_feed_id'
563 + AND meta_value IN {$nukem}
564 + ");
565 +
566 + // ... and kill them all
567 + if (count($post_ids) > 0) :
568 + foreach ($post_ids as $post_id) :
569 + wp_delete_post($post_id);
570 + endforeach;
571 + endif;
572 +
573 + $alter[] = "
574 + DELETE FROM $wpdb->links
575 + WHERE link_id IN {$nukem}
576 + ";
577 + endif;
578 +
579 + if (count($do_it['delete']) > 0) :
580 + $deletem = "(".implode(', ', $do_it['delete']).")";
581 +
582 + // Make the items syndicated from this feed appear to be locally-authored
583 + $alter[] = "
584 + DELETE FROM $wpdb->postmeta
585 + WHERE meta_key = 'syndication_feed_id'
586 + AND meta_value IN {$deletem}
587 + ";
588 +
589 + // ... and delete the links themselves.
590 + $alter[] = "
591 + DELETE FROM $wpdb->links
592 + WHERE link_id IN {$deletem}
593 + ";
594 + endif;
595 +
596 + $errs = array(); $success = array ();
597 + foreach ($alter as $sql) :
598 + $result = $wpdb->query($sql);
599 + if (!$result):
600 + $errs[] = mysql_error();
601 + endif;
602 + endforeach;
603 +
604 + if (count($alter) > 0) :
605 + echo "<div class=\"updated\">\n";
606 + if (count($errs) > 0) :
607 + echo "There were some problems processing your ";
608 + echo "unsubscribe request. [SQL: ".implode('; ', $errs)."]";
609 + else :
610 + echo "Your unsubscribe request(s) have been processed.";
611 + endif;
612 + echo "</div>\n";
613 + endif;
614 +
615 + return true; // Continue on to Syndicated Sites listing
616 + else :
617 + $targets = $wpdb->get_results("
618 + SELECT * FROM $wpdb->links
619 + WHERE link_id IN (".implode(",",$link_ids).")
620 + ");
621 +?>
622 +<form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
623 +<div class="wrap">
624 +<?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
625 +<input type="hidden" name="action" value="Unsubscribe" />
626 +<input type="hidden" name="confirm" value="Delete" />
627 +
628 +<h2>Unsubscribe from Syndicated Links:</h2>
629 +<?php foreach ($targets as $link) :
630 + $link_url = esc_html($link->link_url);
631 + $link_name = esc_html($link->link_name);
632 + $link_description = esc_html($link->link_description);
633 + $link_rss = esc_html($link->link_rss);
634 +?>
635 +<fieldset>
636 +<legend><?php echo $link_name; ?></legend>
637 +<table class="editform" width="100%" cellspacing="2" cellpadding="5">
638 +<tr><th scope="row" width="20%"><?php _e('Feed URI:') ?></th>
639 +<td width="80%"><a href="<?php echo $link_rss; ?>"><?php echo $link_rss; ?></a></td></tr>
640 +<tr><th scope="row" width="20%"><?php _e('Short description:') ?></th>
641 +<td width="80%"><?php echo $link_description; ?></span></td></tr>
642 +<tr><th width="20%" scope="row"><?php _e('Homepage:') ?></th>
643 +<td width="80%"><a href="<?php echo $link_url; ?>"><?php echo $link_url; ?></a></td></tr>
644 +<tr style="vertical-align:top"><th width="20%" scope="row">Subscription <?php _e('Options') ?>:</th>
645 +<td width="80%"><ul style="margin:0; padding: 0; list-style: none">
646 +<li><input type="radio" id="hide-<?php echo $link->link_id; ?>"
647 +name="link_action[<?php echo $link->link_id; ?>]" value="hide" />
648 +<label for="hide-<?php echo $link->link_id; ?>">Turn off the subscription for this
649 +syndicated link<br/><span style="font-size:smaller">(Keep the feed information
650 +and all the posts from this feed in the database, but don't syndicate any
651 +new posts from the feed.)</span></label></li>
652 +<li><input type="radio" id="nuke-<?php echo $link->link_id; ?>"
653 +name="link_action[<?php echo $link->link_id; ?>]" value="nuke" />
654 +<label for="nuke-<?php echo $link->link_id; ?>">Delete this syndicated link and all the
655 +posts that were syndicated from it</label></li>
656 +<li><input type="radio" id="delete-<?php echo $link->link_id; ?>"
657 +name="link_action[<?php echo $link->link_id; ?>]" value="delete" />
658 +<label for="delete-<?php echo $link->link_id; ?>">Delete this syndicated link, but
659 +<em>keep</em> posts that were syndicated from it (as if they were authored
660 +locally).</label></li>
661 +<li><input type="radio" id="nothing-<?php echo $link->link_id; ?>"
662 +name="link_action[<?php echo $link->link_id; ?>]" value="nothing" />
663 +<label for="nothing-<?php echo $link->link_id; ?>">Keep this feed as it is. I changed
664 +my mind.</label></li>
665 +</ul>
666 +</table>
667 +</fieldset>
668 +<?php endforeach; ?>
669 +
670 +<div class="submit">
671 +<input class="delete" type="submit" name="submit" value="<?php _e('Unsubscribe from selected feeds &raquo;') ?>" />
672 +</div>
673 +</div>
674 +<?php
675 + return false; // Don't continue on to Syndicated Sites listing
676 + endif;
677 +}
678 +
679 + $syndicationPage = new FeedWordPressSyndicationPage;
5 680 $syndicationPage->display();
681 +