* @author Jerome Bogaerts * @package tao */ class tao_install_utils_System { /** * Checks if system is installed in Debug mode. * * @return bool */ public static function isTAOInDebugMode() { return defined('DEBUG_MODE') && DEBUG_MODE; } /** * Get informations on the host system. * * @return array where key/values are 'folder' as string, 'host' as string, 'https' as boolean. */ public static function getInfos() { //subfolder shall be detected as /SUBFLODERS/tao/install/index.php so we remove the "/extension/module/action" part: $subfolder = $_SERVER['REQUEST_URI']; $subfolder = preg_replace('/\/(([^\/]*)\/){2}([^\/]*)$/', '', $subfolder); $subfolder = preg_replace('/^\//', '', $subfolder); return [ 'folder' => $subfolder, 'host' => $_SERVER['HTTP_HOST'], 'https' => ($_SERVER['SERVER_PORT'] == 443) ]; } /** * Check if TAO is already installed. * * @return boolean */ public static function isTAOInstalled($path = '') { $path = (empty($path)) ? __DIR__ . '/../../../config' : rtrim($path, '/\\'); $config = "${path}/generis.conf.php"; return file_exists($config); } /** * Check if TAO is already up to date. * * @return boolean */ public static function isTAOUpToDate($path = '') { $path = (empty($path)) ? __DIR__ . '/../../../config' : rtrim($path, '/\\'); $generisConf = "${path}/generis.conf.php"; if (!is_readable($generisConf)) { return false; } include_once($generisConf); $installationConf = "${path}/generis/installation.conf.php"; if (!is_readable($installationConf)) { return false; } $conf = include_once($installationConf); $extIterator = is_array($conf) ? $conf : $conf->getConfig(); foreach ($extIterator as $extName => $ext) { $manifestPath = __DIR__ . "/../../../${extName}/manifest.php"; if (!is_readable($manifestPath)) { return false; } else { $manifest = include_once($manifestPath); if ((!isset($ext["installed"])) || (!isset($manifest["version"])) || ($ext["installed"] !== $manifest["version"])) { return false; } } } return true; } /** * Returns the availables locales (languages or cultures) of the tao platform * on the basis of a particular locale folder e.g. the /locales folder of the tao * meta-extension. * * A locale will be included in the resulting array only if a valid 'lang.rdf' * file is found. * * @param string $path The location of the /locales folder to inspect. * @return array An array of strings where keys are the language code and values the language label. * @throws UnexpectedValueException */ public static function getAvailableLocales($path) { $locales = @scandir($path); $returnValue = []; if ($locales !== false) { foreach ($locales as $l) { if ($l[0] !== '.') { // We found a locale folder. Does it contain a valid lang.rdf file? $langFilePath = $path . '/' . $l . '/lang.rdf'; if (is_file($langFilePath) && is_readable($langFilePath)) { try { $doc = new DOMDocument('1.0', 'UTF-8'); $doc->load($langFilePath); $xpath = new DOMXPath($doc); $xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); $xpath->registerNamespace('rdfs', 'http://www.w3.org/2000/01/rdf-schema#'); $expectedUri = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $l; // Look for an rdf:value equals to the folder name. $rdfValues = $xpath->query("//rdf:Description[@rdf:about='${expectedUri}']/rdf:value"); if ($rdfValues->length == 1 && $rdfValues->item(0)->nodeValue == $l) { $key = $l; $rdfsLabels = $xpath->query("//rdf:Description[@rdf:about='${expectedUri}']/rdfs:label[@xml:lang='en-US']"); if ($rdfsLabels->length == 1) { $value = $rdfsLabels->item(0)->nodeValue; $returnValue[$l] = $value; } } } catch (DOMException $e) { // Invalid lang.rdf file, we continue to look for other ones. continue; } } } } return $returnValue; } else { throw new UnexpectedValueException("Unable to list locales in '${path}'."); } } }