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

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/functions_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?>
Note: See TracChangeset for help on using the changeset viewer.