Passed
Pull Request — master (#2)
by Michael
07:48 queued 04:06
created
class/Voice.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -13,85 +13,85 @@
 block discarded – undo
13 13
  */
14 14
 class Voice extends XoopsObject
15 15
 {
16
-    /**
17
-     * Voice constructor.
18
-     * @param null $fid
19
-     */
20
-    public function __construct($fid = null)
21
-    {
22
-        $this->initVar('vcid', \XOBJ_DTYPE_INT, 0, false);
23
-        $this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, false, 128);
24
-        $this->initVar('artists', \XOBJ_DTYPE_INT, 0, false);
25
-        $this->initVar('albums', \XOBJ_DTYPE_INT, 0, false);
26
-        $this->initVar('songs', \XOBJ_DTYPE_INT, 0, false);
27
-        $this->initVar('hits', \XOBJ_DTYPE_INT, 0, false);
28
-        $this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false);
29
-        $this->initVar('votes', \XOBJ_DTYPE_INT, 0, false);
30
-        $this->initVar('created', \XOBJ_DTYPE_INT, 0, false);
31
-        $this->initVar('updated', \XOBJ_DTYPE_INT, 0, false);
32
-    }
16
+	/**
17
+	 * Voice constructor.
18
+	 * @param null $fid
19
+	 */
20
+	public function __construct($fid = null)
21
+	{
22
+		$this->initVar('vcid', \XOBJ_DTYPE_INT, 0, false);
23
+		$this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, false, 128);
24
+		$this->initVar('artists', \XOBJ_DTYPE_INT, 0, false);
25
+		$this->initVar('albums', \XOBJ_DTYPE_INT, 0, false);
26
+		$this->initVar('songs', \XOBJ_DTYPE_INT, 0, false);
27
+		$this->initVar('hits', \XOBJ_DTYPE_INT, 0, false);
28
+		$this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false);
29
+		$this->initVar('votes', \XOBJ_DTYPE_INT, 0, false);
30
+		$this->initVar('created', \XOBJ_DTYPE_INT, 0, false);
31
+		$this->initVar('updated', \XOBJ_DTYPE_INT, 0, false);
32
+	}
33 33
 
34
-    /**
35
-     * @param bool $as_array
36
-     * @return array|string
37
-     */
38
-    public function getForm($as_array = false)
39
-    {
40
-        return FormController::getFormVoice($this, $as_array);
41
-    }
34
+	/**
35
+	 * @param bool $as_array
36
+	 * @return array|string
37
+	 */
38
+	public function getForm($as_array = false)
39
+	{
40
+		return FormController::getFormVoice($this, $as_array);
41
+	}
42 42
 
43
-    /**
44
-     * @return array
45
-     */
46
-    public function toArray(): array
47
-    {
48
-        $ret  = parent::toArray();
49
-        $form = $this->getForm(true);
50
-        foreach ($form as $key => $element) {
51
-            $ret['form'][$key] = $element->render();
52
-        }
53
-        foreach (['created', 'updated'] as $key) {
54
-            if ($this->getVar($key) > 0) {
55
-                $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
56
-                $ret[$key]         = \date(_DATESTRING, $this->getVar($key));
57
-            }
58
-        }
59
-        $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN;
43
+	/**
44
+	 * @return array
45
+	 */
46
+	public function toArray(): array
47
+	{
48
+		$ret  = parent::toArray();
49
+		$form = $this->getForm(true);
50
+		foreach ($form as $key => $element) {
51
+			$ret['form'][$key] = $element->render();
52
+		}
53
+		foreach (['created', 'updated'] as $key) {
54
+			if ($this->getVar($key) > 0) {
55
+				$ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
56
+				$ret[$key]         = \date(_DATESTRING, $this->getVar($key));
57
+			}
58
+		}
59
+		$ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN;
60 60
 
61
-        return $ret;
62
-    }
61
+		return $ret;
62
+	}
63 63
 
64
-    /**
65
-     * @return string
66
-     */
67
-    public function getURL(): string
68
-    {
69
-        global $file, $op, $fct, $id, $value, $gid, $vid, $cid, $start, $limit;
70
-        if ($GLOBALS['songlistModuleConfig']['htaccess']) {
71
-            return XOOPS_URL
72
-                   . '/'
73
-                   . $GLOBALS['songlistModuleConfig']['baseurl']
74
-                   . '/'
75
-                   . $file
76
-                   . '/'
77
-                   . \urlencode(\str_replace([' ', \chr(9)], '-', $this->getVar('name')))
78
-                   . '/'
79
-                   . $op
80
-                   . '-'
81
-                   . $fct
82
-                   . '-'
83
-                   . $this->getVar('gid')
84
-                   . '-'
85
-                   . \urlencode($value)
86
-                   . '-'
87
-                   . $gid
88
-                   . '-'
89
-                   . $vid
90
-                   . '-'
91
-                   . $cid
92
-                   . $GLOBALS['songlistModuleConfig']['endofurl'];
93
-        }
64
+	/**
65
+	 * @return string
66
+	 */
67
+	public function getURL(): string
68
+	{
69
+		global $file, $op, $fct, $id, $value, $gid, $vid, $cid, $start, $limit;
70
+		if ($GLOBALS['songlistModuleConfig']['htaccess']) {
71
+			return XOOPS_URL
72
+				   . '/'
73
+				   . $GLOBALS['songlistModuleConfig']['baseurl']
74
+				   . '/'
75
+				   . $file
76
+				   . '/'
77
+				   . \urlencode(\str_replace([' ', \chr(9)], '-', $this->getVar('name')))
78
+				   . '/'
79
+				   . $op
80
+				   . '-'
81
+				   . $fct
82
+				   . '-'
83
+				   . $this->getVar('gid')
84
+				   . '-'
85
+				   . \urlencode($value)
86
+				   . '-'
87
+				   . $gid
88
+				   . '-'
89
+				   . $vid
90
+				   . '-'
91
+				   . $cid
92
+				   . $GLOBALS['songlistModuleConfig']['endofurl'];
93
+		}
94 94
 
95
-        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $this->getVar('gid') . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid;
96
-    }
95
+		return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $this->getVar('gid') . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid;
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use XoopsObject;
6 6
 
7
-require_once \dirname(__DIR__) . '/include/songlist.object.php';
7
+require_once \dirname(__DIR__).'/include/songlist.object.php';
8 8
 // require_once \dirname(__DIR__) . '/include/songlist.form.php';
9 9
 use  XoopsModules\Songlist\Form\FormController;
10 10
 
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
             $ret['form'][$key] = $element->render();
52 52
         }
53 53
         foreach (['created', 'updated'] as $key) {
54
-            if ($this->getVar($key) > 0) {
54
+            if ($this->getVar($key)>0) {
55 55
                 $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
56 56
                 $ret[$key]         = \date(_DATESTRING, $this->getVar($key));
57 57
             }
58 58
         }
59
-        $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN;
59
+        $ret['rank'] = \number_format(($this->getVar('rank')>0 && $this->getVar('votes')>0 ? $this->getVar('rank')/$this->getVar('votes') : 0), 2).\_MI_SONGLIST_OFTEN;
60 60
 
61 61
         return $ret;
62 62
     }
@@ -92,6 +92,6 @@  discard block
 block discarded – undo
92 92
                    . $GLOBALS['songlistModuleConfig']['endofurl'];
93 93
         }
94 94
 
95
-        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $this->getVar('gid') . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid;
95
+        return XOOPS_URL.'/modules/songlist/'.$file.'.php?op='.$op.'&fct='.$fct.'&id='.$this->getVar('gid').'&value='.\urlencode($value ?? '').'&gid='.$gid.'&vid='.$vid.'&cid='.$cid;
96 96
     }
97 97
 }
Please login to merge, or discard this patch.
class/Utility.php 2 patches
Indentation   +789 added lines, -789 removed lines patch added patch discarded remove patch
@@ -4,11 +4,11 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Xmf\Request;
6 6
 use XoopsModules\Songlist\Form\{
7
-    SelectAlbumForm,
8
-    SelectCategoryForm,
9
-    SelectGenreForm,
10
-    SelectVoiceForm,
11
-    SelectSongForm
7
+	SelectAlbumForm,
8
+	SelectCategoryForm,
9
+	SelectGenreForm,
10
+	SelectVoiceForm,
11
+	SelectSongForm
12 12
 };
13 13
 
14 14
 
