Version Notes
- Initial release
Download this release
Release Info
Developer | Magento Core Team |
Extension | Flagbit_FeedReader |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Flagbit/FeedReader/Block/Abstract.php +171 -0
- app/code/community/Flagbit/FeedReader/Block/Sidebar.php +31 -0
- app/code/community/Flagbit/FeedReader/etc/config.xml +28 -0
- app/design/frontend/base/default/layout/feedreader.xml +14 -0
- app/design/frontend/base/default/template/feedreader/sidebar.phtml +40 -0
- app/etc/modules/Flagbit_FeedReader.xml +9 -0
- package.xml +20 -0
- skin/frontend/base/default/css/feedreader.css +7 -0
app/code/community/Flagbit/FeedReader/Block/Abstract.php
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* @category Flagbit
|
6 |
+
* @package Flagbit_FeedReader
|
7 |
+
* @copyright Copyright (c) 2010 Flagbit GmbH & Co. KG (http://www.flagbit.de)
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Abstract feed reader block
|
12 |
+
*
|
13 |
+
* @category Flagbit
|
14 |
+
* @package Flagbit_FeedReader
|
15 |
+
* @author David Fuhr <fuhr@flagbit.de>
|
16 |
+
*/
|
17 |
+
abstract class Flagbit_FeedReader_Block_Abstract extends Mage_Core_Block_Template
|
18 |
+
{
|
19 |
+
/**
|
20 |
+
* @var Zend_Feed_Abstract
|
21 |
+
*/
|
22 |
+
protected $_feed = null;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
+
protected $_title = null;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* @var int
|
31 |
+
*/
|
32 |
+
private $_itemCount = 5;
|
33 |
+
|
34 |
+
/**
|
35 |
+
* The constructor
|
36 |
+
*
|
37 |
+
* @return Flagbit_FeedReader_Block_Abstract
|
38 |
+
*/
|
39 |
+
public function __construct()
|
40 |
+
{
|
41 |
+
parent::__construct();
|
42 |
+
|
43 |
+
// set up the cache
|
44 |
+
$this->setCacheLifetime(60 * 30); // 30 minutes
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Sets the feed uri
|
49 |
+
*
|
50 |
+
* @param string $uri The feed uri
|
51 |
+
* @return Flagbit_FeedReader_Block_Abstract
|
52 |
+
*/
|
53 |
+
public function setUri($uri)
|
54 |
+
{
|
55 |
+
try {
|
56 |
+
$this->_feed = Zend_Feed::import($uri);
|
57 |
+
// update the cache tag
|
58 |
+
$this->setCacheKey($uri);
|
59 |
+
}
|
60 |
+
catch (Zend_Http_Client_Exception $e) {
|
61 |
+
Mage::logException($e);
|
62 |
+
}
|
63 |
+
catch (Zend_Feed_Exception $e) {
|
64 |
+
Mage::logException($e);
|
65 |
+
}
|
66 |
+
return $this;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Sets the cache key
|
71 |
+
*
|
72 |
+
* The cache key is extended by the layout, template and locale.
|
73 |
+
*
|
74 |
+
* @param string $cacheKey
|
75 |
+
* @return Flagbit_FeedReader_Block_Abstract
|
76 |
+
*/
|
77 |
+
protected function setCacheKey($cacheKey)
|
78 |
+
{
|
79 |
+
$cacheKey = (string) $cacheKey;
|
80 |
+
|
81 |
+
$cacheKey .= ':' . Mage::getDesign()->getTheme('layout');
|
82 |
+
$cacheKey .= ':' . Mage::getDesign()->getTheme('template');
|
83 |
+
$cacheKey .= ':' . Mage::getDesign()->getTheme('locale');
|
84 |
+
|
85 |
+
return $this->setData('cache_key', $cacheKey);
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Sets the item count
|
90 |
+
*
|
91 |
+
* The item count defines how many feed items are displayed.
|
92 |
+
*
|
93 |
+
* @param int $itemCount The value is cast to int
|
94 |
+
* @return Flagbit_FeedReader_Block_Abstract
|
95 |
+
*/
|
96 |
+
public function setItemCount($itemCount)
|
97 |
+
{
|
98 |
+
$this->_itemCount = (int) $itemCount;
|
99 |
+
return $this;
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Returns the item count
|
104 |
+
*
|
105 |
+
* @return int
|
106 |
+
*/
|
107 |
+
public function getItemCount()
|
108 |
+
{
|
109 |
+
$itemCount = 0;
|
110 |
+
if (!is_null($this->_feed)) {
|
111 |
+
$itemCount = $this->_itemCount;
|
112 |
+
if ($this->_feed->count() < $itemCount) {
|
113 |
+
$itemCount = $this->_feed->count();
|
114 |
+
}
|
115 |
+
}
|
116 |
+
return $itemCount;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Returns the feed title
|
121 |
+
*
|
122 |
+
* If no feed is defined an empty string is returned.
|
123 |
+
*
|
124 |
+
* @return string
|
125 |
+
*/
|
126 |
+
public function getTitle()
|
127 |
+
{
|
128 |
+
$title = '';
|
129 |
+
if (!is_null($this->_title)) {
|
130 |
+
$title = $this->_title;
|
131 |
+
}
|
132 |
+
else if (!is_null($this->_feed)) {
|
133 |
+
$title = $this->_feed->title();
|
134 |
+
}
|
135 |
+
return $title;
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Sets the block's title
|
140 |
+
*
|
141 |
+
* This overrides the feed title.
|
142 |
+
*
|
143 |
+
* @param string $title
|
144 |
+
* @return Flagbit_FeedReader_Block_Abstract
|
145 |
+
*/
|
146 |
+
public function setTitle($title)
|
147 |
+
{
|
148 |
+
$this->_title = (string) $title;
|
149 |
+
return $this;
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Returns the feed items
|
154 |
+
*
|
155 |
+
* @return array
|
156 |
+
*/
|
157 |
+
public function getItems()
|
158 |
+
{
|
159 |
+
$return = array();
|
160 |
+
if (!is_null($this->_feed)) {
|
161 |
+
$itemCount = 0;
|
162 |
+
foreach ($this->_feed as $item) {
|
163 |
+
$return[] = $item;
|
164 |
+
if (++$itemCount >= $this->getItemCount()) {
|
165 |
+
break;
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
return $return;
|
170 |
+
}
|
171 |
+
}
|
app/code/community/Flagbit/FeedReader/Block/Sidebar.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* @category Flagbit
|
6 |
+
* @package Flagbit_FeedReader
|
7 |
+
* @copyright Copyright (c) 2010 Flagbit GmbH & Co. KG (http://www.flagbit.de)
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Feed reader sidebar
|
12 |
+
*
|
13 |
+
* @category Flagbit
|
14 |
+
* @package Flagbit_FeedReader
|
15 |
+
* @author David Fuhr <fuhr@flagbit.de>
|
16 |
+
*/
|
17 |
+
class Flagbit_FeedReader_Block_Sidebar extends Flagbit_FeedReader_Block_Abstract
|
18 |
+
{
|
19 |
+
/**
|
20 |
+
* The constructor
|
21 |
+
*
|
22 |
+
* @return Flagbit_FeedReader_Block_Sidebar
|
23 |
+
*/
|
24 |
+
public function __construct()
|
25 |
+
{
|
26 |
+
parent::__construct();
|
27 |
+
|
28 |
+
// set the template
|
29 |
+
$this->setTemplate('feedreader/sidebar.phtml');
|
30 |
+
}
|
31 |
+
}
|
app/code/community/Flagbit/FeedReader/etc/config.xml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Flagbit_FeedReader>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
<version>1.0.0</version>
|
8 |
+
</Flagbit_FeedReader>
|
9 |
+
</modules>
|
10 |
+
|
11 |
+
<global>
|
12 |
+
<blocks>
|
13 |
+
<feedreader>
|
14 |
+
<class>Flagbit_FeedReader_Block</class>
|
15 |
+
</feedreader>
|
16 |
+
</blocks>
|
17 |
+
</global>
|
18 |
+
|
19 |
+
<frontend>
|
20 |
+
<layout>
|
21 |
+
<updates>
|
22 |
+
<feedreader>
|
23 |
+
<file>feedreader.xml</file>
|
24 |
+
</feedreader>
|
25 |
+
</updates>
|
26 |
+
</layout>
|
27 |
+
</frontend>
|
28 |
+
</config>
|
app/design/frontend/base/default/layout/feedreader.xml
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<default>
|
4 |
+
<reference name="head">
|
5 |
+
<action method="addCss"><stylesheet>css/feedreader.css</stylesheet></action>
|
6 |
+
</reference>
|
7 |
+
<reference name="right">
|
8 |
+
<block type="feedreader/sidebar" name="left.feedreader" template="feedreader/sidebar.phtml">
|
9 |
+
<action method="setUri"><uri>http://rss.cnn.com/rss/edition.rss</uri></action>
|
10 |
+
<action method="setItemCount"><itemCount>4</itemCount></action>
|
11 |
+
</block>
|
12 |
+
</reference>
|
13 |
+
</default>
|
14 |
+
</layout>
|
app/design/frontend/base/default/template/feedreader/sidebar.phtml
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* @category design_default
|
6 |
+
* @package Flagbit_FeedReader
|
7 |
+
* @copyright Copyright (c) 2010 Flagbit GmbH & Co. KG (http://www.flagbit.de)
|
8 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
9 |
+
*/
|
10 |
+
?>
|
11 |
+
<?php if($this->getItemCount() > 0): ?>
|
12 |
+
<div class="block block-feed-reader">
|
13 |
+
<div class="block-title">
|
14 |
+
<strong><?php echo $this->htmlEscape($this->getTitle()); ?></strong>
|
15 |
+
</div>
|
16 |
+
<div class="block-content">
|
17 |
+
<ol id="feed-items">
|
18 |
+
<?php
|
19 |
+
$itemCount = 0;
|
20 |
+
foreach($this->getItems() as $item): ?>
|
21 |
+
<li class="block-feed-item <?php echo (++$itemCount % 2 == 0 ? 'even' : 'odd'); ?><?php if($itemCount == 1): ?> first<?php endif;?><?php if($itemCount >= $this->getItemCount()): ?> last<?php endif; ?>">
|
22 |
+
<h5>
|
23 |
+
<a href="<?php echo $this->htmlEscape($item->link()); ?>">
|
24 |
+
<?php echo $this->htmlEscape($item->title()); ?>
|
25 |
+
</a>
|
26 |
+
</h5>
|
27 |
+
<p class="date">
|
28 |
+
<?php echo $this->htmlEscape(date('d.m.Y H:m', strtotime($item->pubDate()))); ?>
|
29 |
+
</p>
|
30 |
+
<p class="summary">
|
31 |
+
<a href="<?php echo $this->htmlEscape($item->link()); ?>">
|
32 |
+
<?php echo $this->htmlEscape(Mage::helper('core/string')->truncate($item->description(), 80, '...', $remainder, false)); ?>
|
33 |
+
</a>
|
34 |
+
</p>
|
35 |
+
</li>
|
36 |
+
<?php endforeach; ?>
|
37 |
+
</ol>
|
38 |
+
</div>
|
39 |
+
</div>
|
40 |
+
<?php endif; ?>
|
app/etc/modules/Flagbit_FeedReader.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Flagbit_FeedReader>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Flagbit_FeedReader>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Flagbit_FeedReader</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL 3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>A simple feed reader supporting RSS and Atom feeds. Highly customizable and easy to integrate.</summary>
|
10 |
+
<description>A simple feed reader supporting RSS and Atom feeds. Highly customizable and easy to integrate.
|
11 |
+
|
12 |
+
Configuration is done in the default/layout/feedreader.xml. Simply reference the block where you want to create the feed. Feed URI and item count and template can be freely configured.</description>
|
13 |
+
<notes>- Initial release</notes>
|
14 |
+
<authors><author><name>David Fuhr</name><user>auto-converted</user><email>fuhr@flagbit.de</email></author></authors>
|
15 |
+
<date>2010-04-14</date>
|
16 |
+
<time>09:37:02</time>
|
17 |
+
<contents><target name="magecommunity"><dir name="Flagbit"><dir name="FeedReader"><dir name="Block"><file name="Abstract.php" hash="976c980694b2bc229b06810dd938fb1b"/><file name="Sidebar.php" hash="ea5b419e653db76daefabeebbd41ab3b"/></dir><dir name="etc"><file name="config.xml" hash="dd66389978451c6aad3faddb31703584"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Flagbit_FeedReader.xml" hash="302036c0fe8cc40a093ff3c8bd62b399"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="feedreader.css" hash="eb016f3f670214e6472230290c598372"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="feedreader.xml" hash="c5c3f1bf1e2414db5b73fd7328eed8d8"/></dir><dir name="template"><dir name="feedreader"><file name="sidebar.phtml" hash="bf664391777eadae9a6af2d9b6c207a9"/></dir></dir></dir></dir></dir></target></contents>
|
18 |
+
<compatible/>
|
19 |
+
<dependencies/>
|
20 |
+
</package>
|
skin/frontend/base/default/css/feedreader.css
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.block-feed-reader {
|
2 |
+
font-size: 11px;
|
3 |
+
line-height: 1.25;
|
4 |
+
}
|
5 |
+
.block-feed-reader li {
|
6 |
+
padding: 3px 9px;
|
7 |
+
}
|