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