-
Notifications
You must be signed in to change notification settings - Fork 11
/
extension.driver.php
207 lines (181 loc) · 8.08 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
200
201
202
203
204
205
206
207
<?php
/**
* @package filemanager
* @author thomas appel <[email protected]>
* Displays <a href="http://opensource.org/licenses/gpl-3.0.html">GNU Public License</a>
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
*/
require_once(TOOLKIT . '/class.alert.php');
cLass extension_filemanager extends Extension
{
public function getSubscribedDelegates()
{
return array(
// Subsection Manager
array(
'page' => '/backend/',
'delegate' => 'AdminPagePreGenerate',
'callback' => '__appendAssets'
),
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => '__appendPreferences'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'save'
),
array(
'page' => '/backend/',
'delegate' => 'AppendPageAlert',
'callback' => '__checkDependencies'
),
);
}
/**
* TODO: Fix error catching
*/
public function uninstall()
{
/* Drop configuration array */
Symphony::Configuration()->remove('filemanager');
Symphony::Configuration()->write();
/* Drop database tables */
try {
Symphony::Database()->query("DROP TABLE `tbl_fields_filemanager`");
} catch (DatabaseException $db_err) {
}
return true;
}
public function install()
{
if (!Symphony::Configuration()->get('filemanager')) {
Symphony::Configuration()->set('mimetypes', 'application/pdf image/jpeg image/png text/*', 'filemanager');
Symphony::Configuration()->set('ignore', base64_encode('^\..*'), 'filemanager');
Symphony::Configuration()->write();
}
Symphony::Configuration()->write();
Symphony::Database()->query(
"CREATE TABLE IF NOT EXISTS `tbl_fields_filemanager` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`destination` varchar(255) NOT NULL,
`exclude_dirs` varchar(8000) default NULL,
`ignore_files` varchar(255),
`limit_files` int(11) default NULL,
`allow_file_delete` tinyint(1) default '0',
`allow_file_search` tinyint(1) default '1',
`allow_sort_selected` tinyint(1) default '0',
`select_uploaded_files` tinyint(1) default '0',
`unique_file_name` tinyint(1) default '0',
`allow_file_move` tinyint(1) default '0',
`allow_dir_delete` tinyint(1) default '0',
`allow_dir_move` tinyint(1) default '0',
`allow_dir_create` tinyint(1) default '0',
`allow_dir_upload_files` tinyint(1) default '0',
`allowed_types` varchar(255),
`display_mode` varchar(255),
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"
);
return true;
}
public static function hasInstance($ext_name=NULL, $section_handle)
{
if (!$sid = SectionManager::fetchIDFromHandle($section_handle)) {
return;
}
$section = SectionManager::fetch($sid);
$fm = $section->fetchFields($ext_name);
return is_array($fm) && !empty($fm);
}
/**
* apend needed css an js files to the document head
*/
public function __appendAssets($context)
{
$callback = Symphony::Engine()->getPageCallback();
// Append styles for publish area
if ($callback['driver'] === 'publish' && $callback['context']['page'] !== 'index' &&
isset($callback['context']['section_handle']) && !empty($callback['context']['section_handle'])
) {
if (self::hasInstance('filemanager', $callback['context']['section_handle'])) {
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/filemanager/assets/css/filemanager.publish.css', 'screen', 100, false);
Administration::instance()->Page->addScriptToHead(URL . '/extensions/filemanager/assets/js/filemanager.init.js', 400, false);
}
}
}
/**
* set fields for preference page
*/
public function __appendPreferences(&$context)
{
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', 'Filemanager'));
$label = Widget::Label(__('Default MIME types'));
$label->appendChild(
Widget::Input(
'settings[filemanager][mimetypes]',
General::Sanitize(Symphony::Configuration()->get('mimetypes', 'filemanager'))
)
);
$help = new XMLElement('p', __('Define the default mimetypes separated be a whitespace character that should be allowed for uploading. <br/> You can use wildcards as well, e.g. <code>text/*</code> will allow all text based mimetypes. Use a single <code>*</code> to allow all types of files (not recomended).'), array('class' => 'help'));
$ca = array();
array_push($ca, $label, $help);
$group->appendChildArray($ca);
$label = Widget::Label(__('Ignore files'));
$label->appendChild(
Widget::Input(
'settings[filemanager][ignore]',
//General::Sanitize(Symphony::Configuration()->get('ignore', 'filemanager'))
base64_decode(Symphony::Configuration()->get('ignore', 'filemanager'))
)
);
$help = new XMLElement('p', __('<code>RegExp:</code> Define which files should be ignored by the directory listing (default: ignores all dot-files <code>^\..*</code>. Separate expressions with a whitespace)'), array('class' => 'help'));
$ca = array();
array_push($ca, $label, $help);
$group->appendChildArray($ca);
$context['wrapper']->appendChild($group);
}
public function save(&$context)
{
if (!empty($context['settings']['filemanager']['ignore'])) {
$context['settings']['filemanager']['ignore'] = base64_encode($context['settings']['filemanager']['ignore']);
}
}
/**
* @see http://symphony-cms.com/learn/api/2.2/toolkit/extension/#update
*/
public function update($previousVersion)
{
$beta_dev = preg_match('/^\w+\s?/i', $previousVersion);
$previousVersion = preg_replace('/^\w+\s?/i', '', $previousVersion);
if ($beta_dev && version_compare($previousVersion, '1.2', '<')) {
// sanitatize broken ignore regexp form beta 1.1 release
$ignore = base64_decode(Symphony::Configuration()->get('ignore','filemanager'));
$ignore = preg_replace('/(\/i?|\(|\))/i', '', $ignore);
Symphony::Configuration()->set('ignore', base64_encode($ignore), 'filemanager');
Symphony::Configuration()->write();
}
if (version_compare($previousVersion, '.0.5', '<')) {
Symphony::Database()->query("ALTER TABLE `tbl_fields_filemanager` ADD COLUMN `allow_file_search` tinyint(1) default '1'");
}
}
/**
* Append a system alert if dependencies are not isntalled
*/
public function __checkDependencies(&$context)
{
$bb_path = EXTENSIONS . '/sym_backbonejs/assets/backbone.js';
if (!class_exists('extension_sym_requirejs')) {
Symphony::Engine()->Page->Alert[] = new Alert(__('Filemanager requires requirejs. Please make sure the extension <a href="https://github.com/iwyg/sym_requirejs">sym_requirejs</a> is installed'), Alert::ERROR);
}
if (!is_file($bb_path)) {
Symphony::Engine()->Page->Alert[] = new Alert(__('Filemanager requires backbonejs Please make sure extension <a href="https://github.com/iwyg/sym_backbonejs">sym_backbonejs</a> is available'), Alert::ERROR);
}
}
}