home.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * @package chamilo.social
  6. *
  7. * @author Julio Montoya <gugli100@gmail.com>
  8. * @autor Alex Aragon <alex.aragon@beeznest.com> CSS Design and Template
  9. */
  10. $cidReset = true;
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. api_block_anonymous_users();
  13. $user_id = api_get_user_id();
  14. $show_full_profile = true;
  15. // social tab
  16. Session::erase('this_section');
  17. $this_section = SECTION_SOCIAL;
  18. if (api_get_setting('allow_social_tool') !== 'true') {
  19. $url = api_get_path(WEB_CODE_PATH).'auth/profile.php';
  20. header('Location: '.$url);
  21. exit;
  22. }
  23. //fast upload image
  24. if (api_get_setting('profile', 'picture') == 'true') {
  25. $form = new FormValidator('profile', 'post', 'home.php', null, []);
  26. // PICTURE
  27. $form->addElement('file', 'picture', get_lang('AddImage'));
  28. $form->addProgress();
  29. if (!empty($user_data['picture_uri'])) {
  30. $form->addElement(
  31. 'checkbox',
  32. 'remove_picture',
  33. null,
  34. get_lang('DelImage')
  35. );
  36. }
  37. $allowed_picture_types = api_get_supported_image_extensions();
  38. $form->addRule(
  39. 'picture',
  40. get_lang('OnlyImagesAllowed').' ('.implode(
  41. ',',
  42. $allowed_picture_types
  43. ).')',
  44. 'filetype',
  45. $allowed_picture_types
  46. );
  47. $form->addButtonSave(get_lang('SaveSettings'), 'apply_change');
  48. if ($form->validate()) {
  49. // upload picture if a new one is provided
  50. if ($_FILES['picture']['size']) {
  51. if ($new_picture = UserManager::update_user_picture(
  52. api_get_user_id(),
  53. $_FILES['picture']['name'],
  54. $_FILES['picture']['tmp_name']
  55. )) {
  56. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  57. $sql = "UPDATE $table_user
  58. SET
  59. picture_uri = '$new_picture'
  60. WHERE user_id = ".$user_id;
  61. Database::query($sql);
  62. }
  63. }
  64. }
  65. }
  66. SocialManager::handlePosts(api_get_self());
  67. $threadList = SocialManager::getThreadList($user_id);
  68. $threadIdList = [];
  69. if (!empty($threadList)) {
  70. $threadIdList = array_column($threadList, 'id');
  71. }
  72. $posts = SocialManager::getMyWallMessages($user_id, 0, 10, $threadIdList);
  73. $countPost = $posts['count'];
  74. $posts = $posts['posts'];
  75. SocialManager::getScrollJs($countPost, $htmlHeadXtra);
  76. // Block Menu
  77. $menu = SocialManager::show_social_menu('home');
  78. $social_search_block = Display::panel(
  79. UserManager::get_search_form(''),
  80. get_lang('SearchUsers')
  81. );
  82. $social_group_block = SocialManager::getGroupBlock($user_id);
  83. // My friends
  84. $friend_html = SocialManager::listMyFriendsBlock($user_id);
  85. // Block Social Sessions
  86. $social_session_block = null;
  87. //$user_info = api_get_user_info($user_id);
  88. //$sessionList = SessionManager::getSessionsFollowedByUser($user_id, $user_info['status']);
  89. $sessionList = [];
  90. if (count($sessionList) > 0) {
  91. $social_session_block = $sessionList;
  92. }
  93. $wallSocialAddPost = SocialManager::getWallForm(api_get_self());
  94. $socialAutoExtendLink = SocialManager::getAutoExtendLink($user_id, $countPost);
  95. $formSearch = new FormValidator(
  96. 'find_friends_form',
  97. 'get',
  98. api_get_path(WEB_CODE_PATH).'social/search.php?search_type=1',
  99. null,
  100. null,
  101. FormValidator::LAYOUT_BOX_NO_LABEL
  102. );
  103. $formSearch->addHidden('search_type', 1);
  104. $formSearch->addText(
  105. 'q',
  106. get_lang('Search'),
  107. false,
  108. [
  109. 'aria-label' => get_lang('SearchUsers'),
  110. 'custom' => true,
  111. 'placeholder' => get_lang('SearchUsersByName'),
  112. ]
  113. );
  114. // Added a Jquery Function to return the Preview of OpenGraph URL Content
  115. $htmlHeadXtra[] = SocialManager::getScriptToGetOpenGraph();
  116. $tpl = new Template(get_lang('SocialNetwork'));
  117. SocialManager::setSocialUserBlock($tpl, $user_id, 'home');
  118. $tpl->assign('add_post_form', $wallSocialAddPost);
  119. $tpl->assign('posts', $posts);
  120. $tpl->assign('social_menu_block', $menu);
  121. $tpl->assign('social_auto_extend_link', $socialAutoExtendLink);
  122. $tpl->assign('search_friends_form', $formSearch->returnForm());
  123. $tpl->assign('social_friend_block', $friend_html);
  124. $tpl->assign('social_search_block', $social_search_block);
  125. $tpl->assign('social_skill_block', SocialManager::getSkillBlock($user_id, 'vertical'));
  126. $tpl->assign('social_group_block', $social_group_block);
  127. $tpl->assign('session_list', $social_session_block);
  128. $social_layout = $tpl->get_template('social/home.tpl');
  129. $tpl->display($social_layout);