root/trunk/common/rss.php

Revision 776, 6.0 KB (checked in by michiel, 9 months ago)

update copyright year.

Closes #180

  • Property svn:keywords set to Id
Line 
1<?php
2/**
3 * MvBlog -- An open source no-nosense blogtool
4 *
5 * Copyright (C) 2005-2008, Michiel van Baak
6 * Michiel van Baak <mvanbaak@users.sourceforge.net>
7 *
8 * See http://www.mvblog.org for more information on MvBlog.
9 * That page also provides Bugtrackers, Filereleases etc.
10 *
11 * This program is free software, distributed under the terms of
12 * the GNU General Public License Version 2. See the LICENSE file
13 * at the top of the source tree.
14 *
15 * @package MvBlog
16 * @author Michiel van Baak
17 * @version %%VERSION%%
18 * @copyright 2005-2008 Michiel van Baak
19 */
20/*
21 * There are several possible rss feeds:
22 * - global article feed. no url params needed
23 * - comments. rss.php?mode=comments
24 * - comments on a specific article. rss.php?mode=comments&articleid=<nr>
25 * - posts for a category. rss.php&mode=category&cat_id=<nr>
26 * - posts by an author. rss.php&mode=author&author_id=<nr>
27 */
28require("mvblog.php");
29$mvblog = new MvBlog();
30
31//generate url to the root of our website
32if (array_key_exists("HTTPS", $_SERVER) && $_SERVER["HTTPS"] == "on") { $proto = "https"; } else { $proto = "http"; }
33$url = $proto."://".$_SERVER["SERVER_NAME"].(substr($_SERVER["REQUEST_URI"], 0, strpos($_SERVER["REQUEST_URI"], "common/")));
34
35/* most feeds have limit of 1 month */
36$max_time = mktime(0, 0, 0, date("m"), date("d")+1, date("Y"));
37
38if (!array_key_exists("mode", $_REQUEST))
39    $_REQUEST["mode"] = "";
40
41switch ($_REQUEST["mode"]) {
42case "comments" :
43    $sql  = "SELECT c.id AS commentid, c.comment AS body, c.date AS date, c.name AS name, a.title AS title, a.id AS id, a.categories_ids AS categories_id";
44    $sql .= " FROM comments c, articles a WHERE a.active=1 AND a.public=1 AND a.id=c.articles_id";
45    if (array_key_exists("articleid", $_REQUEST)) {
46        $sql .= sprintf(" AND a.id = %d", $_REQUEST["articleid"]);
47    }
48    $sql .= " ORDER BY c.date DESC";
49    $comments = true;
50    break;
51case "category" :
52    if (!array_key_exists("cat_id", $_REQUEST))
53        die("no category given");
54    $sql = sprintf("SELECT * FROM articles WHERE date <= %1\$d AND active=1 AND public=1 AND (
55        categories_ids = '%2\$d' OR categories_ids like '%%,%2\$d' OR categories_ids like '%2\$d,%%' OR categories_ids like '%%,%2\$d,%%'
56        ) ORDER BY date DESC", $max_time, $_REQUEST["cat_id"]);
57    $comments = false;
58    break;
59case "author" :
60    if (!array_key_exists("author_id", $_REQUEST))
61        die("no author given");
62    $sql = sprintf("SELECT * FROM articles WHERE date <= %d AND active=1 AND public=1 AND authors_id = %d ORDER BY date DESC", $max_time, $_REQUEST["author_id"]);
63    $comments = false;
64    break;
65case "dossier" :
66    if (!array_key_exists("dossier_id", $_REQUEST)) {
67        /* list of dossiers */
68        $sql = "SELECT id, name AS title, 0 AS authors_id, ".$mvblog->db_quote("desc")." AS body, '".mktime()."' AS date FROM dossiers WHERE public = 1 AND active = 1 ORDER BY name";
69    } else {
70        /* list articles in given dossier */
71        $sql = sprintf("SELECT * FROM articles WHERE active = 1 AND public = 1 AND dossier_id = %d", $_REQUEST["dossier_id"]);
72    }
73    $comments = false;
74    break;
75default :
76    $sql = sprintf("SELECT * FROM articles WHERE date <= %d AND active=1 AND public=1 ORDER BY date DESC", $max_time);
77    $comments = false;
78    break;
79}
80$mvblog->db->setLimit(20);
81$res =& $mvblog->db->query($sql);
82
83if (PEAR::isError($res)) {
84    die($res->getUserInfo());
85}
86header("Content-Type: text/xml");
87echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
88echo "<rss version=\"2.0\">\n";
89echo "\t<channel>\n";
90echo "\t\t<title>".$mvblog->settings["blogtitle"]."</title>\n";
91echo "\t\t<link>".$url."</link>\n";
92echo "\t\t<description>".htmlentities($mvblog->settings["blogdescription"])."</description>\n";
93echo "\t\t<generator>MvBlog ".$mvblog->version."</generator>\n";
94echo "\t\t<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
95echo "\t\t<ttl>1440</ttl>\n";
96while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
97    if ($comments) {
98        $row["title"] = "Comment on ".$row["title"]." by: ".$row["name"];
99        $link = "#comment".$row["commentid"];
100    } else {
101        $link = "";
102    }
103    echo "\t\t<item>\n";
104    echo "\t\t\t<title>".htmlspecialchars($row["title"])."</title>\n";
105    if (array_key_exists("aside", $row) && $row["aside"] == 1) {
106        echo "\t\t\t<link>".$url."index.php</link>\n";
107        echo "\t\t\t<category>asides</category>\n";
108        echo "\t\t\t<guid isPermaLink=\"false\">".$url."index.php?aside=".$row["id"]."</guid>\n";
109        echo "\t\t\t<author>".htmlspecialchars($mvblog->authors[$row["authors_id"]]["email"])." (".htmlspecialchars($mvblog->authors[$row["authors_id"]]["fullname"]).")</author>\n";
110    } else {
111        if (array_key_exists("mode", $_REQUEST) && $_REQUEST["mode"] == "dossier" && !array_key_exists("dossier_id", $_REQUEST))
112            echo "\t\t\t<link>".$url."index.php?action=viewdossier&amp;id=".$row["id"]."$link</link>\n";
113        else
114            echo "\t\t\t<link>".$url."index.php?action=view&amp;id=".$row["id"]."$link</link>\n";
115        if (array_key_exists("categories_ids", $row))
116            $categories = explode(",", $row["categories_ids"]);
117        else
118            $categories = array();
119        echo "\t\t\t<category>";
120        $category_names = array();
121        foreach ($categories as $v) {
122            if (array_key_exists($v, $mvblog->categories))
123                $category_names[] = $mvblog->categories[$v]["name"];
124        }
125        echo implode(", ", $category_names);
126        echo "</category>\n";
127        if (array_key_exists("mode", $_REQUEST) && $_REQUEST["mode"] == "dossier" && !array_key_exists("dossier_id", $_REQUEST))
128            echo "\t\t\t<guid isPermaLink=\"true\">".$url."index.php?action=viewdossier&amp;id=".$row["id"]."$link</guid>\n";
129        else
130            echo "\t\t\t<guid isPermaLink=\"true\">".$url."index.php?action=view&amp;id=".$row["id"]."$link</guid>\n";
131        if (!$comments) {
132            echo "\t\t\t<comments>".$url."index.php?action=view&amp;id=".$row["id"]."#comments</comments>\n";
133            echo "\t\t\t<author>".htmlspecialchars($mvblog->authors[$row["authors_id"]]["email"])." (".htmlspecialchars($mvblog->authors[$row["authors_id"]]["fullname"]).")</author>\n";
134        }
135    }
136    echo "\t\t\t<description>".htmlentities($mvblog->strip_bbcode(strip_tags(str_replace("##BREAKPOINT##", "", stripslashes($row["body"])))))."</description>\n";
137    echo "\t\t\t<pubDate>".date("r", $row["date"])."</pubDate>\n";
138
139    echo "\t\t</item>\n";
140}
141echo "\t</channel>\n";
142echo "</rss>";
143?>
Note: See TracBrowser for help on using the browser.