コード例 #1
0
ファイル: FeedViewHandler.php プロジェクト: dstansby/camdram
 /**
  * @param $data array
  * @param format string, either rss or atom
  */
 protected function createFeed(View $view, Request $request)
 {
     $feed = new Feed();
     $data = $view->getData();
     $item = current($data);
     $annotationData = $this->reader->read($item);
     if ($item && ($feedData = $annotationData->getFeed())) {
         $class = get_class($item);
         $feed->setTitle($feedData->getName());
         $feed->setDescription($feedData->getDescription());
         $feed->setLink($this->urlGen->generateCollectionUrl($class));
         $feed->setFeedLink($this->urlGen->generateCollectionUrl($class, $request->getRequestFormat()), $request->getRequestFormat());
     } else {
         $feed->setTitle('Camdram feed');
         $feed->setDescription('Camdram feed');
     }
     $lastModified = null;
     $accessor = PropertyAccess::createPropertyAccessor();
     // Add one or more entries. Note that entries must be manually added once created.
     foreach ($data as $document) {
         $entry = $feed->createEntry();
         $entry->setTitle($accessor->getValue($document, $feedData->getTitleField()));
         $entry->setLink($this->urlGen->generateUrl($document));
         $entry->setDescription($this->twig->render($feedData->getTemplate(), array('entity' => $document)));
         if ($accessor->isReadable($document, $feedData->getUpdatedAtField())) {
             $entry->setDateModified($accessor->getValue($document, $feedData->getUpdatedAtField()));
         }
         $feed->addEntry($entry);
         if (!$lastModified || $entry->getDateModified() > $lastModified) {
             $lastModified = $entry->getDateModified();
         }
     }
     $feed->setDateModified($lastModified);
     return $feed->export($request->getRequestFormat());
 }
コード例 #2
0
 /**
  * @return FeedModel
  */
 public function rssAction()
 {
     $feed = new Feed();
     $feed->setTitle('Sample Blog');
     $feed->setFeedLink($this->getUrl() . '/news/rss', 'atom');
     $feed->addAuthor(array('name' => 'Sample Blog Inc.', 'email' => 'contact@' . $this->getRequest()->getUri()->getHost(), 'uri' => $this->getUrl()));
     $feed->setDescription('Description of this feed');
     $feed->setLink($this->getUrl());
     $feed->setDateModified(time());
     $news = $this->getNewsTable()->top();
     foreach ($news as $row) {
         $entry = $feed->createEntry();
         $entry->setTitle($row->title);
         $entry->setLink($this->getUrl() . '/news/read/' . $row->news_id);
         $entry->setContent($row->text);
         $entry->setDescription($row->highlight);
         $entry->setDateModified(strtotime($row->updated_at));
         $entry->setDateCreated(strtotime($row->created_at));
         $feed->addEntry($entry);
     }
     $feed->export('rss');
     $feed_model = new FeedModel();
     $feed_model->setFeed($feed);
     return $feed_model;
 }
コード例 #3
0
ファイル: News.php プロジェクト: uthando-cms/uthando-news
 public function feedAction()
 {
     /* @var \UthandoNews\Options\NewsOptions $options */
     $options = $this->getService('UthandoNewsOptions');
     /* @var \UthandoNews\Options\FeedOptions $feedOptions */
     $feedOptions = $this->getService('UthandoNewsFeedOptions');
     $newService = $this->getService();
     $newsItems = $newService->search(['sort' => $options->getSortOrder()]);
     $uri = $this->getRequest()->getUri();
     $base = sprintf('%s://%s', $uri->getScheme(), $uri->getHost());
     $feed = new Feed();
     $feed->setTitle($feedOptions->getTitle());
     $feed->setFeedLink($base . $this->url()->fromRoute('home'), 'atom');
     $feed->setDescription($feedOptions->getDescription());
     $feed->setLink($base . $this->url()->fromRoute('home'));
     $feed->setDateModified(time());
     /* @var \UthandoNews\Model\News $item */
     foreach ($newsItems as $item) {
         $entry = $feed->createEntry();
         $entry->addAuthor(['name' => $item->getArticle()->getUser()->getFullName()]);
         $entry->setTitle($item->getArticle()->getTitle());
         $entry->setLink($base . $this->url()->fromRoute('news', ['news-item' => $item->getArticle()->getSlug()]));
         $entry->setDescription($item->getArticle()->getDescription());
         $entry->setDateModified($item->getDateModified()->getTimestamp());
         $entry->setDateCreated($item->getArticle()->getDateCreated()->getTimestamp());
         $feed->addEntry($entry);
     }
     $feed->export('rss');
     $feedModel = new FeedModel();
     $feedModel->setFeed($feed);
     return $feedModel;
 }
