2010-07-07 03:34:48 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
2008-09-30 01:41:50 +02:00
|
|
|
* This file is the Sapphire bootstrap. It will get your environment ready to call Director::direct().
|
2008-02-25 03:10:37 +01:00
|
|
|
*
|
2008-09-30 01:41:50 +02:00
|
|
|
* It takes care of:
|
|
|
|
* - Including _ss_environment.php
|
|
|
|
* - Normalisation of $_SERVER values
|
2010-09-21 22:29:14 +02:00
|
|
|
* - Initialisation of necessary constants (mostly paths)
|
2008-09-30 01:41:50 +02:00
|
|
|
* - Checking of PHP memory limit
|
|
|
|
* - Including all the files needed to get the manifest built
|
|
|
|
* - Building and including the manifest
|
|
|
|
*
|
2010-09-21 22:29:14 +02:00
|
|
|
* Initialized constants:
|
|
|
|
* - BASE_URL: Full URL to the webroot, e.g. "http://my-host.com/my-webroot" (no trailing slash).
|
|
|
|
* - BASE_PATH: Absolute path to the webroot, e.g. "/var/www/my-webroot" (no trailing slash).
|
|
|
|
* See Director::baseFolder(). Can be overwritten by Director::setBaseFolder().
|
|
|
|
* - TEMP_FOLDER: Absolute path to temporary folder, used for manifest and template caches. Example: "/var/tmp"
|
|
|
|
* See getTempFolder(). No trailing slash.
|
|
|
|
* - MODULES_DIR: Not used at the moment
|
|
|
|
* - MODULES_PATH: Not used at the moment
|
|
|
|
* - THEMES_DIR: Path relative to webroot, e.g. "themes"
|
|
|
|
* - THEMES_PATH: Absolute filepath, e.g. "/var/www/my-webroot/themes"
|
|
|
|
* - CMS_DIR: Path relative to webroot, e.g. "cms"
|
|
|
|
* - CMS_PATH: Absolute filepath, e.g. "/var/www/my-webroot/cms"
|
|
|
|
* - SAPPHIRE_DIR: Path relative to webroot, e.g. "sapphire"
|
|
|
|
* - SAPPHIRE_PATH:Absolute filepath, e.g. "/var/www/my-webroot/sapphire"
|
|
|
|
* - THIRDPARTY_DIR: Path relative to webroot, e.g. "sapphire/thirdparty"
|
|
|
|
* - THIRDPARTY_PATH: Absolute filepath, e.g. "/var/www/my-webroot/sapphire/thirdparty"
|
|
|
|
*
|
2008-09-30 01:41:50 +02:00
|
|
|
* @todo This file currently contains a lot of bits and pieces, and its various responsibilities should probably be
|
|
|
|
* moved into different subsystems.
|
|
|
|
* @todo A lot of this stuff is very order-independent; for example, the require_once calls have to happen after the defines.'
|
|
|
|
* This could be decoupled.
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage core
|
|
|
|
*/
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ENVIRONMENT CONFIG
|
|
|
|
|
2011-08-26 06:12:57 +02:00
|
|
|
if(defined('E_DEPRECATED')) error_reporting(E_ALL & ~(E_DEPRECATED | E_STRICT));
|
2009-06-26 04:46:14 +02:00
|
|
|
else error_reporting(E_ALL);
|
2010-01-21 01:36:04 +01:00
|
|
|
/*
|
|
|
|
* This is for versions of PHP prior to version 5.2
|
|
|
|
* Creating this here will allow both web requests and cron jobs to inherit it.
|
|
|
|
*/
|
|
|
|
if (!function_exists('array_fill_keys')) {
|
|
|
|
function array_fill_keys($keys,$value) {
|
|
|
|
//Sometimes we get passed an empty array, and if that's the case, you'll get an error message
|
|
|
|
if(sizeof($keys)==0)
|
|
|
|
return Array();
|
|
|
|
else
|
|
|
|
return array_combine($keys,array_fill(0,count($keys),$value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
/**
|
|
|
|
* Include _ss_environment.php files
|
|
|
|
*/
|
2010-07-07 03:33:53 +02:00
|
|
|
$envFiles = array('_ss_environment.php', '../_ss_environment.php', '../../_ss_environment.php', '../../../_ss_environment.php');
|
2008-09-30 01:41:50 +02:00
|
|
|
foreach($envFiles as $envFile) {
|
2009-03-10 23:08:52 +01:00
|
|
|
if(@file_exists($envFile)) {
|
2008-11-18 02:48:37 +01:00
|
|
|
define('SS_ENVIRONMENT_FILE', $envFile);
|
2008-10-20 15:26:52 +02:00
|
|
|
include_once($envFile);
|
2008-09-30 01:41:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GLOBALS AND DEFINE SETTING
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A blank HTTP_HOST value is used to detect command-line execution.
|
|
|
|
* We update the $_SERVER variable to contain data consistent with the rest of the application.
|
|
|
|
*/
|
|
|
|
if(!isset($_SERVER['HTTP_HOST'])) {
|
|
|
|
// HTTP_HOST, REQUEST_PORT, SCRIPT_NAME, and PHP_SELF
|
|
|
|
if(isset($_FILE_TO_URL_MAPPING)) {
|
2010-02-08 21:10:07 +01:00
|
|
|
$fullPath = $testPath = realpath($_SERVER['SCRIPT_FILENAME']);
|
2009-06-26 04:46:14 +02:00
|
|
|
while($testPath && $testPath != "/" && !preg_match('/^[A-Z]:\\\\$/', $testPath)) {
|
2008-09-30 01:41:50 +02:00
|
|
|
if(isset($_FILE_TO_URL_MAPPING[$testPath])) {
|
2009-06-26 04:46:14 +02:00
|
|
|
$url = $_FILE_TO_URL_MAPPING[$testPath]
|
|
|
|
. str_replace(DIRECTORY_SEPARATOR,'/',substr($fullPath,strlen($testPath)));
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
$_SERVER['HTTP_HOST'] = parse_url($url, PHP_URL_HOST);
|
|
|
|
$_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = parse_url($url, PHP_URL_PATH);
|
|
|
|
$_SERVER['REQUEST_PORT'] = parse_url($url, PHP_URL_PORT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$testPath = dirname($testPath);
|
|
|
|
}
|
|
|
|
}
|
2009-06-26 04:46:14 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
// Everything else
|
|
|
|
$serverDefaults = array(
|
|
|
|
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
|
|
|
'HTTP_ACCEPT' => 'text/plain;q=0.5',
|
|
|
|
'HTTP_ACCEPT_LANGUAGE' => '*;q=0.5',
|
|
|
|
'HTTP_ACCEPT_ENCODING' => '',
|
|
|
|
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1;q=0.5',
|
|
|
|
'SERVER_SIGNATURE' => 'Command-line PHP/' . phpversion(),
|
|
|
|
'SERVER_SOFTWARE' => 'PHP/' . phpversion(),
|
|
|
|
'SERVER_ADDR' => '127.0.0.1',
|
|
|
|
'REMOTE_ADDR' => '127.0.0.1',
|
|
|
|
'REQUEST_METHOD' => 'GET',
|
2008-11-09 23:40:08 +01:00
|
|
|
'HTTP_USER_AGENT' => 'CLI',
|
2008-09-30 01:41:50 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$_SERVER = array_merge($serverDefaults, $_SERVER);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If we have an HTTP_HOST value, then we're being called from the webserver and there are some things that
|
|
|
|
* need checking
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* Fix magic quotes setting
|
|
|
|
*/
|
2009-06-16 13:47:23 +02:00
|
|
|
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
|
2008-09-30 01:41:50 +02:00
|
|
|
if($_REQUEST) stripslashes_recursively($_REQUEST);
|
|
|
|
if($_GET) stripslashes_recursively($_GET);
|
|
|
|
if($_POST) stripslashes_recursively($_POST);
|
|
|
|
}
|
2010-01-13 00:34:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fix HTTP_HOST from reverse proxies
|
|
|
|
*/
|
|
|
|
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
|
|
|
|
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
|
|
|
|
}
|
2008-09-30 01:41:50 +02:00
|
|
|
}
|
|
|
|
|
2008-09-29 14:33:07 +02:00
|
|
|
/**
|
|
|
|
* Define system paths
|
|
|
|
*/
|
2010-01-28 06:52:38 +01:00
|
|
|
if(!defined('BASE_PATH')) {
|
|
|
|
// Assuming that this file is sapphire/core/Core.php we can then determine the base path
|
|
|
|
define('BASE_PATH', rtrim(dirname(dirname(dirname(__FILE__)))), DIRECTORY_SEPARATOR);
|
|
|
|
}
|
|
|
|
if(!defined('BASE_URL')) {
|
|
|
|
// Determine the base URL by comparing SCRIPT_NAME to SCRIPT_FILENAME and getting the common
|
|
|
|
// elements
|
|
|
|
if(substr($_SERVER['SCRIPT_FILENAME'],0,strlen(BASE_PATH)) == BASE_PATH) {
|
|
|
|
$urlSegmentToRemove = substr($_SERVER['SCRIPT_FILENAME'],strlen(BASE_PATH));
|
|
|
|
if(substr($_SERVER['SCRIPT_NAME'],-strlen($urlSegmentToRemove)) == $urlSegmentToRemove) {
|
|
|
|
$baseURL = substr($_SERVER['SCRIPT_NAME'], 0, -strlen($urlSegmentToRemove));
|
|
|
|
define('BASE_URL', rtrim($baseURL, DIRECTORY_SEPARATOR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If that didn't work, failover to the old syntax. Hopefully this isn't necessary, and maybe
|
|
|
|
// if can be phased out?
|
|
|
|
if(!defined('BASE_URL')) {
|
2010-02-13 10:42:59 +01:00
|
|
|
$dir = (strpos($_SERVER['SCRIPT_NAME'], 'index.php') !== false)
|
2010-02-13 07:06:30 +01:00
|
|
|
? dirname($_SERVER['SCRIPT_NAME'])
|
|
|
|
: dirname(dirname($_SERVER['SCRIPT_NAME']));
|
|
|
|
define('BASE_URL', rtrim($dir, DIRECTORY_SEPARATOR));
|
2010-01-28 06:52:38 +01:00
|
|
|
}
|
|
|
|
}
|
2008-09-29 14:33:07 +02:00
|
|
|
define('MODULES_DIR', 'modules');
|
|
|
|
define('MODULES_PATH', BASE_PATH . '/' . MODULES_DIR);
|
|
|
|
define('THEMES_DIR', 'themes');
|
|
|
|
define('THEMES_PATH', BASE_PATH . '/' . THEMES_DIR);
|
|
|
|
define('SAPPHIRE_DIR', 'sapphire');
|
|
|
|
define('SAPPHIRE_PATH', BASE_PATH . '/' . SAPPHIRE_DIR);
|
|
|
|
define('CMS_DIR', 'cms');
|
|
|
|
define('CMS_PATH', BASE_PATH . '/' . CMS_DIR);
|
2009-11-26 06:08:08 +01:00
|
|
|
define('THIRDPARTY_DIR', SAPPHIRE_DIR . '/thirdparty');
|
|
|
|
define('THIRDPARTY_PATH', BASE_PATH . '/' . THIRDPARTY_DIR);
|
2008-09-29 14:33:07 +02:00
|
|
|
define('ASSETS_DIR', 'assets');
|
|
|
|
define('ASSETS_PATH', BASE_PATH . '/' . ASSETS_DIR);
|
|
|
|
|
2008-09-29 01:03:28 +02:00
|
|
|
/**
|
|
|
|
* Define the temporary folder if it wasn't defined yet
|
|
|
|
*/
|
|
|
|
if(!defined('TEMP_FOLDER')) {
|
|
|
|
define('TEMP_FOLDER', getTempFolder());
|
|
|
|
}
|
|
|
|
|
2008-09-29 14:33:07 +02:00
|
|
|
/**
|
|
|
|
* Priorities definition. These constants are used in calls to _t() as an optional argument
|
|
|
|
*/
|
|
|
|
define('PR_HIGH',100);
|
|
|
|
define('PR_MEDIUM',50);
|
|
|
|
define('PR_LOW',10);
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
/**
|
|
|
|
* Ensure we have enough memory
|
|
|
|
*/
|
2009-06-17 13:36:49 +02:00
|
|
|
increase_memory_limit_to('64M');
|
2008-09-30 01:41:50 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// INCLUDES
|
|
|
|
|
2010-11-21 23:39:29 +01:00
|
|
|
set_include_path(BASE_PATH . '/sapphire' . PATH_SEPARATOR
|
2010-01-18 00:27:56 +01:00
|
|
|
. BASE_PATH . '/sapphire/parsers' . PATH_SEPARATOR
|
2010-01-17 23:08:51 +01:00
|
|
|
. BASE_PATH . '/sapphire/thirdparty' . PATH_SEPARATOR
|
2010-11-21 23:39:29 +01:00
|
|
|
. get_include_path());
|
2009-05-21 01:19:08 +02:00
|
|
|
|
2010-09-21 22:29:04 +02:00
|
|
|
/**
|
|
|
|
* Sapphire class autoloader. Requires the ManifestBuilder to work.
|
|
|
|
* $_CLASS_MANIFEST must have been loaded up by ManifestBuilder for this to successfully load
|
|
|
|
* classes. Classes will be loaded from any PHP file within the application.
|
|
|
|
* If your class contains an underscore, for example, Page_Controller, then the filename is
|
|
|
|
* expected to be the stuff before the underscore. In this case, Page.php.
|
|
|
|
*
|
|
|
|
* Class names are converted to lowercase for lookup to adhere to PHP's case-insensitive
|
|
|
|
* way of dealing with them.
|
|
|
|
*/
|
2010-11-18 22:37:20 +01:00
|
|
|
function sapphire_autoload($className) {
|
2010-09-21 22:29:04 +02:00
|
|
|
global $_CLASS_MANIFEST;
|
|
|
|
$lClassName = strtolower($className);
|
|
|
|
if(isset($_CLASS_MANIFEST[$lClassName])) include_once($_CLASS_MANIFEST[$lClassName]);
|
|
|
|
else if(isset($_CLASS_MANIFEST[$className])) include_once($_CLASS_MANIFEST[$className]);
|
|
|
|
}
|
|
|
|
|
|
|
|
spl_autoload_register('sapphire_autoload');
|
|
|
|
|
2010-01-28 06:10:32 +01: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");
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// MANIFEST
|
|
|
|
|
|
|
|
/**
|
2008-11-06 05:51:25 +01:00
|
|
|
* Include the manifest
|
2008-09-30 01:41:50 +02:00
|
|
|
*/
|
2008-11-06 05:51:25 +01:00
|
|
|
ManifestBuilder::include_manifest();
|
2008-09-30 01:41:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ?debugmanifest=1 hook
|
|
|
|
*/
|
|
|
|
if(isset($_GET['debugmanifest'])) Debug::show(file_get_contents(MANIFEST_FILE));
|
|
|
|
|
2008-10-08 05:35:28 +02:00
|
|
|
// If this is a dev site, enable php error reporting
|
|
|
|
// This is necessary to force developers to acknowledge and fix
|
|
|
|
// notice level errors (you can override this directive in your _config.php)
|
|
|
|
if (Director::isLive()) {
|
2009-06-26 04:46:14 +02:00
|
|
|
if(defined('E_DEPRECATED')) error_reporting((E_ALL ^ E_NOTICE) ^ E_DEPRECATED);
|
|
|
|
else error_reporting(E_ALL ^ E_NOTICE);
|
2008-10-08 05:35:28 +02:00
|
|
|
}
|
2008-09-30 01:41:50 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// POST-MANIFEST COMMANDS
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load error handlers
|
|
|
|
*/
|
|
|
|
Debug::loadErrorHandlers();
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HELPER FUNCTIONS
|
|
|
|
|
2009-12-01 11:26:08 +01:00
|
|
|
function getSysTempDir() {
|
2010-11-18 22:37:20 +01:00
|
|
|
if(function_exists('sys_get_temp_dir')) {
|
|
|
|
$sysTmp = sys_get_temp_dir();
|
|
|
|
} elseif(isset($_ENV['TMP'])) {
|
2009-12-01 11:26:08 +01:00
|
|
|
$sysTmp = $_ENV['TMP'];
|
2010-11-18 22:37:20 +01:00
|
|
|
} else {
|
|
|
|
$tmpFile = tempnam('adfadsfdas','');
|
|
|
|
unlink($tmpFile);
|
|
|
|
$sysTmp = dirname($tmpFile);
|
|
|
|
}
|
2009-12-01 11:26:08 +01:00
|
|
|
return $sysTmp;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns the temporary folder that sapphire/silverstripe should use for its cache files
|
|
|
|
* This is loaded into the TEMP_FOLDER define on start up
|
2010-01-28 06:52:38 +01:00
|
|
|
*
|
|
|
|
* @param $base The base path to use as the basis for the temp folder name. Defaults to BASE_PATH,
|
|
|
|
* which is usually fine; however, the $base argument can be used to help test.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2010-01-28 06:52:38 +01:00
|
|
|
function getTempFolder($base = null) {
|
|
|
|
if(!$base) $base = BASE_PATH;
|
2010-11-18 22:35:11 +01:00
|
|
|
|
2010-01-28 06:52:38 +01:00
|
|
|
if($base) {
|
|
|
|
$cachefolder = "silverstripe-cache" . str_replace(array(' ', "/", ":", "\\"), "-", $base);
|
2008-08-11 02:03:57 +02:00
|
|
|
} else {
|
|
|
|
$cachefolder = "silverstripe-cache";
|
|
|
|
}
|
2010-11-18 22:35:11 +01:00
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
$ssTmp = BASE_PATH . "/silverstripe-cache";
|
2010-11-18 22:35:11 +01:00
|
|
|
if(@file_exists($ssTmp)) {
|
|
|
|
return $ssTmp;
|
|
|
|
}
|
2007-09-15 02:19:29 +02:00
|
|
|
|
2010-11-18 22:35:11 +01:00
|
|
|
$sysTmp = getSysTempDir();
|
|
|
|
$worked = true;
|
|
|
|
$ssTmp = "$sysTmp/$cachefolder";
|
|
|
|
|
|
|
|
if(!@file_exists($ssTmp)) {
|
|
|
|
@$worked = mkdir($ssTmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$worked) {
|
|
|
|
$ssTmp = BASE_PATH . "/silverstripe-cache";
|
|
|
|
$worked = true;
|
|
|
|
if(!@file_exists($ssTmp)) {
|
|
|
|
@$worked = mkdir($ssTmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$worked) {
|
|
|
|
user_error("Permission problem gaining access to a temp folder. " .
|
|
|
|
"Please create a folder named silverstripe-cache in the base folder " .
|
|
|
|
"of the installation and ensure it has the correct permissions", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ssTmp;
|
2007-09-16 04:44:10 +02:00
|
|
|
}
|
2007-09-15 02:19:29 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2010-05-17 05:22:07 +02:00
|
|
|
* Return the file where that class is stored.
|
|
|
|
*
|
|
|
|
* @param String $className Case-insensitive lookup.
|
|
|
|
* @return String
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
function getClassFile($className) {
|
|
|
|
global $_CLASS_MANIFEST;
|
2010-03-16 04:56:59 +01:00
|
|
|
$lClassName = strtolower($className);
|
|
|
|
if(isset($_CLASS_MANIFEST[$lClassName])) return $_CLASS_MANIFEST[$lClassName];
|
|
|
|
else if(isset($_CLASS_MANIFEST[$className])) return $_CLASS_MANIFEST[$className];
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2009-03-31 21:32:19 +02:00
|
|
|
/**
|
|
|
|
* Creates a class instance by the "singleton" design pattern.
|
|
|
|
* It will always return the same instance for this class,
|
|
|
|
* which can be used for performance reasons and as a simple
|
|
|
|
* way to access instance methods which don't rely on instance
|
|
|
|
* data (e.g. the custom SilverStripe static handling).
|
|
|
|
*
|
|
|
|
* @uses Object::strong_create()
|
|
|
|
*
|
|
|
|
* @param string $className
|
|
|
|
* @return Object
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function singleton($className) {
|
2009-03-31 21:32:19 +02:00
|
|
|
global $_SINGLETONS;
|
2007-07-19 12:40:28 +02:00
|
|
|
if(!isset($className)) user_error("singleton() Called without a class", E_USER_ERROR);
|
2008-11-18 02:48:37 +01:00
|
|
|
if(!is_string($className)) user_error("singleton() passed bad class_name: " . var_export($className,true), E_USER_ERROR);
|
2007-07-19 12:40:28 +02:00
|
|
|
if(!isset($_SINGLETONS[$className])) {
|
2010-11-18 22:37:20 +01:00
|
|
|
if(!class_exists($className)) user_error("Bad class to singleton() - $className", E_USER_ERROR);
|
2007-07-19 12:40:28 +02:00
|
|
|
$_SINGLETONS[$className] = Object::strong_create($className,null, true);
|
|
|
|
if(!$_SINGLETONS[$className]) user_error("singleton() Unknown class '$className'", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
return $_SINGLETONS[$className];
|
|
|
|
}
|
|
|
|
|
|
|
|
function project() {
|
|
|
|
global $project;
|
|
|
|
return $project;
|
|
|
|
}
|
|
|
|
|
|
|
|
function stripslashes_recursively(&$array) {
|
|
|
|
foreach($array as $k => $v) {
|
|
|
|
if(is_array($v)) stripslashes_recursively($array[$k]);
|
|
|
|
else $array[$k] = stripslashes($v);
|
|
|
|
}
|
|
|
|
}
|
2007-09-15 02:12:28 +02:00
|
|
|
|
|
|
|
/**
|
2008-10-17 17:40:59 +02:00
|
|
|
* @see i18n::_t()
|
2007-09-15 02:12:28 +02:00
|
|
|
*/
|
2007-09-15 02:21:51 +02:00
|
|
|
function _t($entity, $string = "", $priority = 40, $context = "") {
|
2008-10-17 17:40:59 +02:00
|
|
|
return i18n::_t($entity, $string, $priority, $context);
|
2007-09-15 02:12:28 +02:00
|
|
|
}
|
2007-09-15 02:19:29 +02:00
|
|
|
|
2009-06-17 13:36:49 +02:00
|
|
|
/**
|
|
|
|
* Increase the memory limit to the given level if it's currently too low.
|
2009-06-28 04:36:46 +02:00
|
|
|
* @param A memory limit string, such as "64M". If omitted, unlimited memory will be set.
|
2009-06-17 13:36:49 +02:00
|
|
|
*/
|
2009-06-28 04:36:46 +02:00
|
|
|
function increase_memory_limit_to($memoryLimit = -1) {
|
|
|
|
$curLimit = ini_get('memory_limit');
|
|
|
|
|
|
|
|
// Can't go higher than infinite
|
|
|
|
if($curLimit == -1) return;
|
|
|
|
|
2009-06-17 13:36:49 +02:00
|
|
|
// Increase the memory limit if it's too low
|
2009-06-28 04:36:46 +02:00
|
|
|
if($memoryLimit == -1 || translate_memstring($memoryLimit) > translate_memstring($curLimit)) {
|
2009-06-17 13:36:49 +02:00
|
|
|
ini_set('memory_limit', $memoryLimit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn a memory string, such as 512M into an actual number of bytes.
|
|
|
|
* @param A memory limit string, such as "64M"
|
|
|
|
*/
|
|
|
|
function translate_memstring($memString) {
|
|
|
|
switch(strtolower(substr($memString, -1))) {
|
|
|
|
case "k": return round(substr($memString, 0, -1)*1024);
|
|
|
|
case "m": return round(substr($memString, 0, -1)*1024*1024);
|
|
|
|
case "g": return round(substr($memString, 0, -1)*1024*1024*1024);
|
|
|
|
default: return round($memString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 04:36:46 +02:00
|
|
|
/**
|
|
|
|
* Increase the time limit of this script. By default, the time will be unlimited.
|
|
|
|
* @param $timeLimit The time limit in seconds. If omitted, no time limit will be set.
|
|
|
|
*/
|
|
|
|
function increase_time_limit_to($timeLimit = null) {
|
|
|
|
if(!ini_get('safe_mode')) {
|
|
|
|
if(!$timeLimit) {
|
|
|
|
set_time_limit(0);
|
|
|
|
} else {
|
|
|
|
$currTimeLimit = ini_get('max_execution_time');
|
|
|
|
if($currTimeLimit && $currTimeLimit < $timeLimit) {
|
|
|
|
set_time_limit($timeLimit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|