Код: Выделить всё
добавить_форум (имя, родитель и пр.)
Код: Выделить всё
добавить_форум (имя, родитель и пр.)
Код: Выделить всё
<?php
define('IN_PHPBB', true);
$phpbb_root_path = '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$auth->login('ЛОГИНАДМИНА','ПАРОЛЬАДМИНА');
$my_subject = utf8_normalize_nfc('Topic Subject Line');
$my_text = utf8_normalize_nfc('
Body
shown as
you want to see it.
');
$poll = $uid = $bitfield = $options = '';
generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
generate_text_for_storage($my_text, $uid, $bitfield, $options, true, true, true);
$data = array(
'forum_id' => 82,
'icon_id' => false,
'enable_bbcode' => true,
'enable_smilies' => true,
'enable_urls' => true,
'enable_sig' => true,
'message' => $my_text,
'message_md5' => md5($my_text),
'bbcode_bitfield' => $bitfield,
'bbcode_uid' => $uid,
'post_edit_locked' => 0,
'topic_title' => $my_subject,
'notify_set' => false,
'notify' => false,
'post_time' => 0,
'forum_name' => '',
'enable_indexing' => true,
);
submit_post('post', $my_subject, '', POST_NORMAL, $poll, $data);
?>
На веб-сайте произошла ошибка при получении http://localhost/phpBB3/123.php. Веб-сайт может быть закрыт на обслуживание или настроен неправильно.
Решениеstas2web писал(а):Типо вот так:Код: Выделить всё
добавить_форум (имя, родитель и пр.)
Код: Выделить всё
function set_forum_data($parent_id, $forum_name, $forum_desc, $forum_rules, $forum_type, $display_subforum_list, $display_on_index, &$errors)
{
global $db, $user, $auth, $template, $cache;
global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
global $acp_forums;
$forum_data = array();
$forum_data += array(
'parent_id' => $parent_id,
'forum_type' => $forum_type,
'type_action' => '',
'forum_status' => ITEM_UNLOCKED,
'forum_parents' => '',
'forum_name' => utf8_normalize_nfc($forum_name),
'forum_link' => '',
'forum_link_track' => false,
'forum_desc' => utf8_normalize_nfc($forum_desc),
'forum_desc_uid' => '',
'forum_desc_options' => 7,
'forum_desc_bitfield' => '',
'forum_rules' => utf8_normalize_nfc($forum_rules),
'forum_rules_uid' => '',
'forum_rules_options' => 7,
'forum_rules_bitfield' => '',
'forum_rules_link' => '',
'forum_image' => '',
'forum_style' => 0,
'display_subforum_list' => $display_subforum_list,
//subforumslist_type_article_mod_start
'forum_subforumslist_type' => 0,
//subforumslist_type_article_mod_end
'display_on_index' => $display_on_index,
'forum_topics_per_page' => 0,
'enable_indexing' => true,
'enable_icons' => true,
'enable_prune' => false,
'enable_post_review' => true,
'enable_quick_reply' => true,
'prune_days' => 7,
'prune_viewed' => 7,
'prune_freq' => 1,
'prune_old_polls' => false,
'prune_announce' => false,
'prune_sticky' => false,
'forum_password' => '',
'forum_password_confirm'=> '',
'forum_password_unset' => false,
);
// Get data for forum rules if specified...
if ($forum_data['forum_rules'])
{
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));
}
// Get data for forum description if specified
if ($forum_data['forum_desc'])
{
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));
}
$errors = update_forum_data($forum_data);
return $forum_data['forum_id'];
}
function update_forum_data(&$forum_data)
{
global $db, $user, $cache, $phpbb_root_path;
$errors = array();
if ($forum_data['forum_name'] == '')
{
$errors[] = $user->lang['FORUM_NAME_EMPTY'];
}
if (utf8_strlen($forum_data['forum_desc']) > 4000)
{
$errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
}
if (utf8_strlen($forum_data['forum_rules']) > 4000)
{
$errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
}
$range_test_ary = array(
array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data['forum_topics_per_page'], 'column_type' => 'TINT:0'),
);
if (!empty($forum_data['forum_image']) && !file_exists($phpbb_root_path . $forum_data['forum_image']))
{
$errors[] = $user->lang['FORUM_IMAGE_NO_EXIST'];
}
validate_range($range_test_ary, $errors);
// Set forum flags
// 1 = link tracking
// 2 = prune old polls
// 4 = prune announcements
// 8 = prune stickies
// 16 = show active topics
// 32 = enable post review
$forum_data['forum_flags'] = 0;
$forum_data['forum_flags'] += ($forum_data['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
$forum_data['forum_flags'] += ($forum_data['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
$forum_data['forum_flags'] += ($forum_data['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
$forum_data['forum_flags'] += ($forum_data['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
$forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
$forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
$forum_data['forum_flags'] += ($forum_data['enable_quick_reply']) ? FORUM_FLAG_QUICK_REPLY : 0;
// Unset data that are not database fields
$forum_data_sql = $forum_data;
unset($forum_data_sql['forum_link_track']);
unset($forum_data_sql['prune_old_polls']);
unset($forum_data_sql['prune_announce']);
unset($forum_data_sql['prune_sticky']);
unset($forum_data_sql['show_active']);
unset($forum_data_sql['enable_post_review']);
unset($forum_data_sql['enable_quick_reply']);
unset($forum_data_sql['forum_password_confirm']);
// What are we going to do tonight Brain? The same thing we do everynight,
// try to take over the world ... or decide whether to continue update
// and if so, whether it's a new forum/cat/link or an existing one
if (sizeof($errors))
{
return $errors;
}
// As we don't know the old password, it's kinda tricky to detect changes
if ($forum_data_sql['forum_password_unset'])
{
$forum_data_sql['forum_password'] = '';
}
else if (empty($forum_data_sql['forum_password']))
{
unset($forum_data_sql['forum_password']);
}
else
{
$forum_data_sql['forum_password'] = phpbb_hash($forum_data_sql['forum_password']);
}
unset($forum_data_sql['forum_password_unset']);
if (!isset($forum_data_sql['forum_id']))
{
// no forum_id means we're creating a new forum
unset($forum_data_sql['type_action']);
if ($forum_data_sql['parent_id'])
{
$sql = 'SELECT left_id, right_id, forum_type
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $forum_data_sql['parent_id'];
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$row)
{
trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
}
if ($row['forum_type'] == FORUM_LINK)
{
$errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
return $errors;
}
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET left_id = left_id + 2, right_id = right_id + 2
WHERE left_id > ' . $row['right_id'];
$db->sql_query($sql);
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET right_id = right_id + 2
WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
$db->sql_query($sql);
$forum_data_sql['left_id'] = $row['right_id'];
$forum_data_sql['right_id'] = $row['right_id'] + 1;
}
else
{
$sql = 'SELECT MAX(right_id) AS right_id
FROM ' . FORUMS_TABLE;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$forum_data_sql['left_id'] = $row['right_id'] + 1;
$forum_data_sql['right_id'] = $row['right_id'] + 2;
}
$sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
$db->sql_query($sql);
$forum_data['forum_id'] = $db->sql_nextid();
add_log('admin', 'LOG_FORUM_ADD', $forum_data['forum_name']);
}
else
{
$row = $this->get_forum_info($forum_data_sql['forum_id']);
if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
{
// Has subforums and want to change into a link?
if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
{
$errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
return $errors;
}
// we're turning a postable forum into a non-postable forum
if ($forum_data_sql['type_action'] == 'move')
{
$to_forum_id = request_var('to_forum_id', 0);
if ($to_forum_id)
{
$errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
}
else
{
return array($user->lang['NO_DESTINATION_FORUM']);
}
}
else if ($forum_data_sql['type_action'] == 'delete')
{
$errors = $this->delete_forum_content($forum_data_sql['forum_id']);
}
else
{
return array($user->lang['NO_FORUM_ACTION']);
}
$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;
$forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
}
else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
{
// Has subforums?
if ($row['right_id'] - $row['left_id'] > 1)
{
// We are turning a category into a link - but need to decide what to do with the subforums.
$action_subforums = request_var('action_subforums', '');
$subforums_to_id = request_var('subforums_to_id', 0);
if ($action_subforums == 'delete')
{
$rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
foreach ($rows as $_row)
{
// Do not remove the forum id we are about to change. ;)
if ($_row['forum_id'] == $row['forum_id'])
{
continue;
}
$forum_ids[] = $_row['forum_id'];
$errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
}
if (sizeof($errors))
{
return $errors;
}
if (sizeof($forum_ids))
{
$sql = 'DELETE FROM ' . FORUMS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
$db->sql_query($sql);
$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
$db->sql_query($sql);
$sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
$db->sql_query($sql);
// Delete forum ids from extension groups table
$sql = 'SELECT group_id, allowed_forums
FROM ' . EXTENSION_GROUPS_TABLE;
$result = $db->sql_query($sql);
while ($_row = $db->sql_fetchrow($result))
{
if (!$_row['allowed_forums'])
{
continue;
}
$allowed_forums = unserialize(trim($_row['allowed_forums']));
$allowed_forums = array_diff($allowed_forums, $forum_ids);
$sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
WHERE group_id = {$_row['group_id']}";
$db->sql_query($sql);
}
$db->sql_freeresult($result);
$cache->destroy('_extensions');
}
}
else if ($action_subforums == 'move')
{
if (!$subforums_to_id)
{
return array($user->lang['NO_DESTINATION_FORUM']);
}
$sql = 'SELECT forum_name
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $subforums_to_id;
$result = $db->sql_query($sql);
$_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$_row)
{
return array($user->lang['NO_FORUM']);
}
$subforums_to_name = $_row['forum_name'];
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE . "
WHERE parent_id = {$row['forum_id']}";
$result = $db->sql_query($sql);
while ($_row = $db->sql_fetchrow($result))
{
$this->move_forum($_row['forum_id'], $subforums_to_id);
}
$db->sql_freeresult($result);
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET parent_id = $subforums_to_id
WHERE parent_id = {$row['forum_id']}";
$db->sql_query($sql);
}
// Adjust the left/right id
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET right_id = left_id + 1
WHERE forum_id = ' . $row['forum_id'];
$db->sql_query($sql);
}
}
else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
{
// Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
$forum_data_sql['forum_posts'] = 0;
$forum_data_sql['forum_topics'] = 0;
$forum_data_sql['forum_topics_real'] = 0;
$forum_data_sql['forum_last_post_id'] = 0;
$forum_data_sql['forum_last_post_subject'] = '';
$forum_data_sql['forum_last_post_time'] = 0;
$forum_data_sql['forum_last_poster_id'] = 0;
$forum_data_sql['forum_last_poster_name'] = '';
$forum_data_sql['forum_last_poster_colour'] = '';
}
if (sizeof($errors))
{
return $errors;
}
if ($row['parent_id'] != $forum_data_sql['parent_id'])
{
if ($row['forum_id'] != $forum_data_sql['parent_id'])
{
$errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
}
else
{
$forum_data_sql['parent_id'] = $row['parent_id'];
}
}
if (sizeof($errors))
{
return $errors;
}
unset($forum_data_sql['type_action']);
if ($row['forum_name'] != $forum_data_sql['forum_name'])
{
// the forum name has changed, clear the parents list of all forums (for safety)
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET forum_parents = ''";
$db->sql_query($sql);
}
// Setting the forum id to the forum id is not really received well by some dbs. ;)
$forum_id = $forum_data_sql['forum_id'];
unset($forum_data_sql['forum_id']);
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
WHERE forum_id = ' . $forum_id;
$db->sql_query($sql);
// Add it back
$forum_data['forum_id'] = $forum_id;
add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
}
return $errors;
}