public function getFeed($mode) { $feedMethod = 'rss'; if ($mode == self::RSS) { $feedMethod = 'rss'; } elseif ($mode == self::ATOM) { $feedMethod = 'atom'; } $feed = new \Zend\Feed\Writer\Feed(); $feed->setTitle(Yii::t('app', 'Introduce business')); $feed->setDescription(Yii::t('app', 'Introduce business')); $feed->setLink(Yii::$app->getRequest()->getHostInfo()); $feed->setFeedLink(Yii::$app->getRequest()->getAbsoluteUrl(), $feedMethod); $feed->setGenerator('Admap', Yii::$app->version, Yii::$app->getRequest()->getHostInfo()); $feed->addAuthor(['name' => 'Jafaripur', 'email' => '*****@*****.**', 'uri' => 'http://www.jafaripur.ir']); $feed->setDateModified(time()); //$feed->addHub('http://pubsubhubbub.appspot.com/'); foreach ($this->getModel(50) as $adver) { $entry = $feed->createEntry(); $entry->setId($adver['id']); $entry->setTitle(Html::encode($adver['title'])); $entry->addCategory(['term' => Html::encode($adver['category']['name']), 'label' => Html::encode($adver['category']['name'])]); $entry->setLink(urldecode(Adver::generateLink($adver['id'], $adver['title'], $adver['category']['name'], $adver['country']['name'], $adver['province']['name'], $adver['city']['name'], $adver['address'], $adver['lang'], true))); /*$entry->addAuthor(array( 'name' => 'Paddy', 'email' => '*****@*****.**', 'uri' => 'http://www.example.com', ));*/ $entry->setDateModified((int) $adver['updated_at']); $entry->setDateCreated((int) $adver['created_at']); $entry->setDescription(\yii\helpers\StringHelper::truncate(strip_tags($adver['description']), 140)); //$entry->setContent ($description); $feed->addEntry($entry); } return $feed->export($feedMethod); }
$app->get('/episode/:episodeSlug', function ($episodeSlug) use($app) { $episode = $app->episodeLister->getEpisode($episodeSlug); if (is_null($episode)) { $app->notFound(); } else { $app->render('episode.twig', ['episode' => $episode]); } }); $app->get('/rss', function () use($app) { /** * Create the parent feed */ $feed = new Zend\Feed\Writer\Feed(); $feed->setTitle('Paddy\'s Blog'); $feed->setLink('http://www.freethegeek.fm'); $feed->setFeedLink('http://www.freethegeek.com/feed/rss', 'rss'); $feed->addAuthor(array('name' => 'Matthew Setter', 'email' => '*****@*****.**', 'uri' => 'http://www.freethegeek.fm')); $feed->setDateModified(time()); $feed->setDescription("Here's a description"); /** * Add one or more entries. Note that entries must * be manually added once created. */ $entry = $feed->createEntry(); $entry->setTitle('All Your Base Are Belong To Us'); $entry->setLink('http://www.example.com/all-your-base-are-belong-to-us'); $entry->addAuthor(array('name' => 'Paddy', 'email' => '*****@*****.**', 'uri' => 'http://www.example.com')); $entry->setDateModified(time()); $entry->setDateCreated(time()); $entry->setDescription('Exposing the difficultly of porting games to English.'); $entry->setContent('I am not writing the article. The example is long enough as is ;).');
/** * Generate a feed (ATOM 1.0 or RSS 2.0 using Zend\Feed\Writer\Feed * * @param string $section Tiki feature the feed is related to * @param string $uniqueid * @param string $feed_version DEPRECATED * @param array $changes the content that will be used to generate the feed * @param string $itemurl base url for items (e.g. "tiki-view_blog_post.php?postId=%s") * @param string $urlparam * @param string $id name of the id field used to identify each feed item (e.g. "postId") * @param string $title title for the feed * @param string $titleId name of the key in the $changes array with the title of each item * @param string $desc description for the feed * @param string $descId name of the key in the $changes array with the description of each item * @param string $dateId name of the key in the $changes array with the date of each item * @param string $authorId name of the key in the $changes array with the author of each item * @param bool $fromcache if true recover the feed from cache * * @return array the generated feed */ function generate_feed($section, $uniqueid, $feed_version, $changes, $itemurl, $urlparam, $id, $title, $titleId, $desc, $descId, $dateId, $authorId, $fromcache = false) { global $tiki_p_admin, $prefs; $userlib = TikiLib::lib('user'); $tikilib = TikiLib::lib('tiki'); $smarty = TikiLib::lib('smarty'); // both title and description fields cannot be null if (empty($title) || empty($desc)) { $msg = tra('The fields title and description are mandatory to generate a feed.'); if ($tiki_p_admin) { $msg .= ' ' . tra('To fix this error go to Admin -> Feeds.'); } else { $msg .= ' ' . tra('Please contact the site administrator and ask him to fix this error'); } $smarty->assign('msg', $msg); $smarty->display('error.tpl'); die; } $feed_format = $this->get_current_feed_format(); $feed_format_name = $this->get_current_feed_format_name(); if ($prefs['feed_cache_time'] < 1) { $fromcache = false; } // only get cache data if rss cache is enabled if ($fromcache) { $output = $this->get_from_cache($uniqueid, $feed_format); if ($output['data'] != 'EMPTY') { return $output; } } $urlarray = parse_url($_SERVER["REQUEST_URI"]); $rawPath = str_replace('\\', '/', dirname($urlarray["path"])); $URLPrefix = $tikilib->httpPrefix() . $rawPath; if ($rawPath != "/") { $URLPrefix .= "/"; // Append a slash unless Tiki is in the document root. dirname() removes a slash except in that case. } if (isset($prefs['feed_' . $section . '_index']) && $prefs['feed_' . $section . '_index'] != '') { $feedLink = $prefs['feed_' . $section . '_index']; } else { $feedLink = htmlspecialchars($tikilib->httpPrefix() . $_SERVER["REQUEST_URI"]); } $img = htmlspecialchars($URLPrefix . $prefs['feed_img']); $title = htmlspecialchars($title); $desc = htmlspecialchars($desc); $read = $URLPrefix . $itemurl; $feed = new Zend\Feed\Writer\Feed(); $feed->setTitle($title); $feed->setDescription($desc); if (!empty($prefs['feed_language'])) { $feed->setLanguage($prefs['feed_language']); } $feed->setLink($tikilib->tikiUrl('')); $feed->setFeedLink($feedLink, $feed_format_name); $feed->setDateModified($tikilib->now); if ($feed_format_name == 'atom') { $author = array(); if (!empty($prefs['feed_atom_author_name'])) { $author['name'] = $prefs['feed_atom_author_name']; } if (!empty($prefs['feed_atom_author_email'])) { $author['email'] = $prefs['feed_atom_author_email']; } if (!empty($prefs['feed_atom_author_url'])) { $author['url'] = $prefs['feed_atom_author_url']; } if (!empty($author)) { if (empty($author['name'])) { $msg = tra('If you set feed author email or URL, you must set feed author name.'); $smarty->assign('msg', $msg); $smarty->display('error.tpl'); die; } $feed->addAuthor($author); } } else { $authors = array(); if (!empty($prefs['feed_rss_editor_email'])) { $authors['name'] = $prefs['feed_rss_editor_email']; } if (!empty($prefs['feed_rss_webmaster_email'])) { $authors['name'] = $prefs['feed_rss_webmaster_email']; } if (!empty($authors)) { $feed->addAuthors(array($authors)); } } if (!empty($prefs['feed_img'])) { $image = array(); $image['uri'] = $tikilib->tikiUrl($prefs['feed_img']); $image['title'] = tra('Feed logo'); $image['link'] = $tikilib->tikiUrl(''); $feed->setImage($image); } foreach ($changes["data"] as $data) { $item = $feed->createEntry(); $item->setTitle($data[$titleId]); if (isset($data['sefurl'])) { $item->setLink($URLPrefix . $data['sefurl']); } elseif ($urlparam != '') { // 2 parameters to replace $item->setlink(sprintf($read, urlencode($data["{$id}"]), urlencode($data["{$urlparam}"]))); } else { $item->setLink(sprintf($read, urlencode($data["{$id}"]))); } if (isset($data[$descId]) && $data[$descId] != '') { $item->setDescription($data[$descId]); } $item->setDateCreated($data[$dateId]); $item->setDateModified($data[$dateId]); if ($authorId != '' && $prefs['feed_' . $section . '_showAuthor'] == 'y') { $author = $this->process_item_author($data[$authorId]); $item->addAuthor($author); } $feed->addEntry($item); } $data = $feed->export($feed_format_name); $this->put_to_cache($uniqueid, $feed_format, $data); $output = array(); $output["data"] = $data; $output["content-type"] = 'application/xml'; return $output; }