social.lib.php 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  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. //display course entry
  457. if (api_get_setting('course_images_in_courses_list') === 'true') {
  458. $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:65px;">';
  459. } else {
  460. $result .= '<li id="course_'.$count.'" class="list-group-item" style="min-height:44px;">';
  461. }
  462. $result .= $imageCourse;
  463. //show a hyperlink to the course, unless the course is closed and user is not course admin
  464. if ($course_visibility != COURSE_VISIBILITY_HIDDEN &&
  465. ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)
  466. ) {
  467. $result .= '<span class="title">' . $course_title . '<span>';
  468. } else {
  469. $result .= $course_title." "." ".get_lang('CourseClosed')."";
  470. }
  471. $result .= '</li>';
  472. $session = '';
  473. if (!empty($my_course['session_name']) && !empty($my_course['id_session'])) {
  474. // Request for the name of the general coach
  475. $sql = 'SELECT lastname, firstname
  476. FROM '.$tbl_session.' ts
  477. LEFT JOIN '.$main_user_table.' tu
  478. ON ts.id_coach = tu.user_id
  479. WHERE ts.id='.(int) $my_course['id_session'].' LIMIT 1';
  480. $rs = Database::query($sql);
  481. $sessioncoach = Database::store_result($rs);
  482. $sessioncoach = $sessioncoach[0];
  483. $session = array();
  484. $session['title'] = $my_course['session_name'];
  485. if ($my_course['access_start_date'] == '0000-00-00') {
  486. $session['dates'] = get_lang('WithoutTimeLimits');
  487. if (api_get_setting('show_session_coach') === 'true') {
  488. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  489. }
  490. } else {
  491. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['access_start_date'].' '.get_lang('To').' '.$my_course['access_end_date'];
  492. if (api_get_setting('show_session_coach') === 'true') {
  493. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  494. }
  495. }
  496. }
  497. $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0;
  498. $output = array(
  499. $my_course['user_course_cat'],
  500. $result,
  501. $my_course['id_session'],
  502. $session,
  503. );
  504. return $output;
  505. }
  506. /**
  507. * Shows the avatar block in social pages
  508. *
  509. * @param string highlight link possible values:
  510. * group_add,
  511. * home,
  512. * messages,
  513. * messages_inbox,
  514. * messages_compose,
  515. * messages_outbox,
  516. * invitations,
  517. * shared_profile,
  518. * friends,
  519. * groups search
  520. * @param int group id
  521. * @param int user id
  522. *
  523. */
  524. public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0)
  525. {
  526. if (empty($user_id)) {
  527. $user_id = api_get_user_id();
  528. }
  529. $show_groups = array(
  530. 'groups',
  531. 'group_messages',
  532. 'messages_list',
  533. 'group_add',
  534. 'mygroups',
  535. 'group_edit',
  536. 'member_list',
  537. 'invite_friends',
  538. 'waiting_list',
  539. 'browse_groups'
  540. );
  541. $template = new Template(null, false, false, false, false, false);
  542. if (in_array($show, $show_groups) && !empty($group_id)) {
  543. // Group image
  544. $userGroup = new UserGroup();
  545. $group_info = $userGroup->get($group_id);
  546. $userGroupImage = $userGroup->get_picture_group(
  547. $group_id,
  548. $group_info['picture'],
  549. 160,
  550. GROUP_IMAGE_SIZE_BIG
  551. );
  552. $template->assign('show_group', true);
  553. $template->assign('group_id', $group_id);
  554. $template->assign('user_group_image', $userGroupImage);
  555. $template->assign('user_group', $group_info);
  556. $template->assign(
  557. 'user_is_group_admin',
  558. $userGroup->is_group_admin(
  559. $group_id,
  560. api_get_user_id()
  561. )
  562. );
  563. } else {
  564. $template->assign('show_user', true);
  565. $template->assign(
  566. 'user_image',
  567. [
  568. 'big' => UserManager::getUserPicture(
  569. $user_id,
  570. USER_IMAGE_SIZE_BIG
  571. ),
  572. 'normal' => UserManager::getUserPicture(
  573. $user_id,
  574. USER_IMAGE_SIZE_MEDIUM
  575. )
  576. ]
  577. );
  578. }
  579. $skillBlock = $template->get_template('social/avatar_block.tpl');
  580. return $template->fetch($skillBlock);
  581. }
  582. /**
  583. * Shows the right menu of the Social Network tool
  584. *
  585. * @param string $show highlight link possible values:
  586. * group_add,
  587. * home,
  588. * messages,
  589. * messages_inbox,
  590. * messages_compose ,
  591. * messages_outbox,
  592. * invitations,
  593. * shared_profile,
  594. * friends,
  595. * groups search
  596. * @param int $group_id group id
  597. * @param int $user_id user id
  598. * @param bool $show_full_profile show profile or not (show or hide the user image/information)
  599. * @param bool $show_delete_account_button
  600. *
  601. */
  602. public static function show_social_menu(
  603. $show = '',
  604. $group_id = 0,
  605. $user_id = 0,
  606. $show_full_profile = false,
  607. $show_delete_account_button = false
  608. ) {
  609. if (empty($user_id)) {
  610. $user_id = api_get_user_id();
  611. }
  612. $usergroup = new UserGroup();
  613. $user_info = api_get_user_info($user_id, true);
  614. $current_user_id = api_get_user_id();
  615. $current_user_info = api_get_user_info($current_user_id, true);
  616. if ($current_user_id == $user_id) {
  617. $user_friend_relation = null;
  618. } else {
  619. $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id);
  620. }
  621. $show_groups = array(
  622. 'groups',
  623. 'group_messages',
  624. 'messages_list',
  625. 'group_add',
  626. 'mygroups',
  627. 'group_edit',
  628. 'member_list',
  629. 'invite_friends',
  630. 'waiting_list',
  631. 'browse_groups'
  632. );
  633. // get count unread message and total invitations
  634. $count_unread_message = MessageManager::get_number_of_messages(true);
  635. $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null;
  636. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  637. $group_pending_invitations = $usergroup->get_groups_by_user(
  638. api_get_user_id(),
  639. GROUP_USER_PERMISSION_PENDING_INVITATION,
  640. false
  641. );
  642. $group_pending_invitations = count($group_pending_invitations);
  643. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  644. $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : '');
  645. $filesIcon = Display::return_icon('sn-files.png', get_lang('MyFiles'), '', ICON_SIZE_SMALL);
  646. $friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), '', ICON_SIZE_SMALL);
  647. $groupsIcon = Display::return_icon('sn-groups.png', get_lang('SocialGroups'), '', ICON_SIZE_SMALL);
  648. $homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), '', ICON_SIZE_SMALL);
  649. $invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), '', ICON_SIZE_SMALL);
  650. $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), '', ICON_SIZE_SMALL);
  651. $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile'));
  652. $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), '', ICON_SIZE_SMALL);
  653. $html = '';
  654. $active = null;
  655. if (!in_array(
  656. $show,
  657. array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends')
  658. )) {
  659. $links .= '<ul class="nav nav-pills nav-stacked">';
  660. $active = $show == 'home' ? 'active' : null;
  661. $links .= '
  662. <li class="home-icon ' . $active . '">
  663. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php">
  664. ' . $homeIcon . ' ' . get_lang('Home') . '
  665. </a>
  666. </li>';
  667. $active = $show == 'messages' ? 'active' : null;
  668. $links .= '
  669. <li class="messages-icon ' . $active . '">
  670. <a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social">
  671. ' . $messagesIcon . ' ' . get_lang('Messages') . $count_unread_message . '
  672. </a>
  673. </li>';
  674. //Invitations
  675. $active = $show == 'invitations' ? 'active' : null;
  676. $links .= '
  677. <li class="invitations-icon ' . $active . '">
  678. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">
  679. ' . $invitationsIcon . ' ' . get_lang('Invitations') . $total_invitations . '
  680. </a>
  681. </li>';
  682. //Shared profile and groups
  683. $active = $show == 'shared_profile' ? 'active' : null;
  684. $links .= '
  685. <li class="shared-profile-icon' . $active . '">
  686. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php">
  687. ' . $sharedProfileIcon . ' ' . get_lang('ViewMySharedProfile') . '
  688. </a>
  689. </li>';
  690. $active = $show == 'friends' ? 'active' : null;
  691. $links .= '
  692. <li class="friends-icon ' . $active . '">
  693. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php">
  694. ' . $friendsIcon . ' ' . get_lang('Friends') . '
  695. </a>
  696. </li>';
  697. $active = $show == 'browse_groups' ? 'active' : null;
  698. $links .= '
  699. <li class="browse-groups-icon ' . $active . '">
  700. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php">
  701. ' . $groupsIcon . ' ' . get_lang('SocialGroups') . '
  702. </a>
  703. </li>';
  704. //Search users
  705. $active = $show == 'search' ? 'active' : null;
  706. $links .= '
  707. <li class="search-icon ' . $active . '">
  708. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php">
  709. ' . $searchIcon . ' ' . get_lang('Search') . '
  710. </a>
  711. </li>';
  712. //My files
  713. $active = $show == 'myfiles' ? 'active' : null;
  714. $links .= '
  715. <li class="myfiles-icon ' . $active . '">
  716. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php">
  717. ' . $filesIcon . ' ' . get_lang('MyFiles') . '
  718. </a>
  719. </li>';
  720. $links .='</ul>';
  721. $html .= Display::panelCollapse(
  722. get_lang('SocialNetwork'),
  723. $links,
  724. 'social-network-menu',
  725. null,
  726. 'sn-sidebar',
  727. 'sn-sidebar-collapse'
  728. );
  729. }
  730. if (in_array($show, $show_groups) && !empty($group_id)) {
  731. $html .= $usergroup->show_group_column_information(
  732. $group_id,
  733. api_get_user_id(),
  734. $show
  735. );
  736. }
  737. if ($show == 'shared_profile') {
  738. $links .= '<ul class="nav nav-pills nav-stacked">';
  739. // My own profile
  740. if ($show_full_profile && $user_id == intval(api_get_user_id())) {
  741. $links .= '
  742. <li class="home-icon ' . $active . '">
  743. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/home.php">
  744. ' . $homeIcon . ' ' . get_lang('Home') . '
  745. </a>
  746. </li>
  747. <li class="messages-icon ' . $active . '">
  748. <a href="' . api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social">
  749. ' . $messagesIcon . ' ' . get_lang('Messages') . $count_unread_message . '
  750. </a>
  751. </li>';
  752. $active = $show == 'invitations' ? 'active' : null;
  753. $links .= '
  754. <li class="invitations-icon' . $active . '">
  755. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/invitations.php">
  756. ' . $invitationsIcon . ' ' . get_lang('Invitations') . $total_invitations . '
  757. </a>
  758. </li>';
  759. $links .= '
  760. <li class="shared-profile-icon active">
  761. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php">
  762. ' . $sharedProfileIcon . ' ' . get_lang('ViewMySharedProfile') . '
  763. </a>
  764. </li>
  765. <li class="friends-icon">
  766. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/friends.php">
  767. ' . $friendsIcon . ' ' . get_lang('Friends') . '
  768. </a>
  769. </li>
  770. <li class="browse-groups-icon">
  771. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/groups.php">
  772. ' . $groupsIcon . ' ' . get_lang('SocialGroups') . '
  773. </a>
  774. </li>';
  775. $active = $show == 'search' ? 'active' : null;
  776. $links .= '
  777. <li class="search-icon ' . $active . '">
  778. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/search.php">
  779. ' . $searchIcon . ' ' . get_lang('Search') . '
  780. </a>
  781. </li>';
  782. $active = $show == 'myfiles' ? 'active' : null;
  783. $links .= '
  784. <li class="myfiles-icon ' . $active . '">
  785. <a href="' . api_get_path(WEB_CODE_PATH) . 'social/myfiles.php">
  786. ' . $filesIcon . ' ' . get_lang('MyFiles') . '
  787. </a>
  788. </li>';
  789. }
  790. // My friend profile.
  791. if ($user_id != api_get_user_id()) {
  792. $sendMessageText = get_lang('SendMessage');
  793. $sendMessageIcon = Display::return_icon(
  794. 'compose_message.png',
  795. $sendMessageText
  796. );
  797. $sendMesssageUrl = api_get_path(WEB_AJAX_PATH)
  798. . 'user_manager.ajax.php?'
  799. . http_build_query([
  800. 'a' => 'get_user_popup',
  801. 'user_id' => $user_id
  802. ]);
  803. $links .= '<li>';
  804. $links .= Display::url(
  805. "$sendMessageIcon $sendMessageText",
  806. $sendMesssageUrl,
  807. [
  808. 'class' => 'ajax',
  809. 'title' => $sendMessageText,
  810. 'data-title' => $sendMessageText
  811. ]
  812. );
  813. $links .= '</li>';
  814. }
  815. // Check if I already sent an invitation message
  816. $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(api_get_user_id());
  817. if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0) {
  818. $links .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">'.Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')).'&nbsp;&nbsp;'.get_lang('YouAlreadySentAnInvitation').'</a></li>';
  819. } else {
  820. if (!$show_full_profile) {
  821. $links .= '<li><a class="btn-to-send-invitation" href="#" data-send-to="' . $user_id . '" title="'.get_lang('SendInvitation').'">'.Display :: return_icon('invitation.png', get_lang('SocialInvitationToFriends')).'&nbsp;'.get_lang('SendInvitation').'</a></li>';
  822. }
  823. }
  824. $links .= '</ul>';
  825. $html .= Display::panelCollapse(
  826. get_lang('SocialNetwork'),
  827. $links,
  828. 'social-network-menu',
  829. null,
  830. 'sn-sidebar',
  831. 'sn-sidebar-collapse'
  832. );
  833. if ($show_full_profile && $user_id == intval(api_get_user_id())) {
  834. $personal_course_list = UserManager::get_personal_session_course_list($user_id);
  835. $course_list_code = array();
  836. $i = 1;
  837. if (is_array($personal_course_list)) {
  838. foreach ($personal_course_list as $my_course) {
  839. if ($i <= 10) {
  840. $course_list_code[] = array('code' => $my_course['code']);
  841. } else {
  842. break;
  843. }
  844. $i++;
  845. }
  846. // To avoid repeated courses
  847. $course_list_code = array_unique_dimensional($course_list_code);
  848. }
  849. // Announcements
  850. $my_announcement_by_user_id = intval($user_id);
  851. $announcements = array();
  852. foreach ($course_list_code as $course) {
  853. $course_info = api_get_course_info($course['code']);
  854. if (!empty($course_info)) {
  855. $content = AnnouncementManager::get_all_annoucement_by_user_course(
  856. $course_info['code'],
  857. $my_announcement_by_user_id
  858. );
  859. if (!empty($content)) {
  860. $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']);
  861. $announcements[] = Display::tag('li', $url);
  862. }
  863. }
  864. }
  865. if (!empty($announcements)) {
  866. $html .= '<div class="social_menu_items">';
  867. $html .= '<ul>';
  868. foreach ($announcements as $announcement) {
  869. $html .= $announcement;
  870. }
  871. $html .= '</ul>';
  872. $html .= '</div>';
  873. }
  874. }
  875. }
  876. if ($show_delete_account_button) {
  877. $html .= '<div class="sidebar-nav"><ul><li>';
  878. $url = api_get_path(WEB_CODE_PATH).'auth/unsubscribe_account.php';
  879. $html .= Display::url(
  880. Display::return_icon(
  881. 'delete.png',
  882. get_lang('Unsubscribe'),
  883. array(),
  884. ICON_SIZE_TINY
  885. ).get_lang('Unsubscribe'),
  886. $url
  887. );
  888. $html .= '</li></ul></div>';
  889. }
  890. $html .= '';
  891. return $html;
  892. }
  893. /**
  894. * Displays a sortable table with the list of online users.
  895. * @param array $user_list The list of users to be shown
  896. * @param bool $wrap Whether we want the function to wrap the spans list in a div or not
  897. * @return string HTML block or null if and ID was defined
  898. * @assert (null) === false
  899. */
  900. public static function display_user_list($user_list, $wrap = true)
  901. {
  902. $html = null;
  903. if (isset($_GET['id']) or count($user_list) < 1) {
  904. return false;
  905. }
  906. $column_size = '12';
  907. $add_row = false;
  908. if (api_is_anonymous()) {
  909. $add_row = true;
  910. }
  911. $extra_params = array();
  912. $course_url = '';
  913. if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  914. $extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']);
  915. $course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
  916. }
  917. $html .= '<div class="row">';
  918. foreach ($user_list as $uid) {
  919. $user_info = api_get_user_info($uid, $checkIfUserOnline = true);
  920. $lastname = $user_info['lastname'];
  921. $firstname = $user_info['firstname'];
  922. $completeName = $firstname.', '.$lastname;
  923. $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);
  924. $status_icon_chat = null;
  925. if ($user_info['user_is_online_in_chat'] == 1) {
  926. $status_icon_chat = Display::return_icon('online.png', get_lang('Online'));
  927. } else {
  928. $status_icon_chat = Display::return_icon('offline.png', get_lang('Offline'));
  929. }
  930. $userPicture = $user_info['avatar'];
  931. $img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">';
  932. $url = null;
  933. // Anonymous users can't have access to the profile
  934. if (!api_is_anonymous()) {
  935. if (api_get_setting('allow_social_tool') == 'true') {
  936. $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url;
  937. } else {
  938. $url = '?id='.$uid.$course_url;
  939. }
  940. } else {
  941. $url = null;
  942. }
  943. $name = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>';
  944. $html .= '<div class="col-xs-6 col-md-2">
  945. <div class="items-user">
  946. <div class="items-user-avatar">'.$img.'</div>
  947. <div class="items-user-name">
  948. '.$name.'
  949. </div>
  950. <div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div>
  951. </div>
  952. </div>';
  953. }
  954. $counter = $_SESSION['who_is_online_counter'];
  955. if ($wrap) {
  956. $html .= '</div>';
  957. }
  958. if (count($user_list) >= 9) {
  959. $html .= '<div class="col-md-'.$column_size.'">
  960. <a class="btn btn-large btn-default" id="link_load_more_items" data_link="'.$counter.'" >'.get_lang('More').'</a></div>';
  961. }
  962. if ($wrap && $add_row) {
  963. $html .= '</div>';
  964. }
  965. return $html;
  966. }
  967. /**
  968. * Displays the information of an individual user
  969. * @param int $user_id
  970. */
  971. public static function display_individual_user($user_id)
  972. {
  973. global $interbreadcrumb;
  974. $safe_user_id = intval($user_id);
  975. $currentUserId = api_get_user_id();
  976. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  977. $sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id;
  978. $result = Database::query($sql);
  979. $html = null;
  980. if (Database::num_rows($result) == 1) {
  981. $user_object = Database::fetch_object($result);
  982. $userInfo = api_get_user_info($user_id);
  983. $alt = $userInfo['complete_name'].($currentUserId == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  984. $status = get_status_from_code($user_object->status);
  985. $interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList'));
  986. $html .= '<div class ="thumbnail">';
  987. $fullurl = $userInfo['avatar'];
  988. $html .= '<img src="'.$fullurl.'" alt="'.$alt.'" />';
  989. if (!empty($status)) {
  990. $html .= '<div class="caption">'.$status.'</div>';
  991. }
  992. $html .= '</div>';
  993. if (api_get_setting('show_email_addresses') == 'true') {
  994. $html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'<br />';
  995. }
  996. if ($user_object->competences) {
  997. $html .= Display::page_subheader(get_lang('MyCompetences'));
  998. $html .= '<p>'.$user_object->competences.'</p>';
  999. }
  1000. if ($user_object->diplomas) {
  1001. $html .= Display::page_subheader(get_lang('MyDiplomas'));
  1002. $html .= '<p>'.$user_object->diplomas.'</p>';
  1003. }
  1004. if ($user_object->teach) {
  1005. $html .= Display::page_subheader(get_lang('MyTeach'));
  1006. $html .= '<p>'.$user_object->teach.'</p>';
  1007. }
  1008. SocialManager::display_productions($user_object->user_id);
  1009. if ($user_object->openarea) {
  1010. $html .= Display::page_subheader(get_lang('MyPersonalOpenArea'));
  1011. $html .= '<p>'.$user_object->openarea.'</p>';
  1012. }
  1013. } else {
  1014. $html .= '<div class="actions-title">';
  1015. $html .= get_lang('UsersOnLineList');
  1016. $html .= '</div>';
  1017. }
  1018. return $html;
  1019. }
  1020. /**
  1021. * Display productions in who is online
  1022. * @param int $user_id User id
  1023. */
  1024. public static function display_productions($user_id)
  1025. {
  1026. $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web');
  1027. $sysdir = UserManager::getUserPathById($user_id, 'system');
  1028. $webdir = UserManager::getUserPathById($user_id, 'web');
  1029. if (!is_dir($sysdir)) {
  1030. mkdir($sysdir, api_get_permissions_for_new_directories(), true);
  1031. }
  1032. $productions = UserManager::get_user_productions($user_id);
  1033. if (count($productions) > 0) {
  1034. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  1035. echo '<dd><ul>';
  1036. foreach ($productions as $file) {
  1037. // Only display direct file links to avoid browsing an empty directory
  1038. if (is_file($sysdir.$file) && $file != $webdir_array['file']) {
  1039. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  1040. }
  1041. // Real productions are under a subdirectory by the User's id
  1042. if (is_dir($sysdir.$file)) {
  1043. $subs = scandir($sysdir.$file);
  1044. foreach ($subs as $my => $sub) {
  1045. if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) {
  1046. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  1047. }
  1048. }
  1049. }
  1050. }
  1051. echo '</ul></dd>';
  1052. }
  1053. }
  1054. /**
  1055. * @param string $content
  1056. * @param string $span_count
  1057. * @return string
  1058. */
  1059. public static function social_wrapper_div($content, $span_count)
  1060. {
  1061. $span_count = intval($span_count);
  1062. $html = '<div class="span'.$span_count.'">';
  1063. $html .= '<div class="well_border">';
  1064. $html .= $content;
  1065. $html .= '</div></div>';
  1066. return $html;
  1067. }
  1068. /**
  1069. * Dummy function
  1070. *
  1071. */
  1072. public static function get_plugins($place = SOCIAL_CENTER_PLUGIN)
  1073. {
  1074. $content = '';
  1075. switch ($place) {
  1076. case SOCIAL_CENTER_PLUGIN:
  1077. $social_plugins = array(1, 2);
  1078. if (is_array($social_plugins) && count($social_plugins) > 0) {
  1079. $content.= '<div id="social-plugins">';
  1080. foreach ($social_plugins as $plugin) {
  1081. $content.= '<div class="social-plugin-item">';
  1082. $content.= $plugin;
  1083. $content.= '</div>';
  1084. }
  1085. $content.= '</div>';
  1086. }
  1087. break;
  1088. case SOCIAL_LEFT_PLUGIN:
  1089. break;
  1090. case SOCIAL_RIGHT_PLUGIN:
  1091. break;
  1092. }
  1093. return $content;
  1094. }
  1095. /**
  1096. * Sends a message to someone's wall
  1097. * @param int $userId id of author
  1098. * @param int $friendId id where we send the message
  1099. * @param string $messageContent of the message
  1100. * @param int $messageId id parent
  1101. * @param string $messageStatus status type of message
  1102. * @return boolean
  1103. * @author Yannick Warnier
  1104. */
  1105. public static function sendWallMessage($userId, $friendId, $messageContent, $messageId = 0 ,$messageStatus)
  1106. {
  1107. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1108. $userId = intval($userId);
  1109. $friendId = intval($friendId);
  1110. $messageId = intval($messageId);
  1111. //Just in case we replace the and \n and \n\r while saving in the DB
  1112. $messageContent = str_replace(array("\n", "\n\r"), '<br />', $messageContent);
  1113. $attributes = array(
  1114. 'user_sender_id' => $userId,
  1115. 'user_receiver_id' => $friendId,
  1116. 'msg_status' => $messageStatus,
  1117. 'send_date' => api_get_utc_datetime(),
  1118. 'title' => '',
  1119. 'content' => $messageContent,
  1120. 'parent_id' => $messageId
  1121. );
  1122. return Database::insert($tblMessage, $attributes);
  1123. }
  1124. /**
  1125. * Send File attachment (jpg,png)
  1126. * @author Anibal Copitan
  1127. * @param int $userId id user
  1128. * @param array $fileAttach
  1129. * @param int $messageId id message (relation with main message)
  1130. * @param string $fileComment description attachment file
  1131. * @return bool
  1132. */
  1133. public static function sendWallMessageAttachmentFile($userId, $fileAttach, $messageId, $fileComment = '')
  1134. {
  1135. $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
  1136. // create directory
  1137. $social = '/social/';
  1138. $pathMessageAttach = UserManager::getUserPathById($userId, 'system').'message_attachments'.$social;
  1139. $safeFileComment = Database::escape_string($fileComment);
  1140. $safeFileName = Database::escape_string($fileAttach['name']);
  1141. $extension = strtolower(substr(strrchr($safeFileName, '.'), 1));
  1142. $allowedTypes = api_get_supported_image_extensions();
  1143. if (!in_array($extension, $allowedTypes)) {
  1144. $flag = false;
  1145. } else {
  1146. $newFileName = uniqid('') . '.' . $extension;
  1147. if (!file_exists($pathMessageAttach)) {
  1148. @mkdir($pathMessageAttach, api_get_permissions_for_new_directories(), true);
  1149. }
  1150. $newPath = $pathMessageAttach . $newFileName;
  1151. if (is_uploaded_file($fileAttach['tmp_name'])) {
  1152. @copy($fileAttach['tmp_name'], $newPath);
  1153. }
  1154. $small = self::resize_picture($newPath, IMAGE_WALL_SMALL_SIZE);
  1155. $medium = self::resize_picture($newPath, IMAGE_WALL_MEDIUM_SIZE);
  1156. $big = new Image($newPath);
  1157. $ok = $small && $small->send_image($pathMessageAttach . IMAGE_WALL_SMALL . '_' . $newFileName) &&
  1158. $medium && $medium->send_image($pathMessageAttach . IMAGE_WALL_MEDIUM .'_' . $newFileName) &&
  1159. $big && $big->send_image($pathMessageAttach . IMAGE_WALL_BIG . '_' . $newFileName);
  1160. // Insert
  1161. $newFileName = $social.$newFileName;
  1162. $params = [
  1163. 'filename' => $safeFileName,
  1164. 'comment' => $safeFileComment,
  1165. 'path' => $newFileName,
  1166. 'message_id' => $messageId,
  1167. 'size' => $fileAttach['size'],
  1168. ];
  1169. Database::insert($tbl_message_attach, $params);
  1170. $flag = true;
  1171. }
  1172. return $flag;
  1173. }
  1174. /**
  1175. * Gets all messages from someone's wall (within specific limits)
  1176. * @param int $userId id of wall shown
  1177. * @param string $messageStatus status wall message
  1178. * @param int|string $parentId id message (Post main)
  1179. * @param date $start Date from which we want to show the messages, in UTC time
  1180. * @param int $limit Limit for the number of parent messages we want to show
  1181. * @param int $offset Wall message query offset
  1182. * @return boolean
  1183. * @author Yannick Warnier
  1184. */
  1185. public static function getWallMessages($userId, $messageStatus, $parentId = '', $start = null, $limit = 10, $offset = 0)
  1186. {
  1187. if (empty($start)) {
  1188. $start = '0000-00-00';
  1189. }
  1190. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1191. $tblMessageAttachment = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
  1192. $userId = intval($userId);
  1193. $start = Database::escape_string($start);
  1194. $limit = intval($limit);
  1195. $sql = "SELECT id, user_sender_id,user_receiver_id, send_date, content, parent_id,
  1196. (SELECT ma.path FROM $tblMessageAttachment ma WHERE ma.message_id = tm.id ) as path,
  1197. (SELECT ma.filename FROM $tblMessageAttachment ma WHERE ma.message_id = tm.id ) as filename
  1198. FROM $tblMessage tm
  1199. WHERE user_receiver_id = $userId
  1200. AND send_date > '$start' ";
  1201. $sql .= (empty($messageStatus) || is_null($messageStatus)) ? '' : " AND msg_status = '$messageStatus' ";
  1202. $sql .= (empty($parentId) || is_null($parentId)) ? '' : " AND parent_id = '$parentId' ";
  1203. $sql .= " ORDER BY send_date DESC LIMIT $offset, $limit ";
  1204. $messages = array();
  1205. $res = Database::query($sql);
  1206. if (Database::num_rows($res) > 0) {
  1207. while ($row = Database::fetch_array($res)) {
  1208. $messages[] = $row;
  1209. }
  1210. }
  1211. return $messages;
  1212. }
  1213. /**
  1214. * Gets all messages from someone's wall (within specific limits), formatted
  1215. * @param int $userId USER ID of the person's wall
  1216. * @param int $friendId id person
  1217. * @param int $idMessage id message
  1218. * @param string $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 string HTML formatted string to show messages
  1222. */
  1223. public static function getWallMessagesHTML($userId, $friendId, $idMessage, $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, $idMessage, $start, $limit, $offset);
  1230. $formattedList = '<div class="sub-mediapost">';
  1231. $users = array();
  1232. // The messages are ordered by date descendant, for comments we need ascendant
  1233. krsort($messages);
  1234. foreach ($messages as $message) {
  1235. $date = api_get_local_time($message['send_date']);
  1236. $userIdLoop = $message['user_sender_id'];
  1237. if (!isset($users[$userIdLoop])) {
  1238. $users[$userIdLoop] = api_get_user_info($userIdLoop);
  1239. }
  1240. $nameComplete = api_is_western_name_order()
  1241. ? $users[$userIdLoop]['firstname'] .' ' . $users[$userIdLoop]['lastname']
  1242. : $users[$userIdLoop]['lastname'] . ' ' . $users[$userIdLoop]['firstname'];
  1243. $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop;
  1244. $media = '';
  1245. $media .= '<div class="rep-post">';
  1246. if ($isOwnWall) {
  1247. $media .= '<div class="pull-right deleted-mgs">';
  1248. $media .= '<a title="'.get_lang("SocialMessageDelete").'" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='.
  1249. $message['id'].'">x</a>';
  1250. $media .= '</div>';
  1251. }
  1252. $media .= '<div class="user-image">';
  1253. $media .= '<a href="'.$url.'" ><img src="'. $users[$userIdLoop]['avatar'] .
  1254. '" alt="'.$users[$userIdLoop]['complete_name'].'" class="avatar-thumb"></a>';
  1255. $media .= '</div>';
  1256. $media .= '<div class="user-data">';
  1257. $media .= '<div class="username">' . '<a href="'.$url.'">'.$nameComplete.'</a></div>';
  1258. $media .= '<div class="time timeago" title="'.$date.'">'.$date.'</div>';
  1259. $media .= '</div>';
  1260. $media .= '<div class="msg-content">';
  1261. $media .= '<p>'.Security::remove_XSS($message['content']).'</p>';
  1262. $media .= '</div></div>';
  1263. $formattedList .= $media;
  1264. }
  1265. $formattedList .= '</div>';
  1266. $formattedList .= '<div class="mediapost-form">';
  1267. $formattedList .= '<form name="social_wall_message" method="POST">
  1268. <label for="social_wall_new_msg" class="hide">'.get_lang('SocialWriteNewComment').'</label>
  1269. <input type="hidden" name = "messageId" value="'.$idMessage.'" />
  1270. <textarea placeholder="'.get_lang('SocialWriteNewComment').
  1271. '" name="social_wall_new_msg" rows="1" style="width:80%;" ></textarea>
  1272. <button type="submit" name="social_wall_new_msg_submit"
  1273. class="pull-right btn btn-default" /><i class="fa fa-pencil"></i> '.get_lang('Post').'</button>
  1274. </form>';
  1275. $formattedList .= '</div>';
  1276. return $formattedList;
  1277. }
  1278. /**
  1279. * Gets all user's starting wall messages (within specific limits)
  1280. * @param int $userId User's id
  1281. * @param int $friendId Friend's id
  1282. * @param date $start Start date (from when we want the messages until today)
  1283. * @param int $limit Limit to the number of messages we want
  1284. * @param int $offset Wall messages offset
  1285. * @return array $data return user's starting wall messages along with message extra data
  1286. */
  1287. public static function getWallMessagesPostHTML($userId, $friendId = 0, $start = null, $limit = 10, $offset= 0)
  1288. {
  1289. if (empty($start)) {
  1290. $start = '0000-00-00';
  1291. }
  1292. $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId);
  1293. $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL_POST , null, $start, $limit, $offset);
  1294. $users = array();
  1295. $data = array();
  1296. foreach ($messages as $key => $message) {
  1297. $userIdLoop = $message['user_sender_id'];
  1298. $userFriendIdLoop = $message['user_receiver_id'];
  1299. if (!isset($users[$userIdLoop])) {
  1300. $users[$userIdLoop] = api_get_user_info($userIdLoop);
  1301. }
  1302. if (!isset($users[$userFriendIdLoop])) {
  1303. $users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop);
  1304. }
  1305. $html = '';
  1306. $html .= self::headerMessagePost(
  1307. $message['user_sender_id'],
  1308. $message['user_receiver_id'],
  1309. $users,
  1310. $message,
  1311. $isOwnWall
  1312. );
  1313. $data[$key]['id'] = $message['id'];
  1314. $data[$key]['html'] = $html;
  1315. }
  1316. return $data;
  1317. }
  1318. /**
  1319. * Returns the formatted header message post
  1320. * @param int $authorId Author's id
  1321. * @param int $receiverId Receiver's id
  1322. * @param array $users Author's and receiver's data
  1323. * @param array $message Message data
  1324. * @param boolean $isOwnWall Determines if the author is in its own social wall or not
  1325. * @return string $html The formatted header message post
  1326. */
  1327. private static function headerMessagePost($authorId, $receiverId, $users, $message, $isOwnWall = false)
  1328. {
  1329. $date = api_get_local_time($message['send_date']);
  1330. $avatarAuthor = $users[$authorId]['avatar'];
  1331. $urlAuthor = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$authorId;
  1332. $nameCompleteAuthor = api_get_person_name(
  1333. $users[$authorId]['firstname'],
  1334. $users[$authorId]['lastname']
  1335. );
  1336. $urlReceiver = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$receiverId;
  1337. $nameCompleteReceiver = api_get_person_name(
  1338. $users[$receiverId]['firstname'],
  1339. $users[$receiverId]['lastname']
  1340. );
  1341. $htmlReceiver = '';
  1342. if ($authorId != $receiverId) {
  1343. $htmlReceiver = ' > <a href="'.$urlReceiver.'">' . $nameCompleteReceiver . '</a> ';
  1344. }
  1345. $wallImage = '';
  1346. if (!empty($message['path'])) {
  1347. $imageBig = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_BIG);
  1348. $imageSmall = UserManager::getUserPicture($authorId, USER_IMAGE_SIZE_SMALL);
  1349. $wallImage = '<a class="thumbnail ajax" href="'.$imageBig.'"><img src="'.$imageSmall.'"></a>';
  1350. }
  1351. $htmlDelete = '';
  1352. if ($isOwnWall) {
  1353. $htmlDelete .= '<a title="'.get_lang("SocialMessageDelete").'" href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='.
  1354. $message['id'].'">x</a>';
  1355. }
  1356. $html = '';
  1357. $html .= '<div class="top-mediapost" >';
  1358. if ($isOwnWall) {
  1359. $html .= '<div class="pull-right deleted-mgs">';
  1360. $html .= $htmlDelete;
  1361. $html .= '</div>';
  1362. }
  1363. $html .= '<div class="user-image" >';
  1364. $html .= '<a href="'.$urlAuthor.'">'.'<img class="avatar-thumb" src="'.$avatarAuthor.'" alt="'.$nameCompleteAuthor.'"></a>';
  1365. $html .= '</div>';
  1366. $html .= '<div class="user-data">';
  1367. $html .= '<div class="username"><a href="'.$urlAuthor.'">'.$nameCompleteAuthor.'</a>'.$htmlReceiver.'</div>';
  1368. $html .= '<div class="time timeago" title="'.$date.'">'.$date.'</div>';
  1369. $html .= '</div>';
  1370. $html .= '<div class="msg-content">';
  1371. $html .= '<div class="img-post">';
  1372. $html .= $wallImage;
  1373. $html .= '</div>';
  1374. $html .= '<p>'. Security::remove_XSS($message['content']).'</p>';
  1375. $html .= '</div>';
  1376. $html .= '</div>'; // end mediaPost
  1377. return $html;
  1378. }
  1379. /**
  1380. * Get schedule html (with data openGrap)
  1381. * @param string $text Content text
  1382. * @return string $newText Content text with OpenGraph
  1383. */
  1384. public static function readContentWithOpenGraph($text)
  1385. {
  1386. // search link in first line
  1387. $regExUrl = "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
  1388. $newText = '';
  1389. if (preg_match($regExUrl, $text, $url)) {
  1390. // Comment this line to disable OpenGraph
  1391. $newText .= self::getHtmlByLink($url[0]);
  1392. // make the urls hyper links
  1393. //$newText .= preg_replace($regExUrl, "<a target=\"_blank\" href=" . $url[0] . ">".$url[0]."</a> ", $text);
  1394. } else {
  1395. $newText = $text;
  1396. }
  1397. return $newText;
  1398. }
  1399. /**
  1400. * html with data OpenGrap
  1401. * @param $link url
  1402. * @return string data html
  1403. */
  1404. public static function getHtmlByLink($link)
  1405. {
  1406. $graph = OpenGraph::fetch($link);
  1407. $url = $graph->url;
  1408. $image = $graph->image;
  1409. $domain = empty($url) ? '' : parse_url($url);
  1410. $domain = $domain['scheme'].'://'.$domain['host'];
  1411. $html = '';
  1412. // Trick to verify if the Image Url Exist because of some bad metatag dev
  1413. if (self::verifyUrl($image) == false){
  1414. if (!($image[0] == '/')){
  1415. $domain = $domain . '/';
  1416. }
  1417. $image = $domain . $image;
  1418. }
  1419. $title = $graph->title;
  1420. $html .= '<div class="post-open-graph">';
  1421. $html .= '<h4><a target="_blank" href="'.$link.'">'.$title.'</a></h4>';
  1422. $html .= empty($image) ? '' : '<img alt="" src="'.$image.'" />';
  1423. $html .= empty($graph->description) ? '' : '<p class="description">'.$graph->description.'<a href="'.$link.'">'.$link.'</a></p>';
  1424. $html .= "</div>";
  1425. return $html;
  1426. }
  1427. /**
  1428. * verify if Url Exist - Using Curl
  1429. * @param $uri url
  1430. *
  1431. * @return boolean
  1432. */
  1433. public static function verifyUrl($uri)
  1434. {
  1435. $curl = curl_init($uri);
  1436. curl_setopt($curl, CURLOPT_FAILONERROR, true);
  1437. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  1438. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  1439. curl_setopt($curl, CURLOPT_TIMEOUT, 15);
  1440. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  1441. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  1442. curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  1443. $response = curl_exec($curl);
  1444. curl_close($curl);
  1445. if (!empty($response)) {
  1446. return true;
  1447. } else {
  1448. return false;
  1449. }
  1450. }
  1451. /**
  1452. * Get full image path from a path and a size
  1453. * @param string $path
  1454. * @return string
  1455. */
  1456. private static function getImagePath($path, $size = '')
  1457. {
  1458. $name = '';
  1459. $array = preg_split('#\/#', $path);
  1460. if (isset($array[2]) && !empty($array[2])) {
  1461. if ($size == IMAGE_WALL_SMALL) {
  1462. $name = IMAGE_WALL_SMALL. '_' . $array[2];
  1463. }else if($size == IMAGE_WALL_MEDIUM){
  1464. $name = IMAGE_WALL_MEDIUM. '_' . $array[2];
  1465. }else if($size == IMAGE_WALL_BIG){
  1466. $name = IMAGE_WALL_BIG. '_' . $array[2];
  1467. }else {
  1468. $name = IMAGE_WALL_SMALL. '_' . $array[2];
  1469. }
  1470. $lessImage = str_replace($array[2], '', $path);
  1471. $name = $lessImage . $name;
  1472. }
  1473. return $name;
  1474. }
  1475. /**
  1476. * Delete messages delete logic
  1477. * @param int $id id message to delete.
  1478. * @return bool status query
  1479. */
  1480. public static function deleteMessage($id)
  1481. {
  1482. $id = intval($id);
  1483. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1484. $statusMessage = MESSAGE_STATUS_WALL_DELETE;
  1485. $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' ";
  1486. return Database::query($sql);
  1487. }
  1488. /**
  1489. * Generate the social block for a user
  1490. * @param Template $template
  1491. * @param int $userId The user id
  1492. * @param string $groupBlock Optional. Highlight link possible values:
  1493. * group_add, home, messages, messages_inbox, messages_compose,
  1494. * messages_outbox, invitations, shared_profile, friends, groups, search
  1495. * @param int $groupId Optional. Group ID
  1496. * @return string The HTML code with the social block
  1497. */
  1498. public static function setSocialUserBlock(Template $template, $userId, $groupBlock = '', $groupId = 0)
  1499. {
  1500. if (api_get_setting('allow_social_tool') != 'true') {
  1501. return '';
  1502. }
  1503. $socialAvatarBlock = SocialManager::show_social_avatar_block(
  1504. $groupBlock,
  1505. $groupId,
  1506. $userId
  1507. );
  1508. $profileEditionLink = null;
  1509. if (api_get_user_id() == $userId) {
  1510. $profileEditionLink = Display::getProfileEditionLink($userId);
  1511. }
  1512. $vCardUserLink = Display::getVCardUserLink($userId);
  1513. $userInfo = api_get_user_info($userId, true, false, true);
  1514. $template->assign('user', $userInfo);
  1515. $template->assign('social_avatar_block', $socialAvatarBlock);
  1516. $template->assign('profile_edition_link', $profileEditionLink);
  1517. //Added the link to export the vCard to the Template
  1518. $template->assign('vcard_user_link', $vCardUserLink);
  1519. if (api_get_setting('gamification_mode') === '1') {
  1520. $gamificationPoints = GamificationUtils::getTotalUserPoints(
  1521. $userId,
  1522. $userInfo['status']
  1523. );
  1524. $template->assign('gamification_points', $gamificationPoints);
  1525. }
  1526. $chatEnabled = api_is_global_chat_enabled();
  1527. $template->assign('chat_enabled', $chatEnabled);
  1528. $templateName = $template->get_template('social/user_block.tpl');
  1529. if (in_array($groupBlock, ['groups', 'group_edit', 'member_list'])) {
  1530. $templateName = $template->get_template('social/group_block.tpl');
  1531. }
  1532. $template->assign('social_avatar_block', $template->fetch($templateName));
  1533. }
  1534. /**
  1535. * @param int $user_id
  1536. * @param $link_shared
  1537. * @param $show_full_profile
  1538. * @return string
  1539. */
  1540. public static function listMyFriends($user_id, $link_shared, $show_full_profile)
  1541. {
  1542. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT
  1543. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
  1544. $number_of_images = 30;
  1545. $number_friends = count($friends);
  1546. $friendHtml = '';
  1547. if ($number_friends != 0) {
  1548. if ($number_friends > $number_of_images) {
  1549. if (api_get_user_id() == $user_id) {
  1550. $friendHtml.= ' <span><a href="friends.php">'.get_lang('SeeAll').'</a></span>';
  1551. } else {
  1552. $friendHtml.= ' <span>'
  1553. .'<a href="'.api_get_path(WEB_CODE_PATH).'social/profile_friends_and_groups.inc.php'
  1554. .'?view=friends&height=390&width=610&user_id='.$user_id.'"'
  1555. .'class="ajax" data-title="'.get_lang('SeeAll').'" title="'.get_lang('SeeAll').'" >'.get_lang('SeeAll').'</a></span>';
  1556. }
  1557. }
  1558. $friendHtml.= '<ul class="nav nav-list">';
  1559. $j = 1;
  1560. for ($k=0; $k < $number_friends; $k++) {
  1561. if ($j > $number_of_images) break;
  1562. if (isset($friends[$k])) {
  1563. $friend = $friends[$k];
  1564. $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
  1565. $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
  1566. if ($user_info_friend['user_is_online']) {
  1567. $statusIcon = Display::span('', array('class' => 'online_user_in_text'));
  1568. } else {
  1569. $statusIcon = Display::span('', array('class' => 'offline_user_in_text'));
  1570. }
  1571. $friendHtml.= '<li class="">';
  1572. $friendHtml.= '<div>';
  1573. // the height = 92 must be the same in the image_friend_network span style in default.css
  1574. $friends_profile = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_SMALL);
  1575. $friendHtml.= '<img src="'.$friends_profile.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'"/>';
  1576. $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared;
  1577. $friendHtml.= $statusIcon .'<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '">' . $name_user .'</a>';
  1578. $friendHtml.= '</div>';
  1579. $friendHtml.= '</li>';
  1580. }
  1581. $j++;
  1582. }
  1583. $friendHtml.='</ul>';
  1584. } else {
  1585. $friendHtml.= '<div class="">'.get_lang('NoFriendsInYourContactList').'<br />'
  1586. .'<a class="btn btn-primary" href="'.api_get_path(WEB_PATH).'whoisonline.php"><i class="fa fa-search"></i> '. get_lang('TryAndFindSomeFriends').'</a></div>';
  1587. }
  1588. $friendHtml = Display::panel($friendHtml, get_lang('SocialFriend').' (' . $number_friends . ')' );
  1589. return $friendHtml;
  1590. }
  1591. /**
  1592. * @param int $user_id
  1593. * @param $link_shared
  1594. * @param $show_full_profile
  1595. * @return string
  1596. */
  1597. public static function listMyFriendsBlock($user_id, $link_shared, $show_full_profile)
  1598. {
  1599. //SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT
  1600. $friends = SocialManager::get_friends($user_id, USER_RELATION_TYPE_FRIEND);
  1601. $number_of_images = 30;
  1602. $number_friends = count($friends);
  1603. $friendHtml = '';
  1604. if ($number_friends != 0) {
  1605. $friendHtml.= '<div class="list-group">';
  1606. $j = 1;
  1607. for ($k=0; $k < $number_friends; $k++) {
  1608. if ($j > $number_of_images) break;
  1609. if (isset($friends[$k])) {
  1610. $friend = $friends[$k];
  1611. $name_user = api_get_person_name($friend['firstName'], $friend['lastName']);
  1612. $user_info_friend = api_get_user_info($friend['friend_user_id'], true);
  1613. if ($user_info_friend['user_is_online']) {
  1614. $statusIcon = Display::return_icon('statusonline.png',get_lang('Online'));
  1615. $status=1;
  1616. } else {
  1617. $statusIcon = Display::return_icon('statusoffline.png',get_lang('Offline'));
  1618. $status=0;
  1619. }
  1620. $friendAvatarMedium = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_MEDIUM);
  1621. $friendAvatarSmall = UserManager::getUserPicture($friend['friend_user_id'], USER_IMAGE_SIZE_SMALL);
  1622. $friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>';
  1623. $showLinkToChat = api_is_global_chat_enabled() &&
  1624. $friend['friend_user_id'] != api_get_user_id();
  1625. if ($showLinkToChat){
  1626. $friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">';
  1627. $friendHtml .= $friend_avatar.' <span class="username">' . $name_user . '</span>';
  1628. $friendHtml .= '<span class="status">' . $statusIcon . '</span>';
  1629. } else {
  1630. $link_shared = (empty($link_shared)) ? '' : '&'.$link_shared;
  1631. $friendHtml .= '<a href="profile.php?' .'u=' . $friend['friend_user_id'] . $link_shared . '" class="list-group-item">';
  1632. $friendHtml .= $friend_avatar.' <span class="username-all">' . $name_user . '</span>';
  1633. }
  1634. $friendHtml .= '</a>';
  1635. }
  1636. $j++;
  1637. }
  1638. $friendHtml.='</div>';
  1639. } else {
  1640. $friendHtml.= '<div class="help">'.get_lang('NoFriendsInYourContactList').' '
  1641. .'<a href="'.api_get_path(WEB_PATH).'whoisonline.php"><i class="fa fa-search"></i> '. get_lang('TryAndFindSomeFriends').'</a></div>';
  1642. }
  1643. return $friendHtml;
  1644. }
  1645. /**
  1646. * @return string
  1647. */
  1648. public static function getWallForm()
  1649. {
  1650. $form = new FormValidator(
  1651. 'social_wall_main',
  1652. 'post',
  1653. api_get_path(WEB_CODE_PATH).'social/profile.php',
  1654. null,
  1655. array('enctype' => 'multipart/form-data') ,
  1656. FormValidator::LAYOUT_HORIZONTAL
  1657. );
  1658. $form->addTextarea(
  1659. 'social_wall_new_msg_main',
  1660. null,
  1661. [
  1662. 'placeholder' => get_lang('SocialWallWhatAreYouThinkingAbout'),
  1663. 'cols-size' => [1, 10, 1]
  1664. ]
  1665. );
  1666. $form->addHtml('<div class="url_preview"></div>');
  1667. $form->addHidden('url_content', '');
  1668. $form->addButtonSend(get_lang('Post'), null, false, ['cols-size' => [1, 10, 1]]);
  1669. $html = Display::panel($form->returnForm(), get_lang('SocialWall'));
  1670. return $html;
  1671. }
  1672. /**
  1673. * @param int $userId
  1674. * @param int $friendId
  1675. * @return string
  1676. */
  1677. public static function getWallMessagesByUser($userId, $friendId)
  1678. {
  1679. $messages = SocialManager::getWallMessagesPostHTML($userId, $friendId);
  1680. $html = '';
  1681. foreach ($messages as $message) {
  1682. $post = $message['html'];
  1683. $comment = SocialManager::getWallMessagesHTML($userId, $friendId, $message['id']);
  1684. $html .= $post.$comment;
  1685. }
  1686. return $html;
  1687. }
  1688. /**
  1689. * Get HTML code block for user skills
  1690. * @param int $userId The user ID
  1691. * @return string
  1692. */
  1693. public static function getSkillBlock($userId)
  1694. {
  1695. if (api_get_setting('allow_skills_tool') !== 'true') {
  1696. return null;
  1697. }
  1698. $skill = new Skill();
  1699. $ranking = $skill->get_user_skill_ranking($userId);
  1700. $skills = $skill->get_user_skills($userId, true);
  1701. $template = new Template(null, false, false, false, false, false);
  1702. $template->assign('ranking', $ranking);
  1703. $template->assign('skills', $skills);
  1704. $template->assign(
  1705. 'show_skills_report_link',
  1706. api_is_student() || api_is_student_boss() || api_is_drh()
  1707. );
  1708. $skillBlock = $template->get_template('social/skills_block.tpl');
  1709. return $template->fetch($skillBlock);
  1710. }
  1711. }