Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make it possible to override all of basics.php

  • Loading branch information...
commit 99b798fa9a49c876721a9b6d60178f9c7e991f0c 1 parent 6664acb
@AD7six AD7six authored
Showing with 430 additions and 350 deletions.
  1. +430 −350 lib/Cake/basics.php
View
780 lib/Cake/basics.php
@@ -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,24 +42,28 @@
* @return boolean Success
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#config
*/
-function config() {
- $args = func_get_args();
- foreach ($args as $arg) {
- if (file_exists(APP . 'Config' . DS . $arg . '.php')) {
- include_once APP . 'Config' . DS . $arg . '.php';
-
- if (count($args) == 1) {
- return true;
- }
- } else {
- if (count($args) == 1) {
- return false;
+ function config() {
+ $args = func_get_args();
+ foreach ($args as $arg) {
+ if (file_exists(APP . 'Config' . DS . $arg . '.php')) {
+ include_once APP . 'Config' . DS . $arg . '.php';
+
+ if (count($args) == 1) {
+ return true;
+ }
+ } else {
+ if (count($args) == 1) {
+ return false;
+ }
}
}
+ return true;
}
- return true;
+
}
+if (!function_exists('debug')) {
+
/**
* Prints out debug information about given variable.
*
@@ -69,18 +75,18 @@ 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) {
- if (Configure::read('debug') > 0) {
- App::uses('Debugger', 'Utility');
- $file = '';
- $line = '';
- $lineInfo = '';
- if ($showFrom) {
- $trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
- $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
- $line = $trace[0]['line'];
- }
- $html = <<<HTML
+ function debug($var = false, $showHtml = null, $showFrom = true) {
+ if (Configure::read('debug') > 0) {
+ App::uses('Debugger', 'Utility');
+ $file = '';
+ $line = '';
+ $lineInfo = '';
+ if ($showFrom) {
+ $trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
+ $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
+ $line = $trace[0]['line'];
+ }
+ $html = <<<HTML
<div class="cake-debug-output">
%s
<pre class="cake-debug">
@@ -88,32 +94,34 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
</pre>
</div>
HTML;
- $text = <<<TEXT
+ $text = <<<TEXT
%s
########## DEBUG ##########
%s
###########################
TEXT;
- $template = $html;
- if (php_sapi_name() == 'cli' || $showHtml === false) {
- $template = $text;
- if ($showFrom) {
- $lineInfo = sprintf('%s (line %s)', $file, $line);
- }
- }
- if ($showHtml === null && $template !== $text) {
- $showHtml = true;
- }
- $var = Debugger::exportVar($var, 25);
- if ($showHtml) {
$template = $html;
- $var = h($var);
- if ($showFrom) {
- $lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
+ if (php_sapi_name() == 'cli' || $showHtml === false) {
+ $template = $text;
+ if ($showFrom) {
+ $lineInfo = sprintf('%s (line %s)', $file, $line);
+ }
+ }
+ if ($showHtml === null && $template !== $text) {
+ $showHtml = true;
}
+ $var = Debugger::exportVar($var, 25);
+ if ($showHtml) {
+ $template = $html;
+ $var = h($var);
+ if ($showFrom) {
+ $lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
+ }
+ }
+ printf($template, $lineInfo, $var);
}
- printf($template, $lineInfo, $var);
}
+
}
if (!function_exists('sortByKey')) {
@@ -151,6 +159,8 @@ function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
}
+if (!function_exists('h')) {
+
/**
* Convenience method for htmlspecialchars.
*
@@ -162,36 +172,40 @@ function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
* @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) {
- if (is_array($text)) {
- $texts = array();
- foreach ($text as $k => $t) {
- $texts[$k] = h($t, $double, $charset);
- }
- return $texts;
- } elseif (is_object($text)) {
- if (method_exists($text, '__toString')) {
- $text = (string)$text;
- } else {
- $text = '(object)' . get_class($text);
+ function h($text, $double = true, $charset = null) {
+ if (is_array($text)) {
+ $texts = array();
+ foreach ($text as $k => $t) {
+ $texts[$k] = h($t, $double, $charset);
+ }
+ return $texts;
+ } elseif (is_object($text)) {
+ if (method_exists($text, '__toString')) {
+ $text = (string)$text;
+ } else {
+ $text = '(object)' . get_class($text);
+ }
+ } elseif (is_bool($text)) {
+ return $text;
}
- } elseif (is_bool($text)) {
- return $text;
- }
- static $defaultCharset = false;
- if ($defaultCharset === false) {
- $defaultCharset = Configure::read('App.encoding');
- if ($defaultCharset === null) {
- $defaultCharset = 'UTF-8';
+ 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);
}
- if (is_string($double)) {
- $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,17 +218,21 @@ 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) {
- if (strpos($name, '.') !== false) {
- $parts = explode('.', $name, 2);
- if ($dotAppend) {
- $parts[0] .= '.';
+ function pluginSplit($name, $dotAppend = false, $plugin = null) {
+ if (strpos($name, '.') !== false) {
+ $parts = explode('.', $name, 2);
+ if ($dotAppend) {
+ $parts[0] .= '.';
+ }
+ 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
* 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) {
- if (Configure::read('debug') > 0) {
- echo '<pre>';
- print_r($var);
- echo '</pre>';
+ 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,18 +263,22 @@ 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() {
- $r = array();
- $args = func_get_args();
- foreach ($args as $a) {
- if (!is_array($a)) {
- $a = array($a);
- }
- $r = array_merge($r, $a);
+ function am() {
+ $r = array();
+ $args = func_get_args();
+ foreach ($args as $a) {
+ if (!is_array($a)) {
+ $a = array($a);
+ }
+ $r = array_merge($r, $a);
+ }
+ return $r;
}
- 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,105 +289,109 @@ 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) {
- if ($key === 'HTTPS') {
- if (isset($_SERVER['HTTPS'])) {
- return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
+ function env($key) {
+ if ($key === 'HTTPS') {
+ if (isset($_SERVER['HTTPS'])) {
+ 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';
+ 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);
- }
+ $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 ($key === 'REMOTE_ADDR' && $val === env('SERVER_ADDR')) {
+ $addr = env('HTTP_PC_REMOTE_ADDR');
+ if ($addr !== null) {
+ $val = $addr;
+ }
}
- }
- if ($val !== null) {
- return $val;
- }
+ if ($val !== null) {
+ return $val;
+ }
- switch ($key) {
- case 'SCRIPT_FILENAME':
- if (defined('SERVER_IIS') && SERVER_IIS === true) {

SERVER_IIS seems to be an undocumented or rather not anymore documented config switch, which was , according to the posts in the Cake's Google group, used in the past to change the behavior of Cake to circumvent how IIS sets some enviornment variables.

https://groups.google.com/forum/?fromgroups&nomobile=true#!searchin/cake-php/SERVER_IIS

I suggest we either document it properly or remove it.
I'd tend to the latter...

@markstory Owner

Removed in fe809cd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- 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($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)) {
+ 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($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;
+ array_shift($parts);
+ return '.' . implode('.', $parts);
+ break;
+ }
+ return null;
}
- return null;
+
}
+if (!function_exists('cache')) {
+
/**
* Reads/writes temporary data to cache files or session.
*
@@ -372,48 +402,52 @@ 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') {
- if (Configure::read('Cache.disable')) {
- return null;
- }
- $now = time();
+ function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
+ if (Configure::read('Cache.disable')) {
+ return null;
+ }
+ $now = time();
- if (!is_numeric($expires)) {
- $expires = strtotime($expires, $now);
- }
+ 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;
+ 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 (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);
+ 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, LOCK_EX);
}
- } elseif (is_writable(dirname($filename))) {
- @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
*
@@ -424,58 +458,62 @@ 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') {
- if (is_string($params) || $params === null) {
- $params = preg_replace('/\/\//', '/', $params);
- $cache = CACHE . $type . DS . $params;
+ function clearCache($params = null, $type = 'views', $ext = '.php') {
+ if (is_string($params) || $params === null) {
+ $params = preg_replace('/\/\//', '/', $params);
+ $cache = CACHE . $type . DS . $params;
- if (is_file($cache . $ext)) {
- @unlink($cache . $ext);
- return true;
- } elseif (is_dir($cache)) {
- $files = glob($cache . '*');
+ if (is_file($cache . $ext)) {
+ @unlink($cache . $ext);
+ return true;
+ } elseif (is_dir($cache)) {
+ $files = glob($cache . '*');
- if ($files === false) {
- return false;
- }
+ if ($files === false) {
+ return false;
+ }
- foreach ($files as $file) {
- if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
- @unlink($file);
+ 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);
+ 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);
+ 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) {
+ clearCache($file, $type, $ext);
}
return true;
}
- } elseif (is_array($params)) {
- foreach ($params as $file) {
- clearCache($file, $type, $ext);
- }
- return true;
+ return false;
}
- return false;
+
}
+if (!function_exists('stripslashes_deep')) {
+
/**
* Recursively strips slashes from all values in an array
*
@@ -483,17 +521,21 @@ 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) {
- if (is_array($values)) {
- foreach ($values as $key => $value) {
- $values[$key] = stripslashes_deep($value);
+ function stripslashes_deep($values) {
+ if (is_array($values)) {
+ foreach ($values as $key => $value) {
+ $values[$key] = stripslashes_deep($value);
+ }
+ } else {
+ $values = stripslashes($values);
}
- } else {
- $values = stripslashes($values);
+ return $values;
}
- return $values;
+
}
+if (!function_exists('__')) {
+
/**
* Returns a translated string if one is found; Otherwise, the submitted message.
*
@@ -502,21 +544,25 @@ 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) {
- if (!$singular) {
- return;
- }
+ function __($singular, $args = null) {
+ if (!$singular) {
+ 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);
+ 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);
}
- 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,21 +574,25 @@ 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) {
- if (!$singular) {
- return;
- }
+ function __n($singular, $plural, $count, $args = null) {
+ if (!$singular) {
+ 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);
+ 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);
}
- return vsprintf($translated, $args);
+
}
+if (!function_exists('__d')) {
+
/**
* Allows you to override the current domain for a single message lookup.
*
@@ -552,20 +602,24 @@ 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) {
- if (!$msg) {
- 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);
+ function __d($domain, $msg, $args = null) {
+ if (!$msg) {
+ 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);
}
- 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,20 +633,24 @@ 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) {
- if (!$singular) {
- 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);
+ function __dn($domain, $singular, $plural, $count, $args = null) {
+ if (!$singular) {
+ 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);
}
- 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,20 +675,24 @@ 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) {
- if (!$msg) {
- 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);
+ function __dc($domain, $msg, $category, $args = null) {
+ if (!$msg) {
+ 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);
}
- 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,20 +721,24 @@ 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) {
- if (!$singular) {
- 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);
+ function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
+ if (!$singular) {
+ 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);
}
- 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,20 +759,24 @@ 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) {
- if (!$msg) {
- 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);
+ function __c($msg, $category, $args = null) {
+ if (!$msg) {
+ 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);
}
- 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) {
- App::uses('CakeLog', 'Log');
- $bad = array("\n", "\r", "\t");
- $good = ' ';
- CakeLog::write('error', str_replace($bad, $good, $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,20 +802,24 @@ 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) {
- $paths = explode(PATH_SEPARATOR, ini_get('include_path'));
- foreach ($paths as $path) {
- $fullPath = $path . DS . $file;
-
- if (file_exists($fullPath)) {
- return $fullPath;
- } elseif (file_exists($file)) {
- return $file;
+ function fileExistsInPath($file) {
+ $paths = explode(PATH_SEPARATOR, ini_get('include_path'));
+ foreach ($paths as $path) {
+ $fullPath = $path . DS . $file;
+
+ if (file_exists($fullPath)) {
+ return $fullPath;
+ } elseif (file_exists($file)) {
+ return $file;
+ }
}
+ return false;
}
- 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) {
- $string = trim($string, '/');
- $string = preg_replace('/\/\//', '/', $string);
- $string = str_replace('/', '_', $string);
- return $string;
+ function convertSlash($string) {
+ $string = trim($string, '/');
+ $string = preg_replace('/\/\//', '/', $string);
+ $string = str_replace('/', '_', $string);
+ return $string;
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.