space_home.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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: space_home.php 30780 2012-06-19 06:01:52Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if(!$_G['uid'] && $_G['setting']['privacy']['view']['home']) {
  12. showmessage('home_no_privilege', '', array(), array('login' => true));
  13. }
  14. require_once libfile('function/feed');
  15. if(empty($_G['setting']['feedhotday'])) {
  16. $_G['setting']['feedhotday'] = 2;
  17. }
  18. $minhot = $_G['setting']['feedhotmin']<1?3:$_G['setting']['feedhotmin'];
  19. space_merge($space, 'count');
  20. if(empty($_GET['view'])) {
  21. if($space['self']) {
  22. if($_G['setting']['showallfriendnum'] && $space['friends'] < $_G['setting']['showallfriendnum']) {
  23. $_GET['view'] = 'all';
  24. } else {
  25. $_GET['view'] = 'we';
  26. }
  27. } else {
  28. $_GET['view'] = 'all';
  29. }
  30. } elseif(!in_array($_GET['view'], array('we', 'me', 'all', 'app'))) {
  31. $_GET['view'] = 'all';
  32. }
  33. if(empty($_GET['order'])) {
  34. $_GET['order'] = 'dateline';
  35. }
  36. $perpage = $_G['setting']['feedmaxnum']<20?20:$_G['setting']['feedmaxnum'];
  37. $perpage = mob_perpage($perpage);
  38. if($_GET['view'] == 'all' && $_GET['order'] == 'hot') {
  39. $perpage = 50;
  40. }
  41. $page = intval($_GET['page']);
  42. if($page < 1) $page = 1;
  43. $start = ($page-1)*$perpage;
  44. ckstart($start, $perpage);
  45. $_G['home_today'] = $_G['timestamp'] - ($_G['timestamp'] + $_G['setting']['timeoffset'] * 3600) % 86400;
  46. $gets = array(
  47. 'mod' => 'space',
  48. 'uid' => $space['uid'],
  49. 'do' => 'home',
  50. 'view' => $_GET['view'],
  51. 'order' => $_GET['order'],
  52. 'appid' => $_GET['appid'],
  53. 'type' => $_GET['type'],
  54. 'icon' => $_GET['icon']
  55. );
  56. $theurl = 'home.php?'.url_implode($gets);
  57. $hotlist = array();
  58. if(!IS_ROBOT) {
  59. $feed_users = $feed_list = $user_list = $filter_list = $list = $magic = array();
  60. if($_GET['view'] != 'app') {
  61. if($space['self'] && empty($start) && $_G['setting']['feedhotnum'] > 0 && ($_GET['view'] == 'we' || $_GET['view'] == 'all')) {
  62. $hotlist_all = array();
  63. $hotstarttime = $_G['timestamp'] - $_G['setting']['feedhotday']*3600*24;
  64. $query = C::t('home_feed')->fetch_all_by_hot($hotstarttime);
  65. foreach ($query as $value) {
  66. if($value['hot']>0 && ckfriend($value['uid'], $value['friend'], $value['target_ids'])) {
  67. if(empty($hotlist)) {
  68. $hotlist[$value['feedid']] = $value;
  69. } else {
  70. $hotlist_all[$value['feedid']] = $value;
  71. }
  72. }
  73. }
  74. $nexthotnum = $_G['setting']['feedhotnum'] - 1;
  75. if($nexthotnum > 0) {
  76. if(count($hotlist_all)> $nexthotnum) {
  77. $hotlist_key = array_rand($hotlist_all, $nexthotnum);
  78. if($nexthotnum == 1) {
  79. $hotlist[$hotlist_key] = $hotlist_all[$hotlist_key];
  80. } else {
  81. foreach ($hotlist_key as $key) {
  82. $hotlist[$key] = $hotlist_all[$key];
  83. }
  84. }
  85. } else {
  86. $hotlist = array_merge($hotlist, $hotlist_all);
  87. }
  88. }
  89. }
  90. }
  91. $need_count = true;
  92. $uids = array();
  93. $multi = $hot = '';
  94. if($_GET['view'] == 'all') {
  95. if($_GET['order'] == 'dateline') {
  96. $ordersql = "dateline DESC";
  97. $f_index = '';
  98. $findex = '';
  99. $orderactives = array('dateline' => ' class="a"');
  100. } else {
  101. $hot = $minhot;
  102. $ordersql = "dateline DESC";
  103. $f_index = '';
  104. $findex = '';
  105. $orderactives = array('hot' => ' class="a"');
  106. }
  107. } elseif($_GET['view'] == 'me') {
  108. $uids = array($space['uid']);
  109. $ordersql = "dateline DESC";
  110. $f_index = '';
  111. $findex = '';
  112. $diymode = 1;
  113. if($space['self'] && $_GET['from'] != 'space') $diymode = 0;
  114. } elseif($_GET['view'] == 'app' && $_G['setting']['my_app_status']) {
  115. $uids = null;
  116. if ($_GET['type'] == 'all') {
  117. $ordersql = "dateline DESC";
  118. $f_index = '';
  119. $findex = '';
  120. } else {
  121. if($_GET['type'] == 'me') {
  122. $uids = $_G['uid'];
  123. $ordersql = "dateline DESC";
  124. $f_index = '';
  125. $findex = '';
  126. } else {
  127. $uids = array_merge(explode(',', $space['feedfriend']), 0);
  128. $ordersql = "dateline DESC";
  129. $f_index = 'USE INDEX(dateline)';
  130. $findex = 'dateline';
  131. $_GET['type'] = 'we';
  132. $_G['home_tpl_hidden_time'] = 1;
  133. }
  134. }
  135. $icon = empty($_GET['icon'])?'':trim($_GET['icon']);
  136. $feed_list = $appfeed_list = $hiddenfeed_list = $filter_list = $hiddenfeed_num = $icon_num = array();
  137. $count = $filtercount = 0;
  138. foreach(C::t('home_feed_app')->fetch_all_by_uid_icon($uids, $icon, $start, $perpage) as $value) {
  139. $feed_list[$value['icon']][] = $value;
  140. $count++;
  141. }
  142. $multi = simplepage($count, $perpage, $page, $theurl);
  143. require_once libfile('function/feed');
  144. $list = array();
  145. foreach ($feed_list as $key => $values) {
  146. $nowcount = 0;
  147. foreach ($values as $value) {
  148. $value = mkfeed($value);
  149. $nowcount++;
  150. if($nowcount>5 && empty($icon)) {
  151. break;
  152. }
  153. $list[$key][] = $value;
  154. }
  155. }
  156. $need_count = false;
  157. $typeactives = array($_GET['type'] => ' class="a"');
  158. } else {
  159. space_merge($space, 'field_home');
  160. if(empty($space['feedfriend'])) {
  161. $need_count = false;
  162. } else {
  163. $uids = array_merge(explode(',', $space['feedfriend']), array(0));
  164. $ordersql = "dateline DESC";
  165. $f_index = 'USE INDEX(dateline)';
  166. $findex = 'dateline';
  167. }
  168. }
  169. $appid = empty($_GET['appid'])?0:intval($_GET['appid']);
  170. $icon = empty($_GET['icon'])?'':trim($_GET['icon']);
  171. $gid = !isset($_GET['gid'])?'-1':intval($_GET['gid']);
  172. if($gid>=0) {
  173. $fuids = array();
  174. $query = C::t('home_friend')->fetch_all_by_uid_gid($_G['uid'], $gid);
  175. foreach($query as $value) {
  176. $fuids[] = $value['fuid'];
  177. }
  178. if(empty($fuids)) {
  179. $need_count = false;
  180. } else {
  181. $uids = $fuids;
  182. }
  183. }
  184. $gidactives[$gid] = ' class="a"';
  185. $count = $filtercount = 0;
  186. if($need_count) {
  187. $query = C::t('home_feed')->fetch_all_by_search(1, $uids, $icon, '', '', '', $hot, '', $start, $perpage, $findex, $appid);
  188. if($_GET['view'] == 'me') {
  189. foreach ($query as $value) {
  190. if(!isset($hotlist[$value['feedid']]) && !isset($hotlist_all[$value['feedid']]) && ckfriend($value['uid'], $value['friend'], $value['target_ids'])) {
  191. $value = mkfeed($value);
  192. if($value['dateline']>=$_G['home_today']) {
  193. $list['today'][] = $value;
  194. } elseif ($value['dateline']>=$_G['home_today']-3600*24) {
  195. $list['yesterday'][] = $value;
  196. } else {
  197. $theday = dgmdate($value['dateline'], 'Y-m-d');
  198. $list[$theday][] = $value;
  199. }
  200. }
  201. $count++;
  202. }
  203. } else {
  204. $hash_datas = array();
  205. $more_list = array();
  206. $uid_feedcount = array();
  207. foreach($query as $value) {
  208. if(!isset($hotlist[$value['feedid']]) && !isset($hotlist_all[$value['feedid']]) && ckfriend($value['uid'], $value['friend'], $value['target_ids'])) {
  209. $value = mkfeed($value);
  210. if(ckicon_uid($value)) {
  211. if($value['dateline']>=$_G['home_today']) {
  212. $dkey = 'today';
  213. } elseif ($value['dateline']>=$_G['home_today']-3600*24) {
  214. $dkey = 'yesterday';
  215. } else {
  216. $dkey = dgmdate($value['dateline'], 'Y-m-d');
  217. }
  218. $maxshownum = 3;
  219. if(empty($value['uid'])) $maxshownum = 10;
  220. if(empty($value['hash_data'])) {
  221. if(empty($feed_users[$dkey][$value['uid']])) $feed_users[$dkey][$value['uid']] = $value;
  222. if(empty($uid_feedcount[$dkey][$value['uid']])) $uid_feedcount[$dkey][$value['uid']] = 0;
  223. $uid_feedcount[$dkey][$value['uid']]++;
  224. if($uid_feedcount[$dkey][$value['uid']]>$maxshownum) {
  225. $more_list[$dkey][$value['uid']][] = $value;
  226. } else {
  227. $feed_list[$dkey][$value['uid']][] = $value;
  228. }
  229. } elseif(empty($hash_datas[$value['hash_data']])) {
  230. $hash_datas[$value['hash_data']] = 1;
  231. if(empty($feed_users[$dkey][$value['uid']])) $feed_users[$dkey][$value['uid']] = $value;
  232. if(empty($uid_feedcount[$dkey][$value['uid']])) $uid_feedcount[$dkey][$value['uid']] = 0;
  233. $uid_feedcount[$dkey][$value['uid']] ++;
  234. if($uid_feedcount[$dkey][$value['uid']]>$maxshownum) {
  235. $more_list[$dkey][$value['uid']][] = $value;
  236. } else {
  237. $feed_list[$dkey][$value['uid']][$value['hash_data']] = $value;
  238. }
  239. } else {
  240. $user_list[$value['hash_data']][] = "<a href=\"home.php?mod=space&uid=$value[uid]\">$value[username]</a>";
  241. }
  242. } else {
  243. $filtercount++;
  244. $filter_list[] = $value;
  245. }
  246. }
  247. $count++;
  248. }
  249. }
  250. $multi = simplepage($count, $perpage, $page, $theurl);
  251. }
  252. }
  253. $olfriendlist = $visitorlist = $task = $ols = $birthlist = $guidelist = array();
  254. $oluids = array();
  255. $groups = array();
  256. $defaultusers = $newusers = $showusers = array();
  257. if($space['self'] && empty($start)) {
  258. space_merge($space, 'field_home');
  259. if($_GET['view'] == 'we') {
  260. require_once libfile('function/friend');
  261. $groups = friend_group_list();
  262. }
  263. $isnewer = ($_G['timestamp']-$space['regdate'] > 3600*24*7) ?0:1;
  264. if($isnewer && $_G['setting']['homestyle']) {
  265. $friendlist = array();
  266. $query = C::t('home_friend')->fetch_all($space['uid']);
  267. foreach($query as $value) {
  268. $friendlist[$value['fuid']] = 1;
  269. }
  270. foreach(C::t('home_specialuser')->fetch_all_by_status(1) as $value) {
  271. if(empty($friendlist[$value['uid']])) {
  272. $defaultusers[] = $value;
  273. $oluids[] = $value['uid'];
  274. }
  275. }
  276. }
  277. if($space['newprompt']) {
  278. space_merge($space, 'status');
  279. }
  280. if($_G['setting']['homestyle']) {
  281. foreach(C::t('home_visitor')->fetch_all_by_uid($space['uid'], 12) as $value) {
  282. $visitorlist[$value['vuid']] = $value;
  283. $oluids[] = $value['vuid'];
  284. }
  285. if($oluids) {
  286. foreach(C::app()->session->fetch_all_by_uid($oluids) as $value) {
  287. if(!$value['invisible']) {
  288. $ols[$value['uid']] = 1;
  289. } elseif ($visitorlist[$value['uid']]) {
  290. unset($visitorlist[$value['uid']]);
  291. }
  292. }
  293. }
  294. $oluids = array();
  295. $olfcount = 0;
  296. if($space['feedfriend']) {
  297. foreach(C::app()->session->fetch_all_by_uid(explode(',', $space['feedfriend']), 15) as $value) {
  298. if($olfcount < 15 && !$value['invisible']) {
  299. $olfriendlist[$value['uid']] = $value;
  300. $ols[$value['uid']] = 1;
  301. $oluids[$value['uid']] = $value['uid'];
  302. $olfcount++;
  303. }
  304. }
  305. }
  306. if($olfcount < 15) {
  307. $query = C::t('home_friend')->fetch_all_by_uid($space['uid'], 0, 32, true);
  308. foreach($query as $value) {
  309. $value['uid'] = $value['fuid'];
  310. $value['username'] = $value['fusername'];
  311. if(empty($oluids[$value['uid']])) {
  312. $olfriendlist[$value['uid']] = $value;
  313. $olfcount++;
  314. if($olfcount == 15) break;
  315. }
  316. }
  317. }
  318. if($space['feedfriend']) {
  319. $birthdaycache = C::t('forum_spacecache')->fetch($_G['uid'], 'birthday');
  320. if(empty($birthdaycache) || TIMESTAMP > $birthdaycache['expiration']) {
  321. $birthlist = C::t('common_member_profile')->fetch_all_will_birthday_by_uid($space['feedfriend']);
  322. C::t('forum_spacecache')->insert(array(
  323. 'uid' => $_G['uid'],
  324. 'variable' => 'birthday',
  325. 'value' => serialize($birthlist),
  326. 'expiration' => getexpiration(),
  327. ), false, true);
  328. } else {
  329. $birthlist = dunserialize($birthdaycache['value']);
  330. }
  331. }
  332. if($_G['setting']['taskon']) {
  333. require_once libfile('class/task');
  334. $tasklib = & task::instance();
  335. $taskarr = $tasklib->tasklist('canapply');
  336. $task = $taskarr[array_rand($taskarr)];
  337. }
  338. if($_G['setting']['magicstatus']) {
  339. loadcache('magics');
  340. if(!empty($_G['cache']['magics'])) {
  341. $magic = $_G['cache']['magics'][array_rand($_G['cache']['magics'])];
  342. $magic['description'] = cutstr($magic['description'], 34, '');
  343. $magic['pic'] = strtolower($magic['identifier']).'.gif';
  344. }
  345. }
  346. }
  347. } elseif(empty($_G['uid'])) {
  348. $defaultusers = C::t('home_specialuser')->fetch_all_by_status(1, 12);
  349. $query = C::t('home_show')->fetch_all_by_credit(0, 12); //DB::query("SELECT * FROM ".DB::table('home_show')." ORDER BY credit DESC LIMIT 0,12");
  350. foreach($query as $value) {
  351. $showusers[] = $value;
  352. }
  353. foreach(C::t('common_member')->range(0, 12,'DESC') as $uid => $value) {
  354. $value['regdate'] = dgmdate($value['regdate'], 'u', 9999, 'm-d');
  355. $newusers[$uid] = $value;
  356. }
  357. }
  358. dsetcookie('home_readfeed', $_G['timestamp'], 365*24*3600);
  359. if($_G['uid']) {
  360. $defaultstr = getdefaultdoing();
  361. space_merge($space, 'status');
  362. if(!$space['profileprogress']) {
  363. include_once libfile('function/profile');
  364. $space['profileprogress'] = countprofileprogress();
  365. }
  366. }
  367. $actives = array($_GET['view'] => ' class="a"');
  368. if($_GET['from'] == 'space') {
  369. if($_GET['do'] == 'home') {
  370. $navtitle = lang('space', 'sb_feed', array('who' => $space['username']));
  371. $metakeywords = lang('space', 'sb_feed', array('who' => $space['username']));
  372. $metadescription = lang('space', 'sb_feed', array('who' => $space['username']));
  373. }
  374. } else {
  375. list($navtitle, $metadescription, $metakeywords) = get_seosetting('home');
  376. if(!$navtitle) {
  377. $navtitle = $_G['setting']['navs'][4]['navname'];
  378. $nobbname = false;
  379. } else {
  380. $nobbname = true;
  381. }
  382. if(!$metakeywords) {
  383. $metakeywords = $_G['setting']['navs'][4]['navname'];
  384. }
  385. if(!$metadescription) {
  386. $metadescription = $_G['setting']['navs'][4]['navname'];
  387. }
  388. }
  389. if(empty($cp_mode)) include_once template("diy:home/space_home");
  390. ?>