Commit 12b5705f authored by sept_7's avatar sept_7

[ENH] auto detect the tikiroot and tikipath, even if called from php script...

[ENH] auto detect the tikiroot and tikipath, even if called from php script not in the Tiki root directory.

This alows to split the code in subdirs for features or extensions.
parent a39eb3ad
<?php
// $Header: /cvsroot/tikiwiki/tiki/lib/setup/absolute_urls.php,v 1.1 2007-10-06 15:18:43 nyloth Exp $
// $Header: /cvsroot/tikiwiki/tiki/lib/setup/absolute_urls.php,v 1.2 2007-10-10 13:30:52 sept_7 Exp $
// Copyright (c) 2002-2005, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for
......@@ -14,16 +14,29 @@ if (strpos($_SERVER['SCRIPT_NAME'],'tiki-setup.php')!=FALSE) {
/* Automatically set params used for absolute URLs - BEGIN */
$tikipath = dirname($_SERVER['SCRIPT_FILENAME']);
if ( substr($tikipath,-1,1) != '/' ) $tikipath .= '/';
$tmp = dirname(str_replace(dirname(dirname(dirname(__FILE__))),'',$_SERVER['SCRIPT_FILENAME']));
if ($tmp != '/') {
$dir_level = substr_count($tmp,"/");
} else {
$dir_level = 0;
}
unset($tmp);
$tikiroot = dirname($_SERVER['PHP_SELF']);
$tikipath = dirname($_SERVER['SCRIPT_FILENAME']);
if ($dir_level > 0) {
$tikiroot = preg_replace('#(/[^/]+){'.$dir_level.'}$#','',$tikiroot);
$tikipath = preg_replace('#(/[^/]+){'.$dir_level.'}$#','',$tikipath);
chdir(join('../',array_fill(0,$dir_level+1,'')));
}
if ( substr($tikiroot,-1,1) != '/' ) $tikiroot .= '/';
if ( substr($tikipath,-1,1) != '/' ) $tikipath .= '/';
if ( $https_port == 443 ) $https_port = '';
if ( $http_port == 80 ) $http_port = '';
// Detect if we are in HTTPS / SSL mode.
//
// Since $_SERVER['HTTPS'] will not be set on some installation, we may need to check port also.
......@@ -48,19 +61,6 @@ $base_url = $url_scheme.'://'.$url_host.(($url_port!='')?":$url_port":'').$url_p
$base_url_http = 'http://'.$url_host.(($http_port!='')?":$http_port":'').$url_path;
$base_url_https = 'https://'.$url_host.(($https_port!='')?":$https_port":'').$url_path;
$smarty->assign('tikipath', $tikipath);
$smarty->assign('tikiroot', $tikiroot);
$smarty->assign('url_scheme', $url_scheme);
$smarty->assign('url_host', $url_host);
$smarty->assign('url_port', $url_port);
$smarty->assign('url_path', $url_path);
$smarty->assign('base_host', $base_host);
$smarty->assign('base_url', $base_url);
$smarty->assign('base_url_http', $base_url_http);
$smarty->assign('base_url_https', $base_url_https);
// SSL options
if ( isset($_REQUEST['stay_in_ssl_mode']) ) {
......@@ -73,7 +73,3 @@ if ( isset($_REQUEST['stay_in_ssl_mode']) ) {
// Show the 'Stay in SSL mode' checkbox only if we are already in HTTPS
$show_stay_in_ssl_mode = $https_mode ? 'y' : 'n';
$smarty->assign('show_stay_in_ssl_mode', $show_stay_in_ssl_mode);
$smarty->assign('stay_in_ssl_mode', $stay_in_ssl_mode);
<?php
// $Header: /cvsroot/tikiwiki/tiki/tiki-setup.php,v 1.467 2007-10-08 14:43:40 sylvieg Exp $
// $Header: /cvsroot/tikiwiki/tiki/tiki-setup.php,v 1.468 2007-10-10 13:30:51 sept_7 Exp $
// Copyright (c) 2002-2005, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for
......@@ -12,6 +12,8 @@ if (strpos($_SERVER['SCRIPT_NAME'],'tiki-setup.php')!=FALSE) {
exit;
}
require_once('lib/setup/absolute_urls.php');
require_once('lib/init/initlib.php');
if ( ! isset($_SESSION['votes']) ) $_SESSION['votes'] = array();
if ( ! isset($_SESSION['user']) ) $_SESSION['user'] = array();
......@@ -25,6 +27,8 @@ require_once('lib/setup/tikisetup.class.php');
TikiSetup::prependIncludePath('lib');
TikiSetup::prependIncludePath('lib/pear');
//echo ini_get('include_path');
require_once('lib/setup/timer.class.php');
$tiki_timer = new timer();
$tiki_timer->start();
......@@ -104,3 +108,19 @@ $smarty->assign('uses_tabs', 'n');
$smarty->assign('uses_jscalendar', 'n');
$smarty->assign('uses_phplayers', 'n');
$smarty->assign('wiki_extras', 'n');
$smarty->assign('tikipath', $tikipath);
$smarty->assign('tikiroot', $tikiroot);
$smarty->assign('url_scheme', $url_scheme);
$smarty->assign('url_host', $url_host);
$smarty->assign('url_port', $url_port);
$smarty->assign('url_path', $url_path);
$smarty->assign('base_host', $base_host);
$smarty->assign('base_url', $base_url);
$smarty->assign('base_url_http', $base_url_http);
$smarty->assign('base_url_https', $base_url_https);
$smarty->assign('show_stay_in_ssl_mode', $show_stay_in_ssl_mode);
$smarty->assign('stay_in_ssl_mode', $stay_in_ssl_mode);
Markdown is supported
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