Completed
Push — master ( 798c64...8bad15 )
by Florin
02:22
created
libs/download.php 2 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -5,109 +5,109 @@
 block discarded – undo
5 5
 use InvalidArgumentException;
6 6
 class download {
7 7
 
8
-    /**
9
-     * File directory
10
-     * @var string
11
-     */
12
-    protected $directory;
13
-
14
-    /**
15
-     * File name
16
-     * @var string
17
-     */
18
-    protected $filename;
19
-
20
-    /**
21
-     * File pointer
22
-     * @var resource
23
-     */
24
-    protected $file;
25
-
26
-    /**
27
-     * File full path
28
-     * @var string
29
-     */
30
-    protected $full_path;
31
-
32
-    /**
33
-     * @param string $phpbb_root_path phpBB root path
34
-     */
35
-    public function __construct($phpbb_root_path) {
36
-        $this->directory = $phpbb_root_path . 'store/messenger/files';
37
-    }
38
-
39
-
40
-    /**
41
-     * Set the filename
42
-     * @param string $filename File name
43
-     * @throws InvalidArgumentException when the file not exist or is not readable
44
-     */
45
-    public function setFile($filename) {
46
-        $file_full_path = $this->directory . '/'. $filename;
47
-        if(!is_file($file_full_path)) {
48
-            throw new InvalidArgumentException("File does not exist");
49
-        } else if(!is_readable($file_full_path)) {
50
-            throw new InvalidArgumentException("File to download is not readable.");
51
-        }
52
-        $this->filename = $filename;
53
-        $this->file = fopen($file_full_path, 'rb');
54
-        $this->full_path = $file_full_path;
55
-    }
56
-
57
-    /**
58
-     * Get file mime type
59
-     * @return string
60
-     */
61
-    private function getMimeType() {
62
-        $fileExtension = pathinfo($this->filename, PATHINFO_EXTENSION);
63
-        $mimeTypeHelper = Mimetypes::getInstance();
64
-        $mimeType = $mimeTypeHelper->fromExtension($fileExtension);
65
-
66
-        return !is_null($mimeType) ? $mimeType : 'application/force-download';
67
-    }
68
-
69
-    /**
70
-     * Get file size
71
-     * @return int
72
-     */
73
-    private function getFileSize() {
74
-        $stat = fstat($this->file);
75
-        return $stat['size'];
76
-    }
77
-
78
-    /**
79
-     * Sends the download to browser
80
-     * @param bool|true $forceDownload
81
-     */
82
-    public function sendDownload($forceDownload = true) {
83
-        if(headers_sent()) {
84
-            throw new \RuntimeException("Cannot send file to the browser, since the headers were already sent");
85
-        }
86
-        $mimeType = $this->getMimeType();
87
-        $fileSize = $this->getFileSize();
88
-
89
-        ini_set('display_errors', 1);
90
-        error_reporting(E_ALL);
91
-
92
-        header("Pragma: public");
93
-        header("Expires: 0");
94
-        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
95
-        header("Cache-Control: private", false);
96
-        header("Content-Type: application/octet-stream");
97
-
98
-        if($forceDownload) {
99
-            header("Content-Disposition: attachment; filename=\"{$this->filename}\";");
100
-        } else {
101
-            header("Content-Disposition: filename=\"{$this->filename}\";");
102
-        }
103
-
104
-        header("Content-Transfer-Encoding: binary");
105
-        header("Content-Length: {$fileSize}");
106
-
107
-        @ob_clean();
108
-
109
-        rewind($this->file);
110
-        fpassthru($this->file);
111
-    }
8
+	/**
9
+	 * File directory
10
+	 * @var string
11
+	 */
12
+	protected $directory;
13
+
14
+	/**
15
+	 * File name
16
+	 * @var string
17
+	 */
18
+	protected $filename;
19
+
20
+	/**
21
+	 * File pointer
22
+	 * @var resource
23
+	 */
24
+	protected $file;
25
+
26
+	/**
27
+	 * File full path
28
+	 * @var string
29
+	 */
30
+	protected $full_path;
31
+
32
+	/**
33
+	 * @param string $phpbb_root_path phpBB root path
34
+	 */
35
+	public function __construct($phpbb_root_path) {
36
+		$this->directory = $phpbb_root_path . 'store/messenger/files';
37
+	}
38
+
39
+
40
+	/**
41
+	 * Set the filename
42
+	 * @param string $filename File name
43
+	 * @throws InvalidArgumentException when the file not exist or is not readable
44
+	 */
45
+	public function setFile($filename) {
46
+		$file_full_path = $this->directory . '/'. $filename;
47
+		if(!is_file($file_full_path)) {
48
+			throw new InvalidArgumentException("File does not exist");
49
+		} else if(!is_readable($file_full_path)) {
50
+			throw new InvalidArgumentException("File to download is not readable.");
51
+		}
52
+		$this->filename = $filename;
53
+		$this->file = fopen($file_full_path, 'rb');
54
+		$this->full_path = $file_full_path;
55
+	}
56
+
57
+	/**
58
+	 * Get file mime type
59
+	 * @return string
60
+	 */
61
+	private function getMimeType() {
62
+		$fileExtension = pathinfo($this->filename, PATHINFO_EXTENSION);
63
+		$mimeTypeHelper = Mimetypes::getInstance();
64
+		$mimeType = $mimeTypeHelper->fromExtension($fileExtension);
65
+
66
+		return !is_null($mimeType) ? $mimeType : 'application/force-download';
67
+	}
68
+
69
+	/**
70
+	 * Get file size
71
+	 * @return int
72
+	 */
73
+	private function getFileSize() {
74
+		$stat = fstat($this->file);
75
+		return $stat['size'];
76
+	}
77
+
78
+	/**
79
+	 * Sends the download to browser
80
+	 * @param bool|true $forceDownload
81
+	 */
82
+	public function sendDownload($forceDownload = true) {
83
+		if(headers_sent()) {
84
+			throw new \RuntimeException("Cannot send file to the browser, since the headers were already sent");
85
+		}
86
+		$mimeType = $this->getMimeType();
87
+		$fileSize = $this->getFileSize();
88
+
89
+		ini_set('display_errors', 1);
90
+		error_reporting(E_ALL);
91
+
92
+		header("Pragma: public");
93
+		header("Expires: 0");
94
+		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
95
+		header("Cache-Control: private", false);
96
+		header("Content-Type: application/octet-stream");
97
+
98
+		if($forceDownload) {
99
+			header("Content-Disposition: attachment; filename=\"{$this->filename}\";");
100
+		} else {
101
+			header("Content-Disposition: filename=\"{$this->filename}\";");
102
+		}
103
+
104
+		header("Content-Transfer-Encoding: binary");
105
+		header("Content-Length: {$fileSize}");
106
+
107
+		@ob_clean();
108
+
109
+		rewind($this->file);
110
+		fpassthru($this->file);
111
+	}
112 112
 
113 113
 }
