Projet

Général

Profil

Paste
Télécharger (19,2 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / advanced_forum / includes / theme.inc @ c169e7c4

1
<?php
2

    
3
/**
4
 * @file
5
 * Holds theme functions and template preprocesses.
6
 * Other style related functions are in style.inc
7
 */
8
// THEME FUNCTIONS **********************************************************/
9

    
10
/**
11
 * Theme function to display a link, optionally buttonized.
12
 */
13
function theme_advanced_forum_l(&$variables) {
14
  $text = $variables['text'];
15
  $path = empty($variables['path']) ? NULL : $variables['path'];
16
  $options = empty($variables['options']) ? array() : $variables['options'];
17
  $button_class = empty($variables['button_class']) ? NULL : $variables['button_class'];
18

    
19
  $l = '';
20
  if (!isset($options['attributes'])) {
21
    $options['attributes'] = array();
22
  }
23
  if (!is_null($button_class)) {
24
    // Buttonized link: add our button class and the span.
25
    if (!isset($options['attributes']['class'])) {
26
      $options['attributes']['class'] = array("af-button-$button_class");
27
    }
28
    else {
29
      $options['attributes']['class'][] = "af-button-$button_class";
30
    }
31
    $options['html'] = TRUE;
32
    $l = l('<span>' . $text . '</span>', $path, $options);
33
  }
34
  else {
35
    // Standard link: just send it through l().
36
    $l = l($text, $path, $options);
37
  }
38

    
39
  return $l;
40
}
41

    
42
/**
43
 * Theme function to show list of types that can be posted in forum.
44
 */
45
function theme_advanced_forum_node_type_create_list(&$variables) {
46
  $forum_id = $variables['forum_id'];
47

    
48
  // Get the list of node types to display links for.
49
  $type_list = advanced_forum_node_type_create_list($forum_id);
50

    
51
  $output = '';
52
  if (is_array($type_list)) {
53
    foreach ($type_list as $type => $item) {
54
      $output .= '<div class="forum-add-node forum-add-' . $type . '">';
55
      $output .= theme('advanced_forum_l', array(
56
        'text' => t('New @node_type', array('@node_type' => $item['name'])),
57
        'path' => $item['href'],
58
        'options' => NULL,
59
        'button_class' => 'large'
60
          ));
61
      $output .= '</div>';
62
    }
63
  }
64
  else {
65
    // User did not have access to create any node types in this fourm so
66
    // we just return the denial text / login prompt.
67
    $output = $type_list;
68
  }
69

    
70
  return $output;
71
}
72

    
73
/**
74
 * Theme function to show simple author pane when not using Author Pane.
75
 */
76
function theme_advanced_forum_simple_author_pane(&$variables) {
77
  $context = $variables['context'];
78
  // Sending the context rather than the account makes it work for anon comments.
79
  $name = theme('username', array('account' => $context));
80

    
81
  $account = user_load($context->uid);
82
  $picture = theme('user_picture', array('account' => $account));
83

    
84
  return '<div class="author-pane">' . $name . $picture . '</div>';
85
}
86

    
87
/**
88
 * Theme function to format the reply link at the top/bottom of topic.
89
 */
90
function theme_advanced_forum_reply_link(&$variables) {
91
  $node = $variables['node'];
92

    
93
  // Get the information about whether the user can reply and the link to do
94
  // so if the user is allowed to.
95
  $reply_link = advanced_forum_get_reply_link($node);
96

    
97
  if (is_array($reply_link)) {
98
    // Reply is allowed. Variable contains the link information.
99
    $output = '<div class="topic-reply-allowed">';
100
    $output .= theme('advanced_forum_l', array(
101
      'text' => $reply_link['title'],
102
      'path' => $reply_link['href'],
103
      'options' => $reply_link['options'],
104
      'button_class' => 'large'
105
        ));
106
    $output .= '</div>';
107
    return $output;
108
  }
109
  elseif ($reply_link == 'reply-locked') {
110
    // @TODO: The double span here is icky but I don't know how else to get
111
    // around the fact that there's no "a" to put the button class on.
112
    return '<div class="topic-reply-locked"><span class="af-button-large"><span>' . t('Topic locked') . '</span></span></div>';
113
  }
114
  elseif ($reply_link == 'reply-forbidden') {
115
    // User is not allowed to reply to this topic.
116
    return theme('comment_post_forbidden', array('node' => $node));
117
  }
118
}
119

    
120
/**
121
 * Theme function to a formatted list of subforums.
122
 *
123
 * @param $subforum_list
124
 *   Array of subforums.
125
 * @return
126
 *   Formatted list of subforums.
127
 */
128
function theme_advanced_forum_subforum_list(&$variables) {
129
  $subforums = array();
130
  foreach ($variables['subforum_list'] as $tid => $subforum) {
131
    // Note: $subforum->name has not been run through check_plain because
132
    // it ends up going through there when l() is called without the HTML
133
    // option. If you change this to set HTML to TRUE, you must sanitize it.
134
    $text = l($subforum->name, "forum/$tid");
135
    $text .= ' (' . $subforum->total_posts;
136

    
137
    if (empty($subforum->new_posts)) {
138
      $text .= ')';
139
    }
140
    else {
141
      $text .= ' - ' . l($subforum->new_posts_text, $subforum->new_posts_path, array('fragment' => 'new')) . ')';
142
    }
143

    
144
    $subforums[] = $text;
145
  }
146
  return implode(', ', $subforums);
147
}
148

    
149
/**
150
 * Theme function to a formatted list of subcontainers.
151
 *
152
 * @param $subcontainer_list
153
 *   Array of subcontainers.
154
 * @return
155
 *   Formatted list of subcontainers.
156
 */
157
function theme_advanced_forum_subcontainer_list(&$variables) {
158
  $subcontainers = array();
159
  foreach ($variables['subcontainer_list'] as $tid => $subcontainer) {
160
    // Note: $subcontainer->name has not been run through check_plain because
161
    // it ends up going through there when l() is called without the HTML
162
    // option. If you change this to set HTML to TRUE, you must sanitize it.
163
    $text = l($subcontainer->name, "forum/$tid");
164
    $text .= ' (' . $subcontainer->total_posts;
165

    
166
    if (empty($subcontainer->new_posts)) {
167
      $text .= ')';
168
    }
169
    else {
170
      $text .= ' - ' . l($subforum->new_posts_text, $subforum->new_posts_path, array('fragment' => 'new')) . ')';
171
    }
172

    
173
    $subcontainers[] = $text;
174
  }
175

    
176
  return implode(', ', $subcontainers);
177
}
178

    
179
// TEMPLATE PREPROCESS ******************************************************/
180

    
181
/* * * FORUM OVERVIEW & TOPIC LIST PAGES ************************************* */
182

    
183
/**
184
 * Preprocesses template variables for the forum template.
185
 */
186
function advanced_forum_preprocess_forums(&$variables) {
187
  include_once drupal_get_path('module', 'advanced_forum') . '/includes/advanced_forum_preprocess_forums.inc';
188
  _advanced_forum_preprocess_forums($variables);
189
}
190

    
191
/**
192
 * Preprocesses template variables for the forum search form template.
193
 */
194
function advanced_forum_preprocess_advanced_forum_search_forum(&$variables) {
195
  advanced_forum_add_template_suggestions("search_forum", $variables);
196

    
197
  $variables['forum'] = !empty($variables['tid']) ? $variables['tid'] : 'All';
198
  $variables['path'] = url('forum/search');
199
}
200

    
201
/**
202
 * Preprocesses template variables for the search results template.
203
 */
204
function advanced_forum_preprocess_views_view_fields__advanced_forum_search(&$variables) {
205
  _advanced_forum_add_files();
206
  advanced_forum_add_template_suggestions("search_result", $variables);
207
}
208

    
209
/**
210
 * Preprocesses template variables for the submitted by/in template.
211
 */
212
function advanced_forum_preprocess_forum_submitted(&$variables) {
213
  advanced_forum_add_template_suggestions("submitted", $variables);
214
  // Avoid E_ALL warning
215
  $variables['topic_link'] = '';
216

    
217
  if (isset($variables['topic']->node_title)) {
218
    $nid = $variables['topic']->nid;
219

    
220
    // Make a fake node object to avoid the node load
221
    $node = new stdClass();
222
    $node->nid = $nid;
223
    $node->type = $variables['topic']->type;
224

    
225
    // Find the page of the first unread comment, if any
226
    $comment_count = db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
227
    $new_replies = advanced_forum_reply_num_new($nid);
228
    $query = advanced_forum_page_first_new($comment_count, $new_replies, $node);
229

    
230
    // Format the node title with a link
231
    $title_length = variable_get('advanced_forum_topic_title_length', 15);
232
    if ($title_length == 0) {
233
      $short_topic_title = $variables['topic']->node_title;
234
    }
235
    else {
236
      $short_topic_title = truncate_utf8($variables['topic']->node_title, $title_length, TRUE, TRUE);
237
    }
238

    
239
    $variables['short_topic_title'] = $short_topic_title;
240

    
241
    $fragment = ($new_replies) ? 'new' : NULL;
242

    
243
    $variables['topic_link_fragment'] = $fragment;
244
    $variables['topic_link_query'] = $query;
245
    $variables['topic_link'] = l($short_topic_title, "node/$nid", array('query' => $query, 'fragment' => $fragment));
246
  }
247

    
248
  if (isset($variables['topic']->created)) {
249
    $timestamp = $variables['topic']->created;
250
    $interval = REQUEST_TIME - $timestamp;
251
    $variables['time'] = format_interval($interval);
252

    
253
    // For items posted more than $cutoff hours ago, offer an actual date.
254
    $cutoff = variable_get('advanced_forum_time_ago_cutoff', 48) * 60 * 60;
255
    if ($interval > $cutoff) {
256
      $variables['date_posted'] = format_date($timestamp, 'short');
257
    }
258
    else {
259
      unset($variables['date_posted']);
260
    }
261
  }
262
}
263

    
264
function advanced_forum_preprocess_advanced_forum_topic_pager(&$variables) {
265
  $pagecount = $variables['pagecount'];
266
  $topic = $variables['topic'];
267

    
268
  // Get the information to assemble the pager. This returns an object with
269
  // the following properties:
270
  //  initial_pages: Array of linked numbers for first set of pages
271
  //  last_page_text: Linked text "Last page" (translatable)
272
  //  last_page_number: Linked number pointing to the last page.
273
  $topic_pager = advanced_forum_create_topic_pager($pagecount, $topic);
274

    
275

    
276
  $variables['last_page_text'] = '';
277

    
278
  if (!empty($topic_pager->initial_pages)) {
279
    $variables['pages'] = $topic_pager->initial_pages;
280
    if (!empty($topic_pager->last_page_text)) {
281
      $variables['last_page'] = $topic_pager->last_page;
282
      $variables['last_page_text'] = $topic_pager->last_page_text;
283
      $variables['last_page_number'] = $topic_pager->last_page_number;
284

    
285
      // If you prefer to end with the number, replace
286
      // $topic_pager->last_page_text with $topic_pager->last_page_number
287
      $variables['last_page_text'] = ' &hellip; ' . $topic_pager->last_page_text;
288
    }
289
  }
290
}
291

    
292
/**
293
 * Preprocess variables for advanced-forum.naked.post-edited.tpl.php
294
 *
295
 */
296
function advanced_forum_preprocess_advanced_forum_post_edited(&$variables) {
297
  $editor = user_load($variables['who']);
298

    
299
  $variables['edited_name'] = theme('username', array('account' => $editor));
300
  $variables['edited_datetime'] = format_date($variables['when'], 'custom', variable_get('date_format_short', 'm/d/Y - H:i'));
301
  $variables['edited_reason'] = empty($variables['why']) ? '' : $variables['why'];
302
}
303

    
304
function advanced_forum_preprocess_advanced_forum_shadow_topic(&$variables) {
305
  $nid = $variables['nid'];
306

    
307
  $variables['new_forum_url'] = url("node/$nid");
308
  // compatibility variable
309
  $variables['new_forum_link'] = l(t('View topic'), "node/$nid");
310
}
311

    
312
/* * * JUST FORUM OVERVIEW PAGE ********************************************** */
313

    
314
/**
315
 * Preprocesses template variables for the forum legend template.
316
 */
317
function advanced_forum_preprocess_advanced_forum_forum_legend(&$variables) {
318
  advanced_forum_add_template_suggestions("forum_legend", $variables);
319
}
320

    
321
/**
322
 * Preprocesses template variables for the forum statistics template.
323
 */
324
function advanced_forum_preprocess_advanced_forum_statistics(&$variables) {
325
  advanced_forum_add_template_suggestions("statistics", $variables);
326

    
327
  $variables['topics'] = advanced_forum_statistics_topics();
328
  $variables['posts'] = advanced_forum_statistics_replies() + $variables['topics'];
329
  $variables['users'] = advanced_forum_statistics_users();
330

    
331
  $authenticated_users = advanced_forum_statistics_online_users();
332
  $variables['online_users'] = implode(', ', $authenticated_users);
333
  $variables['current_users'] = advanced_forum_session_count(FALSE);
334
  $variables['current_guests'] = 0; // for backwards compatibility
335
  $variables['current_total'] = $variables['current_users'] + $variables['current_guests'];
336

    
337
  $latest_users = advanced_forum_statistics_latest_users();
338
  $variables['latest_users'] = implode(', ', $latest_users);
339
}
340

    
341
/**
342
 * Preprocesses template variables for the forum list template.
343
 */
344
function advanced_forum_preprocess_forum_list(&$variables) {
345
  include_once drupal_get_path('module', 'advanced_forum') . '/includes/advanced_forum_preprocess_forum_list.inc';
346
  _advanced_forum_preprocess_forum_list($variables);
347
}
348

    
349
/* * * JUST TOPIC LIST PAGES ************************************************* */
350

    
351
function advanced_forum_preprocess_views_view_forum_topic_list__advanced_forum_topic_list(&$variables) {
352
  _advanced_forum_add_files();
353
  // debug
354
  die("advanced_forum_preprocess_views_view_forum_topic_list__advanced_forum_topic_list");
355
  advanced_forum_add_template_suggestions("topic_list_view", $variables);
356
  // Set a variable for displaying the topic legend.
357
  $variables['topic_legend'] = theme('advanced_forum_topic_legend');
358
}
359

    
360
function advanced_forum_preprocess_views_view__advanced_forum_topic_list(&$variables) {
361
  _advanced_forum_add_files();
362
  advanced_forum_add_template_suggestions("topic_list_outer_view", $variables);
363

    
364
  $variables['node_create_list'] = '';
365
  $variables['forum_tools'] = '';
366
  $variables['forum_jump'] = '';
367

    
368
  $menu_item = menu_get_item();
369

    
370
  if (!empty($menu_item) && $menu_item['access']) {
371
    if (($menu_item['map'][0] == 'forum') && (!empty($menu_item['map'][1]))) {
372
      $forum = $menu_item['map'][1];
373
      if ($forum->vid == variable_get('forum_nav_vocabulary') && $forum->tid > 0) {
374
        $variables['node_create_list'] = theme('advanced_forum_node_type_create_list', array('forum_id' => $forum->tid));
375
        $variables['forum_description'] = $forum->description;
376
        $variables['forum_tools'] = advanced_forum_forum_tools($forum->tid);
377
        $variables['forum_jump'] = advanced_forum_forum_jump($forum->tid);
378
      }
379
    }
380
  }
381
}
382

    
383
/**
384
 * Display a view as a forum topic list style.
385
 */
386
function template_preprocess_advanced_forum_topic_list_view(&$variables) {
387
  include_once drupal_get_path('module', 'advanced_forum') . '/includes/template_preprocess_advanced_forum_topic_list_view.inc';
388
  _template_preprocess_advanced_forum_topic_list_view($variables);
389
}
390

    
391
/**
392
 * Preprocesses template variables for the topic list template.
393
 */
394
function advanced_forum_preprocess_forum_topic_list(&$variables) {
395
  advanced_forum_add_template_suggestions("topic_list", $variables);
396
}
397

    
398
/**
399
 * Preprocesses template variables for the forum icon template.
400
 */
401
function advanced_forum_preprocess_forum_icon(&$variables) {
402
  advanced_forum_add_template_suggestions("topic_icon", $variables);
403
}
404

    
405
/**
406
 * Preprocesses template variables for the topic legend template.
407
 */
408
function advanced_forum_preprocess_advanced_forum_topic_legend(&$variables) {
409
  advanced_forum_add_template_suggestions("topic_legend", $variables);
410
}
411

    
412
/* * * TOPIC PAGES *********************************************************** */
413

    
414
function advanced_forum_preprocess_advanced_forum_search_topic(&$variables) {
415
  advanced_forum_add_template_suggestions("search_topic", $variables);
416

    
417
  $variables['path'] = url('node/' . $variables['node']->nid . '/search');
418
}
419

    
420
function advanced_forum_preprocess_views_view_fields__advanced_forum_search_topic(&$variables) {
421
  _advanced_forum_add_files();
422
  advanced_forum_add_template_suggestions("search_result", $variables);
423
}
424

    
425
/**
426
 * Preprocesses template variables for the topic header template.
427
 */
428
function advanced_forum_preprocess_advanced_forum_topic_header(&$variables) {
429
  advanced_forum_add_template_suggestions("topic_header", $variables);
430

    
431
  $node = $variables['node'];
432

    
433

    
434
  // Reply link / button
435
  $variables['reply_link'] = theme('advanced_forum_reply_link', array('node' => $node));
436

    
437
  // Total posts, including first post.
438
  $posts = (empty($variables['comment_count'])) ? 1 : $variables['comment_count'] + 1;
439
  $variables['total_posts_count'] = format_plural($posts, '1 post', '@count posts');
440

    
441
  // Number of new posts on topic.
442
  $variables['new_posts_count'] = advanced_forum_reply_num_new($node->nid);
443

    
444
  // Link to first new post.
445
  $variables['first_new_post_link'] = '';
446
  if ($posts > 1) {
447
    $variables['first_new_post_link'] = advanced_forum_first_new_post_link($variables['node'], $variables['comment_count']);
448
  }
449

    
450
  // Link to last post in topic.
451
  $variables['last_post_link'] = advanced_forum_last_post_link($node);
452

    
453
  // Pager
454
  if (isset($variables['node']->comment_count))
455
    pager_default_initialize($variables['node']->comment_count, variable_get('comment_default_per_page_' . $variables['node']->type, 50));
456

    
457

    
458
  $variables['pager'] = theme('pager');
459
}
460

    
461
/**
462
 * Preprocesses template variables for the active poster template.
463
 */
464
function advanced_forum_preprocess_advanced_forum_active_poster(&$variables) {
465
  advanced_forum_add_template_suggestions("active_poster", $variables);
466

    
467
  $variables['account_name'] = theme('username', array('account' => $variables['account']));
468
  $variables['picture'] = theme('advanced_forum_user_picture', array('account' => $variables['account']));
469

    
470
  $node = $variables['last_post'];
471
  $variables['last_post_title'] = l($node->title, "node/$node->nid");
472
  $variables['last_post_date'] = format_date($node->created);
473
}
474

    
475
/**
476
 * Preprocesses template variables for the author pane.
477
 */
478
function advanced_forum_preprocess_author_pane(&$variables) {
479
  // Author pane is used in various places. Check the caller to make sure
480
  // we are the one that called it.
481
  if (!empty($variables['caller']) && $variables['caller'] == 'advanced_forum') {
482
    advanced_forum_add_template_suggestions("author_pane", $variables);
483
  }
484
}
485

    
486
/**
487
 * Preprocesses template variables for the page template.
488
 */
489
function advanced_forum_preprocess_page(&$variables) {
490
  if (arg(0) == 'forum') {
491
    $variables['forum_page'] = TRUE;
492
  }
493
  elseif (arg(0) == 'node' && !empty($variables['node']) && advanced_forum_type_is_in_forum($variables['node']->type)) {
494
    $variables['forum_page'] = TRUE;
495
  }
496
}
497

    
498
/**
499
 * Preprocesses template variables for the node template.
500
 */
501
function advanced_forum_preprocess_node(&$variables) {
502
  if (advanced_forum_is_styled($variables['node'], $variables['teaser'], 'node')) {
503
    include_once drupal_get_path('module', 'advanced_forum') . '/includes/advanced_forum_preprocess_node.inc';
504
    _advanced_forum_preprocess_node($variables);
505
  }
506
}
507

    
508
function advanced_forum_preprocess_comment_wrapper(&$variables) {
509
  $variables['reply_link'] = '';
510
  if (advanced_forum_is_styled($variables['node'], FALSE, 'comment-wrapper')) {
511
    advanced_forum_add_template_suggestions("advanced_forum_comment_wrapper", $variables);
512

    
513
    $form_on_seperate_page = variable_get('comment_form_location_' . $variables['node']->type, COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE;
514

    
515
    $comments_locked = $variables['node']->comment != COMMENT_NODE_OPEN;
516

    
517
    if ($form_on_seperate_page || $comments_locked) {
518
      // If the post is locked or the comment form is on a seperate page,
519
      // build the reply/locked link / button
520
      $variables['reply_link'] = theme('advanced_forum_reply_link', array('node' => $variables['node']));
521
    }
522
  }
523
}
524

    
525
/**
526
 * Preprocesses template variables for the comment template.
527
 */
528
function advanced_forum_preprocess_comment(&$variables) {
529
  if (advanced_forum_is_styled($variables['comment'], FALSE, 'comment')) {
530
    include_once drupal_get_path('module', 'advanced_forum') . '/includes/advanced_forum_preprocess_comment.inc';
531
    _advanced_forum_preprocess_comment($variables);
532
  }
533
}
534

    
535
/* * * ORGANIC GROUPS ******************************************************** */
536

    
537
function advanced_forum_preprocess_views_view__advanced_forum_group_topic_list(&$variables) {
538
  _advanced_forum_add_files();
539
  advanced_forum_add_template_suggestions("group_topic_list_outer_view", $variables);
540

    
541
  // Set a variable for displaying the topic legend.
542
  $variables['topic_legend'] = theme('advanced_forum_topic_legend');
543
}