| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | include_once(dirname(__FILE__)."/plog-load-config.php"); |
|---|
| 4 | |
|---|
| 5 | function 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 | |
|---|
| 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 | |
|---|
| 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('&', '&', $_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 | |
|---|
| 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 | |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | $pagelink = $config['gallery_url'] . "?level=picture&id=" . plogger_get_picture_id(); |
|---|
| 96 | |
|---|
| 97 | if ($caption == "" || $caption == " ") $caption = plog_tr("New Image (no caption)"); |
|---|
| 98 | $caption .= " - " . $takendate; |
|---|
| 99 | |
|---|
| 100 | $descript = '<p><a href="'.$pagelink.'" |
|---|
| 101 | title="'.$caption.'"> |
|---|
| 102 | <img src="'.$thumbpath.'" alt="'.$caption.'" style="border: 1px solid #000000;" /> |
|---|
| 103 | </a></p><p>'.$caption.'</p>'; |
|---|
| 104 | |
|---|
| 105 | $descript .= '<p>'.htmlspecialchars(plogger_get_picture_description()).'</p>'; |
|---|
| 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 | |
|---|
| 135 | header("Content-Type: application/xml"); |
|---|
| 136 | |
|---|
| 137 | $level = isset($_GET['level']) ? $_GET['level'] : ''; |
|---|
| 138 | $id = isset($_GET['id']) ? intval($_GET['id']) : '0'; |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | if (!empty($_REQUEST['path'])) { |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 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']); |
|---|
| 153 | if (isset($parts['query'])){ |
|---|
| 154 | parse_str($parts['query'],$query_parts); |
|---|
| 155 | } |
|---|
| 156 | if (isset($query_parts['searchterms'])) { |
|---|
| 157 | generate_RSS_feed($level, $id, $query_parts['searchterms']); |
|---|
| 158 | } else { |
|---|
| 159 | generate_RSS_feed($level, $id); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | ?> |
|---|