This repository was archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
499 lines (455 loc) · 13.8 KB
/
index.php
File metadata and controls
499 lines (455 loc) · 13.8 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
<?php
/**
* moziloCMS Plugin: Search
*
* Does something awesome!
*
* PHP version 5
*
* @category PHP
* @package PHP_MoziloPlugins
* @author DEVMOUNT <mail@devmount.de>
* @license GPL v3+
* @version GIT: v0.1.2015-02-10
* @link https://github.com/devmount-mozilo/Search/wiki/Dokumentation
* @see Ask and it will be given to you; seek and you will find; knock and the door will be opened to you.
* – The Bible
*
* Plugin created by DEVMOUNT
* www.devmount.de
*
*/
// only allow moziloCMS environment
if (!defined('IS_CMS')) {
die();
}
/**
* Search Class
*
* @category PHP
* @package PHP_MoziloPlugins
* @author DEVMOUNT <mail@devmount.de>
* @license GPL v3+
* @link https://github.com/devmount-mozilo/Search
*/
class Search extends Plugin
{
// language
private $_admin_lang;
private $_cms_lang;
// plugin information
const PLUGIN_AUTHOR = 'DEVMOUNT';
const PLUGIN_TITLE = 'Search';
const PLUGIN_VERSION = 'v0.1.2015-02-10';
const MOZILO_VERSION = '2.0';
const PLUGIN_DOCU
= 'https://github.com/devmount-mozilo/Search/wiki/Dokumentation';
private $_plugin_tags = array(
'tag1' => '{Search}',
);
const LOGO_URL = 'http://media.devmount.de/logo_pluginconf.png';
/**
* set configuration elements, their default values and their configuration
* parameters
*
* @var array $_confdefault
* text => default, type, maxlength, size, regex
* textarea => default, type, cols, rows, regex
* password => default, type, maxlength, size, regex, saveasmd5
* check => default, type
* radio => default, type, descriptions
* select => default, type, descriptions, multiselect
*/
private $_confdefault = array(
'html' => array(
'',
'textarea',
'100',
'15',
"",
),
);
/**
* creates plugin content
*
* @param string $value Parameter divided by '|'
*
* @return string HTML output
*/
function getContent($value)
{
global $CMS_CONF;
global $syntax;
// initialize cms lang
$this->_cms_lang = new Language(
$this->PLUGIN_SELF_DIR
. 'lang/cms_language_'
. $CMS_CONF->get('cmslanguage')
. '.txt'
);
// get language labels
$label = $this->_cms_lang->getLanguageValue('label');
// get conf and set default
$conf = array();
foreach ($this->_confdefault as $elem => $default) {
$conf[$elem] = ($this->settings->get($elem) == '')
? $default[0]
: $this->settings->get($elem);
}
// initialize return content, begin plugin content
$content = '<!-- BEGIN ' . self::PLUGIN_TITLE . ' plugin content --> ';
$html = str_replace('<br />', '', $conf['html']);
$content .= $html;
// end plugin content
$content .= '<!-- END ' . self::PLUGIN_TITLE . ' plugin content --> ';
return $content;
}
/**
* sets backend configuration elements and template
*
* @return Array configuration
*/
function getConfig()
{
$config = array();
// read configuration values
foreach ($this->_confdefault as $key => $value) {
// handle each form type
switch ($value[1]) {
case 'text':
$config[$key] = $this->confText(
$this->_admin_lang->getLanguageValue('config_' . $key),
$value[2],
$value[3],
$value[4],
$this->_admin_lang->getLanguageValue(
'config_' . $key . '_error'
)
);
break;
case 'textarea':
$config[$key] = $this->confTextarea(
$this->_admin_lang->getLanguageValue('config_' . $key),
$value[2],
$value[3],
$value[4],
$this->_admin_lang->getLanguageValue(
'config_' . $key . '_error'
)
);
break;
case 'password':
$config[$key] = $this->confPassword(
$this->_admin_lang->getLanguageValue('config_' . $key),
$value[2],
$value[3],
$value[4],
$this->_admin_lang->getLanguageValue(
'config_' . $key . '_error'
),
$value[5]
);
break;
case 'check':
$config[$key] = $this->confCheck(
$this->_admin_lang->getLanguageValue('config_' . $key)
);
break;
case 'radio':
$descriptions = array();
foreach ($value[2] as $label) {
$descriptions[$label] = $this->_admin_lang->getLanguageValue(
'config_' . $key . '_' . $label
);
}
$config[$key] = $this->confRadio(
$this->_admin_lang->getLanguageValue('config_' . $key),
$descriptions
);
break;
case 'select':
$descriptions = array();
foreach ($value[2] as $label) {
$descriptions[$label] = $this->_admin_lang->getLanguageValue(
'config_' . $key . '_' . $label
);
}
$config[$key] = $this->confSelect(
$this->_admin_lang->getLanguageValue('config_' . $key),
$descriptions,
$value[3]
);
break;
default:
break;
}
}
// read admin.css
$admin_css = '';
$lines = file('../plugins/' . self::PLUGIN_TITLE. '/admin.css');
foreach ($lines as $line_num => $line) {
$admin_css .= trim($line);
}
// add template CSS
$template = '<style>' . $admin_css . '</style>';
// build Template
$template .= '
<div class="search-admin-header">
<span>'
. $this->_admin_lang->getLanguageValue(
'admin_header',
self::PLUGIN_TITLE
)
. '</span>
<a href="' . self::PLUGIN_DOCU . '" target="_blank">
<img style="float:right;" src="' . self::LOGO_URL . '" />
</a>
</div>
</li>
<li class="mo-in-ul-li ui-widget-content search-admin-li">
<div class="search-admin-subheader">'
. $this->_admin_lang->getLanguageValue('admin_content')
. '</div>
<div class="search-single-conf">
{html_description}<br />
{html_textarea}
';
$config['--template~~'] = $template;
return $config;
}
/**
* sets default backend configuration elements, if no plugin.conf.php is
* created yet
*
* @return Array configuration
*/
function getDefaultSettings()
{
$config = array('active' => 'true');
foreach ($this->_confdefault as $elem => $default) {
$config[$elem] = $default[0];
}
return $config;
}
/**
* sets backend plugin information
*
* @return Array information
*/
function getInfo()
{
global $ADMIN_CONF;
$this->_admin_lang = new Language(
$this->PLUGIN_SELF_DIR
. 'lang/admin_language_'
. $ADMIN_CONF->get('language')
. '.txt'
);
// build plugin tags
$tags = array();
foreach ($this->_plugin_tags as $key => $tag) {
$tags[$tag] = $this->_admin_lang->getLanguageValue('tag_' . $key);
}
$info = array(
'<b>' . self::PLUGIN_TITLE . '</b> ' . self::PLUGIN_VERSION,
self::MOZILO_VERSION,
$this->_admin_lang->getLanguageValue(
'description',
htmlspecialchars($this->_plugin_tags['tag1'], ENT_COMPAT, 'UTF-8')
),
self::PLUGIN_AUTHOR,
array(
self::PLUGIN_DOCU,
self::PLUGIN_TITLE . ' '
. $this->_admin_lang->getLanguageValue('on_devmount')
),
$tags
);
return $info;
}
/**
* creates configuration for text fields
*
* @param string $description Label
* @param string $maxlength Maximum number of characters
* @param string $size Size
* @param string $regex Regular expression for allowed input
* @param string $regex_error Wrong input error message
*
* @return Array Configuration
*/
protected function confText(
$description,
$maxlength = '',
$size = '',
$regex = '',
$regex_error = ''
) {
// required properties
$conftext = array(
'type' => 'text',
'description' => $description,
);
// optional properties
if ($maxlength != '') {
$conftext['maxlength'] = $maxlength;
}
if ($size != '') {
$conftext['size'] = $size;
}
if ($regex != '') {
$conftext['regex'] = $regex;
}
if ($regex_error != '') {
$conftext['regex_error'] = $regex_error;
}
return $conftext;
}
/**
* creates configuration for textareas
*
* @param string $description Label
* @param string $cols Number of columns
* @param string $rows Number of rows
* @param string $regex Regular expression for allowed input
* @param string $regex_error Wrong input error message
*
* @return Array Configuration
*/
protected function confTextarea(
$description,
$cols = '',
$rows = '',
$regex = '',
$regex_error = ''
) {
// required properties
$conftext = array(
'type' => 'textarea',
'description' => $description,
);
// optional properties
if ($cols != '') {
$conftext['cols'] = $cols;
}
if ($rows != '') {
$conftext['rows'] = $rows;
}
if ($regex != '') {
$conftext['regex'] = $regex;
}
if ($regex_error != '') {
$conftext['regex_error'] = $regex_error;
}
return $conftext;
}
/**
* creates configuration for password fields
*
* @param string $description Label
* @param string $maxlength Maximum number of characters
* @param string $size Size
* @param string $regex Regular expression for allowed input
* @param string $regex_error Wrong input error message
* @param boolean $saveasmd5 Safe password as md5 (recommended!)
*
* @return Array Configuration
*/
protected function confPassword(
$description,
$maxlength = '',
$size = '',
$regex = '',
$regex_error = '',
$saveasmd5 = true
) {
// required properties
$conftext = array(
'type' => 'text',
'description' => $description,
);
// optional properties
if ($maxlength != '') {
$conftext['maxlength'] = $maxlength;
}
if ($size != '') {
$conftext['size'] = $size;
}
if ($regex != '') {
$conftext['regex'] = $regex;
}
$conftext['saveasmd5'] = $saveasmd5;
return $conftext;
}
/**
* creates configuration for checkboxes
*
* @param string $description Label
*
* @return Array Configuration
*/
protected function confCheck($description)
{
// required properties
return array(
'type' => 'checkbox',
'description' => $description,
);
}
/**
* creates configuration for radio buttons
*
* @param string $description Label
* @param string $descriptions Array Single item labels
*
* @return Array Configuration
*/
protected function confRadio($description, $descriptions)
{
// required properties
return array(
'type' => 'select',
'description' => $description,
'descriptions' => $descriptions,
);
}
/**
* creates configuration for select fields
*
* @param string $description Label
* @param string $descriptions Array Single item labels
* @param boolean $multiple Enable multiple item selection
*
* @return Array Configuration
*/
protected function confSelect($description, $descriptions, $multiple = false)
{
// required properties
return array(
'type' => 'select',
'description' => $description,
'descriptions' => $descriptions,
'multiple' => $multiple,
);
}
/**
* throws styled message
*
* @param string $type Type of message ('ERROR', 'SUCCESS')
* @param string $text Content of message
*
* @return string HTML content
*/
protected function throwMessage($text, $type)
{
return '<div class="'
. strtolower(self::PLUGIN_TITLE . '-' . $type)
. '">'
. '<div>'
. $this->_cms_lang->getLanguageValue(strtolower($type))
. '</div>'
. '<span>' . $text. '</span>'
. '</div>';
}
}
?>