Changeset 702 for trunk/forum/includes


Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
Location:
trunk/forum/includes
Files:
92 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/acm/acm_file.php

    r400 r702  
    33*
    44* @package acm
    5 * @version $Id: acm_file.php 9076 2008-11-22 19:06:42Z acydburn $
    6 * @copyright (c) 2005 phpBB Group
     5* @version $Id$
     6* @copyright (c) 2005, 2009 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    88*
     
    4545        function load()
    4646        {
    47                 global $phpEx;
    48                 if (file_exists($this->cache_dir . 'data_global.' . $phpEx))
    49                 {
    50                         @include($this->cache_dir . 'data_global.' . $phpEx);
    51                 }
    52                 else
    53                 {
    54                         return false;
    55                 }
    56 
    57                 return true;
     47                return $this->_read('data_global');
    5848        }
    5949
     
    8777                global $phpEx;
    8878
    89                 if ($fp = @fopen($this->cache_dir . 'data_global.' . $phpEx, 'wb'))
    90                 {
    91                         @flock($fp, LOCK_EX);
    92                         fwrite($fp, "<?php\n\$this->vars = " . var_export($this->vars, true) . ";\n\n\$this->var_expires = " . var_export($this->var_expires, true) . "\n?>");
    93                         @flock($fp, LOCK_UN);
    94                         fclose($fp);
    95 
    96                         if (!function_exists('phpbb_chmod'))
    97                         {
    98                                 global $phpbb_root_path;
    99                                 include($phpbb_root_path . 'includes/functions.' . $phpEx);
    100                         }
    101 
    102                         phpbb_chmod($this->cache_dir . 'data_global.' . $phpEx, CHMOD_WRITE);
    103                 }
    104                 else
     79                if (!$this->_write('data_global'))
    10580                {
    10681                        // Now, this occurred how often? ... phew, just tell the user then...
    10782                        if (!@is_writable($this->cache_dir))
    10883                        {
    109                                 trigger_error($this->cache_dir . ' is NOT writable.', E_USER_ERROR);
    110                         }
    111 
    112                         trigger_error('Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx, E_USER_ERROR);
     84                                // We need to use die() here, because else we may encounter an infinite loop (the message handler calls $cache->unload())
     85                                die($this->cache_dir . ' is NOT writable.');
     86                                exit;
     87                        }
     88
     89                        die('Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx);
     90                        exit;
    11391                }
    11492
     
    130108                }
    131109
     110                $time = time();
     111
    132112                while (($entry = readdir($dir)) !== false)
    133113                {
     
    137117                        }
    138118
    139                         $expired = true;
    140                         @include($this->cache_dir . $entry);
    141                         if ($expired)
     119                        if (!($handle = @fopen($this->cache_dir . $entry, 'rb')))
     120                        {
     121                                continue;
     122                        }
     123
     124                        // Skip the PHP header
     125                        fgets($handle);
     126
     127                        // Skip expiration
     128                        $expires = (int) fgets($handle);
     129
     130                        fclose($handle);
     131
     132                        if ($time >= $expires)
    142133                        {
    143134                                $this->remove_file($this->cache_dir . $entry);
     
    155146                        foreach ($this->var_expires as $var_name => $expires)
    156147                        {
    157                                 if (time() > $expires)
     148                                if ($time >= $expires)
    158149                                {
    159150                                        $this->destroy($var_name);
     
    179170                        }
    180171
    181                         @include($this->cache_dir . "data{$var_name}.$phpEx");
    182                         return (isset($data)) ? $data : false;
     172                        return $this->_read('data' . $var_name);
    183173                }
    184174                else
     
    195185                if ($var_name[0] == '_')
    196186                {
    197                         global $phpEx;
    198 
    199                         if ($fp = @fopen($this->cache_dir . "data{$var_name}.$phpEx", 'wb'))
    200                         {
    201                                 @flock($fp, LOCK_EX);
    202                                 fwrite($fp, "<?php\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\n\$data =  " . (sizeof($var) ? "unserialize(" . var_export(serialize($var), true) . ");" : 'array();') . "\n\n?>");
    203                                 @flock($fp, LOCK_UN);
    204                                 fclose($fp);
    205 
    206                                 if (!function_exists('phpbb_chmod'))
    207                                 {
    208                                         global $phpbb_root_path;
    209                                         include($phpbb_root_path . 'includes/functions.' . $phpEx);
    210                                 }
    211 
    212                                 phpbb_chmod($this->cache_dir . "data{$var_name}.$phpEx", CHMOD_WRITE);
    213                         }
     187                        $this->_write('data' . $var_name, $var, time() + $ttl);
    214188                }
    215189                else
     
    286260                                }
    287261
    288                                 // The following method is more failproof than simply assuming the query is on line 3 (which it should be)
    289                                 $check_line = @file_get_contents($this->cache_dir . $entry);
    290 
    291                                 if (empty($check_line))
     262                                if (!($handle = @fopen($this->cache_dir . $entry, 'rb')))
    292263                                {
    293264                                        continue;
    294265                                }
    295266
    296                                 // Now get the contents between /* and */
    297                                 $check_line = substr($check_line, strpos($check_line, '/* ') + 3, strpos($check_line, ' */') - strpos($check_line, '/* ') - 3);
    298 
    299                                 $found = false;
     267                                // Skip the PHP header
     268                                fgets($handle);
     269
     270                                // Skip expiration
     271                                fgets($handle);
     272
     273                                // Grab the query, remove the LF
     274                                $query = substr(fgets($handle), 0, -1);
     275
     276                                fclose($handle);
     277
    300278                                foreach ($table as $check_table)
    301279                                {
    302280                                        // Better catch partial table names than no table names. ;)
    303                                         if (strpos($check_line, $check_table) !== false)
     281                                        if (strpos($query, $check_table) !== false)
    304282                                        {
    305                                                 $found = true;
     283                                                $this->remove_file($this->cache_dir . $entry);
    306284                                                break;
    307285                                        }
    308                                 }
    309 
    310                                 if ($found)
    311                                 {
    312                                         $this->remove_file($this->cache_dir . $entry);
    313286                                }
    314287                        }
     
    369342        function sql_load($query)
    370343        {
    371                 global $phpEx;
    372 
    373344                // Remove extra spaces and tabs
    374345                $query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
     346
     347                if (($rowset = $this->_read('sql_' . md5($query))) === false)
     348                {
     349                        return false;
     350                }
     351
    375352                $query_id = sizeof($this->sql_rowset);
    376 
    377                 if (!file_exists($this->cache_dir . 'sql_' . md5($query) . ".$phpEx"))
    378                 {
    379                         return false;
    380                 }
    381 
    382                 @include($this->cache_dir . 'sql_' . md5($query) . ".$phpEx");
    383 
    384                 if (!isset($expired))
    385                 {
    386                         return false;
    387                 }
    388                 else if ($expired)
    389                 {
    390                         $this->remove_file($this->cache_dir . 'sql_' . md5($query) . ".$phpEx", true);
    391                         return false;
    392                 }
    393 
     353                $this->sql_rowset[$query_id] = $rowset;
    394354                $this->sql_row_pointer[$query_id] = 0;
    395355
     
    402362        function sql_save($query, &$query_result, $ttl)
    403363        {
    404                 global $db, $phpEx;
     364                global $db;
    405365
    406366                // Remove extra spaces and tabs
    407367                $query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
    408                 $filename = $this->cache_dir . 'sql_' . md5($query) . '.' . $phpEx;
    409 
    410                 if ($fp = @fopen($filename, 'wb'))
    411                 {
    412                         @flock($fp, LOCK_EX);
    413 
    414                         $query_id = sizeof($this->sql_rowset);
    415                         $this->sql_rowset[$query_id] = array();
    416                         $this->sql_row_pointer[$query_id] = 0;
    417 
    418                         while ($row = $db->sql_fetchrow($query_result))
    419                         {
    420                                 $this->sql_rowset[$query_id][] = $row;
    421                         }
    422                         $db->sql_freeresult($query_result);
    423 
    424                         $file = "<?php\n\n/* " . str_replace('*/', '*\/', $query) . " */\n";
    425                         $file .= "\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n";
    426 
    427                         fwrite($fp, $file . "\n\$this->sql_rowset[\$query_id] = " . (sizeof($this->sql_rowset[$query_id]) ? "unserialize(" . var_export(serialize($this->sql_rowset[$query_id]), true) . ");" : 'array();') . "\n\n?>");
    428                         @flock($fp, LOCK_UN);
    429                         fclose($fp);
     368
     369                $query_id = sizeof($this->sql_rowset);
     370                $this->sql_rowset[$query_id] = array();
     371                $this->sql_row_pointer[$query_id] = 0;
     372
     373                while ($row = $db->sql_fetchrow($query_result))
     374                {
     375                        $this->sql_rowset[$query_id][] = $row;
     376                }
     377                $db->sql_freeresult($query_result);
     378
     379                if ($this->_write('sql_' . md5($query), $this->sql_rowset[$query_id], $ttl + time(), $query))
     380                {
     381                        $query_result = $query_id;
     382                }
     383        }
     384
     385        /**
     386        * Ceck if a given sql query exist in cache
     387        */
     388        function sql_exists($query_id)
     389        {
     390                return isset($this->sql_rowset[$query_id]);
     391        }
     392
     393        /**
     394        * Fetch row from cache (database)
     395        */
     396        function sql_fetchrow($query_id)
     397        {
     398                if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
     399                {
     400                        return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
     401                }
     402
     403                return false;
     404        }
     405
     406        /**
     407        * Fetch a field from the current row of a cached database result (database)
     408        */
     409        function sql_fetchfield($query_id, $field)
     410        {
     411                if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
     412                {
     413                        return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++][$field] : false;
     414                }
     415
     416                return false;
     417        }
     418
     419        /**
     420        * Seek a specific row in an a cached database result (database)
     421        */
     422        function sql_rowseek($rownum, $query_id)
     423        {
     424                if ($rownum >= sizeof($this->sql_rowset[$query_id]))
     425                {
     426                        return false;
     427                }
     428
     429                $this->sql_row_pointer[$query_id] = $rownum;
     430                return true;
     431        }
     432
     433        /**
     434        * Free memory used for a cached database result (database)
     435        */
     436        function sql_freeresult($query_id)
     437        {
     438                if (!isset($this->sql_rowset[$query_id]))
     439                {
     440                        return false;
     441                }
     442
     443                unset($this->sql_rowset[$query_id]);
     444                unset($this->sql_row_pointer[$query_id]);
     445
     446                return true;
     447        }
     448
     449        /**
     450        * Read cached data from a specified file
     451        *
     452        * @access private
     453        * @param string $filename Filename to write
     454        * @return mixed False if an error was encountered, otherwise the data type of the cached data
     455        */
     456        function _read($filename)
     457        {
     458                global $phpEx;
     459
     460                $file = "{$this->cache_dir}$filename.$phpEx";
     461
     462                $type = substr($filename, 0, strpos($filename, '_'));
     463
     464                if (!file_exists($file))
     465                {
     466                        return false;
     467                }
     468
     469                if (!($handle = @fopen($file, 'rb')))
     470                {
     471                        return false;
     472                }
     473
     474                // Skip the PHP header
     475                fgets($handle);
     476
     477                if ($filename == 'data_global')
     478                {
     479                        $this->vars = $this->var_expires = array();
     480
     481                        $time = time();
     482
     483                        while (($expires = (int) fgets($handle)) && !feof($handle))
     484                        {
     485                                // Number of bytes of data
     486                                $bytes = substr(fgets($handle), 0, -1);
     487
     488                                if (!is_numeric($bytes) || ($bytes = (int) $bytes) === 0)
     489                                {
     490                                        // We cannot process the file without a valid number of bytes
     491                                        // so we discard it
     492                                        fclose($handle);
     493
     494                                        $this->vars = $this->var_expires = array();
     495                                        $this->is_modified = false;
     496
     497                                        $this->remove_file($file);
     498
     499                                        return false;
     500                                }
     501
     502                                if ($time >= $expires)
     503                                {
     504                                        fseek($handle, $bytes, SEEK_CUR);
     505
     506                                        continue;
     507                                }
     508
     509                                $var_name = substr(fgets($handle), 0, -1);
     510
     511                                // Read the length of bytes that consists of data.
     512                                $data = fread($handle, $bytes - strlen($var_name));
     513                                $data = @unserialize($data);
     514
     515                                // Don't use the data if it was invalid
     516                                if ($data !== false)
     517                                {
     518                                        $this->vars[$var_name] = $data;
     519                                        $this->var_expires[$var_name] = $expires;
     520                                }
     521
     522                                // Absorb the LF
     523                                fgets($handle);
     524                        }
     525
     526                        fclose($handle);
     527
     528                        $this->is_modified = false;
     529
     530                        return true;
     531                }
     532                else
     533                {
     534                        $data = false;
     535                        $line = 0;
     536
     537                        while (($buffer = fgets($handle)) && !feof($handle))
     538                        {
     539                                $buffer = substr($buffer, 0, -1); // Remove the LF
     540
     541                                // $buffer is only used to read integers
     542                                // if it is non numeric we have an invalid
     543                                // cache file, which we will now remove.
     544                                if (!is_numeric($buffer))
     545                                {
     546                                        break;
     547                                }
     548
     549                                if ($line == 0)
     550                                {
     551                                        $expires = (int) $buffer;
     552
     553                                        if (time() >= $expires)
     554                                        {
     555                                                break;
     556                                        }
     557
     558                                        if ($type == 'sql')
     559                                        {
     560                                                // Skip the query
     561                                                fgets($handle);
     562                                        }
     563                                }
     564                                else if ($line == 1)
     565                                {
     566                                        $bytes = (int) $buffer;
     567
     568                                        // Never should have 0 bytes
     569                                        if (!$bytes)
     570                                        {
     571                                                break;
     572                                        }
     573
     574                                        // Grab the serialized data
     575                                        $data = fread($handle, $bytes);
     576
     577                                        // Read 1 byte, to trigger EOF
     578                                        fread($handle, 1);
     579
     580                                        if (!feof($handle))
     581                                        {
     582                                                // Somebody tampered with our data
     583                                                $data = false;
     584                                        }
     585                                        break;
     586                                }
     587                                else
     588                                {
     589                                        // Something went wrong
     590                                        break;
     591                                }
     592                                $line++;
     593                        }
     594                        fclose($handle);
     595
     596                        // unserialize if we got some data
     597                        $data = ($data !== false) ? @unserialize($data) : $data;
     598
     599                        if ($data === false)
     600                        {
     601                                $this->remove_file($file);
     602                                return false;
     603                        }
     604
     605                        return $data;
     606                }
     607        }
     608
     609        /**
     610        * Write cache data to a specified file
     611        *
     612        * 'data_global' is a special case and the generated format is different for this file:
     613        * <code>
     614        * <?php exit; ?>
     615        * (expiration)
     616        * (length of var and serialised data)
     617        * (var)
     618        * (serialised data)
     619        * ... (repeat)
     620        * </code>
     621        *
     622        * The other files have a similar format:
     623        * <code>
     624        * <?php exit; ?>
     625        * (expiration)
     626        * (query) [SQL files only]
     627        * (length of serialised data)
     628        * (serialised data)
     629        * </code>
     630        *
     631        * @access private
     632        * @param string $filename Filename to write
     633        * @param mixed $data Data to store
     634        * @param int $expires Timestamp when the data expires
     635        * @param string $query Query when caching SQL queries
     636        * @return bool True if the file was successfully created, otherwise false
     637        */
     638        function _write($filename, $data = null, $expires = 0, $query = '')
     639        {
     640                global $phpEx;
     641
     642                $file = "{$this->cache_dir}$filename.$phpEx";
     643
     644                if ($handle = @fopen($file, 'wb'))
     645                {
     646                        @flock($handle, LOCK_EX);
     647
     648                        // File header
     649                        fwrite($handle, '<' . '?php exit; ?' . '>');
     650
     651                        if ($filename == 'data_global')
     652                        {
     653                                // Global data is a different format
     654                                foreach ($this->vars as $var => $data)
     655                                {
     656                                        if (strpos($var, "\r") !== false || strpos($var, "\n") !== false)
     657                                        {
     658                                                // CR/LF would cause fgets() to read the cache file incorrectly
     659                                                // do not cache test entries, they probably won't be read back
     660                                                // the cache keys should really be alphanumeric with a few symbols.
     661                                                continue;
     662                                        }
     663                                        $data = serialize($data);
     664
     665                                        // Write out the expiration time
     666                                        fwrite($handle, "\n" . $this->var_expires[$var] . "\n");
     667
     668                                        // Length of the remaining data for this var (ignoring two LF's)
     669                                        fwrite($handle, strlen($data . $var) . "\n");
     670                                        fwrite($handle, $var . "\n");
     671                                        fwrite($handle, $data);
     672                                }
     673                        }
     674                        else
     675                        {
     676                                fwrite($handle, "\n" . $expires . "\n");
     677
     678                                if (strpos($filename, 'sql_') === 0)
     679                                {
     680                                        fwrite($handle, $query . "\n");
     681                                }
     682                                $data = serialize($data);
     683
     684                                fwrite($handle, strlen($data) . "\n");
     685                                fwrite($handle, $data);
     686                        }
     687
     688                        @flock($handle, LOCK_UN);
     689                        fclose($handle);
    430690
    431691                        if (!function_exists('phpbb_chmod'))
     
    435695                        }
    436696
    437                         phpbb_chmod($filename, CHMOD_WRITE);
    438 
    439                         $query_result = $query_id;
    440                 }
    441         }
    442 
    443         /**
    444         * Ceck if a given sql query exist in cache
    445         */
    446         function sql_exists($query_id)
    447         {
    448                 return isset($this->sql_rowset[$query_id]);
    449         }
    450 
    451         /**
    452         * Fetch row from cache (database)
    453         */
    454         function sql_fetchrow($query_id)
    455         {
    456                 if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
    457                 {
    458                         return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
     697                        phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);
     698
     699                        return true;
    459700                }
    460701
    461702                return false;
    462         }
    463 
    464         /**
    465         * Fetch a field from the current row of a cached database result (database)
    466         */
    467         function sql_fetchfield($query_id, $field)
    468         {
    469                 if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
    470                 {
    471                         return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field] : false;
    472                 }
    473 
    474                 return false;
    475         }
    476 
    477         /**
    478         * Seek a specific row in an a cached database result (database)
    479         */
    480         function sql_rowseek($rownum, $query_id)
    481         {
    482                 if ($rownum >= sizeof($this->sql_rowset[$query_id]))
    483                 {
    484                         return false;
    485                 }
    486 
    487                 $this->sql_row_pointer[$query_id] = $rownum;
    488                 return true;
    489         }
    490 
    491         /**
    492         * Free memory used for a cached database result (database)
    493         */
    494         function sql_freeresult($query_id)
    495         {
    496                 if (!isset($this->sql_rowset[$query_id]))
    497                 {
    498                         return false;
    499                 }
    500 
    501                 unset($this->sql_rowset[$query_id]);
    502                 unset($this->sql_row_pointer[$query_id]);
    503 
    504                 return true;
    505703        }
    506704
  • trunk/forum/includes/acp/acp_attachments.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_attachments.php 9041 2008-11-02 11:19:12Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    125125                                                'img_display_inlined'           => array('lang' => 'DISPLAY_INLINED',           'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),
    126126                                                'img_create_thumbnail'          => array('lang' => 'CREATE_THUMBNAIL',          'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),
    127                                                 'img_max_thumb_width'           => array('lang' => 'MAX_THUMB_WIDTH',           'validate' => 'int',    'type' => 'text:7:15', 'explain' => true, 'append' => ' px'),
     127                                                'img_max_thumb_width'           => array('lang' => 'MAX_THUMB_WIDTH',           'validate' => 'int',    'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
    128128                                                'img_min_thumb_filesize'        => array('lang' => 'MIN_THUMB_FILESIZE',        'validate' => 'int',    'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
    129129                                                'img_imagick'                           => array('lang' => 'IMAGICK_PATH',                      'validate' => 'string', 'type' => 'text:20:200', 'explain' => true, 'append' => '&nbsp;&nbsp;<span>[ <a href="' . $this->u_action . '&amp;action=imgmagick">' . $user->lang['SEARCH_IMAGICK'] . '</a> ]</span>'),
    130                                                 'img_max'                                       => array('lang' => 'MAX_IMAGE_SIZE',            'validate' => 'int',    'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
    131                                                 'img_link'                                      => array('lang' => 'IMAGE_LINK_SIZE',           'validate' => 'int',    'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
     130                                                'img_max'                                       => array('lang' => 'MAX_IMAGE_SIZE',            'validate' => 'int',    'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
     131                                                'img_link'                                      => array('lang' => 'IMAGE_LINK_SIZE',           'validate' => 'int',    'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
    132132                                        )
    133133                                );
     
    685685                                                }
    686686
    687                                                 $size_format = ($ext_group_row['max_filesize'] >= 1048576) ? 'mb' : (($ext_group_row['max_filesize'] >= 1024) ? 'kb' : 'b');
    688                                                 $ext_group_row['max_filesize'] = get_formatted_filesize($ext_group_row['max_filesize'], false);
     687                                                $max_filesize = get_formatted_filesize($ext_group_row['max_filesize'], false, array('mb', 'kb', 'b'));
     688                                                $size_format = $max_filesize['si_identifier'];
     689                                                $ext_group_row['max_filesize'] = $max_filesize['value'];
    689690
    690691                                                $img_path = $config['upload_icons_path'];
     
    695696                                                $imglist = filelist($phpbb_root_path . $img_path);
    696697
    697                                                 if (sizeof($imglist))
     698                                                if (!empty($imglist['']))
    698699                                                {
    699700                                                        $imglist = array_values($imglist);
     
    10041005                                                if ($files_added)
    10051006                                                {
    1006                                                         set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
    1007                                                         set_config('num_files', $config['num_files'] + $files_added, true);
     1007                                                        set_config_count('upload_dir_size', $space_taken, true);
     1008                                                        set_config_count('num_files', $files_added, true);
    10081009                                                }
    10091010                                        }
     
    10271028                                                'FILESIZE'                      => get_formatted_filesize($row['filesize']),
    10281029                                                'FILETIME'                      => $user->format_date($row['filetime']),
    1029                                                 'REAL_FILENAME'         => basename($row['real_filename']),
    1030                                                 'PHYSICAL_FILENAME'     => basename($row['physical_filename']),
     1030                                                'REAL_FILENAME'         => utf8_basename($row['real_filename']),
     1031                                                'PHYSICAL_FILENAME'     => utf8_basename($row['physical_filename']),
    10311032                                                'ATTACH_ID'                     => $row['attach_id'],
    10321033                                                'POST_IDS'                      => (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
     
    14301431        {
    14311432                // Determine size var and adjust the value accordingly
    1432                 $size_var = ($value >= 1048576) ? 'mb' : (($value >= 1024) ? 'kb' : 'b');
    1433                 $value = get_formatted_filesize($value, false);
     1433                $filesize = get_formatted_filesize($value, false, array('mb', 'kb', 'b'));
     1434                $size_var = $filesize['si_identifier'];
     1435                $value = $filesize['value'];
    14341436
    14351437                return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
  • trunk/forum/includes/acp/acp_ban.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_ban.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    157157                                        WHERE (ban_end >= ' . time() . "
    158158                                                        OR ban_end = 0)
    159                                                 AND ban_ip <> ''";
     159                                                AND ban_ip <> ''
     160                                        ORDER BY ban_ip";
    160161                        break;
    161162
     
    169170                                        WHERE (ban_end >= ' . time() . "
    170171                                                        OR ban_end = 0)
    171                                                 AND ban_email <> ''";
     172                                                AND ban_email <> ''
     173                                        ORDER BY ban_email";
    172174                        break;
    173175                }
     
    182184
    183185                        $time_length = ($row['ban_end']) ? ($row['ban_end'] - $row['ban_start']) / 60 : 0;
    184                         $ban_length[$row['ban_id']] = (isset($ban_end_text[$time_length])) ? $ban_end_text[$time_length] : $user->lang['UNTIL'] . ' -> ' . $user->format_date($row['ban_end']);
     186
     187                        if ($time_length == 0)
     188                        {
     189                                // Banned permanently
     190                                $ban_length[$row['ban_id']] = $user->lang['PERMANENT'];
     191                        }
     192                        else if (isset($ban_end_text[$time_length]))
     193                        {
     194                                // Banned for a given duration
     195                                $ban_length[$row['ban_id']] = sprintf($user->lang['BANNED_UNTIL_DURATION'], $ban_end_text[$time_length], $user->format_date($row['ban_end'], false, true));
     196                        }
     197                        else
     198                        {
     199                                // Banned until given date
     200                                $ban_length[$row['ban_id']] = sprintf($user->lang['BANNED_UNTIL_DATE'], $user->format_date($row['ban_end'], false, true));
     201                        }
    185202
    186203                        $ban_reasons[$row['ban_id']] = $row['ban_reason'];
  • trunk/forum/includes/acp/acp_bbcodes.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_bbcodes.php 8743 2008-08-12 16:03:18Z Kellanved $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    125125                        case 'create':
    126126
    127                                 $data = $this->build_regexp($bbcode_match, $bbcode_tpl);
    128 
    129                                 // Make sure the user didn't pick a "bad" name for the BBCode tag.
    130                                 $hard_coded = array('code', 'quote', 'quote=', 'attachment', 'attachment=', 'b', 'i', 'url', 'url=', 'img', 'size', 'size=', 'color', 'color=', 'u', 'list', 'list=', 'email', 'email=', 'flash', 'flash=');
    131 
    132                                 if (($action == 'modify' && strtolower($data['bbcode_tag']) !== strtolower($row['bbcode_tag'])) || ($action == 'create'))
    133                                 {
    134                                         $sql = 'SELECT 1 as test
    135                                                 FROM ' . BBCODES_TABLE . "
    136                                                 WHERE LOWER(bbcode_tag) = '" . $db->sql_escape(strtolower($data['bbcode_tag'])) . "'";
    137                                         $result = $db->sql_query($sql);
    138                                         $info = $db->sql_fetchrow($result);
    139                                         $db->sql_freeresult($result);
    140 
    141                                         // Grab the end, interrogate the last closing tag
    142                                         if ($info['test'] === '1' || in_array(strtolower($data['bbcode_tag']), $hard_coded) || (preg_match('#\[/([^[]*)]$#', $bbcode_match, $regs) && in_array(strtolower($regs[1]), $hard_coded)))
    143                                         {
    144                                                 trigger_error($user->lang['BBCODE_INVALID_TAG_NAME'] . adm_back_link($this->u_action), E_USER_WARNING);
    145                                         }
    146                                 }
    147 
    148                                 if (substr($data['bbcode_tag'], -1) === '=')
    149                                 {
    150                                         $test = substr($data['bbcode_tag'], 0, -1);
    151                                 }
    152                                 else
    153                                 {
    154                                         $test = $data['bbcode_tag'];
    155                                 }
    156 
    157                                 if (!preg_match('%\\[' . $test . '[^]]*].*?\\[/' . $test . ']%s', $bbcode_match))
    158                                 {
    159                                         trigger_error($user->lang['BBCODE_OPEN_ENDED_TAG'] . adm_back_link($this->u_action), E_USER_WARNING);
    160                                 }
    161 
    162                                 if (strlen($data['bbcode_tag']) > 16)
    163                                 {
    164                                         trigger_error($user->lang['BBCODE_TAG_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
    165                                 }
    166 
    167                                 if (strlen($bbcode_match) > 4000)
    168                                 {
    169                                         trigger_error($user->lang['BBCODE_TAG_DEF_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
    170                                 }
    171                                
    172                                
    173                                 if (strlen($bbcode_helpline) > 255)
    174                                 {
    175                                         trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
    176                                 }
    177 
    178                                 $sql_ary = array(
    179                                         'bbcode_tag'                            => $data['bbcode_tag'],
    180                                         'bbcode_match'                          => $bbcode_match,
    181                                         'bbcode_tpl'                            => $bbcode_tpl,
    182                                         'display_on_posting'            => $display_on_posting,
    183                                         'bbcode_helpline'                       => $bbcode_helpline,
    184                                         'first_pass_match'                      => $data['first_pass_match'],
    185                                         'first_pass_replace'            => $data['first_pass_replace'],
    186                                         'second_pass_match'                     => $data['second_pass_match'],
    187                                         'second_pass_replace'           => $data['second_pass_replace']
    188                                 );
    189 
    190                                 if ($action == 'create')
    191                                 {
    192                                         $sql = 'SELECT MAX(bbcode_id) as max_bbcode_id
    193                                                 FROM ' . BBCODES_TABLE;
    194                                         $result = $db->sql_query($sql);
    195                                         $row = $db->sql_fetchrow($result);
    196                                         $db->sql_freeresult($result);
    197 
    198                                         if ($row)
    199                                         {
    200                                                 $bbcode_id = $row['max_bbcode_id'] + 1;
    201 
    202                                                 // Make sure it is greater than the core bbcode ids...
    203                                                 if ($bbcode_id <= NUM_CORE_BBCODES)
     127                                $warn_text = preg_match('%<[^>]*\{text[\d]*\}[^>]*>%i', $bbcode_tpl);
     128                                if (!$warn_text || confirm_box(true))
     129                                {
     130                                        $data = $this->build_regexp($bbcode_match, $bbcode_tpl);
     131
     132                                        // Make sure the user didn't pick a "bad" name for the BBCode tag.
     133                                        $hard_coded = array('code', 'quote', 'quote=', 'attachment', 'attachment=', 'b', 'i', 'url', 'url=', 'img', 'size', 'size=', 'color', 'color=', 'u', 'list', 'list=', 'email', 'email=', 'flash', 'flash=');
     134
     135                                        if (($action == 'modify' && strtolower($data['bbcode_tag']) !== strtolower($row['bbcode_tag'])) || ($action == 'create'))
     136                                        {
     137                                                $sql = 'SELECT 1 as test
     138                                                        FROM ' . BBCODES_TABLE . "
     139                                                        WHERE LOWER(bbcode_tag) = '" . $db->sql_escape(strtolower($data['bbcode_tag'])) . "'";
     140                                                $result = $db->sql_query($sql);
     141                                                $info = $db->sql_fetchrow($result);
     142                                                $db->sql_freeresult($result);
     143
     144                                                // Grab the end, interrogate the last closing tag
     145                                                if ($info['test'] === '1' || in_array(strtolower($data['bbcode_tag']), $hard_coded) || (preg_match('#\[/([^[]*)]$#', $bbcode_match, $regs) && in_array(strtolower($regs[1]), $hard_coded)))
     146                                                {
     147                                                        trigger_error($user->lang['BBCODE_INVALID_TAG_NAME'] . adm_back_link($this->u_action), E_USER_WARNING);
     148                                                }
     149                                        }
     150
     151                                        if (substr($data['bbcode_tag'], -1) === '=')
     152                                        {
     153                                                $test = substr($data['bbcode_tag'], 0, -1);
     154                                        }
     155                                        else
     156                                        {
     157                                                $test = $data['bbcode_tag'];
     158                                        }
     159
     160                                        if (!preg_match('%\\[' . $test . '[^]]*].*?\\[/' . $test . ']%s', $bbcode_match))
     161                                        {
     162                                                trigger_error($user->lang['BBCODE_OPEN_ENDED_TAG'] . adm_back_link($this->u_action), E_USER_WARNING);
     163                                        }
     164
     165                                        if (strlen($data['bbcode_tag']) > 16)
     166                                        {
     167                                                trigger_error($user->lang['BBCODE_TAG_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
     168                                        }
     169
     170                                        if (strlen($bbcode_match) > 4000)
     171                                        {
     172                                                trigger_error($user->lang['BBCODE_TAG_DEF_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
     173                                        }
     174
     175
     176                                        if (strlen($bbcode_helpline) > 255)
     177                                        {
     178                                                trigger_error($user->lang['BBCODE_HELPLINE_TOO_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
     179                                        }
     180
     181                                        $sql_ary = array(
     182                                                'bbcode_tag'                            => $data['bbcode_tag'],
     183                                                'bbcode_match'                          => $bbcode_match,
     184                                                'bbcode_tpl'                            => $bbcode_tpl,
     185                                                'display_on_posting'            => $display_on_posting,
     186                                                'bbcode_helpline'                       => $bbcode_helpline,
     187                                                'first_pass_match'                      => $data['first_pass_match'],
     188                                                'first_pass_replace'            => $data['first_pass_replace'],
     189                                                'second_pass_match'                     => $data['second_pass_match'],
     190                                                'second_pass_replace'           => $data['second_pass_replace']
     191                                        );
     192
     193                                        if ($action == 'create')
     194                                        {
     195                                                $sql = 'SELECT MAX(bbcode_id) as max_bbcode_id
     196                                                        FROM ' . BBCODES_TABLE;
     197                                                $result = $db->sql_query($sql);
     198                                                $row = $db->sql_fetchrow($result);
     199                                                $db->sql_freeresult($result);
     200
     201                                                if ($row)
     202                                                {
     203                                                        $bbcode_id = $row['max_bbcode_id'] + 1;
     204
     205                                                        // Make sure it is greater than the core bbcode ids...
     206                                                        if ($bbcode_id <= NUM_CORE_BBCODES)
     207                                                        {
     208                                                                $bbcode_id = NUM_CORE_BBCODES + 1;
     209                                                        }
     210                                                }
     211                                                else
    204212                                                {
    205213                                                        $bbcode_id = NUM_CORE_BBCODES + 1;
    206214                                                }
     215
     216                                                if ($bbcode_id > 1511)
     217                                                {
     218                                                        trigger_error($user->lang['TOO_MANY_BBCODES'] . adm_back_link($this->u_action), E_USER_WARNING);
     219                                                }
     220
     221                                                $sql_ary['bbcode_id'] = (int) $bbcode_id;
     222
     223                                                $db->sql_query('INSERT INTO ' . BBCODES_TABLE . $db->sql_build_array('INSERT', $sql_ary));
     224                                                $cache->destroy('sql', BBCODES_TABLE);
     225
     226                                                $lang = 'BBCODE_ADDED';
     227                                                $log_action = 'LOG_BBCODE_ADD';
    207228                                        }
    208229                                        else
    209230                                        {
    210                                                 $bbcode_id = NUM_CORE_BBCODES + 1;
    211                                         }
    212 
    213                                         if ($bbcode_id > 1511)
    214                                         {
    215                                                 trigger_error($user->lang['TOO_MANY_BBCODES'] . adm_back_link($this->u_action), E_USER_WARNING);
    216                                         }
    217 
    218                                         $sql_ary['bbcode_id'] = (int) $bbcode_id;
    219 
    220                                         $db->sql_query('INSERT INTO ' . BBCODES_TABLE . $db->sql_build_array('INSERT', $sql_ary));
    221                                         $cache->destroy('sql', BBCODES_TABLE);
    222 
    223                                         $lang = 'BBCODE_ADDED';
    224                                         $log_action = 'LOG_BBCODE_ADD';
     231                                                $sql = 'UPDATE ' . BBCODES_TABLE . '
     232                                                        SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
     233                                                        WHERE bbcode_id = ' . $bbcode_id;
     234                                                $db->sql_query($sql);
     235                                                $cache->destroy('sql', BBCODES_TABLE);
     236
     237                                                $lang = 'BBCODE_EDITED';
     238                                                $log_action = 'LOG_BBCODE_EDIT';
     239                                        }
     240
     241                                        add_log('admin', $log_action, $data['bbcode_tag']);
     242
     243                                        trigger_error($user->lang[$lang] . adm_back_link($this->u_action));
    225244                                }
    226245                                else
    227246                                {
    228                                         $sql = 'UPDATE ' . BBCODES_TABLE . '
    229                                                 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
    230                                                 WHERE bbcode_id = ' . $bbcode_id;
    231                                         $db->sql_query($sql);
    232                                         $cache->destroy('sql', BBCODES_TABLE);
    233 
    234                                         $lang = 'BBCODE_EDITED';
    235                                         $log_action = 'LOG_BBCODE_EDIT';
    236                                 }
    237 
    238                                 add_log('admin', $log_action, $data['bbcode_tag']);
    239 
    240                                 trigger_error($user->lang[$lang] . adm_back_link($this->u_action));
     247                                        confirm_box(false, $user->lang['BBCODE_DANGER'], build_hidden_fields(array(
     248                                                'action'                                => $action,
     249                                                'bbcode'                                => $bbcode_id,
     250                                                'bbcode_match'                  => $bbcode_match,
     251                                                'bbcode_tpl'                    => htmlspecialchars($bbcode_tpl),
     252                                                'bbcode_helpline'               => $bbcode_helpline,
     253                                                'display_on_posting'    => $display_on_posting,
     254                                                ))
     255                                        , 'confirm_bbcode.html');
     256                                }
    241257
    242258                        break;
     
    300316                $bbcode_match = trim($bbcode_match);
    301317                $bbcode_tpl = trim($bbcode_tpl);
     318                $utf8 = strpos($bbcode_match, 'INTTEXT') !== false;
     319
     320                // make sure we have utf8 support
     321                $utf8_pcre_properties = false;
     322                if (version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>=')))
     323                {
     324                        // While this is the proper range of PHP versions, PHP may not be linked with the bundled PCRE lib and instead with an older version
     325                        if (@preg_match('/\p{L}/u', 'a') !== false)
     326                        {
     327                                $utf8_pcre_properties = true;
     328                        }
     329                }
    302330
    303331                $fp_match = preg_quote($bbcode_match, '!');
     
    326354                        'SIMPLETEXT' => array(
    327355                                '!([a-zA-Z0-9-+.,_ ]+)!'         =>     "$1"
     356                        ),
     357                        'INTTEXT' => array(
     358                                ($utf8_pcre_properties) ? '!([\p{L}\p{N}\-+,_. ]+)!u' : '!([a-zA-Z0-9\-+,_. ]+)!u'       =>     "$1"
    328359                        ),
    329360                        'IDENTIFIER' => array(
     
    344375                        'TEXT' => '(.*?)',
    345376                        'SIMPLETEXT' => '([a-zA-Z0-9-+.,_ ]+)',
     377                        'INTTEXT' => ($utf8_pcre_properties) ? '([\p{L}\p{N}\-+,_. ]+)' : '([a-zA-Z0-9\-+,_. ]+)',
    346378                        'IDENTIFIER' => '([a-zA-Z0-9-_]+)',
    347379                        'COLOR' => '([a-zA-Z]+|#[0-9abcdefABCDEF]+)',
     
    351383                $pad = 0;
    352384                $modifiers = 'i';
     385                $modifiers .= ($utf8 && $utf8_pcre_properties) ? 'u' : '';
    353386
    354387                if (preg_match_all('/\{(' . implode('|', array_keys($tokens)) . ')[0-9]*\}/i', $bbcode_match, $m))
     
    399432
    400433                        $fp_match = '!' . $fp_match . '!' . $modifiers;
    401                         $sp_match = '!' . $sp_match . '!s';
     434                        $sp_match = '!' . $sp_match . '!s' . (($utf8) ? 'u' : '');
    402435
    403436                        if (strpos($fp_match, 'e') !== false)
  • trunk/forum/includes/acp/acp_board.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_board.php 8911 2008-09-23 13:03:33Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3030                global $db, $user, $auth, $template;
    3131                global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
     32                global $cache;
    3233
    3334                $user->add_lang('acp/board');
    3435
    3536                $action = request_var('action', '');
    36                 $submit = (isset($_POST['submit'])) ? true : false;
     37                $submit = (isset($_POST['submit']) || isset($_POST['allow_quick_reply_enable'])) ? true : false;
    3738
    3839                $form_key = 'acp_board';
     
    6566                                                'legend2'                               => 'WARNINGS',
    6667                                                'warnings_expire_days'  => array('lang' => 'WARNINGS_EXPIRE',           'validate' => 'int',    'type' => 'text:3:4', 'explain' => true, 'append' => ' ' . $user->lang['DAYS']),
     68
     69                                                'legend3'                                       => 'ACP_SUBMIT_CHANGES',
    6770                                        )
    6871                                );
     
    8083                                                'allow_attachments'             => array('lang' => 'ALLOW_ATTACHMENTS',         'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
    8184                                                'allow_pm_attach'               => array('lang' => 'ALLOW_PM_ATTACHMENTS',      'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
     85                                                'allow_pm_report'               => array('lang' => 'ALLOW_PM_REPORT',           'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),
    8286                                                'allow_bbcode'                  => array('lang' => 'ALLOW_BBCODE',                      'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
    8387                                                'allow_smilies'                 => array('lang' => 'ALLOW_SMILIES',                     'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
     
    8690                                                'allow_bookmarks'               => array('lang' => 'ALLOW_BOOKMARKS',           'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),
    8791                                                'allow_birthdays'               => array('lang' => 'ALLOW_BIRTHDAYS',           'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),
     92                                                'allow_quick_reply'             => array('lang' => 'ALLOW_QUICK_REPLY',         'validate' => 'bool',   'type' => 'custom', 'method' => 'quick_reply', 'explain' => true),
    8893
    8994                                                'legend2'                               => 'ACP_LOAD_SETTINGS',
     
    9499                                                'load_cpf_viewprofile'  => array('lang' => 'LOAD_CPF_VIEWPROFILE',      'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
    95100                                                'load_cpf_viewtopic'    => array('lang' => 'LOAD_CPF_VIEWTOPIC',        'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
     101
     102                                                'legend3'                                       => 'ACP_SUBMIT_CHANGES',
    96103                                        )
    97104                                );
     
    109116                                                'avatar_max_height'             => array('lang' => 'MAX_AVATAR_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
    110117
     118                                                'allow_avatar'                  => array('lang' => 'ALLOW_AVATARS',                     'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),
    111119                                                'allow_avatar_local'    => array('lang' => 'ALLOW_LOCAL',                       'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
    112120                                                'allow_avatar_remote'   => array('lang' => 'ALLOW_REMOTE',                      'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),
    113121                                                'allow_avatar_upload'   => array('lang' => 'ALLOW_UPLOAD',                      'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
     122                                                'allow_avatar_remote_upload'=> array('lang' => 'ALLOW_REMOTE_UPLOAD', 'validate' => 'bool',     'type' => 'radio:yes_no', 'explain' => true),
    114123                                                'avatar_filesize'               => array('lang' => 'MAX_FILESIZE',                      'validate' => 'int:0',  'type' => 'text:4:10', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
    115124                                                'avatar_min'                    => array('lang' => 'MIN_AVATAR_SIZE',           'validate' => 'int:0',  'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
     
    144153                                                'auth_img_pm'                   => array('lang' => 'ALLOW_IMG_PM',                      'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
    145154                                                'auth_flash_pm'                 => array('lang' => 'ALLOW_FLASH_PM',            'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),
    146                                                 'enable_pm_icons'               => array('lang' => 'ENABLE_PM_ICONS',           'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false)
     155                                                'enable_pm_icons'               => array('lang' => 'ENABLE_PM_ICONS',           'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
     156
     157                                                'legend3'                                       => 'ACP_SUBMIT_CHANGES',
    147158                                        )
    148159                                );
     
    163174                                                'allow_bookmarks'               => array('lang' => 'ALLOW_BOOKMARKS',           'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),
    164175                                                'enable_post_confirm'   => array('lang' => 'VISUAL_CONFIRM_POST',       'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),
     176                                                'allow_quick_reply'             => array('lang' => 'ALLOW_QUICK_REPLY',         'validate' => 'bool',   'type' => 'custom', 'method' => 'quick_reply', 'explain' => true),
    165177
    166178                                                'legend2'                               => 'POSTING',
    167                                                 'enable_queue_trigger'  => array('lang' => 'ENABLE_QUEUE_TRIGGER',      'validate' => 'bool',           'type' => 'radio:yes_no', 'explain' => true),
    168                                                 'queue_trigger_posts'   => array('lang' => 'QUEUE_TRIGGER_POSTS',       'validate' => 'int:0:250',      'type' => 'text:4:4', 'explain' => true),
    169179                                                'bump_type'                             => false,
    170180                                                'edit_time'                             => array('lang' => 'EDIT_TIME',                         'validate' => 'int:0',          'type' => 'text:5:5', 'explain' => true, 'append' => ' ' . $user->lang['MINUTES']),
     181                                                'delete_time'                   => array('lang' => 'DELETE_TIME',                       'validate' => 'int:0',          'type' => 'text:5:5', 'explain' => true, 'append' => ' ' . $user->lang['MINUTES']),
    171182                                                'display_last_edited'   => array('lang' => 'DISPLAY_LAST_EDITED',       'validate' => 'bool',           'type' => 'radio:yes_no', 'explain' => true),
    172183                                                'flood_interval'                => array('lang' => 'FLOOD_INTERVAL',            'validate' => 'int:0',          'type' => 'text:3:10', 'explain' => true, 'append' => ' ' . $user->lang['SECONDS']),
     
    174185                                                'topics_per_page'               => array('lang' => 'TOPICS_PER_PAGE',           'validate' => 'int:1',          'type' => 'text:3:4', 'explain' => false),
    175186                                                'posts_per_page'                => array('lang' => 'POSTS_PER_PAGE',            'validate' => 'int:1',          'type' => 'text:3:4', 'explain' => false),
     187                                                'smilies_per_page'              => array('lang' => 'SMILIES_PER_PAGE',          'validate' => 'int:1',          'type' => 'text:3:4', 'explain' => false),
    176188                                                'hot_threshold'                 => array('lang' => 'HOT_THRESHOLD',                     'validate' => 'int:0',          'type' => 'text:3:4', 'explain' => true),
    177189                                                'max_poll_options'              => array('lang' => 'MAX_POLL_OPTIONS',          'validate' => 'int:2:127',      'type' => 'text:4:4', 'explain' => false),
    178190                                                'max_post_chars'                => array('lang' => 'CHAR_LIMIT',                        'validate' => 'int:0',          'type' => 'text:4:6', 'explain' => true),
     191                                                'min_post_chars'                => array('lang' => 'MIN_CHAR_LIMIT',            'validate' => 'int:0',          'type' => 'text:4:6', 'explain' => true),
    179192                                                'max_post_smilies'              => array('lang' => 'SMILIES_LIMIT',                     'validate' => 'int:0',          'type' => 'text:4:4', 'explain' => true),
    180193                                                'max_post_urls'                 => array('lang' => 'MAX_POST_URLS',                     'validate' => 'int:0',          'type' => 'text:5:4', 'explain' => true),
     
    183196                                                'max_post_img_width'    => array('lang' => 'MAX_POST_IMG_WIDTH',        'validate' => 'int:0',          'type' => 'text:5:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
    184197                                                'max_post_img_height'   => array('lang' => 'MAX_POST_IMG_HEIGHT',       'validate' => 'int:0',          'type' => 'text:5:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
     198
     199                                                'legend3'                                       => 'ACP_SUBMIT_CHANGES',
    185200                                        )
    186201                                );
     
    206221                                                'max_sig_img_width'             => array('lang' => 'MAX_SIG_IMG_WIDTH',         'validate' => 'int:0',  'type' => 'text:5:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
    207222                                                'max_sig_img_height'    => array('lang' => 'MAX_SIG_IMG_HEIGHT',        'validate' => 'int:0',  'type' => 'text:5:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
     223
     224                                                'legend3'                                       => 'ACP_SUBMIT_CHANGES',
    208225                                        )
    209226                                );
     
    219236
    220237                                                'require_activation'    => array('lang' => 'ACC_ACTIVATION',    'validate' => 'int',    'type' => 'custom', 'method' => 'select_acc_activation', 'explain' => true),
     238                                                'new_member_post_limit' => array('lang' => 'NEW_MEMBER_POST_LIMIT', 'validate' => 'int:0:255', 'type' => 'text:4:4', 'explain' => true, 'append' => ' ' . $user->lang['POSTS']),
     239                                                'new_member_group_default'=> array('lang' => 'NEW_MEMBER_GROUP_DEFAULT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
    221240                                                'min_name_chars'                => array('lang' => 'USERNAME_LENGTH',   'validate' => 'int:1',  'type' => 'custom:5:180', 'method' => 'username_length', 'explain' => true),
    222241                                                'min_pass_chars'                => array('lang' => 'PASSWORD_LENGTH',   'validate' => 'int:1',  'type' => 'custom', 'method' => 'password_length', 'explain' => true),
     
    236255                                                'coppa_mail'            => array('lang' => 'COPPA_MAIL',                'validate' => 'string', 'type' => 'textarea:5:40', 'explain' => true),
    237256                                                'coppa_fax'                     => array('lang' => 'COPPA_FAX',                 'validate' => 'string', 'type' => 'text:25:100', 'explain' => false),
     257
     258                                                'legend4'                       => 'ACP_SUBMIT_CHANGES',
     259                                        )
     260                                );
     261                        break;
     262
     263                        case 'feed':
     264                                $display_vars = array(
     265                                        'title' => 'ACP_FEED_MANAGEMENT',
     266                                        'vars'  => array(
     267                                                'legend1'                                       => 'ACP_FEED_GENERAL',
     268                                                'feed_enable'                           => array('lang' => 'ACP_FEED_ENABLE',                           'validate' => 'bool',   'type' => 'radio:enabled_disabled',     'explain' => true ),
     269                                                'feed_item_statistics'          => array('lang' => 'ACP_FEED_ITEM_STATISTICS',          'validate' => 'bool',   'type' => 'radio:enabled_disabled',     'explain' => true),
     270                                                'feed_http_auth'                        => array('lang' => 'ACP_FEED_HTTP_AUTH',                        'validate' => 'bool',   'type' => 'radio:enabled_disabled',     'explain' => true),
     271
     272                                                'legend2'                                       => 'ACP_FEED_POST_BASED',
     273                                                'feed_limit_post'                       => array('lang' => 'ACP_FEED_LIMIT',                            'validate' => 'int:5',  'type' => 'text:3:4',                           'explain' => true),
     274                                                'feed_overall'                          => array('lang' => 'ACP_FEED_OVERALL',                          'validate' => 'bool',   'type' => 'radio:enabled_disabled',     'explain' => true ),
     275                                                'feed_forum'                            => array('lang' => 'ACP_FEED_FORUM',                            'validate' => 'bool',   'type' => 'radio:enabled_disabled',     'explain' => true ),
     276                                                'feed_topic'                            => array('lang' => 'ACP_FEED_TOPIC',                            'validate' => 'bool',   'type' => 'radio:enabled_disabled',     'explain' => true ),
     277
     278                                                'legend3'                                       => 'ACP_FEED_TOPIC_BASED',
     279                                                'feed_limit_topic'                      => array('lang' => 'ACP_FEED_LIMIT',                            'validate' => 'int:5',  'type' => 'text:3:4',                           'explain' => true),
     280                                                'feed_topics_new'                       => array('lang' => 'ACP_FEED_TOPICS_NEW',                       'validate' => 'bool',   'type' => 'radio:enabled_disabled',     'explain' => true ),
     281                                                'feed_topics_active'            => array('lang' => 'ACP_FEED_TOPICS_ACTIVE',            'validate' => 'bool',   'type' => 'radio:enabled_disabled',     'explain' => true ),
     282                                                'feed_news_id'                          => array('lang' => 'ACP_FEED_NEWS',                                     'validate' => 'string', 'type' => 'custom', 'method' => 'select_news_forums', 'explain' => true),
     283
     284                                                'legend4'                                       => 'ACP_FEED_SETTINGS_OTHER',
     285                                                'feed_overall_forums'           => array('lang' => 'ACP_FEED_OVERALL_FORUMS',           'validate' => 'bool',   'type' => 'radio:enabled_disabled',     'explain' => true ),
     286                                                'feed_exclude_id'                       => array('lang' => 'ACP_FEED_EXCLUDE_ID',                       'validate' => 'string', 'type' => 'custom', 'method' => 'select_exclude_forums', 'explain' => true),
    238287                                        )
    239288                                );
     
    280329                                                'load_cpf_viewprofile'  => array('lang' => 'LOAD_CPF_VIEWPROFILE',      'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
    281330                                                'load_cpf_viewtopic'    => array('lang' => 'LOAD_CPF_VIEWTOPIC',        'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),
     331
     332                                                'legend4'                                       => 'ACP_SUBMIT_CHANGES',
    282333                                        )
    283334                                );
     
    313364                                                'server_port'                   => array('lang' => 'SERVER_PORT',               'validate' => 'int:0',                  'type' => 'text:5:5', 'explain' => true),
    314365                                                'script_path'                   => array('lang' => 'SCRIPT_PATH',               'validate' => 'script_path',    'type' => 'text::255', 'explain' => true),
     366
     367                                                'legend4'                                       => 'ACP_SUBMIT_CHANGES',
    315368                                        )
    316369                                );
     
    361414                                                'smtp_auth_method'              => array('lang' => 'SMTP_AUTH_METHOD',          'validate' => 'string', 'type' => 'select', 'method' => 'mail_auth_select', 'explain' => true),
    362415                                                'smtp_username'                 => array('lang' => 'SMTP_USERNAME',                     'validate' => 'string', 'type' => 'text:25:255', 'explain' => true),
    363                                                 'smtp_password'                 => array('lang' => 'SMTP_PASSWORD',                     'validate' => 'string', 'type' => 'password:25:255', 'explain' => true)
     416                                                'smtp_password'                 => array('lang' => 'SMTP_PASSWORD',                     'validate' => 'string', 'type' => 'password:25:255', 'explain' => true),
     417
     418                                                'legend3'                                       => 'ACP_SUBMIT_CHANGES',
    364419                                        )
    365420                                );
     
    401456                        }
    402457
    403                         if ($config_name == 'auth_method')
     458                        if ($config_name == 'auth_method' || $config_name == 'feed_news_id' || $config_name == 'feed_exclude_id')
    404459                        {
    405460                                continue;
     
    418473                        {
    419474                                set_config($config_name, $config_value);
    420                         }
     475
     476                                if ($config_name == 'allow_quick_reply' && isset($_POST['allow_quick_reply_enable']))
     477                                {
     478                                        enable_bitfield_column_flag(FORUMS_TABLE, 'forum_flags', log(FORUM_FLAG_QUICK_REPLY, 2));
     479                                }
     480                        }
     481                }
     482
     483                // Store news and exclude ids
     484                if ($mode == 'feed' && $submit)
     485                {
     486                        $cache->destroy('_feed_news_forum_ids');
     487                        $cache->destroy('_feed_excluded_forum_ids');
     488
     489                        $this->store_feed_forums(FORUM_OPTION_FEED_NEWS, 'feed_news_id');
     490                        $this->store_feed_forums(FORUM_OPTION_FEED_EXCLUDE, 'feed_exclude_id');
    421491                }
    422492
     
    795865
    796866        /**
     867        * Global quick reply enable/disable setting and button to enable in all forums
     868        */
     869        function quick_reply($value, $key)
     870        {
     871                global $user;
     872
     873                $radio_ary = array(1 => 'YES', 0 => 'NO');
     874
     875                return h_radio('config[allow_quick_reply]', $radio_ary, $value) .
     876                        '<br /><br /><input class="button2" type="submit" id="' . $key . '_enable" name="' . $key . '_enable" value="' . $user->lang['ALLOW_QUICK_REPLY_BUTTON'] . '" />';
     877        }
     878
     879
     880        /**
    797881        * Select default dateformat
    798882        */
     
    831915                <input type=\"text\" name=\"config[$key]\" id=\"$key\" value=\"$value\" maxlength=\"30\" />";
    832916        }
     917
     918        /**
     919        * Select multiple forums
     920        */
     921        function select_news_forums($value, $key)
     922        {
     923                global $user, $config;
     924
     925                $forum_list = make_forum_select(false, false, true, true, true, false, true);
     926
     927                // Build forum options
     928                $s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
     929                foreach ($forum_list as $f_id => $f_row)
     930                {
     931                        $f_row['selected'] = phpbb_optionget(FORUM_OPTION_FEED_NEWS, $f_row['forum_options']);
     932
     933                        $s_forum_options .= '<option value="' . $f_id . '"' . (($f_row['selected']) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
     934                }
     935                $s_forum_options .= '</select>';
     936
     937                return $s_forum_options;
     938        }
     939
     940        function select_exclude_forums($value, $key)
     941        {
     942                global $user, $config;
     943
     944                $forum_list = make_forum_select(false, false, true, true, true, false, true);
     945
     946                // Build forum options
     947                $s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
     948                foreach ($forum_list as $f_id => $f_row)
     949                {
     950                        $f_row['selected'] = phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $f_row['forum_options']);
     951
     952                        $s_forum_options .= '<option value="' . $f_id . '"' . (($f_row['selected']) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
     953                }
     954                $s_forum_options .= '</select>';
     955
     956                return $s_forum_options;
     957        }
     958
     959        function store_feed_forums($option, $key)
     960        {
     961                global $db, $cache;
     962
     963                // Get key
     964                $values = request_var($key, array(0 => 0));
     965
     966                // Empty option bit for all forums
     967                $sql = 'UPDATE ' . FORUMS_TABLE . '
     968                        SET forum_options = forum_options - ' . (1 << $option) . '
     969                        WHERE ' . $db->sql_bit_and('forum_options', $option, '<> 0');
     970                $db->sql_query($sql);
     971
     972                // Already emptied for all...
     973                if (sizeof($values))
     974                {
     975                        // Set for selected forums
     976                        $sql = 'UPDATE ' . FORUMS_TABLE . '
     977                                SET forum_options = forum_options + ' . (1 << $option) . '
     978                                WHERE ' . $db->sql_in_set('forum_id', $values);
     979                        $db->sql_query($sql);
     980                }
     981
     982                // Empty sql cache for forums table because options changed
     983                $cache->destroy('sql', FORUMS_TABLE);
     984        }
     985
    833986}
    834987
  • trunk/forum/includes/acp/acp_captcha.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_captcha.php 8722 2008-07-29 15:13:13Z Kellanved $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3030                $user->add_lang('acp/board');
    3131
     32                include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
     33                $captchas = phpbb_captcha_factory::get_captcha_types();
    3234
    33                 $captcha_vars = array(
    34                         'captcha_gd_x_grid'                             => 'CAPTCHA_GD_X_GRID',
    35                         'captcha_gd_y_grid'                             => 'CAPTCHA_GD_Y_GRID',
    36                         'captcha_gd_foreground_noise'   => 'CAPTCHA_GD_FOREGROUND_NOISE',
    37                         'captcha_gd'                                    => 'CAPTCHA_GD_PREVIEWED'
    38                 );
     35                $selected = request_var('select_captcha', $config['captcha_plugin']);
     36                $selected = (isset($captchas['available'][$selected]) || isset($captchas['unavailable'][$selected])) ? $selected : $config['captcha_plugin'];
     37                $configure = request_var('configure', false);
    3938
    40                 if (isset($_GET['demo']))
     39
     40                // Oh, they are just here for the view
     41                if (isset($_GET['captcha_demo']))
    4142                {
    42                         $captcha_vars = array_keys($captcha_vars);
    43                         foreach ($captcha_vars as $captcha_var)
     43                        $this->deliver_demo($selected);
     44                }
     45
     46                // Delegate
     47                if ($configure)
     48                {
     49                        $config_captcha =& phpbb_captcha_factory::get_instance($selected);
     50                        $config_captcha->acp_page($id, $this);
     51                }
     52                else
     53                {
     54                        $config_vars = array(
     55                                'enable_confirm'                => array('tpl' => 'REG_ENABLE', 'default' => false),
     56                                'enable_post_confirm'   => array('tpl' => 'POST_ENABLE', 'default' => false),
     57                                'confirm_refresh'               => array('tpl' => 'CONFIRM_REFRESH', 'default' => false),
     58                                'max_reg_attempts'              => array('tpl' => 'REG_LIMIT', 'default' => 0),
     59                                'max_login_attempts'            => array('tpl' => 'MAX_LOGIN_ATTEMPTS', 'default' => 0),
     60                        );
     61
     62                        $this->tpl_name = 'acp_captcha';
     63                        $this->page_title = 'ACP_VC_SETTINGS';
     64                        $form_key = 'acp_captcha';
     65                        add_form_key($form_key);
     66
     67                        $submit = request_var('main_submit', false);
     68
     69                        if ($submit && check_form_key($form_key))
    4470                        {
    45                                 $config[$captcha_var] = (isset($_REQUEST[$captcha_var])) ? request_var($captcha_var, 0) : $config[$captcha_var];
     71                                foreach ($config_vars as $config_var => $options)
     72                                {
     73                                        set_config($config_var, request_var($config_var, $options['default']));
     74                                }
     75
     76                                if ($selected !== $config['captcha_plugin'])
     77                                {
     78                                        // sanity check
     79                                        if (isset($captchas['available'][$selected]))
     80                                        {
     81                                                $old_captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
     82                                                $old_captcha->uninstall();
     83
     84                                                set_config('captcha_plugin', $selected);
     85                                                $new_captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
     86                                                $new_captcha->install();
     87
     88                                                add_log('admin', 'LOG_CONFIG_VISUAL');
     89                                        }
     90                                        else
     91                                        {
     92                                                trigger_error($user->lang['CAPTCHA_UNAVAILABLE'] . adm_back_link($this->u_action));
     93                                        }
     94                                }
     95                                trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
    4696                        }
    47                         if ($config['captcha_gd'])
     97                        else if ($submit)
    4898                        {
    49                                 include($phpbb_root_path . 'includes/captcha/captcha_gd.' . $phpEx);
     99                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link());
    50100                        }
    51101                        else
    52102                        {
    53                                 include($phpbb_root_path . 'includes/captcha/captcha_non_gd.' . $phpEx);
     103                                $captcha_select = '';
     104                                foreach ($captchas['available'] as $value => $title)
     105                                {
     106                                        $current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
     107                                        $captcha_select .= '<option value="' . $value . '"' . $current . '>' . $user->lang[$title] . '</option>';
     108                                }
     109
     110                                foreach ($captchas['unavailable'] as $value => $title)
     111                                {
     112                                        $current = ($selected !== false && $value == $selected) ? ' selected="selected"' : '';
     113                                        $captcha_select .= '<option value="' . $value . '"' . $current . ' class="disabled-option">' . $user->lang[$title] . '</option>';
     114                                }
     115
     116                                $demo_captcha =& phpbb_captcha_factory::get_instance($selected);
     117
     118                                foreach ($config_vars as $config_var => $options)
     119                                {
     120                                        $template->assign_var($options['tpl'], (isset($_POST[$config_var])) ? request_var($config_var, $options['default']) : $config[$config_var]) ;
     121                                }
     122
     123                                $template->assign_vars(array(
     124                                        'CAPTCHA_PREVIEW_TPL'   => $demo_captcha->get_demo_template($id),
     125                                        'S_CAPTCHA_HAS_CONFIG'  => $demo_captcha->has_config(),
     126                                        'CAPTCHA_SELECT'                => $captcha_select,
     127                                ));
    54128                        }
    55                         $captcha = new captcha();
    56                         $captcha->execute(gen_rand_string(mt_rand(5, 8)), time());
    57                         exit;
    58129                }
     130        }
    59131
    60                 $config_vars = array(
    61                         'enable_confirm'                => 'REG_ENABLE',
    62                         'enable_post_confirm'   => 'POST_ENABLE',
    63                         'captcha_gd'                    => 'CAPTCHA_GD',
    64                 );
     132        /**
     133        * Entry point for delivering image CAPTCHAs in the ACP.
     134        */
     135        function deliver_demo($selected)
     136        {
     137                global $db, $user, $config;
    65138
    66                 $this->tpl_name = 'acp_captcha';
    67                 $this->page_title = 'ACP_VC_SETTINGS';
    68                 $form_key = 'acp_captcha';
    69                 add_form_key($form_key);
     139                $captcha =& phpbb_captcha_factory::get_instance($selected);
     140                $captcha->init(CONFIRM_REG);
     141                $captcha->execute_demo();
    70142
    71                 $submit = request_var('submit', '');
    72 
    73                 if ($submit && check_form_key($form_key))
    74                 {
    75                         $config_vars = array_keys($config_vars);
    76                         foreach ($config_vars as $config_var)
    77                         {
    78                                 set_config($config_var, request_var($config_var, ''));
    79                         }
    80                         $captcha_vars = array_keys($captcha_vars);
    81                         foreach ($captcha_vars as $captcha_var)
    82                         {
    83                                 $value = request_var($captcha_var, 0);
    84                                 if ($value >= 0)
    85                                 {
    86                                         set_config($captcha_var, $value);
    87                                 }
    88                         }
    89                         trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
    90                 }
    91                 else if ($submit)
    92                 {
    93                                 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action));
    94                 }
    95                 else
    96                 {
    97 
    98                         $preview_image_src = append_sid(append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;demo=demo"));
    99                         if (@extension_loaded('gd'))
    100                         {
    101                                 $template->assign_var('GD', true);
    102                         }
    103                         foreach ($config_vars as $config_var => $template_var)
    104                         {
    105                                 $template->assign_var($template_var, (isset($_REQUEST[$config_var])) ? request_var($config_var, '') : $config[$config_var]) ;
    106                         }
    107                         foreach ($captcha_vars as $captcha_var => $template_var)
    108                         {
    109                                 $var = (isset($_REQUEST[$captcha_var])) ? request_var($captcha_var, 0) : $config[$captcha_var];
    110                                 $template->assign_var($template_var, $var);
    111                                 $preview_image_src .= "&amp;$captcha_var=" . $var;
    112                         }
    113                         $template->assign_vars(array(
    114                                 'CAPTCHA_PREVIEW'       => $preview_image_src,
    115                                 'PREVIEW'                       => isset($_POST['preview']),
    116                         ));
    117 
    118                 }
     143                garbage_collection();
     144                exit_handler();
    119145        }
    120146}
  • trunk/forum/includes/acp/acp_database.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_database.php 8814 2008-09-04 12:01:47Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2828                global $cache, $db, $user, $auth, $template, $table_prefix;
    2929                global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
    30                
     30
    3131                $user->add_lang('acp/database');
    3232
     
    8383
    8484                                                @set_time_limit(1200);
     85                                                @set_time_limit(0);
    8586
    8687                                                $time = time();
     
    142143
    143144                                                                        case 'oracle':
    144                                                                                 $extractor->flush('TRUNCATE TABLE ' . $table_name . "\\\n");
     145                                                                                $extractor->flush('TRUNCATE TABLE ' . $table_name . "/\n");
    145146                                                                        break;
    146147
     
    188189                                                        'U_ACTION'      => $this->u_action . '&amp;action=download'
    189190                                                ));
    190                                                
     191
    191192                                                $available_methods = array('gzip' => 'zlib', 'bzip2' => 'bz2');
    192193
     
    425426                                                $dh = @opendir($dir);
    426427
     428                                                $backup_files = array();
     429
    427430                                                if ($dh)
    428431                                                {
     
    431434                                                                if (preg_match('#^backup_(\d{10,})_[a-z\d]{16}\.(sql(?:\.(?:gz|bz2))?)$#', $file, $matches))
    432435                                                                {
    433                                                                         $supported = in_array($matches[2], $methods);
    434 
    435                                                                         if ($supported == 'true')
     436                                                                        if (in_array($matches[2], $methods))
    436437                                                                        {
    437                                                                                 $template->assign_block_vars('files', array(
    438                                                                                         'FILE'          => $file,
    439                                                                                         'NAME'          => gmdate("d-m-Y H:i:s", $matches[1]),
    440                                                                                         'SUPPORTED'     => $supported
    441                                                                                 ));
     438                                                                                $backup_files[gmdate("d-m-Y H:i:s", $matches[1])] = $file;
    442439                                                                        }
    443440                                                                }
    444441                                                        }
    445442                                                        closedir($dh);
     443                                                }
     444
     445                                                if (!empty($backup_files))
     446                                                {
     447                                                        krsort($backup_files);
     448
     449                                                        foreach ($backup_files as $name => $file)
     450                                                        {
     451                                                                $template->assign_block_vars('files', array(
     452                                                                        'FILE'          => $file,
     453                                                                        'NAME'          => $name,
     454                                                                        'SUPPORTED'     => true,
     455                                                                ));
     456                                                        }
    446457                                                }
    447458
     
    509520                        header("Content-Type: $mimetype; name=\"$name\"");
    510521                        header("Content-disposition: attachment; filename=$name");
    511        
     522
    512523                        switch ($format)
    513524                        {
     
    528539                        }
    529540                }
    530                
     541
    531542                if ($store == true)
    532543                {
    533544                        global $phpbb_root_path;
    534545                        $file = $phpbb_root_path . 'store/' . $filename . $ext;
    535        
     546
    536547                        $this->fp = $open($file, 'w');
    537        
     548
    538549                        if (!$this->fp)
    539550                        {
    540                                 trigger_error('Unable to write temporary file to storage folder', E_USER_ERROR);
     551                                trigger_error('FILE_WRITE_FAIL', E_USER_ERROR);
    541552                        }
    542553                }
     
    546557        {
    547558                static $close;
     559
    548560                if ($this->store)
    549561                {
     
    663675                {
    664676                        $fields_cnt = mysqli_num_fields($result);
    665                
     677
    666678                        // Get field information
    667679                        $field = mysqli_fetch_fields($result);
    668680                        $field_set = array();
    669                
     681
    670682                        for ($j = 0; $j < $fields_cnt; $j++)
    671683                        {
     
    680692                        $query_len              = 0;
    681693                        $max_len                = get_usable_memory();
    682                
     694
    683695                        while ($row = mysqli_fetch_row($result))
    684696                        {
     
    751763                        }
    752764                        $field_set = array();
    753                        
     765
    754766                        for ($j = 0; $j < $fields_cnt; $j++)
    755767                        {
     
    967979                }
    968980                $db->sql_freeresult($result);
    969                
     981
    970982                foreach ($ar as $value)
    971983                {
     
    11251137                }
    11261138                $db->sql_freeresult($result);
    1127        
     1139
    11281140                $field_query = "SELECT a.attnum, a.attname as field, t.typname as type, a.attlen as length, a.atttypmod as lengthvar, a.attnotnull as notnull
    11291141                        FROM pg_class c, pg_attribute a, pg_type t
     
    11461158                                        AND d.adnum = " . $row['attnum'];
    11471159                        $def_res = $db->sql_query($sql_get_default);
    1148 
    1149                         if (!$def_res)
     1160                        $def_row = $db->sql_fetchrow($def_res);
     1161                        $db->sql_freeresult($def_res);
     1162
     1163                        if (empty($def_row))
    11501164                        {
    11511165                                unset($row['rowdefault']);
     
    11531167                        else
    11541168                        {
    1155                                 $row['rowdefault'] = $db->sql_fetchfield('rowdefault', false, $def_res);
    1156                         }
    1157                         $db->sql_freeresult($def_res);
     1169                                $row['rowdefault'] = $def_row['rowdefault'];
     1170                        }
    11581171
    11591172                        if ($row['type'] == 'bpchar')
     
    11891202                                $line .= ' NOT NULL';
    11901203                        }
    1191                        
     1204
    11921205                        $lines[] = $line;
    11931206                }
     
    13891402                $sql_data .= "\nCREATE TABLE [$table_name] (\n";
    13901403                $rows = array();
    1391        
     1404
    13921405                $text_flag = false;
    1393        
     1406
    13941407                $sql = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') as IS_IDENTITY
    13951408                        FROM INFORMATION_SCHEMA.COLUMNS
    13961409                        WHERE TABLE_NAME = '$table_name'";
    13971410                $result = $db->sql_query($sql);
    1398        
     1411
    13991412                while ($row = $db->sql_fetchrow($result))
    14001413                {
    14011414                        $line = "\t[{$row['COLUMN_NAME']}] [{$row['DATA_TYPE']}]";
    1402        
     1415
    14031416                        if ($row['DATA_TYPE'] == 'text')
    14041417                        {
    14051418                                $text_flag = true;
    14061419                        }
    1407        
     1420
    14081421                        if ($row['IS_IDENTITY'])
    14091422                        {
    14101423                                $line .= ' IDENTITY (1 , 1)';
    14111424                        }
    1412        
     1425
    14131426                        if ($row['CHARACTER_MAXIMUM_LENGTH'] && $row['DATA_TYPE'] !== 'text')
    14141427                        {
    14151428                                $line .= ' (' . $row['CHARACTER_MAXIMUM_LENGTH'] . ')';
    14161429                        }
    1417        
     1430
    14181431                        if ($row['IS_NULLABLE'] == 'YES')
    14191432                        {
     
    14241437                                $line .= ' NOT NULL';
    14251438                        }
    1426        
     1439
    14271440                        if ($row['COLUMN_DEFAULT'])
    14281441                        {
    14291442                                $line .= ' DEFAULT ' . $row['COLUMN_DEFAULT'];
    14301443                        }
    1431        
     1444
    14321445                        $rows[] = $line;
    14331446                }
    14341447                $db->sql_freeresult($result);
    1435        
     1448
    14361449                $sql_data .= implode(",\n", $rows);
    14371450                $sql_data .= "\n) ON [PRIMARY]";
    1438        
     1451
    14391452                if ($text_flag)
    14401453                {
    14411454                        $sql_data .= " TEXTIMAGE_ON [PRIMARY]";
    14421455                }
    1443        
     1456
    14441457                $sql_data .= "\nGO\n\n";
    14451458                $rows = array();
    1446        
     1459
    14471460                $sql = "SELECT CONSTRAINT_NAME, COLUMN_NAME
    14481461                        FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
     
    14641477                }
    14651478                $db->sql_freeresult($result);
    1466        
     1479
    14671480                $index = array();
    14681481                $sql = "EXEC sp_statistics '$table_name'";
     
    14761489                }
    14771490                $db->sql_freeresult($result);
    1478        
     1491
    14791492                foreach ($index as $index_name => $column_name)
    14801493                {
    14811494                        $index[$index_name] = implode(', ', $column_name);
    14821495                }
    1483        
     1496
    14841497                foreach ($index as $index_name => $columns)
    14851498                {
     
    15091522                $ident_set = false;
    15101523                $sql_data = '';
    1511                
     1524
    15121525                // Grab all of the data from current table.
    15131526                $sql = "SELECT *
     
    16031616                $ident_set = false;
    16041617                $sql_data = '';
    1605                
     1618
    16061619                // Grab all of the data from current table.
    16071620                $sql = "SELECT *
     
    17041717                global $db;
    17051718                $sql_data = '-- Table: ' . $table_name . "\n";
    1706                 $sql_data .= "DROP TABLE $table_name;\n";
    1707                 $sql_data .= '\\' . "\n";
     1719                $sql_data .= "DROP TABLE $table_name\n/\n";
    17081720                $sql_data .= "\nCREATE TABLE $table_name (\n";
    17091721
     
    17201732                        if ($row['data_type'] !== 'CLOB')
    17211733                        {
    1722                                 if ($row['data_type'] !== 'VARCHAR2')
     1734                                if ($row['data_type'] !== 'VARCHAR2' && $row['data_type'] !== 'CHAR')
    17231735                                {
    17241736                                        $line .= '(' . $row['data_precision'] . ')';
     
    17501762                $result = $db->sql_query($sql);
    17511763
    1752                 while ($row = $db->sql_fetchrow($result))
    1753                 {
    1754                         $rows[] = "  CONSTRAINT {$row['constraint_name']} PRIMARY KEY ({$row['column_name']})";
    1755                 }
    1756                 $db->sql_freeresult($result);
     1764                $primary_key = array();
     1765                $contraint_name = '';
     1766                while ($row = $db->sql_fetchrow($result))
     1767                {
     1768                        $constraint_name = '"' . $row['constraint_name'] . '"';
     1769                        $primary_key[] = '"' . $row['column_name'] . '"';
     1770                }
     1771                $db->sql_freeresult($result);
     1772
     1773                if (sizeof($primary_key))
     1774                {
     1775                        $rows[] = "  CONSTRAINT {$constraint_name} PRIMARY KEY (" . implode(', ', $primary_key) . ')';
     1776                }
    17571777
    17581778                $sql = "SELECT A.CONSTRAINT_NAME, A.COLUMN_NAME
     
    17631783                $result = $db->sql_query($sql);
    17641784
    1765                 while ($row = $db->sql_fetchrow($result))
    1766                 {
    1767                         $rows[] = "  CONSTRAINT {$row['constraint_name']} UNIQUE ({$row['column_name']})";
    1768                 }
    1769                 $db->sql_freeresult($result);
     1785                $unique = array();
     1786                $contraint_name = '';
     1787                while ($row = $db->sql_fetchrow($result))
     1788                {
     1789                        $constraint_name = '"' . $row['constraint_name'] . '"';
     1790                        $unique[] = '"' . $row['column_name'] . '"';
     1791                }
     1792                $db->sql_freeresult($result);
     1793
     1794                if (sizeof($unique))
     1795                {
     1796                        $rows[] = "  CONSTRAINT {$constraint_name} UNIQUE (" . implode(', ', $unique) . ')';
     1797                }
    17701798
    17711799                $sql_data .= implode(",\n", $rows);
    1772                 $sql_data .= "\n)\n\\";
    1773 
    1774                 $sql = "SELECT A.REFERENCED_NAME
    1775                         FROM USER_DEPENDENCIES A, USER_TRIGGERS B
     1800                $sql_data .= "\n)\n/\n";
     1801
     1802                $sql = "SELECT A.REFERENCED_NAME, C.*
     1803                        FROM USER_DEPENDENCIES A, USER_TRIGGERS B, USER_SEQUENCES C
    17761804                        WHERE A.REFERENCED_TYPE = 'SEQUENCE'
    17771805                                AND A.NAME = B.TRIGGER_NAME
    1778                                 AND B. TABLE_NAME = '{$table_name}'";
     1806                                AND B.TABLE_NAME = '{$table_name}'
     1807                                AND C.SEQUENCE_NAME = A.REFERENCED_NAME";
    17791808                $result = $db->sql_query($sql);
    1780                 while ($row = $db->sql_fetchrow($result))
    1781                 {
    1782                         $sql_data .= "\nCREATE SEQUENCE {$row['referenced_name']}\\\n";
     1809
     1810                $type = request_var('type', '');
     1811
     1812                while ($row = $db->sql_fetchrow($result))
     1813                {
     1814                        $sql_data .= "\nDROP SEQUENCE \"{$row['referenced_name']}\"\n/\n";
     1815                        $sql_data .= "\nCREATE SEQUENCE \"{$row['referenced_name']}\"";
     1816
     1817                        if ($type == 'full')
     1818                        {
     1819                                $sql_data .= ' START WITH ' . $row['last_number'];
     1820                        }
     1821
     1822                        $sql_data .= "\n/\n";
    17831823                }
    17841824                $db->sql_freeresult($result);
     
    17901830                while ($row = $db->sql_fetchrow($result))
    17911831                {
    1792                         $sql_data .= "\nCREATE OR REPLACE TRIGGER {$row['description']}WHEN ({$row['when_clause']})\n{$row['trigger_body']}\\";
     1832                        $sql_data .= "\nCREATE OR REPLACE TRIGGER {$row['description']}WHEN ({$row['when_clause']})\n{$row['trigger_body']}\n/\n";
    17931833                }
    17941834                $db->sql_freeresult($result);
     
    18101850                foreach ($index as $index_name => $column_names)
    18111851                {
    1812                         $sql_data .= "\nCREATE INDEX $index_name ON $table_name(" . implode(', ', $column_names) . ")\n\\";
     1852                        $sql_data .= "\nCREATE INDEX $index_name ON $table_name(" . implode(', ', $column_names) . ")\n/\n";
    18131853                }
    18141854                $db->sql_freeresult($result);
     
    18201860                global $db;
    18211861                $ary_type = $ary_name = array();
    1822                
     1862
    18231863                // Grab all of the data from current table.
    18241864                $sql = "SELECT *
     
    18431883                        for ($i = 0; $i < $i_num_fields; $i++)
    18441884                        {
    1845                                 $str_val = $row[$ary_name[$i]];
    1846 
    1847                                 if (preg_match('#char|text|bool|raw#i', $ary_type[$i]))
     1885                                // Oracle uses uppercase - we use lowercase
     1886                                $str_val = $row[strtolower($ary_name[$i])];
     1887
     1888                                if (preg_match('#char|text|bool|raw|clob#i', $ary_type[$i]))
    18481889                                {
    18491890                                        $str_quote = '';
     
    18741915
    18751916                                $schema_vals[$i] = $str_quote . $str_val . $str_quote;
    1876                                 $schema_fields[$i] = '"' . $ary_name[$i] . "'";
     1917                                $schema_fields[$i] = '"' . $ary_name[$i] . '"';
    18771918                        }
    18781919
    18791920                        // Take the ordered fields and their associated data and build it
    18801921                        // into a valid sql statement to recreate that field in the data.
    1881                         $sql_data = "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\n";
     1922                        $sql_data = "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ")\n/\n";
    18821923
    18831924                        $this->flush($sql_data);
     
    19161957                global $db;
    19171958                $ary_type = $ary_name = array();
    1918                
     1959
    19191960                // Grab all of the data from current table.
    19201961                $sql = "SELECT *
     
    21982239function sanitize_data_oracle($text)
    21992240{
    2200         $data = preg_split('/[\0\n\t\r\b\f\'"\\\]/', $text);
    2201         preg_match_all('/[\0\n\t\r\b\f\'"\\\]/', $text, $matches);
     2241//      $data = preg_split('/[\0\n\t\r\b\f\'"\/\\\]/', $text);
     2242//      preg_match_all('/[\0\n\t\r\b\f\'"\/\\\]/', $text, $matches);
     2243        $data = preg_split('/[\0\b\f\'\/]/', $text);
     2244        preg_match_all('/[\0\r\b\f\'\/]/', $text, $matches);
    22022245
    22032246        $val = array();
     
    22452288        $record = '';
    22462289        $delim_len = strlen($delim);
    2247        
     2290
    22482291        while (!$eof($fp))
    22492292        {
  • trunk/forum/includes/acp/acp_email.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_email.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    109109                                        trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
    110110                                }
    111        
     111
    112112                                $i = $j = 0;
    113113
     
    122122                                        if (($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email']) ||
    123123                                                ($row['user_notify_type'] == NOTIFY_IM && $row['user_jabber']) ||
    124                                                 ($row['user_notify_type'] == NOTIFY_BOTH && $row['user_email'] && $row['user_jabber']))
     124                                                ($row['user_notify_type'] == NOTIFY_BOTH && ($row['user_email'] || $row['user_jabber'])))
    125125                                        {
    126126                                                if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type)
     
    174174                                        $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
    175175                                        $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
    176                        
     176
    177177                                        $messenger->subject(htmlspecialchars_decode($subject));
    178178                                        $messenger->set_mail_priority($priority);
     
    182182                                                'MESSAGE'               => htmlspecialchars_decode($message))
    183183                                        );
    184        
     184
    185185                                        if (!($messenger->send($used_method)))
    186186                                        {
     
    240240                $select_list = '<option value="0"' . ((!$group_id) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>';
    241241                $select_list .= group_select_options($group_id, $exclude);
    242                
     242
    243243                $s_priority_options = '<option value="' . MAIL_LOW_PRIORITY . '">' . $user->lang['MAIL_LOW_PRIORITY'] . '</option>';
    244244                $s_priority_options .= '<option value="' . MAIL_NORMAL_PRIORITY . '" selected="selected">' . $user->lang['MAIL_NORMAL_PRIORITY'] . '</option>';
  • trunk/forum/includes/acp/acp_forums.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_forums.php 8898 2008-09-19 17:07:13Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    140140                                                'enable_prune'                  => request_var('enable_prune', false),
    141141                                                'enable_post_review'    => request_var('enable_post_review', true),
     142                                                'enable_quick_reply'    => request_var('enable_quick_reply', false),
    142143                                                'prune_days'                    => request_var('prune_days', 7),
    143144                                                'prune_viewed'                  => request_var('prune_viewed', 7),
     
    151152                                        );
    152153
     154                                        // On add, add empty forum_options... else do not consider it (not updating it)
     155                                        if ($action == 'add')
     156                                        {
     157                                                $forum_data['forum_options'] = 0;
     158                                        }
     159
    153160                                        // Use link_display_on_index setting if forum type is link
    154161                                        if ($forum_data['forum_type'] == FORUM_LINK)
     
    163170                                        }
    164171
    165                                         $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', false) : request_var('display_active', false);
     172                                        $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', true) : request_var('display_active', true);
    166173
    167174                                        // Get data for forum rules if specified...
     
    182189                                        {
    183190                                                $forum_perm_from = request_var('forum_perm_from', 0);
     191                                                $cache->destroy('sql', FORUMS_TABLE);
    184192
    185193                                                // Copy permissions?
    186                                                 if ($forum_perm_from && !empty($forum_perm_from) && $forum_perm_from != $forum_data['forum_id'] &&
    187                                                         (($action != 'edit') || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))))
     194                                                if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] &&
     195                                                        ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))))
    188196                                                {
    189                                                         // if we edit a forum delete current permissions first
    190                                                         if ($action == 'edit')
    191                                                         {
    192                                                                 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
    193                                                                         WHERE forum_id = ' . (int) $forum_data['forum_id'];
    194                                                                 $db->sql_query($sql);
    195 
    196                                                                 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
    197                                                                         WHERE forum_id = ' . (int) $forum_data['forum_id'];
    198                                                                 $db->sql_query($sql);
    199                                                         }
    200 
    201                                                         // From the mysql documentation:
    202                                                         // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
    203                                                         // Due to this we stay on the safe side if we do the insertion "the manual way"
    204 
    205                                                         // Copy permisisons from/to the acl users table (only forum_id gets changed)
    206                                                         $sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
    207                                                                 FROM ' . ACL_USERS_TABLE . '
    208                                                                 WHERE forum_id = ' . $forum_perm_from;
    209                                                         $result = $db->sql_query($sql);
    210 
    211                                                         $users_sql_ary = array();
    212                                                         while ($row = $db->sql_fetchrow($result))
    213                                                         {
    214                                                                 $users_sql_ary[] = array(
    215                                                                         'user_id'                       => (int) $row['user_id'],
    216                                                                         'forum_id'                      => (int) $forum_data['forum_id'],
    217                                                                         'auth_option_id'        => (int) $row['auth_option_id'],
    218                                                                         'auth_role_id'          => (int) $row['auth_role_id'],
    219                                                                         'auth_setting'          => (int) $row['auth_setting']
    220                                                                 );
    221                                                         }
    222                                                         $db->sql_freeresult($result);
    223 
    224                                                         // Copy permisisons from/to the acl groups table (only forum_id gets changed)
    225                                                         $sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
    226                                                                 FROM ' . ACL_GROUPS_TABLE . '
    227                                                                 WHERE forum_id = ' . $forum_perm_from;
    228                                                         $result = $db->sql_query($sql);
    229 
    230                                                         $groups_sql_ary = array();
    231                                                         while ($row = $db->sql_fetchrow($result))
    232                                                         {
    233                                                                 $groups_sql_ary[] = array(
    234                                                                         'group_id'                      => (int) $row['group_id'],
    235                                                                         'forum_id'                      => (int) $forum_data['forum_id'],
    236                                                                         'auth_option_id'        => (int) $row['auth_option_id'],
    237                                                                         'auth_role_id'          => (int) $row['auth_role_id'],
    238                                                                         'auth_setting'          => (int) $row['auth_setting']
    239                                                                 );
    240                                                         }
    241                                                         $db->sql_freeresult($result);
    242 
    243                                                         // Now insert the data
    244                                                         $db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
    245                                                         $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
     197                                                        copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false);
    246198                                                        cache_moderators();
    247199                                                }
    248 
     200/* Commented out because of questionable UI workflow - re-visit for 3.0.7
     201                                                else if (!$this->parent_id && $action != 'edit' && $auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))
     202                                                {
     203                                                        $this->copy_permission_page($forum_data);
     204                                                        return;
     205                                                }
     206*/
    249207                                                $auth->acl_clear_prefetch();
    250                                                 $cache->destroy('sql', FORUMS_TABLE);
    251208
    252209                                                $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_data['forum_id'];
     
    424381                                        $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
    425382                                        $forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
     383                                        $forum_data['forum_flags'] += (request_var('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0;
    426384                                }
    427385
     
    485443                                                        'prune_viewed'                  => 7,
    486444                                                        'prune_freq'                    => 1,
    487                                                         'forum_flags'                   => FORUM_FLAG_POST_REVIEW,
     445                                                        'forum_flags'                   => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS,
     446                                                        'forum_options'                 => 0,
    488447                                                        'forum_password'                => '',
    489448                                                        'forum_password_confirm'=> '',
     
    561520                                        WHERE forum_type = ' . FORUM_POST . "
    562521                                                AND forum_id <> $forum_id";
    563                                 $result = $db->sql_query($sql);
    564 
     522                                $result = $db->sql_query_limit($sql, 1);
     523
     524                                $postable_forum_exists = false;
    565525                                if ($db->sql_fetchrow($result))
    566526                                {
    567                                         $template->assign_vars(array(
    568                                                 'S_MOVE_FORUM_OPTIONS'          => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
    569                                         );
     527                                        $postable_forum_exists = true;
    570528                                }
    571529                                $db->sql_freeresult($result);
     
    584542                                        $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
    585543
    586                                         $sql = 'SELECT forum_id
    587                                                 FROM ' . FORUMS_TABLE . '
    588                                                 WHERE forum_type = ' . FORUM_POST . "
    589                                                         AND forum_id <> $forum_id";
    590                                         $result = $db->sql_query($sql);
    591 
    592                                         if ($db->sql_fetchrow($result))
     544                                        if ($postable_forum_exists)
    593545                                        {
    594546                                                $template->assign_vars(array(
     
    596548                                                );
    597549                                        }
    598                                         $db->sql_freeresult($result);
    599550
    600551                                        $template->assign_vars(array(
    601552                                                'S_HAS_SUBFORUMS'               => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
    602553                                                'S_FORUMS_LIST'                 => $forums_list)
     554                                        );
     555                                }
     556                                else if ($postable_forum_exists)
     557                                {
     558                                        $template->assign_vars(array(
     559                                                'S_MOVE_FORUM_OPTIONS'          => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
    603560                                        );
    604561                                }
     
    685642                                        'S_DISPLAY_ACTIVE_TOPICS'       => ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) ? true : false,
    686643                                        'S_ENABLE_POST_REVIEW'          => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
     644                                        'S_ENABLE_QUICK_REPLY'          => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false,
    687645                                        'S_CAN_COPY_PERMISSIONS'        => ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))) ? true : false,
    688646                                ));
     
    715673                                        WHERE forum_type = ' . FORUM_POST . "
    716674                                                AND forum_id <> $forum_id";
    717                                 $result = $db->sql_query($sql);
     675                                $result = $db->sql_query_limit($sql, 1);
    718676
    719677                                if ($db->sql_fetchrow($result))
     
    743701                                return;
    744702                        break;
     703
     704                        case 'copy_perm':
     705                                $forum_perm_from = request_var('forum_perm_from', 0);
     706
     707                                // Copy permissions?
     708                                if (!empty($forum_perm_from) && $forum_perm_from != $forum_id)
     709                                {
     710                                        copy_forum_permissions($forum_perm_from, $forum_id, true);
     711                                        cache_moderators();
     712                                        $auth->acl_clear_prefetch();
     713                                        $cache->destroy('sql', FORUMS_TABLE);
     714
     715                                        $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_id;
     716
     717                                        $message = $user->lang['FORUM_UPDATED'];
     718
     719                                        // Redirect to permissions
     720                                        if ($auth->acl_get('a_fauth'))
     721                                        {
     722                                                $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
     723                                        }
     724
     725                                        trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
     726                                }
     727
     728                        break;
    745729                }
    746730
     
    807791
    808792                                $url = $this->u_action . "&amp;parent_id=$this->parent_id&amp;f={$row['forum_id']}";
    809 
    810                                 $forum_title = ($forum_type != FORUM_LINK) ? '<a href="' . $this->u_action . '&amp;parent_id=' . $row['forum_id'] . '">' : '';
    811                                 $forum_title .= $row['forum_name'];
    812                                 $forum_title .= ($forum_type != FORUM_LINK) ? '</a>' : '';
    813793
    814794                                $template->assign_block_vars('forums', array(
     
    889869        function update_forum_data(&$forum_data)
    890870        {
    891                 global $db, $user, $cache;
     871                global $db, $user, $cache, $phpbb_root_path;
    892872
    893873                $errors = array();
     
    926906                        array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data['forum_topics_per_page'], 'column_type' => 'TINT:0'),
    927907                );
     908
     909                if (!empty($forum_data['forum_image']) && !file_exists($phpbb_root_path . $forum_data['forum_image']))
     910                {
     911                        $errors[] = $user->lang['FORUM_IMAGE_NO_EXIST'];
     912                }
    928913
    929914                validate_range($range_test_ary, $errors);
     
    943928                $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
    944929                $forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
     930                $forum_data['forum_flags'] += ($forum_data['enable_quick_reply']) ? FORUM_FLAG_QUICK_REPLY : 0;
    945931
    946932                // Unset data that are not database fields
     
    953939                unset($forum_data_sql['show_active']);
    954940                unset($forum_data_sql['enable_post_review']);
     941                unset($forum_data_sql['enable_quick_reply']);
    955942                unset($forum_data_sql['forum_password_confirm']);
    956943
     
    19291916                adm_page_footer();
    19301917        }
     1918
     1919        /**
     1920        * Display copy permission page
     1921        * Not used at the moment - we will have a look at it for 3.0.7
     1922        */
     1923        function copy_permission_page($forum_data)
     1924        {
     1925                global $phpEx, $phpbb_admin_path, $template, $user;
     1926
     1927                $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_data['forum_id'];
     1928                $action = append_sid($this->u_action . "&amp;parent_id={$this->parent_id}&amp;f={$forum_data['forum_id']}&amp;action=copy_perm");
     1929
     1930                $l_acl = sprintf($user->lang['COPY_TO_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
     1931
     1932                $this->tpl_name = 'acp_forums_copy_perm';
     1933
     1934                $template->assign_vars(array(
     1935                        'U_ACL'                         => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url),
     1936                        'L_ACL_LINK'            => $l_acl,
     1937                        'L_BACK_LINK'           => adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id),
     1938                        'S_COPY_ACTION'         => $action,
     1939                        'S_FORUM_OPTIONS'       => make_forum_select($forum_data['parent_id'], $forum_data['forum_id'], false, false, false),
     1940                ));
     1941        }
     1942
    19311943}
    19321944
  • trunk/forum/includes/acp/acp_groups.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_groups.php 9053 2008-11-09 15:10:40Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    310310                                                'max_recipients'        => request_var('group_max_recipients', 0),
    311311                                                'founder_manage'        => 0,
     312                                                'skip_auth'                     => request_var('group_skip_auth', 0),
    312313                                        );
    313314
     
    401402
    402403                                                $group_attributes = array();
    403                                                 $test_variables = array('rank', 'colour', 'avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'receive_pm', 'legend', 'message_limit', 'max_recipients', 'founder_manage');
    404                                                 foreach ($test_variables as $test)
     404                                                $test_variables = array(
     405                                                        'rank'                  => 'int',
     406                                                        'colour'                => 'string',
     407                                                        'avatar'                => 'string',
     408                                                        'avatar_type'   => 'int',
     409                                                        'avatar_width'  => 'int',
     410                                                        'avatar_height' => 'int',
     411                                                        'receive_pm'    => 'int',
     412                                                        'legend'                => 'int',
     413                                                        'message_limit' => 'int',
     414                                                        'max_recipients'=> 'int',
     415                                                        'founder_manage'=> 'int',
     416                                                        'skip_auth'             => 'int',
     417                                                );
     418
     419                                                foreach ($test_variables as $test => $type)
    405420                                                {
    406421                                                        if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test]))
    407422                                                        {
     423                                                                settype($submit_ary[$test], $type);
    408424                                                                $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
    409425                                                        }
     
    563579                                        'GROUP_MAX_RECIPIENTS'  => (isset($group_row['group_max_recipients'])) ? $group_row['group_max_recipients'] : 0,
    564580                                        'GROUP_COLOUR'                  => (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '',
    565 
     581                                        'GROUP_SKIP_AUTH'               => (!empty($group_row['group_skip_auth'])) ? ' checked="checked"' : '',
    566582
    567583                                        'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'],
     
    592608                                        'U_ACTION'                      => "{$this->u_action}&amp;action=$action&amp;g=$group_id",
    593609                                        'L_AVATAR_EXPLAIN'      => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)),
    594                                         )
    595                                 );
     610                                ));
    596611
    597612                                return;
     
    608623
    609624                                // Grab the leaders - always, on every page...
    610                                 $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
     625                                $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_colour, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
    611626                                        FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
    612627                                        WHERE ug.group_id = $group_id
     
    622637
    623638                                                'USERNAME'                      => $row['username'],
     639                                                'USERNAME_COLOUR'       => $row['user_colour'],
    624640                                                'S_GROUP_DEFAULT'       => ($row['group_id'] == $group_id) ? true : false,
    625641                                                'JOINED'                        => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
    626642                                                'USER_POSTS'            => $row['user_posts'],
    627                                                 'USER_ID'                       => $row['user_id'])
    628                                         );
     643                                                'USER_ID'                       => $row['user_id'],
     644                                        ));
    629645                                }
    630646                                $db->sql_freeresult($result);
     
    663679
    664680                                // Grab the members
    665                                 $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
     681                                $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
    666682                                        FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
    667683                                        WHERE ug.group_id = $group_id
     
    688704
    689705                                                'USERNAME'                      => $row['username'],
     706                                                'USERNAME_COLOUR'       => $row['user_colour'],
    690707                                                'S_GROUP_DEFAULT'       => ($row['group_id'] == $group_id) ? true : false,
    691708                                                'JOINED'                        => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
     
    764781                                        'GROUP_NAME'    => $group_name,
    765782                                        'TOTAL_MEMBERS' => $row['total_members'],
    766                                         )
    767                                 );
     783                                ));
    768784                        }
    769785                }
  • trunk/forum/includes/acp/acp_icons.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_icons.php 8974 2008-10-06 13:23:41Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    9090                                        }
    9191
     92                                        // adjust the width and height to be lower than 128px while perserving the aspect ratio (for icons)
     93                                        if ($mode == 'icons')
     94                                        {
     95                                                if ($img_size[0] > 127 && $img_size[0] > $img_size[1])
     96                                                {
     97                                                        $img_size[1] = (int) ($img_size[1] * (127 / $img_size[0]));
     98                                                        $img_size[0] = 127;
     99                                                }
     100                                                else if ($img_size[1] > 127)
     101                                                {
     102                                                        $img_size[0] = (int) ($img_size[0] * (127 / $img_size[1]));
     103                                                        $img_size[1] = 127;
     104                                                }
     105                                        }
     106
    92107                                        $_images[$path . $img]['file'] = $path . $img;
    93108                                        $_images[$path . $img]['width'] = $img_size[0];
     
    169184                                        }
    170185                                }
    171                                
     186
    172187                                $sql = "SELECT *
    173188                                        FROM $table
    174189                                        ORDER BY {$fields}_order " . (($icon_id || $action == 'add') ? 'DESC' : 'ASC');
    175190                                $result = $db->sql_query($sql);
    176                                
     191
    177192                                $data = array();
    178193                                $after = false;
     
    181196                                $add_order_lists = array('', '');
    182197                                $display_count = 0;
    183                                
     198
    184199                                while ($row = $db->sql_fetchrow($result))
    185200                                {
     
    232247                                }
    233248
    234                                 $colspan = (($mode == 'smilies') ? '7' : '5');
     249                                $colspan = (($mode == 'smilies') ? 7 : 5);
    235250                                $colspan += ($icon_id) ? 1 : 0;
    236251                                $colspan += ($action == 'add') ? 2 : 0;
    237                                
     252
    238253                                $template->assign_vars(array(
    239254                                        'S_EDIT'                => true,
    240255                                        'S_SMILIES'             => ($mode == 'smilies') ? true : false,
    241256                                        'S_ADD'                 => ($action == 'add') ? true : false,
    242                                        
     257
    243258                                        'S_ORDER_LIST_DISPLAY'          => $order_list . $order_lists[1],
    244259                                        'S_ORDER_LIST_UNDISPLAY'        => $order_list . $order_lists[0],
     
    287302
    288303                                                'S_IMG_OPTIONS'         => $smiley_options,
    289                                                
     304
    290305                                                'S_ADD_ORDER_LIST_DISPLAY'              => $add_order_list . $add_order_lists[1],
    291306                                                'S_ADD_ORDER_LIST_UNDISPLAY'    => $add_order_list . $add_order_lists[0],
    292                                                
     307
    293308                                                'IMG_SRC'                       => $phpbb_root_path . $img_path . '/' . $default_row['smiley_url'],
    294309                                                'IMG_PATH'                      => $img_path,
     
    304319
    305320                                return;
    306        
     321
    307322                        break;
    308323
     
    312327                                // Get items to create/modify
    313328                                $images = (isset($_POST['image'])) ? array_keys(request_var('image', array('' => 0))) : array();
    314                                
     329
    315330                                // Now really get the items
    316331                                $image_id               = (isset($_POST['id'])) ? request_var('id', array('' => 0)) : array();
     
    349364                                }
    350365
     366                                if ($mode == 'smilies' && $action == 'create')
     367                                {
     368                                        $smiley_count = $this->item_count($table);
     369
     370                                        $addable_smileys_count = sizeof($images);
     371                                        foreach ($images as $image)
     372                                        {
     373                                                if (!isset($image_add[$image]))
     374                                                {
     375                                                        --$addable_smileys_count;
     376                                                }
     377                                        }
     378
     379                                        if ($smiley_count + $addable_smileys_count > SMILEY_LIMIT)
     380                                        {
     381                                                trigger_error(sprintf($user->lang['TOO_MANY_SMILIES'], SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING);
     382                                        }
     383                                }
     384
    351385                                $icons_updated = 0;
    352386                                $errors = array();
     
    368402                                                        $image_width[$image] = $img_size[0];
    369403                                                        $image_height[$image] = $img_size[1];
     404                                                }
     405
     406                                                // Adjust image width/height for icons
     407                                                if ($mode == 'icons')
     408                                                {
     409                                                        if ($image_width[$image] > 127 && $image_width[$image] > $image_height[$image])
     410                                                        {
     411                                                                $image_height[$image] = (int) ($image_height[$image] * (127 / $image_width[$image]));
     412                                                                $image_width[$image] = 127;
     413                                                        }
     414                                                        else if ($image_height[$image] > 127)
     415                                                        {
     416                                                                $image_width[$image] = (int) ($image_width[$image] * (127 / $image_height[$image]));
     417                                                                $image_height[$image] = 127;
     418                                                        }
    370419                                                }
    371420
     
    427476                                                        $icons_updated++;
    428477                                                }
    429                                                
     478
    430479                                        }
    431480                                }
    432                                
     481
    433482                                $cache->destroy('_icons');
    434483                                $cache->destroy('sql', $table);
    435                                
     484
    436485                                $level = E_USER_NOTICE;
    437486                                switch ($icons_updated)
     
    441490                                                $level = E_USER_WARNING;
    442491                                                break;
    443                                                
     492
    444493                                        case 1:
    445494                                                $suc_lang = "{$lang}_ONE";
    446495                                                break;
    447                                                
     496
    448497                                        default:
    449498                                                $suc_lang = $lang;
     
    496545                                        }
    497546
    498 
    499547                                        // The user has already selected a smilies_pak file
    500548                                        if ($current == 'delete')
     
    540588                                                }
    541589                                                $db->sql_freeresult($result);
     590                                        }
     591
     592                                        if ($mode == 'smilies')
     593                                        {
     594                                                $smiley_count = $this->item_count($table);
     595                                                if ($smiley_count + sizeof($pak_ary) > SMILEY_LIMIT)
     596                                                {
     597                                                        trigger_error(sprintf($user->lang['TOO_MANY_SMILIES'], SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING);
     598                                                }
    542599                                        }
    543600
     
    836893
    837894                $spacer = false;
     895                $pagination_start = request_var('start', 0);
     896
     897                $item_count = $this->item_count($table);
    838898
    839899                $sql = "SELECT *
    840900                        FROM $table
    841901                        ORDER BY {$fields}_order ASC";
    842                 $result = $db->sql_query($sql);
     902                $result = $db->sql_query_limit($sql, $config['smilies_per_page'], $pagination_start);
    843903
    844904                while ($row = $db->sql_fetchrow($result))
     
    856916                                'U_EDIT'                => $this->u_action . '&amp;action=edit&amp;id=' . $row[$fields . '_id'],
    857917                                'U_DELETE'              => $this->u_action . '&amp;action=delete&amp;id=' . $row[$fields . '_id'],
    858                                 'U_MOVE_UP'             => $this->u_action . '&amp;action=move_up&amp;id=' . $row[$fields . '_id'],
    859                                 'U_MOVE_DOWN'   => $this->u_action . '&amp;action=move_down&amp;id=' . $row[$fields . '_id'])
    860                         );
     918                                'U_MOVE_UP'             => $this->u_action . '&amp;action=move_up&amp;id=' . $row[$fields . '_id'] . '&amp;start=' . $pagination_start,
     919                                'U_MOVE_DOWN'   => $this->u_action . '&amp;action=move_down&amp;id=' . $row[$fields . '_id'] . '&amp;start=' . $pagination_start,
     920                        ));
    861921
    862922                        if (!$spacer && !$row['display_on_posting'])
     
    866926                }
    867927                $db->sql_freeresult($result);
     928
     929                $template->assign_var('PAGINATION',
     930                        generate_pagination($this->u_action, $item_count, $config['smilies_per_page'], $pagination_start, true)
     931                );
     932        }
     933
     934        /**
     935         * Returns the count of smilies or icons in the database
     936         *
     937         * @param string $table The table of items to count.
     938         * @return int number of items
     939         */
     940        /* private */ function item_count($table)
     941        {
     942                global $db;
     943
     944                $sql = "SELECT COUNT(*) AS item_count
     945                        FROM $table";
     946                $result = $db->sql_query($sql);
     947                $item_count = (int) $db->sql_fetchfield('item_count');
     948                $db->sql_freeresult($result);
     949
     950                return $item_count;
    868951        }
    869952}
  • trunk/forum/includes/acp/acp_inactive.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_inactive.php 8598 2008-06-04 15:37:06Z naderman $
     5* @version $Id$
    66* @copyright (c) 2006 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    5252                add_form_key($form_key);
    5353
     54                // We build the sort key and per page settings here, because they may be needed later
     55
     56                // Number of entries to display
     57                $per_page = request_var('users_per_page', (int) $config['topics_per_page']);
     58
     59                // Sorting
     60                $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
     61                $sort_by_text = array('i' => $user->lang['SORT_INACTIVE'], 'j' => $user->lang['SORT_REG_DATE'], 'l' => $user->lang['SORT_LAST_VISIT'], 'd' => $user->lang['SORT_LAST_REMINDER'], 'r' => $user->lang['SORT_REASON'], 'u' => $user->lang['SORT_USERNAME'], 'p' => $user->lang['SORT_POSTS'], 'e' => $user->lang['SORT_REMINDER']);
     62                $sort_by_sql = array('i' => 'user_inactive_time', 'j' => 'user_regdate', 'l' => 'user_lastvisit', 'd' => 'user_reminded_time', 'r' => 'user_inactive_reason', 'u' => 'username_clean', 'p' => 'user_posts', 'e' => 'user_reminded');
     63
     64                $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
     65                gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
     66
    5467                if ($submit && sizeof($mark))
    5568                {
     
    6881                                                WHERE ' . $db->sql_in_set('user_id', $mark);
    6982                                        $result = $db->sql_query($sql);
    70                                
     83
    7184                                        $user_affected = array();
    7285                                        while ($row = $db->sql_fetchrow($result))
     
    7891                                        if ($action == 'activate')
    7992                                        {
    80                                                 if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
    81                                                 {
    82                                                         // Get those 'being activated'...
    83                                                         $sql = 'SELECT user_id, username, user_email, user_lang
    84                                                                 FROM ' . USERS_TABLE . '
    85                                                                 WHERE ' . $db->sql_in_set('user_id', $mark) . '
    86                                                                         AND user_type = ' . USER_INACTIVE;
    87                                                         $result = $db->sql_query($sql);
    88 
    89                                                         $inactive_users = array();
    90                                                         while ($row = $db->sql_fetchrow($result))
    91                                                         {
    92                                                                 $inactive_users[] = $row;
    93                                                         }
    94                                                         $db->sql_freeresult($result);
    95                                                 }
     93                                                // Get those 'being activated'...
     94                                                $sql = 'SELECT user_id, username' . (($config['require_activation'] == USER_ACTIVATION_ADMIN) ? ', user_email, user_lang' : '') . '
     95                                                        FROM ' . USERS_TABLE . '
     96                                                        WHERE ' . $db->sql_in_set('user_id', $mark) . '
     97                                                                AND user_type = ' . USER_INACTIVE;
     98                                                $result = $db->sql_query($sql);
     99
     100                                                $inactive_users = array();
     101                                                while ($row = $db->sql_fetchrow($result))
     102                                                {
     103                                                        $inactive_users[] = $row;
     104                                                }
     105                                                $db->sql_freeresult($result);
    96106
    97107                                                user_active_flip('activate', $mark);
     
    101111                                                        include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
    102112
    103                                                         $messenger = new messenger();
     113                                                        $messenger = new messenger(false);
    104114
    105115                                                        foreach ($inactive_users as $row)
     
    112122                                                                $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
    113123                                                                $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
     124                                                                $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
    114125
    115126                                                                $messenger->assign_vars(array(
     
    122133                                                        $messenger->save_queue();
    123134                                                }
     135
     136                                                if (!empty($inactive_users))
     137                                                {
     138                                                        foreach ($inactive_users as $row)
     139                                                        {
     140                                                                add_log('admin', 'LOG_USER_ACTIVE', $row['username']);
     141                                                                add_log('user', $row['user_id'], 'LOG_USER_ACTIVE_USER');
     142                                                        }
     143                                                }
     144
     145                                                // For activate we really need to redirect, else a refresh can result in users being deactivated again
     146                                                $u_action = $this->u_action . "&amp;$u_sort_param&amp;start=$start";
     147                                                $u_action .= ($per_page != $config['topics_per_page']) ? "&amp;users_per_page=$per_page" : '';
     148
     149                                                redirect($u_action);
    124150                                        }
    125151                                        else if ($action == 'delete')
     
    162188                                        $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type, user_regdate, user_actkey
    163189                                                FROM ' . USERS_TABLE . '
    164                                                 WHERE ' . $db->sql_in_set('user_id', $mark);
     190                                                WHERE ' . $db->sql_in_set('user_id', $mark) . '
     191                                                        AND user_inactive_reason';
     192
     193                                        $sql .= ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? ' = ' . INACTIVE_REMIND : ' <> ' . INACTIVE_MANUAL;
     194
    165195                                        $result = $db->sql_query($sql);
    166196
     
    171201
    172202                                                $messenger = new messenger();
    173                                                 $usernames = array();
     203                                                $usernames = $user_ids = array();
    174204
    175205                                                do
     
    180210                                                        $messenger->im($row['user_jabber'], $row['username']);
    181211
     212                                                        $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
     213                                                        $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
     214                                                        $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
     215                                                        $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
     216
    182217                                                        $messenger->assign_vars(array(
    183218                                                                'USERNAME'              => htmlspecialchars_decode($row['username']),
    184                                                                 'REGISTER_DATE' => $user->format_date($row['user_regdate']),
     219                                                                'REGISTER_DATE' => $user->format_date($row['user_regdate'], false, true),
    185220                                                                'U_ACTIVATE'    => generate_board_url() . "/ucp.$phpEx?mode=activate&u=" . $row['user_id'] . '&k=' . $row['user_actkey'])
    186221                                                        );
     
    189224
    190225                                                        $usernames[] = $row['username'];
     226                                                        $user_ids[] = (int) $row['user_id'];
    191227                                                }
    192228                                                while ($row = $db->sql_fetchrow($result));
    193229
    194230                                                $messenger->save_queue();
     231
     232                                                // Add the remind state to the database
     233                                                $sql = 'UPDATE ' . USERS_TABLE . '
     234                                                        SET user_reminded = user_reminded + 1,
     235                                                                user_reminded_time = ' . time() . '
     236                                                        WHERE ' . $db->sql_in_set('user_id', $user_ids);
     237                                                $db->sql_query($sql);
    195238
    196239                                                add_log('admin', 'LOG_INACTIVE_REMIND', implode(', ', $usernames));
     
    198241                                        }
    199242                                        $db->sql_freeresult($result);
    200                
     243
     244                                        // For remind we really need to redirect, else a refresh can result in more than one reminder
     245                                        $u_action = $this->u_action . "&amp;$u_sort_param&amp;start=$start";
     246                                        $u_action .= ($per_page != $config['topics_per_page']) ? "&amp;users_per_page=$per_page" : '';
     247
     248                                        redirect($u_action);
     249
    201250                                break;
    202251                        }
    203252                }
    204253
    205                 // Sorting
    206                 $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
    207                 $sort_by_text = array('i' => $user->lang['SORT_INACTIVE'], 'j' => $user->lang['SORT_REG_DATE'], 'l' => $user->lang['SORT_LAST_VISIT'], 'r' => $user->lang['SORT_REASON'], 'u' => $user->lang['SORT_USERNAME']);
    208                 $sort_by_sql = array('i' => 'user_inactive_time', 'j' => 'user_regdate', 'l' => 'user_lastvisit', 'r' => 'user_inactive_reason', 'u' => 'username_clean');
    209 
    210                 $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
    211                 gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
    212 
    213254                // Define where and sort sql for use in displaying logs
    214255                $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
     
    218259                $inactive_count = 0;
    219260
    220                 $start = view_inactive_users($inactive, $inactive_count, $config['topics_per_page'], $start, $sql_where, $sql_sort);
     261                $start = view_inactive_users($inactive, $inactive_count, $per_page, $start, $sql_where, $sql_sort);
    221262
    222263                foreach ($inactive as $row)
     
    224265                        $template->assign_block_vars('inactive', array(
    225266                                'INACTIVE_DATE' => $user->format_date($row['user_inactive_time']),
     267                                'REMINDED_DATE' => $user->format_date($row['user_reminded_time']),
    226268                                'JOINED'                => $user->format_date($row['user_regdate']),
    227269                                'LAST_VISIT'    => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
     270
    228271                                'REASON'                => $row['inactive_reason'],
    229272                                'USER_ID'               => $row['user_id'],
    230                                 'USERNAME'              => $row['username'],
    231                                 'U_USER_ADMIN'  => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}"))
    232                         );
     273                                'POSTS'                 => ($row['user_posts']) ? $row['user_posts'] : 0,
     274                                'REMINDED'              => $row['user_reminded'],
     275
     276                                'REMINDED_EXPLAIN'      => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])),
     277
     278                                'USERNAME_FULL'         => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&amp;mode=overview')),
     279                                'USERNAME'                      => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
     280                                'USER_COLOR'            => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
     281
     282                                'U_USER_ADMIN'  => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}"),
     283                                'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$row['user_id']}&amp;sr=posts") : '',
     284                        ));
    233285                }
    234286
     
    246298                        'S_SORT_KEY'    => $s_sort_key,
    247299                        'S_SORT_DIR'    => $s_sort_dir,
    248                         'S_ON_PAGE'             => on_page($inactive_count, $config['topics_per_page'], $start),
    249                         'PAGINATION'    => generate_pagination($this->u_action . "&amp;$u_sort_param", $inactive_count, $config['topics_per_page'], $start, true),
    250                        
     300                        'S_ON_PAGE'             => on_page($inactive_count, $per_page, $start),
     301                        'PAGINATION'    => generate_pagination($this->u_action . "&amp;$u_sort_param&amp;users_per_page=$per_page", $inactive_count, $per_page, $start, true),
     302                        'USERS_PER_PAGE'        => $per_page,
     303
    251304                        'U_ACTION'              => $this->u_action . '&amp;start=' . $start,
    252305                ));
  • trunk/forum/includes/acp/acp_jabber.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_jabber.php 8990 2008-10-09 15:41:19Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4545                $this->page_title = 'ACP_JABBER_SETTINGS';
    4646
    47                 $jab_enable                     = request_var('jab_enable', $config['jab_enable']);
    48                 $jab_host                       = request_var('jab_host', $config['jab_host']);
    49                 $jab_port                       = request_var('jab_port', $config['jab_port']);
    50                 $jab_username           = request_var('jab_username', $config['jab_username']);
    51                 $jab_password           = request_var('jab_password', $config['jab_password']);
    52                 $jab_package_size       = request_var('jab_package_size', $config['jab_package_size']);
    53                 $jab_use_ssl            = request_var('jab_use_ssl', $config['jab_use_ssl']);
     47                $jab_enable                     = request_var('jab_enable',                     (bool)          $config['jab_enable']);
     48                $jab_host                       = request_var('jab_host',                       (string)        $config['jab_host']);
     49                $jab_port                       = request_var('jab_port',                       (int)           $config['jab_port']);
     50                $jab_username           = request_var('jab_username',           (string)        $config['jab_username']);
     51                $jab_password           = request_var('jab_password',           (string)        $config['jab_password']);
     52                $jab_package_size       = request_var('jab_package_size',       (int)           $config['jab_package_size']);
     53                $jab_use_ssl            = request_var('jab_use_ssl',            (bool)          $config['jab_use_ssl']);
    5454
    5555                $form_name = 'acp_jabber';
     
    8989                        {
    9090                                // This feature is disabled.
    91                                 // We update the user table to be sure all users that have IM as notify type are set to both  as notify type
     91                                // We update the user table to be sure all users that have IM as notify type are set to both as notify type
     92                                // We set this to both because users still have their jabber address entered and may want to receive jabber notifications again once it is re-enabled.
    9293                                $sql_ary = array(
    9394                                        'user_notify_type'              => NOTIFY_BOTH,
     
    117118                        'L_JAB_SERVER_EXPLAIN'  => sprintf($user->lang['JAB_SERVER_EXPLAIN'], '<a href="http://www.jabber.org/">', '</a>'),
    118119                        'JAB_HOST'                              => $jab_host,
    119                         'JAB_PORT'                              => $jab_port,
     120                        'JAB_PORT'                              => ($jab_port) ? $jab_port : '',
    120121                        'JAB_USERNAME'                  => $jab_username,
    121122                        'JAB_PASSWORD'                  => $jab_password,
  • trunk/forum/includes/acp/acp_language.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_language.php 8780 2008-08-22 12:52:48Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    767767                                }
    768768
    769                                 $db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id);
    770 
    771                                 $sql = 'UPDATE ' . USERS_TABLE . "
    772                                         SET user_lang = '" . $db->sql_escape($config['default_lang']) . "'
    773                                         WHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
    774                                 $db->sql_query($sql);
    775 
    776                                 // We also need to remove the translated entries for custom profile fields - we want clean tables, don't we?
    777                                 $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
    778                                 $db->sql_query($sql);
    779 
    780                                 $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
    781                                 $db->sql_query($sql);
    782 
    783                                 $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " WHERE image_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
    784                                 $result = $db->sql_query($sql);
    785 
    786                                 $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
    787 
    788                                 add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']);
    789 
    790                                 trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action));
     769                                if (confirm_box(true))
     770                                {
     771                                        $db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id);
     772
     773                                        $sql = 'UPDATE ' . USERS_TABLE . "
     774                                                SET user_lang = '" . $db->sql_escape($config['default_lang']) . "'
     775                                                WHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
     776                                        $db->sql_query($sql);
     777
     778                                        // We also need to remove the translated entries for custom profile fields - we want clean tables, don't we?
     779                                        $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
     780                                        $db->sql_query($sql);
     781
     782                                        $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
     783                                        $db->sql_query($sql);
     784
     785                                        $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " WHERE image_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
     786                                        $result = $db->sql_query($sql);
     787
     788                                        $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
     789
     790                                        add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']);
     791
     792                                        trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action));
     793                                }
     794                                else
     795                                {
     796                                        $s_hidden_fields = array(
     797                                                'i'                     => $id,
     798                                                'mode'          => $mode,
     799                                                'action'        => $action,
     800                                                'id'            => $lang_id,
     801                                        );
     802                                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
     803                                }
    791804                        break;
    792805
     
    11081121                        while (($file = readdir($dp)) !== false)
    11091122                        {
     1123                                if (!is_dir($phpbb_root_path . 'language/' . $file))
     1124                                {
     1125                                        continue;
     1126                                }
     1127
    11101128                                if ($file[0] != '.' && file_exists("{$phpbb_root_path}language/$file/iso.txt"))
    11111129                                {
     
    12551273
    12561274                $non_static             = array_shift($keys);
    1257                 $value                  = array_shift($keys);
     1275                $value                  = utf8_normalize_nfc(array_shift($keys));
    12581276
    12591277                if (!$non_static)
  • trunk/forum/includes/acp/acp_logs.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_logs.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3434                $action         = request_var('action', '');
    3535                $forum_id       = request_var('f', 0);
     36                $topic_id       = request_var('t', 0);
    3637                $start          = request_var('start', 0);
    3738                $deletemark = (!empty($_POST['delmarked'])) ? true : false;
     
    105106                $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
    106107
     108                $keywords = utf8_normalize_nfc(request_var('keywords', '', true));
     109                $keywords_param = !empty($keywords) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
     110
    107111                $l_title = $user->lang['ACP_' . strtoupper($mode) . '_LOGS'];
    108112                $l_title_explain = $user->lang['ACP_' . strtoupper($mode) . '_LOGS_EXPLAIN'];
     
    124128                $log_data = array();
    125129                $log_count = 0;
    126                 view_log($mode, $log_data, $log_count, $config['topics_per_page'], $start, $forum_id, 0, 0, $sql_where, $sql_sort);
     130                view_log($mode, $log_data, $log_count, $config['topics_per_page'], $start, $forum_id, 0, 0, $sql_where, $sql_sort, $keywords);
    127131
    128132                $template->assign_vars(array(
     
    132136
    133137                        'S_ON_PAGE'             => on_page($log_count, $config['topics_per_page'], $start),
    134                         'PAGINATION'    => generate_pagination($this->u_action . "&amp;$u_sort_param", $log_count, $config['topics_per_page'], $start, true),
     138                        'PAGINATION'    => generate_pagination($this->u_action . "&amp;$u_sort_param$keywords_param", $log_count, $config['topics_per_page'], $start, true),
    135139
    136140                        'S_LIMIT_DAYS'  => $s_limit_days,
     
    138142                        'S_SORT_DIR'    => $s_sort_dir,
    139143                        'S_CLEARLOGS'   => $auth->acl_get('a_clearlogs'),
     144                        'S_KEYWORDS'    => $keywords,
    140145                        )
    141146                );
  • trunk/forum/includes/acp/acp_main.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_main.php 9171 2008-12-04 14:53:04Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    9797                                                $confirm = true;
    9898                                                $confirm_lang = 'PURGE_CACHE_CONFIRM';
     99                                        break;
     100                                        case 'purge_sessions':
     101                                                $confirm = true;
     102                                                $confirm_lang = 'PURGE_SESSIONS_CONFIRM';
    99103                                        break;
    100104
     
    342346                                                add_log('admin', 'LOG_PURGE_CACHE');
    343347                                        break;
     348
     349                                        case 'purge_sessions':
     350                                                if ((int) $user->data['user_type'] !== USER_FOUNDER)
     351                                                {
     352                                                        trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
     353                                                }
     354
     355                                                $tables = array(CONFIRM_TABLE, SESSIONS_TABLE);
     356
     357                                                foreach ($tables as $table)
     358                                                {
     359                                                        switch ($db->sql_layer)
     360                                                        {
     361                                                                case 'sqlite':
     362                                                                case 'firebird':
     363                                                                        $db->sql_query("DELETE FROM $table");
     364                                                                break;
     365
     366                                                                default:
     367                                                                        $db->sql_query("TRUNCATE TABLE $table");
     368                                                                break;
     369                                                        }
     370                                                }
     371
     372                                                // let's restore the admin session
     373                                                $reinsert_ary = array(
     374                                                                'session_id'                    => (string) $user->session_id,
     375                                                                'session_page'                  => (string) substr($user->page['page'], 0, 199),
     376                                                                'session_forum_id'              => $user->page['forum'],
     377                                                                'session_user_id'               => (int) $user->data['user_id'],
     378                                                                'session_start'                 => (int) $user->data['session_start'],
     379                                                                'session_last_visit'    => (int) $user->data['session_last_visit'],
     380                                                                'session_time'                  => (int) $user->time_now,
     381                                                                'session_browser'               => (string) trim(substr($user->browser, 0, 149)),
     382                                                                'session_forwarded_for' => (string) $user->forwarded_for,
     383                                                                'session_ip'                    => (string) $user->ip,
     384                                                                'session_autologin'             => (int) $user->data['session_autologin'],
     385                                                                'session_admin'                 => 1,
     386                                                                'session_viewonline'    => (int) $user->data['session_viewonline'],
     387                                                );
     388
     389                                                $sql = 'INSERT INTO ' . SESSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $reinsert_ary);
     390                                                $db->sql_query($sql);
     391
     392                                                add_log('admin', 'LOG_PURGE_SESSIONS');
     393                                        break;
    344394                                }
    345395                        }
     396                }
     397
     398                // Version check
     399                $user->add_lang('install');
     400
     401                if ($auth->acl_get('a_server') && version_compare(PHP_VERSION, '5.2.0', '<'))
     402                {
     403                        $template->assign_vars(array(
     404                                'S_PHP_VERSION_OLD'     => true,
     405                                'L_PHP_VERSION_OLD'     => sprintf($user->lang['PHP_VERSION_OLD'], '<a href="http://www.phpbb.com/community/viewtopic.php?f=14&amp;t=1958605">', '</a>'),
     406                        ));
     407                }
     408
     409                $latest_version_info = false;
     410                if (($latest_version_info = obtain_latest_version_info(request_var('versioncheck_force', false))) === false)
     411                {
     412                        $template->assign_var('S_VERSIONCHECK_FAIL', true);
     413                }
     414                else
     415                {
     416                        $latest_version_info = explode("\n", $latest_version_info);
     417
     418                        $latest_version = str_replace('rc', 'RC', strtolower(trim($latest_version_info[0])));
     419                        $current_version = str_replace('rc', 'RC', strtolower($config['version']));
     420
     421                        $template->assign_vars(array(
     422                                'S_VERSION_UP_TO_DATE'  => version_compare($current_version, $latest_version, '<') ? false : true,
     423                        ));
    346424                }
    347425
     
    436514                        'TOTAL_ORPHAN'          => $total_orphan,
    437515                        'S_TOTAL_ORPHAN'        => ($total_orphan === false) ? false : true,
    438                         'GZIP_COMPRESSION'      => ($config['gzip_compress']) ? $user->lang['ON'] : $user->lang['OFF'],
     516                        'GZIP_COMPRESSION'      => ($config['gzip_compress'] && @extension_loaded('zlib')) ? $user->lang['ON'] : $user->lang['OFF'],
    439517                        'DATABASE_INFO'         => $db->sql_server_info(),
    440518                        'BOARD_VERSION'         => $config['version'],
     
    443521                        'U_ADMIN_LOG'           => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&amp;mode=admin'),
    444522                        'U_INACTIVE_USERS'      => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=inactive&amp;mode=list'),
     523                        'U_VERSIONCHECK'        => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=update&amp;mode=version_check'),
     524                        'U_VERSIONCHECK_FORCE'  => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=1&amp;versioncheck_force=1'),
    445525
    446526                        'S_ACTION_OPTIONS'      => ($auth->acl_get('a_board')) ? true : false,
     
    469549                if ($auth->acl_get('a_user'))
    470550                {
     551                        $user->add_lang('memberlist');
     552
    471553                        $inactive = array();
    472554                        $inactive_count = 0;
     
    478560                                $template->assign_block_vars('inactive', array(
    479561                                        'INACTIVE_DATE' => $user->format_date($row['user_inactive_time']),
     562                                        'REMINDED_DATE' => $user->format_date($row['user_reminded_time']),
    480563                                        'JOINED'                => $user->format_date($row['user_regdate']),
    481564                                        'LAST_VISIT'    => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
     565
    482566                                        'REASON'                => $row['inactive_reason'],
    483567                                        'USER_ID'               => $row['user_id'],
    484                                         'USERNAME'              => $row['username'],
    485                                         'U_USER_ADMIN'  => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}"))
    486                                 );
     568                                        'POSTS'                 => ($row['user_posts']) ? $row['user_posts'] : 0,
     569                                        'REMINDED'              => $row['user_reminded'],
     570
     571                                        'REMINDED_EXPLAIN'      => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])),
     572
     573                                        'USERNAME_FULL'         => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&amp;mode=overview')),
     574                                        'USERNAME'                      => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
     575                                        'USER_COLOR'            => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
     576
     577                                        'U_USER_ADMIN'  => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}"),
     578                                        'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$row['user_id']}&amp;sr=posts") : '',
     579                                ));
    487580                        }
    488581
     
    500593
    501594                // Warn if install is still present
    502                 if (file_exists($phpbb_root_path . 'install'))
     595                if (file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
    503596                {
    504597                        $template->assign_var('S_REMOVE_INSTALL', true);
    505598                }
    506599
    507                 if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && is_writable($phpbb_root_path . 'config.' . $phpEx))
     600                if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx))
    508601                {
    509602                        // World-Writable? (000x)
    510603                        $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x0002));
     604                }
     605
     606                // Fill dbms version if not yet filled
     607                if (empty($config['dbms_version']))
     608                {
     609                        set_config('dbms_version', $db->sql_server_info(true));
    511610                }
    512611
  • trunk/forum/includes/acp/acp_permissions.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_permissions.php 8710 2008-07-29 13:35:49Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2424        var $u_action;
    2525        var $permission_dropdown;
    26        
     26
    2727        function main($id, $mode)
    2828        {
     
    5555                                return;
    5656                        }
     57                        trigger_error('NO_MODE', E_USER_ERROR);
     58                }
     59
     60                // Copy forum permissions
     61                if ($mode == 'setting_forum_copy')
     62                {
     63                        $this->tpl_name = 'permission_forum_copy';
     64
     65                        if ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))
     66                        {
     67                                $this->page_title = 'ACP_FORUM_PERMISSIONS_COPY';
     68                                $this->copy_forum_permissions();
     69                                return;
     70                        }
     71
    5772                        trigger_error('NO_MODE', E_USER_ERROR);
    5873                }
     
    95110                        $db->sql_freeresult($result);
    96111                }
    97                
     112
    98113                // Map usernames to ids and vice versa
    99114                if ($usernames)
     
    113128                }
    114129                unset($username);
    115                
     130
    116131                // Build forum ids (of all forums are checked or subforum listing used)
    117132                if ($all_forums)
     
    218233                }
    219234
    220 
    221235                // Handle actions
    222236                if (strpos($mode, 'setting_') === 0 && $action)
     
    225239                        {
    226240                                case 'delete':
    227 
    228                                         if (!check_form_key($form_name))
    229                                         {
    230                                                 trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
    231                                         }
    232                                         // All users/groups selected?
    233                                         $all_users = (isset($_POST['all_users'])) ? true : false;
    234                                         $all_groups = (isset($_POST['all_groups'])) ? true : false;
    235 
    236                                         if ($all_users || $all_groups)
    237                                         {
    238                                                 $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type);
    239 
    240                                                 if ($all_users && sizeof($items['user_ids']))
     241                                        if (confirm_box(true))
     242                                        {
     243                                                // All users/groups selected?
     244                                                $all_users = (isset($_POST['all_users'])) ? true : false;
     245                                                $all_groups = (isset($_POST['all_groups'])) ? true : false;
     246
     247                                                if ($all_users || $all_groups)
    241248                                                {
    242                                                         $user_id = $items['user_ids'];
     249                                                        $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type);
     250
     251                                                        if ($all_users && sizeof($items['user_ids']))
     252                                                        {
     253                                                                $user_id = $items['user_ids'];
     254                                                        }
     255                                                        else if ($all_groups && sizeof($items['group_ids']))
     256                                                        {
     257                                                                $group_id = $items['group_ids'];
     258                                                        }
    243259                                                }
    244                                                 else if ($all_groups && sizeof($items['group_ids']))
     260
     261                                                if (sizeof($user_id) || sizeof($group_id))
    245262                                                {
    246                                                         $group_id = $items['group_ids'];
     263                                                        $this->remove_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id, $forum_id);
    247264                                                }
    248                                         }
    249 
    250                                         if (sizeof($user_id) || sizeof($group_id))
    251                                         {
    252                                                 $this->remove_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id, $forum_id);
     265                                                else
     266                                                {
     267                                                        trigger_error($user->lang['NO_USER_GROUP_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
     268                                                }
    253269                                        }
    254270                                        else
    255271                                        {
    256                                                 trigger_error($user->lang['NO_USER_GROUP_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
     272                                                if (isset($_POST['cancel']))
     273                                                {
     274                                                        $u_redirect = $this->u_action . '&amp;type=' . $permission_type;
     275                                                        foreach ($forum_id as $fid)
     276                                                        {
     277                                                                $u_redirect .= '&amp;forum_id[]=' . $fid;
     278                                                        }
     279                                                        redirect($u_redirect);
     280                                                }
     281
     282                                                $s_hidden_fields = array(
     283                                                        'i'                             => $id,
     284                                                        'mode'                  => $mode,
     285                                                        'action'                => array($action => 1),
     286                                                        'user_id'               => $user_id,
     287                                                        'group_id'              => $group_id,
     288                                                        'forum_id'              => $forum_id,
     289                                                        'type'                  => $permission_type,
     290                                                );
     291                                                if (isset($_POST['all_users']))
     292                                                {
     293                                                        $s_hidden_fields['all_users'] = 1;
     294                                                }
     295                                                if (isset($_POST['all_groups']))
     296                                                {
     297                                                        $s_hidden_fields['all_groups'] = 1;
     298                                                }
     299                                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
    257300                                        }
    258301                                break;
     
    529572                                continue;
    530573                        }
    531                        
     574
    532575                        if ($branch_there)
    533576                        {
     
    540583                return $s_options;
    541584        }
    542        
     585
    543586        /**
    544587        * Build dropdown field for changing permission types
     
    547590        {
    548591                global $user, $auth;
    549                
     592
    550593                $s_dropdown_options = '';
    551594                foreach ($options as $setting)
     
    627670                        trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
    628671                }
    629                
     672
    630673                $ug_id = $forum_id = 0;
    631674
     
    763806                $this->log_action($mode, 'add', $permission_type, $ug_type, $ug_ids, $forum_ids);
    764807
    765                 trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
     808                if ($mode == 'setting_forum_local' || $mode == 'setting_mod_local')
     809                {
     810                        trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action . '&amp;forum_id[]=' . implode('&amp;forum_id[]=', $forum_ids)));
     811                }
     812                else
     813                {
     814                        trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
     815                }
    766816        }
    767817
     
    810860        {
    811861                global $user, $db, $auth;
    812                        
     862
    813863                // User or group to be set?
    814864                $ug_type = (sizeof($user_id)) ? 'user' : 'group';
     
    830880                $this->log_action($mode, 'del', $permission_type, $ug_type, (($ug_type == 'user') ? $user_id : $group_id), (sizeof($forum_id) ? $forum_id : array(0 => 0)));
    831881
    832                 trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
     882                if ($mode == 'setting_forum_local' || $mode == 'setting_mod_local')
     883                {
     884                        trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action . '&amp;forum_id[]=' . implode('&amp;forum_id[]=', $forum_id)));
     885                }
     886                else
     887                {
     888                        trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
     889                }
    833890        }
    834891
     
    9501007                        WHERE ug.user_id = ' . $user_id . '
    9511008                                AND ug.user_pending = 0
     1009                                AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
    9521010                        ORDER BY g.group_type DESC, g.group_id DESC';
    9531011                $result = $db->sql_query($sql);
     
    11111169
    11121170        /**
     1171        * Handles copying permissions from one forum to others
     1172        */
     1173        function copy_forum_permissions()
     1174        {
     1175                global $auth, $cache, $template, $user;
     1176
     1177                $user->add_lang('acp/forums');
     1178
     1179                $submit = isset($_POST['submit']) ? true : false;
     1180
     1181                if ($submit)
     1182                {
     1183                        $src = request_var('src_forum_id', 0);
     1184                        $dest = request_var('dest_forum_ids', array(0));
     1185
     1186                        if (confirm_box(true))
     1187                        {
     1188                                if (copy_forum_permissions($src, $dest))
     1189                                {
     1190                                        cache_moderators();
     1191
     1192                                        $auth->acl_clear_prefetch();
     1193                                        $cache->destroy('sql', FORUMS_TABLE);
     1194
     1195                                        trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
     1196                                }
     1197                                else
     1198                                {
     1199                                        trigger_error($user->lang['SELECTED_FORUM_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
     1200                                }
     1201                        }
     1202                        else
     1203                        {
     1204                                $s_hidden_fields = array(
     1205                                        'submit'                        => $submit,
     1206                                        'src_forum_id'          => $src,
     1207                                        'dest_forum_ids'        => $dest,
     1208                                );
     1209
     1210                                $s_hidden_fields = build_hidden_fields($s_hidden_fields);
     1211
     1212                                confirm_box(false, $user->lang['COPY_PERMISSIONS_CONFIRM'], $s_hidden_fields);
     1213                        }
     1214                }
     1215
     1216                $template->assign_vars(array(
     1217                        'S_FORUM_OPTIONS' => make_forum_select(false, false, false, false, false),
     1218                ));
     1219        }
     1220
     1221        /**
    11131222        * Get already assigned users/groups
    11141223        */
     
    11511260                        $sql_where = 'AND (' . $db->sql_in_set('a.auth_option_id', $option_ids) . ' OR ' . $db->sql_in_set('a.auth_role_id', $role_ids) . ')';
    11521261                }
    1153                 else
     1262                else if (sizeof($role_ids))
     1263                {
     1264                        $sql_where = 'AND ' . $db->sql_in_set('a.auth_role_id', $role_ids);
     1265                }
     1266                else if (sizeof($option_ids))
    11541267                {
    11551268                        $sql_where = 'AND ' . $db->sql_in_set('a.auth_option_id', $option_ids);
  • trunk/forum/includes/acp/acp_profile.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_profile.php 9127 2008-11-26 19:58:35Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    370370                                                'field_no_view'         => 0,
    371371                                                'field_show_on_reg'     => 0,
     372                                                'field_show_on_vt'      => 0,
    372373                                                'lang_name'                     => utf8_normalize_nfc(request_var('field_ident', '', true)),
    373374                                                'lang_explain'          => '',
     
    380381                                // $exclude contains the data we gather in each step
    381382                                $exclude = array(
    382                                         1       => array('field_ident', 'lang_name', 'lang_explain', 'field_option_none', 'field_show_on_reg', 'field_required', 'field_hide', 'field_show_profile', 'field_no_view'),
     383                                        1       => array('field_ident', 'lang_name', 'lang_explain', 'field_option_none', 'field_show_on_reg', 'field_show_on_vt', 'field_required', 'field_hide', 'field_show_profile', 'field_no_view'),
    383384                                        2       => array('field_length', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'),
    384385                                        3       => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
     
    406407                                        'field_required',
    407408                                        'field_show_on_reg',
     409                                        'field_show_on_vt',
    408410                                        'field_show_profile',
    409411                                        'field_hide',
     
    508510                                                $var = request_var('field_default_value', 0);
    509511                                        }*/
     512                                        else if ($field_type == FIELD_INT && $key == 'field_default_value')
     513                                        {
     514                                                // Permit an empty string
     515                                                if (request_var('field_default_value', '') === '')
     516                                                {
     517                                                        $var = '';
     518                                                }
     519                                        }
    510520
    511521                                        $cp->vars[$key] = $var;
     
    722732                                                        'S_FIELD_REQUIRED'      => ($cp->vars['field_required']) ? true : false,
    723733                                                        'S_SHOW_ON_REG'         => ($cp->vars['field_show_on_reg']) ? true : false,
     734                                                        'S_SHOW_ON_VT'          => ($cp->vars['field_show_on_vt']) ? true : false,
    724735                                                        'S_FIELD_HIDE'          => ($cp->vars['field_hide']) ? true : false,
    725736                                                        'S_SHOW_PROFILE'        => ($cp->vars['field_show_profile']) ? true : false,
     
    923934                        case FIELD_TEXT:
    924935                        case FIELD_STRING:
    925                                 if ($cp->vars['lang_default_value'])
     936                                if (strlen($cp->vars['lang_default_value']))
    926937                                {
    927938                                        $options['lang_default_value'] = ($field_type == FIELD_STRING) ? 'string' : 'text';
     
    10371048                        'field_required'                => $cp->vars['field_required'],
    10381049                        'field_show_on_reg'             => $cp->vars['field_show_on_reg'],
     1050                        'field_show_on_vt'              => $cp->vars['field_show_on_vt'],
    10391051                        'field_hide'                    => $cp->vars['field_hide'],
    10401052                        'field_show_profile'    => $cp->vars['field_show_profile'],
     
    15401552
    15411553                                // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
    1542                                 $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD \"$field_ident\" ";
     1554                                $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' ADD "' . strtoupper($field_ident) . '" ';
    15431555
    15441556                                switch ($field_type)
  • trunk/forum/includes/acp/acp_prune.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_prune.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    407407                        $where_sql .= ($count !== '') ? " AND user_posts " . $key_match[$count_select] . ' ' . (int) $count . ' ' : '';
    408408
    409                         if (sizeof($active) && $active_select != 'lt')
     409                        // First handle pruning of users who never logged in, last active date is 0000-00-00
     410                        if (sizeof($active) && (int) $active[0] == 0 && (int) $active[1] == 0 && (int) $active[2] == 0)
     411                        {
     412                                $where_sql .= ' AND user_lastvisit = 0';
     413                        }                       
     414                        else if (sizeof($active) && $active_select != 'lt')
    410415                        {
    411416                                $where_sql .= ' AND user_lastvisit ' . $key_match[$active_select] . ' ' . gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]);
  • trunk/forum/includes/acp/acp_ranks.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_ranks.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4040                $this->page_title = 'ACP_MANAGE_RANKS';
    4141
    42                 $form_name = 'acp_prune';
     42                $form_name = 'acp_ranks';
    4343                add_form_key($form_name);
    4444
     
    169169                                                $img = $path . $img;
    170170
    171                                                 if (!in_array($img, $existing_imgs) || $action == 'edit')
     171                                                if ($ranks && $img == $ranks['rank_image'])
    172172                                                {
    173                                                         if ($ranks && $img == $ranks['rank_image'])
    174                                                         {
    175                                                                 $selected = ' selected="selected"';
    176                                                                 $edit_img = $img;
    177                                                         }
    178                                                         else
    179                                                         {
    180                                                                 $selected = '';
    181                                                         }
    182 
    183                                                         if (strlen($img) > 255)
    184                                                         {
    185                                                                 continue;
    186                                                         }
    187 
    188                                                         $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . '</option>';
     173                                                        $selected = ' selected="selected"';
     174                                                        $edit_img = $img;
    189175                                                }
     176                                                else
     177                                                {
     178                                                        $selected = '';
     179                                                }
     180
     181                                                if (strlen($img) > 255)
     182                                                {
     183                                                        continue;
     184                                                }
     185
     186                                                $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . ((in_array($img, $existing_imgs)) ? ' ' . $user->lang['RANK_IMAGE_IN_USE'] : '') . '</option>';
    190187                                        }
    191188                                }
  • trunk/forum/includes/acp/acp_search.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_search.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    6464                        'limit_search_load'                     => 'float',
    6565                        'min_search_author_chars'       => 'integer',
     66                        'max_num_search_keywords'       => 'integer',
    6667                        'search_store_results'          => 'integer',
    6768                );
     
    217218                        'SEARCH_GUEST_INTERVAL' => (float) $config['search_anonymous_interval'],
    218219                        'SEARCH_STORE_RESULTS'  => (int) $config['search_store_results'],
     220                        'MAX_NUM_SEARCH_KEYWORDS'       => (int) $config['max_num_search_keywords'],
    219221
    220222                        'S_SEARCH_TYPES'                => $search_options,
     
    592594                ksort($this->state);
    593595
    594                 set_config('search_indexing_state', implode(',', $this->state));
     596                set_config('search_indexing_state', implode(',', $this->state), true);
    595597        }
    596598
  • trunk/forum/includes/acp/acp_styles.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_styles.php 9152 2008-12-02 16:49:59Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3838                $bitfield = new bitfield();
    3939                $bitfield->set(0);
     40                $bitfield->set(1);
     41                $bitfield->set(2);
    4042                $bitfield->set(3);
     43                $bitfield->set(4);
    4144                $bitfield->set(8);
    4245                $bitfield->set(9);
     
    208211                                                }
    209212
    210                                                 $sql = 'UPDATE ' . STYLES_TABLE . '
    211                                                         SET style_active = ' . (($action == 'activate') ? 1 : 0) . '
    212                                                         WHERE style_id = ' . $style_id;
    213                                                 $db->sql_query($sql);
    214 
    215                                                 // Set style to default for any member using deactivated style
    216                                                 if ($action == 'deactivate')
     213                                                if (($action == 'deactivate' && confirm_box(true)) || $action == 'activate')
    217214                                                {
    218                                                         $sql = 'UPDATE ' . USERS_TABLE . '
    219                                                                 SET user_style = ' . $config['default_style'] . "
    220                                                                 WHERE user_style = $style_id";
     215                                                        $sql = 'UPDATE ' . STYLES_TABLE . '
     216                                                                SET style_active = ' . (($action == 'activate') ? 1 : 0) . '
     217                                                                WHERE style_id = ' . $style_id;
    221218                                                        $db->sql_query($sql);
    222219
    223                                                         $sql = 'UPDATE ' . FORUMS_TABLE . '
    224                                                                 SET forum_style = 0
    225                                                                 WHERE forum_style = ' . $style_id;
    226                                                         $db->sql_query($sql);
     220                                                        // Set style to default for any member using deactivated style
     221                                                        if ($action == 'deactivate')
     222                                                        {
     223                                                                $sql = 'UPDATE ' . USERS_TABLE . '
     224                                                                        SET user_style = ' . $config['default_style'] . "
     225                                                                        WHERE user_style = $style_id";
     226                                                                $db->sql_query($sql);
     227
     228                                                                $sql = 'UPDATE ' . FORUMS_TABLE . '
     229                                                                        SET forum_style = 0
     230                                                                        WHERE forum_style = ' . $style_id;
     231                                                                $db->sql_query($sql);
     232                                                        }
     233                                                }
     234                                                else if ($action == 'deactivate')
     235                                                {
     236                                                        $s_hidden_fields = array(
     237                                                                'i'                     => $id,
     238                                                                'mode'          => $mode,
     239                                                                'action'        => $action,
     240                                                                'style_id'      => $style_id,
     241                                                        );
     242                                                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
    227243                                                }
    228244                                        break;
     
    628644                        while (($file = readdir($dp)) !== false)
    629645                        {
     646                                if (!is_dir($phpbb_root_path . 'styles/' . $file))
     647                                {
     648                                        continue;
     649                                }
     650
    630651                                $subpath = ($mode != 'style') ? "$mode/" : '';
    631652                                if ($file[0] != '.' && file_exists("{$phpbb_root_path}styles/$file/$subpath$mode.cfg"))
     
    732753                                if (!($fp = @fopen($file, 'wb')))
    733754                                {
    734                                         trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
     755                                        // File exists and is writeable, but still not able to be written to
     756                                        trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING);
    735757                                }
    736758                                fwrite($fp, $template_data);
     
    744766                                if (!$template_info['template_storedb'])
    745767                                {
    746                                         if ($this->get_super('template', $template_id))
     768                                        if ($super = $this->get_super('template', $template_id))
    747769                                        {
    748770                                                $this->store_in_db('template', $super['template_id']);
     
    825847                }
    826848
     849                if (empty($filelist['']))
     850                {
     851                        trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
     852                }
     853
    827854                // Now create the categories
    828855                $filelist_cats[''] = array();
     
    10221049                foreach ($file_ary as $file)
    10231050                {
    1024                         $file           = str_replace('/', '.', $file);
     1051                        $file           = str_replace('/', '.', $file);
    10251052
    10261053                        // perform some dirty guessing to get the path right.
    10271054                        // We assume that three dots in a row were '../'
    1028                         $tpl_file       = str_replace('.', '/', $file);
    1029                         $tpl_file       = str_replace('///', '../', $tpl_file);
     1055                        $tpl_file       = str_replace('.', '/', $file);
     1056                        $tpl_file       = str_replace('///', '../', $tpl_file);
    10301057
    10311058                        $filename = "{$cache_prefix}_$file.html.$phpEx";
     
    10591086                        }
    10601087
     1088                        // Correct the filename if it is stored in database and the file is in a subfolder.
     1089                        if ($template_row['template_storedb'])
     1090                        {
     1091                                $file = str_replace('.', '/', $file);
     1092                        }
    10611093
    10621094                        $template->assign_block_vars('file', array(
     
    10661098                                'FILENAME'              => $file,
    10671099                                'FILENAME_PATH' => $file_tpl,
    1068                                 'FILESIZE'              => sprintf('%.1f ' . $user->lang['KIB'], filesize("{$phpbb_root_path}cache/$filename") / 1024),
     1100                                'FILESIZE'              => get_formatted_filesize(filesize("{$phpbb_root_path}cache/$filename")),
    10691101                                'MODIFIED'              => $user->format_date((!$template_row['template_storedb']) ? filemtime($file_tpl) : $filemtime[$file . '.html']))
    10701102                        );
     
    12641296        }
    12651297
    1266 
    12671298        /**
    12681299        * Edit imagesets
     
    12761307                $this->page_title = 'EDIT_IMAGESET';
    12771308
     1309                if (!$imageset_id)
     1310                {
     1311                        trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING);
     1312                }
     1313
    12781314                $update         = (isset($_POST['update'])) ? true : false;
    12791315
    1280                 $imgname        = request_var('imgname', '');
    1281                 $imgpath        = request_var('imgpath', '');
    1282                 $imgsize        = request_var('imgsize', false);
    1283                 $imgwidth       = request_var('imgwidth', 0);
    1284                 $imgheight      = request_var('imgheight', 0);
    1285 
     1316                $imgname        = request_var('imgname', 'site_logo');
    12861317                $imgname        = preg_replace('#[^a-z0-9\-+_]#i', '', $imgname);
    1287                 $imgpath        = str_replace('..', '.', $imgpath);
    1288 
    1289                 if ($imageset_id)
    1290                 {
    1291                         $sql = 'SELECT imageset_path, imageset_name
    1292                                 FROM ' . STYLES_IMAGESET_TABLE . "
    1293                                 WHERE imageset_id = $imageset_id";
    1294                         $result = $db->sql_query($sql);
    1295                         $imageset_row = $db->sql_fetchrow($result);
    1296                         $db->sql_freeresult($result);
    1297 
    1298                         $imageset_path          = $imageset_row['imageset_path'];
    1299                         $imageset_name          = $imageset_row['imageset_name'];
    1300 
    1301                         $sql_extra = '';
    1302                         if (strpos($imgname, '-') !== false)
    1303                         {
    1304                                 list($imgname, $imgnamelang) = explode('-', $imgname);
    1305                                 $sql_extra = " AND image_lang IN ('" . $db->sql_escape($imgnamelang) . "', '')";
    1306                         }
    1307 
    1308                         $sql = 'SELECT image_filename, image_width, image_height, image_lang, image_id
    1309                                 FROM ' . STYLES_IMAGESET_DATA_TABLE . "
    1310                                 WHERE imageset_id = $imageset_id
    1311                                         AND image_name = '" . $db->sql_escape($imgname) . "'$sql_extra";
    1312                         $result = $db->sql_query($sql);
    1313                         $imageset_data_row = $db->sql_fetchrow($result);
    1314                         $db->sql_freeresult($result);
    1315 
    1316                         $image_filename = $imageset_data_row['image_filename'];
    1317                         $image_width    = $imageset_data_row['image_width'];
    1318                         $image_height   = $imageset_data_row['image_height'];
    1319                         $image_lang             = $imageset_data_row['image_lang'];
    1320                         $image_id               = $imageset_data_row['image_id'];
    1321 
    1322                         if (!$imageset_row)
    1323                         {
    1324                                 trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING);
    1325                         }
    1326 
    1327                         // Check to see whether the selected image exists in the table
    1328                         $valid_name = ($update) ? false : true;
    1329 
    1330                         foreach ($this->imageset_keys as $category => $img_ary)
    1331                         {
    1332                                 if (in_array($imgname, $img_ary))
    1333                                 {
    1334                                         $valid_name = true;
    1335                                         break;
    1336                                 }
    1337                         }
    1338 
    1339                         if ($update && isset($_POST['imgpath']))
    1340                         {
    1341                                 if ($valid_name)
    1342                                 {
    1343                                         // If imgwidth and imgheight are non-zero grab the actual size
    1344                                         // from the image itself ... we ignore width settings for the poll center image
    1345                                         $imgwidth       = request_var('imgwidth', 0);
    1346                                         $imgheight      = request_var('imgheight', 0);
    1347                                         $imglang = '';
    1348 
    1349                                         if ($imgpath && !file_exists("{$phpbb_root_path}styles/$imageset_path/imageset/$imgpath"))
    1350                                         {
    1351                                                 trigger_error($user->lang['NO_IMAGE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
    1352                                         }
    1353 
    1354                                         if ($imgsize && $imgpath)
    1355                                         {
    1356                                                 if (!$imgwidth || !$imgheight)
    1357                                                 {
    1358                                                         list($imgwidth_file, $imgheight_file) = getimagesize("{$phpbb_root_path}styles/$imageset_path/imageset/$imgpath");
    1359                                                         $imgwidth = ($imgwidth) ? $imgwidth : $imgwidth_file;
    1360                                                         $imgheight = ($imgheight) ? $imgheight : $imgheight_file;
    1361                                                 }
    1362                                                 $imgwidth       = ($imgname != 'poll_center') ? (int) $imgwidth : 0;
    1363                                                 $imgheight      = (int) $imgheight;
    1364                                         }
    1365 
    1366 
    1367                                         if (strpos($imgpath, '/') !== false)
    1368                                         {
    1369                                                 list($imglang, $imgfilename) = explode('/', $imgpath);
    1370                                         }
    1371                                         else
    1372                                         {
    1373                                                 $imgfilename = $imgpath;
    1374                                         }
    1375 
    1376                                         $sql_ary = array(
    1377                                                 'image_filename'        => (string) $imgfilename,
    1378                                                 'image_width'           => (int) $imgwidth,
    1379                                                 'image_height'          => (int) $imgheight,
    1380                                                 'image_lang'            => (string) $imglang,
    1381                                         );
    1382 
    1383                                         // already exists
    1384                                         if ($imageset_data_row)
    1385                                         {
    1386                                                 $sql = 'UPDATE ' . STYLES_IMAGESET_DATA_TABLE . '
    1387                                                         SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
    1388                                                         WHERE image_id = $image_id";
    1389                                                 $db->sql_query($sql);
    1390                                         }
    1391                                         // does not exist
    1392                                         else if (!$imageset_data_row)
    1393                                         {
    1394                                                 $sql_ary['image_name']  = $imgname;
    1395                                                 $sql_ary['imageset_id'] = (int) $imageset_id;
    1396                                                 $db->sql_query('INSERT INTO ' . STYLES_IMAGESET_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
    1397                                         }
    1398 
    1399                                         $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
    1400 
    1401                                         add_log('admin', 'LOG_IMAGESET_EDIT', $imageset_name);
    1402 
    1403                                         $template->assign_var('SUCCESS', true);
    1404 
    1405                                         $image_filename = $imgfilename;
    1406                                         $image_width    = $imgwidth;
    1407                                         $image_height   = $imgheight;
    1408                                         $image_lang             = $imglang;
    1409                                 }
    1410                         }
     1318                $sql_extra = $imgnamelang = '';
     1319
     1320                $sql = 'SELECT imageset_path, imageset_name
     1321                        FROM ' . STYLES_IMAGESET_TABLE . "
     1322                        WHERE imageset_id = $imageset_id";
     1323                $result = $db->sql_query($sql);
     1324                $imageset_row = $db->sql_fetchrow($result);
     1325                $db->sql_freeresult($result);
     1326
     1327                if (!$imageset_row)
     1328                {
     1329                        trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING);
     1330                }
     1331
     1332                $imageset_path          = $imageset_row['imageset_path'];
     1333                $imageset_name          = $imageset_row['imageset_name'];
     1334
     1335                if (strpos($imgname, '-') !== false)
     1336                {
     1337                        list($imgname, $imgnamelang) = explode('-', $imgname);
     1338                        $sql_extra = " AND image_lang IN ('" . $db->sql_escape($imgnamelang) . "', '')";
     1339                }
     1340
     1341                $sql = 'SELECT image_filename, image_width, image_height, image_lang, image_id
     1342                        FROM ' . STYLES_IMAGESET_DATA_TABLE . "
     1343                        WHERE imageset_id = $imageset_id
     1344                                AND image_name = '" . $db->sql_escape($imgname) . "'$sql_extra";
     1345                $result = $db->sql_query($sql);
     1346                $imageset_data_row = $db->sql_fetchrow($result);
     1347                $db->sql_freeresult($result);
     1348
     1349                $image_filename = $imageset_data_row['image_filename'];
     1350                $image_width    = $imageset_data_row['image_width'];
     1351                $image_height   = $imageset_data_row['image_height'];
     1352                $image_lang             = $imageset_data_row['image_lang'];
     1353                $image_id               = $imageset_data_row['image_id'];
     1354                $imgsize                = ($imageset_data_row['image_width'] && $imageset_data_row['image_height']) ? 1 : 0;
     1355
     1356                // Check to see whether the selected image exists in the table
     1357                $valid_name = ($update) ? false : true;
     1358
     1359                foreach ($this->imageset_keys as $category => $img_ary)
     1360                {
     1361                        if (in_array($imgname, $img_ary))
     1362                        {
     1363                                $valid_name = true;
     1364                                break;
     1365                        }
     1366                }
     1367
     1368                if ($update && isset($_POST['imgpath']) && $valid_name)
     1369                {
     1370                        // If imgwidth and imgheight are non-zero grab the actual size
     1371                        // from the image itself ... we ignore width settings for the poll center image
     1372                        $imgwidth       = request_var('imgwidth', 0);
     1373                        $imgheight      = request_var('imgheight', 0);
     1374                        $imgsize        = request_var('imgsize', 0);
     1375                        $imgpath        = request_var('imgpath', '');
     1376                        $imgpath        = str_replace('..', '.', $imgpath);
     1377
     1378                        // If no dimensions selected, we reset width and height to 0 ;)
     1379                        if (!$imgsize)
     1380                        {
     1381                                $imgwidth = $imgheight = 0;
     1382                        }
     1383
     1384                        $imglang = '';
     1385
     1386                        if ($imgpath && !file_exists("{$phpbb_root_path}styles/$imageset_path/imageset/$imgpath"))
     1387                        {
     1388                                trigger_error($user->lang['NO_IMAGE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
     1389                        }
     1390
     1391                        // Determine width/height. If dimensions included and no width/height given, we detect them automatically...
     1392                        if ($imgsize && $imgpath)
     1393                        {
     1394                                if (!$imgwidth || !$imgheight)
     1395                                {
     1396                                        list($imgwidth_file, $imgheight_file) = getimagesize("{$phpbb_root_path}styles/$imageset_path/imageset/$imgpath");
     1397                                        $imgwidth = ($imgwidth) ? $imgwidth : $imgwidth_file;
     1398                                        $imgheight = ($imgheight) ? $imgheight : $imgheight_file;
     1399                                }
     1400                                $imgwidth       = ($imgname != 'poll_center') ? (int) $imgwidth : 0;
     1401                                $imgheight      = (int) $imgheight;
     1402                        }
     1403
     1404                        if (strpos($imgpath, '/') !== false)
     1405                        {
     1406                                list($imglang, $imgfilename) = explode('/', $imgpath);
     1407                        }
     1408                        else
     1409                        {
     1410                                $imgfilename = $imgpath;
     1411                        }
     1412
     1413                        $sql_ary = array(
     1414                                'image_filename'        => (string) $imgfilename,
     1415                                'image_width'           => (int) $imgwidth,
     1416                                'image_height'          => (int) $imgheight,
     1417                                'image_lang'            => (string) $imglang,
     1418                        );
     1419
     1420                        // already exists
     1421                        if ($imageset_data_row)
     1422                        {
     1423                                $sql = 'UPDATE ' . STYLES_IMAGESET_DATA_TABLE . '
     1424                                        SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
     1425                                        WHERE image_id = $image_id";
     1426                                $db->sql_query($sql);
     1427                        }
     1428                        // does not exist
     1429                        else if (!$imageset_data_row)
     1430                        {
     1431                                $sql_ary['image_name']  = $imgname;
     1432                                $sql_ary['imageset_id'] = (int) $imageset_id;
     1433                                $db->sql_query('INSERT INTO ' . STYLES_IMAGESET_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
     1434                        }
     1435
     1436                        $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
     1437
     1438                        add_log('admin', 'LOG_IMAGESET_EDIT', $imageset_name);
     1439
     1440                        $template->assign_var('SUCCESS', true);
     1441
     1442                        $image_filename = $imgfilename;
     1443                        $image_width    = $imgwidth;
     1444                        $image_height   = $imgheight;
     1445                        $image_lang             = $imglang;
    14111446                }
    14121447
     
    15301565                        'NAME'                          => $imageset_name,
    15311566                        'A_NAME'                        => addslashes($imageset_name),
     1567                        'PATH'                          => $imageset_path,
     1568                        'A_PATH'                        => addslashes($imageset_path),
    15321569                        'ERROR'                         => !$valid_name,
    15331570                        'IMG_SRC'                       => ($image_found) ? '../styles/' . $imageset_path . '/imageset/' . $img_val : 'images/no_image.png',
     
    23962433                }
    23972434
    2398 
    23992435                if ($mode == 'template')
    24002436                {
     
    25272563                                        trigger_error("Could not open {$phpbb_root_path}styles/$template_path$pathfile$file", E_USER_ERROR);
    25282564                                }
    2529                                 $template_data = fread($fp, filesize("{$phpbb_root_path}styles/$template_path$pathfile$file"));
     2565
     2566                                $filesize = filesize("{$phpbb_root_path}styles/$template_path$pathfile$file");
     2567
     2568                                if ($filesize)
     2569                                {
     2570                                        $template_data = fread($fp, $filesize);
     2571                                }
     2572
    25302573                                fclose($fp);
     2574
     2575                                if (!$filesize)
     2576                                {
     2577                                        // File is empty
     2578                                        continue;
     2579                                }
    25312580
    25322581                                if (preg_match_all('#<!-- INCLUDE (.*?\.html) -->#is', $template_data, $matches))
     
    31963245                $db->sql_freeresult($result);
    31973246
    3198 
    31993247                if ($row)
    32003248                {
     
    32113259                if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from'])
    32123260                {
    3213                         $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, {$mode}_storedb
     3261                        if ($mode === 'template')
     3262                        {
     3263                                $select_bf = ', bbcode_bitfield';
     3264                        }
     3265                        else
     3266                        {
     3267                                $select_bf = '';
     3268                        }
     3269
     3270                        $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, {$mode}_storedb $select_bf
    32143271                                FROM $sql_from
    32153272                                WHERE {$mode}_name = '" . $db->sql_escape($cfg_data['inherit_from']) . "'
     
    32263283                                $inherit_id = $row["{$mode}_id"];
    32273284                                $inherit_path = $row["{$mode}_path"];
     3285                                $inherit_bf = ($mode === 'template') ? $row["bbcode_bitfield"] : false;
    32283286                                $cfg_data['store_db'] = $row["{$mode}_storedb"];
    32293287                                $store_db = $row["{$mode}_storedb"];
     
    32343292                        $inherit_id = 0;
    32353293                        $inherit_path = '';
    3236                 }
    3237 
     3294                        $inherit_bf = false;
     3295                }
    32383296
    32393297                if (sizeof($error))
     
    32553313                                {
    32563314                                        $sql_ary['bbcode_bitfield'] = $cfg_data['template_bitfield'];
     3315                                }
     3316                                else if ($inherit_bf)
     3317                                {
     3318                                        $sql_ary['bbcode_bitfield'] = $inherit_bf;
    32573319                                }
    32583320                                else
     
    35023564                }
    35033565
    3504 
    35053566                $sql = "SELECT {$mode}_inherits_id
    35063567                        FROM $sql_from
  • trunk/forum/includes/acp/acp_update.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_update.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3838                $errno = 0;
    3939
    40                 $info = get_remote_file('www.phpbb.com', '/updatecheck', ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno);
     40                $info = obtain_latest_version_info(request_var('versioncheck_force', false), true);
    4141
    4242                if ($info === false)
    4343                {
    44                         trigger_error($errstr, E_USER_WARNING);
     44                        trigger_error('VERSIONCHECK_FAIL', E_USER_WARNING);
    4545                }
    4646
     
    4949
    5050                $announcement_url = trim($info[1]);
     51                $announcement_url = (strpos($announcement_url, '&amp;') === false) ? str_replace('&', '&amp;', $announcement_url) : $announcement_url;
    5152                $update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update');
    5253
     
    6970                        'S_VERSION_CHECK'       => true,
    7071                        'U_ACTION'                      => $this->u_action,
     72                        'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&amp;versioncheck_force=1'),
    7173
    7274                        'LATEST_VERSION'        => $latest_version,
  • trunk/forum/includes/acp/acp_users.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_users.php 8831 2008-09-05 19:02:36Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    386386                                                        user_active_flip('flip', $user_id);
    387387
     388                                                        if ($user_row['user_type'] == USER_INACTIVE)
     389                                                        {
     390                                                                if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
     391                                                                {
     392                                                                        include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
     393
     394                                                                        $messenger = new messenger(false);
     395
     396                                                                        $messenger->template('admin_welcome_activated', $user_row['user_lang']);
     397
     398                                                                        $messenger->to($user_row['user_email'], $user_row['username']);
     399
     400                                                                        $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
     401                                                                        $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
     402                                                                        $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
     403                                                                        $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
     404
     405                                                                        $messenger->assign_vars(array(
     406                                                                                'USERNAME'      => htmlspecialchars_decode($user_row['username']))
     407                                                                        );
     408
     409                                                                        $messenger->send(NOTIFY_EMAIL);
     410                                                                }
     411                                                        }
     412
    388413                                                        $message = ($user_row['user_type'] == USER_INACTIVE) ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
    389414                                                        $log = ($user_row['user_type'] == USER_INACTIVE) ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
     
    494519                                                        }
    495520
     521                                                break;
     522
     523                                                case 'deloutbox':
     524
     525                                                        if (confirm_box(true))
     526                                                        {
     527                                                                $msg_ids = array();
     528                                                                $lang = 'EMPTY';
     529
     530                                                                $sql = 'SELECT msg_id
     531                                                                        FROM ' . PRIVMSGS_TO_TABLE . "
     532                                                                        WHERE author_id = $user_id
     533                                                                                AND folder_id = " . PRIVMSGS_OUTBOX;
     534                                                                $result = $db->sql_query($sql);
     535
     536                                                                if ($row = $db->sql_fetchrow($result))
     537                                                                {
     538                                                                        if (!function_exists('delete_pm'))
     539                                                                        {
     540                                                                                include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
     541                                                                        }
     542
     543                                                                        do
     544                                                                        {
     545                                                                                $msg_ids[] = (int) $row['msg_id'];
     546                                                                        }
     547                                                                        while ($row = $db->sql_fetchrow($result));
     548
     549                                                                        $db->sql_freeresult($result);
     550
     551                                                                        delete_pm($user_id, $msg_ids, PRIVMSGS_OUTBOX);
     552
     553                                                                        add_log('admin', 'LOG_USER_DEL_OUTBOX', $user_row['username']);
     554
     555                                                                        $lang = 'EMPTIED';
     556                                                                }
     557                                                                $db->sql_freeresult($result);
     558
     559                                                                trigger_error($user->lang['USER_OUTBOX_' . $lang] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
     560                                                        }
     561                                                        else
     562                                                        {
     563                                                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
     564                                                                        'u'                             => $user_id,
     565                                                                        'i'                             => $id,
     566                                                                        'mode'                  => $mode,
     567                                                                        'action'                => $action,
     568                                                                        'update'                => true))
     569                                                                );
     570                                                        }
    496571                                                break;
    497572
     
    651726
    652727                                                break;
     728
     729                                                case 'leave_nr':
     730
     731                                                        if (confirm_box(true))
     732                                                        {
     733                                                                remove_newly_registered($user_id, $user_row);
     734
     735                                                                add_log('admin', 'LOG_USER_REMOVED_NR', $user_row['username']);
     736                                                                trigger_error($user->lang['USER_LIFTED_NR'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
     737                                                        }
     738                                                        else
     739                                                        {
     740                                                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
     741                                                                        'u'                             => $user_id,
     742                                                                        'i'                             => $id,
     743                                                                        'mode'                  => $mode,
     744                                                                        'action'                => $action,
     745                                                                        'update'                => true))
     746                                                                );
     747                                                        }
     748
     749                                                break;
    653750                                        }
    654751
     
    776873                                                        $sql_ary += array(
    777874                                                                'user_email'            => $update_email,
    778                                                                 'user_email_hash'       => crc32($update_email) . strlen($update_email)
     875                                                                'user_email_hash'       => phpbb_email_hash($update_email),
    779876                                                        );
    780877
     
    821918                                if ($user_id == $user->data['user_id'])
    822919                                {
    823                                         $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
     920                                        $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
     921                                        if ($user_row['user_new'])
     922                                        {
     923                                                $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
     924                                        }
    824925                                }
    825926                                else
     
    837938                                        }
    838939
    839                                         $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
     940                                        $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
    840941
    841942                                        if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE))
    842943                                        {
    843944                                                $quick_tool_ary['reactivate'] = 'FORCE';
     945                                        }
     946
     947                                        if ($user_row['user_new'])
     948                                        {
     949                                                $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
    844950                                        }
    845951                                }
     
    9181024                                        'U_MCP_QUEUE'   => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
    9191025
    920                                         'U_SWITCH_PERMISSIONS'  => ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&amp;u={$user_row['user_id']}") : '',
     1026                                        'U_SWITCH_PERMISSIONS'  => ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&amp;u={$user_row['user_id']}&amp;hash=" . generate_link_hash('switchperm')) : '',
    9211027
    9221028                                        'POSTS_IN_QUEUE'        => $user_row['posts_in_queue'],
     
    9731079                                                $sql = 'DELETE FROM ' . LOG_TABLE . '
    9741080                                                        WHERE log_type = ' . LOG_USERS . "
     1081                                                        AND reportee_id = $user_id
    9751082                                                        $where_sql";
    9761083                                                $db->sql_query($sql);
     
    10321139                                        );
    10331140                                }
     1141
     1142                        break;
     1143
     1144                        case 'warnings':
     1145                                $user->add_lang('mcp');
     1146
     1147                                // Set up general vars
     1148                                $start          = request_var('start', 0);
     1149                                $deletemark     = (isset($_POST['delmarked'])) ? true : false;
     1150                                $deleteall      = (isset($_POST['delall'])) ? true : false;
     1151                                $confirm        = (isset($_POST['confirm'])) ? true : false;
     1152                                $marked         = request_var('mark', array(0));
     1153                                $message        = utf8_normalize_nfc(request_var('message', '', true));
     1154
     1155                                // Sort keys
     1156                                $sort_days      = request_var('st', 0);
     1157                                $sort_key       = request_var('sk', 't');
     1158                                $sort_dir       = request_var('sd', 'd');
     1159
     1160                                // Delete entries if requested and able
     1161                                if ($deletemark || $deleteall || $confirm)
     1162                                {
     1163                                        if (confirm_box(true))
     1164                                        {
     1165                                                $where_sql = '';
     1166                                                $deletemark = request_var('delmarked', 0);
     1167                                                $deleteall = request_var('delall', 0);
     1168                                                if ($deletemark && $marked)
     1169                                                {
     1170                                                        $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked));
     1171                                                }
     1172
     1173                                                if ($where_sql || $deleteall)
     1174                                                {
     1175                                                        $sql = 'DELETE FROM ' . WARNINGS_TABLE . "
     1176                                                                WHERE user_id = $user_id
     1177                                                                        $where_sql";
     1178                                                        $db->sql_query($sql);
     1179
     1180                                                        if ($deleteall)
     1181                                                        {
     1182                                                                $log_warnings = $deleted_warnings = 0;
     1183                                                        }
     1184                                                        else
     1185                                                        {
     1186                                                                $num_warnings = (int) $db->sql_affectedrows();
     1187                                                                $deleted_warnings = ' user_warnings - ' . $num_warnings;
     1188                                                                $log_warnings = ($num_warnings > 2) ? 2 : $num_warnings;
     1189                                                        }
     1190
     1191                                                        $sql = 'UPDATE ' . USERS_TABLE . "
     1192                                                                SET user_warnings = $deleted_warnings
     1193                                                                WHERE user_id = $user_id";
     1194                                                        $db->sql_query($sql);
     1195
     1196                                                        switch ($log_warnings)
     1197                                                        {
     1198                                                                case 2:
     1199                                                                        add_log('admin', 'LOG_WARNINGS_DELETED', $user_row['username'], $num_warnings);
     1200                                                                break;
     1201                                                                case 1:
     1202                                                                        add_log('admin', 'LOG_WARNING_DELETED', $user_row['username']);
     1203                                                                break;
     1204                                                                default:
     1205                                                                        add_log('admin', 'LOG_WARNINGS_DELETED_ALL', $user_row['username']);
     1206                                                                break;
     1207                                                        }
     1208                                                }
     1209                                        }
     1210                                        else
     1211                                        {
     1212                                                $s_hidden_fields = array(
     1213                                                        'i'                             => $id,
     1214                                                        'mode'                  => $mode,
     1215                                                        'u'                             => $user_id,
     1216                                                        'mark'                  => $marked,
     1217                                                );
     1218                                                if (isset($_POST['delmarked']))
     1219                                                {
     1220                                                        $s_hidden_fields['delmarked'] = 1;
     1221                                                }
     1222                                                if (isset($_POST['delall']))
     1223                                                {
     1224                                                        $s_hidden_fields['delall'] = 1;
     1225                                                }
     1226                                                if (isset($_POST['delall']) || (isset($_POST['delmarked']) && sizeof($marked)))
     1227                                                {
     1228                                                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
     1229                                                }
     1230                                        }
     1231                                }
     1232
     1233                                $sql = 'SELECT w.warning_id, w.warning_time, w.post_id, l.log_operation, l.log_data, l.user_id AS mod_user_id, m.username AS mod_username, m.user_colour AS mod_user_colour
     1234                                        FROM ' . WARNINGS_TABLE . ' w
     1235                                        LEFT JOIN ' . LOG_TABLE . ' l
     1236                                                ON (w.log_id = l.log_id)
     1237                                        LEFT JOIN ' . USERS_TABLE . ' m
     1238                                                ON (l.user_id = m.user_id)
     1239                                        WHERE w.user_id = ' . $user_id . '
     1240                                        ORDER BY w.warning_time DESC';
     1241                                $result = $db->sql_query($sql);
     1242
     1243                                while ($row = $db->sql_fetchrow($result))
     1244                                {
     1245                                        if (!$row['log_operation'])
     1246                                        {
     1247                                                // We do not have a log-entry anymore, so there is no data available
     1248                                                $row['action'] = $user->lang['USER_WARNING_LOG_DELETED'];
     1249                                        }
     1250                                        else
     1251                                        {
     1252                                                $row['action'] = (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}';
     1253                                                if (!empty($row['log_data']))
     1254                                                {
     1255                                                        $log_data_ary = @unserialize($row['log_data']);
     1256                                                        $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary;
     1257
     1258                                                        if (isset($user->lang[$row['log_operation']]))
     1259                                                        {
     1260                                                                // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array
     1261                                                                // It doesn't matter if we add more arguments than placeholders
     1262                                                                if ((substr_count($row['action'], '%') - sizeof($log_data_ary)) > 0)
     1263                                                                {
     1264                                                                        $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - sizeof($log_data_ary), ''));
     1265                                                                }
     1266                                                                $row['action'] = vsprintf($row['action'], $log_data_ary);
     1267                                                                $row['action'] = bbcode_nl2br(censor_text($row['action']));
     1268                                                        }
     1269                                                        else if (!empty($log_data_ary))
     1270                                                        {
     1271                                                                $row['action'] .= '<br />' . implode('', $log_data_ary);
     1272                                                        }
     1273                                                }
     1274                                        }
     1275
     1276
     1277                                        $template->assign_block_vars('warn', array(
     1278                                                'ID'            => $row['warning_id'],
     1279                                                'USERNAME'      => ($row['log_operation']) ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-',
     1280                                                'ACTION'        => make_clickable($row['action']),
     1281                                                'DATE'          => $user->format_date($row['warning_time']),
     1282                                        ));
     1283                                }
     1284                                $db->sql_freeresult($result);
     1285
     1286                                $template->assign_vars(array(
     1287                                        'S_WARNINGS'    => true,
     1288                                ));
    10341289
    10351290                        break;
     
    11361391
    11371392                                                // Update Custom Fields
    1138                                                 if (sizeof($cp_data))
    1139                                                 {
    1140                                                         switch ($db->sql_layer)
    1141                                                         {
    1142                                                                 case 'oracle':
    1143                                                                 case 'firebird':
    1144                                                                 case 'postgres':
    1145                                                                         $right_delim = $left_delim = '"';
    1146                                                                 break;
    1147 
    1148                                                                 case 'sqlite':
    1149                                                                 case 'mssql':
    1150                                                                 case 'mssql_odbc':
    1151                                                                         $right_delim = ']';
    1152                                                                         $left_delim = '[';
    1153                                                                 break;
    1154 
    1155                                                                 case 'mysql':
    1156                                                                 case 'mysql4':
    1157                                                                 case 'mysqli':
    1158                                                                         $right_delim = $left_delim = '`';
    1159                                                                 break;
    1160                                                         }
    1161 
    1162                                                         foreach ($cp_data as $key => $value)
    1163                                                         {
    1164                                                                 $cp_data[$left_delim . $key . $right_delim] = $value;
    1165                                                                 unset($cp_data[$key]);
    1166                                                         }
    1167 
    1168                                                         $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
    1169                                                                 SET ' . $db->sql_build_array('UPDATE', $cp_data) . "
    1170                                                                 WHERE user_id = $user_id";
    1171                                                         $db->sql_query($sql);
    1172 
    1173                                                         if (!$db->sql_affectedrows())
    1174                                                         {
    1175                                                                 $cp_data['user_id'] = (int) $user_id;
    1176 
    1177                                                                 $db->sql_return_on_error(true);
    1178 
    1179                                                                 $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data);
    1180                                                                 $db->sql_query($sql);
    1181 
    1182                                                                 $db->sql_return_on_error(false);
    1183                                                         }
    1184                                                 }
     1393                                                $cp->update_profile_field_data($user_id, $cp_data);
    11851394
    11861395                                                trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
     
    12081417                                $now = getdate();
    12091418                                $s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>';
    1210                                 for ($i = $now['year'] - 100; $i < $now['year']; $i++)
     1419                                for ($i = $now['year'] - 100; $i <= $now['year']; $i++)
    12111420                                {
    12121421                                        $selected = ($i == $data['bday_year']) ? ' selected="selected"' : '';
     
    14751684                                }
    14761685
     1686                                if (!$config['allow_avatar'] && $user_row['user_avatar_type'])
     1687                                {
     1688                                        $error[] = $user->lang['USER_AVATAR_NOT_ALLOWED'];
     1689                                }
     1690                                else if ((($user_row['user_avatar_type'] == AVATAR_UPLOAD) && !$config['allow_avatar_upload']) ||
     1691                                 (($user_row['user_avatar_type'] == AVATAR_REMOTE) && !$config['allow_avatar_remote']) ||
     1692                                 (($user_row['user_avatar_type'] == AVATAR_GALLERY) && !$config['allow_avatar_local']))
     1693                                {
     1694                                        $error[] = $user->lang['USER_AVATAR_TYPE_NOT_ALLOWED'];
     1695                                }
     1696
    14771697                                // Generate users avatar
    1478                                 $avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']) : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
     1698                                $avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height'], 'USER_AVATAR', true) : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
    14791699
    14801700                                $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
     
    14891709                                $template->assign_vars(array(
    14901710                                        'S_AVATAR'                      => true,
    1491                                         'S_CAN_UPLOAD'          => ($can_upload && $config['allow_avatar_upload']) ? true : false,
    1492                                         'S_ALLOW_REMOTE'        => ($config['allow_avatar_remote']) ? true : false,
    1493                                         'S_DISPLAY_GALLERY'     => ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
    1494                                         'S_IN_GALLERY'          => ($config['allow_avatar_local'] && $display_gallery) ? true : false,
     1711                                        'S_CAN_UPLOAD'          => $can_upload,
     1712                                        'S_UPLOAD_FILE'         => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_upload']) ? true : false,
     1713                                        'S_REMOTE_UPLOAD'       => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_remote_upload']) ? true : false,
     1714                                        'S_ALLOW_REMOTE'        => ($config['allow_avatar'] && $config['allow_avatar_remote']) ? true : false,
     1715                                        'S_DISPLAY_GALLERY'     => ($config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery) ? true : false,
     1716                                        'S_IN_GALLERY'          => ($config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery) ? true : false,
    14951717
    14961718                                        'AVATAR_IMAGE'                  => $avatar_img,
     
    15501772                                include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
    15511773
    1552                                 $enable_bbcode  = ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', !$user->optionget('bbcode'))) ? false : true) : false;
    1553                                 $enable_smilies = ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', !$user->optionget('smilies'))) ? false : true) : false;
    1554                                 $enable_urls    = ($config['allow_sig_links']) ? ((request_var('disable_magic_url', false)) ? false : true) : false;
     1774                                $enable_bbcode  = ($config['allow_sig_bbcode']) ? (bool) $this->optionget($user_row, 'sig_bbcode') : false;
     1775                                $enable_smilies = ($config['allow_sig_smilies']) ? (bool) $this->optionget($user_row, 'sig_smilies') : false;
     1776                                $enable_urls    = ($config['allow_sig_links']) ? (bool) $this->optionget($user_row, 'sig_links') : false;
    15551777                                $signature              = utf8_normalize_nfc(request_var('signature', (string) $user_row['user_sig'], true));
    15561778
     
    15601782                                {
    15611783                                        include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
     1784
     1785                                        $enable_bbcode  = ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', false)) ? false : true) : false;
     1786                                        $enable_smilies = ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', false)) ? false : true) : false;
     1787                                        $enable_urls    = ($config['allow_sig_links']) ? ((request_var('disable_magic_url', false)) ? false : true) : false;
    15621788
    15631789                                        $message_parser = new parse_message($signature);
     
    15781804                                        if (!sizeof($error) && $submit)
    15791805                                        {
     1806                                                $this->optionset($user_row, 'sig_bbcode', $enable_bbcode);
     1807                                                $this->optionset($user_row, 'sig_smilies', $enable_smilies);
     1808                                                $this->optionset($user_row, 'sig_links', $enable_urls);
     1809
    15801810                                                $sql_ary = array(
    15811811                                                        'user_sig'                                      => (string) $message_parser->message,
     1812                                                        'user_options'                          => $user_row['user_options'],
    15821813                                                        'user_sig_bbcode_uid'           => (string) $message_parser->bbcode_uid,
    15831814                                                        'user_sig_bbcode_bitfield'      => (string) $message_parser->bbcode_bitfield
     
    18472078
    18482079                                                        $error = array();
     2080
     2081                                                        // The delete action was successful - therefore update the user row...
     2082                                                        $sql = 'SELECT u.*, s.*
     2083                                                                FROM ' . USERS_TABLE . ' u
     2084                                                                        LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
     2085                                                                WHERE u.user_id = ' . $user_id . '
     2086                                                                ORDER BY s.session_time DESC';
     2087                                                        $result = $db->sql_query($sql);
     2088                                                        $user_row = $db->sql_fetchrow($result);
     2089                                                        $db->sql_freeresult($result);
    18492090                                                }
    18502091                                                else
     
    18602101
    18612102                                        break;
     2103
     2104                                        case 'approve':
     2105
     2106                                                if (confirm_box(true))
     2107                                                {
     2108                                                        if (!$group_id)
     2109                                                        {
     2110                                                                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
     2111                                                        }
     2112                                                        group_user_attributes($action, $group_id, $user_id);
     2113                                                }
     2114                                                else
     2115                                                {
     2116                                                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
     2117                                                                'u'                             => $user_id,
     2118                                                                'i'                             => $id,
     2119                                                                'mode'                  => $mode,
     2120                                                                'action'                => $action,
     2121                                                                'g'                             => $group_id))
     2122                                                        );
     2123                                                }
     2124
     2125                                        break;
    18622126                                }
    18632127
     
    19522216                                                        'U_DEMOTE_PROMOTE'      => $this->u_action . '&amp;action=' . (($data['group_leader']) ? 'demote' : 'promote') . "&amp;u=$user_id&amp;g=" . $data['group_id'],
    19532217                                                        'U_DELETE'                      => $this->u_action . "&amp;action=delete&amp;u=$user_id&amp;g=" . $data['group_id'],
     2218                                                        'U_APPROVE'                     => ($group_type == 'pending') ? $this->u_action . "&amp;action=approve&amp;u=$user_id&amp;g=" . $data['group_id'] : '',
    19542219
    19552220                                                        'GROUP_NAME'            => ($group_type == 'special') ? $user->lang['G_' . $data['group_name']] : $data['group_name'],
    19562221                                                        'L_DEMOTE_PROMOTE'      => ($data['group_leader']) ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'],
    19572222
     2223                                                        'S_IS_MEMBER'           => ($group_type != 'pending') ? true : false,
    19582224                                                        'S_NO_DEFAULT'          => ($user_row['group_id'] != $data['group_id']) ? true : false,
    19592225                                                        'S_SPECIAL_GROUP'       => ($group_type == 'special') ? true : false,
  • trunk/forum/includes/acp/acp_words.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_words.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2424{
    2525        var $u_action;
    26        
     26
    2727        function main($id, $mode)
    2828        {
     
    4848                {
    4949                        case 'edit':
     50
    5051                                $word_id = request_var('id', 0);
    51                                
     52
    5253                                if (!$word_id)
    5354                                {
     
    7475                                        'S_HIDDEN_FIELDS'       => $s_hidden_fields)
    7576                                );
    76                                
     77
    7778                                return;
    7879
     
    8586                                        trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
    8687                                }
     88
    8789                                $word_id                = request_var('id', 0);
    8890                                $word                   = utf8_normalize_nfc(request_var('word', '', true));
    8991                                $replacement    = utf8_normalize_nfc(request_var('replacement', '', true));
    90                                
    91                                 if (!$word || !$replacement)
     92
     93                                if ($word === '' || $replacement === '')
    9294                                {
    9395                                        trigger_error($user->lang['ENTER_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
  • trunk/forum/includes/acp/auth.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: auth.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    5959                }
    6060        }
    61        
     61
    6262        /**
    6363        * Get permission mask
     
    141141                                }
    142142
    143                                
     143
    144144                                $hold_ary[$userdata['user_id']] = array();
    145145                                foreach ($forum_ids as $f_id)
     
    346346                // Build js roles array (role data assignments)
    347347                $s_role_js_array = '';
    348                
     348
    349349                if (sizeof($roles))
    350350                {
     
    697697                $cur_options = array();
    698698
     699                // Determine current options
    699700                $sql = 'SELECT auth_option, is_global, is_local
    700701                        FROM ' . ACL_OPTIONS_TABLE . '
     
    704705                while ($row = $db->sql_fetchrow($result))
    705706                {
    706                         if ($row['is_global'])
    707                         {
    708                                 $cur_options['global'][] = $row['auth_option'];
    709                         }
    710 
    711                         if ($row['is_local'])
    712                         {
    713                                 $cur_options['local'][] = $row['auth_option'];
    714                         }
     707                        $cur_options[$row['auth_option']] = ($row['is_global'] && $row['is_local']) ? 'both' : (($row['is_global']) ? 'global' : 'local');
    715708                }
    716709                $db->sql_freeresult($result);
     
    727720                        foreach ($option_ary as $option_value)
    728721                        {
    729                                 if (!in_array($option_value, $cur_options[$type]))
    730                                 {
    731                                         $new_options[$type][] = $option_value;
    732                                 }
     722                                $new_options[$type][] = $option_value;
    733723
    734724                                $flag = substr($option_value, 0, strpos($option_value, '_') + 1);
    735725
    736                                 if (!in_array($flag, $cur_options[$type]) && !in_array($flag, $new_options[$type]))
     726                                if (!in_array($flag, $new_options[$type]))
    737727                                {
    738728                                        $new_options[$type][] = $flag;
     
    745735                $options['local'] = array_diff($new_options['local'], $new_options['global']);
    746736                $options['global'] = array_diff($new_options['global'], $new_options['local']);
    747                 $options['local_global'] = array_intersect($new_options['local'], $new_options['global']);
    748 
    749                 $sql_ary = array();
    750 
     737                $options['both'] = array_intersect($new_options['local'], $new_options['global']);
     738
     739                // Now check which options to add/update
     740                $add_options = $update_options = array();
     741
     742                // First local ones...
    751743                foreach ($options as $type => $option_ary)
    752744                {
    753745                        foreach ($option_ary as $option)
    754746                        {
    755                                 $sql_ary[] = array(
    756                                         'auth_option'   => (string) $option,
    757                                         'is_global'             => ($type == 'global' || $type == 'local_global') ? 1 : 0,
    758                                         'is_local'              => ($type == 'local' || $type == 'local_global') ? 1 : 0
    759                                 );
    760                         }
    761                 }
    762 
    763                 $db->sql_multi_insert(ACL_OPTIONS_TABLE, $sql_ary);
     747                                if (!isset($cur_options[$option]))
     748                                {
     749                                        $add_options[] = array(
     750                                                'auth_option'   => (string) $option,
     751                                                'is_global'             => ($type == 'global' || $type == 'both') ? 1 : 0,
     752                                                'is_local'              => ($type == 'local' || $type == 'both') ? 1 : 0
     753                                        );
     754
     755                                        continue;
     756                                }
     757
     758                                // Else, update existing entry if it is changed...
     759                                if ($type === $cur_options[$option])
     760                                {
     761                                        continue;
     762                                }
     763
     764                                // New type is always both:
     765                                // If is now both, we set both.
     766                                // If it was global the new one is local and we need to set it to both
     767                                // If it was local the new one is global and we need to set it to both
     768                                $update_options[] = $option;
     769                        }
     770                }
     771
     772                if (!empty($add_options))
     773                {
     774                        $db->sql_multi_insert(ACL_OPTIONS_TABLE, $add_options);
     775                }
     776
     777                if (!empty($update_options))
     778                {
     779                        $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
     780                                SET is_global = 1, is_local = 1
     781                                WHERE ' . $db->sql_in_set('auth_option', $update_options);
     782                        $db->sql_query($sql);
     783                }
    764784
    765785                $cache->destroy('_acl_options');
     
    803823                $flag = key($auth);
    804824                $flag = substr($flag, 0, strpos($flag, '_') + 1);
    805                
     825
    806826                // This ID (the any-flag) is set if one or more permissions are true...
    807827                $any_option_id = (int) $this->acl_options['id'][$flag];
     
    917937                $flag = key($auth);
    918938                $flag = substr($flag, 0, strpos($flag, '_') + 1);
    919                
     939
    920940                // Remove any-flag from auth ary
    921941                if (isset($auth[$flag]))
     
    10681088                        $where_sql[] = $db->sql_in_set('auth_option_id', array_map('intval', $option_id_ary));
    10691089                }
    1070                
     1090
    10711091                $sql = "DELETE FROM $table
    10721092                        WHERE " . implode(' AND ', $where_sql);
     
    10911111                                'S_NEVER'       => ($cat_array['S_NEVER'] && !$cat_array['S_YES'] && !$cat_array['S_NO']) ? true : false,
    10921112                                'S_NO'          => ($cat_array['S_NO'] && !$cat_array['S_NEVER'] && !$cat_array['S_YES']) ? true : false,
    1093                                                        
     1113
    10941114                                'CAT_NAME'      => $user->lang['permission_cat'][$cat])
    10951115                        );
     
    11801200                                        );
    11811201                                }
    1182                        
     1202
    11831203                                $cat = $user->lang['acl_' . $permission]['cat'];
    1184                        
     1204
    11851205                                // Build our categories array
    11861206                                if (!isset($categories[$cat]))
  • trunk/forum/includes/acp/info/acp_board.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_board.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2727                                'post'                  => array('title' => 'ACP_POST_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION')),
    2828                                'signature'             => array('title' => 'ACP_SIGNATURE_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION')),
     29                                'feed'                  => array('title' => 'ACP_FEED_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION')),
    2930                                'registration'  => array('title' => 'ACP_REGISTER_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION')),
    3031
  • trunk/forum/includes/acp/info/acp_permissions.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_permissions.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2525
    2626                                'setting_forum_local'   => array('title' => 'ACP_FORUM_PERMISSIONS', 'auth' => 'acl_a_fauth && (acl_a_authusers || acl_a_authgroups)', 'cat' => array('ACP_FORUM_BASED_PERMISSIONS')),
     27                                'setting_forum_copy'    => array('title' => 'ACP_FORUM_PERMISSIONS_COPY', 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', 'cat' => array('ACP_FORUM_BASED_PERMISSIONS')),
    2728                                'setting_mod_local'             => array('title' => 'ACP_FORUM_MODERATORS', 'auth' => 'acl_a_mauth && (acl_a_authusers || acl_a_authgroups)', 'cat' => array('ACP_FORUM_BASED_PERMISSIONS')),
    2829                                'setting_user_global'   => array('title' => 'ACP_USERS_PERMISSIONS', 'auth' => 'acl_a_authusers && (acl_a_aauth || acl_a_mauth || acl_a_uauth)', 'cat' => array('ACP_GLOBAL_PERMISSIONS', 'ACP_CAT_USERS')),
  • trunk/forum/includes/acp/info/acp_users.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: acp_users.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2323                                'overview'              => array('title' => 'ACP_MANAGE_USERS', 'auth' => 'acl_a_user', 'cat' => array('ACP_CAT_USERS')),
    2424                                'feedback'              => array('title' => 'ACP_USER_FEEDBACK', 'auth' => 'acl_a_user', 'display' => false, 'cat' => array('ACP_CAT_USERS')),
     25                                'warnings'              => array('title' => 'ACP_USER_WARNINGS', 'auth' => 'acl_a_user', 'display' => false, 'cat' => array('ACP_CAT_USERS')),
    2526                                'profile'               => array('title' => 'ACP_USER_PROFILE', 'auth' => 'acl_a_user', 'display' => false, 'cat' => array('ACP_CAT_USERS')),
    2627                                'prefs'                 => array('title' => 'ACP_USER_PREFS', 'auth' => 'acl_a_user', 'display' => false, 'cat' => array('ACP_CAT_USERS')),
  • trunk/forum/includes/auth.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: auth.php 8985 2008-10-09 13:18:38Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    6565
    6666                        $cache->put('_acl_options', $this->acl_options);
    67                         $this->acl_cache($userdata);
    68                 }
    69                 else if (!trim($userdata['user_permissions']))
     67                }
     68
     69                if (!trim($userdata['user_permissions']))
    7070                {
    7171                        $this->acl_cache($userdata);
     
    609609                // Now grab group settings - non-role specific...
    610610                $sql_ary[] = 'SELECT ug.user_id, a.forum_id, a.auth_setting, a.auth_option_id' . $sql_opts_select . '
    611                         FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug' . $sql_opts_from . '
     611                        FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . GROUPS_TABLE . ' g' . $sql_opts_from . '
    612612                        WHERE a.auth_role_id = 0 ' .
    613613                                (($sql_opts_from) ? 'AND a.auth_option_id = ao.auth_option_id ' : '') . '
    614614                                AND a.group_id = ug.group_id
     615                                AND g.group_id = ug.group_id
    615616                                AND ug.user_pending = 0
     617                                AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
    616618                                ' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
    617619                                $sql_forum
     
    620622                // Now grab group settings - role specific...
    621623                $sql_ary[] = 'SELECT ug.user_id, a.forum_id, r.auth_setting, r.auth_option_id' . $sql_opts_select . '
    622                         FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . ACL_ROLES_DATA_TABLE . ' r' . $sql_opts_from . '
     624                        FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . GROUPS_TABLE . ' g, ' . ACL_ROLES_DATA_TABLE . ' r' . $sql_opts_from . '
    623625                        WHERE a.auth_role_id = r.role_id ' .
    624626                                (($sql_opts_from) ? 'AND r.auth_option_id = ao.auth_option_id ' : '') . '
    625627                                AND a.group_id = ug.group_id
     628                                AND g.group_id = ug.group_id
    626629                                AND ug.user_pending = 0
     630                                AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
    627631                                ' . (($sql_user) ? 'AND ug.' . $sql_user : '') . "
    628632                                $sql_forum
     
    826830                // Now grab group-specific permission settings
    827831                $sql = 'SELECT a.forum_id, a.auth_option_id, a.auth_role_id, a.auth_setting
    828                         FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug
     832                        FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . GROUPS_TABLE . ' g
    829833                        WHERE a.group_id = ug.group_id
     834                                AND g.group_id = ug.group_id
    830835                                AND ug.user_pending = 0
     836                                AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
    831837                                AND ug.user_id = ' . $user_id;
    832838                $result = $db->sql_query($sql);
  • trunk/forum/includes/auth/auth_apache.php

    r400 r702  
    66*
    77* @package login
    8 * @version $Id: auth_apache.php 8602 2008-06-04 16:05:27Z naderman $
     8* @version $Id$
    99* @copyright (c) 2005 phpBB Group
    1010* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    105105                                );
    106106                        }
    107        
     107
    108108                        // Successful login...
    109109                        return array(
     
    218218                'user_type'             => USER_NORMAL,
    219219                'user_ip'               => $user->ip,
     220                'user_new'              => ($config['new_member_post_limit']) ? 1 : 0,
    220221        );
    221222}
     
    228229function validate_session_apache(&$user)
    229230{
    230         if (!isset($_SERVER['PHP_AUTH_USER']))
    231         {
    232                 return false;
    233         }
    234 
    235         $php_auth_user = '';
    236         set_var($php_auth_user, $_SERVER['PHP_AUTH_USER'], 'string', true);
    237 
    238         return ($php_auth_user === $user['username']) ? true : false;
     231        // Check if PHP_AUTH_USER is set and handle this case
     232        if (isset($_SERVER['PHP_AUTH_USER']))
     233        {
     234                $php_auth_user = '';
     235                set_var($php_auth_user, $_SERVER['PHP_AUTH_USER'], 'string', true);
     236
     237                return ($php_auth_user === $user['username']) ? true : false;
     238        }
     239
     240        // PHP_AUTH_USER is not set. A valid session is now determined by the user type (anonymous/bot or not)
     241        if ($user['user_type'] == USER_IGNORE)
     242        {
     243                return true;
     244        }
     245
     246        return false;
    239247}
    240248
  • trunk/forum/includes/auth/auth_db.php

    r400 r702  
    88*
    99* @package login
    10 * @version $Id: auth_db.php 8479 2008-03-29 00:22:48Z naderman $
     10* @version $Id$
    1111* @copyright (c) 2005 phpBB Group
    1212* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    6363                );
    6464        }
     65        $show_captcha = $config['max_login_attempts'] && $row['user_login_attempts'] >= $config['max_login_attempts'];
    6566
    6667        // If there are too much login attempts, we need to check for an confirm image
    6768        // Every auth module is able to define what to do by itself...
    68         if ($config['max_login_attempts'] && $row['user_login_attempts'] >= $config['max_login_attempts'])
    69         {
    70                 $confirm_id = request_var('confirm_id', '');
    71                 $confirm_code = request_var('confirm_code', '');
    72 
     69        if ($show_captcha)
     70        {
    7371                // Visual Confirmation handling
    74                 if (!$confirm_id)
     72                if (!class_exists('phpbb_captcha_factory'))
     73                {
     74                        global $phpbb_root_path, $phpEx;
     75                        include ($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
     76                }
     77
     78                $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
     79                $captcha->init(CONFIRM_LOGIN);
     80                $vc_response = $captcha->validate($row);
     81                if ($vc_response)
    7582                {
    7683                        return array(
     
    8289                else
    8390                {
    84                         global $user;
    85 
    86                         $sql = 'SELECT code
    87                                 FROM ' . CONFIRM_TABLE . "
    88                                 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
    89                                         AND session_id = '" . $db->sql_escape($user->session_id) . "'
    90                                         AND confirm_type = " . CONFIRM_LOGIN;
    91                         $result = $db->sql_query($sql);
    92                         $confirm_row = $db->sql_fetchrow($result);
    93                         $db->sql_freeresult($result);
    94 
    95                         if ($confirm_row)
    96                         {
    97                                 if (strcasecmp($confirm_row['code'], $confirm_code) === 0)
    98                                 {
    99                                         $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
    100                                                 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
    101                                                         AND session_id = '" . $db->sql_escape($user->session_id) . "'
    102                                                         AND confirm_type = " . CONFIRM_LOGIN;
    103                                         $db->sql_query($sql);
    104                                 }
    105                                 else
    106                                 {
    107                                         return array(
    108                                                 'status'                => LOGIN_ERROR_ATTEMPTS,
    109                                                 'error_msg'             => 'CONFIRM_CODE_WRONG',
    110                                                 'user_row'              => $row,
    111                                         );
    112                                 }
    113                         }
    114                         else
    115                         {
    116                                 return array(
    117                                         'status'                => LOGIN_ERROR_ATTEMPTS,
    118                                         'error_msg'             => 'CONFIRM_CODE_WRONG',
    119                                         'user_row'              => $row,
    120                                 );
    121                         }
    122                 }
     91                        $captcha->reset();
     92                }
     93               
    12394        }
    12495
     
    142113
    143114                        // cp1252 is phpBB2's default encoding, characters outside ASCII range might work when converted into that encoding
    144                         if (md5($password_old_format) == $row['user_password'] || md5(utf8_to_cp1252($password_old_format)) == $row['user_password'])
     115                        // plain md5 support left in for conversions from other systems.
     116                        if ((strlen($row['user_password']) == 34 && (phpbb_check_hash(md5($password_old_format), $row['user_password']) || phpbb_check_hash(md5(utf8_to_cp1252($password_old_format)), $row['user_password'])))
     117                                || (strlen($row['user_password']) == 32  && (md5($password_old_format) == $row['user_password'] || md5(utf8_to_cp1252($password_old_format)) == $row['user_password'])))
    145118                        {
    146119                                $hash = phpbb_hash($password_new_format);
     
    227200        // Give status about wrong password...
    228201        return array(
    229                 'status'                => LOGIN_ERROR_PASSWORD,
    230                 'error_msg'             => 'LOGIN_ERROR_PASSWORD',
     202                'status'                => ($show_captcha) ? LOGIN_ERROR_ATTEMPTS : LOGIN_ERROR_PASSWORD,
     203                'error_msg'             => ($show_captcha) ? 'LOGIN_ERROR_ATTEMPTS' : 'LOGIN_ERROR_PASSWORD',
    231204                'user_row'              => $row,
    232205        );
  • trunk/forum/includes/auth/auth_ldap.php

    r400 r702  
    77*
    88* @package login
    9 * @version $Id: auth_ldap.php 8479 2008-03-29 00:22:48Z naderman $
     9* @version $Id$
    1010* @copyright (c) 2005 phpBB Group
    1111* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    6464        $search = @ldap_search(
    6565                $ldap,
    66                 $config['ldap_base_dn'],
     66                htmlspecialchars_decode($config['ldap_base_dn']),
    6767                ldap_user_filter($user->data['username']),
    68                 (empty($config['ldap_email'])) ? array($config['ldap_uid']) : array($config['ldap_uid'], $config['ldap_email']),
     68                (empty($config['ldap_email'])) ?
     69                        array(htmlspecialchars_decode($config['ldap_uid'])) :
     70                        array(htmlspecialchars_decode($config['ldap_uid']), htmlspecialchars_decode($config['ldap_email'])),
    6971                0,
    7072                1
     
    8688        }
    8789
    88         if (!empty($config['ldap_email']) && !isset($result[0][$config['ldap_email']]))
     90        if (!empty($config['ldap_email']) && !isset($result[0][htmlspecialchars_decode($config['ldap_email'])]))
    8991        {
    9092                return $user->lang['LDAP_NO_EMAIL'];
     
    153155        if ($config['ldap_user'] || $config['ldap_password'])
    154156        {
    155                 if (!@ldap_bind($ldap, $config['ldap_user'], htmlspecialchars_decode($config['ldap_password'])))
     157                if (!@ldap_bind($ldap, htmlspecialchars_decode($config['ldap_user']), htmlspecialchars_decode($config['ldap_password'])))
    156158                {
    157159                        return $user->lang['LDAP_NO_SERVER_CONNECTION'];
     
    161163        $search = @ldap_search(
    162164                $ldap,
    163                 $config['ldap_base_dn'],
     165                htmlspecialchars_decode($config['ldap_base_dn']),
    164166                ldap_user_filter($username),
    165                 (empty($config['ldap_email'])) ? array($config['ldap_uid']) : array($config['ldap_uid'], $config['ldap_email']),
     167                (empty($config['ldap_email'])) ?
     168                        array(htmlspecialchars_decode($config['ldap_uid'])) :
     169                        array(htmlspecialchars_decode($config['ldap_uid']), htmlspecialchars_decode($config['ldap_email'])),
    166170                0,
    167171                1
     
    224228                                        'username'              => $username,
    225229                                        'user_password' => phpbb_hash($password),
    226                                         'user_email'    => (!empty($config['ldap_email'])) ? $ldap_result[0][$config['ldap_email']][0] : '',
     230                                        'user_email'    => (!empty($config['ldap_email'])) ? utf8_htmlspecialchars($ldap_result[0][htmlspecialchars_decode($config['ldap_email'])][0]) : '',
    227231                                        'group_id'              => (int) $row['group_id'],
    228232                                        'user_type'             => USER_NORMAL,
    229233                                        'user_ip'               => $user->ip,
     234                                        'user_new'              => ($config['new_member_post_limit']) ? 1 : 0,
    230235                                );
    231236
     
    277282        if ($config['ldap_user_filter'])
    278283        {
    279                 $filter = "(&$filter({$config['ldap_user_filter']}))";
     284                $_filter = ($config['ldap_user_filter'][0] == '(' && substr($config['ldap_user_filter'], -1) == ')') ? $config['ldap_user_filter'] : "({$config['ldap_user_filter']})";
     285                $filter = "(&{$filter}{$_filter})";
    280286        }
    281287        return $filter;
  • trunk/forum/includes/bbcode.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: bbcode.php 8953 2008-09-28 17:08:09Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    129129        function bbcode_cache_init()
    130130        {
    131                 global $user, $phpbb_root_path;
     131                global $phpbb_root_path, $template, $user;
    132132
    133133                if (empty($this->template_filename))
     
    135135                        $this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']);
    136136                        $this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/bbcode.html';
    137                        
     137
    138138                        if (!@file_exists($this->template_filename))
    139139                        {
     
    266266                                        $this->bbcode_cache[$bbcode_id] = array(
    267267                                                'preg' => array(
    268                                                         '!\[color=(#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is'        => $this->bbcode_tpl('color', $bbcode_id),
     268                                                        '!\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is'   => $this->bbcode_tpl('color', $bbcode_id),
    269269                                                )
    270270                                        );
     
    361361                                                                // to replace all {VARS} to corresponding backreferences
    362362                                                                // Note that backreferences are numbered from bbcode_match
    363                                                                 if (preg_match_all('/\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m))
     363                                                                if (preg_match_all('/\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|INTTEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m))
    364364                                                                {
    365365                                                                        foreach ($m[0] as $i => $tok)
     
    411411                {
    412412                        global $user;
    413                        
     413
    414414                        $bbcode_hardtpl = array(
    415415                                'b_open'        => '<span style="font-weight: bold">',
     
    529529                {
    530530                        $tpl = 'olist_open';
    531                         $type = 'arabic-numbers';
     531                        $type = 'decimal';
    532532                }
    533533                else
    534534                {
    535535                        $tpl = 'olist_open';
    536                         $type = 'arabic-numbers';
     536                        $type = 'decimal';
    537537                }
    538538
  • trunk/forum/includes/cache.php

    r400 r702  
    33*
    44* @package acm
    5 * @version $Id: cache.php 8691 2008-07-28 13:26:20Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    8585                        while ($row = $db->sql_fetchrow($result))
    8686                        {
    87                                 $censors['match'][] = '#(?<!\w)(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')(?!\w)#i';
     87                                if ((version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) && @preg_match('/\p{L}/u', 'a') !== false)
     88                                {
     89                                        $censors['match'][] = '#(?<![\p{Nd}\p{L}_])(' . str_replace('\*', '[\p{Nd}\p{L}_]*?', preg_quote($row['word'], '#')) . ')(?![\p{Nd}\p{L}_])#iu';
     90                                }
     91                                else
     92                                {
     93                                        $censors['match'][] = '#(?<!\S)(' . str_replace('\*', '\S*?', preg_quote($row['word'], '#')) . ')(?!\S)#iu';
     94                                }
     95
    8896                                $censors['replace'][] = $row['replacement'];
    8997                        }
  • trunk/forum/includes/captcha/captcha_gd.php

    r400 r702  
    33*
    44* @package VC
    5 * @version $Id: captcha_gd.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2006 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2828        var $height = 96;
    2929
     30
    3031        /**
    3132        * Create the image containing $code with a seed of $seed
     
    3435        {
    3536                global $config;
    36                 srand($seed);
     37               
    3738                mt_srand($seed);
    3839
     
    5354
    5455                // Generate code characters
    55                 $characters = $sizes = $bounding_boxes = array();
     56                $characters = $sizes = $bounding_boxes = $noise = array();
    5657                $width_avail = $this->width - 15;
    5758                $code_len = strlen($code);
    58 
    5959                $captcha_bitmaps = $this->captcha_bitmaps();
     60
    6061                for ($i = 0; $i < $code_len; ++$i)
    6162                {
     
    7071                }
    7172
     73 
    7274                // Redistribute leftover x-space
    7375                $offset = array();
     
    99101                        }
    100102                }
    101 
     103                if ($config['captcha_gd_wave'] && ($config['captcha_gd_y_grid'] || $config['captcha_gd_y_grid']))
     104                {
     105                        $this->wave($img);
     106                }
     107               
     108               
     109                if ($config['captcha_gd_3d_noise'])
     110                {
     111                        $xoffset = mt_rand(0,9);
     112                        $noise_bitmaps = $this->captcha_noise_bg_bitmaps();
     113                        for ($i = 0; $i < $code_len; ++$i)
     114                        {
     115                                $noise[$i] = new char_cube3d($noise_bitmaps, mt_rand(1, count($noise_bitmaps['data'])));
     116
     117                                list($min, $max) = $noise[$i]->range();
     118                                //$box = $noise[$i]->dimensions($sizes[$i]);
     119                        }
     120                        $xoffset = 0;
     121                        for ($i = 0; $i < $code_len; ++$i)
     122                        {
     123                                $dimm = $bounding_boxes[$i];
     124                                $xoffset += ($offset[$i] - $dimm[0]);
     125                                $yoffset = mt_rand(-$dimm[1], $this->height - $dimm[3]);
     126         
     127                                $noise[$i]->drawchar($sizes[$i], $xoffset, $yoffset, $img, $colour->get_resource('background'), $scheme);
     128                                $xoffset += $dimm[2];
     129                        }
     130                }
    102131                $xoffset = 5;
    103132                for ($i = 0; $i < $code_len; ++$i)
     
    110139                        $xoffset += $dimm[2];
    111140                }
    112                
     141                if ($config['captcha_gd_wave'])
     142                {
     143                        $this->wave($img);
     144                }
    113145                if ($config['captcha_gd_foreground_noise'])
    114146                {
    115147                        $this->noise_line($img, 0, 0, $this->width, $this->height, $colour->get_resource('background'), $scheme, $bg_colours);
    116148                }
    117 
    118149                // Send image
    119150                header('Content-Type: image/png');
     
    124155
    125156        /**
     157        * Sinus
     158        */
     159        function wave($img)
     160        {
     161                global $config;
     162               
     163                $period_x = mt_rand(12,18);
     164                $period_y = mt_rand(7,14);
     165                $amp_x = mt_rand(5,10);
     166                $amp_y = mt_rand(2,4);
     167                $socket = mt_rand(0,100);
     168               
     169                $dampen_x = mt_rand($this->width/5, $this->width/2);
     170                $dampen_y = mt_rand($this->height/5, $this->height/2);
     171                $direction_x = (mt_rand (0, 1));
     172                $direction_y = (mt_rand (0, 1));
     173
     174                for ($i = 0; $i < $this->width; $i++)
     175                {
     176                        $dir = ($direction_x) ? $i : ($this->width - $i);
     177                        imagecopy($img, $img, $i-1, sin($socket+ $i/($period_x + $dir/$dampen_x)) * $amp_x, $i, 0, 1, $this->height);
     178                }
     179                $socket = mt_rand(0,100);
     180                for ($i = 0; $i < $this->height; $i++)
     181                {
     182                        $dir = ($direction_y) ? $i : ($this->height - $i);
     183                        imagecopy($img, $img ,sin($socket + $i/($period_y + ($dir)/$dampen_y)) * $amp_y, $i-1, 0, $i, $this->width, 1);
     184                }
     185                return $img;
     186        }
     187       
     188        /**
    126189        * Noise line
    127190        */
     
    172235        }
    173236
     237
     238        function captcha_noise_bg_bitmaps()
     239        {               
     240                return array(
     241                        'width'         => 15,
     242                        'height'        => 5,
     243                        'data'          => array(
     244
     245                        1 => array(
     246                                array(1,0,0,0,1,0,0,0,0,0,0,0,0,0,0),
     247                                array(1,0,0,0,0,1,0,0,0,0,0,0,0,0,0),
     248                                array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     249                                array(1,0,0,0,0,1,0,0,0,0,0,0,1,0,0),
     250                                array(1,0,0,0,0,0,1,0,0,0,0,1,0,0,0),
     251                        ),
     252                        2 => array(
     253                                array(1,1,mt_rand(0,1),1,0,1,1,1,1,0,0,0,0,0,0),
     254                                array(0,0,0,0,0,0,0,1,0,0,0,0,0,0,0),
     255                                array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     256                                array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     257                                array(0,0,0,0,0,0,0,0,0,1,1,0,1,1,1),
     258                        ),
     259                        3 => array(
     260                                array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
     261                                array(1,0,0,0,0,0,0,0,0,0,0,0,0,1,0),
     262                                array(0,0,0,0,1,0,0,0,0,0,0,0,0,0,1),
     263                                array(1,0,0,0,0,0,0,0,0,0,0,0,0,1,0),
     264                                array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
     265                        ),
     266                        4 => array(
     267                                array(1,0,1,0,1,0,0,1,1,0,0,0,0,0,0),
     268                                array(0,0,0,0,0,0,0,1,0,0,0,0,0,0,0),
     269                                array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     270                                array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     271                                array(1,0,1,0,0,0,0,0,0,0,0,0,0,0,0),
     272                        ),
     273                        5 => array(
     274                                array(1,1,1,1,0,0,0,1,1,1,0,0,1,0,1),
     275                                array(0,0,0,0,0,0,0,1,0,0,0,0,0,0,0),
     276                                array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     277                                array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     278                                array(1,0,1,0,0,0,0,0,0,0,0,0,0,0,0),
     279                        ),
     280                        6 => array(
     281                                array(mt_rand(0,1),mt_rand(0,1),mt_rand(0,1),mt_rand(0,1),mt_rand(0,1),0,mt_rand(0,1),mt_rand(0,1),mt_rand(0,1),mt_rand(0,1),mt_rand(0,1),0,mt_rand(0,1),mt_rand(0,1),mt_rand(0,1)),
     282                                array(0,0,0,0,0,0,0,mt_rand(0,1),0,0,0,0,0,0,0),
     283                                array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     284                                array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     285                                array(mt_rand(0,1),0,mt_rand(0,1),0,0,0,0,0,0,0,0,0,0,0,0),
     286                        ),
     287                        7 => array(
     288                                array(0,0,0,0,0,0,0,0,0,0,1,1,0,1,1),
     289                                array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     290                                array(0,0,1,1,0,0,0,1,0,0,0,0,0,0,0),
     291                                array(0,1,0,0,0,1,0,0,0,0,0,0,0,0,0),
     292                                array(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
     293                        ),
     294                ));
     295        }
     296       
    174297        /**
    175298        * Return bitmaps
     
    177300        function captcha_bitmaps()
    178301        {
     302                global $config;
     303               
     304                $chars = array(
     305                        'A'     =>      array(
     306                                                array(
     307                                                        array(0,0,0,0,1,0,0,0,0),
     308                                                        array(0,0,0,1,0,1,0,0,0),
     309                                                        array(0,0,0,1,0,1,0,0,0),
     310                                                        array(0,0,0,1,0,1,0,0,0),
     311                                                        array(0,0,1,0,0,0,1,0,0),
     312                                                        array(0,0,1,0,0,0,1,0,0),
     313                                                        array(0,0,1,0,0,0,1,0,0),
     314                                                        array(0,1,0,0,0,0,0,1,0),
     315                                                        array(0,1,0,0,0,0,0,1,0),
     316                                                        array(0,1,1,1,1,1,1,1,0),
     317                                                        array(0,1,0,0,0,0,0,1,0),
     318                                                        array(1,0,0,0,0,0,0,0,1),
     319                                                        array(1,0,0,0,0,0,0,0,1),
     320                                                        array(1,0,0,0,0,0,0,0,1),
     321                                                        array(1,0,0,0,0,0,0,0,1),
     322                                                ),
     323                                                array(
     324                                                        array(0,0,0,0,0,0,0,0,0),
     325                                                        array(0,0,0,0,0,0,0,0,0),
     326                                                        array(0,0,0,0,1,0,0,0,0),
     327                                                        array(0,0,0,1,0,1,0,0,0),
     328                                                        array(0,0,1,1,0,1,1,0,0),
     329                                                        array(0,0,1,0,0,0,1,0,0),
     330                                                        array(0,1,0,0,0,0,0,1,0),
     331                                                        array(0,1,0,0,0,0,0,1,0),
     332                                                        array(0,1,1,1,1,1,1,1,0),
     333                                                        array(0,1,0,0,0,0,0,1,0),
     334                                                        array(0,1,0,0,0,0,0,1,0),
     335                                                        array(0,1,0,0,0,0,0,1,0),
     336                                                        array(0,1,0,0,0,0,0,1,0),
     337                                                        array(0,1,0,0,0,0,0,1,0),
     338                                                        array(1,1,1,0,0,0,1,1,1),
     339                                                ),
     340                                                array(
     341                                                        array(0,0,0,0,0,0,0,0,0),
     342                                                        array(0,0,0,0,0,0,0,0,0),
     343                                                        array(0,0,0,0,0,0,0,0,0),
     344                                                        array(0,0,0,0,0,0,0,0,0),
     345                                                        array(0,0,1,1,1,1,1,0,0),
     346                                                        array(0,1,1,0,0,0,1,1,0),
     347                                                        array(1,1,0,0,0,0,0,1,1),
     348                                                        array(1,0,0,0,0,0,0,0,1),
     349                                                        array(0,0,0,0,0,0,0,1,1),
     350                                                        array(0,0,0,0,0,1,1,1,1),
     351                                                        array(0,0,0,1,1,1,0,0,1),
     352                                                        array(0,1,1,1,0,0,0,0,1),
     353                                                        array(1,0,0,0,0,0,0,0,1),
     354                                                        array(1,1,0,0,0,0,1,1,1),
     355                                                        array(0,1,1,1,1,1,1,0,1),
     356                                                ),
     357                                        ),
     358                'B'     =>              array(
     359                                                array(
     360                                                        array(1,1,1,1,1,1,1,0,0),
     361                                                        array(1,0,0,0,0,0,0,1,0),
     362                                                        array(1,0,0,0,0,0,0,0,1),
     363                                                        array(1,0,0,0,0,0,0,0,1),
     364                                                        array(1,0,0,0,0,0,0,0,1),
     365                                                        array(1,0,0,0,0,0,0,0,1),
     366                                                        array(1,0,0,0,0,0,0,1,0),
     367                                                        array(1,1,1,1,1,1,1,0,0),
     368                                                        array(1,0,0,0,0,0,0,1,0),
     369                                                        array(1,0,0,0,0,0,0,0,1),
     370                                                        array(1,0,0,0,0,0,0,0,1),
     371                                                        array(1,0,0,0,0,0,0,0,1),
     372                                                        array(1,0,0,0,0,0,0,0,1),
     373                                                        array(1,0,0,0,0,0,0,1,0),
     374                                                        array(1,1,1,1,1,1,1,0,0),
     375                                                ),
     376                                                array(
     377                                                        array(1,1,1,1,1,1,1,0,0),
     378                                                        array(0,1,0,0,0,0,0,1,0),
     379                                                        array(0,1,0,0,0,0,0,0,1),
     380                                                        array(0,1,0,0,0,0,0,0,1),
     381                                                        array(0,1,0,0,0,0,0,0,1),
     382                                                        array(0,1,0,0,0,0,0,0,1),
     383                                                        array(0,1,0,0,0,0,0,1,0),
     384                                                        array(0,1,1,1,1,1,1,0,0),
     385                                                        array(0,1,0,0,0,0,0,1,0),
     386                                                        array(0,1,0,0,0,0,0,0,1),
     387                                                        array(0,1,0,0,0,0,0,0,1),
     388                                                        array(0,1,0,0,0,0,0,0,1),
     389                                                        array(0,1,0,0,0,0,0,0,1),
     390                                                        array(0,1,0,0,0,0,0,1,0),
     391                                                        array(1,1,1,1,1,1,1,0,0),
     392                                                ),
     393                                                array(
     394                                                        array(0,1,0,0,0,0,0,0,0),
     395                                                        array(0,1,0,0,0,0,0,0,0),
     396                                                        array(0,1,0,0,0,0,0,0,0),
     397                                                        array(0,1,0,0,0,0,0,0,0),
     398                                                        array(0,1,0,0,0,0,0,0,0),
     399                                                        array(0,1,0,0,0,0,0,0,0),
     400                                                        array(0,1,0,0,0,0,0,0,0),
     401                                                        array(0,1,1,1,1,1,1,0,0),
     402                                                        array(0,1,0,0,0,0,0,1,0),
     403                                                        array(0,1,0,0,0,0,0,0,1),
     404                                                        array(0,1,0,0,0,0,0,0,1),
     405                                                        array(0,1,0,0,0,0,0,0,1),
     406                                                        array(0,1,0,0,0,0,0,0,1),
     407                                                        array(0,1,0,0,0,0,0,1,0),
     408                                                        array(0,1,1,1,1,1,1,0,0),
     409                                                ),
     410                                        ),
     411                'C'     =>              array(
     412                                                array(
     413                                                        array(0,0,1,1,1,1,1,0,0),
     414                                                        array(0,1,0,0,0,0,0,1,0),
     415                                                        array(1,0,0,0,0,0,0,0,1),
     416                                                        array(1,0,0,0,0,0,0,0,1),
     417                                                        array(1,0,0,0,0,0,0,0,0),
     418                                                        array(1,0,0,0,0,0,0,0,0),
     419                                                        array(1,0,0,0,0,0,0,0,0),
     420                                                        array(1,0,0,0,0,0,0,0,0),
     421                                                        array(1,0,0,0,0,0,0,0,0),
     422                                                        array(1,0,0,0,0,0,0,0,0),
     423                                                        array(1,0,0,0,0,0,0,0,0),
     424                                                        array(1,0,0,0,0,0,0,0,1),
     425                                                        array(1,0,0,0,0,0,0,0,1),
     426                                                        array(0,1,0,0,0,0,0,1,0),
     427                                                        array(0,0,1,1,1,1,1,0,0),
     428                                                ),
     429                                                array(
     430                                                        array(0,0,1,1,1,1,1,0,1),
     431                                                        array(0,1,0,0,0,0,0,1,1),
     432                                                        array(1,0,0,0,0,0,0,0,1),
     433                                                        array(1,0,0,0,0,0,0,0,1),
     434                                                        array(1,0,0,0,0,0,0,0,0),
     435                                                        array(1,0,0,0,0,0,0,0,0),
     436                                                        array(1,0,0,0,0,0,0,0,0),
     437                                                        array(1,0,0,0,0,0,0,0,0),
     438                                                        array(1,0,0,0,0,0,0,0,0),
     439                                                        array(1,0,0,0,0,0,0,0,0),
     440                                                        array(1,0,0,0,0,0,0,0,0),
     441                                                        array(1,0,0,0,0,0,0,0,1),
     442                                                        array(1,0,0,0,0,0,0,0,1),
     443                                                        array(0,1,0,0,0,0,0,1,1),
     444                                                        array(0,0,1,1,1,1,1,0,1),
     445                                                ),
     446                                        ),
     447                'D'     =>              array(
     448                                                array(
     449                                                        array(1,1,1,1,1,1,1,0,0),
     450                                                        array(1,0,0,0,0,0,0,1,0),
     451                                                        array(1,0,0,0,0,0,0,0,1),
     452                                                        array(1,0,0,0,0,0,0,0,1),
     453                                                        array(1,0,0,0,0,0,0,0,1),
     454                                                        array(1,0,0,0,0,0,0,0,1),
     455                                                        array(1,0,0,0,0,0,0,0,1),
     456                                                        array(1,0,0,0,0,0,0,0,1),
     457                                                        array(1,0,0,0,0,0,0,0,1),
     458                                                        array(1,0,0,0,0,0,0,0,1),
     459                                                        array(1,0,0,0,0,0,0,0,1),
     460                                                        array(1,0,0,0,0,0,0,0,1),
     461                                                        array(1,0,0,0,0,0,0,0,1),
     462                                                        array(1,0,0,0,0,0,0,1,0),
     463                                                        array(1,1,1,1,1,1,1,0,0),
     464                                                ),
     465                                                array(
     466                                                        array(1,1,1,1,1,1,1,0,0),
     467                                                        array(0,1,0,0,0,0,0,1,0),
     468                                                        array(0,1,0,0,0,0,0,0,1),
     469                                                        array(0,1,0,0,0,0,0,0,1),
     470                                                        array(0,1,0,0,0,0,0,0,1),
     471                                                        array(0,1,0,0,0,0,0,0,1),
     472                                                        array(0,1,0,0,0,0,0,0,1),
     473                                                        array(0,1,0,0,0,0,0,0,1),
     474                                                        array(0,1,0,0,0,0,0,0,1),
     475                                                        array(0,1,0,0,0,0,0,0,1),
     476                                                        array(0,1,0,0,0,0,0,0,1),
     477                                                        array(0,1,0,0,0,0,0,0,1),
     478                                                        array(0,1,0,0,0,0,0,0,1),
     479                                                        array(0,1,0,0,0,0,0,1,0),
     480                                                        array(1,1,1,1,1,1,1,0,0),
     481                                                ),
     482                                                array(
     483                                                        array(0,0,0,0,0,0,0,0,1),
     484                                                        array(0,0,0,0,0,0,0,0,1),
     485                                                        array(0,0,0,0,0,0,0,0,1),
     486                                                        array(0,0,0,0,0,0,0,0,1),
     487                                                        array(0,0,0,0,0,0,0,0,1),
     488                                                        array(0,0,0,0,0,0,0,0,1),
     489                                                        array(0,0,0,0,0,0,0,0,1),
     490                                                        array(0,0,1,1,1,1,1,0,1),
     491                                                        array(0,1,1,0,0,0,1,1,1),
     492                                                        array(0,1,0,0,0,0,0,0,1),
     493                                                        array(0,1,0,0,0,0,0,0,1),
     494                                                        array(0,1,0,0,0,0,0,0,1),
     495                                                        array(0,1,0,0,0,0,0,0,1),
     496                                                        array(0,1,1,0,0,0,1,1,1),
     497                                                        array(0,0,1,1,1,1,1,0,1),
     498                                                ),
     499                                        ),
     500                'E'     =>              array(
     501                                                array(
     502                                                        array(1,1,1,1,1,1,1,1,1),
     503                                                        array(1,0,0,0,0,0,0,0,0),
     504                                                        array(1,0,0,0,0,0,0,0,0),
     505                                                        array(1,0,0,0,0,0,0,0,0),
     506                                                        array(1,0,0,0,0,0,0,0,0),
     507                                                        array(1,0,0,0,0,0,0,0,0),
     508                                                        array(1,0,0,0,0,0,0,0,0),
     509                                                        array(1,1,1,1,1,1,1,1,0),
     510                                                        array(1,0,0,0,0,0,0,0,0),
     511                                                        array(1,0,0,0,0,0,0,0,0),
     512                                                        array(1,0,0,0,0,0,0,0,0),
     513                                                        array(1,0,0,0,0,0,0,0,0),
     514                                                        array(1,0,0,0,0,0,0,0,0),
     515                                                        array(1,0,0,0,0,0,0,0,0),
     516                                                        array(1,1,1,1,1,1,1,1,1),
     517                                                ),
     518                                                array(
     519                                                        array(1,1,1,1,1,1,1,1,1),
     520                                                        array(1,0,0,0,0,0,0,0,1),
     521                                                        array(1,0,0,0,0,0,0,0,0),
     522                                                        array(1,0,0,0,0,0,0,0,0),
     523                                                        array(1,0,0,0,0,0,0,0,0),
     524                                                        array(1,0,0,0,0,0,0,0,0),
     525                                                        array(1,0,0,0,0,0,0,0,0),
     526                                                        array(1,1,1,1,1,1,1,0,0),
     527                                                        array(1,0,0,0,0,0,0,0,0),
     528                                                        array(1,0,0,0,0,0,0,0,0),
     529                                                        array(1,0,0,0,0,0,0,0,0),
     530                                                        array(1,0,0,0,0,0,0,0,0),
     531                                                        array(1,0,0,0,0,0,0,0,0),
     532                                                        array(1,0,0,0,0,0,0,0,1),
     533                                                        array(1,1,1,1,1,1,1,1,1),
     534                                                ),
     535                                                array(
     536                                                        array(0,0,0,0,0,0,0,0,0),
     537                                                        array(0,0,0,0,0,0,0,0,0),
     538                                                        array(0,0,0,0,0,0,0,0,0),
     539                                                        array(0,0,0,0,0,0,0,0,0),
     540                                                        array(0,0,0,0,0,0,0,0,0),
     541                                                        array(0,0,0,0,0,0,0,0,0),
     542                                                        array(0,0,0,0,0,0,0,0,0),
     543                                                        array(0,0,1,1,1,1,1,0,0),
     544                                                        array(0,1,1,0,0,0,1,1,0),
     545                                                        array(1,1,0,0,0,0,0,1,1),
     546                                                        array(1,1,1,1,1,1,1,1,1),
     547                                                        array(1,0,0,0,0,0,0,0,0),
     548                                                        array(1,0,0,0,0,0,0,0,1),
     549                                                        array(1,1,0,0,0,0,0,1,1),
     550                                                        array(0,1,1,1,1,1,1,1,0),
     551                                                ),
     552                                        ),
     553                'F'     =>              array(
     554                                                array(
     555                                                        array(1,1,1,1,1,1,1,1,1),
     556                                                        array(1,0,0,0,0,0,0,0,0),
     557                                                        array(1,0,0,0,0,0,0,0,0),
     558                                                        array(1,0,0,0,0,0,0,0,0),
     559                                                        array(1,0,0,0,0,0,0,0,0),
     560                                                        array(1,0,0,0,0,0,0,0,0),
     561                                                        array(1,0,0,0,0,0,0,0,0),
     562                                                        array(1,1,1,1,1,1,1,0,0),
     563                                                        array(1,0,0,0,0,0,0,0,0),
     564                                                        array(1,0,0,0,0,0,0,0,0),
     565                                                        array(1,0,0,0,0,0,0,0,0),
     566                                                        array(1,0,0,0,0,0,0,0,0),
     567                                                        array(1,0,0,0,0,0,0,0,0),
     568                                                        array(1,0,0,0,0,0,0,0,0),
     569                                                        array(1,0,0,0,0,0,0,0,0),
     570                                                ),
     571                                                array(
     572                                                        array(0,1,1,1,1,1,1,1,1),
     573                                                        array(0,1,0,0,0,0,0,0,1),
     574                                                        array(0,1,0,0,0,0,0,0,0),
     575                                                        array(0,1,0,0,0,0,0,0,0),
     576                                                        array(0,1,0,0,0,0,0,0,0),
     577                                                        array(0,1,0,0,0,0,0,0,0),
     578                                                        array(0,1,0,0,0,0,0,0,0),
     579                                                        array(0,1,1,1,1,1,1,0,0),
     580                                                        array(0,1,0,0,0,0,0,0,0),
     581                                                        array(0,1,0,0,0,0,0,0,0),
     582                                                        array(0,1,0,0,0,0,0,0,0),
     583                                                        array(0,1,0,0,0,0,0,0,0),
     584                                                        array(0,1,0,0,0,0,0,0,0),
     585                                                        array(0,1,0,0,0,0,0,0,0),
     586                                                        array(1,1,1,0,0,0,0,0,0),
     587                                                ),
     588                                                array(
     589                                                        array(0,0,0,1,1,0,0,0,0),
     590                                                        array(0,0,1,1,0,0,0,0,0),
     591                                                        array(0,1,1,0,0,0,0,0,0),
     592                                                        array(0,1,0,0,0,0,0,0,0),
     593                                                        array(0,1,0,0,0,0,0,0,0),
     594                                                        array(1,1,1,1,0,0,0,0,0),
     595                                                        array(0,1,0,0,0,0,0,0,0),
     596                                                        array(0,1,0,0,0,0,0,0,0),
     597                                                        array(0,1,0,0,0,0,0,0,0),
     598                                                        array(0,1,0,0,0,0,0,0,0),
     599                                                        array(0,1,0,0,0,0,0,0,0),
     600                                                        array(0,1,0,0,0,0,0,0,0),
     601                                                        array(0,1,0,0,0,0,0,0,0),
     602                                                        array(0,1,0,0,0,0,0,0,0),
     603                                                        array(0,1,0,0,0,0,0,0,0),
     604                                                ),
     605                                        ),
     606                'G'     =>              array(
     607                                                array(
     608                                                        array(0,0,1,1,1,1,1,0,0),
     609                                                        array(0,1,0,0,0,0,0,1,0),
     610                                                        array(1,0,0,0,0,0,0,0,1),
     611                                                        array(1,0,0,0,0,0,0,0,0),
     612                                                        array(1,0,0,0,0,0,0,0,0),
     613                                                        array(1,0,0,0,0,0,0,0,0),
     614                                                        array(1,0,0,0,0,0,0,0,0),
     615                                                        array(1,0,0,0,0,0,0,0,0),
     616                                                        array(1,0,0,0,0,0,1,1,1),
     617                                                        array(1,0,0,0,0,0,0,0,1),
     618                                                        array(1,0,0,0,0,0,0,0,1),
     619                                                        array(1,0,0,0,0,0,0,0,1),
     620                                                        array(1,0,0,0,0,0,0,0,1),
     621                                                        array(0,1,0,0,0,0,0,1,0),
     622                                                        array(0,0,1,1,1,1,1,0,0),
     623                                                ),
     624                                                array(
     625                                                        array(0,0,1,1,1,1,1,0,1),
     626                                                        array(0,1,0,0,0,0,0,1,1),
     627                                                        array(1,0,0,0,0,0,0,0,1),
     628                                                        array(1,0,0,0,0,0,0,0,0),
     629                                                        array(1,0,0,0,0,0,0,0,0),
     630                                                        array(1,0,0,0,0,0,0,0,0),
     631                                                        array(1,0,0,0,0,0,0,0,0),
     632                                                        array(1,0,0,0,0,0,0,0,0),
     633                                                        array(1,0,0,0,1,1,1,1,1),
     634                                                        array(1,0,0,0,1,0,0,0,1),
     635                                                        array(1,0,0,0,1,0,0,0,1),
     636                                                        array(1,0,0,0,0,0,0,0,1),
     637                                                        array(1,0,0,0,0,0,0,0,1),
     638                                                        array(0,1,0,0,0,0,0,1,1),
     639                                                        array(0,0,1,1,1,1,1,0,1),
     640                                                ),
     641                                                array(
     642                                                        array(0,0,1,1,1,1,1,0,1),
     643                                                        array(0,1,1,0,0,0,0,1,1),
     644                                                        array(1,1,0,0,0,0,0,1,1),
     645                                                        array(1,0,0,0,0,0,0,0,1),
     646                                                        array(1,0,0,0,0,0,0,0,1),
     647                                                        array(1,1,1,0,0,0,0,0,1),
     648                                                        array(0,0,1,1,1,1,1,1,1),
     649                                                        array(0,0,0,0,0,0,0,0,1),
     650                                                        array(0,0,0,0,0,0,0,0,1),
     651                                                        array(0,0,0,0,0,0,0,0,1),
     652                                                        array(0,0,0,0,0,0,0,0,1),
     653                                                        array(0,0,0,0,0,0,0,1,1),
     654                                                        array(1,1,1,1,1,1,1,1,0),
     655                                                        array(0,0,0,0,0,0,0,0,0),
     656                                                        array(0,0,0,0,0,0,0,0,0),
     657                                                ),
     658                                        ),
     659                'H'     =>              array(
     660                                                array(
     661                                                        array(1,0,0,0,0,0,0,0,1),
     662                                                        array(1,0,0,0,0,0,0,0,1),
     663                                                        array(1,0,0,0,0,0,0,0,1),
     664                                                        array(1,0,0,0,0,0,0,0,1),
     665                                                        array(1,0,0,0,0,0,0,0,1),
     666                                                        array(1,0,0,0,0,0,0,0,1),
     667                                                        array(1,0,0,0,0,0,0,0,1),
     668                                                        array(1,1,1,1,1,1,1,1,1),
     669                                                        array(1,0,0,0,0,0,0,0,1),
     670                                                        array(1,0,0,0,0,0,0,0,1),
     671                                                        array(1,0,0,0,0,0,0,0,1),
     672                                                        array(1,0,0,0,0,0,0,0,1),
     673                                                        array(1,0,0,0,0,0,0,0,1),
     674                                                        array(1,0,0,0,0,0,0,0,1),
     675                                                        array(1,0,0,0,0,0,0,0,1),
     676                                                ),
     677                                                array(
     678                                                        array(1,1,1,0,0,0,1,1,1),
     679                                                        array(0,1,0,0,0,0,0,1,0),
     680                                                        array(0,1,0,0,0,0,0,1,0),
     681                                                        array(0,1,0,0,0,0,0,1,0),
     682                                                        array(0,1,0,0,0,0,0,1,0),
     683                                                        array(0,1,0,0,0,0,0,1,0),
     684                                                        array(0,1,0,0,0,0,0,1,0),
     685                                                        array(0,1,1,1,1,1,1,1,0),
     686                                                        array(0,1,0,0,0,0,0,1,0),
     687                                                        array(0,1,0,0,0,0,0,1,0),
     688                                                        array(0,1,0,0,0,0,0,1,0),
     689                                                        array(0,1,0,0,0,0,0,1,0),
     690                                                        array(0,1,0,0,0,0,0,1,0),
     691                                                        array(0,1,0,0,0,0,0,1,0),
     692                                                        array(1,1,1,0,0,0,1,1,1),
     693                                                ),
     694                                                array(
     695                                                        array(1,0,0,0,0,0,0,0,0),
     696                                                        array(1,0,0,0,0,0,0,0,0),
     697                                                        array(1,0,0,0,0,0,0,0,0),
     698                                                        array(1,0,0,0,0,0,0,0,0),
     699                                                        array(1,0,0,0,0,0,0,0,0),
     700                                                        array(1,0,0,0,0,0,0,0,0),
     701                                                        array(1,0,0,0,0,0,0,0,0),
     702                                                        array(1,0,0,1,1,1,0,0,0),
     703                                                        array(1,1,1,1,0,1,1,0,0),
     704                                                        array(1,0,0,0,0,0,1,0,0),
     705                                                        array(1,0,0,0,0,0,1,0,0),
     706                                                        array(1,0,0,0,0,0,1,0,0),
     707                                                        array(1,0,0,0,0,0,1,0,0),
     708                                                        array(1,0,0,0,0,0,1,0,0),
     709                                                        array(1,0,0,0,0,0,1,0,0),
     710                                                ),
     711                                        ),
     712                'I'     =>              array(
     713                                                array(
     714                                                        array(1,1,1,1,1,1,1,1,1),
     715                                                        array(0,0,0,0,1,0,0,0,0),
     716                                                        array(0,0,0,0,1,0,0,0,0),
     717                                                        array(0,0,0,0,1,0,0,0,0),
     718                                                        array(0,0,0,0,1,0,0,0,0),
     719                                                        array(0,0,0,0,1,0,0,0,0),
     720                                                        array(0,0,0,0,1,0,0,0,0),
     721                                                        array(0,0,0,0,1,0,0,0,0),
     722                                                        array(0,0,0,0,1,0,0,0,0),
     723                                                        array(0,0,0,0,1,0,0,0,0),
     724                                                        array(0,0,0,0,1,0,0,0,0),
     725                                                        array(0,0,0,0,1,0,0,0,0),
     726                                                        array(0,0,0,0,1,0,0,0,0),
     727                                                        array(0,0,0,0,1,0,0,0,0),
     728                                                        array(1,1,1,1,1,1,1,1,1),
     729                                                ),
     730                                                array(
     731                                                        array(0,0,0,1,1,1,0,0,0),
     732                                                        array(0,0,0,0,1,0,0,0,0),
     733                                                        array(0,0,0,0,1,0,0,0,0),
     734                                                        array(0,0,0,0,1,0,0,0,0),
     735                                                        array(0,0,0,0,1,0,0,0,0),
     736                                                        array(0,0,0,0,1,0,0,0,0),
     737                                                        array(0,0,0,0,1,0,0,0,0),
     738                                                        array(0,0,0,0,1,0,0,0,0),
     739                                                        array(0,0,0,0,1,0,0,0,0),
     740                                                        array(0,0,0,0,1,0,0,0,0),
     741                                                        array(0,0,0,0,1,0,0,0,0),
     742                                                        array(0,0,0,0,1,0,0,0,0),
     743                                                        array(0,0,0,0,1,0,0,0,0),
     744                                                        array(0,0,0,0,1,0,0,0,0),
     745                                                        array(0,0,0,1,1,1,0,0,0),
     746                                                ),
     747                                                array(
     748                                                        array(0,0,0,0,0,0,0,0,0),
     749                                                        array(0,0,0,0,0,0,0,0,0),
     750                                                        array(0,0,0,0,0,0,0,0,0),
     751                                                        array(0,0,0,0,1,0,0,0,0),
     752                                                        array(0,0,0,1,1,1,0,0,0),
     753                                                        array(0,0,0,0,1,0,0,0,0),
     754                                                        array(0,0,0,0,0,0,0,0,0),
     755                                                        array(0,0,0,0,1,0,0,0,0),
     756                                                        array(0,0,0,0,1,0,0,0,0),
     757                                                        array(0,0,0,0,1,0,0,0,0),
     758                                                        array(0,0,0,0,1,0,0,0,0),
     759                                                        array(0,0,0,0,1,0,0,0,0),
     760                                                        array(0,0,0,0,1,0,0,0,0),
     761                                                        array(0,0,0,0,1,0,0,0,0),
     762                                                        array(0,0,0,1,1,1,0,0,0),
     763                                                ),
     764                                        ),
     765                'J'     =>              array(
     766                                                array(
     767                                                        array(1,1,1,1,1,1,1,1,1),
     768                                                        array(0,0,0,0,0,1,0,0,0),
     769                                                        array(0,0,0,0,0,1,0,0,0),
     770                                                        array(0,0,0,0,0,1,0,0,0),
     771                                                        array(0,0,0,0,0,1,0,0,0),
     772                                                        array(0,0,0,0,0,1,0,0,0),
     773                                                        array(0,0,0,0,0,1,0,0,0),
     774                                                        array(0,0,0,0,0,1,0,0,0),
     775                                                        array(0,0,0,0,0,1,0,0,0),
     776                                                        array(0,0,0,0,0,1,0,0,0),
     777                                                        array(0,0,0,0,0,1,0,0,0),
     778                                                        array(1,0,0,0,0,1,0,0,0),
     779                                                        array(1,0,0,0,0,1,0,0,0),
     780                                                        array(0,1,0,0,1,0,0,0,0),
     781                                                        array(0,0,1,1,0,0,0,0,0),
     782                                                ),
     783                                                array(
     784                                                        array(1,1,1,1,1,1,1,1,1),
     785                                                        array(0,0,0,0,0,1,0,0,0),
     786                                                        array(0,0,0,0,0,1,0,0,0),
     787                                                        array(0,0,0,0,0,1,0,0,0),
     788                                                        array(0,0,0,0,0,1,0,0,0),
     789                                                        array(0,0,0,0,0,1,0,0,0),
     790                                                        array(0,0,0,0,0,1,0,0,0),
     791                                                        array(0,0,0,0,0,1,0,0,0),
     792                                                        array(0,0,0,0,0,1,0,0,0),
     793                                                        array(0,0,0,0,0,1,0,0,0),
     794                                                        array(0,0,0,0,0,1,0,0,0),
     795                                                        array(1,0,0,0,0,1,0,0,0),
     796                                                        array(1,0,0,0,0,1,0,0,0),
     797                                                        array(1,1,0,0,1,0,0,0,0),
     798                                                        array(1,0,1,1,0,0,0,0,0),
     799                                                ),
     800                                                array(
     801                                                        array(0,0,0,0,0,0,0,0,0),
     802                                                        array(0,0,0,0,0,0,0,0,0),
     803                                                        array(0,0,0,0,0,0,0,0,0),
     804                                                        array(0,0,0,0,0,0,0,0,0),
     805                                                        array(0,0,0,0,0,1,0,0,0),
     806                                                        array(0,0,0,0,0,0,0,0,0),
     807                                                        array(0,0,0,0,0,1,0,0,0),
     808                                                        array(0,0,0,0,0,1,0,0,0),
     809                                                        array(0,0,0,0,0,1,0,0,0),
     810                                                        array(0,0,0,0,0,1,0,0,0),
     811                                                        array(0,0,0,0,0,1,0,0,0),
     812                                                        array(1,0,0,0,0,1,0,0,0),
     813                                                        array(1,0,0,0,0,1,0,0,0),
     814                                                        array(0,1,0,0,1,0,0,0,0),
     815                                                        array(0,0,1,1,0,0,0,0,0),
     816                                                ),
     817                                        ),
     818                'K'     =>              array(
     819                                                array(    // New 'K', supplied by NeoThermic
     820                                                        array(1,0,0,0,0,0,0,0,1),
     821                                                        array(1,0,0,0,0,0,0,1,0),
     822                                                        array(1,0,0,0,0,0,1,0,0),
     823                                                        array(1,0,0,0,0,1,0,0,0),
     824                                                        array(1,0,0,0,1,0,0,0,0),
     825                                                        array(1,0,0,1,0,0,0,0,0),
     826                                                        array(1,0,1,0,0,0,0,0,0),
     827                                                        array(1,1,0,0,0,0,0,0,0),
     828                                                        array(1,0,1,0,0,0,0,0,0),
     829                                                        array(1,0,0,1,0,0,0,0,0),
     830                                                        array(1,0,0,0,1,0,0,0,0),
     831                                                        array(1,0,0,0,0,1,0,0,0),
     832                                                        array(1,0,0,0,0,0,1,0,0),
     833                                                        array(1,0,0,0,0,0,0,1,0),
     834                                                        array(1,0,0,0,0,0,0,0,1),
     835                                                ),
     836                                                array(
     837                                                        array(0,1,0,0,0,0,0,0,1),
     838                                                        array(0,1,0,0,0,0,0,1,0),
     839                                                        array(0,1,0,0,0,0,1,0,0),
     840                                                        array(0,1,0,0,0,1,0,0,0),
     841                                                        array(0,1,0,0,1,0,0,0,0),
     842                                                        array(0,1,0,1,0,0,0,0,0),
     843                                                        array(0,1,1,0,0,0,0,0,0),
     844                                                        array(0,1,0,0,0,0,0,0,0),
     845                                                        array(0,1,1,0,0,0,0,0,0),
     846                                                        array(0,1,0,1,0,0,0,0,0),
     847                                                        array(0,1,0,0,1,0,0,0,0),
     848                                                        array(0,1,0,0,0,1,0,0,0),
     849                                                        array(0,1,0,0,0,0,1,0,0),
     850                                                        array(0,1,0,0,0,0,0,1,0),
     851                                                        array(1,1,1,0,0,0,1,1,1),
     852                                                ),
     853                                                array(
     854                                                        array(0,0,0,0,0,0,0,0,0),
     855                                                        array(0,1,0,0,0,0,0,0,0),
     856                                                        array(0,1,0,0,0,0,0,0,0),
     857                                                        array(0,1,0,0,0,1,0,0,0),
     858                                                        array(0,1,0,0,1,0,0,0,0),
     859                                                        array(0,1,0,1,0,0,0,0,0),
     860                                                        array(0,1,1,0,0,0,0,0,0),
     861                                                        array(0,1,0,0,0,0,0,0,0),
     862                                                        array(0,1,1,0,0,0,0,0,0),
     863                                                        array(0,1,0,1,0,0,0,0,0),
     864                                                        array(0,1,0,0,1,0,0,0,0),
     865                                                        array(0,1,0,0,0,1,0,0,0),
     866                                                        array(0,1,0,0,0,0,1,0,0),
     867                                                        array(0,1,0,0,0,0,0,1,0),
     868                                                        array(0,1,0,0,0,0,0,1,0),
     869                                                ),
     870                                        ),
     871                'L'     =>              array(
     872                                                array(
     873                                                        array(0,0,0,0,0,0,0,0,0),
     874                                                        array(1,0,0,0,0,0,0,0,0),
     875                                                        array(1,0,0,0,0,0,0,0,0),
     876                                                        array(1,0,0,0,0,0,0,0,0),
     877                                                        array(1,0,0,0,0,0,0,0,0),
     878                                                        array(1,0,0,0,0,0,0,0,0),
     879                                                        array(1,0,0,0,0,0,0,0,0),
     880                                                        array(1,0,0,0,0,0,0,0,0),
     881                                                        array(1,0,0,0,0,0,0,0,0),
     882                                                        array(1,0,0,0,0,0,0,0,0),
     883                                                        array(1,0,0,0,0,0,0,0,0),
     884                                                        array(1,0,0,0,0,0,0,0,0),
     885                                                        array(1,0,0,0,0,0,0,0,0),
     886                                                        array(1,0,0,0,0,0,0,0,0),
     887                                                        array(1,1,1,1,1,1,1,1,1),
     888                                                ),
     889                                                array(
     890                                                        array(0,0,0,0,0,0,0,0,0),
     891                                                        array(0,1,0,0,0,0,0,0,0),
     892                                                        array(0,1,0,0,0,0,0,0,0),
     893                                                        array(0,1,0,0,0,0,0,0,0),
     894                                                        array(0,1,0,0,0,0,0,0,0),
     895                                                        array(0,1,0,0,0,0,0,0,0),
     896                                                        array(0,1,0,0,0,0,0,0,0),
     897                                                        array(0,1,0,0,0,0,0,0,0),
     898                                                        array(0,1,0,0,0,0,0,0,0),
     899                                                        array(0,1,0,0,0,0,0,0,0),
     900                                                        array(0,1,0,0,0,0,0,0,0),
     901                                                        array(0,1,0,0,0,0,0,0,0),
     902                                                        array(0,1,0,0,0,0,0,0,0),
     903                                                        array(0,1,0,0,0,0,0,0,1),
     904                                                        array(1,1,1,1,1,1,1,1,1),
     905                                                ),
     906                                                array(
     907                                                        array(0,0,0,0,0,0,0,0,0),
     908                                                        array(0,1,0,0,0,0,0,0,0),
     909                                                        array(0,1,0,0,0,0,0,0,0),
     910                                                        array(0,1,0,0,0,0,0,0,0),
     911                                                        array(0,1,0,0,0,0,0,0,0),
     912                                                        array(0,1,0,0,0,0,0,0,0),
     913                                                        array(0,1,0,0,0,0,0,0,0),
     914                                                        array(0,1,0,0,0,0,0,0,0),
     915                                                        array(0,1,0,0,0,0,0,0,0),
     916                                                        array(0,1,0,0,0,0,0,0,0),
     917                                                        array(0,1,0,0,0,0,0,0,0),
     918                                                        array(0,1,0,0,0,0,0,0,0),
     919                                                        array(0,1,0,0,0,0,0,0,0),
     920                                                        array(0,1,1,0,0,0,0,0,0),
     921                                                        array(0,0,1,1,1,0,0,0,0),
     922                                                ),
     923                                        ),
     924                'M'     =>              array(
     925                                                array(
     926                                                        array(1,1,0,0,0,0,0,1,1),
     927                                                        array(1,1,0,0,0,0,0,1,1),
     928                                                        array(1,0,1,0,0,0,1,0,1),
     929                                                        array(1,0,1,0,0,0,1,0,1),
     930                                                        array(1,0,1,0,0,0,1,0,1),
     931                                                        array(1,0,0,1,0,1,0,0,1),
     932                                                        array(1,0,0,1,0,1,0,0,1),
     933                                                        array(1,0,0,1,0,1,0,0,1),
     934                                                        array(1,0,0,0,1,0,0,0,1),
     935                                                        array(1,0,0,0,1,0,0,0,1),
     936                                                        array(1,0,0,0,0,0,0,0,1),
     937                                                        array(1,0,0,0,0,0,0,0,1),
     938                                                        array(1,0,0,0,0,0,0,0,1),
     939                                                        array(1,0,0,0,0,0,0,0,1),
     940                                                        array(1,0,0,0,0,0,0,0,1),
     941                                                ),
     942                                                array(
     943                                                        array(0,0,0,0,0,0,0,0,0),
     944                                                        array(0,1,0,0,0,0,0,1,0),
     945                                                        array(0,1,1,0,0,0,1,1,0),
     946                                                        array(0,1,1,0,0,0,1,1,0),
     947                                                        array(0,1,1,0,0,0,1,1,0),
     948                                                        array(0,1,0,1,0,1,0,1,0),
     949                                                        array(0,1,0,1,0,1,0,1,0),
     950                                                        array(0,1,0,1,0,1,0,1,0),
     951                                                        array(0,1,0,0,1,0,0,1,0),
     952                                                        array(0,1,0,0,1,0,0,1,0),
     953                                                        array(0,1,0,0,0,0,0,1,0),
     954                                                        array(0,1,0,0,0,0,0,1,0),
     955                                                        array(0,1,0,0,0,0,0,1,0),
     956                                                        array(0,1,0,0,0,0,0,1,0),
     957                                                        array(1,1,1,0,0,0,1,1,1),
     958                                                ),
     959                                                array(
     960                                                        array(0,0,0,0,0,0,0,0,0),
     961                                                        array(0,0,0,0,0,0,0,0,0),
     962                                                        array(0,0,0,0,0,0,0,0,0),
     963                                                        array(0,0,0,0,0,0,0,0,0),
     964                                                        array(0,0,0,0,0,0,0,0,0),
     965                                                        array(0,0,0,0,0,0,0,0,0),
     966                                                        array(0,1,1,1,0,1,1,1,0),
     967                                                        array(1,1,0,1,1,1,0,1,1),
     968                                                        array(1,0,0,0,1,0,0,0,1),
     969                                                        array(1,0,0,0,1,0,0,0,1),
     970                                                        array(1,0,0,0,1,0,0,0,1),
     971                                                        array(1,0,0,0,1,0,0,0,1),
     972                                                        array(1,0,0,0,1,0,0,0,1),
     973                                                        array(1,0,0,0,1,0,0,0,1),
     974                                                        array(1,0,0,0,1,0,0,0,1),
     975                                                ),
     976                                        ),
     977                'N'     =>              array(
     978                                                array(
     979                                                        array(1,1,0,0,0,0,0,0,1),
     980                                                        array(1,1,0,0,0,0,0,0,1),
     981                                                        array(1,0,1,0,0,0,0,0,1),
     982                                                        array(1,0,1,0,0,0,0,0,1),
     983                                                        array(1,0,0,1,0,0,0,0,1),
     984                                                        array(1,0,0,1,0,0,0,0,1),
     985                                                        array(1,0,0,0,1,0,0,0,1),
     986                                                        array(1,0,0,0,1,0,0,0,1),
     987                                                        array(1,0,0,0,1,0,0,0,1),
     988                                                        array(1,0,0,0,0,1,0,0,1),
     989                                                        array(1,0,0,0,0,1,0,0,1),
     990                                                        array(1,0,0,0,0,0,1,0,1),
     991                                                        array(1,0,0,0,0,0,1,0,1),
     992                                                        array(1,0,0,0,0,0,0,1,1),
     993                                                        array(1,0,0,0,0,0,0,1,1),
     994                                                ),
     995                                                array(
     996                                                        array(0,0,0,0,0,0,0,0,0),
     997                                                        array(0,1,0,0,0,0,0,1,0),
     998                                                        array(0,1,1,0,0,0,0,1,0),
     999                                                        array(0,1,1,0,0,0,0,1,0),
     1000                                                        array(0,1,1,0,0,0,0,1,0),
     1001                                                        array(0,1,0,1,0,0,0,1,0),
     1002                                                        array(0,1,0,1,0,0,0,1,0),
     1003                                                        array(0,1,0,1,0,0,0,1,0),
     1004                                                        array(0,1,0,0,1,0,0,1,0),
     1005                                                        array(0,1,0,0,1,1,0,1,0),
     1006                                                        array(0,1,0,0,0,1,0,1,0),
     1007                                                        array(0,1,0,0,0,1,1,1,0),
     1008                                                        array(0,1,0,0,0,0,1,1,0),
     1009                                                        array(0,1,0,0,0,0,0,1,0),
     1010                                                        array(1,1,1,0,0,0,1,1,1),
     1011                                                ),
     1012                                                array(
     1013                                                        array(0,0,0,0,0,0,0,0,0),
     1014                                                        array(0,0,0,0,0,0,0,0,0),
     1015                                                        array(0,0,0,0,0,0,0,0,0),
     1016                                                        array(0,0,0,0,0,0,0,0,0),
     1017                                                        array(0,0,0,0,0,0,0,0,0),
     1018                                                        array(0,0,0,0,0,0,0,0,0),
     1019                                                        array(0,0,0,0,0,0,0,0,0),
     1020                                                        array(1,0,1,1,1,1,0,0,0),
     1021                                                        array(1,1,1,0,0,1,1,0,0),
     1022                                                        array(1,0,0,0,0,0,1,0,0),
     1023                                                        array(1,0,0,0,0,0,1,0,0),
     1024                                                        array(1,0,0,0,0,0,1,0,0),
     1025                                                        array(1,0,0,0,0,0,1,0,0),
     1026                                                        array(1,0,0,0,0,0,1,0,0),
     1027                                                        array(1,0,0,0,0,0,1,0,0),
     1028                                                ),
     1029                                        ),
     1030                'O'     =>              array(
     1031                                                array(
     1032                                                        array(0,0,1,1,1,1,1,0,0),
     1033                                                        array(0,1,0,0,0,0,0,1,0),
     1034                                                        array(1,0,0,0,0,0,0,0,1),
     1035                                                        array(1,0,0,0,0,0,0,0,1),
     1036                                                        array(1,0,0,0,0,0,0,0,1),
     1037                                                        array(1,0,0,0,0,0,0,0,1),
     1038                                                        array(1,0,0,0,0,0,0,0,1),
     1039                                                        array(1,0,0,0,0,0,0,0,1),
     1040                                                        array(1,0,0,0,0,0,0,0,1),
     1041                                                        array(1,0,0,0,0,0,0,0,1),
     1042                                                        array(1,0,0,0,0,0,0,0,1),
     1043                                                        array(1,0,0,0,0,0,0,0,1),
     1044                                                        array(1,0,0,0,0,0,0,0,1),
     1045                                                        array(0,1,0,0,0,0,0,1,0),
     1046                                                        array(0,0,1,1,1,1,1,0,0),
     1047                                                ),
     1048                                                array(
     1049                                                        array(0,0,1,1,1,1,1,0,0),
     1050                                                        array(0,1,0,0,0,0,0,1,0),
     1051                                                        array(1,1,0,0,0,0,0,1,1),
     1052                                                        array(1,1,0,0,0,0,0,1,1),
     1053                                                        array(1,1,0,0,0,0,0,1,1),
     1054                                                        array(1,1,0,0,0,0,0,1,1),
     1055                                                        array(1,1,0,0,0,0,0,1,1),
     1056                                                        array(1,1,0,0,0,0,0,1,1),
     1057                                                        array(1,1,0,0,0,0,0,1,1),
     1058                                                        array(1,1,0,0,0,0,0,1,1),
     1059                                                        array(1,1,0,0,0,0,0,1,1),
     1060                                                        array(1,1,0,0,0,0,0,1,1),
     1061                                                        array(1,1,0,0,0,0,0,1,1),
     1062                                                        array(0,1,0,0,0,0,0,1,0),
     1063                                                        array(0,0,1,1,1,1,1,0,0),
     1064                                                ),
     1065                                                array(
     1066                                                        array(0,0,0,0,0,0,0,0,0),
     1067                                                        array(0,0,0,0,0,0,0,0,0),
     1068                                                        array(0,0,0,0,0,0,0,0,0),
     1069                                                        array(0,0,0,0,0,0,0,0,0),
     1070                                                        array(0,0,0,0,0,0,0,0,0),
     1071                                                        array(0,0,0,0,0,0,0,0,0),
     1072                                                        array(0,0,0,0,0,0,0,0,0),
     1073                                                        array(0,1,1,1,1,1,0,0,0),
     1074                                                        array(1,1,1,0,0,1,1,0,0),
     1075                                                        array(1,0,0,0,0,0,1,0,0),
     1076                                                        array(1,0,0,0,0,0,1,0,0),
     1077                                                        array(1,0,0,0,0,0,1,0,0),
     1078                                                        array(1,0,0,0,0,0,1,0,0),
     1079                                                        array(1,1,0,0,0,1,1,0,0),
     1080                                                        array(0,1,1,1,1,1,0,0,0),
     1081                                                ),
     1082                                        ),
     1083                'P'     =>              array(
     1084                                                array(
     1085                                                        array(1,1,1,1,1,1,1,0,0),
     1086                                                        array(1,0,0,0,0,0,0,1,0),
     1087                                                        array(1,0,0,0,0,0,0,0,1),
     1088                                                        array(1,0,0,0,0,0,0,0,1),
     1089                                                        array(1,0,0,0,0,0,0,0,1),
     1090                                                        array(1,0,0,0,0,0,0,0,1),
     1091                                                        array(1,0,0,0,0,0,0,1,0),
     1092                                                        array(1,1,1,1,1,1,1,0,0),
     1093                                                        array(1,0,0,0,0,0,0,0,0),
     1094                                                        array(1,0,0,0,0,0,0,0,0),
     1095                                                        array(1,0,0,0,0,0,0,0,0),
     1096                                                        array(1,0,0,0,0,0,0,0,0),
     1097                                                        array(1,0,0,0,0,0,0,0,0),
     1098                                                        array(1,0,0,0,0,0,0,0,0),
     1099                                                        array(1,0,0,0,0,0,0,0,0),
     1100                                                ),
     1101                                                array(
     1102                                                        array(1,1,1,1,1,1,1,0,0),
     1103                                                        array(0,1,0,0,0,0,0,1,0),
     1104                                                        array(0,1,0,0,0,0,0,0,1),
     1105                                                        array(0,1,0,0,0,0,0,0,1),
     1106                                                        array(0,1,0,0,0,0,0,0,1),
     1107                                                        array(0,1,0,0,0,0,0,0,1),
     1108                                                        array(0,1,0,0,0,0,0,1,0),
     1109                                                        array(1,1,1,1,1,1,1,0,0),
     1110                                                        array(0,1,0,0,0,0,0,0,0),
     1111                                                        array(0,1,0,0,0,0,0,0,0),
     1112                                                        array(0,1,0,0,0,0,0,0,0),
     1113                                                        array(0,1,0,0,0,0,0,0,0),
     1114                                                        array(0,1,0,0,0,0,0,0,0),
     1115                                                        array(0,1,0,0,0,0,0,0,0),
     1116                                                        array(1,1,1,0,0,0,0,0,0),
     1117                                                ),
     1118                                                array(
     1119                                                        array(0,0,0,0,0,0,0,0,0),
     1120                                                        array(0,0,0,0,0,0,0,0,0),
     1121                                                        array(1,0,0,0,0,0,0,0,0),
     1122                                                        array(1,0,1,1,0,0,0,0,0),
     1123                                                        array(1,1,0,1,1,0,0,0,0),
     1124                                                        array(1,0,0,0,1,0,0,0,0),
     1125                                                        array(1,0,0,0,1,0,0,0,0),
     1126                                                        array(1,0,0,1,1,0,0,0,0),
     1127                                                        array(1,1,1,1,0,0,0,0,0),
     1128                                                        array(1,0,0,0,0,0,0,0,0),
     1129                                                        array(1,0,0,0,0,0,0,0,0),
     1130                                                        array(1,0,0,0,0,0,0,0,0),
     1131                                                        array(1,0,0,0,0,0,0,0,0),
     1132                                                        array(1,0,0,0,0,0,0,0,0),
     1133                                                        array(1,0,0,0,0,0,0,0,0),
     1134                                                ),
     1135                                        ),
     1136                'Q'     =>              array(
     1137                                                array(
     1138                                                        array(0,0,1,1,1,1,1,0,0),
     1139                                                        array(0,1,0,0,0,0,0,1,0),
     1140                                                        array(1,0,0,0,0,0,0,0,1),
     1141                                                        array(1,0,0,0,0,0,0,0,1),
     1142                                                        array(1,0,0,0,0,0,0,0,1),
     1143                                                        array(1,0,0,0,0,0,0,0,1),
     1144                                                        array(1,0,0,0,0,0,0,0,1),
     1145                                                        array(1,0,0,0,0,0,0,0,1),
     1146                                                        array(1,0,0,0,0,0,0,0,1),
     1147                                                        array(1,0,0,0,0,0,0,0,1),
     1148                                                        array(1,0,0,0,0,0,0,0,1),
     1149                                                        array(1,0,0,0,0,1,0,0,1),
     1150                                                        array(1,0,0,0,0,0,1,0,1),
     1151                                                        array(0,1,0,0,0,0,0,1,0),
     1152                                                        array(0,0,1,1,1,1,1,0,1),
     1153                                                ),
     1154                                                array(
     1155                                                        array(0,0,1,1,1,1,1,0,0),
     1156                                                        array(0,1,0,0,0,0,0,1,0),
     1157                                                        array(1,0,0,0,0,0,0,0,1),
     1158                                                        array(1,0,0,0,0,0,0,0,1),
     1159                                                        array(1,0,0,0,0,0,0,0,1),
     1160                                                        array(1,0,0,0,0,0,0,0,1),
     1161                                                        array(1,0,0,0,0,0,0,0,1),
     1162                                                        array(1,0,0,0,0,0,0,0,1),
     1163                                                        array(1,0,0,0,0,0,0,0,1),
     1164                                                        array(1,0,0,0,1,0,0,0,1),
     1165                                                        array(1,1,0,0,1,1,0,1,1),
     1166                                                        array(0,1,1,1,1,1,1,1,0),
     1167                                                        array(0,0,0,0,0,0,1,1,0),
     1168                                                        array(0,0,0,0,0,0,0,1,1),
     1169                                                        array(0,0,0,0,0,0,0,0,1),
     1170                                                ),
     1171                                                array(
     1172                                                        array(0,0,0,0,0,0,0,0,0),
     1173                                                        array(0,0,0,0,0,0,0,0,0),
     1174                                                        array(0,0,0,0,0,0,0,0,0),
     1175                                                        array(0,0,0,0,0,1,1,1,1),
     1176                                                        array(0,0,0,0,1,1,0,0,1),
     1177                                                        array(0,0,0,0,1,0,0,0,1),
     1178                                                        array(0,0,0,0,1,0,0,0,1),
     1179                                                        array(0,0,0,0,1,1,0,1,1),
     1180                                                        array(0,0,0,0,0,1,1,0,1),
     1181                                                        array(0,0,0,0,0,0,0,0,1),
     1182                                                        array(0,0,0,0,0,0,0,0,1),
     1183                                                        array(0,0,0,0,0,0,0,0,1),
     1184                                                        array(0,0,0,0,0,0,0,0,1),
     1185                                                        array(0,0,0,0,0,0,0,0,1),
     1186                                                        array(0,0,0,0,0,0,0,0,1),
     1187                                                ),
     1188                                        ),
     1189                'R'     =>              array(
     1190                                                array(
     1191                                                        array(1,1,1,1,1,1,1,0,0),
     1192                                                        array(1,0,0,0,0,0,0,1,0),
     1193                                                        array(1,0,0,0,0,0,0,0,1),
     1194                                                        array(1,0,0,0,0,0,0,0,1),
     1195                                                        array(1,0,0,0,0,0,0,0,1),
     1196                                                        array(1,0,0,0,0,0,0,0,1),
     1197                                                        array(1,0,0,0,0,0,0,1,0),
     1198                                                        array(1,1,1,1,1,1,1,0,0),
     1199                                                        array(1,1,1,0,0,0,0,0,0),
     1200                                                        array(1,0,0,1,0,0,0,0,0),
     1201                                                        array(1,0,0,0,1,0,0,0,0),
     1202                                                        array(1,0,0,0,0,1,0,0,0),
     1203                                                        array(1,0,0,0,0,0,1,0,0),
     1204                                                        array(1,0,0,0,0,0,0,1,0),
     1205                                                        array(1,0,0,0,0,0,0,0,1),
     1206                                                ),
     1207                                                array(
     1208                                                        array(1,1,1,1,1,1,1,0,0),
     1209                                                        array(0,1,0,0,0,0,0,1,0),
     1210                                                        array(0,1,0,0,0,0,0,0,1),
     1211                                                        array(0,1,0,0,0,0,0,0,1),
     1212                                                        array(0,1,0,0,0,0,0,0,1),
     1213                                                        array(0,1,0,0,0,0,0,0,1),
     1214                                                        array(0,1,0,0,0,0,0,1,0),
     1215                                                        array(1,1,1,1,1,1,1,0,0),
     1216                                                        array(0,1,1,0,0,0,0,0,0),
     1217                                                        array(0,1,1,1,0,0,0,0,0),
     1218                                                        array(0,1,0,1,1,0,0,0,0),
     1219                                                        array(0,1,0,0,1,1,0,0,0),
     1220                                                        array(0,1,0,0,0,1,1,0,0),
     1221                                                        array(0,1,0,0,0,0,1,1,0),
     1222                                                        array(1,1,1,0,0,0,1,1,1),
     1223                                                ),
     1224                                                array(
     1225                                                        array(0,0,0,0,0,0,0,0,0),
     1226                                                        array(0,0,0,0,0,0,0,0,0),
     1227                                                        array(0,0,0,0,0,0,0,0,0),
     1228                                                        array(0,0,0,0,0,0,0,0,0),
     1229                                                        array(0,0,0,0,0,0,0,0,0),
     1230                                                        array(0,0,0,0,0,0,0,0,0),
     1231                                                        array(1,0,0,0,0,0,0,0,0),
     1232                                                        array(1,1,1,1,1,0,0,0,0),
     1233                                                        array(1,1,0,0,1,1,0,0,0),
     1234                                                        array(1,0,0,0,0,0,0,0,0),
     1235                                                        array(1,0,0,0,0,0,0,0,0),
     1236                                                        array(1,0,0,0,0,0,0,0,0),
     1237                                                        array(1,0,0,0,0,0,0,0,0),
     1238                                                        array(1,0,0,0,0,0,0,0,0),
     1239                                                        array(1,0,0,0,0,0,0,0,0),
     1240                                                ),
     1241                                        ),
     1242                'S'     =>              array(
     1243                                                array(
     1244                                                        array(0,0,1,1,1,1,1,0,0),
     1245                                                        array(0,1,0,0,0,0,0,1,0),
     1246                                                        array(1,0,0,0,0,0,0,0,1),
     1247                                                        array(1,0,0,0,0,0,0,0,0),
     1248                                                        array(1,0,0,0,0,0,0,0,0),
     1249                                                        array(1,0,0,0,0,0,0,0,0),
     1250                                                        array(0,1,0,0,0,0,0,0,0),
     1251                                                        array(0,0,1,1,1,1,1,0,0),
     1252                                                        array(0,0,0,0,0,0,0,1,0),
     1253                                                        array(0,0,0,0,0,0,0,0,1),
     1254                                                        array(0,0,0,0,0,0,0,0,1),
     1255                                                        array(0,0,0,0,0,0,0,0,1),
     1256                                                        array(1,0,0,0,0,0,0,0,1),
     1257                                                        array(0,1,0,0,0,0,0,1,0),
     1258                                                        array(0,0,1,1,1,1,1,0,0),
     1259                                                ),
     1260                                                array(
     1261                                                        array(0,0,1,1,1,1,1,0,1),
     1262                                                        array(0,1,0,0,0,0,0,1,1),
     1263                                                        array(1,0,0,0,0,0,0,0,1),
     1264                                                        array(1,0,0,0,0,0,0,0,1),
     1265                                                        array(1,0,0,0,0,0,0,0,0),
     1266                                                        array(1,0,0,0,0,0,0,0,0),
     1267                                                        array(0,1,0,0,0,0,0,0,0),
     1268                                                        array(0,0,1,1,1,1,1,0,0),
     1269                                                        array(0,0,0,0,0,0,0,1,0),
     1270                                                        array(0,0,0,0,0,0,0,0,1),
     1271                                                        array(1,0,0,0,0,0,0,0,1),
     1272                                                        array(1,0,0,0,0,0,0,0,1),
     1273                                                        array(1,0,0,0,0,0,0,0,1),
     1274                                                        array(1,1,0,0,0,0,0,1,0),
     1275                                                        array(1,0,1,1,1,1,1,0,0),
     1276                                                ),
     1277                                                array(
     1278                                                        array(0,0,0,0,0,0,0,0,0),
     1279                                                        array(0,0,0,0,0,0,0,0,0),
     1280                                                        array(0,0,0,0,0,0,0,0,0),
     1281                                                        array(0,0,0,0,0,0,0,0,0),
     1282                                                        array(0,0,0,0,0,0,0,0,0),
     1283                                                        array(0,0,0,0,0,0,0,0,0),
     1284                                                        array(0,0,0,0,0,0,0,0,0),
     1285                                                        array(0,1,1,1,1,0,0,0,0),
     1286                                                        array(1,0,0,0,0,1,0,0,0),
     1287                                                        array(1,0,0,0,0,0,0,0,0),
     1288                                                        array(1,1,0,0,0,0,0,0,0),
     1289                                                        array(0,1,1,1,1,0,0,0,0),
     1290                                                        array(0,0,0,0,0,1,0,0,0),
     1291                                                        array(1,0,0,0,1,1,0,0,0),
     1292                                                        array(0,1,1,1,1,0,0,0,0),
     1293                                                ),
     1294                                        ),
     1295                'T'     =>              array(
     1296                                                array(
     1297                                                        array(1,1,1,1,1,1,1,1,1),
     1298                                                        array(0,0,0,0,1,0,0,0,0),
     1299                                                        array(0,0,0,0,1,0,0,0,0),
     1300                                                        array(0,0,0,0,1,0,0,0,0),
     1301                                                        array(0,0,0,0,1,0,0,0,0),
     1302                                                        array(0,0,0,0,1,0,0,0,0),
     1303                                                        array(0,0,0,0,1,0,0,0,0),
     1304                                                        array(0,0,0,0,1,0,0,0,0),
     1305                                                        array(0,0,0,0,1,0,0,0,0),
     1306                                                        array(0,0,0,0,1,0,0,0,0),
     1307                                                        array(0,0,0,0,1,0,0,0,0),
     1308                                                        array(0,0,0,0,1,0,0,0,0),
     1309                                                        array(0,0,0,0,1,0,0,0,0),
     1310                                                        array(0,0,0,0,1,0,0,0,0),
     1311                                                        array(0,0,0,0,1,0,0,0,0),
     1312                                                ),
     1313                                                array(
     1314                                                        array(1,1,1,1,1,1,1,1,1),
     1315                                                        array(1,0,0,0,1,0,0,0,1),
     1316                                                        array(0,0,0,0,1,0,0,0,0),
     1317                                                        array(0,0,0,0,1,0,0,0,0),
     1318                                                        array(0,0,0,0,1,0,0,0,0),
     1319                                                        array(0,0,0,0,1,0,0,0,0),
     1320                                                        array(0,0,0,0,1,0,0,0,0),
     1321                                                        array(0,0,0,0,1,0,0,0,0),
     1322                                                        array(0,0,0,0,1,0,0,0,0),
     1323                                                        array(0,0,0,0,1,0,0,0,0),
     1324                                                        array(0,0,0,0,1,0,0,0,0),
     1325                                                        array(0,0,0,0,1,0,0,0,0),
     1326                                                        array(0,0,0,0,1,0,0,0,0),
     1327                                                        array(0,0,0,0,1,0,0,0,0),
     1328                                                        array(0,0,0,1,1,1,0,0,0),
     1329                                                ),
     1330                                                array(
     1331                                                        array(0,0,0,0,1,0,0,0,0),
     1332                                                        array(0,0,0,0,1,0,0,0,0),
     1333                                                        array(0,0,0,0,1,0,0,0,0),
     1334                                                        array(0,0,1,1,1,1,1,1,0),
     1335                                                        array(0,0,0,0,1,0,0,0,0),
     1336                                                        array(0,0,0,0,1,0,0,0,0),
     1337                                                        array(0,0,0,0,1,0,0,0,0),
     1338                                                        array(0,0,0,0,1,0,0,0,0),
     1339                                                        array(0,0,0,0,1,0,0,0,0),
     1340                                                        array(0,0,0,0,1,0,0,0,0),
     1341                                                        array(0,0,0,0,1,0,0,0,0),
     1342                                                        array(0,0,0,0,1,0,0,0,0),
     1343                                                        array(0,0,0,0,1,0,0,0,0),
     1344                                                        array(0,0,0,0,1,1,0,0,0),
     1345                                                        array(0,0,0,0,0,1,1,1,0),
     1346                                                ),
     1347                                        ),
     1348                'U'     =>              array(
     1349                                                array(
     1350                                                        array(1,0,0,0,0,0,0,0,1),
     1351                                                        array(1,0,0,0,0,0,0,0,1),
     1352                                                        array(1,0,0,0,0,0,0,0,1),
     1353                                                        array(1,0,0,0,0,0,0,0,1),
     1354                                                        array(1,0,0,0,0,0,0,0,1),
     1355                                                        array(1,0,0,0,0,0,0,0,1),
     1356                                                        array(1,0,0,0,0,0,0,0,1),
     1357                                                        array(1,0,0,0,0,0,0,0,1),
     1358                                                        array(1,0,0,0,0,0,0,0,1),
     1359                                                        array(1,0,0,0,0,0,0,0,1),
     1360                                                        array(1,0,0,0,0,0,0,0,1),
     1361                                                        array(1,0,0,0,0,0,0,0,1),
     1362                                                        array(1,0,0,0,0,0,0,0,1),
     1363                                                        array(0,1,0,0,0,0,0,1,0),
     1364                                                        array(0,0,1,1,1,1,1,0,0),
     1365                                                ),
     1366                                                array(
     1367                                                        array(1,0,0,0,0,0,0,0,0),
     1368                                                        array(1,1,1,0,0,0,1,1,1),
     1369                                                        array(0,1,0,0,0,0,0,1,0),
     1370                                                        array(0,1,0,0,0,0,0,1,0),
     1371                                                        array(0,1,0,0,0,0,0,1,0),
     1372                                                        array(0,1,0,0,0,0,0,1,0),
     1373                                                        array(0,1,0,0,0,0,0,1,0),
     1374                                                        array(0,1,0,0,0,0,0,1,0),
     1375                                                        array(0,1,0,0,0,0,0,1,0),
     1376                                                        array(0,1,0,0,0,0,0,1,0),
     1377                                                        array(0,1,0,0,0,0,0,1,0),
     1378                                                        array(0,1,0,0,0,0,0,1,0),
     1379                                                        array(0,1,0,0,0,0,0,1,0),
     1380                                                        array(0,1,1,0,0,0,1,1,0),
     1381                                                        array(0,0,1,1,1,1,1,0,0),
     1382                                                ),
     1383                                                array(
     1384                                                        array(0,0,0,0,0,0,0,0,0),
     1385                                                        array(0,0,0,0,0,0,0,0,0),
     1386                                                        array(0,0,0,0,0,0,0,0,0),
     1387                                                        array(0,0,0,0,0,0,0,0,0),
     1388                                                        array(0,0,0,0,0,0,0,0,0),
     1389                                                        array(0,0,0,0,0,0,0,0,0),
     1390                                                        array(0,0,0,0,0,0,0,0,0),
     1391                                                        array(0,0,1,0,0,0,0,0,1),
     1392                                                        array(0,0,1,0,0,0,0,0,1),
     1393                                                        array(0,0,1,0,0,0,0,0,1),
     1394                                                        array(0,0,1,0,0,0,0,0,1),
     1395                                                        array(0,0,1,0,0,0,0,0,1),
     1396                                                        array(0,0,1,0,0,0,0,1,1),
     1397                                                        array(0,0,1,1,0,0,1,1,1),
     1398                                                        array(0,0,0,1,1,1,1,0,1),
     1399                                                ),
     1400                                        ),
     1401                'V'     =>              array(
     1402                                                array(
     1403                                                        array(1,0,0,0,0,0,0,0,1),
     1404                                                        array(1,0,0,0,0,0,0,0,1),
     1405                                                        array(1,0,0,0,0,0,0,0,1),
     1406                                                        array(0,1,0,0,0,0,0,1,0),
     1407                                                        array(0,1,0,0,0,0,0,1,0),
     1408                                                        array(0,1,0,0,0,0,0,1,0),
     1409                                                        array(0,0,1,0,0,0,1,0,0),
     1410                                                        array(0,0,1,0,0,0,1,0,0),
     1411                                                        array(0,0,1,0,0,0,1,0,0),
     1412                                                        array(0,0,1,0,0,0,1,0,0),
     1413                                                        array(0,0,0,1,0,1,0,0,0),
     1414                                                        array(0,0,0,1,0,1,0,0,0),
     1415                                                        array(0,0,0,1,0,1,0,0,0),
     1416                                                        array(0,0,0,0,1,0,0,0,0),
     1417                                                        array(0,0,0,0,1,0,0,0,0),
     1418                                                ),
     1419                                                array(
     1420                                                        array(0,0,0,0,0,0,0,0,0),
     1421                                                        array(0,0,0,0,0,0,0,0,0),
     1422                                                        array(0,0,0,0,0,0,0,0,0),
     1423                                                        array(1,1,1,0,0,0,1,1,1),
     1424                                                        array(0,1,0,0,0,0,0,1,0),
     1425                                                        array(0,1,0,0,0,0,0,1,0),
     1426                                                        array(0,0,1,0,0,0,1,0,0),
     1427                                                        array(0,0,1,0,0,0,1,0,0),
     1428                                                        array(0,0,1,0,0,0,1,0,0),
     1429                                                        array(0,0,1,0,0,0,1,0,0),
     1430                                                        array(0,0,0,1,0,1,0,0,0),
     1431                                                        array(0,0,0,1,0,1,0,0,0),
     1432                                                        array(0,0,0,1,0,1,0,0,0),
     1433                                                        array(0,0,0,0,1,0,0,0,0),
     1434                                                        array(0,0,0,0,1,0,0,0,0),
     1435                                                ),
     1436                                                array(
     1437                                                        array(0,0,0,0,0,0,0,0,0),
     1438                                                        array(0,0,0,0,0,0,0,0,0),
     1439                                                        array(0,0,0,0,0,0,0,0,0),
     1440                                                        array(0,0,0,0,0,0,0,0,0),
     1441                                                        array(0,0,0,0,0,0,0,0,0),
     1442                                                        array(0,0,0,0,0,0,0,0,0),
     1443                                                        array(0,0,1,0,0,0,1,0,0),
     1444                                                        array(0,0,1,0,0,0,1,0,0),
     1445                                                        array(0,0,1,0,0,0,1,0,0),
     1446                                                        array(0,0,1,0,0,0,1,0,0),
     1447                                                        array(0,0,0,1,0,1,0,0,0),
     1448                                                        array(0,0,0,1,0,1,0,0,0),
     1449                                                        array(0,0,0,1,0,1,0,0,0),
     1450                                                        array(0,0,0,0,1,0,0,0,0),
     1451                                                        array(0,0,0,0,1,0,0,0,0),
     1452                                                ),
     1453                                        ),
     1454                'W'     =>              array(
     1455                                                array(
     1456                                                        array(1,0,0,0,0,0,0,0,1),
     1457                                                        array(1,0,0,0,0,0,0,0,1),
     1458                                                        array(1,0,0,0,0,0,0,0,1),
     1459                                                        array(1,0,0,0,0,0,0,0,1),
     1460                                                        array(1,0,0,0,0,0,0,0,1),
     1461                                                        array(1,0,0,0,1,0,0,0,1),
     1462                                                        array(1,0,0,0,1,0,0,0,1),
     1463                                                        array(1,0,0,1,0,1,0,0,1),
     1464                                                        array(1,0,0,1,0,1,0,0,1),
     1465                                                        array(1,0,0,1,0,1,0,0,1),
     1466                                                        array(1,0,1,0,0,0,1,0,1),
     1467                                                        array(1,0,1,0,0,0,1,0,1),
     1468                                                        array(1,0,1,0,0,0,1,0,1),
     1469                                                        array(1,1,0,0,0,0,0,1,1),
     1470                                                        array(1,1,0,0,0,0,0,1,1),
     1471                                                ),
     1472                                                array(
     1473                                                        array(0,0,0,0,0,0,0,0,0),
     1474                                                        array(0,0,0,0,0,0,0,0,0),
     1475                                                        array(1,1,1,0,0,0,1,1,1),
     1476                                                        array(0,1,0,0,0,0,0,1,0),
     1477                                                        array(0,1,0,0,0,0,0,1,0),
     1478                                                        array(0,1,0,0,0,0,0,1,0),
     1479                                                        array(0,1,0,0,0,0,0,1,0),
     1480                                                        array(0,1,0,0,1,0,0,1,0),
     1481                                                        array(0,1,0,0,1,0,0,1,0),
     1482                                                        array(0,1,0,1,1,1,0,1,0),
     1483                                                        array(0,1,0,1,0,1,0,1,0),
     1484                                                        array(0,1,1,1,0,1,1,1,0),
     1485                                                        array(0,1,1,0,0,0,1,1,0),
     1486                                                        array(0,1,0,0,0,0,0,1,0),
     1487                                                        array(0,0,0,0,0,0,0,0,0),
     1488                                                ),
     1489                                                array(
     1490                                                        array(0,0,0,0,0,0,0,0,0),
     1491                                                        array(0,0,0,0,0,0,0,0,0),
     1492                                                        array(0,0,0,0,0,0,0,0,0),
     1493                                                        array(0,0,0,0,0,0,0,0,0),
     1494                                                        array(0,0,0,0,0,0,0,0,0),
     1495                                                        array(0,0,0,0,0,0,0,0,0),
     1496                                                        array(0,1,0,0,0,0,0,1,0),
     1497                                                        array(0,1,0,0,1,0,0,1,0),
     1498                                                        array(0,1,0,0,1,0,0,1,0),
     1499                                                        array(0,1,0,1,1,1,0,1,0),
     1500                                                        array(0,1,0,1,0,1,0,1,0),
     1501                                                        array(0,1,1,1,0,1,1,1,0),
     1502                                                        array(0,1,1,0,0,0,1,1,0),
     1503                                                        array(0,1,0,0,0,0,0,1,0),
     1504                                                        array(0,0,0,0,0,0,0,0,0),
     1505                                                ),
     1506                                        ),
     1507                'X'     =>              array(
     1508                                                array(
     1509                                                        array(1,0,0,0,0,0,0,0,1),
     1510                                                        array(1,0,0,0,0,0,0,0,1),
     1511                                                        array(0,1,0,0,0,0,0,1,0),
     1512                                                        array(0,1,0,0,0,0,0,1,0),
     1513                                                        array(0,0,1,0,0,0,1,0,0),
     1514                                                        array(0,0,0,1,0,1,0,0,0),
     1515                                                        array(0,0,0,1,0,1,0,0,0),
     1516                                                        array(0,0,0,0,1,0,0,0,0),
     1517                                                        array(0,0,0,1,0,1,0,0,0),
     1518                                                        array(0,0,0,1,0,1,0,0,0),
     1519                                                        array(0,0,1,0,0,0,1,0,0),
     1520                                                        array(0,1,0,0,0,0,1,0,0),
     1521                                                        array(0,1,0,0,0,0,0,1,0),
     1522                                                        array(1,0,0,0,0,0,0,0,1),
     1523                                                        array(1,0,0,0,0,0,0,0,1),
     1524                                                ),
     1525                                                array(
     1526                                                        array(0,0,0,0,0,0,0,0,0),
     1527                                                        array(1,1,1,0,0,0,1,1,1),
     1528                                                        array(0,1,0,0,0,0,0,1,0),
     1529                                                        array(0,1,0,0,0,0,0,1,0),
     1530                                                        array(0,0,1,0,0,0,1,0,0),
     1531                                                        array(0,0,0,1,0,1,0,0,0),
     1532                                                        array(0,0,0,1,0,1,0,0,0),
     1533                                                        array(0,0,0,0,1,0,0,0,0),
     1534                                                        array(0,0,0,1,0,1,0,0,0),
     1535                                                        array(0,0,0,1,0,1,0,0,0),
     1536                                                        array(0,0,1,0,0,0,1,0,0),
     1537                                                        array(0,1,0,0,0,0,1,0,0),
     1538                                                        array(0,1,0,0,0,0,0,1,0),
     1539                                                        array(1,1,1,0,0,0,1,1,1),
     1540                                                        array(0,0,0,0,0,0,0,0,0),
     1541                                                ),
     1542                                                array(
     1543                                                        array(0,0,0,0,0,0,0,0,0),
     1544                                                        array(0,0,0,0,0,0,0,0,0),
     1545                                                        array(0,0,0,0,0,0,0,0,0),
     1546                                                        array(0,0,0,0,0,0,0,0,0),
     1547                                                        array(0,0,0,0,0,0,0,0,0),
     1548                                                        array(0,0,0,0,0,0,0,0,0),
     1549                                                        array(0,0,0,0,0,0,0,0,0),
     1550                                                        array(0,1,0,0,0,0,0,1,0),
     1551                                                        array(0,1,1,0,0,0,1,1,0),
     1552                                                        array(0,0,1,1,0,1,1,0,0),
     1553                                                        array(0,0,0,1,1,1,0,0,0),
     1554                                                        array(0,0,0,1,1,1,0,0,0),
     1555                                                        array(0,0,1,1,0,1,1,0,0),
     1556                                                        array(0,1,1,0,0,0,1,1,0),
     1557                                                        array(0,0,0,0,0,0,0,0,0),
     1558                                                ),
     1559                                        ),
     1560                'Y'     =>              array(
     1561                                                array(
     1562                                                        array(1,0,0,0,0,0,0,0,1),
     1563                                                        array(1,0,0,0,0,0,0,0,1),
     1564                                                        array(0,1,0,0,0,0,0,1,0),
     1565                                                        array(0,1,0,0,0,0,0,1,0),
     1566                                                        array(0,0,1,0,0,0,1,0,0),
     1567                                                        array(0,0,1,0,0,0,1,0,0),
     1568                                                        array(0,0,0,1,0,1,0,0,0),
     1569                                                        array(0,0,0,0,1,0,0,0,0),
     1570                                                        array(0,0,0,0,1,0,0,0,0),
     1571                                                        array(0,0,0,0,1,0,0,0,0),
     1572                                                        array(0,0,0,0,1,0,0,0,0),
     1573                                                        array(0,0,0,0,1,0,0,0,0),
     1574                                                        array(0,0,0,0,1,0,0,0,0),
     1575                                                        array(0,0,0,0,1,0,0,0,0),
     1576                                                        array(0,0,0,0,1,0,0,0,0),
     1577                                                ),
     1578                                                array(
     1579                                                        array(0,0,0,0,0,0,0,0,0),
     1580                                                        array(1,1,1,0,0,0,1,1,1),
     1581                                                        array(0,1,0,0,0,0,0,1,0),
     1582                                                        array(0,1,0,0,0,0,0,1,0),
     1583                                                        array(0,0,1,0,0,0,1,0,0),
     1584                                                        array(0,0,1,0,0,0,1,0,0),
     1585                                                        array(0,0,0,1,0,1,0,0,0),
     1586                                                        array(0,0,0,0,1,0,0,0,0),
     1587                                                        array(0,0,0,0,1,0,0,0,0),
     1588                                                        array(0,0,0,0,1,0,0,0,0),
     1589                                                        array(0,0,0,0,1,0,0,0,0),
     1590                                                        array(0,0,0,0,1,0,0,0,0),
     1591                                                        array(0,0,0,0,1,0,0,0,0),
     1592                                                        array(0,0,0,0,1,0,0,0,0),
     1593                                                        array(0,0,0,1,1,1,0,0,0),
     1594                                                ),
     1595                                                array(
     1596                                                        array(0,0,0,0,0,0,0,0,0),
     1597                                                        array(0,0,0,0,0,0,0,0,0),
     1598                                                        array(0,0,0,0,0,0,0,0,0),
     1599                                                        array(0,0,0,0,0,0,0,0,0),
     1600                                                        array(0,0,0,1,0,0,0,0,1),
     1601                                                        array(0,0,0,1,1,0,0,0,1),
     1602                                                        array(0,0,0,0,1,0,0,1,1),
     1603                                                        array(0,0,0,0,1,1,0,1,0),
     1604                                                        array(0,0,0,0,0,1,1,1,0),
     1605                                                        array(0,0,0,0,0,0,1,0,0),
     1606                                                        array(0,0,0,0,0,1,1,0,0),
     1607                                                        array(0,0,0,0,0,1,0,0,0),
     1608                                                        array(0,0,0,0,1,1,0,0,0),
     1609                                                        array(0,0,1,1,1,0,0,0,0),
     1610                                                        array(0,0,0,0,0,0,0,0,0),
     1611                                                ),
     1612                                        ),
     1613                'Z'     =>              array(
     1614                                                array(
     1615                                                        array(1,1,1,1,1,1,1,1,1),
     1616                                                        array(1,0,0,0,0,0,0,0,1),
     1617                                                        array(0,0,0,0,0,0,0,0,1),
     1618                                                        array(0,0,0,0,0,0,0,1,0),
     1619                                                        array(0,0,0,0,0,0,1,0,0),
     1620                                                        array(0,0,0,0,0,1,0,0,0),
     1621                                                        array(0,0,0,0,0,1,0,0,0),
     1622                                                        array(0,0,0,0,1,0,0,0,0),
     1623                                                        array(0,0,0,1,0,0,0,0,0),
     1624                                                        array(0,0,0,1,0,0,0,0,0),
     1625                                                        array(0,0,1,0,0,0,0,0,0),
     1626                                                        array(0,1,0,0,0,0,0,0,0),
     1627                                                        array(1,0,0,0,0,0,0,0,0),
     1628                                                        array(1,0,0,0,0,0,0,0,1),
     1629                                                        array(1,1,1,1,1,1,1,1,1),
     1630                                                ),
     1631                                                array(
     1632                                                        array(1,1,1,1,1,1,1,1,1),
     1633                                                        array(0,0,0,0,0,0,0,0,1),
     1634                                                        array(0,0,0,0,0,0,0,0,1),
     1635                                                        array(0,0,0,0,0,0,0,1,0),
     1636                                                        array(0,0,0,0,0,0,1,0,0),
     1637                                                        array(0,0,0,0,0,1,0,0,0),
     1638                                                        array(0,0,0,0,0,1,0,0,0),
     1639                                                        array(0,0,1,1,1,1,1,0,0),
     1640                                                        array(0,0,0,1,0,0,0,0,0),
     1641                                                        array(0,0,0,1,0,0,0,0,0),
     1642                                                        array(0,0,1,0,0,0,0,0,0),
     1643                                                        array(0,1,0,0,0,0,0,0,0),
     1644                                                        array(1,0,0,0,0,0,0,0,0),
     1645                                                        array(1,0,0,0,0,0,0,0,0),
     1646                                                        array(1,1,1,1,1,1,1,1,1),
     1647                                                ),
     1648                                                array(
     1649                                                        array(0,0,0,0,0,0,0,0,0),
     1650                                                        array(0,0,0,0,0,0,0,0,0),
     1651                                                        array(0,0,0,0,0,0,0,0,0),
     1652                                                        array(0,0,0,0,0,0,0,0,0),
     1653                                                        array(0,0,0,0,0,0,0,0,0),
     1654                                                        array(0,0,0,0,0,0,0,0,0),
     1655                                                        array(0,0,0,0,0,0,0,0,0),
     1656                                                        array(0,0,0,0,0,0,0,0,0),
     1657                                                        array(0,1,1,1,1,1,1,1,0),
     1658                                                        array(0,0,0,0,0,1,1,0,0),
     1659                                                        array(0,0,0,0,1,1,0,0,0),
     1660                                                        array(0,0,0,1,1,0,0,0,0),
     1661                                                        array(0,0,1,1,0,0,0,0,0),
     1662                                                        array(0,0,1,0,0,0,0,0,0),
     1663                                                        array(0,1,1,1,1,1,1,1,0),
     1664                                                ),
     1665                                        ),
     1666                                );
    1791667                return array(
    1801668                        'width'         => 9,
     
    1821670                        'data'          => array(
    1831671
    184                         'A' => array(
    185                                 array(0,0,0,0,1,0,0,0,0),
    186                                 array(0,0,0,1,0,1,0,0,0),
    187                                 array(0,0,0,1,0,1,0,0,0),
    188                                 array(0,0,0,1,0,1,0,0,0),
    189                                 array(0,0,1,0,0,0,1,0,0),
    190                                 array(0,0,1,0,0,0,1,0,0),
    191                                 array(0,0,1,0,0,0,1,0,0),
    192                                 array(0,1,0,0,0,0,0,1,0),
    193                                 array(0,1,0,0,0,0,0,1,0),
    194                                 array(0,1,1,1,1,1,1,1,0),
    195                                 array(0,1,0,0,0,0,0,1,0),
    196                                 array(1,0,0,0,0,0,0,0,1),
    197                                 array(1,0,0,0,0,0,0,0,1),
    198                                 array(1,0,0,0,0,0,0,0,1),
    199                                 array(1,0,0,0,0,0,0,0,1),
    200                         ),
    201                         'B' => array(
    202                                 array(1,1,1,1,1,1,1,0,0),
    203                                 array(1,0,0,0,0,0,0,1,0),
    204                                 array(1,0,0,0,0,0,0,0,1),
    205                                 array(1,0,0,0,0,0,0,0,1),
    206                                 array(1,0,0,0,0,0,0,0,1),
    207                                 array(1,0,0,0,0,0,0,0,1),
    208                                 array(1,0,0,0,0,0,0,1,0),
    209                                 array(1,1,1,1,1,1,1,0,0),
    210                                 array(1,0,0,0,0,0,0,1,0),
    211                                 array(1,0,0,0,0,0,0,0,1),
    212                                 array(1,0,0,0,0,0,0,0,1),
    213                                 array(1,0,0,0,0,0,0,0,1),
    214                                 array(1,0,0,0,0,0,0,0,1),
    215                                 array(1,0,0,0,0,0,0,1,0),
    216                                 array(1,1,1,1,1,1,1,0,0),
    217                         ),
    218                         'C' => array(
    219                                 array(0,0,1,1,1,1,1,0,0),
    220                                 array(0,1,0,0,0,0,0,1,0),
    221                                 array(1,0,0,0,0,0,0,0,1),
    222                                 array(1,0,0,0,0,0,0,0,1),
    223                                 array(1,0,0,0,0,0,0,0,0),
    224                                 array(1,0,0,0,0,0,0,0,0),
    225                                 array(1,0,0,0,0,0,0,0,0),
    226                                 array(1,0,0,0,0,0,0,0,0),
    227                                 array(1,0,0,0,0,0,0,0,0),
    228                                 array(1,0,0,0,0,0,0,0,0),
    229                                 array(1,0,0,0,0,0,0,0,0),
    230                                 array(1,0,0,0,0,0,0,0,1),
    231                                 array(1,0,0,0,0,0,0,0,1),
    232                                 array(0,1,0,0,0,0,0,1,0),
    233                                 array(0,0,1,1,1,1,1,0,0),
    234                         ),
    235                         'D' => array(
    236                                 array(1,1,1,1,1,1,1,0,0),
    237                                 array(1,0,0,0,0,0,0,1,0),
    238                                 array(1,0,0,0,0,0,0,0,1),
    239                                 array(1,0,0,0,0,0,0,0,1),
    240                                 array(1,0,0,0,0,0,0,0,1),
    241                                 array(1,0,0,0,0,0,0,0,1),
    242                                 array(1,0,0,0,0,0,0,0,1),
    243                                 array(1,0,0,0,0,0,0,0,1),
    244                                 array(1,0,0,0,0,0,0,0,1),
    245                                 array(1,0,0,0,0,0,0,0,1),
    246                                 array(1,0,0,0,0,0,0,0,1),
    247                                 array(1,0,0,0,0,0,0,0,1),
    248                                 array(1,0,0,0,0,0,0,0,1),
    249                                 array(1,0,0,0,0,0,0,1,0),
    250                                 array(1,1,1,1,1,1,1,0,0),
    251                         ),
    252                         'E' => array(
    253                                 array(1,1,1,1,1,1,1,1,1),
    254                                 array(1,0,0,0,0,0,0,0,0),
    255                                 array(1,0,0,0,0,0,0,0,0),
    256                                 array(1,0,0,0,0,0,0,0,0),
    257                                 array(1,0,0,0,0,0,0,0,0),
    258                                 array(1,0,0,0,0,0,0,0,0),
    259                                 array(1,0,0,0,0,0,0,0,0),
    260                                 array(1,1,1,1,1,1,1,1,0),
    261                                 array(1,0,0,0,0,0,0,0,0),
    262                                 array(1,0,0,0,0,0,0,0,0),
    263                                 array(1,0,0,0,0,0,0,0,0),
    264                                 array(1,0,0,0,0,0,0,0,0),
    265                                 array(1,0,0,0,0,0,0,0,0),
    266                                 array(1,0,0,0,0,0,0,0,0),
    267                                 array(1,1,1,1,1,1,1,1,1),
    268                         ),
    269                         'F' => array(
    270                                 array(1,1,1,1,1,1,1,1,1),
    271                                 array(1,0,0,0,0,0,0,0,0),
    272                                 array(1,0,0,0,0,0,0,0,0),
    273                                 array(1,0,0,0,0,0,0,0,0),
    274                                 array(1,0,0,0,0,0,0,0,0),
    275                                 array(1,0,0,0,0,0,0,0,0),
    276                                 array(1,0,0,0,0,0,0,0,0),
    277                                 array(1,1,1,1,1,1,1,0,0),
    278                                 array(1,0,0,0,0,0,0,0,0),
    279                                 array(1,0,0,0,0,0,0,0,0),
    280                                 array(1,0,0,0,0,0,0,0,0),
    281                                 array(1,0,0,0,0,0,0,0,0),
    282                                 array(1,0,0,0,0,0,0,0,0),
    283                                 array(1,0,0,0,0,0,0,0,0),
    284                                 array(1,0,0,0,0,0,0,0,0),
    285                         ),
    286                         'G' => array(
    287                                 array(0,0,1,1,1,1,1,0,0),
    288                                 array(0,1,0,0,0,0,0,1,0),
    289                                 array(1,0,0,0,0,0,0,0,1),
    290                                 array(1,0,0,0,0,0,0,0,0),
    291                                 array(1,0,0,0,0,0,0,0,0),
    292                                 array(1,0,0,0,0,0,0,0,0),
    293                                 array(1,0,0,0,0,0,0,0,0),
    294                                 array(1,0,0,0,0,0,0,0,0),
    295                                 array(1,0,0,0,0,0,1,1,1),
    296                                 array(1,0,0,0,0,0,0,0,1),
    297                                 array(1,0,0,0,0,0,0,0,1),
    298                                 array(1,0,0,0,0,0,0,0,1),
    299                                 array(1,0,0,0,0,0,0,0,1),
    300                                 array(0,1,0,0,0,0,0,1,0),
    301                                 array(0,0,1,1,1,1,1,0,0),
    302                         ),
    303                         'H' => array(
    304                                 array(1,0,0,0,0,0,0,0,1),
    305                                 array(1,0,0,0,0,0,0,0,1),
    306                                 array(1,0,0,0,0,0,0,0,1),
    307                                 array(1,0,0,0,0,0,0,0,1),
    308                                 array(1,0,0,0,0,0,0,0,1),
    309                                 array(1,0,0,0,0,0,0,0,1),
    310                                 array(1,0,0,0,0,0,0,0,1),
    311                                 array(1,1,1,1,1,1,1,1,1),
    312                                 array(1,0,0,0,0,0,0,0,1),
    313                                 array(1,0,0,0,0,0,0,0,1),
    314                                 array(1,0,0,0,0,0,0,0,1),
    315                                 array(1,0,0,0,0,0,0,0,1),
    316                                 array(1,0,0,0,0,0,0,0,1),
    317                                 array(1,0,0,0,0,0,0,0,1),
    318                                 array(1,0,0,0,0,0,0,0,1),
    319                         ),
    320                         'I' => array(
    321                                 array(1,1,1,1,1,1,1,1,1),
    322                                 array(0,0,0,0,1,0,0,0,0),
    323                                 array(0,0,0,0,1,0,0,0,0),
    324                                 array(0,0,0,0,1,0,0,0,0),
    325                                 array(0,0,0,0,1,0,0,0,0),
    326                                 array(0,0,0,0,1,0,0,0,0),
    327                                 array(0,0,0,0,1,0,0,0,0),
    328                                 array(0,0,0,0,1,0,0,0,0),
    329                                 array(0,0,0,0,1,0,0,0,0),
    330                                 array(0,0,0,0,1,0,0,0,0),
    331                                 array(0,0,0,0,1,0,0,0,0),
    332                                 array(0,0,0,0,1,0,0,0,0),
    333                                 array(0,0,0,0,1,0,0,0,0),
    334                                 array(0,0,0,0,1,0,0,0,0),
    335                                 array(1,1,1,1,1,1,1,1,1),
    336                         ),
    337                         'J' => array(
    338                                 array(1,1,1,1,1,1,1,1,1),
    339                                 array(0,0,0,0,0,1,0,0,0),
    340                                 array(0,0,0,0,0,1,0,0,0),
    341                                 array(0,0,0,0,0,1,0,0,0),
    342                                 array(0,0,0,0,0,1,0,0,0),
    343                                 array(0,0,0,0,0,1,0,0,0),
    344                                 array(0,0,0,0,0,1,0,0,0),
    345                                 array(0,0,0,0,0,1,0,0,0),
    346                                 array(0,0,0,0,0,1,0,0,0),
    347                                 array(0,0,0,0,0,1,0,0,0),
    348                                 array(0,0,0,0,0,1,0,0,0),
    349                                 array(1,0,0,0,0,1,0,0,0),
    350                                 array(1,0,0,0,0,1,0,0,0),
    351                                 array(0,1,0,0,1,0,0,0,0),
    352                                 array(0,0,1,1,0,0,0,0,0),
    353                         ),
    354                         'K' => array(    // New 'K', supplied by NeoThermic
    355                                 array(1,0,0,0,0,0,0,0,1),
    356                                 array(1,0,0,0,0,0,0,1,0),
    357                                 array(1,0,0,0,0,0,1,0,0),
    358                                 array(1,0,0,0,0,1,0,0,0),
    359                                 array(1,0,0,0,1,0,0,0,0),
    360                                 array(1,0,0,1,0,0,0,0,0),
    361                                 array(1,0,1,0,0,0,0,0,0),
    362                                 array(1,1,0,0,0,0,0,0,0),
    363                                 array(1,0,1,0,0,0,0,0,0),
    364                                 array(1,0,0,1,0,0,0,0,0),
    365                                 array(1,0,0,0,1,0,0,0,0),
    366                                 array(1,0,0,0,0,1,0,0,0),
    367                                 array(1,0,0,0,0,0,1,0,0),
    368                                 array(1,0,0,0,0,0,0,1,0),
    369                                 array(1,0,0,0,0,0,0,0,1),
    370                         ),
    371                         'L' => array(
    372                                 array(0,0,0,0,0,0,0,0,0),
    373                                 array(1,0,0,0,0,0,0,0,0),
    374                                 array(1,0,0,0,0,0,0,0,0),
    375                                 array(1,0,0,0,0,0,0,0,0),
    376                                 array(1,0,0,0,0,0,0,0,0),
    377                                 array(1,0,0,0,0,0,0,0,0),
    378                                 array(1,0,0,0,0,0,0,0,0),
    379                                 array(1,0,0,0,0,0,0,0,0),
    380                                 array(1,0,0,0,0,0,0,0,0),
    381                                 array(1,0,0,0,0,0,0,0,0),
    382                                 array(1,0,0,0,0,0,0,0,0),
    383                                 array(1,0,0,0,0,0,0,0,0),
    384                                 array(1,0,0,0,0,0,0,0,0),
    385                                 array(1,0,0,0,0,0,0,0,0),
    386                                 array(1,1,1,1,1,1,1,1,1),
    387                         ),
    388                         'M' => array(
    389                                 array(1,1,0,0,0,0,0,1,1),
    390                                 array(1,1,0,0,0,0,0,1,1),
    391                                 array(1,0,1,0,0,0,1,0,1),
    392                                 array(1,0,1,0,0,0,1,0,1),
    393                                 array(1,0,1,0,0,0,1,0,1),
    394                                 array(1,0,0,1,0,1,0,0,1),
    395                                 array(1,0,0,1,0,1,0,0,1),
    396                                 array(1,0,0,1,0,1,0,0,1),
    397                                 array(1,0,0,0,1,0,0,0,1),
    398                                 array(1,0,0,0,1,0,0,0,1),
    399                                 array(1,0,0,0,0,0,0,0,1),
    400                                 array(1,0,0,0,0,0,0,0,1),
    401                                 array(1,0,0,0,0,0,0,0,1),
    402                                 array(1,0,0,0,0,0,0,0,1),
    403                                 array(1,0,0,0,0,0,0,0,1),
    404                         ),
    405                         'N' => array(
    406                                 array(1,1,0,0,0,0,0,0,1),
    407                                 array(1,1,0,0,0,0,0,0,1),
    408                                 array(1,0,1,0,0,0,0,0,1),
    409                                 array(1,0,1,0,0,0,0,0,1),
    410                                 array(1,0,0,1,0,0,0,0,1),
    411                                 array(1,0,0,1,0,0,0,0,1),
    412                                 array(1,0,0,0,1,0,0,0,1),
    413                                 array(1,0,0,0,1,0,0,0,1),
    414                                 array(1,0,0,0,1,0,0,0,1),
    415                                 array(1,0,0,0,0,1,0,0,1),
    416                                 array(1,0,0,0,0,1,0,0,1),
    417                                 array(1,0,0,0,0,0,1,0,1),
    418                                 array(1,0,0,0,0,0,1,0,1),
    419                                 array(1,0,0,0,0,0,0,1,1),
    420                                 array(1,0,0,0,0,0,0,1,1),
    421                         ),
    422                         'O' => array(
    423                                 array(0,0,1,1,1,1,1,0,0),
    424                                 array(0,1,0,0,0,0,0,1,0),
    425                                 array(1,0,0,0,0,0,0,0,1),
    426                                 array(1,0,0,0,0,0,0,0,1),
    427                                 array(1,0,0,0,0,0,0,0,1),
    428                                 array(1,0,0,0,0,0,0,0,1),
    429                                 array(1,0,0,0,0,0,0,0,1),
    430                                 array(1,0,0,0,0,0,0,0,1),
    431                                 array(1,0,0,0,0,0,0,0,1),
    432                                 array(1,0,0,0,0,0,0,0,1),
    433                                 array(1,0,0,0,0,0,0,0,1),
    434                                 array(1,0,0,0,0,0,0,0,1),
    435                                 array(1,0,0,0,0,0,0,0,1),
    436                                 array(0,1,0,0,0,0,0,1,0),
    437                                 array(0,0,1,1,1,1,1,0,0),
    438                         ),
    439                         'P' => array(
    440                                 array(1,1,1,1,1,1,1,0,0),
    441                                 array(1,0,0,0,0,0,0,1,0),
    442                                 array(1,0,0,0,0,0,0,0,1),
    443                                 array(1,0,0,0,0,0,0,0,1),
    444                                 array(1,0,0,0,0,0,0,0,1),
    445                                 array(1,0,0,0,0,0,0,0,1),
    446                                 array(1,0,0,0,0,0,0,1,0),
    447                                 array(1,1,1,1,1,1,1,0,0),
    448                                 array(1,0,0,0,0,0,0,0,0),
    449                                 array(1,0,0,0,0,0,0,0,0),
    450                                 array(1,0,0,0,0,0,0,0,0),
    451                                 array(1,0,0,0,0,0,0,0,0),
    452                                 array(1,0,0,0,0,0,0,0,0),
    453                                 array(1,0,0,0,0,0,0,0,0),
    454                                 array(1,0,0,0,0,0,0,0,0),
    455                         ),
    456                         'Q' => array(
    457                                 array(0,0,1,1,1,1,1,0,0),
    458                                 array(0,1,0,0,0,0,0,1,0),
    459                                 array(1,0,0,0,0,0,0,0,1),
    460                                 array(1,0,0,0,0,0,0,0,1),
    461                                 array(1,0,0,0,0,0,0,0,1),
    462                                 array(1,0,0,0,0,0,0,0,1),
    463                                 array(1,0,0,0,0,0,0,0,1),
    464                                 array(1,0,0,0,0,0,0,0,1),
    465                                 array(1,0,0,0,0,0,0,0,1),
    466                                 array(1,0,0,0,0,0,0,0,1),
    467                                 array(1,0,0,0,0,0,0,0,1),
    468                                 array(1,0,0,0,0,1,0,0,1),
    469                                 array(1,0,0,0,0,0,1,0,1),
    470                                 array(0,1,0,0,0,0,0,1,0),
    471                                 array(0,0,1,1,1,1,1,0,1),
    472                         ),
    473                         'R' => array(
    474                                 array(1,1,1,1,1,1,1,0,0),
    475                                 array(1,0,0,0,0,0,0,1,0),
    476                                 array(1,0,0,0,0,0,0,0,1),
    477                                 array(1,0,0,0,0,0,0,0,1),
    478                                 array(1,0,0,0,0,0,0,0,1),
    479                                 array(1,0,0,0,0,0,0,0,1),
    480                                 array(1,0,0,0,0,0,0,1,0),
    481                                 array(1,1,1,1,1,1,1,0,0),
    482                                 array(1,1,1,0,0,0,0,0,0),
    483                                 array(1,0,0,1,0,0,0,0,0),
    484                                 array(1,0,0,0,1,0,0,0,0),
    485                                 array(1,0,0,0,0,1,0,0,0),
    486                                 array(1,0,0,0,0,0,1,0,0),
    487                                 array(1,0,0,0,0,0,0,1,0),
    488                                 array(1,0,0,0,0,0,0,0,1),
    489                         ),
    490                         'S' => array(
    491                                 array(0,0,1,1,1,1,1,0,0),
    492                                 array(0,1,0,0,0,0,0,1,0),
    493                                 array(1,0,0,0,0,0,0,0,1),
    494                                 array(1,0,0,0,0,0,0,0,0),
    495                                 array(1,0,0,0,0,0,0,0,0),
    496                                 array(1,0,0,0,0,0,0,0,0),
    497                                 array(0,1,0,0,0,0,0,0,0),
    498                                 array(0,0,1,1,1,1,1,0,0),
    499                                 array(0,0,0,0,0,0,0,1,0),
    500                                 array(0,0,0,0,0,0,0,0,1),
    501                                 array(0,0,0,0,0,0,0,0,1),
    502                                 array(0,0,0,0,0,0,0,0,1),
    503                                 array(1,0,0,0,0,0,0,0,1),
    504                                 array(0,1,0,0,0,0,0,1,0),
    505                                 array(0,0,1,1,1,1,1,0,0),
    506                         ),
    507                         'T' => array(
    508                                 array(1,1,1,1,1,1,1,1,1),
    509                                 array(0,0,0,0,1,0,0,0,0),
    510                                 array(0,0,0,0,1,0,0,0,0),
    511                                 array(0,0,0,0,1,0,0,0,0),
    512                                 array(0,0,0,0,1,0,0,0,0),
    513                                 array(0,0,0,0,1,0,0,0,0),
    514                                 array(0,0,0,0,1,0,0,0,0),
    515                                 array(0,0,0,0,1,0,0,0,0),
    516                                 array(0,0,0,0,1,0,0,0,0),
    517                                 array(0,0,0,0,1,0,0,0,0),
    518                                 array(0,0,0,0,1,0,0,0,0),
    519                                 array(0,0,0,0,1,0,0,0,0),
    520                                 array(0,0,0,0,1,0,0,0,0),
    521                                 array(0,0,0,0,1,0,0,0,0),
    522                                 array(0,0,0,0,1,0,0,0,0),
    523                         ),
    524                         'U' => array(
    525                                 array(1,0,0,0,0,0,0,0,1),
    526                                 array(1,0,0,0,0,0,0,0,1),
    527                                 array(1,0,0,0,0,0,0,0,1),
    528                                 array(1,0,0,0,0,0,0,0,1),
    529                                 array(1,0,0,0,0,0,0,0,1),
    530                                 array(1,0,0,0,0,0,0,0,1),
    531                                 array(1,0,0,0,0,0,0,0,1),
    532                                 array(1,0,0,0,0,0,0,0,1),
    533                                 array(1,0,0,0,0,0,0,0,1),
    534                                 array(1,0,0,0,0,0,0,0,1),
    535                                 array(1,0,0,0,0,0,0,0,1),
    536                                 array(1,0,0,0,0,0,0,0,1),
    537                                 array(1,0,0,0,0,0,0,0,1),
    538                                 array(0,1,0,0,0,0,0,1,0),
    539                                 array(0,0,1,1,1,1,1,0,0),
    540                         ),
    541                         'V' => array(
    542                                 array(1,0,0,0,0,0,0,0,1),
    543                                 array(1,0,0,0,0,0,0,0,1),
    544                                 array(1,0,0,0,0,0,0,0,1),
    545                                 array(0,1,0,0,0,0,0,1,0),
    546                                 array(0,1,0,0,0,0,0,1,0),
    547                                 array(0,1,0,0,0,0,0,1,0),
    548                                 array(0,0,1,0,0,0,1,0,0),
    549                                 array(0,0,1,0,0,0,1,0,0),
    550                                 array(0,0,1,0,0,0,1,0,0),
    551                                 array(0,0,1,0,0,0,1,0,0),
    552                                 array(0,0,0,1,0,1,0,0,0),
    553                                 array(0,0,0,1,0,1,0,0,0),
    554                                 array(0,0,0,1,0,1,0,0,0),
    555                                 array(0,0,0,0,1,0,0,0,0),
    556                                 array(0,0,0,0,1,0,0,0,0),
    557                         ),
    558                         'W' => array(    // New 'W', supplied by MHobbit
    559                                 array(1,0,0,0,0,0,0,0,1),
    560                                 array(1,0,0,0,0,0,0,0,1),
    561                                 array(1,0,0,0,0,0,0,0,1),
    562                                 array(1,0,0,0,0,0,0,0,1),
    563                                 array(1,0,0,0,0,0,0,0,1),
    564                                 array(1,0,0,0,1,0,0,0,1),
    565                                 array(1,0,0,0,1,0,0,0,1),
    566                                 array(1,0,0,1,0,1,0,0,1),
    567                                 array(1,0,0,1,0,1,0,0,1),
    568                                 array(1,0,0,1,0,1,0,0,1),
    569                                 array(1,0,1,0,0,0,1,0,1),
    570                                 array(1,0,1,0,0,0,1,0,1),
    571                                 array(1,0,1,0,0,0,1,0,1),
    572                                 array(1,1,0,0,0,0,0,1,1),
    573                                 array(1,1,0,0,0,0,0,1,1),
    574                         ),
    575                         'X' => array(
    576                                 array(1,0,0,0,0,0,0,0,1),
    577                                 array(1,0,0,0,0,0,0,0,1),
    578                                 array(0,1,0,0,0,0,0,1,0),
    579                                 array(0,1,0,0,0,0,0,1,0),
    580                                 array(0,0,1,0,0,0,1,0,0),
    581                                 array(0,0,0,1,0,1,0,0,0),
    582                                 array(0,0,0,1,0,1,0,0,0),
    583                                 array(0,0,0,0,1,0,0,0,0),
    584                                 array(0,0,0,1,0,1,0,0,0),
    585                                 array(0,0,0,1,0,1,0,0,0),
    586                                 array(0,0,1,0,0,0,1,0,0),
    587                                 array(0,1,0,0,0,0,1,0,0),
    588                                 array(0,1,0,0,0,0,0,1,0),
    589                                 array(1,0,0,0,0,0,0,0,1),
    590                                 array(1,0,0,0,0,0,0,0,1),
    591                         ),
    592                         'Y' => array(
    593                                 array(1,0,0,0,0,0,0,0,1),
    594                                 array(1,0,0,0,0,0,0,0,1),
    595                                 array(0,1,0,0,0,0,0,1,0),
    596                                 array(0,1,0,0,0,0,0,1,0),
    597                                 array(0,0,1,0,0,0,1,0,0),
    598                                 array(0,0,1,0,0,0,1,0,0),
    599                                 array(0,0,0,1,0,1,0,0,0),
    600                                 array(0,0,0,0,1,0,0,0,0),
    601                                 array(0,0,0,0,1,0,0,0,0),
    602                                 array(0,0,0,0,1,0,0,0,0),
    603                                 array(0,0,0,0,1,0,0,0,0),
    604                                 array(0,0,0,0,1,0,0,0,0),
    605                                 array(0,0,0,0,1,0,0,0,0),
    606                                 array(0,0,0,0,1,0,0,0,0),
    607                                 array(0,0,0,0,1,0,0,0,0),
    608                         ),
    609                         'Z' => array(    // New 'Z' supplied by Anon
    610                                 array(1,1,1,1,1,1,1,1,1),
    611                                 array(1,0,0,0,0,0,0,0,1),
    612                                 array(0,0,0,0,0,0,0,0,1),
    613                                 array(0,0,0,0,0,0,0,1,0),
    614                                 array(0,0,0,0,0,0,1,0,0),
    615                                 array(0,0,0,0,0,1,0,0,0),
    616                                 array(0,0,0,0,0,1,0,0,0),
    617                                 array(0,0,0,0,1,0,0,0,0),
    618                                 array(0,0,0,1,0,0,0,0,0),
    619                                 array(0,0,0,1,0,0,0,0,0),
    620                                 array(0,0,1,0,0,0,0,0,0),
    621                                 array(0,1,0,0,0,0,0,0,0),
    622                                 array(1,0,0,0,0,0,0,0,0),
    623                                 array(1,0,0,0,0,0,0,0,1),
    624                                 array(1,1,1,1,1,1,1,1,1),
    625                         ),
     1672                        'A' =>  $chars['A'][mt_rand(0, min(count($chars['A']), $config['captcha_gd_fonts']) -1)],
     1673                        'B' =>  $chars['B'][mt_rand(0, min(count($chars['B']), $config['captcha_gd_fonts']) -1)],
     1674                        'C' =>  $chars['C'][mt_rand(0, min(count($chars['C']), $config['captcha_gd_fonts']) -1)],
     1675                        'D' =>  $chars['D'][mt_rand(0, min(count($chars['D']), $config['captcha_gd_fonts']) -1)],
     1676                        'E' =>  $chars['E'][mt_rand(0, min(count($chars['E']), $config['captcha_gd_fonts']) -1)],
     1677                        'F' =>  $chars['F'][mt_rand(0, min(count($chars['F']), $config['captcha_gd_fonts']) -1)],
     1678                        'G' =>  $chars['G'][mt_rand(0, min(count($chars['G']), $config['captcha_gd_fonts']) -1)],
     1679                        'H' =>  $chars['H'][mt_rand(0, min(count($chars['H']), $config['captcha_gd_fonts']) -1)],
     1680                        'I' =>  $chars['I'][mt_rand(0, min(count($chars['I']), $config['captcha_gd_fonts']) -1)],
     1681                        'J' =>  $chars['J'][mt_rand(0, min(count($chars['J']), $config['captcha_gd_fonts']) -1)],
     1682                        'K' =>  $chars['K'][mt_rand(0, min(count($chars['K']), $config['captcha_gd_fonts']) -1)],
     1683                        'L' =>  $chars['L'][mt_rand(0, min(count($chars['L']), $config['captcha_gd_fonts']) -1)],
     1684                        'M' =>  $chars['M'][mt_rand(0, min(count($chars['M']), $config['captcha_gd_fonts']) -1)], 
     1685                        'N' =>  $chars['N'][mt_rand(0, min(count($chars['N']), $config['captcha_gd_fonts']) -1)],
     1686                        'O' =>  $chars['O'][mt_rand(0, min(count($chars['O']), $config['captcha_gd_fonts']) -1)],
     1687                        'P' =>  $chars['P'][mt_rand(0, min(count($chars['P']), $config['captcha_gd_fonts']) -1)],
     1688                        'Q' =>  $chars['Q'][mt_rand(0, min(count($chars['Q']), $config['captcha_gd_fonts']) -1)],
     1689                        'R' =>  $chars['R'][mt_rand(0, min(count($chars['R']), $config['captcha_gd_fonts']) -1)],
     1690                        'S' =>  $chars['S'][mt_rand(0, min(count($chars['S']), $config['captcha_gd_fonts']) -1)],
     1691                        'T' =>  $chars['T'][mt_rand(0, min(count($chars['T']), $config['captcha_gd_fonts']) -1)],
     1692                        'U' =>  $chars['U'][mt_rand(0, min(count($chars['U']), $config['captcha_gd_fonts']) -1)],
     1693                        'V' =>  $chars['V'][mt_rand(0, min(count($chars['V']), $config['captcha_gd_fonts']) -1)],
     1694                        'W' =>  $chars['W'][mt_rand(0, min(count($chars['W']), $config['captcha_gd_fonts']) -1)],
     1695                        'X' =>  $chars['X'][mt_rand(0, min(count($chars['X']), $config['captcha_gd_fonts']) -1)],
     1696                        'Y' =>  $chars['Y'][mt_rand(0, min(count($chars['Y']), $config['captcha_gd_fonts']) -1)],
     1697                        'Z' =>  $chars['Z'][mt_rand(0, min(count($chars['Z']), $config['captcha_gd_fonts']) -1)],
     1698
    6261699                        '1' => array(
    6271700                                array(0,0,0,1,1,0,0,0,0),
  • trunk/forum/includes/constants.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: constants.php 9187 2008-12-12 14:47:03Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2626
    2727// phpBB Version
    28 define('PHPBB_VERSION', '3.0.4');
     28define('PHPBB_VERSION', '3.0.7-PL1');
    2929
    3030// QA-related
     
    9292define('FORUM_FLAG_ACTIVE_TOPICS', 16);
    9393define('FORUM_FLAG_POST_REVIEW', 32);
     94define('FORUM_FLAG_QUICK_REPLY', 64);
     95
     96// Forum Options... sequential order. Modifications should begin at number 10 (number 29 is maximum)
     97define('FORUM_OPTION_FEED_NEWS', 1);
     98define('FORUM_OPTION_FEED_EXCLUDE', 2);
    9499
    95100// Optional text flags
     
    161166define('NUM_CORE_BBCODES', 12);
    162167
     168// Smiley hard limit
     169define('SMILEY_LIMIT', 1000);
     170
    163171// Magic url types
    164172define('MAGIC_URL_EMAIL', 1);
     
    185193@define('CHMOD_WRITE', 2);
    186194@define('CHMOD_EXECUTE', 1);
     195
     196// Captcha code length
     197define('CAPTCHA_MIN_CHARS', 4);
     198define('CAPTCHA_MAX_CHARS', 7);
    187199
    188200// Additional constants
  • trunk/forum/includes/db/db_tools.php

    r400 r702  
    33*
    44* @package dbal
    5 * @version $Id: db_tools.php 8814 2008-09-04 12:01:47Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2007 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3131        var $sql_layer = '';
    3232
     33        /**
     34        * @var object DB object
     35        */
     36        var $db = NULL;
     37
     38        /**
     39        * The Column types for every database we support
     40        * @var array
     41        */
    3342        var $dbms_type_map = array(
    3443                'mysql_41'      => array(
     
    243252        );
    244253
    245         // A list of types being unsigned for better reference in some db's
     254        /**
     255        * A list of types being unsigned for better reference in some db's
     256        * @var array
     257        */
    246258        var $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP');
     259
     260        /**
     261        * A list of supported DBMS. We change this class to support more DBMS, the DBMS itself only need to follow some rules.
     262        * @var array
     263        */
    247264        var $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite');
    248265
    249266        /**
    250         * Set this to true if you only want to return the 'to-be-executed' SQL statement(s) (as an array).
     267        * This is set to true if user only wants to return the 'to-be-executed' SQL statement(s) (as an array).
     268        * This mode has no effect on some methods (inserting of data for example). This is expressed within the methods command.
    251269        */
    252270        var $return_statements = false;
    253271
    254272        /**
    255         */
    256         function phpbb_db_tools(&$db)
     273        * Constructor. Set DB Object and set {@link $return_statements return_statements}.
     274        *
     275        * @param phpbb_dbal     $db                                     DBAL object
     276        * @param bool           $return_statements      True if only statements should be returned and no SQL being executed
     277        */
     278        function phpbb_db_tools(&$db, $return_statements = false)
    257279        {
    258280                $this->db = $db;
     281                $this->return_statements = $return_statements;
    259282
    260283                // Determine mapping database type
     
    289312                        break;
    290313                }
     314        }
     315
     316        /**
     317        * Check if table exists
     318        *
     319        *
     320        * @param string $table_name     The table name to check for
     321        * @return bool true if table exists, else false
     322        */
     323        function sql_table_exists($table_name)
     324        {
     325                $this->db->sql_return_on_error(true);
     326                $result = $this->db->sql_query_limit('SELECT * FROM ' . $table_name, 1);
     327                $this->db->sql_return_on_error(false);
     328
     329                if ($result)
     330                {
     331                        $this->db->sql_freeresult($result);
     332                        return true;
     333                }
     334
     335                return false;
     336        }
     337
     338        /**
     339        * Create SQL Table
     340        *
     341        * @param string $table_name     The table name to create
     342        * @param array  $table_data     Array containing table data.
     343        * @return array Statements if $return_statements is true.
     344        */
     345        function sql_create_table($table_name, $table_data)
     346        {
     347                // holds the DDL for a column
     348                $columns = $statements = array();
     349
     350                if ($this->sql_table_exists($table_name))
     351                {
     352                        return $this->_sql_run_sql($statements);
     353                }
     354
     355                // Begin transaction
     356                $statements[] = 'begin';
     357
     358                // Determine if we have created a PRIMARY KEY in the earliest
     359                $primary_key_gen = false;
     360
     361                // Determine if the table must be created with TEXTIMAGE
     362                $create_textimage = false;
     363
     364                // Determine if the table requires a sequence
     365                $create_sequence = false;
     366
     367                // Begin table sql statement
     368                switch ($this->sql_layer)
     369                {
     370                        case 'mssql':
     371                                $table_sql = 'CREATE TABLE [' . $table_name . '] (' . "\n";
     372                        break;
     373
     374                        default:
     375                                $table_sql = 'CREATE TABLE ' . $table_name . ' (' . "\n";
     376                        break;
     377                }
     378
     379                // Iterate through the columns to create a table
     380                foreach ($table_data['COLUMNS'] as $column_name => $column_data)
     381                {
     382                        // here lies an array, filled with information compiled on the column's data
     383                        $prepared_column = $this->sql_prepare_column_data($table_name, $column_name, $column_data);
     384
     385                        // here we add the definition of the new column to the list of columns
     386                        switch ($this->sql_layer)
     387                        {
     388                                case 'mssql':
     389                                        $columns[] = "\t [{$column_name}] " . $prepared_column['column_type_sql_default'];
     390                                break;
     391
     392                                default:
     393                                        $columns[] = "\t {$column_name} " . $prepared_column['column_type_sql'];
     394                                break;
     395                        }
     396
     397                        // see if we have found a primary key set due to a column definition if we have found it, we can stop looking
     398                        if (!$primary_key_gen)
     399                        {
     400                                $primary_key_gen = isset($prepared_column['primary_key_set']) && $prepared_column['primary_key_set'];
     401                        }
     402
     403                        // create textimage DDL based off of the existance of certain column types
     404                        if (!$create_textimage)
     405                        {
     406                                $create_textimage = isset($prepared_column['textimage']) && $prepared_column['textimage'];
     407                        }
     408
     409                        // create sequence DDL based off of the existance of auto incrementing columns
     410                        if (!$create_sequence && isset($prepared_column['auto_increment']) && $prepared_column['auto_increment'])
     411                        {
     412                                $create_sequence = $column_name;
     413                        }
     414                }
     415
     416                // this makes up all the columns in the create table statement
     417                $table_sql .= implode(",\n", $columns);
     418
     419                // Close the table for two DBMS and add to the statements
     420                switch ($this->sql_layer)
     421                {
     422                        case 'firebird':
     423                                $table_sql .= "\n);";
     424                                $statements[] = $table_sql;
     425                        break;
     426
     427                        case 'mssql':
     428                                $table_sql .= "\n) ON [PRIMARY]" . (($create_textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '');
     429                                $statements[] = $table_sql;
     430                        break;
     431                }
     432
     433                // we have yet to create a primary key for this table,
     434                // this means that we can add the one we really wanted instead
     435                if (!$primary_key_gen)
     436                {
     437                        // Write primary key
     438                        if (isset($table_data['PRIMARY_KEY']))
     439                        {
     440                                if (!is_array($table_data['PRIMARY_KEY']))
     441                                {
     442                                        $table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']);
     443                                }
     444
     445                                switch ($this->sql_layer)
     446                                {
     447                                        case 'mysql_40':
     448                                        case 'mysql_41':
     449                                        case 'postgres':
     450                                        case 'sqlite':
     451                                                $table_sql .= ",\n\t PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ')';
     452                                        break;
     453
     454                                        case 'firebird':
     455                                        case 'mssql':
     456                                                // We need the data here
     457                                                $old_return_statements = $this->return_statements;
     458                                                $this->return_statements = true;
     459
     460                                                $primary_key_stmts = $this->sql_create_primary_key($table_name, $table_data['PRIMARY_KEY']);
     461                                                foreach ($primary_key_stmts as $pk_stmt)
     462                                                {
     463                                                        $statements[] = $pk_stmt;
     464                                                }
     465
     466                                                $this->return_statements = $old_return_statements;
     467                                        break;
     468
     469                                        case 'oracle':
     470                                                $table_sql .= ",\n\t CONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ')';
     471                                        break;
     472                                }
     473                        }
     474                }
     475
     476                // close the table
     477                switch ($this->sql_layer)
     478                {
     479                        case 'mysql_41':
     480                                // make sure the table is in UTF-8 mode
     481                                $table_sql .= "\n) CHARACTER SET `utf8` COLLATE `utf8_bin`;";
     482                                $statements[] = $table_sql;
     483                        break;
     484
     485                        case 'mysql_40':
     486                        case 'sqlite':
     487                                $table_sql .= "\n);";
     488                                $statements[] = $table_sql;
     489                        break;
     490
     491                        case 'postgres':
     492                                // do we need to add a sequence for auto incrementing columns?
     493                                if ($create_sequence)
     494                                {
     495                                        $statements[] = "CREATE SEQUENCE {$table_name}_seq;";
     496                                }
     497
     498                                $table_sql .= "\n);";
     499                                $statements[] = $table_sql;
     500                        break;
     501
     502                        case 'oracle':
     503                                $table_sql .= "\n);";
     504                                $statements[] = $table_sql;
     505
     506                                // do we need to add a sequence and a tigger for auto incrementing columns?
     507                                if ($create_sequence)
     508                                {
     509                                        // create the actual sequence
     510                                        $statements[] = "CREATE SEQUENCE {$table_name}_seq";
     511
     512                                        // the trigger is the mechanism by which we increment the counter
     513                                        $trigger = "CREATE OR REPLACE TRIGGER t_{$table_name}\n";
     514                                        $trigger .= "BEFORE INSERT ON {$table_name}\n";
     515                                        $trigger .= "FOR EACH ROW WHEN (\n";
     516                                        $trigger .= "\tnew.{$create_sequence} IS NULL OR new.{$create_sequence} = 0\n";
     517                                        $trigger .= ")\n";
     518                                        $trigger .= "BEGIN\n";
     519                                        $trigger .= "\tSELECT {$table_name}_seq.nextval\n";
     520                                        $trigger .= "\tINTO :new.{$create_sequence}\n";
     521                                        $trigger .= "\tFROM dual\n";
     522                                        $trigger .= "END;";
     523
     524                                        $statements[] = $trigger;
     525                                }
     526                        break;
     527
     528                        case 'firebird':
     529                                if ($create_sequence)
     530                                {
     531                                        $statements[] = "CREATE SEQUENCE {$table_name}_seq;";
     532                                }
     533                        break;
     534                }
     535
     536                // Write Keys
     537                if (isset($table_data['KEYS']))
     538                {
     539                        foreach ($table_data['KEYS'] as $key_name => $key_data)
     540                        {
     541                                if (!is_array($key_data[1]))
     542                                {
     543                                        $key_data[1] = array($key_data[1]);
     544                                }
     545
     546                                $old_return_statements = $this->return_statements;
     547                                $this->return_statements = true;
     548
     549                                $key_stmts = ($key_data[0] == 'UNIQUE') ? $this->sql_create_unique_index($table_name, $key_name, $key_data[1]) : $this->sql_create_index($table_name, $key_name, $key_data[1]);
     550
     551                                foreach ($key_stmts as $key_stmt)
     552                                {
     553                                        $statements[] = $key_stmt;
     554                                }
     555
     556                                $this->return_statements = $old_return_statements;
     557                        }
     558                }
     559
     560                // Commit Transaction
     561                $statements[] = 'commit';
     562
     563                return $this->_sql_run_sql($statements);
    291564        }
    292565
     
    309582        *               )
    310583        *
    311         * For more information have a look at /develop/create_schema_files.php (only available through CVS)
     584        * For more information have a look at /develop/create_schema_files.php (only available through SVN)
    312585        */
    313586        function perform_schema_changes($schema_changes)
     
    319592
    320593                $statements = array();
     594                $sqlite = false;
     595
     596                // For SQLite we need to perform the schema changes in a much more different way
     597                if ($this->db->sql_layer == 'sqlite' && $this->return_statements)
     598                {
     599                        $sqlite_data = array();
     600                        $sqlite = true;
     601                }
    321602
    322603                // Change columns?
     
    327608                                foreach ($columns as $column_name => $column_data)
    328609                                {
    329                                         $result = $this->sql_column_change($table, $column_name, $column_data);
    330 
    331                                         if ($this->return_statements)
     610                                        // If the column exists we change it, else we add it ;)
     611                                        if ($column_exists = $this->sql_column_exists($table, $column_name))
     612                                        {
     613                                                $result = $this->sql_column_change($table, $column_name, $column_data, true);
     614                                        }
     615                                        else
     616                                        {
     617                                                $result = $this->sql_column_add($table, $column_name, $column_data, true);
     618                                        }
     619
     620                                        if ($sqlite)
     621                                        {
     622                                                if ($column_exists)
     623                                                {
     624                                                        $sqlite_data[$table]['change_columns'][] = $result;
     625                                                }
     626                                                else
     627                                                {
     628                                                        $sqlite_data[$table]['add_columns'][] = $result;
     629                                                }
     630                                        }
     631                                        else if ($this->return_statements)
    332632                                        {
    333633                                                $statements = array_merge($statements, $result);
     
    344644                                foreach ($columns as $column_name => $column_data)
    345645                                {
    346                                         // Only add the column if it does not exist yet
    347                                         if (!$this->sql_column_exists($table, $column_name))
    348                                         {
    349                                                 $result = $this->sql_column_add($table, $column_name, $column_data);
    350 
    351                                                 if ($this->return_statements)
     646                                        // Only add the column if it does not exist yet, else change it (to be consistent)
     647                                        if ($column_exists = $this->sql_column_exists($table, $column_name))
     648                                        {
     649                                                $result = $this->sql_column_change($table, $column_name, $column_data, true);
     650                                        }
     651                                        else
     652                                        {
     653                                                $result = $this->sql_column_add($table, $column_name, $column_data, true);
     654                                        }
     655
     656                                        if ($sqlite)
     657                                        {
     658                                                if ($column_exists)
     659                                                {
     660                                                        $sqlite_data[$table]['change_columns'][] = $result;
     661                                                }
     662                                                else
     663                                                {
     664                                                        $sqlite_data[$table]['add_columns'][] = $result;
     665                                                }
     666                                        }
     667                                        else if ($this->return_statements)
     668                                        {
     669                                                $statements = array_merge($statements, $result);
     670                                        }
     671                                }
     672                        }
     673                }
     674
     675                // Remove keys?
     676                if (!empty($schema_changes['drop_keys']))
     677                {
     678                        foreach ($schema_changes['drop_keys'] as $table => $indexes)
     679                        {
     680                                foreach ($indexes as $index_name)
     681                                {
     682                                        $result = $this->sql_index_drop($table, $index_name);
     683
     684                                        if ($this->return_statements)
     685                                        {
     686                                                $statements = array_merge($statements, $result);
     687                                        }
     688                                }
     689                        }
     690                }
     691
     692                // Drop columns?
     693                if (!empty($schema_changes['drop_columns']))
     694                {
     695                        foreach ($schema_changes['drop_columns'] as $table => $columns)
     696                        {
     697                                foreach ($columns as $column)
     698                                {
     699                                        // Only remove the column if it exists...
     700                                        if ($this->sql_column_exists($table, $column))
     701                                        {
     702                                                $result = $this->sql_column_remove($table, $column, true);
     703
     704                                                if ($sqlite)
     705                                                {
     706                                                        $sqlite_data[$table]['drop_columns'][] = $result;
     707                                                }
     708                                                else if ($this->return_statements)
    352709                                                {
    353710                                                        $statements = array_merge($statements, $result);
     
    358715                }
    359716
    360                 // Remove keys?
    361                 if (!empty($schema_changes['drop_keys']))
    362                 {
    363                         foreach ($schema_changes['drop_keys'] as $table => $indexes)
    364                         {
    365                                 foreach ($indexes as $index_name)
    366                                 {
    367                                         $result = $this->sql_index_drop($table, $index_name);
    368 
    369                                         if ($this->return_statements)
    370                                         {
    371                                                 $statements = array_merge($statements, $result);
    372                                         }
    373                                 }
    374                         }
    375                 }
    376 
    377                 // Drop columns?
    378                 if (!empty($schema_changes['drop_columns']))
    379                 {
    380                         foreach ($schema_changes['drop_columns'] as $table => $columns)
    381                         {
    382                                 foreach ($columns as $column)
    383                                 {
    384                                         $result = $this->sql_column_remove($table, $column);
    385 
    386                                         if ($this->return_statements)
    387                                         {
    388                                                 $statements = array_merge($statements, $result);
    389                                         }
    390                                 }
    391                         }
    392                 }
    393 
    394717                // Add primary keys?
    395718                if (!empty($schema_changes['add_primary_keys']))
     
    397720                        foreach ($schema_changes['add_primary_keys'] as $table => $columns)
    398721                        {
    399                                 $result = $this->sql_create_primary_key($table, $columns);
    400 
    401                                 if ($this->return_statements)
     722                                $result = $this->sql_create_primary_key($table, $columns, true);
     723
     724                                if ($sqlite)
     725                                {
     726                                        $sqlite_data[$table]['primary_key'] = $result;
     727                                }
     728                                else if ($this->return_statements)
    402729                                {
    403730                                        $statements = array_merge($statements, $result);
     
    440767                }
    441768
     769                if ($sqlite)
     770                {
     771                        foreach ($sqlite_data as $table_name => $sql_schema_changes)
     772                        {
     773                                // Create temporary table with original data
     774                                $statements[] = 'begin';
     775
     776                                $sql = "SELECT sql
     777                                        FROM sqlite_master
     778                                        WHERE type = 'table'
     779                                                AND name = '{$table_name}'
     780                                        ORDER BY type DESC, name;";
     781                                $result = $this->db->sql_query($sql);
     782
     783                                if (!$result)
     784                                {
     785                                        continue;
     786                                }
     787
     788                                $row = $this->db->sql_fetchrow($result);
     789                                $this->db->sql_freeresult($result);
     790
     791                                // Create a backup table and populate it, destroy the existing one
     792                                $statements[] = preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']);
     793                                $statements[] = 'INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name;
     794                                $statements[] = 'DROP TABLE ' . $table_name;
     795
     796                                // Get the columns...
     797                                preg_match('#\((.*)\)#s', $row['sql'], $matches);
     798
     799                                $plain_table_cols = trim($matches[1]);
     800                                $new_table_cols = preg_split('/,(?![\s\w]+\))/m', $plain_table_cols);
     801                                $column_list = array();
     802
     803                                foreach ($new_table_cols as $declaration)
     804                                {
     805                                        $entities = preg_split('#\s+#', trim($declaration));
     806                                        if ($entities[0] == 'PRIMARY')
     807                                        {
     808                                                continue;
     809                                        }
     810                                        $column_list[] = $entities[0];
     811                                }
     812
     813                                // note down the primary key notation because sqlite only supports adding it to the end for the new table
     814                                $primary_key = false;
     815                                $_new_cols = array();
     816
     817                                foreach ($new_table_cols as $key => $declaration)
     818                                {
     819                                        $entities = preg_split('#\s+#', trim($declaration));
     820                                        if ($entities[0] == 'PRIMARY')
     821                                        {
     822                                                $primary_key = $declaration;
     823                                                continue;
     824                                        }
     825                                        $_new_cols[] = $declaration;
     826                                }
     827
     828                                $new_table_cols = $_new_cols;
     829
     830                                // First of all... change columns
     831                                if (!empty($sql_schema_changes['change_columns']))
     832                                {
     833                                        foreach ($sql_schema_changes['change_columns'] as $column_sql)
     834                                        {
     835                                                foreach ($new_table_cols as $key => $declaration)
     836                                                {
     837                                                        $entities = preg_split('#\s+#', trim($declaration));
     838                                                        if (strpos($column_sql, $entities[0] . ' ') === 0)
     839                                                        {
     840                                                                $new_table_cols[$key] = $column_sql;
     841                                                        }
     842                                                }
     843                                        }
     844                                }
     845
     846                                if (!empty($sql_schema_changes['add_columns']))
     847                                {
     848                                        foreach ($sql_schema_changes['add_columns'] as $column_sql)
     849                                        {
     850                                                $new_table_cols[] = $column_sql;
     851                                        }
     852                                }
     853
     854                                // Now drop them...
     855                                if (!empty($sql_schema_changes['drop_columns']))
     856                                {
     857                                        foreach ($sql_schema_changes['drop_columns'] as $column_name)
     858                                        {
     859                                                // Remove from column list...
     860                                                $new_column_list = array();
     861                                                foreach ($column_list as $key => $value)
     862                                                {
     863                                                        if ($value === $column_name)
     864                                                        {
     865                                                                continue;
     866                                                        }
     867
     868                                                        $new_column_list[] = $value;
     869                                                }
     870
     871                                                $column_list = $new_column_list;
     872
     873                                                // Remove from table...
     874                                                $_new_cols = array();
     875                                                foreach ($new_table_cols as $key => $declaration)
     876                                                {
     877                                                        $entities = preg_split('#\s+#', trim($declaration));
     878                                                        if (strpos($column_name . ' ', $entities[0] . ' ') === 0)
     879                                                        {
     880                                                                continue;
     881                                                        }
     882                                                        $_new_cols[] = $declaration;
     883                                                }
     884                                                $new_table_cols = $_new_cols;
     885                                        }
     886                                }
     887
     888                                // Primary key...
     889                                if (!empty($sql_schema_changes['primary_key']))
     890                                {
     891                                        $new_table_cols[] = 'PRIMARY KEY (' . implode(', ', $sql_schema_changes['primary_key']) . ')';
     892                                }
     893                                // Add a new one or the old primary key
     894                                else if ($primary_key !== false)
     895                                {
     896                                        $new_table_cols[] = $primary_key;
     897                                }
     898
     899                                $columns = implode(',', $column_list);
     900
     901                                // create a new table and fill it up. destroy the temp one
     902                                $statements[] = 'CREATE TABLE ' . $table_name . ' (' . implode(',', $new_table_cols) . ');';
     903                                $statements[] = 'INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;';
     904                                $statements[] = 'DROP TABLE ' . $table_name . '_temp';
     905
     906                                $statements[] = 'commit';
     907                        }
     908                }
     909
    442910                if ($this->return_statements)
    443911                {
     
    448916        /**
    449917        * Check if a specified column exist
     918        *
     919        * @param string $table                  Table to check the column at
     920        * @param string $column_name    The column to check
     921        *
    450922        * @return bool True if column exists, else false
    451923        */
     
    520992                                $sql = "SELECT column_name
    521993                                        FROM user_tab_columns
    522                                         WHERE table_name = '{$table}'";
     994                                        WHERE LOWER(table_name) = '" . strtolower($table) . "'";
    523995                                $result = $this->db->sql_query($sql);
    524996                                while ($row = $this->db->sql_fetchrow($result))
     
    5381010                                $sql = "SELECT RDB\$FIELD_NAME as FNAME
    5391011                                        FROM RDB\$RELATION_FIELDS
    540                                         WHERE RDB\$RELATION_NAME = '{$table}'";
     1012                                        WHERE RDB\$RELATION_NAME = '" . strtoupper($table) . "'";
    5411013                                $result = $this->db->sql_query($sql);
    5421014                                while ($row = $this->db->sql_fetchrow($result))
     
    6331105                {
    6341106                        list($orig_column_type, $column_length) = explode(':', $column_data[0]);
    635 
    6361107                        if (!is_array($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']))
    6371108                        {
     
    6921163                        case 'firebird':
    6931164                                $sql .= " {$column_type} ";
     1165                                $return_array['column_type_sql_type'] = " {$column_type} ";
    6941166
    6951167                                if (!is_null($column_data[1]))
    6961168                                {
    6971169                                        $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' ';
     1170                                        $return_array['column_type_sql_default'] = ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' ';
    6981171                                }
    6991172
     
    7041177                                {
    7051178                                        $sql .= ' COLLATE UNICODE';
     1179                                }
     1180
     1181                                $return_array['auto_increment'] = false;
     1182                                if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
     1183                                {
     1184                                        $return_array['auto_increment'] = true;
    7061185                                }
    7071186
     
    7181197                                        if (strpos($column_data[1], '0x') === 0)
    7191198                                        {
    720                                                 $sql_default .= 'DEFAULT (' . $column_data[1] . ') ';
     1199                                                $return_array['default'] = 'DEFAULT (' . $column_data[1] . ') ';
     1200                                                $sql_default .= $return_array['default'];
    7211201                                        }
    7221202                                        else
    7231203                                        {
    724                                                 $sql_default .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') ';
    725                                         }
    726                                 }
     1204                                                $return_array['default'] = 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') ';
     1205                                                $sql_default .= $return_array['default'];
     1206                                        }
     1207                                }
     1208
     1209                                if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
     1210                                {
     1211//                                      $sql .= 'IDENTITY (1, 1) ';
     1212                                        $sql_default .= 'IDENTITY (1, 1) ';
     1213                                }
     1214
     1215                                $return_array['textimage'] = $column_type === '[text]';
    7271216
    7281217                                $sql .= 'NOT NULL';
     
    7301219
    7311220                                $return_array['column_type_sql_default'] = $sql_default;
     1221
    7321222                        break;
    7331223
     
    7641254                                // Therefore in oracle we allow NULL's for all DEFAULT '' entries
    7651255                                // Oracle does not like setting NOT NULL on a column that is already NOT NULL (this happens only on number fields)
    766                                 if (preg_match('/number/i', $column_type))
     1256                                if (!preg_match('/number/i', $column_type))
    7671257                                {
    7681258                                        $sql .= ($column_data[1] === '') ? '' : 'NOT NULL';
    7691259                                }
     1260
     1261                                $return_array['auto_increment'] = false;
     1262                                if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
     1263                                {
     1264                                        $return_array['auto_increment'] = true;
     1265                                }
     1266
    7701267                        break;
    7711268
     
    7751272                                $sql .= " {$column_type} ";
    7761273
     1274                                $return_array['auto_increment'] = false;
    7771275                                if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
    7781276                                {
    7791277                                        $default_val = "nextval('{$table_name}_seq')";
     1278                                        $return_array['auto_increment'] = true;
    7801279                                }
    7811280                                else if (!is_null($column_data[1]))
     
    7961295                                        $sql .= " CHECK ({$column_name} >= 0)";
    7971296                                }
     1297
    7981298                        break;
    7991299
    8001300                        case 'sqlite':
     1301                                $return_array['primary_key_set'] = false;
    8011302                                if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
    8021303                                {
    8031304                                        $sql .= ' INTEGER PRIMARY KEY';
     1305                                        $return_array['primary_key_set'] = true;
    8041306                                }
    8051307                                else
     
    8101312                                $sql .= ' NOT NULL ';
    8111313                                $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : '';
     1314
    8121315                        break;
    8131316                }
     
    8211324        * Add new column
    8221325        */
    823         function sql_column_add($table_name, $column_name, $column_data)
     1326        function sql_column_add($table_name, $column_name, $column_data, $inline = false)
    8241327        {
    8251328                $column_data = $this->sql_prepare_column_data($table_name, $column_name, $column_data);
     
    8291332                {
    8301333                        case 'firebird':
    831                                 $statements[] = 'ALTER TABLE "' . $table_name . '" ADD "' . $column_name . '" ' . $column_data['column_type_sql'];
     1334                                $statements[] = 'ALTER TABLE ' . $table_name . ' ADD "' . strtoupper($column_name) . '" ' . $column_data['column_type_sql'];
    8321335                        break;
    8331336
     
    8461349
    8471350                        case 'postgres':
    848                                 $statements[] = 'ALTER TABLE ' . $table_name . ' ADD COLUMN "' . $column_name . '" ' . $column_data['column_type_sql'];
     1351                                if (version_compare($this->db->sql_server_info(true), '8.0', '>='))
     1352                                {
     1353                                        $statements[] = 'ALTER TABLE ' . $table_name . ' ADD COLUMN "' . $column_name . '" ' . $column_data['column_type_sql'];
     1354                                }
     1355                                else
     1356                                {
     1357                                        // old versions cannot add columns with default and null information
     1358                                        $statements[] = 'ALTER TABLE ' . $table_name . ' ADD COLUMN "' . $column_name . '" ' . $column_data['column_type'] . ' ' . $column_data['constraint'];
     1359
     1360                                        if (isset($column_data['null']))
     1361                                        {
     1362                                                if ($column_data['null'] == 'NOT NULL')
     1363                                                {
     1364                                                        $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN ' . $column_name . ' SET NOT NULL';
     1365                                                }
     1366                                        }
     1367
     1368                                        if (isset($column_data['default']))
     1369                                        {
     1370                                                $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN ' . $column_name . ' SET DEFAULT ' . $column_data['default'];
     1371                                        }
     1372                                }
     1373
    8491374                        break;
    8501375
    8511376                        case 'sqlite':
     1377
     1378                                if ($inline && $this->return_statements)
     1379                                {
     1380                                        return $column_name . ' ' . $column_data['column_type_sql'];
     1381                                }
     1382
    8521383                                if (version_compare(sqlite_libversion(), '3.0') == -1)
    8531384                                {
     
    9141445        * Drop column
    9151446        */
    916         function sql_column_remove($table_name, $column_name)
     1447        function sql_column_remove($table_name, $column_name, $inline = false)
    9171448        {
    9181449                $statements = array();
     
    9211452                {
    9221453                        case 'firebird':
    923                                 $statements[] = 'ALTER TABLE "' . $table_name . '" DROP "' . $column_name . '"';
     1454                                $statements[] = 'ALTER TABLE ' . $table_name . ' DROP "' . strtoupper($column_name) . '"';
    9241455                        break;
    9251456
     
    9421473
    9431474                        case 'sqlite':
     1475
     1476                                if ($inline && $this->return_statements)
     1477                                {
     1478                                        return $column_name;
     1479                                }
     1480
    9441481                                if (version_compare(sqlite_libversion(), '3.0') == -1)
    9451482                                {
     
    9841521                                        $columns = implode(',', $column_list);
    9851522
    986                                         $new_table_cols = $new_table_cols = preg_replace('/' . $column_name . '[^,]+(?:,|$)/m', '', $new_table_cols);
     1523                                        $new_table_cols = preg_replace('/' . $column_name . '[^,]+(?:,|$)/m', '', $new_table_cols);
    9871524
    9881525                                        // create a new table and fill it up. destroy the temp one
     
    10331570
    10341571        /**
    1035         * Add primary key
    1036         */
    1037         function sql_create_primary_key($table_name, $column)
     1572        * Drop Table
     1573        */
     1574        function sql_table_drop($table_name)
    10381575        {
    10391576                $statements = array();
    10401577
     1578                if (!$this->sql_table_exists($table_name))
     1579                {
     1580                        return $this->_sql_run_sql($statements);
     1581                }
     1582
     1583                // the most basic operation, get rid of the table
     1584                $statements[] = 'DROP TABLE ' . $table_name;
     1585
     1586                switch ($this->sql_layer)
     1587                {
     1588                        case 'firebird':
     1589                                $sql = 'SELECT RDB$GENERATOR_NAME as gen
     1590                                        FROM RDB$GENERATORS
     1591                                        WHERE RDB$SYSTEM_FLAG = 0
     1592                                                AND RDB$GENERATOR_NAME = \'' . strtoupper($table_name) . "_GEN'";
     1593                                $result = $this->db->sql_query($sql);
     1594
     1595                                // does a generator exist?
     1596                                if ($row = $this->db->sql_fetchrow($result))
     1597                                {
     1598                                        $statements[] = "DROP GENERATOR {$row['gen']};";
     1599                                }
     1600                                $this->db->sql_freeresult($result);
     1601                        break;
     1602
     1603                        case 'oracle':
     1604                                $sql = 'SELECT A.REFERENCED_NAME
     1605                                        FROM USER_DEPENDENCIES A, USER_TRIGGERS B
     1606                                        WHERE A.REFERENCED_TYPE = \'SEQUENCE\'
     1607                                                AND A.NAME = B.TRIGGER_NAME
     1608                                                AND B.TABLE_NAME = \'' . strtoupper($table_name) . "'";
     1609                                $result = $this->db->sql_query($sql);
     1610
     1611                                // any sequences ref'd to this table's triggers?
     1612                                while ($row = $this->db->sql_fetchrow($result))
     1613                                {
     1614                                        $statements[] = "DROP SEQUENCE {$row['referenced_name']}";
     1615                                }
     1616                                $this->db->sql_freeresult($result);
     1617
     1618                        case 'postgres':
     1619                                // PGSQL does not "tightly" bind sequences and tables, we must guess...
     1620                                $sql = "SELECT relname
     1621                                        FROM pg_class
     1622                                        WHERE relkind = 'S'
     1623                                                AND relname = '{$table_name}_seq'";
     1624                                $result = $this->db->sql_query($sql);
     1625
     1626                                // We don't even care about storing the results. We already know the answer if we get rows back.
     1627                                if ($this->db->sql_fetchrow($result))
     1628                                {
     1629                                        $statements[] =  "DROP SEQUENCE {$table_name}_seq;\n";
     1630                                }
     1631                                $this->db->sql_freeresult($result);
     1632                        break;
     1633                }
     1634
     1635                return $this->_sql_run_sql($statements);
     1636        }
     1637
     1638        /**
     1639        * Add primary key
     1640        */
     1641        function sql_create_primary_key($table_name, $column, $inline = false)
     1642        {
     1643                $statements = array();
     1644
    10411645                switch ($this->sql_layer)
    10421646                {
    10431647                        case 'firebird':
    10441648                        case 'postgres':
     1649                        case 'mysql_40':
     1650                        case 'mysql_41':
    10451651                                $statements[] = 'ALTER TABLE ' . $table_name . ' ADD PRIMARY KEY (' . implode(', ', $column) . ')';
    10461652                        break;
     
    10551661                        break;
    10561662
    1057                         case 'mysql_40':
    1058                         case 'mysql_41':
    1059                                 $statements[] = 'ALTER TABLE ' . $table_name . ' ADD PRIMARY KEY (' . implode(', ', $column) . ')';
    1060                         break;
    1061 
    10621663                        case 'oracle':
    10631664                                $statements[] = 'ALTER TABLE ' . $table_name . 'add CONSTRAINT pk_' . $table_name . ' PRIMARY KEY (' . implode(', ', $column) . ')';
     
    10651666
    10661667                        case 'sqlite':
     1668
     1669                                if ($inline && $this->return_statements)
     1670                                {
     1671                                        return $column;
     1672                                }
     1673
    10671674                                $sql = "SELECT sql
    10681675                                        FROM sqlite_master
     
    12051812                                        $sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
    12061813                                                FROM RDB\$INDICES
    1207                                                 WHERE RDB\$RELATION_NAME = " . strtoupper($table_name) . "
     1814                                                WHERE RDB\$RELATION_NAME = '" . strtoupper($table_name) . "'
    12081815                                                        AND RDB\$UNIQUE_FLAG IS NULL
    12091816                                                        AND RDB\$FOREIGN_KEY IS NULL";
     
    12321839                                        $sql = "SELECT index_name
    12331840                                                FROM user_indexes
    1234                                                 WHERE table_name = '" . $table_name . "'
    1235                                                         AND generated = 'N'";
     1841                                                WHERE table_name = '" . strtoupper($table_name) . "'
     1842                                                        AND generated = 'N'
     1843                                                        AND uniqueness = 'NONUNIQUE'";
     1844                                        $col = 'index_name';
    12361845                                break;
    12371846
     
    12711880        * Change column type (not name!)
    12721881        */
    1273         function sql_column_change($table_name, $column_name, $column_data)
     1882        function sql_column_change($table_name, $column_name, $column_data, $inline = false)
    12741883        {
    12751884                $column_data = $this->sql_prepare_column_data($table_name, $column_name, $column_data);
     
    12801889                        case 'firebird':
    12811890                                // Change type...
    1282                                 $statements[] = 'ALTER TABLE "' . $table_name . '" ALTER COLUMN "' . $column_name . '" TYPE ' . ' ' . $column_data['column_type_sql'];
     1891                                if (!empty($column_data['column_type_sql_default']))
     1892                                {
     1893                                        $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" TYPE ' . ' ' . $column_data['column_type_sql_type'];
     1894                                        $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" SET DEFAULT ' . ' ' . $column_data['column_type_sql_default'];
     1895                                }
     1896                                else
     1897                                {
     1898                                        $statements[] = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN "' . strtoupper($column_name) . '" TYPE ' . ' ' . $column_data['column_type_sql_type'];
     1899                                }
    12831900                        break;
    12841901
    12851902                        case 'mssql':
    12861903                                $statements[] = 'ALTER TABLE [' . $table_name . '] ALTER COLUMN [' . $column_name . '] ' . $column_data['column_type_sql'];
     1904
     1905                                if (!empty($column_data['default']))
     1906                                {
     1907                                        // Using TRANSACT-SQL for this statement because we do not want to have colliding data if statements are executed at a later stage
     1908                                        $statements[] = "DECLARE @drop_default_name VARCHAR(100), @cmd VARCHAR(1000)
     1909                                                SET @drop_default_name =
     1910                                                        (SELECT so.name FROM sysobjects so
     1911                                                        JOIN sysconstraints sc ON so.id = sc.constid
     1912                                                        WHERE object_name(so.parent_obj) = '{$table_name}'
     1913                                                                AND so.xtype = 'D'
     1914                                                                AND sc.colid = (SELECT colid FROM syscolumns
     1915                                                                        WHERE id = object_id('{$table_name}')
     1916                                                                                AND name = '{$column_name}'))
     1917                                                IF @drop_default_name <> ''
     1918                                                BEGIN
     1919                                                        SET @cmd = 'ALTER TABLE [{$table_name}] DROP CONSTRAINT [' + @drop_default_name + ']'
     1920                                                        EXEC(@cmd)
     1921                                                END
     1922                                                SET @cmd = 'ALTER TABLE [{$table_name}] ADD CONSTRAINT [DF_{$table_name}_{$column_name}_1] {$column_data['default']} FOR [{$column_name}]'
     1923                                                EXEC(@cmd)";
     1924                                }
    12871925                        break;
    12881926
     
    13611999                        case 'sqlite':
    13622000
     2001                                if ($inline && $this->return_statements)
     2002                                {
     2003                                        return $column_name . ' ' . $column_data['column_type_sql'];
     2004                                }
     2005
    13632006                                $sql = "SELECT sql
    13642007                                        FROM sqlite_master
  • trunk/forum/includes/db/dbal.php

    r400 r702  
    33*
    44* @package dbal
    5 * @version $Id: dbal.php 9178 2008-12-06 11:11:10Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    236236        function sql_like_expression($expression)
    237237        {
    238                 $expression = str_replace(array('_', '%'), array("\_", "\%"), $expression);
    239                 $expression = str_replace(array(chr(0) . "\_", chr(0) . "\%"), array('_', '%'), $expression);
     238                $expression = utf8_str_replace(array('_', '%'), array("\_", "\%"), $expression);
     239                $expression = utf8_str_replace(array(chr(0) . "\_", chr(0) . "\%"), array('_', '%'), $expression);
    240240
    241241                return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\'');
     
    413413
    414414        /**
     415        * Run binary AND operator on DB column.
     416        * Results in sql statement: "{$column_name} & (1 << {$bit}) {$compare}"
     417        *
     418        * @param string $column_name The column name to use
     419        * @param int $bit The value to use for the AND operator, will be converted to (1 << $bit). Is used by options, using the number schema... 0, 1, 2...29
     420        * @param string $compare Any custom SQL code after the check (for example "= 0")
     421        */
     422        function sql_bit_and($column_name, $bit, $compare = '')
     423        {
     424                if (method_exists($this, '_sql_bit_and'))
     425                {
     426                        return $this->_sql_bit_and($column_name, $bit, $compare);
     427                }
     428
     429                return $column_name . ' & ' . (1 << $bit) . (($compare) ? ' ' . $compare : '');
     430        }
     431
     432        /**
     433        * Run binary OR operator on DB column.
     434        * Results in sql statement: "{$column_name} | (1 << {$bit}) {$compare}"
     435        *
     436        * @param string $column_name The column name to use
     437        * @param int $bit The value to use for the OR operator, will be converted to (1 << $bit). Is used by options, using the number schema... 0, 1, 2...29
     438        * @param string $compare Any custom SQL code after the check (for example "= 0")
     439        */
     440        function sql_bit_or($column_name, $bit, $compare = '')
     441        {
     442                if (method_exists($this, '_sql_bit_or'))
     443                {
     444                        return $this->_sql_bit_or($column_name, $bit, $compare);
     445                }
     446
     447                return $column_name . ' | ' . (1 << $bit) . (($compare) ? ' ' . $compare : '');
     448        }
     449
     450        /**
    415451        * Run more than one insert statement.
    416452        *
     
    436472                                if (!is_array($_sql_ary))
    437473                                {
    438                                         $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $sql_ary));
    439                                         return true;
     474                                        return $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $sql_ary));
    440475                                }
    441476
     
    448483                        }
    449484
    450                         $this->sql_query('INSERT INTO ' . $table . ' ' . ' (' . implode(', ', array_keys($sql_ary[0])) . ') VALUES ' . implode(', ', $ary));
     485                        return $this->sql_query('INSERT INTO ' . $table . ' ' . ' (' . implode(', ', array_keys($sql_ary[0])) . ') VALUES ' . implode(', ', $ary));
    451486                }
    452487                else
     
    459494                                }
    460495
    461                                 $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $ary));
     496                                $result = $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $ary));
     497
     498                                if (!$result)
     499                                {
     500                                        return false;
     501                                }
    462502                        }
    463503                }
  • trunk/forum/includes/db/firebird.php

    r400 r702  
    33*
    44* @package dbal
    5 * @version $Id: firebird.php 8967 2008-10-02 12:04:12Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2121/**
    2222* Firebird/Interbase Database Abstraction Layer
    23 * Minimum Requirement is Firebird 2.0
     23* Minimum Requirement is Firebird 2.1
    2424* @package dbal
    2525*/
     
    7373                }
    7474
    75                 return ($raw) ? '2.0' : 'Firebird/Interbase';
     75                return ($raw) ? '2.1' : 'Firebird/Interbase';
    7676        }
    7777
     
    447447        }
    448448
     449        function _sql_bit_and($column_name, $bit, $compare = '')
     450        {
     451                return 'BIN_AND(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
     452        }
     453
     454        function _sql_bit_or($column_name, $bit, $compare = '')
     455        {
     456                return 'BIN_OR(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
     457        }
     458
    449459        /**
    450460        * return sql error array
  • trunk/forum/includes/db/mysql.php

    r400 r702  
    33*
    44* @package dbal
    5 * @version $Id: mysql.php 8815 2008-09-04 13:37:01Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4545                $this->sql_layer = 'mysql4';
    4646
    47                 $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link);
     47                $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link);
    4848
    4949                if ($this->db_connect_id && $this->dbname != '')
     
    5252                        {
    5353                                // Determine what version we are using and if it natively supports UNICODE
    54                                 if (version_compare($this->sql_server_info(true), '4.1.3', '>='))
     54                                if (version_compare($this->sql_server_info(true), '4.1.0', '>='))
    5555                                {
    5656                                        @mysql_query("SET NAMES 'utf8'", $this->db_connect_id);
     
    342342                return $data;
    343343        }
    344        
     344
    345345        /**
    346346        * return sql error array
  • trunk/forum/includes/db/oracle.php

    r400 r702  
    33*
    44* @package dbal
    5 * @version $Id: oracle.php 9175 2008-12-05 11:18:59Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    137137        function _rewrite_where($where_clause)
    138138        {
    139                 preg_match_all('/\s*(AND|OR)?\s*([\w_.]++)\s*(?:(=|<[=>]?|>=?)\s*((?>\'(?>[^\']++|\'\')*+\'|[\d-.]+))|((NOT )?IN\s*\((?>\'(?>[^\']++|\'\')*+\',? ?|[\d-.]+,? ?)*+\)))/', $where_clause, $result, PREG_SET_ORDER);
     139                preg_match_all('/\s*(AND|OR)?\s*([\w_.()]++)\s*(?:(=|<[=>]?|>=?|LIKE)\s*((?>\'(?>[^\']++|\'\')*+\'|[\d-.()]+))|((NOT )?IN\s*\((?>\'(?>[^\']++|\'\')*+\',? ?|[\d-.]+,? ?)*+\)))/', $where_clause, $result, PREG_SET_ORDER);
    140140                $out = '';
    141141                foreach ($result as $val)
     
    256256                                if (strlen($query) > 4000)
    257257                                {
    258                                         if (preg_match('/^(INSERT INTO[^(]++)\\(([^()]+)\\) VALUES[^(]++\\((.*?)\\)$/s', $query, $regs))
     258                                        if (preg_match('/^(INSERT INTO[^(]++)\\(([^()]+)\\) VALUES[^(]++\\((.*?)\\)$/sU', $query, $regs))
    259259                                        {
    260260                                                if (strlen($regs[3]) > 4000)
    261261                                                {
    262262                                                        $cols = explode(', ', $regs[2]);
     263
    263264                                                        preg_match_all('/\'(?:[^\']++|\'\')*+\'|[\d-.]+/', $regs[3], $vals, PREG_PATTERN_ORDER);
     265
     266                                                        if (sizeof($cols) !== sizeof($vals))
     267                                                        {
     268                                                                // Try to replace some common data we know is from our restore script or from other sources
     269                                                                $regs[3] = str_replace("'||chr(47)||'", '/', $regs[3]);
     270                                                                $_vals = explode(', ', $regs[3]);
     271
     272                                                                $vals = array();
     273                                                                $is_in_val = false;
     274                                                                $i = 0;
     275                                                                $string = '';
     276
     277                                                                foreach ($_vals as $value)
     278                                                                {
     279                                                                        if (strpos($value, "'") === false && !$is_in_val)
     280                                                                        {
     281                                                                                $vals[$i++] = $value;
     282                                                                                continue;
     283                                                                        }
     284
     285                                                                        if (substr($value, -1) === "'")
     286                                                                        {
     287                                                                                $vals[$i] = $string . (($is_in_val) ? ', ' : '') . $value;
     288                                                                                $string = '';
     289                                                                                $is_in_val = false;
     290
     291                                                                                if ($vals[$i][0] !== "'")
     292                                                                                {
     293                                                                                        $vals[$i] = "''" . $vals[$i];
     294                                                                                }
     295                                                                                $i++;
     296                                                                                continue;
     297                                                                        }
     298                                                                        else
     299                                                                        {
     300                                                                                $string .= (($is_in_val) ? ', ' : '') . $value;
     301                                                                                $is_in_val = true;
     302                                                                        }
     303                                                                }
     304
     305                                                                if ($string)
     306                                                                {
     307                                                                        // New value if cols != value
     308                                                                        $vals[(sizeof($cols) !== sizeof($vals)) ? $i : $i - 1] .= $string;
     309                                                                }
     310
     311                                                                $vals = array(0 => $vals);
     312                                                        }
    264313
    265314                                                        $inserts = $vals[0];
     
    569618        }
    570619
     620        function _sql_bit_and($column_name, $bit, $compare = '')
     621        {
     622                return 'BITAND(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
     623        }
     624
     625        function _sql_bit_or($column_name, $bit, $compare = '')
     626        {
     627                return 'BITOR(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
     628        }
     629
    571630        /**
    572631        * return sql error array
  • trunk/forum/includes/db/postgres.php

    r400 r702  
    33*
    44* @package dbal
    5 * @version $Id: postgres.php 8814 2008-09-04 12:01:47Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2727{
    2828        var $last_query_text = '';
    29        
     29
    3030        /**
    3131        * Connect to server
     
    5656                                $connect_string .= "host=$sqlserver ";
    5757                        }
    58                
     58
    5959                        if ($port)
    6060                        {
     
    225225                if ($total == 0)
    226226                {
    227                         $total = -1;
     227                        $total = 'ALL';
    228228                }
    229229
  • trunk/forum/includes/diff/diff.php

    r400 r702  
    33*
    44* @package diff
    5 * @version $Id: diff.php 8765 2008-08-16 22:18:25Z aptx $
     5* @version $Id$
    66* @copyright (c) 2006 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    1818
    1919/**
    20 * Code from pear.php.net, Text_Diff-1.0.0 package
     20* Code from pear.php.net, Text_Diff-1.1.0 package
    2121* http://pear.php.net/package/Text_Diff/
    2222*
     
    5959        {
    6060                return $this->_edits;
     61        }
     62
     63        /**
     64        * returns the number of new (added) lines in a given diff.
     65        *
     66        * @since Text_Diff 1.1.0
     67        *
     68        * @return integer The number of new lines
     69        */
     70        function count_added_lines()
     71        {
     72                $count = 0;
     73
     74                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     75                {
     76                        $edit = $this->_edits[$i];
     77
     78                        if (is_a($edit, 'diff_op_add') || is_a($edit, 'diff_op_change'))
     79                        {
     80                                $count += $edit->nfinal();
     81                        }
     82                }
     83                return $count;
     84        }
     85
     86        /**
     87        * Returns the number of deleted (removed) lines in a given diff.
     88        *
     89        * @since Text_Diff 1.1.0
     90        *
     91        * @return integer The number of deleted lines
     92        */
     93        function count_deleted_lines()
     94        {
     95                $count = 0;
     96
     97                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     98                {
     99                        $edit = $this->_edits[$i];
     100
     101                        if (is_a($edit, 'diff_op_delete') || is_a($edit, 'diff_op_change'))
     102                        {
     103                                $count += $edit->norig();
     104                        }
     105                }
     106                return $count;
    61107        }
    62108
     
    87133                $rev->_edits = array();
    88134
    89                 foreach ($this->_edits as $edit)
    90                 {
     135                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     136                {
     137                        $edit = $this->_edits[$i];
    91138                        $rev->_edits[] = $edit->reverse();
    92139                }
     
    102149        function is_empty()
    103150        {
    104                 foreach ($this->_edits as $edit)
    105                 {
    106                         if (!is_a($edit, 'diff_op_copy'))
    107                         {
     151                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     152                {
     153                        $edit = $this->_edits[$i];
     154
     155                        // skip diff_op_copy
     156                        if (is_a($edit, 'diff_op_copy'))
     157                        {
     158                                continue;
     159                        }
     160
     161                        if (is_a($edit, 'diff_op_delete') || is_a($edit, 'diff_op_add'))
     162                        {
     163                                $orig = $edit->orig;
     164                                $final = $edit->final;
     165
     166                                // We can simplify one case where the array is usually supposed to be empty...
     167                                if (sizeof($orig) == 1 && trim($orig[0]) === '') $orig = array();
     168                                if (sizeof($final) == 1 && trim($final[0]) === '') $final = array();
     169
     170                                if (!$orig && !$final)
     171                                {
     172                                        continue;
     173                                }
     174
    108175                                return false;
    109176                        }
    110                 }
     177
     178                        return false;
     179                }
     180
    111181                return true;
    112182        }
     
    123193                $lcs = 0;
    124194
    125                 foreach ($this->_edits as $edit)
    126                 {
     195                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     196                {
     197                        $edit = $this->_edits[$i];
     198
    127199                        if (is_a($edit, 'diff_op_copy'))
    128200                        {
     
    144216                $lines = array();
    145217
    146                 foreach ($this->_edits as $edit)
    147                 {
     218                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     219                {
     220                        $edit = $this->_edits[$i];
     221
    148222                        if ($edit->orig)
    149223                        {
     
    165239                $lines = array();
    166240
    167                 foreach ($this->_edits as $edit)
    168                 {
     241                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     242                {
     243                        $edit = $this->_edits[$i];
     244
    169245                        if ($edit->final)
    170246                        {
     
    217293                $prevtype = null;
    218294
    219                 foreach ($this->_edits as $edit)
    220                 {
     295                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     296                {
     297                        $edit = $this->_edits[$i];
     298
    221299                        if ($prevtype == get_class($edit))
    222300                        {
     
    415493        * @param array $final2  The second version to compare to.
    416494        */
    417         function diff3(&$orig, &$final1, &$final2)
     495        function diff3(&$orig, &$final1, &$final2, $preserve_cr = true)
    418496        {
    419497                $diff_engine = new diff_engine();
    420498
    421                 $diff_1 = $diff_engine->diff($orig, $final1);
    422                 $diff_2 = $diff_engine->diff($orig, $final2);
    423 
    424                 unset($engine);
     499                $diff_1 = $diff_engine->diff($orig, $final1, $preserve_cr);
     500                $diff_2 = $diff_engine->diff($orig, $final2, $preserve_cr);
     501
     502                unset($diff_engine);
    425503
    426504                $this->_edits = $this->_diff3($diff_1, $diff_2);
     
    428506
    429507        /**
    430         * Return merged output
     508        * Return number of conflicts
     509        */
     510        function get_num_conflicts()
     511        {
     512                $conflicts = 0;
     513
     514                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     515                {
     516                        $edit = $this->_edits[$i];
     517
     518                        if ($edit->is_conflict())
     519                        {
     520                                $conflicts++;
     521                        }
     522                }
     523
     524                return $conflicts;
     525        }
     526
     527        /**
     528        * Get conflicts content for download. This is generally a merged file, but preserving conflicts and adding explanations to it.
     529        * A user could then go through this file, search for the conflicts and changes the code accordingly.
    431530        *
    432531        * @param string $label1 the cvs file version/label from the original set of lines
    433532        * @param string $label2 the cvs file version/label from the new set of lines
    434533        * @param string $label_sep the explanation between label1 and label2 - more of a helper for the user
    435         * @param bool $get_conflicts if set to true only the number of conflicts is returned
    436         * @param bool $merge_new if set to true the merged output will have the new file contents on a conflicting merge
    437534        *
    438535        * @return mixed the merged output
    439536        */
    440         function merged_output($label1 = 'CURRENT_FILE', $label2 = 'NEW_FILE', $label_sep = 'DIFF_SEP_EXPLAIN', $get_conflicts = false, $merge_new = false)
     537        function get_conflicts_content($label1 = 'CURRENT_FILE', $label2 = 'NEW_FILE', $label_sep = 'DIFF_SEP_EXPLAIN')
    441538        {
    442539                global $user;
    443 
    444                 if ($get_conflicts)
    445                 {
    446                         foreach ($this->_edits as $edit)
    447                         {
    448                                 if ($edit->is_conflict())
    449                                 {
    450                                         $this->_conflicting_blocks++;
    451                                 }
    452                         }
    453 
    454                         return $this->_conflicting_blocks;
    455                 }
    456540
    457541                $label1 = (!empty($user->lang[$label1])) ? $user->lang[$label1] : $label1;
     
    461545                $lines = array();
    462546
    463                 foreach ($this->_edits as $edit)
    464                 {
     547                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     548                {
     549                        $edit = $this->_edits[$i];
     550
    465551                        if ($edit->is_conflict())
    466552                        {
    467                                 if (!$merge_new)
    468                                 {
    469                                         $lines = array_merge($lines, array('<<<<<<<' . ($label1 ? ' ' . $label1 : '')), $edit->final1, array('=======' . ($label_sep ? ' ' . $label_sep : '')), $edit->final2, array('>>>>>>>' . ($label2 ? ' ' . $label2 : '')));
    470                                 }
    471                                 else
    472                                 {
    473                                         $lines = array_merge($lines, $edit->final1);
    474                                 }
     553                                // Start conflict label
     554                                $label_start    = array('<<<<<<< ' . $label1);
     555                                $label_mid              = array('======= ' . $label_sep);
     556                                $label_end              = array('>>>>>>> ' . $label2);
     557
     558                                $lines = array_merge($lines, $label_start, $edit->final1, $label_mid, $edit->final2, $label_end);
    475559                                $this->_conflicting_blocks++;
    476560                        }
     
    485569
    486570        /**
     571        * Return merged output (used by the renderer)
     572        *
     573        * @return mixed the merged output
     574        */
     575        function merged_output()
     576        {
     577                return $this->get_conflicts_content();
     578        }
     579
     580        /**
    487581        * Merge the output and use the new file code for conflicts
    488582        */
     
    491585                $lines = array();
    492586
    493                 foreach ($this->_edits as $edit)
    494                 {
     587                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     588                {
     589                        $edit = $this->_edits[$i];
     590
    495591                        if ($edit->is_conflict())
    496592                        {
     
    513609                $lines = array();
    514610
    515                 foreach ($this->_edits as $edit)
    516                 {
     611                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     612                {
     613                        $edit = $this->_edits[$i];
     614
    517615                        if ($edit->is_conflict())
    518616                        {
     
    535633                $conflicts = array();
    536634
    537                 foreach ($this->_edits as $edit)
    538                 {
     635                for ($i = 0, $size = sizeof($this->_edits); $i < $size; $i++)
     636                {
     637                        $edit = $this->_edits[$i];
     638
    539639                        if ($edit->is_conflict())
    540640                        {
     
    660760                if (!isset($this->_merged))
    661761                {
     762                        // Prepare the arrays before we compare them. ;)
     763                        $this->solve_prepare();
     764
    662765                        if ($this->final1 === $this->final2)
    663766                        {
     
    674777                        else
    675778                        {
     779                                // The following tries to aggressively solve conflicts...
    676780                                $this->_merged = false;
     781                                $this->solve_conflict();
    677782                        }
    678783                }
     
    684789        {
    685790                return ($this->merged() === false) ? true : false;
     791        }
     792
     793        /**
     794        * Function to prepare the arrays for comparing - we want to skip over newline changes
     795        * @author acydburn
     796        */
     797        function solve_prepare()
     798        {
     799                // We can simplify one case where the array is usually supposed to be empty...
     800                if (sizeof($this->orig) == 1 && trim($this->orig[0]) === '') $this->orig = array();
     801                if (sizeof($this->final1) == 1 && trim($this->final1[0]) === '') $this->final1 = array();
     802                if (sizeof($this->final2) == 1 && trim($this->final2[0]) === '') $this->final2 = array();
     803
     804                // Now we only can have the case where the only difference between arrays are newlines, so compare all cases
     805
     806                // First, some strings we can compare...
     807                $orig = $final1 = $final2 = '';
     808
     809                foreach ($this->orig as $null => $line) $orig .= trim($line);
     810                foreach ($this->final1 as $null => $line) $final1 .= trim($line);
     811                foreach ($this->final2 as $null => $line) $final2 .= trim($line);
     812
     813                // final1 === final2
     814                if ($final1 === $final2)
     815                {
     816                        // We preserve the part which will be used in the merge later
     817                        $this->final2 = $this->final1;
     818                }
     819                // final1 === orig
     820                else if ($final1 === $orig)
     821                {
     822                        // Here it does not really matter what we choose, but we will use the new code
     823                        $this->orig = $this->final1;
     824                }
     825                // final2 === orig
     826                else if ($final2 === $orig)
     827                {
     828                        // Here it does not really matter too (final1 will be used), but we will use the new code
     829                        $this->orig = $this->final2;
     830                }
     831        }
     832
     833        /**
     834        * Find code portions from $orig in $final1 and use $final2 as merged instance if provided
     835        * @author acydburn
     836        */
     837        function _compare_conflict_seq($orig, $final1, $final2 = false)
     838        {
     839                $result = array('merge_found' => false, 'merge' => array());
     840
     841                $_orig = &$this->$orig;
     842                $_final1 = &$this->$final1;
     843
     844                // Ok, we basically search for $orig in $final1
     845                $compare_seq = sizeof($_orig);
     846
     847                // Go through the conflict code
     848                for ($i = 0, $j = 0, $size = sizeof($_final1); $i < $size; $i++, $j = $i)
     849                {
     850                        $line = $_final1[$i];
     851                        $skip = 0;
     852
     853                        for ($x = 0; $x < $compare_seq; $x++)
     854                        {
     855                                // Try to skip all matching lines
     856                                if (trim($line) === trim($_orig[$x]))
     857                                {
     858                                        $line = (++$j < $size) ? $_final1[$j] : $line;
     859                                        $skip++;
     860                                }
     861                        }
     862
     863                        if ($skip === $compare_seq)
     864                        {
     865                                $result['merge_found'] = true;
     866
     867                                if ($final2 !== false)
     868                                {
     869                                        $result['merge'] = array_merge($result['merge'], $this->$final2);
     870                                }
     871                                $i += ($skip - 1);
     872                        }
     873                        else if ($final2 !== false)
     874                        {
     875                                $result['merge'][] = $line;
     876                        }
     877                }
     878
     879                return $result;
     880        }
     881
     882        /**
     883        * Tries to solve conflicts aggressively based on typical "assumptions"
     884        * @author acydburn
     885        */
     886        function solve_conflict()
     887        {
     888                $this->_merged = false;
     889
     890                // CASE ONE: orig changed into final2, but modified/unknown code in final1.
     891                // IF orig is found "as is" in final1 we replace the code directly in final1 and populate this as final2/merge
     892                if (sizeof($this->orig) && sizeof($this->final2))
     893                {
     894                        $result = $this->_compare_conflict_seq('orig', 'final1', 'final2');
     895
     896                        if ($result['merge_found'])
     897                        {
     898                                $this->final2 = $result['merge'];
     899                                $this->_merged = &$this->final2;
     900                                return;
     901                        }
     902
     903                        $result = $this->_compare_conflict_seq('final2', 'final1');
     904
     905                        if ($result['merge_found'])
     906                        {
     907                                $this->_merged = &$this->final1;
     908                                return;
     909                        }
     910
     911                        // Try to solve $Id$ issues. ;)
     912                        if (sizeof($this->orig) == 1 && sizeof($this->final1) == 1 && sizeof($this->final2) == 1)
     913                        {
     914                                $match = '#^' . preg_quote('* @version $Id: ', '#') . '[a-z\._\- ]+[0-9]+ [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9\:Z]+ [a-z0-9_\- ]+\$$#';
     915
     916                                if (preg_match($match, $this->orig[0]) && preg_match($match, $this->final1[0]) && preg_match($match, $this->final2[0]))
     917                                {
     918                                        $this->_merged = &$this->final2;
     919                                        return;
     920                                }
     921                        }
     922
     923                        $second_run = false;
     924
     925                        // Try to solve issues where the only reason why the above did not work is a newline being removed in the final1 code but exist in the orig/final2 code
     926                        if (trim($this->orig[0]) === '' && trim($this->final2[0]) === '')
     927                        {
     928                                unset($this->orig[0], $this->final2[0]);
     929                                $this->orig = array_values($this->orig);
     930                                $this->final2 = array_values($this->final2);
     931
     932                                $second_run = true;
     933                        }
     934
     935                        // The same is true for a line at the end. ;)
     936                        if (sizeof($this->orig) && sizeof($this->final2) && sizeof($this->orig) === sizeof($this->final2) && trim($this->orig[sizeof($this->orig)-1]) === '' && trim($this->final2[sizeof($this->final2)-1]) === '')
     937                        {
     938                                unset($this->orig[sizeof($this->orig)-1], $this->final2[sizeof($this->final2)-1]);
     939                                $this->orig = array_values($this->orig);
     940                                $this->final2 = array_values($this->final2);
     941
     942                                $second_run = true;
     943                        }
     944
     945                        if ($second_run)
     946                        {
     947                                $result = $this->_compare_conflict_seq('orig', 'final1', 'final2');
     948
     949                                if ($result['merge_found'])
     950                                {
     951                                        $this->final2 = $result['merge'];
     952                                        $this->_merged = &$this->final2;
     953                                        return;
     954                                }
     955
     956                                $result = $this->_compare_conflict_seq('final2', 'final1');
     957
     958                                if ($result['merge_found'])
     959                                {
     960                                        $this->_merged = &$this->final1;
     961                                        return;
     962                                }
     963                        }
     964
     965                        return;
     966                }
     967
     968                // CASE TWO: Added lines from orig to final2 but final1 had added lines too. Just merge them.
     969                if (!sizeof($this->orig) && $this->final1 !== $this->final2 && sizeof($this->final1) && sizeof($this->final2))
     970                {
     971                        $result = $this->_compare_conflict_seq('final2', 'final1');
     972
     973                        if ($result['merge_found'])
     974                        {
     975                                $this->final2 = $this->final1;
     976                                $this->_merged = &$this->final1;
     977                        }
     978                        else
     979                        {
     980                                $result = $this->_compare_conflict_seq('final1', 'final2');
     981
     982                                if (!$result['merge_found'])
     983                                {
     984                                        $this->final2 = array_merge($this->final1, $this->final2);
     985                                        $this->_merged = &$this->final2;
     986                                }
     987                                else
     988                                {
     989                                        $this->final2 = $this->final1;
     990                                        $this->_merged = &$this->final1;
     991                                }
     992                        }
     993
     994                        return;
     995                }
     996
     997                // CASE THREE: Removed lines (orig has the to-remove line(s), but final1 has additional lines which does not need to be removed). Just remove orig from final1 and then use final1 as final2/merge
     998                if (!sizeof($this->final2) && sizeof($this->orig) && sizeof($this->final1) && $this->orig !== $this->final1)
     999                {
     1000                        $result = $this->_compare_conflict_seq('orig', 'final1');
     1001
     1002                        if (!$result['merge_found'])
     1003                        {
     1004                                return;
     1005                        }
     1006
     1007                        // First of all, try to find the code in orig in final1. ;)
     1008                        $compare_seq = sizeof($this->orig);
     1009                        $begin = $end = -1;
     1010                        $j = 0;
     1011
     1012                        for ($i = 0, $size = sizeof($this->final1); $i < $size; $i++)
     1013                        {
     1014                                $line = $this->final1[$i];
     1015
     1016                                if (trim($line) === trim($this->orig[$j]))
     1017                                {
     1018                                        // Mark begin
     1019                                        if ($begin === -1)
     1020                                        {
     1021                                                $begin = $i;
     1022                                        }
     1023
     1024                                        // End is always $i, the last found line
     1025                                        $end = $i;
     1026
     1027                                        if (isset($this->orig[$j+1]))
     1028                                        {
     1029                                                $j++;
     1030                                        }
     1031                                }
     1032                        }
     1033
     1034                        if ($begin !== -1 && $begin + ($compare_seq - 1) == $end)
     1035                        {
     1036                                foreach ($this->final1 as $i => $line)
     1037                                {
     1038                                        if ($i < $begin || $i > $end)
     1039                                        {
     1040                                                $merged[] = $line;
     1041                                        }
     1042                                }
     1043
     1044                                $this->final2 = $merged;
     1045                                $this->_merged = &$this->final2;
     1046                        }
     1047
     1048                        return;
     1049                }
     1050
     1051                return;
    6861052        }
    6871053}
  • trunk/forum/includes/diff/engine.php

    r400 r702  
    33*
    44* @package diff
    5 * @version $Id: engine.php 8765 2008-08-16 22:18:25Z aptx $
     5* @version $Id$
    66* @copyright (c) 2006 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    1818
    1919/**
    20 * Code from pear.php.net, Text_Diff-1.0.0 package
     20* Code from pear.php.net, Text_Diff-1.1.0 package
    2121* http://pear.php.net/package/Text_Diff/ (native engine)
    2222*
     
    5050class diff_engine
    5151{
     52        /**
     53        * If set to true we trim all lines before we compare them. This ensures that sole space/tab changes do not trigger diffs.
     54        */
     55        var $skip_whitespace_changes = true;
     56
    5257        function diff(&$from_lines, &$to_lines, $preserve_cr = true)
    5358        {
     
    8691                for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++)
    8792                {
    88                         if ($from_lines[$skip] !== $to_lines[$skip])
     93                        if (trim($from_lines[$skip]) !== trim($to_lines[$skip]))
    8994                        {
    9095                                break;
     
    99104                for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++)
    100105                {
    101                         if ($from_lines[$xi] !== $to_lines[$yi])
     106                        if (trim($from_lines[$xi]) !== trim($to_lines[$yi]))
    102107                        {
    103108                                break;
     
    109114                for ($xi = $skip; $xi < $n_from - $endskip; $xi++)
    110115                {
    111                         $xhash[$from_lines[$xi]] = 1;
     116                        if ($this->skip_whitespace_changes) $xhash[trim($from_lines[$xi])] = 1; else $xhash[$from_lines[$xi]] = 1;
    112117                }
    113118
    114119                for ($yi = $skip; $yi < $n_to - $endskip; $yi++)
    115120                {
    116                         $line = $to_lines[$yi];
     121                        $line = ($this->skip_whitespace_changes) ? trim($to_lines[$yi]) : $to_lines[$yi];
    117122
    118123                        if (($this->ychanged[$yi] = empty($xhash[$line])))
     
    127132                for ($xi = $skip; $xi < $n_from - $endskip; $xi++)
    128133                {
    129                         $line = $from_lines[$xi];
     134                        $line = ($this->skip_whitespace_changes) ? trim($from_lines[$xi]) : $from_lines[$xi];
    130135
    131136                        if (($this->xchanged[$xi] = empty($yhash[$line])))
     
    141146
    142147                // Merge edits when possible.
    143                 $this->_shift_boundaries($from_lines, $this->xchanged, $this->ychanged);
    144                 $this->_shift_boundaries($to_lines, $this->ychanged, $this->xchanged);
     148                if ($this->skip_whitespace_changes)
     149                {
     150                        $from_lines_clean = array_map('trim', $from_lines);
     151                        $to_lines_clean = array_map('trim', $to_lines);
     152
     153                        $this->_shift_boundaries($from_lines_clean, $this->xchanged, $this->ychanged);
     154                        $this->_shift_boundaries($to_lines_clean, $this->ychanged, $this->xchanged);
     155
     156                        unset($from_lines_clean, $to_lines_clean);
     157                }
     158                else
     159                {
     160                        $this->_shift_boundaries($from_lines, $this->xchanged, $this->ychanged);
     161                        $this->_shift_boundaries($to_lines, $this->ychanged, $this->xchanged);
     162                }
    145163
    146164                // Compute the edit operations.
  • trunk/forum/includes/diff/renderer.php

    r400 r702  
    33*
    44* @package diff
    5 * @version $Id: renderer.php 8766 2008-08-16 22:24:54Z aptx $
     5* @version $Id$
    66* @copyright (c) 2006 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    1818
    1919/**
    20 * Code from pear.php.net, Text_Diff-1.0.0 package
     20* Code from pear.php.net, Text_Diff-1.1.0 package
    2121* http://pear.php.net/package/Text_Diff/
    2222*
     
    537537        function get_diff_content($diff)
    538538        {
    539                 return '<textarea style="height: 290px;" class="full">' . htmlspecialchars($this->render($diff)) . '</textarea>';
     539                return '<textarea style="height: 290px;" rows="15" cols="76" class="full">' . htmlspecialchars($this->render($diff)) . '</textarea>';
    540540        }
    541541
  • 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';
  • trunk/forum/includes/functions_admin.php

    r400 r702  
    33*
    44* @package acp
    5 * @version $Id: functions_admin.php 9065 2008-11-13 17:32:55Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    1818
    1919/**
    20 * Recalculate Binary Tree
    21 function recalc_btree($sql_id, $sql_table, $module_class = '')
     20* Recalculate Nested Sets
     21*
     22* @param int    $new_id first left_id (should start with 1)
     23* @param string $pkey   primary key-column (containing the id for the parent_id of the children)
     24* @param string $table  constant or fullname of the table
     25* @param int    $parent_id parent_id of the current set (default = 0)
     26* @param array  $where  contains strings to compare closer on the where statement (additional)
     27*
     28* @author EXreaction
     29*/
     30function recalc_nested_sets(&$new_id, $pkey, $table, $parent_id = 0, $where = array())
    2231{
    2332        global $db;
    2433
    25         if (!$sql_id || !$sql_table)
    26         {
    27                 return;
    28         }
    29 
    30         $sql_where = ($module_class) ? " WHERE module_class = '" . $db->sql_escape($module_class) . "'" : '';
    31 
    32         // Reset to minimum possible left and right id
    33         $sql = "SELECT MIN(left_id) as min_left_id, MIN(right_id) as min_right_id
    34                 FROM $sql_table
    35                 $sql_where";
     34        $sql = 'SELECT *
     35                FROM ' . $table . '
     36                WHERE parent_id = ' . (int) $parent_id .
     37                ((!empty($where)) ? ' AND ' . implode(' AND ', $where) : '') . '
     38                ORDER BY left_id ASC';
    3639        $result = $db->sql_query($sql);
    37         $row = $db->sql_fetchrow($result);
     40        while ($row = $db->sql_fetchrow($result))
     41        {
     42                // First we update the left_id for this module
     43                if ($row['left_id'] != $new_id)
     44                {
     45                        $db->sql_query('UPDATE ' . $table . ' SET ' . $db->sql_build_array('UPDATE', array('left_id' => $new_id)) . " WHERE $pkey = {$row[$pkey]}");
     46                }
     47                $new_id++;
     48
     49                // Then we go through any children and update their left/right id's
     50                recalc_nested_sets($new_id, $pkey, $table, $row[$pkey], $where);
     51
     52                // Then we come back and update the right_id for this module
     53                if ($row['right_id'] != $new_id)
     54                {
     55                        $db->sql_query('UPDATE ' . $table . ' SET ' . $db->sql_build_array('UPDATE', array('right_id' => $new_id)) . " WHERE $pkey = {$row[$pkey]}");
     56                }
     57                $new_id++;
     58        }
    3859        $db->sql_freeresult($result);
    39 
    40         $substract = (int) (min($row['min_left_id'], $row['min_right_id']) - 1);
    41 
    42         if ($substract > 0)
    43         {
    44                 $sql = "UPDATE $sql_table
    45                         SET left_id = left_id - $substract, right_id = right_id - $substract
    46                         $sql_where";
    47                 $db->sql_query($sql);
    48         }
    49 
    50         $sql = "SELECT $sql_id, parent_id, left_id, right_id
    51                 FROM $sql_table
    52                 $sql_where
    53                 ORDER BY left_id ASC, parent_id ASC, $sql_id ASC";
    54         $f_result = $db->sql_query($sql);
    55 
    56         while ($item_data = $db->sql_fetchrow($f_result))
    57         {
    58                 if ($item_data['parent_id'])
    59                 {
    60                         $sql = "SELECT left_id, right_id
    61                                 FROM $sql_table
    62                                 $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . "
    63                                         $sql_id = {$item_data['parent_id']}";
    64                         $result = $db->sql_query($sql);
    65 
    66                         if (!$row = $db->sql_fetchrow($result))
    67                         {
    68                                 $sql = "UPDATE $sql_table SET parent_id = 0 WHERE $sql_id = " . $item_data[$sql_id];
    69                                 $db->sql_query($sql);
    70                         }
    71                         $db->sql_freeresult($result);
    72 
    73                         $sql = "UPDATE $sql_table
    74                                 SET left_id = left_id + 2, right_id = right_id + 2
    75                                 $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . "
    76                                         left_id > {$row['right_id']}";
    77                         $db->sql_query($sql);
    78 
    79                         $sql = "UPDATE $sql_table
    80                                 SET right_id = right_id + 2
    81                                 $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . "
    82                                         {$row['left_id']} BETWEEN left_id AND right_id";
    83                         $db->sql_query($sql);
    84 
    85                         $item_data['left_id'] = $row['right_id'];
    86                         $item_data['right_id'] = $row['right_id'] + 1;
    87                 }
    88                 else
    89                 {
    90                         $sql = "SELECT MAX(right_id) AS right_id
    91                                 FROM $sql_table
    92                                 $sql_where";
    93                         $result = $db->sql_query($sql);
    94                         $row = $db->sql_fetchrow($result);
    95                         $db->sql_freeresult($result);
    96 
    97                         $item_data['left_id'] = $row['right_id'] + 1;
    98                         $item_data['right_id'] = $row['right_id'] + 2;
    99                 }
    100 
    101                 $sql = "UPDATE $sql_table
    102                         SET left_id = {$item_data['left_id']}, right_id = {$item_data['right_id']}
    103                         WHERE $sql_id = " . $item_data[$sql_id];
    104                 $db->sql_query($sql);
    105         }
    106         $db->sql_freeresult($f_result);
    10760}
    108 */
    10961
    11062/**
     
    11567        global $db, $user, $auth;
    11668
    117         $acl = ($ignore_acl) ? '' : (($only_acl_post) ? 'f_post' : array('f_list', 'a_forum', 'a_forumadd', 'a_forumdel'));
    118 
    11969        // This query is identical to the jumpbox one
    120         $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
     70        $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, forum_flags, forum_options, left_id, right_id
    12171                FROM ' . FORUMS_TABLE . '
    12272                ORDER BY left_id ASC';
     
    14797                $disabled = false;
    14898
    149                 if ($acl && !$auth->acl_gets($acl, $row['forum_id']))
    150                 {
    151                         // List permission?
    152                         if ($auth->acl_get('f_list', $row['forum_id']))
     99                if (!$ignore_acl && $auth->acl_get('f_list', $row['forum_id']))
     100                {
     101                        if ($only_acl_post && !$auth->acl_get('f_post', $row['forum_id']) || (!$auth->acl_get('m_approve', $row['forum_id']) && !$auth->acl_get('f_noapprove', $row['forum_id'])))
    153102                        {
    154103                                $disabled = true;
    155104                        }
    156                         else
    157                         {
    158                                 continue;
    159                         }
     105                        else if (!$only_acl_post && !$auth->acl_gets(array('f_list', 'a_forum', 'a_forumadd', 'a_forumdel'), $row['forum_id']))
     106                        {
     107                                $disabled = true;
     108                        }
     109                }
     110                else if (!$ignore_acl)
     111                {
     112                        continue;
    160113                }
    161114
     
    303256                if ($acl_list == '' || ($acl_list != '' && $auth->acl_gets($acl_list, $row['forum_id'])))
    304257                {
    305                         $rowset[] = ($id_only) ? $row['forum_id'] : $row;
     258                        $rowset[] = ($id_only) ? (int) $row['forum_id'] : $row;
    306259                }
    307260        }
     
    356309
    357310/**
     311* Copies permissions from one forum to others
     312*
     313* @param int    $src_forum_id           The source forum we want to copy permissions from
     314* @param array  $dest_forum_ids         The destination forum(s) we want to copy to
     315* @param bool   $clear_dest_perms       True if destination permissions should be deleted
     316* @param bool   $add_log                        True if log entry should be added
     317*
     318* @return bool                                          False on error
     319*
     320* @author bantu
     321*/
     322function copy_forum_permissions($src_forum_id, $dest_forum_ids, $clear_dest_perms = true, $add_log = true)
     323{
     324        global $db;
     325
     326        // Only one forum id specified
     327        if (!is_array($dest_forum_ids))
     328        {
     329                $dest_forum_ids = array($dest_forum_ids);
     330        }
     331
     332        // Make sure forum ids are integers
     333        $src_forum_id = (int) $src_forum_id;
     334        $dest_forum_ids = array_map('intval', $dest_forum_ids);
     335
     336        // No source forum or no destination forums specified
     337        if (empty($src_forum_id) || empty($dest_forum_ids))
     338        {
     339                return false;
     340        }
     341
     342        // Check if source forum exists
     343        $sql = 'SELECT forum_name
     344                FROM ' . FORUMS_TABLE . '
     345                WHERE forum_id = ' . $src_forum_id;
     346        $result = $db->sql_query($sql);
     347        $src_forum_name = $db->sql_fetchfield('forum_name');
     348        $db->sql_freeresult($result);
     349
     350        // Source forum doesn't exist
     351        if (empty($src_forum_name))
     352        {
     353                return false;
     354        }
     355
     356        // Check if destination forums exists
     357        $sql = 'SELECT forum_id, forum_name
     358                FROM ' . FORUMS_TABLE . '
     359                WHERE ' . $db->sql_in_set('forum_id', $dest_forum_ids);
     360        $result = $db->sql_query($sql);
     361
     362        $dest_forum_ids = $dest_forum_names = array();
     363        while ($row = $db->sql_fetchrow($result))
     364        {
     365                $dest_forum_ids[]       = (int) $row['forum_id'];
     366                $dest_forum_names[]     = $row['forum_name'];
     367        }
     368        $db->sql_freeresult($result);
     369
     370        // No destination forum exists
     371        if (empty($dest_forum_ids))
     372        {
     373                return false;
     374        }
     375
     376        // From the mysql documentation:
     377        // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear
     378        // in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
     379        // Due to this we stay on the safe side if we do the insertion "the manual way"
     380
     381        // Rowsets we're going to insert
     382        $users_sql_ary = $groups_sql_ary = array();
     383
     384        // Query acl users table for source forum data
     385        $sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
     386                FROM ' . ACL_USERS_TABLE . '
     387                WHERE forum_id = ' . $src_forum_id;
     388        $result = $db->sql_query($sql);
     389
     390        while ($row = $db->sql_fetchrow($result))
     391        {
     392                $row = array(
     393                        'user_id'                       => (int) $row['user_id'],
     394                        'auth_option_id'        => (int) $row['auth_option_id'],
     395                        'auth_role_id'          => (int) $row['auth_role_id'],
     396                        'auth_setting'          => (int) $row['auth_setting'],
     397                );
     398
     399                foreach ($dest_forum_ids as $dest_forum_id)
     400                {
     401                        $users_sql_ary[] = $row + array('forum_id' => $dest_forum_id);
     402                }
     403        }
     404        $db->sql_freeresult($result);
     405
     406        // Query acl groups table for source forum data
     407        $sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
     408                FROM ' . ACL_GROUPS_TABLE . '
     409                WHERE forum_id = ' . $src_forum_id;
     410        $result = $db->sql_query($sql);
     411
     412        while ($row = $db->sql_fetchrow($result))
     413        {
     414                $row = array(
     415                        'group_id'                      => (int) $row['group_id'],
     416                        'auth_option_id'        => (int) $row['auth_option_id'],
     417                        'auth_role_id'          => (int) $row['auth_role_id'],
     418                        'auth_setting'          => (int) $row['auth_setting'],
     419                );
     420
     421                foreach ($dest_forum_ids as $dest_forum_id)
     422                {
     423                        $groups_sql_ary[] = $row + array('forum_id' => $dest_forum_id);
     424                }
     425        }
     426        $db->sql_freeresult($result);
     427
     428        $db->sql_transaction('begin');
     429
     430        // Clear current permissions of destination forums
     431        if ($clear_dest_perms)
     432        {
     433                $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
     434                        WHERE ' . $db->sql_in_set('forum_id', $dest_forum_ids);
     435                $db->sql_query($sql);
     436
     437                $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
     438                        WHERE ' . $db->sql_in_set('forum_id', $dest_forum_ids);
     439                $db->sql_query($sql);
     440        }
     441
     442        $db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
     443        $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
     444
     445        if ($add_log)
     446        {
     447                add_log('admin', 'LOG_FORUM_COPIED_PERMISSIONS', $src_forum_name, implode(', ', $dest_forum_names));
     448        }
     449
     450        $db->sql_transaction('commit');
     451
     452        return true;
     453}
     454
     455/**
    358456* Get physical file listing
    359457*/
    360458function filelist($rootdir, $dir = '', $type = 'gif|jpg|jpeg|png')
    361459{
    362         $matches = array();
     460        $matches = array($dir => array());
    363461
    364462        // Remove initial / if present
     
    620718        if ($approved_topics)
    621719        {
    622                 set_config('num_topics', $config['num_topics'] - $approved_topics, true);
     720                set_config_count('num_topics', $approved_topics * (-1), true);
    623721        }
    624722
     
    653751                }
    654752
    655                 $where_clause = $db->sql_in_set($where_type, array_map('intval', $where_ids));
     753                $where_ids = array_map('intval', $where_ids);
     754
     755/*              Possible code for splitting post deletion
     756                if (sizeof($where_ids) >= 1001)
     757                {
     758                        // Split into chunks of 1000
     759                        $chunks = array_chunk($where_ids, 1000);
     760
     761                        foreach ($chunks as $_where_ids)
     762                        {
     763                                delete_posts($where_type, $_where_ids, $auto_sync, $posted_sync, $post_count_sync, $call_delete_topics);
     764                        }
     765
     766                        return;
     767                }*/
     768
     769                $where_clause = $db->sql_in_set($where_type, $where_ids);
    656770        }
    657771
     
    666780        while ($row = $db->sql_fetchrow($result))
    667781        {
    668                 $post_ids[] = $row['post_id'];
    669                 $poster_ids[] = $row['poster_id'];
    670                 $topic_ids[] = $row['topic_id'];
    671                 $forum_ids[] = $row['forum_id'];
     782                $post_ids[] = (int) $row['post_id'];
     783                $poster_ids[] = (int) $row['poster_id'];
     784                $topic_ids[] = (int) $row['topic_id'];
     785                $forum_ids[] = (int) $row['forum_id'];
    672786
    673787                if ($row['post_postcount'] && $post_count_sync && $row['post_approved'])
     
    777891        if ($approved_posts)
    778892        {
    779                 set_config('num_posts', $config['num_posts'] - $approved_posts, true);
     893                set_config_count('num_posts', $approved_posts * (-1), true);
    780894        }
    781895
     
    800914        global $db, $config;
    801915
    802         if (is_array($ids) && sizeof($ids))
     916        // 0 is as bad as an empty array
     917        if (empty($ids))
     918        {
     919                return false;
     920        }
     921
     922        if (is_array($ids))
    803923        {
    804924                $ids = array_unique($ids);
     
    810930        }
    811931
    812         if (!sizeof($ids))
    813         {
    814                 return false;
    815         }
     932        $sql_where = '';
    816933
    817934        switch ($mode)
     
    820937                case 'message':
    821938                        $sql_id = 'post_msg_id';
     939                        $sql_where = ' AND in_message = ' . ($mode == 'message' ? 1 : 0);
    822940                break;
    823941
     
    843961                        FROM ' . ATTACHMENTS_TABLE . '
    844962                        WHERE ' . $db->sql_in_set($sql_id, $ids);
     963
     964        $sql .= $sql_where;
     965
    845966        $result = $db->sql_query($sql);
    846967
     
    868989        $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
    869990                WHERE ' . $db->sql_in_set($sql_id, $ids);
     991
     992        $sql .= $sql_where;
     993
    870994        $db->sql_query($sql);
    871995        $num_deleted = $db->sql_affectedrows();
     
    8951019        if ($space_removed || $files_removed)
    8961020        {
    897                 set_config('upload_dir_size', $config['upload_dir_size'] - $space_removed, true);
    898                 set_config('num_files', $config['num_files'] - $files_removed, true);
     1021                set_config_count('upload_dir_size', $space_removed * (-1), true);
     1022                set_config_count('num_files', $files_removed * (-1), true);
    8991023        }
    9001024
     
    9161040        if (sizeof($post_ids))
    9171041        {
    918                 $sql = 'UPDATE ' . POSTS_TABLE . '
    919                         SET post_attachment = 0
    920                         WHERE ' . $db->sql_in_set('post_id', $post_ids);
    921                 $db->sql_query($sql);
     1042                // Just check which posts are still having an assigned attachment not orphaned by querying the attachments table
     1043                $sql = 'SELECT post_msg_id
     1044                        FROM ' . ATTACHMENTS_TABLE . '
     1045                        WHERE ' . $db->sql_in_set('post_msg_id', $post_ids) . '
     1046                                AND in_message = 0
     1047                                AND is_orphan = 0';
     1048                $result = $db->sql_query($sql);
     1049
     1050                $remaining_ids = array();
     1051                while ($row = $db->sql_fetchrow($result))
     1052                {
     1053                        $remaining_ids[] = $row['post_msg_id'];
     1054                }
     1055                $db->sql_freeresult($result);
     1056
     1057                // Now only unset those ids remaining
     1058                $post_ids = array_diff($post_ids, $remaining_ids);
     1059
     1060                if (sizeof($post_ids))
     1061                {
     1062                        $sql = 'UPDATE ' . POSTS_TABLE . '
     1063                                SET post_attachment = 0
     1064                                WHERE ' . $db->sql_in_set('post_id', $post_ids);
     1065                        $db->sql_query($sql);
     1066                }
    9221067        }
    9231068
     
    9251070        if (sizeof($message_ids))
    9261071        {
    927                 $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
    928                         SET message_attachment = 0
    929                         WHERE ' . $db->sql_in_set('msg_id', $message_ids);
    930                 $db->sql_query($sql);
     1072                // Just check which messages are still having an assigned attachment not orphaned by querying the attachments table
     1073                $sql = 'SELECT post_msg_id
     1074                        FROM ' . ATTACHMENTS_TABLE . '
     1075                        WHERE ' . $db->sql_in_set('post_msg_id', $message_ids) . '
     1076                                AND in_message = 1
     1077                                AND is_orphan = 0';
     1078                $result = $db->sql_query($sql);
     1079
     1080                $remaining_ids = array();
     1081                while ($row = $db->sql_fetchrow($result))
     1082                {
     1083                        $remaining_ids[] = $row['post_msg_id'];
     1084                }
     1085                $db->sql_freeresult($result);
     1086
     1087                // Now only unset those ids remaining
     1088                $message_ids = array_diff($message_ids, $remaining_ids);
     1089
     1090                if (sizeof($message_ids))
     1091                {
     1092                        $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
     1093                                SET message_attachment = 0
     1094                                WHERE ' . $db->sql_in_set('msg_id', $message_ids);
     1095                        $db->sql_query($sql);
     1096                }
    9311097        }
    9321098
     
    10741240        $sql = 'SELECT COUNT(attach_id) AS num_entries
    10751241                FROM ' . ATTACHMENTS_TABLE . "
    1076                 WHERE physical_filename = '" . $db->sql_escape(basename($filename)) . "'";
     1242                WHERE physical_filename = '" . $db->sql_escape(utf8_basename($filename)) . "'";
    10771243        $result = $db->sql_query($sql);
    10781244        $num_entries = (int) $db->sql_fetchfield('num_entries');
     
    10851251        }
    10861252
    1087         $filename = ($mode == 'thumbnail') ? 'thumb_' . basename($filename) : basename($filename);
     1253        $filename = ($mode == 'thumbnail') ? 'thumb_' . utf8_basename($filename) : utf8_basename($filename);
    10881254        return @unlink($phpbb_root_path . $config['upload_path'] . '/' . $filename);
    10891255}
     
    11691335        {
    11701336                case 'topic_moved':
     1337                        $db->sql_transaction('begin');
    11711338                        switch ($db->sql_layer)
    11721339                        {
     
    12051372                                break;
    12061373                        }
    1207                 break;
     1374
     1375                        $db->sql_transaction('commit');
     1376                        break;
    12081377
    12091378                case 'topic_approved':
     1379
     1380                        $db->sql_transaction('begin');
    12101381                        switch ($db->sql_layer)
    12111382                        {
     
    12431414                                break;
    12441415                        }
    1245                 break;
     1416
     1417                        $db->sql_transaction('commit');
     1418                        break;
    12461419
    12471420                case 'post_reported':
    12481421                        $post_ids = $post_reported = array();
     1422
     1423                        $db->sql_transaction('begin');
    12491424
    12501425                        $sql = 'SELECT p.post_id, p.post_reported
     
    12981473                                $db->sql_query($sql);
    12991474                        }
    1300                 break;
     1475
     1476                        $db->sql_transaction('commit');
     1477                        break;
    13011478
    13021479                case 'topic_reported':
     
    13071484
    13081485                        $topic_ids = $topic_reported = array();
     1486
     1487                        $db->sql_transaction('begin');
    13091488
    13101489                        $sql = 'SELECT DISTINCT(t.topic_id)
     
    13401519                                $db->sql_query($sql);
    13411520                        }
    1342                 break;
     1521
     1522                        $db->sql_transaction('commit');
     1523                        break;
    13431524
    13441525                case 'post_attachment':
    13451526                        $post_ids = $post_attachment = array();
     1527
     1528                        $db->sql_transaction('begin');
    13461529
    13471530                        $sql = 'SELECT p.post_id, p.post_attachment
     
    13951578                                $db->sql_query($sql);
    13961579                        }
    1397                 break;
     1580
     1581                        $db->sql_transaction('commit');
     1582                        break;
    13981583
    13991584                case 'topic_attachment':
     
    14041589
    14051590                        $topic_ids = $topic_attachment = array();
     1591
     1592                        $db->sql_transaction('begin');
    14061593
    14071594                        $sql = 'SELECT DISTINCT(t.topic_id)
     
    14371624                                $db->sql_query($sql);
    14381625                        }
    1439                 break;
     1626
     1627                        $db->sql_transaction('commit');
     1628
     1629                        break;
    14401630
    14411631                case 'forum':
     1632
     1633                        $db->sql_transaction('begin');
    14421634
    14431635                        // 1: Get the list of all forums
     
    16411833                                }
    16421834                        }
    1643                 break;
     1835
     1836                        $db->sql_transaction('commit');
     1837                        break;
    16441838
    16451839                case 'topic':
    16461840                        $topic_data = $post_ids = $approved_unapproved_ids = $resync_forums = $delete_topics = $delete_posts = $moved_topics = array();
     1841
     1842                        $db->sql_transaction('begin');
    16471843
    16481844                        $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_approved, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time
     
    19682164                        unset($topic_data);
    19692165
     2166                        $db->sql_transaction('commit');
     2167
    19702168                        // if some topics have been resync'ed then resync parent forums
    19712169                        // except when we're only syncing a range, we don't want to sync forums during
     
    19752173                                sync('forum', 'forum_id', array_values($resync_forums), true, true);
    19762174                        }
    1977                 break;
     2175                        break;
    19782176        }
    19792177
     
    21612359                // Remove users who have group memberships with DENY moderator permissions
    21622360                $sql = $db->sql_build_query('SELECT', array(
    2163                         'SELECT'        => 'a.forum_id, ug.user_id',
     2361                        'SELECT'        => 'a.forum_id, ug.user_id, g.group_id',
    21642362
    21652363                        'FROM'          => array(
    21662364                                ACL_OPTIONS_TABLE       => 'o',
    21672365                                USER_GROUP_TABLE        => 'ug',
    2168                                 ACL_GROUPS_TABLE        => 'a'
     2366                                GROUPS_TABLE            => 'g',
     2367                                ACL_GROUPS_TABLE        => 'a',
    21692368                        ),
    21702369
     
    21802379                                        OR r.auth_setting = ' . ACL_NEVER . ')
    21812380                                AND a.group_id = ug.group_id
     2381                                AND g.group_id = ug.group_id
     2382                                AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1)
    21822383                                AND ' . $db->sql_in_set('ug.user_id', $ug_id_ary) . "
    21832384                                AND ug.user_pending = 0
     
    22992500* View log
    23002501*/
    2301 function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC')
     2502function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '')
    23022503{
    23032504        global $db, $user, $auth, $phpEx, $phpbb_root_path, $phpbb_admin_path;
     
    23162517                case 'mod':
    23172518                        $log_type = LOG_MOD;
     2519                        $sql_forum = '';
    23182520
    23192521                        if ($topic_id)
    23202522                        {
    2321                                 $sql_forum = 'AND l.topic_id = ' . intval($topic_id);
     2523                                $sql_forum = 'AND l.topic_id = ' . (int) $topic_id;
    23222524                        }
    23232525                        else if (is_array($forum_id))
     
    23252527                                $sql_forum = 'AND ' . $db->sql_in_set('l.forum_id', array_map('intval', $forum_id));
    23262528                        }
    2327                         else
    2328                         {
    2329                                 $sql_forum = ($forum_id) ? 'AND l.forum_id = ' . intval($forum_id) : '';
     2529                        else if ($forum_id)
     2530                        {
     2531                                $sql_forum = 'AND l.forum_id = ' . (int) $forum_id;
    23302532                        }
    23312533                break;
     
    23482550                default:
    23492551                        return;
     2552        }
     2553
     2554        // Use no preg_quote for $keywords because this would lead to sole backslashes being added
     2555        // We also use an OR connection here for spaces and the | string. Currently, regex is not supported for searching (but may come later).
     2556        $keywords = preg_split('#[\s|]+#u', utf8_strtolower($keywords), 0, PREG_SPLIT_NO_EMPTY);
     2557        $sql_keywords = '';
     2558
     2559        if (!empty($keywords))
     2560        {
     2561                $keywords_pattern = array();
     2562
     2563                // Build pattern and keywords...
     2564                for ($i = 0, $num_keywords = sizeof($keywords); $i < $num_keywords; $i++)
     2565                {
     2566                        $keywords_pattern[] = preg_quote($keywords[$i], '#');
     2567                        $keywords[$i] = $db->sql_like_expression($db->any_char . $keywords[$i] . $db->any_char);
     2568                }
     2569
     2570                $keywords_pattern = '#' . implode('|', $keywords_pattern) . '#ui';
     2571
     2572                $operations = array();
     2573                foreach ($user->lang as $key => $value)
     2574                {
     2575                        if (substr($key, 0, 4) == 'LOG_' && preg_match($keywords_pattern, $value))
     2576                        {
     2577                                $operations[] = $key;
     2578                        }
     2579                }
     2580
     2581                $sql_keywords = 'AND (';
     2582                if (!empty($operations))
     2583                {
     2584                        $sql_keywords .= $db->sql_in_set('l.log_operation', $operations) . ' OR ';
     2585                }
     2586                $sql_keywords .= 'LOWER(l.log_data) ' . implode(' OR LOWER(l.log_data) ', $keywords) . ')';
    23502587        }
    23512588
     
    23552592                        AND u.user_id = l.user_id
    23562593                        " . (($limit_days) ? "AND l.log_time >= $limit_days" : '') . "
     2594                        $sql_keywords
    23572595                        $sql_forum
    23582596                ORDER BY $sort_by";
     
    23952633                if (!empty($row['log_data']))
    23962634                {
    2397                         $log_data_ary = unserialize($row['log_data']);
     2635                        $log_data_ary = @unserialize($row['log_data']);
     2636                        $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary;
    23982637
    23992638                        if (isset($user->lang[$row['log_operation']]))
     
    24182657                                }
    24192658                        }
    2420                         else
     2659                        else if (!empty($log_data_ary))
    24212660                        {
    24222661                                $log[$i]['action'] .= '<br />' . implode('', $log_data_ary);
     
    25162755
    25172756        $sql = 'SELECT COUNT(l.log_id) AS total_entries
    2518                 FROM ' . LOG_TABLE . " l
     2757                FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u
    25192758                WHERE l.log_type = $log_type
     2759                        AND l.user_id = u.user_id
    25202760                        AND l.log_time >= $limit_days
     2761                        $sql_keywords
    25212762                        $sql_forum";
    25222763        $result = $db->sql_query($sql);
     
    26612902        }
    26622903
    2663         $sql = 'SELECT user_id, username, user_regdate, user_lastvisit, user_inactive_time, user_inactive_reason
     2904        $sql = 'SELECT *
    26642905                FROM ' . USERS_TABLE . '
    26652906                WHERE user_type = ' . USER_INACTIVE .
     
    30303271}
    30313272
     3273/**
     3274 * Obtains the latest version information
     3275 *
     3276 * @param bool $force_update Ignores cached data. Defaults to false.
     3277 * @param bool $warn_fail Trigger a warning if obtaining the latest version information fails. Defaults to false.
     3278 * @param int $ttl Cache version information for $ttl seconds. Defaults to 86400 (24 hours).
     3279 *
     3280 * @return string | false Version info on success, false on failure.
     3281 */
     3282function obtain_latest_version_info($force_update = false, $warn_fail = false, $ttl = 86400)
     3283{
     3284        global $cache;
     3285
     3286        $info = $cache->get('versioncheck');
     3287
     3288        if ($info === false || $force_update)
     3289        {
     3290                $errstr = '';
     3291                $errno = 0;
     3292
     3293                $info = get_remote_file('www.phpbb.com', '/updatecheck',
     3294                                ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno);
     3295
     3296                if ($info === false)
     3297                {
     3298                        $cache->destroy('versioncheck');
     3299                        if ($warn_fail)
     3300                        {
     3301                                trigger_error($errstr, E_USER_WARNING);
     3302                        }
     3303                        return false;
     3304                }
     3305
     3306                $cache->put('versioncheck', $info, $ttl);
     3307        }
     3308
     3309        return $info;
     3310}
     3311
     3312/**
     3313 * Enables a particular flag in a bitfield column of a given table.
     3314 *
     3315 * @param string        $table_name             The table to update
     3316 * @param string        $column_name    The column containing a bitfield to update
     3317 * @param int           $flag                   The binary flag which is OR-ed with the current column value
     3318 * @param string        $sql_more               This string is attached to the sql query generated to update the table.
     3319 *
     3320 * @return void
     3321 */
     3322function enable_bitfield_column_flag($table_name, $column_name, $flag, $sql_more = '')
     3323{
     3324        global $db;
     3325
     3326        $sql = 'UPDATE ' . $table_name . '
     3327                SET ' . $column_name . ' = ' . $db->sql_bit_or($column_name, $flag) . '
     3328                ' . $sql_more;
     3329        $db->sql_query($sql);
     3330}
     3331
    30323332?>
  • trunk/forum/includes/functions_compress.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_compress.php 8780 2008-08-22 12:52:48Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    8181                        }
    8282                }
     83                else
     84                {
     85                        // $src does not exist
     86                        return false;
     87                }
    8388
    8489                return true;
     
    9095        function add_custom_file($src, $filename)
    9196        {
     97                if (!file_exists($src))
     98                {
     99                        return false;
     100                }
     101
    92102                $this->data($filename, file_get_contents($src), false, stat($src));
    93103                return true;
     
    156166        function compress_zip($mode, $file)
    157167        {
    158                 return $this->fp = @fopen($file, $mode . 'b');
     168                $this->fp = @fopen($file, $mode . 'b');
     169
     170                if (!$this->fp)
     171                {
     172                        trigger_error('Unable to open file ' . $file . ' [' . $mode . 'b]');
     173                }
    159174        }
    160175
  • trunk/forum/includes/functions_content.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_content.php 9184 2008-12-11 14:46:38Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    251251        $text = preg_replace('/ +/', ' ', strtr($text, "\t\n\r\x0C ", '     '));
    252252
     253        // we need to turn the entities back into their original form, to not cut the message in between them
     254        $entities = array('&lt;', '&gt;', '&#91;', '&#93;', '&#46;', '&#58;', '&#058;');
     255        $characters = array('<', '>', '[', ']', '.', ':', ':');
     256        $text = str_replace($entities, $characters, $text);
     257
    253258        $word_indizes = array();
    254259        if (sizeof($words))
     
    262267                                if (preg_match('#(?:[^\w]|^)(' . $word . ')(?:[^\w]|$)#i', $text, $match))
    263268                                {
     269                                        if (empty($match[1]))
     270                                        {
     271                                                continue;
     272                                        }
     273
    264274                                        $pos = utf8_strpos($text, $match[1]);
    265275                                        if ($pos !== false)
     
    341351                                }
    342352                        }
    343                         return $final_text;
     353                        return str_replace($characters, $entities, $final_text);
    344354                }
    345355        }
     
    347357        if (!sizeof($words) || !sizeof($word_indizes))
    348358        {
    349                 return (utf8_strlen($text) >= $length + 3) ? utf8_substr($text, 0, $length) . '...' : $text;
     359                return str_replace($characters, $entities, ((utf8_strlen($text) >= $length + 3) ? utf8_substr($text, 0, $length) . '...' : $text));
    350360        }
    351361}
     
    676686        static $censors;
    677687
     688        // Nothing to do?
     689        if ($text === '')
     690        {
     691                return '';
     692        }
     693
    678694        // We moved the word censor checks in here because we call this function quite often - and then only need to do the check once
    679695        if (!isset($censors) || !is_array($censors))
     
    724740        else
    725741        {
    726                 return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img src="' . $phpbb_root_path . $config['smilies_path'] . '/\2 />', $text);
     742                $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path;
     743                return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img src="' . $root_path . $config['smilies_path'] . '/\2 />', $text);
    727744        }
    728745}
     
    832849                // Some basics...
    833850                $attachment['extension'] = strtolower(trim($attachment['extension']));
    834                 $filename = $phpbb_root_path . $config['upload_path'] . '/' . basename($attachment['physical_filename']);
    835                 $thumbnail_filename = $phpbb_root_path . $config['upload_path'] . '/thumb_' . basename($attachment['physical_filename']);
     851                $filename = $phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($attachment['physical_filename']);
     852                $thumbnail_filename = $phpbb_root_path . $config['upload_path'] . '/thumb_' . utf8_basename($attachment['physical_filename']);
    836853
    837854                $upload_icon = '';
     
    849866                }
    850867
    851                 $filesize = $attachment['filesize'];
    852                 $size_lang = ($filesize >= 1048576) ? $user->lang['MIB'] : (($filesize >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES']);
    853                 $filesize = get_formatted_filesize($filesize, false);
     868                $filesize = get_formatted_filesize($attachment['filesize'], false);
    854869
    855870                $comment = bbcode_nl2br(censor_text($attachment['attach_comment']));
     
    857872                $block_array += array(
    858873                        'UPLOAD_ICON'           => $upload_icon,
    859                         'FILESIZE'                      => $filesize,
    860                         'SIZE_LANG'                     => $size_lang,
    861                         'DOWNLOAD_NAME'         => basename($attachment['real_filename']),
     874                        'FILESIZE'                      => $filesize['value'],
     875                        'SIZE_LANG'                     => $filesize['unit'],
     876                        'DOWNLOAD_NAME'         => utf8_basename($attachment['real_filename']),
    862877                        'COMMENT'                       => $comment,
    863878                );
     
    951966                                                'THUMB_IMAGE'           => $thumbnail_link,
    952967                                        );
     968
     969                                        $update_count[] = $attachment['attach_id'];
    953970                                break;
    954971
     
    9971014                                                'WIDTH'                 => $width,
    9981015                                                'HEIGHT'                => $height,
     1016                                                'U_VIEW_LINK'   => $download_link . '&amp;view=1',
    9991017                                        );
    10001018
     
    10891107* @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char)
    10901108* @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars).
    1091 * @param bool $allow_reply Allow Re: in front of string
     1109* @param bool $allow_reply Allow Re: in front of string
     1110*       NOTE: This parameter can cause undesired behavior (returning strings longer than $max_store_legnth) and is deprecated.
    10921111* @param string $append String to be appended
    10931112*/
    1094 function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = true, $append = '')
     1113function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = false, $append = '')
    10951114{
    10961115        $chars = array();
     
    11271146                        $string = implode('', $chars);
    11281147                }
    1129                 while (utf8_strlen($string) > $max_store_length || !sizeof($chars));
     1148                while (!empty($chars) && utf8_strlen($string) > $max_store_length);
    11301149        }
    11311150
     
    11601179{
    11611180        static $_profile_cache;
    1162         static $_base_profile_url;
    1163 
    1164         $cache_key = $user_id;
    1165 
    1166         // If the get_username_string() function had been executed once with an (to us) unkown mode, all modes are pre-filled and we can just grab it.
    1167         if ($user_id && $user_id != ANONYMOUS && isset($_profile_cache[$cache_key][$mode]))
    1168         {
    1169                 // If the mode is 'no_profile', we simply construct the TPL code due to calls to this mode being very very rare
    1170                 if ($mode == 'no_profile')
    1171                 {
    1172                         $tpl = (!$_profile_cache[$cache_key]['colour']) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
    1173                         return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($_profile_cache[$cache_key]['colour'], $_profile_cache[$cache_key]['username']), $tpl);
    1174                 }
    1175 
    1176                 return $_profile_cache[$cache_key][$mode];
    1177         }
    1178 
    1179         global $phpbb_root_path, $phpEx, $user, $auth;
    1180 
    1181         $username_colour = ($username_colour) ? '#' . $username_colour : '';
    1182 
    1183         if ($guest_username === false)
    1184         {
    1185                 $username = ($username) ? $username : $user->lang['GUEST'];
    1186         }
    1187         else
    1188         {
    1189                 $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']);
    1190         }
    1191 
    1192         // Build cache for all modes
    1193         $_profile_cache[$cache_key]['colour'] = $username_colour;
    1194         $_profile_cache[$cache_key]['username'] = $username;
    1195         $_profile_cache[$cache_key]['no_profile'] = true;
    1196 
    1197         // Profile url - only show if not anonymous and permission to view profile if registered user
    1198         // For anonymous the link leads to a login page.
    1199         if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile')))
    1200         {
    1201                 if (empty($_base_profile_url))
    1202                 {
    1203                         $_base_profile_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u={USER_ID}');
    1204                 }
    1205 
    1206                 $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&amp;u=' . (int) $user_id : str_replace('={USER_ID}', '=' . (int) $user_id, $_base_profile_url);
    1207                 $tpl = (!$username_colour) ? '<a href="{PROFILE_URL}">{USERNAME}</a>' : '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>';
    1208                 $_profile_cache[$cache_key]['full'] = str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl);
    1209         }
    1210         else
    1211         {
    1212                 $tpl = (!$username_colour) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
    1213                 $_profile_cache[$cache_key]['full'] = str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), $tpl);
    1214                 $profile_url = '';
    1215         }
    1216 
    1217         // Use the profile url from above
    1218         $_profile_cache[$cache_key]['profile'] = $profile_url;
    1219 
    1220         // If - by any chance - no_profile is called before any other mode, we need to do the calculation here
    1221         if ($mode == 'no_profile')
    1222         {
    1223                 $tpl = (!$_profile_cache[$cache_key]['colour']) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
    1224                 return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($_profile_cache[$cache_key]['colour'], $_profile_cache[$cache_key]['username']), $tpl);
    1225         }
    1226 
    1227         return $_profile_cache[$cache_key][$mode];
     1181
     1182        // We cache some common variables we need within this function
     1183        if (empty($_profile_cache))
     1184        {
     1185                global $phpbb_root_path, $phpEx;
     1186
     1187                $_profile_cache['base_url'] = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u={USER_ID}');
     1188                $_profile_cache['tpl_noprofile'] = '{USERNAME}';
     1189                $_profile_cache['tpl_noprofile_colour'] = '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
     1190                $_profile_cache['tpl_profile'] = '<a href="{PROFILE_URL}">{USERNAME}</a>';
     1191                $_profile_cache['tpl_profile_colour'] = '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>';
     1192        }
     1193
     1194        global $user, $auth;
     1195
     1196        // This switch makes sure we only run code required for the mode
     1197        switch ($mode)
     1198        {
     1199                case 'full':
     1200                case 'no_profile':
     1201                case 'colour':
     1202
     1203                        // Build correct username colour
     1204                        $username_colour = ($username_colour) ? '#' . $username_colour : '';
     1205
     1206                        // Return colour
     1207                        if ($mode == 'colour')
     1208                        {
     1209                                return $username_colour;
     1210                        }
     1211
     1212                // no break;
     1213
     1214                case 'username':
     1215
     1216                        // Build correct username
     1217                        if ($guest_username === false)
     1218                        {
     1219                                $username = ($username) ? $username : $user->lang['GUEST'];
     1220                        }
     1221                        else
     1222                        {
     1223                                $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']);
     1224                        }
     1225
     1226                        // Return username
     1227                        if ($mode == 'username')
     1228                        {
     1229                                return $username;
     1230                        }
     1231
     1232                // no break;
     1233
     1234                case 'profile':
     1235
     1236                        // Build correct profile url - only show if not anonymous and permission to view profile if registered user
     1237                        // For anonymous the link leads to a login page.
     1238                        if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile')))
     1239                        {
     1240                                $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&amp;u=' . (int) $user_id : str_replace(array('={USER_ID}', '=%7BUSER_ID%7D'), '=' . (int) $user_id, $_profile_cache['base_url']);
     1241                        }
     1242                        else
     1243                        {
     1244                                $profile_url = '';
     1245                        }
     1246
     1247                        // Return profile
     1248                        if ($mode == 'profile')
     1249                        {
     1250                                return $profile_url;
     1251                        }
     1252
     1253                // no break;
     1254        }
     1255
     1256        if (($mode == 'full' && !$profile_url) || $mode == 'no_profile')
     1257        {
     1258                return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']);
     1259        }
     1260
     1261        return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_profile'] : $_profile_cache['tpl_profile_colour']);
    12281262}
    12291263
  • trunk/forum/includes/functions_convert.php

    r400 r702  
    33*
    44* @package install
    5 * @version $Id: functions_convert.php 8876 2008-09-18 14:26:56Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2006 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    206206/**
    207207* Generate the email hash stored in the users table
     208*
     209* Note: Deprecated, calls should directly go to phpbb_email_hash()
    208210*/
    209211function gen_email_hash($email)
    210212{
    211         return (crc32(strtolower($email)) . strlen($email));
     213        return phpbb_email_hash($email);
    212214}
    213215
     
    552554
    553555        // copy file will prepend $phpBB_root_path
    554         $target = $config[$config_var] . '/' . basename(($use_target === false) ? $source : $use_target);
     556        $target = $config[$config_var] . '/' . utf8_basename(($use_target === false) ? $source : $use_target);
    555557
    556558        if (!empty($convert->convertor[$config_var]) && strpos($source, $convert->convertor[$config_var]) !== 0)
     
    568570        if ($result['copied'])
    569571        {
    570                 $result['target'] = basename($target);
     572                $result['target'] = utf8_basename($target);
    571573        }
    572574        else
    573575        {
    574                 $result['target'] = ($use_target !== false) ? $result['orig_source'] : basename($target);
     576                $result['target'] = ($use_target !== false) ? $result['orig_source'] : utf8_basename($target);
    575577        }
    576578
     
    601603                        $thumb_dir = $convert->convertor['thumbnails'][0];
    602604                        $thumb_prefix = $convert->convertor['thumbnails'][1];
    603                         $thumb_source = $thumb_dir . $thumb_prefix . basename($result['source']);
     605                        $thumb_source = $thumb_dir . $thumb_prefix . utf8_basename($result['source']);
    604606
    605607                        if (strpos($thumb_source, $convert->convertor['upload_path']) !== 0)
     
    12331235                }
    12341236
     1237                if (isset($convert->config_schema['array_name']))
     1238                {
     1239                        unset($convert->config_schema['array_name']);
     1240                }
     1241
    12351242                $convert_config = extract_variables_from_file($filename);
    12361243                if (!empty($convert->config_schema['array_name']))
     
    12651272
    12661273        $convert_config = get_config();
     1274
    12671275        foreach ($schema['settings'] as $config_name => $src)
    12681276        {
     
    12751283                else
    12761284                {
    1277                         $config_value = (isset($convert_config[$src])) ? $convert_config[$src] : '';
    1278                 }
     1285                        if ($schema['table_format'] != 'file' || empty($schema['array_name']))
     1286                        {
     1287                                $config_value = (isset($convert_config[$src])) ? $convert_config[$src] : '';
     1288                        }
     1289                        else if (!empty($schema['array_name']))
     1290                        {
     1291                                $src_ary = $schema['array_name'];
     1292                                $config_value = (isset($convert_config[$src_ary][$src])) ? $convert_config[$src_ary][$src] : '';
     1293                        }
     1294                }
    12791295
    12801296                if ($config_value !== '')
     
    16991715                'GLOBAL_MODERATORS'     => array('00AA00', 1, 0),
    17001716                'ADMINISTRATORS'        => array('AA0000', 1, 1),
    1701                 'BOTS'                          => array('9E8DA7', 0, 0)
     1717                'BOTS'                          => array('9E8DA7', 0, 0),
     1718                'NEWLY_REGISTERED'              => array('', 0, 0),
    17021719        );
    17031720
     
    22572274        if (substr($trg, -1) == '/')
    22582275        {
    2259                 $trg .= basename($src);
     2276                $trg .= utf8_basename($src);
    22602277        }
    22612278        $src_path = relative_base($src, $source_relative_path, __LINE__, __FILE__);
  • trunk/forum/includes/functions_display.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_display.php 9082 2008-11-22 20:26:09Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    103103        $forum_tracking_info = array();
    104104        $branch_root_id = $root_data['forum_id'];
     105
     106        // Check for unread global announcements (index page only)
     107        $ga_unread = false;
     108        if ($root_data['forum_id'] == 0)
     109        {
     110                $unread_ga_list = get_unread_topics($user->data['user_id'], 'AND t.forum_id = 0', '', 1);
     111
     112                if (!empty($unread_ga_list))
     113                {
     114                        $ga_unread = true;
     115                }
     116        }
     117
    105118        while ($row = $db->sql_fetchrow($result))
    106119        {
     
    155168                }
    156169
     170                // Count the difference of real to public topics, so we can display an information to moderators
     171                $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0;
    157172                $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
    158173
     
    211226                        {
    212227                                $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
     228                        }
     229
     230                        if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics'])
     231                        {
     232                                $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
    213233                        }
    214234
     
    238258        if ($mark_read == 'forums' || $mark_read == 'all')
    239259        {
    240                 $redirect = build_url('mark', 'hash');
     260                $redirect = build_url(array('mark', 'hash'));
    241261                $token = request_var('hash', '');
    242262                if (check_link_hash($token, 'global'))
     
    249269                        else
    250270                        {
     271                                // Add 0 to forums array to mark global announcements correctly
     272                                $forum_ids[] = 0;
    251273                                markread('topics', $forum_ids);
    252274                                $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
     
    300322
    301323                $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
     324
     325                // Mark the first visible forum on index as unread if there's any unread global announcement
     326                if ($ga_unread && !empty($forum_ids_moderator) && $forum_id == $forum_ids_moderator[0])
     327                {
     328                        $forum_unread = true;
     329                }
    302330
    303331                $folder_image = $folder_alt = $l_subforums = '';
     
    429457                        'S_LIST_SUBFORUMS'      => ($row['display_subforum_list']) ? true : false,
    430458                        'S_SUBFORUMS'           => (sizeof($subforums_list)) ? true : false,
     459                        'S_FEED_ENABLED'        => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options'])) ? true : false,
    431460
    432461                        'FORUM_ID'                              => $row['forum_id'],
     
    452481                        'L_MODERATOR_STR'               => $l_moderator,
    453482
     483                        'U_UNAPPROVED_TOPICS'   => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=unapproved_topics&amp;f=' . $row['forum_id_unapproved_topics']) : '',
    454484                        'U_VIEWFORUM'           => $u_viewforum,
    455485                        'U_LAST_POSTER'         => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
     
    474504                'S_HAS_SUBFORUM'        => ($visible_forums) ? true : false,
    475505                'L_SUBFORUM'            => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
    476                 'LAST_POST_IMG'         => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'))
    477         );
     506                'LAST_POST_IMG'         => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
     507                'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'),
     508        ));
    478509
    479510        if ($return_moderators)
     
    515546function generate_forum_nav(&$forum_data)
    516547{
    517         global $db, $user, $template, $auth;
     548        global $db, $user, $template, $auth, $config;
    518549        global $phpEx, $phpbb_root_path;
    519550
     
    562593                'FORUM_ID'              => $forum_data['forum_id'],
    563594                'FORUM_NAME'    => $forum_data['forum_name'],
    564                 'FORUM_DESC'    => generate_text_for_display($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options']))
    565         );
     595                'FORUM_DESC'    => generate_text_for_display($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options']),
     596
     597                'S_ENABLE_FEEDS_FORUM'  => ($config['feed_forum'] && $forum_data['forum_type'] == FORUM_POST && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data['forum_options'])) ? true : false,
     598        ));
    566599
    567600        return;
     
    659692        global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth;
    660693
    661         // Have we disabled the display of moderators? If so, then return
    662         // from whence we came ...
    663         if (!$config['load_moderators'])
    664         {
    665                 return;
    666         }
    667 
    668         $forum_sql = '';
     694        $forum_id_ary = array();
    669695
    670696        if ($forum_id !== false)
     
    675701                }
    676702
    677                 // If we don't have a forum then we can't have a moderator
    678                 if (!sizeof($forum_id))
    679                 {
    680                         return;
    681                 }
    682 
    683                 $forum_sql = 'AND m.' . $db->sql_in_set('forum_id', $forum_id);
     703                // Exchange key/value pair to be able to faster check for the forum id existence
     704                $forum_id_ary = array_flip($forum_id);
    684705        }
    685706
     
    702723                ),
    703724
    704                 'WHERE'         => "m.display_on_index = 1 $forum_sql",
     725                'WHERE'         => 'm.display_on_index = 1',
    705726        );
    706727
     728        // We query every forum here because for caching we should not have any parameter.
    707729        $sql = $db->sql_build_query('SELECT', $sql_array);
    708730        $result = $db->sql_query($sql, 3600);
     
    710732        while ($row = $db->sql_fetchrow($result))
    711733        {
     734                $f_id = (int) $row['forum_id'];
     735
     736                if (!isset($forum_id_ary[$f_id]))
     737                {
     738                        continue;
     739                }
     740
    712741                if (!empty($row['user_id']))
    713742                {
    714                         $forum_moderators[$row['forum_id']][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
     743                        $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
    715744                }
    716745                else
     
    720749                        if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
    721750                        {
    722                                 $forum_moderators[$row['forum_id']][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
     751                                $forum_moderators[$f_id][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
    723752                        }
    724753                        else
    725754                        {
    726                                 $forum_moderators[$row['forum_id']][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_name . '</a>';
     755                                $forum_moderators[$f_id][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_name . '</a>';
    727756                        }
    728757                }
     
    847876function display_custom_bbcodes()
    848877{
    849         global $db, $template;
     878        global $db, $template, $user;
    850879
    851880        // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
     
    861890        while ($row = $db->sql_fetchrow($result))
    862891        {
     892                // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
     893                if (isset($user->lang[strtoupper($row['bbcode_helpline'])]))
     894                {
     895                        $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];
     896                }
     897
    863898                $template->assign_block_vars('custom_tags', array(
    864899                        'BBCODE_NAME'           => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
     
    11951230* @param string $avatar_height Height of users avatar
    11961231* @param string $alt Optional language string for alt tag within image, can be a language key or text
     1232* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
    11971233*
    11981234* @return string Avatar image
    11991235*/
    1200 function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR')
     1236function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false)
    12011237{
    12021238        global $user, $config, $phpbb_root_path, $phpEx;
    12031239
    1204         if (empty($avatar) || !$avatar_type)
     1240        if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
    12051241        {
    12061242                return '';
     
    12121248        {
    12131249                case AVATAR_UPLOAD:
     1250                        if (!$config['allow_avatar_upload'] && !$ignore_config)
     1251                        {
     1252                                return '';
     1253                        }
    12141254                        $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
    12151255                break;
    12161256
    12171257                case AVATAR_GALLERY:
     1258                        if (!$config['allow_avatar_local'] && !$ignore_config)
     1259                        {
     1260                                return '';
     1261                        }
    12181262                        $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
    12191263                break;
     1264
     1265                case AVATAR_REMOTE:
     1266                        if (!$config['allow_avatar_remote'] && !$ignore_config)
     1267                        {
     1268                                return '';
     1269                        }
     1270                break;
    12201271        }
    12211272
  • trunk/forum/includes/functions_install.php

    r400 r702  
    33*
    44* @package install
    5 * @version $Id: functions_install.php 8507 2008-04-20 04:57:29Z davidmj $
     5* @version $Id$
    66* @copyright (c) 2006 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2222function can_load_dll($dll)
    2323{
    24         return ((@ini_get('enable_dl') || strtolower(@ini_get('enable_dl')) == 'on') && (!@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off') && @dl($dll . '.' . PHP_SHLIB_SUFFIX)) ? true : false;
     24        // SQLite2 is a tricky thing, from 5.0.0 it requires PDO; if PDO is not loaded we must state that SQLite is unavailable
     25        // as the installer doesn't understand that the extension has a prerequisite.
     26        //
     27        // On top of this sometimes the SQLite extension is compiled for a different version of PDO
     28        // by some Linux distributions which causes phpBB to bomb out with a blank page.
     29        //
     30        // Net result we'll disable automatic inclusion of SQLite support
     31        //
     32        // See: r9618 and #56105
     33        if ($dll == 'sqlite')
     34        {
     35                return false;
     36        }
     37        return ((@ini_get('enable_dl') || strtolower(@ini_get('enable_dl')) == 'on') && (!@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off') && function_exists('dl') && @dl($dll . '.' . PHP_SHLIB_SUFFIX)) ? true : false;
    2538}
    2639
     
    176189{
    177190        global $lang;
    178        
     191
    179192        $available_dbms = get_available_dbms(false, false, $only_20x_options);
    180193        $dbms_options = '';
     
    397410                                        else
    398411                                        {
    399                                                 $sql = "SELECT FIRST 0 char_length('')
    400                                                         FROM RDB\$DATABASE";
     412                                                $sql = 'SELECT 1 FROM RDB$DATABASE
     413                                                        WHERE BIN_AND(10, 1) = 0';
    401414                                                $result = $db->sql_query($sql);
    402                                                 if (!$result) // This can only fail if char_length is not defined
     415                                                if (!$result) // This can only fail if BIN_AND is not defined
    403416                                                {
    404417                                                        $error[] = $lang['INST_ERR_DB_NO_FIREBIRD'];
     
    441454                                }
    442455                        break;
    443                        
     456
    444457                        case 'oracle':
    445458                                if ($unicode_check)
     
    463476                                }
    464477                        break;
    465                        
     478
    466479                        case 'postgres':
    467480                                if ($unicode_check)
  • trunk/forum/includes/functions_jabber.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_jabber.php 8979 2008-10-08 12:44:23Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2007 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    477477                                        else if (in_array('PLAIN', $methods) && ($this->session['ssl'] || !empty($this->session['tls'])))
    478478                                        {
     479                                                // http://www.ietf.org/rfc/rfc4616.txt (PLAIN SASL Mechanism)
    479480                                                $this->send("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>"
    480                                                         . base64_encode(chr(0) . $this->username . '@' . $this->server . chr(0) . $this->password) .
     481                                                        . base64_encode($this->username . '@' . $this->server . chr(0) . $this->username . chr(0) . $this->password) .
    481482                                                        '</auth>');
    482483                                        }
  • trunk/forum/includes/functions_messenger.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_messenger.php 9078 2008-11-22 19:55:00Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2828        var $mail_priority = MAIL_NORMAL_PRIORITY;
    2929        var $use_queue = true;
     30
     31        var $tpl_obj = NULL;
    3032        var $tpl_msg = array();
     33        var $eol = "\n";
    3134
    3235        /**
     
    3942                $this->use_queue = (!$config['email_package_size']) ? false : $use_queue;
    4043                $this->subject = '';
     44
     45                // Determine EOL character (\n for UNIX, \r\n for Windows and \r for Mac)
     46                $this->eol = (!defined('PHP_EOL')) ? (($eol = strtolower(substr(PHP_OS, 0, 3))) == 'win') ? "\r\n" : (($eol == 'mac') ? "\r" : "\n") : PHP_EOL;
     47                $this->eol = (!$this->eol) ? "\n" : $this->eol;
    4148        }
    4249
     
    5865                global $config;
    5966
     67                if (!trim($address))
     68                {
     69                        return;
     70                }
     71
    6072                $pos = isset($this->addresses['to']) ? sizeof($this->addresses['to']) : 0;
    6173
     
    7890        function cc($address, $realname = '')
    7991        {
     92                if (!trim($address))
     93                {
     94                        return;
     95                }
     96
    8097                $pos = isset($this->addresses['cc']) ? sizeof($this->addresses['cc']) : 0;
    8198                $this->addresses['cc'][$pos]['email'] = trim($address);
     
    88105        function bcc($address, $realname = '')
    89106        {
     107                if (!trim($address))
     108                {
     109                        return;
     110                }
     111
    90112                $pos = isset($this->addresses['bcc']) ? sizeof($this->addresses['bcc']) : 0;
    91113                $this->addresses['bcc'][$pos]['email'] = trim($address);
     
    99121        {
    100122                // IM-Addresses could be empty
    101                 if (!$address)
     123                if (!trim($address))
    102124                {
    103125                        return;
     
    152174        * Set email template to use
    153175        */
    154         function template($template_file, $template_lang = '')
    155         {
    156                 global $config, $phpbb_root_path;
     176        function template($template_file, $template_lang = '', $template_path = '')
     177        {
     178                global $config, $phpbb_root_path, $user;
    157179
    158180                if (!trim($template_file))
    159181                {
    160                         trigger_error('No template file set', E_USER_ERROR);
     182                        trigger_error('No template file for emailing set.', E_USER_ERROR);
    161183                }
    162184
    163185                if (!trim($template_lang))
    164186                {
     187                        // fall back to board default language if the user's language is
     188                        // missing $template_file.  If this does not exist either,
     189                        // $tpl->set_custom_template will do a trigger_error
    165190                        $template_lang = basename($config['default_lang']);
    166191                }
    167192
    168                 if (empty($this->tpl_msg[$template_lang . $template_file]))
    169                 {
    170                         $tpl_file = "{$phpbb_root_path}language/$template_lang/email/$template_file.txt";
    171 
    172                         if (!file_exists($tpl_file))
    173                         {
    174                                 trigger_error("Could not find email template file [ $tpl_file ]", E_USER_ERROR);
    175                         }
    176 
    177                         if (($data = @file_get_contents($tpl_file)) === false)
    178                         {
    179                                 trigger_error("Failed opening template file [ $tpl_file ]", E_USER_ERROR);
    180                         }
    181 
    182                         $this->tpl_msg[$template_lang . $template_file] = $data;
    183                 }
    184 
    185                 $this->msg = $this->tpl_msg[$template_lang . $template_file];
     193                // tpl_msg now holds a template object we can use to parse the template file
     194                if (!isset($this->tpl_msg[$template_lang . $template_file]))
     195                {
     196                        $this->tpl_msg[$template_lang . $template_file] = new template();
     197                        $tpl = &$this->tpl_msg[$template_lang . $template_file];
     198
     199                        $fallback_template_path = false;
     200
     201                        if (!$template_path)
     202                        {
     203                                $template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
     204                                $template_path .= $template_lang . '/email';
     205
     206                                // we can only specify default language fallback when the path is not a custom one for which we
     207                                // do not know the default language alternative
     208                                if ($template_lang !== basename($config['default_lang']))
     209                                {
     210                                        $fallback_template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
     211                                        $fallback_template_path .= basename($config['default_lang']) . '/email';
     212                                }
     213                        }
     214
     215                        $tpl->set_custom_template($template_path, $template_lang . '_email', $fallback_template_path);
     216
     217                        $tpl->set_filenames(array(
     218                                'body'          => $template_file . '.txt',
     219                        ));
     220                }
     221
     222                $this->tpl_obj = &$this->tpl_msg[$template_lang . $template_file];
     223                $this->vars = &$this->tpl_obj->_rootref;
     224                $this->tpl_msg = '';
    186225
    187226                return true;
     
    193232        function assign_vars($vars)
    194233        {
    195                 $this->vars = (empty($this->vars)) ? $vars : $this->vars + $vars;
     234                if (!is_object($this->tpl_obj))
     235                {
     236                        return;
     237                }
     238
     239                $this->tpl_obj->assign_vars($vars);
     240        }
     241
     242        function assign_block_vars($blockname, $vars)
     243        {
     244                if (!is_object($this->tpl_obj))
     245                {
     246                        return;
     247                }
     248
     249                $this->tpl_obj->assign_block_vars($blockname, $vars);
    196250        }
    197251
     
    204258
    205259                // We add some standard variables we always use, no need to specify them always
    206                 $this->vars['U_BOARD'] = (!isset($this->vars['U_BOARD'])) ? generate_board_url() : $this->vars['U_BOARD'];
    207                 $this->vars['EMAIL_SIG'] = (!isset($this->vars['EMAIL_SIG'])) ? str_replace('<br />', "\n", "-- \n" . htmlspecialchars_decode($config['board_email_sig'])) : $this->vars['EMAIL_SIG'];
    208                 $this->vars['SITENAME'] = (!isset($this->vars['SITENAME'])) ? htmlspecialchars_decode($config['sitename']) : $this->vars['SITENAME'];
    209 
    210                 // Escape all quotes, else the eval will fail.
    211                 $this->msg = str_replace ("'", "\'", $this->msg);
    212                 $this->msg = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "' . ((isset(\$this->vars['\\1'])) ? \$this->vars['\\1'] : '') . '", $this->msg);
    213 
    214                 eval("\$this->msg = '$this->msg';");
     260                if (!isset($this->vars['U_BOARD']))
     261                {
     262                        $this->assign_vars(array(
     263                                'U_BOARD'       => generate_board_url(),
     264                        ));
     265                }
     266
     267                if (!isset($this->vars['EMAIL_SIG']))
     268                {
     269                        $this->assign_vars(array(
     270                                'EMAIL_SIG'     => str_replace('<br />', "\n", "-- \n" . htmlspecialchars_decode($config['board_email_sig'])),
     271                        ));
     272                }
     273
     274                if (!isset($this->vars['SITENAME']))
     275                {
     276                        $this->assign_vars(array(
     277                                'SITENAME'      => htmlspecialchars_decode($config['sitename']),
     278                        ));
     279                }
     280
     281                // Parse message through template
     282                $this->msg = trim($this->tpl_obj->assign_display('body'));
     283
     284                // Because we use \n for newlines in the body message we need to fix line encoding errors for those admins who uploaded email template files in the wrong encoding
     285                $this->msg = str_replace("\r\n", "\n", $this->msg);
    215286
    216287                // We now try and pull a subject from the email body ... if it exists,
     
    310381                global $config;
    311382
     383                // We could use keys here, but we won't do this for 3.0.x to retain backwards compatibility
    312384                $headers = array();
    313385
     
    335407                $headers[] = 'X-Priority: ' . $this->mail_priority;
    336408                $headers[] = 'X-MSMail-Priority: ' . (($this->mail_priority == MAIL_LOW_PRIORITY) ? 'Low' : (($this->mail_priority == MAIL_NORMAL_PRIORITY) ? 'Normal' : 'High'));
    337                 $headers[] = 'X-Mailer: PhpBB3';
     409                $headers[] = 'X-Mailer: phpBB3';
    338410                $headers[] = 'X-MimeOLE: phpBB3';
    339411                $headers[] = 'X-phpBB-Origin: phpbb://' . str_replace(array('http://', 'https://'), array('', ''), generate_board_url());
    340412
    341                 // We use \n here instead of \r\n because our smtp mailer is adjusting it to \r\n automatically, whereby the php mail function only works
    342                 // if using \n.
    343 
    344413                if (sizeof($this->extra_headers))
    345414                {
    346                         $headers[] = implode("\n", $this->extra_headers);
    347                 }
    348 
    349                 return implode("\n", $headers);
     415                        $headers = array_merge($headers, $this->extra_headers);
     416                }
     417
     418                return $headers;
    350419        }
    351420
     
    360429                {
    361430                        return false;
     431                }
     432
     433                // Addresses to send to?
     434                if (empty($this->addresses) || (empty($this->addresses['to']) && empty($this->addresses['cc']) && empty($this->addresses['bcc'])))
     435                {
     436                        // Send was successful. ;)
     437                        return true;
    362438                }
    363439
     
    382458                        $this->from = '<' . $config['board_contact'] . '>';
    383459                }
     460
     461                $encode_eol = ($config['smtp_delivery']) ? "\r\n" : $this->eol;
    384462
    385463                // Build to, cc and bcc strings
     
    394472                        foreach ($address_ary as $which_ary)
    395473                        {
    396                                 $$type .= (($$type != '') ? ', ' : '') . (($which_ary['name'] != '') ? '"' . mail_encode($which_ary['name']) . '" <' . $which_ary['email'] . '>' : $which_ary['email']);
     474                                $$type .= (($$type != '') ? ', ' : '') . (($which_ary['name'] != '') ? mail_encode($which_ary['name'], $encode_eol) . ' <' . $which_ary['email'] . '>' : $which_ary['email']);
    397475                        }
    398476                }
     
    413491                        else
    414492                        {
    415                                 ob_start();
    416                                 $result = $config['email_function_name']($mail_to, mail_encode($this->subject), wordwrap(utf8_wordwrap($this->msg), 997, "\n", true), $headers);
    417                                 $err_msg = ob_get_clean();
     493                                $result = phpbb_mail($mail_to, $this->subject, $this->msg, $headers, $this->eol, $err_msg);
    418494                        }
    419495
     
    452528                if (empty($this->addresses['im']))
    453529                {
    454                         return false;
     530                        // Send was successful. ;)
     531                        return true;
    455532                }
    456533
     
    520597        var $package_size = 0;
    521598        var $cache_file = '';
     599        var $eol = "\n";
    522600
    523601        /**
     
    530608                $this->data = array();
    531609                $this->cache_file = "{$phpbb_root_path}cache/queue.$phpEx";
     610
     611                // Determine EOL character (\n for UNIX, \r\n for Windows and \r for Mac)
     612                $this->eol = (!defined('PHP_EOL')) ? (($eol = strtolower(substr(PHP_OS, 0, 3))) == 'win') ? "\r\n" : (($eol == 'mac') ? "\r" : "\n") : PHP_EOL;
     613                $this->eol = (!$this->eol) ? "\n" : $this->eol;
    532614        }
    533615
     
    652734                                                else
    653735                                                {
    654                                                         ob_start();
    655                                                         $result = $config['email_function_name']($to, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $headers);
    656                                                         $err_msg = ob_get_clean();
     736                                                        $result = phpbb_mail($to, $subject, $msg, $headers, $this->eol, $err_msg);
    657737                                                }
    658738
     
    705785                        {
    706786                                @flock($fp, LOCK_EX);
    707                                 fwrite($fp, "<?php\n\$this->queue_data = unserialize(" . var_export(serialize($this->queue_data), true) . ");\n\n?>");
     787                                fwrite($fp, "<?php\nif (!defined('IN_PHPBB')) exit;\n\$this->queue_data = unserialize(" . var_export(serialize($this->queue_data), true) . ");\n\n?>");
    708788                                @flock($fp, LOCK_UN);
    709789                                fclose($fp);
    710790
    711                                 phpbb_chmod($this->cache_file, CHMOD_WRITE);
     791                                phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);
    712792                        }
    713793                }
     
    746826                {
    747827                        @flock($fp, LOCK_EX);
    748                         fwrite($fp, "<?php\n\$this->queue_data = unserialize(" . var_export(serialize($this->data), true) . ");\n\n?>");
     828                        fwrite($fp, "<?php\nif (!defined('IN_PHPBB')) exit;\n\$this->queue_data = unserialize(" . var_export(serialize($this->data), true) . ");\n\n?>");
    749829                        @flock($fp, LOCK_UN);
    750830                        fclose($fp);
    751831
    752                         phpbb_chmod($this->cache_file, CHMOD_WRITE);
     832                        phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);
    753833                }
    754834        }
     
    758838* Replacement or substitute for PHP's mail command
    759839*/
    760 function smtpmail($addresses, $subject, $message, &$err_msg, $headers = '')
     840function smtpmail($addresses, $subject, $message, &$err_msg, $headers = false)
    761841{
    762842        global $config, $user;
     
    765845        $message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
    766846
    767         if ($headers != '')
    768         {
    769                 if (is_array($headers))
    770                 {
    771                         $headers = (sizeof($headers) > 1) ? join("\n", $headers) : $headers[0];
    772                 }
    773                 $headers = chop($headers);
    774 
    775                 // Make sure there are no bare linefeeds in the headers
    776                 $headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers);
     847        if ($headers !== false)
     848        {
     849                if (!is_array($headers))
     850                {
     851                        // Make sure there are no bare linefeeds in the headers
     852                        $headers = preg_replace('#(?<!\r)\n#si', "\n", $headers);
     853                        $headers = explode("\n", $headers);
     854                }
    777855
    778856                // Ok this is rather confusing all things considered,
    779857                // but we have to grab bcc and cc headers and treat them differently
    780858                // Something we really didn't take into consideration originally
    781                 $header_array = explode("\r\n", $headers);
    782                 $headers = '';
    783 
    784                 foreach ($header_array as $header)
     859                $headers_used = array();
     860
     861                foreach ($headers as $header)
    785862                {
    786863                        if (strpos(strtolower($header), 'cc:') === 0 || strpos(strtolower($header), 'bcc:') === 0)
    787864                        {
    788                                 $header = '';
    789                         }
    790                         $headers .= ($header != '') ? $header . "\r\n" : '';
    791                 }
    792 
    793                 $headers = chop($headers);
     865                                continue;
     866                        }
     867                        $headers_used[] = trim($header);
     868                }
     869
     870                $headers = chop(implode("\r\n", $headers_used));
    794871        }
    795872
     
    9471024
    9481025        // Now any custom headers....
    949         $smtp->server_send("$headers\r\n");
     1026        if ($headers !== false)
     1027        {
     1028                $smtp->server_send("$headers\r\n");
     1029        }
    9501030
    9511031        // Ok now we are ready for the message...
     
    10681148
    10691149                $err_msg = '';
    1070                 $local_host = (function_exists('php_uname')) ? php_uname('n') : $user->host;
     1150
     1151                // Here we try to determine the *real* hostname (reverse DNS entry preferrably)
     1152                $local_host = $user->host;
     1153
     1154                if (function_exists('php_uname'))
     1155                {
     1156                        $local_host = php_uname('n');
     1157
     1158                        // Able to resolve name to IP
     1159                        if (($addr = @gethostbyname($local_host)) !== $local_host)
     1160                        {
     1161                                // Able to resolve IP back to name
     1162                                if (($name = @gethostbyaddr($addr)) !== $addr)
     1163                                {
     1164                                        $local_host = $name;
     1165                                }
     1166                        }
     1167                }
    10711168
    10721169                // If we are authenticating through pop-before-smtp, we
     
    14061503*
    14071504* Please note that this version fully supports RFC 2045 section 6.8.
     1505*
     1506* @param string $eol End of line we are using (optional to be backwards compatible)
    14081507*/
    1409 function mail_encode($str)
     1508function mail_encode($str, $eol = "\r\n")
    14101509{
    14111510        // define start delimimter, end delimiter and spacer
    14121511        $start = "=?UTF-8?B?";
    14131512        $end = "?=";
    1414         $spacer = $end . ' ' . $start;
    1415         $split_length = 64;
    1416 
     1513        $delimiter = "$eol ";
     1514
     1515        // Maximum length is 75. $split_length *must* be a multiple of 4, but <= 75 - strlen($start . $delimiter . $end)!!!
     1516        $split_length = 60;
    14171517        $encoded_str = base64_encode($str);
    14181518
     
    14261526        if (strlen($str) === utf8_strlen($str))
    14271527        {
    1428                 return $start . implode($spacer, str_split($encoded_str, $split_length)) . $end;
     1528                return $start . implode($end . $delimiter . $start, str_split($encoded_str, $split_length)) . $end;
    14291529        }
    14301530
     
    14421542                }
    14431543
    1444                 $str .= $start . base64_encode($text) . $end . ' ';
    1445         }
    1446 
    1447         return substr($str, 0, -1);
     1544                $str .= $start . base64_encode($text) . $end . $delimiter;
     1545        }
     1546
     1547        return substr($str, 0, -strlen($delimiter));
    14481548}
    14491549
     1550/**
     1551* Wrapper for sending out emails with the PHP's mail function
     1552*/
     1553function phpbb_mail($to, $subject, $msg, $headers, $eol, &$err_msg)
     1554{
     1555        global $config;
     1556
     1557        // We use the EOL character for the OS here because the PHP mail function does not correctly transform line endings. On Windows SMTP is used (SMTP is \r\n), on UNIX a command is used...
     1558        // Reference: http://bugs.php.net/bug.php?id=15841
     1559        $headers = implode($eol, $headers);
     1560
     1561        ob_start();
     1562        // On some PHP Versions mail() *may* fail if there are newlines within the subject.
     1563        // Newlines are used as a delimiter for lines in mail_encode() according to RFC 2045 section 6.8.
     1564        // Because PHP can't decide what is wanted we revert back to the non-RFC-compliant way of separating by one space (Use '' as parameter to mail_encode() results in SPACE used)
     1565        $result = $config['email_function_name']($to, mail_encode($subject, ''), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $headers);
     1566        $err_msg = ob_get_clean();
     1567
     1568        return $result;
     1569}
     1570
    14501571?>
  • trunk/forum/includes/functions_posting.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_posting.php 9166 2008-12-03 16:40:53Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    2525        global $phpEx, $phpbb_root_path;
    2626
     27        $start = request_var('start', 0);
     28
    2729        if ($mode == 'window')
    2830        {
     
    4547                page_header($user->lang['SMILIES']);
    4648
     49                $sql = 'SELECT COUNT(smiley_id) AS item_count
     50                        FROM ' . SMILIES_TABLE . '
     51                        GROUP BY smiley_url';
     52                $result = $db->sql_query($sql, 3600);
     53
     54                $smiley_count = 0;
     55                while ($row = $db->sql_fetchrow($result))
     56                {
     57                        ++$smiley_count;
     58                }
     59                $db->sql_freeresult($result);
     60
    4761                $template->set_filenames(array(
    4862                        'body' => 'posting_smilies.html')
     63                );
     64
     65                $template->assign_var('PAGINATION',
     66                        generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&amp;f=' . $forum_id),
     67                                $smiley_count, $config['smilies_per_page'], $start, true)
    4968                );
    5069        }
     
    6584        }
    6685
    67         $last_url = '';
    68 
    69         $sql = 'SELECT *
    70                 FROM ' . SMILIES_TABLE .
    71                 (($mode == 'inline') ? ' WHERE display_on_posting = 1 ' : '') . '
    72                 ORDER BY smiley_order';
    73         $result = $db->sql_query($sql, 3600);
     86        if ($mode == 'window')
     87        {
     88                $sql = 'SELECT smiley_url, MIN(emotion) as emotion, MIN(code) AS code, smiley_width, smiley_height
     89                        FROM ' . SMILIES_TABLE . '
     90                        GROUP BY smiley_url, smiley_width, smiley_height
     91                        ORDER BY MIN(smiley_order)';
     92                $result = $db->sql_query_limit($sql, $config['smilies_per_page'], $start, 3600);
     93        }
     94        else
     95        {
     96                $sql = 'SELECT *
     97                        FROM ' . SMILIES_TABLE . '
     98                        WHERE display_on_posting = 1
     99                        ORDER BY smiley_order';
     100                $result = $db->sql_query($sql, 3600);
     101        }
    74102
    75103        $smilies = array();
     
    85113        if (sizeof($smilies))
    86114        {
     115                $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path;
     116
    87117                foreach ($smilies as $row)
    88118                {
     
    90120                                'SMILEY_CODE'   => $row['code'],
    91121                                'A_SMILEY_CODE' => addslashes($row['code']),
    92                                 'SMILEY_IMG'    => $phpbb_root_path . $config['smilies_path'] . '/' . $row['smiley_url'],
     122                                'SMILEY_IMG'    => $root_path . $config['smilies_path'] . '/' . $row['smiley_url'],
    93123                                'SMILEY_WIDTH'  => $row['smiley_width'],
    94124                                'SMILEY_HEIGHT' => $row['smiley_height'],
     
    615645
    616646        // Do not create a thumbnail if the resulting width/height is bigger than the original one
    617         if ($new_width > $width && $new_height > $height)
     647        if ($new_width >= $width && $new_height >= $height)
    618648        {
    619649                return false;
     
    630660                }
    631661
    632                 @passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $destination) . '"');
     662                @passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -quality 85 -geometry ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" "' . str_replace('\\', '/', $destination) . '"');
    633663
    634664                if (file_exists($destination))
     
    657687
    658688                                case IMG_JPG:
     689                                        @ini_set('gd.jpeg_ignore_warning', 1);
    659690                                        $image = @imagecreatefromjpeg($source);
    660691                                break;
     
    667698                                        $image = @imagecreatefromwbmp($source);
    668699                                break;
     700                        }
     701
     702                        if (empty($image))
     703                        {
     704                                return false;
    669705                        }
    670706
     
    752788                foreach ($attachment_data as $i => $attachment)
    753789                {
    754                         $s_inline_attachment_options .= '<option value="' . $i . '">' . basename($attachment['real_filename']) . '</option>';
     790                        $s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . '</option>';
    755791                }
    756792
     
    786822                {
    787823                        $hidden = '';
    788                         $attach_row['real_filename'] = basename($attach_row['real_filename']);
     824                        $attach_row['real_filename'] = utf8_basename($attach_row['real_filename']);
    789825
    790826                        foreach ($attach_row as $key => $value)
     
    796832
    797833                        $template->assign_block_vars('attach_row', array(
    798                                 'FILENAME'                      => basename($attach_row['real_filename']),
    799                                 'A_FILENAME'            => addslashes(basename($attach_row['real_filename'])),
     834                                'FILENAME'                      => utf8_basename($attach_row['real_filename']),
     835                                'A_FILENAME'            => addslashes(utf8_basename($attach_row['real_filename'])),
    800836                                'FILE_COMMENT'          => $attach_row['attach_comment'],
    801837                                'ATTACH_ID'                     => $attach_row['attach_id'],
     
    819855* Load Drafts
    820856*/
    821 function load_drafts($topic_id = 0, $forum_id = 0, $id = 0)
     857function load_drafts($topic_id = 0, $forum_id = 0, $id = 0, $pm_action = '', $msg_id = 0)
    822858{
    823859        global $user, $db, $template, $auth;
     
    912948                        // Either display as PM draft if forum_id and topic_id are empty or if access to the forums has been denied afterwards...
    913949                        $link_pm = true;
    914                         $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d={$draft['draft_id']}");
     950                        $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=compose&amp;d={$draft['draft_id']}" . (($pm_action) ? "&amp;action=$pm_action" : '') . (($msg_id) ? "&amp;p=$msg_id" : ''));
    915951                }
    916952
     
    945981                        " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . '
    946982                        ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . '
     983                        ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . '
    947984                ORDER BY p.post_time ';
    948985        $sql .= ($mode == 'post_review') ? 'ASC' : 'DESC';
     
    9631000        }
    9641001
     1002        // Handle 'post_review_edit' like 'post_review' from now on
     1003        if ($mode == 'post_review_edit')
     1004        {
     1005                $mode = 'post_review';
     1006        }
     1007
    9651008        $sql = $db->sql_build_query('SELECT', array(
    966                 'SELECT'        => 'u.username, u.user_id, u.user_colour, p.*',
     1009                'SELECT'        => 'u.username, u.user_id, u.user_colour, p.*, z.friend, z.foe',
    9671010
    9681011                'FROM'          => array(
    9691012                        USERS_TABLE             => 'u',
    9701013                        POSTS_TABLE             => 'p',
     1014                ),
     1015
     1016                'LEFT_JOIN'     => array(
     1017                        array(
     1018                                'FROM'  => array(ZEBRA_TABLE => 'z'),
     1019                                'ON'    => 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id'
     1020                        )
    9711021                ),
    9721022
     
    10611111                $post_subject = censor_text($post_subject);
    10621112
     1113                $post_anchor = ($mode == 'post_review') ? 'ppr' . $row['post_id'] : 'pr' . $row['post_id'];
     1114                $u_show_post = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, "f=$forum_id&amp;t=$topic_id&amp;p={$row['post_id']}&amp;view=show#p{$row['post_id']}");
     1115
    10631116                $template->assign_block_vars($mode . '_row', array(
    10641117                        'POST_AUTHOR_FULL'              => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
     
    10681121
    10691122                        'S_HAS_ATTACHMENTS'     => (!empty($attachments[$row['post_id']])) ? true : false,
     1123                        'S_FRIEND'                      => ($row['friend']) ? true : false,
     1124                        'S_IGNORE_POST'         => ($row['foe']) ? true : false,
     1125                        'L_IGNORE_POST'         => ($row['foe']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), "<a href=\"{$u_show_post}\" onclick=\"dE('{$post_anchor}', 1); return false;\">", '</a>') : '',
    10701126
    10711127                        'POST_SUBJECT'          => $post_subject,
     
    11141170        if (!$topic_notification && !$forum_notification)
    11151171        {
    1116                 trigger_error('WRONG_NOTIFICATION_MODE');
     1172                trigger_error('NO_MODE');
    11171173        }
    11181174
     
    15021558        }
    15031559
     1560        if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post'))
     1561        {
     1562                $sql = 'SELECT 1 AS has_attachments
     1563                        FROM ' . ATTACHMENTS_TABLE . '
     1564                        WHERE topic_id = ' . $topic_id;
     1565                $result = $db->sql_query_limit($sql, 1);
     1566                $has_attachments = (int) $db->sql_fetchfield('has_attachments');
     1567                $db->sql_freeresult($result);
     1568
     1569                if (!$has_attachments)
     1570                {
     1571                        $sql_data[TOPICS_TABLE] .= ', topic_attachment = 0';
     1572                }
     1573        }
     1574
    15041575//      $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : '';
    15051576
     
    15531624/**
    15541625* Submit Post
     1626* @todo Split up and create lightweight, simple API for this.
    15551627*/
    1556 function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true)
     1628function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true)
    15571629{
    15581630        global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path;
     
    16061678
    16071679        // This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval
     1680        // The variable name should be $post_approved, because it indicates if the post is approved or not
    16081681        $post_approval = 1;
    16091682
    1610         // Check the permissions for post approval, as well as the queue trigger where users are put on approval with a post count lower than specified. Moderators are not affected.
    1611         if ((($config['enable_queue_trigger'] && $user->data['user_posts'] < $config['queue_trigger_posts']) || !$auth->acl_get('f_noapprove', $data['forum_id'])) && !$auth->acl_get('m_approve', $data['forum_id']))
    1612         {
     1683        // Check the permissions for post approval. Moderators are not affected.
     1684        if (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id']))
     1685        {
     1686                // Post not approved, but in queue
    16131687                $post_approval = 0;
     1688        }
     1689
     1690        // Mods are able to force approved/unapproved posts. True means the post is approved, false the post is unapproved
     1691        if (isset($data['force_approved_state']))
     1692        {
     1693                $post_approval = ($data['force_approved_state']) ? 1 : 0;
    16141694        }
    16151695
     
    17261806                                'topic_poster'                          => (int) $user->data['user_id'],
    17271807                                'topic_time'                            => $current_time,
     1808                                'topic_last_view_time'          => $current_time,
    17281809                                'forum_id'                                      => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'],
    17291810                                'icon_id'                                       => $data['icon_id'],
     
    17391820                        if (isset($poll['poll_options']) && !empty($poll['poll_options']))
    17401821                        {
     1822                                $poll_start = ($poll['poll_start']) ? $poll['poll_start'] : $current_time;
     1823                                $poll_length = $poll['poll_length'] * 86400;
     1824                                if ($poll_length < 0)
     1825                                {
     1826                                        $poll_start = $poll_start + $poll_length;
     1827                                        if ($poll_start < 0)
     1828                                        {
     1829                                                $poll_start = 0;
     1830                                        }
     1831                                        $poll_length = 1;
     1832                                }
     1833
    17411834                                $sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array(
    17421835                                        'poll_title'            => $poll['poll_title'],
    1743                                         'poll_start'            => ($poll['poll_start']) ? $poll['poll_start'] : $current_time,
     1836                                        'poll_start'            => $poll_start,
    17441837                                        'poll_max_options'      => $poll['poll_max_options'],
    1745                                         'poll_length'           => ($poll['poll_length'] * 86400),
     1838                                        'poll_length'           => $poll_length,
    17461839                                        'poll_vote_change'      => $poll['poll_vote_change'])
    17471840                                );
     
    17611854
    17621855                case 'reply':
    1763                         $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . (($post_approval) ? ', topic_replies = topic_replies + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : '');
     1856                        $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ',
     1857                                topic_replies_real = topic_replies_real + 1,
     1858                                topic_bumped = 0,
     1859                                topic_bumper = 0' .
     1860                                (($post_approval) ? ', topic_replies = topic_replies + 1' : '') .
     1861                                ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : '');
     1862
    17641863                        $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : '');
    17651864
     
    17721871                case 'edit_topic':
    17731872                case 'edit_first_post':
     1873                        if (isset($poll['poll_options']) && !empty($poll['poll_options']))
     1874                        {
     1875                                $poll_start = ($poll['poll_start']) ? $poll['poll_start'] : $current_time;
     1876                                $poll_length = $poll['poll_length'] * 86400;
     1877                                if ($poll_length < 0)
     1878                                {
     1879                                        $poll_start = $poll_start + $poll_length;
     1880                                        if ($poll_start < 0)
     1881                                        {
     1882                                                $poll_start = 0;
     1883                                        }
     1884                                        $poll_length = 1;
     1885                                }
     1886                        }
    17741887
    17751888                        $sql_data[TOPICS_TABLE]['sql'] = array(
     
    17821895                                'topic_time_limit'                      => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0,
    17831896                                'poll_title'                            => (isset($poll['poll_options'])) ? $poll['poll_title'] : '',
    1784                                 'poll_start'                            => (isset($poll['poll_options'])) ? (($poll['poll_start']) ? $poll['poll_start'] : $current_time) : 0,
     1897                                'poll_start'                            => (isset($poll['poll_options'])) ? $poll_start : 0,
    17851898                                'poll_max_options'                      => (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1,
    1786                                 'poll_length'                           => (isset($poll['poll_options'])) ? ($poll['poll_length'] * 86400) : 0,
     1899                                'poll_length'                           => (isset($poll['poll_options'])) ? $poll_length : 0,
    17871900                                'poll_vote_change'                      => (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0,
     1901                                'topic_last_view_time'          => $current_time,
    17881902
    17891903                                'topic_attachment'                      => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0),
     
    18111925                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1);
    18121926
    1813                                 set_config('num_topics', $config['num_topics'] - 1, true);
    1814                                 set_config('num_posts', $config['num_posts'] - ($topic_row['topic_replies'] + 1), true);
     1927                                set_config_count('num_topics', -1, true);
     1928                                set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true);
    18151929
    18161930                                // Only decrement this post, since this is the one non-approved now
     
    18291943                        if (!$post_approval && $data['post_approved'])
    18301944                        {
    1831                                 $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1';
     1945                                $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time;
    18321946                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1';
    18331947
    1834                                 set_config('num_posts', $config['num_posts'] - 1, true);
     1948                                set_config_count('num_posts', -1, true);
    18351949
    18361950                                if ($auth->acl_get('f_postcount', $data['forum_id']))
     
    20732187                        {
    20742188                                // insert attachment into db
    2075                                 if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
     2189                                if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
    20762190                                {
    20772191                                        continue;
     
    20992213                if ($space_taken && $files_added)
    21002214                {
    2101                         set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
    2102                         set_config('num_files', $config['num_files'] + $files_added, true);
     2215                        set_config_count('upload_dir_size', $space_taken, true);
     2216                        set_config_count('num_files', $files_added, true);
    21032217                }
    21042218        }
     
    23332447                if ($post_mode == 'post')
    23342448                {
    2335                         set_config('num_topics', $config['num_topics'] + 1, true);
    2336                         set_config('num_posts', $config['num_posts'] + 1, true);
     2449                        set_config_count('num_topics', 1, true);
     2450                        set_config_count('num_posts', 1, true);
    23372451                }
    23382452
    23392453                if ($post_mode == 'reply')
    23402454                {
    2341                         set_config('num_posts', $config['num_posts'] + 1, true);
     2455                        set_config_count('num_posts', 1, true);
    23422456                }
    23432457        }
     
    23772491
    23782492        // Index message contents
    2379         if ($update_message && $data['enable_indexing'])
     2493        if ($update_search_index && $data['enable_indexing'])
    23802494        {
    23812495                // Select the search method and do some additional checks to ensure it can actually be utilised
     
    24122526                        $db->sql_query($sql);
    24132527                }
    2414                 else if ($data['notify_set'] && !$data['notify'])
     2528                else if (($config['email_enable'] || $config['jab_enable']) && $data['notify_set'] && !$data['notify'])
    24152529                {
    24162530                        $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
     
    24292543        // Mark this topic as read
    24302544        // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message)
    2431         markread('topic', $data['forum_id'], $data['topic_id'], time());
     2545        markread('topic', (($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']), $data['topic_id'], time());
    24322546
    24332547        //
     
    24372551                        FROM ' . FORUMS_TRACK_TABLE . '
    24382552                        WHERE user_id = ' . $user->data['user_id'] . '
    2439                                 AND forum_id = ' . $data['forum_id'];
     2553                                AND forum_id = ' . (($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']);
    24402554                $result = $db->sql_query($sql);
    24412555                $f_mark_time = (int) $db->sql_fetchfield('mark_time');
     
    24502564        {
    24512565                // Update forum info
    2452                 $sql = 'SELECT forum_last_post_time
    2453                         FROM ' . FORUMS_TABLE . '
    2454                         WHERE forum_id = ' . $data['forum_id'];
     2566                if ($topic_type == POST_GLOBAL)
     2567                {
     2568                        $sql = 'SELECT MAX(topic_last_post_time) as forum_last_post_time
     2569                                FROM ' . TOPICS_TABLE . '
     2570                                WHERE forum_id = 0';
     2571                }
     2572                else
     2573                {
     2574                        $sql = 'SELECT forum_last_post_time
     2575                                FROM ' . FORUMS_TABLE . '
     2576                                WHERE forum_id = ' . $data['forum_id'];
     2577                }
    24552578                $result = $db->sql_query($sql);
    24562579                $forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time');
    24572580                $db->sql_freeresult($result);
    24582581
    2459                 update_forum_tracking_info($data['forum_id'], $forum_last_post_time, $f_mark_time, false);
     2582                update_forum_tracking_info((($topic_type == POST_GLOBAL) ? 0 : $data['forum_id']), $forum_last_post_time, $f_mark_time, false);
    24602583        }
    24612584
  • trunk/forum/includes/functions_privmsgs.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_privmsgs.php 8993 2008-10-10 17:38:17Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    895895                case 'delete_marked':
    896896
     897                        global $auth;
     898
     899                        if (!$auth->acl_get('u_pm_delete'))
     900                        {
     901                                trigger_error('NO_AUTH_DELETE_MESSAGE');
     902                        }
     903
    897904                        if (confirm_box(true))
    898905                        {
     
    11461153                        $sql = 'SELECT user_id, username, user_colour
    11471154                                FROM ' . USERS_TABLE . '
    1148                                 WHERE ' . $db->sql_in_set('user_id', $u) . '
    1149                                         AND user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
     1155                                WHERE ' . $db->sql_in_set('user_id', $u);
    11501156                        $result = $db->sql_query($sql);
    11511157
     
    13511357                                        AND ug.user_pending = 0
    13521358                                        AND u.user_id = ug.user_id
    1353                                         AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')' . 
     1359                                        AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')' .
    13541360                                        $sql_allow_pm;
    13551361                        $result = $db->sql_query($sql);
     
    13571363                        while ($row = $db->sql_fetchrow($result))
    13581364                        {
     1365                                // Additionally, do not include the sender if he is in the group he wants to send to. ;)
     1366                                if ($row['user_id'] === $user->data['user_id'])
     1367                                {
     1368                                        continue;
     1369                                }
     1370
    13591371                                $field = ($data['address_list']['g'][$row['group_id']] == 'to') ? 'to' : 'bcc';
    13601372                                $recipients[$row['user_id']] = $field;
     
    14061418                                'bbcode_uid'            => $data['bbcode_uid'],
    14071419                                'to_address'            => implode(':', $to),
    1408                                 'bcc_address'           => implode(':', $bcc)
     1420                                'bcc_address'           => implode(':', $bcc),
     1421                                'message_reported'      => 0,
    14091422                        );
    14101423                break;
     
    15461559                        {
    15471560                                // insert attachment into db
    1548                                 if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
     1561                                if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
    15491562                                {
    15501563                                        continue;
     
    15721585                if ($space_taken && $files_added)
    15731586                {
    1574                         set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
    1575                         set_config('num_files', $config['num_files'] + $files_added, true);
     1587                        set_config_count('upload_dir_size', $space_taken, true);
     1588                        set_config_count('num_files', $files_added, true);
    15761589                }
    15771590        }
     
    16921705        global $db, $user, $config, $template, $phpbb_root_path, $phpEx, $auth, $bbcode;
    16931706
     1707        // Select all receipts and the author from the pm we currently view, to only display their pm-history
     1708        $sql = 'SELECT author_id, user_id
     1709                FROM ' . PRIVMSGS_TO_TABLE . "
     1710                WHERE msg_id = $msg_id
     1711                        AND folder_id <> " . PRIVMSGS_HOLD_BOX;
     1712        $result = $db->sql_query($sql);
     1713
     1714        $recipients = array();
     1715        while ($row = $db->sql_fetchrow($result))
     1716        {
     1717                $recipients[] = (int) $row['user_id'];
     1718                $recipients[] = (int) $row['author_id'];
     1719        }
     1720        $db->sql_freeresult($result);
     1721        $recipients = array_unique($recipients);
     1722
    16941723        // Get History Messages (could be newer)
    16951724        $sql = 'SELECT t.*, p.*, u.*
     
    16971726                WHERE t.msg_id = p.msg_id
    16981727                        AND p.author_id = u.user_id
    1699                         AND t.folder_id NOT IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ")
     1728                        AND t.folder_id NOT IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ')
     1729                        AND ' . $db->sql_in_set('t.author_id', $recipients, false, true) . "
    17001730                        AND t.user_id = $user_id";
     1731
     1732        // We no longer need those.
     1733        unset($recipients);
    17011734
    17021735        if (!$message_row['root_level'])
     
    17641797        $next_history_pm = $previous_history_pm = $prev_id = 0;
    17651798
    1766         foreach ($rowset as $id => $row)
    1767         {
     1799        // Re-order rowset to be able to get the next/prev message rows...
     1800        $rowset = array_values($rowset);
     1801
     1802        for ($i = 0, $size = sizeof($rowset); $i < $size; $i++)
     1803        {
     1804                $row = &$rowset[$i];
     1805                $id = (int) $row['msg_id'];
     1806
    17681807                $author_id      = $row['author_id'];
    17691808                $folder_id      = (int) $row['folder_id'];
     
    17761815                $decoded_message = false;
    17771816
    1778                 if ($in_post_mode && $auth->acl_get('u_sendpm') && $author_id != ANONYMOUS && $author_id != $user->data['user_id'])
     1817                if ($in_post_mode && $auth->acl_get('u_sendpm') && $author_id != ANONYMOUS)
    17791818                {
    17801819                        $decoded_message = $message;
     
    17961835                if ($id == $msg_id)
    17971836                {
    1798                         $next_history_pm = next($rowset);
    1799                         $next_history_pm = (sizeof($next_history_pm)) ? (int) $next_history_pm['msg_id'] : 0;
     1837                        $next_history_pm = (isset($rowset[$i + 1])) ? (int) $rowset[$i + 1]['msg_id'] : 0;
    18001838                        $previous_history_pm = $prev_id;
    18011839                }
     
    18201858                        'MSG_ID'                        => $row['msg_id'],
    18211859                        'U_VIEW_MESSAGE'        => "$url&amp;f=$folder_id&amp;p=" . $row['msg_id'],
    1822                         'U_QUOTE'                       => (!$in_post_mode && $auth->acl_get('u_sendpm') && $author_id != ANONYMOUS && $author_id != $user->data['user_id']) ? "$url&amp;mode=compose&amp;action=quote&amp;f=" . $folder_id . "&amp;p=" . $row['msg_id'] : '',
     1860                        'U_QUOTE'                       => (!$in_post_mode && $auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&amp;mode=compose&amp;action=quote&amp;f=" . $folder_id . "&amp;p=" . $row['msg_id'] : '',
    18231861                        'U_POST_REPLY_PM'       => ($author_id != $user->data['user_id'] && $author_id != ANONYMOUS && $auth->acl_get('u_sendpm')) ? "$url&amp;mode=compose&amp;action=reply&amp;f=$folder_id&amp;p=" . $row['msg_id'] : '')
    18241862                );
    1825                 unset($rowset[$id]);
     1863                unset($rowset[$i]);
    18261864                $prev_id = $id;
    18271865        }
     
    18591897}
    18601898
     1899/**
     1900* Generates an array of coloured recipient names from a list of PMs - (groups & users)
     1901*
     1902* @param        array   $pm_by_id       An array of rows from PRIVMSGS_TABLE, keys are the msg_ids.
     1903*
     1904* @return       array                           2D Array: array(msg_id => array('username or group string', ...), ...)
     1905*                                                               Usernames are generated with {@link get_username_string get_username_string}
     1906*                                                               Groups are coloured and have a link to the membership page
     1907*/
     1908function get_recipient_strings($pm_by_id)
     1909{
     1910        global $db, $phpbb_root_path, $phpEx, $user;
     1911
     1912        $address_list = $recipient_list = $address = array();
     1913
     1914        $_types = array('u', 'g');
     1915
     1916        foreach ($pm_by_id as $message_id => $row)
     1917        {
     1918                $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
     1919
     1920                foreach ($_types as $ug_type)
     1921                {
     1922                        if (isset($address[$message_id][$ug_type]) && sizeof($address[$message_id][$ug_type]))
     1923                        {
     1924                                foreach ($address[$message_id][$ug_type] as $ug_id => $in_to)
     1925                                {
     1926                                        $recipient_list[$ug_type][$ug_id] = array('name' => $user->lang['NA'], 'colour' => '');
     1927                                }
     1928                        }
     1929                }
     1930        }
     1931
     1932        foreach ($_types as $ug_type)
     1933        {
     1934                if (!empty($recipient_list[$ug_type]))
     1935                {
     1936                        if ($ug_type == 'u')
     1937                        {
     1938                                $sql = 'SELECT user_id as id, username as name, user_colour as colour
     1939                                        FROM ' . USERS_TABLE . '
     1940                                        WHERE ';
     1941                        }
     1942                        else
     1943                        {
     1944                                $sql = 'SELECT group_id as id, group_name as name, group_colour as colour, group_type
     1945                                        FROM ' . GROUPS_TABLE . '
     1946                                        WHERE ';
     1947                        }
     1948                        $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($recipient_list[$ug_type])));
     1949
     1950                        $result = $db->sql_query($sql);
     1951
     1952                        while ($row = $db->sql_fetchrow($result))
     1953                        {
     1954                                if ($ug_type == 'g')
     1955                                {
     1956                                        $row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name'];
     1957                                }
     1958
     1959                                $recipient_list[$ug_type][$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
     1960                        }
     1961                        $db->sql_freeresult($result);
     1962                }
     1963        }
     1964
     1965        foreach ($address as $message_id => $adr_ary)
     1966        {
     1967                foreach ($adr_ary as $type => $id_ary)
     1968                {
     1969                        foreach ($id_ary as $ug_id => $_id)
     1970                        {
     1971                                if ($type == 'u')
     1972                                {
     1973                                        $address_list[$message_id][] = get_username_string('full', $ug_id, $recipient_list[$type][$ug_id]['name'], $recipient_list[$type][$ug_id]['colour']);
     1974                                }
     1975                                else
     1976                                {
     1977                                        $user_colour = ($recipient_list[$type][$ug_id]['colour']) ? ' style="font-weight: bold; color:#' . $recipient_list[$type][$ug_id]['colour'] . '"' : '';
     1978                                        $link = '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $ug_id) . '"' . $user_colour . '>';
     1979                                        $address_list[$message_id][] = $link . $recipient_list[$type][$ug_id]['name'] . (($link) ? '</a>' : '');
     1980                                }
     1981                        }
     1982                }
     1983        }
     1984
     1985        return $address_list;
     1986}
     1987
    18611988?>
  • trunk/forum/includes/functions_profile_fields.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_profile_fields.php 9127 2008-11-26 19:58:35Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4040                {
    4141                        case 'register':
    42                                 // If the field is required we show it on the registration page and do not show hidden fields
    43                                 $sql_where .= ' AND f.field_show_on_reg = 1 AND f.field_no_view = 0';
     42                                // If the field is required we show it on the registration page
     43                                $sql_where .= ' AND f.field_show_on_reg = 1';
    4444                        break;
    4545
     
    9393                switch ($field_type)
    9494                {
    95                         case FIELD_INT:
    96                         case FIELD_DROPDOWN:
    97                                 $field_value = (int) $field_value;
    98                         break;
    99 
    100                         case FIELD_BOOL:
    101                                 $field_value = (bool) $field_value;
    102                         break;
    103                 }
    104 
    105                 switch ($field_type)
    106                 {
    10795                        case FIELD_DATE:
    10896                                $field_validate = explode('-', $field_value);
     
    134122
    135123                        case FIELD_BOOL:
     124                                $field_value = (bool) $field_value;
     125                       
    136126                                if (!$field_value && $field_data['field_required'])
    137127                                {
     
    141131
    142132                        case FIELD_INT:
    143                                 if (empty($field_value) && !$field_data['field_required'])
     133                                if (trim($field_value) === '' && !$field_data['field_required'])
    144134                                {
    145135                                        return false;
    146136                                }
     137                               
     138                                $field_value = (int) $field_value;
    147139
    148140                                if ($field_value < $field_data['field_minlen'])
     
    157149
    158150                        case FIELD_DROPDOWN:
     151                                $field_value = (int) $field_value;
     152                       
    159153                                if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
    160154                                {
     
    165159                        case FIELD_STRING:
    166160                        case FIELD_TEXT:
    167                                 if (empty($field_value) && !$field_data['field_required'])
     161                                if (trim($field_value) === '' && !$field_data['field_required'])
    168162                                {
    169163                                        return false;
    170164                                }
    171                                 else if (empty($field_value) && $field_data['field_required'])
     165                                else if (trim($field_value) === '' && $field_data['field_required'])
    172166                                {
    173167                                        return 'FIELD_REQUIRED';
     
    260254
    261255        /**
    262         * Submit profile field
     256        * Submit profile field for validation
    263257        * @access public
    264258        */
     
    271265                {
    272266                        case 'register':
    273                                 // If the field is required we show it on the registration page and do not show hidden fields
    274                                 $sql_where .= ' AND f.field_show_on_reg = 1 AND f.field_no_view = 0';
     267                                // If the field is required we show it on the registration page
     268                                $sql_where .= ' AND f.field_show_on_reg = 1';
    275269                        break;
    276270
     
    351345
    352346        /**
     347        * Update profile field data directly
     348        */
     349        function update_profile_field_data($user_id, &$cp_data)
     350        {
     351                global $db;
     352
     353                if (!sizeof($cp_data))
     354                {
     355                        return;
     356                }
     357
     358                switch ($db->sql_layer)
     359                {
     360                        case 'oracle':
     361                        case 'firebird':
     362                        case 'postgres':
     363                                $right_delim = $left_delim = '"';
     364                        break;
     365
     366                        case 'sqlite':
     367                        case 'mssql':
     368                        case 'mssql_odbc':
     369                                $right_delim = ']';
     370                                $left_delim = '[';
     371                        break;
     372
     373                        case 'mysql':
     374                        case 'mysql4':
     375                        case 'mysqli':
     376                                $right_delim = $left_delim = '`';
     377                        break;
     378                }
     379
     380                // use new array for the UPDATE; changes in the key do not affect the original array
     381                $cp_data_sql = array();
     382                foreach ($cp_data as $key => $value)
     383                {
     384                        // Firebird is case sensitive with delimiter
     385                        $cp_data_sql[$left_delim . (($db->sql_layer == 'firebird' || $db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value;
     386                }
     387
     388                $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
     389                        SET ' . $db->sql_build_array('UPDATE', $cp_data_sql) . "
     390                        WHERE user_id = $user_id";
     391                $db->sql_query($sql);
     392
     393                if (!$db->sql_affectedrows())
     394                {
     395                        $cp_data_sql['user_id'] = (int) $user_id;
     396
     397                        $db->sql_return_on_error(true);
     398
     399                        $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data_sql);
     400                        $db->sql_query($sql);
     401
     402                        $db->sql_return_on_error(false);
     403                }
     404        }
     405
     406        /**
    353407        * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled)
    354408        * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template
     
    455509                {
    456510                        case 'int':
    457                                 if ($value == '')
     511                                if ($value === '')
    458512                                {
    459513                                        return NULL;
     
    571625                        else
    572626                        {
    573                                 if (!$preview && isset($user->profile_fields[$user_ident]) && is_null($user->profile_fields[$user_ident]))
     627                                if (!$preview && array_key_exists($user_ident, $user->profile_fields) && is_null($user->profile_fields[$user_ident]))
    574628                                {
    575629                                        $value = NULL;
     
    585639                        }
    586640
    587                         return (is_null($value)) ? '' : (int) $value;
     641                        return (is_null($value) || $value === '') ? '' : (int) $value;
    588642                }
    589643                else
  • trunk/forum/includes/functions_template.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_template.php 8813 2008-09-04 11:52:01Z aptx $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    129129                $code = preg_replace('#<!-- PHP -->.*?<!-- ENDPHP -->#s', '<!-- PHP -->', $code);
    130130
    131                 preg_match_all('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
     131                preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
    132132                $include_blocks = $matches[1];
    133                 $code = preg_replace('#<!-- INCLUDE [a-zA-Z0-9\_\-\+\./]+ -->#', '<!-- INCLUDE -->', $code);
     133                $code = preg_replace('#<!-- INCLUDE (?:\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', '<!-- INCLUDE -->', $code);
    134134
    135135                preg_match_all('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
     
    194194                                case 'INCLUDE':
    195195                                        $temp = array_shift($include_blocks);
     196
     197                                        // Dynamic includes
     198                                        // Cheap match rather than a full blown regexp, we already know
     199                                        // the format of the input so just use string manipulation.
     200                                        if ($temp[0] == '{')
     201                                        {
     202                                                $file = false;
     203
     204                                                if ($temp[1] == '$')
     205                                                {
     206                                                        $var = substr($temp, 2, -1);
     207                                                        //$file = $this->template->_tpldata['DEFINE']['.'][$var];
     208                                                        $temp = "\$this->_tpldata['DEFINE']['.']['$var']";
     209                                                }
     210                                                else
     211                                                {
     212                                                        $var = substr($temp, 1, -1);
     213                                                        //$file = $this->template->_rootref[$var];
     214                                                        $temp = "\$this->_rootref['$var']";
     215                                                }
     216                                        }
     217                                        else
     218                                        {
     219                                                $file = $temp;
     220                                        }
     221
    196222                                        $compile_blocks[] = '<?php ' . $this->compile_tag_include($temp) . ' ?>';
    197                                         $this->template->_tpl_include($temp, false);
     223
     224                                        // No point in checking variable includes
     225                                        if ($file)
     226                                        {
     227                                                $this->template->_tpl_include($file, false);
     228                                        }
    198229                                break;
    199230
     
    221252                }
    222253
     254                // Remove unused opening/closing tags
     255                $template_php = str_replace(' ?><?php ', ' ', $template_php);
     256
     257                // Now add a newline after each php closing tag which already has a newline
     258                // PHP itself strips a newline if a closing tag is used (this is documented behaviour) and it is mostly not intended by style authors to remove newlines
     259                $template_php = preg_replace('#\?\>([\r\n])#', '?>\1\1', $template_php);
     260
    223261                // There will be a number of occasions where we switch into and out of
    224262                // PHP mode instantaneously. Rather than "burden" the parser with this
    225263                // we'll strip out such occurences, minimising such switching
    226                 $template_php = str_replace(' ?><?php ', ' ', $template_php);
    227 
    228                 return (!$no_echo) ? $template_php : "\$$echo_var .= '" . $template_php . "'";
     264                if ($no_echo)
     265                {
     266                        return "\$$echo_var .= '" . $template_php . "'";
     267                }
     268
     269                return $template_php;
    229270        }
    230271
     
    254295                if (strpos($text_blocks, '{L_') !== false)
    255296                {
    256                         $text_blocks = preg_replace('#\{L_([a-z0-9\-_]*)\}#is', "<?php echo ((isset(\$this->_rootref['L_\\1'])) ? \$this->_rootref['L_\\1'] : ((isset(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '{ \\1 }')); ?>", $text_blocks);
     297                        $text_blocks = preg_replace('#\{L_([A-Z0-9\-_]+)\}#', "<?php echo ((isset(\$this->_rootref['L_\\1'])) ? \$this->_rootref['L_\\1'] : ((isset(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '{ \\1 }')); ?>", $text_blocks);
    257298                }
    258299
     
    261302                if (strpos($text_blocks, '{LA_') !== false)
    262303                {
    263                         $text_blocks = preg_replace('#\{LA_([a-z0-9\-_]*)\}#is', "<?php echo ((isset(\$this->_rootref['LA_\\1'])) ? \$this->_rootref['LA_\\1'] : ((isset(\$this->_rootref['L_\\1'])) ? addslashes(\$this->_rootref['L_\\1']) : ((isset(\$user->lang['\\1'])) ? addslashes(\$user->lang['\\1']) : '{ \\1 }'))); ?>", $text_blocks);
     304                        $text_blocks = preg_replace('#\{LA_([A-Z0-9\-_]+)\}#', "<?php echo ((isset(\$this->_rootref['LA_\\1'])) ? \$this->_rootref['LA_\\1'] : ((isset(\$this->_rootref['L_\\1'])) ? addslashes(\$this->_rootref['L_\\1']) : ((isset(\$user->lang['\\1'])) ? addslashes(\$user->lang['\\1']) : '{ \\1 }'))); ?>", $text_blocks);
    264305                }
    265306
    266307                // Handle remaining varrefs
    267                 $text_blocks = preg_replace('#\{([a-z0-9\-_]+)\}#is', "<?php echo (isset(\$this->_rootref['\\1'])) ? \$this->_rootref['\\1'] : ''; ?>", $text_blocks);
    268                 $text_blocks = preg_replace('#\{\$([a-z0-9\-_]+)\}#is', "<?php echo (isset(\$this->_tpldata['DEFINE']['.']['\\1'])) ? \$this->_tpldata['DEFINE']['.']['\\1'] : ''; ?>", $text_blocks);
     308                $text_blocks = preg_replace('#\{([A-Z0-9\-_]+)\}#', "<?php echo (isset(\$this->_rootref['\\1'])) ? \$this->_rootref['\\1'] : ''; ?>", $text_blocks);
     309                $text_blocks = preg_replace('#\{\$([A-Z0-9\-_]+)\}#', "<?php echo (isset(\$this->_tpldata['DEFINE']['.']['\\1'])) ? \$this->_tpldata['DEFINE']['.']['\\1'] : ''; ?>", $text_blocks);
    269310
    270311                return;
     
    592633        function compile_tag_include($tag_args)
    593634        {
     635                // Process dynamic includes
     636                if ($tag_args[0] == '$')
     637                {
     638                        return "if (isset($tag_args)) { \$this->_tpl_include($tag_args); }";
     639                }
     640
    594641                return "\$this->_tpl_include('$tag_args');";
    595642        }
     
    601648        function compile_tag_include_php($tag_args)
    602649        {
    603                 return "include('" . $tag_args . "');";
     650                return "\$this->_php_include('$tag_args');";
    604651        }
    605652
     
    749796                $filename = $this->template->cachepath . str_replace('/', '.', $this->template->filename[$handle]) . '.' . $phpEx;
    750797
     798                $data = "<?php if (!defined('IN_PHPBB')) exit;" . ((strpos($data, '<?php') === 0) ? substr($data, 5) : ' ?>' . $data);
     799
    751800                if ($fp = @fopen($filename, 'wb'))
    752801                {
     
    756805                        @fclose($fp);
    757806
    758                         phpbb_chmod($filename, CHMOD_WRITE);
     807                        phpbb_chmod($filename, CHMOD_READ | CHMOD_WRITE);
    759808                }
    760809
  • trunk/forum/includes/functions_transfer.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_transfer.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    207207
    208208                $this->_chdir($directory);
    209                 $result = $this->_ls('');
     209                $result = $this->_ls();
    210210
    211211                if ($result !== false && is_array($result))
     
    317317                }
    318318
     319                // login to the server
     320                if (!@ftp_login($this->connection, $this->username, $this->password))
     321                {
     322                        return 'ERR_UNABLE_TO_LOGIN';
     323                }
     324
    319325                // attempt to turn pasv mode on
    320326                @ftp_pasv($this->connection, true);
    321 
    322                 // login to the server
    323                 if (!@ftp_login($this->connection, $this->username, $this->password))
    324                 {
    325                         return 'ERR_UNABLE_TO_LOGIN';
    326                 }
    327327
    328328                // change to the root directory
     
    461461        function _ls($dir = './')
    462462        {
    463                 return @ftp_nlist($this->connection, $dir);
     463                $list = @ftp_nlist($this->connection, $dir);
     464
     465                // See bug #46295 - Some FTP daemons don't like './'
     466                if ($dir === './')
     467                {
     468                        // Let's try some alternatives
     469                        $list = (empty($list)) ? @ftp_nlist($this->connection, '.') : $list;
     470                        $list = (empty($list)) ? @ftp_nlist($this->connection, '') : $list;
     471                }
     472
     473                // Return on error
     474                if ($list === false)
     475                {
     476                        return false;
     477                }
     478
     479                // Remove path if prepended
     480                foreach ($list as $key => $item)
     481                {
     482                        // Use same separator for item and dir
     483                        $item = str_replace('\\', '/', $item);
     484                        $dir = str_replace('\\', '/', $dir);
     485
     486                        if (!empty($dir) && strpos($item, $dir) === 0)
     487                        {
     488                                $item = substr($item, strlen($dir));
     489                        }
     490
     491                        $list[$key] = $item;
     492                }
     493
     494                return $list;
    464495        }
    465496
     
    707738                while (!@feof($this->data_connection))
    708739                {
    709                         $list[] = preg_replace('#[\r\n]#', '', @fgets($this->data_connection, 512));
     740                        $filename = preg_replace('#[\r\n]#', '', @fgets($this->data_connection, 512));
     741
     742                        if ($filename !== '')
     743                        {
     744                                $list[] = $filename;
     745                        }
    710746                }
    711747                $this->_close_data_connection();
     748
     749                // Clear buffer
     750                $this->_check_command();
     751
     752                // See bug #46295 - Some FTP daemons don't like './'
     753                if ($dir === './' && empty($list))
     754                {
     755                        // Let's try some alternatives
     756                        $list = $this->_ls('.');
     757
     758                        if (empty($list))
     759                        {
     760                                $list = $this->_ls('');
     761                        }
     762
     763                        return $list;
     764                }
     765
     766                // Remove path if prepended
     767                foreach ($list as $key => $item)
     768                {
     769                        // Use same separator for item and dir
     770                        $item = str_replace('\\', '/', $item);
     771                        $dir = str_replace('\\', '/', $dir);
     772
     773                        if (!empty($dir) && strpos($item, $dir) === 0)
     774                        {
     775                                $item = substr($item, strlen($dir));
     776                        }
     777
     778                        $list[$key] = $item;
     779                }
    712780
    713781                return $list;
     
    792860                        $response .= $result;
    793861                }
    794                 while (substr($response, 3, 1) != ' ');
     862                while (substr($result, 3, 1) !== ' ');
    795863
    796864                if (!preg_match('#^[123]#', $response))
  • trunk/forum/includes/functions_upload.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_upload.php 8783 2008-08-23 17:23:40Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    5959                $this->filename = $upload_ary['tmp_name'];
    6060                $this->filesize = $upload_ary['size'];
    61                 $name = trim(htmlspecialchars(basename($upload_ary['name'])));
     61                $name = trim(utf8_htmlspecialchars(utf8_basename($upload_ary['name'])));
    6262                $this->realname = $this->uploadname = (STRIP) ? stripslashes($name) : $name;
    6363                $this->mimetype = $upload_ary['type'];
     
    291291                $upload_mode = (@ini_get('open_basedir') || @ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'on') ? 'move' : 'copy';
    292292                $upload_mode = ($this->local) ? 'local' : $upload_mode;
    293                 $this->destination_file = $this->destination_path . '/' . basename($this->realname);
     293                $this->destination_file = $this->destination_path . '/' . utf8_basename($this->realname);
    294294
    295295                // Check if the file already exist, else there is something wrong...
     
    314314                                                {
    315315                                                        $this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'GENERAL_UPLOAD_ERROR'], $this->destination_file);
    316                                                         return false;
    317316                                                }
    318317                                        }
    319 
    320                                         @unlink($this->filename);
    321318
    322319                                break;
     
    329326                                                {
    330327                                                        $this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'GENERAL_UPLOAD_ERROR'], $this->destination_file);
    331                                                         return false;
    332328                                                }
    333329                                        }
    334 
    335                                         @unlink($this->filename);
    336330
    337331                                break;
     
    342336                                        {
    343337                                                $this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'GENERAL_UPLOAD_ERROR'], $this->destination_file);
    344                                                 return false;
    345338                                        }
    346                                         @unlink($this->filename);
    347339
    348340                                break;
     341                        }
     342
     343                        // Remove temporary filename
     344                        @unlink($this->filename);
     345
     346                        if (sizeof($this->error))
     347                        {
     348                                return false;
    349349                        }
    350350
     
    418418                if ($this->upload->max_filesize && ($this->get('filesize') > $this->upload->max_filesize || $this->filesize == 0))
    419419                {
    420                         $size_lang = ($this->upload->max_filesize >= 1048576) ? $user->lang['MIB'] : (($this->upload->max_filesize >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES'] );
    421420                        $max_filesize = get_formatted_filesize($this->upload->max_filesize, false);
    422421
    423                         $this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'WRONG_FILESIZE'], $max_filesize, $size_lang);
     422                        $this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']);
    424423
    425424                        return false;
     
    595594                if ($file->get('filename') == 'none')
    596595                {
    597                         $file->error[] = (@ini_get('upload_max_filesize') == '') ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], @ini_get('upload_max_filesize'));
     596                        $max_filesize = @ini_get('upload_max_filesize');
     597                        $unit = 'MB';
     598
     599                        if (!empty($max_filesize))
     600                        {
     601                                $unit = strtolower(substr($max_filesize, -1, 1));
     602                                $max_filesize = (int) $max_filesize;
     603
     604                                $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
     605                        }
     606
     607                        $file->error[] = (empty($max_filesize)) ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], $max_filesize, $user->lang[$unit]);
    598608                        return $file;
    599609                }
     
    625635                if ($filedata === false)
    626636                {
    627                         $_FILES[$form_name]['name'] = basename($source_file);
     637                        $_FILES[$form_name]['name'] = utf8_basename($source_file);
    628638                        $_FILES[$form_name]['size'] = 0;
    629639                        $mimetype = '';
     
    671681                if ($file->get('filename') == 'none')
    672682                {
    673                         $file->error[] = (@ini_get('upload_max_filesize') == '') ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], @ini_get('upload_max_filesize'));
     683                        $max_filesize = @ini_get('upload_max_filesize');
     684                        $unit = 'MB';
     685
     686                        if (!empty($max_filesize))
     687                        {
     688                                $unit = strtolower(substr($max_filesize, -1, 1));
     689                                $max_filesize = (int) $max_filesize;
     690
     691                                $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
     692                        }
     693
     694                        $file->error[] = (empty($max_filesize)) ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], $max_filesize, $user->lang[$unit]);
    674695                        return $file;
    675696                }
     
    726747
    727748                $url['path'] = implode('', $url['path']);
    728                 $upload_ary['name'] = basename($url['path']) . (($ext) ? '.' . $ext : '');
     749                $upload_ary['name'] = utf8_basename($url['path']) . (($ext) ? '.' . $ext : '');
    729750                $filename = $url['path'];
    730751                $filesize = 0;
     
    819840                {
    820841                        case 1:
    821                                 $error = (@ini_get('upload_max_filesize') == '') ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], @ini_get('upload_max_filesize'));
     842                                $max_filesize = @ini_get('upload_max_filesize');
     843                                $unit = 'MB';
     844
     845                                if (!empty($max_filesize))
     846                                {
     847                                        $unit = strtolower(substr($max_filesize, -1, 1));
     848                                        $max_filesize = (int) $max_filesize;
     849
     850                                        $unit = ($unit == 'k') ? 'KB' : (($unit == 'g') ? 'GB' : 'MB');
     851                                }
     852
     853                                $error = (empty($max_filesize)) ? $user->lang[$this->error_prefix . 'PHP_SIZE_NA'] : sprintf($user->lang[$this->error_prefix . 'PHP_SIZE_OVERRUN'], $max_filesize, $user->lang[$unit]);
    822854                        break;
    823855
    824856                        case 2:
    825                                 $size_lang = ($this->max_filesize >= 1048576) ? $user->lang['MIB'] : (($this->max_filesize >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES']);
    826857                                $max_filesize = get_formatted_filesize($this->max_filesize, false);
    827858
    828                                 $error = sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize, $size_lang);
     859                                $error = sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']);
    829860                        break;
    830861
     
    859890                if ($this->max_filesize && ($file->get('filesize') > $this->max_filesize || $file->get('filesize') == 0))
    860891                {
    861                         $size_lang = ($this->max_filesize >= 1048576) ? $user->lang['MIB'] : (($this->max_filesize >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES']);
    862892                        $max_filesize = get_formatted_filesize($this->max_filesize, false);
    863893
    864                         $file->error[] = sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize, $size_lang);
     894                        $file->error[] = sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']);
    865895                }
    866896
  • trunk/forum/includes/functions_user.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_user.php 8949 2008-09-26 21:29:05Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    172172                'user_pass_convert'     => 0,
    173173                'user_email'            => strtolower($user_row['user_email']),
    174                 'user_email_hash'       => crc32(strtolower($user_row['user_email'])) . strlen($user_row['user_email']),
     174                'user_email_hash'       => phpbb_email_hash($user_row['user_email']),
    175175                'group_id'                      => $user_row['group_id'],
    176176                'user_type'                     => $user_row['user_type'],
     
    188188                'user_regdate'          => time(),
    189189                'user_passchg'          => time(),
    190                 'user_options'          => 895,
     190                'user_options'          => 230271,
     191                // We do not set the new flag here - registration scripts need to specify it
     192                'user_new'                      => 0,
    191193
    192194                'user_inactive_reason'  => 0,
     
    276278        group_set_user_default($user_row['group_id'], array($user_id), false);
    277279
     280        // Add to newly registered users group if user_new is 1
     281        if ($config['new_member_post_limit'] && $sql_ary['user_new'])
     282        {
     283                $sql = 'SELECT group_id
     284                        FROM ' . GROUPS_TABLE . "
     285                        WHERE group_name = 'NEWLY_REGISTERED'
     286                                AND group_type = " . GROUP_SPECIAL;
     287                $result = $db->sql_query($sql);
     288                $add_group_id = (int) $db->sql_fetchfield('group_id');
     289                $db->sql_freeresult($result);
     290
     291                if ($add_group_id)
     292                {
     293                        // Because these actions only fill the log unneccessarily we skip the add_log() entry with a little hack. :/
     294                        $GLOBALS['skip_add_log'] = true;
     295
     296                        // Add user to "newly registered users" group and set to default group if admin specified so.
     297                        if ($config['new_member_group_default'])
     298                        {
     299                                group_user_add($add_group_id, $user_id, false, false, true);
     300                        }
     301                        else
     302                        {
     303                                group_user_add($add_group_id, $user_id);
     304                        }
     305
     306                        unset($GLOBALS['skip_add_log']);
     307                }
     308        }
     309
    278310        // set the newest user and adjust the user count if the user is a normal user and no activation mail is sent
    279         if ($user_row['user_type'] == USER_NORMAL)
     311        if ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_FOUNDER)
    280312        {
    281313                set_config('newest_user_id', $user_id, true);
    282314                set_config('newest_username', $user_row['username'], true);
    283                 set_config('num_users', $config['num_users'] + 1, true);
     315                set_config_count('num_users', 1, true);
    284316
    285317                $sql = 'SELECT group_colour
     
    420452                                        SET topic_last_poster_id = ' . ANONYMOUS . ", topic_last_poster_name = '" . $db->sql_escape($post_username) . "', topic_last_poster_colour = ''
    421453                                        WHERE topic_last_poster_id = $user_id";
     454                                $db->sql_query($sql);
     455
     456                                $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
     457                                        SET poster_id = ' . ANONYMOUS . "
     458                                        WHERE poster_id = $user_id";
    422459                                $db->sql_query($sql);
    423460
     
    491528        $db->sql_transaction('begin');
    492529
    493         $table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, FORUMS_TRACK_TABLE, PROFILE_FIELDS_DATA_TABLE, MODERATOR_CACHE_TABLE, DRAFTS_TABLE, BOOKMARKS_TABLE);
     530        $table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, FORUMS_TRACK_TABLE, PROFILE_FIELDS_DATA_TABLE, MODERATOR_CACHE_TABLE, DRAFTS_TABLE, BOOKMARKS_TABLE, SESSIONS_KEYS_TABLE);
    494531
    495532        foreach ($table_ary as $table)
     
    501538
    502539        $cache->destroy('sql', MODERATOR_CACHE_TABLE);
     540
     541        // Delete user log entries about this user
     542        $sql = 'DELETE FROM ' . LOG_TABLE . '
     543                WHERE reportee_id = ' . $user_id;
     544        $db->sql_query($sql);
     545
     546        // Change user_id to anonymous for this users triggered events
     547        $sql = 'UPDATE ' . LOG_TABLE . '
     548                SET user_id = ' . ANONYMOUS . '
     549                WHERE user_id = ' . $user_id;
     550        $db->sql_query($sql);
     551
     552        // Delete the user_id from the zebra table
     553        $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
     554                WHERE user_id = ' . $user_id . '
     555                        OR zebra_id = ' . $user_id;
     556        $db->sql_query($sql);
     557
     558        // Delete the user_id from the banlist
     559        $sql = 'DELETE FROM ' . BANLIST_TABLE . '
     560                WHERE ban_userid = ' . $user_id;
     561        $db->sql_query($sql);
     562
     563        // Delete the user_id from the session table
     564        $sql = 'DELETE FROM ' . SESSIONS_TABLE . '
     565                WHERE session_user_id = ' . $user_id;
     566        $db->sql_query($sql);
    503567
    504568        // Remove any undelivered mails...
     
    570634        if ($user_row['user_type'] != USER_INACTIVE && $user_row['user_type'] != USER_IGNORE)
    571635        {
    572                 set_config('num_users', $config['num_users'] - 1, true);
     636                set_config_count('num_users', -1, true);
    573637        }
    574638
     
    651715        if ($deactivated)
    652716        {
    653                 set_config('num_users', $config['num_users'] - $deactivated, true);
     717                set_config_count('num_users', $deactivated * (-1), true);
    654718        }
    655719
    656720        if ($activated)
    657721        {
    658                 set_config('num_users', $config['num_users'] + $activated, true);
     722                set_config_count('num_users', $activated, true);
    659723        }
    660724
     
    895959                                        }
    896960                                }
    897                                 else
     961
     962                                if (empty($banlist_ary))
    898963                                {
    899964                                        trigger_error('NO_IPS_DEFINED');
     
    9681033                while ($row = $db->sql_fetchrow($result));
    9691034
    970                 $banlist_ary = array_unique(array_diff($banlist_ary, $banlist_ary_tmp));
     1035                $banlist_ary_tmp = array_intersect($banlist_ary, $banlist_ary_tmp);
     1036
     1037                if (sizeof($banlist_ary_tmp))
     1038                {
     1039                        // One or more entities are already banned/excluded, delete the existing bans, so they can be re-inserted with the given new length
     1040                        $sql = 'DELETE FROM ' . BANLIST_TABLE . '
     1041                                WHERE ' . $db->sql_in_set($type, $banlist_ary_tmp) . '
     1042                                        AND ban_exclude = ' . (int) $ban_exclude;
     1043                        $db->sql_query($sql);
     1044                }
     1045
    9711046                unset($banlist_ary_tmp);
    9721047        }
     
    10511126                $log_entry = ($ban_exclude) ? 'LOG_BAN_EXCLUDE_' : 'LOG_BAN_';
    10521127
    1053                 // Add to moderator and admin log
     1128                // Add to moderator log, admin log and user notes
    10541129                add_log('admin', $log_entry . strtoupper($mode), $ban_reason, $ban_list_log);
    10551130                add_log('mod', 0, 0, $log_entry . strtoupper($mode), $ban_reason, $ban_list_log);
     1131                if ($mode == 'user')
     1132                {
     1133                        foreach ($banlist_ary as $user_id)
     1134                        {
     1135                                add_log('user', $user_id, $log_entry . strtoupper($mode), $ban_reason, $ban_list_log);
     1136                        }
     1137                }
    10561138
    10571139                $cache->destroy('sql', BANLIST_TABLE);
     
    10921174                {
    10931175                        case 'user':
    1094                                 $sql = 'SELECT u.username AS unban_info
     1176                                $sql = 'SELECT u.username AS unban_info, u.user_id
    10951177                                        FROM ' . USERS_TABLE . ' u, ' . BANLIST_TABLE . ' b
    10961178                                        WHERE ' . $db->sql_in_set('b.ban_id', $unban_sql) . '
     
    11131195
    11141196                $l_unban_list = '';
     1197                $user_ids_ary = array();
    11151198                while ($row = $db->sql_fetchrow($result))
    11161199                {
    11171200                        $l_unban_list .= (($l_unban_list != '') ? ', ' : '') . $row['unban_info'];
     1201                        if ($mode == 'user')
     1202                        {
     1203                                $user_ids_ary[] = $row['user_id'];
     1204                        }
    11181205                }
    11191206                $db->sql_freeresult($result);
     
    11231210                $db->sql_query($sql);
    11241211
    1125                 // Add to moderator and admin log
     1212                // Add to moderator log, admin log and user notes
    11261213                add_log('admin', 'LOG_UNBAN_' . strtoupper($mode), $l_unban_list);
    11271214                add_log('mod', 0, 0, 'LOG_UNBAN_' . strtoupper($mode), $l_unban_list);
     1215                if ($mode == 'user')
     1216                {
     1217                        foreach ($user_ids_ary as $user_id)
     1218                        {
     1219                                add_log('user', $user_id, 'LOG_UNBAN_' . strtoupper($mode), $l_unban_list);
     1220                        }
     1221                }
    11281222        }
    11291223
     
    11351229/**
    11361230* Whois facility
     1231*
     1232* @link http://tools.ietf.org/html/rfc3912 RFC3912: WHOIS Protocol Specification
    11371233*/
    11381234function user_ipwhois($ip)
     
    11471243        }
    11481244
    1149         $match = array(
    1150                 '#RIPE\.NET#is'                         => 'whois.ripe.net',
    1151                 '#whois\.apnic\.net#is'         => 'whois.apnic.net',
    1152                 '#nic\.ad\.jp#is'                       => 'whois.nic.ad.jp',
    1153                 '#whois\.registro\.br#is'       => 'whois.registro.br'
    1154         );
    1155 
    11561245        if (($fsk = @fsockopen('whois.arin.net', 43)))
    11571246        {
    1158                 fputs($fsk, "$ip\n");
     1247                // CRLF as per RFC3912
     1248                fputs($fsk, "$ip\r\n");
    11591249                while (!feof($fsk))
    11601250                {
     
    11641254        }
    11651255
    1166         foreach (array_keys($match) as $server)
    1167         {
    1168                 if (preg_match($server, $ipwhois))
    1169                 {
    1170                         $ipwhois = '';
    1171                         if (($fsk = @fsockopen($match[$server], 43)))
    1172                         {
    1173                                 fputs($fsk, "$ip\n");
    1174                                 while (!feof($fsk))
    1175                                 {
    1176                                         $ipwhois .= fgets($fsk, 1024);
    1177                                 }
    1178                                 @fclose($fsk);
    1179                         }
    1180                         break;
    1181                 }
     1256        $match = array();
     1257
     1258        // Test for referrals from ARIN to other whois databases, roll on rwhois
     1259        if (preg_match('#ReferralServer: whois://(.+)#im', $ipwhois, $match))
     1260        {
     1261                if (strpos($match[1], ':') !== false)
     1262                {
     1263                        $pos    = strrpos($match[1], ':');
     1264                        $server = substr($match[1], 0, $pos);
     1265                        $port   = (int) substr($match[1], $pos + 1);
     1266                        unset($pos);
     1267                }
     1268                else
     1269                {
     1270                        $server = $match[1];
     1271                        $port   = 43;
     1272                }
     1273
     1274                $buffer = '';
     1275
     1276                if (($fsk = @fsockopen($server, $port)))
     1277                {
     1278                        fputs($fsk, "$ip\r\n");
     1279                        while (!feof($fsk))
     1280                        {
     1281                                $buffer .= fgets($fsk, 1024);
     1282                        }
     1283                        @fclose($fsk);
     1284                }
     1285
     1286                // Use the result from ARIN if we don't get any result here
     1287                $ipwhois = (empty($buffer)) ? $ipwhois : $buffer;
    11821288        }
    11831289
     
    14151521                        else if ($mbstring)
    14161522                        {
    1417                                 $regex = '[-\]_+ [[:upper:][:lower:][:digit:]]+';
     1523                                $regex = '[-\]_+ \[[:upper:][:lower:][:digit:]]+';
    14181524                        }
    14191525                        else
     
    14401546        else if ($mbstring)
    14411547        {
    1442                 $matches = array();
    1443                 mb_ereg_search_init('^' . $username . '$', $regex, $matches);
     1548                mb_ereg_search_init($username, '^' . $regex . '$');
    14441549                if (!mb_ereg_search())
    14451550                {
     
    16231728                $sql = 'SELECT user_email_hash
    16241729                        FROM ' . USERS_TABLE . "
    1625                         WHERE user_email_hash = " . (crc32($email) . strlen($email));
     1730                        WHERE user_email_hash = " . $db->sql_escape(phpbb_email_hash($email));
    16261731                $result = $db->sql_query($sql);
    16271732                $row = $db->sql_fetchrow($result);
     
    20572162                                                {
    20582163                                                        $avatar_list[$file][$avatar_row_count][$avatar_col_count] = array(
    2059                                                                 'file'          => "$file/$sub_file",
    2060                                                                 'filename'      => $sub_file,
     2164                                                                'file'          => rawurlencode($file) . '/' . rawurlencode($sub_file),
     2165                                                                'filename'      => rawurlencode($sub_file),
    20612166                                                                'name'          => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $sub_file))),
    20622167                                                        );
     
    23452450
    23462451        $error = array();
    2347         $attribute_ary = array(
    2348                 'group_colour'                  => 'string',
    2349                 'group_rank'                    => 'int',
    2350                 'group_avatar'                  => 'string',
    2351                 'group_avatar_type'             => 'int',
    2352                 'group_avatar_width'    => 'int',
    2353                 'group_avatar_height'   => 'int',
    2354 
    2355                 'group_receive_pm'              => 'int',
    2356                 'group_legend'                  => 'int',
    2357                 'group_message_limit'   => 'int',
    2358                 'group_max_recipients'  => 'int',
    2359 
    2360                 'group_founder_manage'  => 'int',
    2361         );
    2362 
    2363         // Those are group-only attributes
    2364         $group_only_ary = array('group_receive_pm', 'group_legend', 'group_message_limit', 'group_max_recipients', 'group_founder_manage');
     2452
     2453        // Attributes which also affect the users table
     2454        $user_attribute_ary = array('group_colour', 'group_rank', 'group_avatar', 'group_avatar_type', 'group_avatar_width', 'group_avatar_height');
    23652455
    23662456        // Check data. Limit group name length.
     
    24002490                if (sizeof($group_attributes))
    24012491                {
    2402                         foreach ($attribute_ary as $attribute => $_type)
    2403                         {
    2404                                 if (isset($group_attributes[$attribute]))
    2405                                 {
    2406                                         settype($group_attributes[$attribute], $_type);
    2407                                         $sql_ary[$attribute] = $group_attributes[$attribute];
    2408                                 }
    2409                         }
     2492                        // Merge them with $sql_ary to properly update the group
     2493                        $sql_ary = array_merge($sql_ary, $group_attributes);
    24102494                }
    24112495
     
    24322516                                remove_default_avatar($group_id, $user_ary);
    24332517                        }
     2518
    24342519                        if (isset($sql_ary['group_rank']) && !$sql_ary['group_rank'])
    24352520                        {
     
    24472532                                WHERE group_id = $group_id";
    24482533                        $db->sql_query($sql);
     2534
     2535                        // One special case is the group skip auth setting. If this was changed we need to purge permissions for this group
     2536                        if (isset($group_attributes['group_skip_auth']))
     2537                        {
     2538                                // Get users within this group...
     2539                                $sql = 'SELECT user_id
     2540                                        FROM ' . USER_GROUP_TABLE . '
     2541                                        WHERE group_id = ' . $group_id . '
     2542                                                AND user_pending = 0';
     2543                                $result = $db->sql_query($sql);
     2544
     2545                                $user_id_ary = array();
     2546                                while ($row = $db->sql_fetchrow($result))
     2547                                {
     2548                                        $user_id_ary[] = $row['user_id'];
     2549                                }
     2550                                $db->sql_freeresult($result);
     2551
     2552                                if (!empty($user_id_ary))
     2553                                {
     2554                                        global $auth;
     2555
     2556                                        // Clear permissions cache of relevant users
     2557                                        $auth->acl_clear_prefetch($user_id_ary);
     2558                                }
     2559                        }
    24492560                }
    24502561                else
     
    24572568                {
    24582569                        $group_id = $db->sql_nextid();
     2570
    24592571                        if (isset($sql_ary['group_avatar_type']) && $sql_ary['group_avatar_type'] == AVATAR_UPLOAD)
    24602572                        {
     
    24672579                if (sizeof($group_attributes))
    24682580                {
    2469                         foreach ($attribute_ary as $attribute => $_type)
    2470                         {
    2471                                 if (isset($group_attributes[$attribute]) && !in_array($attribute, $group_only_ary))
     2581                        // Go through the user attributes array, check if a group attribute matches it and then set it. ;)
     2582                        foreach ($user_attribute_ary as $attribute)
     2583                        {
     2584                                if (!isset($group_attributes[$attribute]))
    24722585                                {
    2473                                         // If we are about to set an avatar, we will not overwrite user avatars if no group avatar is set...
    2474                                         if (strpos($attribute, 'group_avatar') === 0 && !$group_attributes[$attribute])
    2475                                         {
    2476                                                 continue;
    2477                                         }
    2478 
    2479                                         $sql_ary[$attribute] = $group_attributes[$attribute];
     2586                                        continue;
    24802587                                }
     2588
     2589                                // If we are about to set an avatar, we will not overwrite user avatars if no group avatar is set...
     2590                                if (strpos($attribute, 'group_avatar') === 0 && !$group_attributes[$attribute])
     2591                                {
     2592                                        continue;
     2593                                }
     2594
     2595                                $sql_ary[$attribute] = $group_attributes[$attribute];
    24812596                        }
    24822597                }
     
    26822797        if ($default)
    26832798        {
    2684                 group_set_user_default($group_id, $user_id_ary, $group_attributes);
     2799                group_user_attributes('default', $group_id, $user_id_ary, false, $group_name, $group_attributes);
    26852800        }
    26862801
     
    26952810        }
    26962811
    2697         $log = ($leader) ? 'LOG_MODS_ADDED' : 'LOG_USERS_ADDED';
     2812        $log = ($leader) ? 'LOG_MODS_ADDED' : (($pending) ? 'LOG_USERS_PENDING' : 'LOG_USERS_ADDED');
    26982813
    26992814        add_log('admin', $log, $group_name, implode(', ', $username_ary));
     
    27142829function group_user_del($group_id, $user_id_ary = false, $username_ary = false, $group_name = false)
    27152830{
    2716         global $db, $auth;
    2717 
    2718         $group_order = array('ADMINISTRATORS', 'GLOBAL_MODERATORS', 'REGISTERED_COPPA', 'REGISTERED', 'BOTS', 'GUESTS');
     2831        global $db, $auth, $config;
     2832
     2833        if ($config['coppa_enable'])
     2834        {
     2835                $group_order = array('ADMINISTRATORS', 'GLOBAL_MODERATORS', 'NEWLY_REGISTERED', 'REGISTERED_COPPA', 'REGISTERED', 'BOTS', 'GUESTS');
     2836        }
     2837        else
     2838        {
     2839                $group_order = array('ADMINISTRATORS', 'GLOBAL_MODERATORS', 'NEWLY_REGISTERED', 'REGISTERED', 'BOTS', 'GUESTS');
     2840        }
    27192841
    27202842        // We need both username and user_id info
     
    27802902        while ($row = $db->sql_fetchrow($result))
    27812903        {
    2782                 if ($default_groups[$row['user_id']] == $group_id && (!isset($temp_ary[$row['user_id']]) || array_search($row['group_name'], $group_order) < $temp_ary[$row['user_id']]))
     2904                if ($default_groups[$row['user_id']] == $group_id && (!isset($temp_ary[$row['user_id']]) || $group_order_id[$row['group_name']] < $temp_ary[$row['user_id']]))
    27832905                {
    27842906                        $temp_ary[$row['user_id']] = $row['group_id'];
     
    27872909        $db->sql_freeresult($result);
    27882910
     2911        // sql_where_ary holds the new default groups and their users
    27892912        $sql_where_ary = array();
    27902913        foreach ($temp_ary as $uid => $gid)
     
    28202943        $log = 'LOG_GROUP_REMOVE';
    28212944
    2822         add_log('admin', $log, $group_name, implode(', ', $username_ary));
     2945        if ($group_name)
     2946        {
     2947                add_log('admin', $log, $group_name, implode(', ', $username_ary));
     2948        }
    28232949
    28242950        group_update_listings($group_id);
     
    30103136
    30113137                case 'default':
     3138                        // We only set default group for approved members of the group
     3139                        $sql = 'SELECT user_id
     3140                                FROM ' . USER_GROUP_TABLE . "
     3141                                WHERE group_id = $group_id
     3142                                        AND user_pending = 0
     3143                                        AND " . $db->sql_in_set('user_id', $user_id_ary);
     3144                        $result = $db->sql_query($sql);
     3145
     3146                        $user_id_ary = $username_ary = array();
     3147                        while ($row = $db->sql_fetchrow($result))
     3148                        {
     3149                                $user_id_ary[] = $row['user_id'];
     3150                        }
     3151                        $db->sql_freeresult($result);
     3152
     3153                        $result = user_get_id_name($user_id_ary, $username_ary);
     3154                        if (!sizeof($user_id_ary) || $result !== false)
     3155                        {
     3156                                return 'NO_USERS';
     3157                        }
     3158
    30123159                        $sql = 'SELECT user_id, group_id FROM ' . USERS_TABLE . '
    30133160                                WHERE ' . $db->sql_in_set('user_id', $user_id_ary, false, true);
     
    30983245function group_set_user_default($group_id, $user_id_ary, $group_attributes = false, $update_listing = false)
    30993246{
    3100         global $db;
     3247        global $cache, $db;
    31013248
    31023249        if (empty($user_id_ary))
     
    31983345                group_update_listings($group_id);
    31993346        }
     3347
     3348        // Because some tables/caches use usercolour-specific data we need to purge this here.
     3349        $cache->destroy('sql', MODERATOR_CACHE_TABLE);
    32003350}
    32013351
     
    32143364        $db->sql_freeresult($result);
    32153365
    3216         if (!$row)
     3366        if (!$row || ($row['group_type'] == GROUP_SPECIAL && empty($user->lang)))
    32173367        {
    32183368                return '';
     
    33573507}
    33583508
     3509
     3510
     3511/**
     3512* Funtion to make a user leave the NEWLY_REGISTERED system group.
     3513* @access public
     3514* @param $user_id The id of the user to remove from the group
     3515*/
     3516function remove_newly_registered($user_id, $user_data = false)
     3517{
     3518        global $db;
     3519
     3520        if ($user_data === false)
     3521        {
     3522                $sql = 'SELECT *
     3523                        FROM ' . USERS_TABLE . '
     3524                        WHERE user_id = ' . $user_id;
     3525                $result = $db->sql_query($sql);
     3526                $user_row = $db->sql_fetchrow($result);
     3527                $db->sql_freeresult($result);
     3528
     3529                if (!$user_row)
     3530                {
     3531                        return false;
     3532                }
     3533                else
     3534                {
     3535                        $user_data  = $user_row;
     3536                }
     3537        }
     3538
     3539        if (empty($user_data['user_new']))
     3540        {
     3541                return false;
     3542        }
     3543
     3544        $sql = 'SELECT group_id
     3545                FROM ' . GROUPS_TABLE . "
     3546                WHERE group_name = 'NEWLY_REGISTERED'
     3547                        AND group_type = " . GROUP_SPECIAL;
     3548        $result = $db->sql_query($sql);
     3549        $group_id = (int) $db->sql_fetchfield('group_id');
     3550        $db->sql_freeresult($result);
     3551
     3552        if (!$group_id)
     3553        {
     3554                return false;
     3555        }
     3556
     3557        // We need to call group_user_del here, because this function makes sure everything is correctly changed.
     3558        // A downside for a call within the session handler is that the language is not set up yet - so no log entry
     3559        group_user_del($group_id, $user_id);
     3560
     3561        // Set user_new to 0 to let this not be triggered again
     3562        $sql = 'UPDATE ' . USERS_TABLE . '
     3563                SET user_new = 0
     3564                WHERE user_id = ' . $user_id;
     3565        $db->sql_query($sql);
     3566
     3567        // The new users group was the users default group?
     3568        if ($user_data['group_id'] == $group_id)
     3569        {
     3570                // Which group is now the users default one?
     3571                $sql = 'SELECT group_id
     3572                        FROM ' . USERS_TABLE . '
     3573                        WHERE user_id = ' . $user_id;
     3574                $result = $db->sql_query($sql);
     3575                $user_data['group_id'] = $db->sql_fetchfield('group_id');
     3576                $db->sql_freeresult($result);
     3577        }
     3578
     3579        return $user_data['group_id'];
     3580}
     3581
    33593582?>
  • trunk/forum/includes/mcp/mcp_front.php

    r400 r702  
    33*
    44* @package mcp
    5 * @version $Id: mcp_front.php 9029 2008-10-18 18:44:41Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3535
    3636                $template->assign_var('S_SHOW_UNAPPROVED', (!empty($forum_list)) ? true : false);
    37                
     37
    3838                if (!empty($forum_list))
    3939                {
     
    120120                        }
    121121
     122                        $s_hidden_fields = build_hidden_fields(array(
     123                                'redirect'              => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main' . (($forum_id) ? '&amp;f=' . $forum_id : ''))
     124                        ));
     125
    122126                        $template->assign_vars(array(
     127                                'S_HIDDEN_FIELDS'               => $s_hidden_fields,
    123128                                'S_MCP_QUEUE_ACTION'    => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue"),
    124129                        ));
     
    153158                                FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p
    154159                                WHERE r.post_id = p.post_id
     160                                        AND r.pm_id = 0
    155161                                        AND r.report_closed = 0
    156162                                        AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')';
     
    182188
    183189                                        'WHERE'         => 'r.post_id = p.post_id
     190                                                AND r.pm_id = 0
    184191                                                AND r.report_closed = 0
    185192                                                AND r.reason_id = rr.reason_id
     
    241248                                );
    242249                        }
     250                }
     251        }
     252
     253        // Latest 5 reported PMs
     254        if ($module->loaded('pm_reports') && $auth->acl_getf_global('m_report'))
     255        {
     256                $template->assign_var('S_SHOW_PM_REPORTS', true);
     257                $user->add_lang(array('ucp'));
     258
     259                $sql = 'SELECT COUNT(r.report_id) AS total
     260                        FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . ' p
     261                        WHERE r.post_id = 0
     262                                AND r.pm_id = p.msg_id
     263                                AND r.report_closed = 0';
     264                $result = $db->sql_query($sql);
     265                $total = (int) $db->sql_fetchfield('total');
     266                $db->sql_freeresult($result);
     267
     268                if ($total)
     269                {
     270                        include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
     271
     272                        $sql = $db->sql_build_query('SELECT', array(
     273                                'SELECT'        => 'r.report_id, r.report_time, p.msg_id, p.message_subject, p.message_time, p.to_address, p.bcc_address, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id',
     274
     275                                'FROM'          => array(
     276                                        REPORTS_TABLE                   => 'r',
     277                                        REPORTS_REASONS_TABLE   => 'rr',
     278                                        USERS_TABLE                             => array('u', 'u2'),
     279                                        PRIVMSGS_TABLE                          => 'p'
     280                                ),
     281
     282                                'WHERE'         => 'r.pm_id = p.msg_id
     283                                        AND r.post_id = 0
     284                                        AND r.report_closed = 0
     285                                        AND r.reason_id = rr.reason_id
     286                                        AND r.user_id = u.user_id
     287                                        AND p.author_id = u2.user_id',
     288
     289                                'ORDER_BY'      => 'p.message_time DESC'
     290                        ));
     291                        $result = $db->sql_query_limit($sql, 5);
     292
     293                        $pm_by_id = $pm_list = array();
     294                        while ($row = $db->sql_fetchrow($result))
     295                        {
     296                                $pm_by_id[(int) $row['msg_id']] = $row;
     297                                $pm_list[] = (int) $row['msg_id'];
     298                        }
     299
     300                        $address_list = get_recipient_strings($pm_by_id);
     301
     302                        foreach ($pm_list as $message_id)
     303                        {
     304                                $row = $pm_by_id[$message_id];
     305
     306                                $template->assign_block_vars('pm_report', array(
     307                                        'U_PM_DETAILS'  => append_sid("{$phpbb_root_path}mcp.$phpEx", 'r=' . $row['report_id'] . "&amp;i=pm_reports&amp;mode=pm_report_details"),
     308
     309                                        'REPORTER_FULL'         => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
     310                                        'REPORTER'                      => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
     311                                        'REPORTER_COLOUR'       => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
     312                                        'U_REPORTER'            => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
     313
     314                                        'PM_AUTHOR_FULL'                => get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']),
     315                                        'PM_AUTHOR'                     => get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']),
     316                                        'PM_AUTHOR_COLOUR'              => get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']),
     317                                        'U_PM_AUTHOR'                   => get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']),
     318
     319                                        'PM_SUBJECT'            => $row['message_subject'],
     320                                        'REPORT_TIME'           => $user->format_date($row['report_time']),
     321                                        'PM_TIME'                       => $user->format_date($row['message_time']),
     322                                        'RECIPIENTS'            => implode(', ', $address_list[$row['msg_id']]),
     323                                ));
     324                        }
     325                }
     326
     327                if ($total == 0)
     328                {
     329                        $template->assign_vars(array(
     330                                'L_PM_REPORTS_TOTAL'    =>      $user->lang['PM_REPORTS_ZERO_TOTAL'],
     331                                'S_HAS_PM_REPORTS'              =>      false)
     332                        );
     333                }
     334                else
     335                {
     336                        $template->assign_vars(array(
     337                                'L_PM_REPORTS_TOTAL'    => ($total == 1) ? $user->lang['PM_REPORT_TOTAL'] : sprintf($user->lang['PM_REPORTS_TOTAL'], $total),
     338                                'S_HAS_PM_REPORTS'              => true)
     339                        );
    243340                }
    244341        }
  • trunk/forum/includes/mcp/mcp_logs.php

    r400 r702  
    33*
    44* @package mcp
    5 * @version $Id: mcp_logs.php 9029 2008-10-18 18:44:41Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    165165                $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
    166166
     167                $keywords = utf8_normalize_nfc(request_var('keywords', '', true));
     168                $keywords_param = !empty($keywords) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
     169
    167170                // Grab log data
    168171                $log_data = array();
    169172                $log_count = 0;
    170                 view_log('mod', $log_data, $log_count, $config['topics_per_page'], $start, $forum_list, $topic_id, 0, $sql_where, $sql_sort);
     173                view_log('mod', $log_data, $log_count, $config['topics_per_page'], $start, $forum_list, $topic_id, 0, $sql_where, $sql_sort, $keywords);
    171174
    172175                $template->assign_vars(array(
    173176                        'PAGE_NUMBER'           => on_page($log_count, $config['topics_per_page'], $start),
    174177                        'TOTAL'                         => ($log_count == 1) ? $user->lang['TOTAL_LOG'] : sprintf($user->lang['TOTAL_LOGS'], $log_count),
    175                         'PAGINATION'            => generate_pagination($this->u_action . "&amp;$u_sort_param", $log_count, $config['topics_per_page'], $start),
     178                        'PAGINATION'            => generate_pagination($this->u_action . "&amp;$u_sort_param$keywords_param", $log_count, $config['topics_per_page'], $start),
    176179
    177180                        'L_TITLE'                       => $user->lang['MCP_LOGS'],
     
    183186                        'S_SELECT_SORT_DAYS'    => $s_limit_days,
    184187                        'S_LOGS'                                => ($log_count > 0),
     188                        'S_KEYWORDS'                    => $keywords,
    185189                        )
    186190                );
     
    189193                {
    190194                        $data = array();
    191                                
     195
    192196                        $checks = array('viewtopic', 'viewforum');
    193197                        foreach ($checks as $check)
  • trunk/forum/includes/mcp/mcp_main.php

    r400 r702  
    33*
    44* @package mcp
    5 * @version $Id: mcp_main.php 8950 2008-09-27 10:59:25Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    569569                                $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
    570570                        }
    571                         else if (!$auth->acl_get('f_post', $to_forum_id))
     571                        else if (!$auth->acl_get('f_post', $to_forum_id) || (!$auth->acl_get('m_approve', $to_forum_id) && !$auth->acl_get('f_noapprove', $to_forum_id)))
    572572                        {
    573573                                $additional_msg = $user->lang['USER_CANNOT_POST'];
     
    595595                $leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;
    596596
    597                 $topics_moved = sizeof($topic_ids);
    598                 $topics_authed_moved = 0;
    599597                $forum_sync_data = array();
    600598
     
    602600                $forum_sync_data[$to_forum_id] = $forum_data;
    603601
     602                // Real topics added to target forum
     603                $topics_moved = sizeof($topic_data);
     604
     605                // Approved topics added to target forum
     606                $topics_authed_moved = 0;
     607
     608                // Posts (topic replies + topic post if approved) added to target forum
     609                $topic_posts_added = 0;
     610
     611                // Posts (topic replies + topic post if approved and not global announcement) removed from source forum
     612                $topic_posts_removed = 0;
     613
     614                // Real topics removed from source forum (all topics without global announcements)
     615                $topics_removed = 0;
     616
     617                // Approved topics removed from source forum (except global announcements)
     618                $topics_authed_removed = 0;
     619
    604620                foreach ($topic_data as $topic_id => $topic_info)
    605621                {
    606                         if ($topic_info['topic_approved'] == '1')
     622                        if ($topic_info['topic_approved'])
    607623                        {
    608624                                $topics_authed_moved++;
     625                                $topic_posts_added++;
     626                        }
     627
     628                        $topic_posts_added += $topic_info['topic_replies'];
     629
     630                        if ($topic_info['topic_type'] != POST_GLOBAL)
     631                        {
     632                                $topics_removed++;
     633                                $topic_posts_removed += $topic_info['topic_replies'];
     634
     635                                if ($topic_info['topic_approved'])
     636                                {
     637                                        $topics_authed_removed++;
     638                                        $topic_posts_removed++;
     639                                }
    609640                        }
    610641                }
     
    612643                $db->sql_transaction('begin');
    613644
    614                 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts
    615                         FROM ' . TOPICS_TABLE . ' t
    616                         WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
    617                 $result = $db->sql_query($sql);
    618                 $row_data = $db->sql_fetchrow($result);
    619                 $db->sql_freeresult($result);
    620 
    621645                $sync_sql = array();
    622646
    623                 if ($row_data['topic_posts'])
    624                 {
    625                         $sync_sql[$forum_id][]          = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
    626                         $sync_sql[$to_forum_id][]       = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
     647                if ($topic_posts_added)
     648                {
     649                        $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $topic_posts_added;
    627650                }
    628651
    629652                if ($topics_authed_moved)
    630653                {
    631                         $sync_sql[$to_forum_id][]       = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
    632                 }
    633 
    634                 $sync_sql[$to_forum_id][]       = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
     654                        $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
     655                }
     656
     657                $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
    635658
    636659                // Move topics, but do not resync yet
     
    693716                                $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
    694717
    695                                 $topics_authed_moved--;
    696                                 $topics_moved--;
     718                                // Shadow topics only count on new "topics" and not posts... a shadow topic alone has 0 posts
     719                                $topics_removed--;
     720                                $topics_authed_removed--;
    697721                        }
    698722                }
    699723                unset($topic_data);
    700724
    701                 $sync_sql[$forum_id][]  = 'forum_topics_real = forum_topics_real - ' . (int) $topics_moved;
    702 
    703                 if ($topics_authed_moved)
    704                 {
    705                         $sync_sql[$forum_id][]  = 'forum_topics = forum_topics - ' . (int) $topics_authed_moved;
     725                if ($topic_posts_removed)
     726                {
     727                        $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . $topic_posts_removed;
     728                }
     729
     730                if ($topics_removed)
     731                {
     732                        $sync_sql[$forum_id][]  = 'forum_topics_real = forum_topics_real - ' . (int) $topics_removed;
     733                }
     734
     735                if ($topics_authed_removed)
     736                {
     737                        $sync_sql[$forum_id][]  = 'forum_topics = forum_topics - ' . (int) $topics_authed_removed;
    706738                }
    707739
     
    782814                foreach ($data as $topic_id => $row)
    783815                {
    784                         add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_' . ($row['topic_moved_id'] ? 'SHADOW_' : '') . 'TOPIC', $row['topic_title']);
     816                        if ($row['topic_moved_id'])
     817                        {
     818                                add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_SHADOW_TOPIC', $row['topic_title']);
     819                        }
     820                        else
     821                        {
     822                                add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']);
     823                        }
    785824                }
    786825
     
    866905                foreach ($post_data as $id => $row)
    867906                {
    868                         add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject']);
     907                        $post_username = ($row['poster_id'] == ANONYMOUS && !empty($row['post_username'])) ? $row['post_username'] : $row['username'];
     908                        add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject'], $post_username);
    869909                }
    870910
     
    930970        else
    931971        {
     972                if ($affected_topics != 1 || $deleted_topics || !$topic_id)
     973                {
     974                        $redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&i=main&mode=forum_view", false);
     975                }
     976
    932977                meta_refresh(3, $redirect);
    933978                trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link));
     
    10281073                                'poll_title'                            => (string) $topic_row['poll_title'],
    10291074                                'poll_start'                            => (int) $topic_row['poll_start'],
    1030                                 'poll_length'                           => (int) $topic_row['poll_length']
     1075                                'poll_length'                           => (int) $topic_row['poll_length'],
     1076                                'poll_max_options'                      => (int) $topic_row['poll_max_options'],
     1077                                'poll_vote_change'                      => (int) $topic_row['poll_vote_change'],
    10311078                        );
    10321079
     
    11301177                                                        'is_orphan'                     => (int) $attach_row['is_orphan'],
    11311178                                                        'poster_id'                     => (int) $attach_row['poster_id'],
    1132                                                         'physical_filename'     => (string) basename($attach_row['physical_filename']),
    1133                                                         'real_filename'         => (string) basename($attach_row['real_filename']),
     1179                                                        'physical_filename'     => (string) utf8_basename($attach_row['physical_filename']),
     1180                                                        'real_filename'         => (string) utf8_basename($attach_row['real_filename']),
    11341181                                                        'download_count'        => (int) $attach_row['download_count'],
    11351182                                                        'attach_comment'        => (string) $attach_row['attach_comment'],
     
    11901237
    11911238                sync('forum', 'forum_id', $to_forum_id);
    1192                 set_config('num_topics', $config['num_topics'] + sizeof($new_topic_id_list), true);
    1193                 set_config('num_posts', $config['num_posts'] + $total_posts, true);
     1239                set_config_count('num_topics', sizeof($new_topic_id_list), true);
     1240                set_config_count('num_posts', $total_posts, true);
    11941241
    11951242                foreach ($new_topic_id_list as $topic_id => $new_topic_id)
  • trunk/forum/includes/mcp/mcp_notes.php

    r400 r702  
    33*
    44* @package mcp
    5 * @version $Id: mcp_notes.php 8598 2008-06-04 15:37:06Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    194194                $sql_sort = $sort_by_sql[$sk] . ' ' . (($sd == 'd') ? 'DESC' : 'ASC');
    195195
     196                $keywords = utf8_normalize_nfc(request_var('keywords', '', true));
     197                $keywords_param = !empty($keywords) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
     198
    196199                $log_data = array();
    197200                $log_count = 0;
    198                 view_log('user', $log_data, $log_count, $config['posts_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
     201                view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort, $keywords);
    199202
    200203                if ($log_count)
     
    220223                        'S_SELECT_SORT_KEY'             => $s_sort_key,
    221224                        'S_SELECT_SORT_DAYS'    => $s_limit_days,
     225                        'S_KEYWORDS'                    => $keywords,
    222226
    223227                        'L_TITLE'                       => $user->lang['MCP_NOTES_USER'],
    224228
    225                         'PAGE_NUMBER'           => on_page($log_count, $config['posts_per_page'], $start),
    226                         'PAGINATION'            => generate_pagination($this->u_action . "&amp;st=$st&amp;sk=$sk&amp;sd=$sd", $log_count, $config['posts_per_page'], $start),
     229                        'PAGE_NUMBER'           => on_page($log_count, $config['topics_per_page'], $start),
     230                        'PAGINATION'            => generate_pagination($this->u_action . "&amp;$u_sort_param$keywords_param", $log_count, $config['topics_per_page'], $start),
    227231                        'TOTAL_REPORTS'         => ($log_count == 1) ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $log_count),
    228232
    229                         'USERNAME'                      => $userrow['username'],
    230                         'USER_COLOR'            => (!empty($userrow['user_colour'])) ? $userrow['user_colour'] : '',
    231233                        'RANK_TITLE'            => $rank_title,
    232234                        'JOINED'                        => $user->format_date($userrow['user_regdate']),
    233235                        'POSTS'                         => ($userrow['user_posts']) ? $userrow['user_posts'] : 0,
    234236                        'WARNINGS'                      => ($userrow['user_warnings']) ? $userrow['user_warnings'] : 0,
     237
     238                        'USERNAME_FULL'         => get_username_string('full', $userrow['user_id'], $userrow['username'], $userrow['user_colour']),
     239                        'USERNAME_COLOUR'       => get_username_string('colour', $userrow['user_id'], $userrow['username'], $userrow['user_colour']),
     240                        'USERNAME'                      => get_username_string('username', $userrow['user_id'], $userrow['username'], $userrow['user_colour']),
     241                        'U_PROFILE'                     => get_username_string('profile', $userrow['user_id'], $userrow['username'], $userrow['user_colour']),
    235242
    236243                        'AVATAR_IMG'            => $avatar_img,
  • trunk/forum/includes/mcp/mcp_queue.php

    r400 r702  
    33*
    44* @package mcp
    5 * @version $Id: mcp_queue.php 9133 2008-11-30 12:03:43Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    106106                                        $template->assign_vars(array(
    107107                                                'S_TOPIC_REVIEW'        => true,
     108                                                'S_BBCODE_ALLOWED'      => $post_info['enable_bbcode'],
    108109                                                'TOPIC_TITLE'           => $post_info['topic_title'])
    109110                                        );
     
    492493
    493494                $total_topics = $total_posts = 0;
    494                 $forum_topics_posts = $topic_approve_sql = $topic_replies_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
    495                 $user_posts_sql = array();
    496 
    497                 $update_forum_information = false;
     495                $topic_approve_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
     496                $user_posts_sql = $post_approved_list = array();
    498497
    499498                foreach ($post_info as $post_id => $post_data)
    500499                {
     500                        if ($post_data['post_approved'])
     501                        {
     502                                $post_approved_list[] = $post_id;
     503                                continue;
     504                        }
     505
    501506                        $topic_id_list[$post_data['topic_id']] = 1;
    502507
     
    518523                                if ($post_data['forum_id'])
    519524                                {
    520                                         if (!isset($forum_topics_posts[$post_data['forum_id']]))
    521                                         {
    522                                                 $forum_topics_posts[$post_data['forum_id']] = array(
    523                                                         'forum_posts'   => 0,
    524                                                         'forum_topics'  => 0
    525                                                 );
    526                                         }
    527 
    528525                                        $total_topics++;
    529                                         $forum_topics_posts[$post_data['forum_id']]['forum_topics']++;
    530526                                }
    531527                                $topic_approve_sql[] = $post_data['topic_id'];
     
    540536                        else
    541537                        {
    542                                 if (!isset($topic_replies_sql[$post_data['topic_id']]))
    543                                 {
    544                                         $topic_replies_sql[$post_data['topic_id']] = 0;
    545                                 }
    546                                 $topic_replies_sql[$post_data['topic_id']]++;
    547 
    548538                                $approve_log[] = array(
    549539                                        'type'                  => 'post',
     
    556546                        if ($post_data['forum_id'])
    557547                        {
    558                                 if (!isset($forum_topics_posts[$post_data['forum_id']]))
    559                                 {
    560                                         $forum_topics_posts[$post_data['forum_id']] = array(
    561                                                 'forum_posts'   => 0,
    562                                                 'forum_topics'  => 0
    563                                         );
    564                                 }
    565 
    566548                                $total_posts++;
    567                                 $forum_topics_posts[$post_data['forum_id']]['forum_posts']++;
    568549
    569550                                // Increment by topic_replies if we approve a topic...
     
    572553                                {
    573554                                        $total_posts += $post_data['topic_replies'];
    574                                         $forum_topics_posts[$post_data['forum_id']]['forum_posts'] += $post_data['topic_replies'];
    575555                                }
    576556                        }
    577557
    578558                        $post_approve_sql[] = $post_id;
    579 
    580                         // If the post is newer than the last post information stored we need to update the forum information
    581                         if ($post_data['post_time'] >= $post_data['forum_last_post_time'])
    582                         {
    583                                 $update_forum_information = true;
    584                         }
     559                }
     560
     561                $post_id_list = array_values(array_diff($post_id_list, $post_approved_list));
     562                for ($i = 0, $size = sizeof($post_approved_list); $i < $size; $i++)
     563                {
     564                        unset($post_info[$post_approved_list[$i]]);
    585565                }
    586566
     
    601581                }
    602582
     583                unset($topic_approve_sql, $post_approve_sql);
     584
    603585                foreach ($approve_log as $log_data)
    604586                {
    605587                        add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_APPROVED' : 'LOG_POST_APPROVED', $log_data['post_subject']);
    606                 }
    607 
    608                 if (sizeof($topic_replies_sql))
    609                 {
    610                         foreach ($topic_replies_sql as $topic_id => $num_replies)
    611                         {
    612                                 $sql = 'UPDATE ' . TOPICS_TABLE . "
    613                                         SET topic_replies = topic_replies + $num_replies
    614                                         WHERE topic_id = $topic_id";
    615                                 $db->sql_query($sql);
    616                         }
    617                 }
    618 
    619                 if (sizeof($forum_topics_posts))
    620                 {
    621                         foreach ($forum_topics_posts as $forum_id => $row)
    622                         {
    623                                 $sql = 'UPDATE ' . FORUMS_TABLE . '
    624                                         SET ';
    625                                 $sql .= ($row['forum_topics']) ? "forum_topics = forum_topics + {$row['forum_topics']}" : '';
    626                                 $sql .= ($row['forum_topics'] && $row['forum_posts']) ? ', ' : '';
    627                                 $sql .= ($row['forum_posts']) ? "forum_posts = forum_posts + {$row['forum_posts']}" : '';
    628                                 $sql .= " WHERE forum_id = $forum_id";
    629 
    630                                 $db->sql_query($sql);
    631                         }
    632588                }
    633589
     
    653609                if ($total_topics)
    654610                {
    655                         set_config('num_topics', $config['num_topics'] + $total_topics, true);
     611                        set_config_count('num_topics', $total_topics, true);
    656612                }
    657613
    658614                if ($total_posts)
    659615                {
    660                         set_config('num_posts', $config['num_posts'] + $total_posts, true);
    661                 }
    662                 unset($topic_approve_sql, $topic_replies_sql, $post_approve_sql);
    663 
    664                 update_post_information('topic', array_keys($topic_id_list));
    665 
    666                 if ($update_forum_information)
    667                 {
    668                         update_post_information('forum', array_keys($forum_id_list));
    669                 }
     616                        set_config_count('num_posts', $total_posts, true);
     617                }
     618
     619                sync('topic', 'topic_id', array_keys($topic_id_list), true);
     620                sync('forum', 'forum_id', array_keys($forum_id_list), true, true);
    670621                unset($topic_id_list, $forum_id_list);
    671622
     
    734685                else
    735686                {
    736                         $success_msg = (sizeof($post_id_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
     687                        $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
    737688                }
    738689        }
     
    846797        if (confirm_box(true))
    847798        {
    848 
    849                 // If Topic -> forum_topics_real -= 1
    850                 // If Post -> topic_replies_real -= 1
    851 
    852                 $num_disapproved = 0;
    853                 $forum_topics_real = $topic_id_list = $forum_id_list = $topic_replies_real_sql = $post_disapprove_sql = $disapprove_log = array();
    854 
     799                $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array();
     800                $topic_replies_real = $post_disapprove_list = array();
     801
     802                // Build a list of posts to be unapproved and get the related topics real replies count
    855803                foreach ($post_info as $post_id => $post_data)
    856804                {
    857                         $topic_id_list[$post_data['topic_id']] = 1;
    858 
    859                         if ($post_data['forum_id'])
    860                         {
    861                                 $forum_id_list[$post_data['forum_id']] = 1;
    862                         }
    863 
    864                         // Topic or Post. ;)
    865                         /**
    866                         * @todo this probably is a different method than the one used by delete_posts, does this cause counter inconsistency?
    867                         */
    868                         if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id)
    869                         {
    870                                 if ($post_data['forum_id'])
    871                                 {
    872                                         if (!isset($forum_topics_real[$post_data['forum_id']]))
    873                                         {
    874                                                 $forum_topics_real[$post_data['forum_id']] = 0;
    875                                         }
    876                                         $forum_topics_real[$post_data['forum_id']]++;
    877                                         $num_disapproved++;
    878                                 }
    879 
    880                                 $disapprove_log[] = array(
    881                                         'type'                  => 'topic',
    882                                         'post_subject'  => $post_data['post_subject'],
    883                                         'forum_id'              => $post_data['forum_id'],
    884                                         'topic_id'              => 0, // useless to log a topic id, as it will be deleted
     805                        $post_disapprove_list[$post_id] = $post_data['topic_id'];
     806                        if (!isset($topic_replies_real[$post_data['topic_id']]))
     807                        {
     808                                $topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real'];
     809                        }
     810                }
     811
     812                // Now we build the log array
     813                foreach ($post_disapprove_list as $post_id => $topic_id)
     814                {
     815                        // If the count of disapproved posts for the topic is greater
     816                        // than topic's real replies count, the whole topic is disapproved/deleted
     817                        if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id])
     818                        {
     819                                // Don't write the log more than once for every topic
     820                                if (!isset($disapprove_log_topics[$topic_id]))
     821                                {
     822                                        // Build disapproved topics log
     823                                        $disapprove_log_topics[$topic_id] = array(
     824                                                'type'                  => 'topic',
     825                                                'post_subject'  => $post_info[$post_id]['topic_title'],
     826                                                'forum_id'              => $post_info[$post_id]['forum_id'],
     827                                                'topic_id'              => 0, // useless to log a topic id, as it will be deleted
     828                                        );
     829                                }
     830                        }
     831                        else
     832                        {
     833                                // Build disapproved posts log
     834                                $disapprove_log_posts[] = array(
     835                                        'type'                  => 'post',
     836                                        'post_subject'  => $post_info[$post_id]['post_subject'],
     837                                        'forum_id'              => $post_info[$post_id]['forum_id'],
     838                                        'topic_id'              => $post_info[$post_id]['topic_id'],
    885839                                );
    886                         }
    887                         else
    888                         {
    889                                 if (!isset($topic_replies_real_sql[$post_data['topic_id']]))
    890                                 {
    891                                         $topic_replies_real_sql[$post_data['topic_id']] = 0;
    892                                 }
    893                                 $topic_replies_real_sql[$post_data['topic_id']]++;
    894 
    895                                 $disapprove_log[] = array(
    896                                         'type'                  => 'post',
    897                                         'post_subject'  => $post_data['post_subject'],
    898                                         'forum_id'              => $post_data['forum_id'],
    899                                         'topic_id'              => $post_data['topic_id'],
    900                                 );
    901                         }
    902 
    903                         $post_disapprove_sql[] = $post_id;
    904                 }
    905 
    906                 unset($post_data);
    907 
    908                 if (sizeof($forum_topics_real))
    909                 {
    910                         foreach ($forum_topics_real as $forum_id => $topics_real)
    911                         {
    912                                 $sql = 'UPDATE ' . FORUMS_TABLE . "
    913                                         SET forum_topics_real = forum_topics_real - $topics_real
    914                                         WHERE forum_id = $forum_id";
    915                                 $db->sql_query($sql);
    916                         }
    917                 }
    918 
    919                 if (sizeof($topic_replies_real_sql))
    920                 {
    921                         foreach ($topic_replies_real_sql as $topic_id => $num_replies)
    922                         {
    923                                 $sql = 'UPDATE ' . TOPICS_TABLE . "
    924                                         SET topic_replies_real = topic_replies_real - $num_replies
    925                                         WHERE topic_id = $topic_id";
    926                                 $db->sql_query($sql);
    927                         }
    928                 }
    929 
    930                 if (sizeof($post_disapprove_sql))
     840
     841                        }
     842                }
     843
     844                // Get disapproved posts/topics counts separately
     845                $num_disapproved_topics = sizeof($disapprove_log_topics);
     846                $num_disapproved_posts = sizeof($disapprove_log_posts);
     847
     848                // Build the whole log
     849                $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
     850
     851                // Unset unneeded arrays
     852                unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
     853
     854                // Let's do the job - delete disapproved posts
     855                if (sizeof($post_disapprove_list))
    931856                {
    932857                        if (!function_exists('delete_posts'))
     
    936861
    937862                        // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
    938                         delete_posts('post_id', $post_disapprove_sql);
     863                        // Note: function delete_posts triggers related forums/topics sync,
     864                        // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
     865                        delete_posts('post_id', array_keys($post_disapprove_list));
    939866
    940867                        foreach ($disapprove_log as $log_data)
     
    943870                        }
    944871                }
    945                 unset($post_disapprove_sql, $topic_replies_real_sql);
    946 
    947                 update_post_information('topic', array_keys($topic_id_list));
    948 
    949                 if (sizeof($forum_id_list))
    950                 {
    951                         update_post_information('forum', array_keys($forum_id_list));
    952                 }
    953                 unset($topic_id_list, $forum_id_list);
    954872
    955873                $messenger = new messenger();
     
    980898                                                        // Load up the language pack
    981899                                                        $lang = array();
    982                                                         @include($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx);
     900                                                        @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
    983901
    984902                                                        // If we find the reason in this language pack use it
     
    1019937                $messenger->save_queue();
    1020938
    1021                 if (sizeof($forum_topics_real))
    1022                 {
    1023                         $success_msg = ($num_disapproved == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
     939                if ($num_disapproved_topics)
     940                {
     941                        $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
    1024942                }
    1025943                else
    1026944                {
    1027                         $success_msg = (sizeof($post_id_list) == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
     945                        $success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
    1028946                }
    1029947        }
  • trunk/forum/includes/mcp/mcp_reports.php

    r400 r702  
    33*
    44* @package mcp
    5 * @version $Id: mcp_reports.php 9015 2008-10-14 18:29:50Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    7878                                                AND rr.reason_id = r.reason_id
    7979                                                AND r.user_id = u.user_id
     80                                                AND r.pm_id = 0
    8081                                        ORDER BY report_closed ASC';
    8182                                $result = $db->sql_query_limit($sql, 1);
     
    116117                                        $template->assign_vars(array(
    117118                                                'S_TOPIC_REVIEW'        => true,
     119                                                'S_BBCODE_ALLOWED'      => $post_info['enable_bbcode'],
    118120                                                'TOPIC_TITLE'           => $post_info['topic_title'])
    119121                                        );
     
    150152                                if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
    151153                                {
    152                                         $extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
    153 
    154154                                        $sql = 'SELECT *
    155155                                                FROM ' . ATTACHMENTS_TABLE . '
    156156                                                WHERE post_msg_id = ' . $post_id . '
    157157                                                        AND in_message = 0
    158                                                 ORDER BY filetime DESC, post_msg_id ASC';
     158                                                ORDER BY filetime DESC';
    159159                                        $result = $db->sql_query($sql);
    160160
     
    259259                                unset($forum_list_read);
    260260
    261                                 if ($topic_id && $forum_id)
     261                                if ($topic_id)
    262262                                {
    263263                                        $topic_info = get_topic_data(array($topic_id));
     
    268268                                        }
    269269
    270                                         $topic_info = $topic_info[$topic_id];
    271                                         $forum_id = $topic_info['forum_id'];
    272                                 }
    273                                 else if ($topic_id && !$forum_id)
    274                                 {
    275                                         $topic_id = 0;
     270                                        if ($forum_id != $topic_info[$topic_id]['forum_id'])
     271                                        {
     272                                                $topic_id = 0;
     273                                        }
     274                                        else
     275                                        {
     276                                                $topic_info = $topic_info[$topic_id];
     277                                                $forum_id = (int) $topic_info['forum_id'];
     278                                        }
    276279                                }
    277280
     
    330333
    331334                                $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
    332                                 $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
     335                                $limit_time_sql = ($sort_days) ? 'AND r.report_time >= ' . (time() - ($sort_days * 86400)) : '';
    333336
    334337                                if ($mode == 'reports')
     
    347350                                                AND r.post_id = p.post_id
    348351                                                " . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
    349                                                 ' . (($sort_order_sql[0] == 'r') ? 'AND ru.user_id = p.poster_id' : '') . '
     352                                                ' . (($sort_order_sql[0] == 'r') ? 'AND ru.user_id = r.user_id' : '') . '
    350353                                                ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
    351354                                                AND t.topic_id = p.topic_id
     355                                                AND r.pm_id = 0
    352356                                                $limit_time_sql
    353357                                        ORDER BY $sort_order_sql";
     
    372376                                                        AND u.user_id = p.poster_id
    373377                                                        AND ru.user_id = r.user_id
     378                                                        AND r.pm_id = 0
    374379                                                ORDER BY ' . $sort_order_sql;
    375380                                        $result = $db->sql_query($sql);
     
    426431                                        'TOPIC_ID'                              => $topic_id,
    427432                                        'TOTAL'                                 => $total,
    428                                         'TOTAL_REPORTS'                 => ($total == 1) ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $total),                                   
     433                                        'TOTAL_REPORTS'                 => ($total == 1) ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $total),
    429434                                        )
    430435                                );
     
    439444* Closes a report
    440445*/
    441 function close_report($report_id_list, $mode, $action)
     446function close_report($report_id_list, $mode, $action, $pm = false)
    442447{
    443         global $db, $template, $user, $config;
     448        global $db, $template, $user, $config, $auth;
    444449        global $phpEx, $phpbb_root_path;
    445450
    446         $sql = 'SELECT r.post_id
    447                 FROM ' . REPORTS_TABLE . ' r
    448                 WHERE ' . $db->sql_in_set('r.report_id', $report_id_list);
     451        $pm_where = ($pm) ? ' AND r.post_id = 0 ' : ' AND r.pm_id = 0 ';
     452        $id_column = ($pm) ? 'pm_id' : 'post_id';
     453        $module = ($pm) ? 'pm_reports' : 'reports';
     454        $pm_prefix = ($pm) ? 'PM_' : '';
     455
     456        $sql = "SELECT r.$id_column
     457                FROM " . REPORTS_TABLE . ' r
     458                WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . $pm_where;
    449459        $result = $db->sql_query($sql);
    450460
     
    452462        while ($row = $db->sql_fetchrow($result))
    453463        {
    454                 $post_id_list[] = $row['post_id'];
     464                $post_id_list[] = $row[$id_column];
    455465        }
    456466        $post_id_list = array_unique($post_id_list);
    457467
    458         if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_report')))
    459         {
    460                 trigger_error('NOT_AUTHORISED');
     468        if ($pm)
     469        {
     470                if (!$auth->acl_getf_global('m_report'))
     471                {
     472                        trigger_error('NOT_AUTHORISED');
     473                }
     474        }
     475        else
     476        {
     477                if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_report')))
     478                {
     479                        trigger_error('NOT_AUTHORISED');
     480                }
    461481        }
    462482
     
    465485                $redirect = request_var('redirect', build_url(array('mode', 'r', 'quickmod')) . '&amp;mode=reports');
    466486        }
     487        elseif ($action == 'delete' && strpos($user->data['session_page'], 'mode=pm_report_details') !== false)
     488        {
     489                $redirect = request_var('redirect', build_url(array('mode', 'r', 'quickmod')) . '&amp;mode=pm_reports');
     490        }
    467491        else if ($action == 'close' && !request_var('r', 0))
    468492        {
    469                 $redirect = request_var('redirect', build_url(array('mode', 'p', 'quickmod')) . '&amp;mode=reports');
     493                $redirect = request_var('redirect', build_url(array('mode', 'p', 'quickmod')) . '&amp;mode=' . $module);
    470494        }
    471495        else
     
    478502
    479503        $s_hidden_fields = build_hidden_fields(array(
    480                 'i'                                     => 'reports',
     504                'i'                                     => $module,
    481505                'mode'                          => $mode,
    482506                'report_id_list'        => $report_id_list,
     
    487511        if (confirm_box(true))
    488512        {
    489                 $post_info = get_post_data($post_id_list, 'm_report');
    490 
    491                 $sql = 'SELECT r.report_id, r.post_id, r.report_closed, r.user_id, r.user_notify, u.username, u.username_clean, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type
    492                         FROM ' . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u
     513                $post_info = ($pm) ? get_pm_data($post_id_list) : get_post_data($post_id_list, 'm_report');
     514
     515                $sql = "SELECT r.report_id, r.$id_column, r.report_closed, r.user_id, r.user_notify, u.username, u.username_clean, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type
     516                        FROM " . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u
    493517                        WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . '
    494518                                ' . (($action == 'close') ? 'AND r.report_closed = 0' : '') . '
    495                                 AND r.user_id = u.user_id';
     519                                AND r.user_id = u.user_id' . $pm_where;
    496520                $result = $db->sql_query($sql);
    497521
     
    504528                        if (!$report['report_closed'])
    505529                        {
    506                                 $close_report_posts[] = $report['post_id'];
    507                                 $close_report_topics[] = $post_info[$report['post_id']]['topic_id'];
     530                                $close_report_posts[] = $report[$id_column];
     531
     532                                if (!$pm)
     533                                {
     534                                        $close_report_topics[] = $post_info[$report['post_id']]['topic_id'];
     535                                }
    508536                        }
    509537
     
    520548                        $close_report_topics = array_unique($close_report_topics);
    521549
    522                         if (sizeof($close_report_posts))
     550                        if (!$pm && sizeof($close_report_posts))
    523551                        {
    524552                                // Get a list of topics that still contain reported posts
     
    559587                        if (sizeof($close_report_posts))
    560588                        {
    561                                 $sql = 'UPDATE ' . POSTS_TABLE . '
    562                                         SET post_reported = 0
    563                                         WHERE ' . $db->sql_in_set('post_id', $close_report_posts);
    564                                 $db->sql_query($sql);
    565 
    566                                 if (sizeof($close_report_topics))
    567                                 {
    568                                         $sql = 'UPDATE ' . TOPICS_TABLE . '
    569                                                 SET topic_reported = 0
    570                                                 WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . '
    571                                                         OR ' . $db->sql_in_set('topic_moved_id', $close_report_topics);
     589                                if ($pm)
     590                                {
     591                                        $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
     592                                                SET message_reported = 0
     593                                                WHERE ' . $db->sql_in_set('msg_id', $close_report_posts);
    572594                                        $db->sql_query($sql);
     595
     596                                        if ($action == 'delete')
     597                                        {
     598                                                delete_pm(ANONYMOUS, $close_report_posts, PRIVMSGS_INBOX);
     599                                        }
     600                                }
     601                                else
     602                                {
     603                                        $sql = 'UPDATE ' . POSTS_TABLE . '
     604                                                SET post_reported = 0
     605                                                WHERE ' . $db->sql_in_set('post_id', $close_report_posts);
     606                                        $db->sql_query($sql);
     607
     608                                        if (sizeof($close_report_topics))
     609                                        {
     610                                                $sql = 'UPDATE ' . TOPICS_TABLE . '
     611                                                        SET topic_reported = 0
     612                                                        WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . '
     613                                                                OR ' . $db->sql_in_set('topic_moved_id', $close_report_topics);
     614                                                $db->sql_query($sql);
     615                                        }
    573616                                }
    574617                        }
     
    580623                foreach ($reports as $report)
    581624                {
    582                         add_log('mod', $post_info[$report['post_id']]['forum_id'], $post_info[$report['post_id']]['topic_id'], 'LOG_REPORT_' .  strtoupper($action) . 'D', $post_info[$report['post_id']]['post_subject']);
     625                        if ($pm)
     626                        {
     627                                add_log('mod', 0, 0, 'LOG_PM_REPORT_' .  strtoupper($action) . 'D', $post_info[$report['pm_id']]['message_subject']);
     628                        }
     629                        else
     630                        {
     631                                add_log('mod', $post_info[$report['post_id']]['forum_id'], $post_info[$report['post_id']]['topic_id'], 'LOG_REPORT_' .  strtoupper($action) . 'D', $post_info[$report['post_id']]['post_subject']);
     632                        }
    583633                }
    584634
     
    595645                                }
    596646
    597                                 $post_id = $reporter['post_id'];
    598 
    599                                 $messenger->template('report_' . $action . 'd', $reporter['user_lang']);
     647                                $post_id = $reporter[$id_column];
     648
     649                                $messenger->template((($pm) ? 'pm_report_' : 'report_') . $action . 'd', $reporter['user_lang']);
    600650
    601651                                $messenger->to($reporter['user_email'], $reporter['username']);
    602652                                $messenger->im($reporter['user_jabber'], $reporter['username']);
    603653
    604                                 $messenger->assign_vars(array(
    605                                         'USERNAME'              => htmlspecialchars_decode($reporter['username']),
    606                                         'CLOSER_NAME'   => htmlspecialchars_decode($user->data['username']),
    607                                         'POST_SUBJECT'  => htmlspecialchars_decode(censor_text($post_info[$post_id]['post_subject'])),
    608                                         'TOPIC_TITLE'   => htmlspecialchars_decode(censor_text($post_info[$post_id]['topic_title'])))
    609                                 );
     654                                if ($pm)
     655                                {
     656                                        $messenger->assign_vars(array(
     657                                                'USERNAME'              => htmlspecialchars_decode($reporter['username']),
     658                                                'CLOSER_NAME'   => htmlspecialchars_decode($user->data['username']),
     659                                                'PM_SUBJECT'    => htmlspecialchars_decode(censor_text($post_info[$post_id]['message_subject'])),
     660                                        ));
     661                                }
     662                                else
     663                                {
     664                                        $messenger->assign_vars(array(
     665                                                'USERNAME'              => htmlspecialchars_decode($reporter['username']),
     666                                                'CLOSER_NAME'   => htmlspecialchars_decode($user->data['username']),
     667                                                'POST_SUBJECT'  => htmlspecialchars_decode(censor_text($post_info[$post_id]['post_subject'])),
     668                                                'TOPIC_TITLE'   => htmlspecialchars_decode(censor_text($post_info[$post_id]['topic_title'])))
     669                                        );
     670                                }
    610671
    611672                                $messenger->send($reporter['user_notify_type']);
    612673                        }
    613674                }
    614                
    615                 foreach ($post_info as $post)
    616                 {
    617                         $forum_ids[$post['forum_id']] = $post['forum_id'];
    618                         $topic_ids[$post['topic_id']] = $post['topic_id'];
    619                 }
    620                
     675
     676                if (!$pm)
     677                {
     678                        foreach ($post_info as $post)
     679                        {
     680                                $forum_ids[$post['forum_id']] = $post['forum_id'];
     681                                $topic_ids[$post['topic_id']] = $post['topic_id'];
     682                        }
     683                }
     684
    621685                unset($notify_reporters, $post_info, $reports);
    622686
    623687                $messenger->save_queue();
    624688
    625                 $success_msg = (sizeof($report_id_list) == 1) ? 'REPORT_' . strtoupper($action) . 'D_SUCCESS' : 'REPORTS_' . strtoupper($action) . 'D_SUCCESS';
     689                $success_msg = (sizeof($report_id_list) == 1) ? "{$pm_prefix}REPORT_" . strtoupper($action) . 'D_SUCCESS' : "{$pm_prefix}REPORTS_" . strtoupper($action) . 'D_SUCCESS';
    626690        }
    627691        else
    628692        {
    629                 confirm_box(false, $user->lang[strtoupper($action) . '_REPORT' . ((sizeof($report_id_list) == 1) ? '' : 'S') . '_CONFIRM'], $s_hidden_fields);
     693                confirm_box(false, $user->lang[strtoupper($action) . "_{$pm_prefix}REPORT" . ((sizeof($report_id_list) == 1) ? '' : 'S') . '_CONFIRM'], $s_hidden_fields);
    630694        }
    631695
     
    640704        {
    641705                meta_refresh(3, $redirect);
     706
    642707                $return_forum = '';
    643                 if (sizeof($forum_ids == 1))
    644                 {
    645                         $return_forum = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
    646                 }
    647708                $return_topic = '';
    648                 if (sizeof($topic_ids == 1))
    649                 {
    650                         $return_topic = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . current($topic_ids) . '&amp;f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
    651                 }
    652                
     709
     710                if (!$pm)
     711                {
     712                        if (sizeof($forum_ids) === 1)
     713                        {
     714                                $return_forum = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
     715                        }
     716
     717                        if (sizeof($topic_ids) === 1)
     718                        {
     719                                $return_topic = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . current($topic_ids) . '&amp;f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
     720                        }
     721                }
     722
    653723                trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_forum . $return_topic . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));
    654724        }
  • trunk/forum/includes/mcp/mcp_topic.php

    r400 r702  
    33*
    44* @package mcp
    5 * @version $Id: mcp_topic.php 9030 2008-10-19 18:32:11Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    107107        if ($total == -1)
    108108        {
    109                 $total = $topic_info['topic_replies'] + 1;
     109                if ($auth->acl_get('m_approve', $topic_info['forum_id']))
     110                {
     111                        $total = $topic_info['topic_replies_real'] + 1;
     112                }
     113                else
     114                {
     115                        $total = $topic_info['topic_replies'] + 1;
     116                }
    110117        }
    111118
     
    260267        $s_topic_icons = false;
    261268
    262         if ($auth->acl_get('m_split', $topic_info['forum_id']))
     269        if ($auth->acl_gets('m_split', 'm_merge', (int) $topic_info['forum_id']))
    263270        {
    264271                include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
     
    302309                'ACTION'                        => $action,
    303310
    304                 'REPORTED_IMG'          => $user->img('icon_topic_reported', 'POST_REPORTED', false, true),
    305                 'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED', false, true),
     311                'REPORTED_IMG'          => $user->img('icon_topic_reported', 'POST_REPORTED'),
     312                'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
     313                'INFO_IMG'                      => $user->img('icon_post_info', 'VIEW_INFO'),
    306314
    307315                'S_MCP_ACTION'          => "$url&amp;i=$id&amp;mode=$mode&amp;action=$action&amp;start=$start",
     
    502510
    503511                // Update forum statistics
    504                 set_config('num_topics', $config['num_topics'] + 1, true);
     512                set_config_count('num_topics', 1, true);
    505513
    506514                // Link back to both topics
  • trunk/forum/includes/mcp/mcp_warn.php

    r400 r702  
    33*
    44* @package mcp
    5 * @version $Id: mcp_warn.php 9002 2008-10-11 17:01:43Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    205205                $sql = 'SELECT u.*, p.*
    206206                        FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
    207                         WHERE post_id = $post_id
     207                        WHERE p.post_id = $post_id
    208208                                AND u.user_id = p.poster_id";
    209209                $result = $db->sql_query($sql);
     
    421421                        'U_POST_ACTION'         => $this->u_action,
    422422
    423                         'USERNAME'                      => $user_row['username'],
    424                         'USER_COLOR'            => (!empty($user_row['user_colour'])) ? $user_row['user_colour'] : '',
    425423                        'RANK_TITLE'            => $rank_title,
    426424                        'JOINED'                        => $user->format_date($user_row['user_regdate']),
    427425                        'POSTS'                         => ($user_row['user_posts']) ? $user_row['user_posts'] : 0,
    428426                        'WARNINGS'                      => ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0,
     427
     428                        'USERNAME_FULL'         => get_username_string('full', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
     429                        'USERNAME_COLOUR'       => get_username_string('colour', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
     430                        'USERNAME'                      => get_username_string('username', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
     431                        'U_PROFILE'                     => get_username_string('profile', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
    429432
    430433                        'AVATAR_IMG'            => $avatar_img,
  • trunk/forum/includes/message_parser.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: message_parser.php 9034 2008-10-24 00:49:30Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    119119                        'img'                   => array('bbcode_id' => 4,      'regexp' => array('#\[img\](.*)\[/img\]#iUe' => "\$this->bbcode_img('\$1')")),
    120120                        'size'                  => array('bbcode_id' => 5,      'regexp' => array('#\[size=([\-\+]?\d+)\](.*?)\[/size\]#ise' => "\$this->bbcode_size('\$1', '\$2')")),
    121                         'color'                 => array('bbcode_id' => 6,      'regexp' => array('!\[color=(#[0-9a-f]{6}|[a-z\-]+)\](.*?)\[/color\]!ise' => "\$this->bbcode_color('\$1', '\$2')")),
     121                        'color'                 => array('bbcode_id' => 6,      'regexp' => array('!\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)\](.*?)\[/color\]!ise' => "\$this->bbcode_color('\$1', '\$2')")),
    122122                        'u'                             => array('bbcode_id' => 7,      'regexp' => array('#\[u\](.*?)\[/u\]#ise' => "\$this->bbcode_underline('\$1')")),
    123123                        'list'                  => array('bbcode_id' => 9,      'regexp' => array('#\[list(?:=(?:[a-z0-9]|disc|circle|square))?].*\[/list]#ise' => "\$this->bbcode_parse_list('\$0')")),
     
    696696                * [quote="[quote]test[/quote]"]test[/quote] (correct: parsed - Username displayed as [quote]test[/quote])
    697697                * #20735 - [quote]test[/[/b]quote] test [/quote][/quote] test - (correct: quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted)
     698                * #40565 - [quote="a"]a[/quote][quote="a]a[/quote] (correct: first quote tag parsed, second quote tag unparsed)
    698699                */
    699700
     
    706707
    707708                // To let the parser not catch tokens within quote_username quotes we encode them before we start this...
    708                 $in = preg_replace('#quote=&quot;(.*?)&quot;\]#ie', "'quote=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), '\$1') . '&quot;]'", $in);
     709                $in = preg_replace('#quote=&quot;(.*?)&quot;\]#ie', "'quote=&quot;' . str_replace(array('[', ']', '\\\"'), array('&#91;', '&#93;', '\"'), '\$1') . '&quot;]'", $in);
    709710
    710711                $tok = ']';
     
    859860                while ($in);
    860861
     862                $out .= $buffer;
     863
    861864                if (sizeof($close_tags))
    862865                {
     
    10501053                // Init BBCode UID
    10511054                $this->bbcode_uid = substr(base_convert(unique_id(), 16, 36), 0, BBCODE_UID_LEN);
    1052 
    1053                 if ($message)
    1054                 {
    1055                         $this->message = $message;
    1056                 }
     1055                $this->message = $message;
    10571056        }
    10581057
     
    10641063                global $config, $db, $user;
    10651064
    1066                 $mode = ($mode != 'post') ? 'sig' : 'post';
    1067 
    10681065                $this->mode = $mode;
     1066
     1067                foreach (array('chars', 'smilies', 'urls', 'font_size', 'img_height', 'img_width') as $key)
     1068                {
     1069                        if (!isset($config['max_' . $mode . '_' . $key]))
     1070                        {
     1071                                $config['max_' . $mode . '_' . $key] = 0;
     1072                        }
     1073                }
    10691074
    10701075                $this->allow_img_bbcode = $allow_img_bbcode;
     
    10911096                $this->message = preg_replace($match, $replace, trim($this->message));
    10921097
    1093                 // Message length check. 0 disables this check completely.
    1094                 if ($config['max_' . $mode . '_chars'] > 0)
    1095                 {
    1096                         $msg_len = ($mode == 'post') ? utf8_strlen($this->message) : utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message));
    1097 
    1098                         if ((!$msg_len && $mode !== 'sig') || $config['max_' . $mode . '_chars'] && $msg_len > $config['max_' . $mode . '_chars'])
    1099                         {
    1100                                 $this->warn_msg[] = (!$msg_len) ? $user->lang['TOO_FEW_CHARS'] : sprintf($user->lang['TOO_MANY_CHARS_' . strtoupper($mode)], $msg_len, $config['max_' . $mode . '_chars']);
     1098                // Store message length...
     1099                $message_length = ($mode == 'post') ? utf8_strlen($this->message) : utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message));
     1100
     1101                // Maximum message length check. 0 disables this check completely.
     1102                if ((int) $config['max_' . $mode . '_chars'] > 0 && $message_length > (int) $config['max_' . $mode . '_chars'])
     1103                {
     1104                        $this->warn_msg[] = sprintf($user->lang['TOO_MANY_CHARS_' . strtoupper($mode)], $message_length, (int) $config['max_' . $mode . '_chars']);
     1105                        return (!$update_this_message) ? $return_message : $this->warn_msg;
     1106                }
     1107
     1108                // Minimum message length check for post only
     1109                if ($mode === 'post')
     1110                {
     1111                        if (!$message_length || $message_length < (int) $config['min_post_chars'])
     1112                        {
     1113                                $this->warn_msg[] = (!$message_length) ? $user->lang['TOO_FEW_CHARS'] : sprintf($user->lang['TOO_FEW_CHARS_LIMIT'], $message_length, (int) $config['min_post_chars']);
    11011114                                return (!$update_this_message) ? $return_message : $this->warn_msg;
    11021115                        }
    1103                 }
    1104 
    1105                 // Check for "empty" message
    1106                 if ($mode !== 'sig' && utf8_clean_string($this->message) === '')
    1107                 {
    1108                         $this->warn_msg[] = $user->lang['TOO_FEW_CHARS'];
    1109                         return (!$update_this_message) ? $return_message : $this->warn_msg;
    11101116                }
    11111117
     
    11501156                                $num_urls += preg_match_all('#\<!-- ([lmwe]) --\>.*?\<!-- \1 --\>#', $this->message, $matches);
    11511157                        }
     1158                }
     1159
     1160                // Check for "empty" message. We do not check here for maximum length, because bbcode, smilies, etc. can add to the length.
     1161                // The maximum length check happened before any parsings.
     1162                if ($mode === 'post' && utf8_clean_string($this->message) === '')
     1163                {
     1164                        $this->warn_msg[] = $user->lang['TOO_FEW_CHARS'];
     1165                        return (!$update_this_message) ? $return_message : $this->warn_msg;
    11521166                }
    11531167
     
    12991313
    13001314                                // (assertion)
    1301                                 $match[] = '(?<=^|[\n .])' . preg_quote($row['code'], '#') . '(?![^<>]*>)';
     1315                                $match[] = preg_quote($row['code'], '#');
    13021316                                $replace[] = '<!-- s' . $row['code'] . ' --><img src="{SMILIES_PATH}/' . $row['smiley_url'] . '" alt="' . $row['code'] . '" title="' . $row['emotion'] . '" /><!-- s' . $row['code'] . ' -->';
    13031317                        }
     
    13091323                        if ($max_smilies)
    13101324                        {
    1311                                 $num_matches = preg_match_all('#' . implode('|', $match) . '#', $this->message, $matches);
     1325                                $num_matches = preg_match_all('#(?<=^|[\n .])(?:' . implode('|', $match) . ')(?![^<>]*>)#', $this->message, $matches);
    13121326                                unset($matches);
    13131327
     
    13201334
    13211335                        // Make sure the delimiter # is added in front and at the end of every element within $match
    1322                         $this->message = trim(preg_replace(explode(chr(0), '#' . implode('#' . chr(0) . '#', $match) . '#'), $replace, $this->message));
     1336                        $this->message = trim(preg_replace(explode(chr(0), '#(?<=^|[\n .])' . implode('(?![^<>]*>)#' . chr(0) . '#(?<=^|[\n .])', $match) . '(?![^<>]*>)#'), $replace, $this->message));
    13231337                }
    13241338        }
     
    16131627                $bbcode_bitfield = $this->bbcode_bitfield;
    16141628
    1615                 $poll['poll_option_text'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false);
     1629                $poll['poll_option_text'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false, 'poll');
    16161630
    16171631                $bbcode_bitfield = base64_encode(base64_decode($bbcode_bitfield) | base64_decode($this->bbcode_bitfield));
     
    16361650                                $this->warn_msg[] = $user->lang['POLL_TITLE_TOO_LONG'];
    16371651                        }
    1638                         $poll['poll_title'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false);
     1652                        $poll['poll_title'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false, 'poll');
    16391653                        if (strlen($poll['poll_title']) > 255)
    16401654                        {
  • trunk/forum/includes/search/fulltext_mysql.php

    r400 r702  
    33*
    44* @package search
    5 * @version $Id: fulltext_mysql.php 8814 2008-09-04 12:01:47Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    119119        function split_keywords(&$keywords, $terms)
    120120        {
    121                 global $config;
     121                global $config, $user;
    122122
    123123                if ($terms == 'all')
     
    166166                        preg_match_all('#(?:[^\w*"()]|^)([+\-|]?(?:[\w*"()]+\'?)*[\w*"()])(?:[^\w*"()]|$)#u', $split_keywords, $matches);
    167167                        $this->split_words = $matches[1];
     168                }
     169
     170                // We limit the number of allowed keywords to minimize load on the database
     171                if ($config['max_num_search_keywords'] && sizeof($this->split_words) > $config['max_num_search_keywords'])
     172                {
     173                        trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], sizeof($this->split_words)));
    168174                }
    169175
     
    319325        *
    320326        * @param        string          $type                           contains either posts or topics depending on what should be searched for
    321         * @param        string          &$fields                        contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)
    322         * @param        string          &$terms                         is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
    323         * @param        array           &$sort_by_sql           contains SQL code for the ORDER BY part of a query
    324         * @param        string          &$sort_key                      is the key of $sort_by_sql for the selected sorting
    325         * @param        string          &$sort_dir                      is either a or d representing ASC and DESC
    326         * @param        string          &$sort_days                     specifies the maximum amount of days a post may be old
    327         * @param        array           &$ex_fid_ary            specifies an array of forum ids which should not be searched
    328         * @param        array           &$m_approve_fid_ary     specifies an array of forum ids in which the searcher is allowed to view unapproved posts
    329         * @param        int                     &$topic_id                      is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
    330         * @param        array           &$author_ary            an array of author ids if the author should be ignored during the search the array is empty
     327        * @param        string          $fields                         contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)
     328        * @param        string          $terms                          is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
     329        * @param        array           $sort_by_sql            contains SQL code for the ORDER BY part of a query
     330        * @param        string          $sort_key                       is the key of $sort_by_sql for the selected sorting
     331        * @param        string          $sort_dir                       is either a or d representing ASC and DESC
     332        * @param        string          $sort_days                      specifies the maximum amount of days a post may be old
     333        * @param        array           $ex_fid_ary                     specifies an array of forum ids which should not be searched
     334        * @param        array           $m_approve_fid_ary      specifies an array of forum ids in which the searcher is allowed to view unapproved posts
     335        * @param        int                     $topic_id                       is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
     336        * @param        array           $author_ary                     an array of author ids if the author should be ignored during the search the array is empty
     337        * @param        string          $author_name            specifies the author match, when ANONYMOUS is also a search-match
    331338        * @param        array           &$id_ary                        passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
    332339        * @param        int                     $start                          indicates the first index of the page
     
    336343        * @access       public
    337344        */
    338         function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page)
     345        function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
    339346        {
    340347                global $config, $db;
     
    435442                $sql_from                       = ($join_topic) ? TOPICS_TABLE . ' t, ' : '';
    436443                $field                          = ($type == 'posts') ? 'post_id' : 'topic_id';
    437                 $sql_author                     = (sizeof($author_ary) == 1) ? ' = ' . $author_ary[0] : 'IN (' . implode(', ', $author_ary) . ')';
     444                if (sizeof($author_ary) && $author_name)
     445                {
     446                        // first one matches post of registered users, second one guests and deleted users
     447                        $sql_author = ' AND (' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
     448                }
     449                else if (sizeof($author_ary))
     450                {
     451                        $sql_author = ' AND ' . $db->sql_in_set('p.poster_id', $author_ary);
     452                }
     453                else
     454                {
     455                        $sql_author = '';
     456                }
    438457
    439458                $sql_where_options = $sql_sort_join;
     
    442461                $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
    443462                $sql_where_options .= $m_approve_fid_sql;
    444                 $sql_where_options .= (sizeof($author_ary)) ? ' AND p.poster_id ' . $sql_author : '';
     463                $sql_where_options .= $sql_author;
    445464                $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
    446465                $sql_where_options .= $sql_match_where;
     
    455474                while ($row = $db->sql_fetchrow($result))
    456475                {
    457                         $id_ary[] = $row[$field];
     476                        $id_ary[] = (int) $row[$field];
    458477                }
    459478                $db->sql_freeresult($result);
     
    490509        * Performs a search on an author's posts without caring about message contents. Depends on display specific params
    491510        *
    492         * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
    493         * @param int $start indicates the first index of the page
    494         * @param int $per_page number of ids each page is supposed to contain
    495         * @return total number of results
    496         */
    497         function author_search($type, $firstpost_only, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page)
     511        * @param        string          $type                           contains either posts or topics depending on what should be searched for
     512        * @param        boolean         $firstpost_only         if true, only topic starting posts will be considered
     513        * @param        array           $sort_by_sql            contains SQL code for the ORDER BY part of a query
     514        * @param        string          $sort_key                       is the key of $sort_by_sql for the selected sorting
     515        * @param        string          $sort_dir                       is either a or d representing ASC and DESC
     516        * @param        string          $sort_days                      specifies the maximum amount of days a post may be old
     517        * @param        array           $ex_fid_ary                     specifies an array of forum ids which should not be searched
     518        * @param        array           $m_approve_fid_ary      specifies an array of forum ids in which the searcher is allowed to view unapproved posts
     519        * @param        int                     $topic_id                       is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
     520        * @param        array           $author_ary                     an array of author ids
     521        * @param        string          $author_name            specifies the author match, when ANONYMOUS is also a search-match
     522        * @param        array           &$id_ary                        passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
     523        * @param        int                     $start                          indicates the first index of the page
     524        * @param        int                     $per_page                       number of ids each page is supposed to contain
     525        * @return       boolean|int                                             total number of results
     526        *
     527        * @access       public
     528        */
     529        function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
    498530        {
    499531                global $config, $db;
     
    517549                        implode(',', $ex_fid_ary),
    518550                        implode(',', $m_approve_fid_ary),
    519                         implode(',', $author_ary)
     551                        implode(',', $author_ary),
     552                        $author_name,
    520553                )));
    521554
     
    530563
    531564                // Create some display specific sql strings
    532                 $sql_author             = $db->sql_in_set('p.poster_id', $author_ary);
     565                if ($author_name)
     566                {
     567                        // first one matches post of registered users, second one guests and deleted users
     568                        $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
     569                }
     570                else
     571                {
     572                        $sql_author = $db->sql_in_set('p.poster_id', $author_ary);
     573                }
    533574                $sql_fora               = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
    534575                $sql_topic_id   = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
     
    610651                while ($row = $db->sql_fetchrow($result))
    611652                {
    612                         $id_ary[] = $row[$field];
     653                        $id_ary[] = (int) $row[$field];
    613654                }
    614655                $db->sql_freeresult($result);
  • trunk/forum/includes/search/fulltext_native.php

    r400 r702  
    33*
    44* @package search
    5 * @version $Id: fulltext_native.php 9173 2008-12-04 17:01:39Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    8282        function split_keywords($keywords, $terms)
    8383        {
    84                 global $db, $user;
     84                global $db, $user, $config;
    8585
    8686                $keywords = trim($this->cleanup($keywords, '+-|()*'));
     
    168168
    169169                $keywords = preg_replace($match, $replace, $keywords);
     170                $num_keywords = sizeof(explode(' ', $keywords));
     171
     172                // We limit the number of allowed keywords to minimize load on the database
     173                if ($config['max_num_search_keywords'] && $num_keywords > $config['max_num_search_keywords'])
     174                {
     175                        trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], $num_keywords));
     176                }
    170177
    171178                // $keywords input format: each word separated by a space, words in a bracket are not separated
     
    196203                        $sql = 'SELECT word_id, word_text, word_common
    197204                                FROM ' . SEARCH_WORDLIST_TABLE . '
    198                                 WHERE ' . $db->sql_in_set('word_text', $exact_words);
     205                                WHERE ' . $db->sql_in_set('word_text', $exact_words) . '
     206                                ORDER BY word_count ASC';
    199207                        $result = $db->sql_query($sql);
    200208
     
    371379                }
    372380
    373                 sort($this->must_contain_ids);
    374                 sort($this->must_not_contain_ids);
    375                 sort($this->must_exclude_one_ids);
    376 
    377381                if (!empty($this->search_query))
    378382                {
     
    386390        *
    387391        * @param        string          $type                           contains either posts or topics depending on what should be searched for
    388         * @param        string          &$fields                        contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)
    389         * @param        string          &$terms                         is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
    390         * @param        array           &$sort_by_sql           contains SQL code for the ORDER BY part of a query
    391         * @param        string          &$sort_key                      is the key of $sort_by_sql for the selected sorting
    392         * @param        string          &$sort_dir                      is either a or d representing ASC and DESC
    393         * @param        string          &$sort_days                     specifies the maximum amount of days a post may be old
    394         * @param        array           &$ex_fid_ary            specifies an array of forum ids which should not be searched
    395         * @param        array           &$m_approve_fid_ary     specifies an array of forum ids in which the searcher is allowed to view unapproved posts
    396         * @param        int                     &$topic_id                      is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
    397         * @param        array           &$author_ary            an array of author ids if the author should be ignored during the search the array is empty
     392        * @param        string          $fields                         contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)
     393        * @param        string          $terms                          is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
     394        * @param        array           $sort_by_sql            contains SQL code for the ORDER BY part of a query
     395        * @param        string          $sort_key                       is the key of $sort_by_sql for the selected sorting
     396        * @param        string          $sort_dir                       is either a or d representing ASC and DESC
     397        * @param        string          $sort_days                      specifies the maximum amount of days a post may be old
     398        * @param        array           $ex_fid_ary                     specifies an array of forum ids which should not be searched
     399        * @param        array           $m_approve_fid_ary      specifies an array of forum ids in which the searcher is allowed to view unapproved posts
     400        * @param        int                     $topic_id                       is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
     401        * @param        array           $author_ary                     an array of author ids if the author should be ignored during the search the array is empty
     402        * @param        string          $author_name            specifies the author match, when ANONYMOUS is also a search-match
    398403        * @param        array           &$id_ary                        passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
    399404        * @param        int                     $start                          indicates the first index of the page
     
    403408        * @access       public
    404409        */
    405         function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page)
     410        function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
    406411        {
    407412                global $config, $db;
     
    413418                }
    414419
     420                $must_contain_ids = $this->must_contain_ids;
     421                $must_not_contain_ids = $this->must_not_contain_ids;
     422                $must_exclude_one_ids = $this->must_exclude_one_ids;
     423
     424                sort($must_contain_ids);
     425                sort($must_not_contain_ids);
     426                sort($must_exclude_one_ids);
     427
    415428                // generate a search_key from all the options to identify the results
    416429                $search_key = md5(implode('#', array(
    417                         serialize($this->must_contain_ids),
    418                         serialize($this->must_not_contain_ids),
    419                         serialize($this->must_exclude_one_ids),
     430                        serialize($must_contain_ids),
     431                        serialize($must_not_contain_ids),
     432                        serialize($must_exclude_one_ids),
    420433                        $type,
    421434                        $fields,
     
    426439                        implode(',', $ex_fid_ary),
    427440                        implode(',', $m_approve_fid_ary),
    428                         implode(',', $author_ary)
     441                        implode(',', $author_ary),
     442                        $author_name,
    429443                )));
    430444
     
    617631                if (sizeof($author_ary))
    618632                {
    619                         $sql_where[] = $db->sql_in_set('p.poster_id', $author_ary);
     633                        if ($author_name)
     634                        {
     635                                // first one matches post of registered users, second one guests and deleted users
     636                                $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
     637                        }
     638                        else
     639                        {
     640                                $sql_author = $db->sql_in_set('p.poster_id', $author_ary);
     641                        }
     642                        $sql_where[] = $sql_author;
    620643                }
    621644
     
    639662                        $sql_array_count = $sql_array;
    640663
     664                        if ($left_join_topics)
     665                        {
     666                                $sql_array_count['LEFT_JOIN'][] = array(
     667                                        'FROM'  => array(TOPICS_TABLE => 't'),
     668                                        'ON'    => 'p.topic_id = t.topic_id'
     669                                );
     670                        }
     671
    641672                        switch ($db->sql_layer)
    642673                        {
     
    645676
    646677                                        // 3.x does not support SQL_CALC_FOUND_ROWS
    647                                         $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT'];
     678                                        // $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT'];
    648679                                        $is_mysql = true;
    649680
     
    694725                        break;
    695726                }
    696                
     727
    697728                if ($left_join_topics)
    698729                {
    699                         $sql_array['LEFT_JOIN'][$left_join_topics] = array(
     730                        $sql_array['LEFT_JOIN'][] = array(
    700731                                'FROM'  => array(TOPICS_TABLE => 't'),
    701732                                'ON'    => 'p.topic_id = t.topic_id'
     
    714745                while ($row = $db->sql_fetchrow($result))
    715746                {
    716                         $id_ary[] = $row[(($type == 'posts') ? 'post_id' : 'topic_id')];
     747                        $id_ary[] = (int) $row[(($type == 'posts') ? 'post_id' : 'topic_id')];
    717748                }
    718749                $db->sql_freeresult($result);
     
    726757                if (!$total_results && $is_mysql)
    727758                {
     759                        // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it.
     760                        $sql_array_copy = $sql_array;
     761                        $sql_array_copy['SELECT'] = 'SQL_CALC_FOUND_ROWS p.post_id ';
     762
     763                        $sql = $db->sql_build_query('SELECT', $sql_array_copy);
     764                        unset($sql_array_copy);
     765
     766                        $db->sql_query($sql);
     767                        $db->sql_freeresult($result);
     768
    728769                        $sql = 'SELECT FOUND_ROWS() as total_results';
    729770                        $result = $db->sql_query($sql);
     
    749790        * @param        string          $type                           contains either posts or topics depending on what should be searched for
    750791        * @param        boolean         $firstpost_only         if true, only topic starting posts will be considered
    751         * @param        array           &$sort_by_sql           contains SQL code for the ORDER BY part of a query
    752         * @param        string          &$sort_key                      is the key of $sort_by_sql for the selected sorting
    753         * @param        string          &$sort_dir                      is either a or d representing ASC and DESC
    754         * @param        string          &$sort_days                     specifies the maximum amount of days a post may be old
    755         * @param        array           &$ex_fid_ary            specifies an array of forum ids which should not be searched
    756         * @param        array           &$m_approve_fid_ary     specifies an array of forum ids in which the searcher is allowed to view unapproved posts
    757         * @param        int                     &$topic_id                      is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
    758         * @param        array           &$author_ary            an array of author ids
     792        * @param        array           $sort_by_sql            contains SQL code for the ORDER BY part of a query
     793        * @param        string          $sort_key                       is the key of $sort_by_sql for the selected sorting
     794        * @param        string          $sort_dir                       is either a or d representing ASC and DESC
     795        * @param        string          $sort_days                      specifies the maximum amount of days a post may be old
     796        * @param        array           $ex_fid_ary                     specifies an array of forum ids which should not be searched
     797        * @param        array           $m_approve_fid_ary      specifies an array of forum ids in which the searcher is allowed to view unapproved posts
     798        * @param        int                     $topic_id                       is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
     799        * @param        array           $author_ary                     an array of author ids
     800        * @param        string          $author_name            specifies the author match, when ANONYMOUS is also a search-match
    759801        * @param        array           &$id_ary                        passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
    760802        * @param        int                     $start                          indicates the first index of the page
     
    764806        * @access       public
    765807        */
    766         function author_search($type, $firstpost_only, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page)
     808        function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
    767809        {
    768810                global $config, $db;
     
    786828                        implode(',', $ex_fid_ary),
    787829                        implode(',', $m_approve_fid_ary),
    788                         implode(',', $author_ary)
     830                        implode(',', $author_ary),
     831                        $author_name,
    789832                )));
    790833
     
    799842
    800843                // Create some display specific sql strings
    801                 $sql_author             = $db->sql_in_set('p.poster_id', $author_ary);
     844                if ($author_name)
     845                {
     846                        // first one matches post of registered users, second one guests and deleted users
     847                        $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
     848                }
     849                else
     850                {
     851                        $sql_author = $db->sql_in_set('p.poster_id', $author_ary);
     852                }
    802853                $sql_fora               = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
    803854                $sql_time               = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
     
    849900                                case 'mysql4':
    850901                                case 'mysqli':
    851                                         $select = 'SQL_CALC_FOUND_ROWS ' . $select;
     902//                                      $select = 'SQL_CALC_FOUND_ROWS ' . $select;
    852903                                        $is_mysql = true;
    853904                                break;
     
    936987                while ($row = $db->sql_fetchrow($result))
    937988                {
    938                         $id_ary[] = $row[$field];
     989                        $id_ary[] = (int) $row[$field];
    939990                }
    940991                $db->sql_freeresult($result);
     
    942993                if (!$total_results && $is_mysql)
    943994                {
     995                        // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it.
     996                        $sql = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql);
     997
     998                        $db->sql_query($sql);
     999                        $db->sql_freeresult($result);
     1000
    9441001                        $sql = 'SELECT FOUND_ROWS() as total_results';
    9451002                        $result = $db->sql_query($sql);
     
    11111168                // Get unique words from the above arrays
    11121169                $unique_add_words = array_unique(array_merge($words['add']['post'], $words['add']['title']));
    1113                
     1170
    11141171                // We now have unique arrays of all words to be added and removed and
    11151172                // individual arrays of added and removed words for text and title. What
  • trunk/forum/includes/session.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: session.php 9170 2008-12-04 12:56:12Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    214214                $this->browser                          = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : '';
    215215                $this->referer                          = (!empty($_SERVER['HTTP_REFERER'])) ? htmlspecialchars((string) $_SERVER['HTTP_REFERER']) : '';
    216                 $this->forwarded_for            = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? (string) $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
     216                $this->forwarded_for            = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? htmlspecialchars((string) $_SERVER['HTTP_X_FORWARDED_FOR']) : '';
    217217
    218218                $this->host                                     = $this->extract_current_hostname();
     
    222222                if ($config['forwarded_for_check'])
    223223                {
    224                         $this->forwarded_for = preg_replace('#, +#', ', ', $this->forwarded_for);
     224                        $this->forwarded_for = preg_replace('#[ ]{2,}#', ' ', str_replace(array(',', ' '), ' ', $this->forwarded_for));
    225225
    226226                        // split the list of IPs
    227                         $ips = explode(', ', $this->forwarded_for);
     227                        $ips = explode(' ', $this->forwarded_for);
    228228                        foreach ($ips as $ip)
    229229                        {
     
    268268                // Why no forwarded_for et al? Well, too easily spoofed. With the results of my recent requests
    269269                // it's pretty clear that in the majority of cases you'll at least be left with a proxy/cache ip.
    270                 $this->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
     270                $this->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars((string) $_SERVER['REMOTE_ADDR']) : '';
     271                $this->ip = preg_replace('#[ ]{2,}#', ' ', str_replace(array(',', ' '), ' ', $this->ip));
     272
     273                // split the list of IPs
     274                $ips = explode(' ', $this->ip);
     275
     276                // Default IP if REMOTE_ADDR is invalid
     277                $this->ip = '127.0.0.1';
     278
     279                foreach ($ips as $ip)
     280                {
     281                        // check IPv4 first, the IPv6 is hopefully only going to be used very seldomly
     282                        if (!empty($ip) && !preg_match(get_preg_expression('ipv4'), $ip) && !preg_match(get_preg_expression('ipv6'), $ip))
     283                        {
     284                                // Just break
     285                                break;
     286                        }
     287
     288                        // Use the last in chain
     289                        $this->ip = $ip;
     290                }
     291
    271292                $this->load = false;
    272293
     
    397418                                                                $db->sql_query($sql);
    398419                                                        }
     420
     421                                                        if ($this->data['user_id'] != ANONYMOUS && !empty($config['new_member_post_limit']) && $this->data['user_new'] && $config['new_member_post_limit'] <= $this->data['user_posts'])
     422                                                        {
     423                                                                $this->leave_newly_registered();
     424                                                        }
    399425                                                }
    400426
     
    481507                                foreach (explode(',', $row['bot_ip']) as $bot_ip)
    482508                                {
     509                                        $bot_ip = trim($bot_ip);
     510
     511                                        if (!$bot_ip)
     512                                        {
     513                                                continue;
     514                                        }
     515
    483516                                        if (strpos($this->ip, $bot_ip) === 0)
    484517                                        {
     
    595628                        else
    596629                        {
    597                                 $ips = explode(', ', $this->forwarded_for);
     630                                $ips = explode(' ', $this->forwarded_for);
    598631                                $ips[] = $this->ip;
    599632                                $this->check_ban($this->data['user_id'], $ips);
     
    720753//              $db->sql_return_on_error(false);
    721754
     755                // Something quite important: session_page always holds the *last* page visited, except for the *first* visit.
     756                // We are not able to simply have an empty session_page btw, therefore we need to tell phpBB how to detect this special case.
     757                // If the session id is empty, we have a completely new one and will set an "identifier" here. This identifier is able to be checked later.
     758                if (empty($this->data['session_id']))
     759                {
     760                        // This is a temporary variable, only set for the very first visit
     761                        $this->data['session_created'] = true;
     762                }
     763
    722764                $this->session_id = $this->data['session_id'] = md5(unique_id());
    723765
     
    876918        function session_gc()
    877919        {
    878                 global $db, $config;
     920                global $db, $config, $phpbb_root_path, $phpEx;
    879921
    880922                $batch_size = 10;
     
    934976                                $db->sql_query($sql);
    935977                        }
    936                         $this->confirm_gc();
     978
     979                        // only called from CRON; should be a safe workaround until the infrastructure gets going
     980                        if (!class_exists('captcha_factory'))
     981                        {
     982                                include($phpbb_root_path . "includes/captcha/captcha_factory." . $phpEx);
     983                        }
     984                        phpbb_captcha_factory::garbage_collect($config['captcha_plugin']);
    937985                }
    938986
    939987                return;
    940988        }
    941 
    942         function confirm_gc($type = 0)
    943         {
    944                 global $db, $config;
    945 
    946                 $sql = 'SELECT DISTINCT c.session_id
    947                                 FROM ' . CONFIRM_TABLE . ' c
    948                                 LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id)
    949                                 WHERE s.session_id IS NULL' .
    950                                         ((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type);
    951                 $result = $db->sql_query($sql);
    952 
    953                 if ($row = $db->sql_fetchrow($result))
    954                 {
    955                         $sql_in = array();
    956                         do
    957                         {
    958                                 $sql_in[] = (string) $row['session_id'];
    959                         }
    960                         while ($row = $db->sql_fetchrow($result));
    961 
    962                         if (sizeof($sql_in))
    963                         {
    964                                 $sql = 'DELETE FROM ' . CONFIRM_TABLE . '
    965                                         WHERE ' . $db->sql_in_set('session_id', $sql_in);
    966                                 $db->sql_query($sql);
    967                         }
    968                 }
    969                 $db->sql_freeresult($result);
    970         }
    971 
    972989
    973990        /**
     
    12051222
    12061223                $dnsbl_check = array(
    1207                         'sbl-xbl.spamhaus.org'  => 'http://www.spamhaus.org/query/bl?ip=',
     1224                        'sbl.spamhaus.org'      => 'http://www.spamhaus.org/query/bl?ip=',
    12081225                );
    12091226
     
    13391356                global $config, $db;
    13401357
    1341                 $user_id = ($user_id === false) ? $this->data['user_id'] : $user_id;
     1358                $user_id = ($user_id === false) ? (int) $this->data['user_id'] : (int) $user_id;
    13421359
    13431360                $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . '
     
    13451362                $db->sql_query($sql);
    13461363
     1364                // If the user is logged in, update last visit info first before deleting sessions
     1365                $sql = 'SELECT session_time, session_page
     1366                        FROM ' . SESSIONS_TABLE . '
     1367                        WHERE session_user_id = ' . (int) $user_id . '
     1368                        ORDER BY session_time DESC';
     1369                $result = $db->sql_query_limit($sql, 1);
     1370                $row = $db->sql_fetchrow($result);
     1371                $db->sql_freeresult($result);
     1372
     1373                if ($row)
     1374                {
     1375                        $sql = 'UPDATE ' . USERS_TABLE . '
     1376                                SET user_lastvisit = ' . (int) $row['session_time'] . ", user_lastpage = '" . $db->sql_escape($row['session_page']) . "'
     1377                                WHERE user_id = " . (int) $user_id;
     1378                        $db->sql_query($sql);
     1379                }
     1380
    13471381                // Let's also clear any current sessions for the specified user_id
    13481382                // If it's the current user then we'll leave this session intact
    13491383                $sql_where = 'session_user_id = ' . (int) $user_id;
    1350                 $sql_where .= ($user_id === $this->data['user_id']) ? " AND session_id <> '" . $db->sql_escape($this->session_id) . "'" : '';
     1384                $sql_where .= ($user_id === (int) $this->data['user_id']) ? " AND session_id <> '" . $db->sql_escape($this->session_id) . "'" : '';
    13511385
    13521386                $sql = 'DELETE FROM ' . SESSIONS_TABLE . "
     
    13561390                // We're changing the password of the current user and they have a key
    13571391                // Lets regenerate it to be safe
    1358                 if ($user_id === $this->data['user_id'] && $this->cookie_data['k'])
     1392                if ($user_id === (int) $this->data['user_id'] && $this->cookie_data['k'])
    13591393                {
    13601394                        $this->set_login_key($user_id);
     
    13691403        function validate_referer($check_script_path = false)
    13701404        {
     1405                global $config;
     1406
    13711407                // no referer - nothing to validate, user's fault for turning it off (we only check on POST; so meta can't be the reason)
    13721408                if (empty($this->referer) || empty($this->host))
     
    13781414                $ref = substr($this->referer, strpos($this->referer, '://') + 3);
    13791415
    1380                 if (!(stripos($ref, $host) === 0))
     1416                if (!(stripos($ref, $host) === 0) && (!$config['force_server_vars'] || !(stripos($ref, $config['server_name']) === 0)))
    13811417                {
    13821418                        return false;
     
    14361472        var $img_array = array();
    14371473
    1438         // Able to add new option (id 7)
    1439         var $keyoptions = array('viewimg' => 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'popuppm' => 10);
     1474        // Able to add new options (up to id 31)
     1475        var $keyoptions = array('viewimg' => 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'popuppm' => 10, 'sig_bbcode' => 15, 'sig_smilies' => 16, 'sig_links' => 17);
    14401476        var $keyvalues = array();
    14411477
     
    15281564                $lang = &$this->lang;
    15291565
    1530                 if ((@include $this->lang_path . $this->lang_name . "/common.$phpEx") === false)
     1566                // Do not suppress error if in DEBUG_EXTRA mode
     1567                $include_result = (defined('DEBUG_EXTRA')) ? (include $this->lang_path . $this->lang_name . "/common.$phpEx") : (@include $this->lang_path . $this->lang_name . "/common.$phpEx");
     1568
     1569                if ($include_result === false)
    15311570                {
    15321571                        die('Language file ' . $this->lang_path . $this->lang_name . "/common.$phpEx" . " couldn't be opened.");
     
    15361575                unset($lang_set);
    15371576
    1538                 if (!empty($_GET['style']) && $auth->acl_get('a_styles'))
     1577                if (!empty($_GET['style']) && $auth->acl_get('a_styles') && !defined('ADMIN_START'))
    15391578                {
    15401579                        global $SID, $_EXTRA_URL;
     
    16581697                $this->img_lang = (file_exists($phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . $this->lang_name)) ? $this->lang_name : $config['default_lang'];
    16591698
    1660                 $sql = 'SELECT image_name, image_filename, image_lang, image_height, image_width
     1699                // Same query in style.php
     1700                $sql = 'SELECT *
    16611701                        FROM ' . STYLES_IMAGESET_DATA_TABLE . '
    16621702                        WHERE imageset_id = ' . $this->theme['imageset_id'] . "
     
    17571797                // Disable board if the install/ directory is still present
    17581798                // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally
    1759                 if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install'))
     1799                if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
    17601800                {
    17611801                        // Adjust the message slightly according to the permissions
     
    17741814                if ($config['board_disable'] && !defined('IN_LOGIN') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
    17751815                {
    1776                         header('HTTP/1.1 503 Service Unavailable');
     1816                        if ($this->data['is_bot'])
     1817                        {
     1818                                header('HTTP/1.1 503 Service Unavailable');
     1819                        }
    17771820
    17781821                        $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
     
    17901833                                if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
    17911834                                {
    1792                                         header('HTTP/1.1 503 Service Unavailable');
     1835                                        if ($this->data['is_bot'])
     1836                                        {
     1837                                                header('HTTP/1.1 503 Service Unavailable');
     1838                                        }
    17931839                                        trigger_error('BOARD_UNAVAILABLE');
    17941840                                }
     
    18281874                // Does the user need to change their password? If so, redirect to the
    18291875                // ucp profile reg_details page ... of course do not redirect if we're already in the ucp
    1830                 if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && $this->data['is_registered'] && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($config['chg_passforce'] * 86400))
     1876                if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && !empty($this->data['is_registered']) && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($config['chg_passforce'] * 86400))
    18311877                {
    18321878                        if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx")
     
    20012047                        }
    20022048
    2003                         if ((@include $language_filename) === false)
     2049                        if (!file_exists($language_filename))
     2050                        {
     2051                                global $config;
     2052
     2053                                if ($this->lang_name == 'en')
     2054                                {
     2055                                        // The user's selected language is missing the file, the board default's language is missing the file, and the file doesn't exist in /en.
     2056                                        $language_filename = str_replace($this->lang_path . 'en', $this->lang_path . $this->data['user_lang'], $language_filename);
     2057                                        trigger_error('Language file ' . $language_filename . ' couldn\'t be opened.', E_USER_ERROR);
     2058                                }
     2059                                else if ($this->lang_name == basename($config['default_lang']))
     2060                                {
     2061                                        // Fall back to the English Language
     2062                                        $this->lang_name = 'en';
     2063                                        $this->set_lang($lang, $help, $lang_file, $use_db, $use_help);
     2064                                }
     2065                                else if ($this->lang_name == $this->data['user_lang'])
     2066                                {
     2067                                        // Fall back to the board default language
     2068                                        $this->lang_name = basename($config['default_lang']);
     2069                                        $this->set_lang($lang, $help, $lang_file, $use_db, $use_help);
     2070                                }
     2071
     2072                                // Reset the lang name
     2073                                $this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']);
     2074                                return;
     2075                        }
     2076
     2077                        // Do not suppress error if in DEBUG_EXTRA mode
     2078                        $include_result = (defined('DEBUG_EXTRA')) ? (include $language_filename) : (@include $language_filename);
     2079
     2080                        if ($include_result === false)
    20042081                        {
    20052082                                trigger_error('Language file ' . $language_filename . ' couldn\'t be opened.', E_USER_ERROR);
     
    20372114                        $date_cache[$format] = array(
    20382115                                'is_short'              => strpos($format, '|'),
    2039                                 'zone_offset'   => $this->timezone + $this->dst,
    20402116                                'format_short'  => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1),
    20412117                                'format_long'   => str_replace('|', '', $format),
     
    20502126                }
    20512127
     2128                // Zone offset
     2129                $zone_offset = $this->timezone + $this->dst;
     2130
    20522131                // Show date <= 1 hour ago as 'xx min ago'
    2053                 // A small tolerence is given for times in the future and times in the future but in the same minute are displayed as '< than a minute ago'
     2132                // A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago'
    20542133                if ($delta <= 3600 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO']))
    20552134                {
     
    20592138                if (!$midnight)
    20602139                {
    2061                         list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $date_cache[$format]['zone_offset']));
    2062                         $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $date_cache[$format]['zone_offset'];
    2063                 }
    2064 
    2065                 if ($date_cache[$format]['is_short'] !== false && !$forcedate)
     2140                        list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset));
     2141                        $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset;
     2142                }
     2143
     2144                if ($date_cache[$format]['is_short'] !== false && !$forcedate && !($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800))
    20662145                {
    20672146                        $day = false;
     
    20822161                        if ($day !== false)
    20832162                        {
    2084                                 return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $date_cache[$format]['zone_offset']), $date_cache[$format]['lang']));
    2085                         }
    2086                 }
    2087 
    2088                 return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $date_cache[$format]['zone_offset']), $date_cache[$format]['lang']);
     2163                                return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $zone_offset), $date_cache[$format]['lang']));
     2164                        }
     2165                }
     2166
     2167                return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']);
    20892168        }
    20902169
     
    21562235                        }
    21572236
    2158                         $img_data['src'] = $phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . ($this->img_array[$img]['image_lang'] ? $this->img_array[$img]['image_lang'] .'/' : '') . $this->img_array[$img]['image_filename'];
     2237                        // Use URL if told so
     2238                        $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path;
     2239
     2240                        $img_data['src'] = $root_path . 'styles/' . rawurlencode($this->theme['imageset_path']) . '/imageset/' . ($this->img_array[$img]['image_lang'] ? $this->img_array[$img]['image_lang'] .'/' : '') . $this->img_array[$img]['image_filename'];
    21592241                        $img_data['width'] = $this->img_array[$img]['image_width'];
    21602242                        $img_data['height'] = $this->img_array[$img]['image_height'];
     
    22292311                }
    22302312        }
     2313
     2314        /**
     2315        * Funtion to make the user leave the NEWLY_REGISTERED system group.
     2316        * @access public
     2317        */
     2318        function leave_newly_registered()
     2319        {
     2320                global $db;
     2321
     2322                if (empty($this->data['user_new']))
     2323                {
     2324                        return false;
     2325                }
     2326
     2327                if (!function_exists('remove_newly_registered'))
     2328                {
     2329                        global $phpbb_root_path, $phpEx;
     2330
     2331                        include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
     2332                }
     2333                if ($group = remove_newly_registered($this->data['user_id'], $this->data))
     2334                {
     2335                        $this->data['group_id'] = $group;
     2336
     2337                }
     2338                $this->data['user_permissions'] = '';
     2339                $this->data['user_new'] = 0;
     2340
     2341                return true;
     2342        }
    22312343}
    22322344
  • trunk/forum/includes/template.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: template.php 8943 2008-09-26 13:09:56Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4040        var $files_template = array();
    4141        var $inherit_root = '';
     42        var $orig_tpl_storedb;
     43        var $orig_tpl_inherits_id;
    4244
    4345        // this will hash handle names to the compiled/uncompiled code for that handle.
     
    5658                        $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template';
    5759                        $this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_';
    58                        
     60
     61                        if ($this->orig_tpl_storedb === null)
     62                        {
     63                                $this->orig_tpl_storedb = $user->theme['template_storedb'];
     64                        }
     65
     66                        if ($this->orig_tpl_inherits_id === null)
     67                        {
     68                                $this->orig_tpl_inherits_id = $user->theme['template_inherits_id'];
     69                        }
     70
     71                        $user->theme['template_storedb'] = $this->orig_tpl_storedb;
     72                        $user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id;
     73
    5974                        if ($user->theme['template_inherits_id'])
    6075                        {
     
    7691        * @access public
    7792        */
    78         function set_custom_template($template_path, $template_name)
    79         {
    80                 global $phpbb_root_path;
     93        function set_custom_template($template_path, $template_name, $fallback_template_path = false)
     94        {
     95                global $phpbb_root_path, $user;
     96
     97                // Make sure $template_path has no ending slash
     98                if (substr($template_path, -1) == '/')
     99                {
     100                        $template_path = substr($template_path, 0, -1);
     101                }
    81102
    82103                $this->root = $template_path;
    83104                $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_';
    84105
     106                if ($fallback_template_path !== false)
     107                {
     108                        if (substr($fallback_template_path, -1) == '/')
     109                        {
     110                                $fallback_template_path = substr($fallback_template_path, 0, -1);
     111                        }
     112
     113                        $this->inherit_root = $fallback_template_path;
     114                        $this->orig_tpl_inherits_id = true;
     115                }
     116                else
     117                {
     118                        $this->orig_tpl_inherits_id = false;
     119                }
     120
     121                // the database does not store the path or name of a custom template
     122                // so there is no way we can properly store custom templates there
     123                $this->orig_tpl_storedb = false;
     124
     125                $this->_rootref = &$this->_tpldata['.'][0];
     126
    85127                return true;
    86128        }
     
    106148                        $this->filename[$handle] = $filename;
    107149                        $this->files[$handle] = $this->root . '/' . $filename;
    108                        
     150
    109151                        if ($this->inherit_root)
    110152                        {
     
    112154                        }
    113155                }
    114                
     156
    115157                return true;
    116158        }
     
    123165        {
    124166                $this->_tpldata = array('.' => array(0 => array()));
     167                $this->_rootref = &$this->_tpldata['.'][0];
    125168        }
    126169
     
    210253                return true;
    211254        }
    212        
     255
    213256        /**
    214257        * Load a compiled template if possible, if not, recompile it
     
    219262                global $user, $phpEx, $config;
    220263
     264                if (!isset($this->filename[$handle]))
     265                {
     266                        trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR);
     267                }
     268
     269                // reload these settings to have the values they had when this object was initialised
     270                // using set_template or set_custom_template, they might otherwise have been overwritten
     271                // by other template class instances in between.
     272                $user->theme['template_storedb'] = $this->orig_tpl_storedb;
     273                $user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id;
     274
    221275                $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx;
    222                 $this->files_template[$handle] = $user->theme['template_id'];
    223                
     276                $this->files_template[$handle] = (isset($user->theme['template_id'])) ? $user->theme['template_id'] : 0;
     277
    224278                $recompile = false;
    225279                if (!file_exists($filename) || @filesize($filename) === 0)
     
    237291                        $recompile = (@filemtime($filename) < filemtime($this->files[$handle])) ? true : false;
    238292                }
    239                
     293
    240294                // Recompile page if the original template is newer, otherwise load the compiled version
    241295                if (!$recompile)
     
    250304                        include($phpbb_root_path . 'includes/functions_template.' . $phpEx);
    251305                }
    252                
     306
    253307                // Inheritance - we point to another template file for this one. Equality is also used for store_db
    254308                if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($this->files[$handle]))
     
    257311                        $this->files_template[$handle] = $user->theme['template_inherits_id'];
    258312                }
    259                
     313
    260314                $compile = new template_compile($this);
    261315
     
    283337                        }
    284338                        $ids[] = $user->theme['template_id'];
    285                        
     339
    286340                        foreach ($ids as $id)
    287341                        {
     
    291345                                        AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "'
    292346                                                OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')';
    293                        
     347
    294348                                $result = $db->sql_query($sql);
    295349                                while ($row = $db->sql_fetchrow($result))
     
    299353                                $db->sql_freeresult($result);
    300354                        }
    301                                        
     355
    302356                        if (sizeof($rows))
    303357                        {
     
    327381                                                $this->files_template[$row['template_filename']] = $user->theme['template_id'];
    328382                                        }
    329                                        
     383
    330384                                        if ($force_reload || $row['template_mtime'] < filemtime($file))
    331385                                        {
     
    469523                                unset($this->_tpldata[$blockname][($s_row_count - 1)]['S_LAST_ROW']);
    470524                        }
    471                        
     525
    472526                        // Add a new iteration to this block with the variable assignments we were given.
    473527                        $this->_tpldata[$blockname][] = $vararray;
     
    512566                        return false;
    513567                }
    514                
     568
    515569                // Change key to zero (change first position) if false and to last position if true
    516570                if ($key === false || $key === true)
     
    615669                }
    616670        }
     671
     672        /**
     673        * Include a php-file
     674        * @access private
     675        */
     676        function _php_include($filename)
     677        {
     678                global $phpbb_root_path;
     679
     680                $file = $phpbb_root_path . $filename;
     681
     682                if (!file_exists($file))
     683                {
     684                        // trigger_error cannot be used here, as the output already started
     685                        echo 'template->_php_include(): File ' . htmlspecialchars($file) . ' does not exist or is empty';
     686                        return;
     687                }
     688                include($file);
     689        }
    617690}
    618691
  • trunk/forum/includes/ucp/ucp_activate.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_activate.php 9067 2008-11-21 13:21:53Z Kellanved $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    5757                }
    5858
     59                // Do not allow activating by non administrators when admin activation is on
     60                // Only activation type the user should be able to do is INACTIVE_REMIND
     61                // or activate a new password which is not an activation state :@
     62                if (!$user_row['user_newpasswd'] && $user_row['user_inactive_reason'] != INACTIVE_REMIND && $config['require_activation'] == USER_ACTIVATION_ADMIN && !$auth->acl_get('a_user'))
     63                {
     64                        if (!$user->data['is_registered'])
     65                        {
     66                                login_box('', $user->lang['NO_AUTH_OPERATION']);
     67                        }
     68                        trigger_error('NO_AUTH_OPERATION');
     69                }
     70
    5971                $update_password = ($user_row['user_newpasswd']) ? true : false;
    6072
     
    7385                                WHERE user_id = ' . $user_row['user_id'];
    7486                        $db->sql_query($sql);
     87
     88                        add_log('user', $user_row['user_id'], 'LOG_USER_NEW_PASSWORD', $user_row['username']);
    7589                }
    7690
  • trunk/forum/includes/ucp/ucp_attachments.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_attachments.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    185185                        'U_SORT_DOWNLOADS'              => $this->u_action . "&amp;sk=e&amp;sd=" . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
    186186                        'U_SORT_POST_TIME'              => $this->u_action . "&amp;sk=f&amp;sd=" . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
    187                         'U_SORT_TOPIC_TITLE'    => $this->u_action . "&amp;sk=g&amp;sd=" . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
     187                        'U_SORT_TOPIC_TITLE'    => $this->u_action . "&amp;sk=g&amp;sd=" . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
    188188
    189189                        'S_DISPLAY_MARK_ALL'    => ($num_attachments) ? true : false,
  • trunk/forum/includes/ucp/ucp_confirm.php

    r400 r702  
    33*
    44* @package VC
    5 * @version $Id: ucp_confirm.php 8655 2008-06-13 19:39:01Z acydburn $
    6 * @copyright (c) 2005 phpBB Group
     5* @version $Id$
     6* @copyright (c) 2005 2008 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    88*
     
    3838                global $db, $user, $phpbb_root_path, $config, $phpEx;
    3939
    40                 // Do we have an id? No, then just exit
    41                 $confirm_id = request_var('id', '');
    42                 $type = request_var('type', 0);
    43 
    44                 if (!$confirm_id || !$type)
    45                 {
    46                         exit;
    47                 }
    48 
    49                 // Try and grab code for this id and session
    50                 $sql = 'SELECT code, seed
    51                         FROM ' . CONFIRM_TABLE . "
    52                         WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
    53                                 AND confirm_id = '" . $db->sql_escape($confirm_id) . "'
    54                                 AND confirm_type = $type";
    55                 $result = $db->sql_query($sql);
    56                 $row = $db->sql_fetchrow($result);
    57                 $db->sql_freeresult($result);
    58 
    59                 // If we have a row then grab data else create a new id
    60                 if (!$row)
    61                 {
    62                         exit;
    63                 }
    64 
    65                 if ($config['captcha_gd'])
    66                 {
    67                         include($phpbb_root_path . 'includes/captcha/captcha_gd.' . $phpEx);
    68                 }
    69                 else
    70                 {
    71                         include($phpbb_root_path . 'includes/captcha/captcha_non_gd.' . $phpEx);
    72                 }
    73 
    74                 $captcha = new captcha();
    75                 $captcha->execute($row['code'], $row['seed']);
     40                include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
     41                $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
     42                $captcha->init(request_var('type', 0));
     43                $captcha->execute();
    7644
    7745                garbage_collection();
  • trunk/forum/includes/ucp/ucp_groups.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_groups.php 9067 2008-11-21 13:21:53Z Kellanved $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4242                {
    4343                        case 'membership':
    44                
     44
    4545                                $this->page_title = 'UCP_USERGROUPS_MEMBER';
    4646
     
    341341                                        );
    342342
    343                                         $group_id_ary[] = $row['group_id'];
     343                                        $group_id_ary[] = (int) $row['group_id'];
    344344                                }
    345345                                $db->sql_freeresult($result);
     
    415415                                $action         = (isset($_POST['addusers'])) ? 'addusers' : request_var('action', '');
    416416                                $group_id       = request_var('g', 0);
    417                                
     417
    418418                                include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
    419419
     
    439439                                                trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . $return_page, E_USER_WARNING);
    440440                                        }
    441                                        
     441
    442442                                        $group_name = $group_row['group_name'];
    443443                                        $group_type = $group_row['group_type'];
    444                                        
     444
    445445                                        $avatar_img = (!empty($group_row['group_avatar'])) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_root_path . 'adm/images/no_avatar.gif" alt="" />';
    446446
     
    451451                                                'GROUP_DESC_DISP'               => generate_text_for_display($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield'], $group_row['group_desc_options']),
    452452                                                'GROUP_TYPE'                    => $group_row['group_type'],
    453                                                
     453
    454454                                                'AVATAR'                                => $avatar_img,
    455455                                                'AVATAR_IMAGE'                  => $avatar_img,
     
    605605                                                                // group. This prevents existing group members being updated if no changes
    606606                                                                // were made.
    607                                                
     607
    608608                                                                $group_attributes = array();
    609                                                                 $test_variables = array('rank', 'colour', 'avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'receive_pm', 'legend', 'message_limit', 'max_recipients');
    610                                                                 foreach ($test_variables as $test)
    611                                                                 {
    612                                                                         if ($action == 'add' || (isset($submit_ary[$test]) && $group_row['group_' . $test] != $submit_ary[$test]))
     609                                                                $test_variables = array(
     610                                                                        'rank'                  => 'int',
     611                                                                        'colour'                => 'string',
     612                                                                        'avatar'                => 'string',
     613                                                                        'avatar_type'   => 'int',
     614                                                                        'avatar_width'  => 'int',
     615                                                                        'avatar_height' => 'int',
     616                                                                        'receive_pm'    => 'int',
     617                                                                        'legend'                => 'int',
     618                                                                        'message_limit' => 'int',
     619                                                                        'max_recipients'=> 'int',
     620                                                                );
     621
     622                                                                foreach ($test_variables as $test => $type)
     623                                                                {
     624                                                                        if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test]))
    613625                                                                        {
     626                                                                                settype($submit_ary[$test], $type);
    614627                                                                                $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
    615628                                                                        }
     
    676689                                                $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
    677690
    678                                                 if ($config['allow_avatar_local'] && $display_gallery)
     691                                                if ($config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery)
    679692                                                {
    680693                                                        avatar_gallery($category, $avatar_select, 4);
    681694                                                }
    682                                                
    683                                                 $avatars_enabled = ($can_upload || ($config['allow_avatar_local'] || $config['allow_avatar_remote'])) ? true : false;
     695
     696                                                $avatars_enabled = ($config['allow_avatar'] && (($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) || ($config['allow_avatar_local'] || $config['allow_avatar_remote']))) ? true : false;
    684697
    685698                                                $template->assign_vars(array(
    686699                                                        'S_EDIT'                        => true,
    687700                                                        'S_INCLUDE_SWATCH'      => true,
    688                                                         'S_CAN_UPLOAD'          => $can_upload,
    689                                                         'S_FORM_ENCTYPE'        => ($can_upload) ? ' enctype="multipart/form-data"' : '',
     701                                                        'S_FORM_ENCTYPE'        => ($config['allow_avatar'] && $can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) ? ' enctype="multipart/form-data"' : '',
    690702                                                        'S_ERROR'                       => (sizeof($error)) ? true : false,
    691703                                                        'S_SPECIAL_GROUP'       => ($group_type == GROUP_SPECIAL) ? true : false,
    692704                                                        'S_AVATARS_ENABLED'     => $avatars_enabled,
    693                                                         'S_DISPLAY_GALLERY'     => ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
     705                                                        'S_DISPLAY_GALLERY'     => ($config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery) ? true : false,
    694706                                                        'S_IN_GALLERY'          => ($config['allow_avatar_local'] && $display_gallery) ? true : false,
     707
     708                                                        'S_UPLOAD_AVATAR_FILE'  => ($config['allow_avatar'] && $config['allow_avatar_upload'] && $can_upload) ? true : false,
     709                                                        'S_UPLOAD_AVATAR_URL'   => ($config['allow_avatar'] && $config['allow_avatar_remote_upload'] && $can_upload) ? true : false,
     710                                                        'S_LINK_AVATAR'                 => ($config['allow_avatar'] && $config['allow_avatar_remote']) ? true : false,
    695711
    696712                                                        'ERROR_MSG'                             => (sizeof($error)) ? implode('<br />', $error) : '',
     
    698714                                                        'GROUP_MESSAGE_LIMIT'   => (isset($group_row['group_message_limit'])) ? $group_row['group_message_limit'] : 0,
    699715                                                        'GROUP_MAX_RECIPIENTS'  => (isset($group_row['group_max_recipients'])) ? $group_row['group_max_recipients'] : 0,
    700                                                        
     716
    701717                                                        'GROUP_DESC'                    => $group_desc_data['text'],
    702718                                                        'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'],
     
    840856
    841857                                                        'U_ACTION'                      => $this->u_action . "&amp;g=$group_id",
     858                                                        'S_UCP_ACTION'          => $this->u_action . "&amp;g=$group_id",
    842859                                                        'U_FIND_USERNAME'       => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=ucp&amp;field=usernames'),
    843860                                                ));
     
    897914                                                        {
    898915                                                                $start = 0;
    899                                
     916
    900917                                                                do
    901918                                                                {
     
    949966                                                }
    950967
     968                                                // redirect to last screen
     969                                                redirect($this->u_action . '&amp;action=list&amp;g=' . $group_id);
     970
    951971                                        break;
    952972
     
    9951015                                                }
    9961016
     1017                                                // redirect to last screen
     1018                                                redirect($this->u_action . '&amp;action=list&amp;g=' . $group_id);
     1019
    9971020                                        break;
    9981021
     
    10281051
    10291052                                                $default = request_var('default', 0);
    1030                                                
     1053
    10311054                                                if (confirm_box(true))
    10321055                                                {
  • trunk/forum/includes/ucp/ucp_main.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_main.php 9136 2008-11-30 14:36:59Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    634634        function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array())
    635635        {
    636                 global $user, $db, $template, $config, $auth, $phpbb_root_path, $phpEx;
     636                global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx;
    637637
    638638                $table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE;
    639639                $start = request_var('start', 0);
     640
     641                // Grab icons
     642                $icons = $cache->obtain_icons();
    640643
    641644                $sql_array = array(
     
    777780                        topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
    778781
    779                         $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
     782                        $view_topic_url_params = "f=$forum_id&amp;t=$topic_id";
     783                        $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
    780784
    781785                        // Send vars to template
     
    810814                                'TOPIC_FOLDER_IMG'              => $user->img($folder_img, $folder_alt),
    811815                                'TOPIC_FOLDER_IMG_SRC'  => $user->img($folder_img, $folder_alt, false, '', 'src'),
     816                                'TOPIC_FOLDER_IMG_ALT'  => $user->lang[$folder_alt],
    812817                                'TOPIC_ICON_IMG'                => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
    813818                                'TOPIC_ICON_IMG_WIDTH'  => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
     
    819824                                'S_UNREAD_TOPIC'                => $unread_topic,
    820825
    821                                 'U_NEWEST_POST'                 => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;view=unread") . '#unread',
    822                                 'U_LAST_POST'                   => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
     826                                'U_NEWEST_POST'                 => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread',
     827                                'U_LAST_POST'                   => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
    823828                                'U_VIEW_TOPIC'                  => $view_topic_url,
    824829                                'U_VIEW_FORUM'                  => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
  • trunk/forum/includes/ucp/ucp_pm.php

    r400 r702  
    22/**
    33* @package ucp
    4 * @version $Id: ucp_pm.php 8521 2008-04-21 13:20:13Z acydburn $
     4* @version $Id$
    55* @copyright (c) 2005 phpBB Group
    66* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    120120                                if (!$auth->acl_get('u_sendpm'))
    121121                                {
    122                                         trigger_error('NO_AUTH_SEND_MESSAGE');
     122                                        // trigger_error('NO_AUTH_SEND_MESSAGE');
     123                                        $template->assign_vars(array(
     124                                                'S_NO_AUTH_SEND_MESSAGE'        => true,
     125                                                'S_COMPOSE_PM_VIEW'                     => true,
     126                                        ));
     127
     128                                        $tpl_file = 'ucp_pm_viewfolder';
     129                                        break;
    123130                                }
    124131
  • trunk/forum/includes/ucp/ucp_pm_compose.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_pm_compose.php 9168 2008-12-03 16:48:06Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4747        $lastclick              = request_var('lastclick', 0);
    4848
     49        // Reply to all triggered (quote/reply)
     50        $reply_to_all   = request_var('reply_to_all', 0);
     51
    4952        // Do NOT use request_var or specialchars here
    5053        $address_list   = isset($_REQUEST['address_list']) ? $_REQUEST['address_list'] : array();
     
    8588                redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm'));
    8689        }
     90
     91        // Since viewtopic.php language entries are used in several modes,
     92        // we include the language file here
     93        $user->add_lang('viewtopic');
    8794
    8895        // Output PM_TO box if message composing
     
    311318                        if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !sizeof($address_list) && !$refresh && !$submit && !$preview)
    312319                        {
    313                                 if ($action == 'quotepost')
     320                                // Add the original author as the recipient if quoting a post or only replying and not having checked "reply to all"
     321                                if ($action == 'quotepost' || !$reply_to_all)
    314322                                {
    315323                                        $address_list = array('u' => array($post['author_id'] => 'to'));
     
    317325                                else
    318326                                {
    319                                         // We try to include every previously listed member from the TO Header
     327                                        // We try to include every previously listed member from the TO Header - Reply to all
    320328                                        $address_list = rebuild_header(array('to' => $post['to_address']));
    321329
     
    440448
    441449        // If this is a quote/reply "to all"... we may increase the max_recpients to the number of original recipients
    442         if (($action == 'reply' || $action == 'quote') && $max_recipients)
     450        if (($action == 'reply' || $action == 'quote') && $max_recipients && $reply_to_all)
    443451        {
    444452                // We try to include every previously listed member from the TO Header
     
    632640        if ($load && $drafts)
    633641        {
    634                 load_drafts(0, 0, $id);
     642                load_drafts(0, 0, $id, $action, $msg_id);
    635643        }
    636644
     
    747755        if (!sizeof($error) && $preview)
    748756        {
    749                 $user->add_lang('viewtopic');
    750757                $preview_message = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
    751758
     
    761768                        $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
    762769
    763                         $parse_sig->format_display($enable_bbcode, $enable_urls, $enable_smilies);
     770                        $parse_sig->format_display($config['allow_sig_bbcode'], $config['allow_sig_links'], $config['allow_sig_smilies']);
    764771                        $preview_signature = $parse_sig->message;
    765772                        unset($parse_sig);
     
    805812
    806813        // Decode text for message display
    807         $bbcode_uid = (($action == 'quote' || $action == 'forward') && !$preview && !$refresh && !sizeof($error)) ? $bbcode_uid : $message_parser->bbcode_uid;
     814        $bbcode_uid = (($action == 'quote' || $action == 'forward') && !$preview && !$refresh && (!sizeof($error) || (sizeof($error) && !$submit))) ? $bbcode_uid : $message_parser->bbcode_uid;
    808815
    809816        $message_parser->decode_message($bbcode_uid);
     
    851858                $forward_text[] = $user->lang['FWD_ORIGINAL_MESSAGE'];
    852859                $forward_text[] = sprintf($user->lang['FWD_SUBJECT'], censor_text($message_subject));
    853                 $forward_text[] = sprintf($user->lang['FWD_DATE'], $user->format_date($message_time));
     860                $forward_text[] = sprintf($user->lang['FWD_DATE'], $user->format_date($message_time, false, true));
    854861                $forward_text[] = sprintf($user->lang['FWD_FROM'], $quote_username_text);
    855862                $forward_text[] = sprintf($user->lang['FWD_TO'], implode(', ', $fwd_to_field['to']));
     
    10401047                'SMILIES_STATUS'                => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
    10411048                'URL_STATUS'                    => ($url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
     1049                'MAX_FONT_SIZE'                 => (int) $config['max_post_font_size'],
    10421050                'MINI_POST_IMG'                 => $user->img('icon_post_target', $user->lang['PM']),
    10431051                'ERROR'                                 => (sizeof($error)) ? implode('<br />', $error) : '',
     
    11251133
    11261134        // Build usernames to add
    1127         $usernames = (isset($_REQUEST['username'])) ? array(request_var('username', '', true)) : array();
     1135        $usernames = request_var('username', '', true);
     1136        $usernames = (empty($usernames)) ? array() : array($usernames);
     1137
    11281138        $username_list = request_var('username_list', '', true);
    11291139        if ($username_list)
     
    11391149                global $refresh, $submit, $preview;
    11401150
    1141                 $refresh = $preview = true;
     1151                $refresh = true;
    11421152                $submit = false;
     1153
     1154                // Preview is only true if there was also a message entered
     1155                if (request_var('message', ''))
     1156                {
     1157                        $preview = true;
     1158                }
    11431159        }
    11441160
  • trunk/forum/includes/ucp/ucp_pm_options.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_pm_options.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    109109                                $db->sql_query($sql);
    110110                                $msg = $user->lang['FOLDER_ADDED'];
     111                        }
     112                        else
     113                        {
     114                                $msg = $user->lang['FOLDER_NAME_EMPTY'];
    111115                        }
    112116                }
     
    634638{
    635639        global $template;
     640        global $module;
     641
     642        $exclude = array();
     643
     644        if (!$module->loaded('zebra', 'friends'))
     645        {
     646                $exclude[RULE_IS_FRIEND] = true;
     647        }
     648
     649        if (!$module->loaded('zebra', 'foes'))
     650        {
     651                $exclude[RULE_IS_FOE] = true;
     652        }
    636653
    637654        $s_rule_options = '';
     
    640657                foreach ($check_ary as $value => $_check)
    641658                {
     659                        if (isset($exclude[$value]))
     660                        {
     661                                continue;
     662                        }
    642663                        $s_rule_options .= '<option value="' . $value . '"' . (($value == $rule_option) ? ' selected="selected"' : '') . '>' . $rule_lang[$value] . '</option>';
    643664                }
  • trunk/forum/includes/ucp/ucp_pm_viewfolder.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_pm_viewfolder.php 8795 2008-08-29 11:50:01Z Kellanved $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    6666                $mark_options = array('mark_important', 'delete_marked');
    6767
     68                // Minimise edits
     69                if (!$auth->acl_get('u_pm_delete') && $key = array_search('delete_marked', $mark_options))
     70                {
     71                        unset($mark_options[$key]);
     72                }
     73
    6874                $s_mark_options = '';
    6975                foreach ($mark_options as $mark_option)
     
    116122                        if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
    117123                        {
    118                                 $recipient_list = $address = array();
    119 
    120                                 foreach ($folder_info['rowset'] as $message_id => $row)
    121                                 {
    122                                         $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
    123                                         $_save = array('u', 'g');
    124                                         foreach ($_save as $save)
    125                                         {
    126                                                 if (isset($address[$message_id][$save]) && sizeof($address[$message_id][$save]))
    127                                                 {
    128                                                         foreach (array_keys($address[$message_id][$save]) as $ug_id)
    129                                                         {
    130                                                                 $recipient_list[$save][$ug_id] = array('name' => $user->lang['NA'], 'colour' => '');
    131                                                         }
    132                                                 }
    133                                         }
    134                                 }
    135 
    136                                 $_types = array('u', 'g');
    137                                 foreach ($_types as $ug_type)
    138                                 {
    139                                         if (!empty($recipient_list[$ug_type]))
    140                                         {
    141                                                 if ($ug_type == 'u')
    142                                                 {
    143                                                         $sql = 'SELECT user_id as id, username as name, user_colour as colour
    144                                                                 FROM ' . USERS_TABLE . '
    145                                                                 WHERE ';
    146                                                 }
    147                                                 else
    148                                                 {
    149                                                         $sql = 'SELECT group_id as id, group_name as name, group_colour as colour, group_type
    150                                                                 FROM ' . GROUPS_TABLE . '
    151                                                                 WHERE ';
    152                                                 }
    153                                                 $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($recipient_list[$ug_type])));
    154 
    155                                                 $result = $db->sql_query($sql);
    156 
    157                                                 while ($row = $db->sql_fetchrow($result))
    158                                                 {
    159                                                         if ($ug_type == 'g')
    160                                                         {
    161                                                                 $row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name'];
    162                                                         }
    163 
    164                                                         $recipient_list[$ug_type][$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
    165                                                 }
    166                                                 $db->sql_freeresult($result);
    167                                         }
    168                                 }
    169 
    170                                 foreach ($address as $message_id => $adr_ary)
    171                                 {
    172                                         foreach ($adr_ary as $type => $id_ary)
    173                                         {
    174                                                 foreach ($id_ary as $ug_id => $_id)
    175                                                 {
    176                                                         if ($type == 'u')
    177                                                         {
    178                                                                 $address_list[$message_id][] = get_username_string('full', $ug_id, $recipient_list[$type][$ug_id]['name'], $recipient_list[$type][$ug_id]['colour']);
    179                                                         }
    180                                                         else
    181                                                         {
    182                                                                 $user_colour = ($recipient_list[$type][$ug_id]['colour']) ? ' style="font-weight: bold; color:#' . $recipient_list[$type][$ug_id]['colour'] . '"' : '';
    183                                                                 $link = '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $ug_id) . '"' . $user_colour . '>';
    184                                                                 $address_list[$message_id][] = $link . $recipient_list[$type][$ug_id]['name'] . (($link) ? '</a>' : '');
    185                                                         }
    186                                                 }
    187                                         }
    188                                 }
    189                                 unset($recipient_list, $address);
     124                                $address_list = get_recipient_strings($folder_info['rowset']);
    190125                        }
    191 
    192                         $data = array();
    193126
    194127                        foreach ($folder_info['pm_list'] as $message_id)
     
    268201                {
    269202                        // Build Recipient List if in outbox/sentbox
    270                         $address = array();
     203
     204                        $address_temp = $address = $data = array();
     205
    271206                        if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
    272207                        {
    273208                                foreach ($folder_info['rowset'] as $message_id => $row)
    274209                                {
    275                                         $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
     210                                        $address_temp[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
     211                                        $address[$message_id] = array();
    276212                                }
    277213                        }
     
    297233                                foreach ($_types as $ug_type)
    298234                                {
    299                                         if (isset($address[$message_id][$ug_type]) && sizeof($address[$message_id][$ug_type]))
     235                                        if (isset($address_temp[$message_id][$ug_type]) && sizeof($address_temp[$message_id][$ug_type]))
    300236                                        {
     237                                                if (!isset($address[$message_id][$ug_type]))
     238                                                {
     239                                                        $address[$message_id][$ug_type] = array();
     240                                                }
    301241                                                if ($ug_type == 'u')
    302242                                                {
     
    311251                                                                WHERE ';
    312252                                                }
    313                                                 $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($address[$message_id][$ug_type])));
     253                                                $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($address_temp[$message_id][$ug_type])));
    314254
    315255                                                $result = $db->sql_query($sql);
     
    317257                                                while ($info_row = $db->sql_fetchrow($result))
    318258                                                {
    319                                                         $address[$message_id][$ug_type][$address[$message_id][$ug_type][$info_row['id']]][] = $info_row['name'];
    320                                                         unset($address[$message_id][$ug_type][$info_row['id']]);
     259                                                        $address[$message_id][$ug_type][$address_temp[$message_id][$ug_type][$info_row['id']]][] = $info_row['name'];
     260                                                        unset($address_temp[$message_id][$ug_type][$info_row['id']]);
    321261                                                }
    322262                                                $db->sql_freeresult($result);
     
    324264                                }
    325265
     266                                // There is the chance that all recipients of the message got deleted. To avoid creating
     267                                // exports without recipients, we add a bogus "undisclosed recipient".
     268                                if (!(isset($address[$message_id]['g']) && sizeof($address[$message_id]['g'])) &&
     269                                    !(isset($address[$message_id]['u']) && sizeof($address[$message_id]['u'])))
     270                                {
     271                                        $address[$message_id]['u'] = array();
     272                                        $address[$message_id]['u']['to'] = array();
     273                                        $address[$message_id]['u']['to'][] = $user->lang['UNDISCLOSED_RECIPIENT'];
     274                                }
     275
    326276                                decode_message($message_row['message_text'], $message_row['bbcode_uid']);
    327 
     277                               
    328278                                $data[] = array(
    329279                                        'subject'       => censor_text($row['message_subject']),
    330280                                        'sender'        => $row['username'],
    331                                         'date'          => $user->format_date($row['message_time']),
     281                                        // ISO 8601 date. For PHP4 we are able to hardcode the timezone because $user->format_date() does not set it.
     282                                        'date'          => $user->format_date($row['message_time'], (PHP_VERSION >= 5) ? 'c' : "Y-m-d\TH:i:s+00:00", true),
    332283                                        'to'            => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? $address[$message_id] : '',
    333284                                        'message'       => $message_row['message_text']
     
    457408        {
    458409                $sort_by_text = array('t' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
    459                 $sort_by_sql = array('t' => 'p.msg_id', 's' => 'p.message_subject');
     410                $sort_by_sql = array('t' => 'p.message_time', 's' => array('p.message_subject', 'p.message_time'));
    460411        }
    461412        else
    462413        {
    463414                $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
    464                 $sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.msg_id', 's' => 'p.message_subject');
     415                $sort_by_sql = array('a' => array('u.username_clean', 'p.message_time'), 't' => 'p.message_time', 's' => array('p.message_subject', 'p.message_time'));
    465416        }
    466417
     
    503454                'TOTAL_MESSAGES'        => (($pm_count == 1) ? $user->lang['VIEW_PM_MESSAGE'] : sprintf($user->lang['VIEW_PM_MESSAGES'], $pm_count)),
    504455
    505                 'POST_IMG'              => (!$auth->acl_get('u_sendpm')) ? $user->img('button_topic_locked', 'PM_LOCKED') : $user->img('button_pm_new', 'POST_PM'),
    506 
    507                 'L_NO_MESSAGES' => (!$auth->acl_get('u_sendpm')) ? $user->lang['POST_PM_LOCKED'] : $user->lang['NO_MESSAGES'],
     456                'POST_IMG'              => (!$auth->acl_get('u_sendpm')) ? $user->img('button_topic_locked', 'POST_PM_LOCKED') : $user->img('button_pm_new', 'POST_NEW_PM'),
     457
     458                'S_NO_AUTH_SEND_MESSAGE'        => !$auth->acl_get('u_sendpm'),
    508459
    509460                'S_SELECT_SORT_DIR'             => $s_sort_dir,
     
    512463                'S_TOPIC_ICONS'                 => ($config['enable_pm_icons']) ? true : false,
    513464
    514                 'U_POST_NEW_TOPIC'      => ($auth->acl_get('u_sendpm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose') : '', 
     465                'U_POST_NEW_TOPIC'      => ($auth->acl_get('u_sendpm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose') : '',
    515466                'S_PM_ACTION'           => append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;mode=view&amp;action=view_folder&amp;f=$folder_id" . (($start !== 0) ? "&amp;start=$start" : '')),
    516467        ));
     
    532483
    533484                // Select the sort order
    534                 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
     485                $direction = ($sort_dir == 'd') ? 'ASC' : 'DESC';
    535486                $sql_start = max(0, $pm_count - $sql_limit - $start);
    536487        }
     
    538489        {
    539490                // Select the sort order
    540                 $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
     491                $direction = ($sort_dir == 'd') ? 'DESC' : 'ASC';
    541492                $sql_start = $start;
     493        }
     494
     495        // Sql sort order
     496        if (is_array($sort_by_sql[$sort_key]))
     497        {
     498                $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
     499        }
     500        else
     501        {
     502                $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
    542503        }
    543504
  • trunk/forum/includes/ucp/ucp_pm_viewmessage.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_pm_viewmessage.php 9174 2008-12-04 19:58:42Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3030        $folder_id      = (int) $folder_id;
    3131        $author_id      = (int) $message_row['author_id'];
     32        $view           = request_var('view', '');
    3233
    3334        // Not able to view message, it was deleted by the sender
     
    169170        $url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm');
    170171
     172        // Number of "to" recipients
     173        $num_recipients = (int) preg_match_all('/:?(u|g)_([0-9]+):?/', $message_row['to_address'], $match);
     174
    171175        $template->assign_vars(array(
    172176                'MESSAGE_AUTHOR_FULL'           => get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']),
     
    179183                'AUTHOR_AVATAR'         => (isset($user_info['avatar'])) ? $user_info['avatar'] : '',
    180184                'AUTHOR_JOINED'         => $user->format_date($user_info['user_regdate']),
    181                 'AUTHOR_POSTS'          => (!empty($user_info['user_posts'])) ? $user_info['user_posts'] : '',
     185                'AUTHOR_POSTS'          => (int) $user_info['user_posts'],
    182186                'AUTHOR_FROM'           => (!empty($user_info['user_from'])) ? $user_info['user_from'] : '',
    183187
     
    190194                'QUOTE_IMG'                     => $user->img('icon_post_quote', $user->lang['POST_QUOTE_PM']),
    191195                'REPLY_IMG'                     => $user->img('button_pm_reply', $user->lang['POST_REPLY_PM']),
     196                'REPORT_IMG'            => $user->img('icon_post_report', 'REPORT_PM'),
    192197                'EDIT_IMG'                      => $user->img('icon_post_edit', $user->lang['POST_EDIT_PM']),
    193198                'MINI_POST_IMG'         => $user->img('icon_post_target', $user->lang['PM']),
    194199
    195                 'SENT_DATE'                     => $user->format_date($message_row['message_time']),
     200                'SENT_DATE'                     => ($view == 'print') ? $user->format_date($message_row['message_time'], false, true) : $user->format_date($message_row['message_time']),
    196201                'SUBJECT'                       => $message_row['message_subject'],
    197202                'MESSAGE'                       => $message,
     
    210215                'U_DELETE'                      => ($auth->acl_get('u_pm_delete')) ? "$url&amp;mode=compose&amp;action=delete&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
    211216                'U_EMAIL'                       => $user_info['email'],
     217                'U_REPORT'                      => ($config['allow_pm_report']) ? append_sid("{$phpbb_root_path}report.$phpEx", "pm=" . $message_row['msg_id']) : '',
    212218                'U_QUOTE'                       => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&amp;mode=compose&amp;action=quote&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
    213219                'U_EDIT'                        => (($message_row['message_time'] > time() - ($config['pm_edit_time'] * 60) || !$config['pm_edit_time']) && $folder_id == PRIVMSGS_OUTBOX && $auth->acl_get('u_pm_edit')) ? "$url&amp;mode=compose&amp;action=edit&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
    214220                'U_POST_REPLY_PM'       => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&amp;mode=compose&amp;action=reply&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] : '',
     221                'U_POST_REPLY_ALL'      => ($auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&amp;mode=compose&amp;action=reply&amp;f=$folder_id&amp;reply_to_all=1&amp;p=" . $message_row['msg_id'] : '',
    215222                'U_PREVIOUS_PM'         => "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=previous",
    216223                'U_NEXT_PM'                     => "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=next",
     224
     225                'U_PM_ACTION'           => $url . '&amp;mode=compose&amp;f=' . $folder_id . '&amp;p=' . $message_row['msg_id'],
    217226
    218227                'S_HAS_ATTACHMENTS'     => (sizeof($attachments)) ? true : false,
     
    220229                'S_AUTHOR_DELETED'      => ($author_id == ANONYMOUS) ? true : false,
    221230                'S_SPECIAL_FOLDER'      => in_array($folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)),
     231                'S_PM_RECIPIENTS'       => $num_recipients,
    222232
    223233                'U_PRINT_PM'            => ($config['print_pm'] && $auth->acl_get('u_pm_printpm')) ? "$url&amp;f=$folder_id&amp;p=" . $message_row['msg_id'] . "&amp;view=print" : '',
     
    287297                if ($row)
    288298                {
    289                         $user_row['online'] = (time() - $update_time < $row['online_time'] && ($row['viewonline'])) ? true : false;
     299                        $user_row['online'] = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? true : false;
    290300                }
    291301        }
  • trunk/forum/includes/ucp/ucp_prefs.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_prefs.php 8990 2008-10-09 15:41:19Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    283283                                        'S_DISABLE_CENSORS'     => $data['wordcensor'],
    284284
    285                                         'S_CHANGE_CENSORS'              => ($auth->acl_get('u_chgcensors')) ? true : false,
     285                                        'S_CHANGE_CENSORS'              => ($auth->acl_get('u_chgcensors') && $config['allow_nocensors']) ? true : false,
    286286
    287287                                        'S_TOPIC_SORT_DAYS'             => $s_limit_topic_days,
  • trunk/forum/includes/ucp/ucp_profile.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_profile.php 8990 2008-10-09 15:41:19Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    111111                                                        'username_clean'        => ($auth->acl_get('u_chgname') && $config['allow_namechange']) ? utf8_clean_string($data['username']) : $user->data['username_clean'],
    112112                                                        'user_email'            => ($auth->acl_get('u_chgemail')) ? $data['email'] : $user->data['user_email'],
    113                                                         'user_email_hash'       => ($auth->acl_get('u_chgemail')) ? crc32($data['email']) . strlen($data['email']) : $user->data['user_email_hash'],
     113                                                        'user_email_hash'       => ($auth->acl_get('u_chgemail')) ? phpbb_email_hash($data['email']) : $user->data['user_email_hash'],
    114114                                                        'user_password'         => ($auth->acl_get('u_chgpasswd') && $data['new_password']) ? phpbb_hash($data['new_password']) : $user->data['user_password'],
    115115                                                        'user_passchg'          => ($auth->acl_get('u_chgpasswd') && $data['new_password']) ? time() : 0,
     
    134134                                                $message = 'PROFILE_UPDATED';
    135135
    136                                                 if ($config['email_enable'] && $data['email'] != $user->data['user_email'] && $user->data['user_type'] != USER_FOUNDER && ($config['require_activation'] == USER_ACTIVATION_SELF || $config['require_activation'] == USER_ACTIVATION_ADMIN))
     136                                                if ($auth->acl_get('u_chgemail') && $config['email_enable'] && $data['email'] != $user->data['user_email'] && $user->data['user_type'] != USER_FOUNDER && ($config['require_activation'] == USER_ACTIVATION_SELF || $config['require_activation'] == USER_ACTIVATION_ADMIN))
    137137                                                {
    138138                                                        $message = ($config['require_activation'] == USER_ACTIVATION_SELF) ? 'ACCOUNT_EMAIL_CHANGED' : 'ACCOUNT_EMAIL_CHANGED_ADMIN';
     
    350350                                                $data['notify'] = $user->data['user_notify_type'];
    351351
    352                                                 if (!$config['jab_enable'] || !$data['jabber'] || !@extension_loaded('xml'))
     352                                                if ($data['notify'] == NOTIFY_IM && (!$config['jab_enable'] || !$data['jabber'] || !@extension_loaded('xml')))
    353353                                                {
    354354                                                        // User has not filled in a jabber address (Or one of the modules is disabled or jabber is disabled)
    355355                                                        // Disable notify by Jabber now for this user.
    356                                                         $data['notify'] = NOTIFY_BOTH;
     356                                                        $data['notify'] = NOTIFY_EMAIL;
    357357                                                }
    358358
     
    381381
    382382                                                // Update Custom Fields
    383                                                 if (sizeof($cp_data))
    384                                                 {
    385                                                         $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
    386                                                                 SET ' . $db->sql_build_array('UPDATE', $cp_data) . '
    387                                                                 WHERE user_id = ' . $user->data['user_id'];
    388                                                         $db->sql_query($sql);
    389 
    390                                                         if (!$db->sql_affectedrows())
    391                                                         {
    392                                                                 $cp_data['user_id'] = (int) $user->data['user_id'];
    393 
    394                                                                 $db->sql_return_on_error(true);
    395 
    396                                                                 $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data);
    397                                                                 $db->sql_query($sql);
    398 
    399                                                                 $db->sql_return_on_error(false);
    400                                                         }
    401                                                 }
     383                                                $cp->update_profile_field_data($user->data['user_id'], $cp_data);
    402384
    403385                                                meta_refresh(3, $this->u_action);
     
    475457                                include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
    476458
    477                                 $enable_bbcode  = ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', !$user->optionget('bbcode'))) ? false : true) : false;
    478                                 $enable_smilies = ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', !$user->optionget('smilies'))) ? false : true) : false;
    479                                 $enable_urls    = ($config['allow_sig_links']) ? ((request_var('disable_magic_url', false)) ? false : true) : false;
     459                                $enable_bbcode  = ($config['allow_sig_bbcode']) ? (bool) $user->optionget('sig_bbcode') : false;
     460                                $enable_smilies = ($config['allow_sig_smilies']) ? (bool) $user->optionget('sig_smilies') : false;
     461                                $enable_urls    = ($config['allow_sig_links']) ? (bool) $user->optionget('sig_links') : false;
    480462
    481463                                $signature              = utf8_normalize_nfc(request_var('signature', (string) $user->data['user_sig'], true));
     
    486468                                {
    487469                                        include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
     470
     471                                        $enable_bbcode  = ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', false)) ? false : true) : false;
     472                                        $enable_smilies = ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', false)) ? false : true) : false;
     473                                        $enable_urls    = ($config['allow_sig_links']) ? ((request_var('disable_magic_url', false)) ? false : true) : false;
    488474
    489475                                        if (!sizeof($error))
     
    506492                                                if (!sizeof($error) && $submit)
    507493                                                {
     494                                                        $user->optionset('sig_bbcode', $enable_bbcode);
     495                                                        $user->optionset('sig_smilies', $enable_smilies);
     496                                                        $user->optionset('sig_links', $enable_urls);
     497
    508498                                                        $sql_ary = array(
    509499                                                                'user_sig'                                      => (string) $message_parser->message,
     500                                                                'user_options'                          => $user->data['user_options'],
    510501                                                                'user_sig_bbcode_uid'           => (string) $message_parser->bbcode_uid,
    511502                                                                'user_sig_bbcode_bitfield'      => $message_parser->bbcode_bitfield
     
    550541                                        'FLASH_STATUS'                  => ($config['allow_sig_flash']) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
    551542                                        'URL_STATUS'                    => ($config['allow_sig_links']) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
     543                                        'MAX_FONT_SIZE'                 => (int) $config['max_sig_font_size'],
    552544
    553545                                        'L_SIGNATURE_EXPLAIN'   => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']),
     
    573565                                $category = basename(request_var('category', ''));
    574566
    575                                 $can_upload = ($config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false;
     567                                $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false;
    576568
    577569                                add_form_key('ucp_avatar');
     
    596588                                }
    597589
     590                                if (!$config['allow_avatar'] && $user->data['user_avatar_type'])
     591                                {
     592                                        $error[] = $user->lang['AVATAR_NOT_ALLOWED'];
     593                                }
     594                                else if ((($user->data['user_avatar_type'] == AVATAR_UPLOAD) && !$config['allow_avatar_upload']) ||
     595                                 (($user->data['user_avatar_type'] == AVATAR_REMOTE) && !$config['allow_avatar_remote']) ||
     596                                 (($user->data['user_avatar_type'] == AVATAR_GALLERY) && !$config['allow_avatar_local']))
     597                                {
     598                                        $error[] = $user->lang['AVATAR_TYPE_NOT_ALLOWED'];
     599                                }
     600
    598601                                $template->assign_vars(array(
    599602                                        'ERROR'                 => (sizeof($error)) ? implode('<br />', $error) : '',
    600                                         'AVATAR'                => get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height']),
     603                                        'AVATAR'                => get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height'], 'USER_AVATAR', true),
    601604                                        'AVATAR_SIZE'   => $config['avatar_filesize'],
    602605
    603606                                        'U_GALLERY'             => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&amp;mode=avatar&amp;display_gallery=1'),
    604607
    605                                         'S_FORM_ENCTYPE'        => ($can_upload) ? ' enctype="multipart/form-data"' : '',
     608                                        'S_FORM_ENCTYPE'        => ($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) ? ' enctype="multipart/form-data"' : '',
    606609
    607610                                        'L_AVATAR_EXPLAIN'      => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024),
    608611                                ));
    609612
    610                                 if ($display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local'])
     613                                if ($config['allow_avatar'] && $display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local'])
    611614                                {
    612615                                        avatar_gallery($category, $avatar_select, 4);
    613616                                }
    614                                 else
    615                                 {
    616                                         $avatars_enabled = ($can_upload || ($auth->acl_get('u_chgavatar') && ($config['allow_avatar_local'] || $config['allow_avatar_remote']))) ? true : false;
     617                                else if ($config['allow_avatar'])
     618                                {
     619                                        $avatars_enabled = (($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) || ($auth->acl_get('u_chgavatar') && ($config['allow_avatar_local'] || $config['allow_avatar_remote']))) ? true : false;
    617620
    618621                                        $template->assign_vars(array(
     
    621624
    622625                                                'S_AVATARS_ENABLED'             => $avatars_enabled,
    623                                                 'S_UPLOAD_AVATAR_FILE'  => $can_upload,
    624                                                 'S_UPLOAD_AVATAR_URL'   => $can_upload,
     626                                                'S_UPLOAD_AVATAR_FILE'  => ($can_upload && $config['allow_avatar_upload']) ? true : false,
     627                                                'S_UPLOAD_AVATAR_URL'   => ($can_upload && $config['allow_avatar_remote_upload']) ? true : false,
    625628                                                'S_LINK_AVATAR'                 => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_remote']) ? true : false,
    626629                                                'S_DISPLAY_GALLERY'             => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) ? true : false)
  • trunk/forum/includes/ucp/ucp_register.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_register.php 8782 2008-08-23 17:20:55Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3838                include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
    3939
    40                 $confirm_id             = request_var('confirm_id', '');
    4140                $coppa                  = (isset($_REQUEST['coppa'])) ? ((!empty($_REQUEST['coppa'])) ? 1 : 0) : false;
    4241                $agreed                 = (!empty($_POST['agreed'])) ? 1 : 0;
     
    5453                }
    5554
    56 
    5755                if ($change_lang || $user_lang != $config['default_lang'])
    5856                {
     
    6967                                }
    7068
    71                                 $user->lang_name = $lang = $use_lang;
     69                                $user->lang_name = $user_lang = $use_lang;
    7270                                $user->lang = array();
     71                                $user->data['user_lang'] = $user->lang_name;
    7372                                $user->add_lang(array('common', 'ucp'));
    7473                        }
     
    8079                }
    8180
     81
    8282                $cp = new custom_profile();
    8383
    8484                $error = $cp_data = $cp_error = array();
    85 
    8685
    8786                if (!$agreed || ($coppa === false && $config['coppa_enable']) || ($coppa && !$config['coppa_enable']))
     
    9089                        $add_coppa = ($coppa !== false) ? '&amp;coppa=' . $coppa : '';
    9190
    92                         $s_hidden_fields = ($confirm_id) ? array('confirm_id' => $confirm_id) : array();
     91                        $s_hidden_fields = array(
     92                                'change_lang'   => $change_lang,
     93                        );
    9394
    9495                        // If we change the language, we want to pass on some more possible parameter.
     
    100101                                        'email'                         => strtolower(request_var('email', '')),
    101102                                        'email_confirm'         => strtolower(request_var('email_confirm', '')),
    102                                         'confirm_code'          => request_var('confirm_code', ''),
    103                                         'confirm_id'            => request_var('confirm_id', ''),
    104103                                        'lang'                          => $user->lang_name,
    105104                                        'tz'                            => request_var('tz', (float) $config['board_timezone']),
    106105                                ));
    107                         }
     106
     107                        }
     108
     109                        // Checking amount of available languages
     110                        $sql = 'SELECT lang_id
     111                                FROM ' . LANG_TABLE;
     112                        $result = $db->sql_query($sql);
     113
     114                        $lang_row = array();
     115                        while ($row = $db->sql_fetchrow($result))
     116                        {
     117                                $lang_row[] = $row;
     118                        }
     119                        $db->sql_freeresult($result);
    108120
    109121                        if ($coppa === false && $config['coppa_enable'])
     
    114126
    115127                                $template->assign_vars(array(
     128                                        'S_LANG_OPTIONS'        => (sizeof($lang_row) > 1) ? language_select($user_lang) : '',
    116129                                        'L_COPPA_NO'            => sprintf($user->lang['UCP_COPPA_BEFORE'], $coppa_birthday),
    117130                                        'L_COPPA_YES'           => sprintf($user->lang['UCP_COPPA_ON_AFTER'], $coppa_birthday),
     
    128141                        {
    129142                                $template->assign_vars(array(
     143                                        'S_LANG_OPTIONS'        => (sizeof($lang_row) > 1) ? language_select($user_lang) : '',
    130144                                        'L_TERMS_OF_USE'        => sprintf($user->lang['TERMS_OF_USE_CONTENT'], $config['sitename'], generate_board_url()),
    131145
     
    137151                                );
    138152                        }
     153                        unset($lang_row);
    139154
    140155                        $this->tpl_name = 'ucp_agreement';
    141156                        return;
    142157                }
    143 
     158               
     159               
     160                // The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
     161                if ($config['enable_confirm'])
     162                {
     163                        include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
     164                        $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
     165                        $captcha->init(CONFIRM_REG);
     166                }
    144167
    145168                // Try to manually determine the timezone and adjust the dst if the server date/time complies with the default setting +/- 1
     
    168191                        'email'                         => strtolower(request_var('email', '')),
    169192                        'email_confirm'         => strtolower(request_var('email_confirm', '')),
    170                         'confirm_code'          => request_var('confirm_code', ''),
    171193                        'lang'                          => basename(request_var('lang', $user->lang_name)),
    172194                        'tz'                            => request_var('tz', (float) $timezone),
     
    188210                                        array('email')),
    189211                                'email_confirm'         => array('string', false, 6, 60),
    190                                 'confirm_code'          => array('string', !$config['enable_confirm'], 5, 8),
    191212                                'tz'                            => array('num', false, -14, 14),
    192213                                'lang'                          => array('match', false, '#^[a-z_\-]{2,}$#i'),
    193214                        ));
     215
    194216                        if (!check_form_key('ucp_register'))
    195217                        {
    196218                                $error[] = $user->lang['FORM_INVALID'];
    197219                        }
     220
    198221                        // Replace "error" strings with their real, localised form
    199222                        $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
    200223
     224                        if ($config['enable_confirm'])
     225                        {
     226                                $vc_response = $captcha->validate($data);
     227                                if ($vc_response !== false)
     228                                {
     229                                        $error[] = $vc_response;
     230                                }
     231
     232                                if ($config['max_reg_attempts'] && $captcha->get_attempt_count() > $config['max_reg_attempts'])
     233                                {
     234                                        $error[] = $user->lang['TOO_MANY_REGISTERS'];
     235                                }
     236                        }
     237
    201238                        // DNSBL check
    202239                        if ($config['check_dnsbl'])
     
    210247                        // validate custom profile fields
    211248                        $cp->submit_cp_field('register', $user->get_iso_lang_id(), $cp_data, $error);
    212 
    213                         // Visual Confirmation handling
    214                         $wrong_confirm = false;
    215                         if ($config['enable_confirm'])
    216                         {
    217                                 if (!$confirm_id)
    218                                 {
    219                                         $error[] = $user->lang['CONFIRM_CODE_WRONG'];
    220                                         $wrong_confirm = true;
    221                                 }
    222                                 else
    223                                 {
    224                                         $sql = 'SELECT code
    225                                                 FROM ' . CONFIRM_TABLE . "
    226                                                 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
    227                                                         AND session_id = '" . $db->sql_escape($user->session_id) . "'
    228                                                         AND confirm_type = " . CONFIRM_REG;
    229                                         $result = $db->sql_query($sql);
    230                                         $row = $db->sql_fetchrow($result);
    231                                         $db->sql_freeresult($result);
    232 
    233                                         if ($row)
    234                                         {
    235                                                 if (strcasecmp($row['code'], $data['confirm_code']) === 0)
    236                                                 {
    237                                                         $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
    238                                                                 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
    239                                                                         AND session_id = '" . $db->sql_escape($user->session_id) . "'
    240                                                                         AND confirm_type = " . CONFIRM_REG;
    241                                                         $db->sql_query($sql);
    242                                                 }
    243                                                 else
    244                                                 {
    245                                                         $error[] = $user->lang['CONFIRM_CODE_WRONG'];
    246                                                         $wrong_confirm = true;
    247                                                 }
    248                                         }
    249                                         else
    250                                         {
    251                                                 $error[] = $user->lang['CONFIRM_CODE_WRONG'];
    252                                                 $wrong_confirm = true;
    253                                         }
    254                                 }
    255                         }
    256249
    257250                        if (!sizeof($error))
     
    327320                                );
    328321
     322                                if ($config['new_member_post_limit'])
     323                                {
     324                                        $user_row['user_new'] = 1;
     325                                }
     326
    329327                                // Register user...
    330328                                $user_id = user_add($user_row, $cp_data);
     
    334332                                {
    335333                                        trigger_error('NO_USER', E_USER_ERROR);
     334                                }
     335
     336                                // Okay, captcha, your job is done.
     337                                if ($config['enable_confirm'] && isset($captcha))
     338                                {
     339                                        $captcha->reset();
    336340                                }
    337341
     
    441445                        $s_hidden_fields['coppa'] = $coppa;
    442446                }
     447
     448                if ($config['enable_confirm'])
     449                {
     450                        $s_hidden_fields = array_merge($s_hidden_fields, $captcha->get_hidden_fields());
     451                }
    443452                $s_hidden_fields = build_hidden_fields($s_hidden_fields);
    444 
    445453                $confirm_image = '';
    446454
    447455                // Visual Confirmation - Show images
    448 
    449456                if ($config['enable_confirm'])
    450457                {
    451                         if ($change_lang)
    452                         {
    453                                 $str = '&amp;change_lang=' . $change_lang;
    454                                 $sql = 'SELECT code
    455                                                 FROM ' . CONFIRM_TABLE . "
    456                                                 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
    457                                                         AND session_id = '" . $db->sql_escape($user->session_id) . "'
    458                                                         AND confirm_type = " . CONFIRM_REG;
    459                                 $result = $db->sql_query($sql);
    460                                 if (!$row = $db->sql_fetchrow($result))
    461                                 {
    462                                         $confirm_id = '';
    463                                 }
    464                                 $db->sql_freeresult($result);
    465                         }
    466                         else
    467                         {
    468                                 $str = '';
    469                         }
    470                         if (!$change_lang || !$confirm_id)
    471                         {
    472                                 $user->confirm_gc(CONFIRM_REG);
    473 
    474                                 $sql = 'SELECT COUNT(session_id) AS attempts
    475                                         FROM ' . CONFIRM_TABLE . "
    476                                         WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
    477                                                 AND confirm_type = " . CONFIRM_REG;
    478                                 $result = $db->sql_query($sql);
    479                                 $attempts = (int) $db->sql_fetchfield('attempts');
    480                                 $db->sql_freeresult($result);
    481 
    482                                 if ($config['max_reg_attempts'] && $attempts > $config['max_reg_attempts'])
    483                                 {
    484                                         trigger_error('TOO_MANY_REGISTERS');
    485                                 }
    486 
    487                                 $code = gen_rand_string(mt_rand(5, 8));
    488                                 $confirm_id = md5(unique_id($user->ip));
    489                                 $seed = hexdec(substr(unique_id(), 4, 10));
    490 
    491                                 // compute $seed % 0x7fffffff
    492                                 $seed -= 0x7fffffff * floor($seed / 0x7fffffff);
    493 
    494                                 $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
    495                                         'confirm_id'    => (string) $confirm_id,
    496                                         'session_id'    => (string) $user->session_id,
    497                                         'confirm_type'  => (int) CONFIRM_REG,
    498                                         'code'                  => (string) $code,
    499                                         'seed'                  => (int) $seed)
    500                                 );
    501                                 $db->sql_query($sql);
    502                         }
    503                         $confirm_image = '<img src="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=confirm&amp;id=' . $confirm_id . '&amp;type=' . CONFIRM_REG . $str) . '" alt="" title="" />';
    504                         $s_hidden_fields .= '<input type="hidden" name="confirm_id" value="' . $confirm_id . '" />';
     458                        $template->assign_vars(array(
     459                                'CAPTCHA_TEMPLATE'              => $captcha->get_template(),
     460                        ));
    505461                }
    506462
     
    525481                        'EMAIL'                         => $data['email'],
    526482                        'EMAIL_CONFIRM'         => $data['email_confirm'],
    527                         'CONFIRM_IMG'           => $confirm_image,
    528 
    529                         'L_CONFIRM_EXPLAIN'                     => sprintf($user->lang['CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'),
     483
    530484                        'L_REG_COND'                            => $l_reg_cond,
    531485                        'L_USERNAME_EXPLAIN'            => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']),
     
    534488                        'S_LANG_OPTIONS'        => language_select($data['lang']),
    535489                        'S_TZ_OPTIONS'          => tz_select($data['tz']),
    536                         'S_CONFIRM_CODE'        => ($config['enable_confirm']) ? true : false,
     490                        'S_CONFIRM_REFRESH'     => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false,
     491                        'S_REGISTRATION'        => true,
    537492                        'S_COPPA'                       => $coppa,
    538493                        'S_HIDDEN_FIELDS'       => $s_hidden_fields,
    539494                        'S_UCP_ACTION'          => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
    540                         )
    541                 );
     495                ));
    542496
    543497                //
  • trunk/forum/includes/ucp/ucp_remind.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_remind.php 8977 2008-10-06 14:04:33Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3939                        $sql = 'SELECT user_id, username, user_permissions, user_email, user_jabber, user_notify_type, user_type, user_lang, user_inactive_reason
    4040                                FROM ' . USERS_TABLE . "
    41                                 WHERE user_email = '" . $db->sql_escape($email) . "'
     41                                WHERE user_email_hash = '" . $db->sql_escape(phpbb_email_hash($email)) . "'
    4242                                        AND username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
    4343                        $result = $db->sql_query($sql);
  • trunk/forum/includes/ucp/ucp_resend.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_resend.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4646                        $sql = 'SELECT user_id, group_id, username, user_email, user_type, user_lang, user_actkey, user_inactive_reason
    4747                                FROM ' . USERS_TABLE . "
    48                                 WHERE user_email = '" . $db->sql_escape($email) . "'
     48                                WHERE user_email_hash = '" . $db->sql_escape(phpbb_email_hash($email)) . "'
    4949                                        AND username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
    5050                        $result = $db->sql_query($sql);
     
    134134                                        $messenger->im($row['user_jabber'], $row['username']);
    135135
     136                                        $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
     137                                        $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
     138                                        $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
     139                                        $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
     140
    136141                                        $messenger->assign_vars(array(
    137142                                                'USERNAME'                      => htmlspecialchars_decode($user_row['username']),
     
    147152                        meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
    148153
    149                         $message = ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? $user->lang['ACIVATION_EMAIL_SENT_ADMIN'] : $user->lang['ACTIVATION_EMAIL_SENT'];
     154                        $message = ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? $user->lang['ACTIVATION_EMAIL_SENT_ADMIN'] : $user->lang['ACTIVATION_EMAIL_SENT'];
    150155                        $message .= '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
    151156                        trigger_error($message);
  • trunk/forum/includes/ucp/ucp_zebra.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_zebra.php 8479 2008-03-29 00:22:48Z naderman $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    5353                                if (confirm_box(true))
    5454                                {
     55                                        // Remove users
     56                                        if (!empty($data['usernames']))
     57                                        {
     58                                                $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
     59                                                        WHERE user_id = ' . $user->data['user_id'] . '
     60                                                                AND ' . $db->sql_in_set('zebra_id', $data['usernames']);
     61                                                $db->sql_query($sql);
     62
     63                                                $updated = true;
     64                                        }
     65
     66                                        // Add users
    5567                                        if ($data['add'])
    5668                                        {
     
    125137                                                                        $user_id_ary[] = $row['user_id'];
    126138                                                                }
     139                                                                else if ($row['user_id'] != ANONYMOUS)
     140                                                                {
     141                                                                        $error[] = $user->lang['NOT_ADDED_' . $l_mode . '_BOTS'];
     142                                                                }
    127143                                                                else
    128144                                                                {
     
    183199                                                        }
    184200                                                }
    185                                         }
    186                                         else if (sizeof($data['usernames']))
    187                                         {
    188                                                 // Force integer values
    189                                                 $data['usernames'] = array_map('intval', $data['usernames']);
    190 
    191                                                 $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
    192                                                         WHERE user_id = ' . $user->data['user_id'] . '
    193                                                                 AND ' . $db->sql_in_set('zebra_id', $data['usernames']);
    194                                                 $db->sql_query($sql);
    195 
    196                                                 $updated = true;
    197201                                        }
    198202
  • trunk/forum/includes/utf/utf_tools.php

    r400 r702  
    33*
    44* @package utf
    5 * @version $Id: utf_tools.php 8510 2008-04-20 05:16:42Z davidmj $
     5* @version $Id$
    66* @copyright (c) 2006 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    7171                $len = strlen($str);
    7272                $ret = '';
    73        
     73
    7474                while ($pos < $len)
    7575                {
     
    253253                {
    254254                        $ar     = explode($needle, $str);
    255                        
     255
    256256                        if (sizeof($ar) > 1)
    257257                        {
     
    528528                }
    529529                else
    530                 {       
     530                {
    531531                        // offset == 0; just anchor the pattern
    532532                        $op = '^';
     
    561561                                $lx = (int) ($length / 65535);
    562562                                $ly = $length % 65535;
    563                                
     563
    564564                                // negative length requires a captured group
    565565                                // of length characters
     
    633633                return array($str);
    634634        }
    635        
     635
    636636        preg_match_all('/.{' . $split_len . '}|[^\x00]{1,' . $split_len . '}$/us', $str, $ar);
    637637        return $ar[0];
     
    19181918}
    19191919
     1920/**
     1921* UTF8-safe basename() function
     1922*
     1923* basename() has some limitations and is dependent on the locale setting
     1924* according to the PHP manual. Therefore we provide our own locale independant
     1925* basename function.
     1926*
     1927* @param string $filename The filename basename() should be applied to
     1928* @return string The basenamed filename
     1929*/
     1930function utf8_basename($filename)
     1931{
     1932        // We always check for forward slash AND backward slash
     1933        // because they could be mixed or "sneaked" in. ;)
     1934        // You know, never trust user input...
     1935        if (strpos($filename, '/') !== false)
     1936        {
     1937                $filename = utf8_substr($filename, utf8_strrpos($filename, '/') + 1);
     1938        }
     1939
     1940        if (strpos($filename, '\\') !== false)
     1941        {
     1942                $filename = utf8_substr($filename, utf8_strrpos($filename, '\\') + 1);
     1943        }
     1944
     1945        return $filename;
     1946}
     1947
     1948/**
     1949* UTF8-safe str_replace() function
     1950*
     1951* @param string $search The value to search for
     1952* @param string $replace The replacement string
     1953* @param string $subject The target string
     1954* @return string The resultant string
     1955*/
     1956function utf8_str_replace($search, $replace, $subject)
     1957{
     1958        if (!is_array($search))
     1959        {
     1960                $search = array($search);
     1961                if (is_array($replace))
     1962                {
     1963                        $replace = (string) $replace;
     1964                        trigger_error('Array to string conversion', E_USER_NOTICE);
     1965                }
     1966        }
     1967
     1968        $length = sizeof($search);
     1969
     1970        if (!is_array($replace))
     1971        {
     1972                $replace = array_fill(0, $length, $replace);
     1973        }
     1974        else
     1975        {
     1976                $replace = array_pad($replace, $length, '');
     1977        }
     1978
     1979        for ($i = 0; $i < $length; $i++)
     1980        {
     1981                $search_length = utf8_strlen($search[$i]);
     1982                $replace_length = utf8_strlen($replace[$i]);
     1983
     1984                $offset = 0;
     1985                while (($start = utf8_strpos($subject, $search[$i], $offset)) !== false)
     1986                {
     1987                        $subject = utf8_substr($subject, 0, $start) . $replace[$i] . utf8_substr($subject, $start + $search_length);
     1988                        $offset = $start + $replace_length;
     1989                }
     1990        }
     1991
     1992        return $subject;
     1993}
     1994
    19201995?>
Note: See TracChangeset for help on using the changeset viewer.