1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Rss
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Review form block
29: *
30: * @category Mage
31: * @package Mage_Rss
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Rss_Block_List extends Mage_Core_Block_Template
35: {
36: const XML_PATH_RSS_METHODS = 'rss';
37:
38: protected $_rssFeeds = array();
39:
40:
41: /**
42: * Add Link elements to head
43: *
44: * @return Mage_Rss_Block_List
45: */
46: protected function _prepareLayout()
47: {
48: $head = $this->getLayout()->getBlock('head');
49: $feeds = $this->getRssMiscFeeds();
50: if ($head && !empty($feeds)) {
51: foreach ($feeds as $feed) {
52: $head->addItem('rss', $feed['url'], 'title="'.$feed['label'].'"');
53: }
54: }
55: return parent::_prepareLayout();
56: }
57:
58: /**
59: * Retrieve rss feeds
60: *
61: * @return array
62: */
63: public function getRssFeeds()
64: {
65: return empty($this->_rssFeeds) ? false : $this->_rssFeeds;
66: }
67:
68: /**
69: * Add new rss feed
70: *
71: * @param string $url
72: * @param string $label
73: * @return Mage_Core_Helper_Abstract
74: */
75: public function addRssFeed($url, $label, $param = array(), $customerGroup=false)
76: {
77: $param = array_merge($param, array('store_id' => $this->getCurrentStoreId()));
78: if ($customerGroup) {
79: $param = array_merge($param, array('cid' => $this->getCurrentCustomerGroupId()));
80: }
81:
82: $this->_rssFeeds[] = new Varien_Object(
83: array(
84: 'url' => Mage::getUrl($url, $param),
85: 'label' => $label
86: )
87: );
88: return $this;
89: }
90:
91: public function resetRssFeed()
92: {
93: $this->_rssFeeds=array();
94: }
95:
96: public function getCurrentStoreId()
97: {
98: return Mage::app()->getStore()->getId();
99: }
100:
101: public function getCurrentCustomerGroupId()
102: {
103: return Mage::getSingleton('customer/session')->getCustomerGroupId();
104: }
105:
106: /**
107: * Retrieve rss catalog feeds
108: *
109: * array structure:
110: *
111: * @return array
112: */
113: public function getRssCatalogFeeds()
114: {
115: $this->resetRssFeed();
116: $this->CategoriesRssFeed();
117: return $this->getRssFeeds();
118:
119: /* $section = Mage::getSingleton('adminhtml/config')->getSections();
120: $catalogFeeds = $section->rss->groups->catalog->fields[0];
121: $res = array();
122: foreach($catalogFeeds as $code => $feed){
123: $prefix = self::XML_PATH_RSS_METHODS.'/catalog/'.$code;
124: if (!Mage::getStoreConfig($prefix) || $code=='tag') {
125: continue;
126: }
127: $res[$code] = $feed;
128: }
129: return $res;
130: */
131: }
132:
133: public function getRssMiscFeeds()
134: {
135: $this->resetRssFeed();
136: $this->NewProductRssFeed();
137: $this->SpecialProductRssFeed();
138: $this->SalesRuleProductRssFeed();
139: return $this->getRssFeeds();
140: }
141:
142: /*
143: public function getCatalogRssUrl($code)
144: {
145: $store_id = Mage::app()->getStore()->getId();
146: $param = array('store_id' => $store_id);
147: $custGroup = Mage::getSingleton('customer/session')->getCustomerGroupId();
148: if ($custGroup) {
149: $param = array_merge($param, array('cid' => $custGroup));
150: }
151:
152: return Mage::getUrl('rss/catalog/'.$code, $param);
153: }
154: */
155:
156: public function NewProductRssFeed()
157: {
158: $path = self::XML_PATH_RSS_METHODS.'/catalog/new';
159: if((bool)Mage::getStoreConfig($path)){
160: $this->addRssFeed($path, $this->__('New Products'));
161: }
162: }
163:
164: public function SpecialProductRssFeed()
165: {
166: $path = self::XML_PATH_RSS_METHODS.'/catalog/special';
167: if((bool)Mage::getStoreConfig($path)){
168: $this->addRssFeed($path, $this->__('Special Products'),array(),true);
169: }
170: }
171:
172: public function SalesRuleProductRssFeed()
173: {
174: $path = self::XML_PATH_RSS_METHODS.'/catalog/salesrule';
175: if((bool)Mage::getStoreConfig($path)){
176: $this->addRssFeed($path, $this->__('Coupons/Discounts'),array(),true);
177: }
178: }
179:
180: public function CategoriesRssFeed()
181: {
182: $path = self::XML_PATH_RSS_METHODS.'/catalog/category';
183: if((bool)Mage::getStoreConfig($path)){
184: $category = Mage::getModel('catalog/category');
185:
186: /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
187: $treeModel = $category->getTreeModel()->loadNode(Mage::app()->getStore()->getRootCategoryId());
188: $nodes = $treeModel->loadChildren()->getChildren();
189:
190: $nodeIds = array();
191: foreach ($nodes as $node) {
192: $nodeIds[] = $node->getId();
193: }
194:
195: $collection = $category->getCollection()
196: ->addAttributeToSelect('url_key')
197: ->addAttributeToSelect('name')
198: ->addAttributeToSelect('is_anchor')
199: ->addAttributeToFilter('is_active',1)
200: ->addIdFilter($nodeIds)
201: ->addAttributeToSort('name')
202: ->load();
203:
204: foreach ($collection as $category) {
205: $this->addRssFeed('rss/catalog/category', $category->getName(),array('cid'=>$category->getId()));
206: }
207: }
208: }
209: }
210: