1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | use Chamilo\CourseBundle\Entity\CForumPost; |
||
6 | use Chamilo\CourseBundle\Entity\CForumThread; |
||
7 | use ChamiloSession as Session; |
||
8 | use GuzzleHttp\Client; |
||
9 | use Zend\Feed\Reader\Entry\Rss; |
||
10 | use Zend\Feed\Reader\Reader; |
||
11 | |||
12 | /** |
||
13 | * Class SocialManager. |
||
14 | * |
||
15 | * This class provides methods for the social network management. |
||
16 | * Include/require it in your code to use its features. |
||
17 | */ |
||
18 | class SocialManager extends UserManager |
||
19 | { |
||
20 | public const DEFAULT_WALL_POSTS = 10; |
||
21 | public const DEFAULT_SCROLL_NEW_POST = 5; |
||
22 | |||
23 | /** |
||
24 | * Constructor. |
||
25 | */ |
||
26 | public function __construct() |
||
27 | { |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Allow to see contacts list. |
||
32 | * |
||
33 | * @author isaac flores paz |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | public static function show_list_type_friends() |
||
38 | { |
||
39 | $table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); |
||
40 | $sql = 'SELECT id, title FROM '.$table.' |
||
41 | WHERE id<>6 |
||
42 | ORDER BY id ASC'; |
||
43 | $result = Database::query($sql); |
||
44 | $friend_relation_list = []; |
||
45 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
||
46 | $friend_relation_list[] = $row; |
||
47 | } |
||
48 | $count_list = count($friend_relation_list); |
||
49 | if ($count_list == 0) { |
||
50 | $friend_relation_list[] = get_lang('Unknown'); |
||
51 | } else { |
||
52 | return $friend_relation_list; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Get the kind of relation between contacts. |
||
58 | * |
||
59 | * @param int $user_id user id |
||
60 | * @param int $user_friend user friend id |
||
61 | * @param bool $includeRH include the RH relationship |
||
62 | * |
||
63 | * @return int |
||
64 | * |
||
65 | * @author isaac flores paz |
||
66 | */ |
||
67 | public static function get_relation_between_contacts($user_id, $user_friend, $includeRH = false) |
||
68 | { |
||
69 | $table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); |
||
70 | $userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
71 | if ($includeRH == false) { |
||
72 | $sql = 'SELECT rt.id as id |
||
73 | FROM '.$table.' rt |
||
74 | WHERE rt.id = ( |
||
75 | SELECT uf.relation_type |
||
76 | FROM '.$userRelUserTable.' uf |
||
77 | WHERE |
||
78 | user_id='.((int) $user_id).' AND |
||
79 | friend_user_id='.((int) $user_friend).' AND |
||
80 | uf.relation_type <> '.USER_RELATION_TYPE_RRHH.' |
||
81 | LIMIT 1 |
||
82 | )'; |
||
83 | } else { |
||
84 | $sql = 'SELECT rt.id as id |
||
85 | FROM '.$table.' rt |
||
86 | WHERE rt.id = ( |
||
87 | SELECT uf.relation_type |
||
88 | FROM '.$userRelUserTable.' uf |
||
89 | WHERE |
||
90 | user_id='.((int) $user_id).' AND |
||
91 | friend_user_id='.((int) $user_friend).' |
||
92 | LIMIT 1 |
||
93 | )'; |
||
94 | } |
||
95 | $res = Database::query($sql); |
||
96 | if (Database::num_rows($res) > 0) { |
||
97 | $row = Database::fetch_array($res, 'ASSOC'); |
||
98 | |||
99 | return (int) $row['id']; |
||
100 | } else { |
||
101 | if (api_get_configuration_value('social_make_teachers_friend_all')) { |
||
102 | $adminsList = UserManager::get_all_administrators(); |
||
103 | foreach ($adminsList as $admin) { |
||
104 | if (api_get_user_id() == $admin['user_id']) { |
||
105 | return USER_RELATION_TYPE_GOODFRIEND; |
||
106 | } |
||
107 | } |
||
108 | $targetUserCoursesList = CourseManager::get_courses_list_by_user_id( |
||
109 | $user_id, |
||
110 | true, |
||
111 | false |
||
112 | ); |
||
113 | $currentUserId = api_get_user_id(); |
||
114 | foreach ($targetUserCoursesList as $course) { |
||
115 | $teachersList = CourseManager::get_teacher_list_from_course_code($course['code']); |
||
116 | foreach ($teachersList as $teacher) { |
||
117 | if ($currentUserId == $teacher['user_id']) { |
||
118 | return USER_RELATION_TYPE_GOODFRIEND; |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | } else { |
||
123 | return USER_UNKNOWN; |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Get count of friends from user. |
||
130 | * |
||
131 | * @param int $userId |
||
132 | * |
||
133 | * @return int |
||
134 | */ |
||
135 | public static function getCountFriends($userId) |
||
136 | { |
||
137 | $table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
138 | $userId = (int) $userId; |
||
139 | if (empty($userId)) { |
||
140 | return 0; |
||
141 | } |
||
142 | |||
143 | $sql = 'SELECT count(friend_user_id) count |
||
144 | FROM '.$table.' |
||
145 | WHERE |
||
146 | relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND |
||
147 | friend_user_id<>'.$userId.' AND |
||
148 | user_id='.$userId; |
||
149 | $res = Database::query($sql); |
||
150 | if (Database::num_rows($res)) { |
||
151 | $row = Database::fetch_array($res, 'ASSOC'); |
||
152 | |||
153 | return (int) $row['count']; |
||
154 | } |
||
155 | |||
156 | return 0; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Gets friends id list. |
||
161 | * |
||
162 | * @param int user id |
||
163 | * @param int group id |
||
164 | * @param string name to search |
||
165 | * @param bool true will load firstname, lastname, and image name |
||
166 | * |
||
167 | * @return array |
||
168 | * |
||
169 | * @author Julio Montoya <[email protected]> Cleaning code, function renamed, $load_extra_info option added |
||
170 | * @author isaac flores paz |
||
171 | */ |
||
172 | public static function get_friends( |
||
173 | $user_id, |
||
174 | $id_group = null, |
||
175 | $search_name = null, |
||
176 | $load_extra_info = true |
||
177 | ) { |
||
178 | $user_id = (int) $user_id; |
||
179 | |||
180 | $tbl_my_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
181 | $tbl_my_user = Database::get_main_table(TABLE_MAIN_USER); |
||
182 | $sql = 'SELECT friend_user_id FROM '.$tbl_my_friend.' |
||
183 | WHERE |
||
184 | relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND |
||
185 | friend_user_id<>'.$user_id.' AND |
||
186 | user_id='.$user_id; |
||
187 | if (isset($id_group) && $id_group > 0) { |
||
188 | $sql .= ' AND relation_type='.$id_group; |
||
189 | } |
||
190 | if (isset($search_name)) { |
||
191 | $search_name = trim($search_name); |
||
192 | $search_name = str_replace(' ', '', $search_name); |
||
193 | $sql .= ' AND friend_user_id IN ( |
||
194 | SELECT user_id FROM '.$tbl_my_user.' |
||
195 | WHERE |
||
196 | firstName LIKE "%'.Database::escape_string($search_name).'%" OR |
||
197 | lastName LIKE "%'.Database::escape_string($search_name).'%" OR |
||
198 | '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' LIKE concat("%","'.Database::escape_string($search_name).'","%") |
||
199 | ) '; |
||
200 | } |
||
201 | |||
202 | $res = Database::query($sql); |
||
203 | $list = []; |
||
204 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
205 | if ($load_extra_info) { |
||
206 | $userInfo = api_get_user_info($row['friend_user_id']); |
||
207 | $list[] = [ |
||
208 | 'friend_user_id' => $row['friend_user_id'], |
||
209 | 'firstName' => $userInfo['firstName'], |
||
210 | 'lastName' => $userInfo['lastName'], |
||
211 | 'username' => $userInfo['username'], |
||
212 | 'image' => $userInfo['avatar'], |
||
213 | 'user_info' => $userInfo, |
||
214 | ]; |
||
215 | } else { |
||
216 | $list[] = $row; |
||
217 | } |
||
218 | } |
||
219 | |||
220 | return $list; |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * get web path of user invitate. |
||
225 | * |
||
226 | * @author isaac flores paz |
||
227 | * @author Julio Montoya setting variable array |
||
228 | * |
||
229 | * @param int user id |
||
230 | * |
||
231 | * @return array |
||
232 | */ |
||
233 | public static function get_list_web_path_user_invitation_by_user_id($user_id) |
||
234 | { |
||
235 | $list_ids = self::get_list_invitation_of_friends_by_user_id($user_id); |
||
236 | $list = []; |
||
237 | foreach ($list_ids as $values_ids) { |
||
238 | $list[] = UserManager::get_user_picture_path_by_id( |
||
239 | $values_ids['user_sender_id'], |
||
240 | 'web' |
||
241 | ); |
||
242 | } |
||
243 | |||
244 | return $list; |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * Sends an invitation to contacts. |
||
249 | * |
||
250 | * @param int user id |
||
251 | * @param int user friend id |
||
252 | * @param string title of the message |
||
253 | * @param string content of the message |
||
254 | * |
||
255 | * @return bool |
||
256 | * |
||
257 | * @author isaac flores paz |
||
258 | * @author Julio Montoya <[email protected]> Cleaning code |
||
259 | */ |
||
260 | public static function send_invitation_friend( |
||
261 | $user_id, |
||
262 | $friend_id, |
||
263 | $message_title, |
||
264 | $message_content |
||
265 | ) { |
||
266 | $tbl_message = Database::get_main_table(TABLE_MESSAGE); |
||
267 | $user_id = (int) $user_id; |
||
268 | $friend_id = (int) $friend_id; |
||
269 | |||
270 | //Just in case we replace the and \n and \n\r while saving in the DB |
||
271 | $message_content = str_replace(["\n", "\n\r"], '<br />', $message_content); |
||
272 | |||
273 | $clean_message_content = Database::escape_string($message_content); |
||
274 | $now = api_get_utc_datetime(); |
||
275 | $sql = 'SELECT COUNT(*) AS count FROM '.$tbl_message.' |
||
276 | WHERE |
||
277 | user_sender_id='.$user_id.' AND |
||
278 | user_receiver_id='.$friend_id.' AND |
||
279 | msg_status IN('.MESSAGE_STATUS_INVITATION_PENDING.', '.MESSAGE_STATUS_INVITATION_ACCEPTED.', '.MESSAGE_STATUS_INVITATION_DENIED.'); |
||
280 | '; |
||
281 | $res_exist = Database::query($sql); |
||
282 | $row_exist = Database::fetch_array($res_exist, 'ASSOC'); |
||
283 | |||
284 | if ($row_exist['count'] == 0) { |
||
285 | $params = [ |
||
286 | 'user_sender_id' => $user_id, |
||
287 | 'user_receiver_id' => $friend_id, |
||
288 | 'msg_status' => MESSAGE_STATUS_INVITATION_PENDING, |
||
289 | 'send_date' => $now, |
||
290 | 'title' => $message_title, |
||
291 | 'content' => $message_content, |
||
292 | 'group_id' => 0, |
||
293 | 'parent_id' => 0, |
||
294 | 'update_date' => $now, |
||
295 | ]; |
||
296 | $messageId = Database::insert($tbl_message, $params); |
||
297 | |||
298 | $senderInfo = api_get_user_info($user_id); |
||
299 | $notification = new Notification(); |
||
300 | $notification->saveNotification( |
||
301 | $messageId, |
||
302 | Notification::NOTIFICATION_TYPE_INVITATION, |
||
303 | [$friend_id], |
||
304 | $message_title, |
||
305 | $message_content, |
||
306 | $senderInfo |
||
307 | ); |
||
308 | |||
309 | return true; |
||
310 | } else { |
||
311 | // invitation already exist |
||
312 | $sql = 'SELECT COUNT(*) AS count, id FROM '.$tbl_message.' |
||
313 | WHERE |
||
314 | user_sender_id='.$user_id.' AND |
||
315 | user_receiver_id='.$friend_id.' AND |
||
316 | msg_status = 7'; |
||
317 | $res_if_exist = Database::query($sql); |
||
318 | $row_if_exist = Database::fetch_array($res_if_exist, 'ASSOC'); |
||
319 | if ($row_if_exist['count'] == 1) { |
||
320 | $sql = 'UPDATE '.$tbl_message.' SET |
||
321 | msg_status = 5, content = "'.$clean_message_content.'" |
||
322 | WHERE |
||
323 | user_sender_id='.$user_id.' AND |
||
324 | user_receiver_id='.$friend_id.' AND |
||
325 | msg_status = 7 '; |
||
326 | Database::query($sql); |
||
327 | |||
328 | return true; |
||
329 | } else { |
||
330 | return false; |
||
331 | } |
||
332 | } |
||
333 | } |
||
334 | |||
335 | /** |
||
336 | * Get number messages of the inbox. |
||
337 | * |
||
338 | * @author isaac flores paz |
||
339 | * |
||
340 | * @param int $userId user receiver id |
||
341 | * |
||
342 | * @return int |
||
343 | */ |
||
344 | public static function get_message_number_invitation_by_user_id($userId) |
||
345 | { |
||
346 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
347 | $userId = (int) $userId; |
||
348 | $sql = 'SELECT COUNT(*) as count_message_in_box FROM '.$table.' |
||
349 | WHERE |
||
350 | user_receiver_id='.$userId.' AND |
||
351 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
352 | $res = Database::query($sql); |
||
353 | $row = Database::fetch_array($res, 'ASSOC'); |
||
354 | if ($row) { |
||
355 | return (int) $row['count_message_in_box']; |
||
356 | } |
||
357 | |||
358 | return 0; |
||
359 | } |
||
360 | |||
361 | /** |
||
362 | * Get number of messages sent to other users. |
||
363 | * |
||
364 | * @param int $userId |
||
365 | * |
||
366 | * @return int |
||
367 | */ |
||
368 | public static function getCountMessagesSent($userId) |
||
369 | { |
||
370 | $userId = (int) $userId; |
||
371 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
372 | $sql = 'SELECT COUNT(*) FROM '.$table.' |
||
373 | WHERE |
||
374 | user_sender_id='.$userId.' AND |
||
375 | msg_status < 5'; |
||
376 | $res = Database::query($sql); |
||
377 | $row = Database::fetch_row($res); |
||
378 | |||
379 | return $row[0]; |
||
380 | } |
||
381 | |||
382 | /** |
||
383 | * Get number of messages received from other users. |
||
384 | * |
||
385 | * @param int $receiver_id |
||
386 | * |
||
387 | * @return int |
||
388 | */ |
||
389 | public static function getCountMessagesReceived($receiver_id) |
||
390 | { |
||
391 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
392 | $sql = 'SELECT COUNT(*) FROM '.$table.' |
||
393 | WHERE |
||
394 | user_receiver_id='.intval($receiver_id).' AND |
||
395 | msg_status < 4'; |
||
396 | $res = Database::query($sql); |
||
397 | $row = Database::fetch_row($res); |
||
398 | |||
399 | return $row[0]; |
||
400 | } |
||
401 | |||
402 | /** |
||
403 | * Get number of messages posted on own wall. |
||
404 | * |
||
405 | * @param int $userId |
||
406 | * |
||
407 | * @return int |
||
408 | */ |
||
409 | public static function getCountWallPostedMessages($userId) |
||
410 | { |
||
411 | $userId = (int) $userId; |
||
412 | |||
413 | if (empty($userId)) { |
||
414 | return 0; |
||
415 | } |
||
416 | |||
417 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
418 | $sql = 'SELECT COUNT(*) |
||
419 | FROM '.$table.' |
||
420 | WHERE |
||
421 | user_sender_id='.$userId.' AND |
||
422 | (msg_status = '.MESSAGE_STATUS_WALL.' OR |
||
423 | msg_status = '.MESSAGE_STATUS_WALL_POST.') AND |
||
424 | parent_id = 0'; |
||
425 | $res = Database::query($sql); |
||
426 | $row = Database::fetch_row($res); |
||
427 | |||
428 | return $row[0]; |
||
429 | } |
||
430 | |||
431 | /** |
||
432 | * Get invitation list received by user. |
||
433 | * |
||
434 | * @author isaac flores paz |
||
435 | * |
||
436 | * @param int $userId |
||
437 | * @param int $limit |
||
438 | * |
||
439 | * @return array |
||
440 | */ |
||
441 | public static function get_list_invitation_of_friends_by_user_id($userId, $limit = 0) |
||
442 | { |
||
443 | $userId = (int) $userId; |
||
444 | $limit = (int) $limit; |
||
445 | |||
446 | if (empty($userId)) { |
||
447 | return []; |
||
448 | } |
||
449 | |||
450 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
451 | $sql = 'SELECT user_sender_id, send_date, title, content |
||
452 | FROM '.$table.' |
||
453 | WHERE |
||
454 | user_receiver_id = '.$userId.' AND |
||
455 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
456 | if ($limit != null && $limit > 0) { |
||
457 | $sql .= ' LIMIT '.$limit; |
||
458 | } |
||
459 | $res = Database::query($sql); |
||
460 | $list = []; |
||
461 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
462 | $list[] = $row; |
||
463 | } |
||
464 | |||
465 | return $list; |
||
466 | } |
||
467 | |||
468 | /** |
||
469 | * Get invitation list sent by user. |
||
470 | * |
||
471 | * @author Julio Montoya <[email protected]> |
||
472 | * |
||
473 | * @param int $userId |
||
474 | * |
||
475 | * @return array |
||
476 | */ |
||
477 | public static function get_list_invitation_sent_by_user_id($userId) |
||
478 | { |
||
479 | $userId = (int) $userId; |
||
480 | |||
481 | if (empty($userId)) { |
||
482 | return []; |
||
483 | } |
||
484 | |||
485 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
486 | $sql = 'SELECT user_receiver_id, send_date,title,content |
||
487 | FROM '.$table.' |
||
488 | WHERE |
||
489 | user_sender_id = '.$userId.' AND |
||
490 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
491 | $res = Database::query($sql); |
||
492 | $list = []; |
||
493 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
494 | $list[$row['user_receiver_id']] = $row; |
||
495 | } |
||
496 | |||
497 | return $list; |
||
498 | } |
||
499 | |||
500 | /** |
||
501 | * Get count invitation sent by user. |
||
502 | * |
||
503 | * @author Julio Montoya <[email protected]> |
||
504 | * |
||
505 | * @param int $userId |
||
506 | * |
||
507 | * @return int |
||
508 | */ |
||
509 | public static function getCountInvitationSent($userId) |
||
510 | { |
||
511 | $userId = (int) $userId; |
||
512 | |||
513 | if (empty($userId)) { |
||
514 | return 0; |
||
515 | } |
||
516 | |||
517 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
518 | $sql = 'SELECT count(user_receiver_id) count |
||
519 | FROM '.$table.' |
||
520 | WHERE |
||
521 | user_sender_id = '.$userId.' AND |
||
522 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
523 | $res = Database::query($sql); |
||
524 | if (Database::num_rows($res)) { |
||
525 | $row = Database::fetch_array($res, 'ASSOC'); |
||
526 | |||
527 | return (int) $row['count']; |
||
528 | } |
||
529 | |||
530 | return 0; |
||
531 | } |
||
532 | |||
533 | /** |
||
534 | * Accepts invitation. |
||
535 | * |
||
536 | * @param int $user_send_id |
||
537 | * @param int $user_receiver_id |
||
538 | * |
||
539 | * @return bool |
||
540 | * |
||
541 | * @author isaac flores paz |
||
542 | * @author Julio Montoya <[email protected]> Cleaning code |
||
543 | */ |
||
544 | public static function invitation_accepted($user_send_id, $user_receiver_id) |
||
545 | { |
||
546 | if (empty($user_send_id) || empty($user_receiver_id)) { |
||
547 | return false; |
||
548 | } |
||
549 | |||
550 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
551 | $sql = "UPDATE $table |
||
552 | SET msg_status = ".MESSAGE_STATUS_INVITATION_ACCEPTED." |
||
553 | WHERE |
||
554 | user_sender_id = ".((int) $user_send_id)." AND |
||
555 | user_receiver_id=".((int) $user_receiver_id)." AND |
||
556 | msg_status = ".MESSAGE_STATUS_INVITATION_PENDING; |
||
557 | Database::query($sql); |
||
558 | |||
559 | return true; |
||
560 | } |
||
561 | |||
562 | /** |
||
563 | * Denies invitation. |
||
564 | * |
||
565 | * @param int user sender id |
||
566 | * @param int user receiver id |
||
567 | * |
||
568 | * @return bool |
||
569 | * |
||
570 | * @author isaac flores paz |
||
571 | * @author Julio Montoya <[email protected]> Cleaning code |
||
572 | */ |
||
573 | public static function invitation_denied($user_send_id, $user_receiver_id) |
||
574 | { |
||
575 | if (empty($user_send_id) || empty($user_receiver_id)) { |
||
576 | return false; |
||
577 | } |
||
578 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
579 | $sql = 'DELETE FROM '.$table.' |
||
580 | WHERE |
||
581 | user_sender_id = '.((int) $user_send_id).' AND |
||
582 | user_receiver_id='.((int) $user_receiver_id).' AND |
||
583 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
584 | Database::query($sql); |
||
585 | |||
586 | return true; |
||
587 | } |
||
588 | |||
589 | /** |
||
590 | * Get user's feeds. |
||
591 | * |
||
592 | * @param int $user User ID |
||
593 | * @param int $limit Limit of posts per feed |
||
594 | * |
||
595 | * @return string HTML section with all feeds included |
||
596 | * |
||
597 | * @author Yannick Warnier |
||
598 | * |
||
599 | * @since Dokeos 1.8.6.1 |
||
600 | */ |
||
601 | public static function getUserRssFeed($user, $limit = 5) |
||
602 | { |
||
603 | $feed = UserManager::get_extra_user_data_by_field($user, 'rssfeeds'); |
||
604 | |||
605 | if (empty($feed)) { |
||
606 | return ''; |
||
607 | } |
||
608 | $feeds = explode(';', $feed['rssfeeds']); |
||
609 | if (0 == count($feeds)) { |
||
610 | return ''; |
||
611 | } |
||
612 | $res = ''; |
||
613 | foreach ($feeds as $url) { |
||
614 | if (empty($url)) { |
||
615 | continue; |
||
616 | } |
||
617 | try { |
||
618 | $channel = Reader::import($url); |
||
619 | $i = 1; |
||
620 | if (!empty($channel)) { |
||
621 | $iconRss = ''; |
||
622 | if (!empty($feed)) { |
||
623 | $iconRss = Display::url( |
||
624 | Display::return_icon('social_rss.png', '', [], 22), |
||
625 | Security::remove_XSS($feed['rssfeeds']), |
||
626 | ['target' => '_blank'] |
||
627 | ); |
||
628 | } |
||
629 | |||
630 | $res .= '<h3 class="title-rss">'.$iconRss.' '.$channel->getTitle().'</h3>'; |
||
631 | $res .= '<div class="rss-items">'; |
||
632 | /** @var Rss $item */ |
||
633 | foreach ($channel as $item) { |
||
634 | if ($limit >= 0 and $i > $limit) { |
||
635 | break; |
||
636 | } |
||
637 | $res .= '<h4 class="rss-title"><a href="'.$item->getLink().'">'.$item->getTitle().'</a></h4>'; |
||
638 | $res .= '<div class="rss-date">'.api_get_local_time($item->getDateCreated()).'</div>'; |
||
639 | $res .= '<div class="rss-content"><p>'.$item->getDescription().'</p></div>'; |
||
640 | $i++; |
||
641 | } |
||
642 | $res .= '</div>'; |
||
643 | } |
||
644 | } catch (Exception $e) { |
||
645 | error_log($e->getMessage()); |
||
646 | } |
||
647 | } |
||
648 | |||
649 | return $res; |
||
650 | } |
||
651 | |||
652 | /** |
||
653 | * Sends invitations to friends. |
||
654 | * |
||
655 | * @param int $userId |
||
656 | * @param string $subject |
||
657 | * @param string $content |
||
658 | * |
||
659 | * @return bool |
||
660 | */ |
||
661 | public static function sendInvitationToUser($userId, $subject = '', $content = '') |
||
662 | { |
||
663 | $user_info = api_get_user_info($userId); |
||
664 | $success = get_lang('MessageSentTo'); |
||
665 | $success .= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']); |
||
666 | $content = strip_tags($content); |
||
667 | |||
668 | if (isset($subject) && isset($content) && isset($userId)) { |
||
669 | $result = MessageManager::send_message($userId, $subject, $content); |
||
670 | |||
671 | if ($result) { |
||
672 | Display::addFlash( |
||
673 | Display::return_message($success, 'normal', false) |
||
674 | ); |
||
675 | } else { |
||
676 | Display::addFlash( |
||
677 | Display::return_message(get_lang('ErrorSendingMessage'), 'error', false) |
||
678 | ); |
||
679 | } |
||
680 | |||
681 | return false; |
||
682 | } elseif (isset($userId) && !isset($subject)) { |
||
683 | if (isset($userId) && $userId > 0) { |
||
684 | $count = self::send_invitation_friend( |
||
685 | api_get_user_id(), |
||
686 | $userId, |
||
687 | get_lang('Invitation'), |
||
688 | $content |
||
689 | ); |
||
690 | |||
691 | if ($count) { |
||
692 | Display::addFlash( |
||
693 | Display::return_message( |
||
694 | api_htmlentities(get_lang('InvitationHasBeenSent')), |
||
695 | 'normal', |
||
696 | false |
||
697 | ) |
||
698 | ); |
||
699 | } else { |
||
700 | Display::addFlash( |
||
701 | Display::return_message( |
||
702 | api_htmlentities(get_lang('YouAlreadySentAnInvitation')), |
||
703 | 'warning', |
||
704 | false |
||
705 | ) |
||
706 | ); |
||
707 | } |
||
708 | } |
||
709 | } |
||
710 | } |
||
711 | |||
712 | /** |
||
713 | * Helper functions definition. |
||
714 | */ |
||
715 | public static function get_logged_user_course_html($my_course, $count) |
||
716 | { |
||
717 | $result = ''; |
||
718 | $count = (int) $count; |
||
719 | |||
720 | // Table definitions |
||
721 | $main_user_table = Database::get_main_table(TABLE_MAIN_USER); |
||
722 | $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
||
723 | $course_directory = $my_course['course_info']['directory']; |
||
724 | $course_title = $my_course['course_info']['title']; |
||
725 | $course_visibility = $my_course['course_info']['visibility']; |
||
726 | |||
727 | $user_in_course_status = CourseManager::getUserInCourseStatus( |
||
728 | api_get_user_id(), |
||
729 | $my_course['course_info']['real_id'] |
||
730 | ); |
||
731 | |||
732 | $course_path = api_get_path(SYS_COURSE_PATH).$course_directory; // course path |
||
733 | if (api_get_setting('course_images_in_courses_list') === 'true') { |
||
734 | if (file_exists($course_path.'/course-pic85x85.png')) { |
||
735 | $image = $my_course['course_info']['course_image']; |
||
736 | $imageCourse = Display::img($image, $course_title, ['class' => 'img-course']); |
||
737 | } else { |
||
738 | $imageCourse = Display::return_icon( |
||
739 | 'session_default_small.png', |
||
740 | $course_title, |
||
741 | ['class' => 'img-course'] |
||
742 | ); |
||
743 | } |
||
744 | } else { |
||
745 | $imageCourse = Display::return_icon( |
||
746 | 'course.png', |
||
747 | get_lang('Course'), |
||
748 | ['class' => 'img-default'] |
||
749 | ); |
||
750 | } |
||
751 | |||
752 | //display course entry |
||
753 | if (api_get_setting('course_images_in_courses_list') === 'true') { |
||
754 | $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:65px;">'; |
||
755 | } else { |
||
756 | $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:44px;">'; |
||
757 | } |
||
758 | $result .= $imageCourse; |
||
759 | |||
760 | //show a hyperlink to the course, unless the course is closed and user is not course admin |
||
761 | if ($course_visibility != COURSE_VISIBILITY_HIDDEN && |
||
762 | ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) |
||
763 | ) { |
||
764 | $result .= '<span class="title">'.$course_title.'<span>'; |
||
765 | } else { |
||
766 | $result .= $course_title.' '.get_lang('CourseClosed'); |
||
767 | } |
||
768 | |||
769 | $result .= '</li>'; |
||
770 | $session = ''; |
||
771 | if (!empty($my_course['session_name']) && !empty($my_course['id_session'])) { |
||
772 | // Request for the name of the general coach |
||
773 | $sql = 'SELECT lastname, firstname |
||
774 | FROM '.$tbl_session.' ts |
||
775 | LEFT JOIN '.$main_user_table.' tu |
||
776 | ON ts.id_coach = tu.user_id |
||
777 | WHERE ts.id='.(int) $my_course['id_session'].' LIMIT 1'; |
||
778 | $rs = Database::query($sql); |
||
779 | $sessioncoach = Database::store_result($rs); |
||
780 | $sessioncoach = $sessioncoach[0]; |
||
781 | |||
782 | $session = []; |
||
783 | $session['title'] = $my_course['session_name']; |
||
784 | if ($my_course['access_start_date'] == '0000-00-00') { |
||
785 | $session['dates'] = get_lang('WithoutTimeLimits'); |
||
786 | if (api_get_setting('show_session_coach') === 'true') { |
||
787 | $session['coach'] = get_lang('GeneralCoach').': '. |
||
788 | api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); |
||
789 | } |
||
790 | } else { |
||
791 | $session['dates'] = ' - '.get_lang('From').' '.$my_course['access_start_date'].' '.get_lang('To').' '.$my_course['access_end_date']; |
||
792 | if (api_get_setting('show_session_coach') === 'true') { |
||
793 | $session['coach'] = get_lang('GeneralCoach').': '. |
||
794 | api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); |
||
795 | } |
||
796 | } |
||
797 | } |
||
798 | |||
799 | $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0; |
||
800 | $output = [ |
||
801 | $my_course['user_course_cat'], |
||
802 | $result, |
||
803 | $my_course['id_session'], |
||
804 | $session, |
||
805 | ]; |
||
806 | |||
807 | return $output; |
||
808 | } |
||
809 | |||
810 | /** |
||
811 | * Shows the avatar block in social pages. |
||
812 | * |
||
813 | * @param string $show highlight link possible values: |
||
814 | * group_add, |
||
815 | * home, |
||
816 | * messages, |
||
817 | * messages_inbox, |
||
818 | * messages_compose, |
||
819 | * messages_outbox, |
||
820 | * invitations, |
||
821 | * shared_profile, |
||
822 | * friends, |
||
823 | * groups search |
||
824 | * @param int $group_id |
||
825 | * @param int $user_id |
||
826 | */ |
||
827 | public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0) |
||
828 | { |
||
829 | $user_id = (int) $user_id; |
||
830 | $group_id = (int) $group_id; |
||
831 | |||
832 | if (empty($user_id)) { |
||
833 | $user_id = api_get_user_id(); |
||
834 | } |
||
835 | |||
836 | $show_groups = [ |
||
837 | 'groups', |
||
838 | 'group_messages', |
||
839 | 'messages_list', |
||
840 | 'group_add', |
||
841 | 'mygroups', |
||
842 | 'group_edit', |
||
843 | 'member_list', |
||
844 | 'invite_friends', |
||
845 | 'waiting_list', |
||
846 | 'browse_groups', |
||
847 | ]; |
||
848 | |||
849 | $template = new Template(null, false, false, false, false, false); |
||
850 | |||
851 | if (in_array($show, $show_groups) && !empty($group_id)) { |
||
852 | // Group image |
||
853 | $userGroup = new UserGroup(); |
||
854 | $group_info = $userGroup->get($group_id); |
||
855 | |||
856 | $userGroupImage = $userGroup->get_picture_group( |
||
857 | $group_id, |
||
858 | $group_info['picture'], |
||
859 | 128, |
||
860 | GROUP_IMAGE_SIZE_BIG |
||
861 | ); |
||
862 | |||
863 | $template->assign('show_group', true); |
||
864 | $template->assign('group_id', $group_id); |
||
865 | $template->assign('user_group_image', $userGroupImage); |
||
866 | $template->assign( |
||
867 | 'user_is_group_admin', |
||
868 | $userGroup->is_group_admin( |
||
869 | $group_id, |
||
870 | api_get_user_id() |
||
871 | ) |
||
872 | ); |
||
873 | } else { |
||
874 | $template->assign('show_group', false); |
||
875 | $template->assign('show_user', true); |
||
876 | $template->assign( |
||
877 | 'user_image', |
||
878 | [ |
||
879 | 'big' => UserManager::getUserPicture( |
||
880 | $user_id, |
||
881 | USER_IMAGE_SIZE_BIG |
||
882 | ), |
||
883 | 'normal' => UserManager::getUserPicture( |
||
884 | $user_id, |
||
885 | USER_IMAGE_SIZE_MEDIUM |
||
886 | ), |
||
887 | ] |
||
888 | ); |
||
889 | } |
||
890 | |||
891 | return $template->fetch($template->get_template('social/avatar_block.tpl')); |
||
892 | } |
||
893 | |||
894 | /** |
||
895 | * Shows the right menu of the Social Network tool. |
||
896 | * |
||
897 | * @param string $show highlight link possible values: |
||
898 | * group_add, |
||
899 | * home, |
||
900 | * messages, |
||
901 | * messages_inbox, |
||
902 | * messages_compose , |
||
903 | * messages_outbox, |
||
904 | * invitations, |
||
905 | * shared_profile, |
||
906 | * friends, |
||
907 | * groups search |
||
908 | * @param int $group_id group id |
||
909 | * @param int $user_id user id |
||
910 | * @param bool $show_full_profile show profile or not (show or hide the user image/information) |
||
911 | * @param bool $show_delete_account_button |
||
912 | */ |
||
913 | public static function show_social_menu( |
||
914 | $show = '', |
||
915 | $group_id = 0, |
||
916 | $user_id = 0, |
||
917 | $show_full_profile = false, |
||
918 | $show_delete_account_button = false |
||
919 | ) { |
||
920 | $user_id = (int) $user_id; |
||
921 | $group_id = (int) $group_id; |
||
922 | $settingExtendedProfileEnabled = api_get_setting('extended_profile'); |
||
923 | |||
924 | if (empty($user_id)) { |
||
925 | $user_id = api_get_user_id(); |
||
926 | } |
||
927 | |||
928 | $myExtendedProfileEdit = ''; |
||
929 | if ($user_id == api_get_user_id()) { |
||
930 | $myExtendedProfileEdit .= '<a href="/main/auth/profile.php?type=extended#openarea" style="display:initial">'. |
||
931 | Display::return_icon('edit.png', get_lang('EditExtendProfile'), '', 16).'</a>'; |
||
932 | } |
||
933 | $usergroup = new UserGroup(); |
||
934 | $show_groups = [ |
||
935 | 'groups', |
||
936 | 'group_messages', |
||
937 | 'messages_list', |
||
938 | 'group_add', |
||
939 | 'mygroups', |
||
940 | 'group_edit', |
||
941 | 'member_list', |
||
942 | 'invite_friends', |
||
943 | 'waiting_list', |
||
944 | 'browse_groups', |
||
945 | ]; |
||
946 | |||
947 | // get count unread message and total invitations |
||
948 | $count_unread_message = MessageManager::getCountNewMessagesFromDB(api_get_user_id()); |
||
949 | $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null; |
||
950 | |||
951 | $number_of_new_messages_of_friend = self::get_message_number_invitation_by_user_id(api_get_user_id()); |
||
952 | $group_pending_invitations = $usergroup->get_groups_by_user( |
||
953 | api_get_user_id(), |
||
954 | GROUP_USER_PERMISSION_PENDING_INVITATION, |
||
955 | false |
||
956 | ); |
||
957 | $group_pending_invitations = count($group_pending_invitations); |
||
958 | $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; |
||
959 | $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : ''); |
||
960 | |||
961 | $filesIcon = Display::return_icon('sn-files.png', get_lang('MyFiles'), null, ICON_SIZE_SMALL); |
||
962 | $friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), null, ICON_SIZE_SMALL); |
||
963 | $groupsIcon = Display::return_icon('sn-groups.png', get_lang('SocialGroups'), null, ICON_SIZE_SMALL); |
||
964 | $homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), null, ICON_SIZE_SMALL); |
||
965 | $invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), null, ICON_SIZE_SMALL); |
||
966 | $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), null, ICON_SIZE_SMALL); |
||
967 | $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile')); |
||
968 | $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), null, ICON_SIZE_SMALL); |
||
969 | $portfolioIcon = Display::return_icon('wiki_task.png', get_lang('Portfolio')); |
||
970 | $personalDataIcon = Display::return_icon('database.png', get_lang('PersonalDataReport')); |
||
971 | $messageSocialIcon = Display::return_icon('promoted_message.png', get_lang('PromotedMessages')); |
||
972 | $portfolio = Display::return_icon('portfolio.png', get_lang('Portfolio ')); |
||
973 | |||
974 | $allowPortfolioTool = api_get_configuration_value('allow_portfolio_tool'); |
||
975 | |||
976 | $forumCourseId = api_get_configuration_value('global_forums_course_id'); |
||
977 | $groupUrl = api_get_path(WEB_CODE_PATH).'social/groups.php'; |
||
978 | if (!empty($forumCourseId)) { |
||
979 | $courseInfo = api_get_course_info_by_id($forumCourseId); |
||
980 | if (!empty($courseInfo)) { |
||
981 | $groupUrl = api_get_path(WEB_CODE_PATH).'forum/index.php?cidReq='.$courseInfo['code']; |
||
982 | } |
||
983 | } |
||
984 | |||
985 | $html = ''; |
||
986 | $active = null; |
||
987 | if (!in_array( |
||
988 | $show, |
||
989 | ['shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'] |
||
990 | )) { |
||
991 | $links = '<ul class="nav nav-pills nav-stacked">'; |
||
992 | $active = $show === 'home' ? 'active' : null; |
||
993 | $links .= ' |
||
994 | <li class="home-icon '.$active.'"> |
||
995 | <a href="'.api_get_path(WEB_CODE_PATH).'social/home.php"> |
||
996 | '.$homeIcon.' '.get_lang('Home').' |
||
997 | </a> |
||
998 | </li>'; |
||
999 | $active = $show === 'messages' ? 'active' : null; |
||
1000 | $links .= ' |
||
1001 | <li class="messages-icon '.$active.'"> |
||
1002 | <a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php"> |
||
1003 | '.$messagesIcon.' '.get_lang('Messages').$count_unread_message.' |
||
1004 | </a> |
||
1005 | </li>'; |
||
1006 | if ($allowPortfolioTool) { |
||
1007 | $links .= ' |
||
1008 | <li class="portoflio-icon '.($show === 'portfolio' ? 'active' : '').'"> |
||
1009 | <a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php"> |
||
1010 | '.$portfolioIcon.' '.get_lang('Portfolio').' |
||
1011 | </a> |
||
1012 | </li> |
||
1013 | '; |
||
1014 | } else { |
||
1015 | if ($settingExtendedProfileEnabled == true) { |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
1016 | $active = $show === 'portfolio' ? 'active' : null; |
||
1017 | $links .= ' |
||
1018 | <li class="portfolio-icon '.$active.'"> |
||
1019 | <a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user_id.'&p=1"> |
||
1020 | '.$portfolio.' '.get_lang('Portfolio').' |
||
1021 | </a> |
||
1022 | </li>'; |
||
1023 | } |
||
1024 | } |
||
1025 | |||
1026 | // Invitations |
||
1027 | $active = $show === 'invitations' ? 'active' : null; |
||
1028 | $links .= ' |
||
1029 | <li class="invitations-icon '.$active.'"> |
||
1030 | <a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php"> |
||
1031 | '.$invitationsIcon.' '.get_lang('Invitations').$total_invitations.' |
||
1032 | </a> |
||
1033 | </li>'; |
||
1034 | |||
1035 | // Shared profile and groups |
||
1036 | $active = $show === 'shared_profile' ? 'active' : null; |
||
1037 | $links .= ' |
||
1038 | <li class="shared-profile-icon'.$active.'"> |
||
1039 | <a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php"> |
||
1040 | '.$sharedProfileIcon.' '.get_lang('ViewMySharedProfile').' |
||
1041 | </a> |
||
1042 | </li>'; |
||
1043 | $active = $show === 'friends' ? 'active' : null; |
||
1044 | $links .= ' |
||
1045 | <li class="friends-icon '.$active.'"> |
||
1046 | <a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php"> |
||
1047 | '.$friendsIcon.' '.get_lang('Friends').' |
||
1048 | </a> |
||
1049 | </li>'; |
||
1050 | $active = $show === 'browse_groups' ? 'active' : null; |
||
1051 | $links .= ' |
||
1052 | <li class="browse-groups-icon '.$active.'"> |
||
1053 | <a href="'.$groupUrl.'"> |
||
1054 | '.$groupsIcon.' '.get_lang('SocialGroups').' |
||
1055 | </a> |
||
1056 | </li>'; |
||
1057 | |||
1058 | // Search users |
||
1059 | $active = $show === 'search' ? 'active' : null; |
||
1060 | $links .= ' |
||
1061 | <li class="search-icon '.$active.'"> |
||
1062 | <a href="'.api_get_path(WEB_CODE_PATH).'social/search.php"> |
||
1063 | '.$searchIcon.' '.get_lang('Search').' |
||
1064 | </a> |
||
1065 | </li>'; |
||
1066 | |||
1067 | // My files |
||
1068 | $active = $show === 'myfiles' ? 'active' : null; |
||
1069 | |||
1070 | $myFiles = ' |
||
1071 | <li class="myfiles-icon '.$active.'"> |
||
1072 | <a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php"> |
||
1073 | '.$filesIcon.' '.get_lang('MyFiles').' |
||
1074 | </a> |
||
1075 | </li>'; |
||
1076 | |||
1077 | if (api_get_setting('allow_my_files') === 'false') { |
||
1078 | $myFiles = ''; |
||
1079 | } |
||
1080 | $links .= $myFiles; |
||
1081 | |||
1082 | if (!api_get_configuration_value('disable_gdpr')) { |
||
1083 | $active = $show === 'personal-data' ? 'active' : null; |
||
1084 | $personalData = ' |
||
1085 | <li class="personal-data-icon '.$active.'"> |
||
1086 | <a href="'.api_get_path(WEB_CODE_PATH).'social/personal_data.php"> |
||
1087 | '.$personalDataIcon.' '.get_lang('PersonalDataReport').' |
||
1088 | </a> |
||
1089 | </li>'; |
||
1090 | $links .= $personalData; |
||
1091 | } |
||
1092 | |||
1093 | if (api_is_platform_admin()) { |
||
1094 | $active = $show === 'promoted_messages' ? 'active' : null; |
||
1095 | $personalData = ' |
||
1096 | <li class="personal-data-icon '.$active.'"> |
||
1097 | <a href="'.api_get_path(WEB_CODE_PATH).'social/promoted_messages.php"> |
||
1098 | '.$messageSocialIcon.' '.get_lang('PromotedMessages').' |
||
1099 | </a> |
||
1100 | </li>'; |
||
1101 | $links .= $personalData; |
||
1102 | } |
||
1103 | $links .= '</ul>'; |
||
1104 | $html .= Display::panelCollapse( |
||
1105 | get_lang('SocialNetwork'), |
||
1106 | $links, |
||
1107 | 'social-network-menu', |
||
1108 | null, |
||
1109 | 'sn-sidebar', |
||
1110 | 'sn-sidebar-collapse' |
||
1111 | ); |
||
1112 | } |
||
1113 | |||
1114 | if (!empty($group_id) && in_array($show, $show_groups)) { |
||
1115 | $html .= $usergroup->show_group_column_information( |
||
1116 | $group_id, |
||
1117 | api_get_user_id(), |
||
1118 | $show |
||
1119 | ); |
||
1120 | } |
||
1121 | |||
1122 | if ($show === 'shared_profile') { |
||
1123 | $links = '<ul class="nav nav-pills nav-stacked">'; |
||
1124 | // My own profile |
||
1125 | if ($show_full_profile && $user_id == api_get_user_id()) { |
||
1126 | $links .= ' |
||
1127 | <li class="home-icon '.$active.'"> |
||
1128 | <a href="'.api_get_path(WEB_CODE_PATH).'social/home.php"> |
||
1129 | '.$homeIcon.' '.get_lang('Home').' |
||
1130 | </a> |
||
1131 | </li> |
||
1132 | <li class="messages-icon '.$active.'"> |
||
1133 | <a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php"> |
||
1134 | '.$messagesIcon.' '.get_lang('Messages').$count_unread_message.' |
||
1135 | </a> |
||
1136 | </li>'; |
||
1137 | if ($allowPortfolioTool) { |
||
1138 | $links .= ' |
||
1139 | <li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'"> |
||
1140 | <a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php"> |
||
1141 | '.$portfolioIcon.' '.get_lang('Portfolio').' |
||
1142 | </a> |
||
1143 | </li> |
||
1144 | '; |
||
1145 | } else { |
||
1146 | if ($settingExtendedProfileEnabled == true) { |
||
0 ignored issues
–
show
|
|||
1147 | $active = $show === 'portfolio' ? 'active' : null; |
||
1148 | $links .= ' |
||
1149 | <li class="portfolio-icon '.$active.'"> |
||
1150 | <a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user_id.'&p=1"> |
||
1151 | '.$portfolio.' '.get_lang('Portfolio').' |
||
1152 | </a> |
||
1153 | </li>'; |
||
1154 | } |
||
1155 | } |
||
1156 | $active = $show === 'invitations' ? 'active' : null; |
||
1157 | $links .= ' |
||
1158 | <li class="invitations-icon'.$active.'"> |
||
1159 | <a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php"> |
||
1160 | '.$invitationsIcon.' '.get_lang('Invitations').$total_invitations.' |
||
1161 | </a> |
||
1162 | </li>'; |
||
1163 | |||
1164 | $links .= ' |
||
1165 | <li class="shared-profile-icon active"> |
||
1166 | <a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php"> |
||
1167 | '.$sharedProfileIcon.' '.get_lang('ViewMySharedProfile').' |
||
1168 | </a> |
||
1169 | </li> |
||
1170 | <li class="friends-icon"> |
||
1171 | <a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php"> |
||
1172 | '.$friendsIcon.' '.get_lang('Friends').' |
||
1173 | </a> |
||
1174 | </li>'; |
||
1175 | |||
1176 | $links .= '<li class="browse-groups-icon"> |
||
1177 | <a href="'.$groupUrl.'"> |
||
1178 | '.$groupsIcon.' '.get_lang('SocialGroups').' |
||
1179 | </a> |
||
1180 | </li>'; |
||
1181 | |||
1182 | $active = $show == 'search' ? 'active' : null; |
||
1183 | $links .= ' |
||
1184 | <li class="search-icon '.$active.'"> |
||
1185 | <a href="'.api_get_path(WEB_CODE_PATH).'social/search.php"> |
||
1186 | '.$searchIcon.' '.get_lang('Search').' |
||
1187 | </a> |
||
1188 | </li>'; |
||
1189 | $active = $show == 'myfiles' ? 'active' : null; |
||
1190 | |||
1191 | $myFiles = ' |
||
1192 | <li class="myfiles-icon '.$active.'"> |
||
1193 | <a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php"> |
||
1194 | '.$filesIcon.' '.get_lang('MyFiles').' |
||
1195 | </a> |
||
1196 | </li>'; |
||
1197 | |||
1198 | if (api_get_setting('allow_my_files') === 'false') { |
||
1199 | $myFiles = ''; |
||
1200 | } |
||
1201 | $links .= $myFiles; |
||
1202 | |||
1203 | if (!api_get_configuration_value('disable_gdpr')) { |
||
1204 | $active = $show == 'personal-data' ? 'active' : null; |
||
1205 | $personalData = ' |
||
1206 | <li class="personal-data-icon '.$active.'"> |
||
1207 | <a href="'.api_get_path(WEB_CODE_PATH).'social/personal_data.php"> |
||
1208 | '.$personalDataIcon.' '.get_lang('PersonalDataReport').' |
||
1209 | </a> |
||
1210 | </li>'; |
||
1211 | $links .= $personalData; |
||
1212 | $links .= '</ul>'; |
||
1213 | } |
||
1214 | } |
||
1215 | |||
1216 | // My friend profile. |
||
1217 | if ($user_id != api_get_user_id()) { |
||
1218 | $sendMessageText = get_lang('SendMessage'); |
||
1219 | $sendMessageIcon = Display::return_icon( |
||
1220 | 'new-message.png', |
||
1221 | $sendMessageText |
||
1222 | ); |
||
1223 | $userIdHash = UserManager::generateUserHash($user_id); |
||
1224 | $sendMessageUrl = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?'.http_build_query([ |
||
1225 | 'a' => 'get_user_popup', |
||
1226 | 'hash' => $userIdHash, |
||
1227 | ]); |
||
1228 | |||
1229 | $links .= '<li>'; |
||
1230 | $links .= Display::url( |
||
1231 | "$sendMessageIcon $sendMessageText", |
||
1232 | $sendMessageUrl, |
||
1233 | [ |
||
1234 | 'class' => 'ajax', |
||
1235 | 'title' => $sendMessageText, |
||
1236 | 'data-title' => $sendMessageText, |
||
1237 | ] |
||
1238 | ); |
||
1239 | if ($allowPortfolioTool) { |
||
1240 | $links .= ' |
||
1241 | <li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'"> |
||
1242 | <a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php?user='.$user_id.'"> |
||
1243 | '.$portfolioIcon.' '.get_lang('Portfolio').' |
||
1244 | </a> |
||
1245 | </li> |
||
1246 | '; |
||
1247 | } else { |
||
1248 | if ($settingExtendedProfileEnabled == true) { |
||
0 ignored issues
–
show
|
|||
1249 | $active = $show === 'portfolio' ? 'active' : null; |
||
1250 | $links .= ' |
||
1251 | <li class="portfolio-icon '.$active.'"> |
||
1252 | <a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user_id.'&p=1"> |
||
1253 | '.$portfolio.' '.get_lang('Portfolio').' |
||
1254 | </a> |
||
1255 | </li>'; |
||
1256 | } |
||
1257 | } |
||
1258 | } |
||
1259 | |||
1260 | // Check if I already sent an invitation message |
||
1261 | $invitationSentList = self::get_list_invitation_sent_by_user_id(api_get_user_id()); |
||
1262 | |||
1263 | if (isset($invitationSentList[$user_id]) && is_array($invitationSentList[$user_id]) && |
||
1264 | count($invitationSentList[$user_id]) > 0 |
||
1265 | ) { |
||
1266 | $links .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">'. |
||
1267 | Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')) |
||
1268 | .' '.get_lang('YouAlreadySentAnInvitation').'</a></li>'; |
||
1269 | } else { |
||
1270 | if (!$show_full_profile) { |
||
1271 | $links .= '<li> |
||
1272 | <a class="btn-to-send-invitation" href="#" data-send-to="'.$user_id.'" title="'.get_lang('SendInvitation').'">'. |
||
1273 | Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')).' '.get_lang('SendInvitation'). |
||
1274 | '</a></li>'; |
||
1275 | } |
||
1276 | } |
||
1277 | |||
1278 | $links .= '</ul>'; |
||
1279 | $html .= Display::panelCollapse( |
||
1280 | get_lang('SocialNetwork'), |
||
1281 | $links, |
||
1282 | 'social-network-menu', |
||
1283 | null, |
||
1284 | 'sn-sidebar', |
||
1285 | 'sn-sidebar-collapse' |
||
1286 | ); |
||
1287 | |||
1288 | if ($show_full_profile && $user_id == api_get_user_id()) { |
||
1289 | // Announcements |
||
1290 | $announcements = []; |
||
1291 | $announcementsByCourse = AnnouncementManager::getAnnoucementCourseTotalByUser($user_id); |
||
1292 | if (!empty($announcementsByCourse)) { |
||
1293 | foreach ($announcementsByCourse as $announcement) { |
||
1294 | $url = Display::url( |
||
1295 | Display::return_icon( |
||
1296 | 'announcement.png', |
||
1297 | get_lang('Announcements') |
||
1298 | ).$announcement['course']['name'].' ('.$announcement['count'].')', |
||
1299 | api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$announcement['course']['code'] |
||
1300 | ); |
||
1301 | $announcements[] = Display::tag('li', $url); |
||
1302 | } |
||
1303 | } |
||
1304 | |||
1305 | if (!empty($announcements)) { |
||
1306 | $html .= '<div class="social_menu_items">'; |
||
1307 | $html .= '<ul>'; |
||
1308 | foreach ($announcements as $announcement) { |
||
1309 | $html .= $announcement; |
||
1310 | } |
||
1311 | $html .= '</ul>'; |
||
1312 | $html .= '</div>'; |
||
1313 | } |
||
1314 | } |
||
1315 | } |
||
1316 | |||
1317 | if ($show_delete_account_button) { |
||
1318 | $html .= '<div class="panel panel-default"><div class="panel-body">'; |
||
1319 | $html .= '<ul class="nav nav-pills nav-stacked"><li>'; |
||
1320 | $url = api_get_path(WEB_CODE_PATH).'auth/unsubscribe_account.php'; |
||
1321 | $html .= Display::url( |
||
1322 | Display::return_icon( |
||
1323 | 'delete.png', |
||
1324 | get_lang('Unsubscribe'), |
||
1325 | [], |
||
1326 | ICON_SIZE_TINY |
||
1327 | ).get_lang('Unsubscribe'), |
||
1328 | $url |
||
1329 | ); |
||
1330 | $html .= '</li></ul>'; |
||
1331 | $html .= '</div></div>'; |
||
1332 | } |
||
1333 | $html .= ''; |
||
1334 | |||
1335 | return $html; |
||
1336 | } |
||
1337 | |||
1338 | /** |
||
1339 | * Displays a sortable table with the list of online users. |
||
1340 | * |
||
1341 | * @param array $user_list The list of users to be shown |
||
1342 | * @param bool $wrap Whether we want the function to wrap the spans list in a div or not |
||
1343 | * |
||
1344 | * @return string HTML block or null if and ID was defined |
||
1345 | * @assert (null) === false |
||
1346 | */ |
||
1347 | public static function display_user_list($user_list, $wrap = true) |
||
1348 | { |
||
1349 | $html = ''; |
||
1350 | |||
1351 | if (isset($_GET['id']) || count($user_list) < 1) { |
||
1352 | return false; |
||
1353 | } |
||
1354 | |||
1355 | $course_url = ''; |
||
1356 | if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) { |
||
1357 | $course_url = '&cidReq='.Security::remove_XSS($_GET['cidReq']); |
||
1358 | } |
||
1359 | |||
1360 | $hide = api_get_configuration_value('hide_complete_name_in_whoisonline'); |
||
1361 | foreach ($user_list as $uid) { |
||
1362 | $user_info = api_get_user_info($uid, true); |
||
1363 | $lastname = $user_info['lastname']; |
||
1364 | $firstname = $user_info['firstname']; |
||
1365 | $completeName = $firstname.', '.$lastname; |
||
1366 | $user_rol = $user_info['status'] == 1 ? Display::return_icon('teacher.png', get_lang('Teacher'), null, ICON_SIZE_TINY) : Display::return_icon('user.png', get_lang('Student'), null, ICON_SIZE_TINY); |
||
1367 | $status_icon_chat = null; |
||
1368 | if (isset($user_info['user_is_online_in_chat']) && $user_info['user_is_online_in_chat'] == 1) { |
||
1369 | $status_icon_chat = Display::return_icon('online.png', get_lang('Online')); |
||
1370 | } else { |
||
1371 | $status_icon_chat = Display::return_icon('offline.png', get_lang('Offline')); |
||
1372 | } |
||
1373 | |||
1374 | $userPicture = $user_info['avatar']; |
||
1375 | $officialCode = ''; |
||
1376 | if (api_get_setting('show_official_code_whoisonline') == 'true') { |
||
1377 | $officialCode .= '<div class="items-user-official-code"><p style="min-height: 30px;" title="'.get_lang('OfficialCode').'">'.$user_info['official_code'].'</p></div>'; |
||
1378 | } |
||
1379 | |||
1380 | if ($hide === true) { |
||
1381 | $completeName = ''; |
||
1382 | $firstname = ''; |
||
1383 | $lastname = ''; |
||
1384 | } |
||
1385 | |||
1386 | $img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">'; |
||
1387 | |||
1388 | $url = null; |
||
1389 | // Anonymous users can't have access to the profile |
||
1390 | if (!api_is_anonymous()) { |
||
1391 | if (api_get_setting('allow_social_tool') === 'true') { |
||
1392 | $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url; |
||
1393 | } else { |
||
1394 | $url = '?id='.$uid.$course_url; |
||
1395 | } |
||
1396 | } else { |
||
1397 | $url = null; |
||
1398 | } |
||
1399 | $name = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>'; |
||
1400 | |||
1401 | $html .= '<div class="col-xs-6 col-md-2"> |
||
1402 | <div class="items-user"> |
||
1403 | <div class="items-user-avatar"><a href="'.$url.'">'.$img.'</a></div> |
||
1404 | <div class="items-user-name"> |
||
1405 | '.$name.' |
||
1406 | </div> |
||
1407 | '.$officialCode.' |
||
1408 | <div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div> |
||
1409 | </div> |
||
1410 | </div>'; |
||
1411 | } |
||
1412 | |||
1413 | return $html; |
||
1414 | } |
||
1415 | |||
1416 | /** |
||
1417 | * Displays the information of an individual user. |
||
1418 | * |
||
1419 | * @param int $user_id |
||
1420 | * |
||
1421 | * @return string |
||
1422 | */ |
||
1423 | public static function display_individual_user($user_id) |
||
1424 | { |
||
1425 | global $interbreadcrumb; |
||
1426 | $safe_user_id = (int) $user_id; |
||
1427 | $currentUserId = api_get_user_id(); |
||
1428 | |||
1429 | $user_table = Database::get_main_table(TABLE_MAIN_USER); |
||
1430 | $sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id; |
||
1431 | $result = Database::query($sql); |
||
1432 | $html = null; |
||
1433 | if (Database::num_rows($result) == 1) { |
||
1434 | $user_object = Database::fetch_object($result); |
||
1435 | $userInfo = api_get_user_info($user_id); |
||
1436 | $alt = $userInfo['complete_name'].($currentUserId == $user_id ? ' ('.get_lang('Me').')' : ''); |
||
1437 | $status = get_status_from_code($user_object->status); |
||
1438 | $interbreadcrumb[] = ['url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList')]; |
||
1439 | |||
1440 | $html .= '<div class ="thumbnail">'; |
||
1441 | $fullurl = $userInfo['avatar']; |
||
1442 | |||
1443 | $html .= '<img src="'.$fullurl.'" alt="'.$alt.'" />'; |
||
1444 | |||
1445 | if (!empty($status)) { |
||
1446 | $html .= '<div class="caption">'.$status.'</div>'; |
||
1447 | } |
||
1448 | $html .= '</div>'; |
||
1449 | |||
1450 | if (api_get_setting('show_email_addresses') == 'true') { |
||
1451 | $html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'<br />'; |
||
1452 | } |
||
1453 | // MY PERSONAL OPEN AREA |
||
1454 | if ($user_object->openarea) { |
||
1455 | $html .= Display::page_subheader(get_lang('MyPersonalOpenArea')); |
||
1456 | $html .= '<p>'.$user_object->openarea.'</p>'; |
||
1457 | } |
||
1458 | // MY COMPETENCES |
||
1459 | if ($user_object->competences) { |
||
1460 | $html .= Display::page_subheader(get_lang('MyCompetences')); |
||
1461 | $html .= '<p>'.$user_object->competences.'</p>'; |
||
1462 | } |
||
1463 | // MY DIPLOMAS |
||
1464 | if ($user_object->diplomas) { |
||
1465 | $html .= Display::page_subheader(get_lang('MyDiplomas')); |
||
1466 | $html .= '<p>'.$user_object->diplomas.'</p>'; |
||
1467 | } |
||
1468 | // WHAT I AM ABLE TO TEACH |
||
1469 | if ($user_object->teach) { |
||
1470 | $html .= Display::page_subheader(get_lang('MyTeach')); |
||
1471 | $html .= '<p>'.$user_object->teach.'</p>'; |
||
1472 | } |
||
1473 | // MY PRODUCTIONS |
||
1474 | self::display_productions($user_object->user_id); |
||
1475 | } else { |
||
1476 | $html .= '<div class="actions-title">'; |
||
1477 | $html .= get_lang('UsersOnLineList'); |
||
1478 | $html .= '</div>'; |
||
1479 | } |
||
1480 | |||
1481 | return $html; |
||
1482 | } |
||
1483 | |||
1484 | /** |
||
1485 | * Display productions in who is online. |
||
1486 | * |
||
1487 | * @param int $user_id User id |
||
1488 | */ |
||
1489 | public static function display_productions($user_id) |
||
1490 | { |
||
1491 | $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web'); |
||
1492 | $sysdir = UserManager::getUserPathById($user_id, 'system'); |
||
1493 | $webdir = UserManager::getUserPathById($user_id, 'web'); |
||
1494 | |||
1495 | if (!is_dir($sysdir)) { |
||
1496 | mkdir($sysdir, api_get_permissions_for_new_directories(), true); |
||
1497 | } |
||
1498 | |||
1499 | $productions = UserManager::get_user_productions($user_id); |
||
1500 | |||
1501 | if (count($productions) > 0) { |
||
1502 | echo '<dt><strong>'.get_lang('Productions').'</strong></dt>'; |
||
1503 | echo '<dd><ul>'; |
||
1504 | foreach ($productions as $file) { |
||
1505 | // Only display direct file links to avoid browsing an empty directory |
||
1506 | if (is_file($sysdir.$file) && $file != $webdir_array['file']) { |
||
1507 | echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>'; |
||
1508 | } |
||
1509 | // Real productions are under a subdirectory by the User's id |
||
1510 | if (is_dir($sysdir.$file)) { |
||
1511 | $subs = scandir($sysdir.$file); |
||
1512 | foreach ($subs as $my => $sub) { |
||
1513 | if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) { |
||
1514 | echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>'; |
||
1515 | } |
||
1516 | } |
||
1517 | } |
||
1518 | } |
||
1519 | echo '</ul></dd>'; |
||
1520 | } |
||
1521 | } |
||
1522 | |||
1523 | /** |
||
1524 | * @param string $content |
||
1525 | * @param string $span_count |
||
1526 | * |
||
1527 | * @return string |
||
1528 | */ |
||
1529 | public static function social_wrapper_div($content, $span_count) |
||
1530 | { |
||
1531 | $span_count = (int) $span_count; |
||
1532 | $html = '<div class="span'.$span_count.'">'; |
||
1533 | $html .= '<div class="well_border">'; |
||
1534 | $html .= $content; |
||
1535 | $html .= '</div></div>'; |
||
1536 | |||
1537 | return $html; |
||
1538 | } |
||
1539 | |||
1540 | /** |
||
1541 | * Dummy function. |
||
1542 | */ |
||
1543 | public static function get_plugins($place = SOCIAL_CENTER_PLUGIN) |
||
1544 | { |
||
1545 | $content = ''; |
||
1546 | switch ($place) { |
||
1547 | case SOCIAL_CENTER_PLUGIN: |
||
1548 | $social_plugins = [1, 2]; |
||
1549 | if (is_array($social_plugins) && count($social_plugins) > 0) { |
||
1550 | $content .= '<div id="social-plugins">'; |
||
1551 | foreach ($social_plugins as $plugin) { |
||
1552 | $content .= '<div class="social-plugin-item">'; |
||
1553 | $content .= $plugin; |
||
1554 | $content .= '</div>'; |
||
1555 | } |
||
1556 | $content .= '</div>'; |
||
1557 | } |
||
1558 | break; |
||
1559 | case SOCIAL_LEFT_PLUGIN: |
||
1560 | break; |
||
1561 | case SOCIAL_RIGHT_PLUGIN: |
||
1562 | break; |
||
1563 | } |
||
1564 | |||
1565 | return $content; |
||
1566 | } |
||
1567 | |||
1568 | /** |
||
1569 | * Sends a message to someone's wall. |
||
1570 | * |
||
1571 | * @param int $userId id of author |
||
1572 | * @param int $friendId id where we send the message |
||
1573 | * @param string $messageContent of the message |
||
1574 | * @param int $messageId id parent |
||
1575 | * @param string $messageStatus status type of message |
||
1576 | * |
||
1577 | * @return int |
||
1578 | * |
||
1579 | * @author Yannick Warnier |
||
1580 | */ |
||
1581 | public static function sendWallMessage( |
||
1582 | $userId, |
||
1583 | $friendId, |
||
1584 | $messageContent, |
||
1585 | $messageId = 0, |
||
1586 | $messageStatus = '' |
||
1587 | ) { |
||
1588 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
1589 | $userId = (int) $userId; |
||
1590 | $friendId = (int) $friendId; |
||
1591 | $messageId = (int) $messageId; |
||
1592 | |||
1593 | if (empty($userId) || empty($friendId)) { |
||
1594 | return 0; |
||
1595 | } |
||
1596 | |||
1597 | // Just in case we replace the and \n and \n\r while saving in the DB |
||
1598 | $messageContent = str_replace(["\n", "\n\r"], '<br />', $messageContent); |
||
1599 | $now = api_get_utc_datetime(); |
||
1600 | |||
1601 | $attributes = [ |
||
1602 | 'user_sender_id' => $userId, |
||
1603 | 'user_receiver_id' => $friendId, |
||
1604 | 'msg_status' => $messageStatus, |
||
1605 | 'send_date' => $now, |
||
1606 | 'title' => '', |
||
1607 | 'content' => $messageContent, |
||
1608 | 'parent_id' => $messageId, |
||
1609 | 'group_id' => 0, |
||
1610 | 'update_date' => $now, |
||
1611 | ]; |
||
1612 | |||
1613 | return Database::insert($tblMessage, $attributes); |
||
1614 | } |
||
1615 | |||
1616 | /** |
||
1617 | * Send File attachment (jpg,png). |
||
1618 | * |
||
1619 | * @author Anibal Copitan |
||
1620 | * |
||
1621 | * @param int $userId id user |
||
1622 | * @param array $fileAttach |
||
1623 | * @param int $messageId id message (relation with main message) |
||
1624 | * @param string $fileComment description attachment file |
||
1625 | * |
||
1626 | * @return bool|int |
||
1627 | */ |
||
1628 | public static function sendWallMessageAttachmentFile( |
||
1629 | $userId, |
||
1630 | $fileAttach, |
||
1631 | $messageId, |
||
1632 | $fileComment = '' |
||
1633 | ) { |
||
1634 | $safeFileName = Database::escape_string($fileAttach['name']); |
||
1635 | |||
1636 | $extension = strtolower(substr(strrchr($safeFileName, '.'), 1)); |
||
1637 | $allowedTypes = api_get_supported_image_extensions(); |
||
1638 | |||
1639 | $allowedTypes[] = 'mp4'; |
||
1640 | $allowedTypes[] = 'webm'; |
||
1641 | $allowedTypes[] = 'ogg'; |
||
1642 | |||
1643 | if (in_array($extension, $allowedTypes)) { |
||
1644 | return MessageManager::saveMessageAttachmentFile($fileAttach, $fileComment, $messageId, $userId); |
||
1645 | } |
||
1646 | |||
1647 | return false; |
||
1648 | } |
||
1649 | |||
1650 | /** |
||
1651 | * Gets all messages from someone's wall (within specific limits). |
||
1652 | * |
||
1653 | * @param int $userId id of wall shown |
||
1654 | * @param int|string $parentId id message (Post main) |
||
1655 | * @param int|array $groupId |
||
1656 | * @param int|array $friendId |
||
1657 | * @param string $startDate Date from which we want to show the messages, in UTC time |
||
1658 | * @param int $start Limit for the number of parent messages we want to show |
||
1659 | * @param int $length Wall message query offset |
||
1660 | * @param bool $getCount |
||
1661 | * @param array $threadList |
||
1662 | * |
||
1663 | * @return array|int |
||
1664 | * |
||
1665 | * @author Yannick Warnier |
||
1666 | */ |
||
1667 | public static function getWallMessages( |
||
1668 | $userId, |
||
1669 | $parentId = 0, |
||
1670 | $groupId = 0, |
||
1671 | $friendId = 0, |
||
1672 | $startDate = '', |
||
1673 | $start = 0, |
||
1674 | $length = 10, |
||
1675 | $getCount = false, |
||
1676 | $threadList = [] |
||
1677 | ) { |
||
1678 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
1679 | |||
1680 | $parentId = (int) $parentId; |
||
1681 | $userId = (int) $userId; |
||
1682 | $start = (int) $start; |
||
1683 | $length = (int) $length; |
||
1684 | |||
1685 | $select = " SELECT |
||
1686 | id, |
||
1687 | user_sender_id, |
||
1688 | user_receiver_id, |
||
1689 | send_date, |
||
1690 | content, |
||
1691 | parent_id, |
||
1692 | msg_status, |
||
1693 | group_id, |
||
1694 | '' as forum_id, |
||
1695 | '' as thread_id, |
||
1696 | '' as c_id |
||
1697 | "; |
||
1698 | |||
1699 | if ($getCount) { |
||
1700 | $select = ' SELECT count(id) as count_items '; |
||
1701 | } |
||
1702 | |||
1703 | $sqlBase = "$select FROM $tblMessage m WHERE "; |
||
1704 | $sql = []; |
||
1705 | $sql[1] = $sqlBase."msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND '; |
||
1706 | |||
1707 | // Get my own posts |
||
1708 | $userReceiverCondition = ' ( |
||
1709 | user_receiver_id = '.$userId.' AND |
||
1710 | msg_status IN ('.MESSAGE_STATUS_WALL_POST.', '.MESSAGE_STATUS_WALL.') AND |
||
1711 | parent_id = '.$parentId.' |
||
1712 | )'; |
||
1713 | |||
1714 | $sql[1] .= $userReceiverCondition; |
||
1715 | |||
1716 | $sql[2] = $sqlBase.' msg_status = '.MESSAGE_STATUS_PROMOTED.' '; |
||
1717 | |||
1718 | // Get my group posts |
||
1719 | $groupCondition = ''; |
||
1720 | if (!empty($groupId)) { |
||
1721 | if (is_array($groupId)) { |
||
1722 | $groupId = array_map('intval', $groupId); |
||
1723 | $groupId = implode(",", $groupId); |
||
1724 | $groupCondition = " ( group_id IN ($groupId) "; |
||
1725 | } else { |
||
1726 | $groupId = (int) $groupId; |
||
1727 | $groupCondition = " ( group_id = $groupId "; |
||
1728 | } |
||
1729 | $groupCondition .= ' AND (msg_status = '.MESSAGE_STATUS_NEW.' OR msg_status = '.MESSAGE_STATUS_UNREAD.')) '; |
||
1730 | } |
||
1731 | if (!empty($groupCondition)) { |
||
1732 | $sql[3] = $sqlBase.$groupCondition; |
||
1733 | } |
||
1734 | |||
1735 | // Get my friend posts |
||
1736 | $friendCondition = ''; |
||
1737 | if (!empty($friendId)) { |
||
1738 | if (is_array($friendId)) { |
||
1739 | $friendId = array_map('intval', $friendId); |
||
1740 | $friendId = implode(",", $friendId); |
||
1741 | $friendCondition = " ( user_receiver_id IN ($friendId) "; |
||
1742 | } else { |
||
1743 | $friendId = (int) $friendId; |
||
1744 | $friendCondition = " ( user_receiver_id = $friendId "; |
||
1745 | } |
||
1746 | $friendCondition .= ' AND msg_status = '.MESSAGE_STATUS_WALL_POST.' AND parent_id = 0) '; |
||
1747 | } |
||
1748 | if (!empty($friendCondition)) { |
||
1749 | $sql[4] = $sqlBase.$friendCondition; |
||
1750 | } |
||
1751 | |||
1752 | if (!empty($threadList)) { |
||
1753 | if ($getCount) { |
||
1754 | $select = ' SELECT count(iid) count_items '; |
||
1755 | } else { |
||
1756 | $select = " SELECT |
||
1757 | iid as id, |
||
1758 | poster_id as user_sender_id, |
||
1759 | '' as user_receiver_id, |
||
1760 | post_date as send_date, |
||
1761 | post_text as content, |
||
1762 | '' as parent_id, |
||
1763 | ".MESSAGE_STATUS_FORUM." as msg_status, |
||
1764 | '' as group_id, |
||
1765 | forum_id, |
||
1766 | thread_id, |
||
1767 | c_id |
||
1768 | "; |
||
1769 | } |
||
1770 | |||
1771 | $threadList = array_map('intval', $threadList); |
||
1772 | $threadList = implode("','", $threadList); |
||
1773 | $condition = " thread_id IN ('$threadList') "; |
||
1774 | $sql[5] = "$select |
||
1775 | FROM c_forum_post |
||
1776 | WHERE $condition |
||
1777 | "; |
||
1778 | } |
||
1779 | |||
1780 | if ($getCount) { |
||
1781 | $count = 0; |
||
1782 | foreach ($sql as $oneQuery) { |
||
1783 | if (!empty($oneQuery)) { |
||
1784 | $res = Database::query($oneQuery); |
||
1785 | $row = Database::fetch_array($res); |
||
1786 | $count += (int) $row['count_items']; |
||
1787 | } |
||
1788 | } |
||
1789 | |||
1790 | return $count; |
||
1791 | } |
||
1792 | |||
1793 | $sqlOrder = ' ORDER BY send_date DESC '; |
||
1794 | $sqlLimit = " LIMIT $start, $length "; |
||
1795 | $messages = []; |
||
1796 | foreach ($sql as $index => $oneQuery) { |
||
1797 | if ($index === 5) { |
||
1798 | // Exception only for the forum query above (field name change) |
||
1799 | $oneQuery .= ' ORDER BY post_date DESC '.$sqlLimit; |
||
1800 | } else { |
||
1801 | $oneQuery .= $sqlOrder.$sqlLimit; |
||
1802 | } |
||
1803 | $res = Database::query($oneQuery); |
||
1804 | $em = Database::getManager(); |
||
1805 | if (Database::num_rows($res) > 0) { |
||
1806 | $repo = $em->getRepository('ChamiloCourseBundle:CForumPost'); |
||
1807 | $repoThread = $em->getRepository('ChamiloCourseBundle:CForumThread'); |
||
1808 | $groups = []; |
||
1809 | $userGroup = new UserGroup(); |
||
1810 | $urlGroup = api_get_path(WEB_CODE_PATH).'social/group_view.php?id='; |
||
1811 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
1812 | $row['group_info'] = []; |
||
1813 | if (!empty($row['group_id'])) { |
||
1814 | if (!in_array($row['group_id'], $groups)) { |
||
1815 | $group = $userGroup->get($row['group_id']); |
||
1816 | $group['url'] = $urlGroup.$group['id']; |
||
1817 | $groups[$row['group_id']] = $group; |
||
1818 | $row['group_info'] = $group; |
||
1819 | } else { |
||
1820 | $row['group_info'] = $groups[$row['group_id']]; |
||
1821 | } |
||
1822 | } |
||
1823 | |||
1824 | // Forums |
||
1825 | $row['post_title'] = ''; |
||
1826 | $row['forum_title'] = ''; |
||
1827 | $row['thread_url'] = ''; |
||
1828 | if ($row['msg_status'] == MESSAGE_STATUS_FORUM) { |
||
1829 | /** @var CForumPost $post */ |
||
1830 | $post = $repo->find($row['id']); |
||
1831 | /** @var CForumThread $thread */ |
||
1832 | $thread = $repoThread->find($row['thread_id']); |
||
1833 | if ($post && $thread) { |
||
1834 | $courseInfo = api_get_course_info_by_id($post->getCId()); |
||
1835 | $row['post_title'] = $post->getForumId(); |
||
1836 | $row['forum_title'] = $thread->getThreadTitle(); |
||
1837 | $row['thread_url'] = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
||
1838 | 'cidReq' => $courseInfo['code'], |
||
1839 | 'forum' => $post->getForumId(), |
||
1840 | 'thread' => $post->getThreadId(), |
||
1841 | 'post_id' => $post->getIid(), |
||
1842 | ]).'#post_id_'.$post->getIid(); |
||
1843 | } |
||
1844 | } |
||
1845 | |||
1846 | $messages[$row['id']] = $row; |
||
1847 | } |
||
1848 | } |
||
1849 | } |
||
1850 | // Reordering messages by ID (reverse order) is enough to have the |
||
1851 | // latest first, as there is currently no option to edit messages |
||
1852 | // afterwards |
||
1853 | krsort($messages); |
||
1854 | |||
1855 | return $messages; |
||
1856 | } |
||
1857 | |||
1858 | /** |
||
1859 | * Gets all messages from someone's wall (within specific limits), formatted. |
||
1860 | * |
||
1861 | * @param int $userId USER ID of the person's wall |
||
1862 | * @param array $messageInfo |
||
1863 | * @param string $start Start date (from when we want the messages until today) |
||
1864 | * @param int $limit Limit to the number of messages we want |
||
1865 | * @param int $offset Wall messages offset |
||
1866 | * |
||
1867 | * @return string HTML formatted string to show messages |
||
1868 | */ |
||
1869 | public static function getWallPostComments( |
||
1870 | $userId, |
||
1871 | $messageInfo, |
||
1872 | $start = null, |
||
1873 | $limit = 10, |
||
1874 | $offset = 0 |
||
1875 | ) { |
||
1876 | $messageId = $messageInfo['id']; |
||
1877 | $messages = MessageManager::getMessagesByParent($messageInfo['id'], 0, $offset, $limit); |
||
1878 | $formattedList = '<div class="sub-mediapost row">'; |
||
1879 | $users = []; |
||
1880 | |||
1881 | // The messages are ordered by date descendant, for comments we need ascendant |
||
1882 | krsort($messages); |
||
1883 | foreach ($messages as $message) { |
||
1884 | $userIdLoop = $message['user_sender_id']; |
||
1885 | if (!isset($users[$userIdLoop])) { |
||
1886 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
1887 | } |
||
1888 | $media = self::processPostComment($message, $users); |
||
1889 | $formattedList .= $media; |
||
1890 | } |
||
1891 | |||
1892 | $formattedList .= '</div>'; |
||
1893 | $formattedList .= '<div class="mediapost-form row">'; |
||
1894 | $formattedList .= '<form class="form-horizontal" id="form_comment_'.$messageId.'" name="post_comment" method="POST"> |
||
1895 | <div class="col-sm-9"> |
||
1896 | <label for="comment" class="hide">'.get_lang('SocialWriteNewComment').'</label> |
||
1897 | <input type="hidden" name = "messageId" value="'.$messageId.'" /> |
||
1898 | <textarea rows="3" class="form-control" placeholder="'.get_lang('SocialWriteNewComment').'" name="comment" rows="1" ></textarea> |
||
1899 | </div> |
||
1900 | <div class="col-sm-3 pull-right"> |
||
1901 | <a onclick="submitComment('.$messageId.');" href="javascript:void(0);" name="social_wall_new_msg_submit" class="btn btn-default btn-post"> |
||
1902 | <em class="fa fa-pencil"></em> '.get_lang('Post').' |
||
1903 | </a> |
||
1904 | </div> |
||
1905 | </form>'; |
||
1906 | $formattedList .= '</div>'; |
||
1907 | |||
1908 | return $formattedList; |
||
1909 | } |
||
1910 | |||
1911 | /** |
||
1912 | * @param array $message |
||
1913 | * @param array $users |
||
1914 | * |
||
1915 | * @return string |
||
1916 | */ |
||
1917 | public static function processPostComment($message, $users = []) |
||
1918 | { |
||
1919 | if (empty($message)) { |
||
1920 | return false; |
||
1921 | } |
||
1922 | |||
1923 | $date = Display::dateToStringAgoAndLongDate($message['send_date']); |
||
1924 | $currentUserId = api_get_user_id(); |
||
1925 | $userIdLoop = $message['user_sender_id']; |
||
1926 | $receiverId = $message['user_receiver_id']; |
||
1927 | |||
1928 | if (!isset($users[$userIdLoop])) { |
||
1929 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
1930 | } |
||
1931 | |||
1932 | $iconStatus = $users[$userIdLoop]['icon_status']; |
||
1933 | $nameComplete = $users[$userIdLoop]['complete_name']; |
||
1934 | $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop; |
||
1935 | |||
1936 | $comment = '<div class="rep-post col-md-12">'; |
||
1937 | $comment .= '<div class="col-md-2 col-xs-2 social-post-answers">'; |
||
1938 | $comment .= '<div class="user-image pull-right">'; |
||
1939 | $comment .= '<a href="'.$url.'"> |
||
1940 | <img src="'.$users[$userIdLoop]['avatar'].'" |
||
1941 | alt="'.$users[$userIdLoop]['complete_name'].'" |
||
1942 | class="avatar-thumb"> |
||
1943 | </a>'; |
||
1944 | $comment .= '</div>'; |
||
1945 | $comment .= '</div>'; |
||
1946 | $comment .= '<div class="col-md-7 col-xs-7 social-post-answers">'; |
||
1947 | $comment .= '<div class="user-data">'; |
||
1948 | $comment .= $iconStatus; |
||
1949 | $comment .= '<div class="username"><a href="'.$url.'">'.$nameComplete.'</a> |
||
1950 | <span>'.Security::remove_XSS($message['content']).'</span> |
||
1951 | </div>'; |
||
1952 | $comment .= '<div>'.$date.'</div>'; |
||
1953 | $comment .= '<br />'; |
||
1954 | $comment .= '</div>'; |
||
1955 | $comment .= '</div>'; |
||
1956 | |||
1957 | $comment .= '<div class="col-md-3 col-xs-3 social-post-answers">'; |
||
1958 | $comment .= '<div class="pull-right btn-group btn-group-sm">'; |
||
1959 | |||
1960 | $comment .= MessageManager::getLikesButton( |
||
1961 | $message['id'], |
||
1962 | $currentUserId |
||
1963 | ); |
||
1964 | |||
1965 | $isOwnWall = $currentUserId == $userIdLoop || $currentUserId == $receiverId; |
||
1966 | if ($isOwnWall) { |
||
1967 | $comment .= Display::button( |
||
1968 | '', |
||
1969 | Display::returnFontAwesomeIcon('trash', '', true), |
||
1970 | [ |
||
1971 | 'id' => 'message_'.$message['id'], |
||
1972 | 'title' => get_lang('SocialMessageDelete'), |
||
1973 | 'type' => 'button', |
||
1974 | 'class' => 'btn btn-default btn-delete-social-comment', |
||
1975 | 'data-id' => $message['id'], |
||
1976 | 'data-sectoken' => Security::get_existing_token('social'), |
||
1977 | ] |
||
1978 | ); |
||
1979 | } |
||
1980 | $comment .= '</div>'; |
||
1981 | $comment .= '</div>'; |
||
1982 | $comment .= '</div>'; |
||
1983 | |||
1984 | return $comment; |
||
1985 | } |
||
1986 | |||
1987 | /** |
||
1988 | * @param array $message |
||
1989 | * |
||
1990 | * @return array |
||
1991 | */ |
||
1992 | public static function getAttachmentPreviewList($message) |
||
1993 | { |
||
1994 | $messageId = $message['id']; |
||
1995 | |||
1996 | $list = []; |
||
1997 | |||
1998 | if (empty($message['group_id'])) { |
||
1999 | $files = MessageManager::getAttachmentList($messageId); |
||
2000 | if ($files) { |
||
2001 | $downloadUrl = api_get_path(WEB_CODE_PATH).'social/download.php?message_id='.$messageId; |
||
2002 | foreach ($files as $row_file) { |
||
2003 | $url = $downloadUrl.'&attachment_id='.$row_file['id']; |
||
2004 | $display = Display::fileHtmlGuesser($row_file['filename'], $url); |
||
2005 | $list[] = $display; |
||
2006 | } |
||
2007 | } |
||
2008 | } else { |
||
2009 | $list = MessageManager::getAttachmentLinkList($messageId, 0); |
||
2010 | } |
||
2011 | |||
2012 | return $list; |
||
2013 | } |
||
2014 | |||
2015 | /** |
||
2016 | * @param array $message |
||
2017 | * |
||
2018 | * @return string |
||
2019 | */ |
||
2020 | public static function getPostAttachment($message) |
||
2021 | { |
||
2022 | $previews = self::getAttachmentPreviewList($message); |
||
2023 | |||
2024 | if (empty($previews)) { |
||
2025 | return ''; |
||
2026 | } |
||
2027 | |||
2028 | return implode('', $previews); |
||
2029 | } |
||
2030 | |||
2031 | /** |
||
2032 | * @param array $messages |
||
2033 | * |
||
2034 | * @return array |
||
2035 | */ |
||
2036 | public static function formatWallMessages($messages) |
||
2037 | { |
||
2038 | $data = []; |
||
2039 | $users = []; |
||
2040 | foreach ($messages as $key => $message) { |
||
2041 | $userIdLoop = $message['user_sender_id']; |
||
2042 | $userFriendIdLoop = $message['user_receiver_id']; |
||
2043 | if (!isset($users[$userIdLoop])) { |
||
2044 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
2045 | } |
||
2046 | |||
2047 | if (!isset($users[$userFriendIdLoop])) { |
||
2048 | $users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop); |
||
2049 | } |
||
2050 | |||
2051 | $html = self::headerMessagePost( |
||
2052 | $users[$userIdLoop], |
||
2053 | $users[$userFriendIdLoop], |
||
2054 | $message |
||
2055 | ); |
||
2056 | |||
2057 | $data[$key] = $message; |
||
2058 | $data[$key]['html'] = $html; |
||
2059 | } |
||
2060 | |||
2061 | return $data; |
||
2062 | } |
||
2063 | |||
2064 | /** |
||
2065 | * get html data with OpenGrap passing the URL. |
||
2066 | */ |
||
2067 | public static function readContentWithOpenGraph(string $link): string |
||
2068 | { |
||
2069 | if (strpos($link, "://") === false && substr($link, 0, 1) != "/") { |
||
2070 | $link = "http://".$link; |
||
2071 | } |
||
2072 | $graph = OpenGraph::fetch($link); |
||
2073 | $link = parse_url($link); |
||
2074 | $host = $link['host'] ? strtoupper($link['host']) : $link['path']; |
||
2075 | if (!$graph) { |
||
2076 | return false; |
||
2077 | } |
||
2078 | $url = $graph->url; |
||
2079 | $image = $graph->image; |
||
2080 | $description = $graph->description; |
||
2081 | $title = $graph->title; |
||
2082 | $html = '<div class="thumbnail social-thumbnail">'; |
||
2083 | $html .= empty($image) ? '' : '<a target="_blank" href="'.$url.'"> |
||
2084 | <img class="img-responsive social-image" src="'.$image.'" /></a>'; |
||
2085 | $html .= '<div class="social-description">'; |
||
2086 | $html .= '<a target="_blank" href="'.$url.'"><h5 class="social-title"><b>'.$title.'</b></h5></a>'; |
||
2087 | $html .= empty($description) ? '' : '<span>'.$description.'</span>'; |
||
2088 | $html .= empty($host) ? '' : '<p>'.$host.'</p>'; |
||
2089 | $html .= '</div>'; |
||
2090 | $html .= '</div>'; |
||
2091 | |||
2092 | return $html; |
||
2093 | } |
||
2094 | |||
2095 | /** |
||
2096 | * verify if Url Exist - Using Curl. |
||
2097 | */ |
||
2098 | public static function verifyUrl(string $uri): bool |
||
2099 | { |
||
2100 | $client = new Client(); |
||
2101 | |||
2102 | try { |
||
2103 | $response = $client->request('GET', $uri, [ |
||
2104 | 'timeout' => 15, |
||
2105 | 'verify' => false, |
||
2106 | 'headers' => [ |
||
2107 | 'User-Agent' => $_SERVER['HTTP_USER_AGENT'], |
||
2108 | ], |
||
2109 | ]); |
||
2110 | |||
2111 | if (200 !== $response->getStatusCode()) { |
||
2112 | return false; |
||
2113 | } |
||
2114 | |||
2115 | return true; |
||
2116 | } catch (Exception $e) { |
||
2117 | return false; |
||
2118 | } |
||
2119 | } |
||
2120 | |||
2121 | /** |
||
2122 | * Soft delete a message and his chidren. |
||
2123 | * |
||
2124 | * @param int $id id message to delete |
||
2125 | * |
||
2126 | * @throws Exception if file cannot be deleted in delete_message_attachment_file() |
||
2127 | * |
||
2128 | * @return bool status query |
||
2129 | */ |
||
2130 | public static function deleteMessage($id) |
||
2131 | { |
||
2132 | $id = (int) $id; |
||
2133 | $messageInfo = MessageManager::get_message_by_id($id); |
||
2134 | if (!empty($messageInfo)) { |
||
2135 | // Delete comments too |
||
2136 | $messages = MessageManager::getMessagesByParent($id); |
||
2137 | if (!empty($messages)) { |
||
2138 | foreach ($messages as $message) { |
||
2139 | self::deleteMessage($message['id']); |
||
2140 | } |
||
2141 | } |
||
2142 | |||
2143 | // Soft delete message |
||
2144 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
2145 | $statusMessage = MESSAGE_STATUS_WALL_DELETE; |
||
2146 | $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' "; |
||
2147 | Database::query($sql); |
||
2148 | |||
2149 | MessageManager::delete_message_attachment_file($id, $messageInfo['user_sender_id']); |
||
2150 | MessageManager::delete_message_attachment_file($id, $messageInfo['user_receiver_id']); |
||
2151 | |||
2152 | return true; |
||
2153 | } |
||
2154 | |||
2155 | return false; |
||
2156 | } |
||
2157 | |||
2158 | /** |
||
2159 | * Generate the social block for a user. |
||
2160 | * |
||
2161 | * @param int $userId The user id |
||
2162 | * @param string $groupBlock Optional. Highlight link possible values: |
||
2163 | * group_add, home, messages, messages_inbox, messages_compose, |
||
2164 | * messages_outbox, invitations, shared_profile, friends, groups, search |
||
2165 | * @param int $groupId Optional. Group ID |
||
2166 | * @param bool $show_full_profile |
||
2167 | * |
||
2168 | * @return string The HTML code with the social block |
||
2169 | */ |
||
2170 | public static function setSocialUserBlock( |
||
2171 | Template $template, |
||
2172 | $userId, |
||
2173 | $groupBlock = '', |
||
2174 | $groupId = 0, |
||
2175 | $show_full_profile = true |
||
2176 | ) { |
||
2177 | if (api_get_setting('allow_social_tool') !== 'true') { |
||
2178 | return ''; |
||
2179 | } |
||
2180 | |||
2181 | $currentUserId = api_get_user_id(); |
||
2182 | $userId = (int) $userId; |
||
2183 | $userRelationType = 0; |
||
2184 | |||
2185 | $socialAvatarBlock = self::show_social_avatar_block( |
||
2186 | $groupBlock, |
||
2187 | $groupId, |
||
2188 | $userId |
||
2189 | ); |
||
2190 | |||
2191 | $profileEditionLink = null; |
||
2192 | if ($currentUserId === $userId) { |
||
2193 | $profileEditionLink = Display::getProfileEditionLink($userId); |
||
2194 | } else { |
||
2195 | $userRelationType = self::get_relation_between_contacts($currentUserId, $userId); |
||
2196 | } |
||
2197 | |||
2198 | $options = api_get_configuration_value('profile_fields_visibility'); |
||
2199 | if (isset($options['options'])) { |
||
2200 | $options = $options['options']; |
||
2201 | } |
||
2202 | |||
2203 | $vCardUserLink = Display::getVCardUserLink($userId); |
||
2204 | if (isset($options['vcard']) && $options['vcard'] === false) { |
||
2205 | $vCardUserLink = ''; |
||
2206 | } |
||
2207 | |||
2208 | $userInfo = api_get_user_info($userId, true, false, true, true); |
||
2209 | |||
2210 | if (isset($options['firstname']) && $options['firstname'] === false) { |
||
2211 | $userInfo['firstname'] = ''; |
||
2212 | } |
||
2213 | if (isset($options['lastname']) && $options['lastname'] === false) { |
||
2214 | $userInfo['lastname'] = ''; |
||
2215 | } |
||
2216 | |||
2217 | if (isset($options['email']) && $options['email'] === false) { |
||
2218 | $userInfo['email'] = ''; |
||
2219 | } |
||
2220 | |||
2221 | // Ofaj |
||
2222 | $hasCertificates = Certificate::getCertificateByUser($userId); |
||
2223 | $userInfo['has_certificates'] = 0; |
||
2224 | if (!empty($hasCertificates)) { |
||
2225 | $userInfo['has_certificates'] = 1; |
||
2226 | } |
||
2227 | |||
2228 | $userInfo['is_admin'] = UserManager::is_admin($userId); |
||
2229 | |||
2230 | $languageId = api_get_language_id($userInfo['language']); |
||
2231 | $languageInfo = api_get_language_info($languageId); |
||
2232 | if ($languageInfo) { |
||
2233 | $userInfo['language'] = [ |
||
2234 | 'label' => $languageInfo['original_name'], |
||
2235 | 'value' => $languageInfo['english_name'], |
||
2236 | 'code' => $languageInfo['isocode'], |
||
2237 | ]; |
||
2238 | } |
||
2239 | |||
2240 | if (isset($options['language']) && $options['language'] === false) { |
||
2241 | $userInfo['language'] = ''; |
||
2242 | } |
||
2243 | |||
2244 | if (isset($options['photo']) && $options['photo'] === false) { |
||
2245 | $socialAvatarBlock = ''; |
||
2246 | } |
||
2247 | |||
2248 | $extraFieldBlock = self::getExtraFieldBlock($userId, true); |
||
2249 | $showLanguageFlag = api_get_configuration_value('social_show_language_flag_in_profile'); |
||
2250 | |||
2251 | $template->assign('user', $userInfo); |
||
2252 | $template->assign('show_language_flag', $showLanguageFlag); |
||
2253 | $template->assign('extra_info', $extraFieldBlock); |
||
2254 | $template->assign('social_avatar_block', $socialAvatarBlock); |
||
2255 | $template->assign('profile_edition_link', $profileEditionLink); |
||
2256 | //Added the link to export the vCard to the Template |
||
2257 | |||
2258 | //If not friend $show_full_profile is False and the user can't see Email Address and Vcard Download Link |
||
2259 | if ($show_full_profile) { |
||
2260 | $template->assign('vcard_user_link', $vCardUserLink); |
||
2261 | } |
||
2262 | |||
2263 | if (api_get_setting('gamification_mode') === '1') { |
||
2264 | $gamificationPoints = GamificationUtils::getTotalUserPoints( |
||
2265 | $userId, |
||
2266 | $userInfo['status'] |
||
2267 | ); |
||
2268 | |||
2269 | $template->assign('gamification_points', $gamificationPoints); |
||
2270 | } |
||
2271 | $chatEnabled = api_is_global_chat_enabled(); |
||
2272 | |||
2273 | if (isset($options['chat']) && $options['chat'] === false) { |
||
2274 | $chatEnabled = ''; |
||
2275 | } |
||
2276 | |||
2277 | $template->assign('chat_enabled', $chatEnabled); |
||
2278 | $template->assign('user_relation', $userRelationType); |
||
2279 | $template->assign('user_relation_type_friend', USER_RELATION_TYPE_FRIEND); |
||
2280 | $template->assign('show_full_profile', $show_full_profile); |
||
2281 | |||
2282 | $templateName = $template->get_template('social/user_block.tpl'); |
||
2283 | |||
2284 | if (in_array($groupBlock, ['groups', 'group_edit', 'member_list'])) { |
||
2285 | $templateName = $template->get_template('social/group_block.tpl'); |
||
2286 | } |
||
2287 | |||
2288 | $template->assign('social_avatar_block', $template->fetch($templateName)); |
||
2289 | } |
||
2290 | |||
2291 | /** |
||
2292 | * @param int $user_id |
||
2293 | * @param $link_shared |
||
2294 | * @param bool $showLinkToChat |
||
2295 | * |
||
2296 | * @return string |
||
2297 | */ |
||
2298 | public static function listMyFriendsBlock($user_id, $link_shared = '', $showLinkToChat = false) |
||
2299 | { |
||
2300 | //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT |
||
2301 | $friends = self::get_friends($user_id, USER_RELATION_TYPE_FRIEND); |
||
2302 | $numberFriends = count($friends); |
||
2303 | $friendHtml = ''; |
||
2304 | |||
2305 | if (!empty($numberFriends)) { |
||
2306 | $friendHtml .= '<div class="list-group contact-list">'; |
||
2307 | $j = 1; |
||
2308 | |||
2309 | usort( |
||
2310 | $friends, |
||
2311 | function ($a, $b) { |
||
2312 | return strcmp($b['user_info']['user_is_online_in_chat'], $a['user_info']['user_is_online_in_chat']); |
||
2313 | } |
||
2314 | ); |
||
2315 | |||
2316 | foreach ($friends as $friend) { |
||
2317 | if ($j > $numberFriends) { |
||
2318 | break; |
||
2319 | } |
||
2320 | $name_user = api_get_person_name($friend['firstName'], $friend['lastName']); |
||
2321 | $user_info_friend = api_get_user_info($friend['friend_user_id'], true); |
||
2322 | |||
2323 | $statusIcon = Display::return_icon('statusoffline.png', get_lang('Offline')); |
||
2324 | $status = 0; |
||
2325 | if (!empty($user_info_friend['user_is_online_in_chat'])) { |
||
2326 | $statusIcon = Display::return_icon('statusonline.png', get_lang('Online')); |
||
2327 | $status = 1; |
||
2328 | } |
||
2329 | |||
2330 | $friendAvatarMedium = UserManager::getUserPicture( |
||
2331 | $friend['friend_user_id'], |
||
2332 | USER_IMAGE_SIZE_MEDIUM |
||
2333 | ); |
||
2334 | $friendAvatarSmall = UserManager::getUserPicture( |
||
2335 | $friend['friend_user_id'], |
||
2336 | USER_IMAGE_SIZE_SMALL |
||
2337 | ); |
||
2338 | $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>'; |
||
2339 | |||
2340 | $relation = self::get_relation_between_contacts( |
||
2341 | $friend['friend_user_id'], |
||
2342 | api_get_user_id() |
||
2343 | ); |
||
2344 | |||
2345 | if ($showLinkToChat) { |
||
2346 | $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">'; |
||
2347 | $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
||
2348 | $friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
||
2349 | } else { |
||
2350 | $link_shared = empty($link_shared) ? '' : '&'.$link_shared; |
||
2351 | $friendHtml .= '<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'" class="list-group-item">'; |
||
2352 | $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
||
2353 | $friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
||
2354 | } |
||
2355 | |||
2356 | $friendHtml .= '</a>'; |
||
2357 | |||
2358 | $j++; |
||
2359 | } |
||
2360 | $friendHtml .= '</div>'; |
||
2361 | } else { |
||
2362 | $friendHtml = Display::return_message(get_lang('NoFriendsInYourContactList'), 'warning'); |
||
2363 | } |
||
2364 | |||
2365 | return $friendHtml; |
||
2366 | } |
||
2367 | |||
2368 | /** |
||
2369 | * @return string Get the JS code necessary for social wall to load open graph from URLs. |
||
2370 | */ |
||
2371 | public static function getScriptToGetOpenGraph(): string |
||
2372 | { |
||
2373 | return '<script> |
||
2374 | $(function() { |
||
2375 | $("[name=\'social_wall_new_msg_main\']").on("paste", function(e) { |
||
2376 | $.ajax({ |
||
2377 | contentType: "application/x-www-form-urlencoded", |
||
2378 | beforeSend: function() { |
||
2379 | $("[name=\'wall_post_button\']").prop( "disabled", true ); |
||
2380 | $(".panel-preview").hide(); |
||
2381 | $(".spinner").html("' |
||
2382 | .'<div class=\'text-center\'>' |
||
2383 | .'<em class=\'fa fa-spinner fa-pulse fa-1x\'></em>' |
||
2384 | .'<p>'.get_lang('Loading').' '.get_lang('Preview').'</p>' |
||
2385 | .'</div>' |
||
2386 | .'"); |
||
2387 | }, |
||
2388 | type: "POST", |
||
2389 | url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=read_url_with_open_graph", |
||
2390 | data: "social_wall_new_msg_main=" + e.originalEvent.clipboardData.getData("text"), |
||
2391 | success: function(response) { |
||
2392 | $("[name=\'wall_post_button\']").prop("disabled", false); |
||
2393 | if (!response == false) { |
||
2394 | $(".spinner").html(""); |
||
2395 | $(".panel-preview").show(); |
||
2396 | $(".url_preview").html(response); |
||
2397 | $("[name=\'url_content\']").val(response); |
||
2398 | $(".url_preview img").addClass("img-responsive"); |
||
2399 | } else { |
||
2400 | $(".spinner").html(""); |
||
2401 | } |
||
2402 | } |
||
2403 | }); |
||
2404 | }); |
||
2405 | }); |
||
2406 | </script>'; |
||
2407 | } |
||
2408 | |||
2409 | public static function displayWallForm(string $urlForm): string |
||
2410 | { |
||
2411 | $form = self::getWallForm($urlForm); |
||
2412 | |||
2413 | return Display::panel($form->returnForm(), get_lang('SocialWall')); |
||
2414 | } |
||
2415 | |||
2416 | /** |
||
2417 | * Show middle section for Portfolio extended. |
||
2418 | * Must be active on main/admin/settings.php?category=User into extended_profile. |
||
2419 | * |
||
2420 | * @param string $urlForm |
||
2421 | * |
||
2422 | * @return string |
||
2423 | */ |
||
2424 | public static function getWallFormPortfolio($urlForm) |
||
2425 | { |
||
2426 | $userId = isset($_GET['u']) ? (int) $_GET['u'] : 0; |
||
2427 | $userId = $userId !== 0 ? $userId : api_get_user_id(); |
||
2428 | $user_info = api_get_user_info($userId); |
||
2429 | $friend = true; |
||
2430 | $editPorfolioLink = ''; |
||
2431 | if ($userId != api_get_user_id()) { |
||
2432 | $friend = self::get_relation_between_contacts(api_get_user_id(), $userId); |
||
2433 | } else { |
||
2434 | $editPorfolioLink .= "<div class=\"pull-right\" style='margin-top: -5px'>". |
||
2435 | '<a href="/main/auth/profile.php?type=extended#openarea" class="btn btn-default btn-sm btn-social-edit">'. |
||
2436 | "<i class=\"fa fa-pencil\" aria-hidden=\"true\"></i>". |
||
2437 | '</a>'. |
||
2438 | "</div>"; |
||
2439 | } |
||
2440 | if ($friend == 0) { |
||
2441 | /* if has not relation, get current user */ |
||
2442 | $userId = api_get_user_id(); |
||
2443 | $user_info = api_get_user_info($userId); |
||
2444 | } |
||
2445 | // Images uploaded by course |
||
2446 | $more_info = ''; |
||
2447 | |||
2448 | // Productions |
||
2449 | $production_list = UserManager::build_production_list($userId); |
||
2450 | |||
2451 | $form = new FormValidator( |
||
2452 | 'social_wall_main', |
||
2453 | 'post', |
||
2454 | $urlForm.$userId, |
||
2455 | null, |
||
2456 | ['enctype' => 'multipart/form-data'], |
||
2457 | FormValidator::LAYOUT_HORIZONTAL |
||
2458 | ); |
||
2459 | |||
2460 | $socialWallPlaceholder = isset($_GET['u']) ? get_lang('SocialWallWriteNewPostToFriend') : get_lang( |
||
2461 | 'SocialWallWhatAreYouThinkingAbout' |
||
2462 | ); |
||
2463 | |||
2464 | if (!empty($user_info['competences']) || !empty($user_info['diplomas']) |
||
2465 | || !empty($user_info['openarea']) || !empty($user_info['teach'])) { |
||
2466 | // $more_info .= '<div><h3>'.get_lang('MoreInformation').'</h3></div>'; |
||
2467 | // MY PERSONAL OPEN AREA |
||
2468 | if (!empty($user_info['openarea'])) { |
||
2469 | $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyPersonalOpenArea').'</strong></div>'; |
||
2470 | $more_info .= '<div class="social-profile-extended">'.$user_info['openarea'].'</div>'; |
||
2471 | $more_info .= '<br />'; |
||
2472 | } |
||
2473 | // MY COMPETENCES |
||
2474 | if (!empty($user_info['competences'])) { |
||
2475 | $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyCompetences').'</strong></div>'; |
||
2476 | $more_info .= '<div class="social-profile-extended">'.$user_info['competences'].'</div>'; |
||
2477 | $more_info .= '<br />'; |
||
2478 | } |
||
2479 | // MY DIPLOMAS |
||
2480 | if (!empty($user_info['diplomas'])) { |
||
2481 | $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyDiplomas').'</strong></div>'; |
||
2482 | $more_info .= '<div class="social-profile-extended">'.$user_info['diplomas'].'</div>'; |
||
2483 | $more_info .= '<br />'; |
||
2484 | } |
||
2485 | // MY PRODUCTIONS |
||
2486 | if (!empty($production_list)) { |
||
2487 | $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyProductions').'</strong></div>'; |
||
2488 | $more_info .= '<div class="social-profile-extended">'.$production_list.'</div>'; |
||
2489 | $more_info .= '<br />'; |
||
2490 | } |
||
2491 | // WHAT I AM ABLE TO TEACH |
||
2492 | if (!empty($user_info['teach'])) { |
||
2493 | $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyTeach').'</strong></div>'; |
||
2494 | $more_info .= '<div class="social-profile-extended">'.$user_info['teach'].'</div>'; |
||
2495 | $more_info .= '<br />'; |
||
2496 | } |
||
2497 | } |
||
2498 | |||
2499 | $form->addTextarea( |
||
2500 | 'social_wall_new_msg_main', |
||
2501 | null, |
||
2502 | [ |
||
2503 | 'placeholder' => $socialWallPlaceholder, |
||
2504 | 'cols-size' => [1, 12, 1], |
||
2505 | 'aria-label' => $socialWallPlaceholder, |
||
2506 | ] |
||
2507 | ); |
||
2508 | $form->addHtml('<div class="form-group">'); |
||
2509 | $form->addHtml('<div class="col-sm-6">'); |
||
2510 | $form->addFile('picture', get_lang('UploadFile'), ['custom' => true]); |
||
2511 | $form->addHtml('</div>'); |
||
2512 | $form->addHtml('<div class="col-sm-6 "><div class="pull-right">'); |
||
2513 | $form->addButtonSend( |
||
2514 | get_lang('Post'), |
||
2515 | 'wall_post_button', |
||
2516 | false, |
||
2517 | [ |
||
2518 | 'cols-size' => [1, 10, 1], |
||
2519 | 'custom' => true, |
||
2520 | ] |
||
2521 | ); |
||
2522 | $form->addHtml('</div></div>'); |
||
2523 | $form->addHtml('</div>'); |
||
2524 | $form->addHidden('url_content', ''); |
||
2525 | |||
2526 | return Display::panel($more_info, get_lang('Portfolio').$editPorfolioLink); |
||
2527 | } |
||
2528 | |||
2529 | /** |
||
2530 | * @param int $userId |
||
2531 | * @param int $start |
||
2532 | * @param int $length |
||
2533 | * @param array $threadList |
||
2534 | * |
||
2535 | * @return array |
||
2536 | */ |
||
2537 | public static function getMyWallMessages($userId, $start = 0, $length = 10, $threadList = []) |
||
2538 | { |
||
2539 | $userGroup = new UserGroup(); |
||
2540 | $groups = $userGroup->get_groups_by_user($userId, [GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_ADMIN]); |
||
2541 | $groupList = []; |
||
2542 | if (!empty($groups)) { |
||
2543 | $groupList = array_column($groups, 'id'); |
||
2544 | } |
||
2545 | |||
2546 | $friends = self::get_friends($userId, USER_RELATION_TYPE_FRIEND); |
||
2547 | $friendList = []; |
||
2548 | if (!empty($friends)) { |
||
2549 | $friendList = array_column($friends, 'friend_user_id'); |
||
2550 | } |
||
2551 | |||
2552 | $messages = self::getWallMessages( |
||
2553 | $userId, |
||
2554 | 0, |
||
2555 | $groupList, |
||
2556 | $friendList, |
||
2557 | '', |
||
2558 | $start, |
||
2559 | $length, |
||
2560 | false, |
||
2561 | $threadList |
||
2562 | ); |
||
2563 | |||
2564 | $countPost = self::getCountWallMessagesByUser($userId, $groupList, $friendList, $threadList); |
||
2565 | $messages = self::formatWallMessages($messages); |
||
2566 | |||
2567 | $html = ''; |
||
2568 | foreach ($messages as $message) { |
||
2569 | $post = $message['html']; |
||
2570 | $comments = ''; |
||
2571 | if (in_array($message['msg_status'], [MESSAGE_STATUS_WALL_POST, MESSAGE_STATUS_PROMOTED])) { |
||
2572 | $comments = self::getWallPostComments($userId, $message); |
||
2573 | } |
||
2574 | |||
2575 | $html .= self::wrapPost($message, $post.$comments); |
||
2576 | } |
||
2577 | |||
2578 | return [ |
||
2579 | 'posts' => $html, |
||
2580 | 'count' => $countPost, |
||
2581 | ]; |
||
2582 | } |
||
2583 | |||
2584 | /** |
||
2585 | * @param string $message |
||
2586 | * @param string $content |
||
2587 | * |
||
2588 | * @return string |
||
2589 | */ |
||
2590 | public static function wrapPost($message, $content) |
||
2591 | { |
||
2592 | $class = ''; |
||
2593 | if ($message['msg_status'] === MESSAGE_STATUS_PROMOTED) { |
||
2594 | $class = 'promoted_post'; |
||
2595 | } |
||
2596 | |||
2597 | return Display::panel($content, '', |
||
2598 | '', |
||
2599 | 'default', |
||
2600 | '', |
||
2601 | 'post_'.$message['id'], |
||
2602 | null, |
||
2603 | $class |
||
2604 | ); |
||
2605 | } |
||
2606 | |||
2607 | /** |
||
2608 | * @param int $userId |
||
2609 | * @param array $groupList |
||
2610 | * @param array $friendList |
||
2611 | * @param array $threadList |
||
2612 | * |
||
2613 | * @return int |
||
2614 | */ |
||
2615 | public static function getCountWallMessagesByUser($userId, $groupList = [], $friendList = [], $threadList = []) |
||
2616 | { |
||
2617 | return self::getWallMessages( |
||
2618 | $userId, |
||
2619 | 0, |
||
2620 | $groupList, |
||
2621 | $friendList, |
||
2622 | '', |
||
2623 | 0, |
||
2624 | 0, |
||
2625 | true, |
||
2626 | $threadList |
||
2627 | ); |
||
2628 | } |
||
2629 | |||
2630 | /** |
||
2631 | * @param int $userId |
||
2632 | * |
||
2633 | * @return string |
||
2634 | */ |
||
2635 | public static function getWallMessagesByUser($userId) |
||
2636 | { |
||
2637 | $messages = self::getWallMessages($userId); |
||
2638 | $messages = self::formatWallMessages($messages); |
||
2639 | |||
2640 | $html = ''; |
||
2641 | foreach ($messages as $message) { |
||
2642 | $post = $message['html']; |
||
2643 | $comments = self::getWallPostComments($userId, $message); |
||
2644 | $html .= self::wrapPost($message, $post.$comments); |
||
2645 | } |
||
2646 | |||
2647 | return $html; |
||
2648 | } |
||
2649 | |||
2650 | /** |
||
2651 | * Get HTML code block for user skills. |
||
2652 | * |
||
2653 | * @param int $userId The user ID |
||
2654 | * @param string $orientation |
||
2655 | * |
||
2656 | * @return string |
||
2657 | */ |
||
2658 | public static function getSkillBlock($userId, $orientation = 'horizontal') |
||
2659 | { |
||
2660 | if (Skill::isAllowed($userId, false) === false) { |
||
2661 | return ''; |
||
2662 | } |
||
2663 | |||
2664 | $skill = new Skill(); |
||
2665 | $ranking = $skill->getUserSkillRanking($userId); |
||
2666 | |||
2667 | $template = new Template(null, false, false, false, false, false); |
||
2668 | $template->assign('ranking', $ranking); |
||
2669 | $template->assign('orientation', $orientation); |
||
2670 | $template->assign('skills', $skill->getUserSkillsTable($userId, 0, 0, false)['skills']); |
||
2671 | $template->assign('user_id', $userId); |
||
2672 | $template->assign('show_skills_report_link', api_is_student() || api_is_student_boss() || api_is_drh()); |
||
2673 | |||
2674 | $skillBlock = $template->get_template('social/skills_block.tpl'); |
||
2675 | |||
2676 | return $template->fetch($skillBlock); |
||
2677 | } |
||
2678 | |||
2679 | /** |
||
2680 | * @param int $user_id |
||
2681 | * @param bool $isArray |
||
2682 | * |
||
2683 | * @return string|array |
||
2684 | */ |
||
2685 | public static function getExtraFieldBlock($user_id, $isArray = false) |
||
2686 | { |
||
2687 | $fieldVisibility = api_get_configuration_value('profile_fields_visibility'); |
||
2688 | $fieldVisibilityKeys = []; |
||
2689 | if (isset($fieldVisibility['options'])) { |
||
2690 | $fieldVisibility = $fieldVisibility['options']; |
||
2691 | $fieldVisibilityKeys = array_keys($fieldVisibility); |
||
2692 | } |
||
2693 | |||
2694 | $t_ufo = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS); |
||
2695 | $extra_user_data = UserManager::get_extra_user_data($user_id); |
||
2696 | |||
2697 | $extra_information = ''; |
||
2698 | if (is_array($extra_user_data) && count($extra_user_data) > 0) { |
||
2699 | $extra_information_value = ''; |
||
2700 | $extraField = new ExtraField('user'); |
||
2701 | $listType = []; |
||
2702 | $extraFieldItem = []; |
||
2703 | foreach ($extra_user_data as $key => $data) { |
||
2704 | if (empty($data)) { |
||
2705 | continue; |
||
2706 | } |
||
2707 | if (in_array($key, $fieldVisibilityKeys) && $fieldVisibility[$key] === false) { |
||
2708 | continue; |
||
2709 | } |
||
2710 | |||
2711 | // Avoiding parameters |
||
2712 | if (in_array( |
||
2713 | $key, |
||
2714 | [ |
||
2715 | 'mail_notify_invitation', |
||
2716 | 'mail_notify_message', |
||
2717 | 'mail_notify_group_message', |
||
2718 | ] |
||
2719 | )) { |
||
2720 | continue; |
||
2721 | } |
||
2722 | // get display text, visibility and type from user_field table |
||
2723 | $field_variable = str_replace('extra_', '', $key); |
||
2724 | |||
2725 | $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable( |
||
2726 | $field_variable |
||
2727 | ); |
||
2728 | |||
2729 | if (in_array($extraFieldInfo['variable'], ['skype', 'linkedin_url'])) { |
||
2730 | continue; |
||
2731 | } |
||
2732 | |||
2733 | // if is not visible skip |
||
2734 | if ($extraFieldInfo['visible_to_self'] != 1) { |
||
2735 | continue; |
||
2736 | } |
||
2737 | |||
2738 | // if is not visible to others skip also |
||
2739 | if ($extraFieldInfo['visible_to_others'] != 1) { |
||
2740 | continue; |
||
2741 | } |
||
2742 | |||
2743 | if (is_array($data)) { |
||
2744 | switch ($extraFieldInfo['field_type']) { |
||
2745 | case ExtraField::FIELD_TYPE_RADIO: |
||
2746 | $objEfOption = new ExtraFieldOption('user'); |
||
2747 | $value = $data['extra_'.$extraFieldInfo['variable']]; |
||
2748 | $optionInfo = $objEfOption->get_field_option_by_field_and_option( |
||
2749 | $extraFieldInfo['id'], |
||
2750 | $value |
||
2751 | ); |
||
2752 | |||
2753 | if ($optionInfo && isset($optionInfo[0])) { |
||
2754 | $optionInfo = $optionInfo[0]; |
||
2755 | $extraFieldItem = [ |
||
2756 | 'variable' => $extraFieldInfo['variable'], |
||
2757 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
2758 | 'value' => $optionInfo['display_text'], |
||
2759 | ]; |
||
2760 | } else { |
||
2761 | $extraFieldItem = [ |
||
2762 | 'variable' => $extraFieldInfo['variable'], |
||
2763 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
2764 | 'value' => implode(',', $data), |
||
2765 | ]; |
||
2766 | } |
||
2767 | break; |
||
2768 | default: |
||
2769 | $extra_information_value .= |
||
2770 | '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).' ' |
||
2771 | .' '.implode(',', $data).'</li>'; |
||
2772 | $extraFieldItem = [ |
||
2773 | 'variable' => $extraFieldInfo['variable'], |
||
2774 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
2775 | 'value' => implode(',', $data), |
||
2776 | ]; |
||
2777 | break; |
||
2778 | } |
||
2779 | } else { |
||
2780 | switch ($extraFieldInfo['field_type']) { |
||
2781 | case ExtraField::FIELD_TYPE_RADIO: |
||
2782 | $objEfOption = new ExtraFieldOption('user'); |
||
2783 | $optionInfo = $objEfOption->get_field_option_by_field_and_option($extraFieldInfo['id'], $extraFieldInfo['value']); |
||
2784 | break; |
||
2785 | case ExtraField::FIELD_TYPE_GEOLOCALIZATION_COORDINATES: |
||
2786 | case ExtraField::FIELD_TYPE_GEOLOCALIZATION: |
||
2787 | $data = explode('::', $data); |
||
2788 | $data = $data[0]; |
||
2789 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '.$data.'</li>'; |
||
2790 | $extraFieldItem = [ |
||
2791 | 'variable' => $extraFieldInfo['variable'], |
||
2792 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
2793 | 'value' => $data, |
||
2794 | ]; |
||
2795 | break; |
||
2796 | case ExtraField::FIELD_TYPE_DOUBLE_SELECT: |
||
2797 | $id_options = explode('::', $data); |
||
2798 | $value_options = []; |
||
2799 | // get option display text from user_field_options table |
||
2800 | foreach ($id_options as $id_option) { |
||
2801 | $sql = "SELECT display_text |
||
2802 | FROM $t_ufo |
||
2803 | WHERE id = '$id_option'"; |
||
2804 | $res_options = Database::query($sql); |
||
2805 | $row_options = Database::fetch_row($res_options); |
||
2806 | $value_options[] = $row_options[0]; |
||
2807 | } |
||
2808 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': ' |
||
2809 | .' '.implode(' ', $value_options).'</li>'; |
||
2810 | $extraFieldItem = [ |
||
2811 | 'variable' => $extraFieldInfo['variable'], |
||
2812 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
2813 | 'value' => $value_options, |
||
2814 | ]; |
||
2815 | break; |
||
2816 | case ExtraField::FIELD_TYPE_TAG: |
||
2817 | $user_tags = UserManager::get_user_tags($user_id, $extraFieldInfo['id']); |
||
2818 | |||
2819 | $tag_tmp = ''; |
||
2820 | foreach ($user_tags as $tags) { |
||
2821 | $tag_tmp .= '<a class="label label_tag"' |
||
2822 | .' href="'.api_get_path(WEB_PATH).'main/social/search.php?q='.$tags['tag'].'">' |
||
2823 | .$tags['tag'] |
||
2824 | .'</a>'; |
||
2825 | } |
||
2826 | if (is_array($user_tags) && count($user_tags) > 0) { |
||
2827 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': ' |
||
2828 | .' '.$tag_tmp.'</li>'; |
||
2829 | } |
||
2830 | $extraFieldItem = [ |
||
2831 | 'variable' => $extraFieldInfo['variable'], |
||
2832 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
2833 | 'value' => $tag_tmp, |
||
2834 | ]; |
||
2835 | break; |
||
2836 | case ExtraField::FIELD_TYPE_SOCIAL_PROFILE: |
||
2837 | $icon_path = UserManager::get_favicon_from_url($data); |
||
2838 | if (!self::verifyUrl($icon_path)) { |
||
2839 | break; |
||
2840 | } |
||
2841 | $bottom = '0.2'; |
||
2842 | //quick hack for hi5 |
||
2843 | $domain = parse_url($icon_path, PHP_URL_HOST); |
||
2844 | if ($domain == 'www.hi5.com' || $domain == 'hi5.com') { |
||
2845 | $bottom = '-0.8'; |
||
2846 | } |
||
2847 | $data = '<a href="'.$data.'">' |
||
2848 | .'<img src="'.$icon_path.'" alt="icon"' |
||
2849 | .' style="margin-right:0.5em;margin-bottom:'.$bottom.'em;" />' |
||
2850 | .$extraFieldInfo['display_text'] |
||
2851 | .'</a>'; |
||
2852 | $extra_information_value .= '<li class="list-group-item">'.$data.'</li>'; |
||
2853 | $extraFieldItem = [ |
||
2854 | 'variable' => $extraFieldInfo['variable'], |
||
2855 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
2856 | 'value' => $data, |
||
2857 | ]; |
||
2858 | break; |
||
2859 | case ExtraField::FIELD_TYPE_SELECT_WITH_TEXT_FIELD: |
||
2860 | $parsedData = explode('::', $data); |
||
2861 | |||
2862 | if (!$parsedData) { |
||
2863 | break; |
||
2864 | } |
||
2865 | |||
2866 | $objEfOption = new ExtraFieldOption('user'); |
||
2867 | $optionInfo = $objEfOption->get($parsedData[0]); |
||
2868 | |||
2869 | $extra_information_value .= '<li class="list-group-item">' |
||
2870 | .$optionInfo['display_text'].': ' |
||
2871 | .$parsedData[1].'</li>'; |
||
2872 | $extraFieldItem = [ |
||
2873 | 'variable' => $extraFieldInfo['variable'], |
||
2874 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
2875 | 'value' => $parsedData[1], |
||
2876 | ]; |
||
2877 | break; |
||
2878 | case ExtraField::FIELD_TYPE_TRIPLE_SELECT: |
||
2879 | $optionIds = explode(';', $data); |
||
2880 | $optionValues = []; |
||
2881 | |||
2882 | foreach ($optionIds as $optionId) { |
||
2883 | $objEfOption = new ExtraFieldOption('user'); |
||
2884 | $optionInfo = $objEfOption->get($optionId); |
||
2885 | |||
2886 | $optionValues[] = $optionInfo['display_text']; |
||
2887 | } |
||
2888 | $extra_information_value .= '<li class="list-group-item">' |
||
2889 | .ucfirst($extraFieldInfo['display_text']).': ' |
||
2890 | .implode(' ', $optionValues).'</li>'; |
||
2891 | $extraFieldItem = [ |
||
2892 | 'variable' => $extraFieldInfo['variable'], |
||
2893 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
2894 | 'value' => implode(' ', $optionValues), |
||
2895 | ]; |
||
2896 | break; |
||
2897 | default: |
||
2898 | // Ofaj |
||
2899 | // Converts "Date of birth" into "age" |
||
2900 | if ($key === 'terms_datedenaissance') { |
||
2901 | $dataArray = date_to_str_ago($data, 'UTC', true); |
||
2902 | $dataToString = isset($dataArray['years']) && !empty($dataArray['years']) ? $dataArray['years'] : 0; |
||
2903 | if (!empty($dataToString)) { |
||
2904 | $data = $dataToString; |
||
2905 | $extraFieldInfo['display_text'] = get_lang('Age'); |
||
2906 | } |
||
2907 | } |
||
2908 | |||
2909 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '.$data.'</li>'; |
||
2910 | $extraFieldItem = [ |
||
2911 | 'variable' => $extraFieldInfo['variable'], |
||
2912 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
2913 | 'value' => $data, |
||
2914 | ]; |
||
2915 | break; |
||
2916 | } |
||
2917 | } |
||
2918 | |||
2919 | $listType[] = $extraFieldItem; |
||
2920 | } |
||
2921 | |||
2922 | if ($isArray) { |
||
2923 | return $listType; |
||
2924 | } else { |
||
2925 | // if there are information to show |
||
2926 | if (!empty($extra_information_value)) { |
||
2927 | $extra_information_value = '<ul class="list-group">'.$extra_information_value.'</ul>'; |
||
2928 | $extra_information .= Display::panelCollapse( |
||
2929 | get_lang('ExtraInformation'), |
||
2930 | $extra_information_value, |
||
2931 | 'sn-extra-information', |
||
2932 | null, |
||
2933 | 'sn-extra-accordion', |
||
2934 | 'sn-extra-collapse' |
||
2935 | ); |
||
2936 | } |
||
2937 | } |
||
2938 | } |
||
2939 | |||
2940 | return $extra_information; |
||
2941 | } |
||
2942 | |||
2943 | /** |
||
2944 | * @param string $url |
||
2945 | */ |
||
2946 | public static function handlePosts($url) |
||
2947 | { |
||
2948 | $friendId = isset($_GET['u']) ? (int) $_GET['u'] : api_get_user_id(); |
||
2949 | $url = Security::remove_XSS($url); |
||
2950 | $wallSocialAddPost = SocialManager::getWallForm(api_get_self()); |
||
2951 | |||
2952 | if (!$wallSocialAddPost->validate()) { |
||
2953 | return; |
||
2954 | } |
||
2955 | |||
2956 | $values = $wallSocialAddPost->exportValues(); |
||
2957 | |||
2958 | // Main post |
||
2959 | if (!empty($values['social_wall_new_msg_main']) || !empty($_FILES['picture']['tmp_name'])) { |
||
2960 | $messageContent = $values['social_wall_new_msg_main']; |
||
2961 | if (!empty($_POST['url_content'])) { |
||
2962 | $messageContent = $values['social_wall_new_msg_main'].'<br /><br />'.$values['url_content']; |
||
2963 | } |
||
2964 | |||
2965 | $messageId = self::sendWallMessage( |
||
2966 | api_get_user_id(), |
||
2967 | $friendId, |
||
2968 | $messageContent, |
||
2969 | 0, |
||
2970 | MESSAGE_STATUS_WALL_POST |
||
2971 | ); |
||
2972 | |||
2973 | if ($messageId && !empty($_FILES['picture']['tmp_name'])) { |
||
2974 | self::sendWallMessageAttachmentFile( |
||
2975 | api_get_user_id(), |
||
2976 | $_FILES['picture'], |
||
2977 | $messageId |
||
2978 | ); |
||
2979 | } |
||
2980 | |||
2981 | Display::addFlash(Display::return_message(get_lang('MessageSent'))); |
||
2982 | header('Location: '.$url); |
||
2983 | exit; |
||
2984 | } |
||
2985 | } |
||
2986 | |||
2987 | /** |
||
2988 | * @param int $countPost |
||
2989 | * @param array $htmlHeadXtra |
||
2990 | */ |
||
2991 | public static function getScrollJs($countPost, &$htmlHeadXtra) |
||
2992 | { |
||
2993 | // $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php'; |
||
2994 | $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php'; |
||
2995 | $javascriptDir = api_get_path(LIBRARY_PATH).'javascript/'; |
||
2996 | $locale = api_get_language_isocode(); |
||
2997 | |||
2998 | // Add Jquery scroll pagination plugin |
||
2999 | $htmlHeadXtra[] = api_get_js('jscroll/jquery.jscroll.js'); |
||
3000 | // Add Jquery Time ago plugin |
||
3001 | $htmlHeadXtra[] = api_get_asset('jquery-timeago/jquery.timeago.js'); |
||
3002 | $timeAgoLocaleDir = $javascriptDir.'jquery-timeago/locales/jquery.timeago.'.$locale.'.js'; |
||
3003 | if (file_exists($timeAgoLocaleDir)) { |
||
3004 | $htmlHeadXtra[] = api_get_js('jquery-timeago/locales/jquery.timeago.'.$locale.'.js'); |
||
3005 | } |
||
3006 | |||
3007 | if ($countPost > self::DEFAULT_WALL_POSTS) { |
||
3008 | $htmlHeadXtra[] = '<script> |
||
3009 | $(function() { |
||
3010 | var container = $("#wallMessages"); |
||
3011 | container.jscroll({ |
||
3012 | loadingHtml: "<div class=\"well_border\">'.get_lang('Loading').' </div>", |
||
3013 | nextSelector: "a.nextPage:last", |
||
3014 | contentSelector: "", |
||
3015 | callback: timeAgo |
||
3016 | }); |
||
3017 | }); |
||
3018 | </script>'; |
||
3019 | } |
||
3020 | |||
3021 | $htmlHeadXtra[] = '<script> |
||
3022 | function submitComment(messageId) |
||
3023 | { |
||
3024 | var data = $("#form_comment_"+messageId).serializeArray(); |
||
3025 | $.ajax({ |
||
3026 | type : "POST", |
||
3027 | url: "'.$socialAjaxUrl.'?a=send_comment" + "&id=" + messageId, |
||
3028 | data: data, |
||
3029 | success: function (result) { |
||
3030 | if (result) { |
||
3031 | $("#post_" + messageId + " textarea").val(""); |
||
3032 | $("#post_" + messageId + " .sub-mediapost").prepend(result); |
||
3033 | $("#post_" + messageId + " .sub-mediapost").append( |
||
3034 | $(\'<div id=result_\' + messageId +\'>'.addslashes(get_lang('Saved')).'</div>\') |
||
3035 | ); |
||
3036 | |||
3037 | $("#result_" + messageId + "").fadeIn("fast", function() { |
||
3038 | $("#result_" + messageId + "").delay(1000).fadeOut("fast", function() { |
||
3039 | $(this).remove(); |
||
3040 | }); |
||
3041 | }); |
||
3042 | } |
||
3043 | } |
||
3044 | }); |
||
3045 | } |
||
3046 | |||
3047 | $(function() { |
||
3048 | timeAgo(); |
||
3049 | |||
3050 | $("body").on("click", ".btn-delete-social-message", function () { |
||
3051 | var id = $(this).data("id"); |
||
3052 | var secToken = $(this).data("sectoken"); |
||
3053 | |||
3054 | $.getJSON( |
||
3055 | "'.$socialAjaxUrl.'", |
||
3056 | { a: "delete_message", id: id, social_sec_token: secToken }, |
||
3057 | function (result) { |
||
3058 | if (result) { |
||
3059 | $("#message_" + id).parent().parent().parent().parent().html(result.message); |
||
3060 | |||
3061 | $(".btn-delete-social-message").data("sectoken", result.secToken); |
||
3062 | } |
||
3063 | } |
||
3064 | ); |
||
3065 | }); |
||
3066 | |||
3067 | $("body").on("click", ".btn-delete-social-comment", function () { |
||
3068 | var id = $(this).data("id"); |
||
3069 | var secToken = $(this).data("sectoken"); |
||
3070 | |||
3071 | $.getJSON( |
||
3072 | "'.$socialAjaxUrl.'", |
||
3073 | { a: "delete_message", id: id, social_sec_token: secToken }, |
||
3074 | function (result) { |
||
3075 | if (result) { |
||
3076 | $("#message_" + id).parent().parent().parent().html(result.message); |
||
3077 | |||
3078 | $(".btn-delete-social-comment").data("sectoken", result.secToken); |
||
3079 | } |
||
3080 | } |
||
3081 | ); |
||
3082 | }); |
||
3083 | }); |
||
3084 | |||
3085 | function timeAgo() { |
||
3086 | $(".timeago").timeago(); |
||
3087 | } |
||
3088 | </script>'; |
||
3089 | } |
||
3090 | |||
3091 | /** |
||
3092 | * @param int $userId |
||
3093 | * @param int $countPost |
||
3094 | * |
||
3095 | * @return string |
||
3096 | */ |
||
3097 | public static function getAutoExtendLink($userId, $countPost) |
||
3098 | { |
||
3099 | $userId = (int) $userId; |
||
3100 | $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php'; |
||
3101 | $socialAutoExtendLink = ''; |
||
3102 | if ($countPost > self::DEFAULT_WALL_POSTS) { |
||
3103 | $socialAutoExtendLink = Display::url( |
||
3104 | get_lang('SeeMore'), |
||
3105 | $socialAjaxUrl.'?u='.$userId.'&a=list_wall_message&start='. |
||
3106 | self::DEFAULT_WALL_POSTS.'&length='.self::DEFAULT_SCROLL_NEW_POST, |
||
3107 | [ |
||
3108 | 'class' => 'nextPage next', |
||
3109 | ] |
||
3110 | ); |
||
3111 | } |
||
3112 | |||
3113 | return $socialAutoExtendLink; |
||
3114 | } |
||
3115 | |||
3116 | /** |
||
3117 | * @param int $userId |
||
3118 | * |
||
3119 | * @return array |
||
3120 | */ |
||
3121 | public static function getThreadList($userId) |
||
3122 | { |
||
3123 | $forumCourseId = api_get_configuration_value('global_forums_course_id'); |
||
3124 | |||
3125 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
||
3126 | |||
3127 | $threads = []; |
||
3128 | if (!empty($forumCourseId)) { |
||
3129 | $courseInfo = api_get_course_info_by_id($forumCourseId); |
||
3130 | getNotificationsPerUser($userId, true, $forumCourseId); |
||
3131 | $notification = Session::read('forum_notification'); |
||
3132 | Session::erase('forum_notification'); |
||
3133 | |||
3134 | $threadUrlBase = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
||
3135 | 'cidReq' => $courseInfo['code'], |
||
3136 | ]).'&'; |
||
3137 | if (isset($notification['thread']) && !empty($notification['thread'])) { |
||
3138 | $threadList = array_filter(array_unique($notification['thread'])); |
||
3139 | $em = Database::getManager(); |
||
3140 | $repo = $em->getRepository('ChamiloCourseBundle:CForumThread'); |
||
3141 | foreach ($threadList as $threadId) { |
||
3142 | /** @var \Chamilo\CourseBundle\Entity\CForumThread $thread */ |
||
3143 | $thread = $repo->find($threadId); |
||
3144 | if ($thread) { |
||
3145 | $threadUrl = $threadUrlBase.http_build_query([ |
||
3146 | 'forum' => $thread->getForumId(), |
||
3147 | 'thread' => $thread->getIid(), |
||
3148 | ]); |
||
3149 | $threads[] = [ |
||
3150 | 'id' => $threadId, |
||
3151 | 'url' => Display::url( |
||
3152 | $thread->getThreadTitle(), |
||
3153 | $threadUrl |
||
3154 | ), |
||
3155 | 'name' => Display::url( |
||
3156 | $thread->getThreadTitle(), |
||
3157 | $threadUrl |
||
3158 | ), |
||
3159 | 'description' => '', |
||
3160 | ]; |
||
3161 | } |
||
3162 | } |
||
3163 | } |
||
3164 | } |
||
3165 | |||
3166 | return $threads; |
||
3167 | } |
||
3168 | |||
3169 | /** |
||
3170 | * @param int $userId |
||
3171 | * |
||
3172 | * @return string |
||
3173 | */ |
||
3174 | public static function getGroupBlock($userId) |
||
3175 | { |
||
3176 | $threadList = self::getThreadList($userId); |
||
3177 | $userGroup = new UserGroup(); |
||
3178 | |||
3179 | $forumCourseId = api_get_configuration_value('global_forums_course_id'); |
||
3180 | $courseInfo = null; |
||
3181 | if (!empty($forumCourseId)) { |
||
3182 | $courseInfo = api_get_course_info_by_id($forumCourseId); |
||
3183 | } |
||
3184 | |||
3185 | $social_group_block = ''; |
||
3186 | if (!empty($courseInfo)) { |
||
3187 | if (!empty($threadList)) { |
||
3188 | $social_group_block .= '<div class="list-group">'; |
||
3189 | foreach ($threadList as $group) { |
||
3190 | $social_group_block .= ' <li class="list-group-item">'; |
||
3191 | $social_group_block .= $group['name']; |
||
3192 | $social_group_block .= '</li>'; |
||
3193 | } |
||
3194 | $social_group_block .= '</div>'; |
||
3195 | } |
||
3196 | |||
3197 | $social_group_block .= Display::url( |
||
3198 | get_lang('SeeAllCommunities'), |
||
3199 | api_get_path(WEB_CODE_PATH).'forum/index.php?cidReq='.$courseInfo['code'] |
||
3200 | ); |
||
3201 | |||
3202 | if (!empty($social_group_block)) { |
||
3203 | $social_group_block = Display::panelCollapse( |
||
3204 | get_lang('MyCommunities'), |
||
3205 | $social_group_block, |
||
3206 | 'sm-groups', |
||
3207 | null, |
||
3208 | 'grups-acordion', |
||
3209 | 'groups-collapse' |
||
3210 | ); |
||
3211 | } |
||
3212 | } else { |
||
3213 | // Load my groups |
||
3214 | $results = $userGroup->get_groups_by_user( |
||
3215 | $userId, |
||
3216 | [ |
||
3217 | GROUP_USER_PERMISSION_ADMIN, |
||
3218 | GROUP_USER_PERMISSION_READER, |
||
3219 | GROUP_USER_PERMISSION_MODERATOR, |
||
3220 | GROUP_USER_PERMISSION_HRM, |
||
3221 | ] |
||
3222 | ); |
||
3223 | |||
3224 | $myGroups = []; |
||
3225 | if (!empty($results)) { |
||
3226 | foreach ($results as $result) { |
||
3227 | $id = $result['id']; |
||
3228 | $result['description'] = Security::remove_XSS($result['description'], STUDENT, true); |
||
3229 | $result['name'] = Security::remove_XSS($result['name'], STUDENT, true); |
||
3230 | |||
3231 | $group_url = "group_view.php?id=$id"; |
||
3232 | |||
3233 | $link = Display::url( |
||
3234 | api_ucwords(cut($result['name'], 40, true)), |
||
3235 | $group_url |
||
3236 | ); |
||
3237 | |||
3238 | $result['name'] = $link; |
||
3239 | |||
3240 | $picture = $userGroup->get_picture_group( |
||
3241 | $id, |
||
3242 | $result['picture'], |
||
3243 | null, |
||
3244 | GROUP_IMAGE_SIZE_BIG |
||
3245 | ); |
||
3246 | |||
3247 | $result['picture'] = '<img class="img-responsive" src="'.$picture['file'].'" />'; |
||
3248 | $group_actions = '<div class="group-more"><a class="btn btn-default" href="groups.php?#tab_browse-2">'. |
||
3249 | get_lang('SeeMore').'</a></div>'; |
||
3250 | $group_info = '<div class="description"><p>'.cut($result['description'], 120, true)."</p></div>"; |
||
3251 | $myGroups[] = [ |
||
3252 | 'url' => Display::url( |
||
3253 | $result['picture'], |
||
3254 | $group_url |
||
3255 | ), |
||
3256 | 'name' => $result['name'], |
||
3257 | 'description' => $group_info.$group_actions, |
||
3258 | ]; |
||
3259 | } |
||
3260 | |||
3261 | $social_group_block .= '<div class="list-group">'; |
||
3262 | foreach ($myGroups as $group) { |
||
3263 | $social_group_block .= ' <li class="list-group-item">'; |
||
3264 | $social_group_block .= $group['name']; |
||
3265 | $social_group_block .= '</li>'; |
||
3266 | } |
||
3267 | $social_group_block .= '</div>'; |
||
3268 | |||
3269 | $form = new FormValidator( |
||
3270 | 'find_groups_form', |
||
3271 | 'get', |
||
3272 | api_get_path(WEB_CODE_PATH).'social/search.php?search_type=2', |
||
3273 | null, |
||
3274 | null, |
||
3275 | FormValidator::LAYOUT_BOX_NO_LABEL |
||
3276 | ); |
||
3277 | $form->addHidden('search_type', 2); |
||
3278 | |||
3279 | $form->addText( |
||
3280 | 'q', |
||
3281 | get_lang('Search'), |
||
3282 | false, |
||
3283 | [ |
||
3284 | 'aria-label' => get_lang('Search'), |
||
3285 | 'custom' => true, |
||
3286 | 'placeholder' => get_lang('Search'), |
||
3287 | ] |
||
3288 | ); |
||
3289 | |||
3290 | $social_group_block .= $form->returnForm(); |
||
3291 | |||
3292 | if (!empty($social_group_block)) { |
||
3293 | $social_group_block = Display::panelCollapse( |
||
3294 | get_lang('MyGroups'), |
||
3295 | $social_group_block, |
||
3296 | 'sm-groups', |
||
3297 | null, |
||
3298 | 'grups-acordion', |
||
3299 | 'groups-collapse' |
||
3300 | ); |
||
3301 | } |
||
3302 | } |
||
3303 | } |
||
3304 | |||
3305 | return $social_group_block; |
||
3306 | } |
||
3307 | |||
3308 | /** |
||
3309 | * @param string $selected |
||
3310 | * |
||
3311 | * @return string |
||
3312 | */ |
||
3313 | public static function getHomeProfileTabs($selected = 'home') |
||
3314 | { |
||
3315 | $headers = [ |
||
3316 | [ |
||
3317 | 'url' => api_get_path(WEB_CODE_PATH).'auth/profile.php', |
||
3318 | 'content' => get_lang('Profile'), |
||
3319 | ], |
||
3320 | ]; |
||
3321 | $allowJustification = api_get_plugin_setting('justification', 'tool_enable') === 'true'; |
||
3322 | if ($allowJustification) { |
||
3323 | $plugin = Justification::create(); |
||
3324 | $headers[] = [ |
||
3325 | 'url' => api_get_path(WEB_CODE_PATH).'auth/justification.php', |
||
3326 | 'content' => $plugin->get_lang('Justification'), |
||
3327 | ]; |
||
3328 | } |
||
3329 | |||
3330 | $allowPauseTraining = api_get_plugin_setting('pausetraining', 'tool_enable') === 'true'; |
||
3331 | $allowEdit = api_get_plugin_setting('pausetraining', 'allow_users_to_edit_pause_formation') === 'true'; |
||
3332 | if ($allowPauseTraining && $allowEdit) { |
||
3333 | $plugin = PauseTraining::create(); |
||
3334 | $headers[] = [ |
||
3335 | 'url' => api_get_path(WEB_CODE_PATH).'auth/pausetraining.php', |
||
3336 | 'content' => $plugin->get_lang('PauseTraining'), |
||
3337 | ]; |
||
3338 | } |
||
3339 | |||
3340 | $selectedItem = 1; |
||
3341 | foreach ($headers as $header) { |
||
3342 | $info = pathinfo($header['url']); |
||
3343 | if ($selected === $info['filename']) { |
||
3344 | break; |
||
3345 | } |
||
3346 | $selectedItem++; |
||
3347 | } |
||
3348 | |||
3349 | $tabs = ''; |
||
3350 | if (count($headers) > 1) { |
||
3351 | $tabs = Display::tabsOnlyLink($headers, $selectedItem); |
||
3352 | } |
||
3353 | |||
3354 | return $tabs; |
||
3355 | } |
||
3356 | |||
3357 | private static function getWallForm(string $urlForm): FormValidator |
||
3358 | { |
||
3359 | $userId = isset($_GET['u']) ? '?u='.((int) $_GET['u']) : ''; |
||
3360 | $form = new FormValidator( |
||
3361 | 'social_wall_main', |
||
3362 | 'post', |
||
3363 | $urlForm.$userId, |
||
3364 | null, |
||
3365 | ['enctype' => 'multipart/form-data'], |
||
3366 | FormValidator::LAYOUT_HORIZONTAL |
||
3367 | ); |
||
3368 | |||
3369 | $socialWallPlaceholder = isset($_GET['u']) |
||
3370 | ? get_lang('SocialWallWriteNewPostToFriend') |
||
3371 | : get_lang('SocialWallWhatAreYouThinkingAbout'); |
||
3372 | |||
3373 | $form->addTextarea( |
||
3374 | 'social_wall_new_msg_main', |
||
3375 | null, |
||
3376 | [ |
||
3377 | 'placeholder' => $socialWallPlaceholder, |
||
3378 | 'cols-size' => [1, 12, 1], |
||
3379 | 'aria-label' => $socialWallPlaceholder, |
||
3380 | ] |
||
3381 | ); |
||
3382 | $form->addHtml('<div class="form-group">'); |
||
3383 | $form->addHtml('<div class="col-sm-6">'); |
||
3384 | $form->addFile('picture', get_lang('UploadFile'), ['custom' => true]); |
||
3385 | $form->addHtml('</div>'); |
||
3386 | $form->addHtml('<div class="col-sm-6 "><div class="pull-right">'); |
||
3387 | $form->addButtonSend( |
||
3388 | get_lang('Post'), |
||
3389 | 'wall_post_button', |
||
3390 | false, |
||
3391 | [ |
||
3392 | 'cols-size' => [1, 10, 1], |
||
3393 | 'custom' => true, |
||
3394 | ] |
||
3395 | ); |
||
3396 | $form->addHtml('</div></div>'); |
||
3397 | $form->addHtml('</div>'); |
||
3398 | $form->addHidden('url_content', ''); |
||
3399 | $form->protect(); |
||
3400 | |||
3401 | return $form; |
||
3402 | } |
||
3403 | |||
3404 | /** |
||
3405 | * Returns the formatted header message post. |
||
3406 | * |
||
3407 | * @param int $authorInfo |
||
3408 | * @param int $receiverInfo |
||
3409 | * @param array $message Message data |
||
3410 | * |
||
3411 | * @return string $html The formatted header message post |
||
3412 | */ |
||
3413 | private static function headerMessagePost($authorInfo, $receiverInfo, $message) |
||
3414 | { |
||
3415 | $currentUserId = api_get_user_id(); |
||
3416 | $authorId = (int) $authorInfo['user_id']; |
||
3417 | $receiverId = (int) $receiverInfo['user_id']; |
||
3418 | $iconStatus = $authorInfo['icon_status']; |
||
3419 | |||
3420 | $date = Display::dateToStringAgoAndLongDate($message['send_date']); |
||
3421 | $avatarAuthor = $authorInfo['avatar']; |
||
3422 | $urlAuthor = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$authorId; |
||
3423 | $nameCompleteAuthor = $authorInfo['complete_name']; |
||
3424 | |||
3425 | $urlReceiver = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$receiverId; |
||
3426 | $nameCompleteReceiver = $receiverInfo['complete_name']; |
||
3427 | |||
3428 | $htmlReceiver = ''; |
||
3429 | if ($authorId !== $receiverId) { |
||
3430 | $htmlReceiver = ' > <a href="'.$urlReceiver.'">'.$nameCompleteReceiver.'</a> '; |
||
3431 | } |
||
3432 | |||
3433 | if (!empty($message['group_info'])) { |
||
3434 | $htmlReceiver = ' > <a href="'.$message['group_info']['url'].'">'.$message['group_info']['name'].'</a> '; |
||
3435 | } |
||
3436 | $canEdit = ($currentUserId == $authorInfo['user_id'] || $currentUserId == $receiverInfo['user_id']) && empty($message['group_info']); |
||
3437 | |||
3438 | if (!empty($message['thread_id'])) { |
||
3439 | $htmlReceiver = ' > <a href="'.$message['thread_url'].'">'.$message['forum_title'].'</a> '; |
||
3440 | $canEdit = false; |
||
3441 | } |
||
3442 | |||
3443 | $postAttachment = self::getPostAttachment($message); |
||
3444 | |||
3445 | $html = '<div class="top-mediapost" >'; |
||
3446 | $html .= '<div class="pull-right btn-group btn-group-sm">'; |
||
3447 | |||
3448 | $html .= MessageManager::getLikesButton( |
||
3449 | $message['id'], |
||
3450 | $currentUserId, |
||
3451 | !empty($message['group_info']['id']) ? (int) $message['group_info']['id'] : 0 |
||
3452 | ); |
||
3453 | |||
3454 | if ($canEdit) { |
||
3455 | $htmlDelete = Display::button( |
||
3456 | '', |
||
3457 | Display::returnFontAwesomeIcon('trash', '', true), |
||
3458 | [ |
||
3459 | 'id' => 'message_'.$message['id'], |
||
3460 | 'title' => get_lang('SocialMessageDelete'), |
||
3461 | 'type' => 'button', |
||
3462 | 'class' => 'btn btn-default btn-delete-social-message', |
||
3463 | 'data-id' => $message['id'], |
||
3464 | 'data-sectoken' => Security::get_existing_token('social'), |
||
3465 | ] |
||
3466 | ); |
||
3467 | |||
3468 | $html .= $htmlDelete; |
||
3469 | } |
||
3470 | $html .= '</div>'; |
||
3471 | |||
3472 | $html .= '<div class="user-image" >'; |
||
3473 | $html .= '<a href="'.$urlAuthor.'"> |
||
3474 | <img class="avatar-thumb" src="'.$avatarAuthor.'" alt="'.$nameCompleteAuthor.'"></a>'; |
||
3475 | $html .= '</div>'; |
||
3476 | $html .= '<div class="user-data">'; |
||
3477 | $html .= $iconStatus; |
||
3478 | $html .= '<div class="username"><a href="'.$urlAuthor.'">'.$nameCompleteAuthor.'</a>'.$htmlReceiver.'</div>'; |
||
3479 | $html .= '<div class="post-date">'.$date.'</div>'; |
||
3480 | $html .= '</div>'; |
||
3481 | $html .= '<div class="msg-content">'; |
||
3482 | if (!empty($postAttachment)) { |
||
3483 | $html .= '<div class="post-attachment thumbnail">'; |
||
3484 | $html .= $postAttachment; |
||
3485 | $html .= '</div>'; |
||
3486 | } |
||
3487 | $html .= '<div>'.Security::remove_XSS($message['content']).'</div>'; |
||
3488 | $html .= '</div>'; |
||
3489 | $html .= '</div>'; // end mediaPost |
||
3490 | |||
3491 | // Popularity post functionality |
||
3492 | $html .= '<div class="popularity-mediapost"></div>'; |
||
3493 | |||
3494 | return $html; |
||
3495 | } |
||
3496 | } |
||
3497 |