social.lib.php 74 KB

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