| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: context.theme.inc,v 1.7.2.4 2010/09/10 18:25:13 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * Contains theme registry and theme implementations for the context tool. 7 */ 8 9 /** 10 * Implementation of hook_theme() 11 */ 12 function ctools_context_theme(&$theme) { 13 $theme['ctools_context_list'] = array( 14 'arguments' => array('object'), 15 'file' => 'includes/context.theme.inc', 16 ); 17 $theme['ctools_context_list_no_table'] = array( 18 'arguments' => array('object'), 19 'file' => 'includes/context.theme.inc', 20 ); 21 $theme['ctools_context_item_form'] = array( 22 'arguments' => array('form'), 23 'file' => 'includes/context.theme.inc', 24 ); 25 $theme['ctools_context_item_row'] = array( 26 'arguments' => array('type', 'form', 'position', 'count', 'with_tr' => TRUE), 27 'file' => 'includes/context.theme.inc', 28 ); 29 30 // For the access plugin 31 $theme['ctools_access_admin_add'] = array( 32 'arguments' => array('form'), 33 'file' => 'includes/context-admin.inc', 34 ); 35 } 36 37 /** 38 * Theme the form item for the context entry. 39 */ 40 function theme_ctools_context_item_row($type, $form, $position, $count, $with_tr = TRUE) { 41 $output = '<td class="title"> ' . drupal_render($form['title']) . '</td>'; 42 if (!empty($form['position'])) { 43 $output .= '<td class="position"> ' . drupal_render($form['position']) . '</td>'; 44 } 45 $output .= '<td class="operation">' . drupal_render($form['settings']); 46 $output .= drupal_render($form['remove']) . '</td>'; 47 48 if ($with_tr) { 49 $output = '<tr id="' . $type . '-row-' . $position . '" class="draggable ' . $type . '-row ' . ($count % 2 ? 'even' : 'odd') . '">' . $output . '</tr>'; 50 } 51 return $output; 52 } 53 54 /** 55 * Display the context item. 56 */ 57 function theme_ctools_context_item_form($form) { 58 $output = ''; 59 $type = $form['#ctools_context_type']; 60 $module = $form['#ctools_context_module']; 61 $name = $form['#object_name']; 62 63 $type_info = ctools_context_info($type); 64 65 if (!empty($form[$type]) && empty($form['#only_buttons'])) { 66 $count = 0; 67 $rows = ''; 68 foreach (array_keys($form[$type]) as $id) { 69 if (!is_numeric($id)) { 70 continue; 71 } 72 $rows .= theme('ctools_context_item_row', $type, $form[$type][$id], $id, $count++); 73 } 74 75 $output .= '<table id="' . $type . '-table">'; 76 $output .= '<thead>'; 77 $output .= '<tr>'; 78 $output .= '<th class="title">' . $type_info['title'] . '</th>'; 79 if (!empty($type_info['sortable']) && $count) { 80 $output .= '<th class="position">' . t('Weight') . '</th>'; 81 } 82 $output .= '<th class="operation">' . t('Operation') . '</th>'; 83 $output .= '</tr>'; 84 $output .= '</thead>'; 85 $output .= '<tbody>'; 86 87 $output .= $rows; 88 89 $output .= '</tbody>'; 90 $output .= '</table>'; 91 } 92 93 if (!empty($form['buttons'])) { 94 // Display the add context item. 95 $row = array(); 96 $row[] = array('data' => drupal_render($form['buttons'][$type]['item']), 'class' => 'title'); 97 $row[] = array('data' => drupal_render($form['buttons'][$type]['add']), 'class' => 'add', 'width' => "60%"); 98 $output .= '<div class="buttons">'; 99 $output .= drupal_render($form['buttons'][$type]); 100 $output .= theme('table', array(), array($row), array('id' => $type . '-add-table')); 101 $output .= '</div>'; 102 } 103 if (!empty($form['description'])) { 104 $output .= drupal_render($form['description']); 105 } 106 107 if (!empty($type_info['sortable'])) { 108 drupal_add_tabledrag($type . '-table', 'order', 'sibling', 'drag-position'); 109 } 110 111 return $output; 112 } 113 114 /** 115 * Create a visible list of all the contexts available on an object. 116 * Assumes arguments, relationships and context objects. 117 * 118 * Contexts must be preloaded. 119 */ 120 function theme_ctools_context_list($object, $header = '', $description = '') { 121 $titles = array(); 122 $output = ''; 123 $count = 1; 124 125 $contexts = ctools_context_load_contexts($object); 126 127 // Describe 'built in' contexts. 128 if (!empty($object->base_contexts)) { 129 foreach ($object->base_contexts as $id => $context) { 130 $output .= '<tr>'; 131 $output .= '<td valign="top"><em>' . t('Built in context') . '</em></td>'; 132 $desc = check_plain($context->identifier); 133 if (isset($context->keyword)) { 134 $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context->keyword)); 135 foreach (ctools_context_get_converters('%' . $context->keyword . ':', $context) as $keyword => $title) { 136 $desc .= '<br />' . t('@keyword --> @title', array('@keyword' => $keyword, '@title' => $title)); 137 } 138 $desc .= '</div>'; 139 140 } 141 if (isset($context->description)) { 142 $desc .= '<div class="description">' . filter_xss_admin($context->description) . '</div>'; 143 } 144 $output .= '<td>' . $desc . '</td>'; 145 $output .= '</tr>'; 146 $titles[$id] = $context->identifier; 147 } 148 } 149 150 // First, make a list of arguments. Arguments are pretty simple. 151 if (!empty($object->arguments)) { 152 foreach ($object->arguments as $argument) { 153 $output .= '<tr>'; 154 $output .= '<td valign="top"><em>' . t('Argument @count', array('@count' => $count)) . '</em></td>'; 155 $desc = check_plain($argument['identifier']); 156 if (isset($argument['keyword'])) { 157 $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $argument['keyword'])); 158 if (isset($contexts[ctools_context_id($argument, 'argument')])) { 159 foreach (ctools_context_get_converters('%' . $argument['keyword'] . ':', $contexts[ctools_context_id($argument, 'argument')]) as $keyword => $title) { 160 $desc .= '<br />' . t('@keyword --> @title', array('@keyword' => $keyword, '@title' => $title)); 161 } 162 } 163 $desc .= '</div>'; 164 } 165 $output .= '<td>' . $desc . '</td>'; 166 $output .= '</tr>'; 167 $titles[ctools_context_id($argument, 'argument')] = $argument['identifier']; 168 $count++; 169 } 170 } 171 172 $count = 1; 173 // Then, make a nice list of contexts. 174 if (!empty($object->contexts)) { 175 foreach ($object->contexts as $context) { 176 $output .= '<tr>'; 177 $output .= '<td valign="top"><em>' . t('Context @count', array('@count' => $count)) . '</em></td>'; 178 $desc = check_plain($context['identifier']); 179 if (isset($context['keyword'])) { 180 $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context['keyword'])); 181 foreach (ctools_context_get_converters('%' . $context['keyword'] . ':', $contexts[ctools_context_id($context, 'context')]) as $keyword => $title) { 182 $desc .= '<br />' . t('@keyword --> @title', array('@keyword' => $keyword, '@title' => $title)); 183 } 184 $desc .= '</div>'; 185 } 186 $output .= '<td>' . $desc . '</td>'; 187 $output .= '</tr>'; 188 $titles[ctools_context_id($context)] = $context['identifier']; 189 $count++; 190 } 191 } 192 193 // And relationships 194 if (!empty($object->relationships)) { 195 foreach ($object->relationships as $relationship) { 196 $output .= '<tr>'; 197 if (is_array($relationship['context'])) { 198 $rtitles = array(); 199 foreach ($relationship['context'] as $cid) { 200 $rtitles[$cid] = $titles[$cid]; 201 } 202 $title = implode(' + ', $rtitles); 203 } 204 else { 205 $title = $titles[$relationship['context']]; 206 } 207 $output .= '<td valign="top"><em>' . t('From "@title"', array('@title' => $title)) . '</em></td>'; 208 $desc = check_plain($relationship['identifier']); 209 if (isset($relationship['keyword'])) { 210 $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $relationship['keyword'])); 211 foreach (ctools_context_get_converters('%' . $relationship['keyword'] . ':', $contexts[ctools_context_id($relationship, 'relationship')]) as $keyword => $title) { 212 $desc .= '<br />' . t('@keyword --> @title', array('@keyword' => $keyword, '@title' => $title)); 213 } 214 $desc .= '</div>'; 215 } 216 $output .= '<td>' . $desc . '</td>'; 217 $output .= '</tr>'; 218 $titles[ctools_context_id($relationship, 'relationship')] = $relationship['identifier']; 219 $count++; 220 } 221 } 222 223 $head = ''; 224 if ($header) { 225 if ($description) { 226 $header .= '<div class="description">' . $description . '</div>'; 227 } 228 $head .= '<thead><tr>'; 229 $head .= '<th colspan="2">' . $header . '</th>'; 230 $head .= '</tr></thead>'; 231 } 232 233 return $output ? "<table>$head<tbody>$output</tbody></table>\n" : "<table>$head</table>\n"; 234 } 235 236 /** 237 * ctools_context_list() but not in a table format because tabledrag 238 * won't let us have tables within tables and still drag. 239 */ 240 function theme_ctools_context_list_no_table($object) { 241 ctools_add_css('context'); 242 $titles = array(); 243 $output = ''; 244 $count = 1; 245 // Describe 'built in' contexts. 246 if (!empty($object->base_contexts)) { 247 foreach ($object->base_contexts as $id => $context) { 248 $output .= '<div class="ctools-context-holder clear-block">'; 249 $output .= '<div class="ctools-context-title">' . t('Built in context') . '</div>'; 250 $desc = check_plain($context->identifier); 251 if (isset($context->keyword)) { 252 $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context->keyword)) . '</div>'; 253 } 254 if (isset($context->description)) { 255 $desc .= '<div class="description">' . filter_xss_admin($context->description) . '</div>'; 256 } 257 $output .= '<div class="ctools-context-content">' . $desc . '</div>'; 258 $output .= '</div>'; 259 $titles[$id] = $context->identifier; 260 $count++; 261 } 262 } 263 264 // First, make a list of arguments. Arguments are pretty simple. 265 if (!empty($object->arguments)) { 266 foreach ($object->arguments as $argument) { 267 $output .= '<div class="ctools-context-holder clear-block">'; 268 $output .= '<div class="ctools-context-title">' . t('Argument @count', array('@count' => $count)) . '</div>'; 269 $desc = check_plain($argument['identifier']); 270 if (isset($argument['keyword'])) { 271 $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $argument['keyword'])) . '</div>'; 272 } 273 $output .= '<div class="ctools-context-content">' . $desc . '</div>'; 274 $output .= '</div>'; 275 $titles[ctools_context_id($argument, 'argument')] = $argument['identifier']; 276 $count++; 277 } 278 } 279 $count = 1; 280 // Then, make a nice list of contexts. 281 if (!empty($object->contexts)) { 282 foreach ($object->contexts as $context) { 283 $output .= '<div class="ctools-context-holder clear-block">'; 284 $output .= '<div class="ctools-context-title">' . t('Context @count', array('@count' => $count)) . '</div>'; 285 $desc = check_plain($context['identifier']); 286 if (isset($context['keyword'])) { 287 $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $context['keyword'])) . '</div>'; 288 } 289 $output .= '<div class="ctools-context-content">' . $desc . '</div>'; 290 $output .= '</div>'; 291 $titles[ctools_context_id($context)] = $context['identifier']; 292 $count++; 293 } 294 } 295 // And relationships 296 if (!empty($object->relationships)) { 297 foreach ($object->relationships as $relationship) { 298 $output .= '<div class="ctools-context-holder clear-block">'; 299 if (is_array($relationship['context'])) { 300 $rtitles = array(); 301 foreach ($relationship['context'] as $cid) { 302 $rtitles[$cid] = $titles[$cid]; 303 } 304 $title = implode(' + ', $rtitles); 305 } 306 else { 307 $title = $titles[$relationship['context']]; 308 } 309 310 $output .= '<div class="ctools-context-title">' . t('From "@title"', array('@title' => $title)) . '</div>'; 311 $desc = check_plain($relationship['identifier']); 312 if (isset($relationship['keyword'])) { 313 $desc .= '<div class="description">' . t('Keyword: %@keyword', array('@keyword' => $relationship['keyword'])) . '</div>'; 314 } 315 $output .= '<div class="ctools-context-content">' . $desc . '</div>'; 316 $output .= '</div>'; 317 $titles[ctools_context_id($relationship, 'relationship')] = $relationship['identifier']; 318 $count++; 319 } 320 } 321 322 return $output; 323 } 324
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 |