/**
  * @param ATOM|RSS2 $feed
  * @return ATOM|RSS2
  */
 protected function generateFeed($feed)
 {
     /* @var Post[] $posts */
     $site_name = ArrayHelper::getValue(Yii::$app->params, 'site_name', Yii::$app->name);
     $posts = Post::find()->where(['status' => Post::STATUS_PUBLISHED])->orderBy(['post_time' => SORT_DESC, 'update_time' => SORT_DESC])->limit(20)->all();
     $feed->setTitle($site_name);
     $feed->setLink(Url::home(true));
     $feed->setSelfLink(Url::to(['feed/rss'], true));
     $feed->setAtomLink(Url::to(['feed/atom'], true));
     $feed->setDescription(ArrayHelper::getValue(Yii::$app->params, 'seo_description', '最新更新的文章'));
     if ($posts) {
         $feed->setDate($posts[0]->update_time);
     } else {
         $feed->setDate(time());
     }
     foreach ($posts as $post) {
         $entry = $feed->createNewItem();
         $entry->setTitle($post->title);
         $entry->setLink($post->getUrl(true));
         $entry->setDate(intval($post->post_time));
         $entry->setDescription($post->excerpt);
         $entry->setAuthor($post->author_name ? $post->author_name : $post->author->nickname);
         $entry->setId($post->alias);
         if ($feed instanceof ATOM) {
             $entry->setContent($post->content);
         }
         $feed->addItem($entry);
     }
     return $feed;
 }
Ejemplo n.º 2
0
 public function index($token_share = '')
 {
     $query = $this->db->query('SELECT mbr.* FROM ' . $this->db->dbprefix('members') . ' AS mbr WHERE mbr.token_share = ? GROUP BY mbr.mbr_id', array($token_share));
     if ($query->num_rows() > 0) {
         //header('content-type: application/atom+xml; charset=UTF-8');
         $member = $query->row();
         $feed = new RSS2();
         if ($member->mbr_nickname) {
             $feed->setTitle($member->mbr_nickname . ' - ' . $this->config->item('title'));
         } else {
             $feed->setTitle($this->lang->line('shared_items'));
         }
         $feed->setLink(base_url() . 'share/' . $token_share);
         if ($member->mbr_description) {
             $feed->setDescription($member->mbr_description);
         }
         $feed->setDate(new DateTime());
         $where = array();
         $bindings = array();
         $where[] = 'itm.fed_id IN ( SELECT sub.fed_id FROM ' . $this->db->dbprefix('subscriptions') . ' AS sub WHERE sub.fed_id = itm.fed_id AND sub.mbr_id = ? )';
         $bindings[] = $member->mbr_id;
         $where[] = 'shr.mbr_id = ?';
         $bindings[] = $member->mbr_id;
         $sql = 'SELECT itm.*, shr.* FROM ' . $this->db->dbprefix('share') . ' AS shr LEFT JOIN ' . $this->db->dbprefix('items') . ' AS itm ON shr.itm_id = itm.itm_id WHERE ' . implode(' AND ', $where) . ' GROUP BY itm.itm_id ORDER BY shr.shr_datecreated DESC LIMIT 0,50';
         $query = $this->db->query($sql, $bindings);
         if ($query->num_rows() > 0) {
             foreach ($query->result() as $itm) {
                 $feed_item = $feed->createNewItem();
                 $feed_item->setTitle($itm->itm_title);
                 $feed_item->setLink($itm->itm_link);
                 $feed_item->setDate($itm->shr_datecreated);
                 if ($itm->itm_author) {
                     $feed_item->setAuthor($itm->itm_author);
                 }
                 $sql = 'SELECT enr.* FROM ' . $this->db->dbprefix('enclosures') . ' AS enr WHERE enr.itm_id = ? GROUP BY enr.enr_id';
                 $enclosures = $this->db->query($sql, array($itm->itm_id))->result();
                 if ($enclosures) {
                     foreach ($enclosures as $enr) {
                         if ($enr->enr_length && $enr->enr_length > 0) {
                             $feed_item->setEnclosure($enr->enr_link, $enr->enr_length, $enr->enr_type);
                         }
                     }
                 }
                 $feed_item->setDescription($itm->itm_content);
                 $feed->addItem($feed_item);
             }
         }
         $feed->printFeed();
         exit(0);
     } else {
         $this->output->set_status_header(404);
         $data = array();
         $content = $this->load->view('error404_index', $data, TRUE);
         $this->readerself_library->set_content($content);
     }
 }
Ejemplo n.º 3
0
 private function prepareFeed($title, $description)
 {
     $feed = new RSS2();
     $feed->setTitle($title);
     $feed->setLink($this->getCurrentUrl());
     $feed->setDescription($description);
     $feed->setDate(date(DATE_RSS, time()));
     $feed->setChannelElement('pubDate', date(\DATE_RSS, strtotime('today midnight')));
     return $feed;
 }
