2007-07-19 12:40:28 +02:00
|
|
|
#!/usr/bin/php5
|
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-02-25 03:10:37 +01:00
|
|
|
* File similar to main.php designed for command-line scripts
|
|
|
|
*
|
|
|
|
* This file lets you execute Sapphire requests from the command-line. The URL is passed as the first argument to the scripts.
|
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage core
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-01-09 05:18:36 +01:00
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
if(isset($_SERVER['argv'][2])) $_SERVER['HTTP_HOST'] = $_SERVER['argv'][2];
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
|
|
|
|
chdir(dirname($_SERVER['SCRIPT_FILENAME']));
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Include Sapphire's core code
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
require_once("core/Core.php");
|
|
|
|
|
|
|
|
header("Content-type: text/html; charset=\"utf-8\"");
|
|
|
|
if(function_exists('mb_http_output')) {
|
|
|
|
mb_http_output('UTF-8');
|
|
|
|
mb_internal_encoding('UTF-8');
|
|
|
|
}
|
|
|
|
|
|
|
|
// figure out the server configuration
|
|
|
|
if( preg_match( '/(test\.totallydigital\.co\.nz|dev\.totallydigital\.co\.nz\/test)(.*)/', $_SERVER['SCRIPT_FILENAME'], $nameMatch ) ) {
|
|
|
|
$_SERVER['SCRIPT_NAME'] = $nameMatch[2];
|
|
|
|
$_SERVER['HTTP_HOST'] = $nameMatch[1];
|
2008-02-25 03:10:37 +01:00
|
|
|
$envType = 'test';
|
|
|
|
} elseif( preg_match( '/dev\.totallydigital\.co\.nz(.*)/', $_SERVER['SCRIPT_FILENAME'], $nameMatch ) ) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$_SERVER['SCRIPT_NAME'] = $nameMatch[1];
|
2008-02-25 03:10:37 +01:00
|
|
|
$envType = 'dev';
|
|
|
|
} elseif( preg_match( '/\/sites\/[^\/]+\/www(.*)/', $_SERVER['SCRIPT_FILENAME'], $nameMatch ) ) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$_SERVER['SCRIPT_NAME'] = $nameMatch[1];
|
2008-02-25 03:10:37 +01:00
|
|
|
$envType = 'live';
|
|
|
|
} elseif( preg_match( '/\/sites\/[^\/]+(.*)/', $_SERVER['SCRIPT_FILENAME'], $nameMatch ) ) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$_SERVER['SCRIPT_NAME'] = $nameMatch[1];
|
2008-02-25 03:10:37 +01:00
|
|
|
} elseif(isset($_SERVER['SCRIPT_NAME'])) {
|
|
|
|
$envType = 'live';
|
|
|
|
} else {
|
2007-07-19 12:40:28 +02:00
|
|
|
echo "Error: could not determine server configuration {$_SERVER['SCRIPT_FILENAME']}\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$baseURL = dirname( dirname( $_SERVER['SCRIPT_NAME'] ) );
|
|
|
|
|
|
|
|
if($_REQUEST && get_magic_quotes_gpc()) {
|
|
|
|
stripslashes_recursively($_REQUEST);
|
|
|
|
}
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
if(isset($_REQUEST['trace'])) apd_set_pprof_trace();
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
require_once("core/ManifestBuilder.php");
|
|
|
|
require_once("core/ClassInfo.php");
|
|
|
|
require_once('core/Object.php');
|
|
|
|
require_once('core/control/Director.php');
|
|
|
|
require_once('filesystem/Filesystem.php');
|
|
|
|
require_once("core/Session.php");
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$envFiles = array('../_ss_environment.php', '../../_ss_environment.php', '../../../_ss_environment.php');
|
|
|
|
foreach($envFiles as $envFile) {
|
|
|
|
if(file_exists($envFile)) {
|
|
|
|
include($envFile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
// Find the URL of this script
|
|
|
|
if(isset($_FILE_TO_URL_MAPPING)) {
|
|
|
|
$fullPath = $testPath = $_SERVER['SCRIPT_FILENAME'];
|
|
|
|
while($testPath && $testPath != "/") {
|
|
|
|
if(isset($_FILE_TO_URL_MAPPING[$testPath])) {
|
|
|
|
$url = $_FILE_TO_URL_MAPPING[$testPath] . substr($fullPath,strlen($testPath));
|
|
|
|
$_SERVER['HTTP_HOST'] = parse_url($url, PHP_URL_HOST);
|
|
|
|
$_SERVER['SCRIPT_NAME'] = parse_url($url, PHP_URL_PATH);
|
|
|
|
$_SERVER['REQUEST_PORT'] = parse_url($url, PHP_URL_PORT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$testPath = dirname($testPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if(ManifestBuilder::staleManifest()){
|
|
|
|
ManifestBuilder::compileManifest();
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once(MANIFEST_FILE);
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
if(isset($_GET['debugmanifest'])) Debug::show(file_get_contents(MANIFEST_FILE));
|
|
|
|
|
|
|
|
if(!isset(Director::$environment_type)) Director::set_environment_type($envType);
|
2007-11-19 03:10:09 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// Load error handlers
|
|
|
|
Debug::loadErrorHandlers();
|
|
|
|
|
|
|
|
// Connect to database
|
|
|
|
require_once("core/model/DB.php");
|
|
|
|
|
|
|
|
DB::connect($databaseConfig);
|
|
|
|
|
|
|
|
|
|
|
|
// Get the request URL
|
|
|
|
// $baseURL = dirname(dirname($_SERVER[SCRIPT_NAME]));
|
|
|
|
$url = $_SERVER['argv'][1];
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
if(isset($_SERVER['argv'][2])) {
|
|
|
|
parse_str($_SERVER['argv'][2], $_GET);
|
|
|
|
$_REQUEST = $_GET;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
// Direct away - this is the "main" function, that hands control to the apporopriate controllerx
|
2007-11-11 08:22:24 +01:00
|
|
|
Director::direct($url);
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-05-24 07:57:09 +02:00
|
|
|
?>
|