-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoo.php
131 lines (110 loc) · 3.81 KB
/
zoo.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
<?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
*/
/**
* Zoo LOGman Plugin.
*
* Provides event handlers for dealing with com_zoo events.
*
* @author Arunas Mazeika <https://github.com/amazeika>
* @package Joomlatools\Plugin\LOGman
*/
class PlgLogmanZoo extends ComLogmanPluginJoomla
{
protected function _initialize(KObjectConfig $config)
{
$config->append(array('resources' => array('category', 'item', 'comment')));
parent::_initialize($config);
}
protected function _getItemObjectData($data, $event)
{
return array(
'id' => $data->id,
'name' => $data->name,
'metadata' => array('type' => $data->type, 'application' => $data->application_id)
);
}
protected function _getCategoryObjectData($data, $event)
{
$object = array(
'id' => $data->id,
'name' => $data->name,
'metadata' => array('application' => array('id' => $data->application_id))
);
$config = new KObjectConfig(array('type' => 'Application'));
$items = $this->_getItems($data->application_id, $config);
$item = current($items);
if ($item) {
$object['metadata']['application']['type'] = $item->application_group;
}
return $object;
}
protected function _getCommentObjectData($data, $event)
{
$object = array(
'id' => $data->id,
'name' => 'comment',
'metadata' => array(
'author' => array(
'name' => $data->author,
'id' => $data->user_id,
'type' => $data->user_type,
'email' => $data->email,
'url' => $data->url,
),
'item' => array('id' => $data->item_id)
)
);
$config = new KObjectConfig(array('type' => 'Item'));
$items = $this->_getItems($data->item_id, $config);
$item = current($items);
// Store the item's application id.
if ($item) {
$object['metadata']['item']['application'] = $item->application_id;
$object['metadata']['item']['type'] = $item->type;
}
return $object;
}
public function onFinderAfterSave($context, $item, $isNew)
{
$this->onContentAfterSave($context, $item, $isNew); // Forward event.
}
public function onContentAfterSave($context, $content, $isNew)
{
$tasks = array('publish', 'unpublish', 'spam', 'approve', 'unapprove');
// Bypass save events that originate on some actions.
if (!in_array($this->getObject('request')->getData()->task, $tasks)) {
parent::onContentAfterSave($context, $content, $isNew);
}
}
public function onFinderAfterDelete($context, $item)
{
$this->onContentAfterDelete($context, $item); // Forward event.
}
protected function _getItems($ids, KObjectConfig $config)
{
$config->append(array('type' => $this->_name));
$items = array();
$class = ucfirst($config->type) . 'Table';
$path = sprintf('%s/tables/%s.php', JPATH_COMPONENT_ADMINISTRATOR, strtolower($config->type));
if (file_exists($path)) {
require_once $path;
}
if (class_exists($class))
{
$table = new $class(App::getInstance('zoo'));
$ids = (array) $ids;
foreach ($ids as $id)
{
if ($item = $table->get($id)) {
$items[] = $item;
}
}
}
return $items;
}
}