fix #136, annoying warnings when is enabled open_basedir or disabled url fopen
[elgg.git] / allpostsfeed.php
bloba5bc8972d3db3d2ef6361b49c079edaf1b199c2f
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
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" ?' . '>';
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;
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);
35 $output .= <<< END
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>
45 END;
49 $output .= <<< END
50 </channel></rss>
51 END;
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");
58 $if_none_match = (isset($_SERVER['HTTP_IF_NONE_MATCH'])) ? preg_replace('/[^0-9a-f]/', '', $_SERVER['HTTP_IF_NONE_MATCH']) : false;
60 $etag = md5($output);
61 header('ETag: "' . $etag . '"');
63 if ($if_none_match && $if_none_match == $etag) {
64 header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
65 exit;
68 header("Content-Length: " . strlen($output));
70 header("Content-type: text/xml; charset=utf-8");
71 echo $output;