function bb_update_topic($title, $topic_id) { $title = stripslashes($title); return bb_insert_topic(array('topic_title' => $title, 'topic_id' => $topic_id)); }
/** * Update a topic's details. * * @param array $args { * Array of arguments. * @type int $topic_id ID of the topic being updated. * @type string $topic_title Updated title of the topic. * @type string $topic_title Updated text of the topic. * @type array|string|bool $topic_tags Array or comma-separated list of * topic tags. False to leave empty. Default: false. * } * @return object Details about the new topic, as returned by * {@link bp_forums_get_topic_details()}. */ function bp_forums_update_topic($args = '') { /** This action is documented in bp-forums/bp-forums-screens */ do_action('bbpress_init'); $r = wp_parse_args($args, array('topic_id' => false, 'topic_title' => '', 'topic_text' => '', 'topic_tags' => false)); extract($r, EXTR_SKIP); // Check if the user is a spammer if (bp_is_user_inactive(bp_loggedin_user_id())) { return false; } // bb_insert_topic() will append tags, but not remove them. So we remove all existing tags. bb_remove_topic_tags($topic_id); if (!($topic_id = bb_insert_topic(array('topic_id' => $topic_id, 'topic_title' => stripslashes($topic_title), 'tags' => $topic_tags)))) { return false; } if (!($post = bb_get_first_post($topic_id))) { return false; } // Update the first post if (!($post = bp_forums_insert_post(array('post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position)))) { return false; } return bp_forums_get_topic_details($topic_id); }
/** * Edits an existing topic * * @since 1.0 * @return array|object The topic data when successfully edited or an IXR_Error object on failure * @param array $args Arguments passed by the XML-RPC call * @param string $args[0] The username for authentication * @param string $args[1] The password for authentication * @param array $args[2] The values for the various parameters in the edited topic * @param integer|string $args[2]['topic_id'] The topic's id or slug * @param string $args[2]['title'] The title of the topic * @param string $args[2]['text'] The text of the topic * * XML-RPC request to edit the title of a topic with the slug "insane-monkeys" * <methodCall> * <methodName>bb.editTopic</methodName> * <params> * <param><value><string>joeblow</string></value></param> * <param><value><string>123password</string></value></param> * <param><value><struct> * <member> * <name>topic_id</name> * <value><string>insane-monkeys</string></value> * </member> * <member> * <name>title</name> * <value><string>Very insane monkeys</string></value> * </member> * </struct></value></param> * </params> * </methodCall> */ function bb_editTopic($args) { do_action('bb_xmlrpc_call', 'bb.editTopic'); // Escape args $this->escape($args); // Get the login credentials $username = $args[0]; $password = (string) $args[1]; // Check the user is valid $user = $this->authenticate($username, $password, 'edit_topics', __('You do not have permission to edit topics.')); // Additionally they need to be able to edit posts if (!$this->error && !bb_current_user_can('edit_posts')) { $this->error = new IXR_Error(403, __('You do not have permission to edit posts.')); } do_action('bb_xmlrpc_call_authenticated', 'bb.editTopic'); // If an error was raised by authentication or by an action then return it if ($this->error) { return $this->error; } // Make sure there is something for us to do if (!$args[2] || !is_array($args[2]) || !count($args[2])) { $this->error = new IXR_Error(400, __('The topic data is invalid.')); return $this->error; } $structure = (array) $args[2]; // Can be numeric id or slug $topic_id = isset($structure['topic_id']) ? $structure['topic_id'] : false; // Check for bad data if (!$topic_id || !is_string($topic_id) && !is_integer($topic_id)) { $this->error = new IXR_Error(400, __('The topic id is invalid.')); return $this->error; } // Check the requested topic exists if (!($topic = get_topic($topic_id))) { $this->error = new IXR_Error(400, __('No topic found.')); return $this->error; } // The topic id may have been a slug, so make sure it's an integer here $topic_id = (int) $topic->topic_id; // Make sure they are allowed to edit this topic if (!bb_current_user_can('edit_topic', $topic_id)) { $this->error = new IXR_Error(403, __('You do not have permission to edit this topic.')); return $this->error; } // Get the first post in the topic (that's where the content is) if (!($post = bb_get_first_post($topic_id))) { $this->error = new IXR_Error(400, __('No posts found.')); return $this->error; } $post_id = (int) $post->post_id; // Make sure they are allowed to edit this post if (!bb_current_user_can('edit_post', $post_id)) { $this->error = new IXR_Error(403, __('You do not have permission to edit this post.')); return $this->error; } // The topic requires a title if (isset($structure['title']) && !$structure['title']) { $this->error = new IXR_Error(400, __('The topic title is invalid.')); return $this->error; } // The topic requires text if (isset($structure['text']) && !$structure['text']) { $this->error = new IXR_Error(400, __('The topic text is invalid.')); return $this->error; } if ($structure['title']) { if (!bb_insert_topic(array('topic_title' => (string) $structure['title'], 'topic_id' => $topic_id))) { $this->error = new IXR_Error(500, __('The topic could not be edited.')); return $this->error; } } if ($structure['text']) { if (!bb_insert_post(array('post_text' => (string) $structure['text'], 'post_id' => $post_id, 'topic_id' => $topic_id))) { $this->error = new IXR_Error(500, __('The post could not be edited.')); return $this->error; } } // Only include "safe" data in the array $topic = $this->prepare_topic(get_topic($topic_id)); do_action('bb_xmlrpc_call_return', 'bb.editTopic'); return $topic; }
function bp_forums_update_topic($args = '') { global $bp; do_action('bbpress_init'); $defaults = array('topic_id' => false, 'topic_title' => '', 'topic_text' => '', 'topic_tags' => false); $r = nxt_parse_args($args, $defaults); extract($r, EXTR_SKIP); // Check if the user is a spammer if (bp_core_is_user_spammer($bp->loggedin_user->id) || bp_core_is_user_deleted($bp->loggedin_user->id)) { return false; } // bb_insert_topic() will append tags, but not remove them. So we remove all existing tags. bb_remove_topic_tags($topic_id); if (!($topic_id = bb_insert_topic(array('topic_id' => $topic_id, 'topic_title' => stripslashes($topic_title), 'tags' => $topic_tags)))) { return false; } if (!($post = bb_get_first_post($topic_id))) { return false; } // Update the first post if (!($post = bp_forums_insert_post(array('post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position)))) { return false; } return bp_forums_get_topic_details($topic_id); }
} if (!empty($_POST['url'])) { $post_url = esc_url(trim($_POST['url'])); } } // Loop through possible anonymous post data foreach (array('post_author', 'post_email', 'post_url') as $field) { if (!empty(${$field})) { $post_data[$field] = ${$field}; } } // Setup topic data if (bb_is_first($bb_post->post_id) && bb_current_user_can('edit_topic', $bb_post->topic_id)) { $post_data['topic_title'] = stripslashes($_POST['topic']); $post_data['topic_id'] = $bb_post->topic_id; bb_insert_topic($post_data); } // Setup post data $post_data['post_text'] = stripslashes($_POST['post_content']); $post_data['post_id'] = $post_id; bb_insert_post($post_data); if ($post_id) { if ($_REQUEST['view'] === 'all') { add_filter('get_post_link', 'bb_make_link_view_all'); } $post_link = get_post_link($post_id); nxt_redirect($post_link); } else { nxt_redirect(bb_get_uri(null, null, BB_URI_CONTEXT_HEADER)); } exit;
/** * Finalises the installation by creating the database and writing all the supplied data to the database. * * @return void **/ function process_form_finalise_installation() { require_once BB_PATH . 'bb-admin/includes/functions.bb-upgrade.php'; require_once BB_PATH . 'bb-admin/includes/functions.bb-admin.php'; $this->inject_form_values_into_data(2); $this->inject_form_values_into_data(3); $data2 =& $this->data[2]['form']; $data3 =& $this->data[3]['form']; $data4 =& $this->data[4]['form']; $error_log = array(); $installation_log = array(); // Check the referer bb_check_admin_referer('bbpress-installer'); $installation_log[] = __('Referrer is OK, beginning installation…'); global $bbdb; // Setup user table variables and constants if available if ($data2['toggle_2_2']['value']) { $installation_log[] = '>>> ' . __('Setting up custom user table constants'); global $bb; global $bb_table_prefix; if (!empty($data2['wp_table_prefix']['value'])) { $bb->wp_table_prefix = $data2['wp_table_prefix']['value']; } if (!empty($data2['user_bbdb_name']['value'])) { $bb->user_bbdb_name = $data2['user_bbdb_name']['value']; } if (!empty($data2['user_bbdb_user']['value'])) { $bb->user_bbdb_user = $data2['user_bbdb_user']['value']; } if (!empty($data2['user_bbdb_password']['value'])) { $bb->user_bbdb_password = $data2['user_bbdb_password']['value']; } if (!empty($data2['user_bbdb_host']['value'])) { $bb->user_bbdb_host = $data2['user_bbdb_host']['value']; } if (!empty($data2['user_bbdb_charset']['value'])) { $bb->user_bbdb_charset = preg_replace('/[^a-z0-9_-]/i', '', $data2['user_bbdb_charset']['value']); } if (!empty($data2['user_bbdb_collate']['value'])) { $bb->user_bbdb_collate = preg_replace('/[^a-z0-9_-]/i', '', $data2['user_bbdb_collate']['value']); } bb_set_custom_user_tables(); // Add custom user database if required if (isset($bb->custom_databases['user'])) { $bbdb->add_db_server('user', $bb->custom_databases['user']); } // Add custom tables if required if (isset($bb->custom_tables)) { $bbdb->tables = array_merge($bbdb->tables, $bb->custom_tables); if (is_wp_error($bbdb->set_prefix($bb_table_prefix))) { die(__('Your user table prefix may only contain letters, numbers and underscores.')); } } } // Create the database $installation_log[] = "\n" . __('Step 1 - Creating database tables'); if (!$this->database_tables_are_installed()) { // Hide db errors $bbdb->hide_errors(); // Install the database $alterations = bb_install(); // Show db errors $bbdb->show_errors(); if (isset($alterations['errors']) && is_array($alterations['errors'])) { $error_log = array_merge($error_log, $alterations['errors']); } if (isset($alterations['messages']) && is_array($alterations['messages'])) { $installation_log = array_merge($installation_log, $alterations['messages']); } if (!$this->database_tables_are_installed()) { $installation_log[] = '>>> ' . __('Database installation failed!!!'); $installation_log[] = '>>>>>> ' . __('Halting installation!'); $error_log[] = __('Database installation failed!!!'); $this->step_status[4] = 'incomplete'; $this->strings[4]['h2'] = __('Installation failed!'); $this->strings[4]['messages']['error'][] = __('The database failed to install. You may need to replace bbPress with a fresh copy and start again.'); $data4['installation_log']['value'] = join("\n", $installation_log); $data4['error_log']['value'] = join("\n", $error_log); return 'incomplete'; } } else { $installation_log[] = '>>> ' . __('Database is already installed!!!'); } // Integration settings passed from step 2 // These are already validated provided that the referer checks out $installation_log[] = "\n" . __('Step 2 - WordPress integration (optional)'); if ($data2['toggle_2_0']['value']) { if ($data2['toggle_2_1']['value']) { bb_update_option('wp_siteurl', $data2['wp_siteurl']['value']); $installation_log[] = '>>> ' . __('WordPress address (URL):') . ' ' . $data2['wp_siteurl']['value']; bb_update_option('wp_home', $data2['wp_home']['value']); $installation_log[] = '>>> ' . __('Blog address (URL):') . ' ' . $data2['wp_home']['value']; $config_result = $this->write_lines_to_file(BB_PATH . 'bb-config.php', false, array("define( 'BB_AUTH_KEY" => array("'" . BB_AUTH_KEY . "'", "'" . $data2['wp_auth_key']['value'] . "'"), "define( 'BB_SECURE_A" => array("'" . BB_SECURE_AUTH_KEY . "'", "'" . $data2['wp_secure_auth_key']['value'] . "'"), "define( 'BB_LOGGED_I" => array("'" . BB_LOGGED_IN_KEY . "'", "'" . $data2['wp_logged_in_key']['value'] . "'"))); switch ($config_result) { case 1: $installation_log[] = '>>> ' . __('WordPress cookie keys set.'); break; default: $error_log[] = '>>> ' . __('WordPress cookie keys not set.'); $error_log[] = '>>>>>> ' . __('Your "bb-config.php" file was not writable.'); $error_log[] = '>>>>>> ' . __('You will need to manually re-define "BB_AUTH_KEY", "BB_SECURE_AUTH_KEY" and "BB_LOGGED_IN_KEY" in your "bb-config.php" file.'); $installation_log[] = '>>> ' . __('WordPress cookie keys not set.'); break; } if (!empty($data2['wp_auth_salt']['value'])) { bb_update_option('bb_auth_salt', $data2['wp_auth_salt']['value']); $installation_log[] = '>>> ' . __('WordPress "auth" cookie salt set from input.'); } if (!empty($data2['wp_secure_auth_salt']['value'])) { bb_update_option('bb_secure_auth_salt', $data2['wp_secure_auth_salt']['value']); $installation_log[] = '>>> ' . __('WordPress "secure auth" cookie salt set from input.'); } if (!empty($data2['wp_logged_in_salt']['value'])) { bb_update_option('bb_logged_in_salt', $data2['wp_logged_in_salt']['value']); $installation_log[] = '>>> ' . __('WordPress "logged in" cookie salt set from input.'); } } if ($data2['toggle_2_2']['value']) { if (!bb_get_option('bb_auth_salt') || !bb_get_option('bb_secure_auth_salt') || !bb_get_option('bb_logged_in_salt')) { $installation_log[] = '>>> ' . __('Fetching missing WordPress cookie salts.'); $_prefix = $bb->wp_table_prefix; if (!empty($data2['wordpress_mu_primary_blog_id']['value'])) { $_prefix .= $data2['wordpress_mu_primary_blog_id']['value'] . '_'; } if (isset($bb->custom_databases['user'])) { $bbdb->tables['options'] = array('user', $_prefix . 'options'); } else { $bbdb->tables['options'] = $_prefix . 'options'; } unset($_prefix); $bbdb->set_prefix($bb_table_prefix); if (!bb_get_option('bb_auth_salt')) { $wp_auth_salt = $bbdb->get_var("SELECT `option_value` FROM {$bbdb->options} WHERE `option_name` = 'auth_salt' LIMIT 1"); if ($wp_auth_salt) { bb_update_option('bb_auth_salt', $wp_auth_salt); $installation_log[] = '>>>>>> ' . __('WordPress "auth" cookie salt set.'); } else { $error_log[] = '>>> ' . __('WordPress "auth" cookie salt not set.'); $error_log[] = '>>>>>> ' . __('Could not fetch "auth" cookie salt from the WordPress options table.'); $error_log[] = '>>>>>> ' . __('You will need to manually define the "auth" cookie salt in your database.'); $installation_log[] = '>>>>>> ' . __('WordPress "auth" cookie salt not set.'); } } if (!bb_get_option('bb_secure_auth_salt')) { $wp_secure_auth_salt = $bbdb->get_var("SELECT `option_value` FROM {$bbdb->options} WHERE `option_name` = 'secure_auth_salt' LIMIT 1"); if ($wp_secure_auth_salt) { bb_update_option('bb_secure_auth_salt', $wp_secure_auth_salt); $installation_log[] = '>>>>>> ' . __('WordPress "secure auth" cookie salt set.'); } else { // This cookie salt is sometimes empty so don't error $installation_log[] = '>>>>>> ' . __('WordPress "secure auth" cookie salt not set.'); } } if (!bb_get_option('bb_logged_in_salt')) { $wp_logged_in_salt = $bbdb->get_var("SELECT `option_value` FROM {$bbdb->options} WHERE `option_name` = 'logged_in_salt' LIMIT 1"); if ($wp_logged_in_salt) { bb_update_option('bb_logged_in_salt', $wp_logged_in_salt); $installation_log[] = '>>>>>> ' . __('WordPress "logged in" cookie salt set.'); } else { $error_log[] = '>>> ' . __('WordPress "logged in" cookie salt not set.'); $error_log[] = '>>>>>> ' . __('Could not fetch "logged in" cookie salt from the WordPress options table.'); $error_log[] = '>>>>>> ' . __('You will need to manually define the "logged in" cookie salt in your database.'); $installation_log[] = '>>>>>> ' . __('WordPress "logged in" cookie salt not set.'); } } } if (!empty($data2['wp_table_prefix']['value'])) { bb_update_option('wp_table_prefix', $data2['wp_table_prefix']['value']); $installation_log[] = '>>> ' . __('User database table prefix:') . ' ' . $data2['wp_table_prefix']['value']; } if (!empty($data2['wordpress_mu_primary_blog_id']['value'])) { bb_update_option('wordpress_mu_primary_blog_id', $data2['wordpress_mu_primary_blog_id']['value']); $installation_log[] = '>>> ' . __('WordPress MU primary blog ID:') . ' ' . $data2['wordpress_mu_primary_blog_id']['value']; } if ($data2['toggle_2_3']['value']) { if (!empty($data2['user_bbdb_name']['value'])) { bb_update_option('user_bbdb_name', $data2['user_bbdb_name']['value']); $installation_log[] = '>>> ' . __('User database name:') . ' ' . $data2['user_bbdb_name']['value']; } if (!empty($data2['user_bbdb_user']['value'])) { bb_update_option('user_bbdb_user', $data2['user_bbdb_user']['value']); $installation_log[] = '>>> ' . __('User database user:'******' ' . $data2['user_bbdb_user']['value']; } if (!empty($data2['user_bbdb_password']['value'])) { bb_update_option('user_bbdb_password', $data2['user_bbdb_password']['value']); $installation_log[] = '>>> ' . __('User database password:'******' ' . $data2['user_bbdb_password']['value']; } if (!empty($data2['user_bbdb_host']['value'])) { bb_update_option('user_bbdb_host', $data2['user_bbdb_host']['value']); $installation_log[] = '>>> ' . __('User database host:') . ' ' . $data2['user_bbdb_host']['value']; } if (!empty($data2['user_bbdb_charset']['value'])) { bb_update_option('user_bbdb_charset', $data2['user_bbdb_charset']['value']); $installation_log[] = '>>> ' . __('User database character set:') . ' ' . $data2['user_bbdb_charset']['value']; } if (!empty($data2['user_bbdb_collate']['value'])) { bb_update_option('user_bbdb_collate', $data2['user_bbdb_collate']['value']); $installation_log[] = '>>> ' . __('User database collation:') . ' ' . $data2['user_bbdb_collate']['value']; } if (!empty($data2['custom_user_table']['value'])) { bb_update_option('custom_user_table', $data2['custom_user_table']['value']); $installation_log[] = '>>> ' . __('User database "user" table:') . ' ' . $data2['custom_user_table']['value']; } if (!empty($data2['custom_user_meta_table']['value'])) { bb_update_option('custom_user_meta_table', $data2['custom_user_meta_table']['value']); $installation_log[] = '>>> ' . __('User database "user meta" table:') . ' ' . $data2['custom_user_meta_table']['value']; } } } } else { $installation_log[] = '>>> ' . __('Integration not enabled'); } // Site settings passed from step 3 // These are already validated provided that the referer checks out $installation_log[] = "\n" . __('Step 3 - Site settings'); bb_update_option('name', $data3['name']['value']); $installation_log[] = '>>> ' . __('Site name:') . ' ' . $data3['name']['value']; bb_update_option('uri', $data3['uri']['value']); $installation_log[] = '>>> ' . __('Site address (URL):') . ' ' . $data3['uri']['value']; bb_update_option('from_email', $data3['keymaster_user_email']['value']); $installation_log[] = '>>> ' . __('From email address:') . ' ' . $data3['keymaster_user_email']['value']; // Create the key master $keymaster_created = false; switch ($data3['keymaster_user_type']['value']) { case 'new': // Check to see if the user login already exists if ($keymaster_user = bb_get_user($data3['keymaster_user_login']['value'], array('by' => 'login'))) { // The keymaster is an existing bbPress user $installation_log[] = '>>> ' . __('Key master could not be created!'); $installation_log[] = '>>>>>> ' . __('That login is already taken!'); $error_log[] = __('Key master could not be created!'); if ($keymaster_user->bb_capabilities['keymaster']) { // The existing user is a key master - continue $bb_current_user = bb_set_current_user($keymaster_user->ID); $installation_log[] = '>>>>>> ' . __('Existing key master entered!'); $data4['keymaster_user_password']['value'] = __('Your bbPress password'); $data3['keymaster_user_email']['value'] = $keymaster_user->user_email; bb_update_option('from_email', $keymaster_user->user_email); $installation_log[] = '>>>>>> ' . __('Re-setting admin email address.'); $keymaster_created = true; } else { // The existing user is a non-key master user - halt installation $installation_log[] = '>>>>>> ' . __('Existing user without key master role entered!'); $installation_log[] = '>>>>>>>>> ' . __('Halting installation!'); $this->step_status[4] = 'incomplete'; $this->strings[4]['h2'] = __('Installation failed!'); $this->strings[4]['messages']['error'][] = __('The key master could not be created. An existing user was found with that user login.'); $data4['installation_log']['value'] = join("\n", $installation_log); $data4['error_log']['value'] = join("\n", $error_log); return 'incomplete'; } break; } // Helper function to let us know the password that was created global $keymaster_password; function bb_get_keymaster_password($user_id, $pass) { global $keymaster_password; $keymaster_password = $pass; } add_action('bb_new_user', 'bb_get_keymaster_password', 10, 2); // Create the new user (automattically given key master role when BB_INSTALLING is true) if ($keymaster_user_id = bb_new_user($data3['keymaster_user_login']['value'], $data3['keymaster_user_email']['value'], '')) { $bb_current_user = bb_set_current_user($keymaster_user_id); $data4['keymaster_user_password']['value'] = $keymaster_password; $installation_log[] = '>>> ' . __('Key master created'); $installation_log[] = '>>>>>> ' . __('Username:'******' ' . $data3['keymaster_user_login']['value']; $installation_log[] = '>>>>>> ' . __('Email address:') . ' ' . $data3['keymaster_user_email']['value']; $installation_log[] = '>>>>>> ' . __('Password:'******' ' . $data4['keymaster_user_password']['value']; $keymaster_created = true; } else { $installation_log[] = '>>> ' . __('Key master could not be created!'); $installation_log[] = '>>>>>> ' . __('Halting installation!'); $error_log[] = __('Key master could not be created!'); $this->step_status[4] = 'incomplete'; $this->strings[4]['h2'] = __('Installation failed!'); $this->strings[4]['messages']['error'][] = __('The key master could not be created. You may need to replace bbPress with a fresh copy and start again.'); $data4['installation_log']['value'] = join("\n", $installation_log); $data4['error_log']['value'] = join("\n", $error_log); return 'incomplete'; } break; case 'old': if ($keymaster_user = bb_get_user($data3['keymaster_user_login']['value'], array('by' => 'login'))) { // The keymaster is an existing bbPress or WordPress user $bb_current_user = bb_set_current_user($keymaster_user->ID); $bb_current_user->set_role('keymaster'); $data4['keymaster_user_password']['value'] = __('Your existing password'); $installation_log[] = '>>> ' . __('Key master role assigned to existing user'); $installation_log[] = '>>>>>> ' . __('Username:'******' ' . $data3['keymaster_user_login']['value']; $installation_log[] = '>>>>>> ' . __('Email address:') . ' ' . $data3['keymaster_user_email']['value']; $installation_log[] = '>>>>>> ' . __('Password:'******' ' . $data4['keymaster_user_password']['value']; $keymaster_created = true; } else { $installation_log[] = '>>> ' . __('Key master role could not be assigned to existing user!'); $installation_log[] = '>>>>>> ' . __('Halting installation!'); $error_log[] = __('Key master could not be created!'); $this->step_status[4] = 'incomplete'; $this->strings[4]['h2'] = __('Installation failed!'); $this->strings[4]['messages']['error'][] = __('The key master could not be assigned. You may need to replace bbPress with a fresh copy and start again.'); $data4['installation_log']['value'] = join("\n", $installation_log); $data4['error_log']['value'] = join("\n", $error_log); return 'incomplete'; } break; } // Don't create an initial forum if any forums already exist if (!$bbdb->get_results('SELECT `forum_id` FROM `' . $bbdb->forums . '` LIMIT 1;')) { if ($this->language != BB_LANG) { global $locale, $l10n; $locale = BB_LANG; unset($l10n['default']); bb_load_default_textdomain(); } $description = __('Just another bbPress community'); bb_update_option('description', $description); if ($this->language != BB_LANG) { $locale = $this->language; unset($l10n['default']); bb_load_default_textdomain(); } $installation_log[] = '>>> ' . __('Description:') . ' ' . $description; if ($forum_id = bb_new_forum(array('forum_name' => $data3['forum_name']['value']))) { $installation_log[] = '>>> ' . __('Forum name:') . ' ' . $data3['forum_name']['value']; if ($this->language != BB_LANG) { $locale = BB_LANG; unset($l10n['default']); bb_load_default_textdomain(); } $topic_title = __('Your first topic'); $topic_id = bb_insert_topic(array('topic_title' => $topic_title, 'forum_id' => $forum_id, 'tags' => 'bbPress')); $post_text = __('First Post! w00t.'); bb_insert_post(array('topic_id' => $topic_id, 'post_text' => $post_text)); if ($this->language != BB_LANG) { $locale = $this->language; unset($l10n['default']); bb_load_default_textdomain(); } $installation_log[] = '>>>>>> ' . __('Topic:') . ' ' . $topic_title; $installation_log[] = '>>>>>>>>> ' . __('Post:') . ' ' . $post_text; } else { $installation_log[] = '>>> ' . __('Forum could not be created!'); $error_log[] = __('Forum could not be created!'); } } else { $installation_log[] = '>>> ' . __('There are existing forums in this database.'); $installation_log[] = '>>>>>> ' . __('No new forum created.'); $error_log[] = __('Forums already exist!'); } if (defined('BB_PLUGIN_DIR') && BB_PLUGIN_DIR && !file_exists(BB_PLUGIN_DIR)) { // Just suppress errors as this is not critical if (@mkdir(BB_PLUGIN_DIR, 0750)) { $installation_log[] = '>>> ' . sprintf(__('Making plugin directory at %s.'), BB_PLUGIN_DIR); } } if (defined('BB_THEME_DIR') && BB_THEME_DIR && !file_exists(BB_THEME_DIR)) { // Just suppress errors as this is not critical if (@mkdir(BB_THEME_DIR, 0750)) { $installation_log[] = '>>> ' . sprintf(__('Making theme directory at %s.'), BB_THEME_DIR); } } if ($keymaster_created) { $keymaster_email_message = sprintf(__("Your new bbPress site has been successfully set up at:\n\n%1\$s\n\nYou can log in to the key master account with the following information:\n\nUsername: %2\$s\nPassword: %3\$s\n\nWe hope you enjoy your new forums. Thanks!\n\n--The bbPress Team\nhttp://bbpress.org/"), bb_get_uri(null, null, BB_URI_CONTEXT_TEXT), $data3['keymaster_user_login']['value'], $data4['keymaster_user_password']['value']); if (bb_mail($data3['keymaster_user_email']['value'], __('New bbPress installation'), $keymaster_email_message)) { $installation_log[] = '>>> ' . __('Key master email sent'); } else { $installation_log[] = '>>> ' . __('Key master email not sent!'); $error_log[] = __('Key master email not sent!'); } } if (count($error_log)) { $this->strings[4]['h2'] = __('Installation completed with some errors!'); $this->strings[4]['messages']['error'][] = __('Your installation completed with some minor errors. See the error log below for more specific information.'); $installation_log[] = "\n" . __('There were some errors encountered during installation!'); } else { $this->strings[4]['messages']['message'][] = __('Your installation completed successfully.'); $installation_log[] = "\n" . __('Installation complete!'); } $this->step_status[4] = 'complete'; $data4['installation_log']['value'] = join("\n", $installation_log); $data4['error_log']['value'] = join("\n", $error_log); return 'complete'; }
require './bb-load.php'; bb_auth('logged_in'); $post_id = (int) $_POST['post_id']; $bb_post = bb_get_post($post_id); if (!$bb_post) { wp_redirect(bb_get_uri(null, null, BB_URI_CONTEXT_HEADER)); die; } if (!bb_current_user_can('edit_post', $post_id)) { bb_die(__('Sorry, post is too old.')); } bb_check_admin_referer('edit-post_' . $post_id); if (0 != $bb_post->post_status && 'all' == $_GET['view']) { // We're trying to edit a deleted post add_filter('bb_is_first_where', 'bb_no_where'); } if (bb_is_first($bb_post->post_id) && bb_current_user_can('edit_topic', $bb_post->topic_id)) { bb_insert_topic(array('topic_title' => stripslashes($_POST['topic']), 'topic_id' => $bb_post->topic_id)); } bb_insert_post(array('post_text' => stripslashes($_POST['post_content']), 'post_id' => $post_id, 'topic_id' => $bb_post->topic_id)); if ($post_id) { if ($_REQUEST['view'] === 'all') { add_filter('get_post_link', 'bb_make_link_view_all'); } $post_link = get_post_link($post_id); wp_redirect($post_link); } else { wp_redirect(bb_get_uri(null, null, BB_URI_CONTEXT_HEADER)); } exit;
function bp_forums_update_topic( $args = '' ) { global $bp; do_action( 'bbpress_init' ); $defaults = array( 'topic_id' => false, 'topic_title' => '', 'topic_text' => '' ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) ) return false; if ( !$post = bb_get_first_post( $topic_id ) ) return false; /* Update the first post */ if ( !$post = bp_forums_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position ) ) ) return false; return bp_forums_get_topic_details( $topic_id ); }
function bw_insert_tweet($t_user, $t_id, $t_title, $t_tweet, $t_tags) { //add a new topic by "Twitter User" $new_topic = bb_insert_topic(array('topic_title' => str_ireplace('#dhanswers', '', $t_title), 'topic_poster' => bw_get_id_from_user($t_user), 'forum_id' => 'general', 'tags' => $t_tags)); //add the tweet guid to the meta table for duplication bb_update_topicmeta($new_topic, 'tweetid', $t_id); //add a new post to this topic with the full tweet bb_insert_post(array('topic_id' => $new_topic, 'post_text' => $t_tweet, 'poster_id' => bw_get_id_from_user($t_user), 'poster_ip' => '127.0.0.1')); }
function bp_ning_import_insert_post($args = '') { global $bp; $defaults = array('topic_title' => '', 'topic_slug' => '', 'topic_text' => '', 'topic_poster' => $bp->loggedin_user->id, 'topic_poster_name' => $bp->loggedin_user->fullname, 'topic_last_poster' => $bp->loggedin_user->id, 'topic_last_poster_name' => $bp->loggedin_user->fullname, 'topic_start_time' => date('Y-m-d H:i:s'), 'topic_time' => date('Y-m-d H:i:s'), 'topic_open' => 1, 'topic_tags' => false, 'forum_id' => 0); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $topic_title = strip_tags($topic_title); if (empty($topic_title) || !strlen(trim($topic_title))) { return false; } if (empty($topic_slug)) { $topic_slug = sanitize_title($topic_title); } if (!($topic_id = bb_insert_topic(array('topic_title' => stripslashes($topic_title), 'topic_slug' => $topic_slug, 'topic_poster' => $topic_poster, 'topic_poster_name' => $topic_poster_name, 'topic_last_poster' => $topic_last_poster, 'topic_last_poster_name' => $topic_last_poster_name, 'topic_start_time' => $topic_start_time, 'topic_time' => $topic_time, 'topic_open' => $topic_open, 'forum_id' => (int) $forum_id, 'tags' => $topic_tags)))) { return false; } /* Now insert the first post. */ if (!bp_forums_insert_post(array('topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster))) { return false; } do_action('bp_forums_new_topic', $topic_id); return $topic_id; }