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