| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @file 4 * Theme functions. 5 */ 6 /** 7 * @addtogroup themeable 8 * @{ 9 * 10 * Formatter themes 11 */ 12 /** 13 * Theme from/to date combination in the view. 14 * 15 * Useful values: 16 * 17 * $node->date_id 18 * If set, this will show only an individual date on a field with 19 * multiple dates. The value should be a string that contains 20 * the following values, separated with periods: 21 * - module name of the module adding the item 22 * - node nid 23 * - field name 24 * - delta value of the field to be displayed 25 * - other information the module's custom theme might need 26 * 27 * Used by the calendar module and available for other uses. 28 * example: 'date.217.field_date.3.test' 29 * 30 * $node->date_repeat_show 31 * If true, tells the theme to show all the computed values 32 * of a repeating date. If not true or not set, only the 33 * start date and the repeat rule will be displayed. 34 * 35 * $dates['format'] - the format string used on these dates 36 * $dates['value']['local']['object'] - the local date object for the From date 37 * $dates['value2']['local']['object'] - the local date object for the To date 38 * $dates['value']['local']['datetime'] - the datetime value of the From date database (GMT) value 39 * $dates['value2']['local']['datetime'] - the datetime value of the To date database (GMT) value 40 * $dates['value']['formatted'] = formatted From date, i.e. 'February 15, 2007 2:00 pm'; 41 * $dates['value']['formatted_date'] - only the date part of the formatted From date 42 * $dates['value']['formatted_time'] - only the time part of the formatted From date 43 * $dates['value2']['formatted'] = formatted To date, i.e. 'February 15, 2007 6:00 pm'; 44 * $dates['value2']['formatted_date'] - only the date part of the formatted To date 45 * $dates['value2']['formatted_time'] - only the time part of the formatted To date 46 */ 47 function theme_date_display_combination($element) { 48 static $repeating_ids = array(); 49 50 $node = $element['#node']; 51 $field_name = $element['#field_name']; 52 $context = !empty($node->content) && !empty($node->content[$field_name]) ? $node->content[$field_name]['#context'] : 'full'; 53 $type_name = $element['#type_name']; 54 $fields = content_fields(); 55 $field = $fields[$field_name]; 56 $item = $element['#item']; 57 58 // Get the formatter settings, either the default settings for this node 59 // type or the View settings stored in $node->date_info. 60 $options = date_formatter_get_settings($field_name, $type_name, $context); 61 if (!empty($node->date_info) && !empty($node->date_info->formatter_settings)) { 62 $options = $node->date_info->formatter_settings; 63 } 64 65 $output = ''; 66 67 // If date_id is set for this field and the delta doesn't match, don't display it. 68 if (!empty($node->date_id)) { 69 foreach ((array) $node->date_id as $key => $id) { 70 list($module, $nid, $field_name, $delta, $other) = explode('.', $id); 71 if ($field_name == $field['field_name'] && isset($item['#delta']) && $delta != $item['#delta']) { 72 return $output; 73 } 74 } 75 } 76 77 // Check the formatter settings to see if the repeat rule should be 78 // displayed. Show it only with the first multiple value date. 79 if (!in_array($node->nid, $repeating_ids) && module_exists('date_repeat') 80 && !empty($item['rrule']) && $options['repeat']['show_repeat_rule'] == 'show') { 81 require_once('./'. drupal_get_path('module', 'date') .'/date_repeat.inc'); 82 $output .= theme('date_repeat_display', $field, $item, $node); 83 $repeating_ids[] = $node->nid; 84 } 85 86 // If this is a full node or a pseudo node created by grouping 87 // multiple values, see exactly which values are supposed to be visible. 88 if (isset($node->$field_name)) { 89 $node = date_prepare_node($node, $field, $type_name, $context, $options); 90 // Did the current value get removed by formatter settings? 91 if (empty($node->{$field_name}[$item['#delta']])) { 92 return $output; 93 } 94 // Adjust the $element values to match the changes. 95 $element['#node'] = $node; 96 } 97 98 // Call the right theme for this formatter. 99 // Update the element with values that might have been altered by 100 // date_prepare_node() and figure out which values to display. 101 $dates = date_formatter_process($element); 102 switch ($options['fromto']['fromto']) { 103 case 'value': 104 $date1 = $dates['value']['formatted']; 105 $date2 = $date1; 106 break; 107 case 'value2': 108 $date2 = $dates['value2']['formatted']; 109 $date1 = $date2; 110 break; 111 default: 112 $date1 = $dates['value']['formatted']; 113 $date2 = $dates['value2']['formatted']; 114 break; 115 } 116 117 // Pull the timezone, if any, out of the formatted result and tack it 118 // back on at the end, if it is in the current formatted date. 119 $timezone = $dates['value']['formatted_timezone']; 120 if ($timezone) { 121 $timezone = ' ' . $timezone; 122 } 123 $date1 = str_replace($timezone, '', $date1); 124 $date2 = str_replace($timezone, '', $date2); 125 126 // No date values, display nothing. 127 if (empty($date1) && empty($date2)) { 128 $output .= ''; 129 } 130 // From and To dates match or there is no To date, display a complete single date. 131 elseif ($date1 == $date2 || empty($date2)) { 132 $output .= theme('date_display_single', $date1, $timezone); 133 } 134 // Same day, different times, don't repeat the date but show both From and To times. 135 elseif (date_has_time($field['granularity']) && $dates['value']['formatted_date'] == $dates['value2']['formatted_date']) { 136 // Replace the original time with the from/to time in the formatted start date. 137 // Make sure that parentheses or brackets wrapping the time will be retained in the 138 // final result. 139 $time1 = preg_replace('`^([\(\[])`', '', $dates['value']['formatted_time']); 140 $time1 = preg_replace('([\)\]]$)', '', $time1); 141 $time2 = preg_replace('`^([\(\[])`', '', $dates['value2']['formatted_time']); 142 $time2 = preg_replace('([\)\]]$)', '', $time2); 143 $time = theme('date_display_range', $time1, $time2); 144 $replaced = str_replace($time1, $time, $date1); 145 $output .= theme('date_display_single', $replaced, $timezone); 146 } 147 // Different days, display both in their entirety. 148 else { 149 $output .= theme('date_display_range', $date1, $date2, $timezone); 150 } 151 return $output; 152 } 153 154 function theme_date_display_single($date, $timezone = NULL) { 155 return '<span class="date-display-single">'. $date . $timezone .'</span>'; 156 } 157 158 function theme_date_display_range($date1, $date2, $timezone = NULL) { 159 return '<span class="date-display-start">'. $date1 .'</span>'. 160 '<span class="date-display-separator"> - </span>' . 161 '<span class="date-display-end">'. $date2 . $timezone. '</span>'; 162 } 163 164 /** 165 * Theme a format interval for a date element 166 * 167 * @param $field = the field settings 168 * @param $node = node information, this is not always available and not 169 * always the full node, it depends on what value was provided to the formatter. 170 * Only the nid is always guaranteed to be available. 171 * @param $dates - an array of date information, see explanation for date_field_object for details. 172 * @return a formatted display 173 * 174 */ 175 function theme_date_format_interval($element) { 176 $node = $element['#node']; 177 $field_name = $element['#field_name']; 178 $context = !empty($node->content) ? $node->content[$field_name]['#context'] : 'full'; 179 $type_name = $element['#type_name']; 180 $fields = content_fields(); 181 $field = $fields[$field_name]; 182 $item = $element['#item']; 183 184 // Get the formatter settings, either the default settings for this node 185 // type or the View settings stored in $node->date_info. 186 $options = date_formatter_get_settings($field_name, $type_name, $context); 187 if (!empty($node->date_info) && !empty($node->date_info->formatter_settings)) { 188 $options = $node->date_info->formatter_settings; 189 } 190 191 // If date_id is set for this field and the delta doesn't match, don't display it. 192 if (!empty($node->date_id)) { 193 foreach ((array) $node->date_id as $key => $id) { 194 list($module, $nid, $field_name, $delta, $other) = explode('.', $id); 195 if ($field_name == $field['field_name'] && isset($item['#delta']) && $delta != $item['#delta']) { 196 return; 197 } 198 } 199 } 200 201 // If this is not coming from Views, it is the full node. 202 // If we aren't retrieving a specific value, adjust the node values 203 // to match the formatter settings, removing values we should not see. 204 if (!empty($node->content) && empty($node->date_id)) { 205 $node = date_prepare_node($node, $field, $type_name, $context, $options); 206 207 // Did the current value get removed by formatter settings? 208 if (empty($node->{$field_name}[$item['#delta']])) { 209 return; 210 } 211 // Adjust the $element values to match the changes. 212 $element['#node'] = $node; 213 } 214 $dates = date_formatter_process($element); 215 return theme('date_time_ago', $dates['value']['local']['object'], $dates['value2']['local']['object']); 216 } 217 218 /** 219 * Theme the human-readable description for a Date Repeat rule. 220 * 221 * TODO - 222 * add in ways to store the description in the date so it isn't regenerated 223 * over and over and find a way to allow description to be shown or hidden. 224 */ 225 function theme_date_repeat_display($field, $item, $node = NULL) { 226 $output = ''; 227 if (!empty($item['rrule'])) { 228 $output = date_repeat_rrule_description($item['rrule']); 229 $output = '<div>'. $output .'</div>'; 230 } 231 return $output; 232 } 233 234 /** 235 * Adjust from/to date format to account for 'all day'. 236 * 237 * @param array $field, the field definition for this date field. 238 * @param string $which, which value to return, 'date1' or 'date2'. 239 * @param object $date1, a date/time object for the 'from' date. 240 * @param object $date2, a date/time object for the 'to' date. 241 * @param string $format 242 * @param object $node, the node this date comes from (may be incomplete, always contains nid). 243 * @param object $view, the view this node comes from, if applicable. 244 * @return formatted date. 245 */ 246 function theme_date_all_day($field, $which, $date1, $date2, $format, $node, $view = NULL) { 247 248 if (empty($date1) || !is_object($date1) || $format == 'format_interval') { 249 return; 250 } 251 if (empty($date2)) { 252 $date2 = $date1; 253 } 254 255 if (!date_has_time($field['granularity'])) { 256 $format = date_limit_format($format, array('year', 'month', 'day')); 257 return date_format_date($$which, 'custom', $format); 258 } 259 260 if ($all_day = date_field_all_day($field, $date1, $date2)) { 261 $format = date_limit_format($format, array('year', 'month', 'day')); 262 return trim(date_format_date($$which, 'custom', $format) .' '. theme('date_all_day_label')); 263 } 264 else { 265 return date_format_date($$which, 'custom', $format); 266 } 267 } 268 269 /** 270 * Theme the way an 'all day' label will look. 271 */ 272 function theme_date_all_day_label() { 273 return '('. date_t('All day', 'datetime') .')'; 274 } 275 /** @} End of addtogroup themeable */
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |