diff options
Diffstat (limited to 'phpBB/includes/functions.php')
| -rw-r--r-- | phpBB/includes/functions.php | 369 |
1 files changed, 350 insertions, 19 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 8adc170b1f..78fcc9ba2f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -116,13 +116,13 @@ function generate_forum_nav(&$forum_data) { $template->assign_block_vars('navlinks', array( 'FORUM_NAME' => $parent_name, - 'U_VIEW_FORUM' => 'viewforum.' . $phpEx . $SID . '&f=' . $parent_forum_id) + 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=$parent_forum_id") ); } $template->assign_block_vars('navlinks', array( 'FORUM_NAME' => $forum_data['forum_name'], - 'U_VIEW_FORUM' => 'viewforum.' . $phpEx . $SID . '&f=' . $forum_data['forum_id']) + 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=" . $forum_data['forum_id']) ); $template->assign_vars(array( @@ -224,7 +224,7 @@ function gen_forum_rules($mode, &$forum_id) return; } -function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, &$sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir) +function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, &$sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir, &$u_sort_param) { global $user; @@ -254,6 +254,8 @@ function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, } $s_sort_dir .= '</select>'; + $u_sort_param = "st=$sort_days&sk=$sort_key&sd=$sort_dir"; + return; } @@ -262,7 +264,7 @@ function make_jumpbox($action, $forum_id = false, $select_all = false) global $auth, $template, $user, $db, $nav_links, $phpEx, $SID; $boxstring = ''; - $sql = 'SELECT forum_id, forum_name, forum_postable, left_id, right_id + $sql = 'SELECT forum_id, forum_name, forum_type, left_id, right_id FROM ' . FORUMS_TABLE . ' ORDER BY left_id ASC'; $result = $db->sql_query($sql, 600); @@ -271,7 +273,7 @@ function make_jumpbox($action, $forum_id = false, $select_all = false) $padding = $forum_list = $holding = ''; while ($row = $db->sql_fetchrow($result)) { - if (!$row['forum_postable'] && ($row['left_id'] + 1 == $row['right_id'])) + if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id'])) { // Non-postable forum with no subforums, don't display continue; @@ -447,10 +449,7 @@ function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $mat $db->sql_query($sql); } - $template->assign_vars(array( - 'META' => '<meta http-equiv="refresh" content="3;url=' . "view$mode.$phpEx$SID&" . $u_url . "=$match_id&start=$start" . '">') - ); - + meta_refresh(3, "view$mode.$phpEx$SID&$u_url=$match_id&start=$start"); $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . "view$mode.$phpEx$SID&" . $u_url . "=$match_id&start=$start" . '">', '</a>'); trigger_error($message); } @@ -481,10 +480,7 @@ function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $mat $db->sql_query($sql); } - $template->assign_vars(array( - 'META' => '<meta http-equiv="refresh" content="3;url=' . "view$mode.$phpEx$SID&" . $u_url . "=$match_id&start=$start" . '">') - ); - + meta_refresh(3, "view$mode.$phpEx$SID&$u_url=$match_id&start=$start"); $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . "view$mode.$phpEx$SID&" . $u_url . "=$match_id&start=$start" . '">', '</a>'); trigger_error($message); } @@ -512,14 +508,14 @@ function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $mat if ($can_watch) { - $s_watching = ($is_watching) ? '<a href="' . "view$mode." . $phpEx . $SID . '&' . $u_url . "=$match_id&unwatch=$mode&start=$start" . '">' . $user->lang['STOP_WATCHING_' . strtoupper($mode)] . '</a>' : '<a href="' . "view$mode." . $phpEx . $SID . '&' . $u_url . "=$match_id&watch=$mode&start=$start" . '">' . $user->lang['START_WATCHING_' . strtoupper($mode)] . '</a>'; + $s_watching = ($is_watching) ? "<a href=\"view$mode.$phpEx$SID&$u_url=$match_id&unwatch=$mode&start=$start\">" . $user->lang['STOP_WATCHING_' . strtoupper($mode)] . '</a>' : "<a href=\"view$mode.$phpEx$SID&$u_url=$match_id&watch=$mode&start=$start\">" . $user->lang['START_WATCHING_' . strtoupper($mode)] . '</a>'; } return; } // Marks a topic or form as read -function markread($mode, $forum_id = 0, $topic_id = 0, $post_id = 0) +function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false) { global $config, $db, $user; @@ -530,7 +526,7 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $post_id = 0) // Default tracking type $type = TRACK_NORMAL; - $current_time = time(); + $current_time = ($marktime) ? $marktime : time(); switch ($mode) { @@ -857,7 +853,7 @@ function generate_board_url() // Redirects the user to another page then exits the script nicely function redirect($url) { - global $db, $cache, $config; + global $db, $cache, $config, $user; if (isset($db)) { @@ -869,13 +865,14 @@ function redirect($url) $cache->unload(); } - $url = generate_board_url() . preg_replace('#^/?(.*?)/?$#', '/\1', trim($url)); + // Local redirect? If not, prepend the boards url + $url = (!strstr($url, '://')) ? (generate_board_url() . preg_replace('#^/?(.*?)/?$#', '/\1', trim($url))) : $url; // Redirect via an HTML form for PITA webservers if (@preg_match('#Microsoft|WebSTAR|Xitami#', getenv('SERVER_SOFTWARE'))) { header('Refresh: 0; URL=' . $url); - echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="0; url=' . $url . '"><title>Redirect</title></head><body><div align="center">If your browser does not support meta redirection please click <a href="' . $url . '">HERE</a> to be redirected</div></body></html>'; + echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="0; url=' . $url . '"><title>Redirect</title></head><body><div align="center">' . sprintf($user->lang['URL_REDIRECT'], '<a href="' . $url . '">', '</a>') . '</div></body></html>'; exit; } @@ -1045,5 +1042,339 @@ function msg_handler($errno, $msg_text, $errfile, $errline) break; } } +/* +// +function page_header($page_title = '') +{ + global $db, $config, $template, $user, $auth, $cache; + + define('HEADER_INC', TRUE); + + // gzip_compression + if ($config['gzip_compress']) + { + if (extension_loaded('zlib') && !headers_sent()) + { + ob_start('ob_gzhandler'); + } + } + + // Generate logged in/logged out status + if ($user->data['user_id'] != ANONYMOUS) + { + $u_login_logout = 'ucp.'.$phpEx. $SID . '&mode=logout'; + $l_login_logout = sprintf($user->lang['LOGOUT_USER'], $user->data['username']); + } + else + { + $u_login_logout = 'ucp.'.$phpEx . $SID . '&mode=login'; + $l_login_logout = $user->lang['LOGIN']; + } + + // Last visit date/time + $s_last_visit = ($user->data['user_id'] != ANONYMOUS) ? $user->format_date($user->data['session_last_visit']) : ''; + + // Get users online list ... if required + $l_online_users = $online_userlist = $l_online_record = ''; + if (!empty($config['load_online']) && !empty($config['load_online_time'])) + { + $userlist_ary = $userlist_visible = array(); + $logged_visible_online = $logged_hidden_online = $guests_online = 0; + + $prev_user_id = 0; + $prev_user_ip = $reading_sql = ''; + if (!empty($_REQUEST['f'])) + { + $reading_sql = "AND s.session_page LIKE '%f=" . intval($_REQUEST['f']) . "%'"; + } + + $sql = "SELECT u.username, u.user_id, u.user_allow_viewonline, u.user_colour, s.session_ip, s.session_allow_viewonline + FROM " . USERS_TABLE . " u, " . SESSIONS_TABLE ." s + WHERE s.session_time >= " . (time() - (intval($config['load_online_time']) * 60)) . " + $reading_sql + AND u.user_id = s.session_user_id + ORDER BY u.username ASC, s.session_ip ASC"; + $result = $db->sql_query($sql, false); + + while ($row = $db->sql_fetchrow($result)) + { + // User is logged in and therefor not a guest + if ($row['user_id'] != ANONYMOUS) + { + // Skip multiple sessions for one user + if ($row['user_id'] != $prev_user_id) + { + if ($row['user_colour']) + { + $row['username'] = '<b style="color:#' . $row['user_colour'] . '">' . $row['username'] . '</b>'; + } + + if ($row['user_allow_viewonline'] && $row['session_allow_viewonline']) + { + $user_online_link = $row['username']; + $logged_visible_online++; + } + else + { + $user_online_link = '<i>' . $row['username'] . '</i>'; + $logged_hidden_online++; + } + + if ($row['user_allow_viewonline'] || $auth->acl_get('u_viewonline')) + { + $user_online_link = '<a href="' . "memberlist.$phpEx$SID&mode=viewprofile&u=" . $row['user_id'] . '">' . $user_online_link . '</a>'; + $online_userlist .= ($online_userlist != '') ? ', ' . $user_online_link : $user_online_link; + } + } + + $prev_user_id = $row['user_id']; + } + else + { + // Skip multiple sessions for one user + if ($row['session_ip'] != $prev_session_ip) + { + $guests_online++; + } + } + + $prev_session_ip = $row['session_ip']; + } + + if ($online_userlist == '') + { + $online_userlist = $user->lang['NONE']; + } + + if (empty($_REQUEST['f'])) + { + $online_userlist = $user->lang['Registered_users'] . ' ' . $online_userlist; + } + else + { + $l_online = ($guests_online == 1) ? $user->lang['Browsing_forum_guest'] : $user->lang['Browsing_forum_guests']; + $online_userlist = sprintf($l_online, $online_userlist, $guests_online); + } + + $total_online_users = $logged_visible_online + $logged_hidden_online + $guests_online; + + if ($total_online_users > $config['record_online_users']) + { + set_config('record_online_users', $total_online_users, TRUE); + set_config('record_online_date', time(), TRUE); + } + + // Build online listing + $vars_online = array( + 'ONLINE'=> array('total_online_users', 'l_t_user_s'), + 'REG' => array('logged_visible_online', 'l_r_user_s'), + 'HIDDEN'=> array('logged_hidden_online', 'l_h_user_s'), + 'GUEST' => array('guests_online', 'l_g_user_s') + ); + + foreach ($vars_online as $l_prefix => $var_ary) + { + switch ($$var_ary[0]) + { + case 0: + $$var_ary[1] = $user->lang[$l_prefix . '_USERS_ZERO_TOTAL']; + break; + + case 1: + $$var_ary[1] = $user->lang[$l_prefix . '_USER_TOTAL']; + break; + + default: + $$var_ary[1] = $user->lang[$l_prefix . '_USERS_TOTAL']; + break; + } + } + unset($vars_online); + + $l_online_users = sprintf($l_t_user_s, $total_online_users); + $l_online_users .= sprintf($l_r_user_s, $logged_visible_online); + $l_online_users .= sprintf($l_h_user_s, $logged_hidden_online); + $l_online_users .= sprintf($l_g_user_s, $guests_online); + $l_online_record = sprintf($user->lang['RECORD_ONLINE_USERS'], $config['record_online_users'], $user->format_date($config['record_online_date'])); + $l_online_time = ($config['load_online_time'] == 1) ? 'VIEW_ONLINE_TIME' : 'VIEW_ONLINE_TIMES'; + $l_online_time = sprintf($user->lang[$l_online_time], $config['load_online_time']); + } + + // Obtain number of new private messages if user is logged in + if ($user->data['user_id'] != ANONYMOUS) + { + if ($user->data['user_new_privmsg']) + { + $l_message_new = ($user->data['user_new_privmsg'] == 1) ? $user->lang['New_pm'] : $user->lang['New_pms']; + $l_privmsgs_text = sprintf($l_message_new, $user->data['user_new_privmsg']); + + if ($user->data['user_last_privmsg'] > $user->data['session_last_visit']) + { + $sql = "UPDATE " . USERS_TABLE . " + SET user_last_privmsg = " . $user->data['session_last_visit'] . " + WHERE user_id = " . $user->data['user_id']; + $db->sql_query($sql); + + $s_privmsg_new = 1; + } + else + { + $s_privmsg_new = 0; + } + } + else + { + $l_privmsgs_text = $user->lang['No_new_pm']; + $s_privmsg_new = 0; + } + + if ($user->data['user_unread_privmsg']) + { + $l_message_unread = ($user->data['user_unread_privmsg'] == 1) ? $user->lang['Unread_pm'] : $user->lang['Unread_pms']; + $l_privmsgs_text_unread = sprintf($l_message_unread, $user->data['user_unread_privmsg']); + } + else + { + $l_privmsgs_text_unread = $user->lang['No_unread_pm']; + } + } + + // Generate HTML required for Mozilla Navigation bar + $nav_links_html = ''; + * + $nav_link_proto = '<link rel="%s" href="%s" title="%s" />' . "\n"; + foreach ($nav_links as $nav_item => $nav_array) + { + if (!empty($nav_array['url'])) + { + $nav_links_html .= sprintf($nav_link_proto, $nav_item, $nav_array['url'], $nav_array['title']); + } + else + { + // We have a nested array, used for items like <link rel='chapter'> that can occur more than once. + foreach ($nav_array as $key => $nested_array) + { + $nav_links_html .= sprintf($nav_link_proto, $nav_item, $nested_array['url'], $nested_array['title']); + } + } + } + * + + // Which timezone? + $tz = ($user->data['user_id'] != ANONYMOUS) ? strval(doubleval($user->data['user_timezone'])) : strval(doubleval($config['board_timezone'])); + + // The following assigns all _common_ variables that may be used at any point + // in a template. + $template->assign_vars(array( + 'SITENAME' => $config['sitename'], + 'SITE_DESCRIPTION' => $config['site_desc'], + 'PAGE_TITLE' => $page_title, + 'LAST_VISIT_DATE' => sprintf($user->lang['YOU_LAST_VISIT'], $s_last_visit), + 'CURRENT_TIME' => sprintf($user->lang['CURRENT_TIME'], $user->format_date(time())), + 'TOTAL_USERS_ONLINE' => $l_online_users, + 'LOGGED_IN_USER_LIST' => $online_userlist, + 'RECORD_USERS' => $l_online_record, + 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, + 'PRIVATE_MESSAGE_NEW_FLAG' => $s_privmsg_new, + 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, + + 'L_LOGIN_LOGOUT' => $l_login_logout, + 'L_INDEX' => $user->lang['FORUM_INDEX'], + 'L_ONLINE_EXPLAIN' => $l_online_time, + + 'U_PRIVATEMSGS' => 'ucp.'.$phpEx.$SID.'&mode=pm&folder=inbox', + 'U_MEMBERLIST' => 'memberlist.'.$phpEx.$SID, + 'U_VIEWONLINE' => 'viewonline.'.$phpEx.$SID, + 'U_MEMBERSLIST' => 'memberlist.'.$phpEx.$SID, + 'U_GROUP_CP' => 'groupcp.'.$phpEx.$SID, + 'U_LOGIN_LOGOUT'=> $u_login_logout, + 'U_INDEX' => 'index.'.$phpEx.$SID, + 'U_SEARCH' => 'search.'.$phpEx.$SID, + 'U_REGISTER' => 'ucp.'.$phpEx.$SID.'&mode=register', + 'U_PROFILE' => 'ucp.'.$phpEx.$SID.'&mode=editprofile', + 'U_MODCP' => 'mcp.'.$phpEx.$SID, + 'U_FAQ' => 'faq.'.$phpEx.$SID, + 'U_SEARCH_SELF' => 'search.'.$phpEx.$SID.'&search_id=egosearch', + 'U_SEARCH_NEW' => 'search.'.$phpEx.$SID.'&search_id=newposts', + 'U_SEARCH_UNANSWERED' => 'search.'.$phpEx.$SID.'&search_id=unanswered', + + 'S_USER_LOGGED_IN' => ($user->data['user_id'] != ANONYMOUS) ? true : false, + 'S_USER_PM_POPUP' => (!empty($user->data['user_popup_pm'])) ? true : false, + 'S_USER_BROWSER' => $user->data['session_browser'], + 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'], + 'S_CONTENT_ENCODING' => $user->lang['ENCODING'], + 'S_CONTENT_DIR_LEFT' => $user->lang['LEFT'], + 'S_CONTENT_DIR_RIGHT' => $user->lang['RIGHT'], + 'S_TIMEZONE' => ($user->data['user_dst'] || ($user->data['user_id'] == ANONYMOUS && $config['board_dst'])) ? sprintf($user->lang['ALL_TIMES'], $user->lang[$tz], $user->lang['tz']['dst']) : sprintf($user->lang['ALL_TIMES'], $user->lang[$tz], ''), + 'S_DISPLAY_ONLINE_LIST' => (!empty($config['load_online'])) ? 1 : 0, + 'S_DISPLAY_SEARCH' => (!empty($config['load_search'])) ? 1 : 0, + 'S_DISPLAY_PM' => (empty($config['privmsg_disable'])) ? 1 : 0, + 'S_DISPLAY_MEMBERLIST' => (isset($auth)) ? $auth->acl_get('u_viewprofile') : 0, + + 'T_STYLESHEET_DATA' => $user->theme['css_data'], + 'T_STYLESHEET_LINK' => 'templates/' . $user->theme['css_external'], + + 'NAV_LINKS' => $nav_links_html) + ); + + if ($config['send_encoding']) + { + header ('Content-type: text/html; charset: ' . $user->lang['ENCODING']); + } + header ('Cache-Control: private, no-cache="set-cookie", pre-check=0, post-check=0'); + header ('Expires: 0'); + header ('Pragma: no-cache'); + + return; +} + +// +function page_footer() +{ + global $db, $config, $template, $user, $auth, $cache, $starttime; + + // Close our DB connection. + $db->sql_close(); + + // Unload cache + if (!empty($cache)) + { + $cache->unload(); + } + + // Output page creation time + if (defined('DEBUG')) + { + $mtime = explode(' ', microtime()); + $totaltime = $mtime[0] + $mtime[1] - $starttime; + + if (!empty($_REQUEST['explain']) && $auth->acl_get('a_')) + { + echo $db->sql_report; + echo "<pre><b>Page generated in $totaltime seconds with " . $db->num_queries . " queries,\nspending " . $db->sql_time . ' doing SQL queries and ' . ($totaltime - $db->sql_time) . ' doing PHP things.</b></pre>'; + + exit; + } + + $debug_output = sprintf('<br /><br />[ Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . ( ( $config['gzip_compress'] ) ? 'On' : 'Off' ) . ' | Load : ' . (($user->load) ? $user->load : 'N/A'), $totaltime); + + if ($auth->acl_get('a_')) + { + $debug_output .= ' | <a href="' . htmlspecialchars($_SERVER['REQUEST_URI']) . '&explain=1">Explain</a>'; + } + $debug_output .= ' ]'; + } + + $template->assign_vars(array( + 'PHPBB_VERSION' => $config['version'], + 'ADMIN_LINK' => ($auth->acl_get('a_')) ? sprintf($user->lang['ACP'], '<a href="' . "adm/index.$phpEx?sid=" . $user->data['session_id'] . '">', '</a>') . '<br /><br />' : '', + 'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '') + ); + + $template->display('body'); + + exit; +} +*/ ?>
\ No newline at end of file |
