Passed
Push — master ( ed55b2...84c1d9 )
by Michael
12:36 queued 12s
created
class/Albums.php 2 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -11,154 +11,154 @@
 block discarded – undo
11 11
  */
12 12
 class Albums extends \XoopsObject
13 13
 {
14
-    /**
15
-     * Albums constructor.
16
-     * @param null $fid
17
-     */
18
-    public function __construct($fid = null)
19
-    {
20
-        $this->initVar('abid', \XOBJ_DTYPE_INT, 0, false);
21
-        $this->initVar('cid', \XOBJ_DTYPE_INT, 0, false);
22
-        $this->initVar('aids', \XOBJ_DTYPE_ARRAY, [], false);
23
-        $this->initVar('sids', \XOBJ_DTYPE_ARRAY, [], false);
24
-        $this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false, 128);
25
-        $this->initVar('image', \XOBJ_DTYPE_TXTBOX, null, false, 255);
26
-        $this->initVar('path', \XOBJ_DTYPE_TXTBOX, null, false, 255);
27
-        $this->initVar('artists', \XOBJ_DTYPE_INT, 0, false);
28
-        $this->initVar('songs', \XOBJ_DTYPE_INT, 0, false);
29
-        $this->initVar('hits', \XOBJ_DTYPE_INT, 0, false);
30
-        $this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false);
31
-        $this->initVar('votes', \XOBJ_DTYPE_INT, 0, false);
32
-        $this->initVar('created', \XOBJ_DTYPE_INT, 0, false);
33
-        $this->initVar('updated', \XOBJ_DTYPE_INT, 0, false);
34
-    }
35
-
36
-    /**
37
-     * @param bool $as_array
38
-     * @return array|string
39
-     */
40
-    public function getForm($as_array = false)
41
-    {
42
-        return FormController::getFormAlbums($this, $as_array);
43
-    }
44
-
45
-    /**
46
-     * @param bool $extra
47
-     * @return array
48
-     */
49
-    public function toArray($extra = true): array
50
-    {
51
-        $ret  = parent::toArray();
52
-        $form = $this->getForm(true);
53
-        foreach ($form as $key => $element) {
54
-            $ret['form'][$key] = $element->render();
55
-        }
56
-        foreach (['created', 'updated'] as $key) {
57
-            if ($this->getVar($key) > 0) {
58
-                $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
59
-                $ret[$key]         = \date(_DATESTRING, $this->getVar($key));
60
-            }
61
-        }
62
-        $ret['picture'] = $this->getImage('image', false);
63
-        $ret['rank']    = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN;
64
-        $ret['url']     = $this->getURL(true);
65
-
66
-        if (!$extra) {
67
-            return $ret;
68
-        }
69
-
70
-        if (0 != $this->getVar('cid')) {
71
-            $categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category');
72
-            $category        = $categoryHandler->get($this->getVar('cid'));
73
-            if (\is_object($category)) {
74
-                $ret['category'] = $category->toArray(false);
75
-            }
76
-        }
77
-
78
-        if (0 != \count($this->getVar('aids'))) {
79
-            $artistsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
80
-            foreach ($this->getVar('aids') as $aid) {
81
-                $artist = $artistsHandler->get($aid);
82
-                if (\is_object($artist)) {
83
-                    $ret['artists_array'][$aid] = $artist->toArray(false);
84
-                }
85
-            }
86
-        }
87
-
88
-        if (0 != \count($this->getVar('sids'))) {
89
-            $songsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs');
90
-            $criteria     = new \Criteria('sid', '(' . \implode(',', $this->getVar('sids')) . ')', 'IN');
91
-            $criteria->setSort('traxid');
92
-            $criteria->setOrder('ASC');
93
-            foreach ($songsHandler->getObjects($criteria, true) as $sid => $song) {
94
-                if (\is_object($song)) {
95
-                    $ret['songs_array'][$sid] = $song->toArray(false);
96
-                }
97
-            }
98
-        }
99
-
100
-        return $ret;
101
-    }
102
-
103
-    /**
104
-     * @param string $field
105
-     * @param bool   $local
106
-     * @return bool|string
107
-     */
108
-    public function getImage($field = 'image', $local = false)
109
-    {
110
-        if ('' == $this->getVar($field)) {
111
-            return false;
112
-        }
113
-        if (!\file_exists($GLOBALS['xoops']->path($this->getVar('path') . $this->getVar($field)))) {
114
-            return false;
115
-        }
116
-        if (!$local) {
117
-            return XOOPS_URL . '/' . \str_replace(DS, '/', $this->getVar('path')) . $this->getVar($field);
118
-        }
119
-
120
-        return XOOPS_ROOT_PATH . DS . $this->getVar('path') . $this->getVar($field);
121
-    }
122
-
123
-    /**
124
-     * @return string
125
-     */
126
-    public function getURL(): string
127
-    {
128
-        global $file, $op, $fct, $id, $value, $gid, $vid, $vcid, $cid, $start, $limit;
129
-        if ($GLOBALS['songlistModuleConfig']['htaccess']) {
130
-            if (0 != $id) {
131
-                $artistHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Albums');
132
-                $artist        = $artistHandler->get($id);
133
-                if (\is_object($artist) && !$artist->isNew()) {
134
-                    return XOOPS_URL
135
-                           . '/'
136
-                           . $GLOBALS['songlistModuleConfig']['baseofurl']
137
-                           . '/albums/'
138
-                           . \urlencode(\str_replace([' ', \chr(9)], '-', $artist->getVar('title')))
139
-                           . '/'
140
-                           . $start
141
-                           . '-'
142
-                           . $id
143
-                           . '-'
144
-                           . $op
145
-                           . '-'
146
-                           . $fct
147
-                           . '-'
148
-                           . $gid
149
-                           . '-'
150
-                           . $cid
151
-                           . '/'
152
-                           . \urlencode($value)
153
-                           . $GLOBALS['songlistModuleConfig']['endofurl'];
154
-                }
155
-
156
-                return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/albums/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
157
-            }
158
-
159
-            return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/albums/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
160
-        }
161
-
162
-        return XOOPS_URL . '/modules/songlist/albums.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start;
163
-    }
14
+	/**
15
+	 * Albums constructor.
16
+	 * @param null $fid
17
+	 */
18
+	public function __construct($fid = null)
19
+	{
20
+		$this->initVar('abid', \XOBJ_DTYPE_INT, 0, false);
21
+		$this->initVar('cid', \XOBJ_DTYPE_INT, 0, false);
22
+		$this->initVar('aids', \XOBJ_DTYPE_ARRAY, [], false);
23
+		$this->initVar('sids', \XOBJ_DTYPE_ARRAY, [], false);
24
+		$this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false, 128);
25
+		$this->initVar('image', \XOBJ_DTYPE_TXTBOX, null, false, 255);
26
+		$this->initVar('path', \XOBJ_DTYPE_TXTBOX, null, false, 255);
27
+		$this->initVar('artists', \XOBJ_DTYPE_INT, 0, false);
28
+		$this->initVar('songs', \XOBJ_DTYPE_INT, 0, false);
29
+		$this->initVar('hits', \XOBJ_DTYPE_INT, 0, false);
30
+		$this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false);
31
+		$this->initVar('votes', \XOBJ_DTYPE_INT, 0, false);
32
+		$this->initVar('created', \XOBJ_DTYPE_INT, 0, false);
33
+		$this->initVar('updated', \XOBJ_DTYPE_INT, 0, false);
34
+	}
35
+
36
+	/**
37
+	 * @param bool $as_array
38
+	 * @return array|string
39
+	 */
40
+	public function getForm($as_array = false)
41
+	{
42
+		return FormController::getFormAlbums($this, $as_array);
43
+	}
44
+
45
+	/**
46
+	 * @param bool $extra
47
+	 * @return array
48
+	 */
49
+	public function toArray($extra = true): array
50
+	{
51
+		$ret  = parent::toArray();
52
+		$form = $this->getForm(true);
53
+		foreach ($form as $key => $element) {
54
+			$ret['form'][$key] = $element->render();
55
+		}
56
+		foreach (['created', 'updated'] as $key) {
57
+			if ($this->getVar($key) > 0) {
58
+				$ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
59
+				$ret[$key]         = \date(_DATESTRING, $this->getVar($key));
60
+			}
61
+		}
62
+		$ret['picture'] = $this->getImage('image', false);
63
+		$ret['rank']    = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN;
64
+		$ret['url']     = $this->getURL(true);
65
+
66
+		if (!$extra) {
67
+			return $ret;
68
+		}
69
+
70
+		if (0 != $this->getVar('cid')) {
71
+			$categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category');
72
+			$category        = $categoryHandler->get($this->getVar('cid'));
73
+			if (\is_object($category)) {
74
+				$ret['category'] = $category->toArray(false);
75
+			}
76
+		}
77
+
78
+		if (0 != \count($this->getVar('aids'))) {
79
+			$artistsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
80
+			foreach ($this->getVar('aids') as $aid) {
81
+				$artist = $artistsHandler->get($aid);
82
+				if (\is_object($artist)) {
83
+					$ret['artists_array'][$aid] = $artist->toArray(false);
84
+				}
85
+			}
86
+		}
87
+
88
+		if (0 != \count($this->getVar('sids'))) {
89
+			$songsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs');
90
+			$criteria     = new \Criteria('sid', '(' . \implode(',', $this->getVar('sids')) . ')', 'IN');
91
+			$criteria->setSort('traxid');
92
+			$criteria->setOrder('ASC');
93
+			foreach ($songsHandler->getObjects($criteria, true) as $sid => $song) {
94
+				if (\is_object($song)) {
95
+					$ret['songs_array'][$sid] = $song->toArray(false);
96
+				}
97
+			}
98
+		}
99
+
100
+		return $ret;
101
+	}
102
+
103
+	/**
104
+	 * @param string $field
105
+	 * @param bool   $local
106
+	 * @return bool|string
107
+	 */
108
+	public function getImage($field = 'image', $local = false)
109
+	{
110
+		if ('' == $this->getVar($field)) {
111
+			return false;
112
+		}
113
+		if (!\file_exists($GLOBALS['xoops']->path($this->getVar('path') . $this->getVar($field)))) {
114
+			return false;
115
+		}
116
+		if (!$local) {
117
+			return XOOPS_URL . '/' . \str_replace(DS, '/', $this->getVar('path')) . $this->getVar($field);
118
+		}
119
+
120
+		return XOOPS_ROOT_PATH . DS . $this->getVar('path') . $this->getVar($field);
121
+	}
122
+
123
+	/**
124
+	 * @return string
125
+	 */
126
+	public function getURL(): string
127
+	{
128
+		global $file, $op, $fct, $id, $value, $gid, $vid, $vcid, $cid, $start, $limit;
129
+		if ($GLOBALS['songlistModuleConfig']['htaccess']) {
130
+			if (0 != $id) {
131
+				$artistHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Albums');
132
+				$artist        = $artistHandler->get($id);
133
+				if (\is_object($artist) && !$artist->isNew()) {
134
+					return XOOPS_URL
135
+						   . '/'
136
+						   . $GLOBALS['songlistModuleConfig']['baseofurl']
137
+						   . '/albums/'
138
+						   . \urlencode(\str_replace([' ', \chr(9)], '-', $artist->getVar('title')))
139
+						   . '/'
140
+						   . $start
141
+						   . '-'
142
+						   . $id
143
+						   . '-'
144
+						   . $op
145
+						   . '-'
146
+						   . $fct
147
+						   . '-'
148
+						   . $gid
149
+						   . '-'
150
+						   . $cid
151
+						   . '/'
152
+						   . \urlencode($value)
153
+						   . $GLOBALS['songlistModuleConfig']['endofurl'];
154
+				}
155
+
156
+				return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/albums/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
157
+			}
158
+
159
+			return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/albums/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
160
+		}
161
+
162
+		return XOOPS_URL . '/modules/songlist/albums.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start;
163
+	}
164 164
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace XoopsModules\Songlist;
4 4
 
