Skip to content
Snippets Groups Projects
Commit 382f2230 authored by llaffont's avatar llaffont
Browse files

Refactoring paths computation

parent 0ec87ba2
Branches
Tags
No related merge requests found
......@@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
xdebug_break();
if(isset($_REQUEST["admin_login"]))
{
$user = trim($_REQUEST["admin_login"]);
......
......@@ -18,7 +18,11 @@ define('COM_ORPHEE', 8);
define('COM_MICROBIB', 9);
define('COM_BIBLIXNET', 10);
define('COM_DYNIX', 11);
xdebug_break();
$basePath = dirname(realpath(__FILE__));
set_include_path(get_include_path()
. PATH_SEPARATOR . $basePath
. PATH_SEPARATOR . $basePath . '/classes/');
if (!function_exists('xdebug_break')) {
function xdebug_break(){};
......@@ -26,16 +30,18 @@ if (!function_exists('xdebug_break')) {
date_default_timezone_set('Europe/Paris');
require_once 'classe_cosmopaths.php';
$cosmo_path = new CosmoPaths();
$argc = isset($argc) ? $argc : 0;
if ($argc < 3) {
if (isset($_SERVER['SERVER_ADDR']) and $_SERVER['SERVER_ADDR'] != "127.0.0.1" and $_SERVER['SERVER_ADDR'] != "::1")
{
$site= "/" . substr($_SERVER['SCRIPT_NAME'], 1, strpos($_SERVER['SCRIPT_NAME'], "/" . APPLI . "/") -1) . "/" ;
$cfgfile= COSMOPATH . $site . APPLI . "/config.php" ;
chdir(COSMOPATH . $site);
define('BASE_URL', $site);
define('USERFILESPATH', COSMOPATH . $site . 'userfiles');
$site = '/' . $cosmo_path->getSite() . '/';
$cfgfile = $cosmo_path->getConfigPath();
chdir($cosmo_path->getBasePath());
define('BASE_URL', $cosmo_path->getBaseUrl());
define('USERFILESPATH', $cosmo_path->getUserfilesPath());
}
else
{
......@@ -60,10 +66,6 @@ if (!isset($cfgfile) || !file_exists($cfgfile)) {
define("URL_BASE","http://" . $_SERVER["HTTP_HOST"] . $site . APPLI . "/");
define("URL_IMG", URL_BASE ."images/");
// Includes
set_include_path(get_include_path()
.PATH_SEPARATOR.dirname(realpath(__FILE__))
.PATH_SEPARATOR.dirname(realpath(__FILE__))."/classes/");
require_once("fonctions/fonctions_base.php");
require_once("fonctions/string.php");
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* AFI-OPAC 2.0 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class CosmoPaths {
const COSMO_DIR_NAME = 'cosmogramme';
public function getBasePath() {
$parts = array_filter(explode('/', $_SERVER['SCRIPT_FILENAME']));
while ((count($parts)>0) && (end($parts) !== self::COSMO_DIR_NAME))
array_pop($parts);
array_pop($parts);
return '/' . implode('/', $parts) . '/';
}
public function getConfigPath() {
return $this->getBasePath() . self::COSMO_DIR_NAME . '/config.php';
}
public function getBaseUrl() {
return str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->getBasePath());
}
public function getUserfilesPath() {
return $this->getBasePath() . 'userfiles';
}
public function getSite() {
return array_pop(array_filter(explode('/', $this->getBasePath())));
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* AFI-OPAC 2.0 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once 'classe_cosmopaths.php';
class CosmoPathsTest extends PHPUnit_Framework_TestCase {
protected $_cosmo_paths;
public function setUp() {
parent::setUp();
$_SERVER = ['SCRIPT_FILENAME' => '/var/www/htdocs/bokeh.fr/cosmogramme/index.php',
'DOCUMENT_ROOT' => '/var/www/htdocs'];
$this->_cosmo_paths = new CosmoPaths();
}
public function tearDown() {
unset($_SERVER['SCRIPT_FILENAME']);
unset($_SERVER['DOCUMENT_ROOT']);
}
/** @test */
public function basePathShouldEndWithDomainBokehDotFr() {
$this->assertEquals('bokeh.fr/', substr($this->_cosmo_paths->getBasePath(), -9));
}
/** @test */
public function configPathShouldEndWithBokehDotFrCosmogrammeConfigDotPhp() {
$this->assertEquals('bokeh.fr/cosmogramme/config.php', substr($this->_cosmo_paths->getConfigPath(), -31));
}
/** @test */
public function baseUrlShouldBeBokehDotFr() {
$this->assertEquals('/bokeh.fr/', $this->_cosmo_paths->getBaseUrl());
}
/** @test */
public function siteShouldBeBokehDotFr() {
$this->assertEquals('bokeh.fr', $this->_cosmo_paths->getSite());
}
/** @test */
public function userFilesPathShouldEndWithBokehDotFrSlashUserfiles() {
$this->assertEquals('bokeh.fr/userfiles', substr($this->_cosmo_paths->getUserfilesPath(), -18));
}
}
?>
\ 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