forked from symphonists/s3upload_field
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.driver.php
125 lines (99 loc) · 4.05 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
<?php
require_once(TOOLKIT . '/class.entrymanager.php');
require_once(EXTENSIONS .'/s3upload_field/lib/S3.php');
Class extension_s3upload_field extends Extension {
public function about() {
return array(
'name' => 'Field: Amazon S3 File Upload',
'version' => '0.6.6',
'release-date' => '2011-11-26',
'author' => array(
array(
'name' => 'Scott Tesoriere',
'website' => 'http://tesoriere.com',
'email' => '[email protected]'
),
array(
'name' => 'Andrew Shooner and Brian Zerangue',
'website' => 'http://andrewshooner.com',
'email' => '[email protected]'
),
),
'description' => 'Upload files to Amazon S3. Based on Brian Zerangue\'s version, based on Michael E\'s upload field.'
);
}
public function getSubscribedDelegates(){
return array(
array(
'page' => '/system/preferences/',
'delegate' => 'CustomActions',
'callback' => 'savePreferences'
),
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),
);
}
public function appendPreferences($context){
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', 'Amazon S3 Security Credentials'));
$div = new XMLElement('div', NULL, array('class' => 'group'));
$label = Widget::Label('Access Key ID');
$label->appendChild(Widget::Input('settings[s3upload_field][access-key-id]', General::Sanitize($this->getAmazonS3AccessKeyId())));
$div->appendChild($label);
$label = Widget::Label('Secret Access Key');
$label->appendChild(Widget::Input('settings[s3upload_field][secret-access-key]', General::Sanitize($this->getAmazonS3SecretAccessKey()), 'password'));
$div->appendChild($label);
$group->appendChild($div);
$group->appendChild(new XMLElement('p', 'Get a Access Key ID and Secret Access Key from the <a href="http://aws.amazon.com">Amazon Web Services site</a>.', array('class' => 'help')));
$label = Widget::Label('Default cache expiry time (in seconds)');
$label->appendChild(Widget::Input('settings[s3upload_field][cache-control]', General::Sanitize($this->getCacheControl())));
$group->appendChild($label);
$context['wrapper']->appendChild($group);
}
public function uninstall() {
Symphony::Database()->query("DROP TABLE `tbl_fields_s3upload`");
Symphony::Configuration()->remove('s3upload_field');
Administration::instance()->saveConfig();
}
public function install() {
return Symphony::Database()->query("CREATE TABLE `tbl_fields_s3upload` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`bucket` varchar(255) NOT NULL,
`cname` varchar(255),
`remove_from_bucket` tinyint(1) DEFAULT '1',
`unique_filename` tinyint(1) DEFAULT '1',
`ssl_option` tinyint(1) DEFAULT '0',
`validator` varchar(50),
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`))"
);
}
public function update($previousVersion) {
if(version_compare($previousVersion, '0.6.4', '<')) {
// Add new row:
Symphony::Database()->query(
"ALTER TABLE `tbl_fields_s3upload` ADD `unique_filename` tinyint(1) DEFAULT '1'"
);
Symphony::Database()->query(
"ALTER TABLE `tbl_fields_s3upload` ADD `ssl_option` tinyint(1) DEFAULT '0'"
);
}
}
public function getCacheControl() {
$val = Symphony::Configuration()->get('cache-control', 's3upload_field');
if (!preg_match('/^[\d]+$/', $val) && $val != '') return '864000';
elseif ($val == '') return false;
else return $val;
}
public function getAmazonS3AccessKeyId(){
return Symphony::Configuration()->get('access-key-id', 's3upload_field');
}
public function getAmazonS3SecretAccessKey(){
return Symphony::Configuration()->get('secret-access-key', 's3upload_field');
}
}