| Total Complexity | 347 |
| Total Lines | 3219 |
| 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) |
||
| 117 | { |
||
| 118 | $table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 119 | $userId = (int) $userId; |
||
| 120 | if (empty($userId)) { |
||
| 121 | return 0; |
||
| 122 | } |
||
| 123 | |||
| 124 | $sql = 'SELECT count(friend_user_id) count |
||
| 125 | FROM '.$table.' |
||
| 126 | WHERE |
||
| 127 | relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND |
||
| 128 | friend_user_id<>'.$userId.' AND |
||
| 129 | user_id='.$userId; |
||
| 130 | $res = Database::query($sql); |
||
| 131 | if (Database::num_rows($res)) { |
||
| 132 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 133 | |||
| 134 | return (int) $row['count']; |
||
| 135 | } |
||
| 136 | |||
| 137 | return 0; |
||
| 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) |
||
| 365 | { |
||
| 366 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 367 | $sql = 'SELECT COUNT(*) FROM '.$table.' |
||
| 368 | WHERE |
||
| 369 | user_receiver_id='.intval($receiver_id).' AND |
||
| 370 | msg_status < 4'; |
||
| 371 | $res = Database::query($sql); |
||
| 372 | $row = Database::fetch_row($res); |
||
| 373 | |||
| 374 | return $row[0]; |
||
| 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) |
||
| 385 | { |
||
| 386 | $userId = (int) $userId; |
||
| 387 | |||
| 388 | if (empty($userId)) { |
||
| 389 | return 0; |
||
| 390 | } |
||
| 391 | |||
| 392 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 393 | $sql = 'SELECT COUNT(*) |
||
| 394 | FROM '.$table.' |
||
| 395 | WHERE |
||
| 396 | user_sender_id='.$userId.' AND |
||
| 397 | (msg_status = '.MESSAGE_STATUS_WALL.' OR |
||
| 398 | msg_status = '.MESSAGE_STATUS_WALL_POST.') AND |
||
| 399 | parent_id = 0'; |
||
| 400 | $res = Database::query($sql); |
||
| 401 | $row = Database::fetch_row($res); |
||
| 402 | |||
| 403 | return $row[0]; |
||
| 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) |
||
| 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 $userId |
||
| 819 | */ |
||
| 820 | public static function getAvatarBlock($show = '', $group_id = 0, $userId = 0) |
||
| 821 | { |
||
| 822 | if (empty($userId)) { |
||
| 823 | $userId = api_get_user_id(); |
||
| 824 | } |
||
| 825 | |||
| 826 | $userInfo = api_get_user_info($userId, true, false, true, true); |
||
| 827 | |||
| 828 | $user = [ |
||
| 829 | 'id' => $userInfo['user_id'], |
||
| 830 | 'complete_name' => $userInfo['complete_name'], |
||
| 831 | 'username' => $userInfo['username'], |
||
| 832 | 'email' => $userInfo['email'], |
||
| 833 | 'status' => $userInfo['status'], |
||
| 834 | ]; |
||
| 835 | |||
| 836 | $show_groups = [ |
||
| 837 | 'groups', |
||
| 838 | 'group_messages', |
||
| 839 | 'messages_list', |
||
| 840 | 'group_add', |
||
| 841 | 'mygroups', |
||
| 842 | 'group_edit', |
||
| 843 | 'member_list', |
||
| 844 | 'invite_friends', |
||
| 845 | 'waiting_list', |
||
| 846 | 'browse_groups', |
||
| 847 | ]; |
||
| 848 | |||
| 849 | $template = new Template(null, false, false, false, false, false); |
||
| 850 | |||
| 851 | if (in_array($show, $show_groups) && !empty($group_id)) { |
||
| 852 | // Group image |
||
| 853 | $userGroup = new UserGroup(); |
||
| 854 | $groupInfo = $userGroup->get($group_id); |
||
| 855 | |||
| 856 | $userGroupImage = [ |
||
| 857 | 'big' => $userGroup->get_picture_group( |
||
| 858 | $group_id, |
||
| 859 | $groupInfo['picture'], |
||
| 860 | 128, |
||
| 861 | GROUP_IMAGE_SIZE_BIG |
||
| 862 | ), |
||
| 863 | 'normal' => $userGroup->get_picture_group( |
||
| 864 | $group_id, |
||
| 865 | $groupInfo['picture'], |
||
| 866 | 128, |
||
| 867 | GROUP_IMAGE_SIZE_MEDIUM |
||
| 868 | ), |
||
| 869 | ]; |
||
| 870 | |||
| 871 | $template->assign('show_group', true); |
||
| 872 | $template->assign('group', $groupInfo); |
||
| 873 | $template->assign('avatar', $userGroupImage); |
||
| 874 | } else { |
||
| 875 | $template->assign('show_group', false); |
||
| 876 | $template->assign('show_user', true); |
||
| 877 | $template->assign('user', $user); |
||
| 878 | $template->assign( |
||
| 879 | 'avatar', |
||
| 880 | [ |
||
| 881 | 'big' => UserManager::getUserPicture( |
||
| 882 | $userId, |
||
| 883 | USER_IMAGE_SIZE_BIG |
||
| 884 | ), |
||
| 885 | 'normal' => UserManager::getUserPicture( |
||
| 886 | $userId, |
||
| 887 | USER_IMAGE_SIZE_MEDIUM |
||
| 888 | ), |
||
| 889 | ] |
||
| 890 | ); |
||
| 891 | } |
||
| 892 | |||
| 893 | $skillBlock = $template->get_template('social/avatar_block.html.twig'); |
||
| 894 | |||
| 895 | return $template->fetch($skillBlock); |
||
| 896 | } |
||
| 897 | |||
| 898 | /** |
||
| 899 | * Shows the right menu of the Social Network tool. |
||
| 900 | * |
||
| 901 | * @param string $show highlight link possible values: |
||
| 902 | * group_add, |
||
| 903 | * home, |
||
| 904 | * messages, |
||
| 905 | * messages_inbox, |
||
| 906 | * messages_compose , |
||
| 907 | * messages_outbox, |
||
| 908 | * invitations, |
||
| 909 | * shared_profile, |
||
| 910 | * friends, |
||
| 911 | * groups search |
||
| 912 | * @param int $group_id group id |
||
| 913 | * @param int $user_id user id |
||
| 914 | * @param bool $show_full_profile show profile or not (show or hide the user image/information) |
||
| 915 | * @param bool $show_delete_account_button |
||
| 916 | */ |
||
| 917 | public static function getMenuSocial( |
||
| 918 | $show = '', |
||
| 919 | $group_id = 0, |
||
| 920 | $user_id = 0, |
||
| 921 | $show_full_profile = false, |
||
| 922 | $show_delete_account_button = false |
||
| 923 | ) { |
||
| 924 | $user_id = (int) $user_id; |
||
| 925 | $group_id = (int) $group_id; |
||
| 926 | |||
| 927 | if (empty($user_id)) { |
||
| 928 | $user_id = api_get_user_id(); |
||
| 929 | } |
||
| 930 | |||
| 931 | $usergroup = new UserGroup(); |
||
| 932 | $show_groups = [ |
||
| 933 | 'groups', |
||
| 934 | 'group_messages', |
||
| 935 | 'messages_list', |
||
| 936 | 'group_add', |
||
| 937 | 'mygroups', |
||
| 938 | 'group_edit', |
||
| 939 | 'member_list', |
||
| 940 | 'invite_friends', |
||
| 941 | 'waiting_list', |
||
| 942 | 'browse_groups', |
||
| 943 | ]; |
||
| 944 | |||
| 945 | // get count unread message and total invitations |
||
| 946 | $count_unread_message = MessageManager::getNumberOfMessages(true); |
||
| 947 | $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null; |
||
| 948 | |||
| 949 | $number_of_new_messages_of_friend = self::get_message_number_invitation_by_user_id(api_get_user_id()); |
||
| 950 | $group_pending_invitations = $usergroup->get_groups_by_user( |
||
| 951 | api_get_user_id(), |
||
| 952 | GROUP_USER_PERMISSION_PENDING_INVITATION, |
||
| 953 | false |
||
| 954 | ); |
||
| 955 | $group_pending_invitations = count($group_pending_invitations); |
||
| 956 | $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; |
||
| 957 | $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : ''); |
||
| 958 | |||
| 959 | $filesIcon = Display::return_icon('sn-files.png', get_lang('MyFiles'), null, ICON_SIZE_SMALL); |
||
| 960 | $friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), null, ICON_SIZE_SMALL); |
||
| 961 | $groupsIcon = Display::return_icon('sn-groups.png', get_lang('SocialGroups'), null, ICON_SIZE_SMALL); |
||
| 962 | $homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), null, ICON_SIZE_SMALL); |
||
| 963 | $invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), null, ICON_SIZE_SMALL); |
||
| 964 | $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), null, ICON_SIZE_SMALL); |
||
| 965 | $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile')); |
||
| 966 | $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), null, ICON_SIZE_SMALL); |
||
| 967 | $portfolioIcon = Display::return_icon('wiki_task.png', get_lang('Portfolio')); |
||
| 968 | $personalDataIcon = Display::return_icon('database.png', get_lang('PersonalDataReport')); |
||
| 969 | |||
| 970 | $forumCourseId = api_get_configuration_value('global_forums_course_id'); |
||
| 971 | $groupUrl = api_get_path(WEB_CODE_PATH).'social/groups.php'; |
||
| 972 | if (!empty($forumCourseId)) { |
||
| 973 | $courseInfo = api_get_course_info_by_id($forumCourseId); |
||
| 974 | if (!empty($courseInfo)) { |
||
| 975 | $groupUrl = api_get_path(WEB_CODE_PATH).'forum/index.php?cidReq='.$courseInfo['code']; |
||
| 976 | } |
||
| 977 | } |
||
| 978 | |||
| 979 | $html = ''; |
||
| 980 | $active = null; |
||
| 981 | $links = null; |
||
| 982 | |||
| 983 | $itemMenu = []; |
||
| 984 | |||
| 985 | if (!in_array( |
||
| 986 | $show, |
||
| 987 | ['shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'] |
||
| 988 | )) { |
||
| 989 | $itemMenu[0] = [ |
||
| 990 | 'item' => get_lang('Home'), |
||
| 991 | 'url' => api_get_path(WEB_CODE_PATH).'social/home.php', |
||
| 992 | 'icon' => $homeIcon, |
||
| 993 | 'active' => ($show == 'home' ? 'active' : null), |
||
| 994 | ]; |
||
| 995 | |||
| 996 | $itemMenu[1] = [ |
||
| 997 | 'item' => get_lang('Messages').$count_unread_message, |
||
| 998 | 'url' => api_get_path(WEB_CODE_PATH).'messages/inbox.php', |
||
| 999 | 'icon' => $messagesIcon, |
||
| 1000 | 'active' => ($show == 'messages' ? 'active' : null), |
||
| 1001 | ]; |
||
| 1002 | |||
| 1003 | $itemMenu[2] = [ |
||
| 1004 | 'item' => get_lang('Invitations').$total_invitations, |
||
| 1005 | 'url' => api_get_path(WEB_CODE_PATH).'social/invitations.php', |
||
| 1006 | 'icon' => $invitationsIcon, |
||
| 1007 | 'active' => ($show == 'invitations' ? 'active' : null), |
||
| 1008 | ]; |
||
| 1009 | |||
| 1010 | $itemMenu[3] = [ |
||
| 1011 | 'item' => get_lang('ViewMySharedProfile'), |
||
| 1012 | 'url' => api_get_path(WEB_CODE_PATH).'social/profile.php', |
||
| 1013 | 'icon' => $sharedProfileIcon, |
||
| 1014 | 'active' => ($show == 'shared_profile' ? 'active' : null), |
||
| 1015 | ]; |
||
| 1016 | |||
| 1017 | $itemMenu[4] = [ |
||
| 1018 | 'item' => get_lang('Friends'), |
||
| 1019 | 'url' => api_get_path(WEB_CODE_PATH).'social/friends.php', |
||
| 1020 | 'icon' => $friendsIcon, |
||
| 1021 | 'active' => ($show == 'friends' ? 'active' : null), |
||
| 1022 | ]; |
||
| 1023 | |||
| 1024 | $itemMenu[5] = [ |
||
| 1025 | 'item' => get_lang('SocialGroups'), |
||
| 1026 | 'url' => api_get_path(WEB_CODE_PATH).'social/groups.php', |
||
| 1027 | 'icon' => $groupsIcon, |
||
| 1028 | 'active' => ($show == 'browse_groups' ? 'active' : null), |
||
| 1029 | ]; |
||
| 1030 | |||
| 1031 | $itemMenu[6] = [ |
||
| 1032 | 'item' => get_lang('Search'), |
||
| 1033 | 'url' => api_get_path(WEB_CODE_PATH).'social/search.php', |
||
| 1034 | 'icon' => $searchIcon, |
||
| 1035 | 'active' => ($show == 'search' ? 'active' : null), |
||
| 1036 | ]; |
||
| 1037 | |||
| 1038 | if (api_get_setting('allow_my_files') === 'false') { |
||
| 1039 | $itemMenu[7] = [ |
||
| 1040 | 'item' => get_lang('MyFiles'), |
||
| 1041 | 'url' => api_get_path(WEB_CODE_PATH).'social/myfiles.php', |
||
| 1042 | 'icon' => $filesIcon, |
||
| 1043 | 'active' => ($show == 'myfiles' ? 'active' : null), |
||
| 1044 | ]; |
||
| 1045 | } |
||
| 1046 | |||
| 1047 | if (api_get_configuration_value('allow_portfolio_tool')) { |
||
| 1048 | $itemMenu[8] = [ |
||
| 1049 | 'item' => get_lang('Portfolio'), |
||
| 1050 | 'url' => api_get_path(WEB_CODE_PATH).'portfolio/index.php', |
||
| 1051 | 'icon' => $portfolioIcon, |
||
| 1052 | 'active' => ($show == 'portfolio' ? 'active' : null), |
||
| 1053 | ]; |
||
| 1054 | } |
||
| 1055 | |||
| 1056 | if (!api_get_configuration_value('disable_gdpr')) { |
||
| 1057 | $itemMenu[9] = [ |
||
| 1058 | 'item' => get_lang('PersonalDataReport'), |
||
| 1059 | 'url' => api_get_path(WEB_CODE_PATH).'social/personal_data.php', |
||
| 1060 | 'icon' => $personalDataIcon, |
||
| 1061 | 'active' => ($show == 'personal-data' ? 'active' : null), |
||
| 1062 | ]; |
||
| 1063 | } |
||
| 1064 | } |
||
| 1065 | //Move group menu to another function |
||
| 1066 | |||
| 1067 | /*if (in_array($show, $show_groups) && !empty($group_id)) { |
||
| 1068 | $html .= $usergroup->show_group_column_information( |
||
| 1069 | $group_id, |
||
| 1070 | api_get_user_id(), |
||
| 1071 | $show |
||
| 1072 | ); |
||
| 1073 | }*/ |
||
| 1074 | |||
| 1075 | if ($show == 'shared_profile') { |
||
| 1076 | // My own profile |
||
| 1077 | if ($show_full_profile && $user_id == intval(api_get_user_id())) { |
||
| 1078 | $itemMenu[0] = [ |
||
| 1079 | 'item' => get_lang('Home'), |
||
| 1080 | 'url' => api_get_path(WEB_CODE_PATH).'social/home.php', |
||
| 1081 | 'icon' => $homeIcon, |
||
| 1082 | 'active' => ($show == 'home' ? 'active' : null), |
||
| 1083 | ]; |
||
| 1084 | |||
| 1085 | $itemMenu[1] = [ |
||
| 1086 | 'item' => get_lang('Messages').$count_unread_message, |
||
| 1087 | 'url' => api_get_path(WEB_CODE_PATH).'messages/inbox.php', |
||
| 1088 | 'icon' => $messagesIcon, |
||
| 1089 | 'active' => ($show == 'messages' ? 'active' : null), |
||
| 1090 | ]; |
||
| 1091 | |||
| 1092 | $itemMenu[2] = [ |
||
| 1093 | 'item' => get_lang('Invitations').$total_invitations, |
||
| 1094 | 'url' => api_get_path(WEB_CODE_PATH).'social/invitations.php', |
||
| 1095 | 'icon' => $invitationsIcon, |
||
| 1096 | 'active' => ($show == 'invitations' ? 'active' : null), |
||
| 1097 | ]; |
||
| 1098 | |||
| 1099 | $itemMenu[3] = [ |
||
| 1100 | 'item' => get_lang('ViewMySharedProfile'), |
||
| 1101 | 'url' => api_get_path(WEB_CODE_PATH).'social/profile.php', |
||
| 1102 | 'icon' => $sharedProfileIcon, |
||
| 1103 | 'active' => ($show == 'shared_profile' ? 'active' : null), |
||
| 1104 | ]; |
||
| 1105 | |||
| 1106 | $itemMenu[4] = [ |
||
| 1107 | 'item' => get_lang('Friends'), |
||
| 1108 | 'url' => api_get_path(WEB_CODE_PATH).'social/friends.php', |
||
| 1109 | 'icon' => $friendsIcon, |
||
| 1110 | 'active' => ($show == 'friends' ? 'active' : null), |
||
| 1111 | ]; |
||
| 1112 | |||
| 1113 | $itemMenu[5] = [ |
||
| 1114 | 'item' => get_lang('SocialGroups'), |
||
| 1115 | 'url' => api_get_path(WEB_CODE_PATH).'social/groups.php', |
||
| 1116 | 'icon' => $groupsIcon, |
||
| 1117 | 'active' => ($show == 'browse_groups' ? 'active' : null), |
||
| 1118 | ]; |
||
| 1119 | |||
| 1120 | $itemMenu[6] = [ |
||
| 1121 | 'item' => get_lang('Search'), |
||
| 1122 | 'url' => api_get_path(WEB_CODE_PATH).'social/search.php', |
||
| 1123 | 'icon' => $searchIcon, |
||
| 1124 | 'active' => ($show == 'search' ? 'active' : null), |
||
| 1125 | ]; |
||
| 1126 | |||
| 1127 | if (api_get_setting('allow_my_files') === 'false') { |
||
| 1128 | $itemMenu[7] = [ |
||
| 1129 | 'item' => get_lang('MyFiles'), |
||
| 1130 | 'url' => api_get_path(WEB_CODE_PATH).'social/myfiles.php', |
||
| 1131 | 'icon' => $filesIcon, |
||
| 1132 | 'active' => ($show == 'myfiles' ? 'active' : null), |
||
| 1133 | ]; |
||
| 1134 | } |
||
| 1135 | |||
| 1136 | if (api_get_configuration_value('allow_portfolio_tool')) { |
||
| 1137 | $itemMenu[8] = [ |
||
| 1138 | 'item' => get_lang('Portfolio'), |
||
| 1139 | 'url' => api_get_path(WEB_CODE_PATH).'portfolio/index.php', |
||
| 1140 | 'icon' => $portfolioIcon, |
||
| 1141 | 'active' => ($show == 'portfolio' ? 'active' : null), |
||
| 1142 | ]; |
||
| 1143 | } |
||
| 1144 | } |
||
| 1145 | |||
| 1146 | // My friend profile. |
||
| 1147 | if ($user_id != api_get_user_id()) { |
||
| 1148 | $sendMessageIcon = Display::return_icon( |
||
| 1149 | 'new-message.png', |
||
| 1150 | get_lang('SendMessage') |
||
| 1151 | ); |
||
| 1152 | $sendMessageUrl = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?'.http_build_query([ |
||
| 1153 | 'a' => 'get_user_popup', |
||
| 1154 | 'user_id' => $user_id, |
||
| 1155 | ]); |
||
| 1156 | |||
| 1157 | $itemMenu[1] = [ |
||
| 1158 | 'item' => get_lang('SendMessage'), |
||
| 1159 | 'url' => $sendMessageUrl, |
||
| 1160 | 'icon' => $sendMessageIcon, |
||
| 1161 | 'class' => 'ajax', |
||
| 1162 | ]; |
||
| 1163 | if (api_get_configuration_value('allow_portfolio_tool')) { |
||
| 1164 | $itemMenu[8] = [ |
||
| 1165 | 'item' => get_lang('Portfolio'), |
||
| 1166 | 'url' => api_get_path(WEB_CODE_PATH).'portfolio/index.php?user='.$user_id, |
||
| 1167 | 'icon' => $portfolioIcon, |
||
| 1168 | 'active' => ($show == 'portfolio' ? 'active' : null), |
||
| 1169 | ]; |
||
| 1170 | } |
||
| 1171 | } |
||
| 1172 | |||
| 1173 | // Check if I already sent an invitation message |
||
| 1174 | /*$invitation_sent_list = self::get_list_invitation_sent_by_user_id( |
||
| 1175 | api_get_user_id() |
||
| 1176 | ); |
||
| 1177 | |||
| 1178 | if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && |
||
| 1179 | count($invitation_sent_list[$user_id]) > 0 |
||
| 1180 | ) { |
||
| 1181 | $links .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">'. |
||
| 1182 | Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')) |
||
| 1183 | .' '.get_lang('YouAlreadySentAnInvitation').'</a></li>'; |
||
| 1184 | } else { |
||
| 1185 | if (!$show_full_profile) { |
||
| 1186 | $links .= '<li> |
||
| 1187 | <a class="btn-to-send-invitation" href="#" data-send-to="'.$user_id.'" title="'.get_lang('SendInvitation').'">'. |
||
| 1188 | Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')).' '.get_lang('SendInvitation'). |
||
| 1189 | '</a></li>'; |
||
| 1190 | } |
||
| 1191 | }*/ |
||
| 1192 | |||
| 1193 | // Announcements in Courses |
||
| 1194 | |||
| 1195 | /*if ($show_full_profile && $user_id == intval(api_get_user_id())) { |
||
| 1196 | $personal_course_list = UserManager::get_personal_session_course_list($user_id); |
||
| 1197 | $course_list_code = []; |
||
| 1198 | $i = 1; |
||
| 1199 | if (is_array($personal_course_list)) { |
||
| 1200 | foreach ($personal_course_list as $my_course) { |
||
| 1201 | if ($i <= 10) { |
||
| 1202 | $course_list_code[] = ['code' => $my_course['code']]; |
||
| 1203 | } else { |
||
| 1204 | break; |
||
| 1205 | } |
||
| 1206 | $i++; |
||
| 1207 | } |
||
| 1208 | // To avoid repeated courses |
||
| 1209 | $course_list_code = array_unique_dimensional($course_list_code); |
||
| 1210 | } |
||
| 1211 | |||
| 1212 | // Announcements |
||
| 1213 | $my_announcement_by_user_id = intval($user_id); |
||
| 1214 | $announcements = []; |
||
| 1215 | foreach ($course_list_code as $course) { |
||
| 1216 | $course_info = api_get_course_info($course['code']); |
||
| 1217 | if (!empty($course_info)) { |
||
| 1218 | $content = AnnouncementManager::get_all_annoucement_by_user_course( |
||
| 1219 | $course_info['code'], |
||
| 1220 | $my_announcement_by_user_id |
||
| 1221 | ); |
||
| 1222 | |||
| 1223 | if (!empty($content)) { |
||
| 1224 | $url = Display::url( |
||
| 1225 | Display::return_icon( |
||
| 1226 | 'announcement.png', |
||
| 1227 | get_lang('Announcements') |
||
| 1228 | ).$course_info['name'].' ('.$content['count'].')', |
||
| 1229 | api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$course['code'] |
||
| 1230 | ); |
||
| 1231 | $announcements[] = Display::tag('li', $url); |
||
| 1232 | } |
||
| 1233 | } |
||
| 1234 | } |
||
| 1235 | if (!empty($announcements)) { |
||
| 1236 | $html .= '<div class="social_menu_items">'; |
||
| 1237 | $html .= '<ul>'; |
||
| 1238 | foreach ($announcements as $announcement) { |
||
| 1239 | $html .= $announcement; |
||
| 1240 | } |
||
| 1241 | $html .= '</ul>'; |
||
| 1242 | $html .= '</div>'; |
||
| 1243 | } |
||
| 1244 | }*/ |
||
| 1245 | } |
||
| 1246 | |||
| 1247 | // if ($show_delete_account_button) { |
||
| 1248 | $deleteIcon = Display::return_icon( |
||
| 1249 | 'delete.png', |
||
| 1250 | get_lang('Unsubscribe'), |
||
| 1251 | [], |
||
| 1252 | ICON_SIZE_TINY |
||
| 1253 | ); |
||
| 1254 | $itemMenu[9] = [ |
||
| 1255 | 'item' => get_lang('Unsubscribe'), |
||
| 1256 | 'url' => api_get_path(WEB_CODE_PATH).'auth/unsubscribe_account.php', |
||
| 1257 | 'icon' => $deleteIcon, |
||
| 1258 | 'active' => null, |
||
| 1259 | ]; |
||
| 1260 | |||
| 1261 | // } |
||
| 1262 | |||
| 1263 | return Display::dropdownMenu($itemMenu); |
||
| 1264 | } |
||
| 1265 | |||
| 1266 | /** |
||
| 1267 | * Displays a sortable table with the list of online users. |
||
| 1268 | * |
||
| 1269 | * @param array $user_list The list of users to be shown |
||
| 1270 | * @param bool $wrap Whether we want the function to wrap the spans list in a div or not |
||
| 1271 | * |
||
| 1272 | * @return string HTML block or null if and ID was defined |
||
| 1273 | * @assert (null) === false |
||
| 1274 | */ |
||
| 1275 | public static function display_user_list($user_list, $wrap = true) |
||
| 1276 | { |
||
| 1277 | $html = ''; |
||
| 1278 | |||
| 1279 | if (isset($_GET['id']) || count($user_list) < 1) { |
||
| 1280 | return false; |
||
| 1281 | } |
||
| 1282 | |||
| 1283 | $course_url = ''; |
||
| 1284 | if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) { |
||
| 1285 | $course_url = '&cidReq='.Security::remove_XSS($_GET['cidReq']); |
||
| 1286 | } |
||
| 1287 | |||
| 1288 | $hide = api_get_configuration_value('hide_complete_name_in_whoisonline'); |
||
| 1289 | foreach ($user_list as $uid) { |
||
| 1290 | $user_info = api_get_user_info($uid, true); |
||
| 1291 | $lastname = $user_info['lastname']; |
||
| 1292 | $firstname = $user_info['firstname']; |
||
| 1293 | $completeName = $firstname.', '.$lastname; |
||
| 1294 | $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); |
||
| 1295 | $status_icon_chat = null; |
||
| 1296 | if (isset($user_info['user_is_online_in_chat']) && $user_info['user_is_online_in_chat'] == 1) { |
||
| 1297 | $status_icon_chat = Display::return_icon('online.png', get_lang('Online')); |
||
| 1298 | } else { |
||
| 1299 | $status_icon_chat = Display::return_icon('offline.png', get_lang('Offline')); |
||
| 1300 | } |
||
| 1301 | |||
| 1302 | $userPicture = $user_info['avatar']; |
||
| 1303 | $officialCode = ''; |
||
| 1304 | if (api_get_setting('show_official_code_whoisonline') == 'true') { |
||
| 1305 | $officialCode .= '<div class="items-user-official-code"><p style="min-height: 30px;" title="'.get_lang('OfficialCode').'">'.$user_info['official_code'].'</p></div>'; |
||
| 1306 | } |
||
| 1307 | |||
| 1308 | if ($hide === true) { |
||
| 1309 | $completeName = ''; |
||
| 1310 | $firstname = ''; |
||
| 1311 | $lastname = ''; |
||
| 1312 | } |
||
| 1313 | |||
| 1314 | $img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">'; |
||
| 1315 | |||
| 1316 | $url = null; |
||
| 1317 | // Anonymous users can't have access to the profile |
||
| 1318 | if (!api_is_anonymous()) { |
||
| 1319 | if (api_get_setting('allow_social_tool') === 'true') { |
||
| 1320 | $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url; |
||
| 1321 | } else { |
||
| 1322 | $url = '?id='.$uid.$course_url; |
||
| 1323 | } |
||
| 1324 | } else { |
||
| 1325 | $url = null; |
||
| 1326 | } |
||
| 1327 | $name = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>'; |
||
| 1328 | |||
| 1329 | $html .= '<div class="col-xs-6 col-md-2"> |
||
| 1330 | <div class="items-user"> |
||
| 1331 | <div class="items-user-avatar"><a href="'.$url.'">'.$img.'</a></div> |
||
| 1332 | <div class="items-user-name"> |
||
| 1333 | '.$name.' |
||
| 1334 | </div> |
||
| 1335 | '.$officialCode.' |
||
| 1336 | <div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div> |
||
| 1337 | </div> |
||
| 1338 | </div>'; |
||
| 1339 | } |
||
| 1340 | |||
| 1341 | return $html; |
||
| 1342 | } |
||
| 1343 | |||
| 1344 | /** |
||
| 1345 | * Display productions in who is online. |
||
| 1346 | * |
||
| 1347 | * @param int $user_id User id |
||
| 1348 | */ |
||
| 1349 | public static function display_productions($user_id) |
||
| 1350 | { |
||
| 1351 | $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web'); |
||
| 1352 | $sysdir = UserManager::getUserPathById($user_id, 'system'); |
||
| 1353 | $webdir = UserManager::getUserPathById($user_id, 'web'); |
||
| 1354 | |||
| 1355 | if (!is_dir($sysdir)) { |
||
| 1356 | mkdir($sysdir, api_get_permissions_for_new_directories(), true); |
||
| 1357 | } |
||
| 1358 | |||
| 1359 | $productions = UserManager::get_user_productions($user_id); |
||
| 1360 | |||
| 1361 | if (count($productions) > 0) { |
||
| 1362 | echo '<dt><strong>'.get_lang('Productions').'</strong></dt>'; |
||
| 1363 | echo '<dd><ul>'; |
||
| 1364 | foreach ($productions as $file) { |
||
| 1365 | // Only display direct file links to avoid browsing an empty directory |
||
| 1366 | if (is_file($sysdir.$file) && $file != $webdir_array['file']) { |
||
| 1367 | echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>'; |
||
| 1368 | } |
||
| 1369 | // Real productions are under a subdirectory by the User's id |
||
| 1370 | if (is_dir($sysdir.$file)) { |
||
| 1371 | $subs = scandir($sysdir.$file); |
||
| 1372 | foreach ($subs as $my => $sub) { |
||
| 1373 | if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) { |
||
| 1374 | echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>'; |
||
| 1375 | } |
||
| 1376 | } |
||
| 1377 | } |
||
| 1378 | } |
||
| 1379 | echo '</ul></dd>'; |
||
| 1380 | } |
||
| 1381 | } |
||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * @param string $content |
||
| 1385 | * @param string $span_count |
||
| 1386 | * |
||
| 1387 | * @return string |
||
| 1388 | */ |
||
| 1389 | public static function social_wrapper_div($content, $span_count) |
||
| 1390 | { |
||
| 1391 | $span_count = (int) $span_count; |
||
| 1392 | $html = '<div class="span'.$span_count.'">'; |
||
| 1393 | $html .= '<div class="well_border">'; |
||
| 1394 | $html .= $content; |
||
| 1395 | $html .= '</div></div>'; |
||
| 1396 | |||
| 1397 | return $html; |
||
| 1398 | } |
||
| 1399 | |||
| 1400 | /** |
||
| 1401 | * Dummy function. |
||
| 1402 | */ |
||
| 1403 | public static function get_plugins($place = SOCIAL_CENTER_PLUGIN) |
||
| 1426 | } |
||
| 1427 | |||
| 1428 | /** |
||
| 1429 | * Sends a message to someone's wall. |
||
| 1430 | * |
||
| 1431 | * @param int $userId id of author |
||
| 1432 | * @param int $friendId id where we send the message |
||
| 1433 | * @param string $messageContent of the message |
||
| 1434 | * @param int $messageId id parent |
||
| 1435 | * @param string $messageStatus status type of message |
||
| 1436 | * |
||
| 1437 | * @return int |
||
| 1438 | * |
||
| 1439 | * @author Yannick Warnier |
||
| 1440 | */ |
||
| 1441 | public static function sendWallMessage( |
||
| 1474 | } |
||
| 1475 | |||
| 1476 | /** |
||
| 1477 | * Send File attachment (jpg,png). |
||
| 1478 | * |
||
| 1479 | * @author Anibal Copitan |
||
| 1480 | * |
||
| 1481 | * @param int $userId id user |
||
| 1482 | * @param array $fileAttach |
||
| 1483 | * @param int $messageId id message (relation with main message) |
||
| 1484 | * @param string $fileComment description attachment file |
||
| 1485 | * |
||
| 1486 | * @return bool|int |
||
| 1487 | */ |
||
| 1488 | public static function sendWallMessageAttachmentFile( |
||
| 1489 | $userId, |
||
| 1490 | $fileAttach, |
||
| 1491 | $messageId, |
||
| 1492 | $fileComment = '' |
||
| 1493 | ) { |
||
| 1494 | $safeFileName = Database::escape_string($fileAttach['name']); |
||
| 1495 | |||
| 1496 | $extension = strtolower(substr(strrchr($safeFileName, '.'), 1)); |
||
| 1497 | $allowedTypes = api_get_supported_image_extensions(); |
||
| 1498 | |||
| 1499 | $allowedTypes[] = 'mp4'; |
||
| 1500 | $allowedTypes[] = 'webm'; |
||
| 1501 | $allowedTypes[] = 'ogg'; |
||
| 1502 | |||
| 1503 | if (in_array($extension, $allowedTypes)) { |
||
| 1504 | return MessageManager::saveMessageAttachmentFile($fileAttach, $fileComment, $messageId, $userId); |
||
| 1505 | } |
||
| 1506 | |||
| 1507 | return false; |
||
| 1508 | } |
||
| 1509 | |||
| 1510 | /** |
||
| 1511 | * Gets all messages from someone's wall (within specific limits). |
||
| 1512 | * |
||
| 1513 | * @param int $userId id of wall shown |
||
| 1514 | * @param int|string $parentId id message (Post main) |
||
| 1515 | * @param int|array $groupId |
||
| 1516 | * @param int|array $friendId |
||
| 1517 | * @param string $startDate Date from which we want to show the messages, in UTC time |
||
| 1518 | * @param int $start Limit for the number of parent messages we want to show |
||
| 1519 | * @param int $length Wall message query offset |
||
| 1520 | * @param bool $getCount |
||
| 1521 | * @param array $threadList |
||
| 1522 | * |
||
| 1523 | * @return array|int |
||
| 1524 | * |
||
| 1525 | * @author Yannick Warnier |
||
| 1526 | */ |
||
| 1527 | public static function getWallMessages( |
||
| 1528 | $userId, |
||
| 1529 | $parentId = 0, |
||
| 1530 | $groupId = 0, |
||
| 1531 | $friendId = 0, |
||
| 1532 | $startDate = '', |
||
| 1533 | $start = 0, |
||
| 1534 | $length = 10, |
||
| 1535 | $getCount = false, |
||
| 1536 | $threadList = [] |
||
| 1537 | ) { |
||
| 1538 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
| 1539 | |||
| 1540 | $parentId = (int) $parentId; |
||
| 1541 | $userId = (int) $userId; |
||
| 1542 | $start = (int) $start; |
||
| 1543 | $length = (int) $length; |
||
| 1544 | $startDate = Database::escape_string($startDate); |
||
| 1545 | |||
| 1546 | $select = " SELECT |
||
| 1547 | id, |
||
| 1548 | user_sender_id, |
||
| 1549 | user_receiver_id, |
||
| 1550 | send_date, |
||
| 1551 | content, |
||
| 1552 | parent_id, |
||
| 1553 | msg_status, |
||
| 1554 | group_id, |
||
| 1555 | '' as forum_id, |
||
| 1556 | '' as thread_id, |
||
| 1557 | '' as c_id |
||
| 1558 | "; |
||
| 1559 | |||
| 1560 | if ($getCount) { |
||
| 1561 | $select = ' SELECT count(id) count '; |
||
| 1562 | } |
||
| 1563 | |||
| 1564 | $sql = "$select |
||
| 1565 | FROM $tblMessage tm |
||
| 1566 | WHERE |
||
| 1567 | msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND '; |
||
| 1568 | |||
| 1569 | // My own posts |
||
| 1570 | $userReceiverCondition = ' ( |
||
| 1571 | user_receiver_id = '.$userId.' AND |
||
| 1572 | msg_status IN ('.MESSAGE_STATUS_WALL_POST.', '.MESSAGE_STATUS_WALL.') AND |
||
| 1573 | parent_id = '.$parentId.' |
||
| 1574 | )'; |
||
| 1575 | |||
| 1576 | // User condition |
||
| 1577 | $sql .= $userReceiverCondition; |
||
| 1578 | |||
| 1579 | // Get my group posts |
||
| 1580 | $groupCondition = ''; |
||
| 1581 | if (!empty($groupId)) { |
||
| 1582 | if (is_array($groupId)) { |
||
| 1583 | $groupId = array_map('intval', $groupId); |
||
| 1584 | $groupId = implode("','", $groupId); |
||
| 1585 | $groupCondition = " OR ( group_id IN ('$groupId') "; |
||
| 1586 | } else { |
||
| 1587 | $groupId = (int) $groupId; |
||
| 1588 | $groupCondition = " OR ( group_id = '$groupId' "; |
||
| 1589 | } |
||
| 1590 | $groupCondition .= ' AND msg_status IN ('.MESSAGE_STATUS_NEW.', '.MESSAGE_STATUS_UNREAD.')) '; |
||
| 1591 | } |
||
| 1592 | |||
| 1593 | $friendCondition = ''; |
||
| 1594 | // Get my friend posts |
||
| 1595 | if (!empty($friendId)) { |
||
| 1596 | if (is_array($friendId)) { |
||
| 1597 | $friendId = array_map('intval', $friendId); |
||
| 1598 | $friendId = implode("','", $friendId); |
||
| 1599 | $friendCondition = " OR ( user_receiver_id IN ('$friendId') "; |
||
| 1600 | } else { |
||
| 1601 | $friendId = (int) $friendId; |
||
| 1602 | $friendCondition = " OR ( user_receiver_id = '$friendId' "; |
||
| 1603 | } |
||
| 1604 | $friendCondition .= ' AND msg_status IN ('.MESSAGE_STATUS_WALL_POST.') AND parent_id = 0) '; |
||
| 1605 | } |
||
| 1606 | |||
| 1607 | if (!empty($groupCondition) || !empty($friendCondition)) { |
||
| 1608 | $sql .= " $groupCondition $friendCondition "; |
||
| 1609 | } |
||
| 1610 | |||
| 1611 | if (!empty($threadList)) { |
||
| 1612 | if ($getCount) { |
||
| 1613 | $select = ' SELECT count(iid) count '; |
||
| 1614 | } else { |
||
| 1615 | $select = " SELECT |
||
| 1616 | iid, |
||
| 1617 | poster_id, |
||
| 1618 | '' as user_receiver_id, |
||
| 1619 | post_date, |
||
| 1620 | post_text, |
||
| 1621 | '' as parent_id, |
||
| 1622 | ".MESSAGE_STATUS_FORUM.", |
||
| 1623 | '' as group_id, |
||
| 1624 | forum_id, |
||
| 1625 | thread_id, |
||
| 1626 | c_id |
||
| 1627 | "; |
||
| 1628 | } |
||
| 1629 | |||
| 1630 | $threadList = array_map('intval', $threadList); |
||
| 1631 | $threadList = implode("','", $threadList); |
||
| 1632 | $condition = " thread_id IN ('$threadList') "; |
||
| 1633 | $sql .= " |
||
| 1634 | UNION ( |
||
| 1635 | $select |
||
| 1636 | FROM c_forum_post |
||
| 1637 | WHERE $condition |
||
| 1638 | ) |
||
| 1639 | "; |
||
| 1640 | } |
||
| 1641 | |||
| 1642 | if ($getCount) { |
||
| 1643 | $res = Database::query($sql); |
||
| 1644 | $row = Database::fetch_array($res); |
||
| 1645 | |||
| 1646 | return (int) $row['count']; |
||
| 1647 | } |
||
| 1648 | |||
| 1649 | $sql .= ' ORDER BY send_date DESC '; |
||
| 1650 | $sql .= " LIMIT $start, $length "; |
||
| 1651 | |||
| 1652 | $messages = []; |
||
| 1653 | $res = Database::query($sql); |
||
| 1654 | $em = Database::getManager(); |
||
| 1655 | if (Database::num_rows($res) > 0) { |
||
| 1656 | $repo = $em->getRepository('ChamiloCourseBundle:CForumPost'); |
||
| 1657 | $repoThread = $em->getRepository('ChamiloCourseBundle:CForumThread'); |
||
| 1658 | $groups = []; |
||
| 1659 | $forums = []; |
||
| 1660 | $userGroup = new UserGroup(); |
||
| 1661 | $urlGroup = api_get_path(WEB_CODE_PATH).'social/group_view.php?id='; |
||
| 1662 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 1663 | $row['group_info'] = []; |
||
| 1664 | if (!empty($row['group_id'])) { |
||
| 1665 | if (!in_array($row['group_id'], $groups)) { |
||
| 1666 | $group = $userGroup->get($row['group_id']); |
||
| 1667 | $group['url'] = $urlGroup.$group['id']; |
||
| 1668 | $groups[$row['group_id']] = $group; |
||
| 1669 | $row['group_info'] = $group; |
||
| 1670 | } else { |
||
| 1671 | $row['group_info'] = $groups[$row['group_id']]; |
||
| 1672 | } |
||
| 1673 | } |
||
| 1674 | |||
| 1675 | // forums |
||
| 1676 | $row['post_title'] = ''; |
||
| 1677 | $row['forum_title'] = ''; |
||
| 1678 | $row['thread_url'] = ''; |
||
| 1679 | if ($row['msg_status'] == MESSAGE_STATUS_FORUM) { |
||
| 1680 | /** @var \Chamilo\CourseBundle\Entity\CForumPost $post */ |
||
| 1681 | $post = $repo->find($row['id']); |
||
| 1682 | /** @var \Chamilo\CourseBundle\Entity\CForumThread $thread */ |
||
| 1683 | $thread = $repoThread->find($row['thread_id']); |
||
| 1684 | if ($post && $thread) { |
||
| 1685 | $courseInfo = api_get_course_info_by_id($post->getCId()); |
||
| 1686 | $row['post_title'] = $post->getForumId(); |
||
| 1687 | $row['forum_title'] = $thread->getThreadTitle(); |
||
| 1688 | $row['thread_url'] = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
||
| 1689 | 'cidReq' => $courseInfo['code'], |
||
| 1690 | 'forum' => $post->getForumId(), |
||
| 1691 | 'thread' => $post->getThreadId(), |
||
| 1692 | 'post_id' => $post->getIid(), |
||
| 1693 | ]).'#post_id_'.$post->getIid(); |
||
| 1694 | } |
||
| 1695 | } |
||
| 1696 | |||
| 1697 | $messages[] = $row; |
||
| 1698 | } |
||
| 1699 | } |
||
| 1700 | |||
| 1701 | return $messages; |
||
| 1702 | } |
||
| 1703 | |||
| 1704 | /** |
||
| 1705 | * Gets all messages from someone's wall (within specific limits), formatted. |
||
| 1706 | * |
||
| 1707 | * @param int $userId USER ID of the person's wall |
||
| 1708 | * @param array $messageInfo |
||
| 1709 | * @param string $start Start date (from when we want the messages until today) |
||
| 1710 | * @param int $limit Limit to the number of messages we want |
||
| 1711 | * @param int $offset Wall messages offset |
||
| 1712 | * |
||
| 1713 | * @return string HTML formatted string to show messages |
||
| 1714 | */ |
||
| 1715 | public static function getWallPostComments( |
||
| 1716 | $userId, |
||
| 1717 | $messageInfo, |
||
| 1718 | $start = null, |
||
| 1719 | $limit = 10, |
||
| 1720 | $offset = 0 |
||
| 1721 | ) { |
||
| 1722 | $messageId = $messageInfo['id']; |
||
| 1723 | $messages = MessageManager::getMessagesByParent($messageInfo['id'], 0, $offset, $limit); |
||
| 1724 | $formattedList = '<div class="sub-mediapost row">'; |
||
| 1725 | $users = []; |
||
| 1726 | |||
| 1727 | // The messages are ordered by date descendant, for comments we need ascendant |
||
| 1728 | krsort($messages); |
||
| 1729 | foreach ($messages as $message) { |
||
| 1730 | $userIdLoop = $message['user_sender_id']; |
||
| 1731 | if (!isset($users[$userIdLoop])) { |
||
| 1732 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
| 1733 | } |
||
| 1734 | $media = self::processPostComment($message, $users); |
||
| 1735 | $formattedList .= $media; |
||
| 1736 | } |
||
| 1737 | |||
| 1738 | $formattedList .= '</div>'; |
||
| 1739 | $formattedList .= '<div class="mediapost-form">'; |
||
| 1740 | $formattedList .= '<form class="form-horizontal" id="form_comment_'.$messageId.'" name="post_comment" method="POST"> |
||
| 1741 | <div class="col-sm-9"> |
||
| 1742 | <label for="comment" class="hide">'.get_lang('SocialWriteNewComment').'</label> |
||
| 1743 | <input type="hidden" name = "messageId" value="'.$messageId.'" /> |
||
| 1744 | <textarea rows="3" class="form-control" placeholder="'.get_lang('SocialWriteNewComment').'" name="comment" rows="1" ></textarea> |
||
| 1745 | </div> |
||
| 1746 | <div class="col-sm-3"> |
||
| 1747 | <a onclick="submitComment('.$messageId.');" href="javascript:void(0);" name="social_wall_new_msg_submit" class="btn btn-default btn-post"> |
||
| 1748 | <em class="fa fa-pencil"></em> '.get_lang('Post').' |
||
| 1749 | </a> |
||
| 1750 | </div> |
||
| 1751 | </form>'; |
||
| 1752 | $formattedList .= '</div>'; |
||
| 1753 | |||
| 1754 | return $formattedList; |
||
| 1755 | } |
||
| 1756 | |||
| 1757 | /** |
||
| 1758 | * @param array $message |
||
| 1759 | * @param array $users |
||
| 1760 | * |
||
| 1761 | * @return string |
||
| 1762 | */ |
||
| 1763 | public static function processPostComment($message, $users = []) |
||
| 1764 | { |
||
| 1765 | if (empty($message)) { |
||
| 1766 | return false; |
||
| 1767 | } |
||
| 1768 | |||
| 1769 | $date = Display::dateToStringAgoAndLongDate($message['send_date']); |
||
| 1770 | $currentUserId = api_get_user_id(); |
||
| 1771 | $userIdLoop = $message['user_sender_id']; |
||
| 1772 | $receiverId = $message['user_receiver_id']; |
||
| 1773 | $urlImg = api_get_path(WEB_IMG_PATH); |
||
| 1774 | |||
| 1775 | if (!isset($users[$userIdLoop])) { |
||
| 1776 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
| 1777 | } |
||
| 1778 | |||
| 1779 | $iconStatus = ''; |
||
| 1780 | $userStatus = (int) $users[$userIdLoop]['status']; |
||
| 1781 | $isAdmin = self::is_admin($users[$userIdLoop]['id']); |
||
| 1782 | if ($userStatus === 5) { |
||
| 1783 | if ($users[$userIdLoop]['has_certificates']) { |
||
| 1784 | $iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_graduated.svg" width="22px" height="22px">'; |
||
| 1785 | } else { |
||
| 1786 | $iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_student.svg" width="22px" height="22px">'; |
||
| 1787 | } |
||
| 1788 | } else { |
||
| 1789 | if ($userStatus === 1) { |
||
| 1790 | if ($isAdmin) { |
||
| 1791 | $iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_admin.svg" width="22px" height="22px">'; |
||
| 1792 | } else { |
||
| 1793 | $iconStatus = '<img src="'.$urlImg.'icons/svg/identifier_teacher.svg" width="22px" height="22px">'; |
||
| 1794 | } |
||
| 1795 | } |
||
| 1796 | } |
||
| 1797 | |||
| 1798 | $nameComplete = $users[$userIdLoop]['complete_name']; |
||
| 1799 | $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop; |
||
| 1800 | |||
| 1801 | $comment = '<div class="rep-post col-md-12">'; |
||
| 1802 | $comment .= '<div class="col-md-2 col-xs-2 social-post-answers">'; |
||
| 1803 | $comment .= '<div class="user-image pull-right">'; |
||
| 1804 | $comment .= '<a href="'.$url.'"> |
||
| 1805 | <img src="'.$users[$userIdLoop]['avatar'].'" |
||
| 1806 | alt="'.$users[$userIdLoop]['complete_name'].'" |
||
| 1807 | class="avatar-thumb"> |
||
| 1808 | </a>'; |
||
| 1809 | $comment .= '</div>'; |
||
| 1810 | $comment .= '</div>'; |
||
| 1811 | $comment .= '<div class="col-md-7 col-xs-7 social-post-answers">'; |
||
| 1812 | $comment .= '<div class="user-data">'; |
||
| 1813 | $comment .= $iconStatus; |
||
| 1814 | $comment .= '<div class="username"><a href="'.$url.'">'.$nameComplete.'</a> |
||
| 1815 | <span>'.Security::remove_XSS($message['content']).'</span> |
||
| 1816 | </div>'; |
||
| 1817 | $comment .= '<div>'.$date.'</div>'; |
||
| 1818 | $comment .= '<br />'; |
||
| 1819 | $comment .= '</div>'; |
||
| 1820 | $comment .= '</div>'; |
||
| 1821 | |||
| 1822 | $comment .= '<div class="col-md-3 col-xs-3 social-post-answers">'; |
||
| 1823 | $comment .= '<div class="pull-right btn-group btn-group-sm">'; |
||
| 1824 | |||
| 1825 | $comment .= MessageManager::getLikesButton( |
||
| 1826 | $message['id'], |
||
| 1827 | $currentUserId |
||
| 1828 | ); |
||
| 1829 | |||
| 1830 | $isOwnWall = $currentUserId == $userIdLoop || $currentUserId == $receiverId; |
||
| 1831 | if ($isOwnWall) { |
||
| 1832 | $comment .= Display::url( |
||
| 1833 | Display::returnFontAwesomeIcon('trash', '', true), |
||
| 1834 | 'javascript:void(0)', |
||
| 1835 | [ |
||
| 1836 | 'id' => 'message_'.$message['id'], |
||
| 1837 | 'title' => get_lang('SocialMessageDelete'), |
||
| 1838 | 'onclick' => 'deleteComment('.$message['id'].')', |
||
| 1839 | 'class' => 'btn btn-default', |
||
| 1840 | ] |
||
| 1841 | ); |
||
| 1842 | } |
||
| 1843 | $comment .= '</div>'; |
||
| 1844 | $comment .= '</div>'; |
||
| 1845 | $comment .= '</div>'; |
||
| 1846 | |||
| 1847 | return $comment; |
||
| 1848 | } |
||
| 1849 | |||
| 1850 | /** |
||
| 1851 | * @param array $message |
||
| 1852 | * |
||
| 1853 | * @return array |
||
| 1854 | */ |
||
| 1855 | public static function getAttachmentPreviewList($message) |
||
| 1856 | { |
||
| 1857 | $messageId = $message['id']; |
||
| 1858 | |||
| 1859 | $list = []; |
||
| 1860 | |||
| 1861 | if (empty($message['group_id'])) { |
||
| 1862 | $files = MessageManager::getAttachmentList($messageId); |
||
| 1863 | if ($files) { |
||
| 1864 | $downloadUrl = api_get_path(WEB_CODE_PATH).'social/download.php?message_id='.$messageId; |
||
| 1865 | foreach ($files as $row_file) { |
||
| 1866 | $url = $downloadUrl.'&attachment_id='.$row_file['id']; |
||
| 1867 | $display = Display::fileHtmlGuesser($row_file['filename'], $url); |
||
| 1868 | $list[] = $display; |
||
| 1869 | } |
||
| 1870 | } |
||
| 1871 | } else { |
||
| 1872 | $list = MessageManager::getAttachmentLinkList($messageId); |
||
| 1873 | } |
||
| 1874 | |||
| 1875 | return $list; |
||
| 1876 | } |
||
| 1877 | |||
| 1878 | /** |
||
| 1879 | * @param array $message |
||
| 1880 | * |
||
| 1881 | * @return string |
||
| 1882 | */ |
||
| 1883 | public static function getPostAttachment($message) |
||
| 1884 | { |
||
| 1885 | $previews = self::getAttachmentPreviewList($message); |
||
| 1886 | |||
| 1887 | if (empty($previews)) { |
||
| 1888 | return ''; |
||
| 1889 | } |
||
| 1890 | |||
| 1891 | return implode('', $previews); |
||
| 1892 | } |
||
| 1893 | |||
| 1894 | /** |
||
| 1895 | * @param array $messages |
||
| 1896 | * |
||
| 1897 | * @return array |
||
| 1898 | */ |
||
| 1899 | public static function formatWallMessages($messages) |
||
| 1900 | { |
||
| 1901 | $data = []; |
||
| 1902 | $users = []; |
||
| 1903 | foreach ($messages as $key => $message) { |
||
| 1904 | $userIdLoop = $message['user_sender_id']; |
||
| 1905 | $userFriendIdLoop = $message['user_receiver_id']; |
||
| 1906 | if (!isset($users[$userIdLoop])) { |
||
| 1907 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
| 1908 | } |
||
| 1909 | |||
| 1910 | if (!isset($users[$userFriendIdLoop])) { |
||
| 1911 | $users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop); |
||
| 1912 | } |
||
| 1913 | |||
| 1914 | $html = self::headerMessagePost( |
||
| 1915 | $users[$userIdLoop], |
||
| 1916 | $users[$userFriendIdLoop], |
||
| 1917 | $message |
||
| 1918 | ); |
||
| 1919 | |||
| 1920 | $data[$key] = $message; |
||
| 1921 | $data[$key]['html'] = $html; |
||
| 1922 | } |
||
| 1923 | |||
| 1924 | return $data; |
||
| 1925 | } |
||
| 1926 | |||
| 1927 | /** |
||
| 1928 | * get html data with OpenGrap passing the URL. |
||
| 1929 | * |
||
| 1930 | * @param $link url |
||
| 1931 | * |
||
| 1932 | * @return string data html |
||
| 1933 | */ |
||
| 1934 | public static function readContentWithOpenGraph($link) |
||
| 1960 | } |
||
| 1961 | |||
| 1962 | /** |
||
| 1963 | * verify if Url Exist - Using Curl. |
||
| 1964 | * |
||
| 1965 | * @param $uri url |
||
| 1966 | * |
||
| 1967 | * @return bool |
||
| 1968 | */ |
||
| 1969 | public static function verifyUrl($uri) |
||
| 1970 | { |
||
| 1971 | $curl = curl_init($uri); |
||
| 1972 | curl_setopt($curl, CURLOPT_FAILONERROR, true); |
||
| 1973 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
||
| 1974 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
| 1975 | curl_setopt($curl, CURLOPT_TIMEOUT, 15); |
||
| 1976 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); |
||
| 1977 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
||
| 1978 | curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); |
||
| 1979 | $response = curl_exec($curl); |
||
| 1980 | curl_close($curl); |
||
| 1981 | if (!empty($response)) { |
||
| 1982 | return true; |
||
| 1983 | } |
||
| 1984 | |||
| 1985 | return false; |
||
| 1986 | } |
||
| 1987 | |||
| 1988 | /** |
||
| 1989 | * Soft delete a message and his chidren. |
||
| 1990 | * |
||
| 1991 | * @param int $id id message to delete |
||
| 1992 | * |
||
| 1993 | * @return bool status query |
||
| 1994 | */ |
||
| 1995 | public static function deleteMessage($id) |
||
| 1996 | { |
||
| 1997 | $id = (int) $id; |
||
| 1998 | $messageInfo = MessageManager::get_message_by_id($id); |
||
| 1999 | if (!empty($messageInfo)) { |
||
| 2000 | // Delete comments too |
||
| 2001 | $messages = MessageManager::getMessagesByParent($id); |
||
| 2002 | if (!empty($messages)) { |
||
| 2003 | foreach ($messages as $message) { |
||
| 2004 | self::deleteMessage($message['id']); |
||
| 2005 | } |
||
| 2006 | } |
||
| 2007 | |||
| 2008 | // Soft delete message |
||
| 2009 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
| 2010 | $statusMessage = MESSAGE_STATUS_WALL_DELETE; |
||
| 2011 | $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' "; |
||
| 2012 | Database::query($sql); |
||
| 2013 | |||
| 2014 | MessageManager::delete_message_attachment_file($id, $messageInfo['user_sender_id']); |
||
| 2015 | MessageManager::delete_message_attachment_file($id, $messageInfo['user_receiver_id']); |
||
| 2016 | |||
| 2017 | return true; |
||
| 2018 | } |
||
| 2019 | |||
| 2020 | return false; |
||
| 2021 | } |
||
| 2022 | |||
| 2023 | /** |
||
| 2024 | * Generate the social block for a user. |
||
| 2025 | * |
||
| 2026 | * @param Template $template |
||
| 2027 | * @param int $userId The user id |
||
| 2028 | * @param string $groupBlock Optional. Highlight link possible values: |
||
| 2029 | * group_add, home, messages, messages_inbox, messages_compose, |
||
| 2030 | * messages_outbox, invitations, shared_profile, friends, groups, search |
||
| 2031 | * @param int $groupId Optional. Group ID |
||
| 2032 | * @param bool $show_full_profile |
||
| 2033 | * |
||
| 2034 | * @return string The HTML code with the social block |
||
| 2035 | */ |
||
| 2036 | public static function setSocialUserBlock( |
||
| 2145 | } |
||
| 2146 | |||
| 2147 | /** |
||
| 2148 | * @param int $user_id |
||
| 2149 | * @param $link_shared |
||
| 2150 | * @param $show_full_profile |
||
| 2151 | * |
||
| 2152 | * @return string |
||
| 2153 | */ |
||
| 2154 | public static function listMyFriends($user_id, $link_shared, $show_full_profile) |
||
| 2155 | { |
||
| 2156 | //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT |
||
| 2157 | $friends = self::get_friends($user_id, USER_RELATION_TYPE_FRIEND); |
||
| 2158 | $number_of_images = 30; |
||
| 2159 | $number_friends = count($friends); |
||
| 2160 | $friendHtml = ''; |
||
| 2161 | if ($number_friends != 0) { |
||
| 2162 | if ($number_friends > $number_of_images) { |
||
| 2163 | if (api_get_user_id() == $user_id) { |
||
| 2164 | $friendHtml .= ' <span><a href="friends.php">'.get_lang('SeeAll').'</a></span>'; |
||
| 2165 | } else { |
||
| 2166 | $friendHtml .= ' <span>' |
||
| 2167 | .'<a href="'.api_get_path(WEB_CODE_PATH).'social/profile_friends_and_groups.inc.php' |
||
| 2168 | .'?view=friends&height=390&width=610&user_id='.$user_id.'"' |
||
| 2169 | .'class="ajax" data-title="'.get_lang('SeeAll').'" title="'.get_lang('SeeAll').'" >'.get_lang('SeeAll').'</a></span>'; |
||
| 2170 | } |
||
| 2171 | } |
||
| 2172 | |||
| 2173 | $friendHtml .= '<ul class="nav nav-list">'; |
||
| 2174 | $j = 1; |
||
| 2175 | for ($k = 0; $k < $number_friends; $k++) { |
||
| 2176 | if ($j > $number_of_images) { |
||
| 2177 | break; |
||
| 2178 | } |
||
| 2179 | if (isset($friends[$k])) { |
||
| 2180 | $friend = $friends[$k]; |
||
| 2181 | $name_user = api_get_person_name($friend['firstName'], $friend['lastName']); |
||
| 2182 | $user_info_friend = api_get_user_info($friend['friend_user_id'], true); |
||
| 2183 | |||
| 2184 | if ($user_info_friend['user_is_online']) { |
||
| 2185 | $statusIcon = Display::span('', ['class' => 'online_user_in_text']); |
||
| 2186 | } else { |
||
| 2187 | $statusIcon = Display::span('', ['class' => 'offline_user_in_text']); |
||
| 2188 | } |
||
| 2189 | |||
| 2190 | $friendHtml .= '<li>'; |
||
| 2191 | $friendHtml .= '<div>'; |
||
| 2192 | |||
| 2193 | // the height = 92 must be the same in the image_friend_network span style in default.css |
||
| 2194 | $friends_profile = UserManager::getUserPicture( |
||
| 2195 | $friend['friend_user_id'], |
||
| 2196 | USER_IMAGE_SIZE_SMALL |
||
| 2197 | ); |
||
| 2198 | $friendHtml .= '<img src="'.$friends_profile.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'"/>'; |
||
| 2199 | $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared; |
||
| 2200 | $friendHtml .= $statusIcon.'<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'">'.$name_user.'</a>'; |
||
| 2201 | $friendHtml .= '</div>'; |
||
| 2202 | $friendHtml .= '</li>'; |
||
| 2203 | } |
||
| 2204 | $j++; |
||
| 2205 | } |
||
| 2206 | $friendHtml .= '</ul>'; |
||
| 2207 | } else { |
||
| 2208 | $friendHtml .= '<div class="">'.get_lang('NoFriendsInYourContactList').'<br /> |
||
| 2209 | <a class="btn btn-primary" href="'.api_get_path(WEB_PATH).'whoisonline.php"> |
||
| 2210 | <em class="fa fa-search"></em> '.get_lang('TryAndFindSomeFriends').'</a></div>'; |
||
| 2211 | } |
||
| 2212 | |||
| 2213 | $friendHtml = Display::panel($friendHtml, get_lang('SocialFriend').' ('.$number_friends.')'); |
||
| 2214 | |||
| 2215 | return $friendHtml; |
||
| 2216 | } |
||
| 2217 | |||
| 2218 | /** |
||
| 2219 | * @param int $user_id |
||
| 2220 | * @param $link_shared |
||
| 2221 | * @param bool $showLinkToChat |
||
| 2222 | * |
||
| 2223 | * @return string |
||
| 2224 | */ |
||
| 2225 | public static function listMyFriendsBlock($user_id, $link_shared = '', $showLinkToChat = false) |
||
| 2226 | { |
||
| 2227 | //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT |
||
| 2228 | $friends = self::get_friends($user_id, USER_RELATION_TYPE_FRIEND); |
||
| 2229 | $numberFriends = count($friends); |
||
| 2230 | $friendHtml = ''; |
||
| 2231 | |||
| 2232 | if (!empty($numberFriends)) { |
||
| 2233 | $friendHtml .= '<div class="list-group contact-list">'; |
||
| 2234 | $j = 1; |
||
| 2235 | |||
| 2236 | usort( |
||
| 2237 | $friends, |
||
| 2238 | function ($a, $b) { |
||
| 2239 | return strcmp($b['user_info']['user_is_online_in_chat'], $a['user_info']['user_is_online_in_chat']); |
||
| 2240 | } |
||
| 2241 | ); |
||
| 2242 | |||
| 2243 | foreach ($friends as $friend) { |
||
| 2244 | if ($j > $numberFriends) { |
||
| 2245 | break; |
||
| 2246 | } |
||
| 2247 | $name_user = api_get_person_name($friend['firstName'], $friend['lastName']); |
||
| 2248 | $user_info_friend = api_get_user_info($friend['friend_user_id'], true); |
||
| 2249 | |||
| 2250 | $statusIcon = Display::return_icon('statusoffline.png', get_lang('Offline')); |
||
| 2251 | $status = 0; |
||
| 2252 | if (!empty($user_info_friend['user_is_online_in_chat'])) { |
||
| 2253 | $statusIcon = Display::return_icon('statusonline.png', get_lang('Online')); |
||
| 2254 | $status = 1; |
||
| 2255 | } |
||
| 2256 | |||
| 2257 | $friendAvatarMedium = UserManager::getUserPicture( |
||
| 2258 | $friend['friend_user_id'], |
||
| 2259 | USER_IMAGE_SIZE_MEDIUM |
||
| 2260 | ); |
||
| 2261 | $friendAvatarSmall = UserManager::getUserPicture( |
||
| 2262 | $friend['friend_user_id'], |
||
| 2263 | USER_IMAGE_SIZE_SMALL |
||
| 2264 | ); |
||
| 2265 | $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>'; |
||
| 2266 | |||
| 2267 | $relation = self::get_relation_between_contacts( |
||
| 2268 | $friend['friend_user_id'], |
||
| 2269 | api_get_user_id() |
||
| 2270 | ); |
||
| 2271 | |||
| 2272 | if ($showLinkToChat) { |
||
| 2273 | $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">'; |
||
| 2274 | $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
||
| 2275 | $friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
||
| 2276 | } else { |
||
| 2277 | $link_shared = empty($link_shared) ? '' : '&'.$link_shared; |
||
| 2278 | $friendHtml .= '<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'" class="list-group-item">'; |
||
| 2279 | $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
||
| 2280 | $friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
||
| 2281 | } |
||
| 2282 | |||
| 2283 | $friendHtml .= '</a>'; |
||
| 2284 | |||
| 2285 | $j++; |
||
| 2286 | } |
||
| 2287 | $friendHtml .= '</div>'; |
||
| 2288 | } |
||
| 2289 | |||
| 2290 | return $friendHtml; |
||
| 2291 | } |
||
| 2292 | |||
| 2293 | /** |
||
| 2294 | * @param string $urlForm |
||
| 2295 | * |
||
| 2296 | * @return string |
||
| 2297 | */ |
||
| 2298 | public static function getWallForm($urlForm) |
||
| 2299 | { |
||
| 2300 | $userId = isset($_GET['u']) ? '?u='.intval($_GET['u']) : ''; |
||
| 2301 | $form = new FormValidator( |
||
| 2302 | 'social_wall_main', |
||
| 2303 | 'post', |
||
| 2304 | $urlForm.$userId, |
||
| 2305 | null, |
||
| 2306 | ['enctype' => 'multipart/form-data'], |
||
| 2307 | FormValidator::LAYOUT_HORIZONTAL |
||
| 2308 | ); |
||
| 2309 | |||
| 2310 | $socialWallPlaceholder = isset($_GET['u']) ? get_lang('SocialWallWriteNewPostToFriend') : get_lang( |
||
| 2311 | 'SocialWallWhatAreYouThinkingAbout' |
||
| 2312 | ); |
||
| 2313 | |||
| 2314 | $form->addTextarea( |
||
| 2315 | 'social_wall_new_msg_main', |
||
| 2316 | null, |
||
| 2317 | [ |
||
| 2318 | 'placeholder' => $socialWallPlaceholder, |
||
| 2319 | 'cols-size' => [1, 10, 1], |
||
| 2320 | 'aria-label' => $socialWallPlaceholder, |
||
| 2321 | ] |
||
| 2322 | ); |
||
| 2323 | $form->addHtml('<div class="form-group">'); |
||
| 2324 | $form->addHtml('<div class="col-sm-4 col-md-offset-1">'); |
||
| 2325 | $form->addFile('picture', get_lang('UploadFile'), ['custom' => true]); |
||
| 2326 | $form->addHtml('</div>'); |
||
| 2327 | $form->addHtml('<div class="col-sm-6">'); |
||
| 2328 | $form->addButtonSend( |
||
| 2329 | get_lang('Post'), |
||
| 2330 | 'wall_post_button', |
||
| 2331 | false, |
||
| 2332 | [ |
||
| 2333 | 'cols-size' => [1, 10, 1], |
||
| 2334 | 'custom' => true, |
||
| 2335 | ] |
||
| 2336 | ); |
||
| 2337 | $form->addHtml('</div>'); |
||
| 2338 | $form->addHtml('</div>'); |
||
| 2339 | |||
| 2340 | $form->addHidden('url_content', ''); |
||
| 2341 | $html = Display::panel($form->returnForm(), get_lang('SocialWall')); |
||
| 2342 | |||
| 2343 | return $html; |
||
| 2344 | } |
||
| 2345 | |||
| 2346 | /** |
||
| 2347 | * @param int $userId |
||
| 2348 | * @param int $start |
||
| 2349 | * @param int $length |
||
| 2350 | * @param array $threadList |
||
| 2351 | * |
||
| 2352 | * @return array |
||
| 2353 | */ |
||
| 2354 | public static function getMyWallMessages($userId, $start = 0, $length = 10, $threadList = []) |
||
| 2355 | { |
||
| 2356 | $userGroup = new UserGroup(); |
||
| 2357 | $groups = $userGroup->get_groups_by_user($userId, [GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_ADMIN]); |
||
| 2358 | $groupList = []; |
||
| 2359 | if (!empty($groups)) { |
||
| 2360 | $groupList = array_column($groups, 'id'); |
||
| 2361 | } |
||
| 2362 | |||
| 2363 | $friends = self::get_friends($userId, USER_RELATION_TYPE_FRIEND); |
||
| 2364 | $friendList = []; |
||
| 2365 | if (!empty($friends)) { |
||
| 2366 | $friendList = array_column($friends, 'friend_user_id'); |
||
| 2367 | } |
||
| 2368 | |||
| 2369 | $messages = self::getWallMessages( |
||
| 2370 | $userId, |
||
| 2371 | 0, |
||
| 2372 | $groupList, |
||
| 2373 | $friendList, |
||
| 2374 | '', |
||
| 2375 | $start, |
||
| 2376 | $length, |
||
| 2377 | false, |
||
| 2378 | $threadList |
||
| 2379 | ); |
||
| 2380 | |||
| 2381 | $countPost = self::getCountWallMessagesByUser($userId, $groupList, $friendList, $threadList); |
||
| 2382 | $messages = self::formatWallMessages($messages); |
||
| 2383 | |||
| 2384 | $html = ''; |
||
| 2385 | foreach ($messages as $message) { |
||
| 2386 | $post = $message['html']; |
||
| 2387 | $comments = ''; |
||
| 2388 | if ($message['msg_status'] == MESSAGE_STATUS_WALL_POST) { |
||
| 2389 | $comments = self::getWallPostComments($userId, $message); |
||
| 2390 | } |
||
| 2391 | |||
| 2392 | $html .= self::wrapPost($message, $post.$comments); |
||
| 2393 | } |
||
| 2394 | |||
| 2395 | return [ |
||
| 2396 | 'posts' => $html, |
||
| 2397 | 'count' => $countPost, |
||
| 2398 | ]; |
||
| 2399 | } |
||
| 2400 | |||
| 2401 | /** |
||
| 2402 | * @param string $message |
||
| 2403 | * @param string $content |
||
| 2404 | * |
||
| 2405 | * @return string |
||
| 2406 | */ |
||
| 2407 | public static function wrapPost($message, $content) |
||
| 2408 | { |
||
| 2409 | return Display::panel($content, '', |
||
| 2410 | '', |
||
| 2411 | 'default', |
||
| 2412 | '', |
||
| 2413 | 'post_'.$message['id'] |
||
| 2414 | ); |
||
| 2415 | } |
||
| 2416 | |||
| 2417 | /** |
||
| 2418 | * @param int $userId |
||
| 2419 | * |
||
| 2420 | * @return int |
||
| 2421 | */ |
||
| 2422 | public static function getCountWallMessagesByUser($userId, $groupList = [], $friendList = [], $threadList = []) |
||
| 2423 | { |
||
| 2424 | $count = self::getWallMessages( |
||
| 2425 | $userId, |
||
| 2426 | 0, |
||
| 2427 | $groupList, |
||
| 2428 | $friendList, |
||
| 2429 | '', |
||
| 2430 | 0, |
||
| 2431 | 0, |
||
| 2432 | true, |
||
| 2433 | $threadList |
||
| 2434 | ); |
||
| 2435 | |||
| 2436 | return $count; |
||
| 2437 | } |
||
| 2438 | |||
| 2439 | /** |
||
| 2440 | * @param int $userId |
||
| 2441 | * |
||
| 2442 | * @return string |
||
| 2443 | */ |
||
| 2444 | public static function getWallMessagesByUser($userId) |
||
| 2445 | { |
||
| 2446 | $messages = self::getWallMessages($userId); |
||
| 2447 | $messages = self::formatWallMessages($messages); |
||
| 2448 | |||
| 2449 | $html = ''; |
||
| 2450 | foreach ($messages as $message) { |
||
| 2451 | $post = $message['html']; |
||
| 2452 | $comments = self::getWallPostComments($userId, $message); |
||
| 2453 | $html .= self::wrapPost($message, $post.$comments); |
||
| 2454 | } |
||
| 2455 | |||
| 2456 | return $html; |
||
| 2457 | } |
||
| 2458 | |||
| 2459 | /** |
||
| 2460 | * Get HTML code block for user skills. |
||
| 2461 | * |
||
| 2462 | * @param int $userId The user ID |
||
| 2463 | * @param string $orientation |
||
| 2464 | * |
||
| 2465 | * @return string |
||
| 2466 | */ |
||
| 2467 | public static function getSkillBlock($userId, $orientation = 'horizontal') |
||
| 2468 | { |
||
| 2469 | if (Skill::isAllowed($userId, false) === false) { |
||
| 2470 | return ''; |
||
| 2471 | } |
||
| 2472 | |||
| 2473 | $skill = new Skill(); |
||
| 2474 | $ranking = $skill->getUserSkillRanking($userId); |
||
| 2475 | |||
| 2476 | $template = new Template(null, false, false, false, false, false); |
||
| 2477 | $template->assign('ranking', $ranking); |
||
| 2478 | $template->assign('orientation', $orientation); |
||
| 2479 | $template->assign('skills', $skill->getUserSkillsTable($userId, 0, 0, false)['skills']); |
||
| 2480 | $template->assign('user_id', $userId); |
||
| 2481 | $template->assign('show_skills_report_link', api_is_student() || api_is_student_boss() || api_is_drh()); |
||
| 2482 | |||
| 2483 | $skillBlock = $template->get_template('social/skills_block.tpl'); |
||
| 2484 | |||
| 2485 | return $template->fetch($skillBlock); |
||
| 2486 | } |
||
| 2487 | |||
| 2488 | /** |
||
| 2489 | * @param int $user_id |
||
| 2490 | * |
||
| 2491 | * @return string|array |
||
| 2492 | */ |
||
| 2493 | public static function getExtraFieldBlock($user_id, $isArray = false) |
||
| 2494 | { |
||
| 2495 | $fieldVisibility = api_get_configuration_value('profile_fields_visibility'); |
||
| 2496 | $fieldVisibilityKeys = []; |
||
| 2497 | if (isset($fieldVisibility['options'])) { |
||
| 2498 | $fieldVisibility = $fieldVisibility['options']; |
||
| 2499 | $fieldVisibilityKeys = array_keys($fieldVisibility); |
||
| 2500 | } |
||
| 2501 | |||
| 2502 | $t_ufo = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS); |
||
| 2503 | $extra_user_data = UserManager::get_extra_user_data($user_id); |
||
| 2504 | |||
| 2505 | $extra_information = ''; |
||
| 2506 | if (is_array($extra_user_data) && count($extra_user_data) > 0) { |
||
| 2507 | $extra_information_value = ''; |
||
| 2508 | $extraField = new ExtraField('user'); |
||
| 2509 | $listType = []; |
||
| 2510 | $extraFieldItem = []; |
||
| 2511 | foreach ($extra_user_data as $key => $data) { |
||
| 2512 | if (empty($data)) { |
||
| 2513 | continue; |
||
| 2514 | } |
||
| 2515 | if (in_array($key, $fieldVisibilityKeys) && $fieldVisibility[$key] === false) { |
||
| 2516 | continue; |
||
| 2517 | } |
||
| 2518 | |||
| 2519 | // Avoiding parameters |
||
| 2520 | if (in_array( |
||
| 2521 | $key, |
||
| 2522 | [ |
||
| 2523 | 'mail_notify_invitation', |
||
| 2524 | 'mail_notify_message', |
||
| 2525 | 'mail_notify_group_message', |
||
| 2526 | ] |
||
| 2527 | )) { |
||
| 2528 | continue; |
||
| 2529 | } |
||
| 2530 | // get display text, visibility and type from user_field table |
||
| 2531 | $field_variable = str_replace('extra_', '', $key); |
||
| 2532 | |||
| 2533 | $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable( |
||
| 2534 | $field_variable |
||
| 2535 | ); |
||
| 2536 | |||
| 2537 | if (in_array($extraFieldInfo['variable'], ['skype', 'linkedin_url'])) { |
||
| 2538 | continue; |
||
| 2539 | } |
||
| 2540 | |||
| 2541 | // if is not visible skip |
||
| 2542 | if ($extraFieldInfo['visible_to_self'] != 1) { |
||
| 2543 | continue; |
||
| 2544 | } |
||
| 2545 | |||
| 2546 | // if is not visible to others skip also |
||
| 2547 | if ($extraFieldInfo['visible_to_others'] != 1) { |
||
| 2548 | continue; |
||
| 2549 | } |
||
| 2550 | |||
| 2551 | if (is_array($data)) { |
||
| 2552 | switch ($extraFieldInfo['field_type']) { |
||
| 2553 | case ExtraField::FIELD_TYPE_RADIO: |
||
| 2554 | $objEfOption = new ExtraFieldOption('user'); |
||
| 2555 | $value = $data['extra_'.$extraFieldInfo['variable']]; |
||
| 2556 | $optionInfo = $objEfOption->get_field_option_by_field_and_option( |
||
| 2557 | $extraFieldInfo['id'], |
||
| 2558 | $value |
||
| 2559 | ); |
||
| 2560 | |||
| 2561 | if ($optionInfo && isset($optionInfo[0])) { |
||
| 2562 | $optionInfo = $optionInfo[0]; |
||
| 2563 | $extraFieldItem = [ |
||
| 2564 | 'variable' => $extraFieldInfo['variable'], |
||
| 2565 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2566 | 'value' => $optionInfo['display_text'], |
||
| 2567 | ]; |
||
| 2568 | } else { |
||
| 2569 | $extraFieldItem = [ |
||
| 2570 | 'variable' => $extraFieldInfo['variable'], |
||
| 2571 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2572 | 'value' => implode(',', $data), |
||
| 2573 | ]; |
||
| 2574 | } |
||
| 2575 | break; |
||
| 2576 | default: |
||
| 2577 | $extra_information_value .= |
||
| 2578 | '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).' ' |
||
| 2579 | .' '.implode(',', $data).'</li>'; |
||
| 2580 | $extraFieldItem = [ |
||
| 2581 | 'variable' => $extraFieldInfo['variable'], |
||
| 2582 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2583 | 'value' => implode(',', $data), |
||
| 2584 | ]; |
||
| 2585 | break; |
||
| 2586 | } |
||
| 2587 | } else { |
||
| 2588 | switch ($extraFieldInfo['field_type']) { |
||
| 2589 | case ExtraField::FIELD_TYPE_RADIO: |
||
| 2590 | $objEfOption = new ExtraFieldOption('user'); |
||
| 2591 | $optionInfo = $objEfOption->get_field_option_by_field_and_option($extraFieldInfo['id'], $extraFieldInfo['value']); |
||
| 2592 | break; |
||
| 2593 | case ExtraField::FIELD_TYPE_GEOLOCALIZATION_COORDINATES: |
||
| 2594 | case ExtraField::FIELD_TYPE_GEOLOCALIZATION: |
||
| 2595 | $data = explode('::', $data); |
||
| 2596 | $data = $data[0]; |
||
| 2597 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '.$data.'</li>'; |
||
| 2598 | $extraFieldItem = [ |
||
| 2599 | 'variable' => $extraFieldInfo['variable'], |
||
| 2600 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2601 | 'value' => $data, |
||
| 2602 | ]; |
||
| 2603 | break; |
||
| 2604 | case ExtraField::FIELD_TYPE_DOUBLE_SELECT: |
||
| 2605 | $id_options = explode('::', $data); |
||
| 2606 | $value_options = []; |
||
| 2607 | // get option display text from user_field_options table |
||
| 2608 | foreach ($id_options as $id_option) { |
||
| 2609 | $sql = "SELECT display_text |
||
| 2610 | FROM $t_ufo |
||
| 2611 | WHERE id = '$id_option'"; |
||
| 2612 | $res_options = Database::query($sql); |
||
| 2613 | $row_options = Database::fetch_row($res_options); |
||
| 2614 | $value_options[] = $row_options[0]; |
||
| 2615 | } |
||
| 2616 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': ' |
||
| 2617 | .' '.implode(' ', $value_options).'</li>'; |
||
| 2618 | $extraFieldItem = [ |
||
| 2619 | 'variable' => $extraFieldInfo['variable'], |
||
| 2620 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2621 | 'value' => $value_options, |
||
| 2622 | ]; |
||
| 2623 | break; |
||
| 2624 | case ExtraField::FIELD_TYPE_TAG: |
||
| 2625 | $user_tags = UserManager::get_user_tags($user_id, $extraFieldInfo['id']); |
||
| 2626 | |||
| 2627 | $tag_tmp = ''; |
||
| 2628 | foreach ($user_tags as $tags) { |
||
| 2629 | $tag_tmp .= '<a class="label label_tag"' |
||
| 2630 | .' href="'.api_get_path(WEB_PATH).'main/social/search.php?q='.$tags['tag'].'">' |
||
| 2631 | .$tags['tag'] |
||
| 2632 | .'</a>'; |
||
| 2633 | } |
||
| 2634 | if (is_array($user_tags) && count($user_tags) > 0) { |
||
| 2635 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': ' |
||
| 2636 | .' '.$tag_tmp.'</li>'; |
||
| 2637 | } |
||
| 2638 | $extraFieldItem = [ |
||
| 2639 | 'variable' => $extraFieldInfo['variable'], |
||
| 2640 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2641 | 'value' => $tag_tmp, |
||
| 2642 | ]; |
||
| 2643 | break; |
||
| 2644 | case ExtraField::FIELD_TYPE_SOCIAL_PROFILE: |
||
| 2645 | $icon_path = UserManager::get_favicon_from_url($data); |
||
| 2646 | if (self::verifyUrl($icon_path) == false) { |
||
| 2647 | break; |
||
| 2648 | } |
||
| 2649 | $bottom = '0.2'; |
||
| 2650 | //quick hack for hi5 |
||
| 2651 | $domain = parse_url($icon_path, PHP_URL_HOST); |
||
| 2652 | if ($domain == 'www.hi5.com' || $domain == 'hi5.com') { |
||
| 2653 | $bottom = '-0.8'; |
||
| 2654 | } |
||
| 2655 | $data = '<a href="'.$data.'">' |
||
| 2656 | .'<img src="'.$icon_path.'" alt="icon"' |
||
| 2657 | .' style="margin-right:0.5em;margin-bottom:'.$bottom.'em;" />' |
||
| 2658 | .$extraFieldInfo['display_text'] |
||
| 2659 | .'</a>'; |
||
| 2660 | $extra_information_value .= '<li class="list-group-item">'.$data.'</li>'; |
||
| 2661 | $extraFieldItem = [ |
||
| 2662 | 'variable' => $extraFieldInfo['variable'], |
||
| 2663 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2664 | 'value' => $data, |
||
| 2665 | ]; |
||
| 2666 | break; |
||
| 2667 | case ExtraField::FIELD_TYPE_SELECT_WITH_TEXT_FIELD: |
||
| 2668 | $parsedData = explode('::', $data); |
||
| 2669 | |||
| 2670 | if (!$parsedData) { |
||
| 2671 | break; |
||
| 2672 | } |
||
| 2673 | |||
| 2674 | $objEfOption = new ExtraFieldOption('user'); |
||
| 2675 | $optionInfo = $objEfOption->get($parsedData[0]); |
||
| 2676 | |||
| 2677 | $extra_information_value .= '<li class="list-group-item">' |
||
| 2678 | .$optionInfo['display_text'].': ' |
||
| 2679 | .$parsedData[1].'</li>'; |
||
| 2680 | $extraFieldItem = [ |
||
| 2681 | 'variable' => $extraFieldInfo['variable'], |
||
| 2682 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2683 | 'value' => $parsedData[1], |
||
| 2684 | ]; |
||
| 2685 | break; |
||
| 2686 | case ExtraField::FIELD_TYPE_TRIPLE_SELECT: |
||
| 2687 | $optionIds = explode(';', $data); |
||
| 2688 | $optionValues = []; |
||
| 2689 | |||
| 2690 | foreach ($optionIds as $optionId) { |
||
| 2691 | $objEfOption = new ExtraFieldOption('user'); |
||
| 2692 | $optionInfo = $objEfOption->get($optionId); |
||
| 2693 | |||
| 2694 | $optionValues[] = $optionInfo['display_text']; |
||
| 2695 | } |
||
| 2696 | $extra_information_value .= '<li class="list-group-item">' |
||
| 2697 | .ucfirst($extraFieldInfo['display_text']).': ' |
||
| 2698 | .implode(' ', $optionValues).'</li>'; |
||
| 2699 | $extraFieldItem = [ |
||
| 2700 | 'variable' => $extraFieldInfo['variable'], |
||
| 2701 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2702 | 'value' => implode(' ', $optionValues), |
||
| 2703 | ]; |
||
| 2704 | break; |
||
| 2705 | default: |
||
| 2706 | // Ofaj |
||
| 2707 | // Converts "Date of birth" into "age" |
||
| 2708 | if ($key === 'terms_datedenaissance') { |
||
| 2709 | $dataArray = date_to_str_ago($data, 'UTC', true); |
||
| 2710 | $dataToString = isset($dataArray['years']) && !empty($dataArray['years']) ? $dataArray['years'] : 0; |
||
| 2711 | if (!empty($dataToString)) { |
||
| 2712 | $data = $dataToString; |
||
| 2713 | $extraFieldInfo['display_text'] = get_lang('Age'); |
||
| 2714 | } |
||
| 2715 | } |
||
| 2716 | |||
| 2717 | $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '.$data.'</li>'; |
||
| 2718 | $extraFieldItem = [ |
||
| 2719 | 'variable' => $extraFieldInfo['variable'], |
||
| 2720 | 'label' => ucfirst($extraFieldInfo['display_text']), |
||
| 2721 | 'value' => $data, |
||
| 2722 | ]; |
||
| 2723 | break; |
||
| 2724 | } |
||
| 2725 | } |
||
| 2726 | |||
| 2727 | $listType[] = $extraFieldItem; |
||
| 2728 | } |
||
| 2729 | |||
| 2730 | if ($isArray) { |
||
| 2731 | return $listType; |
||
| 2732 | } else { |
||
| 2733 | // if there are information to show |
||
| 2734 | if (!empty($extra_information_value)) { |
||
| 2735 | $extra_information_value = '<ul class="list-group">'.$extra_information_value.'</ul>'; |
||
| 2736 | $extra_information .= Display::panelCollapse( |
||
| 2737 | get_lang('ExtraInformation'), |
||
| 2738 | $extra_information_value, |
||
| 2739 | 'sn-extra-information', |
||
| 2740 | null, |
||
| 2741 | 'sn-extra-accordion', |
||
| 2742 | 'sn-extra-collapse' |
||
| 2743 | ); |
||
| 2744 | } |
||
| 2745 | } |
||
| 2746 | } |
||
| 2747 | |||
| 2748 | return $extra_information; |
||
| 2749 | } |
||
| 2750 | |||
| 2751 | /** |
||
| 2752 | * @param string $url |
||
| 2753 | */ |
||
| 2754 | public static function handlePosts($url) |
||
| 2785 | } |
||
| 2786 | } |
||
| 2787 | |||
| 2788 | /** |
||
| 2789 | * @param int $countPost |
||
| 2790 | * @param array $htmlHeadXtra |
||
| 2791 | */ |
||
| 2792 | public static function getScrollJs($countPost, &$htmlHeadXtra) |
||
| 2793 | { |
||
| 2794 | // $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php'; |
||
| 2795 | $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php'; |
||
| 2796 | $javascriptDir = api_get_path(LIBRARY_PATH).'javascript/'; |
||
| 2797 | $locale = api_get_language_isocode(); |
||
| 2798 | |||
| 2799 | // Add Jquery scroll pagination plugin |
||
| 2800 | $htmlHeadXtra[] = api_get_js('jscroll/jquery.jscroll.js'); |
||
| 2801 | // Add Jquery Time ago plugin |
||
| 2802 | $htmlHeadXtra[] = api_get_asset('jquery-timeago/jquery.timeago.js'); |
||
| 2803 | $timeAgoLocaleDir = $javascriptDir.'jquery-timeago/locales/jquery.timeago.'.$locale.'.js'; |
||
| 2804 | if (file_exists($timeAgoLocaleDir)) { |
||
| 2805 | $htmlHeadXtra[] = api_get_js('jquery-timeago/locales/jquery.timeago.'.$locale.'.js'); |
||
| 2806 | } |
||
| 2807 | |||
| 2808 | if ($countPost > self::DEFAULT_WALL_POSTS) { |
||
| 2809 | $htmlHeadXtra[] = '<script> |
||
| 2810 | $(function() { |
||
| 2811 | var container = $("#wallMessages"); |
||
| 2812 | container.jscroll({ |
||
| 2813 | loadingHtml: "<div class=\"well_border\">'.get_lang('Loading').' </div>", |
||
| 2814 | nextSelector: "a.nextPage:last", |
||
| 2815 | contentSelector: "", |
||
| 2816 | callback: timeAgo |
||
| 2817 | }); |
||
| 2818 | }); |
||
| 2819 | </script>'; |
||
| 2820 | } |
||
| 2821 | |||
| 2822 | $htmlHeadXtra[] = '<script> |
||
| 2823 | function deleteMessage(id) |
||
| 2824 | { |
||
| 2825 | $.ajax({ |
||
| 2826 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 2827 | success: function (result) { |
||
| 2828 | if (result) { |
||
| 2829 | $("#message_" + id).parent().parent().parent().parent().html(result); |
||
| 2830 | } |
||
| 2831 | } |
||
| 2832 | }); |
||
| 2833 | } |
||
| 2834 | |||
| 2835 | function deleteComment(id) |
||
| 2836 | { |
||
| 2837 | $.ajax({ |
||
| 2838 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 2839 | success: function (result) { |
||
| 2840 | if (result) { |
||
| 2841 | $("#message_" + id).parent().parent().parent().html(result); |
||
| 2842 | } |
||
| 2843 | } |
||
| 2844 | }); |
||
| 2845 | } |
||
| 2846 | |||
| 2847 | function submitComment(messageId) |
||
| 2848 | { |
||
| 2849 | var data = $("#form_comment_"+messageId).serializeArray(); |
||
| 2850 | $.ajax({ |
||
| 2851 | type : "POST", |
||
| 2852 | url: "'.$socialAjaxUrl.'?a=send_comment" + "&id=" + messageId, |
||
| 2853 | data: data, |
||
| 2854 | success: function (result) { |
||
| 2855 | if (result) { |
||
| 2856 | $("#post_" + messageId + " textarea").val(""); |
||
| 2857 | $("#post_" + messageId + " .sub-mediapost").prepend(result); |
||
| 2858 | $("#post_" + messageId + " .sub-mediapost").append( |
||
| 2859 | $(\'<div id=result_\' + messageId +\'>'.addslashes(get_lang('Saved')).'</div>\') |
||
| 2860 | ); |
||
| 2861 | |||
| 2862 | $("#result_" + messageId + "").fadeIn("fast", function() { |
||
| 2863 | $("#result_" + messageId + "").delay(1000).fadeOut("fast", function() { |
||
| 2864 | $(this).remove(); |
||
| 2865 | }); |
||
| 2866 | }); |
||
| 2867 | } |
||
| 2868 | } |
||
| 2869 | }); |
||
| 2870 | } |
||
| 2871 | |||
| 2872 | $(function() { |
||
| 2873 | timeAgo(); |
||
| 2874 | |||
| 2875 | /*$(".delete_message").on("click", function() { |
||
| 2876 | var id = $(this).attr("id"); |
||
| 2877 | id = id.split("_")[1]; |
||
| 2878 | $.ajax({ |
||
| 2879 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 2880 | success: function (result) { |
||
| 2881 | if (result) { |
||
| 2882 | $("#message_" + id).parent().parent().parent().parent().html(result); |
||
| 2883 | } |
||
| 2884 | } |
||
| 2885 | }); |
||
| 2886 | }); |
||
| 2887 | |||
| 2888 | |||
| 2889 | $(".delete_comment").on("click", function() { |
||
| 2890 | var id = $(this).attr("id"); |
||
| 2891 | id = id.split("_")[1]; |
||
| 2892 | $.ajax({ |
||
| 2893 | url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
||
| 2894 | success: function (result) { |
||
| 2895 | if (result) { |
||
| 2896 | $("#message_" + id).parent().parent().parent().html(result); |
||
| 2897 | } |
||
| 2898 | } |
||
| 2899 | }); |
||
| 2900 | }); |
||
| 2901 | */ |
||
| 2902 | }); |
||
| 2903 | |||
| 2904 | function timeAgo() { |
||
| 2905 | $(".timeago").timeago(); |
||
| 2906 | } |
||
| 2907 | </script>'; |
||
| 2908 | } |
||
| 2909 | |||
| 2910 | /** |
||
| 2911 | * @param int $userId |
||
| 2912 | * @param int $countPost |
||
| 2913 | * |
||
| 2914 | * @return string |
||
| 2915 | */ |
||
| 2916 | public static function getAutoExtendLink($userId, $countPost) |
||
| 2917 | { |
||
| 2918 | $userId = (int) $userId; |
||
| 2919 | $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php'; |
||
| 2920 | $socialAutoExtendLink = ''; |
||
| 2921 | if ($countPost > self::DEFAULT_WALL_POSTS) { |
||
| 2922 | $socialAutoExtendLink = Display::url( |
||
| 2923 | get_lang('SeeMore'), |
||
| 2924 | $socialAjaxUrl.'?u='.$userId.'&a=list_wall_message&start='. |
||
| 2925 | self::DEFAULT_WALL_POSTS.'&length='.self::DEFAULT_SCROLL_NEW_POST, |
||
| 2926 | [ |
||
| 2927 | 'class' => 'nextPage next', |
||
| 2928 | ] |
||
| 2929 | ); |
||
| 2930 | } |
||
| 2931 | |||
| 2932 | return $socialAutoExtendLink; |
||
| 2933 | } |
||
| 2934 | |||
| 2935 | /** |
||
| 2936 | * @param int $userId |
||
| 2937 | * |
||
| 2938 | * @return array |
||
| 2939 | */ |
||
| 2940 | public static function getThreadList($userId) |
||
| 2941 | { |
||
| 2942 | $forumCourseId = api_get_configuration_value('global_forums_course_id'); |
||
| 2943 | |||
| 2944 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
||
| 2945 | |||
| 2946 | $threads = []; |
||
| 2947 | if (!empty($forumCourseId)) { |
||
| 2948 | $courseInfo = api_get_course_info_by_id($forumCourseId); |
||
| 2949 | getNotificationsPerUser($userId, true, $forumCourseId); |
||
| 2950 | $notification = Session::read('forum_notification'); |
||
| 2951 | Session::erase('forum_notification'); |
||
| 2952 | |||
| 2953 | $threadUrlBase = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
||
| 2954 | 'cidReq' => $courseInfo['code'], |
||
| 2955 | ]).'&'; |
||
| 2956 | if (isset($notification['thread']) && !empty($notification['thread'])) { |
||
| 2957 | $threadList = array_filter(array_unique($notification['thread'])); |
||
| 2958 | $em = Database::getManager(); |
||
| 2959 | $repo = $em->getRepository('ChamiloCourseBundle:CForumThread'); |
||
| 2960 | foreach ($threadList as $threadId) { |
||
| 2961 | /** @var \Chamilo\CourseBundle\Entity\CForumThread $thread */ |
||
| 2962 | $thread = $repo->find($threadId); |
||
| 2963 | if ($thread) { |
||
| 2964 | $threadUrl = $threadUrlBase.http_build_query([ |
||
| 2965 | 'forum' => $thread->getForumId(), |
||
| 2966 | 'thread' => $thread->getIid(), |
||
| 2967 | ]); |
||
| 2968 | $threads[] = [ |
||
| 2969 | 'id' => $threadId, |
||
| 2970 | 'url' => Display::url( |
||
| 2971 | $thread->getThreadTitle(), |
||
| 2972 | $threadUrl |
||
| 2973 | ), |
||
| 2974 | 'name' => Display::url( |
||
| 2975 | $thread->getThreadTitle(), |
||
| 2976 | $threadUrl |
||
| 2977 | ), |
||
| 2978 | 'description' => '', |
||
| 2979 | ]; |
||
| 2980 | } |
||
| 2981 | } |
||
| 2982 | } |
||
| 2983 | } |
||
| 2984 | |||
| 2985 | return $threads; |
||
| 2986 | } |
||
| 2987 | |||
| 2988 | /** |
||
| 2989 | * @param int $userId |
||
| 2990 | * |
||
| 2991 | * @return string |
||
| 2992 | */ |
||
| 2993 | public static function getGroupBlock($userId) |
||
| 3124 | } |
||
| 3125 | |||
| 3126 | /** |
||
| 3127 | * Returns the formatted header message post. |
||
| 3128 | * |
||
| 3129 | * @param int $authorInfo |
||
| 3130 | * @param int $receiverInfo |
||
| 3131 | * @param array $message Message data |
||
| 3132 | * |
||
| 3133 | * @return string $html The formatted header message post |
||
| 3134 | */ |
||
| 3135 | private static function headerMessagePost($authorInfo, $receiverInfo, $message) |
||
| 3235 | } |
||
| 3236 | } |
||
| 3237 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.