root/details.php

Revision 336, 27.0 kB (checked in by Nafania, 1 year ago)

Мелкие баг-фиксы. Поддержка сфинкса (корявая) в поиске торрентов. sphinxapi.php надо использовать свой - тот что лежит, только для примера.
Список файлов показывается напрямую из торрент файла, а не из базы, но таблицы пока оставлены - на всякий случай.

Line 
1 <?php</span>
2 <span class="code-lang">$root_path = './';
3 require ($root_path . 'include/config.php');
4
5 $userdata = session_pagestart( $user_ip );
6 init_userprefs( $userdata );
7 parked();
8
9 //loggedinorreturn();
10
11 function dltable( $left_name, $name, $arr, $aname )</span>
12 <span class="code-keyword">{
13     global $userdata, $template, $lang, $theme, $root_path;
14     global $seo;
15
16     $count = sizeof( $arr );
17
18     $template->assign_block_vars( 'peerlist', array(
19         'A_NAME' => $aname,
20         'COUNT' => $count,
21         'NAME' => $name,
22         'LEFT_NAME' => $left_name
23     ));
24
25     if ( !$count ) {
26         return;
27     }
28     $now = time();
29     for ( $i = 0; $i < $count; $i++ ) {
30
31     $secs = ( $now - $arr[$i]['started'] );
32         // we don't want that somebody with class < moderator see VIP's info except themselfs
33         if ( ( $arr[$i]['class'] == UC_VIP || $arr[$i]['privacy'] <> PRIVACY_LEVEL_LOW ) && ( $userdata['class'] < UC_MODERATOR && $userdata['uid'] != $arr[$i]['uid'] ) ) {
34             $ratio = '---';
35             $uploaded = '---';
36             $upload_speed = '---';
37             $downloaded = '---';
38             $download_speed = '---';
39             $percent = '---';
40         }
41         else {
42             $ratio = get_ratio ( $arr[$i]['uploaded'], $arr[$i]['downloaded'] );
43             $uploaded = mksize( $arr[$i]['uploaded'] );
44             $upload_speed = mksize( $arr[$i]['upspeed'] ) . '/' . $lang['secs_short'];
45             $downloaded = mksize( $arr[$i]['downloaded'] );
46             $download_speed = ( $arr[$i]['left'] ? mksize( $arr[$i]['downspeed'] ) . '/' . $lang['secs_short']:'<span style="color:green;">' . $lang['seeds_short'] . '</span>' );
47             $percent = sprintf( '%.2f%%', 100 * ( 1 - ( $arr[$i]['left'] / $arr[$i]['size'] ) ) );
48         }
49
50         if ( $arr[$i]['privacy'] == PRIVACY_LEVEL_HIGH && $userdata['class'] < UC_MODERATOR && $userdata['uid'] != $arr[$i]['uid'] ) {
51             $u_userdetails = '';
52             $username_color = '<i>' . $lang['anonymous'] . '</i>';
53             $username = '<i>' . $lang['anonymous'] . '</i>';
54             $connectable = '---';
55             $connected = '---';
56             $client = '---';
57         }
58         else {
59
60             // www.phpBB-SEO.com SEO TOOLKIT START
61             $seo->set_user_url($arr[$i]['name'], $arr[$i]['uid']);
62             // www.phpBB-SEO.com SEO TOOLKIT END
63
64             $u_userdetails = append_sid($root_path . 'userdetails.php?id=' . $arr[$i]['uid']);
65             $username_color = get_user_class_color( $arr[$i]['class'], $arr[$i]['name'] );
66             $username = $arr[$i]['name'];
67             $connectable = $arr[$i]['port'];
68             $connected = mkprettytime( $now - $arr[$i]['started'] );
69             $client = getagent( $arr[$i]['useragent'], $arr[$i]['peer_id'] );
70         }
71
72         $peer_ip = $arr[$i]['ip'];
73
74         if ( defined('USE_XBTT') ) {
75             $peer_ip = long2ip($peer_ip);
76         }
77
78         if ( $userdata['uid'] == $arr[$i]['uid'] || $userdata['class'] > UC_UPLOADER ) {
79             $ip = '<a href="http://ripe.net/fcgi-bin/whois?form_type=simple&amp;full_query_string=&amp;searchtext=' . $peer_ip . '" target="_blank"><i>' . $peer_ip . '</i></a>';
80         }
81         elseif ( $userdata['class'] == UC_UPLOADER && $arr[$i]['privacy'] == PRIVACY_LEVEL_LOW ) {
82             $ip = preg_replace('/\.\d+$/', '.xxx', $peer_ip);
83         }
84         else {
85             $ip = '';
86         }
87
88         $template->assign_block_vars( 'peerlist.peerlist_row', array(
89             'U_USERDETAILS' => $u_userdetails,
90             'USERNAME_COLOR' =>  $username_color,
91             'USERNAME' =>  $username,
92             'IP' => $ip,
93             'RATIO_COLOR' => get_ratio_color( $ratio ),
94             'RATIO' => $ratio,
95             'CONNECTABLE' => $connectable,
96             'UPLOADED' => $uploaded,
97             'UPLOAD_SPEED' => $upload_speed,
98             'DOWNLOADED' => $downloaded,
99             'DOWNLOAD_SPEED' => $download_speed,
100             'PERCENT' => $percent,
101             'CONNECTED' => $connected,
102             'CLIENT' => $client,
103             'TD_CLASS' => ( $i % 2 ? $theme['td_class1'] : $theme['td_class2'] )
104         ));
105     }
106     return true;
107 }
108
109 function getExtension( $fileName )
110 {
111     global $root_path;
112
113     $noExtensionFile = 'unknown'; // The return when no extension is found
114     // Prepare the loop to find an extension
115     $length = -1 * ( strlen( $fileName ) ); // The maximum negative value for $i
116     $i = -1; //The counter which counts back to $length
117     // Find the last dot in an string
118     while ( substr( $fileName, $i, 1 ) != '.' && $i > $length ) {
119         $i -= 1;
120     }
121     // Get the extension (with dot)
122     $ext = substr( $fileName, $i );
123     // Decide what to return.
124     if ( substr( $ext, 0, 1 ) == '.' ) {
125         $ext = substr( $ext, ( ( -1 * strlen( $ext ) ) + 1 ) );
126     } else {
127         $ext = $noExtensionFile;
128     }
129     $ext = strtolower( $ext );
130     if ( ( substr( $ext, 0, 1 ) == 'z' || substr( $ext, 0, 1 ) == 'r' ) && is_numeric( substr( $ext, 1, 2 ) ) ) {
131         $ext = 'rar';
132     }
133     if ( is_numeric( $ext ) ) { // something like .001, .002 etc
134         $ext = 'rar';
135     }
136
137     if ( file_exists( $root_path . 'pic/files/' . $ext . '.png' ) ) {
138         return $ext;
139     } else {
140         return $noExtensionFile;
141     }
142 }
143
144 $action = request_var('action', '');
145 $do = request_var('do', '');
146 $view = request_var('view', '');
147 $id = request_var('id', 0);</span>
148 <span class="code-lang">
149 if ( $view ) {
150     $use_ajax = ( !$action && !isset( $_GET['id'] ) ? true : false );
151
152     if ( $use_ajax ) {
153         require_once ( $root_path . 'include/ajax.php' );
154         $JsHttpRequest = new JsHttpRequest();
155         $db->sql_return_on_error( true );
156     }
157
158     $id = request_var('id', 0);
159     if ( !$id ) {
160         return $_RESULT = array( 'tpl' => sprintf( $lang['invalid_id'], $id ) );
161     }
162
163     switch ( $view ) {
164         case 'filelist':
165             $template->set_filenames(
166                 array( 'filelist_tpl' => 'details_filelist.html'
167             ));
168             require($root_path . '/include/class.bencode.php');
169
170             $torrent_dir = $root_path . ( !empty($config['torrent_dir']) ? $config['torrent_dir'] : 'torrents');
171             $torrent = new Torrent($torrent_dir . '/' . $id . '.torrent');
172
173             $content = $torrent->content();
174
175             $i = 0;
176             foreach ( $content AS $filename => $size ) {
177                 ++$i;
178                 $template->assign_block_vars( 'filelist_row', array(
179                     'EXT_PIC' => getExtension($filename),
180                     'FILENAME' => $filename,
181                     'SIZE' => mksize($size),
182                     'TD_CLASS' => ( $i % 2 ? $theme['td_class1'] : $theme['td_class2'] )
183                 ));
184             }
185             $db->sql_freeresult( $result );
186
187             $template->assign_vars( array(
188                 'NUM_FILES' => sprintf( $lang['num_files'], $i )
189             ));
190
191             $tpl = $template->assign_display( 'filelist_tpl' );
192
193             if ( $use_ajax ) {
194                 return $_RESULT = array( 'tpl' => $tpl );
195             }
196             break;
197
198         case 'peerlist':
199             $template->set_filenames( array(
200                 'peerlist_tpl' => 'details_peerlist.html'
201             ));
202
203             $seeders = $leechers = array();
204             $sql = 'SELECT p.ip, p.port, p.uploaded, p.downloaded, p.left, p.started, p.useragent, p.peer_id, p.mtime, p.uid, p.upspeed, p.downspeed, u.name, u.privacy, u.class, t.size
205                        FROM ' . PEERS_TABLE . ' p, ' . USERS_TABLE . ' u, ' . TORRENTS_TABLE . ' t
206                         WHERE p.fid = ' . $id . ' AND p.uid = u.uid AND p.fid = t.fid' . ( defined( 'USE_XBTT' ) ? ' AND p.active = 1' : '' ) .
207                     ' ORDER BY p.left, p.started';
208             $result = $db->sql_query( $sql );
209             while ( $subrow = $db->sql_fetchrow( $result ) ) {
210                 if ( !$subrow['left'] ) {
211                     $seeders[] = $subrow;
212                 }
213                 else {
214                     $leechers[] = $subrow;
215                 }
216             }
217             $db->sql_freeresult( $result );
218
219             dltable( $lang['seeders'], $lang['seeds'], $seeders, 'seeders' );
220             dltable( $lang['leechers'], $lang['leechs'], $leechers, 'leechers' );
221
222             $tpl = $template->assign_display( 'peerlist_tpl' );
223
224             if ( $use_ajax ) {
225                 return $_RESULT = array( 'tpl' => $tpl );
226             }
227             break;
228
229         case 'snatchedlist':
230             $template->set_filenames( array(
231                 'snatchedlist_tpl' => 'details_snatchedlist.html'
232             ));
233             $template->assign_vars( array(
234                 'IMG_PM_BUTTON' => $images['pm'],
235                 'SEND_PM' => $lang['send_pm']
236             ));
237
238             $sql = 'SELECT u.name, u.class, u.donor, u.enabled, u.warneduntil, u.parked, u.user_session_time, u.privacy, s.completedat, s.last_action, s.userid, s.uploaded AS tor_uploaded, s.downloaded AS tor_downloaded, p.left, p.active
239                     FROM ' . SNATCHED_TABLE . ' s
240                     LEFT JOIN ' . PEERS_TABLE . ' p ON s.userid = p.uid AND s.torrentid = p.fid,
241                     ' . USERS_TABLE . ' u
242                     WHERE u.uid = s.userid
243                     AND s.completedat <> 0
244                     AND s.torrentid = ' . $id . '
245                     GROUP BY s.userid
246                     ORDER BY s.completedat DESC';
247             $result = $db->sql_query( $sql );
248
249             $i = $anon_users = 0;
250
251             while ( $row = $db->sql_fetchrow( $result ) ) {
252                 if ( $row['privacy'] == PRIVACY_LEVEL_HIGH && $userdata['class'] < UC_MODERATOR ) {
253                     ++$anon_users;
254                     continue;
255                 }
256                 ++$i;
257                 $ratio = get_ratio( $row['tor_uploaded'], $row['tor_downloaded'] );
258
259                 if ( $row['privacy'] <> PRIVACY_LEVEL_LOW && $userdata['class'] < UC_MODERATOR ) {
260                     $ratio = '---';
261                     $uploaded = '---';
262                     $downloaded = '---';
263                     $when_finished = '---';
264                     $last_action = '---';
265                 }
266                 else {
267                     $ratio = '<span style="color:' . get_ratio_color( $ratio ) . ';">' . $ratio . '</span>';
268                     $uploaded = mksize( $row['tor_uploaded'] );
269                     $downloaded = mksize( $row['tor_downloaded'] );
270                     $when_finished = create_date($row['completedat']);
271                     $last_action = create_date($row['last_action']);
272                 }
273
274                 if ( $row['user_session_time'] > ( time() - $config['online_time'] ) ) {
275                     $img_online = $images['online'];
276                     $img_online_alt = sprintf($lang['user_online'], $row['name']);
277                 }
278                 else {
279                     $img_online = $images['offline'];
280                     $img_online_alt = sprintf( $lang['user_offline'], $row['name']);
281                 }
282
283                 // www.phpBB-SEO.com SEO TOOLKIT START
284                 $seo->set_user_url($row['name'], $row['userid']);
285                 // www.phpBB-SEO.com SEO TOOLKIT END
286
287                 if ( defined('USE_XBTT') ) {
288                     $seeder = ( isset($row['left']) && empty($row['left']) ) && !empty($row['active']);
289                 }
290                 else {
291                     $seeder = isset($row['left']) && empty($row['left']);
292                 }
293
294                 $template->assign_block_vars( 'snatchedlist_row', array(
295                     'USERID' => $row['userid'],
296                     'USERNAME' => get_user_class_color( $row['class'], $row['name'] ) . get_user_icons( $row ),
297                     'U_USERDETAILS' => append_sid($root_path . 'userdetails.php?id=' . $row['userid'] ),
298                     'U_SEND_PM' => append_sid( 'message.php?action=send&amp;receiver=' . $row['userid'] ),
299                     'TOR_UPLOADED' => $uploaded,
300                     'TOR_DOWNLOADED' => $downloaded,
301                     'TOR_RATIO' => $ratio,
302                     'WHEN_FINISHED' => $when_finished,
303                     'LAST_ACTION' => $last_action,
304                     'SEEDER' => ( $seeder ? '<b><span style="color:green;">' . $lang['yes'] . '</span></b>' : '<span style="color:red;">' . $lang['no'] . '</span>' ),
305                     'IMG_ONLINE' => $img_online,
306                     'ALT_IMG_ONLINE' => $img_online_alt,
307                     'TD_CLASS' => ( $i % 2 ? $theme['td_class1'] : $theme['td_class2'] )
308                 ));
309         }
310         $db->sql_freeresult( $result );
311
312         $template->assign_vars( array(
313             'L_SNATCHED_TIMES_ANONYMOUSLY' => sprintf($lang['snatched_times_anonymous'], $anon_users ),
314             'L_SNATCHED_COUNT' => sprintf( $lang['snatched_times'], $i )
315         ));
316
317         $tpl = $template->assign_display( 'snatchedlist_tpl' );
318
319         if ( $use_ajax ) {
320             return $_RESULT = array( 'tpl' => $tpl );
321         }
322         break;
323
324         case 'thanks':
325             $sql = 'SELECT t.userid, u.name
326                     FROM ' . THANKS_TABLE . ' t, ' . USERS_TABLE . ' u
327                     WHERE t.torrentid = ' . $id . ' AND t.userid = u.uid';
328             $result = $db->sql_query( $sql );
329
330             if ( $subrow = $db->sql_fetchrow( $result ) ) {
331                 $thanksby = '';
332                 $thanks_userid = '';
333                 do {
334                     $thanksby .= ( $thanks_userid ? ', ' : '' );
335                     $thanks_userid = $subrow['userid'];
336                     // www.phpBB-SEO.com SEO TOOLKIT START
337                     $seo->set_user_url($subrow['name'], $thanks_userid);
338                     // www.phpBB-SEO.com SEO TOOLKIT END
339                     $thanksby .= '<a href="' . append_sid($root_path . 'userdetails.php?id=' . $thanks_userid) . '">' . $subrow['name'] . '</a>';
340                 }
341                 while ( $subrow = $db->sql_fetchrow( $result ) );
342                 $db->sql_freeresult( $result );
343             }
344             else {
345                 $thanksby = '';
346             }
347
348             return $_RESULT = array( 'tpl' => $thanksby );
349         break;
350     }
351 }
352 //here we get all announce urls
353 $base_url = generate_base_url();
354
355 $announce_urls = array();</span>
356 <span class="code-lang">if ( defined('USE_XBTT') ) {
357     $announce = $config['xbt_listen_url'] . ':' . $config['listen_port'] . '/' . ( $userdata['session_logged_in'] ? $userdata['torrent_pass'] . '/' : '' ) . 'announce/';
358 }
359 else {
360     $announce = $base_url . '/announce.php' . ( $userdata['session_logged_in'] ? '?passkey=' . $userdata['torrent_pass'] : '' );
361 }
362
363 $announce_urls[] = $announce;
364 $announce_urls[] = 'http://retracker.local/announce';
365 //here we get all announce urls
366
367 if ( $action ) {</span>
368 <span class="code-keyword">    $files = array();
369     if ( $dir = opendir($root_path . 'include/details/') ) {
370         while ( false !== ($file = readdir($dir)) ) {
371             if ( $file != '.' && $file != '..' ) {
372                 $file = substr($file, 0, strpos($file, '.php'));
373                 $files[] = $file;
374             }
375         }
376     }
377
378     if ( in_array($action, $files) ) {
379         require($root_path . 'include/details/' . $action . '.php');
380     }
381     else {
382         trigger_error('invalid_action');
383     }
384 }
385 else {
386     require ($root_path . 'include/bbcode/bbcode.lib.php');
387     require ($root_path . 'include/functions_post.php');
388     require_once($root_path . 'include/class.tags.php');
389
390     $view = request_var('view', '');
391     $highlight = request_var('highlight', '');
392     $cats = $cache->obtain_cats();
393
394     if ( !$id ) {
395         trigger_error( sprintf( $lang['invalid_id'], $id ) );
396     }
397
398     $sql = 'SELECT t.seeders, t.banned, t.leechers, t.info_hash, t.filename, t.nfo, t.mtime, t.numratings, t.ratingsum, t.name, t.owner, t.descr, t.size, t.ctime, t.views, t.hits, t.disable_comments,
399             t.completed, t.numfiles, t.category, t.hidden, t.free, t.comments, t.moderated, u.name AS username, u.class, u.privacy
400             FROM ' . TORRENTS_TABLE . ' t, ' . USERS_TABLE . ' u
401             WHERE t.owner = u.uid AND t.fid = ' . $id;
402     $result = $db->sql_query( $sql );
403
404     if ( !( $row = $db->sql_fetchrow( $result ) ) || ( $row['banned'] && $userdata['class'] < UC_MODERATOR ) || ( $row['hidden'] && $userdata['class'] < UC_MODERATOR && ( !$userdata['hiddentorrents'] || !$userdata['session_logged_in'] ) ) || ( !$row['moderated'] && $userdata['class'] < UC_MODERATOR && $userdata['uid'] <> $row['owner'] ) ) {
405         $db->sql_freeresult( $result );
406         redirect ( append_sid( 'log.php?query=' . $id ) );
407     }
408     elseif ( !$userdata['session_logged_in'] && !$cats[$row['category']]['anonymous_view'] ) {
409         trigger_error ( $lang['category_only_for_registered_users'] );
410     }
411     else {
412         $torrent_name = censor_text($row['name']);
413
414         $sql_priority = ( $db_type == 'mysql' ) ? ' LOW_PRIORITY' : '';
415         $sql = 'UPDATE' . $sql_priority . ' ' . TORRENTS_TABLE . ' SET views = views + 1 WHERE fid = ' . $id;
416         $db->sql_query( $sql );
417
418         $template->assign_vars( array(
419             'ID' => $id
420         ));
421
422         // www.phpBB-SEO.com SEO TOOLKIT BEGIN
423         $seo->set_torrent_url($id, $row['name'], $row['category']);
424         $seo->set_user_url($row['username'], $row['owner']);
425         // www.phpBB-SEO.com SEO TOOLKIT END
426
427         if ( isset($cats[$cats[$row['category']]['cat_parent']]['cat_name']) ) {
428             $cat_parent = $cats[$cats[$row['category']]['cat_parent']];
429             $cat_parent_name = '<a href="' . append_sid($root_path . 'browse.php?cat=' . $cat_parent['cat_id']) . '">' . $cat_parent['cat_name'] . '</a> -> ';
430         }
431         else {
432             $cat_parent_name = '';
433         }
434
435         if ( $view <> 'comments' ) {
436
437             $message1 = '';
438             $message2 = '';
439
440             if ( isset( $_GET['uploaded'] ) ) {
441                 $message1 = $lang['succefully_uploaded'];
442                 $message2 = $lang['succefully_uploaded_descr'];
443             }
444             elseif ( isset( $_GET['edited'] ) ) {
445                 $message1 = $lang['succefully_edited'];
446             }
447
448             $tzoffset = ( $userdata['session_logged_in'] ? $userdata['tzoffset'] : $config['board_timezone'] );
449
450             if ( $view ) {
451                 $template->assign_vars( array(
452                     strtoupper( $view ) . '_TPL' => ( isset( $tpl ) ? $tpl : '' )
453                 ));
454             }
455
456             $owner = ( $row['owner'] ? ( $row['privacy'] == PRIVACY_LEVEL_HIGH && $userdata['class'] < UC_MODERATOR && $row['owner'] <> $userdata['uid'] ? '<i>' . $lang['anonymous'] . '</i>' : $row['owner'] ) : '<i>' . $lang['unknown'] . '</i>' );
457             $last_activity = ( $row['mtime'] == $row['ctime'] ? $lang['none'] : sprintf( $lang['last_activity'], mkprettytime( time() - $row['mtime'] ) ) . ' (' . create_date($row['mtime']) . ')' );
458
459             $description = $row['descr'];
460             $bb_code = new bbcode($description);
461             $description = $bb_code->get_html();
462             $description = censor_text($description);
463
464             $page_description = split_string(strip_tags(str_replace(array('<br /><br />', '<br />'), array('<br />', ' '), $description)), 400, false);
465
466             if ( $highlight ) {
467                 $description = highlight_text($highlight, $description);
468             }
469
470             $cat_name = '<a href="' . append_sid($root_path . 'browse.php?cat=' . $cats[$row['category']]['cat_id']) . '">' . $cats[$row['category']]['cat_name'] . '</a>';
471
472             $rating_voted = true;
473             if ( $userdata['session_logged_in'] && $userdata['uid'] <> $row['owner'] ) {
474                 $sql = 'SELECT torrent FROM ' . RATINGS_TABLE . ' WHERE torrent = ' . $id . ' AND user = ' . $userdata['uid'];
475                 $result = $db->sql_query($sql);
476                 $rating_voted = $db->sql_fetchrow($result);
477             }
478
479             $rating = ratingpic($row['numratings'], $row['ratingsum'], false);
480             $info_hash = preg_replace_callback('/./s', create_function('$matches','return sprintf(\'%02x\', ord($matches[0]));'), str_pad($row['info_hash'], 20));
481
482             if ( $seo->seo_opt['url_rewrite'] ) {
483                 $u_details_no_sid = $seo->drop_sid(append_sid($root_path . 'details.php?id=' . $id));
484             }
485             else {
486                 $u_details_no_sid = generate_base_url() . '/details.php?id=' . $id;
487             }
488
489             $template->assign_vars( array(
490                 'MESSAGE1' => $message1,
491                 'MESSAGE2' => $message2,
492                 'U_DETAILS' => append_sid($root_path . 'details.php?id=' . $id),
493                 'U_DETAILS_NO_SID' => $u_details_no_sid,
494                 'U_DOWNLOAD' => append_sid($root_path . 'details.php?id=' . $id . '&amp;action=download'),
495                 'U_DOWNLOAD_AS_GZIP' =>  append_sid($root_path . 'details.php?id=' . $id . '&amp;action=download&amp;type=gzip'),
496                 'U_ADD_TO_BOOKMARKS' => append_sid('bookmarks.php?torrent=' . $id ),
497                 'U_VIEW_NFO' => append_sid($root_path . 'details.php?id=' . $id . '&amp;action=viewnfo'),
498                 'U_VIEW_SNATCHEDLIST' => append_sid($root_path . 'details.php?id=' . $id . '&amp;view=snatchedlist'),
499                 'U_VIEW_PEERLIST' => append_sid($root_path . 'details.php?id=' . $id . '&amp;view=peerlist'),
500                 'U_VIEW_FILELIST' => append_sid($root_path . 'details.php?id=' . $id . '&amp;view=filelist'),
501                 'U_MAGNET' => 'magnet:?xt=urn:btih:' . $info_hash . '&amp;dn=' . rawurlencode($row['filename']) . '&amp;tr=' . implode('&amp;tr=', $announce_urls),
502                 'S_EDIT_ACTION' => append_sid($root_path . 'details.php?id=' . $id . '&amp;action=edit'),
503                 'SPACER' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
504                 'NAME' => $torrent_name,
505                 'NAME_ENC' => urlencode($torrent_name),
506                 'NAME_ENC_TEXT' => str_replace(array("'", "(", ")"), array("\'", "\(", "\)"), $torrent_name),
507                 'FREE_ICON' => get_free_icon($row['free']),
508                 'TORRENT_FILENAME' => htmlspecialchars($row['filename']),
509                 'INFO_HASH' => $info_hash,
510                 'DESCRIPTION' => $description,
511                 'BANNED' => ( $row['banned'] ? $lang['yes'] : $lang['no'] ),
512                 'TYPE' => $cat_parent_name . $cat_name,
513                 'LAST_ACTIVITY' => $last_activity,
514                 'SIZE' => mksize( $row['size'] ) . ' (' . number_format( $row['size'] ) . ' ' . $lang['bytes'] . ')',
515                 'ADDED' => create_date($row['ctime']),
516                 'VIEWS' => $row['views'],
517                 'HITS' => $row['hits'],
518                 'HIDDEN' => ( $row['hidden'] ? $lang['yes'] : $lang['no'] ),
519                 'USER_UPLOADED' => ( is_numeric($owner) ? ( '<a href="' . append_sid($root_path . 'userdetails.php?id=' . $owner ) . '"><b>' . $row['username'] . '</b></a>' ) : $owner ),
520                 'NUM_FILES' => sprintf( $lang['num_files'], $row['numfiles'] ),
521                 'PEERS_COUNT' => sprintf( $lang['peers_count'], $row['seeders'], $row['leechers'], ( $row['seeders'] + $row['leechers'] ) ),
522                 'REPORT' => sprintf( $lang['report_descr'], append_sid( 'reports.php?action=send_report&amp;type=torrent&amp;id=' . $id ) ),
523                 'OWNER_ID' => ( is_numeric($owner) ? $owner : 0 ),
524
525                 'COMPLETED' => $row['completed'],
526                 'L_DETAILS_SNATCHED_COUNT' => sprintf( $lang['snatched_times'], $row['completed'] ),
527
528                 'TAG_TYPE' => TYPE_TORRENT,
529                 'ALLOW_ADD_TAGS' => tags::return_allow_add_tag(TYPE_TORRENT, $id, $row['owner']),
530
531                 'RATING' => sprintf($lang['total_rating'], $rating, $row['numratings'], $config['minvotes']),
532                 'RATING_PIC_WIDTH' => $rating * $config['rating_pic_width'],
533                 'RATING_VOTED' => $rating_voted,
534
535                 'SHOW_SOS_BUTTON' => ( $userdata['session_logged_in'] && ( $row['completed'] && $row['seeders'] < $config['min_seeders_for_sos_button'] ) && ( $row['seeders'] < $row['completed'] + 1 ) ? 1 : 0 ),
536
537                 'BOOKMARKS_TITLE' => sprintf($lang['torrent_details'], $torrent_name),
538
539             ));
540
541             if ( $userdata['session_logged_in'] && $userdata['class'] >= UC_ADMINISTRATOR ) {
542                 $template->assign_block_vars( 'switch_add_to_index', array(
543                     'U_ADD_TO_INDEX' => append_sid( 'releases.php?action=autoadd&amp;id=' . $id )
544                 ));
545             }
546             if ( $row['nfo'] ) {
547                 $template->assign_block_vars( 'switch_nfo_section', array() );
548             }
549             if ( $userdata['session_logged_in'] && ( $userdata['hiddentorrents'] || $userdata['class'] >= UC_MODERATOR ) ) {
550                 $template->assign_block_vars( 'switch_hidden_section', array() );
551             }
552
553             if ( $userdata['uid'] == $row['owner'] || $userdata['class'] >= UC_MODERATOR ) {
554                 $template->assign_block_vars( 'switch_owner_section', array() );
555             }
556
557             /* start tags */
558             $tags = tags::tags_for_single(TYPE_TORRENT, $id);
559             $template->assign_vars(array(
560                 'TAGS' => ( sizeof($tags) ? '' : $lang['no_tags'] )
561             ));
562
563             foreach ( $tags AS $_null => $tag_ary ) {
564                 $template->assign_block_vars('tags_row', array(
565                     'TAG_NAME' => $tag_ary['tag_name'],
566                     'JS_TAG_NAME' => $tag_ary['js_tag_name'],
567                     'ENC_TAG_NAME' => $tag_ary['enc_tag_name'],
568                     'TAG_SIZE' => $tag_ary['tag_size'],
569                     'TAG_NUM' => $tag_ary['tag_num'],
570
571                     'U_TAG' => append_sid($root_path . 'browse.php?search_in=3&amp;search=' . $tag_ary['enc_tag_name']),
572                     'U_TAG_USERS' => append_sid($root_path . 'modtask.php?action=tags&amp;do=view_users&amp;tag_name=' . $tag_ary['enc_tag_name'] . '&amp;tag_type=' . TYPE_TORRENT . '&amp;tag_for_id=' . $id),
573                 ));
574             }
575             /* end tags */
576
577             /* start similiar torrents */
578             require ($root_path . 'include/functions_search.php');
579
580             $sim_name = $row['name'];
581             //delete all in () and in []
582             $sim_name = preg_replace('/(\[|\()(.*?)(\]|\))/si', '', $sim_name);
583             //delimeters which used to determine base name, first have highest order
584             $delims = array('/', '-', '.', ':');
585
586             for ( $i = 0; $i < sizeof($delims); ++$i ) {
587                 if ( $pos = strpos($sim_name, $delims[$i]) ) {
588                     $f_sim_name = substr($sim_name, 0, $pos);
589                     $f_sim_name = trim($f_sim_name);
590
591                     //we found small name, try another part
592                     if ( utf_strlen($f_sim_name) <= $config['search_min_chars'] ) {
593                         $sim_name = substr($sim_name, $pos + 1);
594                         //reset loop
595                         $i = -1;
596                         continue;
597                     }
598                     $sim_name = $f_sim_name;
599                     break;
600                 }
601             }
602
603             //delete all double words
604             $sim_name = implode(' ', array_unique(explode(' ', $sim_name)));
605             //delete year (four digits)
606             $sim_name = preg_replace('/[0-9]{4}/si', '', $sim_name);
607             //some clean
608             $sim_name = searchfield($sim_name);
609             //delete all small worlds
610             $sim_name = preg_replace('/(^|[\s])[\S]{1,3}(?=[\s]|$)/iu', '', $sim_name);
611             //delete double spaces
612             $sim_name = str_replace('  ', ' ', $sim_name);
613             //trim and lower case
614             $sim_name = trim(utf_strtolower($sim_name));
615
616             $size_sim = 0;
617
618             $show_similiar_torrents = false;
619
620             if ( utf_strlen($sim_name) >= $config['search_min_chars'] ) {
621
622                 $sql = 'SELECT t.*, u.uid, u.name AS username, u.class, u.privacy
623                         FROM ' . TORRENTS_TABLE . ' t, ' . USERS_TABLE . ' u
624                         WHERE t.moderated = 1
625                         AND u.uid = t.owner
626                         AND t.name LIKE \'%' . str_replace(' ', '%', $sim_name)  . '%\'
627                         AND t.fid <> ' . $id . '
628                         ORDER BY t.category = ' . (int) $row['category'] . ' DESC, t.ctime DESC';
629                 $result = $db->sql_query_limit($sql, 50);
630                 if ( $subrow = $db->sql_fetchrow($result) ) {
631
632                     require ($root_path . 'include/functions_torrenttable.php');
633
634                     $show_similiar_torrents = true;
635                     $ary = array();
636
637                     do {
638                         if ( $userdata['class'] < UC_MODERATOR ) {
639                             if ( $row['hidden'] || $row['banned'] ) {
640                                 continue;
641                             }
642                         }
643                         $ary[] = $subrow;
644                     }
645                     while ( $subrow = $db->sql_fetchrow($result) );
646
647                     if ( $size_sim = sizeof($ary) ) {
648                         torrenttable($ary);
649                     }
650                 }
651             }
652             /* end similiar torrents */
653
654             $include_header = false;
655
656             $body = 'details.html';
657
658             stdhead( sprintf( $lang['torrent_details'], $torrent_name ), false );
659         }
660         else {
661             stdhead( sprintf( $lang['comments_for'], $torrent_name ) );
662             $template->assign_vars(array(
663                 'COMMENTS_FOR' => sprintf( $lang['comments_for'], '<a href="' . append_sid($root_path . 'details.php?id=' . $id) . '">' . $torrent_name . '</a>' )
664             ));
665
666             $include_header = true;
667             $show_similiar_torrents = false;
668             $size_sim = 0;
669
670             $body = 'details_comments.html';
671         }
672         if ( $userdata['session_logged_in'] ) {
673             $sql = 'SELECT checkcomm_view_status FROM ' . COMMENTS_NOTIFY_TABLE . ' WHERE checkcomm_userid = ' . $userdata['uid'] . ' AND checkcomm_type = ' . TYPE_TORRENT . ' AND checkcomm_for_id = ' . $id;
674             $result = $db->sql_query( $sql );
675             $checkcomm = $db->sql_fetchrow( $result );
676             $db->sql_freeresult( $result );
677             if ( $checkcomm ) {
678                 if ( $checkcomm['checkcomm_view_status'] == VIEW_STATUS_NOT_VIEWED ) {
679                     $sql_priority = ( $db_type == 'mysql' ) ? ' LOW_PRIORITY' : '';
680                     $sql = 'UPDATE' . $sql_priority . ' ' . COMMENTS_NOTIFY_TABLE . ' SET checkcomm_view_status = ' . VIEW_STATUS_VIEWED . ', checkcomm_notify_status = ' . NOTIFY_STATUS_UN_NOTIFIED . ' WHERE checkcomm_userid = ' . $userdata['uid'] . ' AND checkcomm_type = ' . TYPE_TORRENT . ' AND checkcomm_for_id = ' . $id;
681                     $db->sql_query($sql);
682                 }
683                 $check_action = append_sid($root_path . 'comment.php?type=' . TYPE_TORRENT . '&amp;action=checkoff&amp;tid=' . $id);
684                 $check_title = $lang['checkcomm_off'];
685             }
686             else {
687                 $check_action = append_sid($root_path . 'comment.php?type=' . TYPE_TORRENT . '&amp;action=check&amp;tid=' . $id);
688                 $check_title = $lang['checkcomm_on'];
689             }
690
691             set_tracking(TYPE_TORRENT, $id);
692         }
693         else {
694             $check_action = '';
695             $check_title = '';
696         }
697
698         if ( $row['comments'] ) {
699             list($pagertop, $pagerbottom, $offset, $limit) = pager($config['posts_per_page'], $row['comments'], 'details.php?id=' . $id . '&amp;' . ( isset( $_GET['view'] ) ? 'view=comments&amp;' : '' ));
700             commenttable(TYPE_TORRENT, $id, $row['owner'], $offset, $limit);
701         }
702         else {
703             $pagertop = '';
704             $pagerbottom = '';
705         }
706
707         $template->assign_vars(array(
708             'U_ADD_COMMENT' => append_sid($root_path . 'comment.php?type=' . TYPE_TORRENT . '&amp;action=add&amp;tid=' . $id ),
709             'U_CHECK' => $check_action,
710             'CHECK_TITLE' => $check_title,
711             'DISABLE_COMMENTS' => $row['disable_comments'],
712
713             'COMMENTS_COUNT' => $row['comments'],
714
715             'INCLUDE_HEADER' => $include_header,
716
717             'PAGERTOP' => $pagertop,
718
719             'PAGERBOTTOM' => $pagerbottom,
720
721             'SHOW_SIMILIAR_TORRENTS' => $show_similiar_torrents,
722             'SIZE_SIM' => ( $size_sim < 5 ? $size_sim * $config['similiar_torrents_height'] : 5 * $config['similiar_torrents_height'] ),
723         ));
724     }
725     $template->set_filenames( array(
726         'body' => $body
727     ));
728     stdfoot();
729 }
730
731 ?>
Note: See TracBrowser for help on using the browser.