@@ -18,789 +18,789 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class Utility extends Common\SysUtility
20 20
 {
21
-    //--------------- Custom module methods -----------------------------
22
-    /**
23
-     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
24
-     *
25
-     * @param string $folder The full path of the directory to check
26
-     */
27
-    public static function createFolder($folder): void
28
-    {
29
-        //        try {
30
-        //            if (!is_dir($folder) && !mkdir($folder) && !is_dir($folder)) {
31
-        //                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
32
-        //            } else {
33
-        //                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
34
-        //            }
35
-        //        }
36
-        //        catch (\Exception $e) {
37
-        //            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
38
-        //        }
39
-        try {
40
-            if (!\is_dir($folder)) {
41
-                if (!\is_dir($folder) && !\mkdir($folder) && !\is_dir($folder)) {
42
-                    throw new \RuntimeException(\sprintf('Unable to create the %s directory', $folder));
43
-                }
44
-                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
45
-            }
46
-        } catch (\Throwable $e) {
47
-            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
48
-        }
49
-    }
50
-
51
-    /**
52
-     * @param string $file
53
-     * @param string $folder
54
-     * @return bool
55
-     */
56
-    public static function copyFile(string $file, string $folder): bool
57
-    {
58
-        return \copy($file, $folder);
59
-        //        try {
60
-        //            if (!is_dir($folder)) {
61
-        //                throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
62
-        //            } else {
63
-        //                return copy($file, $folder);
64
-        //            }
65
-        //        } catch (\Exception $e) {
66
-        //            echo 'Caught exception: ', $e->getMessage(), "\n", "<br>";
67
-        //        }
68
-        //        return false;
69
-    }
70
-
71
-    /**
72
-     * @param $src
73
-     * @param $dst
74
-     */
75
-    public static function recurseCopy($src, $dst): void
76
-    {
77
-        $dir = \opendir($src);
78
-        //    @mkdir($dst);
79
-        while (false !== ($file = \readdir($dir))) {
80
-            if (('.' !== $file) && ('..' !== $file)) {
81
-                if (\is_dir($src . '/' . $file)) {
82
-                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
83
-                } else {
84
-                    \copy($src . '/' . $file, $dst . '/' . $file);
85
-                }
86
-            }
87
-        }
88
-        \closedir($dir);
89
-    }
90
-
91
-    /**
92
-     * Verifies XOOPS version meets minimum requirements for this module
93
-     * @static
94
-     * @param \XoopsModule|null $module
95
-     *
96
-     * @param null|string       $requiredVer
97
-     * @return bool true if meets requirements, false if not
98
-     */
99
-    public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null): bool
100
-    {
101
-        $moduleDirName = \basename(\dirname(__DIR__));
102
-        if (null === $module) {
103
-            $module = \XoopsModule::getByDirname($moduleDirName);
104
-        }
105
-        \xoops_loadLanguage('admin', $moduleDirName);
106
-        \xoops_loadLanguage('common', $moduleDirName);
107
-
108
-        //check for minimum XOOPS version
109
-        $currentVer = mb_substr(\XOOPS_VERSION, 6); // get the numeric part of string
110
-        if (null === $requiredVer) {
111
-            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
112
-        }
113
-        $success = true;
114
-
115
-        if (\version_compare($currentVer, $requiredVer, '<')) {
116
-            $success = false;
117
-            $module->setErrors(\sprintf(\_AM_SONGLIST_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
118
-        }
119
-
120
-        return $success;
121
-    }
122
-
123
-    /**
124
-     * Verifies PHP version meets minimum requirements for this module
125
-     * @static
126
-     * @param \XoopsModule|bool|null $module
127
-     *
128
-     * @return bool true if meets requirements, false if not
129
-     */
130
-    public static function checkVerPhp(\XoopsModule $module = null): bool
131
-    {
132
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
133
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
134
-        if (null === $module) {
135
-            $module = \XoopsModule::getByDirname($moduleDirName);
136
-        }
137
-        \xoops_loadLanguage('admin', $moduleDirName);
138
-        \xoops_loadLanguage('common', $moduleDirName);
139
-
140
-        // check for minimum PHP version
141
-        $success = true;
142
-
143
-        $verNum = \PHP_VERSION;
144
-        $reqVer = &$module->getInfo('min_php');
145
-
146
-        if (false !== $reqVer && '' !== $reqVer) {
147
-            if (\version_compare($verNum, $reqVer, '<')) {
148
-                $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
149
-                $success = false;
150
-            }
151
-        }
152
-
153
-        return $success;
154
-    }
155
-
156
-    /**
157
-     * compares current module version with the latest GitHub release
158
-     * @static
159
-     *
160
-     * @return string|array info about the latest module version, if newer
161
-     */
162
-    public static function checkVerModule(\Xmf\Module\Helper $helper, ?string $source = 'github', ?string $default = 'master'): ?array
163
-    {
164
-        $moduleDirName      = \basename(\dirname(__DIR__, 2));
165
-        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
166
-        $update             = '';
167
-        $repository         = 'XoopsModules25x/' . $moduleDirName;
168
-        //        $repository         = 'XoopsModules25x/publisher'; //for testing only
169
-        $ret             = null;
170
-        $infoReleasesUrl = "https://api.github.com/repos/$repository/releases";
171
-        if ('github' === $source) {
172
-            if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) {
173
-                \curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl);
174
-                \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
175
-                \curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized'
176
-                \curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]);
177
-                $curlReturn = \curl_exec($curlHandle);
178
-                if (false === $curlReturn) {
179
-                    \trigger_error(\curl_error($curlHandle));
180
-                } elseif (false !== \mb_strpos($curlReturn, 'Not Found')) {
181
-                    \trigger_error('Repository Not Found: ' . $infoReleasesUrl);
182
-                } else {
183
-                    $file              = json_decode($curlReturn, false);
184
-                    $latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default);
185
-                    $latestVersion     = $file[0]->tag_name;
186
-                    $prerelease        = $file[0]->prerelease;
187
-                    if ('master' !== $latestVersionLink) {
188
-                        $update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion;
189
-                    }
190
-                    //"PHP-standardized" version
191
-                    $latestVersion = \mb_strtolower($latestVersion);
192
-                    if (false !== mb_strpos($latestVersion, 'final')) {
193
-                        $latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion));
194
-                        $latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion));
195
-                    }
196
-                    $moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
197
-                    //"PHP-standardized" version
198
-                    $moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion));
199
-                    //                    $moduleVersion = '1.0'; //for testing only
200
-                    //                    $moduleDirName = 'publisher'; //for testing only
201
-                    if (!$prerelease && \version_compare($moduleVersion, $latestVersion, '<')) {
202
-                        $ret   = [];
203
-                        $ret[] = $update;
204
-                        $ret[] = $latestVersionLink;
205
-                    }
206
-                }
207
-                \curl_close($curlHandle);
208
-            }
209
-        }
210
-
211
-        return $ret;
212
-    }
213
-
214
-    //=========================================================
215
-
216
-    /**
217
-     * @return mixed
218
-     */
219
-    public static function getToken()
220
-    {
221
-        $sql    = 'SELECT md5(rand()/rand()*rand()/rand()*rand()*rand()/rand()*rand()) as `salt`';
222
-        $result = $GLOBALS['xoopsDB']->queryF($sql);
223
-        [$salt] = $GLOBALS['xoopsDB']->fetchRow($result);
224
-
225
-        return $salt;
226
-    }
227
-
228
-    /**
229
-     * @param $string
230
-     * @return string
231
-     */
232
-    public static function ucword($string): string
233
-    {
234
-        $ret = [];
235
-        foreach (explode(' ', \mb_strtolower($string)) as $part) {
236
-            $ret[] = ucfirst($part);
237
-        }
238
-
239
-        return implode(' ', $ret);
240
-    }
241
-
242
-    /**
243
-     * @param bool|string $ip
244
-     * @return array
245
-     */
246
-    public static function getIPData($ip = false): array
247
-    {
248
-        $ret = [];
249
-        if (is_object($GLOBALS['xoopsUser'])) {
250
-            $ret['uid']   = $GLOBALS['xoopsUser']->getVar('uid');
251
-            $ret['uname'] = $GLOBALS['xoopsUser']->getVar('uname');
252
-            $ret['email'] = $GLOBALS['xoopsUser']->getVar('email');
253
-        } else {
254
-            $ret['uid']   = 0;
255
-            $ret['uname'] = ($_REQUEST['uname'] ?? '');
256
-            $ret['email'] = ($_REQUEST['email'] ?? '');
257
-        }
258
-        $ret['agent'] = $_SERVER['HTTP_USER_AGENT'];
259
-        if ($ip) {
260
-            $ret['is_proxied']   = false;
261
-            $ret['network-addy'] = @gethostbyaddr($ip);
262
-            $ret['long']         = @ip2long($ip);
263
-            if (isIpv6($ip)) {
264
-                $ret['ip6'] = true;
265
-                $ret['ip4'] = false;
266
-            } else {
267
-                $ret['ip4'] = true;
268
-                $ret['ip6'] = false;
269
-            }
270
-            $ret['ip'] = $ip;
271
-        } elseif (Request::hasVar('HTTP_X_FORWARDED_FOR', 'SERVER')) {
272
-            $ip                  = $_SERVER['HTTP_X_FORWARDED_FOR'];
273
-            $ret['is_proxied']   = true;
274
-            $proxy_ip            = $_SERVER['REMOTE_ADDR'];
275
-            $ret['network-addy'] = @gethostbyaddr($ip);
276
-            $ret['long']         = @ip2long($ip);
277
-            if (isIpv6($ip)) {
278
-                $ret['ip6']       = true;
279
-                $ret['proxy-ip6'] = true;
280
-                $ret['ip4']       = false;
281
-                $ret['proxy-ip4'] = false;
282
-            } else {
283
-                $ret['ip4']       = true;
284
-                $ret['proxy-ip4'] = true;
285
-                $ret['ip6']       = false;
286
-                $ret['proxy-ip6'] = false;
287
-            }
288
-            $ret['ip']       = $ip;
289
-            $ret['proxy-ip'] = $proxy_ip;
290
-        } else {
291
-            $ret['is_proxied']   = false;
292
-            $ip                  = $_SERVER['REMOTE_ADDR'];
293
-            $ret['network-addy'] = @gethostbyaddr($ip);
294
-            $ret['long']         = @ip2long($ip);
295
-            if (isIpv6($ip)) {
296
-                $ret['ip6'] = true;
297
-                $ret['ip4'] = false;
298
-            } else {
299
-                $ret['ip4'] = true;
300
-                $ret['ip6'] = false;
301
-            }
302
-            $ret['ip'] = $ip;
303
-        }
304
-        $ret['made'] = time();
305
-
306
-        return $ret;
307
-    }
308
-
309
-    /**
310
-     * @param string $ip
311
-     * @return bool
312
-     */
313
-    public static function isIpv6($ip = ''): bool
314
-    {
315
-        if ('' == $ip) {
316
-            return false;
317
-        }
318
-
319
-        if (mb_substr_count($ip, ':') > 0) {
320
-            return true;
321
-        }
322
-
323
-        return false;
324
-    }
325
-
326
-    /**
327
-     * @param        $filter
328
-     * @param        $field
329
-     * @param string $sort
330
-     * @param string $op
331
-     * @param string $fct
332
-     * @return bool|\XoopsModules\Songlist\Form\SelectAlbumForm|\XoopsModules\Songlist\Form\SelectArtistForm|\XoopsModules\Songlist\Form\SelectCategoryForm|\XoopsModules\Songlist\Form\SelectGenreForm|\XoopsModules\Songlist\Form\SelectVoiceForm
333
-     */
334
-    public static function getFilterElement($filter, $field, $sort = 'created', $op = '', $fct = '')
335
-    {
336
-        $components = static::getFilterURLComponents($filter, $field, $sort);
337
-        $ele        = false;
338
-        require_once dirname(__DIR__) . '/include/songlist.object.php';
339
-        switch ($field) {
340
-            case 'gid':
341
-                if ('genre' !== $op) {
342
-                    $ele = new SelectGenreForm('', 'filter_' . $field . '', $components['value'], 1, false);
343
-                    $ele->setExtra(
344
-                        'onchange="window.open(\''
345
-                        . $_SERVER['SCRIPT_NAME']
346
-                        . '?'
347
-                        . $components['extra']
348
-                        . '&filter='
349
-                        . $components['filter']
350
-                        . (!empty($components['filter']) ? '|' : '')
351
-                        . $field
352
-                        . ',\'+this.options[this.selectedIndex].value'
353
-                        . (!empty($components['operator']) ? '+\','
354
-                                                             . $components['operator']
355
-                                                             . '\'' : '')
356
-                        . ',\'_self\')"'
357
-                    );
358
-                }
359
-                break;
360
-            case 'vcid':
361
-                if ('voice' !== $op) {
362
-                    $ele = new SelectVoiceForm('', 'filter_' . $field . '', $components['value'], 1, false);
363
-                    $ele->setExtra(
364
-                        'onchange="window.open(\''
365
-                        . $_SERVER['SCRIPT_NAME']
366
-                        . '?'
367
-                        . $components['extra']
368
-                        . '&filter='
369
-                        . $components['filter']
370
-                        . (!empty($components['filter']) ? '|' : '')
371
-                        . $field
372
-                        . ',\'+this.options[this.selectedIndex].value'
373
-                        . (!empty($components['operator']) ? '+\','
374
-                                                             . $components['operator']
375
-                                                             . '\'' : '')
376
-                        . ',\'_self\')"'
377
-                    );
378
-                }
379
-                break;
380
-            case 'cid':
381
-                if ('category' !== $op) {
382
-                    $ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false);
383
-                    $ele->setExtra(
384
-                        'onchange="window.open(\''
385
-                        . $_SERVER['SCRIPT_NAME']
386
-                        . '?'
387
-                        . $components['extra']
388
-                        . '&filter='
389
-                        . $components['filter']
390
-                        . (!empty($components['filter']) ? '|' : '')
391
-                        . $field
392
-                        . ',\'+this.options[this.selectedIndex].value'
393
-                        . (!empty($components['operator']) ? '+\','
394
-                                                             . $components['operator']
395
-                                                             . '\'' : '')
396
-                        . ',\'_self\')"'
397
-                    );
398
-                }
399
-                break;
400
-            case 'pid':
401
-                $ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false);
402
-                $ele->setExtra(
403
-                    'onchange="window.open(\''
404
-                    . $_SERVER['SCRIPT_NAME']
405
-                    . '?'
406
-                    . $components['extra']
407
-                    . '&filter='
408
-                    . $components['filter']
409
-                    . (!empty($components['filter']) ? '|' : '')
410
-                    . $field
411
-                    . ',\'+this.options[this.selectedIndex].value'
412
-                    . (!empty($components['operator']) ? '+\','
413
-                                                         . $components['operator']
414
-                                                         . '\'' : '')
415
-                    . ',\'_self\')"'
416
-                );
417
-                break;
418
-            case 'abid':
419
-                if ('albums' !== $op) {
420
-                    $ele = new SelectAlbumForm('', 'filter_' . $field . '', $components['value'], 1, false);
421
-                    $ele->setExtra(
422
-                        'onchange="window.open(\''
423
-                        . $_SERVER['SCRIPT_NAME']
424
-                        . '?'
425
-                        . $components['extra']
426
-                        . '&filter='
427
-                        . $components['filter']
428
-                        . (!empty($components['filter']) ? '|' : '')
429
-                        . $field
430
-                        . ',\'+this.options[this.selectedIndex].value'
431
-                        . (!empty($components['operator']) ? '+\','
432
-                                                             . $components['operator']
433
-                                                             . '\'' : '')
434
-                        . ',\'_self\')"'
435
-                    );
436
-                }
437
-                break;
438
-            case 'aid':
439
-                if ('artists' !== $op) {
440
-                    $ele = new SelectArtistForm('', 'filter_' . $field . '', $components['value'], 1, false);
441
-                    $ele->setExtra(
442
-                        'onchange="window.open(\''
443
-                        . $_SERVER['SCRIPT_NAME']
444
-                        . '?'
445
-                        . $components['extra']
446
-                        . '&filter='
447
-                        . $components['filter']
448
-                        . (!empty($components['filter']) ? '|' : '')
449
-                        . $field
450
-                        . ',\'+this.options[this.selectedIndex].value'
451
-                        . (!empty($components['operator']) ? '+\','
452
-                                                             . $components['operator']
453
-                                                             . '\'' : '')
454
-                        . ',\'_self\')"'
455
-                    );
456
-                }
457
-                break;
458
-            case 'sid':
459
-                if ('songs' !== $op) {
460
-                    $ele = new SelectSongForm('', 'filter_' . $field . '', $components['value'], 1, false);
461
-                    $ele->setExtra(
462
-                        'onchange="window.open(\''
463
-                        . $_SERVER['SCRIPT_NAME']
464
-                        . '?'
465
-                        . $components['extra']
466
-                        . '&filter='
467
-                        . $components['filter']
468
-                        . (!empty($components['filter']) ? '|' : '')
469
-                        . $field
470
-                        . ',\'+this.options[this.selectedIndex].value'
471
-                        . (!empty($components['operator']) ? '+\','
472
-                                                             . $components['operator']
473
-                                                             . '\'' : '')
474
-                        . ',\'_self\')"'
475
-                    );
476
-                }
477
-                break;
478
-            case 'name':
479
-            case 'title':
480
-            case 'artists':
481
-            case 'albums':
482
-            case 'songs':
483
-            case 'hits':
484
-            case 'rank':
485
-            case 'votes':
486
-            case 'description':
487
-            case 'lyrics':
488
-            case 'songid':
489
-            case 'tags':
490
-                $ele = new \XoopsFormElementTray('');
491
-                $ele->addElement(new \XoopsFormText('', 'filter_' . $field . '', 11, 40, $components['value']));
492
-                $button = new \XoopsFormButton('', 'button_' . $field . '', '[+]');
493
-                $button->setExtra(
494
-                    'onclick="window.open(\''
495
-                    . $_SERVER['SCRIPT_NAME']
496
-                    . '?'
497
-                    . $components['extra']
498
-                    . '&filter='
499
-                    . $components['filter']
500
-                    . (!empty($components['filter']) ? '|' : '')
501
-                    . $field
502
-                    . ',\'+$(\'#filter_'
503
-                    . $field
504
-                    . '\').val()'
505
-                    . (!empty($components['operator']) ? '+\','
506
-                                                         . $components['operator']
507
-                                                         . '\'' : '')
508
-                    . ',\'_self\')"'
509
-                );
510
-                $ele->addElement($button);
511
-                break;
512
-        }
513
-
514
-        return $ele;
515
-    }
516
-
517
-    /**
518
-     * @param        $filter
519
-     * @param        $field
520
-     * @param string $sort
521
-     * @return array
522
-     */
523
-    public static function getFilterURLComponents($filter, $field, $sort = 'created'): array
524
-    {
525
-        $parts     = explode('|', $filter);
526
-        $ret       = [];
527
-        $value     = '';
528
-        $ele_value = '';
529
-        $operator  = '';
530
-        foreach ($parts as $part) {
531
-            $var = explode(',', $part);
532
-            if (count($var) > 1) {
533
-                if ($var[0] == $field) {
534
-                    $ele_value = $var[1];
535
-                    if (isset($var[2])) {
536
-                        $operator = $var[2];
537
-                    }
538
-                } elseif (1 != $var[0]) {
539
-                    $ret[] = implode(',', $var);
540
-                }
541
-            }
542
-        }
543
-        $pagenav          = [];
544
-        $pagenav['op']    = $_REQUEST['op'] ?? 'videos';
545
-        $pagenav['fct']   = $_REQUEST['fct'] ?? 'list';
546
-        $pagenav['limit'] = Request::getInt('limit', 30, 'REQUEST');
547
-        $pagenav['start'] = 0;
548
-        $pagenav['order'] = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC';
549
-        $pagenav['sort']  = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : $sort;
550
-        $retb             = [];
551
-        foreach ($pagenav as $key => $value) {
552
-            $retb[] = "$key=$value";
553
-        }
554
-
555
-        return ['value' => $ele_value, 'field' => $field, 'operator' => $operator, 'filter' => implode('|', $ret), 'extra' => implode('&', $retb)];
556
-    }
557
-
558
-    /**
559
-     * @param $objects
560
-     * @return array
561
-     */
562
-    public static function obj2array($objects): array
563
-    {
564
-        $ret = [];
565
-        foreach ((array)$objects as $key => $value) {
566
-            if (is_a($value, 'stdClass')) {
567
-                $ret[$key] = static::obj2array($value);
568
-            } elseif (is_array($value)) {
569
-                $ret[$key] = static::obj2array($value);
570
-            } else {
571
-                $ret[$key] = $value;
572
-            }
573
-        }
574
-
575
-        return $ret;
576
-    }
577
-
578
-    /**
579
-     * @param $url
580
-     * @return mixed
581
-     */
582
-    public static function shortenUrl($url)
583
-    {
584
-        /** @var \XoopsModuleHandler $moduleHandler */
585
-        $moduleHandler = xoops_getHandler('module');
586
-        /** @var \XoopsConfigHandler $configHandler */
587
-        $configHandler                   = xoops_getHandler('config');
588
-        $GLOBALS['songlistModule']       = $moduleHandler->getByDirname('songlist');
589
-        $GLOBALS['songlistModuleConfig'] = $configHandler->getConfigList($GLOBALS['songlistModule']->getVar('mid'));
590
-
591
-        if (!empty($GLOBALS['songlistModuleConfig']['bitly_username']) && !empty($GLOBALS['songlistModuleConfig']['bitly_apikey'])) {
592
-            $source_url = $GLOBALS['songlistModuleConfig']['bitly_apiurl'] . '/shorten?login=' . $GLOBALS['songlistModuleConfig']['bitly_username'] . '&apiKey=' . $GLOBALS['songlistModuleConfig']['bitly_apikey'] . '&format=json&longUrl=' . urlencode($url);
593
-            $cookies    = XOOPS_ROOT_PATH . '/uploads/songlist_' . md5($GLOBALS['songlistModuleConfig']['bitly_apikey']) . '.cookie';
594
-            if (!$ch = curl_init($source_url)) {
595
-                return $url;
596
-            }
597
-            curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
598
-            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
599
-            curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['songlistModuleConfig']['user_agent']);
600
-            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $GLOBALS['songlistModuleConfig']['curl_connect_timeout']);
601
-            curl_setopt($ch, CURLOPT_TIMEOUT, $GLOBALS['songlistModuleConfig']['curl_timeout']);
602
-            $data = curl_exec($ch);
603
-            curl_close($ch);
604
-            $result                = songlist_object2array(json_decode($data));
605
-            $result['status_code'] = 200;
606
-            if ($result['status_code']) {
607
-                if (!empty($result['data']['url'])) {
608
-                    return $result['data']['url'];
609
-                }
610
-
611
-                return $url;
612
-            }
613
-
614
-            return $url;
615
-        }
616
-
617
-        return $url;
618
-    }
619
-
620
-    /**
621
-     * @param        $contents
622
-     * @param int    $get_attributes
623
-     * @param string $priority
624
-     * @return array|void
625
-     */
626
-    public static function xml2array($contents, $get_attributes = 1, $priority = 'tag')
627
-    {
628
-        if (!$contents) {
629
-            return [];
630
-        }
631
-
632
-        if (!function_exists('xml_parser_create')) {
633
-            return [];
634
-        }
635
-
636
-        //Get the XML parser of PHP - PHP must have this module for the parser to work
637
-        $parser = xml_parser_create('');
638
-        xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); # https://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
639
-        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
640
-        xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
641
-        xml_parse_into_struct($parser, trim($contents), $xml_values);
642
-        xml_parser_free($parser);
643
-
644
-        if (!$xml_values) {
645
-            return;
646
-        }//Hmm...
647
-
648
-        //Initializations
649
-        $xml_array   = [];
650
-        $parents     = [];
651
-        $opened_tags = [];
652
-        $arr         = [];
653
-
654
-        $current = &$xml_array; //Refference
655
-
656
-        //Go through the tags.
657
-        $repeated_tag_index = []; //Multiple tags with same name will be turned into an array
658
-        foreach ($xml_values as $data) {
659
-            unset($attributes, $value); //Remove existing values, or there will be trouble
660
-
661
-            //This command will extract these variables into the foreach scope
662
-            // tag(string), type(string), level(int), attributes(array).
663
-            extract($data); //We could use the array by itself, but this cooler.
664
-
665
-            $result          = [];
666
-            $attributes_data = [];
667
-
668
-            if (isset($value)) {
669
-                if ('tag' === $priority) {
670
-                    $result = $value;
671
-                } else {
672
-                    $result['value'] = $value;
673
-                } //Put the value in a assoc array if we are in the 'Attribute' mode
674
-            }
675
-
676
-            //Set the attributes too.
677
-            if (isset($attributes) and $get_attributes) {
678
-                foreach ($attributes as $attr => $val) {
679
-                    if ('tag' === $priority) {
680
-                        $attributes_data[$attr] = $val;
681
-                    } else {
682
-                        $result['attr'][$attr] = $val;
683
-                    } //Set all the attributes in a array called 'attr'
684
-                }
685
-            }
686
-
687
-            //See tag status and do the needed.
688
-            if ('open' === $type) {//The starting of the tag '<tag>'
689
-                $parent[$level - 1] = &$current;
690
-                if (!is_array($current) or (!array_key_exists($tag, $current))) { //Insert New tag
691
-                    $current[$tag] = $result;
692
-                    if ($attributes_data) {
693
-                        $current[$tag . '_attr'] = $attributes_data;
694
-                    }
695
-                    $repeated_tag_index[$tag . '_' . $level] = 1;
696
-
697
-                    $current = &$current[$tag];
698
-                } else { //There was another element with the same tag name
699
-                    if (isset($current[$tag][0])) {//If there is a 0th element it is already an array
700
-                        $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
701
-                        $repeated_tag_index[$tag . '_' . $level]++;
702
-                    } else {//This section will make the value an array if multiple tags with the same name appear together
703
-                        $current[$tag]                           = [$current[$tag], $result]; //This will combine the existing item and the new item together to make an array
704
-                        $repeated_tag_index[$tag . '_' . $level] = 2;
705
-
706
-                        if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well
707
-                            $current[$tag]['0_attr'] = $current[$tag . '_attr'];
708
-                            unset($current[$tag . '_attr']);
709
-                        }
710
-                    }
711
-                    $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
712
-                    $current         = &$current[$tag][$last_item_index];
713
-                }
714
-            } elseif ('complete' === $type) { //Tags that ends in 1 line '<tag>'
715
-                //See if the key is already taken.
716
-                if (isset($current[$tag])) { //If taken, put all things inside a list(array)
717
-                    if (isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array...
718
-                        // ...push the new element into that array.
719
-                        $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
720
-
721
-                        if ('tag' === $priority and $get_attributes and $attributes_data) {
722
-                            $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
723
-                        }
724
-                        $repeated_tag_index[$tag . '_' . $level]++;
725
-                    } else { //If it is not an array...
726
-                        $current[$tag]                           = [$current[$tag], $result]; //...Make it an array using using the existing value and the new value
727
-                        $repeated_tag_index[$tag . '_' . $level] = 1;
728
-                        if ('tag' === $priority and $get_attributes) {
729
-                            if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well
730
-                                $current[$tag]['0_attr'] = $current[$tag . '_attr'];
731
-                                unset($current[$tag . '_attr']);
732
-                            }
733
-
734
-                            if ($attributes_data) {
735
-                                $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
736
-                            }
737
-                        }
738
-                        $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
739
-                    }
740
-                } else { //New Key
741
-                    $current[$tag]                           = $result;
742
-                    $repeated_tag_index[$tag . '_' . $level] = 1;
743
-                    if ('tag' === $priority and $attributes_data) {
744
-                        $current[$tag . '_attr'] = $attributes_data;
745
-                    }
746
-                }
747
-            } elseif ('close' === $type) { //End of tag '</tag>'
748
-                $current = &$parent[$level - 1];
749
-            }
750
-        }
751
-
752
-        return $xml_array;
753
-    }
754
-
755
-    /**
756
-     * @param $array
757
-     * @param $name
758
-     * @param $standalone
759
-     * @param $beginning
760
-     * @param $nested
761
-     * @return string
762
-     */
763
-    public static function toXml($array, $name, $standalone, $beginning, $nested): string
764
-    {
765
-        $output = '';
766
-        if ($beginning) {
767
-            if ($standalone) {
768
-                header('content-type:text/xml;charset=' . _CHARSET);
769
-            }
770
-            $output .= '<' . '?' . 'xml version="1.0" encoding="' . _CHARSET . '"' . '?' . '>' . "\n";
771
-            $output .= '<' . $name . '>' . "\n";
772
-            $nested = 0;
773
-        }
774
-
775
-        if (is_array($array)) {
776
-            foreach ($array as $key => $value) {
777
-                ++$nested;
778
-                if (is_array($value)) {
779
-                    $output .= str_repeat("\t", (int)$nested) . '<' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n";
780
-                    ++$nested;
781
-                    $output .= static::toXml($value, $name, false, false, $nested);
782
-                    $nested--;
783
-                    $output .= str_repeat("\t", (int)$nested) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n";
784
-                } elseif ('' != $value) {
785
-                    ++$nested;
786
-                    $output .= str_repeat("\t", (int)$nested) . '  <' . (is_string($key) ? $key : $name . '_' . $key) . '>' . trim($value) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n";
787
-                    $nested--;
788
-                }
789
-                $nested--;
790
-            }
791
-        } elseif ('' != $array) {
792
-            ++$nested;
793
-            $output .= str_repeat("\t", (int)$nested) . trim($array) . "\n";
794
-            $nested--;
795
-        }
796
-
797
-        if ($beginning) {
798
-            $output .= '</' . $name . '>';
799
-
800
-            return $output;
801
-        }
802
-
803
-        return $output;
804
-    }
21
+	//--------------- Custom module methods -----------------------------
22
+	/**
23
+	 * Function responsible for checking if a directory exists, we can also write in and create an index.html file
24
+	 *
25
+	 * @param string $folder The full path of the directory to check
26
+	 */
27
+	public static function createFolder($folder): void
28
+	{
29
+		//        try {
30
+		//            if (!is_dir($folder) && !mkdir($folder) && !is_dir($folder)) {
31
+		//                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
32
+		//            } else {
33
+		//                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
34
+		//            }
35
+		//        }
36
+		//        catch (\Exception $e) {
37
+		//            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
38
+		//        }
39
+		try {
40
+			if (!\is_dir($folder)) {
41
+				if (!\is_dir($folder) && !\mkdir($folder) && !\is_dir($folder)) {
42
+					throw new \RuntimeException(\sprintf('Unable to create the %s directory', $folder));
43
+				}
44
+				file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
45
+			}
46
+		} catch (\Throwable $e) {
47
+			echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
48
+		}
49
+	}
50
+
51
+	/**
52
+	 * @param string $file
53
+	 * @param string $folder
54
+	 * @return bool
55
+	 */
56
+	public static function copyFile(string $file, string $folder): bool
57
+	{
58
+		return \copy($file, $folder);
59
+		//        try {
60
+		//            if (!is_dir($folder)) {
61
+		//                throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
62
+		//            } else {
63
+		//                return copy($file, $folder);
64
+		//            }
65
+		//        } catch (\Exception $e) {
66
+		//            echo 'Caught exception: ', $e->getMessage(), "\n", "<br>";
67
+		//        }
68
+		//        return false;
69
+	}
70
+
71
+	/**
72
+	 * @param $src
73
+	 * @param $dst
74
+	 */
75
+	public static function recurseCopy($src, $dst): void
76
+	{
77
+		$dir = \opendir($src);
78
+		//    @mkdir($dst);
79
+		while (false !== ($file = \readdir($dir))) {
80
+			if (('.' !== $file) && ('..' !== $file)) {
81
+				if (\is_dir($src . '/' . $file)) {
82
+					self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
83
+				} else {
84
+					\copy($src . '/' . $file, $dst . '/' . $file);
85
+				}
86
+			}
87
+		}
88
+		\closedir($dir);
89
+	}
90
+
91
+	/**
92
+	 * Verifies XOOPS version meets minimum requirements for this module
93
+	 * @static
94
+	 * @param \XoopsModule|null $module
95
+	 *
96
+	 * @param null|string       $requiredVer
97
+	 * @return bool true if meets requirements, false if not
98
+	 */
99
+	public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null): bool
100
+	{
101
+		$moduleDirName = \basename(\dirname(__DIR__));
102
+		if (null === $module) {
103
+			$module = \XoopsModule::getByDirname($moduleDirName);
104
+		}
105
+		\xoops_loadLanguage('admin', $moduleDirName);
106
+		\xoops_loadLanguage('common', $moduleDirName);
107
+
108
+		//check for minimum XOOPS version
109
+		$currentVer = mb_substr(\XOOPS_VERSION, 6); // get the numeric part of string
110
+		if (null === $requiredVer) {
111
+			$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
112
+		}
113
+		$success = true;
114
+
115
+		if (\version_compare($currentVer, $requiredVer, '<')) {
116
+			$success = false;
117
+			$module->setErrors(\sprintf(\_AM_SONGLIST_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
118
+		}
119
+
120
+		return $success;
121
+	}
122
+
123
+	/**
124
+	 * Verifies PHP version meets minimum requirements for this module
125
+	 * @static
126
+	 * @param \XoopsModule|bool|null $module
127
+	 *
128
+	 * @return bool true if meets requirements, false if not
129
+	 */
130
+	public static function checkVerPhp(\XoopsModule $module = null): bool
131
+	{
132
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
133
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
134
+		if (null === $module) {
135
+			$module = \XoopsModule::getByDirname($moduleDirName);
136
+		}
137
+		\xoops_loadLanguage('admin', $moduleDirName);
138
+		\xoops_loadLanguage('common', $moduleDirName);
139
+
140
+		// check for minimum PHP version
141
+		$success = true;
142
+
143
+		$verNum = \PHP_VERSION;
144
+		$reqVer = &$module->getInfo('min_php');
145
+
146
+		if (false !== $reqVer && '' !== $reqVer) {
147
+			if (\version_compare($verNum, $reqVer, '<')) {
148
+				$module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
149
+				$success = false;
150
+			}
151
+		}
152
+
153
+		return $success;
154
+	}
155
+
156
+	/**
157
+	 * compares current module version with the latest GitHub release
158
+	 * @static
159
+	 *
160
+	 * @return string|array info about the latest module version, if newer
161
+	 */
162
+	public static function checkVerModule(\Xmf\Module\Helper $helper, ?string $source = 'github', ?string $default = 'master'): ?array
163
+	{
164
+		$moduleDirName      = \basename(\dirname(__DIR__, 2));
165
+		$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
166
+		$update             = '';
167
+		$repository         = 'XoopsModules25x/' . $moduleDirName;
168
+		//        $repository         = 'XoopsModules25x/publisher'; //for testing only
169
+		$ret             = null;
170
+		$infoReleasesUrl = "https://api.github.com/repos/$repository/releases";
171
+		if ('github' === $source) {
172
+			if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) {
173
+				\curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl);
174
+				\curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
175
+				\curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized'
176
+				\curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]);
177
+				$curlReturn = \curl_exec($curlHandle);
178
+				if (false === $curlReturn) {
179
+					\trigger_error(\curl_error($curlHandle));
180
+				} elseif (false !== \mb_strpos($curlReturn, 'Not Found')) {
181
+					\trigger_error('Repository Not Found: ' . $infoReleasesUrl);
182
+				} else {
183
+					$file              = json_decode($curlReturn, false);
184
+					$latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default);
185
+					$latestVersion     = $file[0]->tag_name;
186
+					$prerelease        = $file[0]->prerelease;
187
+					if ('master' !== $latestVersionLink) {
188
+						$update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion;
189
+					}
190
+					//"PHP-standardized" version
191
+					$latestVersion = \mb_strtolower($latestVersion);
192
+					if (false !== mb_strpos($latestVersion, 'final')) {
193
+						$latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion));
194
+						$latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion));
195
+					}
196
+					$moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
197
+					//"PHP-standardized" version
198
+					$moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion));
199
+					//                    $moduleVersion = '1.0'; //for testing only
200
+					//                    $moduleDirName = 'publisher'; //for testing only
201
+					if (!$prerelease && \version_compare($moduleVersion, $latestVersion, '<')) {
202
+						$ret   = [];
203
+						$ret[] = $update;
204
+						$ret[] = $latestVersionLink;
205
+					}
206
+				}
207
+				\curl_close($curlHandle);
208
+			}
209
+		}
210
+
211
+		return $ret;
212
+	}
213
+
214
+	//=========================================================
215
+
216
+	/**
217
+	 * @return mixed
218
+	 */
219
+	public static function getToken()
220
+	{
221
+		$sql    = 'SELECT md5(rand()/rand()*rand()/rand()*rand()*rand()/rand()*rand()) as `salt`';
222
+		$result = $GLOBALS['xoopsDB']->queryF($sql);
223
+		[$salt] = $GLOBALS['xoopsDB']->fetchRow($result);
224
+
225
+		return $salt;
226
+	}
227
+
228
+	/**
229
+	 * @param $string
230
+	 * @return string
231
+	 */
232
+	public static function ucword($string): string
233
+	{
234
+		$ret = [];
235
+		foreach (explode(' ', \mb_strtolower($string)) as $part) {
236
+			$ret[] = ucfirst($part);
237
+		}
238
+
239
+		return implode(' ', $ret);
240
+	}
241
+
242
+	/**
243
+	 * @param bool|string $ip
244
+	 * @return array
245
+	 */
246
+	public static function getIPData($ip = false): array
247
+	{
248
+		$ret = [];
249
+		if (is_object($GLOBALS['xoopsUser'])) {
250
+			$ret['uid']   = $GLOBALS['xoopsUser']->getVar('uid');
251
+			$ret['uname'] = $GLOBALS['xoopsUser']->getVar('uname');
252
+			$ret['email'] = $GLOBALS['xoopsUser']->getVar('email');
253
+		} else {
254
+			$ret['uid']   = 0;
255
+			$ret['uname'] = ($_REQUEST['uname'] ?? '');
256
+			$ret['email'] = ($_REQUEST['email'] ?? '');
257
+		}
258
+		$ret['agent'] = $_SERVER['HTTP_USER_AGENT'];
259
+		if ($ip) {
260
+			$ret['is_proxied']   = false;
261
+			$ret['network-addy'] = @gethostbyaddr($ip);
262
+			$ret['long']         = @ip2long($ip);
263
+			if (isIpv6($ip)) {
264
+				$ret['ip6'] = true;
265
+				$ret['ip4'] = false;
266
+			} else {
267
+				$ret['ip4'] = true;
268
+				$ret['ip6'] = false;
269
+			}
270
+			$ret['ip'] = $ip;
271
+		} elseif (Request::hasVar('HTTP_X_FORWARDED_FOR', 'SERVER')) {
272
+			$ip                  = $_SERVER['HTTP_X_FORWARDED_FOR'];
273
+			$ret['is_proxied']   = true;
274
+			$proxy_ip            = $_SERVER['REMOTE_ADDR'];
275
+			$ret['network-addy'] = @gethostbyaddr($ip);
276
+			$ret['long']         = @ip2long($ip);
277
+			if (isIpv6($ip)) {
278
+				$ret['ip6']       = true;
279
+				$ret['proxy-ip6'] = true;
280
+				$ret['ip4']       = false;
281
+				$ret['proxy-ip4'] = false;
282
+			} else {
283
+				$ret['ip4']       = true;
284
+				$ret['proxy-ip4'] = true;
285
+				$ret['ip6']       = false;
286
+				$ret['proxy-ip6'] = false;
287
+			}
288
+			$ret['ip']       = $ip;
289
+			$ret['proxy-ip'] = $proxy_ip;
290
+		} else {
291
+			$ret['is_proxied']   = false;
292
+			$ip                  = $_SERVER['REMOTE_ADDR'];
293
+			$ret['network-addy'] = @gethostbyaddr($ip);
294
+			$ret['long']         = @ip2long($ip);
295
+			if (isIpv6($ip)) {
296
+				$ret['ip6'] = true;
297
+				$ret['ip4'] = false;
298
+			} else {
299
+				$ret['ip4'] = true;
300
+				$ret['ip6'] = false;
301
+			}
302
+			$ret['ip'] = $ip;
303
+		}
304
+		$ret['made'] = time();
305
+
306
+		return $ret;
307
+	}
308
+
309
+	/**
310
+	 * @param string $ip
311
+	 * @return bool
312
+	 */
313
+	public static function isIpv6($ip = ''): bool
314
+	{
315
+		if ('' == $ip) {
316
+			return false;
317
+		}
318
+
319
+		if (mb_substr_count($ip, ':') > 0) {
320
+			return true;
321
+		}
322
+
323
+		return false;
324
+	}
325
+
326
+	/**
327
+	 * @param        $filter
328
+	 * @param        $field
329
+	 * @param string $sort
330
+	 * @param string $op
331
+	 * @param string $fct
332
+	 * @return bool|\XoopsModules\Songlist\Form\SelectAlbumForm|\XoopsModules\Songlist\Form\SelectArtistForm|\XoopsModules\Songlist\Form\SelectCategoryForm|\XoopsModules\Songlist\Form\SelectGenreForm|\XoopsModules\Songlist\Form\SelectVoiceForm
333
+	 */
334
+	public static function getFilterElement($filter, $field, $sort = 'created', $op = '', $fct = '')
335
+	{
336
+		$components = static::getFilterURLComponents($filter, $field, $sort);
337
+		$ele        = false;
338
+		require_once dirname(__DIR__) . '/include/songlist.object.php';
339
+		switch ($field) {
340
+			case 'gid':
341
+				if ('genre' !== $op) {
342
+					$ele = new SelectGenreForm('', 'filter_' . $field . '', $components['value'], 1, false);
343
+					$ele->setExtra(
344
+						'onchange="window.open(\''
345
+						. $_SERVER['SCRIPT_NAME']
346
+						. '?'
347
+						. $components['extra']
348
+						. '&filter='
349
+						. $components['filter']
350
+						. (!empty($components['filter']) ? '|' : '')
351
+						. $field
352
+						. ',\'+this.options[this.selectedIndex].value'
353
+						. (!empty($components['operator']) ? '+\','
354
+															 . $components['operator']
355
+															 . '\'' : '')
356
+						. ',\'_self\')"'
357
+					);
358
+				}
359
+				break;
360
+			case 'vcid':
361
+				if ('voice' !== $op) {
362
+					$ele = new SelectVoiceForm('', 'filter_' . $field . '', $components['value'], 1, false);
363
+					$ele->setExtra(
364
+						'onchange="window.open(\''
365
+						. $_SERVER['SCRIPT_NAME']
366
+						. '?'
367
+						. $components['extra']
368
+						. '&filter='
369
+						. $components['filter']
370
+						. (!empty($components['filter']) ? '|' : '')
371
+						. $field
372
+						. ',\'+this.options[this.selectedIndex].value'
373
+						. (!empty($components['operator']) ? '+\','
374
+															 . $components['operator']
375
+															 . '\'' : '')
376
+						. ',\'_self\')"'
377
+					);
378
+				}
379
+				break;
380
+			case 'cid':
381
+				if ('category' !== $op) {
382
+					$ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false);
383
+					$ele->setExtra(
384
+						'onchange="window.open(\''
385
+						. $_SERVER['SCRIPT_NAME']
386
+						. '?'
387
+						. $components['extra']
388
+						. '&filter='
389
+						. $components['filter']
390
+						. (!empty($components['filter']) ? '|' : '')
391
+						. $field
392
+						. ',\'+this.options[this.selectedIndex].value'
393
+						. (!empty($components['operator']) ? '+\','
394
+															 . $components['operator']
395
+															 . '\'' : '')
396
+						. ',\'_self\')"'
397
+					);
398
+				}
399
+				break;
400
+			case 'pid':
401
+				$ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false);
402
+				$ele->setExtra(
403
+					'onchange="window.open(\''
404
+					. $_SERVER['SCRIPT_NAME']
405
+					. '?'
406
+					. $components['extra']
407
+					. '&filter='
408
+					. $components['filter']
409
+					. (!empty($components['filter']) ? '|' : '')
410
+					. $field
411
+					. ',\'+this.options[this.selectedIndex].value'
412
+					. (!empty($components['operator']) ? '+\','
413
+														 . $components['operator']
414
+														 . '\'' : '')
415
+					. ',\'_self\')"'
416
+				);
417
+				break;
418
+			case 'abid':
419
+				if ('albums' !== $op) {
420
+					$ele = new SelectAlbumForm('', 'filter_' . $field . '', $components['value'], 1, false);
421
+					$ele->setExtra(
422
+						'onchange="window.open(\''
423
+						. $_SERVER['SCRIPT_NAME']
424
+						. '?'
425
+						. $components['extra']
426
+						. '&filter='
427
+						. $components['filter']
428
+						. (!empty($components['filter']) ? '|' : '')
429
+						. $field
430
+						. ',\'+this.options[this.selectedIndex].value'
431
+						. (!empty($components['operator']) ? '+\','
432
+															 . $components['operator']
433
+															 . '\'' : '')
434
+						. ',\'_self\')"'
435
+					);
436
+				}
437
+				break;
438
+			case 'aid':
439
+				if ('artists' !== $op) {
440
+					$ele = new SelectArtistForm('', 'filter_' . $field . '', $components['value'], 1, false);
441
+					$ele->setExtra(
442
+						'onchange="window.open(\''
443
+						. $_SERVER['SCRIPT_NAME']
444
+						. '?'
445
+						. $components['extra']
446
+						. '&filter='
447
+						. $components['filter']
448
+						. (!empty($components['filter']) ? '|' : '')
449
+						. $field
450
+						. ',\'+this.options[this.selectedIndex].value'
451
+						. (!empty($components['operator']) ? '+\','
452
+															 . $components['operator']
453
+															 . '\'' : '')
454
+						. ',\'_self\')"'
455
+					);
456
+				}
457
+				break;
458
+			case 'sid':
459
+				if ('songs' !== $op) {
460
+					$ele = new SelectSongForm('', 'filter_' . $field . '', $components['value'], 1, false);
461
+					$ele->setExtra(
462
+						'onchange="window.open(\''
463
+						. $_SERVER['SCRIPT_NAME']
464
+						. '?'
465
+						. $components['extra']
466
+						. '&filter='
467
+						. $components['filter']
468
+						. (!empty($components['filter']) ? '|' : '')
469
+						. $field
470
+						. ',\'+this.options[this.selectedIndex].value'
471
+						. (!empty($components['operator']) ? '+\','
472
+															 . $components['operator']
473
+															 . '\'' : '')
474
+						. ',\'_self\')"'
475
+					);
476
+				}
477
+				break;
478
+			case 'name':
479
+			case 'title':
480
+			case 'artists':
481
+			case 'albums':
482
+			case 'songs':
483
+			case 'hits':
484
+			case 'rank':
485
+			case 'votes':
486
+			case 'description':
487
+			case 'lyrics':
488
+			case 'songid':
489
+			case 'tags':
490
+				$ele = new \XoopsFormElementTray('');
491
+				$ele->addElement(new \XoopsFormText('', 'filter_' . $field . '', 11, 40, $components['value']));
492
+				$button = new \XoopsFormButton('', 'button_' . $field . '', '[+]');
493
+				$button->setExtra(
494
+					'onclick="window.open(\''
495
+					. $_SERVER['SCRIPT_NAME']
496
+					. '?'
497
+					. $components['extra']
498
+					. '&filter='
499
+					. $components['filter']
500
+					. (!empty($components['filter']) ? '|' : '')
501
+					. $field
502
+					. ',\'+$(\'#filter_'
503
+					. $field
504
+					. '\').val()'
505
+					. (!empty($components['operator']) ? '+\','
506
+														 . $components['operator']
507
+														 . '\'' : '')
508
+					. ',\'_self\')"'
509
+				);
510
+				$ele->addElement($button);
511
+				break;
512
+		}
513
+
514
+		return $ele;
515
+	}
516
+
517
+	/**
518
+	 * @param        $filter
519
+	 * @param        $field
520
+	 * @param string $sort
521
+	 * @return array
522
+	 */
523
+	public static function getFilterURLComponents($filter, $field, $sort = 'created'): array
524
+	{
525
+		$parts     = explode('|', $filter);
526
+		$ret       = [];
527
+		$value     = '';
528
+		$ele_value = '';
529
+		$operator  = '';
530
+		foreach ($parts as $part) {
531
+			$var = explode(',', $part);
532
+			if (count($var) > 1) {
533
+				if ($var[0] == $field) {
534
+					$ele_value = $var[1];
535
+					if (isset($var[2])) {
536
+						$operator = $var[2];
537
+					}
538
+				} elseif (1 != $var[0]) {
539
+					$ret[] = implode(',', $var);
540
+				}
541
+			}
542
+		}
543
+		$pagenav          = [];
544
+		$pagenav['op']    = $_REQUEST['op'] ?? 'videos';
545
+		$pagenav['fct']   = $_REQUEST['fct'] ?? 'list';
546
+		$pagenav['limit'] = Request::getInt('limit', 30, 'REQUEST');
547
+		$pagenav['start'] = 0;
548
+		$pagenav['order'] = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC';
549
+		$pagenav['sort']  = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : $sort;
550
+		$retb             = [];
551
+		foreach ($pagenav as $key => $value) {
552
+			$retb[] = "$key=$value";
553
+		}
554
+
555
+		return ['value' => $ele_value, 'field' => $field, 'operator' => $operator, 'filter' => implode('|', $ret), 'extra' => implode('&', $retb)];
556
+	}
557
+
558
+	/**
559
+	 * @param $objects
560
+	 * @return array
561
+	 */
562
+	public static function obj2array($objects): array
563
+	{
564
+		$ret = [];
565
+		foreach ((array)$objects as $key => $value) {
566
+			if (is_a($value, 'stdClass')) {
567
+				$ret[$key] = static::obj2array($value);
568
+			} elseif (is_array($value)) {
569
+				$ret[$key] = static::obj2array($value);
570
+			} else {
571
+				$ret[$key] = $value;
572
+			}
573
+		}
574
+
575
+		return $ret;
576
+	}
577
+
578
+	/**
579
+	 * @param $url
580
+	 * @return mixed
581
+	 */
582
+	public static function shortenUrl($url)
583
+	{
584
+		/** @var \XoopsModuleHandler $moduleHandler */
585
+		$moduleHandler = xoops_getHandler('module');
586
+		/** @var \XoopsConfigHandler $configHandler */
587
+		$configHandler                   = xoops_getHandler('config');
588
+		$GLOBALS['songlistModule']       = $moduleHandler->getByDirname('songlist');
589
+		$GLOBALS['songlistModuleConfig'] = $configHandler->getConfigList($GLOBALS['songlistModule']->getVar('mid'));
590
+
591
+		if (!empty($GLOBALS['songlistModuleConfig']['bitly_username']) && !empty($GLOBALS['songlistModuleConfig']['bitly_apikey'])) {
592
+			$source_url = $GLOBALS['songlistModuleConfig']['bitly_apiurl'] . '/shorten?login=' . $GLOBALS['songlistModuleConfig']['bitly_username'] . '&apiKey=' . $GLOBALS['songlistModuleConfig']['bitly_apikey'] . '&format=json&longUrl=' . urlencode($url);
593
+			$cookies    = XOOPS_ROOT_PATH . '/uploads/songlist_' . md5($GLOBALS['songlistModuleConfig']['bitly_apikey']) . '.cookie';
594
+			if (!$ch = curl_init($source_url)) {
595
+				return $url;
596
+			}
597
+			curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
598
+			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
599
+			curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['songlistModuleConfig']['user_agent']);
600
+			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $GLOBALS['songlistModuleConfig']['curl_connect_timeout']);
601
+			curl_setopt($ch, CURLOPT_TIMEOUT, $GLOBALS['songlistModuleConfig']['curl_timeout']);
602
+			$data = curl_exec($ch);
603
+			curl_close($ch);
604
+			$result                = songlist_object2array(json_decode($data));
605
+			$result['status_code'] = 200;
606
+			if ($result['status_code']) {
607
+				if (!empty($result['data']['url'])) {
608
+					return $result['data']['url'];
609
+				}
610
+
611
+				return $url;
612
+			}
613
+
614
+			return $url;
615
+		}
616
+
617
+		return $url;
618
+	}
619
+
620
+	/**
621
+	 * @param        $contents
622
+	 * @param int    $get_attributes
623
+	 * @param string $priority
624
+	 * @return array|void
625
+	 */
626
+	public static function xml2array($contents, $get_attributes = 1, $priority = 'tag')
627
+	{
628
+		if (!$contents) {
629
+			return [];
630
+		}
631
+
632
+		if (!function_exists('xml_parser_create')) {
633
+			return [];
634
+		}
635
+
636
+		//Get the XML parser of PHP - PHP must have this module for the parser to work
637
+		$parser = xml_parser_create('');
638
+		xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); # https://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
639
+		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
640
+		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
641
+		xml_parse_into_struct($parser, trim($contents), $xml_values);
642
+		xml_parser_free($parser);
643
+
644
+		if (!$xml_values) {
645
+			return;
646
+		}//Hmm...
647
+
648
+		//Initializations
649
+		$xml_array   = [];
650
+		$parents     = [];
651
+		$opened_tags = [];
652
+		$arr         = [];
653
+
654
+		$current = &$xml_array; //Refference
655
+
656
+		//Go through the tags.
657
+		$repeated_tag_index = []; //Multiple tags with same name will be turned into an array
658
+		foreach ($xml_values as $data) {
659
+			unset($attributes, $value); //Remove existing values, or there will be trouble
660
+
661
+			//This command will extract these variables into the foreach scope
662
+			// tag(string), type(string), level(int), attributes(array).
663
+			extract($data); //We could use the array by itself, but this cooler.
664
+
665
+			$result          = [];
666
+			$attributes_data = [];
667
+
668
+			if (isset($value)) {
669
+				if ('tag' === $priority) {
670
+					$result = $value;
671
+				} else {
672
+					$result['value'] = $value;
673
+				} //Put the value in a assoc array if we are in the 'Attribute' mode
674
+			}
675
+
676
+			//Set the attributes too.
677
+			if (isset($attributes) and $get_attributes) {
678
+				foreach ($attributes as $attr => $val) {
679
+					if ('tag' === $priority) {
680
+						$attributes_data[$attr] = $val;
681
+					} else {
682
+						$result['attr'][$attr] = $val;
683
+					} //Set all the attributes in a array called 'attr'
684
+				}
685
+			}
686
+
687
+			//See tag status and do the needed.
688
+			if ('open' === $type) {//The starting of the tag '<tag>'
689
+				$parent[$level - 1] = &$current;
690
+				if (!is_array($current) or (!array_key_exists($tag, $current))) { //Insert New tag
691
+					$current[$tag] = $result;
692
+					if ($attributes_data) {
693
+						$current[$tag . '_attr'] = $attributes_data;
694
+					}
695
+					$repeated_tag_index[$tag . '_' . $level] = 1;
696
+
697
+					$current = &$current[$tag];
698
+				} else { //There was another element with the same tag name
699
+					if (isset($current[$tag][0])) {//If there is a 0th element it is already an array
700
+						$current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
701
+						$repeated_tag_index[$tag . '_' . $level]++;
702
+					} else {//This section will make the value an array if multiple tags with the same name appear together
703
+						$current[$tag]                           = [$current[$tag], $result]; //This will combine the existing item and the new item together to make an array
704
+						$repeated_tag_index[$tag . '_' . $level] = 2;
705
+
706
+						if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well
707
+							$current[$tag]['0_attr'] = $current[$tag . '_attr'];
708
+							unset($current[$tag . '_attr']);
709
+						}
710
+					}
711
+					$last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
712
+					$current         = &$current[$tag][$last_item_index];
713
+				}
714
+			} elseif ('complete' === $type) { //Tags that ends in 1 line '<tag>'
715
+				//See if the key is already taken.
716
+				if (isset($current[$tag])) { //If taken, put all things inside a list(array)
717
+					if (isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array...
718
+						// ...push the new element into that array.
719
+						$current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
720
+
721
+						if ('tag' === $priority and $get_attributes and $attributes_data) {
722
+							$current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
723
+						}
724
+						$repeated_tag_index[$tag . '_' . $level]++;
725
+					} else { //If it is not an array...
726
+						$current[$tag]                           = [$current[$tag], $result]; //...Make it an array using using the existing value and the new value
727
+						$repeated_tag_index[$tag . '_' . $level] = 1;
728
+						if ('tag' === $priority and $get_attributes) {
729
+							if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well
730
+								$current[$tag]['0_attr'] = $current[$tag . '_attr'];
731
+								unset($current[$tag . '_attr']);
732
+							}
733
+
734
+							if ($attributes_data) {
735
+								$current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
736
+							}
737
+						}
738
+						$repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
739
+					}
740
+				} else { //New Key
741
+					$current[$tag]                           = $result;
742
+					$repeated_tag_index[$tag . '_' . $level] = 1;
743
+					if ('tag' === $priority and $attributes_data) {
744
+						$current[$tag . '_attr'] = $attributes_data;
745
+					}
746
+				}
747
+			} elseif ('close' === $type) { //End of tag '</tag>'
748
+				$current = &$parent[$level - 1];
749
+			}
750
+		}
751
+
752
+		return $xml_array;
753
+	}
754
+
755
+	/**
756
+	 * @param $array
757
+	 * @param $name
758
+	 * @param $standalone
759
+	 * @param $beginning
760
+	 * @param $nested
761
+	 * @return string
762
+	 */
763
+	public static function toXml($array, $name, $standalone, $beginning, $nested): string
764
+	{
765
+		$output = '';
766
+		if ($beginning) {
767
+			if ($standalone) {
768
+				header('content-type:text/xml;charset=' . _CHARSET);
769
+			}
770
+			$output .= '<' . '?' . 'xml version="1.0" encoding="' . _CHARSET . '"' . '?' . '>' . "\n";
771
+			$output .= '<' . $name . '>' . "\n";
772
+			$nested = 0;
773
+		}
774
+
775
+		if (is_array($array)) {
776
+			foreach ($array as $key => $value) {
777
+				++$nested;
778
+				if (is_array($value)) {
779
+					$output .= str_repeat("\t", (int)$nested) . '<' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n";
780
+					++$nested;
781
+					$output .= static::toXml($value, $name, false, false, $nested);
782
+					$nested--;
783
+					$output .= str_repeat("\t", (int)$nested) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n";
784
+				} elseif ('' != $value) {
785
+					++$nested;
786
+					$output .= str_repeat("\t", (int)$nested) . '  <' . (is_string($key) ? $key : $name . '_' . $key) . '>' . trim($value) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n";
787
+					$nested--;
788
+				}
789
+				$nested--;
790
+			}
791
+		} elseif ('' != $array) {
792
+			++$nested;
793
+			$output .= str_repeat("\t", (int)$nested) . trim($array) . "\n";
794
+			$nested--;
795
+		}
796
+
797
+		if ($beginning) {
798
+			$output .= '</' . $name . '>';
799
+
800
+			return $output;
801
+		}
802
+
803
+		return $output;
804
+	}
805 805
     
