1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* classGenerator |
4
|
|
|
* walls_watermarks. |
5
|
|
|
* |
6
|
|
|
* You may not change or alter any portion of this comment or credits |
7
|
|
|
* of supporting developers from this source code or any supporting source code |
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
12
|
|
|
* |
13
|
|
|
* |
14
|
|
|
* |
15
|
|
|
* L'utilisation de ce formulaire d'adminitration suppose |
16
|
|
|
* que la classe correspondante de la table a été générées avec classGenerator |
17
|
|
|
**/ |
18
|
|
|
include_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class ExtcalUtilities. |
22
|
|
|
*/ |
23
|
|
|
class ExtcalUtilities |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param $eventId |
27
|
|
|
* |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
|
public static function extcal_getEvent($eventId) |
31
|
|
|
{ |
32
|
|
|
$eventHandler = xoops_getModuleHandler(_EXTCAL_CLS_EVENT, _EXTCAL_MODULE); |
33
|
|
|
$event = $eventHandler->getEvent($eventId); |
34
|
|
|
$t = $event->getVars(); |
35
|
|
|
$data = array(); |
36
|
|
|
while (list($key, $val) = each($t)) { |
37
|
|
|
$data[$key] = $val['value']; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $data; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param $REQUEST |
45
|
|
|
* @param $event_picture1 |
46
|
|
|
* @param $event_picture2 |
47
|
|
|
*/ |
48
|
|
|
public static function extcal_loadImg(&$REQUEST, &$event_picture1, &$event_picture2) |
49
|
|
|
{ |
50
|
|
|
/////////////////////////////////////////////////////////////////////////////// |
51
|
|
|
$uploaddir_event = XOOPS_ROOT_PATH . '/uploads/extcal/'; |
52
|
|
|
$uploadurl_event = XOOPS_URL . '/uploads/extcal/'; |
|
|
|
|
53
|
|
|
//$picture = ''; |
|
|
|
|
54
|
|
|
for ($j = 1; $j < 3; ++$j) { |
55
|
|
|
$delimg = @$REQUEST['delimg_' . $j . '']; |
56
|
|
|
$delimg = isset($delimg) ? (int)$delimg : 0; |
57
|
|
|
if (0 == $delimg && !empty($REQUEST['xoops_upload_file'][$j])) { |
58
|
|
|
$upload = new XoopsMediaUploader($uploaddir_event, array( |
59
|
|
|
'image/gif', |
60
|
|
|
'image/jpeg', |
61
|
|
|
'image/pjpeg', |
62
|
|
|
'image/x-png', |
63
|
|
|
'image/png', |
64
|
|
|
'image/jpg', |
65
|
|
|
), 3145728, null, null); |
66
|
|
|
if ($upload->fetchMedia($REQUEST['xoops_upload_file'][$j])) { |
67
|
|
|
$upload->setPrefix('event_'); |
68
|
|
|
$upload->fetchMedia($REQUEST['xoops_upload_file'][$j]); |
69
|
|
|
if (!$upload->upload()) { |
70
|
|
|
$errors = $upload->getErrors(); |
71
|
|
|
redirect_header('javascript:history.go(-1)', 3, $errors); |
72
|
|
|
} else { |
73
|
|
|
if ($j == 1) { |
74
|
|
|
$event_picture1 = $upload->getSavedFileName(); |
75
|
|
|
} elseif ($j == 2) { |
76
|
|
|
$event_picture2 = $upload->getSavedFileName(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} elseif (!empty($REQUEST['file' . $j])) { |
80
|
|
|
if ($j == 1) { |
81
|
|
|
$event_picture1 = $REQUEST['file' . $j]; |
82
|
|
|
} elseif ($j == 2) { |
83
|
|
|
$event_picture2 = $REQUEST['file' . $j]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} else { |
87
|
|
|
$url_event = XOOPS_ROOT_PATH . '/uploads/extcal/' . $REQUEST['file' . $j]; |
88
|
|
|
if ($j == 1) { |
89
|
|
|
$event_picture1 = ''; |
90
|
|
|
} elseif ($j == 2) { |
91
|
|
|
$event_picture2 = ''; |
92
|
|
|
} |
93
|
|
|
if (is_file($url_event)) { |
94
|
|
|
chmod($url_event, 0777); |
95
|
|
|
unlink($url_event); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
//exit; |
100
|
|
|
/////////////////////////////////////////////////////////////////////////////// |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/******************************************************************* |
104
|
|
|
* |
105
|
|
|
****************************************************************** |
106
|
|
|
* @param $cat |
107
|
|
|
* @param bool $addNone |
108
|
|
|
* @param string $name |
109
|
|
|
* @return XoopsFormSelect |
110
|
|
|
*/ |
111
|
|
|
public static function getListCategories($cat, $addNone = true, $name = 'cat') |
112
|
|
|
{ |
113
|
|
|
global $xoopsUser; |
|
|
|
|
114
|
|
|
// Category selectbox |
115
|
|
|
$catHandler = xoops_getModuleHandler(_EXTCAL_CLS_CAT, _EXTCAL_MODULE); |
116
|
|
|
|
117
|
|
|
$catsList = $catHandler->getAllCat($xoopsUser); |
118
|
|
|
$catSelect = new XoopsFormSelect('', $name, $cat); |
119
|
|
|
if ($addNone) { |
120
|
|
|
$catSelect->addOption(0, ' '); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
foreach ($catsList as $catList) { |
124
|
|
|
$catSelect->addOption($catList->getVar('cat_id'), $catList->getVar('cat_name')); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $catSelect; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/******************************************************************* |
131
|
|
|
* |
132
|
|
|
****************************************************************** |
133
|
|
|
* @param string $name |
134
|
|
|
* @param $cat |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
|
|
public static function getCheckeCategories($name = 'cat', $cat) |
|
|
|
|
138
|
|
|
{ |
139
|
|
|
global $xoopsUser; |
|
|
|
|
140
|
|
|
// Category selectbox |
141
|
|
|
//<option style="background-color:#00FFFF;">VARCHAR</option> |
142
|
|
|
|
143
|
|
|
$catHandler = xoops_getModuleHandler(_EXTCAL_CLS_CAT, _EXTCAL_MODULE); |
144
|
|
|
$catsList = $catHandler->getAllCat($xoopsUser); |
145
|
|
|
|
146
|
|
|
$t = array(); |
147
|
|
|
foreach ($catsList as $catList) { |
148
|
|
|
$cat_id = $catList->getVar('cat_id'); |
149
|
|
|
$name = $catList->getVar('cat_name'); |
150
|
|
|
$cat_color = $catList->getVar('cat_color'); |
151
|
|
|
$checked = in_array($cat_id, $cat) ? 'checked' : ''; |
152
|
|
|
$cat = '' . "<div style='float:left; margin-left:5px;'>" . "<input type='checkbox' name='{$name}[{$cat_id}]' value='1' {$checked}>" |
153
|
|
|
. "<div style='absolute:left;height:12px; width:6px; background-color:#{$cat_color}; border:1px solid black; float:left; margin-right:5px;' ></div>" . " {$name}" . '</div>'; |
154
|
|
|
|
155
|
|
|
$t[] = $cat; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
return $t; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/******************************************************************* |
162
|
|
|
* |
163
|
|
|
****************************************************************** |
164
|
|
|
* @param string $name |
165
|
|
|
* @param string $caption |
166
|
|
|
* @param $defaut |
167
|
|
|
* @param bool $addNone |
168
|
|
|
* @return XoopsFormSelect |
169
|
|
|
*/ |
170
|
|
|
public static function getListOrderBy($name = 'orderby', $caption = '', $defaut, $addNone = false) |
171
|
|
|
{ |
172
|
|
|
global $xoopsUser; |
|
|
|
|
173
|
|
|
|
174
|
|
|
$select = new XoopsFormSelect($caption, $name, $defaut); |
175
|
|
|
if ($addNone) { |
176
|
|
|
$select->addOption('', ''); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$select->addOption('year ASC', _MD_EXTCAL_YEAR . ' ' . _MD_EXTCAL_ORDER_BY_ASC); |
180
|
|
|
$select->addOption('year DESC', _MD_EXTCAL_YEAR . ' ' . _MD_EXTCAL_ORDER_BY_DESC); |
181
|
|
|
|
182
|
|
|
$select->addOption('month ASC', _MD_EXTCAL_MONTH . ' ' . _MD_EXTCAL_ORDER_BY_ASC); |
183
|
|
|
$select->addOption('month DESC', _MD_EXTCAL_MONTH . ' ' . _MD_EXTCAL_ORDER_BY_DESC); |
184
|
|
|
|
185
|
|
|
$select->addOption('event_title ASC', _MD_EXTCAL_ALPHA . ' ' . _MD_EXTCAL_ORDER_BY_ASC); |
186
|
|
|
$select->addOption('event_title DESC', _MD_EXTCAL_ALPHA . ' ' . _MD_EXTCAL_ORDER_BY_DESC); |
187
|
|
|
|
188
|
|
|
$select->addOption('cat_name ASC', _MD_EXTCAL_CATEGORY . ' ' . _MD_EXTCAL_ORDER_BY_ASC); |
189
|
|
|
$select->addOption('cat_name DESC', _MD_EXTCAL_CATEGORY . ' ' . _MD_EXTCAL_ORDER_BY_DESC); |
190
|
|
|
|
191
|
|
|
return $select; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/******************************************************************* |
195
|
|
|
* |
196
|
|
|
****************************************************************** |
197
|
|
|
* @param string $name |
198
|
|
|
* @param string $caption |
199
|
|
|
* @param $defaut |
200
|
|
|
* @return XoopsFormSelect |
201
|
|
|
*/ |
202
|
|
|
public static function getListAndOr($name = 'andor', $caption = '', $defaut) |
203
|
|
|
{ |
204
|
|
|
global $xoopsUser; |
|
|
|
|
205
|
|
|
|
206
|
|
|
$select = new XoopsFormSelect($caption, $name, $defaut); |
207
|
|
|
|
208
|
|
|
$select->addOption('AND', _MD_EXTCAL_AND); |
209
|
|
|
$select->addOption('OR', _MD_EXTCAL_OR); |
210
|
|
|
|
211
|
|
|
return $select; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/******************************************************************* |
215
|
|
|
* |
216
|
|
|
****************************************************************** |
217
|
|
|
* @param $name |
218
|
|
|
* @param $caption |
219
|
|
|
* @param $defaut |
220
|
|
|
* @param $options |
221
|
|
|
* @param string $sep |
222
|
|
|
* @return XoopsFormSelect |
223
|
|
|
*/ |
224
|
|
|
public static function getList($name, $caption, $defaut, $options, $sep = ';') |
225
|
|
|
{ |
226
|
|
|
global $xoopsUser; |
|
|
|
|
227
|
|
|
|
228
|
|
|
$select = new XoopsFormSelect($caption, $name, $defaut); |
229
|
|
|
if (!is_array($options)) { |
230
|
|
|
$options = explode($sep, $options); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
for ($h = 0, $count = count($options); $h < $count; ++$h) { |
234
|
|
|
$select->addOption($h, $options[$h]); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
return $select; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/******************************************************************* |
241
|
|
|
* |
242
|
|
|
****************************************************************** |
243
|
|
|
* @param $ts |
244
|
|
|
* @param $startMonth |
245
|
|
|
* @param $endMonth |
246
|
|
|
* @param string $mode |
247
|
|
|
* @return DateTime |
248
|
|
|
*/ |
249
|
|
|
public static function getDateBetweenDates($ts, $startMonth, $endMonth, $mode = 'w') |
|
|
|
|
250
|
|
|
{ |
251
|
|
|
$d = new DateTime($periodStart); |
|
|
|
|
252
|
|
|
$d->setTimestamp($ts); |
253
|
|
|
|
254
|
|
|
//echo "<br>affichage des periodes : <br>"; |
255
|
|
|
$begin = new DateTime(); |
256
|
|
|
$begin->setTimestamp($startMonth); |
257
|
|
|
//echo $begin->format("d/m/Y à H\hi:s").'<br>'; // 03/10/2007 à 19h39:53 |
|
|
|
|
258
|
|
|
|
259
|
|
|
$end = new DateTime(); |
260
|
|
|
$end->setTimestamp($endMonth); |
261
|
|
|
//echo $end->format("d/m/Y à H\hi:s").'<br>'; // 03/10/2007 à 19h39:53 |
|
|
|
|
262
|
|
|
//echo "<hr>"; |
263
|
|
|
$interval = DateInterval::createFromDateString('next sunday'); |
264
|
|
|
$period = new DatePeriod($begin, $interval, $end); |
|
|
|
|
265
|
|
|
//echoDateArray($period); |
266
|
|
|
|
267
|
|
|
//echo "<hr>{$interval}"; |
268
|
|
|
return $d; |
269
|
|
|
|
270
|
|
|
//echo mktime($heure, $minute, $seconde, $mois, $jour, $an); |
|
|
|
|
271
|
|
|
|
272
|
|
|
// |
273
|
|
|
// $jour = date('d', $ts); |
|
|
|
|
274
|
|
|
// $mois = date('m', $ts); |
|
|
|
|
275
|
|
|
// $an = date('Y', $ts); |
|
|
|
|
276
|
|
|
// $heure = date('H', $ts); |
|
|
|
|
277
|
|
|
// $minute = date('i', $ts); |
|
|
|
|
278
|
|
|
// $seconde = date('s', $ts); |
|
|
|
|
279
|
|
|
// $d->setDate($heure,$minute,$seconde,$mois,$jour,$an); |
|
|
|
|
280
|
|
|
|
281
|
|
|
// <?php |
282
|
|
|
// $interval = DateInterval::createFromDateString('next sunday'); |
|
|
|
|
283
|
|
|
// $period = new DatePeriod($begin, $interval, $end); |
|
|
|
|
284
|
|
|
// foreach ($period as $dt) { |
|
|
|
|
285
|
|
|
// echo $dt->format( "l Y-m-d H:i:s\n" ); |
|
|
|
|
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/* |
|
|
|
|
289
|
|
|
Sunday 2009-11-01 00:00:00 |
290
|
|
|
Sunday 2009-11-08 00:00:00 |
291
|
|
|
Sunday 2009-11-15 00:00:00 |
292
|
|
|
Sunday 2009-11-22 00:00:00 |
293
|
|
|
Sunday 2009-11-29 00:00:00 |
294
|
|
|
Sunday 2009-12-06 00:00:00 |
295
|
|
|
... |
296
|
|
|
*/ |
297
|
|
|
/** |
298
|
|
|
* @param $period |
299
|
|
|
*/ |
300
|
|
|
public static function echoDateArray($period) |
301
|
|
|
{ |
302
|
|
|
foreach ($period as $dt) { |
303
|
|
|
echo $dt->format("l Y-m-d H:i:s\n") . '<br>'; |
304
|
|
|
} |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/*****************************************************************/ |
308
|
|
|
/** |
309
|
|
|
* @param $t |
310
|
|
|
* @param string $msg |
311
|
|
|
*/ |
312
|
|
|
public static function ext_echoArray($t, $msg = '') |
313
|
|
|
{ |
314
|
|
|
if ($msg != '') { |
315
|
|
|
echo "<hr>{$msg}<hr>"; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
$txt = print_r($t, true); |
319
|
|
|
echo '<pre>Number of items: ' . count($t) . "<br>{$txt}</pre>"; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/*****************************************************************/ |
323
|
|
|
/** |
324
|
|
|
* @param $line |
325
|
|
|
* @param string $msg |
326
|
|
|
*/ |
327
|
|
|
public static function ext_echo($line, $msg = '') |
328
|
|
|
{ |
329
|
|
|
if ($msg != '') { |
330
|
|
|
echo "<hr>{$msg}<hr>"; |
331
|
|
|
} |
332
|
|
|
echo $line . '<br>'; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/*****************************************************************/ |
336
|
|
|
/** |
337
|
|
|
* @param $tsName |
338
|
|
|
* @param string $msg |
339
|
|
|
*/ |
340
|
|
|
public static function ext_echoTSN($tsName, $msg = '') |
341
|
|
|
{ |
342
|
|
|
global $$tsName; |
|
|
|
|
343
|
|
|
$ts = $$tsName; |
344
|
|
|
static::ext_echoTSU($ts, $tsName, $msg = ''); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/*****************************************************************/ |
348
|
|
|
/** |
349
|
|
|
* @param $ts |
350
|
|
|
* @param $tsName |
351
|
|
|
* @param string $msg |
352
|
|
|
*/ |
353
|
|
|
public static function ext_echoTSU($ts, $tsName, $msg = '') |
354
|
|
|
{ |
355
|
|
|
if ($msg != '') { |
356
|
|
|
echo "<hr>{$msg}<hr>"; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
echo 'date --->' . $tsName . ' = ' . $ts . ' - ' . date('d-m-Y H:m:s', $ts) . '<br>'; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/*****************************************************************/ |
363
|
|
|
/*****************************************************************/ |
364
|
|
|
/** |
365
|
|
|
* @param $date |
366
|
|
|
* @param string $sep |
367
|
|
|
* |
368
|
|
|
* @return int |
|
|
|
|
369
|
|
|
*/ |
370
|
|
|
public static function ext_convert_date($date, $sep = '-') |
371
|
|
|
{ |
372
|
|
|
$lstSep = '/ .'; |
373
|
|
|
|
374
|
|
|
for ($h = 0, $count = strlen($lstSep); $h < $count; ++$h) { |
|
|
|
|
375
|
|
|
$sep2replace = substr($lstSep, $h, 1); |
376
|
|
|
if (strpos($date, $sep2replace)) { |
377
|
|
|
$date = str_replace($sep2replace, $sep, $date); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
return strtotime($date); |
381
|
|
|
} |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @param $givendate |
386
|
|
|
* @param int $day |
387
|
|
|
* @param int $mth |
388
|
|
|
* @param int $yr |
389
|
|
|
* |
390
|
|
|
* @return int |
391
|
|
|
*/ |
392
|
|
|
public static function ext_DateAdd($givendate, $day = 0, $mth = 0, $yr = 0) |
393
|
|
|
{ |
394
|
|
|
//$cd = strtotime($givendate); |
|
|
|
|
395
|
|
|
$cd = $givendate; |
396
|
|
|
$newdate = date('Y-m-d h:i:s', mktime(date('h', $cd), date('i', $cd), date('s', $cd), date('m', $cd) + $mth, date('d', $cd) + $day, date('Y', $cd) + $yr)); |
397
|
|
|
|
398
|
|
|
return strtotime($newdate); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* @param $date |
403
|
|
|
* @param $number |
404
|
|
|
* @param $interval |
405
|
|
|
* |
406
|
|
|
* @return int |
407
|
|
|
*/ |
408
|
|
|
public static function ext_DateAdd2($date, $number, $interval = 'd') |
409
|
|
|
{ |
410
|
|
|
$date_time_array = getdate($date); |
411
|
|
|
$hours = $date_time_array['hours']; |
412
|
|
|
$minutes = $date_time_array['minutes']; |
413
|
|
|
$seconds = $date_time_array['seconds']; |
414
|
|
|
$month = $date_time_array['mon']; |
415
|
|
|
$day = $date_time_array['mday']; |
416
|
|
|
$year = $date_time_array['year']; |
417
|
|
|
|
418
|
|
|
switch ($interval) { |
419
|
|
|
|
420
|
|
|
case 'yyyy': |
421
|
|
|
$year += $number; |
422
|
|
|
break; |
423
|
|
|
case 'q': |
424
|
|
|
$year += ($number * 3); |
425
|
|
|
break; |
426
|
|
|
case 'm': |
427
|
|
|
$month += $number; |
428
|
|
|
break; |
429
|
|
|
case 'y': |
430
|
|
|
case 'd': |
431
|
|
|
case 'w': |
432
|
|
|
$day += $number; |
433
|
|
|
break; |
434
|
|
|
case 'ww': |
435
|
|
|
$day += ($number * 7); |
436
|
|
|
break; |
437
|
|
|
case 'h': |
438
|
|
|
$hours += $number; |
439
|
|
|
break; |
440
|
|
|
case 'n': |
441
|
|
|
$minutes += $number; |
442
|
|
|
break; |
443
|
|
|
case 's': |
444
|
|
|
$seconds += $number; |
445
|
|
|
break; |
446
|
|
|
} |
447
|
|
|
$timestamp = mktime($hours, $minutes, $seconds, $month, $day, $year); |
448
|
|
|
|
449
|
|
|
return $timestamp; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
// function date_diff($date1, $date2) { |
|
|
|
|
453
|
|
|
// $current = $date1; |
|
|
|
|
454
|
|
|
// $datetime2 = date_create($date2); |
|
|
|
|
455
|
|
|
// $count = 0; |
|
|
|
|
456
|
|
|
// while (date_create($current) < $datetime2) { |
|
|
|
|
457
|
|
|
// $current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current))); |
|
|
|
|
458
|
|
|
// ++$count; |
459
|
|
|
// } |
460
|
|
|
// return $count; |
461
|
|
|
// } |
462
|
|
|
|
463
|
|
|
/**************************************************************************/ |
464
|
|
|
/** |
465
|
|
|
* @param $color |
466
|
|
|
* @param $plancher |
467
|
|
|
* @param $plafond |
468
|
|
|
* |
469
|
|
|
* @return string |
470
|
|
|
*/ |
471
|
|
|
public static function getLighterColor($color, $plancher, $plafond) |
472
|
|
|
{ |
473
|
|
|
include_once __DIR__ . '/colorTools.php'; |
474
|
|
|
|
475
|
|
|
//$ct = new ColorTools(); |
|
|
|
|
476
|
|
|
//return $ct->eclaircir($color,$plancher,$plafond); |
|
|
|
|
477
|
|
|
return ColorTools::eclaircir($color, $plancher, $plafond); |
478
|
|
|
} |
479
|
|
|
/**************************************************************************/ |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* Function responsible for checking if a directory exists, we can also write in and create an index.html file |
483
|
|
|
* |
484
|
|
|
* @param string $folder The full path of the directory to check |
485
|
|
|
* |
486
|
|
|
* @return void |
487
|
|
|
*/ |
488
|
|
|
public static function createFolder($folder) |
489
|
|
|
{ |
490
|
|
|
try { |
491
|
|
|
if (!file_exists($folder)) { |
492
|
|
|
if (!mkdir($folder) && !is_dir($folder)) { |
493
|
|
|
throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
494
|
|
|
} else { |
495
|
|
|
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
496
|
|
|
} |
497
|
|
|
} |
498
|
|
|
} catch (Exception $e) { |
499
|
|
|
echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>'; |
500
|
|
|
} |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* @param $file |
505
|
|
|
* @param $folder |
506
|
|
|
* @return bool |
507
|
|
|
*/ |
508
|
|
|
public static function copyFile($file, $folder) |
509
|
|
|
{ |
510
|
|
|
return copy($file, $folder); |
511
|
|
|
// try { |
512
|
|
|
// if (!is_dir($folder)) { |
|
|
|
|
513
|
|
|
// throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder)); |
|
|
|
|
514
|
|
|
// } else { |
|
|
|
|
515
|
|
|
// return copy($file, $folder); |
|
|
|
|
516
|
|
|
// } |
517
|
|
|
// } catch (Exception $e) { |
|
|
|
|
518
|
|
|
// echo 'Caught exception: ', $e->getMessage(), "\n", "<br/>"; |
|
|
|
|
519
|
|
|
// } |
520
|
|
|
// return false; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* @param $src |
525
|
|
|
* @param $dst |
526
|
|
|
*/ |
527
|
|
|
public static function recurseCopy($src, $dst) |
528
|
|
|
{ |
529
|
|
|
$dir = opendir($src); |
530
|
|
|
// @mkdir($dst); |
531
|
|
|
while (false !== ($file = readdir($dir))) { |
532
|
|
|
if (($file !== '.') && ($file !== '..')) { |
533
|
|
|
if (is_dir($src . '/' . $file)) { |
534
|
|
|
self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
535
|
|
|
} else { |
536
|
|
|
copy($src . '/' . $file, $dst . '/' . $file); |
537
|
|
|
} |
538
|
|
|
} |
539
|
|
|
} |
540
|
|
|
closedir($dir); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* |
545
|
|
|
* Verifies XOOPS version meets minimum requirements for this module |
546
|
|
|
* @static |
547
|
|
|
* @param XoopsModule $module |
548
|
|
|
* |
549
|
|
|
* @return bool true if meets requirements, false if not |
550
|
|
|
*/ |
551
|
|
|
public static function checkXoopsVer(XoopsModule $module) |
552
|
|
|
{ |
553
|
|
|
xoops_loadLanguage('admin', $module->dirname()); |
554
|
|
|
//check for minimum XOOPS version |
555
|
|
|
$currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
556
|
|
|
$currArray = explode('.', $currentVer); |
557
|
|
|
$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
558
|
|
|
$reqArray = explode('.', $requiredVer); |
559
|
|
|
$success = true; |
560
|
|
|
foreach ($reqArray as $k => $v) { |
561
|
|
|
if (isset($currArray[$k])) { |
562
|
|
|
if ($currArray[$k] > $v) { |
563
|
|
|
break; |
564
|
|
|
} elseif ($currArray[$k] == $v) { |
565
|
|
|
continue; |
566
|
|
|
} else { |
567
|
|
|
$success = false; |
568
|
|
|
break; |
569
|
|
|
} |
570
|
|
|
} else { |
571
|
|
|
if ((int)$v > 0) { // handles things like x.x.x.0_RC2 |
572
|
|
|
$success = false; |
573
|
|
|
break; |
574
|
|
|
} |
575
|
|
|
} |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
if (!$success) { |
579
|
|
|
$module->setErrors(sprintf(_AM_TAG_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
return $success; |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
/** |
586
|
|
|
* |
587
|
|
|
* Verifies PHP version meets minimum requirements for this module |
588
|
|
|
* @static |
589
|
|
|
* @param XoopsModule $module |
590
|
|
|
* |
591
|
|
|
* @return bool true if meets requirements, false if not |
592
|
|
|
*/ |
593
|
|
|
public static function checkPhpVer(XoopsModule $module) |
594
|
|
|
{ |
595
|
|
|
xoops_loadLanguage('admin', $module->dirname()); |
596
|
|
|
// check for minimum PHP version |
597
|
|
|
$success = true; |
598
|
|
|
$verNum = phpversion(); |
599
|
|
|
$reqVer =& $module->getInfo('min_php'); |
600
|
|
|
if (false !== $reqVer && '' !== $reqVer) { |
601
|
|
|
if (version_compare($verNum, $reqVer, '<')) { |
602
|
|
|
$module->setErrors(sprintf(_AM_TAG_ERROR_BAD_PHP, $reqVer, $verNum)); |
603
|
|
|
$success = false; |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
return $success; |
608
|
|
|
} |
609
|
|
|
} |
610
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.