mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-06-17 04:03:41 +00:00
make it possible to override all of basics.php
This commit is contained in:
parent
6664acba79
commit
99b798fa9a
1 changed files with 439 additions and 359 deletions
|
@ -30,6 +30,8 @@
|
|||
define('MONTH', 2592000);
|
||||
define('YEAR', 31536000);
|
||||
|
||||
if (!function_exists('config')) {
|
||||
|
||||
/**
|
||||
* Loads configuration files. Receives a set of configuration files
|
||||
* to load.
|
||||
|
@ -40,7 +42,7 @@
|
|||
* @return boolean Success
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#config
|
||||
*/
|
||||
function config() {
|
||||
function config() {
|
||||
$args = func_get_args();
|
||||
foreach ($args as $arg) {
|
||||
if (file_exists(APP . 'Config' . DS . $arg . '.php')) {
|
||||
|
@ -56,8 +58,12 @@ function config() {
|
|||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('debug')) {
|
||||
|
||||
/**
|
||||
* 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/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) {
|
||||
App::uses('Debugger', 'Utility');
|
||||
$file = '';
|
||||
|
@ -114,6 +120,8 @@ TEXT;
|
|||
}
|
||||
printf($template, $lineInfo, $var);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('sortByKey')) {
|
||||
|
@ -151,6 +159,8 @@ if (!function_exists('sortByKey')) {
|
|||
|
||||
}
|
||||
|
||||
if (!function_exists('h')) {
|
||||
|
||||
/**
|
||||
* Convenience method for htmlspecialchars.
|
||||
*
|
||||
|
@ -162,7 +172,7 @@ if (!function_exists('sortByKey')) {
|
|||
* @return string Wrapped text
|
||||
* @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)) {
|
||||
$texts = array();
|
||||
foreach ($text as $k => $t) {
|
||||
|
@ -190,8 +200,12 @@ function h($text, $double = true, $charset = null) {
|
|||
$charset = $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.
|
||||
* 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
|
||||
* @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) {
|
||||
$parts = explode('.', $name, 2);
|
||||
if ($dotAppend) {
|
||||
|
@ -213,8 +227,12 @@ function pluginSplit($name, $dotAppend = false, $plugin = null) {
|
|||
return $parts;
|
||||
}
|
||||
return array($plugin, $name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('pr')) {
|
||||
|
||||
/**
|
||||
* Print_r convenience function, which prints out <PRE> tags around
|
||||
* 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
|
||||
* @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) {
|
||||
echo '<pre>';
|
||||
print_r($var);
|
||||
echo '</pre>';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('am')) {
|
||||
|
||||
/**
|
||||
* Merge a group of arrays
|
||||
*
|
||||
|
@ -241,7 +263,7 @@ function pr($var) {
|
|||
* @return array All array parameters merged into one
|
||||
* @link http://book.cakephp.org/2.0/en/development/debugging.html#am
|
||||
*/
|
||||
function am() {
|
||||
function am() {
|
||||
$r = array();
|
||||
$args = func_get_args();
|
||||
foreach ($args as $a) {
|
||||
|
@ -251,8 +273,12 @@ function am() {
|
|||
$r = array_merge($r, $a);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('env')) {
|
||||
|
||||
/**
|
||||
* Gets an environment variable from available sources, and provides emulation
|
||||
* for unsupported or inconsistent environment variables (i.e. DOCUMENT_ROOT on
|
||||
|
@ -263,7 +289,7 @@ function am() {
|
|||
* @return string Environment variable setting.
|
||||
* @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 (isset($_SERVER['HTTPS'])) {
|
||||
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
|
||||
|
@ -360,8 +386,12 @@ function env($key) {
|
|||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('cache')) {
|
||||
|
||||
/**
|
||||
* Reads/writes temporary data to cache files or session.
|
||||
*
|
||||
|
@ -372,7 +402,7 @@ function env($key) {
|
|||
* @return mixed The contents of the temporary file.
|
||||
* @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')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -412,8 +442,12 @@ function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
|
|||
@file_put_contents($filename, $data, LOCK_EX);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('clearCache')) {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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) {
|
||||
$params = preg_replace('/\/\//', '/', $params);
|
||||
$cache = CACHE . $type . DS . $params;
|
||||
|
@ -474,8 +508,12 @@ function clearCache($params = null, $type = 'views', $ext = '.php') {
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('stripslashes_deep')) {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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)) {
|
||||
foreach ($values as $key => $value) {
|
||||
$values[$key] = stripslashes_deep($value);
|
||||
|
@ -492,8 +530,12 @@ function stripslashes_deep($values) {
|
|||
$values = stripslashes($values);
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('__')) {
|
||||
|
||||
/**
|
||||
* Returns a translated string if one is found; Otherwise, the submitted message.
|
||||
*
|
||||
|
@ -502,7 +544,7 @@ function stripslashes_deep($values) {
|
|||
* @return mixed translated string
|
||||
* @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) {
|
||||
return;
|
||||
}
|
||||
|
@ -515,8 +557,12 @@ function __($singular, $args = null) {
|
|||
$args = array_slice(func_get_args(), 1);
|
||||
}
|
||||
return vsprintf($translated, $args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('__n')) {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -528,7 +574,7 @@ function __($singular, $args = null) {
|
|||
* @return mixed plural form of translated string
|
||||
* @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) {
|
||||
return;
|
||||
}
|
||||
|
@ -541,8 +587,12 @@ function __n($singular, $plural, $count, $args = null) {
|
|||
$args = array_slice(func_get_args(), 3);
|
||||
}
|
||||
return vsprintf($translated, $args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('__d')) {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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) {
|
||||
return;
|
||||
}
|
||||
|
@ -564,8 +614,12 @@ function __d($domain, $msg, $args = null) {
|
|||
$args = array_slice(func_get_args(), 2);
|
||||
}
|
||||
return vsprintf($translated, $args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('__dn')) {
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -579,7 +633,7 @@ function __d($domain, $msg, $args = null) {
|
|||
* @return plural form of translated string
|
||||
* @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) {
|
||||
return;
|
||||
}
|
||||
|
@ -591,8 +645,12 @@ function __dn($domain, $singular, $plural, $count, $args = null) {
|
|||
$args = array_slice(func_get_args(), 4);
|
||||
}
|
||||
return vsprintf($translated, $args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('__dc')) {
|
||||
|
||||
/**
|
||||
* Allows you to override the current domain for a single message lookup.
|
||||
* It also allows you to specify a category.
|
||||
|
@ -617,7 +675,7 @@ function __dn($domain, $singular, $plural, $count, $args = null) {
|
|||
* @return translated string
|
||||
* @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) {
|
||||
return;
|
||||
}
|
||||
|
@ -629,8 +687,12 @@ function __dc($domain, $msg, $category, $args = null) {
|
|||
$args = array_slice(func_get_args(), 3);
|
||||
}
|
||||
return vsprintf($translated, $args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('__dcn')) {
|
||||
|
||||
/**
|
||||
* Allows you to override the current domain for a single plural message lookup.
|
||||
* 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
|
||||
* @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) {
|
||||
return;
|
||||
}
|
||||
|
@ -671,8 +733,12 @@ function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
|
|||
$args = array_slice(func_get_args(), 5);
|
||||
}
|
||||
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.
|
||||
* 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
|
||||
* @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) {
|
||||
return;
|
||||
}
|
||||
|
@ -705,8 +771,12 @@ function __c($msg, $category, $args = null) {
|
|||
$args = array_slice(func_get_args(), 2);
|
||||
}
|
||||
return vsprintf($translated, $args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('LogError')) {
|
||||
|
||||
/**
|
||||
* Shortcut to Log::write.
|
||||
*
|
||||
|
@ -714,13 +784,17 @@ function __c($msg, $category, $args = null) {
|
|||
* @return void
|
||||
* @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');
|
||||
$bad = array("\n", "\r", "\t");
|
||||
$good = ' ';
|
||||
CakeLog::write('error', str_replace($bad, $good, $message));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('fileExistsInPath')) {
|
||||
|
||||
/**
|
||||
* Searches include path for files.
|
||||
*
|
||||
|
@ -728,7 +802,7 @@ function LogError($message) {
|
|||
* @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
|
||||
*/
|
||||
function fileExistsInPath($file) {
|
||||
function fileExistsInPath($file) {
|
||||
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
|
||||
foreach ($paths as $path) {
|
||||
$fullPath = $path . DS . $file;
|
||||
|
@ -740,8 +814,12 @@ function fileExistsInPath($file) {
|
|||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('convertSlash')) {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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 = preg_replace('/\/\//', '/', $string);
|
||||
$string = str_replace('/', '_', $string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue