source: branches/rsr.v5.1.dev/web/punbb/rss.php @ 4

Last change on this file since 4 was 1, checked in by dj3c1t, 13 years ago

import initial

File size: 11.5 KB
Line 
1<?php
2/**
3  * BLOG:CMS: PHP/MySQL Personal Content Management System
4  * http://blogcms.com/
5  * http://forum.blogcms.com/
6  *
7  * 2003-2004, (c) Radek HULAN
8  * http://hulan.cz/
9  *
10  * Mod by Bert Garcia for PunBB 1.2.1
11  * http://nupusi.com
12  *
13  * Additional changes Copyright 2005 by Alex King
14  * Now creates feeds for categories, forums, topics
15  * http://www.alexking.org/software/
16  *
17  * Please see the enclosed readme.txt file for usage
18  *
19  * This program is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU General Public License
21  * as published by the Free Software Foundation; either version 2
22  * of the License, or (at your option) any later version.
23
24// **********************************************************************
25// This program is distributed in the hope that it will be useful, but
26// WITHOUT ANY WARRANTY; without even the implied warranty of
27// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28// *****************************************************************
29
30**/
31
32
33define('PUN_ROOT', './');
34@include PUN_ROOT.'config.php';
35
36// If PUN isn't defined, config.php is missing or corrupt
37if (!defined('PUN'))
38        exit('The file \'config.php\' doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');
39
40// Disable error reporting for uninitialized variables
41error_reporting(E_ERROR | E_WARNING | E_PARSE);
42
43// Turn off magic_quotes_runtime
44set_magic_quotes_runtime(0);
45
46
47// Load the functions script
48require PUN_ROOT.'include/functions.php';
49require PUN_ROOT.'include/parser.php';
50
51// Load DB abstraction layer and try to connect
52require PUN_ROOT.'include/dblayer/common_db.php';
53
54// Get the forum config
55$result = $db->query('SELECT * FROM '.$db->prefix.'config') or error('Unable to fetch forum config', __FILE__, __LINE__, $db->error());
56while ($cur_config_item = $db->fetch_row($result))
57        $pun_config[$cur_config_item[0]] = $cur_config_item[1];
58
59// Make sure we (guests) have permission to read the forums
60$result = $db->query('SELECT g_read_board FROM '.$db->prefix.'groups WHERE g_id=3') or error('Unable to fetch group info', __FILE__, __LINE__, $db->error());
61if ($db->result($result) == '0')
62        exit('No permission');
63
64
65// Attempt to load the common language file
66@include PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/common.php';
67if (!isset($lang_common)) exit('There is no valid language pack \''.$pun_config['o_default_lang'].'\' installed. Please reinstall a language of that name.');
68
69// parse RSS
70ob_start();
71
72// make feed
73/* original query
74$result = $db->query(
75        "select p.id as id, p.message as message, p.posted as postposted, t.subject as subject ".
76        "from ".$db->prefix."posts as p, ".$db->prefix."topics as t ".
77        "where p.topic_id=t.id ".
78        "order by postposted desc ".
79        "limit 0,15")
80        or error('Unable to fetch forum posts', __FILE__, __LINE__, $db->error());;
81*/
82
83if (!empty($_GET["cid"])) {
84        $where = "      AND c.id = '".intval($_GET['cid'])."'";
85        $title = 'cid';
86}
87else if (!empty($_GET["fid"])) {
88        $where = "      AND f.id = '".intval($_GET['fid'])."'";
89        $title = 'fid';
90}
91else if (!empty($_GET["tid"])) {
92        $where = "      AND t.id = '".intval($_GET['tid'])."'";
93        $title = 'tid';
94}
95else {
96        $where = '';
97        $title = '';
98}
99$query ="
100        SELECT p.id AS id, p.message AS message, p.posted AS postposted, t.subject AS subject, f.forum_name, c.cat_name
101        FROM ".$db->prefix."posts p
102        LEFT JOIN ".$db->prefix."topics t
103        ON p.topic_id=t.id
104        INNER JOIN ".$db->prefix."forums AS f
105        ON f.id=t.forum_id
106        LEFT JOIN ".$db->prefix."categories AS c
107        ON f.cat_id = c.id
108        LEFT JOIN ".$db->prefix."forum_perms AS fp
109        ON (
110                fp.forum_id=f.id
111                AND fp.group_id=3
112        )
113        WHERE (
114                fp.read_forum IS NULL
115                OR fp.read_forum=0
116                OR fp.read_forum=1
117        )
118        $where 
119        ORDER BY postposted DESC
120        LIMIT 0,15";
121$result = $db->query($query) or error('Unable to fetch forum posts', __FILE__, __LINE__, $db->error());
122$i = 0;
123while ($cur = $db->fetch_assoc($result))
124{ if($i == 0) { putHeader($cur, $title); $i++; }
125  putPost($cur);
126}
127putEnd();
128
129// get feed into $feed
130$feed = ob_get_contents();
131ob_end_clean();
132
133header ("Content-type: application/rss+xml");
134echo $feed;
135
136/* entity to unicode decimal value */
137function entity_to_decimal_value($string){
138        static $entities_dec = false;
139        if (!is_array($entities_dec)) {
140                $entities_named    = array("&nbsp;","&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;","&uml;","&copy;","&ordf;","&laquo;","&not;","&shy;","&reg;","&macr;","&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;","&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;","&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;","&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;","&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;","&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;","&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;","&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;","&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;","&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;","&fnof;","&Alpha;","&Beta;","&Gamma;","&Delta;","&Epsilon;","&Zeta;","&Eta;","&Theta;","&Iota;","&Kappa;","&Lambda;","&Mu;","&Nu;","&Xi;","&Omicron;","&Pi;","&Rho;","&Sigma;","&Tau;","&Upsilon;","&Phi;","&Chi;","&Psi;","&Omega;","&alpha;","&beta;","&gamma;","&delta;","&epsilon;","&zeta;","&eta;","&theta;","&iota;","&kappa;","&lambda;","&mu;","&nu;","&xi;","&omicron;","&pi;","&rho;","&sigmaf;","&sigma;","&tau;","&upsilon;","&phi;","&chi;","&psi;","&omega;","&thetasym;","&upsih;","&piv;","&bull;","&hellip;","&prime;","&Prime;","&oline;","&frasl;","&weierp;","&image;","&real;","&trade;","&alefsym;","&larr;","&uarr;","&rarr;","&darr;","&harr;","&crarr;","&lArr;","&uArr;","&rArr;","&dArr;","&hArr;","&forall;","&part;","&exist;","&empty;","&nabla;","&isin;","&notin;","&ni;","&prod;","&sum;","&minus;","&lowast;","&radic;","&prop;","&infin;","&ang;","&and;","&or;","&cap;","&cup;","&int;","&there4;","&sim;","&cong;","&asymp;","&ne;","&equiv;","&le;","&ge;","&sub;","&sup;","&nsub;","&sube;","&supe;","&oplus;","&otimes;","&perp;","&sdot;","&lceil;","&rceil;","&lfloor;","&rfloor;","&lang;","&rang;","&loz;","&spades;","&clubs;","&hearts;","&diams;","&quot;","&amp;","&lt;","&gt;","&OElig;","&oelig;","&Scaron;","&scaron;","&Yuml;","&circ;","&tilde;","&ensp;","&emsp;","&thinsp;","&zwnj;","&zwj;","&lrm;","&rlm;","&ndash;","&mdash;","&lsquo;","&rsquo;","&sbquo;","&ldquo;","&rdquo;","&bdquo;","&dagger;","&Dagger;","&permil;","&lsaquo;","&rsaquo;","&euro;","&apos;");
141                $entities_decimal        = array("&#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;","&#225;","&#226;","&#227;","&#228;","&#229;","&#230;","&#231;","&#232;","&#233;","&#234;","&#235;","&#236;","&#237;","&#238;","&#239;","&#240;","&#241;","&#242;","&#243;","&#244;","&#245;","&#246;","&#247;","&#248;","&#249;","&#250;","&#251;","&#252;","&#253;","&#254;","&#255;","&#402;","&#913;","&#914;","&#915;","&#916;","&#917;","&#918;","&#919;","&#920;","&#921;","&#922;","&#923;","&#924;","&#925;","&#926;","&#927;","&#928;","&#929;","&#931;","&#932;","&#933;","&#934;","&#935;","&#936;","&#937;","&#945;","&#946;","&#947;","&#948;","&#949;","&#950;","&#951;","&#952;","&#953;","&#954;","&#955;","&#956;","&#957;","&#958;","&#959;","&#960;","&#961;","&#962;","&#963;","&#964;","&#965;","&#966;","&#967;","&#968;","&#969;","&#977;","&#978;","&#982;","&#8226;","&#8230;","&#8242;","&#8243;","&#8254;","&#8260;","&#8472;","&#8465;","&#8476;","&#8482;","&#8501;","&#8592;","&#8593;","&#8594;","&#8595;","&#8596;","&#8629;","&#8656;","&#8657;","&#8658;","&#8659;","&#8660;","&#8704;","&#8706;","&#8707;","&#8709;","&#8711;","&#8712;","&#8713;","&#8715;","&#8719;","&#8721;","&#8722;","&#8727;","&#8730;","&#8733;","&#8734;","&#8736;","&#8743;","&#8744;","&#8745;","&#8746;","&#8747;","&#8756;","&#8764;","&#8773;","&#8776;","&#8800;","&#8801;","&#8804;","&#8805;","&#8834;","&#8835;","&#8836;","&#8838;","&#8839;","&#8853;","&#8855;","&#8869;","&#8901;","&#8968;","&#8969;","&#8970;","&#8971;","&#9001;","&#9002;","&#9674;","&#9824;","&#9827;","&#9829;","&#9830;","&#34;","&#38;","&#60;","&#62;","&#338;","&#339;","&#352;","&#353;","&#376;","&#710;","&#732;","&#8194;","&#8195;","&#8201;","&#8204;","&#8205;","&#8206;","&#8207;","&#8211;","&#8212;","&#8216;","&#8217;","&#8218;","&#8220;","&#8221;","&#8222;","&#8224;","&#8225;","&#8240;","&#8249;","&#8250;","&#8364;","&#39;");
142                if (function_exists('array_combine')) 
143                        $entities_dec=array_combine($entities_named,$entities_decimal);
144                else {
145                        $i=0;
146                        foreach ($entities_named as $_entities_named) $entities_dec[$_entities_named]=$entities_decimal[$i++];
147                }
148        }
149        return preg_replace( "/&[A-Za-z]+;/", " ", strtr($string,$entities_dec) );
150}
151
152function encode_xml($data){
153        // line breaks
154        $data=str_replace('<br(.*?)>',"\n",$data);
155        // ending html tags into line breaks
156        $data=preg_replace("/<\/(pre|ul|li|p|table|tr)>/","\n",$data);
157        // remove other html tags
158        $data=preg_replace("/<(.*?)>/","",$data);
159        // remove multiple newlines
160        $data=preg_replace("/\n\n+/","\n\n",$data);
161        return entity_to_decimal_value($data);
162}
163
164function putHeader($cur, $title) { 
165        switch ($title) {
166                case "cid":
167                        $title = ' : '.$cur['cat_name'];
168                        break;
169                case "fid":
170                        $title = ' : '.$cur['cat_name'].' : '.$cur['forum_name'];
171                        break;
172                case "tid":
173                        $title = ' : '.$cur['cat_name'].' : '.$cur['forum_name'].' : '.$cur['subject'];
174                        break;
175                default:
176                        $title = '';
177                        break;
178        }
179        global $lang_common,$pun_config;
180        echo '<'.'?xml version="1.0" encoding="'.$lang_common['lang_encoding'].'"?'.'>'."\n";
181        echo "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
182        echo "<channel>\n";
183        echo "<atom:link href=\"http://www.revolutionsoundrecords.org/punbb/rss.php\" rel=\"self\" type=\"application/rss+xml\" />\n";
184        echo "<title>".entity_to_decimal_value(htmlspecialchars($pun_config['o_board_title'].$title))."</title>\n";
185        echo "<link>".$pun_config['o_base_url']."</link>\n";
186        echo "<description>".entity_to_decimal_value(htmlspecialchars($rss_description.' '.$pun_config['o_board_title']))."</description>\n";
187        echo "<pubDate>".strval(date("r",$cur['postposted']))."</pubDate>\n";
188        echo "<lastBuildDate>".strval(date("r",$cur['postposted']))."</lastBuildDate>\n";
189} 
190
191function putPost($cur) {
192        global $pun_config;
193        echo "<item>\n";
194        echo "<title>".entity_to_decimal_value(htmlspecialchars($cur['subject'].' in '.$cur['cat_name'].' : '.$cur['forum_name']))."</title>\n";
195        $link = $pun_config['o_base_url'].'/viewtopic.php?pid='.strval($cur['id']).'#'.strval($cur['id']);
196        echo "<link>".entity_to_decimal_value(htmlspecialchars($link))."</link>\n";
197        echo '<guid isPermaLink="false">'.strval($cur['id']).'@'.$pun_config['o_base_url'].'</guid>'."\n";
198        $data = "Topic: ".parse_message($cur['subject'],0)."\n\nMessage: ".parse_message($cur['message'],0);
199        echo "<description>".encode_xml($data)."</description>\n";
200        echo "<pubDate>".strval(date("r",$cur['postposted']))."</pubDate>\n";
201        echo "</item>\n";
202}
203
204
205function putEnd() {
206        echo "</channel>\n";
207        echo "</rss>\n";
208} 
209
210?>
Note: See TracBrowser for help on using the repository browser.