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,25 +41,25 @@
|
||||||
* @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')) {
|
||||||
include_once(CONFIGS . $arg . '.php');
|
include_once(CONFIGS . $arg . '.php');
|
||||||
} elseif (file_exists(CONFIGS . $arg . '.php')) {
|
} elseif (file_exists(CONFIGS . $arg . '.php')) {
|
||||||
include_once(CONFIGS . $arg . '.php');
|
include_once(CONFIGS . $arg . '.php');
|
||||||
|
|
||||||
if (count($args) == 1) {
|
if (count($args) == 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (count($args) == 1) {
|
if (count($args) == 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints out debug information about given variable.
|
* Prints out debug information about given variable.
|
||||||
|
@ -71,16 +72,16 @@
|
||||||
* @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 = '';
|
||||||
if ($showFrom) {
|
if ($showFrom) {
|
||||||
$calledFrom = debug_backtrace();
|
$calledFrom = debug_backtrace();
|
||||||
$file = substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1);
|
$file = substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1);
|
||||||
$line = $calledFrom[0]['line'];
|
$line = $calledFrom[0]['line'];
|
||||||
}
|
}
|
||||||
$html = <<<HTML
|
$html = <<<HTML
|
||||||
<strong>%s</strong> (line <strong>%s</strong>)
|
<strong>%s</strong> (line <strong>%s</strong>)
|
||||||
<pre class="cake-debug">
|
<pre class="cake-debug">
|
||||||
%s
|
%s
|
||||||
|
@ -94,32 +95,32 @@ HTML;
|
||||||
###########################
|
###########################
|
||||||
|
|
||||||
TEXT;
|
TEXT;
|
||||||
$template = $html;
|
$template = $html;
|
||||||
if (php_sapi_name() == 'cli') {
|
if (php_sapi_name() == 'cli') {
|
||||||
$template = $text;
|
$template = $text;
|
||||||
}
|
|
||||||
if ($showHtml === null && $template !== $text) {
|
|
||||||
$showHtml = true;
|
|
||||||
}
|
|
||||||
$var = print_r($var, true);
|
|
||||||
if ($showHtml) {
|
|
||||||
$var = str_replace(array('<', '>'), array('<', '>'), $var);
|
|
||||||
}
|
|
||||||
printf($template, $file, $line, $var);
|
|
||||||
}
|
}
|
||||||
|
if ($showHtml === null && $template !== $text) {
|
||||||
|
$showHtml = true;
|
||||||
|
}
|
||||||
|
$var = print_r($var, true);
|
||||||
|
if ($showHtml) {
|
||||||
|
$var = str_replace(array('<', '>'), array('<', '>'), $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
|
||||||
* @param string $sortby Sort by this key
|
* @param string $sortby Sort by this key
|
||||||
* @param string $order Sort order asc/desc (ascending or descending).
|
* @param string $order Sort order asc/desc (ascending or descending).
|
||||||
* @param integer $type Type of sorting to perform
|
* @param integer $type Type of sorting to perform
|
||||||
* @return mixed Sorted array
|
* @return mixed Sorted array
|
||||||
*/
|
*/
|
||||||
function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
|
function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
|
||||||
if (!is_array($array)) {
|
if (!is_array($array)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -151,28 +152,28 @@ 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) {
|
||||||
$texts[$k] = h($t, $double, $charset);
|
$texts[$k] = h($t, $double, $charset);
|
||||||
}
|
|
||||||
return $texts;
|
|
||||||
}
|
}
|
||||||
|
return $texts;
|
||||||
static $defaultCharset = false;
|
|
||||||
if ($defaultCharset === false) {
|
|
||||||
$defaultCharset = Configure::read('App.encoding');
|
|
||||||
if ($defaultCharset === null) {
|
|
||||||
$defaultCharset = 'UTF-8';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is_string($double)) {
|
|
||||||
$charset = $double;
|
|
||||||
}
|
|
||||||
return htmlspecialchars($text, ENT_QUOTES, ($charset) ? $charset : $defaultCharset, $double);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static $defaultCharset = false;
|
||||||
|
if ($defaultCharset === false) {
|
||||||
|
$defaultCharset = Configure::read('App.encoding');
|
||||||
|
if ($defaultCharset === null) {
|
||||||
|
$defaultCharset = 'UTF-8';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_string($double)) {
|
||||||
|
$charset = $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.
|
||||||
* 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.
|
||||||
|
@ -184,16 +185,16 @@ 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) {
|
||||||
$parts[0] .= '.';
|
$parts[0] .= '.';
|
||||||
}
|
|
||||||
return $parts;
|
|
||||||
}
|
}
|
||||||
return array($plugin, $name);
|
return $parts;
|
||||||
}
|
}
|
||||||
|
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,17 +222,17 @@ 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) {
|
||||||
if (!is_array($a)) {
|
if (!is_array($a)) {
|
||||||
$a = array($a);
|
$a = array($a);
|
||||||
}
|
|
||||||
$r = array_merge($r, $a);
|
|
||||||
}
|
}
|
||||||
return $r;
|
$r = array_merge($r, $a);
|
||||||
}
|
}
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an environment variable from available sources, and provides emulation
|
* Gets an environment variable from available sources, and provides emulation
|
||||||
|
@ -243,83 +244,105 @@ 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');
|
||||||
}
|
|
||||||
return (strpos(env('SCRIPT_URI'), 'https://') === 0);
|
|
||||||
}
|
}
|
||||||
|
return (strpos(env('SCRIPT_URI'), 'https://') === 0);
|
||||||
if ($key === 'SCRIPT_NAME') {
|
|
||||||
if (env('CGI_MODE') && isset($_ENV['SCRIPT_URL'])) {
|
|
||||||
$key = 'SCRIPT_URL';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$val = null;
|
|
||||||
if (isset($_SERVER[$key])) {
|
|
||||||
$val = $_SERVER[$key];
|
|
||||||
} elseif (isset($_ENV[$key])) {
|
|
||||||
$val = $_ENV[$key];
|
|
||||||
} elseif (getenv($key) !== false) {
|
|
||||||
$val = getenv($key);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($key === 'REMOTE_ADDR' && $val === env('SERVER_ADDR')) {
|
|
||||||
$addr = env('HTTP_PC_REMOTE_ADDR');
|
|
||||||
if ($addr !== null) {
|
|
||||||
$val = $addr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($val !== null) {
|
|
||||||
return $val;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($key) {
|
|
||||||
case 'SCRIPT_FILENAME':
|
|
||||||
if (defined('SERVER_IIS') && SERVER_IIS === true) {
|
|
||||||
return str_replace('\\\\', '\\', env('PATH_TRANSLATED'));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'DOCUMENT_ROOT':
|
|
||||||
$name = env('SCRIPT_NAME');
|
|
||||||
$filename = env('SCRIPT_FILENAME');
|
|
||||||
$offset = 0;
|
|
||||||
if (!strpos($name, '.php')) {
|
|
||||||
$offset = 4;
|
|
||||||
}
|
|
||||||
return substr($filename, 0, strlen($filename) - (strlen($name) + $offset));
|
|
||||||
break;
|
|
||||||
case 'PHP_SELF':
|
|
||||||
return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
|
|
||||||
break;
|
|
||||||
case 'CGI_MODE':
|
|
||||||
return (PHP_SAPI === 'cgi');
|
|
||||||
break;
|
|
||||||
case 'HTTP_BASE':
|
|
||||||
$host = env('HTTP_HOST');
|
|
||||||
$parts = explode('.', $host);
|
|
||||||
$count = count($parts);
|
|
||||||
|
|
||||||
if ($count === 1) {
|
|
||||||
return '.' . $host;
|
|
||||||
} elseif ($count === 2) {
|
|
||||||
return '.' . $host;
|
|
||||||
} 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');
|
|
||||||
if (in_array($parts[1], $gTLD)) {
|
|
||||||
return '.' . $host;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
array_shift($parts);
|
|
||||||
return '.' . implode('.', $parts);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($key === 'SCRIPT_NAME') {
|
||||||
|
if (env('CGI_MODE') && isset($_ENV['SCRIPT_URL'])) {
|
||||||
|
$key = 'SCRIPT_URL';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$val = null;
|
||||||
|
if (isset($_SERVER[$key])) {
|
||||||
|
$val = $_SERVER[$key];
|
||||||
|
} elseif (isset($_ENV[$key])) {
|
||||||
|
$val = $_ENV[$key];
|
||||||
|
} elseif (getenv($key) !== false) {
|
||||||
|
$val = getenv($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($key === 'REMOTE_ADDR' && $val === env('SERVER_ADDR')) {
|
||||||
|
$addr = env('HTTP_PC_REMOTE_ADDR');
|
||||||
|
if ($addr !== null) {
|
||||||
|
$val = $addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($val !== null) {
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($key) {
|
||||||
|
case 'SCRIPT_FILENAME':
|
||||||
|
if (defined('SERVER_IIS') && SERVER_IIS === true) {
|
||||||
|
return str_replace('\\\\', '\\', env('PATH_TRANSLATED'));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'DOCUMENT_ROOT':
|
||||||
|
$name = env('SCRIPT_NAME');
|
||||||
|
$filename = env('SCRIPT_FILENAME');
|
||||||
|
$offset = 0;
|
||||||
|
if (!strpos($name, '.php')) {
|
||||||
|
$offset = 4;
|
||||||
|
}
|
||||||
|
return substr($filename, 0, strlen($filename) - (strlen($name) + $offset));
|
||||||
|
break;
|
||||||
|
case 'PHP_SELF':
|
||||||
|
return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
|
||||||
|
break;
|
||||||
|
case 'CGI_MODE':
|
||||||
|
return (PHP_SAPI === 'cgi');
|
||||||
|
break;
|
||||||
|
case 'HTTP_BASE':
|
||||||
|
$host = env('HTTP_HOST');
|
||||||
|
$parts = explode('.', $host);
|
||||||
|
$count = count($parts);
|
||||||
|
|
||||||
|
if ($count === 1) {
|
||||||
|
return '.' . $host;
|
||||||
|
} elseif ($count === 2) {
|
||||||
|
return '.' . $host;
|
||||||
|
} 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'
|
||||||
|
);
|
||||||
|
if (in_array($parts[1], $gTLD)) {
|
||||||
|
return '.' . $host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array_shift($parts);
|
||||||
|
return '.' . implode('.', $parts);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads/writes temporary data to cache files or session.
|
* Reads/writes temporary data to cache files or session.
|
||||||
*
|
*
|
||||||
|
@ -330,47 +353,47 @@ 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;
|
||||||
}
|
|
||||||
$now = time();
|
|
||||||
|
|
||||||
if (!is_numeric($expires)) {
|
|
||||||
$expires = strtotime($expires, $now);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (strtolower($target)) {
|
|
||||||
case 'cache':
|
|
||||||
$filename = CACHE . $path;
|
|
||||||
break;
|
|
||||||
case 'public':
|
|
||||||
$filename = WWW_ROOT . $path;
|
|
||||||
break;
|
|
||||||
case 'tmp':
|
|
||||||
$filename = TMP . $path;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$timediff = $expires - $now;
|
|
||||||
$filetime = false;
|
|
||||||
|
|
||||||
if (file_exists($filename)) {
|
|
||||||
$filetime = @filemtime($filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($data === null) {
|
|
||||||
if (file_exists($filename) && $filetime !== false) {
|
|
||||||
if ($filetime + $timediff < $now) {
|
|
||||||
@unlink($filename);
|
|
||||||
} else {
|
|
||||||
$data = @file_get_contents($filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif (is_writable(dirname($filename))) {
|
|
||||||
@file_put_contents($filename, $data);
|
|
||||||
}
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
if (!is_numeric($expires)) {
|
||||||
|
$expires = strtotime($expires, $now);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (strtolower($target)) {
|
||||||
|
case 'cache':
|
||||||
|
$filename = CACHE . $path;
|
||||||
|
break;
|
||||||
|
case 'public':
|
||||||
|
$filename = WWW_ROOT . $path;
|
||||||
|
break;
|
||||||
|
case 'tmp':
|
||||||
|
$filename = TMP . $path;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$timediff = $expires - $now;
|
||||||
|
$filetime = false;
|
||||||
|
|
||||||
|
if (file_exists($filename)) {
|
||||||
|
$filetime = @filemtime($filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data === null) {
|
||||||
|
if (file_exists($filename) && $filetime !== false) {
|
||||||
|
if ($filetime + $timediff < $now) {
|
||||||
|
@unlink($filename);
|
||||||
|
} else {
|
||||||
|
$data = @file_get_contents($filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif (is_writable(dirname($filename))) {
|
||||||
|
@file_put_contents($filename, $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,57 +405,57 @@ 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;
|
||||||
|
|
||||||
if (is_file($cache . $ext)) {
|
if (is_file($cache . $ext)) {
|
||||||
@unlink($cache . $ext);
|
@unlink($cache . $ext);
|
||||||
return true;
|
return true;
|
||||||
} elseif (is_dir($cache)) {
|
} elseif (is_dir($cache)) {
|
||||||
$files = glob($cache . '*');
|
$files = glob($cache . '*');
|
||||||
|
|
||||||
if ($files === false) {
|
if ($files === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
|
|
||||||
@unlink($file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
$cache = array(
|
|
||||||
CACHE . $type . DS . '*' . $params . $ext,
|
|
||||||
CACHE . $type . DS . '*' . $params . '_*' . $ext
|
|
||||||
);
|
|
||||||
$files = array();
|
|
||||||
while ($search = array_shift($cache)) {
|
|
||||||
$results = glob($search);
|
|
||||||
if ($results !== false) {
|
|
||||||
$files = array_merge($files, $results);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (empty($files)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
|
|
||||||
@unlink($file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
} elseif (is_array($params)) {
|
|
||||||
foreach ($params as $file) {
|
foreach ($files as $file) {
|
||||||
clearCache($file, $type, $ext);
|
if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
|
||||||
|
@unlink($file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$cache = array(
|
||||||
|
CACHE . $type . DS . '*' . $params . $ext,
|
||||||
|
CACHE . $type . DS . '*' . $params . '_*' . $ext
|
||||||
|
);
|
||||||
|
$files = array();
|
||||||
|
while ($search = array_shift($cache)) {
|
||||||
|
$results = glob($search);
|
||||||
|
if ($results !== false) {
|
||||||
|
$files = array_merge($files, $results);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($files)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
|
||||||
|
@unlink($file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
} elseif (is_array($params)) {
|
||||||
|
foreach ($params as $file) {
|
||||||
|
clearCache($file, $type, $ext);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively strips slashes from all values in an array
|
* Recursively strips slashes from all values in an array
|
||||||
|
@ -441,16 +464,16 @@ 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);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$values = stripslashes($values);
|
|
||||||
}
|
}
|
||||||
return $values;
|
} else {
|
||||||
|
$values = stripslashes($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,21 +483,21 @@ 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;
|
||||||
}
|
|
||||||
|
|
||||||
App::uses('I18n', 'I18n');
|
|
||||||
$translated = I18n::translate($singular);
|
|
||||||
if ($args === null) {
|
|
||||||
return $translated;
|
|
||||||
} elseif (!is_array($args)) {
|
|
||||||
$args = array_slice(func_get_args(), 1);
|
|
||||||
}
|
|
||||||
return vsprintf($translated, $args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App::uses('I18n', 'I18n');
|
||||||
|
$translated = I18n::translate($singular);
|
||||||
|
if ($args === null) {
|
||||||
|
return $translated;
|
||||||
|
} elseif (!is_array($args)) {
|
||||||
|
$args = array_slice(func_get_args(), 1);
|
||||||
|
}
|
||||||
|
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.
|
||||||
* 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.
|
||||||
|
@ -485,21 +508,21 @@ 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;
|
||||||
}
|
|
||||||
|
|
||||||
App::uses('I18n', 'I18n');
|
|
||||||
$translated = I18n::translate($singular, $plural, null, 6, $count);
|
|
||||||
if ($args === null) {
|
|
||||||
return $translated;
|
|
||||||
} elseif (!is_array($args)) {
|
|
||||||
$args = array_slice(func_get_args(), 3);
|
|
||||||
}
|
|
||||||
return vsprintf($translated, $args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App::uses('I18n', 'I18n');
|
||||||
|
$translated = I18n::translate($singular, $plural, null, 6, $count);
|
||||||
|
if ($args === null) {
|
||||||
|
return $translated;
|
||||||
|
} elseif (!is_array($args)) {
|
||||||
|
$args = array_slice(func_get_args(), 3);
|
||||||
|
}
|
||||||
|
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,19 +531,19 @@ 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;
|
||||||
}
|
|
||||||
App::uses('I18n', 'I18n');
|
|
||||||
$translated = I18n::translate($msg, null, $domain);
|
|
||||||
if ($args === null) {
|
|
||||||
return $translated;
|
|
||||||
} elseif (!is_array($args)) {
|
|
||||||
$args = array_slice(func_get_args(), 2);
|
|
||||||
}
|
|
||||||
return vsprintf($translated, $args);
|
|
||||||
}
|
}
|
||||||
|
App::uses('I18n', 'I18n');
|
||||||
|
$translated = I18n::translate($msg, null, $domain);
|
||||||
|
if ($args === null) {
|
||||||
|
return $translated;
|
||||||
|
} elseif (!is_array($args)) {
|
||||||
|
$args = array_slice(func_get_args(), 2);
|
||||||
|
}
|
||||||
|
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,19 +557,19 @@ 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;
|
||||||
}
|
|
||||||
App::uses('I18n', 'I18n');
|
|
||||||
$translated = I18n::translate($singular, $plural, $domain, 6, $count);
|
|
||||||
if ($args === null) {
|
|
||||||
return $translated;
|
|
||||||
} elseif (!is_array($args)) {
|
|
||||||
$args = array_slice(func_get_args(), 4);
|
|
||||||
}
|
|
||||||
return vsprintf($translated, $args);
|
|
||||||
}
|
}
|
||||||
|
App::uses('I18n', 'I18n');
|
||||||
|
$translated = I18n::translate($singular, $plural, $domain, 6, $count);
|
||||||
|
if ($args === null) {
|
||||||
|
return $translated;
|
||||||
|
} elseif (!is_array($args)) {
|
||||||
|
$args = array_slice(func_get_args(), 4);
|
||||||
|
}
|
||||||
|
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,19 +594,19 @@ 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;
|
||||||
}
|
|
||||||
App::uses('I18n', 'I18n');
|
|
||||||
$translated = I18n::translate($msg, null, $domain, $category);
|
|
||||||
if ($args === null) {
|
|
||||||
return $translated;
|
|
||||||
} elseif (!is_array($args)) {
|
|
||||||
$args = array_slice(func_get_args(), 3);
|
|
||||||
}
|
|
||||||
return vsprintf($translated, $args);
|
|
||||||
}
|
}
|
||||||
|
App::uses('I18n', 'I18n');
|
||||||
|
$translated = I18n::translate($msg, null, $domain, $category);
|
||||||
|
if ($args === null) {
|
||||||
|
return $translated;
|
||||||
|
} elseif (!is_array($args)) {
|
||||||
|
$args = array_slice(func_get_args(), 3);
|
||||||
|
}
|
||||||
|
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,19 +635,19 @@ 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;
|
||||||
}
|
|
||||||
App::uses('I18n', 'I18n');
|
|
||||||
$translated = I18n::translate($singular, $plural, $domain, $category, $count);
|
|
||||||
if ($args === null) {
|
|
||||||
return $translated;
|
|
||||||
} elseif (!is_array($args)) {
|
|
||||||
$args = array_slice(func_get_args(), 5);
|
|
||||||
}
|
|
||||||
return vsprintf($translated, $args);
|
|
||||||
}
|
}
|
||||||
|
App::uses('I18n', 'I18n');
|
||||||
|
$translated = I18n::translate($singular, $plural, $domain, $category, $count);
|
||||||
|
if ($args === null) {
|
||||||
|
return $translated;
|
||||||
|
} elseif (!is_array($args)) {
|
||||||
|
$args = array_slice(func_get_args(), 5);
|
||||||
|
}
|
||||||
|
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,31 +668,31 @@ 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;
|
||||||
}
|
|
||||||
App::uses('I18n', 'I18n');
|
|
||||||
$translated = I18n::translate($msg, null, null, $category);
|
|
||||||
if ($args === null) {
|
|
||||||
return $translated;
|
|
||||||
} elseif (!is_array($args)) {
|
|
||||||
$args = array_slice(func_get_args(), 2);
|
|
||||||
}
|
|
||||||
return vsprintf($translated, $args);
|
|
||||||
}
|
}
|
||||||
|
App::uses('I18n', 'I18n');
|
||||||
|
$translated = I18n::translate($msg, null, null, $category);
|
||||||
|
if ($args === null) {
|
||||||
|
return $translated;
|
||||||
|
} elseif (!is_array($args)) {
|
||||||
|
$args = array_slice(func_get_args(), 2);
|
||||||
|
}
|
||||||
|
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,19 +701,19 @@ 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;
|
||||||
|
|
||||||
if (file_exists($fullPath)) {
|
if (file_exists($fullPath)) {
|
||||||
return $fullPath;
|
return $fullPath;
|
||||||
} elseif (file_exists($file)) {
|
} elseif (file_exists($file)) {
|
||||||
return $file;
|
return $file;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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