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
|
|
9
|
/**
|
10
|
* Preprocess comment.
|
11
|
*/
|
12
|
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
|
// Use the preview version.
|
24
|
advanced_forum_add_template_suggestions("post-preview", $variables);
|
25
|
}
|
26
|
else {
|
27
|
// Use our combined node/comment template file.
|
28
|
advanced_forum_add_template_suggestions("post", $variables);
|
29
|
}
|
30
|
|
31
|
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
|
$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
|
// Add the poster's UID.
|
44
|
$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
|
// Set the post ID for theming / targetting.
|
58
|
$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
|
// Page_number sanity check.
|
65
|
if ($page_number > floor($num_comments / $posts_per_page)) {
|
66
|
$page_number = floor($num_comments / $posts_per_page);
|
67
|
}
|
68
|
|
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
|
|
77
|
// Check if node type is forum.
|
78
|
$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
|
|
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 - 1) / $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
|
|
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
|
// If comment titles are disabled, don't display it.
|
119
|
$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
|
// Load up the real user object.
|
136
|
$variables['account'] = user_load($comment->uid);
|
137
|
}
|
138
|
|
139
|
// Create the author pane.
|
140
|
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
|
// Adjust content vriable to suit post template.
|
157
|
if ($key == 'comment_body') {
|
158
|
$variables['content']['body'] = $variables['elements'][$key];
|
159
|
}
|
160
|
else {
|
161
|
$variables['content'][$key] = $variables['elements'][$key];
|
162
|
}
|
163
|
}
|
164
|
|
165
|
// Adjust comment timestamp to match node template.
|
166
|
$variables['date'] = $variables['created'];
|
167
|
|
168
|
/* Post edited */
|
169
|
$variables['post_edited'] = (isset($variables['comment_edited'])) ? $variables['comment_edited'] : "";
|
170
|
}
|