Completed
Push — master ( a9decc...a21b67 )
by Michael
02:51
created

ExtcalUtility::recurseCopy()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 4
nop 2
dl 0
loc 15
rs 8.8571
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 18.

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.

Loading history...
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
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
19
20
/**
21
 * Class ExtcalUtility.
22
 */
23
class ExtcalUtility
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
37
            foreach ($t as $key => $val) {
38
                $data[$key] = $val['value'];
39
            }
40
41
        return $data;
42
    }
43
44
    /**
45
     * @param $REQUEST
46
     * @param $event_picture1
47
     * @param $event_picture2
48
     */
49
    public static function extcal_loadImg(&$REQUEST, &$event_picture1, &$event_picture2)
50
    {
51
        ///////////////////////////////////////////////////////////////////////////////
52
        $uploaddir_event = XOOPS_ROOT_PATH . '/uploads/extcal/';
53
        $uploadurl_event = XOOPS_URL . '/uploads/extcal/';
0 ignored issues
show
Unused Code introduced by
$uploadurl_event is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54
        //$picture = '';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
        for ($j = 1; $j < 3; ++$j) {
56
            $delimg = @$REQUEST['delimg_' . $j . ''];
57
            $delimg = isset($delimg) ? (int)$delimg : 0;
58
            if (0 == $delimg && !empty($REQUEST['xoops_upload_file'][$j])) {
59
                $upload = new XoopsMediaUploader($uploaddir_event, array(
60
                    'image/gif',
61
                    'image/jpeg',
62
                    'image/pjpeg',
63
                    'image/x-png',
64
                    'image/png',
65
                    'image/jpg',
66
                ), 3145728, null, null);
67
                if ($upload->fetchMedia($REQUEST['xoops_upload_file'][$j])) {
68
                    $upload->setPrefix('event_');
69
                    $upload->fetchMedia($REQUEST['xoops_upload_file'][$j]);
70
                    if (!$upload->upload()) {
71
                        $errors = $upload->getErrors();
72
                        redirect_header('javascript:history.go(-1)', 3, $errors);
73
                    } else {
74
                        if ($j == 1) {
75
                            $event_picture1 = $upload->getSavedFileName();
76
                        } elseif ($j == 2) {
77
                            $event_picture2 = $upload->getSavedFileName();
78
                        }
79
                    }
80
                } elseif (!empty($REQUEST['file' . $j])) {
81
                    if ($j == 1) {
82
                        $event_picture1 = $REQUEST['file' . $j];
83
                    } elseif ($j == 2) {
84
                        $event_picture2 = $REQUEST['file' . $j];
85
                    }
86
                }
87
            } else {
88
                $url_event = XOOPS_ROOT_PATH . '/uploads/extcal/' . $REQUEST['file' . $j];
89
                if ($j == 1) {
90
                    $event_picture1 = '';
91
                } elseif ($j == 2) {
92
                    $event_picture2 = '';
93
                }
94
                if (is_file($url_event)) {
95
                    chmod($url_event, 0777);
96
                    unlink($url_event);
97
                }
98
            }
99
        }
100
        //exit;
101
        ///////////////////////////////////////////////////////////////////////////////
102
    }
103
104
    /*******************************************************************
105
     *
106
     ******************************************************************
107
     * @param        $cat
108
     * @param bool   $addNone
109
     * @param string $name
110
     * @return XoopsFormSelect
111
     */
112
    public static function getListCategories($cat, $addNone = true, $name = 'cat')
113
    {
114
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
115
        // Category selectbox
116
        $catHandler = xoops_getModuleHandler(_EXTCAL_CLS_CAT, _EXTCAL_MODULE);
117
118
        $catsList  = $catHandler->getAllCat($xoopsUser);
119
        $catSelect = new XoopsFormSelect('', $name, $cat);
120
        if ($addNone) {
121
            $catSelect->addOption(0, ' ');
122
        }
123
124
        foreach ($catsList as $catList) {
125
            $catSelect->addOption($catList->getVar('cat_id'), $catList->getVar('cat_name'));
126
        }
127
128
        return $catSelect;
129
    }
