social.lib.php 74 KB

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