social.lib.php 76 KB

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