| 1 |  |  | <?php | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * You may not change or alter any portion of this comment or credits | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * of supporting developers from this source code or any supporting source code | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * which is considered copyrighted (c) material of the original comment or credit authors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @copyright    XOOPS Project http://xoops.org/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @package | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @author       XOOPS Development Team | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof XoopsUser) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     || !$GLOBALS['xoopsUser']->IsAdmin() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     exit('Restricted access' . PHP_EOL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * @param string $tablename | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * @return bool | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 29 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | function tableExists($tablename) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     $result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     return ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) ? true : false; | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  * Prepares system prior to attempting to install module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  * @param XoopsModule $module {@link XoopsModule} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  * @return bool true if ready to install, false if not | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | function xoops_module_pre_update_adslight(XoopsModule $module) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     $moduleDirName = basename(dirname(__DIR__)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     $className = ucfirst($moduleDirName) . 'Utilities'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     if (!class_exists($className)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         xoops_load('utilities', $moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     //check for minimum XOOPS version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     if (!$className::checkXoopsVer($module)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     // check for minimum PHP version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     if (!$className::checkPHPVer($module)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  * Performs tasks required during update of the module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  * @param XoopsModule $module {@link XoopsModule} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  * @param null        $previousVersion | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  * @return bool true if update successful, false if not | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | function xoops_module_update_adslight(XoopsModule $module, $previousVersion = null) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     global $xoopsDB; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     $moduleDirName = basename(dirname(__DIR__)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     if ($previousVersion < 230) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $configurator = include __DIR__ . '/config.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $classUtilities = ucfirst($moduleDirName) . 'Utilities'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         if (!class_exists($classUtilities)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             xoops_load('utilities', $moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         //delete old HTML templates | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         if (count($configurator['templateFolders']) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             foreach ($configurator['templateFolders'] as $folder) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 if (is_dir($templateFolder)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                     $templateList = array_diff(scandir($templateFolder), array('..', '.')); | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 90 |  | View Code Duplication |                     foreach ($templateList as $k => $v) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                         $fileInfo = new SplFileInfo($templateFolder . $v); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                         if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                             if (file_exists($templateFolder . $v)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                                 unlink($templateFolder . $v); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         //  ---  DELETE OLD FILES --------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         if (count($configurator['oldFiles']) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             foreach (array_keys($configurator['oldFiles']) as $i) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                 $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator['oldFiles'][$i]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 if (is_file($tempFile)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                     unlink($tempFile); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         //  ---  DELETE OLD FOLDERS --------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         xoops_load('XoopsFile'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         if (count($configurator['oldFolders']) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             foreach (array_keys($configurator['oldFolders']) as $i) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                 $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator['oldFolders'][$i]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                 /** @var XoopsObjectHandler $folderHandler */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                 $folderHandler   = XoopsFile::getHandler('folder', $tempFolder); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                 $folderHandler->delete($tempFolder); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         //  ---  CREATE FOLDERS --------------- | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 127 |  | View Code Duplication |         if (count($configurator['uploadFolders']) > 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             foreach (array_keys($configurator['uploadFolders']) as $i) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                 $classUtilities::createFolder($configurator['uploadFolders'][$i]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         //  ---  COPY blank.png FILES --------------- | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 135 |  | View Code Duplication |         if (count($configurator['copyFiles']) > 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |             $file = __DIR__ . '/../assets/images/blank.png'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |             foreach (array_keys($configurator['copyFiles']) as $i) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                 $dest = $configurator['copyFiles'][$i] . '/blank.png'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                 $classUtilities::copyFile($file, $dest); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         //delete .html entries from the tpl table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         $sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                                                                                                           'n') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                . "' AND `tpl_file` LIKE '%.html%'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         $xoopsDB->queryF($sql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     $gpermHandler = xoops_getHandler('groupperm'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 153 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 154 |  |  |  | 
            
                        
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.