profile.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. $menu = 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. $addPostForm = 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[] = SocialManager::getScriptToGetOpenGraph();
  164. $socialRightInformation = '';
  165. $social_right_content = '';
  166. $listInvitations = '';
  167. if ($show_full_profile) {
  168. $social_group_info_block = SocialManager::getGroupBlock($friendId);
  169. // Block Social Course
  170. $my_courses = null;
  171. // COURSES LIST
  172. if (is_array($list)) {
  173. // Courses without sessions
  174. $my_course = '';
  175. $i = 1;
  176. foreach ($list as $key => $value) {
  177. if (empty($value[2])) { //if out of any session
  178. $my_courses .= $value[1];
  179. $i++;
  180. }
  181. }
  182. $social_course_block .= $my_courses;
  183. }
  184. // Block Social Sessions
  185. if (count($sessionList) > 0) {
  186. $social_session_block = $sessionList;
  187. }
  188. // Block Social User Feeds
  189. $user_feeds = SocialManager::getUserRssFeed($user_id);
  190. if (!empty($user_feeds)) {
  191. $social_rss_block = Display::panel($user_feeds, get_lang('RSSFeeds'));
  192. }
  193. // Productions
  194. $production_list = UserManager::build_production_list($user_id);
  195. // Images uploaded by course
  196. $file_list = '';
  197. if (is_array($course_list_code) && count($course_list_code) > 0) {
  198. foreach ($course_list_code as $course) {
  199. $file_list .= UserManager::get_user_upload_files_by_course(
  200. $user_id,
  201. $course['code'],
  202. $resourcetype = 'images'
  203. );
  204. }
  205. }
  206. $count_pending_invitations = 0;
  207. if (!isset($_GET['u']) ||
  208. (isset($_GET['u']) && $_GET['u'] == api_get_user_id())
  209. ) {
  210. $pending_invitations = SocialManager::get_list_invitation_of_friends_by_user_id(api_get_user_id());
  211. $list_get_path_web = SocialManager::get_list_web_path_user_invitation_by_user_id(api_get_user_id());
  212. $count_pending_invitations = count($pending_invitations);
  213. }
  214. if (!empty($production_list) || !empty($file_list) || $count_pending_invitations > 0) {
  215. // Pending invitations
  216. if (!isset($_GET['u']) || (isset($_GET['u']) && $_GET['u'] == api_get_user_id())) {
  217. if ($count_pending_invitations > 0) {
  218. $invitations = '<ul class="list-group">';
  219. for ($i = 0; $i < $count_pending_invitations; $i++) {
  220. $user_invitation_id = $pending_invitations[$i]['user_sender_id'];
  221. $invitations .= '<li id="dpending_'.$user_invitation_id.'" class="list-group-item">';
  222. $invitations .= '<img class="img-rounded" '
  223. .' src="'.$list_get_path_web[$i]['dir'].'/'.$list_get_path_web[$i]['file'].'"'
  224. .' width="40px">';
  225. $userInfo = api_get_user_info($user_invitation_id);
  226. $invitations .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php?u='.$user_invitation_id.'">'
  227. .api_get_person_name($userInfo['firstname'], $userInfo['lastname']).'</a>';
  228. $invitations .= '<div class="pull-right">';
  229. $invitations .= Display::toolbarButton(
  230. get_lang('SocialAddToFriends'),
  231. api_get_path(WEB_AJAX_PATH).'social.ajax.php?'.http_build_query([
  232. 'a' => 'add_friend',
  233. 'friend_id' => $user_invitation_id,
  234. 'is_my_friend' => 'friend',
  235. ]),
  236. 'plus',
  237. 'default',
  238. ['class' => 'btn-sm'],
  239. false
  240. );
  241. $invitations .= '</div>';
  242. $invitations .= '<div id="id_response"></div>';
  243. $invitations .= '</li>';
  244. }
  245. $invitations .= '</ul>';
  246. $listInvitations = Display::panelCollapse(
  247. get_lang('PendingInvitations'),
  248. $invitations,
  249. 'invitations',
  250. null,
  251. 'invitations-acordion',
  252. 'invitations-collapse'
  253. );
  254. }
  255. }
  256. // Productions
  257. $production_list = UserManager::build_production_list($user_id);
  258. $product_content = '';
  259. if (!empty($production_list)) {
  260. $product_content .= '<div><h3>'.get_lang('MyProductions').'</h3></div>';
  261. $product_content .= $production_list;
  262. $socialRightInformation .= SocialManager::social_wrapper_div($product_content, 4);
  263. }
  264. $images_uploaded = null;
  265. // Images uploaded by course
  266. if (!empty($file_list)) {
  267. $images_uploaded .= '<div><h3>'.get_lang('ImagesUploaded').'</h3></div>';
  268. $images_uploaded .= '<div class="social-content-information">';
  269. $images_uploaded .= $file_list;
  270. $images_uploaded .= '</div>';
  271. $socialRightInformation .= SocialManager::social_wrapper_div($images_uploaded, 4);
  272. }
  273. }
  274. if (!empty($user_info['competences']) || !empty($user_info['diplomas'])
  275. || !empty($user_info['openarea']) || !empty($user_info['teach'])) {
  276. $more_info .= '<div><h3>'.get_lang('MoreInformation').'</h3></div>';
  277. if (!empty($user_info['competences'])) {
  278. $more_info .= '<br />';
  279. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyCompetences').'</strong></div>';
  280. $more_info .= '<div class="social-profile-extended">'.$user_info['competences'].'</div>';
  281. $more_info .= '<br />';
  282. }
  283. if (!empty($user_info['diplomas'])) {
  284. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyDiplomas').'</strong></div>';
  285. $more_info .= '<div class="social-profile-extended">'.$user_info['diplomas'].'</div>';
  286. $more_info .= '<br />';
  287. }
  288. if (!empty($user_info['openarea'])) {
  289. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyPersonalOpenArea').'</strong></div>';
  290. $more_info .= '<div class="social-profile-extended">'.$user_info['openarea'].'</div>';
  291. $more_info .= '<br />';
  292. }
  293. if (!empty($user_info['teach'])) {
  294. $more_info .= '<div class="social-actions-message"><strong>'.get_lang('MyTeach').'</strong></div>';
  295. $more_info .= '<div class="social-profile-extended">'.$user_info['teach'].'</div>';
  296. $more_info .= '<br />';
  297. }
  298. $socialRightInformation .= SocialManager::social_wrapper_div($more_info, 4);
  299. }
  300. }
  301. $tpl = new Template(get_lang('Social'));
  302. // Block Avatar Social
  303. SocialManager::setSocialUserBlock(
  304. $tpl,
  305. $friendId,
  306. 'shared_profile',
  307. 0,
  308. $show_full_profile
  309. );
  310. $tpl->assign('social_friend_block', $friend_html);
  311. $tpl->assign('social_menu_block', $menu);
  312. $tpl->assign('add_post_form', $addPostForm);
  313. $tpl->assign('posts', $posts);
  314. $tpl->assign('social_course_block', $social_course_block);
  315. $tpl->assign('social_group_info_block', $social_group_info_block);
  316. $tpl->assign('social_rss_block', $social_rss_block);
  317. $tpl->assign('social_skill_block', SocialManager::getSkillBlock($friendId, 'vertical'));
  318. $tpl->assign('session_list', $social_session_block);
  319. $tpl->assign('invitations', $listInvitations);
  320. $tpl->assign('social_right_information', $socialRightInformation);
  321. $tpl->assign('social_auto_extend_link', $socialAutoExtendLink);
  322. $formModalTpl = new Template();
  323. $formModalTpl->assign('invitation_form', MessageManager::generate_invitation_form());
  324. $template = $formModalTpl->get_template('social/form_modals.tpl');
  325. $formModals = $formModalTpl->fetch($template);
  326. $tpl->assign('form_modals', $formModals);
  327. $social_layout = $tpl->get_template('social/profile.tpl');
  328. $tpl->display($social_layout);