-
-
Notifications
You must be signed in to change notification settings - Fork 689
/
uploadfile.php
95 lines (67 loc) · 4.12 KB
/
uploadfile.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
<?php
erLhcoreClassRestAPIHandler::setHeaders();
$fileData = (array)erLhcoreClassModelChatConfig::fetch('file_configuration')->data;
$chat = erLhcoreClassModelChat::fetch($Params['user_parameters']['chat_id']);
$chatVariables = $chat->chat_variables_array;
if (isset($fileData['active_user_upload']) && $fileData['active_user_upload'] == true || (isset($chatVariables['lhc_fu']) && $chatVariables['lhc_fu'] == 1)) {
$db = ezcDbInstance::get();
try {
$db->beginTransaction();
$chat = erLhcoreClassModelChat::fetchAndLock($Params['user_parameters']['chat_id'], false);
$chatVariables = $chat->chat_variables_array;
if (!(isset($fileData['active_user_upload']) && $fileData['active_user_upload'] == true || (isset($chatVariables['lhc_fu']) && $chatVariables['lhc_fu'] == 1))) {
// Make sure nothing changed since last request
exit;
}
if ($chat->hash == $Params['user_parameters']['hash'] && ($chat->status == erLhcoreClassModelChat::STATUS_BOT_CHAT || $chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT || $chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT)) // Allow add messages only if chat is active
{
$errors = array();
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.before_user_uploadfile.file_store', array('errors' => & $errors));
if (empty($errors)) {
$fileData = erLhcoreClassModelChatConfig::fetch('file_configuration');
$data = (array)$fileData->data;
$path = 'var/storage/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/' . $chat->id . '/';
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.uploadfile.file_path', array('path' => & $path, 'storage_id' => $chat->id));
$clamav = false;
if (isset($data['clamav_enabled']) && $data['clamav_enabled'] == true) {
$opts = array();
if (isset($data['clamd_sock']) && !empty($data['clamd_sock'])) {
$opts['clamd_sock'] = $data['clamd_sock'];
}
if (isset($data['clamd_sock_len']) && !empty($data['clamd_sock_len'])) {
$opts['clamd_sock_len'] = $data['clamd_sock_len'];
}
$clamav = new Clamav($opts);
}
$upload_handler = new erLhcoreClassFileUpload(array(
'remove_meta' => (isset($data['remove_meta']) ? $data['remove_meta'] : false),
'antivirus' => $clamav,
'user_id' => 0,
'max_file_size' => $data['fs_max'] * 1024,
'accept_file_types_lhc' => '/\.(' . $data['ft_us'] . ')$/i',
'chat' => $chat,
'download_via_php' => true,
'upload_dir' => $path));
if ($upload_handler->uploadedFile instanceof erLhcoreClassModelChatFile) {
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.uploadfile.file_store', array('chat'=> $chat, 'chat_file' => $upload_handler->uploadedFile));
$chat->user_typing_txt = '100%';
} elseif (is_object($upload_handler->uploadedFile)) {
$chat->user_typing_txt = $upload_handler->uploadedFile->error;
echo json_encode(array('error' => 'true', 'error_msg' => $upload_handler->uploadedFile->error ));
exit;
}
$chat->user_typing = time();
$chat->updateThis(array('update' => array('user_typing_txt','user_typing')));
echo json_encode(array('error' => 'false'));
} else {
echo json_encode(array('error' => 'true', 'error_msg' => implode(PHP_EOL, $errors)));
}
}
$db->commit();
} catch (Exception $e) {
echo json_encode(array('error' => 'true', 'error_msg' => $e->getMessage()));
$db->rollback();
}
}
exit;
?>