This repository has been archived by the owner on May 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimplepie_wordpress_2.php
2208 lines (1953 loc) · 73.2 KB
/
simplepie_wordpress_2.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
/*
Plugin Name: SimplePie Plugin for WordPress
Version: 2.2.1
Plugin URI: http://simplepie.org/wiki/plugins/wordpress/simplepie_plugin_for_wordpress
Description: A fast and easy way to add RSS and Atom feeds to your WordPress blog. Go to <a href="options-general.php?page=simplepie_wordpress_2">Settings→SimplePie for WP</a> to adjust default settings.
Author: Ryan Parman
Author URI: http://simplepie.org/
*/
/*********************************************************************************/
/**
* Define version for the plugin.
*/
define('SIMPLEPIE_PLUGIN', '2.2.1');
/**
* Expected minimum SimplePie build number.
*/
define('EXPECTED_SIMPLEPIE_VERSION', '1.1.1');
/**
* Expected minimum SimplePie build number.
*/
define('EXPECTED_SIMPLEPIE_BUILD', 20080315205903);
/**
* WordPress version.
*/
define('WP_VERSION', get_bloginfo('version'));
/**
* Web-accessible wp-content directory.
*/
define('WP_CONTENT_WEB', get_bloginfo('wpurl') . '/wp-content');
/**
* Web-accessible control panel page.
*/
define('WP_CPANEL', get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=simplepie_wordpress_2');
/**
* Set absolute SimplePie plugin directory.
*/
define('SIMPLEPIE_PLUGINDIR', dirname(__FILE__));
/**
* Get only the name of the plugin directory.
*/
define('SIMPLEPIE_PLUGINDIR_NAME', pathinfo(dirname(__FILE__), PATHINFO_BASENAME));
/**
* Web-accessible URL for the plugin directory.
*/
define('SIMPLEPIE_PLUGINDIR_WEB', WP_CONTENT_WEB . '/plugins/' . SIMPLEPIE_PLUGINDIR_NAME);
/**
* Default cache directory.
*/
define('SIMPLEPIE_CACHEDIR', dirname(dirname(SIMPLEPIE_PLUGINDIR)) . '/cache');
/*********************************************************************************/
/**
* Wrapper class for static functions
*/
class SimplePie_WordPress
{
/**
* Shortens path names based on the location of /wp-content/.
*/
function clean_wp_path($path)
{
if ($wp_path = stristr($path, 'wp-content'))
{
return '[WP Install]/' . $wp_path;
}
else
{
return $path;
}
}
/**
* Re-implement str_split() in PHP 4.x
* Written by dacmeaux at gmail dot com, posted to http://us3.php.net/str_split
* Modified by Ryan Parman, http://simplepie.org
*/
function str_split($text)
{
// If str_split() exists in PHP, use it.
if (function_exists('str_split'))
{
return str_split($text);
}
// Otherwise, emulate it.
else
{
$array = array();
$text_len = strlen($text);
for ($i = 0; $i < $text_len; $i++)
{
$key = NULL;
for ($j = 0; $j < 1; $j++)
{
$key .= $text[$i];
}
array_push($array, $key);
}
return $array;
}
}
/**
* version_compare() is being stupid, so let's work around it.
*/
function convert_to_version($s)
{
$s = strval($s);
$s = SimplePie_WordPress::str_split($s);
$s = implode('.', $s);
return $s;
}
/**
* Get a list of files from a given directory.
*/
function get_files($dir, $extension)
{
$temp = array();
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if (!is_dir($file))
{
// Determine location of the file
$location = $dir . $file;
// Determine label for the template file
$label = explode($extension, $file);
$label = str_replace('_', ' ', $label[0]);
$label = str_replace('-', ' ', $label);
$label = str_replace('.', ' ', $label);
$label = ucwords($label);
// Add them to the array.
$temp[] = array('location' => $location, 'label' => $label);
}
}
closedir($dh);
}
}
return $temp;
}
/**
* Handles the post-processing of data.
*/
function post_process($swap, $s)
{
if (class_exists('SimplePie_PostProcess'))
{
$swap = strtolower($swap);
$post = new SimplePie_PostProcess;
if (method_exists($post, $swap))
{
$s = SimplePie_PostProcess::$swap($s);
}
}
return $s;
}
/**
* Delete all related values in the database.
*/
function delete_values()
{
// General settings
delete_option('simplepie_template');
delete_option('simplepie_items');
delete_option('simplepie_items_per_feed');
delete_option('simplepie_date_format');
delete_option('simplepie_enable_cache');
delete_option('simplepie_set_cache_location');
delete_option('simplepie_set_cache_duration');
delete_option('simplepie_enable_order_by_date');
delete_option('simplepie_set_timeout');
// Text-shortening settings
delete_option('simplepie_truncate_feed_title');
delete_option('simplepie_truncate_feed_description');
delete_option('simplepie_truncate_item_title');
delete_option('simplepie_truncate_item_description');
// Advanced settings
delete_option('simplepie_processing');
delete_option('simplepie_locale');
delete_option('simplepie_local_date_format');
delete_option('simplepie_strip_htmltags');
delete_option('simplepie_strip_attributes');
delete_option('simplepie_set_max_checked_feeds');
delete_option('simplepie_plugin_installed');
}
}
/**
* Set if this we're asked to reset the settings.
*/
if (isset($_POST['reset_all_settings']))
{
SimplePie_WordPress::delete_values();
}
/**
* Set default options if they're not already set.
*/
if (!get_option('simplepie_template'))
{
update_option('simplepie_template', SIMPLEPIE_PLUGINDIR . '/templates/default.tmpl', 'The template to use for displaying feeds.');
}
if (!get_option('simplepie_items'))
{
update_option('simplepie_items', 0, 'The number of feed items to display by default.');
}
if (!get_option('simplepie_items_per_feed'))
{
update_option('simplepie_items_per_feed', 0, 'The number of feed items to display per feed when using Multifeeds.');
}
if (!get_option('simplepie_date_format'))
{
update_option('simplepie_date_format', 'l, j F Y, g:i a', 'The default format for English dates.');
}
if (!get_option('simplepie_enable_cache'))
{
update_option('simplepie_enable_cache', 1, 'Whether the feeds should be cached or not.');
}
if (!get_option('simplepie_set_cache_location'))
{
update_option('simplepie_set_cache_location', SIMPLEPIE_CACHEDIR, 'The file system location for the cache.');
}
if (!get_option('simplepie_set_cache_duration'))
{
update_option('simplepie_set_cache_duration', 3600, 'The number of seconds that feed data should be cached for before asking the feed if it\'s been changed.');
}
if (!get_option('simplepie_enable_order_by_date'))
{
update_option('simplepie_enable_order_by_date', 1, 'Feeds items aren\'t always in chronological order. This fixes that.');
}
if (!get_option('simplepie_set_timeout'))
{
update_option('simplepie_set_timeout', 10, 'Number of seconds to wait for a remote feed to respond before giving up.');
}
if (!get_option('simplepie_truncate_feed_title'))
{
update_option('simplepie_truncate_feed_title', 0, 'Number of characters to shorten the text to.');
}
if (!get_option('simplepie_truncate_feed_description'))
{
update_option('simplepie_truncate_feed_description', 200, 'Number of characters to shorten the text to.');
}
if (!get_option('simplepie_truncate_item_title'))
{
update_option('simplepie_truncate_item_title', 0, 'Number of characters to shorten the text to.');
}
if (!get_option('simplepie_truncate_item_description'))
{
update_option('simplepie_truncate_item_description', 200, 'Number of characters to shorten the text to.');
}
if (!get_option('simplepie_processing'))
{
update_option('simplepie_processing', SIMPLEPIE_PLUGINDIR . '/processing/none.php', 'The rules to use for post-processing feeds.');
}
if (!get_option('simplepie_locale'))
{
update_option('simplepie_locale', 'auto', 'The locale for the website.');
}
if (!get_option('simplepie_local_date_format'))
{
update_option('simplepie_local_date_format', '%A, %e %B %Y, %H:%M', 'The default format for localized dates.');
}
if (!get_option('simplepie_strip_htmltags'))
{
update_option('simplepie_strip_htmltags', 'base blink body doctype embed font form frame frameset html iframe input marquee meta noscript object param script style', 'The HTML tags to be stripped by default.');
}
if (!get_option('simplepie_strip_attributes'))
{
update_option('simplepie_strip_attributes', 'bgsound class expr id style onclick onerror onfinish onmouseover onmouseout onfocus onblur lowsrc dynsrc', 'The HTML attributes to be stripped by default.');
}
if (!get_option('simplepie_set_max_checked_feeds'))
{
update_option('simplepie_set_max_checked_feeds', 10, 'The number of links in the document to check for feeds.');
}
/*********************************************************************************/
/**
* Add menu item to Options menu.
*/
function simplepie_options()
{
if (function_exists('add_options_page'))
{
add_options_page('SimplePie for WP', 'SimplePie for WP', 8, 'simplepie_wordpress_2', 'simplepie_options_page');
}
}
/**
* Trigger the adding of the menu option.
*/
add_action('admin_menu', 'simplepie_options');
/**
* Draw normal options page.
*/
function simplepie_options_page()
{
if (isset($_POST['reset_all_settings']) && !empty($_POST['reset_all_settings']))
{
// Display the reset message.
echo '<div id="message" class="updated fade"><p><strong>All of your options for this plugin have been reset to their default values.</strong></p></div>';
}
else if (isset($_POST['submitted']) && !empty($_POST['submitted']))
{
/**
* Get form data
*/
// General settings
$simplepie_template = (string) $_POST['simplepie_template'];
$simplepie_items = (integer) $_POST['simplepie_items'];
$simplepie_items_per_feed = (integer) $_POST['simplepie_items_per_feed'];
$simplepie_date_format = (string) $_POST['simplepie_date_format'];
$simplepie_enable_cache = (bool) $_POST['simplepie_enable_cache'];
$simplepie_set_cache_location = (string) $_POST['simplepie_set_cache_location'];
$simplepie_set_cache_duration = (integer) $_POST['simplepie_set_cache_duration'];
$simplepie_enable_order_by_date = (bool) $_POST['simplepie_enable_order_by_date'];
$simplepie_set_timeout = (integer) $_POST['simplepie_set_timeout'];
// Text-shortening settings
$simplepie_truncate_feed_title = (integer) $_POST['simplepie_truncate_feed_title'];
$simplepie_truncate_feed_description = (integer) $_POST['simplepie_truncate_feed_description'];
$simplepie_truncate_item_title = (integer) $_POST['simplepie_truncate_item_title'];
$simplepie_truncate_item_description = (integer) $_POST['simplepie_truncate_item_description'];
// Advanced settings
$simplepie_processing = (string) $_POST['simplepie_processing'];
$simplepie_locale = (string) $_POST['simplepie_locale'];
$simplepie_local_date_format = (string) $_POST['simplepie_local_date_format'];
$simplepie_strip_htmltags = (string) $_POST['simplepie_strip_htmltags'];
$simplepie_strip_attributes = (string) $_POST['simplepie_strip_attributes'];
$simplepie_set_max_checked_feeds = (integer) $_POST['simplepie_set_max_checked_feeds'];
/**
* Update plugin options
*/
// General settings
update_option("simplepie_template", $simplepie_template);
update_option("simplepie_items", $simplepie_items);
update_option("simplepie_items_per_feed", $simplepie_items_per_feed);
update_option("simplepie_date_format", $simplepie_date_format);
update_option("simplepie_enable_cache", $simplepie_enable_cache);
update_option("simplepie_set_cache_location", $simplepie_set_cache_location);
update_option("simplepie_set_cache_duration", $simplepie_set_cache_duration);
update_option("simplepie_enable_order_by_date", $simplepie_enable_order_by_date);
update_option("simplepie_set_timeout", $simplepie_set_timeout);
// Text-shortening settings
update_option("simplepie_truncate_feed_title", $simplepie_truncate_feed_title);
update_option("simplepie_truncate_feed_description", $simplepie_truncate_feed_description);
update_option("simplepie_truncate_item_title", $simplepie_truncate_item_title);
update_option("simplepie_truncate_item_description", $simplepie_truncate_item_description);
// Advanced settings
update_option("simplepie_processing", $simplepie_processing);
update_option("simplepie_locale", $simplepie_locale);
update_option("simplepie_local_date_format", $simplepie_local_date_format);
update_option("simplepie_strip_htmltags", $simplepie_strip_htmltags);
update_option("simplepie_strip_attributes", $simplepie_strip_attributes);
update_option("simplepie_set_max_checked_feeds", $simplepie_set_max_checked_feeds);
// Display the updated message.
echo '<div id="message" class="updated fade"><p><strong>Your options were saved successfully!</strong></p></div>';
}
if (get_option('simplepie_locale') && get_option('simplepie_locale') != 'auto')
{
setlocale(LC_TIME, get_option('simplepie_locale'));
}
?>
<style type="text/css">
.submit input.warning {
background-color:#c00;
background-image:none;
border-color:#f00 #900 #900 #f00;
color:#fff;
}
.submit {
text-align:right;
background-color:#e9f5ff;
margin:0;
padding:15px;
}
.submit input {
font-size:115%;
padding:5px 10px;
border:1px solid #999;
}
.warning {
background-color:#c00;
color:#fff;
padding:1px 2px;
}
div.wrap h3 {
font-size:20px;
padding-top:10px;
border-bottom:1px solid #000;
}
code {
color:#000080;
background-color:#eef;
font-size:0.95em;
}
input.text {
background-color:#e9f5ff;
color:#333;
border:1px solid #ccc;
}
input.text:focus {
background-color:#ffc;
color:#000;
border:1px solid #f90;
}
input#simplepie_set_cache_location {
width:90%;
}
td.break,
td.break-noborder {
padding:15px 0;
}
td.break {
border-bottom:1px solid #999;
}
.footnote,
.footnote a {
font-size:12px;
line-height:1.3em;
color:#aaa;
}
.footnote em {
background-color:transparent;
font-style:italic;
}
.footnote code {
background-color:transparent;
font:11px/14px monospace;
color:#fff;
background-color:#ccc;
padding:0 1px;
}
</style>
<form method="post" action="" name="simplepie" onsubmit="document.forms['simplepie'].simplepie_set_cache_duration.value = parseFloat(document.forms['simplepie'].simplepie_set_cache_duration.value) * parseInt(document.forms['simplepie'].simplepie_cache_duration_units[document.forms['simplepie'].simplepie_cache_duration_units.selectedIndex].value);document.forms['simplepie'].simplepie_cache_duration_units.selectedIndex=0;">
<?php wp_nonce_field('update-options') ?>
<div class="wrap">
<h2>SimplePie Plugin for WordPress</h2>
<h3>Installation Status</h3>
<p>This information will help with debugging in case something goes wrong.</p>
<fieldset class="options">
<table width="100%" cellspacing="2" cellpadding="5" class="optiontable editform">
<tr>
<th width="33%" scope="row" valign="top">Version of WordPress:</th>
<td valign="top"><img src="<?php echo SIMPLEPIE_PLUGINDIR_WEB; ?>/images/ok.png" /> <?php echo WP_VERSION; ?></td>
</tr>
<tr>
<th width="33%" scope="row" valign="top">Version of <a href="http://wordpress.org/extend/plugins/simplepie-plugin-for-wordpress/">SimplePie Plugin for WordPress</a>:</th>
<td valign="top"><img src="<?php echo SIMPLEPIE_PLUGINDIR_WEB; ?>/images/ok.png" /> <?php echo SIMPLEPIE_PLUGIN; ?></td>
</tr>
<tr>
<th width="33%" scope="row" valign="top">Version of <a href="http://wordpress.org/extend/plugins/simplepie-core/">SimplePie Core</a>:</th>
<?php if ($e = version_compare(SimplePie_WordPress::convert_to_version(SIMPLEPIE_BUILD), SimplePie_WordPress::convert_to_version(EXPECTED_SIMPLEPIE_BUILD)) > -1): ?>
<td valign="top"><img src="<?php echo SIMPLEPIE_PLUGINDIR_WEB; ?>/images/ok.png" /> <?php echo SIMPLEPIE_VERSION; ?> (<a href="options-general.php?page=simplepie_core">Details</a>)</td>
<?php elseif (!defined('SIMPLEPIE_BUILD')): ?>
<td valign="top"><img src="<?php echo SIMPLEPIE_PLUGINDIR_WEB; ?>/images/error.png" /> <span class="warning">None</span> — Please download and install <a href="http://wordpress.org/extend/plugins/simplepie-core/">SimplePie Core</a>.<p class="footnote">This plugin requires <a href="http://wordpress.org/extend/plugins/simplepie-core/">SimplePie Core</a> (version <?php echo EXPECTED_SIMPLEPIE_VERSION; ?>) to be installed. Check out the <a href="http://codex.wordpress.org/Managing_Plugins#Installing_Plugins">"Installing Plugins"</a> documentation at the WordPress site for help.</p></td>
<?php else: ?>
<td valign="top"><img src="<?php echo SIMPLEPIE_PLUGINDIR_WEB; ?>/images/error.png" /> <span class="warning"><?php echo SIMPLEPIE_VERSION; ?></span> — This version is out-of-date. Please update <a href="http://wordpress.org/extend/plugins/simplepie-core/">SimplePie Core</a> to the latest version.<p class="footnote"><a href="http://wordpress.org/extend/plugins/simplepie-core/">SimplePie Core</a> (version <?php echo EXPECTED_SIMPLEPIE_VERSION; ?> or newer) is required. If you already have the latest version, you might have a situation where another plugin has bundled SimplePie and that plugin has loaded before SimplePie Core, causing strange things to happen. If so, try either disabling the other plugin or checking for an updated version that has been updated to utilize SimplePie Core for best compatibility.</p></td>
<?php endif; ?>
</tr>
<tr>
<th width="33%" scope="row" valign="top">Plugin install location:</th>
<td valign="top"><img src="<?php echo SIMPLEPIE_PLUGINDIR_WEB; ?>/images/ok.png" /> <code><?php echo SimplePie_WordPress::clean_wp_path(SIMPLEPIE_PLUGINDIR); ?>/</code>.</td>
</tr>
<tr>
<th width="33%" scope="row" valign="top">Cache directory writable?:</th>
<?php if (!get_option('simplepie_enable_cache')): ?>
<td valign="top"><img src="<?php echo SIMPLEPIE_PLUGINDIR_WEB; ?>/images/error.png" /> <span class="warning">Cache disabled!</span>
<p class="footnote">You have chosen to disable caching. Be aware that this will negatively impact performance.</p></td>
<?php elseif (!is_dir(get_option('simplepie_set_cache_location'))): ?>
<td valign="top"><img src="<?php echo SIMPLEPIE_PLUGINDIR_WEB; ?>/images/error.png" /> <span class="warning">Cache directory does not exist!</span>
<p class="footnote">Please either create a <a href="http://simplepie.org/wiki/faq/file_permissions">writable</a> cache directory at <code><?php echo get_option('simplepie_set_cache_location'); ?></code>, or change the preferred location below.</p></td>
<?php elseif (!is_writable(get_option('simplepie_set_cache_location'))): ?>
<td valign="top"><img src="<?php echo SIMPLEPIE_PLUGINDIR_WEB; ?>/images/error.png" /> <span class="warning">Cache directory not writable!</span>
<p class="footnote">Please make sure that the cache directory at <code><?php echo get_option('simplepie_set_cache_location'); ?></code> is <a href="http://simplepie.org/wiki/faq/file_permissions">writable by the server</a>, or change the preferred location below.</p></td>
<?php else: ?>
<td valign="top"><img src="<?php echo SIMPLEPIE_PLUGINDIR_WEB; ?>/images/ok.png" /> <code><?php echo SimplePie_WordPress::clean_wp_path(get_option('simplepie_set_cache_location')); ?></code> exists and is writable.</td>
<?php endif; ?>
</tr>
</table>
</fieldset>
<h3>General Settings</h3>
<p>Most people should feel comfortable tweaking and modifying these settings. These settings are the defaults for SimplePie, but you can override any individual feed instance on the fly by passing additional parameters to it. See the <a href="http://simplepie.org/wiki/plugins/wordpress/simplepie_plugin_for_wordpress">documentation</a> to learn how to do this.</p>
<fieldset class="options">
<table width="100%" cellspacing="2" cellpadding="5" class="optiontable editform">
<tr>
<th width="33%" scope="row" valign="top"><h4>Layout template:</h4></th>
<td class="break"><select name="simplepie_template">
<?php
$templates = SimplePie_WordPress::get_files(SIMPLEPIE_PLUGINDIR . '/templates/', '.tmpl');
sort($templates);
foreach($templates as $template)
{
echo '<option value="' . $template['location'] . '">' . $template['label'] . '</option>' . "\n";
}
?>
</select>
<p class="footnote">Add or edit templates in the following directory:<br /><code><?php echo SimplePie_WordPress::clean_wp_path(SIMPLEPIE_PLUGINDIR); ?>/templates/</code></p></td>
</tr>
<tr>
<th width="33%" scope="row" valign="top"><h4>Number of items to display:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_items" value="<?php echo get_option('simplepie_items'); ?>" size="3" maxlength="3" /> items
<p class="footnote">By default, how many feed items (i.e. posts) to display. Use <code>0</code> for ALL.</p></td>
</tr>
<tr>
<th width="33%" scope="row" valign="top"><h4>Number of items to display per feed:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_items_per_feed" value="<?php echo get_option('simplepie_items_per_feed'); ?>" size="3" maxlength="3" /> items
<p class="footnote">Limit the number of items (i.e. posts) to use per-feed when merging multiple feeds. Use <code>0</code> for ALL.</p></td>
</tr>
<tr>
<th width="33%" scope="row" valign="top"><h4>Default format for English dates:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_date_format" value="<?php echo get_option('simplepie_date_format'); ?>" /> (i.e. <?php echo date(get_option('simplepie_date_format')); ?>)
<p class="footnote">Supports any format supported by PHP's <a href="http://php.net/date">date()</a> function. Only used with <code>{ITEM_DATE}</code> and <code>{ITEM_DATE_UTC}</code>.</p></td>
</tr>
<tr>
<th width="33%" scope="row" valign="top"><h4>Should we use caching:</h4></th>
<td class="break"><select name="simplepie_enable_cache" onchange="simplepie_color_temp=document.body.style.color;if(document.forms['simplepie'].simplepie_enable_cache.value=='false'){document.forms['simplepie'].simplepie_set_cache_duration.disabled=true;document.forms['simplepie'].simplepie_cache_duration_units.disabled=true;document.getElementById('set_cache_duration_title').style.color='#cccccc';}else{document.forms['simplepie'].simplepie_set_cache_duration.disabled=false;document.forms['simplepie'].simplepie_cache_duration_units.disabled=false;document.getElementById('set_cache_duration_title').style.color=simplepie_color_temp;}">
<option value="1">Yes (Recommended)</option>
<option value="0">No</option>
</select>
<p class="footnote">Disabling cache will negatively impact performance (and anger feed creators), but will ensure that the very freshest version of the feed is displayed at all times.</p></td>
</tr>
<tr>
<th width="33%" scope="row" valign="top"><h4>Cache storage location:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_set_cache_location" id="simplepie_set_cache_location" value="<?php echo get_option('simplepie_set_cache_location'); ?>" />
<p class="footnote">This should be a complete, writable file system location. Default value is auto-detected, but is not always correct for all WordPress installations. Adjust only if cache isn't working.</p></td>
</tr>
<tr>
<th width="33%" scope="row" id="set_cache_duration_title" valign="top"><h4>How long should we cache for?:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_set_cache_duration" value="<?php echo get_option('simplepie_set_cache_duration'); ?>" size="10" />
<select name="simplepie_cache_duration_units">
<option value="1">Seconds</option>
<option value="60">Minutes</option>
<option value="3600">Hours</option>
<option value="87840">Days</option>
</select>
<p class="footnote">How long before we ask the feed if it's been updated? Recommend 1 hour (3600 seconds).</p></td>
</tr>
<tr>
<th width="33%" scope="row" valign="top"><h4>Re-order items by date:</h4></th>
<td class="break"><select name="simplepie_enable_order_by_date">
<option value="1">Yes (Recommended)</option>
<option value="0">No</option>
</select>
<p class="footnote">Some feeds have items that are not chronologically ordered. This fixes that.</p></td>
</tr>
<tr>
<th width="33%" scope="row" valign="top"><h4>Seconds to wait while fetching data:</h4></th>
<td class="break-noborder"><input type="text" class="text" name="simplepie_set_timeout" value="<?php echo get_option('simplepie_set_timeout'); ?>" size="3" maxlength="3" /> seconds
<p class="footnote">Some feeds are on slow servers, so increasing this time allows more time to fetch the feed.</p></td>
</tr>
</table>
<p class="submit"><input type="submit" name="submitted" value="<?php _e('Update Options »') ?>" /></p>
</fieldset>
<h3>Text-Shortening Settings</h3>
<p>Most people should feel comfortable tweaking and modifying these settings. These settings allow you to set default lengths for truncated text, but you can override any individual feed instance on the fly by passing additional parameters to it. See the <a href="http://simplepie.org/wiki/plugins/wordpress/simplepie_plugin_for_wordpress">documentation</a> to learn how to do this.</p>
<p>These settings only apply to the <code>TRUNCATE_*</code> template tags: <code>{TRUNCATE_FEED_DESCRIPTION}</code>, <code>{TRUNCATE_ITEM_PARENT_DESCRIPTION}</code>, <code>{TRUNCATE_FEED_TITLE}</code>, <code>{TRUNCATE_ITEM_PARENT_TITLE}</code>, <code>{TRUNCATE_ITEM_DESCRIPTION}</code>, and <code>{TRUNCATE_ITEM_TITLE}</code>.</p>
<fieldset class="options">
<table width="100%" cellspacing="2" cellpadding="5" class="optiontable editform">
<tr valign="top">
<th width="33%" scope="row" valign="top"><h4>Length for shortened feed titles:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_truncate_feed_title" value="<?php echo get_option('simplepie_truncate_feed_title'); ?>" size="5" maxlength="5" /> characters
<p class="footnote">Strips HTML, linebreaks, and converts entities first. Set <code>0</code> to clean (but not shorten) the text.</p></td>
</tr>
<tr valign="top">
<th width="33%" scope="row" valign="top"><h4>Length for shortened feed descriptions:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_truncate_feed_description" value="<?php echo get_option('simplepie_truncate_feed_description'); ?>" size="5" maxlength="5" /> characters
<p class="footnote">Strips HTML, linebreaks, and converts entities first. Set <code>0</code> to clean (but not shorten) the text.</p></td>
</tr>
<tr valign="top">
<th width="33%" scope="row" valign="top"><h4>Length for shortened item titles:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_truncate_item_title" value="<?php echo get_option('simplepie_truncate_item_title'); ?>" size="5" maxlength="5" /> characters
<p class="footnote">Strips HTML, linebreaks, and converts entities first. Set <code>0</code> to clean (but not shorten) the text.</p></td>
</tr>
<tr valign="top">
<th width="33%" scope="row" valign="top"><h4>Length for shortened item descriptions:</h4></th>
<td class="break-noborder"><input type="text" class="text" name="simplepie_truncate_item_description" value="<?php echo get_option('simplepie_truncate_item_description'); ?>" size="5" maxlength="5" /> characters
<p class="footnote">Strips HTML, linebreaks, and converts entities first. Set <code>0</code> to clean (but not shorten) the text.</p></td>
</tr>
</table>
<p class="submit"><input type="submit" name="submitted" value="<?php _e('Update Options »') ?>" /></p>
</fieldset>
<h3>Advanced Settings</h3>
<p>These settings should only be modified if you know what you're doing.</p>
<fieldset class="options">
<table width="100%" cellspacing="2" cellpadding="5" class="optiontable editform">
<tr valign="top">
<th width="33%" scope="row" valign="top"><h4>Content Post-Processing Rules:</h4></th>
<td class="break"><select name="simplepie_processing">
<?php
$processes = SimplePie_WordPress::get_files(SIMPLEPIE_PLUGINDIR . '/processing/', '.php');
sort($processes);
foreach($processes as $process)
{
echo '<option value="' . $process['location'] . '">' . $process['label'] . '</option>' . "\n";
}
?>
</select>
<p class="footnote">Add or edit processing rules in the following directory:<br /><code><?php echo SimplePie_WordPress::clean_wp_path(SIMPLEPIE_PLUGINDIR); ?>/processing/</code>.</p></td>
</tr>
<tr valign="top">
<th width="33%" scope="row" valign="top"><h4>Locale for the website:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_locale" value="<?php echo get_option('simplepie_locale'); ?>" />
<p class="footnote">Switch the locale for the website to use. There are a variety of formats that can be used, depending on your server setup. See PHP's <a href="http://php.net/setlocale">setlocale()</a> function. Use <code>auto</code> to use the server's default.</p></td>
</tr>
<tr valign="top">
<th width="33%" scope="row" valign="top"><h4>Default format for localized dates:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_local_date_format" value="<?php echo get_option('simplepie_local_date_format'); ?>" /> (i.e. <?php echo strftime(get_option('simplepie_local_date_format')); ?>)
<p class="footnote">Supports any format supported by PHP's <a href="http://php.net/strftime">strftime()</a> function. Only used with <code>{ITEM_LOCAL_DATE}</code> and <code>{ITEM_LOCAL_DATE_UTC}</code>.</p></td>
</tr>
<tr valign="top">
<th width="33%" scope="row" valign="top"><h4>HTML tags to strip out of feeds:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_strip_htmltags" value="<?php echo get_option('simplepie_strip_htmltags'); ?>" size="50" /> (space separated)
<p class="footnote">These tags will be stripped from the output. By default, removes potentially dangerous tags as well as some deprecated ones.</p></td>
</tr>
<tr valign="top">
<th width="33%" scope="row" valign="top"><h4>HTML attributes to strip out of feeds:</h4></th>
<td class="break"><input type="text" class="text" name="simplepie_strip_attributes" value="<?php echo get_option('simplepie_strip_attributes'); ?>" size="50" /> (space separated)
<p class="footnote">These attributes will be stripped from the output. By default, removes potentially dangerous attributes as well as some deprecated ones.</p></td>
</tr>
<tr valign="top">
<th width="33%" scope="row" valign="top"><h4>Number of links to check during auto-discovery:</h4></th>
<td class="break-noborder"><input type="text" class="text" name="simplepie_set_max_checked_feeds" value="<?php echo get_option('simplepie_set_max_checked_feeds'); ?>" size="3" maxlength="3" /> links
<p class="footnote">SimplePie's ultra-liberal feed locator satisfies points 1–6 of Mark Pilgrim's <a href="http://diveintomark.org/archives/2002/08/15/ultraliberal_rss_locator">feed usability rant</a>. This tells how many links to check.</p></td>
</tr>
</table>
<p class="submit"><input type="submit" name="submitted" value="<?php _e('Update Options »') ?>" /></p>
</fieldset>
</div>
</form>
<br /><br /><br /><br /><br />
<form method="post" action="" name="simplepie">
<?php wp_nonce_field('update-options') ?>
<div class="wrap">
<h2>Reset ALL Settings</h2>
<p>Wipe out ALL custom settings (except for changes or additions to templates and post-processing files), and reset everything back to their default values.</p>
<fieldset class="options">
<input type="hidden" name="reset_all_settings" value="true" />
<p class="submit"><input type="submit" name="submitted" class="warning" value="Reset ALL settings for this plugin to their default values!" /></p>
</fieldset>
</div>
</form>
<script type="text/javascript" charset="utf-8">
// Set the correct value for simplepie_template
for (var x = 0; x < document.forms['simplepie'].simplepie_template.length; x++) {
if (document.forms['simplepie'].simplepie_template[x].value == "<?php echo get_option('simplepie_template'); ?>") {
document.forms['simplepie'].simplepie_template.selectedIndex = x;
break;
}
}
// Set the correct value for simplepie_enable_cache
for (var x = 0; x < document.forms['simplepie'].simplepie_enable_cache.length; x++) {
if (document.forms['simplepie'].simplepie_enable_cache[x].value == "<?php echo get_option('simplepie_enable_cache'); ?>") {
document.forms['simplepie'].simplepie_enable_cache.selectedIndex = x;
break;
}
}
// Set the correct value for simplepie_enable_order_by_date
for (var x = 0; x < document.forms['simplepie'].simplepie_enable_order_by_date.length; x++) {
if (document.forms['simplepie'].simplepie_enable_order_by_date[x].value == "<?php echo get_option('simplepie_enable_order_by_date'); ?>") {
document.forms['simplepie'].simplepie_enable_order_by_date.selectedIndex = x;
break;
}
}
// Set the correct value for simplepie_processing
for (var x = 0; x < document.forms['simplepie'].simplepie_processing.length; x++) {
if (document.forms['simplepie'].simplepie_processing[x].value == "<?php echo get_option('simplepie_processing'); ?>") {
document.forms['simplepie'].simplepie_processing.selectedIndex = x;
break;
}
}
</script>
<?php
}
/**
* Function that truncates text.
*/
function SimplePie_Truncate($s, $length = 0)
{
// Strip out HTML tags.
$s = strip_tags($s);
// Strip out superfluous whitespace and line breaks.
$s = preg_replace('/(\s+)/', ' ', $s);
// Avoid PHP 4.x bug. Only do this if we're on PHP5. http://bugs.php.net/25670
if (SIMPLEPIE_PHP5)
{
// Convert all HTML entities to their character counterparts.
$s = html_entity_decode($s, ENT_QUOTES, 'UTF-8');
}
// Shorten the string to the number of characters requested, and strip wrapping whitespace.
if ($length > 0 && strlen($s) > $length)
{
$s = trim(substr($s, 0, $length)) . '. […]';
}
// Return the value.
return $s;
}
/**
* Take the namespaced function and make it global so that it can be called by usort().
*/
function sort_items($a, $b)
{
return SimplePie::sort_items($a, $b);
}
/**
* The actual function that can be called on webpages.
*/
function SimplePieWP($feed_url, $options = null)
{
// Quit if the SimplePie class isn't loaded.
if (!class_exists('SimplePie'))
{
die('<p style="font-size:16px; line-height:1.5em; background-color:#c00; color:#fff; padding:10px; border:3px solid #f00; text-align:left;"><img src="' . SIMPLEPIE_PLUGINDIR_WEB . '/images/error.png" /> There is a problem with the SimplePie Plugin for WordPress. Check your <a href="' . WP_CPANEL . '" style="color:#ff0; text-decoration:underline;">Installation Status</a> for more information.</p>');
}
if (isset($locale) && !empty($locale) && $locale != 'auto')
{
setlocale(LC_TIME, $locale);
}
// Default general settings
$template = get_option('simplepie_template');
$items = get_option('simplepie_items');
$items_per_feed = get_option('simplepie_items_per_feed');
$date_format = get_option('simplepie_date_format');
$enable_cache = get_option('simplepie_enable_cache');
$set_cache_location = get_option('simplepie_set_cache_location');
$set_cache_duration = get_option('simplepie_set_cache_duration');
$enable_order_by_date = get_option('simplepie_enable_order_by_date');
$set_timeout = get_option('simplepie_set_timeout');
// Default text-shortening settings
$truncate_feed_title = get_option('simplepie_truncate_feed_title');
$truncate_feed_description = get_option('simplepie_truncate_feed_description');
$truncate_item_title = get_option('simplepie_truncate_item_title');
$truncate_item_description = get_option('simplepie_truncate_item_description');
// Default advanced settings
$processing = get_option('simplepie_processing');
$locale = get_option('simplepie_locale');
$local_date_format = get_option('simplepie_local_date_format');
$strip_htmltags = get_option('simplepie_strip_htmltags');
$strip_attributes = get_option('simplepie_strip_attributes');
$set_max_checked_feeds = get_option('simplepie_set_max_checked_feeds');
// Overridden settings
if ($options)
{
// Fix the template location if one was passed in.
if (isset($options['template']) && !empty($options['template']))
{
$options['template'] = SIMPLEPIE_PLUGINDIR . '/templates/' . strtolower(str_replace(' ', '_', $options['template'])) . '.tmpl';
}
// Fix the processing location if one was passed in.
if (isset($options['processing']) && !empty($options['processing']))
{
$options['processing'] = SIMPLEPIE_PLUGINDIR . '/processing/' . strtolower(str_replace(' ', '_', $options['processing'])) . '.php';
}
extract($options);
}
// Load post-processing file.
if ($processing && $processing != '')
{
include_once($processing);
}
// If template doesn't exist, die.
if (!file_exists($template) || !is_readable($template))
{
die('<p style="font-size:16px; line-height:1.5em; background-color:#c00; color:#fff; padding:10px; border:3px solid #f00; text-align:left;"><img src="' . SIMPLEPIE_PLUGINDIR_WEB . '/images/error.png" /> The SimplePie template file is not readable by WordPress. Check the <a href="' . WP_CPANEL . '" style="color:#ff0; text-decoration:underline;">WordPress Control Panel</a> for more information.</p>');
}
// Initialize SimplePie
$feed = new SimplePie();
$feed->set_feed_url($feed_url);
$feed->enable_cache($enable_cache);
$feed->set_item_limit($items_per_feed);
$feed->set_cache_location($set_cache_location);
$feed->set_cache_duration($set_cache_duration);
$feed->enable_order_by_date($enable_order_by_date);
$feed->set_timeout($set_timeout);
$feed->strip_htmltags(explode(' ', $strip_htmltags));
$feed->strip_attributes(explode(' ', $strip_attributes));
$feed->set_max_checked_feeds($set_max_checked_feeds);
$feed->init();
// Load up the selected template file
$handle = fopen($template, 'r');
$tmpl = fread($handle, filesize($template));
fclose($handle);
/**************************************************************************************************************/
// ERRORS
// I'm absolutely sure that there is a better way to do this.
// Define what we're looking for
$error_start_tag = '{IF_ERROR_BEGIN}';
$error_end_tag = '{IF_ERROR_END}';
$error_start_length = strlen($error_start_tag);
$error_end_length = strlen($error_end_tag);
// Find what we're looking for
$error_start_pos = strpos($tmpl, $error_start_tag);
$error_end_pos = strpos($tmpl, $error_end_tag);
$error_length_pos = $error_end_pos - $error_start_pos;
// Grab what we're looking for
$error_string = substr($tmpl, $error_start_pos + $error_start_length, $error_length_pos - $error_start_length);
$replacable_string = $error_start_tag . $error_string . $error_end_tag;
if ($error_message = $feed->error())
{
$tmpl = str_replace($replacable_string, $error_string, $tmpl);
$tmpl = str_replace('{ERROR_MESSAGE}', SimplePie_WordPress::post_process('ERROR_MESSAGE', $error_message), $tmpl);
}
elseif ($feed->get_item_quantity() == 0)
{
$tmpl = str_replace($replacable_string, $error_string, $tmpl);
$tmpl = str_replace('{ERROR_MESSAGE}', SimplePie_WordPress::post_process('ERROR_MESSAGE', 'There are no items in this feed.'), $tmpl);
}
else
{
$tmpl = str_replace($replacable_string, '', $tmpl);
}
/**************************************************************************************************************/
// FEED
// FEED_AUTHOR_EMAIL
if ($author = $feed->get_author())
{
if ($email = $author->get_email())
{
$tmpl = str_replace('{FEED_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('FEED_AUTHOR_EMAIL', $email), $tmpl);
}
else
{
$tmpl = str_replace('{FEED_AUTHOR_EMAIL}', '', $tmpl);
}
}
else
{
$tmpl = str_replace('{FEED_AUTHOR_EMAIL}', '', $tmpl);
}
// FEED_AUTHOR_LINK
if ($author = $feed->get_author())
{
if ($link = $author->get_link())
{
$tmpl = str_replace('{FEED_AUTHOR_LINK}', SimplePie_WordPress::post_process('FEED_AUTHOR_LINK', $link), $tmpl);
}
else
{
$tmpl = str_replace('{FEED_AUTHOR_LINK}', '', $tmpl);
}
}
else
{
$tmpl = str_replace('{FEED_AUTHOR_LINK}', '', $tmpl);
}
// FEED_AUTHOR_NAME
if ($author = $feed->get_author())
{
if ($name = $author->get_name())
{
$tmpl = str_replace('{FEED_AUTHOR_NAME}', SimplePie_WordPress::post_process('FEED_AUTHOR_NAME', $name), $tmpl);
}
else
{