5
-require_once \dirname(__DIR__) . '/include/songlist.object.php';
5
+require_once \dirname(__DIR__).'/include/songlist.object.php';
6 6
 // require_once \dirname(__DIR__) . '/include/songlist.form.php';
7 7
 use  XoopsModules\Songlist\Form\FormController;
8 8
 
@@ -54,20 +54,20 @@  discard block
 block discarded – undo
54 54
             $ret['form'][$key] = $element->render();
55 55
         }
56 56
         foreach (['created', 'updated'] as $key) {
57
-            if ($this->getVar($key) > 0) {
57
+            if ($this->getVar($key)>0) {
58 58
                 $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
59 59
                 $ret[$key]         = \date(_DATESTRING, $this->getVar($key));
60 60
             }
61 61
         }
62 62
         $ret['picture'] = $this->getImage('image', false);
63
-        $ret['rank']    = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN;
63
+        $ret['rank']    = \number_format(($this->getVar('rank')>0 && $this->getVar('votes')>0 ? $this->getVar('rank')/$this->getVar('votes') : 0), 2).\_MI_SONGLIST_OFTEN;
64 64
         $ret['url']     = $this->getURL(true);
65 65
 
66 66
         if (!$extra) {
67 67
             return $ret;
68 68
         }
69 69
 
70
-        if (0 != $this->getVar('cid')) {
70
+        if (0!=$this->getVar('cid')) {
71 71
             $categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category');
72 72
             $category        = $categoryHandler->get($this->getVar('cid'));
73 73
             if (\is_object($category)) {
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             }
76 76
         }
77 77
 
78
-        if (0 != \count($this->getVar('aids'))) {
78
+        if (0!=\count($this->getVar('aids'))) {
79 79
             $artistsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
80 80
             foreach ($this->getVar('aids') as $aid) {
81 81
                 $artist = $artistsHandler->get($aid);
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
             }
86 86
         }
87 87
 
88
-        if (0 != \count($this->getVar('sids'))) {
88
+        if (0!=\count($this->getVar('sids'))) {
89 89
             $songsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs');
90
-            $criteria     = new \Criteria('sid', '(' . \implode(',', $this->getVar('sids')) . ')', 'IN');
90
+            $criteria     = new \Criteria('sid', '('.\implode(',', $this->getVar('sids')).')', 'IN');
91 91
             $criteria->setSort('traxid');
92 92
             $criteria->setOrder('ASC');
93 93
             foreach ($songsHandler->getObjects($criteria, true) as $sid => $song) {
@@ -107,17 +107,17 @@  discard block
 block discarded – undo
107 107
      */
108 108
     public function getImage($field = 'image', $local = false)
109 109
     {
110
-        if ('' == $this->getVar($field)) {
110
+        if (''==$this->getVar($field)) {
111 111
             return false;
112 112
         }
113
-        if (!\file_exists($GLOBALS['xoops']->path($this->getVar('path') . $this->getVar($field)))) {
113
+        if (!\file_exists($GLOBALS['xoops']->path($this->getVar('path').$this->getVar($field)))) {
114 114
             return false;
115 115
         }
116 116
         if (!$local) {
117
-            return XOOPS_URL . '/' . \str_replace(DS, '/', $this->getVar('path')) . $this->getVar($field);
117
+            return XOOPS_URL.'/'.\str_replace(DS, '/', $this->getVar('path')).$this->getVar($field);
118 118
         }
119 119
 
120
-        return XOOPS_ROOT_PATH . DS . $this->getVar('path') . $this->getVar($field);
120
+        return XOOPS_ROOT_PATH.DS.$this->getVar('path').$this->getVar($field);
121 121
     }
122 122
 
123 123
     /**
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
     {
128 128
         global $file, $op, $fct, $id, $value, $gid, $vid, $vcid, $cid, $start, $limit;
129 129
         if ($GLOBALS['songlistModuleConfig']['htaccess']) {
130
-            if (0 != $id) {
130
+            if (0!=$id) {
131 131
                 $artistHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Albums');
132 132
                 $artist        = $artistHandler->get($id);
133 133
                 if (\is_object($artist) && !$artist->isNew()) {
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
                            . $GLOBALS['songlistModuleConfig']['endofurl'];
154 154
                 }
155 155
 
156
-                return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/albums/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
156
+                return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/albums/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.\urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl'];
157 157
             }
158 158
 
159
-            return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/albums/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
159
+            return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/albums/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.\urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl'];
160 160
         }
161 161
 
162
-        return XOOPS_URL . '/modules/songlist/albums.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start;
162
+        return XOOPS_URL.'/modules/songlist/albums.php?op='.$op.'&fct='.$fct.'&id='.$id.'&value='.\urlencode($value ?? '').'&gid='.$gid.'&vid='.$vid.'&cid='.$cid.'&start='.$start;
163 163
     }
164 164
 }
Please login to merge, or discard this patch.
class/common/Migrate.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -25,49 +25,49 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class Migrate extends \Xmf\Database\Migrate
27 27
 {
28
-    private $moduleDirName;
29
-    private $renameColumns;
30
-    private $renameTables;
28
+	private $moduleDirName;
29
+	private $renameColumns;
30
+	private $renameTables;
31 31
 
32
-    /**
33
-     * Migrate constructor.
34
-     * @throws \RuntimeException
35
-     * @throws \InvalidArgumentException
36
-     */
37
-    public function __construct()
38
-    {
39
-        $class = __NAMESPACE__ . '\\' . 'Configurator';
40
-        if (!\class_exists($class)) {
41
-            throw new \RuntimeException("Class '$class' not found");
42
-        }
43
-        $configurator       = new $class();
44
-        $this->renameTables = $configurator->renameTables;
45
-        $this->renameColumns = $configurator->renameColumns;
32
+	/**
33
+	 * Migrate constructor.
34
+	 * @throws \RuntimeException
35
+	 * @throws \InvalidArgumentException
36
+	 */
37
+	public function __construct()
38
+	{
39
+		$class = __NAMESPACE__ . '\\' . 'Configurator';
40
+		if (!\class_exists($class)) {
41
+			throw new \RuntimeException("Class '$class' not found");
42
+		}
43
+		$configurator       = new $class();
44
+		$this->renameTables = $configurator->renameTables;
45
+		$this->renameColumns = $configurator->renameColumns;
46 46
 
47
-        $this->moduleDirName = \basename(\dirname(__DIR__, 2));
48
-        parent::__construct($this->moduleDirName);
49
-    }
47
+		$this->moduleDirName = \basename(\dirname(__DIR__, 2));
48
+		parent::__construct($this->moduleDirName);
49
+	}
50 50
 
51
-    /**
52
-     * change table prefix if needed
53
-     */
54
-    private function changePrefix()
55
-    {
51
+	/**
52
+	 * change table prefix if needed
53
+	 */
54
+	private function changePrefix()
55
+	{
56 56
 //        foreach ($this->renameTables as $oldName => $newName) {
57 57
 //            if ($this->tableHandler->useTable($oldName) && !$this->tableHandler->useTable($newName)) {
58 58
 //                $this->tableHandler->renameTable($oldName, $newName);
59 59
 //            }
60 60
 //        }
61
-    }
61
+	}
62 62
 
63
-    /**
64
-     * Change integer IPv4 column to varchar IPv6 capable
65
-     *
66
-     * @param string $tableName  table to convert
67
-     * @param string $columnName column with IP address
68
-     */
69
-    private function convertIPAddresses($tableName, $columnName)
70
-    {
63
+	/**
64
+	 * Change integer IPv4 column to varchar IPv6 capable
65
+	 *
66
+	 * @param string $tableName  table to convert
67
+	 * @param string $columnName column with IP address
68
+	 */
69
+	private function convertIPAddresses($tableName, $columnName)
70
+	{
71 71
 //        if ($this->tableHandler->useTable($tableName)) {
72 72
 //            $attributes = $this->tableHandler->getColumnAttributes($tableName, $columnName);
73 73
 //            if (false !== \mb_strpos($attributes, ' int(')) {
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
 //                $this->tableHandler->update($tableName, [$columnName => "INET_NTOA($columnName)"], '', false);
80 80
 //            }
81 81
 //        }
82
-    }
82
+	}
83 83
 
84
-    /**
85
-     * @deprecated (just as an example here)
86
-     * Move do* columns from newbb_posts to newbb_posts_text table
87
-     */
88
-    private function moveDoColumns()
89
-    {
84
+	/**
85
+	 * @deprecated (just as an example here)
86
+	 * Move do* columns from newbb_posts to newbb_posts_text table
87
+	 */
88
+	private function moveDoColumns()
89
+	{
90 90
 //        $tableName    = 'newbb_posts_text';
91 91
 //        $srcTableName = 'newbb_posts';
92 92
 //        if ($this->tableHandler->useTable($tableName)
@@ -100,62 +100,62 @@  discard block
 block discarded – undo
100 100
 //                $this->tableHandler->addToQueue($sql);
101 101
 //            }
102 102
 //        }
103
-    }
103
+	}
104 104
 
105
-    /**
106
-     * rename table if needed
107
-     */
108
-    private function renameTable()
109
-    {
110
-        foreach ($this->renameTables as $oldName => $newName) {
111
-            if ($this->tableHandler->useTable($oldName) && !$this->tableHandler->useTable($newName)) {
112
-                $this->tableHandler->renameTable($oldName, $newName);
113
-            }
114
-        }
115
-    }
105
+	/**
106
+	 * rename table if needed
107
+	 */
108
+	private function renameTable()
109
+	{
110
+		foreach ($this->renameTables as $oldName => $newName) {
111
+			if ($this->tableHandler->useTable($oldName) && !$this->tableHandler->useTable($newName)) {
112
+				$this->tableHandler->renameTable($oldName, $newName);
113
+			}
114
+		}
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * rename columns if needed
120
-     */
121
-    private function renameColumns()
122
-    {
123
-        foreach ($this->renameColumns as $tableName) {
124
-            if ($this->tableHandler->useTable($tableName)) {
125
-                $oldName = $tableName['from'];
126
-                $newName = $tableName['to'];
127
-                $attributes = $this->tableHandler->getColumnAttributes($tableName, $oldName);
128
-                if (false !== \strpos($attributes, ' int(')) {
129
-                    $this->tableHandler->alterColumn($tableName, $oldName, $attributes, $newName);
130
-                }
131
-            }
132
-        }
133
-    }
118
+	/**
119
+	 * rename columns if needed
120
+	 */
121
+	private function renameColumns()
122
+	{
123
+		foreach ($this->renameColumns as $tableName) {
124
+			if ($this->tableHandler->useTable($tableName)) {
125
+				$oldName = $tableName['from'];
126
+				$newName = $tableName['to'];
127
+				$attributes = $this->tableHandler->getColumnAttributes($tableName, $oldName);
128
+				if (false !== \strpos($attributes, ' int(')) {
129
+					$this->tableHandler->alterColumn($tableName, $oldName, $attributes, $newName);
130
+				}
131
+			}
132
+		}
133
+	}
134 134
 
135
-    /**
136
-     * Perform any upfront actions before synchronizing the schema
137
-     *
138
-     * Some typical uses include
139
-     *   table and column renames
140
-     *   data conversions
141
-     */
142
-    protected function preSyncActions()
143
-    {
144
-        // change 'bb' table prefix to 'newbb'
145
-        $this->changePrefix();
146
-        // columns dohtml, dosmiley, doxcode, doimage and dobr moved between tables as some point
147
-        $this->moveDoColumns();
148
-        // Convert IP address columns from int to readable varchar(45) for IPv6
135
+	/**
136
+	 * Perform any upfront actions before synchronizing the schema
137
+	 *
138
+	 * Some typical uses include
139
+	 *   table and column renames
140
+	 *   data conversions
141
+	 */
142
+	protected function preSyncActions()
143
+	{
144
+		// change 'bb' table prefix to 'newbb'
145
+		$this->changePrefix();
146
+		// columns dohtml, dosmiley, doxcode, doimage and dobr moved between tables as some point
147
+		$this->moveDoColumns();
148
+		// Convert IP address columns from int to readable varchar(45) for IPv6
149 149
 //        $this->convertIPAddresses('newbb_posts', 'poster_ip');
150 150
 //        $this->convertIPAddresses('newbb_report', 'reporter_ip');
151 151
 
152
-        // rename table
153
-        if ($this->renameTables && \is_array($this->renameTables)) {
154
-            $this->renameTable();
155
-        }
156
-        // rename column
157
-        if ($this->renameColumns && \is_array($this->renameColumns)) {
158
-            $this->renameColumns();
159
-        }
160
-    }
152
+		// rename table
153
+		if ($this->renameTables && \is_array($this->renameTables)) {
154
+			$this->renameTable();
155
+		}
156
+		// rename column
157
+		if ($this->renameColumns && \is_array($this->renameColumns)) {
158
+			$this->renameColumns();
159
+		}
160
+	}
161 161
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function __construct()
38 38
     {
39
-        $class = __NAMESPACE__ . '\\' . 'Configurator';
39
+        $class = __NAMESPACE__.'\\'.'Configurator';
40 40
         if (!\class_exists($class)) {
41 41
             throw new \RuntimeException("Class '$class' not found");
42 42
         }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
                 $oldName = $tableName['from'];
126 126
                 $newName = $tableName['to'];
127 127
                 $attributes = $this->tableHandler->getColumnAttributes($tableName, $oldName);
128
-                if (false !== \strpos($attributes, ' int(')) {
128
+                if (false!==\strpos($attributes, ' int(')) {
129 129
                     $this->tableHandler->alterColumn($tableName, $oldName, $attributes, $newName);
130 130
                 }
131 131
             }
Please login to merge, or discard this patch.
class/common/Cloner.php 2 patches
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -9,101 +9,101 @@
 block discarded – undo
9 9
  */
10 10
 class Cloner
11 11
 {
12
-    // recursive cloning script
13
-    /**
14
-     * @param $path
15
-     */
16
-    public static function cloneFileFolder($path)
17
-    {
18
-        global $patKeys;
19
-        global $patValues;
12
+	// recursive cloning script
13
+	/**
14
+	 * @param $path
15
+	 */
16
+	public static function cloneFileFolder($path)
17
+	{
18
+		global $patKeys;
19
+		global $patValues;
20 20
 
21
-        $newPath = \str_replace($patKeys[0], $patValues[0], $path);
21
+		$newPath = \str_replace($patKeys[0], $patValues[0], $path);
22 22
 
23
-        if (\is_dir($path)) {
24
-            // create new dir
25
-            if (!\mkdir($newPath) && !\is_dir($newPath)) {
26
-                throw new \RuntimeException(\sprintf('Directory "%s" was not created', $newPath));
27
-            }
23
+		if (\is_dir($path)) {
24
+			// create new dir
25
+			if (!\mkdir($newPath) && !\is_dir($newPath)) {
26
+				throw new \RuntimeException(\sprintf('Directory "%s" was not created', $newPath));
27
+			}
28 28
 
29
-            // check all files in dir, and process it
30
-            $handle = \opendir($path);
31
-            if (false !== $handle) {
32
-                while (false !== ($file = \readdir($handle))) {
33
-                    if (0 !== \mb_strpos($file, '.')) {
34
-                        self::cloneFileFolder("{$path}/{$file}");
35
-                    }
36
-                }
37
-                \closedir($handle);
38
-            }
39
-        } else {
40
-            $noChangeExtensions = ['jpeg', 'jpg', 'gif', 'png', 'zip', 'ttf'];
41
-            if (\in_array(\mb_strtolower((string)\pathinfo($path, \PATHINFO_EXTENSION)), $noChangeExtensions, true)) {
42
-                // image
43
-                \copy($path, $newPath);
44
-            } else {
45
-                // file, read it
46
-                $content = file_get_contents($path);
47
-                $content = \str_replace($patKeys, $patValues, $content);
48
-                file_put_contents($newPath, $content);
49
-            }
50
-        }
51
-    }
29
+			// check all files in dir, and process it
30
+			$handle = \opendir($path);
31
+			if (false !== $handle) {
32
+				while (false !== ($file = \readdir($handle))) {
33
+					if (0 !== \mb_strpos($file, '.')) {
34
+						self::cloneFileFolder("{$path}/{$file}");
35
+					}
36
+				}
37
+				\closedir($handle);
38
+			}
39
+		} else {
40
+			$noChangeExtensions = ['jpeg', 'jpg', 'gif', 'png', 'zip', 'ttf'];
41
+			if (\in_array(\mb_strtolower((string)\pathinfo($path, \PATHINFO_EXTENSION)), $noChangeExtensions, true)) {
42
+				// image
43
+				\copy($path, $newPath);
44
+			} else {
45
+				// file, read it
46
+				$content = file_get_contents($path);
47
+				$content = \str_replace($patKeys, $patValues, $content);
48
+				file_put_contents($newPath, $content);
49
+			}
50
+		}
51
+	}
52 52
 
53
-    /**
54
-     * @param $dirname
55
-     *
56
-     * @return bool
57
-     */
58
-    public static function createLogo($dirname): bool
59
-    {
60
-        if (!\extension_loaded('gd')) {
61
-            return false;
62
-        }
63
-        $requiredFunctions = [
64
-            'imagecreatefrompng',
65
-            'imagecolorallocate',
66
-            'imagefilledrectangle',
67
-            'imagepng',
68
-            'imagedestroy',
69
-            'imagefttext',
70
-            'imagealphablending',
71
-            'imagesavealpha',
72
-        ];
73
-        foreach ($requiredFunctions as $func) {
74
-            if (!\function_exists($func)) {
75
-                return false;
76
-            }
77
-        }
78
-        //            unset($func);
53
+	/**
54
+	 * @param $dirname
55
+	 *
56
+	 * @return bool
57
+	 */
58
+	public static function createLogo($dirname): bool
59
+	{
60
+		if (!\extension_loaded('gd')) {
61
+			return false;
62
+		}
63
+		$requiredFunctions = [
64
+			'imagecreatefrompng',
65
+			'imagecolorallocate',
66
+			'imagefilledrectangle',
67
+			'imagepng',
68
+			'imagedestroy',
69
+			'imagefttext',
70
+			'imagealphablending',
71
+			'imagesavealpha',
72
+		];
73
+		foreach ($requiredFunctions as $func) {
74
+			if (!\function_exists($func)) {
75
+				return false;
76
+			}
77
+		}
78
+		//            unset($func);
79 79
 
80
-        if (!\file_exists($imageBase = $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/logoModule.png'))
81
-            || !\file_exists($font = $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/VeraBd.ttf'))) {
82
-            return false;
83
-        }
80
+		if (!\file_exists($imageBase = $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/logoModule.png'))
81
+			|| !\file_exists($font = $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/VeraBd.ttf'))) {
82
+			return false;
83
+		}
84 84
 
85
-        $imageModule = \imagecreatefrompng($imageBase);
86
-        // save existing alpha channel
87
-        imagealphablending($imageModule, false);
88
-        imagesavealpha($imageModule, true);
85
+		$imageModule = \imagecreatefrompng($imageBase);
86
+		// save existing alpha channel
87
+		imagealphablending($imageModule, false);
88
+		imagesavealpha($imageModule, true);
89 89
 
90
-        //Erase old text
91
-        $greyColor = \imagecolorallocate($imageModule, 237, 237, 237);
92
-        \imagefilledrectangle($imageModule, 5, 35, 85, 46, $greyColor);
90
+		//Erase old text
91
+		$greyColor = \imagecolorallocate($imageModule, 237, 237, 237);
92
+		\imagefilledrectangle($imageModule, 5, 35, 85, 46, $greyColor);
93 93
 
94
-        // Write text
95
-        $textColor     = \imagecolorallocate($imageModule, 0, 0, 0);
96
-        $spaceToBorder = (int)((80 - \mb_strlen($dirname) * 6.5) / 2);
97
-        \imagefttext($imageModule, 8.5, 0, $spaceToBorder, 45, $textColor, $font, \ucfirst($dirname), []);
94
+		// Write text
95
+		$textColor     = \imagecolorallocate($imageModule, 0, 0, 0);
96
+		$spaceToBorder = (int)((80 - \mb_strlen($dirname) * 6.5) / 2);
97
+		\imagefttext($imageModule, 8.5, 0, $spaceToBorder, 45, $textColor, $font, \ucfirst($dirname), []);
98 98
 
99
-        // Set transparency color
100
-        //$white = imagecolorallocatealpha($imageModule, 255, 255, 255, 127);
101
-        //imagefill($imageModule, 0, 0, $white);
102
-        //imagecolortransparent($imageModule, $white);
99
+		// Set transparency color
100
+		//$white = imagecolorallocatealpha($imageModule, 255, 255, 255, 127);
101
+		//imagefill($imageModule, 0, 0, $white);
102
+		//imagecolortransparent($imageModule, $white);
103 103
 
104
-        \imagepng($imageModule, $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/logoModule.png'));
105
-        \imagedestroy($imageModule);
104
+		\imagepng($imageModule, $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/logoModule.png'));
105
+		\imagedestroy($imageModule);
106 106
 
107
-        return true;
108
-    }
107
+		return true;
108
+	}
109 109
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 
29 29
             // check all files in dir, and process it
30 30
             $handle = \opendir($path);
31
-            if (false !== $handle) {
32
-                while (false !== ($file = \readdir($handle))) {
33
-                    if (0 !== \mb_strpos($file, '.')) {
31
+            if (false!==$handle) {
32
+                while (false!==($file = \readdir($handle))) {
33
+                    if (0!==\mb_strpos($file, '.')) {
34 34
                         self::cloneFileFolder("{$path}/{$file}");
35 35
                     }
36 36
                 }
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
             }
39 39
         } else {
40 40
             $noChangeExtensions = ['jpeg', 'jpg', 'gif', 'png', 'zip', 'ttf'];
41
-            if (\in_array(\mb_strtolower((string)\pathinfo($path, \PATHINFO_EXTENSION)), $noChangeExtensions, true)) {
41
+            if (\in_array(\mb_strtolower((string) \pathinfo($path, \PATHINFO_EXTENSION)), $noChangeExtensions, true)) {
42 42
                 // image
43 43
                 \copy($path, $newPath);
44 44
             } else {
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
         }
78 78
         //            unset($func);
79 79
 
80
-        if (!\file_exists($imageBase = $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/logoModule.png'))
81
-            || !\file_exists($font = $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/VeraBd.ttf'))) {
80
+        if (!\file_exists($imageBase = $GLOBALS['xoops']->path('modules/'.$dirname.'/assets/images/logoModule.png'))
81
+            || !\file_exists($font = $GLOBALS['xoops']->path('modules/'.$dirname.'/assets/images/VeraBd.ttf'))) {
82 82
             return false;
83 83
         }
84 84
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 
94 94
         // Write text
95 95
         $textColor     = \imagecolorallocate($imageModule, 0, 0, 0);
96
-        $spaceToBorder = (int)((80 - \mb_strlen($dirname) * 6.5) / 2);
96
+        $spaceToBorder = (int) ((80-\mb_strlen($dirname)*6.5)/2);
97 97
         \imagefttext($imageModule, 8.5, 0, $spaceToBorder, 45, $textColor, $font, \ucfirst($dirname), []);
98 98
 
99 99
         // Set transparency color
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
         //imagefill($imageModule, 0, 0, $white);
102 102
         //imagecolortransparent($imageModule, $white);
103 103
 
104
-        \imagepng($imageModule, $GLOBALS['xoops']->path('modules/' . $dirname . '/assets/images/logoModule.png'));
104
+        \imagepng($imageModule, $GLOBALS['xoops']->path('modules/'.$dirname.'/assets/images/logoModule.png'));
105 105
         \imagedestroy($imageModule);
106 106
 
107 107
         return true;
Please login to merge, or discard this patch.
class/common/FilesManagement.php 2 patches
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -24,226 +24,226 @@
 block discarded – undo
24 24
  */
25 25
 trait FilesManagement
26 26
 {
27
-    /**
28
-     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
29
-     *
30
-     * @param string $folder The full path of the directory to check
31
-     */
32
-    public static function createFolder($folder): void
33
-    {
34
-        try {
35
-            if (!\is_dir($folder)) {
36
-                if (!\is_dir($folder) && !\mkdir($folder) && !\is_dir($folder)) {
37
-                    throw new RuntimeException(\sprintf('Unable to create the %s directory', $folder));
38
-                }
39
-
40
-                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
41
-            }
42
-        } catch (\Throwable $e) {
43
-            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
44
-        }
45
-    }
46
-
47
-    /**
48
-     * @param string $file
49
-     * @param string $folder
50
-     * @return bool
51
-     */
52
-    public static function copyFile(string $file, string $folder): bool
53
-    {
54
-        return \copy($file, $folder);
55
-    }
56
-
57
-    /**
58
-     * @param $src
59
-     * @param $dst
60
-     */
61
-    public static function recurseCopy($src, $dst): void
62
-    {
63
-        $dir = \opendir($src);
64
-        //        @mkdir($dst);
65
-        if (!@\mkdir($dst) && !\is_dir($dst)) {
66
-            throw new RuntimeException('The directory ' . $dst . ' could not be created.');
67
-        }
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
-     * Remove files and (sub)directories
82
-     *
83
-     * @param string $src source directory to delete
84
-     *
85
-     * @return bool true on success
86
-     * @uses \Xmf\Module\Helper::isUserAdmin()
87
-     *
88
-     * @uses \Xmf\Module\Helper::getHelper()
89
-     */
90
-    public static function deleteDirectory($src): bool
91
-    {
92
-        // Only continue if user is a 'global' Admin
93
-        if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
94
-            return false;
95
-        }
96
-
97
-        $success = true;
98
-        // remove old files
99
-        $dirInfo = new SplFileInfo($src);
100
-        // validate is a directory
101
-        if ($dirInfo->isDir()) {
102
-            $fileList = \array_diff(\scandir($src, \SCANDIR_SORT_NONE), ['..', '.']);
103
-            foreach ($fileList as $k => $v) {
104
-                $fileInfo = new SplFileInfo("{$src}/{$v}");
105
-                if ($fileInfo->isDir()) {
106
-                    // recursively handle subdirectories
107
-                    if (!$success = self::deleteDirectory($fileInfo->getRealPath())) {
108
-                        break;
109
-                    }
110
-                } elseif (!($success = \unlink($fileInfo->getRealPath()))) {
111
-                    break;
112
-                }
113
-            }
114
-            // now delete this (sub)directory if all the files are gone
115
-            if ($success) {
116
-                $success = \rmdir($dirInfo->getRealPath());
117
-            }
118
-        } else {
119
-            // input is not a valid directory
120
-            $success = false;
121
-        }
122
-
123
-        return $success;
124
-    }
125
-
126
-    /**
127
-     * Recursively remove directory
128
-     *
129
-     * @todo currently won't remove directories with hidden files, should it?
130
-     *
131
-     * @param string $src directory to remove (delete)
132
-     *
133
-     * @return bool true on success
134
-     */
135
-    public static function rrmdir($src): bool
136
-    {
137
-        // Only continue if user is a 'global' Admin
138
-        if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
139
-            return false;
140
-        }
141
-
142
-        // If source is not a directory stop processing
143
-        if (!\is_dir($src)) {
144
-            return false;
145
-        }
146
-
147
-        $success = true;
148
-
149
-        // Open the source directory to read in files
150
-        $iterator = new DirectoryIterator($src);
151
-        foreach ($iterator as $fObj) {
152
-            if ($fObj->isFile()) {
153
-                $filename = $fObj->getPathname();
154
-                $fObj     = null; // clear this iterator object to close the file
155
-                if (!\unlink($filename)) {
156
-                    return false; // couldn't delete the file
157
-                }
158
-            } elseif (!$fObj->isDot() && $fObj->isDir()) {
159
-                // Try recursively on directory
160
-                self::rrmdir($fObj->getPathname());
161
-            }
162
-        }
163
-        $iterator = null;   // clear iterator Obj to close file/directory
164
-
165
-        return \rmdir($src); // remove the directory & return results
166
-    }
167
-
168
-    /**
169
-     * Recursively move files from one directory to another
170
-     *
171
-     * @param string $src  - Source of files being moved
172
-     * @param string $dest - Destination of files being moved
173
-     *
174
-     * @return bool true on success
175
-     */
176
-    public static function rmove($src, $dest): bool
177
-    {
178
-        // Only continue if user is a 'global' Admin
179
-        if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
180
-            return false;
181
-        }
182
-
183
-        // If source is not a directory stop processing
184
-        if (!\is_dir($src)) {
185
-            return false;
186
-        }
187
-
188
-        // If the destination directory does not exist and could not be created stop processing
189
-        if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) {
190
-            return false;
191
-        }
192
-
193
-        // Open the source directory to read in files
194
-        $iterator = new DirectoryIterator($src);
195
-        foreach ($iterator as $fObj) {
196
-            if ($fObj->isFile()) {
197
-                \rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
198
-            } elseif (!$fObj->isDot() && $fObj->isDir()) {
199
-                // Try recursively on directory
200
-                self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
201
-                //                rmdir($fObj->getPath()); // now delete the directory
202
-            }
203
-        }
204
-        $iterator = null;   // clear iterator Obj to close file/directory
205
-
206
-        return \rmdir($src); // remove the directory & return results
207
-    }
208
-
209
-    /**
210
-     * Recursively copy directories and files from one directory to another
211
-     *
212
-     * @param string $src  - Source of files being moved
213
-     * @param string $dest - Destination of files being moved
214
-     *
215
-     * @return bool true on success
216
-     * @uses \Xmf\Module\Helper::isUserAdmin()
217
-     *
218
-     * @uses \Xmf\Module\Helper::getHelper()
219
-     */
220
-    public static function rcopy($src, $dest): bool
221
-    {
222
-        // Only continue if user is a 'global' Admin
223
-        if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
224
-            return false;
225
-        }
226
-
227
-        // If source is not a directory stop processing
228
-        if (!\is_dir($src)) {
229
-            return false;
230
-        }
231
-
232
-        // If the destination directory does not exist and could not be created stop processing
233
-        if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) {
234
-            return false;
235
-        }
236
-
237
-        // Open the source directory to read in files
238
-        $iterator = new DirectoryIterator($src);
239
-        foreach ($iterator as $fObj) {
240
-            if ($fObj->isFile()) {
241
-                \copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
242
-            } elseif (!$fObj->isDot() && $fObj->isDir()) {
243
-                self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
244
-            }
245
-        }
246
-
247
-        return true;
248
-    }
27
+	/**
28
+	 * Function responsible for checking if a directory exists, we can also write in and create an index.html file
29
+	 *
30
+	 * @param string $folder The full path of the directory to check
31
+	 */
32
+	public static function createFolder($folder): void
33
+	{
34
+		try {
35
+			if (!\is_dir($folder)) {
36
+				if (!\is_dir($folder) && !\mkdir($folder) && !\is_dir($folder)) {
37
+					throw new RuntimeException(\sprintf('Unable to create the %s directory', $folder));
38
+				}
39
+
40
+				file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
41
+			}
42
+		} catch (\Throwable $e) {
43
+			echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
44
+		}
45
+	}
46
+
47
+	/**
48
+	 * @param string $file
49
+	 * @param string $folder
50
+	 * @return bool
51
+	 */
52
+	public static function copyFile(string $file, string $folder): bool
53
+	{
54
+		return \copy($file, $folder);
55
+	}
56
+
57
+	/**
58
+	 * @param $src
59
+	 * @param $dst
60
+	 */
61
+	public static function recurseCopy($src, $dst): void
62
+	{
63
+		$dir = \opendir($src);
64
+		//        @mkdir($dst);
65
+		if (!@\mkdir($dst) && !\is_dir($dst)) {
66
+			throw new RuntimeException('The directory ' . $dst . ' could not be created.');
67
+		}
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
+	 * Remove files and (sub)directories
82
+	 *
83
+	 * @param string $src source directory to delete
84
+	 *
85
+	 * @return bool true on success
86
+	 * @uses \Xmf\Module\Helper::isUserAdmin()
87
+	 *
88
+	 * @uses \Xmf\Module\Helper::getHelper()
89
+	 */
90
+	public static function deleteDirectory($src): bool
91
+	{
92
+		// Only continue if user is a 'global' Admin
93
+		if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
94
+			return false;
95
+		}
96
+
97
+		$success = true;
98
+		// remove old files
99
+		$dirInfo = new SplFileInfo($src);
100
+		// validate is a directory
101
+		if ($dirInfo->isDir()) {
102
+			$fileList = \array_diff(\scandir($src, \SCANDIR_SORT_NONE), ['..', '.']);
103
+			foreach ($fileList as $k => $v) {
104
+				$fileInfo = new SplFileInfo("{$src}/{$v}");
105
+				if ($fileInfo->isDir()) {
106
+					// recursively handle subdirectories
107
+					if (!$success = self::deleteDirectory($fileInfo->getRealPath())) {
108
+						break;
109
+					}
110
+				} elseif (!($success = \unlink($fileInfo->getRealPath()))) {
111
+					break;
112
+				}
113
+			}
114
+			// now delete this (sub)directory if all the files are gone
115
+			if ($success) {
116
+				$success = \rmdir($dirInfo->getRealPath());
117
+			}
118
+		} else {
119
+			// input is not a valid directory
120
+			$success = false;
121
+		}
122
+
123
+		return $success;
124
+	}
125
+
126
+	/**
127
+	 * Recursively remove directory
128
+	 *
129
+	 * @todo currently won't remove directories with hidden files, should it?
130
+	 *
131
+	 * @param string $src directory to remove (delete)
132
+	 *
133
+	 * @return bool true on success
134
+	 */
135
+	public static function rrmdir($src): bool
136
+	{
137
+		// Only continue if user is a 'global' Admin
138
+		if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
139
+			return false;
140
+		}
141
+
142
+		// If source is not a directory stop processing
143
+		if (!\is_dir($src)) {
144
+			return false;
145
+		}
146
+
147
+		$success = true;
148
+
149
+		// Open the source directory to read in files
150
+		$iterator = new DirectoryIterator($src);
151
+		foreach ($iterator as $fObj) {
152
+			if ($fObj->isFile()) {
153
+				$filename = $fObj->getPathname();
154
+				$fObj     = null; // clear this iterator object to close the file
155
+				if (!\unlink($filename)) {
156
+					return false; // couldn't delete the file
157
+				}
158
+			} elseif (!$fObj->isDot() && $fObj->isDir()) {
159
+				// Try recursively on directory
160
+				self::rrmdir($fObj->getPathname());
161
+			}
162
+		}
163
+		$iterator = null;   // clear iterator Obj to close file/directory
164
+
165
+		return \rmdir($src); // remove the directory & return results
166
+	}
167
+
168
+	/**
169
+	 * Recursively move files from one directory to another
170
+	 *
171
+	 * @param string $src  - Source of files being moved
172
+	 * @param string $dest - Destination of files being moved
173
+	 *
174
+	 * @return bool true on success
175
+	 */
176
+	public static function rmove($src, $dest): bool
177
+	{
178
+		// Only continue if user is a 'global' Admin
179
+		if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
180
+			return false;
181
+		}
182
+
183
+		// If source is not a directory stop processing
184
+		if (!\is_dir($src)) {
185
+			return false;
186
+		}
187
+
188
+		// If the destination directory does not exist and could not be created stop processing
189
+		if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) {
190
+			return false;
191
+		}
192
+
193
+		// Open the source directory to read in files
194
+		$iterator = new DirectoryIterator($src);
195
+		foreach ($iterator as $fObj) {
196
+			if ($fObj->isFile()) {
197
+				\rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
198
+			} elseif (!$fObj->isDot() && $fObj->isDir()) {
199
+				// Try recursively on directory
200
+				self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
201
+				//                rmdir($fObj->getPath()); // now delete the directory
202
+			}
203
+		}
204
+		$iterator = null;   // clear iterator Obj to close file/directory
205
+
206
+		return \rmdir($src); // remove the directory & return results
207
+	}
208
+
209
+	/**
210
+	 * Recursively copy directories and files from one directory to another
211
+	 *
212
+	 * @param string $src  - Source of files being moved
213
+	 * @param string $dest - Destination of files being moved
214
+	 *
215
+	 * @return bool true on success
216
+	 * @uses \Xmf\Module\Helper::isUserAdmin()
217
+	 *
218
+	 * @uses \Xmf\Module\Helper::getHelper()
219
+	 */
220
+	public static function rcopy($src, $dest): bool
221
+	{
222
+		// Only continue if user is a 'global' Admin
223
+		if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
224
+			return false;
225
+		}
226
+
227
+		// If source is not a directory stop processing
228
+		if (!\is_dir($src)) {
229
+			return false;
230
+		}
231
+
232
+		// If the destination directory does not exist and could not be created stop processing
233
+		if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) {
234
+			return false;
235
+		}
236
+
237
+		// Open the source directory to read in files
238
+		$iterator = new DirectoryIterator($src);
239
+		foreach ($iterator as $fObj) {
240
+			if ($fObj->isFile()) {
241
+				\copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
242
+			} elseif (!$fObj->isDot() && $fObj->isDir()) {
243
+				self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
244
+			}
245
+		}
246
+
247
+		return true;
248
+	}
249 249
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
                     throw new RuntimeException(\sprintf('Unable to create the %s directory', $folder));
38 38
                 }
39 39
 
40
-                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
40
+                file_put_contents($folder.'/index.html', '<script>history.go(-1);</script>');
41 41
             }
42 42
         } catch (\Throwable $e) {
43 43
             echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
         $dir = \opendir($src);
64 64
         //        @mkdir($dst);
65 65
         if (!@\mkdir($dst) && !\is_dir($dst)) {
66
-            throw new RuntimeException('The directory ' . $dst . ' could not be created.');
66
+            throw new RuntimeException('The directory '.$dst.' could not be created.');
67 67
         }
68
-        while (false !== ($file = \readdir($dir))) {
69
-            if (('.' !== $file) && ('..' !== $file)) {
70
-                if (\is_dir($src . '/' . $file)) {
71
-                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
68
+        while (false!==($file = \readdir($dir))) {
69
+            if (('.'!==$file) && ('..'!==$file)) {
70
+                if (\is_dir($src.'/'.$file)) {
71
+                    self::recurseCopy($src.'/'.$file, $dst.'/'.$file);
72 72
                 } else {
73
-                    \copy($src . '/' . $file, $dst . '/' . $file);
73
+                    \copy($src.'/'.$file, $dst.'/'.$file);
74 74
                 }
75 75
             }
76 76
         }
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                 self::rrmdir($fObj->getPathname());
161 161
             }
162 162
         }
163
-        $iterator = null;   // clear iterator Obj to close file/directory
163
+        $iterator = null; // clear iterator Obj to close file/directory
164 164
 
165 165
         return \rmdir($src); // remove the directory & return results
166 166
     }
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
         $iterator = new DirectoryIterator($src);
195 195
         foreach ($iterator as $fObj) {
196 196
             if ($fObj->isFile()) {
197
-                \rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
197
+                \rename($fObj->getPathname(), "{$dest}/".$fObj->getFilename());
198 198
             } elseif (!$fObj->isDot() && $fObj->isDir()) {
199 199
                 // Try recursively on directory
200
-                self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
200
+                self::rmove($fObj->getPathname(), "{$dest}/".$fObj->getFilename());
201 201
                 //                rmdir($fObj->getPath()); // now delete the directory
202 202
             }
203 203
         }
204
-        $iterator = null;   // clear iterator Obj to close file/directory
204
+        $iterator = null; // clear iterator Obj to close file/directory
205 205
 
206 206
         return \rmdir($src); // remove the directory & return results
207 207
     }
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
         $iterator = new DirectoryIterator($src);
239 239
         foreach ($iterator as $fObj) {
240 240
             if ($fObj->isFile()) {
241
-                \copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
241
+                \copy($fObj->getPathname(), "{$dest}/".$fObj->getFilename());
242 242
             } elseif (!$fObj->isDot() && $fObj->isDir()) {
243
-                self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
243
+                self::rcopy($fObj->getPathname(), "{$dest}/".$fObj->getFilename());
244 244
             }
245 245
         }
246 246
 
Please login to merge, or discard this patch.
class/common/ServerStats.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -19,60 +19,60 @@
 block discarded – undo
19 19
  */
20 20
 trait ServerStats
21 21
 {
22
-    /**
23
-     * serverStats()
24
-     *
25
-     * @return string
26
-     */
27
-    public static function getServerStats(): string
28
-    {
29
-        //mb    $wfdownloads = WfdownloadsWfdownloads::getInstance();
30
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
31
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
32
-        \xoops_loadLanguage('common', $moduleDirName);
33
-        $html = '';
34
-        //        $sql   = 'SELECT metavalue';
35
-        //        $sql   .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_meta');
36
-        //        $sql   .= " WHERE metakey='version' LIMIT 1";
37
-        //        $query = $GLOBALS['xoopsDB']->query($sql);
38
-        //        list($meta) = $GLOBALS['xoopsDB']->fetchRow($query);
39
-        $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . \constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n";
40
-        $html .= "<div style='padding: 8px;'>\n";
41
-        //        $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n";
42
-        //        $html .= "<br>\n";
43
-        //        $html .= "<br>\n";
44
-        $html .= '<div>' . \constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n";
45
-        $html .= "<ul>\n";
22
+	/**
23
+	 * serverStats()
24
+	 *
25
+	 * @return string
26
+	 */
27
+	public static function getServerStats(): string
28
+	{
29
+		//mb    $wfdownloads = WfdownloadsWfdownloads::getInstance();
30
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
31
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
32
+		\xoops_loadLanguage('common', $moduleDirName);
33
+		$html = '';
34
+		//        $sql   = 'SELECT metavalue';
35
+		//        $sql   .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_meta');
36
+		//        $sql   .= " WHERE metakey='version' LIMIT 1";
37
+		//        $query = $GLOBALS['xoopsDB']->query($sql);
38
+		//        list($meta) = $GLOBALS['xoopsDB']->fetchRow($query);
39
+		$html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . \constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n";
40
+		$html .= "<div style='padding: 8px;'>\n";
41
+		//        $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n";
42
+		//        $html .= "<br>\n";
43
+		//        $html .= "<br>\n";
44
+		$html .= '<div>' . \constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n";
45
+		$html .= "<ul>\n";
46 46
 
47
-        $gdlib = \function_exists('gd_info') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>';
48
-        $html  .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib;
49
-        if (\function_exists('gd_info')) {
50
-            if (true == ($gdlib = gd_info())) {
51
-                $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>';
52
-            }
53
-        }
54
-        //
55
-        //    $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF');
56
-        //    $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode;
57
-        //
58
-        //    $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>';
59
-        //    $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals;
60
-        //
61
-        $downloads = \ini_get('file_uploads') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>';
62
-        $html      .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads;
47
+		$gdlib = \function_exists('gd_info') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>';
48
+		$html  .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib;
49
+		if (\function_exists('gd_info')) {
50
+			if (true == ($gdlib = gd_info())) {
51
+				$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>';
52
+			}
53
+		}
54
+		//
55
+		//    $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF');
56
+		//    $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode;
57
+		//
58
+		//    $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>';
59
+		//    $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals;
60
+		//
61
+		$downloads = \ini_get('file_uploads') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>';
62
+		$html      .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads;
63 63
 
64
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . \ini_get('upload_max_filesize') . "</span></b>\n";
65
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . \ini_get('post_max_size') . "</span></b>\n";
66
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . \ini_get('memory_limit') . "</span></b>\n";
67
-        $html .= "</ul>\n";
68
-        $html .= "<ul>\n";
69
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n";
70
-        $html .= "</ul>\n";
71
-        $html .= "<br>\n";
72
-        $html .= \constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n";
73
-        $html .= '</div>';
74
-        $html .= '</fieldset><br>';
64
+		$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . \ini_get('upload_max_filesize') . "</span></b>\n";
65
+		$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . \ini_get('post_max_size') . "</span></b>\n";
66
+		$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . \ini_get('memory_limit') . "</span></b>\n";
67
+		$html .= "</ul>\n";
68
+		$html .= "<ul>\n";
69
+		$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n";
70
+		$html .= "</ul>\n";
71
+		$html .= "<br>\n";
72
+		$html .= \constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n";
73
+		$html .= '</div>';
74
+		$html .= '</fieldset><br>';
75 75
 
76
-        return $html;
77
-    }
76
+		return $html;
77
+	}
78 78
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -36,19 +36,19 @@  discard block
 block discarded – undo
36 36
         //        $sql   .= " WHERE metakey='version' LIMIT 1";
37 37
         //        $query = $GLOBALS['xoopsDB']->query($sql);
38 38
         //        list($meta) = $GLOBALS['xoopsDB']->fetchRow($query);
39
-        $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . \constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n";
39
+        $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>".\constant('CO_'.$moduleDirNameUpper.'_IMAGEINFO')."</legend>\n";
40 40
         $html .= "<div style='padding: 8px;'>\n";
41 41
         //        $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n";
42 42
         //        $html .= "<br>\n";
43 43
         //        $html .= "<br>\n";
44
-        $html .= '<div>' . \constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n";
44
+        $html .= '<div>'.\constant('CO_'.$moduleDirNameUpper.'_SPHPINI')."</div>\n";
45 45
         $html .= "<ul>\n";
46 46
 
47
-        $gdlib = \function_exists('gd_info') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>';
48
-        $html  .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib;
47
+        $gdlib = \function_exists('gd_info') ? '<span style="color: green;">'.\constant('CO_'.$moduleDirNameUpper.'_GDON').'</span>' : '<span style="color: red;">'.\constant('CO_'.$moduleDirNameUpper.'_GDOFF').'</span>';
48
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_GDLIBSTATUS').$gdlib;
49 49
         if (\function_exists('gd_info')) {
50
-            if (true == ($gdlib = gd_info())) {
51
-                $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>';
50
+            if (true==($gdlib = gd_info())) {
51
+                $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_GDLIBVERSION').'<b>'.$gdlib['GD Version'].'</b>';
52 52
             }
53 53
         }
54 54
         //
@@ -58,18 +58,18 @@  discard block
 block discarded – undo
58 58
         //    $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>';
59 59
         //    $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals;
60 60
         //
61
-        $downloads = \ini_get('file_uploads') ? '<span style="color: green;">' . \constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . \constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>';
62
-        $html      .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads;
61
+        $downloads = \ini_get('file_uploads') ? '<span style="color: green;">'.\constant('CO_'.$moduleDirNameUpper.'_ON').'</span>' : '<span style="color: red;">'.\constant('CO_'.$moduleDirNameUpper.'_OFF').'</span>';
62
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_SERVERUPLOADSTATUS').$downloads;
63 63
 
64
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . \ini_get('upload_max_filesize') . "</span></b>\n";
65
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . \ini_get('post_max_size') . "</span></b>\n";
66
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . \ini_get('memory_limit') . "</span></b>\n";
64
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_MAXUPLOADSIZE').' <b><span style="color: blue;">'.\ini_get('upload_max_filesize')."</span></b>\n";
65
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_MAXPOSTSIZE').' <b><span style="color: blue;">'.\ini_get('post_max_size')."</span></b>\n";
66
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_MEMORYLIMIT').' <b><span style="color: blue;">'.\ini_get('memory_limit')."</span></b>\n";
67 67
         $html .= "</ul>\n";
68 68
         $html .= "<ul>\n";
69
-        $html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n";
69
+        $html .= '<li>'.\constant('CO_'.$moduleDirNameUpper.'_SERVERPATH').' <b>'.XOOPS_ROOT_PATH."</b>\n";
70 70
         $html .= "</ul>\n";
71 71
         $html .= "<br>\n";
72
-        $html .= \constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n";
72
+        $html .= \constant('CO_'.$moduleDirNameUpper.'_UPLOADPATHDSC')."\n";
73 73
         $html .= '</div>';
74 74
         $html .= '</fieldset><br>';
75 75
 
Please login to merge, or discard this patch.
class/common/TestdataButtons.php 2 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -29,64 +29,64 @@
 block discarded – undo
29 29
  */
30 30
 class TestdataButtons
31 31
 {
32
-    /** Button status constants */
33
-    private const SHOW_BUTTONS = 1;
34
-    private const HIDE_BUTTONS = 0;
32
+	/** Button status constants */
33
+	private const SHOW_BUTTONS = 1;
34
+	private const HIDE_BUTTONS = 0;
35 35
 
36
-    /**
37
-     * Load the test button configuration
38
-     *
39
-     * @param \Xmf\Module\Admin $adminObject
40
-     *
41
-     * @return void
42
-     */
43
-    public static function loadButtonConfig($adminObject): void
44
-    {
45
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
46
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
47
-        $helper              = Helper::getInstance();
48
-        $yamlFile            = $helper->path('/config/admin.yml');
49
-        $config             = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
50
-        $displaySampleButton = $config['displaySampleButton'];
36
+	/**
37
+	 * Load the test button configuration
38
+	 *
39
+	 * @param \Xmf\Module\Admin $adminObject
40
+	 *
41
+	 * @return void
42
+	 */
43
+	public static function loadButtonConfig($adminObject): void
44
+	{
45
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
46
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
47
+		$helper              = Helper::getInstance();
48
+		$yamlFile            = $helper->path('/config/admin.yml');
49
+		$config             = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
50
+		$displaySampleButton = $config['displaySampleButton'];
51 51
 
52
-        if (self::SHOW_BUTTONS == $displaySampleButton) {
53
-            \xoops_loadLanguage('admin/modulesadmin', 'system');
54
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
55
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
56
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
57
-            //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
58
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
59
-        } else {
60
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
61
-            // $displaySampleButton = $config['displaySampleButton'];
62
-        }
63
-    }
52
+		if (self::SHOW_BUTTONS == $displaySampleButton) {
53
+			\xoops_loadLanguage('admin/modulesadmin', 'system');
54
+			$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
55
+			$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
56
+			$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
57
+			//    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
58
+			$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
59
+		} else {
60
+			$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
61
+			// $displaySampleButton = $config['displaySampleButton'];
62
+		}
63
+	}
64 64
 
65
-    /**
66
-     * Hide the test buttons
67
-     *
68
-     * @return void
69
-     */
70
-    public static function hideButtons(): void
71
-    {
72
-        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
73
-        $app                        = [];
74
-        $app['displaySampleButton'] = self::HIDE_BUTTONS;
75
-        Yaml::save($app, $yamlFile);
76
-        \redirect_header('index.php', 0, '');
77
-    }
65
+	/**
66
+	 * Hide the test buttons
67
+	 *
68
+	 * @return void
69
+	 */
70
+	public static function hideButtons(): void
71
+	{
72
+		$yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
73
+		$app                        = [];
74
+		$app['displaySampleButton'] = self::HIDE_BUTTONS;
75
+		Yaml::save($app, $yamlFile);
76
+		\redirect_header('index.php', 0, '');
77
+	}
78 78
 
79
-    /**
80
-     * Show the test buttons
81
-     *
82
-     * @return void
83
-     */
84
-    public static function showButtons(): void
85
-    {
86
-        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
87
-        $app                        = [];
88
-        $app['displaySampleButton'] = self::SHOW_BUTTONS;
89
-        Yaml::save($app, $yamlFile);
90
-        \redirect_header('index.php', 0, '');
91
-    }
79
+	/**
80
+	 * Show the test buttons
81
+	 *
82
+	 * @return void
83
+	 */
84
+	public static function showButtons(): void
85
+	{
86
+		$yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
87
+		$app                        = [];
88
+		$app['displaySampleButton'] = self::SHOW_BUTTONS;
89
+		Yaml::save($app, $yamlFile);
90
+		\redirect_header('index.php', 0, '');
91
+	}
92 92
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
         $config             = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
50 50
         $displaySampleButton = $config['displaySampleButton'];
51 51
 
52
-        if (self::SHOW_BUTTONS == $displaySampleButton) {
52
+        if (self::SHOW_BUTTONS==$displaySampleButton) {
53 53
             \xoops_loadLanguage('admin/modulesadmin', 'system');
54
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
55
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
56
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
54
+            $adminObject->addItemButton(\constant('CO_'.$moduleDirNameUpper.'_'.'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
55
+            $adminObject->addItemButton(\constant('CO_'.$moduleDirNameUpper.'_'.'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
56
+            $adminObject->addItemButton(\constant('CO_'.$moduleDirNameUpper.'_'.'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
57 57
             //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
58
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
58
+            $adminObject->addItemButton(\constant('CO_'.$moduleDirNameUpper.'_'.'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
59 59
         } else {
60
-            $adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
60
+            $adminObject->addItemButton(\constant('CO_'.$moduleDirNameUpper.'_'.'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
61 61
             // $displaySampleButton = $config['displaySampleButton'];
62 62
         }
63 63
     }
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public static function hideButtons(): void
71 71
     {
72
-        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
72
+        $yamlFile                   = \dirname(__DIR__, 2).'/config/admin.yml';
73 73
         $app                        = [];
74 74
         $app['displaySampleButton'] = self::HIDE_BUTTONS;
75 75
         Yaml::save($app, $yamlFile);
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public static function showButtons(): void
85 85
     {
86
-        $yamlFile                   = \dirname(__DIR__, 2) . '/config/admin.yml';
86
+        $yamlFile                   = \dirname(__DIR__, 2).'/config/admin.yml';
87 87
         $app                        = [];
88 88
         $app['displaySampleButton'] = self::SHOW_BUTTONS;
89 89
         Yaml::save($app, $yamlFile);
Please login to merge, or discard this patch.
class/common/VersionChecks.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -19,127 +19,127 @@
 block discarded – undo
19 19
  */
20 20
 trait VersionChecks
21 21
 {
22
-    /**
23
-     * Verifies XOOPS version meets minimum requirements for this module
24
-     * @static
25
-     * @param \XoopsModule|null $module
26
-     *
27
-     * @param null|string       $requiredVer
28
-     * @return bool true if meets requirements, false if not
29
-     */
30
-    public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null): bool
31
-    {
32
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
33
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
34
-        if (null === $module) {
35
-            $module = \XoopsModule::getByDirname($moduleDirName);
36
-        }
37
-        \xoops_loadLanguage('admin', $moduleDirName);
38
-        \xoops_loadLanguage('common', $moduleDirName);
22
+	/**
23
+	 * Verifies XOOPS version meets minimum requirements for this module
24
+	 * @static
25
+	 * @param \XoopsModule|null $module
26
+	 *
27
+	 * @param null|string       $requiredVer
28
+	 * @return bool true if meets requirements, false if not
29
+	 */
30
+	public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null): bool
31
+	{
32
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
33
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
34
+		if (null === $module) {
35
+			$module = \XoopsModule::getByDirname($moduleDirName);
36
+		}
37
+		\xoops_loadLanguage('admin', $moduleDirName);
38
+		\xoops_loadLanguage('common', $moduleDirName);
39 39
 
40
-        //check for minimum XOOPS version
41
-        $currentVer = mb_substr(\XOOPS_VERSION, 6); // get the numeric part of string
42
-        if (null === $requiredVer) {
43
-            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
44
-        }
45
-        $success = true;
40
+		//check for minimum XOOPS version
41
+		$currentVer = mb_substr(\XOOPS_VERSION, 6); // get the numeric part of string
42
+		if (null === $requiredVer) {
43
+			$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
44
+		}
45
+		$success = true;
46 46
 
47
-        if (\version_compare($currentVer, $requiredVer, '<')) {
48
-            $success = false;
49
-            $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
50
-        }
47
+		if (\version_compare($currentVer, $requiredVer, '<')) {
48
+			$success = false;
49
+			$module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
50
+		}
51 51
 
52
-        return $success;
53
-    }
52
+		return $success;
53
+	}
54 54
 
55
-    /**
56
-     * Verifies PHP version meets minimum requirements for this module
57
-     * @static
58
-     * @param \XoopsModule|bool|null $module
59
-     *
60
-     * @return bool true if meets requirements, false if not
61
-     */
62
-    public static function checkVerPhp(\XoopsModule $module = null): bool
63
-    {
64
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
65
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
66
-        if (null === $module) {
67
-            $module = \XoopsModule::getByDirname($moduleDirName);
68
-        }
69
-        \xoops_loadLanguage('admin', $moduleDirName);
70
-        \xoops_loadLanguage('common', $moduleDirName);
55
+	/**
56
+	 * Verifies PHP version meets minimum requirements for this module
57
+	 * @static
58
+	 * @param \XoopsModule|bool|null $module
59
+	 *
60
+	 * @return bool true if meets requirements, false if not
61
+	 */
62
+	public static function checkVerPhp(\XoopsModule $module = null): bool
63
+	{
64
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
65
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
66
+		if (null === $module) {
67
+			$module = \XoopsModule::getByDirname($moduleDirName);
68
+		}
69
+		\xoops_loadLanguage('admin', $moduleDirName);
70
+		\xoops_loadLanguage('common', $moduleDirName);
71 71
 
72
-        // check for minimum PHP version
73
-        $success = true;
72
+		// check for minimum PHP version
73
+		$success = true;
74 74
 
75
-        $verNum = \PHP_VERSION;
76
-        $reqVer = &$module->getInfo('min_php');
75
+		$verNum = \PHP_VERSION;
76
+		$reqVer = &$module->getInfo('min_php');
77 77
 
78
-        if (false !== $reqVer && '' !== $reqVer) {
79
-            if (\version_compare($verNum, $reqVer, '<')) {
80
-                $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
81
-                $success = false;
82
-            }
83
-        }
78
+		if (false !== $reqVer && '' !== $reqVer) {
79
+			if (\version_compare($verNum, $reqVer, '<')) {
80
+				$module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
81
+				$success = false;
82
+			}
83
+		}
84 84
 
85
-        return $success;
86
-    }
85
+		return $success;
86
+	}
87 87
 
88
-    /**
89
-     * compares current module version with the latest GitHub release
90
-     * @static
91
-     *
92
-     * @return string|array info about the latest module version, if newer
93
-     */
94
-    public static function checkVerModule(\Xmf\Module\Helper $helper, ?string $source = 'github', ?string $default = 'master'): ?array
95
-    {
96
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
97
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
98
-        $update             = '';
99
-        $repository         = 'XoopsModules25x/' . $moduleDirName;
100
-        //        $repository         = 'XoopsModules25x/publisher'; //for testing only
101
-        $ret             = null;
102
-        $infoReleasesUrl = "https://api.github.com/repos/$repository/releases";
103
-        if ('github' === $source) {
104
-            if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) {
105
-                \curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl);
106
-                \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
107
-                \curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized'
108
-                \curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]);
109
-                $curlReturn = \curl_exec($curlHandle);
110
-                if (false === $curlReturn) {
111
-                    \trigger_error(\curl_error($curlHandle));
112
-                } elseif (false !== \mb_strpos($curlReturn, 'Not Found')) {
113
-                    \trigger_error('Repository Not Found: ' . $infoReleasesUrl);
114
-                } else {
115
-                    $file              = json_decode($curlReturn, false);
116
-                    $latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default);
117
-                    $latestVersion     = $file[0]->tag_name;
118
-                    $prerelease        = $file[0]->prerelease;
119
-                    if ('master' !== $latestVersionLink) {
120
-                        $update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion;
121
-                    }
122
-                    //"PHP-standardized" version
123
-                    $latestVersion = \mb_strtolower($latestVersion);
124
-                    if (false !== mb_strpos($latestVersion, 'final')) {
125
-                        $latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion));
126
-                        $latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion));
127
-                    }
128
-                    $moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
129
-                    //"PHP-standardized" version
130
-                    $moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion));
131
-                    //                    $moduleVersion = '1.0'; //for testing only
132
-                    //                    $moduleDirName = 'publisher'; //for testing only
133
-                    if (!$prerelease && \version_compare($moduleVersion, $latestVersion, '<')) {
134
-                        $ret   = [];
135
-                        $ret[] = $update;
136
-                        $ret[] = $latestVersionLink;
137
-                    }
138
-                }
139
-                \curl_close($curlHandle);
140
-            }
141
-        }
88
+	/**
89
+	 * compares current module version with the latest GitHub release
90
+	 * @static
91
+	 *
92
+	 * @return string|array info about the latest module version, if newer
93
+	 */
94
+	public static function checkVerModule(\Xmf\Module\Helper $helper, ?string $source = 'github', ?string $default = 'master'): ?array
95
+	{
96
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
97
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
98
+		$update             = '';
99
+		$repository         = 'XoopsModules25x/' . $moduleDirName;
100
+		//        $repository         = 'XoopsModules25x/publisher'; //for testing only
101
+		$ret             = null;
102
+		$infoReleasesUrl = "https://api.github.com/repos/$repository/releases";
103
+		if ('github' === $source) {
104
+			if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) {
105
+				\curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl);
106
+				\curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
107
+				\curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized'
108
+				\curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]);
109
+				$curlReturn = \curl_exec($curlHandle);
110
+				if (false === $curlReturn) {
111
+					\trigger_error(\curl_error($curlHandle));
112
+				} elseif (false !== \mb_strpos($curlReturn, 'Not Found')) {
113
+					\trigger_error('Repository Not Found: ' . $infoReleasesUrl);
114
+				} else {
115
+					$file              = json_decode($curlReturn, false);
116
+					$latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default);
117
+					$latestVersion     = $file[0]->tag_name;
118
+					$prerelease        = $file[0]->prerelease;
119
+					if ('master' !== $latestVersionLink) {
120
+						$update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion;
121
+					}
122
+					//"PHP-standardized" version
123
+					$latestVersion = \mb_strtolower($latestVersion);
124
+					if (false !== mb_strpos($latestVersion, 'final')) {
125
+						$latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion));
126
+						$latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion));
127
+					}
128
+					$moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
129
+					//"PHP-standardized" version
130
+					$moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion));
131
+					//                    $moduleVersion = '1.0'; //for testing only
132
+					//                    $moduleDirName = 'publisher'; //for testing only
133
+					if (!$prerelease && \version_compare($moduleVersion, $latestVersion, '<')) {
134
+						$ret   = [];
135
+						$ret[] = $update;
136
+						$ret[] = $latestVersionLink;
137
+					}
138
+				}
139
+				\curl_close($curlHandle);
140
+			}
141
+		}
142 142
 
143
-        return $ret;
144
-    }
143
+		return $ret;
144
+	}
145 145
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     {
32 32
         $moduleDirName      = \basename(\dirname(__DIR__, 2));
33 33
         $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
34
-        if (null === $module) {
34
+        if (null===$module) {
35 35
             $module = \XoopsModule::getByDirname($moduleDirName);
36 36
         }
37 37
         \xoops_loadLanguage('admin', $moduleDirName);
@@ -39,14 +39,14 @@  discard block
 block discarded – undo
39 39
 
40 40
         //check for minimum XOOPS version
41 41
         $currentVer = mb_substr(\XOOPS_VERSION, 6); // get the numeric part of string
42
-        if (null === $requiredVer) {
43
-            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
42
+        if (null===$requiredVer) {
43
+            $requiredVer = ''.$module->getInfo('min_xoops'); //making sure it's a string
44 44
         }
45 45
         $success = true;
46 46
 
47 47
         if (\version_compare($currentVer, $requiredVer, '<')) {
48 48
             $success = false;
49
-            $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
49
+            $module->setErrors(\sprintf(\constant('CO_'.$moduleDirNameUpper.'_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
50 50
         }
51 51
 
52 52
         return $success;
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     {
64 64
         $moduleDirName      = \basename(\dirname(__DIR__, 2));
65 65
         $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
66
-        if (null === $module) {
66
+        if (null===$module) {
67 67
             $module = \XoopsModule::getByDirname($moduleDirName);
68 68
         }
69 69
         \xoops_loadLanguage('admin', $moduleDirName);
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
         $verNum = \PHP_VERSION;
76 76
         $reqVer = &$module->getInfo('min_php');
77 77
 
78
-        if (false !== $reqVer && '' !== $reqVer) {
78
+        if (false!==$reqVer && ''!==$reqVer) {
79 79
             if (\version_compare($verNum, $reqVer, '<')) {
80
-                $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
80
+                $module->setErrors(\sprintf(\constant('CO_'.$moduleDirNameUpper.'_ERROR_BAD_PHP'), $reqVer, $verNum));
81 81
                 $success = false;
82 82
             }
83 83
         }
@@ -96,36 +96,36 @@  discard block
 block discarded – undo
96 96
         $moduleDirName      = \basename(\dirname(__DIR__, 2));
97 97
         $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
98 98
         $update             = '';
99
-        $repository         = 'XoopsModules25x/' . $moduleDirName;
99
+        $repository         = 'XoopsModules25x/'.$moduleDirName;
100 100
         //        $repository         = 'XoopsModules25x/publisher'; //for testing only
101 101
         $ret             = null;
102 102
         $infoReleasesUrl = "https://api.github.com/repos/$repository/releases";
103
-        if ('github' === $source) {
104
-            if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) {
103
+        if ('github'===$source) {
104
+            if (\function_exists('curl_init') && false!==($curlHandle = \curl_init())) {
105 105
                 \curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl);
106 106
                 \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
107 107
                 \curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized'
108 108
                 \curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]);
109 109
                 $curlReturn = \curl_exec($curlHandle);
110
-                if (false === $curlReturn) {
110
+                if (false===$curlReturn) {
111 111
                     \trigger_error(\curl_error($curlHandle));
112
-                } elseif (false !== \mb_strpos($curlReturn, 'Not Found')) {
113
-                    \trigger_error('Repository Not Found: ' . $infoReleasesUrl);
112
+                } elseif (false!==\mb_strpos($curlReturn, 'Not Found')) {
113
+                    \trigger_error('Repository Not Found: '.$infoReleasesUrl);
114 114
                 } else {
115 115
                     $file              = json_decode($curlReturn, false);
116 116
                     $latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default);
117 117
                     $latestVersion     = $file[0]->tag_name;
118 118
                     $prerelease        = $file[0]->prerelease;
119
-                    if ('master' !== $latestVersionLink) {
120
-                        $update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion;
119
+                    if ('master'!==$latestVersionLink) {
120
+                        $update = \constant('CO_'.$moduleDirNameUpper.'_'.'NEW_VERSION').$latestVersion;
121 121
                     }
122 122
                     //"PHP-standardized" version
123 123
                     $latestVersion = \mb_strtolower($latestVersion);
124
-                    if (false !== mb_strpos($latestVersion, 'final')) {
124
+                    if (false!==mb_strpos($latestVersion, 'final')) {
125 125
                         $latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion));
126 126
                         $latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion));
127 127
                     }
128
-                    $moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
128
+                    $moduleVersion = ($helper->getModule()->getInfo('version').'_'.$helper->getModule()->getInfo('module_status'));
129 129
                     //"PHP-standardized" version
130 130
                     $moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion));
131 131
                     //                    $moduleVersion = '1.0'; //for testing only
Please login to merge, or discard this patch.
class/common/Configurator.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -24,41 +24,41 @@
 block discarded – undo
24 24
  */
25 25
 class Configurator
26 26
 {
27
-    public $name;
28
-    public $paths           = [];
29
-    public $uploadFolders   = [];
30
-    public $copyBlankFiles  = [];
31
-    public $copyTestFolders = [];
32
-    public $templateFolders = [];
33
-    public $oldFiles        = [];
34
-    public $oldFolders      = [];
35
-    public $renameTables    = [];
36
-    public $renameColumns   = [];
37
-    public $moduleStats     = [];
38
-    public $modCopyright;
39
-    public $icons;
27
+	public $name;
28
+	public $paths           = [];
29
+	public $uploadFolders   = [];
30
+	public $copyBlankFiles  = [];
31
+	public $copyTestFolders = [];
32
+	public $templateFolders = [];
33
+	public $oldFiles        = [];
34
+	public $oldFolders      = [];
35
+	public $renameTables    = [];
36
+	public $renameColumns   = [];
37
+	public $moduleStats     = [];
38
+	public $modCopyright;
39
+	public $icons;
40 40
 
41
-    /**
42
-     * Configurator constructor.
43
-     */
44
-    public function __construct()
45
-    {
46
-        $config = require \dirname(__DIR__, 2) . '/config/config.php';
41
+	/**
42
+	 * Configurator constructor.
43
+	 */
44
+	public function __construct()
45
+	{
46
+		$config = require \dirname(__DIR__, 2) . '/config/config.php';
47 47
 
48
-        $this->name            = $config->name;
49
-        $this->paths           = $config->paths;
50
-        $this->uploadFolders   = $config->uploadFolders;
51
-        $this->copyBlankFiles  = $config->copyBlankFiles;
52
-        $this->copyTestFolders = $config->copyTestFolders;
53
-        $this->templateFolders = $config->templateFolders;
54
-        $this->oldFiles        = $config->oldFiles;
55
-        $this->oldFolders      = $config->oldFolders;
56
-        $this->renameTables    = $config->renameTables;
57
-        $this->renameColumns   = $config->renameColumns;
58
-        $this->moduleStats     = $config->moduleStats;
59
-        $this->modCopyright    = $config->modCopyright;
48
+		$this->name            = $config->name;
49
+		$this->paths           = $config->paths;
50
+		$this->uploadFolders   = $config->uploadFolders;
51
+		$this->copyBlankFiles  = $config->copyBlankFiles;
52
+		$this->copyTestFolders = $config->copyTestFolders;
53
+		$this->templateFolders = $config->templateFolders;
54
+		$this->oldFiles        = $config->oldFiles;
55
+		$this->oldFolders      = $config->oldFolders;
56
+		$this->renameTables    = $config->renameTables;
57
+		$this->renameColumns   = $config->renameColumns;
58
+		$this->moduleStats     = $config->moduleStats;
59
+		$this->modCopyright    = $config->modCopyright;
60 60
 
61
-        $this->icons = require \dirname(__DIR__, 2) . '/config/icons.php';
62
-        $this->paths = require \dirname(__DIR__, 2) . '/config/paths.php';
63
-    }
61
+		$this->icons = require \dirname(__DIR__, 2) . '/config/icons.php';
62
+		$this->paths = require \dirname(__DIR__, 2) . '/config/paths.php';
63
+	}
64 64
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function __construct()
45 45
     {
46
-        $config = require \dirname(__DIR__, 2) . '/config/config.php';
46
+        $config = require \dirname(__DIR__, 2).'/config/config.php';
47 47
 
48 48
         $this->name            = $config->name;
49 49
         $this->paths           = $config->paths;
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         $this->moduleStats     = $config->moduleStats;
59 59
         $this->modCopyright    = $config->modCopyright;
60 60
 
61
-        $this->icons = require \dirname(__DIR__, 2) . '/config/icons.php';
62
-        $this->paths = require \dirname(__DIR__, 2) . '/config/paths.php';
61
+        $this->icons = require \dirname(__DIR__, 2).'/config/icons.php';
62
+        $this->paths = require \dirname(__DIR__, 2).'/config/paths.php';
63 63
     }
64 64
 }
Please login to merge, or discard this patch.
class/common/Breadcrumb.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -32,39 +32,39 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class Breadcrumb
34 34
 {
35
-    public  $dirname;
36
-    private $bread = [];
35
+	public  $dirname;
36
+	private $bread = [];
37 37
 
38
-    public function __construct()
39
-    {
40
-        $this->dirname = \basename(\dirname(__DIR__, 2));
41
-    }
38
+	public function __construct()
39
+	{
40
+		$this->dirname = \basename(\dirname(__DIR__, 2));
41
+	}
42 42
 
43
-    /**
44
-     * Add link to breadcrumb
45
-     *
46
-     * @param string $title
47
-     * @param string $link
48
-     */
49
-    public function addLink($title = '', $link = ''): void
50
-    {
51
-        $this->bread[] = [
52
-            'link'  => $link,
53
-            'title' => $title,
54
-        ];
55
-    }
43
+	/**
44
+	 * Add link to breadcrumb
45
+	 *
46
+	 * @param string $title
47
+	 * @param string $link
48
+	 */
49
+	public function addLink($title = '', $link = ''): void
50
+	{
51
+		$this->bread[] = [
52
+			'link'  => $link,
53
+			'title' => $title,
54
+		];
55
+	}
56 56
 
57
-    /**
58
-     * Render BreadCrumb
59
-     */
60
-    public function render(): void
61
-    {
62
-        /*
57
+	/**
58
+	 * Render BreadCrumb
59
+	 */
60
+	public function render(): void
61
+	{
62
+		/*
63 63
         TODO if you want to use the render code below,
64 64
         1) create ./templates/chess_common_breadcrumb.tpl)
65 65
         2) add declaration to  xoops_version.php
66 66
         */
67
-        /*
67
+		/*
68 68
         if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) {
69 69
             require $GLOBALS['xoops']->path('class/theme.php');
70 70
 
@@ -83,5 +83,5 @@  discard block
 block discarded – undo
83 83
 
84 84
         return $html;
85 85
         */
86
-    }
86
+	}
87 87
 }
Please login to merge, or discard this patch.