-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modules.php
executable file
·110 lines (83 loc) · 3.55 KB
/
Modules.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
<?php namespace components\media; if(!defined('TX')) die('No direct access.');
class Modules extends \dependencies\BaseViews
{
protected
$default_permission = 2,
$permissions = array(
'image_uploader' => 0,
'image_upload_module' => 0,
'file_upload_module' => 0
);
protected function image_uploader($options)
{
//Create resulting settings
$valueset = Data();
//Insert a salt into the valueset
$valueset->salt = tx('Security')->random_string(20);
//See if we use auto uploading
$valueset->auto_upload->set($options->auto_upload->is_true());
//Set the max file size
$valueset->max_file_size->set($options->max_file_size->otherwise('10mb'));
//See if we're using the default html
$options->insert_html->is('set')
->success(function()use($options, $valueset){
//When using default html, generate the ID's
$valueset->use_default_html->set(true);
$valueset->ids->set(array(
'main' => $valueset->salt.'-container',
'header' => $valueset->salt.'-header',
'drop' => $valueset->salt.'-drop',
'filelist' => $valueset->salt.'-filelist',
'upload' => $valueset->salt.'-upload',
'browse' => $valueset->salt.'-browse'
));
$valueset->insert_html->set(array(
'header' => 'Upload images',
'drop' => 'Drop images here.',
'browse' => 'Browse',
'upload' => 'Upload'
));
$valueset->insert_html->merge($options->insert_html);
})
->failure(function()use($options, $valueset){
//If default html is not used a lot of ids should be defined.
$valueset->use_default_html->set(false);
$options->ids
->main->validate('$options->ids->main', array('required', 'string', 'no_html'))->back()
->filelist->validate('$options->ids->filelist', array('required', 'string', 'no_html'))->back()
->browse->validate('$options->ids->browse', array('required', 'string', 'no_html'))->back()
->is($valueset->auto_upload->is_false(), function($ids){
$ids->upload->validate('$options->ids->upload', array('required', 'string', 'no_html'))->back();
});
$options->ids->moveto($valueset->ids);
});
//Validate callbacks that have been provided
$options->callbacks->each(function($callback)use($valueset){
$callback->validate('$options->callbacks->'.$callback->key(), array('string', 'no_html', 'javascript_variable_name'))->back();
$callback->moveto($valueset->callbacks->{$callback->key()});
});
return $valueset;
}
protected function image_upload_module($options)
{
//Write to output buffer so it only gets included once.
tx('Ob')->script('media_image_upload_js');
//Plupload plugin.
echo load_plugin('plupload');
//The image upload script (section).
?><script type="text/javascript" src="<?php echo url('?section=media/image_upload_js',1); ?>"></script><?php
//End of output buffer section.
tx('Ob')->end();
}
protected function file_upload_module($options)
{
//Write to output buffer so it only gets included once.
tx('Ob')->script('media_file_upload_js');
//Plupload plugin.
echo load_plugin('plupload');
//The image upload script (section).
?><script type="text/javascript" src="<?php echo url('?section=media/file_upload_js',1); ?>"></script><?php
//End of output buffer section.
tx('Ob')->end();
}
}