Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 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
$data = phorum_cache_get("rss", $cache_key);
33
 
34
if(empty($data)){
35
 
36
    if($PHORUM["forum_id"]==$PHORUM["vroot"]){
37
        $forums = phorum_db_get_forums(0, -1, $PHORUM["vroot"]);
38
        $forum_ids = array_keys($forums);
39
    } elseif($PHORUM["folder_flag"] && $PHORUM["vroot"]==0 && $PHORUM["forum_id"]!=0){
40
        // we don't support rss for normal folders
41
        exit();
42
    } else {
43
        $forum_ids = $PHORUM["forum_id"];
44
        $forums = phorum_db_get_forums($PHORUM["forum_id"]);
45
    }
46
 
47
    // find default forum for announcements
48
    foreach($forums as $forum_id=>$forum){
49
        if($forum["folder_flag"]){
50
            unset($forums[$forum_id]);
51
        } elseif(empty($default_forum_id)) {
52
            $default_forum_id = $forum_id;
53
        }
54
    }
55
 
56
    $PHORUM["threaded_list"]=false;
57
    $PHORUM["float_to_top"]=false;
58
 
59
    // get the thread set started
60
    $rows = array();
61
    $thread = (isset($PHORUM["args"][1])) ? (int)$PHORUM["args"][1] : 0;
62
 
63
    $rows = phorum_db_get_recent_messages(30, $forum_ids, $thread);
64
 
65
    unset($rows["users"]);
66
 
67
    $items = array();
68
    $pub_date=0;
69
    foreach($rows as $key => $row){
70
 
71
        if(!$PHORUM["forum_id"]){
72
            $row["subject"]="[".$forums[$row["forum_id"]]["name"]."] ".$row["subject"];
73
        }
74
 
75
        $forum_id = ($row["forum_id"]==0) ? $default_forum_id : $row["forum_id"];
76
 
77
        $items[]=array(
78
            "pub_date" => date("r",$row["datestamp"]),
79
            "url" => phorum_get_url(PHORUM_FOREIGN_READ_URL, $forum_id, $row["thread"], $row["message_id"]),
80
            "headline" => $row["subject"],
81
            "description" => strip_tags($row["body"]),
82
            "author" => $row["author"],
83
            "category" => $forums[$row["forum_id"]]["name"]
84
        );
85
 
86
 
87
        $pub_date = max($row["datestamp"], $pub_date);
88
 
89
    }
90
 
91
    if (!$PHORUM['locale']) $PHORUM['locale'] ="en"; //if locale not set make it 'en'
92
 
93
    if($PHORUM["forum_id"]){
94
        $url = phorum_get_url(PHORUM_LIST_URL);
95
        $name = $PHORUM["name"];
96
        $description = strip_tags($PHORUM["description"]);
97
    } else {
98
        $url = phorum_get_url(PHORUM_INDEX_URL);
99
        $name = $PHORUM["title"];
100
        $description = "";
101
    }
102
 
103
    $channel = array(
104
 
105
        "name" => $name,
106
        "url" => $url,
107
        "description" => $description,
108
        "pub_date" => date("r",$pub_date),
109
        "language" => $PHORUM['locale']
110
 
111
    );
112
 
113
    $data = create_rss_feed($channel, $items);
114
 
115
}
116
 
117
$charset = '';
118
if (! empty($GLOBALS["PHORUM"]["DATA"]["CHARSET"])) {
119
    $charset = '; charset=' . htmlspecialchars($GLOBALS["PHORUM"]["DATA"]['CHARSET']);
120
}
121
header("Content-Type: text/xml$charset");
122
 
123
echo $data;
124
 
125
phorum_cache_put("rss", $cache_key, $data, 300);
126
 
127
/*******************************************************/
128
 
129
function create_rss_feed($channel, $items)
130
{
131
 
132
    if(empty($items)){
133
        return;
134
    }
135
 
136
    $encoding = '';
137
    if (! empty($GLOBALS["PHORUM"]["DATA"]["CHARSET"])) {
138
        $encoding = 'encoding="' . htmlspecialchars($GLOBALS["PHORUM"]["DATA"]['CHARSET']) . '"';
139
    }
140
 
141
    $data ="<?xml version=\"1.0\" $encoding ?>\n";
142
    $data.="<rss version=\"2.0\">\n";
143
    $data.="  <channel>\n";
144
    $data.="    <title>".htmlspecialchars(strip_tags($channel["name"]))."</title>\n";
145
    $data.="    <link>$channel[url]</link>\n";
146
    $data.="    <description><![CDATA[$channel[description]]]></description>\n";
147
    $data.="    <language>$channel[language]</language>\n";
148
 
149
    $data.="    <pubDate>$channel[pub_date]</pubDate>\n";
150
    $data.="    <lastBuildDate>$channel[pub_date]</lastBuildDate>\n";
151
    $data.="    <category>".htmlspecialchars(strip_tags($channel["name"]))."</category>\n";
152
    $data.="    <generator>Phorum ".PHORUM."</generator>\n";
153
 
154
    $data.="    <ttl>600</ttl>\n";
155
 
156
    foreach($items as $item){
157
        $data.="    <item>\n";
158
        $data.="      <title>".htmlspecialchars($item['headline'])."</title>\n";
159
        $data.="      <link>$item[url]</link>\n";
160
        $data.="      <author>".htmlspecialchars($item['author'])."</author>\n";
161
        $data.="      <description><![CDATA[".htmlspecialchars($item['description'])."]]></description>\n";
162
        $data.="      <category>".htmlspecialchars(strip_tags($item['category']))."</category>\n";
163
        $data.="      <guid isPermaLink=\"true\">$item[url]</guid>\n";
164
        $data.="      <pubDate>$item[pub_date]</pubDate>\n";
165
        $data.="    </item>\n";
166
    }
167
 
168
    $data.="  </channel>\n";
169
    $data.="</rss>\n";
170
 
171
    return $data;
172
 
173
}
174
 
175
 
176
?>