forked from wp-plugins/powerpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
powerpress.php
3167 lines (2725 loc) · 111 KB
/
powerpress.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: Blubrry PowerPress
Plugin URI: http://create.blubrry.com/resources/powerpress/
Description: <a href="http://create.blubrry.com/resources/powerpress/" target="_blank">Blubrry PowerPress</a> is the No. 1 Podcasting plugin for WordPress. Developed by podcasters for podcasters; features include Simple and Advanced modes, multiple audio/video player options, subscribe to podcast tools, podcast SEO features, and more! Fully supports iTunes, Google Play, Stitcher, and Blubrry Podcasting directories, as well as all podcast applications and clients.
Version: 6.2.1
Author: Blubrry
Author URI: http://www.blubrry.com/
Requires at least: 3.7
Tested up to: 4.4
Text Domain: powerpress
Change Log:
Please see readme.txt for detailed change log.
Contributors:
Angelo Mandato, CIO RawVoice - Plugin founder, architect and lead developer
See readme.txt for full list of contributors.
Credits:
getID3(), License: GPL 2.0+ by James Heinrich <info [at] getid3.org> http://www.getid3.org
Note: getid3.php analyze() function modified to prevent redundant filesize() function call.
FlowPlayer, License: GPL 3.0+ http://flowplayer.org/; source: http://flowplayer.org/download.html
flashembed(), License: MIT by Tero Piirainen (tipiirai [at] gmail.com)
Note: code found at bottom of player.js
Copyright 2008-2014 RawVoice Inc. (http://www.rawvoice.com)
License: GPL (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
This project uses source that is GPL licensed.
*/
if( !function_exists('add_action') )
die("access denied.");
// WP_PLUGIN_DIR (REMEMBER TO USE THIS DEFINE IF NEEDED)
define('POWERPRESS_VERSION', '6.2.1' );
// Translation support:
if ( !defined('POWERPRESS_ABSPATH') )
define('POWERPRESS_ABSPATH', dirname(__FILE__) );
/////////////////////////////////////////////////////
// The following define options should be placed in your
// wp-config.php file so the setting is not disrupted when
// you upgrade the plugin.
/////////////////////////////////////////////////////
if( !defined('POWERPRESS_BLUBRRY_API_URL') )
define('POWERPRESS_BLUBRRY_API_URL', 'http://api.blubrry.com/');
// Replace validator service with one that is more reliable here:
// define('POWERPRESS_FEEDVALIDATOR_URL', 'http://www.feedvalidator.org/check.cgi?url=');
// Display custom play image for quicktime media. Applies to on page player only.
//define('POWERPRESS_PLAY_IMAGE', 'http://www.blubrry.com/themes/blubrry/images/player/PlayerBadge150x50NoBorder.jpg');
if( !defined('POWERPRESS_CONTENT_ACTION_PRIORITY') )
define('POWERPRESS_CONTENT_ACTION_PRIORITY', 10 );
// Added so administrators can customize what capability is needed for PowerPress
if( !defined('POWERPRESS_CAPABILITY_MANAGE_OPTIONS') )
define('POWERPRESS_CAPABILITY_MANAGE_OPTIONS', 'manage_options');
if( !defined('POWERPRESS_CAPABILITY_EDIT_PAGES') )
define('POWERPRESS_CAPABILITY_EDIT_PAGES', 'edit_pages');
//define('POWERPRESS_ENABLE_HTTPS_MEDIA', true); // Add this define to your wp-config.php if you wnat to allow media URLs that begin with https://
// Define variables, advanced users could define these in their own wp-config.php so lets not try to re-define
if( !defined('POWERPRESS_LINK_SEPARATOR') )
define('POWERPRESS_LINK_SEPARATOR', '|');
if( !defined('POWERPRESS_TEXT_SEPARATOR') )
define('POWERPRESS_TEXT_SEPARATOR', ':');
if( !defined('POWERPRESS_PLAY_IMAGE') )
define('POWERPRESS_PLAY_IMAGE', 'play_video_default.jpg');
if( !defined('PHP_EOL') )
define('PHP_EOL', "\n"); // We need this variable defined for new lines.
if( defined('POWERPRESS_DEBUG') ) {
if( !defined('PHP_EOL_WEB') ) {
define('PHP_EOL_WEB', "\n"); // Helps with readability
}
} else {
if( !defined('PHP_EOL_WEB') ) {
define('PHP_EOL_WEB', ''); // We don't necessarily need new lines for web output
}
}
if( !defined('POWERPRESS_SUBSCRIBE') )
define('POWERPRESS_SUBSCRIBE', true);
// Set regular expression values for determining mobile devices
if( !defined('POWERPRESS_MOBILE_REGEX') )
define('POWERPRESS_MOBILE_REGEX', 'iphone|ipod|ipad|aspen|android|blackberry|opera mini|webos|incognito|webmate|silk');
$powerpress_feed = NULL; // DO NOT CHANGE
function powerpress_content($content)
{
global $post, $g_powerpress_excerpt_post_id;
if( defined('PODPRESS_VERSION') || isset($GLOBALS['podcasting_player_id']) || isset($GLOBALS['podcast_channel_active']) || defined('PODCASTING_VERSION') )
return $content;
if( empty($post->ID) || !is_object($post) )
return $content;
if( defined('POWERPRESS_DO_ENCLOSE_FIX') )
$content = preg_replace('/\<!--.*added by PowerPress.*-->/im', '', $content );
if( is_feed() )
return $content; // We don't want to do anything to the feed
if( function_exists('post_password_required') )
{
if( post_password_required($post) )
return $content;
}
// PowerPress settings:
$GeneralSettings = get_option('powerpress_general');
// No player or links to add to content...
if( !empty($GeneralSettings['disable_appearance']) )
return $content;
// check for themes/plugins where we know we need to do this...
if( empty($GeneralSettings['player_aggressive']) )
{
if( !empty($GLOBALS['fb_ver']) && version_compare($GLOBALS['fb_ver'], '1.0', '<=') ) {
$GeneralSettings['player_aggressive'] = 1;
}
if( defined('JETPACK__VERSION') && version_compare(JETPACK__VERSION, '2.0', '>=') ) {
$GeneralSettings['player_aggressive'] = 1; // Jet pack still doesn't behave with PowerPress the_content
}
if( defined('WPSEO_VERSION') ) {
$GeneralSettings['player_aggressive'] = 4;
}
}
if( !empty($GeneralSettings['player_aggressive']) )
{
if( $GeneralSettings['player_aggressive'] == 4 )
{
$in_http_head = powerpress_in_wp_head();
if( $in_http_head === true )
return $content;
}
else if( $GeneralSettings['player_aggressive'] == 2 ) // If we do not have theme issues then lets keep this logic clean. and only display playes after the wp_head only
{
if( empty($GLOBALS['powerpress_wp_head_completed']) )
return $content;
}
else // method 1 or 3...
{
if( strstr($content, '<!--powerpress_player-->') !== false )
return $content; // The players were already added to the content
if( $GeneralSettings['player_aggressive'] != 3 && $g_powerpress_excerpt_post_id > 0 )
$g_powerpress_excerpt_post_id = 0; // Hack, set this to zero so it always goes past...
if( $GeneralSettings['player_aggressive'] == 3 )
$GeneralSettings['player_aggressive'] = 1; // remainder of the system will function as normal
}
}
// Problem: If the_excerpt is used instead of the_content, both the_exerpt and the_content will be called here.
// Important to note, get_the_excerpt will be called before the_content is called, so we add a simple little hack
if( current_filter() == 'get_the_excerpt' )
{
$g_powerpress_excerpt_post_id = $post->ID;
return $content; // We don't want to do anything to this content yet...
}
else if( current_filter() == 'the_content' && $g_powerpress_excerpt_post_id == $post->ID )
{
return $content; // We don't want to do anything to this excerpt content in this call either...
}
if( !isset($GeneralSettings['custom_feeds']) )
$GeneralSettings['custom_feeds'] = array('podcast'=>'Default Podcast Feed');
if( empty($GeneralSettings['custom_feeds']['podcast']) )
$GeneralSettings['custom_feeds']['podcast'] = 'Default Podcast Feed';
// Re-order so the default podcast episode is the top most...
$Temp = $GeneralSettings['custom_feeds'];
$GeneralSettings['custom_feeds'] = array();
$GeneralSettings['custom_feeds']['podcast'] = 'Default Podcast Feed';
while( list($feed_slug, $feed_title) = each($Temp) )
{
if( $feed_slug == 'podcast' )
continue;
$GeneralSettings['custom_feeds'][ $feed_slug ] = $feed_title;
}
// Handle post type feeds....
if( !empty($GeneralSettings['posttype_podcasting']) )
{
$post_type = get_query_var('post_type');
//$post_type = get_post_type();
// Get the feed slugs and titles for this post type
$PostTypeSettingsArray = get_option('powerpress_posttype_'.$post_type);
// Loop through this array of post type settings...
if( !empty($PostTypeSettingsArray) )
{
switch($post_type)
{
case 'post':
case 'page': {
// Do nothing!, we want the default podcast to appear in these post types
}; break;
default: {
if( !empty($post_type) && empty($PostTypeSettingsArray['podcast']) )
unset($GeneralSettings['custom_feeds']['podcast']); // special case, we do not want an accidental podcast episode to appear in a custom post type if the feature is enabled
}; break;
}
while( list($feed_slug, $postTypeSettings) = each($PostTypeSettingsArray) )
{
if( !empty( $postTypeSettings['title']) )
$GeneralSettings['custom_feeds'][ $feed_slug ] = $postTypeSettings['title'];
else
$GeneralSettings['custom_feeds'][ $feed_slug ] = $feed_slug;
}
}
}
if( !isset($GeneralSettings['display_player']) )
$GeneralSettings['display_player'] = 1;
if( !isset($GeneralSettings['player_function']) )
$GeneralSettings['player_function'] = 1;
if( !isset($GeneralSettings['podcast_link']) )
$GeneralSettings['podcast_link'] = 1;
// The blog owner doesn't want anything displayed, so don't bother wasting anymore CPU cycles
if( $GeneralSettings['display_player'] == 0 )
return $content;
if( current_filter() == 'the_excerpt' && empty($GeneralSettings['display_player_excerpt']) )
return $content; // We didn't want to modify this since the user didn't enable it for excerpts
// Figure out which players are alerady in the body of the page...
$ExcludePlayers = array();
if( isset($GeneralSettings['disable_player']) )
$ExcludePlayers = $GeneralSettings['disable_player']; // automatically disable the players configured
if( !empty($GeneralSettings['process_podpress']) && strstr($content, '[display_podcast]') )
return $content;
if( preg_match_all('/(.?)\[(powerpress)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)/s', $content, $matches) )
{
if( isset($matches[3]) )
{
while( list($key,$row) = each($matches[3]) )
{
$attributes = shortcode_parse_atts($row);
if( isset($attributes['url']) )
{
// not a problem...
}
else if( isset($attributes['feed']) )
{
// we want to exclude this feed from the links aera...
$ExcludePlayers[ $attributes['feed'] ] = true;
}
else
{
// we don't want to include any players below...
$ExcludePlayers = $GeneralSettings['custom_feeds'];
}
}
}
}
// LOOP HERE TO DISPLAY EACH MEDIA TYPE
$new_content = '';
while( list($feed_slug,$feed_title) = each($GeneralSettings['custom_feeds']) )
{
// Get the enclosure data
$EpisodeData = powerpress_get_enclosure_data($post->ID, $feed_slug);
if( !$EpisodeData && !empty($GeneralSettings['process_podpress']) && $feed_slug == 'podcast' )
$EpisodeData = powerpress_get_enclosure_data_podpress($post->ID);
if( !$EpisodeData || !$EpisodeData['url'] )
continue;
// Just in case, if there's no URL lets escape!
if( !$EpisodeData['url'] )
continue;
// If the player is not already inserted in the body of the post using the shortcode...
//if( preg_match('/\[powerpress(.*)\]/is', $content) == 0 )
if( !isset($ExcludePlayers[ $feed_slug ]) ) // If the player is not in our exclude list because it's already in the post body somewhere...
{
if( isset($GeneralSettings['premium_caps']) && $GeneralSettings['premium_caps'] && !powerpress_premium_content_authorized($feed_slug) )
{
$new_content .= powerpress_premium_content_message($post->ID, $feed_slug, $EpisodeData);
}
else
{
if( !isset($EpisodeData['no_links']) || ($GeneralSettings['player_function'] != 3 && $GeneralSettings['player_function'] != 0) )
{
do_action('wp_powerpress_player_scripts');
}
if( $GeneralSettings['player_function'] != 3 && $GeneralSettings['player_function'] != 0 ) // Play in new window only or disabled
{
$AddDefaultPlayer = empty($EpisodeData['no_player']);
if( $EpisodeData && !empty($EpisodeData['embed']) )
{
$new_content .= trim($EpisodeData['embed']);
if( !empty($GeneralSettings['embed_replace_player']) )
$AddDefaultPlayer = false;
}
if( $AddDefaultPlayer )
{
$image = '';
if( isset($EpisodeData['image']) && $EpisodeData['image'] != '' )
$image = $EpisodeData['image'];
$new_content .= apply_filters('powerpress_player', '', powerpress_add_flag_to_redirect_url($EpisodeData['url'], 'p'), $EpisodeData );
}
}
if( !isset($EpisodeData['no_links']) )
$new_content .= apply_filters('powerpress_player_links', '', powerpress_add_flag_to_redirect_url($EpisodeData['url'], 'p'), $EpisodeData );
//$new_content .= powerpress_get_player_links($post->ID, $feed_slug, $EpisodeData);
$new_content .= apply_filters('powerpress_player_subscribe_links', '', powerpress_add_flag_to_redirect_url($EpisodeData['url'], 'p'), $EpisodeData );
}
}
}
if( $new_content == '' )
return $content;
switch( $GeneralSettings['display_player'] )
{
case 1: { // Below posts
return $content.$new_content.( !empty($GeneralSettings['player_aggressive']) && $GeneralSettings['player_aggressive'] == 1 ?'<!--powerpress_player-->':'');
}; break;
case 2: { // Above posts
return ( !empty($GeneralSettings['player_aggressive']) && $GeneralSettings['player_aggressive'] == 1 ?'<!--powerpress_player-->':'').$new_content.$content;
}; break;
}
return $content;
}//end function
add_filter('get_the_excerpt', 'powerpress_content', (POWERPRESS_CONTENT_ACTION_PRIORITY - 1) );
add_filter('the_content', 'powerpress_content', POWERPRESS_CONTENT_ACTION_PRIORITY);
if( !defined('POWERPRESS_NO_THE_EXCERPT') )
add_filter('the_excerpt', 'powerpress_content', POWERPRESS_CONTENT_ACTION_PRIORITY);
/* Specail case fix Yoast bug which messes up the HTML */
function powerpress_yoast_gawp_fix($content)
{
$content= preg_replace(
array('/return powerpress\_pinw\(\"/', '/return powerpress\_embed\_quicktime\(\"/', '/return powerpress\_embed\_winplayer\(\"/', '/return powerpress\_embed\_swf\(\"/', '/return powerpress\_show\_embed\(\"/', '/return powerpress\_embed\_html5v\(\"/', '/return powerpress\_embed\_html5a\(\"/', ),
array('return powerpress_pinw(\'', 'return powerpress_embed_quicktime(\'', 'return powerpress_embed_winplayer(\'', 'return powerpress_embed_swf(\'', 'return powerpress_show_embed(\'', 'return powerpress_embed_html5v(\'', 'return powerpress_embed_html5a(\'' ),
$content);
return $content;
}
function powerpress_header()
{
// PowerPress settings:
$Powerpress = get_option('powerpress_general');
if( !isset($Powerpress['custom_feeds']) )
$Powerpress['custom_feeds'] = array('podcast'=>'Default Podcast Feed');
if( empty($Powerpress['disable_appearance']) || $Powerpress['disable_appearance'] == false )
{
if( !isset($Powerpress['player_function']) || $Powerpress['player_function'] > 0 ) // Don't include the player in the header if it is not needed...
{
$PowerpressPluginURL = powerpress_get_root_url();
?>
<script type="text/javascript"><!--
<?php
$new_window_width = 420;
$new_window_height = 240;
if( isset($Powerpress['new_window_width']) && $Powerpress['new_window_width'] > 0 )
$new_window_width = $Powerpress['new_window_width'];
else if( isset($Powerpress['new_window_width']) )
$new_window_width = 420;
if( isset($Powerpress['new_window_height']) && $Powerpress['new_window_height'] > 0 )
$new_window_height = $Powerpress['new_window_height'];
else if( isset($Powerpress['new_window_height']) )
$new_window_height = 240;
if( empty($Powerpress['new_window_nofactor']) )
{
$new_window_width += 40;
$new_window_height += 80;
}
?>
function powerpress_pinw(pinw_url){window.open(pinw_url, 'PowerPressPlayer','toolbar=0,status=0,resizable=1,width=<?php echo ($new_window_width); ?>,height=<?php echo ($new_window_height); ?>'); return false;}
//-->
</script>
<?php
}
}
if( !empty($Powerpress['feed_links']) )
{
// Loop through podcast feeds and display them here
while( list($feed_slug, $title) = each($Powerpress['custom_feeds']) )
{
$href = get_feed_link($feed_slug);
if ( isset($title) && isset($href) )
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
}
reset($Powerpress['custom_feeds']);
}
}
add_action('wp_head', 'powerpress_header');
function powerpress_wp_head_completed()
{
$GLOBALS['powerpress_wp_head_completed'] = true;
}
add_action('wp_head', 'powerpress_wp_head_completed', 100000);
function powerpress_exit_on_http_head($return)
{
if( is_feed() )
{
// Set the content type for HTTP headers...
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
// Needs authentication?
$GeneralSettings = get_option('powerpress_general');
if( !empty($GeneralSettings['premium_caps']) )
{
$feed_slug = get_query_var('feed');
$FeedSettings = get_option('powerpress_feed_'.$feed_slug);
if( !empty($FeedSettings['premium']) )
{
return false; // Let the logic further into PowerPress authenticate this HEAD request
}
}
}
return $return;
}
add_filter('exit_on_http_head', 'powerpress_exit_on_http_head' );
function powerpress_rss2_ns()
{
if( !powerpress_is_podcast_feed() )
return;
// Okay, lets add the namespace
echo 'xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"'.PHP_EOL;
if( !defined('POWERPRESS_RAWVOICE_RSS') || POWERPRESS_RAWVOICE_RSS != false )
{
echo 'xmlns:rawvoice="http://www.rawvoice.com/rawvoiceRssModule/"'.PHP_EOL;
}
if( !defined('POWERPRESS_GOOGLEPLAY_RSS') || POWERPRESS_GOOGLEPLAY_RSS != false )
{
echo 'xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"'.PHP_EOL;
}
}
add_action('rss2_ns', 'powerpress_rss2_ns');
function powerpress_rss2_head()
{
global $powerpress_feed;
if( !powerpress_is_podcast_feed() )
return; // Not a feed we manage
$feed_slug = get_query_var( 'feed' );
$cat_ID = get_query_var('cat');
$Feed = get_option('powerpress_feed'); // Get the main feed settings
if( !empty($powerpress_feed['category']) )
{
$CustomFeed = get_option('powerpress_cat_feed_'.$powerpress_feed['category']); // Get the custom podcast feed settings saved in the database
if( $CustomFeed )
$Feed = powerpress_merge_empty_feed_settings($CustomFeed, $Feed);
}
else if( !empty($powerpress_feed['term_taxonomy_id']) )
{
$CustomFeed = get_option('powerpress_taxonomy_'.$powerpress_feed['term_taxonomy_id']); // Get the taxonomy podcast settings saved in the database
if( $CustomFeed )
$Feed = powerpress_merge_empty_feed_settings($CustomFeed, $Feed);
}
else if( powerpress_is_custom_podcast_feed() ) // If we're handling a custom podcast feed...
{
$CustomFeed = get_option('powerpress_feed_'.$feed_slug); // Get the custom podcast feed settings saved in the database
$Feed = powerpress_merge_empty_feed_settings($CustomFeed, $Feed, ($feed_slug == 'podcast') );
}
if( !isset($Feed['url']) || trim($Feed['url']) == '' )
{
if( is_category() )
$Feed['url'] = get_category_link($cat_ID);
else
$Feed['url'] = get_bloginfo('url');
}
$General = get_option('powerpress_general');
// We made it this far, lets write stuff to the feed!
echo '<!-- podcast_generator="Blubrry PowerPress/'. POWERPRESS_VERSION .'" ';
if( isset($General['advanced_mode_2']) && empty($General['advanced_mode_2']) )
echo 'mode="simple" ';
else
echo 'mode="advanced" ';
if( defined('POWERPRESS_DEBUG') )
{
if( !empty($powerpress_feed['category']) )
echo 'category="'.$powerpress_feed['category'].'" ';
if( !empty($powerpress_feed['term_taxonomy_id']) )
echo 'ttid="'.$powerpress_feed['term_taxonomy_id'].'" ';
if( !empty($powerpress_feed['post_type']) )
echo 'posttype="'.$powerpress_feed['post_type'].'" ';
if( !empty($powerpress_feed['feed-slug']) )
echo 'feedslug="'.$powerpress_feed['feed-slug'].'" ';
}
echo '-->'.PHP_EOL;
// add the itunes:new-feed-url tag to feed
if( powerpress_is_custom_podcast_feed() )
{
if( !empty($Feed['itunes_new_feed_url']) )
{
$Feed['itunes_new_feed_url'] = str_replace('&', '&', $Feed['itunes_new_feed_url']);
echo "\t<itunes:new-feed-url>". htmlspecialchars(trim($Feed['itunes_new_feed_url'])) .'</itunes:new-feed-url>'.PHP_EOL;
}
}
else if( !empty($Feed['itunes_new_feed_url']) && ($feed_slug == 'feed' || $feed_slug == 'rss2') ) // If it is the default feed (We don't wnat to apply this to category or tag feeds
{
$Feed['itunes_new_feed_url'] = str_replace('&', '&', $Feed['itunes_new_feed_url']);
echo "\t<itunes:new-feed-url>". htmlspecialchars(trim($Feed['itunes_new_feed_url'])) .'</itunes:new-feed-url>'.PHP_EOL;
}
if( !empty($Feed['itunes_summary']) )
echo "\t".'<itunes:summary>'. powerpress_format_itunes_value( $Feed['itunes_summary'], 'summary' ) .'</itunes:summary>'.PHP_EOL;
else
echo "\t".'<itunes:summary>'. powerpress_format_itunes_value( get_bloginfo('description'), 'summary' ) .'</itunes:summary>'.PHP_EOL;
if( !empty($powerpress_feed['itunes_talent_name']) )
echo "\t<itunes:author>" . esc_html($powerpress_feed['itunes_talent_name']) . '</itunes:author>'.PHP_EOL;
if( !empty($powerpress_feed['explicit']) )
echo "\t".'<itunes:explicit>' . $powerpress_feed['explicit'] . '</itunes:explicit>'.PHP_EOL;
if( !empty($Feed['itunes_block']) )
echo "\t<itunes:block>yes</itunes:block>".PHP_EOL;
if( !empty($Feed['itunes_complete']) )
echo "\t<itunes:complete>yes</itunes:complete>".PHP_EOL;
if( !empty($Feed['itunes_image']) )
{
echo "\t".'<itunes:image href="' . esc_html( str_replace(' ', '+', $Feed['itunes_image']), 'double') . '" />'.PHP_EOL;
}
else
{
echo "\t".'<itunes:image href="' . powerpress_get_root_url() . 'itunes_default.jpg" />'.PHP_EOL;
}
if( !empty($Feed['email']) )
{
echo "\t".'<itunes:owner>'.PHP_EOL;
echo "\t\t".'<itunes:name>' . esc_html($powerpress_feed['itunes_talent_name']) . '</itunes:name>'.PHP_EOL;
echo "\t\t".'<itunes:email>' . esc_html($Feed['email']) . '</itunes:email>'.PHP_EOL;
echo "\t".'</itunes:owner>'.PHP_EOL;
echo "\t".'<managingEditor>'. esc_html($Feed['email'] .' ('. $powerpress_feed['itunes_talent_name'] .')') .'</managingEditor>'.PHP_EOL;
}
if( !empty($Feed['copyright']) )
{
// In case the user entered the copyright html version or the copyright UTF-8 or ASCII symbol or just (c)
$Feed['copyright'] = str_replace(array('©', '(c)', '(C)', chr(194) . chr(169), chr(169) ), '©', $Feed['copyright']);
echo "\t".'<copyright>'. esc_html($Feed['copyright']) . '</copyright>'.PHP_EOL;
}
if( !empty($Feed['itunes_subtitle']) )
echo "\t".'<itunes:subtitle>' . powerpress_format_itunes_value($Feed['itunes_subtitle'], 'subtitle') . '</itunes:subtitle>'.PHP_EOL;
else
echo "\t".'<itunes:subtitle>'. powerpress_format_itunes_value( get_bloginfo('description'), 'subtitle') .'</itunes:subtitle>'.PHP_EOL;
if( !empty($Feed['rss2_image']) || !empty($Feed['itunes_image']) )
{
if( !empty($Feed['rss2_image']) ) // If the RSS image is set, use it, otherwise use the iTunes image...
$rss_image = $Feed['rss2_image'];
else
$rss_image = $Feed['itunes_image'];
echo "\t". '<image>' .PHP_EOL;
if( is_category() && !empty($Feed['title']) )
echo "\t\t".'<title>' . esc_html( get_bloginfo_rss('name') ) . '</title>'.PHP_EOL;
else
echo "\t\t".'<title>' . esc_html( get_bloginfo_rss('name') . get_wp_title_rss() ) . '</title>'.PHP_EOL;
echo "\t\t".'<url>' . esc_html( str_replace(' ', '+', $rss_image)) . '</url>'.PHP_EOL;
echo "\t\t".'<link>'. $Feed['url'] . '</link>' . PHP_EOL;
echo "\t".'</image>' . PHP_EOL;
}
else // Use the default image
{
echo "\t". '<image>' .PHP_EOL;
if( (is_category() || is_tax() || is_tag() ) && !empty($Feed['title']) )
echo "\t\t".'<title>' . esc_html( get_bloginfo_rss('name') ) . '</title>'.PHP_EOL;
else
echo "\t\t".'<title>' . esc_html( get_bloginfo_rss('name') . get_wp_title_rss() ) . '</title>'.PHP_EOL;
echo "\t\t".'<url>' . powerpress_get_root_url() . 'rss_default.jpg</url>'.PHP_EOL;
echo "\t\t".'<link>'. $Feed['url'] . '</link>' . PHP_EOL;
echo "\t".'</image>' . PHP_EOL;
}
// Handle iTunes categories
$Categories = powerpress_itunes_categories();
$Cat1 = false; $Cat2 = false; $Cat3 = false;
if( !empty($Feed['itunes_cat_1']) )
list($Cat1, $SubCat1) = explode('-', $Feed['itunes_cat_1']);
if( !empty($Feed['itunes_cat_2']) )
list($Cat2, $SubCat2) = explode('-', $Feed['itunes_cat_2']);
if( !empty($Feed['itunes_cat_3']) )
list($Cat3, $SubCat3) = explode('-', $Feed['itunes_cat_3']);
if( $Cat1 )
{
$CatDesc = $Categories[$Cat1.'-00'];
$SubCatDesc = $Categories[$Cat1.'-'.$SubCat1];
if( $Cat1 != $Cat2 && $SubCat1 == '00' )
{
echo "\t".'<itunes:category text="'. esc_html($CatDesc) .'" />'.PHP_EOL;
}
else
{
echo "\t".'<itunes:category text="'. esc_html($CatDesc) .'">'.PHP_EOL;
if( $SubCat1 != '00' )
echo "\t\t".'<itunes:category text="'. esc_html($SubCatDesc) .'" />'.PHP_EOL;
// End this category set
if( $Cat1 != $Cat2 )
echo "\t".'</itunes:category>'.PHP_EOL;
}
}
if( $Cat2 )
{
$CatDesc = $Categories[$Cat2.'-00'];
$SubCatDesc = $Categories[$Cat2.'-'.$SubCat2];
// It's a continuation of the last category...
if( $Cat1 == $Cat2 )
{
if( $SubCat2 != '00' )
echo "\t\t".'<itunes:category text="'. esc_html($SubCatDesc) .'" />'.PHP_EOL;
// End this category set
if( $Cat2 != $Cat3 )
echo "\t".'</itunes:category>'.PHP_EOL;
}
else // This is not a continuation, lets start a new category set
{
if( $Cat2 != $Cat3 && $SubCat2 == '00' )
{
echo "\t".'<itunes:category text="'. esc_html($CatDesc) .'" />'.PHP_EOL;
}
else // We have nested values
{
if( $Cat1 != $Cat2 ) // Start a new category set
echo "\t".'<itunes:category text="'. esc_html($CatDesc) .'">'.PHP_EOL;
if( $SubCat2 != '00' )
echo "\t\t".'<itunes:category text="'. esc_html($SubCatDesc) .'" />'.PHP_EOL;
if( $Cat2 != $Cat3 ) // End this category set
echo "\t".'</itunes:category>'.PHP_EOL;
}
}
}
if( $Cat3 )
{
$CatDesc = $Categories[$Cat3.'-00'];
$SubCatDesc = $Categories[$Cat3.'-'.$SubCat3];
// It's a continuation of the last category...
if( $Cat2 == $Cat3 )
{
if( $SubCat3 != '00' )
echo "\t\t".'<itunes:category text="'. esc_html($SubCatDesc) .'" />'.PHP_EOL;
// End this category set
echo "\t".'</itunes:category>'.PHP_EOL;
}
else // This is not a continuation, lets start a new category set
{
if( $Cat2 != $Cat3 && $SubCat3 == '00' )
{
echo "\t".'<itunes:category text="'. esc_html($CatDesc) .'" />'.PHP_EOL;
}
else // We have nested values
{
if( $Cat2 != $Cat3 ) // Start a new category set
echo "\t".'<itunes:category text="'. esc_html($CatDesc) .'">'.PHP_EOL;
if( $SubCat3 != '00' )
echo "\t\t".'<itunes:category text="'. esc_html($SubCatDesc) .'" />'.PHP_EOL;
// End this category set
echo "\t".'</itunes:category>'.PHP_EOL;
}
}
}
// End Handle iTunes categories
if( !empty($Feed['googleplay_email']) )
{
echo "\t".'<googleplay:email>' . esc_html($Feed['googleplay_email']) . '</googleplay:email>'.PHP_EOL;
}
if( !empty($Feed['googleplay_description']) )
{
echo "\t".'<googleplay:description>' . esc_html($Feed['googleplay_description']) . '</googleplay:description>'.PHP_EOL;
}
if( !empty($Feed['googleplay_explicit']) )
{
echo "\t".'<googleplay:explicit>Yes</googleplay:explicit>'.PHP_EOL;
}
// google_play_cat // google_play_explicit
if( !empty($Feed['googleplay_cat']) )
{
$play_cats = powerpress_googleplay_categories();
if( !empty($play_cats[ $Feed['googleplay_cat'] ]) )
{
echo "\t".'<googleplay:category text="'. esc_html($play_cats[ $Feed['googleplay_cat'] ]) .'" />'.PHP_EOL;
}
}
if( !empty($Feed['googleplay_image']) )
{
echo "\t".'<googleplay:image href="' . esc_html( str_replace(' ', '+', $Feed['googleplay_image']), 'double') . '" />'.PHP_EOL;
}
// RawVoice RSS Tags
if( !defined('POWERPRESS_RAWVOICE_RSS') || POWERPRESS_RAWVOICE_RSS != false )
{
if( !empty($Feed['parental_rating']) )
echo "\t<rawvoice:rating>". $Feed['parental_rating'] ."</rawvoice:rating>".PHP_EOL;
if( !empty($Feed['location']) )
echo "\t<rawvoice:location>". htmlspecialchars($Feed['location']) ."</rawvoice:location>".PHP_EOL;
if( !empty($Feed['frequency']) )
echo "\t<rawvoice:frequency>". htmlspecialchars($Feed['frequency']) ."</rawvoice:frequency>".PHP_EOL;
if( !empty($Feed['donate_link']) && !empty($Feed['donate_url']) )
echo "\t<rawvoice:donate href=\"". htmlspecialchars( $Feed['donate_url'] ) ."\">". htmlspecialchars( (empty($Feed['donate_label'])?'':$Feed['donate_label']) ) ."</rawvoice:donate>".PHP_EOL;
}
}
add_action('rss2_head', 'powerpress_rss2_head');
function powerpress_rss2_item()
{
global $post, $powerpress_feed;
// are we processing a feed that powerpress should handle
if( !powerpress_is_podcast_feed() )
return;
if( function_exists('post_password_required') )
{
if( post_password_required($post) )
return $content;
}
// Check and see if we're working with a podcast episode
$custom_enclosure = false;
if( powerpress_is_custom_podcast_feed() && get_query_var('feed') != 'podcast' && !is_category() && !is_tax() && !is_tag() )
{
$EpisodeData = powerpress_get_enclosure_data($post->ID, get_query_var('feed') );
$custom_enclosure = true;
}
else
{
$EpisodeData = powerpress_get_enclosure_data($post->ID, 'podcast');
if( !$EpisodeData && !empty($powerpress_feed['process_podpress']) )
{
$EpisodeData = powerpress_get_enclosure_data_podpress($post->ID);
$custom_enclosure = true;
}
}
if( !$EpisodeData || !$EpisodeData['url'] )
return;
// If enclosure not added, check to see why...
if( defined('POWERPRESS_ENCLOSURE_FIX') && POWERPRESS_ENCLOSURE_FIX && !$custom_enclosure && $GLOBALS['powerpress_rss_enclosure_post_id'] != $post->ID )
{
$enclosure_in_wp = apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($EpisodeData['url']) . '" length="' . $EpisodeData['size'] . '" type="' . $EpisodeData['type'] . '" />' . "\n") );
if( !$enclosure_in_wp )
$custom_enclosure = true;
}
$author = $powerpress_feed['itunes_talent_name'];
if( isset($powerpress_feed['itunes_author_post']) )
$author = get_the_author();
$explicit = $powerpress_feed['explicit'];
$summary = false;
$subtitle = false;
$block = false;
$cc = false;
if( isset( $EpisodeData['summary'] ) && strlen($EpisodeData['summary']) > 1 )
$summary = $EpisodeData['summary'];
if( isset( $EpisodeData['subtitle'] ) && strlen($EpisodeData['subtitle']) > 1 )
$subtitle = $EpisodeData['subtitle'];
if( isset( $EpisodeData['explicit'] ) && is_numeric($EpisodeData['explicit']) )
{
$explicit_array = array("no", "yes", "clean");
$explicit = $explicit_array[$EpisodeData['explicit']];
}
// Code for future use:
if( !empty( $EpisodeData['author'] ) )
$author = $EpisodeData['author'];
if( !empty( $EpisodeData['block'] ) )
$block = 'yes';
if( !empty( $EpisodeData['cc'] ) )
$cc = 'yes';
if( $custom_enclosure ) // We need to add the enclosure tag here...
{
if( empty($EpisodeData['size']) )
$EpisodeData['size'] = 5242880; // Use the dummy 5MB size since we don't have a size to quote
echo "\t". sprintf('<enclosure url="%s" length="%d" type="%s" />%s',
trim($EpisodeData['url']),
trim($EpisodeData['size']),
trim($EpisodeData['type']),
PHP_EOL);
}
$excerpt_no_html = '';
$content_no_html = '';
$content_no_html_a = '';
if( !$subtitle || !$summary )
{
$excerpt_no_html_a = strip_tags($post->post_excerpt , '<a>');
$excerpt_no_html = strip_tags($post->post_excerpt);
}
if( (!$subtitle && !$excerpt_no_html) || (!$summary && !$powerpress_feed['enhance_itunes_summary'] && !$excerpt_no_html ) )
{
// Strip and format the wordpress way, but don't apply any other filters for these itunes tags
$content_no_html = $post->post_content;
$content_no_html = strip_shortcodes( $content_no_html );
$content_no_html = str_replace(']]>', ']]>', $content_no_html);
$content_no_html_a = strip_tags($content_no_html, '<a>');
$content_no_html = strip_tags($content_no_html);
}
if( $subtitle )
echo "\t<itunes:subtitle>". powerpress_format_itunes_value($subtitle, 'subtitle') .'</itunes:subtitle>'.PHP_EOL;
else if( $excerpt_no_html )
echo "\t<itunes:subtitle>". powerpress_format_itunes_value($excerpt_no_html, 'subtitle') .'</itunes:subtitle>'.PHP_EOL;
else if( $content_no_html )
echo "\t<itunes:subtitle>". powerpress_format_itunes_value($content_no_html, 'subtitle') .'</itunes:subtitle>'.PHP_EOL;
if( empty($powerpress_feed['feed_maximizer_on']) )
{
if( $summary )
echo "\t\t<itunes:summary>". powerpress_format_itunes_value($summary, 'summary') .'</itunes:summary>'.PHP_EOL;
else if( $powerpress_feed['enhance_itunes_summary'] )
echo "\t\t<itunes:summary><![CDATA[". powerpress_itunes_summary($post->post_content) .']]></itunes:summary>'.PHP_EOL;
else if( $excerpt_no_html ) // $content_no_html_a
echo "\t\t<itunes:summary>". powerpress_format_itunes_value($excerpt_no_html, 'summary') .'</itunes:summary>'.PHP_EOL;
else
echo "\t\t<itunes:summary>". powerpress_format_itunes_value($content_no_html_a, 'summary') .'</itunes:summary>'.PHP_EOL;
if( $author )
echo "\t\t<itunes:author>" . esc_html($author) . '</itunes:author>'.PHP_EOL;
else
echo "\t\t<itunes:author>".'NO AUTHOR</itunes:author>'.PHP_EOL;
// itunes episode image
if( !empty( $EpisodeData['itunes_image']) )
echo "\t\t".'<itunes:image href="' . esc_html( str_replace(' ', '+', $EpisodeData['itunes_image']), 'double') . '" />'.PHP_EOL;
else if( !empty($powerpress_feed['itunes_image']) )
echo "\t\t".'<itunes:image href="' . esc_html( str_replace(' ', '+', $powerpress_feed['itunes_image']), 'double') . '" />'.PHP_EOL;
}
if( $explicit )
echo "\t\t<itunes:explicit>" . $explicit . '</itunes:explicit>'.PHP_EOL;
if( $EpisodeData['duration'] && preg_match('/^(\d{1,2}:){0,2}\d{1,2}$/i', ltrim($EpisodeData['duration'], '0:') ) ) // Include duration if it is valid
echo "\t\t<itunes:duration>" . ltrim($EpisodeData['duration'], '0:') . '</itunes:duration>'.PHP_EOL;
if( $block && $block == 'yes' )
echo "\t\t<itunes:block>yes</itunes:block>".PHP_EOL;
if( $cc && $cc == 'yes' )
echo "\t\t<itunes:isClosedCaptioned>yes</itunes:isClosedCaptioned>".PHP_EOL;
if( !empty($powerpress_feed['itunes_feature']) ) // We are using the itunes:order option to feature a specific episode.
{
// Skip inserting the order tag
}
else
{
if( isset( $EpisodeData['order'] ) && is_numeric($EpisodeData['order']) )
echo "\t\t<itunes:order>". $EpisodeData['order'] ."</itunes:order>".PHP_EOL;
}
// Google Play tags:
if( !empty( $EpisodeData['gp_desc'] ) )
{
echo "\t\t<googleplay:description>". powerpress_format_itunes_value($EpisodeData['gp_desc'], 'summary') ."</googleplay:description>".PHP_EOL;
}
if( !empty( $EpisodeData['gp_explicit'] ) )
{
echo "\t\t<googleplay:explicit>yes</googleplay:explicit>".PHP_EOL;
}
if( !empty( $EpisodeData['gp_block'] ) )
{
echo "\t\t<googleplay:block>yes</googleplay:block>".PHP_EOL;
}
// RawVoice RSS Tags
if( empty($powerpress_feed['feed_maximizer_on']) )
{
if( !defined('POWERPRESS_RAWVOICE_RSS') || POWERPRESS_RAWVOICE_RSS != false )
{
if( !empty($EpisodeData['ishd']) )
echo "\t\t<rawvoice:isHD>yes</rawvoice:isHD>".PHP_EOL;;
if( !empty($EpisodeData['image']) )
echo "\t\t<rawvoice:poster url=\"". $EpisodeData['image'] ."\" />".PHP_EOL;
if( !empty($EpisodeData['embed']) )
echo "\t\t<rawvoice:embed>". htmlspecialchars($EpisodeData['embed']) ."</rawvoice:embed>".PHP_EOL;
else if( !empty($powerpress_feed['podcast_embed_in_feed']) && function_exists('powerpress_generate_embed') )
{
$player = powerpressplayer_embedable($EpisodeData['url'], $EpisodeData);
$embed_content = '';
// TODO:
if( $player )
$embed_content = powerpress_generate_embed($player, $EpisodeData);
if( $embed_content )
echo "\t\t<rawvoice:embed>". htmlspecialchars( $embed_content ) ."</rawvoice:embed>".PHP_EOL;
}
if( !empty($EpisodeData['webm_src']) )
{
echo "\t\t<rawvoice:webm src=\"". $EpisodeData['webm_src'] ."\"";
if( $EpisodeData['webm_length'] )
echo " length=\"". $EpisodeData['webm_length'] ."\"";
echo " type=\"video/webm\" />".PHP_EOL;
}
$GeneralSettings = get_option('powerpress_general');
if( !empty($GeneralSettings) && !empty($GeneralSettings['metamarks']) )
{
require_once(POWERPRESS_ABSPATH .'/powerpressadmin-metamarks.php');
powerpress_metamarks_print_rss2($EpisodeData);
}
}
}
}
add_action('rss2_item', 'powerpress_rss2_item');
function powerpress_filter_rss_enclosure($content)
{
if( defined('PODPRESS_VERSION') || isset($GLOBALS['podcasting_player_id']) || isset($GLOBALS['podcast_channel_active']) || defined('PODCASTING_VERSION') )
return $content; // Another podcasting plugin is enabled...
if( powerpress_is_custom_podcast_feed() && get_query_var('feed') != 'podcast' && !is_category() && !is_tag() && !is_tax() )
return ''; // We will handle this enclosure in the powerpress_rss2_item() function
$match_count = preg_match('/\surl="([^"]*)"/', $content, $matches);
if( count($matches) != 2)
return $content;
// Original Media URL
$OrigURL = $matches[1];
if( substr($OrigURL, 0, 5) != 'http:' && substr($OrigURL, 0, 6) != 'https:' )
return ''; // The URL value is invalid