/**
  * Get/load the feed.
  *
  * @param string url The feed url.
  * @param string category An optional category; default is <code>null</code>.
  * @param int limit An optional item limit; default is 5; use 0 for all.
  * @return RssFedd A <code>RssFeed</code> instance.
  */
 public function getFeed($url, $category = null, $limit = 5)
 {
     $cacheKey = Toolbox::hash('feeds', $url, implode(':', $this->config));
     if (!$this->cache || false === ($rssParser = $this->cache->lookup($cacheKey))) {
         $rssParser = new RssParser($this->config);
         // todo: conditional GET
         $rssParser->parse(file_get_contents($url, $this->config['useIncludePath'], $this->getContext()));
     }
     $feed = new RssFeed();
     $feed->setChannel(new RssChannel($rssParser->getChannel()));
     $items = array();
     foreach ($rssParser->getItems() as $itemData) {
         $item = new RssItem($itemData);
         if (null == $category || in_array($category, $item->getCategories())) {
             $items[] = $item;
         }
         if (0 != $limit && $limit <= count($items)) {
             break;
         }
     }
     $feed->setItems(new \ArrayIterator($items));
     // cache if enabled
     if ($this->cache) {
         $this->cache->save($rssParser, $cacheKey);
     }
     return $feed;
 }
 /**
  * Generate RSS feed for all categories.
  *
  * @param ZenMagick\Http\Request request The current request.
  * @param boolean full Indicates whether to generate a full feed or not; default is <code>false</code>.
  * @return RssFeed The feed.
  */
 protected function getCategoriesFeed($request, $full)
 {
     $settingsService = $this->container->get('settingsService');
     $translator = $this->container->get('translator');
     $router = $this->container->get('router');
     $channel = new RssChannel();
     $channel->setTitle($translator->trans('Categories at %store_name%', array('%store_name%' => $settingsService->get('storeName'))));
     $channel->setLink($router->generate('index', array(), true));
     $channel->setDescription($translator->trans('All categories at %store_name%', array('%store_name%' => $settingsService->get('storeName'))));
     $channel->setLastBuildDate($lastPubDate);
     $feed = new RssFeed();
     $feed->setChannel($channel);
     // set up item iterator
     $languageId = $request->getSession()->getLanguageId();
     $categoryService = $this->container->get('categoryService');
     //TODO: $categoryService->setCache(null);
     $categoryInfo = array();
     foreach ($categoryService->getAllCategories($languageId) as $category) {
         if ($category->isActive()) {
             $categoryInfo[] = array('id' => $category->getId(), 'url' => $router->generate('category', array('cPath' => implode('_', $category->getPath()))));
         }
     }
     $itemIterator = new CatalogCategoryRssItemIterator($categoryInfo, $languageId, $this->fullFeed);
     $itemIterator->setContainer($this->container);
     $feed->setItems($itemIterator);
     return $feed;
 }
 /**
  * Generate RSS feed for products.
  *
  * @param ZenMagick\Http\Request request The current request.
  * @param string key Optional key value for various product types; supported: 'new'
  * @return RssFeed The feed data.
  */
 protected function getProductsFeed($request, $key = null)
 {
     if ('new' != $key) {
         return null;
     }
     $toolbox = $this->container->get('toolbox');
     $translator = $this->container->get('translator');
     $lastPubDate = null;
     $items = array();
     $products = array_slice(array_reverse($this->container->get('productService')->getNewProducts()), 0, 20);
     foreach ($products as $product) {
         $item = new RssItem();
         $item->setTitle($product->getName());
         $url = $router->generate('product_info', array('productId' => $productId), true);
         $item->setLink($url);
         $item->setDescription($toolbox->html->more($toolbox->html->strip($product->getDescription()), 60));
         $item->setPubDate($product->getDateAdded());
         $items[] = $item;
         if (null === $lastPubDate) {
             $lastPubDate = $product->getDateAdded();
         }
     }
     $settingsService = $this->container->get('settingsService');
     $router = $this->container->get('router');
     $channel = new RssChannel();
     $channel->setTitle($translator->trans('New Products at %store_name%', array('%store_name%' => $settingsService->get('storeName'))));
     $channel->setLink($router->generate('index', array(), true));
     $channel->setDescription($translator->trans("The latest updates to %store_name%'s product list", array('%store_name%' => $settingsService->get('storeName'))));
     $channel->setLastBuildDate($lastPubDate);
     $feed = new RssFeed();
     $feed->setChannel($channel);
     $feed->setItems(new \ArrayIterator($items));
     return $feed;
 }