[ Index ] |
|
Code source de Phorum 5.1.25 |
1 <?php 2 3 //////////////////////////////////////////////////////////////////////////////// 4 // // 5 // Copyright (C) 2006 Phorum Development Team // 6 // http://www.phorum.org // 7 // // 8 // This program is free software. You can redistribute it and/or modify // 9 // it under the terms of either the current Phorum License (viewable at // 10 // phorum.org) or the Phorum License that was distributed with this file // 11 // // 12 // This program is distributed in the hope that it will be useful, // 13 // but WITHOUT ANY WARRANTY, without even the implied warranty of // 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // 15 // // 16 // You should have received a copy of the Phorum License // 17 // along with this program. // 18 // July 19 Fixed by Dagon, Date format and Location default // 19 //////////////////////////////////////////////////////////////////////////////// 20 21 define('phorum_page', 'rss'); 22 23 include_once ("./common.php"); 24 include_once ("./include/format_functions.php"); 25 26 // check this forum allows RSS 27 if(!$PHORUM['use_rss']){ 28 exit(); 29 } 30 31 $cache_key = $_SERVER["QUERY_STRING"].",".$PHORUM["user"]["user_id"]; 32 33 $data=""; 34 // only do this with caching enabled 35 if(isset($PHORUM['cache_rss']) && !empty($PHORUM['cache_rss'])) { 36 $data = phorum_cache_get("rss", $cache_key); 37 } 38 39 if(empty($data)){ 40 41 if($PHORUM["forum_id"]==$PHORUM["vroot"]){ 42 $forums = phorum_db_get_forums(0, -1, $PHORUM["vroot"]); 43 $forum_ids = array_keys($forums); 44 } elseif($PHORUM["folder_flag"] && $PHORUM["vroot"]==0 && $PHORUM["forum_id"]!=0){ 45 // we don't support rss for normal folders 46 exit(); 47 } else { 48 $forum_ids = $PHORUM["forum_id"]; 49 $forums = phorum_db_get_forums($PHORUM["forum_id"]); 50 } 51 52 // find default forum for announcements 53 foreach($forums as $forum_id=>$forum){ 54 if($forum["folder_flag"]){ 55 unset($forums[$forum_id]); 56 } elseif(empty($default_forum_id)) { 57 $default_forum_id = $forum_id; 58 } 59 } 60 61 $PHORUM["threaded_list"]=false; 62 $PHORUM["float_to_top"]=false; 63 64 // get the thread set started 65 $rows = array(); 66 $thread = (isset($PHORUM["args"][1])) ? (int)$PHORUM["args"][1] : 0; 67 68 $rows = phorum_db_get_recent_messages(30, $forum_ids, $thread); 69 70 unset($rows["users"]); 71 72 $items = array(); 73 $pub_date=0; 74 foreach($rows as $key => $row){ 75 76 if(!$PHORUM["forum_id"]){ 77 $row["subject"]="[".$forums[$row["forum_id"]]["name"]."] ".$row["subject"]; 78 } 79 80 $forum_id = ($row["forum_id"]==0) ? $default_forum_id : $row["forum_id"]; 81 82 $items[]=array( 83 "pub_date" => date("r",$row["datestamp"]), 84 "url" => phorum_get_url(PHORUM_FOREIGN_READ_URL, $forum_id, $row["thread"], $row["message_id"]), 85 "headline" => $row["subject"], 86 "description" => $row["body"], 87 "author" => $row["author"], 88 "category" => $forums[$row["forum_id"]]["name"] 89 ); 90 91 92 $pub_date = max($row["datestamp"], $pub_date); 93 94 } 95 96 if (!$PHORUM['locale']) $PHORUM['locale'] ="en"; //if locale not set make it 'en' 97 98 if($PHORUM["forum_id"]){ 99 $url = phorum_get_url(PHORUM_LIST_URL); 100 $name = $PHORUM["name"]; 101 $description = strip_tags($PHORUM["description"]); 102 } else { 103 $url = phorum_get_url(PHORUM_INDEX_URL); 104 $name = $PHORUM["title"]; 105 $description = ""; 106 } 107 108 $channel = array( 109 110 "name" => $name, 111 "url" => $url, 112 "description" => $description, 113 "pub_date" => date("r",$pub_date), 114 "language" => $PHORUM['locale'] 115 116 ); 117 $items = rss_bad_word_check($items); 118 $data = create_rss_feed($channel, $items); 119 120 } 121 122 $charset = ''; 123 if (! empty($GLOBALS["PHORUM"]["DATA"]["CHARSET"])) { 124 $charset = '; charset=' . htmlspecialchars($GLOBALS["PHORUM"]["DATA"]['CHARSET']); 125 } 126 header("Content-Type: text/xml$charset"); 127 128 echo $data; 129 // only do this with caching enabled 130 if(isset($PHORUM['cache_rss']) && !empty($PHORUM['cache_rss'])) { 131 phorum_cache_put("rss", $cache_key, $data, 300); 132 } 133 134 /*******************************************************/ 135 136 function create_rss_feed($channel, $items) 137 { 138 if(empty($items)){ 139 return; 140 } 141 142 $encoding = ''; 143 if (! empty($GLOBALS["PHORUM"]["DATA"]["CHARSET"])) { 144 $encoding = 'encoding="' . htmlspecialchars($GLOBALS["PHORUM"]["DATA"]['CHARSET']) . '"'; 145 } 146 147 $data ="<?xml version=\"1.0\" $encoding ?>\n"; 148 $data.="<rss version=\"2.0\">\n"; 149 $data.=" <channel>\n"; 150 $data.=" <title>".htmlspecialchars(strip_tags($channel["name"]))."</title>\n"; 151 $data.=" <link>" . htmlspecialchars($channel["url"]) . "</link>\n"; 152 $data.=" <description><![CDATA[$channel[description]]]></description>\n"; 153 $data.=" <language>" . htmlspecialchars($channel["language"]) . "</language>\n"; 154 155 $data.=" <pubDate>$channel[pub_date]</pubDate>\n"; 156 $data.=" <lastBuildDate>$channel[pub_date]</lastBuildDate>\n"; 157 $data.=" <category>".htmlspecialchars(strip_tags($channel["name"]))."</category>\n"; 158 $data.=" <generator>Phorum ".PHORUM."</generator>\n"; 159 160 $data.=" <ttl>60</ttl>\n"; 161 162 foreach($items as $item){ 163 $data.=" <item>\n"; 164 $data.=" <title>".htmlspecialchars($item["headline"])."</title>\n"; 165 $data.=" <link>$item[url]</link>\n"; 166 $data.=" <author>".htmlspecialchars($item["author"])."</author>\n"; 167 $data.=" <description><![CDATA[".nl2br(htmlspecialchars($item["description"]))."]]></description>\n"; 168 $data.=" <category>".htmlspecialchars(strip_tags($item["category"]))."</category>\n"; 169 $data.=" <guid isPermaLink=\"true\">".htmlspecialchars($item["url"])."</guid>\n"; 170 $data.=" <pubDate>$item[pub_date]</pubDate>\n"; 171 $data.=" </item>\n"; 172 } 173 174 $data.=" </channel>\n"; 175 $data.="</rss>\n"; 176 177 return $data; 178 } 179 180 181 function rss_bad_word_check($items) { 182 $PHORUM = $GLOBALS["PHORUM"]; 183 184 // Prepare the bad-words replacement code. 185 $bad_word_check= false; 186 $banlists = phorum_db_get_banlists(); 187 if (isset($banlists[PHORUM_BAD_WORDS]) && is_array($banlists[PHORUM_BAD_WORDS])) { 188 $replace_vals = array(); 189 $replace_words = array(); 190 foreach ($banlists[PHORUM_BAD_WORDS] as $item) { 191 $replace_words[] = "/\b".preg_quote($item['string'])."(ing|ed|s|er|es)*\b/i"; 192 $replace_vals[] = PHORUM_BADWORD_REPLACE; 193 $bad_word_check = true; 194 } 195 } 196 197 // only go in if we actually have replace items 198 if($bad_word_check) { 199 foreach ($items as $key => $value) { 200 $items[$key]['headline'] = preg_replace($replace_words, $replace_vals, $items[$key]['headline']); 201 $items[$key]['description'] = preg_replace($replace_words, $replace_vals, $items[$key]['description']); 202 } 203 } 204 205 return $items; 206 } 207 208 209 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:22:27 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |