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. $user_data = $form->getSubmitValues();
  50. // upload picture if a new one is provided
  51. if ($_FILES['picture']['size']) {
  52. if ($new_picture = UserManager::update_user_picture(
  53. api_get_user_id(),
  54. $_FILES['picture']['name'],
  55. $_FILES['picture']['tmp_name']
  56. )) {
  57. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  58. $sql = "UPDATE $table_user
  59. SET
  60. picture_uri = '$new_picture'
  61. WHERE user_id = ".api_get_user_id();
  62. $result = Database::query($sql);
  63. }
  64. }
  65. }
  66. }
  67. SocialManager::handlePosts(api_get_self());
  68. $threadList = SocialManager::getThreadList($user_id);
  69. $threadIdList = [];
  70. if (!empty($threadList)) {
  71. $threadIdList = array_column($threadList, 'id');
  72. }
  73. $posts = SocialManager::getMyWallMessages($user_id, 0, 10, $threadIdList);
  74. $countPost = $posts['count'];
  75. $posts = $posts['posts'];
  76. SocialManager::getScrollJs($countPost, $htmlHeadXtra);
  77. // Block Menu
  78. $menu = SocialManager::show_social_menu('home');
  79. $social_search_block = Display::panel(
  80. UserManager::get_search_form(''),
  81. get_lang('SearchUsers')
  82. );
  83. $social_group_block = SocialManager::getGroupBlock($user_id);
  84. // My friends
  85. $friend_html = SocialManager::listMyFriendsBlock($user_id);
  86. // Block Social Sessions
  87. $social_session_block = null;
  88. $user_info = api_get_user_info($user_id);
  89. $sessionList = SessionManager::getSessionsFollowedByUser($user_id, $user_info['status']);
  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);