/
AJAXChatIntegration.php
134 lines (106 loc) · 3.48 KB
/
AJAXChatIntegration.php
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
133
134
<?php
if (!defined('SMF'))
die('Hacking attempt...');
function ajaxchat_getOnlineUsers()
{
global $smcFunc;
$result = $smcFunc['db_query']('', '
SELECT userID
FROM {db_prefix}ajaxchat_online
WHERE NOW() <= DATE_ADD(dateTime, interval 2 MINUTE)' ,
array()
);
$userIDs = array();
while($row = $smcFunc['db_fetch_assoc']($result)) {
array_push($userIDs, $row['userID']);
}
$smcFunc['db_free_result']($result);
return array_unique($userIDs);
}
function ajaxchat_getOnlineUserLinks($userIDs = null)
{
global $scripturl, $smcFunc;
$userIDs = (!is_null($userIDs) ? $userIDs : ajaxchat_getOnlineUsers());
if (empty($userIDs))
return array();
$result = $smcFunc['db_query']('', '
SELECT mem.ID_MEMBER, mem.real_name, mem.ID_GROUP, mg.online_color, mg.ID_GROUP
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}membergroups AS mg
ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))
WHERE mem.ID_MEMBER' . (count($userIDs) == 1 ? ' = {int:user_ids}' : ' IN ({array_int:user_ids})'),
array(
'user_ids' => (count($userIDs) == 1 ? $userIDs[0] : $userIDs),
)
);
$user_links = array();
while ($row = $smcFunc['db_fetch_assoc']($result)) {
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'];
if($row['online_color']) {
$link .= '" style="color: ' . $row['online_color'];
}
$link .= '">' . $row['real_name'] . '</a>';
array_push($user_links, $link);
}
$smcFunc['db_free_result']($result);
return $user_links;
}
function ajaxchat_getOnlineUserTxt($user_links, $join = ': ')
{
global $txt;
$n_users = count($user_links);
if ($n_users == 0)
return $txt['chat_no_user'];
elseif ($n_users == 1)
return '1' . $txt['chat_aUser'] . $join . implode($user_links);
else
return $n_users . $txt['chat_users']. $join . implode(', ', $user_links);
}
function ajaxchat_modifySettings($return_config = false)
{
global $txt, $scripturl, $context, $settings, $sc, $modSettings;
$config_vars = array(
array('check', 'enableShoutBox'),
array('check', 'anyPageShoutBox'),
array('check', 'enableChatButtonNo'),
);
if ($return_config)
return $config_vars;
$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=chat';
$context['settings_title'] = $txt['chat'];
// No removing this line you, dirty unwashed mod authors. :p
if (empty($config_vars)) {
$context['settings_save_dont_show'] = true;
$context['settings_message'] = '<div style="text-align: center">' . $txt['modification_no_misc_settings'] . '</div>';
return prepareDBSettingContext($config_vars);
}
// Saving?
if (isset($_GET['save'])) {
checkSession();
$save_vars = $config_vars;
saveDBSettings($save_vars);
redirectexit('action=admin;area=modsettings;sa=chat');
}
prepareDBSettingContext($config_vars);
}
function ajaxchat_getShoutBoxContent()
{
global $scripturl, $modSettings;
// Get the URL to the chat directory:
if (!defined('AJAX_CHAT_URL'))
define('AJAX_CHAT_URL', str_replace("index.php", "chat/", $scripturl));
// Get the real path to the chat directory:
if (!defined('AJAX_CHAT_PATH'))
define('AJAX_CHAT_PATH', dirname(dirname(__FILE__)) . '/chat/');
// Validate the path to the chat:
if (@is_file(AJAX_CHAT_PATH . 'lib/classes.php')) {
// Include Class libraries:
require_once(AJAX_CHAT_PATH.'lib/classes.php');
// Initialize the shoutbox:
$ajaxChat = new CustomAJAXChatShoutBox();
// Parse and return the shoutbox template content:
return $ajaxChat->getShoutBoxContent(false);
}
return null;
}
?>