| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: theme.inc,v 1.1.4.38 2010/11/20 13:25:54 karens Exp $ 3 /** 4 * Preprocessor to construct back and next navigation from the date argument. 5 */ 6 function template_preprocess_date_navigation(&$vars) { 7 $view = $vars['view']; 8 $next_args = $view->args; 9 $prev_args = $view->args; 10 $pos = $view->date_info->date_arg_pos; 11 $min_date = is_object($view->date_info->min_date) ? $view->date_info->min_date : date_now(); 12 $max_date = is_object($view->date_info->max_date) ? $view->date_info->max_date : date_now(); 13 14 if (empty($view->date_info->hide_nav)) { 15 $prev_date = drupal_clone($min_date); 16 date_modify($prev_date, '-1 '. $view->date_info->granularity); 17 $next_date = drupal_clone($min_date); 18 date_modify($next_date, '+1 '. $view->date_info->granularity); 19 $format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d'); 20 switch ($view->date_info->granularity) { 21 case 'week': 22 $next_week = date_week(date_format($next_date, 'Y-m-d')); 23 $prev_week = date_week(date_format($prev_date, 'Y-m-d')); 24 $next_arg = date_format($next_date, 'Y-\W') . $next_week; 25 $prev_arg = date_format($prev_date, 'Y-\W') . $prev_week; 26 break; 27 default: 28 $next_arg = date_format($next_date, $format[$view->date_info->granularity]); 29 $prev_arg = date_format($prev_date, $format[$view->date_info->granularity]); 30 } 31 $next_path = str_replace($view->date_info->date_arg, $next_arg, $view->date_info->url); 32 $prev_path = str_replace($view->date_info->date_arg, $prev_arg, $view->date_info->url); 33 $next_args[$pos] = $next_arg; 34 $prev_args[$pos] = $prev_arg; 35 $vars['next_url'] = date_real_url($view, NULL, $next_arg); 36 $vars['prev_url'] = date_real_url($view, NULL, $prev_arg); 37 $vars['next_options'] = $vars['prev_options'] = array(); 38 } 39 else { 40 $next_path = ''; 41 $prev_path = ''; 42 $vars['next_url'] = ''; 43 $vars['prev_url'] = ''; 44 $vars['next_options'] = $vars['prev_options'] = array(); 45 } 46 47 // Check whether navigation links would point to 48 // a date outside the allowed range. 49 if (!empty($next_date) && !empty($vars['next_url']) && date_format($next_date, 'Y') > $view->date_info->max_allowed_year) { 50 $vars['next_url'] = ''; 51 } 52 if (!empty($prev_date) && !empty($vars['prev_url']) && date_format($prev_date, 'Y') < $view->date_info->min_allowed_year) { 53 $vars['prev_url'] = ''; 54 } 55 56 $vars['prev_options'] += array('attributes' => array()); 57 $vars['next_options'] += array('attributes' => array()); 58 $prev_title = ''; 59 $next_title = ''; 60 61 // Build next/prev link titles. 62 switch($view->date_info->granularity) { 63 case 'year': 64 $prev_title = t('Navigate to previous year'); 65 $next_title = t('Navigate to next year'); 66 break; 67 case 'month': 68 $prev_title = t('Navigate to previous month'); 69 $next_title = t('Navigate to next month'); 70 break; 71 case 'week': 72 $prev_title = t('Navigate to previous week'); 73 $next_title = t('Navigate to next week'); 74 break; 75 case 'day': 76 $prev_title = t('Navigate to previous day'); 77 $next_title = t('Navigate to next day'); 78 break; 79 } 80 $vars['prev_options']['attributes'] += array('title' => $prev_title); 81 $vars['next_options']['attributes'] += array('title' => $next_title); 82 83 // Add nofollow for next/prev links. 84 $vars['prev_options']['attributes'] += array('rel' => 'nofollow'); 85 $vars['next_options']['attributes'] += array('rel' => 'nofollow'); 86 87 $link = FALSE; 88 // Month navigation titles are used as links in the block view. 89 if (!empty($view->date_info->block) && $view->date_info->granularity == 'month') { 90 $link = TRUE; 91 } 92 93 $nav_title = theme('date_nav_title', $view->date_info->granularity, $view, $link); 94 $vars['nav_title'] = $nav_title; 95 $vars['block'] = !empty($view->date_info->block); 96 } 97 98 /** 99 * Theme the calendar title 100 */ 101 function theme_date_nav_title($granularity, $view, $link = FALSE, $format = NULL) { 102 switch ($granularity) { 103 case 'year': 104 $title = $view->date_info->year; 105 $date_arg = $view->date_info->year; 106 break; 107 case 'month': 108 $format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'F Y' : 'F'); 109 $title = date_format_date($view->date_info->min_date, 'custom', $format); 110 $date_arg = $view->date_info->year .'-'. date_pad($view->date_info->month); 111 break; 112 case 'day': 113 $format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'l, F j Y' : 'l, F j'); 114 $title = date_format_date($view->date_info->min_date, 'custom', $format); 115 $date_arg = $view->date_info->year .'-'. date_pad($view->date_info->month) .'-'. date_pad($view->date_info->day); 116 break; 117 case 'week': 118 $format = !empty($format) ? $format : (empty($view->date_info->mini) ? 'F j Y' : 'F j'); 119 $title = t('Week of @date', array('@date' => date_format_date($view->date_info->min_date, 'custom', $format))); 120 $date_arg = $view->date_info->year .'-W'. date_pad($view->date_info->week); 121 break; 122 } 123 if (!empty($view->date_info->mini) || $link) { 124 // Month navigation titles are used as links in the mini view. 125 $attributes = array('title' => t('View full page month')); 126 $url = date_real_url($view, $granularity, $date_arg, TRUE); 127 return l($title, $url, array('attributes' => $attributes)); 128 } 129 else { 130 return $title; 131 } 132 } 133 134 /** 135 * Preprocessor to construct an ical vcalendar 136 * 137 * @param $events 138 * An array of events where each event is an array keyed on the uid: 139 * 'start' 140 * Start date object, 141 * 'end' 142 * End date object, optional, omit for all day event. 143 * 'summary' 144 * Title of event (Text) 145 * 'description' 146 * Description of event (Text) 147 * 'location' 148 * Location of event (Text or vvenue id) 149 * 'uid' 150 * ID of the event for use by calendaring program, usually the url of the node 151 * 'url' 152 * URL of event information 153 * 154 * 'alarm' 155 * sub-array of alarm information for the event, including: 156 * - 'action' - the action to take, either 'DISPLAY' or 'EMAIL' 157 * - 'trigger' - the time period for the trigger, like -P2D. 158 * - 'repeat' - the number of times to repeat the alarm. 159 * - 'duration' - the time period between repeated alarms, like P1D. 160 * - 'description' - the description of the alarm. 161 * An email alarm should have two additional parts: 162 * - 'email' - a comma-separated list of email recipients. 163 * - 'summary' - the subject of the alarm email. 164 * 165 * @param $calname 166 * Name of the calendar. Use site name if none is specified. 167 * 168 */ 169 function template_preprocess_date_vcalendar(&$vars) { 170 171 $vars['current_date'] = date_format(date_now(), DATE_FORMAT_ICAL); 172 $vars['current_date_utc'] = date_format(date_now('UTC'), DATE_FORMAT_ICAL); 173 $vars['site_timezone'] = date_default_timezone_name(); 174 $vars['calname'] = date_ical_escape_text(!empty($vars['calname']) ? $vars['calname'] : variable_get('site_name', '')); 175 176 // Format the event results as iCal expects. 177 $events_in = $vars['events']; 178 $events = array(); 179 $rows = $vars['rows']; 180 foreach ($events_in as $uid => $event) { 181 $row = array_shift($rows); 182 // Omit any items with empty dates. 183 if (!empty($event['start'])) { 184 $events[$uid] = $event; 185 $timezone = timezone_name_get(date_timezone_get($event['start'])); 186 if (!empty($timezone)) { 187 $events[$uid]['timezone'] = "TZID=$timezone:"; 188 } 189 else { 190 $events[$uid]['timezone'] = ''; 191 } 192 $date_format = ($row->calendar_all_day == TRUE) ? DATE_FORMAT_ICAL_DATE : DATE_FORMAT_ICAL; 193 $events[$uid]['start'] = date_format($event['start'], $date_format); 194 if ($event['start'] && $event['end']) { 195 $events[$uid]['end'] = date_format($event['end'], $date_format); 196 } 197 else { 198 $events[$uid]['end'] = $events[$uid]['start']; 199 } 200 foreach ($event as $key => $value) { 201 if (is_string($value)) { 202 $event[trim($key)] = trim($value); 203 } 204 } 205 206 // Escape text values. 207 foreach ($event as $key => $value) { 208 if ($key == 'alarm') { 209 foreach ($value as $alarm_key => $alarm_value) { 210 if (in_array($alarm_key, array('summary', 'description'))) { 211 $events[$uid]['alarm'][$alarm_key] = date_ical_escape_text($alarm_value); 212 } 213 } 214 } 215 elseif (in_array($key, array('summary', 'description', 'location'))) { 216 $events[$uid][$key] = date_ical_escape_text(html_entity_decode($value, ENT_QUOTES, 'UTF-8')); 217 } 218 } 219 } 220 } 221 222 $vars['events'] = $events; 223 } 224 225 /** 226 * Preprocessor for Date Views filter form. 227 */ 228 function template_preprocess_date_views_filter_form(&$vars) { 229 $form = $vars['form']; 230 $vars['date'] = drupal_render($form['valuedate']); 231 $vars['mindate'] = drupal_render($form['mindate']); 232 $vars['maxdate'] = drupal_render($form['maxdate']); 233 $vars['adjustment'] = drupal_render($form['valueadjustment']); 234 $vars['minadjustment'] = drupal_render($form['minadjustment']); 235 $vars['maxadjustment'] = drupal_render($form['maxadjustment']); 236 $vars['description'] = drupal_render($form['description']) . drupal_render($form); 237 } 238 239 /** 240 * Format a date timezone element. 241 * 242 * @param $element 243 * An associative array containing the properties of the element. 244 * Properties used: title, value, options, description, required and attributes. 245 * @return 246 * A themed HTML string representing the date selection boxes. 247 */ 248 function theme_date_timezone($element) { 249 return '<div class="date-clear">'. theme('form_element', $element, $element['#children']) .'</div>'; 250 } 251 252 /** 253 * Format a date selection element. 254 * 255 * @param $element 256 * An associative array containing the properties of the element. 257 * Properties used: title, value, options, description, required and attributes. 258 * @return 259 * A themed HTML string representing the date selection boxes. 260 */ 261 function theme_date_select($element) { 262 $output = ''; 263 $class = 'container-inline-date'; 264 // Add #date_float to allow date parts to float together on the same line. 265 if (empty($element['#date_float'])) { 266 $class .= ' date-clear-block'; 267 } 268 if (isset($element['#children'])) { 269 $output = $element['#children']; 270 } 271 return '<div class="'. $class .'">'. theme('form_element', $element, $output) .'</div>'; 272 } 273 274 /** 275 * Format a date text element. 276 * 277 * @param $element 278 * An associative array containing the properties of the element. 279 * Properties used: title, value, options, description, required and attributes. 280 * @return 281 * A themed HTML string representing the date selection boxes. 282 */ 283 function theme_date_text($element) { 284 $output = ''; 285 $class = 'container-inline-date'; 286 // Add #date_float to allow date parts to float together on the same line. 287 if (empty($element['#date_float'])) { 288 $class .= ' date-clear-block'; 289 } 290 if (isset($element['#children'])) { 291 $output = $element['#children']; 292 } 293 return '<div class="'. $class .'">'. theme('form_element', $element, $output) .'</div>'; 294 } 295 296 /** 297 * Themes for date input form elements 298 */ 299 function theme_date_select_element($element) { 300 $part = array_pop($element['#parents']); 301 return '<div class="date-'. $part .'">'. theme('select', $element) .'</div>'; 302 } 303 304 function theme_date_textfield_element($element) { 305 $part = array_pop($element['#parents']); 306 return '<div class="date-'. $part .'">'. theme('textfield', $element) .'</div>'; 307 } 308 309 /** 310 * Functions to separate date parts in form. 311 * 312 * Separators float up to the title level for elements with titles, 313 * so won't work if this element has titles above the element date parts. 314 */ 315 function theme_date_part_hour_prefix($element) { 316 if ($element['#date_label_position'] != 'above') { 317 return '<span class="form-item date-spacer"> - </span>'; 318 } 319 } 320 321 function theme_date_part_minsec_prefix($element) { 322 if ($element['#date_label_position'] != 'above') { 323 return '<span class="form-item date-spacer">:</span>'; 324 } 325 } 326 327 /** 328 * Format labels for each date part in a date_select. 329 * 330 * @param $part_type 331 * the type of field used for this part, 'textfield' or 'select' 332 * @param $element 333 * An associative array containing the properties of the element. 334 * Properties used: title, value, options, description, required and attributes. 335 */ 336 function theme_date_part_label_year($part_type, $element) { 337 return date_t('Year', 'datetime'); 338 } 339 function theme_date_part_label_month($part_type, $element) { 340 return date_t('Month', 'datetime'); 341 } 342 function theme_date_part_label_day($part_type, $element) { 343 return date_t('Day', 'datetime'); 344 } 345 function theme_date_part_label_hour($part_type, $element) { 346 return date_t('Hour', 'datetime'); 347 } 348 function theme_date_part_label_minute($part_type, $element) { 349 return date_t('Minute', 'datetime'); 350 } 351 function theme_date_part_label_second($part_type, $element) { 352 return date_t('Second', 'datetime'); 353 } 354 function theme_date_part_label_ampm($part_type, $element) { 355 return ' '; 356 } 357 function theme_date_part_label_timezone($part_type, $element) { 358 return t('Timezone'); 359 } 360 361 /** 362 * Theme for a date block that looks like a mini calendar day. 363 * Pass in a date object already set to the right timezone, 364 * format as a calendar page date. The calendar styling is created in css. 365 */ 366 function theme_date_calendar_day($date) { 367 if (empty($date)) { 368 return NULL; 369 } 370 return '<div class="date-calendar-day">' . 371 '<span class="month">' . date_format_date($date, 'custom', 'M') . '</span>' . 372 '<span class="day">' . date_format_date($date, 'custom', 'j') . '</span>' . 373 '<span class="year">' . date_format_date($date, 'custom', 'Y') . '</span>' . 374 '</div>'; 375 } 376 377 function theme_date_time_ago($start_date, $end_date, $interval = 2) { 378 // If no date is sent, then return nothing 379 if (empty($start_date) || empty($end_date)){ 380 return NULL; 381 } 382 383 // Time to compare dates to 384 $now = date_format(date_now(), DATE_FORMAT_DATETIME); 385 $start = date_format($start_date, DATE_FORMAT_DATETIME); 386 $end = date_format($end_date, DATE_FORMAT_DATETIME); 387 388 // 1) The date is entirely in the future 389 if ($now < $start) { 390 return t('!time from now', array('!time' => date_format_interval($start_date, $interval))); 391 } 392 // 2) Ongoing date 393 elseif ($now > $start && $now <= $end) { 394 //return t('Started !time ago', array('!time' => $dates['value']['interval'])); 395 return t('ongoing'); 396 } 397 // 3) Date is in the past (format_interval added 'ago' to the value). 398 else { 399 return date_format_interval($start_date, $interval); 400 } 401 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |