-
Notifications
You must be signed in to change notification settings - Fork 63
/
feedwordpresssyndicationpage.class.php
1449 lines (1274 loc) · 53.4 KB
/
feedwordpresssyndicationpage.class.php
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
/**
* feedwordpresssyndicationpage.class.php
* feedwordpress
*
* @author radgeek
*/
require_once dirname(__FILE__) . '/admin-ui.php';
require_once dirname(__FILE__) . '/feedfinder.class.php';
################################################################################
## ADMIN MENU ADD-ONS: implement Dashboard management pages ####################
################################################################################
define( 'FWP_PROJECT_WEBSITE_URL', 'https://fwpplugin.com/' );
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' );
/**
* Tab for the admin page where syndication is dealt with.
*
* @extends FeedWordPressAdminPage
*
* @uses MyPHP
* @uses FeedFinder
* @uses FeedWordPress
* @uses FeedWordPressCompatibility
* @uses FeedWordPressDiagnostic
*/
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 */
/**
* Stub function to comply with parent class.
*
* @return bool Always returns FALSE in this class.
*/
function has_link()
{
return false;
} /* FeedWordPressSyndicationPage::has_link() */
/** @var array|null List of sources which gets initialised by $this->sources('Y') if it's still NULL */
var $_sources = NULL;
/**
* Builds _sources (list of visible or invisible links to sources of syndicated links)
* or returns existing _sources if it's already built.
*
* @param string $visibility Unknown flag which toggles source visibility
*
* @return array Constructed list of visible/invisible sources
*
* @uses FeedWordPress::syndicated_links()
*
*/
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() */
/**
* Toggles source visibility, using the side-effect of pseudo-getter $this->sources(...) method-
*
* @return string
*
* @uses FeedWordPress::param()
*/
function visibility_toggle()
{
$sources = $this->sources( '*' ); // return value unnecessary, it seems the code is just using the side-effect of initialising $this->_sources if it's uninitialised. (gwyneth 20230916)
$defaultVisibility = 'Y';
if ( ( count( $this->sources( 'N' ) ) > 0 )
and ( count( $this->sources( 'Y' ) ) == 0 ) ) :
$defaultVisibility = 'N';
endif;
// this may be output into HTML, and it should really only ever be Y or N...
$sVisibility = FeedWordPress::param( 'visibility', $defaultVisibility );
$visibility = preg_replace( '/[^YyNn]+/', '', $sVisibility );
return ( strlen( $visibility ) > 0 ? $visibility : $defaultVisibility );
} /* FeedWordPressSyndicationPage::visibility_toggle() */
/**
* Shows source feeds that are currently not visible.
*
* @return string
*/
function show_inactive()
{
return ( 'N' == $this->visibility_toggle() );
}
/**
* 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()
* @uses sanitize_text_field()
* @uses MyPHP::post()
* @uses MyPHP::request()
* @uses FeedWordPress::post()
*/
public function requested_link_ids_sql()
{
// Multiple link IDs passed in link_ids[]=...
$link_ids = array_map(
'sanitize_text_field',
(array) MyPHP::request( 'link_ids', array() )
);
// Or single in link_id=...
if ( ! is_null( MyPHP::request( 'link_id' ) ) ) :
array_push( $link_ids, sanitize_text_field( MyPHP::request( 'link_id' ) ) );
endif;
// Now use method to sanitize 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 () */
/**
* Returns the list of requested updates.
*
* @return array List of requested updates
*
* @uses MyPHP::post()
* @uses MyPHP::request()
* @uses FeedWordPress::post()
* @uses FeedWordPressDiagnostic::critical_bug()
*/
function updates_requested()
{
global $wpdb;
if ( FeedWordPress::post( 'update' ) || FeedWordPress::post( 'action' ) || FeedWordPress::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( FeedWordPress::post( 'update_uri' ) ) ) :
$targets = FeedWordPress::post( 'update_uri' );
if ( !is_array( $targets ) ) :
$targets = array( $targets );
endif;
$targets_keys = array_keys( $targets );
$first_key = reset( $targets_keys );
if ( !is_numeric( $first_key) ) : // URLs in keys
$targets = $targets_keys;
endif;
$update_set = $targets;
endif;
endif;
return $update_set;
}
/**
* Cancels the request.
*
* @return bool Success
*
* @uses FeedWordPress::post()
*/
public function cancel_requested()
{
$cancel = FeedWordPress::post( 'cancel' );
return ( $cancel === __( FWP_CANCEL_BUTTON ) );
}
/**
* Adds multiple requests.
*
* @return bool Success
*
* @uses FeedWordPress::post()
*/
public function multiadd_requested()
{
$multiadd = FeedWordPress::post( 'multiadd' );
return ( $multiadd === FWP_SYNDICATE_NEW );
}
/**
* Confirms that multiple requests were added.
*
* @return bool Success
*
* @uses FeedWordPress::post()
*/
public function multiadd_confirm_requested()
{
$confirm = FeedWordPress::post( 'confirm' );
return ( $confirm === 'multiadd' );
}
/**
* Accepts multiple requests that were added.
*
* @return bool Always true
*
* @uses FeedWordPress::post()
* @uses FeedWordPress::syndicate_link()
* @uses FeedWordPressCompatibility::validate_http_request()
*/
function accept_multiadd()
{
if ( $this->cancel_requested() ) :
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 = FeedWordPress::post( 'multilookup', '' )
. FeedWordPress::post( 'opml_lookup', '' );
if ( $this->multiadd_confirm_requested() ) :
$chex = FeedWordPress::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 ( !empty( $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 = feedwordpress_display_url($url);
printf(
'<li><a href="%s">%s</a>',
esc_url( $url ),
esc_html( $short )
);
if ( is_wp_error( $err[1] ) ) :
$error = $err[1];
printf( ' (<code>%s</code>)', esc_html( $error->get_error_messages() ) );
endif;
print "</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...
}
/**
* Emits HTML for multiple added lines.
*
* @param array $line Line item to be displayed.
*/
function display_multiadd_line( $line )
{
$short_feed = feedwordpress_display_url( $line['feed'] );
$feed = $line['feed'];
$link = $line['link'];
$title = $line['title'];
$i = $line['i'];
print "<li><label><input type='checkbox' name='multilookup[" . esc_attr( $i ) . "][add]' value='yes'";
if ( strlen( $line['checked'] ) > 0 ) :
print ' checked="checked" ';
endif;
print "/> " . esc_html( $title ) . "</label> · <a href='"
. esc_url($feed) . "'>" . esc_html( $short_feed ) . "</a>";
if ( isset( $line['extra']) ) :
print " · " . esc_html( $line['extra'] );
endif;
print
"<input type='hidden' name='multilookup[" . esc_attr( $i ) . "][url]' value='" . esc_attr( $feed ) . "' />
<input type='hidden' name='multilookup[" . esc_attr( $i ) . "][link]' value='" . esc_attr( $link ) . "' />
<input type='hidden' name='multilookup[" . esc_attr( $i ) . "][title]' value='" . esc_attr( $title ) . "' />
</li>\n";
flush();
}
/**
* Emits HTML for the box that allows adding multiple sources.
*
* @param int $page Unknown and unused.
* @param string|null $box Unknown and unused.
*
* @return bool Always true
*
* @uses file_get_contents()
* @uses FeedFinder
* @uses FeedWordPress::fetch()
* @uses FeedWordPress::post()
* @uses FeedWordPressCompatibility::stamp_nonce()
*/
function multiadd_box($page, $box = NULL)
{
$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 ( ! is_null( FeedWordPress::post( 'multilookup' ) ) ) :
$in = FeedWordPress::post( 'multilookup' );
$merge_all = false;
elseif ( ! is_null( FeedWordPress::post( 'opml_lookup' ) ) ) :
$in = FeedWordPress::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;
?>
<!-- Page: <? echo $page; ?> Box: <? echo $box ?: '(empty)'; ?> -->
<form id="multiadd-form" action="<?php print esc_attr( $this->form_action() ); ?>" method="post">
<div><?php FeedWordPressCompatibility::stamp_nonce( 'feedwordpress_feeds' ); ?>
<input type="hidden" name="multiadd" value="<?php print esc_attr( FWP_SYNDICATE_NEW ); ?>" />
<input type="hidden" name="confirm" value="multiadd" />
<input type="hidden" name="multiadd" value="<?php print esc_attr( 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="" />
<?php esc_html_e( 'Looking up feed information...' ); ?></p>
</div>
<div id="multiadd-buttons">
<input type="submit" class="button" name="cancel" value="<?php esc_html_e( FWP_CANCEL_BUTTON ); ?>" />
<input type="submit" class="button-primary" value="<?php esc_html_e( 'Subscribe to selected sources →' ); ?>" />
</div>
<p><?php esc_html_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;
$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
}
/**
* Displays the main syndication page.
*
* @uses FeedWordPress::needs_upgrade()
* @uses FeedWordPress::param()
*/
function display()
{
if ( FeedWordPress::needs_upgrade() ) :
fwp_upgrade_page();
return;
endif;
$cont = true;
$dispatcher = array(
"feedfinder" => 'feedfinder_page',
FWP_SYNDICATE_NEW => 'feedfinder_page',
"switchfeed" => 'switchfeed_page',
FWP_UNSUB_CHECKED => 'multidelete_page',
FWP_DELETE_CHECKED => 'multidelete_page',
'Unsubscribe' => 'multidelete_page',
FWP_RESUB_CHECKED => 'multiundelete_page',
);
$act = FeedWordPress::param( 'action' );
if ( isset( $dispatcher[ $act ] ) ) :
$method = $dispatcher[ $act ];
if ( method_exists( $this, $method ) ) :
$cont = $this->{$method}();
else :
$cont = call_user_func( $method );
endif;
elseif ( $this->multiadd_requested() ) :
$cont = $this->accept_multiadd();
endif;
if ( $cont ) :
$links = $this->sources( 'Y' ); // side-effect of getting _sources instantiated... (gwyneth 20230916)
$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 () */
/**
* Displays the dashboard box.
*
* @param int $page Unknown usage.
* @param array|null $box Unknown usage.
*/
function dashboard_box($page, $box = NULL)
{
$links = FeedWordPress::syndicated_links( array( "hide_invisible" => false ) ); // what is $links for? (gwyneth 20230916)
$sources = $this->sources( '*' ); // uses side-effects to initialise _sources (gwyneth 20230916)
/** @var string what is this used for? (gwyneth 20230915) */
$visibility = 'Y';
$hrefPrefix = $this->form_action();
$activeHref = $hrefPrefix . '&visibility=' . $visibility;
$inactiveHref = $hrefPrefix . '&visibility=N';
$lastUpdate = get_option( 'feedwordpress_last_update_all', NULL );
$automatic_updates = get_option( 'feedwordpress_automatic_updates', NULL );
/** @var string default value set here, to avoid having a else clause, but also to init the variable in the right scope. (gwyneth 20230915) */
$update_setting = __( 'using a cron job or manual check-ins' );
if ( 'init' == $automatic_updates ) :
$update_setting = __( 'automatically before page loads' );
elseif ( 'shutdown' == $automatic_updates ) :
$update_setting = __( 'automatically after page loads' );
endif;
// Hey ho, let's go...
?>
<div style="float: left; background: /* #F5F5F5 */ white; padding-top: 5px; padding-right: 5px;"><a href="<?php print esc_url( $this->form_action() ); ?>"><img src="<?php print esc_url( plugins_url( /* "feedwordpress.png" */ "assets/images/icon.svg", __FILE__ ) ); ?>" width="36px" height="36px" alt="FeedWordPress Logo" /></a></div>
<p class="info" style="margin-bottom: 0px; border-bottom: 1px dotted black;"><?php esc_html_e( 'Managed by' ); ?><a href="<?php print esc_url( FWP_PROJECT_WEBSITE_URL ); ?>">FeedWordPress</a>
<?php print esc_html( FEEDWORDPRESS_VERSION ); ?>.</p>
<?php if ( FEEDWORDPRESS_BLEG ) : ?>
<p class="info" style="margin-top: 0px; font-style: italic; font-size: 75%; color: #666;"><?php esc_html_e( 'If you find this tool useful for your daily work, you can
contribute to ongoing support and development with '); ?>
<a href="<?php print esc_url( FWP_PROJECT_WEBSITE_URL ); ?>donate/"><?php esc_html_e('a modest donation'); ?></a>.</p>
<br style="clear: left;" />
<?php endif; ?>
<div class="feedwordpress-actions">
<h4>Updates</h4>
<ul class="options">
<li><strong><?php esc_html_e( 'Scheduled:' ); ?></strong> <?php print esc_html($update_setting); ?>
(<a href="<?php print esc_url($this->form_action('feeds-page.php')); ?>"><?php esc_html_e( 'change setting' ); ?></a>)</li>
<li><?php if ( !is_null($lastUpdate)) : ?>
<strong><?php esc_html_e( 'Last checked:' );?></strong> <?php print esc_html(fwp_time_elapsed($lastUpdate)); ?>
<?php else : ?>
<strong><?php esc_html_e( 'Last checked:' );?> </strong><?php esc_html_e( 'none yet' ); ?>
<?php endif; ?> </li>
</ul>
</div>
<div class="feedwordpress-stats">
<h4><?php esc_html_e( 'Subscriptions' ); ?></h4>
<table>
<tbody>
<tr class="first">
<td class="first b b-active"><a href="<?php print esc_url($activeHref); ?>"><?php print esc_html(count($sources['Y'])); ?></a></td>
<td class="t active"><a href="<?php print esc_url($activeHref); ?>"><?php esc_html_e( 'Active' ); ?></a></td>
</tr>
<tr>
<td class="b b-inactive"><a href="<?php print esc_url($inactiveHref); ?>"><?php print esc_html(count($sources['N'])); ?></a></td>
<td class="t inactive"><a href="<?php print esc_url($inactiveHref); ?>"><?php esc_html_e( '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 esc_url( $this->form_action() ); ?>" method="POST">
<div class="container"><input type="submit" class="button-primary" name"update" value="<?php print esc_attr(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 esc_url( $this->form_action() ); // TODO: needs to be checked, because it doesn't seem to be defined properly (gwyneth 20230915) ?>" 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 esc_attr( FWP_SYNDICATE_NEW ); ?>" />
<input style="vertical-align: middle;" type="image" src="<?php print esc_url(plugins_url('plus.png', __FILE__)); ?>" alt="<?php print esc_html(FWP_SYNDICATE_NEW); ?>" /></div>
</form>
</div> <!-- id="add-single-uri" -->
<br style="clear: both;" />
<?php
} /* FeedWordPressSyndicationPage::dashboard_box () */
/**
* One of the status boxes for the FWP dashboard.
*
* @param mixed $page Unused
* @param mixed|null $box Unused
* *
* @uses FeedWordPress::syndicated_links()
* @uses FeedWordPressCompatibility::stamp_nonce()
* @uses FeedWordPressSettingsUI::magic_input_tip_js()
*/
function syndicated_sources_box ($page, $box = NULL) {
$links = FeedWordPress::syndicated_links(array("hide_invisible" => false)); // what is $links for? (gwyneth 20230916)
$sources = $this->sources('*');
$visibility = $this->visibility_toggle();
$showInactive = $this->show_inactive();
$hrefPrefix = $this->form_action();
$formHref = sprintf( '%s&visibility=%s', $hrefPrefix, urlencode($visibility) );
?>
<div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
<div class="tablenav">
<div id="add-multiple-uri" class="hide-if-js">
<form action="<?php print esc_url( $formHref ); ?>" method="post">
<div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
<h4><?php esc_html_e( 'Add Multiple Sources' ); ?></h4>
<div><?php esc_html_e( '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 esc_attr(FWP_SYNDICATE_NEW); ?>" /></div>
<div class="alignleft"><input type="button" class="button-secondary" name="action" value="<?php print esc_attr(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><?php esc_html_e( 'Import source list' ); ?></h4>
<p><?php esc_html_e( '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 esc_url( $formHref ); ?>" 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;"><?php esc_html_e( '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;"><?php esc_html_e( '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 esc_html(FWP_SYNDICATE_NEW); ?>" /></div>
<div class="alignleft"><input type="button" class="button-secondary" name="action" value="<?php print esc_html(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 esc_url( $formHref ); ?>" method="post">
<div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
<ul class="subsubsub">
<li><label for="add-uri"><?php esc_html_e( '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 esc_html( FWP_SYNDICATE_NEW ); ?>" />
<div style="text-align: right; margin-right: 2.0em">
<!-- Using WP Dashicon plus and down-arrow symbols below (gwyneth 20210717) -->
<a id="turn-on-multiple-sources" href="#add-multiple-uri"><span class="dashicons feedwordpress-dashicons dashicons-list-view"></span> <?php esc_html_e( 'add multiple' ); ?></a>
<span class="screen-reader-text"> or </span>
<a id="turn-on-opml-upload" href="#upload-opml"><span class="dashicons feedwordpress-dashicons dashicons-upload"></span> <?php esc_html_e( '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 esc_url( $formHref ); ?>" 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"><?php esc_html_e( '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() */
/**
* Handles subpages on syndication dashboard (showing active/inactive feeds).
*
* @param array $sources List of feed URLs (active or inactive).
* @param bool $showInactive True if we're showing the inactive feeds.
*
*/
function manage_page_links_subsubsub( $sources, $showInactive ) {
$hrefPrefix = $this->admin_page_href( "syndication.php" );
$hrefY = sprintf( "%s&visibility=%s", $hrefPrefix, "Y" );
$hrefN = sprintf( "%s&visibility=%s", $hrefPrefix, "N" );
?>
<ul class="subsubsub">
<li><a <?php if ( ! $showInactive ) : ?>class="current" <?php endif; ?>href="<?php print esc_url( $hrefY ); ?>"><?php esc_html_e( '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 esc_url( $hrefN ); ?>"><?php esc_html_e( 'Inactive' ); ?></a>
<span class="count">(<?php print count( $sources['N'] ); ?>)</span></a></li>
<?php endif; ?>
</ul> <!-- class="subsubsub" -->
<?php
} /* FeedWordPressSyndicationPage::manage_page_links_subsubsub() */
/**
* Displays the button bar showing options per feed.
*
* @param bool $showInactive True if we're showing inactive feeds.
*/
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 esc_attr( FWP_RESUB_CHECKED ); ?>" />
<input class="button-secondary" type="submit" name="action" value="<?php print esc_attr( FWP_DELETE_CHECKED ); ?>" />
<?php else : ?>
<input class="button-secondary" type="submit" name="action" value="<?php print esc_attr( FWP_UPDATE_CHECKED ); ?>" />
<input class="button-secondary delete" type="submit" name="action" value="<?php print esc_attr( FWP_UNSUB_CHECKED ); ?>" />
<?php endif ; ?>
</div> <!-- class="alignleft" -->
<br class="clear" />
<?php
}
/**
* Displays page to thank user for donation.
*
* @param mixed $page Unused.
* @param mixed|null $box Unused.
*/
function bleg_thanks( $page, $box = NULL ) {
?>
<div class="donation-thanks">
<h4><?php esc_html_e( 'Thank you!' ); ?></h4>
<p><strong><?php esc_html_e( 'Thank you' ); ?></strong> <?php esc_html_e( ' for your contribution to '); ?>
<a href="<?php print esc_url( FWP_PROJECT_WEBSITE_URL ); ?>"><?php esc_html_e( 'FeedWordPress development' ); ?></a>.
<?php esc_html_e( 'Your generous gifts make ongoing support and development for
FeedWordPress possible.' ); ?></p>
<p><?php esc_html_e( '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="<?php print esc_url( FWP_PROJECT_WEBSITE_URL ); ?>contact"><?php esc_html_e( 'contact me' ); ?></a>
<?php esc_html_e(' and let me know what you’re thinking about.' ); ?></p>
<p class="signature">—<a href="<?php print esc_url( FWP_PROJECT_WEBSITE_URL ); ?>">Charles Johnson</a>, <?php esc_html_e(' Developer' ); ?>, <a href="<?php print esc_url( FWP_PROJECT_WEBSITE_URL ); ?>">FeedWordPress</a>.</p>
</div>
<?php
} /* FeedWordPressSyndicationPage::bleg_thanks () */
/**
* Displays a donation form.
*
* @note Flattr unfortunately changed their business model :-(
* (gwyneth 20230917)
*
* @param mixed $page Unused.
* @param mixed|null $box Unused.
*/
function bleg_box ($page, $box = NULL) {
?>
<div class="donation-form">
<h4><?php esc_html_e( '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="<?php print esc_url( FWP_PROJECT_WEBSITE_URL ); ?>">FeedWordPress</a> <?php esc_html_e( '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="<?php print esc_url( FWP_PROJECT_WEBSITE_URL ); ?>donate/"><?php esc_html_e( 'a modest gift' ); ?></a>
<?php esc_html_e( ' 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 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('assets/images/btc-qr-128px.png') ) ); ?>" alt="<?php esc_html_e( 'Donate' ); ?>" /></a>
<div><a href="bitcoin:<?php print esc_attr( FEEDWORDPRESS_BLEG_BTC ); ?>"><?php esc_html_e( '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('assets/images/paypal-donation-64px.png' ) ) ); ?>" style="width: 128px; height: 128px;" alt="<?php esc_html_e( 'Donate via 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="<?php esc_html_e( '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="<?php print esc_url( FWP_PROJECT_WEBSITE_URL ); ?>/ipn/donation" />
<input type="hidden" name="custom" value="1" />
<div><?php esc_html_e( 'via PayPal' ); ?></div>
</div> <!-- style="display: inline-block" -->
</div> <!-- id="flattr-paypal" -->
</div> <!-- class="donate" -->
</div> <!-- class="donation-form" -->
</form>
<p><?php esc_html_e( 'You can make a gift online (or ' ); ?><a href="<?php print esc_url( FWP_PROJECT_WEBSITE_URL ) ;?>donation"><?php esc_html_e( 'set up an automatic
regular donation' ); ?></a><?php esc_html_e( ' using an existing PayPal account or any major credit card.' ); ?></p>
<div class="sod-off">
<form style="text-align: center" action="<?php print esc_url( $this->form_action() ); ?>" method="POST"><div>
<input class="button" type="submit" name="maybe_later" value="<?php esc_attr_e( 'Maybe Later' ); ?>"/>
<input class="button" type="submit" name="go_away" value="<?php esc_attr_e( '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'):
$actions = array(); // avoids "else" complaint _and_ guarantees that we don't have any scoping issues (gwyneth 20230916)
if ( is_array(MyPHP::post('link_action')) ) :
$actions = MyPHP::post('link_action');
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'