コード例 #4
0
 public function generateXmlFeed()
 {
     $feed = new Feed();
     $feed->setTitle('xtreamwayz');
     $feed->setLink($this->generateUrl('home', [], true));
     $feed->setFeedLink($this->generateUrl('feed', [], true), 'atom');
     $feed->addAuthor(['name' => 'Geert Eltink', 'uri' => 'https://xtreamwayz.com']);
     $feed->setDateModified(time());
     $feed->setCopyright(sprintf('Copyright (c) 2005-%s Geert Eltink. All Rights Reserved.', date('Y')));
     $feed->setDescription('A web developer\'s playground, notes and thoughts.');
     $feed->setId($this->generateUrl('home', [], true));
     $posts = array_slice(array_reverse($this->postRepository->findAll()), 0, 5);
     /** @var \App\Domain\Post\Post $post */
     foreach ($posts as $post) {
         $entry = $feed->createEntry();
         $entry->setTitle($post->getTitle());
         $entry->setLink($this->generateUrl('blog.post', ['id' => $post->getId()], true));
         $entry->setId($this->generateUrl('blog.post', ['id' => $post->getId()], true));
         $entry->setDateCreated($post->getPublished());
         if ($post->getModified()) {
             $entry->setDateModified($post->getModified());
         } else {
             $entry->setDateModified($post->getPublished());
         }
         $entry->setDescription($post->getSummary());
         $entry->setContent($post->getContent());
         $entry->addAuthor(['name' => 'Geert Eltink', 'uri' => 'https://xtreamwayz.com']);
         $feed->addEntry($entry);
     }
     return $feed->export('atom');
 }
コード例 #5
0
 /**
  * RSS feed for recently added modules
  * @return FeedModel
  */
 public function feedAction()
 {
     // Prepare the feed
     $feed = new Feed();
     $feed->setTitle('ZF2 Modules');
     $feed->setDescription('Recently added modules.');
     $feed->setFeedLink('http://modules.zendframework.com/feed', 'atom');
     $feed->setLink('http://modules.zendframework.com');
     // Get the recent modules
     $page = 1;
     $mapper = $this->getServiceLocator()->get('zfmodule_mapper_module');
     $repositories = $mapper->pagination($page, self::MODULES_PER_PAGE, null, 'created_at', 'DESC');
     // Load them into the feed
     foreach ($repositories as $module) {
         $entry = $feed->createEntry();
         $entry->setTitle($module->getName());
         if ($module->getDescription() == '') {
             $moduleDescription = "No Description available";
         } else {
             $moduleDescription = $module->getDescription();
         }
         $entry->setDescription($moduleDescription);
         $entry->setLink($module->getUrl());
         $entry->setDateCreated(strtotime($module->getCreatedAt()));
         $feed->addEntry($entry);
     }
     // Render the feed
     $feedmodel = new FeedModel();
     $feedmodel->setFeed($feed);
     return $feedmodel;
 }
コード例 #6
0
 /**
  * @param ModuleEntity $module
  * @return Entry
  */
 public function addModule(ModuleEntity $module)
 {
     $moduleDescription = $module->getDescription();
     if (empty($moduleDescription)) {
         $moduleDescription = 'No description available';
     }
     $moduleName = $module->getName();
     $urlParams = ['vendor' => $module->getOwner(), 'module' => $moduleName];
     $entry = $this->feed->createEntry();
     $entry->setId($module->getIdentifier());
     $entry->setTitle($moduleName);
     $entry->setDescription($moduleDescription);
     $entry->setLink($this->urlPlugin->fromRoute('view-module', $urlParams, ['force_canonical' => true]));
     $entry->addAuthor(['name' => $module->getOwner()]);
     $entry->setDateCreated($module->getCreatedAtDateTime());
     $this->feed->addEntry($entry);
     return $entry;
 }
コード例 #7
0
ファイル: FeedGenerator.php プロジェクト: risinglf/UniversiBO
 private function newsToEntry(Feed $feed, NewsItem $item, $base, Router $router, $legacy)
 {
     $entry = $feed->createEntry();
     $entry->setTitle($item->getTitolo());
     $id = $item->getIdNotizia();
     if ($legacy) {
         $link = $base . $id;
     } else {
         $link = $router->generate('news_show', array('id' => $id), true);
     }
     $entry->setLink($link);
     $entry->addAuthor(array('name' => $item->getUsername()));
     $entry->setContent($item->getNotizia());
     $entry->setDateCreated($item->getDataIns());
     $entry->setDateModified($item->getUltimaModifica());
     $feed->addEntry($entry);
 }
