-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeedAnnotation.php
114 lines (104 loc) · 2.62 KB
/
FeedAnnotation.php
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
<?php
/**
* Piwik - Open source web analytics
*
* @link http://github.com/halfdan/piwik-feedannotation-plugin
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package Piwik_FeedAnnotation
*/
namespace Piwik\Plugins\FeedAnnotation;
use Piwik\Common;
use Piwik\Piwik;
use Piwik\Plugin;
/**
*
* @package Piwik_FeedAnnotation
*/
class FeedAnnotation extends Plugin
{
/**
* Create required FeedAnnotation database table
*
* @throws \Exception
*/
public function install() {
$tableFeedAnnotation = "CREATE TABLE " . Common::prefixTable("feedannotation") . " (
idfeed INT NOT NULL AUTO_INCREMENT,
idsite INT(11) NOT NULL,
feed_url VARCHAR(200) NOT NULL,
last_processed DATETIME,
PRIMARY KEY (idfeed)
) DEFAULT CHARSET=utf8;";
try {
\Piwik\Db::Exec($tableFeedAnnotation);
} catch (\Exception $e) {
// mysql code error 1050:table already exists
// see bug #153 http://dev.piwik.org/trac/ticket/153
if (!\Zend_Registry::get('db')->isErrNo($e, '1050')) {
throw $e;
}
}
}
/**
* Return the registered hooks
*
* @return array
*/
public function getListHooksRegistered()
{
return array(
'Menu.Admin.addItems' => 'addAdminMenu',
'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'AssetManager.getJavaScriptFiles' => 'getJsFiles'
);
}
/**
* Add new "Feed Annotations" admin menu.
*/
public function addAdminMenu() {
Piwik_AddAdminSubMenu('General_Settings', 'FeedAnnotation_MenuGeneralSettings',
array('module' => 'FeedAnnotation', 'action' => 'index'),
Piwik::isUserHasSomeAdminAccess(),
$order = 10);
}
/**
* Add feedannotation.js
* for the AssetManager.
*/
public function getJsFiles(&$jsFiles)
{
$jsFiles[] = "plugins/FeedAnnotation/templates/feedannotation.js";
}
/**
* Gets all scheduled tasks executed by this plugin.
*
* @param \EventNotification $notification notification object
*/
public function getScheduledTasks($notification)
{
$tasks = &$notification->getNotificationObject();
$updateFeedAnnotationsTask = new \Piwik\ScheduledTask(
$this,
'updateFeedAnnotations',
null,
new \Piwik\ScheduledTime\Daily()
);
$tasks[] = $updateFeedAnnotationsTask;
}
/**
* Fetches configured feeds and creates/updates Annotations.
*/
public function updateFeedAnnotations() {
$feeds = API::getInstance()->getFeeds();
foreach($feeds as $feed) {
$processor = new FeedProcessor($feed);
try {
$processor->processFeed();
} catch (\Zend_Feed_Exception $ex) {
\Piwik\Registry::get('logger_exception')->logEvent( $ex );
}
}
}
}