Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 58 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| tao_install_utils_System | |
0.00% |
0 / 58 |
|
0.00% |
0 / 5 |
650 | |
0.00% |
0 / 1 |
| isTAOInDebugMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| getInfos | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| isTAOInstalled | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| isTAOUpToDate | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
110 | |||
| getAvailableLocales | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
110 | |||
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | /** |
| 28 | * This class aims at providing utilities about the current installation from |
| 29 | * the host system and its filesystem, including the tao platform directory. |
| 30 | * |
| 31 | * @author Somsack Sipasseuth <somsack.sipasseuth@tudor.lu> |
| 32 | * @author Jerome Bogaerts <jerome.bogaerts@tudor.lu> |
| 33 | * @package tao |
| 34 | |
| 35 | */ |
| 36 | class tao_install_utils_System |
| 37 | { |
| 38 | /** |
| 39 | * Checks if system is installed in Debug mode. |
| 40 | * |
| 41 | * @return bool |
| 42 | */ |
| 43 | public static function isTAOInDebugMode() |
| 44 | { |
| 45 | return defined('DEBUG_MODE') && DEBUG_MODE; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get informations on the host system. |
| 50 | * |
| 51 | * @return array where key/values are 'folder' as string, 'host' as string, 'https' as boolean. |
| 52 | */ |
| 53 | public static function getInfos() |
| 54 | { |
| 55 | |
| 56 | |
| 57 | // subfolder shall be detected as /SUBFLODERS/tao/install/index.php so we remove the "/extension/module/action" |
| 58 | // part: |
| 59 | $subfolder = $_SERVER['REQUEST_URI']; |
| 60 | $subfolder = preg_replace('/\/(([^\/]*)\/){2}([^\/]*)$/', '', $subfolder); |
| 61 | $subfolder = preg_replace('/^\//', '', $subfolder); |
| 62 | |
| 63 | return [ |
| 64 | 'folder' => $subfolder, |
| 65 | 'host' => $_SERVER['HTTP_HOST'], |
| 66 | 'https' => ($_SERVER['SERVER_PORT'] == 443) |
| 67 | ]; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Check if TAO is already installed. |
| 72 | * |
| 73 | * @return boolean |
| 74 | */ |
| 75 | public static function isTAOInstalled($path = '') |
| 76 | { |
| 77 | $path = (empty($path)) ? __DIR__ . '/../../../config' : rtrim($path, '/\\'); |
| 78 | $config = "${path}/generis.conf.php"; |
| 79 | return file_exists($config); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Check if TAO is already up to date. |
| 84 | * |
| 85 | * @return boolean |
| 86 | */ |
| 87 | public static function isTAOUpToDate($path = '') |
| 88 | { |
| 89 | $path = (empty($path)) ? __DIR__ . '/../../../config' : rtrim($path, '/\\'); |
| 90 | $generisConf = "${path}/generis.conf.php"; |
| 91 | |
| 92 | if (!is_readable($generisConf)) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | include_once($generisConf); |
| 97 | $installationConf = "${path}/generis/installation.conf.php"; |
| 98 | |
| 99 | if (!is_readable($installationConf)) { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | $conf = include_once($installationConf); |
| 104 | $extIterator = is_array($conf) ? $conf : $conf->getConfig(); |
| 105 | |
| 106 | foreach ($extIterator as $extName => $ext) { |
| 107 | $manifestPath = __DIR__ . "/../../../${extName}/manifest.php"; |
| 108 | |
| 109 | if (!is_readable($manifestPath)) { |
| 110 | return false; |
| 111 | } else { |
| 112 | $manifest = include_once($manifestPath); |
| 113 | |
| 114 | if ( |
| 115 | (!isset($ext["installed"])) |
| 116 | || (!isset($manifest["version"])) |
| 117 | || ($ext["installed"] !== $manifest["version"]) |
| 118 | ) { |
| 119 | return false; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Returns the availables locales (languages or cultures) of the tao platform |
| 129 | * on the basis of a particular locale folder e.g. the /locales folder of the tao |
| 130 | * meta-extension. |
| 131 | * |
| 132 | * A locale will be included in the resulting array only if a valid 'lang.rdf' |
| 133 | * file is found. |
| 134 | * |
| 135 | * @param string $path The location of the /locales folder to inspect. |
| 136 | * @return array An array of strings where keys are the language code and values the language label. |
| 137 | * @throws UnexpectedValueException |
| 138 | */ |
| 139 | public static function getAvailableLocales($path) |
| 140 | { |
| 141 | $locales = @scandir($path); |
| 142 | $returnValue = []; |
| 143 | |
| 144 | if ($locales !== false) { |
| 145 | foreach ($locales as $l) { |
| 146 | if ($l[0] !== '.') { |
| 147 | // We found a locale folder. Does it contain a valid lang.rdf file? |
| 148 | $langFilePath = $path . '/' . $l . '/lang.rdf'; |
| 149 | if (is_file($langFilePath) && is_readable($langFilePath)) { |
| 150 | try { |
| 151 | $doc = new DOMDocument('1.0', 'UTF-8'); |
| 152 | $doc->load($langFilePath); |
| 153 | $xpath = new DOMXPath($doc); |
| 154 | $xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); |
| 155 | $xpath->registerNamespace('rdfs', 'http://www.w3.org/2000/01/rdf-schema#'); |
| 156 | $expectedUri = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $l; |
| 157 | |
| 158 | // Look for an rdf:value equals to the folder name. |
| 159 | $rdfValues = $xpath->query("//rdf:Description[@rdf:about='${expectedUri}']/rdf:value"); |
| 160 | if ($rdfValues->length == 1 && $rdfValues->item(0)->nodeValue == $l) { |
| 161 | $key = $l; |
| 162 | |
| 163 | $rdfsLabels = $xpath->query( |
| 164 | "//rdf:Description[@rdf:about='${expectedUri}']/rdfs:label[@xml:lang='en-US']" |
| 165 | ); |
| 166 | if ($rdfsLabels->length == 1) { |
| 167 | $value = $rdfsLabels->item(0)->nodeValue; |
| 168 | $returnValue[$l] = $value; |
| 169 | } |
| 170 | } |
| 171 | } catch (DOMException $e) { |
| 172 | // Invalid lang.rdf file, we continue to look for other ones. |
| 173 | continue; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | return $returnValue; |
| 180 | } else { |
| 181 | throw new UnexpectedValueException("Unable to list locales in '${path}'."); |
| 182 | } |
| 183 | } |
| 184 | } |