/** * Récupère la liste des maps en local à partir d'un chemin * * @param string $path -> Le chemin du dossier à lister * @param string $sortBy -> Le tri à faire sur la liste * @return array */ public static function getLocalMapList($directory, $currentPath, $sortBy = null) { global $client; $out = array(); if (is_array($directory)) { if (!empty($directory['files'])) { // Récupération du cache existant $mapsDirectoryPath = self::getMapsDirectoryPath(); $cache = new AdminServCache(); $cacheKey = 'mapslist-' . Str::replaceChars($mapsDirectoryPath . $currentPath); $cacheMaps = $cache->get($cacheKey); // Fichiers $files = array(); foreach ($directory['files'] as $fileName => $fileValues) { $dbExt = File::getDoubleExtension($fileName); if (in_array($dbExt, AdminServConfig::$MAP_EXTENSION)) { $files[$fileName] = $fileValues; } } // Suppression du cache en trop $cacheOverFiles = array_diff_key($cacheMaps, $files); if (!empty($cacheOverFiles)) { foreach ($cacheOverFiles as $fileName => $fileValues) { if (isset($cacheMaps[$fileName])) { unset($cacheMaps[$fileName]); } } $cache->set($cacheKey, $cacheMaps); } // Ajout des fichiers manquant dans le cache $cacheMissingFiles = array_diff_key($files, $cacheMaps); if (!empty($cacheMissingFiles)) { // Path $path = $mapsDirectoryPath . $currentPath; // Création du cache foreach ($cacheMissingFiles as $file => $values) { // Données $processFile = utf8_decode($file); if (SERVER_VERSION_NAME == 'TmForever') { $Gbx = new GBXChallengeFetcher($path . $processFile); } else { $Gbx = new GBXChallMapFetcher(); $Gbx->processFile($path . $processFile); } // Name $filename = $Gbx->name; if ($filename == 'read error') { $filename = str_ireplace('.' . $dbExt, '', $file); } $name = htmlspecialchars($filename, ENT_QUOTES, 'UTF-8'); $out['lst'][$file]['Name'] = TmNick::toHtml($name, 10, true); // Environnement $env = $Gbx->envir; if ($env == 'read error') { $env = null; } if ($env == 'Speed') { $env = 'Desert'; } else { if ($env == 'Alpine') { $env = 'Snow'; } } $out['lst'][$file]['Environment'] = $env; // Autres $out['lst'][$file]['FileName'] = $currentPath . $file; $uid = $Gbx->uid; if ($uid == 'read error') { $uid = null; } $out['lst'][$file]['UId'] = $uid; $author = $Gbx->author; if ($author == 'read error') { $author = null; } $out['lst'][$file]['Author'] = $author; $out['lst'][$file]['Recent'] = $values['recent']; // MapType $mapType = $Gbx->mapType; if ($mapType == null && $Gbx->typeName != null) { $mapType = $Gbx->typeName; } $out['lst'][$file]['Type']['Name'] = self::formatScriptName($mapType); $out['lst'][$file]['Type']['FullName'] = $mapType; } // Mise à jour du cache if (!empty($cacheMaps)) { $out['lst'] = array_merge($cacheMaps, $out['lst']); } $cache->set($cacheKey, $out['lst']); } else { $out['lst'] = $cacheMaps; } // Maps on server? $currentMapsListUId = null; if (AdminServConfig::LOCAL_GET_MAPS_ON_SERVER) { $currentMapsListUId = self::getMapListField('UId'); } foreach ($out['lst'] as &$file) { $file['OnServer'] = false; if ($currentMapsListUId) { if (in_array($file['UId'], $currentMapsListUId)) { $file['OnServer'] = true; } } } // Nombre de maps $out += self::getNbMaps($out); if ($out['nbm']['count'] == 0) { $out['lst'] = Utils::t('No map'); } else { // TRIS if ($sortBy != null) { switch ($sortBy) { case 'filename': uasort($out['lst'], 'AdminServSort::sortByFileName'); break; case 'name': uasort($out['lst'], 'AdminServSort::sortByName'); break; case 'env': uasort($out['lst'], 'AdminServSort::sortByEnviro'); break; case 'type': uasort($out['lst'], 'AdminServSort::sortByType'); break; case 'author': uasort($out['lst'], 'AdminServSort::sortByAuthor'); break; } } } } else { $out += self::getNbMaps($out); $out['lst'] = Utils::t('No map'); } } else { $out = $directory; } return $out; }
$newPath = addslashes($_POST['optionFolderHiddenFieldValue']); if ($newPath == '.') { $newPath = $data['mapsDirectoryPath']; } $newPath .= basename($args['directory']) . '/'; $newPathFromMapsPath = str_replace($data['mapsDirectoryPath'], '', $newPath); if ($newPathFromMapsPath) { $newPathFromMapsPath = '&d=' . $newPathFromMapsPath; } if (($result = Folder::rename($data['mapsDirectoryPath'] . $args['directory'], $newPath)) !== true) { AdminServ::error(Utils::t('Unable to move the folder') . ' : ' . $args['directory'] . ' (' . $result . ')'); } else { AdminServLogs::add('action', 'Move folder: ' . $args['directory'] . ' to ' . $newPathFromMapsPath); Utils::redirection(false, '?p=' . USER_PAGE . $newPathFromMapsPath); } } else { if (isset($_POST['optionFolderHiddenFieldAction']) && $_POST['optionFolderHiddenFieldAction'] == 'delete') { if (($result = Folder::delete($data['mapsDirectoryPath'] . $args['directory'])) !== true) { AdminServ::error(Utils::t('Unable to delete the folder') . ' : ' . $args['directory'] . ' (' . $result . ')'); } else { // Clean cache $cache = new AdminServCache(); $cacheKey = 'mapslist-' . Str::replaceChars($data['mapsDirectoryPath'] . $args['directory']); $cache->delete($cacheKey); AdminServLogs::add('action', 'Delete folder: ' . $args['directory']); Utils::redirection(false, '?p=' . USER_PAGE); } } } } }