root/trunk/plog-rss.php

Revision 585, 5.9 KB (checked in by kimparsell, 3 months ago)

+ Resolution for ticket 182: update Exifer lib to version 1.7 after successful testing with latest SVN version
+ Miscellaneous cleanup of the other libs
+ Admin:

  • Login: update to new style
  • Themes: Add 2 new column titles and make all titles translatable
  • Import: change table header and appearance to match overall admin theme
  • Miscellaneous file cleanup

+ Themes: miscellaneous cleanup
+ General: miscellaneous cleanup

Line 
1<?php
2// this file handles the generation of the RSS feed.
3include_once(dirname(__FILE__)."/plog-load-config.php");
4
5function generate_RSS_feed ($level, $id, $search = "") {
6    global $config;
7
8    $config["feed_title"] = SmartStripSlashes($config["feed_title"]);
9
10    if (!empty($search)) $level = "search";
11
12    // aggregate feed of all albums with collection specified by id
13    if ($level == "collection") {
14        plogger_init_pictures(array(
15        'type' => 'collection',
16        'value' => $id,
17        'limit' => $config['feed_num_entries'],
18        'sortby' => 'id',
19        ));
20        $collection = get_collection_by_id($id);
21        $config["feed_title"] .= ": " . $collection['name'] . " " . plog_tr("Collection");
22
23    } else if ($level == "album") {
24        plogger_init_pictures(array(
25        'type' => 'album',
26        'value' => $id,
27        'limit' => $config['feed_num_entries'],
28        'sortby' => 'id',
29        ));
30        $album = get_album_by_id($id);
31        $config["feed_title"] .= ": " . $album['album_name'] . " " . plog_tr("Album");
32
33    } else if ($level == "picture") {
34        plogger_init_picture(array(
35        'id' => $id,
36        'comments' => 'DESC'
37        ));
38        $picture = get_picture_by_id($id);
39        $config["feed_title"] .= ": " . basename($picture['path']);
40
41    } else if ($level == "search") {
42        plogger_init_search(array(
43        'searchterms' => $search,
44        'limit' => $config['feed_num_entries'],
45        ));
46
47    } else if (($level == "collections") or ($level == "")) {
48        plogger_init_pictures(array(
49        'type' => 'latest',
50        'limit' => $config['feed_num_entries'],
51        'sortby' => 'id',
52        ));
53        $config["feed_title"] .= ": " . plog_tr("Entire Gallery");
54    }
55
56    // generate RSS header
57    $rssFeed = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
58    $rssFeed.= "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:media=\"http://search.yahoo.com/mrss/\">\n";
59
60    $rssFeed.= "<channel>\n";
61    $rssFeed.= "<title>".$config['feed_title']."</title>\n";
62    $rssFeed.= "<description>" . plog_tr("Plogger RSS Feed") . "</description>\n";
63    $rssFeed.= "<language>".$config['feed_language']."</language>\n";
64    $rssFeed.= "<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
65    $rssFeed.= "<generator>Plogger</generator>\n";
66    $rssFeed.= "<link>".$config['gallery_url']."</link>\n";
67    $rssFeed.= "<atom:link href=\"http://".$_SERVER['HTTP_HOST'].str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."\" rel=\"self\" type=\"application/rss+xml\" />\n";
68
69    $header = 1;
70
71    while(plogger_has_pictures()) {
72        plogger_load_picture();
73        // if at picture level, check to make sure it has comments first
74        if ($level != "picture" || plogger_picture_has_comments()) {
75
76            if ($header) {
77                $submitdate = plogger_get_picture_date("D, d M Y H:i:s O",1);
78                $takendate = plogger_get_picture_date();
79
80                $rssFeed.= "<pubDate>". $submitdate . "</pubDate>\n";
81                $rssFeed.= "<lastBuildDate>". $submitdate . "</lastBuildDate>\n";
82                $header = 0;
83            }
84
85            $rssFeed .= "<item>\n";
86
87            $urlPath = str_replace(array("%2F", "%3A"), array("/", ":"), rawurlencode(plogger_get_source_picture_url()));
88
89            $caption = plogger_get_picture_caption();
90            $thumbpath = plogger_get_picture_thumb(THUMB_RSS);
91
92            //$pagelink = $config["address"] . plogger_get_picture_url();
93            // XXX: Below won't look nice with mod_rewrite, but plogger_get_picture_url
94            // returns wrong filename, needs to be fixed - still needs to be fixed as this does not always work as wanted either
95            $pagelink = $config['gallery_url'] . "?level=picture&amp;id=" . plogger_get_picture_id();
96
97            if ($caption == "" || $caption == "&nbsp;") $caption = plog_tr("New Image (no caption)");
98            $caption .= " - " . $takendate;
99
100            $descript = '&lt;p&gt;&lt;a href="'.$pagelink.'"
101            title="'.$caption.'"&gt;
102            &lt;img src="'.$thumbpath.'" alt="'.$caption.'" style="border: 1px solid #000000;" /&gt;
103            &lt;/a&gt;&lt;/p&gt;&lt;p&gt;'.$caption.'&lt;/p&gt;';
104
105            $descript .= '&lt;p&gt;'.htmlspecialchars(plogger_get_picture_description()).'&lt;/p&gt;';
106
107            $rssFeed .= "\t<pubDate>" . $submitdate . "</pubDate>\n";
108            $rssFeed .= "\t<title>" . $caption "</title>\n";
109            $rssFeed .= "\t<link>" . $pagelink . "</link>\n";
110            $rssFeed .= "\t<description>" . $descript "</description>\n";
111            $rssFeed .= "\t<guid isPermaLink=\"false\">".$thumbpath."</guid>\n";
112            $rssFeed .= "\t<media:content url=\"" . $urlPath . "\" type=\"image/jpeg\" />\n";
113            $rssFeed .= "\t<media:title>" . $caption . "</media:title>\n";
114            $rssFeed .= "</item>\n";
115            if ($level == "picture") {
116                while(plogger_picture_has_comments()) {
117                    plogger_load_comment();
118                    $rssFeed .= "<item>\n";
119                    $rssFeed .= "\t<pubDate>" . plogger_get_comment_date("D, d M Y H:i:s O") . "</pubDate>\n";
120                    $rssFeed .= "\t<title>Comment by " . plogger_get_comment_author() . "</title>\n";
121                    $rssFeed .= "\t<link>" . $pagelink . "</link>\n";
122                    $rssFeed .= "\t<description>" . plogger_get_comment_text() .  "</description>\n";
123                    $rssFeed .= "\t<guid isPermaLink=\"true\">".$pagelink."#Comment-".plogger_get_comment_id()."</guid>\n";
124                    $rssFeed .= "</item>\n";
125                }
126            }
127        }
128    }
129
130    $rssFeed .= "</channel>\n</rss>";
131    echo $rssFeed;
132}
133
134// send proper header
135header("Content-Type: application/xml");
136
137$level = isset($_GET['level']) ? $_GET['level'] : '';
138$id = isset($_GET['id']) ? intval($_GET['id']) : '0';
139
140// process path here - is set if mod_rewrite is in use
141
142// Some Estonian remarks was here
143if (!empty($_REQUEST['path'])) {
144    // The following line calculates the path in the album and excludes any subdirectories if
145    // Plogger is installed in one
146    $path = join("/",array_diff(explode("/",$_SERVER["REQUEST_URI"]),explode("/",$_SERVER["PHP_SELF"])));
147    $resolved_path = resolve_path($path);
148    $level = (isset($resolved_path['level'])) ? $resolved_path['level'] : "collections";
149    $id = (isset($resolved_path['id'])) ? $resolved_path['id'] : 0;
150}
151
152$parts = parse_url($_SERVER['REQUEST_URI']);
153if (isset($parts['query'])){
154    parse_str($parts['query'],$query_parts);
155}
156if (isset($query_parts['searchterms'])) {
157    generate_RSS_feed($level, $id, $query_parts['searchterms']);
158} else {
159    generate_RSS_feed($level, $id);
160}
161
162?>
Note: See TracBrowser for help on using the browser.