コード例 #8
0
ファイル: NewsController.php プロジェクト: arbi/MyCode
 public function feedAction()
 {
     /**
      * @var NewsDao $newsDao
      */
     $newsDao = $this->getServiceLocator()->get('dao_news_news');
     $newsList = $newsDao->getNewsListForFeed();
     $feed = new Feed();
     $feed->setTitle('Ginosi\'s News');
     $feed->setLink('//www.ginosi.com');
     $feed->setFeedLink('//www.ginosi.com/news/feed', 'rss');
     $feed->setDateModified(time());
     $feed->addHub('//pubsubhubbub.appspot.com/');
     $feed->setDescription('Ginosi\'s News');
     foreach ($newsList as $row) {
         preg_match('/<p>(.*)<\\/p>/', $row->getEn(), $matches);
         if (isset($matches[1]) && !is_null($matches[1])) {
             $desc = $matches[1];
         } else {
             $contents = preg_split('/\\n/', $row->getEn());
             $desc = $contents[0];
         }
         $entry = $feed->createEntry();
         $entry->setTitle($row->getEn_title());
         $entry->setLink("//" . DomainConstants::WS_DOMAIN_NAME . "/news/" . Helper::urlForSite($row->getEn_title()));
         $entry->setDateModified(strtotime($row->getDate()));
         $entry->setDateCreated(strtotime($row->getDate()));
         $entry->setDescription($desc);
         $entry->setContent($row->getEn());
         $feed->addEntry($entry);
     }
     /**
      * Render the resulting feed to Atom 1.0 and assign to $out.
      * You can substitute "atom" with "rss" to generate an RSS 2.0 feed.
      */
     $this->getServiceLocator()->get('Application')->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function ($event) {
         $event->getResponse()->getHeaders()->addHeaderLine('Content-Type', 'text/xml; charset=UTF-8');
     }, -10000);
     $feed->export('rss');
     return (new FeedModel())->setFeed($feed);
 }
コード例 #9
0
ファイル: FeedGenerator.php プロジェクト: bcremer/mwop.net
 private function generateFeed($type, $fileBase, $baseUri, $title, $landingRoute, $feedRoute, array $routeOptions, $posts)
 {
     $routeOptions['type'] = $type;
     $landingUri = $baseUri . $this->generateUri($landingRoute, $routeOptions);
     $feedUri = $baseUri . $this->generateUri($feedRoute, $routeOptions);
     $feed = new FeedWriter();
     $feed->setTitle($title);
     $feed->setLink($landingUri);
     $feed->setFeedLink($feedUri, $type);
     if ($type === 'rss') {
         $feed->setDescription($title);
     }
     $parser = new Parser(null, new CommonMarkParser());
     $latest = false;
     $posts->setCurrentPageNumber(1);
     foreach ($posts as $details) {
         $document = $parser->parse(file_get_contents($details['path']));
         $post = $document->getYAML();
         $html = $document->getContent();
         $author = $this->getAuthor($post['author']);
         if (!$latest) {
             $latest = $post;
         }
         $entry = $feed->createEntry();
         $entry->setTitle($post['title']);
         $entry->setLink($baseUri . $this->generateUri('blog.post', ['id' => $post['id']]));
         $entry->addAuthor($author);
         $entry->setDateModified(new DateTime($post['updated']));
         $entry->setDateCreated(new DateTime($post['created']));
         $entry->setContent($this->createContent($html, $post));
         $feed->addEntry($entry);
     }
     // Set feed date
     $feed->setDateModified(new DateTime($latest['updated']));
     // Write feed to file
     $file = sprintf('%s%s.xml', $fileBase, $type);
     $file = str_replace(' ', '+', $file);
     file_put_contents($file, $feed->export($type));
 }
