Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,19 +2,18 @@
/**
* Time Helper class file.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.View.Helper
* @since CakePHP(tm) v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('CakeTime', 'Utility');
@ -34,6 +33,8 @@ class TimeHelper extends AppHelper {
/**
* CakeTime instance
*
* @var CakeTime
*/
protected $_engine = null;
@ -46,7 +47,7 @@ class TimeHelper extends AppHelper {
* The class needs to be placed in the `Utility` directory.
*
* @param View $View the view object the helper is attached to.
* @param array $settings Settings array Settings array
* @param array $settings Settings array
* @throws CakeException When the engine class could not be found.
*/
public function __construct(View $View, $settings = array()) {
@ -66,16 +67,15 @@ class TimeHelper extends AppHelper {
*
* @param string $name Name of the attribute to set.
* @param string $value Value of the attribute to set.
* @return mixed
* @return void
*/
public function __set($name, $value) {
switch ($name) {
case 'niceFormat':
$this->_engine->{$name} = $value;
break;
break;
default:
$this->{$name} = $value;
break;
}
}
@ -83,7 +83,7 @@ class TimeHelper extends AppHelper {
* Magic isset check for deprecated attributes.
*
* @param string $name Name of the attribute to check.
* @return boolean
* @return bool|null
*/
public function __isset($name) {
if (isset($this->{$name})) {
@ -115,18 +115,24 @@ class TimeHelper extends AppHelper {
/**
* Call methods from CakeTime utility class
*
* @param string $method Method to call.
* @param array $params Parameters to pass to method.
* @return mixed Whatever is returned by called method, or false on failure
*/
public function __call($method, $params) {
return call_user_func_array(array($this->_engine, $method), $params);
}
/**
* @see CakeTime::convertSpecifiers()
* Converts a string representing the format for the function strftime and returns a
* Windows safe and i18n aware format.
*
* @param string $format Format with specifiers for strftime function.
* Accepts the special specifier %S which mimics the modifier S for date()
* @param string $time UNIX timestamp
* @return string windows safe and date() function compatible format for strftime
* @return string Windows safe and date() function compatible format for strftime
* @see CakeTime::convertSpecifiers()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function convertSpecifiers($format, $time = null) {
@ -134,11 +140,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::convert()
* Converts given time (in server's time zone) to user's local time, given his/her timezone.
*
* @param string $serverTime UNIX timestamp
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return integer UNIX timestamp
* @return int UNIX timestamp
* @see CakeTime::convert()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function convert($serverTime, $timezone) {
@ -146,9 +153,10 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::serverOffset()
* Returns server's offset
*
* @return integer Offset
* @return int Offset
* @see CakeTime::serverOffset()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function serverOffset() {
@ -156,11 +164,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::fromString()
* Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return string Parsed timestamp
* @see CakeTime::fromString()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function fromString($dateString, $timezone = null) {
@ -168,12 +177,13 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::nice()
* Returns a nicely formatted date string for given Datetime string.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @param string $format The format to use. If null, `TimeHelper::$niceFormat` is used
* @param string $format The format to use. If null, `CakeTime::$niceFormat` is used
* @return string Formatted date string
* @see CakeTime::nice()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function nice($dateString = null, $timezone = null, $format = null) {
@ -181,11 +191,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::niceShort()
* Returns a formatted descriptive date string for given datetime string.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime objectp
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object.
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return string Described, relative date string
* @see CakeTime::niceShort()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function niceShort($dateString = null, $timezone = null) {
@ -193,13 +204,14 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::daysAsSql()
* Returns a partial SQL string to search for all records between two dates.
*
* @param integer|string|DateTime $begin UNIX timestamp, strtotime() valid string or DateTime object
* @param integer|string|DateTime $end UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $begin UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $end UNIX timestamp, strtotime() valid string or DateTime object
* @param string $fieldName Name of database field to compare with
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return string Partial SQL string.
* @see CakeTime::daysAsSql()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function daysAsSql($begin, $end, $fieldName, $timezone = null) {
@ -207,12 +219,14 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::dayAsSql()
* Returns a partial SQL string to search for all records between two times
* occurring on the same day.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string $fieldName Name of database field to compare with
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return string Partial SQL string.
* @see CakeTime::dayAsSql()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function dayAsSql($dateString, $fieldName, $timezone = null) {
@ -220,11 +234,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::isToday()
* Returns true if given datetime string is today.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return boolean True if datetime string is today
* @return bool True if datetime string is today
* @see CakeTime::isToday()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public function isToday($dateString, $timezone = null) {
@ -232,11 +247,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::isThisWeek()
* Returns true if given datetime string is within this week.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return boolean True if datetime string is within current week
* @return bool True if datetime string is within current week
* @see CakeTime::isThisWeek()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public function isThisWeek($dateString, $timezone = null) {
@ -244,11 +260,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::isThisMonth()
* Returns true if given datetime string is within this month
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return boolean True if datetime string is within current month
* @return bool True if datetime string is within current month
* @see CakeTime::isThisMonth()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public function isThisMonth($dateString, $timezone = null) {
@ -256,11 +273,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::isThisYear()
* Returns true if given datetime string is within current year.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return boolean True if datetime string is within current year
* @return bool True if datetime string is within current year
* @see CakeTime::isThisYear()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public function isThisYear($dateString, $timezone = null) {
@ -268,24 +286,25 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::wasYesterday()
* Returns true if given datetime string was yesterday.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return boolean True if datetime string was yesterday
* @return bool True if datetime string was yesterday
* @see CakeTime::wasYesterday()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*
*/
public function wasYesterday($dateString, $timezone = null) {
return $this->_engine->wasYesterday($dateString, $timezone);
}
/**
* @see CakeTime::isTomorrow()
* Returns true if given datetime string is tomorrow.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return boolean True if datetime string was yesterday
* @return bool True if datetime string was yesterday
* @see CakeTime::isTomorrow()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public function isTomorrow($dateString, $timezone = null) {
@ -293,11 +312,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::toQuarter()
* Returns the quarter
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param boolean $range if true returns a range in Y-m-d format
* @return mixed 1, 2, 3, or 4 quarter of year or array if $range true
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param bool $range if true returns a range in Y-m-d format
* @return int|array 1, 2, 3, or 4 quarter of year or array if $range true
* @see CakeTime::toQuarter()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function toQuarter($dateString, $range = false) {
@ -305,11 +325,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::toUnix()
* Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return integer Unix timestamp
* @return int Unix timestamp
* @see CakeTime::toUnix()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function toUnix($dateString, $timezone = null) {
@ -317,11 +338,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::toAtom()
* Returns a date formatted for Atom RSS feeds.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return string Formatted date string
* @see CakeTime::toAtom()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function toAtom($dateString, $timezone = null) {
@ -329,11 +351,12 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::toRSS()
* Formats date for RSS feeds
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return string Formatted date string
* @see CakeTime::toRSS()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function toRSS($dateString, $timezone = null) {
@ -341,25 +364,26 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::timeAgoInWords()
* Formats a date into a phrase expressing the relative time.
*
* ## Addition options
*
* - `element` - The element to wrap the formatted time in.
* Has a few additional options:
* - `tag` - The tag to use, defaults to 'span'.
* - `class` - The classname to use, defaults to `time-ago-in-words`.
* - `class` - The class name to use, defaults to `time-ago-in-words`.
* - `title` - Defaults to the $dateTime input.
*
* @param integer|string|DateTime $dateTime UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateTime UNIX timestamp, strtotime() valid string or DateTime object
* @param array $options Default format if timestamp is used in $dateString
* @return string Relative time string.
* @see CakeTime::timeAgoInWords()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function timeAgoInWords($dateTime, $options = array()) {
$element = null;
if (is_array($options) && !empty($options['element'])) {
if (!empty($options['element'])) {
$element = array(
'tag' => 'span',
'class' => 'time-ago-in-words',
@ -367,7 +391,7 @@ class TimeHelper extends AppHelper {
);
if (is_array($options['element'])) {
$element = array_merge($element, $options['element']);
$element = $options['element'] + $element;
} else {
$element['tag'] = $options['element'];
}
@ -388,13 +412,14 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::wasWithinLast()
* Returns true if specified datetime was within the interval specified, else false.
*
* @param string|integer $timeInterval the numeric value with space then time type.
* @param string|int $timeInterval the numeric value with space then time type.
* Example of valid types: 6 hours, 2 days, 1 minute.
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return boolean
* @return bool
* @see CakeTime::wasWithinLast()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public function wasWithinLast($timeInterval, $dateString, $timezone = null) {
@ -402,13 +427,14 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::isWithinLast()
* Returns true if specified datetime is within the interval specified, else false.
*
* @param string|integer $timeInterval the numeric value with space then time type.
* @param string|int $timeInterval the numeric value with space then time type.
* Example of valid types: 6 hours, 2 days, 1 minute.
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return boolean
* @return bool
* @see CakeTime::isWithinLast()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
*/
public function isWithinNext($timeInterval, $dateString, $timezone = null) {
@ -416,10 +442,11 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::gmt()
* Returns gmt as a UNIX timestamp.
*
* @param integer|string|DateTime $string UNIX timestamp, strtotime() valid string or DateTime object
* @return integer UNIX timestamp
* @param int|string|DateTime $string UNIX timestamp, strtotime() valid string or DateTime object
* @return int UNIX timestamp
* @see CakeTime::gmt()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function gmt($string = null) {
@ -427,13 +454,27 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::format()
* Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string.
* This function also accepts a time string and a format string as first and second parameters.
* In that case this function behaves as a wrapper for TimeHelper::i18nFormat()
*
* @param integer|string|DateTime $format date format string (or a UNIX timestamp, strtotime() valid string or DateTime object)
* @param integer|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object (or a date format string)
* @param boolean $invalid flag to ignore results of fromString == false
* ## Examples
*
* Create localized & formatted time:
*
* ```
* $this->Time->format('2012-02-15', '%m-%d-%Y'); // returns 02-15-2012
* $this->Time->format('2012-02-15 23:01:01', '%c'); // returns preferred date and time based on configured locale
* $this->Time->format('0000-00-00', '%d-%m-%Y', 'N/A'); // return N/A because an invalid date was passed
* $this->Time->format('2012-02-15 23:01:01', '%c', 'N/A', 'America/New_York'); // converts passed date to timezone
* ```
*
* @param int|string|DateTime $format date format string (or a UNIX timestamp, strtotime() valid string or DateTime object)
* @param int|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object (or a date format string)
* @param bool $invalid flag to ignore results of fromString == false
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return string Formatted date string
* @see CakeTime::format()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function format($format, $date = null, $invalid = false, $timezone = null) {
@ -441,13 +482,15 @@ class TimeHelper extends AppHelper {
}
/**
* @see CakeTime::i18nFormat()
* Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string.
* It takes into account the default date format for the current language if a LC_TIME file is used.
*
* @param integer|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object
* @param int|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object
* @param string $format strftime format string.
* @param boolean $invalid flag to ignore results of fromString == false
* @param bool $invalid flag to ignore results of fromString == false
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return string Formatted and translated date string
* @see CakeTime::i18nFormat()
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
public function i18nFormat($date, $format = null, $invalid = false, $timezone = null) {