avatar

560

OS X compliant. Fully valid RSS. Fake-file extension support added for images

by brian, 27 Jun, 2009 04:46 PM
558 560  
5858 
5959    function imageAction()
6060    {
61       $content = new Content($this->args[1]);
61       $c_id = explode('.', $this->args[1]); //In case a file extension is passed, we'll want to remove it
62       $content = new Content($c_id[0]);
6263       $this->file = $content->content;
6364       $this->height = $_GET['height'];
6465       $this->width = $_GET['width'];
008 008  
220220     header("Content-type: text/xml");
221221     echo '<?xml version="1.0"?>';
222222 ?>
223 <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:dcterms="http://purl.org/dc/terms/">
223 <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:atom="http://www.w3.org/2005/Atom">
224224     <channel>
225225         <title><?= htmlspecialchars(utf8_encode($feed_title)) ?></title>
226226         <link>http://<?= $_SERVER['SERVER_NAME'] ?>/<?= ROOT_URL ?></link>
------
229229         <pubDate><?= rssdate("now") ?></pubDate>
230230         <generator>Concerto API 0.08</generator>
231231         <webMaster><?= SYSTEM_EMAIL ?> (Concerto Digital Signage)</webMaster>
232         <atom:link href="<?= 'http://' . $_SERVER['SERVER_NAME'] . htmlspecialchars($_SERVER['REQUEST_URI']) ?>" rel="self" type="application/rss+xml" />
232233         <image>
233234             <url><?= 'http://' . $_SERVER['SERVER_NAME'] . ADMIN_BASE_URL ?>/images/concerto_48x48.png</url>
234             <title>Concerto</title>
235             <link><?= 'http://' . $_SERVER['SERVER_NAME'] . ADMIN_BASE_URL ?></link>
235             <title><?= htmlspecialchars(utf8_encode($feed_title)) ?></title>
236             <link>http://<?= $_SERVER['SERVER_NAME'] ?>/<?= ROOT_URL ?></link>
236237             <width>48</width>
237238             <height>48</height>
238239         </image>
239240 
240 <?  foreach($content_arr as $content){
241 <? 
242  /*Sometimes, including the 'index.php' portion of the URL breaks clients like the built-in OS X screensaver.
243   *By removing the reference to index.php, the screensaver doesn't know what to expect, and works.
244   *This has taken multiple months to find.
245   */
246   $script_name = preg_replace('/(index\.php)$/', '', $_SERVER['SCRIPT_NAME']);
247   
248   foreach($content_arr as $content){
241249         $link = 'http://' . $_SERVER['SERVER_NAME'] .  $_SERVER['SCRIPT_NAME'] . '?' . criteria_string($criteria) . '&select_id=' . $content->id . '&select=content&format=rss';
242250         $link = htmlspecialchars($link);
243251         $feeds = $content->list_feeds();
244252         $user = new User($content->user_id);
245253         $rss_link = 'http://' . $_SERVER['SERVER_NAME'] .  $_SERVER['SCRIPT_NAME'] . '?' . criteria_string($criteria, 'rss') . '&select=content&select_id='.$content->id.'&format=raw';
246         $raw_link = 'http://' . $_SERVER['SERVER_NAME'] .  $_SERVER['SCRIPT_NAME'] . '?' . criteria_string($criteria) . '&select=content&select_id='.$content->id.'&format=raw';
254         
255        /* If mod_rewrite isn't enabled, this won't work, but it is required for some clients that care about file extensions
256         * Without mod_rewrite, you can just use remove "'image_' . $content->content"
257         */
258         $raw_link = 'http://' . $_SERVER['SERVER_NAME'] .  $script_name . 'image_' . $content->content . '?' . criteria_string($criteria) . '&select=content&select_id='.$content->id.'&format=raw';
247259         if(strpos($content->mime_type,'image') !== false){
248260             $desc = '<![CDATA[ <img src="' . $rss_link . '" /> ]]>';
249261         } elseif(strpos($content->mime_type, 'html')){
------
258270             <description><?= $desc ?></description>
259271             <pubDate><?= rssdate($content->submitted) ?></pubDate>
260272             <author><?= $user->username ?>@rpi.edu (<?= htmlspecialchars(utf8_encode($user->name)) ?>)</author>
261             <guid isPermaLink="false"><?= $content->id ?></guid>
273             <guid isPermaLink="false"><?= 'http://' . $_SERVER['SERVER_NAME'] . ADMIN_URL ?>/content/show/<?= $content->id ?></guid>
262274 <?          foreach($feeds as $feed_obj){
263275                 if($feed_obj['moderation_flag'] == 1 && $feed_obj['feed']->type != 3){
264276                     $feed = $feed_obj['feed'];
------
270282             }
271283             if(strpos($content->mime_type,'image') !== false){
272284 ?>
273             <enclosure url="<?= htmlspecialchars($raw_link) ?>" type="<?= $content->mime_type ?>" />
285             <enclosure url="<?= htmlspecialchars($raw_link) ?>" type="<?= $content->mime_type ?>" length='0'/>
274286             <media:content url="<?= htmlspecialchars($raw_link) ?>" type="<?= $content->mime_type ?>" expression="full" />
275287             <media:title type="plain"><?= htmlspecialchars($content->name) ?></media:title>
276288             <media:thumbnail url="<?= htmlspecialchars($rss_link) ?>" width="100" height="100"/>