social.lib.php 77 KB

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