make it possible to override all of basics.php

This commit is contained in:
AD7six 2012-09-05 16:43:24 +02:00
parent 6664acba79
commit 99b798fa9a

View file

@ -30,6 +30,8 @@
define('MONTH', 2592000); define('MONTH', 2592000);
define('YEAR', 31536000); define('YEAR', 31536000);
if (!function_exists('config')) {
/** /**
* Loads configuration files. Receives a set of configuration files * Loads configuration files. Receives a set of configuration files
* to load. * to load.
@ -40,7 +42,7 @@
* @return boolean Success * @return boolean Success
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#config * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#config
*/ */
function config() { function config() {
$args = func_get_args(); $args = func_get_args();
foreach ($args as $arg) { foreach ($args as $arg) {
if (file_exists(APP . 'Config' . DS . $arg . '.php')) { if (file_exists(APP . 'Config' . DS . $arg . '.php')) {
@ -56,8 +58,12 @@ function config() {
} }
} }
return true; return true;
}
} }
if (!function_exists('debug')) {
/** /**
* Prints out debug information about given variable. * Prints out debug information about given variable.
* *
@ -69,7 +75,7 @@ function config() {
* @link http://book.cakephp.org/2.0/en/development/debugging.html#basic-debugging * @link http://book.cakephp.org/2.0/en/development/debugging.html#basic-debugging
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#debug * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#debug
*/ */
function debug($var = false, $showHtml = null, $showFrom = true) { function debug($var = false, $showHtml = null, $showFrom = true) {
if (Configure::read('debug') > 0) { if (Configure::read('debug') > 0) {
App::uses('Debugger', 'Utility'); App::uses('Debugger', 'Utility');
$file = ''; $file = '';
@ -114,6 +120,8 @@ TEXT;
} }
printf($template, $lineInfo, $var); printf($template, $lineInfo, $var);
} }
}
} }
if (!function_exists('sortByKey')) { if (!function_exists('sortByKey')) {
@ -151,6 +159,8 @@ if (!function_exists('sortByKey')) {
} }
if (!function_exists('h')) {
/** /**
* Convenience method for htmlspecialchars. * Convenience method for htmlspecialchars.
* *
@ -162,7 +172,7 @@ if (!function_exists('sortByKey')) {
* @return string Wrapped text * @return string Wrapped text
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#h * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#h
*/ */
function h($text, $double = true, $charset = null) { function h($text, $double = true, $charset = null) {
if (is_array($text)) { if (is_array($text)) {
$texts = array(); $texts = array();
foreach ($text as $k => $t) { foreach ($text as $k => $t) {
@ -190,8 +200,12 @@ function h($text, $double = true, $charset = null) {
$charset = $double; $charset = $double;
} }
return htmlspecialchars($text, ENT_QUOTES, ($charset) ? $charset : $defaultCharset, $double); return htmlspecialchars($text, ENT_QUOTES, ($charset) ? $charset : $defaultCharset, $double);
}
} }
if (!function_exists('pluginSplit')) {
/** /**
* Splits a dot syntax plugin name into its plugin and classname. * Splits a dot syntax plugin name into its plugin and classname.
* If $name does not have a dot, then index 0 will be null. * If $name does not have a dot, then index 0 will be null.
@ -204,7 +218,7 @@ function h($text, $double = true, $charset = null) {
* @return array Array with 2 indexes. 0 => plugin name, 1 => classname * @return array Array with 2 indexes. 0 => plugin name, 1 => classname
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#pluginSplit * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#pluginSplit
*/ */
function pluginSplit($name, $dotAppend = false, $plugin = null) { function pluginSplit($name, $dotAppend = false, $plugin = null) {
if (strpos($name, '.') !== false) { if (strpos($name, '.') !== false) {
$parts = explode('.', $name, 2); $parts = explode('.', $name, 2);
if ($dotAppend) { if ($dotAppend) {
@ -213,8 +227,12 @@ function pluginSplit($name, $dotAppend = false, $plugin = null) {
return $parts; return $parts;
} }
return array($plugin, $name); return array($plugin, $name);
}
} }
if (!function_exists('pr')) {
/** /**
* Print_r convenience function, which prints out <PRE> tags around * Print_r convenience function, which prints out <PRE> tags around
* the output of given array. Similar to debug(). * the output of given array. Similar to debug().
@ -223,14 +241,18 @@ function pluginSplit($name, $dotAppend = false, $plugin = null) {
* @param array $var Variable to print out * @param array $var Variable to print out
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#pr * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#pr
*/ */
function pr($var) { function pr($var) {
if (Configure::read('debug') > 0) { if (Configure::read('debug') > 0) {
echo '<pre>'; echo '<pre>';
print_r($var); print_r($var);
echo '</pre>'; echo '</pre>';
} }
}
} }
if (!function_exists('am')) {
/** /**
* Merge a group of arrays * Merge a group of arrays
* *
@ -241,7 +263,7 @@ function pr($var) {
* @return array All array parameters merged into one * @return array All array parameters merged into one
* @link http://book.cakephp.org/2.0/en/development/debugging.html#am * @link http://book.cakephp.org/2.0/en/development/debugging.html#am
*/ */
function am() { function am() {
$r = array(); $r = array();
$args = func_get_args(); $args = func_get_args();
foreach ($args as $a) { foreach ($args as $a) {
@ -251,8 +273,12 @@ function am() {
$r = array_merge($r, $a); $r = array_merge($r, $a);
} }
return $r; return $r;
}
} }
if (!function_exists('env')) {
/** /**
* Gets an environment variable from available sources, and provides emulation * Gets an environment variable from available sources, and provides emulation
* for unsupported or inconsistent environment variables (i.e. DOCUMENT_ROOT on * for unsupported or inconsistent environment variables (i.e. DOCUMENT_ROOT on
@ -263,7 +289,7 @@ function am() {
* @return string Environment variable setting. * @return string Environment variable setting.
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#env * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#env
*/ */
function env($key) { function env($key) {
if ($key === 'HTTPS') { if ($key === 'HTTPS') {
if (isset($_SERVER['HTTPS'])) { if (isset($_SERVER['HTTPS'])) {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'); return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
@ -360,8 +386,12 @@ function env($key) {
break; break;
} }
return null; return null;
}
} }
if (!function_exists('cache')) {
/** /**
* Reads/writes temporary data to cache files or session. * Reads/writes temporary data to cache files or session.
* *
@ -372,7 +402,7 @@ function env($key) {
* @return mixed The contents of the temporary file. * @return mixed The contents of the temporary file.
* @deprecated Please use Cache::write() instead * @deprecated Please use Cache::write() instead
*/ */
function cache($path, $data = null, $expires = '+1 day', $target = 'cache') { function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
if (Configure::read('Cache.disable')) { if (Configure::read('Cache.disable')) {
return null; return null;
} }
@ -412,8 +442,12 @@ function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
@file_put_contents($filename, $data, LOCK_EX); @file_put_contents($filename, $data, LOCK_EX);
} }
return $data; return $data;
}
} }
if (!function_exists('clearCache')) {
/** /**
* Used to delete files in the cache directories, or clear contents of cache directories * Used to delete files in the cache directories, or clear contents of cache directories
* *
@ -424,7 +458,7 @@ function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
* @param string $ext The file extension you are deleting * @param string $ext The file extension you are deleting
* @return true if files found and deleted false otherwise * @return true if files found and deleted false otherwise
*/ */
function clearCache($params = null, $type = 'views', $ext = '.php') { function clearCache($params = null, $type = 'views', $ext = '.php') {
if (is_string($params) || $params === null) { if (is_string($params) || $params === null) {
$params = preg_replace('/\/\//', '/', $params); $params = preg_replace('/\/\//', '/', $params);
$cache = CACHE . $type . DS . $params; $cache = CACHE . $type . DS . $params;
@ -474,8 +508,12 @@ function clearCache($params = null, $type = 'views', $ext = '.php') {
return true; return true;
} }
return false; return false;
}
} }
if (!function_exists('stripslashes_deep')) {
/** /**
* Recursively strips slashes from all values in an array * Recursively strips slashes from all values in an array
* *
@ -483,7 +521,7 @@ function clearCache($params = null, $type = 'views', $ext = '.php') {
* @return mixed What is returned from calling stripslashes * @return mixed What is returned from calling stripslashes
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#stripslashes_deep * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#stripslashes_deep
*/ */
function stripslashes_deep($values) { function stripslashes_deep($values) {
if (is_array($values)) { if (is_array($values)) {
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
$values[$key] = stripslashes_deep($value); $values[$key] = stripslashes_deep($value);
@ -492,8 +530,12 @@ function stripslashes_deep($values) {
$values = stripslashes($values); $values = stripslashes($values);
} }
return $values; return $values;
}
} }
if (!function_exists('__')) {
/** /**
* Returns a translated string if one is found; Otherwise, the submitted message. * Returns a translated string if one is found; Otherwise, the submitted message.
* *
@ -502,7 +544,7 @@ function stripslashes_deep($values) {
* @return mixed translated string * @return mixed translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__ * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__
*/ */
function __($singular, $args = null) { function __($singular, $args = null) {
if (!$singular) { if (!$singular) {
return; return;
} }
@ -515,8 +557,12 @@ function __($singular, $args = null) {
$args = array_slice(func_get_args(), 1); $args = array_slice(func_get_args(), 1);
} }
return vsprintf($translated, $args); return vsprintf($translated, $args);
}
} }
if (!function_exists('__n')) {
/** /**
* Returns correct plural form of message identified by $singular and $plural for count $count. * Returns correct plural form of message identified by $singular and $plural for count $count.
* Some languages have more than one form for plural messages dependent on the count. * Some languages have more than one form for plural messages dependent on the count.
@ -528,7 +574,7 @@ function __($singular, $args = null) {
* @return mixed plural form of translated string * @return mixed plural form of translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__n * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__n
*/ */
function __n($singular, $plural, $count, $args = null) { function __n($singular, $plural, $count, $args = null) {
if (!$singular) { if (!$singular) {
return; return;
} }
@ -541,8 +587,12 @@ function __n($singular, $plural, $count, $args = null) {
$args = array_slice(func_get_args(), 3); $args = array_slice(func_get_args(), 3);
} }
return vsprintf($translated, $args); return vsprintf($translated, $args);
}
} }
if (!function_exists('__d')) {
/** /**
* Allows you to override the current domain for a single message lookup. * Allows you to override the current domain for a single message lookup.
* *
@ -552,7 +602,7 @@ function __n($singular, $plural, $count, $args = null) {
* @return translated string * @return translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__d * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__d
*/ */
function __d($domain, $msg, $args = null) { function __d($domain, $msg, $args = null) {
if (!$msg) { if (!$msg) {
return; return;
} }
@ -564,8 +614,12 @@ function __d($domain, $msg, $args = null) {
$args = array_slice(func_get_args(), 2); $args = array_slice(func_get_args(), 2);
} }
return vsprintf($translated, $args); return vsprintf($translated, $args);
}
} }
if (!function_exists('__dn')) {
/** /**
* Allows you to override the current domain for a single plural message lookup. * Allows you to override the current domain for a single plural message lookup.
* Returns correct plural form of message identified by $singular and $plural for count $count * Returns correct plural form of message identified by $singular and $plural for count $count
@ -579,7 +633,7 @@ function __d($domain, $msg, $args = null) {
* @return plural form of translated string * @return plural form of translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dn * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dn
*/ */
function __dn($domain, $singular, $plural, $count, $args = null) { function __dn($domain, $singular, $plural, $count, $args = null) {
if (!$singular) { if (!$singular) {
return; return;
} }
@ -591,8 +645,12 @@ function __dn($domain, $singular, $plural, $count, $args = null) {
$args = array_slice(func_get_args(), 4); $args = array_slice(func_get_args(), 4);
} }
return vsprintf($translated, $args); return vsprintf($translated, $args);
}
} }
if (!function_exists('__dc')) {
/** /**
* Allows you to override the current domain for a single message lookup. * Allows you to override the current domain for a single message lookup.
* It also allows you to specify a category. * It also allows you to specify a category.
@ -617,7 +675,7 @@ function __dn($domain, $singular, $plural, $count, $args = null) {
* @return translated string * @return translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dc * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dc
*/ */
function __dc($domain, $msg, $category, $args = null) { function __dc($domain, $msg, $category, $args = null) {
if (!$msg) { if (!$msg) {
return; return;
} }
@ -629,8 +687,12 @@ function __dc($domain, $msg, $category, $args = null) {
$args = array_slice(func_get_args(), 3); $args = array_slice(func_get_args(), 3);
} }
return vsprintf($translated, $args); return vsprintf($translated, $args);
}
} }
if (!function_exists('__dcn')) {
/** /**
* Allows you to override the current domain for a single plural message lookup. * Allows you to override the current domain for a single plural message lookup.
* It also allows you to specify a category. * It also allows you to specify a category.
@ -659,7 +721,7 @@ function __dc($domain, $msg, $category, $args = null) {
* @return plural form of translated string * @return plural form of translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dcn * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dcn
*/ */
function __dcn($domain, $singular, $plural, $count, $category, $args = null) { function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
if (!$singular) { if (!$singular) {
return; return;
} }
@ -671,8 +733,12 @@ function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
$args = array_slice(func_get_args(), 5); $args = array_slice(func_get_args(), 5);
} }
return vsprintf($translated, $args); return vsprintf($translated, $args);
}
} }
if (!function_exists('__c')) {
/** /**
* The category argument allows a specific category of the locale settings to be used for fetching a message. * The category argument allows a specific category of the locale settings to be used for fetching a message.
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL. * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
@ -693,7 +759,7 @@ function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
* @return translated string * @return translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
*/ */
function __c($msg, $category, $args = null) { function __c($msg, $category, $args = null) {
if (!$msg) { if (!$msg) {
return; return;
} }
@ -705,8 +771,12 @@ function __c($msg, $category, $args = null) {
$args = array_slice(func_get_args(), 2); $args = array_slice(func_get_args(), 2);
} }
return vsprintf($translated, $args); return vsprintf($translated, $args);
}
} }
if (!function_exists('LogError')) {
/** /**
* Shortcut to Log::write. * Shortcut to Log::write.
* *
@ -714,13 +784,17 @@ function __c($msg, $category, $args = null) {
* @return void * @return void
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#LogError * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#LogError
*/ */
function LogError($message) { function LogError($message) {
App::uses('CakeLog', 'Log'); App::uses('CakeLog', 'Log');
$bad = array("\n", "\r", "\t"); $bad = array("\n", "\r", "\t");
$good = ' '; $good = ' ';
CakeLog::write('error', str_replace($bad, $good, $message)); CakeLog::write('error', str_replace($bad, $good, $message));
}
} }
if (!function_exists('fileExistsInPath')) {
/** /**
* Searches include path for files. * Searches include path for files.
* *
@ -728,7 +802,7 @@ function LogError($message) {
* @return Full path to file if exists, otherwise false * @return Full path to file if exists, otherwise false
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#fileExistsInPath * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#fileExistsInPath
*/ */
function fileExistsInPath($file) { function fileExistsInPath($file) {
$paths = explode(PATH_SEPARATOR, ini_get('include_path')); $paths = explode(PATH_SEPARATOR, ini_get('include_path'));
foreach ($paths as $path) { foreach ($paths as $path) {
$fullPath = $path . DS . $file; $fullPath = $path . DS . $file;
@ -740,8 +814,12 @@ function fileExistsInPath($file) {
} }
} }
return false; return false;
}
} }
if (!function_exists('convertSlash')) {
/** /**
* Convert forward slashes to underscores and removes first and last underscores in a string * Convert forward slashes to underscores and removes first and last underscores in a string
* *
@ -749,9 +827,11 @@ function fileExistsInPath($file) {
* @return string with underscore remove from start and end of string * @return string with underscore remove from start and end of string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#convertSlash * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#convertSlash
*/ */
function convertSlash($string) { function convertSlash($string) {
$string = trim($string, '/'); $string = trim($string, '/');
$string = preg_replace('/\/\//', '/', $string); $string = preg_replace('/\/\//', '/', $string);
$string = str_replace('/', '_', $string); $string = str_replace('/', '_', $string);
return $string; return $string;
}
} }