Ejemplo n.º 4
0
include 'db_conn.php';
date_default_timezone_set('Asia/Shanghai');
use FeedWriter\RSS2;
if ($_GET['id']) {
    $name = $_GET['id'];
    $sql = "SELECT * FROM list WHERE name = '{$name}'";
    mysql_query('set names utf8');
    mysql_query("set character set 'utf8'");
    $retval = mysql_query($sql);
    $row = mysql_fetch_array($retval, MYSQL_ASSOC);
    $TestFeed = new RSS2();
    $TestFeed->setTitle($row['name']);
    $TestFeed->setLink($row['link']);
    $TestFeed->setDescription($row['description']);
    $TestFeed->setChannelElement('language', 'zh-CN');
    $TestFeed->setDate(date(DATE_RSS, time()));
    $TestFeed->setChannelElement('copyright', $row['account']);
    $TestFeed->addGenerator();
    mysql_query("set character set 'utf8'");
    $sql = "SELECT * FROM `{$name}` ORDER BY lastModified DESC";
    mysql_select_db('weixincrawler');
    $retval = mysql_query($sql);
    if (!$retval) {
        die('Could not get data: ' . mysql_error());
    }
    while ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
        $newItem = $TestFeed->createNewItem();
        $newItem->setTitle($row["title"]);
        $newItem->setLink($row["url"]);
        $newItem->setDescription($row["description"]);
        $newItem->setDate($row["lastModified"]);
Ejemplo n.º 5
0
$title = $siteConfig->getOption("site_name");
$urlParams = parse_url($_GET["url"]);
if (!empty($urlParams["query"])) {
    parse_str($urlParams["query"], $aQuery);
    if (!empty($aQuery["q"])) {
        $title .= " - " . $aQuery["q"];
    }
}
$feeds = new RSS2();
$feeds->setTitle($siteConfig->getOption("site_name"));
$feeds->setLink($siteConfig->getOption("site_url"));
$feeds->setSelfLink(!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" ? "https" : "http" . "://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
$feeds->setDescription("Flux RSS de la recherche : " . $_GET["url"]);
$feeds->setChannelElement("language", "fr-FR");
// The date when this feed was lastly updated. The publication date is also set.
$feeds->setDate(date(DATE_RSS, time()));
$feeds->setChannelElement("pubDate", date(\DATE_RSS, strtotime("2013-04-06")));
$feeds->addGenerator();
if (count($ads)) {
    foreach ($ads as $ad) {
        $item = $feeds->createNewItem();
        $item->setTitle($ad->getTitle());
        $item->setLink($ad->getLink());
        $item->setDescription(require DOCUMENT_ROOT . "/app/rss/views/rss-ad.phtml");
        $item->setDate($ad->getDate());
        $item->setId(md5($ad->getId()));
        $feeds->addItem($item);
    }
}
$content = $feeds->generateFeed();
file_put_contents($cache_filename, $content);
Ejemplo n.º 6
0
 /**
  * Get RSS feed
  *
  * Converts a JSON array of event objects into an RSS feed
  * 
  * @param mixed $events Array of events to be converted
  *
  * @return string Complete markup for RSS feed
  */
 public function RSSify($events)
 {
     $feed = new RSS2();
     $this->getBuildings(null, false);
     $feed->setTitle('Upcoming Events');
     $feed->setLink('http://events.uoit.ca');
     $feed->setImage('Upcoming Events', 'http://events.uoit.ca', 'http://events.uoit.ca/img/uoit_logo.svg');
     $feed->setDescription('Upcoming events, deadlines and more at the University of Ontario Institute of Technology');
     $feed->setChannelElement('language', 'en-US');
     $feed->setDate(date(DATE_RSS, time()));
     $feed->setSelfLink(currentURL);
     $feed->setAtomLink('http://feeds.feedburner.com/uoit/events', 'hub');
     foreach ($events as $key => $event) {
         $time = date('g:i', strtotime($event['event_startdate']));
         $ampm = date('a', strtotime($event['event_startdate'])) == 'am' ? 'a.m.' : 'p.m.';
         $item = $feed->createNewItem();
         $item->setTitle($event['event_name']);
         $item->setLink('http://events.uoit.ca/event/' . $event['id']);
         $item->setId($event['id'], false);
         $item->setDescription($event['event_description']);
         $item->setDate(date("Y-m-d H:i:s"));
         $item->addElement('date', strtotime($event['event_startdate']));
         $item->addElement('time', $time . ' ' . $ampm);
         if ($event['contact_event_firstname'] && $event['contact_event_lastname'] && $event['contact_event_email']) {
             $item->setAuthor($event['contact_event_firstname'] . ' ' . $event['contact_event_lastname'], $event['contact_event_email']);
         }
         $item->addElement('location', $this->parseLocation($this->buildings, $event['location_campus'], $event['location_building'], $event['location_room'], $event['location_other']));
         $feed->addItem($item);
     }
     $output = $feed->generateFeed();
     return $output;
 }