Projet

Général

Profil

Révision b720ea3e

Ajouté par Assos Assos il y a plus de 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date/date.module
1 1
<?php
2

  
2 3
/**
3 4
 * @file
4 5
 * Defines date/time field types.
5 6
 */
7

  
6 8
module_load_include('theme', 'date', 'date');
7 9
module_load_include('inc', 'date', 'date.field');
8 10
module_load_include('inc', 'date', 'date_elements');
......
15 17
    case 'field_collection_item':
16 18
      $bundle = $entity->field_name;
17 19
      break;
20

  
18 21
    default:
19 22
      $bundle = field_extract_bundle($entity_type, $entity);
20 23
      break;
......
40 43
 * Wrapper function around each of the widget types for creating a date object.
41 44
 */
42 45
function date_input_date($field, $instance, $element, $input) {
46
  // Trim extra spacing off user input of text fields.
47
  if (isset($input['date'])) {
48
    $input['date'] = trim($input['date']);
49
  }
50

  
43 51
  switch ($instance['widget']['type']) {
44 52
    case 'date_text':
45 53
      $function = 'date_text_input_date';
46 54
      break;
55

  
47 56
    case 'date_popup':
48 57
      $function = 'date_popup_input_date';
49 58
      break;
59

  
50 60
    default:
51 61
      $function = 'date_select_input_date';
52 62
  }
......
66 76
  );
67 77
  $themes = array(
68 78
    'date_combo' => $base + array('render element' => 'element'),
79
    'date_form_element' => $base + array('render element' => 'element'),
69 80
    'date_text_parts' => $base + array('render element' => 'element'),
70 81
    'date' => $base + array('render element' => 'element'),
71 82
    'date_display_single' => $base + array(
......
97 108
        'add_rdf' => NULL,
98 109
        'microdata' => NULL,
99 110
        'add_microdata' => NULL,
100
    )),
111
      ),
112
    ),
113
    'date_display_remaining' => $base + array(
114
      'variables' => array(
115
        'remaining_days' => NULL,
116
      ),
117
    ),
101 118
    'date_display_combination' => $base + array(
102 119
      'variables' => array(
103 120
        'entity_type' => NULL,
......
130 147
        'attributes' => array(),
131 148
        'rdf_mapping' => NULL,
132 149
        'add_rdf' => NULL,
133
       ),
150
      ),
134 151
    ),
135 152
  );
136 153

  
......
209 226
  $settings = $display['settings'];
210 227
  $field_name = $field['field_name'];
211 228
  $format = date_formatter_format($formatter, $settings, $granularity, $langcode);
212
  $timezone = isset($item['timezone']) ? $item['timezone'] : '';
213
  $timezone = date_get_timezone($field['settings']['tz_handling'], $timezone);
229
  if (!isset($field['settings']['tz_handling']) || $field['settings']['tz_handling'] !== 'utc') {
230
    $timezone = isset($item['timezone']) ? $item['timezone'] : '';
231
    $timezone = date_get_timezone($field['settings']['tz_handling'], $timezone);
232
  }
214 233
  $timezone_db = date_get_timezone_db($field['settings']['tz_handling']);
215 234
  $db_format = date_type_format($field['type']);
216 235
  $process = date_process_values($field);
......
246 265
      $dates[$processed]['formatted_iso'] = date_format_date($date, 'custom', 'c');
247 266
      if (is_object($date)) {
248 267
        if ($format == 'format_interval') {
249
           $dates[$processed]['interval'] = date_format_interval($date);
268
          $dates[$processed]['interval'] = date_format_interval($date);
250 269
        }
251 270
        elseif ($format == 'format_calendar_day') {
252
           $dates[$processed]['calendar_day'] = date_format_calendar_day($date);
271
          $dates[$processed]['calendar_day'] = date_format_calendar_day($date);
253 272
        }
254 273
        elseif ($format == 'U' || $format == 'r' || $format == 'c') {
255 274
          $dates[$processed]['formatted'] = date_format_date($date, 'custom', $format);
......
258 277
          $dates[$processed]['formatted_timezone'] = '';
259 278
        }
260 279
        elseif (!empty($format)) {
261
          $dates[$processed]['formatted'] = date_format_date($date, 'custom', $format);
262
          $dates[$processed]['formatted_date'] = date_format_date($date, 'custom', date_limit_format($format, array('year', 'month', 'day')));
263
          $dates[$processed]['formatted_time'] = date_format_date($date, 'custom', date_limit_format($format, array('hour', 'minute', 'second')));
264
          $dates[$processed]['formatted_timezone'] = date_format_date($date, 'custom', date_limit_format($format, array('timezone')));
280
          $formats = _get_custom_date_format($date, $format);
281
          $dates[$processed]['formatted'] = $formats['formatted'];
282
          $dates[$processed]['formatted_date'] = $formats['date'];
283
          $dates[$processed]['formatted_time'] = $formats['time'];
284
          $dates[$processed]['formatted_timezone'] = $formats['zone'];
265 285
        }
266 286
      }
267 287
    }
......
288 308
  return $dates;
289 309
}
290 310

  
311
/**
312
 * Get a custom date format.
313
 */
