Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/functions.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions.php 9153 2008-12-02 17:02:56Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    7272        }
    7373
    74         if (!isset($_REQUEST[$var_name]) || (is_array($_REQUEST[$var_name]) && !is_array($default)) || (is_array($default) && !is_array($_REQUEST[$var_name])))
     74        $super_global = ($cookie) ? '_COOKIE' : '_REQUEST';
     75        if (!isset($GLOBALS[$super_global][$var_name]) || is_array($GLOBALS[$super_global][$var_name]) != is_array($default))
    7576        {
    7677                return (is_array($default)) ? array() : $default;
    7778        }
    7879
    79         $var = $_REQUEST[$var_name];
     80        $var = $GLOBALS[$super_global][$var_name];
    8081        if (!is_array($default))
    8182        {
     
    166167
    167168/**
     169* Set dynamic config value with arithmetic operation.
     170*/
     171function set_config_count($config_name, $increment, $is_dynamic = false)
     172{
     173        global $db, $cache;
     174
     175        switch ($db->sql_layer)
     176        {
     177                case 'firebird':
     178                        $sql_update = 'CAST(CAST(config_value as integer) + ' . (int) $increment . ' as VARCHAR(255))';
     179                break;
     180
     181                case 'postgres':
     182                        $sql_update = 'int4(config_value) + ' . (int) $increment;
     183                break;
     184
     185                // MySQL, SQlite, mssql, mssql_odbc, oracle
     186                default:
     187                        $sql_update = 'config_value + ' . (int) $increment;
     188                break;
     189        }
     190
     191        $db->sql_query('UPDATE ' . CONFIG_TABLE . ' SET config_value = ' . $sql_update . " WHERE config_name = '" . $db->sql_escape($config_name) . "'");
     192
     193        if (!$is_dynamic)
     194        {
     195                $cache->destroy('config');
     196        }
     197}
     198
     199/**
    168200* Generates an alphanumeric random string of given length
    169201*/
     
    201233/**
    202234* Return formatted string for filesizes
    203 */
    204 function get_formatted_filesize($bytes, $add_size_lang = true)
     235*
     236* @param int    $value                  filesize in bytes
     237* @param bool   $string_only    true if language string should be returned
     238* @param array  $allowed_units  only allow these units (data array indexes)
     239*
     240* @return mixed                                 data array if $string_only is false
     241* @author bantu
     242*/
     243function get_formatted_filesize($value, $string_only = true, $allowed_units = false)
    205244{
    206245        global $user;
    207246
    208         if ($bytes >= pow(2, 20))
    209         {
    210                 return ($add_size_lang) ? round($bytes / 1024 / 1024, 2) . ' ' . $user->lang['MIB'] : round($bytes / 1024 / 1024, 2);
    211         }
    212 
    213         if ($bytes >= pow(2, 10))
    214         {
    215                 return ($add_size_lang) ? round($bytes / 1024, 2) . ' ' . $user->lang['KIB'] : round($bytes / 1024, 2);
    216         }
    217 
    218         return ($add_size_lang) ? ($bytes) . ' ' . $user->lang['BYTES'] : ($bytes);
     247        $available_units = array(
     248                'gb' => array(
     249                        'min'           => 1073741824, // pow(2, 30)
     250                        'index'         => 3,
     251                        'si_unit'       => 'GB',
     252                        'iec_unit'      => 'GIB',
     253                ),
     254                'mb' => array(
     255                        'min'           => 1048576, // pow(2, 20)
     256                        'index'         => 2,
     257                        'si_unit'       => 'MB',
     258                        'iec_unit'      => 'MIB',
     259                ),
     260                'kb' => array(
     261                        'min'           => 1024, // pow(2, 10)
     262                        'index'         => 1,
     263                        'si_unit'       => 'KB',
     264                        'iec_unit'      => 'KIB',
     265                ),
     266                'b' => array(
     267                        'min'           => 0,
     268                        'index'         => 0,
     269                        'si_unit'       => 'BYTES', // Language index
     270                        'iec_unit'      => 'BYTES',  // Language index
     271                ),
     272        );
     273
     274        foreach ($available_units as $si_identifier => $unit_info)
     275        {
     276                if (!empty($allowed_units) && $si_identifier != 'b' && !in_array($si_identifier, $allowed_units))
     277                {
     278                        continue;
     279                }
     280
     281                if ($value >= $unit_info['min'])
     282                {
     283                        $unit_info['si_identifier'] = $si_identifier;
     284
     285                        break;
     286                }
     287        }
     288        unset($available_units);
     289
     290        for ($i = 0; $i < $unit_info['index']; $i++)
     291        {
     292                $value /= 1024;
     293        }
     294        $value = round($value, 2);
     295
     296        // Lookup units in language dictionary
     297        $unit_info['si_unit'] = (isset($user->lang[$unit_info['si_unit']])) ? $user->lang[$unit_info['si_unit']] : $unit_info['si_unit'];
     298        $unit_info['iec_unit'] = (isset($user->lang[$unit_info['iec_unit']])) ? $user->lang[$unit_info['iec_unit']] : $unit_info['iec_unit'];
     299
     300        // Default to IEC
     301        $unit_info['unit'] = $unit_info['iec_unit'];
     302
     303        if (!$string_only)
     304        {
     305                $unit_info['value'] = $value;
     306
     307                return $unit_info;
     308        }
     309
     310        return $value  . ' ' . $unit_info['unit'];
    219311}
    220312
     
    461553
    462554/**
     555* Hashes an email address to a big integer
     556*
     557* @param string $email          Email address
     558*
     559* @return string                        Unsigned Big Integer
     560*/
     561function phpbb_email_hash($email)
     562{
     563        return sprintf('%u', crc32(strtolower($email))) . strlen($email);
     564}
     565
     566/**
    463567* Global function for chmodding directories and files for internal use
     568*
    464569* This function determines owner and group whom the file belongs to and user and group of PHP and then set safest possible file permissions.
    465 * The function determines owner and group from common.php file and sets the same to the provided file. Permissions are mapped to the group, user always has rw(x) permission.
     570* The function determines owner and group from common.php file and sets the same to the provided file.
    466571* The function uses bit fields to build the permissions.
    467572* The function sets the appropiate execute bit on directories.
     
    476581* NOTE: The function uses POSIX extension and fileowner()/filegroup() functions. If any of them is disabled, this function tries to build proper permissions, by calling is_readable() and is_writable() functions.
    477582*
    478 * @param $filename The file/directory to be chmodded
    479 * @param $perms Permissions to set
    480 * @return true on success, otherwise false
    481 *
     583* @param string $filename       The file/directory to be chmodded
     584* @param int    $perms          Permissions to set
     585*
     586* @return bool  true on success, otherwise false
    482587* @author faw, phpBB Group
    483588*/
    484589function phpbb_chmod($filename, $perms = CHMOD_READ)
    485590{
     591        static $_chmod_info;
     592
    486593        // Return if the file no longer exists.
    487594        if (!file_exists($filename))
     
    490597        }
    491598
    492         if (!function_exists('fileowner') || !function_exists('filegroup'))
    493         {
    494                 $file_uid = $file_gid = false;
    495                 $common_php_owner = $common_php_group = false;
    496         }
    497         else
    498         {
    499                 global $phpbb_root_path, $phpEx;
    500 
    501                 // Determine owner/group of common.php file and the filename we want to change here
    502                 $common_php_owner = fileowner($phpbb_root_path . 'common.' . $phpEx);
    503                 $common_php_group = filegroup($phpbb_root_path . 'common.' . $phpEx);
    504 
    505                 $file_uid = fileowner($filename);
    506                 $file_gid = filegroup($filename);
    507 
    508                 // Try to set the owner to the same common.php has
    509                 if ($common_php_owner !== $file_uid && $common_php_owner !== false && $file_uid !== false)
    510                 {
    511                         // Will most likely not work
    512                         if (@chown($filename, $common_php_owner));
    513                         {
    514                                 clearstatcache();
    515                                 $file_uid = fileowner($filename);
    516                         }
    517                 }
    518 
    519                 // Try to set the group to the same common.php has
    520                 if ($common_php_group !== $file_gid && $common_php_group !== false && $file_gid !== false)
    521                 {
    522                         if (@chgrp($filename, $common_php_group));
    523                         {
    524                                 clearstatcache();
    525                                 $file_gid = filegroup($filename);
    526                         }
    527                 }
    528         }
    529 
    530         // And the owner and the groups PHP is running under.
    531         $php_uid = (function_exists('posix_getuid')) ? @posix_getuid() : false;
    532         $php_gids = (function_exists('posix_getgroups')) ? @posix_getgroups() : false;
    533 
    534         // Who is PHP?
    535         if ($file_uid === false || $file_gid === false || $php_uid === false || $php_gids === false)
    536         {
    537                 $php = NULL;
    538         }
    539         else if ($file_uid == $php_uid /* && $common_php_owner !== false && $common_php_owner === $file_uid*/)
    540         {
    541                 $php = 'owner';
    542         }
    543         else if (in_array($file_gid, $php_gids))
    544         {
    545                 $php = 'group';
    546         }
    547         else
     599        // Determine some common vars
     600        if (empty($_chmod_info))
     601        {
     602                if (!function_exists('fileowner') || !function_exists('filegroup'))
     603                {
     604                        // No need to further determine owner/group - it is unknown
     605                        $_chmod_info['process'] = false;
     606                }
     607                else
     608                {
     609                        global $phpbb_root_path, $phpEx;
     610
     611                        // Determine owner/group of common.php file and the filename we want to change here
     612                        $common_php_owner = @fileowner($phpbb_root_path . 'common.' . $phpEx);
     613                        $common_php_group = @filegroup($phpbb_root_path . 'common.' . $phpEx);
     614
     615                        // And the owner and the groups PHP is running under.
     616                        $php_uid = (function_exists('posix_getuid')) ? @posix_getuid() : false;
     617                        $php_gids = (function_exists('posix_getgroups')) ? @posix_getgroups() : false;
     618
     619                        // If we are unable to get owner/group, then do not try to set them by guessing
     620                        if (!$php_uid || empty($php_gids) || !$common_php_owner || !$common_php_group)
     621                        {
     622                                $_chmod_info['process'] = false;
     623                        }
     624                        else
     625                        {
     626                                $_chmod_info = array(
     627                                        'process'               => true,
     628                                        'common_owner'  => $common_php_owner,
     629                                        'common_group'  => $common_php_group,
     630                                        'php_uid'               => $php_uid,
     631                                        'php_gids'              => $php_gids,
     632                                );
     633                        }
     634                }
     635        }
     636
     637        if ($_chmod_info['process'])
     638        {
     639                $file_uid = @fileowner($filename);
     640                $file_gid = @filegroup($filename);
     641
     642                // Change owner
     643                if (@chown($filename, $_chmod_info['common_owner']))
     644                {
     645                        clearstatcache();
     646                        $file_uid = @fileowner($filename);
     647                }
     648
     649                // Change group
     650                if (@chgrp($filename, $_chmod_info['common_group']))
     651                {
     652                        clearstatcache();
     653                        $file_gid = @filegroup($filename);
     654                }
     655
     656                // If the file_uid/gid now match the one from common.php we can process further, else we are not able to change something
     657                if ($file_uid != $_chmod_info['common_owner'] || $file_gid != $_chmod_info['common_group'])
     658                {
     659                        $_chmod_info['process'] = false;
     660                }
     661        }
     662
     663        // Still able to process?
     664        if ($_chmod_info['process'])
     665        {
     666                if ($file_uid == $_chmod_info['php_uid'])
     667                {
     668                        $php = 'owner';
     669                }
     670                else if (in_array($file_gid, $_chmod_info['php_gids']))
     671                {
     672                        $php = 'group';
     673                }
     674                else
     675                {
     676                        // Since we are setting the everyone bit anyway, no need to do expensive operations
     677                        $_chmod_info['process'] = false;
     678                }
     679        }
     680
     681        // We are not able to determine or change something
     682        if (!$_chmod_info['process'])
    548683        {
    549684                $php = 'other';
     
    565700        switch ($php)
    566701        {
    567                 case null:
    568702                case 'owner':
    569                         /* ATTENTION: if php is owner or NULL we set it to group here. This is the most failsafe combination for the vast majority of server setups.
    570 
    571703                        $result = @chmod($filename, ($owner << 6) + (0 << 3) + (0 << 0));
    572704
    573705                        clearstatcache();
    574706
    575                         if (!is_null($php) || (is_readable($filename) && is_writable($filename)))
     707                        if (is_readable($filename) && is_writable($filename))
    576708                        {
    577709                                break;
    578710                        }
    579                 */
    580711
    581712                case 'group':
     
    584715                        clearstatcache();
    585716
    586                         if (!is_null($php) || ((!($perms & CHMOD_READ) || is_readable($filename)) && (!($perms & CHMOD_WRITE) || is_writable($filename))))
     717                        if ((!($perms & CHMOD_READ) || is_readable($filename)) && (!($perms & CHMOD_WRITE) || is_writable($filename)))
    587718                        {
    588719                                break;
     
    594725                        clearstatcache();
    595726
    596                         if (!is_null($php) || ((!($perms & CHMOD_READ) || is_readable($filename)) && (!($perms & CHMOD_WRITE) || is_writable($filename))))
     727                        if ((!($perms & CHMOD_READ) || is_readable($filename)) && (!($perms & CHMOD_WRITE) || is_writable($filename)))
    597728                        {
    598729                                break;
     
    605736
    606737        return $result;
     738}
     739
     740/**
     741* Test if a file/directory is writable
     742*
     743* This function calls the native is_writable() when not running under
     744* Windows and it is not disabled.
     745*
     746* @param string $file Path to perform write test on
     747* @return bool True when the path is writable, otherwise false.
     748*/
     749function phpbb_is_writable($file)
     750{
     751        if (strtolower(substr(PHP_OS, 0, 3)) === 'win' || !function_exists('is_writable'))
     752        {
     753                if (file_exists($file))
     754                {
     755                        // Canonicalise path to absolute path
     756                        $file = phpbb_realpath($file);
     757
     758                        if (is_dir($file))
     759                        {
     760                                // Test directory by creating a file inside the directory
     761                                $result = @tempnam($file, 'i_w');
     762
     763                                if (is_string($result) && file_exists($result))
     764                                {
     765                                        unlink($result);
     766
     767                                        // Ensure the file is actually in the directory (returned realpathed)
     768                                        return (strpos($result, $file) === 0) ? true : false;
     769                                }
     770                        }
     771                        else
     772                        {
     773                                $handle = @fopen($file, 'r+');
     774
     775                                if (is_resource($handle))
     776                                {
     777                                        fclose($handle);
     778                                        return true;
     779                                }
     780                        }
     781                }
     782                else
     783                {
     784                        // file does not exist test if we can write to the directory
     785                        $dir = dirname($file);
     786
     787                        if (file_exists($dir) && is_dir($dir) && phpbb_is_writable($dir))
     788                        {
     789                                return true;
     790                        }
     791                }
     792
     793                return false;
     794        }
     795        else
     796        {
     797                return is_writable($file);
     798        }
    607799}
    608800
     
    704896function is_absolute($path)
    705897{
    706         return ($path[0] == '/' || (DIRECTORY_SEPARATOR == '\\' && preg_match('#^[a-z]:/#i', $path))) ? true : false;
     898        return ($path[0] == '/' || (DIRECTORY_SEPARATOR == '\\' && preg_match('#^[a-z]:[/\\\]#i', $path))) ? true : false;
    707899}
    708900
     
    9851177                {
    9861178                        $selected = ($offset == $default) ? ' selected="selected"' : '';
    987                         $tz_select .= '<option title="'.$zone.'" value="' . $offset . '"' . $selected . '>' . $zone_trunc . '</option>';
     1179                        $tz_select .= '<option title="' . $zone . '" value="' . $offset . '"' . $selected . '>' . $zone_trunc . '</option>';
    9881180                }
    9891181        }
     
    10481240
    10491241                // Add 0 to forums array to mark global announcements correctly
    1050                 $forum_id[] = 0;
     1242                // $forum_id[] = 0;
    10511243
    10521244                if ($config['load_db_lastread'] && $user->data['is_registered'])
     
    10661258                        while ($row = $db->sql_fetchrow($result))
    10671259                        {
    1068                                 $sql_update[] = $row['forum_id'];
     1260                                $sql_update[] = (int) $row['forum_id'];
    10691261                        }
    10701262                        $db->sql_freeresult($result);
     
    14631655
    14641656        return $last_read;
     1657}
     1658
     1659/**
     1660* Get list of unread topics
     1661*
     1662* @param int $user_id                   User ID (or false for current user)
     1663* @param string $sql_extra              Extra WHERE SQL statement
     1664* @param string $sql_sort               ORDER BY SQL sorting statement
     1665* @param string $sql_limit              Limits the size of unread topics list, 0 for unlimited query
     1666*
     1667* @return array[int][int]               Topic ids as keys, mark_time of topic as value
     1668*/
     1669function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001)
     1670{
     1671        global $config, $db, $user;
     1672
     1673        $user_id = ($user_id === false) ? (int) $user->data['user_id'] : (int) $user_id;
     1674
     1675        // Data array we're going to return
     1676        $unread_topics = array();
     1677
     1678        if (empty($sql_sort))
     1679        {
     1680                $sql_sort = 'ORDER BY t.topic_last_post_time DESC';
     1681        }
     1682
     1683        if ($config['load_db_lastread'] && $user->data['is_registered'])
     1684        {
     1685                // Get list of the unread topics
     1686                $last_mark = $user->data['user_lastmark'];
     1687
     1688                $sql_array = array(
     1689                        'SELECT'                => 't.topic_id, t.topic_last_post_time, tt.mark_time as topic_mark_time, ft.mark_time as forum_mark_time',
     1690
     1691                        'FROM'                  => array(TOPICS_TABLE => 't'),
     1692
     1693                        'LEFT_JOIN'             => array(
     1694                                array(
     1695                                        'FROM'  => array(TOPICS_TRACK_TABLE => 'tt'),
     1696                                        'ON'    => "tt.user_id = $user_id AND t.topic_id = tt.topic_id",
     1697                                ),
     1698                                array(
     1699                                        'FROM'  => array(FORUMS_TRACK_TABLE => 'ft'),
     1700                                        'ON'    => "ft.user_id = $user_id AND t.forum_id = ft.forum_id",
     1701                                ),
     1702                        ),
     1703
     1704                        'WHERE'                 => "
     1705                                (
     1706                                (tt.mark_time IS NOT NULL AND t.topic_last_post_time > tt.mark_time) OR
     1707                                (tt.mark_time IS NULL AND ft.mark_time IS NOT NULL AND t.topic_last_post_time > ft.mark_time) OR
     1708                                (tt.mark_time IS NULL AND ft.mark_time IS NULL AND t.topic_last_post_time > $last_mark)
     1709                                )
     1710                                $sql_extra
     1711                                $sql_sort",
     1712                );
     1713
     1714                $sql = $db->sql_build_query('SELECT', $sql_array);
     1715                $result = $db->sql_query_limit($sql, $sql_limit);
     1716
     1717                while ($row = $db->sql_fetchrow($result))
     1718                {
     1719                        $topic_id = (int) $row['topic_id'];
     1720                        $unread_topics[$topic_id] = ($row['topic_mark_time']) ? (int) $row['topic_mark_time'] : (($row['forum_mark_time']) ? (int) $row['forum_mark_time'] : $last_mark);
     1721                }
     1722                $db->sql_freeresult($result);
     1723        }
     1724        else if ($config['load_anon_lastread'] || $user->data['is_registered'])
     1725        {
     1726                global $tracking_topics;
     1727
     1728                if (empty($tracking_topics))
     1729                {
     1730                        $tracking_topics = request_var($config['cookie_name'] . '_track', '', false, true);
     1731                        $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
     1732                }
     1733
     1734                if (!$user->data['is_registered'])
     1735                {
     1736                        $user_lastmark = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;
     1737                }
     1738                else
     1739                {
     1740                        $user_lastmark = (int) $user->data['user_lastmark'];
     1741                }
     1742
     1743                $sql = 'SELECT t.topic_id, t.forum_id, t.topic_last_post_time
     1744                        FROM ' . TOPICS_TABLE . ' t
     1745                        WHERE t.topic_last_post_time > ' . $user_lastmark . "
     1746                        $sql_extra
     1747                        $sql_sort";
     1748                $result = $db->sql_query_limit($sql, $sql_limit);
     1749
     1750                while ($row = $db->sql_fetchrow($result))
     1751                {
     1752                        $forum_id = (int) $row['forum_id'];
     1753                        $topic_id = (int) $row['topic_id'];
     1754                        $topic_id36 = base_convert($topic_id, 10, 36);
     1755
     1756                        if (isset($tracking_topics['t'][$topic_id36]))
     1757                        {
     1758                                $last_read = base_convert($tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate'];
     1759
     1760                                if ($row['topic_last_post_time'] > $last_read)
     1761                                {
     1762                                        $unread_topics[$topic_id] = $last_read;
     1763                                }
     1764                        }
     1765                        else if (isset($tracking_topics['f'][$forum_id]))
     1766                        {
     1767                                $mark_time = base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'];
     1768
     1769                                if ($row['topic_last_post_time'] > $mark_time)
     1770                                {
     1771                                        $unread_topics[$topic_id] = $mark_time;
     1772                                }
     1773                        }
     1774                        else
     1775                        {
     1776                                $unread_topics[$topic_id] = $user_lastmark;
     1777                        }
     1778                }
     1779                $db->sql_freeresult($result);
     1780        }
     1781
     1782        return $unread_topics;
    14651783}
    14661784
     
    17152033
    17162034        $on_page = floor($start_item / $per_page) + 1;
    1717         $url_delim = (strpos($base_url, '?') === false) ? '?' : '&amp;';
     2035        $url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&amp;');
    17182036
    17192037        $page_string = ($on_page == 1) ? '<strong>1</strong>' : '<a href="' . $base_url . '">1</a>';
     
    19942312
    19952313        // Determine which type of redirect we need to handle...
    1996         $url_parts = parse_url($url);
     2314        $url_parts = @parse_url($url);
    19972315
    19982316        if ($url_parts === false)
     
    21382456
    21392457        // Remove previously added sid
    2140         if (strpos($url, '?sid=') !== false)
    2141         {
    2142                 $url = preg_replace('/(\?)sid=[a-z0-9]+(&amp;|&)?/', '\1', $url);
    2143         }
    2144         else if (strpos($url, '&sid=') !== false)
    2145         {
    2146                 $url = preg_replace('/&sid=[a-z0-9]+(&)?/', '\1', $url);
    2147         }
    2148         else if (strpos($url, '&amp;sid=') !== false)
    2149         {
    2150                 $url = preg_replace('/&amp;sid=[a-z0-9]+(&amp;)?/', '\1', $url);
     2458        if (strpos($url, 'sid=') !== false)
     2459        {
     2460                // All kind of links
     2461                $url = preg_replace('/(\?)?(&amp;|&)?sid=[a-z0-9]+/', '', $url);
     2462                // if the sid was the first param, make the old second as first ones
     2463                $url = preg_replace("/$phpEx(&amp;|&)+?/", "$phpEx?", $url);
    21512464        }
    21522465
     
    22102523
    22112524                $redirect .= ($query) ? '?' . $query : '';
     2525        }
     2526
     2527        // We need to be cautious here.
     2528        // On some situations, the redirect path is an absolute URL, sometimes a relative path
     2529        // For a relative path, let's prefix it with $phpbb_root_path to point to the correct location,
     2530        // else we use the URL directly.
     2531        $url_parts = @parse_url($redirect);
     2532
     2533        // URL
     2534        if ($url_parts !== false && !empty($url_parts['scheme']) && !empty($url_parts['host']))
     2535        {
     2536                return str_replace('&', '&amp;', $redirect);
    22122537        }
    22132538
     
    23732698        if ($check && $confirm)
    23742699        {
    2375                 $user_id = request_var('user_id', 0);
     2700                $user_id = request_var('confirm_uid', 0);
    23762701                $session_id = request_var('sess', '');
    23772702                $confirm_key = request_var('confirm_key', '');
     
    23952720
    23962721        $s_hidden_fields = build_hidden_fields(array(
    2397                 'user_id'       => $user->data['user_id'],
    2398                 'sess'          => $user->session_id,
    2399                 'sid'           => $user->session_id)
    2400         );
     2722                'confirm_uid'   => $user->data['user_id'],
     2723                'sess'                  => $user->session_id,
     2724                'sid'                   => $user->session_id,
     2725        ));
    24012726
    24022727        // generate activation key
     
    24092734        else
    24102735        {
    2411                 page_header((!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title]);
     2736                page_header(((!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title]), false);
    24122737        }
    24132738
     
    24572782{
    24582783        global $db, $user, $template, $auth, $phpEx, $phpbb_root_path, $config;
     2784
     2785        if (!class_exists('phpbb_captcha_factory'))
     2786        {
     2787                include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
     2788        }
    24592789
    24602790        $err = '';
     
    25682898                        case LOGIN_ERROR_ATTEMPTS:
    25692899
    2570                                 // Show confirm image
    2571                                 $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
    2572                                         WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
    2573                                                 AND confirm_type = " . CONFIRM_LOGIN;
    2574                                 $db->sql_query($sql);
    2575 
    2576                                 // Generate code
    2577                                 $code = gen_rand_string(mt_rand(5, 8));
    2578                                 $confirm_id = md5(unique_id($user->ip));
    2579                                 $seed = hexdec(substr(unique_id(), 4, 10));
    2580 
    2581                                 // compute $seed % 0x7fffffff
    2582                                 $seed -= 0x7fffffff * floor($seed / 0x7fffffff);
    2583 
    2584                                 $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
    2585                                         'confirm_id'    => (string) $confirm_id,
    2586                                         'session_id'    => (string) $user->session_id,
    2587                                         'confirm_type'  => (int) CONFIRM_LOGIN,
    2588                                         'code'                  => (string) $code,
    2589                                         'seed'                  => (int) $seed)
    2590                                 );
    2591                                 $db->sql_query($sql);
     2900                                $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
     2901                                $captcha->init(CONFIRM_LOGIN);
     2902                                // $captcha->reset();
    25922903
    25932904                                $template->assign_vars(array(
    2594                                         'S_CONFIRM_CODE'                        => true,
    2595                                         'CONFIRM_ID'                            => $confirm_id,
    2596                                         'CONFIRM_IMAGE'                         => '<img src="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=confirm&amp;id=' . $confirm_id . '&amp;type=' . CONFIRM_LOGIN) . '" alt="" title="" />',
    2597                                         'L_LOGIN_CONFIRM_EXPLAIN'       => sprintf($user->lang['LOGIN_CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'),
     2905                                        'CAPTCHA_TEMPLATE'                      => $captcha->get_template(),
    25982906                                ));
    25992907
    26002908                                $err = $user->lang[$result['error_msg']];
    2601 
    26022909                        break;
    26032910
     
    26262933        }
    26272934
    2628         if (!$redirect)
    2629         {
    2630                 // We just use what the session code determined...
    2631                 // If we are not within the admin directory we use the page dir...
    2632                 $redirect = '';
    2633 
    2634                 if (!$admin)
    2635                 {
    2636                         $redirect .= ($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '';
    2637                 }
    2638 
    2639                 $redirect .= $user->page['page_name'] . (($user->page['query_string']) ? '?' . htmlspecialchars($user->page['query_string']) : '');
    2640         }
    2641 
    26422935        // Assign credential for username/password pair
    26432936        $credential = ($admin) ? md5(unique_id()) : false;
    26442937
    26452938        $s_hidden_fields = array(
    2646                 'redirect'      => $redirect,
    26472939                'sid'           => $user->session_id,
    26482940        );
     2941
     2942        if ($redirect)
     2943        {
     2944                $s_hidden_fields['redirect'] = $redirect;
     2945        }
    26492946
    26502947        if ($admin)
     
    26602957
    26612958                'U_SEND_PASSWORD'               => ($config['email_enable']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') : '',
    2662                 'U_RESEND_ACTIVATION'   => ($config['require_activation'] != USER_ACTIVATION_NONE && $config['email_enable']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=resend_act') : '',
     2959                'U_RESEND_ACTIVATION'   => ($config['require_activation'] == USER_ACTIVATION_SELF && $config['email_enable']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=resend_act') : '',
    26632960                'U_TERMS_USE'                   => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=terms'),
    26642961                'U_PRIVACY'                             => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=privacy'),
    26652962
    26662963                'S_DISPLAY_FULL_LOGIN'  => ($s_display) ? true : false,
    2667                 'S_LOGIN_ACTION'                => (!$admin) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("index.$phpEx", false, true, $user->session_id), // Needs to stay index.$phpEx because we are within the admin directory
    26682964                'S_HIDDEN_FIELDS'               => $s_hidden_fields,
    26692965
     
    27493045        }
    27503046
    2751         page_header($user->lang['LOGIN']);
     3047        page_header($user->lang['LOGIN'], false);
    27523048
    27533049        $template->assign_vars(array(
     3050                'S_LOGIN_ACTION'                => build_url(array('f')),
    27543051                'S_HIDDEN_FIELDS'               => build_hidden_fields(array('f' => $forum_data['forum_id'])))
    27553052        );
     
    28703167{
    28713168        global $db, $user;
     3169
     3170        // In phpBB 3.1.x i want to have logging in a class to be able to control it
     3171        // For now, we need a quite hakish approach to circumvent logging for some actions
     3172        // @todo implement cleanly
     3173        if (!empty($GLOBALS['skip_add_log']))
     3174        {
     3175                return false;
     3176        }
    28723177
    28733178        $args = func_get_args();
     
    31383443
    31393444        // Do not display notices if we suppress them via @
    3140         if (error_reporting() == 0)
     3445        if (error_reporting() == 0 && $errno != E_USER_ERROR && $errno != E_USER_WARNING && $errno != E_USER_NOTICE)
    31413446        {
    31423447                return;
     
    31473452        {
    31483453                $msg_text = $msg_long_text;
     3454        }
     3455
     3456        if (!defined('E_DEPRECATED'))
     3457        {
     3458                define('E_DEPRECATED', 8192);
    31493459        }
    31503460
     
    31813491                                $errfile = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $errfile);
    31823492                                $msg_text = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $msg_text);
    3183 
    31843493                                echo '<b>[phpBB Debug] PHP Notice</b>: in file <b>' . $errfile . '</b> on line <b>' . $errline . '</b>: <b>' . $msg_text . '</b><br />' . "\n";
     3494
     3495                                // we are writing an image - the user won't see the debug, so let's place it in the log
     3496                                if (defined('IMAGE_OUTPUT') || defined('IN_CRON'))
     3497                                {
     3498                                        add_log('critical', 'LOG_IMAGE_GENERATION_ERROR', $errfile, $errline, $msg_text);
     3499                                }
     3500                                // echo '<br /><br />BACKTRACE<br />' . get_backtrace() . '<br />' . "\n";
    31853501                        }
    31863502
     
    32153531                                }
    32163532                        }
     3533
     3534                        if ((defined('DEBUG') || defined('IN_CRON') || defined('IMAGE_OUTPUT')) && isset($db))
     3535                        {
     3536                                // let's avoid loops
     3537                                $db->sql_return_on_error(true);
     3538                                add_log('critical', 'LOG_GENERAL_ERROR', $msg_title, $msg_text);
     3539                                $db->sql_return_on_error(false);
     3540                        }
     3541
     3542                        // Do not send 200 OK, but service unavailable on errors
     3543                        header('HTTP/1.1 503 Service Unavailable');
    32173544
    32183545                        garbage_collection();
     
    32943621                                else
    32953622                                {
    3296                                         page_header($msg_title);
     3623                                        page_header($msg_title, false);
    32973624                                }
    32983625                        }
     
    33233650                        exit_handler();
    33243651                break;
     3652
     3653                // PHP4 compatibility
     3654                case E_DEPRECATED:
     3655                        return true;
     3656                break;
    33253657        }
    33263658
     
    33323664/**
    33333665* Queries the session table to get information about online guests
    3334 * @param int $forum_id Limits the search to the forum with this id
     3666* @param int $item_id Limits the search to the item with this id
     3667* @param string $item The name of the item which is stored in the session table as session_{$item}_id
    33353668* @return int The number of active distinct guest sessions
    33363669*/
    3337 function obtain_guest_count($forum_id = 0)
     3670function obtain_guest_count($item_id = 0, $item = 'forum')
    33383671{
    33393672        global $db, $config;
    33403673
    3341         if ($forum_id)
    3342         {
    3343                 $reading_sql = ' AND s.session_forum_id = ' . (int) $forum_id;
     3674        if ($item_id)
     3675        {
     3676                $reading_sql = ' AND s.session_' . $item . '_id = ' . (int) $item_id;
    33443677        }
    33453678        else
     
    33703703                        $reading_sql;
    33713704        }
    3372         $result = $db->sql_query($sql, 60);
     3705        $result = $db->sql_query($sql);
    33733706        $guests_online = (int) $db->sql_fetchfield('num_guests');
    33743707        $db->sql_freeresult($result);
     
    33793712/**
    33803713* Queries the session table to get information about online users
    3381 * @param int $forum_id Limits the search to the forum with this id
     3714* @param int $item_id Limits the search to the item with this id
     3715* @param string $item The name of the item which is stored in the session table as session_{$item}_id
    33823716* @return array An array containing the ids of online, hidden and visible users, as well as statistical info
    33833717*/
    3384 function obtain_users_online($forum_id = 0)
     3718function obtain_users_online($item_id = 0, $item = 'forum')
    33853719{
    33863720        global $db, $config, $user;
    33873721
    33883722        $reading_sql = '';
    3389         if ($forum_id !== 0)
    3390         {
    3391                 $reading_sql = ' AND s.session_forum_id = ' . (int) $forum_id;
     3723        if ($item_id !== 0)
     3724        {
     3725                $reading_sql = ' AND s.session_' . $item . '_id = ' . (int) $item_id;
    33923726        }
    33933727
     
    34033737        if ($config['load_online_guests'])
    34043738        {
    3405                 $online_users['guests_online'] = obtain_guest_count($forum_id);
     3739                $online_users['guests_online'] = obtain_guest_count($item_id, $item);
    34063740        }
    34073741
     
    34423776* Uses the result of obtain_users_online to generate a localized, readable representation.
    34433777* @param mixed $online_users result of obtain_users_online - array with user_id lists for total, hidden and visible users, and statistics
    3444 * @param int $forum_id Indicate that the data is limited to one forum and not global.
     3778* @param int $item_id Indicate that the data is limited to one item and not global
     3779* @param string $item The name of the item which is stored in the session table as session_{$item}_id
    34453780* @return array An array containing the string for output to the template
    34463781*/
    3447 function obtain_users_online_string($online_users, $forum_id = 0)
     3782function obtain_users_online_string($online_users, $item_id = 0, $item = 'forum')
    34483783{
    34493784        global $config, $db, $user, $auth;
    34503785
    34513786        $user_online_link = $online_userlist = '';
     3787        // Need caps version of $item for language-strings
     3788        $item_caps = strtoupper($item);
    34523789
    34533790        if (sizeof($online_users['online_users']))
     
    34843821        }
    34853822
    3486         if ($forum_id === 0)
     3823        if ($item_id === 0)
    34873824        {
    34883825                $online_userlist = $user->lang['REGISTERED_USERS'] . ' ' . $online_userlist;
     
    34903827        else if ($config['load_online_guests'])
    34913828        {
    3492                 $l_online = ($online_users['guests_online'] === 1) ? $user->lang['BROWSING_FORUM_GUEST'] : $user->lang['BROWSING_FORUM_GUESTS'];
     3829                $l_online = ($online_users['guests_online'] === 1) ? $user->lang['BROWSING_' . $item_caps . '_GUEST'] : $user->lang['BROWSING_' . $item_caps . '_GUESTS'];
    34933830                $online_userlist = sprintf($l_online, $online_userlist, $online_users['guests_online']);
    34943831        }
    34953832        else
    34963833        {
    3497                 $online_userlist = sprintf($user->lang['BROWSING_FORUM'], $online_userlist);
     3834                $online_userlist = sprintf($user->lang['BROWSING_' . $item_caps], $online_userlist);
    34983835        }
    34993836        // Build online listing
     
    35493886}
    35503887
     3888/**
     3889* Get option bitfield from custom data
     3890*
     3891* @param int    $bit            The bit/value to get
     3892* @param int    $data           Current bitfield to check
     3893* @return bool  Returns true if value of constant is set in bitfield, else false
     3894*/
     3895function phpbb_optionget($bit, $data)
     3896{
     3897        return ($data & 1 << (int) $bit) ? true : false;
     3898}
     3899
     3900/**
     3901* Set option bitfield
     3902*
     3903* @param int    $bit            The bit/value to set/unset
     3904* @param bool   $set            True if option should be set, false if option should be unset.
     3905* @param int    $data           Current bitfield to change
     3906*
     3907* @return int   The new bitfield
     3908*/
     3909function phpbb_optionset($bit, $set, $data)
     3910{
     3911        if ($set && !($data & 1 << $bit))
     3912        {
     3913                $data += 1 << $bit;
     3914        }
     3915        else if (!$set && ($data & 1 << $bit))
     3916        {
     3917                $data -= 1 << $bit;
     3918        }
     3919
     3920        return $data;
     3921}
     3922
     3923/**
     3924* Login using http authenticate.
     3925*
     3926* @param array  $param          Parameter array, see $param_defaults array.
     3927*
     3928* @return void
     3929*/
     3930function phpbb_http_login($param)
     3931{
     3932        global $auth, $user;
     3933        global $config;
     3934
     3935        $param_defaults = array(
     3936                'auth_message'  => '',
     3937
     3938                'autologin'             => false,
     3939                'viewonline'    => true,
     3940                'admin'                 => false,
     3941        );
     3942
     3943        // Overwrite default values with passed values
     3944        $param = array_merge($param_defaults, $param);
     3945
     3946        // User is already logged in
     3947        // We will not overwrite his session
     3948        if (!empty($user->data['is_registered']))
     3949        {
     3950                return;
     3951        }
     3952
     3953        // $_SERVER keys to check
     3954        $username_keys = array(
     3955                'PHP_AUTH_USER',
     3956                'Authorization',
     3957                'REMOTE_USER', 'REDIRECT_REMOTE_USER',
     3958                'HTTP_AUTHORIZATION', 'REDIRECT_HTTP_AUTHORIZATION',
     3959                'REMOTE_AUTHORIZATION', 'REDIRECT_REMOTE_AUTHORIZATION',
     3960                'AUTH_USER',
     3961        );
     3962
     3963        $password_keys = array(
     3964                'PHP_AUTH_PW',
     3965                'REMOTE_PASSWORD',
     3966                'AUTH_PASSWORD',
     3967        );
     3968
     3969        $username = null;
     3970        foreach ($username_keys as $k)
     3971        {
     3972                if (isset($_SERVER[$k]))
     3973                {
     3974                        $username = $_SERVER[$k];
     3975                        break;
     3976                }
     3977        }
     3978
     3979        $password = null;
     3980        foreach ($password_keys as $k)
     3981        {
     3982                if (isset($_SERVER[$k]))
     3983                {
     3984                        $password = $_SERVER[$k];
     3985                        break;
     3986                }
     3987        }
     3988
     3989        // Decode encoded information (IIS, CGI, FastCGI etc.)
     3990        if (!is_null($username) && is_null($password) && strpos($username, 'Basic ') === 0)
     3991        {
     3992                list($username, $password) = explode(':', base64_decode(substr($username, 6)), 2);
     3993    }
     3994
     3995        if (!is_null($username) && !is_null($password))
     3996        {
     3997                set_var($username, $username, 'string', true);
     3998                set_var($password, $password, 'string', true);
     3999
     4000                $auth_result = $auth->login($username, $password, $param['autologin'], $param['viewonline'], $param['admin']);
     4001
     4002                if ($auth_result['status'] == LOGIN_SUCCESS)
     4003                {
     4004                        return;
     4005                }
     4006                else if ($auth_result['status'] == LOGIN_ERROR_ATTEMPTS)
     4007                {
     4008                        header('HTTP/1.0 401 Unauthorized');
     4009                        trigger_error('NOT_AUTHORISED');
     4010                }
     4011        }
     4012
     4013        // Prepend sitename to auth_message
     4014        $param['auth_message'] = ($param['auth_message'] === '') ? $config['sitename'] : $config['sitename'] . ' - ' . $param['auth_message'];
     4015
     4016        // We should probably filter out non-ASCII characters - RFC2616
     4017        $param['auth_message'] = preg_replace('/[\x80-\xFF]/', '?', $param['auth_message']);
     4018
     4019        header('WWW-Authenticate: Basic realm="' . $param['auth_message'] . '"');
     4020        header('HTTP/1.0 401 Unauthorized');
     4021
     4022        trigger_error('NOT_AUTHORISED');
     4023}
    35514024
    35524025/**
    35534026* Generate page header
    35544027*/
    3555 function page_header($page_title = '', $display_online_list = true)
     4028function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum')
    35564029{
    35574030        global $db, $config, $template, $SID, $_SID, $user, $auth, $phpEx, $phpbb_root_path;
     
    35894062
    35904063        // Get users online list ... if required
    3591         $l_online_users = $online_userlist = $l_online_record = '';
     4064        $l_online_users = $online_userlist = $l_online_record = $l_online_time = '';
    35924065
    35934066        if ($config['load_online'] && $config['load_online_time'] && $display_online_list)
    35944067        {
    3595                 $f = request_var('f', 0);
    3596                 $f = max($f, 0);
    3597                 $online_users = obtain_users_online($f);
    3598                 $user_online_strings = obtain_users_online_string($online_users, $f);
     4068                /**
     4069                * Load online data:
     4070                * For obtaining another session column use $item and $item_id in the function-parameter, whereby the column is session_{$item}_id.
     4071                */
     4072                $item_id = max($item_id, 0);
     4073
     4074                $online_users = obtain_users_online($item_id, $item);
     4075                $user_online_strings = obtain_users_online_string($online_users, $item_id, $item);
    35994076
    36004077                $l_online_users = $user_online_strings['l_online_users'];
     
    36084085                }
    36094086
    3610                 $l_online_record = sprintf($user->lang['RECORD_ONLINE_USERS'], $config['record_online_users'], $user->format_date($config['record_online_date']));
     4087                $l_online_record = sprintf($user->lang['RECORD_ONLINE_USERS'], $config['record_online_users'], $user->format_date($config['record_online_date'], false, true));
    36114088
    36124089                $l_online_time = ($config['load_online_time'] == 1) ? 'VIEW_ONLINE_TIME' : 'VIEW_ONLINE_TIMES';
    36134090                $l_online_time = sprintf($user->lang[$l_online_time], $config['load_online_time']);
    3614         }
    3615         else
    3616         {
    3617                 $l_online_time = '';
    36184091        }
    36194092
     
    36574130                }
    36584131        }
     4132
     4133        $forum_id = request_var('f', 0);
     4134        $topic_id = request_var('t', 0);
     4135
     4136        $s_feed_news = false;
     4137
     4138        // Get option for news
     4139        if ($config['feed_enable'])
     4140        {
     4141                $sql = 'SELECT forum_id
     4142                        FROM ' . FORUMS_TABLE . '
     4143                        WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
     4144                $result = $db->sql_query_limit($sql, 1, 0, 600);
     4145                $s_feed_news = (int) $db->sql_fetchfield('forum_id');
     4146                $db->sql_freeresult($result);
     4147        }
     4148
     4149        // Determine board url - we may need it later
     4150        $board_url = generate_board_url() . '/';
     4151        $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $phpbb_root_path;
    36594152
    36604153        // Which timezone?
     
    36854178                'S_USER_NEW_PRIVMSG'                    => $user->data['user_new_privmsg'],
    36864179                'S_USER_UNREAD_PRIVMSG'                 => $user->data['user_unread_privmsg'],
     4180                'S_USER_NEW'                                    => $user->data['user_new'],
    36874181
    36884182                'SID'                           => $SID,
     
    36904184                'SESSION_ID'            => $user->session_id,
    36914185                'ROOT_PATH'                     => $phpbb_root_path,
     4186                'BOARD_URL'                     => $board_url,
    36924187
    36934188                'L_LOGIN_LOGOUT'        => $l_login_logout,
     
    37114206                'U_SEARCH_NEW'                  => append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=newposts'),
    37124207                'U_SEARCH_UNANSWERED'   => append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=unanswered'),
     4208                'U_SEARCH_UNREAD'               => append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=unreadposts'),
    37134209                'U_SEARCH_ACTIVE_TOPICS'=> append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=active_topics'),
    37144210                'U_DELETE_COOKIES'              => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=delete_cookies'),
    37154211                'U_TEAM'                                => ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile')) ? '' : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=leaders'),
     4212                'U_TERMS_USE'                   => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=terms'),
     4213                'U_PRIVACY'                             => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=privacy'),
    37164214                'U_RESTORE_PERMISSIONS' => ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm') : '',
     4215                'U_FEED'                                => generate_board_url() . "/feed.$phpEx",
    37174216
    37184217                'S_USER_LOGGED_IN'              => ($user->data['user_id'] != ANONYMOUS) ? true : false,
     
    37364235                'S_NEW_PM'                              => ($s_privmsg_new) ? 1 : 0,
    37374236                'S_REGISTER_ENABLED'    => ($config['require_activation'] != USER_ACTIVATION_DISABLE) ? true : false,
    3738 
    3739                 'T_THEME_PATH'                  => "{$phpbb_root_path}styles/" . $user->theme['theme_path'] . '/theme',
    3740                 'T_TEMPLATE_PATH'               => "{$phpbb_root_path}styles/" . $user->theme['template_path'] . '/template',
    3741                 'T_SUPER_TEMPLATE_PATH' => (isset($user->theme['template_inherit_path']) && $user->theme['template_inherit_path']) ? "{$phpbb_root_path}styles/" . $user->theme['template_inherit_path'] . '/template' : "{$phpbb_root_path}styles/" . $user->theme['template_path'] . '/template',
    3742                 'T_IMAGESET_PATH'               => "{$phpbb_root_path}styles/" . $user->theme['imageset_path'] . '/imageset',
    3743                 'T_IMAGESET_LANG_PATH'  => "{$phpbb_root_path}styles/" . $user->theme['imageset_path'] . '/imageset/' . $user->data['user_lang'],
    3744                 'T_IMAGES_PATH'                 => "{$phpbb_root_path}images/",
    3745                 'T_SMILIES_PATH'                => "{$phpbb_root_path}{$config['smilies_path']}/",
    3746                 'T_AVATAR_PATH'                 => "{$phpbb_root_path}{$config['avatar_path']}/",
    3747                 'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
    3748                 'T_ICONS_PATH'                  => "{$phpbb_root_path}{$config['icons_path']}/",
    3749                 'T_RANKS_PATH'                  => "{$phpbb_root_path}{$config['ranks_path']}/",
    3750                 'T_UPLOAD_PATH'                 => "{$phpbb_root_path}{$config['upload_path']}/",
    3751                 'T_STYLESHEET_LINK'             => (!$user->theme['theme_storedb']) ? "{$phpbb_root_path}styles/" . $user->theme['theme_path'] . '/theme/stylesheet.css' : "{$phpbb_root_path}style.$phpEx?sid=$user->session_id&amp;id=" . $user->theme['style_id'] . '&amp;lang=' . $user->data['user_lang'],
     4237                'S_FORUM_ID'                    => $forum_id,
     4238                'S_TOPIC_ID'                    => $topic_id,
     4239
     4240                'S_LOGIN_ACTION'                => ((!defined('ADMIN_START')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("index.$phpEx", false, true, $user->session_id)),
     4241                'S_LOGIN_REDIRECT'              => build_hidden_fields(array('redirect' => str_replace('&amp;', '&', build_url()))),
     4242
     4243                'S_ENABLE_FEEDS'                        => ($config['feed_enable']) ? true : false,
     4244                'S_ENABLE_FEEDS_OVERALL'        => ($config['feed_overall']) ? true : false,
     4245                'S_ENABLE_FEEDS_FORUMS'         => ($config['feed_overall_forums']) ? true : false,
     4246                'S_ENABLE_FEEDS_TOPICS'         => ($config['feed_topics_new']) ? true : false,
     4247                'S_ENABLE_FEEDS_TOPICS_ACTIVE'  => ($config['feed_topics_active']) ? true : false,
     4248                'S_ENABLE_FEEDS_NEWS'           => ($s_feed_news) ? true : false,
     4249
     4250                'T_THEME_PATH'                  => "{$web_path}styles/" . $user->theme['theme_path'] . '/theme',
     4251                'T_TEMPLATE_PATH'               => "{$web_path}styles/" . $user->theme['template_path'] . '/template',
     4252                'T_SUPER_TEMPLATE_PATH' => (isset($user->theme['template_inherit_path']) && $user->theme['template_inherit_path']) ? "{$web_path}styles/" . $user->theme['template_inherit_path'] . '/template' : "{$web_path}styles/" . $user->theme['template_path'] . '/template',
     4253                'T_IMAGESET_PATH'               => "{$web_path}styles/" . $user->theme['imageset_path'] . '/imageset',
     4254                'T_IMAGESET_LANG_PATH'  => "{$web_path}styles/" . $user->theme['imageset_path'] . '/imageset/' . $user->data['user_lang'],
     4255                'T_IMAGES_PATH'                 => "{$web_path}images/",
     4256                'T_SMILIES_PATH'                => "{$web_path}{$config['smilies_path']}/",
     4257                'T_AVATAR_PATH'                 => "{$web_path}{$config['avatar_path']}/",
     4258                'T_AVATAR_GALLERY_PATH' => "{$web_path}{$config['avatar_gallery_path']}/",
     4259                'T_ICONS_PATH'                  => "{$web_path}{$config['icons_path']}/",
     4260                'T_RANKS_PATH'                  => "{$web_path}{$config['ranks_path']}/",
     4261                'T_UPLOAD_PATH'                 => "{$web_path}{$config['upload_path']}/",
     4262                'T_STYLESHEET_LINK'             => (!$user->theme['theme_storedb']) ? "{$web_path}styles/" . $user->theme['theme_path'] . '/theme/stylesheet.css' : append_sid("{$phpbb_root_path}style.$phpEx", 'id=' . $user->theme['style_id'] . '&amp;lang=' . $user->data['user_lang'], true, $user->session_id),
    37524263                'T_STYLESHEET_NAME'             => $user->theme['theme_name'],
     4264
     4265                'T_THEME_NAME'                  => $user->theme['theme_path'],
     4266                'T_TEMPLATE_NAME'               => $user->theme['template_path'],
     4267                'T_SUPER_TEMPLATE_NAME' => (isset($user->theme['template_inherit_path']) && $user->theme['template_inherit_path']) ? $user->theme['template_inherit_path'] : $user->theme['template_path'],
     4268                'T_IMAGESET_NAME'               => $user->theme['imageset_path'],
     4269                'T_IMAGESET_LANG_NAME'  => $user->data['user_lang'],
     4270                'T_IMAGES'                              => 'images',
     4271                'T_SMILIES'                             => $config['smilies_path'],
     4272                'T_AVATAR'                              => $config['avatar_path'],
     4273                'T_AVATAR_GALLERY'              => $config['avatar_gallery_path'],
     4274                'T_ICONS'                               => $config['icons_path'],
     4275                'T_RANKS'                               => $config['ranks_path'],
     4276                'T_UPLOAD'                              => $config['upload_path'],
    37534277
    37544278                'SITE_LOGO_IMG'                 => $user->img('site_logo'),
     
    37854309                }
    37864310
    3787                 $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
     4311                $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
    37884312
    37894313                if ($auth->acl_get('a_') && defined('DEBUG_EXTRA'))
     
    38134337
    38144338        // Call cron-type script
     4339        $call_cron = false;
    38154340        if (!defined('IN_CRON') && $run_cron && !$config['board_disable'])
    38164341        {
     4342                $call_cron = true;
     4343                $time_now = (!empty($user->time_now) && is_int($user->time_now)) ? $user->time_now : time();
     4344
     4345                // Any old lock present?
     4346                if (!empty($config['cron_lock']))
     4347                {
     4348                        $cron_time = explode(' ', $config['cron_lock']);
     4349
     4350                        // If 1 hour lock is present we do not call cron.php
     4351                        if ($cron_time[0] + 3600 >= $time_now)
     4352                        {
     4353                                $call_cron = false;
     4354                        }
     4355                }
     4356        }
     4357
     4358        // Call cron job?
     4359        if ($call_cron)
     4360        {
    38174361                $cron_type = '';
    38184362
    3819                 if (time() - $config['queue_interval'] > $config['last_queue_run'] && !defined('IN_ADMIN') && file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
     4363                if ($time_now - $config['queue_interval'] > $config['last_queue_run'] && !defined('IN_ADMIN') && file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
    38204364                {
    38214365                        // Process email queue
    38224366                        $cron_type = 'queue';
    38234367                }
    3824                 else if (method_exists($cache, 'tidy') && time() - $config['cache_gc'] > $config['cache_last_gc'])
     4368                else if (method_exists($cache, 'tidy') && $time_now - $config['cache_gc'] > $config['cache_last_gc'])
    38254369                {
    38264370                        // Tidy the cache
    38274371                        $cron_type = 'tidy_cache';
    38284372                }
    3829                 else if (time() - $config['warnings_gc'] > $config['warnings_last_gc'])
     4373                else if ($config['warnings_expire_days'] && ($time_now - $config['warnings_gc'] > $config['warnings_last_gc']))
    38304374                {
    38314375                        $cron_type = 'tidy_warnings';
    38324376                }
    3833                 else if (time() - $config['database_gc'] > $config['database_last_gc'])
     4377                else if ($time_now - $config['database_gc'] > $config['database_last_gc'])
    38344378                {
    38354379                        // Tidy the database
    38364380                        $cron_type = 'tidy_database';
    38374381                }
    3838                 else if (time() - $config['search_gc'] > $config['search_last_gc'])
     4382                else if ($time_now - $config['search_gc'] > $config['search_last_gc'])
    38394383                {
    38404384                        // Tidy the search
    38414385                        $cron_type = 'tidy_search';
    38424386                }
    3843                 else if (time() - $config['session_gc'] > $config['session_last_gc'])
     4387                else if ($time_now - $config['session_gc'] > $config['session_last_gc'])
    38444388                {
    38454389                        $cron_type = 'tidy_sessions';
Note: See TracChangeset for help on using the changeset viewer.