示例#1
0
 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;
 }
示例#2
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;
 }
示例#3
0
 /**
  * @return \Illuminate\Http\Response|mixed
  */
 public function render()
 {
     try {
         $feed = $this->feed->export($this->format);
         return \Response::make($feed, 200, $this->header[$this->format]);
     } catch (\Zend\Feed\Writer\Exception\InvalidArgumentException $w) {
         return \Response::make([], 404);
     }
 }
 /**
  * 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;
 }
示例#5
0
 /**
  * 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);
     }
 }
示例#6
0
 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);
 }
 /**
  * @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;
 }
示例#8
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;
 }
示例#9
0
 private function generateFeed(string $type, string $fileBase, string $baseUri, string $title, string $landingRoute, string $feedRoute, array $routeOptions, Traversable $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->setLink($baseUri . sprintf('/blog/%s.html', $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
 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
 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;
 }
 /**
  * RSS feed for recently added modules
  * @return FeedModel
  */
 public function feedAction()
 {
     $url = $this->plugin('url');
     // Prepare the feed
     $feed = new Feed();
     $feed->setTitle('ZF2 Modules');
     $feed->setDescription('Recently added ZF2 modules');
     $feed->setFeedLink($url->fromRoute('feed', [], ['force_canonical' => true]), 'atom');
     $feed->setLink($url->fromRoute('home', [], ['force_canonical' => true]));
     // Get the recent modules
     $page = 1;
     $modules = $this->moduleMapper->pagination($page, self::MODULES_PER_PAGE, null, 'created_at', 'DESC');
     // Load them into the feed
     $mapper = new Mapper\ModuleToFeed($feed, $url);
     $mapper->addModules($modules);
     // Render the feed
     $feedmodel = new FeedModel();
     $feedmodel->setFeed($feed);
     return $feedmodel;
 }
示例#13
0
 public function feedAction()
 {
     $blogDao = $this->getServiceLocator()->get('dao_blog_blog');
     $blogList = $blogDao->getBlogListForFeed();
     $feed = new Feed();
     $feed->setTitle('Ginosi\'s Blog');
     $feed->setLink('//www.ginosi.com');
     $feed->setFeedLink('//www.ginosi.com/blog/feed', 'rss');
     $feed->setDateModified(time());
     $feed->addHub('//pubsubhubbub.appspot.com/');
     $feed->setDescription('Ginosi\'s Blog');
     foreach ($blogList as $row) {
         preg_match('/<p>(.*)<\\/p>/', $row->getContent(), $matches);
         if (isset($matches[1]) && !is_null($matches[1])) {
             $desc = $matches[1];
         } else {
             $contents = preg_split('/\\n/', $row->getContent());
             $desc = $contents[0];
         }
         $entry = $feed->createEntry();
         $entry->setTitle($row->getTitle());
         $entry->setLink("//" . DomainConstants::WS_DOMAIN_NAME . "/blog/" . Helper::urlForSite($row->getTitle()));
         $entry->setDateModified(strtotime($row->getDate()));
         $entry->setDateCreated(strtotime($row->getDate()));
         $entry->setDescription($desc);
         $entry->setContent($row->getContent());
         $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.
      */
     $feed->export('rss');
     $feedmodel = new FeedModel();
     $feedmodel->setFeed($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);
     return $feedmodel;
 }
示例#14
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));
 }
 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');
 }
示例#16
0
 /**
  * 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);
 }
示例#17
0
 public function testFluentInterface()
 {
     $writer = new Writer\Feed();
     $return = $writer->addAuthor(array('name' => 'foo'))->addAuthors(array(array('name' => 'foo')))->setCopyright('copyright')->addCategories(array(array('term' => 'foo')))->addCategory(array('term' => 'foo'))->addHub('foo')->addHubs(array('foo'))->setBaseUrl('http://www.example.com')->setDateCreated(null)->setDateModified(null)->setDescription('description')->setEncoding('utf-8')->setId('1')->setImage(array('uri' => 'http://www.example.com'))->setLanguage('fr')->setLastBuildDate(null)->setLink('foo')->setTitle('foo')->setType('foo');
     $this->assertSame($return, $writer);
 }
示例#18
0
use Adrenth\RssFetcher\Models\Feed as FeedModel;
use Adrenth\RssFetcher\Models\Item;
use Adrenth\RssFetcher\Models\Source;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Response;
use Zend\Feed\Exception\InvalidArgumentException;
use Zend\Feed\Writer\Entry;
use Zend\Feed\Writer\Feed;
Route::get('/feeds/{path}', function ($path) {
    /** @type FeedModel $model */
    $model = FeedModel::where('path', '=', $path)->first();
    if ($model === null) {
        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)) {
示例#19
0
 /**
  * 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;
 }
示例#20
0
 /**
  * Creates a HTTP Response and exports feed
  *
  * @param \Zend\Feed\Writer\Feed $feed
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function buildResponse(Request $req, Feed $feed)
 {
     $content = $feed->export($req->getRequestFormat());
     $response = new Response($content, 200);
     $response->setSharedMaxAge(3600);
     return $response;
 }
示例#21
0
 /**
  * @covers Zend\Feed\Writer\Feed::export
  */
 public function testExportWrongTypeException()
 {
     $writer = new Writer\Feed();
     try {
         $writer->export('foo');
         $this->fail();
     } catch (Writer\Exception\InvalidArgumentException $e) {
     }
 }
示例#22
0
 /**
  * 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;
 }
 /**
  * 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;
 }
示例#24
0
 /**
  * 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);
 }
示例#25
0
 /**
  * @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());
 }
示例#26
0
 /**
  * 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();
     }
 }
示例#27
0
 /**
  * @expectedException Zend\Feed\Writer\Exception
  */
 public function testSetSummaryThrowsExceptionWhenValueExceeds4000Chars()
 {
     $feed = new Writer\Feed;
     $feed->setItunesSummary(str_repeat('a',4001));
 }
 /**
  * @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;
 }