This repository was archived by the owner on Oct 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMillcoBrowser.module.php
More file actions
executable file
·505 lines (388 loc) · 14.7 KB
/
MillcoBrowser.module.php
File metadata and controls
executable file
·505 lines (388 loc) · 14.7 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<?php
/*
#-------------------------------------------------------------------------
# Module: MillcoBrowser
# Version: 1.0
# //stephen 150903
#-------------------------------------------------------------------------
*/
// ini_set('error_reporting', E_ERROR);
class MillcoBrowser extends CMSModule
{
function GetName()
{
return 'MillcoBrowser';
}
/*---------------------------------------------------------
GetFriendlyName()
---------------------------------------------------------*/
function GetFriendlyName()
{
return 'MillcoBrowser';
}
/*---------------------------------------------------------
GetVersion()
---------------------------------------------------------*/
function GetVersion()
{
return '1.0';
}
/*---------------------------------------------------------
GetHelp()
This returns HTML information on the module.
Typically, you'll want to include information on how to
use the module.
See the note on localization at the top of this file.
---------------------------------------------------------*/
function GetHelp()
{
return $this->Lang('help');
}
function GetAuthor()
{
return 'stephen at millipedia';
}
/*---------------------------------------------------------
GetAuthorEmail()
---------------------------------------------------------*/
function GetAuthorEmail()
{
return 'stephen@millipedia.co.uk';
}
/*---------------------------------------------------------
GetChangeLog()
This returns a string that is presented in the module
Admin if you click on the About link. It helps users
figure out what's changed between releases.
See the note on localization at the top of this file.
---------------------------------------------------------*/
function GetChangeLog()
{
return $this->Lang('changelog');
}
/*---------------------------------------------------------
IsPluginModule()
This function returns true or false, depending upon
whether users can include the module in a page or
template using a smarty tag of the form
{cms_module module='MillcoBrowser' param1=val param2=val...}
If your module does not get included in pages or
templates, return "false" here.
---------------------------------------------------------*/
function IsPluginModule()
{
return true;
}
/*---------------------------------------------------------
HasAdmin()
This function returns a boolean value, depending on
whether your module adds anything to the Admin area of
the site. For the rest of these comments, I'll be calling
the admin part of your module the "Admin Panel" for
want of a better term.
---------------------------------------------------------*/
function HasAdmin()
{
return false;
}
/*---------------------------------------------------------
GetAdminSection()
If your module has an Admin Panel, you can specify
which Admin Section (or top-level Admin Menu) it shows
up in. This method returns a string to specify that
section. Valid return values are:
main - the Main menu tab.
content - the Content menu
layout - the Layout menu
usersgroups - the Users and Groups menu
extensions - the Extensions menu (this is the default)
siteadmin - the Site Admin menu
viewsite - the View Site menu tab
logout - the Logout menu tab
Note that if you place your module in the main,
viewsite, or logout sections, it will show up in the
menus, but will not be visible in any top-level
section pages.
---------------------------------------------------------*/
function GetAdminSection()
{
return 'extensions';
}
/*---------------------------------------------------------
GetAdminDescription()
If your module does have an Admin Panel, you
can have it return a description string that gets shown
in the Admin Section page that contains the module.
See the note on localization at the top of this file.
---------------------------------------------------------*/
function GetAdminDescription()
{
return $this->Lang('moddescription');
}
/*---------------------------------------------------------
VisibleToAdminUser()
If your module does have an Admin Panel, you
can control whether or not it's displayed by the boolean
that is returned by this method. This is primarily used
to hide modules from admins who lack permission to use
them.
In this case, the module will only be visible to admins
who have "Use MillcoBrowser" permissions.
---------------------------------------------------------*/
function VisibleToAdminUser()
{
return $this->CheckPermission('Use MillcoBrowser');
}
/*---------------------------------------------------------
GetDependencies()
Your module may need another module to already be installed
before you can install it.
This method returns a list of those dependencies and
minimum version numbers that this module requires.
It should return an hash, eg.
return array('somemodule'=>'1.0', 'othermodule'=>'1.1');
---------------------------------------------------------*/
function GetDependencies()
{
return array();
}
/*---------------------------------------------------------
MinimumCMSVersion()
Your module may require functions or objects from
a specific version of CMS Made Simple.
Ever since version 0.11, you can specify which minimum
CMS MS version is required for your module, which will
prevent it from being installed by a version of CMS that
can't run it.
This method returns a string representing the
minimum version that this module requires.
---------------------------------------------------------*/
function MinimumCMSVersion()
{
return "1.12";
}
/*---------------------------------------------------------
SetParameters()
This function enables you to create mappings for
your module when using "Pretty Urls".
Typically, modules create internal links that have
big ugly strings along the lines of:
index.php?mact=ModName,cntnt01,actionName,0&cntnt01param1=1&cntnt01param2=2&cntnt01returnid=3
You might prefer these to look like:
/ModuleFunction/2/3
To do this, you have to register routes and map
your parameters in a way that the API will be able
to understand.
Also note that any calls to CreateLink will need to
be updated to pass the pretty url parameter.
Since the MillcoBrowser doesn't really create any links,
the section below is commented out, but you can
use it to figure out pretty urls.
---------------------------------------------------------*/
function SetParameters()
{
// $this->RegisterModulePlugin();
// Don't allow parameters other than the ones you've explicitly defined
$this->RestrictUnknownParams();
// syntax for creating a parameter is parameter name, default value, description
$this->CreateParameter('fieldID', '', ' ');
$this->SetParameterType('fieldID',CLEAN_STRING);
$this->SetParameterType('block_name', CLEAN_STRING);
$this->CreateParameter('folder', '', ' ');
$this->SetParameterType('folder', CLEAN_STRING);
$this->CreateParameter('file_type', '', $this->Lang('param_file_type'));
$this->SetParameterType('file_type', CLEAN_STRING);
// $this->AddEventHandler( 'Core', 'ContentPostRender', true );
}
/*---------------------------------------------------------
GetEventDescription()
If your module can create events, you will need
to provide the API with documentation of what
that event does. This method wraps up a simple
return of the localized description.
---------------------------------------------------------*/
function GetEventDescription ( $eventname )
{
return $this->Lang('event_info_'.$eventname );
}
/*---------------------------------------------------------
GetEventHelp()
If your module can create events, you will need
to provide the API with documentation of how to
use the event. This method wraps up a simple
return of the localized description.
---------------------------------------------------------*/
function GetEventHelp ( $eventname )
{
return $this->Lang('event_help_'.$eventname );
}
/*---------------------------------------------------------
InstallPostMessage()
After installation, there may be things you want to
communicate to your admin. This function returns a
string which will be displayed.
See the note on localization at the top of this file.
---------------------------------------------------------*/
function InstallPostMessage()
{
return $this->Lang('postinstall');
}
/*---------------------------------------------------------
UninstallPostMessage()
After removing a module, there may be things you want to
communicate to your admin. This function returns a
string which will be displayed.
See the note on localization at the top of this file.
---------------------------------------------------------*/
function UninstallPostMessage()
{
return $this->Lang('postuninstall');
}
/**
* UninstallPreMessage()
* This allows you to display a message along with a Yes/No dialog box. If the user responds
* in the affirmative to your message, the uninstall will proceed. If they respond in the
* negative, the uninstall will be canceled. Thus, your message should be of the form
* "All module data will be deleted. Are you sure you want to uninstall this module?"
*
* If you don't want the dialog, have this method return a FALSE, which will cause the
* module to uninstall immediately if the user clicks the "uninstall" link.
*/
function UninstallPreMessage()
{
return $this->Lang('really_uninstall');
}
//ok, this says we can add a content_module tag to a template
function HasCapability($capability,$params = array())
{
if ($capability == 'contentblocks')
return true;
return false;
}
function GetContentBlockFieldInput($blockName,$value,$params,$adding, ContentBase $content_obj){
//TODO add more params, file type etc.
if(isset($params['folder'])){
$folder=$params['folder'];
}else{
$folder='';
}
$file_type='img'; //image - our default file_type
if(isset($params['file_type'])){
$file_type=$params['file_type'];
}
//get the input
$millcobrowser_input=$this->millco_create_filepicker($blockName, $value, $folder, $file_type);
return $millcobrowser_input;
}
function GetContentBlockFieldValue($blockName,$blockParams,$inputParams, ContentBase $content_obj){
if (isset($inputParams[$blockName]))
return $inputParams[$blockName];
}
// function ValidateContentBlockValue($blockName,$value,$blockparams){
// // dont care really
// return true;
// }
function DoEvent( $originator, $eventname, &$params )
{
if ($originator == 'Core' && $eventname == 'ContentPostRender')
{
$tempcontent=$params['content'];
$pos=stripos($tempcontent,"</head");
if( $pos !== FALSE && isset($this->mb_meta)){
$tempcontent=substr($tempcontent,0,$pos).$this->mb_meta.substr($tempcontent,$pos);
$params['content'] = $tempcontent;
}
}
}
// load required js in admin.
function GetHeaderHTML(){
// this doesn't work for a content module by the looks of things.
// will put in template till we work out why...
return '
<!-- required js and styles for MillcoBrowser module -->
<script src="' . $this->config['root_url'] . '/modules/MillcoBrowser/js/millco_browser.min.js"></script>
<link type="text/css" rel="stylesheet" href="' . $this->config['root_url'] . '/modules/MillcoBrowser/css/mb.css">
';
}
/*non API funcs from here on */
//translate our file type string to numeric value
function _file_type($file_string){
switch ($file_string) {
case 'file':
$file_type=2; //file
break;
case 'video':
$file_type=3; //video
break;
default:
$file_type=1; //image
break;
}
return $file_type;
}
function DisplayErrorPage($id, &$params, $returnid, $message='')
{
$this->smarty->assign('title_error', $this->Lang('error'));
if ($message != '')
{
$this->smarty->assign_by_ref('message', $message);
}
// Display the populated template
echo $this->ProcessTemplate('error.tpl');
}
function millco_tidy_input($grubby){
$clean=trim($grubby);
$clean=filter_var($clean, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
//$clean = preg_replace('/[^a-z0-9\s]/i', '', $clean);
return $clean;
}
// this function is really the only thing done in this module.
function millco_create_filepicker($field_id='' , $current_value='' , $folder='', $file_type='img'){
if(strlen($field_id) < 1){
$file_picker="invalid field id";
}else{
// we store an access key which is then used in filemanager config.
if(!(isset($_SESSION['millcobrowser_key']) && strlen($_SESSION['millcobrowser_key']) > 2 )){
$_SESSION['millcobrowser_key'] = md5(uniqid());
}
//translate our string to file type value;
$file_type_val=$this->_file_type($file_type);
$file_picker='';
$fp_image='';
$fp_thumbpath=$this->config['root_path'] . '/tmp/thumbs/';
$fp_thumburl=$this->config['root_url'] . '/tmp/thumbs/';
if($file_type=='img'){
//see if we have a thumbnail for our current image:
$current_thumb = $fp_thumbpath . $current_value;
if (file_exists($current_thumb)) {
$fp_image = $fp_thumburl . $current_value;
}else{ // just use a placeholder thumb.
$fp_image= $this->config['root_url'] . '/modules/MillcoBrowser/lib/filemanager/img/ico/gif.jpg';
}
}
$fp_js= $this->config['root_url'] . '/modules/MillcoBrowser/js/millco_browser.js';
// one day we could put more of these into options.
$fp_url=$this->config['root_url'] . '/modules/MillcoBrowser/lib/filemanager/dialog.php?';
$fp_url.='type=' . $file_type_val;
$fp_url.='&popup=1';
$fp_url.='&field_id=' . $field_id .'';
$fp_url.='&relative_url=1';
if($folder!==''){
$fp_url.='&fldr=' . $folder;
}
$fp_url.='&akey=' . $_SESSION['millcobrowser_key'];
$fp_url.='&' . '_sk_=' . session_id();
$fp_url.='&nocache=' . time();
$tpl = $this->smarty->CreateTemplate($this->GetTemplateResource('file_picker.tpl'));
$tpl->assign('fp_url',$fp_url);
$tpl->assign('fp_js',$fp_js);
$tpl->assign('fp_thumburl',$fp_thumburl);
$tpl->assign('fp_image',$fp_image);
$tpl->assign('fp_image_id', $field_id.'-thumb');
$tpl->assign('fp_input',$this->CreateInputText('', $field_id, $current_value));
$file_picker=$tpl->fetch();
}
return $file_picker;
}
}
?>