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