This repository has been 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
/
Copy pathindex.php
579 lines (532 loc) · 16.5 KB
/
index.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
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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
<?php
/**
* moziloCMS Plugin: Losungen
*
* Shows the german Losung for the current day
*
* PHP version 5
*
* @category PHP
* @package PHP_MoziloPlugins
* @author DEVMOUNT <mail@devmount.de>
* @license GPL v3+
* @version GIT: v0.x.jjjj-mm-dd
* @link https://github.com/devmount-mozilo/Losungen
* @see Verse
* – The Bible
*
* Plugin created by DEVMOUNT
* www.devmount.de
*
*/
// only allow moziloCMS environment
if (!defined('IS_CMS')) {
die();
}
/**
* Losungen Class
*
* @category PHP
* @package PHP_MoziloPlugins
* @author DEVMOUNT <mail@devmount.de>
* @license GPL v3+
* @link https://github.com/devmount-mozilo/Losungen
*/
class Losungen extends Plugin
{
// language
private $_admin_lang;
private $_cms_lang;
// plugin information
const PLUGIN_AUTHOR = 'DEVMOUNT';
const PLUGIN_TITLE = 'Losungen';
const PLUGIN_VERSION = 'v0.x.jjjj-mm-dd';
const MOZILO_VERSION = '2.0';
const PLUGIN_DOCU
= 'https://github.com/devmount-mozilo/Losungen';
private $_plugin_tags = array(
'tag1' => '{Losungen}',
);
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(
'text' => array(
'string',
'text',
'100',
'5',
"/^[0-9]{1,3}$/",
),
'textarea' => array(
'string',
'textarea',
'100',
'15',
"/^[a-zA-Z0-9]{1,10}$/",
),
'password' => array(
'string',
'password',
'100',
'5',
"/^[a-zA-Z0-9]{8,20}$/",
true,
),
'check' => array(
'true',
'check',
),
'radio' => array(
'red',
'radio',
array('red', 'green', 'blue'),
),
'select' => array(
'bike',
'select',
array('car','bike','plane'),
false,
),
);
/**
* 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 params
list($param_1, $param_2) = array_map(trim, explode('|', $value));
// 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);
}
// include jquery and Losungen javascript
$syntax->insert_jquery_in_head('jquery');
$syntax->insert_in_head(
'<script type="text/javascript" src="'
. $this->PLUGIN_SELF_URL
. 'js/Losungen.js"></script>'
);
// initialize return content, begin plugin content
$content = '<!-- BEGIN ' . self::PLUGIN_TITLE . ' plugin content --> ';
$content .= '<div class="losungen"> ';
$year = date('Y');
$srcfile = PLUGIN_DIR_REL . self::PLUGIN_TITLE . '/src/' . $year . '.xml';
// check if xml file for current year exists
if (file_exists($srcfile)) {
$xml = simplexml_load_file($srcfile);
foreach ($xml->Losungen as $losung) {
$date = strtotime($losung->Datum);
// find current losung
if (date('Y-m-d') == date('Y-m-d', $date)) {
$content .= '<h2>'. $losung->Wtag . ' — ' . date('d.m.Y', $date) . '</h2>';
$content .= '<h3>'. $losung->Sonntag . '</h3>';
$content .= '<blockquote>' . $losung->Losungstext . '<cite>— '
. $losung->Losungsvers . '</cite></blockquote>';
$content .= '<blockquote>' . $losung->Lehrtext . '<cite>— '
. $losung->Lehrtextvers . '</cite></blockquote>';
break;
}
}
} else {
$content .= 'Für das aktuelle Jahr sind leider keine Losungen verfügbar.';
}
$content .= '
<div class="copy">
[link=Die Losungen|http://www.losungen.de]<br />
© Evangelische Brüder-Unität<br />
[link=Herrnhuter Brüdergemeine|http://www.herrnhuter.de]
</div>
';
$content .= '</div>';
// 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="losungen-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 losungen-admin-li">
<div class="losungen-admin-subheader">'
. $this->_admin_lang->getLanguageValue('admin_test')
. '</div>
<div class="losungen-single-conf">
{test1_text}
{test1_description}
<span class="losungen-admin-default">
[' . /*$this->_confdefault['test1'][0] .*/']
</span>
</div>
<div class="losungen-single-conf">
{test2_text}
{test2_description}
<span class="losungen-admin-default">
[' . /*$this->_confdefault['test2'][0] .*/']
</span>
';
$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>';
}
}
?>