[1] | 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 | |
---|
| 33 | define('PUN_ROOT', './'); |
---|
| 34 | @include PUN_ROOT.'config.php'; |
---|
| 35 | |
---|
| 36 | // If PUN isn't defined, config.php is missing or corrupt |
---|
| 37 | if (!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 |
---|
| 41 | error_reporting(E_ERROR | E_WARNING | E_PARSE); |
---|
| 42 | |
---|
| 43 | // Turn off magic_quotes_runtime |
---|
| 44 | set_magic_quotes_runtime(0); |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | // Load the functions script |
---|
| 48 | require PUN_ROOT.'include/functions.php'; |
---|
| 49 | require PUN_ROOT.'include/parser.php'; |
---|
| 50 | |
---|
| 51 | // Load DB abstraction layer and try to connect |
---|
| 52 | require 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()); |
---|
| 56 | while ($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()); |
---|
| 61 | if ($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'; |
---|
| 67 | if (!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 |
---|
| 70 | ob_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 | |
---|
| 83 | if (!empty($_GET["cid"])) { |
---|
| 84 | $where = " AND c.id = '".intval($_GET['cid'])."'"; |
---|
| 85 | $title = 'cid'; |
---|
| 86 | } |
---|
| 87 | else if (!empty($_GET["fid"])) { |
---|
| 88 | $where = " AND f.id = '".intval($_GET['fid'])."'"; |
---|
| 89 | $title = 'fid'; |
---|
| 90 | } |
---|
| 91 | else if (!empty($_GET["tid"])) { |
---|
| 92 | $where = " AND t.id = '".intval($_GET['tid'])."'"; |
---|
| 93 | $title = 'tid'; |
---|
| 94 | } |
---|
| 95 | else { |
---|
| 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; |
---|
| 123 | while ($cur = $db->fetch_assoc($result)) |
---|
| 124 | { if($i == 0) { putHeader($cur, $title); $i++; } |
---|
| 125 | putPost($cur); |
---|
| 126 | } |
---|
| 127 | putEnd(); |
---|
| 128 | |
---|
| 129 | // get feed into $feed |
---|
| 130 | $feed = ob_get_contents(); |
---|
| 131 | ob_end_clean(); |
---|
| 132 | |
---|
| 133 | header ("Content-type: application/rss+xml"); |
---|
| 134 | echo $feed; |
---|
| 135 | |
---|
| 136 | /* entity to unicode decimal value */ |
---|
| 137 | function entity_to_decimal_value($string){ |
---|
| 138 | static $entities_dec = false; |
---|
| 139 | if (!is_array($entities_dec)) { |
---|
| 140 | $entities_named = array(" ","¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯","°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿","À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ","ƒ","Α","Β","Γ","Δ","Ε","Ζ","Η","Θ","Ι","Κ","Λ","Μ","Ν","Ξ","Ο","Π","Ρ","Σ","Τ","Υ","Φ","Χ","Ψ","Ω","α","β","γ","δ","ε","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","ς","σ","τ","υ","φ","χ","ψ","ω","ϑ","ϒ","ϖ","•","…","′","″","‾","⁄","℘","ℑ","ℜ","™","ℵ","←","↑","→","↓","↔","↵","⇐","⇑","⇒","⇓","⇔","∀","∂","∃","∅","∇","∈","∉","∋","∏","∑","−","∗","√","∝","∞","∠","∧","∨","∩","∪","∫","∴","∼","≅","≈","≠","≡","≤","≥","⊂","⊃","⊄","⊆","⊇","⊕","⊗","⊥","⋅","⌈","⌉","⌊","⌋","⟨","⟩","◊","♠","♣","♥","♦",""","&","<",">","Œ","œ","Š","š","Ÿ","ˆ","˜"," "," "," ","‌","‍","‎","‏","–","—","‘","’","‚","“","”","„","†","‡","‰","‹","›","€","'"); |
---|
| 141 | $entities_decimal = array(" ","¡","¢","£","¤","¥","¦","§","¨","©","ª","«","¬","­","®","¯","°","±","²","³","´","µ","¶","·","¸","¹","º","»","¼","½","¾","¿","À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ","ƒ","Α","Β","Γ","Δ","Ε","Ζ","Η","Θ","Ι","Κ","Λ","Μ","Ν","Ξ","Ο","Π","Ρ","Σ","Τ","Υ","Φ","Χ","Ψ","Ω","α","β","γ","δ","ε","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","ς","σ","τ","υ","φ","χ","ψ","ω","ϑ","ϒ","ϖ","•","…","′","″","‾","⁄","℘","ℑ","ℜ","™","ℵ","←","↑","→","↓","↔","↵","⇐","⇑","⇒","⇓","⇔","∀","∂","∃","∅","∇","∈","∉","∋","∏","∑","−","∗","√","∝","∞","∠","∧","∨","∩","∪","∫","∴","∼","≅","≈","≠","≡","≤","≥","⊂","⊃","⊄","⊆","⊇","⊕","⊗","⊥","⋅","⌈","⌉","⌊","⌋","〈","〉","◊","♠","♣","♥","♦",""","&","<",">","Œ","œ","Š","š","Ÿ","ˆ","˜"," "," "," ","‌","‍","‎","‏","–","—","‘","’","‚","“","”","„","†","‡","‰","‹","›","€","'"); |
---|
| 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 | |
---|
| 152 | function 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 | |
---|
| 164 | function 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 | |
---|
| 191 | function 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 | |
---|
| 205 | function putEnd() { |
---|
| 206 | echo "</channel>\n"; |
---|
| 207 | echo "</rss>\n"; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | ?> |
---|