Changeset 299

Show
Ignore:
Timestamp:
02/16/10 15:14:19 (2 years ago)
Author:
Nafania
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • index.php

    r280 r299  
    1111$sql = 'SELECT uid, name FROM ' . USERS_TABLE . ' WHERE status = 1 AND uid <> ' . ANONYMOUS . ' ORDER BY uid DESC'; 
    1212$result = $db->sql_query_limit($sql, 1, 0, 20 * 60); 
    13 if ($row = $db->sql_fetchrow($result)) { 
     13if ( $row = $db->sql_fetchrow($result) ) { 
    1414 
    1515        // www.phpBB-SEO.com SEO TOOLKIT START 
     
    2525        // start birthday users 
    2626        $now = date('m-d', time() + $userdata['tzoffset']); 
    27         $sql = 'SELECT uid, name, class, parked, warneduntil, enabled, donor, birthday FROM ' . USERS_TABLE . ' WHERE birthday LIKE \'%-' . $now . '\' AND enabled = 1 AND status = 1'; 
     27        $sql = 'SELECT uid, name, class, parked, warneduntil, enabled, donor, birthday 
     28                        FROM ' . USERS_TABLE . ' 
     29                        WHERE birthday LIKE \'%-' . $now . '\' 
     30                        AND enabled = 1 
     31                        AND status = 1 
     32                        ORDER BY class DESC, name ASC'; 
    2833        $result = $db->sql_query($sql, 120 * 60); 
    2934 
    3035        $birthday_users = ''; 
    31         if ( $birthday_arr = $db->sql_fetchrow($result) ) { 
     36        $i = 0; 
     37        if ( $row = $db->sql_fetchrow($result) ) { 
    3238                do { 
     39                        ++$i; 
    3340                        // www.phpBB-SEO.com SEO TOOLKIT START 
    34                         $seo->set_user_url($birthday_arr['name'], $birthday_arr['uid']); 
     41                        $seo->set_user_url($row['name'], $row['uid']); 
    3542                        // www.phpBB-SEO.com SEO TOOLKIT END 
    3643 
    37                $age = get_age($birthday_arr['birthday']); 
    38                $birthday_arr['name'] = get_user_class_color($birthday_arr['class'], $birthday_arr['name']); 
    39                $birthday_users .= ( $birthday_users ? ', ' : '' ) . '<a href="' . append_sid($root_path . 'userdetails.php?id=' . $birthday_arr['uid']) . '">' . $birthday_arr['name'] . '</a> (' . $age . ')' . get_user_icons($birthday_arr); 
     44               $age = get_age($row['birthday']); 
     45               $row['name'] = get_user_class_color($row['class'], $row['name']); 
     46               $birthday_users .= ( $birthday_users ? ', ' : '' ) . '<a href="' . append_sid($root_path . 'userdetails.php?id=' . $row['uid']) . '">' . $row['name'] . '</a> (' . $age . ')' . get_user_icons($row); 
     47 
     48               if ( $i == 50 ) { 
     49                       $birthday_users .= ' <a href="javascript:;" onclick="$(this).next(\'span\').show();$(this).remove();">' . $lang['see_full_list'] . '</a><span style="display:none">'; 
     50               } 
     51 
    4052 
    4153                } 
    42           while ($birthday_arr = $db->sql_fetchrow($result)); 
     54          while ( $row = $db->sql_fetchrow($result) ); 
     55 
     56          if ( $i > 50 ) { 
     57                  $birthday_users .= '</span>'; 
     58          } 
    4359        } 
    4460        $db->sql_freeresult($result); 
     
    4662 
    4763        $template->assign_vars(array( 
    48                 'BIRTHDAY_USERS' => $birthday_users ) 
    49         )
     64                'BIRTHDAY_USERS' => $birthday_users 
     65        ))
    5066 
    5167        /* start poll */ 
  • js/signup.js

    r293 r299  
    66                        passagain: {required: true,minlength: 6,maxlength: 40,equalTo: '#wantpassword'}, 
    77                        email: {required: true,email: true,remote : S_EMAIL_CHECK}, 
    8                         month: {required: true,digits:true}, 
    9                         day: {required: true,digits:true}, 
    10                         year: {required: true,digits:true}, 
     8                        month: {required: true}, 
     9                        day: {required: true}, 
     10                        year: {required: true}, 
    1111                        country: {required: true}, 
    1212                        upload: {required: true}, 
     
    1919                        wantusername: {remote : L_JS_USERNAME_CHECK_INVALID}, 
    2020                        email: {remote : L_JS_EMAIL_CHECK_INVALID} 
    21                 }, 
     21                } 
    2222        }); 
    2323 
  • languages/lang_english/lang_forum.php

    r269 r299  
    260260        'post_a_reply' =>  'Post a reply', 
    261261        'post_topic_as' =>  'Post topic as', 
     262        'topic_first_post_sticky' =>  'First post is sticky', 
    262263        'edit_post' =>  'Edit post', 
    263264        'options' =>  'Options', 
  • languages/lang_english/lang_main.php

    r296 r299  
    10491049                'April' => 'April', 
    10501050                'May' => 'May', 
     1051                'May_short' => 'May', 
    10511052                'June' => 'June', 
    10521053                'July' => 'July', 
     
    10671068                'Oct' => 'Oct', 
    10681069                'Nov' => 'Nov', 
    1069                 'Dec' => 'Dec' 
     1070                'Dec' => 'Dec', 
     1071 
     1072                        'today'         => 'Today', 
     1073                        'tomorrow'      => 'Tomorrow', 
     1074                        'yesterday'     => 'Yesterday', 
     1075                        'ago'           => array( 
     1076                                0               => 'less than a minute ago', 
     1077                                1               => '%d minute ago', 
     1078                                2               => '%d minutes ago', 
     1079                                60              => '1 hour ago', 
     1080                ), 
    10701081        ), 
    10711082 
     
    12271238        'similiar_torrents' => 'Similiar torrents', 
    12281239 
     1240        'top_ten_popular_torrents' => 'Топ популярных торрентов', 
     1241        'top_ten_users' => 'Топ пользователей', 
     1242        'top_ten_peers' => 'Топ пиров', 
     1243        'top_ten_by_completed' => 'По скачиваниям', 
     1244        'top_ten_by_peers' => 'По количеству пиров', 
     1245        'top_ten_by_comments' => 'По комментариям', 
     1246        'top_ten_by_uploaded' => 'По загруженной информации', 
     1247        'top_ten_by_downloaded' => 'По скачанной информации', 
     1248        'top_ten_by_ratio' => 'По ратио', 
     1249        'top_ten_by_total_seed_time' => 'По времени сидирования', 
     1250        'top_ten_by_reputation' => 'По репутации', 
     1251        'top_ten_by_upspeed' => 'По скорости загрузки', 
     1252        'top_ten_by_downspeed' => 'По скорости скачивания', 
     1253        'show_by' => 'Выводить по', 
     1254        'for' => 'за', 
     1255        'and_sort' => 'и сортировать', 
     1256        'sort_asc' => 'По возрастанию', 
     1257        'sort_desc' => 'По убыванию', 
     1258        'show' => 'Показать', 
     1259        'all_time' => 'Все время', 
     1260        'show_all_cats' => 'Показывать все категории', 
     1261        'show_only_my_cats' => 'Показывать только мои категории', 
     1262 
    12291263        'translated_by' => 'Translation to english made by %s', 
    12301264)); 
  • languages/lang_russian/lang_forum.php

    r269 r299  
    265265        'post_a_reply' =>  'Ответить', 
    266266        'post_topic_as' =>  'Статус создаваемой темы', 
     267        'topic_first_post_sticky' =>  'Прилепить первый пост', 
    267268        'edit_post' =>  'Редактировать сообщение', 
    268269        'options' =>  'Настройки', 
  • languages/lang_russian/lang_main.php

    r296 r299  
    428428        'required' => 'обязательно', 
    429429        'some_other' => 'Прочее', 
    430         'torrent_details' => 'Детали торрента &quot;%s&quot;', 
     430        'torrent_details' => 'Скачать торрент &quot;%s&quot;', 
    431431        'succefully_uploaded' => 'Успешно загружено!', 
    432432        'succefully_uploaded_descr' => 'Теперь вы можете сидировать. <b>Внимание</b> торрента не будет видно пока вы это не сделаете!', 
     
    10561056                'April' => 'Апрель', 
    10571057                'May' => 'Май', 
     1058                'May_short' => 'Май', 
    10581059                'June' => 'Июнь', 
    10591060                'July' => 'Июль', 
     
    10741075                'Oct' => 'Окт', 
    10751076                'Nov' => 'Ноя', 
    1076                 'Dec' => 'Дек' 
     1077                'Dec' => 'Дек', 
     1078 
     1079                'today' => 'сегодня', 
     1080                'tomorrow' => 'завтра', 
     1081                'yesterday' => 'вчера', 
     1082 
     1083                'ago'           => array( 
     1084                        0               => 'менее минуты назад', 
     1085                        1               => '%d минуту назад', 
     1086                        2               => '%d минуты назад', 
     1087                        5               => '%d минут назад', 
     1088                        21              => '%d минуту назад', 
     1089                        22              => '%d минуты назад', 
     1090                        25              => '%d минут назад', 
     1091                        31              => '%d минуту назад', 
     1092                        32              => '%d минуты назад', 
     1093                        35              => '%d минут назад', 
     1094                        41              => '%d минуту назад', 
     1095                        42              => '%d минуты назад', 
     1096                        45              => '%d минут назад', 
     1097                        51              => '%d минуту назад', 
     1098                        52              => '%d минуты назад', 
     1099                        55              => '%d минут назад', 
     1100                        60              => '1 час назад', 
     1101                ), 
    10771102        ), 
    10781103 
     
    12351260        'similiar_torrents' => 'Похожие торренты', 
    12361261 
     1262        'top_ten_popular_torrents' => 'Топ популярных торрентов', 
     1263        'top_ten_users' => 'Топ пользователей', 
     1264        'top_ten_peers' => 'Топ пиров', 
     1265        'top_ten_by_completed' => 'По скачиваниям', 
     1266        'top_ten_by_peers' => 'По количеству пиров', 
     1267        'top_ten_by_comments' => 'По комментариям', 
     1268        'top_ten_by_uploaded' => 'По загруженной информации', 
     1269        'top_ten_by_downloaded' => 'По скачанной информации', 
     1270        'top_ten_by_ratio' => 'По ратио', 
     1271        'top_ten_by_total_seed_time' => 'По времени сидирования', 
     1272        'top_ten_by_reputation' => 'По репутации', 
     1273        'top_ten_by_upspeed' => 'По скорости загрузки', 
     1274        'top_ten_by_downspeed' => 'По скорости скачивания', 
     1275        'show_by' => 'Выводить по', 
     1276        'for' => 'за', 
     1277        'and_sort' => 'и сортировать', 
     1278        'sort_asc' => 'По возрастанию', 
     1279        'sort_desc' => 'По убыванию', 
     1280        'show' => 'Показать', 
     1281        'all_time' => 'Все время', 
     1282        'show_all_cats' => 'Показывать все категории', 
     1283        'show_only_my_cats' => 'Показывать только мои категории', 
     1284 
     1285        'show_profile' => 'Показать профиль', 
     1286        'search_torrents' => 'Поиск торрентов', 
     1287 
    12371288        'translated_by' => 'На русский язык перевел %s', 
    12381289)); 
  • phpBB2/includes/functions.php

    r295 r299  
    434434                                $db->sql_query('DELETE FROM ' . TOPICS_TRACK_TABLE . " WHERE user_id = {$userdata['uid']}"); 
    435435                                $db->sql_query('DELETE FROM ' . FORUMS_TRACK_TABLE . " WHERE user_id = {$userdata['uid']}"); 
    436                                 $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE user_id = {$userdata['uid']}"); 
     436                                $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE uid = {$userdata['uid']}"); 
    437437                        } 
    438438                        else if ($config['load_anon_lastread'] || $userdata['session_logged_in']) 
     
    451451                                unset($tracking_topics); 
    452452 
    453                                 /*if ($userdata['session_logged_in']) 
    454                                 { 
    455                                         $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE user_id = {$userdata['uid']}"); 
    456                                 }*/ 
    457                                 //$userdata['user_lastmark'] = time(); 
     453                                if ($userdata['session_logged_in']) 
     454                                { 
     455                                        $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE uid = {$userdata['uid']}"); 
     456                                } 
    458457                        } 
    459458                } 
     
    595594                        $topic_id36 = base_convert($topic_id, 10, 36); 
    596595 
    597                         //if (!isset($tracking['t'][$topic_id36])) 
    598                         //
     596                        if (!isset($tracking['t'][$topic_id36])) 
     597                       
    599598                                $tracking['tf'][$forum_id][$topic_id36] = true; 
    600                         //
     599                       
    601600 
    602601                        $post_time = ($post_time) ? $post_time : time(); 
     
    636635                                { 
    637636                                        $userdata['user_lastmark'] = intval(base_convert(max($time_keys) + $config['onlinesince'], 36, 10)); 
    638                                         //$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . $userdata['user_lastmark'] . " WHERE user_id = {$userdata['uid']}"); 
     637                                        $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . $userdata['user_lastmark'] . " WHERE uid = {$userdata['uid']}"); 
    639638                                } 
    640639                                else 
     
    741740 
    742741                $user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $userdata['user_lastmark']; 
    743                 //$userdata['user_lastmark'] = $user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $userdata['user_lastmark']; 
    744742 
    745743                foreach ($topic_ids as $topic_id) 
     
    808806 
    809807                        $user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $userdata['user_lastmark']; 
    810                         //$userdata['user_lastmark'] = $user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $userdata['user_lastmark']; 
    811808 
    812809                        foreach ($topic_ids as $topic_id) 
     
    833830                } 
    834831 
    835                 //if (!$userdata['session_logged_in']) 
    836                 //
     832                if (!$userdata['session_logged_in']) 
     833               
    837834                        $user_lastmark = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince'] : 0; 
    838                 //
    839                 //else 
    840                 //
    841                 //    $user_lastmark = $userdata['user_lastmark']; 
    842                 //
     835               
     836                else 
     837               
     838                      $user_lastmark = $userdata['user_lastmark']; 
     839               
    843840 
    844841                foreach ($topic_ids as $topic_id) 
     
    913910        } 
    914911 
    915         if ($config['load_db_lastread'] && $user->data['is_registered']) 
     912        if ($config['load_db_lastread'] && $userdata['session_logged_in']) 
    916913        { 
    917914                // Get list of the unread topics 
    918                 $last_mark = $user->data['user_lastmark']; 
     915                $last_mark = $userdata['user_lastmark']; 
    919916 
    920917                $sql_array = array( 
     
    954951                $db->sql_freeresult($result); 
    955952        } 
    956         else if ($config['load_anon_lastread'] || $user->data['is_registered']) 
     953        else if ($config['load_anon_lastread'] || $userdata['session_logged_in']) 
    957954        { 
    958955                global $tracking_topics; 
     
    964961                } 
    965962 
    966                 if (!$user->data['is_registered']) 
    967                 { 
    968                         $user_lastmark = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0; 
     963                if (!$userdata['session_logged_in']) 
     964                { 
     965                        $user_lastmark = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince'] : 0; 
    969966                } 
    970967                else 
    971968                { 
    972                         $user_lastmark = (int) $user->data['user_lastmark']; 
     969                        $user_lastmark = (int) $userdata['user_lastmark']; 
    973970                } 
    974971 
     
    988985                        if (isset($tracking_topics['t'][$topic_id36])) 
    989986                        { 
    990                                 $last_read = base_convert($tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate']; 
     987                                $last_read = base_convert($tracking_topics['t'][$topic_id36], 36, 10) + $config['onlinesince']; 
    991988 
    992989                                if ($row['topic_last_post_time'] > $last_read) 
     
    997994                        else if (isset($tracking_topics['f'][$forum_id])) 
    998995                        { 
    999                                 $mark_time = base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']; 
     996                                $mark_time = base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['onlinesince']; 
    1000997 
    1001998                                if ($row['topic_last_post_time'] > $mark_time) 
     
    10411038                        $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array(); 
    10421039 
    1043                         //if (!$userdata['session_logged_in']) 
    1044                         //
     1040                        if (!$userdata['session_logged_in']) 
     1041                       
    10451042                                $userdata['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince']) : 0; 
    1046                         //
     1043                       
    10471044 
    10481045                        $mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['onlinesince']) : $userdata['user_lastmark']; 
     
    10851082                else 
    10861083                { 
    1087                         $sql = 'SELECT t.topic_id, p.post_time 
    1088                                 FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p 
    1089                                 WHERE t.forum_id = ' . $forum_id . ' 
    1090                                 AND p.topic_id = t.topic_id 
    1091                                         AND p.post_time > ' . $mark_time_forum . ' 
    1092                                         AND t.topic_moved_id = 0'; 
     1084                        $sql = 'SELECT topic_id 
     1085                                FROM ' . TOPICS_TABLE . ' 
     1086                                WHERE forum_id = ' . $forum_id . ' 
     1087                                        AND topic_last_post_time > ' . $mark_time_forum . ' 
     1088                                        AND topic_moved_id = 0'; 
    10931089                        $result = $db->sql_query($sql); 
    10941090 
  • phpBB2/includes/functions_post.php

    r295 r299  
    8080function submit_merged_post($post_id, $forum_id, $subject, $message, &$return_message, &$return_meta) 
    8181{ 
    82         global $config, $db, $lang, $phpEx, $root_path
     82        global $config, $db, $lang, $phpEx, $root_path, $userdata
    8383 
    8484        include($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_merge.' . $phpEx); 
     
    151151        $result = $db->sql_query($sql); 
    152152 
    153         $sql = "UPDATE " . FORUMS_TABLE . " SET forum_last_post_id = $post_id WHERE forum_id = $forum_id"; 
     153        $sql = "UPDATE " . FORUMS_TABLE . " SET forum_last_post_id = $post_id, forum_last_post_time = $current_time WHERE forum_id = $forum_id"; 
     154        $result = $db->sql_query($sql); 
     155 
     156        $sql = "UPDATE " . TOPICS_TABLE . " SET topic_last_post_time = $current_time WHERE topic_id = " . $last_post_data['topic_id']; 
    154157        $result = $db->sql_query($sql); 
    155158 
     
    157160        remove_search_post($post_id); 
    158161        add_search_words('single', $post_id, $message, $subject); 
     162 
     163 
     164        markread('post', $forum_id, $last_post_data['topic_id'], $current_time); 
     165 
     166        // Mark this topic as read 
     167        // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message) 
     168        markread('topic', $forum_id, $last_post_data['topic_id'], $current_time); 
     169        // 
     170 
     171        if ($config['load_db_lastread'] && $userdata['session_logged_in']) 
     172        { 
     173                $sql = 'SELECT mark_time 
     174                        FROM ' . FORUMS_TRACK_TABLE . ' 
     175                        WHERE user_id = ' . $userdata['user_id'] . ' 
     176                        AND forum_id = ' . $data['forum_id']; 
     177                $result = $db->sql_query($sql); 
     178                $f_mark_time = (int) $db->sql_fetchfield('mark_time'); 
     179                $db->sql_freeresult($result); 
     180        } 
     181        else if ($config['load_anon_lastread'] || $userdata['session_logged_in']) 
     182        { 
     183                $f_mark_time = false; 
     184        } 
     185 
     186        if (($config['load_db_lastread'] && $userdata['session_logged_in']) || $config['load_anon_lastread'] || $userdata['session_logged_in']) 
     187        { 
     188                // Update forum info 
     189                $sql = 'SELECT forum_last_post_time 
     190                        FROM ' . FORUMS_TABLE . ' 
     191                        WHERE forum_id = ' . $forum_id; 
     192                $result = $db->sql_query($sql); 
     193                $forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time'); 
     194                $db->sql_freeresult($result); 
     195 
     196                update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time, false); 
     197        } 
    159198 
    160199        // Meta & return message 
     
    273312// Post a new topic/reply/poll or edit existing post/poll 
    274313// 
    275 function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id, &$topic_type, &$bbcode_on, &$html_on, &$smilies_on, &$attach_sig, $post_username, $post_subject, $post_message, $poll_title, &$poll_options, &$poll_length
     314function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id, &$topic_type, &$bbcode_on, &$html_on, &$smilies_on, &$attach_sig, $post_username, $post_subject, $post_message, $poll_title, &$poll_options, &$poll_length, &$topic_first_post_sticky
    276315{ 
    277316        global $config, $lang, $db, $root_path, $phpEx; 
     
    313352                $topic_vote = (!empty($poll_title) && count($poll_options) >= 2) ? 1 : 0; 
    314353 
    315                 $sql  = ($mode != "editpost") ? "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) VALUES ('" . $db->sql_escape($post_subject) . "', " . $userdata['uid'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_vote)" : "UPDATE " . TOPICS_TABLE . " SET topic_title = '" . $db->sql_escape($post_subject) . "', topic_type = $topic_type " . (($post_data['edit_vote'] || !empty($poll_title)) ? ", topic_vote = " . $topic_vote : "") . " WHERE topic_id = $topic_id"; 
     354                if ( $mode != 'editpost' ) { 
     355                        $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array( 
     356                                'topic_title' => $post_subject, 
     357                                'topic_poster' => $userdata['uid'], 
     358                                'topic_time' => $current_time, 
     359                                'forum_id' => $forum_id, 
     360                                'topic_status' => TOPIC_UNLOCKED, 
     361                                'topic_type' => $topic_type, 
     362                                'topic_first_post_sticky' => $topic_first_post_sticky, 
     363                                'topic_vote' => $topic_vote, 
     364                        )); 
     365                } 
     366                else { 
     367                        $sql = "UPDATE " . TOPICS_TABLE . " SET topic_title = '" . $db->sql_escape($post_subject) . "', topic_type = $topic_type " . (($post_data['edit_vote'] || !empty($poll_title)) ? ", topic_vote = " . $topic_vote : "") . ", topic_first_post_sticky = $topic_first_post_sticky WHERE topic_id = $topic_id"; 
     368                } 
    316369                $db->sql_query($sql); 
    317370 
     
    394447        } 
    395448 
     449        $post_data['post_time'] = $current_time; 
     450 
     451        if ($mode == 'post' || $mode == 'reply' || $mode == 'quote') 
     452        { 
     453                // Mark this topic as posted to 
     454                markread('post', $forum_id, $topic_id, $current_time); 
     455        } 
     456 
     457        // Mark this topic as read 
     458        // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message) 
     459        markread('topic', $forum_id, $topic_id, time()); 
     460        // 
     461 
     462        if ($config['load_db_lastread'] && $userdata['session_logged_in']) 
     463        { 
     464                $sql = 'SELECT mark_time 
     465                        FROM ' . FORUMS_TRACK_TABLE . ' 
     466                        WHERE user_id = ' . $userdata['user_id'] . ' 
     467                        AND forum_id = ' . $data['forum_id']; 
     468                $result = $db->sql_query($sql); 
     469                $f_mark_time = (int) $db->sql_fetchfield('mark_time'); 
     470                $db->sql_freeresult($result); 
     471        } 
     472        else if ($config['load_anon_lastread'] || $userdata['session_logged_in']) 
     473        { 
     474                $f_mark_time = false; 
     475        } 
     476 
     477        if (($config['load_db_lastread'] && $userdata['session_logged_in']) || $config['load_anon_lastread'] || $userdata['session_logged_in']) 
     478        { 
     479                // Update forum info 
     480                $sql = 'SELECT forum_last_post_time 
     481                                FROM ' . FORUMS_TABLE . ' 
     482                                WHERE forum_id = ' . $forum_id; 
     483                $result = $db->sql_query($sql); 
     484                $forum_last_post_time = (int) $db->sql_fetchfield('post_time'); 
     485                $db->sql_freeresult($result); 
     486 
     487                update_forum_tracking_info($forum_id,$forum_last_post_time, $f_mark_time, false); 
     488        } 
     489 
    396490        //$meta = '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">'; 
    397491        $meta = '<meta http-equiv="refresh" content="3;url=' . append_sid($root_path . "phpbb2.php?page=viewtopic&" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">'; 
     
    426520                                $topic_update_sql .= 'topic_replies = topic_replies - 1'; 
    427521 
    428                                 $sql = "SELECT MAX(post_id) AS last_post_id 
    429                                         FROM " . POSTS_TABLE . " 
    430                                         WHERE topic_id = $topic_id"; 
    431                                 $result = $db->sql_query($sql); 
     522                                $sql = "SELECT p.post_id AS last_post_id, p2.post_time 
     523                                        FROM " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 
     524                                        WHERE p.topic_id = $topic_id AND p.post_id = p2.post_id 
     525                                        ORDER BY p.post_id DESC"; 
     526                                $result = $db->sql_query_limit($sql, 1); 
    432527 
    433528                                if ($row = $db->sql_fetchrow($result)) 
    434529                                { 
    435530                                        $topic_update_sql .= ', topic_last_post_id = ' . $row['last_post_id']; 
     531                                        $topic_update_sql .= ', topic_last_post_time = ' . $row['post_time']; 
    436532                                } 
    437533                        } 
     
    439535                        if ($post_data['last_topic']) 
    440536                        { 
    441                                 $sql = "SELECT MAX(post_id) AS last_post_id 
    442                                         FROM " . POSTS_TABLE . " 
    443                                         WHERE forum_id = $forum_id"; 
    444                                 $result = $db->sql_query($sql); 
     537                                $sql = "SELECT p.post_id AS last_post_id, p2.post_time 
     538                                        FROM " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 
     539                                        WHERE p.forum_id = $forum_id AND p.post_id = p2.post_id 
     540                                        ORDER BY p.post_id DESC"; 
     541                                $result = $db->sql_query_limit($sql, 1); 
    445542 
    446543                                if ($row = $db->sql_fetchrow($result)) 
    447544                                { 
    448                                         $forum_update_sql .= ($row['last_post_id']) ? ', forum_last_post_id = ' . $row['last_post_id'] : ', forum_last_post_id = 0'; 
     545                                        $forum_update_sql .= ($row['last_post_id']) ? ', forum_last_post_id = ' . $row['last_post_id'] . ', forum_last_post_time = ' . $row['post_time'] : ', forum_last_post_id = 0'; 
    449546                                } 
    450547                        } 
     
    469566        else if ($mode != 'poll_delete') 
    470567        { 
    471                 $forum_update_sql .= ", forum_last_post_id = $post_id" . (($mode == 'newtopic') ? ", forum_topics = forum_topics $sign" : ""); 
    472                 $topic_update_sql = "topic_last_post_id = $post_id" . (($mode == 'reply') ? ", topic_replies = topic_replies $sign" : ", topic_first_post_id = $post_id"); 
     568                $forum_update_sql .= ", forum_last_post_id = $post_id, forum_last_post_time = " . $post_data['post_time'] . (($mode == 'newtopic') ? ", forum_topics = forum_topics $sign" : ""); 
     569                $topic_update_sql = "topic_last_post_id = $post_id, topic_last_post_time = " . $post_data['post_time'] . (($mode == 'reply') ? ", topic_replies = topic_replies $sign" : ", topic_first_post_id = $post_id"); 
    473570        } 
    474571        else 
  • phpBB2/index.php

    r295 r299  
    8585        $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array(); 
    8686 
    87 //     if (!$user->data['is_registered']) 
    88 //    { 
    89                 $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince']) : 0; 
    90 //    } 
     87       if (!$userdata['session_logged_in']) 
     88      { 
     89                $userdata['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince']) : 0; 
     90      } 
    9191} 
    9292 
     
    191191        while( $row = $db->sql_fetchrow($result) ) 
    192192        { 
    193                 if ($config['load_db_lastread'] && $user->data['is_registered']) 
     193                if ($config['load_db_lastread'] && $userdata['session_logged_in']) 
    194194                { 
    195195                        $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $userdata['user_lastmark']; 
    196196                } 
    197                 else if ($config['load_anon_lastread'] || $user->data['is_registered']) 
    198                 { 
    199                         //if (!$userdata['session_logged_in']) 
    200                         //
     197                else if ($config['load_anon_lastread'] || $userdata['session_logged_in']) 
     198                { 
     199                        if (!$userdata['session_logged_in']) 
     200                       
    201201                                $userdata['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince']) : 0; 
    202                         //
     202                       
    203203                        $forum_tracking_info[$row['forum_id']] = (isset($tracking_topics['f'][$row['forum_id']])) ? (int) (base_convert($tracking_topics['f'][$row['forum_id']], 36, 10) + $config['onlinesince']) : $userdata['user_lastmark']; 
    204204                } 
  • phpBB2/modcp.php

    r280 r299  
    278278                        $sql = "SELECT poster_id, COUNT(post_id) AS posts 
    279279                                FROM " . POSTS_TABLE . " 
    280                                 WHERE topic_id IN ($topic_id_sql) 
     280                                WHERE topic_id IN ($topic_id_sql) AND poster_id <> " . ANONYMOUS . " 
    281281                                GROUP BY poster_id"; 
    282282                        $result = $db->sql_query($sql); 
     
    489489                                        if ( isset($_POST['move_leave_shadow']) ) 
    490490                                        { 
     491                                                $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array( 
     492                                                        'forum_id' => $old_forum_id, 
     493                                                        'topic_title' => str_replace("\'", "''", $row[$i]['topic_title']), 
     494                                                        'topic_poster' => str_replace("\'", "''", $row[$i]['topic_poster']), 
     495                                                        'topic_time' => $row[$i]['topic_time'], 
     496                                                        'topic_status' => TOPIC_MOVED, 
     497                                                        'topic_type' => POST_NORMAL, 
     498                                                        'topic_vote' => $row[$i]['topic_vote'], 
     499                                                        'topic_views' => $row[$i]['topic_views'], 
     500                                                        'topic_replies' => $row[$i]['topic_replies'], 
     501                                                        'topic_first_post_id' => $row[$i]['topic_first_post_id'], 
     502                                                        'topic_last_post_id' => $row[$i]['topic_last_post_id'], 
     503                                                        'topic_last_post_time' => $row[$i]['topic_last_post_time'], 
     504                                                        'topic_moved_id' => $topic_id, 
     505                                                                        )); 
    491506                                                // Insert topic in the old forum that indicates that the forum has moved. 
    492                                                 $sql = "INSERT INTO " . TOPICS_TABLE . " (forum_id, topic_title, topic_poster, topic_time, topic_status, topic_type, topic_vote, topic_views, topic_replies, topic_first_post_id, topic_last_post_id, topic_moved_id) 
    493                                                         VALUES ($old_forum_id, '" . addslashes(str_replace("\'", "''", $row[$i]['topic_title'])) . "', '" . str_replace("\'", "''", $row[$i]['topic_poster']) . "', " . $row[$i]['topic_time'] . ", " . TOPIC_MOVED . ", " . POST_NORMAL . ", " . $row[$i]['topic_vote'] . ", " . $row[$i]['topic_views'] . ", " . $row[$i]['topic_replies'] . ", " . $row[$i]['topic_first_post_id'] . ", " . $row[$i]['topic_last_post_id'] . ", $topic_id)"; 
    494507                                                $db->sql_query($sql); 
    495508                                        } 
     
    13811394                // End Simple Subforums MOD 
    13821395 
    1383                 $sql = "SELECT t.*, u.name AS username, u.uid, p.post_time 
    1384                         FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p 
     1396                $sql = "SELECT t.*, u.name AS username, u.uid 
     1397                        FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u 
    13851398                        WHERE t.forum_id = $forum_id 
    13861399                                AND t.topic_poster = u.uid 
    1387                                 AND p.post_id = t.topic_last_post_id 
    1388                         ORDER BY t.topic_type DESC, p.post_time DESC 
     1400                        ORDER BY t.topic_type DESC, t.topic_last_post_time DESC 
    13891401                        LIMIT $start, " . $config['topics_per_page']; 
    13901402                $result = $db->sql_query($sql); 
     
    14511463                        $topic_replies = $row['topic_replies']; 
    14521464 
    1453                         $last_post_time = create_date($row['post_time']); 
     1465                        $last_post_time = create_date($row['topic_last_post_time']); 
    14541466 
    14551467                        $template->assign_block_vars('topicrow', array( 
  • phpBB2/posting.php

    r295 r299  
    5959$topic_type = request_var('topictype', POST_NORMAL); 
    6060$topic_type = ( in_array($topic_type, array(POST_NORMAL, POST_STICKY, POST_ANNOUNCE)) ) ? $topic_type : POST_NORMAL; 
     61$topic_first_post_sticky = request_var('topic_first_post_sticky', 0); 
    6162 
    6263// 
     
    213214                $where_sql = "AND pt.post_id = p.post_id AND u.uid = p.poster_id"; 
    214215 
    215                 $sql = "SELECT f.*, t.topic_id, t.topic_status, t.topic_type, t.topic_first_post_id, t.topic_last_post_id, t.topic_vote, p.post_id, p.poster_id" . $select_sql . " 
     216                $sql = "SELECT f.*, t.topic_id, t.topic_status, t.topic_type, t.topic_first_post_id, t.topic_last_post_id, t.topic_vote, t.topic_first_post_sticky, p.post_id, p.poster_id" . $select_sql . " 
    216217                        FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $from_sql . " 
    217218                        WHERE p.post_id = $post_id 
     
    265266                $post_data['topic_type'] = $post_info['topic_type']; 
    266267                $post_data['poster_id'] = $post_info['poster_id']; 
     268                $post_data['topic_first_post_sticky'] = $post_info['topic_first_post_sticky']; 
    267269 
    268270                if ( $post_data['first_post'] && $post_data['has_poll'] ) 
     
    602604                                        $topic_type = ( $topic_type != $post_data['topic_type'] && !$is_auth['auth_sticky'] && !$is_auth['auth_announce'] ) ? $post_data['topic_type'] : $topic_type; 
    603605 
    604                                         submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, str_replace("\'", "''", $username), str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length); 
     606                                        submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, str_replace("\'", "''", $username), str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length, $topic_first_post_sticky); 
    605607                                } 
    606608                        } 
     
    609611                                $error_msg = ''; 
    610612                                submit_merged_post($last_post_id, $forum_id, $subject, $message, $return_message, $return_meta); 
    611                         } 
    612  
    613                         if ( $error_msg == '' ) { 
    614                                 $current_time = time(); 
    615  
    616                                 if ($mode == 'post' || $mode == 'reply' || $mode == 'quote') 
    617                                 { 
    618                                 // Mark this topic as posted to 
    619                                         markread('post', $forum_id, $topic_id, $current_time); 
    620                                 } 
    621  
    622                                 // Mark this topic as read 
    623                                 // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message) 
    624                                 markread('topic', $forum_id, $topic_id, $current_time); 
    625                                 // 
    626  
    627                                 if ($config['load_db_lastread'] && $user->data['is_registered']) 
    628                                 { 
    629                                         $sql = 'SELECT mark_time 
    630                                                 FROM ' . FORUMS_TRACK_TABLE . ' 
    631                                                 WHERE user_id = ' . $user->data['user_id'] . ' 
    632                                                 AND forum_id = ' . $data['forum_id']; 
    633                                         $result = $db->sql_query($sql); 
    634                                         $f_mark_time = (int) $db->sql_fetchfield('mark_time'); 
    635                                         $db->sql_freeresult($result); 
    636                                 } 
    637                                 else if ($config['load_anon_lastread'] || $user->data['is_registered']) 
    638                                 { 
    639                                         $f_mark_time = false; 
    640                                 } 
    641  
    642                                 if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $user->data['is_registered']) 
    643                                 { 
    644                                         // Update forum info 
    645                                         $sql = 'SELECT p.post_time 
    646                                                 FROM ' . FORUMS_TABLE . ' f LEFT JOIN ' . POSTS_TABLE . ' p ON ( f.forum_last_post_id = p.post_id ) 
    647                                                 WHERE f.forum_id = ' . $forum_id; 
    648                                         $result = $db->sql_query($sql); 
    649                                         $forum_last_post_time = (int) $db->sql_fetchfield('post_time'); 
    650                                         $db->sql_freeresult($result); 
    651  
    652                                         update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time, false); 
    653                                 } 
    654613                        } 
    655614                break; 
     
    997956                } 
    998957                $topic_type_toggle .= ' /> ' . $lang['post_sticky'] . '&nbsp;&nbsp;'; 
     958 
    999959        } 
    1000960 
     
    1012972        { 
    1013973                $topic_type_toggle = $lang['post_topic_as'] . ': <input type="radio" name="topictype" value="' . POST_NORMAL .'"' . ( ( $post_data['topic_type'] == POST_NORMAL || $topic_type == POST_NORMAL ) ? ' checked="checked"' : '' ) . ' /> ' . $lang['post_normal'] . '&nbsp;&nbsp;' . $topic_type_toggle; 
     974        } 
     975 
     976        if( $is_auth['auth_sticky'] ) { 
     977 
     978                $topic_type_toggle .= '<br /><input type="checkbox" name="topic_first_post_sticky" value="1"' . ( $post_data['topic_first_post_sticky'] ? ' checked="checked"' : '' ) . ' /> ' . $lang['topic_first_post_sticky']; 
    1014979        } 
    1015980} 
  • phpBB2/search.php

    r295 r299  
    729729                $per_page = ( $show_results == 'posts' ) ? $config['posts_per_page'] : $config['topics_per_page']; 
    730730 
    731                         /*if ($user->data['is_registered']) 
     731                        /*if ($userdata['session_logged_in']) 
    732732                        { 
    733                                 if ($config['load_db_track'] && $author_id !== $user->data['user_id']) 
     733                                if ($config['load_db_track'] && $author_id !== $userdata['uid']) 
    734734                                { 
    735                                         $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.user_id = ' . $user->data['user_id'] . ' 
     735                                        $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.user_id = ' . $userdata['uid'] . ' 
    736736                                                AND t.topic_id = tp.topic_id)'; 
    737737                                        $sql_select .= ', tp.topic_posted'; 
     
    740740                                if ($config['load_db_lastread']) 
    741741                                { 
    742                                         $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . ' 
     742                                        $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $userdata['uid'] . ' 
    743743                                                        AND t.topic_id = tt.topic_id) 
    744                                                 LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' 
     744                                                LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $userdata['uid'] . ' 
    745745                                                        AND ft.forum_id = f.forum_id)'; 
    746746                                        $sql_select .= ', tt.mark_time, ft.mark_time as f_mark_time'; 
     
    748748                        } 
    749749 
    750                         if ($config['load_anon_lastread'] || ($user->data['is_registered'] && !$config['load_db_lastread'])) 
     750                        if ($config['load_anon_lastread'] || ($userdata['session_logged_in'] && !$config['load_db_lastread'])) 
    751751                        {*/ 
    752752                                $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : ''; 
     
    790790                        foreach ($forums as $forum_id => $forum) 
    791791                        { 
    792                                 /*if ($user->data['is_registered'] && $config['load_db_lastread']) 
     792                                /*if ($userdata['session_logged_in'] && $config['load_db_lastread']) 
    793793                                { 
    794794                                        $topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), ($forum_id) ? false : $forum['topic_list']); 
    795795                                } 
    796                                 else if ($config['load_anon_lastread'] || $user->data['is_registered']) 
     796                                else if ($config['load_anon_lastread'] || $userdata['session_logged_in']) 
    797797                                {*/ 
    798798                                        $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], ($forum_id) ? false : $forum['topic_list']); 
    799799 
    800                                         //if (!$user->data['is_registered']) 
    801                                         //
    802                                                 $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince']) : 0; 
    803                                         //
     800                                        if (!$userdata['session_logged_in']) 
     801                                       
     802                                                $userdata['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince']) : 0; 
     803                                       
    804804                                //} 
    805805                        } 
  • phpBB2/viewforum.php

    r295 r299  
    208208 
    209209        $sql = "SELECT COUNT(t.topic_id) AS forum_topics 
    210                 FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p 
     210                FROM " . TOPICS_TABLE . " t 
    211211                WHERE t.forum_id = $forum_id 
    212                         AND p.post_id = t.topic_last_post_id 
    213                         AND p.post_time >= $min_topic_time"; 
     212                        AND t.topic_last_post_time >= $min_topic_time"; 
    214213 
    215214        $result = $db->sql_query($sql); 
     
    256255 
    257256$topic_rowset = array(); 
     257$topic_list = array(); 
    258258$total_announcements = 0; 
    259259while( $row = $db->sql_fetchrow($result) ) 
    260260{ 
    261261        $topic_rowset[] = $row; 
     262        $topic_list[] = $row['topic_id']; 
    262263        $total_announcements++; 
    263264} 
     
    283284 
    284285$total_topics = 0; 
    285 $topic_list = array(); 
    286286while( $row = $db->sql_fetchrow($result) ) 
    287287{ 
     
    425425 
    426426$topic_tracking_info = $tracking_topics = array(); 
    427 $forum_row['forum_last_post_time'] = 0; 
    428427 
    429428if( $total_topics ) 
     
    432431        $mark_time_forum = 0; 
    433432 
    434         $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list); 
    435         $userdata['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince']) : 0; 
    436         $mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['onlinesince']) : $userdata['user_lastmark']; 
     433        if ($config['load_db_lastread'] && $userdata['session_logged_in']) 
     434        { 
     435                $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list); 
     436                $mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $userdata['user_lastmark']; 
     437        } 
     438        else if ($config['load_anon_lastread'] || $userdata['session_logged_in']) 
     439        { 
     440                $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list); 
     441 
     442                if (!$userdata['session_logged_in']) 
     443                { 
     444                        $userdata['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince']) : 0; 
     445                } 
     446                $mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['onlinesince']) : $userdata['user_lastmark']; 
     447        } 
    437448 
    438449        for($i = 0; $i < $total_topics; $i++) 
     
    578589                $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2']; 
    579590                $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2']; 
    580  
    581                 $forum_row['forum_last_post_time'] = max($forum_row['forum_last_post_time'], $topic_rowset[$i]['post_time']); 
    582591 
    583592                $template->assign_block_vars('topicrow', array( 
     
    712721        // posts made since user last visited 
    713722        // 
    714         if ( $userdata['session_logged_in'] ) 
    715         { 
    716                 $sql = "SELECT t.forum_id, t.topic_id, p.post_time 
    717                         FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p 
    718                         WHERE p.post_id = t.topic_last_post_id 
    719                                 AND p.post_time > " . $userdata['user_lastvisit'] . " 
     723/*      if ( $userdata['session_logged_in'] ) 
     724        { 
     725                $sql = "SELECT t.forum_id, t.topic_id, t.topic_last_post_time 
     726                        FROM " . TOPICS_TABLE . " t 
     727                        WHERE t.topic_last_post_time > " . $userdata['user_lastvisit'] . " 
    720728                                AND t.topic_moved_id = 0"; 
    721729                $result = $db->sql_query($sql); 
     
    724732                while( $topic_data = $db->sql_fetchrow($result) ) 
    725733                { 
    726                         $new_topic_data[$topic_data['forum_id']][$topic_data['topic_id']] = $topic_data['post_time']; 
     734                        $new_topic_data[$topic_data['forum_id']][$topic_data['topic_id']] = $topic_data['topic_last_post_time']; 
    727735                } 
    728736                $db->sql_freeresult($result); 
    729         } 
     737        }*/ 
     738 
    730739        // 
    731740        // Obtain list of moderators of each forum 
     
    777786                if ( $is_auth_ary[$subforum_id]['auth_view'] ) 
    778787                { 
    779                         $subforum_last_post_time = 0; 
    780  
    781                         while( list($check_topic_id, $check_post_time) = @each($new_topic_data[$subforum_id]) ) 
    782                         { 
    783                                 $subforum_last_post_time = max($check_post_time, $subforum_last_post_time); 
    784                         } 
    785  
    786                         $unread_topics = (isset($topic_tracking_info[$topic_id]) && $subforum_last_post_time > $topic_tracking_info[$topic_id]) ? true : false; 
    787  
    788                         if ( $unread_topics ) { 
    789                                 $mark_forum_read = false; 
    790                         } 
     788                        $subforum_last_post_time = $subforum_data[$j]['forum_last_post_time']; 
     789 
     790                        if ($config['load_db_lastread'] && $userdata['session_logged_in']) 
     791                        { 
     792                                $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $userdata['user_lastmark']; 
     793                        } 
     794                        else if ($config['load_anon_lastread'] || $userdata['session_logged_in']) 
     795                        { 
     796                                if (!$userdata['session_logged_in']) 
     797                                { 
     798                                        $userdata['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince']) : 0; 
     799                                } 
     800                                $forum_tracking_info[$subforum_id] = (isset($tracking_topics['f'][$subforum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['onlinesince']) : $userdata['user_lastmark']; 
     801                        } 
     802 
     803                        $unread_topics = (isset($forum_tracking_info[$subforum_id]) && $subforum_last_post_time > $forum_tracking_info[$subforum_id]) ? true : false; 
     804 
     805                        //if ( $unread_topics ) { 
     806                        //      $mark_forum_read = false; 
     807                        //} 
    791808 
    792809 
  • phpBB2/viewtopic.php

    r295 r299  
    9696                $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id); 
    9797 
    98                 $topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : 0
     98                $topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : $userdata['session_time']
    9999 
    100100                        $sql = "SELECT p.post_id 
     
    153153// page the post is on and the correct display of viewtopic) 
    154154// 
    155 $join_sql_table = (!$post_id) ? '' : ", " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2 "; 
    156 $join_sql = (!$post_id) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= $post_id"; 
    157 $count_sql = (!$post_id) ? '' : ", COUNT(p2.post_id) AS prev_posts"; 
    158  
    159 //$order_sql = (!$post_id) ? '' : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments ORDER BY p.post_id ASC"; 
    160 $order_sql = (!$post_id) ? '' : "ORDER BY p.post_id ASC"; 
    161  
    162 $sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, t.topic_first_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments, pt.post_time AS forum_last_post_time, pt2.post_time AS topic_last_post_time " . $count_sql . " 
    163                 FROM " . TOPICS_TABLE . " t LEFT JOIN " . POSTS_TABLE . " pt2 ON ( t.topic_last_post_id = pt2.post_id ), " . FORUMS_TABLE . " f LEFT JOIN " . POSTS_TABLE . " pt ON ( f.forum_last_post_id = pt.post_id ) " . $join_sql_table . " 
    164                 WHERE $join_sql 
    165                 AND f.forum_id = t.forum_id 
    166                 $order_sql"; 
     155$sql_array['SELECT'] = 't.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, t.topic_last_post_time, t.topic_first_post_id, t.topic_first_post_sticky, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments, f.forum_last_post_time'; 
     156$sql_array['FROM'] = array( 
     157        TOPICS_TABLE    => 't', 
     158        FORUMS_TABLE    => 'f' 
     159); 
     160$sql_array['WHERE'] = "t.topic_id = $topic_id AND f.forum_id = t.forum_id"; 
     161 
     162 
     163if ( $post_id ) { 
     164        $sql_array['SELECT'] .= ', COUNT(p2.post_id) AS prev_posts'; 
     165        $sql_array['FROM'] += array( 
     166                POSTS_TABLE     => 'p', 
     167        ); 
     168 
     169        $sql_array['LEFT_JOIN'] = array( 
     170                array( 
     171                        'FROM' => array(POSTS_TABLE => 'p2'), 
     172                        'ON' => "p2.topic_id = p.topic_id AND p2.post_id <= $post_id" 
     173        )); 
     174        $sql_array['WHERE'] = "p.post_id = $post_id AND t.topic_id = p.topic_id AND f.forum_id = t.forum_id"; 
     175        $sql_array['ORDER_BY'] = 'p.post_id'; 
     176
     177 
     178$sql = $db->sql_build_query('SELECT', $sql_array); 
    167179$result = $db->sql_query($sql); 
    168180 
     
    377389 
    378390        // Get topic tracking info 
    379         if ($config['load_db_lastread'] && $user->data['is_registered']) 
     391        if ($config['load_db_lastread'] && $userdata['session_logged_in']) 
    380392        { 
    381393                $tmp_topic_data = array($topic_id => $topic_data); 
     
    383395                unset($tmp_topic_data); 
    384396        } 
    385         else if ($config['load_anon_lastread'] || $user->data['is_registered']) 
     397        else if ($config['load_anon_lastread'] || $userdata['session_logged_in']) 
    386398        { 
    387399                $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id); 
     
    414426        $limit = $config['posts_per_page']; 
    415427} 
    416 $sql = "SELECT u.name AS username, u.uid, u.user_posts, u.email, u.user_session_time, u.user_lastvisit, p.*,  pt.post_text, pt.post_subject, u.gender, u.birthday, u.warneduntil, u.parked, u.donor, u.added AS user_regdate, u.uploaded, u.downloaded, u.avatar AS user_avatar, u.icq AS user_icq, u.msn, u.aim AS user_aim, u.yahoo AS user_yim, u.skype AS user_skype, u.title AS user_rank, u.privacy, u.class AS user_class, u.enabled, u.user_sig, u.user_reputation_level, u.user_rank_id 
    417         FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u , " . POSTS_TEXT_TABLE . " pt 
    418         WHERE p.topic_id = $topic_id 
    419                 $limit_posts_time 
    420                 AND pt.post_id = p.post_id 
    421                 AND u.uid = p.poster_id 
    422         ORDER BY p.post_time $post_time_order 
    423         LIMIT $start, ". $limit; 
    424 $result = $db->sql_query($sql); 
     428 
     429$sql_array = array(); 
     430$sql_array['SELECT'] = 'u.name AS username, u.uid, u.user_posts, u.email, u.user_session_time, u.user_lastvisit, p.*,  pt.post_text, pt.post_subject, u.gender, u.birthday, u.warneduntil, u.parked, u.donor, u.added AS user_regdate, u.uploaded, u.downloaded, u.avatar AS user_avatar, u.icq AS user_icq, u.msn, u.aim AS user_aim, u.yahoo AS user_yim, u.skype AS user_skype, u.title AS user_rank, u.privacy, u.class AS user_class, u.enabled, u.user_sig, u.user_reputation_level, u.user_rank_id'; 
     431$sql_array['FROM'] = array( 
     432        POSTS_TABLE     => 'p', 
     433        USERS_TABLE     => 'u', 
     434        POSTS_TEXT_TABLE        => 'pt', 
     435); 
     436$sql_array['WHERE'] = "p.topic_id = $topic_id AND pt.post_id = p.post_id AND u.uid = p.poster_id $limit_posts_time"; 
     437$sql_array['ORDER_BY'] = 'p.post_time ' . $post_time_order; 
     438 
     439 
     440$sql = $db->sql_build_query('SELECT', $sql_array); 
     441 
     442//topic sticky or announce, let's do first post sticky and we view not a first page 
     443$sql_array = array(); 
     444if ( $forum_topic_data['topic_first_post_sticky'] && $start ) { 
     445        $sql_array['SELECT'] = 'u.name AS username, u.uid, u.user_posts, u.email, u.user_session_time, u.user_lastvisit, p.*,  pt.post_text, pt.post_subject, u.gender, u.birthday, u.warneduntil, u.parked, u.donor, u.added AS user_regdate, u.uploaded, u.downloaded, u.avatar AS user_avatar, u.icq AS user_icq, u.msn, u.aim AS user_aim, u.yahoo AS user_yim, u.skype AS user_skype, u.title AS user_rank, u.privacy, u.class AS user_class, u.enabled, u.user_sig, u.user_reputation_level, u.user_rank_id'; 
     446        $sql_array['FROM'] = array( 
     447                POSTS_TABLE     => 'p', 
     448                USERS_TABLE     => 'u', 
     449                POSTS_TEXT_TABLE        => 'pt', 
     450        ); 
     451        $sql_array['WHERE'] = "p.post_id = " . $forum_topic_data['topic_first_post_id'] . " AND pt.post_id = p.post_id AND u.uid = p.poster_id"; 
     452 
     453        //$limit -= 1; 
     454
     455 
     456$result = $db->sql_query_limit($sql, $limit, $start); 
    425457 
    426458$postrow = array(); 
     
    436468        while ($row = $db->sql_fetchrow($result)); 
    437469        $db->sql_freeresult($result); 
     470 
     471        if ( sizeof($sql_array) ) { 
     472                $sql = $db->sql_build_query('SELECT', $sql_array); 
     473                $result = $db->sql_query($sql); 
     474                $first_post_data = array($db->sql_fetchrow($result)); 
     475                $postrow = array_merge($first_post_data, $postrow); 
     476        } 
    438477 
    439478        if ( sizeof($posts_ary) ) { 
     
    450489        } 
    451490 
    452         $total_posts = count($postrow); 
     491        $total_posts = sizeof($postrow); 
    453492} 
    454493else 
     
    13941433if (isset($topic_tracking_info[$topic_id]) && $forum_topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id] && $max_post_time > $topic_tracking_info[$topic_id]) 
    13951434{ 
    1396  
    13971435        markread('topic', $forum_id, $topic_id, $max_post_time); 
    13981436 
  • sql.sql

    r293 r299  
    417417('tags_max_allow', '10', 0), 
    418418('tags_max_length', '50', 0), 
    419 ('tags_min_length', '3', 0); 
     419('tags_min_length', '3', 0), 
     420('load_db_lastread', '0', 0), 
     421('load_anon_lastread', '1', 0), 
     422('load_db_track', '0', 0); 
    420423 
    421424-- -------------------------------------------------------- 
     
    680683  `auth_attachments` tinyint(2) default '0', 
    681684  `forum_parent` int(11) default '0', 
     685  `forum_last_post_time` int(11) default '0', 
    682686  PRIMARY KEY  (`forum_id`), 
    683687  KEY `forums_order` (`forum_order`), 
     
    880884  `topic_type` tinyint(3) default '0', 
    881885  `topic_first_post_id` mediumint(8) unsigned default '0', 
     886  `topic_first_post_sticky` tinyint(1) default '0', 
    882887  `topic_last_post_id` mediumint(8) unsigned default '0', 
    883888  `topic_moved_id` mediumint(8) unsigned default '0', 
     889  `topic_last_post_time` int(11) default '0', 
    884890  PRIMARY KEY  (`topic_id`), 
    885891  KEY `forum_id` (`forum_id`), 
     
    11701176  `completed` int(11) default '0', 
    11711177  `active` tinyint(4) default '0', 
    1172   KEY `userid` (`uid`), 
    1173   KEY `fid_2` (`fid`), 
     1178  UNIQUE KEY `fid_uid` (`fid`,`uid`), 
    11741179  KEY `peer_id` (`peer_id`(20)) 
    11751180) ENGINE=MyISAM DEFAULT CHARSET=utf8; 
     
    16161621  `torrentid` int(10) default '0', 
    16171622  `userid` int(10) default '0', 
    1618   `port` smallint(5) unsigned default '0', 
    16191623  `uploaded` bigint(20) unsigned default '0', 
    16201624  `downloaded` bigint(20) unsigned default '0', 
    16211625  `last_action` int(11) default '0', 
    16221626  `completedat` int(11) default '0', 
    1623   UNIQUE KEY `torrentid` (`torrentid`,`userid`), 
     1627  UNIQUE KEY `fid_uid` (`torrentid`,`userid`), 
    16241628  KEY `userid` (`userid`), 
    1625   KEY `torrentid_2` (`torrentid`) 
     1629  KEY `torrentid` (`torrentid`) 
    16261630) ENGINE=MyISAM DEFAULT CHARSET=utf8; 
    16271631 
     
    19011905  `user_unread_pms` int(10) default '0', 
    19021906  `user_rank_id` int(10) default '0', 
     1907  `user_lastmark` int(11) default '0', 
    19031908  PRIMARY KEY  (`uid`), 
    19041909  UNIQUE KEY `torrent_pass` (`torrent_pass`), 
  • templates/bithdtv/bbcode.html

    r269 r299  
    2020 
    2121<!-- BEGIN spoiler_close --> 
    22 </div> 
     22 
     23<span style="display:block;text-align:right;"><a href="javascript:;" onclick="$(this).parents('div:first').toggle('slow');">{L_CLOSE}</a></span></div> 
     24 
    2325<!-- END spoiler_close --> 
    2426 
  • templates/main/bbcode.html

    r269 r299  
    1212 
    1313<!-- BEGIN spoiler_header_open --> 
    14 <div class="quotetitle"><a href="javascript:;" onclick="$(this).parents('div:first').next('div').toggle('slow');">{TEXT}:</a></div><div class="quotecontent" style="display:none;"> 
     14 
     15<div class="quotetitle"> 
     16        <a href="javascript:;" onclick="$(this).parents('div:first').next('div').toggle('slow');">{TEXT}:</a> 
     17</div> 
     18 
     19<div class="quotecontent" style="display:none;"> 
     20 
    1521<!-- END spoiler_header_open --> 
    1622 
    1723<!-- BEGIN spoiler_open --> 
    18 <div class="quotetitle"><a href="javascript:;" onclick="$(this).parents('div:first').next('div').toggle('slow');">{L_SPOILER}:</a></div><div class="quotecontent" style="display:none"> 
     24 
     25<div class="quotetitle"> 
     26        <a href="javascript:;" onclick="$(this).parents('div:first').next('div').toggle('slow');">{L_SPOILER}:</a> 
     27</div> 
     28 
     29<div class="quotecontent" style="display:none"> 
    1930<!-- END spoiler_open --> 
    2031 
    2132<!-- BEGIN spoiler_close --> 
    22 </div> 
     33 
     34<span style="display:block;text-align:right;"><a href="javascript:;" onclick="$(this).parents('div:first').toggle('slow');">{L_CLOSE}</a></span></div> 
     35 
    2336<!-- END spoiler_close --> 
    2437 
     
    6679</table> 
    6780<!-- END mod_close --> 
    68  
    69 <!-- BEGIN flash --> 
    70         <object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="{WIDTH}" height="{HEIGHT}"> 
    71                 <param name="movie" value="{URL}" /> 
    72                 <param name="play" value="true" /> 
    73                 <param name="loop" value="true" /> 
    74                 <param name="quality" value="high" /> 
    75                 <param name="allowScriptAccess" value="never" /> 
    76                 <embed src="{URL}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="{WIDTH}" height="{HEIGHT}" play="true" loop="true" quality="high" allowscriptaccess="never"></embed> 
    77         </object> 
    78 <!-- END flash --> 
  • templates/reflection/bbcode.html

    r269 r299  
    2020 
    2121<!-- BEGIN spoiler_close --> 
    22 </div> 
     22 
     23<span style="display:block;text-align:right;"><a href="javascript:;" onclick="$(this).parents('div:first').toggle('slow');">{L_CLOSE}</a></span></div> 
     24 
    2325<!-- END spoiler_close --> 
    2426 
  • topten.php

    r280 r299  
    22$root_path = './'; 
    33require ($root_path . 'include/config.php'); 
     4require ($root_path . 'include/functions_torrenttable.php'); 
    45 
    56$userdata = session_pagestart($user_ip); 
     
    78loggedinorreturn(); 
    89 
    9 $type = ( isset($_GET['type']) ? intval($_GET['type']) : 1 ); 
    10 $limit = ( isset($_GET['lim']) ? intval($_GET['lim']) : 10 ); 
    11 $subtype = ( isset($_GET['subtype']) ? strval($_GET['subtype']) : '' ); 
    12 if (!in_array($type,array(1,2,3,4,5))) { 
    13         $type = 1; 
    14 
    15  
    16 /*function respects_table($res, $frame_caption) { 
    17         global $template, $db; 
    18  
    19         $template->assign_block_vars('respects_top', array( 
    20                 'U_TOP100_RESPECTS' => append_sid('topten.php?type=1&amp;lim=100&amp;subtype=respects'), 
    21                 'U_TOP250_RESPECTS' => append_sid('topten.php?type=1&amp;lim=250&amp;subtype=respects'), 
    22                 'FRAME_CAPTION' => $frame_caption) 
    23         ); 
    24         $i = 0; 
    25         while ( $row = $db->sql_fetchrow($res) ) { 
    26                 ++$i; 
    27                 $ratio = get_ratio ($row['uploaded'], $row['downloaded']); 
    28                 $ratio = '<span style="color: ' . get_ratio_color($ratio)  . ';">' . $ratio . '</span>'; 
    29                 $username = get_user_class_color($row['class'], $row['username']); 
    30                 $template->assign_block_vars('respects_top.respects_row', array( 
    31                         'U_USERDETAILS' => append_sid('userdetails.php?id=' . $row['uid']), 
    32                         'NUM' => $i, 
    33                         'USER_ID' => $row['uid'], 
    34                         'USERNAME' => $username, 
    35                         'USER_ICONS' => get_user_icons($row), 
    36                         'SIMPATY' => $row['simpaty'], 
    37                         'RATIO' => $ratio, 
    38                         'UPLOADED' => mksize($row['uploaded']), 
    39                         'DOWNLOADED' => mksize($row['downloaded']), 
    40                         'ADDED' => get_elapsed_time($row['added']) ) 
    41                 ); 
    42         } 
    43 }*/ 
    44  
    45 function usertable($res, $frame_caption, $subtype, $total_seed = 0) { 
    46         global $template, $lang, $db, $userdata; 
    47  
    48         $template->assign_block_vars('users_top', array( 
    49                 'U_TOP100_USERS' => append_sid('topten.php?type=1&amp;lim=100&amp;subtype=' . $subtype), 
    50                 'U_TOP250_USERS' => append_sid('topten.php?type=1&amp;lim=250&amp;subtype=' . $subtype), 
    51                 'TOTAL_SEED' => $total_seed, 
    52                 'FRAME_CAPTION' => $frame_caption, 
    53                 'SUBTYPE' => $subtype) 
    54         ); 
    55         $i = 0; 
    56         while ( $row = $db->sql_fetchrow($res) ) { 
    57                 if ( $row['privacy'] == PRIVACY_LEVEL_HIGH && $userdata['class'] < UC_MODERATOR && $userdata['uid'] <> $row['userid'] ) { 
    58                         continue; 
    59                 } 
    60                 if ( ( $row['class'] == UC_VIP || $row['privacy'] <> PRIVACY_LEVEL_LOW ) && ( $userdata['class'] < UC_MODERATOR && $userdata['uid'] != $row['userid'] ) ) { 
    61                         $ratio = '---'; 
    62                         $uploaded = '---'; 
    63                         $downloaded = '---'; 
    64                         $upspeed = '---'; 
    65                         $downspeed = '---'; 
    66                         $total_seed_time = '---'; 
    67                 } 
    68                 else { 
    69                         $ratio = get_ratio ($row['uploaded'], $row['downloaded']); 
    70                         $ratio = '<span style="color: ' . get_ratio_color($ratio)  . ';">' . $ratio . '</span>'; 
    71                         $uploaded = mksize($row['uploaded']); 
    72                         $downloaded = mksize($row['downloaded']); 
    73                         $upspeed = mksize($row['upspeed']) . '/' . $lang['secs_short']; 
    74                         $downspeed = mksize($row['downspeed']) . '/' . $lang['secs_short']; 
    75                         $total_seed_time = mkprettytime($row['total_seed_time']); 
    76                 } 
    77                 ++$i; 
    78                 $row['username'] = get_user_class_color($row['class'], $row['username']); 
    79                 $template->assign_block_vars('users_top.users_row', array( 
    80                         'U_USERDEATILS' => append_sid('userdetails.php?id=' . $row['userid']), 
    81                         'RATIO' => $ratio, 
    82                         'USERNAME' => $row['username'], 
    83                         'USER_ICONS' => get_user_icons($row), 
    84                         'NUM' => $i, 
    85                         'USERID' => $row['userid'], 
    86                         'UPLOADED' => $uploaded, 
    87                         'UP_SPEED' => $upspeed, 
    88                         'DOWNLOADED' => $downloaded, 
    89                         'DOWN_SPEED' => $downspeed, 
    90                         'TOTAL_SEED_TIME' => $total_seed_time, 
    91                         'ADDED' => get_elapsed_time($row['added']) 
    92                         ) 
    93                 ); 
    94         } 
    95  
    96  
    97 
    98  
    99 function torrents_top($res, $frame_caption, $subtype) { 
    100         global $template, $db, $root_path; 
    101         global $seo; 
    102  
    103         $template->assign_block_vars('torrents_top', array( 
    104                 'U_TOP25_TORRENTS' => append_sid('topten.php?type=2&amp;lim=25&amp;subtype=' . $subtype), 
    105                 'U_TOP50_TORRENTS' => append_sid('topten.php?type=2&amp;lim=50&amp;subtype=' . $subtype), 
    106                 'FRAME_CAPTION' => $frame_caption) 
    107         ); 
    108         $i = 0; 
    109         while ( $row = $db->sql_fetchrow($res) ) { 
    110                 ++$i; 
    111                 $ratio = get_ratio($row['seeders'], $row['leechers']); 
    112                 $ratio = '<span style="color: ' . get_ratio_color($ratio)  . ';">' . $ratio . '</span>'; 
     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', 365); 
     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(); 
     27 
     28if ( !isset($sort_ary[$sort]) ) { 
     29        $sort = 'desc'; 
     30
     31 
     32$top_ten_types = array( 
     33        '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 
     53foreach ( $top_ten_types AS $type => $types_ary ) { 
     54 
     55        $template->assign_block_vars('topten_row', array( 
     56                'TITLE' => $lang['top_ten_' . $type], 
     57        )); 
     58 
     59        foreach ( $types_ary AS $subtype => $_null ) { 
     60                $template->assign_block_vars('topten_row.subtypes_row', array( 
     61                        'SELECTED' => $subtype == $do, 
     62                        'TITLE' => $lang['top_ten_' . $subtype], 
     63                        'U_TYPE' => append_sid($root_path . 'topten.php?action=' . $type . '&amp;do=' . $subtype . '&amp;limit=' . $limit . '&amp;range=' . $range), 
     64                )); 
     65        } 
     66
     67 
     68$wherecatina = array(); 
     69$cats_sql = ''; 
     70if ( strpos($userdata['notifs'], '[cat') !== false && !$view ) { 
     71        foreach ( $cats AS $cat_id => $cat_ary ) { 
     72                if ( strpos($userdata['notifs'], '[cat' . $cat_id . ']') !== false ) { 
     73                        $wherecatina[] = $cat_id; 
     74          } 
     75     } 
     76
     77if ( sizeof($wherecatina) && sizeof($wherecatina) != sizeof($cats) ) { 
     78        $new_wherecatina = array(); 
     79        foreach ( $wherecatina AS $_null => $_val ) { 
     80                if ( isset($cats[$_val]) ) { 
     81                        if ( $cats[$_val]['cat_parent'] ) { 
     82                                $new_wherecatina[] = $_val; 
     83                        } 
     84                        //no cat parent, try to get all child cats 
     85                        else { 
     86                                foreach ( $cats AS $_key => $_ary ) { 
     87                                        if ( $_ary['cat_parent'] == $_val ) { 
     88                                                $new_wherecatina[] = $_key; 
     89                                        } 
     90                                } 
     91                                $new_wherecatina[] = $_val; 
     92                        } 
     93                } 
     94        } 
     95        $wherecatina = $new_wherecatina; 
     96        if ( sizeof($wherecatina) ) { 
     97                $cats_sql = 't.category IN (' . implode(', ', $wherecatina) . ')'; 
     98        } 
     99
     100 
     101switch ( $action ) { 
     102        case 'users': 
     103                $order_field = ( isset($top_ten_types[$action][$do]) ? $top_ten_types[$action][$do] : 'uploaded' ); 
     104 
     105                $sql = 'SELECT * 
     106                                FROM ' . USERS_TABLE . ' 
     107                                WHERE enabled = 1 
     108                                ' . ( $range ? ' AND added > ' . ( time() - $range * 24 * 60 * 60 ) : '' ) . ' 
     109                                AND uploaded > ' . 1 * 1024 * 1024 * 1024 . ' 
     110                                AND downloaded > ' . 1 * 1024 * 1024 * 1024 . ' 
     111                                ORDER BY ' . $order_field . ' ' . $sort; 
     112                $result = $db->sql_query_limit($sql, $limit); 
     113 
     114                while ( $row = $db->sql_fetchrow($result) )  { 
     115                        $ratio = get_ratio($row['uploaded'], $row['downloaded']); 
     116 
     117                        // www.phpBB-SEO.com SEO TOOLKIT START 
     118                        $seo->set_user_url($row['name'], $row['uid']); 
     119                        // www.phpBB-SEO.com SEO TOOLKIT END 
     120 
     121                        $template->assign_block_vars('users_table', array( 
     122                                'U_USERDETAILS' => append_sid($root_path . 'userdetails.php?id=' . $row['uid']), 
     123                                'USERNAME' => get_user_class_color ($row['class'], $row['name']), 
     124                                'USER_ICONS' =>  get_user_icons($row), 
     125                                'UPLOADED' => mksize($row['uploaded']), 
     126                                'DOWNLOADED' => mksize($row['downloaded']), 
     127                                'RATIO' => $ratio, 
     128                                'TOTAL_SEED_TIME' => mkprettytime($row['total_seed_time']), 
     129                                'REPUTATION' => $row['user_reputation'], 
     130 
     131                                'HIGHLIGHT' => $userdata['uid'] == $row['uid'], 
     132                        )); 
     133                } 
     134 
     135                $body = 'top_users_body.html'; 
     136        break; 
     137 
     138        case 'peers': 
     139                $order_field = ( isset($top_ten_types[$action][$do]) ? $top_ten_types[$action][$do] : 'uploaded' ); 
     140 
     141                $sql = 'SELECT p.upspeed, p.downspeed, u.uid, u.name, t.name AS torrent_name, p.fid, t.category, u.class 
     142                                FROM ' . PEERS_TABLE . ' p, ' . USERS_TABLE . ' u, ' . TORRENTS_TABLE . ' t 
     143                                WHERE p.uid = u.uid 
     144                                AND p.fid = t.fid 
     145                                AND u.enabled = 1 
     146                                ' . ( $range ? ' AND started > ' . ( time() - $range * 24 * 60 * 60 ) : '' ) . ' 
     147                                ORDER BY ' . $order_field . ' ' . $sort; 
     148                $result = $db->sql_query_limit($sql, $limit); 
     149 
     150                while ( $row = $db->sql_fetchrow($result) )  { 
     151                        $cat_id = $row['category']; 
     152                        $cat_parent_id = ( isset($cats[$cats[$cat_id]['cat_parent']]['cat_id']) ? $cats[$cats[$cat_id]['cat_parent']]['cat_id'] : 0 ); 
     153 
     154                        $id = $row['fid']; 
     155                        $dispname = $row['torrent_name']; 
     156                        $dispname = censor_text($dispname); 
    113157 
    114158                        // www.phpBB-SEO.com SEO TOOLKIT BEGIN 
    115                         if ( empty($seo->seo_url['details'][$row['fid']]) ) { 
    116                                 $seo->seo_url['details'][$row['fid']] = $seo->set_url(censor_text($row['name']), $row['fid'], $seo->seo_static['details']); 
    117                         } 
     159                        if ( $cat_parent_id ) { 
     160                                $seo->set_url($cats[$cat_parent_id]['cat_name'], $cat_parent_id, $seo->seo_static['browse']); 
     161                                $seo->set_parent($cat_id, $seo->seo_static['browse'], $cat_parent_id, $seo->seo_static['browse']); 
     162                        } 
     163 
     164                        $seo->set_url($cats[$cat_id]['cat_name'], $cat_id, $seo->seo_static['browse']); 
     165 
     166                        $seo->set_parent($id, $seo->seo_static['details'], $cat_id, $seo->seo_static['browse']); 
     167 
     168                        $seo->set_url($dispname, $id, $seo->seo_static['details']); 
    118169                        // www.phpBB-SEO.com SEO TOOLKIT END 
    119170 
    120                 $template->assign_block_vars('torrents_top.torrents_row', array( 
    121                         'U_DETAILS' => append_sid($root_path . 'details.php?id=' . $row['fid']), 
    122                         'NUM' => $i, 
    123                         'TORRENT_ID' => $row['fid'], 
    124                         'TORRENT_NAME' => split_string($row['name'], 40), 
    125                         'TORRENT_FULL_NAME' => $row['name'], 
    126                         'TIMES_COMPLETED' => $row['completed'], 
    127                         'DATA' => mksize($row['data']), 
    128                         'SEEDERS' => $row['seeders'], 
    129                         'LEECHERS' => $row['leechers'], 
    130                         'PEERS' => ($row['leechers'] + $row['seeders']), 
    131                         'RATIO' => $ratio 
    132                         ) 
    133                 ); 
    134         } 
    135  
    136  
    137 
    138  
    139 function countriestable($res, $frame_caption, $what, $subtype) { 
    140         global $template, $lang, $db; 
    141  
    142         if ($what == 1) { 
    143                 $type = $lang['users']; 
    144         } 
    145         elseif ($what == 2) { 
    146                 $type = $lang['total_uploaded']; 
    147         } 
    148         elseif ($what == 3) { 
    149                 $type = $lang['average']; 
    150         } 
    151         else { 
    152                 $type = $lang['ratio']; 
    153         } 
    154  
    155         $template->assign_block_vars('countries_top', array( 
    156                 'U_TOP25_COUNTRIES' => append_sid('topten.php?type=3&amp;lim=25&amp;subtype=' . $subtype), 
    157                 'FRAME_CAPTION' => $frame_caption, 
    158                 'TYPE' => $type) 
    159         ); 
    160         $i = 0; 
    161         while ( $row = $db->sql_fetchrow($res) ) { 
    162                 ++$i; 
    163                 if ($what == 1) { 
    164                         $value = number_format($row['num']); 
    165                 } 
    166                 elseif ($what == 2) { 
    167                         $value = mksize($row['ul']); 
    168                 } 
    169                 elseif ($what == 3) { 
    170                         $value = mksize($row['ul_avg']); 
    171                 } 
    172                 else { 
    173                         $value = number_format($row['r'],2); 
    174                 } 
    175                 $template->assign_block_vars('countries_top.countries_row', array( 
    176                         'NUM' => $i, 
    177                         'FLAG_PIC' => $row['flagpic'], 
    178                         'COUNTRY_NAME' => $row['name'], 
    179                         'VALUE' => $value 
    180                         ) 
    181                 ); 
    182         } 
    183  
    184  
    185 
    186  
    187 function peerstable($res, $frame_caption, $subtype) { 
    188         global $template, $lang, $db, $userdata; 
    189         $template->assign_block_vars('peers_top', array( 
    190                 'U_TOP100_PEERS' => append_sid('topten.php?type=4&amp;lim=100&amp;subtype=' . $subtype), 
    191                 'U_TOP250_PEERS' => append_sid('topten.php?type=4&amp;lim=250&amp;subtype=' . $subtype), 
    192                 'FRAME_CAPTION' => $frame_caption) 
    193         ); 
    194         $i = 0; 
    195         while ( $row = $db->sql_fetchrow($res) ) { 
    196                 if ( $row['privacy'] == PRIVACY_LEVEL_HIGH && $userdata['class'] < UC_MODERATOR && $userdata['uid'] <> $row['uid'] ) { 
    197                         continue; 
    198                 } 
    199                 if ( ( $row['class'] == UC_VIP || $row['privacy'] <> PRIVACY_LEVEL_LOW ) && ( $userdata['class'] < UC_MODERATOR && $userdata['uid'] != $row['uid'] ) ) { 
    200                         $upspeed = '---'; 
    201                         $downspeed = '---'; 
    202                 } 
    203                 else { 
    204                         $upspeed = mksize($row['upspeed']) . '/' . $lang['secs_short']; 
    205                         $downspeed = mksize($row['downspeed']) . '/' . $lang['secs_short']; 
    206                 } 
    207                 ++$i; 
    208                         $row['name'] = get_user_class_color($row['class'], $row['name']); 
    209                 $template->assign_block_vars('peers_top.peers_row', array( 
    210                         'U_USERDETAILS' => append_sid('userdetails.php?id=' . $row['uid']), 
    211                         'NUM' => $i, 
    212                         'USER_ID' => $row['uid'], 
    213                         'USERNAME' => $row['name'], 
    214                         'USER_ICONS' =>  get_user_icons($row), 
    215                         'UPRATE' => $upspeed, 
    216                         'DOWNRATE' => $downspeed 
    217                         ) 
    218                 ); 
    219         } 
    220  
    221  
    222  
    223 
    224  
    225 function bt_clients($res, $frame_caption, $limit) { 
    226         global $template, $db; 
    227         $template->assign_block_vars('clients_top', array( 
    228                 'U_TOP25_CLIENTS' => append_sid('topten.php?type=5&amp;lim=25'), 
    229                 'U_TOP50_CLIENTS' => append_sid('topten.php?type=5&amp;lim=50'), 
    230                 'FRAME_CAPTION' => $frame_caption) 
    231         ); 
    232  
    233         $agents = array(); 
    234         $sum = 0; 
    235         while ( $row = $db->sql_fetchrow($res) ) { 
    236                 $client = getagent($row['useragent'], $row['peer_id']); 
    237                 if (array_key_exists($client, $agents) ) { 
    238                         $agents[$client]++; 
    239                 } 
    240                 else { 
    241                         $agents[$client] = 0; 
    242                 } 
    243                 $sum++; 
     171                        // www.phpBB-SEO.com SEO TOOLKIT START 
     172                        $seo->set_user_url($row['name'], $row['uid']); 
     173                        // www.phpBB-SEO.com SEO TOOLKIT END 
     174 
     175                        $template->assign_block_vars('peers_table', array( 
     176                                'U_USERDETAILS' => append_sid($root_path . 'userdetails.php?id=' . $row['uid']), 
     177                                'USERNAME' => get_user_class_color ($row['class'], $row['name']), 
     178                                'UPSPEED' => mksize($row['upspeed']), 
     179                                'DOWNSPEED' => mksize($row['downspeed']), 
     180                                'U_DETAILS'  => append_sid($root_path . 'details.php?id=' . $id), 
     181                                'DISPNAME' => $dispname, 
     182 
     183                                'HIGHLIGHT' => $userdata['uid'] == $row['uid'], 
     184 
     185                        )); 
     186                } 
     187 
     188                $body = 'top_peers_body.html'; 
     189        break; 
     190 
     191        default: 
     192        case 'popular_torrents': 
     193 
     194                $order_field = ( isset($top_ten_types[$action][$do]) ? $top_ten_types[$action][$do] : 'completed' ); 
     195 
     196                $sql = 'SELECT * 
     197                                FROM ' . TORRENTS_TABLE . ' t 
     198                                WHERE banned = 0 AND hidden = 0 AND moderated = 1 
     199                                ' . ( $cats_sql ? ' AND ' . $cats_sql : '' ) . 
     200                                ( $range ? ' AND ctime > ' . ( time() - $range * 24 * 60 * 60 ) : '' ) . ' 
     201                                ORDER BY ' . $order_field . ' ' . $sort; 
     202                $result = $db->sql_query_limit($sql, $limit); 
     203 
     204                while ( $row = $db->sql_fetchrow($result) )  { 
     205 
     206                        $cat_id = $row['category']; 
     207                        $cat_parent_id = ( isset($cats[$cats[$cat_id]['cat_parent']]['cat_id']) ? $cats[$cats[$cat_id]['cat_parent']]['cat_id'] : 0 ); 
     208 
     209                        $id = $row['fid']; 
     210                        $dispname = $row['name']; 
     211                        $dispname = censor_text($dispname); 
     212 
     213                        // www.phpBB-SEO.com SEO TOOLKIT BEGIN 
     214                        if ( $cat_parent_id ) { 
     215                                $seo->set_url($cats[$cat_parent_id]['cat_name'], $cat_parent_id, $seo->seo_static['browse']); 
     216                                $seo->set_parent($cat_id, $seo->seo_static['browse'], $cat_parent_id, $seo->seo_static['browse']); 
     217                        } 
     218 
     219                        $seo->set_url($cats[$cat_id]['cat_name'], $cat_id, $seo->seo_static['browse']); 
     220 
     221                        $seo->set_parent($id, $seo->seo_static['details'], $cat_id, $seo->seo_static['browse']); 
     222 
     223                        $seo->set_url($dispname, $id, $seo->seo_static['details']); 
     224                        // www.phpBB-SEO.com SEO TOOLKIT END 
     225 
     226                        if ( $row['seeders'] ) { 
     227                                $ratio = ( $row['leechers'] ? $row['seeders'] / $row['leechers'] : 1 ); 
     228                                $slr_color = get_slr_color($ratio); 
     229                        } 
     230                        else { 
     231                                $slr_color = 'FF0000'; 
     232                        } 
     233 
     234                        $cat_name_display = ''; 
     235                        if ( $cat_parent_id ) { 
     236                                $cat_name_display .= '<a href="' . append_sid($root_path . 'browse.php?cat=' . $cat_parent_id) . '">' . $cats[$cats[$cat_id]['cat_parent']]['cat_name'] . '</a> -> '; 
     237                        } 
     238                        $cat_name_display .= '<a href="' . append_sid($root_path . 'browse.php?cat=' . $cat_id) . '">' . $cats[$cat_id]['cat_name'] . '</a>'; 
     239 
     240                        $template->assign_block_vars('torrents_table', array( 
     241                                'U_CATEGORY' => append_sid($root_path . 'browse.php?cat=' . $cat_id), 
     242                                'U_DETAILS'  => append_sid($root_path . 'details.php?id=' . $id), 
     243                                'U_DOWNLOAD' => append_sid($root_path . 'details.php?id=' . $id . '&amp;action=download'), 
     244                                'U_ADD_BOOKMARK' => append_sid($root_path . 'bookmarks.php?torrent=' . $id), 
     245                                'U_SNATCHED' => append_sid($root_path . 'details.php?id=' . $id . '&amp;view=snatchedlist#snatched'), 
     246                                'U_PEERLIST' => append_sid($root_path . 'details.php?id=' . $id . '&amp;view=peerlist'), 
     247                                'DISPNAME' => $dispname, 
     248                                'TORRENT_FREE_ICON' => get_free_icon($row['free']), 
     249                                'TORRENT_COMPLETED' => $row['completed'], 
     250                                'TORRENT_SEEDERS' => $row['seeders'], 
     251                                'TORRENT_LEECHERS' => $row['leechers'], 
     252                                'SLR_COLOR' => $slr_color, 
     253                                'ADDED' => create_date($row['ctime']), 
     254                                'CAT_PIC' => $cats[$cat_id]['cat_pic'], 
     255                                'CAT_NAME' => $cats[$cat_id]['cat_name'], 
     256                                'CAT_NAME_DISPLAY' => $cat_name_display, 
     257                                'SIZE' => mksize($row['size']), 
     258 
     259                                'HIGHLIGHT' => $userdata['uid'] == $row['owner'], 
     260 
     261                                'ID' => $row['fid'], 
     262                        )); 
     263                } 
     264 
     265                $body = 'top_torrents_body.html'; 
     266        break; 
     267
     268 
     269$limit_options = '<select name="limit">'; 
     270foreach ( $limit_ary AS $null => $_limit ) { 
     271        $limit_options .= '<option value="' . $_limit . '"' . ( $_limit == $limit ? ' selected="selected"' : '' ) . '>' . $_limit . '</option>'; 
     272
     273$limit_options .= '</select>'; 
     274 
     275$range_options = '<select name="range">'; 
     276foreach ( $range_ary AS $null => $_range ) { 
     277        $range_options .= '<option value="' . $_range . '"' . ( $_range == $range ? ' selected="selected"' : '' ) . '>' . $_range . '</option>'; 
     278
     279$range_options .= '</select>'; 
     280 
     281$sort_options = '<select name="sort">'; 
     282foreach ( $sort_ary AS $null => $_sort ) { 
     283        $sort_options .= '<option value="' . $null . '"' . ( $null == $sort ? ' selected="selected"' : '' ) . '>' . $_sort . '</option>'; 
     284
     285$sort_options .= '</select>'; 
     286 
     287$view_options = ''; 
     288if ( $action == 'popular_torrents' ) { 
     289        $view_options = '<select name="view">'; 
     290        foreach ( $view_ary AS $null => $_view ) { 
     291                $view_options .= '<option value="' . $null . '"' . ( $null == $view ? ' selected="selected"' : '' ) . '>' . $_view . '</option>'; 
    244292        } 
    245         arsort ($agents); 
    246         reset ($agents); 
    247         $limit = ( $limit > $sum ? $sum : $limit ); 
    248         $i = 0; 
    249         while (list ($key, $val) = each ($agents)) { 
    250                 ++$i; 
    251                 $template->assign_block_vars('clients_top.clients_row', array( 
    252                         'NUM' => $i, 
    253                         'CLIENT' => $key, 
    254                         'VALUE' => number_format($val), 
    255                         'PERCENT' => sprintf( '%.2f%%', 100 * ( $val / $sum ) ) 
    256                         ) 
    257                 ); 
    258                 if ($i == $limit) { 
    259                         break; 
    260                 } 
    261         } 
    262 
    263  
    264 $pu = $userdata['class'] >= UC_POWER_USER; 
    265  
    266 if (!$pu) { 
    267         $limit = 10; 
    268 
    269  
    270 if ($type == 1) { 
    271         $mainquery = 'SELECT uid AS userid, name AS username, added, uploaded, downloaded, total_seed_time, uploaded / (UNIX_TIMESTAMP(NOW()) - added) AS upspeed, downloaded / (UNIX_TIMESTAMP(NOW()) - added) AS downspeed, donor, warneduntil, parked, class, enabled, privacy 
    272                       FROM ' . USERS_TABLE . ' 
    273                       WHERE enabled = 1 AND uid <> ' . ANONYMOUS; 
    274  
    275         if (!$limit || $limit > 250) { 
    276                 $limit = 10; 
    277         } 
    278  
    279         if ($limit == 10 || $subtype == 'ul') { 
    280                 $order = 'uploaded DESC'; 
    281                 $sql = $mainquery . ' ORDER BY ' . $order . ' LIMIT ' . $limit; 
    282                 $result = $db->sql_query($sql, 60 * 60); 
    283                 usertable($result, sprintf($lang['top_uploaded'], $limit), 'ul'); 
    284         } 
    285  
    286         if ($limit == 10 || $subtype == 'dl') { 
    287                 $order = 'downloaded DESC'; 
    288                 $sql = $mainquery . ' ORDER BY ' . $order . ' LIMIT ' . $limit; 
    289                 $result = $db->sql_query($sql, 60 * 60); 
    290                 usertable($result, sprintf($lang['top_downloaded'], $limit), 'dl'); 
    291         } 
    292  
    293         if ($limit == 10 || $subtype == 'uls') { 
    294                 $order = 'upspeed DESC'; 
    295                 $sql = $mainquery . ' ORDER BY ' . $order . ' LIMIT ' . $limit; 
    296                 $result = $db->sql_query($sql, 60 * 60); 
    297                 usertable($result, sprintf($lang['top_seeders'], $limit), 'uls'); 
    298         } 
    299  
    300  
    301         if ($limit == 10 || $subtype == 'dls') { 
    302                 $order = 'downspeed DESC'; 
    303                 $sql = $mainquery . ' ORDER BY ' . $order . ' LIMIT ' . $limit; 
    304                 $result = $db->sql_query($sql, 60 * 60); 
    305                 usertable($result, sprintf($lang['top_leechers'], $limit), 'dls'); 
    306         } 
    307  
    308         if ($limit == 10 || $subtype == 'bsh') { 
    309                 $order = 'uploaded / downloaded DESC'; 
    310                 $extrawhere = ' AND downloaded > 1073741824'; 
    311                 $sql = $mainquery . $extrawhere. ' ORDER BY ' . $order . ' LIMIT ' . $limit; 
    312                 $result = $db->sql_query($sql, 60 * 60); 
    313                 usertable($result, sprintf($lang['top_best_users'], $limit), 'bsh'); 
    314         } 
    315  
    316         if ($limit == 10 || $subtype == 'wsh') { 
    317                 $order = 'uploaded / downloaded ASC, downloaded DESC'; 
    318                 $extrawhere = ' AND downloaded > 0.5*1024*1024*1024'; 
    319                 $sql = $mainquery . $extrawhere. ' ORDER BY ' . $order . ' LIMIT ' . $limit; 
    320                 $result = $db->sql_query($sql, 60 * 60); 
    321                 usertable($result, sprintf($lang['top_worst_users'], $limit), 'wsh'); 
    322         } 
    323  
    324         if ($limit == 10 || $subtype == 'seedtime') { 
    325                 $order = 'total_seed_time DESC'; 
    326                 $sql = $mainquery . ' ORDER BY ' . $order . ' LIMIT ' . $limit; 
    327                 $result = $db->sql_query($sql, 60 * 60); 
    328                 usertable($result, sprintf($lang['top_seedtime'], $limit), 'seedtime', 1); 
    329         } 
    330  
    331         /*if ($limit == 10 || $subtype == 'respects') { 
    332                 $sql = 'SELECT uid, simpaty, name AS username, parked, warneduntil, enabled, donor, class, added, uploaded, downloaded, privacy 
    333                         FROM ' . USERS_TABLE . ' 
    334                         WHERE uid <> ' . ANONYMOUS . ' 
    335                         ORDER BY simpaty DESC 
    336                         LIMIT ' . $limit; 
    337                 $result = $db->sql_query($sql, 60 * 60); 
    338                 respects_table($result, sprintf($lang['top_respects'], $limit)); 
    339         }*/ 
    340 
    341  
    342 elseif ($type == 2) { 
    343         if (!$limit || $limit > 50) { 
    344                 $limit = 10; 
    345         } 
    346  
    347         $mainquery = 'SELECT t.fid, t.name, t.completed, t.seeders, t.leechers, (t.size * t.completed + SUM(p.downloaded)) AS data 
    348                       FROM ' . TORRENTS_TABLE . ' t, ' . PEERS_TABLE . ' p 
    349                       WHERE t.fid = p.fid AND p.left <> 0'; 
    350  
    351           if ($limit == 10 || $subtype == 'act') { 
    352                 $add_query = ' GROUP BY t.fid ORDER BY t.seeders + t.leechers DESC, t.seeders DESC, t.ctime ASC LIMIT ' . $limit; 
    353                 $sql = $mainquery . $add_query; 
    354                 $result = $db->sql_query($sql, 60 * 60); 
    355                 torrents_top($result, sprintf($lang['top_active_torrents'], $limit), 'act'); 
    356           } 
    357  
    358            if ($limit == 10 || $subtype == 'sna') { 
    359                 $add_query = ' GROUP BY t.fid ORDER BY t.completed DESC LIMIT ' . $limit; 
    360                 $sql = $mainquery . $add_query; 
    361                 $result = $db->sql_query($sql, 60 * 60); 
    362                 torrents_top($result, sprintf($lang['top_popular_torrents'], $limit) ,'sna'); 
    363            } 
    364  
    365            if ($limit == 10 || $subtype == 'mdt') { 
    366                 $add_query = ' AND t.leechers >= 5 AND t.completed > 0 GROUP BY t.fid ORDER BY data DESC, ctime ASC LIMIT ' . $limit; 
    367                 $sql = $mainquery . $add_query; 
    368                 $result = $db->sql_query($sql, 60 * 60); 
    369                 torrents_top($result, sprintf($lang['top_traffic_torrents'], $limit), 'mdt'); 
    370            } 
    371  
    372            if ($limit == 10 || $subtype == 'bse') { 
    373                 $add_query = ' AND seeders >= 5 GROUP BY t.fid ORDER BY seeders / leechers DESC, seeders DESC, ctime ASC LIMIT ' . $limit; 
    374                 $sql = $mainquery . $add_query; 
    375                 $result = $db->sql_query($sql, 60 * 60); 
    376                 torrents_top($result, sprintf($lang['top_best_seeding_torrents'], $limit), 'bse'); 
    377            } 
    378  
    379            if ($limit == 10 || $subtype == 'wse') { 
    380                 $add_query = ' AND leechers >= 5 AND t.completed > 0 GROUP BY t.fid ORDER BY seeders / leechers ASC, leechers DESC LIMIT ' . $limit; 
    381                 $sql = $mainquery . $add_query; 
    382                 $result = $db->sql_query($sql, 60 * 60); 
    383                 torrents_top($result, sprintf($lang['top_worst_seeding_torrents'], $limit), 'wse'); 
    384            } 
    385   } 
    386   elseif ($type == 3) { 
    387           if (!$limit || $limit > 25) { 
    388                   $limit = 10; 
    389           } 
    390  
    391           if ($limit == 10 || $subtype == 'us') { 
    392                   $sql = 'SELECT c.name, c.flagpic, COUNT(u.country) as num 
    393                           FROM ' . COUNTRIES_TABLE . ' c, ' . USERS_TABLE . ' u 
    394                           WHERE u.country = c.id 
    395                           GROUP BY c.name 
    396                           ORDER BY num DESC 
    397                           LIMIT ' . $limit; 
    398  
    399                   $result = $db->sql_query($sql, 60 * 60); 
    400                   countriestable($result, sprintf($lang['top_countries'], $limit) . '<span class="small">(' . $lang['top_countries_users'] . ')</span>', 1, 'us'); 
    401           } 
    402  
    403           if ($limit == 10 || $subtype == 'ul') { 
    404                   $sql = 'SELECT c.name, c.flagpic, sum(u.uploaded) AS ul 
    405                           FROM ' . USERS_TABLE . ' u, ' . COUNTRIES_TABLE . ' c 
    406                           WHERE u.country = c.id AND u.enabled = 1 
    407                           GROUP BY c.name 
    408                           ORDER BY ul DESC 
    409                           LIMIT ' . $limit; 
    410  
    411                   $result = $db->sql_query($sql, 60 * 60); 
    412                   countriestable($result, sprintf($lang['top_countries'], $limit) . '<span class="small">(' . $lang['top_countries_total_uploaded'] . ')</span>', 2, 'ul'); 
    413           } 
    414  
    415           if ($limit == 10 || $subtype == 'avg') { 
    416                 $min_uploaded = 100 * 1024 * 1024 * 1024; //100 gb 
    417                 $min_users = 100; 
    418                 $sql = 'SELECT c.name, c.flagpic, SUM(u.uploaded)/COUNT(u.uid) AS ul_avg 
    419                         FROM ' . USERS_TABLE . ' u, ' . COUNTRIES_TABLE . ' c 
    420                         WHERE u.country = c.id AND u.enabled = 1 
    421                         GROUP BY c.name 
    422                         HAVING sum(u.uploaded) > ' . $min_uploaded . ' AND count(*) >= ' . $min_users . ' 
    423                         ORDER BY ul_avg DESC 
    424                         LIMIT ' . $limit; 
    425  
    426  
    427                 $result = $db->sql_query($sql, 60 * 60); 
    428                 countriestable($result, sprintf($lang['top_countries'], $limit) . '<span class="small">(' . sprintf($lang['top_countries_average_uploaded'], mksize($min_uploaded), $min_users) . ')</span>', 3, 'avg'); 
    429           } 
    430  
    431           if ($limit == 10 || $subtype == 'r') { 
    432                 $min_uploaded = 100 * 1024 * 1024 * 1024; //100 gb 
    433                 $min_downloaded = 100 * 1024 * 1024 * 1024; //100 gb 
    434                 $min_users = 100; 
    435                 $sql = 'SELECT c.name, c.flagpic, sum(u.uploaded)/sum(u.downloaded) AS r 
    436                         FROM ' . USERS_TABLE . ' u, ' . COUNTRIES_TABLE . ' c 
    437                         WHERE u.country = c.id AND u.enabled = 1 
    438                         GROUP BY c.name 
    439                         HAVING SUM(u.uploaded) > ' . $min_uploaded . ' AND SUM(u.downloaded) > ' . $min_downloaded . ' AND COUNT(*) >= ' . $min_users . ' 
    440                         ORDER BY r DESC 
    441                         LIMIT ' . $limit; 
    442  
    443                 $result = $db->sql_query($sql, 60 * 60); 
    444                 countriestable($result,  sprintf($lang['top_countries'], $limit) . '<span class="small">(' . sprintf($lang['top_countries_ratio'], mksize($min_uploaded), mksize($min_downloaded), $min_users) . ')</span>', 4, 'r'); 
    445           } 
    446   } 
    447 elseif ($type == 4) { 
    448         if (!$limit || $limit > 250) { 
    449                 $limit = 10; 
    450         } 
    451  
    452         if ($limit == 10 || $subtype == 'pul') { 
    453                 $sql = 'SELECT u.uid, u.name, u.class, u.donor, u.warneduntil, u.parked, u.enabled, u.privacy, p.upspeed, p.downspeed 
    454                         FROM ' . PEERS_TABLE . ' p , ' . USERS_TABLE . ' u 
    455                         WHERE p.uid = u.uid 
    456                         ORDER BY p.upspeed DESC LIMIT ' . $limit; 
    457  
    458                 $result = $db->sql_query($sql, 60 * 60); 
    459                 peerstable($result, sprintf($lang['top_fastest_seeders'], $limit), 'pul'); 
    460         } 
    461  
    462         if ($limit == 10 || $subtype == 'pdl') { 
    463                 $sql = 'SELECT u.uid, u.class, u.donor, u.warneduntil, u.parked, u.enabled, u.name, u.privacy, p.uploaded, p.downloaded, p.upspeed, p.downspeed 
    464                         FROM ' . PEERS_TABLE . ' p, ' . USERS_TABLE . ' u 
    465                         WHERE p.uid = u.uid 
    466                         ORDER BY p.downspeed DESC LIMIT ' . $limit; 
    467  
    468                 $result = $db->sql_query($sql, 60 * 60);; 
    469                 peerstable($result, sprintf($lang['top_fastest_leechers'], $limit), 'pdl'); 
    470         } 
    471 
    472  
    473  
    474 elseif ($type == 5) { 
    475         if (!$limit || $limit > 50) { 
    476                 $limit = 10; 
    477         } 
    478         $sql = 'SELECT peer_id, useragent FROM ' . PEERS_TABLE . ' GROUP BY uid'; 
    479         $result = $db->sql_query($sql, 60 * 60); 
    480         bt_clients($result, sprintf($lang['top_clients'], $limit), $limit); 
    481 
    482  
    483 $template->assign_vars(array ( 
    484         'U_TOP10_USERS' => append_sid('topten.php?type=1'), 
    485         'U_TOP10_TORRENTS' => append_sid('topten.php?type=2'), 
    486         'U_TOP10_COUNTRIES' => append_sid('topten.php?type=3'), 
    487         'U_TOP10_PEERS' => append_sid('topten.php?type=4'), 
    488         'U_TOP10_CLIENTS' => append_sid('topten.php?type=5'), 
    489         'TYPE' => $type, 
    490         'POWER_USER' => $pu, 
    491         'LIMIT' => $limit ) 
    492 ); 
     293        $view_options .= '</select>'; 
     294
     295 
     296 
     297$template->assign_vars(array( 
     298        'LIMIT_OPTIONS' => $limit_options, 
     299        'RANGE_OPTIONS' => $range_options, 
     300        'SORT_OPTIONS' => $sort_options, 
     301        'VIEW_OPTIONS' => $view_options, 
     302 
     303        'S_FORM_ACTION' => append_sid($root_path . 'topten.php'), 
     304        'ACTION' => $action, 
     305        'DO' => $do, 
     306)); 
     307 
     308$template->set_filenames(array( 
     309        'template' => $body 
     310)); 
     311$template->assign_display('template', 'INCLUDE_TEMPLATE', false); 
    493312 
    494313stdhead($lang['top10']); 
    495314$template->set_filenames(array( 
    496         'body' => 'top10.html') 
    497 )
     315        'body' => 'top_ten_body.html' 
     316))
    498317stdfoot(); 
    499318?>