| 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 |  |  |  * Module: xsitemap | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @package    module\xsitemap\includes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @author     Taiwen Jiang <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @author     ZySpec <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @copyright  https://xoops.org 2001-2017 XOOPS Project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @license    http://www.fsf.org/copyleft/gpl.html GNU public license | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @link       https://xoops.org XOOPS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @since      1.00 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use \Xoopsmodules\xsitemap; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * @internal {Make sure you PROTECT THIS FILE} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 29 |  | View Code Duplication | if ((!defined('XOOPS_ROOT_PATH')) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     || !($GLOBALS['xoopsUser'] instanceof XoopsUser) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     || !$GLOBALS['xoopsUser']->isAdmin() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     exit('Restricted access' . PHP_EOL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  * Prepares system prior to attempting to install module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  * @param XoopsModule $module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  * @return bool true if ready to install, false if not | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 43 |  |  |  */ | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 44 |  | View Code Duplication | function xoops_module_pre_install_xsitemap(XoopsModule $module) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     $moduleDirName = basename(dirname(__DIR__)); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     /** @var Utility $utilityClass */ | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     $utilityClass    = xsitemap\Utility; | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     if (!class_exists($utilityClass)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         xoops_load('utility', $moduleDirName); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     $xoopsSuccess = $utilityClass::checkVerXoops($module); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     $phpSuccess   = $utilityClass::checkVerPhp($module); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     return $xoopsSuccess && $phpSuccess; | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  * Performs tasks required during installation of the module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  * @param XoopsModule $module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  * @return bool true if installation successful, false if not | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | function xoops_module_install_xsitemap(XoopsModule $module) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     return true; // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** @internal following code removed, it will fail because module not fully loaded/available until | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * after install, module now uses XOOPS preload instead */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     /* | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     //28/08/2009 by urbanspaceman | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     include_once $GLOBALS['xoops']->path("class/tree.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     include_once $GLOBALS['xoops']->path("modules/" . $module->dirname() . "/class/plugin.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     include_once $GLOBALS['xoops']->path("modules/" . $module->dirname() . "/include/functions.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     include_once $GLOBALS['xoops']->path("modules/" . $module->dirname(). "/class/dummy.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     //Create the xsitemap.xml file in the site root | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     $xsitemap_show = Utility::generateSitemap(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     return Utility::saveSitemap($xsitemap_show) ? true : false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  * Prepares system prior to attempting to update module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  * @param XoopsModule $module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  * @return bool true if successfully ready to update module, false if not | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 92 |  | View Code Duplication | function xoops_module_pre_update_xsitemap(XoopsModule $module) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     $moduleDirName = basename(dirname(__DIR__)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     /** @var XsitemapUtility $utilityClass */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     $utilityClass    = \Utility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     if (!class_exists($utilityClass)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         xoops_load('utility', $moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     $xoopsSuccess = $utilityClass::checkVerXoops($module); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     $phpSuccess   = $utilityClass::checkVerPhp($module); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     return $xoopsSuccess && $phpSuccess; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  * Functions to upgrade from previous version of the module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  * @param XoopsModule $module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  * @param int|null        $previousVersion | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  * @return bool true if successfully updated module, false if not | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  * @internal param int $curr_version version number of module currently installed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | function xoops_module_update_xsitemap(XoopsModule $module, $previousVersion = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     /*====================================================================== | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         //---------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         // Remove xSitemap uploads folder (and all subfolders) if they exist | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         //----------------------------------------------------------------* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $utilityClass = ucfirst($moduleDirName) . 'Utility'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         if (!class_exists($utilityClass)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             xoops_load('utility', $moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         // Recursively delete directories | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $xsUploadDir = realpath(XOOPS_UPLOAD_PATH . "/" . $module->dirname()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $success = $utilityClass::rrmdir($xsUploadDir); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         if (true !== $success) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             \Xmf\Language::load('admin', $module->dirname()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |             $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $xsUploadDir)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         return $success; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     ======================================================================*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     $moduleDirName = $module->getVar('dirname'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     $helper      = \Xmf\Module\Helper::getHelper($moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     /** @var XsitemapUtility $utilityClass */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     $utilityClass = ucfirst($moduleDirName) . 'Utility'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     if (!class_exists($utilityClass)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         xoops_load('utility', $moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     //----------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     // Upgrade for Xsitemap < 1.54 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     //----------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     $success = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     $helper->loadLanguage('modinfo'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     $helper->loadLanguage('admin'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 153 |  | View Code Duplication |     if ($previousVersion < 154) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         //---------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         // Remove previous css & images directories since they've been relocated to ./assets | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         // Also remove uploads directories since they're no longer used | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         //---------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         $old_directories = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             $helper->path('css/'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             $helper->path('js/'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             $helper->path('images/'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             XOOPS_UPLOAD_PATH . '/' . $module->dirname() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         foreach ($old_directories as $old_dir) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             $dirInfo = new SplFileInfo($old_dir); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             if ($dirInfo->isDir()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |                 // The directory exists so delete it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |                 if (false === $utilityClass::rrmdir($old_dir)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |                     $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |                     return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |             unset($dirInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         //----------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         // Remove ./template/*.html (except index.html) files since they've | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         // been replaced by *.tpl files | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         // Note: this will also remove /template/xsitemap_style.html since it's no longer used | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         //----------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         $path       = $helper->path('templates/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         $unfiltered = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         $iterator   = new RegexIterator($unfiltered, "/.*\.html/"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         foreach ($iterator as $name => $fObj) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |             if ($fObj->isFile() && ('index.html' !== $fObj->getFilename())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |                 if (false === ($success = unlink($fObj->getPathname()))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |                     $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $fObj->getPathname())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |                     return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         //----------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |         // Now remove a some misc files that were renamed or deprecated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         //----------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $oldFiles = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |             $helper->path('include/install.php'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |             $helper->path('class/module.php'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |             $helper->path('class/menu.php') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         foreach ($oldFiles as $file) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |             if (is_file($file)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |                 if (false === ($delOk = unlink($file))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |                     $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $file)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |                 $success = $success && $delOk; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |     return $success; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |  * Function to perform before module uninstall | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |  * @param XoopsModule $module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |  * @return bool true if successfully executed, false if not | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | function xoops_module_pre_uninstall_xsitemap(XoopsModule $module) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |     return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |  * Function to complete upon module uninstall | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |  * @param XoopsModule $module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |  * @return bool true if successfully executed uninstall of module, false if not | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | function xoops_module_uninstall_xsitemap(XoopsModule $module) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |     //    return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |     $moduleDirName = $module->getVar('dirname'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |     /** @var XsitemapUtility $utilityClass */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |     $helper      = \Xmf\Module\Helper::getHelper($moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |     $utilityClass    =  \Utility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |     if (!class_exists($utilityClass)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |         xoops_load('utility', $moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |     $success = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |     $helper->loadLanguage('admin'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |     //------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |     // Remove xSitemap uploads folder (and all subfolders) if they exist | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |     //------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |     $old_directories = [$GLOBALS['xoops']->path("uploads/{$moduleDirName}")]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |     foreach ($old_directories as $old_dir) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |         $dirInfo = new SplFileInfo($old_dir); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         if ($dirInfo->isDir()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |             // The directory exists so delete it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |             if (false === $utilityClass::rrmdir($old_dir)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |                 $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |                 $success = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |         unset($dirInfo); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |     //------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |     // Remove xsitemap.xml from XOOPS root folder if it exists | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |     //------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |     $xmlfile = $GLOBALS['xoops']->path('xsitemap.xml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     if (is_file($xmlfile)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         if (false === ($delOk = unlink($xmlfile))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |             $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $xmlfile)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |     return $success && $delOk; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 274 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 275 |  |  |  | 
            
                        
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.