-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow_moderators.php
More file actions
132 lines (111 loc) · 4.27 KB
/
Copy pathshow_moderators.php
File metadata and controls
132 lines (111 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
if (!defined('PHORUM')) return;
require_once('./mods/show_moderators/defaults.php');
// Generate the template data for the index page and handle automatic
// displaying of moderators on the index page.
function phorum_mod_show_moderators_index($data)
{
$PHORUM = $GLOBALS['PHORUM'];
// Determine the template file to use for automatic displaying.
if (!empty($PHORUM['mod_show_moderators']['show_on_index'])) {
$template = phorum_get_template('show_moderators::index');
}
foreach ($data as $id => $forum)
{
if (empty($forum['folder_flag']))
{
// Retrieve the list of moderators.
$moderators = mod_show_moderators_get_list($forum['forum_id']);
// Add the moderator list in the forum data.
$data[$id]['MODERATORS'] = $moderators;
$data[$id]['MODERATOR_COUNT'] = count($moderators);
// In case automatic displaying is enabled, then add the
// moderator(s) to the message description.
if (!empty($PHORUM['mod_show_moderators']['show_on_index']))
{
$PHORUM['DATA']['MODERATORS'] = $moderators;
$PHORUM['DATA']['MODERATOR_COUNT'] = count($moderators);
ob_start();
include($template);
$data[$id]['description'] .= ob_get_contents();
ob_end_clean();
}
}
}
return $data;
}
// Generate the template data for the list page.
function phorum_mod_show_moderators_list($data)
{
$PHORUM = $GLOBALS['PHORUM'];
$moderators = mod_show_moderators_get_list($PHORUM['forum_id']);
$GLOBALS['PHORUM']['DATA']['MODERATORS'] = $moderators;
$GLOBALS['PHORUM']['DATA']['MODERATOR_COUNT'] = count($moderators);
return $data;
}
// Generate the template data for the read page.
function phorum_mod_show_moderators_read($data)
{
$PHORUM = $GLOBALS['PHORUM'];
$moderators = mod_show_moderators_get_list($PHORUM['forum_id']);
$GLOBALS['PHORUM']['DATA']['MODERATORS'] = $moderators;
$GLOBALS['PHORUM']['DATA']['MODERATOR_COUNT'] = count($moderators);
return $data;
}
// Handle automatic displaying of moderators for the list and read pages.
function phorum_mod_show_moderators_before_footer()
{
global $PHORUM;
if ( (phorum_page == 'list' &&
!empty($PHORUM['mod_show_moderators']['show_on_list'])) ||
(phorum_page == 'read' &&
!empty($PHORUM['mod_show_moderators']['show_on_read'])) ) {
include(phorum_get_template('show_moderators::footer'));
}
}
/**
* Retrieve the moderators for a given forum.
*
* @param integer $forum_id
* The id of the forum for which to retrieve the moderator list.
*
* @return array
* An array of moderators for the forum.
*
*/
function mod_show_moderators_get_list($forum_id)
{
$PHORUM = $GLOBALS['PHORUM'];
$no_admins = empty($PHORUM['mod_show_moderators']['include_admins']) ? 1:0;
$cache_type = 'show_moderators';
$cache_key = $forum_id . '-' . $no_admins;
$moderators = NULL;
// Try to retrieve the moderator list from the cache.
if (!empty($PHORUM['mod_show_moderators']['cache'])) {
$moderators = phorum_cache_get($cache_type, $cache_key);
}
// No info read from cache. Load the list from the database.
if ($moderators === NULL)
{
$moderators = phorum_api_user_list_moderators($forum_id, $no_admins);
if (!empty($moderators)) {
$users = phorum_api_user_get(array_keys($moderators));
$moderators = array();
foreach($users as $id => $user) {
$display_name = empty($PHORUM["custom_display_name"]) ? htmlspecialchars($user["display_name"], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]) : $user["display_name"];
$profile_url = phorum_get_url(PHORUM_PROFILE_URL, $id);
$moderators[$id] = array(
'DISPLAY_NAME' => $display_name,
'PROFILE' => $profile_url
);
}
}
// Store the list in the cache.
if (!empty($PHORUM['mod_show_moderators']['cache'])) {
$ttl = $PHORUM['mod_show_moderators']['cache'];
phorum_cache_put($cache_type, $cache_key, $moderators, $ttl);
}
}
return $moderators;
}
?>