misc_ranklist.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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: misc_ranklist.php 32807 2013-03-13 08:49:49Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $page = $_G['page'];
  12. $type = $_GET['type'];
  13. $_G['disabledwidthauto'] = 1;
  14. if(!in_array($type, array('index', 'member', 'thread', 'blog', 'poll', 'picture', 'activity', 'forum', 'group'))) {
  15. $type = 'index';
  16. }
  17. $ranklist_setting = $_G['setting']['ranklist'];
  18. if(!$ranklist_setting['status']) {
  19. showmessage('ranklist_status_off');
  20. }
  21. $navtitle = lang('core', 'title_ranklist_'.$type);
  22. if($type != 'index') {
  23. if(!$ranklist_setting[$type]['available']) {
  24. showmessage('ranklist_this_status_off');
  25. }
  26. }
  27. include libfile('misc/ranklist_'.$type, 'include');
  28. function getranklist_thread($num = 20, $view = 'replies', $orderby = 'all') {
  29. global $_G;
  30. $dateline = '';
  31. $timestamp = 0;
  32. if($orderby == 'today') {
  33. $timestamp = TIMESTAMP - 86400;
  34. } elseif($orderby == 'thisweek') {
  35. $timestamp = TIMESTAMP - 604800;
  36. } elseif($orderby == 'thismonth') {
  37. $timestamp = TIMESTAMP - 2592000;
  38. }
  39. $data = array();
  40. $rank = 0;
  41. $notfid = $_G['setting']['ranklist']['ignorefid'] ? explode(',', $_G['setting']['ranklist']['ignorefid']) : array();
  42. foreach(C::t('forum_thread')->fetch_all_rank_thread($timestamp, $notfid, $view, $num) as $thread) {
  43. ++$rank;
  44. $thread['rank'] = $rank;
  45. $thread['dateline'] = dgmdate($thread['dateline']);
  46. $data[] = $thread;
  47. }
  48. return $data;
  49. }
  50. function getranklist_poll($num = 20, $view = 'heats', $orderby = 'all') {
  51. global $_G;
  52. $dateline = '';
  53. $timestamp = 0;
  54. if($orderby == 'today') {
  55. $timestamp = TIMESTAMP - 86400;
  56. } elseif($orderby == 'thisweek') {
  57. $timestamp = TIMESTAMP - 604800;
  58. } elseif($orderby == 'thismonth') {
  59. $timestamp = TIMESTAMP - 2592000;
  60. }
  61. $data = array();
  62. require_once libfile('function/forum');
  63. $rank = 0;
  64. $notfid = $_G['setting']['ranklist']['ignorefid'] ? explode(',', $_G['setting']['ranklist']['ignorefid']) : array();
  65. foreach(C::t('forum_thread')->fetch_all_rank_poll($timestamp, $notfid, $view, $num) as $poll) {
  66. ++$rank;
  67. $poll['rank'] = $rank;
  68. $poll['avatar'] = avatar($poll['authorid'], 'small');
  69. $poll['dateline'] = dgmdate($poll['dateline']);
  70. $poll['pollpreview'] = explode("\t", trim($poll['pollpreview']));
  71. $data[] = $poll;
  72. }
  73. return $data;
  74. }
  75. function getranklist_activity($num = 20, $view = 'heats', $orderby = 'all') {
  76. global $_G;
  77. $dateline = '';
  78. $timestamp = 0;
  79. if($orderby == 'today') {
  80. $timestamp = TIMESTAMP - 86400;
  81. } elseif($orderby == 'thisweek') {
  82. $timestamp = TIMESTAMP - 604800;
  83. } elseif($orderby == 'thismonth') {
  84. $timestamp = TIMESTAMP - 2592000;
  85. }
  86. $data = array();
  87. $rank = 0;$attachtables = array();
  88. $notfid = $_G['setting']['ranklist']['ignorefid'] ? explode(',', $_G['setting']['ranklist']['ignorefid']) : array();
  89. foreach(C::t('forum_thread')->fetch_all_rank_activity($timestamp, $notfid, $view, $num) as $thread) {
  90. ++$rank;
  91. $thread['rank'] = $rank;
  92. $thread['starttimefrom'] = dgmdate($thread['starttimefrom']);
  93. if($thread['starttimeto']) {
  94. $thread['starttimeto'] = dgmdate($thread['starttimeto']);
  95. } else {
  96. $thread['starttimeto'] = '';
  97. }
  98. if($thread['expiration'] && TIMESTAMP > $thread['expiration']) {
  99. $thread['has_expiration'] = true;
  100. } else {
  101. $thread['has_expiration'] = false;
  102. }
  103. $data[$thread['tid']] = $thread;
  104. $attachtables[getattachtableid($thread['tid'])][] = $thread['aid'];
  105. }
  106. foreach($attachtables as $attachtable => $aids) {
  107. $attachs = C::t('forum_attachment_n')->fetch_all($attachtable, $aids);
  108. foreach($attachs as $attach) {
  109. $attach['attachurl'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/'.$attach['attachment'];
  110. $data[$attach['tid']] = array_merge($data[$attach['tid']], $attach);
  111. }
  112. }
  113. return $data;
  114. }
  115. function getranklist_picture($num = 20, $view = 'hot', $orderby = 'all') {
  116. $timestamp = TIMESTAMP - 86400;
  117. $dateline = 'p.'.DB::field('dateline', $timestamp, '>=');
  118. if($orderby == 'thisweek') {
  119. $timestamp = TIMESTAMP - 604800;
  120. $dateline = 'p.'.DB::field('dateline', $timestamp, '>=');
  121. } elseif($orderby == 'thismonth') {
  122. $timestamp = TIMESTAMP - 2592000;
  123. $dateline = 'p.'.DB::field('dateline', $timestamp, '>=');
  124. }
  125. $data = array();
  126. $query = C::t('home_pic')->fetch_all_by_sql($dateline, 'p.'.DB::order($view, 'DESC'), 0, $num);
  127. require_once libfile('function/home');
  128. $rank = 0;
  129. foreach($query as $value) {
  130. ++$rank;
  131. $picture = array('picid' => $value['picid'], 'uid' => $value['uid'], 'username' => $value['username'], 'title' => $value['title'], 'filepath' => $value['filepath'], 'thumb' => $value['thumb'], 'remote' => $value['remote'], 'hot' => $value['hot'], 'sharetimes' => $value['sharetimes'], 'click1' => $value['click1'], 'click2' => $value['click2'], 'click3' => $value['click3'], 'click4' => $value['click4'], 'click5' => $value['click5'], 'click6' => $value['click6'], 'click7' => $value['click7'], 'click8' => $value['click8'], 'albumid' => $value['albumid'], 'albumname' => $value['albumname'], 'friend' => $value['friend']);
  132. $picture['rank'] = $rank;
  133. $picture['url'] = $picture['friend'] == 0 ? pic_get($picture['filepath'], 'album', $picture['thumb'], $picture['remote']) : STATICURL.'image/common/nopublish.gif';;
  134. $picture['origurl'] = pic_get($picture['filepath'], 'album', 0, $picture['remote']);
  135. $data[] = $picture;
  136. }
  137. return $data;
  138. }
  139. function getranklist_pictures_index($num = 20, $dateline = 0, $orderby = 'hot DESC') {
  140. $picturelist = array();
  141. $query = C::t('home_pic')->fetch_all_by_sql('p.hot>3', 'p.dateline DESC', 0, $num);
  142. require_once libfile('function/home');
  143. foreach($query as $value) {
  144. $picture = array('picid' => $value['picid'], 'uid' => $value['uid'], 'username' => $value['username'], 'title' => $value['title'], 'filepath' => $value['filepath'], 'thumb' => $value['thumb'], 'remote' => $value['remote'], 'albumid' => $value['albumid'], 'albumname' => $value['albumname'], 'friend' => $value['friend']);
  145. $picture['url'] = $picture['friend'] == 0 ? pic_get($picture['filepath'], 'album', $picture['thumb'], $picture['remote']) : STATICURL.'image/common/nopublish.gif';;
  146. $picture['origurl'] = $picture['friend'] == 0 ? pic_get($picture['filepath'], 'album', 0, $picture['remote']) : STATICURL.'image/common/nopublish.gif';
  147. $picturelist[] = $picture;
  148. }
  149. return $picturelist;
  150. }
  151. function getranklist_members($offset = 0, $limit = 20) {
  152. require_once libfile('function/forum');
  153. $members = array();
  154. $topusers = C::t('home_show')->fetch_all_by_unitprice($offset, $limit, true);
  155. foreach($topusers as $member) {
  156. $member['avatar'] = avatar($member['uid'], 'small');
  157. $member['note'] = dhtmlspecialchars($member['note']);
  158. $members[] = $member;
  159. }
  160. return $members;
  161. }
  162. function getranklist_girls($offset = 0, $limit = 20, $orderby = 'ORDER BY s.unitprice DESC, s.credit DESC') {
  163. return C::t('common_member')->fetch_all_girls_for_ranklist($offset, $limit, $orderby);
  164. }
  165. function getranklist_blog($num = 20, $view = 'hot', $orderby = 'all') {
  166. $dateline = $timestamp = '';
  167. if($orderby == 'today') {
  168. $timestamp = TIMESTAMP - 86400;
  169. } elseif($orderby == 'thisweek') {
  170. $timestamp = TIMESTAMP - 604800;
  171. } elseif($orderby == 'thismonth') {
  172. $timestamp = TIMESTAMP - 2592000;
  173. }
  174. $data = array();
  175. $data_blog = C::t('home_blog')->range(0, $num, 'DESC', $view, 0, 0, null, $timestamp);
  176. $blogids = array_keys($data_blog);
  177. $data_blogfield = C::t('home_blogfield')->fetch_all($blogids);
  178. require_once libfile('function/forum');
  179. require_once libfile('function/post');
  180. $rank = 0;
  181. foreach($data_blog as $curblogid => $blog) {
  182. $blog = array_merge($blog, (array)$data_blogfield[$curblogid]);
  183. ++$rank;
  184. $blog['rank'] = $rank;
  185. $blog['dateline'] = dgmdate($blog['dateline']);
  186. $blog['avatar'] = avatar($blog['uid'], 'small');
  187. $blog['message'] = preg_replace('/<([^>]*?)>/', '', $blog['message']);
  188. $blog['message'] = messagecutstr($blog['message'], 140);
  189. $data[] = $blog;
  190. }
  191. return $data;
  192. }
  193. function getranklist_forum($num = 20, $view = 'threads') {
  194. global $_G;
  195. $data = array();
  196. $timelimit = 0;
  197. if($view == 'posts') {
  198. $key = 'posts';
  199. } elseif($view == 'today') {
  200. $key = 'todayposts';
  201. } else {
  202. $key = 'threads';
  203. }
  204. $query = C::t('forum_forum')->fetch_all_for_ranklist(1, 0, $key, 0, $num, explode(',', $_G['setting']['ranklist']['ignorefid']));
  205. $i = 1;
  206. foreach($query as $row) {
  207. $result = array('fid' => $row['fid'], 'name' => $row['name']);
  208. $result['posts'] = $row[$key];
  209. $result['rank'] = $i;
  210. $data[] = $result;
  211. $i++;
  212. }
  213. return $data;
  214. }
  215. function getranklist_group($num = 20, $view = 'threads') {
  216. global $_G;
  217. $timestamp = TIMESTAMP;
  218. $data = array();
  219. $timelimit = 0;
  220. if($view == 'posts') {
  221. $key = 'posts';
  222. } elseif($view == 'today'){
  223. $key = 'todayposts';
  224. } elseif($view == 'credit'){
  225. $key = 'commoncredits';
  226. } elseif($view == 'member'){
  227. $key = 'membernum';
  228. } else {
  229. $key = 'threads';
  230. }
  231. $query = C::t('forum_forum')->fetch_all_for_ranklist(3, 'sub', $key, 0, $num, explode(',', $_G['setting']['ranklist']['ignorefid']));
  232. $i = 1;
  233. foreach($query as $row) {
  234. $result = array('fid' => $row['fid'], 'name' => $row['name']);
  235. $result[$key] = $result['posts'] = $row[$key];
  236. $result['rank'] = $i;
  237. $data[] = $result;
  238. $i++;
  239. }
  240. return $data;
  241. }
  242. function getranklist_member($num = 20, $view = 'credit', $orderby = 'all') {
  243. $data = array();
  244. $functionname = 'getranklist_member_'.$view;
  245. $data = $functionname($num, $orderby);
  246. return $data;
  247. }
  248. function getranklist_member_credit($num, $orderby) {
  249. return C::t('common_member')->fetch_all_order_by_credit_for_ranklist($num, $orderby);
  250. }
  251. function getranklist_member_friendnum($num) {
  252. return C::t('common_member')->fetch_all_order_by_friendnum_for_ranklist($num);
  253. }
  254. function getranklist_member_invite($num, $orderby) {
  255. global $_G;
  256. if($orderby == 'thisweek') {
  257. $dateline = TIMESTAMP - 604800;
  258. } elseif($orderby == 'thismonth') {
  259. $dateline = TIMESTAMP - 2592000;
  260. } elseif($orderby == 'today') {
  261. $dateline = TIMESTAMP - 86400;
  262. }
  263. $invite = $invitearray = $inviteuidarray = $invitefieldarray = array();
  264. foreach(C::t('common_invite')->fetch_all_invitenum_group_by_uid($dateline) as $result) {
  265. $invitearray[] = $result;
  266. $inviteuidarray[] = $result['uid'];
  267. }
  268. $invitememberfield = C::t('common_member')->fetch_all($inviteuidarray, false, 0);
  269. if($invitearray) {
  270. foreach($invitearray as $key => $var) {
  271. $invite[] = $var;
  272. $invite[$key]['username'] = $invitememberfield[$var['uid']]['username'];
  273. $invite[$key]['videophotostatus'] = $invitememberfield[$var['uid']]['videophotostatus'];
  274. $invite[$key]['groupid'] = $invitememberfield[$var['uid']]['groupid'];
  275. }
  276. }
  277. return $invite;
  278. }
  279. function getranklist_member_onlinetime($num, $orderby) {
  280. global $_G;
  281. if($orderby == 'thismonth') {
  282. $orderby = 'thismonth';
  283. $online = 'thismonth AS onlinetime';
  284. } elseif($orderby == 'all') {
  285. $orderby = 'total';
  286. $online = 'total AS onlinetime';
  287. }
  288. $onlinetime = $onlinetimearray = $onlinetimeuidarray = $onlinetimefieldarray = array();
  289. $onlinetimearray = C::t('common_onlinetime')->range_by_field(0, $num, $orderby, 'DESC');
  290. $onlinetimeuidarray = array_keys($onlinetimearray);
  291. $onlinetimefieldarray = C::t('common_member')->fetch_all($onlinetimeuidarray, false, 0);
  292. if($onlinetimearray) {
  293. foreach($onlinetimearray as $key => $var) {
  294. $var['onlinetime'] = $var[$orderby];
  295. $var['username'] = $onlinetimefieldarray[$var['uid']]['username'];
  296. $var['videophotostatus'] = $onlinetimefieldarray[$var['uid']]['videophotostatus'];
  297. $var['groupid'] = $onlinetimefieldarray[$var['uid']]['groupid'];
  298. $onlinetime[$key] = $var;
  299. }
  300. }
  301. return $onlinetime;
  302. }
  303. function getranklist_member_blog($num) {
  304. global $_G;
  305. $blogs = array();
  306. $sql = "SELECT m.uid,m.username,m.videophotostatus,m.groupid,c.blogs FROM ".DB::table('common_member').
  307. " m LEFT JOIN ".DB::table('common_member_count')." c ON m.uid=c.uid WHERE c.blogs>0 ORDER BY blogs DESC LIMIT 0, $num";
  308. $query = DB::query($sql);
  309. while($result = DB::fetch($query)) {
  310. $blogs[] = $result;
  311. }
  312. return $blogs;
  313. }
  314. function getranklist_member_gender($gender, $num = 20) {
  315. global $_G;
  316. $num = intval($num);
  317. $num = $num ? $num : 20;
  318. $users = array();
  319. $query = DB::query("SELECT c.uid, c.views FROM ".DB::table('common_member_count')." c
  320. LEFT JOIN ".DB::table('common_member_profile')." p ON c.uid=p.uid
  321. WHERE c.views>0 AND p.gender = '$gender' ORDER BY c.views DESC LIMIT 0, $num");
  322. while($user = DB::fetch($query)) {
  323. $users[$user['uid']] = $user;
  324. }
  325. $uids = array_keys($users);
  326. if($uids) {
  327. foreach(C::t('common_member')->fetch_all($uids, false, 0) as $uid => $value) {
  328. $users[$uid] = array_merge($users[$uid], $value);
  329. }
  330. }
  331. return $users;
  332. }
  333. function getranklist_member_beauty($num = 20) {
  334. return getranklist_member_gender(2, $num);
  335. }
  336. function getranklist_member_handsome($num = 20) {
  337. return getranklist_member_gender(1, $num);
  338. }
  339. function getranklist_member_post($num, $orderby) {
  340. global $_G;
  341. $timestamp = TIMESTAMP;
  342. $posts = array();
  343. $timelimit = 0;
  344. if($orderby == 'digestposts') {
  345. $sql = "SELECT m.username, m.uid, mc.digestposts AS posts
  346. FROM ".DB::table('common_member')." m
  347. LEFT JOIN ".DB::table('common_member_count')." mc ON mc.uid=m.uid WHERE mc.digestposts>0
  348. ORDER BY mc.digestposts DESC LIMIT 0, $num";
  349. } elseif($orderby == 'thismonth') {
  350. $timelimit = $timestamp-86400*30;
  351. } elseif($orderby == 'today') {
  352. $timelimit = $timestamp-86400;
  353. } else {
  354. $sql = "SELECT m.username, m.uid, mc.posts
  355. FROM ".DB::table('common_member')." m
  356. LEFT JOIN ".DB::table('common_member_count')." mc ON mc.uid=m.uid WHERE mc.posts>0
  357. ORDER BY mc.posts DESC LIMIT 0, $num";
  358. }
  359. if($timelimit) {
  360. $posts = C::t('forum_post')->fetch_all_top_post_author(0, $timelimit, $num);
  361. } else {
  362. $query = DB::query($sql);
  363. while($result = DB::fetch($query)) {
  364. $posts[] = $result;
  365. }
  366. }
  367. return $posts;
  368. }
  369. function getranklistdata($type, $view = '', $orderby = 'all') {
  370. global $_G;
  371. $cache_time = $_G['setting']['ranklist'][$type]['cache_time'];
  372. $cache_num = $_G['setting']['ranklist'][$type]['show_num'];
  373. if($cache_time <= 0 ) {
  374. $cache_time = 5;
  375. }
  376. $cache_time = $cache_time * 3600;
  377. if($cache_num <= 0 ) {
  378. $cache_num = 20;
  379. }
  380. $ranklistvars = array();
  381. loadcache('ranklist_'.$type);
  382. $ranklistvars = & $_G['cache']['ranklist_'.$type][$view][$orderby];
  383. if(empty($ranklistvars['lastupdated']) || (TIMESTAMP - $ranklistvars['lastupdated'] > $cache_time)) {
  384. $functionname = 'getranklist_'.$type;
  385. if(!discuz_process::islocked('ranklist_update', 600)) {
  386. $ranklistvars = $functionname($cache_num, $view, $orderby);
  387. $ranklistvars['lastupdated'] = TIMESTAMP;
  388. $ranklistvars['lastupdate'] = dgmdate(TIMESTAMP);
  389. $ranklistvars['nextupdate'] = dgmdate(TIMESTAMP + $cache_time);
  390. $_G['cache']['ranklist_'.$type][$view][$orderby] = $ranklistvars;
  391. savecache('ranklist_'.$type, $_G['cache']['ranklist_'.$type]);
  392. }
  393. discuz_process::unlock('ranklist_update');
  394. }
  395. $_G['lastupdate'] = $ranklistvars['lastupdate'];
  396. $_G['nextupdate'] = $ranklistvars['nextupdate'];
  397. unset($ranklistvars['lastupdated'], $ranklistvars['lastupdate'], $ranklistvars['nextupdate']);
  398. return $ranklistvars;
  399. }
  400. function getignorefid($pre = '') {
  401. global $_G;
  402. $fidsql = '';
  403. if($_G['setting']['ranklist']['ignorefid']) {
  404. $fidsql = ' AND '.($pre ? $pre.'.' : '').'fid NOT IN('.dimplode(explode(',', $_G['setting']['ranklist']['ignorefid'])).')';
  405. }
  406. return $fidsql;
  407. }
  408. ?>