2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2013-10-09 23:38:16 +00:00
|
|
|
* Basic CakePHP functionality.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Core functions for including other source files, loading models and so forth.
|
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2008-05-30 11:40:08 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 0.2.9
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Basic defines for timing functions.
|
|
|
|
*/
|
|
|
|
define('SECOND', 1);
|
2010-01-20 12:39:26 +00:00
|
|
|
define('MINUTE', 60);
|
|
|
|
define('HOUR', 3600);
|
|
|
|
define('DAY', 86400);
|
|
|
|
define('WEEK', 604800);
|
|
|
|
define('MONTH', 2592000);
|
|
|
|
define('YEAR', 31536000);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('config')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Loads configuration files. Receives a set of configuration files
|
|
|
|
* to load.
|
|
|
|
* Example:
|
2009-09-07 04:18:08 +00:00
|
|
|
*
|
|
|
|
* `config('config1', 'config2');`
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#config
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function config() {
|
|
|
|
$args = func_get_args();
|
2012-09-14 18:26:00 +00:00
|
|
|
$count = count($args);
|
|
|
|
$included = 0;
|
2012-09-05 14:43:24 +00:00
|
|
|
foreach ($args as $arg) {
|
|
|
|
if (file_exists(APP . 'Config' . DS . $arg . '.php')) {
|
|
|
|
include_once APP . 'Config' . DS . $arg . '.php';
|
2012-09-14 18:26:00 +00:00
|
|
|
$included++;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-14 18:26:00 +00:00
|
|
|
return $included === $count;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('debug')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Prints out debug information about given variable.
|
|
|
|
*
|
2008-10-31 19:44:23 +00:00
|
|
|
* Only runs if debug level is greater than zero.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2013-09-25 19:53:23 +00:00
|
|
|
* @param mixed $var Variable to show debug information for.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param bool $showHtml If set to true, the method prints the debug data in a browser-friendly way.
|
|
|
|
* @param bool $showFrom If set to true, the method prints from where the function was called.
|
2013-07-05 15:19:22 +00:00
|
|
|
* @return void
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/development/debugging.html#basic-debugging
|
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#debug
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-10-12 14:14:17 +00:00
|
|
|
function debug($var, $showHtml = null, $showFrom = true) {
|
2014-07-09 23:49:28 +00:00
|
|
|
if (!Configure::read('debug')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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
|
2011-09-02 15:45:09 +00:00
|
|
|
<div class="cake-debug-output">
|
2011-11-04 13:58:06 +00:00
|
|
|
%s
|
2010-10-24 22:23:27 +00:00
|
|
|
<pre class="cake-debug">
|
|
|
|
%s
|
|
|
|
</pre>
|
2011-09-02 15:45:09 +00:00
|
|
|
</div>
|
2010-10-24 22:23:27 +00:00
|
|
|
HTML;
|
2014-07-09 23:49:28 +00:00
|
|
|
$text = <<<TEXT
|
2011-11-04 13:58:06 +00:00
|
|
|
%s
|
2010-10-24 22:23:27 +00:00
|
|
|
########## DEBUG ##########
|
|
|
|
%s
|
|
|
|
###########################
|
2013-05-28 11:57:59 +00:00
|
|
|
|
2010-10-24 22:23:27 +00:00
|
|
|
TEXT;
|
2014-07-09 23:49:28 +00:00
|
|
|
$template = $html;
|
2015-07-26 13:35:03 +00:00
|
|
|
if (PHP_SAPI === 'cli' || $showHtml === false) {
|
2014-07-09 23:49:28 +00:00
|
|
|
$template = $text;
|
|
|
|
if ($showFrom) {
|
|
|
|
$lineInfo = sprintf('%s (line %s)', $file, $line);
|
2011-11-04 13:58:06 +00:00
|
|
|
}
|
2014-07-09 23:49:28 +00:00
|
|
|
}
|
|
|
|
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);
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2014-07-09 23:49:28 +00:00
|
|
|
printf($template, $lineInfo, $var);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('stackTrace')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs a stack trace based on the supplied options.
|
|
|
|
*
|
|
|
|
* ### Options
|
|
|
|
*
|
|
|
|
* - `depth` - The number of stack frames to return. Defaults to 999
|
|
|
|
* - `args` - Should arguments for functions be shown? If true, the arguments for each method call
|
|
|
|
* will be displayed.
|
|
|
|
* - `start` - The stack frame to start generating a trace from. Defaults to 1
|
|
|
|
*
|
|
|
|
* @param array $options Format for outputting stack trace
|
|
|
|
* @return mixed Formatted stack trace
|
|
|
|
* @see Debugger::trace()
|
|
|
|
*/
|
|
|
|
function stackTrace(array $options = array()) {
|
|
|
|
if (!Configure::read('debug')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
App::uses('Debugger', 'Utility');
|
|
|
|
|
|
|
|
$options += array('start' => 0);
|
|
|
|
$options['start']++;
|
|
|
|
echo Debugger::trace($options);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2010-10-24 22:23:27 +00:00
|
|
|
|
2008-09-18 03:09:19 +00:00
|
|
|
if (!function_exists('sortByKey')) {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-03-05 03:49:38 +00:00
|
|
|
/**
|
2013-10-23 15:28:48 +00:00
|
|
|
* Sorts given $array by key $sortBy.
|
2012-03-05 03:49:38 +00:00
|
|
|
*
|
2014-06-01 01:53:54 +00:00
|
|
|
* @param array &$array Array to sort
|
2013-10-23 15:28:48 +00:00
|
|
|
* @param string $sortBy Sort by this key
|
2013-07-05 12:36:40 +00:00
|
|
|
* @param string $order Sort order asc/desc (ascending or descending).
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $type Type of sorting to perform
|
2014-11-05 12:03:27 +00:00
|
|
|
* @return array|null Sorted array, or null if not an array.
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#sortByKey
|
2012-03-05 03:49:38 +00:00
|
|
|
*/
|
2013-10-23 15:28:48 +00:00
|
|
|
function sortByKey(&$array, $sortBy, $order = 'asc', $type = SORT_NUMERIC) {
|
2008-09-18 03:09:19 +00:00
|
|
|
if (!is_array($array)) {
|
|
|
|
return null;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-09-18 03:09:19 +00:00
|
|
|
foreach ($array as $key => $val) {
|
2013-10-23 15:28:48 +00:00
|
|
|
$sa[$key] = $val[$sortBy];
|
2008-09-18 03:09:19 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-02-12 02:38:08 +00:00
|
|
|
if ($order === 'asc') {
|
2008-09-18 03:09:19 +00:00
|
|
|
asort($sa, $type);
|
|
|
|
} else {
|
|
|
|
arsort($sa, $type);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-09-18 03:09:19 +00:00
|
|
|
foreach ($sa as $key => $val) {
|
|
|
|
$out[] = $array[$key];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-09-18 03:09:19 +00:00
|
|
|
return $out;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-03-11 03:30:56 +00:00
|
|
|
|
2008-09-18 03:09:19 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('h')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for htmlspecialchars.
|
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* @param string|array|object $text Text to wrap through htmlspecialchars. Also works with arrays, and objects.
|
|
|
|
* Arrays will be mapped and have all their elements escaped. Objects will be string cast if they
|
|
|
|
* implement a `__toString` method. Otherwise the class name will be used.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param bool $double Encode existing html entities
|
2012-12-22 22:48:15 +00:00
|
|
|
* @param string $charset Character set to use when escaping. Defaults to config value in 'App.encoding' or 'UTF-8'
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Wrapped text
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#h
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function h($text, $double = true, $charset = null) {
|
2014-07-10 11:53:10 +00:00
|
|
|
if (is_string($text)) {
|
|
|
|
//optimize for strings
|
|
|
|
} elseif (is_array($text)) {
|
2012-09-05 14:43:24 +00:00
|
|
|
$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;
|
2011-10-28 01:28:42 +00:00
|
|
|
}
|
2010-01-19 11:31:27 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
static $defaultCharset = false;
|
|
|
|
if ($defaultCharset === false) {
|
|
|
|
$defaultCharset = Configure::read('App.encoding');
|
|
|
|
if ($defaultCharset === null) {
|
|
|
|
$defaultCharset = 'UTF-8';
|
|
|
|
}
|
2010-10-12 02:26:41 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
if (is_string($double)) {
|
|
|
|
$charset = $double;
|
|
|
|
}
|
|
|
|
return htmlspecialchars($text, ENT_QUOTES, ($charset) ? $charset : $defaultCharset, $double);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('pluginSplit')) {
|
|
|
|
|
2009-11-15 23:16:12 +00:00
|
|
|
/**
|
2013-10-23 02:59:50 +00:00
|
|
|
* Splits a dot syntax plugin name into its plugin and class name.
|
2009-11-15 23:16:12 +00:00
|
|
|
* If $name does not have a dot, then index 0 will be null.
|
|
|
|
*
|
2009-11-16 00:12:00 +00:00
|
|
|
* Commonly used like `list($plugin, $name) = pluginSplit($name);`
|
2009-11-15 23:16:12 +00:00
|
|
|
*
|
|
|
|
* @param string $name The name you want to plugin split.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param bool $dotAppend Set to true if you want the plugin to have a '.' appended to it.
|
2009-11-16 00:54:33 +00:00
|
|
|
* @param string $plugin Optional default plugin to use if no plugin is found. Defaults to null.
|
2013-10-23 02:59:50 +00:00
|
|
|
* @return array Array with 2 indexes. 0 => plugin name, 1 => class name
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#pluginSplit
|
2009-11-15 23:16:12 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function pluginSplit($name, $dotAppend = false, $plugin = null) {
|
|
|
|
if (strpos($name, '.') !== false) {
|
|
|
|
$parts = explode('.', $name, 2);
|
|
|
|
if ($dotAppend) {
|
|
|
|
$parts[0] .= '.';
|
|
|
|
}
|
|
|
|
return $parts;
|
2009-11-15 23:16:12 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
return array($plugin, $name);
|
2009-11-15 23:16:12 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-11-15 23:16:12 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('pr')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2013-02-16 12:12:39 +00:00
|
|
|
* print_r() convenience function
|
2013-05-28 11:57:59 +00:00
|
|
|
*
|
|
|
|
* In terminals this will act the same as using print_r() directly, when not run on cli
|
2013-02-16 12:12:39 +00:00
|
|
|
* print_r() will wrap <PRE> tags around the output of given array. Similar to debug().
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2014-04-02 21:52:11 +00:00
|
|
|
* @param mixed $var Variable to print out
|
2013-07-05 15:19:22 +00:00
|
|
|
* @return void
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#pr
|
2014-06-01 01:53:54 +00:00
|
|
|
* @see debug()
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function pr($var) {
|
|
|
|
if (Configure::read('debug') > 0) {
|
2015-07-26 13:35:03 +00:00
|
|
|
$template = PHP_SAPI !== 'cli' ? '<pre>%s</pre>' : "\n%s\n";
|
2013-09-11 01:52:18 +00:00
|
|
|
printf($template, print_r($var, true));
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('am')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Merge a group of arrays
|
|
|
|
*
|
2014-06-01 01:53:54 +00:00
|
|
|
* Accepts variable arguments. Each argument will be converted into an array and then merged.
|
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return array All array parameters merged into one
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#am
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
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;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('env')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Gets an environment variable from available sources, and provides emulation
|
2008-10-31 19:44:23 +00:00
|
|
|
* for unsupported or inconsistent environment variables (i.e. DOCUMENT_ROOT on
|
2012-12-22 22:48:15 +00:00
|
|
|
* IIS, or SCRIPT_NAME in CGI mode). Also exposes some additional custom
|
2008-05-30 11:40:08 +00:00
|
|
|
* environment information.
|
|
|
|
*
|
2013-07-05 12:15:18 +00:00
|
|
|
* @param string $key Environment variable name.
|
2014-11-05 12:03:27 +00:00
|
|
|
* @return string|bool|null Environment variable setting.
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#env
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function env($key) {
|
|
|
|
if ($key === 'HTTPS') {
|
|
|
|
if (isset($_SERVER['HTTPS'])) {
|
|
|
|
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
|
|
|
|
}
|
|
|
|
return (strpos(env('SCRIPT_URI'), 'https://') === 0);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if ($key === 'SCRIPT_NAME') {
|
|
|
|
if (env('CGI_MODE') && isset($_ENV['SCRIPT_URL'])) {
|
|
|
|
$key = 'SCRIPT_URL';
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
$val = null;
|
|
|
|
if (isset($_SERVER[$key])) {
|
|
|
|
$val = $_SERVER[$key];
|
|
|
|
} elseif (isset($_ENV[$key])) {
|
|
|
|
$val = $_ENV[$key];
|
|
|
|
} elseif (getenv($key) !== false) {
|
|
|
|
$val = getenv($key);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if ($key === 'REMOTE_ADDR' && $val === env('SERVER_ADDR')) {
|
|
|
|
$addr = env('HTTP_PC_REMOTE_ADDR');
|
|
|
|
if ($addr !== null) {
|
|
|
|
$val = $addr;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if ($val !== null) {
|
|
|
|
return $val;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
switch ($key) {
|
|
|
|
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));
|
|
|
|
case 'PHP_SELF':
|
|
|
|
return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
|
|
|
|
case 'CGI_MODE':
|
|
|
|
return (PHP_SAPI === 'cgi');
|
|
|
|
case 'HTTP_BASE':
|
|
|
|
$host = env('HTTP_HOST');
|
|
|
|
$parts = explode('.', $host);
|
|
|
|
$count = count($parts);
|
|
|
|
|
|
|
|
if ($count === 1) {
|
2011-01-14 22:14:22 +00:00
|
|
|
return '.' . $host;
|
2012-09-05 14:43:24 +00:00
|
|
|
} 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;
|
|
|
|
}
|
2008-09-29 18:01:52 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
array_shift($parts);
|
|
|
|
return '.' . implode('.', $parts);
|
|
|
|
}
|
|
|
|
return null;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('cache')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Reads/writes temporary data to cache files or session.
|
|
|
|
*
|
2013-07-05 12:15:18 +00:00
|
|
|
* @param string $path File path within /tmp to save the file.
|
|
|
|
* @param mixed $data The data to save to the temporary file.
|
|
|
|
* @param mixed $expires A valid strtotime string when the data expires.
|
|
|
|
* @param string $target The target of the cached data; either 'cache' or 'public'.
|
|
|
|
* @return mixed The contents of the temporary file.
|
2014-09-02 15:03:22 +00:00
|
|
|
* @deprecated 3.0.0 Will be removed in 3.0. Please use Cache::write() instead.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
|
|
|
|
if (Configure::read('Cache.disable')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$now = time();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!is_numeric($expires)) {
|
|
|
|
$expires = strtotime($expires, $now);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
switch (strtolower($target)) {
|
|
|
|
case 'cache':
|
|
|
|
$filename = CACHE . $path;
|
2013-07-02 22:52:48 +00:00
|
|
|
break;
|
2012-09-05 14:43:24 +00:00
|
|
|
case 'public':
|
|
|
|
$filename = WWW_ROOT . $path;
|
2013-07-02 22:52:48 +00:00
|
|
|
break;
|
2012-09-05 14:43:24 +00:00
|
|
|
case 'tmp':
|
|
|
|
$filename = TMP . $path;
|
2013-07-02 22:52:48 +00:00
|
|
|
break;
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
|
|
|
$timediff = $expires - $now;
|
|
|
|
$filetime = false;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (file_exists($filename)) {
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreStart
|
2012-09-05 14:43:24 +00:00
|
|
|
$filetime = @filemtime($filename);
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreEnd
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if ($data === null) {
|
|
|
|
if (file_exists($filename) && $filetime !== false) {
|
|
|
|
if ($filetime + $timediff < $now) {
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreStart
|
2012-09-05 14:43:24 +00:00
|
|
|
@unlink($filename);
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreEnd
|
2012-09-05 14:43:24 +00:00
|
|
|
} else {
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreStart
|
2012-09-05 14:43:24 +00:00
|
|
|
$data = @file_get_contents($filename);
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreEnd
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
} elseif (is_writable(dirname($filename))) {
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreStart
|
2012-09-05 14:43:24 +00:00
|
|
|
@file_put_contents($filename, $data, LOCK_EX);
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreEnd
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
return $data;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('clearCache')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Used to delete files in the cache directories, or clear contents of cache directories
|
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param string|array $params As String name to be searched for deletion, if name is a directory all files in
|
2009-09-07 04:18:08 +00:00
|
|
|
* directory will be deleted. If array, names to be searched for deletion. If clearCache() without params,
|
|
|
|
* all files in app/tmp/cache/views will be deleted
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $type Directory in tmp/cache defaults to view directory
|
|
|
|
* @param string $ext The file extension you are deleting
|
|
|
|
* @return true if files found and deleted false otherwise
|
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function clearCache($params = null, $type = 'views', $ext = '.php') {
|
|
|
|
if (is_string($params) || $params === null) {
|
|
|
|
$params = preg_replace('/\/\//', '/', $params);
|
|
|
|
$cache = CACHE . $type . DS . $params;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (is_file($cache . $ext)) {
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreStart
|
2012-09-05 14:43:24 +00:00
|
|
|
@unlink($cache . $ext);
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreEnd
|
2012-09-05 14:43:24 +00:00
|
|
|
return true;
|
|
|
|
} elseif (is_dir($cache)) {
|
|
|
|
$files = glob($cache . '*');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if ($files === false) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
foreach ($files as $file) {
|
|
|
|
if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreStart
|
2012-09-05 14:43:24 +00:00
|
|
|
@unlink($file);
|
2012-11-21 04:02:33 +00:00
|
|
|
//@codingStandardsIgnoreEnd
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
2008-08-01 23:46:53 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
return true;
|
2013-07-03 17:27:17 +00:00
|
|
|
}
|
|
|
|
$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);
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
2013-07-03 17:27:17 +00:00
|
|
|
}
|
|
|
|
if (empty($files)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
|
|
|
|
//@codingStandardsIgnoreStart
|
|
|
|
@unlink($file);
|
|
|
|
//@codingStandardsIgnoreEnd
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
2013-07-03 17:27:17 +00:00
|
|
|
return true;
|
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
} elseif (is_array($params)) {
|
|
|
|
foreach ($params as $file) {
|
|
|
|
clearCache($file, $type, $ext);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
return false;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('stripslashes_deep')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Recursively strips slashes from all values in an array
|
|
|
|
*
|
2008-09-12 05:11:34 +00:00
|
|
|
* @param array $values Array of values to strip slashes
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return mixed What is returned from calling stripslashes
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#stripslashes_deep
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function stripslashes_deep($values) {
|
|
|
|
if (is_array($values)) {
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
$values[$key] = stripslashes_deep($value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$values = stripslashes($values);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
return $values;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('__')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-10-31 19:44:23 +00:00
|
|
|
* Returns a translated string if one is found; Otherwise, the submitted message.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $singular Text to translate
|
2010-12-05 01:34:59 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function
|
2010-12-04 22:19:17 +00:00
|
|
|
* @return mixed translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function __($singular, $args = null) {
|
|
|
|
if (!$singular) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
2010-12-06 04:13:58 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($singular);
|
2014-06-08 11:41:48 +00:00
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 1));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('__n')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param string $singular Singular text to translate
|
|
|
|
* @param string $plural Plural text
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $count Count
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2010-12-04 22:19:17 +00:00
|
|
|
* @return mixed plural form of translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__n
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function __n($singular, $plural, $count, $args = null) {
|
|
|
|
if (!$singular) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
2010-12-06 04:13:58 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
App::uses('I18n', 'I18n');
|
2014-03-23 11:47:35 +00:00
|
|
|
$translated = I18n::translate($singular, $plural, null, I18n::LC_MESSAGES, $count);
|
2014-06-08 11:41:48 +00:00
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 3));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('__d')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Allows you to override the current domain for a single message lookup.
|
|
|
|
*
|
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $msg String to translate
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__d
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function __d($domain, $msg, $args = null) {
|
|
|
|
if (!$msg) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($msg, null, $domain);
|
2014-06-08 11:41:48 +00:00
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 2));
|
2008-06-20 20:17:23 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('__dn')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-10-31 19:44:23 +00:00
|
|
|
* Allows you to override the current domain for a single plural message lookup.
|
2008-05-30 11:40:08 +00:00
|
|
|
* Returns correct plural form of message identified by $singular and $plural for count $count
|
2008-10-31 19:44:23 +00:00
|
|
|
* from domain $domain.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $singular Singular string to translate
|
|
|
|
* @param string $plural Plural
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $count Count
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string plural form of translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dn
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function __dn($domain, $singular, $plural, $count, $args = null) {
|
|
|
|
if (!$singular) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
|
|
|
App::uses('I18n', 'I18n');
|
2014-03-23 11:47:35 +00:00
|
|
|
$translated = I18n::translate($singular, $plural, $domain, I18n::LC_MESSAGES, $count);
|
2014-06-08 11:41:48 +00:00
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 4));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('__dc')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Allows you to override the current domain for a single message lookup.
|
|
|
|
* It also allows you to specify a category.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2014-03-23 11:47:35 +00:00
|
|
|
* Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
|
2009-09-07 04:18:08 +00:00
|
|
|
*
|
2014-03-23 11:47:35 +00:00
|
|
|
* - LC_ALL I18n::LC_ALL
|
|
|
|
* - LC_COLLATE I18n::LC_COLLATE
|
|
|
|
* - LC_CTYPE I18n::LC_CTYPE
|
|
|
|
* - LC_MONETARY I18n::LC_MONETARY
|
|
|
|
* - LC_NUMERIC I18n::LC_NUMERIC
|
|
|
|
* - LC_TIME I18n::LC_TIME
|
|
|
|
* - LC_MESSAGES I18n::LC_MESSAGES
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $msg Message to translate
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $category Category
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dc
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function __dc($domain, $msg, $category, $args = null) {
|
|
|
|
if (!$msg) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($msg, null, $domain, $category);
|
2014-06-08 11:41:48 +00:00
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 3));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('__dcn')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Allows you to override the current domain for a single plural message lookup.
|
|
|
|
* It also allows you to specify a category.
|
|
|
|
* Returns correct plural form of message identified by $singular and $plural for count $count
|
2008-10-31 19:44:23 +00:00
|
|
|
* from domain $domain.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2014-03-23 11:47:35 +00:00
|
|
|
* Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
|
2009-09-07 04:18:08 +00:00
|
|
|
*
|
2014-03-23 11:47:35 +00:00
|
|
|
* - LC_ALL I18n::LC_ALL
|
|
|
|
* - LC_COLLATE I18n::LC_COLLATE
|
|
|
|
* - LC_CTYPE I18n::LC_CTYPE
|
|
|
|
* - LC_MONETARY I18n::LC_MONETARY
|
|
|
|
* - LC_NUMERIC I18n::LC_NUMERIC
|
|
|
|
* - LC_TIME I18n::LC_TIME
|
|
|
|
* - LC_MESSAGES I18n::LC_MESSAGES
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $singular Singular string to translate
|
|
|
|
* @param string $plural Plural
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $count Count
|
|
|
|
* @param int $category Category
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string plural form of translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dcn
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
|
|
|
|
if (!$singular) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($singular, $plural, $domain, $category, $count);
|
2014-06-08 11:41:48 +00:00
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 5));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('__c')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2014-03-23 11:47:35 +00:00
|
|
|
* Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
|
2009-09-07 04:18:08 +00:00
|
|
|
*
|
2014-03-23 11:47:35 +00:00
|
|
|
* - LC_ALL I18n::LC_ALL
|
|
|
|
* - LC_COLLATE I18n::LC_COLLATE
|
|
|
|
* - LC_CTYPE I18n::LC_CTYPE
|
|
|
|
* - LC_MONETARY I18n::LC_MONETARY
|
|
|
|
* - LC_NUMERIC I18n::LC_NUMERIC
|
|
|
|
* - LC_TIME I18n::LC_TIME
|
|
|
|
* - LC_MESSAGES I18n::LC_MESSAGES
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $msg String to translate
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $category Category
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function __c($msg, $category, $args = null) {
|
|
|
|
if (!$msg) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2012-09-05 14:43:24 +00:00
|
|
|
}
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($msg, null, null, $category);
|
2014-06-08 11:41:48 +00:00
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 2));
|
2008-06-20 20:17:23 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2014-06-08 09:54:28 +00:00
|
|
|
if (!function_exists('__x')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a translated string if one is found; Otherwise, the submitted message.
|
|
|
|
*
|
|
|
|
* @param string $context Context of the text
|
|
|
|
* @param string $singular Text to translate
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2014-06-08 09:54:28 +00:00
|
|
|
* @return mixed translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__
|
2014-06-08 09:54:28 +00:00
|
|
|
*/
|
|
|
|
function __x($context, $singular, $args = null) {
|
|
|
|
if (!$singular) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2014-06-08 09:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($singular, null, null, null, null, null, $context);
|
|
|
|
$arguments = func_get_args();
|
2014-07-19 16:27:44 +00:00
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('__xn')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param string $context Context of the text
|
|
|
|
* @param string $singular Singular text to translate
|
|
|
|
* @param string $plural Plural text
|
2014-10-02 00:34:33 +00:00
|
|
|
* @param int $count Count
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2014-07-19 16:27:44 +00:00
|
|
|
* @return mixed plural form of translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__n
|
2014-07-19 16:27:44 +00:00
|
|
|
*/
|
|
|
|
function __xn($context, $singular, $plural, $count, $args = null) {
|
|
|
|
if (!$singular) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2014-07-19 16:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($singular, $plural, null, I18n::LC_MESSAGES, $count, null, $context);
|
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 4));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('__dx')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows you to override the current domain for a single message lookup.
|
|
|
|
*
|
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $context Context of the text
|
|
|
|
* @param string $msg String to translate
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__d
|
2014-07-19 16:27:44 +00:00
|
|
|
*/
|
|
|
|
function __dx($domain, $context, $msg, $args = null) {
|
|
|
|
if (!$msg) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2014-07-19 16:27:44 +00:00
|
|
|
}
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($msg, null, $domain, null, null, null, $context);
|
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 3));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('__dxn')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* from domain $domain.
|
|
|
|
*
|
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $context Context of the text
|
|
|
|
* @param string $singular Singular string to translate
|
|
|
|
* @param string $plural Plural
|
2014-10-02 00:34:33 +00:00
|
|
|
* @param int $count Count
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string plural form of translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dn
|
2014-07-19 16:27:44 +00:00
|
|
|
*/
|
|
|
|
function __dxn($domain, $context, $singular, $plural, $count, $args = null) {
|
|
|
|
if (!$singular) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2014-07-19 16:27:44 +00:00
|
|
|
}
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($singular, $plural, $domain, I18n::LC_MESSAGES, $count, null, $context);
|
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 5));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('__dxc')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows you to override the current domain for a single message lookup.
|
|
|
|
* It also allows you to specify a category.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
|
|
|
|
*
|
|
|
|
* - LC_ALL I18n::LC_ALL
|
|
|
|
* - LC_COLLATE I18n::LC_COLLATE
|
|
|
|
* - LC_CTYPE I18n::LC_CTYPE
|
|
|
|
* - LC_MONETARY I18n::LC_MONETARY
|
|
|
|
* - LC_NUMERIC I18n::LC_NUMERIC
|
|
|
|
* - LC_TIME I18n::LC_TIME
|
|
|
|
* - LC_MESSAGES I18n::LC_MESSAGES
|
|
|
|
*
|
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $context Context of the text
|
|
|
|
* @param string $msg Message to translate
|
2014-10-02 00:34:33 +00:00
|
|
|
* @param int $category Category
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dc
|
2014-07-19 16:27:44 +00:00
|
|
|
*/
|
|
|
|
function __dxc($domain, $context, $msg, $category, $args = null) {
|
|
|
|
if (!$msg) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2014-07-19 16:27:44 +00:00
|
|
|
}
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($msg, null, $domain, $category, null, null, $context);
|
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 4));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('__dxcn')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows you to override the current domain for a single plural message lookup.
|
|
|
|
* It also allows you to specify a category.
|
|
|
|
* Returns correct plural form of message identified by $singular and $plural for count $count
|
|
|
|
* from domain $domain.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
|
|
|
|
*
|
|
|
|
* - LC_ALL I18n::LC_ALL
|
|
|
|
* - LC_COLLATE I18n::LC_COLLATE
|
|
|
|
* - LC_CTYPE I18n::LC_CTYPE
|
|
|
|
* - LC_MONETARY I18n::LC_MONETARY
|
|
|
|
* - LC_NUMERIC I18n::LC_NUMERIC
|
|
|
|
* - LC_TIME I18n::LC_TIME
|
|
|
|
* - LC_MESSAGES I18n::LC_MESSAGES
|
|
|
|
*
|
|
|
|
* @param string $domain Domain
|
|
|
|
* @param string $context Context of the text
|
|
|
|
* @param string $singular Singular string to translate
|
|
|
|
* @param string $plural Plural
|
2014-10-02 00:34:33 +00:00
|
|
|
* @param int $count Count
|
|
|
|
* @param int $category Category
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string plural form of translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dcn
|
2014-07-19 16:27:44 +00:00
|
|
|
*/
|
|
|
|
function __dxcn($domain, $context, $singular, $plural, $count, $category, $args = null) {
|
|
|
|
if (!$singular) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2014-07-19 16:27:44 +00:00
|
|
|
}
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($singular, $plural, $domain, $category, $count, null, $context);
|
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 6));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('__xc')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
|
|
|
|
*
|
|
|
|
* - LC_ALL I18n::LC_ALL
|
|
|
|
* - LC_COLLATE I18n::LC_COLLATE
|
|
|
|
* - LC_CTYPE I18n::LC_CTYPE
|
|
|
|
* - LC_MONETARY I18n::LC_MONETARY
|
|
|
|
* - LC_NUMERIC I18n::LC_NUMERIC
|
|
|
|
* - LC_TIME I18n::LC_TIME
|
|
|
|
* - LC_MESSAGES I18n::LC_MESSAGES
|
|
|
|
*
|
|
|
|
* @param string $context Context of the text
|
|
|
|
* @param string $msg String to translate
|
2014-10-02 00:34:33 +00:00
|
|
|
* @param int $category Category
|
2015-09-25 15:11:20 +00:00
|
|
|
* @param mixed $args Array with arguments or multiple arguments in function, otherwise null.
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string translated string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
|
2014-07-19 16:27:44 +00:00
|
|
|
*/
|
|
|
|
function __xc($context, $msg, $category, $args = null) {
|
|
|
|
if (!$msg) {
|
2015-09-25 15:11:20 +00:00
|
|
|
return null;
|
2014-07-19 16:27:44 +00:00
|
|
|
}
|
|
|
|
App::uses('I18n', 'I18n');
|
|
|
|
$translated = I18n::translate($msg, null, null, $category, null, null, $context);
|
|
|
|
$arguments = func_get_args();
|
|
|
|
return I18n::insertArgs($translated, array_slice($arguments, 3));
|
2014-06-08 09:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('LogError')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Shortcut to Log::write.
|
|
|
|
*
|
|
|
|
* @param string $message Message to write to log
|
2011-11-26 22:42:37 +00:00
|
|
|
* @return void
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#LogError
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function LogError($message) {
|
|
|
|
App::uses('CakeLog', 'Log');
|
|
|
|
$bad = array("\n", "\r", "\t");
|
|
|
|
$good = ' ';
|
|
|
|
CakeLog::write('error', str_replace($bad, $good, $message));
|
|
|
|
}
|
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('fileExistsInPath')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-10-31 19:44:23 +00:00
|
|
|
* Searches include path for files.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $file File to look for
|
2015-07-08 09:23:29 +00:00
|
|
|
* @return string Full path to file if exists, otherwise false
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#fileExistsInPath
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
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;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
return false;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-09-05 14:43:24 +00:00
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-05 14:43:24 +00:00
|
|
|
if (!function_exists('convertSlash')) {
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Convert forward slashes to underscores and removes first and last underscores in a string
|
|
|
|
*
|
2014-06-01 01:53:54 +00:00
|
|
|
* @param string $string String to convert
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string with underscore remove from start and end of string
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#convertSlash
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-09-05 14:43:24 +00:00
|
|
|
function convertSlash($string) {
|
|
|
|
$string = trim($string, '/');
|
|
|
|
$string = preg_replace('/\/\//', '/', $string);
|
|
|
|
$string = str_replace('/', '_', $string);
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2011-04-28 13:16:55 +00:00
|
|
|
}
|
2015-03-14 09:13:31 +00:00
|
|
|
|
|
|
|
if (!function_exists('json_last_error_msg')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides the fallback implementation of json_last_error_msg() available in PHP 5.5 and above.
|
|
|
|
*
|
|
|
|
* @return string Error message.
|
|
|
|
*/
|
|
|
|
function json_last_error_msg() {
|
|
|
|
static $errors = array(
|
|
|
|
JSON_ERROR_NONE => '',
|
|
|
|
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
|
|
|
|
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',
|
|
|
|
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
|
|
|
|
JSON_ERROR_SYNTAX => 'Syntax error',
|
|
|
|
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
|
|
|
|
);
|
|
|
|
$error = json_last_error();
|
|
|
|
return array_key_exists($error, $errors) ? $errors[$error] : "Unknown error ({$error})";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|