-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed-podcast.php
124 lines (111 loc) · 5.08 KB
/
feed-podcast.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
<?php
$args = array(
'post_type' => 'podcast',
'posts_per_page' => 10
);
$podcast = new WP_Query( $args );
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $podcast;
/**
* Returns the size of a file without downloading it, or -1 if the file
* size could not be determined.
*
* https://stackoverflow.com/a/2602624
*
* @param $url - The location of the remote file to download. Cannot
* be null or empty.
*
* @return The size of the file referenced by $url, or -1 if the size
* could not be determined.
*/
function curl_get_file_size( $url ) {
// Assume failure.
$result = -1;
$curl = curl_init( $url );
// Issue a HEAD request and follow any redirects.
curl_setopt( $curl, CURLOPT_NOBODY, true );
curl_setopt( $curl, CURLOPT_HEADER, true );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
// curl_setopt( $curl, CURLOPT_USERAGENT, get_user_agent_string() );
$data = curl_exec( $curl );
curl_close( $curl );
if( $data ) {
$content_length = "unknown";
$status = "unknown";
if( preg_match( "/^HTTP\/1\.[01] (\d\d\d)/", $data, $matches ) ) {
$status = (int)$matches[1];
}
if( preg_match( "/Content-Length: (\d+)/", $data, $matches ) ) {
$content_length = (int)$matches[1];
}
// http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
if( $status == 200 || ($status > 300 && $status <= 308) ) {
$result = $content_length;
}
}
return $result;
}
header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
<?php do_action('rss2_ns'); ?>>
<channel>
<title>Speaking of Us</title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url') ?></link>
<description>
<![CDATA[
Speaking of Us explores what language teaches us about who we are and where we come from. In this podcast, you’ll get to know people from every culture on Earth. You’ll learn about their languages, their history, and how they navigate our rapidly-changing world.
For accompanying media, guest information, and transcripts, visit www.wikitongues.org/podcast.
]]>
</description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<language><?php bloginfo_rss('language'); ?></language>
<copyright>c 2020 Wikitongues</copyright>
<itunes:author>Wikitongues</itunes:author>
<itunes:owner>
<itunes:name>Wikitongues</itunes:name>
<itunes:email>[email protected]</itunes:email>
</itunes:owner>
<itunes:image href="https://wikitongues.org/wp-content/uploads/2020/05/Square.png" />
<itunes:explicit>no</itunes:explicit>
<itunes:category text="Science">
<itunes:category text="Natural Sciences"/>
</itunes:category>
<itunes:category text="Society & Culture">
<itunes:category text="Documentary"/>
</itunes:category>
<itunes:category text="History"/>
<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
<?php do_action('rss2_head'); ?>
<?php while($podcast->have_posts()) : $podcast->the_post(); ?>
<item>
<title><?php the_title_rss(); ?></title>
<link><?php the_permalink_rss(); ?></link>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
<dc:creator><?php the_author(); ?></dc:creator>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<description><![CDATA[<?php echo get_field('podcast_summary'); ?>]]></description>
<content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
<itunes:image href="<?php the_post_thumbnail_url(); ?>" />
<itunes:explicit>no</itunes:explicit>
<enclosure
url="<?php echo get_field('audio_file'); ?>"
length="<?php echo curl_get_file_size(get_field('audio_file')); ?>"
type="audio/mpeg" />
<?php do_action('rss2_item'); ?>
</item>
<?php endwhile; ?>
</channel>
</rss>