social.lib.php 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954
  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('.MESSAGE_STATUS_INVITATION_PENDING.', '.MESSAGE_STATUS_INVITATION_ACCEPTED.', '.MESSAGE_STATUS_INVITATION_DENIED.');
  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. * Get user's feeds
  335. * @param int User ID
  336. * @param int Limit of posts per feed
  337. * @return string HTML section with all feeds included
  338. * @author Yannick Warnier
  339. * @since Dokeos 1.8.6.1
  340. */
  341. public static function get_user_feeds($user, $limit = 5)
  342. {
  343. $feed = UserManager::get_extra_user_data_by_field($user, 'rssfeeds');
  344. if (empty($feed)) {
  345. return '';
  346. }
  347. $feeds = explode(';', $feed['rssfeeds']);
  348. if (count($feeds) == 0) {
  349. return '';
  350. }
  351. $res = '';
  352. foreach ($feeds as $url) {
  353. if (empty($url)) {
  354. continue;
  355. }
  356. $channel = Reader::import($url);
  357. $i = 1;
  358. if (!empty($channel)) {
  359. $icon_rss = '';
  360. if (!empty($feed)) {
  361. $icon_rss = Display::url(
  362. Display::return_icon('social_rss.png', '', array(), 22),
  363. Security::remove_XSS($feed['rssfeeds']),
  364. array('target' => '_blank')
  365. );
  366. }
  367. $res .= '<h3 class="title-rss">'.$icon_rss.' '.$channel->getTitle().'</h3>';
  368. $res .= '<div class="rss-items">';
  369. /** @var Rss $item */
  370. foreach ($channel as $item) {
  371. if ($limit >= 0 and $i > $limit) {
  372. break;
  373. }
  374. $res .= '<h4 class="rss-title"><a href="'.$item->getLink().'">'.$item->getTitle().'</a></h4>';
  375. $res .= '<div class="rss-date">'.api_get_local_time($item->getDateCreated()).'</div>';
  376. $res .= '<div class="rss-content"><p>'.$item->getDescription().'</p></div>';
  377. $i++;
  378. }
  379. $res .= '</div>';
  380. }
  381. }
  382. return $res;
  383. }
  384. /**
  385. * Sends invitations to friends
  386. *
  387. * @param int $userId
  388. * @param string $subject
  389. * @param string $content
  390. *
  391. * @return string message invitation
  392. */
  393. public static function sendInvitationToUser($userId, $subject = '', $content = '')
  394. {
  395. $user_info = api_get_user_info($userId);
  396. $success = get_lang('MessageSentTo');
  397. $success.= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']);
  398. if (isset($subject) && isset($content) && isset($userId)) {
  399. $result = MessageManager::send_message($userId, $subject, $content);
  400. if ($result) {
  401. Display::addFlash(
  402. Display::return_message($success, 'normal', false)
  403. );
  404. } else {
  405. Display::addFlash(
  406. Display::return_message(get_lang('ErrorSendingMessage'), 'error', false)
  407. );
  408. }
  409. return false;
  410. } elseif (isset($userId) && !isset($subject)) {
  411. if (isset($userId) && $userId > 0) {
  412. $count = self::send_invitation_friend(
  413. api_get_user_id(),
  414. $userId,
  415. get_lang('Invitation'),
  416. $content
  417. );
  418. if ($count) {
  419. Display::addFlash(
  420. Display::return_message(
  421. api_htmlentities(get_lang('InvitationHasBeenSent')),
  422. 'normal',
  423. false
  424. )
  425. );
  426. } else {
  427. Display::addFlash(
  428. Display::return_message(
  429. api_htmlentities(get_lang('YouAlreadySentAnInvitation')),
  430. 'warning',
  431. false
  432. )
  433. );
  434. }
  435. }
  436. }
  437. }
  438. /**
  439. * Helper functions definition
  440. */
  441. public static function get_logged_user_course_html($my_course, $count)
  442. {
  443. $result = '';
  444. // Table definitions
  445. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  446. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  447. $course_directory = $my_course['course_info']['directory'];
  448. $course_title = $my_course['course_info']['title'];
  449. $course_visibility = $my_course['course_info']['visibility'];
  450. $user_in_course_status = CourseManager::getUserInCourseStatus(
  451. api_get_user_id(),
  452. $my_course['course_info']['real_id']
  453. );
  454. //$valor = api_get_settings_params();
  455. $course_path = api_get_path(SYS_COURSE_PATH).$course_directory; // course path
  456. if (api_get_setting('course_images_in_courses_list') === 'true') {
  457. if (file_exists($course_path.'/course-pic85x85.png')) {
  458. $image = $my_course['course_info']['course_image'];
  459. $imageCourse = Display::img($image, $course_title, array('class'=>'img-course'));
  460. } else {
  461. $imageCourse = Display::return_icon(
  462. 'session_default_small.png',
  463. $course_title,
  464. array('class' => 'img-course')
  465. );
  466. }
  467. } else {
  468. $imageCourse = Display::return_icon('course.png', get_lang('Course'), array('class' => 'img-default'));
  469. }
  470. //display course entry
  471. if (api_get_setting('course_images_in_courses_list') === 'true') {
  472. $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:65px;">';
  473. } else {
  474. $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:44px;">';
  475. }
  476. $result .= $imageCourse;
  477. //show a hyperlink to the course, unless the course is closed and user is not course admin
  478. if ($course_visibility != COURSE_VISIBILITY_HIDDEN &&
  479. ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)
  480. ) {
  481. $result .= '<span class="title">' . $course_title . '<span>';
  482. } else {
  483. $result .= $course_title." ".get_lang('CourseClosed');
  484. }
  485. $result .= '</li>';
  486. $session = '';
  487. if (!empty($my_course['session_name']) && !empty($my_course['id_session'])) {
  488. // Request for the name of the general coach
  489. $sql = 'SELECT lastname, firstname
  490. FROM '.$tbl_session.' ts
  491. LEFT JOIN '.$main_user_table.' tu
  492. ON ts.id_coach = tu.user_id
  493. WHERE ts.id='.(int) $my_course['id_session'].' LIMIT 1';
  494. $rs = Database::query($sql);
  495. $sessioncoach = Database::store_result($rs);
  496. $sessioncoach = $sessioncoach[0];
  497. $session = array();
  498. $session['title'] = $my_course['session_name'];
  499. if ($my_course['access_start_date'] == '0000-00-00') {
  500. $session['dates'] = get_lang('WithoutTimeLimits');
  501. if (api_get_setting('show_session_coach') === 'true') {
  502. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  503. }
  504. } else {
  505. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['access_start_date'].' '.get_lang('To').' '.$my_course['access_end_date'];
  506. if (api_get_setting('show_session_coach') === 'true') {
  507. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  508. }
  509. }
  510. }
  511. $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0;
  512. $output = array(
  513. $my_course['user_course_cat'],
  514. $result,
  515. $my_course['id_session'],
  516. $session
  517. );
  518. return $output;
  519. }
  520. /**
  521. * Shows the avatar block in social pages
  522. *
  523. * @param string $show highlight link possible values:
  524. * group_add,
  525. * home,
  526. * messages,
  527. * messages_inbox,
  528. * messages_compose,
  529. * messages_outbox,
  530. * invitations,
  531. * shared_profile,
  532. * friends,
  533. * groups search
  534. * @param int $group_id
  535. * @param int $user_id
  536. *
  537. */
  538. public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0)
  539. {
  540. if (empty($user_id)) {
  541. $user_id = api_get_user_id();
  542. }
  543. $show_groups = array(
  544. 'groups',
  545. 'group_messages',
  546. 'messages_list',
  547. 'group_add',
  548. 'mygroups',
  549. 'group_edit',
  550. 'member_list',
  551. 'invite_friends',
  552. 'waiting_list',
  553. 'browse_groups',
  554. );
  555. $template = new Template(null, false, false, false, false, false);
  556. if (in_array($show, $show_groups) && !empty($group_id)) {
  557. // Group image
  558. $userGroup = new UserGroup();
  559. $group_info = $userGroup->get($group_id);
  560. $userGroupImage = $userGroup->get_picture_group(
  561. $group_id,
  562. $group_info['picture'],
  563. 128,
  564. GROUP_IMAGE_SIZE_BIG
  565. );
  566. $template->assign('show_group', true);
  567. $template->assign('group_id', $group_id);
  568. $template->assign('user_group_image', $userGroupImage);
  569. //$template->assign('user_group', $group_info);
  570. $template->assign(
  571. 'user_is_group_admin',
  572. $userGroup->is_group_admin(
  573. $group_id,
  574. api_get_user_id()
  575. )
  576. );
  577. } else {
  578. $template->assign('show_group', false);
  579. $template->assign('show_user', true);
  580. $template->assign(
  581. 'user_image',
  582. [
  583. 'big' => UserManager::getUserPicture(
  584. $user_id,
  585. USER_IMAGE_SIZE_BIG
  586. ),
  587. 'normal' => UserManager::getUserPicture(
  588. $user_id,
  589. USER_IMAGE_SIZE_MEDIUM
  590. )
  591. ]
  592. );
  593. }
  594. $skillBlock = $template->get_template('social/avatar_block.tpl');
  595. return $template->fetch($skillBlock);
  596. }
  597. /**
  598. * Shows the right menu of the Social Network tool
  599. *
  600. * @param string $show highlight link possible values:
  601. * group_add,
  602. * home,
  603. * messages,
  604. * messages_inbox,
  605. * messages_compose ,
  606. * messages_outbox,
  607. * invitations,
  608. * shared_profile,
  609. * friends,
  610. * groups search
  611. * @param int $group_id group id
  612. * @param int $user_id user id
  613. * @param bool $show_full_profile show profile or not (show or hide the user image/information)
  614. * @param bool $show_delete_account_button
  615. *
  616. */
  617. public static function show_social_menu(
  618. $show = '',
  619. $group_id = 0,
  620. $user_id = 0,
  621. $show_full_profile = false,
  622. $show_delete_account_button = false
  623. ) {
  624. if (empty($user_id)) {
  625. $user_id = api_get_user_id();
  626. }
  627. $usergroup = new UserGroup();
  628. $show_groups = array(
  629. 'groups',
  630. 'group_messages',
  631. 'messages_list',
  632. 'group_add',
  633. 'mygroups',
  634. 'group_edit',
  635. 'member_list',
  636. 'invite_friends',
  637. 'waiting_list',
  638. 'browse_groups',
  639. );
  640. // get count unread message and total invitations
  641. $count_unread_message = MessageManager::get_number_of_messages(true);
  642. $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null;
  643. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  644. $group_pending_invitations = $usergroup->get_groups_by_user(
  645. api_get_user_id(),
  646. GROUP_USER_PERMISSION_PENDING_INVITATION,
  647. false
  648. );
  649. $group_pending_invitations = count($group_pending_invitations);
  650. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  651. $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : '');
  652. $filesIcon = Display::return_icon('sn-files.png', get_lang('MyFiles'), '', ICON_SIZE_SMALL);
  653. $friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), '', ICON_SIZE_SMALL);
  654. $groupsIcon = Display::return_icon('sn-groups.png', get_lang('SocialGroups'), '', ICON_SIZE_SMALL);
  655. $homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), '', ICON_SIZE_SMALL);
  656. $invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), '', ICON_SIZE_SMALL);
  657. $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), '', ICON_SIZE_SMALL);
  658. $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile'));
  659. $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), '', ICON_SIZE_SMALL);
  660. $html = '';
  661. $active = null;
  662. if (!in_array(
  663. $show,
  664. array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends')
  665. )) {
  666. $links = '<ul class="nav nav-pills nav-stacked">';
  667. $active = $show == 'home' ? 'active' : null;
  668. $links .= '
  669. <li class="home-icon ' . $active . '">
  670. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php">
  671. ' . $homeIcon . ' ' . get_lang('Home') . '
  672. </a>
  673. </li>';
  674. $active = $show == 'messages' ? 'active' : null;
  675. $links .= '
  676. <li class="messages-icon ' . $active . '">
  677. <a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social">
  678. ' . $messagesIcon . ' ' . get_lang('Messages') . $count_unread_message . '
  679. </a>
  680. </li>';
  681. //Invitations
  682. $active = $show == 'invitations' ? 'active' : null;
  683. $links .= '
  684. <li class="invitations-icon ' . $active . '">
  685. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">
  686. ' . $invitationsIcon . ' ' . get_lang('Invitations') . $total_invitations . '
  687. </a>
  688. </li>';
  689. //Shared profile and groups
  690. $active = $show == 'shared_profile' ? 'active' : null;
  691. $links .= '
  692. <li class="shared-profile-icon' . $active . '">
  693. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php">
  694. ' . $sharedProfileIcon . ' ' . get_lang('ViewMySharedProfile') . '
  695. </a>
  696. </li>';
  697. $active = $show == 'friends' ? 'active' : null;
  698. $links .= '
  699. <li class="friends-icon ' . $active . '">
  700. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php">
  701. ' . $friendsIcon . ' ' . get_lang('Friends') . '
  702. </a>
  703. </li>';
  704. $active = $show == 'browse_groups' ? 'active' : null;
  705. $links .= '
  706. <li class="browse-groups-icon ' . $active . '">
  707. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php">
  708. ' . $groupsIcon . ' ' . get_lang('SocialGroups') . '
  709. </a>
  710. </li>';
  711. //Search users
  712. $active = $show == 'search' ? 'active' : null;
  713. $links .= '
  714. <li class="search-icon ' . $active . '">
  715. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php">
  716. ' . $searchIcon . ' ' . get_lang('Search') . '
  717. </a>
  718. </li>';
  719. //My files
  720. $active = $show == 'myfiles' ? 'active' : null;
  721. $myFiles = '
  722. <li class="myfiles-icon ' . $active . '">
  723. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php">
  724. ' . $filesIcon . ' ' . get_lang('MyFiles') . '
  725. </a>
  726. </li>';
  727. if (api_get_setting('allow_my_files') === 'false') {
  728. $myFiles = '';
  729. }
  730. $links .= $myFiles;
  731. $links .='</ul>';
  732. $html .= Display::panelCollapse(
  733. get_lang('SocialNetwork'),
  734. $links,
  735. 'social-network-menu',
  736. null,
  737. 'sn-sidebar',
  738. 'sn-sidebar-collapse'
  739. );
  740. }
  741. if (in_array($show, $show_groups) && !empty($group_id)) {
  742. $html .= $usergroup->show_group_column_information(
  743. $group_id,
  744. api_get_user_id(),
  745. $show
  746. );
  747. }
  748. if ($show == 'shared_profile') {
  749. $links = '<ul class="nav nav-pills nav-stacked">';
  750. // My own profile
  751. if ($show_full_profile && $user_id == intval(api_get_user_id())) {
  752. $links .= '
  753. <li class="home-icon ' . $active . '">
  754. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php">
  755. ' . $homeIcon . ' ' . get_lang('Home') . '
  756. </a>
  757. </li>
  758. <li class="messages-icon ' . $active . '">
  759. <a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social">
  760. ' . $messagesIcon . ' ' . get_lang('Messages') . $count_unread_message . '
  761. </a>
  762. </li>';
  763. $active = $show == 'invitations' ? 'active' : null;
  764. $links .= '
  765. <li class="invitations-icon' . $active . '">
  766. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">
  767. ' . $invitationsIcon . ' ' . get_lang('Invitations') . $total_invitations . '
  768. </a>
  769. </li>';
  770. $links .= '
  771. <li class="shared-profile-icon active">
  772. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php">
  773. ' . $sharedProfileIcon . ' ' . get_lang('ViewMySharedProfile') . '
  774. </a>
  775. </li>
  776. <li class="friends-icon">
  777. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php">
  778. ' . $friendsIcon . ' ' . get_lang('Friends') . '
  779. </a>
  780. </li>
  781. <li class="browse-groups-icon">
  782. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php">
  783. ' . $groupsIcon . ' ' . get_lang('SocialGroups') . '
  784. </a>
  785. </li>';
  786. $active = $show == 'search' ? 'active' : null;
  787. $links .= '
  788. <li class="search-icon ' . $active . '">
  789. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php">
  790. ' . $searchIcon . ' ' . get_lang('Search') . '
  791. </a>
  792. </li>';
  793. $active = $show == 'myfiles' ? 'active' : null;
  794. $myFiles = '
  795. <li class="myfiles-icon ' . $active . '">
  796. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php">
  797. ' . $filesIcon . ' ' . get_lang('MyFiles') . '
  798. </a>
  799. </li>';
  800. if (api_get_setting('allow_my_files') === 'false') {
  801. $myFiles = '';
  802. }
  803. $links .= $myFiles;
  804. }
  805. // My friend profile.
  806. if ($user_id != api_get_user_id()) {
  807. $sendMessageText = get_lang('SendMessage');
  808. $sendMessageIcon = Display::return_icon(
  809. 'new-message.png',
  810. $sendMessageText
  811. );
  812. $sendMesssageUrl = api_get_path(WEB_AJAX_PATH)
  813. . 'user_manager.ajax.php?'
  814. . http_build_query([
  815. 'a' => 'get_user_popup',
  816. 'user_id' => $user_id,
  817. ]);
  818. $links .= '<li>';
  819. $links .= Display::url(
  820. "$sendMessageIcon $sendMessageText",
  821. $sendMesssageUrl,
  822. [
  823. 'class' => 'ajax',
  824. 'title' => $sendMessageText,
  825. 'data-title' => $sendMessageText,
  826. ]
  827. );
  828. $links .= '</li>';
  829. }
  830. // Check if I already sent an invitation message
  831. $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(
  832. api_get_user_id()
  833. );
  834. if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0) {
  835. $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>';
  836. } else {
  837. if (!$show_full_profile) {
  838. $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>';
  839. }
  840. }
  841. $links .= '</ul>';
  842. $html .= Display::panelCollapse(
  843. get_lang('SocialNetwork'),
  844. $links,
  845. 'social-network-menu',
  846. null,
  847. 'sn-sidebar',
  848. 'sn-sidebar-collapse'
  849. );
  850. if ($show_full_profile && $user_id == intval(api_get_user_id())) {
  851. $personal_course_list = UserManager::get_personal_session_course_list($user_id);
  852. $course_list_code = array();
  853. $i = 1;
  854. if (is_array($personal_course_list)) {
  855. foreach ($personal_course_list as $my_course) {
  856. if ($i <= 10) {
  857. $course_list_code[] = array('code' => $my_course['code']);
  858. } else {
  859. break;
  860. }
  861. $i++;
  862. }
  863. // To avoid repeated courses
  864. $course_list_code = array_unique_dimensional($course_list_code);
  865. }
  866. // Announcements
  867. $my_announcement_by_user_id = intval($user_id);
  868. $announcements = array();
  869. foreach ($course_list_code as $course) {
  870. $course_info = api_get_course_info($course['code']);
  871. if (!empty($course_info)) {
  872. $content = AnnouncementManager::get_all_annoucement_by_user_course(
  873. $course_info['code'],
  874. $my_announcement_by_user_id
  875. );
  876. if (!empty($content)) {
  877. $url = Display::url(
  878. Display::return_icon('announcement.png', get_lang('Announcements')).$course_info['name'].' ('.$content['count'].')',
  879. api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$course['code']
  880. );
  881. $announcements[] = Display::tag('li', $url);
  882. }
  883. }
  884. }
  885. if (!empty($announcements)) {
  886. $html .= '<div class="social_menu_items">';
  887. $html .= '<ul>';
  888. foreach ($announcements as $announcement) {
  889. $html .= $announcement;
  890. }
  891. $html .= '</ul>';
  892. $html .= '</div>';
  893. }
  894. }
  895. }
  896. if ($show_delete_account_button) {
  897. $html .= '<div class="panel panel-default"><div class="panel-body">';
  898. $html .= '<ul class="nav nav-pills nav-stacked"><li>';
  899. $url = api_get_path(WEB_CODE_PATH).'auth/unsubscribe_account.php';
  900. $html .= Display::url(
  901. Display::return_icon(
  902. 'delete.png',
  903. get_lang('Unsubscribe'),
  904. array(),
  905. ICON_SIZE_TINY
  906. ).get_lang('Unsubscribe'),
  907. $url
  908. );
  909. $html .= '</li></ul>';
  910. $html .= '</div></div>';
  911. }
  912. $url = api_get_plugin_setting('logintcc', 'sso_url');
  913. $value = new ExtraFieldValue('user');
  914. $data = $value->get_values_by_handler_and_field_variable(api_get_user_id(), 'tcc_hash_key');
  915. $hashKey = $data['value'];
  916. $links = '<ul class="nav nav-pills nav-stacked">';
  917. $links .= '
  918. <li class="home-icon">
  919. <form target="_blank" action="'.$url.'" method="post">
  920. <input type="hidden" id="HashKey" name="HashKey" value="'.$hashKey.'"/>
  921. <input type="submit" value="'.get_lang('TCCConnect').'" class="btn btn-primary"/>
  922. </form>
  923. </li>
  924. </ul>
  925. ';
  926. $html .= Display::panelCollapse(
  927. get_lang('TCCConnection'),
  928. $links,
  929. 'tcc-menu',
  930. null,
  931. 'sn-sidebar-tcc',
  932. 'sn-sidebar-collapse-tcc'
  933. );
  934. return $html;
  935. }
  936. /**
  937. * Displays a sortable table with the list of online users.
  938. * @param array $user_list The list of users to be shown
  939. * @param bool $wrap Whether we want the function to wrap the spans list in a div or not
  940. * @return string HTML block or null if and ID was defined
  941. * @assert (null) === false
  942. */
  943. public static function display_user_list($user_list, $wrap = true)
  944. {
  945. $html = null;
  946. if (isset($_GET['id']) or count($user_list) < 1) {
  947. return false;
  948. }
  949. $course_url = '';
  950. if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  951. $course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
  952. }
  953. foreach ($user_list as $uid) {
  954. $user_info = api_get_user_info($uid, $checkIfUserOnline = true);
  955. $lastname = $user_info['lastname'];
  956. $firstname = $user_info['firstname'];
  957. $completeName = $firstname.', '.$lastname;
  958. $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);
  959. $status_icon_chat = null;
  960. if ($user_info['user_is_online_in_chat'] == 1) {
  961. $status_icon_chat = Display::return_icon('online.png', get_lang('Online'));
  962. } else {
  963. $status_icon_chat = Display::return_icon('offline.png', get_lang('Offline'));
  964. }
  965. $userPicture = $user_info['avatar'];
  966. $officialCode = '';
  967. if (api_get_setting('show_official_code_whoisonline') == 'true') {
  968. $officialCode .= '<div class="items-user-official-code"><p style="min-height: 30px;" title="'.get_lang('OfficialCode').'">'.$user_info['official_code'].'</p></div>';
  969. }
  970. $img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">';
  971. $url = null;
  972. // Anonymous users can't have access to the profile
  973. if (!api_is_anonymous()) {
  974. if (api_get_setting('allow_social_tool') === 'true') {
  975. $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url;
  976. } else {
  977. $url = '?id='.$uid.$course_url;
  978. }
  979. } else {
  980. $url = null;
  981. }
  982. $name = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>';
  983. $html .= '<div class="col-xs-6 col-md-2">
  984. <div class="items-user">
  985. <div class="items-user-avatar"><a href="'.$url.'">'.$img.'</a></div>
  986. <div class="items-user-name">
  987. '.$name.'
  988. </div>
  989. '.$officialCode.'
  990. <div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div>
  991. </div>
  992. </div>';
  993. }
  994. return $html;
  995. }
  996. /**
  997. * Displays the information of an individual user
  998. * @param int $user_id
  999. */
  1000. public static function display_individual_user($user_id)
  1001. {
  1002. global $interbreadcrumb;
  1003. $safe_user_id = intval($user_id);
  1004. $currentUserId = api_get_user_id();
  1005. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  1006. $sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id;
  1007. $result = Database::query($sql);
  1008. $html = null;
  1009. if (Database::num_rows($result) == 1) {
  1010. $user_object = Database::fetch_object($result);
  1011. $userInfo = api_get_user_info($user_id);
  1012. $alt = $userInfo['complete_name'].($currentUserId == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  1013. $status = get_status_from_code($user_object->status);
  1014. $interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList'));
  1015. $html .= '<div class ="thumbnail">';
  1016. $fullurl = $userInfo['avatar'];
  1017. $html .= '<img src="'.$fullurl.'" alt="'.$alt.'" />';
  1018. if (!empty($status)) {
  1019. $html .= '<div class="caption">'.$status.'</div>';
  1020. }
  1021. $html .= '</div>';
  1022. if (api_get_setting('show_email_addresses') == 'true') {
  1023. $html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'<br />';
  1024. }
  1025. if ($user_object->competences) {
  1026. $html .= Display::page_subheader(get_lang('MyCompetences'));
  1027. $html .= '<p>'.$user_object->competences.'</p>';
  1028. }
  1029. if ($user_object->diplomas) {
  1030. $html .= Display::page_subheader(get_lang('MyDiplomas'));
  1031. $html .= '<p>'.$user_object->diplomas.'</p>';
  1032. }
  1033. if ($user_object->teach) {
  1034. $html .= Display::page_subheader(get_lang('MyTeach'));
  1035. $html .= '<p>'.$user_object->teach.'</p>';
  1036. }
  1037. SocialManager::display_productions($user_object->user_id);
  1038. if ($user_object->openarea) {
  1039. $html .= Display::page_subheader(get_lang('MyPersonalOpenArea'));
  1040. $html .= '<p>'.$user_object->openarea.'</p>';
  1041. }
  1042. } else {
  1043. $html .= '<div class="actions-title">';
  1044. $html .= get_lang('UsersOnLineList');
  1045. $html .= '</div>';
  1046. }
  1047. return $html;
  1048. }
  1049. /**
  1050. * Display productions in who is online
  1051. * @param int $user_id User id
  1052. */
  1053. public static function display_productions($user_id)
  1054. {
  1055. $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web');
  1056. $sysdir = UserManager::getUserPathById($user_id, 'system');
  1057. $webdir = UserManager::getUserPathById($user_id, 'web');
  1058. if (!is_dir($sysdir)) {
  1059. mkdir($sysdir, api_get_permissions_for_new_directories(), true);
  1060. }
  1061. $productions = UserManager::get_user_productions($user_id);
  1062. if (count($productions) > 0) {
  1063. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  1064. echo '<dd><ul>';
  1065. foreach ($productions as $file) {
  1066. // Only display direct file links to avoid browsing an empty directory
  1067. if (is_file($sysdir.$file) && $file != $webdir_array['file']) {
  1068. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  1069. }
  1070. // Real productions are under a subdirectory by the User's id
  1071. if (is_dir($sysdir.$file)) {
  1072. $subs = scandir($sysdir.$file);
  1073. foreach ($subs as $my => $sub) {
  1074. if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) {
  1075. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  1076. }
  1077. }
  1078. }
  1079. }
  1080. echo '</ul></dd>';
  1081. }
  1082. }
  1083. /**
  1084. * @param string $content
  1085. * @param string $span_count
  1086. * @return string
  1087. */
  1088. public static function social_wrapper_div($content, $span_count)
  1089. {
  1090. $span_count = intval($span_count);
  1091. $html = '<div class="span'.$span_count.'">';
  1092. $html .= '<div class="well_border">';
  1093. $html .= $content;
  1094. $html .= '</div></div>';
  1095. return $html;
  1096. }
  1097. /**
  1098. * Dummy function
  1099. *
  1100. */
  1101. public static function get_plugins($place = SOCIAL_CENTER_PLUGIN)
  1102. {
  1103. $content = '';
  1104. switch ($place) {
  1105. case SOCIAL_CENTER_PLUGIN:
  1106. $social_plugins = array(1, 2);
  1107. if (is_array($social_plugins) && count($social_plugins) > 0) {
  1108. $content.= '<div id="social-plugins">';
  1109. foreach ($social_plugins as $plugin) {
  1110. $content.= '<div class="social-plugin-item">';
  1111. $content.= $plugin;
  1112. $content.= '</div>';
  1113. }
  1114. $content.= '</div>';
  1115. }
  1116. break;
  1117. case SOCIAL_LEFT_PLUGIN:
  1118. break;
  1119. case SOCIAL_RIGHT_PLUGIN:
  1120. break;
  1121. }
  1122. return $content;
  1123. }
  1124. /**
  1125. * Sends a message to someone's wall
  1126. * @param int $userId id of author
  1127. * @param int $friendId id where we send the message
  1128. * @param string $messageContent of the message
  1129. * @param int $messageId id parent
  1130. * @param string $messageStatus status type of message
  1131. * @return boolean
  1132. * @author Yannick Warnier
  1133. */
  1134. public static function sendWallMessage($userId, $friendId, $messageContent, $messageId = 0, $messageStatus = '')
  1135. {
  1136. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1137. $userId = intval($userId);
  1138. $friendId = intval($friendId);
  1139. $messageId = intval($messageId);
  1140. // Just in case we replace the and \n and \n\r while saving in the DB
  1141. $messageContent = str_replace(array("\n", "\n\r"), '<br />', $messageContent);
  1142. $now = api_get_utc_datetime();
  1143. $attributes = array(
  1144. 'user_sender_id' => $userId,
  1145. 'user_receiver_id' => $friendId,
  1146. 'msg_status' => $messageStatus,
  1147. 'send_date' => $now,
  1148. 'title' => '',
  1149. 'content' => $messageContent,
  1150. 'parent_id' => $messageId,
  1151. 'group_id' => 0,
  1152. 'update_date' => $now
  1153. );
  1154. return Database::insert($tblMessage, $attributes);
  1155. }
  1156. /**
  1157. * Send File attachment (jpg,png)
  1158. * @author Anibal Copitan
  1159. * @param int $userId id user
  1160. * @param array $fileAttach
  1161. * @param int $messageId id message (relation with main message)
  1162. * @param string $fileComment description attachment file
  1163. * @return bool
  1164. */
  1165. public static function sendWallMessageAttachmentFile($userId, $fileAttach, $messageId, $fileComment = '')
  1166. {
  1167. $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
  1168. // create directory
  1169. $social = '/social/';
  1170. $pathMessageAttach = UserManager::getUserPathById($userId, 'system').'message_attachments'.$social;
  1171. $safeFileComment = Database::escape_string($fileComment);
  1172. $safeFileName = Database::escape_string($fileAttach['name']);
  1173. $extension = strtolower(substr(strrchr($safeFileName, '.'), 1));
  1174. $allowedTypes = api_get_supported_image_extensions();
  1175. if (!in_array($extension, $allowedTypes)) {
  1176. $flag = false;
  1177. } else {
  1178. $newFileName = uniqid('') . '.' . $extension;
  1179. if (!file_exists($pathMessageAttach)) {
  1180. @mkdir($pathMessageAttach, api_get_permissions_for_new_directories(), true);
  1181. }
  1182. $newPath = $pathMessageAttach . $newFileName;
  1183. if (is_uploaded_file($fileAttach['tmp_name'])) {
  1184. @copy($fileAttach['tmp_name'], $newPath);
  1185. }
  1186. $small = self::resize_picture($newPath, IMAGE_WALL_SMALL_SIZE);
  1187. $medium = self::resize_picture($newPath, IMAGE_WALL_MEDIUM_SIZE);
  1188. $big = new Image($newPath);
  1189. $ok = $small && $small->send_image($pathMessageAttach . IMAGE_WALL_SMALL . '_' . $newFileName) &&
  1190. $medium && $medium->send_image($pathMessageAttach . IMAGE_WALL_MEDIUM .'_' . $newFileName) &&
  1191. $big && $big->send_image($pathMessageAttach . IMAGE_WALL_BIG . '_' . $newFileName);
  1192. // Insert
  1193. $newFileName = $social.$newFileName;
  1194. $params = [
  1195. 'filename' => $safeFileName,
  1196. 'comment' => $safeFileComment,
  1197. 'path' => $newFileName,
  1198. 'message_id' => $messageId,
  1199. 'size' => $fileAttach['size'],
  1200. ];
  1201. Database::insert($tbl_message_attach, $params);
  1202. $flag = true;
  1203. }
  1204. return $flag;
  1205. }
  1206. /**
  1207. * Gets all messages from someone's wall (within specific limits)
  1208. * @param int $userId id of wall shown
  1209. * @param string $messageStatus status wall message
  1210. * @param int|string $parentId id message (Post main)
  1211. * @param date $start Date from which we want to show the messages, in UTC time
  1212. * @param int $limit Limit for the number of parent messages we want to show
  1213. * @param int $offset Wall message query offset
  1214. * @return boolean
  1215. * @author Yannick Warnier
  1216. */
  1217. public static function getWallMessages($userId, $messageStatus, $parentId = '', $start = null, $limit = 10, $offset = 0)
  1218. {
  1219. if (empty($start)) {
  1220. $start = '0000-00-00';
  1221. }
  1222. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1223. $tblMessageAttachment = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
  1224. $userId = intval($userId);
  1225. $start = Database::escape_string($start);
  1226. $limit = intval($limit);
  1227. $sql = "SELECT
  1228. id,
  1229. user_sender_id,
  1230. user_receiver_id,
  1231. send_date,
  1232. content,
  1233. parent_id,
  1234. (
  1235. SELECT ma.path FROM $tblMessageAttachment ma
  1236. WHERE ma.message_id = tm.id
  1237. ) as path,
  1238. (
  1239. SELECT ma.filename FROM $tblMessageAttachment ma
  1240. WHERE ma.message_id = tm.id
  1241. ) as filename
  1242. FROM $tblMessage tm
  1243. WHERE
  1244. user_receiver_id = $userId AND
  1245. send_date > '$start'
  1246. ";
  1247. $sql .= (empty($messageStatus) || is_null($messageStatus)) ? '' : " AND msg_status = '$messageStatus' ";
  1248. $sql .= (empty($parentId) || is_null($parentId)) ? '' : " AND parent_id = '$parentId' ";
  1249. $sql .= " ORDER BY send_date DESC LIMIT $offset, $limit ";
  1250. $messages = array();
  1251. $res = Database::query($sql);
  1252. if (Database::num_rows($res) > 0) {
  1253. while ($row = Database::fetch_array($res)) {
  1254. $messages[] = $row;
  1255. }
  1256. }
  1257. return $messages;
  1258. }
  1259. /**
  1260. * Gets all messages from someone's wall (within specific limits), formatted
  1261. * @param int $userId USER ID of the person's wall
  1262. * @param int $friendId id person
  1263. * @param int $idMessage id message
  1264. * @param string $start Start date (from when we want the messages until today)
  1265. * @param int $limit Limit to the number of messages we want
  1266. * @param int $offset Wall messages offset
  1267. * @return string HTML formatted string to show messages
  1268. */
  1269. public static function getWallMessagesHTML($userId, $friendId, $idMessage, $start = null, $limit = 10, $offset = 0)
  1270. {
  1271. if (empty($start)) {
  1272. $start = '0000-00-00';
  1273. }
  1274. $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId);
  1275. $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL, $idMessage, $start, $limit, $offset);
  1276. $formattedList = '<div class="sub-mediapost">';
  1277. $users = array();
  1278. // The messages are ordered by date descendant, for comments we need ascendant
  1279. krsort($messages);
  1280. foreach ($messages as $message) {
  1281. $date = api_get_local_time($message['send_date']);
  1282. $userIdLoop = $message['user_sender_id'];
  1283. if (!isset($users[$userIdLoop])) {
  1284. $users[$userIdLoop] = api_get_user_info($userIdLoop);
  1285. }
  1286. $nameComplete = api_is_western_name_order()
  1287. ? $users[$userIdLoop]['firstname'] .' ' . $users[$userIdLoop]['lastname']
  1288. : $users[$userIdLoop]['lastname'] . ' ' . $users[$userIdLoop]['firstname'];
  1289. $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop;
  1290. $media = '';
  1291. $media .= '<div class="rep-post">';
  1292. $media .= '<div class="col-md-2 col-xs-2 social-post-answers">';
  1293. $media .= '<div class="user-image pull-right">';
  1294. $media .= '<a href="'.$url.'" ><img src="'. $users[$userIdLoop]['avatar'] .
  1295. '" alt="'.$users[$userIdLoop]['complete_name'].'" class="avatar-thumb"></a>';
  1296. $media .= '</div>';
  1297. $media .= '</div>';
  1298. $media .= '<div class="col-md-9 col-xs-9 social-post-answers">';
  1299. $media .= '<div class="user-data">';
  1300. $media .= '<div class="username">' . '<a href="'.$url.'">'.$nameComplete.'</a> <span>'.Security::remove_XSS($message['content']).'</span></div>';
  1301. $media .= '<div class="time timeago" title="'.$date.'">'.$date.'</div>';
  1302. $media .= '<br />';
  1303. $media .= '</div>';
  1304. $media .= '</div>';
  1305. $media .= '</div>';
  1306. if ($isOwnWall) {
  1307. $media .= '<div class="col-md-1 col-xs-1 social-post-answers">';
  1308. $media .= '<div class="pull-right deleted-mgs">';
  1309. $media .= '<a title="'.get_lang("SocialMessageDelete").'" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='.
  1310. $message['id'].'">x</a>';
  1311. $media .= '</div>';
  1312. $media .= '</div>';
  1313. }
  1314. $formattedList .= $media;
  1315. }
  1316. $formattedList .= '</div>';
  1317. $formattedList .= '<div class="mediapost-form">';
  1318. $formattedList .= '<form name="social_wall_message" method="POST">
  1319. <label for="social_wall_new_msg" class="hide">'.get_lang('SocialWriteNewComment').'</label>
  1320. <input type="hidden" name = "messageId" value="'.$idMessage.'" />
  1321. <textarea placeholder="'.get_lang('SocialWriteNewComment').
  1322. '" name="social_wall_new_msg" rows="1" style="width:80%;" ></textarea>
  1323. <button type="submit" name="social_wall_new_msg_submit"
  1324. class="pull-right btn btn-default" /><em class="fa fa-pencil"></em> '.get_lang('Post').'</button>
  1325. </form>';
  1326. $formattedList .= '</div>';
  1327. return $formattedList;
  1328. }
  1329. /**
  1330. * Gets all user's starting wall messages (within specific limits)
  1331. * @param int $userId User's id
  1332. * @param int $friendId Friend's id
  1333. * @param date $start Start date (from when we want the messages until today)
  1334. * @param int $limit Limit to the number of messages we want
  1335. * @param int $offset Wall messages offset
  1336. * @return array $data return user's starting wall messages along with message extra data
  1337. */
  1338. public static function getWallMessagesPostHTML($userId, $friendId = 0, $start = null, $limit = 10, $offset= 0)
  1339. {
  1340. if (empty($start)) {
  1341. $start = '0000-00-00';
  1342. }
  1343. $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId);
  1344. $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL_POST, null, $start, $limit, $offset);
  1345. $users = array();
  1346. $data = array();
  1347. foreach ($messages as $key => $message) {
  1348. $userIdLoop = $message['user_sender_id'];
  1349. $userFriendIdLoop = $message['user_receiver_id'];
  1350. if (!isset($users[$userIdLoop])) {
  1351. $users[$userIdLoop] = api_get_user_info($userIdLoop);
  1352. }
  1353. if (!isset($users[$userFriendIdLoop])) {
  1354. $users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop);
  1355. }
  1356. $html = '';
  1357. $html .= self::headerMessagePost(
  1358. $message['user_sender_id'],
  1359. $message['user_receiver_id'],
  1360. $users,
  1361. $message,
  1362. $isOwnWall
  1363. );
  1364. $data[$key]['id'] = $message['id'];
  1365. $data[$key]['html'] = $html;
  1366. }
  1367. return $data;
  1368. }
  1369. /**
  1370. * Returns the formatted header message post
  1371. * @param int $authorId Author's id
  1372. * @param int $receiverId Receiver's id
  1373. * @param array $users Author's and receiver's data
  1374. * @param array $message Message data
  1375. * @param boolean $isOwnWall Determines if the author is in its own social wall or not
  1376. * @return string $html The formatted header message post
  1377. */
  1378. private static function headerMessagePost($authorId, $receiverId, $users, $message, $isOwnWall = false)
  1379. {
  1380. $date = api_get_local_time($message['send_date']);
  1381. $avatarAuthor = $users[$authorId]['avatar'];
  1382. $urlAuthor = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$authorId;
  1383. $nameCompleteAuthor = api_get_person_name(
  1384. $users[$authorId]['firstname'],
  1385. $users[$authorId]['lastname']
  1386. );
  1387. $urlReceiver = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$receiverId;
  1388. $nameCompleteReceiver = api_get_person_name(
  1389. $users[$receiverId]['firstname'],
  1390. $users[$receiverId]['lastname']
  1391. );
  1392. $htmlReceiver = '';
  1393. if ($authorId != $receiverId) {
  1394. $htmlReceiver = ' > <a href="'.$urlReceiver.'">' . $nameCompleteReceiver . '</a> ';
  1395. }
  1396. $wallImage = '';
  1397. if (!empty($message['path'])) {
  1398. $imageBig = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_BIG);
  1399. $imageSmall = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_SMALL);
  1400. $wallImage = '<a class="thumbnail ajax" href="'.$imageBig.'"><img src="'.$imageSmall.'"></a>';
  1401. }
  1402. $htmlDelete = '';
  1403. if ($isOwnWall) {
  1404. $htmlDelete .= '<a title="'.get_lang("SocialMessageDelete").'" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='.
  1405. $message['id'].'">x</a>';
  1406. }
  1407. $html = '';
  1408. $html .= '<div class="top-mediapost" >';
  1409. if ($isOwnWall) {
  1410. $html .= '<div class="pull-right deleted-mgs">';
  1411. $html .= $htmlDelete;
  1412. $html .= '</div>';
  1413. }
  1414. $html .= '<div class="user-image" >';
  1415. $html .= '<a href="'.$urlAuthor.'">'.'<img class="avatar-thumb" src="'.$avatarAuthor.'" alt="'.$nameCompleteAuthor.'"></a>';
  1416. $html .= '</div>';
  1417. $html .= '<div class="user-data">';
  1418. $html .= '<div class="username"><a href="'.$urlAuthor.'">'.$nameCompleteAuthor.'</a>'.$htmlReceiver.'</div>';
  1419. $html .= '<div class="time timeago" title="'.$date.'">'.$date.'</div>';
  1420. $html .= '</div>';
  1421. $html .= '<div class="msg-content">';
  1422. $html .= '<div class="img-post">';
  1423. $html .= $wallImage;
  1424. $html .= '</div>';
  1425. $html .= '<p>'. Security::remove_XSS($message['content']).'</p>';
  1426. $html .= '</div>';
  1427. $html .= '</div>'; // end mediaPost
  1428. // Popularity post functionality
  1429. $html .= '<div class="popularity-mediapost"></div>';
  1430. return $html;
  1431. }
  1432. /**
  1433. * get html data with OpenGrap passing the Url
  1434. * @param $link url
  1435. * @return string data html
  1436. */
  1437. public static function readContentWithOpenGraph($link)
  1438. {
  1439. if (strpos($link, "://") === false && substr($link, 0, 1) != "/") {
  1440. $link = "http://".$link;
  1441. }
  1442. $graph = OpenGraph::fetch($link);
  1443. $link = parse_url($link);
  1444. $host = $link['host'] ? strtoupper($link['host']) : $link['path'];
  1445. if (!$graph) {
  1446. return false;
  1447. }
  1448. $url = $graph->url;
  1449. $image = $graph->image;
  1450. $description = $graph->description;
  1451. $title = $graph->title;
  1452. $html = '<div class="thumbnail social-thumbnail">';
  1453. $html .= empty($image) ? '' : '<a target="_blank" href="'.$url.'"><img class="img-responsive social-image" src="'.$image.'" /></a>';
  1454. $html .= '<div class="social-description">';
  1455. $html .= '<a target="_blank" href="'.$url.'"><h5 class="social-title"><b>'.$title.'</b></h5></a>';
  1456. $html .= empty($description) ? '' : '<span>'.$description.'</span>';
  1457. $html .= empty($host) ? '' : '<p>'.$host.'</p>';
  1458. $html .= '</div>';
  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. * Delete messages delete logic
  1488. * @param int $id id message to delete.
  1489. * @return bool status query
  1490. */
  1491. public static function deleteMessage($id)
  1492. {
  1493. $id = intval($id);
  1494. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1495. $statusMessage = MESSAGE_STATUS_WALL_DELETE;
  1496. $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' ";
  1497. return Database::query($sql);
  1498. }
  1499. /**
  1500. * Generate the social block for a user
  1501. * @param Template $template
  1502. * @param int $userId The user id
  1503. * @param string $groupBlock Optional. Highlight link possible values:
  1504. * group_add, home, messages, messages_inbox, messages_compose,
  1505. * messages_outbox, invitations, shared_profile, friends, groups, search
  1506. * @param int $groupId Optional. Group ID
  1507. * @return string The HTML code with the social block
  1508. */
  1509. public static function setSocialUserBlock(
  1510. Template $template,
  1511. $userId,
  1512. $groupBlock = '',
  1513. $groupId = 0,
  1514. $show_full_profile = true
  1515. ) {
  1516. if (api_get_setting('allow_social_tool') != 'true') {
  1517. return '';
  1518. }
  1519. $currentUserId = api_get_user_id();
  1520. $userId = intval($userId);
  1521. $userRelationType = 0;
  1522. $socialAvatarBlock = SocialManager::show_social_avatar_block(
  1523. $groupBlock,
  1524. $groupId,
  1525. $userId
  1526. );
  1527. $profileEditionLink = null;
  1528. if ($currentUserId === $userId) {
  1529. $profileEditionLink = Display::getProfileEditionLink($userId);
  1530. } else {
  1531. $userRelationType = SocialManager::get_relation_between_contacts(
  1532. $currentUserId,
  1533. $userId
  1534. );
  1535. }
  1536. $vCardUserLink = Display::getVCardUserLink($userId);
  1537. $userInfo = api_get_user_info($userId, true, false, true, true);
  1538. $template->assign('user', $userInfo);
  1539. $template->assign('social_avatar_block', $socialAvatarBlock);
  1540. $template->assign('profile_edition_link', $profileEditionLink);
  1541. //Added the link to export the vCard to the Template
  1542. //If not friend $show_full_profile is False and the user can't see Email Address and Vcard Download Link
  1543. if ($show_full_profile) {
  1544. $template->assign('vcard_user_link', $vCardUserLink);
  1545. }
  1546. if (api_get_setting('gamification_mode') === '1') {
  1547. $gamificationPoints = GamificationUtils::getTotalUserPoints(
  1548. $userId,
  1549. $userInfo['status']
  1550. );
  1551. $template->assign('gamification_points', $gamificationPoints);
  1552. }
  1553. $chatEnabled = api_is_global_chat_enabled();
  1554. $template->assign('chat_enabled', $chatEnabled);
  1555. $template->assign('user_relation', $userRelationType);
  1556. $template->assign('user_relation_type_friend', USER_RELATION_TYPE_FRIEND);
  1557. $template->assign('show_full_profile', $show_full_profile);
  1558. $templateName = $template->get_template('social/user_block.tpl');
  1559. if (in_array($groupBlock, ['groups', 'group_edit', 'member_list'])) {
  1560. $templateName = $template->get_template('social/group_block.tpl');
  1561. }
  1562. $template->assign('social_avatar_block', $template->fetch($templateName));
  1563. }
  1564. /**
  1565. * @param int $user_id
  1566. * @param $link_shared
  1567. * @param $show_full_profile
  1568. * @return string
  1569. */
  1570. public static function listMyFriends($user_id, $link_shared, $show_full_profile)
  1571. {
  1572. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT
  1573. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
  1574. $number_of_images = 30;
  1575. $number_friends = count($friends);
  1576. $friendHtml = '';
  1577. if ($number_friends != 0) {
  1578. if ($number_friends > $number_of_images) {
  1579. if (api_get_user_id() == $user_id) {
  1580. $friendHtml.= ' <span><a href="friends.php">'.get_lang('SeeAll').'</a></span>';
  1581. } else {
  1582. $friendHtml.= ' <span>'
  1583. .'<a href="'.api_get_path(WEB_CODE_PATH).'social/profile_friends_and_groups.inc.php'
  1584. .'?view=friends&height=390&width=610&user_id='.$user_id.'"'
  1585. .'class="ajax" data-title="'.get_lang('SeeAll').'" title="'.get_lang('SeeAll').'" >'.get_lang('SeeAll').'</a></span>';
  1586. }
  1587. }
  1588. $friendHtml.= '<ul class="nav nav-list">';
  1589. $j = 1;
  1590. for ($k=0; $k < $number_friends; $k++) {
  1591. if ($j > $number_of_images) break;
  1592. if (isset($friends[$k])) {
  1593. $friend = $friends[$k];
  1594. $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
  1595. $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
  1596. if ($user_info_friend['user_is_online']) {
  1597. $statusIcon = Display::span('', array('class' => 'online_user_in_text'));
  1598. } else {
  1599. $statusIcon = Display::span('', array('class' => 'offline_user_in_text'));
  1600. }
  1601. $friendHtml.= '<li>';
  1602. $friendHtml.= '<div>';
  1603. // the height = 92 must be the same in the image_friend_network span style in default.css
  1604. $friends_profile = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_SMALL);
  1605. $friendHtml.= '<img src="'.$friends_profile.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'"/>';
  1606. $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared;
  1607. $friendHtml.= $statusIcon .'<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '">' . $name_user .'</a>';
  1608. $friendHtml.= '</div>';
  1609. $friendHtml.= '</li>';
  1610. }
  1611. $j++;
  1612. }
  1613. $friendHtml.='</ul>';
  1614. } else {
  1615. $friendHtml.= '<div class="">'.get_lang('NoFriendsInYourContactList').'<br />'
  1616. .'<a class="btn btn-primary" href="'.api_get_path(WEB_PATH).'whoisonline.php"><em class="fa fa-search"></em> '. get_lang('TryAndFindSomeFriends').'</a></div>';
  1617. }
  1618. $friendHtml = Display::panel($friendHtml, get_lang('SocialFriend').' (' . $number_friends . ')' );
  1619. return $friendHtml;
  1620. }
  1621. /**
  1622. * @param int $user_id
  1623. * @param $link_shared
  1624. * @param $show_full_profile
  1625. * @return string
  1626. */
  1627. public static function listMyFriendsBlock($user_id, $link_shared = '', $show_full_profile = '')
  1628. {
  1629. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT
  1630. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
  1631. $number_of_images = 30;
  1632. $number_friends = count($friends);
  1633. $friendHtml = '';
  1634. if ($number_friends != 0) {
  1635. $friendHtml.= '<div class="list-group">';
  1636. $j = 1;
  1637. for ($k=0; $k < $number_friends; $k++) {
  1638. if ($j > $number_of_images) {
  1639. break;
  1640. }
  1641. if (isset($friends[$k])) {
  1642. $friend = $friends[$k];
  1643. $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
  1644. $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
  1645. if ($user_info_friend['user_is_online']) {
  1646. $statusIcon = Display::return_icon('statusonline.png',get_lang('Online'));
  1647. $status=1;
  1648. } else {
  1649. $statusIcon = Display::return_icon('statusoffline.png',get_lang('Offline'));
  1650. $status=0;
  1651. }
  1652. $friendAvatarMedium = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_MEDIUM);
  1653. $friendAvatarSmall = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_SMALL);
  1654. $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>';
  1655. $showLinkToChat = api_is_global_chat_enabled() &&
  1656. $friend['friend_user_id'] != api_get_user_id();
  1657. if ($showLinkToChat){
  1658. $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">';
  1659. $friendHtml .= $friend_avatar.' <span class="username">' . $name_user . '</span>';
  1660. $friendHtml .= '<span class="status">' . $statusIcon . '</span>';
  1661. } else {
  1662. $link_shared = empty($link_shared) ? '' : '&'.$link_shared;
  1663. $friendHtml .= '<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '" class="list-group-item">';
  1664. $friendHtml .= $friend_avatar.' <span class="username-all">' . $name_user . '</span>';
  1665. }
  1666. $friendHtml .= '</a>';
  1667. }
  1668. $j++;
  1669. }
  1670. $friendHtml.='</div>';
  1671. } else {
  1672. $friendHtml.= '<div class="help">'.get_lang('NoFriendsInYourContactList').' '
  1673. .'<a href="'.api_get_path(WEB_PATH).'whoisonline.php"><em class="fa fa-search"></em> '. get_lang('TryAndFindSomeFriends').'</a></div>';
  1674. }
  1675. return $friendHtml;
  1676. }
  1677. /**
  1678. * @return string
  1679. */
  1680. public static function getWallForm($show_full_profile = true)
  1681. {
  1682. if ($show_full_profile) {
  1683. $userId = isset($_GET['u']) ? '?u='.intval($_GET['u']) : '';
  1684. $form = new FormValidator(
  1685. 'social_wall_main',
  1686. 'post',
  1687. api_get_path(WEB_CODE_PATH).'social/profile.php'.$userId,
  1688. null,
  1689. array('enctype' => 'multipart/form-data') ,
  1690. FormValidator::LAYOUT_HORIZONTAL
  1691. );
  1692. $socialWallPlaceholder = isset($_GET['u']) ? get_lang('SocialWallWriteNewPostToFriend') : get_lang('SocialWallWhatAreYouThinkingAbout');
  1693. $form->addTextarea(
  1694. 'social_wall_new_msg_main',
  1695. null,
  1696. [
  1697. 'placeholder' => $socialWallPlaceholder,
  1698. 'cols-size' => [1, 10, 1],
  1699. ]
  1700. );
  1701. $form->addHidden('url_content', '');
  1702. $form->addButtonSend(get_lang('Post'), 'wall_post_button', false, ['cols-size' => [1, 10, 1]]);
  1703. $html = Display::panel($form->returnForm(), get_lang('SocialWall'));
  1704. return $html;
  1705. }
  1706. }
  1707. /**
  1708. * @param int $userId
  1709. * @param int $friendId
  1710. * @return string
  1711. */
  1712. public static function getWallMessagesByUser($userId, $friendId)
  1713. {
  1714. $messages = SocialManager::getWallMessagesPostHTML($userId, $friendId);
  1715. $html = '';
  1716. foreach ($messages as $message) {
  1717. $post = $message['html'];
  1718. $comment = SocialManager::getWallMessagesHTML($userId, $friendId, $message['id']);
  1719. $html .= Display::panel($post.$comment, '');
  1720. }
  1721. return $html;
  1722. }
  1723. /**
  1724. * Get HTML code block for user skills
  1725. * @param int $userId The user ID
  1726. * @return string
  1727. */
  1728. public static function getSkillBlock($userId)
  1729. {
  1730. if (api_get_setting('allow_skills_tool') !== 'true') {
  1731. return null;
  1732. }
  1733. $skill = new Skill();
  1734. $ranking = $skill->get_user_skill_ranking($userId);
  1735. $skills = $skill->get_user_skills($userId, true);
  1736. $template = new Template(null, false, false, false, false, false);
  1737. $template->assign('ranking', $ranking);
  1738. $template->assign('skills', $skills);
  1739. $template->assign('user_id', $userId);
  1740. $template->assign(
  1741. 'show_skills_report_link',
  1742. api_is_student() || api_is_student_boss() || api_is_drh()
  1743. );
  1744. $skillBlock = $template->get_template('social/skills_block.tpl');
  1745. return $template->fetch($skillBlock);
  1746. }
  1747. }