private function install() { global $wpdb; $sql = array(); $charset_collate = ''; //check if tables exist, //just update one table in that case require_once ABSPATH . 'wp-admin/includes/upgrade.php'; /* BuddyPress component DB schema */ if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } $bp_prefix = bp_core_get_table_prefix(); $bp_chat = bp_chat(); //install $sql_table_exists_check = "SHOW TABLES LIKE '" . $bp_prefix . "_bp_chat_%'"; if ($wpdb->get_col($sql_table_exists_check)) { ////just update the user table $sql[] = "ALTER TABLE {$bp_chat->table_name_users} MODIFY last_active_time DATETIME "; } else { //if tables do not exist $sql[] = "CREATE TABLE {$bp_chat->table_name_users} (\r\n\t\t\t\t\t\tuser_id bigint(20) NOT NULL,\r\n\t\t\t\t\t\tis_online tinyint(4) NOT NULL,\r\n\t\t\t\t\t\tlast_active_time datetime NOT NULL,\r\n\t\t\t\t\t\tstatus_message varchar(255) NOT NULL,\r\n\t\t\t\t\t\tlast_fetch_time datetime NOT NULL ,\r\n\t\t\t\t\t\tfriends_only tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t\tPRIMARY KEY (user_id)\r\n\t\t\t\t\t ) {$charset_collate};"; $sql[] = "CREATE TABLE {$bp_chat->table_name_channels} (\r\n\t\t\t\t\t\tid bigint(20) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t\tlast_message_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n\t\t\t\t\t\ttime_created datetime NOT NULL,\r\n\t\t\t\t\t\tstatus tinyint(3) unsigned NOT NULL,\r\n\t\t\t\t\t\tis_multichat tinyint(3) NOT NULL,\r\n\t\t\t\t\t\tis_open tinyint(4) NOT NULL,\r\n\t\t\t\t\t\tPRIMARY KEY (id)\r\n\t\t\t\t\t ) {$charset_collate};"; $sql[] = "CREATE TABLE {$bp_chat->table_name_channel_users} (\r\n\t\t\t\t\t\tchannel_id bigint(20) NOT NULL,\r\n\t\t\t\t\t\tuser_id bigint(20) NOT NULL,\r\n\t\t\t\t\t\tstatus varchar(32) NOT NULL,\r\n\t\t\t\t\t\thas_initiated tinyint(4) NOT NULL,\r\n\t\t\t\t\t\tKEY channel_id (channel_id,user_id)\r\n\t\t\t\t ) {$charset_collate};"; //meta data $sql[] = "CREATE TABLE {$bp_chat->table_name_messages} (\r\n\t\t\t\t\t\t\tid bigint(20) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t\t\tsender_id bigint(20) NOT NULL,\r\n\t\t\t\t\t\t\tchannel_id bigint(20) NOT NULL,\r\n\t\t\t\t\t\t\tmessage text NOT NULL,\r\n\t\t\t\t\t\t\tsent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\r\n\t\t\t\t\t\t\tPRIMARY KEY (id),\r\n\t\t\t\t\t\t\tKEY channel_id (channel_id)\r\n\t\t\t\t\t ) {$charset_collate};"; } //execute sql dbDelta($sql); update_site_option('bp-chat-db-version', BP_CHAT_DB_VERSION); }
private function setup_table_names() { $table_prefix = bp_core_get_table_prefix(); $this->table_name_users = $table_prefix . 'bp_chat_users'; $this->table_name_channels = $table_prefix . 'bp_chat_channels'; $this->table_name_channel_users = $table_prefix . 'bp_chat_channel_users'; $this->table_name_messages = $table_prefix . 'bp_chat_messages'; }
/** * Set up component global data. * * @since BuddyPress (1.9.0) * * @see BP_Component::setup_globals() for a description of arguments. * * @param array $args See BP_Component::setup_globals() for a description. */ public function setup_globals($args = array()) { // Define a slug, if necessary if (!defined('BP_NOTIFICATIONS_SLUG')) { define('BP_NOTIFICATIONS_SLUG', $this->id); } // Global tables for the notifications component $global_tables = array('table_name' => bp_core_get_table_prefix() . 'bp_notifications'); // All globals for the notifications component. // Note that global_tables is included in this array. $args = array('slug' => BP_NOTIFICATIONS_SLUG, 'has_directory' => false, 'search_string' => __('Search Notifications...', 'buddypress'), 'global_tables' => $global_tables); parent::setup_globals($args); }
function mpp_upgrade_legacy_1_0_b1_activity() { if (get_option('mpp_upgraded_1_0_b1')) { return; //already upgraded } add_option('mpp_upgraded_1_0_b1', 1); if (!get_option('mpp-settings')) { return; //mediapress was not installed earlier } if (!function_exists('buddypress')) { return; } global $wpdb; $activity_table = bp_core_get_table_prefix() . 'bp_activity_meta'; //rename _mpp_attached_media_ids key tp _mpp_attached_media_id $sql = "UPDATE {$activity_table} SET meta_key = '_mpp_attached_media_id' WHERE meta_key = '_mpp_attached_media_ids'"; $wpdb->query($sql); //add context to all Media comments $update_query = "INSERT INTO {$activity_table} (activity_id, meta_key, meta_value) \n\t\t\tSELECT activity_id, %s as meta_key, %s as meta_value FROM {$activity_table} where meta_key ='_mpp_galery_id'"; //update the context? should we? $wpdb->query($wpdb->prepare($update_query, '_mpp_context', 'gallery')); //update type $wpdb->query($wpdb->prepare($update_query, '_mpp_activity_type', 'media_upload')); //for media comments //$entries = $wpdb->get_col( "SELECT activity_id, meta_value FROM {$activity_table} WHERE meta_key = '_mpp_media_id'" ); $entries = $wpdb->get_results("SELECT activity_id, meta_value FROM {$activity_table} WHERE meta_key = '_mpp_media_id'"); $media_ids = wp_list_pluck($entries, 'meta_value'); //comments are there if (!empty($media_ids)) { _prime_post_caches($media_ids, false, false); //add parent gallery id for each of the media foreach ($entries as $entry) { $media = get_post($entry->meta_value); mpp_activity_update_gallery_id($entry->activity_id, $media->post_parent); } //update context to 'media' $update_query = "INSERT INTO {$activity_table} (activity_id, meta_key, meta_value) \n\t\t\tSELECT activity_id, %s as meta_key, %s as meta_value FROM {$activity_table} WHERE meta_key ='_mpp_media_id'"; $wpdb->query($wpdb->prepare($update_query, '_mpp_activity_type', 'media_comment')); $wpdb->query($wpdb->prepare($update_query, '_mpp_activity_type', 'media')); } }
/** * Set up bp-members global settings. * * The BP_MEMBERS_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since 1.5.0 * * @see BP_Component::setup_globals() for description of parameters. * * @param array $args See {@link BP_Component::setup_globals()}. */ public function setup_globals($args = array()) { global $wpdb; $bp = buddypress(); /** Component Globals ************************************************ */ // Define a slug, as a fallback for backpat. if (!defined('BP_MEMBERS_SLUG')) { define('BP_MEMBERS_SLUG', $this->id); } // Override any passed args. $args = array('slug' => BP_MEMBERS_SLUG, 'root_slug' => isset($bp->pages->members->slug) ? $bp->pages->members->slug : BP_MEMBERS_SLUG, 'has_directory' => true, 'directory_title' => _x('Members', 'component directory title', 'buddypress'), 'search_string' => __('Search Members...', 'buddypress'), 'global_tables' => array('table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity', 'table_name_signups' => $wpdb->base_prefix . 'signups')); parent::setup_globals($args); /** Logged in user *************************************************** */ // The core userdata of the user who is currently logged in. $bp->loggedin_user->userdata = bp_core_get_core_userdata(bp_loggedin_user_id()); // Fetch the full name for the logged in user. $bp->loggedin_user->fullname = isset($bp->loggedin_user->userdata->display_name) ? $bp->loggedin_user->userdata->display_name : ''; // Hits the DB on single WP installs so get this separately. $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin(bp_loggedin_user_id()); // The domain for the user currently logged in. eg: http://example.com/members/andy. $bp->loggedin_user->domain = bp_core_get_user_domain(bp_loggedin_user_id()); /** Displayed user *************************************************** */ // The core userdata of the user who is currently being displayed. $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id()); // Fetch the full name displayed user. $bp->displayed_user->fullname = isset($bp->displayed_user->userdata->display_name) ? $bp->displayed_user->userdata->display_name : ''; // The domain for the user currently being displayed. $bp->displayed_user->domain = bp_core_get_user_domain(bp_displayed_user_id()); /** Signup *********************************************************** */ $bp->signup = new stdClass(); /** Profiles Fallback ************************************************ */ if (!bp_is_active('xprofile')) { $bp->profile = new stdClass(); $bp->profile->slug = 'profile'; $bp->profile->id = 'profile'; } }
/** * Install database tables for the Sites component * * @since BuddyPress (1.0.0) * * @uses bp_core_set_charset() * @uses bp_core_get_table_prefix() * @uses dbDelta() */ function bp_core_install_blog_tracking() { $sql = array(); $charset_collate = bp_core_set_charset(); $bp_prefix = bp_core_get_table_prefix(); $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs (\n\t\t\t\tid bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\tuser_id bigint(20) NOT NULL,\n\t\t\t\tblog_id bigint(20) NOT NULL,\n\t\t\t\tKEY user_id (user_id),\n\t\t\t\tKEY blog_id (blog_id)\n\t\t\t) {$charset_collate};"; $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs_blogmeta (\n\t\t\t\tid bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\tblog_id bigint(20) NOT NULL,\n\t\t\t\tmeta_key varchar(255) DEFAULT NULL,\n\t\t\t\tmeta_value longtext DEFAULT NULL,\n\t\t\t\tKEY blog_id (blog_id),\n\t\t\t\tKEY meta_key (meta_key(191))\n\t\t\t) {$charset_collate};"; dbDelta($sql); }
/** * Perform database operations that must take place before the general schema upgrades. * * `dbDelta()` cannot handle certain operations - like changing indexes - so we do it here instead. * * @since 2.3.0 */ function bp_pre_schema_upgrade() { global $wpdb; $raw_db_version = (int) bp_get_db_version_raw(); $bp_prefix = bp_core_get_table_prefix(); // 2.3.0: Change index lengths to account for utf8mb4. if ($raw_db_version < 9695) { // table_name => columns. $tables = array($bp_prefix . 'bp_activity_meta' => array('meta_key'), $bp_prefix . 'bp_groups_groupmeta' => array('meta_key'), $bp_prefix . 'bp_messages_meta' => array('meta_key'), $bp_prefix . 'bp_notifications_meta' => array('meta_key'), $bp_prefix . 'bp_user_blogs_blogmeta' => array('meta_key'), $bp_prefix . 'bp_xprofile_meta' => array('meta_key')); foreach ($tables as $table_name => $indexes) { foreach ($indexes as $index) { if ($wpdb->query($wpdb->prepare("SHOW TABLES LIKE %s", bp_esc_like($table_name)))) { $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index}"); } } } } }
/** * Create/update the BuddyPress profile field. */ function set_bp_xprofile_field($field_id, $user_id, $data) { if (!defined('BP_VERSION')) { return true; } $field_id = (int) $field_id; $user_id = (int) $user_id; if (!$field_id || !$user_id) { return false; } //if (is_array($data)) $data = $data['name']; // For complex FB fields that return JSON objects if (is_array($data) && isset($data['name'])) { $data = $data['name']; } else { if (is_array($data) && isset($data[0]) && isset($data[0]['name'])) { $data = join(', ', array_map(create_function('$m', 'return $m["name"];'), $data)); } } $data = apply_filters('wdfb-profile_sync-bp-field_value', $data, $field_id, $user_id); if (!$data) { return false; } // Don't waste cycles if we don't need to $tbl_pfx = function_exists('bp_core_get_table_prefix') ? bp_core_get_table_prefix() : apply_filters('bp_core_get_table_prefix', $this->db->base_prefix); $sql = "SELECT id FROM {$tbl_pfx}bp_xprofile_data WHERE field_id={$field_id} AND user_id={$user_id}"; $id = $this->db->get_var($sql); if ($id) { $sql = "UPDATE {$tbl_pfx}bp_xprofile_data SET value='" . $data . "' WHERE id={$id}"; } else { $sql = "INSERT INTO {$tbl_pfx}bp_xprofile_data (field_id, user_id, value, last_updated) VALUES (" . (int) $field_id . ', ' . (int) $user_id . ", '" . $data . "', '" . date('Y-m-d H:i:s') . "')"; } return $this->db->query($sql); }
function buddypress_f_p_c_notice() { if (is_user_logged_in()) { $user_id = wp_get_current_user()->ID; $current_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $redirect_url = buddypress_get_redirect_url($user_id); if (strpos($current_url, $redirect_url) !== false) { global $wpdb; $bp_prefix = bp_core_get_table_prefix(); $xprofile_fields = $wpdb->get_results("SELECT `name` FROM {$bp_prefix}bp_xprofile_fields WHERE parent_id = 0 AND is_required = 1 AND id NOT IN (SELECT field_id FROM {$bp_prefix}bp_xprofile_data WHERE user_id = {$user_id} AND `value` IS NOT NULL AND `value` != '')"); $xprofile_fields_count = count($xprofile_fields); if ($xprofile_fields_count > 0) { // Assigning notification message in $message variable $message = '<div id="buddypress_fpc_message" style="color: white; font-size: 18px;font-variant: small-caps;">' . __('Complete Your Missed Profile Completion', 'Buddypress Force Profile Completion') . ' [' . $xprofile_fields_count . __(' Missing', 'Buddypress Force Profile Completion') . ']</div>'; $message .= '<ol id="buddypress_fpc_fields" class="msg_class">'; foreach ($xprofile_fields as $field) { $message .= '<li>' . $field->name . $field->description . ' <span>Required Field !</span></li>'; } $message .= '</ol>'; echo '<div id="buddypress_fpc_notice" class="notice_msg foot_1"><div id="buddypress_fpc_container" class="red">' . $message . '</div></div>'; } } } }
function bpdd_clear_db() { global $wpdb; $prefix = bp_core_get_table_prefix(); if (bp_is_active('activity')) { $sqls[] = "TRUNCATE TABLE {$prefix}bp_activity;"; $sqls[] = "TRUNCATE TABLE {$prefix}bp_activity_meta;"; } if (bp_is_active('groups')) { $sqls[] = "TRUNCATE TABLE {$prefix}bp_groups;"; $sqls[] = "TRUNCATE TABLE {$prefix}bp_groups_members;"; $sqls[] = "TRUNCATE TABLE {$prefix}bp_groups_groupmeta;"; } if (bp_is_active('messages')) { $sqls[] = "TRUNCATE TABLE {$prefix}bp_messages_recipients;"; $sqls[] = "TRUNCATE TABLE {$prefix}bp_messages_messages;"; } if (bp_is_active('friends')) { $sqls[] = "TRUNCATE TABLE {$prefix}bp_friends;"; } if (bp_is_active('xprofile')) { $sqls[] = "DELETE FROM {$prefix}bp_xprofile_data WHERE user_id > 1;"; } if (bp_is_active('forums') && bp_forums_is_installed_correctly()) { $sqls[] = "TRUNCATE TABLE {$prefix}bb_posts;"; $sqls[] = "DELETE FROM {$prefix}bb_forums WHERE forum_id > 1;"; } $sqls[] = "TRUNCATE TABLE {$prefix}bp_notifications;"; $sqls[] = "DELETE FROM {$wpdb->prefix}users WHERE ID > 1;"; $sqls[] = "DELETE FROM {$wpdb->prefix}usermeta WHERE user_id > 1;"; $sqls[] = "DELETE FROM {$wpdb->prefix}usermeta WHERE meta_key = 'total_friend_count';"; foreach ($sqls as $sql) { $wpdb->query($sql); } }
/** * SETUP MENU, ADD NAVIGATION OPTIONS * * @since BuddyBoss 2.0 * @todo: cache the amount of pics */ function setup_bp_menu() { global $wpdb, $bp; if (!isset($bp->displayed_user->id)) { return; } $photos_user_id = $bp->displayed_user->id; $activity_table = bp_core_get_table_prefix() . 'bp_activity'; $activity_meta_table = bp_core_get_table_prefix() . 'bp_activity_meta'; $groups_table = bp_core_get_table_prefix() . 'bp_groups'; // Prepare a SQL query to retrieve the activity posts // that have pictures associated with them $sql = "SELECT COUNT(*) as photo_count FROM {$activity_table} a\n\t\t\t\t\t\t\tINNER JOIN {$activity_meta_table} am ON a.id = am.activity_id\n\t\t\t\t\t\t\tLEFT JOIN (SELECT activity_id, meta_key, meta_value FROM {$activity_meta_table}\n\t\t\t\t\t\t\t WHERE meta_key = 'activityprivacy') am2 ON a.id = am2.activity_id\n\t \t\t\t\t\tLEFT JOIN (SELECT id FROM {$groups_table} WHERE status != 'public' ) grp ON a.item_id = grp.id\n\t\t\t\t\t\t\tWHERE a.user_id = %d\n\t\t\t\t\t\t\tAND (am.meta_key = 'buddyboss_pics_aid' OR am.meta_key = 'bboss_pics_aid')\n\t\t\t\t\t\t\tAND (a.component != 'groups' || a.item_id != grp.id)"; $sql = $wpdb->prepare($sql, $photos_user_id); buddyboss_log(' MENU PHOTO COUNT SQL '); buddyboss_log($sql); $photos_cnt = $wpdb->get_var($sql); /* Add 'Photos' to the main user profile navigation */ bp_core_new_nav_item(array('name' => sprintf(__('Photos <span>%d</span>', 'buddyboss'), $photos_cnt), 'slug' => BUDDYBOSS_PICS_SLUG, 'position' => 80, 'screen_function' => 'buddyboss_pics_screen_picture_grid', 'default_subnav_slug' => 'my-gallery')); $buddyboss_pics_link = $bp->displayed_user->domain . BUDDYBOSS_PICS_SLUG . '/'; bp_core_new_subnav_item(array('name' => __('Photos', 'buddyboss'), 'slug' => 'my-gallery', 'parent_slug' => BUDDYBOSS_PICS_SLUG, 'parent_url' => $buddyboss_pics_link, 'screen_function' => 'buddyboss_pics_screen_picture_grid', 'position' => 10)); }
/** * Set up bp-core global settings. * * Sets up a majority of the BuddyPress globals that require a minimal * amount of processing, meaning they cannot be set in the BuddyPress class. * * @since BuddyPress (1.5.0) * * @see BP_Component::setup_globals() for description of parameters. * * @param array $args See {@link BP_Component::setup_globals()}. */ public function setup_globals($args = array()) { $bp = buddypress(); /** Database **********************************************************/ // Get the base database prefix if (empty($bp->table_prefix)) { $bp->table_prefix = bp_core_get_table_prefix(); } // The domain for the root of the site where the main blog resides if (empty($bp->root_domain)) { $bp->root_domain = bp_core_get_root_domain(); } // Fetches all of the core BuddyPress settings in one fell swoop if (empty($bp->site_options)) { $bp->site_options = bp_core_get_root_options(); } // The names of the core WordPress pages used to display BuddyPress content if (empty($bp->pages)) { $bp->pages = bp_core_get_directory_pages(); } /** Basic current user data *******************************************/ // Logged in user is the 'current_user' $current_user = wp_get_current_user(); // The user ID of the user who is currently logged in. $bp->loggedin_user = new stdClass(); $bp->loggedin_user->id = isset($current_user->ID) ? $current_user->ID : 0; /** Avatars ***********************************************************/ // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar $bp->grav_default = new stdClass(); $bp->grav_default->user = apply_filters('bp_user_gravatar_default', $bp->site_options['avatar_default']); $bp->grav_default->group = apply_filters('bp_group_gravatar_default', $bp->grav_default->user); $bp->grav_default->blog = apply_filters('bp_blog_gravatar_default', $bp->grav_default->user); // Notifications table. Included here for legacy purposes. Use // bp-notifications instead. $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications'; /** * Used to determine if user has admin rights on current content. If the * logged in user is viewing their own profile and wants to delete * something, is_item_admin is used. This is a generic variable so it * can be used by other components. It can also be modified, so when * viewing a group 'is_item_admin' would be 'true' if they are a group * admin, and 'false' if they are not. */ bp_update_is_item_admin(bp_user_has_access(), 'core'); // Is the logged in user is a mod for the current item? bp_update_is_item_mod(false, 'core'); do_action('bp_core_setup_globals'); }
/** * Upgrade method for the older BP message thread DB table. * * @since 1.2.0 * * @todo We should remove this. No one is going to upgrade from v1.1, right? * @return bool */ public static function update_tables() { global $wpdb; $bp_prefix = bp_core_get_table_prefix(); $errors = false; $threads = $wpdb->get_results("SELECT * FROM {$bp_prefix}bp_messages_threads"); // Nothing to update, just return true to remove the table if (empty($threads)) { return true; } $bp = buddypress(); foreach ((array) $threads as $thread) { $message_ids = maybe_unserialize($thread->message_ids); if (!empty($message_ids)) { $message_ids = implode(',', $message_ids); // Add the thread_id to the messages table if (!$wpdb->query($wpdb->prepare("UPDATE {$bp->messages->table_name_messages} SET thread_id = %d WHERE id IN ({$message_ids})", $thread->id))) { $errors = true; } } } return (bool) (!$errors); }
function activity_privacy($sql, $select_sql, $from_sql, $where_sql, $sort, $pag_sql = '') { if (is_rt_admin()) { return $sql; } $sql = ''; $where = ''; global $bp, $wpdb; $rtmedia_model = new RTMediaModel(); if (is_user_logged_in()) { $user = get_current_user_id(); } else { $user = 0; } // admin has upgraded rtmedia activity so we can use rt_rtm_activity table for rtmedia related activity filters if ($this->can_use_rtm_ac_privacy()) { $rtmedia_activity_model = new RTMediaActivityModel(); $where .= " ({$this->rtm_activity_table_alias}.privacy is NULL OR {$this->rtm_activity_table_alias}.privacy <= 0) "; if ($user) { $where .= "OR (({$this->rtm_activity_table_alias}.privacy=20)"; $where .= " OR (a.user_id={$user} AND {$this->rtm_activity_table_alias}.privacy >= 40)"; if (class_exists('BuddyPress')) { if (bp_is_active('friends')) { $friendship = new RTMediaFriends(); $friends = $friendship->get_friends_cache($user); if (isset($friends) && !empty($friends)) { $in_str_arr = array_fill(0, count($friends), '%d'); $in_str = join(',', $in_str_arr); $where .= $wpdb->prepare(" OR ({$this->rtm_activity_table_alias}.privacy=40 AND a.user_id IN ({$in_str}) )", $friends); // @codingStandardsIgnoreLine } } } $where .= ')'; } if (strpos($select_sql, 'SELECT DISTINCT') === false) { $select_sql = str_replace('SELECT', 'SELECT DISTINCT', $select_sql); } $select_sql .= " ,{$this->rtm_activity_table_alias}.privacy "; $from_sql = $wpdb->prepare(" FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID LEFT JOIN {$rtmedia_activity_model->table_name} {$this->rtm_activity_table_alias} ON ( a.id = {$this->rtm_activity_table_alias}.activity_id and ra.blog_id = %d ) ", get_current_blog_id()); // @codingStandardsIgnoreLine // removed NOT EXISTS check for `rtmedia_privacy` activty meta value. // check git history for more details ;) $where_sql = $where_sql . " AND ({$where})"; $newsql = "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}"; } else { $where .= ' (m.max_privacy is NULL OR m.max_privacy <= 0) '; if ($user) { $where .= 'OR ((m.max_privacy=20)'; $where .= " OR (a.user_id={$user} AND m.max_privacy >= 40)"; if (class_exists('BuddyPress')) { if (bp_is_active('friends')) { $friendship = new RTMediaFriends(); $friends = $friendship->get_friends_cache($user); if (isset($friends) && !empty($friends)) { $where .= " OR (m.max_privacy=40 AND a.user_id IN ('" . implode("','", $friends) . "'))"; } } } $where .= ')'; } if (function_exists('bp_core_get_table_prefix')) { $bp_prefix = bp_core_get_table_prefix(); } else { $bp_prefix = ''; } if (strpos($select_sql, 'SELECT DISTINCT') === false) { $select_sql = str_replace('SELECT', 'SELECT DISTINCT', $select_sql); } $media_table = "SELECT *, max( privacy ) as max_privacy from {$rtmedia_model->table_name} group by activity_id"; $from_sql = $wpdb->prepare(" FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID LEFT JOIN ( {$media_table} ) m ON ( a.id = m.activity_id AND m.blog_id = %d ) ", get_current_blog_id()); // @codingStandardsIgnoreLine $where_sql = $where_sql . " AND (NOT EXISTS (SELECT m.activity_id FROM {$bp_prefix}bp_activity_meta m WHERE m.meta_key='rtmedia_privacy' AND m.activity_id=a.id) OR ( {$where} ) )"; $newsql = "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}"; } return $newsql; }
/** * Manages plugin install and upgrade. * * @since 2.0.2 * @global object $bp BuddyPress global settings * @global nxtdb $nxtdb NXTClass database object */ function dpa_install_and_upgrade() { global $bp, $nxtdb; $version = get_site_option('achievements-db-version'); if (false !== $version && ACHIEVEMENTS_DB_VERSION == $version) { return; } if (!$version) { $version = 0; } $charset_collate = !empty($nxtdb->charset) ? "DEFAULT CHARACTER SET {$nxtdb->charset}" : ''; $table_prefix = bp_core_get_table_prefix(); if ($version != ACHIEVEMENTS_DB_VERSION) { for ($i = $version; $i < ACHIEVEMENTS_DB_VERSION; $i++) { switch ($i) { case 0: $sql = array(); $sql[] = "CREATE TABLE {$table_prefix}achievements (\n\t\t\t\t\t\t\t\t\tid bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t\t\t\t\taction_id bigint(20) NOT NULL,\n\t\t\t\t\t\t\t\t\tpicture_id bigint(20) NOT NULL,\n\t\t\t\t\t\t\t\t\taction_count SMALLINT NOT NULL,\n\t\t\t\t\t\t\t\t\tname VARCHAR(200) NOT NULL,\n\t\t\t\t\t\t\t\t\tdescription text NOT NULL,\n\t\t\t\t\t\t\t\t\tpoints int NOT NULL,\n\t\t\t\t\t\t\t\t\tis_active int(1) NOT NULL,\n\t\t\t\t\t\t\t\t\tslug VARCHAR(200) NOT NULL,\n\t\t\t\t\t\t\t\t\tKEY action_id_is_active (action_id,is_active),\n\t\t\t\t\t\t\t\t\tKEY slug (slug(20))\n\t\t\t\t\t\t\t\t ) {$charset_collate};"; $sql[] = "CREATE TABLE {$table_prefix}achievements_unlocked (\n\t\t\t\t\t\t\t\t\tid bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t\t\t\t\tachievement_id bigint(20) NOT NULL,\n\t\t\t\t\t\t\t\t user_id bigint(20) NOT NULL,\n\t\t\t\t\t\t\t\t\tachieved_at DATETIME NOT NULL,\n\t\t\t\t\t\t\t\t\tKEY user_id (user_id),\n\t\t\t\t\t\t\t\t\tKEY achievement_id (achievement_id),\n\t\t\t\t\t\t\t\t\tKEY user_achievement_ids (user_id,achievement_id)\n\t\t\t\t\t\t\t\t ) {$charset_collate};"; $sql[] = "CREATE TABLE {$table_prefix}achievements_actions (\n\t\t\t\t\t\t\t\t\tid bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t\t\t\t\tcategory TINYTEXT NOT NULL,\n\t\t\t\t\t\t\t\t\tname text NOT NULL,\n\t\t\t\t\t\t\t\t\tdescription text NOT NULL\n\t\t\t\t\t\t\t\t ) {$charset_collate};"; require_once ABSPATH . 'nxt-admin/includes/upgrade.php'; dbDelta($sql); // Insert the default actions $actions = array(); $actions[] = array('category' => 'blog', 'name' => 'comment_post', 'description' => __("The user writes a comment on a post or page.", 'dpa')); $actions[] = array('category' => 'blog', 'name' => 'publish_post', 'description' => __("The user publishes a post or page.", 'dpa')); $actions[] = array('category' => 'members', 'name' => 'friends_friendship_requested', 'description' => __("The user sends a friendship request to someone.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_invite_user', 'description' => __("The user invites someone to join a group.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_join_group', 'description' => __("The user joins a group.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_promoted_member', 'description' => __("The user promotes a group member to a moderator or administrator.", 'dpa')); $actions[] = array('category' => 'messaging', 'name' => 'messages_message_sent', 'description' => __("The user sends or replies to a private message.", 'dpa')); $actions[] = array('category' => 'profile', 'name' => 'xprofile_updated_profile', 'description' => __("The user updates their profile.", 'dpa')); $actions[] = array('category' => 'profile', 'name' => 'bp_core_activated_user', 'description' => __("A new user activates their account.", 'dpa')); foreach ($actions as $action) { $nxtdb->insert("{$table_prefix}achievements_actions", $action); } // Per-achievement settings: number of people who have unlocked it. update_site_option('achievements_meta', array()); // 0 => array( 'no_of_unlocks' => 0 ) break; case 1: $nxtdb->query($nxtdb->prepare("ALTER TABLE {$table_prefix}achievements ADD COLUMN site_id bigint(20) NOT NULL")); $nxtdb->update("{$table_prefix}achievements", array('site_id' => BP_ROOT_BLOG), null, '%d'); break; case 2: $actions = array(); $actions[] = array('category' => 'profile', 'name' => 'xprofile_avatar_uploaded', 'description' => __("The user changes their profile's avatar.", 'dpa')); $actions[] = array('category' => 'members', 'name' => 'friends_friendship_accepted', 'description' => __("The user accepts a friendship request from someone.", 'dpa')); $actions[] = array('category' => 'members', 'name' => 'friends_friendship_rejected', 'description' => __("The user rejects a friendship request from someone.", 'dpa')); $actions[] = array('category' => 'blog', 'name' => 'trashed_post', 'description' => __("The user trashes a post or page.", 'dpa')); $actions[] = array('category' => 'messaging', 'name' => 'messages_delete_thread', 'description' => __("The user deletes a private message.", 'dpa')); $actions[] = array('category' => 'members', 'name' => 'friends_friendship_deleted', 'description' => __("The user cancels a friendship.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_created_group', 'description' => __("The user creates a group.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_leave_group', 'description' => __("The user leaves a group.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_delete_group', 'description' => __("The user deletes a group.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_new_forum_topic', 'description' => __("The user creates a new group forum topic.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_new_forum_topic_post', 'description' => __("The user replies to a group forum topic.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_delete_group_forum_post', 'description' => __("The user deletes a group forum post.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_delete_group_forum_topic', 'description' => __("The user deletes a group forum topic.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_update_group_forum_post', 'description' => __("The user modifies a group forum post.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'groups_update_group_forum_topic', 'description' => __("The user modifies a group forum topic.", 'dpa')); $actions[] = array('category' => 'groups', 'name' => 'bp_groups_posted_update', 'description' => __("The user writes a message in a group's activity stream.", 'dpa')); $actions[] = array('category' => 'profile', 'name' => 'bp_activity_posted_update', 'description' => __("The user writes a message in their activity stream.", 'dpa')); foreach ($actions as $action) { $nxtdb->insert("{$table_prefix}achievements_actions", $action); } break; case 3: $actions = array(); $actions[] = array('category' => 'members', 'name' => 'bp_activity_comment_posted', 'description' => __("The user replies to any item in any activity stream.", 'dpa')); $actions[] = array('category' => 'blog', 'name' => 'signup_finished', 'description' => __("The user creates a new site.", 'dpa')); foreach ($actions as $action) { $nxtdb->insert("{$table_prefix}achievements_actions", $action); } break; case 4: $nxtdb->query($nxtdb->prepare("CREATE INDEX name ON {$table_prefix}achievements (name(20))")); $nxtdb->query($nxtdb->prepare("CREATE INDEX action_id ON {$table_prefix}achievements (action_id)")); $nxtdb->query($nxtdb->prepare("CREATE INDEX description ON {$table_prefix}achievements (description(20))")); break; case 5: $nxtdb->query($nxtdb->prepare("ALTER TABLE {$table_prefix}achievements ADD COLUMN group_id bigint(20) NOT NULL")); $nxtdb->update("{$table_prefix}achievements", array('group_id' => -1), null, '%d'); $nxtdb->query($nxtdb->prepare("CREATE INDEX group_id ON {$table_prefix}achievements (group_id)")); break; case 6: $nxtdb->update("{$table_prefix}achievements_actions", array('name' => 'bp_core_activated_user'), array('name' => 'bp_core_account_activated'), '%s'); break; case 7: $actions = array(); $actions[] = array('category' => 'achievements', 'name' => 'dpa_points_incremented', 'description' => __("The user is awarded points by unlocking an Achievement.", 'dpa')); $actions[] = array('category' => 'achievements', 'name' => 'dpa_achievement_unlocked', 'description' => __("The user unlocks an Achievement.", 'dpa')); foreach ($actions as $action) { $nxtdb->insert("{$table_prefix}achievements_actions", $action); } break; case 8: $actions = array(); $actions[] = array('category' => 'eventpress', 'name' => 'publish_ep_event', 'description' => __("The user publishes an event.", 'dpa')); $actions[] = array('category' => 'eventpress', 'name' => 'reg_approved_ep_reg', 'description' => __("The user registers to attend an event.", 'dpa')); foreach ($actions as $action) { $nxtdb->insert("{$table_prefix}achievements_actions", $action); } break; case 9: $nxtdb->query($nxtdb->prepare("ALTER TABLE {$table_prefix}achievements_actions ADD COLUMN is_group_action int(1) NOT NULL")); $nxtdb->update("{$table_prefix}achievements_actions", array('is_group_action' => 0), null, '%d'); $nxtdb->update("{$table_prefix}achievements_actions", array('is_group_action' => 1), array('category' => 'groups'), '%d'); break; case 10: $nxtdb->update("{$table_prefix}achievements_actions", array('name' => 'groups_create_group'), array('name' => 'groups_created_group'), '%s'); break; case 11: $actions = array(); $actions[] = array('category' => 'bpmoderation', 'name' => 'bp_moderation_content_status_changed', 'description' => __("When the reported content is moderated by an administrator", 'dpa'), 'is_group_action' => 0); foreach ($actions as $action) { $nxtdb->insert("{$table_prefix}achievements_actions", $action); } break; case 12: $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'blog'), array('name' => 'bp_core_activated_user'), '%s'); $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'forum'), array('name' => 'groups_new_forum_topic'), '%s'); $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'forum'), array('name' => 'groups_new_forum_topic_post'), '%s'); $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'forum'), array('name' => 'groups_delete_group_forum_post'), '%s'); $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'forum'), array('name' => 'groups_delete_group_forum_topic'), '%s'); $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'forum'), array('name' => 'groups_update_group_forum_post'), '%s'); $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'forum'), array('name' => 'groups_update_group_forum_topic'), '%s'); $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'activitystream'), array('name' => 'bp_groups_posted_update'), '%s'); $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'activitystream'), array('name' => 'bp_activity_posted_update'), '%s'); $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'activitystream'), array('name' => 'bp_activity_comment_posted'), '%s'); $nxtdb->update("{$table_prefix}achievements_actions", array('category' => 'multisite'), array('name' => 'signup_finished'), '%s'); break; case 13: $nxtdb->update("{$table_prefix}achievements_actions", array('is_group_action' => 0), array('name' => 'groups_create_group'), '%d'); $nxtdb->update("{$table_prefix}achievements_actions", array('is_group_action' => 0), array('name' => 'groups_delete_group'), '%d'); break; case 14: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'bpprivacy', 'name' => 'bp_privacy_update_privacy_settings', 'description' => __("The user updates their privacy settings.", 'dpa'), 'is_group_action' => 0)); break; case 15: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'activitystream', 'name' => 'bp_activity_add_user_favorite', 'description' => __("The user marks any item in any activity stream as a favourite.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'activitystream', 'name' => 'bp_activity_remove_user_favorite', 'description' => __("The user removes a favourited item from any activity stream.", 'dpa'), 'is_group_action' => 0)); break; case 16: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'bpmoderation', 'name' => 'bp_moderation_content_flagged', 'description' => __("The user flags any content as inappropiate.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'bpmoderation', 'name' => 'bp_moderation_content_unflagged', 'description' => __("The user unflags content that was previously marked as inappropiate.", 'dpa'), 'is_group_action' => 0)); break; case 17: $nxtdb->update("{$table_prefix}achievements_actions", array('name' => 'draft_to_publish'), array('name' => 'publish_post'), '%s'); break; case 18: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'groups', 'name' => 'groups_demoted_member', 'description' => __("The user demotes a group member from a moderator or administrator.", 'dpa'), 'is_group_action' => 1)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'groups', 'name' => 'groups_banned_member', 'description' => __("The user bans a member from a group.", 'dpa'), 'is_group_action' => 1)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'groups', 'name' => 'groups_unbanned_member', 'description' => __("The user unbans a member from a group.", 'dpa'), 'is_group_action' => 1)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'groups', 'name' => 'groups_premote_member', 'description' => __("The user receives a promotion to group moderator or administrator.", 'dpa'), 'is_group_action' => 1)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'groups', 'name' => 'groups_demote_member', 'description' => __("The user receives a demotion from group moderator or administrator.", 'dpa'), 'is_group_action' => 1)); break; case 19: $nxtdb->query($nxtdb->prepare("CREATE INDEX is_active ON {$table_prefix}achievements (is_active)")); break; case 20: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'buddystream', 'name' => 'buddystream_twitter_activated', 'description' => __("The user succesfully authorises and connects to their Twitter account.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'buddystream', 'name' => 'buddystream_facebook_activated', 'description' => __("The user succesfully authorises and connects to their Facebook account.", 'dpa'), 'is_group_action' => 0)); break; case 21: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'buddystream', 'name' => 'buddystream_lastfm_activated', 'description' => __("The user connects to their Last.fm account.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'buddystream', 'name' => 'buddystream_youtube_activated', 'description' => __("The user connects to their YouTube account.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'buddystream', 'name' => 'buddystream_flickr_activated', 'description' => __("The user connects to their Flickr account.", 'dpa'), 'is_group_action' => 0)); break; case 22: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'inviteanyone', 'name' => 'accepted_email_invite', 'description' => __("A new user activates their account.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'inviteanyone', 'name' => 'sent_email_invite', 'description' => __("The user invites someone to join the site.", 'dpa'), 'is_group_action' => 0)); break; case 23: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'buddypresslinks', 'name' => 'bp_links_cast_vote_success', 'description' => __("The user votes on a link.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'buddypresslinks', 'name' => 'bp_links_delete_link', 'description' => __("The user deletes a link.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'buddypresslinks', 'name' => 'bp_links_posted_update', 'description' => __("The user writes a comment on a link.", 'dpa'), 'is_group_action' => 0)); break; case 24: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'buddypresslinks', 'name' => 'bp_links_create_complete', 'description' => __("The user creates a link.", 'dpa'), 'is_group_action' => 0)); break; case 25: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'jes', 'name' => 'events_event_create_complete', 'description' => __("The user creates an event.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'jes', 'name' => 'events_join_event', 'description' => __("The user registers to attend an event.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'jes', 'name' => 'events_leave_event', 'description' => __("The user cancels their registration to an event.", 'dpa'), 'is_group_action' => 0)); $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'jes', 'name' => 'events_event_deleted', 'description' => __("The user deletes an event.", 'dpa'), 'is_group_action' => 0)); break; case 26: $nxtdb->insert("{$table_prefix}achievements_actions", array('category' => 'blog', 'name' => 'nxt_login', 'description' => __("The user logs in to the site.", 'dpa'), 'is_group_action' => 0)); break; } } update_site_option('achievements-db-version', ACHIEVEMENTS_DB_VERSION); } }
function setup_globals() { global $bp; /** Database **********************************************************/ // Get the base database prefix if (empty($bp->table_prefix)) { $bp->table_prefix = bp_core_get_table_prefix(); } // The domain for the root of the site where the main blog resides if (empty($bp->root_domain)) { $bp->root_domain = bp_core_get_root_domain(); } // Fetches all of the core BuddyPress settings in one fell swoop if (empty($bp->site_options)) { $bp->site_options = bp_core_get_root_options(); } // The names of the core NXTClass pages used to display BuddyPress content if (empty($bp->pages)) { $bp->pages = bp_core_get_directory_pages(); } /** Admin Bar *********************************************************/ // Set the 'My Account' global to prevent debug notices $bp->my_account_menu_id = false; /** Component and Action **********************************************/ // Used for overriding the 2nd level navigation menu so it can be used to // display custom navigation for an item (for example a group) $bp->is_single_item = false; // Sets up the array container for the component navigation rendered // by bp_get_nav() $bp->bp_nav = array(); // Sets up the array container for the component options navigation // rendered by bp_get_options_nav() $bp->bp_options_nav = array(); // Contains an array of all the active components. The key is the slug, // value the internal ID of the component. //$bp->active_components = array(); /** Basic current user data *******************************************/ // Logged in user is the 'current_user' $current_user = nxt_get_current_user(); // The user ID of the user who is currently logged in. $bp->loggedin_user->id = $current_user->ID; /** Avatars ***********************************************************/ // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar $bp->grav_default->user = apply_filters('bp_user_gravatar_default', $bp->site_options['avatar_default']); $bp->grav_default->group = apply_filters('bp_group_gravatar_default', $bp->grav_default->user); $bp->grav_default->blog = apply_filters('bp_blog_gravatar_default', $bp->grav_default->user); // Notifications Table $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications'; /** * Used to determine if user has admin rights on current content. If the * logged in user is viewing their own profile and wants to delete * something, is_item_admin is used. This is a generic variable so it * can be used by other components. It can also be modified, so when * viewing a group 'is_item_admin' would be 'true' if they are a group * admin, and 'false' if they are not. */ bp_update_is_item_admin(bp_user_has_access(), 'core'); // Is the logged in user is a mod for the current item? bp_update_is_item_mod(false, 'core'); do_action('bp_core_setup_globals'); }
/** * GET FEED ACTIVITES */ function get_feed_activities($page = 0, $per_page = 20) { global $bp, $wpdb, $buddyboss_ajax_qs; $min = $page > 0 ? ($page - 1) * $per_page : 0; $max = ($page + 1) * $per_page; $per_page = bp_get_activity_per_page(); buddyboss_log("per page: {$per_page}"); if (isset($bp->loggedin_user) && isset($bp->loggedin_user->id) && $bp->displayed_user->id == $bp->loggedin_user->id) { $myprofile = true; } else { $myprofile = false; } $wpdb->show_errors = BUDDYBOSS_DEBUG; $user_id = $bp->displayed_user->id; $user_name = $bp->displayed_user->userdata->user_login; $filter = $bp->displayed_user->domain; buddyboss_log("Looking at {$user_id}"); // Get friend's user IDs $user_ids = friends_get_friend_user_ids($user_id, false, false); // Add logged in user to news feed results // $user_ids[] = $user_id; $user_list = implode(',', $user_ids); // buddyboss_log( $friend_id_list ); $table = bp_core_get_table_prefix() . 'bp_activity'; $table2 = bp_core_get_table_prefix() . 'bp_activity_meta'; // Default WHERE $where = "WHERE ( {$table}.user_id IN ({$user_list}) AND {$table}.type != 'activity_comment' )"; // Add when user joined a group $group_modifier = "OR ( {$table}.user_id = {$user_id} AND {$table}.component = 'groups' ) "; // If we have a filter enabled, let's handle that $ajax_qs = !empty($buddyboss_ajax_qs) ? wp_parse_args($buddyboss_ajax_qs) : false; if (is_array($ajax_qs) && isset($ajax_qs['action'])) { // Clear group modifier $group_modifier = ''; $filter_qs = $ajax_qs['action']; // Check for commas and adjust if (strpos($filter_qs, ',')) { $filters = explode(',', $filter_qs); } else { $filters = (array) $filter_qs; } // Clean each filter $filters_clean = array(); foreach ($filters as $filter) { $filters_clean[] = $wpdb->escape($filter); } $filter_sql = "AND ( {$table}.type='" . implode("' OR {$table}.type='", $filters_clean) . "' )"; $where = "WHERE ( {$table}.user_id IN ({$user_list}) {$filter_sql} )"; } // Filter where SQL $where_filtered = apply_filters('buddyboss_wall_query_feed_activity_ids_where', $where); // Filter modifier SQL $group_filtered = apply_filters('buddyboss_wall_query_feed_activity_ids_groups', $group_modifier); // Build Query $query_sql = "SELECT DISTINCT {$table}.id FROM {$table} LEFT JOIN {$table2} ON {$table}.id = {$table2}.activity_id\n\t\t\t{$where_filtered}\n\t\t\t{$group_filtered}\n\t\t\tORDER BY date_recorded DESC LIMIT {$min}, 40"; // Filter full query SQL $query_filtered = apply_filters('buddyboss_wall_query_feed_activity_ids_full', $query_sql); // Run query $activities = $wpdb->get_results($query_filtered, ARRAY_A); buddyboss_log($query_filtered); buddyboss_log($activities); if (empty($activities)) { return null; } $tmp = array(); foreach ($activities as $a) { $tmp[] = $a["id"]; } $activity_list = implode(",", $tmp); return $activity_list; }
function update_bebop_status($deleted_ids) { global $wpdb; foreach ($deleted_ids as $id) { $result = $wpdb->get_row('SELECT id FROM ' . bp_core_get_table_prefix() . "bp_bebop_oer_manager WHERE activity_stream_id = '" . $id . "'"); if (!empty($result->id)) { bebop_tables::update_oer_data($result->id, 'status', 'deleted'); bebop_tables::update_oer_data($result->id, 'activity_stream_id', ''); } } }
function get_initial_import_feeds($user_id, $extension) { global $wpdb; $return = array(); $results = $wpdb->get_results('SELECT value FROM ' . bp_core_get_table_prefix() . "bp_bebop_first_imports WHERE user_id = '" . $wpdb->escape($user_id) . "' AND extension = '" . $wpdb->escape($extension) . "'"); foreach ($results as $result) { $return[] = bebop_tables::sanitise_element($result->value); } return $return; }
function search_and_replace($old, $new) { global $wpdb; if (function_exists('bp_core_get_table_prefix')) { $bp_prefix = bp_core_get_table_prefix(); } else { $bp_prefix = $wpdb->prefix; } $sql = $wpdb->prepare("update {$bp_prefix}bp_activity set action=replace(action,%s,%s) ,content=replace(content,%s,%s), primary_link=replace(primary_link,%s,%s) where id > 0;", $old, $new, $old, $new, $old, $new); $wpdb->get_row($sql); }
/** * bp_core_setup_globals() * * Sets up default global BuddyPress configuration settings and stores * them in a $bp variable. * * @package BuddyPress Core Core * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() * @global $current_user A WordPress global containing current user information * @global $current_component Which is set up in /bp-core/bp-core-catch-uri.php * @global $current_action Which is set up in /bp-core/bp-core-catch-uri.php * @global $action_variables Which is set up in /bp-core/bp-core-catch-uri.php * @uses bp_core_get_user_domain() Returns the domain for a user */ function bp_core_setup_globals() { global $bp; global $current_user, $current_component, $current_action, $current_blog; global $displayed_user_id; global $action_variables; $current_user = wp_get_current_user(); /* Get the base database prefix */ $bp->table_prefix = bp_core_get_table_prefix(); /* The domain for the root of the site where the main blog resides */ $bp->root_domain = bp_core_get_root_domain(); /* The user ID of the user who is currently logged in. */ $bp->loggedin_user->id = $current_user->ID; /* The domain for the user currently logged in. eg: http://domain.com/members/andy */ $bp->loggedin_user->domain = bp_core_get_user_domain( $bp->loggedin_user->id ); /* The core userdata of the user who is currently logged in. */ $bp->loggedin_user->userdata = bp_core_get_core_userdata( $bp->loggedin_user->id ); /* is_super_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop. */ $bp->loggedin_user->is_super_admin = is_super_admin(); $bp->loggedin_user->is_site_admin = $bp->loggedin_user->is_super_admin; // deprecated 1.2.6 /* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */ $bp->displayed_user->id = $displayed_user_id; /* The domain for the user currently being displayed */ $bp->displayed_user->domain = bp_core_get_user_domain( $bp->displayed_user->id ); /* The core userdata of the user who is currently being displayed */ $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id ); /* The component being used eg: http://domain.com/members/andy/ [profile] */ $bp->current_component = $current_component; // type: string /* The current action for the component eg: http://domain.com/members/andy/profile/ [edit] */ $bp->current_action = $current_action; // type: string /* The action variables for the current action eg: http://domain.com/members/andy/profile/edit/ [group] / [6] */ $bp->action_variables = $action_variables; // type: array /* Only used where a component has a sub item, e.g. groups: http://domain.com/members/andy/groups/ [my-group] / home - manipulated in the actual component not in catch uri code.*/ $bp->current_item = ''; // type: string /* Used for overriding the 2nd level navigation menu so it can be used to display custom navigation for an item (for example a group) */ $bp->is_single_item = false; /* The default component to use if none are set and someone visits: http://domain.com/members/andy */ if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) { if ( defined( 'BP_ACTIVITY_SLUG' ) ) $bp->default_component = BP_ACTIVITY_SLUG; else $bp->default_component = 'profile'; } else { $bp->default_component = BP_DEFAULT_COMPONENT; } /* Fetches all of the core database based BuddyPress settings in one foul swoop */ $bp->site_options = bp_core_get_site_options(); /* Sets up the array container for the component navigation rendered by bp_get_nav() */ $bp->bp_nav = array(); /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */ $bp->bp_options_nav = array(); /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */ $bp->active_components = array(); /* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */ $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['user-avatar-default'] ); $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' ); $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' ); /* Fetch the full name for the logged in and current user */ $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id ); $bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id ); /* Used to determine if user has admin rights on current content. If the logged in user is viewing their own profile and wants to delete something, is_item_admin is used. This is a generic variable so it can be used by other components. It can also be modified, so when viewing a group 'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */ $bp->is_item_admin = bp_user_has_access(); /* Used to determine if the logged in user is a moderator for the current content. */ $bp->is_item_mod = false; $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications'; if ( !$bp->current_component && $bp->displayed_user->id ) $bp->current_component = $bp->default_component; do_action( 'bp_core_setup_globals' ); }
function activity_privacy($sql, $select_sql, $from_sql, $where_sql, $sort, $pag_sql = '') { if (is_rt_admin()) { return $sql; } $sql = ''; $where = ''; global $bp, $wpdb; $rtmedia_model = new RTMediaModel(); if (is_user_logged_in()) { $user = get_current_user_id(); } else { $user = 0; } $activity_upgrade_done = rtmedia_get_site_option('rtmedia_activity_done_upgrade'); // admin has upgraded rtmedia activity so we can use rt_rtm_activity table for rtmedia related activity filters if ($activity_upgrade_done) { $rtmedia_activity_model = new RTMediaActivityModel(); $where .= " (ra.privacy is NULL OR ra.privacy <= 0) "; if ($user) { $where .= "OR ((ra.privacy=20)"; $where .= " OR (a.user_id={$user} AND ra.privacy >= 40)"; if (class_exists('BuddyPress')) { if (bp_is_active('friends')) { $friendship = new RTMediaFriends(); $friends = $friendship->get_friends_cache($user); if (isset($friends) && !empty($friends) != "") { $where .= " OR (ra.privacy=40 AND a.user_id IN ('" . implode("','", $friends) . "'))"; } } } $where .= ')'; } if (function_exists("bp_core_get_table_prefix")) { $bp_prefix = bp_core_get_table_prefix(); } else { $bp_prefix = ""; } if (strpos($select_sql, "SELECT DISTINCT") === false) { $select_sql = str_replace("SELECT", "SELECT DISTINCT", $select_sql); } $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID LEFT JOIN {$rtmedia_model->table_name} m ON ( a.id = m.activity_id AND m.blog_id = '" . get_current_blog_id() . "' ) LEFT JOIN {$rtmedia_activity_model->table_name} ra ON ( a.id = ra.activity_id and ra.blog_id = '" . get_current_blog_id() . "' ) "; $where_sql = $where_sql . " AND (NOT EXISTS (SELECT m.activity_id FROM {$bp_prefix}bp_activity_meta m WHERE m.meta_key='rtmedia_privacy' AND m.activity_id=a.id) OR ( {$where} ) )"; $newsql = "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}"; } else { $where .= " (m.max_privacy is NULL OR m.max_privacy <= 0) "; if ($user) { $where .= "OR ((m.max_privacy=20)"; $where .= " OR (a.user_id={$user} AND m.max_privacy >= 40)"; if (class_exists('BuddyPress')) { if (bp_is_active('friends')) { $friendship = new RTMediaFriends(); $friends = $friendship->get_friends_cache($user); if (isset($friends) && !empty($friends) != "") { $where .= " OR (m.max_privacy=40 AND a.user_id IN ('" . implode("','", $friends) . "'))"; } } } $where .= ')'; } if (function_exists("bp_core_get_table_prefix")) { $bp_prefix = bp_core_get_table_prefix(); } else { $bp_prefix = ""; } if (strpos($select_sql, "SELECT DISTINCT") === false) { $select_sql = str_replace("SELECT", "SELECT DISTINCT", $select_sql); } $media_table = "SELECT *, max( privacy ) as max_privacy from {$rtmedia_model->table_name} group by activity_id"; $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID LEFT JOIN ( {$media_table} ) m ON ( a.id = m.activity_id AND m.blog_id = '" . get_current_blog_id() . "' ) "; $where_sql = $where_sql . " AND (NOT EXISTS (SELECT m.activity_id FROM {$bp_prefix}bp_activity_meta m WHERE m.meta_key='rtmedia_privacy' AND m.activity_id=a.id) OR ( {$where} ) )"; $newsql = "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}"; } return $newsql; }
/** * Setup globals * * The BP_MEMBERS_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since BuddyPress (1.5) */ public function setup_globals($args = array()) { $bp = buddypress(); // Define a slug, if necessary if (!defined('BP_MEMBERS_SLUG')) { define('BP_MEMBERS_SLUG', $this->id); } $members_globals = array('slug' => BP_MEMBERS_SLUG, 'root_slug' => isset($bp->pages->members->slug) ? $bp->pages->members->slug : BP_MEMBERS_SLUG, 'has_directory' => true, 'directory_title' => _x('Members', 'component directory title', 'buddypress'), 'global_tables' => array('table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity', 'table_name_signups' => bp_core_get_table_prefix() . 'signups'), 'search_string' => __('Search Members...', 'buddypress')); parent::setup_globals($members_globals); /** Logged in user ****************************************************/ // Fetch the full name for the logged in user $bp->loggedin_user->fullname = bp_core_get_user_displayname(bp_loggedin_user_id()); // Hits the DB on single WP installs so get this separately $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin(bp_loggedin_user_id()); // The domain for the user currently logged in. eg: http://domain.com/members/andy $bp->loggedin_user->domain = bp_core_get_user_domain(bp_loggedin_user_id()); // The core userdata of the user who is currently logged in. $bp->loggedin_user->userdata = bp_core_get_core_userdata(bp_loggedin_user_id()); /** Displayed user ****************************************************/ // The domain for the user currently being displayed $bp->displayed_user->domain = bp_core_get_user_domain(bp_displayed_user_id()); // The core userdata of the user who is currently being displayed $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id()); // Fetch the full name displayed user $bp->displayed_user->fullname = bp_core_get_user_displayname(bp_displayed_user_id()); /** Signup ***************************************************/ $bp->signup = new stdClass(); /** Profiles Fallback *************************************************/ if (!bp_is_active('xprofile')) { $bp->profile = new stdClass(); $bp->profile->slug = 'profile'; $bp->profile->id = 'profile'; } /** Default Profile Component *****************************************/ if (!defined('BP_DEFAULT_COMPONENT')) { if (bp_is_active('activity') && isset($bp->pages->activity)) { $bp->default_component = bp_get_activity_slug(); } else { $bp->default_component = 'xprofile' === $bp->profile->id ? 'profile' : $bp->profile->id; } } else { $bp->default_component = BP_DEFAULT_COMPONENT; } if (bp_displayed_user_id()) { $bp->canonical_stack['base_url'] = bp_displayed_user_domain(); if (bp_current_component()) { $bp->canonical_stack['component'] = bp_current_component(); } if (bp_current_action()) { $bp->canonical_stack['action'] = bp_current_action(); } if (!empty($bp->action_variables)) { $bp->canonical_stack['action_variables'] = bp_action_variables(); } if (!bp_current_component()) { $bp->current_component = $bp->default_component; } else { if (bp_is_current_component($bp->default_component) && !bp_current_action()) { // The canonical URL will not contain the default component unset($bp->canonical_stack['component']); } } // if we're on a spammer's profile page, only users with the 'bp_moderate' cap // can view subpages on the spammer's profile // // users without the cap trying to access a spammer's subnav page will get // redirected to the root of the spammer's profile page. this occurs by // by removing the component in the canonical stack. if (bp_is_user_spammer(bp_displayed_user_id()) && !bp_current_user_can('bp_moderate')) { unset($bp->canonical_stack['component']); } } }
function bp_update_db_stuff() { $bp_prefix = bp_core_get_table_prefix(); // Rename the old user activity cached table if needed. if ($nxtdb->get_var("SHOW TABLES LIKE '%{$bp_prefix}bp_activity_user_activity_cached%'")) { $nxtdb->query("RENAME TABLE {$bp_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}"); } // Rename fields from pre BP 1.2 if ($nxtdb->get_var("SHOW TABLES LIKE '%{$bp->activity->table_name}%'")) { if ($nxtdb->get_var("SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'")) { $nxtdb->query("ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL"); } if ($nxtdb->get_var("SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'")) { $nxtdb->query("ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL"); } } // On first installation - record all existing blogs in the system. if (!(int) $bp->site_options['bp-blogs-first-install']) { bp_blogs_record_existing_blogs(); bp_update_option('bp-blogs-first-install', 1); } if (is_multisite()) { bp_core_add_illegal_names(); } // Update and remove the message threads table if it exists if ($nxtdb->get_var("SHOW TABLES LIKE '%{$bp_prefix}bp_messages_threads%'")) { $update = BP_Messages_Thread::update_tables(); if ($update) { $nxtdb->query("DROP TABLE {$bp_prefix}bp_messages_threads"); } } }
bebop_tables::add_option('bebop_db_update_2', true); } //3 - hash secondary_item_ids $update_3 = bebop_tables::get_option_value('bebop_db_update_3'); if (!$update_3) { $update_secondary_item_id = array(); $results = $wpdb->get_results('SELECT id, secondary_item_id FROM ' . bp_core_get_table_prefix() . 'bp_bebop_oer_manager'); if (!empty($results)) { foreach ($results as $result) { $update_secondary_item_id[] = array('indices' => array('id' => $result->id), 'data' => md5($result->secondary_item_id)); } $update_array = array('secondary_item_id' => $update_secondary_item_id); $update_string = array(); foreach ($update_array as $key => $data) { $string = $key . ' = CASE '; foreach ($data as $update_data) { $indices_loop = array(); foreach ($update_data['indices'] as $index_name => $index_data) { $indices_loop[] = $index_name . ' = \'' . $index_data . '\''; } $string .= 'WHEN ' . implode(' AND ', $indices_loop) . ' THEN \'' . $update_data['data'] . '\' '; } $update_string[] = $string . 'ELSE ' . $key . ' END'; } $query = implode(', ', $update_string); $update = $wpdb->get_results('UPDATE ' . bp_core_get_table_prefix() . 'bp_bebop_oer_manager SET ' . $query); unset($update_secondary_item_id); } bebop_tables::add_option('bebop_db_update_3', true); } bebop_tables::add_option('bebop_db_version', '1.3.1');