コード例 #10
0
ファイル: FeedController.php プロジェクト: usban/entilocali
 public function indexAction()
 {
     $moduleConfig = $this->getServiceLocator()->get('config');
     $feedClassMap = $moduleConfig['feed_class_map'];
     $appServiceLoader = $this->recoverAppServiceLoader();
     $configurations = $appServiceLoader->recoverService('configurations');
     $input = array_merge($configurations, $appServiceLoader->getProperties());
     $resourceClassName = isset($feedClassMap[$this->params()->fromRoute('resource')]) ? $feedClassMap[$this->params()->fromRoute('resource')] : null;
     if (empty($resourceClassName) or !class_exists($resourceClassName)) {
         return $this->redirect()->toRoute('home', array('lang' => 'it'));
     }
     /**
      * @var \Feed\Model\FeedBuilderAbstract $resourceClassInstance
      */
     $resourceClassInstance = new $resourceClassName();
     $resourceClassInstance->setInput($input);
     $feed = new Feed();
     $feed->setTitle($resourceClassInstance->getTitle());
     $feed->setFeedLink($resourceClassInstance->getFeedLink(), $resourceClassInstance->getFeedType());
     // $feed->addAuthor($resourceClassInstance->getAuthor());
     $feed->setDescription($resourceClassInstance->getDescription());
     $feed->setLink($resourceClassInstance->getLink());
     $feed->setDateModified(time());
     $data = $resourceClassInstance->formatRecords($resourceClassInstance->recoverRecords());
     foreach ($data as $row) {
         $entry = $feed->createEntry();
         $entry->setTitle($row['title']);
         $entry->setLink($row['link']);
         $entry->setDescription($row['content']);
         $entry->setDateModified(strtotime($row['date_created']));
         $entry->setDateCreated(strtotime($row['date_modified']));
         $feed->addEntry($entry);
     }
     $feed->export('rss');
     $feedmodel = new FeedModel();
     $feedmodel->setFeed($feed);
     return $feedmodel;
 }
コード例 #11
0
ファイル: FeedTest.php プロジェクト: pnaq57/zf2demo
 /**
  * @covers Zend\Feed\Writer\Feed::removeEntry
  */
 public function testRemoveEntry()
 {
     $writer = new Writer\Feed();
     $entry = $writer->createEntry();
     $entry->setDateCreated(1234567890);
     $entry2 = $writer->createEntry();
     $entry2->setDateCreated(1230000000);
     $entry3 = $writer->createEntry();
     $entry3->setDateCreated(1239999999);
     $writer->addEntry($entry);
     $writer->addEntry($entry2);
     $writer->addEntry($entry3);
     $writer->orderByDate();
     $this->assertEquals('1234567890', $writer->getEntry(1)->getDateCreated()->getTimestamp());
     $writer->removeEntry(1);
     $writer->orderByDate();
     $this->assertEquals('1230000000', $writer->getEntry(1)->getDateCreated()->getTimestamp());
 }
コード例 #12
0
ファイル: FeedFactory.php プロジェクト: necrogami/zf2
    /**
     * Create and attach entries to a feed
     * 
     * @param  array|Traversable $entries 
     * @param  Feed $feed 
     * @return void
     */
    protected static function createEntries($entries, Feed $feed)
    {
        if (!is_array($entries) && !$entries instanceof Traversable) {
            throw new Exception\InvalidArgumentException(sprintf(
                '%s::factory expects the "entries" value to be an array or Traversable; received "%s"',
                get_called_class(),
                (is_object($entries) ? get_class($entries) : gettype($entries))
            ));
        }

        foreach ($entries as $data) {
            if (!is_array($data) && !$data instanceof Traversable && !$data instanceof Entry) {
                throw new Exception\InvalidArgumentException(sprintf(
                    '%s expects an array, Traversable, or Zend\Feed\Writer\Entry argument; received "%s"',
                    __METHOD__,
                    (is_object($data) ? get_class($data) : gettype($data))
                ));
            }

            // Use case 1: Entry item
            if ($data instanceof Entry) {
                $feed->addEntry($data);
                continue;
            }

            // Use case 2: iterate item and populate entry
            $entry = $feed->createEntry();
            foreach ($data as $key => $value) {
                $key    = static::convertKey($key);
                $method = 'set' . $key;
                if (!method_exists($entry, $method)) {
                    continue;
                }
                $entry->$method($value);
            }
            $feed->addEntry($entry);
        }
    }
