home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / phpbb2plus / phpBB2_plus_1.52.exe / phpBB2 / recent.php < prev    next >
PHP Script  |  2004-07-18  |  21KB  |  391 lines

  1. <?php
  2. // ############ Edit below ############
  3. $length = '25'; // length of topic title
  4. $special_forums = '0'; // 0 = no; 1 = yes
  5. $forums = '1,2,3'; // IDs of forums; separate them with a comma
  6. // ############ Edit above ############
  7.  
  8. define('IN_PHPBB', true);
  9. $phpbb_root_path = './'; // board folder with! ending mark (if in same folder just './')
  10. include($phpbb_root_path . 'extension.inc');
  11. include($phpbb_root_path . 'common.'.$phpEx);
  12.  
  13. $userdata = session_pagestart($user_ip, PAGE_INDEX, $board_config['session_length']);
  14. init_userprefs($userdata);
  15.  
  16. $page_title = $lang['latest_posts'];
  17. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  18.  
  19. $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
  20. $selorder = ( $HTTP_POST_VARS['selorder'] ) ? $HTTP_POST_VARS['selorder'] : $HTTP_GET_VARS['selorder'];
  21. $nodays = ( $HTTP_POST_VARS['nodays'] ) ? $HTTP_POST_VARS['nodays'] : $HTTP_GET_VARS['nodays'];
  22. if (!isset($selorder)) $selorder = "las24";
  23. if (!isset($nodays)) $nodays = 3;
  24.  
  25. $sql = "SELECT post_id FROM " . POSTS_TABLE;
  26. if ( !($result = $db->sql_query($sql)) )
  27. {
  28.     message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
  29. }
  30. $recent_ids = array();
  31. while( $row = $db->sql_fetchrow($result) )
  32. {
  33.     $recent_ids[] = $row['post_id'];
  34. }
  35. $db->sql_freeresult($result);
  36.  
  37. $recent_forum = ( isset($HTTP_POST_VARS['forum']) ) ? intval($HTTP_POST_VARS['forum']) : -1;
  38. if ( $recent_forum == -1 )
  39. {
  40.         $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); 
  41.         $ignore_forum_sql = '';
  42.         while( list($key, $value) = each($is_auth_ary) )
  43.         {
  44.                 if ( !$value['auth_read'] )
  45.                 {
  46.                         $ignore_forum_sql .= ( ( $ignore_forum_sql != '' ) ? ', ' : '' ) . $key;
  47.                 }
  48.         }
  49.         if ( $ignore_forum_sql != '' )
  50.         {
  51.                 $auth_sql .= ( $auth_sql != '' ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) ";
  52.         }
  53. }
  54.                 if ( $recent_author == '' && $auth_sql == '' )
  55.                 {
  56.                         $sql = "SELECT topic_id FROM " . POSTS_TABLE . "
  57.                                 WHERE post_id IN (" . implode(", ", $recent_ids) . ") 
  58.                                 $where_sql GROUP BY topic_id";
  59.                 }
  60.                 else
  61.                 {
  62.                         $from_sql = POSTS_TABLE . " p"; 
  63.                         if ( $auth_sql != '' )
  64.                         {
  65.                                 $from_sql .= ", " . FORUMS_TABLE . " f";
  66.                                 $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
  67.                         }
  68.                         $sql = "SELECT p.topic_id FROM $from_sql 
  69.                                 WHERE p.post_id IN (" . implode(", ", $recent_ids) . ") 
  70.                                 $where_sql GROUP BY p.topic_id";
  71.                 }
  72.                 if ( !($result = $db->sql_query($sql)) )
  73.                 {
  74.                         message_die(GENERAL_ERROR, 'Could not obtain topic ids', '', __LINE__, __FILE__, $sql);
  75.                 }
  76.  
  77.                 $recent_ids = array();
  78.                 while( $row = $db->sql_fetchrow($result) )
  79.                 {
  80.                         $recent_ids[] = $row['topic_id'];
  81.                 }
  82.                 $db->sql_freeresult($result);
  83.  
  84. $auth_results = implode(', ', $recent_ids);
  85. $where_part1 = ( $special_forums == '0' ) ? 't.topic_id IN ('.$auth_results.')' : 'f.forum_id IN ('.$forums.')';
  86.  
  87. $part1 = "SELECT from_unixtime(p.post_time, '%d.%m.%y %H:%i:%s') as topic_time, f.forum_name as forum_name, f.forum_id as forum_id,
  88.                         u.username as username, u2.username as username2, u2.user_id as user_id2, p.poster_id as poster_id, p.post_username as post_username, p.post_id as post_id, t.*, p.post_time as post_time
  89.                FROM ".TOPICS_TABLE." t, ".POSTS_TABLE." p
  90.                         LEFT OUTER JOIN ".FORUMS_TABLE." f on p.forum_id = f.forum_id
  91.                         LEFT OUTER JOIN ".USERS_TABLE." u on p.poster_id = u.user_id
  92.                         LEFT OUTER JOIN ".USERS_TABLE." u2 on u2.user_id = t.topic_poster
  93.                WHERE $where_part1 AND p.post_id = t.topic_last_post_id AND ";
  94. $part2 = " ORDER BY p.post_time desc LIMIT $start, ".$board_config['topics_per_page'];
  95.  
  96. $showdays = 86400 * $nodays;
  97.  
  98. $lastweeksql  = $part1."UNIX_TIMESTAMP(NOW()) - p.post_time < 691200".$part2;
  99. $yesterdaysql = $part1."FROM_UNIXTIME(p.post_time,'%Y%m%d') - FROM_UNIXTIME(unix_timestamp(NOW()),'%Y%m%d') = -1".$part2;
  100. $todaysql     = $part1."FROM_UNIXTIME(p.post_time,'%Y%m%d') - FROM_UNIXTIME(unix_timestamp(NOW()),'%Y%m%d') = 0".$part2;
  101. $last24hsql   = $part1."UNIX_TIMESTAMP(NOW()) - p.post_time < 86400".$part2;
  102. $lastXdsql    = $part1."UNIX_TIMESTAMP(NOW()) - p.post_time < $showdays".$part2;
  103.  
  104. switch ($selorder)
  105. {
  106.  case "las24" : $sql = $last24hsql; $template->assign_vars(array("MSG" => $lang['last_24h'])); break;
  107.  case "today" : $sql = $todaysql; $template->assign_vars(array("MSG" => $lang['today'])); break;
  108.  case "yestr" : $sql = $yesterdaysql; $template->assign_vars(array("MSG" => $lang['yesterday'])); break;
  109.  case "lweek" : $sql = $lastweeksql; $template->assign_vars(array("MSG" => $lang['last_week'])); break;
  110.  case "laday" : $sql = $lastXdsql; $template->assign_vars(array("MSG" => $lang['last_xdays1'].$nodays.$lang['last_xdays2'])); break;
  111. }
  112.  
  113. $style = 0;
  114. if ( !$result = $db->sql_query($sql) )
  115. {
  116.         message_die(GENERAL_ERROR, 'Could not obtain main information', '', __LINE__, __FILE__, $sql);
  117. }
  118. $line = array();
  119. while( $row = $db->sql_fetchrow($result) )
  120. {
  121.         $line[] = $row;
  122. }
  123. $db->sql_freeresult($result);        
  124.         
  125.         $template->set_filenames(array(
  126.                 'body' => 'recent_body.tpl')
  127.         );
  128.  
  129.         $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
  130.         $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
  131.         for($i = 0; $i < count($line); $i++)
  132.         {
  133.                 $forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $line[$i]['forum_id']);
  134.                 $forum_id = $line[$i]['forum_id'];
  135.                 $topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $line[$i]['topic_id']);
  136.                 $topic_id = $line[$i]['topic_id'];
  137.  
  138.                 $orig_word = array();
  139.                 $replacement_word = array();
  140.                 obtain_word_list($orig_word, $replacement_word);
  141.                 $word_censor = ( count($orig_word) ) ? preg_replace($orig_word, $replacement_word, $line[$i]['topic_title']) : $line[$i]['topic_title']; 
  142.                 $topic_title = ( strlen($line[$i]['topic_title']) < $length ) ? $word_censor : substr(stripslashes($word_censor), 0, $length) . "..."; 
  143.  
  144.                 $topic_type = ( $line[$i]['topic_type'] == POST_ANNOUNCE ) ? $lang['Topic_Announcement'] .' ': '';
  145.                 $topic_type .= ( $line[$i]['topic_type'] == POST_GLOBAL_ANNOUNCE ) ? $lang['Topic_global_announcement'] .' ': '';
  146.                 $topic_type .= ( $line[$i]['topic_type'] == POST_STICKY ) ? $lang['Topic_Sticky'] .' ': '';
  147.                 $topic_type .= ( $line[$i]['topic_vote'] ) ? $lang['Topic_Poll'] .' ': '';
  148.  
  149.                 $views = $line[$i]['topic_views'];
  150.                 $replies = $line[$i]['topic_replies'];
  151.                 if ( ( $replies + 1 ) > $board_config['posts_per_page'] )
  152.                 {
  153.                         $total_pages = ceil( ( $replies + 1 ) / $board_config['posts_per_page'] );
  154.                         $goto_page = ' [ ';
  155.                         $times = 1;
  156.                         for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page'])
  157.                         {
  158.                                 $goto_page .= '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $topic_id . "&start=$j") . '" class=genmed>' . $times . '</a>';
  159.                                 if ( $times == 1 && $total_pages > 4 )
  160.                                 {
  161.                                         $goto_page .= ' ... ';
  162.                                         $times = $total_pages - 3;
  163.                                         $j += ( $total_pages - 4 ) * $board_config['posts_per_page'];
  164.                                 }
  165.                                 else if ( $times < $total_pages )
  166.                                 {
  167.                                         $goto_page .= ', ';
  168.                                 }
  169.                                 $times++;
  170.                         }
  171.                         $goto_page .= ' ] ';
  172.                 }
  173.                 else
  174.                 {
  175.                         $goto_page = '';
  176.                 }
  177.  
  178.                 if ( $line[$i]['topic_status'] == TOPIC_LOCKED )
  179.                 {
  180.                         $folder = $images['folder_locked'];
  181.                         $folder_new = $images['folder_locked_new'];
  182.                 }
  183.                 else if ( $line[$i]['topic_type'] == POST_ANNOUNCE )
  184.                 {
  185.                         $folder = $images['folder_announce'];
  186.                         $folder_new = $images['folder_announce_new'];
  187.                 }
  188.                 else if ( $line[$i]['topic_type'] == POST_GLOBAL_ANNOUNCE )
  189.                 {
  190.                         $folder = $images['folder_global_announce'];
  191.                         $folder_new = $images['folder_global_announce_new'];
  192.                 }
  193.                 else if ( $line[$i]['topic_type'] == POST_STICKY )
  194.                 {
  195.                         $folder = $images['folder_sticky'];
  196.                         $folder_new = $images['folder_sticky_new'];
  197.                 }
  198.                 else
  199.                 {
  200.                         if ( $replies >= $board_config['hot_threshold'] )
  201.                         {
  202.                                 $folder = $images['folder_hot'];
  203.                                 $folder_new = $images['folder_hot_new'];
  204.                         }
  205.                         else
  206.                         {
  207.                                 $folder = $images['folder'];
  208.                                 $folder_new = $images['folder_new'];
  209.                         }
  210.                 }
  211.  
  212.                 if ( $userdata['session_logged_in'] )
  213.                 {
  214.                         if ( $line[$i]['post_time'] > $userdata['user_lastvisit'] ) 
  215.                         {
  216.                                 if ( !empty($tracking_topics) || !empty($tracking_forums) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
  217.                                 {
  218.                                         $unread_topics = true;
  219.                                         if ( !empty($tracking_topics[$topic_id]) )
  220.                                         {
  221.                                                 if ( $tracking_topics[$topic_id] > $line[$i]['post_time'] )
  222.                                                 {
  223.                                                         $unread_topics = false;
  224.                                                 }
  225.                                         }
  226.                                         if ( !empty($tracking_forums[$forum_id]) )
  227.                                         {
  228.                                                 if ( $tracking_forums[$forum_id] > $line[$i]['post_time'] )
  229.                                                 {
  230.                                                         $unread_topics = false;
  231.                     }
  232.                                         }
  233.                                         if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
  234.                                         {
  235.                                                 if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $line[$i]['post_time'] )
  236.                                                 {
  237.                                                         $unread_topics = false;
  238.                     }
  239.                                         }
  240.                                         if ( $unread_topics )
  241.                                         {
  242.                                                 $folder_image = $folder_new;
  243.                     $folder_alt = $lang['New_posts'];
  244.                                 $newest_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
  245.                                         }
  246.                                         else
  247.                                         {
  248.                                                 $folder_alt = ( $line[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
  249.                                                 $folder_image = $folder;
  250.                     $folder_alt = $folder_alt;
  251.                     $newest_img = '';
  252.                                         }
  253.                                 }
  254.                                 else if ( $line[$i]['post_time'] > $userdata['user_lastvisit'] ) 
  255.                                 {
  256.                                         $folder_image = $folder_new;
  257.                                         $folder_alt = $lang['New_posts'];
  258.                                         $newest_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
  259.                                 }
  260.                                 else 
  261.                                 {
  262.                                         $folder_image = $folder;
  263.                                         $folder_alt = ( $line[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
  264.                                         $newest_img = '';
  265.                                 }
  266.                         }
  267.                         else
  268.                         {
  269.                                 $folder_image = $folder;
  270.                                 $folder_alt = ( $line[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
  271.                                 $newest_img = '';
  272.                         }
  273.                 }
  274.                 else
  275.                 {
  276.                         $folder_image = $folder;
  277.                         $folder_alt = ( $line[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
  278.                         $newest_img = '';
  279.                 }
  280.                 
  281.                 $first_time = create_date($board_config['default_dateformat'], $line[$i]['topic_time'], $board_config['board_timezone']);
  282.         if ( $line[$i]['user_id2'] != ANONYMOUS )
  283.         {
  284.             $first_author = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '='  . $line[$i]['user_id2']) . '">'.$line[$i]['username2'].'</a>';
  285.         }
  286.         else
  287.         {
  288.             $sql = "SELECT p.post_username FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
  289.                 WHERE t.topic_first_post_id = p.post_id
  290.                 AND t.topic_id = $topic_id";
  291.             if ( !$result = $db->sql_query($sql) )
  292.             {
  293.                 message_die(GENERAL_ERROR, 'Could not get topic autor name', '', __LINE__, __FILE__, $sql);
  294.             }
  295.             $row = $db->sql_fetchrow($result);
  296.             $topic_author_name = $row['post_username'];
  297.             $first_author = ($topic_author_name != '' ) ? $topic_author_name : $lang['Guest'];
  298.         }
  299.                 $last_time = create_date($board_config['default_dateformat'], $line[$i]['post_time'], $board_config['board_timezone']);
  300.                 $last_author = ( $line[$i]['poster_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '='  . $line[$i]['poster_id']) . '">'.$line[$i]['username'].'</a>' : ( ($line[$i]['post_username'] != '' ) ? $line[$i]['post_username'] : $lang['Guest'] );
  301.                 $last_url = '<a href="' . append_sid("viewtopic.$phpEx?"  . POST_POST_URL . '=' . $line[$i]['topic_last_post_id']) . '#' . $line[$i]['topic_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" border="0" /></a>';
  302.  
  303.                 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
  304.  
  305.                 $template->assign_block_vars('recent', array(
  306.                         'TOPIC_TITLE' => $topic_title,
  307.                         'TOPIC_TYPE' => $topic_type,
  308.                         'VIEWS' => $views,
  309.                         'REPLIES' => $replies,
  310.                         'GOTO_PAGE' => $goto_page,
  311.                         'TOPIC_FOLDER_IMG' => '<img src="'.$folder_image.'" width="19" height="18" alt="'.$folder_alt.'" />', 
  312.                         'NEWEST_IMG' => $newest_img, 
  313.                         'FIRST_TIME' => sprintf($lang['Started'], $first_time),
  314.                         'FIRST_AUTHOR' => sprintf($lang['By'], $first_author),
  315.                         'LAST_TIME' => $last_time,
  316.                         'LAST_AUTHOR' => $last_author,
  317.                         'LAST_URL' => $last_url,
  318.                         'ROW_CLASS' => $row_class,
  319.                         'L_REPLIES' => $lang['Replies'],
  320.                         'L_VIEWS' => $lang['Views'],
  321.                         'FORUM_NAME' => $line[$i]['forum_name'],
  322.                         'U_VIEW_FORUM' => $forum_url, 
  323.                         'FORUM_ID' => $forum_id,
  324.                         'U_VIEW_TOPIC' => $topic_url,
  325.                         'TOPIC_ID' => $topic_id
  326.                 ));
  327.         }
  328.  
  329. if ( $selorder == 'las24' )
  330. {
  331.         $where = "WHERE t.topic_id IN ($auth_results) AND UNIX_TIMESTAMP(NOW()) - p.post_time < 86400";
  332.         $l_selorder = $lang['24h'];
  333. }
  334. else if ( $selorder == 'today' )
  335. {
  336.         $where = "WHERE $where_part1 AND FROM_UNIXTIME(p.post_time,'%Y%m%d') - FROM_UNIXTIME(unix_timestamp(NOW()),'%Y%m%d') = 0";
  337.         $l_selorder = $lang['tday'];
  338. }
  339. else if ( $selorder == 'yestr' )
  340. {
  341.         $where = "WHERE $where_part1 AND FROM_UNIXTIME(p.post_time,'%Y%m%d') - FROM_UNIXTIME(unix_timestamp(NOW()),'%Y%m%d') = -1";
  342.         $l_selorder = $lang['yday'];
  343. }
  344. else if ( $selorder == 'lweek' )
  345. {
  346.         $where = "WHERE $where_part1 AND UNIX_TIMESTAMP(NOW()) - p.post_time < 691200";
  347.         $l_selorder = $lang['week'];
  348. }
  349. else if ( $selorder == 'laday' )
  350. {
  351.         $where = "WHERE $where_part1 AND UNIX_TIMESTAMP(NOW()) - p.post_time < $showdays";
  352.         $l_selorder = sprintf($lang['xdays'],$nodays);
  353. }
  354.  
  355. $select_special = ( $special_forums == '0' ) ? '' : ' , '.FORUMS_TABLE.' f';
  356. $where_special = ( $special_forums == '0' ) ? '' : ' AND t.forum_id = f.forum_id';
  357. $sql = "SELECT count(*) AS total FROM ".TOPICS_TABLE." t , ".POSTS_TABLE." p $select_special $where AND p.post_id = t.topic_last_post_id $where_special";
  358.  
  359. if ( !($result = $db->sql_query($sql)) )
  360. {
  361.         message_die(GENERAL_ERROR, 'Error getting total topics', '', __LINE__, __FILE__, $sql);
  362. }
  363. if ( $total = $db->sql_fetchrow($result) )
  364. {
  365.         $total_topics = $total['total'];
  366.         $pagination = generate_pagination("recent.$phpEx?nodays=$nodays&selorder=$selorder", $total_topics, $board_config['topics_per_page'], $start). ' ';
  367. }
  368.  
  369. $template->assign_vars(array(
  370.         'L_RECENT_TITLE' => sprintf($lang['Title'],$total_topics,$l_selorder),
  371.         'L_TOPIC' => $lang['Topic'],
  372.         'L_MATCHES' => $lang['matches'],
  373.         'L_LAS24_MSG' => $lang['last_24h'],
  374.         'L_TODAY_MSG' => $lang['today'],
  375.         'L_YESTR_MSG' => $lang['yesterday'],
  376.         'L_LWEEK_MSG' => $lang['last_week'],
  377.         'L_LADAY_MSG' => $lang['last_xdays'],
  378.         'L_SHOW' => $lang['show_posts'],
  379.         'L_SHOWING' => $lang['showing_posts'],
  380.         'L_DAYS' => $lang['day_posts'],
  381.         'L_LAST' => $lang['last_posts'],
  382.         'L_GOTO_PAGE' => $lang['Goto_page'],
  383.         'NODAYS' => $nodays,
  384.         'FORM_ACTION' => $PHP_SELF,
  385.         'PAGINATION' => $pagination,
  386.         'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $total_topics / $board_config['topics_per_page'] )), 
  387. ));
  388.  
  389. $template->pparse('body');
  390. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  391. ?>