114 114
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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}\";");
Please login to merge, or discard this patch.
controller/main.php 2 patches
Indentation   +242 added lines, -242 removed lines patch added patch discarded remove patch
@@ -8,247 +8,247 @@
 block discarded – undo
8 8
 class main
9 9
 {
10 10
 
11
-    protected $config;
12
-    protected $helper;
13
-    protected $template;
14
-    protected $user;
15
-    protected $model;
16
-    protected $request;
17
-    protected $notification_manager;
18
-    protected $emojione;
19
-    protected $upload;
20
-    protected $download;
21
-
22
-    public function __construct(
23
-        \phpbb\config\config $config,
24
-        \phpbb\controller\helper $helper,
25
-        \phpbb\template\template $template,
26
-        \phpbb\request\request $request,
27
-        \phpbb\user $user,
28
-        \florinp\messenger\models\main_model $model,
29
-        \phpbb\notification\manager $notification_manager,
30
-        \florinp\messenger\libs\emojione $emojione,
31
-        \florinp\messenger\libs\upload $upload,
32
-        \florinp\messenger\libs\download $download
33
-    )
34
-    {
35
-        $this->config = $config;
36
-        $this->helper = $helper;
37
-        $this->template = $template;
38
-        $this->request = $request;
39
-        $this->user = $user;
40
-        $this->model = $model;
41
-        $this->notification_manager = $notification_manager;
42
-        $this->emojione = $emojione;
43
-        $this->upload = $upload;
44
-        $this->download = $download;
45
-    }
46
-
47
-    public function handle()
48
-    {
49
-    }
50
-
51
-    public function index()
52
-    {
53
-
54
-    }
55
-
56
-    public function publish()
57
-    {
58
-        /* AJAX check  */
59
-        $http_request = $this->request->server('HTTP_X_REQUESTED_WITH');
60
-        if (empty($http_request) && strtolower($http_request) != 'xmlhttprequest') {
61
-            return new Response("The request is invalid", 500);
62
-        }
63
-
64
-        $text = $this->request->variable('text', '', true);
65
-        $receiver_id = $this->request->variable('receiver_id', 0);
66
-        $sender_id = $this->user->data['user_id'];
67
-
68
-
69
-        if ($receiver_id != 0 && trim($text) != '') {
70
-            $text = htmlspecialchars($text);
71
-            $text = str_replace(array("\n", "\r"), '', $text);
72
-
73
-            $message = array(
74
-                'sender_id' => $sender_id,
75
-                'receiver_id' => $receiver_id,
76
-                'text' => $text,
77
-                'sentAt' => time()
78
-            );
79
-
80
-            if ($id = $this->model->sendMessage($message)) {
81
-                $lastMessage = $this->model->getMessageById($id);
82
-                $response = array('success' => true, 'message' => $lastMessage);
83
-            } else {
84
-                $response = array(
85
-                    'succes' => false,
86
-                    'error' => 'An error has been ocurred!'
87
-                );
88
-            }
89
-        }
90
-
91
-        return new JsonResponse($response, 200);
92
-    }
93
-
94
-    public function getFile($id)
95
-    {
96
-        $id = explode('_', $id)[1];
97
-        $file = $this->model->getFileById($id);
98
-        $this->download->setFile($file['file']);
99
-        $this->download->sendDownload();
100
-    }
101
-
102
-    public function sendFile()
103
-    {
104
-        $receiver_id = $this->request->variable('receiver_id', 0);
105
-        $sender_id = $this->user->data['user_id'];
106
-
107
-        $file = $this->request->file('file');
108
-        if ($receiver_id != 0 && !empty($file)) {
109
-            if ($file['error'] == 0) {
110
-                $this->upload->file($file);
111
-                $this->upload->set_allowed_mime_types(array(
112
-                    'image/gif',
113
-                    'image/jpeg',
114
-                    'image/png',
115
-                    'application/pdf',
116
-                    'application/x-rar-compressed',
117
-                    'application/zip',
118
-                    'application/x-7z-compressed',
119
-                    'text/plain'
120
-                ));
121
-                $results = $this->upload->upload();
122
-                if (isset($results['errors']) && count($results['errors'])) {
123
-                    $response = array(
124
-                        'success' => false,
125
-                        'errors' => $results['errors']
126
-                    );
127
-                } else {
128
-                    $data = array(
129
-                        'sender_id' => $sender_id,
130
-                        'receiver_id' => $receiver_id,
131
-                        'fileName' => $results['original_filename'],
132
-                        'file' => $results['filename'],
133
-                        'type' => $results['mime'],
134
-                    );
135
-                    if ($id = $this->model->sendFile($data)) {
136
-                        $lastFile = $this->model->getFileById($id);
137
-                        $response = array(
138
-                            'success' => true,
139
-                            'file' => $lastFile
140
-                        );
141
-                    } else {
142
-                        $response = array(
143
-                            'succes' => false,
144
-                            'error' => 'An error has been ocurred!'
145
-                        );
146
-                    }
147
-                }
148
-            } else {
149
-                $response = array(
150
-                    'succes' => false,
151
-                    'error' => $file['error']
152
-                );
153
-            }
154
-        } else {
155
-            $response = array(
156
-                'succes' => false,
157
-                'error' => 'An error has been ocurred!'
158
-            );
159
-        }
160
-
161
-        return new JsonResponse($response, 200);
162
-    }
163
-
164
-    public function load()
165
-    {
166
-        /* AJAX check  */
167
-        $http_request = $this->request->server('HTTP_X_REQUESTED_WITH');
168
-        if (empty($http_request) && strtolower($http_request) != 'xmlhttprequest') {
169
-            return new Response("The request is invalid", 500);
170
-        }
171
-
172
-        $friend_id = $this->request->variable('friend_id', 0);
173
-
174
-        if ($friend_id > 0) {
175
-            $messages = $this->model->getMessages($friend_id);
176
-            return new JsonResponse($messages, 200);
177
-        }
178
-        return new JsonResponse(array('success' => false, 'error' => 'The request is invalid'), 200);
179
-    }
180
-
181
-    public function updateMessages()
182
-    {
183
-        /* AJAX check  */
184
-        $http_request = $this->request->server('HTTP_X_REQUESTED_WITH');
185
-        if (empty($http_request) && strtolower($http_request) != 'xmlhttprequest') {
186
-            return new Response("The request is invalid", 500);
187
-        }
188
-
189
-        $friend_id = $this->request->variable('friend_id', 0);
190
-        if ($friend_id > 0) {
191
-            $newVal = $this->model->updateMessagesStatus($friend_id);
192
-            return new JsonResponse(array('success' => true, 'newVal' => $newVal), 200);
193
-        }
194
-        return new JsonResponse(array('success' => false), 200);
195
-    }
196
-
197
-    public function checkForNewMessages()
198
-    {
199
-        /* AJAX check  */
200
-        $http_request = $this->request->server('HTTP_X_REQUESTED_WITH');
201
-        if (empty($http_request) && strtolower($http_request) != 'xmlhttprequest') {
202
-            return new Response("The request is invalid", 500);
203
-        }
204
-
205
-        $friend_id = $this->request->variable('friend_id', 0);
206
-        if ($friend_id > 0) {
207
-            $messages = $this->model->getInboxFromId($friend_id);
208
-            return new JsonResponse(array('success' => true, 'messages' => $messages), 200);
209
-        }
210
-        return new JsonResponse(array('success' => false), 200);
211
-    }
212
-
213
-    public function getFriends()
214
-    {
215
-        /* AJAX check  */
216
-        $http_request = $this->request->server('HTTP_X_REQUESTED_WITH');
217
-        if (empty($http_request) && strtolower($http_request) != 'xmlhttprequest') {
218
-            return new Response("The request is invalid", 500);
219
-        }
220
-
221
-        $friends = $this->model->getFriends();
222
-        $friends_online = array_filter($friends, function ($friend) {
223
-            return $friend['user_status'] != 0;
224
-        });
225
-
226
-        $response = array(
227
-            'friends_online' => count($friends_online),
228
-            'friends_list' => $friends
229
-        );
230
-
231
-        return new JsonResponse($response, 200);
232
-    }
233
-
234
-    public function getEmoticons()
235
-    {
236
-        $emoticons = \florinp\messenger\libs\emojione::$ascii_replace;
237
-        $eicons = array();
238
-        foreach ($emoticons as $code => $value) {
239
-            $eicons[$value] = $code;
240
-        }
241
-
242
-        $response = array();
243
-        foreach ($eicons as $emoticon) {
244
-            $item = array();
245
-            $item['code'] = $emoticon;
246
-            $item['image'] = $this->emojione->toImage($emoticon);
247
-
248
-            $response[] = $item;
249
-        }
250
-
251
-        return new JsonResponse($response, 200);
252
-    }
11
+	protected $config;
12
+	protected $helper;
13
+	protected $template;
14
+	protected $user;
15
+	protected $model;
16
+	protected $request;
17
+	protected $notification_manager;
18
+	protected $emojione;
19
+	protected $upload;
20
+	protected $download;
21
+
22
+	public function __construct(
23
+		\phpbb\config\config $config,
24
+		\phpbb\controller\helper $helper,
25
+		\phpbb\template\template $template,
26
+		\phpbb\request\request $request,
27
+		\phpbb\user $user,
28
+		\florinp\messenger\models\main_model $model,
29
+		\phpbb\notification\manager $notification_manager,
30
+		\florinp\messenger\libs\emojione $emojione,
31
+		\florinp\messenger\libs\upload $upload,
32
+		\florinp\messenger\libs\download $download
33
+	)
34
+	{
35
+		$this->config = $config;
36
+		$this->helper = $helper;
37
+		$this->template = $template;
38
+		$this->request = $request;
39
+		$this->user = $user;
40
+		$this->model = $model;
41
+		$this->notification_manager = $notification_manager;
42
+		$this->emojione = $emojione;
43
+		$this->upload = $upload;
44
+		$this->download = $download;
45
+	}
46
+
47
+	public function handle()
48
+	{
49
+	}
50
+
51
+	public function index()
52
+	{
53
+
54
+	}
55
+
56
+	public function publish()
57
+	{
58
+		/* AJAX check  */
59
+		$http_request = $this->request->server('HTTP_X_REQUESTED_WITH');
60
+		if (empty($http_request) && strtolower($http_request) != 'xmlhttprequest') {
61
+			return new Response("The request is invalid", 500);
62
+		}
63
+
64
+		$text = $this->request->variable('text', '', true);
65
+		$receiver_id = $this->request->variable('receiver_id', 0);
66
+		$sender_id = $this->user->data['user_id'];
67
+
68
+
69
+		if ($receiver_id != 0 && trim($text) != '') {
70
+			$text = htmlspecialchars($text);
71
+			$text = str_replace(array("\n", "\r"), '', $text);
72
+
73
+			$message = array(
74
+				'sender_id' => $sender_id,
75
+				'receiver_id' => $receiver_id,
76
+				'text' => $text,
77
+				'sentAt' => time()
78
+			);
79
+
80
+			if ($id = $this->model->sendMessage($message)) {
81
+				$lastMessage = $this->model->getMessageById($id);
82
+				$response = array('success' => true, 'message' => $lastMessage);
83
+			} else {
84
+				$response = array(
85
+					'succes' => false,
86
+					'error' => 'An error has been ocurred!'
87
+				);
88
+			}
89
+		}
90
+
91
+		return new JsonResponse($response, 200);
92
+	}
93
+
94
+	public function getFile($id)
95
+	{
96
+		$id = explode('_', $id)[1];
97
+		$file = $this->model->getFileById($id);
98
+		$this->download->setFile($file['file']);
99
+		$this->download->sendDownload();
100
+	}
101
+
102
+	public function sendFile()
103
+	{
104
+		$receiver_id = $this->request->variable('receiver_id', 0);
105
+		$sender_id = $this->user->data['user_id'];
106
+
107
+		$file = $this->request->file('file');
108
+		if ($receiver_id != 0 && !empty($file)) {
109
+			if ($file['error'] == 0) {
110
+				$this->upload->file($file);
111
+				$this->upload->set_allowed_mime_types(array(
112
+					'image/gif',
113
+					'image/jpeg',
114
+					'image/png',
115
+					'application/pdf',
116
+					'application/x-rar-compressed',
117
+					'application/zip',
118
+					'application/x-7z-compressed',
119
+					'text/plain'
120
+				));
121
+				$results = $this->upload->upload();
122
+				if (isset($results['errors']) && count($results['errors'])) {
123
+					$response = array(
124
+						'success' => false,
125
+						'errors' => $results['errors']
126
+					);
127
+				} else {
128
+					$data = array(
129
+						'sender_id' => $sender_id,
130
+						'receiver_id' => $receiver_id,
131
+						'fileName' => $results['original_filename'],
132
+						'file' => $results['filename'],
133
+						'type' => $results['mime'],
134
+					);
135
+					if ($id = $this->model->sendFile($data)) {
136
+						$lastFile = $this->model->getFileById($id);
137
+						$response = array(
138
+							'success' => true,
139
+							'file' => $lastFile
140
+						);
141
+					} else {
142
+						$response = array(
143
+							'succes' => false,
144
+							'error' => 'An error has been ocurred!'
145
+						);
146
+					}
147
+				}
148
+			} else {
149
+				$response = array(
150
+					'succes' => false,
151
+					'error' => $file['error']
152
+				);
153
+			}
154
+		} else {
155
+			$response = array(
156
+				'succes' => false,
157
+				'error' => 'An error has been ocurred!'
158
+			);
159
+		}
160
+
161
+		return new JsonResponse($response, 200);
162
+	}
163
+
164
+	public function load()
165
+	{
166
+		/* AJAX check  */
167
+		$http_request = $this->request->server('HTTP_X_REQUESTED_WITH');
168
+		if (empty($http_request) && strtolower($http_request) != 'xmlhttprequest') {
169
+			return new Response("The request is invalid", 500);
170
+		}
171
+
172
+		$friend_id = $this->request->variable('friend_id', 0);
173
+
174
+		if ($friend_id > 0) {
175
+			$messages = $this->model->getMessages($friend_id);
176
+			return new JsonResponse($messages, 200);
177
+		}
178
+		return new JsonResponse(array('success' => false, 'error' => 'The request is invalid'), 200);
179
+	}
180
+
181
+	public function updateMessages()
182
+	{
183
+		/* AJAX check  */
184
+		$http_request = $this->request->server('HTTP_X_REQUESTED_WITH');
185
+		if (empty($http_request) && strtolower($http_request) != 'xmlhttprequest') {
186
+			return new Response("The request is invalid", 500);
187
+		}
188
+
189
+		$friend_id = $this->request->variable('friend_id', 0);
190
+		if ($friend_id > 0) {
191
+			$newVal = $this->model->updateMessagesStatus($friend_id);
192
+			return new JsonResponse(array('success' => true, 'newVal' => $newVal), 200);
193
+		}
194
+		return new JsonResponse(array('success' => false), 200);
195
+	}
196
+
197
+	public function checkForNewMessages()
198
+	{
199
+		/* AJAX check  */
200
+		$http_request = $this->request->server('HTTP_X_REQUESTED_WITH');
201
+		if (empty($http_request) && strtolower($http_request) != 'xmlhttprequest') {
202
+			return new Response("The request is invalid", 500);
203
+		}
204
+
205
+		$friend_id = $this->request->variable('friend_id', 0);
206
+		if ($friend_id > 0) {
207
+			$messages = $this->model->getInboxFromId($friend_id);
208
+			return new JsonResponse(array('success' => true, 'messages' => $messages), 200);
209
+		}
210
+		return new JsonResponse(array('success' => false), 200);
211
+	}
212
+
213
+	public function getFriends()
214
+	{
215
+		/* AJAX check  */
216
+		$http_request = $this->request->server('HTTP_X_REQUESTED_WITH');
217
+		if (empty($http_request) && strtolower($http_request) != 'xmlhttprequest') {
218
+			return new Response("The request is invalid", 500);
219
+		}
220
+
221
+		$friends = $this->model->getFriends();
222
+		$friends_online = array_filter($friends, function ($friend) {
223
+			return $friend['user_status'] != 0;
224
+		});
225
+
226
+		$response = array(
227
+			'friends_online' => count($friends_online),
228
+			'friends_list' => $friends
229
+		);
230
+
231
+		return new JsonResponse($response, 200);
232
+	}
233
+
234
+	public function getEmoticons()
235
+	{
236
+		$emoticons = \florinp\messenger\libs\emojione::$ascii_replace;
237
+		$eicons = array();
238
+		foreach ($emoticons as $code => $value) {
239
+			$eicons[$value] = $code;
240
+		}
241
+
242
+		$response = array();
243
+		foreach ($eicons as $emoticon) {
244
+			$item = array();
245
+			$item['code'] = $emoticon;
246
+			$item['image'] = $this->emojione->toImage($emoticon);
247
+
248
+			$response[] = $item;
249
+		}
250
+
251
+		return new JsonResponse($response, 200);
252
+	}
253 253
 
254 254
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -219,7 +219,7 @@
 block discarded – undo
219 219
         }