コード例 #13
0
ファイル: routes.php プロジェクト: adrenth/rssfetcher
        return Response::make('Not Found', 404);
    }
    $feed = new Feed();
    $feed->setTitle($model->getAttribute('title'))->setDescription($model->getAttribute('description'))->setBaseUrl(Url::to('/'))->setGenerator('OctoberCMS/Adrenth.RssFetcher')->setId('Adrenth.RssFecther.' . $model->getAttribute('id'))->setLink(Url::to('/feeds/' . $path))->setFeedLink(Url::to('/feeds/' . $path), $model->getAttribute('type'))->setDateModified()->addAuthor(['name' => 'OctoberCMS']);
    /** @type Collection $sources */
    $sources = $model->sources;
    $ids = Arr::pluck($sources->toArray(), 'id');
    $items = [];
    Source::with(['items' => function ($builder) use(&$items, $model) {
        $items = $builder->where('is_published', '=', 1)->whereDate('pub_date', '=', date('Y-m-d'))->orderBy('pub_date', 'desc')->limit($model->getAttribute('max_items'))->get();
    }])->whereIn('id', $ids)->where('is_enabled', '=', 1)->get();
    /** @type Item $item */
    foreach ($items as $item) {
        try {
            $entry = new Entry();
            $entry->setId((string) $item->getAttribute('id'))->setTitle($item->getAttribute('title'))->setDescription($item->getAttribute('description'))->setLink($item->getAttribute('link'))->setDateModified($item->getAttribute('pub_date'));
            $comments = $item->getAttribute('comments');
            if (!empty($comments)) {
                $entry->setCommentLink($comments);
            }
            $category = $item->getAttribute('category');
            if (!empty($category)) {
                $entry->addCategory(['term' => $category]);
            }
            $feed->addEntry($entry);
        } catch (InvalidArgumentException $e) {
            continue;
        }
    }
    return Response::make($feed->export($model->getAttribute('type')), 200, ['Content-Type' => sprintf('application/%s+xml', $model->getAttribute('type'))]);
});
コード例 #14
0
ファイル: Recent.php プロジェクト: logue/pukiwiki_adv
 /**
  * Atom/rssを出力
  * string $page ページ名(ページ名が入っている場合はキャッシュは無効)
  * string $type rssかatomか。
  * boolean $force キャッシュ生成しない
  * return void
  */
 public static function getFeed($page = '', $type = 'rss', $force = false)
 {
     global $vars, $site_name, $site_logo, $modifier, $modifierlink, $_string, $cache;
     static $feed;
     // rss, atom以外はエラー
     if (!($type === 'rss' || $type === 'atom')) {
         throw new Exception('Recent::getFeed(): Unknown feed type.');
     }
     $content_type = $type === 'rss' ? 'application/rss+xml' : 'application/atom+xml';
     $body = '';
     if (empty($page)) {
         // recentキャッシュの更新チェック
         if ($cache['wiki']->getMetadata(self::RECENT_CACHE_NAME)['mtime'] > $cache['wiki']->getMetadata(self::FEED_CACHE_NAME)['mtime']) {
             $force = true;
         }
         if ($force) {
             // キャッシュ再生成
             unset($feed);
             $cache['wiki']->removeItem(self::FEED_CACHE_NAME);
         } else {
             if (!empty($feed)) {
                 // メモリにキャッシュがある場合
             } else {
                 if ($cache['wiki']->hasItem(self::FEED_CACHE_NAME)) {
                     // キャッシュから最終更新を読み込む
                     $feed = $cache['wiki']->getItem(self::FEED_CACHE_NAME);
                 }
             }
         }
     }
     if (empty($feed)) {
         // Feedを作る
         $feed = new Feed();
         // Wiki名
         $feed->setTitle($site_name);
         // Wikiのアドレス
         $feed->setLink(Router::get_script_absuri());
         // サイトのロゴ
         //$feed->setImage(array(
         //	'title'=>$site_name,
         //	'uri'=>$site_logo,
         //	'link'=>Router::get_script_absuri()
         //));
         // Feedの解説
         $feed->setDescription(sprintf($_string['feed_description'], $site_name));
         // Feedの発行者など
         $feed->addAuthor(array('name' => $modifier, 'uri' => $modifierlink));
         // feedの更新日時(生成された時間なので、この実装で問題ない)
         $feed->setDateModified(time());
         $feed->setDateCreated(time());
         // Feedの生成
         $feed->setGenerator(S_APPNAME, S_VERSION, 'http://pukiwiki.logue.be/');
         if (empty($page)) {
             // feedのアドレス
             // ※Zend\Feedの仕様上、&が自動的に&amp;に変更されてしまう
             $feed->setFeedLink(Router::get_cmd_uri('feed') . '&type=atom', 'atom');
             $feed->setFeedLink(Router::get_cmd_uri('feed'), 'rss');
             // PubSubHubbubの送信
             foreach (Ping::$pubsubhubbub_server as $uri) {
                 $feed->addHub($uri);
             }
         } else {
             $r_page = rawurlencode($page);
             $feed->setFeedLink(Router::get_cmd_uri('feed') . '&type=atom&refer=' . $r_page, 'atom');
             $feed->setFeedLink(Router::get_cmd_uri('feed') . '&refer=' . $r_page, 'rss');
         }
         $i = 0;
         // エントリを取得
         foreach (self::get() as $_page => $time) {
             // ページ名が指定されていた場合、そのページより下位の更新履歴のみ出力
             if (!empty($page) && strpos($_page, $page . '/') === false) {
                 continue;
             }
             $wiki = Factory::Wiki($_page);
             if ($wiki->isHidden()) {
                 continue;
             }
             $entry = $feed->createEntry();
             // ページのタイトル
             $entry->setTitle($wiki->title());
             // ページのアドレス
             $entry->setLink($wiki->uri());
             // ページの更新日時
             $entry->setDateModified($wiki->time());
             // ページの要約
             $entry->setDescription($wiki->description(self::FEED_ENTRY_DESCRIPTION_LENGTH));
             // 項目を追加
             $feed->addEntry($entry);
             $i++;
             if ($i >= self::RECENT_MAX_SHOW_PAGES) {
                 break;
             }
         }
         if (empty($page)) {
             // キャッシュに保存
             $cache['wiki']->setItem(self::FEED_CACHE_NAME, $feed);
         }
     }
     flush();
     $headers = Header::getHeaders($content_type);
     Header::writeResponse($headers, 200, $feed->export($type));
     //header('Content-Type: ' . $content_type);
     //echo $body;
     exit;
 }
