root/releases/0.8/allpostsfeed.php

Revision 907, 2.5 kB (checked in by sven, 2 years ago)

add usual http headers to all posts feed

Line 
1 <?php
2 # allpostsfeed.php : script to create a feed out of all public weblog
3 # post of a single elgg installation
4 # coded by Vermario (www.vermario.com) , based by index.php for elgg.net
5
6 //let's include the basic stuff
7 require_once("includes.php");
8
9 # let's create the top part of the feed, with the usual declarations:
10 # for the language part, let's use the locale setting, that makes some sense.
11
12 $output = '<?xml version="1.0" encoding="UTF-8" ?' . '>';
13 $output .= <<< END
14 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
15 <channel>
16 <title><![CDATA[{$CFG->sitename}: Latest blog posts]]></title>
17 <link>{$CFG->wwwroot}</link>
18 <description><![CDATA[Latest public blog posts from {$CFG->sitename}]]></description>
19 <generator><![CDATA[{$CFG->sitename}]]></generator>
20 <language>{$CFG->defaultlocale}</language>
21 END;
22
23 // query the database directly:
24 $posts = get_records_sql('SELECT wp.ident, u.name, u.username, wp.body, wp.title, wp.ident as postid, wp.posted
25 FROM '.$CFG->prefix.'weblog_posts wp
26 LEFT JOIN '.$CFG->prefix.'users u ON u.ident = wp.weblog
27 WHERE wp.access = "PUBLIC"
28 ORDER BY wp.posted DESC LIMIT 20');
29
30 foreach ($posts as $post) {
31     
32     $body = strip_tags($post->body);
33     $body = preg_replace( "|\w{3,10}://[\w\.\-_]+(:\d+)?[^\s\"\'<>\(\)\{\}]*|", "", $body);
34     $date = date("D, d M Y G:i:s O",$post->posted);
35     $output .= <<< END
36     
37     <item>
38         <title><![CDATA[{$post->title}]]></title>
39         <link>{$CFG->wwwroot}{$post->username}/weblog/{$post->postid}.html</link>
40         <guid isPermaLink="true">{$CFG->wwwroot}{$post->username}/weblog/{$post->postid}.html</guid>
41         <pubDate>{$date}</pubDate>
42         <description><![CDATA[{$body}]]></description>
43     </item>
44     
45 END;
46
47 }
48
49 $output .= <<< END
50 </channel></rss>
51 END;
52
53     if ($output) {
54         header("Pragma: public");
55         header("Cache-Control: public");
56         header('Expires: ' . gmdate("D, d M Y H:i:s", (time()+60)) . " GMT");
57         
58         $if_none_match = (isset($_SERVER['HTTP_IF_NONE_MATCH'])) ? preg_replace('/[^0-9a-f]/', '', $_SERVER['HTTP_IF_NONE_MATCH']) : false;
59         
60         $etag = md5($output);
61         header('ETag: "' . $etag . '"');
62         
63         if ($if_none_match && $if_none_match == $etag) {
64             header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
65             exit;
66         }
67         
68         header("Content-Length: " . strlen($output));
69         
70         header("Content-type: text/xml; charset=utf-8");
71         echo $output;
72     }
73     
74 ?>
Note: See TracBrowser for help on using the browser.