/** * @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; }
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); }
public function testAddingHubUrlThrowsExceptionOnInvalidUri() { $writer = new Writer\Feed(); try { $writer->addHub('http://'); $this->fail(); } catch (Writer\Exception $e) { } }
/** * 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; }