-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper-iflychat.php
266 lines (239 loc) · 7.59 KB
/
helper-iflychat.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
require_once('LogInOut.php');
include_once "../SSI.php";
function iflychat_get_option($optionName)
{
global $modSettings;
if (isset($modSettings[$optionName])) {
return $modSettings[$optionName];
} else {
return;
}
}
function iflychat_get_user_pic_url()
{
global $user_info, $modSettings, $settings;
$url = '';
if ($modSettings['iflychat_theme'] == 1) {
$iflychat_theme = 'light';
} else {
$iflychat_theme = 'dark';
}
$pUrl = $modSettings['avatar_url'] . '/' . $user_info['avatar']['url'];
if (empty($user_info['avatar']['url']) && empty($user_info['avatar']['filename'])) {
$url = "{$settings['default_theme_url']}/iflychat/themes/{$iflychat_theme}/images/default_avatar.png";
} else if (!empty($user_info['avatar']['filename'])){
// return ($modSettings['avatar_url'] . '/' . $user_info['avatar']['filename']);
$idMember = $user_info['id'];
$res = ssi_fetchMember([$idMember], null);
return $res[$idMember]['avatar']['href'];
} else if (substr($user_info['avatar']['url'], 0, 4) === "http") {
return ($user_info['avatar']['url']);
} else {
return $pUrl;
}
}
function iflychat_get_user_profile_url()
{
global $user_info;
$id = $user_info['id'];
$upl = getUserUrl($id);
if ($upl !== 'javascript:void(0);') {
$pos = strpos($upl, ':');
if ($pos !== false) {
$upl = substr($upl, $pos + 1);
}
}
return $upl;
}
function iflychat_compute_guest_session($id)
{
global $modSettings;
return md5(substr($modSettings['iflychat_external_api_key'], 0, 5) . $id);
}
function check_plain($text)
{
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}
function iflychat_get_random_name()
{
global $settings;
$path = "{$settings['default_theme_url']}/iflychat/guest_names/iflychat_guest_random_names.txt";
$f_contents = file($path);
$line = trim($f_contents[rand(0, count($f_contents) - 1)]);
return $line;
}
function getUserUrl($id)
{
global $scripturl;
if ($id != 0) {
return $scripturl . '?action=profile;u=' . $id;
} else {
return 'javascript:void(0);';
}
}
function iflychat_path_check()
{
// /smftest/index.php?action=admin
/*$page_match = FALSE;
if (trim(iflychat_get_option('iflychat_path_pages')) !== '')
{
if(function_exists('mb_strtolower')) {
$pages = mb_strtolower(iflychat_get_option('iflychat_path_pages'));
$path = mb_strtolower($_SERVER['REQUEST_URI']);
}
else {
$pages = strtolower(iflychat_get_option('iflychat_path_pages'));
$path = strtolower($_SERVER['REQUEST_URI']);
}
$page_match = iflychat_match_path($path, $pages);
$page_match = (iflychat_get_option('iflychat_path_visibility') === '1')?(!$page_match):$page_match;
}
else if(iflychat_get_option('iflychat_path_visibility') == 1){
$page_match = TRUE;
}
return $page_match;*/
$page_match = FALSE;
if (trim(iflychat_get_option('iflychat_path_pages')) != '') {
if (function_exists('mb_strtolower')) {
$pages = mb_strtolower(iflychat_get_option('iflychat_path_pages'));
$path = mb_strtolower($_SERVER['REQUEST_URI']);
} else {
$pages = strtolower(iflychat_get_option('iflychat_path_pages'));
$path = strtolower($_SERVER['REQUEST_URI']);
}
$page_match = iflychat_match_path($path, $pages);
if (iflychat_get_option('iflychat_popup_chat') == '3') $page_match = !$page_match;
if (iflychat_get_option('ififlychat_match_pathlychat_popup_chat') == '4') $page_match = $page_match;
//$page_match = (iflychat_get_option('iflychat_popup_chat') == '3') ? (!$page_match) : $page_match;
} else if (iflychat_get_option('iflychat_popup_chat') == '1' || iflychat_get_option('iflychat_popup_chat') == '2') {
$page_match = TRUE;
}
return $page_match;
}
function iflychat_match_path($path, $patterns)
{
$to_replace = array(
'/(\r\n?|\n)/',
'/\\\\\*/',
);
$replacements = array(
'|',
'.*',
);
$patterns_quoted = preg_quote($patterns, '/');
$regexps[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';
return (bool)preg_match($regexps[$patterns], $path);
}
function iflychat_is_user_loggedin()
{
global $user_info;
if ($user_info['is_guest'] != 1) {
return TRUE;
} else {
return FALSE;
}
}
function isSSL()
{
global $scripturl;
$ssl = explode(":", $scripturl);
if ($ssl[0] === 'https') {
return TRUE;
}
}
function iflychat_check_chat_admin()
{
global $user_info;
if ($user_info['is_admin']) {
return true;
}
$a = iflychat_get_option('iflychat_chat_admins_array');
if (!empty($a) && ($user_info['id'])) {
$a_names = explode(",", $a);
foreach ($a_names as $an) {
$aa = trim($an);
if ($aa == $user_info['username']) {
return TRUE;
break;
}
}
}
return FALSE;
}
function friends_get_friend_user_ids($id)
{
global $user_info;
$a = $user_info['buddies'];
if (!empty($a) && ($user_info['id'])) {
$a_friendsNames = explode(",", $a);
foreach ($a_friendsNames as $af) {
$aa = trim($af);
if ($aa == $user_info[$aa]) {
return TRUE;
break;
}
}
}
}
function iflychat_get_user_name()
{
global $user_info;
if (iflychat_get_option('iflychat_use_name') == 1) {
return $user_info['username'];
}
{
return $user_info['name'];
}
}
function iflychat_check_chat_moderator()
{
global $user_info;
$a = iflychat_get_option('iflychat_chat_moderators_array');
if (!empty($a) && ($user_info['id'])) {
$a_names = explode(",", $a);
foreach ($a_names as $an) {
$aa = trim($an);
if ($aa == $user_info['username']) {
return TRUE;
break;
}
}
}
return FALSE;
}
function iflychat_token_destroy()
{
$data = array(
'api_key' => iflychat_get_option('iflychat_external_api_key')
);
$options = array(
'method' => 'POST',
'body' => $data,
//'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$options = json_encode($options);
$result = extendedHttpRequest(SMFCHAT_EXTERNAL_A_HOST . ':' . SMFCHAT_EXTERNAL_A_PORT . '/api/1.1/token/' . $_SESSION['token'] . '/delete', $options);
//if(!is_wp_error($result) && $result['response']['code'] == 200) {
//echo($_SESSION['token']." ".$result);exit();
unset($_SESSION['token']);
LogOut();
//session_unset();
//}
}
function extendedHttpRequest($url, $data_json)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$res_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result = json_decode($result);
$result->code = $res_code;
curl_close($ch);
return $result;
}