-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkomento.php
162 lines (143 loc) · 4.6 KB
/
komento.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
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
158
159
160
161
162
<?php
/**
* @package LOGman
* @copyright Copyright (C) 2011 - 2016 Timble CVBA. (http://www.timble.net)
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link http://www.joomlatools.com
*/
/**
* Komento LOGman Plugin.
*
* Provides handlers for dealing with Komento events.
*
* @author Arunas Mazeika <https://github.com/amazeika>
* @package Joomlatools\Plugin\LOGman
*/
class PlgLogmanKomento extends ComLogmanPluginLogger
{
/**
* Keeps track of triggered events.
*
* @var array
*/
protected $_triggered_events = array('publish' => array(), 'unpublish' => array(), 'delete' => array());
/**
* Overridden to handle Komento events only.
*/
public function update(&$args)
{
$result = null;
if (isset($args[2]))
{
$comment = $args[2];
if (is_array($comment)) {
$comment = current($comment);
}
if ($comment instanceof KomentoComment) {
$result = parent::update($args);
}
}
return $result;
}
/**
* After save event handler.
*
* @param $component The comment component.
* @param $cid The component resource ID.
* @param $comment The comment object.
*/
public function onAfterSaveComment($component, $cid, $comment)
{
$comment = current($comment);
$this->log(array(
'object' => array(
'package' => 'komento',
'type' => 'comment',
'id' => $comment->id,
'name' => $comment->name,
'metadata' => array('component' => $component, 'cid' => $cid)
),
'result' => 'saved',
'verb' => 'save',
'actor' => $comment->created_by
));
}
/**
* After delete event handler.
*
* @param $component The comment component.
* @param $cid The component resource ID.
* @param $comment The comment object.
*/
public function onAfterDeleteComment($component, $cid, $comment)
{
$comment = current($comment);
if (!in_array($comment->id, $this->_triggered_events['delete']))
{
$this->log(array(
'object' => array(
'package' => 'komento',
'type' => 'comment',
'id' => $comment->id,
'name' => $comment->name,
'metadata' => array('component' => $component, 'cid' => $cid)
),
'result' => 'deleted',
'verb' => 'delete',
));
$this->_triggered_events['delete'][] = $comment->id;
}
}
/**
* After publish event handler.
*
* @param $component The comment component.
* @param $cid The component resource ID.
* @param $comment The comment object.
*/
public function onAfterPublishComment($component, $cid, $comment)
{
$comment = current($comment);
if (!in_array($comment->id, $this->_triggered_events['publish']))
{
$this->log(array(
'object' => array(
'package' => 'komento',
'type' => 'comment',
'id' => $comment->id,
'name' => $comment->name,
'metadata' => array('component' => $component, 'cid' => $cid)
),
'result' => 'published',
'verb' => 'publish'
));
$this->_triggered_events['published'][] = $comment->id;
}
}
/**
* After un-publish event handler.
*
* @param $component The comment component.
* @param $cid The component resource ID.
* @param $comment The comment object.
*/
public function onAfterUnpublishComment($component, $cid, $comment)
{
$comment = current($comment);
if (!in_array($comment->id, $this->_triggered_events['unpublish']))
{
$this->log(array(
'object' => array(
'package' => 'komento',
'type' => 'comment',
'id' => $comment->id,
'name' => $comment->name,
'metadata' => array('component' => $component, 'cid' => $cid)
),
'result' => 'unpublished',
'verb' => 'unpublish',
));
$this->_triggered_events['unpublish'][] = $comment->id;
}
}
}