12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365 |
- <?php
- /* For licensing terms, see /license.txt */
- use Chamilo\CourseBundle\Entity\CForumPost;
- use Chamilo\CourseBundle\Entity\CForumThread;
- use ChamiloSession as Session;
- use Zend\Feed\Reader\Entry\Rss;
- use Zend\Feed\Reader\Reader;
- /**
- * Class SocialManager.
- *
- * This class provides methods for the social network management.
- * Include/require it in your code to use its features.
- *
- * @package chamilo.social
- */
- class SocialManager extends UserManager
- {
- const DEFAULT_WALL_POSTS = 10;
- const DEFAULT_SCROLL_NEW_POST = 5;
- /**
- * Constructor.
- */
- public function __construct()
- {
- }
- /**
- * Allow to see contacts list.
- *
- * @author isaac flores paz
- *
- * @return array
- */
- public static function show_list_type_friends()
- {
- $table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
- $sql = 'SELECT id, title FROM '.$table.'
- WHERE id<>6
- ORDER BY id ASC';
- $result = Database::query($sql);
- $friend_relation_list = [];
- 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
- *
- * @return int
- *
- * @author isaac flores paz
- */
- public static function get_relation_between_contacts($user_id, $user_friend)
- {
- $table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
- $userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
- $sql = 'SELECT rt.id as id
- FROM '.$table.' rt
- WHERE rt.id = (
- SELECT uf.relation_type
- FROM '.$userRelUserTable.' 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_UNKNOWN;
- }
- }
- /**
- * Get count of friends from user.
- *
- * @param int $userId
- *
- * @return int
- */
- public static function getCountFriends($userId)
- {
- $table = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
- $userId = (int) $userId;
- if (empty($userId)) {
- return 0;
- }
- $sql = 'SELECT count(friend_user_id) count
- FROM '.$table.'
- WHERE
- relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND
- friend_user_id<>'.$userId.' AND
- user_id='.$userId;
- $res = Database::query($sql);
- if (Database::num_rows($res)) {
- $row = Database::fetch_array($res, 'ASSOC');
- return (int) $row['count'];
- }
- return 0;
- }
- /**
- * 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 <gugli100@gmail.com> 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
- ) {
- $user_id = (int) $user_id;
- $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<>'.$user_id.' AND
- user_id='.$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);
- $list = [];
- while ($row = Database::fetch_array($res, 'ASSOC')) {
- if ($load_extra_info) {
- $userInfo = api_get_user_info($row['friend_user_id']);
- $list[] = [
- 'friend_user_id' => $row['friend_user_id'],
- 'firstName' => $userInfo['firstName'],
- 'lastName' => $userInfo['lastName'],
- 'username' => $userInfo['username'],
- 'image' => $userInfo['avatar'],
- 'user_info' => $userInfo,
- ];
- } else {
- $list[] = $row;
- }
- }
- return $list;
- }
- /**
- * 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 = [];
- 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 bool
- *
- * @author isaac flores paz
- * @author Julio Montoya <gugli100@gmail.com> 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 = (int) $user_id;
- $friend_id = (int) $friend_id;
- //Just in case we replace the and \n and \n\r while saving in the DB
- $message_content = str_replace(["\n", "\n\r"], '<br />', $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('.MESSAGE_STATUS_INVITATION_PENDING.', '.MESSAGE_STATUS_INVITATION_ACCEPTED.', '.MESSAGE_STATUS_INVITATION_DENIED.');
- ';
- $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,
- 'group_id' => 0,
- 'parent_id' => 0,
- 'update_date' => $now,
- ];
- $messageId = Database::insert($tbl_message, $params);
- $senderInfo = api_get_user_info($user_id);
- $notification = new Notification();
- $notification->saveNotification(
- $messageId,
- Notification::NOTIFICATION_TYPE_INVITATION,
- [$friend_id],
- $message_title,
- $message_content,
- $senderInfo
- );
- 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 $userId user receiver id
- *
- * @return int
- */
- public static function get_message_number_invitation_by_user_id($userId)
- {
- $table = Database::get_main_table(TABLE_MESSAGE);
- $userId = (int) $userId;
- $sql = 'SELECT COUNT(*) as count_message_in_box FROM '.$table.'
- WHERE
- user_receiver_id='.$userId.' AND
- msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
- $res = Database::query($sql);
- $row = Database::fetch_array($res, 'ASSOC');
- if ($row) {
- return (int) $row['count_message_in_box'];
- }
- return 0;
- }
- /**
- * Get number of messages sent to other users.
- *
- * @param int $userId
- *
- * @return int
- */
- public static function getCountMessagesSent($userId)
- {
- $userId = (int) $userId;
- $table = Database::get_main_table(TABLE_MESSAGE);
- $sql = 'SELECT COUNT(*) FROM '.$table.'
- WHERE
- user_sender_id='.$userId.' AND
- msg_status < 5';
- $res = Database::query($sql);
- $row = Database::fetch_row($res);
- return $row[0];
- }
- /**
- * Get number of messages received from other users.
- *
- * @param int $receiver_id
- *
- * @return int
- */
- public static function getCountMessagesReceived($receiver_id)
- {
- $table = Database::get_main_table(TABLE_MESSAGE);
- $sql = 'SELECT COUNT(*) FROM '.$table.'
- WHERE
- user_receiver_id='.intval($receiver_id).' AND
- msg_status < 4';
- $res = Database::query($sql);
- $row = Database::fetch_row($res);
- return $row[0];
- }
- /**
- * Get number of messages posted on own wall.
- *
- * @param int $userId
- *
- * @return int
- */
- public static function getCountWallPostedMessages($userId)
- {
- $userId = (int) $userId;
- if (empty($userId)) {
- return 0;
- }
- $table = Database::get_main_table(TABLE_MESSAGE);
- $sql = 'SELECT COUNT(*)
- FROM '.$table.'
- WHERE
- user_sender_id='.$userId.' AND
- (msg_status = '.MESSAGE_STATUS_WALL.' OR
- msg_status = '.MESSAGE_STATUS_WALL_POST.') AND
- parent_id = 0';
- $res = Database::query($sql);
- $row = Database::fetch_row($res);
- return $row[0];
- }
- /**
- * Get invitation list received by user.
- *
- * @author isaac flores paz
- *
- * @param int $userId
- * @param int $limit
- *
- * @return array
- */
- public static function get_list_invitation_of_friends_by_user_id($userId, $limit = 0)
- {
- $userId = (int) $userId;
- $limit = (int) $limit;
- if (empty($userId)) {
- return [];
- }
- $table = Database::get_main_table(TABLE_MESSAGE);
- $sql = 'SELECT user_sender_id, send_date, title, content
- FROM '.$table.'
- WHERE
- user_receiver_id = '.$userId.' AND
- msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
- if ($limit != null && $limit > 0) {
- $sql .= ' LIMIT '.$limit;
- }
- $res = Database::query($sql);
- $list = [];
- while ($row = Database::fetch_array($res, 'ASSOC')) {
- $list[] = $row;
- }
- return $list;
- }
- /**
- * Get invitation list sent by user.
- *
- * @author Julio Montoya <gugli100@gmail.com>
- *
- * @param int $userId
- *
- * @return array
- */
- public static function get_list_invitation_sent_by_user_id($userId)
- {
- $userId = (int) $userId;
- if (empty($userId)) {
- return [];
- }
- $table = Database::get_main_table(TABLE_MESSAGE);
- $sql = 'SELECT user_receiver_id, send_date,title,content
- FROM '.$table.'
- WHERE
- user_sender_id = '.$userId.' AND
- msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
- $res = Database::query($sql);
- $list = [];
- while ($row = Database::fetch_array($res, 'ASSOC')) {
- $list[$row['user_receiver_id']] = $row;
- }
- return $list;
- }
- /**
- * Get count invitation sent by user.
- *
- * @author Julio Montoya <gugli100@gmail.com>
- *
- * @param int $userId
- *
- * @return int
- */
- public static function getCountInvitationSent($userId)
- {
- $userId = (int) $userId;
- if (empty($userId)) {
- return 0;
- }
- $table = Database::get_main_table(TABLE_MESSAGE);
- $sql = 'SELECT count(user_receiver_id) count
- FROM '.$table.'
- WHERE
- user_sender_id = '.$userId.' AND
- msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
- $res = Database::query($sql);
- if (Database::num_rows($res)) {
- $row = Database::fetch_array($res, 'ASSOC');
- return (int) $row['count'];
- }
- return 0;
- }
- /**
- * Accepts invitation.
- *
- * @param int $user_send_id
- * @param int $user_receiver_id
- *
- * @return bool
- *
- * @author isaac flores paz
- * @author Julio Montoya <gugli100@gmail.com> Cleaning code
- */
- public static function invitation_accepted($user_send_id, $user_receiver_id)
- {
- if (empty($user_send_id) || empty($user_receiver_id)) {
- return false;
- }
- $table = Database::get_main_table(TABLE_MESSAGE);
- $sql = "UPDATE $table
- 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);
- return true;
- }
- /**
- * Denies invitation.
- *
- * @param int user sender id
- * @param int user receiver id
- *
- * @return bool
- *
- * @author isaac flores paz
- * @author Julio Montoya <gugli100@gmail.com> Cleaning code
- */
- public static function invitation_denied($user_send_id, $user_receiver_id)
- {
- if (empty($user_send_id) || empty($user_receiver_id)) {
- return false;
- }
- $table = Database::get_main_table(TABLE_MESSAGE);
- $sql = 'DELETE FROM '.$table.'
- 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);
- return true;
- }
- /**
- * Get user's feeds.
- *
- * @param int $user User ID
- * @param int $limit 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 getUserRssFeed($user, $limit = 5)
- {
- $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;
- }
- try {
- $channel = Reader::import($url);
- $i = 1;
- if (!empty($channel)) {
- $iconRss = '';
- if (!empty($feed)) {
- $iconRss = Display::url(
- Display::return_icon('social_rss.png', '', [], 22),
- Security::remove_XSS($feed['rssfeeds']),
- ['target' => '_blank']
- );
- }
- $res .= '<h3 class="title-rss">'.$iconRss.' '.$channel->getTitle().'</h3>';
- $res .= '<div class="rss-items">';
- /** @var Rss $item */
- foreach ($channel as $item) {
- if ($limit >= 0 and $i > $limit) {
- break;
- }
- $res .= '<h4 class="rss-title"><a href="'.$item->getLink().'">'.$item->getTitle().'</a></h4>';
- $res .= '<div class="rss-date">'.api_get_local_time($item->getDateCreated()).'</div>';
- $res .= '<div class="rss-content"><p>'.$item->getDescription().'</p></div>';
- $i++;
- }
- $res .= '</div>';
- }
- } catch (Exception $e) {
- error_log($e->getMessage());
- }
- }
- return $res;
- }
- /**
- * Sends invitations to friends.
- *
- * @param int $userId
- * @param string $subject
- * @param string $content
- *
- * @return bool
- */
- public static function sendInvitationToUser($userId, $subject = '', $content = '')
- {
- $user_info = api_get_user_info($userId);
- $success = get_lang('MessageSentTo');
- $success .= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']);
- if (isset($subject) && isset($content) && isset($userId)) {
- $result = MessageManager::send_message($userId, $subject, $content);
- if ($result) {
- Display::addFlash(
- Display::return_message($success, 'normal', false)
- );
- } else {
- Display::addFlash(
- Display::return_message(get_lang('ErrorSendingMessage'), 'error', false)
- );
- }
- return false;
- } elseif (isset($userId) && !isset($subject)) {
- if (isset($userId) && $userId > 0) {
- $count = self::send_invitation_friend(
- api_get_user_id(),
- $userId,
- get_lang('Invitation'),
- $content
- );
- if ($count) {
- Display::addFlash(
- Display::return_message(
- api_htmlentities(get_lang('InvitationHasBeenSent')),
- 'normal',
- false
- )
- );
- } else {
- Display::addFlash(
- Display::return_message(
- api_htmlentities(get_lang('YouAlreadySentAnInvitation')),
- 'warning',
- false
- )
- );
- }
- }
- }
- }
- /**
- * Helper functions definition.
- */
- public static function get_logged_user_course_html($my_course, $count)
- {
- $result = '';
- $count = (int) $count;
- // Table definitions
- $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $course_directory = $my_course['course_info']['directory'];
- $course_title = $my_course['course_info']['title'];
- $course_visibility = $my_course['course_info']['visibility'];
- $user_in_course_status = CourseManager::getUserInCourseStatus(
- api_get_user_id(),
- $my_course['course_info']['real_id']
- );
- $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, ['class' => 'img-course']);
- } else {
- $imageCourse = Display::return_icon(
- 'session_default_small.png',
- $course_title,
- ['class' => 'img-course']
- );
- }
- } else {
- $imageCourse = Display::return_icon(
- 'course.png',
- get_lang('Course'),
- ['class' => 'img-default']
- );
- }
- //display course entry
- if (api_get_setting('course_images_in_courses_list') === 'true') {
- $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:65px;">';
- } else {
- $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:44px;">';
- }
- $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 .= '<span class="title">'.$course_title.'<span>';
- } else {
- $result .= $course_title.' '.get_lang('CourseClosed');
- }
- $result .= '</li>';
- $session = '';
- 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 = [];
- $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']);
- }
- } 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 = [
- $my_course['user_course_cat'],
- $result,
- $my_course['id_session'],
- $session,
- ];
- return $output;
- }
- /**
- * Shows the avatar block in social pages.
- *
- * @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
- * @param int $user_id
- */
- public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0)
- {
- $user_id = (int) $user_id;
- $group_id = (int) $group_id;
- if (empty($user_id)) {
- $user_id = api_get_user_id();
- }
- $show_groups = [
- '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'],
- 128,
- GROUP_IMAGE_SIZE_BIG
- );
- $template->assign('show_group', true);
- $template->assign('group_id', $group_id);
- $template->assign('user_group_image', $userGroupImage);
- $template->assign(
- 'user_is_group_admin',
- $userGroup->is_group_admin(
- $group_id,
- api_get_user_id()
- )
- );
- } else {
- $template->assign('show_group', false);
- $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
- ) {
- $user_id = (int) $user_id;
- $group_id = (int) $group_id;
- if (empty($user_id)) {
- $user_id = api_get_user_id();
- }
- $usergroup = new UserGroup();
- $show_groups = [
- '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::getCountNewMessagesFromDB(api_get_user_id());
- $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null;
- $number_of_new_messages_of_friend = self::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) : '');
- $filesIcon = Display::return_icon('sn-files.png', get_lang('MyFiles'), null, ICON_SIZE_SMALL);
- $friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), null, ICON_SIZE_SMALL);
- $groupsIcon = Display::return_icon('sn-groups.png', get_lang('SocialGroups'), null, ICON_SIZE_SMALL);
- $homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), null, ICON_SIZE_SMALL);
- $invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), null, ICON_SIZE_SMALL);
- $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), null, ICON_SIZE_SMALL);
- $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile'));
- $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), null, ICON_SIZE_SMALL);
- $portfolioIcon = Display::return_icon('wiki_task.png', get_lang('Portfolio'));
- $personalDataIcon = Display::return_icon('database.png', get_lang('PersonalDataReport'));
- $messageSocialIcon = Display::return_icon('promoted_message.png', get_lang('PromotedMessages'));
- $forumCourseId = api_get_configuration_value('global_forums_course_id');
- $groupUrl = api_get_path(WEB_CODE_PATH).'social/groups.php';
- if (!empty($forumCourseId)) {
- $courseInfo = api_get_course_info_by_id($forumCourseId);
- if (!empty($courseInfo)) {
- $groupUrl = api_get_path(WEB_CODE_PATH).'forum/index.php?cidReq='.$courseInfo['code'];
- }
- }
- $html = '';
- $active = null;
- if (!in_array(
- $show,
- ['shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends']
- )) {
- $links = '<ul class="nav nav-pills nav-stacked">';
- $active = $show === 'home' ? 'active' : null;
- $links .= '
- <li class="home-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/home.php">
- '.$homeIcon.' '.get_lang('Home').'
- </a>
- </li>';
- $active = $show === 'messages' ? 'active' : null;
- $links .= '
- <li class="messages-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">
- '.$messagesIcon.' '.get_lang('Messages').$count_unread_message.'
- </a>
- </li>';
- // Invitations
- $active = $show === 'invitations' ? 'active' : null;
- $links .= '
- <li class="invitations-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">
- '.$invitationsIcon.' '.get_lang('Invitations').$total_invitations.'
- </a>
- </li>';
- // Shared profile and groups
- $active = $show === 'shared_profile' ? 'active' : null;
- $links .= '
- <li class="shared-profile-icon'.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php">
- '.$sharedProfileIcon.' '.get_lang('ViewMySharedProfile').'
- </a>
- </li>';
- $active = $show === 'friends' ? 'active' : null;
- $links .= '
- <li class="friends-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php">
- '.$friendsIcon.' '.get_lang('Friends').'
- </a>
- </li>';
- $active = $show === 'browse_groups' ? 'active' : null;
- $links .= '
- <li class="browse-groups-icon '.$active.'">
- <a href="'.$groupUrl.'">
- '.$groupsIcon.' '.get_lang('SocialGroups').'
- </a>
- </li>';
- // Search users
- $active = $show === 'search' ? 'active' : null;
- $links .= '
- <li class="search-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/search.php">
- '.$searchIcon.' '.get_lang('Search').'
- </a>
- </li>';
- // My files
- $active = $show === 'myfiles' ? 'active' : null;
- $myFiles = '
- <li class="myfiles-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php">
- '.$filesIcon.' '.get_lang('MyFiles').'
- </a>
- </li>';
- if (api_get_setting('allow_my_files') === 'false') {
- $myFiles = '';
- }
- $links .= $myFiles;
- if (api_get_configuration_value('allow_portfolio_tool')) {
- $links .= '
- <li class="portoflio-icon '.($show === 'portfolio' ? 'active' : '').'">
- <a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php">
- '.$portfolioIcon.' '.get_lang('Portfolio').'
- </a>
- </li>
- ';
- }
- if (!api_get_configuration_value('disable_gdpr')) {
- $active = $show === 'personal-data' ? 'active' : null;
- $personalData = '
- <li class="personal-data-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/personal_data.php">
- '.$personalDataIcon.' '.get_lang('PersonalDataReport').'
- </a>
- </li>';
- $links .= $personalData;
- }
- if (api_is_platform_admin()) {
- $active = $show === 'promoted_messages' ? 'active' : null;
- $personalData = '
- <li class="personal-data-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/promoted_messages.php">
- '.$messageSocialIcon.' '.get_lang('PromotedMessages').'
- </a>
- </li>';
- $links .= $personalData;
- }
- $links .= '</ul>';
- $html .= Display::panelCollapse(
- get_lang('SocialNetwork'),
- $links,
- 'social-network-menu',
- null,
- 'sn-sidebar',
- 'sn-sidebar-collapse'
- );
- }
- if (!empty($group_id) && in_array($show, $show_groups)) {
- $html .= $usergroup->show_group_column_information(
- $group_id,
- api_get_user_id(),
- $show
- );
- }
- if ($show === 'shared_profile') {
- $links = '<ul class="nav nav-pills nav-stacked">';
- // My own profile
- if ($show_full_profile && $user_id == api_get_user_id()) {
- $links .= '
- <li class="home-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/home.php">
- '.$homeIcon.' '.get_lang('Home').'
- </a>
- </li>
- <li class="messages-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">
- '.$messagesIcon.' '.get_lang('Messages').$count_unread_message.'
- </a>
- </li>';
- $active = $show === 'invitations' ? 'active' : null;
- $links .= '
- <li class="invitations-icon'.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">
- '.$invitationsIcon.' '.get_lang('Invitations').$total_invitations.'
- </a>
- </li>';
- $links .= '
- <li class="shared-profile-icon active">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php">
- '.$sharedProfileIcon.' '.get_lang('ViewMySharedProfile').'
- </a>
- </li>
- <li class="friends-icon">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php">
- '.$friendsIcon.' '.get_lang('Friends').'
- </a>
- </li>';
- $links .= '<li class="browse-groups-icon">
- <a href="'.$groupUrl.'">
- '.$groupsIcon.' '.get_lang('SocialGroups').'
- </a>
- </li>';
- $active = $show == 'search' ? 'active' : null;
- $links .= '
- <li class="search-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/search.php">
- '.$searchIcon.' '.get_lang('Search').'
- </a>
- </li>';
- $active = $show == 'myfiles' ? 'active' : null;
- $myFiles = '
- <li class="myfiles-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php">
- '.$filesIcon.' '.get_lang('MyFiles').'
- </a>
- </li>';
- if (api_get_setting('allow_my_files') === 'false') {
- $myFiles = '';
- }
- $links .= $myFiles;
- if (api_get_configuration_value('allow_portfolio_tool')) {
- $links .= '
- <li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'">
- <a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php">
- '.$portfolioIcon.' '.get_lang('Portfolio').'
- </a>
- </li>
- ';
- }
- if (!api_get_configuration_value('disable_gdpr')) {
- $active = $show == 'personal-data' ? 'active' : null;
- $personalData = '
- <li class="personal-data-icon '.$active.'">
- <a href="'.api_get_path(WEB_CODE_PATH).'social/personal_data.php">
- '.$personalDataIcon.' '.get_lang('PersonalDataReport').'
- </a>
- </li>';
- $links .= $personalData;
- $links .= '</ul>';
- }
- }
- // My friend profile.
- if ($user_id != api_get_user_id()) {
- $sendMessageText = get_lang('SendMessage');
- $sendMessageIcon = Display::return_icon(
- 'new-message.png',
- $sendMessageText
- );
- $sendMessageUrl = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?'.http_build_query([
- 'a' => 'get_user_popup',
- 'user_id' => $user_id,
- ]);
- $links .= '<li>';
- $links .= Display::url(
- "$sendMessageIcon $sendMessageText",
- $sendMessageUrl,
- [
- 'class' => 'ajax',
- 'title' => $sendMessageText,
- 'data-title' => $sendMessageText,
- ]
- );
- $links .= '</li>';
- if (api_get_configuration_value('allow_portfolio_tool')) {
- $links .= '
- <li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'">
- <a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php?user='.$user_id.'">
- '.$portfolioIcon.' '.get_lang('Portfolio').'
- </a>
- </li>
- ';
- }
- }
- // Check if I already sent an invitation message
- $invitationSentList = self::get_list_invitation_sent_by_user_id(api_get_user_id());
- if (isset($invitationSentList[$user_id]) && is_array($invitationSentList[$user_id]) &&
- count($invitationSentList[$user_id]) > 0
- ) {
- $links .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">'.
- Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation'))
- .' '.get_lang('YouAlreadySentAnInvitation').'</a></li>';
- } else {
- if (!$show_full_profile) {
- $links .= '<li>
- <a class="btn-to-send-invitation" href="#" data-send-to="'.$user_id.'" title="'.get_lang('SendInvitation').'">'.
- Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')).' '.get_lang('SendInvitation').
- '</a></li>';
- }
- }
- $links .= '</ul>';
- $html .= Display::panelCollapse(
- get_lang('SocialNetwork'),
- $links,
- 'social-network-menu',
- null,
- 'sn-sidebar',
- 'sn-sidebar-collapse'
- );
- if ($show_full_profile && $user_id == api_get_user_id()) {
- $personal_course_list = UserManager::get_personal_session_course_list($user_id);
- $course_list_code = [];
- $i = 1;
- if (is_array($personal_course_list)) {
- foreach ($personal_course_list as $my_course) {
- if ($i <= 10) {
- $course_list_code[] = ['code' => $my_course['code']];
- } else {
- break;
- }
- $i++;
- }
- // To avoid repeated courses
- $course_list_code = array_unique_dimensional($course_list_code);
- }
- // Announcements
- $announcements = [];
- 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'],
- $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 .= '<div class="social_menu_items">';
- $html .= '<ul>';
- foreach ($announcements as $announcement) {
- $html .= $announcement;
- }
- $html .= '</ul>';
- $html .= '</div>';
- }
- }
- }
- if ($show_delete_account_button) {
- $html .= '<div class="panel panel-default"><div class="panel-body">';
- $html .= '<ul class="nav nav-pills nav-stacked"><li>';
- $url = api_get_path(WEB_CODE_PATH).'auth/unsubscribe_account.php';
- $html .= Display::url(
- Display::return_icon(
- 'delete.png',
- get_lang('Unsubscribe'),
- [],
- ICON_SIZE_TINY
- ).get_lang('Unsubscribe'),
- $url
- );
- $html .= '</li></ul>';
- $html .= '</div></div>';
- }
- $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 = '';
- if (isset($_GET['id']) || count($user_list) < 1) {
- return false;
- }
- $course_url = '';
- if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
- $course_url = '&cidReq='.Security::remove_XSS($_GET['cidReq']);
- }
- $hide = api_get_configuration_value('hide_complete_name_in_whoisonline');
- foreach ($user_list as $uid) {
- $user_info = api_get_user_info($uid, 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 (isset($user_info['user_is_online_in_chat']) && $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'];
- $officialCode = '';
- if (api_get_setting('show_official_code_whoisonline') == 'true') {
- $officialCode .= '<div class="items-user-official-code"><p style="min-height: 30px;" title="'.get_lang('OfficialCode').'">'.$user_info['official_code'].'</p></div>';
- }
- if ($hide === true) {
- $completeName = '';
- $firstname = '';
- $lastname = '';
- }
- $img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">';
- $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 = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>';
- $html .= '<div class="col-xs-6 col-md-2">
- <div class="items-user">
- <div class="items-user-avatar"><a href="'.$url.'">'.$img.'</a></div>
- <div class="items-user-name">
- '.$name.'
- </div>
- '.$officialCode.'
- <div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div>
- </div>
- </div>';
- }
- return $html;
- }
- /**
- * Displays the information of an individual user.
- *
- * @param int $user_id
- *
- * @return string
- */
- public static function display_individual_user($user_id)
- {
- global $interbreadcrumb;
- $safe_user_id = (int) $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[] = ['url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList')];
- $html .= '<div class ="thumbnail">';
- $fullurl = $userInfo['avatar'];
- $html .= '<img src="'.$fullurl.'" alt="'.$alt.'" />';
- if (!empty($status)) {
- $html .= '<div class="caption">'.$status.'</div>';
- }
- $html .= '</div>';
- if (api_get_setting('show_email_addresses') == 'true') {
- $html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'<br />';
- }
- if ($user_object->competences) {
- $html .= Display::page_subheader(get_lang('MyCompetences'));
- $html .= '<p>'.$user_object->competences.'</p>';
- }
- if ($user_object->diplomas) {
- $html .= Display::page_subheader(get_lang('MyDiplomas'));
- $html .= '<p>'.$user_object->diplomas.'</p>';
- }
- if ($user_object->teach) {
- $html .= Display::page_subheader(get_lang('MyTeach'));
- $html .= '<p>'.$user_object->teach.'</p>';
- }
- self::display_productions($user_object->user_id);
- if ($user_object->openarea) {
- $html .= Display::page_subheader(get_lang('MyPersonalOpenArea'));
- $html .= '<p>'.$user_object->openarea.'</p>';
- }
- } else {
- $html .= '<div class="actions-title">';
- $html .= get_lang('UsersOnLineList');
- $html .= '</div>';
- }
- 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 '<dt><strong>'.get_lang('Productions').'</strong></dt>';
- echo '<dd><ul>';
- 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 '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
- }
- // 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 '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
- }
- }
- }
- }
- echo '</ul></dd>';
- }
- }
- /**
- * @param string $content
- * @param string $span_count
- *
- * @return string
- */
- public static function social_wrapper_div($content, $span_count)
- {
- $span_count = (int) $span_count;
- $html = '<div class="span'.$span_count.'">';
- $html .= '<div class="well_border">';
- $html .= $content;
- $html .= '</div></div>';
- return $html;
- }
- /**
- * Dummy function.
- */
- public static function get_plugins($place = SOCIAL_CENTER_PLUGIN)
- {
- $content = '';
- switch ($place) {
- case SOCIAL_CENTER_PLUGIN:
- $social_plugins = [1, 2];
- if (is_array($social_plugins) && count($social_plugins) > 0) {
- $content .= '<div id="social-plugins">';
- foreach ($social_plugins as $plugin) {
- $content .= '<div class="social-plugin-item">';
- $content .= $plugin;
- $content .= '</div>';
- }
- $content .= '</div>';
- }
- 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 int
- *
- * @author Yannick Warnier
- */
- public static function sendWallMessage(
- $userId,
- $friendId,
- $messageContent,
- $messageId = 0,
- $messageStatus = ''
- ) {
- $tblMessage = Database::get_main_table(TABLE_MESSAGE);
- $userId = (int) $userId;
- $friendId = (int) $friendId;
- $messageId = (int) $messageId;
- if (empty($userId) || empty($friendId)) {
- return 0;
- }
- // Just in case we replace the and \n and \n\r while saving in the DB
- $messageContent = str_replace(["\n", "\n\r"], '<br />', $messageContent);
- $now = api_get_utc_datetime();
- $attributes = [
- 'user_sender_id' => $userId,
- 'user_receiver_id' => $friendId,
- 'msg_status' => $messageStatus,
- 'send_date' => $now,
- 'title' => '',
- 'content' => $messageContent,
- 'parent_id' => $messageId,
- 'group_id' => 0,
- 'update_date' => $now,
- ];
- 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|int
- */
- public static function sendWallMessageAttachmentFile(
- $userId,
- $fileAttach,
- $messageId,
- $fileComment = ''
- ) {
- $safeFileName = Database::escape_string($fileAttach['name']);
- $extension = strtolower(substr(strrchr($safeFileName, '.'), 1));
- $allowedTypes = api_get_supported_image_extensions();
- $allowedTypes[] = 'mp4';
- $allowedTypes[] = 'webm';
- $allowedTypes[] = 'ogg';
- if (in_array($extension, $allowedTypes)) {
- return MessageManager::saveMessageAttachmentFile($fileAttach, $fileComment, $messageId, $userId);
- }
- return false;
- }
- /**
- * Gets all messages from someone's wall (within specific limits).
- *
- * @param int $userId id of wall shown
- * @param int|string $parentId id message (Post main)
- * @param int|array $groupId
- * @param int|array $friendId
- * @param string $startDate Date from which we want to show the messages, in UTC time
- * @param int $start Limit for the number of parent messages we want to show
- * @param int $length Wall message query offset
- * @param bool $getCount
- * @param array $threadList
- *
- * @return array|int
- *
- * @author Yannick Warnier
- */
- public static function getWallMessages(
- $userId,
- $parentId = 0,
- $groupId = 0,
- $friendId = 0,
- $startDate = '',
- $start = 0,
- $length = 10,
- $getCount = false,
- $threadList = []
- ) {
- $tblMessage = Database::get_main_table(TABLE_MESSAGE);
- $parentId = (int) $parentId;
- $userId = (int) $userId;
- $start = (int) $start;
- $length = (int) $length;
- $select = " SELECT
- id,
- user_sender_id,
- user_receiver_id,
- send_date,
- content,
- parent_id,
- msg_status,
- group_id,
- '' as forum_id,
- '' as thread_id,
- '' as c_id
- ";
- if ($getCount) {
- $select = ' SELECT count(id) count ';
- }
- $sql = "$select
- FROM $tblMessage m
- WHERE
- msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND ';
- // Get my own posts
- $userReceiverCondition = ' (
- user_receiver_id = '.$userId.' AND
- msg_status IN ('.MESSAGE_STATUS_WALL_POST.', '.MESSAGE_STATUS_WALL.') AND
- parent_id = '.$parentId.'
- )';
- $sql .= $userReceiverCondition;
- $sql .= ' OR ( msg_status = '.MESSAGE_STATUS_PROMOTED.' ) ';
- // Get my group posts
- $groupCondition = '';
- if (!empty($groupId)) {
- if (is_array($groupId)) {
- $groupId = array_map('intval', $groupId);
- $groupId = implode("','", $groupId);
- $groupCondition = " OR ( group_id IN ('$groupId') ";
- } else {
- $groupId = (int) $groupId;
- $groupCondition = " OR ( group_id = '$groupId' ";
- }
- $groupCondition .= ' AND msg_status IN ('.MESSAGE_STATUS_NEW.', '.MESSAGE_STATUS_UNREAD.')) ';
- }
- // Get my friend posts
- $friendCondition = '';
- if (!empty($friendId)) {
- if (is_array($friendId)) {
- $friendId = array_map('intval', $friendId);
- $friendId = implode("','", $friendId);
- $friendCondition = " OR ( user_receiver_id IN ('$friendId') ";
- } else {
- $friendId = (int) $friendId;
- $friendCondition = " OR ( user_receiver_id = '$friendId' ";
- }
- $friendCondition .= ' AND msg_status = '.MESSAGE_STATUS_WALL_POST.' AND parent_id = 0) ';
- }
- if (!empty($groupCondition) || !empty($friendCondition)) {
- $sql .= " $groupCondition $friendCondition ";
- }
- if (!empty($threadList)) {
- if ($getCount) {
- $select = ' SELECT count(iid) count ';
- } else {
- $select = " SELECT
- iid,
- poster_id,
- '' as user_receiver_id,
- post_date,
- post_text,
- '' as parent_id,
- ".MESSAGE_STATUS_FORUM.",
- '' as group_id,
- forum_id,
- thread_id,
- c_id
- ";
- }
- $threadList = array_map('intval', $threadList);
- $threadList = implode("','", $threadList);
- $condition = " thread_id IN ('$threadList') ";
- $sql .= "
- UNION (
- $select
- FROM c_forum_post
- WHERE $condition
- )
- ";
- }
- if ($getCount) {
- $res = Database::query($sql);
- $row = Database::fetch_array($res);
- return (int) $row['count'];
- }
- $sql .= ' ORDER BY send_date DESC ';
- $sql .= " LIMIT $start, $length ";
- $messages = [];
- $res = Database::query($sql);
- $em = Database::getManager();
- if (Database::num_rows($res) > 0) {
- $repo = $em->getRepository('ChamiloCourseBundle:CForumPost');
- $repoThread = $em->getRepository('ChamiloCourseBundle:CForumThread');
- $groups = [];
- $userGroup = new UserGroup();
- $urlGroup = api_get_path(WEB_CODE_PATH).'social/group_view.php?id=';
- while ($row = Database::fetch_array($res, 'ASSOC')) {
- $row['group_info'] = [];
- if (!empty($row['group_id'])) {
- if (!in_array($row['group_id'], $groups)) {
- $group = $userGroup->get($row['group_id']);
- $group['url'] = $urlGroup.$group['id'];
- $groups[$row['group_id']] = $group;
- $row['group_info'] = $group;
- } else {
- $row['group_info'] = $groups[$row['group_id']];
- }
- }
- // Forums
- $row['post_title'] = '';
- $row['forum_title'] = '';
- $row['thread_url'] = '';
- if ($row['msg_status'] == MESSAGE_STATUS_FORUM) {
- /** @var CForumPost $post */
- $post = $repo->find($row['id']);
- /** @var CForumThread $thread */
- $thread = $repoThread->find($row['thread_id']);
- if ($post && $thread) {
- $courseInfo = api_get_course_info_by_id($post->getCId());
- $row['post_title'] = $post->getForumId();
- $row['forum_title'] = $thread->getThreadTitle();
- $row['thread_url'] = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([
- 'cidReq' => $courseInfo['code'],
- 'forum' => $post->getForumId(),
- 'thread' => $post->getThreadId(),
- 'post_id' => $post->getIid(),
- ]).'#post_id_'.$post->getIid();
- }
- }
- $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 array $messageInfo
- * @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 getWallPostComments(
- $userId,
- $messageInfo,
- $start = null,
- $limit = 10,
- $offset = 0
- ) {
- $messageId = $messageInfo['id'];
- $messages = MessageManager::getMessagesByParent($messageInfo['id'], 0, $offset, $limit);
- $formattedList = '<div class="sub-mediapost row">';
- $users = [];
- // The messages are ordered by date descendant, for comments we need ascendant
- krsort($messages);
- foreach ($messages as $message) {
- $userIdLoop = $message['user_sender_id'];
- if (!isset($users[$userIdLoop])) {
- $users[$userIdLoop] = api_get_user_info($userIdLoop);
- }
- $media = self::processPostComment($message, $users);
- $formattedList .= $media;
- }
- $formattedList .= '</div>';
- $formattedList .= '<div class="mediapost-form row">';
- $formattedList .= '<form class="form-horizontal" id="form_comment_'.$messageId.'" name="post_comment" method="POST">
- <div class="col-sm-9">
- <label for="comment" class="hide">'.get_lang('SocialWriteNewComment').'</label>
- <input type="hidden" name = "messageId" value="'.$messageId.'" />
- <textarea rows="3" class="form-control" placeholder="'.get_lang('SocialWriteNewComment').'" name="comment" rows="1" ></textarea>
- </div>
- <div class="col-sm-3 pull-right">
- <a onclick="submitComment('.$messageId.');" href="javascript:void(0);" name="social_wall_new_msg_submit" class="btn btn-default btn-post">
- <em class="fa fa-pencil"></em> '.get_lang('Post').'
- </a>
- </div>
- </form>';
- $formattedList .= '</div>';
- return $formattedList;
- }
- /**
- * @param array $message
- * @param array $users
- *
- * @return string
- */
- public static function processPostComment($message, $users = [])
- {
- if (empty($message)) {
- return false;
- }
- $date = Display::dateToStringAgoAndLongDate($message['send_date']);
- $currentUserId = api_get_user_id();
- $userIdLoop = $message['user_sender_id'];
- $receiverId = $message['user_receiver_id'];
- if (!isset($users[$userIdLoop])) {
- $users[$userIdLoop] = api_get_user_info($userIdLoop);
- }
- $iconStatus = $users[$userIdLoop]['icon_status'];
- $nameComplete = $users[$userIdLoop]['complete_name'];
- $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop;
- $comment = '<div class="rep-post col-md-12">';
- $comment .= '<div class="col-md-2 col-xs-2 social-post-answers">';
- $comment .= '<div class="user-image pull-right">';
- $comment .= '<a href="'.$url.'">
- <img src="'.$users[$userIdLoop]['avatar'].'"
- alt="'.$users[$userIdLoop]['complete_name'].'"
- class="avatar-thumb">
- </a>';
- $comment .= '</div>';
- $comment .= '</div>';
- $comment .= '<div class="col-md-7 col-xs-7 social-post-answers">';
- $comment .= '<div class="user-data">';
- $comment .= $iconStatus;
- $comment .= '<div class="username"><a href="'.$url.'">'.$nameComplete.'</a>
- <span>'.Security::remove_XSS($message['content']).'</span>
- </div>';
- $comment .= '<div>'.$date.'</div>';
- $comment .= '<br />';
- $comment .= '</div>';
- $comment .= '</div>';
- $comment .= '<div class="col-md-3 col-xs-3 social-post-answers">';
- $comment .= '<div class="pull-right btn-group btn-group-sm">';
- $comment .= MessageManager::getLikesButton(
- $message['id'],
- $currentUserId
- );
- $isOwnWall = $currentUserId == $userIdLoop || $currentUserId == $receiverId;
- if ($isOwnWall) {
- $comment .= Display::url(
- Display::returnFontAwesomeIcon('trash', '', true),
- 'javascript:void(0)',
- [
- 'id' => 'message_'.$message['id'],
- 'title' => get_lang('SocialMessageDelete'),
- 'onclick' => 'deleteComment('.$message['id'].')',
- 'class' => 'btn btn-default',
- ]
- );
- }
- $comment .= '</div>';
- $comment .= '</div>';
- $comment .= '</div>';
- return $comment;
- }
- /**
- * @param array $message
- *
- * @return array
- */
- public static function getAttachmentPreviewList($message)
- {
- $messageId = $message['id'];
- $list = [];
- if (empty($message['group_id'])) {
- $files = MessageManager::getAttachmentList($messageId);
- if ($files) {
- $downloadUrl = api_get_path(WEB_CODE_PATH).'social/download.php?message_id='.$messageId;
- foreach ($files as $row_file) {
- $url = $downloadUrl.'&attachment_id='.$row_file['id'];
- $display = Display::fileHtmlGuesser($row_file['filename'], $url);
- $list[] = $display;
- }
- }
- } else {
- $list = MessageManager::getAttachmentLinkList($messageId, 0);
- }
- return $list;
- }
- /**
- * @param array $message
- *
- * @return string
- */
- public static function getPostAttachment($message)
- {
- $previews = self::getAttachmentPreviewList($message);
- if (empty($previews)) {
- return '';
- }
- return implode('', $previews);
- }
- /**
- * @param array $messages
- *
- * @return array
- */
- public static function formatWallMessages($messages)
- {
- $data = [];
- $users = [];
- 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 = self::headerMessagePost(
- $users[$userIdLoop],
- $users[$userFriendIdLoop],
- $message
- );
- $data[$key] = $message;
- $data[$key]['html'] = $html;
- }
- return $data;
- }
- /**
- * get html data with OpenGrap passing the URL.
- *
- * @param $link url
- *
- * @return string data html
- */
- public static function readContentWithOpenGraph($link)
- {
- if (strpos($link, "://") === false && substr($link, 0, 1) != "/") {
- $link = "http://".$link;
- }
- $graph = OpenGraph::fetch($link);
- $link = parse_url($link);
- $host = $link['host'] ? strtoupper($link['host']) : $link['path'];
- if (!$graph) {
- return false;
- }
- $url = $graph->url;
- $image = $graph->image;
- $description = $graph->description;
- $title = $graph->title;
- $html = '<div class="thumbnail social-thumbnail">';
- $html .= empty($image) ? '' : '<a target="_blank" href="'.$url.'">
- <img class="img-responsive social-image" src="'.$image.'" /></a>';
- $html .= '<div class="social-description">';
- $html .= '<a target="_blank" href="'.$url.'"><h5 class="social-title"><b>'.$title.'</b></h5></a>';
- $html .= empty($description) ? '' : '<span>'.$description.'</span>';
- $html .= empty($host) ? '' : '<p>'.$host.'</p>';
- $html .= '</div>';
- $html .= '</div>';
- return $html;
- }
- /**
- * verify if Url Exist - Using Curl.
- *
- * @param $uri url
- *
- * @return bool
- */
- public static function verifyUrl($uri)
- {
- $curl = curl_init($uri);
- curl_setopt($curl, CURLOPT_FAILONERROR, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_TIMEOUT, 15);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
- $response = curl_exec($curl);
- curl_close($curl);
- if (!empty($response)) {
- return true;
- }
- return false;
- }
- /**
- * Soft delete a message and his chidren.
- *
- * @param int $id id message to delete
- *
- * @return bool status query
- */
- public static function deleteMessage($id)
- {
- $id = (int) $id;
- $messageInfo = MessageManager::get_message_by_id($id);
- if (!empty($messageInfo)) {
- // Delete comments too
- $messages = MessageManager::getMessagesByParent($id);
- if (!empty($messages)) {
- foreach ($messages as $message) {
- self::deleteMessage($message['id']);
- }
- }
- // Soft delete message
- $tblMessage = Database::get_main_table(TABLE_MESSAGE);
- $statusMessage = MESSAGE_STATUS_WALL_DELETE;
- $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' ";
- Database::query($sql);
- MessageManager::delete_message_attachment_file($id, $messageInfo['user_sender_id']);
- MessageManager::delete_message_attachment_file($id, $messageInfo['user_receiver_id']);
- return true;
- }
- return false;
- }
- /**
- * 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
- * @param bool $show_full_profile
- *
- * @return string The HTML code with the social block
- */
- public static function setSocialUserBlock(
- Template $template,
- $userId,
- $groupBlock = '',
- $groupId = 0,
- $show_full_profile = true
- ) {
- if (api_get_setting('allow_social_tool') != 'true') {
- return '';
- }
- $currentUserId = api_get_user_id();
- $userId = (int) $userId;
- $userRelationType = 0;
- $socialAvatarBlock = self::show_social_avatar_block(
- $groupBlock,
- $groupId,
- $userId
- );
- $profileEditionLink = null;
- if ($currentUserId === $userId) {
- $profileEditionLink = Display::getProfileEditionLink($userId);
- } else {
- $userRelationType = self::get_relation_between_contacts($currentUserId, $userId);
- }
- $options = api_get_configuration_value('profile_fields_visibility');
- if (isset($options['options'])) {
- $options = $options['options'];
- }
- $vCardUserLink = Display::getVCardUserLink($userId);
- if (isset($options['vcard']) && $options['vcard'] === false) {
- $vCardUserLink = '';
- }
- $userInfo = api_get_user_info($userId, true, false, true, true);
- if (isset($options['firstname']) && $options['firstname'] === false) {
- $userInfo['firstname'] = '';
- }
- if (isset($options['lastname']) && $options['lastname'] === false) {
- $userInfo['lastname'] = '';
- }
- if (isset($options['email']) && $options['email'] === false) {
- $userInfo['email'] = '';
- }
- // Ofaj
- $hasCertificates = Certificate::getCertificateByUser($userId);
- $userInfo['has_certificates'] = 0;
- if (!empty($hasCertificates)) {
- $userInfo['has_certificates'] = 1;
- }
- $userInfo['is_admin'] = UserManager::is_admin($userId);
- $languageId = api_get_language_id($userInfo['language']);
- $languageInfo = api_get_language_info($languageId);
- if ($languageInfo) {
- $userInfo['language'] = [
- 'label' => $languageInfo['original_name'],
- 'value' => $languageInfo['english_name'],
- 'code' => $languageInfo['isocode'],
- ];
- }
- if (isset($options['language']) && $options['language'] === false) {
- $userInfo['language'] = '';
- }
- if (isset($options['photo']) && $options['photo'] === false) {
- $socialAvatarBlock = '';
- }
- $extraFieldBlock = self::getExtraFieldBlock($userId, true);
- $showLanguageFlag = api_get_configuration_value('social_show_language_flag_in_profile');
- $template->assign('user', $userInfo);
- $template->assign('show_language_flag', $showLanguageFlag);
- $template->assign('extra_info', $extraFieldBlock);
- $template->assign('social_avatar_block', $socialAvatarBlock);
- $template->assign('profile_edition_link', $profileEditionLink);
- //Added the link to export the vCard to the Template
- //If not friend $show_full_profile is False and the user can't see Email Address and Vcard Download Link
- if ($show_full_profile) {
- $template->assign('vcard_user_link', $vCardUserLink);
- }
- if (api_get_setting('gamification_mode') === '1') {
- $gamificationPoints = GamificationUtils::getTotalUserPoints(
- $userId,
- $userInfo['status']
- );
- $template->assign('gamification_points', $gamificationPoints);
- }
- $chatEnabled = api_is_global_chat_enabled();
- if (isset($options['chat']) && $options['chat'] === false) {
- $chatEnabled = '';
- }
- $template->assign('chat_enabled', $chatEnabled);
- $template->assign('user_relation', $userRelationType);
- $template->assign('user_relation_type_friend', USER_RELATION_TYPE_FRIEND);
- $template->assign('show_full_profile', $show_full_profile);
- $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 = self::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 .= ' <span><a href="friends.php">'.get_lang('SeeAll').'</a></span>';
- } else {
- $friendHtml .= ' <span>'
- .'<a href="'.api_get_path(WEB_CODE_PATH).'social/profile_friends_and_groups.inc.php'
- .'?view=friends&height=390&width=610&user_id='.$user_id.'"'
- .'class="ajax" data-title="'.get_lang('SeeAll').'" title="'.get_lang('SeeAll').'" >'.get_lang('SeeAll').'</a></span>';
- }
- }
- $friendHtml .= '<ul class="nav nav-list">';
- $j = 1;
- for ($k = 0; $k < $number_friends; $k++) {
- if ($j > $number_of_images) {
- break;
- }
- if (isset($friends[$k])) {
- $friend = $friends[$k];
- $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
- $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
- if ($user_info_friend['user_is_online']) {
- $statusIcon = Display::span('', ['class' => 'online_user_in_text']);
- } else {
- $statusIcon = Display::span('', ['class' => 'offline_user_in_text']);
- }
- $friendHtml .= '<li>';
- $friendHtml .= '<div>';
- // the height = 92 must be the same in the image_friend_network span style in default.css
- $friends_profile = UserManager::getUserPicture(
- $friend['friend_user_id'],
- USER_IMAGE_SIZE_SMALL
- );
- $friendHtml .= '<img src="'.$friends_profile.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'"/>';
- $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared;
- $friendHtml .= $statusIcon.'<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'">'.$name_user.'</a>';
- $friendHtml .= '</div>';
- $friendHtml .= '</li>';
- }
- $j++;
- }
- $friendHtml .= '</ul>';
- } else {
- $friendHtml .= '<div class="">'.get_lang('NoFriendsInYourContactList').'<br />
- <a class="btn btn-primary" href="'.api_get_path(WEB_PATH).'whoisonline.php">
- <em class="fa fa-search"></em> '.get_lang('TryAndFindSomeFriends').'</a></div>';
- }
- $friendHtml = Display::panel($friendHtml, get_lang('SocialFriend').' ('.$number_friends.')');
- return $friendHtml;
- }
- /**
- * @param int $user_id
- * @param $link_shared
- * @param bool $showLinkToChat
- *
- * @return string
- */
- public static function listMyFriendsBlock($user_id, $link_shared = '', $showLinkToChat = false)
- {
- //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT
- $friends = self::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
- $numberFriends = count($friends);
- $friendHtml = '';
- if (!empty($numberFriends)) {
- $friendHtml .= '<div class="list-group contact-list">';
- $j = 1;
- usort(
- $friends,
- function ($a, $b) {
- return strcmp($b['user_info']['user_is_online_in_chat'], $a['user_info']['user_is_online_in_chat']);
- }
- );
- foreach ($friends as $friend) {
- if ($j > $numberFriends) {
- break;
- }
- $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
- $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
- $statusIcon = Display::return_icon('statusoffline.png', get_lang('Offline'));
- $status = 0;
- if (!empty($user_info_friend['user_is_online_in_chat'])) {
- $statusIcon = Display::return_icon('statusonline.png', get_lang('Online'));
- $status = 1;
- }
- $friendAvatarMedium = UserManager::getUserPicture(
- $friend['friend_user_id'],
- USER_IMAGE_SIZE_MEDIUM
- );
- $friendAvatarSmall = UserManager::getUserPicture(
- $friend['friend_user_id'],
- USER_IMAGE_SIZE_SMALL
- );
- $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>';
- $relation = self::get_relation_between_contacts(
- $friend['friend_user_id'],
- api_get_user_id()
- );
- if ($showLinkToChat) {
- $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">';
- $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>';
- $friendHtml .= '<span class="status">'.$statusIcon.'</span>';
- } else {
- $link_shared = empty($link_shared) ? '' : '&'.$link_shared;
- $friendHtml .= '<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'" class="list-group-item">';
- $friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>';
- $friendHtml .= '<span class="status">'.$statusIcon.'</span>';
- }
- $friendHtml .= '</a>';
- $j++;
- }
- $friendHtml .= '</div>';
- } else {
- $friendHtml = Display::return_message(get_lang('NoFriendsInYourContactList'), 'warning');
- }
- return $friendHtml;
- }
- /**
- * @return string Get the JS code necessary for social wall to load open graph from URLs.
- */
- public static function getScriptToGetOpenGraph()
- {
- return '<script>
- $(function() {
- $("[name=\'social_wall_new_msg_main\']").on("paste", function(e) {
- $.ajax({
- contentType: "application/x-www-form-urlencoded",
- beforeSend: function() {
- $("[name=\'wall_post_button\']").prop( "disabled", true );
- $(".panel-preview").hide();
- $(".spinner").html("'
- .'<div class=\'text-center\'>'
- .'<em class=\'fa fa-spinner fa-pulse fa-1x\'></em>'
- .'<p>'.get_lang('Loading').' '.get_lang('Preview').'</p>'
- .'</div>'
- .'");
- },
- type: "POST",
- url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=read_url_with_open_graph",
- data: "social_wall_new_msg_main=" + e.originalEvent.clipboardData.getData("text"),
- success: function(response) {
- $("[name=\'wall_post_button\']").prop("disabled", false);
- if (!response == false) {
- $(".spinner").html("");
- $(".panel-preview").show();
- $(".url_preview").html(response);
- $("[name=\'url_content\']").val(response);
- $(".url_preview img").addClass("img-responsive");
- } else {
- $(".spinner").html("");
- }
- }
- });
- });
- });
- </script>';
- }
- /**
- * @param string $urlForm
- *
- * @return string
- */
- public static function getWallForm($urlForm)
- {
- $userId = isset($_GET['u']) ? '?u='.intval($_GET['u']) : '';
- $form = new FormValidator(
- 'social_wall_main',
- 'post',
- $urlForm.$userId,
- null,
- ['enctype' => 'multipart/form-data'],
- FormValidator::LAYOUT_HORIZONTAL
- );
- $socialWallPlaceholder = isset($_GET['u']) ? get_lang('SocialWallWriteNewPostToFriend') : get_lang(
- 'SocialWallWhatAreYouThinkingAbout'
- );
- $form->addTextarea(
- 'social_wall_new_msg_main',
- null,
- [
- 'placeholder' => $socialWallPlaceholder,
- 'cols-size' => [1, 12, 1],
- 'aria-label' => $socialWallPlaceholder,
- ]
- );
- $form->addHtml('<div class="form-group">');
- $form->addHtml('<div class="col-sm-6">');
- $form->addFile('picture', get_lang('UploadFile'), ['custom' => true]);
- $form->addHtml('</div>');
- $form->addHtml('<div class="col-sm-6 "><div class="pull-right">');
- $form->addButtonSend(
- get_lang('Post'),
- 'wall_post_button',
- false,
- [
- 'cols-size' => [1, 10, 1],
- 'custom' => true,
- ]
- );
- $form->addHtml('</div></div>');
- $form->addHtml('</div>');
- $form->addHidden('url_content', '');
- $html = Display::panel($form->returnForm(), get_lang('SocialWall'));
- return $html;
- }
- /**
- * @param int $userId
- * @param int $start
- * @param int $length
- * @param array $threadList
- *
- * @return array
- */
- public static function getMyWallMessages($userId, $start = 0, $length = 10, $threadList = [])
- {
- $userGroup = new UserGroup();
- $groups = $userGroup->get_groups_by_user($userId, [GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_ADMIN]);
- $groupList = [];
- if (!empty($groups)) {
- $groupList = array_column($groups, 'id');
- }
- $friends = self::get_friends($userId, USER_RELATION_TYPE_FRIEND);
- $friendList = [];
- if (!empty($friends)) {
- $friendList = array_column($friends, 'friend_user_id');
- }
- $messages = self::getWallMessages(
- $userId,
- 0,
- $groupList,
- $friendList,
- '',
- $start,
- $length,
- false,
- $threadList
- );
- $countPost = self::getCountWallMessagesByUser($userId, $groupList, $friendList, $threadList);
- $messages = self::formatWallMessages($messages);
- $html = '';
- foreach ($messages as $message) {
- $post = $message['html'];
- $comments = '';
- if (in_array($message['msg_status'], [MESSAGE_STATUS_WALL_POST, MESSAGE_STATUS_PROMOTED])) {
- $comments = self::getWallPostComments($userId, $message);
- }
- $html .= self::wrapPost($message, $post.$comments);
- }
- return [
- 'posts' => $html,
- 'count' => $countPost,
- ];
- }
- /**
- * @param string $message
- * @param string $content
- *
- * @return string
- */
- public static function wrapPost($message, $content)
- {
- $class = '';
- if ($message['msg_status'] === MESSAGE_STATUS_PROMOTED) {
- $class = 'promoted_post';
- }
- return Display::panel($content, '',
- '',
- 'default',
- '',
- 'post_'.$message['id'],
- null,
- $class
- );
- }
- /**
- * @param int $userId
- * @param array $groupList
- * @param array $friendList
- * @param array $threadList
- *
- * @return int
- */
- public static function getCountWallMessagesByUser($userId, $groupList = [], $friendList = [], $threadList = [])
- {
- $count = self::getWallMessages(
- $userId,
- 0,
- $groupList,
- $friendList,
- '',
- 0,
- 0,
- true,
- $threadList
- );
- return $count;
- }
- /**
- * @param int $userId
- *
- * @return string
- */
- public static function getWallMessagesByUser($userId)
- {
- $messages = self::getWallMessages($userId);
- $messages = self::formatWallMessages($messages);
- $html = '';
- foreach ($messages as $message) {
- $post = $message['html'];
- $comments = self::getWallPostComments($userId, $message);
- $html .= self::wrapPost($message, $post.$comments);
- }
- return $html;
- }
- /**
- * Get HTML code block for user skills.
- *
- * @param int $userId The user ID
- * @param string $orientation
- *
- * @return string
- */
- public static function getSkillBlock($userId, $orientation = 'horizontal')
- {
- if (Skill::isAllowed($userId, false) === false) {
- return '';
- }
- $skill = new Skill();
- $ranking = $skill->getUserSkillRanking($userId);
- $template = new Template(null, false, false, false, false, false);
- $template->assign('ranking', $ranking);
- $template->assign('orientation', $orientation);
- $template->assign('skills', $skill->getUserSkillsTable($userId, 0, 0, false)['skills']);
- $template->assign('user_id', $userId);
- $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);
- }
- /**
- * @param int $user_id
- * @param bool $isArray
- *
- * @return string|array
- */
- public static function getExtraFieldBlock($user_id, $isArray = false)
- {
- $fieldVisibility = api_get_configuration_value('profile_fields_visibility');
- $fieldVisibilityKeys = [];
- if (isset($fieldVisibility['options'])) {
- $fieldVisibility = $fieldVisibility['options'];
- $fieldVisibilityKeys = array_keys($fieldVisibility);
- }
- $t_ufo = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS);
- $extra_user_data = UserManager::get_extra_user_data($user_id);
- $extra_information = '';
- if (is_array($extra_user_data) && count($extra_user_data) > 0) {
- $extra_information_value = '';
- $extraField = new ExtraField('user');
- $listType = [];
- $extraFieldItem = [];
- foreach ($extra_user_data as $key => $data) {
- if (empty($data)) {
- continue;
- }
- if (in_array($key, $fieldVisibilityKeys) && $fieldVisibility[$key] === false) {
- continue;
- }
- // Avoiding parameters
- if (in_array(
- $key,
- [
- 'mail_notify_invitation',
- 'mail_notify_message',
- 'mail_notify_group_message',
- ]
- )) {
- continue;
- }
- // get display text, visibility and type from user_field table
- $field_variable = str_replace('extra_', '', $key);
- $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable(
- $field_variable
- );
- if (in_array($extraFieldInfo['variable'], ['skype', 'linkedin_url'])) {
- continue;
- }
- // if is not visible skip
- if ($extraFieldInfo['visible_to_self'] != 1) {
- continue;
- }
- // if is not visible to others skip also
- if ($extraFieldInfo['visible_to_others'] != 1) {
- continue;
- }
- if (is_array($data)) {
- switch ($extraFieldInfo['field_type']) {
- case ExtraField::FIELD_TYPE_RADIO:
- $objEfOption = new ExtraFieldOption('user');
- $value = $data['extra_'.$extraFieldInfo['variable']];
- $optionInfo = $objEfOption->get_field_option_by_field_and_option(
- $extraFieldInfo['id'],
- $value
- );
- if ($optionInfo && isset($optionInfo[0])) {
- $optionInfo = $optionInfo[0];
- $extraFieldItem = [
- 'variable' => $extraFieldInfo['variable'],
- 'label' => ucfirst($extraFieldInfo['display_text']),
- 'value' => $optionInfo['display_text'],
- ];
- } else {
- $extraFieldItem = [
- 'variable' => $extraFieldInfo['variable'],
- 'label' => ucfirst($extraFieldInfo['display_text']),
- 'value' => implode(',', $data),
- ];
- }
- break;
- default:
- $extra_information_value .=
- '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).' '
- .' '.implode(',', $data).'</li>';
- $extraFieldItem = [
- 'variable' => $extraFieldInfo['variable'],
- 'label' => ucfirst($extraFieldInfo['display_text']),
- 'value' => implode(',', $data),
- ];
- break;
- }
- } else {
- switch ($extraFieldInfo['field_type']) {
- case ExtraField::FIELD_TYPE_RADIO:
- $objEfOption = new ExtraFieldOption('user');
- $optionInfo = $objEfOption->get_field_option_by_field_and_option($extraFieldInfo['id'], $extraFieldInfo['value']);
- break;
- case ExtraField::FIELD_TYPE_GEOLOCALIZATION_COORDINATES:
- case ExtraField::FIELD_TYPE_GEOLOCALIZATION:
- $data = explode('::', $data);
- $data = $data[0];
- $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '.$data.'</li>';
- $extraFieldItem = [
- 'variable' => $extraFieldInfo['variable'],
- 'label' => ucfirst($extraFieldInfo['display_text']),
- 'value' => $data,
- ];
- break;
- case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
- $id_options = explode('::', $data);
- $value_options = [];
- // get option display text from user_field_options table
- foreach ($id_options as $id_option) {
- $sql = "SELECT display_text
- FROM $t_ufo
- WHERE id = '$id_option'";
- $res_options = Database::query($sql);
- $row_options = Database::fetch_row($res_options);
- $value_options[] = $row_options[0];
- }
- $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '
- .' '.implode(' ', $value_options).'</li>';
- $extraFieldItem = [
- 'variable' => $extraFieldInfo['variable'],
- 'label' => ucfirst($extraFieldInfo['display_text']),
- 'value' => $value_options,
- ];
- break;
- case ExtraField::FIELD_TYPE_TAG:
- $user_tags = UserManager::get_user_tags($user_id, $extraFieldInfo['id']);
- $tag_tmp = '';
- foreach ($user_tags as $tags) {
- $tag_tmp .= '<a class="label label_tag"'
- .' href="'.api_get_path(WEB_PATH).'main/social/search.php?q='.$tags['tag'].'">'
- .$tags['tag']
- .'</a>';
- }
- if (is_array($user_tags) && count($user_tags) > 0) {
- $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '
- .' '.$tag_tmp.'</li>';
- }
- $extraFieldItem = [
- 'variable' => $extraFieldInfo['variable'],
- 'label' => ucfirst($extraFieldInfo['display_text']),
- 'value' => $tag_tmp,
- ];
- break;
- case ExtraField::FIELD_TYPE_SOCIAL_PROFILE:
- $icon_path = UserManager::get_favicon_from_url($data);
- if (self::verifyUrl($icon_path) == false) {
- break;
- }
- $bottom = '0.2';
- //quick hack for hi5
- $domain = parse_url($icon_path, PHP_URL_HOST);
- if ($domain == 'www.hi5.com' || $domain == 'hi5.com') {
- $bottom = '-0.8';
- }
- $data = '<a href="'.$data.'">'
- .'<img src="'.$icon_path.'" alt="icon"'
- .' style="margin-right:0.5em;margin-bottom:'.$bottom.'em;" />'
- .$extraFieldInfo['display_text']
- .'</a>';
- $extra_information_value .= '<li class="list-group-item">'.$data.'</li>';
- $extraFieldItem = [
- 'variable' => $extraFieldInfo['variable'],
- 'label' => ucfirst($extraFieldInfo['display_text']),
- 'value' => $data,
- ];
- break;
- case ExtraField::FIELD_TYPE_SELECT_WITH_TEXT_FIELD:
- $parsedData = explode('::', $data);
- if (!$parsedData) {
- break;
- }
- $objEfOption = new ExtraFieldOption('user');
- $optionInfo = $objEfOption->get($parsedData[0]);
- $extra_information_value .= '<li class="list-group-item">'
- .$optionInfo['display_text'].': '
- .$parsedData[1].'</li>';
- $extraFieldItem = [
- 'variable' => $extraFieldInfo['variable'],
- 'label' => ucfirst($extraFieldInfo['display_text']),
- 'value' => $parsedData[1],
- ];
- break;
- case ExtraField::FIELD_TYPE_TRIPLE_SELECT:
- $optionIds = explode(';', $data);
- $optionValues = [];
- foreach ($optionIds as $optionId) {
- $objEfOption = new ExtraFieldOption('user');
- $optionInfo = $objEfOption->get($optionId);
- $optionValues[] = $optionInfo['display_text'];
- }
- $extra_information_value .= '<li class="list-group-item">'
- .ucfirst($extraFieldInfo['display_text']).': '
- .implode(' ', $optionValues).'</li>';
- $extraFieldItem = [
- 'variable' => $extraFieldInfo['variable'],
- 'label' => ucfirst($extraFieldInfo['display_text']),
- 'value' => implode(' ', $optionValues),
- ];
- break;
- default:
- // Ofaj
- // Converts "Date of birth" into "age"
- if ($key === 'terms_datedenaissance') {
- $dataArray = date_to_str_ago($data, 'UTC', true);
- $dataToString = isset($dataArray['years']) && !empty($dataArray['years']) ? $dataArray['years'] : 0;
- if (!empty($dataToString)) {
- $data = $dataToString;
- $extraFieldInfo['display_text'] = get_lang('Age');
- }
- }
- $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '.$data.'</li>';
- $extraFieldItem = [
- 'variable' => $extraFieldInfo['variable'],
- 'label' => ucfirst($extraFieldInfo['display_text']),
- 'value' => $data,
- ];
- break;
- }
- }
- $listType[] = $extraFieldItem;
- }
- if ($isArray) {
- return $listType;
- } else {
- // if there are information to show
- if (!empty($extra_information_value)) {
- $extra_information_value = '<ul class="list-group">'.$extra_information_value.'</ul>';
- $extra_information .= Display::panelCollapse(
- get_lang('ExtraInformation'),
- $extra_information_value,
- 'sn-extra-information',
- null,
- 'sn-extra-accordion',
- 'sn-extra-collapse'
- );
- }
- }
- }
- return $extra_information;
- }
- /**
- * @param string $url
- */
- public static function handlePosts($url)
- {
- $friendId = isset($_GET['u']) ? (int) $_GET['u'] : api_get_user_id();
- $url = Security::remove_XSS($url);
- // Main post
- if (!empty($_POST['social_wall_new_msg_main']) || !empty($_FILES['picture']['tmp_name'])) {
- $messageContent = $_POST['social_wall_new_msg_main'];
- if (!empty($_POST['url_content'])) {
- $messageContent = $_POST['social_wall_new_msg_main'].'<br /><br />'.$_POST['url_content'];
- }
- $messageId = self::sendWallMessage(
- api_get_user_id(),
- $friendId,
- $messageContent,
- 0,
- MESSAGE_STATUS_WALL_POST
- );
- if ($messageId && !empty($_FILES['picture']['tmp_name'])) {
- self::sendWallMessageAttachmentFile(
- api_get_user_id(),
- $_FILES['picture'],
- $messageId
- );
- }
- Display::addFlash(Display::return_message(get_lang('MessageSent')));
- header('Location: '.$url);
- exit;
- }
- }
- /**
- * @param int $countPost
- * @param array $htmlHeadXtra
- */
- public static function getScrollJs($countPost, &$htmlHeadXtra)
- {
- // $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php';
- $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php';
- $javascriptDir = api_get_path(LIBRARY_PATH).'javascript/';
- $locale = api_get_language_isocode();
- // Add Jquery scroll pagination plugin
- $htmlHeadXtra[] = api_get_js('jscroll/jquery.jscroll.js');
- // Add Jquery Time ago plugin
- $htmlHeadXtra[] = api_get_asset('jquery-timeago/jquery.timeago.js');
- $timeAgoLocaleDir = $javascriptDir.'jquery-timeago/locales/jquery.timeago.'.$locale.'.js';
- if (file_exists($timeAgoLocaleDir)) {
- $htmlHeadXtra[] = api_get_js('jquery-timeago/locales/jquery.timeago.'.$locale.'.js');
- }
- if ($countPost > self::DEFAULT_WALL_POSTS) {
- $htmlHeadXtra[] = '<script>
- $(function() {
- var container = $("#wallMessages");
- container.jscroll({
- loadingHtml: "<div class=\"well_border\">'.get_lang('Loading').' </div>",
- nextSelector: "a.nextPage:last",
- contentSelector: "",
- callback: timeAgo
- });
- });
- </script>';
- }
- $htmlHeadXtra[] = '<script>
- function deleteMessage(id)
- {
- $.ajax({
- url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id,
- success: function (result) {
- if (result) {
- $("#message_" + id).parent().parent().parent().parent().html(result);
- }
- }
- });
- }
-
- function deleteComment(id)
- {
- $.ajax({
- url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id,
- success: function (result) {
- if (result) {
- $("#message_" + id).parent().parent().parent().html(result);
- }
- }
- });
- }
-
- function submitComment(messageId)
- {
- var data = $("#form_comment_"+messageId).serializeArray();
- $.ajax({
- type : "POST",
- url: "'.$socialAjaxUrl.'?a=send_comment" + "&id=" + messageId,
- data: data,
- success: function (result) {
- if (result) {
- $("#post_" + messageId + " textarea").val("");
- $("#post_" + messageId + " .sub-mediapost").prepend(result);
- $("#post_" + messageId + " .sub-mediapost").append(
- $(\'<div id=result_\' + messageId +\'>'.addslashes(get_lang('Saved')).'</div>\')
- );
-
- $("#result_" + messageId + "").fadeIn("fast", function() {
- $("#result_" + messageId + "").delay(1000).fadeOut("fast", function() {
- $(this).remove();
- });
- });
- }
- }
- });
- }
-
- $(function() {
- timeAgo();
-
- /*$(".delete_message").on("click", function() {
- var id = $(this).attr("id");
- id = id.split("_")[1];
- $.ajax({
- url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id,
- success: function (result) {
- if (result) {
- $("#message_" + id).parent().parent().parent().parent().html(result);
- }
- }
- });
- });
-
-
- $(".delete_comment").on("click", function() {
- var id = $(this).attr("id");
- id = id.split("_")[1];
- $.ajax({
- url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id,
- success: function (result) {
- if (result) {
- $("#message_" + id).parent().parent().parent().html(result);
- }
- }
- });
- });
- */
- });
-
- function timeAgo() {
- $(".timeago").timeago();
- }
- </script>';
- }
- /**
- * @param int $userId
- * @param int $countPost
- *
- * @return string
- */
- public static function getAutoExtendLink($userId, $countPost)
- {
- $userId = (int) $userId;
- $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php';
- $socialAutoExtendLink = '';
- if ($countPost > self::DEFAULT_WALL_POSTS) {
- $socialAutoExtendLink = Display::url(
- get_lang('SeeMore'),
- $socialAjaxUrl.'?u='.$userId.'&a=list_wall_message&start='.
- self::DEFAULT_WALL_POSTS.'&length='.self::DEFAULT_SCROLL_NEW_POST,
- [
- 'class' => 'nextPage next',
- ]
- );
- }
- return $socialAutoExtendLink;
- }
- /**
- * @param int $userId
- *
- * @return array
- */
- public static function getThreadList($userId)
- {
- $forumCourseId = api_get_configuration_value('global_forums_course_id');
- require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
- $threads = [];
- if (!empty($forumCourseId)) {
- $courseInfo = api_get_course_info_by_id($forumCourseId);
- getNotificationsPerUser($userId, true, $forumCourseId);
- $notification = Session::read('forum_notification');
- Session::erase('forum_notification');
- $threadUrlBase = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([
- 'cidReq' => $courseInfo['code'],
- ]).'&';
- if (isset($notification['thread']) && !empty($notification['thread'])) {
- $threadList = array_filter(array_unique($notification['thread']));
- $em = Database::getManager();
- $repo = $em->getRepository('ChamiloCourseBundle:CForumThread');
- foreach ($threadList as $threadId) {
- /** @var \Chamilo\CourseBundle\Entity\CForumThread $thread */
- $thread = $repo->find($threadId);
- if ($thread) {
- $threadUrl = $threadUrlBase.http_build_query([
- 'forum' => $thread->getForumId(),
- 'thread' => $thread->getIid(),
- ]);
- $threads[] = [
- 'id' => $threadId,
- 'url' => Display::url(
- $thread->getThreadTitle(),
- $threadUrl
- ),
- 'name' => Display::url(
- $thread->getThreadTitle(),
- $threadUrl
- ),
- 'description' => '',
- ];
- }
- }
- }
- }
- return $threads;
- }
- /**
- * @param int $userId
- *
- * @return string
- */
- public static function getGroupBlock($userId)
- {
- $threadList = self::getThreadList($userId);
- $userGroup = new UserGroup();
- $forumCourseId = api_get_configuration_value('global_forums_course_id');
- $courseInfo = null;
- if (!empty($forumCourseId)) {
- $courseInfo = api_get_course_info_by_id($forumCourseId);
- }
- $social_group_block = '';
- if (!empty($courseInfo)) {
- if (!empty($threadList)) {
- $social_group_block .= '<div class="list-group">';
- foreach ($threadList as $group) {
- $social_group_block .= ' <li class="list-group-item">';
- $social_group_block .= $group['name'];
- $social_group_block .= '</li>';
- }
- $social_group_block .= '</div>';
- }
- $social_group_block .= Display::url(
- get_lang('SeeAllCommunities'),
- api_get_path(WEB_CODE_PATH).'forum/index.php?cidReq='.$courseInfo['code']
- );
- if (!empty($social_group_block)) {
- $social_group_block = Display::panelCollapse(
- get_lang('MyCommunities'),
- $social_group_block,
- 'sm-groups',
- null,
- 'grups-acordion',
- 'groups-collapse'
- );
- }
- } else {
- // Load my groups
- $results = $userGroup->get_groups_by_user(
- $userId,
- [
- GROUP_USER_PERMISSION_ADMIN,
- GROUP_USER_PERMISSION_READER,
- GROUP_USER_PERMISSION_MODERATOR,
- GROUP_USER_PERMISSION_HRM,
- ]
- );
- $myGroups = [];
- if (!empty($results)) {
- foreach ($results as $result) {
- $id = $result['id'];
- $result['description'] = Security::remove_XSS($result['description'], STUDENT, true);
- $result['name'] = Security::remove_XSS($result['name'], STUDENT, true);
- $group_url = "group_view.php?id=$id";
- $link = Display::url(
- api_ucwords(cut($result['name'], 40, true)),
- $group_url
- );
- $result['name'] = $link;
- $picture = $userGroup->get_picture_group(
- $id,
- $result['picture'],
- null,
- GROUP_IMAGE_SIZE_BIG
- );
- $result['picture'] = '<img class="img-responsive" src="'.$picture['file'].'" />';
- $group_actions = '<div class="group-more"><a class="btn btn-default" href="groups.php?#tab_browse-2">'.
- get_lang('SeeMore').'</a></div>';
- $group_info = '<div class="description"><p>'.cut($result['description'], 120, true)."</p></div>";
- $myGroups[] = [
- 'url' => Display::url(
- $result['picture'],
- $group_url
- ),
- 'name' => $result['name'],
- 'description' => $group_info.$group_actions,
- ];
- }
- $social_group_block .= '<div class="list-group">';
- foreach ($myGroups as $group) {
- $social_group_block .= ' <li class="list-group-item">';
- $social_group_block .= $group['name'];
- $social_group_block .= '</li>';
- }
- $social_group_block .= '</div>';
- $form = new FormValidator(
- 'find_groups_form',
- 'get',
- api_get_path(WEB_CODE_PATH).'social/search.php?search_type=2',
- null,
- null,
- FormValidator::LAYOUT_BOX_NO_LABEL
- );
- $form->addHidden('search_type', 2);
- $form->addText(
- 'q',
- get_lang('Search'),
- false,
- [
- 'aria-label' => get_lang('Search'),
- 'custom' => true,
- 'placeholder' => get_lang('Search'),
- ]
- );
- $social_group_block .= $form->returnForm();
- if (!empty($social_group_block)) {
- $social_group_block = Display::panelCollapse(
- get_lang('MyGroups'),
- $social_group_block,
- 'sm-groups',
- null,
- 'grups-acordion',
- 'groups-collapse'
- );
- }
- }
- }
- return $social_group_block;
- }
- /**
- * Returns the formatted header message post.
- *
- * @param int $authorInfo
- * @param int $receiverInfo
- * @param array $message Message data
- *
- * @return string $html The formatted header message post
- */
- private static function headerMessagePost($authorInfo, $receiverInfo, $message)
- {
- $currentUserId = api_get_user_id();
- $authorId = (int) $authorInfo['user_id'];
- $receiverId = (int) $receiverInfo['user_id'];
- $iconStatus = $authorInfo['icon_status'];
- $date = Display::dateToStringAgoAndLongDate($message['send_date']);
- $avatarAuthor = $authorInfo['avatar'];
- $urlAuthor = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$authorId;
- $nameCompleteAuthor = $authorInfo['complete_name'];
- $urlReceiver = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$receiverId;
- $nameCompleteReceiver = $receiverInfo['complete_name'];
- $htmlReceiver = '';
- if ($authorId !== $receiverId) {
- $htmlReceiver = ' > <a href="'.$urlReceiver.'">'.$nameCompleteReceiver.'</a> ';
- }
- if (!empty($message['group_info'])) {
- $htmlReceiver = ' > <a href="'.$message['group_info']['url'].'">'.$message['group_info']['name'].'</a> ';
- }
- $canEdit = ($currentUserId == $authorInfo['user_id'] || $currentUserId == $receiverInfo['user_id']) && empty($message['group_info']);
- if (!empty($message['thread_id'])) {
- $htmlReceiver = ' > <a href="'.$message['thread_url'].'">'.$message['forum_title'].'</a> ';
- $canEdit = false;
- }
- $postAttachment = self::getPostAttachment($message);
- $html = '<div class="top-mediapost" >';
- $html .= '<div class="pull-right btn-group btn-group-sm">';
- $html .= MessageManager::getLikesButton(
- $message['id'],
- $currentUserId,
- !empty($message['group_info']['id']) ? (int) $message['group_info']['id'] : 0
- );
- if ($canEdit) {
- $htmlDelete = Display::url(
- Display::returnFontAwesomeIcon('trash', '', true),
- 'javascript:void(0)',
- [
- 'id' => 'message_'.$message['id'],
- 'title' => get_lang('SocialMessageDelete'),
- 'onclick' => 'deleteMessage('.$message['id'].')',
- 'class' => 'btn btn-default',
- ]
- );
- $html .= $htmlDelete;
- }
- $html .= '</div>';
- $html .= '<div class="user-image" >';
- $html .= '<a href="'.$urlAuthor.'">
- <img class="avatar-thumb" src="'.$avatarAuthor.'" alt="'.$nameCompleteAuthor.'"></a>';
- $html .= '</div>';
- $html .= '<div class="user-data">';
- $html .= $iconStatus;
- $html .= '<div class="username"><a href="'.$urlAuthor.'">'.$nameCompleteAuthor.'</a>'.$htmlReceiver.'</div>';
- $html .= '<div class="post-date">'.$date.'</div>';
- $html .= '</div>';
- $html .= '<div class="msg-content">';
- if (!empty($postAttachment)) {
- $html .= '<div class="post-attachment thumbnail">';
- $html .= $postAttachment;
- $html .= '</div>';
- }
- $html .= '<div>'.Security::remove_XSS($message['content']).'</div>';
- $html .= '</div>';
- $html .= '</div>'; // end mediaPost
- // Popularity post functionality
- $html .= '<div class="popularity-mediapost"></div>';
- return $html;
- }
- }
|