forked from andrewminton/enhanced_upload_field
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.driver.php
63 lines (54 loc) · 1.85 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
<?php
require_once(TOOLKIT . '/class.alert.php');
class Extension_Enhanced_Upload_Field extends Extension {
const FIELD_TABLE = 'tbl_fields_enhanced_upload';
const FIELD_NAME = 'enhanced_upload';
public function getSubscribedDelegates() {
return array(
array(
'page' => '/backend/',
'delegate' => 'AdminPagePreGenerate',
'callback' => '__appendAssets'
),
);
}
public static function hasInstance($ext_name=NULL, $section_handle) {
$sid = SectionManager::fetchIDFromHandle($section_handle);
$section = SectionManager::fetch($sid);
$fm = $section->fetchFields($ext_name);
return is_array($fm) && !empty($fm);
}
/**
* append 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') {
if (self::hasInstance('enhanced_upload', $callback['context']['section_handle'])) {
Administration::instance()->Page->addScriptToHead(URL . '/extensions/enhanced_upload_field/assets/script.enhanced_upload_field.js', 80, false);
}
}
}
public function uninstall() {
return Symphony::Database()->query(sprintf(
"DROP TABLE IF EXISTS `%s`",
self::FIELD_TABLE
));
}
public function install(){
return Symphony::Database()->query(sprintf(
"CREATE TABLE `%s` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`destination` varchar(255) NOT NULL,
`override` enum('yes','no') default 'yes',
`validator` varchar(50),
`unique` enum('yes','no') default 'yes',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;",
self::FIELD_TABLE
));
}
}