-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwritexml.php
More file actions
122 lines (81 loc) · 3.06 KB
/
writexml.php
File metadata and controls
122 lines (81 loc) · 3.06 KB
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
<?php
require_once('../headers/db_header.php');
if(isset($_GET['channel'])){
$channel_id = $_GET['channel'];
} else {
echo ' need channel id or "all"';
}
if ($channel_id == 'all'){
$query = "SELECT * FROM podcast_channels ";
} else {
$query = "SELECT * FROM podcast_channels WHERE id ='".$channel_id."'";
}
//execute the query.
$channels = array();
$episode_lists = array();
if ($result = mysqli_query($db, $query) ){
while($row = mysqli_fetch_array($result)) {
$channels []= $row;
$query2 = "SELECT * FROM podcast_episodes WHERE channel_id = ".$row['id'];
//execute the query.
$episodes = array();
if ($result2 = mysqli_query($db, $query2) ){
while($row = mysqli_fetch_array($result2)) {
$episodes []= $row;
}
$episode_lists [] = $episodes;
} else { echo 'db prob. query 2 is '.$query2;}
}
foreach($channels as $i => $channel){
make_podcast($channel,$episode_lists[$i]);
}
}
function make_podcast($channel,$episodes){
foreach($channel as $i => $v){
$channel[$i] = htmlspecialchars(html_entity_decode($v));
}
$xml_head = '<?xml version="1.0" ?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0" >';
$xml = '';
$xml .= $xml_head;
$xml .= '<channel>';
$xml .= '<title>'.$channel['title'].'</title>';
$xml .= '<description>'.$channel['summary'].'</description>';
$xml .= '<itunes:summary>'.$channel['summary'].'</itunes:summary>';
$xml .= '<itunes:author>'.$channel['author'].'</itunes:author>';
$xml .= '<itunes:subtitle>'.$channel['subtitle'].'</itunes:subtitle>';
$xml .= '<itunes:owner> '.
'<itunes:name>'.$channel['owner_name'].'</itunes:name>'.
'<itunes:email>'.$channel['owner_email'].'</itunes:email>'.
'</itunes:owner>';
$xml .= '<itunes:image href="'.$channel['image_url'].'"/>';
$xml .= '<itunes:link rel="image" type="video/jpeg" href="'.$channel['image_url'].'">'.$channel['title'].'</itunes:link>';
$xml .= '<image>'.
'<link>'.$channel['link'].'</link>'.
'<url>'.$channel['image_url'].'</url>'.
'<title>'.$channel['title'].'</title>'.
'</image>';
$xml .= '<link>'.$channel['link'].'</link>';
$xml .= '<generator> podcast mate 2000</generator>';
foreach($episodes as $i => $episode){
foreach($episode as $in => $val){
$episode[$in] = htmlspecialchars(html_entity_decode($val));
}
$xml .=
'<item>'.
'<title>'.$episode['title'].'</title>'.
'<pubDate>'.$episode['date'].'</pubDate>'.
'<description>'.$episode['summary'].'</description>'.
'<itunes:subtitle>'.$episode['subtitle'].'</itunes:subtitle>';
$xml .= ($episode['duration'] > 0) ? '<itunes:duration>'.$episode['duration'].'</itunes:duration>':'';
$xml .=
'<enclosure url="'.$episode['url'].'" length="'.$episode['length'].'" type="audio/mpeg"/>'.
'<guid isPermaLink="true">'.$episode['url'].'</guid></item>';
}
$xml.= '</channel></rss>';
// $filename = urlencode(html_entity_decode(str_replace(' ','',$channel['title'])).'.xml';
$file = fopen('podcast-media/xml/'.$channel['xml'],'wb');
if($file){
echo fwrite($file, $xml).' bytes written.';
} else {echo 'could not write file';}
}