security updates
have to check views and entityreference for custom patches
This commit is contained in:
@@ -9,9 +9,9 @@ stylesheets[all][] = date.css
|
||||
files[] = date_api.module
|
||||
files[] = date_api_sql.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-08-13
|
||||
version = "7.x-2.6"
|
||||
; Information added by Drupal.org packaging script on 2014-07-29
|
||||
version = "7.x-2.8"
|
||||
core = "7.x"
|
||||
project = "date"
|
||||
datestamp = "1344850024"
|
||||
datestamp = "1406653438"
|
||||
|
||||
|
@@ -276,18 +276,17 @@ class DateObject extends DateTime {
|
||||
$this->setGranularityFromTime($time, $tz);
|
||||
}
|
||||
}
|
||||
// If this tz was given as just an offset or the timezone
|
||||
// was invalid, we need to do some tweaking.
|
||||
|
||||
// If we haven't got a valid timezone name yet, we need to set one or
|
||||
// we will get undefined index errors.
|
||||
// This can happen if $time had an offset or no timezone.
|
||||
if (!$this->getTimezone() || !preg_match('/[a-zA-Z]/', $this->getTimezone()->getName())) {
|
||||
|
||||
// If the timezone name is an offset and the original
|
||||
// $tz has a name, use it. This happens if you pass in
|
||||
// a date string with an offset along with a specific timezone name.
|
||||
if (!preg_match('/[a-zA-Z]/', $this->getTimezone()->getName()) && preg_match('/[a-zA-Z]/', $tz->getName())) {
|
||||
// If the original $tz has a name, use it.
|
||||
if (preg_match('/[a-zA-Z]/', $tz->getName())) {
|
||||
$this->setTimezone($tz);
|
||||
}
|
||||
// If we get this far, we have no information about the timezone name,
|
||||
// but we will get undefined index errors without any name.
|
||||
// We have no information about the timezone so must fallback to a default.
|
||||
else {
|
||||
$this->setTimezone(new DateTimeZone("UTC"));
|
||||
$this->errors['timezone'] = t('No valid timezone name was provided.');
|
||||
@@ -459,8 +458,27 @@ class DateObject extends DateTime {
|
||||
$true = $this->hasGranularity() && (!$granularity || $flexible || $this->hasGranularity($granularity));
|
||||
if (!$true && $granularity) {
|
||||
foreach ((array) $granularity as $part) {
|
||||
if (!$this->hasGranularity($part)) {
|
||||
$this->errors[$part] = t("The @part is missing.", array('@part' => $part));
|
||||
if (!$this->hasGranularity($part) && in_array($part, array('second', 'minute', 'hour', 'day', 'month', 'year'))) {
|
||||
switch ($part) {
|
||||
case 'second':
|
||||
$this->errors[$part] = t('The second is missing.');
|
||||
break;
|
||||
case 'minute':
|
||||
$this->errors[$part] = t('The minute is missing.');
|
||||
break;
|
||||
case 'hour':
|
||||
$this->errors[$part] = t('The hour is missing.');
|
||||
break;
|
||||
case 'day':
|
||||
$this->errors[$part] = t('The day is missing.');
|
||||
break;
|
||||
case 'month':
|
||||
$this->errors[$part] = t('The month is missing.');
|
||||
break;
|
||||
case 'year':
|
||||
$this->errors[$part] = t('The year is missing.');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -574,7 +592,7 @@ class DateObject extends DateTime {
|
||||
$regex2 = preg_replace($patterns, $repl2, $format_regexp, 1);
|
||||
$regex2 = str_replace('A', '(AM|PM)', $regex2);
|
||||
$regex2 = str_replace('a', '(am|pm)', $regex2);
|
||||
preg_match('`^' . $regex2 . '$`', $date, $values);
|
||||
preg_match('`^' . $regex2 . '$`u', $date, $values);
|
||||
array_shift($values);
|
||||
// If we did not find all the values for the patterns in the format, abort.
|
||||
if (count($letters) != count($values)) {
|
||||
@@ -951,6 +969,11 @@ class DateObject extends DateTime {
|
||||
if ($year_diff == 0) {
|
||||
return intval($item2 - $item1);
|
||||
}
|
||||
elseif ($year_diff < 0) {
|
||||
$item_diff = 0 - $item1;
|
||||
$item_diff -= intval((abs($year_diff) - 1) * 12);
|
||||
return $item_diff - (12 - $item2);
|
||||
}
|
||||
else {
|
||||
$item_diff = 12 - $item1;
|
||||
$item_diff += intval(($year_diff - 1) * 12);
|
||||
@@ -965,6 +988,14 @@ class DateObject extends DateTime {
|
||||
if ($year_diff == 0) {
|
||||
return intval($item2 - $item1);
|
||||
}
|
||||
elseif ($year_diff < 0) {
|
||||
$item_diff = 0 - $item1;
|
||||
for ($i = 1; $i < abs($year_diff); $i++) {
|
||||
date_modify($date1, '-1 year');
|
||||
$item_diff -= date_days_in_year($date1);
|
||||
}
|
||||
return $item_diff - (date_days_in_year($date2) - $item2);
|
||||
}
|
||||
else {
|
||||
$item_diff = date_days_in_year($date1) - $item1;
|
||||
for ($i = 1; $i < $year_diff; $i++) {
|
||||
@@ -978,9 +1009,12 @@ class DateObject extends DateTime {
|
||||
case 'weeks':
|
||||
$week_diff = date_format($date2, 'W') - date_format($date1, 'W');
|
||||
$year_diff = date_format($date2, 'o') - date_format($date1, 'o');
|
||||
for ($i = 1; $i <= $year_diff; $i++) {
|
||||
date_modify($date1, '+1 year');
|
||||
$week_diff += date_iso_weeks_in_year($date1);
|
||||
|
||||
$sign = ($year_diff < 0) ? -1 : 1;
|
||||
|
||||
for ($i = 1; $i <= abs($year_diff); $i++) {
|
||||
date_modify($date1, (($sign > 0) ? '+': '-').'1 year');
|
||||
$week_diff += (date_iso_weeks_in_year($date1) * $sign);
|
||||
}
|
||||
return $week_diff;
|
||||
}
|
||||
@@ -1705,11 +1739,28 @@ function date_format_interval($date, $granularity = 2, $display_ago = TRUE) {
|
||||
* (optional) Optionally force time to a specific timezone, defaults to user
|
||||
* timezone, if set, otherwise site timezone. Defaults to NULL.
|
||||
*
|
||||
* @param boolean $reset [optional]
|
||||
* Static cache reset
|
||||
*
|
||||
* @return object
|
||||
* The current time as a date object.
|
||||
*/
|
||||
function date_now($timezone = NULL) {
|
||||
return new DateObject('now', $timezone);
|
||||
function date_now($timezone = NULL, $reset = FALSE) {
|
||||
if ($reset) {
|
||||
drupal_static_reset(__FUNCTION__ . $timezone);
|
||||
}
|
||||
|
||||
$now = &drupal_static(__FUNCTION__ . $timezone);
|
||||
|
||||
if (!isset($now)) {
|
||||
$now = new DateObject('now', $timezone);
|
||||
}
|
||||
|
||||
// Avoid unexpected manipulation of cached $now object
|
||||
// by subsequent code execution
|
||||
// @see https://drupal.org/node/2261395
|
||||
$clone = clone $now;
|
||||
return $clone;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2100,6 +2151,17 @@ function date_part_format($part, $format) {
|
||||
* The format string with all other elements removed.
|
||||
*/
|
||||
function date_limit_format($format, $granularity) {
|
||||
// Use the advanced drupal_static() pattern to improve performance.
|
||||
static $drupal_static_fast;
|
||||
if (!isset($drupal_static_fast)) {
|
||||
$drupal_static_fast['formats'] = &drupal_static(__FUNCTION__);
|
||||
}
|
||||
$formats = &$drupal_static_fast['formats'];
|
||||
$format_granularity_cid = $format .'|'. implode(',', $granularity);
|
||||
if (isset($formats[$format_granularity_cid])) {
|
||||
return $formats[$format_granularity_cid];
|
||||
}
|
||||
|
||||
// If punctuation has been escaped, remove the escaping. Done using strtr()
|
||||
// because it is easier than getting the escape character extracted using
|
||||
// preg_replace().
|
||||
@@ -2169,11 +2231,14 @@ function date_limit_format($format, $granularity) {
|
||||
// After removing the non-desired parts of the format, test if the only things
|
||||
// left are escaped, non-date, characters. If so, return nothing.
|
||||
// Using S instead of w to pick up non-ASCII characters.
|
||||
$test = trim(preg_replace('(\\\\\S{1,3})', '', $format));
|
||||
$test = trim(preg_replace('(\\\\\S{1,3})u', '', $format));
|
||||
if (empty($test)) {
|
||||
$format = '';
|
||||
}
|
||||
|
||||
// Store the return value in the static array for performance.
|
||||
$formats[$format_granularity_cid] = $format;
|
||||
|
||||
return $format;
|
||||
}
|
||||
|
||||
@@ -2320,26 +2385,38 @@ function date_get_timezone($handling, $timezone = '') {
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to figure out which db timezone applies to a date and select it.
|
||||
* Function to figure out which db timezone applies to a date.
|
||||
*
|
||||
* @param string $handling
|
||||
* The timezone handling.
|
||||
* @param string $timezone
|
||||
* (optional) A timezone string. Defaults to an empty string.
|
||||
* (optional) When $handling is 'date', date_get_timezone_db() returns this
|
||||
* value.
|
||||
*
|
||||
* @return string
|
||||
* The timezone string.
|
||||
*/
|
||||
function date_get_timezone_db($handling, $timezone = '') {
|
||||
function date_get_timezone_db($handling, $timezone = NULL) {
|
||||
switch ($handling) {
|
||||
case 'none':
|
||||
$timezone = date_default_timezone();
|
||||
break;
|
||||
default:
|
||||
case ('utc'):
|
||||
case ('site'):
|
||||
case ('user'):
|
||||
// These handling modes all convert to UTC before storing in the DB.
|
||||
$timezone = 'UTC';
|
||||
break;
|
||||
case ('date'):
|
||||
if ($timezone == NULL) {
|
||||
// This shouldn't happen, since it's meaning is undefined. But we need
|
||||
// to fall back to *something* that's a legal timezone.
|
||||
$timezone = date_default_timezone();
|
||||
}
|
||||
break;
|
||||
case ('none'):
|
||||
default:
|
||||
$timezone = date_default_timezone();
|
||||
break;
|
||||
}
|
||||
return $timezone > '' ? $timezone : 'UTC';
|
||||
return $timezone;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -239,7 +239,8 @@ function date_timezone_element_process($element, &$form_state, $form) {
|
||||
$label = theme('date_part_label_timezone', array('part_type' => 'select', 'element' => $element));
|
||||
$element['timezone'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => $element['#date_label_position'] == 'above' ? $label : '',
|
||||
'#title' => $label,
|
||||
'#title_display' => $element['#date_label_position'] == 'above' ? 'before' : 'invisible',
|
||||
'#options' => date_timezone_names($element['#required']),
|
||||
'#value' => $element['#value'],
|
||||
'#weight' => $element['#weight'],
|
||||
@@ -320,6 +321,8 @@ function date_text_element_process($element, &$form_state, $form) {
|
||||
$element['date']['#weight'] = !empty($element['date']['#weight']) ? $element['date']['#weight'] : $element['#weight'];
|
||||
$element['date']['#attributes'] = array('class' => isset($element['#attributes']['class']) ? $element['#attributes']['class'] += array('date-date') : array('date-date'));
|
||||
$now = date_example_date();
|
||||
$element['date']['#title'] = t('Date');
|
||||
$element['date']['#title_display'] = 'invisible';
|
||||
$element['date']['#description'] = ' ' . t('Format: @date', array('@date' => date_format_date(date_example_date(), 'custom', $element['#date_format'])));
|
||||
$element['date']['#ajax'] = !empty($element['#ajax']) ? $element['#ajax'] : FALSE;
|
||||
|
||||
@@ -585,6 +588,8 @@ function date_parts_element($element, $date, $format) {
|
||||
$sub_element[$field]['#type'] = 'textfield';
|
||||
$sub_element[$field]['#theme'] = 'date_textfield_element';
|
||||
$sub_element[$field]['#size'] = 7;
|
||||
$sub_element[$field]['#title'] = $label;
|
||||
$sub_element[$field]['#title_display'] = in_array($element['#date_label_position'], array('within', 'none')) ? 'invisible' : 'before';
|
||||
if ($element['#date_label_position'] == 'within') {
|
||||
if (!empty($sub_element[$field]['#options']) && is_array($sub_element[$field]['#options'])) {
|
||||
$sub_element[$field]['#options'] = array(
|
||||
@@ -594,20 +599,16 @@ function date_parts_element($element, $date, $format) {
|
||||
$sub_element[$field]['#default_value'] = '-' . $label;
|
||||
}
|
||||
}
|
||||
elseif ($element['#date_label_position'] != 'none') {
|
||||
$sub_element[$field]['#title'] = $label;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sub_element[$field]['#type'] = 'select';
|
||||
$sub_element[$field]['#theme'] = 'date_select_element';
|
||||
$sub_element[$field]['#title'] = $label;
|
||||
$sub_element[$field]['#title_display'] = in_array($element['#date_label_position'], array('within', 'none')) ? 'invisible' : 'before';
|
||||
if ($element['#date_label_position'] == 'within') {
|
||||
$sub_element[$field]['#options'] = array(
|
||||
'' => '-' . $label) + $sub_element[$field]['#options'];
|
||||
}
|
||||
elseif ($element['#date_label_position'] != 'none') {
|
||||
$sub_element[$field]['#title'] = $label;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,9 +622,12 @@ function date_parts_element($element, $date, $format) {
|
||||
}
|
||||
|
||||
if (($hours_format == 'g' || $hours_format == 'h') && date_has_time($granularity)) {
|
||||
$label = theme('date_part_label_ampm', array('part_type' => 'ampm', 'element' => $element));
|
||||
$sub_element['ampm'] = array(
|
||||
'#type' => 'select',
|
||||
'#theme' => 'date_select_element',
|
||||
'#title' => $label,
|
||||
'#title_display' => in_array($element['#date_label_position'], array('within', 'none')) ? 'invisible' : 'before',
|
||||
'#default_value' => is_object($date) ? (date_format($date, 'G') >= 12 ? 'pm' : 'am') : '',
|
||||
'#options' => drupal_map_assoc(date_ampm($part_required)),
|
||||
'#required' => $part_required,
|
||||
@@ -631,10 +635,7 @@ function date_parts_element($element, $date, $format) {
|
||||
'#attributes' => array('class' => array('date-ampm')),
|
||||
);
|
||||
if ($element['#date_label_position'] == 'within') {
|
||||
$sub_element['ampm']['#options'] = array('' => '-' . theme('date_part_label_ampm', array('part_type' => 'ampm', 'eleement' => $element))) + $sub_element['ampm']['#options'];
|
||||
}
|
||||
elseif ($element['#date_label_position'] != 'none') {
|
||||
$sub_element['ampm']['#title'] = theme('date_part_label_ampm', array('part_type' => 'ampm', 'element' => $element));
|
||||
$sub_element['ampm']['#options'] = array('' => '-' . $label) + $sub_element['ampm']['#options'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,9 +20,8 @@
|
||||
* Correct sql string for database type.
|
||||
*/
|
||||
function date_sql_concat($array) {
|
||||
switch (db_driver()) {
|
||||
switch (Database::getConnection()->databaseType()) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
return "CONCAT(" . implode(",", $array) . ")";
|
||||
case 'pgsql':
|
||||
return implode(" || ", $array);
|
||||
@@ -39,9 +38,8 @@ function date_sql_concat($array) {
|
||||
* SQL statement to return the first non-NULL value in the list.
|
||||
*/
|
||||
function date_sql_coalesce($array) {
|
||||
switch (db_driver()) {
|
||||
switch (Database::getConnection()->databaseType()) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
case 'pgsql':
|
||||
return "COALESCE(" . implode(',', $array) . ")";
|
||||
}
|
||||
@@ -89,7 +87,7 @@ class date_sql_handler {
|
||||
* The object constuctor.
|
||||
*/
|
||||
function __construct($date_type = DATE_DATETIME, $local_timezone = NULL, $offset = '+00:00') {
|
||||
$this->db_type = db_driver();
|
||||
$this->db_type = Database::getConnection()->databaseType();
|
||||
$this->date_type = $date_type;
|
||||
$this->db_timezone = 'UTC';
|
||||
$this->local_timezone = isset($local_timezone) ? $local_timezone : date_default_timezone();
|
||||
@@ -105,7 +103,6 @@ class date_sql_handler {
|
||||
$has_support = FALSE;
|
||||
switch ($this->db_type) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
$test = db_query("SELECT CONVERT_TZ('2008-02-15 12:00:00', 'UTC', 'US/Central')")->fetchField();
|
||||
if ($test == '2008-02-15 06:00:00') {
|
||||
$has_support = TRUE;
|
||||
@@ -141,11 +138,10 @@ class date_sql_handler {
|
||||
*/
|
||||
function set_db_timezone($offset = '+00:00') {
|
||||
static $already_set = FALSE;
|
||||
$type = db_driver();
|
||||
$type = Database::getConnection()->databaseType();
|
||||
if (!$already_set) {
|
||||
switch ($type) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
db_query("SET @@session.time_zone = '$offset'");
|
||||
break;
|
||||
case 'pgsql':
|
||||
@@ -199,7 +195,6 @@ class date_sql_handler {
|
||||
}
|
||||
switch ($this->db_type) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
switch ($this->date_type) {
|
||||
case DATE_UNIX:
|
||||
$field = "FROM_UNIXTIME($field)";
|
||||
@@ -258,7 +253,6 @@ class date_sql_handler {
|
||||
if (!empty($offset)) {
|
||||
switch ($this->db_type) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
return "ADDTIME($field, SEC_TO_TIME($offset))";
|
||||
case 'pgsql':
|
||||
return "($field + INTERVAL '$offset SECONDS')";;
|
||||
@@ -288,7 +282,6 @@ class date_sql_handler {
|
||||
$granularity = strtoupper($granularity);
|
||||
switch ($this->db_type) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
switch ($direction) {
|
||||
case 'ADD':
|
||||
return "DATE_ADD($field, INTERVAL $count $granularity)";
|
||||
@@ -358,7 +351,6 @@ class date_sql_handler {
|
||||
else {
|
||||
switch ($this->db_type) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
return "CONVERT_TZ($field, $db_zone, $localzone)";
|
||||
case 'pgsql':
|
||||
// WITH TIME ZONE assumes the date is using the system
|
||||
@@ -382,7 +374,6 @@ class date_sql_handler {
|
||||
function sql_format($format, $field) {
|
||||
switch ($this->db_type) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
$replace = array(
|
||||
'Y' => '%Y',
|
||||
'y' => '%y',
|
||||
@@ -553,7 +544,6 @@ class date_sql_handler {
|
||||
case 'WEEK':
|
||||
switch ($this->db_type) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
// WEEK using arg 3 in MySQl should return the same value as
|
||||
// Postgres EXTRACT.
|
||||
return "WEEK($field, 3)";
|
||||
@@ -563,7 +553,6 @@ class date_sql_handler {
|
||||
case 'DOW':
|
||||
switch ($this->db_type) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
// MySQL returns 1 for Sunday through 7 for Saturday, PHP date
|
||||
// functions and Postgres use 0 for Sunday and 6 for Saturday.
|
||||
return "INTEGER(DAYOFWEEK($field) - 1)";
|
||||
@@ -573,7 +562,6 @@ class date_sql_handler {
|
||||
case 'DOY':
|
||||
switch ($this->db_type) {
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
return "DAYOFYEAR($field)";
|
||||
case 'pgsql':
|
||||
return "EXTRACT(DOY FROM($field))";
|
||||
@@ -896,30 +884,30 @@ class date_sql_handler {
|
||||
}
|
||||
$formats = array('display', 'sql');
|
||||
// Start with the site long date format and add seconds to it.
|
||||
$long = str_replace(':i', ':i:s', variable_get('date_format_long', 'l, F j, Y - H:i'));
|
||||
$short = str_replace(':i', ':i:s', variable_get('date_format_short', 'l, F j, Y - H:i'));
|
||||
switch ($granularity) {
|
||||
case 'year':
|
||||
$formats['display'] = 'Y';
|
||||
$formats['sql'] = 'Y';
|
||||
break;
|
||||
case 'month':
|
||||
$formats['display'] = date_limit_format($long, array('year', 'month'));
|
||||
$formats['display'] = date_limit_format($short, array('year', 'month'));
|
||||
$formats['sql'] = 'Y-m';
|
||||
break;
|
||||
case 'day':
|
||||
$formats['display'] = date_limit_format($long, array('year', 'month', 'day'));
|
||||
$formats['display'] = date_limit_format($short, array('year', 'month', 'day'));
|
||||
$formats['sql'] = 'Y-m-d';
|
||||
break;
|
||||
case 'hour':
|
||||
$formats['display'] = date_limit_format($long, array('year', 'month', 'day', 'hour'));
|
||||
$formats['display'] = date_limit_format($short, array('year', 'month', 'day', 'hour'));
|
||||
$formats['sql'] = 'Y-m-d\TH';
|
||||
break;
|
||||
case 'minute':
|
||||
$formats['display'] = date_limit_format($long, array('year', 'month', 'day', 'hour', 'minute'));
|
||||
$formats['display'] = date_limit_format($short, array('year', 'month', 'day', 'hour', 'minute'));
|
||||
$formats['sql'] = 'Y-m-d\TH:i';
|
||||
break;
|
||||
case 'second':
|
||||
$formats['display'] = date_limit_format($long, array('year', 'month', 'day', 'hour', 'minute', 'second'));
|
||||
$formats['display'] = date_limit_format($short, array('year', 'month', 'day', 'hour', 'minute', 'second'));
|
||||
$formats['sql'] = 'Y-m-d\TH:i:s';
|
||||
break;
|
||||
case 'week':
|
||||
|
Reference in New Issue
Block a user