20 $query_saved = substr($_SERVER['QUERY_STRING'],2); // strip '?=', save
27 $query_original = substr($query_saved,4); // strip 'atom'
29 $query_original = trim($query_original,'/');
31 ereg("[/]?page=([0-9]*)",$query_original,$va);
33 if(((count($va)) > 1) && ($va[1] > 0)) {
35 $query_original = ereg_replace("([/]?page=[0-9]*)","",$query_original);
36 $startrecord = ($pagenum * $articles_page) - $articles_page;
40 if(substr($query_original,-4,4) == 'text') {
42 $query_original = substr($query_original,0,-4);
45 $query_original = trim($query_original,'/');
47 if(substr($query_original,0,5) == 'forum') {
49 $query_original = substr($query_original,5);
52 $query_original = trim($query_original,'/');
54 $cmd = explode('/',$query_original);
57 if($cmd[0] == 'category') {
64 switch (count($cmd)) {
66 if($cmd[0] == 'share') {
91 // build the return link
95 $href .= preg_replace("@^atom@","/weblog",$query_saved);
97 $href .= preg_replace("@^atom@","",$query_saved);
98 $href = preg_replace("@/text$@","",$href);
99 $href = preg_replace("@/share/@","/view/",$href);
102 session_write_close();
104 if((xint($SITE_RESTRICTED)) && (! xint($_SESSION['authenticated'])))
108 header("Content-type: text/plain");
110 header("Content-type: application/atom+xml");
111 echo '<?xml version="1.0" encoding="utf-8" ?>'."\r\n";
113 include("globs.php");
116 $sitesubs = get_default_subs();
119 $blog_url = $SITE_URL;
120 $blog_title = xmlificator($SITE_TITLE);
121 $blog_desc = xmlificator($BLOG_DESC);
122 $blog_author = xmlificator($BLOG_AUTHOR);
123 $blog_email = xmlificator($BLOG_EMAIL);
124 $blog_logo = $BLOG_LOGO;
125 if((strlen($blog_logo)) && (! strstr($blog_logo,"://")))
126 $blog_logo = $SITE_URL.'/'.$blog_logo;
128 $category = dbesc($category);
129 $author = dbesc($author);
130 $dest = dbesc($dest);
132 if(strlen($category) && (! ($category_id = category::get_cat_id($category,$author))))
135 if(strlen($author)) {
136 $author_info = get_author($author);
137 if(count($author_info)) {
138 $blog_url = xmlificator($SITE_URL.'/weblog/'.$author);
139 if(strlen($author_info[0]['blogname']))
140 $blog_title = xmlificator($author_info[0]['blogname']);
141 if(strlen($author_info[0]['blogdesc']))
142 $blog_desc = xmlificator($author_info[0]['blogdesc']);
143 if(strlen($author_info[0]['fullname']))
144 $blog_author = xmlificator($author_info[0]['fullname']);
145 if(strlen($author_info[0]['email']))
146 $blog_email = xmlificator($author_info[0]['email']);
147 if(strlen($author_info[0]['bloglogo'])) {
148 $blog_logo = xmlificator($author_info[0]['bloglogo']);
149 if((strlen($blog_logo)) && (! strstr($blog_logo,"://")))
150 $blog_logo = $SITE_URL.'/'.$blog_logo;
156 $x = get_user($share);
159 && (! $x[0]['lurker'])
160 && (! $x[0]['sharecensor'])
161 && (! $x[0]['sharemutual'])) {
163 if(xstr($x[0]['sitetitle']))
164 $blog_title = $x[0]['sitetitle'];
165 if(xstr($x[0]['sitedesc']))
166 $blog_desc = $x[0]['sitedesc'];
167 if(xstr($x[0]['sitelogo']))
168 $blog_logo = $x[0]['sitelogo'];
170 $newsubs = get_subs($x[0]['name']);
171 $groups = groupsinit();
174 foreach($newsubs as $sub) {
175 $p = fetch_permissions('forum',$sub);
176 if(check_access($_SESSION['username'], $groups, '',$p))
185 $media = getmediamap();
186 $build_date = gmdate('c');
187 $copyright = 'Copyright '.date('Y').' '.$blog_author;
188 $canonical = $SITE_URL;
189 if(substr($canonical,0,-1) != '/')
193 if(substr($query_saved,0,1) == '/')
194 $self .= substr($query_saved,1);
196 $self .= $query_saved;
199 if(strlen($blog_desc))
200 $subtitle = "<subtitle>$blog_desc</subtitle>";
203 <feed xmlns="http://www.w3.org/2005/Atom"
204 xmlns:thr="http://purl.org/syndication/thread/1.0" >
207 <title>$blog_title</title>
208 <link rel="alternate" href="$href" />
209 <updated>$build_date</updated>
214 if(strlen($blog_logo)) {
216 <logo>$blog_logo</logo>
221 $article_id_list = array();
225 $ss['tolerance'] = 0;
228 $ss['category_id'] = $category_id;
231 $ss['type'] = 'weblog';
232 $ss['author'] = $author;
236 $ss['type'] = 'forum';
237 $ss['forum'] = $dest;
241 $ss['countonly'] = true;
243 $rt = article_query($ss);
244 $totalarticles = $rt[0]['total'];
246 echo " <link rel=\"self\" href=\"$self\" />\r\n";
248 $self = ereg_replace("([/]?page=[0-9]*)","",$self);
250 if($totalarticles > $articles_page) {
253 $ppage = $pagenum - 1;
254 echo " <link rel=\"previous\" href=\"$self/page=$ppage\" />\r\n";
256 echo " <link rel=\"first\" href=\"$self/".'page=1'."\" />\r\n";
258 $numpages = $totalarticles / $articles_page;
260 $lastpage = (($numpages > intval($numpages))
261 ? intval($numpages)+1
264 echo " <link rel=\"last\" href=\"$self/page=$lastpage\" />\r\n";
266 if(($totalarticles - ($articles_page * $pagenum)) > 0) {
267 $npage = $pagenum + 1;
268 echo " <link rel=\"next\" href=\"$self/page=$npage\" />\r\n";
273 unset($ss['countonly']);
275 $ss['startat'] = $startrecord;
276 $ss['articles_page'] = $articles_page;
278 $r = article_query($ss);
282 $article_id_list[] = "'".$rr['id']."'";
286 if(count($article_id_list)) {
287 $rcc = fetch_comments_by_list($article_id_list,'article');
288 $ratt = fetch_attachments_by_list($article_id_list);
293 $link = "{$SITE_URL}/article/{$rr['guid']}";
294 $datestr = $rr['created'];
295 $pubdate = gmdate('c',strtotime($datestr.' +0000'));
296 $datestr = $rr['edited'];
297 $editdate = gmdate('c',strtotime($datestr.' +0000'));
298 if(strstr($rr['type'],'news')) {
299 if(strlen($rr['ext_author']))
300 $authorstr = "<author><name>{$rr['ext_author']}</name></author>\r\n";
302 $authorstr = "<author><name>External Author</name></author>\r\n";
306 if(strlen($rr['fullname']))
307 $authorstr = "<author><name>{$rr['fullname']}</name></author>\r\n";
309 $authorstr = "<author><name>{$rr['author']}</name></author>\r\n";
311 $guid = "urn:uuid:{$rr[guid]}";
312 $comments = "{$SITE_URL}/comments/{$rr['guid']}";
314 $contents = $rr['body'];
316 if((! $rr['approved']) && (! strstr($rr['type'], 'news')))
317 $contents = filter_images($contents);
319 $contents = macro_youtube($contents);
320 $contents = reltoabs($contents,$SITE_URL.'/');
322 $title = xmlificator($rr['title']);
323 if(! strlen($title)) {
324 $title = xmlificator(substr($datestr,0,11));
326 // Use the first 28 chars of text for the title-summary. Watch that
327 // we don't end up with a _partial_ escape sequence at the end.
329 $stripped = xmlificator(strip_tags($contents));
334 $summary=substr($stripped,0,$len);
335 if(($teststr = strrchr($summary,"&")) && (! strchr($teststr,";"))) {
344 // Chopped off words don't look pretty in an RSS title
346 if(strrpos($summary,' ') > 10)
347 $title .= ' '.substr($summary,0,(strrpos($summary,' ')));
350 $contents .= feed_attachments($ratt,$rr['id']);
351 $contents .= feed_comments($rcc,$rr['id'],$rr['guid'],$rr['rank']);
353 $contents = reltoabs($contents,$SITE_URL.'/');
355 $contents = xmlificator($contents);
363 <title type="html">$title</title>
364 <published>$pubdate</published>
365 <updated>$editdate</updated>
366 <link rel="alternate" href="$link" />
367 <content type="html">$contents</content>
372 $rc = category::categories_by_article($rr['id']);
374 for($x = 0; $x < count($rc); $x ++)
375 echo ' <category term="'.xmlificator($rc[$x]).'"/>'."\r\n";
377 $rat = attachments_fetch($rr['id']);
379 foreach($rat as $att) {
380 $filename = $att['filename'];
381 $ext = substr($filename,strrpos($filename,'.'));
382 $type = 'application/octet-stream';
383 foreach($media as $m) {
389 echo ' <link rel="enclosure" href="'.$SITE_URL.'/'.xmlificator($filename).'" length="'.$att['size'].'" type="'.$type.'" />'."\r\n";
393 echo "</entry>\r\n\r\n";
395 // if(($ALLOW_COMMENTS == "1") && (count($rcc))) {
396 // foreach($rcc as $c) {
397 // if($c['tid'] != $rr['id'])
399 // $cguid = "urn:uuid:{$c['guid']}";
400 // $datestr = $c['created'];
401 // $cpubdate = date(c,strtotime($datestr));
403 // $ccontents = format_avatar($c['avatar'],$c['author'],$c['userid'],
404 // $c['censored'],0,'',64).'<br />';
405 // $ccontents .= $c['body'];
407 // $ccontents = filter_images($ccontents);
408 // $ccontents = reltoabs($ccontents,$SITE_URL.'/');
409 // $ccontents = xmlificator($ccontents);
410 // if(strlen($c['fullname']))
411 // $cauthor = xmlificator($c['fullname']);
413 // $cauthor = xmlificator($c['author']);
414 // $cauthorstr = '<author><name>'.$cauthor.'</name>';
415 // if(strlen($c['url']))
416 // $cauthorstr .= '<uri>'.xmlificator($c['url']).'</uri>';
417 // $cauthorstr .= '</author>';
421 //<thr:in-reply-to ref="$guid" />
423 //<title type="html">Re: $title</title>
424 //<link rel="related" href="$link" />
425 //<published>$cpubdate</published>
426 //<updated>$cpubdate</updated>
427 //<content type="html">$ccontents</content>