function wordbb_select_mybb_db() { global $wpdb, $wordbb; // property_exists — Checks if the object or class has a property //if($wordbb->mybbdb) if (property_exists('wordbb', 'mybbdb')) { return; } $dbuser = get_option('wordbb_dbuser'); $dbpass = get_option('wordbb_dbpass'); $dbname = get_option('wordbb_dbname'); $dbhost = get_option('wordbb_dbhost'); if (empty($dbuser) && empty($dbpass) && empty($dbname)) { $wordbb->mybbdb =& $wpdb; return true; } if (empty($dbhost)) { $dbhost = DB_HOST; } $wordbb->mybbdb = new wpdb($dbuser, $dbpass, $dbname, $dbhost); // Output error connecting to WordPress Database if there was an error... // This does not apply if we entered separate database details for MyBB if (property_exists('mybbdb', 'error')) { if (is_wp_error($wordbb->mybbdb->error)) { $errors = array("Couldn't connect to the specified database"); wordbb_set_errors('Database configuration error. Go to <a href="options-general.php?page=wordbb-options">WordBB Options</a>', $errors, false); return false; } } return true; }
function wordbb_bridge_wp_post($id) { $post_bridge = wordbb_get_bridge(WORDBB_POST, $id); $post = get_post($id); if (get_option('wordbb_create_thread_excerpt') == "on") { $post_content = wordbb_get_post_teaser($post); } else { $post_content = wordbb_filter_post_content($post->post_content); } if (get_option('wordbb_create_thread_post_link') == "on") { $link_text = get_option('wordbb_create_thread_post_link_text'); if (empty($link_text)) { $link_text = __('Read the full article on the blog.'); } $link_text = str_replace('%title%', $post->post_title, $link_text); $link = '<a class="wordbb-full-post" href="' . get_permalink($id) . '" title="' . $post->post_title . '">' . $link_text . '</a>'; if (get_option('wordbb_create_thread_post_link_place') == 'before') { $post_content = $link . '<br />' . $post_content; } else { $post_content = $post_content . '<br />' . $link; } } $categories = get_the_category($post->ID); foreach ($categories as $category) { // get mybb forum corresponding to wp post category $fid = false; $bridge = wordbb_get_bridge(WORDBB_CAT, $category->cat_ID); if ($bridge) { $fid = $bridge->mybb_id; } if (empty($fid)) { // if a bridge was not found, use default forum $fid = get_option('wordbb_post_forum'); if (empty($fid)) { // still nothing, give up continue; } } // get mybb user corresponding to wp post author $uid = false; $bridge = wordbb_get_bridge(WORDBB_USER, $post->post_author); if ($bridge) { $uid = $bridge->mybb_id; } if (empty($uid)) { // if a bridge was not found, use default author $post_author = wordbb_get_user_info_by_username(get_option('wordbb_post_author')); if (!empty($post_author)) { $uid = $post_author->uid; } if (!$uid) { return; } } if ($post_bridge) { $params = array(); $params['tid'] = $post_bridge->mybb_id; $params['subject'] = $post->post_title; $params['message'] = $post_content; $params['fid'] = $fid; $params['uid'] = $uid; $params['ip'] = wordbb_get_ip(); $ret = wordbb_do_action('update_thread', $params); if (is_array($ret)) { wordbb_set_errors($post->post_title, $ret); return; } } else { $params = array(); $params['subject'] = $post->post_title; $params['message'] = $post_content; $params['fid'] = $fid; $params['uid'] = $uid; $params['ip'] = wordbb_get_ip(); $ret = wordbb_do_action('create_thread', $params); if (is_array($ret)) { if (!isset($ret['tid'])) { wordbb_set_errors($post->post_title, $ret); return; } // create bridge wordbb_bridge(WORDBB_POST, $id, $ret['tid'], WORDBB_WP); } } } }