home.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. $userGroup = new UserGroup();
  24. //fast upload image
  25. if (api_get_setting('profile', 'picture') == 'true') {
  26. $form = new FormValidator('profile', 'post', 'home.php', null, []);
  27. // PICTURE
  28. $form->addElement('file', 'picture', get_lang('AddImage'));
  29. $form->addProgress();
  30. if (!empty($user_data['picture_uri'])) {
  31. $form->addElement(
  32. 'checkbox',
  33. 'remove_picture',
  34. null,
  35. get_lang('DelImage')
  36. );
  37. }
  38. $allowed_picture_types = api_get_supported_image_extensions();
  39. $form->addRule(
  40. 'picture',
  41. get_lang('OnlyImagesAllowed').' ('.implode(
  42. ',',
  43. $allowed_picture_types
  44. ).')',
  45. 'filetype',
  46. $allowed_picture_types
  47. );
  48. $form->addButtonSave(get_lang('SaveSettings'), 'apply_change');
  49. if ($form->validate()) {
  50. $user_data = $form->getSubmitValues();
  51. // upload picture if a new one is provided
  52. if ($_FILES['picture']['size']) {
  53. if ($new_picture = UserManager::update_user_picture(
  54. api_get_user_id(),
  55. $_FILES['picture']['name'],
  56. $_FILES['picture']['tmp_name']
  57. )) {
  58. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  59. $sql = "UPDATE $table_user
  60. SET
  61. picture_uri = '$new_picture'
  62. WHERE user_id = ".api_get_user_id();
  63. $result = Database::query($sql);
  64. }
  65. }
  66. }
  67. }
  68. SocialManager::handlePosts(api_get_self());
  69. $threadList = SocialManager::getThreadList($user_id);
  70. $threadIdList = [];
  71. if (!empty($threadList)) {
  72. $threadIdList = array_column($threadList, 'id');
  73. }
  74. // Social Post Wall
  75. $posts = SocialManager::getMyWallMessages($user_id, 0, 10, $threadIdList);
  76. $countPost = $posts['count'];
  77. $posts = $posts['posts'];
  78. SocialManager::getScrollJs($countPost, $htmlHeadXtra);
  79. // Block Menu
  80. $social_menu_block = SocialManager::show_social_menu('home');
  81. $social_search_block = Display::panel(
  82. UserManager::get_search_form(''),
  83. get_lang('SearchUsers')
  84. );
  85. $social_group_block = SocialManager::getGroupBlock($user_id);
  86. // My friends
  87. $friend_html = SocialManager::listMyFriendsBlock($user_id);
  88. // Block Social Sessions
  89. $social_session_block = null;
  90. $user_info = api_get_user_info($user_id);
  91. $sessionList = SessionManager::getSessionsFollowedByUser($user_id, $user_info['status']);
  92. if (count($sessionList) > 0) {
  93. $social_session_block = $sessionList;
  94. }
  95. $wallSocialAddPost = SocialManager::getWallForm(api_get_self());
  96. $socialAutoExtendLink = SocialManager::getAutoExtendLink($user_id, $countPost);
  97. $formSearch = new FormValidator(
  98. 'find_friends_form',
  99. 'get',
  100. api_get_path(WEB_CODE_PATH).'social/search.php?search_type=1',
  101. null,
  102. null,
  103. FormValidator::LAYOUT_BOX_NO_LABEL
  104. );
  105. $formSearch->addHidden('search_type', 1);
  106. $formSearch->addText(
  107. 'q',
  108. get_lang('Search'),
  109. false,
  110. [
  111. 'aria-label' => get_lang('SearchUsers'),
  112. 'custom' => true,
  113. 'placeholder' => get_lang('SearchUsersByName'),
  114. ]
  115. );
  116. // Added a Jquery Function to return the Preview of OpenGraph URL Content
  117. $htmlHeadXtra[] = SocialManager::getScriptToGetOpenGraph();
  118. $tpl = new Template(get_lang('SocialNetwork'));
  119. SocialManager::setSocialUserBlock($tpl, $user_id, 'home');
  120. $tpl->assign('social_wall_block', $wallSocialAddPost);
  121. $tpl->assign('social_post_wall_block', $posts);
  122. $tpl->assign('social_menu_block', $social_menu_block);
  123. $tpl->assign('social_auto_extend_link', $socialAutoExtendLink);
  124. $tpl->assign('search_friends_form', $formSearch->returnForm());
  125. $tpl->assign('social_friend_block', $friend_html);
  126. $tpl->assign('social_search_block', $social_search_block);
  127. $tpl->assign('social_skill_block', SocialManager::getSkillBlock($user_id, 'vertical'));
  128. $tpl->assign('social_group_block', $social_group_block);
  129. $tpl->assign('session_list', $social_session_block);
  130. $social_layout = $tpl->get_template('social/home.tpl');
  131. $tpl->display($social_layout);