806 806
 }
Please login to merge, or discard this patch.
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
                 if (!\is_dir($folder) && !\mkdir($folder) && !\is_dir($folder)) {
42 42
                     throw new \RuntimeException(\sprintf('Unable to create the %s directory', $folder));
43 43
                 }
44
-                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
44
+                file_put_contents($folder.'/index.html', '<script>history.go(-1);</script>');
45 45
             }
46 46
         } catch (\Throwable $e) {
47 47
             echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
     {
77 77
         $dir = \opendir($src);
78 78
         //    @mkdir($dst);
79
-        while (false !== ($file = \readdir($dir))) {
80
-            if (('.' !== $file) && ('..' !== $file)) {
81
-                if (\is_dir($src . '/' . $file)) {
82
-                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
79
+        while (false!==($file = \readdir($dir))) {
80
+            if (('.'!==$file) && ('..'!==$file)) {
81
+                if (\is_dir($src.'/'.$file)) {
82
+                    self::recurseCopy($src.'/'.$file, $dst.'/'.$file);
83 83
                 } else {
84
-                    \copy($src . '/' . $file, $dst . '/' . $file);
84
+                    \copy($src.'/'.$file, $dst.'/'.$file);
85 85
                 }
86 86
             }
87 87
         }
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null): bool
100 100
     {
101 101
         $moduleDirName = \basename(\dirname(__DIR__));
102
-        if (null === $module) {
102
+        if (null===$module) {
103 103
             $module = \XoopsModule::getByDirname($moduleDirName);
104 104
         }
105 105
         \xoops_loadLanguage('admin', $moduleDirName);
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 
108 108
         //check for minimum XOOPS version
109 109
         $currentVer = mb_substr(\XOOPS_VERSION, 6); // get the numeric part of string
110
-        if (null === $requiredVer) {
111
-            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
110
+        if (null===$requiredVer) {
111
+            $requiredVer = ''.$module->getInfo('min_xoops'); //making sure it's a string
112 112
         }
113 113
         $success = true;
114 114
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
     {
132 132
         $moduleDirName      = \basename(\dirname(__DIR__, 2));
133 133
         $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
134
-        if (null === $module) {
134
+        if (null===$module) {
135 135
             $module = \XoopsModule::getByDirname($moduleDirName);
136 136
         }
137 137
         \xoops_loadLanguage('admin', $moduleDirName);
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
         $verNum = \PHP_VERSION;
144 144
         $reqVer = &$module->getInfo('min_php');
145 145
 
146
-        if (false !== $reqVer && '' !== $reqVer) {
146
+        if (false!==$reqVer && ''!==$reqVer) {
147 147
             if (\version_compare($verNum, $reqVer, '<')) {
148
-                $module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum));
148
+                $module->setErrors(\sprintf(\constant('CO_'.$moduleDirNameUpper.'_ERROR_BAD_PHP'), $reqVer, $verNum));
149 149
                 $success = false;
150 150
             }
151 151
         }
@@ -164,36 +164,36 @@  discard block
 block discarded – undo
164 164
         $moduleDirName      = \basename(\dirname(__DIR__, 2));
165 165
         $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
166 166
         $update             = '';
167
-        $repository         = 'XoopsModules25x/' . $moduleDirName;
167
+        $repository         = 'XoopsModules25x/'.$moduleDirName;
168 168
         //        $repository         = 'XoopsModules25x/publisher'; //for testing only
169 169
         $ret             = null;
170 170
         $infoReleasesUrl = "https://api.github.com/repos/$repository/releases";
171
-        if ('github' === $source) {
172
-            if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) {
171
+        if ('github'===$source) {
172
+            if (\function_exists('curl_init') && false!==($curlHandle = \curl_init())) {
173 173
                 \curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl);
174 174
                 \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
175 175
                 \curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized'
176 176
                 \curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]);
177 177
                 $curlReturn = \curl_exec($curlHandle);
178
-                if (false === $curlReturn) {
178
+                if (false===$curlReturn) {
179 179
                     \trigger_error(\curl_error($curlHandle));
180
-                } elseif (false !== \mb_strpos($curlReturn, 'Not Found')) {
181
-                    \trigger_error('Repository Not Found: ' . $infoReleasesUrl);
180
+                } elseif (false!==\mb_strpos($curlReturn, 'Not Found')) {
181
+                    \trigger_error('Repository Not Found: '.$infoReleasesUrl);
182 182
                 } else {
183 183
                     $file              = json_decode($curlReturn, false);
184 184
                     $latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default);
185 185
                     $latestVersion     = $file[0]->tag_name;
186 186
                     $prerelease        = $file[0]->prerelease;
187
-                    if ('master' !== $latestVersionLink) {
188
-                        $update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion;
187
+                    if ('master'!==$latestVersionLink) {
188
+                        $update = \constant('CO_'.$moduleDirNameUpper.'_'.'NEW_VERSION').$latestVersion;
189 189
                     }
190 190
                     //"PHP-standardized" version
191 191
                     $latestVersion = \mb_strtolower($latestVersion);
192
-                    if (false !== mb_strpos($latestVersion, 'final')) {
192
+                    if (false!==mb_strpos($latestVersion, 'final')) {
193 193
                         $latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion));
194 194
                         $latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion));
195 195
                     }
196
-                    $moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'));
196
+                    $moduleVersion = ($helper->getModule()->getInfo('version').'_'.$helper->getModule()->getInfo('module_status'));
197 197
                     //"PHP-standardized" version
198 198
                     $moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion));
199 199
                     //                    $moduleVersion = '1.0'; //for testing only
@@ -312,11 +312,11 @@  discard block
 block discarded – undo
312 312
      */
313 313
     public static function isIpv6($ip = ''): bool
314 314
     {
315
-        if ('' == $ip) {
315
+        if (''==$ip) {
316 316
             return false;
317 317
         }
318 318
 
319
-        if (mb_substr_count($ip, ':') > 0) {
319
+        if (mb_substr_count($ip, ':')>0) {
320 320
             return true;
321 321
         }
322 322
 
@@ -335,11 +335,11 @@  discard block
 block discarded – undo
335 335
     {
336 336
         $components = static::getFilterURLComponents($filter, $field, $sort);
337 337
         $ele        = false;
338
-        require_once dirname(__DIR__) . '/include/songlist.object.php';
338
+        require_once dirname(__DIR__).'/include/songlist.object.php';
339 339
         switch ($field) {
340 340
             case 'gid':
341
-                if ('genre' !== $op) {
342
-                    $ele = new SelectGenreForm('', 'filter_' . $field . '', $components['value'], 1, false);
341
+                if ('genre'!==$op) {
342
+                    $ele = new SelectGenreForm('', 'filter_'.$field.'', $components['value'], 1, false);
343 343
                     $ele->setExtra(
344 344
                         'onchange="window.open(\''
345 345
                         . $_SERVER['SCRIPT_NAME']
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
                 }
359 359
                 break;
360 360
             case 'vcid':
361
-                if ('voice' !== $op) {
362
-                    $ele = new SelectVoiceForm('', 'filter_' . $field . '', $components['value'], 1, false);
361
+                if ('voice'!==$op) {
362
+                    $ele = new SelectVoiceForm('', 'filter_'.$field.'', $components['value'], 1, false);
363 363
                     $ele->setExtra(
364 364
                         'onchange="window.open(\''
365 365
                         . $_SERVER['SCRIPT_NAME']
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
                 }
379 379
                 break;
380 380
             case 'cid':
381
-                if ('category' !== $op) {
382
-                    $ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false);
381
+                if ('category'!==$op) {
382
+                    $ele = new SelectCategoryForm('', 'filter_'.$field.'', $components['value'], 1, false);
383 383
                     $ele->setExtra(
384 384
                         'onchange="window.open(\''
385 385
                         . $_SERVER['SCRIPT_NAME']
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
                 }
399 399
                 break;
400 400
             case 'pid':
401
-                $ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false);
401
+                $ele = new SelectCategoryForm('', 'filter_'.$field.'', $components['value'], 1, false);
402 402
                 $ele->setExtra(
403 403
                     'onchange="window.open(\''
404 404
                     . $_SERVER['SCRIPT_NAME']
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
                 );
417 417
                 break;
418 418
             case 'abid':
419
-                if ('albums' !== $op) {
420
-                    $ele = new SelectAlbumForm('', 'filter_' . $field . '', $components['value'], 1, false);
419
+                if ('albums'!==$op) {
420
+                    $ele = new SelectAlbumForm('', 'filter_'.$field.'', $components['value'], 1, false);
421 421
                     $ele->setExtra(
422 422
                         'onchange="window.open(\''
423 423
                         . $_SERVER['SCRIPT_NAME']
@@ -436,8 +436,8 @@  discard block
 block discarded – undo
436 436
                 }
437 437
                 break;
438 438
             case 'aid':
439
-                if ('artists' !== $op) {
440
-                    $ele = new SelectArtistForm('', 'filter_' . $field . '', $components['value'], 1, false);
439
+                if ('artists'!==$op) {
440
+                    $ele = new SelectArtistForm('', 'filter_'.$field.'', $components['value'], 1, false);
441 441
                     $ele->setExtra(
442 442
                         'onchange="window.open(\''
443 443
                         . $_SERVER['SCRIPT_NAME']
@@ -456,8 +456,8 @@  discard block
 block discarded – undo
456 456
                 }
457 457
                 break;
458 458
             case 'sid':
459
-                if ('songs' !== $op) {
460
-                    $ele = new SelectSongForm('', 'filter_' . $field . '', $components['value'], 1, false);
459
+                if ('songs'!==$op) {
460
+                    $ele = new SelectSongForm('', 'filter_'.$field.'', $components['value'], 1, false);
461 461
                     $ele->setExtra(
462 462
                         'onchange="window.open(\''
463 463
                         . $_SERVER['SCRIPT_NAME']
@@ -488,8 +488,8 @@  discard block
 block discarded – undo
488 488
             case 'songid':
489 489
             case 'tags':
490 490
                 $ele = new \XoopsFormElementTray('');
491
-                $ele->addElement(new \XoopsFormText('', 'filter_' . $field . '', 11, 40, $components['value']));
492
-                $button = new \XoopsFormButton('', 'button_' . $field . '', '[+]');
491
+                $ele->addElement(new \XoopsFormText('', 'filter_'.$field.'', 11, 40, $components['value']));
492
+                $button = new \XoopsFormButton('', 'button_'.$field.'', '[+]');
493 493
                 $button->setExtra(
494 494
                     'onclick="window.open(\''
495 495
                     . $_SERVER['SCRIPT_NAME']
@@ -529,13 +529,13 @@  discard block
 block discarded – undo
529 529
         $operator  = '';
530 530
         foreach ($parts as $part) {
531 531
             $var = explode(',', $part);
532
-            if (count($var) > 1) {
533
-                if ($var[0] == $field) {
532
+            if (count($var)>1) {
533
+                if ($var[0]==$field) {
534 534
                     $ele_value = $var[1];
535 535
                     if (isset($var[2])) {
536 536
                         $operator = $var[2];
537 537
                     }
538
-                } elseif (1 != $var[0]) {
538
+                } elseif (1!=$var[0]) {
539 539
                     $ret[] = implode(',', $var);
540 540
                 }
541 541
             }
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
         $pagenav['limit'] = Request::getInt('limit', 30, 'REQUEST');
547 547
         $pagenav['start'] = 0;
548 548
         $pagenav['order'] = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC';
549
-        $pagenav['sort']  = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : $sort;
549
+        $pagenav['sort']  = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : $sort;
550 550
         $retb             = [];
551 551
         foreach ($pagenav as $key => $value) {
552 552
             $retb[] = "$key=$value";
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
     public static function obj2array($objects): array
563 563
     {
564 564
         $ret = [];
565
-        foreach ((array)$objects as $key => $value) {
565
+        foreach ((array) $objects as $key => $value) {
566 566
             if (is_a($value, 'stdClass')) {
567 567
                 $ret[$key] = static::obj2array($value);
568 568
             } elseif (is_array($value)) {
@@ -589,8 +589,8 @@  discard block
 block discarded – undo
589 589
         $GLOBALS['songlistModuleConfig'] = $configHandler->getConfigList($GLOBALS['songlistModule']->getVar('mid'));
590 590
 
591 591
         if (!empty($GLOBALS['songlistModuleConfig']['bitly_username']) && !empty($GLOBALS['songlistModuleConfig']['bitly_apikey'])) {
592
-            $source_url = $GLOBALS['songlistModuleConfig']['bitly_apiurl'] . '/shorten?login=' . $GLOBALS['songlistModuleConfig']['bitly_username'] . '&apiKey=' . $GLOBALS['songlistModuleConfig']['bitly_apikey'] . '&format=json&longUrl=' . urlencode($url);
593
-            $cookies    = XOOPS_ROOT_PATH . '/uploads/songlist_' . md5($GLOBALS['songlistModuleConfig']['bitly_apikey']) . '.cookie';
592
+            $source_url = $GLOBALS['songlistModuleConfig']['bitly_apiurl'].'/shorten?login='.$GLOBALS['songlistModuleConfig']['bitly_username'].'&apiKey='.$GLOBALS['songlistModuleConfig']['bitly_apikey'].'&format=json&longUrl='.urlencode($url);
593
+            $cookies    = XOOPS_ROOT_PATH.'/uploads/songlist_'.md5($GLOBALS['songlistModuleConfig']['bitly_apikey']).'.cookie';
594 594
             if (!$ch = curl_init($source_url)) {
595 595
                 return $url;
596 596
             }
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
             $attributes_data = [];
667 667
 
668 668
             if (isset($value)) {
669
-                if ('tag' === $priority) {
669
+                if ('tag'===$priority) {
670 670
                     $result = $value;
671 671
                 } else {
672 672
                     $result['value'] = $value;
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
             //Set the attributes too.
677 677
             if (isset($attributes) and $get_attributes) {
678 678
                 foreach ($attributes as $attr => $val) {
679
-                    if ('tag' === $priority) {
679
+                    if ('tag'===$priority) {
680 680
                         $attributes_data[$attr] = $val;
681 681
                     } else {
682 682
                         $result['attr'][$attr] = $val;
@@ -685,67 +685,67 @@  discard block
 block discarded – undo
685 685
             }
686 686
 
687 687
             //See tag status and do the needed.
688
-            if ('open' === $type) {//The starting of the tag '<tag>'
689
-                $parent[$level - 1] = &$current;
688
+            if ('open'===$type) {//The starting of the tag '<tag>'
689
+                $parent[$level-1] = &$current;
690 690
                 if (!is_array($current) or (!array_key_exists($tag, $current))) { //Insert New tag
691 691
                     $current[$tag] = $result;
692 692
                     if ($attributes_data) {
693
-                        $current[$tag . '_attr'] = $attributes_data;
693
+                        $current[$tag.'_attr'] = $attributes_data;
694 694
                     }
695
-                    $repeated_tag_index[$tag . '_' . $level] = 1;
695
+                    $repeated_tag_index[$tag.'_'.$level] = 1;
696 696
 
697 697
                     $current = &$current[$tag];
698 698
                 } else { //There was another element with the same tag name
699 699
                     if (isset($current[$tag][0])) {//If there is a 0th element it is already an array
700
-                        $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
701
-                        $repeated_tag_index[$tag . '_' . $level]++;
700
+                        $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
701
+                        $repeated_tag_index[$tag.'_'.$level]++;
702 702
                     } else {//This section will make the value an array if multiple tags with the same name appear together
703 703
                         $current[$tag]                           = [$current[$tag], $result]; //This will combine the existing item and the new item together to make an array
704
-                        $repeated_tag_index[$tag . '_' . $level] = 2;
704
+                        $repeated_tag_index[$tag.'_'.$level] = 2;
705 705
 
706
-                        if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well
707
-                            $current[$tag]['0_attr'] = $current[$tag . '_attr'];
708
-                            unset($current[$tag . '_attr']);
706
+                        if (isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
707
+                            $current[$tag]['0_attr'] = $current[$tag.'_attr'];
708
+                            unset($current[$tag.'_attr']);
709 709
                         }
710 710
                     }
711
-                    $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
711
+                    $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
712 712
                     $current         = &$current[$tag][$last_item_index];
713 713
                 }
714
-            } elseif ('complete' === $type) { //Tags that ends in 1 line '<tag>'
714
+            } elseif ('complete'===$type) { //Tags that ends in 1 line '<tag>'
715 715
                 //See if the key is already taken.
716 716
                 if (isset($current[$tag])) { //If taken, put all things inside a list(array)
717 717
                     if (isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array...
718 718
                         // ...push the new element into that array.
719
-                        $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
719
+                        $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
720 720
 
721
-                        if ('tag' === $priority and $get_attributes and $attributes_data) {
722
-                            $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
721
+                        if ('tag'===$priority and $get_attributes and $attributes_data) {
722
+                            $current[$tag][$repeated_tag_index[$tag.'_'.$level].'_attr'] = $attributes_data;
723 723
                         }
724
-                        $repeated_tag_index[$tag . '_' . $level]++;
724
+                        $repeated_tag_index[$tag.'_'.$level]++;
725 725
                     } else { //If it is not an array...
726 726
                         $current[$tag]                           = [$current[$tag], $result]; //...Make it an array using using the existing value and the new value
727
-                        $repeated_tag_index[$tag . '_' . $level] = 1;
728
-                        if ('tag' === $priority and $get_attributes) {
729
-                            if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well
730
-                                $current[$tag]['0_attr'] = $current[$tag . '_attr'];
731
-                                unset($current[$tag . '_attr']);
727
+                        $repeated_tag_index[$tag.'_'.$level] = 1;
728
+                        if ('tag'===$priority and $get_attributes) {
729
+                            if (isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
730
+                                $current[$tag]['0_attr'] = $current[$tag.'_attr'];
731
+                                unset($current[$tag.'_attr']);
732 732
                             }
733 733
 
734 734
                             if ($attributes_data) {
735
-                                $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
735
+                                $current[$tag][$repeated_tag_index[$tag.'_'.$level].'_attr'] = $attributes_data;
736 736
                             }
737 737
                         }
738
-                        $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
738
+                        $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken
739 739
                     }
740 740
                 } else { //New Key
741 741
                     $current[$tag]                           = $result;
742
-                    $repeated_tag_index[$tag . '_' . $level] = 1;
743
-                    if ('tag' === $priority and $attributes_data) {
744
-                        $current[$tag . '_attr'] = $attributes_data;
742
+                    $repeated_tag_index[$tag.'_'.$level] = 1;
743
+                    if ('tag'===$priority and $attributes_data) {
744
+                        $current[$tag.'_attr'] = $attributes_data;
745 745
                     }
746 746
                 }
747
-            } elseif ('close' === $type) { //End of tag '</tag>'
748
-                $current = &$parent[$level - 1];
747
+            } elseif ('close'===$type) { //End of tag '</tag>'
748
+                $current = &$parent[$level-1];
749 749
             }
750 750
         }
751 751
 
@@ -765,10 +765,10 @@  discard block
 block discarded – undo
765 765
         $output = '';
766 766
         if ($beginning) {
767 767
             if ($standalone) {
768
-                header('content-type:text/xml;charset=' . _CHARSET);
768
+                header('content-type:text/xml;charset='._CHARSET);
769 769
             }
770
-            $output .= '<' . '?' . 'xml version="1.0" encoding="' . _CHARSET . '"' . '?' . '>' . "\n";
771
-            $output .= '<' . $name . '>' . "\n";
770
+            $output .= '<'.'?'.'xml version="1.0" encoding="'._CHARSET.'"'.'?'.'>'."\n";
771
+            $output .= '<'.$name.'>'."\n";
772 772
             $nested = 0;
773 773
         }
774 774
 
@@ -776,26 +776,26 @@  discard block
 block discarded – undo
776 776
             foreach ($array as $key => $value) {
777 777
                 ++$nested;
778 778
                 if (is_array($value)) {
779
-                    $output .= str_repeat("\t", (int)$nested) . '<' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n";
779
+                    $output .= str_repeat("\t", (int) $nested).'<'.(is_string($key) ? $key : $name.'_'.$key).'>'."\n";
780 780
                     ++$nested;
781 781
                     $output .= static::toXml($value, $name, false, false, $nested);
782 782
                     $nested--;
783
-                    $output .= str_repeat("\t", (int)$nested) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n";
784
-                } elseif ('' != $value) {
783
+                    $output .= str_repeat("\t", (int) $nested).'</'.(is_string($key) ? $key : $name.'_'.$key).'>'."\n";
784
+                } elseif (''!=$value) {
785 785
                     ++$nested;
786
-                    $output .= str_repeat("\t", (int)$nested) . '  <' . (is_string($key) ? $key : $name . '_' . $key) . '>' . trim($value) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n";
786
+                    $output .= str_repeat("\t", (int) $nested).'  <'.(is_string($key) ? $key : $name.'_'.$key).'>'.trim($value).'</'.(is_string($key) ? $key : $name.'_'.$key).'>'."\n";
787 787
                     $nested--;
788 788
                 }
789 789
                 $nested--;
790 790
             }
791
-        } elseif ('' != $array) {
791
+        } elseif (''!=$array) {
792 792
             ++$nested;
793
-            $output .= str_repeat("\t", (int)$nested) . trim($array) . "\n";
793
+            $output .= str_repeat("\t", (int) $nested).trim($array)."\n";
794 794
             $nested--;
795 795
         }
796 796
 
797 797
         if ($beginning) {
798
-            $output .= '</' . $name . '>';
798
+            $output .= '</'.$name.'>';
799 799
 
800 800
             return $output;
801 801
         }
Please login to merge, or discard this patch.
class/GenreHandler.php 2 patches
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -11,121 +11,121 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class GenreHandler extends \XoopsPersistableObjectHandler
13 13
 {
14
-    /**
15
-     * GenreHandler constructor.
16
-     * @param \XoopsDatabase $db
17
-     */
18
-    public function __construct(\XoopsDatabase $db)
19
-    {
20
-        parent::__construct($db, 'songlist_genre', Genre::class, 'gid', 'name');
21
-    }
22
-
23
-    /**
24
-     * @return array
25
-     */
26
-    public function filterFields(): array
27
-    {
28
-        return ['gid', 'name', 'artists', 'albums', 'songs', 'hits', 'rank', 'votes', 'created', 'updated'];
29
-    }
30
-
31
-    /**
32
-     * @param $filter
33
-     * @return \CriteriaCompo
34
-     */
35
-    public function getFilterCriteria($filter): \CriteriaCompo
36
-    {
37
-        $parts    = \explode('|', $filter);
38
-        $criteria = new \CriteriaCompo();
39
-        foreach ($parts as $part) {
40
-            $var = \explode(',', $part);
41
-            if (!empty($var[1]) && !\is_numeric($var[0])) {
42
-                $object = $this->create();
43
-                if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
44
-                    || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
45
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
46
-                } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
47
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
48
-                } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
49
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
50
-                } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
51
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
52
-                }
53
-            } elseif (!empty($var[1]) && \is_numeric($var[0])) {
54
-                $criteria->add(new \Criteria($var[0], $var[1]));
55
-            }
56
-        }
57
-
58
-        return $criteria;
59
-    }
60
-
61
-    /**
62
-     * @param        $filter
63
-     * @param        $field
64
-     * @param string $sort
65
-     * @param string $op
66
-     * @param string $fct
67
-     * @return string
68
-     */
69
-    public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string
70
-    {
71
-        $ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct);
72
-        if (\is_object($ele)) {
73
-            return $ele->render();
74
-        }
75
-
76
-        return '&nbsp;';
77
-    }
78
-
79
-    /**
80
-     * @param bool $force
81
-     * @return bool|mixed
82
-     */
83
-    public function insert(\XoopsObject $obj, $force = true)
84
-    {
85
-        if ($obj->isNew()) {
86
-            $obj->setVar('created', \time());
87
-        } else {
88
-            $obj->setVar('updated', \time());
89
-        }
90
-        if ('' == $obj->getVar('name')) {
91
-            return false;
92
-        }
93
-
94
-        return parent::insert($obj, $force);
95
-    }
96
-
97
-    public $_objects = ['object' => [], 'array' => []];
98
-
99
-    /**
100
-     * @param null $id
101
-     * @param null $fields
102
-     * @return \XoopsObject
103
-     */
104
-    public function get($id = null, $fields = null): \XoopsObject//get($id, $fields = '*')
105
-    {
106
-        $fields = $fields ?: '*';
107
-        if (!isset($this->_objects['object'][$id])) {
108
-            $this->_objects['object'][$id] = parent::get($id, $fields);
109
-            if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
110
-                $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
111
-                $GLOBALS['xoopsDB']->queryF($sql);
112
-            }
113
-        }
114
-
115
-        return $this->_objects['object'][$id];
116
-    }
117
-
118
-    /**
119
-     * @param \CriteriaElement|\CriteriaCompo $criteria
120
-     * @param bool $id_as_key
121
-     * @param bool $as_object
122
-     * @return array
123
-     */
124
-    public function &getObjects($criteria = null, $id_as_key = false, $as_object = true): array
125
-    {
126
-        $ret = parent::getObjects($criteria, $id_as_key, $as_object);
127
-
128
-        /*if (!isset($GLOBALS['songlistAdmin'])) {
14
+	/**
15
+	 * GenreHandler constructor.
16
+	 * @param \XoopsDatabase $db
17
+	 */
18
+	public function __construct(\XoopsDatabase $db)
19
+	{
20
+		parent::__construct($db, 'songlist_genre', Genre::class, 'gid', 'name');
21
+	}
22
+
23
+	/**
24
+	 * @return array
25
+	 */
26
+	public function filterFields(): array
27
+	{
28
+		return ['gid', 'name', 'artists', 'albums', 'songs', 'hits', 'rank', 'votes', 'created', 'updated'];
29
+	}
30
+
31
+	/**
32
+	 * @param $filter
33
+	 * @return \CriteriaCompo
34
+	 */
35
+	public function getFilterCriteria($filter): \CriteriaCompo
36
+	{
37
+		$parts    = \explode('|', $filter);
38
+		$criteria = new \CriteriaCompo();
39
+		foreach ($parts as $part) {
40
+			$var = \explode(',', $part);
41
+			if (!empty($var[1]) && !\is_numeric($var[0])) {
42
+				$object = $this->create();
43
+				if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
44
+					|| \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
45
+					$criteria->add(new \Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
46
+				} elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
47
+					$criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
48
+				} elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
49
+					$criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
50
+				} elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
51
+					$criteria->add(new \Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
52
+				}
53
+			} elseif (!empty($var[1]) && \is_numeric($var[0])) {
54
+				$criteria->add(new \Criteria($var[0], $var[1]));
55
+			}
56
+		}
57
+
58
+		return $criteria;
59
+	}
60
+
61
+	/**
62
+	 * @param        $filter
63
+	 * @param        $field
64
+	 * @param string $sort
65
+	 * @param string $op
66
+	 * @param string $fct
67
+	 * @return string
68
+	 */
69
+	public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string
70
+	{
71
+		$ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct);
72
+		if (\is_object($ele)) {
73
+			return $ele->render();
74
+		}
75
+
76
+		return '&nbsp;';
77
+	}
78
+
79
+	/**
80
+	 * @param bool $force
81
+	 * @return bool|mixed
82
+	 */
83
+	public function insert(\XoopsObject $obj, $force = true)
84
+	{
85
+		if ($obj->isNew()) {
86
+			$obj->setVar('created', \time());
87
+		} else {
88
+			$obj->setVar('updated', \time());
89
+		}
90
+		if ('' == $obj->getVar('name')) {
91
+			return false;
92
+		}
93
+
94
+		return parent::insert($obj, $force);
95
+	}
96
+
97
+	public $_objects = ['object' => [], 'array' => []];
98
+
99
+	/**
100
+	 * @param null $id
101
+	 * @param null $fields
102
+	 * @return \XoopsObject
103
+	 */
104
+	public function get($id = null, $fields = null): \XoopsObject//get($id, $fields = '*')
105
+	{
106
+		$fields = $fields ?: '*';
107
+		if (!isset($this->_objects['object'][$id])) {
108
+			$this->_objects['object'][$id] = parent::get($id, $fields);
109
+			if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
110
+				$sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
111
+				$GLOBALS['xoopsDB']->queryF($sql);
112
+			}
113
+		}
114
+
115
+		return $this->_objects['object'][$id];
116
+	}
117
+
118
+	/**
119
+	 * @param \CriteriaElement|\CriteriaCompo $criteria
120
+	 * @param bool $id_as_key
121
+	 * @param bool $as_object
122
+	 * @return array
123
+	 */
124
+	public function &getObjects($criteria = null, $id_as_key = false, $as_object = true): array
125
+	{
126
+		$ret = parent::getObjects($criteria, $id_as_key, $as_object);
127
+
128
+		/*if (!isset($GLOBALS['songlistAdmin'])) {
129 129
             $id = [];
130 130
             foreach($ret as $data) {
131 131
                 if ($as_object==true) {
@@ -146,51 +146,51 @@  discard block
 block discarded – undo
146 146
             $GLOBALS['xoopsDB']->queryF($sql);
147 147
         }*/
148 148
 
149
-        return $ret;
150
-    }
151
-
152
-    /**
153
-     * @return string
154
-     */
155
-    public function getURL(): string
156
-    {
157
-        global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit;
158
-        if ($GLOBALS['songlistModuleConfig']['htaccess']) {
159
-            return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseurl'] . '/' . $file . '/' . $start . '-' . $op . '-' . $fct . '-' . $id . '-' . \urlencode($value) . '-' . $gid . '-' . $cid . $GLOBALS['songlistModuleConfig']['endofurl'];
160
-        }
161
-
162
-        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&cid=' . $cid . '&start=' . $start;
163
-    }
164
-
165
-    /**
166
-     * @param int $limit
167
-     * @return array
168
-     */
169
-    public function getTop($limit = 1): array
170
-    {
171
-        $sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
172
-        $results = $GLOBALS['xoopsDB']->queryF($sql);
173
-        $ret     = [];
174
-        $i       = 0;
175
-        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
176
-            $ret[$i] = $this->create();
177
-            $ret[$i]->assignVars($row);
178
-            ++$i;
179
-        }
180
-
181
-        return $ret;
182
-    }
183
-
184
-    /**
185
-     * @param \XoopsObject $object
186
-     * @param bool         $force
187
-     * @return bool
188
-     */
189
-    public function delete(\XoopsObject $object, $force = true): bool
190
-    {
191
-        parent::delete($object, $force);
192
-        $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . ' SET `gid` = 0 WHERE `gid` = ' . $object->getVar('gid');
193
-
194
-        return $GLOBALS['xoopsDB']->queryF($sql);
195
-    }
149
+		return $ret;
150
+	}
151
+
152
+	/**
153
+	 * @return string
154
+	 */
155
+	public function getURL(): string
156
+	{
157
+		global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit;
158
+		if ($GLOBALS['songlistModuleConfig']['htaccess']) {
159
+			return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseurl'] . '/' . $file . '/' . $start . '-' . $op . '-' . $fct . '-' . $id . '-' . \urlencode($value) . '-' . $gid . '-' . $cid . $GLOBALS['songlistModuleConfig']['endofurl'];
160
+		}
161
+
162
+		return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&cid=' . $cid . '&start=' . $start;
163
+	}
164
+
165
+	/**
166
+	 * @param int $limit
167
+	 * @return array
168
+	 */
169
+	public function getTop($limit = 1): array
170
+	{
171
+		$sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
172
+		$results = $GLOBALS['xoopsDB']->queryF($sql);
173
+		$ret     = [];
174
+		$i       = 0;
175
+		while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
176
+			$ret[$i] = $this->create();
177
+			$ret[$i]->assignVars($row);
178
+			++$i;
179
+		}
180
+
181
+		return $ret;
182
+	}
183
+
184
+	/**
185
+	 * @param \XoopsObject $object
186
+	 * @param bool         $force
187
+	 * @return bool
188
+	 */
189
+	public function delete(\XoopsObject $object, $force = true): bool
190
+	{
191
+		parent::delete($object, $force);
192
+		$sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . ' SET `gid` = 0 WHERE `gid` = ' . $object->getVar('gid');
193
+
194
+		return $GLOBALS['xoopsDB']->queryF($sql);
195
+	}
196 196
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 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
 
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
             $var = \explode(',', $part);
41 41
             if (!empty($var[1]) && !\is_numeric($var[0])) {
42 42
                 $object = $this->create();
43
-                if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
44
-                    || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
45
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
43
+                if (\XOBJ_DTYPE_TXTBOX==$object->vars[$var[0]]['data_type']
44
+                    || \XOBJ_DTYPE_TXTAREA==$object->vars[$var[0]]['data_type']) {
45
+                    $criteria->add(new \Criteria('`'.$var[0].'`', '%'.$var[1].'%', ($var[2] ?? 'LIKE')));
46 46
                 } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
47
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
48
-                } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
49
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
50
-                } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
51
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
47
+                    $criteria->add(new \Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '=')));
48
+                } elseif (\XOBJ_DTYPE_ENUM==$object->vars[$var[0]]['data_type']) {
49
+                    $criteria->add(new \Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '=')));
50
+                } elseif (\XOBJ_DTYPE_ARRAY==$object->vars[$var[0]]['data_type']) {
51
+                    $criteria->add(new \Criteria('`'.$var[0].'`', '%"'.$var[1].'";%', ($var[2] ?? 'LIKE')));
52 52
                 }
53 53
             } elseif (!empty($var[1]) && \is_numeric($var[0])) {
54 54
                 $criteria->add(new \Criteria($var[0], $var[1]));
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         } else {
88 88
             $obj->setVar('updated', \time());
89 89
         }
90
-        if ('' == $obj->getVar('name')) {
90
+        if (''==$obj->getVar('name')) {
91 91
             return false;
92 92
         }
93 93
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         if (!isset($this->_objects['object'][$id])) {
108 108
             $this->_objects['object'][$id] = parent::get($id, $fields);
109 109
             if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
110
-                $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
110
+                $sql = 'UPDATE `'.$this->table.'` set hits=hits+1 where `'.$this->keyName.'` = '.$this->_objects['object'][$id]->getVar($this->keyName);
111 111
                 $GLOBALS['xoopsDB']->queryF($sql);
112 112
             }
113 113
         }
@@ -156,10 +156,10 @@  discard block
 block discarded – undo
156 156
     {
157 157
         global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit;
158 158
         if ($GLOBALS['songlistModuleConfig']['htaccess']) {
159
-            return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseurl'] . '/' . $file . '/' . $start . '-' . $op . '-' . $fct . '-' . $id . '-' . \urlencode($value) . '-' . $gid . '-' . $cid . $GLOBALS['songlistModuleConfig']['endofurl'];
159
+            return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseurl'].'/'.$file.'/'.$start.'-'.$op.'-'.$fct.'-'.$id.'-'.\urlencode($value).'-'.$gid.'-'.$cid.$GLOBALS['songlistModuleConfig']['endofurl'];
160 160
         }
161 161
 
162
-        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&cid=' . $cid . '&start=' . $start;
162
+        return XOOPS_URL.'/modules/songlist/'.$file.'.php?op='.$op.'&fct='.$fct.'&id='.$id.'&value='.\urlencode($value ?? '').'&gid='.$gid.'&cid='.$cid.'&start='.$start;
163 163
     }
164 164
 
165 165
     /**
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public function getTop($limit = 1): array
170 170
     {
171
-        $sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
171
+        $sql     = 'SELECT * FROM `'.$this->table.'` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT '.$limit;
172 172
         $results = $GLOBALS['xoopsDB']->queryF($sql);
173 173
         $ret     = [];
174 174
         $i       = 0;
175
-        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
175
+        while (false!==($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
176 176
             $ret[$i] = $this->create();
177 177
             $ret[$i]->assignVars($row);
178 178
             ++$i;
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     public function delete(\XoopsObject $object, $force = true): bool
190 190
     {
191 191
         parent::delete($object, $force);
192
-        $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . ' SET `gid` = 0 WHERE `gid` = ' . $object->getVar('gid');
192
+        $sql = 'UPDATE '.$GLOBALS['xoopsDB']->prefix('songlist_songs').' SET `gid` = 0 WHERE `gid` = '.$object->getVar('gid');
193 193
 
194 194
         return $GLOBALS['xoopsDB']->queryF($sql);
195 195
     }
Please login to merge, or discard this patch.
class/Uploader.php 2 patches
Indentation   +381 added lines, -381 removed lines patch added patch discarded remove patch
@@ -11,39 +11,39 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class Uploader
13 13
 {
14
-    public $mediaName;
15
-    public $mediaType;
16
-    public $mediaSize;
17
-    public $mediaTmpName;
18
-    public $mediaError;
19
-    public $uploadDir         = '';
20
-    public $allowedMimeTypes  = [];
21
-    public $allowedExtensions = [];
22
-    public $maxFileSize       = 3299999999;
23
-    public $maxWidth;
24
-    public $maxHeight;
25
-    public $targetFileName;
26
-    public $prefix;
27
-    public $errors            = [];
28
-    public $savedDestination;
29
-    public $savedFileName;
30
-
31
-    /**
32
-     * Constructor
33
-     *
34
-     * @param string $uploadDir
35
-     * @param array  $allowedMimeTypes
36
-     * @param int    $maxFileSize
37
-     * @param int    $maxWidth
38
-     * @param int    $maxHeight
39
-     * @param array  $allowedExtensions
40
-     * @internal param int $cmodvalue
41
-     */
42
-    public function __construct($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth = null, $maxHeight = null, $allowedExtensions = null)
43
-    {
44
-        if (\is_array($allowedMimeTypes)) {
45
-            $this->allowedMimeTypes = &$allowedMimeTypes;
46
-        }
14
+	public $mediaName;
15
+	public $mediaType;
16
+	public $mediaSize;
17
+	public $mediaTmpName;
18
+	public $mediaError;
19
+	public $uploadDir         = '';
20
+	public $allowedMimeTypes  = [];
21
+	public $allowedExtensions = [];
22
+	public $maxFileSize       = 3299999999;
23
+	public $maxWidth;
24
+	public $maxHeight;
25
+	public $targetFileName;
26
+	public $prefix;
27
+	public $errors            = [];
28
+	public $savedDestination;
29
+	public $savedFileName;
30
+
31
+	/**
32
+	 * Constructor
33
+	 *
34
+	 * @param string $uploadDir
35
+	 * @param array  $allowedMimeTypes
36
+	 * @param int    $maxFileSize
37
+	 * @param int    $maxWidth
38
+	 * @param int    $maxHeight
39
+	 * @param array  $allowedExtensions
40
+	 * @internal param int $cmodvalue
41
+	 */
42
+	public function __construct($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth = null, $maxHeight = null, $allowedExtensions = null)
43
+	{
44
+		if (\is_array($allowedMimeTypes)) {
45
+			$this->allowedMimeTypes = &$allowedMimeTypes;
46
+		}
47 47
 //        $this->uploadDir = $uploadDir . (DS != mb_substr($uploadDir, mb_strlen($uploadDir) - 1, 1) ? DS : '');
48 48
 //        if (\is_dir($uploadDir)) {
49 49
 //            foreach (\explode(DS, $uploadDir) as $folder) {
@@ -53,352 +53,352 @@  discard block
 block discarded – undo
53 53
 //                }
54 54
 //            }
55 55
 //        }
56
-        $this->uploadDir = $uploadDir;
57
-        $this->maxFileSize = (int)$maxFileSize;
58
-        if (isset($maxWidth)) {
59
-            $this->maxWidth = (int)$maxWidth;
60
-        }
61
-        if (isset($maxHeight)) {
62
-            $this->maxHeight = (int)$maxHeight;
63
-        }
64
-        if (isset($allowedExtensions) && \is_array($allowedExtensions)) {
65
-            $this->allowedExtensions = &$allowedExtensions;
66
-        }
67
-    }
68
-
69
-    /**
70
-     * Fetch the uploaded file
71
-     *
72
-     * @param       $index_name
73
-     * @param int   $index Index of the file (if more than one uploaded under that name)
74
-     * @return bool
75
-     * @internal param string $media_name Name of the file field
76
-     */
77
-    public function fetchMedia($index_name, $index = null): bool
78
-    {
79
-        if (!isset($_FILES[$index_name])) {
80
-            $this->setErrors('File not found');
81
-
82
-            return false;
83
-        }
84
-
85
-        if (\is_array($_FILES[$index_name]['name'][$index]) && isset($index)) {
86
-            $this->mediaName    = $_FILES[$index_name]['name'][$index];
87
-            $this->mediaType    = $_FILES[$index_name]['type'][$index];
88
-            $this->mediaSize    = $_FILES[$index_name]['size'][$index];
89
-            $this->mediaTmpName = $_FILES[$index_name]['tmp_name'][$index];
90
-            $this->mediaError   = !empty($_FILES[$index_name]['error'][$index]) ? $_FILES[$index_name]['errir'][$index] : 0;
91
-        } else {
92
-            $this->mediaName    = $_FILES[$index_name]['name'];
93
-            $this->mediaType    = $_FILES[$index_name]['type'];
94
-            $this->mediaSize    = $_FILES[$index_name]['size'];
95
-            $this->mediaTmpName = $_FILES[$index_name]['tmp_name'];
96
-            $this->mediaError   = !empty($_FILES[$index_name]['error']) ? $_FILES[$index_name]['error'] : 0;
97
-        }
98
-        $this->errors = [];
99
-        if ((int)$this->mediaSize < 0) {
100
-            $this->setErrors('Invalid File Size');
101
-
102
-            return false;
103
-        }
104
-        if ('' == $this->mediaName) {
105
-            $this->setErrors('Filename Is Empty');
106
-
107
-            return false;
108
-        }
109
-        if ('none' === $this->mediaTmpName || !\is_uploaded_file($this->mediaTmpName) || 0 == $this->mediaSize) {
110
-            $this->setErrors('No file uploaded');
111
-
112
-            return false;
113
-        }
114
-        if ($this->mediaError > 0) {
115
-            $this->setErrors('Error occurred: Error #' . $this->mediaError);
116
-
117
-            return false;
118
-        }
119
-
120
-        return true;
121
-    }
122
-
123
-    /**
124
-     * Set the target filename
125
-     *
126
-     * @param string $value
127
-     **/
128
-    public function setTargetFileName(string $value): void
129
-    {
130
-        $this->targetFileName = \trim($value);
131
-    }
132
-
133
-    /**
134
-     * Set the prefix
135
-     *
136
-     * @param string $value
137
-     **/
138
-    public function setPrefix($value): void
139
-    {
140
-        $this->prefix = \trim($value);
141
-    }
142
-
143
-    /**
144
-     * Get the uploaded filename
145
-     *
146
-     * @return  string
147
-     **/
148
-    public function getMediaName(): string
149
-    {
150
-        return $this->mediaName;
151
-    }
152
-
153
-    /**
154
-     * Get the type of the uploaded file
155
-     *
156
-     * @return  string
157
-     **/
158
-    public function getMediaType(): string
159
-    {
160
-        return $this->mediaType;
161
-    }
162
-
163
-    /**
164
-     * Get the size of the uploaded file
165
-     *
166
-     * @return  int
167
-     **/
168
-    public function getMediaSize(): int
169
-    {
170
-        return $this->mediaSize;
171
-    }
172
-
173
-    /**
174
-     * Get the temporary name that the uploaded file was stored under
175
-     *
176
-     * @return  string
177
-     **/
178
-    public function getMediaTmpName(): string
179
-    {
180
-        return $this->mediaTmpName;
181
-    }
182
-
183
-    /**
184
-     * Get the saved filename
185
-     *
186
-     * @return  string
187
-     **/
188
-    public function getSavedFileName(): string
189
-    {
190
-        return $this->savedFileName;
191
-    }
192
-
193
-    /**
194
-     * Get the destination the file is saved to
195
-     *
196
-     * @return  string
197
-     **/
198
-    public function getSavedDestination(): string
199
-    {
200
-        return $this->savedDestination;
201
-    }
202
-
203
-    /**
204
-     * Check the file and copy it to the destination
205
-     *
206
-     * @param int $chmod
207
-     * @return bool
208
-     */
209
-    public function upload($chmod = 0644): bool
210
-    {
211
-        if ('' == $this->uploadDir) {
212
-            $this->setErrors('Upload directory not set');
213
-
214
-            return false;
215
-        }
216
-        if (!\is_dir($this->uploadDir)) {
217
-            $this->setErrors('Failed opening directory: ' . $this->uploadDir);
218
-
219
-            return false;
220
-        }
221
-        if (!\is_writable($this->uploadDir)) {
222
-            $this->setErrors('Failed opening directory with write permission: ' . $this->uploadDir);
223
-
224
-            return false;
225
-        }
226
-        if (!$this->checkMimeType()) {
227
-            $this->setErrors('MIME type not allowed: ' . $this->mediaType);
228
-
229
-            return false;
230
-        }
231
-        if (!$this->checkExtension()) {
232
-            $this->setErrors('Extension not allowed');
233
-
234
-            return false;
235
-        }
236
-        if (!$this->checkMaxFileSize()) {
237
-            $this->setErrors('File size too large: ' . $this->mediaSize);
238
-        }
239
-        if (!$this->checkMaxWidth()) {
240
-            $this->setErrors(\sprintf('File width must be smaller than %u', $this->maxWidth));
241
-        }
242
-        if (!$this->checkMaxHeight()) {
243
-            $this->setErrors(\sprintf('File height must be smaller than %u', $this->maxHeight));
244
-        }
245
-        if (\count($this->errors) > 0) {
246
-            return false;
247
-        }
248
-        if (!$this->_copyFile($chmod)) {
249
-            $this->setErrors('Failed uploading file: ' . $this->mediaName);
250
-
251
-            return false;
252
-        }
253
-
254
-        return true;
255
-    }
256
-
257
-    /**
258
-     * Copy the file to its destination
259
-     *
260
-     * @param $chmod
261
-     * @return bool
262
-     */
263
-    public function _copyFile($chmod): bool
264
-    {
265
-        $matched = [];
266
-        if (!\preg_match('/\.([a-zA-Z0-9]+)$/', $this->mediaName, $matched)) {
267
-            return false;
268
-        }
269
-        if (isset($this->targetFileName)) {
270
-            $this->savedFileName = $this->targetFileName;
271
-        } elseif (isset($this->prefix)) {
272
-            $this->savedFileName = \uniqid($this->prefix, true) . '.' . \mb_strtolower($matched[1]);
273
-        } else {
274
-            $this->savedFileName = \mb_strtolower($this->mediaName);
275
-        }
276
-        $this->savedDestination = $this->uploadDir . '/' . $this->savedFileName;
277
-        if (!\move_uploaded_file($this->mediaTmpName, $this->savedDestination)) {
278
-            return false;
279
-        }
280
-        @\chmod($this->savedDestination, $chmod);
281
-
282
-        return true;
283
-    }
284
-
285
-    /**
286
-     * Is the file the right size?
287
-     *
288
-     * @return  bool
289
-     **/
290
-    public function checkMaxFileSize(): bool
291
-    {
292
-        if ($this->mediaSize > $this->maxFileSize) {
293
-            return false;
294
-        }
295
-
296
-        return true;
297
-    }
298
-
299
-    /**
300
-     * Is the picture the right width?
301
-     *
302
-     * @return  bool
303
-     **/
304
-    public function checkMaxWidth(): bool
305
-    {
306
-        if (!isset($this->maxWidth) || $this->maxWidth < 1) {
307
-            return true;
308
-        }
309
-        if (false !== $dimension = \getimagesize($this->mediaTmpName)) {
310
-            if ($dimension[0] > $this->maxWidth) {
311
-                return false;
312
-            }
313
-        } else {
314
-            \trigger_error(\sprintf('Failed fetching image size of %s, skipping max width check..', $this->mediaTmpName), \E_USER_WARNING);
315
-        }
316
-
317
-        return true;
318
-    }
319
-
320
-    /**
321
-     * Is the picture the right height?
322
-     *
323
-     * @return  bool
324
-     **/
325
-    public function checkMaxHeight(): bool
326
-    {
327
-        if (!isset($this->maxHeight) || $this->maxHeight < 1) {
328
-            return true;
329
-        }
330
-        if (false !== $dimension = \getimagesize($this->mediaTmpName)) {
331
-            if ($dimension[1] > $this->maxHeight) {
332
-                return false;
333
-            }
334
-        } else {
335
-            \trigger_error(\sprintf('Failed fetching image size of %s, skipping max height check..', $this->mediaTmpName), \E_USER_WARNING);
336
-        }
337
-
338
-        return true;
339
-    }
340
-
341
-    /**
342
-     * Is the file the right Mime type
343
-     *
344
-     * (is there a right type of mime? ;-)
345
-     *
346
-     * @return  bool
347
-     **/
348
-    public function checkMimeType(): bool
349
-    {
350
-        if (\count($this->allowedMimeTypes) > 0 && !\in_array($this->mediaType, $this->allowedMimeTypes, true)) {
351
-            return false;
352
-        }
353
-
354
-        return true;
355
-    }
356
-
357
-    /**
358
-     * Is the file the right extension
359
-     *
360
-     * @return  bool
361
-     **/
362
-    public function checkExtension(): bool
363
-    {
364
-        $ext = mb_substr(mb_strrchr($this->mediaName, '.'), 1);
365
-        if (!empty($this->allowedExtensions) && !\in_array(mb_strtolower($ext), $this->allowedExtensions, true)) {
366
-            return false;
367
-        }
368
-
369
-        return true;
370
-    }
371
-
372
-    /**
373
-     * Add an error
374
-     *
375
-     * @param string $error
376
-     **/
377
-    public function setErrors($error): void
378
-    {
379
-        $this->errors[] = \trim($error);
380
-    }
381
-
382
-    /**
383
-     * Get generated errors
384
-     *
385
-     * @param bool $ashtml Format using HTML?
386
-     *
387
-     * @return  array|string    Array of array messages OR HTML string
388
-     */
389
-    public function &getErrors($ashtml = true)
390
-    {
391
-        if (!$ashtml) {
392
-            return $this->errors;
393
-        }
394
-        $ret = '';
395
-        if (\count($this->errors) > 0) {
396
-            $ret = '<h4>Errors Returned While Uploading</h4>';
397
-            foreach ($this->errors as $error) {
398
-                $ret .= $error . '<br>';
399
-            }
400
-        }
401
-
402
-        return $ret;
403
-    }
56
+		$this->uploadDir = $uploadDir;
57
+		$this->maxFileSize = (int)$maxFileSize;
58
+		if (isset($maxWidth)) {
59
+			$this->maxWidth = (int)$maxWidth;
60
+		}
61
+		if (isset($maxHeight)) {
62
+			$this->maxHeight = (int)$maxHeight;
63
+		}
64
+		if (isset($allowedExtensions) && \is_array($allowedExtensions)) {
65
+			$this->allowedExtensions = &$allowedExtensions;
66
+		}
67
+	}
68
+
69
+	/**
70
+	 * Fetch the uploaded file
71
+	 *
72
+	 * @param       $index_name
73
+	 * @param int   $index Index of the file (if more than one uploaded under that name)
74
+	 * @return bool
75
+	 * @internal param string $media_name Name of the file field
76
+	 */
77
+	public function fetchMedia($index_name, $index = null): bool
78
+	{
79
+		if (!isset($_FILES[$index_name])) {
80
+			$this->setErrors('File not found');
81
+
82
+			return false;
83
+		}
84
+
85
+		if (\is_array($_FILES[$index_name]['name'][$index]) && isset($index)) {
86
+			$this->mediaName    = $_FILES[$index_name]['name'][$index];
87
+			$this->mediaType    = $_FILES[$index_name]['type'][$index];
88
+			$this->mediaSize    = $_FILES[$index_name]['size'][$index];
89
+			$this->mediaTmpName = $_FILES[$index_name]['tmp_name'][$index];
90
+			$this->mediaError   = !empty($_FILES[$index_name]['error'][$index]) ? $_FILES[$index_name]['errir'][$index] : 0;
91
+		} else {
92
+			$this->mediaName    = $_FILES[$index_name]['name'];
93
+			$this->mediaType    = $_FILES[$index_name]['type'];
94
+			$this->mediaSize    = $_FILES[$index_name]['size'];
95
+			$this->mediaTmpName = $_FILES[$index_name]['tmp_name'];
96
+			$this->mediaError   = !empty($_FILES[$index_name]['error']) ? $_FILES[$index_name]['error'] : 0;
97
+		}
98
+		$this->errors = [];
99
+		if ((int)$this->mediaSize < 0) {
100
+			$this->setErrors('Invalid File Size');
101
+
102
+			return false;
103
+		}
104
+		if ('' == $this->mediaName) {
105
+			$this->setErrors('Filename Is Empty');
106
+
107
+			return false;
108
+		}
109
+		if ('none' === $this->mediaTmpName || !\is_uploaded_file($this->mediaTmpName) || 0 == $this->mediaSize) {
110
+			$this->setErrors('No file uploaded');
111
+
112
+			return false;
113
+		}
114
+		if ($this->mediaError > 0) {
115
+			$this->setErrors('Error occurred: Error #' . $this->mediaError);
116
+
117
+			return false;
118
+		}
119
+
120
+		return true;
121
+	}
122
+
123
+	/**
124
+	 * Set the target filename
125
+	 *
126
+	 * @param string $value
127
+	 **/
128
+	public function setTargetFileName(string $value): void
129
+	{
130
+		$this->targetFileName = \trim($value);
131
+	}
132
+
133
+	/**
134
+	 * Set the prefix
135
+	 *
136
+	 * @param string $value
137
+	 **/
138
+	public function setPrefix($value): void
139
+	{
140
+		$this->prefix = \trim($value);
141
+	}
142
+
143
+	/**
144
+	 * Get the uploaded filename
145
+	 *
146
+	 * @return  string
147
+	 **/
148
+	public function getMediaName(): string
149
+	{
150
+		return $this->mediaName;
151
+	}
152
+
153
+	/**
154
+	 * Get the type of the uploaded file
155
+	 *
156
+	 * @return  string
157
+	 **/
158
+	public function getMediaType(): string
159
+	{
160
+		return $this->mediaType;
161
+	}
162
+
163
+	/**
164
+	 * Get the size of the uploaded file
165
+	 *
166
+	 * @return  int
167
+	 **/
168
+	public function getMediaSize(): int
169
+	{
170
+		return $this->mediaSize;
171
+	}
172
+
173
+	/**
174
+	 * Get the temporary name that the uploaded file was stored under
175
+	 *
176
+	 * @return  string
177
+	 **/
178
+	public function getMediaTmpName(): string
179
+	{
180
+		return $this->mediaTmpName;
181
+	}
182
+
183
+	/**
184
+	 * Get the saved filename
185
+	 *
186
+	 * @return  string
187
+	 **/
188
+	public function getSavedFileName(): string
189
+	{
190
+		return $this->savedFileName;
191
+	}
192
+
193
+	/**
194
+	 * Get the destination the file is saved to
195
+	 *
196
+	 * @return  string
197
+	 **/
198
+	public function getSavedDestination(): string
199
+	{
200
+		return $this->savedDestination;
201
+	}
202
+
203
+	/**
204
+	 * Check the file and copy it to the destination
205
+	 *
206
+	 * @param int $chmod
207
+	 * @return bool
208
+	 */
209
+	public function upload($chmod = 0644): bool
210
+	{
211
+		if ('' == $this->uploadDir) {
212
+			$this->setErrors('Upload directory not set');
213
+
214
+			return false;
215
+		}
216
+		if (!\is_dir($this->uploadDir)) {
217
+			$this->setErrors('Failed opening directory: ' . $this->uploadDir);
218
+
219
+			return false;
220
+		}
221
+		if (!\is_writable($this->uploadDir)) {
222
+			$this->setErrors('Failed opening directory with write permission: ' . $this->uploadDir);
223
+
224
+			return false;
225
+		}
226
+		if (!$this->checkMimeType()) {
227
+			$this->setErrors('MIME type not allowed: ' . $this->mediaType);
228
+
229
+			return false;
230
+		}
231
+		if (!$this->checkExtension()) {
232
+			$this->setErrors('Extension not allowed');
233
+
234
+			return false;
235
+		}
236
+		if (!$this->checkMaxFileSize()) {
237
+			$this->setErrors('File size too large: ' . $this->mediaSize);
238
+		}
239
+		if (!$this->checkMaxWidth()) {
240
+			$this->setErrors(\sprintf('File width must be smaller than %u', $this->maxWidth));
241
+		}
242
+		if (!$this->checkMaxHeight()) {
243
+			$this->setErrors(\sprintf('File height must be smaller than %u', $this->maxHeight));
244
+		}
245
+		if (\count($this->errors) > 0) {
246
+			return false;
247
+		}
248
+		if (!$this->_copyFile($chmod)) {
249
+			$this->setErrors('Failed uploading file: ' . $this->mediaName);
250
+
251
+			return false;
252
+		}
253
+
254
+		return true;
255
+	}
256
+
257
+	/**
258
+	 * Copy the file to its destination
259
+	 *
260
+	 * @param $chmod
261
+	 * @return bool
262
+	 */
263
+	public function _copyFile($chmod): bool
264
+	{
265
+		$matched = [];
266
+		if (!\preg_match('/\.([a-zA-Z0-9]+)$/', $this->mediaName, $matched)) {
267
+			return false;
268
+		}
269
+		if (isset($this->targetFileName)) {
270
+			$this->savedFileName = $this->targetFileName;
271
+		} elseif (isset($this->prefix)) {
272
+			$this->savedFileName = \uniqid($this->prefix, true) . '.' . \mb_strtolower($matched[1]);
273
+		} else {
274
+			$this->savedFileName = \mb_strtolower($this->mediaName);
275
+		}
276
+		$this->savedDestination = $this->uploadDir . '/' . $this->savedFileName;
277
+		if (!\move_uploaded_file($this->mediaTmpName, $this->savedDestination)) {
278
+			return false;
279
+		}
280
+		@\chmod($this->savedDestination, $chmod);
281
+
282
+		return true;
283
+	}
284
+
285
+	/**
286
+	 * Is the file the right size?
287
+	 *
288
+	 * @return  bool
289
+	 **/
290
+	public function checkMaxFileSize(): bool
291
+	{
292
+		if ($this->mediaSize > $this->maxFileSize) {
293
+			return false;
294
+		}
295
+
296
+		return true;
297
+	}
298
+
299
+	/**
300
+	 * Is the picture the right width?
301
+	 *
302
+	 * @return  bool
303
+	 **/
304
+	public function checkMaxWidth(): bool
305
+	{
306
+		if (!isset($this->maxWidth) || $this->maxWidth < 1) {
307
+			return true;
308
+		}
309
+		if (false !== $dimension = \getimagesize($this->mediaTmpName)) {
310
+			if ($dimension[0] > $this->maxWidth) {
311
+				return false;
312
+			}
313
+		} else {
314
+			\trigger_error(\sprintf('Failed fetching image size of %s, skipping max width check..', $this->mediaTmpName), \E_USER_WARNING);
315
+		}
316
+
317
+		return true;
318
+	}
319
+
320
+	/**
321
+	 * Is the picture the right height?
322
+	 *
323
+	 * @return  bool
324
+	 **/
325
+	public function checkMaxHeight(): bool
326
+	{
327
+		if (!isset($this->maxHeight) || $this->maxHeight < 1) {
328
+			return true;
329
+		}
330
+		if (false !== $dimension = \getimagesize($this->mediaTmpName)) {
331
+			if ($dimension[1] > $this->maxHeight) {
332
+				return false;
333
+			}
334
+		} else {
335
+			\trigger_error(\sprintf('Failed fetching image size of %s, skipping max height check..', $this->mediaTmpName), \E_USER_WARNING);
336
+		}
337
+
338
+		return true;
339
+	}
340
+
341
+	/**
342
+	 * Is the file the right Mime type
343
+	 *
344
+	 * (is there a right type of mime? ;-)
345
+	 *
346
+	 * @return  bool
347
+	 **/
348
+	public function checkMimeType(): bool
349
+	{
350
+		if (\count($this->allowedMimeTypes) > 0 && !\in_array($this->mediaType, $this->allowedMimeTypes, true)) {
351
+			return false;
352
+		}
353
+
354
+		return true;
355
+	}
356
+
357
+	/**
358
+	 * Is the file the right extension
359
+	 *
360
+	 * @return  bool
361
+	 **/
362
+	public function checkExtension(): bool
363
+	{
364
+		$ext = mb_substr(mb_strrchr($this->mediaName, '.'), 1);
365
+		if (!empty($this->allowedExtensions) && !\in_array(mb_strtolower($ext), $this->allowedExtensions, true)) {
366
+			return false;
367
+		}
368
+
369
+		return true;
370
+	}
371
+
372
+	/**
373
+	 * Add an error
374
+	 *
375
+	 * @param string $error
376
+	 **/
377
+	public function setErrors($error): void
378
+	{
379
+		$this->errors[] = \trim($error);
380
+	}
381
+
382
+	/**
383
+	 * Get generated errors
384
+	 *
385
+	 * @param bool $ashtml Format using HTML?
386
+	 *
387
+	 * @return  array|string    Array of array messages OR HTML string
388
+	 */
389
+	public function &getErrors($ashtml = true)
390
+	{
391
+		if (!$ashtml) {
392
+			return $this->errors;
393
+		}
394
+		$ret = '';
395
+		if (\count($this->errors) > 0) {
396
+			$ret = '<h4>Errors Returned While Uploading</h4>';
397
+			foreach ($this->errors as $error) {
398
+				$ret .= $error . '<br>';
399
+			}
400
+		}
401
+
402
+		return $ret;
403
+	}
404 404
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     public $maxHeight;
25 25
     public $targetFileName;
26 26
     public $prefix;
27
-    public $errors            = [];
27
+    public $errors = [];
28 28
     public $savedDestination;
29 29
     public $savedFileName;
30 30
 
@@ -54,12 +54,12 @@  discard block
 block discarded – undo
54 54
 //            }
55 55
 //        }
56 56
         $this->uploadDir = $uploadDir;
57
-        $this->maxFileSize = (int)$maxFileSize;
57
+        $this->maxFileSize = (int) $maxFileSize;
58 58
         if (isset($maxWidth)) {
59
-            $this->maxWidth = (int)$maxWidth;
59
+            $this->maxWidth = (int) $maxWidth;
60 60
         }
61 61
         if (isset($maxHeight)) {
62
-            $this->maxHeight = (int)$maxHeight;
62
+            $this->maxHeight = (int) $maxHeight;
63 63
         }
64 64
         if (isset($allowedExtensions) && \is_array($allowedExtensions)) {
65 65
             $this->allowedExtensions = &$allowedExtensions;
@@ -96,23 +96,23 @@  discard block
 block discarded – undo
96 96
             $this->mediaError   = !empty($_FILES[$index_name]['error']) ? $_FILES[$index_name]['error'] : 0;
97 97
         }
98 98
         $this->errors = [];
99
-        if ((int)$this->mediaSize < 0) {
99
+        if ((int) $this->mediaSize<0) {
100 100
             $this->setErrors('Invalid File Size');
101 101
 
102 102
             return false;
103 103
         }
104
-        if ('' == $this->mediaName) {
104
+        if (''==$this->mediaName) {
105 105
             $this->setErrors('Filename Is Empty');
106 106
 
107 107
             return false;
108 108
         }
109
-        if ('none' === $this->mediaTmpName || !\is_uploaded_file($this->mediaTmpName) || 0 == $this->mediaSize) {
109
+        if ('none'===$this->mediaTmpName || !\is_uploaded_file($this->mediaTmpName) || 0==$this->mediaSize) {
110 110
             $this->setErrors('No file uploaded');
111 111
 
112 112
             return false;
113 113
         }
114
-        if ($this->mediaError > 0) {
115
-            $this->setErrors('Error occurred: Error #' . $this->mediaError);
114
+        if ($this->mediaError>0) {
115
+            $this->setErrors('Error occurred: Error #'.$this->mediaError);
116 116
 
117 117
             return false;
118 118
         }
@@ -208,23 +208,23 @@  discard block
 block discarded – undo
208 208
      */
209 209
     public function upload($chmod = 0644): bool
210 210
     {
211
-        if ('' == $this->uploadDir) {
211
+        if (''==$this->uploadDir) {
212 212
             $this->setErrors('Upload directory not set');
213 213
 
214 214
             return false;
215 215
         }
216 216
         if (!\is_dir($this->uploadDir)) {
217
-            $this->setErrors('Failed opening directory: ' . $this->uploadDir);
217
+            $this->setErrors('Failed opening directory: '.$this->uploadDir);
218 218
 
219 219
             return false;
220 220
         }
221 221
         if (!\is_writable($this->uploadDir)) {
222
-            $this->setErrors('Failed opening directory with write permission: ' . $this->uploadDir);
222
+            $this->setErrors('Failed opening directory with write permission: '.$this->uploadDir);
223 223
 
224 224
             return false;
225 225
         }
226 226
         if (!$this->checkMimeType()) {
227
-            $this->setErrors('MIME type not allowed: ' . $this->mediaType);
227
+            $this->setErrors('MIME type not allowed: '.$this->mediaType);
228 228
 
229 229
             return false;
230 230
         }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             return false;
235 235
         }
236 236
         if (!$this->checkMaxFileSize()) {
237
-            $this->setErrors('File size too large: ' . $this->mediaSize);
237
+            $this->setErrors('File size too large: '.$this->mediaSize);
238 238
         }
239 239
         if (!$this->checkMaxWidth()) {
240 240
             $this->setErrors(\sprintf('File width must be smaller than %u', $this->maxWidth));
@@ -242,11 +242,11 @@  discard block
 block discarded – undo
242 242
         if (!$this->checkMaxHeight()) {
243 243
             $this->setErrors(\sprintf('File height must be smaller than %u', $this->maxHeight));
244 244
         }
245
-        if (\count($this->errors) > 0) {
245
+        if (\count($this->errors)>0) {
246 246
             return false;
247 247
         }
248 248
         if (!$this->_copyFile($chmod)) {
249
-            $this->setErrors('Failed uploading file: ' . $this->mediaName);
249
+            $this->setErrors('Failed uploading file: '.$this->mediaName);
250 250
 
251 251
             return false;
252 252
         }
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
         if (isset($this->targetFileName)) {
270 270
             $this->savedFileName = $this->targetFileName;
271 271
         } elseif (isset($this->prefix)) {
272
-            $this->savedFileName = \uniqid($this->prefix, true) . '.' . \mb_strtolower($matched[1]);
272
+            $this->savedFileName = \uniqid($this->prefix, true).'.'.\mb_strtolower($matched[1]);
273 273
         } else {
274 274
             $this->savedFileName = \mb_strtolower($this->mediaName);
275 275
         }
276
-        $this->savedDestination = $this->uploadDir . '/' . $this->savedFileName;
276
+        $this->savedDestination = $this->uploadDir.'/'.$this->savedFileName;
277 277
         if (!\move_uploaded_file($this->mediaTmpName, $this->savedDestination)) {
278 278
             return false;
279 279
         }
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      **/
290 290
     public function checkMaxFileSize(): bool
291 291
     {
292
-        if ($this->mediaSize > $this->maxFileSize) {
292
+        if ($this->mediaSize>$this->maxFileSize) {
293 293
             return false;
294 294
         }
295 295
 
@@ -303,11 +303,11 @@  discard block
 block discarded – undo
303 303
      **/
304 304
     public function checkMaxWidth(): bool
305 305
     {
306
-        if (!isset($this->maxWidth) || $this->maxWidth < 1) {
306
+        if (!isset($this->maxWidth) || $this->maxWidth<1) {
307 307
             return true;
308 308
         }
309
-        if (false !== $dimension = \getimagesize($this->mediaTmpName)) {
310
-            if ($dimension[0] > $this->maxWidth) {
309
+        if (false!==$dimension = \getimagesize($this->mediaTmpName)) {
310
+            if ($dimension[0]>$this->maxWidth) {
311 311
                 return false;
312 312
             }
313 313
         } else {
@@ -324,11 +324,11 @@  discard block
 block discarded – undo
324 324
      **/
325 325
     public function checkMaxHeight(): bool
326 326
     {
327
-        if (!isset($this->maxHeight) || $this->maxHeight < 1) {
327
+        if (!isset($this->maxHeight) || $this->maxHeight<1) {
328 328
             return true;
329 329
         }
330
-        if (false !== $dimension = \getimagesize($this->mediaTmpName)) {
331
-            if ($dimension[1] > $this->maxHeight) {
330
+        if (false!==$dimension = \getimagesize($this->mediaTmpName)) {
331
+            if ($dimension[1]>$this->maxHeight) {
332 332
                 return false;
333 333
             }
334 334
         } else {
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
      **/
348 348
     public function checkMimeType(): bool
349 349
     {
350
-        if (\count($this->allowedMimeTypes) > 0 && !\in_array($this->mediaType, $this->allowedMimeTypes, true)) {
350
+        if (\count($this->allowedMimeTypes)>0 && !\in_array($this->mediaType, $this->allowedMimeTypes, true)) {
351 351
             return false;
352 352
         }
353 353
 
@@ -392,10 +392,10 @@  discard block
 block discarded – undo
392 392
             return $this->errors;
393 393
         }
394 394
         $ret = '';
395
-        if (\count($this->errors) > 0) {
395
+        if (\count($this->errors)>0) {
396 396
             $ret = '<h4>Errors Returned While Uploading</h4>';
397 397
             foreach ($this->errors as $error) {
398
-                $ret .= $error . '<br>';
398
+                $ret .= $error.'<br>';
399 399
             }
400 400
         }
401 401
 
Please login to merge, or discard this patch.
class/Helper.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -23,57 +23,57 @@
 block discarded – undo
23 23
  */
24 24
 class Helper extends \Xmf\Module\Helper
25 25
 {
26
-    public $debug;
26
+	public $debug;
27 27
 
28
-    /**
29
-     * @param bool $debug
30
-     */
31
-    public function __construct($debug = false)
32
-    {
33
-        $this->debug   = $debug;
34
-        $moduleDirName = \basename(\dirname(__DIR__));
35
-        parent::__construct($moduleDirName);
36
-    }
28
+	/**
29
+	 * @param bool $debug
30
+	 */
31
+	public function __construct($debug = false)
32
+	{
33
+		$this->debug   = $debug;
34
+		$moduleDirName = \basename(\dirname(__DIR__));
35
+		parent::__construct($moduleDirName);
36
+	}
37 37
 
38
-    public static function getInstance(bool $debug = false): self
39
-    {
40
-        static $instance;
41
-        if (null === $instance) {
42
-            $instance = new static($debug);
43
-        }
38
+	public static function getInstance(bool $debug = false): self
39
+	{
40
+		static $instance;
41
+		if (null === $instance) {
42
+			$instance = new static($debug);
43
+		}
44 44
 
45
-        return $instance;
46
-    }
45
+		return $instance;
46
+	}
47 47
 
48
-    /**
49
-     * @return string
50
-     */
51
-    public function getDirname(): string
52
-    {
53
-        return $this->dirname;
54
-    }
48
+	/**
49
+	 * @return string
50
+	 */
51
+	public function getDirname(): string
52
+	{
53
+		return $this->dirname;
54
+	}
55 55
 
56
-    /**
57
-     * Get an Object Handler
58
-     *
59
-     * @param string $name name of handler to load
60
-     *
61
-     * @return \XoopsPersistableObjectHandler
62
-     */
63
-    public function getHandler($name): ?\XoopsPersistableObjectHandler
64
-    {
65
-        $ret = null;
56
+	/**
57
+	 * Get an Object Handler
58
+	 *
59
+	 * @param string $name name of handler to load
60
+	 *
61
+	 * @return \XoopsPersistableObjectHandler
62
+	 */
63
+	public function getHandler($name): ?\XoopsPersistableObjectHandler
64
+	{
65
+		$ret = null;
66 66
 
67
-        $class = __NAMESPACE__ . '\\' . \ucfirst($name) . 'Handler';
68
-        if (!\class_exists($class)) {
69
-            throw new \RuntimeException("Class '$class' not found");
70
-        }
71
-        /** @var \XoopsMySQLDatabase $db */
72
-        $db     = \XoopsDatabaseFactory::getDatabaseConnection();
73
-        $helper = self::getInstance();
74
-        $ret    = new $class($db, $helper);
75
-        $this->addLog("Getting handler '$name'");
76
-        return $ret;
77
-    }
67
+		$class = __NAMESPACE__ . '\\' . \ucfirst($name) . 'Handler';
68
+		if (!\class_exists($class)) {
69
+			throw new \RuntimeException("Class '$class' not found");
70
+		}
71
+		/** @var \XoopsMySQLDatabase $db */
72
+		$db     = \XoopsDatabaseFactory::getDatabaseConnection();
73
+		$helper = self::getInstance();
74
+		$ret    = new $class($db, $helper);
75
+		$this->addLog("Getting handler '$name'");
76
+		return $ret;
77
+	}
78 78
 }
79 79
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     public static function getInstance(bool $debug = false): self
39 39
     {
40 40
         static $instance;
41
-        if (null === $instance) {
41
+        if (null===$instance) {
42 42
             $instance = new static($debug);
43 43
         }
44 44
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     {
65 65
         $ret = null;
66 66
 
67
-        $class = __NAMESPACE__ . '\\' . \ucfirst($name) . 'Handler';
67
+        $class = __NAMESPACE__.'\\'.\ucfirst($name).'Handler';
68 68
         if (!\class_exists($class)) {
69 69
             throw new \RuntimeException("Class '$class' not found");
70 70
         }
Please login to merge, or discard this patch.
class/Visibility.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,10 +25,10 @@
 block discarded – undo
25 25
  */
26 26
 class Visibility extends XoopsObject
27 27
 {
28
-    public function __construct()
29
-    {
30
-        $this->initVar('field_id', \XOBJ_DTYPE_INT);
31
-        $this->initVar('user_group', \XOBJ_DTYPE_INT);
32
-        $this->initVar('profile_group', \XOBJ_DTYPE_INT);
33
-    }
28
+	public function __construct()
29
+	{
30
+		$this->initVar('field_id', \XOBJ_DTYPE_INT);
31
+		$this->initVar('user_group', \XOBJ_DTYPE_INT);
32
+		$this->initVar('profile_group', \XOBJ_DTYPE_INT);
33
+	}
34 34
 }
Please login to merge, or discard this patch.
class/AlbumsHandler.php 2 patches
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -17,188 +17,188 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class AlbumsHandler extends XoopsPersistableObjectHandler
19 19
 {
20
-    /**
21
-     * AlbumsHandler constructor.
22
-     * @param \XoopsDatabase $db
23
-     */
24
-    public function __construct(XoopsDatabase $db)
25
-    {
26
-        parent::__construct($db, 'songlist_albums', Albums::class, 'abid', 'title');
27
-    }
20
+	/**
21
+	 * AlbumsHandler constructor.
22
+	 * @param \XoopsDatabase $db
23
+	 */
24
+	public function __construct(XoopsDatabase $db)
25
+	{
26
+		parent::__construct($db, 'songlist_albums', Albums::class, 'abid', 'title');
27
+	}
28 28
 
29
-    /**
30
-     * @return array
31
-     */
32
-    public function filterFields(): array
33
-    {
34
-        return ['abid', 'cid', 'aids', 'sids', 'title', 'image', 'path', 'artists', 'songs', 'hits', 'rank', 'votes', 'created', 'updated'];
35
-    }
29
+	/**
30
+	 * @return array
31
+	 */
32
+	public function filterFields(): array
33
+	{
34
+		return ['abid', 'cid', 'aids', 'sids', 'title', 'image', 'path', 'artists', 'songs', 'hits', 'rank', 'votes', 'created', 'updated'];
35
+	}
36 36
 
37
-    /**
38
-     * @param $filter
39
-     * @return \CriteriaCompo
40
-     */
41
-    public function getFilterCriteria($filter): CriteriaCompo
42
-    {
43
-        $parts    = \explode('|', $filter);
44
-        $criteria = new CriteriaCompo();
45
-        foreach ($parts as $part) {
46
-            $var = \explode(',', $part);
47
-            if (!empty($var[1]) && !\is_numeric($var[0])) {
48
-                $object = $this->create();
49
-                if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
50
-                    || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
51
-                    $criteria->add(new Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
52
-                } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
53
-                    $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
54
-                } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
55
-                    $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
56
-                } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
57
-                    $criteria->add(new Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
58
-                }
59
-            } elseif (!empty($var[1]) && \is_numeric($var[0])) {
60
-                $criteria->add(new Criteria($var[0], $var[1]));
61
-            }
62
-        }
37
+	/**
38
+	 * @param $filter
39
+	 * @return \CriteriaCompo
40
+	 */
41
+	public function getFilterCriteria($filter): CriteriaCompo
42
+	{
43
+		$parts    = \explode('|', $filter);
44
+		$criteria = new CriteriaCompo();
45
+		foreach ($parts as $part) {
46
+			$var = \explode(',', $part);
47
+			if (!empty($var[1]) && !\is_numeric($var[0])) {
48
+				$object = $this->create();
49
+				if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
50
+					|| \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
51
+					$criteria->add(new Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
52
+				} elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
53
+					$criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
54
+				} elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
55
+					$criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
56
+				} elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
57
+					$criteria->add(new Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
58
+				}
59
+			} elseif (!empty($var[1]) && \is_numeric($var[0])) {
60
+				$criteria->add(new Criteria($var[0], $var[1]));
61
+			}
62
+		}
63 63
 
64
-        return $criteria;
65
-    }
64
+		return $criteria;
65
+	}
66 66
 
67
-    /**
68
-     * @param        $filter
69
-     * @param        $field
70
-     * @param string $sort
71
-     * @param string $op
72
-     * @param string $fct
73
-     * @return string
74
-     */
75
-    public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string
76
-    {
77
-        $ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct);
78
-        if (\is_object($ele)) {
79
-            return $ele->render();
80
-        }
67
+	/**
68
+	 * @param        $filter
69
+	 * @param        $field
70
+	 * @param string $sort
71
+	 * @param string $op
72
+	 * @param string $fct
73
+	 * @return string
74
+	 */
75
+	public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string
76
+	{
77
+		$ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct);
78
+		if (\is_object($ele)) {
79
+			return $ele->render();
80
+		}
81 81
 
82
-        return '&nbsp;';
83
-    }
82
+		return '&nbsp;';
83
+	}
84 84
 
85
-    /**
86
-     * @param bool $force
87
-     * @param null $object
88
-     * @return bool|mixed
89
-     */
90
-    public function insert(XoopsObject $obj, $force = true, $object = null)
91
-    {
92
-        if ($obj->isNew()) {
93
-            $new = true;
94
-            $old = $this->create();
95
-            $obj->setVar('created', \time());
96
-        } else {
97
-            $new = false;
98
-            $old = $this->get($obj->getVar('abid'));
99
-            $obj->setVar('updated', \time());
100
-        }
85
+	/**
86
+	 * @param bool $force
87
+	 * @param null $object
88
+	 * @return bool|mixed
89
+	 */
90
+	public function insert(XoopsObject $obj, $force = true, $object = null)
91
+	{
92
+		if ($obj->isNew()) {
93
+			$new = true;
94
+			$old = $this->create();
95
+			$obj->setVar('created', \time());
96
+		} else {
97
+			$new = false;
98
+			$old = $this->get($obj->getVar('abid'));
99
+			$obj->setVar('updated', \time());
100
+		}
101 101
 
102
-        $artistsHandler  = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
103
-        $genreHandler    = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Genre');
104
-        $voiceHandler    = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Voice');
105
-        $categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category');
102
+		$artistsHandler  = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
103
+		$genreHandler    = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Genre');
104
+		$voiceHandler    = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Voice');
105
+		$categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category');
106 106
 
107
-        if ($object instanceof Songs) {
108
-            if (true === $obj->vars['cid']['changed']) {
109
-                if ($obj->vars['cid']['value'] != $old->vars['cid']['value']) {
110
-                    $category = $categoryHandler->get($obj->vars['cid']['value']);
111
-                    if (\is_object($category)) {
112
-                        $category->setVar('albums', $category->getVar('albums') + 1);
113
-                        $categoryHandler->insert($category, true, $obj);
114
-                        if (!$old->isNew() && $old->vars['cid']['value'] > 0) {
115
-                            $category = $categoryHandler->get($old->vars['cid']['value']);
116
-                            if (\is_object($category)) {
117
-                                $category->setVar('albums', $category->getVar('albums') - 1);
118
-                                $categoryHandler->insert($category, true, $obj);
119
-                            }
120
-                        }
121
-                    }
122
-                }
123
-            }
107
+		if ($object instanceof Songs) {
108
+			if (true === $obj->vars['cid']['changed']) {
109
+				if ($obj->vars['cid']['value'] != $old->vars['cid']['value']) {
110
+					$category = $categoryHandler->get($obj->vars['cid']['value']);
111
+					if (\is_object($category)) {
112
+						$category->setVar('albums', $category->getVar('albums') + 1);
113
+						$categoryHandler->insert($category, true, $obj);
114
+						if (!$old->isNew() && $old->vars['cid']['value'] > 0) {
115
+							$category = $categoryHandler->get($old->vars['cid']['value']);
116
+							if (\is_object($category)) {
117
+								$category->setVar('albums', $category->getVar('albums') - 1);
118
+								$categoryHandler->insert($category, true, $obj);
119
+							}
120
+						}
121
+					}
122
+				}
123
+			}
124 124
 
125
-            if (is_array($obj->vars['aids']['value']) && 0 != \count($obj->vars['aids']['value']) && true === $obj->vars['aids']['changed']) {
126
-                foreach ($obj->vars['aids']['value'] as $aid) {
127
-                    if (!\is_array($aid, $old->getVar('aids')) && 0 != $aid) {
128
-                        $artists = $artistsHandler->get($aid);
129
-                        if (\is_object($artists)) {
130
-                            $artists->setVar('albums', $artists->getVar('albums') + 1);
131
-                            $artistsHandler->insert($artists, true, $obj);
132
-                        }
133
-                    }
134
-                }
135
-                if (!$old->isNew()) {
136
-                    foreach ($old->getVar('aids') as $aid) {
137
-                        if (!\is_array($aid, $obj->vars['aids']['value']) && 0 != $aid) {
138
-                            $artists = $artistsHandler->get($aid);
139
-                            if (\is_object($artists)) {
140
-                                $artists->setVar('albums', $artists->getVar('albums') - 1);
141
-                                $artistsHandler->insert($artists, true, $obj);
142
-                            }
143
-                        }
144
-                    }
145
-                }
146
-            }
125
+			if (is_array($obj->vars['aids']['value']) && 0 != \count($obj->vars['aids']['value']) && true === $obj->vars['aids']['changed']) {
126
+				foreach ($obj->vars['aids']['value'] as $aid) {
127
+					if (!\is_array($aid, $old->getVar('aids')) && 0 != $aid) {
128
+						$artists = $artistsHandler->get($aid);
129
+						if (\is_object($artists)) {
130
+							$artists->setVar('albums', $artists->getVar('albums') + 1);
131
+							$artistsHandler->insert($artists, true, $obj);
132
+						}
133
+					}
134
+				}
135
+				if (!$old->isNew()) {
136
+					foreach ($old->getVar('aids') as $aid) {
137
+						if (!\is_array($aid, $obj->vars['aids']['value']) && 0 != $aid) {
138
+							$artists = $artistsHandler->get($aid);
139
+							if (\is_object($artists)) {
140
+								$artists->setVar('albums', $artists->getVar('albums') - 1);
141
+								$artistsHandler->insert($artists, true, $obj);
142
+							}
143
+						}
144
+					}
145
+				}
146
+			}
147 147
 
148
-            if (0 != $object->vars['gid']['value']??'' && true === $object->vars['gid']['changed']??'') {
149
-                $genre = $genreHandler->get($object->vars['gid']['value']);
150
-                if (\is_object($genre)) {
151
-                    $genre->setVar('albums', $genre->getVar('albums') + 1);
152
-                    $genreHandler->insert($genre, true, $obj);
153
-                }
154
-            }
155
-            if (0 != $object->vars['vid']['value']??'' && true === $object->vars['vid']['changed']??'') {
156
-                $voice = $voiceHandler->get($object->vars['vid']['value']);
157
-                if (\is_object($voice)) {
158
-                    $voice->setVar('albums', $voice->getVar('albums') + 1);
159
-                    $voiceHandler->insert($voice, true, $obj);
160
-                }
161
-            }
162
-        }
163
-        if ('' == $obj->getVar('title')) {
164
-            return false;
165
-        }
148
+			if (0 != $object->vars['gid']['value']??'' && true === $object->vars['gid']['changed']??'') {
149
+				$genre = $genreHandler->get($object->vars['gid']['value']);
150
+				if (\is_object($genre)) {
151
+					$genre->setVar('albums', $genre->getVar('albums') + 1);
152
+					$genreHandler->insert($genre, true, $obj);
153
+				}
154
+			}
155
+			if (0 != $object->vars['vid']['value']??'' && true === $object->vars['vid']['changed']??'') {
156
+				$voice = $voiceHandler->get($object->vars['vid']['value']);
157
+				if (\is_object($voice)) {
158
+					$voice->setVar('albums', $voice->getVar('albums') + 1);
159
+					$voiceHandler->insert($voice, true, $obj);
160
+				}
161
+			}
162
+		}
163
+		if ('' == $obj->getVar('title')) {
164
+			return false;
165
+		}
166 166
 
167
-        return parent::insert($obj, $force);
168
-    }
167
+		return parent::insert($obj, $force);
168
+	}
169 169
 
170
-    public $_objects = ['object' => [], 'array' => []];
170
+	public $_objects = ['object' => [], 'array' => []];
171 171
 
172
-    /**
173
-     * @param null $id
174
-     * @param null $fields
175
-     * @return \XoopsObject
176
-     */
177
-    public function get($id = null, $fields = null)//get($id, $fields = '*')
178
-    {
179
-        $fields = $fields ?: '*';
180
-        if (!isset($this->_objects['object'][$id])) {
181
-            $this->_objects['object'][$id] = parent::get($id, $fields);
182
-            if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
183
-                $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
184
-                $GLOBALS['xoopsDB']->queryF($sql);
185
-            }
186
-        }
172
+	/**
173
+	 * @param null $id
174
+	 * @param null $fields
175
+	 * @return \XoopsObject
176
+	 */
177
+	public function get($id = null, $fields = null)//get($id, $fields = '*')
178
+	{
179
+		$fields = $fields ?: '*';
180
+		if (!isset($this->_objects['object'][$id])) {
181
+			$this->_objects['object'][$id] = parent::get($id, $fields);
182
+			if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
183
+				$sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
184
+				$GLOBALS['xoopsDB']->queryF($sql);
185
+			}
186
+		}
187 187
 
188
-        return $this->_objects['object'][$id];
189
-    }
188
+		return $this->_objects['object'][$id];
189
+	}
190 190
 
191
-    /**
192
-     * @param \CriteriaElement|\CriteriaCompo $criteria
193
-     * @param bool $id_as_key
194
-     * @param bool $as_object
195
-     * @return array
196
-     */
197
-    public function &getObjects($criteria = null, $id_as_key = false, $as_object = true): array
198
-    {
199
-        $ret = parent::getObjects($criteria, $id_as_key, $as_object);
191
+	/**
192
+	 * @param \CriteriaElement|\CriteriaCompo $criteria
193
+	 * @param bool $id_as_key
194
+	 * @param bool $as_object
195
+	 * @return array
196
+	 */
197
+	public function &getObjects($criteria = null, $id_as_key = false, $as_object = true): array
198
+	{
199
+		$ret = parent::getObjects($criteria, $id_as_key, $as_object);
200 200
 
201
-        /* if (!isset($GLOBALS['songlistAdmin'])) {
201
+		/* if (!isset($GLOBALS['songlistAdmin'])) {
202 202
             $id = [];
203 203
             foreach($ret as $data) {
204 204
                 if ($as_object==true) {
@@ -219,69 +219,69 @@  discard block
 block discarded – undo
219 219
             $GLOBALS['xoopsDB']->queryF($sql);
220 220
         }*/
221 221
 
222
-        return $ret;
223
-    }
222
+		return $ret;
223
+	}
224 224
 
225
-    /**
226
-     * @return string
227
-     */
228
-    public function getURL(): string
229
-    {
230
-        global $file, $op, $fct, $id, $value, $gid, $vid, $cid, $start, $limit;
231
-        if ($GLOBALS['songlistModuleConfig']['htaccess']) {
232
-            if (0 != $cid) {
233
-                $artistHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
234
-                $artist        = $artistHandler->get($cid);
235
-                if (\is_object($artist) && !$artist->isNew()) {
236
-                    return XOOPS_URL
237
-                           . '/'
238
-                           . $GLOBALS['songlistModuleConfig']['baseofurl']
239
-                           . '/'
240
-                           . $file
241
-                           . '/'
242
-                           . \urlencode(\str_replace([' ', \chr(9)], '-', $artist->getVar('name')))
243
-                           . '/'
244
-                           . $start
245
-                           . '-'
246
-                           . $id
247
-                           . '-'
248
-                           . $op
249
-                           . '-'
250
-                           . $fct
251
-                           . '-'
252
-                           . $gid
253
-                           . '-'
254
-                           . $cid
255
-                           . '/'
256
-                           . \urlencode($value)
257
-                           . $GLOBALS['songlistModuleConfig']['endofurl'];
258
-                }
225
+	/**
226
+	 * @return string
227
+	 */
228
+	public function getURL(): string
229
+	{
230
+		global $file, $op, $fct, $id, $value, $gid, $vid, $cid, $start, $limit;
231
+		if ($GLOBALS['songlistModuleConfig']['htaccess']) {
232
+			if (0 != $cid) {
233
+				$artistHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
234
+				$artist        = $artistHandler->get($cid);
235
+				if (\is_object($artist) && !$artist->isNew()) {
236
+					return XOOPS_URL
237
+						   . '/'
238
+						   . $GLOBALS['songlistModuleConfig']['baseofurl']
239
+						   . '/'
240
+						   . $file
241
+						   . '/'
242
+						   . \urlencode(\str_replace([' ', \chr(9)], '-', $artist->getVar('name')))
243
+						   . '/'
244
+						   . $start
245
+						   . '-'
246
+						   . $id
247
+						   . '-'
248
+						   . $op
249
+						   . '-'
250
+						   . $fct
251
+						   . '-'
252
+						   . $gid
253
+						   . '-'
254
+						   . $cid
255
+						   . '/'
256
+						   . \urlencode($value)
257
+						   . $GLOBALS['songlistModuleConfig']['endofurl'];
258
+				}
259 259
 
260
-                return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
261
-            }
260
+				return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
261
+			}
262 262
 
263
-            return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
264
-        }
263
+			return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
264
+		}
265 265
 
266
-        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start;
267
-    }
266
+		return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start;
267
+	}
268 268
 
269
-    /**
270
-     * @param int $limit
271
-     * @return array
272
-     */
273
-    public function getTop($limit = 1): array
274
-    {
275
-        $sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
276
-        $results = $GLOBALS['xoopsDB']->queryF($sql);
277
-        $ret     = [];
278
-        $i       = 0;
279
-        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
280
-            $ret[$i] = $this->create();
281
-            $ret[$i]->assignVars($row);
282
-            ++$i;
283
-        }
269
+	/**
270
+	 * @param int $limit
271
+	 * @return array
272
+	 */
273
+	public function getTop($limit = 1): array
274
+	{
275
+		$sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
276
+		$results = $GLOBALS['xoopsDB']->queryF($sql);
277
+		$ret     = [];
278
+		$i       = 0;
279
+		while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
280
+			$ret[$i] = $this->create();
281
+			$ret[$i]->assignVars($row);
282
+			++$i;
283
+		}
284 284
 
285
-        return $ret;
286
-    }
285
+		return $ret;
286
+	}
287 287
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use XoopsObject;
9 9
 use XoopsPersistableObjectHandler;
10 10
 
11
-require_once \dirname(__DIR__) . '/include/songlist.object.php';
11
+require_once \dirname(__DIR__).'/include/songlist.object.php';
12 12
 // require_once \dirname(__DIR__) . '/include/songlist.form.php';
13 13
 use  XoopsModules\Songlist\Form\FormController;
14 14
 
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
             $var = \explode(',', $part);
47 47
             if (!empty($var[1]) && !\is_numeric($var[0])) {
48 48
                 $object = $this->create();
49
-                if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
50
-                    || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
51
-                    $criteria->add(new Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
49
+                if (\XOBJ_DTYPE_TXTBOX==$object->vars[$var[0]]['data_type']
50
+                    || \XOBJ_DTYPE_TXTAREA==$object->vars[$var[0]]['data_type']) {
51
+                    $criteria->add(new Criteria('`'.$var[0].'`', '%'.$var[1].'%', ($var[2] ?? 'LIKE')));
52 52
                 } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
53
-                    $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
54
-                } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
55
-                    $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
56
-                } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
57
-                    $criteria->add(new Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
53
+                    $criteria->add(new Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '=')));
54
+                } elseif (\XOBJ_DTYPE_ENUM==$object->vars[$var[0]]['data_type']) {
55
+                    $criteria->add(new Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '=')));
56
+                } elseif (\XOBJ_DTYPE_ARRAY==$object->vars[$var[0]]['data_type']) {
57
+                    $criteria->add(new Criteria('`'.$var[0].'`', '%"'.$var[1].'";%', ($var[2] ?? 'LIKE')));
58 58
                 }
59 59
             } elseif (!empty($var[1]) && \is_numeric($var[0])) {
60 60
                 $criteria->add(new Criteria($var[0], $var[1]));
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
         $categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category');
106 106
 
107 107
         if ($object instanceof Songs) {
108
-            if (true === $obj->vars['cid']['changed']) {
109
-                if ($obj->vars['cid']['value'] != $old->vars['cid']['value']) {
108
+            if (true===$obj->vars['cid']['changed']) {
109
+                if ($obj->vars['cid']['value']!=$old->vars['cid']['value']) {
110 110
                     $category = $categoryHandler->get($obj->vars['cid']['value']);
111 111
                     if (\is_object($category)) {
112
-                        $category->setVar('albums', $category->getVar('albums') + 1);
112
+                        $category->setVar('albums', $category->getVar('albums')+1);
113 113
                         $categoryHandler->insert($category, true, $obj);
114
-                        if (!$old->isNew() && $old->vars['cid']['value'] > 0) {
114
+                        if (!$old->isNew() && $old->vars['cid']['value']>0) {
115 115
                             $category = $categoryHandler->get($old->vars['cid']['value']);
116 116
                             if (\is_object($category)) {
117
-                                $category->setVar('albums', $category->getVar('albums') - 1);
117
+                                $category->setVar('albums', $category->getVar('albums')-1);
118 118
                                 $categoryHandler->insert($category, true, $obj);
119 119
                             }
120 120
                         }
@@ -122,22 +122,22 @@  discard block
 block discarded – undo
122 122
                 }
123 123
             }
124 124
 
125
-            if (is_array($obj->vars['aids']['value']) && 0 != \count($obj->vars['aids']['value']) && true === $obj->vars['aids']['changed']) {
125
+            if (is_array($obj->vars['aids']['value']) && 0!=\count($obj->vars['aids']['value']) && true===$obj->vars['aids']['changed']) {
126 126
                 foreach ($obj->vars['aids']['value'] as $aid) {
127
-                    if (!\is_array($aid, $old->getVar('aids')) && 0 != $aid) {
127
+                    if (!\is_array($aid, $old->getVar('aids')) && 0!=$aid) {
128 128
                         $artists = $artistsHandler->get($aid);
129 129
                         if (\is_object($artists)) {
130
-                            $artists->setVar('albums', $artists->getVar('albums') + 1);
130
+                            $artists->setVar('albums', $artists->getVar('albums')+1);
131 131
                             $artistsHandler->insert($artists, true, $obj);
132 132
                         }
133 133
                     }
134 134
                 }
135 135
                 if (!$old->isNew()) {
136 136
                     foreach ($old->getVar('aids') as $aid) {
137
-                        if (!\is_array($aid, $obj->vars['aids']['value']) && 0 != $aid) {
137
+                        if (!\is_array($aid, $obj->vars['aids']['value']) && 0!=$aid) {
138 138
                             $artists = $artistsHandler->get($aid);
139 139
                             if (\is_object($artists)) {
140
-                                $artists->setVar('albums', $artists->getVar('albums') - 1);
140
+                                $artists->setVar('albums', $artists->getVar('albums')-1);
141 141
                                 $artistsHandler->insert($artists, true, $obj);
142 142
                             }
143 143
                         }
@@ -145,22 +145,22 @@  discard block
 block discarded – undo
145 145
                 }
146 146
             }
147 147
 
148
-            if (0 != $object->vars['gid']['value']??'' && true === $object->vars['gid']['changed']??'') {
148
+            if (0!=$object->vars['gid']['value'] ?? '' && true===$object->vars['gid']['changed'] ?? '') {
149 149
                 $genre = $genreHandler->get($object->vars['gid']['value']);
150 150
                 if (\is_object($genre)) {
151
-                    $genre->setVar('albums', $genre->getVar('albums') + 1);
151
+                    $genre->setVar('albums', $genre->getVar('albums')+1);
152 152
                     $genreHandler->insert($genre, true, $obj);
153 153
                 }
154 154
             }
155
-            if (0 != $object->vars['vid']['value']??'' && true === $object->vars['vid']['changed']??'') {
155
+            if (0!=$object->vars['vid']['value'] ?? '' && true===$object->vars['vid']['changed'] ?? '') {
156 156
                 $voice = $voiceHandler->get($object->vars['vid']['value']);
157 157
                 if (\is_object($voice)) {
158
-                    $voice->setVar('albums', $voice->getVar('albums') + 1);
158
+                    $voice->setVar('albums', $voice->getVar('albums')+1);
159 159
                     $voiceHandler->insert($voice, true, $obj);
160 160
                 }
161 161
             }
162 162
         }
163
-        if ('' == $obj->getVar('title')) {
163
+        if (''==$obj->getVar('title')) {
164 164
             return false;
165 165
         }
166 166
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         if (!isset($this->_objects['object'][$id])) {
181 181
             $this->_objects['object'][$id] = parent::get($id, $fields);
182 182
             if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
183
-                $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
183
+                $sql = 'UPDATE `'.$this->table.'` set hits=hits+1 where `'.$this->keyName.'` = '.$this->_objects['object'][$id]->getVar($this->keyName);
184 184
                 $GLOBALS['xoopsDB']->queryF($sql);
185 185
             }
186 186
         }
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
     {
230 230
         global $file, $op, $fct, $id, $value, $gid, $vid, $cid, $start, $limit;
231 231
         if ($GLOBALS['songlistModuleConfig']['htaccess']) {
232
-            if (0 != $cid) {
232
+            if (0!=$cid) {
233 233
                 $artistHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
234 234
                 $artist        = $artistHandler->get($cid);
235 235
                 if (\is_object($artist) && !$artist->isNew()) {
@@ -257,13 +257,13 @@  discard block
 block discarded – undo
257 257
                            . $GLOBALS['songlistModuleConfig']['endofurl'];
258 258
                 }
259 259
 
260
-                return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
260
+                return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/'.$file.'/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.\urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl'];
261 261
             }
262 262
 
263
-            return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
263
+            return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/'.$file.'/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.\urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl'];
264 264
         }
265 265
 
266
-        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start;
266
+        return XOOPS_URL.'/modules/songlist/'.$file.'.php?op='.$op.'&fct='.$fct.'&id='.$id.'&value='.\urlencode($value ?? '').'&gid='.$gid.'&vid='.$vid.'&cid='.$cid.'&start='.$start;
267 267
     }
268 268
 
269 269
     /**
@@ -272,11 +272,11 @@  discard block
 block discarded – undo
272 272
      */
273 273
     public function getTop($limit = 1): array
274 274
     {
275
-        $sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
275
+        $sql     = 'SELECT * FROM `'.$this->table.'` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT '.$limit;
276 276
         $results = $GLOBALS['xoopsDB']->queryF($sql);
277 277
         $ret     = [];
278 278
         $i       = 0;
279
-        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
279
+        while (false!==($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
280 280
             $ret[$i] = $this->create();
281 281
             $ret[$i]->assignVars($row);
282 282
             ++$i;
Please login to merge, or discard this patch.
class/FieldHandler.php 2 patches
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -7,238 +7,238 @@
 block discarded – undo
7 7
  */
8 8
 class FieldHandler extends \XoopsPersistableObjectHandler
9 9
 {
10
-    /**
11
-     * FieldHandler constructor.
12
-     * @param \XoopsDatabase $db
13
-     */
14
-    public function __construct(\XoopsDatabase $db)
15
-    {
16
-        parent::__construct($db, 'songlist_field', Field::class, 'field_id', 'field_title');
17
-    }
10
+	/**
11
+	 * FieldHandler constructor.
12
+	 * @param \XoopsDatabase $db
13
+	 */
14
+	public function __construct(\XoopsDatabase $db)
15
+	{
16
+		parent::__construct($db, 'songlist_field', Field::class, 'field_id', 'field_title');
17
+	}
18 18
 
19
-    /**
20
-     * Read field information from cached storage
21
-     *
22
-     * @param bool $force_update read fields from database and not cached storage
23
-     *
24
-     * @return array|false
25
-     */
26
-    public function loadFields($force_update = false)
27
-    {
28
-        static $fields = [];
29
-        if (!empty($force_update) || 0 == \count($fields)) {
30
-            $criteria = new \Criteria('field_id', 0, '!=');
31
-            $criteria->setSort('field_weight');
32
-            if (0 == $this->getCount($criteria)) {
33
-                return false;
34
-            }
35
-            $field_objs = $this->getObjects($criteria);
36
-            foreach (\array_keys($field_objs) as $i) {
37
-                $fields[$field_objs[$i]->getVar('field_name')] = $field_objs[$i];
38
-            }
39
-        }
19
+	/**
20
+	 * Read field information from cached storage
21
+	 *
22
+	 * @param bool $force_update read fields from database and not cached storage
23
+	 *
24
+	 * @return array|false
25
+	 */
26
+	public function loadFields($force_update = false)
27
+	{
28
+		static $fields = [];
29
+		if (!empty($force_update) || 0 == \count($fields)) {
30
+			$criteria = new \Criteria('field_id', 0, '!=');
31
+			$criteria->setSort('field_weight');
32
+			if (0 == $this->getCount($criteria)) {
33
+				return false;
34
+			}
35
+			$field_objs = $this->getObjects($criteria);
36
+			foreach (\array_keys($field_objs) as $i) {
37
+				$fields[$field_objs[$i]->getVar('field_name')] = $field_objs[$i];
38
+			}
39
+		}
40 40
 
41
-        return $fields;
42
-    }
41
+		return $fields;
42
+	}
43 43
 
44
-    /**
45
-     * save a profile field in the database
46
-     *
47
-     * @param \XoopsObject $obj   reference to the object
48
-     * @param bool         $force whether to force the query execution despite security settings
49
-     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
50
-     * @internal param bool $checkObject check if the object is dirty and clean the attributes
51
-     */
52
-    public function insert(\XoopsObject $obj, $force = false)
53
-    {
54
-        $objectsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Extras');
55
-        $obj->setVar('field_name', \str_replace(' ', '_', $obj->getVar('field_name')));
56
-        $obj->cleanVars();
57
-        $defaultstring = '';
58
-        switch ($obj->getVar('field_type')) {
59
-            case 'datetime':
60
-            case 'date':
61
-                $obj->setVar('field_valuetype', \XOBJ_DTYPE_INT);
62
-                $obj->setVar('field_maxlength', 10);
63
-                break;
64
-            case 'longdate':
65
-                $obj->setVar('field_valuetype', \XOBJ_DTYPE_MTIME);
66
-                break;
67
-            case 'yesno':
68
-                $obj->setVar('field_valuetype', \XOBJ_DTYPE_INT);
69
-                $obj->setVar('field_maxlength', 1);
70
-                break;
71
-            case 'textbox':
72
-                if (\XOBJ_DTYPE_INT != $obj->getVar('field_valuetype')) {
73
-                    $obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTBOX);
74
-                }
75
-                break;
76
-            case 'autotext':
77
-                if (\XOBJ_DTYPE_INT != $obj->getVar('field_valuetype')) {
78
-                    $obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTAREA);
79
-                }
80
-                break;
81
-            case 'group_multi':
82
-            case 'select_multi':
83
-            case 'checkbox':
84
-                $obj->setVar('field_valuetype', \XOBJ_DTYPE_ARRAY);
85
-                break;
86
-            case 'language':
87
-            case 'timezone':
88
-            case 'theme':
89
-                $obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTBOX);
90
-                break;
91
-            case 'dhtml':
92
-            case 'textarea':
93
-                $obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTAREA);
94
-                break;
95
-        }
44
+	/**
45
+	 * save a profile field in the database
46
+	 *
47
+	 * @param \XoopsObject $obj   reference to the object
48
+	 * @param bool         $force whether to force the query execution despite security settings
49
+	 * @return bool FALSE if failed, TRUE if already present and unchanged or successful
50
+	 * @internal param bool $checkObject check if the object is dirty and clean the attributes
51
+	 */
52
+	public function insert(\XoopsObject $obj, $force = false)
53
+	{
54
+		$objectsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Extras');
55
+		$obj->setVar('field_name', \str_replace(' ', '_', $obj->getVar('field_name')));
56
+		$obj->cleanVars();
57
+		$defaultstring = '';
58
+		switch ($obj->getVar('field_type')) {
59
+			case 'datetime':
60
+			case 'date':
61
+				$obj->setVar('field_valuetype', \XOBJ_DTYPE_INT);
62
+				$obj->setVar('field_maxlength', 10);
63
+				break;
64
+			case 'longdate':
65
+				$obj->setVar('field_valuetype', \XOBJ_DTYPE_MTIME);
66
+				break;
67
+			case 'yesno':
68
+				$obj->setVar('field_valuetype', \XOBJ_DTYPE_INT);
69
+				$obj->setVar('field_maxlength', 1);
70
+				break;
71
+			case 'textbox':
72
+				if (\XOBJ_DTYPE_INT != $obj->getVar('field_valuetype')) {
73
+					$obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTBOX);
74
+				}
75
+				break;
76
+			case 'autotext':
77
+				if (\XOBJ_DTYPE_INT != $obj->getVar('field_valuetype')) {
78
+					$obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTAREA);
79
+				}
80
+				break;
81
+			case 'group_multi':
82
+			case 'select_multi':
83
+			case 'checkbox':
84
+				$obj->setVar('field_valuetype', \XOBJ_DTYPE_ARRAY);
85
+				break;
86
+			case 'language':
87
+			case 'timezone':
88
+			case 'theme':
89
+				$obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTBOX);
90
+				break;
91
+			case 'dhtml':
92
+			case 'textarea':
93
+				$obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTAREA);
94
+				break;
95
+		}
96 96
 
97
-        if ('' == $obj->getVar('field_valuetype')) {
98
-            $obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTBOX);
99
-        }
97
+		if ('' == $obj->getVar('field_valuetype')) {
98
+			$obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTBOX);
99
+		}
100 100
 
101
-        if (!\in_array($obj->getVar('field_name'), $this->getPostVars(), true)) {
102
-            if ($obj->isNew()) {
103
-                //add column to table
104
-                $changetype = 'ADD';
105
-            } else {
106
-                //update column information
107
-                $changetype = 'CHANGE `' . $obj->getVar('field_name', 'n') . '`';
108
-            }
109
-            $maxlengthstring = $obj->getVar('field_maxlength') > 0 ? '(' . $obj->getVar('field_maxlength') . ')' : '';
110
-            $notnullstring   = ' NOT NULL';
111
-            //set type
112
-            switch ($obj->getVar('field_valuetype')) {
113
-                default:
114
-                case \XOBJ_DTYPE_ARRAY:
115
-                case \XOBJ_DTYPE_UNICODE_ARRAY:
116
-                    $type = 'mediumtext';
117
-                    break;
118
-                case \XOBJ_DTYPE_UNICODE_EMAIL:
119
-                case \XOBJ_DTYPE_UNICODE_TXTBOX:
120
-                case \XOBJ_DTYPE_UNICODE_URL:
121
-                case \XOBJ_DTYPE_EMAIL:
122
-                case \XOBJ_DTYPE_TXTBOX:
123
-                case \XOBJ_DTYPE_URL:
124
-                    $type = 'varchar';
125
-                    // varchars must have a maxlength
126
-                    if (!$maxlengthstring) {
127
-                        //so set it to max if maxlength is not set - or should it fail?
128
-                        $maxlengthstring = '(255)';
129
-                        $obj->setVar('field_maxlength', 255);
130
-                    }
131
-                    //if ( $obj->getVar('field_default')  ) {
132
-                    $defaultstring = ' DEFAULT ' . $this->db->quote($obj->cleanVars['field_default']);
133
-                    //}
134
-                    break;
135
-                case \XOBJ_DTYPE_INT:
136
-                    $type = 'int';
137
-                    if ($obj->getVar('field_default') || '' !== $obj->getVar('field_default')) {
138
-                        $defaultstring = " DEFAULT '" . (int)$obj->cleanVars['field_default'] . "'";
139
-                        $obj->setVar('field_default', (int)$obj->cleanVars['field_default']);
140
-                    }
141
-                    break;
142
-                case \XOBJ_DTYPE_DECIMAL:
143
-                    $type = 'decimal(14,6)';
144
-                    if ($obj->getVar('field_default') || '' !== $obj->getVar('field_default')) {
145
-                        $defaultstring = " DEFAULT '" . (float)$obj->cleanVars['field_default'] . "'";
146
-                        $obj->setVar('field_default', (float)$obj->cleanVars['field_default']);
147
-                    }
148
-                    break;
149
-                case XOBJ_DTYPE_FLOAT:
150
-                    $type = 'float(15,9)';
151
-                    if ($obj->getVar('field_default') || '' !== $obj->getVar('field_default')) {
152
-                        $defaultstring = " DEFAULT '" . (float)$obj->cleanVars['field_default'] . "'";
153
-                        $obj->setVar('field_default', (float)$obj->cleanVars['field_default']);
154
-                    }
155
-                    break;
156
-                case \XOBJ_DTYPE_OTHER:
157
-                case \XOBJ_DTYPE_UNICODE_TXTAREA:
158
-                case \XOBJ_DTYPE_TXTAREA:
159
-                    $type            = 'text';
160
-                    $maxlengthstring = '';
161
-                    $notnullstring   = '';
162
-                    break;
163
-                case \XOBJ_DTYPE_MTIME:
164
-                    $type            = 'date';
165
-                    $maxlengthstring = '';
166
-                    break;
167
-            }
101
+		if (!\in_array($obj->getVar('field_name'), $this->getPostVars(), true)) {
102
+			if ($obj->isNew()) {
103
+				//add column to table
104
+				$changetype = 'ADD';
105
+			} else {
106
+				//update column information
107
+				$changetype = 'CHANGE `' . $obj->getVar('field_name', 'n') . '`';
108
+			}
109
+			$maxlengthstring = $obj->getVar('field_maxlength') > 0 ? '(' . $obj->getVar('field_maxlength') . ')' : '';
110
+			$notnullstring   = ' NOT NULL';
111
+			//set type
112
+			switch ($obj->getVar('field_valuetype')) {
113
+				default:
114
+				case \XOBJ_DTYPE_ARRAY:
115
+				case \XOBJ_DTYPE_UNICODE_ARRAY:
116
+					$type = 'mediumtext';
117
+					break;
118
+				case \XOBJ_DTYPE_UNICODE_EMAIL:
119
+				case \XOBJ_DTYPE_UNICODE_TXTBOX:
120
+				case \XOBJ_DTYPE_UNICODE_URL:
121
+				case \XOBJ_DTYPE_EMAIL:
122
+				case \XOBJ_DTYPE_TXTBOX:
123
+				case \XOBJ_DTYPE_URL:
124
+					$type = 'varchar';
125
+					// varchars must have a maxlength
126
+					if (!$maxlengthstring) {
127
+						//so set it to max if maxlength is not set - or should it fail?
128
+						$maxlengthstring = '(255)';
129
+						$obj->setVar('field_maxlength', 255);
130
+					}
131
+					//if ( $obj->getVar('field_default')  ) {
132
+					$defaultstring = ' DEFAULT ' . $this->db->quote($obj->cleanVars['field_default']);
133
+					//}
134
+					break;
135
+				case \XOBJ_DTYPE_INT:
136
+					$type = 'int';
137
+					if ($obj->getVar('field_default') || '' !== $obj->getVar('field_default')) {
138
+						$defaultstring = " DEFAULT '" . (int)$obj->cleanVars['field_default'] . "'";
139
+						$obj->setVar('field_default', (int)$obj->cleanVars['field_default']);
140
+					}
141
+					break;
142
+				case \XOBJ_DTYPE_DECIMAL:
143
+					$type = 'decimal(14,6)';
144
+					if ($obj->getVar('field_default') || '' !== $obj->getVar('field_default')) {
145
+						$defaultstring = " DEFAULT '" . (float)$obj->cleanVars['field_default'] . "'";
146
+						$obj->setVar('field_default', (float)$obj->cleanVars['field_default']);
147
+					}
148
+					break;
149
+				case XOBJ_DTYPE_FLOAT:
150
+					$type = 'float(15,9)';
151
+					if ($obj->getVar('field_default') || '' !== $obj->getVar('field_default')) {
152
+						$defaultstring = " DEFAULT '" . (float)$obj->cleanVars['field_default'] . "'";
153
+						$obj->setVar('field_default', (float)$obj->cleanVars['field_default']);
154
+					}
155
+					break;
156
+				case \XOBJ_DTYPE_OTHER:
157
+				case \XOBJ_DTYPE_UNICODE_TXTAREA:
158
+				case \XOBJ_DTYPE_TXTAREA:
159
+					$type            = 'text';
160
+					$maxlengthstring = '';
161
+					$notnullstring   = '';
162
+					break;
163
+				case \XOBJ_DTYPE_MTIME:
164
+					$type            = 'date';
165
+					$maxlengthstring = '';
166
+					break;
167
+			}
168 168
 
169
-            $sql = 'ALTER TABLE `' . $objectsHandler->table . '` ' . $changetype . ' `' . $obj->cleanVars['field_name'] . '` ' . $type . $maxlengthstring . $notnullstring . $defaultstring;
170
-            if (!$this->db->query($sql)) {
171
-                return false;
172
-            }
173
-        }
169
+			$sql = 'ALTER TABLE `' . $objectsHandler->table . '` ' . $changetype . ' `' . $obj->cleanVars['field_name'] . '` ' . $type . $maxlengthstring . $notnullstring . $defaultstring;
170
+			if (!$this->db->query($sql)) {
171
+				return false;
172
+			}
173
+		}
174 174
 
175
-        //change this to also update the cached field information storage
176
-        $obj->setDirty();
177
-        if (!parent::insert($obj, $force)) {
178
-            return false;
179
-        }
175
+		//change this to also update the cached field information storage
176
+		$obj->setDirty();
177
+		if (!parent::insert($obj, $force)) {
178
+			return false;
179
+		}
180 180
 
181
-        return $obj->getVar('field_id');
182
-    }
181
+		return $obj->getVar('field_id');
182
+	}
183 183
 
184
-    /**
185
-     * delete a profile field from the database
186
-     *
187
-     * @param \XoopsObject $obj reference to the object to delete
188
-     * @param bool         $force
189
-     * @return bool FALSE if failed.
190
-     **/
191
-    public function delete(\XoopsObject $obj, $force = false): bool
192
-    {
193
-        $objectsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Extras');
194
-        // remove column from table
195
-        $sql = 'ALTER TABLE ' . $objectsHandler->table . ' DROP `' . $obj->getVar('field_name', 'n') . '`';
196
-        if ($this->db->query($sql)) {
197
-            //change this to update the cached field information storage
198
-            if (!parent::delete($obj, $force)) {
199
-                return false;
200
-            }
184
+	/**
185
+	 * delete a profile field from the database
186
+	 *
187
+	 * @param \XoopsObject $obj reference to the object to delete
188
+	 * @param bool         $force
189
+	 * @return bool FALSE if failed.
190
+	 **/
191
+	public function delete(\XoopsObject $obj, $force = false): bool
192
+	{
193
+		$objectsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Extras');
194
+		// remove column from table
195
+		$sql = 'ALTER TABLE ' . $objectsHandler->table . ' DROP `' . $obj->getVar('field_name', 'n') . '`';
196
+		if ($this->db->query($sql)) {
197
+			//change this to update the cached field information storage
198
+			if (!parent::delete($obj, $force)) {
199
+				return false;
200
+			}
201 201
 
202
-            if ($obj->getVar('field_show') || $obj->getVar('field_edit')) {
203
-                $moduleHandler  = \xoops_getHandler('module');
204
-                $objects_module = $moduleHandler->getByDirname('profile');
205
-                if (\is_object($objects_module)) {
206
-                    // Remove group permissions
207
-                    $grouppermHandler = \xoops_getHandler('groupperm');
208
-                    $criteria         = new \CriteriaCompo(new \Criteria('gperm_modid', $objects_module->getVar('mid')));
209
-                    $criteria->add(new \Criteria('gperm_itemid', $obj->getVar('field_id')));
202
+			if ($obj->getVar('field_show') || $obj->getVar('field_edit')) {
203
+				$moduleHandler  = \xoops_getHandler('module');
204
+				$objects_module = $moduleHandler->getByDirname('profile');
205
+				if (\is_object($objects_module)) {
206
+					// Remove group permissions
207
+					$grouppermHandler = \xoops_getHandler('groupperm');
208
+					$criteria         = new \CriteriaCompo(new \Criteria('gperm_modid', $objects_module->getVar('mid')));
209
+					$criteria->add(new \Criteria('gperm_itemid', $obj->getVar('field_id')));
210 210
 
211
-                    return $grouppermHandler->deleteAll($criteria);
212
-                }
213
-            }
214
-        }
211
+					return $grouppermHandler->deleteAll($criteria);
212
+				}
213
+			}
214
+		}
215 215
 
216
-        return false;
217
-    }
216
+		return false;
217
+	}
218 218
 
219
-    /**
220
-     * Get array of standard variable names (song table)
221
-     *
222
-     * @return array
223
-     */
224
-    public function getPostVars(): array
225
-    {
226
-        return [
227
-            'sid',
228
-            'cid',
229
-            'gid',
230
-            'aids',
231
-            'abid',
232
-            'songid',
233
-            'traxid',
234
-            'title',
235
-            'lyrics',
236
-            'hits',
237
-            'rank',
238
-            'votes',
239
-            'tags',
240
-            'created',
241
-            'updated',
242
-        ];
243
-    }
219
+	/**
220
+	 * Get array of standard variable names (song table)
221
+	 *
222
+	 * @return array
223
+	 */
224
+	public function getPostVars(): array
225
+	{
226
+		return [
227
+			'sid',
228
+			'cid',
229
+			'gid',
230
+			'aids',
231
+			'abid',
232
+			'songid',
233
+			'traxid',
234
+			'title',
235
+			'lyrics',
236
+			'hits',
237
+			'rank',
238
+			'votes',
239
+			'tags',
240
+			'created',
241
+			'updated',
242
+		];
243
+	}
244 244
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -26,10 +26,10 @@  discard block
 block discarded – undo
26 26
     public function loadFields($force_update = false)
27 27
     {
28 28
         static $fields = [];
29
-        if (!empty($force_update) || 0 == \count($fields)) {
29
+        if (!empty($force_update) || 0==\count($fields)) {
30 30
             $criteria = new \Criteria('field_id', 0, '!=');
31 31
             $criteria->setSort('field_weight');
32
-            if (0 == $this->getCount($criteria)) {
32
+            if (0==$this->getCount($criteria)) {
33 33
                 return false;
34 34
             }
35 35
             $field_objs = $this->getObjects($criteria);
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
                 $obj->setVar('field_maxlength', 1);
70 70
                 break;
71 71
             case 'textbox':
72
-                if (\XOBJ_DTYPE_INT != $obj->getVar('field_valuetype')) {
72
+                if (\XOBJ_DTYPE_INT!=$obj->getVar('field_valuetype')) {
73 73
                     $obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTBOX);
74 74
                 }
75 75
                 break;
76 76
             case 'autotext':
77
-                if (\XOBJ_DTYPE_INT != $obj->getVar('field_valuetype')) {
77
+                if (\XOBJ_DTYPE_INT!=$obj->getVar('field_valuetype')) {
78 78
                     $obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTAREA);
79 79
                 }
80 80
                 break;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
                 break;
95 95
         }
96 96
 
97
-        if ('' == $obj->getVar('field_valuetype')) {
97
+        if (''==$obj->getVar('field_valuetype')) {
98 98
             $obj->setVar('field_valuetype', \XOBJ_DTYPE_TXTBOX);
99 99
         }
100 100
 
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
                 $changetype = 'ADD';
105 105
             } else {
106 106
                 //update column information
107
-                $changetype = 'CHANGE `' . $obj->getVar('field_name', 'n') . '`';
107
+                $changetype = 'CHANGE `'.$obj->getVar('field_name', 'n').'`';
108 108
             }
109
-            $maxlengthstring = $obj->getVar('field_maxlength') > 0 ? '(' . $obj->getVar('field_maxlength') . ')' : '';
109
+            $maxlengthstring = $obj->getVar('field_maxlength')>0 ? '('.$obj->getVar('field_maxlength').')' : '';
110 110
             $notnullstring   = ' NOT NULL';
111 111
             //set type
112 112
             switch ($obj->getVar('field_valuetype')) {
@@ -129,28 +129,28 @@  discard block
 block discarded – undo
129 129
                         $obj->setVar('field_maxlength', 255);
130 130
                     }
131 131
                     //if ( $obj->getVar('field_default')  ) {
132
-                    $defaultstring = ' DEFAULT ' . $this->db->quote($obj->cleanVars['field_default']);
132
+                    $defaultstring = ' DEFAULT '.$this->db->quote($obj->cleanVars['field_default']);
133 133
                     //}
134 134
                     break;
135 135
                 case \XOBJ_DTYPE_INT:
136 136
                     $type = 'int';
137
-                    if ($obj->getVar('field_default') || '' !== $obj->getVar('field_default')) {
138
-                        $defaultstring = " DEFAULT '" . (int)$obj->cleanVars['field_default'] . "'";
139
-                        $obj->setVar('field_default', (int)$obj->cleanVars['field_default']);
137
+                    if ($obj->getVar('field_default') || ''!==$obj->getVar('field_default')) {
138
+                        $defaultstring = " DEFAULT '".(int) $obj->cleanVars['field_default']."'";
139
+                        $obj->setVar('field_default', (int) $obj->cleanVars['field_default']);
140 140
                     }
141 141
                     break;
142 142
                 case \XOBJ_DTYPE_DECIMAL:
143 143
                     $type = 'decimal(14,6)';
144
-                    if ($obj->getVar('field_default') || '' !== $obj->getVar('field_default')) {
145
-                        $defaultstring = " DEFAULT '" . (float)$obj->cleanVars['field_default'] . "'";
146
-                        $obj->setVar('field_default', (float)$obj->cleanVars['field_default']);
144
+                    if ($obj->getVar('field_default') || ''!==$obj->getVar('field_default')) {
145
+                        $defaultstring = " DEFAULT '".(float) $obj->cleanVars['field_default']."'";
146
+                        $obj->setVar('field_default', (float) $obj->cleanVars['field_default']);
147 147
                     }
148 148
                     break;
149 149
                 case XOBJ_DTYPE_FLOAT:
150 150
                     $type = 'float(15,9)';
151
-                    if ($obj->getVar('field_default') || '' !== $obj->getVar('field_default')) {
152
-                        $defaultstring = " DEFAULT '" . (float)$obj->cleanVars['field_default'] . "'";
153
-                        $obj->setVar('field_default', (float)$obj->cleanVars['field_default']);
151
+                    if ($obj->getVar('field_default') || ''!==$obj->getVar('field_default')) {
152
+                        $defaultstring = " DEFAULT '".(float) $obj->cleanVars['field_default']."'";
153
+                        $obj->setVar('field_default', (float) $obj->cleanVars['field_default']);
154 154
                     }
155 155
                     break;
156 156
                 case \XOBJ_DTYPE_OTHER:
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
                     break;
167 167
             }
168 168
 
169
-            $sql = 'ALTER TABLE `' . $objectsHandler->table . '` ' . $changetype . ' `' . $obj->cleanVars['field_name'] . '` ' . $type . $maxlengthstring . $notnullstring . $defaultstring;
169
+            $sql = 'ALTER TABLE `'.$objectsHandler->table.'` '.$changetype.' `'.$obj->cleanVars['field_name'].'` '.$type.$maxlengthstring.$notnullstring.$defaultstring;
170 170
             if (!$this->db->query($sql)) {
171 171
                 return false;
172 172
             }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     {
193 193
         $objectsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Extras');
194 194
         // remove column from table
195
-        $sql = 'ALTER TABLE ' . $objectsHandler->table . ' DROP `' . $obj->getVar('field_name', 'n') . '`';
195
+        $sql = 'ALTER TABLE '.$objectsHandler->table.' DROP `'.$obj->getVar('field_name', 'n').'`';
196 196
         if ($this->db->query($sql)) {
197 197
             //change this to update the cached field information storage
198 198
             if (!parent::delete($obj, $force)) {
Please login to merge, or discard this patch.
class/ArtistsHandler.php 2 patches
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -15,182 +15,182 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class ArtistsHandler extends \XoopsPersistableObjectHandler
17 17
 {
18
-    /**
19
-     * ArtistsHandler constructor.
20
-     * @param \XoopsDatabase $db
21
-     */
22
-    public function __construct(XoopsDatabase $db)
23
-    {
24
-        parent::__construct($db, 'songlist_artists', Artists::class, 'aid', 'name');
25
-    }
18
+	/**
19
+	 * ArtistsHandler constructor.
20
+	 * @param \XoopsDatabase $db
21
+	 */
22
+	public function __construct(XoopsDatabase $db)
23
+	{
24
+		parent::__construct($db, 'songlist_artists', Artists::class, 'aid', 'name');
25
+	}
26 26
 
27
-    /**
28
-     * @return array
29
-     */
30
-    public function filterFields(): array
31
-    {
32
-        return ['aid', 'cids', 'singer', 'name', 'albums', 'songs', 'hits', 'rank', 'votes', 'created', 'updated'];
33
-    }
27
+	/**
28
+	 * @return array
29
+	 */
30
+	public function filterFields(): array
31
+	{
32
+		return ['aid', 'cids', 'singer', 'name', 'albums', 'songs', 'hits', 'rank', 'votes', 'created', 'updated'];
33
+	}
34 34
 
35
-    /**
36
-     * @param $filter
37
-     * @return \CriteriaCompo
38
-     */
39
-    public function getFilterCriteria($filter): CriteriaCompo
40
-    {
41
-        $parts    = \explode('|', $filter);
42
-        $criteria = new CriteriaCompo();
43
-        foreach ($parts as $part) {
44
-            $var = \explode(',', $part);
45
-            if (!empty($var[1]) && !\is_numeric($var[0])) {
46
-                $object = $this->create();
47
-                if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
48
-                    || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
49
-                    $criteria->add(new Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
50
-                } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
51
-                    $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
52
-                } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
53
-                    $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
54
-                } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
55
-                    $criteria->add(new Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
56
-                }
57
-            } elseif (!empty($var[1]) && \is_numeric($var[0])) {
58
-                $criteria->add(new Criteria($var[0], $var[1]));
59
-            }
60
-        }
35
+	/**
36
+	 * @param $filter
37
+	 * @return \CriteriaCompo
38
+	 */
39
+	public function getFilterCriteria($filter): CriteriaCompo
40
+	{
41
+		$parts    = \explode('|', $filter);
42
+		$criteria = new CriteriaCompo();
43
+		foreach ($parts as $part) {
44
+			$var = \explode(',', $part);
45
+			if (!empty($var[1]) && !\is_numeric($var[0])) {
46
+				$object = $this->create();
47
+				if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
48
+					|| \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
49
+					$criteria->add(new Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
50
+				} elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
51
+					$criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
52
+				} elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
53
+					$criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
54
+				} elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
55
+					$criteria->add(new Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
56
+				}
57
+			} elseif (!empty($var[1]) && \is_numeric($var[0])) {
58
+				$criteria->add(new Criteria($var[0], $var[1]));
59
+			}
60
+		}
61 61
 
62
-        return $criteria;
63
-    }
62
+		return $criteria;
63
+	}
64 64
 
65
-    /**
66
-     * @param        $filter
67
-     * @param        $field
68
-     * @param string $sort
69
-     * @param string $op
70
-     * @param string $fct
71
-     * @return string
72
-     */
73
-    public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string
74
-    {
75
-        $ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct);
76
-        if (\is_object($ele)) {
77
-            return $ele->render();
78
-        }
65
+	/**
66
+	 * @param        $filter
67
+	 * @param        $field
68
+	 * @param string $sort
69
+	 * @param string $op
70
+	 * @param string $fct
71
+	 * @return string
72
+	 */
73
+	public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string
74
+	{
75
+		$ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct);
76
+		if (\is_object($ele)) {
77
+			return $ele->render();
78
+		}
79 79
 
80
-        return '&nbsp;';
81
-    }
80
+		return '&nbsp;';
81
+	}
82 82
 
83
-    /**
84
-     * @param bool $force
85
-     * @param null $object
86
-     * @return bool|mixed
87
-     */
88
-    public function insert(\XoopsObject $obj, $force = true, $object = null)
89
-    {
90
-        if ($obj->isNew()) {
91
-            $new = true;
92
-            $old = $this->create();
93
-            $obj->setVar('created', \time());
94
-        } else {
95
-            $new = false;
96
-            $old = $this->get($obj->getVar('aid'));
97
-            $obj->setVar('updated', \time());
98
-        }
83
+	/**
84
+	 * @param bool $force
85
+	 * @param null $object
86
+	 * @return bool|mixed
87
+	 */
88
+	public function insert(\XoopsObject $obj, $force = true, $object = null)
89
+	{
90
+		if ($obj->isNew()) {
91
+			$new = true;
92
+			$old = $this->create();
93
+			$obj->setVar('created', \time());
94
+		} else {
95
+			$new = false;
96
+			$old = $this->get($obj->getVar('aid'));
97
+			$obj->setVar('updated', \time());
98
+		}
99 99
 
100
-        $albumsHandler   = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Albums');
101
-        $songsHandler    = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs');
102
-        $genreHandler    = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Genre');
103
-        $voiceHandler    = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Voice');
104
-        $categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category');
100
+		$albumsHandler   = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Albums');
101
+		$songsHandler    = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs');
102
+		$genreHandler    = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Genre');
103
+		$voiceHandler    = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Voice');
104
+		$categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category');
105 105
 
106
-        if ($object instanceof Songs) {
107
-            if (true === $object->vars['cid']['changed']) {
108
-                foreach ($obj->vars['cids']['value'] as $cid) {
109
-                    if (is_array( $object->getVar('cid')) && !\in_array($cid, $object->getVar('cid'), true) && 0 != $cid) {
110
-                        $obj->setVar('cids', \array_merge($obj->getVar('cids'), [$object->getVar('cid') => $object->getVar('cid')]));
111
-                        $category = $categoryHandler->get($cid);
112
-                        if (\is_object($category)) {
113
-                            $category->setVar('artists', $category->getVar('artists') + 1);
114
-                            $categoryHandler->insert($category, true, $obj);
115
-                        }
116
-                    }
117
-                }
118
-                if (!$old->isNew()) {
119
-                    foreach ($old->getVar('cids') as $cid) {
120
-                        if (!\in_array($cid, $obj->vars['cids']['value'], true) && 0 != $cid) {
121
-                            $category = $categoryHandler->get($cid);
122
-                            if (\is_object($category)) {
123
-                                $category->setVar('artists', $category->getVar('artists') - 1);
124
-                                $categoryHandler->insert($category, true, $obj);
125
-                            }
126
-                        }
127
-                    }
128
-                }
129
-            }
106
+		if ($object instanceof Songs) {
107
+			if (true === $object->vars['cid']['changed']) {
108
+				foreach ($obj->vars['cids']['value'] as $cid) {
109
+					if (is_array( $object->getVar('cid')) && !\in_array($cid, $object->getVar('cid'), true) && 0 != $cid) {
110
+						$obj->setVar('cids', \array_merge($obj->getVar('cids'), [$object->getVar('cid') => $object->getVar('cid')]));
111
+						$category = $categoryHandler->get($cid);
112
+						if (\is_object($category)) {
113
+							$category->setVar('artists', $category->getVar('artists') + 1);
114
+							$categoryHandler->insert($category, true, $obj);
115
+						}
116
+					}
117
+				}
118
+				if (!$old->isNew()) {
119
+					foreach ($old->getVar('cids') as $cid) {
120
+						if (!\in_array($cid, $obj->vars['cids']['value'], true) && 0 != $cid) {
121
+							$category = $categoryHandler->get($cid);
122
+							if (\is_object($category)) {
123
+								$category->setVar('artists', $category->getVar('artists') - 1);
124
+								$categoryHandler->insert($category, true, $obj);
125
+							}
126
+						}
127
+					}
128
+				}
129
+			}
130 130
 
131
-            if (0 != $object->vars['abid']['value'] && true === $object->vars['aids']['changed']) {
132
-                $album = $albumsHandler->get($object->vars['abid']['value']);
133
-                if (\is_object($album)) {
134
-                    $album->setVar('artists', $album->getVar('artists') + 1);
135
-                    $albumsHandler->insert($album, true, $obj);
136
-                }
137
-            }
131
+			if (0 != $object->vars['abid']['value'] && true === $object->vars['aids']['changed']) {
132
+				$album = $albumsHandler->get($object->vars['abid']['value']);
133
+				if (\is_object($album)) {
134
+					$album->setVar('artists', $album->getVar('artists') + 1);
135
+					$albumsHandler->insert($album, true, $obj);
136
+				}
137
+			}
138 138
 
139
-            if (0 != $object->vars['gid']['value'] && true === $object->vars['gid']['changed']) {
140
-                $genre = $genreHandler->get($object->vars['gid']['value']);
141
-                if (\is_object($genre)) {
142
-                    $genre->setVar('artists', $genre->getVar('artists') + 1);
143
-                    $genreHandler->insert($genre, true, $obj);
144
-                }
145
-            }
146
-            if (0 != $object->vars['vid']['value'] && true === $object->vars['vid']['changed']) {
147
-                $voice = $voiceHandler->get($object->vars['vid']['value']);
148
-                if (\is_object($voice)) {
149
-                    $voice->setVar('artists', $voice->getVar('artists') + 1);
150
-                    $voiceHandler->insert($voice, true, $obj);
151
-                }
152
-            }
153
-        }
139
+			if (0 != $object->vars['gid']['value'] && true === $object->vars['gid']['changed']) {
140
+				$genre = $genreHandler->get($object->vars['gid']['value']);
141
+				if (\is_object($genre)) {
142
+					$genre->setVar('artists', $genre->getVar('artists') + 1);
143
+					$genreHandler->insert($genre, true, $obj);
144
+				}
145
+			}
146
+			if (0 != $object->vars['vid']['value'] && true === $object->vars['vid']['changed']) {
147
+				$voice = $voiceHandler->get($object->vars['vid']['value']);
148
+				if (\is_object($voice)) {
149
+					$voice->setVar('artists', $voice->getVar('artists') + 1);
150
+					$voiceHandler->insert($voice, true, $obj);
151
+				}
152
+			}
153
+		}
154 154
 
155
-        if ('' == $obj->getVar('name')) {
156
-            return false;
157
-        }
155
+		if ('' == $obj->getVar('name')) {
156
+			return false;
157
+		}
158 158
 
159
-        return parent::insert($obj, $force);
160
-    }
159
+		return parent::insert($obj, $force);
160
+	}
161 161
 
162
-    public $_objects = ['object' => [], 'array' => []];
162
+	public $_objects = ['object' => [], 'array' => []];
163 163
 
164
-    /**
165
-     * @param null $id
166
-     * @param null $fields
167
-     * @return \XoopsObject
168
-     */
169
-    public function get($id = null, $fields = null): \XoopsObject//get($id, $fields = '*')
170
-    {
171
-        $fields = $fields ?: '*';
172
-        if (!isset($this->_objects['object'][$id])) {
173
-            $this->_objects['object'][$id] = parent::get($id, $fields);
174
-            if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
175
-                $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
176
-                $GLOBALS['xoopsDB']->queryF($sql);
177
-            }
178
-        }
164
+	/**
165
+	 * @param null $id
166
+	 * @param null $fields
167
+	 * @return \XoopsObject
168
+	 */
169
+	public function get($id = null, $fields = null): \XoopsObject//get($id, $fields = '*')
170
+	{
171
+		$fields = $fields ?: '*';
172
+		if (!isset($this->_objects['object'][$id])) {
173
+			$this->_objects['object'][$id] = parent::get($id, $fields);
174
+			if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
175
+				$sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
176
+				$GLOBALS['xoopsDB']->queryF($sql);
177
+			}
178
+		}
179 179
 
180
-        return $this->_objects['object'][$id];
181
-    }
180
+		return $this->_objects['object'][$id];
181
+	}
182 182
 
183
-    /**
184
-     * @param \CriteriaElement|\CriteriaCompo $criteria
185
-     * @param bool $id_as_key
186
-     * @param bool $as_object
187
-     * @return array
188
-     */
189
-    public function &getObjects($criteria = null, $id_as_key = false, $as_object = true): array
190
-    {
191
-        $ret = parent::getObjects($criteria, $id_as_key, $as_object);
183
+	/**
184
+	 * @param \CriteriaElement|\CriteriaCompo $criteria
185
+	 * @param bool $id_as_key
186
+	 * @param bool $as_object
187
+	 * @return array
188
+	 */
189
+	public function &getObjects($criteria = null, $id_as_key = false, $as_object = true): array
190
+	{
191
+		$ret = parent::getObjects($criteria, $id_as_key, $as_object);
192 192
 
193
-        /*if (!isset($GLOBALS['songlistAdmin'])) {
193
+		/*if (!isset($GLOBALS['songlistAdmin'])) {
194 194
             $id = [];
195 195
             foreach($ret as $data) {
196 196
                 if ($as_object==true) {
@@ -211,87 +211,87 @@  discard block
 block discarded – undo
211 211
             $GLOBALS['xoopsDB']->queryF($sql);
212 212
         }*/
213 213
 
214
-        return $ret;
215
-    }
214
+		return $ret;
215
+	}
216 216
 
217
-    /**
218
-     * @return string
219
-     */
220
-    public function getURL(): string
221
-    {
222
-        global $file, $op, $fct, $id, $value, $gid, $vid, $cid, $start, $limit;
223
-        if ($GLOBALS['songlistModuleConfig']['htaccess']) {
224
-            if (0 != $cid) {
225
-                $artistHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
226
-                $artist        = $artistHandler->get($cid);
227
-                if (\is_object($artist) && !$artist->isNew()) {
228
-                    return XOOPS_URL
229
-                           . '/'
230
-                           . $GLOBALS['songlistModuleConfig']['baseofurl']
231
-                           . '/'
232
-                           . $file
233
-                           . '/'
234
-                           . \urlencode(\str_replace([' ', \chr(9)], '-', $artist->getVar('name')))
235
-                           . '/'
236
-                           . $start
237
-                           . '-'
238
-                           . $id
239
-                           . '-'
240
-                           . $op
241
-                           . '-'
242
-                           . $fct
243
-                           . '-'
244
-                           . $gid
245
-                           . '-'
246
-                           . $cid
247
-                           . '/'
248
-                           . \urlencode($value)
249
-                           . $GLOBALS['songlistModuleConfig']['endofurl'];
250
-                }
217
+	/**
218
+	 * @return string
219
+	 */
220
+	public function getURL(): string
221
+	{
222
+		global $file, $op, $fct, $id, $value, $gid, $vid, $cid, $start, $limit;
223
+		if ($GLOBALS['songlistModuleConfig']['htaccess']) {
224
+			if (0 != $cid) {
225
+				$artistHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
226
+				$artist        = $artistHandler->get($cid);
227
+				if (\is_object($artist) && !$artist->isNew()) {
228
+					return XOOPS_URL
229
+						   . '/'
230
+						   . $GLOBALS['songlistModuleConfig']['baseofurl']
231
+						   . '/'
232
+						   . $file
233
+						   . '/'
234
+						   . \urlencode(\str_replace([' ', \chr(9)], '-', $artist->getVar('name')))
235
+						   . '/'
236
+						   . $start
237
+						   . '-'
238
+						   . $id
239
+						   . '-'
240
+						   . $op
241
+						   . '-'
242
+						   . $fct
243
+						   . '-'
244
+						   . $gid
245
+						   . '-'
246
+						   . $cid
247
+						   . '/'
248
+						   . \urlencode($value)
249
+						   . $GLOBALS['songlistModuleConfig']['endofurl'];
250
+				}
251 251
 
252
-                return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
253
-            }
252
+				return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
253
+			}
254 254
 
255
-            return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
256
-        }
255
+			return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
256
+		}
257 257
 
258
-        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start;
259
-    }
258
+		return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start;
259
+	}
260 260
 
261
-    /**
262
-     * @param null $criteria
263
-     * @return array
264
-     */
265
-    public function getSIDs($criteria = null): array
266
-    {
267
-        $ret         = [];
268
-        $songHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs');
269
-        foreach ($this->getObjects($criteria, true) as $aid => $object) {
270
-            $crita = new Criteria('aids', '%"' . $aid . '"%', 'LIKE');
271
-            foreach ($songHandler->getObjects($crita, true) as $sid => $song) {
272
-                $ret[$sid] = $sid;
273
-            }
274
-        }
261
+	/**
262
+	 * @param null $criteria
263
+	 * @return array
264
+	 */
265
+	public function getSIDs($criteria = null): array
266
+	{
267
+		$ret         = [];
268
+		$songHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs');
269
+		foreach ($this->getObjects($criteria, true) as $aid => $object) {
270
+			$crita = new Criteria('aids', '%"' . $aid . '"%', 'LIKE');
271
+			foreach ($songHandler->getObjects($crita, true) as $sid => $song) {
272
+				$ret[$sid] = $sid;
273
+			}
274
+		}
275 275
 
276
-        return $ret;
277
-    }
276
+		return $ret;
277
+	}
278 278
 
279
-    /**
280
-     * @param int $limit
281
-     * @return array
282
-     */
283
-    public function getTop($limit = 1): array
284
-    {
285
-        $sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
286
-        $results = $GLOBALS['xoopsDB']->queryF($sql);
287
-        $ret     = [];
288
-        $i       = 0;
289
-        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
290
-            $ret[$i] = $this->create();
291
-            $ret[$i]->assignVars($row);
292
-            ++$i;
293
-        }
279
+	/**
280
+	 * @param int $limit
281
+	 * @return array
282
+	 */
283
+	public function getTop($limit = 1): array
284
+	{
285
+		$sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
286
+		$results = $GLOBALS['xoopsDB']->queryF($sql);
287
+		$ret     = [];
288
+		$i       = 0;
289
+		while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
290
+			$ret[$i] = $this->create();
291
+			$ret[$i]->assignVars($row);
292
+			++$i;
293
+		}
294 294
 
295
-        return $ret;
296
-    }
295
+		return $ret;
296
+	}
297 297
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use CriteriaCompo;
7 7
 use XoopsDatabase;
8 8
 
9
-require_once \dirname(__DIR__) . '/include/songlist.object.php';
9
+require_once \dirname(__DIR__).'/include/songlist.object.php';
10 10
 // require_once \dirname(__DIR__) . '/include/songlist.form.php';
11 11
 use  XoopsModules\Songlist\Form\FormController;
12 12
 
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
             $var = \explode(',', $part);
45 45
             if (!empty($var[1]) && !\is_numeric($var[0])) {
46 46
                 $object = $this->create();
47
-                if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
48
-                    || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
49
-                    $criteria->add(new Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
47
+                if (\XOBJ_DTYPE_TXTBOX==$object->vars[$var[0]]['data_type']
48
+                    || \XOBJ_DTYPE_TXTAREA==$object->vars[$var[0]]['data_type']) {
49
+                    $criteria->add(new Criteria('`'.$var[0].'`', '%'.$var[1].'%', ($var[2] ?? 'LIKE')));
50 50
                 } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
51
-                    $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
52
-                } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
53
-                    $criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
54
-                } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
55
-                    $criteria->add(new Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
51
+                    $criteria->add(new Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '=')));
52
+                } elseif (\XOBJ_DTYPE_ENUM==$object->vars[$var[0]]['data_type']) {
53
+                    $criteria->add(new Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '=')));
54
+                } elseif (\XOBJ_DTYPE_ARRAY==$object->vars[$var[0]]['data_type']) {
55
+                    $criteria->add(new Criteria('`'.$var[0].'`', '%"'.$var[1].'";%', ($var[2] ?? 'LIKE')));
56 56
                 }
57 57
             } elseif (!empty($var[1]) && \is_numeric($var[0])) {
58 58
                 $criteria->add(new Criteria($var[0], $var[1]));
@@ -104,23 +104,23 @@  discard block
 block discarded – undo
104 104
         $categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category');
105 105
 
106 106
         if ($object instanceof Songs) {
107
-            if (true === $object->vars['cid']['changed']) {
107
+            if (true===$object->vars['cid']['changed']) {
108 108
                 foreach ($obj->vars['cids']['value'] as $cid) {
109
-                    if (is_array( $object->getVar('cid')) && !\in_array($cid, $object->getVar('cid'), true) && 0 != $cid) {
109
+                    if (is_array($object->getVar('cid')) && !\in_array($cid, $object->getVar('cid'), true) && 0!=$cid) {
110 110
                         $obj->setVar('cids', \array_merge($obj->getVar('cids'), [$object->getVar('cid') => $object->getVar('cid')]));
111 111
                         $category = $categoryHandler->get($cid);
112 112
                         if (\is_object($category)) {
113
-                            $category->setVar('artists', $category->getVar('artists') + 1);
113
+                            $category->setVar('artists', $category->getVar('artists')+1);
114 114
                             $categoryHandler->insert($category, true, $obj);
115 115
                         }
116 116
                     }
117 117
                 }
118 118
                 if (!$old->isNew()) {
119 119
                     foreach ($old->getVar('cids') as $cid) {
120
-                        if (!\in_array($cid, $obj->vars['cids']['value'], true) && 0 != $cid) {
120
+                        if (!\in_array($cid, $obj->vars['cids']['value'], true) && 0!=$cid) {
121 121
                             $category = $categoryHandler->get($cid);
122 122
                             if (\is_object($category)) {
123
-                                $category->setVar('artists', $category->getVar('artists') - 1);
123
+                                $category->setVar('artists', $category->getVar('artists')-1);
124 124
                                 $categoryHandler->insert($category, true, $obj);
125 125
                             }
126 126
                         }
@@ -128,31 +128,31 @@  discard block
 block discarded – undo
128 128
                 }
129 129
             }
130 130
 
131
-            if (0 != $object->vars['abid']['value'] && true === $object->vars['aids']['changed']) {
131
+            if (0!=$object->vars['abid']['value'] && true===$object->vars['aids']['changed']) {
132 132
                 $album = $albumsHandler->get($object->vars['abid']['value']);
133 133
                 if (\is_object($album)) {
134
-                    $album->setVar('artists', $album->getVar('artists') + 1);
134
+                    $album->setVar('artists', $album->getVar('artists')+1);
135 135
                     $albumsHandler->insert($album, true, $obj);
136 136
                 }
137 137
             }
138 138
 
139
-            if (0 != $object->vars['gid']['value'] && true === $object->vars['gid']['changed']) {
139
+            if (0!=$object->vars['gid']['value'] && true===$object->vars['gid']['changed']) {
140 140
                 $genre = $genreHandler->get($object->vars['gid']['value']);
141 141
                 if (\is_object($genre)) {
142
-                    $genre->setVar('artists', $genre->getVar('artists') + 1);
142
+                    $genre->setVar('artists', $genre->getVar('artists')+1);
143 143
                     $genreHandler->insert($genre, true, $obj);
144 144
                 }
145 145
             }
146
-            if (0 != $object->vars['vid']['value'] && true === $object->vars['vid']['changed']) {
146
+            if (0!=$object->vars['vid']['value'] && true===$object->vars['vid']['changed']) {
147 147
                 $voice = $voiceHandler->get($object->vars['vid']['value']);
148 148
                 if (\is_object($voice)) {
149
-                    $voice->setVar('artists', $voice->getVar('artists') + 1);
149
+                    $voice->setVar('artists', $voice->getVar('artists')+1);
150 150
                     $voiceHandler->insert($voice, true, $obj);
151 151
                 }
152 152
             }
153 153
         }
154 154
 
155
-        if ('' == $obj->getVar('name')) {
155
+        if (''==$obj->getVar('name')) {
156 156
             return false;
157 157
         }
158 158
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
         if (!isset($this->_objects['object'][$id])) {
173 173
             $this->_objects['object'][$id] = parent::get($id, $fields);
174 174
             if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
175
-                $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
175
+                $sql = 'UPDATE `'.$this->table.'` set hits=hits+1 where `'.$this->keyName.'` = '.$this->_objects['object'][$id]->getVar($this->keyName);
176 176
                 $GLOBALS['xoopsDB']->queryF($sql);
177 177
             }
178 178
         }
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
     {
222 222
         global $file, $op, $fct, $id, $value, $gid, $vid, $cid, $start, $limit;
223 223
         if ($GLOBALS['songlistModuleConfig']['htaccess']) {
224
-            if (0 != $cid) {
224
+            if (0!=$cid) {
225 225
                 $artistHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists');
226 226
                 $artist        = $artistHandler->get($cid);
227 227
                 if (\is_object($artist) && !$artist->isNew()) {
@@ -249,13 +249,13 @@  discard block
 block discarded – undo
249 249
                            . $GLOBALS['songlistModuleConfig']['endofurl'];
250 250
                 }
251 251
 
252
-                return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
252
+                return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/'.$file.'/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.\urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl'];
253 253
             }
254 254
 
255
-            return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/' . $file . '/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl'];
255
+            return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/'.$file.'/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.\urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl'];
256 256
         }
257 257
 
258
-        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start;
258
+        return XOOPS_URL.'/modules/songlist/'.$file.'.php?op='.$op.'&fct='.$fct.'&id='.$id.'&value='.\urlencode($value ?? '').'&gid='.$gid.'&vid='.$vid.'&cid='.$cid.'&start='.$start;
259 259
     }
260 260
 
261 261
     /**
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
         $ret         = [];
268 268
         $songHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs');
269 269
         foreach ($this->getObjects($criteria, true) as $aid => $object) {
270
-            $crita = new Criteria('aids', '%"' . $aid . '"%', 'LIKE');
270
+            $crita = new Criteria('aids', '%"'.$aid.'"%', 'LIKE');
271 271
             foreach ($songHandler->getObjects($crita, true) as $sid => $song) {
272 272
                 $ret[$sid] = $sid;
273 273
             }
@@ -282,11 +282,11 @@  discard block
 block discarded – undo
282 282
      */
283 283
     public function getTop($limit = 1): array
284 284
     {
285
-        $sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
285
+        $sql     = 'SELECT * FROM `'.$this->table.'` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT '.$limit;
286 286
         $results = $GLOBALS['xoopsDB']->queryF($sql);
287 287
         $ret     = [];
288 288
         $i       = 0;
289
-        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
289
+        while (false!==($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
290 290
             $ret[$i] = $this->create();
291 291
             $ret[$i]->assignVars($row);
292 292
             ++$i;
Please login to merge, or discard this patch.