function render_rss($content_arr, $criteria){
    if($criteria['select'] == 'user'){
        $filter = 'username';
    }else{
        $filter = 'id';
    }
    $sql = "SELECT name FROM {$criteria['select']} WHERE $filter = '{$criteria['select_id']}' LIMIT 1";
    $res = sql_query($sql);
    $row = sql_row_keyed($res,0);
    $feed_title = $row['name'];
    
    header("Content-type: text/xml");
    echo '<?xml version="1.0"?>';
?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:dcterms="http://purl.org/dc/terms/">
    <channel>
        <title><?php 
echo htmlspecialchars($feed_title);
?>
</title>
        <link>http://<?php 
echo $_SERVER['SERVER_NAME'];
?>
/<?php 
echo ROOT_URL;
?>
</link>
        <description>RSS Feed from Concerto API</description>
        <language>en-us</language>
        <pubDate><?php 
echo rssdate("now");
?>
</pubDate>
        <generator>Concerto API 0.07</generator>
        <webMaster><?php 
echo SYSTEM_EMAIL;
?>
</webMaster>
        <image>
            <url><?php 
echo 'http://' . $_SERVER['SERVER_NAME'] . ADMIN_BASE_URL;
?>
/images/conc_logowhitebg_sm.jpg</url>
            <title>Concerto</title>
            <link><?php 
echo 'http://' . $_SERVER['SERVER_NAME'] . ADMIN_BASE_URL;
?>
</link>
            <width>700</width>
            <height>185</height>
        </image>

<?  foreach($content_arr as $content){
        $link = 'http://' . $_SERVER['SERVER_NAME'] .  $_SERVER['SCRIPT_NAME'] . '?' . criteria_string($criteria) . '&select_id=' . $content->id . '&select=content&format=rss';
        $link = htmlspecialchars($link);
        $feeds = $content->list_feeds();
        $user = new User($content->user_id);
        $rss_link = 'http://' . $_SERVER['SERVER_NAME'] .  $_SERVER['SCRIPT_NAME'] . '?' . criteria_string($criteria, 'rss') . '&select=content&select_id='.$content->id.'&format=raw';
        $raw_link = 'http://' . $_SERVER['SERVER_NAME'] .  $_SERVER['SCRIPT_NAME'] . '?' . criteria_string($criteria) . '&select=content&select_id='.$content->id.'&format=raw';
        if(strpos($content->mime_type,'image') !== false){
            $desc = '<![CDATA[ <img src="' . $rss_link . '" /> ]]>';
        } elseif(strpos($content->mime_type, 'html')){
            $desc = '<![CDATA[' . $content->content . ' ]]>';
        } else {
            $desc = $content->content;
        }
?>
        <item>
            <title><?php 
echo htmlspecialchars($content->name);
?>
</title>
            <link><?php 
echo $link;
?>
</link>
            <description><?php 
echo $desc;
?>
</description>
            <pubDate><?php 
echo rssdate($content->submitted);
?>
</pubDate>
            <author><?php 
echo $user->username;
?>
 (<?php 
echo htmlspecialchars($user->name);
?>
)</author>
            <guid><?php 
echo $content->id;
?>
</guid>
<?          foreach($feeds as $feed_obj){
                if($feed_obj['moderation_flag'] == 1 && $feed_obj['feed']->type != 3){
                    $feed = $feed_obj['feed'];
                    $feed_link = 'http://' . $_SERVER['SERVER_NAME'] .  $_SERVER['SCRIPT_NAME'] . '?' . criteria_string($criteria) . "&select=feed&select_id={$feed->id}&format=rss";
?>
            <category domain="<?php 
echo htmlspecialchars($feed_link);
?>
"><?php 
echo htmlspecialchars($feed->name);
?>
</category>
<?
                }
            }
            if(strpos($content->mime_type,'image') !== false){
?>
            <media:content url="<?php 
echo htmlspecialchars($raw_link);
?>
" type="<?php 
echo $content->mime_type;
?>
" expression="full" />
            <media:title type="plain"><?php 
echo htmlspecialchars($content->name);
?>
</media:title>
            <media:thumbnail url="<?php 
echo htmlspecialchars($rss_link);
?>
" width="100" height="100"/>
<?
            }
?>
            <dcterms:valid>
                start=<?php 
echo w3date($content->start_time);
?>
;
                end=<?php 
echo w3date($content->end_time);
?>
;
                scheme=W3C-DTF
            </dcterms:valid>
        </item>
<?  } ?>
    </channel>
</rss>
<?
}
Esempio n. 2
0
function render_rss($content_arr, $criteria)
{
    if ($criteria['select'] == 'user') {
        $filter = 'username';
    } else {
        $filter = 'id';
    }
    $sql = "SELECT name FROM {$criteria['select']} WHERE {$filter} = '{$criteria['select_id']}' LIMIT 1";
    $res = sql_query($sql);
    $row = sql_row_keyed($res, 0);
    $feed_title = $row['name'];
    header("Content-type: text/xml");
    echo '<?xml version="1.0"?>';
    ?>
<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">
    <channel>
        <title><?php 
    echo htmlspecialchars(utf8_encode($feed_title));
    ?>
</title>
        <link>http://<?php 
    echo $_SERVER['SERVER_NAME'];
    ?>
/<?php 
    echo ROOT_URL;
    ?>
</link>
        <description>RSS Feed from Concerto API</description>
        <language>en-us</language>
        <pubDate><?php 
    echo rssdate("now");
    ?>
</pubDate>
        <generator>Concerto API 0.08</generator>
        <webMaster><?php 
    echo SYSTEM_EMAIL;
    ?>
 (Concerto Digital Signage)</webMaster>
        <atom:link href="<?php 
    echo 'http://' . $_SERVER['SERVER_NAME'] . htmlspecialchars($_SERVER['REQUEST_URI']);
    ?>
" rel="self" type="application/rss+xml" />
        <image>
            <url><?php 
    echo 'http://' . $_SERVER['SERVER_NAME'] . ADMIN_BASE_URL;
    ?>
/images/concerto_48x48.png</url>
            <title><?php 
    echo htmlspecialchars(utf8_encode($feed_title));
    ?>
</title>
            <link>http://<?php 
    echo $_SERVER['SERVER_NAME'];
    ?>
/<?php 
    echo ROOT_URL;
    ?>
</link>
            <width>48</width>
            <height>48</height>
        </image>

<?php 
    /*Sometimes, including the 'index.php' portion of the URL breaks clients like the built-in OS X screensaver.
     *By removing the reference to index.php, the screensaver doesn't know what to expect, and works.
     *This has taken multiple months to find.
     */
    $script_name = preg_replace('/(index\\.php)$/', '', $_SERVER['SCRIPT_NAME']);
    foreach ($content_arr as $content) {
        $link = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '?' . criteria_string($criteria) . '&select_id=' . $content->id . '&select=content&format=rss';
        $link = htmlspecialchars($link);
        $feeds = $content->list_feeds();
        $user = new User($content->user_id);
        $rss_link = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '?' . criteria_string($criteria, 'rss') . '&select=content&select_id=' . $content->id . '&format=raw';
        /*
         * So 10.6 inspects the last few characters of the enclosure url querystring
         * instead of the characters in the filename.  We add on this fake param to
         * satisfy its selfish needs.  If I had more time before this had to work,
         * I would make my own non-lame screensaver.
         */
        preg_match('/.+\\/(.+)/', $content->mime_type, $matches);
        if (isset($matches[1]) && $matches[1] == 'jpeg') {
            $file_ext = 'jpg';
        } elseif (isset($matches[1])) {
            $file_ext = $matches[1];
        } else {
            $file_ext = 'unknown';
        }
        /* If mod_rewrite isn't enabled, this won't work, but it is required for some clients that care about file extensions
         * Without mod_rewrite, you can just use remove "'image_' . $content->content"
         */
        $raw_link = 'http://' . $_SERVER['SERVER_NAME'] . $script_name . 'image_' . $content->content . '?' . criteria_string($criteria) . '&select=content&select_id=' . $content->id . '&format=raw&file_ext=.' . $file_ext;
        if (strpos($content->mime_type, 'image') !== false) {
            $desc = '<![CDATA[ <img src="' . $rss_link . '" /> ]]>';
        } elseif (strpos($content->mime_type, 'html')) {
            $desc = '<![CDATA[' . $content->content . ' ]]>';
        } else {
            $desc = $content->content;
        }
        ?>
        <item>
            <title><?php 
        echo htmlspecialchars($content->name);
        ?>
</title>
            <link><?php 
        echo $link;
        ?>
</link>
            <description><?php 
        echo $desc;
        ?>
</description>
            <pubDate><?php 
        echo rssdate($content->submitted);
        ?>
</pubDate>
            <author><?php 
        echo $user->username;
        ?>
@rpi.edu (<?php 
        echo htmlspecialchars(utf8_encode($user->name));
        ?>
)</author>
            <guid isPermaLink="false"><?php 
        echo 'http://' . $_SERVER['SERVER_NAME'] . ADMIN_URL;
        ?>
/content/show/<?php 
        echo $content->id;
        ?>
</guid>
<?php 
        foreach ($feeds as $feed_obj) {
            if ($feed_obj['moderation_flag'] == 1 && $feed_obj['feed']->type != 3) {
                $feed = $feed_obj['feed'];
                $feed_link = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '?' . criteria_string($criteria) . "&select=feed&select_id={$feed->id}&format=rss";
                ?>
            <category domain="<?php 
                echo htmlspecialchars($feed_link);
                ?>
"><?php 
                echo htmlspecialchars($feed->name);
                ?>
</category>
<?php 
            }
        }
        if (strpos($content->mime_type, 'image') !== false) {
            ?>
            <enclosure url="<?php 
            echo htmlspecialchars($raw_link);
            ?>
" type="<?php 
            echo $content->mime_type;
            ?>
" length='0'/>
            <media:content url="<?php 
            echo htmlspecialchars($raw_link);
            ?>
" type="<?php 
            echo $content->mime_type;
            ?>
" expression="full" />
            <media:title type="plain"><?php 
            echo htmlspecialchars($content->name);
            ?>
</media:title>
            <media:thumbnail url="<?php 
            echo htmlspecialchars($rss_link);
            ?>
" width="100" height="100"/>
<?php 
        }
        ?>
            <dcterms:valid>
                start=<?php 
        echo w3date($content->start_time);
        ?>
;
                end=<?php 
        echo w3date($content->end_time);
        ?>
;
                scheme=W3C-DTF
            </dcterms:valid>
        </item>
<?php 
    }
    ?>
    </channel>
</rss>
<?php 
}