Projet

Général

Profil

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

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

1
<?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
function _advanced_forum_preprocess_comment(&$variables) {
9
  /* Easy links to the comment and parent node */
10
  $comment = $variables['comment'];
11
  $node = node_load($comment->nid);
12
  $variables['first_post'] = $node;
13

    
14
  // This is a comment, not the node.
15
  $variables['top_post'] = FALSE;
16

    
17
  /* Determine the template file to use for the comment. */
18
  if (arg(1) == 'reply' || arg(2) == 'edit') {
19
    // Use the preview version
20
    advanced_forum_add_template_suggestions("post-preview", $variables);
21
  }
22
  else {
23
    // Use our combined node/comment template file
24
    advanced_forum_add_template_suggestions("post", $variables);
25
  }
26

    
27

    
28
  // Add in our classes overwriting existing.
29
  $variables['classes_array'] = array();
30
  $variables['classes_array'][] = 'forum-post clearfix';
31

    
32
  // Add the current language to the classes for image handling.
33
  global $language;
34
  if (!empty($language->language)) {
35
    $variables['classes_array'][] = $language->language;
36
  }
37

    
38
  // Add the poster's UID
39
  $variables['classes_array'][] = "posted-by-$comment->uid";
40

    
41
  // Add class if the poster is the viewer.
42
  global $user;
43
  if ($user->uid > 0 && $user->uid == $comment->uid) {
44
    $variables['classes_array'][] = "post-by-viewer";
45
  }
46

    
47
  // Add class if the poster is the topic starter.
48
  if ($node->uid > 0 && $node->uid == $comment->uid) {
49
    $variables['classes_array'][] = "post-by-starter";
50
  }
51

    
52
  // Set the post ID for theming / targetting
53
  $variables['post_id'] = "post-$comment->cid";
54

    
55
  
56

    
57
  $num_comments = $node->comment_count;
58
  $posts_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
59

    
60
  $page_number = !empty($_GET['page']) ? $_GET['page'] : 0;
61

    
62
  // page_number sanity check
63
  if ($page_number > floor($num_comments / $posts_per_page))
64
    $page_number = floor($num_comments / $posts_per_page);
65

    
66
  if (!$page_number) {
67
    $page_number = 0;
68
  }
69
  
70
  /* Linked post number */
71
  if (!isset($post_number)) {
72
    static $post_number = 1;
73
  }
74
 
75
  // check if node type is forum
76
  $topic_id = advanced_forum_node_is_styled($variables['node']);
77
  $post_number_delta = ($topic_id) ? 1 : 0;
78
   
79
  $linktext = '#' . (($page_number * $posts_per_page) + $post_number + $post_number_delta);
80
  
81
  $post_number++;
82
  
83
  // Permalink
84
  //  You can erase next 3 lines if you wish to use built-in Permalink.
85
  //  Template adjusted: $post_link -> $permalink
86
  $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
      $page_number = floor(($post_position - 2) / $posts_per_page);
102

    
103
      // Assemble the link.
104
      $fragment = 'comment-' . $comment->pid;
105

    
106
      if ($page_number)
107
        $query = array('page' => $page_number);
108

    
109
      $linktext = t("(Reply to #!post_position)", array('!post_position' => $post_position));
110
      $linkpath = "node/$node->nid";
111
      $variables['in_reply_to'] = l($linktext, $linkpath, array('query' => empty($query) ? array() : $query, 'fragment' => $fragment));
112
    }
113
  }
114

    
115
  /* Title */
116
  if (variable_get('comment_subject_field_' . $node->type, 1) == 0) {
117
    // if comment titles are disabled, don't display it.
118
    $variables['title'] = '';
119
  }
120
  else {
121
    // Assign the subject to the title variable for consistancy with nodes.
122
    $variables['title'] = check_plain($comment->subject);
123
  }
124

    
125
  $variables['account'] = new stdClass();
126
  /* User information / author pane */
127
  if ($comment->uid == 0) {
128
    // Anonymous user. Make a fake user object for theme_username
129
    $variables['account']->name = empty($comment->name) ? "" : $comment->name;
130
    $variables['account']->homepage = empty($comment->homepage) ? "" : $comment->homepage;
131
    $variables['account']->email = empty($comment->email) ? "" : $comment->email;
132
  }
133
  else {
134
    // Load up the real user object
135
    $variables['account'] = user_load($comment->uid);
136
  }
137

    
138
  // Create the author pane
139
  if (module_exists('author_pane')) {
140
    $variables['author_pane'] = theme('author_pane', array(
141
      'account' => $variables['account'],
142
      'caller' => 'advanced_forum',
143
      'picture_preset' => variable_get('advanced_forum_user_picture_preset', ''),
144
      'context' => $comment,
145
      'disable_css' => TRUE,
146
      'join_date_type' => variable_get('advanced_forum_author_pane_join_date_type', 'short'),
147
        ));
148
  }
149
  else {
150
    $variables['author_pane'] = theme('advanced_forum_simple_author_pane', array('context' => $comment));
151
  }
152
  /* Content */
153
  // Helpful $content variable for templates.
154
  foreach (element_children($variables['elements']) as $key) {
155
    // Adjust content vriable to suit post template
156
    if ($key == 'comment_body')
157
      $variables['content']['body'] = $variables['elements'][$key];
158
    else
159
      $variables['content'][$key] = $variables['elements'][$key];
160
  }
161

    
162
  // Adjust comment timestamp to match node template
163
  $variables['date'] = $variables['created'];
164

    
165
  /* Post edited */
166
  $variables['post_edited'] = (isset($variables['comment_edited'])) ? $variables['comment_edited'] : "";
167
}