XoopsModules25x /
xsitemap
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 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 | * Module: xsitemap |
||||
| 14 | * |
||||
| 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 | Helper, |
||||
| 25 | Utility |
||||
| 26 | }; |
||||
| 27 | /** @var Helper $helper */ |
||||
| 28 | /** @var Utility $utility */ |
||||
| 29 | |||||
| 30 | /** |
||||
| 31 | * @internal {Make sure you PROTECT THIS FILE} |
||||
| 32 | */ |
||||
| 33 | if ((!defined('XOOPS_ROOT_PATH')) |
||||
| 34 | || !($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
||||
| 35 | || !$GLOBALS['xoopsUser']->isAdmin()) { |
||||
| 36 | exit('Restricted access' . PHP_EOL); |
||||
| 37 | } |
||||
| 38 | /** |
||||
| 39 | * Prepares system prior to attempting to install module |
||||
| 40 | * |
||||
| 41 | * @param \XoopsModule $module |
||||
| 42 | * |
||||
| 43 | * @return bool true if ready to install, false if not |
||||
| 44 | */ |
||||
| 45 | function xoops_module_pre_install_xsitemap(\XoopsModule $module) |
||||
| 46 | { |
||||
| 47 | $moduleDirName = \basename(\dirname(__DIR__)); |
||||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||||
| 48 | $utility = new Utility(); |
||||
| 49 | $xoopsSuccess = $utility::checkVerXoops($module); |
||||
| 50 | $phpSuccess = $utility::checkVerPhp($module); |
||||
| 51 | return $xoopsSuccess && $phpSuccess; |
||||
| 52 | } |
||||
| 53 | |||||
| 54 | /** |
||||
| 55 | * Performs tasks required during installation of the module |
||||
| 56 | * |
||||
| 57 | * @param \XoopsModule $module |
||||
| 58 | * |
||||
| 59 | * @return bool true if installation successful, false if not |
||||
| 60 | */ |
||||
| 61 | function xoops_module_install_xsitemap(\XoopsModule $module) |
||||
|
0 ignored issues
–
show
The parameter
$module is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 62 | { |
||||
| 63 | return true; |
||||
| 64 | /** @internal following code removed, it will fail because module not fully loaded/available until |
||||
| 65 | * after install, module now uses XOOPS preload instead */ |
||||
| 66 | /* |
||||
| 67 | //28/08/2009 by urbanspaceman |
||||
| 68 | require_once $GLOBALS['xoops']->path("class/tree.php"); |
||||
| 69 | require_once $GLOBALS['xoops']->path("modules/" . $module->dirname() . "/class/plugin.php"); |
||||
| 70 | require_once $GLOBALS['xoops']->path("modules/" . $module->dirname() . "/include/functions.php"); |
||||
| 71 | require_once $GLOBALS['xoops']->path("modules/" . $module->dirname(). "/class/DummyObject.php"); |
||||
| 72 | |||||
| 73 | //Create the xsitemap.xml file in the site root |
||||
| 74 | $xsitemap_show = Utility::generateSitemap(); |
||||
| 75 | return Utility::saveSitemap($xsitemap_show) ? true : false; |
||||
| 76 | */ |
||||
| 77 | } |
||||
| 78 | |||||
| 79 | /** |
||||
| 80 | * Prepares system prior to attempting to update module |
||||
| 81 | * |
||||
| 82 | * @param \XoopsModule $module |
||||
| 83 | * |
||||
| 84 | * @return bool true if successfully ready to update module, false if not |
||||
| 85 | */ |
||||
| 86 | function xoops_module_pre_update_xsitemap(\XoopsModule $module) |
||||
| 87 | { |
||||
| 88 | $moduleDirName = \basename(\dirname(__DIR__)); |
||||
|
0 ignored issues
–
show
|
|||||
| 89 | $helper = Helper::getInstance(); |
||||
|
0 ignored issues
–
show
|
|||||
| 90 | $utility = new Utility(); |
||||
| 91 | $xoopsSuccess = $utility::checkVerXoops($module); |
||||
| 92 | $phpSuccess = $utility::checkVerPhp($module); |
||||
| 93 | return $xoopsSuccess && $phpSuccess; |
||||
| 94 | } |
||||
| 95 | |||||
| 96 | /** |
||||
| 97 | * Functions to upgrade from previous version of the module |
||||
| 98 | * |
||||
| 99 | * @param \XoopsModule $module |
||||
| 100 | * @param int|null $previousVersion |
||||
| 101 | * @return bool true if successfully updated module, false if not |
||||
| 102 | * @internal param int $curr_version version number of module currently installed |
||||
| 103 | */ |
||||
| 104 | function xoops_module_update_xsitemap(\XoopsModule $module, $previousVersion = null) |
||||
| 105 | { |
||||
| 106 | /*====================================================================== |
||||
| 107 | //---------------------------------------------------------------- |
||||
| 108 | // Remove xSitemap uploads folder (and all subfolders) if they exist |
||||
| 109 | //----------------------------------------------------------------* |
||||
| 110 | $utility = new Utility(); |
||||
| 111 | if (!class_exists($utility)) { |
||||
| 112 | xoops_load('utility', $moduleDirName); |
||||
| 113 | } |
||||
| 114 | |||||
| 115 | // Recursively delete directories |
||||
| 116 | $xsUploadDir = realpath(XOOPS_UPLOAD_PATH . "/" . $module->dirname()); |
||||
| 117 | $success = $utility::rrmdir($xsUploadDir); |
||||
| 118 | if (true !== $success) { |
||||
| 119 | \Xmf\Language::load('admin', $module->dirname()); |
||||
| 120 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $xsUploadDir)); |
||||
| 121 | } |
||||
| 122 | return $success; |
||||
| 123 | ======================================================================*/ |
||||
| 124 | $moduleDirName = \basename(\dirname(__DIR__)); |
||||
| 125 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); |
||||
|
0 ignored issues
–
show
|
|||||
| 126 | |||||
| 127 | $helper = Helper::getInstance(); |
||||
| 128 | $utility = new Utility(); |
||||
| 129 | |||||
| 130 | //----------------------------------------------------------------------- |
||||
| 131 | // Upgrade for Xsitemap < 1.54 |
||||
| 132 | //----------------------------------------------------------------------- |
||||
| 133 | $success = true; |
||||
| 134 | $helper->loadLanguage('modinfo'); |
||||
| 135 | $helper->loadLanguage('admin'); |
||||
| 136 | if ($previousVersion < 154) { |
||||
| 137 | //---------------------------------------------------------------- |
||||
| 138 | // Remove previous css & images directories since they've been relocated to ./assets |
||||
| 139 | // Also remove uploads directories since they're no longer used |
||||
| 140 | //---------------------------------------------------------------- |
||||
| 141 | $old_directories = [ |
||||
| 142 | $helper->path('css/'), |
||||
| 143 | $helper->path('js/'), |
||||
| 144 | $helper->path('images/'), |
||||
| 145 | XOOPS_UPLOAD_PATH . '/' . $module->dirname(), |
||||
| 146 | ]; |
||||
| 147 | foreach ($old_directories as $old_dir) { |
||||
| 148 | $dirInfo = new \SplFileInfo($old_dir); |
||||
| 149 | if ($dirInfo->isDir()) { |
||||
| 150 | // The directory exists so delete it |
||||
| 151 | if (false === $utility::rrmdir($old_dir)) { |
||||
| 152 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir)); |
||||
| 153 | return false; |
||||
| 154 | } |
||||
| 155 | } |
||||
| 156 | unset($dirInfo); |
||||
| 157 | } |
||||
| 158 | //----------------------------------------------------------------------- |
||||
| 159 | // Remove ./template/*.html (except index.html) files since they've |
||||
| 160 | // been replaced by *.tpl files |
||||
| 161 | // Note: this will also remove /template/xsitemap_style.html since it's no longer used |
||||
| 162 | //----------------------------------------------------------------------- |
||||
| 163 | $path = $helper->path('templates/'); |
||||
| 164 | $unfiltered = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); |
||||
| 165 | $iterator = new RegexIterator($unfiltered, '/.*\.html/'); |
||||
| 166 | foreach ($iterator as $name => $fObj) { |
||||
| 167 | if ($fObj->isFile() && ('index.html' !== $fObj->getFilename())) { |
||||
| 168 | if (false === ($success = unlink($fObj->getPathname()))) { |
||||
| 169 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $fObj->getPathname())); |
||||
| 170 | return false; |
||||
| 171 | } |
||||
| 172 | } |
||||
| 173 | } |
||||
| 174 | //----------------------------------------------------------------------- |
||||
| 175 | // Now remove a some misc files that were renamed or deprecated |
||||
| 176 | //----------------------------------------------------------------------- |
||||
| 177 | $oldFiles = [ |
||||
| 178 | $helper->path('include/install.php'), |
||||
| 179 | $helper->path('class/module.php'), |
||||
| 180 | $helper->path('class/menu.php'), |
||||
| 181 | ]; |
||||
| 182 | foreach ($oldFiles as $file) { |
||||
| 183 | if (is_file($file)) { |
||||
| 184 | if (false === ($delOk = unlink($file))) { |
||||
| 185 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $file)); |
||||
| 186 | } |
||||
| 187 | $success = $success && $delOk; |
||||
| 188 | } |
||||
| 189 | } |
||||
| 190 | } |
||||
| 191 | return $success; |
||||
| 192 | } |
||||
| 193 | |||||
| 194 | /** |
||||
| 195 | * Function to perform before module uninstall |
||||
| 196 | * |
||||
| 197 | * @param \XoopsModule $module |
||||
| 198 | * |
||||
| 199 | * @return bool true if successfully executed, false if not |
||||
| 200 | */ |
||||
| 201 | function xoops_module_pre_uninstall_xsitemap(\XoopsModule $module) |
||||
|
0 ignored issues
–
show
The parameter
$module is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 202 | { |
||||
| 203 | return true; |
||||
| 204 | } |
||||
| 205 | |||||
| 206 | /** |
||||
| 207 | * Function to complete upon module uninstall |
||||
| 208 | * |
||||
| 209 | * @param \XoopsModule $module |
||||
| 210 | * |
||||
| 211 | * @return bool true if successfully executed uninstall of module, false if not |
||||
| 212 | */ |
||||
| 213 | function xoops_module_uninstall_xsitemap(\XoopsModule $module) |
||||
| 214 | { |
||||
| 215 | // return true; |
||||
| 216 | $moduleDirName = $module->getVar('dirname'); |
||||
| 217 | $helper = Helper::getInstance(); |
||||
| 218 | $utility = new Utility(); |
||||
| 219 | $delOk = false; |
||||
| 220 | // if (!class_exists($utility)) { |
||||
| 221 | // xoops_load('utility', $moduleDirName); |
||||
| 222 | // } |
||||
| 223 | $success = true; |
||||
| 224 | $helper->loadLanguage('admin'); |
||||
| 225 | //------------------------------------------------------------------ |
||||
| 226 | // Remove xSitemap uploads folder (and all subfolders) if they exist |
||||
| 227 | //------------------------------------------------------------------ |
||||
| 228 | $old_directories = [$GLOBALS['xoops']->path("uploads/{$moduleDirName}")]; |
||||
| 229 | foreach ($old_directories as $old_dir) { |
||||
| 230 | $dirInfo = new \SplFileInfo($old_dir); |
||||
| 231 | if ($dirInfo->isDir()) { |
||||
| 232 | // The directory exists so delete it |
||||
| 233 | if (false === $utility::rrmdir($old_dir)) { |
||||
| 234 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir)); |
||||
| 235 | $success = false; |
||||
| 236 | } |
||||
| 237 | } |
||||
| 238 | unset($dirInfo); |
||||
| 239 | } |
||||
| 240 | //------------------------------------------------------------------ |
||||
| 241 | // Remove xsitemap.xml from XOOPS root folder if it exists |
||||
| 242 | //------------------------------------------------------------------ |
||||
| 243 | $xmlfile = $GLOBALS['xoops']->path('xsitemap.xml'); |
||||
| 244 | if (is_file($xmlfile)) { |
||||
| 245 | if (false === ($delOk = unlink($xmlfile))) { |
||||
| 246 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $xmlfile)); |
||||
| 247 | } |
||||
| 248 | } |
||||
| 249 | return $success && $delOk; |
||||
| 250 | } |
||||
| 251 |