-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplog-rss.php
executable file
·224 lines (183 loc) · 7.76 KB
/
plog-rss.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
<?php
/* This file handles the generation of the RSS feed. */
include_once(dirname(__FILE__).'/plog-load-config.php');
function generate_RSS_feed ($level, $id, $search = '') {
global $config;
$config['feed_title'] = SmartStripSlashes($config['feed_title']);
// remove plog-rss from the end, if present .. is there a better way to determine the full url?
$is_rss = strpos($config['baseurl'], 'plog-rss.php');
if ($is_rss !== false) {
$config['baseurl'] = substr($config['baseurl'], 0, $is_rss);
}
if (!empty($search)) $level = 'search';
// Aggregate feed of all albums with collection specified by id
if ($level == 'collection') {
if ($config['feed_content'] == 0 ) {
plogger_init_albums(array(
'collection_id' => $id,
'sortby' => 'id',
'sortdir' => 'DESC',
'from' => 0,
'limit' => $config['feed_num_entries']
));
} else {
plogger_init_pictures(array(
'type' => 'collection',
'value' => $id,
'limit' => $config['feed_num_entries'],
'sortby' => 'id',
));
}
$collection = get_collection_by_id($id);
$config['feed_title'] .= ': '.$collection['name'];
} else if ($level == 'album') {
plogger_init_pictures(array(
'type' => 'album',
'value' => $id,
'limit' => $config['feed_num_entries'],
'sortby' => 'id',
));
$album = get_album_by_id($id);
$config['feed_title'] .= ': '.$album['album_name'];
} else if ($level == 'picture') {
plogger_init_picture(array(
'id' => $id,
'comments' => 'DESC'
));
$picture = get_picture_by_id($id);
$config['feed_title'] .= ': '.basename($picture['path']);
} else if ($level == 'search') {
plogger_init_search(array(
'searchterms' => $search,
'limit' => $config['feed_num_entries'],
));
} else if (($level == 'collections') or ($level == '')) {
plogger_init_albums(array(
'collection_id' => -1,
'sortby' => 'id',
'sortdir' => 'DESC',
'from' => 0,
'limit' => $config['feed_num_entries']
));
$config['feed_title'] .= ': '.plog_tr('Entire Gallery');
}
// generate RSS header
$rssFeed = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$rssFeed.= "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:media=\"http://search.yahoo.com/mrss/\">\n";
$rssFeed.= "<channel>\n";
$rssFeed.= "<title>".$config['feed_title']."</title>\n";
$rssFeed.= "<description>".plog_tr('Plogger RSS Feed')."</description>\n";
$rssFeed.= "<language>".$GLOBALS['locale']."</language>\n";
$rssFeed.= "<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
$rssFeed.= "<generator>Plogger</generator>\n";
$rssFeed.= "<link>".$config['gallery_url']."</link>\n";
$rssFeed.= "<atom:link href=\"http://".$_SERVER['HTTP_HOST'].str_replace('&', '&', $_SERVER['REQUEST_URI'])."\" rel=\"self\" type=\"application/rss+xml\" />\n";
$header = 1;
while(plogger_has_albums()) {
plogger_load_album();
if ($header) {
$submitdate = date('D, d M Y H:i:s O');
$rssFeed.= "<pubDate>".$submitdate."</pubDate>\n";
$rssFeed.= "<lastBuildDate>".$submitdate."</lastBuildDate>\n";
$header = 0;
}
$sql = "SELECT UNIX_TIMESTAMP(\"date_modified\") AS \"pubdate\" FROM \"".PLOGGER_TABLE_PREFIX."pictures\" WHERE \"parent_album\" = '".plogger_get_album_id()."' ORDER BY \"date_modified\" DESC LIMIT 1";
$result = run_query($sql);
$row = $result->fetch();
$pubdate = date('D, d M Y H:i:s O', $row['pubdate']);
$title = plogger_get_album_name();
$num = plogger_album_picture_count();
$num_pictures = ($num == 1) ? plog_tr('image') : plog_tr('images');
$pagelink = plogger_get_album_url();
$thumbpath = str_replace(array('%2F', '%3A'), array('/', ':'), rawurlencode(plogger_get_album_thumb()));
$descript = '<p><a href="'.$pagelink.'"
title="'.$title.'">
<img src="'.$thumbpath.'" alt="'.$title.'" style="border: 2px solid #000;" />
</a></p><p>'.$title.' ('.$num.' '.$num_pictures.')</p><p>'.htmlspecialchars(plogger_get_album_description()).'</p>';
$rssFeed .= "<item>\n";
$rssFeed .= "\t<pubDate>".$pubdate."</pubDate>\n";
$rssFeed .= "\t<title>".$title."</title>\n";
$rssFeed .= "\t<link>".$pagelink."</link>\n";
$rssFeed .= "\t<description>".$descript."</description>\n";
$rssFeed .= "\t<guid isPermaLink=\"false\">".$thumbpath."</guid>\n";
$rssFeed .= "\t<media:content url=\"".$thumbpath."\" type=\"image/jpeg\" />\n";
$rssFeed .= "\t<media:title>".$title."</media:title>\n";
$rssFeed .= "</item>\n";
}
while(plogger_has_pictures()) {
plogger_load_picture();
// If at picture level, check to make sure it has comments first
if ($level != 'picture' || plogger_picture_has_comments()) {
if ($header) {
$submitdate = plogger_get_picture_date('D, d M Y H:i:s O', 1);
$takendate = plogger_get_picture_date();
$rssFeed.= "<pubDate>".$submitdate."</pubDate>\n";
$rssFeed.= "<lastBuildDate>".$submitdate."</lastBuildDate>\n";
$header = 0;
}
$rssFeed .= "<item>\n";
if ($config['allow_fullpic']) {
$urlPath = str_replace(array('%2F', '%3A'), array('/', ':'), rawurlencode(plogger_get_source_picture_url()));
} else {
$urlPath = str_replace(array('%2F', '%3A'), array('/', ':'), rawurlencode(plogger_get_picture_thumb(THUMB_LARGE)));
}
$caption = plogger_get_picture_caption();
$thumbpath = plogger_get_picture_thumb(THUMB_RSS);
$pagelink = plogger_get_picture_url();
if ($caption == '' || $caption == ' ') $caption = plog_tr('New Image (no caption)');
$caption .= ' - '.$takendate;
$descript = '<p><a href="'.$pagelink.'"
title="'.$caption.'">
<img src="'.$thumbpath.'" alt="'.$caption.'" style="border: 2px solid #000;" />
</a></p><p>'.$caption.'</p>';
$descript .= '<p>'.htmlspecialchars(plogger_get_picture_description()).'</p>';
$rssFeed .= "\t<pubDate>".$submitdate."</pubDate>\n";
$rssFeed .= "\t<title>".$caption."</title>\n";
$rssFeed .= "\t<link>".$pagelink."</link>\n";
$rssFeed .= "\t<description>".$descript."</description>\n";
$rssFeed .= "\t<guid isPermaLink=\"false\">".$thumbpath."</guid>\n";
$rssFeed .= "\t<media:content url=\"".$urlPath."\" type=\"image/jpeg\" />\n";
$rssFeed .= "\t<media:title>".$caption."</media:title>\n";
$rssFeed .= "</item>\n";
if ($level == 'picture') {
while(plogger_picture_has_comments()) {
plogger_load_comment();
$rssFeed .= "<item>\n";
$rssFeed .= "\t<pubDate>".plogger_get_comment_date('D, d M Y H:i:s O')."</pubDate>\n";
$rssFeed .= "\t<title>Comment by ".plogger_get_comment_author()."</title>\n";
$rssFeed .= "\t<link>".$pagelink."</link>\n";
$rssFeed .= "\t<description>".plogger_get_comment_text()."</description>\n";
$rssFeed .= "\t<guid isPermaLink=\"true\">".$pagelink."#Comment-".plogger_get_comment_id()."</guid>\n";
$rssFeed .= "</item>\n";
}
}
}
}
$rssFeed .= "</channel>\n</rss>";
echo $rssFeed;
}
// Send proper header
header('Content-Type: application/xml');
$level = isset($_GET['level']) ? $_GET['level'] : '';
$id = isset($_GET['id']) ? intval($_GET['id']) : '0';
// Process path here - is set if mod_rewrite is in use
// Some Estonian remarks were here
if (!empty($_REQUEST['path'])) {
// The following line calculates the path in the album and excludes any subdirectories if
// Plogger is installed in one
$path = join('/', array_diff(explode('/', $_SERVER['REQUEST_URI']), explode('/', $_SERVER['PHP_SELF'])));
$resolved_path = resolve_path($path);
$level = (isset($resolved_path['level'])) ? $resolved_path['level'] : 'collections';
$id = (isset($resolved_path['id'])) ? $resolved_path['id'] : 0;
}
$parts = parse_url($_SERVER['REQUEST_URI']);
if (isset($parts['query'])) {
parse_str($parts['query'], $query_parts);
}
if (isset($query_parts['searchterms'])) {
generate_RSS_feed($level, $id, $query_parts['searchterms']);
} else {
generate_RSS_feed($level, $id);
}
close_db();
?>