/**
  * @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;
 }
예제 #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);
     }
 }
예제 #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;
 }
예제 #4
0
 /**
  * Handles the RSS action. Constructs the rss feed of the latest posts. The
  * number of posts to return is stored in the configuration section
  *
  * @return Response
  */
 public function rssAction()
 {
     $feed = new RSS2();
     $feed->setEncoding('UTF-8');
     $feed->setTitle($this->config->rss->title);
     $feed->setDescription($this->config->rss->description);
     $feed->setLink($this->getFullUrl());
     $posts = $this->finder->getLatest(1);
     foreach ($posts as $post) {
         $feedItem = new Item();
         $feedItem->setTitle($post->getTitle());
         $feedItem->setLink($this->getFullUrl('/post/' . $post->getSlug()));
         $feedItem->setDescription($post->getContent());
         $feedItem->setDate($post->getDate());
         $feed->addItem($feedItem);
     }
     $response = new Response();
     $response->setHeader('Content-Type', 'application/xml');
     $response->setContent($feed->generateFeed());
     return $response;
 }
예제 #5
0
include 'Feed.php';
include 'RSS2.php';
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"]);
예제 #6
0
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
// Creating an instance of RSS2 class.
$TestFeed = new RSS2();
// Setting some basic channel elements. These three elements are mandatory.
$TestFeed->setTitle('Testing & Checking the Feed Writer project');
$TestFeed->setLink('https://github.com/mibe/FeedWriter');
$TestFeed->setDescription('This is just an example how to use the Feed Writer project in your code.');
// Image title and link must match with the 'title' and 'link' channel elements for RSS 2.0,
// which were set above.
$TestFeed->setImage('Testing & Checking the Feed Writer project', 'https://github.com/mibe/FeedWriter', 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Rss-feed.svg/256px-Rss-feed.svg.png');
// Use core setChannelElement() function for other optional channel elements.
// See http://www.rssboard.org/rss-specification#optionalChannelElements
// for other optional channel elements. Here the language code for American English and
$TestFeed->setChannelElement('language', 'en-US');
// The date when this feed was lastly updated. The publication date is also set.
$TestFeed->setDate(date(DATE_RSS, time()));
$TestFeed->setChannelElement('pubDate', date(\DATE_RSS, strtotime('2013-04-06')));
// You can add additional link elements, e.g. to a PubSubHubbub server with custom relations.
// It's recommended to provide a backlink to the feed URL.
$TestFeed->setSelfLink('http://example.com/myfeed');
$TestFeed->setAtomLink('http://pubsubhubbub.appspot.com', 'hub');
// You can add more XML namespaces for more custom channel elements which are not defined
예제 #7
0
$filter = new \AdService\Filter($params);
$siteConfig = \AdService\SiteConfigFactory::factory($_GET["url"]);
$ads = $parser->process($content, $filter, parse_url($_GET["url"], PHP_URL_SCHEME));
$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);
    }
예제 #8
0
$c = new Cache("rss");
$c->eraseExpired();
$emission = $_GET["q"];
if (!isset($emission)) {
    $emission = "";
}
$sans100 = isset($_GET["sans-100"]);
header("Content-Type: application/rss+xml");
$feedkey = $sans100 ? "sans100" : ($emission == "" ? "all" : $emission);
if ($c->isCached($feedkey)) {
    echo $c->retrieve($feedkey);
    return;
}
$TestFeed = new RSS2();
if ($emission != "") {
    $TestFeed->setDescription('Tous les podcasts de l\'émission ' . $emission . ' diffusés sur Radio Campus Clermont-Ferrand');
    $url = 'http://www.campus-clermont.net/onair/podcast/player/?search=' . urlencode($emission);
    $title = 'Podcasts de l\'émission ' . $emission . ' sur Radio Campus Clermont-Ferrand';
    $jsonObject = json_decode(file_get_contents("http://" . $_SERVER['HTTP_HOST'] . "/ws/?req=image&t=" . urlencode($emission)));
    $image = 'http://' . $_SERVER["HTTP_HOST"] . $jsonObject[0]->uri;
} else {
    $TestFeed->setDescription('Tous les podcasts de Radio Campus Clermont-Ferrand');
    $url = 'http://www.campus-clermont.net/onair/podcast/player/';
    $title = 'Le podcast de Radio Campus';
    $image = "http://www.campus-clermont.net/onair/podcast/player/images/logo.png";
}
$TestFeed->setTitle($title);
$TestFeed->setLink($url);
$TestFeed->setImage($title, $url, $image);
if ($emission != "") {
    $jsonObject = json_decode(file_get_contents("http://" . $_SERVER['HTTP_HOST'] . "/onair/podcast/player/ws/search.php?q=" . urlencode($emission)));
예제 #9
0
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//Creating an instance of RSS2 class.
$TestFeed = new RSS2();
//Setting the channel elements
//Use wrapper functions for common channel elements
$TestFeed->setTitle('Testing & Checking the RSS writer class');
$TestFeed->setLink('http://www.ajaxray.com/projects/rss');
$TestFeed->setDescription('This is a test of creating a RSS 2.0 feed Universal Feed Writer');
//Image title and link must match with the 'title' and 'link' channel elements for valid RSS 2.0
$TestFeed->setImage('Testing & Checking the RSS writer class', 'http://www.ajaxray.com/projects/rss', 'http://www.rightbrainsolution.com/_resources/img/logo.png');
//Let's add some feed items: Create two empty Item instances
$itemOne = $TestFeed->createNewItem();
$itemTwo = $TestFeed->createNewItem();
//Add item details
$itemOne->setTitle('The title of the first entry.');
$itemOne->setLink('http://www.google.de');
$itemOne->setDate(time());
$itemOne->setDescription('And here\'s the description of the entry.');
$itemTwo->setTitle('Lorem ipsum');
$itemTwo->setLink('http://www.example.com');
$itemTwo->setDate(1234567890);
$itemTwo->setDescription('Lorem ipsum dolor sit amet, consectetur, adipisci velit');
//Now add the feed item
예제 #10
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;
 }