Projet

Général

Profil

Paste
Télécharger (5,79 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / advanced_forum / includes / advanced_forum_preprocess_comment.inc @ c22e192e

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Holds the contents of a preprocess function moved into its own file
6
 * to ease memory requirements and having too much code in one file.
7
 */
8 13c3c9b4 Assos Assos
9
/**
10
 * Preprocess comment.
11
 */
12 85ad3d82 Assos Assos
function _advanced_forum_preprocess_comment(&$variables) {
13
  /* Easy links to the comment and parent node */
14
  $comment = $variables['comment'];
15
  $node = node_load($comment->nid);
16
  $variables['first_post'] = $node;
17
18
  // This is a comment, not the node.
19
  $variables['top_post'] = FALSE;
20
21
  /* Determine the template file to use for the comment. */
22
  if (arg(1) == 'reply' || arg(2) == 'edit') {
23 13c3c9b4 Assos Assos
    // Use the preview version.
24 85ad3d82 Assos Assos
    advanced_forum_add_template_suggestions("post-preview", $variables);
25
  }
26
  else {
27 13c3c9b4 Assos Assos
    // Use our combined node/comment template file.
28 85ad3d82 Assos Assos
    advanced_forum_add_template_suggestions("post", $variables);
29
  }
30
31 13c3c9b4 Assos Assos
  if (!variable_get('advanced_forum_keep_classes', FALSE) || !is_array($variables['classes_array'])) {
32
    // Add in our classes overwriting existing.
33
    $variables['classes_array'] = array();
34
  }
35 85ad3d82 Assos Assos
  $variables['classes_array'][] = 'forum-post clearfix';
36
37
  // Add the current language to the classes for image handling.
38
  global $language;
39
  if (!empty($language->language)) {
40
    $variables['classes_array'][] = $language->language;
41
  }
42
43 13c3c9b4 Assos Assos
  // Add the poster's UID.
44 85ad3d82 Assos Assos
  $variables['classes_array'][] = "posted-by-$comment->uid";
45
46
  // Add class if the poster is the viewer.
47
  global $user;
48
  if ($user->uid > 0 && $user->uid == $comment->uid) {
49
    $variables['classes_array'][] = "post-by-viewer";
50
  }
51
52
  // Add class if the poster is the topic starter.
53
  if ($node->uid > 0 && $node->uid == $comment->uid) {
54
    $variables['classes_array'][] = "post-by-starter";
55
  }
56
57 13c3c9b4 Assos Assos
  // Set the post ID for theming / targetting.
58 85ad3d82 Assos Assos
  $variables['post_id'] = "post-$comment->cid";
59
  $num_comments = $node->comment_count;
60
  $posts_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
61
62
  $page_number = !empty($_GET['page']) ? $_GET['page'] : 0;
63
64 13c3c9b4 Assos Assos
  // Page_number sanity check.
65
  if ($page_number > floor($num_comments / $posts_per_page)) {
66 85ad3d82 Assos Assos
    $page_number = floor($num_comments / $posts_per_page);
67 13c3c9b4 Assos Assos
  }
68 85ad3d82 Assos Assos
69
  if (!$page_number) {
70
    $page_number = 0;
71
  }
72
  /* Linked post number */
73
  if (!isset($post_number)) {
74
    static $post_number = 1;
75
  }
76 13c3c9b4 Assos Assos
77
  // Check if node type is forum.
78 85ad3d82 Assos Assos
  $topic_id = advanced_forum_node_is_styled($variables['node']);
79
  $post_number_delta = ($topic_id) ? 1 : 0;
80
  $linktext = '#' . (($page_number * $posts_per_page) + $post_number + $post_number_delta);
81
  $post_number++;
82 13c3c9b4 Assos Assos
83
  // Permalink.
84
  // You can erase next 3 lines if you wish to use built-in Permalink.
85
  // Template adjusted: $post_link -> $permalink.
86 85ad3d82 Assos Assos
  $uri = entity_uri('comment', $comment);
87
  $uri['options'] += array('attributes' => array('class' => array('permalink'), 'rel' => 'bookmark'));
88
  $variables['permalink'] = l($linktext, $uri['path'], $uri['options']);
89
90
  /* In reply to */
91
  $variables['in_reply_to'] = "";
92
  if ($comment->pid > 0) {
93
    // Find the display position of the parent post;.
94
    $post_position = advanced_forum_post_position($node, $comment);
95
96
    // This extra if test is a sanity check in case the comment being replied
97
    // to no longer exists.
98
    if ($post_position > 0) {
99
      // Find the page the post is on. We need to compensate for the topic node
100
      // being #1 which puts an extra post on the first page but not on the rest.
101 13c3c9b4 Assos Assos
      $page_number = floor(($post_position - 1) / $posts_per_page);
102 85ad3d82 Assos Assos
103
      // Assemble the link.
104
      $fragment = 'comment-' . $comment->pid;
105
106 13c3c9b4 Assos Assos
      if ($page_number) {
107 85ad3d82 Assos Assos
        $query = array('page' => $page_number);
108 13c3c9b4 Assos Assos
      }
109 85ad3d82 Assos Assos
110
      $linktext = t("(Reply to #!post_position)", array('!post_position' => $post_position));
111
      $linkpath = "node/$node->nid";
112
      $variables['in_reply_to'] = l($linktext, $linkpath, array('query' => empty($query) ? array() : $query, 'fragment' => $fragment));
113
    }
114
  }
115
116
  /* Title */
117
  if (variable_get('comment_subject_field_' . $node->type, 1) == 0) {
118 13c3c9b4 Assos Assos
    // If comment titles are disabled, don't display it.
119 85ad3d82 Assos Assos
    $variables['title'] = '';
120
  }
121
  else {
122
    // Assign the subject to the title variable for consistancy with nodes.
123
    $variables['title'] = check_plain($comment->subject);
124
  }
125
126
  $variables['account'] = new stdClass();
127
  /* User information / author pane */
128
  if ($comment->uid == 0) {
129
    // Anonymous user. Make a fake user object for theme_username
130
    $variables['account']->name = empty($comment->name) ? "" : $comment->name;
131
    $variables['account']->homepage = empty($comment->homepage) ? "" : $comment->homepage;
132
    $variables['account']->email = empty($comment->email) ? "" : $comment->email;
133
  }
134
  else {
135 13c3c9b4 Assos Assos
    // Load up the real user object.
136 85ad3d82 Assos Assos
    $variables['account'] = user_load($comment->uid);
137
  }
138
139 13c3c9b4 Assos Assos
  // Create the author pane.
140 85ad3d82 Assos Assos
  if (module_exists('author_pane')) {
141
    $variables['author_pane'] = theme('author_pane', array(
142
      'account' => $variables['account'],
143
      'caller' => 'advanced_forum',
144
      'picture_preset' => variable_get('advanced_forum_user_picture_preset', ''),
145
      'context' => $comment,
146
      'disable_css' => TRUE,
147
      'join_date_type' => variable_get('advanced_forum_author_pane_join_date_type', 'short'),
148
        ));
149
  }
150
  else {
151
    $variables['author_pane'] = theme('advanced_forum_simple_author_pane', array('context' => $comment));
152
  }
153
  /* Content */
154
  // Helpful $content variable for templates.
155
  foreach (element_children($variables['elements']) as $key) {
156 13c3c9b4 Assos Assos
    // Adjust content vriable to suit post template.
157
    if ($key == 'comment_body') {
158 85ad3d82 Assos Assos
      $variables['content']['body'] = $variables['elements'][$key];
159 13c3c9b4 Assos Assos
    }
160
    else {
161 85ad3d82 Assos Assos
      $variables['content'][$key] = $variables['elements'][$key];
162 13c3c9b4 Assos Assos
    }
163 85ad3d82 Assos Assos
  }
164
165 13c3c9b4 Assos Assos
  // Adjust comment timestamp to match node template.
166 85ad3d82 Assos Assos
  $variables['date'] = $variables['created'];
167
168
  /* Post edited */
169
  $variables['post_edited'] = (isset($variables['comment_edited'])) ? $variables['comment_edited'] : "";
170 13c3c9b4 Assos Assos
}