/**
 * Universal Feed Loader
 * hooked function
 * supports custom settings
 * NOTE uses just-in-time initialization
 * @see     functions.php, feed-links include module
 * @uses    Universal Feed Writer class
 */
function tLoadFeed()
{
    global $tFeeds, $tCurrentFeed, $wp_query, $post;
    $tCurrentFeed = get_query_var('feed');
    // FB::trace($tCurrentFeed);
    if (empty($tCurrentFeed) || $tCurrentFeed == 'feed') {
        $tCurrentFeed = get_default_feed();
        # rss2
    }
    $args =& $tFeeds[$tCurrentFeed];
    $defaults = array('num_entries' => get_option('posts_per_rss'), 'do_images' => true, 'size_image' => 'large', 'feed_type' => defined('TFEED') ? TFEED : 'atom', 'feed_title' => 'Recent Posts', 'feed_description' => 'An unfiltered list limited to ' . $num_entries . ' posts');
    $args = apply_filters('t_load_feed_args', $args);
    $args = wp_parse_args($args, $defaults);
    # customizing default info
    if (is_category()) {
        $category = t_get_term_name(get_query_var('cat'), 'category');
        $args['feed_title'] = 'Feed for ' . $category;
        $args['feed_description'] = 'A list limited to ' . $args['num_entries'] . ' posts categorized under ' . $category;
    }
    if ($wp_query->is_comment_feed) {
        # comment feed
        if (is_singular()) {
            $args['feed_title'] = 'Recent comments on ' . get_the_title_rss();
        } elseif (is_search()) {
            $args['feed_title'] = 'Comments for search on ' . attribute_escape($wp_query->query_vars['s']);
        } else {
            $args['feed_title'] = 'Recent comments for ' . get_wp_title_rss();
        }
        $args['feed_title'] = ent2ncr($args['feed_title']);
        $args['feed_description'] = 'A list limited to ' . $args['num_entries'] . ' comments';
    }
    $args['query'] = tGetFeedQuery();
    if (is_array($args['query'])) {
        $args['query']['showposts'] =& $args['num_entries'];
    }
    if ($tCurrentFeed == 'rss' || $tCurrentFeed == 'rss2' || $tCurrentFeed == 'atom') {
        $args['feed_type'] = $tCurrentFeed;
    } else {
        $args['feed_title'] = ucwords(str_replace('_', ' ', $tCurrentFeed));
    }
    extract($args);
    # namespacing
    switch ($feed_type) {
        case 'rss2':
            $namespace = '
                 xmlns:dc="http://purl.org/dc/elements/1.1/"
                 xmlns:atom="http://www.w3.org/2005/Atom"
                 xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
                ';
            $feedType = RSS2;
            break;
        case 'rss':
            $namespace = '
                 xmlns:dc="http://purl.org/dc/elements/1.1/"
                 xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
                 xmlns:admin="http://webns.net/mvcb/"
                 xmlns:content="http://purl.org/rss/1.0/modules/content/"
                ';
            $feedType = RSS1;
            break;
        case 'atom':
        default:
            $namespace = '
                 xmlns:thr="http://purl.org/syndication/thread/1.0"
                 xml:lang="' . get_option('rss_language') . '"
                 xml:base="' . get_bloginfo_rss('url') . '"
                 ';
            $feedType = ATOM;
            break;
    }
    $GLOBALS['t_feed_ns'] = $namespace;
    # for use in FeedWriter
    add_filter('t_feed_ns', create_function('$default', 'return $default . $GLOBALS["t_feed_ns"];'));
    # start
    $feedWriter = new FeedWriter($feedType);
    require TDIR . TMODINC . 'feed-head.php';
    require TDIR . TMODINC . 'feed-body.php';
    # output
    $out = ob_get_contents();
    $out = str_replace(array("\n", "\r", "\t", ' '), '', $input);
    ob_end_clean();
    $feedWriter->generateFeed();
    // lifestream_rss_feed();
    // FB::info($args);
}
                 if (isset($_apc_item['ctime'])) {
                     $_apc_item['creation_time'] = $_apc_item['ctime'];
                 }
                 if (isset($_apc_item['key'])) {
                     $_apc_item['info'] = $_apc_item['key'];
                 }
                 if ($_apc_item['ttl'] > 0 && $_apc_item['ttl'] + $_apc_item['creation_time'] < time()) {
                     apc_delete($_apc_item['info']);
                 }
             }
         }
     }
 }
 if ($add_to_cache) {
     ob_start();
     $output->generateFeed();
     $output = ob_get_contents();
     ob_end_clean();
     if ($accept === 'html' && $item_count == 0) {
         // do not cache - in case of temporary server glitch at source URL
     } else {
         $cache = get_cache();
         if ($add_to_cache) {
             $cache->save($output, $cache_id);
         }
     }
     echo $output;
 } else {
     $output->generateFeed();
 }
 if ($callback) {
예제 #3
0
<?php

/**
 * Create a rss of the recorded programs.
 *
 * @license     GPL
 *
 * @package     MythWeb
 * @subpackage  TV
 *
 **/
$Feed = new FeedWriter(RSS2);
$Feed->setTitle('MythWeb - ' . t('Recorded Programs'));
$Feed->setLink(root_url);
$Feed->setDescription('MythWeb - ' . t('Recorded Programs'));
foreach ($All_Shows as $show) {
    $item = $Feed->createNewItem();
    $item->setTitle($show->title . (strlen($show->subtitle) > 0 ? ' - ' . $show->subtitle : ''));
    $item->setLink(root_url . 'tv/detail/' . $show->chanid . '/' . $show->recstartts);
    $item->setDate($show->starttime);
    $item->setDescription($show->description);
    $Feed->addItem($item);
}
$Feed->generateFeed();
예제 #4
0
파일: Vk2rss.php 프로젝트: woxcab/vk2rss
 /**
  * Generate RSS feed
  */
 public function generateRSS()
 {
     include 'FeedWriter.php';
     include 'FeedItem.php';
     $feed = new FeedWriter(RSS2);
     $wall = $this->getContent();
     $title = !empty($this->domain) ? $this->domain : $this->owner_id;
     $feed->setTitle('vk.com/' . $title);
     $feed->setLink('http://vk.com/' . $title);
     $feed->setDescription('wall from vk.com/' . $title);
     $feed->setChannelElement('language', 'ru-ru');
     $feed->setChannelElement('pubDate', date(DATE_RSS, time()));
     foreach (array_slice($wall->response, 1) as $post) {
         $newItem = $feed->createNewItem();
         $newItem->setLink("http://vk.com/wall{$post->to_id}_{$post->id}");
         $newItem->setDate($post->date);
         $description = $post->text;
         if (isset($post->copy_text)) {
             # additional content in re-posts
             $description .= (empty($description) ? '' : self::VERTICAL_DELIMITER) . $post->copy_text;
         }
         if (isset($post->attachment->photo->text) and !empty($post->attachment->photo->text)) {
             $description .= (empty($description) ? '' : self::VERTICAL_DELIMITER) . $post->attachment->photo->text;
         }
         if (isset($post->attachment->video->text) and !empty($post->attachment->video->text)) {
             $description .= (empty($description) ? '' : self::VERTICAL_DELIMITER) . $post->attachment->video->text;
         }
         if (isset($post->attachment->link)) {
             $description .= (empty($description) ? '' : self::VERTICAL_DELIMITER) . $post->attachment->link->title . '<br/>' . $post->attachment->link->description;
         }
         if (!is_null($this->include) && preg_match('/' . $this->include . '/iu', $description) !== 1) {
             continue;
         }
         if (!is_null($this->exclude) && preg_match('/' . $this->exclude . '/iu', $description) !== 0) {
             continue;
         }
         $hashTags = array();
         $description = preg_replace('/\\[[^|]+\\|([^\\]]+)\\]/u', '$1', $description);
         // remove internal vk links
         preg_match_all('/#([\\d\\w_]+)/u', $description, $hashTags);
         if (isset($post->attachments)) {
             foreach ($post->attachments as $attachment) {
                 switch ($attachment->type) {
                     case 'photo':
                         $description .= "<br><img src='{$attachment->photo->src_big}'/>";
                         break;
                         /*case 'audio': {
                             $description .= "<br><a href='http://vk.com/wall{$owner_id}_{$post->id}'>{$attachment->audio->performer} &ndash; {$attachment->audio->title}</a>";
                             break;
                           }*/
                     /*case 'audio': {
                         $description .= "<br><a href='http://vk.com/wall{$owner_id}_{$post->id}'>{$attachment->audio->performer} &ndash; {$attachment->audio->title}</a>";
                         break;
                       }*/
                     case 'doc':
                         $description .= "<br><a href='{$attachment->doc->url}'>{$attachment->doc->title}</a>";
                         break;
                     case 'link':
                         $description .= "<br><a href='{$attachment->link->url}'>{$attachment->link->title}</a>";
                         break;
                         /*case 'video': {
                             $description .= "<br><a href='http://vk.com/video{$attachment->video->owner_id}_{$attachment->video->vid}'><img src='{$attachment->video->image_big}'/></a>";
                             break;
                           }*/
                 }
             }
         }
         $newItem->setDescription($description);
         $newItem->addElement('title', $this->getTitle($description));
         $newItem->addElement('guid', $post->id);
         foreach ($hashTags[1] as $hashTag) {
             $newItem->addElement('category', $hashTag);
         }
         $feed->addItem($newItem);
     }
     $feed->generateFeed();
 }