コード例 #15
0
 /**
  * Builds the desired feed
  *
  * @param string $title
  * @param string $description
  * @param array  $items
  *
  * @return \Zend\Feed\Writer\Feed
  */
 protected function buildFeed(Request $req, $title, $description, $url, $items)
 {
     $feed = new Feed();
     $feed->setTitle($title);
     $feed->setDescription($description);
     $feed->setLink($url);
     $feed->setGenerator('Packagist');
     foreach ($items as $item) {
         $entry = $feed->createEntry();
         $this->populateEntry($entry, $item);
         $feed->addEntry($entry);
     }
     if ($req->getRequestFormat() == 'atom') {
         $feed->setFeedLink($req->getUri(), $req->getRequestFormat());
     }
     if ($feed->count()) {
         $feed->setDateModified($feed->getEntry(0)->getDateModified());
     } else {
         $feed->setDateModified(new \DateTime());
     }
     return $feed;
 }
コード例 #16
0
 /**
  * RSS feed
  *
  * @param Request $request
  *
  * @return Response
  *
  * @Route("/blog/rss", name="blog_rss")
  */
 public function rssAction(Request $request)
 {
     $feed = new Feed();
     $config = $this->container->getParameter('stfalcon_blog.config');
     $feed->setTitle($config['rss']['title']);
     $feed->setDescription($config['rss']['description']);
     $feed->setLink($this->generateUrl('blog_rss', array(), true));
     $posts = $this->get('doctrine')->getManager()->getRepository("StfalconBlogBundle:Post")->getAllPublishedPosts($request->getLocale());
     /** @var Post $post */
     foreach ($posts as $post) {
         $entry = new Entry();
         $entry->setTitle($post->getTitle());
         $entry->setLink($this->generateUrl('blog_post_view', array('slug' => $post->getSlug()), true));
         $feed->addEntry($entry);
     }
     $response = new Response($feed->export('rss'));
     $response->headers->add(array('Content-Type' => 'application/xml'));
     return $response;
 }
コード例 #17
0
 /**
  * Adds an entry to a feed data object.
  *
  * @param \Zend\Feed\Writer\Feed $feed
  * @return \Zend\Feed\Writer\Entry
  */
 protected function addFeedEntry(Feed $feed)
 {
     $entry = $feed->createEntry();
     $id = ++$this->id;
     $datetime = new \DateTime('2014-07-09T20:53:59+0000');
     $time = $datetime->format('U');
     $entry->setId((string) $id);
     $entry->setTitle('Title ' . $id);
     $entry->setDescription('Description ' . $id);
     $entry->setDateModified($time + $id);
     $entry->addAuthor(array('name' => 'Name ' . $id, 'email' => $id . '@example.com', 'uri' => 'http://localhost/feed.xml?author=' . $id));
     $entry->setLink('http://localhost/feed.xml?id=' . $id);
     $entry->setContent('Content ' . $id);
     $feed->addEntry($entry);
     return $entry;
 }
コード例 #18
0
ファイル: FeedTest.php プロジェクト: narixx/zf2
 public function testAddsAndOrdersEntriesByDateIfRequested()
 {
     $writer = new Writer\Feed();
     $entry = $writer->createEntry();
     $entry->setDateCreated(1234567890);
     $entry2 = $writer->createEntry();
     $entry2->setDateCreated(1230000000);
     $writer->addEntry($entry);
     $writer->addEntry($entry2);
     $writer->orderByDate();
     $this->assertEquals(1230000000, $writer->getEntry(1)->getDateCreated()->get(Date\Date::TIMESTAMP));
 }
