/
chatwidgetchat.php
185 lines (148 loc) · 7.15 KB
/
chatwidgetchat.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
<?php
// For IE to support headers if chat is installed on different domain
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
header('Cache-Control: nocache, no-store, max-age=0, must-revalidate');
header('Pragma: no-cache');
header('Expires: Sun, 02 Jan 1990 00:00:00 GMT');
$tpl = erLhcoreClassTemplate::getInstance( 'lhchat/chat.tpl.php');
$embedMode = false;
$modeAppend = '';
if ((string)$Params['user_parameters_unordered']['mode'] == 'embed') {
$embedMode = true;
$modeAppend = '/(mode)/embed';
}
$noMobile = false;
if ((string)$Params['user_parameters_unordered']['mobile'] == 'false') {
$modeAppend .= '/(mobile)/false';
$noMobile = true;
}
if (isset($Params['user_parameters_unordered']['theme']) && (int)$Params['user_parameters_unordered']['theme'] > 0){
try {
$theme = erLhAbstractModelWidgetTheme::fetch($Params['user_parameters_unordered']['theme']);
$theme->translate();
$Result['theme'] = $theme;
$tpl->set('theme',$theme);
$modeAppend .= '/(theme)/'.$theme->id;
} catch (Exception $e) {
}
}
if ($Params['user_parameters_unordered']['sound'] !== null && is_numeric($Params['user_parameters_unordered']['sound'])) {
erLhcoreClassModelUserSetting::setSetting('chat_message',(int)$Params['user_parameters_unordered']['sound'] == 1 ? 1 : 0);
}
if ($Params['user_parameters_unordered']['cstarted'] !== null && $Params['user_parameters_unordered']['cstarted'] != '') {
$Result['parent_messages'][] = 'lh_callback:' . (string)strip_tags($Params['user_parameters_unordered']['cstarted']);
$tpl->set('chat_started_now',true);
}
try {
$db = ezcDbInstance::get();
$db->beginTransaction();
$chat = erLhcoreClassModelChat::fetchAndLock($Params['user_parameters']['chat_id']);
if (!($chat instanceof erLhcoreClassModelChat)) {
throw new Exception('Chat not found!');
}
erLhcoreClassChat::setTimeZoneByChat($chat);
if (is_numeric($Params['user_parameters_unordered']['pchat'])) {
erLhcoreClassChatPaid::openChatWidget(array(
'tpl' => & $tpl,
'pchat' => $Params['user_parameters_unordered']['pchat'],
'chat' => $chat
));
}
if ($chat->hash == $Params['user_parameters']['hash'])
{
$survey = is_numeric($Params['user_parameters_unordered']['survey']) ? (int)$Params['user_parameters_unordered']['survey'] : false;
$tpl->set('chat_id',$Params['user_parameters']['chat_id']);
$tpl->set('hash',$Params['user_parameters']['hash']);
$tpl->set('chat',$chat);
$tpl->set('chat_widget_mode',true);
$tpl->set('chat_embed_mode',$embedMode);
$tpl->set('survey',$survey);
if ($survey > 0) {
$Result['parent_messages'][] = 'lhc_chat_survey:' . $survey;
}
$Result['chat'] = $chat;
// If survey send parent message instantly
if ($chat->status_sub == erLhcoreClassModelChat::STATUS_SUB_SURVEY_SHOW) {
$args = erLhcoreClassChatHelper::getSubStatusArguments($chat);
$Result['parent_messages'][] = 'lhc_chat_closed' . ($args != '' ? ':' . $args : '');
}
// User online
if ($chat->user_status != 0) {
$chat->support_informed = 1;
$chat->user_typing = time();// Show for shorter period these status messages
$chat->is_user_typing = 1;
if (($refererSite = erLhcoreClassModelChatOnlineUser::getReferer()) != '') {
if (strlen($refererSite) > 50) {
if ( function_exists('mb_substr') ) {
$refererSite = mb_substr($refererSite, 0, 50);
} else {
$refererSite = substr($refererSite, 0, 50);
}
}
$chat->user_typing_txt = $refererSite;
} else {
$chat->user_typing_txt = htmlspecialchars_decode(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/userjoined','Visitor has joined the chat!'),ENT_QUOTES);
}
if ($chat->user_status == erLhcoreClassModelChat::USER_STATUS_PENDING_REOPEN && ($onlineuser = $chat->online_user) !== false) {
$onlineuser->reopen_chat = 0;
$onlineuser->saveThis();
}
$chat->unread_op_messages_informed = 0;
$chat->has_unread_op_messages = 0;
$chat->unanswered_chat = 0;
$chat->user_status = erLhcoreClassModelChat::USER_STATUS_JOINED_CHAT;
$nick = isset($_GET['prefill']['username']) ? trim($_GET['prefill']['username']) : '';
// Update nick if required
if (isset($_GET['prefill']['username']) && $chat->nick != $_GET['prefill']['username'] && !empty($nick) && $chat->nick == erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat','Visitor')) {
$chat->nick = $_GET['prefill']['username'];
$chat->operation_admin .= "lhinst.updateVoteStatus(".$chat->id.");";
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.nickchanged', array('chat' => & $chat));
}
if ($chat->unanswered_chat == 1 && $chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT)
{
$chat->unanswered_chat = 0;
}
$chat->updateThis(array('update' => array(
'unanswered_chat',
'operation_admin',
'nick',
'user_status',
'has_unread_op_messages',
'unread_op_messages_informed',
'user_typing_txt',
'support_informed',
'user_typing',
'is_user_typing'
)));
}
$db->commit();
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.chatwidgetchat',array('result' => & $Result , 'tpl' => & $tpl, 'params' => & $Params, 'chat' => & $chat));
} else {
$tpl->setFile( 'lhchat/errors/chatnotexists.tpl.php');
}
} catch(Exception $e) {
$db->rollback();
$tpl->setFile('lhchat/errors/chatnotexists.tpl.php');
}
if (isset($Params['user_parameters_unordered']['fullheight']) && $Params['user_parameters_unordered']['fullheight'] == 'true') {
$Result['fullheight'] = true;
$tpl->set('fullheight', true);
} else {
$Result['fullheight'] = false;
$tpl->set('fullheight', false);
}
$Result['content'] = $tpl->fetch();
$Result['pagelayout'] = 'widget';
$Result['pagelayout_css_append'] = 'widget-chat';
$Result['dynamic_height'] = true;
$Result['dynamic_height_message'] = 'lhc_sizing_chat';
$Result['path'] = array(array('title' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chat','Chat started')));
$Result['is_sync_required'] = true;
if ($noMobile === true) {
$Result['no_mobile_css'] = true;
}
if ($embedMode == true) {
$Result['dynamic_height_message'] = 'lhc_sizing_chat_page';
$Result['pagelayout_css_append'] = 'embed-widget';
}
?>