social.lib.php 76 KB

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