1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package Piwik_ExampleRssWidget
*/
/**
*
* @package Piwik_ExampleRssWidget
*/
class Piwik_ExampleRssWidget extends Piwik_Plugin
{
/**
* Return information about this plugin.
*
* @see Piwik_Plugin
*
* @return array
*/
public function getInformation()
{
return array(
'description' => Piwik_Translate('ExampleRssWidget_PluginDescription'),
'author' => 'Piwik',
'author_homepage' => 'http://piwik.org/',
'version' => '0.1',
);
}
public function getListHooksRegistered()
{
return array(
'AssetManager.getCssFiles' => 'getCssFiles',
'WidgetsList.add' => 'addWidgets'
);
}
/**
* @param Piwik_Event_Notification $notification notification object
*/
function getCssFiles( $notification )
{
$cssFiles = &$notification->getNotificationObject();
$cssFiles[] = "plugins/ExampleRssWidget/templates/styles.css";
}
public function addWidgets()
{
Piwik_AddWidget('Example Widgets', 'Piwik.org Blog', 'ExampleRssWidget', 'rssPiwik');
Piwik_AddWidget('Example Widgets', 'Piwik Changelog', 'ExampleRssWidget', 'rssChangelog');
}
}
/**
*
* @package Piwik_ExampleRssWidget
*/
class Piwik_ExampleRssWidget_Controller extends Piwik_Controller
{
function rssPiwik()
{
try {
$rss = new Piwik_ExampleRssWidget_Rss('http://feeds.feedburner.com/Piwik');
$rss->showDescription(true);
echo $rss->get();
} catch(Exception $e) {
$this->error($e);
}
}
function rssChangelog()
{
try {
$rss = new Piwik_ExampleRssWidget_Rss('http://feeds.feedburner.com/PiwikReleases');
$rss->setCountPosts(1);
$rss->showDescription(false);
$rss->showContent(true);
echo $rss->get();
} catch(Exception $e) {
$this->error($e);
}
}
protected function error($e)
{
echo '<div class="pk-emptyDataTable">'
. Piwik_Translate('General_ErrorRequest')
. ' - ' . $e->getMessage() . '</div>';
}
}
/**
*
* @package Piwik_ExampleRssWidget
*/
class Piwik_ExampleRssWidget_Rss
{
protected $url = null;
protected $count = 3;
protected $showDescription = false;
protected $showContent = false;
function __construct($url)
{
$this->url = $url;
}
function showDescription($bool)
{
$this->showDescription = $bool;
}
function showContent($bool)
{
$this->showContent = $bool;
}
function setCountPosts($count)
{
$this->count = $count;
}
function get()
{
try {
$rss = Zend_Feed::import($this->url);
} catch (Zend_Feed_Exception $e) {
echo "Error while importing feed: {$e->getMessage()}\n";
exit;
}
$output = '<div style="padding:10px 15px;"><ul class="rss">';
$i = 0;
foreach($rss as $post)
{
$title = $post->title();
$date = @strftime("%B %e, %Y", strtotime($post->pubDate()));
$link = $post->link();
$output .= '<li><a class="rss-title" title="" target="_blank" href="?module=Proxy&action=redirect&url='.$link.'">'.$title.'</a>'.
'<span class="rss-date">'.$date.'</span>';
if($this->showDescription)
{
$output .= '<div class="rss-description">'.$post->description().'</div>';
}
if($this->showContent)
{
$output .= '<div class="rss-content">'.$post->content().'</div>';
}
$output .= '</li>';
if(++$i == $this->count) break;
}
$output .= '</ul></div>';
return $output;
}
}
|