|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Craft; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Audit Log Plugin. |
|
7
|
|
|
* |
|
8
|
|
|
* Allows you to log adding/updating/deleting of categories/entries/users. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Bob Olde Hampsink <[email protected]> |
|
11
|
|
|
* @copyright Copyright (c) 2015, Bob Olde Hampsink |
|
12
|
|
|
* @license http://buildwithcraft.com/license Craft License Agreement |
|
13
|
|
|
* |
|
14
|
|
|
* @link http://github.com/boboldehampsink/auditlog |
|
15
|
|
|
*/ |
|
16
|
|
|
class AuditLogPlugin extends BasePlugin |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Return the plugin name. |
|
20
|
|
|
* |
|
21
|
|
|
* @return string |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getName() |
|
24
|
|
|
{ |
|
25
|
|
|
return Craft::t('Audit Log'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Return the plugin version. |
|
30
|
|
|
* |
|
31
|
|
|
* @return string |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getVersion() |
|
34
|
|
|
{ |
|
35
|
|
|
return '0.7.0'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Return the developer name. |
|
40
|
|
|
* |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getDeveloper() |
|
44
|
|
|
{ |
|
45
|
|
|
return 'Bob Olde Hampsink'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Return the developer URL. |
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getDeveloperUrl() |
|
54
|
|
|
{ |
|
55
|
|
|
return 'https://github.com/boboldehampsink'; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Tell Craft we have a Control Panel section. |
|
60
|
|
|
* |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
63
|
|
|
public function hasCpSection() |
|
64
|
|
|
{ |
|
65
|
|
|
return true; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Register routes for Control Panel. |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
public function registerCpRoutes() |
|
74
|
|
|
{ |
|
75
|
|
|
return array( |
|
76
|
|
|
'auditlog/(?P<logId>\d+)' => 'auditlog/_log', |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Let the user decide what to log. |
|
82
|
|
|
* |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function defineSettings() |
|
86
|
|
|
{ |
|
87
|
|
|
return array( |
|
88
|
|
|
'enabled' => array(AttributeType::Mixed, 'default' => array( |
|
89
|
|
|
ElementType::Entry, |
|
90
|
|
|
ElementType::Category, |
|
91
|
|
|
ElementType::User, |
|
92
|
|
|
)), |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Render the settings template. |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getSettingsHtml() |
|
102
|
|
|
{ |
|
103
|
|
|
return craft()->templates->render('auditlog/_settings', array( |
|
104
|
|
|
'settings' => $this->getSettings(), |
|
105
|
|
|
)); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Log all specific element types that have the right events. |
|
110
|
|
|
*/ |
|
111
|
|
|
public function init() |
|
112
|
|
|
{ |
|
113
|
|
|
// Get settings |
|
114
|
|
|
$settings = $this->getSettings(); |
|
115
|
|
|
|
|
116
|
|
|
// Log entries, when enabled |
|
117
|
|
|
if (in_array(ElementType::Entry, $settings->enabled)) { |
|
118
|
|
|
craft()->auditLog_entry->log(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
// Log categories, when enabled |
|
122
|
|
|
if (in_array(ElementType::Category, $settings->enabled)) { |
|
123
|
|
|
craft()->auditLog_category->log(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
// Log users, when enabled |
|
127
|
|
|
if (in_array(ElementType::User, $settings->enabled)) { |
|
128
|
|
|
craft()->auditLog_user->log(); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|