| 1 |
<?php
|
| 2 |
/* $Id: template.php,v 1.26 2008/09/15 20:15:19 robinmonks Exp $ */
|
| 3 |
|
| 4 |
/*
|
| 5 |
we need a much more robust hyphenation algorithm
|
| 6 |
(i.e. to cut URLs off at the slashes)!
|
| 7 |
*/
|
| 8 |
function _civicspace_word_split($text, $max_char = 30) {
|
| 9 |
return preg_replace('/((?:[^ &]|&[^;]+;){' . $max_char . '})(?=[^ ])/u', '\1<wbr />', $text[0]);
|
| 10 |
}
|
| 11 |
|
| 12 |
function civicspace_word_split($text) {
|
| 13 |
return substr(preg_replace_callback('/>[^<]+</', '_civicspace_word_split', '>'. $text .'<'), 1, -1);
|
| 14 |
}
|
| 15 |
|
| 16 |
/* Checks to see if we're in the admin section */
|
| 17 |
function civicspace_is_admin() {
|
| 18 |
if ((arg(0) == 'admin') && (user_access('access administration pages'))) {
|
| 19 |
return true;
|
| 20 |
}
|
| 21 |
}
|
| 22 |
|
| 23 |
/* Generates path to style; similar to path_to_theme() */
|
| 24 |
function civicspace_path_to_style() {
|
| 25 |
global $theme_key;
|
| 26 |
$themes = list_themes();
|
| 27 |
return dirname($themes[$theme_key]->filename);
|
| 28 |
}
|
| 29 |
|
| 30 |
/* generates a list of body classes for bad-ass per-page CSS hacking */
|
| 31 |
function civicspace_get_body_classes($sidebar_left, $sidebar_right) {
|
| 32 |
global $node;
|
| 33 |
|
| 34 |
$body_classes = array();
|
| 35 |
|
| 36 |
if (strlen($sidebar_left) && strlen($sidebar_right)) {
|
| 37 |
$body_classes[] = 'three-column';
|
| 38 |
}
|
| 39 |
else if (strlen($sidebar_left)) {
|
| 40 |
$body_classes[] = 'two-column';
|
| 41 |
}
|
| 42 |
else if (strlen($sidebar_right)) {
|
| 43 |
$body_classes[] = 'two-column-right';
|
| 44 |
}
|
| 45 |
else {
|
| 46 |
$body_classes[] = 'one-column';
|
| 47 |
}
|
| 48 |
|
| 49 |
if ($_GET['q'] == variable_get('site_frontpage', 'node')) {
|
| 50 |
$body_classes[] = 'home';
|
| 51 |
}
|
| 52 |
|
| 53 |
if (arg(1)) {
|
| 54 |
$body_classes[] = check_plain(arg(0)) . '-' . check_plain(arg(1));
|
| 55 |
}
|
| 56 |
if (isset($node->type)) {
|
| 57 |
$body_classes[] = $node->type;
|
| 58 |
}
|
| 59 |
$path_class = explode('/', drupal_get_path_alias(check_plain($_GET['q'])));
|
| 60 |
$body_classes[] = reset($path_class);
|
| 61 |
$body_classes[] = preg_replace('/-\d+/', '', str_replace('/', '-', check_plain($_GET['q'])));
|
| 62 |
$body_classes[] = 'page-' . str_replace('/', '-', check_plain($_GET['q']));
|
| 63 |
|
| 64 |
return $body_classes;
|
| 65 |
}
|
| 66 |
|
| 67 |
/**
|
| 68 |
* =Comments
|
| 69 |
*/
|
| 70 |
|
| 71 |
function phptemplate_comment_view($comment, $links = '', $visible = 1) {
|
| 72 |
|
| 73 |
// Emit selectors:
|
| 74 |
$output = '';
|
| 75 |
global $comment_new;
|
| 76 |
if (($comment->new = node_mark($comment->nid, $comment->timestamp)) != MARK_READ && !$comment_new) {
|
| 77 |
$output .= "<a id=\"new\"></a>\n";
|
| 78 |
$comment_new = TRUE;
|
| 79 |
}
|
| 80 |
|
| 81 |
if (@$comment->cid) {
|
| 82 |
$output .= "<a id=\"comment-$comment->cid\"></a>\n";
|
| 83 |
}
|
| 84 |
|
| 85 |
// Switch to folded/unfolded view of the comment
|
| 86 |
if ($visible) {
|
| 87 |
$comment->comment = check_output($comment->comment, $comment->format);
|
| 88 |
$output .= theme('comment', $comment, $links);
|
| 89 |
}
|
| 90 |
else {
|
| 91 |
$output .= theme('comment_folded', $comment);
|
| 92 |
}
|
| 93 |
|
| 94 |
return $output;
|
| 95 |
}
|
| 96 |
|
| 97 |
function phptemplate_comment_form($edit, $title) {
|
| 98 |
global $user;
|
| 99 |
|
| 100 |
$form .= "<a id=\"comment\"></a>\n";
|
| 101 |
|
| 102 |
// contact information:
|
| 103 |
if ($user->uid) {
|
| 104 |
$form .= form_item(t('Your name'), format_name($user));
|
| 105 |
}
|
| 106 |
else if (variable_get('comment_anonymous', 0) == 1) {
|
| 107 |
$form .= form_textfield(t('Your name'), 'name', $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous') , 20, 60);
|
| 108 |
$form .= form_textfield(t('E-mail'), 'mail', $edit['mail'], 20, 64, t('The content of this field is kept private and will not be shown publicly.'));
|
| 109 |
$form .= form_textfield(t('Homepage'), 'homepage', $edit['homepage'], 20, 255);
|
| 110 |
}
|
| 111 |
else if (variable_get('comment_anonymous', 0) == 2) {
|
| 112 |
$form .= form_textfield(t('Your name'), 'name', $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous') , 20, 60, NULL, NULL, TRUE);
|
| 113 |
$form .= form_textfield(t('E-mail'), 'mail', $edit['mail'], 20, 64, t('The content of this field is kept private and will not be shown publicly.'), NULL, TRUE);
|
| 114 |
$form .= form_textfield(t('Homepage'), 'homepage', $edit['homepage'], 20, 255);
|
| 115 |
}
|
| 116 |
|
| 117 |
// subject field:
|
| 118 |
if (variable_get('comment_subject_field', 1)) {
|
| 119 |
$form .= form_textfield(t('Subject'), 'subject', $edit['subject'], 50, 64);
|
| 120 |
}
|
| 121 |
|
| 122 |
// comment field:
|
| 123 |
$form .= form_textarea(t('Comment'), 'comment', $edit['comment'] ? $edit['comment'] : $user->signature, 70, 10, '', NULL, TRUE);
|
| 124 |
|
| 125 |
// format selector
|
| 126 |
$form .= filter_form('format', $edit['format']);
|
| 127 |
|
| 128 |
// preview button:
|
| 129 |
$form .= form_hidden('cid', $edit['cid']);
|
| 130 |
$form .= form_hidden('pid', $edit['pid']);
|
| 131 |
$form .= form_hidden('nid', $edit['nid']);
|
| 132 |
|
| 133 |
$form .= form_submit(t('Preview comment'));
|
| 134 |
|
| 135 |
// Only show post button if preview is optional or if we are in preview mode.
|
| 136 |
// We show the post button in preview mode even if there are form errors so that
|
| 137 |
// optional form elements (e.g., captcha) can be updated in preview mode.
|
| 138 |
if (!variable_get('comment_preview', 1) || ($_POST['op'] == t('Preview comment')) || ($_POST['op'] == t('Post comment'))) {
|
| 139 |
$form .= form_submit(t('Post comment'));
|
| 140 |
}
|
| 141 |
|
| 142 |
return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid'])));
|
| 143 |
}
|
| 144 |
|
| 145 |
function phptemplate_comment_thread_min($comment, $threshold, $pid = 0) {
|
| 146 |
if (comment_visible($comment, $threshold)) {
|
| 147 |
/* padding instead of margin to keep IE sane */
|
| 148 |
$output = '<div style="padding-left:'. ($comment->depth * 20) ."px;\">\n";
|
| 149 |
$output .= theme('comment_view', $comment, '', 0);
|
| 150 |
$output .= "</div>\n";
|
| 151 |
}
|
| 152 |
return $output;
|
| 153 |
}
|
| 154 |
|
| 155 |
function phptemplate_comment_thread_max($comment, $threshold, $level = 0) {
|
| 156 |
$output = '';
|
| 157 |
if ($comment->depth) {
|
| 158 |
/* padding instead of margin to keep IE sane */
|
| 159 |
$output .= '<div style="padding-left:'. ($comment->depth * 20) ."px;\">\n";
|
| 160 |
}
|
| 161 |
|
| 162 |
$output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)), comment_visible($comment, $threshold));
|
| 163 |
|
| 164 |
if ($comment->depth) {
|
| 165 |
$output .= "</div>\n";
|
| 166 |
}
|
| 167 |
|
| 168 |
return $output;
|
| 169 |
}
|
| 170 |
|
| 171 |
function _phptemplate_variables($hook, $vars) {
|
| 172 |
$vars = array();
|
| 173 |
if ($hook == 'page') {
|
| 174 |
foreach (array('primary', 'secondary') as $type) {
|
| 175 |
//Get the data to populate the textfields, if the variable is not an array .. try to parse the old-style link format.
|
| 176 |
$value = variable_get('phptemplate_'. $type .'_links', array());
|
| 177 |
//Get the amount of links to show, possibly expanding if there are more links defined than the count specifies.
|
| 178 |
$count = variable_get('phptemplate_'. $type .'_link_count', 5);
|
| 179 |
$count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']);
|
| 180 |
if (theme_get_setting('toggle_'. $type .'_links')) {
|
| 181 |
for ($i =0; $i < $count; $i++) {
|
| 182 |
unset($attributes);
|
| 183 |
if (!empty($value['text'][$i])) {
|
| 184 |
if (!empty($value['description'][$i])) {
|
| 185 |
$attributes['title'] = $value['description'][$i];
|
| 186 |
}
|
| 187 |
//Custom attribute, class='first' if first anchor...
|
| 188 |
if ($i == 0) {
|
| 189 |
$attributes['class'] = 'first';
|
| 190 |
}
|
| 191 |
$links[$type][] = l($value['text'][$i], $value['link'][$i], $attributes);
|
| 192 |
$vars[$type . '_links'] = $links[$type];
|
| 193 |
}
|
| 194 |
}
|
| 195 |
}
|
| 196 |
}
|
| 197 |
// Set admin theme
|
| 198 |
if (civicspace_is_admin()) {
|
| 199 |
$vars['template_file'] = 'page_admin';
|
| 200 |
}
|
| 201 |
}
|
| 202 |
return $vars;
|
| 203 |
}
|
| 204 |
|
| 205 |
function phptemplate_item_list($items = array(), $title = NULL) {
|
| 206 |
$output = '<div class="item-list">' ."\n";
|
| 207 |
if (isset($title)) {
|
| 208 |
$output .= '<h3>'. $title .'</h3>'."\n";
|
| 209 |
}
|
| 210 |
|
| 211 |
if (isset($items)) {
|
| 212 |
$output .= '<ul>'."\n";
|
| 213 |
foreach ($items as $item) {
|
| 214 |
static $class;
|
| 215 |
$class += 1;
|
| 216 |
$alt = ($class % 2 == 1) ? ' ': ' class="alt"';
|
| 217 |
$output .= "<li$alt>$item</li>\n";
|
| 218 |
}
|
| 219 |
$output .= '</ul>'."\n";
|
| 220 |
}
|
| 221 |
$output .= '</div>'."\n";
|
| 222 |
return $output;
|
| 223 |
}
|
| 224 |
|
| 225 |
/* Return a themed submenu, typically displayed under the tabs. */
|
| 226 |
function phptemplate_submenu($links) {
|
| 227 |
return '<div class="submenu">'. implode(' | ', $links) .'</div>';
|
| 228 |
}
|
| 229 |
|
| 230 |
|
| 231 |
/**
|
| 232 |
* =Messages
|
| 233 |
*/
|
| 234 |
/* altered to always output a list of messages, even if only one message is returned */
|
| 235 |
function phptemplate_status_messages() {
|
| 236 |
if ($data = drupal_get_messages()) {
|
| 237 |
$output = '';
|
| 238 |
foreach ($data as $type => $messages) {
|
| 239 |
$output .= "<div class=\"$type\">\n";
|
| 240 |
$theme_path = path_to_theme();
|
| 241 |
// output an image
|
| 242 |
if ($type == 'error') {
|
| 243 |
$output .= '<img src="'. $theme_path .'/images/icon_error.png" alt="Error icon" class="icon-error" />' ."\n";
|
| 244 |
}
|
| 245 |
else if ($type == 'status') {
|
| 246 |
$output .= '<img src="'. $theme_path .'/images/icon_status.png" alt="Status icon" class="icon-status" />' ."\n";
|
| 247 |
}
|
| 248 |
$output .= " <div class=\"content\">\n";
|
| 249 |
if (count($messages) > 1) {
|
| 250 |
$output .= " <ul>\n";
|
| 251 |
foreach($messages as $message) {
|
| 252 |
$output .= ' <li>'. $message ."</li>\n";
|
| 253 |
}
|
| 254 |
$output .= " </ul>\n";
|
| 255 |
}
|
| 256 |
else {
|
| 257 |
$output .= $messages[0] ."\n";
|
| 258 |
}
|
| 259 |
$output .= " </div>\n";
|
| 260 |
$output .= "</div>\n";
|
| 261 |
}
|
| 262 |
|
| 263 |
return $output;
|
| 264 |
}
|
| 265 |
}
|
| 266 |
|
| 267 |
/**
|
| 268 |
* =Error messages
|
| 269 |
*/
|
| 270 |
function phptemplate_error($message) {
|
| 271 |
$output = '';
|
| 272 |
$output .= '<div class="error">';
|
| 273 |
$output .= ' <img src="'. path_to_theme() .'/images/icon_error.png" alt="Error icon" class="icon icon-error" />';
|
| 274 |
$output .= " <div class=\"content\">\n";
|
| 275 |
$output .= $message;
|
| 276 |
$output .= " </div>\n";
|
| 277 |
$output .= "</div>\n";
|
| 278 |
return $output;
|
| 279 |
}
|
| 280 |
|
| 281 |
/**
|
| 282 |
* =Confirmation
|
| 283 |
*/
|
| 284 |
function phptemplate_confirm($question, $path, $description = NULL, $yes = NULL, $no = NULL, $extra = NULL, $name = 'confirm') {
|
| 285 |
drupal_set_title($question);
|
| 286 |
|
| 287 |
if (is_null($description)) {
|
| 288 |
$description = t('This action cannot be undone.');
|
| 289 |
}
|
| 290 |
|
| 291 |
$output .= '<p>'. $description ."</p>\n";
|
| 292 |
if (!is_null($extra)) {
|
| 293 |
$output .= $extra;
|
| 294 |
}
|
| 295 |
$output .= '<div class="container-inline">';
|
| 296 |
$output .= form_submit($yes ? $yes : t('Confirm'));
|
| 297 |
$output .= '<span class="cancel-link">'. l($no ? $no : t('Cancel and go back'), $path) .'</span>';
|
| 298 |
$output .= "</div>\n";
|
| 299 |
|
| 300 |
$output .= form_hidden($name, 1);
|
| 301 |
return form($output, 'post', NULL, array('class' => 'confirmation'));
|
| 302 |
}
|
| 303 |
|
| 304 |
/**
|
| 305 |
* =Table formating
|
| 306 |
*/
|
| 307 |
function phptemplate_table($header, $rows, $attributes = array()) {
|
| 308 |
|
| 309 |
$output = '<div class="table-wrapper">'. "\n" .'<table'. drupal_attributes($attributes) .">\n";
|
| 310 |
|
| 311 |
// Format the table header:
|
| 312 |
if (is_array($header)) {
|
| 313 |
$ts = tablesort_init($header);
|
| 314 |
$output .= ' <tr>';
|
| 315 |
foreach ($header as $cell) {
|
| 316 |
$cell = tablesort_header($cell, $header, $ts);
|
| 317 |
$output .= _phptemplate_table_cell($cell, 1);
|
| 318 |
}
|
| 319 |
$output .= " </tr>\n";
|
| 320 |
}
|
| 321 |
|
| 322 |
// Format the table rows:
|
| 323 |
if (is_array($rows)) {
|
| 324 |
foreach ($rows as $number => $row) {
|
| 325 |
$attributes = array();
|
| 326 |
|
| 327 |
// Check if we're dealing with a simple or complex row
|
| 328 |
if (isset($row['data'])) {
|
| 329 |
foreach ($row as $key => $value) {
|
| 330 |
if ($key == 'data') {
|
| 331 |
$cells = $value;
|
| 332 |
}
|
| 333 |
else {
|
| 334 |
$attributes[$key] = $value;
|
| 335 |
}
|
| 336 |
}
|
| 337 |
}
|
| 338 |
else {
|
| 339 |
$cells = $row;
|
| 340 |
}
|
| 341 |
|
| 342 |
// Modified for simpler alternating classes
|
| 343 |
if ($number % 2) {
|
| 344 |
if (isset($attributes['class'])) {
|
| 345 |
$attributes['class'] .= ' alt';
|
| 346 |
}
|
| 347 |
else {
|
| 348 |
$attributes['class'] = 'alt';
|
| 349 |
}
|
| 350 |
}
|
| 351 |
|
| 352 |
// Build row
|
| 353 |
$output .= ' <tr'. drupal_attributes($attributes) .'>' ."\n";
|
| 354 |
$i = 0;
|
| 355 |
foreach ($cells as $cell) {
|
| 356 |
$cell = tablesort_cell($cell, $header, $ts, $i++);
|
| 357 |
$output .= _phptemplate_table_cell($cell, 0); // internal call
|
| 358 |
}
|
| 359 |
$output .= " </tr>\n";
|
| 360 |
}
|
| 361 |
}
|
| 362 |
|
| 363 |
$output .= "</table>\n</div>\n\n";
|
| 364 |
return $output;
|
| 365 |
}
|
| 366 |
|
| 367 |
function _phptemplate_table_cell($cell, $header = 0) {
|
| 368 |
$attributes = '';
|
| 369 |
|
| 370 |
if (is_array($cell)) {
|
| 371 |
$data = $cell['data'];
|
| 372 |
foreach ($cell as $key => $value) {
|
| 373 |
if ($key != 'data') {
|
| 374 |
$attributes .= " $key=\"$value\"";
|
| 375 |
}
|
| 376 |
}
|
| 377 |
}
|
| 378 |
else {
|
| 379 |
$data = $cell;
|
| 380 |
}
|
| 381 |
|
| 382 |
if ($header) {
|
| 383 |
$output = " <th$attributes>\n$data\n </th>\n";
|
| 384 |
}
|
| 385 |
else {
|
| 386 |
$output = " <td$attributes>\n$data\n </td>\n";
|
| 387 |
}
|
| 388 |
|
| 389 |
return $output;
|
| 390 |
}
|
| 391 |
|
| 392 |
/**
|
| 393 |
* =Pager
|
| 394 |
*/
|
| 395 |
function phptemplate_pager($tags = array(), $limit = 10, $element = 0, $attributes = array()) {
|
| 396 |
global $pager_total;
|
| 397 |
$output = '';
|
| 398 |
|
| 399 |
if ($pager_total[$element] > $limit) {
|
| 400 |
$total_row_count = '';
|
| 401 |
if ($pager_total[$element] > 1000000) {
|
| 402 |
$total_row_count = 'millions';
|
| 403 |
}
|
| 404 |
else if ($pager_total[$element] > 1000) {
|
| 405 |
$total_row_count = 'thousands';
|
| 406 |
}
|
| 407 |
else {
|
| 408 |
$total_row_count = $pager_total[$element];
|
| 409 |
}
|
| 410 |
$output .= '<div id="pager">' ."\n";
|
| 411 |
$output .= theme('pager_first', ($tags[0] ? $tags[0] : t('« First')), $limit, $element, $attributes);
|
| 412 |
$output .= theme('pager_previous', ($tags[1] ? $tags[1] : t('‹ Previous')), $limit, $element, 1, $attributes);
|
| 413 |
$output .= phptemplate_pager_detail($limit, $element, 'Showing <span class="pager-record-count">%d - %d</span> of <span class="pager-total">'. $total_row_count .'</span>.');
|
| 414 |
$output .= theme('pager_next', ($tags[3] ? $tags[3] : t('Next ›')), $limit, $element, 1, $attributes);
|
| 415 |
$output .= theme('pager_last', ($tags[4] ? $tags[4] : t('Last »')), $limit, $element, $attributes);
|
| 416 |
$output .= "\n</div>";
|
| 417 |
|
| 418 |
return $output;
|
| 419 |
}
|
| 420 |
}
|
| 421 |
|
| 422 |
function phptemplate_pager_next($text, $limit, $element = 0, $interval = 1, $attributes = array()) {
|
| 423 |
global $pager_from_array, $pager_total;
|
| 424 |
$from_new = pager_load_array(((int)$pager_from_array[$element] + ((int)$limit * (int)$interval)), $element, $pager_from_array);
|
| 425 |
if ($from_new[$element] < $pager_total[$element]) {
|
| 426 |
$output .= ' <a href="'. pager_link($from_new, $element, $attributes) .'">'. $text .'</a>'."\n";
|
| 427 |
}
|
| 428 |
else {
|
| 429 |
$output .= ' ';
|
| 430 |
}
|
| 431 |
return $output;
|
| 432 |
}
|
| 433 |
|
| 434 |
function phptemplate_pager_previous($text, $limit, $element = 0, $interval = 1, $attributes = array()) {
|
| 435 |
global $pager_from_array;
|
| 436 |
$from_new = pager_load_array(((int)$pager_from_array[$element] - ((int)$limit * (int)$interval)), $element, $pager_from_array);
|
| 437 |
if ($from_new[$element] < 1) {
|
| 438 |
$output .= theme('pager_first', $text, $limit, $element, $attributes);
|
| 439 |
}
|
| 440 |
else {
|
| 441 |
$output .= '<a href="'. pager_link($from_new, $element, $attributes) .'">'. $text .'</a>';
|
| 442 |
}
|
| 443 |
return $output;
|
| 444 |
}
|
| 445 |
|
| 446 |
function phptemplate_pager_first($text, $limit, $element = 0, $attributes = array()) {
|
| 447 |
global $pager_from_array;
|
| 448 |
|
| 449 |
if ((($pager_from_array[$element] > 0) && ($pager_from_array[$element] <= $limit*2))) {
|
| 450 |
$output .= '<a href="'. pager_link(pager_load_array(0, $element, $pager_from_array), $element, $attributes) .'">'. $text .'</a>';
|
| 451 |
}
|
| 452 |
else {
|
| 453 |
$output .= ' ';
|
| 454 |
}
|
| 455 |
return $output;
|
| 456 |
}
|
| 457 |
|
| 458 |
function phptemplate_pager_last($text, $limit, $element = 0, $attributes = array()) {
|
| 459 |
global $pager_from_array, $pager_total;
|
| 460 |
|
| 461 |
// calculate how many items are on the last page
|
| 462 |
$last_num = (($pager_total[$element] % $limit) ? ($pager_total[$element] % $limit) : $limit);
|
| 463 |
// fetch pager array of pages starting from the beginning of the last page
|
| 464 |
$from_new = pager_load_array(($pager_total[$element] - $last_num), $element, $pager_from_array);
|
| 465 |
|
| 466 |
if ($from_new[$element] < ($pager_from_array[$element] + $limit)) {
|
| 467 |
$output .= theme('pager_next', $text, $limit, $element, 1, $attributes);
|
| 468 |
}
|
| 469 |
else if (($from_new[$element] > $pager_from_array[$element]) && ($from_new[$element] > 0) && ($from_new[$element] < $pager_total[$element])) {
|
| 470 |
$output .= ' <a href="'. pager_link($from_new, $element, $attributes) .'">'. $text .'</a>';
|
| 471 |
}
|
| 472 |
else {
|
| 473 |
$output .= ' ';
|
| 474 |
}
|
| 475 |
return $output;
|
| 476 |
}
|
| 477 |
|
| 478 |
function phptemplate_pager_detail($limit, $element = 0, $format = '%d - %d of %d.') {
|
| 479 |
global $pager_from_array, $pager_total;
|
| 480 |
|
| 481 |
$output = '<div class="pager-detail">'. "\n";
|
| 482 |
if ($pager_total[$element] > (int)$pager_from_array[$element] + 1) {
|
| 483 |
$output .= sprintf(t($format), (int)$pager_from_array[$element] + 1, ((int)$pager_from_array[$element] + $limit <= $pager_total[$element] ? (int)$pager_from_array[$element] + $limit : $pager_total[$element]), $pager_total[$element]);
|
| 484 |
}
|
| 485 |
$output .= '</div>';
|
| 486 |
|
| 487 |
return $output;
|
| 488 |
}
|
| 489 |
|
| 490 |
/**
|
| 491 |
* =Forums
|
| 492 |
*/
|
| 493 |
function phptemplate_forum_list($forums, $parents, $tid) {
|
| 494 |
global $user;
|
| 495 |
|
| 496 |
if ($forums) {
|
| 497 |
|
| 498 |
$header = array(t('Forum'), t('Topics'), t('Posts'), t('Last post'));
|
| 499 |
|
| 500 |
foreach ($forums as $forum) {
|
| 501 |
if ($forum->container) {
|
| 502 |
$description = '<div style="padding-left: '. ($forum->depth * 20) ."px;\">\n";
|
| 503 |
$description .= ' <div class="name">'. "\n". l($forum->name, "forum/$forum->tid") ."\n</div>\n";
|
| 504 |
|
| 505 |
if ($forum->description) {
|
| 506 |
$description .= " <div class=\"description\">\n $forum->description\n</div>\n";
|
| 507 |
}
|
| 508 |
$description .= "</div>\n";
|
| 509 |
|
| 510 |
$rows[] = array(array('data' => $description, 'class' => 'container', 'colspan' => '4'));
|
| 511 |
}
|
| 512 |
else {
|
| 513 |
$forum->old_topics = _forum_topics_read($forum->tid, $user->uid);
|
| 514 |
if ($user->uid) {
|
| 515 |
$new_topics = $forum->num_topics - $forum->old_topics;
|
| 516 |
}
|
| 517 |
else {
|
| 518 |
$new_topics = 0;
|
| 519 |
}
|
| 520 |
|
| 521 |
$description = '<div style="padding-left: '. ($forum->depth * 20) ."px;\">\n";
|
| 522 |
$description .= ' <div class="name">'. l($forum->name, "forum/$forum->tid") ."</div>\n";
|
| 523 |
|
| 524 |
if ($forum->description) {
|
| 525 |
$description .= " <div class=\"description\">$forum->description</div>\n";
|
| 526 |
}
|
| 527 |
$description .= "</div>\n";
|
| 528 |
|
| 529 |
// I would like to add a link to the most recent post in the fourth column, but this is not possible
|
| 530 |
// See: http://drupal.org/node/23251
|
| 531 |
|
| 532 |
$rows[] = array(
|
| 533 |
array('data' => $description, 'class' => 'forum'),
|
| 534 |
array('data' => $forum->num_topics . ($new_topics ? '<br />'. l(t('%a new', array('%a' => $new_topics)), "forum/$forum->tid", NULL, NULL, 'new') : ''), 'class' => 'topics'),
|
| 535 |
array('data' => $forum->num_posts, 'class' => 'posts'),
|
| 536 |
array('data' => _phptemplate_forum_format($forum->last_post), 'class' => 'last-reply'));
|
| 537 |
}
|
| 538 |
}
|
| 539 |
|
| 540 |
return theme('table', $header, $rows);
|
| 541 |
|
| 542 |
}
|
| 543 |
|
| 544 |
}
|
| 545 |
|
| 546 |
function phptemplate_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_per_page) {
|
| 547 |
global $user;
|
| 548 |
// forum list, topics list, topic browser and 'add new topic' link
|
| 549 |
|
| 550 |
$vocabulary = taxonomy_get_vocabulary(variable_get('forum_nav_vocabulary', ''));
|
| 551 |
$title = $vocabulary->name;
|
| 552 |
|
| 553 |
// Breadcrumb navigation:
|
| 554 |
$breadcrumb = array();
|
| 555 |
if ($tid) {
|
| 556 |
$breadcrumb[] = array('path' => 'forum', 'title' => $title);
|
| 557 |
}
|
| 558 |
|
| 559 |
if ($parents) {
|
| 560 |
$parents = array_reverse($parents);
|
| 561 |
foreach ($parents as $p) {
|
| 562 |
if ($p->tid == $tid) {
|
| 563 |
$title = $p->name;
|
| 564 |
}
|
| 565 |
else {
|
| 566 |
$breadcrumb[] = array('path' => 'forum/'. $p->tid, 'title' => $p->name);
|
| 567 |
}
|
| 568 |
}
|
| 569 |
}
|
| 570 |
|
| 571 |
drupal_set_title($title);
|
| 572 |
|
| 573 |
$breadcrumb[] = array('path' => $_GET['q']);
|
| 574 |
menu_set_location($breadcrumb);
|
| 575 |
|
| 576 |
/*
|
| 577 |
This should use menu_local_tasks for these options
|
| 578 |
*/
|
| 579 |
|
| 580 |
if (count($forums) || count($parents)) {
|
| 581 |
$output = '<div id="forum">';
|
| 582 |
$output .= '<ul>';
|
| 583 |
|
| 584 |
if (module_exist('tracker')) {
|
| 585 |
if ($user->uid) {
|
| 586 |
$output .= ' <li>'. l(t('My forum discussions.'), "tracker/$user->uid") .'</li>';
|
| 587 |
}
|
| 588 |
|
| 589 |
$output .= ' <li>'. l(t('Active forum discussions.'), 'tracker') .'</li>';
|
| 590 |
}
|
| 591 |
|
| 592 |
if (user_access('create forum topics')) {
|
| 593 |
$output .= '<li>'. l(t('Post new forum topic.'), "node/add/forum/$tid") .'</li>';
|
| 594 |
}
|
| 595 |
else if ($user->uid) {
|
| 596 |
$output .= '<li>'. t('You are not allowed to post a new forum topic.') .'</li>';
|
| 597 |
}
|
| 598 |
else {
|
| 599 |
$output .= '<li>'. t('<a href="%login">Login</a> to post a new forum topic.', array('%login' => url('user/login'))) .'</li>';
|
| 600 |
}
|
| 601 |
$output .= '</ul>';
|
| 602 |
|
| 603 |
$output .= theme('forum_list', $forums, $parents, $tid);
|
| 604 |
|
| 605 |
if ($tid && !in_array($tid, variable_get('forum_containers', array()))) {
|
| 606 |
drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url('taxonomy/term/'. $tid .'/0/feed') .'" />');
|
| 607 |
|
| 608 |
$output .= theme('forum_topic_list', $tid, $topics, $sortby, $forum_per_page);
|
| 609 |
$output .= theme('xml_icon', url("taxonomy/term/$tid/0/feed"));
|
| 610 |
}
|
| 611 |
$output .= '</div>';
|
| 612 |
}
|
| 613 |
else {
|
| 614 |
drupal_set_title(t('No forums defined'));
|
| 615 |
$output = '';
|
| 616 |
}
|
| 617 |
|
| 618 |
return $output;
|
| 619 |
}
|
| 620 |
|
| 621 |
function phptemplate_forum_topic_list($tid, $topics, $sortby, $forum_per_page) {
|
| 622 |
global $forum_topic_list_header;
|
| 623 |
|
| 624 |
if ($topics) {
|
| 625 |
|
| 626 |
foreach ($topics as $topic) {
|
| 627 |
// folder is new if topic is new or there are new comments since last visit
|
| 628 |
if ($topic->tid != $tid) {
|
| 629 |
$rows[] = array(
|
| 630 |
array('data' => _forum_icon($topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
|
| 631 |
array('data' => check_plain($topic->title), 'class' => 'title'),
|
| 632 |
array('data' => l(t('This topic has been moved'), "forum/$topic->tid"), 'colspan' => '3')
|
| 633 |
);
|
| 634 |
}
|
| 635 |
else {
|
| 636 |
$rows[] = array(
|
| 637 |
array('data' => _forum_icon($topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
|
| 638 |
array('data' => l($topic->title, "node/$topic->nid"), 'class' => 'topic'),
|
| 639 |
array('data' => $topic->num_comments . ($topic->new_replies ? '<br />'. l(t('%a new', array('%a' => $topic->new_replies)), "node/$topic->nid", NULL, NULL, 'new') : ''), 'class' => 'replies'),
|
| 640 |
array('data' => _phptemplate_forum_format($topic), 'class' => 'created'),
|
| 641 |
array('data' => _phptemplate_forum_format($topic->last_reply), 'class' => 'last-reply')
|
| 642 |
);
|
| 643 |
}
|
| 644 |
}
|
| 645 |
|
| 646 |
if ($pager = theme('pager', NULL, $forum_per_page, 0, tablesort_pager())) {
|
| 647 |
$rows[] = array(array('data' => $pager, 'colspan' => '5', 'class' => 'pager'));
|
| 648 |
}
|
| 649 |
}
|
| 650 |
|
| 651 |
$output .= theme('table', $forum_topic_list_header, $rows);
|
| 652 |
|
| 653 |
return $output;
|
| 654 |
}
|
| 655 |
|
| 656 |
function _phptemplate_forum_format($topic) {
|
| 657 |
if ($topic && $topic->timestamp) {
|
| 658 |
return t('<div="topic-posted">'. "\n" .'%time ago'. "\n" .'</div>'. "\n" .'<div="topic-author">'. "\n" .'%author</div>', array('%time' => format_interval(time() - $topic->timestamp), '%author' => format_name($topic)));
|
| 659 |
}
|
| 660 |
else {
|
| 661 |
return message_na();
|
| 662 |
}
|
| 663 |
}
|
| 664 |
|
| 665 |
|
| 666 |
/**
|
| 667 |
* =Mark
|
| 668 |
*/
|
| 669 |
function phptemplate_mark($type = MARK_NEW) {
|
| 670 |
global $user;
|
| 671 |
if ($user->uid) {
|
| 672 |
if ($type == MARK_NEW) {
|
| 673 |
return '<span class="marker marker-new">'. t('new') .'</span>';
|
| 674 |
}
|
| 675 |
else if ($type == MARK_UPDATED) {
|
| 676 |
return '<span class="marker marker-updated">'. t('updated') .'</span>';
|
| 677 |
}
|
| 678 |
}
|
| 679 |
}
|
| 680 |
|
| 681 |
/**
|
| 682 |
* =Filter tips
|
| 683 |
*/
|
| 684 |
/* outputs collapsible filter tips */
|
| 685 |
function phptemplate_filter_tips($tips, $long = false, $extra = '') {
|
| 686 |
static $format_id;
|
| 687 |
$format_id += 1;
|
| 688 |
$tips_to_hide ='';
|
| 689 |
$output = '';
|
| 690 |
|
| 691 |
$multiple = count($tips) > 1;
|
| 692 |
if ($multiple) {
|
| 693 |
$output = t('Input formats') .':';
|
| 694 |
}
|
| 695 |
|
| 696 |
if (count($tips)) {
|
| 697 |
if ($multiple) {
|
| 698 |
$output .= '<ul class="filter-list">' . "\n";
|
| 699 |
}
|
| 700 |
foreach ($tips as $name => $tiplist) {
|
| 701 |
if ($multiple) {
|
| 702 |
$output .= '<li><div class="filter-name"><strong>'. $name .'</strong>:</div>' . "\n";
|
| 703 |
}
|
| 704 |
|
| 705 |
$tips = '';
|
| 706 |
foreach ($tiplist as $tip) {
|
| 707 |
$tips .= '<li'. ($long ? ' id="filter-'. str_replace("/", "-", $tip['id']) .'">' : '>') . $tip['tip'] . '</li>'. "\n";
|
| 708 |
}
|
| 709 |
|
| 710 |
if ($tips) {
|
| 711 |
if (!$multiple) {
|
| 712 |
$output .= '<span class="toggle-button" id="show-input-formats-'. $format_id .'">'. "\n" .' <a href="javascript:void(0);" onclick="toggleShow(\'input-formats-container-' . $format_id . '\');toggleShow(\'hide-input-formats-'. $format_id .'\');toggleHide(\'show-input-formats-'. $format_id .'\');return true;"><img src="' . path_to_theme() . '/global/images/icon_collapsed.png" alt="Expand filter description" /></a>'. "\n" .'</span>' . "\n";
|
| 713 |
$output .= '<span class="toggle-button" style="display: none;" id="hide-input-formats-'. $format_id .'">'. "\n" .' <a href="javascript:void(0);" onclick="toggleHide(\'input-formats-container-' . $format_id . '\');toggleHide(\'hide-input-formats-'. $format_id .'\');toggleShow(\'show-input-formats-'. $format_id .'\');return true;"><img src="' . path_to_theme() . '/global/images/icon_expanded.png" alt="Hide filter description" /></a>'. "\n" .'</span>' . "\n";
|
| 714 |
$output .= '<div id="input-formats-container-'. $format_id .'">'. "\n";
|
| 715 |
}
|
| 716 |
|
| 717 |
$output .= "<ul class=\"tips\">\n$tips\n</ul>";
|
| 718 |
|
| 719 |
if (!$multiple) {
|
| 720 |
$output .= '</div>';
|
| 721 |
$output .= '<script language="JavaScript1.2" type="text/javascript">'. "\n" .' window.onload = toggleHide(\'input-formats-container-' . $format_id . "');\n</script>\n";
|
| 722 |
}
|
| 723 |
}
|
| 724 |
|
| 725 |
if ($multiple) {
|
| 726 |
$output .= '</li>' . "\n";
|
| 727 |
}
|
| 728 |
}
|
| 729 |
if ($multiple) {
|
| 730 |
$output .= '</ul>'. "\n";
|
| 731 |
}
|
| 732 |
}
|
| 733 |
return $output;
|
| 734 |
}
|
| 735 |
|
| 736 |
/* changed sort images */
|
| 737 |
function phptemplate_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
|
| 738 |
switch ($path) {
|
| 739 |
case 'misc/arrow-asc.png':
|
| 740 |
$path = path_to_theme() . '/global/images/asc.png';
|
| 741 |
break;
|
| 742 |
case 'misc/arrow-desc.png':
|
| 743 |
$path = path_to_theme() . '/global/images/desc.png';
|
| 744 |
break;
|
| 745 |
}
|
| 746 |
if (!$getsize || (is_file($path) && (list($width, $height, $type) = @getimagesize($path)))) {
|
| 747 |
return '<img src="'. check_url($path) .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' />';
|
| 748 |
}
|
| 749 |
}
|
| 750 |
|
| 751 |
|
| 752 |
/**
|
| 753 |
* =Books
|
| 754 |
*/
|
| 755 |
function phptemplate_book_navigation($node) {
|
| 756 |
$path = book_location($node);
|
| 757 |
|
| 758 |
// Construct the breadcrumb:
|
| 759 |
|
| 760 |
$node->breadcrumb = array(); // Overwrite the trail with a book trail.
|
| 761 |
foreach ($path as $level) {
|
| 762 |
$node->breadcrumb[] = array('path' => 'node/'. $level->nid, 'title' => $level->title);
|
| 763 |
}
|
| 764 |
$node->breadcrumb[] = array('path' => 'node/'. $node->nid);
|
| 765 |
|
| 766 |
if ($node->nid) {
|
| 767 |
$output .= '<div class="book">';
|
| 768 |
|
| 769 |
if ($tree = book_tree($node->nid)) {
|
| 770 |
$output .= '<div class="tree">'. $tree .'</div>';
|
| 771 |
}
|
| 772 |
|
| 773 |
if ($prev = book_prev($node)) {
|
| 774 |
$links .= '<div class="prev">';
|
| 775 |
$links .= l(t('previous'), 'node/'. $prev->nid, array('title' => t('View the previous page.')));
|
| 776 |
$links .= '</div>';
|
| 777 |
$titles .= '<div class="prev">'. check_plain($prev->title) .'</div>';
|
| 778 |
}
|
| 779 |
else {
|
| 780 |
$links .= '<div class="prev"> </div>'; // Make an empty div to fill the space.
|
| 781 |
}
|
| 782 |
|
| 783 |
if ($next = book_next($node)) {
|
| 784 |
$links .= '<div class="next">';
|
| 785 |
$links .= l(t('next'), 'node/'. $next->nid, array('title' => t('View the next page.')));
|
| 786 |
$links .= '</div>';
|
| 787 |
$titles .= '<div class="next">'. check_plain($next->title) .'</div>';
|
| 788 |
}
|
| 789 |
else {
|
| 790 |
$links .= '<div class="next"> </div>'; // Make an empty div to fill the space.
|
| 791 |
}
|
| 792 |
|
| 793 |
if ($node->parent) {
|
| 794 |
$links .= '<div class="up">';
|
| 795 |
$links .= l(t('up'), 'node/'. $node->parent, array('title' => t('View this page\'s parent section.')));
|
| 796 |
$links .= '</div>';
|
| 797 |
}
|
| 798 |
|
| 799 |
$output .= '<div class="nav">';
|
| 800 |
$output .= ' <div class="links">'. $links .'</div>';
|
| 801 |
$output .= ' <div class="titles">'. $titles .'</div>';
|
| 802 |
$output .= '</div>';
|
| 803 |
$output .= '</div>';
|
| 804 |
}
|
| 805 |
|
| 806 |
$node->body = $node->body.$output;
|
| 807 |
|
| 808 |
return $node;
|
| 809 |
}
|
| 810 |
|
| 811 |
?>
|