<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[PunBB Forums — logout not working]]></title>
		<link>https://punbb.informer.com/forums/topic/22064/logout-not-working/</link>
		<atom:link href="https://punbb.informer.com/forums/feed/rss/topic/22064/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in logout not working.]]></description>
		<lastBuildDate>Tue, 25 Aug 2009 15:25:20 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: logout not working]]></title>
			<link>https://punbb.informer.com/forums/post/129959/#p129959</link>
			<description><![CDATA[<p>Not a problem. <img src="https://punbb.informer.com/forums/img/smilies/wink.png" width="15" height="15" alt="wink" /></p>]]></description>
			<author><![CDATA[null@example.com (StevenBullen)]]></author>
			<pubDate>Tue, 25 Aug 2009 15:25:20 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/129959/#p129959</guid>
		</item>
		<item>
			<title><![CDATA[Re: logout not working]]></title>
			<link>https://punbb.informer.com/forums/post/129958/#p129958</link>
			<description><![CDATA[<div class="quotebox"><cite>StevenBullen wrote:</cite><blockquote><p>Remove<br /></p><div class="codebox"><pre><code>require PUN_ROOT.&#039;include/pms/functions_navlinks2.php&#039;;</code></pre></div></blockquote></div><p>wah nice..thank you so much for helping me.</p>]]></description>
			<author><![CDATA[null@example.com (MCommunity)]]></author>
			<pubDate>Tue, 25 Aug 2009 15:22:11 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/129958/#p129958</guid>
		</item>
		<item>
			<title><![CDATA[Re: logout not working]]></title>
			<link>https://punbb.informer.com/forums/post/129957/#p129957</link>
			<description><![CDATA[<p>Remove<br /></p><div class="codebox"><pre><code>require PUN_ROOT.&#039;include/pms/functions_navlinks2.php&#039;;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (StevenBullen)]]></author>
			<pubDate>Tue, 25 Aug 2009 15:17:12 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/129957/#p129957</guid>
		</item>
		<item>
			<title><![CDATA[Re: logout not working]]></title>
			<link>https://punbb.informer.com/forums/post/129956/#p129956</link>
			<description><![CDATA[<p>^ thanks sir. its working now. i can logout and login back.<br />but how to remove one messages button. its show to message button.<br /> Index User list Rules Search Profile Administration ChatBox<strong> Messages Messages</strong> Logout</p>]]></description>
			<author><![CDATA[null@example.com (MCommunity)]]></author>
			<pubDate>Tue, 25 Aug 2009 15:13:37 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/129956/#p129956</guid>
		</item>
		<item>
			<title><![CDATA[Re: logout not working]]></title>
			<link>https://punbb.informer.com/forums/post/129955/#p129955</link>
			<description><![CDATA[<p>Ok the problem is with the PM mod that you installed. You went over the proper log out code.</p><p>Change this line<br /></p><div class="codebox"><pre><code>$links[] = &#039;&lt;li id=&quot;navlogout&quot;&gt;&lt;a href=&quot;login.php?action=out&amp;amp;id=&#039;.$pun_user[&#039;id&#039;].&#039;&quot;&gt;&#039;.$lang_common[&#039;Logout&#039;].&#039;&lt;/a&gt;&#039;;</code></pre></div><p>to<br /></p><div class="codebox"><pre><code>$links[] = &#039;&lt;li id=&quot;navlogout&quot;&gt;&lt;a href=&quot;login.php?action=out&amp;amp;id=&#039;.$pun_user[&#039;id&#039;].&#039;&amp;amp;csrf_token=&#039;.sha1($pun_user[&#039;id&#039;].sha1(get_remote_address())).&#039;&quot;&gt;&#039;.$lang_common[&#039;Logout&#039;].&#039;&lt;/a&gt;&#039;;</code></pre></div><p>It will occur twice by the way.</p>]]></description>
			<author><![CDATA[null@example.com (StevenBullen)]]></author>
			<pubDate>Tue, 25 Aug 2009 15:03:32 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/129955/#p129955</guid>
		</item>
		<item>
			<title><![CDATA[logout not working]]></title>
			<link>https://punbb.informer.com/forums/post/129954/#p129954</link>
			<description><![CDATA[<p>this is my functions.php code</p><div class="codebox"><pre><code>&lt;?php
/***********************************************************************

  Copyright (C) 2002-2008  PunBB

  This file is part of PunBB.

  PunBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  PunBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  MA  02111-1307  USA

************************************************************************/

//
// Cookie stuff!
//
function check_cookie(&amp;$pun_user)
{
    global $db, $db_type, $pun_config, $cookie_name, $cookie_seed;

    $now = time();
    $expire = $now + 31536000;    // The cookie expires after a year

    // We assume it&#039;s a guest
    $cookie = array(&#039;user_id&#039; =&gt; 1, &#039;password_hash&#039; =&gt; &#039;Guest&#039;);

    // If a cookie is set, we get the user_id and password hash from it
    if (isset($_COOKIE[$cookie_name]))
        list($cookie[&#039;user_id&#039;], $cookie[&#039;password_hash&#039;]) = @unserialize($_COOKIE[$cookie_name]);

    if ($cookie[&#039;user_id&#039;] &gt; 1)
    {
        // Check if there&#039;s a user with the user ID and password hash from the cookie
        $result = $db-&gt;query(&#039;SELECT u.*, g.*, o.logged, o.idle FROM &#039;.$db-&gt;prefix.&#039;users AS u INNER JOIN &#039;.$db-&gt;prefix.&#039;groups AS g ON u.group_id=g.g_id LEFT JOIN &#039;.$db-&gt;prefix.&#039;online AS o ON o.user_id=u.id WHERE u.id=&#039;.intval($cookie[&#039;user_id&#039;])) or error(&#039;Unable to fetch user information&#039;, __FILE__, __LINE__, $db-&gt;error());
        $pun_user = $db-&gt;fetch_assoc($result);

        // If user authorisation failed
        if (!isset($pun_user[&#039;id&#039;]) || md5($cookie_seed.$pun_user[&#039;password&#039;]) !== $cookie[&#039;password_hash&#039;])
        {
            pun_setcookie(1, md5(uniqid(rand(), true)), $expire);
            set_default_user();

            return;
        }

        // Set a default language if the user selected language no longer exists
        if (!@file_exists(PUN_ROOT.&#039;lang/&#039;.$pun_user[&#039;language&#039;]))
            $pun_user[&#039;language&#039;] = $pun_config[&#039;o_default_lang&#039;];

        // Set a default style if the user selected style no longer exists
        if (!@file_exists(PUN_ROOT.&#039;style/&#039;.$pun_user[&#039;style&#039;].&#039;.css&#039;))
            $pun_user[&#039;style&#039;] = $pun_config[&#039;o_default_style&#039;];

        if (!$pun_user[&#039;disp_topics&#039;])
            $pun_user[&#039;disp_topics&#039;] = $pun_config[&#039;o_disp_topics_default&#039;];
        if (!$pun_user[&#039;disp_posts&#039;])
            $pun_user[&#039;disp_posts&#039;] = $pun_config[&#039;o_disp_posts_default&#039;];

        if ($pun_user[&#039;save_pass&#039;] == &#039;0&#039;)
            $expire = 0;

        // Define this if you want this visit to affect the online list and the users last visit data
        if (!defined(&#039;PUN_QUIET_VISIT&#039;))
        {
            // Update the online list
            if (!$pun_user[&#039;logged&#039;])
            {
                $pun_user[&#039;logged&#039;] = $now;

                // With MySQL/MySQLi, REPLACE INTO avoids a user having two rows in the online table
                switch ($db_type)
                {
                    case &#039;mysql&#039;:
                    case &#039;mysqli&#039;:
                        $db-&gt;query(&#039;REPLACE INTO &#039;.$db-&gt;prefix.&#039;online (user_id, ident, logged) VALUES(&#039;.$pun_user[&#039;id&#039;].&#039;, \&#039;&#039;.$db-&gt;escape($pun_user[&#039;username&#039;]).&#039;\&#039;, &#039;.$pun_user[&#039;logged&#039;].&#039;)&#039;) or error(&#039;Unable to insert into online list&#039;, __FILE__, __LINE__, $db-&gt;error());
                        break;

                    default:
                        $db-&gt;query(&#039;INSERT INTO &#039;.$db-&gt;prefix.&#039;online (user_id, ident, logged) VALUES(&#039;.$pun_user[&#039;id&#039;].&#039;, \&#039;&#039;.$db-&gt;escape($pun_user[&#039;username&#039;]).&#039;\&#039;, &#039;.$pun_user[&#039;logged&#039;].&#039;)&#039;) or error(&#039;Unable to insert into online list&#039;, __FILE__, __LINE__, $db-&gt;error());
                        break;
                }
            }
            else
            {
                // Special case: We&#039;ve timed out, but no other user has browsed the forums since we timed out
                if ($pun_user[&#039;logged&#039;] &lt; ($now-$pun_config[&#039;o_timeout_visit&#039;]))
                {
                    $db-&gt;query(&#039;UPDATE &#039;.$db-&gt;prefix.&#039;users SET last_visit=&#039;.$pun_user[&#039;logged&#039;].&#039; WHERE id=&#039;.$pun_user[&#039;id&#039;]) or error(&#039;Unable to update user visit data&#039;, __FILE__, __LINE__, $db-&gt;error());
                    $pun_user[&#039;last_visit&#039;] = $pun_user[&#039;logged&#039;];
                }

                $idle_sql = ($pun_user[&#039;idle&#039;] == &#039;1&#039;) ? &#039;, idle=0&#039; : &#039;&#039;;
                $db-&gt;query(&#039;UPDATE &#039;.$db-&gt;prefix.&#039;online SET logged=&#039;.$now.$idle_sql.&#039; WHERE user_id=&#039;.$pun_user[&#039;id&#039;]) or error(&#039;Unable to update online list&#039;, __FILE__, __LINE__, $db-&gt;error());
            }
        }

        $pun_user[&#039;is_guest&#039;] = false;
    }
    else
        set_default_user();
}


//
// Fill $pun_user with default values (for guests)
//
function set_default_user()
{
    global $db, $db_type, $pun_user, $pun_config;

    $remote_addr = get_remote_address();

    // Fetch guest user
    $result = $db-&gt;query(&#039;SELECT u.*, g.*, o.logged FROM &#039;.$db-&gt;prefix.&#039;users AS u INNER JOIN &#039;.$db-&gt;prefix.&#039;groups AS g ON u.group_id=g.g_id LEFT JOIN &#039;.$db-&gt;prefix.&#039;online AS o ON o.ident=\&#039;&#039;.$remote_addr.&#039;\&#039; WHERE u.id=1&#039;) or error(&#039;Unable to fetch guest information&#039;, __FILE__, __LINE__, $db-&gt;error());
    if (!$db-&gt;num_rows($result))
        exit(&#039;Unable to fetch guest information. The table \&#039;&#039;.$db-&gt;prefix.&#039;users\&#039; must contain an entry with id = 1 that represents anonymous users.&#039;);

    $pun_user = $db-&gt;fetch_assoc($result);

    // Update online list
    if (!$pun_user[&#039;logged&#039;])
    {
        $pun_user[&#039;logged&#039;] = time();

        // With MySQL/MySQLi, REPLACE INTO avoids a user having two rows in the online table
        switch ($db_type)
        {
            case &#039;mysql&#039;:
            case &#039;mysqli&#039;:
                $db-&gt;query(&#039;REPLACE INTO &#039;.$db-&gt;prefix.&#039;online (user_id, ident, logged) VALUES(1, \&#039;&#039;.$db-&gt;escape($remote_addr).&#039;\&#039;, &#039;.$pun_user[&#039;logged&#039;].&#039;)&#039;) or error(&#039;Unable to insert into online list&#039;, __FILE__, __LINE__, $db-&gt;error());
                break;

            default:
                $db-&gt;query(&#039;INSERT INTO &#039;.$db-&gt;prefix.&#039;online (user_id, ident, logged) VALUES(1, \&#039;&#039;.$db-&gt;escape($remote_addr).&#039;\&#039;, &#039;.$pun_user[&#039;logged&#039;].&#039;)&#039;) or error(&#039;Unable to insert into online list&#039;, __FILE__, __LINE__, $db-&gt;error());
                break;
        }
    }
    else
        $db-&gt;query(&#039;UPDATE &#039;.$db-&gt;prefix.&#039;online SET logged=&#039;.time().&#039; WHERE ident=\&#039;&#039;.$db-&gt;escape($remote_addr).&#039;\&#039;&#039;) or error(&#039;Unable to update online list&#039;, __FILE__, __LINE__, $db-&gt;error());

    $pun_user[&#039;disp_topics&#039;] = $pun_config[&#039;o_disp_topics_default&#039;];
    $pun_user[&#039;disp_posts&#039;] = $pun_config[&#039;o_disp_posts_default&#039;];
    $pun_user[&#039;timezone&#039;] = $pun_config[&#039;o_server_timezone&#039;];
    $pun_user[&#039;language&#039;] = $pun_config[&#039;o_default_lang&#039;];
    $pun_user[&#039;style&#039;] = $pun_config[&#039;o_default_style&#039;];
    $pun_user[&#039;is_guest&#039;] = true;
}


//
// Set a cookie, PunBB style!
//
function pun_setcookie($user_id, $password_hash, $expire)
{
    global $cookie_name, $cookie_path, $cookie_domain, $cookie_secure, $cookie_seed;

    // Enable sending of a P3P header by removing // from the following line (try this if login is failing in IE6)
//    @header(&#039;P3P: CP=&quot;CUR ADM&quot;&#039;);

    if (version_compare(PHP_VERSION, &#039;5.2.0&#039;, &#039;&gt;=&#039;))
        setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$password_hash))), $expire, $cookie_path, $cookie_domain, $cookie_secure, true);
    else
        setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$password_hash))), $expire, $cookie_path.&#039;; HttpOnly&#039;, $cookie_domain, $cookie_secure);
}


//
// Check whether the connecting user is banned (and delete any expired bans while we&#039;re at it)
//
function check_bans()
{
    global $db, $pun_config, $lang_common, $pun_user, $pun_bans;

    // Admins aren&#039;t affected
    if ($pun_user[&#039;g_id&#039;] == PUN_ADMIN || !$pun_bans)
        return;

    // Add a dot at the end of the IP address to prevent banned address 192.168.0.5 from matching e.g. 192.168.0.50
    $user_ip = get_remote_address().&#039;.&#039;;
    $bans_altered = false;

    foreach ($pun_bans as $cur_ban)
    {
        // Has this ban expired?
        if ($cur_ban[&#039;expire&#039;] != &#039;&#039; &amp;&amp; $cur_ban[&#039;expire&#039;] &lt;= time())
        {
            $db-&gt;query(&#039;DELETE FROM &#039;.$db-&gt;prefix.&#039;bans WHERE id=&#039;.$cur_ban[&#039;id&#039;]) or error(&#039;Unable to delete expired ban&#039;, __FILE__, __LINE__, $db-&gt;error());
            $bans_altered = true;
            continue;
        }

        if ($cur_ban[&#039;username&#039;] != &#039;&#039; &amp;&amp; !strcasecmp($pun_user[&#039;username&#039;], $cur_ban[&#039;username&#039;]))
        {
            $db-&gt;query(&#039;DELETE FROM &#039;.$db-&gt;prefix.&#039;online WHERE ident=\&#039;&#039;.$db-&gt;escape($pun_user[&#039;username&#039;]).&#039;\&#039;&#039;) or error(&#039;Unable to delete from online list&#039;, __FILE__, __LINE__, $db-&gt;error());
            message($lang_common[&#039;Ban message&#039;].&#039; &#039;.(($cur_ban[&#039;expire&#039;] != &#039;&#039;) ? $lang_common[&#039;Ban message 2&#039;].&#039; &#039;.strtolower(format_time($cur_ban[&#039;expire&#039;], true)).&#039;. &#039; : &#039;&#039;).(($cur_ban[&#039;message&#039;] != &#039;&#039;) ? $lang_common[&#039;Ban message 3&#039;].&#039;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&#039;.pun_htmlspecialchars($cur_ban[&#039;message&#039;]).&#039;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&#039; : &#039;&lt;br /&gt;&lt;br /&gt;&#039;).$lang_common[&#039;Ban message 4&#039;].&#039; &lt;a href=&quot;mailto:&#039;.$pun_config[&#039;o_admin_email&#039;].&#039;&quot;&gt;&#039;.$pun_config[&#039;o_admin_email&#039;].&#039;&lt;/a&gt;.&#039;, true);
        }

        if ($cur_ban[&#039;ip&#039;] != &#039;&#039;)
        {
            $cur_ban_ips = explode(&#039; &#039;, $cur_ban[&#039;ip&#039;]);

            for ($i = 0; $i &lt; count($cur_ban_ips); ++$i)
            {
                $cur_ban_ips[$i] = $cur_ban_ips[$i].&#039;.&#039;;

                if (substr($user_ip, 0, strlen($cur_ban_ips[$i])) == $cur_ban_ips[$i])
                {
                    $db-&gt;query(&#039;DELETE FROM &#039;.$db-&gt;prefix.&#039;online WHERE ident=\&#039;&#039;.$db-&gt;escape($pun_user[&#039;username&#039;]).&#039;\&#039;&#039;) or error(&#039;Unable to delete from online list&#039;, __FILE__, __LINE__, $db-&gt;error());
                    message($lang_common[&#039;Ban message&#039;].&#039; &#039;.(($cur_ban[&#039;expire&#039;] != &#039;&#039;) ? $lang_common[&#039;Ban message 2&#039;].&#039; &#039;.strtolower(format_time($cur_ban[&#039;expire&#039;], true)).&#039;. &#039; : &#039;&#039;).(($cur_ban[&#039;message&#039;] != &#039;&#039;) ? $lang_common[&#039;Ban message 3&#039;].&#039;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&#039;.pun_htmlspecialchars($cur_ban[&#039;message&#039;]).&#039;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&#039; : &#039;&lt;br /&gt;&lt;br /&gt;&#039;).$lang_common[&#039;Ban message 4&#039;].&#039; &lt;a href=&quot;mailto:&#039;.$pun_config[&#039;o_admin_email&#039;].&#039;&quot;&gt;&#039;.$pun_config[&#039;o_admin_email&#039;].&#039;&lt;/a&gt;.&#039;, true);
                }
            }
        }
    }

    // If we removed any expired bans during our run-through, we need to regenerate the bans cache
    if ($bans_altered)
    {
        require_once PUN_ROOT.&#039;include/cache.php&#039;;
        generate_bans_cache();
    }
}


//
// Update &quot;Users online&quot;
//
function update_users_online()
{
    global $db, $pun_config, $pun_user;

    $now = time();

    // Fetch all online list entries that are older than &quot;o_timeout_online&quot;
    $result = $db-&gt;query(&#039;SELECT * FROM &#039;.$db-&gt;prefix.&#039;online WHERE logged&lt;&#039;.($now-$pun_config[&#039;o_timeout_online&#039;])) or error(&#039;Unable to fetch old entries from online list&#039;, __FILE__, __LINE__, $db-&gt;error());
    while ($cur_user = $db-&gt;fetch_assoc($result))
    {
        // If the entry is a guest, delete it
        if ($cur_user[&#039;user_id&#039;] == &#039;1&#039;)
            $db-&gt;query(&#039;DELETE FROM &#039;.$db-&gt;prefix.&#039;online WHERE ident=\&#039;&#039;.$db-&gt;escape($cur_user[&#039;ident&#039;]).&#039;\&#039;&#039;) or error(&#039;Unable to delete from online list&#039;, __FILE__, __LINE__, $db-&gt;error());
        else
        {
            // If the entry is older than &quot;o_timeout_visit&quot;, update last_visit for the user in question, then delete him/her from the online list
            if ($cur_user[&#039;logged&#039;] &lt; ($now-$pun_config[&#039;o_timeout_visit&#039;]))
            {
                $db-&gt;query(&#039;UPDATE &#039;.$db-&gt;prefix.&#039;users SET last_visit=&#039;.$cur_user[&#039;logged&#039;].&#039; WHERE id=&#039;.$cur_user[&#039;user_id&#039;]) or error(&#039;Unable to update user visit data&#039;, __FILE__, __LINE__, $db-&gt;error());
                $db-&gt;query(&#039;DELETE FROM &#039;.$db-&gt;prefix.&#039;online WHERE user_id=&#039;.$cur_user[&#039;user_id&#039;]) or error(&#039;Unable to delete from online list&#039;, __FILE__, __LINE__, $db-&gt;error());
            }
            else if ($cur_user[&#039;idle&#039;] == &#039;0&#039;)
                $db-&gt;query(&#039;UPDATE &#039;.$db-&gt;prefix.&#039;online SET idle=1 WHERE user_id=&#039;.$cur_user[&#039;user_id&#039;]) or error(&#039;Unable to insert into online list&#039;, __FILE__, __LINE__, $db-&gt;error());
        }
    }
}


//
// Generate the &quot;navigator&quot; that appears at the top of every page
//
function generate_navlinks()
{
    global $pun_config, $lang_common, $pun_user;

    // Index and Userlist should always be displayed
    $links[] = &#039;&lt;li id=&quot;navindex&quot;&gt;&lt;a href=&quot;index.php&quot;&gt;&#039;.$lang_common[&#039;Index&#039;].&#039;&lt;/a&gt;&#039;;
    $links[] = &#039;&lt;li id=&quot;navuserlist&quot;&gt;&lt;a href=&quot;userlist.php&quot;&gt;&#039;.$lang_common[&#039;User list&#039;].&#039;&lt;/a&gt;&#039;;

    if ($pun_config[&#039;o_rules&#039;] == &#039;1&#039;)
        $links[] = &#039;&lt;li id=&quot;navrules&quot;&gt;&lt;a href=&quot;misc.php?action=rules&quot;&gt;&#039;.$lang_common[&#039;Rules&#039;].&#039;&lt;/a&gt;&#039;;

    if ($pun_user[&#039;is_guest&#039;])
    {
        if ($pun_user[&#039;g_search&#039;] == &#039;1&#039;)
            $links[] = &#039;&lt;li id=&quot;navsearch&quot;&gt;&lt;a href=&quot;search.php&quot;&gt;&#039;.$lang_common[&#039;Search&#039;].&#039;&lt;/a&gt;&#039;;

        $links[] = &#039;&lt;li id=&quot;navregister&quot;&gt;&lt;a href=&quot;register.php&quot;&gt;&#039;.$lang_common[&#039;Register&#039;].&#039;&lt;/a&gt;&#039;;
        $links[] = &#039;&lt;li id=&quot;navlogin&quot;&gt;&lt;a href=&quot;login.php&quot;&gt;&#039;.$lang_common[&#039;Login&#039;].&#039;&lt;/a&gt;&#039;;

        $info = $lang_common[&#039;Not logged in&#039;];
    }
    else
    {
if ($pun_user[&#039;g_id&#039;] &gt; PUN_MOD)
        {
            if ($pun_user[&#039;g_search&#039;] == &#039;1&#039;)
                $links[] = &#039;&lt;li id=&quot;navsearch&quot;&gt;&lt;a href=&quot;search.php&quot;&gt;&#039;.$lang_common[&#039;Search&#039;].&#039;&lt;/a&gt;&#039;;

            $links[] = &#039;&lt;li id=&quot;navprofile&quot;&gt;&lt;a href=&quot;profile.php?id=&#039;.$pun_user[&#039;id&#039;].&#039;&quot;&gt;&#039;.$lang_common[&#039;Profile&#039;].&#039;&lt;/a&gt;&#039;;
            require(PUN_ROOT.&#039;include/pms/functions_navlinks.php&#039;);
            $links[] = &#039;&lt;li id=&quot;navlogout&quot;&gt;&lt;a href=&quot;login.php?action=out&amp;amp;id=&#039;.$pun_user[&#039;id&#039;].&#039;&quot;&gt;&#039;.$lang_common[&#039;Logout&#039;].&#039;&lt;/a&gt;&#039;;
        }
        else
        {
            $links[] = &#039;&lt;li id=&quot;navsearch&quot;&gt;&lt;a href=&quot;search.php&quot;&gt;&#039;.$lang_common[&#039;Search&#039;].&#039;&lt;/a&gt;&#039;;
            $links[] = &#039;&lt;li id=&quot;navprofile&quot;&gt;&lt;a href=&quot;profile.php?id=&#039;.$pun_user[&#039;id&#039;].&#039;&quot;&gt;&#039;.$lang_common[&#039;Profile&#039;].&#039;&lt;/a&gt;&#039;;
            $links[] = &#039;&lt;li id=&quot;navadmin&quot;&gt;&lt;a href=&quot;admin_index.php&quot;&gt;&#039;.$lang_common[&#039;Admin&#039;].&#039;&lt;/a&gt;&#039;;
            require(PUN_ROOT.&#039;include/pms/functions_navlinks.php&#039;);
            $links[] = &#039;&lt;li id=&quot;navlogout&quot;&gt;&lt;a href=&quot;login.php?action=out&amp;amp;id=&#039;.$pun_user[&#039;id&#039;].&#039;&quot;&gt;&#039;.$lang_common[&#039;Logout&#039;].&#039;&lt;/a&gt;&#039;;
        }
    }

    // Are there any additional navlinks we should insert into the array before imploding it?
    if ($pun_config[&#039;o_additional_navlinks&#039;] != &#039;&#039;)
    {
        if (preg_match_all(&#039;#([0-9]+)\s*=\s*(.*?)\n#s&#039;, $pun_config[&#039;o_additional_navlinks&#039;].&quot;\n&quot;, $extra_links))
        {
            // Insert any additional links into the $links array (at the correct index)
            for ($i = 0; $i &lt; count($extra_links[1]); ++$i)
                array_splice($links, $extra_links[1][$i], 0, array(&#039;&lt;li id=&quot;navextra&#039;.($i + 1).&#039;&quot;&gt;&#039;.$extra_links[2][$i]));
        }
    }

    require PUN_ROOT.&#039;include/pms/functions_navlinks2.php&#039;;
    return &#039;&lt;ul&gt;&#039;.&quot;\n\t\t\t\t&quot;.implode($lang_common[&#039;Link separator&#039;].&#039;&lt;/li&gt;&#039;.&quot;\n\t\t\t\t&quot;, $links).&#039;&lt;/li&gt;&#039;.&quot;\n\t\t\t&quot;.&#039;&lt;/ul&gt;&#039;;
}


//
// Display the profile navigation menu
//
function generate_profile_menu($page = &#039;&#039;)
{
    global $lang_profile, $pun_config, $pun_user, $id;

?&gt;
&lt;div id=&quot;profile&quot; class=&quot;block2col&quot;&gt;
    &lt;div class=&quot;blockmenu&quot;&gt;
        &lt;h2&gt;&lt;span&gt;&lt;?php echo $lang_profile[&#039;Profile menu&#039;] ?&gt;&lt;/span&gt;&lt;/h2&gt;
        &lt;div class=&quot;box&quot;&gt;
            &lt;div class=&quot;inbox&quot;&gt;
                &lt;ul&gt;
                    &lt;li&lt;?php if ($page == &#039;essentials&#039;) echo &#039; class=&quot;isactive&quot;&#039;; ?&gt;&gt;&lt;a href=&quot;profile.php?section=essentials&amp;amp;id=&lt;?php echo $id ?&gt;&quot;&gt;&lt;?php echo $lang_profile[&#039;Section essentials&#039;] ?&gt;&lt;/a&gt;&lt;/li&gt;
                    &lt;li&lt;?php if ($page == &#039;personal&#039;) echo &#039; class=&quot;isactive&quot;&#039;; ?&gt;&gt;&lt;a href=&quot;profile.php?section=personal&amp;amp;id=&lt;?php echo $id ?&gt;&quot;&gt;&lt;?php echo $lang_profile[&#039;Section personal&#039;] ?&gt;&lt;/a&gt;&lt;/li&gt;
                    &lt;li&lt;?php if ($page == &#039;messaging&#039;) echo &#039; class=&quot;isactive&quot;&#039;; ?&gt;&gt;&lt;a href=&quot;profile.php?section=messaging&amp;amp;id=&lt;?php echo $id ?&gt;&quot;&gt;&lt;?php echo $lang_profile[&#039;Section messaging&#039;] ?&gt;&lt;/a&gt;&lt;/li&gt;
                    &lt;li&lt;?php if ($page == &#039;personality&#039;) echo &#039; class=&quot;isactive&quot;&#039;; ?&gt;&gt;&lt;a href=&quot;profile.php?section=personality&amp;amp;id=&lt;?php echo $id ?&gt;&quot;&gt;&lt;?php echo $lang_profile[&#039;Section personality&#039;] ?&gt;&lt;/a&gt;&lt;/li&gt;
                    &lt;li&lt;?php if ($page == &#039;display&#039;) echo &#039; class=&quot;isactive&quot;&#039;; ?&gt;&gt;&lt;a href=&quot;profile.php?section=display&amp;amp;id=&lt;?php echo $id ?&gt;&quot;&gt;&lt;?php echo $lang_profile[&#039;Section display&#039;] ?&gt;&lt;/a&gt;&lt;/li&gt;
                    &lt;li&lt;?php if ($page == &#039;privacy&#039;) echo &#039; class=&quot;isactive&quot;&#039;; ?&gt;&gt;&lt;a href=&quot;profile.php?section=privacy&amp;amp;id=&lt;?php echo $id ?&gt;&quot;&gt;&lt;?php echo $lang_profile[&#039;Section privacy&#039;] ?&gt;&lt;/a&gt;&lt;/li&gt;
&lt;?php if ($pun_user[&#039;g_id&#039;] == PUN_ADMIN || ($pun_user[&#039;g_id&#039;] == PUN_MOD &amp;&amp; $pun_config[&#039;p_mod_ban_users&#039;] == &#039;1&#039;)): ?&gt;                    &lt;li&lt;?php if ($page == &#039;admin&#039;) echo &#039; class=&quot;isactive&quot;&#039;; ?&gt;&gt;&lt;a href=&quot;profile.php?section=admin&amp;amp;id=&lt;?php echo $id ?&gt;&quot;&gt;&lt;?php echo $lang_profile[&#039;Section admin&#039;] ?&gt;&lt;/a&gt;&lt;/li&gt;
&lt;?php endif; ?&gt;                &lt;/ul&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;?php

}


//
// Update posts, topics, last_post, last_post_id and last_poster for a forum
//
function update_forum($forum_id)
{
    global $db;

    $result = $db-&gt;query(&#039;SELECT COUNT(id), SUM(num_replies) FROM &#039;.$db-&gt;prefix.&#039;topics WHERE forum_id=&#039;.$forum_id) or error(&#039;Unable to fetch forum topic count&#039;, __FILE__, __LINE__, $db-&gt;error());
    list($num_topics, $num_posts) = $db-&gt;fetch_row($result);

    $num_posts = $num_posts + $num_topics;        // $num_posts is only the sum of all replies (we have to add the topic posts)

    $result = $db-&gt;query(&#039;SELECT last_post, last_post_id, last_poster FROM &#039;.$db-&gt;prefix.&#039;topics WHERE forum_id=&#039;.$forum_id.&#039; AND moved_to IS NULL ORDER BY last_post DESC LIMIT 1&#039;) or error(&#039;Unable to fetch last_post/last_post_id/last_poster&#039;, __FILE__, __LINE__, $db-&gt;error());
    if ($db-&gt;num_rows($result))        // There are topics in the forum
    {
        list($last_post, $last_post_id, $last_poster) = $db-&gt;fetch_row($result);

        $db-&gt;query(&#039;UPDATE &#039;.$db-&gt;prefix.&#039;forums SET num_topics=&#039;.$num_topics.&#039;, num_posts=&#039;.$num_posts.&#039;, last_post=&#039;.$last_post.&#039;, last_post_id=&#039;.$last_post_id.&#039;, last_poster=\&#039;&#039;.$db-&gt;escape($last_poster).&#039;\&#039; WHERE id=&#039;.$forum_id) or error(&#039;Unable to update last_post/last_post_id/last_poster&#039;, __FILE__, __LINE__, $db-&gt;error());
    }
    else    // There are no topics
        $db-&gt;query(&#039;UPDATE &#039;.$db-&gt;prefix.&#039;forums SET num_topics=&#039;.$num_topics.&#039;, num_posts=&#039;.$num_posts.&#039;, last_post=NULL, last_post_id=NULL, last_poster=NULL WHERE id=&#039;.$forum_id) or error(&#039;Unable to update last_post/last_post_id/last_poster&#039;, __FILE__, __LINE__, $db-&gt;error());
}


//
// Delete a topic and all of it&#039;s posts
//
function delete_topic($topic_id)
{
    global $db;

    // Delete the topic and any redirect topics
    $db-&gt;query(&#039;DELETE FROM &#039;.$db-&gt;prefix.&#039;topics WHERE id=&#039;.$topic_id.&#039; OR moved_to=&#039;.$topic_id) or error(&#039;Unable to delete topic&#039;, __FILE__, __LINE__, $db-&gt;error());

    // Create a list of the post ID&#039;s in this topic
    $post_ids = &#039;&#039;;
    $result = $db-&gt;query(&#039;SELECT id FROM &#039;.$db-&gt;prefix.&#039;posts WHERE topic_id=&#039;.$topic_id) or error(&#039;Unable to fetch posts&#039;, __FILE__, __LINE__, $db-&gt;error());
    while ($row = $db-&gt;fetch_row($result))
        $post_ids .= ($post_ids != &#039;&#039;) ? &#039;,&#039;.$row[0] : $row[0];

    // Make sure we have a list of post ID&#039;s
    if ($post_ids != &#039;&#039;)
    {
        strip_search_index($post_ids);

        // Delete posts in topic
        $db-&gt;query(&#039;DELETE FROM &#039;.$db-&gt;prefix.&#039;posts WHERE topic_id=&#039;.$topic_id) or error(&#039;Unable to delete posts&#039;, __FILE__, __LINE__, $db-&gt;error());
    }

    // Delete any subscriptions for this topic
    $db-&gt;query(&#039;DELETE FROM &#039;.$db-&gt;prefix.&#039;subscriptions WHERE topic_id=&#039;.$topic_id) or error(&#039;Unable to delete subscriptions&#039;, __FILE__, __LINE__, $db-&gt;error());
}


//
// Delete a single post
//
function delete_post($post_id, $topic_id)
{
    global $db;

    $result = $db-&gt;query(&#039;SELECT id, poster, posted FROM &#039;.$db-&gt;prefix.&#039;posts WHERE topic_id=&#039;.$topic_id.&#039; ORDER BY id DESC LIMIT 2&#039;) or error(&#039;Unable to fetch post info&#039;, __FILE__, __LINE__, $db-&gt;error());
    list($last_id, ,) = $db-&gt;fetch_row($result);
    list($second_last_id, $second_poster, $second_posted) = $db-&gt;fetch_row($result);

    // Delete the post
    $db-&gt;query(&#039;DELETE FROM &#039;.$db-&gt;prefix.&#039;posts WHERE id=&#039;.$post_id) or error(&#039;Unable to delete post&#039;, __FILE__, __LINE__, $db-&gt;error());

    strip_search_index($post_id);

    // Count number of replies in the topic
    $result = $db-&gt;query(&#039;SELECT COUNT(id) FROM &#039;.$db-&gt;prefix.&#039;posts WHERE topic_id=&#039;.$topic_id) or error(&#039;Unable to fetch post count for topic&#039;, __FILE__, __LINE__, $db-&gt;error());
    $num_replies = $db-&gt;result($result, 0) - 1;

    // If the message we deleted is the most recent in the topic (at the end of the topic)
    if ($last_id == $post_id)
    {
        // If there is a $second_last_id there is more than 1 reply to the topic
        if (!empty($second_last_id))
            $db-&gt;query(&#039;UPDATE &#039;.$db-&gt;prefix.&#039;topics SET last_post=&#039;.$second_posted.&#039;, last_post_id=&#039;.$second_last_id.&#039;, last_poster=\&#039;&#039;.$db-&gt;escape($second_poster).&#039;\&#039;, num_replies=&#039;.$num_replies.&#039; WHERE id=&#039;.$topic_id) or error(&#039;Unable to update topic&#039;, __FILE__, __LINE__, $db-&gt;error());
        else
            // We deleted the only reply, so now last_post/last_post_id/last_poster is posted/id/poster from the topic itself
            $db-&gt;query(&#039;UPDATE &#039;.$db-&gt;prefix.&#039;topics SET last_post=posted, last_post_id=id, last_poster=poster, num_replies=&#039;.$num_replies.&#039; WHERE id=&#039;.$topic_id) or error(&#039;Unable to update topic&#039;, __FILE__, __LINE__, $db-&gt;error());
    }
    else
        // Otherwise we just decrement the reply counter
        $db-&gt;query(&#039;UPDATE &#039;.$db-&gt;prefix.&#039;topics SET num_replies=&#039;.$num_replies.&#039; WHERE id=&#039;.$topic_id) or error(&#039;Unable to update topic&#039;, __FILE__, __LINE__, $db-&gt;error());
}


//
// Replace censored words in $text
//
function censor_words($text)
{
    global $db;
    static $search_for, $replace_with;

    // If not already built in a previous call, build an array of censor words and their replacement text
    if (!isset($search_for))
    {
        $result = $db-&gt;query(&#039;SELECT search_for, replace_with FROM &#039;.$db-&gt;prefix.&#039;censoring&#039;) or error(&#039;Unable to fetch censor word list&#039;, __FILE__, __LINE__, $db-&gt;error());
        $num_words = $db-&gt;num_rows($result);

        $search_for = array();
        for ($i = 0; $i &lt; $num_words; ++$i)
        {
            list($search_for[$i], $replace_with[$i]) = $db-&gt;fetch_row($result);
            $search_for[$i] = &#039;/\b(&#039;.str_replace(&#039;\*&#039;, &#039;\w*?&#039;, preg_quote($search_for[$i], &#039;/&#039;)).&#039;)\b/i&#039;;
        }
    }

    if (!empty($search_for))
        $text = substr(preg_replace($search_for, $replace_with, &#039; &#039;.$text.&#039; &#039;), 1, -1);

    return $text;
}


//
// Determines the correct title for $user
// $user must contain the elements &#039;username&#039;, &#039;title&#039;, &#039;posts&#039;, &#039;g_id&#039; and &#039;g_user_title&#039;
//
function get_title($user)
{
    global $db, $pun_config, $pun_bans, $lang_common;
    static $ban_list, $pun_ranks;

    // If not already built in a previous call, build an array of lowercase banned usernames
    if (empty($ban_list))
    {
        $ban_list = array();

        foreach ($pun_bans as $cur_ban)
            $ban_list[] = strtolower($cur_ban[&#039;username&#039;]);
    }

    // If not already loaded in a previous call, load the cached ranks
    if ($pun_config[&#039;o_ranks&#039;] == &#039;1&#039; &amp;&amp; empty($pun_ranks))
    {
        @include PUN_ROOT.&#039;cache/cache_ranks.php&#039;;
        if (!defined(&#039;PUN_RANKS_LOADED&#039;))
        {
            require_once PUN_ROOT.&#039;include/cache.php&#039;;
            generate_ranks_cache();
            require PUN_ROOT.&#039;cache/cache_ranks.php&#039;;
        }
    }

    // If the user has a custom title
    if ($user[&#039;title&#039;] != &#039;&#039;)
        $user_title = pun_htmlspecialchars($user[&#039;title&#039;]);
    // If the user is banned
    else if (in_array(strtolower($user[&#039;username&#039;]), $ban_list))
        $user_title = $lang_common[&#039;Banned&#039;];
    // If the user group has a default user title
    else if ($user[&#039;g_user_title&#039;] != &#039;&#039;)
        $user_title = pun_htmlspecialchars($user[&#039;g_user_title&#039;]);
    // If the user is a guest
    else if ($user[&#039;g_id&#039;] == PUN_GUEST)
        $user_title = $lang_common[&#039;Guest&#039;];
    else
    {
        // Are there any ranks?
        if ($pun_config[&#039;o_ranks&#039;] == &#039;1&#039; &amp;&amp; !empty($pun_ranks))
        {
            @reset($pun_ranks);
            while (list(, $cur_rank) = @each($pun_ranks))
            {
                if (intval($user[&#039;num_posts&#039;]) &gt;= $cur_rank[&#039;min_posts&#039;])
                    $user_title = pun_htmlspecialchars($cur_rank[&#039;rank&#039;]);
            }
        }

        // If the user didn&#039;t &quot;reach&quot; any rank (or if ranks are disabled), we assign the default
        if (!isset($user_title))
            $user_title = $lang_common[&#039;Member&#039;];
    }

    return $user_title;
}


//
// Generate a string with numbered links (for multipage scripts)
//
function paginate($num_pages, $cur_page, $link_to)
{
    $pages = array();
    $link_to_all = false;

    // If $cur_page == -1, we link to all pages (used in viewforum.php)
    if ($cur_page == -1)
    {
        $cur_page = 1;
        $link_to_all = true;
    }

    if ($num_pages &lt;= 1)
        $pages = array(&#039;&lt;strong&gt;1&lt;/strong&gt;&#039;);
    else
    {
        if ($cur_page &gt; 3)
        {
            $pages[] = &#039;&lt;a href=&quot;&#039;.$link_to.&#039;&amp;amp;p=1&quot;&gt;1&lt;/a&gt;&#039;;

            if ($cur_page != 4)
                $pages[] = &#039;&amp;hellip;&#039;;
        }

        // Don&#039;t ask me how the following works. It just does, OK? :-)
        for ($current = $cur_page - 2, $stop = $cur_page + 3; $current &lt; $stop; ++$current)
        {
            if ($current &lt; 1 || $current &gt; $num_pages)
                continue;
            else if ($current != $cur_page || $link_to_all)
                $pages[] = &#039;&lt;a href=&quot;&#039;.$link_to.&#039;&amp;amp;p=&#039;.$current.&#039;&quot;&gt;&#039;.$current.&#039;&lt;/a&gt;&#039;;
            else
                $pages[] = &#039;&lt;strong&gt;&#039;.$current.&#039;&lt;/strong&gt;&#039;;
        }

        if ($cur_page &lt;= ($num_pages-3))
        {
            if ($cur_page != ($num_pages-3))
                $pages[] = &#039;&amp;hellip;&#039;;

            $pages[] = &#039;&lt;a href=&quot;&#039;.$link_to.&#039;&amp;amp;p=&#039;.$num_pages.&#039;&quot;&gt;&#039;.$num_pages.&#039;&lt;/a&gt;&#039;;
        }
    }

    return implode(&#039;&amp;nbsp;&#039;, $pages);
}


//
// Display a message
//
function message($message, $no_back_link = false)
{
    global $db, $lang_common, $pun_config, $pun_start, $tpl_main;

    if (!defined(&#039;PUN_HEADER&#039;))
    {
        global $pun_user;

        $page_title = pun_htmlspecialchars($pun_config[&#039;o_board_title&#039;]).&#039; / &#039;.$lang_common[&#039;Info&#039;];
        require PUN_ROOT.&#039;header.php&#039;;
    }

?&gt;

&lt;div id=&quot;msg&quot; class=&quot;block&quot;&gt;
    &lt;h2&gt;&lt;span&gt;&lt;?php echo $lang_common[&#039;Info&#039;] ?&gt;&lt;/span&gt;&lt;/h2&gt;
    &lt;div class=&quot;box&quot;&gt;
        &lt;div class=&quot;inbox&quot;&gt;
        &lt;p&gt;&lt;?php echo $message ?&gt;&lt;/p&gt;
&lt;?php if (!$no_back_link): ?&gt;        &lt;p&gt;&lt;a href=&quot;javascript: history.go(-1)&quot;&gt;&lt;?php echo $lang_common[&#039;Go back&#039;] ?&gt;&lt;/a&gt;&lt;/p&gt;
&lt;?php endif; ?&gt;        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;?php

    require PUN_ROOT.&#039;footer.php&#039;;
}


//
// Format a time string according to $time_format and timezones
//
function format_time($timestamp, $date_only = false)
{
    global $pun_config, $lang_common, $pun_user;

    if ($timestamp == &#039;&#039;)
        return $lang_common[&#039;Never&#039;];

    $diff = ($pun_user[&#039;timezone&#039;] - $pun_config[&#039;o_server_timezone&#039;]) * 3600;
    $timestamp += $diff;
    $now = time();

    $date = date($pun_config[&#039;o_date_format&#039;], $timestamp);
    $today = date($pun_config[&#039;o_date_format&#039;], $now+$diff);
    $yesterday = date($pun_config[&#039;o_date_format&#039;], $now+$diff-86400);

    if ($date == $today)
        $date = $lang_common[&#039;Today&#039;];
    else if ($date == $yesterday)
        $date = $lang_common[&#039;Yesterday&#039;];

    if (!$date_only)
        return $date.&#039; &#039;.date($pun_config[&#039;o_time_format&#039;], $timestamp);
    else
        return $date;
}


//
// If we are running pre PHP 4.3.0, we add our own implementation of file_get_contents
//
if (!function_exists(&#039;file_get_contents&#039;))
{
    function file_get_contents($filename, $use_include_path = 0)
    {
        $data = &#039;&#039;;

        if ($fh = fopen($filename, &#039;rb&#039;, $use_include_path))
        {
            $data = fread($fh, filesize($filename));
            fclose($fh);
        }

        return $data;
    }
}


//
// Make sure that HTTP_REFERER matches $pun_config[&#039;o_base_url&#039;]/$script
//
function confirm_referrer($script)
{
    global $pun_config, $lang_common;

    if (!preg_match(&#039;#^&#039;.preg_quote(str_replace(&#039;www.&#039;, &#039;&#039;, $pun_config[&#039;o_base_url&#039;]).&#039;/&#039;.$script, &#039;#&#039;).&#039;#i&#039;, str_replace(&#039;www.&#039;, &#039;&#039;, (isset($_SERVER[&#039;HTTP_REFERER&#039;]) ? $_SERVER[&#039;HTTP_REFERER&#039;] : &#039;&#039;))))
        message($lang_common[&#039;Bad referrer&#039;]);
}


//
// Generate a random password of length $len
//
function random_pass($len)
{
    $chars = &#039;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&#039;;

    $password = &#039;&#039;;
    for ($i = 0; $i &lt; $len; ++$i)
        $password .= substr($chars, (mt_rand() % strlen($chars)), 1);

    return $password;
}


//
// Compute a hash of $str
// Uses sha1() if available. If not, SHA1 through mhash() if available. If not, fall back on md5().
//
function pun_hash($str)
{
    if (function_exists(&#039;sha1&#039;))    // Only in PHP 4.3.0+
        return sha1($str);
    else if (function_exists(&#039;mhash&#039;))    // Only if Mhash library is loaded
        return bin2hex(mhash(MHASH_SHA1, $str));
    else
        return md5($str);
}


//
// Try to determine the correct remote IP-address
//
function get_remote_address()
{
    return $_SERVER[&#039;REMOTE_ADDR&#039;];
}


//
// Equivalent to htmlspecialchars(), but allows &amp;#[0-9]+ (for unicode)
//
function pun_htmlspecialchars($str)
{
    $str = preg_replace(&#039;/&amp;(?!#[0-9]+;)/s&#039;, &#039;&amp;amp;&#039;, $str);
    $str = str_replace(array(&#039;&lt;&#039;, &#039;&gt;&#039;, &#039;&quot;&#039;), array(&#039;&amp;lt;&#039;, &#039;&amp;gt;&#039;, &#039;&amp;quot;&#039;), $str);

    return $str;
}


//
// Equivalent to strlen(), but counts &amp;#[0-9]+ as one character (for unicode)
//
function pun_strlen($str)
{
    return strlen(preg_replace(&#039;/&amp;#([0-9]+);/&#039;, &#039;!&#039;, $str));
}


//
// Convert \r\n and \r to \n
//
function pun_linebreaks($str)
{
    return str_replace(&quot;\r&quot;, &quot;\n&quot;, str_replace(&quot;\r\n&quot;, &quot;\n&quot;, $str));
}


//
// A more aggressive version of trim()
//
function pun_trim($str)
{
    global $lang_common;

    if (strpos($lang_common[&#039;lang_encoding&#039;], &#039;8859&#039;) !== false)
    {
        $fishy_chars = array(chr(0x81), chr(0x8D), chr(0x8F), chr(0x90), chr(0x9D), chr(0xA0));
        return trim(str_replace($fishy_chars, &#039; &#039;, $str));
    }
    else
        return trim($str);
}


//
// Display a message when board is in maintenance mode
//
function maintenance_message()
{
    global $db, $pun_config, $lang_common, $pun_user;

    // Deal with newlines, tabs and multiple spaces
    $pattern = array(&quot;\t&quot;, &#039;  &#039;, &#039;  &#039;);
    $replace = array(&#039;&amp;nbsp; &amp;nbsp; &#039;, &#039;&amp;nbsp; &#039;, &#039; &amp;nbsp;&#039;);
    $message = str_replace($pattern, $replace, $pun_config[&#039;o_maintenance_message&#039;]);


    // Load the maintenance template
    $tpl_maint = trim(file_get_contents(PUN_ROOT.&#039;include/template/maintenance.tpl&#039;));


    // START SUBST - &lt;pun_include &quot;*&quot;&gt;
    while (preg_match(&#039;#&lt;pun_include &quot;([^/\\\\]*?)\.(php[45]?|inc|html?|txt)&quot;&gt;#&#039;, $tpl_maint, $cur_include))
    {
        if (!file_exists(PUN_ROOT.&#039;include/user/&#039;.$cur_include[1].&#039;.&#039;.$cur_include[2]))
            error(&#039;Unable to process user include &#039;.htmlspecialchars($cur_include[0]).&#039; from template maintenance.tpl. There is no such file in folder /include/user/&#039;);

        ob_start();
        include PUN_ROOT.&#039;include/user/&#039;.$cur_include[1].&#039;.&#039;.$cur_include[2];
        $tpl_temp = ob_get_contents();
        $tpl_maint = str_replace($cur_include[0], $tpl_temp, $tpl_maint);
        ob_end_clean();
    }
    // END SUBST - &lt;pun_include &quot;*&quot;&gt;


    // START SUBST - &lt;pun_content_direction&gt;
    $tpl_maint = str_replace(&#039;&lt;pun_content_direction&gt;&#039;, $lang_common[&#039;lang_direction&#039;], $tpl_maint);
    // END SUBST - &lt;pun_content_direction&gt;


    // START SUBST - &lt;pun_char_encoding&gt;
    $tpl_maint = str_replace(&#039;&lt;pun_char_encoding&gt;&#039;, $lang_common[&#039;lang_encoding&#039;], $tpl_maint);
    // END SUBST - &lt;pun_char_encoding&gt;


    // START SUBST - &lt;pun_head&gt;
    ob_start();

?&gt;
&lt;title&gt;&lt;?php echo pun_htmlspecialchars($pun_config[&#039;o_board_title&#039;]).&#039; / &#039;.$lang_common[&#039;Maintenance&#039;] ?&gt;&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style/&lt;?php echo $pun_user[&#039;style&#039;].&#039;.css&#039; ?&gt;&quot; /&gt;
&lt;?php

    $tpl_temp = trim(ob_get_contents());
    $tpl_maint = str_replace(&#039;&lt;pun_head&gt;&#039;, $tpl_temp, $tpl_maint);
    ob_end_clean();
    // END SUBST - &lt;pun_head&gt;


    // START SUBST - &lt;pun_maint_heading&gt;
    $tpl_maint = str_replace(&#039;&lt;pun_maint_heading&gt;&#039;, $lang_common[&#039;Maintenance&#039;], $tpl_maint);
    // END SUBST - &lt;pun_maint_heading&gt;


    // START SUBST - &lt;pun_maint_message&gt;
    $tpl_maint = str_replace(&#039;&lt;pun_maint_message&gt;&#039;, $message, $tpl_maint);
    // END SUBST - &lt;pun_maint_message&gt;


    // End the transaction
    $db-&gt;end_transaction();


    // Close the db connection (and free up any result data)
    $db-&gt;close();

    exit($tpl_maint);
}


//
// Display $message and redirect user to $destination_url
//
function redirect($destination_url, $message)
{
    global $db, $pun_config, $lang_common, $pun_user;

    // Prefix with o_base_url (unless there&#039;s already a valid URI)
    if (strpos($destination_url, &#039;http://&#039;) !== 0 &amp;&amp; strpos($destination_url, &#039;https://&#039;) !== 0 &amp;&amp; strpos($destination_url, &#039;/&#039;) !== 0)
        $destination_url = $pun_config[&#039;o_base_url&#039;].&#039;/&#039;.$destination_url;

    // Do a little spring cleaning
    $destination_url = preg_replace(&#039;/([\r\n])|(%0[ad])|(;[\s]*data[\s]*:)/i&#039;, &#039;&#039;, $destination_url);

    // If the delay is 0 seconds, we might as well skip the redirect all together
    if ($pun_config[&#039;o_redirect_delay&#039;] == &#039;0&#039;)
        header(&#039;Location: &#039;.str_replace(&#039;&amp;amp;&#039;, &#039;&amp;&#039;, $destination_url));


    // Load the redirect template
    $tpl_redir = trim(file_get_contents(PUN_ROOT.&#039;include/template/redirect.tpl&#039;));


    // START SUBST - &lt;pun_include &quot;*&quot;&gt;
    while (preg_match(&#039;#&lt;pun_include &quot;([^/\\\\]*?)\.(php[45]?|inc|html?|txt)&quot;&gt;#&#039;, $tpl_redir, $cur_include))
    {
        if (!file_exists(PUN_ROOT.&#039;include/user/&#039;.$cur_include[1].&#039;.&#039;.$cur_include[2]))
            error(&#039;Unable to process user include &#039;.htmlspecialchars($cur_include[0]).&#039; from template redirect.tpl. There is no such file in folder /include/user/&#039;);

        ob_start();
        include PUN_ROOT.&#039;include/user/&#039;.$cur_include[1].&#039;.&#039;.$cur_include[2];
        $tpl_temp = ob_get_contents();
        $tpl_redir = str_replace($cur_include[0], $tpl_temp, $tpl_redir);
        ob_end_clean();
    }
    // END SUBST - &lt;pun_include &quot;*&quot;&gt;


    // START SUBST - &lt;pun_content_direction&gt;
    $tpl_redir = str_replace(&#039;&lt;pun_content_direction&gt;&#039;, $lang_common[&#039;lang_direction&#039;], $tpl_redir);
    // END SUBST - &lt;pun_content_direction&gt;


    // START SUBST - &lt;pun_char_encoding&gt;
    $tpl_redir = str_replace(&#039;&lt;pun_char_encoding&gt;&#039;, $lang_common[&#039;lang_encoding&#039;], $tpl_redir);
    // END SUBST - &lt;pun_char_encoding&gt;


    // START SUBST - &lt;pun_head&gt;
    ob_start();

?&gt;
&lt;meta http-equiv=&quot;refresh&quot; content=&quot;&lt;?php echo $pun_config[&#039;o_redirect_delay&#039;] ?&gt;;URL=&lt;?php echo str_replace(array(&#039;&lt;&#039;, &#039;&gt;&#039;, &#039;&quot;&#039;), array(&#039;&amp;lt;&#039;, &#039;&amp;gt;&#039;, &#039;&amp;quot;&#039;), $destination_url) ?&gt;&quot; /&gt;
&lt;title&gt;&lt;?php echo pun_htmlspecialchars($pun_config[&#039;o_board_title&#039;]).&#039; / &#039;.$lang_common[&#039;Redirecting&#039;] ?&gt;&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style/&lt;?php echo $pun_user[&#039;style&#039;].&#039;.css&#039; ?&gt;&quot; /&gt;
&lt;?php

    $tpl_temp = trim(ob_get_contents());
    $tpl_redir = str_replace(&#039;&lt;pun_head&gt;&#039;, $tpl_temp, $tpl_redir);
    ob_end_clean();
    // END SUBST - &lt;pun_head&gt;


    // START SUBST - &lt;pun_redir_heading&gt;
    $tpl_redir = str_replace(&#039;&lt;pun_redir_heading&gt;&#039;, $lang_common[&#039;Redirecting&#039;], $tpl_redir);
    // END SUBST - &lt;pun_redir_heading&gt;


    // START SUBST - &lt;pun_redir_text&gt;
    $tpl_temp = $message.&#039;&lt;br /&gt;&lt;br /&gt;&#039;.&#039;&lt;a href=&quot;&#039;.$destination_url.&#039;&quot;&gt;&#039;.$lang_common[&#039;Click redirect&#039;].&#039;&lt;/a&gt;&#039;;
    $tpl_redir = str_replace(&#039;&lt;pun_redir_text&gt;&#039;, $tpl_temp, $tpl_redir);
    // END SUBST - &lt;pun_redir_text&gt;


    // START SUBST - &lt;pun_footer&gt;
    ob_start();

    // End the transaction
    $db-&gt;end_transaction();

    // Display executed queries (if enabled)
    if (defined(&#039;PUN_SHOW_QUERIES&#039;))
        display_saved_queries();

    $tpl_temp = trim(ob_get_contents());
    $tpl_redir = str_replace(&#039;&lt;pun_footer&gt;&#039;, $tpl_temp, $tpl_redir);
    ob_end_clean();
    // END SUBST - &lt;pun_footer&gt;


    // Close the db connection (and free up any result data)
    $db-&gt;close();

    exit($tpl_redir);
}


//
// Display a simple error message
//
function error($message, $file, $line, $db_error = false)
{
    global $pun_config;

    // Set a default title if the script failed before $pun_config could be populated
    if (empty($pun_config))
        $pun_config[&#039;o_board_title&#039;] = &#039;PunBB&#039;;

    // Empty output buffer and stop buffering
    @ob_end_clean();

    // &quot;Restart&quot; output buffering if we are using ob_gzhandler (since the gzip header is already sent)
    if (!empty($pun_config[&#039;o_gzip&#039;]) &amp;&amp; extension_loaded(&#039;zlib&#039;) &amp;&amp; (strpos($_SERVER[&#039;HTTP_ACCEPT_ENCODING&#039;], &#039;gzip&#039;) !== false || strpos($_SERVER[&#039;HTTP_ACCEPT_ENCODING&#039;], &#039;deflate&#039;) !== false))
        ob_start(&#039;ob_gzhandler&#039;);

?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; dir=&quot;ltr&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
&lt;title&gt;&lt;?php echo pun_htmlspecialchars($pun_config[&#039;o_board_title&#039;]) ?&gt; / Error&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
&lt;!--
BODY {MARGIN: 10% 20% auto 20%; font: 10px Verdana, Arial, Helvetica, sans-serif}
#errorbox {BORDER: 1px solid #B84623}
H2 {MARGIN: 0; COLOR: #FFFFFF; BACKGROUND-COLOR: #B84623; FONT-SIZE: 1.1em; PADDING: 5px 4px}
#errorbox DIV {PADDING: 6px 5px; BACKGROUND-COLOR: #F1F1F1}
--&gt;
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id=&quot;errorbox&quot;&gt;
    &lt;h2&gt;An error was encountered&lt;/h2&gt;
    &lt;div&gt;
&lt;?php

    if (defined(&#039;PUN_DEBUG&#039;))
    {
        echo &quot;\t\t&quot;.&#039;&lt;strong&gt;File:&lt;/strong&gt; &#039;.$file.&#039;&lt;br /&gt;&#039;.&quot;\n\t\t&quot;.&#039;&lt;strong&gt;Line:&lt;/strong&gt; &#039;.$line.&#039;&lt;br /&gt;&lt;br /&gt;&#039;.&quot;\n\t\t&quot;.&#039;&lt;strong&gt;PunBB reported&lt;/strong&gt;: &#039;.$message.&quot;\n&quot;;

        if ($db_error)
        {
            echo &quot;\t\t&quot;.&#039;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Database reported:&lt;/strong&gt; &#039;.pun_htmlspecialchars($db_error[&#039;error_msg&#039;]).(($db_error[&#039;error_no&#039;]) ? &#039; (Errno: &#039;.$db_error[&#039;error_no&#039;].&#039;)&#039; : &#039;&#039;).&quot;\n&quot;;

            if ($db_error[&#039;error_sql&#039;] != &#039;&#039;)
                echo &quot;\t\t&quot;.&#039;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Failed query:&lt;/strong&gt; &#039;.pun_htmlspecialchars($db_error[&#039;error_sql&#039;]).&quot;\n&quot;;
        }
    }
    else
        echo &quot;\t\t&quot;.&#039;Error: &lt;strong&gt;&#039;.$message.&#039;.&lt;/strong&gt;&#039;.&quot;\n&quot;;

?&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
&lt;?php

    // If a database connection was established (before this error) we close it
    if ($db_error)
        $GLOBALS[&#039;db&#039;]-&gt;close();

    exit;
}

// DEBUG FUNCTIONS BELOW

//
// Display executed queries (if enabled)
//
function display_saved_queries()
{
    global $db, $lang_common;

    // Get the queries so that we can print them out
    $saved_queries = $db-&gt;get_saved_queries();

?&gt;

&lt;div id=&quot;debug&quot; class=&quot;blocktable&quot;&gt;
    &lt;h2&gt;&lt;span&gt;&lt;?php echo $lang_common[&#039;Debug table&#039;] ?&gt;&lt;/span&gt;&lt;/h2&gt;
    &lt;div class=&quot;box&quot;&gt;
        &lt;div class=&quot;inbox&quot;&gt;
            &lt;table cellspacing=&quot;0&quot;&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                    &lt;th class=&quot;tcl&quot; scope=&quot;col&quot;&gt;Time (s)&lt;/th&gt;
                    &lt;th class=&quot;tcr&quot; scope=&quot;col&quot;&gt;Query&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
&lt;?php

    $query_time_total = 0.0;
    while (list(, $cur_query) = @each($saved_queries))
    {
        $query_time_total += $cur_query[1];

?&gt;
                &lt;tr&gt;
                    &lt;td class=&quot;tcl&quot;&gt;&lt;?php echo ($cur_query[1] != 0) ? $cur_query[1] : &#039;&amp;nbsp;&#039; ?&gt;&lt;/td&gt;
                    &lt;td class=&quot;tcr&quot;&gt;&lt;?php echo pun_htmlspecialchars($cur_query[0]) ?&gt;&lt;/td&gt;
                &lt;/tr&gt;
&lt;?php

    }

?&gt;
                &lt;tr&gt;
                    &lt;td class=&quot;tcl&quot; colspan=&quot;2&quot;&gt;Total query time: &lt;?php echo $query_time_total ?&gt; s&lt;/td&gt;
                &lt;/tr&gt;
            &lt;/tbody&gt;
            &lt;/table&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;?php

}


//
// Unset any variables instantiated as a result of register_globals being enabled
//
function unregister_globals()
{
    $register_globals = @ini_get(&#039;register_globals&#039;);
    if ($register_globals === &quot;&quot; || $register_globals === &quot;0&quot; || strtolower($register_globals) === &quot;off&quot;)
        return;

    // Prevent script.php?GLOBALS[foo]=bar
    if (isset($_REQUEST[&#039;GLOBALS&#039;]) || isset($_FILES[&#039;GLOBALS&#039;]))
        exit(&#039;I\&#039;ll have a steak sandwich and... a steak sandwich.&#039;);
    
    // Variables that shouldn&#039;t be unset
    $no_unset = array(&#039;GLOBALS&#039;, &#039;_GET&#039;, &#039;_POST&#039;, &#039;_COOKIE&#039;, &#039;_REQUEST&#039;, &#039;_SERVER&#039;, &#039;_ENV&#039;, &#039;_FILES&#039;);

    // Remove elements in $GLOBALS that are present in any of the superglobals
    $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) &amp;&amp; is_array($_SESSION) ? $_SESSION : array());
    foreach ($input as $k =&gt; $v)
    {
        if (!in_array($k, $no_unset) &amp;&amp; isset($GLOBALS[$k]))
        {
            unset($GLOBALS[$k]);
            unset($GLOBALS[$k]);    // Double unset to circumvent the zend_hash_del_key_or_index hole in PHP &lt;4.4.3 and &lt;5.1.4
        }
    }
}


//
// Dump contents of variable(s)
//
function dump()
{
    echo &#039;&lt;pre&gt;&#039;;

    $num_args = func_num_args();

    for ($i = 0; $i &lt; $num_args; ++$i)
    {
        print_r(func_get_arg($i));
        echo &quot;\n\n&quot;;
    }

    echo &#039;&lt;/pre&gt;&#039;;
    exit;
}</code></pre></div><p>hope someone can help me. i just new in punbb <img src="https://punbb.informer.com/forums/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[null@example.com (MCommunity)]]></author>
			<pubDate>Tue, 25 Aug 2009 15:00:40 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/129954/#p129954</guid>
		</item>
	</channel>
</rss>
