forked from 360tradingview/Cometchat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cometchat_send.php
196 lines (153 loc) · 7.55 KB
/
cometchat_send.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
<?php
/*
CometChat
Copyright (c) 2014 Inscripts
CometChat ('the Software') is a copyrighted work of authorship. Inscripts
retains ownership of the Software and any copies of it, regardless of the
form in which the copies may exist. This license is not a sale of the
original Software or any copies.
By installing and using CometChat on your server, you agree to the following
terms and conditions. Such agreement is either on your own behalf or on behalf
of any corporate entity which employs you or which you represent
('Corporate Licensee'). In this Agreement, 'you' includes both the reader
and any Corporate Licensee and 'Inscripts' means Inscripts (I) Private Limited:
CometChat license grants you the right to run one instance (a single installation)
of the Software on one web server and one web site for each license purchased.
Each license may power one instance of the Software on one domain. For each
installed instance of the Software, a separate license is required.
The Software is licensed only to you. You may not rent, lease, sublicense, sell,
assign, pledge, transfer or otherwise dispose of the Software in any form, on
a temporary or permanent basis, without the prior written consent of Inscripts.
The license is effective until terminated. You may terminate it
at any time by uninstalling the Software and destroying any copies in any form.
The Software source code may be altered (at your risk)
All Software copyright notices within the scripts must remain unchanged (and visible).
The Software may not be used for anything that would represent or is associated
with an Intellectual Property violation, including, but not limited to,
engaging in any activity that infringes or misappropriates the intellectual property
rights of others, including copyrights, trademarks, service marks, trade secrets,
software piracy, and patents held by individuals, corporations, or other entities.
If any of the terms of this Agreement are violated, Inscripts reserves the right
to revoke the Software license at any time.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
include_once dirname(__FILE__).DIRECTORY_SEPARATOR."cometchat_init.php";
if (isset($_REQUEST['status'])) {
if ($userid > 0) {
$message = $_REQUEST['status'];
$sql = ("insert into cometchat_status (userid,status) values ('".mysqli_real_escape_string($GLOBALS['dbh'],$userid)."','".mysqli_real_escape_string($GLOBALS['dbh'],sanitize_core($message))."') on duplicate key update status = '".mysqli_real_escape_string($GLOBALS['dbh'],sanitize_core($message))."'");
$query = mysqli_query($GLOBALS['dbh'],$sql);
if (defined('DEV_MODE') && DEV_MODE == '1') { echo mysqli_error($GLOBALS['dbh']); }
if ($message == 'offline') {
$_SESSION['cometchat']['cometchat_sessionvars']['buddylist'] = 0;
}
if (function_exists('hooks_activityupdate')) {
hooks_activityupdate($userid,$message);
}
}
if (!empty($_GET['callback'])) {
header('content-type: application/json; charset=utf-8');
echo $_GET['callback'].'(1)';
} else {
echo "1";
}
exit(0);
}
if (isset($_GET['guestname']) && $userid > 0) {
$guestname = mysqli_real_escape_string($GLOBALS['dbh'],sanitize_core($_GET['guestname']));
$sql = ("UPDATE `cometchat_guests` SET name='".mysqli_real_escape_string($GLOBALS['dbh'],$guestname)."' where id='".mysqli_real_escape_string($GLOBALS['dbh'],$userid)."'");
$query = mysqli_query($GLOBALS['dbh'],$sql);
if (defined('DEV_MODE') && DEV_MODE == '1') { echo mysqli_error($GLOBALS['dbh']); }
if(!empty($guestnamePrefix)){ $guestnamePrefix .= '-'; }
$_SESSION['cometchat']['username'] = $guestnamePrefix.$guestname;
if (!empty($_GET['callback'])) {
header('content-type: application/json; charset=utf-8');
echo $_GET['callback'].'(1)';
} else {
echo "1";
}
exit(0);
}
if (isset($_REQUEST['statusmessage'])) {
$message = $_REQUEST['statusmessage'];
if (empty($_SESSION['cometchat']['statusmessage']) || ($_SESSION['cometchat']['statusmessage'] != $message)) {
$sql = ("insert into cometchat_status (userid,message) values ('".mysqli_real_escape_string($GLOBALS['dbh'],$userid)."','".mysqli_real_escape_string($GLOBALS['dbh'],sanitize_core($message))."') on duplicate key update message = '".mysqli_real_escape_string($GLOBALS['dbh'],sanitize_core($message))."'");
$query = mysqli_query($GLOBALS['dbh'],$sql);
if (defined('DEV_MODE') && DEV_MODE == '1') { echo mysqli_error($GLOBALS['dbh']); }
$_SESSION['cometchat']['statusmessage'] = $message;
if (function_exists('hooks_statusupdate')) {
hooks_statusupdate($userid,$message);
}
}
if (!empty($_GET['callback'])) {
header('content-type: application/json; charset=utf-8');
echo $_GET['callback'].'(1)';
} else {
echo "1";
}
exit(0);
}
if ( (!empty($_REQUEST['to']) && isset($_REQUEST['message']) && $_REQUEST['message']!='')||(!empty($_REQUEST['broadcast']))) {
if(!empty($_REQUEST['broadcast'])){
$broadcasttemp = $_REQUEST['broadcast'];
$broadcast = array();
$broadcast_toids = array();
$bsize =sizeof($broadcasttemp);
for ($i=0; $i < $bsize ; $i++) {
array_push($broadcast_toids, $broadcasttemp[$i]);
$tempa = array('to' => $broadcasttemp[$i],'message' => $broadcasttemp[++$i], 'dir' => 0 );
array_push($broadcast, $tempa);
}
}else{
$to = $_REQUEST['to'];
$message = $_REQUEST['message'];
}
if ($userid > 0) {
if (!in_array($userid,$bannedUserIDs) && !in_array($_SERVER['REMOTE_ADDR'],$bannedUserIPs)) {
if(empty($_REQUEST['broadcast'])){
$response = sendMessage($to,$message,0);
}else{
$response = broadcastMessage($broadcast);
}
if (!empty($_REQUEST['callbackfn']) && $_REQUEST['callbackfn'] == 'mobileapp' && empty($_REQUEST['v2'])) {
$response = $response['id'];
}
if (!empty($_GET['callback'])) {
header('content-type: application/json; charset=utf-8');
sendCCResponse($_GET['callback'].'('.json_encode($response).')');
} else {
sendCCResponse(json_encode($response));
}
if(empty($_REQUEST['broadcast'])){
parsePusher($to,$response['id'],$_SESSION['cometchat']['user']['n'].": ".$response['m']);
}else{
if(USE_COMET == '1'){
publishCometMessages($broadcast,$response[0]['id']);
}
foreach ($response as $rkey => $rvalue) {
parsePusher($rvalue['from'],$rvalue['id'],$_SESSION['cometchat']['user']['n'].": ".$rvalue['m']);
}
}
} else if(empty($_REQUEST['broadcast'])){
$sql = ("insert into cometchat (cometchat.from,cometchat.to,cometchat.message,cometchat.sent,cometchat.read,cometchat.direction) values ('".mysqli_real_escape_string($GLOBALS['dbh'],$userid)."', '".mysqli_real_escape_string($GLOBALS['dbh'],$to)."','".mysqli_real_escape_string($GLOBALS['dbh'],sanitize($bannedMessage))."','".mysqli_real_escape_string($GLOBALS['dbh'],getTimeStamp())."',0,2)");
$query = mysqli_query($GLOBALS['dbh'],$sql);
if (defined('DEV_MODE') && DEV_MODE == '1') { echo mysqli_error($GLOBALS['dbh']); }
if (!empty($_GET['callback'])) {
header('content-type: application/json; charset=utf-8');
echo $_GET['callback'].'()';
}
}
if (function_exists('hooks_message')) {
hooks_message($userid,$to,$message);
}
}
exit(0);
}