profile.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This is the profile social main page.
  6. *
  7. * @author Julio Montoya <gugli100@gmail.com>
  8. * @author Isaac Flores Paz <florespaz_isaac@hotmail.com>
  9. *
  10. * @todo use Display::panel()
  11. *
  12. * @package chamilo.social
  13. */
  14. $cidReset = true;
  15. require_once __DIR__.'/../inc/global.inc.php';
  16. if (api_get_setting('allow_social_tool') != 'true') {
  17. $url = api_get_path(WEB_PATH).'whoisonline.php?id='.intval($_GET['u']);
  18. header('Location: '.$url);
  19. exit;
  20. }
  21. $user_id = api_get_user_id();
  22. $friendId = isset($_GET['u']) ? (int) $_GET['u'] : api_get_user_id();
  23. $isAdmin = api_is_platform_admin($user_id);
  24. $userGroup = new UserGroup();
  25. $show_full_profile = true;
  26. //social tab
  27. $this_section = SECTION_SOCIAL;
  28. // Initialize blocks
  29. $social_course_block = null;
  30. $social_group_info_block = null;
  31. $social_rss_block = null;
  32. $social_session_block = null;
  33. SocialManager::handlePosts(api_get_self().'?u='.$friendId);
  34. if (isset($_GET['u'])) {
  35. //I'm your friend? I can see your profile?
  36. $user_id = intval($_GET['u']);
  37. if (api_is_anonymous($user_id, true)) {
  38. api_not_allowed(true);
  39. }
  40. // It's me!
  41. if (api_get_user_id() != $user_id) {
  42. $user_info = api_get_user_info($user_id);
  43. $show_full_profile = false;
  44. if (!$user_info) {
  45. // user does no exist !!
  46. api_not_allowed(true);
  47. } else {
  48. //checking the relationship between me and my friend
  49. $my_status = SocialManager::get_relation_between_contacts(
  50. api_get_user_id(),
  51. $user_id
  52. );
  53. if (in_array($my_status, [
  54. USER_RELATION_TYPE_PARENT,
  55. USER_RELATION_TYPE_FRIEND,
  56. USER_RELATION_TYPE_GOODFRIEND,
  57. ])
  58. ) {
  59. $show_full_profile = true;
  60. }
  61. //checking the relationship between my friend and me
  62. $my_friend_status = SocialManager::get_relation_between_contacts(
  63. $user_id,
  64. api_get_user_id()
  65. );
  66. if (in_array($my_friend_status, [
  67. USER_RELATION_TYPE_PARENT,
  68. USER_RELATION_TYPE_FRIEND,
  69. USER_RELATION_TYPE_GOODFRIEND,
  70. ])
  71. ) {
  72. $show_full_profile = true;
  73. } else {
  74. // im probably not a good friend
  75. $show_full_profile = false;
  76. }
  77. }
  78. } else {
  79. $user_info = api_get_user_info($user_id);
  80. }
  81. } else {
  82. $user_info = api_get_user_info($user_id);
  83. }
  84. $isSelfUser = false;
  85. if ($user_info['user_id'] == api_get_user_id()) {
  86. $isSelfUser = true;
  87. }
  88. $userIsOnline = user_is_online($user_id);
  89. $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php';
  90. $socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php';
  91. $javascriptDir = api_get_path(LIBRARY_PATH).'javascript/';
  92. api_block_anonymous_users();
  93. $countPost = SocialManager::getCountWallMessagesByUser($friendId);
  94. SocialManager::getScrollJs($countPost, $htmlHeadXtra);
  95. $link_shared = '';
  96. $nametool = get_lang('ViewMySharedProfile');
  97. if (isset($_GET['shared'])) {
  98. $my_link = '../social/profile.php';
  99. $link_shared = 'shared='.Security::remove_XSS($_GET['shared']);
  100. } else {
  101. $my_link = '../social/profile.php';
  102. $link_shared = '';
  103. }
  104. $interbreadcrumb[] = [
  105. 'url' => 'home.php',
  106. 'name' => get_lang('SocialNetwork'),
  107. ];
  108. if (isset($_GET['u']) && is_numeric($_GET['u']) && $_GET['u'] != api_get_user_id()) {
  109. $info_user = api_get_user_info($_GET['u']);
  110. $interbreadcrumb[] = [
  111. 'url' => '#',
  112. 'name' => $info_user['complete_name'],
  113. ];
  114. $nametool = '';
  115. }
  116. if (isset($_GET['u'])) {
  117. $param_user = 'u='.Security::remove_XSS($_GET['u']);
  118. } else {
  119. $info_user = api_get_user_info(api_get_user_id());
  120. $param_user = '';
  121. }
  122. Session::write('social_user_id', (int) $user_id);
  123. // Setting some course info
  124. $personal_course_list = UserManager::get_personal_session_course_list(
  125. $friendId,
  126. 50
  127. );
  128. $course_list_code = [];
  129. $i = 1;
  130. $list = [];
  131. if (is_array($personal_course_list)) {
  132. foreach ($personal_course_list as $my_course) {
  133. if ($i <= 10) {
  134. $list[] = SocialManager::get_logged_user_course_html($my_course, $i);
  135. $course_list_code[] = ['code' => $my_course['code']];
  136. } else {
  137. break;
  138. }
  139. $i++;
  140. }
  141. //to avoid repeted courses
  142. $course_list_code = array_unique_dimensional($course_list_code);
  143. }
  144. //Social Block Menu
  145. $social_menu_block = SocialManager::show_social_menu(
  146. 'shared_profile',
  147. null,
  148. $user_id,
  149. $show_full_profile
  150. );
  151. //Setting some session info
  152. $user_info = api_get_user_info($friendId);
  153. $sessionList = SessionManager::getSessionsFollowedByUser(
  154. $friendId,
  155. $user_info['status']
  156. );
  157. // My friends
  158. $friend_html = SocialManager::listMyFriendsBlock($user_id, $link_shared);
  159. $wallSocialAddPost = SocialManager::getWallForm(api_get_self());
  160. $posts = SocialManager::getWallMessagesByUser($friendId);
  161. $socialAutoExtendLink = SocialManager::getAutoExtendLink($user_id, $countPost);
  162. // Added a Jquery Function to return the Preview of OpenGraph URL Content
  163. $htmlHeadXtra[] = '<script>
  164. $(document).ready(function() {
  165. var getUrl = $("[name=\'social_wall_new_msg_main\']");
  166. var matchUrl = /https?:\/\/w{0,3}\w*?\.(\w*?\.)?\w{2,3}\S*|www\.(\w*?\.)?\w*?\.\w{2,3}\S*|(\w*?\.)?\w*?\.\w{2,3}[\/\?]\S*/ ;
  167. getUrl.on("paste", function(e) {
  168. $.ajax({
  169. contentType: "application/x-www-form-urlencoded",
  170. beforeSend: function() {
  171. $("[name=\'wall_post_button\']").prop( "disabled", true );
  172. $(".panel-preview").hide();
  173. $(".spinner").html("'.
  174. '<div class=\'text-center\'>'.
  175. '<em class=\'fa fa-spinner fa-pulse fa-1x\'></em>'.
  176. '<p>'.get_lang('Loading').' '.get_lang('Preview').'</p>'.
  177. '</div>'.
  178. '");
  179. },
  180. type: "POST",
  181. url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=read_url_with_open_graph",
  182. data: "social_wall_new_msg_main=" + e.originalEvent.clipboardData.getData("text"),
  183. success: function(response) {
  184. $("[name=\'wall_post_button\']").prop( "disabled", false );
  185. if (!response == false) {
  186. $(".spinner").html("");
  187. $(".panel-preview").show();
  188. $(".url_preview").html(response);
  189. $("[name=\'url_content\']").val(response);
  190. $(".url_preview img").addClass("img-responsive");
  191. } else {
  192. $(".spinner").html("");
  193. }
  194. }
  195. });
  196. });
  197. });
  198. </script>';
  199. $socialRightInformation = '';
  200. $social_right_content = '';
  201. $listInvitations = '';
  202. if ($show_full_profile) {
  203. $social_group_info_block = SocialManager::getGroupBlock($friendId);
  204. // Block Social Course
  205. $my_courses = null;
  206. // COURSES LIST
  207. if (is_array($list)) {
  208. // Courses without sessions
  209. $my_course = '';
  210. $i = 1;
  211. foreach ($list as $key => $value) {
  212. if (empty($value[2])) { //if out of any session
  213. $my_courses .= $value[1];
  214. $i++;
  215. }
  216. }
  217. $social_course_block .= $my_courses;
  218. }
  219. // Block Social Sessions
  220. if (count($sessionList) > 0) {
  221. $social_session_block = $sessionList;
  222. }
  223. // Block Social User Feeds
  224. $user_feeds = SocialManager::getUserRssFeed($user_id);
  225. if (!empty($user_feeds)) {
  226. $social_rss_block = Display::panel($user_feeds, get_lang('RSSFeeds'));
  227. }
  228. // Productions
  229. $production_list = UserManager::build_production_list($user_id);
  230. // Images uploaded by course
  231. $file_list = '';
  232. if (is_array($course_list_code) && count($course_list_code) > 0) {
  233. foreach ($course_list_code as $course) {
  234. $file_list .= UserManager::get_user_upload_files_by_course(
  235. $user_id,
  236. $course['code'],
  237. $resourcetype = 'images'
  238. );
  239. }
  240. }
  241. $count_pending_invitations = 0;
  242. if (!isset($_GET['u']) ||
  243. (isset($_GET['u']) && $_GET['u'] == api_get_user_id())
  244. ) {
  245. $pending_invitations = SocialManager::get_list_invitation_of_friends_by_user_id(api_get_user_id());
  246. $list_get_path_web = SocialManager::get_list_web_path_user_invitation_by_user_id(api_get_user_id());
  247. $count_pending_invitations = count($pending_invitations);
  248. }
  249. if (!empty($production_list) || !empty($file_list) || $count_pending_invitations > 0) {
  250. // Pending invitations
  251. if (!isset($_GET['u']) || (isset($_GET['u']) && $_GET['u'] == api_get_user_id())) {
  252. if ($count_pending_invitations > 0) {
  253. $invitations = '<ul class="list-group">';
  254. for ($i = 0; $i < $count_pending_invitations; $i++) {
  255. $user_invitation_id = $pending_invitations[$i]['user_sender_id'];
  256. $invitations .= '<li id="dpending_'.$user_invitation_id.'" class="list-group-item">';
  257. $invitations .= '<img class="img-rounded" '
  258. .' src="'.$list_get_path_web[$i]['dir'].'/'.$list_get_path_web[$i]['file'].'"'
  259. .' width="40px">';
  260. $userInfo = api_get_user_info($user_invitation_id);
  261. $invitations .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php?u='.$user_invitation_id.'">'
  262. .api_get_person_name($userInfo['firstname'], $userInfo['lastname']).'</a>';
  263. $invitations .= '<div class="pull-right">';
  264. $invitations .= Display::toolbarButton(
  265. get_lang('SocialAddToFriends'),
  266. api_get_path(WEB_AJAX_PATH).'social.ajax.php?'.http_build_query([
  267. 'a' => 'add_friend',
  268. 'friend_id' => $user_invitation_id,
  269. 'is_my_friend' => 'friend',
  270. ]),
  271. 'plus',
  272. 'default',
  273. ['class' => 'btn-sm'],
  274. false
  275. );
  276. $invitations .= '</div>';
  277. $invitations .= '<div id="id_response"></div>';
  278. $invitations .= '</li>';
  279. }
  280. $invitations .= '</ul>';
  281. $listInvitations = Display::panelCollapse(
  282. get_lang('PendingInvitations'),
  283. $invitations,
  284. 'invitations',
  285. null,
  286. 'invitations-acordion',
  287. 'invitations-collapse'
  288. );
  289. }
  290. }
  291. // Productions
  292. $production_list = UserManager::build_production_list($user_id);
  293. $product_content = '';
  294. if (!empty($production_list)) {
  295. $product_content .= '<div><h3>'.get_lang('MyProductions').'</h3></div>';
  296. $product_content .= $production_list;
  297. $socialRightInformation .= SocialManager::social_wrapper_div($product_content, 4);
  298. }
  299. $images_uploaded = null;
  300. // Images uploaded by course
  301. if (!empty($file_list)) {
  302. $images_uploaded .= '<div><h3>'.get_lang('ImagesUploaded').'</h3></div>';
  303. $images_uploaded .= '<div class="social-content-information">';
  304. $images_uploaded .= $file_list;
  305. $images_uploaded .= '</div>';
  306. $socialRightInformation .= SocialManager::social_wrapper_div($images_uploaded, 4);
  307. }
  308. }
  309. if (!empty($user_info['competences']) || !empty($user_info['diplomas'])
  310. || !empty($user_info['openarea']) || !empty($user_info['teach'])) {
  311. $more_info .= '<div><h3>'.get_lang('MoreInformation').'</h3></div>';
  312. if (!empty($user_info['competences'])) {
  313. $more_info .= '<br />';
  314. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyCompetences').'</strong></div>';
  315. $more_info .= '<div class="social-profile-extended">'.$user_info['competences'].'</div>';
  316. $more_info .= '<br />';
  317. }
  318. if (!empty($user_info['diplomas'])) {
  319. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyDiplomas').'</strong></div>';
  320. $more_info .= '<div class="social-profile-extended">'.$user_info['diplomas'].'</div>';
  321. $more_info .= '<br />';
  322. }
  323. if (!empty($user_info['openarea'])) {
  324. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyPersonalOpenArea').'</strong></div>';
  325. $more_info .= '<div class="social-profile-extended">'.$user_info['openarea'].'</div>';
  326. $more_info .= '<br />';
  327. }
  328. if (!empty($user_info['teach'])) {
  329. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyTeach').'</strong></div>';
  330. $more_info .= '<div class="social-profile-extended">'.$user_info['teach'].'</div>';
  331. $more_info .= '<br />';
  332. }
  333. $socialRightInformation .= SocialManager::social_wrapper_div($more_info, 4);
  334. }
  335. }
  336. $tpl = new Template(get_lang('Social'));
  337. // Block Avatar Social
  338. SocialManager::setSocialUserBlock(
  339. $tpl,
  340. $friendId,
  341. 'shared_profile',
  342. 0,
  343. $show_full_profile
  344. );
  345. $tpl->assign('social_friend_block', $friend_html);
  346. $tpl->assign('social_menu_block', $social_menu_block);
  347. $tpl->assign('social_wall_block', $wallSocialAddPost);
  348. $tpl->assign('social_post_wall_block', $posts);
  349. $tpl->assign('social_course_block', $social_course_block);
  350. $tpl->assign('social_group_info_block', $social_group_info_block);
  351. $tpl->assign('social_rss_block', $social_rss_block);
  352. $tpl->assign('social_skill_block', SocialManager::getSkillBlock($friendId, 'vertical'));
  353. $tpl->assign('session_list', $social_session_block);
  354. $tpl->assign('invitations', $listInvitations);
  355. $tpl->assign('social_right_information', $socialRightInformation);
  356. $tpl->assign('social_auto_extend_link', $socialAutoExtendLink);
  357. $formModalTpl = new Template();
  358. $formModalTpl->assign('invitation_form', MessageManager::generate_invitation_form('send_invitation'));
  359. $template = $formModalTpl->get_template('social/form_modals.tpl');
  360. $formModals = $formModalTpl->fetch($template);
  361. $tpl->assign('form_modals', $formModals);
  362. $social_layout = $tpl->get_template('social/profile.tpl');
  363. $tpl->display($social_layout);