示例#1
0
/**
 * Render a sepecific feed instance
 *
 * @param Feed $feed
 * @param Smarty $smarty
 * @return null
 */
function render_rss_feed($feed, $header = true)
{
    if ($header) {
        header('Content-Type: text/xml; charset=utf-8');
    }
    // if
    $result = "<rss version=\"2.0\">\n<channel>\n";
    $result .= '<title>' . clean($feed->getTitle()) . "</title>\n";
    $result .= '<link>' . clean($feed->getLink()) . "</link>\n";
    if ($description = trim($feed->getDescription())) {
        $result .= '<description><![CDATA[' . clean($description) . "]]></description>\n";
    }
    // if
    if ($language = trim($feed->getLanguage())) {
        $result .= '<language>' . clean($language) . "</language>\n";
    }
    // if
    foreach ($feed->getItems() as $item) {
        $result .= "<item>\n";
        $result .= '<title>' . clean($item->getTitle()) . "</title>\n";
        $result .= '<link>' . clean($item->getLink()) . "</link>\n";
        if ($description = trim($item->getDescription())) {
            $result .= '<description><![CDATA[' . $description . "]]></description>\n";
        }
        // if
        $author = $item->getAuthor();
        if (instance_of($author, 'FeedAuthor')) {
            $result .= '<author>' . clean($author->getEmail()) . ' (' . clean($author->getName()) . ")</author>\n";
        }
        // if
        $pubdate = $item->getPublicationDate();
        if (instance_of($pubdate, 'DateValue')) {
            $result .= '<pubDate>' . $pubdate->toRSS() . "</pubDate>\n";
        }
        // if
        $id = $item->getId();
        if ($id) {
            $result .= '<guid>' . clean($id) . "</guid>\n";
        }
        // if
        $result .= "</item>\n";
    }
    // foreach
    $result .= "</channel>\n</rss>";
    return $result;
}
示例#2
0
    /*i*/
}
/*i*/
define('INSIGHT_IPS', '*');
/*i*/
define('INSIGHT_AUTHKEYS', '*');
/*i*/
define('INSIGHT_PATHS', dirname(__FILE__));
/*i*/
define('INSIGHT_SERVER_PATH', './index.php');
/*i*/
require_once 'FirePHP/Init.php';
/*i*/
FirePHP::plugin('firephp')->trapProblems();
/*i*/
FirePHP::plugin('firephp')->recordEnvironment(FirePHP::to('request')->console('Environment')->on('Show Environment'));
/*i*/
FirePHP::to('request')->console('Feed')->info('Startup');
// Application Code
require_once dirname(__FILE__) . '/feed.php';
$feed = new Feed('http://www.phpdeveloper.org/feed');
$items = $feed->getItems();
echo '<p><b>See:</b> <a target="_blank" href="http://www.christophdorn.com/Blog/2010/08/24/gain-insight-into-your-cache-interaction-with-firephp-companion/">http://www.christophdorn.com/Blog/2010/08/24/gain-insight-into-your-cache-interaction-with-firephp-companion/</a></p>' . "\n";
if ($feed->didLoad()) {
    echo '<p><b>Loading feed from: ' . $feed->getUrl() . '</b></p>' . "\n";
}
foreach ($items as $item) {
    echo '<p><a href="' . $item['link'] . '">' . $item['title'] . '</a></p>' . "\n";
}
/*i*/
FirePHP::to('request')->console('Feed')->info('Shutdown');
示例#3
0
<div class="container">
  <?php 
$top = false;
$middle = false;
if (isset($_GET['page'])) {
    switch ($_GET['page']) {
        case "news":
            // Nieuwe feed
            $feed = new Feed("https://news.google.com/news?cf=all&hl=nl_nl&pz=1&ned=" . $feed . "&topic=h&output=rss");
            // Feed channel laten zien
            $channel = $feed->getChannel();
            $page = "<h2><a href='" . $channel->link . "' target='_blank'>" . $channel->title . "</a></h2>";
            $page .= "<br />";
            // Feed items laten zien
            foreach ($feed->getItems() as $val) {
                $page .= "<p>";
                $page .= $val->title;
                $page .= "<br />";
                $page .= $val->description;
                $page .= "</p>";
            }
            break;
        case "educations":
            $page = educationsPage();
            break;
        case "contact":
            $page = contactPage();
            break;
        default:
            $top = true;
示例#4
0
    public function save(Feed $feed, $folderid)
    {
        $title = $feed->getTitle();
        $url = $feed->getUrl();
        $url_hash = md5($url);
        if (empty($title)) {
            $l = \OC_L10N::get('news');
            $title = $l->t('no title');
        }
        $favicon = $feed->getFavicon();
        //FIXME: Detect when feed contains already a database id
        $feedid = $this->findIdFromUrl($url);
        if ($feedid === null) {
            $query = \OCP\DB::prepare("\n\t\t\t\tINSERT INTO " . self::tableName . "(url, url_hash, title, favicon_link, folder_id, user_id, added, lastmodified)\n\t\t\t\tVALUES (?, ?, ?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())\n\t\t\t\t");
            $params = array($url, $url_hash, $title, $favicon, $folderid, $this->userid);
            $query->execute($params);
            $feedid = \OCP\DB::insertid(self::tableName);
        } else {
            //update the db. it needs to be done, since it might be the first save after a full fetch
            $stmt = \OCP\DB::prepare('
					UPDATE ' . self::tableName . ' SET favicon_link = ? , lastmodified = UNIX_TIMESTAMP() , folder_id = ?
					WHERE id = ?
					');
            $params = array($favicon, $folderid, $feedid);
            $stmt->execute($params);
        }
        $feed->setId($feedid);
        $itemMapper = new ItemMapper();
        $items = $feed->getItems();
        if ($items !== null) {
            foreach ($items as $item) {
                $itemMapper->save($item, $feedid);
            }
        }
        return $feedid;
    }