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