本文整理汇总了PHP中bp_core_get_table_prefix函数的典型用法代码示例。如果您正苦于以下问题:PHP bp_core_get_table_prefix函数的具体用法?PHP bp_core_get_table_prefix怎么用?PHP bp_core_get_table_prefix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bp_core_get_table_prefix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
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);
}
示例2: setup_table_names
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';
}
示例3: setup_globals
/**
* 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);
}
示例4: mpp_upgrade_legacy_1_0_b1_activity
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'));
}
}
示例5: setup_globals
/**
* 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';
}
}
示例6: bp_core_install_blog_tracking
/**
* 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);
}
示例7: bp_pre_schema_upgrade
/**
* 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}");
}
}
}
}
}
示例8: set_bp_xprofile_field
/**
* 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);
}
示例9: buddypress_f_p_c_notice
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>';
}
}
}
}
开发者ID:NitinPrakash,项目名称:buddypress-force-profile-completion,代码行数:24,代码来源:buddy-press-force-profile-completion.php
示例10: bpdd_clear_db
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);
}
}
示例11: setup_bp_menu
/**
* 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));
}
示例12: setup_globals
/**
* 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');
}
示例13: update_tables
/**
* 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);
}
示例14: activity_privacy
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;
}
示例15: dpa_install_and_upgrade
/**
* 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) {
//.........这里部分代码省略.........