/** * @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()); }
/** * @param string $format * @return mixed|void */ public function setHeaders($format = 'atom') { $this->feed->setTitle(\Config::get('recipe.title')); $this->feed->setLink(url()); $this->feed->setFeedLink(route('feed.index', ['format' => $format]), $format); $this->feed->setDescription(\Config::get('recipe.title')); $this->feed->setDateModified(time()); $this->feed->addAuthor(['name' => 'Yuuki Takezawa', 'email' => '*****@*****.**']); $this->feed->addHub('http://pubsubhubbub.appspot.com/'); $this->format = $format; }
/** * @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; }
/** * 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; }
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'); }
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; }
/** * Generates a feed from Canale * @param Canale $canale * @return Feed */ public function generateFeed(Canale $canale, Router $router, $legacy = true) { $context = $router->getContext(); $base = $context->getScheme() . '://' . $context->getHost() . '/v2.php?do=ShowPermalink&id_notizia='; $idCanale = $canale->getIdCanale(); $feed = new Feed(); $feed->setTitle($nome = $canale->getTitolo()); $feed->setDescription('Feed ' . $nome); $feed->setLink($router->generate('rss', array('idCanale' => $idCanale), true)); $newsRepository = $this->repository; $news = $newsRepository->findByCanale($idCanale, 20); $news = is_array($news) ? $news : array(); foreach ($news as $item) { $this->newsToEntry($feed, $item, $base, $router, $legacy); } return $feed; }
/** * 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; }
/** * 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; }
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); }
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)); }
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; }
/** * Represent the current search results as a feed. * * @param \VuFind\Search\Base\Results $results Search results to convert to * feed * @param string $currentPath Base path to display in feed * (leave null to load dynamically using currentpath view helper) * * @return Feed */ public function __invoke($results, $currentPath = null) { $this->registerExtension(); // Determine base URL if not already provided: if (is_null($currentPath)) { $currentPath = $this->getView()->plugin('currentpath')->__invoke(); } $serverUrl = $this->getView()->plugin('serverurl'); $baseUrl = $serverUrl($currentPath); // Create the parent feed $feed = new Feed(); $feed->setTitle($this->translate('Results for') . ' ' . $results->getParams()->getDisplayQuery()); $feed->setLink($baseUrl . $results->getUrlQuery()->setViewParam(null, false)); $feed->setFeedLink($baseUrl . $results->getUrlQuery()->getParams(false), $results->getParams()->getView()); $feed->setDescription($this->translate('Showing') . ' ' . $results->getStartRecord() . '-' . $results->getEndRecord() . ' ' . $this->translate('of') . ' ' . $results->getResultTotal()); $params = $results->getParams(); // add atom links for easier paging $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage(1, false), 'first', $params->getView()); if ($params->getPage() > 1) { $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($params->getPage() - 1, false), 'previous', $params->getView()); } $lastPage = ceil($results->getResultTotal() / $params->getLimit()); if ($params->getPage() < $lastPage) { $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($params->getPage() + 1, false), 'next', $params->getView()); } $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($lastPage, false), 'last', $params->getView()); // add opensearch fields $feed->setOpensearchTotalResults($results->getResultTotal()); $feed->setOpensearchItemsPerPage($params->getLimit()); $feed->setOpensearchStartIndex($results->getStartRecord() - 1); $feed->setOpensearchSearchTerms($params->getQuery()->getString()); $records = $results->getResults(); foreach ($records as $current) { $this->addEntry($feed, $current); } return $feed; }
/** * @covers Zend\Feed\Writer\Feed::export */ public function testExportRss() { $writer = new Writer\Feed(); $writer->setTitle('foo'); $writer->setDescription('bar'); $writer->setLink('http://www.example.org'); $export = $writer->export('rss'); $feed = <<<'EOT' <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"> <channel> <title>foo</title> <description>bar</description> <generator>Zend_Feed_Writer %version% (http://framework.zend.com)</generator> <link>http://www.example.org</link> </channel> </rss> EOT; $feed = str_replace('%version%', Version::VERSION, $feed); $feed = str_replace("\r\n", "\n", $feed); $this->assertEquals($feed, $export); }
/** * 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の仕様上、&が自動的に&に変更されてしまう $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; }
/** * 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; }
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 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(); } }
public function testSetDescriptionThrowsExceptionOnInvalidParameter() { $writer = new Writer\Feed(); try { $writer->setDescription(''); $this->fail(); } catch (Writer\Exception $e) { } }
/** * 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; }
/** * 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; }
/** * Represent the current search results as a feed. * * @param \VuFind\Search\Base\Results $results Search results to convert to * feed * @param string $currentPath Base path to display in feed * (leave null to load dynamically using currentpath view helper) * * @return Feed */ public function __invoke($results, $currentPath = null) { $this->registerExtension(); // Determine base URL if not already provided: if (is_null($currentPath)) { $currentPath = $this->getView()->plugin('currentpath')->__invoke(); } $serverUrl = $this->getView()->plugin('serverurl'); $baseUrl = $serverUrl($currentPath); // Create the parent feed $feed = new Feed(); $translator = $this->getTranslator(); $feed->setTitle($translator('Results for') . ' ' . $results->getParams()->getDisplayQuery()); $feed->setLink($baseUrl . $results->getUrlQuery()->setViewParam(null, false)); $feed->setFeedLink($baseUrl . $results->getUrlQuery()->getParams(false), $results->getParams()->getView()); $records = $results->getResults(); $feed->setDescription($translator('Displaying the top') . ' ' . count($records) . ' ' . $translator('search results of') . ' ' . $results->getResultTotal() . ' ' . $translator('found')); foreach ($records as $current) { $this->addEntry($feed, $current); } return $feed; }