root/topten.php

Revision 337, 13.5 kB (checked in by Nafania, 1 year ago)

Небольшой фикс для поиска сфинкса и фикс ошибки sql error Duplicate entry '***' for key 1 occured in sql query INSERT INTO sessions...

Line 
1 <?php</span>
2 <span class="code-lang">$root_path = './';
3 require ($root_path . 'include/config.php');
4 require ($root_path . 'include/functions_torrenttable.php');
5
6 $userdata = session_pagestart($user_ip);
7 init_userprefs($userdata);
8 loggedinorreturn();
9
10 $action = request_var('action', 'popular_torrents');
11 $do = request_var('do', 'by_completed');
12 $limit = min(100, request_var('limit', 20));
13 $range = request_var('range', 0);
14 $sort = request_var('sort', '');
15 $sort_type = request_var('sort_type', 'desc');
16 $view = request_var('view', 0);
17
18 $cats = $cache->obtain_cats();
19
20
21 $limit_ary = array( 20, 50, 100 );
22 $range_ary = array( 7, 30, 180, 365, $lang['all_time'] );
23 $sort_ary = array( 'asc' => $lang['sort_asc'], 'desc' => $lang['sort_desc']);
24 $view_ary = array( 0 => $lang['show_only_my_cats'], 1 => $lang['show_all_cats'] );
25
26 $cats = $cache->obtain_cats();</span>
27 <span class="code-lang">
28 if ( !isset($sort_ary[$sort]) ) {
29     $sort = 'desc';
30 }
31
32 $top_ten_types = array(</span>
33 <span class="code-lang">    'popular_torrents' => array(
34         'by_completed' => 'completed',
35         'by_peers' => 'seeders + leechers',
36         'by_comments' => 'comments',
37     ),
38
39     'users' => array(
40         'by_uploaded' => 'uploaded',
41         'by_downloaded' => 'downloaded',
42         'by_ratio' => 'uploaded / downloaded',
43         'by_total_seed_time' => 'total_seed_time',
44         'by_reputation' => 'user_reputation',
45     ),
46
47     'peers' => array(
48         'by_upspeed' => 'upspeed',
49         'by_downspeed' => 'downspeed',
50     ),
51
52     'forum' => array(
53         'by_popular_topics' => 'topic_replies',
54         'by_reputation_posts' => 'post_reputation',
55     ),
56 );
57
58 foreach ( $top_ten_types AS $type => $types_ary ) {
59
60     $template->assign_block_vars('topten_row', array(
61         'TITLE' => $lang['top_ten_' . $type],
62     ));
63
64     foreach ( $types_ary AS $subtype => $_null ) {
65         $template->assign_block_vars('topten_row.subtypes_row', array(
66             'SELECTED' => $subtype == $do,
67             'TITLE' => $lang['top_ten_' . $subtype],
68             'U_TYPE' => append_sid($root_path . 'topten.php?action=' . $type . '&amp;do=' . $subtype . '&amp;limit=' . $limit . '&amp;range=' . $range),
69         ));
70     }
71 }
72
73 $wherecatina = array();
74 $cats_sql = '';</span>
75 <span class="code-lang">if ( strpos($userdata['notifs'], '[cat') !== false && !$view ) {
76     foreach ( $cats AS $cat_id => $cat_ary ) {
77         if ( strpos($userdata['notifs'], '[cat' . $cat_id . ']') !== false ) {
78             $wherecatina[] = $cat_id;
79           }
80      }
81 }
82 if ( sizeof($wherecatina) && sizeof($wherecatina) != sizeof($cats) ) {
83     $new_wherecatina = array();
84     foreach ( $wherecatina AS $_null => $_val ) {
85         if ( isset($cats[$_val]) ) {
86             if ( $cats[$_val]['cat_parent'] ) {
87                 $new_wherecatina[] = $_val;
88             }
89             //no cat parent, try to get all child cats
90             else {
91                 foreach ( $cats AS $_key => $_ary ) {
92                     if ( $_ary['cat_parent'] == $_val ) {
93                         $new_wherecatina[] = $_key;
94                     }
95                 }
96                 $new_wherecatina[] = $_val;
97             }
98         }
99     }
100     $wherecatina = $new_wherecatina;
101     if ( sizeof($wherecatina) ) {
102         $cats_sql = 't.category IN (' . implode(', ', $wherecatina) . ')';
103     }
104 }
105
106 switch ( $action ) {
107     case 'forum':
108         $order_field = ( isset($top_ten_types[$action][$do]) ? $top_ten_types[$action][$do] : 'topic_replies' );
109
110         $sql = "SELECT f.* FROM " . FORUMS_TABLE . " f";
111         $result = $db->sql_query($sql);
112
113         $forum_data = array();
114         while( $row = $db->sql_fetchrow($result) ) {
115             $forum_data[] = $row;
116         }
117
118         $auth_forums = array();
119         $is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata, $forum_data);
120
121         foreach ( $is_auth_ary AS $forum_id => $forum_ary ) {
122             if ( $forum_ary['auth_view'] ) {
123                 $auth_forums[] = $forum_id;
124             }
125         }
126
127         switch( $do ){
128             default:
129             case 'topic_replies':
130                 $sql = 'SELECT u.uid, u.name, u.name_append, u.uid, u.class, t.topic_replies, t.topic_title, t.topic_id
131                         FROM ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
132                         WHERE u.uid = t.topic_poster AND ' . $db->sql_in_set('t.forum_id', $auth_forums) . '
133                         ' . ( $range ? ' AND t.topic_time > ' . ( time() - $range * 24 * 60 * 60 ) : '' ) . '
134                         ORDER BY ' . $order_field . ' ' . $sort;
135                 $result = $db->sql_query_limit($sql, $limit);
136
137                 while ( $row = $db->sql_fetchrow($result) )  {
138
139                     $template->assign_block_vars('forum_row', array(
140                         'USERNAME' => parse_username($row),
141                         'TOPIC_REPLIES' => $row['topic_replies'],
142                         'U_TOPIC' => append_sid($root_path . 'phpbb2.php?page=viewtopic&amp;t=' . $row['topic_id']),
143                         'TOPIC_TITLE' => $row['topic_title'],
144
145                         'HIGHLIGHT' => $userdata['uid'] == $row['uid'],
146                     ));
147                 }
148
149                 $body = 'top_forum_body.html';
150             break;
151
152             case 'by_reputation_posts':
153                 $sql = 'SELECT u.uid, u.name, u.name_append, u.uid, u.class, p.post_reputation, p.post_id, t.topic_title
154                         FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
155                         WHERE p.topic_id = t.topic_id AND p.poster_id = u.uid AND ' . $db->sql_in_set('t.forum_id', $auth_forums) . '
156                         ' . ( $range ? ' AND p.post_created > ' . ( time() - $range * 24 * 60 * 60 ) : '' ) . '
157                         ORDER BY ' . $order_field . ' ' . $sort;
158                 $result = $db->sql_query_limit($sql, $limit);
159
160                 while ( $row = $db->sql_fetchrow($result) )  {
161
162                     $template->assign_block_vars('forum_row', array(
163                         'USERNAME' => parse_username($row),
164                         'REPUTATION' => $row['post_reputation'],
165                         'U_POST' => append_sid($root_path . 'phpbb2.php?page=viewtopic&amp;p=' . $row['post_id'] . '#' . $row['post_id']),
166                         'TOPIC_TITLE' => $row['topic_title'],
167
168                         'HIGHLIGHT' => $userdata['uid'] == $row['uid'],
169                     ));
170                 }
171
172                 $body = 'top_forum_topics_body.html';
173             break;
174         }
175
176         break;
177
178     case 'users':
179         $order_field = ( isset($top_ten_types[$action][$do]) ? $top_ten_types[$action][$do] : 'uploaded' );
180
181         $sql = 'SELECT *
182                 FROM ' . USERS_TABLE . '
183                 WHERE enabled = 1
184                 ' . ( $range ? ' AND added > ' . ( time() - $range * 24 * 60 * 60 ) : '' ) . '
185                 AND uploaded > ' . 1 * 1024 * 1024 * 1024 . '
186                 AND downloaded > ' . 1 * 1024 * 1024 * 1024 . '
187                 ORDER BY ' . $order_field . ' ' . $sort;
188         $result = $db->sql_query_limit($sql, $limit);
189
190         while ( $row = $db->sql_fetchrow($result) )  {
191             $ratio = get_ratio($row['uploaded'], $row['downloaded']);
192
193             // www.phpBB-SEO.com SEO TOOLKIT START
194             $seo->set_user_url($row['name'], $row['uid']);
195             // www.phpBB-SEO.com SEO TOOLKIT END
196
197             $template->assign_block_vars('users_table', array(
198                 'U_USERDETAILS' => append_sid($root_path . 'userdetails.php?id=' . $row['uid']),
199                 'USERNAME' => get_user_class_color ($row['class'], $row['name']),
200                 'USER_ICONS' =>  get_user_icons($row),
201                 'UPLOADED' => mksize($row['uploaded']),
202                 'DOWNLOADED' => mksize($row['downloaded']),
203                 'RATIO' => $ratio,
204                 'TOTAL_SEED_TIME' => mkprettytime($row['total_seed_time']),
205                 'REPUTATION' => $row['user_reputation'],
206
207                 'HIGHLIGHT' => $userdata['uid'] == $row['uid'],
208             ));
209         }
210
211         $body = 'top_users_body.html';
212     break;
213
214     case 'peers':
215         $order_field = ( isset($top_ten_types[$action][$do]) ? $top_ten_types[$action][$do] : 'uploaded' );
216
217         $sql = 'SELECT p.upspeed, p.downspeed, u.uid, u.name, t.name AS torrent_name, p.fid, t.category, u.class
218                 FROM ' . PEERS_TABLE . ' p, ' . USERS_TABLE . ' u, ' . TORRENTS_TABLE . ' t
219                 WHERE p.uid = u.uid
220                 AND p.fid = t.fid
221                 AND u.enabled = 1
222                 ' . ( $range ? ' AND started > ' . ( time() - $range * 24 * 60 * 60 ) : '' ) . '
223                 ORDER BY ' . $order_field . ' ' . $sort;
224         $result = $db->sql_query_limit($sql, $limit);
225
226         while ( $row = $db->sql_fetchrow($result) )  {
227             $cat_id = $row['category'];
228             $cat_parent_id = ( isset($cats[$cats[$cat_id]['cat_parent']]['cat_id']) ? $cats[$cats[$cat_id]['cat_parent']]['cat_id'] : 0 );
229
230             $id = $row['fid'];
231             $dispname = $row['torrent_name'];
232             $dispname = censor_text($dispname);
233
234             // www.phpBB-SEO.com SEO TOOLKIT BEGIN
235             if ( $cat_parent_id ) {
236                 $seo->set_url($cats[$cat_parent_id]['cat_name'], $cat_parent_id, $seo->seo_static['browse']);
237                 $seo->set_parent($cat_id, $seo->seo_static['browse'], $cat_parent_id, $seo->seo_static['browse']);
238             }
239
240             $seo->set_url($cats[$cat_id]['cat_name'], $cat_id, $seo->seo_static['browse']);
241
242             $seo->set_parent($id, $seo->seo_static['details'], $cat_id, $seo->seo_static['browse']);
243
244             $seo->set_url($dispname, $id, $seo->seo_static['details']);
245             // www.phpBB-SEO.com SEO TOOLKIT END
246
247             // www.phpBB-SEO.com SEO TOOLKIT START
248             $seo->set_user_url($row['name'], $row['uid']);
249             // www.phpBB-SEO.com SEO TOOLKIT END
250
251             $template->assign_block_vars('peers_table', array(
252                 'U_USERDETAILS' => append_sid($root_path . 'userdetails.php?id=' . $row['uid']),
253                 'USERNAME' => get_user_class_color ($row['class'], $row['name']),
254                 'UPSPEED' => mksize($row['upspeed']),
255                 'DOWNSPEED' => mksize($row['downspeed']),
256                 'U_DETAILS'  => append_sid($root_path . 'details.php?id=' . $id),
257                 'DISPNAME' => $dispname,
258
259                 'HIGHLIGHT' => $userdata['uid'] == $row['uid'],
260
261             ));
262         }
263
264         $body = 'top_peers_body.html';
265     break;
266
267     default:
268     case 'popular_torrents':
269
270         $order_field = ( isset($top_ten_types[$action][$do]) ? $top_ten_types[$action][$do] : 'completed' );
271
272         $sql = 'SELECT *
273                 FROM ' . TORRENTS_TABLE . ' t
274                 WHERE banned = 0 AND hidden = 0 AND moderated = 1
275                 ' . ( $cats_sql ? ' AND ' . $cats_sql : '' ) .
276                 ( $range ? ' AND ctime > ' . ( time() - $range * 24 * 60 * 60 ) : '' ) . '
277                 ORDER BY ' . $order_field . ' ' . $sort;
278         $result = $db->sql_query_limit($sql, $limit);
279
280         while ( $row = $db->sql_fetchrow($result) )  {
281
282             $cat_id = $row['category'];
283             $cat_parent_id = ( isset($cats[$cats[$cat_id]['cat_parent']]['cat_id']) ? $cats[$cats[$cat_id]['cat_parent']]['cat_id'] : 0 );
284
285             $id = $row['fid'];
286             $dispname = $row['name'];
287             $dispname = censor_text($dispname);
288
289             // www.phpBB-SEO.com SEO TOOLKIT BEGIN
290             if ( $cat_parent_id ) {
291                 $seo->set_url($cats[$cat_parent_id]['cat_name'], $cat_parent_id, $seo->seo_static['browse']);
292                 $seo->set_parent($cat_id, $seo->seo_static['browse'], $cat_parent_id, $seo->seo_static['browse']);
293             }
294
295             $seo->set_url($cats[$cat_id]['cat_name'], $cat_id, $seo->seo_static['browse']);
296
297             $seo->set_parent($id, $seo->seo_static['details'], $cat_id, $seo->seo_static['browse']);
298
299             $seo->set_url($dispname, $id, $seo->seo_static['details']);
300             // www.phpBB-SEO.com SEO TOOLKIT END
301
302             if ( $row['seeders'] ) {
303                 $ratio = ( $row['leechers'] ? $row['seeders'] / $row['leechers'] : 1 );
304                 $slr_color = get_slr_color($ratio);
305             }
306             else {
307                 $slr_color = 'FF0000';
308             }
309
310             $cat_name_display = '';
311             if ( $cat_parent_id ) {
312                 $cat_name_display .= '<a href="' . append_sid($root_path . 'browse.php?cat=' . $cat_parent_id) . '">' . $cats[$cats[$cat_id]['cat_parent']]['cat_name'] . '</a> -> ';
313             }
314             $cat_name_display .= '<a href="' . append_sid($root_path . 'browse.php?cat=' . $cat_id) . '">' . $cats[$cat_id]['cat_name'] . '</a>';
315
316             $template->assign_block_vars('torrents_table', array(
317                 'U_CATEGORY' => append_sid($root_path . 'browse.php?cat=' . $cat_id),
318                 'U_DETAILS'  => append_sid($root_path . 'details.php?id=' . $id),
319                 'U_DOWNLOAD' => append_sid($root_path . 'details.php?id=' . $id . '&amp;action=download'),
320                 'U_ADD_BOOKMARK' => append_sid($root_path . 'bookmarks.php?torrent=' . $id),
321                 'U_SNATCHED' => append_sid($root_path . 'details.php?id=' . $id . '&amp;view=snatchedlist#snatched'),
322                 'U_PEERLIST' => append_sid($root_path . 'details.php?id=' . $id . '&amp;view=peerlist'),
323                 'DISPNAME' => $dispname,
324                 'TORRENT_FREE_ICON' => get_free_icon($row['free']),
325                 'TORRENT_COMPLETED' => $row['completed'],
326                 'TORRENT_SEEDERS' => $row['seeders'],
327                 'TORRENT_LEECHERS' => $row['leechers'],
328                 'SLR_COLOR' => $slr_color,
329                 'ADDED' => create_date($row['ctime']),
330                 'CAT_PIC' => $cats[$cat_id]['cat_pic'],
331                 'CAT_NAME' => $cats[$cat_id]['cat_name'],
332                 'CAT_NAME_DISPLAY' => $cat_name_display,
333                 'SIZE' => mksize($row['size']),
334
335                 'HIGHLIGHT' => $userdata['uid'] == $row['owner'],
336
337                 'ID' => $row['fid'],
338             ));
339         }
340
341         $body = 'top_torrents_body.html';
342     break;
343 }
344
345 $limit_options = '<select name="limit">';</span>
346 <span class="code-lang">foreach ( $limit_ary AS $null => $_limit ) {
347     $limit_options .= '<option value="' . $_limit . '"' . ( $_limit == $limit ? ' selected="selected"' : '' ) . '>' . $_limit . '</option>';
348 }
349 $limit_options .= '</select>';
350
351 $range_options = '<select name="range">';</span>
352 <span class="code-lang">foreach ( $range_ary AS $null => $_range ) {
353     $range_options .= '<option value="' . $_range . '"' . ( $_range == $range ? ' selected="selected"' : '' ) . '>' . $_range . '</option>';
354 }
355 $range_options .= '</select>';
356
357 $sort_options = '<select name="sort">';</span>
358 <span class="code-lang">foreach ( $sort_ary AS $null => $_sort ) {
359     $sort_options .= '<option value="' . $null . '"' . ( $null == $sort ? ' selected="selected"' : '' ) . '>' . $_sort . '</option>';
360 }
361 $sort_options .= '</select>';
362
363 $view_options = '';</span>
364 <span class="code-lang">if ( $action == 'popular_torrents' ) {
365     $view_options = '<select name="view">';
366     foreach ( $view_ary AS $null => $_view ) {
367         $view_options .= '<option value="' . $null . '"' . ( $null == $view ? ' selected="selected"' : '' ) . '>' . $_view . '</option>';
368     }
369     $view_options .= '</select>';
370 }
371
372
373 $template->assign_vars(array(</span>
374 <span class="code-lang">    'LIMIT_OPTIONS' => $limit_options,
375     'RANGE_OPTIONS' => $range_options,
376     'SORT_OPTIONS' => $sort_options,
377     'VIEW_OPTIONS' => $view_options,
378
379     'S_FORM_ACTION' => append_sid($root_path . 'topten.php'),
380     'ACTION' => $action,
381     'DO' => $do,
382 ));
383
384 $template->set_filenames(array(</span>
385 <span class="code-lang">    'template' => $body
386 ));
387 $template->assign_display('template', 'INCLUDE_TEMPLATE', false);
388
389 stdhead($lang['top10']);
390 $template->set_filenames(array(</span>
391 <span class="code-lang">        'body' => 'top_ten_body.html'
392 ));
393 stdfoot();
394 ?>
Note: See TracBrowser for help on using the browser.