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
6 //let's include the basic stuff
7 require_once("includes.php");
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.
12 $output = '<?xml version="1.0" encoding="UTF-8" ?' . '>';
14 <rss version
="2.0" xmlns
:content
="http://purl.org/rss/1.0/modules/content/">
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
>
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');
30 foreach ($posts as $post) {
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
);
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
>
54 header("Pragma: public");
55 header("Cache-Control: public");
56 header('Expires: ' . gmdate("D, d M Y H:i:s", (time()+
60)) . " GMT");
58 $if_none_match = (isset($_SERVER['HTTP_IF_NONE_MATCH'])) ?
preg_replace('/[^0-9a-f]/', '', $_SERVER['HTTP_IF_NONE_MATCH']) : false;
61 header('ETag: "' . $etag . '"');
63 if ($if_none_match && $if_none_match == $etag) {
64 header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
68 header("Content-Length: " . strlen($output));
70 header("Content-type: text/xml; charset=utf-8");