diff --git a/date/date.devel_generate.inc b/date/date.devel_generate.inc deleted file mode 100644 index 0280911b3c9277aad6c4a548a32333ba4c630b2f..0000000000000000000000000000000000000000 --- a/date/date.devel_generate.inc +++ /dev/null @@ -1,188 +0,0 @@ -difference($start2); - $form_values = array(); - - // Create the default case more frequently than case 1 or 2. - $which = mt_rand(0, 10); - $max_items = 10; - $intervals = array_keys(INTERVAL_options()); - unset($intervals[0]); - $interval = $intervals[mt_rand(1, 3)]; - switch ($which) { - case 1: - $mo = mt_rand(1, 28); - $options = array('YEARLY', 'MONTHLY'); - $freq = date_content_generate_key($options); - $freq = $options[$freq]; - $form_values['FREQ'] = $freq; - // Make sure we'll find a match in our range. - if ($freq == 'YEARLY') { - $interval = 1; - } - $form_values['BYMONTHDAY'] = array($mo); - break; - case 2: - $mo = mt_rand(1, 12); - $options = array('YEARLY', 'MONTHLY'); - $freq = date_content_generate_key($options); - $freq = $options[$freq]; - $form_values['FREQ'] = $freq; - // Make sure we'll find a match in our range. - if ($freq == 'YEARLY') { - $interval = 1; - } - $form_values['BYMONTH'] = array($mo); - break; - default: - $dows = array_keys(date_content_repeat_dow_options()); - $day = date_content_generate_key($dows); - $dow = $dows[$day]; - $options = array('MONTHLY', 'DAILY', 'WEEKLY'); - $freq = date_content_generate_key($options); - $freq = $options[$freq]; - $form_values['FREQ'] = $freq; - $form_values['BYDAY'] = array($dow); - break; - } - - $form_values['INTERVAL'] = $interval; - - switch ($freq) { - case 'YEARLY': - $period = 'year'; - break; - case 'MONTHLY': - $period = 'month'; - break; - case 'WEEKLY': - $period = 'week'; - break; - default: - $period = 'day'; - break; - - } - date_modify($start2, '+' . max(1, $forward) . ' years'); - date_increment_round($start2, $increment); - $until = date_format($start2, 'Y-m-d H:i:s'); - $form_values['UNTIL'] = array('datetime' => $until, 'tz' => 'UTC'); - $form_values['COUNT'] = $max_items; - - $rrule = date_api_ical_build_rrule($form_values); - $values = date_repeat_build_dates($rrule, $form_values, $field, $node_field); - - $start = $node_field; - $node_field = array(0 => $start); - $node_field[0]['rrule'] = $rrule; - $node_field += $values; - } - return $node_field; -} - -function date_content_generate_key($array) { - $keys = array_keys($array); - $min = array_shift($keys); - $max = array_pop($keys); - return mt_rand($min, $max); -} - -/** - * Helper function for BYDAY options. - * - * Creates options like -1SU and 2TU - * Omit options that won't find many matches, like 5th Sunday. - */ -function date_content_repeat_dow_options() { - $options = array(); - foreach (date_repeat_dow_count_options() as $count_key => $count_value) { - foreach (date_repeat_dow_day_options() as $dow_key => $dow_value) { - if ($count_key != 5 && $count_key != -5) { - $options[$count_key . $dow_key] = $count_value . ' ' . $dow_value; - } - } - } - return $options; -} \ No newline at end of file diff --git a/date/date.field.inc b/date/date.field.inc deleted file mode 100644 index c6f8f1246474cf64dea45b38ca9535320dd264ce..0000000000000000000000000000000000000000 --- a/date/date.field.inc +++ /dev/null @@ -1,543 +0,0 @@ - array( - 'label' => t('Default'), - 'field types' => array('date', 'datestamp', 'datetime'), - 'settings' => array( - 'format_type' => 'long', - 'show_repeat_rule' => 'show', - 'multiple_number' => '', - 'multiple_from' => '', - 'multiple_to' => '', - 'fromto' => 'both', - ), - ), - 'format_interval' => array( - 'label' => t('As Time Ago'), - 'field types' => array('date', 'datestamp', 'datetime'), - 'settings' => array( - 'interval' => 2, - ), - ), - ); - $formats = _system_date_format_types_build(); - foreach ($formats as $format => $value) { - $formatters['date_' . $format] = $formatters['date_default']; - $formatters['date_' . $format]['format_type'] = $format; - $formatters['date_' . $format]['label'] = $value['title']; - } - return $formatters; -} - -/** - * Implements hook_field_formatter_settings_form(). - */ -function date_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { - $display = $instance['display'][$view_mode]; - $formatter = $display['type']; - module_load_include('inc', 'date', 'date_admin'); - switch ($formatter) { - case 'format_interval': - return date_interval_formatter_settings_form($field, $instance, $view_mode, $form, $form_state); - default: - return date_default_formatter_settings_form($field, $instance, $view_mode, $form, $form_state); - } -} - -/** - * Implements hook_field_formatter_settings_summary(). - */ -function date_field_formatter_settings_summary($field, $instance, $view_mode) { - $display = $instance['display'][$view_mode]; - $formatter = $display['type']; - module_load_include('inc', 'date', 'date_admin'); - switch ($formatter) { - case 'format_interval': - return date_interval_formatter_settings_summary($field, $instance, $view_mode); - default: - return date_default_formatter_settings_summary($field, $instance, $view_mode); - } -} - -/** - * Implements hook_field_formatter_view(). - * - * Useful values: - * - * $entity->date_id - * If set, this will show only an individual date on a field with - * multiple dates. The value should be a string that contains - * the following values, separated with colons: - * - module name of the module adding the item - * - node nid - * - field name - * - delta value of the field to be displayed - * - other information the module's custom theme might need - * - * Used by the calendar module and available for other uses. - * example: 'date:217:field_date:3:test' - * - * $entity->date_repeat_show - * If true, tells the theme to show all the computed values - * of a repeating date. If not true or not set, only the - * start date and the repeat rule will be displayed. - * - */ -function date_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { - $element = array(); - $settings = $display['settings']; - $formatter = $display['type']; - $vars = array( - 'entity' => $entity, - 'entity_type' => $entity_type, - 'field' => $field, - 'instance' => $instance, - 'langcode' => $langcode, - 'items' => $items, - 'display' => $display, - 'dates' => array(), - ); - - // See if we are only supposed to display a selected - // item from multiple value date fields. - $selected_deltas = array(); - if (!empty($entity->date_id)) { - foreach ((array) $entity->date_id as $key => $id) { - list($module, $nid, $field_name, $selected_delta, $other) = explode(':', $id); - if ($field_name == $field['field_name']) { - $selected_deltas[] = $selected_delta; - } - } - } - - switch ($display['type']) { - case 'format_interval': - foreach ($items as $delta => $item) { - if (!empty($entity->date_id) && !in_array($delta, $selected_deltas)) { - continue; - } - else { - $vars['delta'] = $delta; - $vars['item'] = $item; - $vars['dates'] = date_formatter_process($formatter, $entity_type, $entity, $field, $instance, $langcode, $item, $display); - $element[$delta] = array('#markup' => theme('date_display_interval', $vars)); - } - } - break; - default: - foreach ($items as $delta => $item) { - if (!empty($entity->date_id) && !in_array($delta, $selected_deltas)) { - continue; - } - else { - $vars['delta'] = $delta; - $vars['item'] = $item; - $vars['dates'] = date_formatter_process($formatter, $entity_type, $entity, $field, $instance, $langcode, $item, $display); - $element[$delta] = array('#markup' => theme('date_display_combination', $vars)); - } - } - break; - } - - return $element; -} - -/** - * Implements hook_field_is_empty(). - */ -function date_field_is_empty($item, $field) { - // Sometimes a $item is a date object. - // Coming from repeating dates. Why?? - if (!is_array($item)) { - return FALSE; - } - if (empty($item['value'])) { - return TRUE; - } - elseif ($field['settings']['todate'] == 'required' && empty($item['value2'])) { - return TRUE; - } - return FALSE; -} - -/** - * Implements hook_field_info(). - */ -function date_field_info() { - $settings = array( - 'settings' => array( - 'todate' => '', - 'repeat' => 0, - 'granularity' => drupal_map_assoc(array('year', 'month', 'day', 'hour', 'minute')), - 'tz_handling' => 'site', - 'timezone_db' => 'UTC', - ), - 'instance_settings' => array( - 'default_value' => 'now', - 'default_value_code' => '', - 'default_value2' => 'blank', - 'default_value_code2' => '', - 'default_format' => 'medium', - ), - // Integrate with the Entity Metadata module. - 'property_type' => 'date', - 'property_callbacks' => array('date_entity_metadata_property_info_alter'), - ); - return array( - 'date' => array( - 'label' => 'Date', - 'description' => t('Store a date in the database as an ISO date, recommended for historical or partial dates.'), - 'default_widget' => 'date_select', - 'default_formatter' => 'date_default', - ) + $settings, - 'datestamp' => array( - 'label' => 'Datestamp', - 'description' => t('Store a date in the database as a timestamp, deprecated format to suppport legacy data.'), - 'default_widget' => 'date_select', - 'default_formatter' => 'date_default', - ) + $settings, - 'datetime' => array( - 'label' => 'Datetime', - 'description' => t('Store a date in the database as a datetime field, recommended for complete dates and times that may need timezone conversion.'), - 'default_widget' => 'date_select', - 'default_formatter' => 'date_default', - ) + $settings, - ); -} - -/** - * Implements hook_field_widget_info(). - */ -function date_field_widget_info() { - $settings = array( - 'settings' => array( - 'input_format' => date_default_format('date_select'), - 'input_format_custom' => '', - 'increment' => 1, - 'text_parts' => array(), - 'year_range' => '-3:+3', - 'label_position' => 'above', - 'repeat_collapsed' => 0, - ), - 'behaviors' => array( - 'multiple values' => FIELD_BEHAVIOR_DEFAULT, - 'default value' => FIELD_BEHAVIOR_CUSTOM, - ), - ); - - // Repeating dates have custom handling - // for multiple values. - $repeat_settings = $settings; - $repeat_settings['behaviors']['multiple values'] = FIELD_BEHAVIOR_CUSTOM; - - $info = array( - 'date_select' => array( - 'label' => t('Select List'), - 'field types' => array('date', 'datestamp', 'datetime'), - ) + $settings, - 'date_select_repeat' => array( - 'label' => t('Select List with Repeat options'), - 'field types' => array('date', 'datestamp', 'datetime'), - ) + $repeat_settings, - 'date_text' => array( - 'label' => t('Text Field with custom input format'), - 'field types' => array('date', 'datestamp', 'datetime'), - ) + $settings, - 'date_text_repeat' => array( - 'label' => t('Text Field with Repeat options'), - 'field types' => array('date', 'datestamp', 'datetime'), - ) + $repeat_settings, - ); - if (module_exists('date_popup')) { - $info['date_popup'] = array( - 'label' => t('Text Field with Date Pop-up calendar'), - 'field types' => array('date', 'datestamp', 'datetime'), - ) + $settings; - $info['date_popup_repeat'] = array( - 'label' => t('Text Field with Date Pop-up and Repeat options'), - 'field types' => array('date', 'datestamp', 'datetime'), - ) + $repeat_settings; - } - if (!module_exists('date_repeat')) { - unset($info['date_select_repeat']); - unset($info['date_text_repeat']); - if (isset($info['date_popup_repeat'])) { - unset($info['date_popup_repeat']); - } - } - return $info; -} - -/** - * Implements hook_field_load(). - */ -function date_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) { - foreach ($entities as $id => $entity) { - foreach ($items[$id] as $delta => $item) { - // If the file does not exist, mark the entire item as empty. - $timezone = isset($item['timezone']) ? $item['timezone'] : ''; - if (is_array($item)) { - $items[$id][$delta]['timezone'] = date_get_timezone($field['settings']['tz_handling'], $timezone); - $items[$id][$delta]['timezone_db'] = date_get_timezone_db($field['settings']['tz_handling']); - $items[$id][$delta]['date_type'] = $field['type']; - } - } - } -} - -/** - * Implements hook_field_validate(). - */ -function date_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) { - $field_name = $field['field_name']; - $flexible = 0; - - // Don't try to validate if there were any errors before this point - // since the element won't have been munged back into a date. - if (!form_get_errors()) { - foreach ($items as $delta => $item) { - if (is_array($item)) { - $process = date_process_values($field, $instance); - $date1 = new DateObject($item['value'], $item['timezone'], date_type_format($field['type'])); - if (empty($item['value2']) && $item['value2'] !== 0) { - $date2 = clone($date1); - } - else { - $date2 = new DateObject($item['value2'], $item['timezone'], date_type_format($field['type'])); - } - $valid1 = $date1->validGranularity($field['settings']['granularity'], $flexible); - $valid2 = $date2->validGranularity($field['settings']['granularity'], $flexible); - - foreach ($process as $processed) { - if ($processed == 'value' && $field['settings']['todate'] && !$valid1 && $valid2) { - $errors[$field['field_name']][$langcode][$delta][] = array( - 'error' => 'value', - 'message' => t("A 'From date' date is required for field %field #%delta.", array('%delta' => $field['cardinality'] ? intval($delta + 1) : '', '%field' => t($instance['label']))), - ); - } - if ($processed == 'value2' && $field['settings']['todate'] == 'required' && ($instance['required'] && $valid1 && !$valid2)) { - $errors[$field['field_name']][$langcode][$delta][] = array( - 'error' => 'value2', - 'message' => t("A 'To date' is required for field %field #%delta.", array('%delta' => $field['cardinality'] ? intval($delta + 1) : '', '%field' => t($instance['label']))), - ); - } - } - } - } - } - -} - -/** - * Implements hook_field_presave(). - */ -function date_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) { - date_field_update($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_insert(). - */ -function date_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { - date_field_update($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_update(). - */ -function date_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { - $field_name = $field['field_name']; - - if (empty($items)) { - return; - } - // Add some information needed to interpret token values. - $values = $items; - foreach ($values as $delta => $item) { - $timezone = isset($item['timezone']) ? $item['timezone'] : ''; - if (is_array($item)) { - $items[$delta]['timezone'] = date_get_timezone($field['settings']['tz_handling'], $timezone); - $items[$delta]['timezone_db'] = date_get_timezone_db($field['settings']['tz_handling']); - $items[$delta]['date_type'] = $field['type']; - } - } - $entity->{$field['field_name']}[$langcode] = $items; - - foreach ($values as $delta => $item) { - if (is_array($item)) { - // Special case for ISO dates which may have been given artificial values for - // some date parts to make them into valid dates. - // @TODO Decide how to replace the date_limit_value() function. - if (!empty($item['value']) && $field['type'] == DATE_ISO) { - //$items[$delta]['value'] = date_limit_value($items[$delta]['value'], date_granularity($field), $field['type']); - if ($field['settings']['todate']) { - //$items[$delta]['value2'] = date_limit_value($items[$delta]['value2'], date_granularity($field), $field['type']); - } - } - } - } - $entity->{$field['field_name']}[$langcode] = $items; -} - -/** - * Wrapper functions for date administration, included only when - * processing field settings. - */ -function date_field_instance_settings_form($field, $instance) { - module_load_include('inc', 'date', 'date_admin'); - return _date_field_instance_settings_form($field, $instance); -} - -function date_field_widget_settings_form($field, $instance) { - module_load_include('inc', 'date', 'date_admin'); - return _date_field_widget_settings_form($field, $instance); -} - -function date_field_settings_form($field, $instance, $has_data) { - module_load_include('inc', 'date', 'date_admin'); - return _date_field_settings_form($field, $instance, $has_data); -} - -/** - * Implements hook_content_migrate_field_alter(). - * - * Use this to tweak the conversion of field settings - * from the D6 style to the D7 style for specific - * situations not handled by basic conversion, - * as when field types or settings are changed. - * - * $field_value['widget_type'] is available to - * see what widget type was originally used. - */ -function date_content_migrate_field_alter(&$field_value) { - - switch ($field_value['module']) { - case 'date': - - // So far, no changes to field except those we have to make - // later in the instance, to move some values from the - // field to the widget. - break; - } -} - -/** - * Implements hook_content_migrate_instance_alter(). - * - * Use this to tweak the conversion of instance or widget settings - * from the D6 style to the D7 style for specific - * situations not handled by basic conversion, as when - * formatter or widget names or settings are changed. - */ -function date_content_migrate_instance_alter(&$instance_value) { - switch ($instance_value['module']) { - case 'date': - - $field_value = content_migrate_get_field_values($instance_value['field_name']); - - // Some settings have been moved from field to instance. - $default_format = $field_value['settings']['default_format']; - unset($field_value['settings']['default_format']); - $instance_value['settings']['repeat_collapsed'] = $field_value['settings']['repeat_collapsed']; - unset($field_value['settings']['repeat_collapsed']); - - // Some settings have been moved from widget settings to instance settings. - $instance_value['settings']['default_value'] = $instance_value['default_value']; - unset($instance_value['default_value']); - $instance_value['settings']['default_value_code'] = $instance_value['widget']['settings']['default_value_code']; - unset($instance_value['widget']['settings']['default_value_code']); - $instance_value['settings']['default_value2'] = $instance_value['widget']['settings']['default_value2']; - unset($instance_value['widget']['settings']['default_value2']); - $instance_value['settings']['default_value_code2'] = $instance_value['widget']['settings']['default_value_code2']; - unset($instance_value['widget']['settings']['default_value_code2']); - break; - - // We need to retrieve formatter settings from the variables and store them in the instance. - // Some formatter names changed, and system date type names changed. - $new_type = array( - 'format_interval' => 'format_interval', - 'default' => 'date_default', - 'small' => 'date_short', - 'large' => 'date_long', - 'medium' => 'date_medium', - ); - $new_settings = array( - 'date_default' => array( - 'format_type' => $default_format, - 'show_repeat_rule' => 'show', - 'multiple_number' => '', - 'multiple_from' => '', - 'multiple_to' => '', - 'fromto' => 'both', - ), - 'format_interval' => array( - 'interval' => 2, - ), - 'date_short' => array( - 'format_type' => 'short', - 'show_repeat_rule' => 'show', - 'multiple_number' => '', - 'multiple_from' => '', - 'multiple_to' => '', - 'fromto' => 'both', - ), - 'date_long' => array( - 'format_type' => 'long', - 'show_repeat_rule' => 'show', - 'multiple_number' => '', - 'multiple_from' => '', - 'multiple_to' => '', - 'fromto' => 'both', - ), - 'date_medium' => array( - 'format_type' => 'medium', - 'show_repeat_rule' => 'show', - 'multiple_number' => '', - 'multiple_from' => '', - 'multiple_to' => '', - 'fromto' => 'both', - ), - ); - // Add the custom date format options to the list. - $formats = array_keys(system_get_date_formats()); - foreach ($formats as $format) { - if ($format != 'short' && $format != 'long' && $format != 'medium') { - $new_type['date_' . $format] = $new_format; - $new_settings['date_' . $format] = $new_settings['date_default']; - $new_settings['date_' . $format]['format_type'] = $format; - } - } - foreach ($instance_value['display'] as $context => $settings) { - $instance_value['display'][$context]['type'] = $new_type[$settings['type']]; - $old_settings = date_old_formatter_get_settings($instance['field_name'], $instance['bundle'], $context); - foreach ($new_settings as $key => $value) { - $instance_value['display'][$context]['settings'][$key] = !empty($old_settings[$key]) ? $old_settings[$key] : $value; - } - } - - // We changed some of the field values, save them. - field_info_update($field_values); - break; - } -} - -function date_old_formatter_get_settings($field_name, $type_name, $context) { - $options = array(); - $value = 'date:'. $type_name .':'. $context .':'. $field_name; - $options['show_repeat_rule'] = variable_get($value .'_show_repeat_rule', 'show'); - $options['multiple_number'] = variable_get($value .'_multiple_number', ''); - $options['multiple_from'] = variable_get($value .'_multiple_from', ''); - $options['multiple_to'] = variable_get($value .'_multiple_to', ''); - $options['fromto'] = variable_get($value .'_fromto', 'both'); - return $options; -} diff --git a/date/date.info b/date/date.info deleted file mode 100644 index abc3e5b2b2616e3461063be95b7d04b6ab717e55..0000000000000000000000000000000000000000 --- a/date/date.info +++ /dev/null @@ -1,17 +0,0 @@ -; $Id$ -name = Date -description = Defines CCK date/time fields and widgets. -dependencies[] = date_api -package = Date/Time -core = 7.x -php = 5.2 -files[] = date_admin.inc -files[] = date_content_generate.inc -files[] = date_elements.inc -files[] = date_handler_field_multiple.inc -files[] = date_repeat.inc -files[] = date_token.inc -files[] = date.install -files[] = date.module -files[] = date.theme -files[] = date.views.inc diff --git a/date/date.install b/date/date.install deleted file mode 100644 index 8b8e5ae975e80f2cdcb781f2fc3705976ac3d953..0000000000000000000000000000000000000000 --- a/date/date.install +++ /dev/null @@ -1,99 +0,0 @@ - 'int', - 'not null' => FALSE, - 'sortable' => TRUE, - 'views' => TRUE, - ); - break; - case 'datetime': - $db_columns['value'] = array( - 'type' => 'datetime', - 'mysql_type' => 'DATETIME', - 'pgsql_type' => 'timestamp without time zone', - 'not null' => FALSE, - 'sortable' => TRUE, - 'views' => TRUE, - ); - break; - default: - $db_columns['value'] = array( - 'type' => 'varchar', - 'length' => 20, - 'not null' => FALSE, - 'sortable' => TRUE, - 'views' => TRUE, - ); - break; - } - - // If a second date is needed for 'To date', just make a copy of the first one. - if (!empty($field['settings']['todate'])) { - $db_columns['value2'] = $db_columns['value']; - - // We don't want CCK to create additional columns, just the first. - // We modify them our own way in views data. - $db_columns['value2']['views'] = FALSE; - } - // timezone and offset columns are used only if date-specific dates are chosen. - if (isset($field['settings']['tz_handling']) && $field['settings']['tz_handling'] == 'date') { - $db_columns['timezone'] = array( - 'type' => 'varchar', - 'length' => 50, - 'not null' => FALSE, - 'sortable' => TRUE, - 'views' => FALSE, - ); - $db_columns['offset'] = array( - 'type' => 'int', - 'not null' => FALSE, - 'sortable' => TRUE, - 'views' => FALSE, - ); - if (!empty($field['settings']['todate'])) $db_columns['offset2'] = array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE, 'views' => FALSE); - } - if (isset($field['settings']['repeat']) && $field['settings']['repeat'] == 1) { - $db_columns['rrule'] = array( - 'type' => 'text', - 'not null' => FALSE, - 'sortable' => FALSE, - 'views' => FALSE, - ); - } - return array('columns' => $db_columns); -} - - -function date_update_last_removed() { - return 6005; -} - -/** - * Move settings that were stored in variables to field formatter settings. - */ -// TODO, update field formatter settings with the variables, once we know -// how the field update process will work. - -/** - * A copy of a D6 function we can use to retrive the formatter settings - * and return them as an option array. - */ -function date_formatter_get_settings($field_name, $bundle, $context) { - $options = array(); - $value = 'date:' . $bundle . ':' . $context . ':' . $field_name; - $options['repeat']['show_repeat_rule'] = variable_get($value . '_show_repeat_rule', 'show'); - $options['multiple']['multiple_number'] = variable_get($value . '_multiple_number', ''); - $options['multiple']['multiple_from'] = variable_get($value . '_multiple_from', ''); - $options['multiple']['multiple_to'] = variable_get($value . '_multiple_to', ''); - $options['fromto']['fromto'] = variable_get($value . '_fromto', 'both'); - return $options; -} diff --git a/date/date.module b/date/date.module deleted file mode 100644 index 389b3f13f3b9652ef60eb89dd66f62d977d8632d..0000000000000000000000000000000000000000 --- a/date/date.module +++ /dev/null @@ -1,731 +0,0 @@ - 'Repeats', - 'page callback' => 'date_repeat_page', - 'page arguments' => array(1, 'node'), - 'access callback' => 'date_repeat_entity', - 'access arguments' => array(1, 'node'), - 'type' => MENU_LOCAL_TASK, - ); - - return $items; -} - -function date_permission() { - return array('view date repeats' => array( - 'title' => t('View Repeating Dates'), - 'description' => t('Allow user to see a tab with all the times this date repeats.'), - )); -} - -/** - * See if the user can access repeat date - * info on this entity. - */ -function date_repeat_entity($entity, $entity_type = 'node') { - if (date_repeat_type($entity, $entity_type = 'node')) { - return user_access('view date repeats'); - } - return FALSE; -} - -/** - * See if there is a date field in this instance. - * - * Field type is not in the $field array we get from - * field_info_instances(), we need to call - * field_info_field() to find that. - */ -function date_repeat_type($entity, $entity_type = 'node') { - $bundle = ''; - switch ($entity_type) { - case 'node': - $bundle = $entity->type; - break; - } - $type = field_info_instances($entity_type, $bundle); - foreach ($type as $field_name => $field) { - $field = field_info_field($field_name); - if (in_array($field['type'], array('date', 'datestamp', 'datetime')) && $field['settings']['repeat']) { - return TRUE; - } - } - return FALSE; -} - -function date_repeat_fields($entity, $entity_type = 'node') { - $bundle = ''; - switch ($entity_type) { - case 'node': - $bundle = $entity->type; - break; - } - $type = field_info_instances($entity_type, $bundle); - $fields = array(); - foreach ($type as $field_name => $field) { - $field = field_info_field($field_name); - if (in_array($field['type'], array('date', 'datestamp', 'datetime')) && $field['settings']['repeat']) { - $fields[] = $field_name; - } - } - return $fields; -} - -function date_repeat_page($entity, $entity_type = 'node') { - drupal_set_title($entity->title); - $entity->date_repeat_show_all = TRUE; - $entity->content = array(); - $field_names = date_repeat_fields($entity, $entity_type); - $output = ''; - foreach ($field_names as $field_name) { - $output .= drupal_render(field_view_field($entity_type, $entity, $field_name, 'full')); - } - return $output; -} - -function date_is_repeat_field($field, $instance) { - $repeat_widgets = array( - 'date_select_repeat', - 'date_text_repeat', - 'date_popup_repeat', - ); - if (in_array($instance['widget']['type'], $repeat_widgets)) { - return TRUE; - } - elseif (in_array($instance['widget']['type']['#value'], $repeat_widgets)) { - return TRUE; - } - return FALSE; -} - -function date_default_format($type) { - if (stristr($type, 'date_popup') && module_exists('date_popup')) { - $formats = date_popup_formats(); - $default_format = array_shift($formats); - } - else { - // example input formats must show all possible date parts, so add seconds. - $default_format = str_replace('i', 'i:s', variable_get('date_format_short', 'm/d/Y - H:i')); - } - return $default_format; -} - -function date_input_date($field, $instance, $element, $input) { - switch ($instance['widget']['type']) { - case 'date_text': - case 'date_text_repeat': - $function = 'date_text_input_date'; - break; - case 'date_popup': - case 'date_popup_repeat': - $function = 'date_popup_input_date'; - break; - default: - $function = 'date_select_input_date'; - } - return $function($element, $input); -} - -/** - * Implements hook_theme(). - */ -function date_theme() { - $path = drupal_get_path('module', 'date'); - module_load_include('theme', 'date', 'date'); - - $base = array( - 'file' => 'date.theme', - 'path' => "$path", - ); - $themes = array( - 'date_combo' => $base + array('render element' => 'element'), - 'date_text_parts' => $base + array('render element' => 'element'), - 'date' => $base + array('render element' => 'element'), - 'date_all_day' => $base + array( - 'variables' => array( - 'field' => NULL, - 'instance' => NULL, - 'which' => NULL, - 'date1' => NULL, - 'date2' => NULL, - 'format' => NULL, - 'entity_type' => NULL, - 'entity' => NULL, - 'view' => NULL - ) - ), - 'date_all_day_label' => $base + array('variables' => array()), - 'date_display_single' => $base + array('variables' => array( - 'date' => NULL, - 'timezone' => NULL - )), - 'date_display_range' => $base + array( - 'variables' => array( - 'date1' => NULL, - 'date2' => NULL, - 'timezone' => NULL - )), - 'date_repeat_display' => $base + array( - 'variables' => array( - 'field' => NULL, - 'item' => NULL, - 'entity_type' => NULL, - 'entity' => NULL, - 'dates' => NULL - ), - 'function' => 'theme_date_repeat_display', - ), - 'date_display_combination' => $base + array( - 'variables' => array( - 'entity_type' => NULL, - 'entity' => NULL, - 'field' => NULL, - 'instance' => NULL, - 'langcode' => NULL, - 'item' => NULL, - 'delta' => NULL, - 'display' => NULL, - 'dates' => NULL, - ), - ), - 'date_display_interval' => $base + array( - 'variables' => array( - 'entity_type' => NULL, - 'entity' => NULL, - 'field' => NULL, - 'instance' => NULL, - 'langcode' => NULL, - 'item' => NULL, - 'delta' => NULL, - 'display' => NULL, - 'dates' => NULL, - ), - ), - ); - - return $themes; -} - -/** - * Implements hook_element_info(). - * - * date_combo will create a 'from' and optional 'to' date, along with - * an optional 'timezone' column for date-specific timezones. Each - * 'from' and 'to' date will be constructed from date_select or date_text. - */ -function date_element_info() { - $type = array(); - $type['date_combo'] = array( - '#input' => TRUE, - '#delta' => 0, - '#columns' => array('value', 'value2', 'timezone', 'offset', 'offset2'), - '#process' => array('date_combo_element_process'), - '#element_validate' => array('date_combo_validate'), - '#value_callback' => 'date_combo_value_callback', - '#theme_wrappers' => array('date_combo'), - ); - return $type; -} - -/** - * Helper function for creating formatted date arrays from a formatter. - * - * Use the Date API to get an object representation of a date field - * - * @param array $field - * @param array $item - a entity field item, like $entity->myfield[0] - * - * @return array that holds the From and To date objects - * Each date object looks like: - * date [value] => array ( - * [db] => array ( // the value stored in the database - * [object] => the datetime object - * [datetime] => 2007-02-15 20:00:00 - * ) - * [local] => array ( // the local representation of that value - * [object] => the datetime object - * [datetime] => 2007-02-15 14:00:00 - * [timezone] => US/Central - * [offset] => -21600 - * ) - * ) - */ -function date_formatter_process($formatter, $entity_type, $entity, $field, $instance, $langcode, $item, $display) { - $dates = array(); - $timezone = date_default_timezone(); - if (empty($timezone)) { - return $dates; - } - - $granularity = date_granularity($field); - $settings = $display['settings']; - $field_name = $field['field_name']; - $format = date_formatter_format($formatter, $settings, $granularity, $langcode); - $timezone = isset($item['timezone']) ? $item['timezone'] : ''; - $timezone = date_get_timezone($field['settings']['tz_handling'], $timezone); - $timezone_db = date_get_timezone_db($field['settings']['tz_handling']); - $process = date_process_values($field); - foreach ($process as $processed) { - if (empty($item[$processed])) { - $dates[$processed] = NULL; - } - else { - // create a date object with a gmt timezone from the database value - $value = $item[$processed]; - // @TODO Figure out how to replace date_fuzzy_datetime() function. - if ($field['type'] == DATE_ISO) { - //$value = str_replace(' ', 'T', date_fuzzy_datetime($value)); - } - $date = new DateObject($value, $timezone_db); - $date->limitGranularity($field['settings']['granularity']); - - $dates[$processed] = array(); - $dates[$processed]['db']['object'] = $date; - $dates[$processed]['db']['datetime'] = date_format($date, DATE_FORMAT_DATETIME); - - date_timezone_set($date, timezone_open($timezone)); - $dates[$processed]['local']['object'] = $date; - $dates[$processed]['local']['datetime'] = date_format($date, DATE_FORMAT_DATETIME); - $dates[$processed]['local']['timezone'] = $timezone; - $dates[$processed]['local']['offset'] = date_offset_get($date); - - //format the date, special casing the 'interval' format which doesn't need to be processed - $dates[$processed]['formatted'] = ''; - if (is_object($date)) { - if ($format == 'format_interval') { - $dates[$processed]['interval'] = date_format_interval($date); - } - elseif ($format == 'format_calendar_day') { - $dates[$processed]['calendar_day'] = date_format_calendar_day($date); - } - elseif ($format == 'U') { - $dates[$processed]['formatted'] = date_format_date($date, 'custom', $format); - $dates[$processed]['formatted_date'] = date_format_date($date, 'custom', $format); - $dates[$processed]['formatted_time'] = ''; - $dates[$processed]['formatted_timezone'] = ''; - } - elseif (!empty($format)) { - $dates[$processed]['formatted'] = date_format_date($date, 'custom', $format); - $dates[$processed]['formatted_date'] = date_format_date($date, 'custom', date_limit_format($format, array('year', 'month', 'day'))); - $dates[$processed]['formatted_time'] = date_format_date($date, 'custom', date_limit_format($format, array('hour', 'minute', 'second'))); - $dates[$processed]['formatted_timezone'] = date_format_date($date, 'custom', date_limit_format($format, array('timezone'))); - } - } - } - } - if (empty($dates['value2'])) { - $dates['value2'] = $dates['value']; - } - $date1 = $dates['value']['local']['object']; - $date2 = $dates['value2']['local']['object']; - - $all_day = ''; - $all_day2 = ''; - if ($format != 'format_interval') { - $all_day1 = theme('date_all_day', array( - 'field' => $field, - 'which' => 'date1', - 'date1' => $date1, - 'date2' => $date2, - 'format' => $format, - 'entity_type' => $entity_type, - 'entity' => $entity)); - $all_day2 = theme('date_all_day', array( - 'field' => $field, - 'which' => 'date2', - 'date1' => $date1, - 'date2' => $date2, - 'format' => $format, - 'entity_type' => $entity_type, - 'entity' => $entity)); - } - if ((!empty($all_day1) && $all_day1 != $dates['value']['formatted']) - || (!empty($all_day2) && $all_day2 != $dates['value2']['formatted'])) { - $dates['value']['formatted_time'] = theme('date_all_day_label'); - $dates['value2']['formatted_time'] = theme('date_all_day_label'); - $dates['value']['formatted'] = $all_day1; - $dates['value2']['formatted'] = $all_day2; - } - $dates['format'] = $format; - return $dates; -} - -/** - * $field['settings']['granularity'] will contain an array like ('hour' => 'hour', 'month' => 0) - * where the values turned on return their own names and the values turned off return a zero - * need to reconfigure this into a simple array of the turned on values - */ -function date_granularity($field) { - if (!is_array($field) || !is_array($field['settings']['granularity'])) { - $field['settings']['granularity'] = drupal_map_assoc(array('year', 'month', 'day')); - } - return array_values(array_filter($field['settings']['granularity'])); -} - -/** - * Helper function to create an array of the date values in a - * field that need to be processed. - */ -function date_process_values($field) { - return $field['settings']['todate'] ? array('value', 'value2') : array('value'); -} - -/** - * Implement hook_help(). - */ -function date_help($path, $arg) { - switch ($path) { - case 'admin/help#date': - return '
' . t('Complete documentation for the Date and Date API modules is available at http://drupal.org/node/92460.', array('@link' => 'http://drupal.org/node/92460')) . '
'; - break; - } -} - -/** - * Implements hook_form_alter(). - * Make sure date information gets updated. - */ -function date_form_alter(&$form, &$form_state, $form_id) { - if ($form_id == 'field_ui_field_edit_form') { - $field = $form['field']; - $instance = $form['instance']; - // If adding a repeat, override the Content module's handling of the multiple values option. - if (module_exists('date_repeat') && date_is_repeat_field($field, $instance)) { - $form['field']['cardinality'] = array('#type' => 'hidden', '#value' => FIELD_CARDINALITY_UNLIMITED); - } - } -} - -/** - * Implements hook_field_widget_error(). - */ -function date_field_widget_error($element, $error, $form, &$form_state) { - form_error($element[$error['error']], $error['message']); -} - -/** - * Retrieve a date format string from formatter settings. - */ -function date_formatter_format($formatter, $settings, $granularity = NULL, $langcode = NULL) { - $default = variable_get('date_format_medium', 'D, m/d/Y - H:i'); - $format_type = !empty($settings['format_type']) ? $settings['format_type'] : 'format_interval'; - - switch ($formatter) { - case 'format_interval': - return 'format_interval'; - break; - case 'date_default': - $format = system_date_format_locale($langcode, $format_type); - if (empty($format)) { - $format = variable_get('date_format_'. $format_type, $default); - } - break; - default: - $type = str_replace('date_', '', $formatter); - $format = system_date_format_locale($langcode, $type); - if (empty($format)) { - $format = variable_get('date_format_'. $type, $default); - } - break; - } - - // A selected format might include timezone information. - array_push($granularity, 'timezone'); - return date_limit_format($format, $granularity); -} - -/** - * Implements hook_views_api(). - */ -function date_views_api() { - return array( - 'api' => 2, - 'path' => drupal_get_path('module', 'date'), - ); -} - -/** - * Helper function to adapt entity date fields to formatter settings. - */ -function date_prepare_entity($formatter, $entity_type, $entity, $field, $instance, $langcode, $item, $display) { - - // If there are options to limit multiple values, - // alter the entity values to match. - $field_name = $field['field_name']; - $options = $display['settings']; - $max_count = $options['multiple_number']; - - // If no results should be shown, empty the values and return. - if (is_numeric($max_count) && $max_count == 0) { - $entity->{$field_name} = array(); - return $entity; - } - - // Otherwise removed values that should not be displayed. - if (!empty($options['multiple_from']) || !empty($options['multiple_to']) || !empty($max_count)) { - $format = date_type_format($field['type']); - include_once(drupal_get_path('module', 'date_api') . '/date_api_sql.inc'); - $date_handler = new date_sql_handler($field); - $arg0 = !empty($options['multiple_from']) ? $date_handler->arg_replace($options['multiple_from']) : variable_get('date_min_year', 100) . '-01-01T00:00:00'; - $arg1 = !empty($options['multiple_to']) ? $date_handler->arg_replace($options['multiple_to']) : variable_get('date_max_year', 4000) . '-12-31T23:59:59'; - if (!empty($arg0) && !empty($arg1)) { - $arg = $arg0 . '--' . $arg1; - } - elseif (!empty($arg0)) { - $arg = $arg0; - } - elseif (!empty($arg1)) { - $arg = $arg1; - } - if (!empty($arg)) { - $range = $date_handler->arg_range($arg); - $start = date_format($range[0], $format); - $end = date_format($range[1], $format); - // Empty out values we don't want to see. - $count = 0; - foreach ($entity->{$field_name}[$langcode] as $delta => $value) { - if (!empty($entity->date_repeat_show_all)) { - break; - } - elseif ((!empty($max_count) && is_numeric($max_count) && $count >= $max_count) || - (!empty($value['value']) && $value['value'] < $start) || - (!empty($value['value2']) && $value['value2'] > $end)) { - unset($entity->{$field_name}[$langcode][$delta]); - } - else { - $count++; - } - } - } - } - - return $entity; -} - -/** - * Identify all fields in this view that use the CCK Date handler. - */ -function date_handler_fields($view) { - $field_names = array(); - if (empty($view->date_info->date_fields)) { - $view->date_info->date_fields = array(); - } - foreach ($view->field as $field) { - if ($field->definition['handler'] == 'date_handler_field_multiple') { - $name = $field->field; - $group = $field->options['multiple']; - if (substr($name, -7) == '_value2') { - $field_name = substr($name, 0, strlen($name) - 7); - } - elseif (substr($name, -6) == '_value') { - $field_name = substr($name, 0, strlen($name) - 6); - } - else { - $field_name = ''; - $group = array(); - continue; - } - foreach ($view->date_info->date_fields as $date_field) { - if (strstr($date_field, ' . ' . $field_name)) { - $delta_field = 'entity_data_' . $field_name . '_delta'; - $field_names[$field_name] = array('options' => $group, 'delta_field' => $delta_field, 'view_field' => clone($field)); - // Get rid of the huge view object in the field handler. - unset($field_names[$field_name]['view_field']->view); - } - } - } - } - return $field_names; -} - - -/** - * Generate a DateAPI SQL handler for the given CCK date field. - * - * The handler will be set up to make the correct timezone adjustments - * for the field settings. - * - * @param $field - * - a $field array. - * @param $compare_tz - * - the timezone used for comparison values in the SQL. - */ - function date_field_get_sql_handler($field, $compare_tz = NULL) { - module_load_include('inc', 'date_api', 'date_api_sql'); - - $db_info = date_api_database_info($field); - - // Create a DateAPI SQL handler class for this field type. - $handler = new date_sql_handler(); - $handler->construct($field['type']); - - // If this date field stores a timezone in the DB, tell the handler about it. - if ($field['settings']['tz_handling'] == 'date') { - $handler->db_timezone_field = $db_info['columns']['timezone']['column']; - } - else { - $handler->db_timezone = date_get_timezone_db($field['settings']['tz_handling']); - } - - if (empty($compare_tz)) { - $compare_tz = date_get_timezone($field['settings']['tz_handling']); - } - $handler->local_timezone = $compare_tz; - - // Now that the handler is properly initialized, force the DB - // to use UTC so no timezone conversions get added to things like - // NOW() or FROM_UNIXTIME(). - $handler->set_db_timezone(); - - return $handler; -} - -/** - * Callback to alter the property info of date fields. - * - * @see date_field_info() - */ -function date_entity_metadata_property_info_alter(&$info, $entity_type, $field, $instance, $field_type) { - $name = $field['field_name']; - $property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name]; - if ($field['type'] != 'datestamp' || $field['settings']['timezone_db'] != 'UTC') { - // Add a getter callback to convert the date into the right format. - $property['getter callback'] = 'date_entity_metadata_field_getter'; - unset($property['query callback']); - unset($property['setter callback']); - } - if (!empty($field['settings']['todate'])) { - // Define a simple data structure containing both dates. - $property['type'] = ($field['cardinality'] != 1) ? 'list' . t("The custom value for a Relative default should be something that describes a time by reference to the current day using strtotime, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See !strtotime for more details.", array('!strtotime' => l(t('strtotime'), 'http://www.php.net/manual/en/function.strtotime.php'))) . '
', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => 3, - ); - $form['default']['default_value_code'] = array( - '#type' => 'textfield', '#title' => t('Custom default value'), - '#default_value' => $settings['default_value_code'], - ); - if (!empty($field['settings']['todate'])) { - $form['default']['default_value_code2'] = array( - '#type' => 'textfield', '#title' => t('Custom default value for To date'), - '#default_value' => $settings['default_value_code2'], - ); - } - - $format_types = array(); - foreach (_system_date_format_types_build() as $name => $info) { - $format_types[$name] = $info['title']; - } - - $form['default_format'] = array( - '#type' => 'select', - '#title' => t('Default Display'), - '#default_value' => $settings['default_format'], - '#options' => $format_types, - '#description' => t('Select a default format type to be used for the date display. Visit the Date and time date format page to add and edit format types.', array('@date-time-page' => url('admin/config/regional/date-time/formats'))), - ); - if (module_exists('date_repeat') && date_is_repeat_field($field, $instance)) { - $form['repeat_collapsed'] = array( - '#type' => 'radios', - '#default_value' => $widget_settings['repeat_collapsed'], - '#options' => array(0 => t('Expanded'), 1 => t('Collapsed')), - '#title' => t('Repeat display'), - '#description' => t("Should the repeat options form start out expanded or collapsed? Set to 'Collapsed' to make those options less obtrusive."), - ); - } - return $form; -} - -function date_field_instance_settings_form_validate(&$form, &$form_state) { - $settings = $form_state['values']['instance']['settings']; - if ($settings['default_value'] == 'strtotime') { - $is_strtotime = @strtotime($settings['default_value_code']); - if (!$is_strtotime) { - form_set_error('instance][settings][default_value_code', t('The Strtotime default value is invalid.')); - } - } - if ($settings['default_value2'] == 'strtotime') { - $is_strtotime = @strtotime($settings['default_value_code2']); - if (!$is_strtotime) { - form_set_error('instance][settings][default_value_code2', t('The Strtotime default value for the To Date is invalid.')); - } - } -} - -function _date_field_widget_settings_form($field, $instance) { - $widget = $instance['widget']; - $settings = $widget['settings']; - - $form = array( - '#element_validate' => array('date_field_widget_settings_form_validate'), - ); - - $options = array(); - if ($widget['type'] == 'date_popup' && module_exists('date_popup')) { - $formats = date_popup_formats(); - } - else { - // example input formats must show all possible date parts, so add seconds. - $formats = str_replace('i', 'i:s', array_keys(system_get_date_formats('short'))); - $formats = drupal_map_assoc($formats); - } - $now = date_example_date(); - foreach ($formats as $f) { - $options[$f] = date_format_date($now, 'custom', $f); - } - $form['input_format'] = array( - '#type' => 'select', '#title' => t('Input format'), - '#default_value' => $settings['input_format'], - '#options' => $options, - '#description' => t('Set the order and format for the date parts in the input form. The format will be adapted to remove values not in the granularity for this field.'), - '#weight' => 4, - - ); - - // Only a limited set of formats is available for the Date Popup module - if ($widget['type'] != 'date_popup') { - $form['format'] = array( - '#type' => 'fieldset', - '#title' => t('Customize Input Format'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => 5, - ); - $form['format']['input_format_custom'] = array( - '#type' => 'textfield', - '#title' => t('Custom input format'), - '#default_value' => $settings['input_format_custom'], - '#description' => t("The custom format, if provided, will override the input format selected above. The custom format, if provided, will override the selected display or input options. Define a php date format string like 'm-d-Y H:i' (see http://php.net/date for more details).", array('@link' => 'http://php.net/date')), - ); - } - else { - $form['format']['input_format_custom'] = array( - '#type' => 'hidden', - '#value' => '', - ); - } - if (in_array($widget['type'], array('date_select', 'date_popup', 'date_select_repeat', 'date_popup_repeat'))) { - $form['year_range'] = array( - '#type' => 'textfield', - '#title' => t('Years back and forward'), - '#default_value' => $settings['year_range'], - '#size' => 10, - '#maxsize' => 10, - '#description' => t('Number of years to go back and forward in the year selection list, default is -3:+3.'), - '#weight' => 6, - ); - $form['increment'] = array( - '#type' => 'select', '#title' => t('Time increment'), - '#default_value' => $settings['increment'], - '#options' => array(1 => 1, 5 => 5, 10 => 10, 15 => 15, 30 => 30), - '#description' => t('Increment the minute and second fields by this amount.'), - '#weight' => 7, - ); - } - else { - $form['increment'] = array( - '#type' => 'hidden', - '#value' => $settings['increment'], - ); - $form['year_range'] = array( - '#type' => 'hidden', - '#value' => $settings['year_range'], - ); - } - - $form['label_position'] = array( - '#type' => 'value', - '#value' => $settings['label_position'], - ); - $form['text_parts'] = array( - '#type' => 'value', - '#value' => $settings['text_parts'], - ); - $form['advanced'] = array( - '#type' => 'fieldset', - '#title' => t('Customize Date Parts'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => 8, - ); - $form['advanced']['label_position'] = array( - '#type' => 'radios', - '#options' => array('above' => t('Above'), 'within' => t('Within'), 'none' => t('None')), - '#default_value' => $settings['label_position'], - '#title' => t('Position of date part labels'), - '#description' => t("The location of date part labels, like 'Year', 'Month', or 'Day' . 'Above' will display them as titles above each date part. 'Within' will insert the label as the first option in the select list and in blank textfields. 'None' will not label any of the date parts. The exact text in the label is controlled by themes like 'date_part_label_year' and 'date_part_label_month' ."), - ); - $form['advanced']['text_parts'] = array( - '#theme' => $widget['type'] == 'date_select' ? 'date_text_parts' : '', - ); - $text_parts = (array) $settings['text_parts']; - foreach (date_granularity_names() as $key => $value) { - if ($widget['type'] == 'date_select') { - $form['advanced']['text_parts'][$key] = array( - '#type' => 'radios', - '#default_value' => in_array($key, $text_parts) ? 1 : 0, - '#options' => array(0 => '', 1 => ''), - ); - } - else { - $form['advanced']['text_parts'][$key] = array( - '#type' => 'value', - '#value' => in_array($key, (array) $settings['text_parts']) ? 1 : 0, - ); - } - } - return $form; -} - -function date_field_widget_settings_form_validate(&$form, &$form_state) { - $widget = $form_state['values']['instance']['widget']; - if (isset($widget['settings']['advanced']['label_position'])) { - form_set_value($form['label_position'], $widget['settings']['advanced']['label_position'], $form_state); - } - // Munge the table display for text parts back into an array of text parts. - if (is_array($widget['settings']['advanced']['text_parts'])) { - form_set_value($form['text_parts'], array_keys(array_filter($widget['settings']['advanced']['text_parts'])), $form_state); - } - if (in_array($widget['type'], array('date_select', 'date_popup', 'date_select_repeat', 'date_popup_repeat')) && !date_range_valid($widget['settings']['year_range'])) { - form_set_error('instance][widget][settings][year_range', t('Years back and forward must be in the format -9:+9.')); - } -} - -function _date_field_settings_form($field, $instance, $has_data) { - $settings = $field['settings']; - - $form = array( - '#element_validate' => array('date_field_settings_validate'), - ); - // Make sure granularity is in the right format and has no empty values. - if (!empty($settings['granularity']) && is_array($settings['granularity'])) { - $granularity = array_filter($settings['granularity']); - } - $tz_handling = $settings['tz_handling']; - - // If adding a repeat, override the Content module's handling of the multiple values option. - if (module_exists('date_repeat') && date_is_repeat_field($field, $instance)) { - $form['repeat'] = array('#type' => 'hidden', '#value' => 1); - } - else { - $form['repeat'] = array('#type' => 'hidden', '#value' => 0); - } - - $description = t("Display a matching second date field as a 'To date' . If marked 'Optional' field will be presented but not required. If marked 'Required' the 'To date' will be required if the 'From date' is required or filled in."); - $form['todate'] = array( - '#type' => 'select', - '#title' => t('To Date'), - '#options' => array('' => t('Never'), 'optional' => t('Optional'), 'required' => t('Required')), - '#description' => $description, - '#default_value' => $settings['todate'], - '#disabled' => $has_data, - ); - $description = t('Set the date elements to be stored (at least a year is required).'); - $form['granularity'] = array( - '#type' => 'select', - '#title' => t('Granularity'), - '#default_value' => $granularity, - '#options' => date_granularity_names(), - '#multiple' => TRUE, - '#description' => $description, - '#disabled' => $has_data, - ); - $description = t('Select the timezone handling method to be used for this date field.'); - $form['tz_handling'] = array( - '#type' => 'select', - '#title' => t('Time zone handling'), - '#default_value' => $tz_handling, - '#options' => date_timezone_handling_options(), - '#description' => $description, - '#disabled' => $has_data, - ); - // Force this value to hidden because we don't want to allow it to be changed right now, - // but allow it to be a variable if needed. - $form['timezone_db'] = array( - '#type' => 'hidden', - '#value' => date_get_timezone_db($tz_handling), - ); - - - return $form; -} - -/** - * Custom field settings manipulation. - */ -function date_field_settings_validate(&$form, &$form_state) { - $field = $form_state['values']['field']; - if ($field['settings']['tz_handling'] == 'none') { - form_set_value($form['timezone_db'], '', $form_state); - } - else { - form_set_value($form['timezone_db'], date_get_timezone_db($field['settings']['tz_handling']), $form_state); - } - if (!in_array('year', $field['settings']['granularity'])) { - form_set_error('field][settings][granularity', t('Granularity must include a year.')); - } - if ($field['settings']['tz_handling'] != 'none' && !in_array('hour', array_filter($field['settings']['granularity']))) { - form_set_error('field][settings][tz_handling', t('Dates without hours granularity must not use any timezone handling.')); - } -} - -/** - * Timezone handling options - * - * the 'none' option will do no timezone conversions and will store and display dates exactly as entered - * useful in locales or situations where timezone conversions are not working reliably, - * for dates with no times, for historical dates where timezones are irrelevant, - * or anytime conversion is unnecessary or undesirable - */ -function date_timezone_handling_options() { - return array( - 'site' => t("Site's time zone"), - 'date' => t("Date's time zone"), - 'user' => t("User's time zone"), - 'utc' => 'UTC', - 'none' => t('No time zone conversion'), - ); -} - -/** - * Get an example date and make sure the difference between - * month and day and 12 and 24 hours will be clear. - */ -function date_example_date() { - $now = date_now(); - if (date_format($now, 'm') == date_format($now, 'd')) { - date_modify($now, '+1 day'); - } - if (date_format($now, 'H') == date_format($now, 'h')) { - date_modify($now, '+12 hours'); - } - return $now; -} - diff --git a/date/date_elements.inc b/date/date_elements.inc deleted file mode 100644 index 181622132bd92341c156f6ddd5004cd2eb2ed87d..0000000000000000000000000000000000000000 --- a/date/date_elements.inc +++ /dev/null @@ -1,522 +0,0 @@ - 'timezone' => value)). After struggling - // with this a while, I can find no way to get it displayed in the form - // correctly and get it to use the timezone element without ending up - // with nesting. - if (is_array($timezone)) { - $timezone = $timezone['timezone']; - } - - // Convert UTC dates to their local values in DATETIME format, - // and adjust the default values as specified in the field settings. - - // It would seem to make sense to do this conversion when the data - // is loaded instead of when the form is created, but the loaded - // field data is cached and we can't cache dates that have been converted - // to the timezone of an individual user, so we cache the UTC values - // instead and do our conversion to local dates in the form and - // in the formatters. - $process = date_process_values($field, $instance); - foreach ($process as $processed) { - if (!isset($items[$delta][$processed])) { - $items[$delta][$processed] = ''; - } - $date = date_local_date($form, $form_state, $delta, $items[$delta], $timezone, $field, $instance, $processed); - $items[$delta][$processed] = is_object($date) ? date_format($date, DATE_FORMAT_DATETIME) : ''; - } - - $element += array( - '#type' => 'date_combo', - '#theme_wrappers' => array('date_combo'), - '#weight' => $delta, - '#default_value' => isset($items[$delta]) ? $items[$delta] : '', - '#date_timezone' => $timezone, - '#element_validate' => array('date_combo_validate', 'date_widget_validate'), - ); - - if ($field['settings']['tz_handling'] == 'date') { - $element['timezone'] = array( - '#type' => 'date_timezone', - '#delta' => $delta, - '#default_value' => $timezone, - '#weight' => $instance['widget']['weight'] + .2, - ); - } - - // Add a date repeat form element, if needed. - if (module_exists('date_repeat') && $field['settings']['repeat'] == 1) { - module_load_include('inc', 'date', 'date_repeat'); - _date_repeat_widget($element, $field, $instance, $items, $delta); - $element['rrule']['#weight'] = $instance['widget']['weight'] + .4; - } - - return $element; -} - -function date_combo_value_callback($element, $input = FALSE, &$form_state) { - if (!$input) { - return array(); - } -} - -/** - * Create local date object. - * - * Create a date object set to local time from the field and - * widget settings and item values, using field settings to - * determine what to do with empty values. - */ -function date_local_date($form, $form_state, $delta, $item, $timezone, $field, $instance, $part = 'value') { - if (!empty($form['nid']['#value'])) { - $default_value = ''; - $default_value_code = ''; - } - elseif ($part == 'value') { - $default_value = $instance['settings']['default_value']; - $default_value_code = $instance['settings']['default_value_code']; - } - else { - $default_value = $instance['settings']['default_value2']; - $default_value_code = $instance['settings']['default_value_code2']; - } - if (empty($item) || empty($item[$part])) { - if (empty($default_value) || $default_value == 'blank' || $delta > 0) { - return NULL; - } - elseif ($part == 'value2' && $default_value == 'same') { - if ($instance['settings']['default_value'] == 'blank' || empty($item['value'])) { - return NULL; - } - else { - $date = new DateObject($item['value'], $timezone, DATE_FORMAT_DATETIME); - $date->limitGranularity($field['settings']['granularity']); - } - } - // Special case for 'now' when using dates with no timezone, - // make sure 'now' isn't adjusted to UTC value of 'now' . - elseif ($field['settings']['tz_handling'] == 'none') { - $date = date_now(); - } - else { - $date = date_now($timezone); - } - } - else { - $value = $item[$part]; - - // @TODO Figure out how to replace date_fuzzy_datetime() function. - // Special case for ISO dates to create a valid date object for formatting. - // Is this still needed? - /* - if ($field['type'] == DATE_ISO) { - $value = date_fuzzy_datetime($value); - } - else { - $db_timezone = date_get_timezone_db($field['settings']['tz_handling']); - $value = date_convert($value, $field['type'], DATE_DATETIME, $db_timezone); - } - */ - - $date = new DateObject($value, date_get_timezone_db($field['settings']['tz_handling'])); - $date->limitGranularity($field['settings']['granularity']); - if (empty($date)) { - return NULL; - } - date_timezone_set($date, timezone_open($timezone)); - } - if (is_object($date) && empty($item[$part]) && $default_value == 'strtotime' && !empty($default_value_code)) { - date_modify($date, $default_value_code); - } - return $date; -} - -/** - * Process an individual date element. - */ -function date_combo_element_process($element, &$form_state, $form) { - if (isset($element['#access']) && empty($element['#access'])) { - return; - } - - $field_name = $element['#field_name']; - $delta = $element['#delta']; - $bundle = $element['#bundle']; - $entity_type = $element['#entity_type']; - $field = field_widget_field($element, $form_state); - $instance = field_widget_instance($element, $form_state); - - $columns = $element['#columns']; - if (isset($columns['rrule'])) { - unset($columns['rrule']); - } - $from_field = 'value'; - $to_field = 'value2'; - $tz_field = 'timezone'; - $offset_field = 'offset'; - $offset_field2 = 'offset2'; - - if ($field['settings']['todate'] != 'required' - && !empty($element['#default_value'][$to_field]) - && $element['#default_value'][$to_field] == $element['#default_value'][$from_field]) { - unset($element['#default_value'][$to_field]); - } - - $element[$from_field] = array( - '#field' => $field, - '#title' => t($instance['label']), - '#weight' => $instance['widget']['weight'], - '#required' => ($instance['required'] && $delta == 0) ? 1 : 0, - '#default_value' => isset($element['#default_value'][$from_field]) ? $element['#default_value'][$from_field] : '', - '#field' => $field, - '#delta' => $delta, - '#date_timezone' => $element['#date_timezone'], - '#date_format' => date_limit_format(date_input_format($element, $field, $instance), $field['settings']['granularity']), - '#date_text_parts' => (array) $instance['widget']['settings']['text_parts'], - '#date_increment' => $instance['widget']['settings']['increment'], - '#date_year_range' => $instance['widget']['settings']['year_range'], - '#date_label_position' => $instance['widget']['settings']['label_position'], - ); - - $description = !empty($instance['description']) ? t($instance['description']) : ''; - - // Give this element the right type, using a Date API - // or a Date Popup element type. - - switch ($instance['widget']['type']) { - case 'date_select': - case 'date_select_repeat': - // From/to selectors with lots of parts will look better if displayed - // on two rows instead of in a single row. - if (!empty($field['settings']['todate']) && count($field['settings']['granularity']) > 3) { - $element[$from_field]['#attributes'] = array('class' => array('date-clear')); - } - $element[$from_field]['#type'] = 'date_select'; - $element[$from_field]['#theme_wrappers'] = array('date_select'); - break; - case 'date_popup': - case 'date_popup_repeat': - $element[$from_field]['#type'] = 'date_popup'; - $element[$from_field]['#theme_wrappers'] = array('date_popup'); - break; - default: - $element[$from_field]['#type'] = 'date_text'; - $element[$from_field]['#theme_wrappers'] = array('date_text'); - break; - } - - // If this field uses the 'To', add matching element - // for the 'To' date, and adapt titles to make it clear which - // is the 'From' and which is the 'To' . - - if (!empty($field['settings']['todate'])) { - $element['#date_float'] = TRUE; - $element[$from_field]['#title'] = t('From date'); - $element[$to_field] = $element[$from_field]; - $element[$to_field]['#title'] = t('To date'); - $element[$to_field]['#default_value'] = isset($element['#default_value'][$to_field]) ? $element['#default_value'][$to_field] : ''; - $element[$to_field]['#required'] = FALSE; - $element[$to_field]['#weight'] += .1; - if ($instance['widget']['type'] == 'date_select') { - $description .= ' ' . t("Empty 'To date' values will use the 'From date' values."); - } - $element['#fieldset_description'] = $description; - } - else { - $element[$from_field]['#description'] = $description; - } - - // Create label for error messages that make sense in multiple values - // and when the title field is left blank. - if (!empty($field['cardinality']) && empty($field['settings']['repeat'])) { - $element[$from_field]['#date_title'] = t('@field_name From date value #@delta', array('@field_name' => $instance['label'], '@delta' => $delta + 1)); - if (!empty($field['settings']['todate'])) { - $element[$to_field]['#date_title'] = t('@field_name To date value #@delta', array('@field_name' => $instance['label'], '@delta' => $delta + 1)); - } - } - elseif (!empty($field['settings']['todate'])) { - $element[$from_field]['#date_title'] = t('@field_name From date', array('@field_name' => $instance['label'])); - $element[$to_field]['#date_title'] = t('@field_name To date', array('@field_name' => $instance['label'])); - } - else { - $element[$from_field]['#date_title'] = $instance['label']; - } - - // Make sure field info will be available to the validator which - // does not get the values in $form. - $form_state['#field_info'][$field['field_name']] = $field; - - return $element; -} - -function date_element_empty($element, &$form_state) { - $item = array(); - $item['value'] = NULL; - $item['value2'] = NULL; - $item['timezone'] = NULL; - $item['offset'] = NULL; - $item['offset2'] = NULL; - $item['rrule'] = NULL; - form_set_value($element, $item, $form_state); - return $item; -} - -/** - * Validate and update a combo element. - * Don't try this if there were errors before reaching this point. - */ -function date_combo_validate($element, &$form_state) { - - $form_values = $form_state['values']; - $field_name = $element['#field_name']; - $delta = $element['#delta']; - $langcode = $element['#language']; - - // If the whole field is empty and that's OK, stop now. - if (empty($form_state['input'][$field_name]) && !$element['#required']) { - return; - } - - // Repeating dates have a different form structure, so get the - // right item values. - $item = isset($form_values[$field_name][$langcode]['rrule']) ? $form_values[$field_name][$langcode] : $form_values[$field_name][$langcode][$delta]; - $posted = isset($form_values[$field_name][$langcode]['rrule']) ? $form_state['input'][$field_name][$langcode] : $form_state['input'][$field_name][$langcode][$delta]; - - $field = field_widget_field($element, $form_state); - $instance = field_widget_instance($element, $form_state); - - $from_field = 'value'; - $to_field = 'value2'; - $tz_field = 'timezone'; - $offset_field = 'offset'; - $offset_field2 = 'offset2'; - - // Unfortunately, due to the fact that much of the processing is already - // done by the time we get here, it is not possible highlight the field - // with an error, we just try to explain which element is creating the - // problem in the error message. - $parent = $element['#parents']; - $error_field = array_pop($parent); - $errors = array(); - - // Check for empty 'From date', which could either be an empty - // value or an array of empty values, depending on the widget. - $empty = TRUE; - if (!empty($item[$from_field])) { - if (!is_array($item[$from_field])) { - $empty = FALSE; - } - else { - foreach ($item[$from_field] as $key => $value) { - if (!empty($value)) { - $empty = FALSE; - break; - } - } - } - } - - // A 'To' date without a 'From' date is a validation error. - if ($empty && !empty($item[$to_field])) { - if (!is_array($item[$to_field])) { - form_set_error($error_field, t("A 'From date' date is required if a 'To date' is supplied for field %field #%delta.", array('%delta' => $field['cardinality'] ? intval($delta + 1) : '', '%field' => t($instance['label'])))); - $empty = FALSE; - } - else { - foreach ($item[$to_field] as $key => $value) { - if (!empty($value)) { - form_set_error($error_field, t("A 'From date' date is required if a 'To date' is supplied for field %field #%delta.", array('%delta' => $field['cardinality'] ? intval($delta + 1) : '', '%field' => t($instance['label'])))); - $empty = FALSE; - break; - } - } - } - } - - if ($empty) { - $item = date_element_empty($element, $form_state); - if (!$element['#required']) { - return; - } - } - // Don't look for further errors if errors are already flagged - // because otherwise we'll show errors on the nested elements - // more than once. - elseif (!form_get_errors()) { - - // Check todate input for blank values and substitute in fromdate - // values where needed, then re-compute the todate with those values. - if ($field['settings']['todate']) { - $merged_date = array(); - $to_date_empty = TRUE; - foreach ($posted[$to_field] as $part => $value) { - $to_date_empty = $to_date_empty && empty($value) && !is_numeric($value); - $merged_date[$part] = empty($value) && !is_numeric($value) ? $posted[$from_field][$part] : $value; - if ($part == 'ampm' && $merged_date['ampm'] == 'pm' && $merged_date['hour'] < 12) { - $merged_date['hour'] += 12; - } - elseif ($part == 'ampm' && $merged_date['ampm'] == 'am' && $merged_date['hour'] == 12) { - $merged_date['hour'] -= 12; - } - } - - // If all date values were empty and a date is required, throw - // an error on the first element. We don't want to create - // duplicate messages on every date part, so the error will - // only go on the first. - if ($to_date_empty && $field['settings']['todate'] == 'required') { - $errors[] = t('Some value must be entered in the To date.'); - } - - $element[$to_field]['#value'] = $merged_date; - - // Call the right function to turn this altered user input into - // a new value for the todate. - $item[$to_field] = $merged_date; - } - else { - $item[$to_field] = $item[$from_field]; - } - - $from_date = date_input_date($field, $instance, $element[$from_field], $posted[$from_field]); - - if (!empty($field['settings']['todate'])) { - $to_date = date_input_date($field, $instance, $element[$to_field], $merged_date); - } - else { - $to_date = $from_date; - } - - - // Neither the from date nor the to date should be empty at this point - // unless they held values that couldn't be evaluated. - if (!$instance['required'] && (empty($from_date) || empty($to_date))) { - $item = date_element_empty($element, $form_state); - $errors[] = t('The dates are invalid.'); - } - elseif (!empty($field['settings']['todate']) && $from_date > $to_date) { - form_set_value($element[$to_field], $to_date, $form_state); - $errors[] = t('The To date must be greater than the From date.'); - } - else { - // Convert input dates back to their UTC values and re-format to ISO - // or UNIX instead of the DATETIME format used in element processing. - $timezone = !empty($item[$tz_field]) ? $item[$tz_field] : $element['#date_timezone']; - $timezone_db = date_get_timezone_db($field['settings']['tz_handling']); - $item[$tz_field] = $timezone; - - $item[$offset_field] = date_offset_get($from_date); - - $test_from = date_format($from_date, 'r'); - $test_to = date_format($to_date, 'r'); - - $item[$offset_field2] = date_offset_get($to_date); - date_timezone_set($from_date, timezone_open($timezone_db)); - date_timezone_set($to_date, timezone_open($timezone_db)); - $item[$from_field] = date_format($from_date, date_type_format($field['type'])); - $item[$to_field] = date_format($to_date, date_type_format($field['type'])); - if (isset($form_values[$field_name]['rrule'])) { - $item['rrule'] = $form_values[$field['field_name']]['rrule']; - } - - // Test a roundtrip back to the original timezone to catch - // invalid dates, like 2AM on the day that spring daylight savings - // time begins in the US. - date_timezone_set($from_date, timezone_open($timezone)); - date_timezone_set($to_date, timezone_open($timezone)); - if ($test_from != date_format($from_date, 'r')) { - $errors[] = t('The From date is invalid.'); - } - if ($test_to != date_format($to_date, 'r')) { - $errors[] = t('The To date is invalid.'); - } - if (empty($errors)) { - form_set_value($element, $item, $form_state); - } - } - } - if (!empty($errors)) { - if ($field['cardinality']) { - form_set_error($error_field, t('There are errors in @field_name value #@delta:', array('@field_name' => $instance['label'], '@delta' => $delta + 1)) . theme('item_list', array('items' => $errors))); - } - else { - form_set_error($error_field, t('There are errors in @field_name:', array('@field_name' => $instance['label'])) . theme('item_list', array('items' => $errors))); - } - } -} - -/** - * Handle widget processing. - */ -function date_widget_validate($element, &$form_state) { - $field = field_widget_field($element, $form_state); - if (module_exists('date_repeat') && $field['settings']['repeat']) { - module_load_include('inc', 'date', 'date_repeat'); - return _date_repeat_widget_validate($element, $form_state); - } -} - -/** - * Determine the input format for this element. - */ -function date_input_format($element, $field, $instance) { - if (!empty($instance['widget']['settings']['input_format_custom'])) { - return $instance['widget']['settings']['input_format_custom']; - } - elseif (!empty($instance['widget']['settings']['input_format']) && $instance['widget']['settings']['input_format'] != 'site-wide') { - return $instance['widget']['settings']['input_format']; - } - return variable_get('date_format_short', 'm/d/Y - H:i'); -} \ No newline at end of file diff --git a/date/date_handler_field_multiple.inc b/date/date_handler_field_multiple.inc deleted file mode 100644 index 08e4c03adfbf99125ab5b616d774944052fec102..0000000000000000000000000000000000000000 --- a/date/date_handler_field_multiple.inc +++ /dev/null @@ -1,177 +0,0 @@ - array( - 'show_repeat_rule' => array('default' => ''), - ) - ); - $options['multiple'] = array( - 'contains' => array( - 'multiple_to' => array('default' => ''), - ) - ); - $options['fromto'] = array( - 'contains' => array( - 'fromto' => array('default' => 'both'), - ) - ); - - return $options; - } - - /** - * Provide 'group multiple values' option, - * adapted to the needs of the Date module. - */ - function options_form(&$form, &$form_state) { - parent::options_form($form, $form_state); - unset($form['multiple']); - - $field_name = $this->content_field_name; - $field = field_info_field($field_name); - $options = $this->options; - - //$form += date_formatter_settings($form_state, $field, $options, TRUE); - $form['multiple']['#weight'] = 1; - $form['multiple']['group'] = array( - '#title' => t('Group multiple values'), - '#type' => 'checkbox', - '#default_value' => $options['multiple']['group'], - '#description' => t('If unchecked, each item in the field will create a new row, which may appear to cause duplicates. This setting is not compatible with click-sorting in table displays.'), - ); - } - - function pre_render($values) { - - // If there are no values to render (displaying a summary, or query returned no results), - // or if this is not a grouped field, do nothing specific. - if (isset($this->view->build_info['summary']) || empty($values) || !$this->defer_query) { - return parent::pre_render($values); - } - - $field_name = $this->content_field_name; - $field = field_info_field($field_name); - $db_info = date_api_database_info($field); - $options = $this->options; - $this->view->date_info->date_handler_fields = date_handler_fields($this->view); - - // Build the list of vids to retrieve. - // TODO: try fetching from cache_content first ?? - $vids = array(); - $this->field_values = array(); - foreach ($values as $result) { - if (isset($result->{$this->field_alias})) { - $vids[] = $result->{$this->field_alias}; - } - } - - // List columns to retrieve. - $alias = content_views_tablename($field); - // Prefix aliases with '_' to avoid clashing with field columns names. - $query_columns = array( - 'node.vid AS _vid', - "$alias.delta as _delta", - // nid is needed to generate the links for 'link to node' option. - 'node.nid AS _nid', - ); - // The actual field columns. - foreach ($db_info['columns'] as $column => $attributes) { - $query_columns[] = "$alias.$attributes[column] AS $column"; - $query_fields[] = "$alias.$attributes[column]"; - } - // Retrieve all values, we limit them in date_prepare_node(), - // a function that is used both by the handler and by the - // node theme to take advantage of formatter settings. - $where = array('1'); - $query = 'SELECT ' . implode(', ', $query_columns) . - ' FROM {' . $db_info['table'] . "} $alias" . - " LEFT JOIN {node} node ON node.vid = $alias.vid" . - " WHERE node.vid IN (" . implode(',', $vids) . ') AND ' . implode(' OR ', $where) . - " ORDER BY node.nid ASC, $alias.delta ASC"; - $result = db_query($query); - - while ($item = db_fetch_array($result)) { - // Clean up the $item from vid and delta. We keep nid for now. - $vid = $item['_vid']; - unset($item['_vid']); - $delta = !empty($item['_delta']) ? $item['_delta'] : 0; - $item['#delta'] = $item['_delta']; - unset($item['_delta']); - $this->field_values[$vid][$delta] = $item; - } - } - - function render($values) { - - // By this time $values is a pseudo node that will be passed - // to the theme. Add view information to it. - $values->date_info = !empty($this->view->date_info) ? $this->view->date_info : new stdClass(); - $values->date_info->date_handler_fields = date_handler_fields($this->view); - - // Add the formatter settings to the pseudo node. - $values->date_info->formatter_settings = $this->options; - $values->date_info->aliases = $this->aliases; - - // If this is not a grouped field, use content_handler_field::render(). - if (!$this->defer_query) { - return parent::render($values); - } - - $field_name = $this->content_field_name; - $field = field_info_field($field_name); - $options = $this->options; - - $vid = $values->{$this->field_alias}; - if (isset($this->field_values[$vid])) { - // Build a pseudo-node from the retrieved values. - $node = clone($values); - // content_format and formatters will need a 'type' . - $node->type = $values->{$this->aliases['type']}; - $node->nid = $values->{$this->aliases['nid']}; - $node->vid = $values->{$this->aliases['vid']}; - $items = $this->field_values[$vid]; - $node->$field_name = $items; - - // Some formatters need to behave differently depending on the build_mode - // (for instance: preview), so we provide one. - // TODO This has changed in D7. - $node->build_mode = NODE_BUILD_NORMAL; - - // Render items. - $formatter_name = $options['format']; - if ($items && ($formatter = _content_get_formatter($formatter_name, $field['type']))) { - $rendered = array(); - - // Multiple values formatter. - $output = content_format($field, $items, $formatter_name, $values); - if (!empty($output)) { - $rendered[] = $this->render_link($output, (object) array('nid' => $this->aliases['nid'])); - } - } - - if (count($rendered) > 1) { - // TODO: could we use generic field display ? - return theme('field_view_multiple_field', $rendered, $field, $values); - } - elseif ($rendered) { - return $rendered[0]; - } - } - - return ''; - - } - -} \ No newline at end of file diff --git a/date/date_repeat.inc b/date/date_repeat.inc deleted file mode 100644 index 5a526b1c890637387ee6aeade0a3b83017029eff..0000000000000000000000000000000000000000 --- a/date/date_repeat.inc +++ /dev/null @@ -1,204 +0,0 @@ - 'date_repeat_rrule', - '#theme_wrappers' => array('date_repeat_rrule'), - '#default_value' => isset($items[0]['rrule']) ? $items[0]['rrule'] : '', - '#date_timezone' => $element['#date_timezone'], - '#date_format' => date_limit_format(date_input_format($element, $field, $instance), $field['settings']['granularity']), - '#date_text_parts' => (array) $instance['widget']['settings']['text_parts'], - '#date_increment' => $instance['widget']['settings']['increment'], - '#date_year_range' => $instance['widget']['settings']['year_range'], - '#date_label_position' => $instance['widget']['settings']['label_position'], - '#prev_value' => isset($items[0]['value']) ? $items[0]['value'] : '', - '#prev_value2' => isset($items[0]['value2']) ? $items[0]['value2'] : '', - '#prev_rrule' => isset($items[0]['rrule']) ? $items[0]['rrule'] : '', - '#date_repeat_widget' => str_replace('_repeat', '', $instance['widget']['type']), - '#date_repeat_collapsed' => $instance['settings']['repeat_collapsed'], - ); - return $element; -} -/** - * Validation for date repeat form element. - * - * Create multiple values from the RRULE results. - * Lots more work needed here. - */ -function _date_repeat_widget_validate($element, &$form_state) { - module_load_include('inc', 'date_repeat', 'date_repeat_form'); - $field_name = $element['#field_name']; - $field = field_widget_field($element, $form_state); - $instance = field_widget_instance($element, $form_state); - - $form_values = $form_state['values']; - $item = $form_values; - $input = $form_state['input']; - foreach ($element['#parents'] as $key) { - $item = $item[$key]; - $input = $input[$key]; - } - $rrule_values = date_repeat_merge($input['rrule'], $element['rrule']); - - // If no start date was set, clean up the form and return. - // If no repeats are set, clean up the form and return. - if (empty($item['value']) || $rrule_values['FREQ'] == 'NONE') { - $item['rrule'] = NULL; - form_set_value($element, array($item), $form_state); - return; - } - - // Require the UNTIL date for now. - // The RRULE has already been created by this point, so go back - // to the posted values to see if this was filled out. - $error_field = implode('][', $element['#parents']) . '][rrule][UNTIL][datetime][date'; - if (empty($rrule_values['UNTIL']['datetime'])) { - form_set_error($error_field, t('The UNTIL value is required for repeating dates.')); - } - if (form_get_errors()) { - return; - } - - // If the rule, the start date, or the end date have changed, re-calculate - // the repeating dates, wipe out the previous values, and populate the - // field with the new values. - - // TODO - // Is it right to not do anything unless there are changes? Will that - // confuse anyone? Commenting that out for now... - $rrule = $item['rrule']; - - if (!empty($rrule) - //&& ($rrule != $element['rrule']['#prev_rrule'] - //|| $item['value'] != $element['rrule']['#prev_value'] - //|| $item['value2'] != $element['rrule']['#prev_value2']) - ) { - - // Avoid undefined index problems on dates that don't have all parts. - $possible_items = array('value', 'value2', 'timezone', 'offset', 'offset2'); - foreach ($possible_items as $key) { - if (empty($item[$key])) { - $item[$key] = ''; - } - } - $value = date_repeat_build_dates($rrule, $rrule_values, $field, $item); - form_set_value($element, $value, $form_state); - } - else { - // If no changes are needed, move the RRULE back to the zero value - // item of the field. - form_set_value(array('#parents' => array($field_name, $element['#language'], 0, 'rrule')), $rrule, $form_state); - form_set_value($element, NULL, $form_state); - } -} - -/** - * Helper function to build repeating dates from a $node_field. - * - * Pass in either the RRULE or the $form_values array for the RRULE, - * whichever is missing will be created when needed. - */ -function date_repeat_build_dates($rrule = NULL, $rrule_values = NULL, $field, $item) { - include_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'date_api') . '/date_api_ical.inc'); - $field_name = $field['field_name']; - - if (empty($rrule)) { - $rrule = date_api_ical_build_rrule($rrule_values); - } - elseif (empty($rrule_values)) { - $rrule_values = date_ical_parse($rrule); - } - - // By the time we get here, the start and end dates have been - // adjusted back to UTC, but we want localtime dates to do - // things like '+1 Tuesday', so adjust back to localtime. - $timezone = date_get_timezone($field['settings']['tz_handling'], $item['timezone']); - $timezone_db = date_get_timezone_db($field['settings']['tz_handling']); - $start = new DateObject($item['value'], $timezone_db, date_type_format($field['type'])); - $start->limitGranularity($field['settings']['granularity']); - if ($timezone != $timezone_db) { - date_timezone_set($start, timezone_open($timezone)); - } - if (!empty($item['value2']) && $item['value2'] != $item['value']) { - $end = new DateObject($item['value2'], date_get_timezone_db($field['settings']['tz_handling']), date_type_format($field['type'])); - $end->limitGranularity($field['settings']['granularity']); - date_timezone_set($end, timezone_open($timezone)); - } - else { - $end = $start; - } - $duration = $start->difference($end); - $start_datetime = date_format($start, DATE_FORMAT_DATETIME); - - if (!empty($rrule_values['UNTIL']['datetime'])) { - $end = date_ical_date($rrule_values['UNTIL'], $timezone); - } - $end_datetime = date_format($end, DATE_FORMAT_DATETIME); - - // Split the RRULE into RRULE, EXDATE, and RDATE parts. - $parts = date_repeat_split_rrule($rrule); - $parsed_exceptions = (array) $parts[1]; - $exceptions = array(); - foreach ($parsed_exceptions as $exception) { - $date = date_ical_date($exception); - $exceptions[] = date_format($date, 'Y-m-d'); - } - - $parsed_rdates = (array) $parts[2]; - $additions = array(); - foreach ($parsed_rdates as $rdate) { - $additions[] = date_ical_date($rdate); - } - - $dates = date_repeat_calc($rrule, $start_datetime, $end_datetime, $exceptions, $timezone, $additions); - - - $value = array(); - foreach ($dates as $delta => $date) { - // date_repeat_calc always returns DATE_DATETIME dates, which is - // not necessarily $field['type'] dates. - // Convert returned dates back to db timezone before storing. - $date_start = new DateObject($date, $timezone, DATE_FORMAT_DATETIME); - $date_start->limitGranularity($field['settings']['granularity']); - date_timezone_set($date_start, timezone_open($timezone_db)); - $date_end = clone($date_start); - date_modify($date_end, '+' . $duration . ' seconds'); - $value[$delta] = array( - 'value' => date_format($date_start, date_type_format($field['type'])), - 'value2' => date_format($date_end, date_type_format($field['type'])), - 'offset' => date_offset_get($date_start), - 'offset2' => date_offset_get($date_end), - 'timezone' => $timezone, - 'rrule' => $rrule, - ); - } - return $value; -} \ No newline at end of file diff --git a/date/date_token.inc b/date/date_token.inc deleted file mode 100644 index c51b3cfa8a08191f66bfc11504e66d4d77e018b8..0000000000000000000000000000000000000000 --- a/date/date_token.inc +++ /dev/null @@ -1,98 +0,0 @@ - -# Generated from files: -# date_admin.inc,v 1.40.2.3.2.13 2008/08/24 06:39:38 karens -# date.module,v 1.61.2.4.2.19 2008/09/04 14:55:31 karens -# date_elements.inc,v 1.46.2.2.2.22 2008/08/30 13:57:39 karens -# date_repeat.inc,v 1.22.2.1.2.10 2008/08/19 13:39:23 karens -# date_token.inc,v 1.2.2.1.2.2 2008/09/01 12:05:12 karens -# date.theme,v 1.6.4.20 2008/09/03 14:20:26 karens -# date.install,v 1.37.2.5.2.13 2008/09/06 10:29:04 karens -# date.info,v 1.3 2008/02/18 19:32:28 karens -# -msgid "" -msgstr "" -"Project-Id-Version: \n" -"POT-Creation-Date: 2009-03-07 19:12+0100\n" -"PO-Revision-Date: 2009-03-07 19:38+0100\n" -"Last-Translator: Alexander Haß\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=2; plural=(n != 1)\n" -"X-Poedit-Language: German\n" -"X-Poedit-Country: GERMANY\n" - -#: date/date_admin.inc:25 -msgid "The Strtotime default value is invalid." -msgstr "Der standardmäßige Wert für „Strtotime“ ist ungültig." - -#: date/date_admin.inc:31 -msgid "The Strtotime default value for the To Date is invalid." -msgstr "Der standardmäßige Wert für das „Bis“-Datum ist ungültig." - -#: date/date_admin.inc:35 -msgid "Years back and forward must be in the format -9:+9." -msgstr "Die Jahre rückwärts und vorwärts müssen dem Format -9:+9 entsprechen." - -#: date/date_admin.inc:70 -msgid "Default value" -msgstr "Standardwert" - -#: date/date_admin.inc:72;78 -msgid "Blank" -msgstr "Leer" - -#: date/date_admin.inc:72;78 -msgid "Relative" -msgstr "Relativ" - -#: date/date_admin.inc:73;79 -#, fuzzy -msgid "A default value to use for this field. If you select 'Relative', add details below." -msgstr "Der standardmäßig zu verwendende Wert für dieses Feld. If you select 'Relative', add details below." - -#: date/date_admin.inc:76 -msgid "Default value for To date" -msgstr "Standardwert für „Bis“-Datum" - -#: date/date_admin.inc:78 -msgid "Same as From date" -msgstr "Dasselbe wie „Von“-Datum" - -#: date/date_admin.inc:83 -msgid "Customize Default Value" -msgstr "Standardmäßigen Wert anpassen" - -#: date/date_admin.inc:84 -msgid "The custom value for a Relative default should be something that describes a time by reference to the current day using strtotime, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See !strtotime for more details." -msgstr "" - -#: date/date_admin.inc:84 -msgid "strtotime" -msgstr "strtotime" - -#: date/date_admin.inc:89 -msgid "Custom value for From date" -msgstr "Benutzerdefinierter Wert für „Von“-Datum" - -#: date/date_admin.inc:94 -msgid "Custom value for To date" -msgstr "Benutzerdefinierter Wert für das „Bis“-Datum" - -#: date/date_admin.inc:114 -msgid "Input format" -msgstr "Eingabeformat" - -#: date/date_admin.inc:117 -msgid "Set the order and format for the date parts in the input form. The format will be adapted to remove values not in the granularity for this field." -msgstr "" - -#: date/date_admin.inc:123 -msgid "Custom input format" -msgstr "Benutzerdefiniertes Eingabeformat" - -#: date/date_admin.inc:125 -msgid "The custom format, if provided, will override the input format selected above. The custom format, if provided, will override the selected display or input options. Define a php date format string like 'm-d-Y H:i' (see http://php.net/date for more details)." -msgstr "" - -#: date/date_admin.inc:137 -msgid "Years back and forward" -msgstr "Jahre rückwärts und vorwärts" - -#: date/date_admin.inc:141 -msgid "Number of years to go back and forward in the year selection list, default is -3:+3." -msgstr "" - -#: date/date_admin.inc:144 -#, fuzzy -msgid "Time increment" -msgstr "Zeiterhöhung" - -# Erhöhung oder Schrittweite -#: date/date_admin.inc:147 -#, fuzzy -msgid "Increment the minute and second fields by this amount." -msgstr "Die Minuten- und Sekundenfelder um diesen Betrag erhöhen." - -#: date/date_admin.inc:172 -msgid "Customize Date Parts" -msgstr "Datumsbestandteile anpassen" - -#: date/date_admin.inc:178 -msgid "Above" -msgstr "Oberhalb" - -#: date/date_admin.inc:178 -msgid "Within" -msgstr "Innerhalb" - -#: date/date_admin.inc:178 -msgid "None" -msgstr "Keine" - -#: date/date_admin.inc:180 -msgid "Position of date part labels" -msgstr "Position der Beschriftungen von Datumsbestandteilen" - -#: date/date_admin.inc:181 -msgid "The location of date part labels, like 'Year', 'Month', or 'Day'. 'Above' will display them as titles above each date part. 'Within' will insert the label as the first option in the select list and in blank textfields. 'None' will not label any of the date parts. The exact text in the label is controlled by themes like 'date_part_label_year' and 'date_part_label_month'." -msgstr "" - -#: date/date_admin.inc:224 -msgid "Input Type" -msgstr "Eingabetyp" - -#: date/date_admin.inc:224 -msgid "Select list" -msgstr "Auswahlliste" - -#: date/date_admin.inc:224 -msgid "Text field" -msgstr "Textfeld" - -#: date/date_admin.inc:239 -msgid "Granularity must include a year." -msgstr "Die Granularität muss ein Jahr enthalten." - -#: date/date_admin.inc:242 -msgid "Dates without hours granularity must not use any timezone handling." -msgstr "" - -#: date/date_admin.inc:347 -msgid "Display a matching second date field as a 'To date'. If marked 'Optional' field will be presented but not required. If marked 'Required' the 'To date' will be required if the 'From date' is required or filled in." -msgstr "" - -#: date/date_admin.inc:350 -msgid "To Date" -msgstr "„Bis“-Datum" - -#: date/date_admin.inc:351 -msgid "Never" -msgstr "Nie" - -#: date/date_admin.inc:351 -msgid "Optional" -msgstr "Optional" - -#: date/date_admin.inc:351 -msgid "Required" -msgstr "Erforderlich" - -#: date/date_admin.inc:360 -msgid "Set the date elements to be stored (at least a year is required)." -msgstr "" - -#: date/date_admin.inc:368 -msgid "Default Display" -msgstr "Standardmäßige Anzeige" - -#: date/date_admin.inc:371 -msgid "Select a default format type to be used for the date display. Visit the Date and time date format page to add and edit format types." -msgstr "" - -#: date/date_admin.inc:374 -msgid "Select the timezone handling method to be used for this date field." -msgstr "" - -#: date/date_admin.inc:378 -msgid "Time zone handling" -msgstr "Zeitzonenbehandlung" - -#: date/date_admin.inc:394 -#, fuzzy -msgid "Expanded" -msgstr "Geöffnet" - -#: date/date_admin.inc:394 -msgid "Collapsed" -msgstr "Zusammengeklappt" - -#: date/date_admin.inc:395 -msgid "Repeat display" -msgstr "Terminserienanzeige" - -#: date/date_admin.inc:396 -msgid "Should the repeat options form start out expanded or collapsed? Set to 'Collapsed' to make those options less obtrusive." -msgstr "" - -#: date/date_admin.inc:419 -msgid "Changing the %name setting after data has been created could result in the loss of data!" -msgstr "" - -#: date/date_admin.inc:432 -msgid "Site's time zone" -msgstr "Zeitzone der Website" - -# What the heck is this? -#: date/date_admin.inc:433 -msgid "Date's time zone" -msgstr "Zeitzone des Datums" - -#: date/date_admin.inc:434 -msgid "User's time zone" -msgstr "Zeitzone des Benutzers" - -#: date/date_admin.inc:436 -msgid "No time zone conversion" -msgstr "Keine Umstellung der Zeitzone" - -#: date/date_admin.inc:601 -msgid "Display From and To dates" -msgstr "Das „Von“ und „Bis“-Datum anzeigen" - -#: date/date_admin.inc:602 -msgid "Display From date only" -msgstr "Nur das „Von“-Datum anzeigen" - -#: date/date_admin.inc:603 -msgid "Display To date only" -msgstr "Nur das „Bis“-Datum anzeigen" - -#: date/date_admin.inc:622 -msgid "Show @count value(s)" -msgstr "" - -#: date/date_admin.inc:644 -msgid "starting from @count" -msgstr "" - -#: date/date_admin.inc:666 -msgid "ending on @count" -msgstr "" - -#: date/date_admin.inc:695 -msgid "Display repeat rule" -msgstr "Wiederholungsregel anzeigen" - -#: date/date_admin.inc:696 -msgid "Hide repeat rule" -msgstr "Wiederholungsregel verstecken" - -#: date/date_elements.inc:28 -msgid "A 'From date' date is required for field %field %delta." -msgstr "Ein „Von“-Datum ist für %field %delta erforderlich." - -#: date/date_elements.inc:34 -msgid "A 'To date' is required for field %field %delta." -msgstr "Ein „Bis“-Datum ist für %field %delta erforderlich." - -#: date/date_elements.inc:331 -msgid "Empty 'To date' values will use the 'From date' values." -msgstr "Ein leerer „Bis“-Datumswert wird den „Von“-Datumswert verwenden." - -#: date/date_elements.inc:342 -msgid "@field_name From date value #@delta" -msgstr "" - -#: date/date_elements.inc:344 -msgid "@field_name To date value #@delta" -msgstr "" - -#: date/date_elements.inc:348 -msgid "@field_name From date" -msgstr "" - -#: date/date_elements.inc:349 -msgid "@field_name To date" -msgstr "" - -#: date/date_elements.inc:425 -msgid "Some value must be entered in the To date." -msgstr "" - -#: date/date_elements.inc:442 -msgid "The To date must be greater than the From date." -msgstr "" - -#: date/date_elements.inc:477 -msgid "The From date is invalid." -msgstr "Das „Von“-Datum ist ungültig." - -#: date/date_elements.inc:480 -msgid "The To date is invalid." -msgstr "Das „Bis“-Datum ist ungültig." - -#: date/date_elements.inc:489 -msgid "There are errors in @field_name value #@delta:" -msgstr "" - -#: date/date_elements.inc:492 -msgid "There are errors in @field_name:" -msgstr "" - -#: date/date_handler_field_multiple.inc:36 -msgid "Group multiple values" -msgstr "Mehrere Werte gruppieren" - -#: date/date_handler_field_multiple.inc:39 -msgid "If unchecked, each item in the field will create a new row, which may appear to cause duplicates. This setting is not compatible with click-sorting in table displays." -msgstr "" - -#: date/date_repeat.inc:77 -msgid "The UNTIL value is required for repeating dates." -msgstr "Der BIS-Wert ist für Terminserien erforderlich." - -#: date/date_token.inc:12 -msgid "The raw date value." -msgstr "Der unbearbeitete Datumswert." - -#: date/date_token.inc:13 -msgid "The formatted date." -msgstr "Das formatierte Datum." - -#: date/date_token.inc:14 -msgid "The raw date timestamp." -msgstr "Der unbearbeitete Zeitstempel." - -#: date/date_token.inc:15 -msgid "Date year (four digit)" -msgstr "Datum: Jahr (vierstellig)" - -#: date/date_token.inc:16 -msgid "Date year (two digit)" -msgstr "Datum: Jahr (zweistellig)" - -#: date/date_token.inc:17 -msgid "Date month (full word)" -msgstr "Datum: Monat (vollständiges Wort)" - -#: date/date_token.inc:18 -msgid "Date month (abbreviated)" -msgstr "Datum: Monat (abgekürzt)" - -#: date/date_token.inc:19 -msgid "Date month (two digit, zero padded)" -msgstr "Datum: Monat (zweistellig, mit 0 aufgefüllt)" - -#: date/date_token.inc:20 -msgid "Date month (one or two digit)" -msgstr "Datum: Monat (ein- oder zweistellig)" - -#: date/date_token.inc:21 -msgid "Date week (two digit)" -msgstr "Datum: Woche (zweistellig)" - -#: date/date_token.inc:22 -msgid "Date date (YYYY-MM-DD)" -msgstr "" - -#: date/date_token.inc:23 -msgid "Date day (full word)" -msgstr "Datum: Tag (vollständiges Wort)" - -#: date/date_token.inc:24 -msgid "Date day (abbreviation)" -msgstr "Datum: Tag (abgekürzt)" - -#: date/date_token.inc:25 -msgid "Date day (two digit, zero-padded)" -msgstr "Datum: Tag (zweistellig, mit 0 aufgefüllt)" - -#: date/date_token.inc:26 -msgid "Date day (one or two digit)" -msgstr "Datum: Tag (ein- oder zweistellig)" - -#: date/date_token.inc:28 -msgid "If the field has a to-date defined, the same tokens exist in the form: [to-????], where ???? is the normal token." -msgstr "" - -#: date/date.module:121 -msgid "Store a date in the database as an ISO date, recommended for historical or partial dates." -msgstr "" - -#: date/date.module:125 -msgid "Store a date in the database as a timestamp, deprecated format to suppport legacy data." -msgstr "" - -#: date/date.module:129 -msgid "Store a date in the database as a datetime field, recommended for complete dates and times that may need timezone conversion." -msgstr "" - -#: date/date.module:140 -msgid "Select List" -msgstr "Auswahlliste" - -#: date/date.module:148 -msgid "Select List with Repeat options" -msgstr "Auswahlliste mit Terminserienoptionen" - -#: date/date.module:156 -msgid "Text Field with custom input format" -msgstr "Textfeld mit benutzerdefiniertem Eingabeformat" - -#: date/date.module:164 -msgid "Text Field with Repeat options" -msgstr "Textfeld mit Terminserien" - -#: date/date.module:174 -msgid "Text Field with Date Pop-up calendar" -msgstr "Textfeld mit Kalender" - -#: date/date.module:182 -msgid "Text Field with Date Pop-up and Repeat options" -msgstr "Textfeld mit Kalender & Terminserienoptionen" - -#: date/date.module:221 -msgid "Default" -msgstr "Standard" - -#: date/date.module:224 -msgid "As Time Ago" -msgstr "" - -#: date/date.module:420 -msgid "Complete documentation for the Date and Date API modules is available at http://drupal.org/node/92460." -msgstr "" - -#: date/date.module:716 -msgid "Add format type" -msgstr "Formattyp hinzufügen" - -#: date/date.module:720 -msgid "Name" -msgstr "Name" - -#: date/date.module:721 -msgid "The human-readable name for this format type." -msgstr "" - -#: date/date.module:728 -msgid "Type" -msgstr "Typ" - -#: date/date.module:729 -msgid "The machine-readable name of this format type.