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