Révision 13c3c9b4
Ajouté par Assos Assos il y a environ 9 ans
drupal7/sites/all/modules/advanced_forum/advanced_forum.module | ||
---|---|---|
4 | 4 |
* @file |
5 | 5 |
* Enables the look and feel of other popular forum software. |
6 | 6 |
*/ |
7 |
// DRUPAL HOOKS **************************************************************/ |
|
8 | 7 |
|
9 | 8 |
/** |
10 | 9 |
* Implementation of hook_perm(). |
... | ... | |
12 | 11 |
function advanced_forum_permission() { |
13 | 12 |
return array( |
14 | 13 |
'administer advanced forum' => array( |
15 |
'title' => t('Administer Advanced Forum') |
|
14 |
'title' => t('Administer Advanced Forum'),
|
|
16 | 15 |
), |
17 | 16 |
'view forum statistics' => array( |
18 |
'title' => t('View Advanced Forum statistics') |
|
17 |
'title' => t('View Advanced Forum statistics'),
|
|
19 | 18 |
), |
20 | 19 |
'view last edited notice' => array( |
21 |
'title' => t('View last edited notice') |
|
20 |
'title' => t('View last edited notice'),
|
|
22 | 21 |
) |
23 | 22 |
); |
24 | 23 |
} |
25 | 24 |
|
26 | 25 |
/** |
27 |
* Implementation of hook_menu().
|
|
26 |
* Implements hook_menu().
|
|
28 | 27 |
*/ |
29 | 28 |
function advanced_forum_menu() { |
30 | 29 |
$items['admin/config/content/advanced-forum'] = array( |
... | ... | |
33 | 32 |
'page arguments' => array('advanced_forum_settings_page'), |
34 | 33 |
'page callback' => 'drupal_get_form', |
35 | 34 |
'title' => 'Advanced Forum', |
36 |
'file' => 'includes/settings.inc' |
|
35 |
'file' => 'includes/settings.inc',
|
|
37 | 36 |
); |
38 | 37 |
|
39 | 38 |
$items['forum/markasread'] = array( |
... | ... | |
55 | 54 |
} |
56 | 55 |
|
57 | 56 |
/** |
58 |
* Implementation of hook_cron().
|
|
57 |
* Implements hook_cron().
|
|
59 | 58 |
*/ |
60 | 59 |
function advanced_forum_cron() { |
61 |
// ensure the reply stats are up-to-date
|
|
60 |
// Ensure the reply stats are up-to-date.
|
|
62 | 61 |
advanced_forum_statistics_replies(NULL, TRUE); |
63 | 62 |
} |
64 | 63 |
|
65 | 64 |
/** |
66 |
* Implementation of hook_menu_alter().
|
|
65 |
* Implements hook_menu_alter().
|
|
67 | 66 |
*/ |
68 | 67 |
function advanced_forum_menu_alter(&$items) { |
69 | 68 |
// Take over the forum page creation so we can add more information. |
... | ... | |
71 | 70 |
$items['forum']['module'] = 'advanced_forum'; |
72 | 71 |
unset($items['forum']['file']); |
73 | 72 |
|
74 |
|
|
75 | 73 |
// Take over forum/%forum_forum page because we want advanced_forum_forum_load |
76 | 74 |
// is called instead of core forum_forum_load |
77 | 75 |
$items['forum/%advanced_forum_forum'] = $items['forum/%forum_forum']; |
... | ... | |
93 | 91 |
} |
94 | 92 |
|
95 | 93 |
/** |
96 |
* Implementation of hook_module_implements_alter().
|
|
94 |
* Implements hook_module_implements_alter().
|
|
97 | 95 |
* |
98 | 96 |
* We don't want forum_menu_local_tasks_alter() to be called and mess with our links. |
99 |
* |
|
100 | 97 |
*/ |
101 | 98 |
function advanced_forum_module_implements_alter(&$implementations, $hook) { |
102 | 99 |
if ($hook == 'menu_local_tasks_alter') { |
... | ... | |
105 | 102 |
} |
106 | 103 |
|
107 | 104 |
/** |
108 |
* Implementation of hook_theme().
|
|
105 |
* Implements hook_theme().
|
|
109 | 106 |
*/ |
110 | 107 |
function advanced_forum_theme() { |
111 | 108 |
advanced_forum_load_style_includes(); |
112 | 109 |
|
113 |
// Bulk read all available (active) style templates |
|
110 |
// Bulk read all available (active) style templates.
|
|
114 | 111 |
$existing_items = advanced_forum_find_style_templates(); |
115 | 112 |
|
116 | 113 |
$items['advanced_forum_l'] = array( |
... | ... | |
119 | 116 |
'path' => NULL, |
120 | 117 |
'options' => array(), |
121 | 118 |
'button_class' => NULL, |
122 |
) |
|
119 |
),
|
|
123 | 120 |
); |
124 | 121 |
|
125 | 122 |
$items['advanced_forum_topic_header'] = array( |
126 | 123 |
'variables' => array( |
127 | 124 |
'node' => NULL, |
128 | 125 |
'comment_count' => NULL, |
129 |
) |
|
126 |
),
|
|
130 | 127 |
); |
131 | 128 |
|
132 | 129 |
$items['advanced_forum_active_poster'] = array( |
... | ... | |
136 | 133 |
'posts' => NULL, |
137 | 134 |
'topics' => NULL, |
138 | 135 |
'last_post' => NULL, |
139 |
) |
|
136 |
),
|
|
140 | 137 |
); |
141 | 138 |
|
142 | 139 |
$items['advanced_forum_user_picture'] = array( |
143 | 140 |
'variables' => array( |
144 | 141 |
'account' => NULL, |
145 |
) |
|
142 |
),
|
|
146 | 143 |
); |
147 | 144 |
|
148 | 145 |
$items['advanced_forum_reply_link'] = array( |
149 | 146 |
'variables' => array( |
150 | 147 |
'node' => NULL, |
151 |
) |
|
148 |
),
|
|
152 | 149 |
); |
153 | 150 |
|
154 | 151 |
$items['advanced_forum_topic_pager'] = array( |
155 | 152 |
'variables' => array( |
156 | 153 |
'pagecount' => NULL, |
157 | 154 |
'topic' => NULL, |
158 |
) |
|
155 |
),
|
|
159 | 156 |
); |
160 | 157 |
|
161 | 158 |
$items['advanced_forum_shadow_topic'] = array( |
... | ... | |
163 | 160 |
'title' => NULL, |
164 | 161 |
'nid' => NULL, |
165 | 162 |
'new_forum' => NULL, |
166 |
) |
|
163 |
),
|
|
167 | 164 |
); |
168 | 165 |
|
169 | 166 |
$items['advanced_forum_subforum_list'] = array( |
170 | 167 |
'variables' => array( |
171 | 168 |
'subforum_list' => NULL, |
172 |
) |
|
169 |
),
|
|
173 | 170 |
); |
174 | 171 |
|
175 | 172 |
$items['advanced_forum_subcontainer_list'] = array( |
176 | 173 |
'variables' => array( |
177 | 174 |
'subcontainer_list' => NULL, |
178 |
) |
|
175 |
),
|
|
179 | 176 |
); |
180 | 177 |
|
181 | 178 |
$items['advanced_forum_simple_author_pane'] = array( |
182 | 179 |
'variables' => array( |
183 | 180 |
'context' => NULL, |
184 |
) |
|
181 |
),
|
|
185 | 182 |
); |
186 | 183 |
|
187 | 184 |
$items['advanced_forum_post_edited'] = array( |
... | ... | |
189 | 186 |
'who' => NULL, |
190 | 187 |
'when' => NULL, |
191 | 188 |
'why' => NULL, |
192 |
) |
|
189 |
),
|
|
193 | 190 |
); |
194 | 191 |
|
195 | 192 |
$items['advanced_forum_node_type_create_list'] = array( |
196 | 193 |
'variables' => array( |
197 | 194 |
'forum_id' => NULL, |
198 |
) |
|
195 |
),
|
|
199 | 196 |
); |
200 | 197 |
/* |
201 |
// Templates for features added by Views
|
|
198 |
// Templates for features added by Views |
|
202 | 199 |
|
203 |
// style
|
|
204 |
$items['views_view_forum_topic_list__advanced_forum_topic_list'] = array(
|
|
205 |
'variables' => array('view' => NULL, 'options' => NULL, 'rows' => NULL, 'title' => NULL),
|
|
206 |
'template' => 'advanced-forum-topic-list-view',
|
|
207 |
//'base hook' => 'views_view_forum_topic_list',
|
|
208 |
);
|
|
200 |
// style |
|
201 |
$items['views_view_forum_topic_list__advanced_forum_topic_list'] = array( |
|
202 |
'variables' => array('view' => NULL, 'options' => NULL, 'rows' => NULL, 'title' => NULL), |
|
203 |
'template' => 'advanced-forum-topic-list-view', |
|
204 |
//'base hook' => 'views_view_forum_topic_list', |
|
205 |
); |
|
209 | 206 |
*/ |
210 |
//display
|
|
207 |
// Display.
|
|
211 | 208 |
$items['views_view__advanced_forum_topic_list'] = array( |
212 | 209 |
'variables' => array('view' => NULL), |
213 | 210 |
'template' => 'advanced-forum-topic-list-outer-view', |
214 |
//'base hook' => 'views_view', |
|
215 | 211 |
); |
216 | 212 |
|
217 |
//display group
|
|
213 |
// Display group.
|
|
218 | 214 |
$items['views_view__advanced_forum_group_topic_list'] = array( |
219 | 215 |
'variables' => array('view' => NULL), |
220 | 216 |
'template' => 'advanced-forum-group-topic-list-outer-view', |
221 |
//'base hook' => 'views_view', |
|
222 | 217 |
); |
223 | 218 |
|
224 | 219 |
// Return merged items found in style folder with new ones |
225 |
// array_merge_recursive doesn't work as desired |
|
220 |
// array_merge_recursive doesn't work as desired.
|
|
226 | 221 |
foreach ($items as $key => $item) { |
227 | 222 |
if (array_key_exists($key, $existing_items)) { |
228 | 223 |
$existing_items[$key] += $item; |
... | ... | |
236 | 231 |
} |
237 | 232 |
|
238 | 233 |
/** |
239 |
* Implementation of hook_theme_registry_alter().
|
|
234 |
* Implements hook_theme_registry_alter().
|
|
240 | 235 |
*/ |
241 | 236 |
function advanced_forum_theme_registry_alter(&$theme_registry) { |
242 | 237 |
advanced_forum_load_style_includes(); |
... | ... | |
274 | 269 |
// --- for the given templates can be found first in the (sub)theme directory |
275 | 270 |
// --- then in ancestor themes, if any, then in the active style directory |
276 | 271 |
// --- for advanced forum or any ancestor styles. |
277 |
// Affected templates |
|
272 |
// Affected templates.
|
|
278 | 273 |
$templates = array( |
279 | 274 |
'node', |
280 | 275 |
'comment', |
... | ... | |
294 | 289 |
'advanced_forum_active_poster', */ |
295 | 290 |
); |
296 | 291 |
|
297 |
// Get the sequence of styles to look in for templates |
|
292 |
// Get the sequence of styles to look in for templates.
|
|
298 | 293 |
$lineage = advanced_forum_style_lineage(); |
299 | 294 |
|
300 | 295 |
if (!array_key_exists('naked', $lineage)) { |
... | ... | |
303 | 298 |
$lineage['naked'] = drupal_get_path('module', 'advanced_forum') . '/styles/naked'; |
304 | 299 |
} |
305 | 300 |
|
306 |
// Get theme engine extension |
|
301 |
// Get theme engine extension.
|
|
307 | 302 |
global $theme_engine; |
308 | 303 |
$extension = '.tpl.php'; |
309 | 304 |
if (isset($theme_engine)) { |
... | ... | |
336 | 331 |
} |
337 | 332 |
} |
338 | 333 |
|
339 |
|
|
340 |
// temp workaround |
|
334 |
// Temp workaround. |
|
341 | 335 |
if (isset($theme_registry['views_view__advanced_forum_topic_list']['preprocess functions'])) { |
342 | 336 |
array_splice($theme_registry['views_view__advanced_forum_topic_list']['preprocess functions'], 1, 0, 'template_preprocess_views_view'); |
343 | 337 |
} |
344 | 338 |
if (isset($theme_registry['views_view__advanced_forum_group_topic_list']['preprocess functions'])) { |
345 | 339 |
array_splice($theme_registry['views_view__advanced_forum_group_topic_list']['preprocess functions'], 1, 0, 'template_preprocess_views_view'); |
346 | 340 |
} |
347 |
//array_splice($theme_registry['views_view_forum_topic_list__advanced_forum_topic_list']['preprocess functions'], 1, 0, 'template_preprocess_views_view_forum_topic_list'); |
|
348 | 341 |
} |
349 | 342 |
|
350 | 343 |
/** |
351 |
* Own link alteration implementaion because there are no |
|
352 |
* hook_link nor hook_link_alter in D7 |
|
344 |
* Own link alteration implementation because there are no hook_link nor hook_link_alter in D7. |
|
353 | 345 |
* |
354 | 346 |
* Name changed intentionally to avoid confusion with hook_link_alter! |
355 | 347 |
*/ |
356 | 348 |
function advanced_forum_links_alter(&$object, $view_mode, $object_type = 'node') { |
357 |
// Don't alter anything if in preview mode |
|
349 |
// Don't alter anything if in preview mode.
|
|
358 | 350 |
if (!empty($object->in_preview)) { |
359 | 351 |
return; |
360 | 352 |
} |
... | ... | |
398 | 390 |
$links['comment-add']['href'] = "comment/reply/$node->nid"; |
399 | 391 |
} |
400 | 392 |
|
401 |
|
|
402 | 393 |
// List the keys we are interested in. |
403 |
$affected_keys = array('post-edit', 'comment-edit', 'post-delete', 'comment-delete', 'quote', 'comment-add', 'comment-reply'); |
|
394 |
$affected_keys = array( |
|
395 |
'post-edit', |
|
396 |
'comment-edit', |
|
397 |
'post-delete', |
|
398 |
'comment-delete', |
|
399 |
'quote', |
|
400 |
'comment-add', |
|
401 |
'comment-reply', |
|
402 |
); |
|
404 | 403 |
|
405 | 404 |
// Add extra span tags for image replacement. |
406 |
foreach ($links AS $key => $link) {
|
|
405 |
foreach ($links as $key => $link) {
|
|
407 | 406 |
if (in_array($key, $affected_keys)) { |
408 | 407 |
$links[$key]['attributes']['class'][] = "af-button-small"; |
409 | 408 |
$links[$key]['title'] = '<span>' . $links[$key]['title'] . '</span>'; |
... | ... | |
420 | 419 |
} |
421 | 420 |
} |
422 | 421 |
|
423 |
// we want to put comment links last
|
|
422 |
// We want to put comment links last.
|
|
424 | 423 |
unset($object->content['links']['comment']); |
425 | 424 |
$object->content['links']['comment'] = $comment_links; |
426 | 425 |
|
427 |
// put links back
|
|
426 |
// Put links back.
|
|
428 | 427 |
$object->content['links']['comment']['#links'] = $links; |
429 | 428 |
} |
430 | 429 |
|
431 | 430 |
/** |
432 |
* Implementation of hook_node_view().
|
|
431 |
* Implements hook_node_view().
|
|
433 | 432 |
* |
434 |
* hook_link() and hook_link_alter() functionalty implemented here |
|
433 |
* hook_link() and hook_link_alter() functionality implemented here
|
|
435 | 434 |
*/ |
436 | 435 |
function advanced_forum_node_view($node, $view_mode, $langcode) { |
437 | 436 |
advanced_forum_links_alter($node, $view_mode, 'node'); |
438 | 437 |
} |
439 | 438 |
|
440 | 439 |
/** |
441 |
* Implementation of hook_comment_view().
|
|
440 |
* Implements hook_comment_view().
|
|
442 | 441 |
*/ |
443 | 442 |
function advanced_forum_comment_view($comment, $view_mode, $langcode) { |
444 | 443 |
advanced_forum_links_alter($comment, $view_mode, 'comment'); |
445 | 444 |
} |
446 | 445 |
|
447 | 446 |
/** |
448 |
* Implementation of hook_comment_delete().
|
|
447 |
* Implements hook_comment_delete().
|
|
449 | 448 |
*/ |
450 | 449 |
function advanced_forum_comment_delete($comment) { |
451 | 450 |
if (!empty($comment->node_type) && ($comment->node_type == "comment_node_forum")) { |
... | ... | |
454 | 453 |
} |
455 | 454 |
|
456 | 455 |
/** |
457 |
* Implementation of hook_comment_update().
|
|
456 |
* Implements hook_comment_update().
|
|
458 | 457 |
*/ |
459 | 458 |
function advanced_forum_comment_update($comment) { |
460 | 459 |
if (!empty($comment->node_type) && ($comment->node_type == "comment_node_forum")) { |
461 |
// comment unpublished?
|
|
460 |
// Comment unpublished?
|
|
462 | 461 |
if (!$comment->status) { |
463 | 462 |
advanced_forum_statistics_replies(-1); |
464 | 463 |
} |
... | ... | |
466 | 465 |
} |
467 | 466 |
|
468 | 467 |
/** |
469 |
* Implementation of hook_comment_publish().
|
|
468 |
* Implements hook_comment_publish().
|
|
470 | 469 |
*/ |
471 | 470 |
function advanced_forum_comment_publish($comment) { |
472 | 471 |
if (!empty($comment->node_type) && ($comment->node_type == "comment_node_forum")) { |
... | ... | |
475 | 474 |
} |
476 | 475 |
|
477 | 476 |
/** |
478 |
* Implementation of hook_form_alter().
|
|
477 |
* Implements hook_form_alter().
|
|
479 | 478 |
*/ |
480 | 479 |
function advanced_forum_form_alter(&$form, &$form_state, $form_id) { |
481 | 480 |
if (!empty($form['#node']->type) && advanced_forum_type_is_in_forum($form['#node']) && isset($form['body_field']) && isset($form['body_field']['#after_build'])) { |
... | ... | |
492 | 491 |
} |
493 | 492 |
} |
494 | 493 |
|
495 |
// MAKE VIEWS BITS WORK *****************************************************/ |
|
494 |
/** |
|
495 |
* Implements hook_views_api(). |
|
496 |
*/ |
|
496 | 497 |
function advanced_forum_views_api() { |
497 | 498 |
return array( |
498 | 499 |
'api' => '3.0-alpha1', |
... | ... | |
500 | 501 |
); |
501 | 502 |
} |
502 | 503 |
|
503 |
// MAKE CTOOLS BITS WORK *****************************************************/ |
|
504 | 504 |
/** |
505 | 505 |
* Tell CTools about what plugins we support. |
506 | 506 |
*/ |
... | ... | |
514 | 514 |
} |
515 | 515 |
} |
516 | 516 |
|
517 |
/** |
|
518 |
* Implements hook_ctools_plugin_api(). |
|
519 |
*/ |
|
517 | 520 |
function advanced_forum_ctools_plugin_api($module, $api) { |
518 | 521 |
if ($module == 'page_manager' && $api = 'pages_default') { |
519 | 522 |
return array( |
... | ... | |
536 | 539 |
module_load_include('inc', 'advanced_forum', 'includes/mark-read'); |
537 | 540 |
|
538 | 541 |
// VIEWS RELATED GOODIES ******************************************************/ |
539 |
|
|
540 | 542 |
/** |
541 | 543 |
* Post render a view and replace any advanced forum tokens. |
542 | 544 |
*/ |
... | ... | |
557 | 559 |
// Replace the Author Pane token with the actual Author Pane. |
558 | 560 |
if (preg_match_all('/<!--post:author-pane-([\d]+)-->/us', $output, $matches)) { |
559 | 561 |
foreach ($matches[1] as $match => $uid) { |
560 |
$token = $matches[0][$match]; // This is the exact string that matched. |
|
562 |
// This is the exact string that matched. |
|
563 |
$token = $matches[0][$match]; |
|
561 | 564 |
if (!isset($tokens[$token])) { |
562 | 565 |
$account = user_load($uid); |
563 | 566 |
$tokens[$token] = theme('author_pane', array( |
... | ... | |
575 | 578 |
// Replace the Post edited token. |
576 | 579 |
if (preg_match_all('/<!--post:post-edited-([\d]+)-->/us', $output, $matches)) { |
577 | 580 |
foreach ($matches[1] as $match => $nid) { |
578 |
$token = $matches[0][$match]; // This is the exact string that matched. |
|
581 |
// This is the exact string that matched. |
|
582 |
$token = $matches[0][$match]; |
|
579 | 583 |
if (!isset($tokens[$token])) { |
580 | 584 |
if (user_access('view last edited notice')) { |
581 | 585 |
$sql = 'SELECT uid, log, timestamp FROM {node_revision} WHERE nid = %d ORDER BY timestamp DESC'; |
... | ... | |
597 | 601 |
// Replace the core Signature token. |
598 | 602 |
if (preg_match_all('/<!--post:signature-core-([\d]+)-->/us', $output, $matches)) { |
599 | 603 |
foreach ($matches[1] as $match => $uid) { |
600 |
$token = $matches[0][$match]; // This is the exact string that matched. |
|
604 |
// This is the exact string that matched. |
|
605 |
$token = $matches[0][$match]; |
|
601 | 606 |
if (!isset($tokens[$token])) { |
602 | 607 |
$account = user_load($uid); |
603 | 608 |
if ($account->signature) { |
... | ... | |
613 | 618 |
} |
614 | 619 |
|
615 | 620 |
/** |
616 |
* Display the "sort" widget. This is a specially hacked widget that only |
|
621 |
* Display the "sort" widget. |
|
622 |
* |
|
623 |
* This is a specially hacked widget that only |
|
617 | 624 |
* works with tablesorting. Tablesorting MUST be on for these widgets |
618 | 625 |
* to appear. |
619 | 626 |
*/ |
... | ... | |
630 | 637 |
return drupal_render($form); |
631 | 638 |
} |
632 | 639 |
|
640 |
/** |
|
641 |
* Sort form. |
|
642 |
*/ |
|
633 | 643 |
function advanced_forum_forum_topic_list_sort_form($form_state) { |
634 | 644 |
$view = views_get_view('advanced_forum_topic_list'); |
635 | 645 |
$view->set_display('default'); |
... | ... | |
701 | 711 |
} |
702 | 712 |
|
703 | 713 |
// STATISTICS *****************************************************************/ |
704 |
|
|
705 | 714 |
/** |
706 | 715 |
* Count total amount of forum threads. |
707 | 716 |
*/ |
... | ... | |
710 | 719 |
} |
711 | 720 |
|
712 | 721 |
/** |
713 |
* Counts total amount of replies. Initial posts are added to this total |
|
714 |
* in the calling function. |
|
722 |
* Counts total amount of replies. |
|
723 |
* |
|
724 |
* Initial posts are added to this total in the calling function. |
|
715 | 725 |
* |
716 |
* @param $delta |
|
726 |
* @param int|null $delta
|
|
717 | 727 |
* if not NULL, a numerical delta which should be applied to the count |
718 |
* @param $refresh
|
|
719 |
* @param $refresh |
|
728 |
* |
|
729 |
* @param bool $refresh
|
|
720 | 730 |
* TRUE if the stored count should be updated. |
721 |
* @return |
|
731 |
* |
|
732 |
* @return int |
|
722 | 733 |
* Total number of replies in the forum. |
723 | 734 |
*/ |
724 | 735 |
function advanced_forum_statistics_replies($delta = NULL, $refresh = FALSE) { |
... | ... | |
731 | 742 |
$total_replies = $cache->data; |
732 | 743 |
} |
733 | 744 |
|
734 |
|
|
735 | 745 |
if (!empty($delta) && is_numeric($delta)) { |
736 | 746 |
$total_replies += $delta; |
737 | 747 |
cache_set('advanced_forum_stats_replies', $total_replies); |
... | ... | |
751 | 761 |
* Return the newest X active (not blocked) users, linked to their profiles. |
752 | 762 |
*/ |
753 | 763 |
function advanced_forum_statistics_latest_users() { |
754 |
$number_to_fetch = 5; // @TODO: Make this a setting. |
|
764 |
// @TODO: Make this a setting. |
|
765 |
$number_to_fetch = 5; |
|
755 | 766 |
|
756 | 767 |
$query = db_select("users", "u") |
757 | 768 |
->fields("u", array("uid", "name")) |
... | ... | |
767 | 778 |
return $list; |
768 | 779 |
} |
769 | 780 |
|
781 |
/** |
|
782 |
* Returns session count. |
|
783 |
*/ |
|
770 | 784 |
function advanced_forum_session_count($anonymous = TRUE) { |
771 | 785 |
|
772 | 786 |
$interval = REQUEST_TIME - variable_get('user_block_seconds_online', 900); |
... | ... | |
808 | 822 |
return $list; |
809 | 823 |
} |
810 | 824 |
|
811 |
// CALCULATING LINKS - New, Last, Etc *****************************************/ |
|
812 |
|
|
825 |
/** |
|
826 |
* Calculating links - New, Last, Etc. |
|
827 |
*/ |
|
813 | 828 |
function advanced_forum_get_reply_link($node) { |
814 | 829 |
$reply_link = array(); |
815 | 830 |
|
... | ... | |
820 | 835 |
|
821 | 836 |
$allowed = FALSE; |
822 | 837 |
if (module_exists('forum_access')) { |
823 |
// get tid
|
|
838 |
// Get tid.
|
|
824 | 839 |
if (!empty($node->taxonomy_forums)) { |
825 | 840 |
reset($node->taxonomy_forums); |
826 | 841 |
$langcode = key($node->taxonomy_forums); |
... | ... | |
854 | 869 |
$reply_link['href'] = $_GET['q']; |
855 | 870 |
$reply_link['options']['fragment'] = $fragment; |
856 | 871 |
$current_page = isset($_GET['page']) ? $_GET['page'] : 0; |
857 |
if ($current_page) |
|
872 |
if ($current_page) {
|
|
858 | 873 |
$reply_link['options']['query'] = array('page' => $current_page); |
874 |
} |
|
859 | 875 |
|
860 | 876 |
$reply_link['class'] = 'reply-allowed'; |
861 | 877 |
$reply_link['title'] = t('Quick reply'); |
... | ... | |
877 | 893 |
/** |
878 | 894 |
* Get a link to the last post in a topic. |
879 | 895 |
* |
880 |
* @param $node |
|
896 |
* @param object $node
|
|
881 | 897 |
* Node object |
882 |
* @return |
|
898 |
* |
|
899 |
* @return string |
|
883 | 900 |
* Text linking to the last post in a topic. |
884 | 901 |
*/ |
885 | 902 |
function advanced_forum_last_post_link($node) { |
886 | 903 |
$last_comment_id = advanced_forum_last_post_in_topic($node->nid); |
887 | 904 |
// Return empty link if post doesn't have comments. |
888 |
if (empty($last_comment_id)) |
|
905 |
if (empty($last_comment_id)) {
|
|
889 | 906 |
return ''; |
907 |
} |
|
890 | 908 |
|
891 | 909 |
$last_page = advanced_forum_get_last_page($node); |
892 | 910 |
|
893 |
if ($last_page > 0) |
|
911 |
if ($last_page > 0) {
|
|
894 | 912 |
$query = array('page' => $last_page); |
913 |
} |
|
895 | 914 |
|
896 | 915 |
$options = array( |
897 | 916 |
'html' => TRUE, |
... | ... | |
910 | 929 |
/** |
911 | 930 |
* Returns a link directly to the first new post in a topic. |
912 | 931 |
* |
913 |
* @param $node |
|
932 |
* @param object $node
|
|
914 | 933 |
* Node object |
915 |
* @param $comment_count |
|
934 |
* |
|
935 |
* @param int $comment_count |
|
916 | 936 |
* Number of comments on passed node. |
917 |
* @return |
|
937 |
* |
|
938 |
* @return string |
|
918 | 939 |
* Link to the first unread post. |
919 | 940 |
*/ |
920 | 941 |
function advanced_forum_first_new_post_link($node, $comment_count) { |
... | ... | |
935 | 956 |
$options = array( |
936 | 957 |
'html' => TRUE, |
937 | 958 |
'query' => $page_of_first_new, |
938 |
'fragment' => "comment-$cid_of_first_new" |
|
959 |
'fragment' => "comment-$cid_of_first_new",
|
|
939 | 960 |
); |
940 | 961 |
|
941 | 962 |
return theme('advanced_forum_l', array( |
942 | 963 |
'text' => t('First unread'), |
943 | 964 |
'path' => "node/$nid", |
944 | 965 |
'options' => $options, |
945 |
'button_class' => 'large' |
|
966 |
'button_class' => 'large',
|
|
946 | 967 |
)); |
947 | 968 |
} |
948 | 969 |
} |
... | ... | |
963 | 984 |
static $number_new_for_node = array(); |
964 | 985 |
|
965 | 986 |
// $nid is empty if new topic in preview. |
966 |
if (empty($nid)) |
|
987 |
if (empty($nid)) {
|
|
967 | 988 |
return 0; |
989 |
} |
|
968 | 990 |
|
969 | 991 |
if (empty($number_new_for_node[$nid])) { |
970 | 992 |
global $user; |
971 | 993 |
|
972 | 994 |
$node = node_load($nid); |
973 | 995 |
|
974 |
// We must also check the forum post itself to see if we have viewed it |
|
975 |
$viewed = 0; // If not told otherwise, it has been viewed before |
|
996 |
// We must also check the forum post itself to see if we have viewed it. |
|
997 |
// If not told otherwise, it has been viewed before. |
|
998 |
$viewed = 0; |
|
976 | 999 |
if ($user->uid) { |
977 | 1000 |
$viewed = node_last_viewed($nid); |
978 | 1001 |
// Set it to 1 if it has not been viewed before. |
... | ... | |
988 | 1011 |
/** |
989 | 1012 |
* Get the comment id of the last post in a topic. |
990 | 1013 |
* |
991 |
* @param $node |
|
992 |
* Node object |
|
993 |
* @return |
|
1014 |
* @param int $nid |
|
1015 |
* Node id. |
|
1016 |
* |
|
1017 |
* @return int |
|
994 | 1018 |
* cid of last post. |
995 | 1019 |
*/ |
996 | 1020 |
function advanced_forum_last_post_in_topic($nid) { |
997 | 1021 |
// $nid is empty if new topic in preview. |
998 |
if (empty($nid)) |
|
1022 |
if (empty($nid)) {
|
|
999 | 1023 |
return NULL; |
1024 |
} |
|
1000 | 1025 |
|
1001 | 1026 |
$node = node_load($nid); |
1002 | 1027 |
|
1003 |
// Comment module version |
|
1028 |
// Comment module version.
|
|
1004 | 1029 |
$query = 'SELECT c.cid |
1005 | 1030 |
FROM {comment} c |
1006 | 1031 |
WHERE c.nid = :nid AND c.status = :status |
... | ... | |
1023 | 1048 |
/** |
1024 | 1049 |
* Returns the ID of the first unread comment. |
1025 | 1050 |
* |
1026 |
* @param $nid |
|
1051 |
* @param int $nid
|
|
1027 | 1052 |
* Node ID |
1028 |
* @param $timestamp |
|
1053 |
* |
|
1054 |
* @param int $timestamp |
|
1029 | 1055 |
* Date/time used to override when the user last viewed the node. |
1030 |
* @return |
|
1056 |
* |
|
1057 |
* @return int |
|
1031 | 1058 |
* Comment ID |
1032 | 1059 |
*/ |
1033 | 1060 |
function advanced_forum_first_new_comment($nid, $timestamp = 0) { |
... | ... | |
1040 | 1067 |
$timestamp = node_last_viewed($nid); |
1041 | 1068 |
} |
1042 | 1069 |
|
1043 |
// Set the timestamp to the limit if the node was last read past the cutoff |
|
1070 |
// Set the timestamp to the limit if the node was last read past the cutoff.
|
|
1044 | 1071 |
$timestamp = ($timestamp > NODE_NEW_LIMIT ? $timestamp : NODE_NEW_LIMIT); |
1045 | 1072 |
|
1046 | 1073 |
// Use the timestamp to retrieve the oldest new comment. |
... | ... | |
1059 | 1086 |
} |
1060 | 1087 |
|
1061 | 1088 |
// GENERAL UTILITY FUNCTIONS *************************************************/ |
1062 |
|
|
1063 | 1089 |
/** |
1064 | 1090 |
* Return an array of node types allowed in a given vocabulary or term ID. |
1065 | 1091 |
*/ |
... | ... | |
1087 | 1113 |
function advanced_forum_type_is_in_forum($node, $tid = 0) { |
1088 | 1114 |
$vid = (empty($vid)) ? variable_get('forum_nav_vocabulary', 0) : $vid; |
1089 | 1115 |
if (!empty($node->taxonomy_forums)) { |
1090 |
// Check for language used |
|
1116 |
// Check for language used.
|
|
1091 | 1117 |
if (!isset($node->taxonomy_forums[$node->language])) { |
1092 | 1118 |
$langcode = LANGUAGE_NONE; |
1093 | 1119 |
} |
... | ... | |
1099 | 1125 |
if (!isset($tforum['taxonomy_term'])) { |
1100 | 1126 |
continue; |
1101 | 1127 |
} |
1102 |
if (($tforum['taxonomy_term']->vid == $vid) || ($tforum['taxonomy_term']->tid == $tid)) |
|
1128 |
if (($tforum['taxonomy_term']->vid == $vid) || ($tforum['taxonomy_term']->tid == $tid)) {
|
|
1103 | 1129 |
return TRUE; |
1130 |
} |
|
1104 | 1131 |
} |
1105 | 1132 |
} |
1106 | 1133 |
return FALSE; |
... | ... | |
1206 | 1233 |
/** |
1207 | 1234 |
* Creates a pager to place on each multi-page topic of the topic listing page. |
1208 | 1235 |
* |
1209 |
* @param $max_pages_to_display |
|
1236 |
* @param int $max_pages_to_display
|
|
1210 | 1237 |
* Number of pages to include on the pager. |
1211 |
* @param $topic |
|
1238 |
* |
|
1239 |
* @param object $topic |
|
1212 | 1240 |
* Topic object to create a pager for. |
1213 |
* @return |
|
1241 |
* |
|
1242 |
* @return object |
|
1214 | 1243 |
* Object containing the linked pages ready assembly by the theme function. |
1215 | 1244 |
*/ |
1216 | 1245 |
function advanced_forum_create_topic_pager($max_pages_to_display, $topic) { |
... | ... | |
1222 | 1251 |
// first page because that doesn't have a query. |
1223 | 1252 |
$pager_array = array(); |
1224 | 1253 |
$current_display_page = 1; |
1254 |
// @codingStandardsIgnoreStart |
|
1225 | 1255 |
$pager_array[0] = l('1', "node/$topic->nid"); |
1256 |
// @codingStandardsIgnoreEnd |
|
1226 | 1257 |
|
1227 | 1258 |
// Find the ending point. The pager URL is always 1 less than |
1228 | 1259 |
// the number being displayed because the first page is 0. |
... | ... | |
1231 | 1262 |
|
1232 | 1263 |
// Add pages until we run out or until we hit the max to show. |
1233 | 1264 |
while (($current_display_page < $last_display_page) && ($current_display_page < $max_pages_to_display)) { |
1234 |
// Move to the next page |
|
1265 |
// Move to the next page.
|
|
1235 | 1266 |
$current_display_page++; |
1236 | 1267 |
|
1237 |
// The page number we link to is 1 less than what's displayed |
|
1268 |
// The page number we link to is 1 less than what's displayed.
|
|
1238 | 1269 |
$link_to_page = $current_display_page - 1; |
1239 | 1270 |
|
1240 |
// Add the link to the array |
|
1271 |
// Add the link to the array.
|
|
1241 | 1272 |
$pager_array[$link_to_page] = l($current_display_page, "node/$topic->nid", array('query' => array('page' => $link_to_page))); |
1242 | 1273 |
} |
1243 | 1274 |
|
1244 |
// Move to the next page |
|
1275 |
// Move to the next page.
|
|
1245 | 1276 |
$current_display_page++; |
1246 | 1277 |
|
1247 | 1278 |
if ($current_display_page == $last_display_page) { |
... | ... | |
1276 | 1307 |
} |
1277 | 1308 |
|
1278 | 1309 |
/** |
1279 |
* Create a drop down list of forum hierarchy |
|
1310 |
* Create a drop down list of forum hierarchy.
|
|
1280 | 1311 |
*/ |
1281 | 1312 |
function advanced_forum_forum_jump($tid = 0) { |
1282 | 1313 |
global $user; |
... | ... | |
1290 | 1321 |
$select[url("forum/" . $forum->tid)] = str_repeat("-", $forum->depth) . $forum->name; |
1291 | 1322 |
} |
1292 | 1323 |
} |
1293 |
else { |
|
1294 |
// nothing |
|
1295 |
} |
|
1296 | 1324 |
|
1297 | 1325 |
$options['choose'] = t("- Select a forum -"); |
1298 | 1326 |
|
... | ... | |
1302 | 1330 |
} |
1303 | 1331 |
|
1304 | 1332 |
/** |
1305 |
* Calculates the number of unread replies for each forum and returns the |
|
1306 |
* count for the requested forum. |
|
1333 |
* Calculates the number of unread replies for each forum and returns the count for the requested forum. |
|
1307 | 1334 |
*/ |
1308 | 1335 |
function advanced_forum_unread_replies_in_forum($tid, $uid) { |
1309 | 1336 |
static $result_cache = NULL; |
... | ... | |
1313 | 1340 |
|
1314 | 1341 |
$query = db_select("comment", "c"); |
1315 | 1342 |
$f_alias = $query->join("forum", "f", "c.nid = f.nid"); |
1316 |
//$n_alias = $query->join("node", "n", "f.vid = n.vid"); |
|
1317 | 1343 |
$h_alias = $query->leftJoin("history", "h", "c.nid = h.nid AND h.uid = :uid", array(":uid" => $uid)); |
1318 | 1344 |
$query->addExpression("COUNT(DISTINCT(c.cid))", "count"); |
1319 | 1345 |
$query->addField($f_alias, "tid"); |
... | ... | |
1382 | 1408 |
if (($index = array_search($post_id, $post_order[$node_id])) !== FALSE) { |
1383 | 1409 |
$post_position = $index; |
1384 | 1410 |
|
1385 |
// We need to add 2 because the array starts at 0 and also because the topic |
|
1386 |
// node is post #1 on display but is not included in the index. |
|
1387 |
$post_position = $post_position + 2; |
|
1411 |
$advanced_forum_styled_node_types = variable_get('advanced_forum_styled_node_types', array('forum')); |
|
1412 |
// We need to add 1 because the topic node is post #1 on display but is not included in the index. |
|
1413 |
if (in_array($node->type, $advanced_forum_styled_node_types)) { |
|
1414 |
$post_position = $post_position + 1; |
|
1415 |
} |
|
1388 | 1416 |
} |
1389 | 1417 |
} |
1390 | 1418 |
|
Formats disponibles : Unified diff
Weekly update of contrib modules