social.lib.php 71 KB

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