| @@ -6,14 +6,14 @@ discard block | ||
| 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 | ||
| 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 | } | 
| @@ -12,35 +12,35 @@ discard block | ||
| 12 | 12 | class main_model | 
| 13 | 13 |  { | 
| 14 | 14 | |
| 15 | - /** | |
| 16 | - * @var config | |
| 17 | - */ | |
| 18 | - protected $config; | |
| 19 | - | |
| 20 | - /** | |
| 21 | - * @var driver_interface | |
| 22 | - */ | |
| 23 | - protected $phpbb_db; | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * @var user | |
| 27 | - */ | |
| 28 | - protected $user; | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * @var database | |
| 32 | - */ | |
| 33 | - protected $db; | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * @var string | |
| 37 | - */ | |
| 38 | - protected $friends_request_table; | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * @var string | |
| 42 | - */ | |
| 43 | - protected $user_friends_table; | |
| 15 | + /** | |
| 16 | + * @var config | |
| 17 | + */ | |
| 18 | + protected $config; | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * @var driver_interface | |
| 22 | + */ | |
| 23 | + protected $phpbb_db; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * @var user | |
| 27 | + */ | |
| 28 | + protected $user; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * @var database | |
| 32 | + */ | |
| 33 | + protected $db; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * @var string | |
| 37 | + */ | |
| 38 | + protected $friends_request_table; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * @var string | |
| 42 | + */ | |
| 43 | + protected $user_friends_table; | |
| 44 | 44 | |
| 45 | 45 | /** | 
| 46 | 46 | * @var user_loader | 
| @@ -48,32 +48,32 @@ discard block | ||
| 48 | 48 | protected $user_loader; | 
| 49 | 49 | |
| 50 | 50 | |
| 51 | - public function __construct( | |
| 52 | - config $config, | |
| 53 | - driver_interface $phpbb_db, | |
| 54 | - user $user, | |
| 51 | + public function __construct( | |
| 52 | + config $config, | |
| 53 | + driver_interface $phpbb_db, | |
| 54 | + user $user, | |
| 55 | 55 | user_loader $user_loader, | 
| 56 | - database $db, | |
| 57 | - $friends_request_table, | |
| 58 | - $user_friends_table | |
| 59 | - ) | |
| 60 | -    { | |
| 61 | - $this->config = $config; | |
| 62 | - $this->phpbb_db = $phpbb_db; | |
| 63 | - $this->user = $user; | |
| 64 | - $this->db = $db; | |
| 65 | - $this->friends_request_table = $friends_request_table; | |
| 66 | - $this->user_friends_table = $user_friends_table; | |
| 56 | + database $db, | |
| 57 | + $friends_request_table, | |
| 58 | + $user_friends_table | |
| 59 | + ) | |
| 60 | +	{ | |
| 61 | + $this->config = $config; | |
| 62 | + $this->phpbb_db = $phpbb_db; | |
| 63 | + $this->user = $user; | |
| 64 | + $this->db = $db; | |
| 65 | + $this->friends_request_table = $friends_request_table; | |
| 66 | + $this->user_friends_table = $user_friends_table; | |
| 67 | 67 | $this->user_loader = $user_loader; | 
| 68 | - } | |
| 69 | - | |
| 70 | - /** | |
| 71 | - * get all friends | |
| 72 | - * @return array the list of friends | |
| 73 | - */ | |
| 74 | - public function getFriends() | |
| 75 | -    { | |
| 76 | - $sql = " | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * get all friends | |
| 72 | + * @return array the list of friends | |
| 73 | + */ | |
| 74 | + public function getFriends() | |
| 75 | +	{ | |
| 76 | + $sql = " | |
| 77 | 77 | SELECT u.user_id, | 
| 78 | 78 | u.username, | 
| 79 | 79 | u.username_clean, | 
| @@ -87,32 +87,32 @@ discard block | ||
| 87 | 87 | WHERE " . $this->user_friends_table.".user_id = ".(int)$this->user->data['user_id']." | 
| 88 | 88 | GROUP BY u.user_id | 
| 89 | 89 | "; | 
| 90 | - $result = $this->phpbb_db->sql_query($sql); | |
| 91 | - | |
| 92 | - $friends = array(); | |
| 93 | -        while ($row = $this->phpbb_db->sql_fetchrow($result)) { | |
| 94 | - $friends[] = array( | |
| 95 | - 'user_id' => $row['user_id'], | |
| 96 | - 'username' => $row['username_clean'], | |
| 97 | - 'user_colour' => $row['user_colour'], | |
| 98 | - 'user_status' => ($row['session_time'] >= (time() - ($this->config['load_online_time'] * 60))) ? 1 : 0, | |
| 90 | + $result = $this->phpbb_db->sql_query($sql); | |
| 91 | + | |
| 92 | + $friends = array(); | |
| 93 | +		while ($row = $this->phpbb_db->sql_fetchrow($result)) { | |
| 94 | + $friends[] = array( | |
| 95 | + 'user_id' => $row['user_id'], | |
| 96 | + 'username' => $row['username_clean'], | |
| 97 | + 'user_colour' => $row['user_colour'], | |
| 98 | + 'user_status' => ($row['session_time'] >= (time() - ($this->config['load_online_time'] * 60))) ? 1 : 0, | |
| 99 | 99 | 'user_avatar' => $this->user_loader->get_avatar($row['user_id'], true, true), | 
| 100 | - 'inbox' => $this->getInboxFromId($row['user_id']) | |
| 101 | - ); | |
| 102 | - } | |
| 103 | - $this->phpbb_db->sql_freeresult(); | |
| 104 | - | |
| 105 | - return $friends; | |
| 106 | - } | |
| 107 | - | |
| 108 | - /** | |
| 109 | - * checks if a user is friend with other user and vice-versa | |
| 110 | - * @param int $friend_id | |
| 111 | - * @return bool | |
| 112 | - */ | |
| 113 | - public function checkFriend($friend_id) | |
| 114 | -    { | |
| 115 | - $sql = " | |
| 100 | + 'inbox' => $this->getInboxFromId($row['user_id']) | |
| 101 | + ); | |
| 102 | + } | |
| 103 | + $this->phpbb_db->sql_freeresult(); | |
| 104 | + | |
| 105 | + return $friends; | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * checks if a user is friend with other user and vice-versa | |
| 110 | + * @param int $friend_id | |
| 111 | + * @return bool | |
| 112 | + */ | |
| 113 | + public function checkFriend($friend_id) | |
| 114 | +	{ | |
| 115 | + $sql = " | |
| 116 | 116 | SELECT COUNT(zebra_id) as friend_count | 
| 117 | 117 | FROM " . ZEBRA_TABLE." | 
| 118 | 118 | WHERE user_id = " . (int)$friend_id." | 
| @@ -211,48 +211,48 @@ discard block | ||
| 211 | 211 | LIMIT 1 | 
| 212 | 212 | "; | 
| 213 | 213 | |
| 214 | - $message = $this->db->select($sql, array( | |
| 215 | - ':id' => $id | |
| 216 | - )); | |
| 214 | + $message = $this->db->select($sql, array( | |
| 215 | + ':id' => $id | |
| 216 | + )); | |
| 217 | 217 | $message = $message[0]; | 
| 218 | 218 | $message = $this->parseMessage($message, $message['type']); | 
| 219 | 219 | |
| 220 | - return $message; | |
| 221 | - } | |
| 222 | - | |
| 223 | - /** | |
| 224 | - * Returns a file by id | |
| 225 | - * @param $id File id | |
| 226 | - * @return mixed | |
| 227 | - */ | |
| 228 | - public function getFileById($id) | |
| 229 | -    { | |
| 230 | - $sql = " | |
| 220 | + return $message; | |
| 221 | + } | |
| 222 | + | |
| 223 | + /** | |
| 224 | + * Returns a file by id | |
| 225 | + * @param $id File id | |
| 226 | + * @return mixed | |
| 227 | + */ | |
| 228 | + public function getFileById($id) | |
| 229 | +	{ | |
| 230 | + $sql = " | |
| 231 | 231 | SELECT * | 
| 232 | 232 | FROM `files` | 
| 233 | 233 | WHERE `id` = :id | 
| 234 | 234 | LIMIT 1 | 
| 235 | 235 | "; | 
| 236 | - $file = $this->db->select($sql, array( | |
| 237 | - ':id' => $id | |
| 238 | - )); | |
| 236 | + $file = $this->db->select($sql, array( | |
| 237 | + ':id' => $id | |
| 238 | + )); | |
| 239 | 239 | $file = $file[0]; | 
| 240 | 240 | $file = $this->parseFile($file, $file['type']); | 
| 241 | 241 | |
| 242 | - return $file; | |
| 243 | - } | |
| 242 | + return $file; | |
| 243 | + } | |
| 244 | 244 | |
| 245 | - /** | |
| 246 | - * Get all message from an user | |
| 247 | - * @param int $friend_id | |
| 248 | - * @return array | |
| 249 | - */ | |
| 250 | - public function getMessages($friend_id) | |
| 251 | -    { | |
| 245 | + /** | |
| 246 | + * Get all message from an user | |
| 247 | + * @param int $friend_id | |
| 248 | + * @return array | |
| 249 | + */ | |
| 250 | + public function getMessages($friend_id) | |
| 251 | +	{ | |
| 252 | 252 | $this->user_loader->load_users([$this->user->data['user_id'], $friend_id]); | 
| 253 | 253 | |
| 254 | - // get the sent messages | |
| 255 | - $sql = "SELECT * | |
| 254 | + // get the sent messages | |
| 255 | + $sql = "SELECT * | |
| 256 | 256 | FROM `messages` | 
| 257 | 257 | WHERE `sender_id` = :sender_id | 
| 258 | 258 | AND `receiver_id` = :receiver_id | 
| @@ -265,58 +265,58 @@ discard block | ||
| 265 | 265 | ORDER BY `sentAt` ASC | 
| 266 | 266 | "; | 
| 267 | 267 | |
| 268 | - $sentMessages = $this->db->select($sql, array( | |
| 269 | - ':sender_id' => $this->user->data['user_id'], | |
| 270 | - ':receiver_id' => $friend_id | |
| 271 | - )); | |
| 272 | - $getInbox = $this->db->select($sql, array( | |
| 273 | - ':sender_id' => $friend_id, | |
| 274 | - ':receiver_id' => $this->user->data['user_id'] | |
| 275 | - )); | |
| 276 | - | |
| 277 | - $sentFiles = $this->db->select($sqlFiles, array( | |
| 278 | - ':sender_id' => $this->user->data['user_id'], | |
| 279 | - ':receiver_id' => $friend_id | |
| 280 | - )); | |
| 281 | - $getFiles = $this->db->select($sqlFiles, array( | |
| 282 | - ':sender_id' => $friend_id, | |
| 283 | - ':receiver_id' => $this->user->data['user_id'] | |
| 284 | - )); | |
| 285 | - | |
| 286 | - $sent = array(); | |
| 287 | -        foreach ($sentMessages as $msg) { | |
| 288 | - $item = $this->parseMessage($msg, 'sent'); | |
| 289 | - $sent[] = $item; | |
| 290 | - } | |
| 291 | - $inbox = array(); | |
| 292 | -        foreach ($getInbox as $msg) { | |
| 293 | - $item = $this->parseMessage($msg, 'inbox'); | |
| 294 | - $inbox[] = $item; | |
| 295 | - } | |
| 296 | - | |
| 297 | -        foreach ($sentFiles as $file) { | |
| 298 | - $item = $this->parseFile($file, 'sent'); | |
| 299 | - $sent[] = $item; | |
| 300 | - } | |
| 301 | - | |
| 302 | -        foreach ($getFiles as $file) { | |
| 303 | - $item = $this->parseFile($file, 'inbox'); | |
| 304 | - $inbox[] = $item; | |
| 305 | - } | |
| 306 | - | |
| 307 | - $unsorted_messages = array_merge($sent, $inbox); | |
| 308 | - | |
| 309 | -        uasort($unsorted_messages, function ($a, $b) { | |
| 310 | - return ($a['sentAt'] > $b['sentAt']) ? -1 : 1; | |
| 311 | - }); | |
| 312 | - | |
| 313 | - $sorted_messages = array(); | |
| 314 | -        foreach ($unsorted_messages as $msg) { | |
| 315 | - $sorted_messages[] = $msg; | |
| 316 | - } | |
| 317 | - | |
| 318 | - return $sorted_messages; | |
| 319 | - } | |
| 268 | + $sentMessages = $this->db->select($sql, array( | |
| 269 | + ':sender_id' => $this->user->data['user_id'], | |
| 270 | + ':receiver_id' => $friend_id | |
| 271 | + )); | |
| 272 | + $getInbox = $this->db->select($sql, array( | |
| 273 | + ':sender_id' => $friend_id, | |
| 274 | + ':receiver_id' => $this->user->data['user_id'] | |
| 275 | + )); | |
| 276 | + | |
| 277 | + $sentFiles = $this->db->select($sqlFiles, array( | |
| 278 | + ':sender_id' => $this->user->data['user_id'], | |
| 279 | + ':receiver_id' => $friend_id | |
| 280 | + )); | |
| 281 | + $getFiles = $this->db->select($sqlFiles, array( | |
| 282 | + ':sender_id' => $friend_id, | |
| 283 | + ':receiver_id' => $this->user->data['user_id'] | |
| 284 | + )); | |
| 285 | + | |
| 286 | + $sent = array(); | |
| 287 | +		foreach ($sentMessages as $msg) { | |
| 288 | + $item = $this->parseMessage($msg, 'sent'); | |
| 289 | + $sent[] = $item; | |
| 290 | + } | |
| 291 | + $inbox = array(); | |
| 292 | +		foreach ($getInbox as $msg) { | |
| 293 | + $item = $this->parseMessage($msg, 'inbox'); | |
| 294 | + $inbox[] = $item; | |
| 295 | + } | |
| 296 | + | |
| 297 | +		foreach ($sentFiles as $file) { | |
| 298 | + $item = $this->parseFile($file, 'sent'); | |
| 299 | + $sent[] = $item; | |
| 300 | + } | |
| 301 | + | |
| 302 | +		foreach ($getFiles as $file) { | |
| 303 | + $item = $this->parseFile($file, 'inbox'); | |
| 304 | + $inbox[] = $item; | |
| 305 | + } | |
| 306 | + | |
| 307 | + $unsorted_messages = array_merge($sent, $inbox); | |
| 308 | + | |
| 309 | +		uasort($unsorted_messages, function ($a, $b) { | |
| 310 | + return ($a['sentAt'] > $b['sentAt']) ? -1 : 1; | |
| 311 | + }); | |
| 312 | + | |
| 313 | + $sorted_messages = array(); | |
| 314 | +		foreach ($unsorted_messages as $msg) { | |
| 315 | + $sorted_messages[] = $msg; | |
| 316 | + } | |
| 317 | + | |
| 318 | + return $sorted_messages; | |
| 319 | + } | |
| 320 | 320 | |
| 321 | 321 | /** | 
| 322 | 322 | * Parse message to specific array | 
| @@ -359,15 +359,15 @@ discard block | ||
| 359 | 359 | return $item; | 
| 360 | 360 | } | 
| 361 | 361 | |
| 362 | - /** | |
| 363 | - * Change messages status to read | |
| 364 | - * @param $friend_id | |
| 365 | - * @return int | |
| 366 | - */ | |
| 367 | - public function updateMessagesStatus($friend_id) | |
| 368 | -    { | |
| 362 | + /** | |
| 363 | + * Change messages status to read | |
| 364 | + * @param $friend_id | |
| 365 | + * @return int | |
| 366 | + */ | |
| 367 | + public function updateMessagesStatus($friend_id) | |
| 368 | +	{ | |
| 369 | 369 | |
| 370 | - $sql = " | |
| 370 | + $sql = " | |
| 371 | 371 | UPDATE `messages` | 
| 372 | 372 | SET `newMsg` = 0 | 
| 373 | 373 | WHERE `newMsg` = 1 | 
| @@ -14,119 +14,119 @@ | ||
| 14 | 14 | class main_listener implements EventSubscriberInterface | 
| 15 | 15 |  { | 
| 16 | 16 | |
| 17 | - static public function getSubscribedEvents() | |
| 18 | -    { | |
| 19 | - return array( | |
| 20 | - 'core.user_setup' => 'load_language_on_setup', | |
| 21 | - 'core.page_footer' => 'get_language', | |
| 22 | - 'core.page_header' => 'check_login', | |
| 23 | - 'core.memberlist_view_profile' => 'check_friends' | |
| 24 | - ); | |
| 25 | - } | |
| 26 | - | |
| 27 | - | |
| 28 | - /* @var \phpbb\template\template */ | |
| 29 | - protected $template; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * @var main_model | |
| 33 | - */ | |
| 34 | - protected $model; | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * @var friends_model | |
| 38 | - */ | |
| 39 | - protected $friends_model; | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * @var user | |
| 43 | - */ | |
| 44 | - protected $user; | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * @var symfony_request | |
| 48 | - */ | |
| 49 | - protected $symfony_request; | |
| 50 | - | |
| 51 | - public function __construct( | |
| 52 | - template $template, | |
| 53 | - main_model $model, | |
| 54 | - friends_model $friends_model, | |
| 55 | - user $user, | |
| 56 | - symfony_request $symfony_request | |
| 57 | - ) | |
| 58 | -    { | |
| 59 | - $this->template = $template; | |
| 60 | - $this->model = $model; | |
| 61 | - $this->friends_model = $friends_model; | |
| 62 | - $this->user = $user; | |
| 63 | - $this->symfony_request = $symfony_request; | |
| 64 | - } | |
| 65 | - | |
| 66 | - public function get_language() | |
| 67 | -    { | |
| 68 | - $this->template->assign_vars(array( | |
| 69 | - 'CHAT_LANGUAGE' => $this->user->lang_name | |
| 70 | - )); | |
| 71 | - } | |
| 72 | - | |
| 73 | - public function load_language_on_setup($event) | |
| 74 | -    { | |
| 75 | - $lang_set_ext = $event['lang_set_ext']; | |
| 76 | - $lang_set_ext[] = array( | |
| 77 | - 'ext_name' => 'florinp/messenger', | |
| 78 | - 'lang_set' => 'common', | |
| 79 | - ); | |
| 80 | - $event['lang_set_ext'] = $lang_set_ext; | |
| 81 | - } | |
| 82 | - | |
| 83 | - public function check_login() | |
| 84 | -    { | |
| 85 | - $s_enable_messenger = 0; | |
| 86 | -        if (in_array($this->user->data['user_type'], array(USER_NORMAL, USER_FOUNDER))) { | |
| 87 | - $s_enable_messenger = 1; | |
| 88 | - } | |
| 89 | -        $this->template->assign_var('S_ENABLE_MESSENGER', $s_enable_messenger); | |
| 90 | - } | |
| 91 | - | |
| 92 | - public function check_friends($event) | |
| 93 | -    { | |
| 94 | - $context = new RequestContext(); | |
| 95 | - $context->fromRequest($this->symfony_request); | |
| 96 | - $baseUrl = generate_board_url(true) . $context->getBaseUrl(); | |
| 97 | - | |
| 98 | - $scriptName = $this->symfony_request->getScriptName(); | |
| 99 | - $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName); | |
| 100 | - | |
| 101 | -        if ($scriptName != '') { | |
| 102 | -            $baseUrl = str_replace('/' . $scriptName, '', $baseUrl); | |
| 103 | - } | |
| 104 | - | |
| 105 | - $user_id = $event['member']['user_id']; | |
| 106 | - $sender_id = $this->user->data['user_id']; | |
| 107 | - $request = $this->friends_model->get_request_by_sender_id($sender_id); | |
| 108 | - $check_friend = $this->friends_model->check_friend(array( | |
| 109 | - 'user_id' => $this->user->data['user_id'], | |
| 110 | - 'friend_id' => $user_id, | |
| 111 | - )); | |
| 112 | - $check_request = $this->friends_model->check_request(array( | |
| 113 | - 'user_id' => $user_id, | |
| 114 | - 'sender_id' => $this->user->data['user_id'] | |
| 115 | - )); | |
| 116 | - $check_request_confirm = $this->friends_model->check_request(array( | |
| 117 | - 'user_id' => $this->user->data['user_id'], | |
| 118 | - 'sender_id' => $user_id | |
| 119 | - )); | |
| 120 | - $check_widget = true; | |
| 121 | - if ($user_id == $this->user->data['user_id']) $check_widget = false; | |
| 122 | - $this->template->assign_vars(array( | |
| 123 | - 'U_USER_ID' => $user_id, | |
| 124 | - 'U_CHECK_FRIEND' => $check_friend, | |
| 125 | - 'U_CHECK_REQUEST' => $check_request, | |
| 126 | - 'U_CHECK_REQUEST_CONFIRM' => $check_request_confirm, | |
| 127 | - 'U_CHECK_WIDGET' => $check_widget, | |
| 128 | - 'U_REQUEST_ID' => $request['request_id'], | |
| 129 | - 'BASE_URL' => $baseUrl | |
| 130 | - )); | |
| 131 | - } | |
| 17 | + static public function getSubscribedEvents() | |
| 18 | +	{ | |
| 19 | + return array( | |
| 20 | + 'core.user_setup' => 'load_language_on_setup', | |
| 21 | + 'core.page_footer' => 'get_language', | |
| 22 | + 'core.page_header' => 'check_login', | |
| 23 | + 'core.memberlist_view_profile' => 'check_friends' | |
| 24 | + ); | |
| 25 | + } | |
| 26 | + | |
| 27 | + | |
| 28 | + /* @var \phpbb\template\template */ | |
| 29 | + protected $template; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * @var main_model | |
| 33 | + */ | |
| 34 | + protected $model; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * @var friends_model | |
| 38 | + */ | |
| 39 | + protected $friends_model; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * @var user | |
| 43 | + */ | |
| 44 | + protected $user; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * @var symfony_request | |
| 48 | + */ | |
| 49 | + protected $symfony_request; | |
| 50 | + | |
| 51 | + public function __construct( | |
| 52 | + template $template, | |
| 53 | + main_model $model, | |
| 54 | + friends_model $friends_model, | |
| 55 | + user $user, | |
| 56 | + symfony_request $symfony_request | |
| 57 | + ) | |
| 58 | +	{ | |
| 59 | + $this->template = $template; | |
| 60 | + $this->model = $model; | |
| 61 | + $this->friends_model = $friends_model; | |
| 62 | + $this->user = $user; | |
| 63 | + $this->symfony_request = $symfony_request; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public function get_language() | |
| 67 | +	{ | |
| 68 | + $this->template->assign_vars(array( | |
| 69 | + 'CHAT_LANGUAGE' => $this->user->lang_name | |
| 70 | + )); | |
| 71 | + } | |
| 72 | + | |
| 73 | + public function load_language_on_setup($event) | |
| 74 | +	{ | |
| 75 | + $lang_set_ext = $event['lang_set_ext']; | |
| 76 | + $lang_set_ext[] = array( | |
| 77 | + 'ext_name' => 'florinp/messenger', | |
| 78 | + 'lang_set' => 'common', | |
| 79 | + ); | |
| 80 | + $event['lang_set_ext'] = $lang_set_ext; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public function check_login() | |
| 84 | +	{ | |
| 85 | + $s_enable_messenger = 0; | |
| 86 | +		if (in_array($this->user->data['user_type'], array(USER_NORMAL, USER_FOUNDER))) { | |
| 87 | + $s_enable_messenger = 1; | |
| 88 | + } | |
| 89 | +		$this->template->assign_var('S_ENABLE_MESSENGER', $s_enable_messenger); | |
| 90 | + } | |
| 91 | + | |
| 92 | + public function check_friends($event) | |
| 93 | +	{ | |
| 94 | + $context = new RequestContext(); | |
| 95 | + $context->fromRequest($this->symfony_request); | |
| 96 | + $baseUrl = generate_board_url(true) . $context->getBaseUrl(); | |
| 97 | + | |
| 98 | + $scriptName = $this->symfony_request->getScriptName(); | |
| 99 | + $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName); | |
| 100 | + | |
| 101 | +		if ($scriptName != '') { | |
| 102 | +			$baseUrl = str_replace('/' . $scriptName, '', $baseUrl); | |
| 103 | + } | |
| 104 | + | |
| 105 | + $user_id = $event['member']['user_id']; | |
| 106 | + $sender_id = $this->user->data['user_id']; | |
| 107 | + $request = $this->friends_model->get_request_by_sender_id($sender_id); | |
| 108 | + $check_friend = $this->friends_model->check_friend(array( | |
| 109 | + 'user_id' => $this->user->data['user_id'], | |
| 110 | + 'friend_id' => $user_id, | |
| 111 | + )); | |
| 112 | + $check_request = $this->friends_model->check_request(array( | |
| 113 | + 'user_id' => $user_id, | |
| 114 | + 'sender_id' => $this->user->data['user_id'] | |
| 115 | + )); | |
| 116 | + $check_request_confirm = $this->friends_model->check_request(array( | |
| 117 | + 'user_id' => $this->user->data['user_id'], | |
| 118 | + 'sender_id' => $user_id | |
| 119 | + )); | |
| 120 | + $check_widget = true; | |
| 121 | + if ($user_id == $this->user->data['user_id']) $check_widget = false; | |
| 122 | + $this->template->assign_vars(array( | |
| 123 | + 'U_USER_ID' => $user_id, | |
| 124 | + 'U_CHECK_FRIEND' => $check_friend, | |
| 125 | + 'U_CHECK_REQUEST' => $check_request, | |
| 126 | + 'U_CHECK_REQUEST_CONFIRM' => $check_request_confirm, | |
| 127 | + 'U_CHECK_WIDGET' => $check_widget, | |
| 128 | + 'U_REQUEST_ID' => $request['request_id'], | |
| 129 | + 'BASE_URL' => $baseUrl | |
| 130 | + )); | |
| 131 | + } | |
| 132 | 132 | } |