Completed
Push — master ( 266444...2ebe1b )
by Michael
01:31
created

class/utility.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Class MyalbumUtil
5
 */
6
class ContactUtility extends XoopsObject
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...
7
{
8
    /**
9
     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
10
     *
11
     * @param string $folder The full path of the directory to check
12
     *
13
     * @return void
14
     */
15
    public static function createFolder($folder)
16
    {
17
        //        try {
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...
18
//            if (!mkdir($folder) && !is_dir($folder)) {
19
//                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
20
//            } else {
21
//                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
22
//            }
23
//        }
24
//        catch (Exception $e) {
25
//            echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>';
26
//        }
27
        try {
28
            if (!file_exists($folder)) {
29
                if (!mkdir($folder) && !is_dir($folder)) {
30
                    throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
31
                } else {
32
                    file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
33
                }
34
            }
35
        } catch (Exception $e) {
36
            echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>';
37
        }
38
    }
39
40
    /**
41
     * @param $file
42
     * @param $folder
43
     * @return bool
44
     */
45
    public static function copyFile($file, $folder)
46
    {
47
        return copy($file, $folder);
48
        //        try {
49
        //            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...
50
        //                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...
51
        //            } 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...
52
        //                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...
53
        //            }
54
        //        } 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...
55
        //            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...
56
        //        }
57
        //        return false;
58
    }
59
60
    /**
61
     * @param $src
62
     * @param $dst
63
     */
64
    public static function recurseCopy($src, $dst)
65
    {
66
        $dir = opendir($src);
67
        //    @mkdir($dst);
68
        while (false !== ($file = readdir($dir))) {
69
            if (($file !== '.') && ($file !== '..')) {
70
                if (is_dir($src . '/' . $file)) {
71
                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
72
                } else {
73
                    copy($src . '/' . $file, $dst . '/' . $file);
74
                }
75
            }
76
        }
77
        closedir($dir);
78
    }
79
80
    /**
81
     *
82
     * Verifies XOOPS version meets minimum requirements for this module
83
     * @static
84
     * @param XoopsModule $module
85
     *
86
     * @return bool true if meets requirements, false if not
87
     */
88
    public static function checkVerXoops(XoopsModule $module)
89
    {
90
        xoops_loadLanguage('admin', $module->dirname());
91
        //check for minimum XOOPS version
92
        $currentVer  = substr(XOOPS_VERSION, 6); // get the numeric part of string
93
        $currArray   = explode('.', $currentVer);
94
        $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
95
        $reqArray    = explode('.', $requiredVer);
96
        $success     = true;
97
        foreach ($reqArray as $k => $v) {
98
            if (isset($currArray[$k])) {
99
                if ($currArray[$k] > $v) {
100
                    break;
101
                } elseif ($currArray[$k] == $v) {
102
                    continue;
103
                } else {
104
                    $success = false;
105
                    break;
106
                }
107
            } else {
108
                if ((int)$v > 0) { // handles things like x.x.x.0_RC2
109
                    $success = false;
110
                    break;
111
                }
112
            }
113
        }
114
115
        if (!$success) {
116
            $module->setErrors(sprintf(_AM_CONTACT_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
117
        }
118
119
        return $success;
120
    }
121
122
    /**
123
     *
124
     * Verifies PHP version meets minimum requirements for this module
125
     * @static
126
     * @param XoopsModule $module
127
     *
128
     * @return bool true if meets requirements, false if not
129
     */
130
    public static function checkVerPhp(XoopsModule $module)
131
    {
132
        xoops_loadLanguage('admin', $module->dirname());
133
        // check for minimum PHP version
134
        $success = true;
135
        $verNum  = PHP_VERSION;
136
        $reqVer  =& $module->getInfo('min_php');
137
        if (false !== $reqVer && '' !== $reqVer) {
138
            if (version_compare($verNum, $reqVer, '<')) {
139
                $module->setErrors(sprintf(_AM_CONTACT_ERROR_BAD_PHP, $reqVer, $verNum));
140
                $success = false;
141
            }
142
        }
143
144
        return $success;
145
    }
146
}
147