@@ -14,144 +14,144 @@ |
||
| 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' => 'friends_list', |
|
| 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 friends_list() |
|
| 67 | - { |
|
| 68 | - $context = new RequestContext(); |
|
| 69 | - $context->fromRequest($this->symfony_request); |
|
| 70 | - $baseUrl = generate_board_url(true) . $context->getBaseUrl(); |
|
| 71 | - |
|
| 72 | - $scriptName = $this->symfony_request->getScriptName(); |
|
| 73 | - $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName); |
|
| 74 | - |
|
| 75 | - if ($scriptName != '') { |
|
| 76 | - $baseUrl = str_replace('/' . $scriptName, '', $baseUrl); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $friends = $this->model->getFriends(); |
|
| 80 | - $friends_online = array_filter($friends, function ($friend) { |
|
| 81 | - return $friend['user_status'] != 0; |
|
| 82 | - }); |
|
| 83 | - $this->template->assign_var('S_COUNT_FRIENDS', count($friends_online)); |
|
| 84 | - foreach ($friends as $friend) { |
|
| 85 | - $this->template->assign_block_vars('chat_friends', array( |
|
| 86 | - 'U_USERID' => $friend['user_id'], |
|
| 87 | - 'U_USERNAME' => $friend['username'], |
|
| 88 | - 'U_USERCOLOR' => $friend['user_colour'], |
|
| 89 | - 'U_STATUS' => $friend['user_status'], |
|
| 90 | - 'U_USERINBOX' => $friend['inbox'], |
|
| 91 | - )); |
|
| 92 | - } |
|
| 93 | - $this->template->assign_vars(array( |
|
| 94 | - 'BASE_URL' => $baseUrl |
|
| 95 | - )); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - public function load_language_on_setup($event) |
|
| 99 | - { |
|
| 100 | - $lang_set_ext = $event['lang_set_ext']; |
|
| 101 | - $lang_set_ext[] = array( |
|
| 102 | - 'ext_name' => 'florinp/messenger', |
|
| 103 | - 'lang_set' => 'common', |
|
| 104 | - ); |
|
| 105 | - $event['lang_set_ext'] = $lang_set_ext; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function check_login() |
|
| 109 | - { |
|
| 110 | - $s_enable_messenger = 0; |
|
| 111 | - if (in_array($this->user->data['user_type'], array(USER_NORMAL, USER_FOUNDER))) { |
|
| 112 | - $s_enable_messenger = 1; |
|
| 113 | - } |
|
| 114 | - $this->template->assign_var('S_ENABLE_MESSENGER', $s_enable_messenger); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - public function check_friends($event) |
|
| 118 | - { |
|
| 119 | - $context = new RequestContext(); |
|
| 120 | - $context->fromRequest($this->symfony_request); |
|
| 121 | - $baseUrl = generate_board_url(true) . $context->getBaseUrl(); |
|
| 122 | - |
|
| 123 | - $scriptName = $this->symfony_request->getScriptName(); |
|
| 124 | - $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName); |
|
| 125 | - |
|
| 126 | - if ($scriptName != '') { |
|
| 127 | - $baseUrl = str_replace('/' . $scriptName, '', $baseUrl); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $user_id = $event['member']['user_id']; |
|
| 131 | - $sender_id = $this->user->data['user_id']; |
|
| 132 | - $request = $this->friends_model->get_request_by_sender_id($sender_id); |
|
| 133 | - $check_friend = $this->friends_model->check_friend(array( |
|
| 134 | - 'user_id' => $this->user->data['user_id'], |
|
| 135 | - 'friend_id' => $user_id, |
|
| 136 | - )); |
|
| 137 | - $check_request = $this->friends_model->check_request(array( |
|
| 138 | - 'user_id' => $user_id, |
|
| 139 | - 'sender_id' => $this->user->data['user_id'] |
|
| 140 | - )); |
|
| 141 | - $check_request_confirm = $this->friends_model->check_request(array( |
|
| 142 | - 'user_id' => $this->user->data['user_id'], |
|
| 143 | - 'sender_id' => $user_id |
|
| 144 | - )); |
|
| 145 | - $check_widget = true; |
|
| 146 | - if ($user_id == $this->user->data['user_id']) $check_widget = false; |
|
| 147 | - $this->template->assign_vars(array( |
|
| 148 | - 'U_USER_ID' => $user_id, |
|
| 149 | - 'U_CHECK_FRIEND' => $check_friend, |
|
| 150 | - 'U_CHECK_REQUEST' => $check_request, |
|
| 151 | - 'U_CHECK_REQUEST_CONFIRM' => $check_request_confirm, |
|
| 152 | - 'U_CHECK_WIDGET' => $check_widget, |
|
| 153 | - 'U_REQUEST_ID' => $request['request_id'], |
|
| 154 | - 'BASE_URL' => $baseUrl |
|
| 155 | - )); |
|
| 156 | - } |
|
| 17 | + static public function getSubscribedEvents() |
|
| 18 | + { |
|
| 19 | + return array( |
|
| 20 | + 'core.user_setup' => 'load_language_on_setup', |
|
| 21 | + 'core.page_footer' => 'friends_list', |
|
| 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 friends_list() |
|
| 67 | + { |
|
| 68 | + $context = new RequestContext(); |
|
| 69 | + $context->fromRequest($this->symfony_request); |
|
| 70 | + $baseUrl = generate_board_url(true) . $context->getBaseUrl(); |
|
| 71 | + |
|
| 72 | + $scriptName = $this->symfony_request->getScriptName(); |
|
| 73 | + $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName); |
|
| 74 | + |
|
| 75 | + if ($scriptName != '') { |
|
| 76 | + $baseUrl = str_replace('/' . $scriptName, '', $baseUrl); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $friends = $this->model->getFriends(); |
|
| 80 | + $friends_online = array_filter($friends, function ($friend) { |
|
| 81 | + return $friend['user_status'] != 0; |
|
| 82 | + }); |
|
| 83 | + $this->template->assign_var('S_COUNT_FRIENDS', count($friends_online)); |
|
| 84 | + foreach ($friends as $friend) { |
|
| 85 | + $this->template->assign_block_vars('chat_friends', array( |
|
| 86 | + 'U_USERID' => $friend['user_id'], |
|
| 87 | + 'U_USERNAME' => $friend['username'], |
|
| 88 | + 'U_USERCOLOR' => $friend['user_colour'], |
|
| 89 | + 'U_STATUS' => $friend['user_status'], |
|
| 90 | + 'U_USERINBOX' => $friend['inbox'], |
|
| 91 | + )); |
|
| 92 | + } |
|
| 93 | + $this->template->assign_vars(array( |
|
| 94 | + 'BASE_URL' => $baseUrl |
|
| 95 | + )); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + public function load_language_on_setup($event) |
|
| 99 | + { |
|
| 100 | + $lang_set_ext = $event['lang_set_ext']; |
|
| 101 | + $lang_set_ext[] = array( |
|
| 102 | + 'ext_name' => 'florinp/messenger', |
|
| 103 | + 'lang_set' => 'common', |
|
| 104 | + ); |
|
| 105 | + $event['lang_set_ext'] = $lang_set_ext; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function check_login() |
|
| 109 | + { |
|
| 110 | + $s_enable_messenger = 0; |
|
| 111 | + if (in_array($this->user->data['user_type'], array(USER_NORMAL, USER_FOUNDER))) { |
|
| 112 | + $s_enable_messenger = 1; |
|
| 113 | + } |
|
| 114 | + $this->template->assign_var('S_ENABLE_MESSENGER', $s_enable_messenger); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + public function check_friends($event) |
|
| 118 | + { |
|
| 119 | + $context = new RequestContext(); |
|
| 120 | + $context->fromRequest($this->symfony_request); |
|
| 121 | + $baseUrl = generate_board_url(true) . $context->getBaseUrl(); |
|
| 122 | + |
|
| 123 | + $scriptName = $this->symfony_request->getScriptName(); |
|
| 124 | + $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName); |
|
| 125 | + |
|
| 126 | + if ($scriptName != '') { |
|
| 127 | + $baseUrl = str_replace('/' . $scriptName, '', $baseUrl); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $user_id = $event['member']['user_id']; |
|
| 131 | + $sender_id = $this->user->data['user_id']; |
|
| 132 | + $request = $this->friends_model->get_request_by_sender_id($sender_id); |
|
| 133 | + $check_friend = $this->friends_model->check_friend(array( |
|
| 134 | + 'user_id' => $this->user->data['user_id'], |
|
| 135 | + 'friend_id' => $user_id, |
|
| 136 | + )); |
|
| 137 | + $check_request = $this->friends_model->check_request(array( |
|
| 138 | + 'user_id' => $user_id, |
|
| 139 | + 'sender_id' => $this->user->data['user_id'] |
|
| 140 | + )); |
|
| 141 | + $check_request_confirm = $this->friends_model->check_request(array( |
|
| 142 | + 'user_id' => $this->user->data['user_id'], |
|
| 143 | + 'sender_id' => $user_id |
|
| 144 | + )); |
|
| 145 | + $check_widget = true; |
|
| 146 | + if ($user_id == $this->user->data['user_id']) $check_widget = false; |
|
| 147 | + $this->template->assign_vars(array( |
|
| 148 | + 'U_USER_ID' => $user_id, |
|
| 149 | + 'U_CHECK_FRIEND' => $check_friend, |
|
| 150 | + 'U_CHECK_REQUEST' => $check_request, |
|
| 151 | + 'U_CHECK_REQUEST_CONFIRM' => $check_request_confirm, |
|
| 152 | + 'U_CHECK_WIDGET' => $check_widget, |
|
| 153 | + 'U_REQUEST_ID' => $request['request_id'], |
|
| 154 | + 'BASE_URL' => $baseUrl |
|
| 155 | + )); |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -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']; |
@@ -143,7 +143,9 @@ |
||
| 143 | 143 | 'sender_id' => $user_id |
| 144 | 144 | )); |
| 145 | 145 | $check_widget = true; |
| 146 | - if ($user_id == $this->user->data['user_id']) $check_widget = false; |
|
| 146 | + if ($user_id == $this->user->data['user_id']) { |
|
| 147 | + $check_widget = false; |
|
| 148 | + } |
|
| 147 | 149 | $this->template->assign_vars(array( |
| 148 | 150 | 'U_USER_ID' => $user_id, |
| 149 | 151 | 'U_CHECK_FRIEND' => $check_friend, |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | public function insert_friends_request(array $data) |
| 135 | 135 | { |
| 136 | 136 | $sql = " |
| 137 | - INSERT INTO " . $this->friends_request_table . " |
|
| 137 | + INSERT INTO " . $this->friends_request_table." |
|
| 138 | 138 | ( |
| 139 | 139 | `user_id`, |
| 140 | 140 | `sender_id`, |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | public function delete_friend_request($request_id) |
| 158 | 158 | { |
| 159 | 159 | $sql = " |
| 160 | - DELETE FROM " . $this->friends_request_table . " WHERE `request_id` = " . (int)$request_id . " |
|
| 160 | + DELETE FROM " . $this->friends_request_table." WHERE `request_id` = ".(int)$request_id." |
|
| 161 | 161 | "; |
| 162 | 162 | |
| 163 | 163 | return $this->db->sql_query($sql); |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | public function approve_friend_request($request_id) |
| 167 | 167 | { |
| 168 | 168 | $sql = " |
| 169 | - UPDATE " . $this->friends_request_table . " SET `status` = 1 WHERE `request_id` = " . (int)$request_id . " |
|
| 169 | + UPDATE " . $this->friends_request_table." SET `status` = 1 WHERE `request_id` = ".(int)$request_id." |
|
| 170 | 170 | "; |
| 171 | 171 | |
| 172 | 172 | return $this->db->sql_query($sql); |
@@ -178,15 +178,15 @@ discard block |
||
| 178 | 178 | $check_friend = $this->check_friend($data); |
| 179 | 179 | if ($check_friend == false) { |
| 180 | 180 | $sql = " |
| 181 | - INSERT INTO " . $this->user_friends_table . " |
|
| 181 | + INSERT INTO " . $this->user_friends_table." |
|
| 182 | 182 | ( |
| 183 | 183 | `user_id`, |
| 184 | 184 | `friend_id` |
| 185 | 185 | ) |
| 186 | 186 | VALUES |
| 187 | 187 | ( |
| 188 | - " . (int)$data['user_id'] . ", |
|
| 189 | - " . (int)$data['friend_id'] . " |
|
| 188 | + " . (int)$data['user_id'].", |
|
| 189 | + " . (int)$data['friend_id']." |
|
| 190 | 190 | ) |
| 191 | 191 | "; |
| 192 | 192 | if ($this->db->sql_query($sql)) { |
@@ -242,10 +242,10 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | public function remove_friend($user_id) |
| 244 | 244 | { |
| 245 | - $sql = "DELETE FROM " . $this->user_friends_table . " WHERE `user_id` = " . (int)$user_id . ""; |
|
| 245 | + $sql = "DELETE FROM ".$this->user_friends_table." WHERE `user_id` = ".(int)$user_id.""; |
|
| 246 | 246 | $this->db->sql_query($sql); |
| 247 | 247 | |
| 248 | - $sql = "DELETE FROM " . $this->user_friends_table . " WHERE `friend_id` = " . (int)$user_id . ""; |
|
| 248 | + $sql = "DELETE FROM ".$this->user_friends_table." WHERE `friend_id` = ".(int)$user_id.""; |
|
| 249 | 249 | $this->db->sql_query($sql); |
| 250 | 250 | } |
| 251 | 251 | |