~ubuntu-gr-webteam/ubuntu-gr-website/drupal6-site

« back to all changes in this revision

Viewing changes to sites/all/modules/date/date/date.theme

  • Committer: Thanos Lefteris
  • Date: 2009-07-29 17:46:54 UTC
  • Revision ID: alefteris@gmail.com-20090729174654-pgfr1vtqw8ikvo5r
* Upgraded calendar module
* Upgraded commentrss module
* Upgraded date module
* Upgraded webfm module

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
//$Id: date.theme,v 1.6.4.43 2009/03/26 10:57:11 karens Exp $
 
2
//$Id: date.theme,v 1.6.4.51 2009/06/09 17:20:31 karens Exp $
3
3
/**
4
4
 * @file
5
5
 * Theme functions.
50
50
  
51
51
  $node = $element['#node'];
52
52
  $field_name = $element['#field_name'];
53
 
  $context = !empty($node->content) ? $node->content[$field_name]['#context'] : '';
 
53
  $context = !empty($node->content) && !empty($node->content[$field_name]) ? $node->content[$field_name]['#context'] : 'full';
54
54
  $type_name = $element['#type_name'];
55
55
  $fields = content_fields();
56
56
  $field = $fields[$field_name];
100
100
  // Update the element with values that might have been altered by 
101
101
  // date_prepare_node() and figure out which values to display.
102
102
  $dates = date_formatter_process($element);
103
 
  
104
103
  switch ($options['fromto']['fromto']) {
105
104
    case 'value':
106
105
      $date1 = $dates['value']['formatted'];
131
130
  }
132
131
  // From and To dates match or there is no To date, display a complete single date.
133
132
  elseif ($date1 == $date2 || empty($date2)) {
134
 
    $output .= '<span class="date-display-single">'. $date1 . $timezone .'</span>';
 
133
    $output .= theme('date_display_single', $date1, $timezone);
135
134
  }
136
135
  // Same day, different times, don't repeat the date but show both From and To times.
137
 
  elseif ($dates['value']['formatted_date'] == $dates['value2']['formatted_date']) {
 
136
  elseif (date_has_time($field['granularity']) && $dates['value']['formatted_date'] == $dates['value2']['formatted_date']) {
138
137
    // Replace the original time with the from/to time in the formatted start date.  
139
138
    // Make sure that parentheses or brackets wrapping the time will be retained in the
140
139
    // final result.
142
141
    $time1 = preg_replace('([\)\]]$)', '', $time1);
143
142
    $time2 = preg_replace('`^([\(\[])`', '', $dates['value2']['formatted_time']);
144
143
    $time2 = preg_replace('([\)\]]$)', '', $time2);
145
 
    $time = '<span class="date-display-start">'. $time1 .'</span>'.
146
 
      '<span class="date-display-separator"> &#8211; </span>'.
147
 
      '<span class="date-display-end">'. $time2 .'</span>';
 
144
    $time = theme('date_display_range', $time1, $time2);
148
145
    $replaced = str_replace($time1, $time, $date1);
149
 
    $output .= '<span class="date-display-single">'. $replaced . $timezone .'</span> ';
 
146
    $output .= theme('date_display_single', $replaced, $timezone);
150
147
  }
151
148
  // Different days, display both in their entirety.
152
149
  else {
153
 
    $output .= '<span class="date-display-start">'. $date1 .'</span>'.
154
 
      '<span class="date-display-separator"> &#8211; </span>'.
 
150
    $output .= theme('date_display_range', $date1, $date2, $timezone);
 
151
  }
 
152
  
 
153
  return $output;
 
154
}
 
155
 
 
156
function theme_date_display_single($date, $timezone = NULL) {
 
157
  return '<span class="date-display-single">'. $date . $timezone .'</span>';
 
158
}
 
159
 
 
160
function theme_date_display_range($date1, $date2, $timezone = NULL) {
 
161
  return '<span class="date-display-start">'. $date1 .'</span>'.
 
162
      '<span class="date-display-separator"> - </span>' .
155
163
      '<span class="date-display-end">'. $date2 . $timezone. '</span>';
156
 
  }
157
 
  
158
 
  return $output;
159
164
}
160
165
 
161
166
/**
172
177
function theme_date_format_interval($element) {
173
178
  $node = $element['#node'];
174
179
  $field_name = $element['#field_name'];
175
 
  $context = !empty($node->content) ? $node->content[$field_name]['#context'] : '';
 
180
  $context = !empty($node->content) ? $node->content[$field_name]['#context'] : 'full';
176
181
  $type_name = $element['#type_name'];
177
182
  $fields = content_fields();
178
183
  $field = $fields[$field_name];
212
217
  return theme('date_time_ago', $dates['value']['local']['object'], $dates['value2']['local']['object']);
213
218
}
214
219
 
215
 
function theme_date_time_ago($start_date, $end_date) {
216
 
  // Time to compare dates to
217
 
  $now = date_format(date_now(), DATE_FORMAT_DATETIME);
218
 
  $start = date_format($start_date, DATE_FORMAT_DATETIME);
219
 
  $end = date_format($end_date, DATE_FORMAT_DATETIME);
220
 
  
221
 
  // 1) The date is entirely in the future
222
 
  if ($now < $start) {
223
 
    return t('!time from now', array('!time' => date_format_interval($start_date, 2)));
224
 
  }
225
 
  // 2) Ongoing date
226
 
  elseif ($now > $start && $now <= $end) {
227
 
    //return t('Started !time ago', array('!time' => $dates['value']['interval']));
228
 
    return t('ongoing');
229
 
  }
230
 
  // 3) Date is in the past (format_interval added 'ago' to the value).
231
 
  else {
232
 
    return date_format_interval($start_date, 2);
233
 
  }
234
 
}
235
 
 
236
220
/**
237
221
 * Theme the human-readable description for a Date Repeat rule.
238
222
 *