Пример #1
0
 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);
 }
Пример #2
0
    $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 ;).');
    $feed->addEntry($entry);
Пример #3
0
 public function feedAction()
 {
     $this->doNotRender();
     if ($this->hasParam('id')) {
         $id = (int) $this->getParam('id');
         $record = Podcast::find($id);
         if (!$record instanceof Podcast) {
             throw new \DF\Exception\DisplayOnly('Show record not found!');
         }
         $feed_title = $record->name;
         $feed_desc = $record->description ? $record->description : 'A Ponyville Live! Show.';
         $cache_name = 'podcasts_' . $id . '_feed';
         $q = $this->em->createQuery('SELECT pe, p FROM Entity\\PodcastEpisode pe JOIN pe.podcast p WHERE p.is_approved = 1 AND p.id = :id ORDER BY pe.timestamp DESC')->setParameter('id', $id);
     } else {
         $feed_title = 'Ponyville Live! Shows';
         $feed_desc = 'The partner shows of the Ponyville Live! network, including commentary, interviews, episode reviews, convention coverage, and more.';
         $cache_name = 'podcasts_all_feed';
         $q = $this->em->createQuery('SELECT pe, p FROM Entity\\PodcastEpisode pe JOIN pe.podcast p WHERE p.is_approved = 1 AND pe.timestamp >= :threshold ORDER BY pe.timestamp DESC')->setParameter('threshold', strtotime('-3 months'));
     }
     $rss = \DF\Cache::get($cache_name);
     if (!$rss) {
         $records = $q->getArrayResult();
         // Initial RSS feed setup.
         $feed = new \Zend\Feed\Writer\Feed();
         $feed->setTitle($feed_title);
         $feed->setLink('http://ponyvillelive.com/');
         $feed->setDescription($feed_desc);
         $feed->addAuthor(array('name' => 'Ponyville Live!', 'email' => '*****@*****.**', 'uri' => 'http://ponyvillelive.com'));
         $feed->setDateModified(time());
         foreach ((array) $records as $episode) {
             try {
                 $podcast = $episode['podcast'];
                 $title = $episode['title'];
                 // Check for podcast name preceding episode name.
                 if (substr($title, 0, strlen($podcast['name'])) == $podcast['name']) {
                     $title = substr($title, strlen($podcast['name']));
                 }
                 $title = trim($title, " :-\t\n\r\v");
                 $title = $podcast['name'] . ' - ' . $title;
                 // Create record.
                 $entry = $feed->createEntry();
                 $entry->setTitle($title);
                 $entry->setLink($episode['web_url']);
                 $entry->addAuthor(array('name' => $podcast['name'], 'uri' => $podcast['web_url']));
                 $entry->setDateModified($episode['timestamp']);
                 $entry->setDateCreated($episode['timestamp']);
                 if ($podcast['description']) {
                     $entry->setDescription($podcast['description']);
                 }
                 if ($episode['body']) {
                     $entry->setContent($episode['body']);
                 }
                 $feed->addEntry($entry);
             } catch (\Exception $e) {
             }
         }
         // Export feed.
         $rss = $feed->export('rss');
         \DF\Cache::set($rss, $cache_name, array(), 60 * 15);
     }
     header("Content-Type: application/rss+xml");
     echo $rss;
 }
Пример #4
0
 /**
  * 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;
 }