space_friend.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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_friend.php 32006 2012-10-30 09:51:28Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $perpage = 24;
  12. $perpage = mob_perpage($perpage);
  13. $list = $ols = $fuids = array();
  14. $count = 0;
  15. $page = empty($_GET['page'])?0:intval($_GET['page']);
  16. if($page<1) $page = 1;
  17. $start = ($page-1)*$perpage;
  18. if(empty($_GET['view']) || $_GET['view'] == 'all') $_GET['view'] = 'me';
  19. ckstart($start, $perpage);
  20. if($_GET['view'] == 'online') {
  21. $theurl = "home.php?mod=space&uid=$space[uid]&do=friend&view=online";
  22. $actives = array('me'=>' class="a"');
  23. space_merge($space, 'field_home');
  24. $onlinedata = array();
  25. $wheresql = '';
  26. if($_GET['type']=='near') {
  27. $theurl = "home.php?mod=space&uid=$space[uid]&do=friend&view=online&type=near";
  28. if(($count = C::app()->session->count_by_ip($_G['clientip']))) {
  29. $onlinedata = C::app()->session->fetch_all_by_ip($_G['clientip'], $start, $perpage);
  30. }
  31. } elseif($_GET['type']=='friend') {
  32. $theurl = "home.php?mod=space&uid=$space[uid]&do=friend&view=online&type=friend";
  33. if(!empty($space['feedfriend'])) {
  34. $onlinedata = C::app()->session->fetch_all_by_uid(explode(',', $space['feedfriend']), $start, $perpage);
  35. }
  36. $count = count($onlinedata);
  37. } elseif($_GET['type']=='member') {
  38. $theurl = "home.php?mod=space&uid=$space[uid]&do=friend&view=online&type=member";
  39. $wheresql = " WHERE uid>0";
  40. if(($count = C::app()->session->count(1))) {
  41. $onlinedata = C::app()->session->fetch_member(1, 2, $start, $perpage);
  42. }
  43. } else {
  44. $_GET['type']=='all';
  45. $theurl = "home.php?mod=space&uid=$space[uid]&do=friend&view=online&type=all";
  46. if(($count = C::app()->session->count_invisible(0))) {
  47. $onlinedata = C::app()->session->fetch_member(0, 2, $start, $perpage);
  48. }
  49. }
  50. if($count) {
  51. foreach($onlinedata as $value) {
  52. if($_GET['type']=='near') {
  53. if($value['uid'] == $space['uid']) {
  54. $count = $count-1;
  55. continue;
  56. }
  57. }
  58. if(!$value['invisible']) $ols[$value['uid']] = $value['lastactivity'];
  59. $list[$value['uid']] = $value;
  60. $fuids[$value['uid']] = $value['uid'];
  61. }
  62. if($fuids) {
  63. require_once libfile('function/friend');
  64. friend_check($space['uid'], $fuids);
  65. $fieldhome = C::t('common_member_field_home')->fetch_all($fuids);
  66. foreach(C::t('common_member')->fetch_all($fuids) as $uid => $value) {
  67. $value = array_merge($value, $fieldhome[$uid]);
  68. $value['isfriend'] = $uid==$space['uid'] || $_G["home_friend_".$space['uid'].'_'.$uid] ? 1 : 0;
  69. $list[$uid] = array_merge($list[$uid], $value);
  70. }
  71. }
  72. }
  73. $multi = multi($count, $perpage, $page, $theurl);
  74. } elseif($_GET['view'] == 'visitor' || $_GET['view'] == 'trace') {
  75. $theurl = "home.php?mod=space&uid=$space[uid]&do=friend&view=$_GET[view]";
  76. $actives = array('me'=>' class="a"');
  77. if($_GET['view'] == 'visitor') {
  78. $count = C::t('home_visitor')->count_by_uid($space['uid']);
  79. } else {
  80. $count = C::t('home_visitor')->count_by_vuid($space['uid']);
  81. }
  82. if($count) {
  83. if($_GET['view'] == 'visitor') {
  84. $visitors = C::t('home_visitor')->fetch_all_by_uid($space['uid'], $start, $perpage);
  85. } else {
  86. $visitors = C::t('home_visitor')->fetch_all_by_vuid($space['uid'], $start, $perpage);
  87. }
  88. foreach($visitors as $value) {
  89. if($_GET['view'] == 'visitor') {
  90. $value['uid'] = $value['vuid'];
  91. $value['username'] = $value['vusername'];
  92. }
  93. $fuids[] = $value['uid'];
  94. $list[$value['uid']] = $value;
  95. }
  96. }
  97. $multi = multi($count, $perpage, $page, $theurl);
  98. } elseif($_GET['view'] == 'blacklist') {
  99. $theurl = "home.php?mod=space&uid=$space[uid]&do=friend&view=$_GET[view]";
  100. $actives = array('me'=>' class="a"');
  101. $count = C::t('home_blacklist')->count_by_uid_buid($space['uid']);
  102. if($count) {
  103. $backlist = C::t('home_blacklist')->fetch_all_by_uid($space['uid'], $start,$perpage);
  104. $members = C::t('common_member')->fetch_all(array_keys($backlist));
  105. foreach($backlist as $buid => $value) {
  106. $value = array_merge($value, $members[$buid]);
  107. $value['isfriend'] = 0;
  108. $fuids[] = $value['uid'];
  109. $list[$value['uid']] = $value;
  110. }
  111. }
  112. $multi = multi($count, $perpage, $page, $theurl);
  113. } else {
  114. $theurl = "home.php?mod=space&uid=$space[uid]&do=$do";
  115. $actives = array('me'=>' class="a"');
  116. $_GET['view'] = 'me';
  117. $querydata = array();
  118. if($space['self']) {
  119. require_once libfile('function/friend');
  120. $groups = friend_group_list();
  121. $group = !isset($_GET['group'])?'-1':intval($_GET['group']);
  122. if($group > -1) {
  123. $querydata['gid'] = $group;
  124. $theurl .= "&group=$group";
  125. }
  126. }
  127. if($_GET['searchkey']) {
  128. require_once libfile('function/search');
  129. $querydata['searchkey'] = $_GET['searchkey'];
  130. $theurl .= "&searchkey=$_GET[searchkey]";
  131. }
  132. $count = C::t('home_friend')->fetch_all_search($space['uid'], $querydata['gid'], $querydata['searchkey'], true);
  133. $membercount = C::t('common_member_count')->fetch($_G['uid']);
  134. $friendnum = $membercount['friends'];
  135. unset($membercount);
  136. if($count) {
  137. $query = C::t('home_friend')->fetch_all_search($space['uid'], $querydata['gid'], $querydata['searchkey'], false, $start, $perpage, $_GET['order'] ? true : false);
  138. foreach($query as $value) {
  139. $value['uid'] = $value['fuid'];
  140. $_G["home_friend_".$space['uid'].'_'.$value['uid']] = $value['isfriend'] = 1;
  141. $fuids[$value['uid']] = $value['uid'];
  142. $list[$value['uid']] = $value;
  143. }
  144. } elseif(!$friendnum) {
  145. if(($specialuser_count = C::t('home_specialuser')->count_by_status(1))) {
  146. foreach(C::t('home_specialuser')->fetch_all_by_status(1, 7) as $value) {
  147. if($_G['uid'] !== $value['uid']) {
  148. $fuids[$value['uid']] = $value['uid'];
  149. $specialuser_list[$value['uid']] = $value;
  150. }
  151. if(count($fuids) >= 6) {
  152. break;
  153. }
  154. }
  155. $specialuser_list = getfollowflag($specialuser_list);
  156. }
  157. if(($online_count = C::app()->session->count(1)) > 1) {
  158. $oluids = $online_list = array();
  159. foreach(C::app()->session->fetch_member(1, 2, 7) as $value) {
  160. if($value['uid'] != $_G['uid'] && count($oluids) <= 6) {
  161. $fuids[$value['uid']] = $value['uid'];
  162. $oluids[$value['uid']] = $value['uid'];
  163. $online_list[$value['uid']] = $value;
  164. }
  165. }
  166. $online_list = getfollowflag($online_list);
  167. $fieldhome = C::t('common_member_field_home')->fetch_all($oluids, false, 0);
  168. foreach(C::t('common_member')->fetch_all($oluids, false, 0) as $uid => $value) {
  169. $value = array_merge($value, $fieldhome[$uid]);
  170. $online_list[$uid] = array_merge($online_list[$uid], $value);
  171. }
  172. }
  173. }
  174. $diymode = 1;
  175. if($space['self'] && ($_GET['from'] != 'space' || !$_G['setting']['homepagestyle'])) $diymode = 0;
  176. if($diymode) {
  177. $theurl .= "&from=space";
  178. }
  179. $multi = multi($count, $perpage, $page, $theurl);
  180. if($space['self']) {
  181. $groupselect = array($group => ' class="a"');
  182. $maxfriendnum = checkperm('maxfriendnum');
  183. if($maxfriendnum) {
  184. $maxfriendnum = checkperm('maxfriendnum') + $space['addfriend'];
  185. }
  186. }
  187. }
  188. if($fuids) {
  189. foreach(C::app()->session->fetch_all_by_uid($fuids) as $value) {
  190. if(!$value['invisible']) {
  191. $ols[$value['uid']] = $value['lastactivity'];
  192. } elseif($list[$value['uid']] && !in_array($_GET['view'], array('me', 'trace', 'blacklist'))) {
  193. unset($list[$value['uid']]);
  194. $count = $count - 1;
  195. }
  196. }
  197. if($_GET['view'] != 'me') {
  198. require_once libfile('function/friend');
  199. friend_check($fuids);
  200. }
  201. if($list) {
  202. $fieldhome = C::t('common_member_field_home')->fetch_all($fuids);
  203. foreach(C::t('common_member')->fetch_all($fuids) as $uid => $value) {
  204. $value = array_merge($value, $fieldhome[$uid]);
  205. $value['isfriend'] = $uid==$space['uid'] || $_G["home_friend_".$space['uid'].'_'.$uid] ? 1 : 0;
  206. if(empty($list[$uid])) $list[$uid] = array();
  207. $list[$uid] = array_merge($list[$uid], $value);
  208. }
  209. }
  210. }
  211. if($list) {
  212. $list = getfollowflag($list);
  213. }
  214. $navtitle = lang('core', 'title_friend_list');
  215. $navtitle = lang('space', 'sb_friend', array('who' => $space['username']));
  216. $metakeywords = lang('space', 'sb_friend', array('who' => $space['username']));
  217. $metadescription = lang('space', 'sb_share', array('who' => $space['username']));
  218. $a_actives = array($_GET['view'].$_GET['type'] => ' class="a"');
  219. include_once template("diy:home/space_friend");
  220. function getfollowflag($data) {
  221. global $_G;
  222. if($data) {
  223. $follows = C::t('home_follow')->fetch_all_by_uid_followuid($_G['uid'], array_keys($data));
  224. foreach($data as $uid => $value) {
  225. $data[$uid]['follow'] = isset($follows[$uid]) ? 1 : 0;
  226. }
  227. }
  228. return $data;
  229. }
  230. ?>