contents->content_types->{$slug}->slug = $slug; $bp->contents->content_types->{$slug}->id = $id; $bp->contents->content_types->{$slug}->title = $title; $bp->contents->content_types->{$slug}->multi_source = $multi_source; } // Add bpc as a root component in bp function oci_setup_root_component() { bp_core_add_root_component( OCI_CONTENTS_SLUG ); } add_action( 'plugins_loaded', 'oci_setup_root_component', 1 ); function oci_setup_globals() { global $wpdb, $bp, $wp_taxonomies; $bp->contents->items->table_name = $wpdb->base_prefix . 'bpc_items'; $bp->contents->meta->table_name = $wpdb->base_prefix . 'bpc_meta'; $bp->contents->terms->table_name = $wpdb->base_prefix . 'bpc_terms'; $bp->contents->term_taxonomy->table_name = $wpdb->base_prefix . 'bpc_term_taxonomy'; $bp->contents->term_relationships->table_name = $wpdb->base_prefix . 'bpc_term_relationships'; $bp->contents->actions = array(OCI_TAG, OCI_CATEGORY); $bp->contents->image_base = WP_PLUGIN_URL . '/bpcontents/images'; $bp->contents->slug = OCI_CONTENTS_SLUG; $bp->version_numbers->contents = OCI_CONTENTS_VERSION; } add_action( 'plugins_loaded', 'oci_setup_globals', 5); add_action( 'admin_menu', 'oci_setup_globals', 1); /** * oci_install() * * Creates the tables or updates them when site admin vistis the backend of wpmu. * * @global $wpdb wordpress global db object instance * @global $oci bpc global var instance * @global $ocitree bpc global mptt tree object */ function oci_install() { global $wpdb, $bp; if ( !empty($wpdb->charset) ) $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; $sql[] = "CREATE TABLE {$bp->contents->items->table_name} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, date_created datetime NOT NULL, date_updated datetime NOT NULL, item_type varchar(9) NOT NULL, item_id varchar(20) NOT NULL, item_source varchar(20) NOT NULL, item_status varchar(20) NOT NULL, PRIMARY KEY id (id), KEY source_id (item_type, item_source, item_id) KEY date_updated (date_created) ) {$charset_collate};"; $sql[] .= "CREATE TABLE {$bp->contents->meta->table_name} ( meta_id bigint(20) NOT NULL AUTO_INCREMENT, object_type varchar(32) NOT NULL default '', object_source varchar(255) NOT NULL default '', object_division varchar(255) NOT NULL default '', object_id varchar(255) NOT NULL default '', meta_key varchar(255) NOT NULL default '', meta_value longtext, PRIMARY KEY meta_id (meta_id), KEY object_key (object_type, object_source, object_division, object_id), KEY object_id_key (object_type, object_id), KEY object_meta_key (object_type, meta_key) ) {$charset_collate};"; $sql[] .= "CREATE TABLE {$bp->contents->terms->table_name} ( term_id bigint(20) unsigned NOT NULL auto_increment, name varchar(200) NOT NULL default '', slug varchar(200) NOT NULL default '', term_group bigint(10) NOT NULL default 0, PRIMARY KEY (term_id), UNIQUE KEY slug (slug), KEY name (name) ) {$charset_collate};"; $sql[] .= "CREATE TABLE {$bp->contents->term_taxonomy->table_name} ( term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment, term_id bigint(20) unsigned NOT NULL default 0, taxonomy varchar(32) NOT NULL default '', description longtext NOT NULL, parent bigint(20) unsigned NOT NULL default 0, count bigint(20) NOT NULL default 0, PRIMARY KEY (term_taxonomy_id), UNIQUE KEY term_id_taxonomy (term_id,taxonomy), KEY taxonomy (taxonomy) ) {$charset_collate};"; $sql[] .= "CREATE TABLE {$bp->contents->term_relationships->table_name} ( object_id bigint(20) unsigned NOT NULL default 0, term_taxonomy_id bigint(20) unsigned NOT NULL default 0, term_order int(11) NOT NULL default 0, PRIMARY KEY (object_id,term_taxonomy_id), KEY term_taxonomy_id (term_taxonomy_id) ) {$charset_collate};"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); update_site_option( 'bpc-contents-db-version', OCI_CONTENTS_DB_VERSION ); } function oci_copy_10_to_11_taxonomies(){ // for all old tag taxonomies $taxs = array(OCI_DEFAULT_TAG_TAXONOMY, OCI_SITE_WIDE_USER_TAG_TAXONOMY, OCI_SITE_WIDE_GROUP_TAG_TAXONOMY, OCI_SITE_WIDE_BLOG_TAG_TAXONOMY); foreach ($taxs as $tax){ $args = array('get' => 'all'); $terms = get_terms($tax, $args); foreach($terms as $term){ oci_insert_term($term->name, $tax, array('description' => $term->description)); } $terms = get_terms($tax, $args); foreach($terms as $term){ $items = get_objects_in_term($term->term_id, $tax); foreach ($items as $item){ $tt_ids = oci_set_object_terms((int)$item, $term->name, $tax, true); } unset($items); } unset($terms); } // for all old cat taxonomies $taxs = array(OCI_SITE_WIDE_USER_CATEGORY_TAXONOMY, OCI_SITE_WIDE_GROUP_CATEGORY_TAXONOMY, OCI_SITE_WIDE_BLOG_CATEGORY_TAXONOMY); foreach ($taxs as $tax){ $args = array('get' => 'all'); $terms = get_terms($tax, $args); foreach($terms as $term){ $ctt_id = oci_insert_term($term->name, $tax); if ($term->parent){ $parent_term = get_term($term->parent, $tax); $ptt_id = oci_insert_term($parent_term->name, $tax); $cat = array('parent' => $ptt_id['term_id']); oci_update_term($ctt_id['term_id'], $tax, $cat); } } reset($terms); foreach($terms as $term){ $items = get_objects_in_term($term->term_id, $tax); foreach ($items as $item){ $tt_ids = oci_set_object_terms((int)$item, $term->name, $tax, true); } unset($items); } unset($terms); } // update sitewide cats $taxs = array(OCI_SITE_WIDE_USER_CATEGORY_TAXONOMY, OCI_SITE_WIDE_GROUP_CATEGORY_TAXONOMY, OCI_SITE_WIDE_BLOG_CATEGORY_TAXONOMY); foreach ($taxs as $tax){ $args = array('get' => 'all'); $terms = get_terms($tax, $args); foreach($terms as $term){ $ctt_id = oci_insert_term($term->name, OCI_DEFAULT_CATEGORY_TAXONOMY); if ($term->parent){ $parent_term = get_term($term->parent, $tax); $ptt_id = oci_insert_term($parent_term->name, OCI_DEFAULT_CATEGORY_TAXONOMY); $cat = array('parent' => $ptt_id['term_id']); oci_update_term($ctt_id['term_id'], OCI_DEFAULT_CATEGORY_TAXONOMY, $cat); } } reset($terms); foreach($terms as $term){ $items = get_objects_in_term($term->term_id, $tax); foreach ($items as $item){ $tt_ids = oci_set_object_terms((int)$item, $term->name, OCI_DEFAULT_CATEGORY_TAXONOMY, true); } unset($items); } unset($terms); } update_site_option( 'bpc-contents-11-upgrade', 1); } /** * oci_check_installed() * * Standard bp mechanism to check if the tables are installed or need upgrading. * * @global $wpdb * @global $oci * @global $ocitree */ function oci_check_installed() { global $wpdb, $bp; if ( is_site_admin() ) { /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */ if ( ( false == $wpdb->get_var("show tables like '%{$bp->contents->items->table_name}%'") ) || ( get_site_option('bpc-contents-db-version') < OCI_CONTENTS_DB_VERSION ) ) oci_install(); if (!get_site_option('bpc-contents-11-upgrade')) oci_copy_10_to_11_taxonomies(); } } add_action( 'admin_menu', 'oci_check_installed' ); /** * oci_add_structure_css() * * Queues the bpc CSS file. */ function oci_add_structure_css() { /* Enqueue the structure CSS file to give basic positional formatting for components */ wp_enqueue_style( 'oci-contents-structure', WP_PLUGIN_URL . '/bpcontents/css/structure.css' ); } add_action( 'bp_styles', 'oci_add_structure_css' ); /** * oci_setup_nav() * * Sets up the bpc nav items in member profile, group home and blog admin. * */ function oci_setup_nav() { global $bp; bp_core_add_nav_item( __('Contents', 'bpcontents'), $bp->contents->slug); bp_core_add_nav_default( $bp->contents->slug, 'oci_screen_profile_contents', 'profile', false ); } add_action( 'wp', 'oci_setup_nav', 2 ); add_action( 'admin_menu', 'oci_setup_nav', 2 ); function oci_force_buddypress_theme( $template ) { global $bp; if ( $bp->current_component == $bp->contents->slug && empty( $bp->current_action ) ) { $member_theme = get_site_option( 'active-member-theme' ); if ( empty( $member_theme ) ) $member_theme = 'bpmember'; add_filter( 'theme_root', 'bp_core_filter_buddypress_theme_root' ); add_filter( 'theme_root_uri', 'bp_core_filter_buddypress_theme_root_uri' ); return $member_theme; } else { return $template; } } add_filter( 'template', 'oci_force_buddypress_theme', 1, 1 ); function oci_force_buddypress_stylesheet( $stylesheet ) { global $bp; if ( $bp->current_component == $bp->contents->slug && empty( $bp->current_action ) ) { $member_theme = get_site_option( 'active-member-theme' ); if ( empty( $member_theme ) ) $member_theme = 'bpmember'; add_filter( 'theme_root', 'bp_core_filter_buddypress_theme_root' ); add_filter( 'theme_root_uri', 'bp_core_filter_buddypress_theme_root_uri' ); return $member_theme; } else { return $stylesheet; } } add_filter( 'stylesheet', 'oci_force_buddypress_stylesheet', 1, 1 ); ?>