Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

content_visibility.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 21.00 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb;
 015   
 016  /**
 017  * phpbb_visibility
 018  * Handle fetching and setting the visibility for topics and posts
 019  */
 020  class content_visibility
 021  {
 022      /**
 023      * Database object
 024      * @var \phpbb\db\driver\driver_interface
 025      */
 026      protected $db;
 027   
 028      /**
 029      * User object
 030      * @var \phpbb\user
 031      */
 032      protected $user;
 033   
 034      /**
 035      * Auth object
 036      * @var \phpbb\auth\auth
 037      */
 038      protected $auth;
 039   
 040      /**
 041      * config object
 042      * @var \phpbb\config\config
 043      */
 044      protected $config;
 045   
 046      /**
 047      * phpBB root path
 048      * @var string
 049      */
 050      protected $phpbb_root_path;
 051   
 052      /**
 053      * PHP Extension
 054      * @var string
 055      */
 056      protected $php_ext;
 057   
 058      /**
 059      * Constructor
 060      *
 061      * @param    \phpbb\auth\auth        $auth    Auth object
 062      * @param    \phpbb\config\config    $config    Config object
 063      * @param    \phpbb\db\driver\driver_interface    $db        Database object
 064      * @param    \phpbb\user        $user            User object
 065      * @param    string        $phpbb_root_path    Root path
 066      * @param    string        $php_ext            PHP Extension
 067      * @param    string        $forums_table        Forums table name
 068      * @param    string        $posts_table        Posts table name
 069      * @param    string        $topics_table        Topics table name
 070      * @param    string        $users_table        Users table name
 071      */
 072      public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path, $php_ext, $forums_table, $posts_table, $topics_table, $users_table)
 073      {
 074          $this->auth = $auth;
 075          $this->config = $config;
 076          $this->db = $db;
 077          $this->user = $user;
 078          $this->phpbb_root_path = $phpbb_root_path;
 079          $this->php_ext = $php_ext;
 080          $this->forums_table = $forums_table;
 081          $this->posts_table = $posts_table;
 082          $this->topics_table = $topics_table;
 083          $this->users_table = $users_table;
 084      }
 085   
 086      /**
 087      * Can the current logged-in user soft-delete posts?
 088      *
 089      * @param $forum_id        int        Forum ID whose permissions to check
 090      * @param $poster_id        int        Poster ID of the post in question
 091      * @param $post_locked    bool    Is the post locked?
 092      * @return bool
 093      */
 094      public function can_soft_delete($forum_id, $poster_id, $post_locked)
 095      {
 096          if ($this->auth->acl_get('m_softdelete', $forum_id))
 097          {
 098              return true;
 099          }
 100          else if ($this->auth->acl_get('f_softdelete', $forum_id) && $poster_id == $this->user->data['user_id'] && !$post_locked)
 101          {
 102              return true;
 103          }
 104   
 105          return false;
 106      }
 107   
 108      /**
 109      * Get the topics post count or the forums post/topic count based on permissions
 110      *
 111      * @param $mode            string    One of topic_posts, forum_posts or forum_topics
 112      * @param $data            array    Array with the topic/forum data to calculate from
 113      * @param $forum_id        int        The forum id is used for permission checks
 114      * @return int    Number of posts/topics the user can see in the topic/forum
 115      */
 116      public function get_count($mode, $data, $forum_id)
 117      {
 118          if (!$this->auth->acl_get('m_approve', $forum_id))
 119          {
 120              return (int) $data[$mode . '_approved'];
 121          }
 122   
 123          return (int) $data[$mode . '_approved'] + (int) $data[$mode . '_unapproved'] + (int) $data[$mode . '_softdeleted'];
 124      }
 125   
 126      /**
 127      * Create topic/post visibility SQL for a given forum ID
 128      *
 129      * Note: Read permissions are not checked.
 130      *
 131      * @param $mode            string    Either "topic" or "post"
 132      * @param $forum_id        int        The forum id is used for permission checks
 133      * @param $table_alias    string    Table alias to prefix in SQL queries
 134      * @return string    The appropriate combination SQL logic for topic/post_visibility
 135      */
 136      public function get_visibility_sql($mode, $forum_id, $table_alias = '')
 137      {
 138          if ($this->auth->acl_get('m_approve', $forum_id))
 139          {
 140              return '1 = 1';
 141          }
 142   
 143          return $table_alias . $mode . '_visibility = ' . ITEM_APPROVED;
 144      }
 145   
 146      /**
 147      * Create topic/post visibility SQL for a set of forums
 148      *
 149      * Note: Read permissions are not checked. Forums without read permissions
 150      *        should not be in $forum_ids
 151      *
 152      * @param $mode            string    Either "topic" or "post"
 153      * @param $forum_ids        array    Array of forum ids which the posts/topics are limited to
 154      * @param $table_alias    string    Table alias to prefix in SQL queries
 155      * @return string    The appropriate combination SQL logic for topic/post_visibility
 156      */
 157      public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_alias = '')
 158      {
 159          $where_sql = '(';
 160   
 161          $approve_forums = array_intersect($forum_ids, array_keys($this->auth->acl_getf('m_approve', true)));
 162   
 163          if (sizeof($approve_forums))
 164          {
 165              // Remove moderator forums from the rest
 166              $forum_ids = array_diff($forum_ids, $approve_forums);
 167   
 168              if (!sizeof($forum_ids))
 169              {
 170                  // The user can see all posts/topics in all specified forums
 171                  return $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums);
 172              }
 173              else
 174              {
 175                  // Moderator can view all posts/topics in some forums
 176                  $where_sql .= $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ' OR ';
 177              }
 178          }
 179          else
 180          {
 181              // The user is just a normal user
 182              return $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . '
 183                  AND ' . $this->db->sql_in_set($table_alias . 'forum_id', $forum_ids, false, true);
 184          }
 185   
 186          $where_sql .= '(' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . '
 187              AND ' . $this->db->sql_in_set($table_alias . 'forum_id', $forum_ids) . '))';
 188   
 189          return $where_sql;
 190      }
 191   
 192      /**
 193      * Create topic/post visibility SQL for all forums on the board
 194      *
 195      * Note: Read permissions are not checked. Forums without read permissions
 196      *        should be in $exclude_forum_ids
 197      *
 198      * @param $mode                string    Either "topic" or "post"
 199      * @param $exclude_forum_ids    array    Array of forum ids which are excluded
 200      * @param $table_alias        string    Table alias to prefix in SQL queries
 201      * @return string    The appropriate combination SQL logic for topic/post_visibility
 202      */
 203      public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $table_alias = '')
 204      {
 205          $where_sqls = array();
 206   
 207          $approve_forums = array_diff(array_keys($this->auth->acl_getf('m_approve', true)), $exclude_forum_ids);
 208   
 209          if (sizeof($exclude_forum_ids))
 210          {
 211              $where_sqls[] = '(' . $this->db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true) . '
 212                  AND ' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ')';
 213          }
 214          else
 215          {
 216              $where_sqls[] = $table_alias . $mode . '_visibility = ' . ITEM_APPROVED;
 217          }
 218   
 219          if (sizeof($approve_forums))
 220          {
 221              $where_sqls[] = $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums);
 222              return '(' . implode(' OR ', $where_sqls) . ')';
 223          }
 224   
 225          // There is only one element, so we just return that one
 226          return $where_sqls[0];
 227      }
 228   
 229      /**
 230      * Change visibility status of one post or all posts of a topic
 231      *
 232      * @param $visibility    int        Element of {ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE}
 233      * @param $post_id        mixed    Post ID or array of post IDs to act on,
 234      *                                if it is empty, all posts of topic_id will be modified
 235      * @param $topic_id        int        Topic where $post_id is found
 236      * @param $forum_id        int        Forum where $topic_id is found
 237      * @param $user_id        int        User performing the action
 238      * @param $time            int        Timestamp when the action is performed
 239      * @param $reason        string    Reason why the visibility was changed.
 240      * @param $is_starter    bool    Is this the first post of the topic changed?
 241      * @param $is_latest        bool    Is this the last post of the topic changed?
 242      * @param $limit_visibility    mixed    Limit updating per topic_id to a certain visibility
 243      * @param $limit_delete_time    mixed    Limit updating per topic_id to a certain deletion time
 244      * @return array        Changed post data, empty array if an error occurred.
 245      */
 246      public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $limit_visibility = false, $limit_delete_time = false)
 247      {
 248          if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE)))
 249          {
 250              return array();
 251          }
 252   
 253          if ($post_id)
 254          {
 255              if (is_array($post_id))
 256              {
 257                  $where_sql = $this->db->sql_in_set('post_id', array_map('intval', $post_id));
 258              }
 259              else
 260              {
 261                  $where_sql = 'post_id = ' . (int) $post_id;
 262              }
 263              $where_sql .= ' AND topic_id = ' . (int) $topic_id;
 264          }
 265          else
 266          {
 267              $where_sql = 'topic_id = ' . (int) $topic_id;
 268   
 269              // Limit the posts to a certain visibility and deletion time
 270              // This allows us to only restore posts, that were approved
 271              // when the topic got soft deleted. So previous soft deleted
 272              // and unapproved posts are still soft deleted/unapproved
 273              if ($limit_visibility !== false)
 274              {
 275                  $where_sql .= ' AND post_visibility = ' . (int) $limit_visibility;
 276              }
 277   
 278              if ($limit_delete_time !== false)
 279              {
 280                  $where_sql .= ' AND post_delete_time = ' . (int) $limit_delete_time;
 281              }
 282          }
 283   
 284          $sql = 'SELECT poster_id, post_id, post_postcount, post_visibility
 285              FROM ' . $this->posts_table . '
 286              WHERE ' . $where_sql;
 287          $result = $this->db->sql_query($sql);
 288   
 289          $post_ids = $poster_postcounts = $postcounts = $postcount_visibility = array();
 290          while ($row = $this->db->sql_fetchrow($result))
 291          {
 292              $post_ids[] = (int) $row['post_id'];
 293   
 294              if ($row['post_visibility'] != $visibility)
 295              {
 296                  if ($row['post_postcount'] && !isset($poster_postcounts[(int) $row['poster_id']]))
 297                  {
 298                      $poster_postcounts[(int) $row['poster_id']] = 1;
 299                  }
 300                  else if ($row['post_postcount'])
 301                  {
 302                      $poster_postcounts[(int) $row['poster_id']]++;
 303                  }
 304   
 305                  if (!isset($postcount_visibility[$row['post_visibility']]))
 306                  {
 307                      $postcount_visibility[$row['post_visibility']] = 1;
 308                  }
 309                  else
 310                  {
 311                      $postcount_visibility[$row['post_visibility']]++;
 312                  }
 313              }
 314          }
 315          $this->db->sql_freeresult($result);
 316   
 317          if (empty($post_ids))
 318          {
 319              return array();
 320          }
 321   
 322          $data = array(
 323              'post_visibility'        => (int) $visibility,
 324              'post_delete_user'        => (int) $user_id,
 325              'post_delete_time'        => ((int) $time) ?: time(),
 326              'post_delete_reason'    => truncate_string($reason, 255, 255, false),
 327          );
 328   
 329          $sql = 'UPDATE ' . $this->posts_table . '
 330              SET ' . $this->db->sql_build_array('UPDATE', $data) . '
 331              WHERE ' . $this->db->sql_in_set('post_id', $post_ids);
 332          $this->db->sql_query($sql);
 333   
 334          // Group the authors by post count, to reduce the number of queries
 335          foreach ($poster_postcounts as $poster_id => $num_posts)
 336          {
 337              $postcounts[$num_posts][] = $poster_id;
 338          }
 339   
 340          // Update users postcounts
 341          foreach ($postcounts as $num_posts => $poster_ids)
 342          {
 343              if (in_array($visibility, array(ITEM_REAPPROVE, ITEM_DELETED)))
 344              {
 345                  $sql = 'UPDATE ' . $this->users_table . '
 346                      SET user_posts = 0
 347                      WHERE ' . $this->db->sql_in_set('user_id', $poster_ids) . '
 348                          AND user_posts < ' . $num_posts;
 349                  $this->db->sql_query($sql);
 350   
 351                  $sql = 'UPDATE ' . $this->users_table . '
 352                      SET user_posts = user_posts - ' . $num_posts . '
 353                      WHERE ' . $this->db->sql_in_set('user_id', $poster_ids) . '
 354                          AND user_posts >= ' . $num_posts;
 355                  $this->db->sql_query($sql);
 356              }
 357              else
 358              {
 359                  $sql = 'UPDATE ' . $this->users_table . '
 360                      SET user_posts = user_posts + ' . $num_posts . '
 361                      WHERE ' . $this->db->sql_in_set('user_id', $poster_ids);
 362                  $this->db->sql_query($sql);
 363              }
 364          }
 365   
 366          $update_topic_postcount = true;
 367   
 368          // Sync the first/last topic information if needed
 369          if (!$is_starter && $is_latest)
 370          {
 371              if (!function_exists('update_post_information'))
 372              {
 373                  include($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext);
 374              }
 375   
 376              // update_post_information can only update the last post info ...
 377              if ($topic_id)
 378              {
 379                  update_post_information('topic', $topic_id, false);
 380              }
 381              if ($forum_id)
 382              {
 383                  update_post_information('forum', $forum_id, false);
 384              }
 385          }
 386          else if ($is_starter && $topic_id)
 387          {
 388              if (!function_exists('sync'))
 389              {
 390                  include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
 391              }
 392   
 393              // ... so we need to use sync, if the first post is changed.
 394              // The forum is resynced recursive by sync() itself.
 395              sync('topic', 'topic_id', $topic_id, true);
 396   
 397              // sync recalculates the topic replies and forum posts by itself, so we don't do that.
 398              $update_topic_postcount = false;
 399          }
 400   
 401          $topic_update_array = array();
 402          // Update the topic's reply count and the forum's post count
 403          if ($update_topic_postcount)
 404          {
 405              $field_alias = array(
 406                  ITEM_APPROVED    => 'posts_approved',
 407                  ITEM_UNAPPROVED    => 'posts_unapproved',
 408                  ITEM_DELETED    => 'posts_softdeleted',
 409                  ITEM_REAPPROVE    => 'posts_unapproved',
 410              );
 411              $cur_posts = array_fill_keys($field_alias, 0);
 412   
 413              foreach ($postcount_visibility as $post_visibility => $visibility_posts)
 414              {
 415                  $cur_posts[$field_alias[(int) $post_visibility]] += $visibility_posts;
 416              }
 417   
 418              $sql_ary = array();
 419              $recipient_field = $field_alias[$visibility];
 420   
 421              foreach ($cur_posts as $field => $count)
 422              {
 423                  // Decrease the count for the old statuses.
 424                  if ($count && $field != $recipient_field)
 425                  {
 426                      $sql_ary[$field] = " - $count";
 427                  }
 428              }
 429              // Add up the count from all statuses excluding the recipient status.
 430              $count_increase = array_sum(array_diff($cur_posts, array($recipient_field)));
 431   
 432              if ($count_increase)
 433              {
 434                  $sql_ary[$recipient_field] = " + $count_increase";
 435              }
 436   
 437              if (sizeof($sql_ary))
 438              {
 439                  $forum_sql = array();
 440   
 441                  foreach ($sql_ary as $field => $value_change)
 442                  {
 443                      $topic_update_array[] = 'topic_' . $field . ' = topic_' . $field . $value_change;
 444                      $forum_sql[] = 'forum_' . $field . ' = forum_' . $field . $value_change;
 445                  }
 446   
 447                  $sql = 'UPDATE ' . $this->forums_table . '
 448                      SET ' . implode(', ', $forum_sql) . '
 449                      WHERE forum_id = ' . (int) $forum_id;
 450                  $this->db->sql_query($sql);
 451              }
 452          }
 453   
 454          if ($post_id)
 455          {
 456              $sql = 'SELECT 1 AS has_attachments
 457                  FROM ' . POSTS_TABLE . '
 458                  WHERE topic_id = ' . (int) $topic_id . '
 459                      AND post_attachment = 1
 460                      AND post_visibility = ' . ITEM_APPROVED . '
 461                      AND ' . $this->db->sql_in_set('post_id', $post_id, true);
 462              $result = $this->db->sql_query_limit($sql, 1);
 463   
 464              $has_attachment = (bool) $this->db->sql_fetchfield('has_attachments');
 465              $this->db->sql_freeresult($result);
 466   
 467              if ($has_attachment && $visibility == ITEM_APPROVED)
 468              {
 469                  $topic_update_array[] = 'topic_attachment = 1';
 470              }
 471              else if (!$has_attachment && $visibility != ITEM_APPROVED)
 472              {
 473                  $topic_update_array[] = 'topic_attachment = 0';
 474              }
 475          }
 476   
 477          if (!empty($topic_update_array))
 478          {
 479              // Update the number for replies and posts, and update the attachments flag
 480              $sql = 'UPDATE ' . $this->topics_table . '
 481                  SET ' . implode(', ', $topic_update_array) . '
 482                  WHERE topic_id = ' . (int) $topic_id;
 483              $this->db->sql_query($sql);
 484          }
 485   
 486          return $data;
 487      }
 488   
 489      /**
 490      * Set topic visibility
 491      *
 492      * Allows approving (which is akin to undeleting/restore) or soft deleting an entire topic.
 493      * Calls set_post_visibility as needed.
 494      *
 495      * Note: By default, when a soft deleted topic is restored. Only posts that
 496      *        were approved at the time of soft deleting, are being restored.
 497      *        Same applies to soft deleting. Only approved posts will be marked
 498      *        as soft deleted.
 499      *        If you want to update all posts, use the force option.
 500      *
 501      * @param $visibility    int        Element of {ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE}
 502      * @param $topic_id        mixed    Topic ID to act on
 503      * @param $forum_id        int        Forum where $topic_id is found
 504      * @param $user_id        int        User performing the action
 505      * @param $time            int        Timestamp when the action is performed
 506      * @param $reason        string    Reason why the visibilty was changed.
 507      * @param $force_update_all    bool    Force to update all posts within the topic
 508      * @return array        Changed topic data, empty array if an error occured.
 509      */
 510      public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false)
 511      {
 512          if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE)))
 513          {
 514              return array();
 515          }
 516   
 517          if (!$force_update_all)
 518          {
 519              $sql = 'SELECT topic_visibility, topic_delete_time
 520                  FROM ' . $this->topics_table . '
 521                  WHERE topic_id = ' . (int) $topic_id;
 522              $result = $this->db->sql_query($sql);
 523              $original_topic_data = $this->db->sql_fetchrow($result);
 524              $this->db->sql_freeresult($result);
 525   
 526              if (!$original_topic_data)
 527              {
 528                  // The topic does not exist...
 529                  return array();
 530              }
 531          }
 532   
 533          // Note, we do not set a reason for the posts, just for the topic
 534          $data = array(
 535              'topic_visibility'        => (int) $visibility,
 536              'topic_delete_user'        => (int) $user_id,
 537              'topic_delete_time'        => ((int) $time) ?: time(),
 538              'topic_delete_reason'    => truncate_string($reason, 255, 255, false),
 539          );
 540   
 541          $sql = 'UPDATE ' . $this->topics_table . '
 542              SET ' . $this->db->sql_build_array('UPDATE', $data) . '
 543              WHERE topic_id = ' . (int) $topic_id;
 544          $this->db->sql_query($sql);
 545   
 546          if (!$this->db->sql_affectedrows())
 547          {
 548              return array();
 549          }
 550   
 551          if (!$force_update_all && $original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED)
 552          {
 553              // If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion.
 554              $this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility'], $original_topic_data['topic_delete_time']);
 555          }
 556          else if (!$force_update_all && $original_topic_data['topic_visibility'] == ITEM_APPROVED && $visibility == ITEM_DELETED)
 557          {
 558              // If we're soft deleting a topic we only mark approved posts as soft deleted.
 559              $this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility']);
 560          }
 561          else
 562          {
 563              $this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true);
 564          }
 565   
 566          return $data;
 567      }
 568   
 569      /**
 570      * Add post to topic and forum statistics
 571      *
 572      * @param $data            array    Contains information from the topics table about given topic
 573      * @param &$sql_data        array    Populated with the SQL changes, may be empty at call time
 574      * @return null
 575      */
 576      public function add_post_to_statistic($data, &$sql_data)
 577      {
 578          $sql_data[$this->topics_table] = (($sql_data[$this->topics_table]) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved + 1';
 579   
 580          $sql_data[$this->forums_table] = (($sql_data[$this->forums_table]) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved + 1';
 581   
 582          if ($data['post_postcount'])
 583          {
 584              $sql_data[$this->users_table] = (($sql_data[$this->users_table]) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts + 1';
 585          }
 586   
 587          $this->config->increment('num_posts', 1, false);
 588      }
 589   
 590      /**
 591      * Remove post from topic and forum statistics
 592      *
 593      * @param $data            array    Contains information from the topics table about given topic
 594      * @param &$sql_data        array    Populated with the SQL changes, may be empty at call time
 595      * @return null
 596      */
 597      public function remove_post_from_statistic($data, &$sql_data)
 598      {
 599          if ($data['post_visibility'] == ITEM_APPROVED)
 600          {
 601              $sql_data[$this->topics_table] = ((!empty($sql_data[$this->topics_table])) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved - 1';
 602              $sql_data[$this->forums_table] = ((!empty($sql_data[$this->forums_table])) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved - 1';
 603   
 604              if ($data['post_postcount'])
 605              {
 606                  $sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1';
 607              }
 608   
 609              $this->config->increment('num_posts', -1, false);
 610          }
 611          else if ($data['post_visibility'] == ITEM_UNAPPROVED || $data['post_visibility'] == ITEM_REAPPROVE)
 612          {
 613              $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_unapproved = forum_posts_unapproved - 1';
 614              $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_unapproved = topic_posts_unapproved - 1';
 615          }
 616          else if ($data['post_visibility'] == ITEM_DELETED)
 617          {
 618              $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_softdeleted = forum_posts_softdeleted - 1';
 619              $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_softdeleted = topic_posts_softdeleted - 1';
 620          }
 621      }
 622   
 623      /**
 624      * Remove topic from forum statistics
 625      *
 626      * @param $data            array    Post and topic data
 627      * @param &$sql_data        array    Populated with the SQL changes, may be empty at call time
 628      * @return null
 629      */
 630      public function remove_topic_from_statistic($data, &$sql_data)
 631      {
 632          if ($data['topic_visibility'] == ITEM_APPROVED)
 633          {
 634              $sql_data[FORUMS_TABLE] .= 'forum_posts_approved = forum_posts_approved - 1, forum_topics_approved = forum_topics_approved - 1';
 635   
 636              if ($data['post_postcount'])
 637              {
 638                  $sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1';
 639              }
 640          }
 641          else if ($data['topic_visibility'] == ITEM_UNAPPROVED || $data['post_visibility'] == ITEM_REAPPROVE)
 642          {
 643              $sql_data[FORUMS_TABLE] .= 'forum_posts_unapproved = forum_posts_unapproved - 1, forum_topics_unapproved = forum_topics_unapproved - 1';
 644          }
 645          else if ($data['topic_visibility'] == ITEM_DELETED)
 646          {
 647              $sql_data[FORUMS_TABLE] .= 'forum_posts_softdeleted = forum_posts_softdeleted - 1, forum_topics_softdeleted = forum_topics_softdeleted - 1';
 648          }
 649   
 650      }
 651  }
 652