130
131
    /*******************************************************************
132
     *
133
     ******************************************************************
134
     * @param string $name
135
     * @param        $cat
136
     * @return array
137
     */
138
    public static function getCheckeCategories($name = 'cat', $cat)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
139
    {
140
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
141
        // Category selectbox
142
        //<option style="background-color:#00FFFF;">VARCHAR</option>
143
144
        $catHandler = xoops_getModuleHandler(_EXTCAL_CLS_CAT, _EXTCAL_MODULE);
145
        $catsList   = $catHandler->getAllCat($xoopsUser);
146
147
        $t = array();
148
        foreach ($catsList as $catList) {
149
            $cat_id    = $catList->getVar('cat_id');
150
            $name      = $catList->getVar('cat_name');
151
            $cat_color = $catList->getVar('cat_color');
152
            $checked   = in_array($cat_id, $cat) ? 'checked' : '';
153
            $cat       = ''
154
                         . "<div style='float:left; margin-left:5px;'>"
155
                         . "<input type='checkbox' name='{$name}[{$cat_id}]' value='1' {$checked}>"
156
                         . "<div style='absolute:left;height:12px; width:6px; background-color:#{$cat_color}; border:1px solid black; float:left; margin-right:5px;' ></div>"
157
                         . " {$name}"
158
                         . '</div>';
159
160
            $t[] = $cat;
161
        }
162
163
        return $t;
164
    }
165
166
    /*******************************************************************
167
     *
168
     ******************************************************************
169
     * @param string $name
170
     * @param string $caption
171
     * @param        $defaut
172
     * @param bool   $addNone
173
     * @return XoopsFormSelect
174
     */
175
    public static function getListOrderBy($name = 'orderby', $caption = '', $defaut, $addNone = false)
176
    {
177
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
178
179
        $select = new XoopsFormSelect($caption, $name, $defaut);
180
        if ($addNone) {
181
            $select->addOption('', '');
182
        }
183
184
        $select->addOption('year ASC', _MD_EXTCAL_YEAR . ' ' . _MD_EXTCAL_ORDER_BY_ASC);
185
        $select->addOption('year DESC', _MD_EXTCAL_YEAR . ' ' . _MD_EXTCAL_ORDER_BY_DESC);
186
187
        $select->addOption('month ASC', _MD_EXTCAL_MONTH . ' ' . _MD_EXTCAL_ORDER_BY_ASC);
188
        $select->addOption('month DESC', _MD_EXTCAL_MONTH . ' ' . _MD_EXTCAL_ORDER_BY_DESC);
189
190
        $select->addOption('event_title ASC', _MD_EXTCAL_ALPHA . ' ' . _MD_EXTCAL_ORDER_BY_ASC);
191
        $select->addOption('event_title DESC', _MD_EXTCAL_ALPHA . ' ' . _MD_EXTCAL_ORDER_BY_DESC);
192
193
        $select->addOption('cat_name ASC', _MD_EXTCAL_CATEGORY . ' ' . _MD_EXTCAL_ORDER_BY_ASC);
194
        $select->addOption('cat_name DESC', _MD_EXTCAL_CATEGORY . ' ' . _MD_EXTCAL_ORDER_BY_DESC);
195
196
        return $select;
197
    }
198
199
    /*******************************************************************
200
     *
201
     ******************************************************************
202
     * @param string $name
203
     * @param string $caption
204
     * @param        $defaut
205
     * @return XoopsFormSelect
206
     */
207
    public static function getListAndOr($name = 'andor', $caption = '', $defaut)
208
    {
209
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
210
211
        $select = new XoopsFormSelect($caption, $name, $defaut);
212
213
        $select->addOption('AND', _MD_EXTCAL_AND);
214
        $select->addOption('OR', _MD_EXTCAL_OR);
215
216
        return $select;
217
    }
218
219
    /*******************************************************************
220
     *
221
     ******************************************************************
222
     * @param        $name
223
     * @param        $caption
224
     * @param        $defaut
225
     * @param        $options
226
     * @param string $sep
227
     * @return XoopsFormSelect
228
     */
229
    public static function getList($name, $caption, $defaut, $options, $sep = ';')
