|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @package acp
|
|
|
4c79b5 |
* @version $Id: acp_forums.php 8898 2008-09-19 17:07:13Z acydburn $
|
|
|
4c79b5 |
* @copyright (c) 2005 phpBB Group
|
|
|
4c79b5 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* @ignore
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
if (!defined('IN_PHPBB'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* @package acp
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
class acp_forums
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var $u_action;
|
|
|
4c79b5 |
var $parent_id = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function main($id, $mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user, $auth, $template, $cache;
|
|
|
4c79b5 |
global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$user->add_lang('acp/forums');
|
|
|
4c79b5 |
$this->tpl_name = 'acp_forums';
|
|
|
4c79b5 |
$this->page_title = 'ACP_MANAGE_FORUMS';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$form_key = 'acp_forums';
|
|
|
4c79b5 |
add_form_key($form_key);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$action = request_var('action', '');
|
|
|
4c79b5 |
$update = (isset($_POST['update'])) ? true : false;
|
|
|
4c79b5 |
$forum_id = request_var('f', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->parent_id = request_var('parent_id', 0);
|
|
|
4c79b5 |
$forum_data = $errors = array();
|
|
|
4c79b5 |
if ($update && !check_form_key($form_key))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$update = false;
|
|
|
4c79b5 |
$errors[] = $user->lang['FORM_INVALID'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check additional permissions
|
|
|
4c79b5 |
switch ($action)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'progress_bar':
|
|
|
4c79b5 |
$start = request_var('start', 0);
|
|
|
4c79b5 |
$total = request_var('total', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->display_progress_bar($start, $total);
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'delete':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$auth->acl_get('a_forumdel'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'add':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$auth->acl_get('a_forumadd'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Major routines
|
|
|
4c79b5 |
if ($update)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($action)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'delete':
|
|
|
4c79b5 |
$action_subforums = request_var('action_subforums', '');
|
|
|
4c79b5 |
$subforums_to_id = request_var('subforums_to_id', 0);
|
|
|
4c79b5 |
$action_posts = request_var('action_posts', '');
|
|
|
4c79b5 |
$posts_to_id = request_var('posts_to_id', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($errors))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$auth->acl_clear_prefetch();
|
|
|
4c79b5 |
$cache->destroy('sql', FORUMS_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'edit':
|
|
|
4c79b5 |
$forum_data = array(
|
|
|
4c79b5 |
'forum_id' => $forum_id
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// No break here
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'add':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_data += array(
|
|
|
4c79b5 |
'parent_id' => request_var('forum_parent_id', $this->parent_id),
|
|
|
4c79b5 |
'forum_type' => request_var('forum_type', FORUM_POST),
|
|
|
4c79b5 |
'type_action' => request_var('type_action', ''),
|
|
|
4c79b5 |
'forum_status' => request_var('forum_status', ITEM_UNLOCKED),
|
|
|
4c79b5 |
'forum_parents' => '',
|
|
|
4c79b5 |
'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
|
|
|
4c79b5 |
'forum_link' => request_var('forum_link', ''),
|
|
|
4c79b5 |
'forum_link_track' => request_var('forum_link_track', false),
|
|
|
4c79b5 |
'forum_desc' => utf8_normalize_nfc(request_var('forum_desc', '', true)),
|
|
|
4c79b5 |
'forum_desc_uid' => '',
|
|
|
4c79b5 |
'forum_desc_options' => 7,
|
|
|
4c79b5 |
'forum_desc_bitfield' => '',
|
|
|
4c79b5 |
'forum_rules' => utf8_normalize_nfc(request_var('forum_rules', '', true)),
|
|
|
4c79b5 |
'forum_rules_uid' => '',
|
|
|
4c79b5 |
'forum_rules_options' => 7,
|
|
|
4c79b5 |
'forum_rules_bitfield' => '',
|
|
|
4c79b5 |
'forum_rules_link' => request_var('forum_rules_link', ''),
|
|
|
4c79b5 |
'forum_image' => request_var('forum_image', ''),
|
|
|
4c79b5 |
'forum_style' => request_var('forum_style', 0),
|
|
|
4c79b5 |
'display_subforum_list' => request_var('display_subforum_list', false),
|
|
|
4c79b5 |
'display_on_index' => request_var('display_on_index', false),
|
|
|
4c79b5 |
'forum_topics_per_page' => request_var('topics_per_page', 0),
|
|
|
4c79b5 |
'enable_indexing' => request_var('enable_indexing', true),
|
|
|
4c79b5 |
'enable_icons' => request_var('enable_icons', false),
|
|
|
4c79b5 |
'enable_prune' => request_var('enable_prune', false),
|
|
|
4c79b5 |
'enable_post_review' => request_var('enable_post_review', true),
|
|
|
4c79b5 |
'prune_days' => request_var('prune_days', 7),
|
|
|
4c79b5 |
'prune_viewed' => request_var('prune_viewed', 7),
|
|
|
4c79b5 |
'prune_freq' => request_var('prune_freq', 1),
|
|
|
4c79b5 |
'prune_old_polls' => request_var('prune_old_polls', false),
|
|
|
4c79b5 |
'prune_announce' => request_var('prune_announce', false),
|
|
|
4c79b5 |
'prune_sticky' => request_var('prune_sticky', false),
|
|
|
4c79b5 |
'forum_password' => request_var('forum_password', '', true),
|
|
|
4c79b5 |
'forum_password_confirm'=> request_var('forum_password_confirm', '', true),
|
|
|
4c79b5 |
'forum_password_unset' => request_var('forum_password_unset', false),
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Use link_display_on_index setting if forum type is link
|
|
|
4c79b5 |
if ($forum_data['forum_type'] == FORUM_LINK)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data['display_on_index'] = request_var('link_display_on_index', false);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Linked forums and categories are not able to be locked...
|
|
|
4c79b5 |
if ($forum_data['forum_type'] == FORUM_LINK || $forum_data['forum_type'] == FORUM_CAT)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data['forum_status'] = ITEM_UNLOCKED;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', false) : request_var('display_active', false);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Get data for forum rules if specified...
|
|
|
4c79b5 |
if ($forum_data['forum_rules'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_parse_bbcode', false), request_var('rules_parse_urls', false), request_var('rules_parse_smilies', false));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Get data for forum description if specified
|
|
|
4c79b5 |
if ($forum_data['forum_desc'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_parse_bbcode', false), request_var('desc_parse_urls', false), request_var('desc_parse_smilies', false));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$errors = $this->update_forum_data($forum_data);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($errors))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_perm_from = request_var('forum_perm_from', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Copy permissions?
|
|
|
4c79b5 |
if ($forum_perm_from && !empty($forum_perm_from) && $forum_perm_from != $forum_data['forum_id'] &&
|
|
|
4c79b5 |
(($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'))))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// if we edit a forum delete current permissions first
|
|
|
4c79b5 |
if ($action == 'edit')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . (int) $forum_data['forum_id'];
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . (int) $forum_data['forum_id'];
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// From the mysql documentation:
|
|
|
4c79b5 |
// Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
|
|
|
4c79b5 |
// Due to this we stay on the safe side if we do the insertion "the manual way"
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Copy permisisons from/to the acl users table (only forum_id gets changed)
|
|
|
4c79b5 |
$sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
|
|
|
4c79b5 |
FROM ' . ACL_USERS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $forum_perm_from;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$users_sql_ary = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$users_sql_ary[] = array(
|
|
|
4c79b5 |
'user_id' => (int) $row['user_id'],
|
|
|
4c79b5 |
'forum_id' => (int) $forum_data['forum_id'],
|
|
|
4c79b5 |
'auth_option_id' => (int) $row['auth_option_id'],
|
|
|
4c79b5 |
'auth_role_id' => (int) $row['auth_role_id'],
|
|
|
4c79b5 |
'auth_setting' => (int) $row['auth_setting']
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Copy permisisons from/to the acl groups table (only forum_id gets changed)
|
|
|
4c79b5 |
$sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
|
|
|
4c79b5 |
FROM ' . ACL_GROUPS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $forum_perm_from;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$groups_sql_ary = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$groups_sql_ary[] = array(
|
|
|
4c79b5 |
'group_id' => (int) $row['group_id'],
|
|
|
4c79b5 |
'forum_id' => (int) $forum_data['forum_id'],
|
|
|
4c79b5 |
'auth_option_id' => (int) $row['auth_option_id'],
|
|
|
4c79b5 |
'auth_role_id' => (int) $row['auth_role_id'],
|
|
|
4c79b5 |
'auth_setting' => (int) $row['auth_setting']
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Now insert the data
|
|
|
4c79b5 |
$db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
|
|
|
4c79b5 |
$db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
|
|
|
4c79b5 |
cache_moderators();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$auth->acl_clear_prefetch();
|
|
|
4c79b5 |
$cache->destroy('sql', FORUMS_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Redirect to permissions
|
|
|
4c79b5 |
if ($auth->acl_get('a_fauth'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$message .= '
' . sprintf($user->lang['REDIRECT_ACL'], '', '');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// redirect directly to permission settings screen if authed
|
|
|
4c79b5 |
if ($action == 'add' && !$forum_perm_from && $auth->acl_get('a_fauth'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($action)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'move_up':
|
|
|
4c79b5 |
case 'move_down':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$forum_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$move_forum_name = $this->move_forum_by($row, $action, 1);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($move_forum_name !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
|
|
|
4c79b5 |
$cache->destroy('sql', FORUMS_TABLE);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'sync':
|
|
|
4c79b5 |
if (!$forum_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
@set_time_limit(0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_name, forum_topics_real
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row['forum_topics_real'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
|
|
|
4c79b5 |
FROM ' . TOPICS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $forum_id;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row2 = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Typecast to int if there is no data available
|
|
|
4c79b5 |
$row2['min_topic_id'] = (int) $row2['min_topic_id'];
|
|
|
4c79b5 |
$row2['max_topic_id'] = (int) $row2['max_topic_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$start = request_var('start', $row2['min_topic_id']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$batch_size = 2000;
|
|
|
4c79b5 |
$end = $start + $batch_size;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Sync all topics in batch mode...
|
|
|
4c79b5 |
sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
|
|
|
4c79b5 |
sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($end < $row2['max_topic_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// We really need to find a way of showing statistics... no progress here
|
|
|
4c79b5 |
$sql = 'SELECT COUNT(topic_id) as num_topics
|
|
|
4c79b5 |
FROM ' . TOPICS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $forum_id . '
|
|
|
4c79b5 |
AND topic_id BETWEEN ' . $start . ' AND ' . $end;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$start += $batch_size;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync&start=$start&topics_done=$topics_done&total={$row['forum_topics_real']}";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
meta_refresh(0, $url);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}",
|
|
|
4c79b5 |
'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}"),
|
|
|
4c79b5 |
'S_CONTINUE_SYNC' => true,
|
|
|
4c79b5 |
'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real']))
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync_forum";
|
|
|
4c79b5 |
meta_refresh(0, $url);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
|
|
|
4c79b5 |
'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
|
|
|
4c79b5 |
'S_CONTINUE_SYNC' => true,
|
|
|
4c79b5 |
'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real']))
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'sync_forum':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_name, forum_type
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
sync('forum', 'forum_id', $forum_id, false, true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
|
|
|
4c79b5 |
$cache->destroy('sql', FORUMS_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'add':
|
|
|
4c79b5 |
case 'edit':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($update)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data['forum_flags'] = 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += (request_var('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += (request_var('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += (request_var('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += (request_var('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Show form to create/modify a forum
|
|
|
4c79b5 |
if ($action == 'edit')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->page_title = 'EDIT_FORUM';
|
|
|
4c79b5 |
$row = $this->get_forum_info($forum_id);
|
|
|
4c79b5 |
$old_forum_type = $row['forum_type'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$update)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data = $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data['left_id'] = $row['left_id'];
|
|
|
4c79b5 |
$forum_data['right_id'] = $row['right_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Make sure no direct child forums are able to be selected as parents.
|
|
|
4c79b5 |
$exclude_forums = array();
|
|
|
4c79b5 |
foreach (get_forum_branch($forum_id, 'children') as $row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$exclude_forums[] = $row['forum_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_data['forum_password_confirm'] = $forum_data['forum_password'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->page_title = 'CREATE_FORUM';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_id = $this->parent_id;
|
|
|
4c79b5 |
$parents_list = make_forum_select($this->parent_id, false, false, false, false);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Fill forum data with default values
|
|
|
4c79b5 |
if (!$update)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data = array(
|
|
|
4c79b5 |
'parent_id' => $this->parent_id,
|
|
|
4c79b5 |
'forum_type' => FORUM_POST,
|
|
|
4c79b5 |
'forum_status' => ITEM_UNLOCKED,
|
|
|
4c79b5 |
'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
|
|
|
4c79b5 |
'forum_link' => '',
|
|
|
4c79b5 |
'forum_link_track' => false,
|
|
|
4c79b5 |
'forum_desc' => '',
|
|
|
4c79b5 |
'forum_rules' => '',
|
|
|
4c79b5 |
'forum_rules_link' => '',
|
|
|
4c79b5 |
'forum_image' => '',
|
|
|
4c79b5 |
'forum_style' => 0,
|
|
|
4c79b5 |
'display_subforum_list' => true,
|
|
|
4c79b5 |
'display_on_index' => false,
|
|
|
4c79b5 |
'forum_topics_per_page' => 0,
|
|
|
4c79b5 |
'enable_indexing' => true,
|
|
|
4c79b5 |
'enable_icons' => false,
|
|
|
4c79b5 |
'enable_prune' => false,
|
|
|
4c79b5 |
'prune_days' => 7,
|
|
|
4c79b5 |
'prune_viewed' => 7,
|
|
|
4c79b5 |
'prune_freq' => 1,
|
|
|
4c79b5 |
'forum_flags' => FORUM_FLAG_POST_REVIEW,
|
|
|
4c79b5 |
'forum_password' => '',
|
|
|
4c79b5 |
'forum_password_confirm'=> '',
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_rules_data = array(
|
|
|
4c79b5 |
'text' => $forum_data['forum_rules'],
|
|
|
4c79b5 |
'allow_bbcode' => true,
|
|
|
4c79b5 |
'allow_smilies' => true,
|
|
|
4c79b5 |
'allow_urls' => true
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_desc_data = array(
|
|
|
4c79b5 |
'text' => $forum_data['forum_desc'],
|
|
|
4c79b5 |
'allow_bbcode' => true,
|
|
|
4c79b5 |
'allow_smilies' => true,
|
|
|
4c79b5 |
'allow_urls' => true
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_rules_preview = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Parse rules if specified
|
|
|
4c79b5 |
if ($forum_data['forum_rules'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!isset($forum_data['forum_rules_uid']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
|
|
|
4c79b5 |
$forum_data['forum_rules_uid'] = '';
|
|
|
4c79b5 |
$forum_data['forum_rules_bitfield'] = '';
|
|
|
4c79b5 |
$forum_data['forum_rules_options'] = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_allow_bbcode', false), request_var('rules_allow_urls', false), request_var('rules_allow_smilies', false));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Generate preview content
|
|
|
4c79b5 |
$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']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// decode...
|
|
|
4c79b5 |
$forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Parse desciption if specified
|
|
|
4c79b5 |
if ($forum_data['forum_desc'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!isset($forum_data['forum_desc_uid']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
|
|
|
4c79b5 |
$forum_data['forum_desc_uid'] = '';
|
|
|
4c79b5 |
$forum_data['forum_desc_bitfield'] = '';
|
|
|
4c79b5 |
$forum_data['forum_desc_options'] = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_allow_bbcode', false), request_var('desc_allow_urls', false), request_var('desc_allow_smilies', false));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// decode...
|
|
|
4c79b5 |
$forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_type_options = '';
|
|
|
4c79b5 |
$forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($forum_type_ary as $value => $lang)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$styles_list = style_select($forum_data['forum_style'], true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$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>';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_id
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_type = ' . FORUM_POST . "
|
|
|
4c79b5 |
AND forum_id <> $forum_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Subforum move options
|
|
|
4c79b5 |
if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$subforums_id = array();
|
|
|
4c79b5 |
$subforums = get_forum_branch($forum_id, 'children');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($subforums as $row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$subforums_id[] = $row['forum_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_id
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_type = ' . FORUM_POST . "
|
|
|
4c79b5 |
AND forum_id <> $forum_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
|
|
|
4c79b5 |
'S_FORUMS_LIST' => $forums_list)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$s_show_display_on_index = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($forum_data['parent_id'] > 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// if this forum is a subforum put the "display on index" checkbox
|
|
|
4c79b5 |
if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$s_show_display_on_index = true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (strlen($forum_data['forum_password']) == 32)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['FORUM_PASSWORD_OLD'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_EDIT_FORUM' => true,
|
|
|
4c79b5 |
'S_ERROR' => (sizeof($errors)) ? true : false,
|
|
|
4c79b5 |
'S_PARENT_ID' => $this->parent_id,
|
|
|
4c79b5 |
'S_FORUM_PARENT_ID' => $forum_data['parent_id'],
|
|
|
4c79b5 |
'S_ADD_ACTION' => ($action == 'add') ? true : false,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
|
|
|
4c79b5 |
'U_EDIT_ACTION' => $this->u_action . "&parent_id={$this->parent_id}&action=$action&f=$forum_id",
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
|
|
|
4c79b5 |
'L_TITLE' => $user->lang[$this->page_title],
|
|
|
4c79b5 |
'ERROR_MSG' => (sizeof($errors)) ? implode(' ', $errors) : '',
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'FORUM_NAME' => $forum_data['forum_name'],
|
|
|
4c79b5 |
'FORUM_DATA_LINK' => $forum_data['forum_link'],
|
|
|
4c79b5 |
'FORUM_IMAGE' => $forum_data['forum_image'],
|
|
|
4c79b5 |
'FORUM_IMAGE_SRC' => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
|
|
|
4c79b5 |
'FORUM_POST' => FORUM_POST,
|
|
|
4c79b5 |
'FORUM_LINK' => FORUM_LINK,
|
|
|
4c79b5 |
'FORUM_CAT' => FORUM_CAT,
|
|
|
4c79b5 |
'PRUNE_FREQ' => $forum_data['prune_freq'],
|
|
|
4c79b5 |
'PRUNE_DAYS' => $forum_data['prune_days'],
|
|
|
4c79b5 |
'PRUNE_VIEWED' => $forum_data['prune_viewed'],
|
|
|
4c79b5 |
'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'],
|
|
|
4c79b5 |
'FORUM_RULES_LINK' => $forum_data['forum_rules_link'],
|
|
|
4c79b5 |
'FORUM_RULES' => $forum_data['forum_rules'],
|
|
|
4c79b5 |
'FORUM_RULES_PREVIEW' => $forum_rules_preview,
|
|
|
4c79b5 |
'FORUM_RULES_PLAIN' => $forum_rules_data['text'],
|
|
|
4c79b5 |
'S_BBCODE_CHECKED' => ($forum_rules_data['allow_bbcode']) ? true : false,
|
|
|
4c79b5 |
'S_SMILIES_CHECKED' => ($forum_rules_data['allow_smilies']) ? true : false,
|
|
|
4c79b5 |
'S_URLS_CHECKED' => ($forum_rules_data['allow_urls']) ? true : false,
|
|
|
4c79b5 |
'S_FORUM_PASSWORD_SET' => (empty($forum_data['forum_password'])) ? false : true,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'FORUM_DESC' => $forum_desc_data['text'],
|
|
|
4c79b5 |
'S_DESC_BBCODE_CHECKED' => ($forum_desc_data['allow_bbcode']) ? true : false,
|
|
|
4c79b5 |
'S_DESC_SMILIES_CHECKED' => ($forum_desc_data['allow_smilies']) ? true : false,
|
|
|
4c79b5 |
'S_DESC_URLS_CHECKED' => ($forum_desc_data['allow_urls']) ? true : false,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'S_FORUM_TYPE_OPTIONS' => $forum_type_options,
|
|
|
4c79b5 |
'S_STATUS_OPTIONS' => $statuslist,
|
|
|
4c79b5 |
'S_PARENT_OPTIONS' => $parents_list,
|
|
|
4c79b5 |
'S_STYLES_OPTIONS' => $styles_list,
|
|
|
4c79b5 |
'S_FORUM_OPTIONS' => make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
|
|
|
4c79b5 |
'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index,
|
|
|
4c79b5 |
'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
|
|
|
4c79b5 |
'S_FORUM_ORIG_POST' => (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
|
|
|
4c79b5 |
'S_FORUM_ORIG_CAT' => (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
|
|
|
4c79b5 |
'S_FORUM_ORIG_LINK' => (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
|
|
|
4c79b5 |
'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
|
|
|
4c79b5 |
'S_FORUM_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
|
|
|
4c79b5 |
'S_ENABLE_INDEXING' => ($forum_data['enable_indexing']) ? true : false,
|
|
|
4c79b5 |
'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false,
|
|
|
4c79b5 |
'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false,
|
|
|
4c79b5 |
'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false,
|
|
|
4c79b5 |
'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false,
|
|
|
4c79b5 |
'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
|
|
|
4c79b5 |
'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
|
|
|
4c79b5 |
'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
|
|
|
4c79b5 |
'S_PRUNE_STICKY' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
|
|
|
4c79b5 |
'S_DISPLAY_ACTIVE_TOPICS' => ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) ? true : false,
|
|
|
4c79b5 |
'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
|
|
|
4c79b5 |
'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,
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'delete':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$forum_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_data = $this->get_forum_info($forum_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$subforums_id = array();
|
|
|
4c79b5 |
$subforums = get_forum_branch($forum_id, 'children');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($subforums as $row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$subforums_id[] = $row['forum_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_id
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_type = ' . FORUM_POST . "
|
|
|
4c79b5 |
AND forum_id <> $forum_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_DELETE_FORUM' => true,
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . "&parent_id={$parent_id}&action=delete&f=$forum_id",
|
|
|
4c79b5 |
'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'FORUM_NAME' => $forum_data['forum_name'],
|
|
|
4c79b5 |
'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
|
|
|
4c79b5 |
'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
|
|
|
4c79b5 |
'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
|
|
|
4c79b5 |
'S_FORUMS_LIST' => $forums_list,
|
|
|
4c79b5 |
'S_ERROR' => (sizeof($errors)) ? true : false,
|
|
|
4c79b5 |
'ERROR_MSG' => (sizeof($errors)) ? implode(' ', $errors) : '')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Default management page
|
|
|
4c79b5 |
if (!$this->parent_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$navigation = $user->lang['FORUM_INDEX'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$navigation = '' . $user->lang['FORUM_INDEX'] . '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
|
|
|
4c79b5 |
foreach ($forums_nav as $row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($row['forum_id'] == $this->parent_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$navigation .= ' -> ' . $row['forum_name'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$navigation .= ' -> ' . $row['forum_name'] . '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Jumpbox
|
|
|
4c79b5 |
$forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($action == 'sync' || $action == 'sync_forum')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_var('S_RESYNCED', true);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE parent_id = $this->parent_id
|
|
|
4c79b5 |
ORDER BY left_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
do
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_type = $row['forum_type'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row['forum_status'] == ITEM_LOCKED)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$folder_image = '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($forum_type)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case FORUM_LINK:
|
|
|
4c79b5 |
$folder_image = '';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
$folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '' : '';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$url = $this->u_action . "&parent_id=$this->parent_id&f={$row['forum_id']}";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_title = ($forum_type != FORUM_LINK) ? '' : '';
|
|
|
4c79b5 |
$forum_title .= $row['forum_name'];
|
|
|
4c79b5 |
$forum_title .= ($forum_type != FORUM_LINK) ? '' : '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_block_vars('forums', array(
|
|
|
4c79b5 |
'FOLDER_IMAGE' => $folder_image,
|
|
|
4c79b5 |
'FORUM_IMAGE' => ($row['forum_image']) ? '' : '',
|
|
|
4c79b5 |
'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
|
|
|
4c79b5 |
'FORUM_NAME' => $row['forum_name'],
|
|
|
4c79b5 |
'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
|
|
|
4c79b5 |
'FORUM_TOPICS' => $row['forum_topics'],
|
|
|
4c79b5 |
'FORUM_POSTS' => $row['forum_posts'],
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false,
|
|
|
4c79b5 |
'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_FORUM' => $this->u_action . '&parent_id=' . $row['forum_id'],
|
|
|
4c79b5 |
'U_MOVE_UP' => $url . '&action=move_up',
|
|
|
4c79b5 |
'U_MOVE_DOWN' => $url . '&action=move_down',
|
|
|
4c79b5 |
'U_EDIT' => $url . '&action=edit',
|
|
|
4c79b5 |
'U_DELETE' => $url . '&action=delete',
|
|
|
4c79b5 |
'U_SYNC' => $url . '&action=sync')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($this->parent_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$row = $this->get_forum_info($this->parent_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$url = $this->u_action . '&parent_id=' . $this->parent_id . '&f=' . $row['forum_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_NO_FORUMS' => true,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_EDIT' => $url . '&action=edit',
|
|
|
4c79b5 |
'U_DELETE' => $url . '&action=delete',
|
|
|
4c79b5 |
'U_SYNC' => $url . '&action=sync')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'ERROR_MSG' => (sizeof($errors)) ? implode(' ', $errors) : '',
|
|
|
4c79b5 |
'NAVIGATION' => $navigation,
|
|
|
4c79b5 |
'FORUM_BOX' => $forum_box,
|
|
|
4c79b5 |
'U_SEL_ACTION' => $this->u_action,
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . '&parent_id=' . $this->parent_id,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
|
|
|
4c79b5 |
'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get forum details
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_forum_info($forum_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Update forum data
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function update_forum_data(&$forum_data)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user, $cache;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$errors = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$forum_data['forum_name'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['FORUM_NAME_EMPTY'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (utf8_strlen($forum_data['forum_desc']) > 4000)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (utf8_strlen($forum_data['forum_rules']) > 4000)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($forum_data['forum_password'] || $forum_data['forum_password_confirm'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($forum_data['forum_password'] != $forum_data['forum_password_confirm'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data['forum_password'] = $forum_data['forum_password_confirm'] = '';
|
|
|
4c79b5 |
$errors[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($forum_data['prune_days'] < 0 || $forum_data['prune_viewed'] < 0 || $forum_data['prune_freq'] < 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data['prune_days'] = $forum_data['prune_viewed'] = $forum_data['prune_freq'] = 0;
|
|
|
4c79b5 |
$errors[] = $user->lang['FORUM_DATA_NEGATIVE'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$range_test_ary = array(
|
|
|
4c79b5 |
array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data['forum_topics_per_page'], 'column_type' => 'TINT:0'),
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
validate_range($range_test_ary, $errors);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Set forum flags
|
|
|
4c79b5 |
// 1 = link tracking
|
|
|
4c79b5 |
// 2 = prune old polls
|
|
|
4c79b5 |
// 4 = prune announcements
|
|
|
4c79b5 |
// 8 = prune stickies
|
|
|
4c79b5 |
// 16 = show active topics
|
|
|
4c79b5 |
// 32 = enable post review
|
|
|
4c79b5 |
$forum_data['forum_flags'] = 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += ($forum_data['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += ($forum_data['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += ($forum_data['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += ($forum_data['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
|
|
|
4c79b5 |
$forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Unset data that are not database fields
|
|
|
4c79b5 |
$forum_data_sql = $forum_data;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
unset($forum_data_sql['forum_link_track']);
|
|
|
4c79b5 |
unset($forum_data_sql['prune_old_polls']);
|
|
|
4c79b5 |
unset($forum_data_sql['prune_announce']);
|
|
|
4c79b5 |
unset($forum_data_sql['prune_sticky']);
|
|
|
4c79b5 |
unset($forum_data_sql['show_active']);
|
|
|
4c79b5 |
unset($forum_data_sql['enable_post_review']);
|
|
|
4c79b5 |
unset($forum_data_sql['forum_password_confirm']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// What are we going to do tonight Brain? The same thing we do everynight,
|
|
|
4c79b5 |
// try to take over the world ... or decide whether to continue update
|
|
|
4c79b5 |
// and if so, whether it's a new forum/cat/link or an existing one
|
|
|
4c79b5 |
if (sizeof($errors))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// As we don't know the old password, it's kinda tricky to detect changes
|
|
|
4c79b5 |
if ($forum_data_sql['forum_password_unset'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data_sql['forum_password'] = '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (empty($forum_data_sql['forum_password']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
unset($forum_data_sql['forum_password']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data_sql['forum_password'] = phpbb_hash($forum_data_sql['forum_password']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($forum_data_sql['forum_password_unset']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!isset($forum_data_sql['forum_id']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// no forum_id means we're creating a new forum
|
|
|
4c79b5 |
unset($forum_data_sql['type_action']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($forum_data_sql['parent_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT left_id, right_id, forum_type
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $forum_data_sql['parent_id'];
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&' . $this->parent_id), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row['forum_type'] == FORUM_LINK)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
SET left_id = left_id + 2, right_id = right_id + 2
|
|
|
4c79b5 |
WHERE left_id > ' . $row['right_id'];
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
SET right_id = right_id + 2
|
|
|
4c79b5 |
WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_data_sql['left_id'] = $row['right_id'];
|
|
|
4c79b5 |
$forum_data_sql['right_id'] = $row['right_id'] + 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT MAX(right_id) AS right_id
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_data_sql['left_id'] = $row['right_id'] + 1;
|
|
|
4c79b5 |
$forum_data_sql['right_id'] = $row['right_id'] + 2;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_data['forum_id'] = $db->sql_nextid();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_ADD', $forum_data['forum_name']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$row = $this->get_forum_info($forum_data_sql['forum_id']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Has subforums and want to change into a link?
|
|
|
4c79b5 |
if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// we're turning a postable forum into a non-postable forum
|
|
|
4c79b5 |
if ($forum_data_sql['type_action'] == 'move')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$to_forum_id = request_var('to_forum_id', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($to_forum_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return array($user->lang['NO_DESTINATION_FORUM']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($forum_data_sql['type_action'] == 'delete')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors = $this->delete_forum_content($forum_data_sql['forum_id']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return array($user->lang['NO_FORUM_ACTION']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_data_sql['forum_posts'] = $forum_data_sql['forum_topics'] = $forum_data_sql['forum_topics_real'] = $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0;
|
|
|
4c79b5 |
$forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Has subforums?
|
|
|
4c79b5 |
if ($row['right_id'] - $row['left_id'] > 1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// We are turning a category into a link - but need to decide what to do with the subforums.
|
|
|
4c79b5 |
$action_subforums = request_var('action_subforums', '');
|
|
|
4c79b5 |
$subforums_to_id = request_var('subforums_to_id', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($action_subforums == 'delete')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($rows as $_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Do not remove the forum id we are about to change. ;)
|
|
|
4c79b5 |
if ($_row['forum_id'] == $row['forum_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_ids[] = $_row['forum_id'];
|
|
|
4c79b5 |
$errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($errors))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($forum_ids))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Delete forum ids from extension groups table
|
|
|
4c79b5 |
$sql = 'SELECT group_id, allowed_forums
|
|
|
4c79b5 |
FROM ' . EXTENSION_GROUPS_TABLE;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($_row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$_row['allowed_forums'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$allowed_forums = unserialize(trim($_row['allowed_forums']));
|
|
|
4c79b5 |
$allowed_forums = array_diff($allowed_forums, $forum_ids);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
|
|
|
4c79b5 |
SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
|
|
|
4c79b5 |
WHERE group_id = {$_row['group_id']}";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache->destroy('_extensions');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($action_subforums == 'move')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$subforums_to_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return array($user->lang['NO_DESTINATION_FORUM']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_name
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $subforums_to_id;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return array($user->lang['NO_FORUM']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$subforums_to_name = $_row['forum_name'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_id
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE parent_id = {$row['forum_id']}";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($_row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->move_forum($_row['forum_id'], $subforums_to_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET parent_id = $subforums_to_id
|
|
|
4c79b5 |
WHERE parent_id = {$row['forum_id']}";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Adjust the left/right id
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
SET right_id = left_id + 1
|
|
|
4c79b5 |
WHERE forum_id = ' . $row['forum_id'];
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
|
|
|
4c79b5 |
$forum_data_sql['forum_posts'] = 0;
|
|
|
4c79b5 |
$forum_data_sql['forum_topics'] = 0;
|
|
|
4c79b5 |
$forum_data_sql['forum_topics_real'] = 0;
|
|
|
4c79b5 |
$forum_data_sql['forum_last_post_id'] = 0;
|
|
|
4c79b5 |
$forum_data_sql['forum_last_post_subject'] = '';
|
|
|
4c79b5 |
$forum_data_sql['forum_last_post_time'] = 0;
|
|
|
4c79b5 |
$forum_data_sql['forum_last_poster_id'] = 0;
|
|
|
4c79b5 |
$forum_data_sql['forum_last_poster_name'] = '';
|
|
|
4c79b5 |
$forum_data_sql['forum_last_poster_colour'] = '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($errors))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row['parent_id'] != $forum_data_sql['parent_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($row['forum_id'] != $forum_data_sql['parent_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_data_sql['parent_id'] = $row['parent_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($errors))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
unset($forum_data_sql['type_action']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row['forum_name'] != $forum_data_sql['forum_name'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// the forum name has changed, clear the parents list of all forums (for safety)
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET forum_parents = ''";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Setting the forum id to the forum id is not really received well by some dbs. ;)
|
|
|
4c79b5 |
$forum_id = $forum_data_sql['forum_id'];
|
|
|
4c79b5 |
unset($forum_data_sql['forum_id']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $forum_id;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Add it back
|
|
|
4c79b5 |
$forum_data['forum_id'] = $forum_id;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Move forum
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function move_forum($from_id, $to_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$to_data = $moved_ids = $errors = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check if we want to move to a parent with link type
|
|
|
4c79b5 |
if ($to_id > 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$to_data = $this->get_forum_info($to_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($to_data['forum_type'] == FORUM_LINK)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$moved_forums = get_forum_branch($from_id, 'children', 'descending');
|
|
|
4c79b5 |
$from_data = $moved_forums[0];
|
|
|
4c79b5 |
$diff = sizeof($moved_forums) * 2;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$moved_ids = array();
|
|
|
4c79b5 |
for ($i = 0; $i < sizeof($moved_forums); ++$i)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$moved_ids[] = $moved_forums[$i]['forum_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Resync parents
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET right_id = right_id - $diff, forum_parents = ''
|
|
|
4c79b5 |
WHERE left_id < " . $from_data['right_id'] . "
|
|
|
4c79b5 |
AND right_id > " . $from_data['right_id'];
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Resync righthand side of tree
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
|
|
|
4c79b5 |
WHERE left_id > " . $from_data['right_id'];
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($to_id > 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Retrieve $to_data again, it may have been changed...
|
|
|
4c79b5 |
$to_data = $this->get_forum_info($to_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Resync new parents
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET right_id = right_id + $diff, forum_parents = ''
|
|
|
4c79b5 |
WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
|
|
|
4c79b5 |
AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Resync the righthand side of the tree
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
|
|
|
4c79b5 |
WHERE left_id > " . $to_data['right_id'] . '
|
|
|
4c79b5 |
AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Resync moved branch
|
|
|
4c79b5 |
$to_data['right_id'] += $diff;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($to_data['right_id'] > $from_data['right_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT MAX(right_id) AS right_id
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('forum_id', $moved_ids, true);
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
|
|
|
4c79b5 |
WHERE " . $db->sql_in_set('forum_id', $moved_ids);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Move forum content from one to another forum
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function move_forum_content($from_id, $to_id, $sync = true)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($table_ary as $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "UPDATE $table
|
|
|
4c79b5 |
SET forum_id = $to_id
|
|
|
4c79b5 |
WHERE forum_id = $from_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($table_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($table_ary as $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "DELETE FROM $table
|
|
|
4c79b5 |
WHERE forum_id = $from_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($sync)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Delete ghost topics that link back to the same forum then resync counters
|
|
|
4c79b5 |
sync('topic_moved');
|
|
|
4c79b5 |
sync('forum', 'forum_id', $to_id, false, true);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return array();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Remove complete forum
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user, $cache;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$forum_data = $this->get_forum_info($forum_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$errors = array();
|
|
|
4c79b5 |
$log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = '';
|
|
|
4c79b5 |
$forum_ids = array($forum_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($action_posts == 'delete')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$log_action_posts = 'POSTS';
|
|
|
4c79b5 |
$errors = array_merge($errors, $this->delete_forum_content($forum_id));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($action_posts == 'move')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$posts_to_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['NO_DESTINATION_FORUM'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$log_action_posts = 'MOVE_POSTS';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_name
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $posts_to_id;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['NO_FORUM'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$posts_to_name = $row['forum_name'];
|
|
|
4c79b5 |
$errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($errors))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($action_subforums == 'delete')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$log_action_forums = 'FORUMS';
|
|
|
4c79b5 |
$rows = get_forum_branch($forum_id, 'children', 'descending', false);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($rows as $row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$forum_ids[] = $row['forum_id'];
|
|
|
4c79b5 |
$errors = array_merge($errors, $this->delete_forum_content($row['forum_id']));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($errors))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$diff = sizeof($forum_ids) * 2;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($action_subforums == 'move')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$subforums_to_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['NO_DESTINATION_FORUM'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$log_action_forums = 'MOVE_FORUMS';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_name
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $subforums_to_id;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errors[] = $user->lang['NO_FORUM'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$subforums_to_name = $row['forum_name'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_id
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE parent_id = $forum_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->move_forum($row['forum_id'], $subforums_to_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Grab new forum data for correct tree updating later
|
|
|
4c79b5 |
$forum_data = $this->get_forum_info($forum_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET parent_id = $subforums_to_id
|
|
|
4c79b5 |
WHERE parent_id = $forum_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$diff = 2;
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($errors))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$diff = 2;
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
|
|
|
4c79b5 |
WHERE forum_id = $forum_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Resync tree
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET right_id = right_id - $diff
|
|
|
4c79b5 |
WHERE left_id < {$forum_data['right_id']} AND right_id > {$forum_data['right_id']}";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET left_id = left_id - $diff, right_id = right_id - $diff
|
|
|
4c79b5 |
WHERE left_id > {$forum_data['right_id']}";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Delete forum ids from extension groups table
|
|
|
4c79b5 |
$sql = 'SELECT group_id, allowed_forums
|
|
|
4c79b5 |
FROM ' . EXTENSION_GROUPS_TABLE;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$row['allowed_forums'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$allowed_forums = unserialize(trim($row['allowed_forums']));
|
|
|
4c79b5 |
$allowed_forums = array_diff($allowed_forums, $forum_ids);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
|
|
|
4c79b5 |
SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
|
|
|
4c79b5 |
WHERE group_id = {$row['group_id']}";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache->destroy('_extensions');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$log_action = implode('_', array($log_action_posts, $log_action_forums));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($log_action)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'MOVE_POSTS_MOVE_FORUMS':
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', $posts_to_name, $subforums_to_name, $forum_data['forum_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'MOVE_POSTS_FORUMS':
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', $posts_to_name, $forum_data['forum_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'POSTS_MOVE_FORUMS':
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case '_MOVE_FORUMS':
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_DEL_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'MOVE_POSTS_':
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS', $posts_to_name, $forum_data['forum_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'POSTS_FORUMS':
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_DEL_POSTS_FORUMS', $forum_data['forum_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case '_FORUMS':
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_DEL_FORUMS', $forum_data['forum_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'POSTS_':
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_DEL_POSTS', $forum_data['forum_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
add_log('admin', 'LOG_FORUM_DEL_FORUM', $forum_data['forum_name']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $errors;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Delete forum content
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function delete_forum_content($forum_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $config, $phpbb_root_path, $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Select then delete all attachments
|
|
|
4c79b5 |
$sql = 'SELECT a.topic_id
|
|
|
4c79b5 |
FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
|
|
|
4c79b5 |
WHERE p.forum_id = $forum_id
|
|
|
4c79b5 |
AND a.in_message = 0
|
|
|
4c79b5 |
AND a.topic_id = p.topic_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$topic_ids = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$topic_ids[] = $row['topic_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
delete_attachments('topic', $topic_ids, false);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Before we remove anything we make sure we are able to adjust the post counts later. ;)
|
|
|
4c79b5 |
$sql = 'SELECT poster_id
|
|
|
4c79b5 |
FROM ' . POSTS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $forum_id . '
|
|
|
4c79b5 |
AND post_postcount = 1
|
|
|
4c79b5 |
AND post_approved = 1';
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$post_counts = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($db->sql_layer)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'mysql4':
|
|
|
4c79b5 |
case 'mysqli':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Delete everything else and thank MySQL for offering multi-table deletion
|
|
|
4c79b5 |
$tables_ary = array(
|
|
|
4c79b5 |
SEARCH_WORDMATCH_TABLE => 'post_id',
|
|
|
4c79b5 |
REPORTS_TABLE => 'post_id',
|
|
|
4c79b5 |
WARNINGS_TABLE => 'post_id',
|
|
|
4c79b5 |
BOOKMARKS_TABLE => 'topic_id',
|
|
|
4c79b5 |
TOPICS_WATCH_TABLE => 'topic_id',
|
|
|
4c79b5 |
TOPICS_POSTED_TABLE => 'topic_id',
|
|
|
4c79b5 |
POLL_OPTIONS_TABLE => 'topic_id',
|
|
|
4c79b5 |
POLL_VOTES_TABLE => 'topic_id',
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE ' . POSTS_TABLE;
|
|
|
4c79b5 |
$sql_using = "\nFROM " . POSTS_TABLE;
|
|
|
4c79b5 |
$sql_where = "\nWHERE " . POSTS_TABLE . ".forum_id = $forum_id\n";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($tables_ary as $table => $field)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql .= ", $table ";
|
|
|
4c79b5 |
$sql_using .= ", $table ";
|
|
|
4c79b5 |
$sql_where .= "\nAND $table.$field = " . POSTS_TABLE . ".$field";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_query($sql . $sql_using . $sql_where);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Delete everything else and curse your DB for not offering multi-table deletion
|
|
|
4c79b5 |
$tables_ary = array(
|
|
|
4c79b5 |
'post_id' => array(
|
|
|
4c79b5 |
SEARCH_WORDMATCH_TABLE,
|
|
|
4c79b5 |
REPORTS_TABLE,
|
|
|
4c79b5 |
WARNINGS_TABLE,
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'topic_id' => array(
|
|
|
4c79b5 |
BOOKMARKS_TABLE,
|
|
|
4c79b5 |
TOPICS_WATCH_TABLE,
|
|
|
4c79b5 |
TOPICS_POSTED_TABLE,
|
|
|
4c79b5 |
POLL_OPTIONS_TABLE,
|
|
|
4c79b5 |
POLL_VOTES_TABLE,
|
|
|
4c79b5 |
)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($tables_ary as $field => $tables)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$start = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
do
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "SELECT $field
|
|
|
4c79b5 |
FROM " . POSTS_TABLE . '
|
|
|
4c79b5 |
WHERE forum_id = ' . $forum_id;
|
|
|
4c79b5 |
$result = $db->sql_query_limit($sql, 500, $start);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$ids = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$ids[] = $row[$field];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($ids))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$start += sizeof($ids);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($tables as $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_query("DELETE FROM $table WHERE " . $db->sql_in_set($field, $ids));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
while ($row);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($ids);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, LOG_TABLE, MODERATOR_CACHE_TABLE, POSTS_TABLE, TOPICS_TABLE, TOPICS_TRACK_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($table_ary as $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_query("DELETE FROM $table WHERE forum_id = $forum_id");
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Set forum ids to 0
|
|
|
4c79b5 |
$table_ary = array(DRAFTS_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($table_ary as $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_query("UPDATE $table SET forum_id = 0 WHERE forum_id = $forum_id");
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Adjust users post counts
|
|
|
4c79b5 |
if (sizeof($post_counts))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($post_counts as $poster_id => $substract)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . '
|
|
|
4c79b5 |
SET user_posts = 0
|
|
|
4c79b5 |
WHERE user_id = ' . $poster_id . '
|
|
|
4c79b5 |
AND user_posts < ' . $substract;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . '
|
|
|
4c79b5 |
SET user_posts = user_posts - ' . $substract . '
|
|
|
4c79b5 |
WHERE user_id = ' . $poster_id . '
|
|
|
4c79b5 |
AND user_posts >= ' . $substract;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Make sure the overall post/topic count is correct...
|
|
|
4c79b5 |
$sql = 'SELECT COUNT(post_id) AS stat
|
|
|
4c79b5 |
FROM ' . POSTS_TABLE . '
|
|
|
4c79b5 |
WHERE post_approved = 1';
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
set_config('num_posts', (int) $row['stat'], true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT COUNT(topic_id) AS stat
|
|
|
4c79b5 |
FROM ' . TOPICS_TABLE . '
|
|
|
4c79b5 |
WHERE topic_approved = 1';
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
set_config('num_topics', (int) $row['stat'], true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT COUNT(attach_id) as stat
|
|
|
4c79b5 |
FROM ' . ATTACHMENTS_TABLE;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
set_config('num_files', (int) $row['stat'], true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT SUM(filesize) as stat
|
|
|
4c79b5 |
FROM ' . ATTACHMENTS_TABLE;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
set_config('upload_dir_size', (float) $row['stat'], true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return array();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Move forum position by $steps up/down
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function move_forum_by($forum_row, $action = 'move_up', $steps = 1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Fetch all the siblings between the module's current spot
|
|
|
4c79b5 |
* and where we want to move it to. If there are less than $steps
|
|
|
4c79b5 |
* siblings between the current spot and the target then the
|
|
|
4c79b5 |
* module will move as far as possible
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
$sql = 'SELECT forum_id, forum_name, left_id, right_id
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
WHERE parent_id = {$forum_row['parent_id']}
|
|
|
4c79b5 |
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");
|
|
|
4c79b5 |
$result = $db->sql_query_limit($sql, $steps);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$target = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$target = $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($target))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// The forum is already on top or bottom
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* $left_id and $right_id define the scope of the nodes that are affected by the move.
|
|
|
4c79b5 |
* $diff_up and $diff_down are the values to substract or add to each node's left_id
|
|
|
4c79b5 |
* and right_id in order to move them up or down.
|
|
|
4c79b5 |
* $move_up_left and $move_up_right define the scope of the nodes that are moving
|
|
|
4c79b5 |
* up. Other nodes in the scope of ($left_id, $right_id) are considered to move down.
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
if ($action == 'move_up')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$left_id = $target['left_id'];
|
|
|
4c79b5 |
$right_id = $forum_row['right_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$diff_up = $forum_row['left_id'] - $target['left_id'];
|
|
|
4c79b5 |
$diff_down = $forum_row['right_id'] + 1 - $forum_row['left_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$move_up_left = $forum_row['left_id'];
|
|
|
4c79b5 |
$move_up_right = $forum_row['right_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$left_id = $forum_row['left_id'];
|
|
|
4c79b5 |
$right_id = $target['right_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$diff_up = $forum_row['right_id'] + 1 - $forum_row['left_id'];
|
|
|
4c79b5 |
$diff_down = $target['right_id'] - $forum_row['right_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$move_up_left = $forum_row['right_id'] + 1;
|
|
|
4c79b5 |
$move_up_right = $target['right_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Now do the dirty job
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET left_id = left_id + CASE
|
|
|
4c79b5 |
WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
|
|
|
4c79b5 |
ELSE {$diff_down}
|
|
|
4c79b5 |
END,
|
|
|
4c79b5 |
right_id = right_id + CASE
|
|
|
4c79b5 |
WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
|
|
|
4c79b5 |
ELSE {$diff_down}
|
|
|
4c79b5 |
END,
|
|
|
4c79b5 |
forum_parents = ''
|
|
|
4c79b5 |
WHERE
|
|
|
4c79b5 |
left_id BETWEEN {$left_id} AND {$right_id}
|
|
|
4c79b5 |
AND right_id BETWEEN {$left_id} AND {$right_id}";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $target['forum_name'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Display progress bar for syncinc forums
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function display_progress_bar($start, $total)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $template, $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
adm_page_header($user->lang['SYNC_IN_PROGRESS']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->set_filenames(array(
|
|
|
4c79b5 |
'body' => 'progress_bar.html')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'L_PROGRESS' => $user->lang['SYNC_IN_PROGRESS'],
|
|
|
4c79b5 |
'L_PROGRESS_EXPLAIN' => ($start && $total) ? sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $start, $total) : $user->lang['SYNC_IN_PROGRESS'])
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
adm_page_footer();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|