forked from radgeek/feedwordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeedwordpresssyndicationpage.class.php
More file actions
1261 lines (1085 loc) · 45.4 KB
/
feedwordpresssyndicationpage.class.php
File metadata and controls
1261 lines (1085 loc) · 45.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require_once(dirname(__FILE__) . '/admin-ui.php');
require_once(dirname(__FILE__) . '/feedfinder.class.php');
################################################################################
## ADMIN MENU ADD-ONS: implement Dashboard management pages ####################
################################################################################
define('FWP_UPDATE_CHECKED', 'Update Checked');
define('FWP_UNSUB_CHECKED', 'Unsubscribe');
define('FWP_DELETE_CHECKED', 'Delete');
define('FWP_RESUB_CHECKED', 'Re-subscribe');
define('FWP_SYNDICATE_NEW', 'Add →');
define('FWP_UNSUB_FULL', 'Unsubscribe from selected feeds →');
define('FWP_CANCEL_BUTTON', '× Cancel');
define('FWP_CHECK_FOR_UPDATES', 'Update');
class FeedWordPressSyndicationPage extends FeedWordPressAdminPage {
public function __construct ($filename = NULL) {
parent::__construct('feedwordpresssyndication', /*link=*/ NULL);
// No over-arching form element
$this->dispatch = NULL;
if (is_null($filename)) :
$this->filename = __FILE__;
else :
$this->filename = $filename;
endif;
} /* FeedWordPressSyndicationPage constructor */
function has_link () { return false; }
var $_sources = NULL;
function sources ($visibility = 'Y') {
if (is_null($this->_sources)) :
$links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
$this->_sources = array("Y" => array(), "N" => array());
foreach ($links as $link) :
$this->_sources[$link->link_visible][] = $link;
endforeach;
endif;
$ret = (
array_key_exists($visibility, $this->_sources)
? $this->_sources[$visibility]
: $this->_sources
);
return $ret;
} /* FeedWordPressSyndicationPage::sources() */
function visibility_toggle () {
$sources = $this->sources('*');
$defaultVisibility = 'Y';
if ((count($this->sources('N')) > 0)
and (count($this->sources('Y'))==0)) :
$defaultVisibility = 'N';
endif;
$visibility = (
isset($_REQUEST['visibility'])
? $_REQUEST['visibility']
: $defaultVisibility
);
return $visibility;
} /* FeedWordPressSyndicationPage::visibility_toggle() */
function show_inactive () {
return ($this->visibility_toggle() == 'N');
}
/**
* sanitize_ids: Protect id numbers from untrusted sources (POST array etc.)
* from possibility of SQLi attacks. Runs everything through an intval filter
* and then for good measure through esc_sql()
*
* @param array $link_ids An array of one or more putative link IDs
* @return array
*/
public function sanitize_ids_sql ($link_ids) {
$link_ids = array_map(
'esc_sql',
array_map(
'intval',
$link_ids
)
);
return $link_ids;
} /* FeedWordPressSyndicationPage::sanitize_ids_sql () */
/**
* requested_link_ids_sql ()
*
* @return string An SQL list literal containing the link IDs, sanitized
* and escaped for direct use in MySQL queries.
*
* @uses sanitize_ids_sql()
*/
public function requested_link_ids_sql () {
// Multiple link IDs passed in link_ids[]=... . . .
$link_ids = (isset($_REQUEST['link_ids']) ? $_REQUEST['link_ids'] : array());
// Or single in link_id=...
if (isset($_REQUEST['link_id'])) : array_push($link_ids, $_REQUEST['link_id']); endif;
// Filter for safe use in MySQL queries.
$link_ids = $this->sanitize_ids_sql($link_ids);
// Convert to MySQL list literal.
return "('".implode("', '", $link_ids)."')";
} /* FeedWordPressSyndicationPage::requested_link_ids_sql () */
function updates_requested () {
global $wpdb;
if (isset($_POST['update']) or isset($_POST['action']) or isset($_POST['update_uri'])) :
// Only do things with side-effects for HTTP POST or command line
$fwp_update_invoke = 'post';
else :
$fwp_update_invoke = 'get';
endif;
$update_set = array();
if ($fwp_update_invoke != 'get') :
if (is_array(MyPHP::post('link_ids'))
and (MyPHP::post('action')==FWP_UPDATE_CHECKED)) :
// Get single link ID or multiple link IDs from REQUEST parameters
// if available. Sanitize values for MySQL.
$link_list = $this->requested_link_ids_sql();
// $link_list has previously been sanitized for html by self::requested_link_ids_sql
$targets = $wpdb->get_results("
SELECT * FROM $wpdb->links
WHERE link_id IN ${link_list}
");
if (is_array($targets)) :
foreach ($targets as $target) :
$update_set[] = $target->link_rss;
endforeach;
else : // This should never happen
FeedWordPressDiagnostic::critical_bug('fwp_syndication_manage_page::targets', $targets, __LINE__, __FILE__);
endif;
elseif (!is_null(MyPHP::post('update_uri'))) :
$targets = MyPHP::post('update_uri');
if (!is_array($targets)) :
$targets = array($targets);
endif;
$first = each($targets);
if (!is_numeric($first['key'])) : // URLs in keys
$targets = array_keys($targets);
endif;
$update_set = $targets;
endif;
endif;
return $update_set;
}
function accept_multiadd () {
global $fwp_post;
if (isset($fwp_post['cancel']) and $fwp_post['cancel']==__(FWP_CANCEL_BUTTON)) :
return true; // Continue ....
endif;
// If this is a POST, validate source and user credentials
FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
$in = (isset($fwp_post['multilookup']) ? $fwp_post['multilookup'] : '')
.(isset($fwp_post['opml_lookup']) ? $fwp_post['opml_lookup'] : '');
if (isset($fwp_post['confirm']) and $fwp_post['confirm']=='multiadd') :
$chex = $fwp_post['multilookup'];
$added = array(); $errors = array();
foreach ($chex as $feed) :
if (isset($feed['add']) and $feed['add']=='yes') :
// Then, add in the URL.
$link_id = FeedWordPress::syndicate_link(
$feed['title'],
$feed['link'],
$feed['url']
);
if ($link_id and !is_wp_error($link_id)):
$added[] = $link_id;
else :
$errors[] = array($feed['url'], $link_id);
endif;
endif;
endforeach;
print "<div class='updated'>\n";
print "<p>Added ".count($added)." new syndicated sources.</p>";
if (count($errors) > 0) :
print "<p>FeedWordPress encountered errors trying to add the following sources:</p>
<ul>\n";
foreach ($errors as $err) :
$url = $err[0];
$short = esc_html(feedwordpress_display_url($url));
$url = esc_html($url);
$wp = $err[1];
if (is_wp_error($err[1])) :
$error = $err[1];
$mesg = " (<code>".$error->get_error_messages()."</code>)";
else :
$mesg = '';
endif;
print "<li><a href='$url'>$short</a>$mesg</li>\n";
endforeach;
print "</ul>\n";
endif;
print "</div>\n";
elseif (is_array($in) or strlen($in) > 0) :
add_meta_box(
/*id=*/ 'feedwordpress_multiadd_box',
/*title=*/ __('Add Feeds'),
/*callback=*/ array($this, 'multiadd_box'),
/*page=*/ $this->meta_box_context(),
/*context =*/ $this->meta_box_context()
);
endif;
return true; // Continue...
}
function display_multiadd_line ($line) {
$short_feed = esc_html(feedwordpress_display_url($line['feed']));
$feed = esc_html($line['feed']);
$link = esc_html($line['link']);
$title = esc_html($line['title']);
$checked = $line['checked'];
$i = esc_html($line['i']);
print "<li><label><input type='checkbox' name='multilookup[$i][add]' value='yes' $checked />
$title</label> · <a href='$feed'>$short_feed</a>";
if (isset($line['extra'])) :
print " · ".esc_html($line['extra']);
endif;
print "<input type='hidden' name='multilookup[$i][url]' value='$feed' />
<input type='hidden' name='multilookup[$i][link]' value='$link' />
<input type='hidden' name='multilookup[$i][title]' value='$title' />
</li>\n";
flush();
}
function multiadd_box ($page, $box = NULL) {
global $fwp_post;
$localData = NULL;
if (isset($_FILES['opml_upload']['name']) and
(strlen($_FILES['opml_upload']['name']) > 0)) :
$in = 'tag:localhost';
/*FIXME: check whether $_FILES['opml_upload']['error'] === UPLOAD_ERR_OK or not...*/
$localData = file_get_contents($_FILES['opml_upload']['tmp_name']);
$merge_all = true;
elseif (isset($fwp_post['multilookup'])) :
$in = $fwp_post['multilookup'];
$merge_all = false;
elseif (isset($fwp_post['opml_lookup'])) :
$in = $fwp_post['opml_lookup'];
$merge_all = true;
else :
$in = '';
$merge_all = false;
endif;
if (strlen($in) > 0) :
$lines = preg_split(
"/\s+/",
$in,
/*no limit soldier*/ -1,
PREG_SPLIT_NO_EMPTY
);
$i = 0;
?>
<form id="multiadd-form" action="<?php print $this->form_action(); ?>" method="post">
<div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
<input type="hidden" name="multiadd" value="<?php print FWP_SYNDICATE_NEW; ?>" />
<input type="hidden" name="confirm" value="multiadd" />
<input type="hidden" name="multiadd" value="<?php print FWP_SYNDICATE_NEW; ?>" />
<input type="hidden" name="confirm" value="multiadd" /></div>
<div id="multiadd-status">
<p><img src="<?php print esc_url ( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
Looking up feed information...</p>
</div>
<div id="multiadd-buttons">
<input type="submit" class="button" name="cancel" value="<?php _e(FWP_CANCEL_BUTTON); ?>" />
<input type="submit" class="button-primary" value="<?php print _e('Subscribe to selected sources →'); ?>" />
</div>
<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>
<?php
print "<ul id=\"multiadd-list\">\n"; flush();
foreach ($lines as $line) :
$url = trim($line);
if (strlen($url) > 0) :
// First, use FeedFinder to check the URL.
if (is_null($localData)) :
$finder = new FeedFinder($url, /*verify=*/ false, /*fallbacks=*/ 1);
else :
$finder = new FeedFinder('tag:localhost', /*verify=*/ false, /*fallbacks=*/ 1);
$finder->upload_data($localData);
endif;
$feeds = array_values(
array_unique(
$finder->find()
)
);
$found = false;
if (count($feeds) > 0) :
foreach ($feeds as $feed) :
$pie = FeedWordPress::fetch($feed);
if (!is_wp_error($pie)) :
$found = true;
$short_feed = esc_html(feedwordpress_display_url($feed));
$feed = esc_html($feed);
$title = esc_html($pie->get_title());
$checked = ' checked="checked"';
$link = esc_html($pie->get_link());
$this->display_multiadd_line(array(
'feed' => $feed,
'title' => $pie->get_title(),
'link' => $pie->get_link(),
'checked' => ' checked="checked"',
'i' => $i,
));
$i++; // Increment field counter
if (!$merge_all) : // Break out after first find
break;
endif;
endif;
endforeach;
endif;
if (!$found) :
$this->display_multiadd_line(array(
'feed' => $url,
'title' => feedwordpress_display_url($url),
'extra' => " [FeedWordPress couldn't detect any feeds for this URL.]",
'link' => NULL,
'checked' => '',
'i' => $i,
));
$i++; // Increment field counter
endif;
endif;
endforeach;
print "</ul>\n";
?>
</form>
<script type="text/javascript">
jQuery(document).ready( function () {
// Hide it now that we're done.
jQuery('#multiadd-status').fadeOut(500 /*ms*/);
} );
</script>
<?php
endif;
$this->_sources = NULL; // Force reload of sources list
return true; // Continue
}
function display () {
global $wpdb;
global $fwp_post;
if (FeedWordPress::needs_upgrade()) :
fwp_upgrade_page();
return;
endif;
$cont = true;
$dispatcher = array(
"feedfinder" => 'fwp_feedfinder_page',
FWP_SYNDICATE_NEW => 'fwp_feedfinder_page',
"switchfeed" => 'fwp_switchfeed_page',
FWP_UNSUB_CHECKED => 'multidelete_page',
FWP_DELETE_CHECKED => 'multidelete_page',
'Unsubscribe' => 'multidelete_page',
FWP_RESUB_CHECKED => 'multiundelete_page',
);
$act = MyPHP::request('action');
if (isset($dispatcher[$act])) :
$method = $dispatcher[$act];
if (method_exists($this, $method)) :
$cont = $this->{$method}();
else :
$cont = call_user_func($method);
endif;
elseif (isset($fwp_post['multiadd']) and $fwp_post['multiadd']==FWP_SYNDICATE_NEW) :
$cont = $this->accept_multiadd($fwp_post);
endif;
if ($cont):
$links = $this->sources('Y');
$potential_updates = (!$this->show_inactive() and (count($this->sources('Y')) > 0));
$this->open_sheet('Syndicated Sites');
?>
<div id="post-body">
<?php
if ($potential_updates
or (count($this->updates_requested()) > 0)) :
add_meta_box(
/*id=*/ 'feedwordpress_update_box',
/*title=*/ __('Update feeds now'),
/*callback=*/ 'fwp_syndication_manage_page_update_box',
/*page=*/ $this->meta_box_context(),
/*context =*/ $this->meta_box_context()
);
endif;
add_meta_box(
/*id=*/ 'feedwordpress_feeds_box',
/*title=*/ __('Syndicated sources'),
/*callback=*/ array($this, 'syndicated_sources_box'),
/*page=*/ $this->meta_box_context(),
/*context =*/ $this->meta_box_context()
);
do_action('feedwordpress_admin_page_syndication_meta_boxes', $this);
?>
<div class="metabox-holder">
<?php
do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
?>
</div> <!-- class="metabox-holder" -->
</div> <!-- id="post-body" -->
<?php $this->close_sheet(/*dispatch=*/ NULL); ?>
<div style="display: none">
<div id="tags-input"></div> <!-- avoid JS error from WP 2.5 bug -->
</div>
<?php
endif;
} /* FeedWordPressSyndicationPage::display () */
function dashboard_box ($page, $box = NULL) {
$links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
$sources = $this->sources('*');
$visibility = 'Y';
$hrefPrefix = $this->form_action();
$activeHref = $hrefPrefix.'&visibility=Y';
$inactiveHref = $hrefPrefix.'&visibility=N';
$lastUpdate = get_option('feedwordpress_last_update_all', NULL);
$automatic_updates = get_option('feedwordpress_automatic_updates', NULL);
if ('init'==$automatic_updates) :
$update_setting = 'automatically before page loads';
elseif ('shutdown'==$automatic_updates) :
$update_setting = 'automatically after page loads';
else :
$update_setting = 'using a cron job or manual check-ins';
endif;
// Hey ho, let's go...
?>
<div style="float: left; background: #F5F5F5; padding-top: 5px; padding-right: 5px;"><a href="<?php print $this->form_action(); ?>"><img src="<?php print esc_url(plugins_url( "feedwordpress.png", __FILE__ ) ); ?>" alt="" /></a></div>
<p class="info" style="margin-bottom: 0px; border-bottom: 1px dotted black;">Managed by <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>
<?php print FEEDWORDPRESS_VERSION; ?>.</p>
<?php if (FEEDWORDPRESS_BLEG) : ?>
<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
contribute to ongoing support and development with
<a href="http://feedwordpress.radgeek.com/donate/">a modest donation</a>.</p>
<br style="clear: left;" />
<?php endif; ?>
<div class="feedwordpress-actions">
<h4>Updates</h4>
<ul class="options">
<li><strong>Scheduled:</strong> <?php print $update_setting; ?>
(<a href="<?php print $this->form_action('feeds-page.php'); ?>">change setting</a>)</li>
<li><?php if (!is_null($lastUpdate)) : ?>
<strong>Last checked:</strong> <?php print fwp_time_elapsed($lastUpdate); ?>
<?php else : ?>
<strong>Last checked:</strong> none yet
<?php endif; ?> </li>
</ul>
</div>
<div class="feedwordpress-stats">
<h4>Subscriptions</h4>
<table>
<tbody>
<tr class="first">
<td class="first b b-active"><a href="<?php print esc_html($activeHref); ?>"><?php print count($sources['Y']); ?></a></td>
<td class="t active"><a href="<?php print esc_html($activeHref); ?>">Active</a></td>
</tr>
<tr>
<td class="b b-inactive"><a href="<?php print esc_html($inactiveHref); ?>"><?php print count($sources['N']); ?></a></td>
<td class="t inactive"><a href="<?php print esc_html($inactiveHref); ?>">Inactive</a></td>
</tr>
</table>
</div>
<div id="add-single-uri">
<?php if (count($sources['Y']) > 0) : ?>
<form id="check-for-updates" action="<?php print $this->form_action(); ?>" method="POST">
<div class="container"><input type="submit" class="button-primary" name"update" value="<?php print FWP_CHECK_FOR_UPDATES; ?>" />
<?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
<input type="hidden" name="update_uri" value="*" /></div>
</form>
<?php endif; ?>
<form id="syndicated-links" action="<?php print $hrefPrefix; ?>&visibility=<?php print $visibility; ?>" method="post">
<div class="container"><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
<label for="add-uri">Add:
<input type="text" name="lookup" id="add-uri" placeholder="Source URL"
value="Source URL" style="width: 55%;" /></label>
<?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); ?>
<input type="hidden" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" />
<input style="vertical-align: middle;" type="image" src="<?php print esc_url(plugins_url('plus.png', __FILE__)); ?>" alt="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
</form>
</div> <!-- id="add-single-uri" -->
<br style="clear: both;" />
<?php
} /* FeedWordPressSyndicationPage::dashboard_box () */
function syndicated_sources_box ($page, $box = NULL) {
$links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
$sources = $this->sources('*');
$visibility = $this->visibility_toggle();
$showInactive = $this->show_inactive();
$hrefPrefix = $this->form_action();
?>
<div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
<div class="tablenav">
<div id="add-multiple-uri" class="hide-if-js">
<form action="<?php print $hrefPrefix; ?>&visibility=<?php print $visibility; ?>" method="post">
<div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
<h4>Add Multiple Sources</h4>
<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>
<div><textarea name="multilookup" rows="8" cols="60"
style="vertical-align: top"></textarea></div>
<div style="border-top: 1px dotted black; padding-top: 10px">
<div class="alignright"><input type="submit" class="button-primary" name="multiadd" value="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
<div class="alignleft"><input type="button" class="button-secondary" name="action" value="<?php print FWP_CANCEL_BUTTON; ?>" id="turn-off-multiple-sources" /></div>
</div>
</form>
</div> <!-- id="add-multiple-uri" -->
<div id="upload-opml" style="float: right" class="hide-if-js">
<h4>Import source list</h4>
<p>You can import a list of sources in OPML format, either by providing
a URL for the OPML document, or by uploading a copy from your
computer.</p>
<form enctype="multipart/form-data" action="<?php print $hrefPrefix; ?>&visibility=<?php print $visibility; ?>" method="post">
<div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?><input type="hidden" name="MAX_FILE_SIZE" value="100000" /></div>
<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>
<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>
<div style="border-top: 1px dotted black; padding-top: 10px">
<div class="alignright"><input type="submit" class="button-primary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
<div class="alignleft"><input type="button" class="button-secondary" name="action" value="<?php print FWP_CANCEL_BUTTON; ?>" id="turn-off-opml-upload" /></div>
</div>
</form>
</div> <!-- id="upload-opml" -->
<div id="add-single-uri" class="alignright">
<form id="syndicated-links" action="<?php print $hrefPrefix; ?>&visibility=<?php print $visibility; ?>" method="post">
<div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
<ul class="subsubsub">
<li><label for="add-uri">New source:</label>
<input type="text" name="lookup" id="add-uri" value="Website or feed URI" />
<?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); FeedWordPressSettingsUI::magic_input_tip_js('opml-lookup'); ?>
<input type="hidden" name="action" value="feedfinder" />
<input type="submit" class="button-secondary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" />
<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 esc_url(plugins_url('down.png', __FILE__)); ?>" alt="" /> add multiple</a>
<span class="screen-reader-text"> or </span>
<a id="turn-on-opml-upload" href="#upload-opml"><img src="<?php print esc_url(plugins_url('plus.png', __FILE__)); ?>" alt="" style="vertical-align: middle" /> import source list</a></div>
</li>
</ul>
</form>
</div> <!-- class="alignright" -->
<div class="alignleft">
<?php
if (count($sources[$visibility]) > 0) :
$this->manage_page_links_subsubsub($sources, $showInactive);
endif;
?>
</div> <!-- class="alignleft" -->
</div> <!-- class="tablenav" -->
<form id="syndicated-links" action="<?php print $hrefPrefix; ?>&visibility=<?php print $visibility; ?>" method="post">
<div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
<?php if ($showInactive) : ?>
<div style="clear: right" class="alignright">
<p style="font-size: smaller; font-style: italic">FeedWordPress used to syndicate
posts from these sources, but you have unsubscribed from them.</p>
</div>
<?php
endif;
?>
<?php
if (count($sources[$visibility]) > 0) :
$this->display_button_bar($showInactive);
else :
$this->manage_page_links_subsubsub($sources, $showInactive);
endif;
fwp_syndication_manage_page_links_table_rows($sources[$visibility], $this, $visibility);
$this->display_button_bar($showInactive);
?>
</form>
<?php
} /* FeedWordPressSyndicationPage::syndicated_sources_box() */
function manage_page_links_subsubsub ($sources, $showInactive) {
$hrefPrefix = $this->admin_page_href("syndication.php");
?>
<ul class="subsubsub">
<li><a <?php if (!$showInactive) : ?>class="current" <?php endif; ?>href="<?php print $hrefPrefix; ?>&visibility=Y">Subscribed
<span class="count">(<?php print count($sources['Y']); ?>)</span></a></li>
<?php if ($showInactive or (count($sources['N']) > 0)) : ?>
<li><a <?php if ($showInactive) : ?>class="current" <?php endif; ?>href="<?php print $hrefPrefix; ?>&visibility=N">Inactive</a>
<span class="count">(<?php print count($sources['N']); ?>)</span></a></li>
<?php endif; ?>
</ul> <!-- class="subsubsub" -->
<?php
}
function display_button_bar ($showInactive) {
?>
<div style="clear: left" class="alignleft">
<?php if ($showInactive) : ?>
<input class="button-secondary" type="submit" name="action" value="<?php print FWP_RESUB_CHECKED; ?>" />
<input class="button-secondary" type="submit" name="action" value="<?php print FWP_DELETE_CHECKED; ?>" />
<?php else : ?>
<input class="button-secondary" type="submit" name="action" value="<?php print FWP_UPDATE_CHECKED; ?>" />
<input class="button-secondary delete" type="submit" name="action" value="<?php print FWP_UNSUB_CHECKED; ?>" />
<?php endif ; ?>
</div> <!-- class="alignleft" -->
<br class="clear" />
<?php
}
function bleg_thanks ($page, $box = NULL) {
?>
<div class="donation-thanks">
<h4>Thank you!</h4>
<p><strong>Thank you</strong> for your contribution to <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a> development.
Your generous gifts make ongoing support and development for
FeedWordPress possible.</p>
<p>If you have any questions about FeedWordPress, or if there
is anything I can do to help make FeedWordPress more useful for
you, please <a href="http://feedwordpress.radgeek.com/contact">contact me</a>
and let me know what you're thinking about.</p>
<p class="signature">—<a href="http://radgeek.com/">Charles Johnson</a>, Developer, <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>.</p>
</div>
<?php
} /* FeedWordPressSyndicationPage::bleg_thanks () */
function bleg_box ($page, $box = NULL) {
?>
<script type="text/javascript">
/* <![CDATA[ */
(function() {
var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'https://api.flattr.com/js/0.6/load.js?mode=auto';
t.parentNode.insertBefore(s, t);
})();
/* ]]> */</script>
<div class="donation-form">
<h4>Consider a Donation to FeedWordPress</h4>
<form action="https://www.paypal.com/cgi-bin/webscr" accept-charset="UTF-8" method="post"><div>
<p><a href="http://feedwordpress.radgeek.com/">FeedWordPress</a> makes syndication
simple and empowers you to stream content from all over the web into your
WordPress hub. If you’re finding FWP useful,
<a href="http://feedwordpress.radgeek.com/donate/">a modest gift</a>
is the best way to support steady progress on development, enhancements,
support, and documentation.</p>
<div class="donate" style="vertical-align: middle">
<div id="flattr-paypal">
<div style="display: inline-block; vertical-align: middle; ">
<a class="FlattrButton" style="display:none;" href="http://feedwordpress.radgeek.com/"></a>
<noscript>
<a href="https://flattr.com/thing/1380856/FeedWordPress" target="_blank"><img src="https://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" /></a>
</noscript>
<div>via Flattr</div>
</div> <!-- style="display: inline-block" -->
<div class="hovered-component" style="display: inline-block; vertical-align: bottom">
<a href="bitcoin:<?php print esc_attr(FEEDWORDPRESS_BLEG_BTC); ?>"><img src="<?php print esc_url( plugins_url('/'.FeedWordPress::path('btc-qr-64px.png') ) ); ?>" alt="Donate" /></a>
<div><a href="bitcoin:<?php print esc_attr(FEEDWORDPRESS_BLEG_BTC); ?>">via bitcoin<span class="hover-on pop-over" style="background-color: #ddffdd; padding: 5px; color: black; border-radius: 5px;">bitcoin:<?php print esc_html(FEEDWORDPRESS_BLEG_BTC); ?></span></a></div>
</div>
<div style="display: inline-block; vertical-align: bottom">
<input type="image" name="submit" src="<?php print esc_url(plugins_url('/' . FeedWordPress::path('paypal-donation-64px.png' ) ) ); ?>" alt="Donate through PayPal" />
<input type="hidden" name="business" value="<?php print esc_attr(FEEDWORDPRESS_BLEG_PAYPAL); ?>" />
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="item_name" value="FeedWordPress donation" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="return" value="<?php print esc_attr($this->admin_page_href(basename($this->filename), array('paid' => 'yes'))); ?>" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="notify_url" value="http://feedwordpress.radgeek.com/ipn/donation" />
<input type="hidden" name="custom" value="1" />
<div>via PayPal</div>
</div> <!-- style="display: inline-block" -->
</div> <!-- id="flattr-paypal" -->
</div> <!-- class="donate" -->
</div> <!-- class="donation-form" -->
</form>
<p>You can make a gift online (or
<a href="http://feedwordpress.radgeek.com/donation">set up an automatic
regular donation</a>) using an existing PayPal account or any major credit card.</p>
<div class="sod-off">
<form style="text-align: center" action="<?php print $this->form_action(); ?>" method="POST"><div>
<input class="button" type="submit" name="maybe_later" value="Maybe Later" />
<input class="button" type="submit" name="go_away" value="Dismiss" />
</div></form>
</div>
</div> <!-- class="donation-form" -->
<?php
} /* FeedWordPressSyndicationPage::bleg_box () */
/**
* Override the default display of a save-settings button and replace
* it with nothing.
*/
function interstitial () {
/* NOOP */
} /* FeedWordPressSyndicationPage::interstitial() */
function multidelete_page () {
global $wpdb;
// If this is a POST, validate source and user credentials
FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
if (MyPHP::post('submit')==FWP_CANCEL_BUTTON) :
return true; // Continue without further ado.
endif;
// Get single link ID or multiple link IDs from REQUEST parameters
// if available. Sanitize values for MySQL.
$link_list = $this->requested_link_ids_sql();
if (MyPHP::post('confirm')=='Delete'):
if ( is_array(MyPHP::post('link_action')) ) :
$actions = MyPHP::post('link_action');
else :
$actions = array();
endif;
$do_it = array(
'hide' => array(),
'nuke' => array(),
'delete' => array(),
);
foreach ($actions as $link_id => $what) :
$do_it[$what][] = $link_id;
endforeach;
$alter = array();
if (count($do_it['hide']) > 0) :
$hidem = "(".implode(', ', $do_it['hide']).")";
$alter[] = "
UPDATE $wpdb->links
SET link_visible = 'N'
WHERE link_id IN {$hidem}
";
endif;
if (count($do_it['nuke']) > 0) :
$nukem = "(".implode(', ', $do_it['nuke']).")";
// Make a list of the items syndicated from this feed...
$post_ids = $wpdb->get_col("
SELECT post_id FROM $wpdb->postmeta
WHERE meta_key = 'syndication_feed_id'
AND meta_value IN {$nukem}
");
// ... and kill them all
if (count($post_ids) > 0) :
foreach ($post_ids as $post_id) :
// Force scrubbing of deleted post
// rather than sending to Trashcan
wp_delete_post(
/*postid=*/ $post_id,
/*force_delete=*/ true
);
endforeach;
endif;
$alter[] = "
DELETE FROM $wpdb->links
WHERE link_id IN {$nukem}
";
endif;
if (count($do_it['delete']) > 0) :
$deletem = "(".implode(', ', $do_it['delete']).")";
// Make the items syndicated from this feed appear to be locally-authored
$alter[] = "
DELETE FROM $wpdb->postmeta
WHERE meta_key = 'syndication_feed_id'
AND meta_value IN {$deletem}
";
// ... and delete the links themselves.
$alter[] = "
DELETE FROM $wpdb->links
WHERE link_id IN {$deletem}
";
endif;
$errs = array(); $success = array ();
foreach ($alter as $sql) :
$result = $wpdb->query($sql);
if (!$result):
$errs[] = $wpdb->last_error;
endif;
endforeach;
if (count($alter) > 0) :
echo "<div class=\"updated\">\n";
if (count($errs) > 0) :
echo "There were some problems processing your ";
echo "unsubscribe request. [SQL: ".implode('; ', $errs)."]";
else :
echo "Your unsubscribe request(s) have been processed.";
endif;
echo "</div>\n";
endif;
return true; // Continue on to Syndicated Sites listing
else :
// $link_list has previously been sanitized for html by self::requested_link_ids_sql
$targets = $wpdb->get_results("
SELECT * FROM $wpdb->links
WHERE link_id IN ${link_list}
");
?>
<form action="<?php print $this->form_action(); ?>" method="post">
<div class="wrap">
<?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
<input type="hidden" name="action" value="Unsubscribe" />
<input type="hidden" name="confirm" value="Delete" />
<h2>Unsubscribe from Syndicated Links:</h2>
<?php foreach ($targets as $link) :
$subscribed = ('Y' == strtoupper($link->link_visible));
$link_url = esc_html($link->link_url);
$link_name = esc_html($link->link_name);
$link_description = esc_html($link->link_description);
$link_rss = esc_html($link->link_rss);
?>
<fieldset>
<legend><?php echo $link_name; ?></legend>
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
<tr><th scope="row" width="20%"><?php _e('Feed URI:') ?></th>
<td width="80%"><a href="<?php echo $link_rss; ?>"><?php echo $link_rss; ?></a></td></tr>
<tr><th scope="row" width="20%"><?php _e('Short description:') ?></th>
<td width="80%"><?php echo $link_description; ?></span></td></tr>
<tr><th width="20%" scope="row"><?php _e('Homepage:') ?></th>
<td width="80%"><a href="<?php echo $link_url; ?>"><?php echo $link_url; ?></a></td></tr>
<tr style="vertical-align:top"><th width="20%" scope="row">Subscription <?php _e('Options') ?>:</th>
<td width="80%"><ul style="margin:0; padding: 0; list-style: none">
<?php if ($subscribed) : ?>
<li><input type="radio" id="hide-<?php echo $link->link_id; ?>"
name="link_action[<?php echo $link->link_id; ?>]" value="hide" checked="checked" />
<label for="hide-<?php echo $link->link_id; ?>">Turn off the subscription for this
syndicated link<br/><span style="font-size:smaller">(Keep the feed information
and all the posts from this feed in the database, but don't syndicate any
new posts from the feed.)</span></label></li>
<?php endif; ?>
<li><input type="radio" id="nuke-<?php echo $link->link_id; ?>"<?php if (!$subscribed) : ?> checked="checked"<?php endif; ?>
name="link_action[<?php echo $link->link_id; ?>]" value="nuke" />
<label for="nuke-<?php echo $link->link_id; ?>">Delete this syndicated link and all the
posts that were syndicated from it</label></li>
<li><input type="radio" id="delete-<?php echo $link->link_id; ?>"
name="link_action[<?php echo $link->link_id; ?>]" value="delete" />
<label for="delete-<?php echo $link->link_id; ?>">Delete this syndicated link, but
<em>keep</em> posts that were syndicated from it (as if they were authored
locally).</label></li>
<li><input type="radio" id="nothing-<?php echo $link->link_id; ?>"
name="link_action[<?php echo $link->link_id; ?>]" value="nothing" />
<label for="nothing-<?php echo $link->link_id; ?>">Keep this feed as it is. I changed
my mind.</label></li>
</ul>
</table>
</fieldset>
<?php endforeach; ?>
<div class="submit">
<input type="submit" name="submit" value="<?php _e(FWP_CANCEL_BUTTON); ?>" />
<input class="delete" type="submit" name="submit" value="<?php _e(FWP_UNSUB_FULL) ?>" />
</div>
</div>
<?php
return false; // Don't continue on to Syndicated Sites listing
endif;
} /* FeedWordPressSyndicationPage::multidelete_page() */
function multiundelete_page () {
global $wpdb;
// If this is a POST, validate source and user credentials
FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
// Get single link ID or multiple link IDs from REQUEST parameters
// if available. Sanitize values for MySQL.
$link_list = $this->requested_link_ids_sql();
if (MyPHP::post('confirm')=='Undelete'):
if ( is_array(MyPHP::post('link_action')) ) :
$actions = MyPHP::post('link_action');
else :
$actions = array();
endif;
$do_it = array(
'unhide' => array(),
);
foreach ($actions as $link_id => $what) :
$do_it[$what][] = $link_id;
endforeach;
$alter = array();
if (count($do_it['unhide']) > 0) :
$unhiddem = "(".implode(', ', $do_it['unhide']).")";
$alter[] = "
UPDATE $wpdb->links
SET link_visible = 'Y'
WHERE link_id IN {$unhiddem}
";
endif;
$errs = array(); $success = array ();
foreach ($alter as $sql) :
$result = $wpdb->query($sql);
if (!$result):
$errs[] = $wpdb->last_error;
endif;
endforeach;
if (count($alter) > 0) :
echo "<div class=\"updated\">\n";
if (count($errs) > 0) :
echo "There were some problems processing your ";
echo "re-subscribe request. [SQL: ".implode('; ', $errs)."]";
else :
echo "Your re-subscribe request(s) have been processed.";
endif;
echo "</div>\n";