230
    {
231
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
232
233
        $select = new XoopsFormSelect($caption, $name, $defaut);
234
        if (!is_array($options)) {
235
            $options = explode($sep, $options);
236
        }
237
238
        for ($h = 0, $count = count($options); $h < $count; ++$h) {
239
            $select->addOption($h, $options[$h]);
240
        }
241
242
        return $select;
243
    }
244
245
    /*******************************************************************
246
     *
247
     ******************************************************************
248
     * @param        $ts
249
     * @param        $startMonth
250
     * @param        $endMonth
251
     * @param string $mode
252
     * @return DateTime
253
     */
254
    public static function getDateBetweenDates($ts, $startMonth, $endMonth, $mode = 'w')
0 ignored issues
show
Unused Code introduced by
The parameter $mode is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
255
    {
256
        $d = new DateTime($periodStart);
0 ignored issues
show
Bug introduced by
The variable $periodStart does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
257
        $d->setTimestamp($ts);
258
259
        //echo "<br>affichage des periodes : <br>";
260
        $begin = new DateTime();
261
        $begin->setTimestamp($startMonth);
262
        //echo $begin->format("d/m/Y à H\hi:s").'<br>'; // 03/10/2007 à 19h39:53
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
263
264
        $end = new DateTime();
265
        $end->setTimestamp($endMonth);
266
        //echo $end->format("d/m/Y à H\hi:s").'<br>'; // 03/10/2007 à 19h39:53
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
267
        //echo "<hr>";
268
        $interval = DateInterval::createFromDateString('next sunday');
269
        $period   = new DatePeriod($begin, $interval, $end);
0 ignored issues
show
Unused Code introduced by
$period is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
270
        //echoDateArray($period);
271
272
        //echo "<hr>{$interval}";
273
        return $d;
274
275
        //echo mktime($heure, $minute, $seconde, $mois, $jour, $an);
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
276
277
        //
278
        //   $jour = date('d', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
279
        //   $mois = date('m', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
280
        //   $an = date('Y', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
281
        //   $heure = date('H', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
282
        //   $minute = date('i', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
283
        //   $seconde = date('s', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
284
        //   $d->setDate($heure,$minute,$seconde,$mois,$jour,$an);
0 ignored issues
show
Unused Code Comprehensibility introduced by
89% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
285
286
        // <?php
287
        // $interval = DateInterval::createFromDateString('next sunday');
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
288
        // $period = new DatePeriod($begin, $interval, $end);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
289
        // foreach ($period as $dt) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
290
        //   echo $dt->format( "l Y-m-d H:i:s\n" );
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
291
    }
292
293
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
294
    Sunday 2009-11-01 00:00:00
295
    Sunday 2009-11-08 00:00:00
296
    Sunday 2009-11-15 00:00:00
297
    Sunday 2009-11-22 00:00:00
298
    Sunday 2009-11-29 00:00:00
299
    Sunday 2009-12-06 00:00:00
300
    ...
301
    */
302
    /**
303
     * @param $period
304
     */
305
    public static function echoDateArray($period)
306
    {
307
        foreach ($period as $dt) {
308
            echo $dt->format("l Y-m-d H:i:s\n") . '<br>';
309
        }
310
    }
311
312
    /*****************************************************************/
313
    /**
314
     * @param        $t
315
     * @param string $msg
316
     */
317
    public static function ext_echoArray($t, $msg = '')
318
    {
319
        if ($msg != '') {
320
            echo "<hr>{$msg}<hr>";
321
        }
322
323
        $txt = print_r($t, true);
324
        echo '<pre>Number of items: ' . count($t) . "<br>{$txt}</pre>";
325
    }
326
327
    /*****************************************************************/
328
    /**
329
     * @param        $line
330
     * @param string $msg
331
     */
332
    public static function ext_echo($line, $msg = '')
333
    {
334
        if ($msg != '') {
335
            echo "<hr>{$msg}<hr>";
336
        }
337
        echo $line . '<br>';
338
    }
339
340
    /*****************************************************************/
341
    /**
342
     * @param        $tsName
343
     * @param string $msg
344
     */
