mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
update basics to match code standards
global functions are not indented
This commit is contained in:
parent
43a95a79fc
commit
d861a73327
1 changed files with 385 additions and 362 deletions
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic Cake functionality.
|
* Basic Cake functionality.
|
||||||
*
|
*
|
||||||
|
@ -40,7 +41,7 @@
|
||||||
* @return boolean Success
|
* @return boolean Success
|
||||||
* @link http://book.cakephp.org/view/1125/config
|
* @link http://book.cakephp.org/view/1125/config
|
||||||
*/
|
*/
|
||||||
function config() {
|
function config() {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
foreach ($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
if ($arg === 'database' && file_exists(CONFIGS . 'database.php')) {
|
if ($arg === 'database' && file_exists(CONFIGS . 'database.php')) {
|
||||||
|
@ -58,7 +59,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints out debug information about given variable.
|
* Prints out debug information about given variable.
|
||||||
|
@ -71,7 +72,7 @@
|
||||||
* @link http://book.cakephp.org/view/1190/Basic-Debugging
|
* @link http://book.cakephp.org/view/1190/Basic-Debugging
|
||||||
* @link http://book.cakephp.org/view/1128/debug
|
* @link http://book.cakephp.org/view/1128/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) {
|
||||||
$file = '';
|
$file = '';
|
||||||
$line = '';
|
$line = '';
|
||||||
|
@ -107,11 +108,11 @@ TEXT;
|
||||||
}
|
}
|
||||||
printf($template, $file, $line, $var);
|
printf($template, $file, $line, $var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('sortByKey')) {
|
if (!function_exists('sortByKey')) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts given $array by key $sortby.
|
* Sorts given $array by key $sortby.
|
||||||
*
|
*
|
||||||
* @param array $array Array to sort
|
* @param array $array Array to sort
|
||||||
|
@ -151,7 +152,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @return string Wrapped text
|
* @return string Wrapped text
|
||||||
* @link http://book.cakephp.org/view/1132/h
|
* @link http://book.cakephp.org/view/1132/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) {
|
||||||
|
@ -171,7 +172,7 @@ if (!function_exists('sortByKey')) {
|
||||||
$charset = $double;
|
$charset = $double;
|
||||||
}
|
}
|
||||||
return htmlspecialchars($text, ENT_QUOTES, ($charset) ? $charset : $defaultCharset, $double);
|
return htmlspecialchars($text, ENT_QUOTES, ($charset) ? $charset : $defaultCharset, $double);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits a dot syntax plugin name into its plugin and classname.
|
* Splits a dot syntax plugin name into its plugin and classname.
|
||||||
|
@ -184,7 +185,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @param string $plugin Optional default plugin to use if no plugin is found. Defaults to null.
|
* @param string $plugin Optional default plugin to use if no plugin is found. Defaults to null.
|
||||||
* @return array Array with 2 indexes. 0 => plugin name, 1 => classname
|
* @return array Array with 2 indexes. 0 => plugin name, 1 => classname
|
||||||
*/
|
*/
|
||||||
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) {
|
||||||
|
@ -193,7 +194,7 @@ if (!function_exists('sortByKey')) {
|
||||||
return $parts;
|
return $parts;
|
||||||
}
|
}
|
||||||
return array($plugin, $name);
|
return array($plugin, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print_r convenience function, which prints out <PRE> tags around
|
* Print_r convenience function, which prints out <PRE> tags around
|
||||||
|
@ -203,13 +204,13 @@ if (!function_exists('sortByKey')) {
|
||||||
* @param array $var Variable to print out
|
* @param array $var Variable to print out
|
||||||
* @link http://book.cakephp.org/view/1136/pr
|
* @link http://book.cakephp.org/view/1136/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>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge a group of arrays
|
* Merge a group of arrays
|
||||||
|
@ -221,7 +222,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @return array All array parameters merged into one
|
* @return array All array parameters merged into one
|
||||||
* @link http://book.cakephp.org/view/1124/am
|
* @link http://book.cakephp.org/view/1124/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) {
|
||||||
|
@ -231,7 +232,7 @@ if (!function_exists('sortByKey')) {
|
||||||
$r = array_merge($r, $a);
|
$r = array_merge($r, $a);
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an environment variable from available sources, and provides emulation
|
* Gets an environment variable from available sources, and provides emulation
|
||||||
|
@ -243,7 +244,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @return string Environment variable setting.
|
* @return string Environment variable setting.
|
||||||
* @link http://book.cakephp.org/view/1130/env
|
* @link http://book.cakephp.org/view/1130/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');
|
||||||
|
@ -308,7 +309,29 @@ if (!function_exists('sortByKey')) {
|
||||||
} elseif ($count === 2) {
|
} elseif ($count === 2) {
|
||||||
return '.' . $host;
|
return '.' . $host;
|
||||||
} elseif ($count === 3) {
|
} elseif ($count === 3) {
|
||||||
$gTLD = array('aero', 'asia', 'biz', 'cat', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'jobs', 'mil', 'mobi', 'museum', 'name', 'net', 'org', 'pro', 'tel', 'travel', 'xxx');
|
$gTLD = array(
|
||||||
|
'aero',
|
||||||
|
'asia',
|
||||||
|
'biz',
|
||||||
|
'cat',
|
||||||
|
'com',
|
||||||
|
'coop',
|
||||||
|
'edu',
|
||||||
|
'gov',
|
||||||
|
'info',
|
||||||
|
'int',
|
||||||
|
'jobs',
|
||||||
|
'mil',
|
||||||
|
'mobi',
|
||||||
|
'museum',
|
||||||
|
'name',
|
||||||
|
'net',
|
||||||
|
'org',
|
||||||
|
'pro',
|
||||||
|
'tel',
|
||||||
|
'travel',
|
||||||
|
'xxx'
|
||||||
|
);
|
||||||
if (in_array($parts[1], $gTLD)) {
|
if (in_array($parts[1], $gTLD)) {
|
||||||
return '.' . $host;
|
return '.' . $host;
|
||||||
}
|
}
|
||||||
|
@ -318,7 +341,7 @@ if (!function_exists('sortByKey')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads/writes temporary data to cache files or session.
|
* Reads/writes temporary data to cache files or session.
|
||||||
|
@ -330,7 +353,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
@ -370,7 +393,7 @@ if (!function_exists('sortByKey')) {
|
||||||
@file_put_contents($filename, $data);
|
@file_put_contents($filename, $data);
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -382,7 +405,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @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;
|
||||||
|
@ -432,7 +455,7 @@ if (!function_exists('sortByKey')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively strips slashes from all values in an array
|
* Recursively strips slashes from all values in an array
|
||||||
|
@ -441,7 +464,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @return mixed What is returned from calling stripslashes
|
* @return mixed What is returned from calling stripslashes
|
||||||
* @link http://book.cakephp.org/view/1138/stripslashes_deep
|
* @link http://book.cakephp.org/view/1138/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);
|
||||||
|
@ -450,7 +473,7 @@ if (!function_exists('sortByKey')) {
|
||||||
$values = stripslashes($values);
|
$values = stripslashes($values);
|
||||||
}
|
}
|
||||||
return $values;
|
return $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a translated string if one is found; Otherwise, the submitted message.
|
* Returns a translated string if one is found; Otherwise, the submitted message.
|
||||||
|
@ -460,7 +483,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @return mixed translated string
|
* @return mixed translated string
|
||||||
* @link http://book.cakephp.org/view/1121/__
|
* @link http://book.cakephp.org/view/1121/__
|
||||||
*/
|
*/
|
||||||
function __($singular, $args = null) {
|
function __($singular, $args = null) {
|
||||||
if (!$singular) {
|
if (!$singular) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -473,7 +496,7 @@ if (!function_exists('sortByKey')) {
|
||||||
$args = array_slice(func_get_args(), 1);
|
$args = array_slice(func_get_args(), 1);
|
||||||
}
|
}
|
||||||
return vsprintf($translated, $args);
|
return vsprintf($translated, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
@ -485,7 +508,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @param mixed $args Array with arguments or multiple arguments in function
|
* @param mixed $args Array with arguments or multiple arguments in function
|
||||||
* @return mixed plural form of translated string
|
* @return mixed plural form of translated string
|
||||||
*/
|
*/
|
||||||
function __n($singular, $plural, $count, $args = null) {
|
function __n($singular, $plural, $count, $args = null) {
|
||||||
if (!$singular) {
|
if (!$singular) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -498,7 +521,7 @@ if (!function_exists('sortByKey')) {
|
||||||
$args = array_slice(func_get_args(), 3);
|
$args = array_slice(func_get_args(), 3);
|
||||||
}
|
}
|
||||||
return vsprintf($translated, $args);
|
return vsprintf($translated, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows you to override the current domain for a single message lookup.
|
* Allows you to override the current domain for a single message lookup.
|
||||||
|
@ -508,7 +531,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @param mixed $args Array with arguments or multiple arguments in function
|
* @param mixed $args Array with arguments or multiple arguments in function
|
||||||
* @return translated string
|
* @return translated string
|
||||||
*/
|
*/
|
||||||
function __d($domain, $msg, $args = null) {
|
function __d($domain, $msg, $args = null) {
|
||||||
if (!$msg) {
|
if (!$msg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -520,7 +543,7 @@ if (!function_exists('sortByKey')) {
|
||||||
$args = array_slice(func_get_args(), 2);
|
$args = array_slice(func_get_args(), 2);
|
||||||
}
|
}
|
||||||
return vsprintf($translated, $args);
|
return vsprintf($translated, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
@ -534,7 +557,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @param mixed $args Array with arguments or multiple arguments in function
|
* @param mixed $args Array with arguments or multiple arguments in function
|
||||||
* @return plural form of translated string
|
* @return plural form of translated string
|
||||||
*/
|
*/
|
||||||
function __dn($domain, $singular, $plural, $count, $args = null) {
|
function __dn($domain, $singular, $plural, $count, $args = null) {
|
||||||
if (!$singular) {
|
if (!$singular) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -546,7 +569,7 @@ if (!function_exists('sortByKey')) {
|
||||||
$args = array_slice(func_get_args(), 4);
|
$args = array_slice(func_get_args(), 4);
|
||||||
}
|
}
|
||||||
return vsprintf($translated, $args);
|
return vsprintf($translated, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows you to override the current domain for a single message lookup.
|
* Allows you to override the current domain for a single message lookup.
|
||||||
|
@ -571,7 +594,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @param mixed $args Array with arguments or multiple arguments in function
|
* @param mixed $args Array with arguments or multiple arguments in function
|
||||||
* @return translated string
|
* @return translated string
|
||||||
*/
|
*/
|
||||||
function __dc($domain, $msg, $category, $args = null) {
|
function __dc($domain, $msg, $category, $args = null) {
|
||||||
if (!$msg) {
|
if (!$msg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -583,7 +606,7 @@ if (!function_exists('sortByKey')) {
|
||||||
$args = array_slice(func_get_args(), 3);
|
$args = array_slice(func_get_args(), 3);
|
||||||
}
|
}
|
||||||
return vsprintf($translated, $args);
|
return vsprintf($translated, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
@ -612,7 +635,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @param mixed $args Array with arguments or multiple arguments in function
|
* @param mixed $args Array with arguments or multiple arguments in function
|
||||||
* @return plural form of translated string
|
* @return plural form of translated string
|
||||||
*/
|
*/
|
||||||
function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
|
function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
|
||||||
if (!$singular) {
|
if (!$singular) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -624,7 +647,7 @@ if (!function_exists('sortByKey')) {
|
||||||
$args = array_slice(func_get_args(), 5);
|
$args = array_slice(func_get_args(), 5);
|
||||||
}
|
}
|
||||||
return vsprintf($translated, $args);
|
return vsprintf($translated, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
@ -645,7 +668,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @param mixed $args Array with arguments or multiple arguments in function
|
* @param mixed $args Array with arguments or multiple arguments in function
|
||||||
* @return translated string
|
* @return translated string
|
||||||
*/
|
*/
|
||||||
function __c($msg, $category, $args = null) {
|
function __c($msg, $category, $args = null) {
|
||||||
if (!$msg) {
|
if (!$msg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -657,19 +680,19 @@ if (!function_exists('sortByKey')) {
|
||||||
$args = array_slice(func_get_args(), 2);
|
$args = array_slice(func_get_args(), 2);
|
||||||
}
|
}
|
||||||
return vsprintf($translated, $args);
|
return vsprintf($translated, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut to Log::write.
|
* Shortcut to Log::write.
|
||||||
*
|
*
|
||||||
* @param string $message Message to write to log
|
* @param string $message Message to write to log
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches include path for files.
|
* Searches include path for files.
|
||||||
|
@ -678,7 +701,7 @@ if (!function_exists('sortByKey')) {
|
||||||
* @return Full path to file if exists, otherwise false
|
* @return Full path to file if exists, otherwise false
|
||||||
* @link http://book.cakephp.org/view/1131/fileExistsInPath
|
* @link http://book.cakephp.org/view/1131/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;
|
||||||
|
@ -690,7 +713,7 @@ if (!function_exists('sortByKey')) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -699,9 +722,9 @@ if (!function_exists('sortByKey')) {
|
||||||
* @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/view/1126/convertSlash
|
* @link http://book.cakephp.org/view/1126/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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue