Skip to content
Snippets Groups Projects
Commit 193862f0 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #32112 : source format

parent cd44e577
Branches
Tags
4 merge requests!1267Master,!1221Master,!1220Hotline master,!1212Hotline#32112 faille secu explorateur fichiers
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
class CosmoPaths { class CosmoPaths {
protected protected
$_root_dir_name, $_root_dir_name,
$_filesystem; $_filesystem;
...@@ -30,84 +30,84 @@ class CosmoPaths { ...@@ -30,84 +30,84 @@ class CosmoPaths {
} }
public function getBasePath() { public function getBasePath() {
$parts = array_filter(explode('/', $this->getFilePath())); $parts = array_filter(explode('/', $this->getFilePath()));
while ((count($parts)>0) && (end($parts) !== $this->_root_dir_name)) while ((count($parts)>0) && (end($parts) !== $this->_root_dir_name))
array_pop($parts); array_pop($parts);
array_pop($parts); array_pop($parts);
return ($this->isWindowsPath() ? '' : '/') . implode('/', $parts) . '/'; return ($this->isWindowsPath() ? '' : '/') . implode('/', $parts) . '/';
} }
public function isWindowsPath() { public function isWindowsPath() {
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
} }
public function setFileSystem($filesystem) { public function setFileSystem($filesystem) {
$this->_filesystem = $filesystem; $this->_filesystem = $filesystem;
} }
public function getFilesystem() { public function getFilesystem() {
require_once(realpath(dirname(__FILE__)).'/../../../library/Class/Testing/FileSystem.php'); require_once(realpath(dirname(__FILE__)).'/../../../library/Class/Testing/FileSystem.php');
return null == $this->_filesystem return null == $this->_filesystem
? new Class_Testing_FileSystem() ? new Class_Testing_FileSystem()
: $this->_filesystem; : $this->_filesystem;
} }
public function getConfigPath() { public function getConfigPath() {
return $this->getBasePath() . $this->_root_dir_name . '/config.php'; return $this->getBasePath() . $this->_root_dir_name . '/config.php';
} }
public function getBokehConfigPath() { public function getBokehConfigPath() {
return $this->getBasePath() . 'config.ini'; return $this->getBasePath() . 'config.ini';
} }
public function getBaseUrl() { public function getBaseUrl() {
if (!isset($_SERVER['SCRIPT_NAME'])) if (!isset($_SERVER['SCRIPT_NAME']))
return '/' . $this->getSite(); return '/' . $this->getSite();
$parts = array_filter(explode('/', $_SERVER['SCRIPT_NAME'])); $parts = array_filter(explode('/', $_SERVER['SCRIPT_NAME']));
while ((count($parts)>0) && (end($parts) !== $this->_root_dir_name)) while ((count($parts)>0) && (end($parts) !== $this->_root_dir_name))
array_pop($parts); array_pop($parts);
array_pop($parts); array_pop($parts);
return $parts return $parts
? '/' . implode('/', $parts) ? '/' . implode('/', $parts)
: ''; : '';
} }
public function getCosmoBaseUrl() { public function getCosmoBaseUrl() {
return $this->getBaseUrl() . '/' . $this->_root_dir_name . '/'; return $this->getBaseUrl() . '/' . $this->_root_dir_name . '/';
} }
public function getUserfilesPath() { public function getUserfilesPath() {
return $this->getBasePath() . 'userfiles'; return $this->getBasePath() . 'userfiles';
} }
public function getSite() { public function getSite() {
$parts = array_filter(explode('/', $this->getBasePath())); $parts = array_filter(explode('/', $this->getBasePath()));
return array_pop($parts); return array_pop($parts);
} }
protected function getFilePath() { protected function getFilePath() {
if (isset($_SERVER['SCRIPT_FILENAME']) if (isset($_SERVER['SCRIPT_FILENAME'])
&& false !== strpos($_SERVER['SCRIPT_FILENAME'], $this->_root_dir_name)) && false !== strpos($_SERVER['SCRIPT_FILENAME'], $this->_root_dir_name))
return $_SERVER['SCRIPT_FILENAME']; return $_SERVER['SCRIPT_FILENAME'];
$current_path = $this->getFileSystem()->getcwd(); $current_path = $this->getFileSystem()->getcwd();
if (false !== strpos($current_path, $this->_root_dir_name)) if (false !== strpos($current_path, $this->_root_dir_name))
return $current_path; return $current_path;
return realpath(dirname(__FILE__)); return realpath(dirname(__FILE__));
} }
} }
?> ?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment