-
Notifications
You must be signed in to change notification settings - Fork 3
/
extension.driver.php
199 lines (158 loc) · 5.39 KB
/
extension.driver.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
require_once(TOOLKIT . '/class.sectionmanager.php');
class Extension_MassUploadUtility extends Extension {
/*-------------------------------------------------------------------------
Definition:
-------------------------------------------------------------------------*/
public function uninstall() {
Symphony::Configuration()->remove('massuploadutility');
Symphony::Configuration()->write();
}
public function install() {
}
public function getSubscribedDelegates() {
return array(
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),
array(
'page' => '/system/preferences/',
'delegate' => 'CustomActions',
'callback' => 'savePreferences'
),
array(
'page' => '/backend/',
'delegate' => 'AdminPagePreGenerate',
'callback' => 'initaliseAdminPageHead'
),
array(
'page' => '/publish/new/',
'delegate' => 'EntryPostCreate',
'callback' => 'returnJSON'
),
);
}
// this only reaches here if an entry is created successfully, so we can avoid a redirect
public function returnJSON($context) {
if (isset($_REQUEST['MUUsource']) && isset($_POST['action']) && $_POST['action']['muu'] == true) {
$response['status'] = 'success';
echo(json_encode($response));
exit;
}
}
public function initaliseAdminPageHead($context) {
$page = $context['oPage'];
$assets_path = '/extensions/massuploadutility/assets/';
// to check if it's an excluded section
$section_id = SectionManager::fetchIDFromHandle($page->_context['section_handle']);
if ($page instanceof contentPublish and $page->_context['page'] == 'new' and
$this->validateSection($section_id) and $this->validateUser()) {
Administration::instance()->Page->addStylesheetToHead(URL . $assets_path . 'massuploadutility.css', 'screen', 14145);
Administration::instance()->Page->addScriptToHead(URL . $assets_path . 'massuploadutility.publish.js',14156);
Administration::instance()->Page->addScriptToHead(URL . $assets_path . 'jquery.html5_upload.js',14156);
}
}
/**
* I absolutely stole this next bit! Thank you craig zheng ([email protected]) :)
* via the Tracker extension
*/
public function appendPreferences($context){
include_once(TOOLKIT . '/class.authormanager.php');
include_once(TOOLKIT . '/class.sectionmanager.php');
// Fieldset and layout
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('Mass Upload Utility')));
$div = new XMLElement('div');
$div->setAttribute('class', 'group double');
// Excluded Sections
$label = Widget::Label(__('Excluded Sections'));
$options = array();
$sections = SectionManager::fetch();
$excluded_sections = explode(',', Symphony::Configuration()->get('excluded-sections', 'massuploadutility'));
if(!empty($sections) && is_array($sections)){
foreach($sections as $section) {
$selected = (in_array($section->get('id'), $excluded_sections) ? TRUE : FALSE);
$options[] = array(
$section->get('id'),
$selected,
$section->get('name')
);
}
}
$input = Widget::Select(
'settings[massuploadutility][excluded-sections][]',
$options,
array('multiple' => 'multiple')
);
$label->appendChild($input);
$div->appendChild($label);
// Excluded Users
$label = Widget::Label(__('Excluded Users'));
$options = array();
$am = new AuthorManager(Administration::instance());
$authors = $am->fetch();
$excluded_authors = explode(',',Symphony::Configuration()->get('excluded-users', 'massuploadutility'));
if(!empty($authors) && is_array($authors)){
foreach($authors as $author) {
$selected = (in_array($author->get('id'), $excluded_authors) ? TRUE : FALSE);
$options[] = array(
$author->get('id'),
$selected,
$author->getFullName()
);
}
}
$input = Widget::Select(
'settings[massuploadutility][excluded-users][]',
$options,
array('multiple' => 'multiple')
);
$label->appendChild($input);
$div->appendChild($label);
$group->appendChild($div);
$context['wrapper']->appendChild($group);
}
public function savePreferences() {
/**
* Remove existing configuration settings.
*/
Symphony::Configuration()->remove('massuploadutility');
Administration::instance()->saveConfig();
/**
* If there are MassUploadUtility settings, format them
*/
if(is_array($_POST['settings']['massuploadutility'])){
foreach($_POST['settings']['massuploadutility'] as $preference => $value){
if(is_array($value)){
$_POST['settings']['massuploadutility'][$preference] = implode(',',$value);
}
}
}
}
public function getExclusions($type) {
return explode(',', Symphony::Configuration()->get('excluded-' . $type, 'massuploadutility'));
}
public function validateSection($id) {
if(in_array($id, $this->getExclusions('sections'))) {
return FALSE;
}
else {
return TRUE;
}
}
public function validateUser($id = NULL) {
if(is_null($id)) {
$id = Symphony::Engine()->Author->get('id');
}
if(in_array($id, $this->getExclusions('users'))) {
return FALSE;
}
else {
return TRUE;
}
}
}
?>