social.lib.php 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990
  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. $officialCode = '';
  970. if (api_get_setting('show_official_code_whoisonline') == 'true') {
  971. $officialCode .= '<div class="items-user-official-code"><p style="min-height: 30px;" title="'.get_lang('OfficialCode').'">'.$user_info['official_code'].'</p></div>';
  972. }
  973. $img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">';
  974. $url = null;
  975. // Anonymous users can't have access to the profile
  976. if (!api_is_anonymous()) {
  977. if (api_get_setting('allow_social_tool') == 'true') {
  978. $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url;
  979. } else {
  980. $url = '?id='.$uid.$course_url;
  981. }
  982. } else {
  983. $url = null;
  984. }
  985. $name = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>';
  986. $html .= '<div class="col-xs-6 col-md-2">
  987. <div class="items-user">
  988. <div class="items-user-avatar"><a href="'.$url.'">'.$img.'</a></div>
  989. <div class="items-user-name">
  990. '.$name.'
  991. </div>
  992. '.$officialCode.'
  993. <div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div>
  994. </div>
  995. </div>';
  996. }
  997. $counter = $_SESSION['who_is_online_counter'];
  998. if ($wrap) {
  999. $html .= '</div>';
  1000. }
  1001. if (count($user_list) >= 9) {
  1002. $html .= '<div class="col-md-'.$column_size.'">
  1003. <a class="btn btn-large btn-default" id="link_load_more_items" data_link="'.$counter.'" >'.get_lang('More').'</a></div>';
  1004. }
  1005. if ($wrap && $add_row) {
  1006. $html .= '</div>';
  1007. }
  1008. return $html;
  1009. }
  1010. /**
  1011. * Displays the information of an individual user
  1012. * @param int $user_id
  1013. */
  1014. public static function display_individual_user($user_id)
  1015. {
  1016. global $interbreadcrumb;
  1017. $safe_user_id = intval($user_id);
  1018. $currentUserId = api_get_user_id();
  1019. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  1020. $sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id;
  1021. $result = Database::query($sql);
  1022. $html = null;
  1023. if (Database::num_rows($result) == 1) {
  1024. $user_object = Database::fetch_object($result);
  1025. $userInfo = api_get_user_info($user_id);
  1026. $alt = $userInfo['complete_name'].($currentUserId == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  1027. $status = get_status_from_code($user_object->status);
  1028. $interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList'));
  1029. $html .= '<div class ="thumbnail">';
  1030. $fullurl = $userInfo['avatar'];
  1031. $html .= '<img src="'.$fullurl.'" alt="'.$alt.'" />';
  1032. if (!empty($status)) {
  1033. $html .= '<div class="caption">'.$status.'</div>';
  1034. }
  1035. $html .= '</div>';
  1036. if (api_get_setting('show_email_addresses') == 'true') {
  1037. $html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'<br />';
  1038. }
  1039. if ($user_object->competences) {
  1040. $html .= Display::page_subheader(get_lang('MyCompetences'));
  1041. $html .= '<p>'.$user_object->competences.'</p>';
  1042. }
  1043. if ($user_object->diplomas) {
  1044. $html .= Display::page_subheader(get_lang('MyDiplomas'));
  1045. $html .= '<p>'.$user_object->diplomas.'</p>';
  1046. }
  1047. if ($user_object->teach) {
  1048. $html .= Display::page_subheader(get_lang('MyTeach'));
  1049. $html .= '<p>'.$user_object->teach.'</p>';
  1050. }
  1051. SocialManager::display_productions($user_object->user_id);
  1052. if ($user_object->openarea) {
  1053. $html .= Display::page_subheader(get_lang('MyPersonalOpenArea'));
  1054. $html .= '<p>'.$user_object->openarea.'</p>';
  1055. }
  1056. } else {
  1057. $html .= '<div class="actions-title">';
  1058. $html .= get_lang('UsersOnLineList');
  1059. $html .= '</div>';
  1060. }
  1061. return $html;
  1062. }
  1063. /**
  1064. * Display productions in who is online
  1065. * @param int $user_id User id
  1066. */
  1067. public static function display_productions($user_id)
  1068. {
  1069. $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web');
  1070. $sysdir = UserManager::getUserPathById($user_id, 'system');
  1071. $webdir = UserManager::getUserPathById($user_id, 'web');
  1072. if (!is_dir($sysdir)) {
  1073. mkdir($sysdir, api_get_permissions_for_new_directories(), true);
  1074. }
  1075. $productions = UserManager::get_user_productions($user_id);
  1076. if (count($productions) > 0) {
  1077. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  1078. echo '<dd><ul>';
  1079. foreach ($productions as $file) {
  1080. // Only display direct file links to avoid browsing an empty directory
  1081. if (is_file($sysdir.$file) && $file != $webdir_array['file']) {
  1082. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  1083. }
  1084. // Real productions are under a subdirectory by the User's id
  1085. if (is_dir($sysdir.$file)) {
  1086. $subs = scandir($sysdir.$file);
  1087. foreach ($subs as $my => $sub) {
  1088. if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) {
  1089. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  1090. }
  1091. }
  1092. }
  1093. }
  1094. echo '</ul></dd>';
  1095. }
  1096. }
  1097. /**
  1098. * @param string $content
  1099. * @param string $span_count
  1100. * @return string
  1101. */
  1102. public static function social_wrapper_div($content, $span_count)
  1103. {
  1104. $span_count = intval($span_count);
  1105. $html = '<div class="span'.$span_count.'">';
  1106. $html .= '<div class="well_border">';
  1107. $html .= $content;
  1108. $html .= '</div></div>';
  1109. return $html;
  1110. }
  1111. /**
  1112. * Dummy function
  1113. *
  1114. */
  1115. public static function get_plugins($place = SOCIAL_CENTER_PLUGIN)
  1116. {
  1117. $content = '';
  1118. switch ($place) {
  1119. case SOCIAL_CENTER_PLUGIN:
  1120. $social_plugins = array(1, 2);
  1121. if (is_array($social_plugins) && count($social_plugins) > 0) {
  1122. $content.= '<div id="social-plugins">';
  1123. foreach ($social_plugins as $plugin) {
  1124. $content.= '<div class="social-plugin-item">';
  1125. $content.= $plugin;
  1126. $content.= '</div>';
  1127. }
  1128. $content.= '</div>';
  1129. }
  1130. break;
  1131. case SOCIAL_LEFT_PLUGIN:
  1132. break;
  1133. case SOCIAL_RIGHT_PLUGIN:
  1134. break;
  1135. }
  1136. return $content;
  1137. }
  1138. /**
  1139. * Sends a message to someone's wall
  1140. * @param int $userId id of author
  1141. * @param int $friendId id where we send the message
  1142. * @param string $messageContent of the message
  1143. * @param int $messageId id parent
  1144. * @param string $messageStatus status type of message
  1145. * @return boolean
  1146. * @author Yannick Warnier
  1147. */
  1148. public static function sendWallMessage($userId, $friendId, $messageContent, $messageId = 0, $messageStatus = '')
  1149. {
  1150. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1151. $userId = intval($userId);
  1152. $friendId = intval($friendId);
  1153. $messageId = intval($messageId);
  1154. // Just in case we replace the and \n and \n\r while saving in the DB
  1155. $messageContent = str_replace(array("\n", "\n\r"), '<br />', $messageContent);
  1156. $now = api_get_utc_datetime();
  1157. $attributes = array(
  1158. 'user_sender_id' => $userId,
  1159. 'user_receiver_id' => $friendId,
  1160. 'msg_status' => $messageStatus,
  1161. 'send_date' => $now,
  1162. 'title' => '',
  1163. 'content' => $messageContent,
  1164. 'parent_id' => $messageId,
  1165. 'group_id' => 0,
  1166. 'update_date' => $now
  1167. );
  1168. return Database::insert($tblMessage, $attributes);
  1169. }
  1170. /**
  1171. * Send File attachment (jpg,png)
  1172. * @author Anibal Copitan
  1173. * @param int $userId id user
  1174. * @param array $fileAttach
  1175. * @param int $messageId id message (relation with main message)
  1176. * @param string $fileComment description attachment file
  1177. * @return bool
  1178. */
  1179. public static function sendWallMessageAttachmentFile($userId, $fileAttach, $messageId, $fileComment = '')
  1180. {
  1181. $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
  1182. // create directory
  1183. $social = '/social/';
  1184. $pathMessageAttach = UserManager::getUserPathById($userId, 'system').'message_attachments'.$social;
  1185. $safeFileComment = Database::escape_string($fileComment);
  1186. $safeFileName = Database::escape_string($fileAttach['name']);
  1187. $extension = strtolower(substr(strrchr($safeFileName, '.'), 1));
  1188. $allowedTypes = api_get_supported_image_extensions();
  1189. if (!in_array($extension, $allowedTypes)) {
  1190. $flag = false;
  1191. } else {
  1192. $newFileName = uniqid('') . '.' . $extension;
  1193. if (!file_exists($pathMessageAttach)) {
  1194. @mkdir($pathMessageAttach, api_get_permissions_for_new_directories(), true);
  1195. }
  1196. $newPath = $pathMessageAttach . $newFileName;
  1197. if (is_uploaded_file($fileAttach['tmp_name'])) {
  1198. @copy($fileAttach['tmp_name'], $newPath);
  1199. }
  1200. $small = self::resize_picture($newPath, IMAGE_WALL_SMALL_SIZE);
  1201. $medium = self::resize_picture($newPath, IMAGE_WALL_MEDIUM_SIZE);
  1202. $big = new Image($newPath);
  1203. $ok = $small && $small->send_image($pathMessageAttach . IMAGE_WALL_SMALL . '_' . $newFileName) &&
  1204. $medium && $medium->send_image($pathMessageAttach . IMAGE_WALL_MEDIUM .'_' . $newFileName) &&
  1205. $big && $big->send_image($pathMessageAttach . IMAGE_WALL_BIG . '_' . $newFileName);
  1206. // Insert
  1207. $newFileName = $social.$newFileName;
  1208. $params = [
  1209. 'filename' => $safeFileName,
  1210. 'comment' => $safeFileComment,
  1211. 'path' => $newFileName,
  1212. 'message_id' => $messageId,
  1213. 'size' => $fileAttach['size'],
  1214. ];
  1215. Database::insert($tbl_message_attach, $params);
  1216. $flag = true;
  1217. }
  1218. return $flag;
  1219. }
  1220. /**
  1221. * Gets all messages from someone's wall (within specific limits)
  1222. * @param int $userId id of wall shown
  1223. * @param string $messageStatus status wall message
  1224. * @param int|string $parentId id message (Post main)
  1225. * @param date $start Date from which we want to show the messages, in UTC time
  1226. * @param int $limit Limit for the number of parent messages we want to show
  1227. * @param int $offset Wall message query offset
  1228. * @return boolean
  1229. * @author Yannick Warnier
  1230. */
  1231. public static function getWallMessages($userId, $messageStatus, $parentId = '', $start = null, $limit = 10, $offset = 0)
  1232. {
  1233. if (empty($start)) {
  1234. $start = '0000-00-00';
  1235. }
  1236. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1237. $tblMessageAttachment = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
  1238. $userId = intval($userId);
  1239. $start = Database::escape_string($start);
  1240. $limit = intval($limit);
  1241. $sql = "
  1242. SELECT
  1243. id,
  1244. user_sender_id,
  1245. user_receiver_id,
  1246. send_date,
  1247. content,
  1248. parent_id,
  1249. (SELECT ma.path FROM $tblMessageAttachment ma
  1250. WHERE ma.message_id = tm.id ) as path,
  1251. (SELECT ma.filename FROM $tblMessageAttachment ma
  1252. WHERE ma.message_id = tm.id ) as filename
  1253. FROM $tblMessage tm
  1254. WHERE
  1255. user_receiver_id = $userId AND
  1256. send_date > '$start'
  1257. ";
  1258. $sql .= (empty($messageStatus) || is_null($messageStatus)) ? '' : " AND msg_status = '$messageStatus' ";
  1259. $sql .= (empty($parentId) || is_null($parentId)) ? '' : " AND parent_id = '$parentId' ";
  1260. $sql .= " ORDER BY send_date DESC LIMIT $offset, $limit ";
  1261. $messages = array();
  1262. $res = Database::query($sql);
  1263. if (Database::num_rows($res) > 0) {
  1264. while ($row = Database::fetch_array($res)) {
  1265. $messages[] = $row;
  1266. }
  1267. }
  1268. return $messages;
  1269. }
  1270. /**
  1271. * Gets all messages from someone's wall (within specific limits), formatted
  1272. * @param int $userId USER ID of the person's wall
  1273. * @param int $friendId id person
  1274. * @param int $idMessage id message
  1275. * @param string $start Start date (from when we want the messages until today)
  1276. * @param int $limit Limit to the number of messages we want
  1277. * @param int $offset Wall messages offset
  1278. * @return string HTML formatted string to show messages
  1279. */
  1280. public static function getWallMessagesHTML($userId, $friendId, $idMessage, $start = null, $limit = 10, $offset = 0)
  1281. {
  1282. if (empty($start)) {
  1283. $start = '0000-00-00';
  1284. }
  1285. $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId);
  1286. $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL, $idMessage, $start, $limit, $offset);
  1287. $formattedList = '<div class="sub-mediapost">';
  1288. $users = array();
  1289. // The messages are ordered by date descendant, for comments we need ascendant
  1290. krsort($messages);
  1291. foreach ($messages as $message) {
  1292. $date = api_get_local_time($message['send_date']);
  1293. $userIdLoop = $message['user_sender_id'];
  1294. if (!isset($users[$userIdLoop])) {
  1295. $users[$userIdLoop] = api_get_user_info($userIdLoop);
  1296. }
  1297. $nameComplete = api_is_western_name_order()
  1298. ? $users[$userIdLoop]['firstname'] .' ' . $users[$userIdLoop]['lastname']
  1299. : $users[$userIdLoop]['lastname'] . ' ' . $users[$userIdLoop]['firstname'];
  1300. $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop;
  1301. $media = '';
  1302. $media .= '<div class="rep-post">';
  1303. if ($isOwnWall) {
  1304. $media .= '<div class="pull-right deleted-mgs">';
  1305. $media .= '<a title="'.get_lang("SocialMessageDelete").'" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='.
  1306. $message['id'].'">x</a>';
  1307. $media .= '</div>';
  1308. }
  1309. $media .= '<div class="user-image">';
  1310. $media .= '<a href="'.$url.'" ><img src="'. $users[$userIdLoop]['avatar'] .
  1311. '" alt="'.$users[$userIdLoop]['complete_name'].'" class="avatar-thumb"></a>';
  1312. $media .= '</div>';
  1313. $media .= '<div class="user-data">';
  1314. $media .= '<div class="username">' . '<a href="'.$url.'">'.$nameComplete.'</a></div>';
  1315. $media .= '<div class="time timeago" title="'.$date.'">'.$date.'</div>';
  1316. $media .= '</div>';
  1317. $media .= '<div class="msg-content">';
  1318. $media .= '<p>'.Security::remove_XSS($message['content']).'</p>';
  1319. $media .= '</div></div>';
  1320. $formattedList .= $media;
  1321. }
  1322. $formattedList .= '</div>';
  1323. $formattedList .= '<div class="mediapost-form">';
  1324. $formattedList .= '<form name="social_wall_message" method="POST">
  1325. <label for="social_wall_new_msg" class="hide">'.get_lang('SocialWriteNewComment').'</label>
  1326. <input type="hidden" name = "messageId" value="'.$idMessage.'" />
  1327. <textarea placeholder="'.get_lang('SocialWriteNewComment').
  1328. '" name="social_wall_new_msg" rows="1" style="width:80%;" ></textarea>
  1329. <button type="submit" name="social_wall_new_msg_submit"
  1330. class="pull-right btn btn-default" /><em class="fa fa-pencil"></em> '.get_lang('Post').'</button>
  1331. </form>';
  1332. $formattedList .= '</div>';
  1333. return $formattedList;
  1334. }
  1335. /**
  1336. * Gets all user's starting wall messages (within specific limits)
  1337. * @param int $userId User's id
  1338. * @param int $friendId Friend's id
  1339. * @param date $start Start date (from when we want the messages until today)
  1340. * @param int $limit Limit to the number of messages we want
  1341. * @param int $offset Wall messages offset
  1342. * @return array $data return user's starting wall messages along with message extra data
  1343. */
  1344. public static function getWallMessagesPostHTML($userId, $friendId = 0, $start = null, $limit = 10, $offset= 0)
  1345. {
  1346. if (empty($start)) {
  1347. $start = '0000-00-00';
  1348. }
  1349. $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId);
  1350. $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL_POST, null, $start, $limit, $offset);
  1351. $users = array();
  1352. $data = array();
  1353. foreach ($messages as $key => $message) {
  1354. $userIdLoop = $message['user_sender_id'];
  1355. $userFriendIdLoop = $message['user_receiver_id'];
  1356. if (!isset($users[$userIdLoop])) {
  1357. $users[$userIdLoop] = api_get_user_info($userIdLoop);
  1358. }
  1359. if (!isset($users[$userFriendIdLoop])) {
  1360. $users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop);
  1361. }
  1362. $html = '';
  1363. $html .= self::headerMessagePost(
  1364. $message['user_sender_id'],
  1365. $message['user_receiver_id'],
  1366. $users,
  1367. $message,
  1368. $isOwnWall
  1369. );
  1370. $data[$key]['id'] = $message['id'];
  1371. $data[$key]['html'] = $html;
  1372. }
  1373. return $data;
  1374. }
  1375. /**
  1376. * Returns the formatted header message post
  1377. * @param int $authorId Author's id
  1378. * @param int $receiverId Receiver's id
  1379. * @param array $users Author's and receiver's data
  1380. * @param array $message Message data
  1381. * @param boolean $isOwnWall Determines if the author is in its own social wall or not
  1382. * @return string $html The formatted header message post
  1383. */
  1384. private static function headerMessagePost($authorId, $receiverId, $users, $message, $isOwnWall = false)
  1385. {
  1386. $date = api_get_local_time($message['send_date']);
  1387. $avatarAuthor = $users[$authorId]['avatar'];
  1388. $urlAuthor = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$authorId;
  1389. $nameCompleteAuthor = api_get_person_name(
  1390. $users[$authorId]['firstname'],
  1391. $users[$authorId]['lastname']
  1392. );
  1393. $urlReceiver = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$receiverId;
  1394. $nameCompleteReceiver = api_get_person_name(
  1395. $users[$receiverId]['firstname'],
  1396. $users[$receiverId]['lastname']
  1397. );
  1398. $htmlReceiver = '';
  1399. if ($authorId != $receiverId) {
  1400. $htmlReceiver = ' > <a href="'.$urlReceiver.'">' . $nameCompleteReceiver . '</a> ';
  1401. }
  1402. $wallImage = '';
  1403. if (!empty($message['path'])) {
  1404. $imageBig = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_BIG);
  1405. $imageSmall = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_SMALL);
  1406. $wallImage = '<a class="thumbnail ajax" href="'.$imageBig.'"><img src="'.$imageSmall.'"></a>';
  1407. }
  1408. $htmlDelete = '';
  1409. if ($isOwnWall) {
  1410. $htmlDelete .= '<a title="'.get_lang("SocialMessageDelete").'" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='.
  1411. $message['id'].'">x</a>';
  1412. }
  1413. $html = '';
  1414. $html .= '<div class="top-mediapost" >';
  1415. if ($isOwnWall) {
  1416. $html .= '<div class="pull-right deleted-mgs">';
  1417. $html .= $htmlDelete;
  1418. $html .= '</div>';
  1419. }
  1420. $html .= '<div class="user-image" >';
  1421. $html .= '<a href="'.$urlAuthor.'">'.'<img class="avatar-thumb" src="'.$avatarAuthor.'" alt="'.$nameCompleteAuthor.'"></a>';
  1422. $html .= '</div>';
  1423. $html .= '<div class="user-data">';
  1424. $html .= '<div class="username"><a href="'.$urlAuthor.'">'.$nameCompleteAuthor.'</a>'.$htmlReceiver.'</div>';
  1425. $html .= '<div class="time timeago" title="'.$date.'">'.$date.'</div>';
  1426. $html .= '</div>';
  1427. $html .= '<div class="msg-content">';
  1428. $html .= '<div class="img-post">';
  1429. $html .= $wallImage;
  1430. $html .= '</div>';
  1431. $html .= '<p>'. Security::remove_XSS($message['content']).'</p>';
  1432. $html .= '</div>';
  1433. $html .= '</div>'; // end mediaPost
  1434. return $html;
  1435. }
  1436. /**
  1437. * get html data with OpenGrap passing the Url
  1438. * @param $link url
  1439. * @return string data html
  1440. */
  1441. public static function readContentWithOpenGraph($link)
  1442. {
  1443. $graph = OpenGraph::fetch($link);
  1444. if (!$graph) {
  1445. return false;
  1446. }
  1447. $url = $graph->url;
  1448. $image = $graph->image;
  1449. $domain = empty($url) ? parse_url($link) : parse_url($url);
  1450. $domain = $domain['scheme'].'://'.$domain['host'];
  1451. // Trick to verify if the Image Url Exist because of some bad metatag dev
  1452. if (self::verifyUrl($image) == false){
  1453. if (!($image[0] == '/')){
  1454. $domain = $domain . '/';
  1455. }
  1456. $image = $domain . $image;
  1457. }
  1458. $title = $graph->title;
  1459. $html = '<div class="thumbnail">';
  1460. $html .= '<a target="_blank" href="'.$link.'"><h3>'.$title.'</h3>';
  1461. $html .= empty($image) ? '' : '<img alt="" src="'.$image.'" /></a>';
  1462. $html .= empty($graph->description) ? '' : '<p class="description">'.$graph->description.'</p>';
  1463. $html .= '<a href="'.$link.'">'.$link.'</a>';
  1464. $html .= '</div>';
  1465. return $html;
  1466. }
  1467. /**
  1468. * verify if Url Exist - Using Curl
  1469. * @param $uri url
  1470. *
  1471. * @return boolean
  1472. */
  1473. public static function verifyUrl($uri)
  1474. {
  1475. $curl = curl_init($uri);
  1476. curl_setopt($curl, CURLOPT_FAILONERROR, true);
  1477. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  1478. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  1479. curl_setopt($curl, CURLOPT_TIMEOUT, 15);
  1480. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  1481. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  1482. curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  1483. $response = curl_exec($curl);
  1484. curl_close($curl);
  1485. if (!empty($response)) {
  1486. return true;
  1487. } else {
  1488. return false;
  1489. }
  1490. }
  1491. /**
  1492. * Get full image path from a path and a size
  1493. * @param string $path
  1494. * @return string
  1495. */
  1496. private static function getImagePath($path, $size = '')
  1497. {
  1498. $name = '';
  1499. $array = preg_split('#\/#', $path);
  1500. if (isset($array[2]) && !empty($array[2])) {
  1501. if ($size == IMAGE_WALL_SMALL) {
  1502. $name = IMAGE_WALL_SMALL. '_' . $array[2];
  1503. }else if($size == IMAGE_WALL_MEDIUM){
  1504. $name = IMAGE_WALL_MEDIUM. '_' . $array[2];
  1505. }else if($size == IMAGE_WALL_BIG){
  1506. $name = IMAGE_WALL_BIG. '_' . $array[2];
  1507. }else {
  1508. $name = IMAGE_WALL_SMALL. '_' . $array[2];
  1509. }
  1510. $lessImage = str_replace($array[2], '', $path);
  1511. $name = $lessImage . $name;
  1512. }
  1513. return $name;
  1514. }
  1515. /**
  1516. * Delete messages delete logic
  1517. * @param int $id id message to delete.
  1518. * @return bool status query
  1519. */
  1520. public static function deleteMessage($id)
  1521. {
  1522. $id = intval($id);
  1523. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1524. $statusMessage = MESSAGE_STATUS_WALL_DELETE;
  1525. $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' ";
  1526. return Database::query($sql);
  1527. }
  1528. /**
  1529. * Generate the social block for a user
  1530. * @param Template $template
  1531. * @param int $userId The user id
  1532. * @param string $groupBlock Optional. Highlight link possible values:
  1533. * group_add, home, messages, messages_inbox, messages_compose,
  1534. * messages_outbox, invitations, shared_profile, friends, groups, search
  1535. * @param int $groupId Optional. Group ID
  1536. * @return string The HTML code with the social block
  1537. */
  1538. public static function setSocialUserBlock(Template $template, $userId, $groupBlock = '', $groupId = 0, $show_full_profile = true)
  1539. {
  1540. if (api_get_setting('allow_social_tool') != 'true') {
  1541. return '';
  1542. }
  1543. $currentUserId = api_get_user_id();
  1544. $userId = intval($userId);
  1545. $userRelationType = 0;
  1546. $socialAvatarBlock = SocialManager::show_social_avatar_block(
  1547. $groupBlock,
  1548. $groupId,
  1549. $userId
  1550. );
  1551. $profileEditionLink = null;
  1552. if ($currentUserId === $userId) {
  1553. $profileEditionLink = Display::getProfileEditionLink($userId);
  1554. } else {
  1555. $userRelationType = SocialManager::get_relation_between_contacts(
  1556. $currentUserId,
  1557. $userId
  1558. );
  1559. }
  1560. $vCardUserLink = Display::getVCardUserLink($userId);
  1561. $userInfo = api_get_user_info($userId, true, false, true, true);
  1562. $template->assign('user', $userInfo);
  1563. $template->assign('social_avatar_block', $socialAvatarBlock);
  1564. $template->assign('profile_edition_link', $profileEditionLink);
  1565. //Added the link to export the vCard to the Template
  1566. //If not friend $show_full_profile is False and the user can't see Email Address and Vcard Download Link
  1567. if ($show_full_profile) {
  1568. $template->assign('vcard_user_link', $vCardUserLink);
  1569. }
  1570. if (api_get_setting('gamification_mode') === '1') {
  1571. $gamificationPoints = GamificationUtils::getTotalUserPoints(
  1572. $userId,
  1573. $userInfo['status']
  1574. );
  1575. $template->assign('gamification_points', $gamificationPoints);
  1576. }
  1577. $chatEnabled = api_is_global_chat_enabled();
  1578. $template->assign('chat_enabled', $chatEnabled);
  1579. $template->assign('user_relation', $userRelationType);
  1580. $template->assign('user_relation_type_friend', USER_RELATION_TYPE_FRIEND);
  1581. $template->assign('show_full_profile', $show_full_profile);
  1582. $templateName = $template->get_template('social/user_block.tpl');
  1583. if (in_array($groupBlock, ['groups', 'group_edit', 'member_list'])) {
  1584. $templateName = $template->get_template('social/group_block.tpl');
  1585. }
  1586. $template->assign('social_avatar_block', $template->fetch($templateName));
  1587. }
  1588. /**
  1589. * @param int $user_id
  1590. * @param $link_shared
  1591. * @param $show_full_profile
  1592. * @return string
  1593. */
  1594. public static function listMyFriends($user_id, $link_shared, $show_full_profile)
  1595. {
  1596. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT
  1597. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
  1598. $number_of_images = 30;
  1599. $number_friends = count($friends);
  1600. $friendHtml = '';
  1601. if ($number_friends != 0) {
  1602. if ($number_friends > $number_of_images) {
  1603. if (api_get_user_id() == $user_id) {
  1604. $friendHtml.= ' <span><a href="friends.php">'.get_lang('SeeAll').'</a></span>';
  1605. } else {
  1606. $friendHtml.= ' <span>'
  1607. .'<a href="'.api_get_path(WEB_CODE_PATH).'social/profile_friends_and_groups.inc.php'
  1608. .'?view=friends&height=390&width=610&user_id='.$user_id.'"'
  1609. .'class="ajax" data-title="'.get_lang('SeeAll').'" title="'.get_lang('SeeAll').'" >'.get_lang('SeeAll').'</a></span>';
  1610. }
  1611. }
  1612. $friendHtml.= '<ul class="nav nav-list">';
  1613. $j = 1;
  1614. for ($k=0; $k < $number_friends; $k++) {
  1615. if ($j > $number_of_images) break;
  1616. if (isset($friends[$k])) {
  1617. $friend = $friends[$k];
  1618. $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
  1619. $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
  1620. if ($user_info_friend['user_is_online']) {
  1621. $statusIcon = Display::span('', array('class' => 'online_user_in_text'));
  1622. } else {
  1623. $statusIcon = Display::span('', array('class' => 'offline_user_in_text'));
  1624. }
  1625. $friendHtml.= '<li>';
  1626. $friendHtml.= '<div>';
  1627. // the height = 92 must be the same in the image_friend_network span style in default.css
  1628. $friends_profile = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_SMALL);
  1629. $friendHtml.= '<img src="'.$friends_profile.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'"/>';
  1630. $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared;
  1631. $friendHtml.= $statusIcon .'<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '">' . $name_user .'</a>';
  1632. $friendHtml.= '</div>';
  1633. $friendHtml.= '</li>';
  1634. }
  1635. $j++;
  1636. }
  1637. $friendHtml.='</ul>';
  1638. } else {
  1639. $friendHtml.= '<div class="">'.get_lang('NoFriendsInYourContactList').'<br />'
  1640. .'<a class="btn btn-primary" href="'.api_get_path(WEB_PATH).'whoisonline.php"><em class="fa fa-search"></em> '. get_lang('TryAndFindSomeFriends').'</a></div>';
  1641. }
  1642. $friendHtml = Display::panel($friendHtml, get_lang('SocialFriend').' (' . $number_friends . ')' );
  1643. return $friendHtml;
  1644. }
  1645. /**
  1646. * @param int $user_id
  1647. * @param $link_shared
  1648. * @param $show_full_profile
  1649. * @return string
  1650. */
  1651. public static function listMyFriendsBlock($user_id, $link_shared = '', $show_full_profile = '')
  1652. {
  1653. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT
  1654. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
  1655. $number_of_images = 30;
  1656. $number_friends = count($friends);
  1657. $friendHtml = '';
  1658. if ($number_friends != 0) {
  1659. $friendHtml.= '<div class="list-group">';
  1660. $j = 1;
  1661. for ($k=0; $k < $number_friends; $k++) {
  1662. if ($j > $number_of_images) {
  1663. break;
  1664. }
  1665. if (isset($friends[$k])) {
  1666. $friend = $friends[$k];
  1667. $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
  1668. $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
  1669. if ($user_info_friend['user_is_online']) {
  1670. $statusIcon = Display::return_icon('statusonline.png',get_lang('Online'));
  1671. $status=1;
  1672. } else {
  1673. $statusIcon = Display::return_icon('statusoffline.png',get_lang('Offline'));
  1674. $status=0;
  1675. }
  1676. $friendAvatarMedium = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_MEDIUM);
  1677. $friendAvatarSmall = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_SMALL);
  1678. $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>';
  1679. $showLinkToChat = api_is_global_chat_enabled() &&
  1680. $friend['friend_user_id'] != api_get_user_id();
  1681. if ($showLinkToChat){
  1682. $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">';
  1683. $friendHtml .= $friend_avatar.' <span class="username">' . $name_user . '</span>';
  1684. $friendHtml .= '<span class="status">' . $statusIcon . '</span>';
  1685. } else {
  1686. $link_shared = empty($link_shared) ? '' : '&'.$link_shared;
  1687. $friendHtml .= '<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '" class="list-group-item">';
  1688. $friendHtml .= $friend_avatar.' <span class="username-all">' . $name_user . '</span>';
  1689. }
  1690. $friendHtml .= '</a>';
  1691. }
  1692. $j++;
  1693. }
  1694. $friendHtml.='</div>';
  1695. } else {
  1696. $friendHtml.= '<div class="help">'.get_lang('NoFriendsInYourContactList').' '
  1697. .'<a href="'.api_get_path(WEB_PATH).'whoisonline.php"><em class="fa fa-search"></em> '. get_lang('TryAndFindSomeFriends').'</a></div>';
  1698. }
  1699. return $friendHtml;
  1700. }
  1701. /**
  1702. * @return string
  1703. */
  1704. public static function getWallForm($show_full_profile = true)
  1705. {
  1706. if ($show_full_profile) {
  1707. $userId = isset($_GET['u']) ? '?u='.intval($_GET['u']) : '';
  1708. $form = new FormValidator(
  1709. 'social_wall_main',
  1710. 'post',
  1711. api_get_path(WEB_CODE_PATH).'social/profile.php'.$userId,
  1712. null,
  1713. array('enctype' => 'multipart/form-data') ,
  1714. FormValidator::LAYOUT_HORIZONTAL
  1715. );
  1716. $socialWallPlaceholder = isset($_GET['u']) ? get_lang('SocialWallWriteNewPostToFriend') : get_lang('SocialWallWhatAreYouThinkingAbout');
  1717. $form->addTextarea(
  1718. 'social_wall_new_msg_main',
  1719. null,
  1720. [
  1721. 'placeholder' => $socialWallPlaceholder,
  1722. 'cols-size' => [1, 10, 1],
  1723. ]
  1724. );
  1725. $form->addHidden('url_content', '');
  1726. $form->addButtonSend(get_lang('Post'), 'wall_post_button', false, ['cols-size' => [1, 10, 1]]);
  1727. $html = Display::panel($form->returnForm(), get_lang('SocialWall'));
  1728. return $html;
  1729. }
  1730. }
  1731. /**
  1732. * @param int $userId
  1733. * @param int $friendId
  1734. * @return string
  1735. */
  1736. public static function getWallMessagesByUser($userId, $friendId)
  1737. {
  1738. $messages = SocialManager::getWallMessagesPostHTML($userId, $friendId);
  1739. $html = '';
  1740. foreach ($messages as $message) {
  1741. $post = $message['html'];
  1742. $comment = SocialManager::getWallMessagesHTML($userId, $friendId, $message['id']);
  1743. $html .= $post.$comment;
  1744. }
  1745. return $html;
  1746. }
  1747. /**
  1748. * Get HTML code block for user skills
  1749. * @param int $userId The user ID
  1750. * @return string
  1751. */
  1752. public static function getSkillBlock($userId)
  1753. {
  1754. if (api_get_setting('allow_skills_tool') !== 'true') {
  1755. return null;
  1756. }
  1757. $skill = new Skill();
  1758. $ranking = $skill->get_user_skill_ranking($userId);
  1759. $skills = $skill->get_user_skills($userId, true);
  1760. $template = new Template(null, false, false, false, false, false);
  1761. $template->assign('ranking', $ranking);
  1762. $template->assign('skills', $skills);
  1763. $template->assign('user_id', $userId);
  1764. $template->assign(
  1765. 'show_skills_report_link',
  1766. api_is_student() || api_is_student_boss() || api_is_drh()
  1767. );
  1768. $skillBlock = $template->get_template('social/skills_block.tpl');
  1769. return $template->fetch($skillBlock);
  1770. }
  1771. }