| Total Complexity | 243 |
| Total Lines | 2135 |
| 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 |
||
| 15 | class SocialManager extends UserManager |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Constructor |
||
| 19 | */ |
||
| 20 | public function __construct() |
||
| 21 | { |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Allow to see contacts list |
||
| 26 | * @author isaac flores paz |
||
| 27 | * @return array |
||
| 28 | */ |
||
| 29 | public static function show_list_type_friends() |
||
| 30 | { |
||
| 31 | $table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); |
||
| 32 | $sql = 'SELECT id, title FROM '.$table.' |
||
| 33 | WHERE id<>6 |
||
| 34 | ORDER BY id ASC'; |
||
| 35 | $result = Database::query($sql); |
||
| 36 | $friend_relation_list = []; |
||
| 37 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
||
| 38 | $friend_relation_list[] = $row; |
||
| 39 | } |
||
| 40 | $count_list = count($friend_relation_list); |
||
| 41 | if ($count_list == 0) { |
||
| 42 | $friend_relation_list[] = get_lang('Unknown'); |
||
| 43 | } else { |
||
| 44 | return $friend_relation_list; |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Get relation type contact by name |
||
| 50 | * @param string names of the kind of relation |
||
| 51 | * @return int |
||
| 52 | * @author isaac flores paz |
||
| 53 | */ |
||
| 54 | public static function get_relation_type_by_name($relation_type_name) |
||
| 55 | { |
||
| 56 | $list_type_friend = self::show_list_type_friends(); |
||
| 57 | foreach ($list_type_friend as $value_type_friend) { |
||
| 58 | if (strtolower($value_type_friend['title']) == $relation_type_name) { |
||
| 59 | return $value_type_friend['id']; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get the kind of relation between contacts |
||
| 66 | * @param int user id |
||
| 67 | * @param int user friend id |
||
| 68 | * @param string |
||
| 69 | * @return int |
||
| 70 | * @author isaac flores paz |
||
| 71 | */ |
||
| 72 | public static function get_relation_between_contacts($user_id, $user_friend) |
||
| 73 | { |
||
| 74 | $table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); |
||
| 75 | $userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 76 | $sql = 'SELECT rt.id as id |
||
| 77 | FROM '.$table.' rt |
||
| 78 | WHERE rt.id = ( |
||
| 79 | SELECT uf.relation_type |
||
| 80 | FROM '.$userRelUserTable.' uf |
||
| 81 | WHERE |
||
| 82 | user_id='.((int) $user_id).' AND |
||
| 83 | friend_user_id='.((int) $user_friend).' AND |
||
| 84 | uf.relation_type <> '.USER_RELATION_TYPE_RRHH.' |
||
| 85 | LIMIT 1 |
||
| 86 | )'; |
||
| 87 | $res = Database::query($sql); |
||
| 88 | if (Database::num_rows($res) > 0) { |
||
| 89 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 90 | |||
| 91 | return $row['id']; |
||
| 92 | } else { |
||
| 93 | return USER_UNKNOWN; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Get count of friends from user |
||
| 99 | * |
||
| 100 | * @param int $userId |
||
| 101 | * @return int |
||
| 102 | */ |
||
| 103 | public static function getCountFriends($userId) |
||
| 104 | { |
||
| 105 | $table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 106 | $userId = (int) $userId; |
||
| 107 | if (empty($userId)) { |
||
| 108 | return 0; |
||
| 109 | } |
||
| 110 | |||
| 111 | $sql = 'SELECT count(friend_user_id) count |
||
| 112 | FROM '.$table.' |
||
| 113 | WHERE |
||
| 114 | relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND |
||
| 115 | friend_user_id<>'.($userId).' AND |
||
| 116 | user_id='.($userId); |
||
| 117 | $res = Database::query($sql); |
||
| 118 | if (Database::num_rows($res)) { |
||
| 119 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 120 | return (int) $row['count']; |
||
| 121 | } |
||
| 122 | |||
| 123 | return 0; |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Gets friends id list |
||
| 128 | * @param int user id |
||
| 129 | * @param int group id |
||
| 130 | * @param string name to search |
||
| 131 | * @param bool true will load firstname, lastname, and image name |
||
| 132 | * @return array |
||
| 133 | * @author Julio Montoya <[email protected]> Cleaning code, function renamed, $load_extra_info option added |
||
| 134 | * @author isaac flores paz |
||
| 135 | */ |
||
| 136 | public static function get_friends( |
||
| 137 | $user_id, |
||
| 138 | $id_group = null, |
||
| 139 | $search_name = null, |
||
| 140 | $load_extra_info = true |
||
| 141 | ) { |
||
| 142 | $list_ids_friends = []; |
||
| 143 | $tbl_my_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 144 | $tbl_my_user = Database::get_main_table(TABLE_MAIN_USER); |
||
| 145 | $sql = 'SELECT friend_user_id FROM '.$tbl_my_friend.' |
||
| 146 | WHERE |
||
| 147 | relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND |
||
| 148 | friend_user_id<>'.((int) $user_id).' AND |
||
| 149 | user_id='.((int) $user_id); |
||
| 150 | if (isset($id_group) && $id_group > 0) { |
||
| 151 | $sql .= ' AND relation_type='.$id_group; |
||
| 152 | } |
||
| 153 | if (isset($search_name)) { |
||
| 154 | $search_name = trim($search_name); |
||
| 155 | $search_name = str_replace(' ', '', $search_name); |
||
| 156 | $sql .= ' AND friend_user_id IN ( |
||
| 157 | SELECT user_id FROM '.$tbl_my_user.' |
||
| 158 | WHERE |
||
| 159 | firstName LIKE "%'.Database::escape_string($search_name).'%" OR |
||
| 160 | lastName LIKE "%'.Database::escape_string($search_name).'%" OR |
||
| 161 | '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' LIKE concat("%","'.Database::escape_string($search_name).'","%") |
||
| 162 | ) '; |
||
| 163 | } |
||
| 164 | |||
| 165 | $res = Database::query($sql); |
||
| 166 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 167 | if ($load_extra_info) { |
||
| 168 | $my_user_info = api_get_user_info($row['friend_user_id']); |
||
| 169 | $list_ids_friends[] = [ |
||
| 170 | 'friend_user_id' => $row['friend_user_id'], |
||
| 171 | 'firstName' => $my_user_info['firstName'], |
||
| 172 | 'lastName' => $my_user_info['lastName'], |
||
| 173 | 'username' => $my_user_info['username'], |
||
| 174 | 'image' => $my_user_info['avatar'], |
||
| 175 | 'user_info' => $my_user_info, |
||
| 176 | ]; |
||
| 177 | } else { |
||
| 178 | $list_ids_friends[] = $row; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | return $list_ids_friends; |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * get web path of user invitate |
||
| 187 | * @author isaac flores paz |
||
| 188 | * @author Julio Montoya setting variable array |
||
| 189 | * @param int user id |
||
| 190 | * |
||
| 191 | * @return array |
||
| 192 | */ |
||
| 193 | public static function get_list_web_path_user_invitation_by_user_id($user_id) |
||
| 194 | { |
||
| 195 | $list_ids = self::get_list_invitation_of_friends_by_user_id($user_id); |
||
| 196 | $list = []; |
||
| 197 | foreach ($list_ids as $values_ids) { |
||
| 198 | $list[] = UserManager::get_user_picture_path_by_id( |
||
| 199 | $values_ids['user_sender_id'], |
||
| 200 | 'web' |
||
| 201 | ); |
||
| 202 | } |
||
| 203 | |||
| 204 | return $list; |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Sends an invitation to contacts |
||
| 209 | * @param int user id |
||
| 210 | * @param int user friend id |
||
| 211 | * @param string title of the message |
||
| 212 | * @param string content of the message |
||
| 213 | * @return boolean |
||
| 214 | * @author isaac flores paz |
||
| 215 | * @author Julio Montoya <[email protected]> Cleaning code |
||
| 216 | */ |
||
| 217 | public static function send_invitation_friend( |
||
| 218 | $user_id, |
||
| 219 | $friend_id, |
||
| 220 | $message_title, |
||
| 221 | $message_content |
||
| 222 | ) { |
||
| 223 | $tbl_message = Database::get_main_table(TABLE_MESSAGE); |
||
| 224 | $user_id = intval($user_id); |
||
| 225 | $friend_id = intval($friend_id); |
||
| 226 | |||
| 227 | //Just in case we replace the and \n and \n\r while saving in the DB |
||
| 228 | $message_content = str_replace(["\n", "\n\r"], '<br />', $message_content); |
||
| 229 | |||
| 230 | $clean_message_content = Database::escape_string($message_content); |
||
| 231 | $now = api_get_utc_datetime(); |
||
| 232 | $sql = 'SELECT COUNT(*) AS count FROM '.$tbl_message.' |
||
| 233 | WHERE |
||
| 234 | user_sender_id='.$user_id.' AND |
||
| 235 | user_receiver_id='.$friend_id.' AND |
||
| 236 | msg_status IN('.MESSAGE_STATUS_INVITATION_PENDING.', '.MESSAGE_STATUS_INVITATION_ACCEPTED.', '.MESSAGE_STATUS_INVITATION_DENIED.'); |
||
| 237 | '; |
||
| 238 | $res_exist = Database::query($sql); |
||
| 239 | $row_exist = Database::fetch_array($res_exist, 'ASSOC'); |
||
| 240 | |||
| 241 | if ($row_exist['count'] == 0) { |
||
| 242 | $params = [ |
||
| 243 | 'user_sender_id' => $user_id, |
||
| 244 | 'user_receiver_id' => $friend_id, |
||
| 245 | 'msg_status' => MESSAGE_STATUS_INVITATION_PENDING, |
||
| 246 | 'send_date' => $now, |
||
| 247 | 'title' => $message_title, |
||
| 248 | 'content' => $message_content, |
||
| 249 | 'group_id' => 0, |
||
| 250 | 'parent_id' => 0, |
||
| 251 | 'update_date' => $now |
||
| 252 | ]; |
||
| 253 | $messageId = Database::insert($tbl_message, $params); |
||
| 254 | |||
| 255 | $senderInfo = api_get_user_info($user_id); |
||
| 256 | $notification = new Notification(); |
||
| 257 | $notification->saveNotification( |
||
| 258 | $messageId, |
||
|
|
|||
| 259 | Notification::NOTIFICATION_TYPE_INVITATION, |
||
| 260 | [$friend_id], |
||
| 261 | $message_title, |
||
| 262 | $message_content, |
||
| 263 | $senderInfo |
||
| 264 | ); |
||
| 265 | |||
| 266 | return true; |
||
| 267 | } else { |
||
| 268 | // invitation already exist |
||
| 269 | $sql = 'SELECT COUNT(*) AS count, id FROM '.$tbl_message.' |
||
| 270 | WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7'; |
||
| 271 | $res_if_exist = Database::query($sql); |
||
| 272 | $row_if_exist = Database::fetch_array($res_if_exist, 'ASSOC'); |
||
| 273 | if ($row_if_exist['count'] == 1) { |
||
| 274 | $sql = 'UPDATE '.$tbl_message.' SET |
||
| 275 | msg_status=5, content = "'.$clean_message_content.'" |
||
| 276 | WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7 '; |
||
| 277 | Database::query($sql); |
||
| 278 | return true; |
||
| 279 | } else { |
||
| 280 | return false; |
||
| 281 | } |
||
| 282 | } |
||
| 283 | } |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Get number messages of the inbox |
||
| 287 | * @author isaac flores paz |
||
| 288 | * @param int user receiver id |
||
| 289 | * @return int |
||
| 290 | */ |
||
| 291 | public static function get_message_number_invitation_by_user_id($user_receiver_id) |
||
| 292 | { |
||
| 293 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 294 | $sql = 'SELECT COUNT(*) as count_message_in_box FROM '.$table.' |
||
| 295 | WHERE |
||
| 296 | user_receiver_id='.intval($user_receiver_id).' AND |
||
| 297 | msg_status='.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 298 | $res = Database::query($sql); |
||
| 299 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 300 | |||
| 301 | return $row['count_message_in_box']; |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Get number of messages sent to other users |
||
| 306 | * @param int $sender_id |
||
| 307 | * @return int |
||
| 308 | */ |
||
| 309 | public static function getCountMessagesSent($sender_id) |
||
| 310 | { |
||
| 311 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 312 | $sql = 'SELECT COUNT(*) FROM '.$table.' |
||
| 313 | WHERE |
||
| 314 | user_sender_id='.intval($sender_id).' AND |
||
| 315 | msg_status < 5'; |
||
| 316 | $res = Database::query($sql); |
||
| 317 | $row = Database::fetch_row($res); |
||
| 318 | |||
| 319 | return $row[0]; |
||
| 320 | } |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Get number of messages received from other users |
||
| 324 | * @param int $receiver_id |
||
| 325 | * @return int |
||
| 326 | */ |
||
| 327 | public static function getCountMessagesReceived($receiver_id) |
||
| 328 | { |
||
| 329 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 330 | $sql = 'SELECT COUNT(*) FROM '.$table.' |
||
| 331 | WHERE |
||
| 332 | user_receiver_id='.intval($receiver_id).' AND |
||
| 333 | msg_status < 4'; |
||
| 334 | $res = Database::query($sql); |
||
| 335 | $row = Database::fetch_row($res); |
||
| 336 | |||
| 337 | return $row[0]; |
||
| 338 | } |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Get number of messages posted on own wall |
||
| 342 | * @param int $userId |
||
| 343 | * @return int |
||
| 344 | */ |
||
| 345 | public static function getCountWallPostedMessages($userId) |
||
| 346 | { |
||
| 347 | if (empty($userId)) { |
||
| 348 | return 0; |
||
| 349 | } |
||
| 350 | |||
| 351 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 352 | $sql = 'SELECT COUNT(*) |
||
| 353 | FROM '.$table.' |
||
| 354 | WHERE |
||
| 355 | user_sender_id='.intval($userId).' AND |
||
| 356 | (msg_status = '.MESSAGE_STATUS_WALL.' OR |
||
| 357 | msg_status = '.MESSAGE_STATUS_WALL_POST.') AND |
||
| 358 | parent_id = 0'; |
||
| 359 | $res = Database::query($sql); |
||
| 360 | $row = Database::fetch_row($res); |
||
| 361 | |||
| 362 | return $row[0]; |
||
| 363 | } |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Get invitation list received by user |
||
| 367 | * @author isaac flores paz |
||
| 368 | * @param int $userId |
||
| 369 | * |
||
| 370 | * @return array |
||
| 371 | */ |
||
| 372 | public static function get_list_invitation_of_friends_by_user_id($userId) |
||
| 373 | { |
||
| 374 | if (empty($userId)) { |
||
| 375 | return []; |
||
| 376 | } |
||
| 377 | |||
| 378 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 379 | $sql = 'SELECT user_sender_id, send_date, title, content |
||
| 380 | FROM '.$table.' |
||
| 381 | WHERE |
||
| 382 | user_receiver_id = '.intval($userId).' AND |
||
| 383 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 384 | $res = Database::query($sql); |
||
| 385 | $list = []; |
||
| 386 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 387 | $list[] = $row; |
||
| 388 | } |
||
| 389 | |||
| 390 | return $list; |
||
| 391 | } |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Get invitation list sent by user |
||
| 395 | * @author Julio Montoya <[email protected]> |
||
| 396 | * @param int $userId |
||
| 397 | * @return array |
||
| 398 | */ |
||
| 399 | public static function get_list_invitation_sent_by_user_id($userId) |
||
| 400 | { |
||
| 401 | if (empty($userId)) { |
||
| 402 | return []; |
||
| 403 | } |
||
| 404 | |||
| 405 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 406 | $sql = 'SELECT user_receiver_id, send_date,title,content |
||
| 407 | FROM '.$table.' |
||
| 408 | WHERE |
||
| 409 | user_sender_id = '.intval($userId).' AND |
||
| 410 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 411 | $res = Database::query($sql); |
||
| 412 | $list = []; |
||
| 413 | while ($row = Database::fetch_array($res, 'ASSOC')) { |
||
| 414 | $list[$row['user_receiver_id']] = $row; |
||
| 415 | } |
||
| 416 | |||
| 417 | return $list; |
||
| 418 | } |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Get count invitation sent by user |
||
| 422 | * @author Julio Montoya <[email protected]> |
||
| 423 | * @param int $userId |
||
| 424 | * |
||
| 425 | * @return int |
||
| 426 | */ |
||
| 427 | public static function getCountInvitationSent($userId) |
||
| 428 | { |
||
| 429 | if (empty($userId)) { |
||
| 430 | return 0; |
||
| 431 | } |
||
| 432 | |||
| 433 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 434 | $sql = 'SELECT count(user_receiver_id) count |
||
| 435 | FROM '.$table.' |
||
| 436 | WHERE |
||
| 437 | user_sender_id = '.intval($userId).' AND |
||
| 438 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 439 | $res = Database::query($sql); |
||
| 440 | if (Database::num_rows($res)) { |
||
| 441 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 442 | return (int) $row['count']; |
||
| 443 | } |
||
| 444 | |||
| 445 | return 0; |
||
| 446 | } |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Accepts invitation |
||
| 450 | * @param int $user_send_id |
||
| 451 | * @param int $user_receiver_id |
||
| 452 | * @return bool |
||
| 453 | * |
||
| 454 | * @author isaac flores paz |
||
| 455 | * @author Julio Montoya <[email protected]> Cleaning code |
||
| 456 | */ |
||
| 457 | public static function invitation_accepted($user_send_id, $user_receiver_id) |
||
| 458 | { |
||
| 459 | if (empty($user_send_id) || empty($user_receiver_id)) { |
||
| 460 | return false; |
||
| 461 | } |
||
| 462 | |||
| 463 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 464 | $sql = "UPDATE $table |
||
| 465 | SET msg_status = ".MESSAGE_STATUS_INVITATION_ACCEPTED." |
||
| 466 | WHERE |
||
| 467 | user_sender_id = ".((int) $user_send_id)." AND |
||
| 468 | user_receiver_id=".((int) $user_receiver_id)." AND |
||
| 469 | msg_status = ".MESSAGE_STATUS_INVITATION_PENDING; |
||
| 470 | Database::query($sql); |
||
| 471 | |||
| 472 | return true; |
||
| 473 | } |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Denies invitation |
||
| 477 | * @param int user sender id |
||
| 478 | * @param int user receiver id |
||
| 479 | * @return bool |
||
| 480 | * |
||
| 481 | * @author isaac flores paz |
||
| 482 | * @author Julio Montoya <[email protected]> Cleaning code |
||
| 483 | */ |
||
| 484 | public static function invitation_denied($user_send_id, $user_receiver_id) |
||
| 485 | { |
||
| 486 | if (empty($user_send_id) || empty($user_receiver_id)) { |
||
| 487 | return false; |
||
| 488 | } |
||
| 489 | $table = Database::get_main_table(TABLE_MESSAGE); |
||
| 490 | $sql = 'DELETE FROM '.$table.' |
||
| 491 | WHERE |
||
| 492 | user_sender_id = '.((int) $user_send_id).' AND |
||
| 493 | user_receiver_id='.((int) $user_receiver_id).' AND |
||
| 494 | msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
||
| 495 | Database::query($sql); |
||
| 496 | |||
| 497 | return true; |
||
| 498 | } |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Allow attaching to group |
||
| 502 | * @author Isaac Flores Paz |
||
| 503 | * @param int $id_friend_qualify User to qualify |
||
| 504 | * @param int $type_qualify Kind of rating |
||
| 505 | * @return void |
||
| 506 | * @deprecated 2017-03 |
||
| 507 | */ |
||
| 508 | public static function qualify_friend($id_friend_qualify, $type_qualify) |
||
| 509 | { |
||
| 510 | $table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
||
| 511 | $user_id = api_get_user_id(); |
||
| 512 | $sql = 'UPDATE '.$table.' SET relation_type='.((int) $type_qualify).' |
||
| 513 | WHERE user_id = '.((int) $user_id).' AND friend_user_id='.(int) $id_friend_qualify; |
||
| 514 | Database::query($sql); |
||
| 515 | } |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Get user's feeds |
||
| 519 | * @param int $user User ID |
||
| 520 | * @param int $limit Limit of posts per feed |
||
| 521 | * @return string HTML section with all feeds included |
||
| 522 | * @author Yannick Warnier |
||
| 523 | * @since Dokeos 1.8.6.1 |
||
| 524 | */ |
||
| 525 | public static function getUserRssFeed($user, $limit = 5) |
||
| 574 | } |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Sends invitations to friends |
||
| 578 | * |
||
| 579 | * @param int $userId |
||
| 580 | * @param string $subject |
||
| 581 | * @param string $content |
||
| 582 | * @return bool |
||
| 583 | */ |
||
| 584 | public static function sendInvitationToUser($userId, $subject = '', $content = '') |
||
| 585 | { |
||
| 586 | $user_info = api_get_user_info($userId); |
||
| 587 | $success = get_lang('MessageSentTo'); |
||
| 588 | $success .= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']); |
||
| 589 | |||
| 590 | if (isset($subject) && isset($content) && isset($userId)) { |
||
| 591 | $result = MessageManager::send_message($userId, $subject, $content); |
||
| 592 | |||
| 593 | if ($result) { |
||
| 594 | Display::addFlash( |
||
| 595 | Display::return_message($success, 'normal', false) |
||
| 596 | ); |
||
| 597 | } else { |
||
| 598 | Display::addFlash( |
||
| 599 | Display::return_message(get_lang('ErrorSendingMessage'), 'error', false) |
||
| 600 | ); |
||
| 601 | } |
||
| 602 | return false; |
||
| 603 | } elseif (isset($userId) && !isset($subject)) { |
||
| 604 | if (isset($userId) && $userId > 0) { |
||
| 605 | $count = self::send_invitation_friend( |
||
| 606 | api_get_user_id(), |
||
| 607 | $userId, |
||
| 608 | get_lang('Invitation'), |
||
| 609 | $content |
||
| 610 | ); |
||
| 611 | |||
| 612 | if ($count) { |
||
| 613 | Display::addFlash( |
||
| 614 | Display::return_message( |
||
| 615 | api_htmlentities(get_lang('InvitationHasBeenSent')), |
||
| 616 | 'normal', |
||
| 617 | false |
||
| 618 | ) |
||
| 619 | ); |
||
| 620 | } else { |
||
| 621 | Display::addFlash( |
||
| 622 | Display::return_message( |
||
| 623 | api_htmlentities(get_lang('YouAlreadySentAnInvitation')), |
||
| 624 | 'warning', |
||
| 625 | false |
||
| 626 | ) |
||
| 627 | ); |
||
| 628 | } |
||
| 629 | } |
||
| 630 | } |
||
| 631 | } |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Helper functions definition |
||
| 635 | */ |
||
| 636 | public static function get_logged_user_course_html($my_course, $count) |
||
| 637 | { |
||
| 638 | $result = ''; |
||
| 639 | // Table definitions |
||
| 640 | $main_user_table = Database::get_main_table(TABLE_MAIN_USER); |
||
| 641 | $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
||
| 642 | $course_directory = $my_course['course_info']['directory']; |
||
| 643 | $course_title = $my_course['course_info']['title']; |
||
| 644 | $course_visibility = $my_course['course_info']['visibility']; |
||
| 645 | |||
| 646 | $user_in_course_status = CourseManager::getUserInCourseStatus( |
||
| 647 | api_get_user_id(), |
||
| 648 | $my_course['course_info']['real_id'] |
||
| 649 | ); |
||
| 650 | |||
| 651 | $course_path = api_get_path(SYS_COURSE_PATH).$course_directory; // course path |
||
| 652 | if (api_get_setting('course_images_in_courses_list') === 'true') { |
||
| 653 | if (file_exists($course_path.'/course-pic85x85.png')) { |
||
| 654 | $image = $my_course['course_info']['course_image']; |
||
| 655 | $imageCourse = Display::img($image, $course_title, ['class'=>'img-course']); |
||
| 656 | } else { |
||
| 657 | $imageCourse = Display::return_icon( |
||
| 658 | 'session_default_small.png', |
||
| 659 | $course_title, |
||
| 660 | ['class' => 'img-course'] |
||
| 661 | ); |
||
| 662 | } |
||
| 663 | } else { |
||
| 664 | $imageCourse = Display::return_icon( |
||
| 665 | 'course.png', |
||
| 666 | get_lang('Course'), |
||
| 667 | ['class' => 'img-default'] |
||
| 668 | ); |
||
| 669 | } |
||
| 670 | |||
| 671 | //display course entry |
||
| 672 | if (api_get_setting('course_images_in_courses_list') === 'true') { |
||
| 673 | $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:65px;">'; |
||
| 674 | } else { |
||
| 675 | $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:44px;">'; |
||
| 676 | } |
||
| 677 | $result .= $imageCourse; |
||
| 678 | |||
| 679 | //show a hyperlink to the course, unless the course is closed and user is not course admin |
||
| 680 | if ($course_visibility != COURSE_VISIBILITY_HIDDEN && |
||
| 681 | ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) |
||
| 682 | ) { |
||
| 683 | $result .= '<span class="title">'.$course_title.'<span>'; |
||
| 684 | } else { |
||
| 685 | $result .= $course_title." ".get_lang('CourseClosed'); |
||
| 686 | } |
||
| 687 | |||
| 688 | $result .= '</li>'; |
||
| 689 | $session = ''; |
||
| 690 | if (!empty($my_course['session_name']) && !empty($my_course['id_session'])) { |
||
| 691 | // Request for the name of the general coach |
||
| 692 | $sql = 'SELECT lastname, firstname |
||
| 693 | FROM '.$tbl_session.' ts |
||
| 694 | LEFT JOIN '.$main_user_table.' tu |
||
| 695 | ON ts.id_coach = tu.user_id |
||
| 696 | WHERE ts.id='.(int) $my_course['id_session'].' LIMIT 1'; |
||
| 697 | $rs = Database::query($sql); |
||
| 698 | $sessioncoach = Database::store_result($rs); |
||
| 699 | $sessioncoach = $sessioncoach[0]; |
||
| 700 | |||
| 701 | $session = []; |
||
| 702 | $session['title'] = $my_course['session_name']; |
||
| 703 | if ($my_course['access_start_date'] == '0000-00-00') { |
||
| 704 | $session['dates'] = get_lang('WithoutTimeLimits'); |
||
| 705 | if (api_get_setting('show_session_coach') === 'true') { |
||
| 706 | $session['coach'] = get_lang('GeneralCoach').': '. |
||
| 707 | api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); |
||
| 708 | } |
||
| 709 | } else { |
||
| 710 | $session ['dates'] = ' - '.get_lang('From').' '.$my_course['access_start_date'].' '.get_lang('To').' '.$my_course['access_end_date']; |
||
| 711 | if (api_get_setting('show_session_coach') === 'true') { |
||
| 712 | $session['coach'] = get_lang('GeneralCoach').': '. |
||
| 713 | api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); |
||
| 714 | } |
||
| 715 | } |
||
| 716 | } |
||
| 717 | |||
| 718 | $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0; |
||
| 719 | $output = [ |
||
| 720 | $my_course['user_course_cat'], |
||
| 721 | $result, |
||
| 722 | $my_course['id_session'], |
||
| 723 | $session |
||
| 724 | ]; |
||
| 725 | |||
| 726 | return $output; |
||
| 727 | } |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Shows the avatar block in social pages |
||
| 731 | * |
||
| 732 | * @param string $show highlight link possible values: |
||
| 733 | * group_add, |
||
| 734 | * home, |
||
| 735 | * messages, |
||
| 736 | * messages_inbox, |
||
| 737 | * messages_compose, |
||
| 738 | * messages_outbox, |
||
| 739 | * invitations, |
||
| 740 | * shared_profile, |
||
| 741 | * friends, |
||
| 742 | * groups search |
||
| 743 | * @param int $group_id |
||
| 744 | * @param int $user_id |
||
| 745 | * |
||
| 746 | */ |
||
| 747 | public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0) |
||
| 812 | } |
||
| 813 | |||
| 814 | /** |
||
| 815 | * Shows the right menu of the Social Network tool |
||
| 816 | * |
||
| 817 | * @param string $show highlight link possible values: |
||
| 818 | * group_add, |
||
| 819 | * home, |
||
| 820 | * messages, |
||
| 821 | * messages_inbox, |
||
| 822 | * messages_compose , |
||
| 823 | * messages_outbox, |
||
| 824 | * invitations, |
||
| 825 | * shared_profile, |
||
| 826 | * friends, |
||
| 827 | * groups search |
||
| 828 | * @param int $group_id group id |
||
| 829 | * @param int $user_id user id |
||
| 830 | * @param bool $show_full_profile show profile or not (show or hide the user image/information) |
||
| 831 | * @param bool $show_delete_account_button |
||
| 832 | * |
||
| 833 | */ |
||
| 834 | public static function show_social_menu( |
||
| 835 | $show = '', |
||
| 836 | $group_id = 0, |
||
| 837 | $user_id = 0, |
||
| 838 | $show_full_profile = false, |
||
| 839 | $show_delete_account_button = false |
||
| 840 | ) { |
||
| 841 | if (empty($user_id)) { |
||
| 842 | $user_id = api_get_user_id(); |
||
| 843 | } |
||
| 844 | |||
| 845 | $usergroup = new UserGroup(); |
||
| 846 | $show_groups = [ |
||
| 847 | 'groups', |
||
| 848 | 'group_messages', |
||
| 849 | 'messages_list', |
||
| 850 | 'group_add', |
||
| 851 | 'mygroups', |
||
| 852 | 'group_edit', |
||
| 853 | 'member_list', |
||
| 854 | 'invite_friends', |
||
| 855 | 'waiting_list', |
||
| 856 | 'browse_groups', |
||
| 857 | ]; |
||
| 858 | |||
| 859 | // get count unread message and total invitations |
||
| 860 | $count_unread_message = MessageManager::getNumberOfMessages(true); |
||
| 861 | $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null; |
||
| 862 | |||
| 863 | $number_of_new_messages_of_friend = self::get_message_number_invitation_by_user_id(api_get_user_id()); |
||
| 864 | $group_pending_invitations = $usergroup->get_groups_by_user( |
||
| 865 | api_get_user_id(), |
||
| 866 | GROUP_USER_PERMISSION_PENDING_INVITATION, |
||
| 867 | false |
||
| 868 | ); |
||
| 869 | $group_pending_invitations = count($group_pending_invitations); |
||
| 870 | $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; |
||
| 871 | $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : ''); |
||
| 872 | |||
| 873 | $filesIcon = Display::return_icon('sn-files.png', get_lang('MyFiles'), null, ICON_SIZE_SMALL); |
||
| 874 | $friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), null, ICON_SIZE_SMALL); |
||
| 875 | $groupsIcon = Display::return_icon('sn-groups.png', get_lang('SocialGroups'), null, ICON_SIZE_SMALL); |
||
| 876 | $homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), null, ICON_SIZE_SMALL); |
||
| 877 | $invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), null, ICON_SIZE_SMALL); |
||
| 878 | $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), null, ICON_SIZE_SMALL); |
||
| 879 | $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile')); |
||
| 880 | $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), null, ICON_SIZE_SMALL); |
||
| 881 | |||
| 882 | $html = ''; |
||
| 883 | $active = null; |
||
| 884 | if (!in_array( |
||
| 885 | $show, |
||
| 886 | ['shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'] |
||
| 887 | )) { |
||
| 888 | $links = '<ul class="nav nav-pills nav-stacked">'; |
||
| 889 | $active = $show == 'home' ? 'active' : null; |
||
| 890 | $links .= ' |
||
| 891 | <li class="home-icon ' . $active.'"> |
||
| 892 | <a href="' . api_get_path(WEB_CODE_PATH).'social/home.php"> |
||
| 893 | ' . $homeIcon.' '.get_lang('Home').' |
||
| 894 | </a> |
||
| 895 | </li>'; |
||
| 896 | $active = $show == 'messages' ? 'active' : null; |
||
| 897 | $links .= ' |
||
| 898 | <li class="messages-icon ' . $active.'"> |
||
| 899 | <a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php"> |
||
| 900 | '.$messagesIcon.' '.get_lang('Messages').$count_unread_message.' |
||
| 901 | </a> |
||
| 902 | </li>'; |
||
| 903 | |||
| 904 | //Invitations |
||
| 905 | $active = $show == 'invitations' ? 'active' : null; |
||
| 906 | $links .= ' |
||
| 907 | <li class="invitations-icon ' . $active.'"> |
||
| 908 | <a href="' . api_get_path(WEB_CODE_PATH).'social/invitations.php"> |
||
| 909 | ' . $invitationsIcon.' '.get_lang('Invitations').$total_invitations.' |
||
| 910 | </a> |
||
| 911 | </li>'; |
||
| 912 | |||
| 913 | //Shared profile and groups |
||
| 914 | $active = $show == 'shared_profile' ? 'active' : null; |
||
| 915 | $links .= ' |
||
| 916 | <li class="shared-profile-icon' . $active.'"> |
||
| 917 | <a href="' . api_get_path(WEB_CODE_PATH).'social/profile.php"> |
||
| 918 | ' . $sharedProfileIcon.' '.get_lang('ViewMySharedProfile').' |
||
| 919 | </a> |
||
| 920 | </li>'; |
||
| 921 | $active = $show == 'friends' ? 'active' : null; |
||
| 922 | $links .= ' |
||
| 923 | <li class="friends-icon ' . $active.'"> |
||
| 924 | <a href="' . api_get_path(WEB_CODE_PATH).'social/friends.php"> |
||
| 925 | ' . $friendsIcon.' '.get_lang('Friends').' |
||
| 926 | </a> |
||
| 927 | </li>'; |
||
| 928 | $active = $show == 'browse_groups' ? 'active' : null; |
||
| 929 | $links .= ' |
||
| 930 | <li class="browse-groups-icon ' . $active.'"> |
||
| 931 | <a href="' . api_get_path(WEB_CODE_PATH).'social/groups.php"> |
||
| 932 | ' . $groupsIcon.' '.get_lang('SocialGroups').' |
||
| 933 | </a> |
||
| 934 | </li>'; |
||
| 935 | |||
| 936 | //Search users |
||
| 937 | $active = $show == 'search' ? 'active' : null; |
||
| 938 | $links .= ' |
||
| 939 | <li class="search-icon ' . $active.'"> |
||
| 940 | <a href="' . api_get_path(WEB_CODE_PATH).'social/search.php"> |
||
| 941 | ' . $searchIcon.' '.get_lang('Search').' |
||
| 942 | </a> |
||
| 943 | </li>'; |
||
| 944 | |||
| 945 | //My files |
||
| 946 | $active = $show == 'myfiles' ? 'active' : null; |
||
| 947 | |||
| 948 | $myFiles = ' |
||
| 949 | <li class="myfiles-icon ' . $active.'"> |
||
| 950 | <a href="' . api_get_path(WEB_CODE_PATH).'social/myfiles.php"> |
||
| 951 | ' . $filesIcon.' '.get_lang('MyFiles').' |
||
| 952 | </a> |
||
| 953 | </li>'; |
||
| 954 | |||
| 955 | if (api_get_setting('allow_my_files') === 'false') { |
||
| 956 | $myFiles = ''; |
||
| 957 | } |
||
| 958 | $links .= $myFiles; |
||
| 959 | $links .= '</ul>'; |
||
| 960 | |||
| 961 | $html .= Display::panelCollapse( |
||
| 962 | get_lang('SocialNetwork'), |
||
| 963 | $links, |
||
| 964 | 'social-network-menu', |
||
| 965 | null, |
||
| 966 | 'sn-sidebar', |
||
| 967 | 'sn-sidebar-collapse' |
||
| 968 | ); |
||
| 969 | } |
||
| 970 | |||
| 971 | if (in_array($show, $show_groups) && !empty($group_id)) { |
||
| 972 | $html .= $usergroup->show_group_column_information( |
||
| 973 | $group_id, |
||
| 974 | api_get_user_id(), |
||
| 975 | $show |
||
| 976 | ); |
||
| 977 | } |
||
| 978 | |||
| 979 | if ($show == 'shared_profile') { |
||
| 980 | $links = '<ul class="nav nav-pills nav-stacked">'; |
||
| 981 | // My own profile |
||
| 982 | if ($show_full_profile && $user_id == intval(api_get_user_id())) { |
||
| 983 | $links .= ' |
||
| 984 | <li class="home-icon '.$active.'"> |
||
| 985 | <a href="'.api_get_path(WEB_CODE_PATH).'social/home.php"> |
||
| 986 | '.$homeIcon.' '.get_lang('Home').' |
||
| 987 | </a> |
||
| 988 | </li> |
||
| 989 | <li class="messages-icon '.$active.'"> |
||
| 990 | <a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php"> |
||
| 991 | '.$messagesIcon.' '.get_lang('Messages').$count_unread_message.' |
||
| 992 | </a> |
||
| 993 | </li>'; |
||
| 994 | $active = $show == 'invitations' ? 'active' : null; |
||
| 995 | $links .= ' |
||
| 996 | <li class="invitations-icon'.$active.'"> |
||
| 997 | <a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php"> |
||
| 998 | '.$invitationsIcon.' '.get_lang('Invitations').$total_invitations.' |
||
| 999 | </a> |
||
| 1000 | </li>'; |
||
| 1001 | |||
| 1002 | $links .= ' |
||
| 1003 | <li class="shared-profile-icon active"> |
||
| 1004 | <a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php"> |
||
| 1005 | '.$sharedProfileIcon.' '.get_lang('ViewMySharedProfile').' |
||
| 1006 | </a> |
||
| 1007 | </li> |
||
| 1008 | <li class="friends-icon"> |
||
| 1009 | <a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php"> |
||
| 1010 | '.$friendsIcon.' '.get_lang('Friends').' |
||
| 1011 | </a> |
||
| 1012 | </li> |
||
| 1013 | <li class="browse-groups-icon"> |
||
| 1014 | <a href="'.api_get_path(WEB_CODE_PATH).'social/groups.php"> |
||
| 1015 | '.$groupsIcon.' '.get_lang('SocialGroups').' |
||
| 1016 | </a> |
||
| 1017 | </li>'; |
||
| 1018 | $active = $show == 'search' ? 'active' : null; |
||
| 1019 | $links .= ' |
||
| 1020 | <li class="search-icon '.$active.'"> |
||
| 1021 | <a href="'.api_get_path(WEB_CODE_PATH).'social/search.php"> |
||
| 1022 | '.$searchIcon.' '.get_lang('Search').' |
||
| 1023 | </a> |
||
| 1024 | </li>'; |
||
| 1025 | $active = $show == 'myfiles' ? 'active' : null; |
||
| 1026 | |||
| 1027 | $myFiles = ' |
||
| 1028 | <li class="myfiles-icon '.$active.'"> |
||
| 1029 | <a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php"> |
||
| 1030 | '.$filesIcon.' '.get_lang('MyFiles').' |
||
| 1031 | </a> |
||
| 1032 | </li>'; |
||
| 1033 | |||
| 1034 | if (api_get_setting('allow_my_files') === 'false') { |
||
| 1035 | $myFiles = ''; |
||
| 1036 | } |
||
| 1037 | $links .= $myFiles; |
||
| 1038 | } |
||
| 1039 | |||
| 1040 | // My friend profile. |
||
| 1041 | if ($user_id != api_get_user_id()) { |
||
| 1042 | $sendMessageText = get_lang('SendMessage'); |
||
| 1043 | $sendMessageIcon = Display::return_icon( |
||
| 1044 | 'new-message.png', |
||
| 1045 | $sendMessageText |
||
| 1046 | ); |
||
| 1047 | $sendMessageUrl = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?'. http_build_query([ |
||
| 1048 | 'a' => 'get_user_popup', |
||
| 1049 | 'user_id' => $user_id, |
||
| 1050 | ]); |
||
| 1051 | |||
| 1052 | $links .= '<li>'; |
||
| 1053 | $links .= Display::url( |
||
| 1054 | "$sendMessageIcon $sendMessageText", |
||
| 1055 | $sendMessageUrl, |
||
| 1056 | [ |
||
| 1057 | 'class' => 'ajax', |
||
| 1058 | 'title' => $sendMessageText, |
||
| 1059 | 'data-title' => $sendMessageText, |
||
| 1060 | ] |
||
| 1061 | ); |
||
| 1062 | $links .= '</li>'; |
||
| 1063 | } |
||
| 1064 | |||
| 1065 | // Check if I already sent an invitation message |
||
| 1066 | $invitation_sent_list = self::get_list_invitation_sent_by_user_id( |
||
| 1067 | api_get_user_id() |
||
| 1068 | ); |
||
| 1069 | |||
| 1070 | if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && |
||
| 1071 | count($invitation_sent_list[$user_id]) > 0 |
||
| 1072 | ) { |
||
| 1073 | $links .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">'. |
||
| 1074 | Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')) |
||
| 1075 | .' '.get_lang('YouAlreadySentAnInvitation').'</a></li>'; |
||
| 1076 | } else { |
||
| 1077 | if (!$show_full_profile) { |
||
| 1078 | $links .= '<li> |
||
| 1079 | <a class="btn-to-send-invitation" href="#" data-send-to="'.$user_id.'" title="'.get_lang('SendInvitation').'">'. |
||
| 1080 | Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')).' '.get_lang('SendInvitation'). |
||
| 1081 | '</a></li>'; |
||
| 1082 | } |
||
| 1083 | } |
||
| 1084 | |||
| 1085 | $links .= '</ul>'; |
||
| 1086 | $html .= Display::panelCollapse( |
||
| 1087 | get_lang('SocialNetwork'), |
||
| 1088 | $links, |
||
| 1089 | 'social-network-menu', |
||
| 1090 | null, |
||
| 1091 | 'sn-sidebar', |
||
| 1092 | 'sn-sidebar-collapse' |
||
| 1093 | ); |
||
| 1094 | |||
| 1095 | if ($show_full_profile && $user_id == intval(api_get_user_id())) { |
||
| 1096 | $personal_course_list = UserManager::get_personal_session_course_list($user_id); |
||
| 1097 | $course_list_code = []; |
||
| 1098 | $i = 1; |
||
| 1099 | if (is_array($personal_course_list)) { |
||
| 1100 | foreach ($personal_course_list as $my_course) { |
||
| 1101 | if ($i <= 10) { |
||
| 1102 | $course_list_code[] = ['code' => $my_course['code']]; |
||
| 1103 | } else { |
||
| 1104 | break; |
||
| 1105 | } |
||
| 1106 | $i++; |
||
| 1107 | } |
||
| 1108 | // To avoid repeated courses |
||
| 1109 | $course_list_code = array_unique_dimensional($course_list_code); |
||
| 1110 | } |
||
| 1111 | |||
| 1112 | // Announcements |
||
| 1113 | $my_announcement_by_user_id = intval($user_id); |
||
| 1114 | $announcements = []; |
||
| 1115 | foreach ($course_list_code as $course) { |
||
| 1116 | $course_info = api_get_course_info($course['code']); |
||
| 1117 | if (!empty($course_info)) { |
||
| 1118 | $content = AnnouncementManager::get_all_annoucement_by_user_course( |
||
| 1119 | $course_info['code'], |
||
| 1120 | $my_announcement_by_user_id |
||
| 1121 | ); |
||
| 1122 | |||
| 1123 | if (!empty($content)) { |
||
| 1124 | $url = Display::url( |
||
| 1125 | Display::return_icon( |
||
| 1126 | 'announcement.png', |
||
| 1127 | get_lang('Announcements') |
||
| 1128 | ).$course_info['name'].' ('.$content['count'].')', |
||
| 1129 | api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$course['code'] |
||
| 1130 | ); |
||
| 1131 | $announcements[] = Display::tag('li', $url); |
||
| 1132 | } |
||
| 1133 | } |
||
| 1134 | } |
||
| 1135 | if (!empty($announcements)) { |
||
| 1136 | $html .= '<div class="social_menu_items">'; |
||
| 1137 | $html .= '<ul>'; |
||
| 1138 | foreach ($announcements as $announcement) { |
||
| 1139 | $html .= $announcement; |
||
| 1140 | } |
||
| 1141 | $html .= '</ul>'; |
||
| 1142 | $html .= '</div>'; |
||
| 1143 | } |
||
| 1144 | } |
||
| 1145 | } |
||
| 1146 | |||
| 1147 | if ($show_delete_account_button) { |
||
| 1148 | $html .= '<div class="panel panel-default"><div class="panel-body">'; |
||
| 1149 | $html .= '<ul class="nav nav-pills nav-stacked"><li>'; |
||
| 1150 | $url = api_get_path(WEB_CODE_PATH).'auth/unsubscribe_account.php'; |
||
| 1151 | $html .= Display::url( |
||
| 1152 | Display::return_icon( |
||
| 1153 | 'delete.png', |
||
| 1154 | get_lang('Unsubscribe'), |
||
| 1155 | [], |
||
| 1156 | ICON_SIZE_TINY |
||
| 1157 | ).get_lang('Unsubscribe'), |
||
| 1158 | $url |
||
| 1159 | ); |
||
| 1160 | $html .= '</li></ul>'; |
||
| 1161 | $html .= '</div></div>'; |
||
| 1162 | } |
||
| 1163 | $html .= ''; |
||
| 1164 | |||
| 1165 | return $html; |
||
| 1166 | } |
||
| 1167 | |||
| 1168 | /** |
||
| 1169 | * Displays a sortable table with the list of online users. |
||
| 1170 | * @param array $user_list The list of users to be shown |
||
| 1171 | * @param bool $wrap Whether we want the function to wrap the spans list in a div or not |
||
| 1172 | * @return string HTML block or null if and ID was defined |
||
| 1173 | * @assert (null) === false |
||
| 1174 | */ |
||
| 1175 | public static function display_user_list($user_list, $wrap = true) |
||
| 1176 | { |
||
| 1177 | $html = null; |
||
| 1178 | |||
| 1179 | if (isset($_GET['id']) || count($user_list) < 1) { |
||
| 1180 | return false; |
||
| 1181 | } |
||
| 1182 | |||
| 1183 | $course_url = ''; |
||
| 1184 | if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) { |
||
| 1185 | $course_url = '&cidReq='.Security::remove_XSS($_GET['cidReq']); |
||
| 1186 | } |
||
| 1187 | |||
| 1188 | foreach ($user_list as $uid) { |
||
| 1189 | $user_info = api_get_user_info($uid, true); |
||
| 1190 | $lastname = $user_info['lastname']; |
||
| 1191 | $firstname = $user_info['firstname']; |
||
| 1192 | $completeName = $firstname.', '.$lastname; |
||
| 1193 | |||
| 1194 | $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); |
||
| 1195 | $status_icon_chat = null; |
||
| 1196 | if (isset($user_info['user_is_online_in_chat']) && $user_info['user_is_online_in_chat'] == 1) { |
||
| 1197 | $status_icon_chat = Display::return_icon('online.png', get_lang('Online')); |
||
| 1198 | } else { |
||
| 1199 | $status_icon_chat = Display::return_icon('offline.png', get_lang('Offline')); |
||
| 1200 | } |
||
| 1201 | |||
| 1202 | $userPicture = $user_info['avatar']; |
||
| 1203 | $officialCode = ''; |
||
| 1204 | if (api_get_setting('show_official_code_whoisonline') == 'true') { |
||
| 1205 | $officialCode .= '<div class="items-user-official-code"><p style="min-height: 30px;" title="'.get_lang('OfficialCode').'">'.$user_info['official_code'].'</p></div>'; |
||
| 1206 | } |
||
| 1207 | $img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">'; |
||
| 1208 | |||
| 1209 | $url = null; |
||
| 1210 | // Anonymous users can't have access to the profile |
||
| 1211 | if (!api_is_anonymous()) { |
||
| 1212 | if (api_get_setting('allow_social_tool') === 'true') { |
||
| 1213 | $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url; |
||
| 1214 | } else { |
||
| 1215 | $url = '?id='.$uid.$course_url; |
||
| 1216 | } |
||
| 1217 | } else { |
||
| 1218 | $url = null; |
||
| 1219 | } |
||
| 1220 | $name = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>'; |
||
| 1221 | |||
| 1222 | $html .= '<div class="col-xs-6 col-md-2"> |
||
| 1223 | <div class="items-user"> |
||
| 1224 | <div class="items-user-avatar"><a href="'.$url.'">'.$img.'</a></div> |
||
| 1225 | <div class="items-user-name"> |
||
| 1226 | '.$name.' |
||
| 1227 | </div> |
||
| 1228 | '.$officialCode.' |
||
| 1229 | <div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div> |
||
| 1230 | </div> |
||
| 1231 | </div>'; |
||
| 1232 | } |
||
| 1233 | |||
| 1234 | return $html; |
||
| 1235 | } |
||
| 1236 | |||
| 1237 | /** |
||
| 1238 | * Displays the information of an individual user |
||
| 1239 | * @param int $user_id |
||
| 1240 | * @return string |
||
| 1241 | */ |
||
| 1242 | public static function display_individual_user($user_id) |
||
| 1243 | { |
||
| 1244 | global $interbreadcrumb; |
||
| 1245 | $safe_user_id = intval($user_id); |
||
| 1246 | $currentUserId = api_get_user_id(); |
||
| 1247 | |||
| 1248 | $user_table = Database::get_main_table(TABLE_MAIN_USER); |
||
| 1249 | $sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id; |
||
| 1250 | $result = Database::query($sql); |
||
| 1251 | $html = null; |
||
| 1252 | if (Database::num_rows($result) == 1) { |
||
| 1253 | $user_object = Database::fetch_object($result); |
||
| 1254 | $userInfo = api_get_user_info($user_id); |
||
| 1255 | $alt = $userInfo['complete_name'].($currentUserId == $user_id ? ' ('.get_lang('Me').')' : ''); |
||
| 1256 | $status = get_status_from_code($user_object->status); |
||
| 1257 | $interbreadcrumb[] = ['url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList')]; |
||
| 1258 | |||
| 1259 | $html .= '<div class ="thumbnail">'; |
||
| 1260 | $fullurl = $userInfo['avatar']; |
||
| 1261 | |||
| 1262 | $html .= '<img src="'.$fullurl.'" alt="'.$alt.'" />'; |
||
| 1263 | |||
| 1264 | if (!empty($status)) { |
||
| 1265 | $html .= '<div class="caption">'.$status.'</div>'; |
||
| 1266 | } |
||
| 1267 | $html .= '</div>'; |
||
| 1268 | |||
| 1269 | if (api_get_setting('show_email_addresses') == 'true') { |
||
| 1270 | $html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'<br />'; |
||
| 1271 | } |
||
| 1272 | |||
| 1273 | if ($user_object->competences) { |
||
| 1274 | $html .= Display::page_subheader(get_lang('MyCompetences')); |
||
| 1275 | $html .= '<p>'.$user_object->competences.'</p>'; |
||
| 1276 | } |
||
| 1277 | if ($user_object->diplomas) { |
||
| 1278 | $html .= Display::page_subheader(get_lang('MyDiplomas')); |
||
| 1279 | $html .= '<p>'.$user_object->diplomas.'</p>'; |
||
| 1280 | } |
||
| 1281 | if ($user_object->teach) { |
||
| 1282 | $html .= Display::page_subheader(get_lang('MyTeach')); |
||
| 1283 | $html .= '<p>'.$user_object->teach.'</p>'; |
||
| 1284 | } |
||
| 1285 | self::display_productions($user_object->user_id); |
||
| 1286 | if ($user_object->openarea) { |
||
| 1287 | $html .= Display::page_subheader(get_lang('MyPersonalOpenArea')); |
||
| 1288 | $html .= '<p>'.$user_object->openarea.'</p>'; |
||
| 1289 | } |
||
| 1290 | } else { |
||
| 1291 | $html .= '<div class="actions-title">'; |
||
| 1292 | $html .= get_lang('UsersOnLineList'); |
||
| 1293 | $html .= '</div>'; |
||
| 1294 | } |
||
| 1295 | |||
| 1296 | return $html; |
||
| 1297 | } |
||
| 1298 | |||
| 1299 | /** |
||
| 1300 | * Display productions in who is online |
||
| 1301 | * @param int $user_id User id |
||
| 1302 | */ |
||
| 1303 | public static function display_productions($user_id) |
||
| 1304 | { |
||
| 1305 | $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web'); |
||
| 1306 | $sysdir = UserManager::getUserPathById($user_id, 'system'); |
||
| 1307 | $webdir = UserManager::getUserPathById($user_id, 'web'); |
||
| 1308 | |||
| 1309 | if (!is_dir($sysdir)) { |
||
| 1310 | mkdir($sysdir, api_get_permissions_for_new_directories(), true); |
||
| 1311 | } |
||
| 1312 | |||
| 1313 | $productions = UserManager::get_user_productions($user_id); |
||
| 1314 | |||
| 1315 | if (count($productions) > 0) { |
||
| 1316 | echo '<dt><strong>'.get_lang('Productions').'</strong></dt>'; |
||
| 1317 | echo '<dd><ul>'; |
||
| 1318 | foreach ($productions as $file) { |
||
| 1319 | // Only display direct file links to avoid browsing an empty directory |
||
| 1320 | if (is_file($sysdir.$file) && $file != $webdir_array['file']) { |
||
| 1321 | echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>'; |
||
| 1322 | } |
||
| 1323 | // Real productions are under a subdirectory by the User's id |
||
| 1324 | if (is_dir($sysdir.$file)) { |
||
| 1325 | $subs = scandir($sysdir.$file); |
||
| 1326 | foreach ($subs as $my => $sub) { |
||
| 1327 | if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) { |
||
| 1328 | echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>'; |
||
| 1329 | } |
||
| 1330 | } |
||
| 1331 | } |
||
| 1332 | } |
||
| 1333 | echo '</ul></dd>'; |
||
| 1334 | } |
||
| 1335 | } |
||
| 1336 | |||
| 1337 | /** |
||
| 1338 | * @param string $content |
||
| 1339 | * @param string $span_count |
||
| 1340 | * @return string |
||
| 1341 | */ |
||
| 1342 | public static function social_wrapper_div($content, $span_count) |
||
| 1343 | { |
||
| 1344 | $span_count = intval($span_count); |
||
| 1345 | $html = '<div class="span'.$span_count.'">'; |
||
| 1346 | $html .= '<div class="well_border">'; |
||
| 1347 | $html .= $content; |
||
| 1348 | $html .= '</div></div>'; |
||
| 1349 | |||
| 1350 | return $html; |
||
| 1351 | } |
||
| 1352 | |||
| 1353 | /** |
||
| 1354 | * Dummy function |
||
| 1355 | * |
||
| 1356 | */ |
||
| 1357 | public static function get_plugins($place = SOCIAL_CENTER_PLUGIN) |
||
| 1358 | { |
||
| 1359 | $content = ''; |
||
| 1360 | switch ($place) { |
||
| 1361 | case SOCIAL_CENTER_PLUGIN: |
||
| 1362 | $social_plugins = [1, 2]; |
||
| 1363 | if (is_array($social_plugins) && count($social_plugins) > 0) { |
||
| 1364 | $content .= '<div id="social-plugins">'; |
||
| 1365 | foreach ($social_plugins as $plugin) { |
||
| 1366 | $content .= '<div class="social-plugin-item">'; |
||
| 1367 | $content .= $plugin; |
||
| 1368 | $content .= '</div>'; |
||
| 1369 | } |
||
| 1370 | $content .= '</div>'; |
||
| 1371 | } |
||
| 1372 | break; |
||
| 1373 | case SOCIAL_LEFT_PLUGIN: |
||
| 1374 | break; |
||
| 1375 | case SOCIAL_RIGHT_PLUGIN: |
||
| 1376 | break; |
||
| 1377 | } |
||
| 1378 | |||
| 1379 | return $content; |
||
| 1380 | } |
||
| 1381 | /** |
||
| 1382 | * Sends a message to someone's wall |
||
| 1383 | * @param int $userId id of author |
||
| 1384 | * @param int $friendId id where we send the message |
||
| 1385 | * @param string $messageContent of the message |
||
| 1386 | * @param int $messageId id parent |
||
| 1387 | * @param string $messageStatus status type of message |
||
| 1388 | * @return boolean |
||
| 1389 | * @author Yannick Warnier |
||
| 1390 | */ |
||
| 1391 | public static function sendWallMessage( |
||
| 1392 | $userId, |
||
| 1393 | $friendId, |
||
| 1394 | $messageContent, |
||
| 1395 | $messageId = 0, |
||
| 1396 | $messageStatus = '' |
||
| 1397 | ) { |
||
| 1398 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
| 1399 | $userId = intval($userId); |
||
| 1400 | $friendId = intval($friendId); |
||
| 1401 | $messageId = intval($messageId); |
||
| 1402 | |||
| 1403 | // Just in case we replace the and \n and \n\r while saving in the DB |
||
| 1404 | $messageContent = str_replace(["\n", "\n\r"], '<br />', $messageContent); |
||
| 1405 | $now = api_get_utc_datetime(); |
||
| 1406 | |||
| 1407 | $attributes = [ |
||
| 1408 | 'user_sender_id' => $userId, |
||
| 1409 | 'user_receiver_id' => $friendId, |
||
| 1410 | 'msg_status' => $messageStatus, |
||
| 1411 | 'send_date' => $now, |
||
| 1412 | 'title' => '', |
||
| 1413 | 'content' => $messageContent, |
||
| 1414 | 'parent_id' => $messageId, |
||
| 1415 | 'group_id' => 0, |
||
| 1416 | 'update_date' => $now |
||
| 1417 | ]; |
||
| 1418 | |||
| 1419 | return Database::insert($tblMessage, $attributes); |
||
| 1420 | } |
||
| 1421 | |||
| 1422 | /** |
||
| 1423 | * Send File attachment (jpg,png) |
||
| 1424 | * @author Anibal Copitan |
||
| 1425 | * @param int $userId id user |
||
| 1426 | * @param array $fileAttach |
||
| 1427 | * @param int $messageId id message (relation with main message) |
||
| 1428 | * @param string $fileComment description attachment file |
||
| 1429 | * @return bool |
||
| 1430 | */ |
||
| 1431 | public static function sendWallMessageAttachmentFile( |
||
| 1432 | $userId, |
||
| 1433 | $fileAttach, |
||
| 1434 | $messageId, |
||
| 1435 | $fileComment = '' |
||
| 1436 | ) { |
||
| 1437 | $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); |
||
| 1438 | |||
| 1439 | // create directory |
||
| 1440 | $social = '/social/'; |
||
| 1441 | $pathMessageAttach = UserManager::getUserPathById($userId, 'system').'message_attachments'.$social; |
||
| 1442 | $safeFileComment = Database::escape_string($fileComment); |
||
| 1443 | $safeFileName = Database::escape_string($fileAttach['name']); |
||
| 1444 | |||
| 1445 | $extension = strtolower(substr(strrchr($safeFileName, '.'), 1)); |
||
| 1446 | $allowedTypes = api_get_supported_image_extensions(); |
||
| 1447 | if (!in_array($extension, $allowedTypes)) { |
||
| 1448 | $flag = false; |
||
| 1449 | } else { |
||
| 1450 | $newFileName = uniqid('').'.'.$extension; |
||
| 1451 | if (!file_exists($pathMessageAttach)) { |
||
| 1452 | @mkdir($pathMessageAttach, api_get_permissions_for_new_directories(), true); |
||
| 1453 | } |
||
| 1454 | |||
| 1455 | $newPath = $pathMessageAttach.$newFileName; |
||
| 1456 | if (is_uploaded_file($fileAttach['tmp_name'])) { |
||
| 1457 | @copy($fileAttach['tmp_name'], $newPath); |
||
| 1458 | } |
||
| 1459 | |||
| 1460 | $small = self::resize_picture($newPath, IMAGE_WALL_SMALL_SIZE); |
||
| 1461 | $medium = self::resize_picture($newPath, IMAGE_WALL_MEDIUM_SIZE); |
||
| 1462 | |||
| 1463 | $big = new Image($newPath); |
||
| 1464 | $ok = $small && $small->send_image($pathMessageAttach.IMAGE_WALL_SMALL.'_'.$newFileName) && |
||
| 1465 | $medium && $medium->send_image($pathMessageAttach.IMAGE_WALL_MEDIUM.'_'.$newFileName) && |
||
| 1466 | $big && $big->send_image($pathMessageAttach.IMAGE_WALL_BIG.'_'.$newFileName); |
||
| 1467 | |||
| 1468 | // Insert |
||
| 1469 | $newFileName = $social.$newFileName; |
||
| 1470 | |||
| 1471 | $params = [ |
||
| 1472 | 'filename' => $safeFileName, |
||
| 1473 | 'comment' => $safeFileComment, |
||
| 1474 | 'path' => $newFileName, |
||
| 1475 | 'message_id' => $messageId, |
||
| 1476 | 'size' => $fileAttach['size'], |
||
| 1477 | ]; |
||
| 1478 | Database::insert($tbl_message_attach, $params); |
||
| 1479 | $flag = true; |
||
| 1480 | } |
||
| 1481 | |||
| 1482 | return $flag; |
||
| 1483 | } |
||
| 1484 | |||
| 1485 | /** |
||
| 1486 | * Gets all messages from someone's wall (within specific limits) |
||
| 1487 | * @param int $userId id of wall shown |
||
| 1488 | * @param string $messageStatus status wall message |
||
| 1489 | * @param int|string $parentId id message (Post main) |
||
| 1490 | * @param string $start Date from which we want to show the messages, in UTC time |
||
| 1491 | * @param int $limit Limit for the number of parent messages we want to show |
||
| 1492 | * @param int $offset Wall message query offset |
||
| 1493 | * @return array |
||
| 1494 | * @author Yannick Warnier |
||
| 1495 | */ |
||
| 1496 | public static function getWallMessages( |
||
| 1497 | $userId, |
||
| 1498 | $messageStatus, |
||
| 1499 | $parentId = '', |
||
| 1500 | $start = null, |
||
| 1501 | $limit = 10, |
||
| 1502 | $offset = 0 |
||
| 1503 | ) { |
||
| 1504 | if (empty($start)) { |
||
| 1505 | $start = '0000-00-00'; |
||
| 1506 | } |
||
| 1507 | |||
| 1508 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
| 1509 | $tblMessageAttachment = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); |
||
| 1510 | |||
| 1511 | $userId = intval($userId); |
||
| 1512 | $start = Database::escape_string($start); |
||
| 1513 | $limit = intval($limit); |
||
| 1514 | |||
| 1515 | $sql = "SELECT |
||
| 1516 | id, |
||
| 1517 | user_sender_id, |
||
| 1518 | user_receiver_id, |
||
| 1519 | send_date, |
||
| 1520 | content, |
||
| 1521 | parent_id, |
||
| 1522 | ( |
||
| 1523 | SELECT ma.path FROM $tblMessageAttachment ma |
||
| 1524 | WHERE ma.message_id = tm.id |
||
| 1525 | ) as path, |
||
| 1526 | ( |
||
| 1527 | SELECT ma.filename FROM $tblMessageAttachment ma |
||
| 1528 | WHERE ma.message_id = tm.id |
||
| 1529 | ) as filename |
||
| 1530 | FROM $tblMessage tm |
||
| 1531 | WHERE |
||
| 1532 | user_receiver_id = $userId AND |
||
| 1533 | send_date > '$start' |
||
| 1534 | "; |
||
| 1535 | |||
| 1536 | $sql .= (empty($messageStatus) || is_null($messageStatus)) ? '' : " AND msg_status = '$messageStatus' "; |
||
| 1537 | $sql .= (empty($parentId) || is_null($parentId)) ? '' : " AND parent_id = '$parentId' "; |
||
| 1538 | $sql .= " ORDER BY send_date DESC LIMIT $offset, $limit "; |
||
| 1539 | $messages = []; |
||
| 1540 | $res = Database::query($sql); |
||
| 1541 | if (Database::num_rows($res) > 0) { |
||
| 1542 | while ($row = Database::fetch_array($res)) { |
||
| 1543 | $messages[] = $row; |
||
| 1544 | } |
||
| 1545 | } |
||
| 1546 | |||
| 1547 | return $messages; |
||
| 1548 | } |
||
| 1549 | |||
| 1550 | /** |
||
| 1551 | * Gets all messages from someone's wall (within specific limits), formatted |
||
| 1552 | * @param int $userId USER ID of the person's wall |
||
| 1553 | * @param int $friendId id person |
||
| 1554 | * @param int $idMessage id message |
||
| 1555 | * @param string $start Start date (from when we want the messages until today) |
||
| 1556 | * @param int $limit Limit to the number of messages we want |
||
| 1557 | * @param int $offset Wall messages offset |
||
| 1558 | * @return string HTML formatted string to show messages |
||
| 1559 | */ |
||
| 1560 | public static function getWallMessagesHTML( |
||
| 1561 | $userId, |
||
| 1562 | $friendId, |
||
| 1563 | $idMessage, |
||
| 1564 | $start = null, |
||
| 1565 | $limit = 10, |
||
| 1566 | $offset = 0 |
||
| 1567 | ) { |
||
| 1568 | if (empty($start)) { |
||
| 1569 | $start = '0000-00-00'; |
||
| 1570 | } |
||
| 1571 | |||
| 1572 | $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId); |
||
| 1573 | $messages = self::getWallMessages( |
||
| 1574 | $userId, |
||
| 1575 | MESSAGE_STATUS_WALL, |
||
| 1576 | $idMessage, |
||
| 1577 | $start, |
||
| 1578 | $limit, |
||
| 1579 | $offset |
||
| 1580 | ); |
||
| 1581 | $formattedList = '<div class="sub-mediapost">'; |
||
| 1582 | $users = []; |
||
| 1583 | |||
| 1584 | // The messages are ordered by date descendant, for comments we need ascendant |
||
| 1585 | krsort($messages); |
||
| 1586 | foreach ($messages as $message) { |
||
| 1587 | $date = api_get_local_time($message['send_date']); |
||
| 1588 | $userIdLoop = $message['user_sender_id']; |
||
| 1589 | if (!isset($users[$userIdLoop])) { |
||
| 1590 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
| 1591 | } |
||
| 1592 | |||
| 1593 | $nameComplete = api_is_western_name_order() |
||
| 1594 | ? $users[$userIdLoop]['firstname'].' '.$users[$userIdLoop]['lastname'] |
||
| 1595 | : $users[$userIdLoop]['lastname'].' '.$users[$userIdLoop]['firstname']; |
||
| 1596 | $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop; |
||
| 1597 | $media = ''; |
||
| 1598 | $media .= '<div class="rep-post">'; |
||
| 1599 | $media .= '<div class="col-md-2 col-xs-2 social-post-answers">'; |
||
| 1600 | $media .= '<div class="user-image pull-right">'; |
||
| 1601 | $media .= '<a href="'.$url.'" ><img src="'.$users[$userIdLoop]['avatar']. |
||
| 1602 | '" alt="'.$users[$userIdLoop]['complete_name'].'" class="avatar-thumb"></a>'; |
||
| 1603 | $media .= '</div>'; |
||
| 1604 | $media .= '</div>'; |
||
| 1605 | $media .= '<div class="col-md-9 col-xs-9 social-post-answers">'; |
||
| 1606 | $media .= '<div class="user-data">'; |
||
| 1607 | $media .= '<div class="username">'.'<a href="'.$url.'">'.$nameComplete.'</a> |
||
| 1608 | <span>'.Security::remove_XSS($message['content']).'</span> |
||
| 1609 | </div>'; |
||
| 1610 | $media .= '<div class="time timeago" title="'.$date.'">'.$date.'</div>'; |
||
| 1611 | $media .= '<br />'; |
||
| 1612 | $media .= '</div>'; |
||
| 1613 | $media .= '</div>'; |
||
| 1614 | $media .= '</div>'; |
||
| 1615 | if ($isOwnWall) { |
||
| 1616 | $media .= '<div class="col-md-1 col-xs-1 social-post-answers">'; |
||
| 1617 | $media .= '<div class="pull-right deleted-mgs">'; |
||
| 1618 | $media .= '<a title="'.get_lang("SocialMessageDelete").'" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='. |
||
| 1619 | $message['id'].'">x</a>'; |
||
| 1620 | $media .= '</div>'; |
||
| 1621 | $media .= '</div>'; |
||
| 1622 | } |
||
| 1623 | |||
| 1624 | $formattedList .= $media; |
||
| 1625 | } |
||
| 1626 | |||
| 1627 | $formattedList .= '</div>'; |
||
| 1628 | |||
| 1629 | $formattedList .= '<div class="mediapost-form">'; |
||
| 1630 | $formattedList .= '<form name="social_wall_message" method="POST"> |
||
| 1631 | <label for="social_wall_new_msg" class="hide">'.get_lang('SocialWriteNewComment').'</label> |
||
| 1632 | <input type="hidden" name = "messageId" value="'.$idMessage.'" /> |
||
| 1633 | <textarea placeholder="'.get_lang('SocialWriteNewComment'). |
||
| 1634 | '" name="social_wall_new_msg" rows="1" style="width:80%;" ></textarea> |
||
| 1635 | <button type="submit" name="social_wall_new_msg_submit" |
||
| 1636 | class="pull-right btn btn-default" /><em class="fa fa-pencil"></em> '.get_lang('Post').'</button> |
||
| 1637 | </form>'; |
||
| 1638 | $formattedList .= '</div>'; |
||
| 1639 | |||
| 1640 | return $formattedList; |
||
| 1641 | } |
||
| 1642 | |||
| 1643 | /** |
||
| 1644 | * Gets all user's starting wall messages (within specific limits) |
||
| 1645 | * @param int $userId User's id |
||
| 1646 | * @param int $friendId Friend's id |
||
| 1647 | * @param date $start Start date (from when we want the messages until today) |
||
| 1648 | * @param int $limit Limit to the number of messages we want |
||
| 1649 | * @param int $offset Wall messages offset |
||
| 1650 | * @return array $data return user's starting wall messages along with message extra data |
||
| 1651 | */ |
||
| 1652 | public static function getWallMessagesPostHTML( |
||
| 1653 | $userId, |
||
| 1654 | $friendId = 0, |
||
| 1655 | $start = null, |
||
| 1656 | $limit = 10, |
||
| 1657 | $offset = 0 |
||
| 1658 | ) { |
||
| 1659 | if (empty($start)) { |
||
| 1660 | $start = '0000-00-00'; |
||
| 1661 | } |
||
| 1662 | $isOwnWall = api_get_user_id() == $userId && $userId == $friendId; |
||
| 1663 | $messages = self::getWallMessages( |
||
| 1664 | $userId, |
||
| 1665 | MESSAGE_STATUS_WALL_POST, |
||
| 1666 | null, |
||
| 1667 | $start, |
||
| 1668 | $limit, |
||
| 1669 | $offset |
||
| 1670 | ); |
||
| 1671 | $users = []; |
||
| 1672 | $data = []; |
||
| 1673 | foreach ($messages as $key => $message) { |
||
| 1674 | $userIdLoop = $message['user_sender_id']; |
||
| 1675 | $userFriendIdLoop = $message['user_receiver_id']; |
||
| 1676 | |||
| 1677 | if (!isset($users[$userIdLoop])) { |
||
| 1678 | $users[$userIdLoop] = api_get_user_info($userIdLoop); |
||
| 1679 | } |
||
| 1680 | |||
| 1681 | if (!isset($users[$userFriendIdLoop])) { |
||
| 1682 | $users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop); |
||
| 1683 | } |
||
| 1684 | |||
| 1685 | $html = ''; |
||
| 1686 | $html .= self::headerMessagePost( |
||
| 1687 | $message['user_sender_id'], |
||
| 1688 | $message['user_receiver_id'], |
||
| 1689 | $users, |
||
| 1690 | $message, |
||
| 1691 | $isOwnWall |
||
| 1692 | ); |
||
| 1693 | |||
| 1694 | $data[$key]['id'] = $message['id']; |
||
| 1695 | $data[$key]['html'] = $html; |
||
| 1696 | } |
||
| 1697 | |||
| 1698 | return $data; |
||
| 1699 | } |
||
| 1700 | |||
| 1701 | /** |
||
| 1702 | * Returns the formatted header message post |
||
| 1703 | * @param int $authorId Author's id |
||
| 1704 | * @param int $receiverId Receiver's id |
||
| 1705 | * @param array $users Author's and receiver's data |
||
| 1706 | * @param array $message Message data |
||
| 1707 | * @param boolean $isOwnWall Determines if the author is in its own social wall or not |
||
| 1708 | * @return string $html The formatted header message post |
||
| 1709 | */ |
||
| 1710 | private static function headerMessagePost($authorId, $receiverId, $users, $message, $isOwnWall = false) |
||
| 1711 | { |
||
| 1712 | $date = api_get_local_time($message['send_date']); |
||
| 1713 | $avatarAuthor = $users[$authorId]['avatar']; |
||
| 1714 | $urlAuthor = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$authorId; |
||
| 1715 | $nameCompleteAuthor = api_get_person_name( |
||
| 1716 | $users[$authorId]['firstname'], |
||
| 1717 | $users[$authorId]['lastname'] |
||
| 1718 | ); |
||
| 1719 | |||
| 1720 | $urlReceiver = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$receiverId; |
||
| 1721 | $nameCompleteReceiver = api_get_person_name( |
||
| 1722 | $users[$receiverId]['firstname'], |
||
| 1723 | $users[$receiverId]['lastname'] |
||
| 1724 | ); |
||
| 1725 | |||
| 1726 | $htmlReceiver = ''; |
||
| 1727 | if ($authorId != $receiverId) { |
||
| 1728 | $htmlReceiver = ' > <a href="'.$urlReceiver.'">'.$nameCompleteReceiver.'</a> '; |
||
| 1729 | } |
||
| 1730 | |||
| 1731 | $wallImage = ''; |
||
| 1732 | if (!empty($message['path'])) { |
||
| 1733 | $imageBig = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_BIG); |
||
| 1734 | $imageSmall = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_SMALL); |
||
| 1735 | |||
| 1736 | $wallImage = '<a class="thumbnail ajax" href="'.$imageBig.'"><img src="'.$imageSmall.'"></a>'; |
||
| 1737 | } |
||
| 1738 | |||
| 1739 | $htmlDelete = ''; |
||
| 1740 | if ($isOwnWall) { |
||
| 1741 | $htmlDelete .= '<a title="'.get_lang("SocialMessageDelete").'" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='. |
||
| 1742 | $message['id'].'">x</a>'; |
||
| 1743 | } |
||
| 1744 | |||
| 1745 | $html = ''; |
||
| 1746 | $html .= '<div class="top-mediapost" >'; |
||
| 1747 | if ($isOwnWall) { |
||
| 1748 | $html .= '<div class="pull-right deleted-mgs">'; |
||
| 1749 | $html .= $htmlDelete; |
||
| 1750 | $html .= '</div>'; |
||
| 1751 | } |
||
| 1752 | $html .= '<div class="user-image" >'; |
||
| 1753 | $html .= '<a href="'.$urlAuthor.'">'.'<img class="avatar-thumb" src="'.$avatarAuthor.'" alt="'.$nameCompleteAuthor.'"></a>'; |
||
| 1754 | $html .= '</div>'; |
||
| 1755 | $html .= '<div class="user-data">'; |
||
| 1756 | $html .= '<div class="username"><a href="'.$urlAuthor.'">'.$nameCompleteAuthor.'</a>'.$htmlReceiver.'</div>'; |
||
| 1757 | $html .= '<div class="time timeago" title="'.$date.'">'.$date.'</div>'; |
||
| 1758 | $html .= '</div>'; |
||
| 1759 | $html .= '<div class="msg-content">'; |
||
| 1760 | $html .= '<div class="img-post">'; |
||
| 1761 | $html .= $wallImage; |
||
| 1762 | $html .= '</div>'; |
||
| 1763 | $html .= '<p>'.Security::remove_XSS($message['content']).'</p>'; |
||
| 1764 | $html .= '</div>'; |
||
| 1765 | $html .= '</div>'; // end mediaPost |
||
| 1766 | |||
| 1767 | // Popularity post functionality |
||
| 1768 | $html .= '<div class="popularity-mediapost"></div>'; |
||
| 1769 | |||
| 1770 | return $html; |
||
| 1771 | } |
||
| 1772 | |||
| 1773 | /** |
||
| 1774 | * get html data with OpenGrap passing the Url |
||
| 1775 | * @param $link url |
||
| 1776 | * @return string data html |
||
| 1777 | */ |
||
| 1778 | public static function readContentWithOpenGraph($link) |
||
| 1803 | } |
||
| 1804 | |||
| 1805 | /** |
||
| 1806 | * verify if Url Exist - Using Curl |
||
| 1807 | * @param $uri url |
||
| 1808 | * |
||
| 1809 | * @return boolean |
||
| 1810 | */ |
||
| 1811 | public static function verifyUrl($uri) |
||
| 1812 | { |
||
| 1813 | $curl = curl_init($uri); |
||
| 1814 | curl_setopt($curl, CURLOPT_FAILONERROR, true); |
||
| 1815 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
||
| 1816 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
| 1817 | curl_setopt($curl, CURLOPT_TIMEOUT, 15); |
||
| 1818 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); |
||
| 1819 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
||
| 1820 | curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); |
||
| 1821 | $response = curl_exec($curl); |
||
| 1822 | curl_close($curl); |
||
| 1823 | if (!empty($response)) { |
||
| 1824 | return true; |
||
| 1825 | } else { |
||
| 1826 | return false; |
||
| 1827 | } |
||
| 1828 | } |
||
| 1829 | |||
| 1830 | /** |
||
| 1831 | * Delete messages delete logic |
||
| 1832 | * @param int $id id message to delete. |
||
| 1833 | * @return bool status query |
||
| 1834 | */ |
||
| 1835 | public static function deleteMessage($id) |
||
| 1836 | { |
||
| 1837 | $id = intval($id); |
||
| 1838 | $tblMessage = Database::get_main_table(TABLE_MESSAGE); |
||
| 1839 | $statusMessage = MESSAGE_STATUS_WALL_DELETE; |
||
| 1840 | $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' "; |
||
| 1841 | |||
| 1842 | return Database::query($sql); |
||
| 1843 | } |
||
| 1844 | |||
| 1845 | /** |
||
| 1846 | * Generate the social block for a user |
||
| 1847 | * @param Template $template |
||
| 1848 | * @param int $userId The user id |
||
| 1849 | * @param string $groupBlock Optional. Highlight link possible values: |
||
| 1850 | * group_add, home, messages, messages_inbox, messages_compose, |
||
| 1851 | * messages_outbox, invitations, shared_profile, friends, groups, search |
||
| 1852 | * @param int $groupId Optional. Group ID |
||
| 1853 | * @param bool $show_full_profile |
||
| 1854 | * @return string The HTML code with the social block |
||
| 1855 | */ |
||
| 1856 | public static function setSocialUserBlock( |
||
| 1921 | } |
||
| 1922 | |||
| 1923 | /** |
||
| 1924 | * @param int $user_id |
||
| 1925 | * @param $link_shared |
||
| 1926 | * @param $show_full_profile |
||
| 1927 | * @return string |
||
| 1928 | */ |
||
| 1929 | public static function listMyFriends($user_id, $link_shared, $show_full_profile) |
||
| 1930 | { |
||
| 1931 | //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT |
||
| 1932 | $friends = self::get_friends($user_id, USER_RELATION_TYPE_FRIEND); |
||
| 1933 | $number_of_images = 30; |
||
| 1934 | $number_friends = count($friends); |
||
| 1935 | $friendHtml = ''; |
||
| 1936 | if ($number_friends != 0) { |
||
| 1937 | if ($number_friends > $number_of_images) { |
||
| 1938 | if (api_get_user_id() == $user_id) { |
||
| 1939 | $friendHtml .= ' <span><a href="friends.php">'.get_lang('SeeAll').'</a></span>'; |
||
| 1940 | } else { |
||
| 1941 | $friendHtml .= ' <span>' |
||
| 1942 | .'<a href="'.api_get_path(WEB_CODE_PATH).'social/profile_friends_and_groups.inc.php' |
||
| 1943 | .'?view=friends&height=390&width=610&user_id='.$user_id.'"' |
||
| 1944 | .'class="ajax" data-title="'.get_lang('SeeAll').'" title="'.get_lang('SeeAll').'" >'.get_lang('SeeAll').'</a></span>'; |
||
| 1945 | } |
||
| 1946 | } |
||
| 1947 | |||
| 1948 | $friendHtml .= '<ul class="nav nav-list">'; |
||
| 1949 | $j = 1; |
||
| 1950 | for ($k = 0; $k < $number_friends; $k++) { |
||
| 1951 | if ($j > $number_of_images) { |
||
| 1952 | break; |
||
| 1953 | } |
||
| 1954 | if (isset($friends[$k])) { |
||
| 1955 | $friend = $friends[$k]; |
||
| 1956 | $name_user = api_get_person_name($friend['firstName'], $friend['lastName']); |
||
| 1957 | $user_info_friend = api_get_user_info($friend['friend_user_id'], true); |
||
| 1958 | |||
| 1959 | if ($user_info_friend['user_is_online']) { |
||
| 1960 | $statusIcon = Display::span('', ['class' => 'online_user_in_text']); |
||
| 1961 | } else { |
||
| 1962 | $statusIcon = Display::span('', ['class' => 'offline_user_in_text']); |
||
| 1963 | } |
||
| 1964 | |||
| 1965 | $friendHtml .= '<li>'; |
||
| 1966 | $friendHtml .= '<div>'; |
||
| 1967 | |||
| 1968 | // the height = 92 must be the same in the image_friend_network span style in default.css |
||
| 1969 | $friends_profile = UserManager::getUserPicture( |
||
| 1970 | $friend['friend_user_id'], |
||
| 1971 | USER_IMAGE_SIZE_SMALL |
||
| 1972 | ); |
||
| 1973 | $friendHtml .= '<img src="'.$friends_profile.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'"/>'; |
||
| 1974 | $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared; |
||
| 1975 | $friendHtml .= $statusIcon.'<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'">'.$name_user.'</a>'; |
||
| 1976 | $friendHtml .= '</div>'; |
||
| 1977 | $friendHtml .= '</li>'; |
||
| 1978 | } |
||
| 1979 | $j++; |
||
| 1980 | } |
||
| 1981 | $friendHtml .= '</ul>'; |
||
| 1982 | } else { |
||
| 1983 | $friendHtml .= '<div class="">'.get_lang('NoFriendsInYourContactList').'<br />' |
||
| 1984 | .'<a class="btn btn-primary" href="'.api_get_path(WEB_PATH).'whoisonline.php"><em class="fa fa-search"></em> '.get_lang('TryAndFindSomeFriends').'</a></div>'; |
||
| 1985 | } |
||
| 1986 | |||
| 1987 | $friendHtml = Display::panel($friendHtml, get_lang('SocialFriend').' ('.$number_friends.')'); |
||
| 1988 | |||
| 1989 | return $friendHtml; |
||
| 1990 | } |
||
| 1991 | |||
| 1992 | /** |
||
| 1993 | * @param int $user_id |
||
| 1994 | * @param $link_shared |
||
| 1995 | * @param $show_full_profile |
||
| 1996 | * @return string |
||
| 1997 | */ |
||
| 1998 | public static function listMyFriendsBlock($user_id, $link_shared = '', $show_full_profile = '') |
||
| 1999 | { |
||
| 2000 | //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT |
||
| 2001 | $friends = self::get_friends($user_id, USER_RELATION_TYPE_FRIEND); |
||
| 2002 | $number_of_images = 30; |
||
| 2003 | $number_friends = count($friends); |
||
| 2004 | $friendHtml = ''; |
||
| 2005 | |||
| 2006 | if ($number_friends != 0) { |
||
| 2007 | $friendHtml .= '<div class="list-group">'; |
||
| 2008 | $j = 1; |
||
| 2009 | for ($k = 0; $k < $number_friends; $k++) { |
||
| 2010 | if ($j > $number_of_images) { |
||
| 2011 | break; |
||
| 2012 | } |
||
| 2013 | if (isset($friends[$k])) { |
||
| 2014 | $friend = $friends[$k]; |
||
| 2015 | $name_user = api_get_person_name($friend['firstName'], $friend['lastName']); |
||
| 2016 | $user_info_friend = api_get_user_info($friend['friend_user_id'], true); |
||
| 2017 | |||
| 2018 | if (!empty($user_info_friend['user_is_online'])) { |
||
| 2019 | $statusIcon = Display::return_icon('statusonline.png', get_lang('Online')); |
||
| 2020 | $status = 1; |
||
| 2021 | } else { |
||
| 2022 | $statusIcon = Display::return_icon('statusoffline.png', get_lang('Offline')); |
||
| 2023 | $status = 0; |
||
| 2024 | } |
||
| 2025 | |||
| 2026 | $friendAvatarMedium = UserManager::getUserPicture( |
||
| 2027 | $friend['friend_user_id'], |
||
| 2028 | USER_IMAGE_SIZE_MEDIUM |
||
| 2029 | ); |
||
| 2030 | $friendAvatarSmall = UserManager::getUserPicture( |
||
| 2031 | $friend['friend_user_id'], |
||
| 2032 | USER_IMAGE_SIZE_SMALL |
||
| 2033 | ); |
||
| 2034 | $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>'; |
||
| 2035 | |||
| 2036 | $relation = SocialManager::get_relation_between_contacts( |
||
| 2037 | $friend['friend_user_id'], |
||
| 2038 | api_get_user_id() |
||
| 2039 | ); |
||
| 2040 | $showLinkToChat = api_is_global_chat_enabled() && $friend['friend_user_id'] != api_get_user_id() && $relation == USER_RELATION_TYPE_FRIEND; |
||
| 2041 | |||
| 2042 | if ($showLinkToChat) { |
||
| 2043 | $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">'; |
||
| 2044 | $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
||
| 2045 | $friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
||
| 2046 | } else { |
||
| 2047 | $link_shared = empty($link_shared) ? '' : '&'.$link_shared; |
||
| 2048 | $friendHtml .= '<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'" class="list-group-item">'; |
||
| 2049 | $friendHtml .= $friend_avatar.' <span class="username-all">'.$name_user.'</span>'; |
||
| 2050 | } |
||
| 2051 | |||
| 2052 | $friendHtml .= '</a>'; |
||
| 2053 | } |
||
| 2054 | $j++; |
||
| 2055 | } |
||
| 2056 | $friendHtml .= '</div>'; |
||
| 2057 | } else { |
||
| 2058 | $friendHtml .= '<div class="help">'.get_lang('NoFriendsInYourContactList').' ' |
||
| 2059 | .'<a href="'.api_get_path(WEB_PATH).'whoisonline.php"><em class="fa fa-search"></em> '.get_lang('TryAndFindSomeFriends').'</a></div>'; |
||
| 2060 | } |
||
| 2061 | |||
| 2062 | return $friendHtml; |
||
| 2063 | } |
||
| 2064 | |||
| 2065 | /** |
||
| 2066 | * @return string |
||
| 2067 | */ |
||
| 2068 | public static function getWallForm($show_full_profile = true) |
||
| 2102 | } |
||
| 2103 | } |
||
| 2104 | |||
| 2105 | /** |
||
| 2106 | * @param int $userId |
||
| 2107 | * @param int $friendId |
||
| 2108 | * @return string |
||
| 2109 | */ |
||
| 2110 | public static function getWallMessagesByUser($userId, $friendId) |
||
| 2122 | } |
||
| 2123 | |||
| 2124 | /** |
||
| 2125 | * Get HTML code block for user skills |
||
| 2126 | * @param int $userId The user ID |
||
| 2127 | * @return string |
||
| 2128 | */ |
||
| 2129 | public static function getSkillBlock($userId) |
||
| 2150 | } |
||
| 2151 | } |
||
| 2152 |