social.lib.php 80 KB

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