Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
acp_forums.php
0001 <?php
0002 /**
0003 *
0004 * This file is part of the phpBB Forum Software package.
0005 *
0006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
0007 * @license GNU General Public License, version 2 (GPL-2.0)
0008 *
0009 * For full copyright and license information, please see
0010 * the docs/CREDITS.txt file.
0011 *
0012 */
0013
0014 /**
0015 * @ignore
0016 */
0017 if (!defined('IN_PHPBB'))
0018 {
0019 exit;
0020 }
0021
0022 class acp_forums
0023 {
0024 var $u_action;
0025 var $parent_id = 0;
0026
0027 function main($id, $mode)
0028 {
0029 global $db, $user, $auth, $template, $cache, $request, $phpbb_dispatcher;
0030 global $phpbb_admin_path, $phpbb_root_path, $phpEx, $phpbb_log;
0031
0032 $user->add_lang('acp/forums');
0033 $this->tpl_name = 'acp_forums';
0034 $this->page_title = 'ACP_MANAGE_FORUMS';
0035
0036 $form_key = 'acp_forums';
0037 add_form_key($form_key);
0038
0039 $action = $request->variable('action', '');
0040 $update = (isset($_POST['update'])) ? true : false;
0041 $forum_id = $request->variable('f', 0);
0042
0043 $this->parent_id = $request->variable('parent_id', 0);
0044 $forum_data = $errors = array();
0045 if ($update && !check_form_key($form_key))
0046 {
0047 $update = false;
0048 $errors[] = $user->lang['FORM_INVALID'];
0049 }
0050
0051 // Check additional permissions
0052 switch ($action)
0053 {
0054 case 'progress_bar':
0055 $start = $request->variable('start', 0);
0056 $total = $request->variable('total', 0);
0057
0058 $this->display_progress_bar($start, $total);
0059 break;
0060
0061 case 'delete':
0062
0063 if (!$auth->acl_get('a_forumdel'))
0064 {
0065 trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0066 }
0067
0068 break;
0069
0070 case 'add':
0071
0072 if (!$auth->acl_get('a_forumadd'))
0073 {
0074 trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0075 }
0076
0077 break;
0078 }
0079
0080 // Major routines
0081 if ($update)
0082 {
0083 switch ($action)
0084 {
0085 case 'delete':
0086 $action_subforums = $request->variable('action_subforums', '');
0087 $subforums_to_id = $request->variable('subforums_to_id', 0);
0088 $action_posts = $request->variable('action_posts', '');
0089 $posts_to_id = $request->variable('posts_to_id', 0);
0090
0091 $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
0092
0093 if (sizeof($errors))
0094 {
0095 break;
0096 }
0097
0098 $auth->acl_clear_prefetch();
0099 $cache->destroy('sql', FORUMS_TABLE);
0100
0101 trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
0102
0103 break;
0104
0105 case 'edit':
0106 $forum_data = array(
0107 'forum_id' => $forum_id
0108 );
0109
0110 // No break here
0111
0112 case 'add':
0113
0114 $forum_data += array(
0115 'parent_id' => $request->variable('forum_parent_id', $this->parent_id),
0116 'forum_type' => $request->variable('forum_type', FORUM_POST),
0117 'type_action' => $request->variable('type_action', ''),
0118 'forum_status' => $request->variable('forum_status', ITEM_UNLOCKED),
0119 'forum_parents' => '',
0120 'forum_name' => $request->variable('forum_name', '', true),
0121 'forum_link' => $request->variable('forum_link', ''),
0122 'forum_link_track' => $request->variable('forum_link_track', false),
0123 'forum_desc' => $request->variable('forum_desc', '', true),
0124 'forum_desc_uid' => '',
0125 'forum_desc_options' => 7,
0126 'forum_desc_bitfield' => '',
0127 'forum_rules' => $request->variable('forum_rules', '', true),
0128 'forum_rules_uid' => '',
0129 'forum_rules_options' => 7,
0130 'forum_rules_bitfield' => '',
0131 'forum_rules_link' => $request->variable('forum_rules_link', ''),
0132 'forum_image' => $request->variable('forum_image', ''),
0133 'forum_style' => $request->variable('forum_style', 0),
0134 'display_subforum_list' => $request->variable('display_subforum_list', false),
0135 'display_on_index' => $request->variable('display_on_index', false),
0136 'forum_topics_per_page' => $request->variable('topics_per_page', 0),
0137 'enable_indexing' => $request->variable('enable_indexing', true),
0138 'enable_icons' => $request->variable('enable_icons', false),
0139 'enable_prune' => $request->variable('enable_prune', false),
0140 'enable_post_review' => $request->variable('enable_post_review', true),
0141 'enable_quick_reply' => $request->variable('enable_quick_reply', false),
0142 'enable_shadow_prune' => $request->variable('enable_shadow_prune', false),
0143 'prune_days' => $request->variable('prune_days', 7),
0144 'prune_viewed' => $request->variable('prune_viewed', 7),
0145 'prune_freq' => $request->variable('prune_freq', 1),
0146 'prune_old_polls' => $request->variable('prune_old_polls', false),
0147 'prune_announce' => $request->variable('prune_announce', false),
0148 'prune_sticky' => $request->variable('prune_sticky', false),
0149 'prune_shadow_days' => $request->variable('prune_shadow_days', 7),
0150 'prune_shadow_freq' => $request->variable('prune_shadow_freq', 1),
0151 'forum_password' => $request->variable('forum_password', '', true),
0152 'forum_password_confirm'=> $request->variable('forum_password_confirm', '', true),
0153 'forum_password_unset' => $request->variable('forum_password_unset', false),
0154 );
0155
0156 /**
0157 * Request forum data and operate on it (parse texts, etc.)
0158 *
0159 * @event core.acp_manage_forums_request_data
0160 * @var string action Type of the action: add|edit
0161 * @var array forum_data Array with new forum data
0162 * @since 3.1.0-a1
0163 */
0164 $vars = array('action', 'forum_data');
0165 extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_request_data', compact($vars)));
0166
0167 // On add, add empty forum_options... else do not consider it (not updating it)
0168 if ($action == 'add')
0169 {
0170 $forum_data['forum_options'] = 0;
0171 }
0172
0173 // Use link_display_on_index setting if forum type is link
0174 if ($forum_data['forum_type'] == FORUM_LINK)
0175 {
0176 $forum_data['display_on_index'] = $request->variable('link_display_on_index', false);
0177 }
0178
0179 // Linked forums and categories are not able to be locked...
0180 if ($forum_data['forum_type'] == FORUM_LINK || $forum_data['forum_type'] == FORUM_CAT)
0181 {
0182 $forum_data['forum_status'] = ITEM_UNLOCKED;
0183 }
0184
0185 $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? $request->variable('display_recent', true) : $request->variable('display_active', false);
0186
0187 // Get data for forum rules if specified...
0188 if ($forum_data['forum_rules'])
0189 {
0190 generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], $request->variable('rules_parse_bbcode', false), $request->variable('rules_parse_urls', false), $request->variable('rules_parse_smilies', false));
0191 }
0192
0193 // Get data for forum description if specified
0194 if ($forum_data['forum_desc'])
0195 {
0196 generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], $request->variable('desc_parse_bbcode', false), $request->variable('desc_parse_urls', false), $request->variable('desc_parse_smilies', false));
0197 }
0198
0199 $errors = $this->update_forum_data($forum_data);
0200
0201 if (!sizeof($errors))
0202 {
0203 $forum_perm_from = $request->variable('forum_perm_from', 0);
0204 $cache->destroy('sql', FORUMS_TABLE);
0205
0206 $copied_permissions = false;
0207 // Copy permissions?
0208 if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] &&
0209 ($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'))))
0210 {
0211 copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false);
0212 phpbb_cache_moderators($db, $cache, $auth);
0213 $copied_permissions = true;
0214 }
0215 /* Commented out because of questionable UI workflow - re-visit for 3.0.7
0216 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'))
0217 {
0218 $this->copy_permission_page($forum_data);
0219 return;
0220 }
0221 */
0222 $auth->acl_clear_prefetch();
0223
0224 $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
0225
0226 $message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
0227
0228 // redirect directly to permission settings screen if authed
0229 if ($action == 'add' && !$copied_permissions && $auth->acl_get('a_fauth'))
0230 {
0231 $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
0232
0233 meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
0234 }
0235
0236 trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
0237 }
0238
0239 break;
0240 }
0241 }
0242
0243 switch ($action)
0244 {
0245 case 'move_up':
0246 case 'move_down':
0247
0248 if (!$forum_id)
0249 {
0250 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0251 }
0252
0253 $sql = 'SELECT *
0254 FROM ' . FORUMS_TABLE . "
0255 WHERE forum_id = $forum_id";
0256 $result = $db->sql_query($sql);
0257 $row = $db->sql_fetchrow($result);
0258 $db->sql_freeresult($result);
0259
0260 if (!$row)
0261 {
0262 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0263 }
0264
0265 $move_forum_name = $this->move_forum_by($row, $action, 1);
0266
0267 if ($move_forum_name !== false)
0268 {
0269 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_' . strtoupper($action), false, array($row['forum_name'], $move_forum_name));
0270 $cache->destroy('sql', FORUMS_TABLE);
0271 }
0272
0273 if ($request->is_ajax())
0274 {
0275 $json_response = new \phpbb\json_response;
0276 $json_response->send(array('success' => ($move_forum_name !== false)));
0277 }
0278
0279 break;
0280
0281 case 'sync':
0282 if (!$forum_id)
0283 {
0284 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0285 }
0286
0287 @set_time_limit(0);
0288
0289 $sql = 'SELECT forum_name, (forum_topics_approved + forum_topics_unapproved + forum_topics_softdeleted) AS total_topics
0290 FROM ' . FORUMS_TABLE . "
0291 WHERE forum_id = $forum_id";
0292 $result = $db->sql_query($sql);
0293 $row = $db->sql_fetchrow($result);
0294 $db->sql_freeresult($result);
0295
0296 if (!$row)
0297 {
0298 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0299 }
0300
0301 if ($row['total_topics'])
0302 {
0303 $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
0304 FROM ' . TOPICS_TABLE . '
0305 WHERE forum_id = ' . $forum_id;
0306 $result = $db->sql_query($sql);
0307 $row2 = $db->sql_fetchrow($result);
0308 $db->sql_freeresult($result);
0309
0310 // Typecast to int if there is no data available
0311 $row2['min_topic_id'] = (int) $row2['min_topic_id'];
0312 $row2['max_topic_id'] = (int) $row2['max_topic_id'];
0313
0314 $start = $request->variable('start', $row2['min_topic_id']);
0315
0316 $batch_size = 2000;
0317 $end = $start + $batch_size;
0318
0319 // Sync all topics in batch mode...
0320 sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
0321
0322 if ($end < $row2['max_topic_id'])
0323 {
0324 // We really need to find a way of showing statistics... no progress here
0325 $sql = 'SELECT COUNT(topic_id) as num_topics
0326 FROM ' . TOPICS_TABLE . '
0327 WHERE forum_id = ' . $forum_id . '
0328 AND topic_id BETWEEN ' . $start . ' AND ' . $end;
0329 $result = $db->sql_query($sql);
0330 $topics_done = $request->variable('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
0331 $db->sql_freeresult($result);
0332
0333 $start += $batch_size;
0334
0335 $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync&start=$start&topics_done=$topics_done&total={$row['total_topics']}";
0336
0337 meta_refresh(0, $url);
0338
0339 $template->assign_vars(array(
0340 'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$topics_done&total={$row['total_topics']}",
0341 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$topics_done&total={$row['total_topics']}"),
0342 'S_CONTINUE_SYNC' => true,
0343 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['total_topics']))
0344 );
0345
0346 return;
0347 }
0348 }
0349
0350 $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync_forum";
0351 meta_refresh(0, $url);
0352
0353 $template->assign_vars(array(
0354 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
0355 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
0356 'S_CONTINUE_SYNC' => true,
0357 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['total_topics']))
0358 );
0359
0360 return;
0361
0362 break;
0363
0364 case 'sync_forum':
0365
0366 $sql = 'SELECT forum_name, forum_type
0367 FROM ' . FORUMS_TABLE . "
0368 WHERE forum_id = $forum_id";
0369 $result = $db->sql_query($sql);
0370 $row = $db->sql_fetchrow($result);
0371 $db->sql_freeresult($result);
0372
0373 if (!$row)
0374 {
0375 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0376 }
0377
0378 sync('forum', 'forum_id', $forum_id, false, true);
0379
0380 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_SYNC', false, array($row['forum_name']));
0381
0382 $cache->destroy('sql', FORUMS_TABLE);
0383
0384 $template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
0385
0386 break;
0387
0388 case 'add':
0389 case 'edit':
0390
0391 if ($update)
0392 {
0393 $forum_data['forum_flags'] = 0;
0394 $forum_data['forum_flags'] += ($request->variable('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
0395 $forum_data['forum_flags'] += ($request->variable('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
0396 $forum_data['forum_flags'] += ($request->variable('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
0397 $forum_data['forum_flags'] += ($request->variable('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
0398 $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
0399 $forum_data['forum_flags'] += ($request->variable('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
0400 $forum_data['forum_flags'] += ($request->variable('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0;
0401 }
0402
0403 // Initialise $row, so we always have it in the event
0404 $row = array();
0405
0406 // Show form to create/modify a forum
0407 if ($action == 'edit')
0408 {
0409 $this->page_title = 'EDIT_FORUM';
0410 $row = $this->get_forum_info($forum_id);
0411 $old_forum_type = $row['forum_type'];
0412
0413 if (!$update)
0414 {
0415 $forum_data = $row;
0416 }
0417 else
0418 {
0419 $forum_data['left_id'] = $row['left_id'];
0420 $forum_data['right_id'] = $row['right_id'];
0421 }
0422
0423 // Make sure no direct child forums are able to be selected as parents.
0424 $exclude_forums = array();
0425 foreach (get_forum_branch($forum_id, 'children') as $row)
0426 {
0427 $exclude_forums[] = $row['forum_id'];
0428 }
0429
0430 $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
0431
0432 $forum_data['forum_password_confirm'] = $forum_data['forum_password'];
0433 }
0434 else
0435 {
0436 $this->page_title = 'CREATE_FORUM';
0437
0438 $forum_id = $this->parent_id;
0439 $parents_list = make_forum_select($this->parent_id, false, false, false, false);
0440
0441 // Fill forum data with default values
0442 if (!$update)
0443 {
0444 $forum_data = array(
0445 'parent_id' => $this->parent_id,
0446 'forum_type' => FORUM_POST,
0447 'forum_status' => ITEM_UNLOCKED,
0448 'forum_name' => $request->variable('forum_name', '', true),
0449 'forum_link' => '',
0450 'forum_link_track' => false,
0451 'forum_desc' => '',
0452 'forum_rules' => '',
0453 'forum_rules_link' => '',
0454 'forum_image' => '',
0455 'forum_style' => 0,
0456 'display_subforum_list' => true,
0457 'display_on_index' => false,
0458 'forum_topics_per_page' => 0,
0459 'enable_indexing' => true,
0460 'enable_icons' => false,
0461 'enable_prune' => false,
0462 'prune_days' => 7,
0463 'prune_viewed' => 7,
0464 'prune_freq' => 1,
0465 'enable_shadow_prune' => false,
0466 'prune_shadow_days' => 7,
0467 'prune_shadow_freq' => 1,
0468 'forum_flags' => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS,
0469 'forum_options' => 0,
0470 'forum_password' => '',
0471 'forum_password_confirm'=> '',
0472 );
0473 }
0474 }
0475
0476 /**
0477 * Initialise data before we display the add/edit form
0478 *
0479 * @event core.acp_manage_forums_initialise_data
0480 * @var string action Type of the action: add|edit
0481 * @var bool update Do we display the form only
0482 * or did the user press submit
0483 * @var int forum_id When editing: the forum id,
0484 * when creating: the parent forum id
0485 * @var array row Array with current forum data
0486 * empty when creating new forum
0487 * @var array forum_data Array with new forum data
0488 * @var string parents_list List of parent options
0489 * @since 3.1.0-a1
0490 */
0491 $vars = array('action', 'update', 'forum_id', 'row', 'forum_data', 'parents_list');
0492 extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_initialise_data', compact($vars)));
0493
0494 $forum_rules_data = array(
0495 'text' => $forum_data['forum_rules'],
0496 'allow_bbcode' => true,
0497 'allow_smilies' => true,
0498 'allow_urls' => true
0499 );
0500
0501 $forum_desc_data = array(
0502 'text' => $forum_data['forum_desc'],
0503 'allow_bbcode' => true,
0504 'allow_smilies' => true,
0505 'allow_urls' => true
0506 );
0507
0508 $forum_rules_preview = '';
0509
0510 // Parse rules if specified
0511 if ($forum_data['forum_rules'])
0512 {
0513 if (!isset($forum_data['forum_rules_uid']))
0514 {
0515 // Before we are able to display the preview and plane text, we need to parse our $request->variable()'d value...
0516 $forum_data['forum_rules_uid'] = '';
0517 $forum_data['forum_rules_bitfield'] = '';
0518 $forum_data['forum_rules_options'] = 0;
0519
0520 generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], $request->variable('rules_allow_bbcode', false), $request->variable('rules_allow_urls', false), $request->variable('rules_allow_smilies', false));
0521 }
0522
0523 // Generate preview content
0524 $forum_rules_preview = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
0525
0526 // decode...
0527 $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
0528 }
0529
0530 // Parse desciption if specified
0531 if ($forum_data['forum_desc'])
0532 {
0533 if (!isset($forum_data['forum_desc_uid']))
0534 {
0535 // Before we are able to display the preview and plane text, we need to parse our $request->variable()'d value...
0536 $forum_data['forum_desc_uid'] = '';
0537 $forum_data['forum_desc_bitfield'] = '';
0538 $forum_data['forum_desc_options'] = 0;
0539
0540 generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], $request->variable('desc_allow_bbcode', false), $request->variable('desc_allow_urls', false), $request->variable('desc_allow_smilies', false));
0541 }
0542
0543 // decode...
0544 $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
0545 }
0546
0547 $forum_type_options = '';
0548 $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
0549
0550 foreach ($forum_type_ary as $value => $lang)
0551 {
0552 $forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
0553 }
0554
0555 $styles_list = style_select($forum_data['forum_style'], true);
0556
0557 $statuslist = '<option value="' . ITEM_UNLOCKED . '"' . (($forum_data['forum_status'] == ITEM_UNLOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['UNLOCKED'] . '</option><option value="' . ITEM_LOCKED . '"' . (($forum_data['forum_status'] == ITEM_LOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['LOCKED'] . '</option>';
0558
0559 $sql = 'SELECT forum_id
0560 FROM ' . FORUMS_TABLE . '
0561 WHERE forum_type = ' . FORUM_POST . "
0562 AND forum_id <> $forum_id";
0563 $result = $db->sql_query_limit($sql, 1);
0564
0565 $postable_forum_exists = false;
0566 if ($db->sql_fetchrow($result))
0567 {
0568 $postable_forum_exists = true;
0569 }
0570 $db->sql_freeresult($result);
0571
0572 // Subforum move options
0573 if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
0574 {
0575 $subforums_id = array();
0576 $subforums = get_forum_branch($forum_id, 'children');
0577
0578 foreach ($subforums as $row)
0579 {
0580 $subforums_id[] = $row['forum_id'];
0581 }
0582
0583 $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
0584
0585 if ($postable_forum_exists)
0586 {
0587 $template->assign_vars(array(
0588 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
0589 );
0590 }
0591
0592 $template->assign_vars(array(
0593 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
0594 'S_FORUMS_LIST' => $forums_list)
0595 );
0596 }
0597 else if ($postable_forum_exists)
0598 {
0599 $template->assign_vars(array(
0600 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
0601 );
0602 }
0603
0604 $s_show_display_on_index = false;
0605
0606 if ($forum_data['parent_id'] > 0)
0607 {
0608 // if this forum is a subforum put the "display on index" checkbox
0609 if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
0610 {
0611 if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
0612 {
0613 $s_show_display_on_index = true;
0614 }
0615 }
0616 }
0617
0618 if (strlen($forum_data['forum_password']) == 32)
0619 {
0620 $errors[] = $user->lang['FORUM_PASSWORD_OLD'];
0621 }
0622
0623 $template_data = array(
0624 'S_EDIT_FORUM' => true,
0625 'S_ERROR' => (sizeof($errors)) ? true : false,
0626 'S_PARENT_ID' => $this->parent_id,
0627 'S_FORUM_PARENT_ID' => $forum_data['parent_id'],
0628 'S_ADD_ACTION' => ($action == 'add') ? true : false,
0629
0630 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
0631 'U_EDIT_ACTION' => $this->u_action . "&parent_id={$this->parent_id}&action=$action&f=$forum_id",
0632
0633 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
0634 'L_TITLE' => $user->lang[$this->page_title],
0635 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
0636
0637 'FORUM_NAME' => $forum_data['forum_name'],
0638 'FORUM_DATA_LINK' => $forum_data['forum_link'],
0639 'FORUM_IMAGE' => $forum_data['forum_image'],
0640 'FORUM_IMAGE_SRC' => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
0641 'FORUM_POST' => FORUM_POST,
0642 'FORUM_LINK' => FORUM_LINK,
0643 'FORUM_CAT' => FORUM_CAT,
0644 'PRUNE_FREQ' => $forum_data['prune_freq'],
0645 'PRUNE_DAYS' => $forum_data['prune_days'],
0646 'PRUNE_VIEWED' => $forum_data['prune_viewed'],
0647 'PRUNE_SHADOW_FREQ' => $forum_data['prune_shadow_freq'],
0648 'PRUNE_SHADOW_DAYS' => $forum_data['prune_shadow_days'],
0649 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'],
0650 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'],
0651 'FORUM_RULES' => $forum_data['forum_rules'],
0652 'FORUM_RULES_PREVIEW' => $forum_rules_preview,
0653 'FORUM_RULES_PLAIN' => $forum_rules_data['text'],
0654 'S_BBCODE_CHECKED' => ($forum_rules_data['allow_bbcode']) ? true : false,
0655 'S_SMILIES_CHECKED' => ($forum_rules_data['allow_smilies']) ? true : false,
0656 'S_URLS_CHECKED' => ($forum_rules_data['allow_urls']) ? true : false,
0657 'S_FORUM_PASSWORD_SET' => (empty($forum_data['forum_password'])) ? false : true,
0658
0659 'FORUM_DESC' => $forum_desc_data['text'],
0660 'S_DESC_BBCODE_CHECKED' => ($forum_desc_data['allow_bbcode']) ? true : false,
0661 'S_DESC_SMILIES_CHECKED' => ($forum_desc_data['allow_smilies']) ? true : false,
0662 'S_DESC_URLS_CHECKED' => ($forum_desc_data['allow_urls']) ? true : false,
0663
0664 'S_FORUM_TYPE_OPTIONS' => $forum_type_options,
0665 'S_STATUS_OPTIONS' => $statuslist,
0666 'S_PARENT_OPTIONS' => $parents_list,
0667 'S_STYLES_OPTIONS' => $styles_list,
0668 'S_FORUM_OPTIONS' => make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
0669 'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index,
0670 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
0671 'S_FORUM_ORIG_POST' => (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
0672 'S_FORUM_ORIG_CAT' => (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
0673 'S_FORUM_ORIG_LINK' => (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
0674 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
0675 'S_FORUM_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
0676 'S_ENABLE_INDEXING' => ($forum_data['enable_indexing']) ? true : false,
0677 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false,
0678 'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false,
0679 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false,
0680 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false,
0681 'S_PRUNE_SHADOW_ENABLE' => ($forum_data['enable_shadow_prune']) ? true : false,
0682 'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
0683 'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
0684 'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
0685 'S_PRUNE_STICKY' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
0686 'S_DISPLAY_ACTIVE_TOPICS' => ($forum_data['forum_type'] == FORUM_POST) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : true,
0687 'S_ENABLE_ACTIVE_TOPICS' => ($forum_data['forum_type'] == FORUM_CAT) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : false,
0688 'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
0689 'S_ENABLE_QUICK_REPLY' => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false,
0690 '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,
0691 );
0692
0693 /**
0694 * Modify forum template data before we display the form
0695 *
0696 * @event core.acp_manage_forums_display_form
0697 * @var string action Type of the action: add|edit
0698 * @var bool update Do we display the form only
0699 * or did the user press submit
0700 * @var int forum_id When editing: the forum id,
0701 * when creating: the parent forum id
0702 * @var array row Array with current forum data
0703 * empty when creating new forum
0704 * @var array forum_data Array with new forum data
0705 * @var string parents_list List of parent options
0706 * @var array errors Array of errors, if you add errors
0707 * ensure to update the template variables
0708 * S_ERROR and ERROR_MSG to display it
0709 * @var array template_data Array with new forum data
0710 * @since 3.1.0-a1
0711 */
0712 $vars = array(
0713 'action',
0714 'update',
0715 'forum_id',
0716 'row',
0717 'forum_data',
0718 'parents_list',
0719 'errors',
0720 'template_data',
0721 );
0722 extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_display_form', compact($vars)));
0723
0724 $template->assign_vars($template_data);
0725
0726 return;
0727
0728 break;
0729
0730 case 'delete':
0731
0732 if (!$forum_id)
0733 {
0734 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0735 }
0736
0737 $forum_data = $this->get_forum_info($forum_id);
0738
0739 $subforums_id = array();
0740 $subforums = get_forum_branch($forum_id, 'children');
0741
0742 foreach ($subforums as $row)
0743 {
0744 $subforums_id[] = $row['forum_id'];
0745 }
0746
0747 $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
0748
0749 $sql = 'SELECT forum_id
0750 FROM ' . FORUMS_TABLE . '
0751 WHERE forum_type = ' . FORUM_POST . "
0752 AND forum_id <> $forum_id";
0753 $result = $db->sql_query_limit($sql, 1);
0754
0755 if ($db->sql_fetchrow($result))
0756 {
0757 $template->assign_vars(array(
0758 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
0759 );
0760 }
0761 $db->sql_freeresult($result);
0762
0763 $parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
0764
0765 $template->assign_vars(array(
0766 'S_DELETE_FORUM' => true,
0767 'U_ACTION' => $this->u_action . "&parent_id={$parent_id}&action=delete&f=$forum_id",
0768 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
0769
0770 'FORUM_NAME' => $forum_data['forum_name'],
0771 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
0772 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
0773 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
0774 'S_FORUMS_LIST' => $forums_list,
0775 'S_ERROR' => (sizeof($errors)) ? true : false,
0776 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '')
0777 );
0778
0779 return;
0780 break;
0781
0782 case 'copy_perm':
0783 $forum_perm_from = $request->variable('forum_perm_from', 0);
0784
0785 // Copy permissions?
0786 if (!empty($forum_perm_from) && $forum_perm_from != $forum_id)
0787 {
0788 copy_forum_permissions($forum_perm_from, $forum_id, true);
0789 phpbb_cache_moderators($db, $cache, $auth);
0790 $auth->acl_clear_prefetch();
0791 $cache->destroy('sql', FORUMS_TABLE);
0792
0793 $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_id;
0794
0795 $message = $user->lang['FORUM_UPDATED'];
0796
0797 // Redirect to permissions
0798 if ($auth->acl_get('a_fauth'))
0799 {
0800 $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
0801 }
0802
0803 trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
0804 }
0805
0806 break;
0807 }
0808
0809 // Default management page
0810 if (!$this->parent_id)
0811 {
0812 $navigation = $user->lang['FORUM_INDEX'];
0813 }
0814 else
0815 {
0816 $navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
0817
0818 $forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
0819 foreach ($forums_nav as $row)
0820 {
0821 if ($row['forum_id'] == $this->parent_id)
0822 {
0823 $navigation .= ' -> ' . $row['forum_name'];
0824 }
0825 else
0826 {
0827 $navigation .= ' -> <a href="' . $this->u_action . '&parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
0828 }
0829 }
0830 }
0831
0832 // Jumpbox
0833 $forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
0834
0835 if ($action == 'sync' || $action == 'sync_forum')
0836 {
0837 $template->assign_var('S_RESYNCED', true);
0838 }
0839
0840 $sql = 'SELECT *
0841 FROM ' . FORUMS_TABLE . "
0842 WHERE parent_id = $this->parent_id
0843 ORDER BY left_id";
0844 $result = $db->sql_query($sql);
0845
0846 $rowset = array();
0847 while ($row = $db->sql_fetchrow($result))
0848 {
0849 $rowset[(int) $row['forum_id']] = $row;
0850 }
0851 $db->sql_freeresult($result);
0852
0853 /**
0854 * Modify the forum list data
0855 *
0856 * @event core.acp_manage_forums_modify_forum_list
0857 * @var array rowset Array with the forums list data
0858 * @since 3.1.10-RC1
0859 */
0860 $vars = array('rowset');
0861 extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_modify_forum_list', compact($vars)));
0862
0863 if (!empty($rowset))
0864 {
0865 foreach ($rowset as $row)
0866 {
0867 $forum_type = $row['forum_type'];
0868
0869 if ($row['forum_status'] == ITEM_LOCKED)
0870 {
0871 $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
0872 }
0873 else
0874 {
0875 switch ($forum_type)
0876 {
0877 case FORUM_LINK:
0878 $folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
0879 break;
0880
0881 default:
0882 $folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" alt="' . $user->lang['SUBFORUM'] . '" />' : '<img src="images/icon_folder.gif" alt="' . $user->lang['FOLDER'] . '" />';
0883 break;
0884 }
0885 }
0886
0887 $url = $this->u_action . "&parent_id=$this->parent_id&f={$row['forum_id']}";
0888
0889 $template->assign_block_vars('forums', array(
0890 'FOLDER_IMAGE' => $folder_image,
0891 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
0892 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
0893 'FORUM_NAME' => $row['forum_name'],
0894 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
0895 'FORUM_TOPICS' => $row['forum_topics_approved'],
0896 'FORUM_POSTS' => $row['forum_posts_approved'],
0897
0898 'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false,
0899 'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false,
0900
0901 'U_FORUM' => $this->u_action . '&parent_id=' . $row['forum_id'],
0902 'U_MOVE_UP' => $url . '&action=move_up',
0903 'U_MOVE_DOWN' => $url . '&action=move_down',
0904 'U_EDIT' => $url . '&action=edit',
0905 'U_DELETE' => $url . '&action=delete',
0906 'U_SYNC' => $url . '&action=sync')
0907 );
0908 }
0909 }
0910 else if ($this->parent_id)
0911 {
0912 $row = $this->get_forum_info($this->parent_id);
0913
0914 $url = $this->u_action . '&parent_id=' . $this->parent_id . '&f=' . $row['forum_id'];
0915
0916 $template->assign_vars(array(
0917 'S_NO_FORUMS' => true,
0918
0919 'U_EDIT' => $url . '&action=edit',
0920 'U_DELETE' => $url . '&action=delete',
0921 'U_SYNC' => $url . '&action=sync')
0922 );
0923 }
0924 unset($rowset);
0925
0926 $template->assign_vars(array(
0927 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
0928 'NAVIGATION' => $navigation,
0929 'FORUM_BOX' => $forum_box,
0930 'U_SEL_ACTION' => $this->u_action,
0931 'U_ACTION' => $this->u_action . '&parent_id=' . $this->parent_id,
0932
0933 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
0934 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
0935 ));
0936 }
0937
0938 /**
0939 * Get forum details
0940 */
0941 function get_forum_info($forum_id)
0942 {
0943 global $db;
0944
0945 $sql = 'SELECT *
0946 FROM ' . FORUMS_TABLE . "
0947 WHERE forum_id = $forum_id";
0948 $result = $db->sql_query($sql);
0949 $row = $db->sql_fetchrow($result);
0950 $db->sql_freeresult($result);
0951
0952 if (!$row)
0953 {
0954 trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
0955 }
0956
0957 return $row;
0958 }
0959
0960 /**
0961 * Update forum data
0962 */
0963 function update_forum_data(&$forum_data_ary)
0964 {
0965 global $db, $user, $cache, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher, $phpbb_log, $request;
0966
0967 $errors = array();
0968
0969 $forum_data = $forum_data_ary;
0970 /**
0971 * Validate the forum data before we create/update the forum
0972 *
0973 * @event core.acp_manage_forums_validate_data
0974 * @var array forum_data Array with new forum data
0975 * @var array errors Array of errors, should be strings and not
0976 * language key.
0977 * @since 3.1.0-a1
0978 */
0979 $vars = array('forum_data', 'errors');
0980 extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_validate_data', compact($vars)));
0981 $forum_data_ary = $forum_data;
0982 unset($forum_data);
0983
0984 if ($forum_data_ary['forum_name'] == '')
0985 {
0986 $errors[] = $user->lang['FORUM_NAME_EMPTY'];
0987 }
0988
0989 if (utf8_strlen($forum_data_ary['forum_desc']) > 4000)
0990 {
0991 $errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
0992 }
0993
0994 if (utf8_strlen($forum_data_ary['forum_rules']) > 4000)
0995 {
0996 $errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
0997 }
0998
0999 if ($forum_data_ary['forum_password'] || $forum_data_ary['forum_password_confirm'])
1000 {
1001 if ($forum_data_ary['forum_password'] != $forum_data_ary['forum_password_confirm'])
1002 {
1003 $forum_data_ary['forum_password'] = $forum_data_ary['forum_password_confirm'] = '';
1004 $errors[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
1005 }
1006 }
1007
1008 if ($forum_data_ary['prune_days'] < 0 || $forum_data_ary['prune_viewed'] < 0 || $forum_data_ary['prune_freq'] < 0)
1009 {
1010 $forum_data_ary['prune_days'] = $forum_data_ary['prune_viewed'] = $forum_data_ary['prune_freq'] = 0;
1011 $errors[] = $user->lang['FORUM_DATA_NEGATIVE'];
1012 }
1013
1014 $range_test_ary = array(
1015 array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data_ary['forum_topics_per_page'], 'column_type' => 'TINT:0'),
1016 );
1017
1018 if (!empty($forum_data_ary['forum_image']) && !file_exists($phpbb_root_path . $forum_data_ary['forum_image']))
1019 {
1020 $errors[] = $user->lang['FORUM_IMAGE_NO_EXIST'];
1021 }
1022
1023 validate_range($range_test_ary, $errors);
1024
1025 // Set forum flags
1026 // 1 = link tracking
1027 // 2 = prune old polls
1028 // 4 = prune announcements
1029 // 8 = prune stickies
1030 // 16 = show active topics
1031 // 32 = enable post review
1032 $forum_data_ary['forum_flags'] = 0;
1033 $forum_data_ary['forum_flags'] += ($forum_data_ary['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
1034 $forum_data_ary['forum_flags'] += ($forum_data_ary['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
1035 $forum_data_ary['forum_flags'] += ($forum_data_ary['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
1036 $forum_data_ary['forum_flags'] += ($forum_data_ary['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
1037 $forum_data_ary['forum_flags'] += ($forum_data_ary['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
1038 $forum_data_ary['forum_flags'] += ($forum_data_ary['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
1039 $forum_data_ary['forum_flags'] += ($forum_data_ary['enable_quick_reply']) ? FORUM_FLAG_QUICK_REPLY : 0;
1040
1041 // Unset data that are not database fields
1042 $forum_data_sql = $forum_data_ary;
1043
1044 unset($forum_data_sql['forum_link_track']);
1045 unset($forum_data_sql['prune_old_polls']);
1046 unset($forum_data_sql['prune_announce']);
1047 unset($forum_data_sql['prune_sticky']);
1048 unset($forum_data_sql['show_active']);
1049 unset($forum_data_sql['enable_post_review']);
1050 unset($forum_data_sql['enable_quick_reply']);
1051 unset($forum_data_sql['forum_password_confirm']);
1052
1053 // What are we going to do tonight Brain? The same thing we do everynight,
1054 // try to take over the world ... or decide whether to continue update
1055 // and if so, whether it's a new forum/cat/link or an existing one
1056 if (sizeof($errors))
1057 {
1058 return $errors;
1059 }
1060
1061 // As we don't know the old password, it's kinda tricky to detect changes
1062 if ($forum_data_sql['forum_password_unset'])
1063 {
1064 $forum_data_sql['forum_password'] = '';
1065 }
1066 else if (empty($forum_data_sql['forum_password']))
1067 {
1068 unset($forum_data_sql['forum_password']);
1069 }
1070 else
1071 {
1072 // Instantiate passwords manager
1073 /* @var $passwords_manager \phpbb\passwords\manager */
1074 $passwords_manager = $phpbb_container->get('passwords.manager');
1075
1076 $forum_data_sql['forum_password'] = $passwords_manager->hash($forum_data_sql['forum_password']);
1077 }
1078 unset($forum_data_sql['forum_password_unset']);
1079
1080 $forum_data = $forum_data_ary;
1081 /**
1082 * Remove invalid values from forum_data_sql that should not be updated
1083 *
1084 * @event core.acp_manage_forums_update_data_before
1085 * @var array forum_data Array with forum data
1086 * @var array forum_data_sql Array with data we are going to update
1087 * If forum_data_sql[forum_id] is set, we update
1088 * that forum, otherwise a new one is created.
1089 * @since 3.1.0-a1
1090 */
1091 $vars = array('forum_data', 'forum_data_sql');
1092 extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_before', compact($vars)));
1093 $forum_data_ary = $forum_data;
1094 unset($forum_data);
1095
1096 $is_new_forum = !isset($forum_data_sql['forum_id']);
1097
1098 if ($is_new_forum)
1099 {
1100 // no forum_id means we're creating a new forum
1101 unset($forum_data_sql['type_action']);
1102
1103 if ($forum_data_sql['parent_id'])
1104 {
1105 $sql = 'SELECT left_id, right_id, forum_type
1106 FROM ' . FORUMS_TABLE . '
1107 WHERE forum_id = ' . $forum_data_sql['parent_id'];
1108 $result = $db->sql_query($sql);
1109 $row = $db->sql_fetchrow($result);
1110 $db->sql_freeresult($result);
1111
1112 if (!$row)
1113 {
1114 trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
1115 }
1116
1117 if ($row['forum_type'] == FORUM_LINK)
1118 {
1119 $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
1120 return $errors;
1121 }
1122
1123 $sql = 'UPDATE ' . FORUMS_TABLE . '
1124 SET left_id = left_id + 2, right_id = right_id + 2
1125 WHERE left_id > ' . $row['right_id'];
1126 $db->sql_query($sql);
1127
1128 $sql = 'UPDATE ' . FORUMS_TABLE . '
1129 SET right_id = right_id + 2
1130 WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
1131 $db->sql_query($sql);
1132
1133 $forum_data_sql['left_id'] = $row['right_id'];
1134 $forum_data_sql['right_id'] = $row['right_id'] + 1;
1135 }
1136 else
1137 {
1138 $sql = 'SELECT MAX(right_id) AS right_id
1139 FROM ' . FORUMS_TABLE;
1140 $result = $db->sql_query($sql);
1141 $row = $db->sql_fetchrow($result);
1142 $db->sql_freeresult($result);
1143
1144 $forum_data_sql['left_id'] = $row['right_id'] + 1;
1145 $forum_data_sql['right_id'] = $row['right_id'] + 2;
1146 }
1147
1148 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
1149 $db->sql_query($sql);
1150
1151 $forum_data_ary['forum_id'] = $db->sql_nextid();
1152
1153 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_ADD', false, array($forum_data_ary['forum_name']));
1154 }
1155 else
1156 {
1157 $row = $this->get_forum_info($forum_data_sql['forum_id']);
1158
1159 if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
1160 {
1161 // Has subforums and want to change into a link?
1162 if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
1163 {
1164 $errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
1165 return $errors;
1166 }
1167
1168 // we're turning a postable forum into a non-postable forum
1169 if ($forum_data_sql['type_action'] == 'move')
1170 {
1171 $to_forum_id = $request->variable('to_forum_id', 0);
1172
1173 if ($to_forum_id)
1174 {
1175 $errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
1176 }
1177 else
1178 {
1179 return array($user->lang['NO_DESTINATION_FORUM']);
1180 }
1181 }
1182 else if ($forum_data_sql['type_action'] == 'delete')
1183 {
1184 $errors = $this->delete_forum_content($forum_data_sql['forum_id']);
1185 }
1186 else
1187 {
1188 return array($user->lang['NO_FORUM_ACTION']);
1189 }
1190
1191 $forum_data_sql['forum_posts_approved'] = $forum_data_sql['forum_posts_unapproved'] = $forum_data_sql['forum_posts_softdeleted'] = $forum_data_sql['forum_topics_approved'] = $forum_data_sql['forum_topics_unapproved'] = $forum_data_sql['forum_topics_softdeleted'] = 0;
1192 $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0;
1193 $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
1194 }
1195 else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
1196 {
1197 // Has subforums?
1198 if ($row['right_id'] - $row['left_id'] > 1)
1199 {
1200 // We are turning a category into a link - but need to decide what to do with the subforums.
1201 $action_subforums = $request->variable('action_subforums', '');
1202 $subforums_to_id = $request->variable('subforums_to_id', 0);
1203
1204 if ($action_subforums == 'delete')
1205 {
1206 $rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
1207
1208 foreach ($rows as $_row)
1209 {
1210 // Do not remove the forum id we are about to change. ;)
1211 if ($_row['forum_id'] == $row['forum_id'])
1212 {
1213 continue;
1214 }
1215
1216 $forum_ids[] = $_row['forum_id'];
1217 $errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
1218 }
1219
1220 if (sizeof($errors))
1221 {
1222 return $errors;
1223 }
1224
1225 if (sizeof($forum_ids))
1226 {
1227 $sql = 'DELETE FROM ' . FORUMS_TABLE . '
1228 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1229 $db->sql_query($sql);
1230
1231 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
1232 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1233 $db->sql_query($sql);
1234
1235 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
1236 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1237 $db->sql_query($sql);
1238
1239 // Delete forum ids from extension groups table
1240 $sql = 'SELECT group_id, allowed_forums
1241 FROM ' . EXTENSION_GROUPS_TABLE;
1242 $result = $db->sql_query($sql);
1243
1244 while ($_row = $db->sql_fetchrow($result))
1245 {
1246 if (!$_row['allowed_forums'])
1247 {
1248 continue;
1249 }
1250
1251 $allowed_forums = unserialize(trim($_row['allowed_forums']));
1252 $allowed_forums = array_diff($allowed_forums, $forum_ids);
1253
1254 $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
1255 SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
1256 WHERE group_id = {$_row['group_id']}";
1257 $db->sql_query($sql);
1258 }
1259 $db->sql_freeresult($result);
1260
1261 $cache->destroy('_extensions');
1262 }
1263 }
1264 else if ($action_subforums == 'move')
1265 {
1266 if (!$subforums_to_id)
1267 {
1268 return array($user->lang['NO_DESTINATION_FORUM']);
1269 }
1270
1271 $sql = 'SELECT forum_name
1272 FROM ' . FORUMS_TABLE . '
1273 WHERE forum_id = ' . $subforums_to_id;
1274 $result = $db->sql_query($sql);
1275 $_row = $db->sql_fetchrow($result);
1276 $db->sql_freeresult($result);
1277
1278 if (!$_row)
1279 {
1280 return array($user->lang['NO_FORUM']);
1281 }
1282
1283 $sql = 'SELECT forum_id
1284 FROM ' . FORUMS_TABLE . "
1285 WHERE parent_id = {$row['forum_id']}";
1286 $result = $db->sql_query($sql);
1287
1288 while ($_row = $db->sql_fetchrow($result))
1289 {
1290 $this->move_forum($_row['forum_id'], $subforums_to_id);
1291 }
1292 $db->sql_freeresult($result);
1293
1294 $sql = 'UPDATE ' . FORUMS_TABLE . "
1295 SET parent_id = $subforums_to_id
1296 WHERE parent_id = {$row['forum_id']}";
1297 $db->sql_query($sql);
1298 }
1299
1300 // Adjust the left/right id
1301 $sql = 'UPDATE ' . FORUMS_TABLE . '
1302 SET right_id = left_id + 1
1303 WHERE forum_id = ' . $row['forum_id'];
1304 $db->sql_query($sql);
1305 }
1306 }
1307 else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
1308 {
1309 // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
1310 $forum_data_sql['forum_posts_approved'] = 0;
1311 $forum_data_sql['forum_posts_unapproved'] = 0;
1312 $forum_data_sql['forum_posts_softdeleted'] = 0;
1313 $forum_data_sql['forum_topics_approved'] = 0;
1314 $forum_data_sql['forum_topics_unapproved'] = 0;
1315 $forum_data_sql['forum_topics_softdeleted'] = 0;
1316 $forum_data_sql['forum_last_post_id'] = 0;
1317 $forum_data_sql['forum_last_post_subject'] = '';
1318 $forum_data_sql['forum_last_post_time'] = 0;
1319 $forum_data_sql['forum_last_poster_id'] = 0;
1320 $forum_data_sql['forum_last_poster_name'] = '';
1321 $forum_data_sql['forum_last_poster_colour'] = '';
1322 }
1323
1324 if (sizeof($errors))
1325 {
1326 return $errors;
1327 }
1328
1329 if ($row['parent_id'] != $forum_data_sql['parent_id'])
1330 {
1331 if ($row['forum_id'] != $forum_data_sql['parent_id'])
1332 {
1333 $errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
1334 }
1335 else
1336 {
1337 $forum_data_sql['parent_id'] = $row['parent_id'];
1338 }
1339 }
1340
1341 if (sizeof($errors))
1342 {
1343 return $errors;
1344 }
1345
1346 unset($forum_data_sql['type_action']);
1347
1348 if ($row['forum_name'] != $forum_data_sql['forum_name'])
1349 {
1350 // the forum name has changed, clear the parents list of all forums (for safety)
1351 $sql = 'UPDATE ' . FORUMS_TABLE . "
1352 SET forum_parents = ''";
1353 $db->sql_query($sql);
1354 }
1355
1356 // Setting the forum id to the forum id is not really received well by some dbs. ;)
1357 $forum_id = $forum_data_sql['forum_id'];
1358 unset($forum_data_sql['forum_id']);
1359
1360 $sql = 'UPDATE ' . FORUMS_TABLE . '
1361 SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
1362 WHERE forum_id = ' . $forum_id;
1363 $db->sql_query($sql);
1364
1365 // Add it back
1366 $forum_data_ary['forum_id'] = $forum_id;
1367
1368 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_EDIT', false, array($forum_data_ary['forum_name']));
1369 }
1370
1371 $forum_data = $forum_data_ary;
1372 /**
1373 * Event after a forum was updated or created
1374 *
1375 * @event core.acp_manage_forums_update_data_after
1376 * @var array forum_data Array with forum data
1377 * @var array forum_data_sql Array with data we updated
1378 * @var bool is_new_forum Did we create a forum or update one
1379 * If you want to overwrite this value,
1380 * ensure to set forum_data_sql[forum_id]
1381 * @var array errors Array of errors, should be strings and not
1382 * language key.
1383 * @since 3.1.0-a1
1384 */
1385 $vars = array('forum_data', 'forum_data_sql', 'is_new_forum', 'errors');
1386 extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_after', compact($vars)));
1387 $forum_data_ary = $forum_data;
1388 unset($forum_data);
1389
1390 return $errors;
1391 }
1392
1393 /**
1394 * Move forum
1395 */
1396 function move_forum($from_id, $to_id)
1397 {
1398 global $db, $user, $phpbb_dispatcher;
1399
1400 $errors = array();
1401
1402 // Check if we want to move to a parent with link type
1403 if ($to_id > 0)
1404 {
1405 $to_data = $this->get_forum_info($to_id);
1406
1407 if ($to_data['forum_type'] == FORUM_LINK)
1408 {
1409 $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
1410 }
1411 }
1412
1413 /**
1414 * Event when we move all children of one forum to another
1415 *
1416 * This event may be triggered, when a forum is deleted
1417 *
1418 * @event core.acp_manage_forums_move_children
1419 * @var int from_id If of the current parent forum
1420 * @var int to_id If of the new parent forum
1421 * @var array errors Array of errors, should be strings and not
1422 * language key.
1423 * @since 3.1.0-a1
1424 */
1425 $vars = array('from_id', 'to_id', 'errors');
1426 extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_children', compact($vars)));
1427
1428 // Return if there were errors
1429 if (!empty($errors))
1430 {
1431 return $errors;
1432 }
1433
1434 $moved_forums = get_forum_branch($from_id, 'children', 'descending');
1435 $from_data = $moved_forums[0];
1436 $diff = sizeof($moved_forums) * 2;
1437
1438 $moved_ids = array();
1439 for ($i = 0, $size = sizeof($moved_forums); $i < $size; ++$i)
1440 {
1441 $moved_ids[] = $moved_forums[$i]['forum_id'];
1442 }
1443
1444 // Resync parents
1445 $sql = 'UPDATE ' . FORUMS_TABLE . "
1446 SET right_id = right_id - $diff, forum_parents = ''
1447 WHERE left_id < " . $from_data['right_id'] . "
1448 AND right_id > " . $from_data['right_id'];
1449 $db->sql_query($sql);
1450
1451 // Resync righthand side of tree
1452 $sql = 'UPDATE ' . FORUMS_TABLE . "
1453 SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
1454 WHERE left_id > " . $from_data['right_id'];
1455 $db->sql_query($sql);
1456
1457 if ($to_id > 0)
1458 {
1459 // Retrieve $to_data again, it may have been changed...
1460 $to_data = $this->get_forum_info($to_id);
1461
1462 // Resync new parents
1463 $sql = 'UPDATE ' . FORUMS_TABLE . "
1464 SET right_id = right_id + $diff, forum_parents = ''
1465 WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
1466 AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
1467 $db->sql_query($sql);
1468
1469 // Resync the righthand side of the tree
1470 $sql = 'UPDATE ' . FORUMS_TABLE . "
1471 SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
1472 WHERE left_id > " . $to_data['right_id'] . '
1473 AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
1474 $db->sql_query($sql);
1475
1476 // Resync moved branch
1477 $to_data['right_id'] += $diff;
1478
1479 if ($to_data['right_id'] > $from_data['right_id'])
1480 {
1481 $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
1482 }
1483 else
1484 {
1485 $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
1486 }
1487 }
1488 else
1489 {
1490 $sql = 'SELECT MAX(right_id) AS right_id
1491 FROM ' . FORUMS_TABLE . '
1492 WHERE ' . $db->sql_in_set('forum_id', $moved_ids, true);
1493 $result = $db->sql_query($sql);
1494 $row = $db->sql_fetchrow($result);
1495 $db->sql_freeresult($result);
1496
1497 $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
1498 }
1499
1500 $sql = 'UPDATE ' . FORUMS_TABLE . "
1501 SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
1502 WHERE " . $db->sql_in_set('forum_id', $moved_ids);
1503 $db->sql_query($sql);
1504
1505 return $errors;
1506 }
1507
1508 /**
1509 * Move forum content from one to another forum
1510 */
1511 function move_forum_content($from_id, $to_id, $sync = true)
1512 {
1513 global $db, $phpbb_dispatcher;
1514
1515 $errors = array();
1516
1517 /**
1518 * Event when we move content from one forum to another
1519 *
1520 * @event core.acp_manage_forums_move_content
1521 * @var int from_id If of the current parent forum
1522 * @var int to_id If of the new parent forum
1523 * @var bool sync Shall we sync the "to"-forum's data
1524 * @var array errors Array of errors, should be strings and not
1525 * language key. If this array is not empty,
1526 * The content will not be moved.
1527 * @since 3.1.0-a1
1528 */
1529 $vars = array('from_id', 'to_id', 'sync', 'errors');
1530 extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_content', compact($vars)));
1531
1532 // Return if there were errors
1533 if (!empty($errors))
1534 {
1535 return $errors;
1536 }
1537
1538 $table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
1539
1540 foreach ($table_ary as $table)
1541 {
1542 $sql = "UPDATE $table
1543 SET forum_id = $to_id
1544 WHERE forum_id = $from_id";
1545 $db->sql_query($sql);
1546 }
1547 unset($table_ary);
1548
1549 $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
1550
1551 foreach ($table_ary as $table)
1552 {
1553 $sql = "DELETE FROM $table
1554 WHERE forum_id = $from_id";
1555 $db->sql_query($sql);
1556 }
1557
1558 if ($sync)
1559 {
1560 // Delete ghost topics that link back to the same forum then resync counters
1561 sync('topic_moved');
1562 sync('forum', 'forum_id', $to_id, false, true);
1563 }
1564
1565 return array();
1566 }
1567
1568 /**
1569 * Remove complete forum
1570 */
1571 function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
1572 {
1573 global $db, $user, $cache, $phpbb_log;
1574
1575 $forum_data = $this->get_forum_info($forum_id);
1576
1577 $errors = array();
1578 $log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = '';
1579 $forum_ids = array($forum_id);
1580
1581 if ($action_posts == 'delete')
1582 {
1583 $log_action_posts = 'POSTS';
1584 $errors = array_merge($errors, $this->delete_forum_content($forum_id));
1585 }
1586 else if ($action_posts == 'move')
1587 {
1588 if (!$posts_to_id)
1589 {
1590 $errors[] = $user->lang['NO_DESTINATION_FORUM'];
1591 }
1592 else
1593 {
1594 $log_action_posts = 'MOVE_POSTS';
1595
1596 $sql = 'SELECT forum_name
1597 FROM ' . FORUMS_TABLE . '
1598 WHERE forum_id = ' . $posts_to_id;
1599 $result = $db->sql_query($sql);
1600 $row = $db->sql_fetchrow($result);
1601 $db->sql_freeresult($result);
1602
1603 if (!$row)
1604 {
1605 $errors[] = $user->lang['NO_FORUM'];
1606 }
1607 else
1608 {
1609 $posts_to_name = $row['forum_name'];
1610 $errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id));
1611 }
1612 }
1613 }
1614
1615 if (sizeof($errors))
1616 {
1617 return $errors;
1618 }
1619
1620 if ($action_subforums == 'delete')
1621 {
1622 $log_action_forums = 'FORUMS';
1623 $rows = get_forum_branch($forum_id, 'children', 'descending', false);
1624
1625 foreach ($rows as $row)
1626 {
1627 $forum_ids[] = $row['forum_id'];
1628 $errors = array_merge($errors, $this->delete_forum_content($row['forum_id']));
1629 }
1630
1631 if (sizeof($errors))
1632 {
1633 return $errors;
1634 }
1635
1636 $diff = sizeof($forum_ids) * 2;
1637
1638 $sql = 'DELETE FROM ' . FORUMS_TABLE . '
1639 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1640 $db->sql_query($sql);
1641
1642 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
1643 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1644 $db->sql_query($sql);
1645
1646 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
1647 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1648 $db->sql_query($sql);
1649 }
1650 else if ($action_subforums == 'move')
1651 {
1652 if (!$subforums_to_id)
1653 {
1654 $errors[] = $user->lang['NO_DESTINATION_FORUM'];
1655 }
1656 else
1657 {
1658 $log_action_forums = 'MOVE_FORUMS';
1659
1660 $sql = 'SELECT forum_name
1661 FROM ' . FORUMS_TABLE . '
1662 WHERE forum_id = ' . $subforums_to_id;
1663 $result = $db->sql_query($sql);
1664 $row = $db->sql_fetchrow($result);
1665 $db->sql_freeresult($result);
1666
1667 if (!$row)
1668 {
1669 $errors[] = $user->lang['NO_FORUM'];
1670 }
1671 else
1672 {
1673 $subforums_to_name = $row['forum_name'];
1674
1675 $sql = 'SELECT forum_id
1676 FROM ' . FORUMS_TABLE . "
1677 WHERE parent_id = $forum_id";
1678 $result = $db->sql_query($sql);
1679
1680 while ($row = $db->sql_fetchrow($result))
1681 {
1682 $this->move_forum($row['forum_id'], $subforums_to_id);
1683 }
1684 $db->sql_freeresult($result);
1685
1686 // Grab new forum data for correct tree updating later
1687 $forum_data = $this->get_forum_info($forum_id);
1688
1689 $sql = 'UPDATE ' . FORUMS_TABLE . "
1690 SET parent_id = $subforums_to_id
1691 WHERE parent_id = $forum_id";
1692 $db->sql_query($sql);
1693
1694 $diff = 2;
1695 $sql = 'DELETE FROM ' . FORUMS_TABLE . "
1696 WHERE forum_id = $forum_id";
1697 $db->sql_query($sql);
1698
1699 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
1700 WHERE forum_id = $forum_id";
1701 $db->sql_query($sql);
1702
1703 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
1704 WHERE forum_id = $forum_id";
1705 $db->sql_query($sql);
1706 }
1707 }
1708
1709 if (sizeof($errors))
1710 {
1711 return $errors;
1712 }
1713 }
1714 else
1715 {
1716 $diff = 2;
1717 $sql = 'DELETE FROM ' . FORUMS_TABLE . "
1718 WHERE forum_id = $forum_id";
1719 $db->sql_query($sql);
1720
1721 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
1722 WHERE forum_id = $forum_id";
1723 $db->sql_query($sql);
1724
1725 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
1726 WHERE forum_id = $forum_id";
1727 $db->sql_query($sql);
1728 }
1729
1730 // Resync tree
1731 $sql = 'UPDATE ' . FORUMS_TABLE . "
1732 SET right_id = right_id - $diff
1733 WHERE left_id < {$forum_data['right_id']} AND right_id > {$forum_data['right_id']}";
1734 $db->sql_query($sql);
1735
1736 $sql = 'UPDATE ' . FORUMS_TABLE . "
1737 SET left_id = left_id - $diff, right_id = right_id - $diff
1738 WHERE left_id > {$forum_data['right_id']}";
1739 $db->sql_query($sql);
1740
1741 // Delete forum ids from extension groups table
1742 $sql = 'SELECT group_id, allowed_forums
1743 FROM ' . EXTENSION_GROUPS_TABLE;
1744 $result = $db->sql_query($sql);
1745
1746 while ($row = $db->sql_fetchrow($result))
1747 {
1748 if (!$row['allowed_forums'])
1749 {
1750 continue;
1751 }
1752
1753 $allowed_forums = unserialize(trim($row['allowed_forums']));
1754 $allowed_forums = array_diff($allowed_forums, $forum_ids);
1755
1756 $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
1757 SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
1758 WHERE group_id = {$row['group_id']}";
1759 $db->sql_query($sql);
1760 }
1761 $db->sql_freeresult($result);
1762
1763 $cache->destroy('_extensions');
1764
1765 $log_action = implode('_', array($log_action_posts, $log_action_forums));
1766
1767 switch ($log_action)
1768 {
1769 case 'MOVE_POSTS_MOVE_FORUMS':
1770 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', false, array($posts_to_name, $subforums_to_name, $forum_data['forum_name']));
1771 break;
1772
1773 case 'MOVE_POSTS_FORUMS':
1774 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', false, array($posts_to_name, $forum_data['forum_name']));
1775 break;
1776
1777 case 'POSTS_MOVE_FORUMS':
1778 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS', false, array($subforums_to_name, $forum_data['forum_name']));
1779 break;
1780
1781 case '_MOVE_FORUMS':
1782 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_DEL_MOVE_FORUMS', false, array($subforums_to_name, $forum_data['forum_name']));
1783 break;
1784
1785 case 'MOVE_POSTS_':
1786 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_DEL_MOVE_POSTS', false, array($posts_to_name, $forum_data['forum_name']));
1787 break;
1788
1789 case 'POSTS_FORUMS':
1790 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_DEL_POSTS_FORUMS', false, array($forum_data['forum_name']));
1791 break;
1792
1793 case '_FORUMS':
1794 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_DEL_FORUMS', false, array($forum_data['forum_name']));
1795 break;
1796
1797 case 'POSTS_':
1798 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_DEL_POSTS', false, array($forum_data['forum_name']));
1799 break;
1800
1801 default:
1802 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_DEL_FORUM', false, array($forum_data['forum_name']));
1803 break;
1804 }
1805
1806 return $errors;
1807 }
1808
1809 /**
1810 * Delete forum content
1811 */
1812 function delete_forum_content($forum_id)
1813 {
1814 global $db, $config, $phpbb_root_path, $phpEx, $phpbb_container, $phpbb_dispatcher;
1815
1816 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
1817
1818 $db->sql_transaction('begin');
1819
1820 // Select then delete all attachments
1821 $sql = 'SELECT a.topic_id
1822 FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
1823 WHERE p.forum_id = $forum_id
1824 AND a.in_message = 0
1825 AND a.topic_id = p.topic_id";
1826 $result = $db->sql_query($sql);
1827
1828 $topic_ids = array();
1829 while ($row = $db->sql_fetchrow($result))
1830 {
1831 $topic_ids[] = $row['topic_id'];
1832 }
1833 $db->sql_freeresult($result);
1834
1835 /** @var \phpbb\attachment\manager $attachment_manager */
1836 $attachment_manager = $phpbb_container->get('attachment.manager');
1837 $attachment_manager->delete('topic', $topic_ids, false);
1838 unset($attachment_manager);
1839
1840 // Delete shadow topics pointing to topics in this forum
1841 delete_topic_shadows($forum_id);
1842
1843 // Before we remove anything we make sure we are able to adjust the post counts later. ;)
1844 $sql = 'SELECT poster_id
1845 FROM ' . POSTS_TABLE . '
1846 WHERE forum_id = ' . $forum_id . '
1847 AND post_postcount = 1
1848 AND post_visibility = ' . ITEM_APPROVED;
1849 $result = $db->sql_query($sql);
1850
1851 $post_counts = array();
1852 while ($row = $db->sql_fetchrow($result))
1853 {
1854 $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1;
1855 }
1856 $db->sql_freeresult($result);
1857
1858 switch ($db->get_sql_layer())
1859 {
1860 case 'mysql4':
1861 case 'mysqli':
1862
1863 // Delete everything else and thank MySQL for offering multi-table deletion
1864 $tables_ary = array(
1865 SEARCH_WORDMATCH_TABLE => 'post_id',
1866 REPORTS_TABLE => 'post_id',
1867 WARNINGS_TABLE => 'post_id',
1868 BOOKMARKS_TABLE => 'topic_id',
1869 TOPICS_WATCH_TABLE => 'topic_id',
1870 TOPICS_POSTED_TABLE => 'topic_id',
1871 POLL_OPTIONS_TABLE => 'topic_id',
1872 POLL_VOTES_TABLE => 'topic_id',
1873 );
1874
1875 $sql = 'DELETE ' . POSTS_TABLE;
1876 $sql_using = "\nFROM " . POSTS_TABLE;
1877 $sql_where = "\nWHERE " . POSTS_TABLE . ".forum_id = $forum_id\n";
1878
1879 foreach ($tables_ary as $table => $field)
1880 {
1881 $sql .= ", $table ";
1882 $sql_using .= ", $table ";
1883 $sql_where .= "\nAND $table.$field = " . POSTS_TABLE . ".$field";
1884 }
1885
1886 $db->sql_query($sql . $sql_using . $sql_where);
1887
1888 break;
1889
1890 default:
1891
1892 // Delete everything else and curse your DB for not offering multi-table deletion
1893 $tables_ary = array(
1894 'post_id' => array(
1895 SEARCH_WORDMATCH_TABLE,
1896 REPORTS_TABLE,
1897 WARNINGS_TABLE,
1898 ),
1899
1900 'topic_id' => array(
1901 BOOKMARKS_TABLE,
1902 TOPICS_WATCH_TABLE,
1903 TOPICS_POSTED_TABLE,
1904 POLL_OPTIONS_TABLE,
1905 POLL_VOTES_TABLE,
1906 )
1907 );
1908
1909 // Amount of rows we select and delete in one iteration.
1910 $batch_size = 500;
1911
1912 foreach ($tables_ary as $field => $tables)
1913 {
1914 $start = 0;
1915
1916 do
1917 {
1918 $sql = "SELECT $field
1919 FROM " . POSTS_TABLE . '
1920 WHERE forum_id = ' . $forum_id;
1921 $result = $db->sql_query_limit($sql, $batch_size, $start);
1922
1923 $ids = array();
1924 while ($row = $db->sql_fetchrow($result))
1925 {
1926 $ids[] = $row[$field];
1927 }
1928 $db->sql_freeresult($result);
1929
1930 if (sizeof($ids))
1931 {
1932 $start += sizeof($ids);
1933
1934 foreach ($tables as $table)
1935 {
1936 $db->sql_query("DELETE FROM $table WHERE " . $db->sql_in_set($field, $ids));
1937 }
1938 }
1939 }
1940 while (sizeof($ids) == $batch_size);
1941 }
1942 unset($ids);
1943
1944 break;
1945 }
1946
1947 $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, LOG_TABLE, MODERATOR_CACHE_TABLE, POSTS_TABLE, TOPICS_TABLE, TOPICS_TRACK_TABLE);
1948
1949 /**
1950 * Perform additional actions before forum content deletion
1951 *
1952 * @event core.delete_forum_content_before_query
1953 * @var array table_ary Array of tables from which all rows will be deleted that hold the forum_id
1954 * @var int forum_id the forum id
1955 * @var array topic_ids Array of the topic ids from the forum to be deleted
1956 * @var array post_counts Array of counts of posts in the forum, by poster_id
1957 * @since 3.1.6-RC1
1958 */
1959 $vars = array(
1960 'table_ary',
1961 'forum_id',
1962 'topic_ids',
1963 'post_counts',
1964 );
1965 extract($phpbb_dispatcher->trigger_event('core.delete_forum_content_before_query', compact($vars)));
1966
1967 foreach ($table_ary as $table)
1968 {
1969 $db->sql_query("DELETE FROM $table WHERE forum_id = $forum_id");
1970 }
1971
1972 // Set forum ids to 0
1973 $table_ary = array(DRAFTS_TABLE);
1974
1975 foreach ($table_ary as $table)
1976 {
1977 $db->sql_query("UPDATE $table SET forum_id = 0 WHERE forum_id = $forum_id");
1978 }
1979
1980 // Adjust users post counts
1981 if (sizeof($post_counts))
1982 {
1983 foreach ($post_counts as $poster_id => $substract)
1984 {
1985 $sql = 'UPDATE ' . USERS_TABLE . '
1986 SET user_posts = 0
1987 WHERE user_id = ' . $poster_id . '
1988 AND user_posts < ' . $substract;
1989 $db->sql_query($sql);
1990
1991 $sql = 'UPDATE ' . USERS_TABLE . '
1992 SET user_posts = user_posts - ' . $substract . '
1993 WHERE user_id = ' . $poster_id . '
1994 AND user_posts >= ' . $substract;
1995 $db->sql_query($sql);
1996 }
1997 }
1998
1999 $db->sql_transaction('commit');
2000
2001 // Make sure the overall post/topic count is correct...
2002 $sql = 'SELECT COUNT(post_id) AS stat
2003 FROM ' . POSTS_TABLE . '
2004 WHERE post_visibility = ' . ITEM_APPROVED;
2005 $result = $db->sql_query($sql);
2006 $row = $db->sql_fetchrow($result);
2007 $db->sql_freeresult($result);
2008
2009 $config->set('num_posts', (int) $row['stat'], false);
2010
2011 $sql = 'SELECT COUNT(topic_id) AS stat
2012 FROM ' . TOPICS_TABLE . '
2013 WHERE topic_visibility = ' . ITEM_APPROVED;
2014 $result = $db->sql_query($sql);
2015 $row = $db->sql_fetchrow($result);
2016 $db->sql_freeresult($result);
2017
2018 $config->set('num_topics', (int) $row['stat'], false);
2019
2020 $sql = 'SELECT COUNT(attach_id) as stat
2021 FROM ' . ATTACHMENTS_TABLE;
2022 $result = $db->sql_query($sql);
2023 $row = $db->sql_fetchrow($result);
2024 $db->sql_freeresult($result);
2025
2026 $config->set('num_files', (int) $row['stat'], false);
2027
2028 $sql = 'SELECT SUM(filesize) as stat
2029 FROM ' . ATTACHMENTS_TABLE;
2030 $result = $db->sql_query($sql);
2031 $row = $db->sql_fetchrow($result);
2032 $db->sql_freeresult($result);
2033
2034 $config->set('upload_dir_size', (float) $row['stat'], false);
2035
2036 return array();
2037 }
2038
2039 /**
2040 * Move forum position by $steps up/down
2041 */
2042 function move_forum_by($forum_row, $action = 'move_up', $steps = 1)
2043 {
2044 global $db;
2045
2046 /**
2047 * Fetch all the siblings between the module's current spot
2048 * and where we want to move it to. If there are less than $steps
2049 * siblings between the current spot and the target then the
2050 * module will move as far as possible
2051 */
2052 $sql = 'SELECT forum_id, forum_name, left_id, right_id
2053 FROM ' . FORUMS_TABLE . "
2054 WHERE parent_id = {$forum_row['parent_id']}
2055 AND " . (($action == 'move_up') ? "right_id < {$forum_row['right_id']} ORDER BY right_id DESC" : "left_id > {$forum_row['left_id']} ORDER BY left_id ASC");
2056 $result = $db->sql_query_limit($sql, $steps);
2057
2058 $target = array();
2059 while ($row = $db->sql_fetchrow($result))
2060 {
2061 $target = $row;
2062 }
2063 $db->sql_freeresult($result);
2064
2065 if (!sizeof($target))
2066 {
2067 // The forum is already on top or bottom
2068 return false;
2069 }
2070
2071 /**
2072 * $left_id and $right_id define the scope of the nodes that are affected by the move.
2073 * $diff_up and $diff_down are the values to substract or add to each node's left_id
2074 * and right_id in order to move them up or down.
2075 * $move_up_left and $move_up_right define the scope of the nodes that are moving
2076 * up. Other nodes in the scope of ($left_id, $right_id) are considered to move down.
2077 */
2078 if ($action == 'move_up')
2079 {
2080 $left_id = $target['left_id'];
2081 $right_id = $forum_row['right_id'];
2082
2083 $diff_up = $forum_row['left_id'] - $target['left_id'];
2084 $diff_down = $forum_row['right_id'] + 1 - $forum_row['left_id'];
2085
2086 $move_up_left = $forum_row['left_id'];
2087 $move_up_right = $forum_row['right_id'];
2088 }
2089 else
2090 {
2091 $left_id = $forum_row['left_id'];
2092 $right_id = $target['right_id'];
2093
2094 $diff_up = $forum_row['right_id'] + 1 - $forum_row['left_id'];
2095 $diff_down = $target['right_id'] - $forum_row['right_id'];
2096
2097 $move_up_left = $forum_row['right_id'] + 1;
2098 $move_up_right = $target['right_id'];
2099 }
2100
2101 // Now do the dirty job
2102 $sql = 'UPDATE ' . FORUMS_TABLE . "
2103 SET left_id = left_id + CASE
2104 WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
2105 ELSE {$diff_down}
2106 END,
2107 right_id = right_id + CASE
2108 WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
2109 ELSE {$diff_down}
2110 END,
2111 forum_parents = ''
2112 WHERE
2113 left_id BETWEEN {$left_id} AND {$right_id}
2114 AND right_id BETWEEN {$left_id} AND {$right_id}";
2115 $db->sql_query($sql);
2116
2117 return $target['forum_name'];
2118 }
2119
2120 /**
2121 * Display progress bar for syncinc forums
2122 */
2123 function display_progress_bar($start, $total)
2124 {
2125 global $template, $user;
2126
2127 adm_page_header($user->lang['SYNC_IN_PROGRESS']);
2128
2129 $template->set_filenames(array(
2130 'body' => 'progress_bar.html')
2131 );
2132
2133 $template->assign_vars(array(
2134 'L_PROGRESS' => $user->lang['SYNC_IN_PROGRESS'],
2135 'L_PROGRESS_EXPLAIN' => ($start && $total) ? sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $start, $total) : $user->lang['SYNC_IN_PROGRESS'])
2136 );
2137
2138 adm_page_footer();
2139 }
2140
2141 /**
2142 * Display copy permission page
2143 * Not used at the moment - we will have a look at it for 3.0.7
2144 */
2145 function copy_permission_page($forum_data)
2146 {
2147 global $phpEx, $phpbb_admin_path, $template, $user;
2148
2149 $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
2150 $action = append_sid($this->u_action . "&parent_id={$this->parent_id}&f={$forum_data['forum_id']}&action=copy_perm");
2151
2152 $l_acl = sprintf($user->lang['COPY_TO_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
2153
2154 $this->tpl_name = 'acp_forums_copy_perm';
2155
2156 $template->assign_vars(array(
2157 'U_ACL' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url),
2158 'L_ACL_LINK' => $l_acl,
2159 'L_BACK_LINK' => adm_back_link($this->u_action . '&parent_id=' . $this->parent_id),
2160 'S_COPY_ACTION' => $action,
2161 'S_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_data['forum_id'], false, false, false),
2162 ));
2163 }
2164
2165 }
2166