home_follow.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: home_follow.php 33660 2013-07-29 07:51:05Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if(!$_G['uid']) {
  12. showmessage('login_before_enter_home', null, array(), array('showmsg' => true, 'login' => 1));
  13. }
  14. $dos = array('feed', 'follower', 'following', 'view');
  15. $do = (!empty($_GET['do']) && in_array($_GET['do'], $dos)) ? $_GET['do'] : (!$_GET['uid'] ? 'feed' : 'view');
  16. $page = empty($_GET['page']) ? 1 : intval($_GET['page']);
  17. if($page<1) $page=1;
  18. $perpage = 20;
  19. $start = ($page-1)*$perpage;
  20. $multi = '';
  21. $theurl = 'home.php?mod='.($do == 'view' ? 'space' : 'follow').(!in_array($do, array('feed', 'view')) ? '&do='.$do : '');
  22. $uid = $_GET['uid'] ? $_GET['uid'] : $_G['uid'];
  23. $viewself = $uid == $_G['uid'] ? true : false;
  24. $space = $viewself ? $_G['member'] : getuserbyuid($uid, 1);
  25. if(empty($space)) {
  26. showmessage('follow_visituser_not_exist');
  27. } elseif(in_array($space['groupid'], array(4, 5, 6)) && ($_G['adminid'] != 1 && $space['uid'] != $_G['uid'])) {
  28. dheader("Location:home.php?mod=space&uid=$uid&do=profile");
  29. }
  30. space_merge($space, 'count');
  31. space_merge($space, 'profile');
  32. space_merge($space, 'field_home');
  33. if($viewself) {
  34. $showguide = false;
  35. } else {
  36. $theurl .= $uid ? '&uid='.$uid : '';
  37. $do = $do == 'feed' ? 'view' : $do;
  38. $flag = C::t('home_follow')->fetch_status_by_uid_followuid($_G['uid'], $uid);
  39. }
  40. $showrecommend = true;
  41. $archiver = $primary = 1;
  42. $followerlist = array();
  43. $space['bio'] = cutstr($space['bio'], 200);
  44. $lastviewtime = 0;
  45. if($do == 'feed') {
  46. $view = 'follow';
  47. if(in_array($_GET['view'], array('special', 'follow', 'other'))) {
  48. $view = $_GET['view'];
  49. $theurl .= '&view='.$_GET['view'];
  50. }
  51. $vuid = $view == 'other' ? 0 : $_G['uid'];
  52. $list = getfollowfeed($vuid, $view, false, $start, $perpage);
  53. if((empty($list['feed']) || count($list['feed']) < 20) && (!empty($list['user']) || $view == 'other')) {
  54. $primary = 0;
  55. $alist = getfollowfeed($vuid, $view, true, $start, $perpage);
  56. if(empty($list['feed']) && empty($alist['feed'])) {
  57. $showguide = true;
  58. $archiver = 0;
  59. } else {
  60. $showguide = false;
  61. foreach($alist as $key => $values) {
  62. if($key != 'user') {
  63. foreach($values as $id => $value) {
  64. if(!isset($list[$key][$id])) {
  65. $list[$key][$id] = $value;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. } elseif(empty($list['user']) && $view != 'other') {
  72. $archiver = $primary = 0;
  73. $showguide = false;
  74. }
  75. if($showguide) {
  76. if(!empty($_G['cookie']['lastshowtime'])) {
  77. $time = explode('|', $_G['cookie']['lastshowtime']);
  78. $today = strtotime(dgmdate($_G['timestamp'], 'Y-m-d'));
  79. if($time[0] == $uid && (TIMESTAMP - $time[1] < 86400 && $time[1] > $today)) {
  80. $showguide = false;
  81. }
  82. }
  83. dsetcookie('lastshowtime', $uid.'|'.TIMESTAMP, 86400);
  84. }
  85. if(!empty($_G['cookie']['lastviewtime'])) {
  86. $time = explode('|', $_G['cookie']['lastviewtime']);
  87. if($time[0] == $_G['uid']) {
  88. $lastviewtime = $time[1];
  89. }
  90. } else {
  91. $lastviewtime = getuserprofile('lastactivity');
  92. }
  93. dsetcookie('lastviewtime', $_G['uid'].'|'.TIMESTAMP, 31536000);
  94. if($_G['member']['newprompt_num']['follow']) {
  95. C::t('home_notification')->delete_by_type('follow', $_G['uid']);
  96. helper_notification::update_newprompt($_G['uid'], 'follow');
  97. }
  98. $recommend = $users = array();
  99. if(helper_access::check_module('follow')) {
  100. loadcache('recommend_follow');
  101. if(empty($_G['cache']['recommend_follow']) || !empty($_G['cache']['recommend_follow']) && (empty($_G['cache']['recommend_follow']['users']) || TIMESTAMP - $_G['cache']['recommend_follow']['dateline'] > 86400)) {
  102. foreach(C::t('home_specialuser')->fetch_all_by_status(0, 10) as $value) {
  103. $recommend[$value['uid']] = $value['username'];
  104. }
  105. unset($recommend[$_G['uid']]);
  106. if(count($recommend) < 10) {
  107. $followuser = C::t('common_member_count')->range_by_field(0, 100, 'follower', 'DESC');
  108. $userstatus = C::t('common_member_status')->fetch_all_orderby_lastpost(array_keys($followuser), 0, 20);
  109. $users = C::t('common_member')->fetch_all_username_by_uid(array_keys($userstatus));
  110. }
  111. savecache('recommend_follow', array('dateline'=>TIMESTAMP, 'users'=>$users, 'defaultusers' => $recommend));
  112. } else {
  113. $users = &$_G['cache']['recommend_follow']['users'];
  114. $recommend = &$_G['cache']['recommend_follow']['defaultusers'];
  115. }
  116. if(!empty($users)) {
  117. if(count($recommend) < 10) {
  118. $randkeys = array_rand($users, 11 - count($recommend));
  119. foreach($randkeys as $ruid) {
  120. if($ruid != $_G['uid']) {
  121. $recommend[$ruid] = $users[$ruid];
  122. }
  123. }
  124. }
  125. }
  126. if($do == 'following') {
  127. foreach($list as $ruid => $user) {
  128. if(isset($recommend[$ruid])) {
  129. unset($recommend[$ruid]);
  130. }
  131. }
  132. }
  133. if($recommend) {
  134. $users = C::t('home_follow')->fetch_all_by_uid_followuid($_G['uid'], array_keys($recommend));
  135. foreach($users as $ruid => $user) {
  136. if(isset($recommend[$ruid])) {
  137. unset($recommend[$ruid]);
  138. }
  139. }
  140. }
  141. }
  142. $navactives = array('feed' => ' class="a"');
  143. $actives = array($view => ' class="a"');
  144. list($seccodecheck, $secqaacheck) = seccheck('publish');
  145. } elseif($do == 'view') {
  146. $list = getfollowfeed($uid, 'self', false, $start, $perpage);
  147. if(empty($list['feed'])) {
  148. $primary = 0;
  149. $list = getfollowfeed($uid, 'self', true, $start, $perpage);
  150. if(empty($list['user'])) {
  151. $archiver = 0;
  152. }
  153. }
  154. if(!isset($_G['cache']['forums'])) {
  155. loadcache('forums');
  156. }
  157. if(helper_access::check_module('follow')) {
  158. $followerlist = C::t('home_follow')->fetch_all_following_by_uid($uid, 0, 9);
  159. }
  160. $seccodecheck = ($_G['setting']['seccodestatus'] & 4) && (!$_G['setting']['seccodedata']['minposts'] || getuserprofile('posts') < $_G['setting']['seccodedata']['minposts']);
  161. $secqaacheck = $_G['setting']['secqaa']['status'] & 2 && (!$_G['setting']['secqaa']['minposts'] || getuserprofile('posts') < $_G['setting']['secqaa']['minposts']);
  162. } elseif($do == 'follower') {
  163. $count = C::t('home_follow')->count_follow_user($uid, 1);
  164. if($viewself && !empty($_G['member']['newprompt_num']['follower'])) {
  165. $newfollower = C::t('home_notification')->fetch_all_by_uid($uid, -1, 'follower', 0, $_G['member']['newprompt_num']['follower']);
  166. $newfollower_list = array();
  167. foreach($newfollower as $val) {
  168. $newfollower_list[] = $val['from_id'];
  169. }
  170. C::t('home_notification')->delete_by_type('follower', $_G['uid']);
  171. helper_notification::update_newprompt($_G['uid'], 'follower');
  172. }
  173. if($count) {
  174. $list = C::t('home_follow')->fetch_all_follower_by_uid($uid, $start, $perpage);
  175. $multi = multi($count, $perpage, $page, $theurl);
  176. }
  177. if(helper_access::check_module('follow')) {
  178. $followerlist = C::t('home_follow')->fetch_all_following_by_uid($uid, 0, 9);
  179. }
  180. $navactives = array($do => ' class="a"');
  181. } elseif($do == 'following') {
  182. $count = C::t('home_follow')->count_follow_user($uid);
  183. if($count) {
  184. $status = $_GET['status'] ? 1 : 0;
  185. $list = C::t('home_follow')->fetch_all_following_by_uid($uid, $status, $start, $perpage);
  186. $multi = multi($count, $perpage, $page, $theurl);
  187. }
  188. if(helper_access::check_module('follow')) {
  189. $followerlist = C::t('home_follow')->fetch_all_follower_by_uid($uid, 9);
  190. }
  191. $navactives = array($do => ' class="a"');
  192. }
  193. if(($do == 'follower' || $do == 'following') && $list) {
  194. $uids = array_keys($list);
  195. $fieldhome = C::t('common_member_field_home')->fetch_all($uids);
  196. foreach($fieldhome as $fuid => $val) {
  197. $list[$fuid]['recentnote'] = $val['recentnote'];
  198. }
  199. $memberinfo = C::t('common_member_count')->fetch_all($uids);
  200. $memberprofile = C::t('common_member_profile')->fetch_all($uids);
  201. if(!$viewself) {
  202. $myfollow = C::t('home_follow')->fetch_all_by_uid_followuid($_G['uid'], $uids);
  203. foreach($uids as $muid) {
  204. $list[$muid]['mutual'] = 0;
  205. if(!empty($myfollow[$muid])) {
  206. $list[$muid]['mutual'] = $myfollow[$muid]['mutual'] ? 1 : -1;
  207. }
  208. }
  209. }
  210. $specialfollow = C::t('home_follow')->fetch_all_following_by_uid($uid, 1, 10);
  211. }
  212. if($viewself) {
  213. if(!isset($_G['cache']['forums'])) {
  214. loadcache('forums');
  215. }
  216. $fields = C::t('forum_forumfield')->fetch_all_by_fid(array_keys($_G['cache']['forums']));
  217. foreach($fields as $fid => $field) {
  218. if(!empty($field['threadsorts'])) {
  219. unset($_G['cache']['forums'][$fid]);
  220. }
  221. }
  222. require_once libfile('function/forumlist');
  223. $forumlist = forumselect();
  224. $defaultforum = $_G['setting']['followforumid'] ? $_G['cache']['forums'][$_G['setting']['followforumid']] : array();
  225. require_once libfile('function/upload');
  226. $swfconfig = getuploadconfig($_G['uid']);
  227. }
  228. if($do == 'feed') {
  229. $navigation = ' <em>&rsaquo;</em> <a href="home.php?mod=follow&view='.$view.'">'.lang('space', 'follow_view_'.$view).'</a>';
  230. $navtitle = lang('space', 'follow_view_'.$view);
  231. } elseif($do == 'view') {
  232. $navigation = ' <em>&rsaquo;</em> <a href="home.php?mod=space&uid='.$uid.'">'.$space['username'].'</a>';
  233. if($type != 'feed') {
  234. $navigation .= ' <em>&rsaquo;</em> '.lang('space', 'follow_view_type_feed').'</a>';
  235. }
  236. $navtitle = lang('space', 'follow_view_feed', array('who' => $space['username']));
  237. } else {
  238. $navigation = ' <em>&rsaquo;</em> <a href="home.php?mod=space&uid='.$uid.'">'.$space['username'].'</a> <em>&rsaquo;</em> '.lang('space', 'follow_view_'.($viewself?'my':'do').'_'.$do);
  239. $navtitle = lang('space', 'follow_view_'.($viewself?'my':'do').'_'.$do);
  240. }
  241. $metakeywords = $navtitle;
  242. $metadescription = $navtitle;
  243. $navtitle = helper_seo::get_title_page($navtitle, $_G['page']);
  244. include template('diy:home/follow_feed');
  245. ?>