forked from boboldehampsink/auditlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuditLogPlugin.php
131 lines (118 loc) · 2.69 KB
/
AuditLogPlugin.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
namespace Craft;
/**
* Audit Log Plugin.
*
* Allows you to log adding/updating/deleting of categories/entries/users.
*
* @author Bob Olde Hampsink <[email protected]>
* @copyright Copyright (c) 2015, Bob Olde Hampsink
* @license http://buildwithcraft.com/license Craft License Agreement
*
* @link http://github.com/boboldehampsink/auditlog
*/
class AuditLogPlugin extends BasePlugin
{
/**
* Return the plugin name.
*
* @return string
*/
public function getName()
{
return Craft::t('Audit Log');
}
/**
* Return the plugin version.
*
* @return string
*/
public function getVersion()
{
return '0.7.1';
}
/**
* Return the developer name.
*
* @return string
*/
public function getDeveloper()
{
return 'Bob Olde Hampsink';
}
/**
* Return the developer URL.
*
* @return string
*/
public function getDeveloperUrl()
{
return 'https://github.com/boboldehampsink';
}
/**
* Tell Craft we have a Control Panel section.
*
* @return bool
*/
public function hasCpSection()
{
return true;
}
/**
* Register routes for Control Panel.
*
* @return array
*/
public function registerCpRoutes()
{
return array(
'auditlog/(?P<logId>\d+)' => 'auditlog/_log',
);
}
/**
* Let the user decide what to log.
*
* @return array
*/
protected function defineSettings()
{
return array(
'enabled' => array(AttributeType::Mixed, 'default' => array(
ElementType::Entry,
ElementType::Category,
ElementType::User,
)),
);
}
/**
* Render the settings template.
*
* @return string
*/
public function getSettingsHtml()
{
return craft()->templates->render('auditlog/_settings', array(
'settings' => $this->getSettings(),
));
}
/**
* Log all specific element types that have the right events.
*/
public function init()
{
// Get settings
$settings = $this->getSettings();
// Log entries, when enabled
if (in_array(ElementType::Entry, $settings->enabled)) {
craft()->auditLog_entry->log();
}
// Log categories, when enabled
if (in_array(ElementType::Category, $settings->enabled)) {
craft()->auditLog_category->log();
}
// Log users, when enabled
if (in_array(ElementType::User, $settings->enabled)) {
craft()->auditLog_user->log();
}
}
}