@@ -124,7 +124,9 @@ |
||
124 | 124 | 'sender_id' => $user_id |
125 | 125 | )); |
126 | 126 | $check_widget = true; |
127 | - if ($user_id == $this->user->data['user_id']) $check_widget = false; |
|
127 | + if ($user_id == $this->user->data['user_id']) { |
|
128 | + $check_widget = false; |
|
129 | + } |
|
128 | 130 | $this->template->assign_vars(array( |
129 | 131 | 'U_USER_ID' => $user_id, |
130 | 132 | 'U_CHECK_FRIEND' => $check_friend, |
@@ -67,17 +67,17 @@ discard block |
||
67 | 67 | { |
68 | 68 | $context = new RequestContext(); |
69 | 69 | $context->fromRequest($this->symfony_request); |
70 | - $baseUrl = generate_board_url(true) . $context->getBaseUrl(); |
|
70 | + $baseUrl = generate_board_url(true).$context->getBaseUrl(); |
|
71 | 71 | |
72 | 72 | $scriptName = $this->symfony_request->getScriptName(); |
73 | 73 | $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName); |
74 | 74 | |
75 | 75 | if ($scriptName != '') { |
76 | - $baseUrl = str_replace('/' . $scriptName, '', $baseUrl); |
|
76 | + $baseUrl = str_replace('/'.$scriptName, '', $baseUrl); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | $friends = $this->model->getFriends(); |
80 | - $friends_online = array_filter($friends, function ($friend) { |
|
80 | + $friends_online = array_filter($friends, function($friend) { |
|
81 | 81 | return $friend['user_status'] != 0; |
82 | 82 | }); |
83 | 83 | $this->template->assign_var('S_COUNT_FRIENDS', count($friends_online)); |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | { |
119 | 119 | $context = new RequestContext(); |
120 | 120 | $context->fromRequest($this->symfony_request); |
121 | - $baseUrl = generate_board_url(true) . $context->getBaseUrl(); |
|
121 | + $baseUrl = generate_board_url(true).$context->getBaseUrl(); |
|
122 | 122 | |
123 | 123 | $scriptName = $this->symfony_request->getScriptName(); |
124 | 124 | $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName); |
125 | 125 | |
126 | 126 | if ($scriptName != '') { |
127 | - $baseUrl = str_replace('/' . $scriptName, '', $baseUrl); |
|
127 | + $baseUrl = str_replace('/'.$scriptName, '', $baseUrl); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | $user_id = $event['member']['user_id']; |
@@ -15,187 +15,187 @@ |
||
15 | 15 | class main |
16 | 16 | { |
17 | 17 | |
18 | - protected $user; |
|
19 | - protected $model; |
|
20 | - protected $request; |
|
21 | - protected $notification_manager; |
|
22 | - protected $upload; |
|
23 | - protected $download; |
|
24 | - |
|
25 | - public function __construct( |
|
26 | - request $request, |
|
27 | - user $user, |
|
28 | - main_model $model, |
|
29 | - manager $notification_manager, |
|
30 | - upload $upload, |
|
31 | - download $download |
|
32 | - ) |
|
33 | - { |
|
34 | - $this->request = $request; |
|
35 | - $this->user = $user; |
|
36 | - $this->model = $model; |
|
37 | - $this->notification_manager = $notification_manager; |
|
38 | - $this->upload = $upload; |
|
39 | - $this->download = $download; |
|
40 | - } |
|
41 | - |
|
42 | - public function handle() |
|
43 | - { |
|
44 | - } |
|
45 | - |
|
46 | - public function index() |
|
47 | - { |
|
48 | - |
|
49 | - } |
|
50 | - |
|
51 | - public function publish() |
|
52 | - { |
|
53 | - $text = $this->request->variable('text', '', true); |
|
54 | - $receiver_id = $this->request->variable('receiver_id', 0); |
|
55 | - $sender_id = $this->user->data['user_id']; |
|
56 | - |
|
57 | - $response = array(); |
|
58 | - if ($receiver_id != 0 && trim($text) != '') { |
|
59 | - $text = htmlspecialchars($text); |
|
60 | - $text = str_replace(array("\n", "\r"), '', $text); |
|
61 | - |
|
62 | - $message = array( |
|
63 | - 'sender_id' => $sender_id, |
|
64 | - 'receiver_id' => $receiver_id, |
|
65 | - 'text' => $text, |
|
66 | - 'sentAt' => time() |
|
67 | - ); |
|
68 | - |
|
69 | - if ($id = $this->model->sendMessage($message)) { |
|
70 | - $lastMessage = $this->model->getMessageById($id); |
|
71 | - $response = array('success' => true, 'message' => $lastMessage); |
|
72 | - } else { |
|
73 | - $response = array( |
|
74 | - 'succes' => false, |
|
75 | - 'error' => 'An error has been ocurred!' |
|
76 | - ); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - return new JsonResponse($response, 200); |
|
81 | - } |
|
82 | - |
|
83 | - public function getFile($id) |
|
84 | - { |
|
85 | - $id = explode('_', $id)[1]; |
|
86 | - $file = $this->model->getFileById($id); |
|
87 | - $this->download->setFile($file['file']); |
|
88 | - $this->download->sendDownload(); |
|
89 | - } |
|
90 | - |
|
91 | - public function sendFile() |
|
92 | - { |
|
93 | - $receiver_id = $this->request->variable('receiver_id', 0); |
|
94 | - $sender_id = $this->user->data['user_id']; |
|
95 | - |
|
96 | - $response = array(); |
|
97 | - $file = $this->request->file('file'); |
|
98 | - if ($receiver_id != 0 && !empty($file)) { |
|
99 | - if ($file['error'] == 0) { |
|
100 | - $this->upload->file($file); |
|
101 | - $this->upload->set_allowed_mime_types(array( |
|
102 | - 'image/gif', |
|
103 | - 'image/jpeg', |
|
104 | - 'image/png', |
|
105 | - 'application/pdf', |
|
106 | - 'application/x-rar-compressed', |
|
107 | - 'application/zip', |
|
108 | - 'application/x-7z-compressed', |
|
109 | - 'text/plain' |
|
110 | - )); |
|
111 | - $results = $this->upload->upload(); |
|
112 | - if (isset($results['errors']) && count($results['errors'])) { |
|
113 | - $response = array( |
|
114 | - 'success' => false, |
|
115 | - 'errors' => $results['errors'] |
|
116 | - ); |
|
117 | - } else { |
|
118 | - $data = array( |
|
119 | - 'sender_id' => $sender_id, |
|
120 | - 'receiver_id' => $receiver_id, |
|
121 | - 'fileName' => $results['original_filename'], |
|
122 | - 'file' => $results['filename'], |
|
123 | - 'type' => $results['mime'], |
|
124 | - ); |
|
125 | - if ($id = $this->model->sendFile($data)) { |
|
126 | - $lastFile = $this->model->getFileById($id); |
|
127 | - $response = array( |
|
128 | - 'success' => true, |
|
129 | - 'file' => $lastFile |
|
130 | - ); |
|
131 | - } else { |
|
132 | - $response = array( |
|
133 | - 'succes' => false, |
|
134 | - 'error' => 'An error has been ocurred!' |
|
135 | - ); |
|
136 | - } |
|
137 | - } |
|
138 | - } else { |
|
139 | - $response = array( |
|
140 | - 'succes' => false, |
|
141 | - 'error' => $file['error'] |
|
142 | - ); |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - return new JsonResponse($response, 200); |
|
147 | - } |
|
148 | - |
|
149 | - public function load() |
|
150 | - { |
|
151 | - $friend_id = $this->request->variable('friend_id', 0); |
|
152 | - |
|
153 | - if ($friend_id > 0) { |
|
154 | - $messages = $this->model->getMessages($friend_id); |
|
155 | - return new JsonResponse($messages, 200); |
|
156 | - } |
|
157 | - return new JsonResponse(array('success' => false, 'error' => 'The request is invalid'), 200); |
|
158 | - } |
|
159 | - |
|
160 | - public function updateMessages() |
|
161 | - { |
|
162 | - $friend_id = $this->request->variable('friend_id', 0); |
|
163 | - if ($friend_id > 0) { |
|
164 | - $newVal = $this->model->updateMessagesStatus($friend_id); |
|
165 | - return new JsonResponse(array('success' => true, 'newVal' => $newVal), 200); |
|
166 | - } |
|
167 | - return new JsonResponse(array('success' => false), 200); |
|
168 | - } |
|
169 | - |
|
170 | - public function checkForNewMessages() |
|
171 | - { |
|
172 | - $friend_id = $this->request->variable('friend_id', 0); |
|
173 | - if ($friend_id > 0) { |
|
174 | - $messages = $this->model->getInboxFromId($friend_id); |
|
175 | - return new JsonResponse(array('success' => true, 'messages' => $messages), 200); |
|
176 | - } |
|
177 | - return new JsonResponse(array('success' => false), 200); |
|
178 | - } |
|
179 | - |
|
180 | - public function getFriends() |
|
181 | - { |
|
182 | - $friends = $this->model->getFriends(); |
|
183 | - $friends_online = array_filter($friends, function($friend) { |
|
184 | - return $friend['user_status'] != 0; |
|
185 | - }); |
|
186 | - |
|
187 | - $response = array( |
|
188 | - 'friends_online' => count($friends_online), |
|
189 | - 'friends_list' => $friends |
|
190 | - ); |
|
191 | - |
|
192 | - return new JsonResponse($response, 200); |
|
193 | - } |
|
194 | - |
|
195 | - public function getEmoticons() |
|
196 | - { |
|
197 | - $response = array(); |
|
198 | - return new JsonResponse($response, 200); |
|
199 | - } |
|
18 | + protected $user; |
|
19 | + protected $model; |
|
20 | + protected $request; |
|
21 | + protected $notification_manager; |
|
22 | + protected $upload; |
|
23 | + protected $download; |
|
24 | + |
|
25 | + public function __construct( |
|
26 | + request $request, |
|
27 | + user $user, |
|
28 | + main_model $model, |
|
29 | + manager $notification_manager, |
|
30 | + upload $upload, |
|
31 | + download $download |
|
32 | + ) |
|
33 | + { |
|
34 | + $this->request = $request; |
|
35 | + $this->user = $user; |
|
36 | + $this->model = $model; |
|
37 | + $this->notification_manager = $notification_manager; |
|
38 | + $this->upload = $upload; |
|
39 | + $this->download = $download; |
|
40 | + } |
|
41 | + |
|
42 | + public function handle() |
|
43 | + { |
|
44 | + } |
|
45 | + |
|
46 | + public function index() |
|
47 | + { |
|
48 | + |
|
49 | + } |
|
50 | + |
|
51 | + public function publish() |
|
52 | + { |
|
53 | + $text = $this->request->variable('text', '', true); |
|
54 | + $receiver_id = $this->request->variable('receiver_id', 0); |
|
55 | + $sender_id = $this->user->data['user_id']; |
|
56 | + |
|
57 | + $response = array(); |
|
58 | + if ($receiver_id != 0 && trim($text) != '') { |
|
59 | + $text = htmlspecialchars($text); |
|
60 | + $text = str_replace(array("\n", "\r"), '', $text); |
|
61 | + |
|
62 | + $message = array( |
|
63 | + 'sender_id' => $sender_id, |
|
64 | + 'receiver_id' => $receiver_id, |
|
65 | + 'text' => $text, |
|
66 | + 'sentAt' => time() |
|
67 | + ); |
|
68 | + |
|
69 | + if ($id = $this->model->sendMessage($message)) { |
|
70 | + $lastMessage = $this->model->getMessageById($id); |
|
71 | + $response = array('success' => true, 'message' => $lastMessage); |
|
72 | + } else { |
|
73 | + $response = array( |
|
74 | + 'succes' => false, |
|
75 | + 'error' => 'An error has been ocurred!' |
|
76 | + ); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + return new JsonResponse($response, 200); |
|
81 | + } |
|
82 | + |
|
83 | + public function getFile($id) |
|
84 | + { |
|
85 | + $id = explode('_', $id)[1]; |
|
86 | + $file = $this->model->getFileById($id); |
|
87 | + $this->download->setFile($file['file']); |
|
88 | + $this->download->sendDownload(); |
|
89 | + } |
|
90 | + |
|
91 | + public function sendFile() |
|
92 | + { |
|
93 | + $receiver_id = $this->request->variable('receiver_id', 0); |
|
94 | + $sender_id = $this->user->data['user_id']; |
|
95 | + |
|
96 | + $response = array(); |
|
97 | + $file = $this->request->file('file'); |
|
98 | + if ($receiver_id != 0 && !empty($file)) { |
|
99 | + if ($file['error'] == 0) { |
|
100 | + $this->upload->file($file); |
|
101 | + $this->upload->set_allowed_mime_types(array( |
|
102 | + 'image/gif', |
|
103 | + 'image/jpeg', |
|
104 | + 'image/png', |
|
105 | + 'application/pdf', |
|
106 | + 'application/x-rar-compressed', |
|
107 | + 'application/zip', |
|
108 | + 'application/x-7z-compressed', |
|
109 | + 'text/plain' |
|
110 | + )); |
|
111 | + $results = $this->upload->upload(); |
|
112 | + if (isset($results['errors']) && count($results['errors'])) { |
|
113 | + $response = array( |
|
114 | + 'success' => false, |
|
115 | + 'errors' => $results['errors'] |
|
116 | + ); |
|
117 | + } else { |
|
118 | + $data = array( |
|
119 | + 'sender_id' => $sender_id, |
|
120 | + 'receiver_id' => $receiver_id, |
|
121 | + 'fileName' => $results['original_filename'], |
|
122 | + 'file' => $results['filename'], |
|
123 | + 'type' => $results['mime'], |
|
124 | + ); |
|
125 | + if ($id = $this->model->sendFile($data)) { |
|
126 | + $lastFile = $this->model->getFileById($id); |
|
127 | + $response = array( |
|
128 | + 'success' => true, |
|
129 | + 'file' => $lastFile |
|
130 | + ); |
|
131 | + } else { |
|
132 | + $response = array( |
|
133 | + 'succes' => false, |
|
134 | + 'error' => 'An error has been ocurred!' |
|
135 | + ); |
|
136 | + } |
|
137 | + } |
|
138 | + } else { |
|
139 | + $response = array( |
|
140 | + 'succes' => false, |
|
141 | + 'error' => $file['error'] |
|
142 | + ); |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + return new JsonResponse($response, 200); |
|
147 | + } |
|
148 | + |
|
149 | + public function load() |
|
150 | + { |
|
151 | + $friend_id = $this->request->variable('friend_id', 0); |
|
152 | + |
|
153 | + if ($friend_id > 0) { |
|
154 | + $messages = $this->model->getMessages($friend_id); |
|
155 | + return new JsonResponse($messages, 200); |
|
156 | + } |
|
157 | + return new JsonResponse(array('success' => false, 'error' => 'The request is invalid'), 200); |
|
158 | + } |
|
159 | + |
|
160 | + public function updateMessages() |
|
161 | + { |
|
162 | + $friend_id = $this->request->variable('friend_id', 0); |
|
163 | + if ($friend_id > 0) { |
|
164 | + $newVal = $this->model->updateMessagesStatus($friend_id); |
|
165 | + return new JsonResponse(array('success' => true, 'newVal' => $newVal), 200); |
|
166 | + } |
|
167 | + return new JsonResponse(array('success' => false), 200); |
|
168 | + } |
|
169 | + |
|
170 | + public function checkForNewMessages() |
|
171 | + { |
|
172 | + $friend_id = $this->request->variable('friend_id', 0); |
|
173 | + if ($friend_id > 0) { |
|
174 | + $messages = $this->model->getInboxFromId($friend_id); |
|
175 | + return new JsonResponse(array('success' => true, 'messages' => $messages), 200); |
|
176 | + } |
|
177 | + return new JsonResponse(array('success' => false), 200); |
|
178 | + } |
|
179 | + |
|
180 | + public function getFriends() |
|
181 | + { |
|
182 | + $friends = $this->model->getFriends(); |
|
183 | + $friends_online = array_filter($friends, function($friend) { |
|
184 | + return $friend['user_status'] != 0; |
|
185 | + }); |
|
186 | + |
|
187 | + $response = array( |
|
188 | + 'friends_online' => count($friends_online), |
|
189 | + 'friends_list' => $friends |
|
190 | + ); |
|
191 | + |
|
192 | + return new JsonResponse($response, 200); |
|
193 | + } |
|
194 | + |
|
195 | + public function getEmoticons() |
|
196 | + { |
|
197 | + $response = array(); |
|
198 | + return new JsonResponse($response, 200); |
|
199 | + } |
|
200 | 200 | |
201 | 201 | } |
@@ -13,514 +13,514 @@ |
||
13 | 13 | class upload |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Default directory persmissions (destination dir) |
|
18 | - */ |
|
19 | - protected $default_permissions = 750; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * File post array |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $files_post = array(); |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * Destination directory |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $destination; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Fileinfo |
|
40 | - * |
|
41 | - * @var object |
|
42 | - */ |
|
43 | - protected $finfo; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Data about file |
|
48 | - * |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - public $file = array(); |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Max. file size |
|
56 | - * |
|
57 | - * @var int |
|
58 | - */ |
|
59 | - protected $max_file_size; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Allowed mime types |
|
64 | - * |
|
65 | - * @var array |
|
66 | - */ |
|
67 | - protected $mimes = array(); |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * External callback object |
|
72 | - * |
|
73 | - * @var obejct |
|
74 | - */ |
|
75 | - protected $external_callback_object; |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * External callback methods |
|
80 | - * |
|
81 | - * @var array |
|
82 | - */ |
|
83 | - protected $external_callback_methods = array(); |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Temp path |
|
88 | - * |
|
89 | - * @var string |
|
90 | - */ |
|
91 | - protected $tmp_name; |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Validation errors |
|
96 | - * |
|
97 | - * @var array |
|
98 | - */ |
|
99 | - protected $validation_errors = array(); |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Filename (new) |
|
104 | - * |
|
105 | - * @var string |
|
106 | - */ |
|
107 | - protected $filename; |
|
108 | - |
|
109 | - /** |
|
110 | - * File extension |
|
111 | - * @var string |
|
112 | - */ |
|
113 | - protected $extension; |
|
114 | - |
|
115 | - /** |
|
116 | - * Internal callbacks (filesize check, mime, etc) |
|
117 | - * |
|
118 | - * @var array |
|
119 | - */ |
|
120 | - private $callbacks = array(); |
|
121 | - |
|
122 | - /** |
|
123 | - * Root dir |
|
124 | - * |
|
125 | - * @var string |
|
126 | - */ |
|
127 | - protected $root; |
|
128 | - |
|
129 | - /** |
|
130 | - * Return upload object |
|
131 | - * |
|
132 | - * $destination = 'path/to/your/file/destination/folder'; |
|
133 | - * |
|
134 | - * @param string $phpbb_root_path |
|
135 | - * @return Upload |
|
136 | - */ |
|
137 | - public static function factory($phpbb_root_path) |
|
138 | - { |
|
139 | - return new Upload($phpbb_root_path); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Define ROOT constant and set & create destination path |
|
144 | - * |
|
145 | - * @param string $phpbb_root_path |
|
146 | - * @throws Exception |
|
147 | - */ |
|
148 | - public function __construct($phpbb_root_path) |
|
149 | - { |
|
150 | - $phpbb_root_path = $phpbb_root_path.'store/messenger/files'; |
|
151 | - // set & create destination path |
|
152 | - if (!$this->set_destination($phpbb_root_path)) { |
|
153 | - throw new Exception('Upload: Can\'t create destination. '.$this->root.$this->destination); |
|
154 | - } |
|
155 | - |
|
156 | - //create finfo object |
|
157 | - $this->finfo = new finfo(); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Set target filename |
|
162 | - * |
|
163 | - * @param string $filename |
|
164 | - */ |
|
165 | - public function set_filename($filename) |
|
166 | - { |
|
167 | - $this->filename = $filename; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Check & Save file |
|
172 | - * |
|
173 | - * Return data about current upload |
|
174 | - * |
|
175 | - * @return array |
|
176 | - */ |
|
177 | - public function upload($filename = '') |
|
178 | - { |
|
179 | - if ($this->check()) { |
|
180 | - $this->save(); |
|
181 | - } |
|
182 | - // return state data |
|
183 | - return $this->get_state(); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Save file on server |
|
189 | - * |
|
190 | - * Return state data |
|
191 | - * |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - public function save() |
|
195 | - { |
|
196 | - $this->save_file(); |
|
197 | - return $this->get_state(); |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Validate file (execute callbacks) |
|
203 | - * |
|
204 | - * Returns TRUE if validation successful |
|
205 | - * |
|
206 | - * @return bool |
|
207 | - */ |
|
208 | - public function check() |
|
209 | - { |
|
210 | - //execute callbacks (check filesize, mime, also external callbacks |
|
211 | - $this->validate(); |
|
212 | - |
|
213 | - //add error messages |
|
214 | - $this->file['errors'] = $this->get_errors(); |
|
215 | - |
|
216 | - //change file validation status |
|
217 | - $this->file['status'] = empty($this->validation_errors); |
|
218 | - |
|
219 | - return $this->file['status']; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Get current state data |
|
224 | - * |
|
225 | - * @return array |
|
226 | - */ |
|
227 | - public function get_state() |
|
228 | - { |
|
229 | - return $this->file; |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * Save file on server |
|
235 | - */ |
|
236 | - protected function save_file() |
|
237 | - { |
|
238 | - //create & set new filename |
|
239 | - if (empty($this->filename)) { |
|
240 | - $this->create_new_filename(); |
|
241 | - } |
|
242 | - |
|
243 | - //set filename |
|
244 | - $this->file['filename'] = $this->filename; |
|
245 | - |
|
246 | - //set full path |
|
247 | - $this->file['full_path'] = $this->root.$this->destination.$this->filename; |
|
248 | - $this->file['path'] = $this->destination.$this->filename; |
|
249 | - |
|
250 | - $status = move_uploaded_file($this->tmp_name, $this->file['full_path']); |
|
251 | - |
|
252 | - //checks whether upload successful |
|
253 | - if (!$status) { |
|
254 | - throw new Exception('Upload: Can\'t upload file.'); |
|
255 | - } |
|
256 | - |
|
257 | - //done |
|
258 | - $this->file['status'] = true; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Set data about file |
|
263 | - */ |
|
264 | - protected function set_file_data() |
|
265 | - { |
|
266 | - $file_size = $this->get_file_size(); |
|
267 | - |
|
268 | - $this->file = array( |
|
269 | - 'status' => false, |
|
270 | - 'destination' => $this->destination, |
|
271 | - 'size_in_bytes' => $file_size, |
|
272 | - 'size_in_mb' => $this->bytes_to_mb($file_size), |
|
273 | - 'mime' => $this->get_file_mime(), |
|
274 | - 'original_filename' => $this->file_post['name'], |
|
275 | - 'tmp_name' => $this->file_post['tmp_name'], |
|
276 | - 'post_data' => $this->file_post, |
|
277 | - ); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Set validation error |
|
282 | - * |
|
283 | - * @param string $message |
|
284 | - */ |
|
285 | - public function set_error($message) |
|
286 | - { |
|
287 | - $this->validation_errors[] = $message; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Return validation errors |
|
292 | - * |
|
293 | - * @return array |
|
294 | - */ |
|
295 | - public function get_errors() |
|
296 | - { |
|
297 | - return $this->validation_errors; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Set external callback methods |
|
302 | - * |
|
303 | - * @param object $instance_of_callback_object |
|
304 | - * @param array $callback_methods |
|
305 | - * @throws Exception |
|
306 | - */ |
|
307 | - public function callbacks($instance_of_callback_object, $callback_methods) |
|
308 | - { |
|
309 | - if (empty($instance_of_callback_object)) { |
|
310 | - throw new Exception('Upload: $instance_of_callback_object can\'t be empty.'); |
|
311 | - } |
|
312 | - |
|
313 | - if (!is_array($callback_methods)) { |
|
314 | - throw new Exception('Upload: $callback_methods data type need to be array.'); |
|
315 | - } |
|
316 | - |
|
317 | - $this->external_callback_object = $instance_of_callback_object; |
|
318 | - $this->external_callback_methods = $callback_methods; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Execute callbacks |
|
323 | - */ |
|
324 | - protected function validate() |
|
325 | - { |
|
326 | - //get curent errors |
|
327 | - $errors = $this->get_errors(); |
|
328 | - |
|
329 | - if (empty($errors)) { |
|
330 | - //set data about current file |
|
331 | - $this->set_file_data(); |
|
332 | - |
|
333 | - //execute internal callbacks |
|
334 | - $this->execute_callbacks($this->callbacks, $this); |
|
335 | - |
|
336 | - //execute external callbacks |
|
337 | - $this->execute_callbacks($this->external_callback_methods, $this->external_callback_object); |
|
338 | - } |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Execute callbacks |
|
343 | - */ |
|
344 | - protected function execute_callbacks($callbacks, $object) |
|
345 | - { |
|
346 | - foreach ($callbacks as $method) { |
|
347 | - $object->$method($this); |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * File mime type validation callback |
|
353 | - * |
|
354 | - * @param mixed $object |
|
355 | - */ |
|
356 | - protected function check_mime_type($object) |
|
357 | - { |
|
358 | - if (!empty($object->mimes)) { |
|
359 | - if (!in_array($object->file['mime'], $object->mimes)) { |
|
360 | - $object->set_error('Mime type not allowed.'); |
|
361 | - } |
|
362 | - } |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Set allowed mime types |
|
367 | - * |
|
368 | - * @param string[] $mimes |
|
369 | - */ |
|
370 | - public function set_allowed_mime_types($mimes) |
|
371 | - { |
|
372 | - $this->mimes = $mimes; |
|
373 | - //if mime types is set -> set callback |
|
374 | - $this->callbacks[] = 'check_mime_type'; |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * File size validation callback |
|
379 | - * |
|
380 | - * @param object $object |
|
381 | - */ |
|
382 | - protected function check_file_size($object) |
|
383 | - { |
|
384 | - if (!empty($object->max_file_size)) { |
|
385 | - $file_size_in_mb = $this->bytes_to_mb($object->file['size_in_bytes']); |
|
386 | - if ($object->max_file_size <= $file_size_in_mb) { |
|
387 | - $object->set_error('File is too big.'); |
|
388 | - } |
|
389 | - } |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Set max. file size |
|
394 | - * |
|
395 | - * @param int $size |
|
396 | - */ |
|
397 | - public function set_max_file_size($size) |
|
398 | - { |
|
399 | - $this->max_file_size = $size; |
|
400 | - //if max file size is set -> set callback |
|
401 | - $this->callbacks[] = 'check_file_size'; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Set File array to object |
|
406 | - * |
|
407 | - * @param array $file |
|
408 | - */ |
|
409 | - public function file($file) |
|
410 | - { |
|
411 | - $this->set_file_array($file); |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Set file array |
|
416 | - * |
|
417 | - * @param array $file |
|
418 | - */ |
|
419 | - protected function set_file_array($file) |
|
420 | - { |
|
421 | - //checks whether file array is valid |
|
422 | - if (!$this->check_file_array($file)) { |
|
423 | - //file not selected or some bigger problems (broken files array) |
|
424 | - $this->set_error('Please select file.'); |
|
425 | - } |
|
426 | - |
|
427 | - //set file data |
|
428 | - $this->file_post = $file; |
|
429 | - |
|
430 | - //set tmp path |
|
431 | - $this->tmp_name = $file['tmp_name']; |
|
432 | - |
|
433 | - // set file extension |
|
434 | - $this->extension = pathinfo($file['name'], PATHINFO_EXTENSION); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Checks whether Files post array is valid |
|
439 | - * |
|
440 | - * @return bool |
|
441 | - */ |
|
442 | - protected function check_file_array($file) |
|
443 | - { |
|
444 | - return isset($file['error']) |
|
445 | - && !empty($file['name']) |
|
446 | - && !empty($file['type']) |
|
447 | - && !empty($file['tmp_name']) |
|
448 | - && !empty($file['size']); |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Get file mime type |
|
453 | - * |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - protected function get_file_mime() |
|
457 | - { |
|
458 | - return $this->finfo->file($this->tmp_name, FILEINFO_MIME_TYPE); |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * Get file size |
|
463 | - * |
|
464 | - * @return int |
|
465 | - */ |
|
466 | - protected function get_file_size() |
|
467 | - { |
|
468 | - return filesize($this->tmp_name); |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Set destination path (return TRUE on success) |
|
473 | - * |
|
474 | - * @param string $destination |
|
475 | - * @return bool |
|
476 | - */ |
|
477 | - protected function set_destination($destination) |
|
478 | - { |
|
479 | - $this->destination = $destination.DIRECTORY_SEPARATOR; |
|
480 | - return $this->destination_exist() ? TRUE : $this->create_destination(); |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Checks whether destination folder exists |
|
485 | - * |
|
486 | - * @return bool |
|
487 | - */ |
|
488 | - protected function destination_exist() |
|
489 | - { |
|
490 | - return is_writable($this->root.$this->destination); |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Create path to destination |
|
495 | - * |
|
496 | - * @return bool |
|
497 | - */ |
|
498 | - protected function create_destination() |
|
499 | - { |
|
500 | - return mkdir($this->root.$this->destination, $this->default_permissions, true); |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Set unique filename |
|
505 | - * |
|
506 | - * @return string |
|
507 | - */ |
|
508 | - protected function create_new_filename() |
|
509 | - { |
|
510 | - $filename = sha1(mt_rand(1, 9999).$this->destination.uniqid()).time().'.'.$this->extension; |
|
511 | - $this->set_filename($filename); |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * Convert bytes to mb. |
|
516 | - * |
|
517 | - * @param int $bytes |
|
518 | - * @return double |
|
519 | - */ |
|
520 | - protected function bytes_to_mb($bytes) |
|
521 | - { |
|
522 | - return round(($bytes / 1048576), 2); |
|
523 | - } |
|
16 | + /** |
|
17 | + * Default directory persmissions (destination dir) |
|
18 | + */ |
|
19 | + protected $default_permissions = 750; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * File post array |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $files_post = array(); |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * Destination directory |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $destination; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Fileinfo |
|
40 | + * |
|
41 | + * @var object |
|
42 | + */ |
|
43 | + protected $finfo; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Data about file |
|
48 | + * |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + public $file = array(); |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Max. file size |
|
56 | + * |
|
57 | + * @var int |
|
58 | + */ |
|
59 | + protected $max_file_size; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Allowed mime types |
|
64 | + * |
|
65 | + * @var array |
|
66 | + */ |
|
67 | + protected $mimes = array(); |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * External callback object |
|
72 | + * |
|
73 | + * @var obejct |
|
74 | + */ |
|
75 | + protected $external_callback_object; |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * External callback methods |
|
80 | + * |
|
81 | + * @var array |
|
82 | + */ |
|
83 | + protected $external_callback_methods = array(); |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Temp path |
|
88 | + * |
|
89 | + * @var string |
|
90 | + */ |
|
91 | + protected $tmp_name; |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Validation errors |
|
96 | + * |
|
97 | + * @var array |
|
98 | + */ |
|
99 | + protected $validation_errors = array(); |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Filename (new) |
|
104 | + * |
|
105 | + * @var string |
|
106 | + */ |
|
107 | + protected $filename; |
|
108 | + |
|
109 | + /** |
|
110 | + * File extension |
|
111 | + * @var string |
|
112 | + */ |
|
113 | + protected $extension; |
|
114 | + |
|
115 | + /** |
|
116 | + * Internal callbacks (filesize check, mime, etc) |
|
117 | + * |
|
118 | + * @var array |
|
119 | + */ |
|
120 | + private $callbacks = array(); |
|
121 | + |
|
122 | + /** |
|
123 | + * Root dir |
|
124 | + * |
|
125 | + * @var string |
|
126 | + */ |
|
127 | + protected $root; |
|
128 | + |
|
129 | + /** |
|
130 | + * Return upload object |
|
131 | + * |
|
132 | + * $destination = 'path/to/your/file/destination/folder'; |
|
133 | + * |
|
134 | + * @param string $phpbb_root_path |
|
135 | + * @return Upload |
|
136 | + */ |
|
137 | + public static function factory($phpbb_root_path) |
|
138 | + { |
|
139 | + return new Upload($phpbb_root_path); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Define ROOT constant and set & create destination path |
|
144 | + * |
|
145 | + * @param string $phpbb_root_path |
|
146 | + * @throws Exception |
|
147 | + */ |
|
148 | + public function __construct($phpbb_root_path) |
|
149 | + { |
|
150 | + $phpbb_root_path = $phpbb_root_path.'store/messenger/files'; |
|
151 | + // set & create destination path |
|
152 | + if (!$this->set_destination($phpbb_root_path)) { |
|
153 | + throw new Exception('Upload: Can\'t create destination. '.$this->root.$this->destination); |
|
154 | + } |
|
155 | + |
|
156 | + //create finfo object |
|
157 | + $this->finfo = new finfo(); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Set target filename |
|
162 | + * |
|
163 | + * @param string $filename |
|
164 | + */ |
|
165 | + public function set_filename($filename) |
|
166 | + { |
|
167 | + $this->filename = $filename; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Check & Save file |
|
172 | + * |
|
173 | + * Return data about current upload |
|
174 | + * |
|
175 | + * @return array |
|
176 | + */ |
|
177 | + public function upload($filename = '') |
|
178 | + { |
|
179 | + if ($this->check()) { |
|
180 | + $this->save(); |
|
181 | + } |
|
182 | + // return state data |
|
183 | + return $this->get_state(); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Save file on server |
|
189 | + * |
|
190 | + * Return state data |
|
191 | + * |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + public function save() |
|
195 | + { |
|
196 | + $this->save_file(); |
|
197 | + return $this->get_state(); |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Validate file (execute callbacks) |
|
203 | + * |
|
204 | + * Returns TRUE if validation successful |
|
205 | + * |
|
206 | + * @return bool |
|
207 | + */ |
|
208 | + public function check() |
|
209 | + { |
|
210 | + //execute callbacks (check filesize, mime, also external callbacks |
|
211 | + $this->validate(); |
|
212 | + |
|
213 | + //add error messages |
|
214 | + $this->file['errors'] = $this->get_errors(); |
|
215 | + |
|
216 | + //change file validation status |
|
217 | + $this->file['status'] = empty($this->validation_errors); |
|
218 | + |
|
219 | + return $this->file['status']; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Get current state data |
|
224 | + * |
|
225 | + * @return array |
|
226 | + */ |
|
227 | + public function get_state() |
|
228 | + { |
|
229 | + return $this->file; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * Save file on server |
|
235 | + */ |
|
236 | + protected function save_file() |
|
237 | + { |
|
238 | + //create & set new filename |
|
239 | + if (empty($this->filename)) { |
|
240 | + $this->create_new_filename(); |
|
241 | + } |
|
242 | + |
|
243 | + //set filename |
|
244 | + $this->file['filename'] = $this->filename; |
|
245 | + |
|
246 | + //set full path |
|
247 | + $this->file['full_path'] = $this->root.$this->destination.$this->filename; |
|
248 | + $this->file['path'] = $this->destination.$this->filename; |
|
249 | + |
|
250 | + $status = move_uploaded_file($this->tmp_name, $this->file['full_path']); |
|
251 | + |
|
252 | + //checks whether upload successful |
|
253 | + if (!$status) { |
|
254 | + throw new Exception('Upload: Can\'t upload file.'); |
|
255 | + } |
|
256 | + |
|
257 | + //done |
|
258 | + $this->file['status'] = true; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Set data about file |
|
263 | + */ |
|
264 | + protected function set_file_data() |
|
265 | + { |
|
266 | + $file_size = $this->get_file_size(); |
|
267 | + |
|
268 | + $this->file = array( |
|
269 | + 'status' => false, |
|
270 | + 'destination' => $this->destination, |
|
271 | + 'size_in_bytes' => $file_size, |
|
272 | + 'size_in_mb' => $this->bytes_to_mb($file_size), |
|
273 | + 'mime' => $this->get_file_mime(), |
|
274 | + 'original_filename' => $this->file_post['name'], |
|
275 | + 'tmp_name' => $this->file_post['tmp_name'], |
|
276 | + 'post_data' => $this->file_post, |
|
277 | + ); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Set validation error |
|
282 | + * |
|
283 | + * @param string $message |
|
284 | + */ |
|
285 | + public function set_error($message) |
|
286 | + { |
|
287 | + $this->validation_errors[] = $message; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Return validation errors |
|
292 | + * |
|
293 | + * @return array |
|
294 | + */ |
|
295 | + public function get_errors() |
|
296 | + { |
|
297 | + return $this->validation_errors; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Set external callback methods |
|
302 | + * |
|
303 | + * @param object $instance_of_callback_object |
|
304 | + * @param array $callback_methods |
|
305 | + * @throws Exception |
|
306 | + */ |
|
307 | + public function callbacks($instance_of_callback_object, $callback_methods) |
|
308 | + { |
|
309 | + if (empty($instance_of_callback_object)) { |
|
310 | + throw new Exception('Upload: $instance_of_callback_object can\'t be empty.'); |
|
311 | + } |
|
312 | + |
|
313 | + if (!is_array($callback_methods)) { |
|
314 | + throw new Exception('Upload: $callback_methods data type need to be array.'); |
|
315 | + } |
|
316 | + |
|
317 | + $this->external_callback_object = $instance_of_callback_object; |
|
318 | + $this->external_callback_methods = $callback_methods; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Execute callbacks |
|
323 | + */ |
|
324 | + protected function validate() |
|
325 | + { |
|
326 | + //get curent errors |
|
327 | + $errors = $this->get_errors(); |
|
328 | + |
|
329 | + if (empty($errors)) { |
|
330 | + //set data about current file |
|
331 | + $this->set_file_data(); |
|
332 | + |
|
333 | + //execute internal callbacks |
|
334 | + $this->execute_callbacks($this->callbacks, $this); |
|
335 | + |
|
336 | + //execute external callbacks |
|
337 | + $this->execute_callbacks($this->external_callback_methods, $this->external_callback_object); |
|
338 | + } |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Execute callbacks |
|
343 | + */ |
|
344 | + protected function execute_callbacks($callbacks, $object) |
|
345 | + { |
|
346 | + foreach ($callbacks as $method) { |
|
347 | + $object->$method($this); |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * File mime type validation callback |
|
353 | + * |
|
354 | + * @param mixed $object |
|
355 | + */ |
|
356 | + protected function check_mime_type($object) |
|
357 | + { |
|
358 | + if (!empty($object->mimes)) { |
|
359 | + if (!in_array($object->file['mime'], $object->mimes)) { |
|
360 | + $object->set_error('Mime type not allowed.'); |
|
361 | + } |
|
362 | + } |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Set allowed mime types |
|
367 | + * |
|
368 | + * @param string[] $mimes |
|
369 | + */ |
|
370 | + public function set_allowed_mime_types($mimes) |
|
371 | + { |
|
372 | + $this->mimes = $mimes; |
|
373 | + //if mime types is set -> set callback |
|
374 | + $this->callbacks[] = 'check_mime_type'; |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * File size validation callback |
|
379 | + * |
|
380 | + * @param object $object |
|
381 | + */ |
|
382 | + protected function check_file_size($object) |
|
383 | + { |
|
384 | + if (!empty($object->max_file_size)) { |
|
385 | + $file_size_in_mb = $this->bytes_to_mb($object->file['size_in_bytes']); |
|
386 | + if ($object->max_file_size <= $file_size_in_mb) { |
|
387 | + $object->set_error('File is too big.'); |
|
388 | + } |
|
389 | + } |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Set max. file size |
|
394 | + * |
|
395 | + * @param int $size |
|
396 | + */ |
|
397 | + public function set_max_file_size($size) |
|
398 | + { |
|
399 | + $this->max_file_size = $size; |
|
400 | + //if max file size is set -> set callback |
|
401 | + $this->callbacks[] = 'check_file_size'; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Set File array to object |
|
406 | + * |
|
407 | + * @param array $file |
|
408 | + */ |
|
409 | + public function file($file) |
|
410 | + { |
|
411 | + $this->set_file_array($file); |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Set file array |
|
416 | + * |
|
417 | + * @param array $file |
|
418 | + */ |
|
419 | + protected function set_file_array($file) |
|
420 | + { |
|
421 | + //checks whether file array is valid |
|
422 | + if (!$this->check_file_array($file)) { |
|
423 | + //file not selected or some bigger problems (broken files array) |
|
424 | + $this->set_error('Please select file.'); |
|
425 | + } |
|
426 | + |
|
427 | + //set file data |
|
428 | + $this->file_post = $file; |
|
429 | + |
|
430 | + //set tmp path |
|
431 | + $this->tmp_name = $file['tmp_name']; |
|
432 | + |
|
433 | + // set file extension |
|
434 | + $this->extension = pathinfo($file['name'], PATHINFO_EXTENSION); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Checks whether Files post array is valid |
|
439 | + * |
|
440 | + * @return bool |
|
441 | + */ |
|
442 | + protected function check_file_array($file) |
|
443 | + { |
|
444 | + return isset($file['error']) |
|
445 | + && !empty($file['name']) |
|
446 | + && !empty($file['type']) |
|
447 | + && !empty($file['tmp_name']) |
|
448 | + && !empty($file['size']); |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Get file mime type |
|
453 | + * |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + protected function get_file_mime() |
|
457 | + { |
|
458 | + return $this->finfo->file($this->tmp_name, FILEINFO_MIME_TYPE); |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * Get file size |
|
463 | + * |
|
464 | + * @return int |
|
465 | + */ |
|
466 | + protected function get_file_size() |
|
467 | + { |
|
468 | + return filesize($this->tmp_name); |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Set destination path (return TRUE on success) |
|
473 | + * |
|
474 | + * @param string $destination |
|
475 | + * @return bool |
|
476 | + */ |
|
477 | + protected function set_destination($destination) |
|
478 | + { |
|
479 | + $this->destination = $destination.DIRECTORY_SEPARATOR; |
|
480 | + return $this->destination_exist() ? TRUE : $this->create_destination(); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Checks whether destination folder exists |
|
485 | + * |
|
486 | + * @return bool |
|
487 | + */ |
|
488 | + protected function destination_exist() |
|
489 | + { |
|
490 | + return is_writable($this->root.$this->destination); |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Create path to destination |
|
495 | + * |
|
496 | + * @return bool |
|
497 | + */ |
|
498 | + protected function create_destination() |
|
499 | + { |
|
500 | + return mkdir($this->root.$this->destination, $this->default_permissions, true); |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Set unique filename |
|
505 | + * |
|
506 | + * @return string |
|
507 | + */ |
|
508 | + protected function create_new_filename() |
|
509 | + { |
|
510 | + $filename = sha1(mt_rand(1, 9999).$this->destination.uniqid()).time().'.'.$this->extension; |
|
511 | + $this->set_filename($filename); |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * Convert bytes to mb. |
|
516 | + * |
|
517 | + * @param int $bytes |
|
518 | + * @return double |
|
519 | + */ |
|
520 | + protected function bytes_to_mb($bytes) |
|
521 | + { |
|
522 | + return round(($bytes / 1048576), 2); |
|
523 | + } |
|
524 | 524 | |
525 | 525 | |
526 | 526 | } // end of Upload |
527 | 527 | \ No newline at end of file |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | { |
13 | 13 | global $phpbb_root_path; |
14 | 14 | |
15 | - $database = $phpbb_root_path . 'store/messenger.db'; |
|
16 | - parent::__construct('sqlite:' . $database); |
|
15 | + $database = $phpbb_root_path.'store/messenger.db'; |
|
16 | + parent::__construct('sqlite:'.$database); |
|
17 | 17 | parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
18 | 18 | } |
19 | 19 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | //ksort($data); |
42 | 42 | |
43 | 43 | $fieldNames = implode('`, `', array_keys($data)); |
44 | - $fieldValues = ':' . implode(', :', array_keys($data)); |
|
44 | + $fieldValues = ':'.implode(', :', array_keys($data)); |
|
45 | 45 | |
46 | 46 | $sth = $this->prepare("INSERT INTO $table (`$fieldNames`) VALUES ($fieldValues)"); |
47 | 47 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param string $phpbb_root_path phpBB root path |
34 | 34 | */ |
35 | 35 | public function __construct($phpbb_root_path) { |
36 | - $this->directory = $phpbb_root_path . 'store/messenger/files'; |
|
36 | + $this->directory = $phpbb_root_path.'store/messenger/files'; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | * @throws InvalidArgumentException when the file not exist or is not readable |
44 | 44 | */ |
45 | 45 | public function setFile($filename) { |
46 | - $file_full_path = $this->directory . '/'. $filename; |
|
47 | - if(!is_file($file_full_path)) { |
|
46 | + $file_full_path = $this->directory.'/'.$filename; |
|
47 | + if (!is_file($file_full_path)) { |
|
48 | 48 | throw new InvalidArgumentException("File does not exist"); |
49 | - } else if(!is_readable($file_full_path)) { |
|
49 | + } else if (!is_readable($file_full_path)) { |
|
50 | 50 | throw new InvalidArgumentException("File to download is not readable."); |
51 | 51 | } |
52 | 52 | $this->filename = $filename; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @param bool|true $forceDownload |
81 | 81 | */ |
82 | 82 | public function sendDownload($forceDownload = true) { |
83 | - if(headers_sent()) { |
|
83 | + if (headers_sent()) { |
|
84 | 84 | throw new \RuntimeException("Cannot send file to the browser, since the headers were already sent"); |
85 | 85 | } |
86 | 86 | $mimeType = $this->getMimeType(); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | header("Cache-Control: private", false); |
96 | 96 | header("Content-Type: application/octet-stream"); |
97 | 97 | |
98 | - if($forceDownload) { |
|
98 | + if ($forceDownload) { |
|
99 | 99 | header("Content-Disposition: attachment; filename=\"{$this->filename}\";"); |
100 | 100 | } else { |
101 | 101 | header("Content-Disposition: filename=\"{$this->filename}\";"); |