314
function _get_custom_date_format($date, $format) {
315
  $custom = array();
316
  $custom['granularities'] = array(
317
    'date' => array('year', 'month', 'day'),
318
    'time' => array('hour', 'minute', 'second'),
319
    'zone' => array('timezone'),
320
  );
321
  $custom['limits'] = array(
322
    'date' => date_limit_format($format, $custom['granularities']['date']),
323
    'time' => date_limit_format($format, $custom['granularities']['time']),
324
    'zone' => date_limit_format($format, $custom['granularities']['zone']),
325
  );
326

  
327
  return array(
328
    'formatted' => date_format_date($date, 'custom', $format),
329
    'date'      => date_format_date($date, 'custom', $custom['limits']['date']),
330
    'time'      => date_format_date($date, 'custom', $custom['limits']['time']),
331
    'zone'      => date_format_date($date, 'custom', $custom['limits']['zone']),
332
  );
333
}
334

  
291 335
/**
292 336
 * Retrieves the granularity for a field.
293 337
 *
......
301 345
 */
302 346
function date_granularity($field) {
303 347
  if (!is_array($field) || !is_array($field['settings']['granularity'])) {
304
    $field['settings']['granularity'] = drupal_map_assoc(array('year', 'month', 'day'));
348
    $granularity = drupal_map_assoc(array('year', 'month', 'day'));
349
    $field['settings']['granularity'] = $granularity;
305 350
  }
306 351
  return array_values(array_filter($field['settings']['granularity']));
307 352
}
308 353

  
309 354
/**
310
 * Helper function to create an array of the date values in a
311
 * field that need to be processed.
355
 * Helper function to create an array of the date values in a field that need to be processed.
312 356
 */
313 357
function date_process_values($field) {
314 358
  return $field['settings']['todate'] ? array('value', 'value2') : array('value');
......
394 438
  switch ($formatter) {
395 439
    case 'format_interval':
396 440
      return 'format_interval';
397
      break;
441

  
398 442
    case 'date_plain':
399 443
      return 'date_plain';
400
      break;
444

  
401 445
    default:
402 446
      $format = date_format_type_format($format_type, $langcode);
403 447
      break;
......
410 454

  
411 455
/**
412 456
 * Helper function to get the right format for a format type.
457
 *
413 458
 * Checks for locale-based format first.
414 459
 */
415 460
function date_format_type_format($format_type, $langcode = NULL) {
......
432 477
        case 'short':
433 478
          $default = 'm/d/Y - H:i';
434 479
          break;
480

  
435 481
        case 'long':
436 482
          $default = 'l, F j, Y - H:i';
437 483
          break;
484

  
438 485
        // If it's not one of the core date types and isn't stored in the
439 486
        // database, we'll fall back on using the same default format as the
440 487
        // 'medium' type.
441 488
        case 'medium':
442 489
        default:
443 490
          // @todo: If a non-core module provides a date type and does not
444
          //   variable_set() a default for it, the default assumed here may
445
          //   not be correct (since the default format used by 'medium' may
446
          //   not even be one of the allowed formats for the date type in
447
          //   question). To fix this properly, we should really call
448
          //   system_get_date_formats($format_type) and take the first
449
          //   format from that list as the default. However, this function
450
          //   is called often (on many different page requests), so calling
451
          //   system_get_date_formats() from here would be a performance hit
452
          //   since that function writes several records to the database
453
          //   during each page request that calls it.
491
          // variable_set() a default for it, the default assumed here may
492
          // not be correct (since the default format used by 'medium' may
493
          // not even be one of the allowed formats for the date type in
494
          // question). To fix this properly, we should really call
495
          // system_get_date_formats($format_type) and take the first
496
          // format from that list as the default. However, this function
497
          // is called often (on many different page requests), so calling
498
          // system_get_date_formats() from here would be a performance hit
499
          // since that function writes several records to the database
500
          // during each page request that calls it.
454 501
          $default = 'D, m/d/Y - H:i';
455 502
          break;
503

  
456 504
      }
457 505
      $format = variable_get('date_format_' . $format_type, $default);
458 506
    }
......
506 554
        elseif ((!empty($max_count) && is_numeric($max_count) && $count >= $max_count) ||
507 555
          (!empty($value['value'])  && $value['value'] < $start) ||
508 556
          (!empty($value['value2']) && $value['value2'] > $end)) {
509
            unset($entity->{$field_name}[$langcode][$delta]);
557
          unset($entity->{$field_name}[$langcode][$delta]);
510 558
        }
511 559
        else {
512 560
          $count++;
......
647 695
}
648 696

  
649 697
/**
650
 * Auto creation callback for fields which contain two date values in one
698
 * Auto creation callback for fields which contain two date values in one.
651 699
 */
652 700
function date_entity_metadata_struct_create($name, $property_info) {
653 701
  return array(
......
658 706

  
659 707
/**
660 708
 * Callback for setting an individual field value if a to-date may be there too.
709
 *
661 710
 * Based on entity_property_verbatim_set().
662 711
 *
663
 * The passed in unix timestamp (UTC) is converted to the right value and
664
 * format dependent on the field.
712
 * The passed in unix timestamp (UTC) is converted to the right value and format dependent on the field.
665 713
 *
666 714
 * $name is either 'value' or 'value2'.
667 715
 */
......
683 731
}
684 732

  
685 733
/**
686
 * Duplicate functionality of what is now date_all_day_field() in
687
 * the Date All Day module. Copy left here to avoid breaking other
688
 * modules that use this function.
734
 * Duplicate functionality of what is now date_all_day_field() in the Date All Day module.
735
 *
736
 * Copy left here to avoid breaking other modules that use this function.
689 737
 *
690 738
 * DEPRECATED!, will be removed at some time in the future.
691 739
 */
......
759 807
    $entity = $context['entity'];
760 808
    $info = entity_get_info($entity_type);
761 809
    $id = $info['entity keys']['id'];
762
    $widget['is_new']= FALSE;
810
    $widget['is_new'] = FALSE;
763 811
    if (empty($entity->$id)) {
764 812
      $widget['is_new'] = TRUE;
765 813
    }

Formats disponibles : Unified diff