345
    public static function ext_echoTSN($tsName, $msg = '')
346
    {
347
        global $$tsName;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
348
        $ts = $$tsName;
349
        static::ext_echoTSU($ts, $tsName, $msg = '');
350
    }
351
352
    /*****************************************************************/
353
    /**
354
     * @param        $ts
355
     * @param        $tsName
356
     * @param string $msg
357
     */
358
    public static function ext_echoTSU($ts, $tsName, $msg = '')
359
    {
360
        if ($msg != '') {
361
            echo "<hr>{$msg}<hr>";
362
        }
363
364
        echo 'date --->' . $tsName . ' = ' . $ts . ' - ' . date('d-m-Y H:m:s', $ts) . '<br>';
365
    }
366
367
    /*****************************************************************/
368
    /*****************************************************************/
369
    /**
370
     * @param        $date
371
     * @param string $sep
372
     *
373
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
374
     */
375
    public static function ext_convert_date($date, $sep = '-')
376
    {
377
        $lstSep = '/ .';
378
379
        for ($h = 0, $count = strlen($lstSep); $h < $count; ++$h) {
0 ignored issues
show
Unused Code introduced by
++$h; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
380
            $sep2replace = substr($lstSep, $h, 1);
381
            if (strpos($date, $sep2replace)) {
382
                $date = str_replace($sep2replace, $sep, $date);
383
            }
384
385
            return strtotime($date);
386
        }
387
    }
388
389
    /**
390
     * @param     $givendate
391
     * @param int $day
392
     * @param int $mth
393
     * @param int $yr
394
     *
395
     * @return int
396
     */
397
    public static function ext_DateAdd($givendate, $day = 0, $mth = 0, $yr = 0)
398
    {
399
        //$cd = strtotime($givendate);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
400
        $cd      = $givendate;
401
        $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));
402
403
        return strtotime($newdate);
404
    }
405
406
    /**
407
     * @param $date
408
     * @param $number
409
     * @param $interval
410
     *
411
     * @return int
412
     */
413
    public static function ext_DateAdd2($date, $number, $interval = 'd')
414
    {
415
        $date_time_array = getdate($date);
416
        $hours           = $date_time_array['hours'];
417
        $minutes         = $date_time_array['minutes'];
418
        $seconds         = $date_time_array['seconds'];
419
        $month           = $date_time_array['mon'];
420
        $day             = $date_time_array['mday'];
421
        $year            = $date_time_array['year'];
422
423
        switch ($interval) {
424
425
            case 'yyyy':
426
                $year += $number;
427
                break;
428
            case 'q':
429
                $year += ($number * 3);
430
                break;
431
            case 'm':
432
                $month += $number;
433
                break;
434
            case 'y':
435
            case 'd':
436
            case 'w':
437
                $day += $number;
438
                break;
439
            case 'ww':
440
                $day += ($number * 7);
441
                break;
442
            case 'h':
443
                $hours += $number;
444
                break;
445
            case 'n':
446
                $minutes += $number;
447
                break;
448
            case 's':
449
                $seconds += $number;
450
                break;
451
        }
452
        $timestamp = mktime($hours, $minutes, $seconds, $month, $day, $year);
453
454
        return $timestamp;
455
    }
456
457
    // function date_diff($date1, $date2) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
458
    //     $current = $date1;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
459
    //     $datetime2 = date_create($date2);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
460
    //     $count = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
461
    //     while (date_create($current) < $datetime2) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
462
    //         $current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current)));
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
463
    //         ++$count;
464
    //     }
465
    //     return $count;
466
    // }
467
468
    /**************************************************************************/
469
    /**
470
     * @param $color
471
     * @param $plancher
472
     * @param $plafond
473
     *
474
     * @return string
475
     */
476
    public static function getLighterColor($color, $plancher, $plafond)
477
    {
478
        require_once __DIR__ . '/colorTools.php';
479
480
        //$ct = new ColorTools();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
481
        //return $ct->eclaircir($color,$plancher,$plafond);
0 ignored issues
show
Unused Code Comprehensibility introduced by
85% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
482
        return ColorTools::eclaircir($color, $plancher, $plafond);
483
    }
