@@ -2,8 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace florinp\messenger\tests\controller; |
4 | 4 | |
5 | -use Symfony\Component\HttpFoundation\JsonResponse; |
|
6 | - |
|
7 | 5 | class main_test extends \phpbb_test_case { |
8 | 6 | |
9 | 7 | /** |
@@ -6,114 +6,114 @@ |
||
6 | 6 | |
7 | 7 | class main_test extends \phpbb_test_case { |
8 | 8 | |
9 | - /** |
|
10 | - * @var \florinp\messenger\controller\main |
|
11 | - */ |
|
12 | - protected $controller; |
|
13 | - |
|
14 | - public function setUp() { |
|
15 | - parent::setUp(); |
|
16 | - /** |
|
17 | - * @var \phpbb\user $user Mock the user class |
|
18 | - */ |
|
19 | - $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); |
|
20 | - |
|
21 | - /** |
|
22 | - * @var \phpbb\request\request $request |
|
23 | - */ |
|
24 | - $request = $this->getMockBuilder('\phpbb\request\request') |
|
25 | - ->disableOriginalConstructor() |
|
26 | - ->getMock(); |
|
27 | - |
|
28 | - /** |
|
29 | - * @var \florinp\messenger\models\main_model $model |
|
30 | - */ |
|
31 | - $model = $this->getMockBuilder('\florinp\messenger\models\main_model') |
|
32 | - ->disableOriginalConstructor() |
|
33 | - ->getMock(); |
|
34 | - |
|
35 | - /** |
|
36 | - * @var \phpbb\notification\manager $notification_manager |
|
37 | - */ |
|
38 | - $notification_manager = $this->getMockBuilder('\phpbb\notification\manager') |
|
39 | - ->disableOriginalConstructor() |
|
40 | - ->getMock(); |
|
41 | - |
|
42 | - /** |
|
43 | - * @var \florinp\messenger\libs\emojione $emojione |
|
44 | - */ |
|
45 | - $emojione = $this->getMockBuilder('\florinp\messenger\libs\emojione') |
|
46 | - ->disableOriginalConstructor() |
|
47 | - ->getMock(); |
|
48 | - |
|
49 | - /** |
|
50 | - * @var \florinp\messenger\libs\upload $upload |
|
51 | - */ |
|
52 | - $upload = $this->getMockBuilder('\florinp\messenger\libs\upload') |
|
53 | - ->disableOriginalConstructor() |
|
54 | - ->getMock(); |
|
55 | - |
|
56 | - /** |
|
57 | - * @var \florinp\messenger\libs\download $download |
|
58 | - */ |
|
59 | - $download = $this->getMockBuilder('\florinp\messenger\libs\download') |
|
60 | - ->disableOriginalConstructor() |
|
61 | - ->getMock(); |
|
62 | - |
|
63 | - $this->controller = new \florinp\messenger\controller\main( |
|
64 | - $request, |
|
65 | - $user, |
|
66 | - $model, |
|
67 | - $notification_manager, |
|
68 | - $emojione, |
|
69 | - $upload, |
|
70 | - $download |
|
71 | - ); |
|
72 | - } |
|
73 | - |
|
74 | - public function tearDown() { |
|
75 | - $this->controller = null; |
|
76 | - parent::tearDown(); |
|
77 | - } |
|
78 | - |
|
79 | - public function publish_data() { |
|
80 | - return array( |
|
81 | - array(200, json_encode(array())) |
|
82 | - ); |
|
83 | - } |
|
84 | - /** |
|
85 | - * @dataProvider publish_data |
|
86 | - */ |
|
87 | - public function test_publish($status_code, $page_content) { |
|
88 | - $response = $this->controller->publish(); |
|
89 | - $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
|
90 | - $this->assertEquals($status_code, $response->getStatusCode()); |
|
91 | - $this->assertEquals($page_content, $response->getContent()); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - public function load_data() { |
|
96 | - return array( |
|
97 | - array(200, json_encode(array( |
|
98 | - 'success' => false, |
|
99 | - 'error' => 'The request is invalid' |
|
100 | - ))) |
|
101 | - ); |
|
102 | - } |
|
103 | - /** |
|
104 | - * @dataProvider load_data |
|
105 | - */ |
|
106 | - public function test_load($status_code, $page_content) { |
|
107 | - $response = $this->controller->load(); |
|
108 | - $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
|
109 | - $this->assertEquals($status_code, $response->getStatusCode()); |
|
110 | - $this->assertEquals($page_content, $response->getContent()); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - public function updateMessages_data() { |
|
115 | - return array( |
|
116 | - array(200, json_encode(array('success' => false))) |
|
117 | - ); |
|
118 | - } |
|
9 | + /** |
|
10 | + * @var \florinp\messenger\controller\main |
|
11 | + */ |
|
12 | + protected $controller; |
|
13 | + |
|
14 | + public function setUp() { |
|
15 | + parent::setUp(); |
|
16 | + /** |
|
17 | + * @var \phpbb\user $user Mock the user class |
|
18 | + */ |
|
19 | + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); |
|
20 | + |
|
21 | + /** |
|
22 | + * @var \phpbb\request\request $request |
|
23 | + */ |
|
24 | + $request = $this->getMockBuilder('\phpbb\request\request') |
|
25 | + ->disableOriginalConstructor() |
|
26 | + ->getMock(); |
|
27 | + |
|
28 | + /** |
|
29 | + * @var \florinp\messenger\models\main_model $model |
|
30 | + */ |
|
31 | + $model = $this->getMockBuilder('\florinp\messenger\models\main_model') |
|
32 | + ->disableOriginalConstructor() |
|
33 | + ->getMock(); |
|
34 | + |
|
35 | + /** |
|
36 | + * @var \phpbb\notification\manager $notification_manager |
|
37 | + */ |
|
38 | + $notification_manager = $this->getMockBuilder('\phpbb\notification\manager') |
|
39 | + ->disableOriginalConstructor() |
|
40 | + ->getMock(); |
|
41 | + |
|
42 | + /** |
|
43 | + * @var \florinp\messenger\libs\emojione $emojione |
|
44 | + */ |
|
45 | + $emojione = $this->getMockBuilder('\florinp\messenger\libs\emojione') |
|
46 | + ->disableOriginalConstructor() |
|
47 | + ->getMock(); |
|
48 | + |
|
49 | + /** |
|
50 | + * @var \florinp\messenger\libs\upload $upload |
|
51 | + */ |
|
52 | + $upload = $this->getMockBuilder('\florinp\messenger\libs\upload') |
|
53 | + ->disableOriginalConstructor() |
|
54 | + ->getMock(); |
|
55 | + |
|
56 | + /** |
|
57 | + * @var \florinp\messenger\libs\download $download |
|
58 | + */ |
|
59 | + $download = $this->getMockBuilder('\florinp\messenger\libs\download') |
|
60 | + ->disableOriginalConstructor() |
|
61 | + ->getMock(); |
|
62 | + |
|
63 | + $this->controller = new \florinp\messenger\controller\main( |
|
64 | + $request, |
|
65 | + $user, |
|
66 | + $model, |
|
67 | + $notification_manager, |
|
68 | + $emojione, |
|
69 | + $upload, |
|
70 | + $download |
|
71 | + ); |
|
72 | + } |
|
73 | + |
|
74 | + public function tearDown() { |
|
75 | + $this->controller = null; |
|
76 | + parent::tearDown(); |
|
77 | + } |
|
78 | + |
|
79 | + public function publish_data() { |
|
80 | + return array( |
|
81 | + array(200, json_encode(array())) |
|
82 | + ); |
|
83 | + } |
|
84 | + /** |
|
85 | + * @dataProvider publish_data |
|
86 | + */ |
|
87 | + public function test_publish($status_code, $page_content) { |
|
88 | + $response = $this->controller->publish(); |
|
89 | + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
|
90 | + $this->assertEquals($status_code, $response->getStatusCode()); |
|
91 | + $this->assertEquals($page_content, $response->getContent()); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + public function load_data() { |
|
96 | + return array( |
|
97 | + array(200, json_encode(array( |
|
98 | + 'success' => false, |
|
99 | + 'error' => 'The request is invalid' |
|
100 | + ))) |
|
101 | + ); |
|
102 | + } |
|
103 | + /** |
|
104 | + * @dataProvider load_data |
|
105 | + */ |
|
106 | + public function test_load($status_code, $page_content) { |
|
107 | + $response = $this->controller->load(); |
|
108 | + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
|
109 | + $this->assertEquals($status_code, $response->getStatusCode()); |
|
110 | + $this->assertEquals($page_content, $response->getContent()); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + public function updateMessages_data() { |
|
115 | + return array( |
|
116 | + array(200, json_encode(array('success' => false))) |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | } |
120 | 120 | \ No newline at end of file |
@@ -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, |
@@ -12,160 +12,160 @@ |
||
12 | 12 | class friends |
13 | 13 | { |
14 | 14 | |
15 | - protected $template; |
|
16 | - protected $user; |
|
17 | - protected $user_loader; |
|
18 | - protected $model; |
|
19 | - protected $request; |
|
20 | - protected $notification_manager; |
|
21 | - protected $u_action; |
|
22 | - |
|
23 | - public function __construct( |
|
24 | - template $template, |
|
25 | - request $request, |
|
26 | - user $user, |
|
27 | - user_loader $user_loader, |
|
28 | - friends_model $model, |
|
29 | - manager $notification_manager |
|
30 | - ) |
|
31 | - { |
|
32 | - $this->template = $template; |
|
33 | - $this->request = $request; |
|
34 | - $this->user = $user; |
|
35 | - $this->user_loader = $user_loader; |
|
36 | - $this->model = $model; |
|
37 | - $this->notification_manager = $notification_manager; |
|
38 | - } |
|
39 | - |
|
40 | - public function friends_list() |
|
41 | - { |
|
42 | - $friends = $this->model->getFriends(); |
|
43 | - $i = 0; |
|
44 | - foreach ($friends as $friend) { |
|
45 | - $i = $i + 1; |
|
46 | - $this->user_loader->load_users(array( |
|
47 | - $friend['user_id'] |
|
48 | - )); |
|
49 | - $this->template->assign_block_vars('friends', array( |
|
50 | - 'user_id' => $friend['user_id'], |
|
51 | - 'username' => $this->user_loader->get_username($friend['user_id'], 'full'), |
|
52 | - 'user_colour' => $friend['user_colour'], |
|
53 | - 'user_status' => ($friend['user_status'] == 1) ? 'online' : 'offline', |
|
54 | - 'row_count' => $i |
|
55 | - )); |
|
56 | - } |
|
57 | - |
|
58 | - $this->template->assign_vars(array( |
|
59 | - 'U_ACTION' => $this->u_action, |
|
60 | - )); |
|
61 | - } |
|
62 | - |
|
63 | - public function requests() |
|
64 | - { |
|
65 | - $requests = $this->model->get_friends_requests(); |
|
66 | - $i = 0; |
|
67 | - foreach ($requests as $request) { |
|
68 | - $i = $i + 1; |
|
69 | - $this->user_loader->load_users(array( |
|
70 | - $request['user_id'], |
|
71 | - $request['sender_id'] |
|
72 | - )); |
|
73 | - $this->template->assign_block_vars('requests', array( |
|
74 | - 'request_id' => $request['request_id'], |
|
75 | - 'sender_username' => $this->user_loader->get_username($request['sender_id'], 'full'), |
|
76 | - 'status' => ($request['status'] == 1) ? ($this->user->lang['APPROVED']) : ($this->user->lang['WAITING_FOR_APPROVAL']), |
|
77 | - 'time' => date('d M Y H:i:s', $request['time']), |
|
78 | - 'row_count' => $i |
|
79 | - )); |
|
80 | - } |
|
81 | - |
|
82 | - $this->template->assign_vars(array( |
|
83 | - 'U_ACTION' => $this->u_action, |
|
84 | - )); |
|
85 | - } |
|
86 | - |
|
87 | - public function delete_request($requests_id) |
|
88 | - { |
|
89 | - if (is_array($requests_id)) { |
|
90 | - foreach ($requests_id as $id) { |
|
91 | - $this->model->delete_friend_request($id); |
|
92 | - } |
|
93 | - } else { |
|
94 | - $this->model->delete_friend_request($requests_id); |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - public function approve_request($requests_id) |
|
99 | - { |
|
100 | - if (is_array($requests_id)) { |
|
101 | - foreach ($requests_id as $id) { |
|
102 | - $request_data = $this->model->get_friend_request($id); |
|
103 | - if ($request_data) { |
|
104 | - $this->model->add_friend(array( |
|
105 | - 'user_id' => $request_data['user_id'], |
|
106 | - 'friend_id' => $request_data['sender_id'] |
|
107 | - )); |
|
108 | - } |
|
109 | - |
|
110 | - } |
|
111 | - } else { |
|
112 | - $this->model->approve_friend_request($requests_id); |
|
113 | - $request_data = $this->model->get_friend_request($requests_id); |
|
114 | - $this->model->add_friend(array( |
|
115 | - 'user_id' => $request_data['user_id'], |
|
116 | - 'friend_id' => $request_data['sender_id'] |
|
117 | - )); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - public function send_request($user_id) |
|
122 | - { |
|
123 | - $user_id = (int)$user_id; |
|
124 | - $sender_id = $this->user->data['user_id']; |
|
125 | - |
|
126 | - $insert = array( |
|
127 | - 'user_id' => $user_id, |
|
128 | - 'sender_id' => $sender_id |
|
129 | - ); |
|
130 | - |
|
131 | - if ($request_id = $this->model->insert_friends_request($insert)) { |
|
132 | - |
|
133 | - $notification_data = array( |
|
134 | - 'request_id' => $request_id, |
|
135 | - 'sender_id' => $sender_id, |
|
136 | - 'sender_username' => $this->user->data ['username'], |
|
137 | - 'user_id' => $user_id |
|
138 | - ); |
|
139 | - |
|
140 | - $this->notification_manager->add_notifications(array( |
|
141 | - 'florinp.messenger.notification.type.friend_request' |
|
142 | - ), $notification_data); |
|
143 | - |
|
144 | - return true; |
|
145 | - } |
|
146 | - |
|
147 | - return false; |
|
148 | - } |
|
149 | - |
|
150 | - public function remove_friend($user_id) |
|
151 | - { |
|
152 | - |
|
153 | - if (is_array($user_id)) { |
|
154 | - foreach ($user_id as $id) { |
|
155 | - $this->model->remove_friend($id); |
|
156 | - } |
|
157 | - return true; |
|
158 | - } else { |
|
159 | - if ($user_id > 1) { |
|
160 | - $this->model->remove_friend($user_id); |
|
161 | - return true; |
|
162 | - } |
|
163 | - } |
|
164 | - return false; |
|
165 | - } |
|
166 | - |
|
167 | - public function set_page_url($u_action) |
|
168 | - { |
|
169 | - $this->u_action = $u_action; |
|
170 | - } |
|
15 | + protected $template; |
|
16 | + protected $user; |
|
17 | + protected $user_loader; |
|
18 | + protected $model; |
|
19 | + protected $request; |
|
20 | + protected $notification_manager; |
|
21 | + protected $u_action; |
|
22 | + |
|
23 | + public function __construct( |
|
24 | + template $template, |
|
25 | + request $request, |
|
26 | + user $user, |
|
27 | + user_loader $user_loader, |
|
28 | + friends_model $model, |
|
29 | + manager $notification_manager |
|
30 | + ) |
|
31 | + { |
|
32 | + $this->template = $template; |
|
33 | + $this->request = $request; |
|
34 | + $this->user = $user; |
|
35 | + $this->user_loader = $user_loader; |
|
36 | + $this->model = $model; |
|
37 | + $this->notification_manager = $notification_manager; |
|
38 | + } |
|
39 | + |
|
40 | + public function friends_list() |
|
41 | + { |
|
42 | + $friends = $this->model->getFriends(); |
|
43 | + $i = 0; |
|
44 | + foreach ($friends as $friend) { |
|
45 | + $i = $i + 1; |
|
46 | + $this->user_loader->load_users(array( |
|
47 | + $friend['user_id'] |
|
48 | + )); |
|
49 | + $this->template->assign_block_vars('friends', array( |
|
50 | + 'user_id' => $friend['user_id'], |
|
51 | + 'username' => $this->user_loader->get_username($friend['user_id'], 'full'), |
|
52 | + 'user_colour' => $friend['user_colour'], |
|
53 | + 'user_status' => ($friend['user_status'] == 1) ? 'online' : 'offline', |
|
54 | + 'row_count' => $i |
|
55 | + )); |
|
56 | + } |
|
57 | + |
|
58 | + $this->template->assign_vars(array( |
|
59 | + 'U_ACTION' => $this->u_action, |
|
60 | + )); |
|
61 | + } |
|
62 | + |
|
63 | + public function requests() |
|
64 | + { |
|
65 | + $requests = $this->model->get_friends_requests(); |
|
66 | + $i = 0; |
|
67 | + foreach ($requests as $request) { |
|
68 | + $i = $i + 1; |
|
69 | + $this->user_loader->load_users(array( |
|
70 | + $request['user_id'], |
|
71 | + $request['sender_id'] |
|
72 | + )); |
|
73 | + $this->template->assign_block_vars('requests', array( |
|
74 | + 'request_id' => $request['request_id'], |
|
75 | + 'sender_username' => $this->user_loader->get_username($request['sender_id'], 'full'), |
|
76 | + 'status' => ($request['status'] == 1) ? ($this->user->lang['APPROVED']) : ($this->user->lang['WAITING_FOR_APPROVAL']), |
|
77 | + 'time' => date('d M Y H:i:s', $request['time']), |
|
78 | + 'row_count' => $i |
|
79 | + )); |
|
80 | + } |
|
81 | + |
|
82 | + $this->template->assign_vars(array( |
|
83 | + 'U_ACTION' => $this->u_action, |
|
84 | + )); |
|
85 | + } |
|
86 | + |
|
87 | + public function delete_request($requests_id) |
|
88 | + { |
|
89 | + if (is_array($requests_id)) { |
|
90 | + foreach ($requests_id as $id) { |
|
91 | + $this->model->delete_friend_request($id); |
|
92 | + } |
|
93 | + } else { |
|
94 | + $this->model->delete_friend_request($requests_id); |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + public function approve_request($requests_id) |
|
99 | + { |
|
100 | + if (is_array($requests_id)) { |
|
101 | + foreach ($requests_id as $id) { |
|
102 | + $request_data = $this->model->get_friend_request($id); |
|
103 | + if ($request_data) { |
|
104 | + $this->model->add_friend(array( |
|
105 | + 'user_id' => $request_data['user_id'], |
|
106 | + 'friend_id' => $request_data['sender_id'] |
|
107 | + )); |
|
108 | + } |
|
109 | + |
|
110 | + } |
|
111 | + } else { |
|
112 | + $this->model->approve_friend_request($requests_id); |
|
113 | + $request_data = $this->model->get_friend_request($requests_id); |
|
114 | + $this->model->add_friend(array( |
|
115 | + 'user_id' => $request_data['user_id'], |
|
116 | + 'friend_id' => $request_data['sender_id'] |
|
117 | + )); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + public function send_request($user_id) |
|
122 | + { |
|
123 | + $user_id = (int)$user_id; |
|
124 | + $sender_id = $this->user->data['user_id']; |
|
125 | + |
|
126 | + $insert = array( |
|
127 | + 'user_id' => $user_id, |
|
128 | + 'sender_id' => $sender_id |
|
129 | + ); |
|
130 | + |
|
131 | + if ($request_id = $this->model->insert_friends_request($insert)) { |
|
132 | + |
|
133 | + $notification_data = array( |
|
134 | + 'request_id' => $request_id, |
|
135 | + 'sender_id' => $sender_id, |
|
136 | + 'sender_username' => $this->user->data ['username'], |
|
137 | + 'user_id' => $user_id |
|
138 | + ); |
|
139 | + |
|
140 | + $this->notification_manager->add_notifications(array( |
|
141 | + 'florinp.messenger.notification.type.friend_request' |
|
142 | + ), $notification_data); |
|
143 | + |
|
144 | + return true; |
|
145 | + } |
|
146 | + |
|
147 | + return false; |
|
148 | + } |
|
149 | + |
|
150 | + public function remove_friend($user_id) |
|
151 | + { |
|
152 | + |
|
153 | + if (is_array($user_id)) { |
|
154 | + foreach ($user_id as $id) { |
|
155 | + $this->model->remove_friend($id); |
|
156 | + } |
|
157 | + return true; |
|
158 | + } else { |
|
159 | + if ($user_id > 1) { |
|
160 | + $this->model->remove_friend($user_id); |
|
161 | + return true; |
|
162 | + } |
|
163 | + } |
|
164 | + return false; |
|
165 | + } |
|
166 | + |
|
167 | + public function set_page_url($u_action) |
|
168 | + { |
|
169 | + $this->u_action = $u_action; |
|
170 | + } |
|
171 | 171 | } |
@@ -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 | } |
@@ -11,61 +11,61 @@ discard block |
||
11 | 11 | class main_model |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @var config |
|
16 | - */ |
|
17 | - protected $config; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var driver_interface |
|
21 | - */ |
|
22 | - protected $phpbb_db; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var user |
|
26 | - */ |
|
27 | - protected $user; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var database |
|
31 | - */ |
|
32 | - protected $db; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected $friends_request_table; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $user_friends_table; |
|
43 | - |
|
44 | - |
|
45 | - public function __construct( |
|
46 | - config $config, |
|
47 | - driver_interface $phpbb_db, |
|
48 | - user $user, |
|
49 | - database $db, |
|
50 | - $friends_request_table, |
|
51 | - $user_friends_table |
|
52 | - ) |
|
53 | - { |
|
54 | - $this->config = $config; |
|
55 | - $this->phpbb_db = $phpbb_db; |
|
56 | - $this->user = $user; |
|
57 | - $this->db = $db; |
|
58 | - $this->friends_request_table = $friends_request_table; |
|
59 | - $this->user_friends_table = $user_friends_table; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * get all friends |
|
64 | - * @return array the list of friends |
|
65 | - */ |
|
66 | - public function getFriends() |
|
67 | - { |
|
68 | - $sql = " |
|
14 | + /** |
|
15 | + * @var config |
|
16 | + */ |
|
17 | + protected $config; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var driver_interface |
|
21 | + */ |
|
22 | + protected $phpbb_db; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var user |
|
26 | + */ |
|
27 | + protected $user; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var database |
|
31 | + */ |
|
32 | + protected $db; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected $friends_request_table; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $user_friends_table; |
|
43 | + |
|
44 | + |
|
45 | + public function __construct( |
|
46 | + config $config, |
|
47 | + driver_interface $phpbb_db, |
|
48 | + user $user, |
|
49 | + database $db, |
|
50 | + $friends_request_table, |
|
51 | + $user_friends_table |
|
52 | + ) |
|
53 | + { |
|
54 | + $this->config = $config; |
|
55 | + $this->phpbb_db = $phpbb_db; |
|
56 | + $this->user = $user; |
|
57 | + $this->db = $db; |
|
58 | + $this->friends_request_table = $friends_request_table; |
|
59 | + $this->user_friends_table = $user_friends_table; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * get all friends |
|
64 | + * @return array the list of friends |
|
65 | + */ |
|
66 | + public function getFriends() |
|
67 | + { |
|
68 | + $sql = " |
|
69 | 69 | SELECT u.user_id, |
70 | 70 | u.username, |
71 | 71 | u.username_clean, |
@@ -79,31 +79,31 @@ discard block |
||
79 | 79 | WHERE " . $this->user_friends_table . ".user_id = " . (int)$this->user->data['user_id'] . " |
80 | 80 | GROUP BY u.user_id |
81 | 81 | "; |
82 | - $result = $this->phpbb_db->sql_query($sql); |
|
83 | - |
|
84 | - $friends = array(); |
|
85 | - while ($row = $this->phpbb_db->sql_fetchrow($result)) { |
|
86 | - $friends[] = array( |
|
87 | - 'user_id' => $row['user_id'], |
|
88 | - 'username' => $row['username_clean'], |
|
89 | - 'user_colour' => $row['user_colour'], |
|
90 | - 'user_status' => ($row['session_time'] >= (time() - ($this->config['load_online_time'] * 60))) ? 1 : 0, |
|
91 | - 'inbox' => $this->getInboxFromId($row['user_id']) |
|
92 | - ); |
|
93 | - } |
|
94 | - $this->phpbb_db->sql_freeresult(); |
|
95 | - |
|
96 | - return $friends; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * checks if a user is friend with other user and vice-versa |
|
101 | - * @param int $friend_id |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function checkFriend($friend_id) |
|
105 | - { |
|
106 | - $sql = " |
|
82 | + $result = $this->phpbb_db->sql_query($sql); |
|
83 | + |
|
84 | + $friends = array(); |
|
85 | + while ($row = $this->phpbb_db->sql_fetchrow($result)) { |
|
86 | + $friends[] = array( |
|
87 | + 'user_id' => $row['user_id'], |
|
88 | + 'username' => $row['username_clean'], |
|
89 | + 'user_colour' => $row['user_colour'], |
|
90 | + 'user_status' => ($row['session_time'] >= (time() - ($this->config['load_online_time'] * 60))) ? 1 : 0, |
|
91 | + 'inbox' => $this->getInboxFromId($row['user_id']) |
|
92 | + ); |
|
93 | + } |
|
94 | + $this->phpbb_db->sql_freeresult(); |
|
95 | + |
|
96 | + return $friends; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * checks if a user is friend with other user and vice-versa |
|
101 | + * @param int $friend_id |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function checkFriend($friend_id) |
|
105 | + { |
|
106 | + $sql = " |
|
107 | 107 | SELECT COUNT(zebra_id) as friend_count |
108 | 108 | FROM " . ZEBRA_TABLE . " |
109 | 109 | WHERE user_id = " . (int)$friend_id . " |
@@ -111,233 +111,233 @@ discard block |
||
111 | 111 | AND friend = 1 |
112 | 112 | AND foe = 0 |
113 | 113 | "; |
114 | - $result = $this->phpbb_db->sql_query($sql); |
|
115 | - $friend_count = (int)$this->phpbb_db->sql_fetchfield('friend_count'); |
|
116 | - $this->phpbb_db->sql_freeresult($result); |
|
117 | - |
|
118 | - if ($friend_count > 0) { |
|
119 | - return true; |
|
120 | - } else { |
|
121 | - return false; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Get number of unread messages from an user |
|
127 | - * @param $friend_id |
|
128 | - * @return int |
|
129 | - */ |
|
130 | - public function getInboxFromId($friend_id) |
|
131 | - { |
|
132 | - $sql = "SELECT * |
|
114 | + $result = $this->phpbb_db->sql_query($sql); |
|
115 | + $friend_count = (int)$this->phpbb_db->sql_fetchfield('friend_count'); |
|
116 | + $this->phpbb_db->sql_freeresult($result); |
|
117 | + |
|
118 | + if ($friend_count > 0) { |
|
119 | + return true; |
|
120 | + } else { |
|
121 | + return false; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Get number of unread messages from an user |
|
127 | + * @param $friend_id |
|
128 | + * @return int |
|
129 | + */ |
|
130 | + public function getInboxFromId($friend_id) |
|
131 | + { |
|
132 | + $sql = "SELECT * |
|
133 | 133 | FROM `messages` |
134 | 134 | WHERE `sender_id` = :sender_id |
135 | 135 | AND `receiver_id` = :receiver_id |
136 | 136 | AND `newMsg` = 1 |
137 | 137 | "; |
138 | - $results = $this->db->select($sql, array( |
|
139 | - ':sender_id' => (int)$friend_id, |
|
140 | - ':receiver_id' => (int)$this->user->data['user_id'] |
|
141 | - )); |
|
142 | - |
|
143 | - return count($results); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Insert a message in database |
|
148 | - * @param array $data Message data |
|
149 | - * @return bool|string |
|
150 | - */ |
|
151 | - public function sendMessage($data) |
|
152 | - { |
|
153 | - $insert = array( |
|
154 | - 'sender_id' => $data['sender_id'], |
|
155 | - 'receiver_id' => $data['receiver_id'], |
|
156 | - 'text' => $data['text'], |
|
157 | - 'newMsg' => 1, |
|
158 | - 'sentAt' => time() |
|
159 | - ); |
|
160 | - |
|
161 | - if ($this->db->insert('messages', $insert)) |
|
162 | - return $this->db->lastInsertId(); |
|
163 | - else |
|
164 | - return false; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Insert a file in database |
|
169 | - * @param $data File data |
|
170 | - * @return bool|string |
|
171 | - */ |
|
172 | - public function sendFile($data) |
|
173 | - { |
|
174 | - $insert = array( |
|
175 | - 'sender_id' => $data['sender_id'], |
|
176 | - 'receiver_id' => $data['receiver_id'], |
|
177 | - 'fileName' => $data['fileName'], |
|
178 | - 'file' => $data['file'], |
|
179 | - 'type' => $data['type'], |
|
180 | - 'sentAt' => time() |
|
181 | - ); |
|
182 | - |
|
183 | - if ($this->db->insert('files', $insert)) |
|
184 | - return $this->db->lastInsertId(); |
|
185 | - else |
|
186 | - return false; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Returns a message by a id |
|
191 | - * @param $id Message id |
|
192 | - * @return mixed |
|
193 | - */ |
|
194 | - public function getMessageById($id) |
|
195 | - { |
|
196 | - $sql = " |
|
138 | + $results = $this->db->select($sql, array( |
|
139 | + ':sender_id' => (int)$friend_id, |
|
140 | + ':receiver_id' => (int)$this->user->data['user_id'] |
|
141 | + )); |
|
142 | + |
|
143 | + return count($results); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Insert a message in database |
|
148 | + * @param array $data Message data |
|
149 | + * @return bool|string |
|
150 | + */ |
|
151 | + public function sendMessage($data) |
|
152 | + { |
|
153 | + $insert = array( |
|
154 | + 'sender_id' => $data['sender_id'], |
|
155 | + 'receiver_id' => $data['receiver_id'], |
|
156 | + 'text' => $data['text'], |
|
157 | + 'newMsg' => 1, |
|
158 | + 'sentAt' => time() |
|
159 | + ); |
|
160 | + |
|
161 | + if ($this->db->insert('messages', $insert)) |
|
162 | + return $this->db->lastInsertId(); |
|
163 | + else |
|
164 | + return false; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Insert a file in database |
|
169 | + * @param $data File data |
|
170 | + * @return bool|string |
|
171 | + */ |
|
172 | + public function sendFile($data) |
|
173 | + { |
|
174 | + $insert = array( |
|
175 | + 'sender_id' => $data['sender_id'], |
|
176 | + 'receiver_id' => $data['receiver_id'], |
|
177 | + 'fileName' => $data['fileName'], |
|
178 | + 'file' => $data['file'], |
|
179 | + 'type' => $data['type'], |
|
180 | + 'sentAt' => time() |
|
181 | + ); |
|
182 | + |
|
183 | + if ($this->db->insert('files', $insert)) |
|
184 | + return $this->db->lastInsertId(); |
|
185 | + else |
|
186 | + return false; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Returns a message by a id |
|
191 | + * @param $id Message id |
|
192 | + * @return mixed |
|
193 | + */ |
|
194 | + public function getMessageById($id) |
|
195 | + { |
|
196 | + $sql = " |
|
197 | 197 | SELECT * |
198 | 198 | FROM `messages` |
199 | 199 | WHERE `id` = :id |
200 | 200 | LIMIT 1 |
201 | 201 | "; |
202 | - $message = $this->db->select($sql, array( |
|
203 | - ':id' => $id |
|
204 | - )); |
|
205 | - |
|
206 | - return $message[0]; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Returns a file by id |
|
211 | - * @param $id File id |
|
212 | - * @return mixed |
|
213 | - */ |
|
214 | - public function getFileById($id) |
|
215 | - { |
|
216 | - $sql = " |
|
202 | + $message = $this->db->select($sql, array( |
|
203 | + ':id' => $id |
|
204 | + )); |
|
205 | + |
|
206 | + return $message[0]; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Returns a file by id |
|
211 | + * @param $id File id |
|
212 | + * @return mixed |
|
213 | + */ |
|
214 | + public function getFileById($id) |
|
215 | + { |
|
216 | + $sql = " |
|
217 | 217 | SELECT * |
218 | 218 | FROM `files` |
219 | 219 | WHERE `id` = :id |
220 | 220 | LIMIT 1 |
221 | 221 | "; |
222 | - $file = $this->db->select($sql, array( |
|
223 | - ':id' => $id |
|
224 | - )); |
|
225 | - |
|
226 | - return $file[0]; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Get all message from an user |
|
231 | - * @param int $friend_id |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - public function getMessages($friend_id) |
|
235 | - { |
|
236 | - // get the sent messages |
|
237 | - $sql = "SELECT * |
|
222 | + $file = $this->db->select($sql, array( |
|
223 | + ':id' => $id |
|
224 | + )); |
|
225 | + |
|
226 | + return $file[0]; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Get all message from an user |
|
231 | + * @param int $friend_id |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + public function getMessages($friend_id) |
|
235 | + { |
|
236 | + // get the sent messages |
|
237 | + $sql = "SELECT * |
|
238 | 238 | FROM `messages` |
239 | 239 | WHERE `sender_id` = :sender_id |
240 | 240 | AND `receiver_id` = :receiver_id |
241 | 241 | ORDER BY `sentAt` ASC |
242 | 242 | "; |
243 | - $sqlFiles = "SELECT * |
|
243 | + $sqlFiles = "SELECT * |
|
244 | 244 | FROM `files` |
245 | 245 | WHERE `sender_id` = :sender_id |
246 | 246 | AND `receiver_id` = :receiver_id |
247 | 247 | ORDER BY `sentAt` ASC |
248 | 248 | "; |
249 | - $sentMessages = $this->db->select($sql, array( |
|
250 | - ':sender_id' => $this->user->data['user_id'], |
|
251 | - ':receiver_id' => $friend_id |
|
252 | - )); |
|
253 | - $getInbox = $this->db->select($sql, array( |
|
254 | - ':sender_id' => $friend_id, |
|
255 | - ':receiver_id' => $this->user->data['user_id'] |
|
256 | - )); |
|
257 | - |
|
258 | - $sentFiles = $this->db->select($sqlFiles, array( |
|
259 | - ':sender_id' => $this->user->data['user_id'], |
|
260 | - ':receiver_id' => $friend_id |
|
261 | - )); |
|
262 | - $getFiles = $this->db->select($sqlFiles, array( |
|
263 | - ':sender_id' => $friend_id, |
|
264 | - ':receiver_id' => $this->user->data['user_id'] |
|
265 | - )); |
|
266 | - |
|
267 | - $sent = array(); |
|
268 | - foreach ($sentMessages as $msg) { |
|
269 | - $item = array(); |
|
270 | - $item['id'] = $msg['id']; |
|
271 | - $item['sender_id'] = $msg['sender_id']; |
|
272 | - $item['receiver_id'] = $msg['receiver_id']; |
|
273 | - $item['text'] = $msg['text']; |
|
274 | - $item['sentAt'] = $msg['sentAt']; |
|
275 | - $item['type'] = 'sent'; |
|
276 | - |
|
277 | - $sent[] = $item; |
|
278 | - } |
|
279 | - $inbox = array(); |
|
280 | - foreach ($getInbox as $msg) { |
|
281 | - $item = array(); |
|
282 | - $item['id'] = $msg['id']; |
|
283 | - $item['sender_id'] = $msg['sender_id']; |
|
284 | - $item['receiver_id'] = $msg['receiver_id']; |
|
285 | - $item['text'] = $msg['text']; |
|
286 | - $item['sentAt'] = $msg['sentAt']; |
|
287 | - $item['type'] = 'inbox'; |
|
288 | - |
|
289 | - $inbox[] = $item; |
|
290 | - } |
|
291 | - |
|
292 | - foreach ($sentFiles as $file) { |
|
293 | - $item = array(); |
|
294 | - $item['id'] = 'f_' . $file['id']; |
|
295 | - $item['sender_id'] = $file['sender_id']; |
|
296 | - $item['receiver_id'] = $file['receiver_id']; |
|
297 | - $item['fileName'] = $file['fileName']; |
|
298 | - $item['file'] = $file['file']; |
|
299 | - $item['sentAt'] = $file['sentAt']; |
|
300 | - $item['type'] = 'sent'; |
|
301 | - |
|
302 | - $sent[] = $item; |
|
303 | - } |
|
304 | - |
|
305 | - foreach ($getFiles as $file) { |
|
306 | - $item = array(); |
|
307 | - $item['id'] = 'f_' . $file['id']; |
|
308 | - $item['sender_id'] = $file['sender_id']; |
|
309 | - $item['receiver_id'] = $file['receiver_id']; |
|
310 | - $item['fileName'] = $file['fileName']; |
|
311 | - $item['file'] = $file['file']; |
|
312 | - $item['sentAt'] = $file['sentAt']; |
|
313 | - $item['type'] = 'inbox'; |
|
314 | - |
|
315 | - $inbox[] = $item; |
|
316 | - } |
|
317 | - |
|
318 | - $unsorted_messages = array_merge($sent, $inbox); |
|
319 | - |
|
320 | - uasort($unsorted_messages, function ($a, $b) { |
|
321 | - return ($a['sentAt'] > $b['sentAt']) ? -1 : 1; |
|
322 | - }); |
|
323 | - |
|
324 | - $sorted_messages = array(); |
|
325 | - foreach ($unsorted_messages as $msg) { |
|
326 | - $sorted_messages[] = $msg; |
|
327 | - } |
|
328 | - |
|
329 | - return $sorted_messages; |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Change messages status to read |
|
334 | - * @param $friend_id |
|
335 | - * @return int |
|
336 | - */ |
|
337 | - public function updateMessagesStatus($friend_id) |
|
338 | - { |
|
339 | - |
|
340 | - $sql = " |
|
249 | + $sentMessages = $this->db->select($sql, array( |
|
250 | + ':sender_id' => $this->user->data['user_id'], |
|
251 | + ':receiver_id' => $friend_id |
|
252 | + )); |
|
253 | + $getInbox = $this->db->select($sql, array( |
|
254 | + ':sender_id' => $friend_id, |
|
255 | + ':receiver_id' => $this->user->data['user_id'] |
|
256 | + )); |
|
257 | + |
|
258 | + $sentFiles = $this->db->select($sqlFiles, array( |
|
259 | + ':sender_id' => $this->user->data['user_id'], |
|
260 | + ':receiver_id' => $friend_id |
|
261 | + )); |
|
262 | + $getFiles = $this->db->select($sqlFiles, array( |
|
263 | + ':sender_id' => $friend_id, |
|
264 | + ':receiver_id' => $this->user->data['user_id'] |
|
265 | + )); |
|
266 | + |
|
267 | + $sent = array(); |
|
268 | + foreach ($sentMessages as $msg) { |
|
269 | + $item = array(); |
|
270 | + $item['id'] = $msg['id']; |
|
271 | + $item['sender_id'] = $msg['sender_id']; |
|
272 | + $item['receiver_id'] = $msg['receiver_id']; |
|
273 | + $item['text'] = $msg['text']; |
|
274 | + $item['sentAt'] = $msg['sentAt']; |
|
275 | + $item['type'] = 'sent'; |
|
276 | + |
|
277 | + $sent[] = $item; |
|
278 | + } |
|
279 | + $inbox = array(); |
|
280 | + foreach ($getInbox as $msg) { |
|
281 | + $item = array(); |
|
282 | + $item['id'] = $msg['id']; |
|
283 | + $item['sender_id'] = $msg['sender_id']; |
|
284 | + $item['receiver_id'] = $msg['receiver_id']; |
|
285 | + $item['text'] = $msg['text']; |
|
286 | + $item['sentAt'] = $msg['sentAt']; |
|
287 | + $item['type'] = 'inbox'; |
|
288 | + |
|
289 | + $inbox[] = $item; |
|
290 | + } |
|
291 | + |
|
292 | + foreach ($sentFiles as $file) { |
|
293 | + $item = array(); |
|
294 | + $item['id'] = 'f_' . $file['id']; |
|
295 | + $item['sender_id'] = $file['sender_id']; |
|
296 | + $item['receiver_id'] = $file['receiver_id']; |
|
297 | + $item['fileName'] = $file['fileName']; |
|
298 | + $item['file'] = $file['file']; |
|
299 | + $item['sentAt'] = $file['sentAt']; |
|
300 | + $item['type'] = 'sent'; |
|
301 | + |
|
302 | + $sent[] = $item; |
|
303 | + } |
|
304 | + |
|
305 | + foreach ($getFiles as $file) { |
|
306 | + $item = array(); |
|
307 | + $item['id'] = 'f_' . $file['id']; |
|
308 | + $item['sender_id'] = $file['sender_id']; |
|
309 | + $item['receiver_id'] = $file['receiver_id']; |
|
310 | + $item['fileName'] = $file['fileName']; |
|
311 | + $item['file'] = $file['file']; |
|
312 | + $item['sentAt'] = $file['sentAt']; |
|
313 | + $item['type'] = 'inbox'; |
|
314 | + |
|
315 | + $inbox[] = $item; |
|
316 | + } |
|
317 | + |
|
318 | + $unsorted_messages = array_merge($sent, $inbox); |
|
319 | + |
|
320 | + uasort($unsorted_messages, function ($a, $b) { |
|
321 | + return ($a['sentAt'] > $b['sentAt']) ? -1 : 1; |
|
322 | + }); |
|
323 | + |
|
324 | + $sorted_messages = array(); |
|
325 | + foreach ($unsorted_messages as $msg) { |
|
326 | + $sorted_messages[] = $msg; |
|
327 | + } |
|
328 | + |
|
329 | + return $sorted_messages; |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Change messages status to read |
|
334 | + * @param $friend_id |
|
335 | + * @return int |
|
336 | + */ |
|
337 | + public function updateMessagesStatus($friend_id) |
|
338 | + { |
|
339 | + |
|
340 | + $sql = " |
|
341 | 341 | UPDATE `messages` |
342 | 342 | SET `newMsg` = 0 |
343 | 343 | WHERE `newMsg` = 1 |
@@ -345,12 +345,12 @@ discard block |
||
345 | 345 | AND `receiver_id` = :receiver_id |
346 | 346 | "; |
347 | 347 | |
348 | - $sth = $this->db->prepare($sql); |
|
349 | - $sth->bindValue(':sender_id', $friend_id); |
|
350 | - $sth->bindValue(':receiver_id', $this->user->data['user_id']); |
|
351 | - $sth->execute(); |
|
348 | + $sth = $this->db->prepare($sql); |
|
349 | + $sth->bindValue(':sender_id', $friend_id); |
|
350 | + $sth->bindValue(':receiver_id', $this->user->data['user_id']); |
|
351 | + $sth->execute(); |
|
352 | 352 | |
353 | - return $this->getInboxFromId($friend_id); |
|
354 | - } |
|
353 | + return $this->getInboxFromId($friend_id); |
|
354 | + } |
|
355 | 355 | |
356 | 356 | } |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | u.user_colour, |
74 | 74 | s.session_id, |
75 | 75 | s.session_time |
76 | - FROM " . $this->user_friends_table . " |
|
77 | - LEFT JOIN " . USERS_TABLE . " AS u ON u.user_id = " . $this->user_friends_table . ".friend_id |
|
78 | - LEFT JOIN " . SESSIONS_TABLE . " AS s ON s.session_user_id = u.user_id |
|
79 | - WHERE " . $this->user_friends_table . ".user_id = " . (int)$this->user->data['user_id'] . " |
|
76 | + FROM " . $this->user_friends_table." |
|
77 | + LEFT JOIN " . USERS_TABLE." AS u ON u.user_id = ".$this->user_friends_table.".friend_id |
|
78 | + LEFT JOIN " . SESSIONS_TABLE." AS s ON s.session_user_id = u.user_id |
|
79 | + WHERE " . $this->user_friends_table.".user_id = ".(int)$this->user->data['user_id']." |
|
80 | 80 | GROUP BY u.user_id |
81 | 81 | "; |
82 | 82 | $result = $this->phpbb_db->sql_query($sql); |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | { |
106 | 106 | $sql = " |
107 | 107 | SELECT COUNT(zebra_id) as friend_count |
108 | - FROM " . ZEBRA_TABLE . " |
|
109 | - WHERE user_id = " . (int)$friend_id . " |
|
110 | - AND zebra_id = " . (int)$this->user->data['user_id'] . " |
|
108 | + FROM " . ZEBRA_TABLE." |
|
109 | + WHERE user_id = " . (int)$friend_id." |
|
110 | + AND zebra_id = " . (int)$this->user->data['user_id']." |
|
111 | 111 | AND friend = 1 |
112 | 112 | AND foe = 0 |
113 | 113 | "; |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | |
292 | 292 | foreach ($sentFiles as $file) { |
293 | 293 | $item = array(); |
294 | - $item['id'] = 'f_' . $file['id']; |
|
294 | + $item['id'] = 'f_'.$file['id']; |
|
295 | 295 | $item['sender_id'] = $file['sender_id']; |
296 | 296 | $item['receiver_id'] = $file['receiver_id']; |
297 | 297 | $item['fileName'] = $file['fileName']; |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | |
305 | 305 | foreach ($getFiles as $file) { |
306 | 306 | $item = array(); |
307 | - $item['id'] = 'f_' . $file['id']; |
|
307 | + $item['id'] = 'f_'.$file['id']; |
|
308 | 308 | $item['sender_id'] = $file['sender_id']; |
309 | 309 | $item['receiver_id'] = $file['receiver_id']; |
310 | 310 | $item['fileName'] = $file['fileName']; |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | |
318 | 318 | $unsorted_messages = array_merge($sent, $inbox); |
319 | 319 | |
320 | - uasort($unsorted_messages, function ($a, $b) { |
|
320 | + uasort($unsorted_messages, function($a, $b) { |
|
321 | 321 | return ($a['sentAt'] > $b['sentAt']) ? -1 : 1; |
322 | 322 | }); |
323 | 323 |
@@ -158,10 +158,11 @@ discard block |
||
158 | 158 | 'sentAt' => time() |
159 | 159 | ); |
160 | 160 | |
161 | - if ($this->db->insert('messages', $insert)) |
|
162 | - return $this->db->lastInsertId(); |
|
163 | - else |
|
164 | - return false; |
|
161 | + if ($this->db->insert('messages', $insert)) { |
|
162 | + return $this->db->lastInsertId(); |
|
163 | + } else { |
|
164 | + return false; |
|
165 | + } |
|
165 | 166 | } |
166 | 167 | |
167 | 168 | /** |
@@ -180,10 +181,11 @@ discard block |
||
180 | 181 | 'sentAt' => time() |
181 | 182 | ); |
182 | 183 | |
183 | - if ($this->db->insert('files', $insert)) |
|
184 | - return $this->db->lastInsertId(); |
|
185 | - else |
|
186 | - return false; |
|
184 | + if ($this->db->insert('files', $insert)) { |
|
185 | + return $this->db->lastInsertId(); |
|
186 | + } else { |
|
187 | + return false; |
|
188 | + } |
|
187 | 189 | } |
188 | 190 | |
189 | 191 | /** |
@@ -8,30 +8,30 @@ discard block |
||
8 | 8 | |
9 | 9 | class friends_model |
10 | 10 | { |
11 | - protected $config; |
|
12 | - protected $db; |
|
13 | - protected $user; |
|
14 | - protected $friends_request_table; |
|
15 | - protected $user_friends_table; |
|
16 | - |
|
17 | - public function __construct( |
|
18 | - config $config, |
|
19 | - driver_interface $db, |
|
20 | - user $user, |
|
21 | - $friends_request_table, |
|
22 | - $user_friends_table |
|
23 | - ) |
|
24 | - { |
|
25 | - $this->config = $config; |
|
26 | - $this->db = $db; |
|
27 | - $this->user = $user; |
|
28 | - $this->friends_request_table = $friends_request_table; |
|
29 | - $this->user_friends_table = $user_friends_table; |
|
30 | - } |
|
31 | - |
|
32 | - public function getFriends() |
|
33 | - { |
|
34 | - $sql = " |
|
11 | + protected $config; |
|
12 | + protected $db; |
|
13 | + protected $user; |
|
14 | + protected $friends_request_table; |
|
15 | + protected $user_friends_table; |
|
16 | + |
|
17 | + public function __construct( |
|
18 | + config $config, |
|
19 | + driver_interface $db, |
|
20 | + user $user, |
|
21 | + $friends_request_table, |
|
22 | + $user_friends_table |
|
23 | + ) |
|
24 | + { |
|
25 | + $this->config = $config; |
|
26 | + $this->db = $db; |
|
27 | + $this->user = $user; |
|
28 | + $this->friends_request_table = $friends_request_table; |
|
29 | + $this->user_friends_table = $user_friends_table; |
|
30 | + } |
|
31 | + |
|
32 | + public function getFriends() |
|
33 | + { |
|
34 | + $sql = " |
|
35 | 35 | SELECT u.user_id, |
36 | 36 | u.username, |
37 | 37 | u.username_clean, |
@@ -45,28 +45,28 @@ discard block |
||
45 | 45 | WHERE " . $this->user_friends_table . ".user_id = " . (int)$this->user->data['user_id'] . " |
46 | 46 | GROUP BY u.user_id |
47 | 47 | "; |
48 | - $result = $this->db->sql_query($sql); |
|
48 | + $result = $this->db->sql_query($sql); |
|
49 | 49 | |
50 | - $friends = array(); |
|
51 | - while ($row = $this->db->sql_fetchrow($result)) { |
|
52 | - $friends[] = array( |
|
53 | - 'user_id' => $row['user_id'], |
|
54 | - 'username' => $row['username_clean'], |
|
55 | - 'user_colour' => $row['user_colour'], |
|
56 | - 'user_status' => ($row['session_time'] >= (time() - ($this->config['load_online_time'] * 60))) ? 1 : 0, |
|
57 | - ); |
|
58 | - } |
|
59 | - $this->db->sql_freeresult(); |
|
50 | + $friends = array(); |
|
51 | + while ($row = $this->db->sql_fetchrow($result)) { |
|
52 | + $friends[] = array( |
|
53 | + 'user_id' => $row['user_id'], |
|
54 | + 'username' => $row['username_clean'], |
|
55 | + 'user_colour' => $row['user_colour'], |
|
56 | + 'user_status' => ($row['session_time'] >= (time() - ($this->config['load_online_time'] * 60))) ? 1 : 0, |
|
57 | + ); |
|
58 | + } |
|
59 | + $this->db->sql_freeresult(); |
|
60 | 60 | |
61 | - return $friends; |
|
62 | - } |
|
61 | + return $friends; |
|
62 | + } |
|
63 | 63 | |
64 | - public function get_friends_requests() |
|
65 | - { |
|
64 | + public function get_friends_requests() |
|
65 | + { |
|
66 | 66 | |
67 | - $requests = array(); |
|
67 | + $requests = array(); |
|
68 | 68 | |
69 | - $sql = " |
|
69 | + $sql = " |
|
70 | 70 | SELECT `request_id`, |
71 | 71 | `user_id`, |
72 | 72 | `sender_id`, |
@@ -78,18 +78,18 @@ discard block |
||
78 | 78 | ORDER BY `time` DESC |
79 | 79 | "; |
80 | 80 | |
81 | - $result = $this->db->sql_query($sql); |
|
81 | + $result = $this->db->sql_query($sql); |
|
82 | 82 | |
83 | - while ($row = $this->db->sql_fetchrow($result)) { |
|
84 | - $requests[] = $row; |
|
85 | - } |
|
83 | + while ($row = $this->db->sql_fetchrow($result)) { |
|
84 | + $requests[] = $row; |
|
85 | + } |
|
86 | 86 | |
87 | - return $requests; |
|
88 | - } |
|
87 | + return $requests; |
|
88 | + } |
|
89 | 89 | |
90 | - public function get_friend_request($id) |
|
91 | - { |
|
92 | - $sql = " |
|
90 | + public function get_friend_request($id) |
|
91 | + { |
|
92 | + $sql = " |
|
93 | 93 | SELECT `request_id`, |
94 | 94 | `user_id`, |
95 | 95 | `sender_id`, |
@@ -101,19 +101,19 @@ discard block |
||
101 | 101 | ORDER BY `time` DESC |
102 | 102 | LIMIT 1 |
103 | 103 | "; |
104 | - $result = $this->db->sql_query($sql); |
|
105 | - $row = $this->db->sql_fetchrow($result); |
|
106 | - |
|
107 | - if ($this->approve_friend_request($id)) { |
|
108 | - return $row; |
|
109 | - } else { |
|
110 | - return false; |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - public function get_request_by_sender_id($sender_id) |
|
115 | - { |
|
116 | - $sql = " |
|
104 | + $result = $this->db->sql_query($sql); |
|
105 | + $row = $this->db->sql_fetchrow($result); |
|
106 | + |
|
107 | + if ($this->approve_friend_request($id)) { |
|
108 | + return $row; |
|
109 | + } else { |
|
110 | + return false; |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + public function get_request_by_sender_id($sender_id) |
|
115 | + { |
|
116 | + $sql = " |
|
117 | 117 | SELECT `request_id`, |
118 | 118 | `user_id`, |
119 | 119 | `sender_id`, |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | ORDER BY `time` DESC |
126 | 126 | LIMIT 1 |
127 | 127 | "; |
128 | - $result = $this->db->sql_query($sql); |
|
129 | - $row = $this->db->sql_fetchrow($result); |
|
128 | + $result = $this->db->sql_query($sql); |
|
129 | + $row = $this->db->sql_fetchrow($result); |
|
130 | 130 | |
131 | - return $row; |
|
132 | - } |
|
131 | + return $row; |
|
132 | + } |
|
133 | 133 | |
134 | - public function insert_friends_request(array $data) |
|
135 | - { |
|
136 | - $sql = " |
|
134 | + public function insert_friends_request(array $data) |
|
135 | + { |
|
136 | + $sql = " |
|
137 | 137 | INSERT INTO " . $this->friends_request_table . " |
138 | 138 | ( |
139 | 139 | `user_id`, |
@@ -149,35 +149,35 @@ discard block |
||
149 | 149 | " . time() . " |
150 | 150 | ) |
151 | 151 | "; |
152 | - $this->db->sql_query($sql); |
|
152 | + $this->db->sql_query($sql); |
|
153 | 153 | |
154 | - return $this->db->sql_nextid(); |
|
155 | - } |
|
154 | + return $this->db->sql_nextid(); |
|
155 | + } |
|
156 | 156 | |
157 | - public function delete_friend_request($request_id) |
|
158 | - { |
|
159 | - $sql = " |
|
157 | + public function delete_friend_request($request_id) |
|
158 | + { |
|
159 | + $sql = " |
|
160 | 160 | DELETE FROM " . $this->friends_request_table . " WHERE `request_id` = " . (int)$request_id . " |
161 | 161 | "; |
162 | 162 | |
163 | - return $this->db->sql_query($sql); |
|
164 | - } |
|
163 | + return $this->db->sql_query($sql); |
|
164 | + } |
|
165 | 165 | |
166 | - public function approve_friend_request($request_id) |
|
167 | - { |
|
168 | - $sql = " |
|
166 | + public function approve_friend_request($request_id) |
|
167 | + { |
|
168 | + $sql = " |
|
169 | 169 | UPDATE " . $this->friends_request_table . " SET `status` = 1 WHERE `request_id` = " . (int)$request_id . " |
170 | 170 | "; |
171 | 171 | |
172 | - return $this->db->sql_query($sql); |
|
173 | - } |
|
172 | + return $this->db->sql_query($sql); |
|
173 | + } |
|
174 | 174 | |
175 | - public function add_friend($data) |
|
176 | - { |
|
175 | + public function add_friend($data) |
|
176 | + { |
|
177 | 177 | |
178 | - $check_friend = $this->check_friend($data); |
|
179 | - if ($check_friend == false) { |
|
180 | - $sql = " |
|
178 | + $check_friend = $this->check_friend($data); |
|
179 | + if ($check_friend == false) { |
|
180 | + $sql = " |
|
181 | 181 | INSERT INTO " . $this->user_friends_table . " |
182 | 182 | ( |
183 | 183 | `user_id`, |
@@ -189,41 +189,41 @@ discard block |
||
189 | 189 | " . (int)$data['friend_id'] . " |
190 | 190 | ) |
191 | 191 | "; |
192 | - if ($this->db->sql_query($sql)) { |
|
193 | - $aux = $data['user_id']; |
|
194 | - $data['user_id'] = $data['friend_id']; |
|
195 | - $data['friend_id'] = $aux; |
|
196 | - |
|
197 | - self::add_friend($data); |
|
198 | - } else { |
|
199 | - return false; |
|
200 | - } |
|
201 | - } else { |
|
202 | - return false; |
|
203 | - } |
|
204 | - |
|
205 | - } |
|
206 | - |
|
207 | - public function check_friend($data) |
|
208 | - { |
|
209 | - $sql = " |
|
192 | + if ($this->db->sql_query($sql)) { |
|
193 | + $aux = $data['user_id']; |
|
194 | + $data['user_id'] = $data['friend_id']; |
|
195 | + $data['friend_id'] = $aux; |
|
196 | + |
|
197 | + self::add_friend($data); |
|
198 | + } else { |
|
199 | + return false; |
|
200 | + } |
|
201 | + } else { |
|
202 | + return false; |
|
203 | + } |
|
204 | + |
|
205 | + } |
|
206 | + |
|
207 | + public function check_friend($data) |
|
208 | + { |
|
209 | + $sql = " |
|
210 | 210 | SELECT COUNT(*) AS `count` |
211 | 211 | FROM " . $this->user_friends_table . " |
212 | 212 | WHERE `user_id` = " . (int)$data['user_id'] . " |
213 | 213 | AND `friend_id` = " . (int)$data['friend_id'] . " |
214 | 214 | "; |
215 | - $this->db->sql_query($sql); |
|
216 | - $count = $this->db->sql_fetchfield('count'); |
|
217 | - if ($count > 0) { |
|
218 | - return true; |
|
219 | - } else { |
|
220 | - return false; |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - public function check_request($data) |
|
225 | - { |
|
226 | - $sql = " |
|
215 | + $this->db->sql_query($sql); |
|
216 | + $count = $this->db->sql_fetchfield('count'); |
|
217 | + if ($count > 0) { |
|
218 | + return true; |
|
219 | + } else { |
|
220 | + return false; |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + public function check_request($data) |
|
225 | + { |
|
226 | + $sql = " |
|
227 | 227 | SELECT COUNT(*) AS `count` |
228 | 228 | FROM " . $this->friends_request_table . " |
229 | 229 | WHERE `user_id` = " . (int)$data['user_id'] . " |
@@ -231,22 +231,22 @@ discard block |
||
231 | 231 | AND `status` = 0 |
232 | 232 | LIMIT 1 |
233 | 233 | "; |
234 | - $this->db->sql_query($sql); |
|
235 | - $count = $this->db->sql_fetchfield('count'); |
|
236 | - if ($count > 0) { |
|
237 | - return true; |
|
238 | - } else { |
|
239 | - return false; |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - public function remove_friend($user_id) |
|
244 | - { |
|
245 | - $sql = "DELETE FROM " . $this->user_friends_table . " WHERE `user_id` = " . (int)$user_id . ""; |
|
246 | - $this->db->sql_query($sql); |
|
247 | - |
|
248 | - $sql = "DELETE FROM " . $this->user_friends_table . " WHERE `friend_id` = " . (int)$user_id . ""; |
|
249 | - $this->db->sql_query($sql); |
|
250 | - } |
|
234 | + $this->db->sql_query($sql); |
|
235 | + $count = $this->db->sql_fetchfield('count'); |
|
236 | + if ($count > 0) { |
|
237 | + return true; |
|
238 | + } else { |
|
239 | + return false; |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + public function remove_friend($user_id) |
|
244 | + { |
|
245 | + $sql = "DELETE FROM " . $this->user_friends_table . " WHERE `user_id` = " . (int)$user_id . ""; |
|
246 | + $this->db->sql_query($sql); |
|
247 | + |
|
248 | + $sql = "DELETE FROM " . $this->user_friends_table . " WHERE `friend_id` = " . (int)$user_id . ""; |
|
249 | + $this->db->sql_query($sql); |
|
250 | + } |
|
251 | 251 | |
252 | 252 | } |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | u.user_colour, |
40 | 40 | s.session_id, |
41 | 41 | s.session_time |
42 | - FROM " . $this->user_friends_table . " |
|
43 | - LEFT JOIN " . USERS_TABLE . " AS u ON u.user_id = " . $this->user_friends_table . ".friend_id |
|
44 | - LEFT JOIN " . SESSIONS_TABLE . " AS s ON s.session_user_id = u.user_id |
|
45 | - WHERE " . $this->user_friends_table . ".user_id = " . (int)$this->user->data['user_id'] . " |
|
42 | + FROM " . $this->user_friends_table." |
|
43 | + LEFT JOIN " . USERS_TABLE." AS u ON u.user_id = ".$this->user_friends_table.".friend_id |
|
44 | + LEFT JOIN " . SESSIONS_TABLE." AS s ON s.session_user_id = u.user_id |
|
45 | + WHERE " . $this->user_friends_table.".user_id = ".(int)$this->user->data['user_id']." |
|
46 | 46 | GROUP BY u.user_id |
47 | 47 | "; |
48 | 48 | $result = $this->db->sql_query($sql); |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | `sender_id`, |
73 | 73 | `status`, |
74 | 74 | `time` |
75 | - FROM " . $this->friends_request_table . " |
|
76 | - WHERE `user_id` = " . (int)$this->user->data['user_id'] . " |
|
75 | + FROM " . $this->friends_request_table." |
|
76 | + WHERE `user_id` = " . (int)$this->user->data['user_id']." |
|
77 | 77 | AND `status` = 0 |
78 | 78 | ORDER BY `time` DESC |
79 | 79 | "; |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | `sender_id`, |
96 | 96 | `status`, |
97 | 97 | `time` |
98 | - FROM " . $this->friends_request_table . " |
|
99 | - WHERE `request_id` = " . (int)$id . " |
|
98 | + FROM " . $this->friends_request_table." |
|
99 | + WHERE `request_id` = " . (int)$id." |
|
100 | 100 | AND `status` = 0 |
101 | 101 | ORDER BY `time` DESC |
102 | 102 | LIMIT 1 |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | `sender_id`, |
120 | 120 | `status`, |
121 | 121 | `time` |
122 | - FROM " . $this->friends_request_table . " |
|
123 | - WHERE `sender_id` = " . (int)$sender_id . " |
|
122 | + FROM " . $this->friends_request_table." |
|
123 | + WHERE `sender_id` = " . (int)$sender_id." |
|
124 | 124 | AND `status` = 0 |
125 | 125 | ORDER BY `time` DESC |
126 | 126 | LIMIT 1 |
@@ -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`, |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | ) |
144 | 144 | VALUES |
145 | 145 | ( |
146 | - " . ( int )$data ['user_id'] . ", |
|
147 | - " . ( int )$data ['sender_id'] . ", |
|
146 | + " . (int)$data ['user_id'].", |
|
147 | + " . (int)$data ['sender_id'].", |
|
148 | 148 | 0, |
149 | - " . time() . " |
|
149 | + " . time()." |
|
150 | 150 | ) |
151 | 151 | "; |
152 | 152 | $this->db->sql_query($sql); |
@@ -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)) { |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | { |
209 | 209 | $sql = " |
210 | 210 | SELECT COUNT(*) AS `count` |
211 | - FROM " . $this->user_friends_table . " |
|
212 | - WHERE `user_id` = " . (int)$data['user_id'] . " |
|
213 | - AND `friend_id` = " . (int)$data['friend_id'] . " |
|
211 | + FROM " . $this->user_friends_table." |
|
212 | + WHERE `user_id` = " . (int)$data['user_id']." |
|
213 | + AND `friend_id` = " . (int)$data['friend_id']." |
|
214 | 214 | "; |
215 | 215 | $this->db->sql_query($sql); |
216 | 216 | $count = $this->db->sql_fetchfield('count'); |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | { |
226 | 226 | $sql = " |
227 | 227 | SELECT COUNT(*) AS `count` |
228 | - FROM " . $this->friends_request_table . " |
|
229 | - WHERE `user_id` = " . (int)$data['user_id'] . " |
|
230 | - AND `sender_id` = " . (int)$data['sender_id'] . " |
|
228 | + FROM " . $this->friends_request_table." |
|
229 | + WHERE `user_id` = " . (int)$data['user_id']." |
|
230 | + AND `sender_id` = " . (int)$data['sender_id']." |
|
231 | 231 | AND `status` = 0 |
232 | 232 | LIMIT 1 |
233 | 233 | "; |
@@ -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 |