220 220
 
221 221
         $friends = $this->model->getFriends();
222
-        $friends_online = array_filter($friends, function ($friend) {
222
+        $friends_online = array_filter($friends, function($friend) {
223 223
             return $friend['user_status'] != 0;
224 224
         });
225 225
 
Please login to merge, or discard this patch.
ext.php 2 patches
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@  discard block
 block discarded – undo
6 6
 class ext extends \phpbb\extension\base
7 7
 {
8 8
 
9
-    public function enable_step($old_state)
10
-    {
11
-        global $phpbb_root_path;
12
-
13
-        switch ($old_state) {
14
-            case '':
15
-                $db = new \florinp\messenger\libs\database();
16
-                $db->exec("
9
+	public function enable_step($old_state)
10
+	{
11
+		global $phpbb_root_path;
12
+
13
+		switch ($old_state) {
14
+			case '':
15
+				$db = new \florinp\messenger\libs\database();
16
+				$db->exec("
17 17
           CREATE TABLE IF NOT EXISTS messages (
18 18
             `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
19 19
             `sender_id` INTEGER NOT NULL,
@@ -33,87 +33,87 @@  discard block
 block discarded – undo
33 33
           );
34 34
         ");
35 35
 
36
-                $messengerDir = $phpbb_root_path . 'store/messenger';
37
-                if (!is_dir($messengerDir)) {
38
-                    mkdir($messengerDir, 0777);
39
-                    $filesDir = $messengerDir . '/files';
40
-                    if (!is_dir($filesDir)) {
41
-                        mkdir($filesDir, 0777);
42
-                    }
43
-                }
44
-                return 'notifications';
45
-                break;
46
-
47
-            case 'notifications':
48
-                $phpbb_notifications = $this->container->get('notification_manager');
49
-                $phpbb_notifications->enable_notifications('florinp.messenger.notification.type.friend_request');
50
-                return 'step2';
51
-                break;
52
-
53
-            default:
54
-                return parent::enable_step($old_state);
55
-                break;
56
-        }
57
-
58
-    }
59
-
60
-    public function disable_step($old_state)
61
-    {
62
-        switch ($old_state) {
63
-            case '':
64
-                $phpbb_notifications = $this->container->get('notification_manager');
65
-                $phpbb_notifications->disable_notifications('florinp.messenger.notification.type.friend_request');
66
-                return 'notifications';
67
-                break;
68
-
69
-            default:
70
-
71
-                return parent::disable_step($old_state);
72
-                break;
73
-        }
74
-    }
75
-
76
-    public function purge_step($old_state)
77
-    {
78
-        global $phpbb_root_path;
79
-
80
-        $database = $phpbb_root_path . 'store/messenger.db';
81
-        if (is_file($database)) {
82
-            unlink($database);
83
-        }
84
-
85
-        $messengerDir = $phpbb_root_path . 'store/messenger';
86
-        if (is_dir($messengerDir)) {
87
-            $objects = scandir($messengerDir);
88
-            foreach ($objects as $object) {
89
-                if ($object != '.' && $object != '..') {
90
-                    if (filetype($messengerDir . "/" . $object) == "dir") {
91
-                        $dir = $messengerDir . "/" . $object;
92
-                        $subObjects = scandir($dir);
93
-                        if(count($subObjects) > 0) {
94
-                            foreach($subObjects as $subObject) {
95
-                                if($subObject != '.' && $subObject != '..') {
96
-                                    if(filetype($dir . '/' . $subObject) != 'dir') {
97
-                                        unlink($dir . '/' . $subObject);
98
-                                    }
99
-                                } else {
100
-                                    continue;
101
-                                }
102
-                            }
103
-
104
-                        }
105
-                        rmdir($messengerDir . "/" . $object);
106
-                    } else {
107
-                        unlink($messengerDir . "/" . $object);
108
-                    }
109
-                }
110
-            }
111
-            reset($objects);
112
-            rmdir($messengerDir);
113
-        }
114
-
115
-        return parent::purge_step($old_state);
116
-
117
-    }
36
+				$messengerDir = $phpbb_root_path . 'store/messenger';
37
+				if (!is_dir($messengerDir)) {
38
+					mkdir($messengerDir, 0777);
39
+					$filesDir = $messengerDir . '/files';
40
+					if (!is_dir($filesDir)) {
41
+						mkdir($filesDir, 0777);
42
+					}
43
+				}
44
+				return 'notifications';
45
+				break;
46
+
47
+			case 'notifications':
48
+				$phpbb_notifications = $this->container->get('notification_manager');
49
+				$phpbb_notifications->enable_notifications('florinp.messenger.notification.type.friend_request');
50
+				return 'step2';
51
+				break;
52
+
53
+			default:
54
+				return parent::enable_step($old_state);
55
+				break;
56
+		}
57
+
58
+	}
59
+
60
+	public function disable_step($old_state)
61
+	{
62
+		switch ($old_state) {
63
+			case '':
64
+				$phpbb_notifications = $this->container->get('notification_manager');
65
+				$phpbb_notifications->disable_notifications('florinp.messenger.notification.type.friend_request');
66
+				return 'notifications';
67
+				break;
68
+
69
+			default:
70
+
71
+				return parent::disable_step($old_state);
72
+				break;
73
+		}
74
+	}
75
+
76
+	public function purge_step($old_state)
77
+	{
78
+		global $phpbb_root_path;
79
+
80
+		$database = $phpbb_root_path . 'store/messenger.db';
81
+		if (is_file($database)) {
82
+			unlink($database);
83
+		}
84
+
85
+		$messengerDir = $phpbb_root_path . 'store/messenger';
86
+		if (is_dir($messengerDir)) {
87
+			$objects = scandir($messengerDir);
88
+			foreach ($objects as $object) {
89
+				if ($object != '.' && $object != '..') {
90
+					if (filetype($messengerDir . "/" . $object) == "dir") {
91
+						$dir = $messengerDir . "/" . $object;
92
+						$subObjects = scandir($dir);
93
+						if(count($subObjects) > 0) {
94
+							foreach($subObjects as $subObject) {
95
+								if($subObject != '.' && $subObject != '..') {
96
+									if(filetype($dir . '/' . $subObject) != 'dir') {
97
+										unlink($dir . '/' . $subObject);
98
+									}
99
+								} else {
100
+									continue;
101
+								}
102
+							}
103
+
104
+						}
105
+						rmdir($messengerDir . "/" . $object);
106
+					} else {
107
+						unlink($messengerDir . "/" . $object);
108
+					}
109
+				}
110
+			}
111
+			reset($objects);
112
+			rmdir($messengerDir);
113
+		}
114
+
115
+		return parent::purge_step($old_state);
116
+
117
+	}
118 118
 
119 119
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -33,10 +33,10 @@  discard block
 block discarded – undo
33 33
           );
34 34
         ");
35 35
 
36
-                $messengerDir = $phpbb_root_path . 'store/messenger';
36
+                $messengerDir = $phpbb_root_path.'store/messenger';
37 37
                 if (!is_dir($messengerDir)) {
38 38
                     mkdir($messengerDir, 0777);
39
-                    $filesDir = $messengerDir . '/files';
39
+                    $filesDir = $messengerDir.'/files';
40 40
                     if (!is_dir($filesDir)) {
41 41
                         mkdir($filesDir, 0777);
42 42
                     }
@@ -77,24 +77,24 @@  discard block
 block discarded – undo
77 77
     {
78 78
         global $phpbb_root_path;
79 79
 
80
-        $database = $phpbb_root_path . 'store/messenger.db';
80
+        $database = $phpbb_root_path.'store/messenger.db';
81 81
         if (is_file($database)) {
82 82
             unlink($database);
83 83
         }
84 84
 
85
-        $messengerDir = $phpbb_root_path . 'store/messenger';
85
+        $messengerDir = $phpbb_root_path.'store/messenger';
86 86
         if (is_dir($messengerDir)) {
87 87
             $objects = scandir($messengerDir);
88 88
             foreach ($objects as $object) {
89 89
                 if ($object != '.' && $object != '..') {
90
-                    if (filetype($messengerDir . "/" . $object) == "dir") {
91
-                        $dir = $messengerDir . "/" . $object;
90
+                    if (filetype($messengerDir."/".$object) == "dir") {
91
+                        $dir = $messengerDir."/".$object;
92 92
                         $subObjects = scandir($dir);
93
-                        if(count($subObjects) > 0) {
94
-                            foreach($subObjects as $subObject) {
95
-                                if($subObject != '.' && $subObject != '..') {
96
-                                    if(filetype($dir . '/' . $subObject) != 'dir') {
97
-                                        unlink($dir . '/' . $subObject);
93
+                        if (count($subObjects) > 0) {
94
+                            foreach ($subObjects as $subObject) {
95
+                                if ($subObject != '.' && $subObject != '..') {
96
+                                    if (filetype($dir.'/'.$subObject) != 'dir') {
97
+                                        unlink($dir.'/'.$subObject);
98 98
                                     }
99 99
                                 } else {
100 100
                                     continue;
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
                             }
103 103
 
104 104
                         }
105
-                        rmdir($messengerDir . "/" . $object);
105
+                        rmdir($messengerDir."/".$object);
106 106
                     } else {
107
-                        unlink($messengerDir . "/" . $object);
107
+                        unlink($messengerDir."/".$object);
108 108
                     }
109 109
                 }
110 110
             }
Please login to merge, or discard this patch.