forked from radgeek/feedwordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feeds-page.php
1313 lines (1143 loc) · 47.2 KB
/
feeds-page.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
require_once(dirname(__FILE__) . '/admin-ui.php');
require_once(dirname(__FILE__) . '/magpiemocklink.class.php');
require_once(dirname(__FILE__) . '/feedfinder.class.php');
require_once(dirname(__FILE__) . '/updatedpostscontrol.class.php');
class FeedWordPressFeedsPage extends FeedWordPressAdminPage {
var $HTTPStatusMessages = array (
200 => 'OK. FeedWordPress had no problems retrieving the content at this URL but the content does not seem to be a feed, and does not seem to include links to any feeds.',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
400 => 'Bad Request',
401 => 'Unauthorized. This URL probably needs a username and password for you to access it.',
402 => 'Payment Required',
403 => 'Forbidden. The URL is not made available for the machine that FeedWordPress is running on.',
404 => 'Not Found. There is nothing at this URL. Have you checked the address for typos?',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone. This URL is no longer available on this server and no forwarding address is known.',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
500 => 'Internal Server Error. Something unexpected went wrong with the configuration of the server that hosts this URL. You might try again later to see if this issue has been resolved.',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable. The server is currently unable to handle the request due to a temporary overloading or maintenance of the server that hosts this URL. This is probably a temporary condition and you should try again later to see if the issue has been resolved.',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
);
var $updatedPosts = NULL;
var $special_settings = array ( /* Regular expression syntax is OK here */
'cats',
'cat_split',
'fetch timeout',
'freeze updates',
'hardcode name',
'hardcode url',
'hardcode description',
'hardcode categories', /* Deprecated */
'comment status',
'terms',
'map authors',
'munge permalink',
'ping status',
'post status',
'postmeta',
'query parameters',
'resolve relative',
'syndicated post type',
'tags',
'unfamiliar author',
'unfamliar categories', /* Deprecated */
'unfamiliar category',
'unfamiliar post_tag',
'add/.*',
'update/.*',
'feed/.*',
'link/.*',
'match/.*',
);
/**
* Constructs the Feeds page object
*
* @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings
*/
public function __construct( $link = -1 ) {
if (is_numeric($link) and -1 == $link) :
$link = $this->submitted_link();
endif;
parent::__construct('feedwordpressfeeds', $link);
$this->dispatch = 'feedwordpress_admin_page_feeds';
$this->pagenames = array(
'default' => 'Feeds',
'settings-update' => 'Syndicated feed',
'open-sheet' => 'Feed and Update',
);
$this->filename = __FILE__;
$this->updatedPosts = new UpdatedPostsControl($this);
$this->special_settings = apply_filters('syndicated_feed_special_settings', $this->special_settings, $this);
} /* FeedWordPressFeedsPage constructor */
function display () {
global $fwp_post;
global $post_source;
$this->boxes_by_methods = array(
'feed_information_box' => __('Feed Information'),
'global_feeds_box' => __('Update Scheduling'),
'updated_posts_box' => __('Updated Posts'),
'custom_settings_box' => __('Custom Feed Settings (for use in templates)'),
'advanced_settings_box' => __('Advanced Settings'),
);
if ($this->for_default_settings()) :
unset($this->boxes_by_methods['custom_settings_box']);
endif;
// Allow overriding of normal source for FeedFinder, which may
// be called from multiple points.
if (isset($post_source) and !is_null($post_source)) :
$source = $post_source;
else :
$source = $this->dispatch;
endif;
if (isset($_REQUEST['feedfinder'])
or (isset($_REQUEST['action']) and $_REQUEST['action']=='feedfinder')
or (isset($_REQUEST['action']) and $_REQUEST['action']==FWP_SYNDICATE_NEW)) :
// If this is a POST, validate source and user credentials
FeedWordPressCompatibility::validate_http_request(/*action=*/ $source, /*capability=*/ 'manage_links');
return $this->display_feedfinder(); // re-route to Feed Finder page
endif;
parent::display();
return false; // Don't continue
} /* FeedWordPressFeedsPage::display() */
function ajax_interface_js () {
parent::ajax_interface_js();
?>
jQuery(document).ready( function () {
contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');
contextual_appearance('time-limit', 'time-limit-box', null, 'yes');
contextual_appearance('use-default-update-window-no', 'update-scheduling-note', null, null, 'block', true);
jQuery('#use-default-update-window-yes, #use-default-update-window-no').click( function () {
contextual_appearance('use-default-update-window-no', 'update-scheduling-note', null, null, 'block', true);
} );
var els = ['name', 'description', 'url'];
for (var i = 0; i < els.length; i++) {
contextual_appearance(
/*item=*/ 'basics-hardcode-'+els[i],
/*appear=*/ 'basics-'+els[i]+'-view',
/*disappear=*/ 'basics-'+els[i]+'-edit',
/*value=*/ 'no',
/*visibleStyle=*/ 'block',
/*checkbox=*/ true
);
} /* for */
// Let's make the interface for the PAUSE/RESUME a bit better
jQuery('<tr id="reveal-pause-resume"><th></th><td><button id="pause-resume-reveal-button">— PAUSE or RESUME UPDATES —</button></td></tr>').insertBefore('#pause-resume');
jQuery('#pause-resume').hide();
jQuery('#pause-resume-reveal-button').click(function(ev) {
ev.preventDefault();
jQuery('#pause-resume').toggle();
return false;
});
} );
<?php
}
/*static*/ function updated_posts_box ($page, $box = NULL) {
?>
<table class="edit-form">
<?php $page->updatedPosts->display(); ?>
</table>
<?php
} /* FeedWordPressFeedsPage::updated_posts_box() */
/*static*/ function global_feeds_box ($page, $box = NULL) {
global $feedwordpress;
$automatic_updates = $feedwordpress->automatic_update_hook(array('setting only' => true));
$update_time_limit = (int) get_option('feedwordpress_update_time_limit');
// Hey, ho, let's go...
?>
<table class="edit-form">
<?php if ($page->for_default_settings()) : ?>
<tr>
<th scope="row">Update Method:</th>
<td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');">
<option value="shutdown"<?php echo ($automatic_updates=='shutdown')?' selected="selected"':''; ?>>automatically check for updates after pages load</option>
<option value="init"<?php echo ($automatic_updates=='init')?' selected="selected"':''; ?>>automatically check for updates before pages load</option>
<option value="no"<?php echo (!$automatic_updates)?' selected="selected"':''; ?>>cron job or manual updates</option>
</select>
<div id="cron-job-explanation" class="setting-description">
<p><?php
// Do we have shell_exec() available from here, or is it disabled for security reasons?
// If it's available, use it to execute `which` to try to get a realistic path to curl,
// or to wget. If everything fails or shell_exec() isn't available, then just make
// up something for the sake of example.
$curlOrWgetPath = NULL;
$shellExecAvailable = (is_callable('shell_exec') && false === stripos(ini_get('disable_functions'), 'shell_exec'));
if ($shellExecAvailable) :
$curlOrWgetPath = `which curl`; $opts = '--silent %s';
endif;
if ($shellExecAvailable and (is_null($curlOrWgetPath) or strlen(trim($curlOrWgetPath))==0)) :
$curlOrWgetPath = `which wget`; $opts = '-q -O - %s';
endif;
if (is_null($curlOrWgetPath) or strlen(trim($curlOrWgetPath))==0) :
$curlOrWgetPath = '/usr/bin/curl'; $opts = '--silent %s';
endif;
$curlOrWgetPath = preg_replace('/\n+$/', '', $curlOrWgetPath);
$cmdline = $curlOrWgetPath . ' ' . sprintf($opts, get_bloginfo('url').'?update_feedwordpress=1');
?>If you want to use a cron job,
you can perform scheduled updates by sending regularly-scheduled
requests to <a href="<?php bloginfo('url'); ?>?update_feedwordpress=1"><code><?php bloginfo('url') ?>?update_feedwordpress=1</code></a>
For example, inserting the following line in your crontab:</p>
<pre style="font-size: 0.80em"><code>*/10 * * * * <?php print esc_html($cmdline); ?></code></pre>
<p class="setting-description">will check in every 10 minutes
and check for updates on any feeds that are ready to be polled for updates.</p>
</div>
</td>
</tr>
<?php else : /* Feed-specific settings */ ?>
<tr>
<th scope="row"><?php _e('Last update') ?>:</th>
<td><?php
if (isset($page->link->settings['update/last'])) :
echo fwp_time_elapsed($page->link->settings['update/last'])." ";
else :
echo " none yet";
endif;
?></td></tr>
<tr><th><?php _e('Next update') ?>:</th>
<td><?php
$holdem = (isset($page->link->settings['update/hold']) ? $page->link->settings['update/hold'] : 'scheduled');
?>
<select name="update_schedule">
<option value="scheduled"<?php echo ($holdem=='scheduled')?' selected="selected"':''; ?>>update on schedule <?php
echo " (";
if (isset($page->link->settings['update/ttl']) and is_numeric($page->link->settings['update/ttl'])) :
if (isset($page->link->settings['update/timed']) and $page->link->settings['update/timed']=='automatically') :
echo 'next: ';
$next = $page->link->settings['update/last'] + ((int) $page->link->settings['update/ttl'] * 60);
if (strftime('%x', time()) != strftime('%x', $next)) :
echo strftime('%x', $next)." ";
endif;
echo strftime('%X', $page->link->settings['update/last']+((int) $page->link->settings['update/ttl']*60));
else :
echo "every ".$page->link->settings['update/ttl']." minute".(($page->link->settings['update/ttl']!=1)?"s":"");
endif;
else:
echo "next scheduled update";
endif;
echo ")";
?></option>
<option value="next"<?php echo ($holdem=='next')?' selected="selected"':''; ?>>update ASAP</option>
<option value="ping"<?php echo ($holdem=='ping')?' selected="selected"':''; ?>>update only when pinged</option>
</select></td></tr>
<?php endif; ?>
<tr id="pause-resume">
<th scope="row"><?php print __('Pause/Resume:'); ?></th>
<td><?php
$this->setting_radio_control(
'update/pause', 'update_pause',
/*options=*/ array(
'no' => '<strong>UPDATE:</strong> import new posts as normal',
'yes' => '<strong>PAUSE:</strong> do not import new posts until I unpause updates',
),
/*params=*/ array(
'setting-default' => NULL,
'global-setting-default' => 'no',
'default-input-value' => 'default',
)
);
?></td>
</tr>
<tr>
<th scope="row"><?php print __('Update scheduling:') ?></th>
<td><p style="margin-top:0px">How long should FeedWordPress wait between updates before it considers this feed ready to be polled for updates again?</p>
<?php
$this->setting_radio_control(
'update/window', 'update_window',
array($this, 'update_window_edit_box'),
array(
'global-setting-default' => DEFAULT_UPDATE_PERIOD,
'default-input-name' => 'use_default_update_window',
'default-input-id' => 'use-default-update-window-yes',
'default-input-id-no' => 'use-default-update-window-no',
'labels' => array($this, 'update_window_currently'),
)
);
?></td>
</tr>
<tr>
<th scope="row"><?php print __('Minimum Interval:'); ?></th>
<td><p style="margin-top:0px">Some feeds include standard elements that
request a specific update schedule. If the interval requested by the
feed provider is <em>longer</em> than FeedWordPress's normal scheduling,
FeedWordPress will always respect their request to slow down. But what
should it do if the update interval is <em>shorter</em> than the schedule set above?</p>
<?php
$this->setting_radio_control(
'update/minimum', 'update_minimum',
/*options=*/ array(
'no' => 'Speed up and accept the interval from the feed provider',
'yes' => 'Keep pace and use the longer scheduling from FeedWordPress',
),
/*params=*/ array(
'setting-default' => NULL,
'global-setting-default' => 'no',
'default-input-value' => 'default',
)
);
?>
</td>
</tr>
<?php if ($this->for_default_settings()) : ?>
<tr>
<th scope="row"><?php print __('Time limit on updates'); ?>:</th>
<td><select id="time-limit" name="update_time_limit" size="1" onchange="contextual_appearance('time-limit', 'time-limit-box', null, 'yes');">
<option value="no"<?php echo ($update_time_limit>0)?'':' selected="selected"'; ?>>no time limit on updates</option>
<option value="yes"<?php echo ($update_time_limit>0)?' selected="selected"':''; ?>>limit updates to no more than...</option>
</select>
<span id="time-limit-box"><label><input type="text" name="time_limit_seconds" value="<?php print $update_time_limit; ?>" size="5" /> seconds</label></span>
</tr>
<?php endif; ?>
</table>
<?php
} /* FeedWordPressFeedsPage::global_feeds_box() */
function update_window_edit_box ($updateWindow, $defaulted, $params) {
if (!is_numeric($updateWindow)) :
$updateWindow = DEFAULT_UPDATE_PERIOD;
endif;
?>
<p>Wait <input type="text" name="update_window" value="<?php print $updateWindow; ?>" size="4" /> minutes between polling.</p>
<div class="setting-description" id="update-scheduling-note">
<p<?php if ($updateWindow<50) : ?> style="color: white; background-color: #703030; padding: 1.0em;"<?php endif; ?>><strong>Recommendation.</strong> Unless you are positive that you have the webmaster's permission, you generally should not set FeedWordPress to poll feeds more frequently than once every 60 minutes. Many webmasters consider more frequent automated polling to be abusive, and may complain to your web host, or ban your IP address, as retaliation for hammering their servers too hard.</p>
<p><strong>Note.</strong> This is a default setting that FeedWordPress uses to schedule updates when the feed does not provide any scheduling requests. If this feed does provide update scheduling information (through elements such as <code><rss:ttl></code> or <code><sy:updateFrequency></code>), FeedWordPress will respect the feed's request.</p>
</div>
<?php
} /* FeedWordPressFeedsPage::update_window_edit_box () */
function update_window_currently ($updateWindow, $defaulted, $params) {
$updateWindow = (int) $updateWindow;
if (1==$updateWindow) :
$caption = 'wait %d minute between polling';
else :
$caption = 'wait %d minutes between polling';
endif;
return sprintf(__($caption), $updateWindow);
} /* FeedWordPressFeedsPage::update_window_currently () */
function fetch_timeout_setting ($setting, $defaulted, $params) {
$timeout = intval($this->setting('fetch timeout', FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT));
if ($this->for_feed_settings()) :
$article = 'this';
else :
$article = 'a';
endif;
?>
<p>Wait no more than
than <input name="fetch_timeout" type="number" min="0" size="3" value="<?php print $timeout; ?>" />
second(s) when trying to fetch <?php print $article; ?> feed to check for updates.</p>
<p>If <?php print $article; ?> source's web server does not respond before time runs
out, FeedWordPress will skip over the source and try again during
the next update cycle.</p>
<?php
}
function fetch_timeout_setting_value ($setting, $defaulted, $params) {
print number_format(intval($setting)) . " " . (($setting==1) ? "second" : "seconds");
}
function advanced_settings_box ($page, $box = NULL) {
?>
<table class="edit-form">
<tr>
<th>Fetch Timeout:</th>
<td>
<?php
$this->setting_radio_control(
'fetch timeout', 'fetch_timeout',
array($this, 'fetch_timeout_setting'),
array(
'global-setting-default' => FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT,
'input-name' => 'fetch_timeout',
'default-input-name' => 'fetch_timeout_default',
'labels' => array($this, 'fetch_timeout_setting_value'),
)
);
?>
</td>
</tr>
<tr>
<th>Feed Update Type:</th>
<td><?php
$this->setting_radio_control('update_incremental', 'update_incremental',
/*options=*/ array(
'incremental' => '<strong>Incremental.</strong> When items no longer appear on the feed, keep them in the WordPress posts table.',
'complete' => '<strong>Complete.</strong> When items no longer appear on the feed, they are obsolete; retire them from the WordPress posts table.',
),
/*params=*/ array(
'setting-default' => NULL,
'global-setting-default' => 'incremental',
'default-input-value' => 'default',
)
); ?></td>
</tr>
<tr>
<th>Allow Feeds to Delete Posts:</th>
<td><?php
$this->setting_radio_control('tombstones', 'tombstones',
/*options=*/ array(
'yes' => 'Yes. If a feed indicates that one of its posts has been deleted, delete the local copy syndicated to this website.',
'no' => 'No. Even if a feed indicates that one of its posts has been deleted, retain the local copy on this website.',
),
/*params=*/ array(
'setting-default' => NULL,
'global-setting-default' => 'yes',
'default-input-value' => 'default',
)
); ?></td>
</tr>
</table>
<?php
} /* FeedWordPressFeedsPage::advanced_settings_box () */
function display_authentication_credentials_box ($params = array()) {
static $count = 0;
$params = wp_parse_args($params, array(
'username' => NULL,
'password' => NULL,
'method' => '-',
));
// Equivalents
if (is_null($params['method'])) : $params['method'] = '-'; endif;
$count++;
$slug = ($count > 1 ? '-'.$count : '');
global $feedwordpress;
$authMethods = apply_filters(
'feedwordpress_http_auth_methods',
$feedwordpress->httpauth->methods_available()
);
if (count($authMethods) > 1) : /* More than '-' */
?>
<div class="link-rss-authentication" id="link-rss-authentication<?php print $slug; ?>">
<table>
<tbody>
<tr class="link-rss-authentication-credentials" id="link-rss-authentication-credentials<?php print $slug; ?>">
<td><label>user: <input type="text" name="link_rss_username"
value="<?php print esc_attr($params['username']); ?>" size="16"
placeholder="username to access this feed" /></label></td>
<td><label>pass: <input type="text" name="link_rss_password"
value="<?php print esc_attr($params['password']); ?>" size="16"
placeholder="password to access this feed" /></label></td>
<td class="link-rss-authentication-method" id="link-rss-authentication-method<?php print $slug; ?>"><label>method: <select class="link-rss-auth-method" id="link-rss-auth-method" name="link_rss_auth_method" size="1">
<?php foreach ($authMethods as $value => $label) : ?>
<option value="<?php print esc_attr($value); ?>"<?php
if ($value == $params['method']) : ?> selected="selected"<?php
endif; ?>><?php print esc_html($label); ?></option>
<?php endforeach; ?>
</select></label></td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
jQuery('<td><a class="add-remove remove-it" id="link-rss-userpass-remove<?php print $slug; ?>" href="#"><span class="x">(X)</span> Remove</a></td>')
.appendTo('#link-rss-authentication-credentials<?php print $slug; ?>')
.click( feedAuthenticationMethodUnPress );
jQuery('#link-rss-auth-method<?php print $slug; ?>').change( feedAuthenticationMethod );
feedAuthenticationMethod({
init: true,
node: jQuery('#link-rss-authentication<?php print $slug; ?>') });
</script>
<?php
endif;
}
function feed_information_box ($page, $box = NULL) {
global $wpdb;
$link_rss_params = maybe_unserialize($page->setting('query parameters', ''));
if (!is_array($link_rss_params)) :
$link_rss_params = array();
endif;
if ($page->for_feed_settings()) :
$info['name'] = esc_html($page->link->link->link_name);
$info['description'] = esc_html($page->link->link->link_description);
$info['url'] = esc_html($page->link->link->link_url);
$rss_url = $page->link->link->link_rss;
$hardcode['name'] = $page->link->hardcode('name');
$hardcode['description'] = $page->link->hardcode('description');
$hardcode['url'] = $page->link->hardcode('url');
else :
$cat_id = FeedWordPress::link_category_id();
$params = array();
$params['taxonomy'] = 'link_category';
$params['hide_empty'] = false;
$results = get_categories($params);
// Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
$found_link_category_id = false;
foreach ($results as $row) :
// Normalize case
if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
if ($row->cat_id == $cat_id) : $found_link_category_id = true; endif;
endforeach;
if (!$found_link_category_id) :
$results[] = get_category($cat_id);
endif;
$info = array();
$rss_url = null;
$hardcode['name'] = get_option('feedwordpress_hardcode_name');
$hardcode['description'] = get_option('feedwordpress_hardcode_description');
$hardcode['url'] = get_option('feedwordpress_hardcode_url');
endif;
$hideAuth = false;
$username = $this->setting('http username', NULL);
if (is_null($username)) :
$username = '';
$hideAuth = true;
endif;
$password = $this->setting('http password', NULL);
if (is_null($password)) :
$password = '';
endif;
$auth = $this->setting('http auth method', NULL);
global $feedwordpress;
if (is_null($auth) or (strlen($auth)==0)) :
$auth = '-';
$hideAuth = true;
endif;
// Hey ho, let's go
?>
<table class="edit-form">
<?php if ($page->for_feed_settings()) : ?>
<tr>
<th scope="row"><?php _e('Feed URL:') ?></th>
<td><a href="<?php echo esc_html($rss_url); ?>"><?php echo esc_html($rss_url); ?></a>
(<a href="<?php echo FEEDVALIDATOR_URI; ?>?url=<?php echo urlencode($rss_url); ?>"
title="Check feed <<?php echo esc_html($rss_url); ?>> for validity">validate</a>)
<input type="submit" name="feedfinder" value="switch →" style="font-size:smaller" />
<?php $this->display_authentication_credentials_box(array(
'username' => $username,
'password' => $password,
'method' => $auth,
)); ?>
<table id="link-rss-params">
<tbody>
<?php
$link_rss_params['new'] = array('', '');
$i = 0;
foreach ($link_rss_params as $index => $pair) :
?>
<tr class="link-rss-params-row" id="link-rss-params-<?php print $index; ?>">
<td><label>Parameter: <input type="text" class="link_params_key"
name="link_rss_params_key[<?php print $index; ?>]" value="<?php print esc_html($pair[0]); ?>"
size="5" style="width: 5em" placeholder="name" /></label></td>
<td class="link-rss-params-value-cell"><label class="link_params_value_label">= <input type="text" class="link_params_value"
name="link_rss_params_value[<?php print $index; ?>]" value="<?php print esc_html($pair[1]); ?>"
size="8" placeholder="value" /></label></td>
</tr>
<?php
$i++;
endforeach;
?>
</tbody>
</table>
<div><input type="hidden" id="link-rss-params-num" name="link_rss_params_num" value="<?php print $i; ?>" /></div>
<script type="text/javascript">
function linkParamsRowRemove (element) {
jQuery(element).closest('tr').fadeOut('slow', function () {
jQuery(this).remove();
} );
}
jQuery('<td><a href="#" class="add-remove link-rss-params-remove"><span class="x">(X)</span> Remove</a></td>').insertAfter('.link-rss-params-value-cell');
jQuery('#link-rss-params-new').hide();
jQuery('<a class="add-remove" id="link-rss-params-add" href="#">+ Add a query parameter</a>').insertAfter('#link-rss-params');
jQuery('#link-rss-params-add').click( function () {
var next = jQuery('#link-rss-params-num').val();
var newRow = jQuery('#link-rss-params-new').clone().attr('id', 'link-rss-params-'+next);
newRow.find('.link_params_key').attr('name', 'link_rss_params_key['+next+']');
newRow.find('.link_params_value').attr('name', 'link_rss_params_value['+next+']');
newRow.find('.link-rss-params-remove').click( function () {
linkParamsRowRemove(this);
return false;
} );
newRow.appendTo('#link-rss-params');
newRow.show();
// Update counter for next row.
next++;
jQuery('#link-rss-params-num').val(next);
return false;
} );
jQuery('.link-rss-params-remove').click( function () {
linkParamsRowRemove(this);
return false;
} );
</script>
</td>
</tr>
<?php
$rows = array(
"name" => __('Link Name'),
"description" => __('Short Description'),
"url" => __('Homepage'),
);
foreach ($rows as $what => $label) :
?>
<tr>
<th scope="row"><?php print $label ?></th>
<td>
<div id="basics-<?php print $what; ?>-edit"><input type="text" name="link<?php print $what; ?>"
value="<?php echo $info[$what]; ?>" style="width: 95%" /></div>
<div id="basics-<?php print $what; ?>-view">
<?php if ($what=='url') : ?><a href="<?php print $info[$what]; ?>"><?php else : ?><strong><?php endif; ?>
<?php print (strlen(trim($info[$what])) > 0) ? $info[$what] : '(none provided)'; ?>
<?php if ($what=='url') : ?></a><?php else : ?></strong><?php endif; ?></div>
<div>
<label><input id="basics-hardcode-<?php print $what; ?>"
type="radio" name="hardcode_<?php print $what; ?>" value="no"
<?php echo (($hardcode[$what]=='yes')?'':' checked="checked"');?>
onchange="contextual_appearance('basics-hardcode-<?php print $what; ?>', 'basics-<?php print $what; ?>-view', 'basics-<?php print $what; ?>-edit', 'no', 'block', /*checkbox=*/ true)"
/> Update automatically from feed</label>
<label><input type="radio" name="hardcode_<?php print $what; ?>" value="yes"
<?php echo (($hardcode[$what]!='yes')?'':' checked="checked"');?>
onchange="contextual_appearance('basics-hardcode-<?php print $what; ?>', 'basics-<?php print $what; ?>-view', 'basics-<?php print $what; ?>-edit', 'no', 'block', /*checkbox=*/ true)"
/> Edit manually</label>
</div>
</td>
</tr>
<?php
endforeach;
?>
<?php else : ?>
<tr>
<th scope="row">Syndicated Link category:</th>
<td><p><select name="syndication_category" size="1">
<?php
foreach ($results as $row) :
// Normalize case
if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
echo "\n\t<option value=\"$row->cat_id\"";
if ($row->cat_id == $cat_id) :
echo " selected='selected'";
endif;
echo ">$row->cat_id: ".esc_html($row->cat_name);
echo "</option>\n";
endforeach;
?></select></p>
<p class="setting-description">FeedWordPress will syndicate the
links placed under this link category.</p>
</td>
</tr>
<tr>
<th scope="row">Link Names:</th>
<td><label><input type="checkbox" name="hardcode_name" value="no"<?php echo (($hardcode['name']=='yes')?'':' checked="checked"');?>/> Update contributor titles automatically when the feed title changes</label></td>
</tr>
<tr>
<th scope="row">Short descriptions:</th>
<td><label><input type="checkbox" name="hardcode_description" value="no"<?php echo (($hardcode['description']=='yes')?'':' checked="checked"');?>/> Update contributor descriptions automatically when the feed tagline changes</label></td>
</tr>
<tr>
<th scope="row">Homepages:</th>
<td><label><input type="checkbox" name="hardcode_url" value="no"<?php echo (($hardcode['url']=='yes')?'':' checked="checked"');?>/> Update contributor homepages automatically when the feed link changes</label></td>
</tr>
<?php endif; ?>
</table>
<?php
} /* FeedWordPressFeedsPage::feed_information_box() */
function custom_settings_box ($page, $box = NULL) {
$postsSettings = $this->admin_page_href('posts-page.php', array(), $page->link);
?>
<p class="setting-description">These custom settings are special fields for the <strong>feed</strong> you are
syndicating, to be retrieved in templates using the <code>get_feed_meta()</code> function. They do not create
custom fields on syndicated <strong>posts</strong>. If you want to create custom fields that are applied to each
individual post from this feed, set up the settings in <a href="<?php print $postsSettings; ?>">Syndicated Posts</a>.</p>
<div id="postcustomstuff">
<table id="meta-list" cellpadding="3">
<tr>
<th>Key</th>
<th>Value</th>
<th>Action</th>
</tr>
<?php
$i = 0;
foreach ($page->link->settings as $key => $value) :
if (!preg_match("\007^((".implode(')|(', $page->special_settings)."))$\007i", $key)) :
?>
<tr style="vertical-align:top">
<th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo esc_html($key); ?>" />
<input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo esc_html($key); ?>" /></th>
<td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?>-value" name="notes[<?php echo $i; ?>][value]"><?php echo esc_html($value); ?></textarea></td>
<td width="10%"><select name="notes[<?php echo $i; ?>][action]">
<option value="update">save changes</option>
<option value="delete">delete this setting</option>
</select></td>
</tr>
<?php
$i++;
endif;
endforeach;
?>
<tr>
<th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?>][key1]" value="" /></th>
<td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea></td>
<td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td>
</tr>
</table>
</div> <!-- id="postcustomstuff" -->
<?php
}
function url_for_401 ($err) {
$ret = NULL;
if (is_wp_error($err)) :
if ($err->get_error_code()=='http_request_failed') :
$data = $err->get_error_data('http_request_failed');
if (is_array($data) and isset($data['status'])) :
if (401==$data['status']) :
$ret = $data['uri'];
endif;
endif;
endif;
endif;
return $ret;
}
function display_feedfinder () {
global $wpdb;
$lookup = (isset($_REQUEST['lookup']) ? $_REQUEST['lookup'] : NULL);
$auth = MyPHP::request('link_rss_auth_method');
$username = MyPHP::request('link_rss_username');
$password = MyPHP::request('link_rss_password');
$credentials = array(
"authentication" => $auth,
"username" => $username,
"password" => $password,
);
$feeds = array(); $feedSwitch = false; $current = null;
if ($this->for_feed_settings()) : // Existing feed?
$feedSwitch = true;
if (is_null($lookup)) :
// Switch Feed without a specific feed yet suggested
// Go to the human-readable homepage to look for
// auto-detection links
$lookup = $this->link->link->link_url;
$auth = $this->link->setting('http auth method');
$username = $this->link->setting('http username');
$password = $this->link->setting('http password');
// Guarantee that you at least have the option to
// stick with what works.
$current = $this->link->link->link_rss;
$feeds[] = $current;
endif;
$name = esc_html($this->link->link->link_name);
else: // Or a new subscription to add?
$name = "Subscribe to <code>".esc_html(feedwordpress_display_url($lookup))."</code>";
endif;
?>
<div class="wrap" id="feed-finder">
<h2>Feed Finder: <?php echo $name; ?></h2>
<?php
if ($feedSwitch) :
$this->display_alt_feed_box($lookup);
endif;
$finder = array();
if (!is_null($current)) :
$finder[$current] = new FeedFinder($current);
endif;
$finder[$lookup] = new FeedFinder($lookup);
foreach ($finder as $url => $ff) :
$feeds = array_merge($feeds, $ff->find(
/*url=*/ NULL,
/*params=*/ $credentials));
endforeach;
$feeds = array_values( // Renumber from 0..(N-1)
$feeds
);
// Allow for some simple FeedFinder results filtering
$feeds = apply_filters(
'feedwordpress_feedfinder_results',
$feeds,
array(
"url" => $lookup,
"auth" => $auth,
"username" => $username,
"password" => $password,
"finder" => $finder,
),
$this
);
if (count($feeds) > 0):
if ($feedSwitch) :
?>
<h3>Feeds Found</h3>
<?php
endif;
if (count($feeds) > 1) :
$option_template = 'Option %d: ';
$form_class = ' class="multi"';
?>
<p><strong>This web page provides at least <?php print count($feeds); ?> different feeds.</strong> These feeds may provide the same information
in different formats, or may track different items. (You can check the Feed Information and the
Sample Item for each feed to get an idea of what the feed provides.) Please select the feed that you'd like to subscribe to.</p>
<?php
else :
$option_template = '';
$form_class = '';
endif;
global $fwp_credentials;
foreach ($feeds as $key => $f):
$ofc = $fwp_credentials;
$fwp_credentials = $credentials; // Set
$pie = FeedWordPress::fetch($f, array("cache" => false));
$fwp_credentials = $ofc; // Re-Set
$rss = (is_wp_error($pie) ? $pie : new MagpieFromSimplePie($pie));
if ($this->url_for_401($pie)) :
$this->display_alt_feed_box($lookup, array(
"err" => $pie,
"auth" => $auth,
"username" => $username,
"password" => $password
));
continue;
endif;
if ($rss and !is_wp_error($rss)):
$feed_link = (isset($rss->channel['link'])?$rss->channel['link']:'');
$feed_title = (isset($rss->channel['title'])?$rss->channel['title']:$feed_link);
$feed_type = ($rss->feed_type ? $rss->feed_type : 'Unknown');
$feed_version_template = '%.1f';
$feed_version = $rss->feed_version;
else :
// Give us some sucky defaults
$feed_title = feedwordpress_display_url($lookup);
$feed_link = $lookup;
$feed_type = 'Unknown';
$feed_version_template = '';
$feed_version = '';
endif;
?>
<form<?php print $form_class; ?> action="<?php print $this->form_action('syndication.php'); ?>" method="post">
<div class="inside"><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_switchfeed'); ?>
<?php
$classes = array('feed-found'); $currentFeed = '';
if (!is_null($current) and $current==$f) :
$classes[] = 'current';
$currentFeed = ' (currently subscribed)';
endif;
if ($key%2) :
$classes[] = 'alt';
endif;
?>
<fieldset class="<?php print implode(" ", $classes); ?>">
<legend><?php printf($option_template, ($key+1)); print $feed_type." "; printf($feed_version_template, $feed_version); ?> feed<?php print $currentFeed; ?></legend>
<?php
$this->stamp_link_id();
// No feed specified = add new feed; we
// need to pass along a starting title
// and homepage URL for the new Link.
if (!$this->for_feed_settings()):
?>
<input type="hidden" name="feed_title" value="<?php echo esc_html($feed_title); ?>" />
<input type="hidden" name="feed_link" value="<?php echo esc_html($feed_link); ?>" />
<?php
endif;
?>
<input type="hidden" name="feed" value="<?php echo esc_html($f); ?>" />
<input type="hidden" name="action" value="switchfeed" />
<div>
<div class="feed-sample">
<?php
$link = NULL;
$post = NULL;
if (!is_wp_error($rss) and count($rss->items) > 0):
// Prepare to display Sample Item
$link = new MagpieMockLink(array('simplepie' => $pie, 'magpie' => $rss), $f);
$post = new SyndicatedPost(array('simplepie' => $rss->originals[0], 'magpie' => $rss->items[0]), $link);
?>
<h3>Sample Item</h3>
<ul>
<li><strong>Title:</strong> <a href="<?php echo $post->post['meta']['syndication_permalink']; ?>"><?php echo $post->post['post_title']; ?></a></li>
<li><strong>Date:</strong> <?php print date('d-M-y g:i:s a', $post->published()); ?></li>
</ul>
<div class="entry">
<?php print $post->post['post_content']; ?>
</div>
<?php
do_action('feedwordpress_feed_finder_sample_item', $f, $post, $link);
else:
if (is_wp_error($rss)) :
print '<div class="feed-problem">';
print "<h3>Problem:</h3>\n";
print "<p>FeedWordPress encountered the following error
when trying to retrieve this feed:</p>";
print '<p style="margin: 1.0em 3.0em"><code>'.$rss->get_error_message().'</code></p>';