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