6 ORDER BY id ASC'; $result = Database::query($sql); while ($row = Database::fetch_array($result, 'ASSOC')) { $friend_relation_list[] = $row; } $count_list = count($friend_relation_list); if ($count_list == 0) { $friend_relation_list[] = get_lang('Unknown'); } else { return $friend_relation_list; } } /** * Get relation type contact by name * @param string names of the kind of relation * @return int * @author isaac flores paz */ public static function get_relation_type_by_name($relation_type_name) { $list_type_friend = self::show_list_type_friends(); foreach ($list_type_friend as $value_type_friend) { if (strtolower($value_type_friend['title']) == $relation_type_name) { return $value_type_friend['id']; } } } /** * Get the kind of relation between contacts * @param int user id * @param int user friend id * @param string * @author isaac flores paz */ public static function get_relation_between_contacts($user_id, $user_friend) { $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER); $sql = 'SELECT rt.id as id FROM '.$tbl_my_friend_relation_type.' rt WHERE rt.id = ( SELECT uf.relation_type FROM '.$tbl_my_friend.' uf WHERE user_id='.((int) $user_id).' AND friend_user_id='.((int) $user_friend).' AND uf.relation_type <> '.USER_RELATION_TYPE_RRHH.' LIMIT 1 )'; $res = Database::query($sql); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res, 'ASSOC'); return $row['id']; } else { return USER_UNKNOW; } } /** * Gets friends id list * @param int user id * @param int group id * @param string name to search * @param bool true will load firstname, lastname, and image name * @return array * @author Julio Montoya Cleaning code, function renamed, $load_extra_info option added * @author isaac flores paz */ public static function get_friends($user_id, $id_group = null, $search_name = null, $load_extra_info = true) { $list_ids_friends = array(); $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER); $tbl_my_user = Database :: get_main_table(TABLE_MAIN_USER); $sql = 'SELECT friend_user_id FROM '.$tbl_my_friend.' WHERE relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND friend_user_id<>'.((int) $user_id).' AND user_id='.((int) $user_id); if (isset($id_group) && $id_group > 0) { $sql.=' AND relation_type='.$id_group; } if (isset($search_name)) { $search_name = trim($search_name); $search_name = str_replace(' ', '', $search_name); $sql.=' AND friend_user_id IN ( SELECT user_id FROM '.$tbl_my_user.' WHERE firstName LIKE "%'.Database::escape_string($search_name).'%" OR lastName LIKE "%'.Database::escape_string($search_name).'%" OR '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' LIKE concat("%","'.Database::escape_string($search_name).'","%") ) '; } $res = Database::query($sql); while ($row = Database::fetch_array($res, 'ASSOC')) { if ($load_extra_info) { $my_user_info = api_get_user_info($row['friend_user_id']); $list_ids_friends[] = array( 'friend_user_id' => $row['friend_user_id'], 'firstName' => $my_user_info['firstName'], 'lastName' => $my_user_info['lastName'], 'username' => $my_user_info['username'], 'image' => $my_user_info['avatar'] ); } else { $list_ids_friends[] = $row; } } return $list_ids_friends; } /** * get web path of user invitate * @author isaac flores paz * @author Julio Montoya setting variable array * @param int user id * * @return array */ public static function get_list_web_path_user_invitation_by_user_id($user_id) { $list_ids = self::get_list_invitation_of_friends_by_user_id($user_id); $list = array(); foreach ($list_ids as $values_ids) { $list[] = UserManager::get_user_picture_path_by_id( $values_ids['user_sender_id'], 'web' ); } return $list; } /** * Sends an invitation to contacts * @param int user id * @param int user friend id * @param string title of the message * @param string content of the message * @return boolean * @author isaac flores paz * @author Julio Montoya Cleaning code */ public static function send_invitation_friend($user_id, $friend_id, $message_title, $message_content) { $tbl_message = Database::get_main_table(TABLE_MESSAGE); $user_id = intval($user_id); $friend_id = intval($friend_id); //Just in case we replace the and \n and \n\r while saving in the DB $message_content = str_replace(array("\n", "\n\r"), '
', $message_content); $clean_message_content = Database::escape_string($message_content); $now = api_get_utc_datetime(); $sql = 'SELECT COUNT(*) AS count FROM '.$tbl_message.' WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status IN(5,6,7); '; $res_exist = Database::query($sql); $row_exist = Database::fetch_array($res_exist, 'ASSOC'); if ($row_exist['count'] == 0) { $params = [ 'user_sender_id' => $user_id, 'user_receiver_id' => $friend_id, 'msg_status' => MESSAGE_STATUS_INVITATION_PENDING, 'send_date' => $now, 'title' => $message_title, 'content' => $message_content, ]; Database::insert($tbl_message, $params); $sender_info = api_get_user_info($user_id); $notification = new Notification(); $notification->save_notification( Notification::NOTIFICATION_TYPE_INVITATION, array($friend_id), $message_title, $message_content, $sender_info ); return true; } else { // invitation already exist $sql = 'SELECT COUNT(*) AS count, id FROM '.$tbl_message.' WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7'; $res_if_exist = Database::query($sql); $row_if_exist = Database::fetch_array($res_if_exist, 'ASSOC'); if ($row_if_exist['count'] == 1) { $sql = 'UPDATE '.$tbl_message.' SET msg_status=5, content = "'.$clean_message_content.'" WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7 '; Database::query($sql); return true; } else { return false; } } } /** * Get number messages of the inbox * @author isaac flores paz * @param int user receiver id * @return int */ public static function get_message_number_invitation_by_user_id($user_receiver_id) { $tbl_message = Database::get_main_table(TABLE_MESSAGE); $sql = 'SELECT COUNT(*) as count_message_in_box FROM '.$tbl_message.' WHERE user_receiver_id='.intval($user_receiver_id).' AND msg_status='.MESSAGE_STATUS_INVITATION_PENDING; $res = Database::query($sql); $row = Database::fetch_array($res, 'ASSOC'); return $row['count_message_in_box']; } /** * Get invitation list received by user * @author isaac flores paz * @param int user id * @return array */ public static function get_list_invitation_of_friends_by_user_id($user_id) { $tbl_message = Database::get_main_table(TABLE_MESSAGE); $sql = 'SELECT user_sender_id, send_date, title, content FROM '.$tbl_message.' WHERE user_receiver_id = '.intval($user_id).' AND msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; $res = Database::query($sql); $list_friend_invitation = array(); while ($row = Database::fetch_array($res, 'ASSOC')) { $list_friend_invitation[] = $row; } return $list_friend_invitation; } /** * Get invitation list sent by user * @author Julio Montoya * @param int user id * @return array() */ public static function get_list_invitation_sent_by_user_id($user_id) { $list_friend_invitation = array(); $tbl_message = Database::get_main_table(TABLE_MESSAGE); $sql = 'SELECT user_receiver_id, send_date,title,content FROM '.$tbl_message.' WHERE user_sender_id = '.intval($user_id).' AND msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; $res = Database::query($sql); while ($row = Database::fetch_array($res, 'ASSOC')) { $list_friend_invitation[$row['user_receiver_id']] = $row; } return $list_friend_invitation; } /** * Accepts invitation * @param int $user_send_id * @param int $user_receiver_id * @author isaac flores paz * @author Julio Montoya Cleaning code */ public static function invitation_accepted($user_send_id, $user_receiver_id) { $tbl_message = Database::get_main_table(TABLE_MESSAGE); $sql = "UPDATE $tbl_message SET msg_status = ".MESSAGE_STATUS_INVITATION_ACCEPTED." WHERE user_sender_id = ".((int) $user_send_id)." AND user_receiver_id=".((int) $user_receiver_id)." AND msg_status = ".MESSAGE_STATUS_INVITATION_PENDING; Database::query($sql); } /** * Denies invitation * @param int user sender id * @param int user receiver id * @author isaac flores paz * @author Julio Montoya Cleaning code */ public static function invitation_denied($user_send_id, $user_receiver_id) { $tbl_message = Database::get_main_table(TABLE_MESSAGE); $sql = 'DELETE FROM '.$tbl_message.' WHERE user_sender_id = '.((int) $user_send_id).' AND user_receiver_id='.((int) $user_receiver_id).' AND msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; Database::query($sql); } /** * allow attach to group * @author isaac flores paz * @param int user to qualify * @param int kind of rating * @return void() */ public static function qualify_friend($id_friend_qualify, $type_qualify) { $tbl_user_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER); $user_id = api_get_user_id(); $sql = 'UPDATE '.$tbl_user_friend.' SET relation_type='.((int) $type_qualify).' WHERE user_id = '.((int) $user_id).' AND friend_user_id='.(int) $id_friend_qualify; Database::query($sql); } /** * Sends invitations to friends * @author Isaac Flores Paz * @author Julio Montoya Cleaning code * @param void * @return string message invitation */ public static function send_invitation_friend_user($userfriend_id, $subject_message = '', $content_message = '') { global $charset; $user_info = api_get_user_info($userfriend_id); $succes = get_lang('MessageSentTo'); $succes.= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']); if (isset($subject_message) && isset($content_message) && isset($userfriend_id)) { $send_message = MessageManager::send_message($userfriend_id, $subject_message, $content_message); if ($send_message) { Display::addFlash( Display::display_confirmation_message($succes, true, true) ); } else { Display::addFlash( Display::display_error_message(get_lang('ErrorSendingMessage'), true, true) ); } return false; } elseif (isset($userfriend_id) && !isset($subject_message)) { $count_is_true = false; if (isset($userfriend_id) && $userfriend_id > 0) { $message_title = get_lang('Invitation'); $count_is_true = self::send_invitation_friend(api_get_user_id(), $userfriend_id, $message_title, $content_message); if ($count_is_true) { Display::addFlash( Display::display_confirmation_message( api_htmlentities(get_lang('InvitationHasBeenSent'), ENT_QUOTES, $charset), false, true ) ); } else { Display::addFlash( Display::display_warning_message( api_htmlentities(get_lang('YouAlreadySentAnInvitation'), ENT_QUOTES, $charset), false, true ) ); } } } } /** * Get user's feeds * @param int User ID * @param int Limit of posts per feed * @return string HTML section with all feeds included * @author Yannick Warnier * @since Dokeos 1.8.6.1 */ public static function get_user_feeds($user, $limit = 5) { if (!function_exists('fetch_rss')) { return ''; } $feed = UserManager::get_extra_user_data_by_field($user, 'rssfeeds'); if (empty($feed)) { return ''; } $feeds = explode(';', $feed['rssfeeds']); if (count($feeds) == 0) { return ''; } $res = ''; foreach ($feeds as $url) { if (empty($url)) { continue; } $rss = @fetch_rss($url); $i = 1; if (!empty($rss->items)) { $icon_rss = ''; if (!empty($feed)) { $icon_rss = Display::url( Display::return_icon('social_rss.png', '', array(), 22), Security::remove_XSS($feed['rssfeeds']), array('target' => '_blank') ); } $res .= '

'.$icon_rss.' '.$rss->channel['title'].'

'; $res .= '
'; foreach ($rss->items as $item) { if ($limit >= 0 and $i > $limit) { break; } $res .= '

'.$item['title'].'

'; $res .= '
'.api_get_local_time($item['date_timestamp']).'
'; $res .= '

'.$item['description'].'

'; $i++; } $res .= '
'; } } return $res; } /** * Helper functions definition */ public static function get_logged_user_course_html($my_course, $count) { $result = ''; // Table definitions $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); $course_code = $my_course['code']; $course_directory = $my_course['course_info']['directory']; $course_title = $my_course['course_info']['title']; $course_access_settings = CourseManager :: get_access_settings($course_code); $course_visibility = $course_access_settings['visibility']; $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_code); //$valor = api_get_settings_params(); $course_path = api_get_path(SYS_COURSE_PATH).$course_directory; // course path if (api_get_setting('course_images_in_courses_list') === 'true') { if (file_exists($course_path.'/course-pic85x85.png')) { $image = $my_course['course_info']['course_image']; $imageCourse = Display::img($image, $course_title, array('class'=>'img-course')); } else { $imageCourse = Display::return_icon('session_default_small.png', $course_title, array('class' => 'img-course')); } } else { $imageCourse = Display::return_icon('course.png', get_lang('Course'), array('class' => 'img-default')); } //$imageCourse = Display::return_icon('course.png', get_lang('Course')); //display course entry if (api_get_setting('course_images_in_courses_list') === 'true') { $result .= '
  • '; } else { $result .= '
  • '; } $result .= $imageCourse; //show a hyperlink to the course, unless the course is closed and user is not course admin if ($course_visibility != COURSE_VISIBILITY_HIDDEN && ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) ) { $result .= '' . $course_title . ''; } else { $result .= $course_title." "." ".get_lang('CourseClosed').""; } $result .= '
  • '; $session = ''; $active = false; if (!empty($my_course['session_name']) && !empty($my_course['id_session'])) { // Request for the name of the general coach $sql = 'SELECT lastname, firstname FROM '.$tbl_session.' ts LEFT JOIN '.$main_user_table.' tu ON ts.id_coach = tu.user_id WHERE ts.id='.(int) $my_course['id_session'].' LIMIT 1'; $rs = Database::query($sql); $sessioncoach = Database::store_result($rs); $sessioncoach = $sessioncoach[0]; $session = array(); $session['title'] = $my_course['session_name']; if ($my_course['access_start_date'] == '0000-00-00') { $session['dates'] = get_lang('WithoutTimeLimits'); if (api_get_setting('show_session_coach') === 'true') { $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); } $active = true; } else { $session ['dates'] = ' - '.get_lang('From').' '.$my_course['access_start_date'].' '.get_lang('To').' '.$my_course['access_end_date']; if (api_get_setting('show_session_coach') === 'true') { $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); } } } $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0; $output = array($my_course['user_course_cat'], $result, $my_course['id_session'], $session); return $output; } /** * Shows the avatar block in social pages * * @param string highlight link possible values: * group_add, * home, * messages, * messages_inbox, * messages_compose, * messages_outbox, * invitations, * shared_profile, * friends, * groups search * @param int group id * @param int user id * */ public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0) { if (empty($user_id)) { $user_id = api_get_user_id(); } $show_groups = array( 'groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups' ); $template = new Template(null, false, false, false, false, false); if (in_array($show, $show_groups) && !empty($group_id)) { // Group image $userGroup = new UserGroup(); $group_info = $userGroup->get($group_id); $userGroupImage = $userGroup->get_picture_group( $group_id, $group_info['picture'], 160, GROUP_IMAGE_SIZE_BIG ); $template->assign('show_group', true); $template->assign('group_id', $group_id); $template->assign('user_group_image', $userGroupImage); $template->assign('user_group', $group_info); $template->assign( 'user_is_group_admin', $userGroup->is_group_admin( $group_id, api_get_user_id() ) ); } else { $template->assign('show_user', true); $template->assign( 'user_image', [ 'big' => UserManager::getUserPicture( $user_id, USER_IMAGE_SIZE_BIG ), 'normal' => UserManager::getUserPicture( $user_id, USER_IMAGE_SIZE_MEDIUM ) ] ); } $skillBlock = $template->get_template('social/avatar_block.tpl'); return $template->fetch($skillBlock); } /** * Shows the right menu of the Social Network tool * * @param string $show highlight link possible values: * group_add, * home, * messages, * messages_inbox, * messages_compose , * messages_outbox, * invitations, * shared_profile, * friends, * groups search * @param int $group_id group id * @param int $user_id user id * @param bool $show_full_profile show profile or not (show or hide the user image/information) * @param bool $show_delete_account_button * */ public static function show_social_menu( $show = '', $group_id = 0, $user_id = 0, $show_full_profile = false, $show_delete_account_button = false ) { if (empty($user_id)) { $user_id = api_get_user_id(); } $usergroup = new UserGroup(); $user_info = api_get_user_info($user_id, true); $current_user_id = api_get_user_id(); $current_user_info = api_get_user_info($current_user_id, true); if ($current_user_id == $user_id) { $user_friend_relation = null; } else { $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id); } $show_groups = array( 'groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups' ); // get count unread message and total invitations $count_unread_message = MessageManager::get_number_of_messages(true); $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null; $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id()); $group_pending_invitations = $usergroup->get_groups_by_user( api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false ); $group_pending_invitations = count($group_pending_invitations); $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : ''); $html = ''; $active = null; if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'))) { $html .= ''; } if (in_array($show, $show_groups) && !empty($group_id)) { $html .= $usergroup->show_group_column_information( $group_id, api_get_user_id(), $show ); } if ($show == 'shared_profile') { $html .= ''; if ($show_full_profile && $user_id == intval(api_get_user_id())) { $personal_course_list = UserManager::get_personal_session_course_list($user_id); $course_list_code = array(); $i = 1; if (is_array($personal_course_list)) { foreach ($personal_course_list as $my_course) { if ($i <= 10) { $course_list_code[] = array('code' => $my_course['code']); } else { break; } $i++; } // To avoid repeated courses $course_list_code = array_unique_dimensional($course_list_code); } // Announcements $my_announcement_by_user_id = intval($user_id); $announcements = array(); foreach ($course_list_code as $course) { $course_info = api_get_course_info($course['code']); if (!empty($course_info)) { $content = AnnouncementManager::get_all_annoucement_by_user_course( $course_info['code'], $my_announcement_by_user_id ); if (!empty($content)) { $url = Display::url(Display::return_icon('announcement.png', get_lang('Announcements')).$course_info['name'].' ('.$content['count'].')', api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$course['code']); $announcements[] = Display::tag('li', $url); } } } if (!empty($announcements)) { $html .= ''; } } } if ($show_delete_account_button) { $html .= ''; } $html .= ''; return $html; } /** * Displays a sortable table with the list of online users. * @param array $user_list The list of users to be shown * @param bool $wrap Whether we want the function to wrap the spans list in a div or not * @return string HTML block or null if and ID was defined * @assert (null) === false */ public static function display_user_list($user_list, $wrap = true) { $html = null; if (isset($_GET['id']) or count($user_list) < 1) { return false; } $column_size = '12'; $add_row = false; //var_dump(api_set_anonymous()); if (api_is_anonymous()) { $add_row = true; } $extra_params = array(); $course_url = ''; if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) { $extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']); $course_url = '&cidReq='.Security::remove_XSS($_GET['cidReq']); } $html .= '
    '; foreach ($user_list as $uid) { $user_info = api_get_user_info($uid, $checkIfUserOnline = true); $lastname = $user_info['lastname']; $firstname = $user_info['firstname']; $completeName = $firstname.', '.$lastname; $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); $status_icon_chat = null; if ($user_info['user_is_online_in_chat'] == 1) { $status_icon_chat = Display::return_icon('online.png', get_lang('Online')); } else { $status_icon_chat = Display::return_icon('offline.png', get_lang('Offline')); } $userPicture = $user_info['avatar']; $img = ''.$completeName.''; $url = null; // Anonymous users can't have access to the profile if (!api_is_anonymous()) { if (api_get_setting('allow_social_tool') == 'true') { $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url; } else { $url = '?id='.$uid.$course_url; } } else { $url = null; } $name = ''.$firstname.'
    '.$lastname.'
    '; $html .= '
    '.$img.'
    '.$name.'
    '.$status_icon_chat.' '.$user_rol.'
    '; } $counter = $_SESSION['who_is_online_counter']; if ($wrap) { $html .= '
    '; } if (count($user_list) >= 9) { $html .= ''; } if ($wrap && $add_row) { $html .= ''; } return $html; } /** * Displays the information of an individual user * @param int $user_id */ public static function display_individual_user($user_id) { global $interbreadcrumb; $safe_user_id = intval($user_id); $currentUserId = api_get_user_id(); $user_table = Database::get_main_table(TABLE_MAIN_USER); $sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id; $result = Database::query($sql); $html = null; if (Database::num_rows($result) == 1) { $user_object = Database::fetch_object($result); $userInfo = api_get_user_info($user_id); $alt = $userInfo['complete_name'].($currentUserId == $user_id ? ' ('.get_lang('Me').')' : ''); $status = get_status_from_code($user_object->status); $interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList')); $html .= '
    '; $fullurl = $userInfo['avatar']; $html .= ''.$alt.''; if (!empty($status)) { $html .= '
    '.$status.'
    '; } $html .= '
    '; if (api_get_setting('show_email_addresses') == 'true') { $html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'
    '; } if ($user_object->competences) { $html .= Display::page_subheader(get_lang('MyCompetences')); $html .= '

    '.$user_object->competences.'

    '; } if ($user_object->diplomas) { $html .= Display::page_subheader(get_lang('MyDiplomas')); $html .= '

    '.$user_object->diplomas.'

    '; } if ($user_object->teach) { $html .= Display::page_subheader(get_lang('MyTeach')); $html .= '

    '.$user_object->teach.'

    '; } SocialManager::display_productions($user_object->user_id); if ($user_object->openarea) { $html .= Display::page_subheader(get_lang('MyPersonalOpenArea')); $html .= '

    '.$user_object->openarea.'

    '; } } else { $html .= '
    '; $html .= get_lang('UsersOnLineList'); $html .= '
    '; } return $html; } /** * Display productions in who is online * @param int $user_id User id */ public static function display_productions($user_id) { $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web'); $sysdir = UserManager::getUserPathById($user_id, 'system'); $webdir = UserManager::getUserPathById($user_id, 'web'); if (!is_dir($sysdir)) { mkdir($sysdir, api_get_permissions_for_new_directories(), true); } $productions = UserManager::get_user_productions($user_id); if (count($productions) > 0) { echo '
    '.get_lang('Productions').'
    '; echo '
      '; foreach ($productions as $file) { // Only display direct file links to avoid browsing an empty directory if (is_file($sysdir.$file) && $file != $webdir_array['file']) { echo '
    • '.$file.'
    • '; } // Real productions are under a subdirectory by the User's id if (is_dir($sysdir.$file)) { $subs = scandir($sysdir.$file); foreach ($subs as $my => $sub) { if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) { echo '
    • '.$sub.'
    • '; } } } } echo '
    '; } } /** * @param string $content * @param string $span_count * @return string */ public static function social_wrapper_div($content, $span_count) { $span_count = intval($span_count); $html = '
    '; $html .= '
    '; $html .= $content; $html .= '
    '; return $html; } /** * Dummy function * */ public static function get_plugins($place = SOCIAL_CENTER_PLUGIN) { $content = ''; switch ($place) { case SOCIAL_CENTER_PLUGIN: $social_plugins = array(1, 2); if (is_array($social_plugins) && count($social_plugins) > 0) { $content.= '
    '; foreach ($social_plugins as $plugin) { $content.= ''; } $content.= '
    '; } break; case SOCIAL_LEFT_PLUGIN: break; case SOCIAL_RIGHT_PLUGIN: break; } return $content; } /** * Sends a message to someone's wall * @param int $userId id of author * @param int $friendId id where we send the message * @param string $messageContent of the message * @param int $messageId id parent * @param string $messageStatus status type of message * @return boolean * @author Yannick Warnier */ public static function sendWallMessage($userId, $friendId, $messageContent, $messageId = 0 ,$messageStatus) { $tblMessage = Database::get_main_table(TABLE_MESSAGE); $userId = intval($userId); $friendId = intval($friendId); $messageId = intval($messageId); //Just in case we replace the and \n and \n\r while saving in the DB $messageContent = str_replace(array("\n", "\n\r"), '
    ', $messageContent); $cleanMessageContent = Database::escape_string($messageContent); $attributes = array( 'user_sender_id' => $userId, 'user_receiver_id' => $friendId, 'msg_status' => $messageStatus, 'send_date' => api_get_utc_datetime(), 'title' => '', 'content' => $cleanMessageContent, 'parent_id' => $messageId ); return Database::insert($tblMessage, $attributes); } /** * Send File attachment (jpg,png) * @author Anibal Copitan * @param int $userId id user * @param array $fileAttach * @param int $messageId id message (relation with main message) * @param string $fileComment description attachment file * @return bool */ public static function sendWallMessageAttachmentFile($userId, $fileAttach, $messageId, $fileComment = '') { $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); // create directory $social = '/social/'; $pathMessageAttach = UserManager::getUserPathById($userId, 'system').'message_attachments'.$social; $safeFileComment = Database::escape_string($fileComment); $safeFileName = Database::escape_string($fileAttach['name']); $extension = strtolower(substr(strrchr($safeFileName, '.'), 1)); $allowedTypes = api_get_supported_image_extensions(); if (!in_array($extension, $allowedTypes)) { $flag = false; } else { $newFileName = uniqid('') . '.' . $extension; if (!file_exists($pathMessageAttach)) { @mkdir($pathMessageAttach, api_get_permissions_for_new_directories(), true); } $newPath = $pathMessageAttach . $newFileName; if (is_uploaded_file($fileAttach['tmp_name'])) { @copy($fileAttach['tmp_name'], $newPath); } $small = self::resize_picture($newPath, IMAGE_WALL_SMALL_SIZE); $medium = self::resize_picture($newPath, IMAGE_WALL_MEDIUM_SIZE); $big = new Image($newPath); $ok = $small && $small->send_image($pathMessageAttach . IMAGE_WALL_SMALL . '_' . $newFileName) && $medium && $medium->send_image($pathMessageAttach . IMAGE_WALL_MEDIUM .'_' . $newFileName) && $big && $big->send_image($pathMessageAttach . IMAGE_WALL_BIG . '_' . $newFileName); // Insert $newFileName = $social.$newFileName; $params = [ 'filename' => $safeFileName, 'comment' => $safeFileComment, 'path' => $newFileName, 'message_id' => $messageId, 'size' => $fileAttach['size'], ]; Database::insert($tbl_message_attach, $params); $flag = true; } return $flag; } /** * Gets all messages from someone's wall (within specific limits) * @param int $userId id of wall shown * @param string $messageStatus status wall message * @param int|string $parentId id message (Post main) * @param date $start Date from which we want to show the messages, in UTC time * @param int $limit Limit for the number of parent messages we want to show * @param int $offset Wall message query offset * @return boolean * @author Yannick Warnier */ public static function getWallMessages($userId, $messageStatus, $parentId = '', $start = null, $limit = 10, $offset = 0) { if (empty($start)) { $start = '0000-00-00'; } $tblMessage = Database::get_main_table(TABLE_MESSAGE); $tblMessageAttachment = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); $userId = intval($userId); $start = Database::escape_string($start); $limit = intval($limit); $sql = "SELECT id, user_sender_id,user_receiver_id, send_date, content, parent_id, (SELECT ma.path FROM $tblMessageAttachment ma WHERE ma.message_id = tm.id ) as path, (SELECT ma.filename FROM $tblMessageAttachment ma WHERE ma.message_id = tm.id ) as filename FROM $tblMessage tm WHERE user_receiver_id = $userId AND send_date > '$start' "; $sql .= (empty($messageStatus) || is_null($messageStatus)) ? '' : " AND msg_status = '$messageStatus' "; $sql .= (empty($parentId) || is_null($parentId)) ? '' : " AND parent_id = '$parentId' "; $sql .= " ORDER BY send_date DESC LIMIT $offset, $limit "; $messages = array(); $res = Database::query($sql); if (Database::num_rows($res) > 0) { while ($row = Database::fetch_array($res)) { $messages[] = $row; } } return $messages; } /** * Gets all messages from someone's wall (within specific limits), formatted * @param int $userId USER ID of the person's wall * @param int $friendId id person * @param int $idMessage id message * @param string $start Start date (from when we want the messages until today) * @param int $limit Limit to the number of messages we want * @param int $offset Wall messages offset * @return string HTML formatted string to show messages */ public static function getWallMessagesHTML($userId, $friendId, $idMessage, $start = null, $limit = 10, $offset = 0) { if (empty($start)) { $start = '0000-00-00'; } $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId); $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL, $idMessage, $start, $limit, $offset); $formattedList = '
    '; $users = array(); // The messages are ordered by date descendant, for comments we need ascendant krsort($messages); foreach ($messages as $message) { $date = api_get_local_time($message['send_date']); $userIdLoop = $message['user_sender_id']; if (!isset($users[$userIdLoop])) { $users[$userIdLoop] = api_get_user_info($userIdLoop); } $nameComplete = api_is_western_name_order() ? $users[$userIdLoop]['firstname'] .' ' . $users[$userIdLoop]['lastname'] : $users[$userIdLoop]['lastname'] . ' ' . $users[$userIdLoop]['firstname']; $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop; $media = ''; $media .= '
    '; if ($isOwnWall) { $media .= '
    '; $media .= 'x'; $media .= '
    '; } $media .= '
    '; $media .= ''.$users[$userIdLoop]['complete_name'].''; $media .= '
    '; $media .= '
    '; $media .= ''; $media .= '
    '.$date.'
    '; $media .= '
    '; $media .= '
    '; $media .= '

    '.Security::remove_XSS($message['content']).'

    '; $media .= '
    '; $formattedList .= $media; } $formattedList .= '
    '; $formattedList .= '
    '; $formattedList .= '
    '; $formattedList .= '
    '; return $formattedList; } /** * Gets all user's starting wall messages (within specific limits) * @param int $userId User's id * @param int $friendId Friend's id * @param date $start Start date (from when we want the messages until today) * @param int $limit Limit to the number of messages we want * @param int $offset Wall messages offset * @return array $data return user's starting wall messages along with message extra data */ public static function getWallMessagesPostHTML($userId, $friendId = 0, $start = null, $limit = 10, $offset= 0) { if (empty($start)) { $start = '0000-00-00'; } $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId); $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL_POST , null, $start, $limit, $offset); $users = array(); $data = array(); foreach ($messages as $key => $message) { $userIdLoop = $message['user_sender_id']; $userFriendIdLoop = $message['user_receiver_id']; if (!isset($users[$userIdLoop])) { $users[$userIdLoop] = api_get_user_info($userIdLoop); } if (!isset($users[$userFriendIdLoop])) { $users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop); } $html = ''; $html .= self::headerMessagePost( $message['user_sender_id'], $message['user_receiver_id'], $users, $message, $isOwnWall ); $data[$key]['id'] = $message['id']; $data[$key]['html'] = $html; } return $data; } /** * Returns the formatted header message post * @param int $authorId Author's id * @param int $receiverId Receiver's id * @param array $users Author's and receiver's data * @param array $message Message data * @param boolean $isOwnWall Determines if the author is in its own social wall or not * @return string $html The formatted header message post */ private static function headerMessagePost($authorId, $receiverId, $users, $message, $isOwnWall = false) { $date = api_get_local_time($message['send_date']); $avatarAuthor = $users[$authorId]['avatar']; $urlAuthor = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$authorId; $nameCompleteAuthor = api_get_person_name( $users[$authorId]['firstname'], $users[$authorId]['lastname'] ); $urlReceiver = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$receiverId; $nameCompleteReceiver = api_get_person_name( $users[$receiverId]['firstname'], $users[$receiverId]['lastname'] ); $htmlReceiver = ''; if ($authorId != $receiverId) { $htmlReceiver = ' > ' . $nameCompleteReceiver . ' '; } $wallImage = ''; if (!empty($message['path'])) { $imageBig = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_BIG); $imageSmall = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_SMALL); $wallImage = ''; } $htmlDelete = ''; if ($isOwnWall) { $htmlDelete .= 'x'; } $html = ''; $html .= '
    '; if ($isOwnWall) { $html .= '
    '; $html .= $htmlDelete; $html .= '
    '; } $html .= '
    '; $html .= ''.''.$nameCompleteAuthor.''; $html .= '
    '; $html .= '
    '; $html .= '
    '.$nameCompleteAuthor.''.$htmlReceiver.'
    '; $html .= '
    '.$date.'
    '; $html .= '
    '; $html .= '
    '; $html .= '
    '; $html .= $wallImage; $html .= '
    '; $html .= '

    '. Security::remove_XSS(self::readContentWithOpenGraph($message['content'])).'

    '; $html .= '
    '; $html .= '
    '; // end mediaPost return $html; } /** * Get schedule html (with data openGrap) * @param string $text Content text * @return string $newText Content text with OpenGraph */ public static function readContentWithOpenGraph($text) { // search link in first line $regExUrl = "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; $newText = ''; $count = 0; if(preg_match($regExUrl, $text, $url)) { // make the urls hyper links $newText .= preg_replace($regExUrl, "".$url[0]." ", $text); if ($count == 0) { // Comment this line to disable OpenGraph //$newText .= self::getHtmlByLink($url[0]); } $count++; } else { $newText .= $text; } return $newText; } /** * html with data OpenGrap * @param $link url * @return string data html */ public static function getHtmlByLink($link) { $graph = OpenGraph::fetch($link); $title = $graph->title; $html = '
    '; $html .= '

    '.$title.'

    '; $html .= empty($graph->image) ? '' : '
    '; $html .= empty($graph->description) ? '' : '
    '.$graph->description.'
    '; $html .= "
    "; return $html; } /** * Get full image path from a path and a size * @param string $path * @return string */ private static function getImagePath($path, $size = '') { $name = ''; $array = preg_split('#\/#', $path); if (isset($array[2]) && !empty($array[2])) { if ($size == IMAGE_WALL_SMALL) { $name = IMAGE_WALL_SMALL. '_' . $array[2]; }else if($size == IMAGE_WALL_MEDIUM){ $name = IMAGE_WALL_MEDIUM. '_' . $array[2]; }else if($size == IMAGE_WALL_BIG){ $name = IMAGE_WALL_BIG. '_' . $array[2]; }else { $name = IMAGE_WALL_SMALL. '_' . $array[2]; } $lessImage = str_replace($array[2], '', $path); $name = $lessImage . $name; } return $name; } /** * Delete messages delete logic * @param int $id id message to delete. * @return bool status query */ public static function deleteMessage($id) { $id = intval($id); $tblMessage = Database::get_main_table(TABLE_MESSAGE); $statusMessage = MESSAGE_STATUS_WALL_DELETE; $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' "; return Database::query($sql); } /** * Generate the social block for a user * @param Template $template * @param int $userId The user id * @param string $groupBlock Optional. Highlight link possible values: * group_add, home, messages, messages_inbox, messages_compose, * messages_outbox, invitations, shared_profile, friends, groups, search * @param int $groupId Optional. Group ID * @return string The HTML code with the social block */ public static function setSocialUserBlock(Template $template, $userId, $groupBlock = '', $groupId = 0) { if (api_get_setting('allow_social_tool') != 'true') { return ''; } $socialAvatarBlock = SocialManager::show_social_avatar_block( $groupBlock, $groupId, $userId ); $profileEditionLink = null; if (api_get_user_id() == $userId) { $profileEditionLink = Display::getProfileEditionLink($userId); } $userInfo = api_get_user_info($userId, true, false, true); $template->assign('user', $userInfo); $template->assign('socialAvatarBlock', $socialAvatarBlock); $template->assign('profileEditionLink', $profileEditionLink); if (api_get_setting('gamification_mode') === '1') { $gamificationPoints = GamificationUtils::getTotalUserPoints( $userId, $userInfo['status'] ); $template->assign('gamification_points', $gamificationPoints); } $chatEnabled = api_is_global_chat_enabled(); $template->assign('chat_enabled', $chatEnabled); $templateName = $template->get_template('social/user_block.tpl'); if (in_array($groupBlock, ['groups', 'group_edit', 'member_list'])) { $templateName = $template->get_template('social/group_block.tpl'); } $template->assign('social_avatar_block', $template->fetch($templateName)); } /** * @param int $user_id * @param $link_shared * @param $show_full_profile * @return string */ public static function listMyFriends($user_id, $link_shared, $show_full_profile) { //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND); $number_of_images = 30; $number_friends = count($friends); $friendHtml = ''; if ($number_friends != 0) { if ($number_friends > $number_of_images) { if (api_get_user_id() == $user_id) { $friendHtml.= ' '.get_lang('SeeAll').''; } else { $friendHtml.= ' ' .''.get_lang('SeeAll').''; } } $friendHtml.= ''; } else { $friendHtml.= '
    '.get_lang('NoFriendsInYourContactList').'
    ' .' '. get_lang('TryAndFindSomeFriends').'
    '; } $friendHtml = Display::panel($friendHtml, get_lang('SocialFriend').' (' . $number_friends . ')' ); return $friendHtml; } /** * @param int $user_id * @param $link_shared * @param $show_full_profile * @return string */ public static function listMyFriendsBlock($user_id, $link_shared, $show_full_profile) { //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND); $number_of_images = 30; $number_friends = count($friends); $friendHtml = ''; if ($number_friends != 0) { $friendHtml.= ''; } else { $friendHtml.= '
    '.get_lang('NoFriendsInYourContactList').'
    ' .' '. get_lang('TryAndFindSomeFriends').'
    '; } return $friendHtml; } /** * @return string */ public static function getWallForm() { $form = new FormValidator( 'social_wall_main', 'post', api_get_path(WEB_CODE_PATH).'social/profile.php', null, array('enctype' => 'multipart/form-data') ); $form->addTextarea('social_wall_new_msg_main', null, array('placeholder' => get_lang('SocialWallWhatAreYouThinkingAbout'))); $form->addButtonSend(get_lang('Post')); $html = Display::panel($form->returnForm(), get_lang('SocialWall')); return $html; } /** * @param int $userId * @param int $friendId * @return string */ public static function getWallMessagesByUser($userId, $friendId) { $messages = SocialManager::getWallMessagesPostHTML($userId, $friendId); $html = ''; foreach ($messages as $message) { $post = $message['html']; $comment = SocialManager::getWallMessagesHTML($userId, $friendId, $message['id']); $html .= $post.$comment; } return $html; } /** * Get HTML code block for user skills * @param int $userId The user ID * @return string */ public static function getSkillBlock($userId) { if (api_get_setting('allow_skills_tool') !== 'true') { return null; } $skill = new Skill(); $ranking = $skill->get_user_skill_ranking($userId); $skills = $skill->get_user_skills($userId, true); $template = new Template(null, false, false, false, false, false); $template->assign('ranking', $ranking); $template->assign('skills', $skills); $template->assign( 'show_skills_report_link', api_is_student() || api_is_student_boss() || api_is_drh() ); $skillBlock = $template->get_template('social/skills_block.tpl'); return $template->fetch($skillBlock); } }