コード例 #19
0
ファイル: GroupController.php プロジェクト: bix0r/Stjornvisi
 /**
  * RSS feed for all news
  *
  * Get all news from two months back in time
  *
  * @return array|FeedModel
  */
 public function rssNewsAction()
 {
     $sm = $this->getServiceLocator();
     $groupService = $sm->get('Stjornvisi\\Service\\Group');
     //ITEM FOUND
     //  item is in storage
     if (($group = $groupService->get($this->params()->fromRoute('name', 0))) != null) {
         $sm = $this->getServiceLocator();
         $newsService = $sm->get('Stjornvisi\\Service\\News');
         $from = new DateTime();
         $from->sub(new DateInterval('P2M'));
         $to = new DateTime();
         $to->add(new DateInterval('P2M'));
         $feed = new Feed();
         $feed->setTitle('Feed Example');
         $feed->setFeedLink('http://ourdomain.com/rss', 'atom');
         $feed->addAuthor(['name' => 'Stjórnvísi', 'email' => '*****@*****.**', 'uri' => 'http://stjornvisi.is']);
         $feed->setDescription('Fréttir');
         $feed->setLink('http://ourdomain.com');
         $feed->setDateModified(new DateTime());
         $data = [];
         foreach ($newsService->getRangeByGroup($group->id, $from, $to) as $row) {
             //create entry...
             $entry = $feed->createEntry();
             $entry->setTitle($row->title);
             $entry->setLink('http://stjornvisi.is/');
             $entry->setDescription($row->body . '.');
             $entry->setDateModified($row->created_date);
             $entry->setDateCreated($row->created_date);
             $feed->addEntry($entry);
         }
         $feed->export('rss');
         $feedmodel = new FeedModel();
         $feedmodel->setFeed($feed);
         return $feedmodel;
         //ITEM NOT FOUND
         //
     } else {
         return $this->notFoundAction();
     }
 }
コード例 #20
0
ファイル: ResultFeed.php プロジェクト: tillk/vufind
 /**
  * Support method to turn a record driver object into an RSS entry.
  *
  * @param Feed                              $feed   Feed to update
  * @param \VuFind\RecordDriver\AbstractBase $record Record to add to feed
  *
  * @return void
  */
 protected function addEntry($feed, $record)
 {
     $entry = $feed->createEntry();
     $title = $record->tryMethod('getTitle');
     $entry->setTitle(empty($title) ? $record->getBreadcrumb() : $title);
     $serverUrl = $this->getView()->plugin('serverurl');
     $recordLink = $this->getView()->plugin('recordlink');
     try {
         $url = $serverUrl($recordLink->getUrl($record));
     } catch (\Zend\Mvc\Router\Exception\RuntimeException $e) {
         // No route defined? See if we can get a URL out of the driver.
         // Useful for web results, among other things.
         $url = $record->tryMethod('getUrl');
         if (empty($url) || !is_string($url)) {
             throw new \Exception('Cannot find URL for record.');
         }
     }
     $entry->setLink($url);
     $date = $this->getDateModified($record);
     if (!empty($date)) {
         $entry->setDateModified($date);
     }
     $author = $record->tryMethod('getPrimaryAuthor');
     if (!empty($author)) {
         $entry->addAuthor(['name' => $author]);
     }
     $formats = $record->tryMethod('getFormats');
     if (is_array($formats)) {
         foreach ($formats as $format) {
             $entry->addDCFormat($format);
         }
     }
     $date = $record->tryMethod('getPublicationDates');
     if (isset($date[0]) && !empty($date[0])) {
         $entry->setDCDate($date[0]);
     }
     $feed->addEntry($entry);
 }
コード例 #21
0
ファイル: ResultFeed.php プロジェクト: no-reply/cbpl-vufind
 /**
  * Support method to turn a record driver object into an RSS entry.
  *
  * @param Feed                              $feed   Feed to update
  * @param \VuFind\RecordDriver\AbstractBase $record Record to add to feed
  *
  * @return void
  */
 protected function addEntry($feed, $record)
 {
     $entry = $feed->createEntry();
     $title = $record->tryMethod('getTitle');
     $entry->setTitle(empty($title) ? $record->getBreadcrumb() : $title);
     $serverUrl = $this->getView()->plugin('serverurl');
     $recordLink = $this->getView()->plugin('recordlink');
     $entry->setLink($serverUrl($recordLink->getUrl($record)));
     $date = $this->getDateModified($record);
     if (!empty($date)) {
         $entry->setDateModified($date);
     }
     $author = $record->tryMethod('getPrimaryAuthor');
     if (!empty($author)) {
         $entry->addAuthor(array('name' => $author));
     }
     $formats = $record->tryMethod('getFormats');
     if (is_array($formats)) {
         foreach ($formats as $format) {
             $entry->addDCFormat($format);
         }
     }
     $date = $record->tryMethod('getPublicationDates');
     if (isset($date[0]) && !empty($date[0])) {
         $entry->setDCDate($date[0]);
     }
     $feed->addEntry($entry);
 }
