/** * Rock the Symfony cache to avoid fetching the same external URL over and over * These defaults are safe and boring and way faster than bashing on other servers. * But here's a tip. If you don't have APC enabled your site is probably running very, * very slowly, so fix that. And then do this for even better speed: * * a: * feed: * cache_class: sfAPCCache * cache_options: { } * @param mixed $url * @param mixed $interval * @return mixed */ public static function fetchCachedFeed($url, $interval = 300) { $cacheClass = sfConfig::get('app_a_feed_cache_class', 'sfFileCache'); $cache = new $cacheClass(sfConfig::get('app_a_feed_cache_options', array('cache_dir' => aFiles::getWritableDataFolder(array('a_feed_cache'))))); $key = 'apostrophe:feed:' . $url; $feed = $cache->get($key, false); if ($feed === 'invalid') { return false; } else { if ($feed !== false) { // sfFeed is designed to serialize well $feed = unserialize($feed); } } if (!$feed) { try { // We now always use the fopen adapter and specify a time limit, which is configurable. // Francois' comments about fopen being slow are probably dated, the stream wrappers are // quite good in modern PHP and in any case Apostrophe uses them consistently elsewhere $options = array('adapter' => 'sfFopenAdapter', 'adapter_options' => array('timeout' => sfConfig::get('app_a_feed_timeout', 30))); $feed = sfFeedPeer::createFromWeb($url, $options); $cache->set($key, serialize($feed), $interval); } catch (Exception $e) { // Cache the fact that the feed is invalid for 60 seconds so we don't // beat the daylights out of a dead feed $cache->set($key, 'invalid', 60); return false; } } return $feed; }
public function executeFeed(sfWebRequest $request) { $format = $request->getParameter('format'); if ($format === 'atom') { $format = 'atom1'; } elseif ($format === 'rss') { $format = 'rss201'; } $feed = sfFeedPeer::newInstance($format); $feed->setTitle(sfConfig::get('app_rt_blog_title', 'Latest News')); $feed->setLink('http://' . rtSiteToolkit::getCurrentDomain()); $feed->setAuthorEmail(sfConfig::get('app_rt_blog_author_email')); $feed->setAuthorName(sfConfig::get('app_rt_blog_author_name', 'News Editor')); // $feedImage = new sfFeedImage(); // $feedImage->setFavicon('http://'.rtSiteToolkit::getCurrentDomain().'/favicon.ico'); // $feed->setImage($feedImage); $query = Doctrine::getTable('rtBlogPage')->addPublishedQuery(); $query->limit(20)->orderBy('page.id DESC'); $posts = $query->execute(); foreach ($posts as $rt_blog_page) { $item = new sfFeedItem(); $item->setTitle($rt_blog_page->getTitle()); $item->setLink($this->generateUrl('rt_blog_page_show', $rt_blog_page, array('absolute' => true))); $item->setAuthorName($rt_blog_page->getAuthorName()); $item->setAuthorEmail($rt_blog_page->getAuthorEmail()); $item->setPubdate(strtotime($rt_blog_page->getCreatedAt())); $item->setUniqueId($rt_blog_page->getSlug()); $item->setDescription($rt_blog_page->getDescription()); $feed->addItem($item); } $this->feed = $feed; }
public static function fetchCachedFeed($url, $interval = 300) { $cacheClass = sfConfig::get('app_a_feed_cache_class', 'sfFileCache'); $cache = new $cacheClass(sfConfig::get('app_a_feed_cache_options', array('cache_dir' => aFiles::getWritableDataFolder(array('a_feed_cache'))))); $key = 'apostrophe:feed:' . $url; $feed = $cache->get($key, false); if ($feed === 'invalid') { return false; } else { if ($feed !== false) { // sfFeed is designed to serialize well $feed = unserialize($feed); } } if (!$feed) { try { $feed = sfFeedPeer::createFromWeb($url); $cache->set($key, serialize($feed), $interval); } catch (Exception $e) { // Cache the fact that the feed is invalid for 60 seconds so we don't // beat the daylights out of a dead feed $cache->set($key, 'invalid', 60); return false; } } return $feed; }
public function getFeed() { $this->articles = $this->pager->getResults(); $title = sfConfig::get('app_aEvent_feed_title', $this->page->getTitle()); $this->feed = sfFeedPeer::createFromObjects($this->articles, array('format' => 'rss', 'title' => $title, 'link' => '@a_event', 'authorEmail' => sfConfig::get('app_aEvent_feed_author_email'), 'authorName' => sfConfig::get('app_aEvent_feed_author_name'), 'routeName' => '@a_event', 'methods' => array('description' => 'getFeedText'))); $this->getResponse()->setContent($this->feed->asXml()); }
protected function getItemCollection($url) { $browser = $this->getService('web_browser'); if ($browser->get($url)->responseIsError()) { throw new dmException(sprintf('The given URL (%s) returns an error (%s: %s)', $url, $browser->getResponseCode(), $browser->getResponseMessage())); } return sfFeedPeer::createFromXml($browser->getResponseText(), $url)->getItems(); }
public function executeFeed() { /** @var sfWebRequest **/ $request = $this->getContext()->getRequest(); $IdType = $this->getRequestParameter('IdType', null); $id = $this->getRequestParameter('id', null); //Build the title $title = "Metadata Registry Change History"; $filter = false; switch ($IdType) { //ElementSet :: (Schema)Element :: (Schema)ElementProperty //Schema :: SchemaProperty :: SchemaPropertyElement case "schema_property_element_id": /** @var SchemaPropertyElement **/ $element = DbFinder::from('SchemaPropertyElement')->findPk($id); if ($element) { /** @var SchemaProperty **/ $property = $element->getSchemaPropertyRelatedBySchemaPropertyId(); $title .= " for Property: '" . $element->getProfileProperty()->getLabel(); if ($property) { $title .= "' of Element: '" . $property->getLabel() . "' in Element Set: '" . $property->getSchema()->getName() . "'"; } } $filter = true; break; case "schema_property_id": /** @var SchemaProperty **/ $property = DbFinder::from('SchemaProperty')->findPk($id); if ($property) { $title .= " for Element: '" . $property->getLabel() . "' in Element Set: '" . $property->getSchema()->getName() . "'"; } $filter = true; break; case "schema_id": /** @var Schema **/ $schema = DbFinder::from('Schema')->findPk($id); if ($schema) { $title .= " for Element Set: '" . $schema->getName() . "'"; } $filter = true; break; default: //the whole shebang $title .= " for all Element Sets"; break; } $column = sfInflector::camelize($IdType); //default limit to 100 if not set in config $limit = $request->getParameter('nb', sfConfig::get('app_frontend_feed_count', 100)); $finder = DbFinder::from('SchemaPropertyElementHistory')->orderBy('SchemaPropertyElementHistory.CreatedAt', 'desc')->join('SchemaPropertyElementHistory.SchemaPropertyElementId', 'SchemaPropertyElement.Id', 'left join')->join('SchemaProperty', 'left join')->join('Schema', 'left join')->join('Status', 'left join')->join('User', 'left join')->join('ProfileProperty', 'left join')->with('Schema', 'ProfileProperty', 'User', 'Status', 'SchemaProperty'); if ($filter) { $finder = $finder->where('SchemaPropertyElementHistory.' . $column, $id); } $finder = $finder->find($limit); $this->setTemplate('feed'); $this->feed = sfFeedPeer::createFromObjects($finder, array('format' => $request->getParameter('format', 'atom1'), 'link' => $request->getUriPrefix() . $request->getPathInfo(), 'feedUrl' => $request->getUriPrefix() . $request->getPathInfo(), 'title' => htmlentities($title), 'methods' => array('authorEmail' => '', 'link' => 'getFeedUniqueId'))); return; }
public function executePostsForTagFeed() { sfLoader::loadHelpers(array('I18N')); $tag = $this->getRequestParameter('tag'); $this->forward404Unless($tag); $posts = sfSimpleBlogPostPeer::getTagged($tag, $this->getRequestParameter('nb', sfConfig::get('app_sfSimpleBlog_feed_count', 5))); $this->feed = sfFeedPeer::createFromObjects($posts, array('format' => $this->getRequestParameter('format', 'atom1'), 'title' => __('Posts tagged "%1%" from %2%', array('%1%' => $tag, '%2%' => sfConfig::get('app_sfSimpleBlog_title', ''))), 'link' => $this->getController()->genUrl('sfSimpleBlog/showByTag?tag=' . $tag), 'authorName' => sfConfig::get('app_sfSimpleBlog_author', ''), 'methods' => array('authorEmail' => ''))); $this->setTemplate('feed'); }
private function getFeed($format = 'atom1') { $feed = sfFeedPeer::newInstance($format); $feed->setTitle('PluginsKit - Latest'); $feed->setLink('@homepage'); $feedImage = new sfFeedImage(); $feedImage->setLink('@homepage'); $feed->setImage($feedImage); return $feed; }
public function executeHudsonBox() { $cache = $this->context->get('cache_manager')->getCache('feed'); if ($cache->has('hudson-last')) { $this->items = $cache->get('hudson-last'); } elseif (!sfConfig::get('dm_search_populating')) { $url = 'http://ci.diem-project.org/rssAll'; $this->items = sfFeedPeer::createFromWeb($url)->getItems(); $cache->set('hudson-last', $this->items, 10800); } }
/** * rss and atom feeds * * @return return_type */ public function executeFeed() { /** @var sfWebRequest **/ $request = $this->getContext()->getRequest(); $IdType = $this->getRequestParameter('IdType', null); $id = $this->getRequestParameter('id', null); //Build the title $title = "Metadata Registry Change History"; $filter = false; switch ($IdType) { case "property_id": /** @var ConceptProperty **/ $conceptProperty = ConceptPropertyPeer::retrieveByPK($id); if ($conceptProperty) { $vocabularyname = $conceptProperty->getVocabulary() ? $conceptProperty->getVocabulary()->getName() : "?"; $title .= " for Property: '" . $conceptProperty->getProfileProperty()->getName() . "' of Concept: '" . $conceptProperty->getConceptRelatedByConceptId()->getPrefLabel() . "' in Vocabulary: '" . $vocabularyname . "'"; } $filter = true; break; case "concept_id": /** @var Concept **/ $concept = DbFinder::from('Concept')->findPk($id); if ($concept) { $title .= " for Concept: '" . $concept->getPrefLabel() . "' in Vocabulary: '" . $concept->getVocabulary()->getName() . "'"; } $filter = true; break; case "vocabulary_id": /** @var Vocabulary **/ $vocab = DbFinder::from('Vocabulary')->findPk($id); if ($vocab) { $title .= " for Vocabulary: '" . $vocab->getName() . "'"; } $filter = true; break; default: //the whole shebang $title .= " for all Vocabularies"; break; } //special rule for property_id $column = "property_id" == $IdType ? "ConceptPropertyId" : sfInflector::camelize($IdType); //default limit to 100 if not set in config $limit = $request->getParameter('nb', sfConfig::get('app_frontend_feed_count', 100)); $finder = DbFinder::from('ConceptPropertyHistory')->orderBy('ConceptPropertyHistory.CreatedAt', 'desc')->join('ConceptProperty', 'left join')->join('Concept', 'left join')->join('Vocabulary', 'left join')->join('Status', 'left join')->join('User', 'left join')->join('SkosProperty', 'left join')->with('Vocabulary', 'SkosProperty', 'User', 'Status', 'ConceptProperty', 'Concept'); if ($filter) { $finder = $finder->where('ConceptPropertyHistory.' . $column, $id); } $finder = $finder->find($limit); $this->setTemplate('feed'); $this->feed = sfFeedPeer::createFromObjects($finder, array('format' => $request->getParameter('format', 'atom1'), 'link' => $request->getUriPrefix() . $request->getPathInfo(), 'feedUrl' => $request->getUriPrefix() . $request->getPathInfo(), 'title' => htmlentities($title), 'methods' => array('authorEmail' => '', 'link' => 'getFeedUniqueId'))); return; }
public function run(sfEvent $event) { if (isset($event['pager'])) { $pager = $event['pager']; $context = sfContext::getInstance(); $response = $context->getResponse(); $request = $context->getRequest(); $className = 'sf' . ucfirst($event['format']) . 'Feed'; if (!class_exists($className)) { return false; } $feed = sfFeedPeer::newInstance($event['format']); $feed->initialize(array('title' => $response->getTitle(), 'link' => $request->getUri())); $items = sfFeedPeer::convertObjectsToItems($pager->getResults()); $feed->addItems($items); $event->setProcessed(true); $event->setReturnValue($feed->asXml()); $request->setRequestFormat($event['format']); return true; } else { return false; } }
protected function getFeedFromObjects($objects) { $feed = sfFeedPeer::createFromObjects($objects, array('format' => 'atom1', 'title' => $this->feed_title, 'link' => $this->rule, 'methods' => array('authorEmail' => ''))); $this->setLayout(false); return $feed->asXml(); }
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; sfContext::getInstance(); $cache = new sfArrayCache(sfConfig::get('sf_cache_dir')); $cache->setLifeTime(86400); // convert to seconds $pages = $cache->get('pages', 'my_cache_dir'); // test for empty or timed out cache if ($pages === null) { $pages = array(); /* $feeds = array( 'http://www.fbi.gov/rss/topten.xml', 'http://www.fbi.gov/rss/terrorists.xml' );*/ $feeds = array('http://www.fbi.gov/rss/topten.xml', 'http://www.fbi.gov/rss/terrorists.xml', 'http://www.fbi.gov/rss/murder.xml', 'http://www.fbi.gov/rss/violent.xml', 'http://www.fbi.gov/rss/cyber.xml', 'http://www.fbi.gov/rss/cac.xml', 'http://www.fbi.gov/rss/criment.xml', 'http://www.fbi.gov/rss/white.xml'); foreach ($feeds as $feedurl) { $feed = sfFeedPeer::createFromWeb($feedurl); $items = $feed->getItems(); foreach ($items as $item) { $pages[] = $item->getLink(); } } $cache->set('pages', 'my_cache_dir', $pages); } $images = $cache->get('images', 'my_cache_dir'); if ($images === null) { $images = array(); $numofpages = count($pages); foreach ($pages as $pageindex => $url) { $path = substr($url, 0, strrpos($url, '/') + 1); $b = new sfWebBrowser(); $b->get($url);
public function getDefaultFeed($max = 25) { $feed = new sfRssFeed(); $feed->initialize(array('title' => 'Cothink Feed for ' . $this->getFullName(), 'link' => 'http://www.cothink.org/', 'authorEmail' => $this->getPrimaryContactInfo()->getEmail(), 'authorName' => $this->getFullName())); $events = HistoryEventPeer::retrieveByUser($this->getUserId(), $max); // TODO: Allow user to configure max $eventItems = sfFeedPeer::convertObjectsToItems($events, array('routeName' => '@permalink')); $feed->addItems($eventItems); return $feed; }
<div class="sevencol"> <!-- Banner Camere Aperte 2013 --> <div style="margin-bottom:20px;"> <?php echo link_to(image_tag('ca2014_banner.png', array('alt' => 'Indice 2014')), 'http://blog.openpolis.it/2014/11/03/pubblicato-il-minidossier-indice-di-produttivita-parlamentare/'); ?> </div> <!-- in evidenza dal blog --> <div class="section-box" style="padding-bottom:20px;"> <?php echo link_to(image_tag('ico-rss.png', array('alt' => 'rss')), 'http://feeds.feedburner.com/openpolis?format=xml', array('class' => 'section-box-rss')); ?> <h3>in evidenza dal blog di openpolis</h3> <?php include_partial('sfSimpleBlog/inevidenza', array('feed' => sfFeedPeer::createFromWeb('http://blog.openpolis.it/categorie/inparlamento/feed/'), 'limit' => 3)); ?> <p align=right><strong><a href="http://blog.openpolis.it/">vai al blog di openpolis</a></strong></p> </div> <!-- box keyvotes --> <?php include_component('votazione', 'keyvotes', array('limit' => '5', 'pagina' => 'homepage', 'type' => 'key')); ?> <div class="clear-both"></div> <!-- Box attivita' utenti --> <div class="section-box" style="margin-top: 2em;"> <h3 class="section-box-no-rss">ultime dalla comunità</h3> <?php
/** * Displays the latest changes to the registry * */ public function getChangeFeed() { try { $feed1 = sfFeedPeer::createFromWeb($this->getRequest()->getUriPrefix() . "/schemahistory/feed.atom"); $feed2 = sfFeedPeer::createFromWeb($this->getRequest()->getUriPrefix() . "/history/feed.atom"); if ($feed1 && $feed2) { $image = new sfFeedImage(); $image->setFavicon($this->getRequest()->getUriPrefix() . "/favicon.ico"); $image->setFeed($this->getRequest()->getUriPrefix() . "/allhistoryfeeds.atom"); $image->setLink($image->getFeed()); $image->setTitle("Metadata Registry Change History"); $this->feed = sfFeedPeer::aggregate(array($feed1, $feed2), array('limit' => 100, 'format' => 'atom1', 'link' => $image->getLink(), 'title' => $image->getTitle(), 'feedUrl' => $image->getFeed(), 'image' => $image, 'description' => 'A statement-level list of all of the recent changes to the vocabularies and element sets maintained in the Metadata registry.')); $this->changeFeedItems = $this->feed->getItems(); } } catch (Exception $e) { } }
public function executeCommentsForPostFeed() { sfLoader::loadHelpers(array('I18N')); $post = sfSimpleBlogPostPeer::retrieveByStrippedTitleAndDate($this->getRequestParameter('stripped_title'), $this->getDateFromRequest()); $this->forward404Unless($post); $comments = sfSimpleBlogCommentPeer::getForPost($post, $this->getRequestParameter('nb', sfConfig::get('app_sfSimpleBlog_feed_count', 5))); $this->feed = sfFeedPeer::createFromObjects($comments, array('format' => $this->getRequestParameter('format', 'atom1'), 'title' => __('Comments on post "%1%" from %2%', array('%1%' => $post->getTitle(), '%2%' => sfConfig::get('app_sfSimpleBlog_title', ''))), 'link' => $this->getController()->genUrl('sfSimpleBlog/show?stripped_title=' . $post->getStrippedTitle()), 'authorName' => sfConfig::get('app_sfSimpleBlog_author', ''), 'methods' => array('title' => 'getPostTitle', 'authorEmail' => ''))); $this->setTemplate('feed'); }
protected function browser2feed(sfWebBrowser $b) { if ($b == null) { throw new limeException('curl', "Can't make feed from nothing"); } try { return sfFeedPeer::createFromXml($b->getResponseText(), $this->getRssUrl()); } catch (Exception $e) { } return null; }
?> <div id="last_docs" class="latest"> <?php if (!isset($default_open)) { $default_open = true; } include_partial('documents/home_section_title', array('module' => 'docs', 'custom_title_icon' => 'list', 'has_title_link' => false, 'has_title_rss' => true, 'custom_title_text' => __('Latest documents'), 'custom_rss' => link_to('', $sf_request->getUriPrefix() . '/static/rss/latest_docs.rss', array('class' => 'home_title_right picto_rss', 'title' => __("Subscribe to latest documents creations"))))); ?> <div id="last_docs_section_container" class="home_container_text"> <?php try { $rssfile = SF_ROOT_DIR . '/web/static/rss/latest_docs.rss'; if (file_exists($rssfile)) { $rss = file_get_contents($rssfile); $feed = sfFeedPeer::createFromXml($rss, $sf_request->getUriPrefix() . '/documents/latest'); $items = array_reverse(sfFeedPeer::aggregate(array($feed))->getItems(), true); } else { $items = array(); } } catch (Exception $e) { $items = array(); } if (count($items) == 0) { ?> <p><?php echo __('No recent changes available'); ?> </p> <?php } else { ?>
public function executeNameWire() { $feed = sfFeedPeer::createFromWeb('http://blog.littlesis.org/category/namewire/feed'); $this->posts = $feed->getItems(); if (count($this->posts) > 3) { $this->posts = array_slice($this->posts, 0, 3); } }