484
    /**************************************************************************/
485
486
    /**
487
     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
488
     *
489
     * @param string $folder The full path of the directory to check
490
     *
491
     * @return void
492
     */
493
    public static function createFolder($folder)
494
    {
495
        try {
496
            if (!file_exists($folder)) {
497
                if (!mkdir($folder) && !is_dir($folder)) {
498
                    throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
499
                } else {
500
                    file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
501
                }
502
            }
503
        } catch (Exception $e) {
504
            echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>';
505
        }
506
    }
507
508
    /**
509
     * @param $file
510
     * @param $folder
511
     * @return bool
512
     */
513
    public static function copyFile($file, $folder)
514
    {
515
        return copy($file, $folder);
516
        //        try {
517
        //            if (!is_dir($folder)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
518
        //                throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
519
        //            } else {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
520
        //                return copy($file, $folder);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
521
        //            }
522
        //        } catch (Exception $e) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
523
        //            echo 'Caught exception: ', $e->getMessage(), "\n", "<br/>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
524
        //        }
525
        //        return false;
526
    }
527
528
    /**
529
     * @param $src
530
     * @param $dst
531
     */
532
    public static function recurseCopy($src, $dst)
533
    {
534
        $dir = opendir($src);
535
        //    @mkdir($dst);
536
        while (false !== ($file = readdir($dir))) {
537
            if (($file !== '.') && ($file !== '..')) {
538
                if (is_dir($src . '/' . $file)) {
539
                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
540
                } else {
541
                    copy($src . '/' . $file, $dst . '/' . $file);
542
                }
543
            }
544
        }
545
        closedir($dir);
546
    }
547
548
    /**
549
     *
550
     * Verifies XOOPS version meets minimum requirements for this module
551
     * @static
552
     * @param XoopsModule $module
0 ignored issues
show
Documentation introduced by
Should the type for parameter $module not be null|XoopsModule?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
553
     * @param null|string        $requiredVer
554
     *
555
     * @return bool true if meets requirements, false if not
556
     */
557
    public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null)
558
    {
559
        $moduleDirName = basename(dirname(__DIR__));
560
        if (null === $module) {
561
            $module        = XoopsModule::getByDirname($moduleDirName);
562
        }
563
        xoops_loadLanguage('admin', $moduleDirName);
564
        //check for minimum XOOPS version
565
        $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
566
        $currArray  = explode('.', $currentVer);
567
        if (null === $requiredVer) {
568
            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
569
        }
570
        $reqArray = explode('.', $requiredVer);
571
        $success  = true;
572
        foreach ($reqArray as $k => $v) {
573
            if (isset($currArray[$k])) {
574
                if ($currArray[$k] > $v) {
575
                    break;
576
                } elseif ($currArray[$k] == $v) {
577
                    continue;
578
                } else {
579
                    $success = false;
580
                    break;
581
                }
582
            } else {
583
                if ((int)$v > 0) { // handles things like x.x.x.0_RC2
584
                    $success = false;
585
                    break;
586
                }
587
            }
588
        }
589
590
        if (!$success) {
591
            $module->setErrors(sprintf(_AM_TAG_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
592
        }
593
594
        return $success;
595
    }
596
597
    /**
598
     *
599
     * Verifies PHP version meets minimum requirements for this module
600
     * @static
601
     * @param XoopsModule $module
602
     *
603
     * @return bool true if meets requirements, false if not
604
     */
605
    public static function checkVerPhp(XoopsModule $module)
606
    {
607
        xoops_loadLanguage('admin', $module->dirname());
608
        // check for minimum PHP version
609
        $success = true;
610
        $verNum  = PHP_VERSION;
611
        $reqVer  = $module->getInfo('min_php');
612
        if (false !== $reqVer && '' !== $reqVer) {
613
            if (version_compare($verNum, $reqVer, '<')) {
614
                $module->setErrors(sprintf(_AM_TAG_ERROR_BAD_PHP, $reqVer, $verNum));
615
                $success = false;
616
            }
617
        }
618
619
        return $success;
620
    }
621
}
622