コード例 #22
0
 public function rssAction()
 {
     $feed = new Feed();
     $type = $this->params('type');
     $age = (int) $this->params('age');
     $maxAge = new DateTime($age . ' days ago');
     $entities = $this->getEntityManager()->findEntitiesByTypeName($type);
     $chain = new FilterChain();
     $chain->attach(new EntityAgeCollectionFilter($maxAge));
     $chain->attach(new NotTrashedCollectionFilter());
     $entities = $chain->filter($entities);
     $data = $this->normalize($entities);
     foreach ($data as $item) {
         try {
             $entry = $feed->createEntry();
             $entry->setTitle($item['title']);
             $entry->setDescription($item['description']);
             $entry->setId($item['guid']);
             $entry->setLink($item['link']);
             foreach ($item['categories'] as $keyword) {
                 $entry->addCategory(['term' => $keyword]);
             }
             $entry->setDateModified($item['lastModified']);
             $feed->addEntry($entry);
         } catch (\Exception $e) {
             // Invalid Item, do not add
         }
     }
     $feed->setTitle($this->brand()->getHeadTitle());
     $feed->setDescription($this->brand()->getDescription());
     $feed->setDateModified(time());
     $feed->setLink($this->url()->fromRoute('home', [], ['force_canonical' => true]));
     $feed->setFeedLink($this->url()->fromRoute('entity/api/rss', ['type' => $type, 'age' => $age], ['force_canonical' => true]), 'atom');
     $feed->export('atom');
     $feedModel = new FeedModel();
     $feedModel->setFeed($feed);
     return $feedModel;
 }
コード例 #23
0
 /**
  * Handle rss page
  */
 public function rssAction()
 {
     // set page and max blog per page
     $page = 1;
     $maxPage = 10;
     // get blog entries
     $blogList = $this->getBlogService()->fetchList($page, $maxPage);
     // create feed
     $feed = new Feed();
     $feed->setTitle('Luigis Pizza-Blog');
     $feed->setFeedLink('http://luigis-pizza.local/blog/rss', 'atom');
     $feed->addAuthor(array('name' => 'Luigi Bartoli', 'email' => '*****@*****.**', 'uri' => 'http://luigis-pizza.local'));
     $feed->setDescription('Luigis Pizza-Blog Beiträge');
     $feed->setLink('http://luigis-pizza.local');
     $feed->setDateModified(time());
     // add blog entries
     foreach ($blogList as $blog) {
         $entry = $feed->createEntry();
         $entry->setTitle($blog->getTitle());
         $entry->setLink('http://luigis-pizza.local/blog/' . $blog->getUrl());
         $entry->setDescription($blog->getContent());
         $entry->setDateCreated(strtotime($blog->getCdate()));
         $feed->addEntry($entry);
     }
     // create feed model
     $feedmodel = new FeedModel();
     $feedmodel->setFeed($feed);
     return $feedmodel;
 }
コード例 #24
0
ファイル: PostService.php プロジェクト: rkeplin/zf2-d2-blog
 /**
  * Gets RSS feed of published posts
  *
  * @param void
  * @return Zend\Feed\Writer\Feed
  **/
 public function getRssFeed()
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('p')->from(self::ENTITY_POST, 'p')->where('p.isPublished = :published')->orderBy('p.dateAdded', 'DESC')->setMaxResults(10)->setParameters(array('published' => 1));
     $query = $qb->getQuery();
     $result = $query->getResult();
     $feed = new Feed();
     $feed->setTitle("Rob's Blog");
     $feed->setFeedLink('http://' . $_SERVER['SERVER_NAME'] . '/blog/rss', 'atom');
     $feed->addAuthor(array('name' => 'Rob', 'email' => '*****@*****.**', 'uri' => 'http://' . $_SERVER['SERVER_NAME']));
     $feed->setDescription("A PHP developer's blog");
     $feed->setLink('http://' . $_SERVER['SERVER_NAME']);
     $feed->setDateModified($result[0]->getDateAdded());
     foreach ($result as $post) {
         $entry = $feed->createEntry();
         $entry->setTitle($post->getTitle());
         $entry->setLink(sprintf('http://' . $_SERVER['SERVER_NAME'] . '/blog/view?title=%s', strtolower(urlencode($post->getTitle()))));
         $entry->setDescription(substr(strip_tags($post->getContent()), 0, 150) . '...');
         $entry->setDateModified($post->getDateAdded());
         $entry->setDateCreated($post->getDateAdded());
         $feed->addEntry($entry);
     }
     $feed->export('rss');
     return $feed;
 }