social.lib.php 79 KB

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