Commit 94e428f7 authored by root's avatar root Committed by lechuck

Adding plugin buddypress

parent e0dac9e4

Too many changes to show.

To preserve performance only 159 of 159+ files are displayed.
<?php
define ( 'BP_ACTIVITY_DB_VERSION', '2100' );
/* Define the slug for the component */
if ( !defined( 'BP_ACTIVITY_SLUG' ) )
define ( 'BP_ACTIVITY_SLUG', 'activity' );
require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-classes.php' );
require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-templatetags.php' );
require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-filters.php' );
function bp_activity_install() {
global $wpdb, $bp;
if ( !empty($wpdb->charset) )
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
/* Rename the old user activity cached table if needed. */
if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$wpdb->base_prefix}bp_activity_user_activity_cached%'" ) )
$wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
/* Rename fields from pre BP 1.2 */
if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'" ) )
$wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL" );
if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'" ) )
$wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL" );
}
/**
* Build the tables
*/
$sql[] = "CREATE TABLE {$bp->activity->table_name} (
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
user_id bigint(20) NOT NULL,
component varchar(75) NOT NULL,
type varchar(75) NOT NULL,
action text NOT NULL,
content longtext NOT NULL,
primary_link varchar(150) NOT NULL,
item_id varchar(75) NOT NULL,
secondary_item_id varchar(75) DEFAULT NULL,
date_recorded datetime NOT NULL,
hide_sitewide bool DEFAULT 0,
mptt_left int(11) NOT NULL DEFAULT 0,
mptt_right int(11) NOT NULL DEFAULT 0,
KEY date_recorded (date_recorded),
KEY user_id (user_id),
KEY item_id (item_id),
KEY secondary_item_id (secondary_item_id),
KEY component (component),
KEY type (type),
KEY mptt_left (mptt_left),
KEY mptt_right (mptt_right),
KEY hide_sitewide (hide_sitewide)
) {$charset_collate};";
$sql[] = "CREATE TABLE {$bp->activity->table_name_meta} (
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
activity_id bigint(20) NOT NULL,
meta_key varchar(255) DEFAULT NULL,
meta_value longtext DEFAULT NULL,
KEY activity_id (activity_id),
KEY meta_key (meta_key)
) {$charset_collate};";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql);
update_site_option( 'bp-activity-db-version', BP_ACTIVITY_DB_VERSION );
}
function bp_activity_setup_globals() {
global $bp, $current_blog;
/* Internal identifier */
$bp->activity->id = 'activity';
$bp->activity->slug = BP_ACTIVITY_SLUG;
$bp->activity->table_name = $bp->table_prefix . 'bp_activity';
$bp->activity->table_name_meta = $bp->table_prefix . 'bp_activity_meta';
$bp->activity->format_notification_function = 'bp_activity_format_notifications';
/* Register this in the active components array */
$bp->active_components[$bp->activity->slug] = $bp->activity->id;
do_action( 'bp_activity_setup_globals' );
}
add_action( 'bp_setup_globals', 'bp_activity_setup_globals' );
function bp_activity_check_installed() {
global $bp;
if ( get_site_option( 'bp-activity-db-version' ) < BP_ACTIVITY_DB_VERSION )
bp_activity_install();
}
add_action( 'admin_menu', 'bp_activity_check_installed' );
function bp_activity_setup_root_component() {
/* Register 'activity' as a root component (for RSS feed use) */
bp_core_add_root_component( BP_ACTIVITY_SLUG );
}
add_action( 'bp_setup_root_components', 'bp_activity_setup_root_component' );
function bp_activity_setup_nav() {
global $bp;
/* Add 'Activity' to the main navigation */
bp_core_new_nav_item( array( 'name' => __( 'Activity', 'buddypress' ), 'slug' => $bp->activity->slug, 'position' => 10, 'screen_function' => 'bp_activity_screen_my_activity', 'default_subnav_slug' => 'just-me', 'item_css_id' => $bp->activity->id ) );
$user_domain = ( !empty( $bp->displayed_user->domain ) ) ? $bp->displayed_user->domain : $bp->loggedin_user->domain;
$user_login = ( !empty( $bp->displayed_user->userdata->user_login ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
$activity_link = $user_domain . $bp->activity->slug . '/';
/* Add the subnav items to the activity nav item if we are using a theme that supports this */
bp_core_new_subnav_item( array( 'name' => __( 'Personal', 'buddypress' ), 'slug' => 'just-me', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_my_activity', 'position' => 10 ) );
if ( bp_is_active( 'friends' ) )
bp_core_new_subnav_item( array( 'name' => __( 'Friends', 'buddypress' ), 'slug' => BP_FRIENDS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_friends', 'position' => 20, 'item_css_id' => 'activity-friends' ) );
if ( bp_is_active( 'groups' ) )
bp_core_new_subnav_item( array( 'name' => __( 'Groups', 'buddypress' ), 'slug' => BP_GROUPS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_groups', 'position' => 30, 'item_css_id' => 'activity-groups' ) );
bp_core_new_subnav_item( array( 'name' => __( 'Favorites', 'buddypress' ), 'slug' => 'favorites', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_favorites', 'position' => 40, 'item_css_id' => 'activity-favs' ) );
bp_core_new_subnav_item( array( 'name' => sprintf( __( '@%s Mentions', 'buddypress' ), $user_login ), 'slug' => 'mentions', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_mentions', 'position' => 50, 'item_css_id' => 'activity-mentions' ) );
if ( $bp->current_component == $bp->activity->slug ) {
if ( bp_is_my_profile() ) {
$bp->bp_options_title = __( 'My Activity', 'buddypress' );
} else {
$bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
$bp->bp_options_title = $bp->displayed_user->fullname;
}
}
do_action( 'bp_activity_setup_nav' );
}
add_action( 'bp_setup_nav', 'bp_activity_setup_nav' );
function bp_activity_directory_activity_setup() {
global $bp;
if ( $bp->current_component == $bp->activity->slug && empty( $bp->current_action ) ) {
$bp->is_directory = true;
do_action( 'bp_activity_directory_activity_setup' );
bp_core_load_template( apply_filters( 'bp_activity_directory_activity_setup', 'activity/index' ) );
}
}
add_action( 'wp', 'bp_activity_directory_activity_setup', 2 );
/********************************************************************************
* Screen Functions
*
* Screen functions are the controllers of BuddyPress. They will execute when their
* specific URL is caught. They will first save or manipulate data using business
* functions, then pass on the user to a template file.
*/
function bp_activity_screen_my_activity() {
do_action( 'bp_activity_screen_my_activity' );
bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
}
function bp_activity_screen_friends() {
global $bp;
if ( !bp_is_active( 'friends' ) )
return false;
if ( !is_super_admin() )
$bp->is_item_admin = false;
do_action( 'bp_activity_screen_friends' );
bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
}
function bp_activity_screen_groups() {
global $bp;
if ( !bp_is_active( 'groups' ) )
return false;
if ( !is_super_admin() )
$bp->is_item_admin = false;
do_action( 'bp_activity_screen_groups' );
bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
}
function bp_activity_screen_favorites() {
global $bp;
if ( !is_super_admin() )
$bp->is_item_admin = false;
do_action( 'bp_activity_screen_favorites' );
bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
}
function bp_activity_screen_mentions() {
global $bp;
if ( !is_super_admin() )
$bp->is_item_admin = false;
do_action( 'bp_activity_screen_mentions' );
bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
}
function bp_activity_screen_single_activity_permalink() {
global $bp;
if ( !$bp->displayed_user->id || $bp->current_component != $bp->activity->slug )
return false;
if ( empty( $bp->current_action ) || !is_numeric( $bp->current_action ) )
return false;
/* Get the activity details */
$activity = bp_activity_get_specific( array( 'activity_ids' => $bp->current_action ) );
if ( !$activity = $activity['activities'][0] )
bp_core_redirect( $bp->root_domain );
$has_access = true;
/* Redirect based on the type of activity */
if ( $activity->component == $bp->groups->id ) {
if ( !function_exists( 'groups_get_group' ) )
bp_core_redirect( $bp->root_domain );
if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
/* Check to see if the group is not public, if so, check the user has access to see this activity */
if ( 'public' != $group->status ) {
if ( !groups_is_user_member( $bp->loggedin_user->id, $group->id ) )
$has_access = false;
}
}
}
$has_access = apply_filters( 'bp_activity_permalink_access', $has_access, &$activity );
do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
if ( !$has_access ) {
bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
if ( is_user_logged_in() )
bp_core_redirect( $bp->loggedin_user->domain );
else
bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . esc_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );
}
bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
}
/* This screen is not attached to a nav item, so we need to add an action for it. */
add_action( 'wp', 'bp_activity_screen_single_activity_permalink', 3 );
function bp_activity_screen_notification_settings() {
global $bp; ?>
<table class="notification-settings zebra" id="activity-notification-settings">
<thead>
<tr>
<th class="icon"></th>
<th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
<th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
<th class="no"><?php _e( 'No', 'buddypress' )?></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) ) ?></td>
<td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php if ( !get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) || 'yes' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) ) { ?>checked="checked" <?php } ?>/></td>
<td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php if ( 'no' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) ) { ?>checked="checked" <?php } ?>/></td>
</tr>
<tr>
<td></td>
<td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td>
<td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php if ( !get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) || 'yes' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) ) { ?>checked="checked" <?php } ?>/></td>
<td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php if ( 'no' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) ) { ?>checked="checked" <?php } ?>/></td>
</tr>
<?php do_action( 'bp_activity_screen_notification_settings' ) ?>
</tbody>
</table>
<?php
}
add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
/********************************************************************************
* Action Functions
*
* Action functions are exactly the same as screen functions, however they do not
* have a template screen associated with them. Usually they will send the user
* back to the default screen after execution.
*/
function bp_activity_action_permalink_router() {
global $bp;
if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'p' )
return false;
if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
return false;
/* Get the activity details */
$activity = bp_activity_get_specific( array( 'activity_ids' => $bp->action_variables[0] ) );
if ( !$activity = $activity['activities'][0] )
bp_core_redirect( $bp->root_domain );
$redirect = false;
/* Redirect based on the type of activity */
if ( $activity->component == $bp->groups->id ) {
if ( $activity->user_id )
$redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id . '/';
else {
if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
$redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id . '/';
}
} else
$redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
$redirect = apply_filters( 'bp_activity_permalink_redirect_url', $redirect, &$activity );
if ( !$redirect )
bp_core_redirect( $bp->root_domain );
/* Redirect to the actual activity permalink page */
bp_core_redirect( $redirect );
}
add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
function bp_activity_action_delete_activity() {
global $bp;
if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'delete' )
return false;
if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
return false;
/* Check the nonce */
check_admin_referer( 'bp_activity_delete_link' );
$activity_id = $bp->action_variables[0];
$activity = new BP_Activity_Activity( $activity_id );
/* Check access */
if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
return false;
/* Call the action before the delete so plugins can still fetch information about it */
do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
/* Now delete the activity item */
if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
else
bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
bp_core_redirect( wp_get_referer() );
}
add_action( 'wp', 'bp_activity_action_delete_activity', 3 );
function bp_activity_action_post_update() {
global $bp;
if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'post' )
return false;
/* Check the nonce */
check_admin_referer( 'post_update', '_wpnonce_post_update' );
$content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
$object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
$item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
if ( empty( $content ) ) {
bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
bp_core_redirect( wp_get_referer() );
}
if ( !(int)$item_id ) {
$activity_id = bp_activity_post_update( array( 'content' => $content ) );
} else if ( 'groups' == $object && function_exists( 'groups_post_update' ) ) {
if ( (int)$item_id ) {
$activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
}
} else
$activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
if ( !empty( $activity_id ) )
bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
else
bp_core_add_message( __( 'There was an error when posting your update, please try again.', 'buddypress' ), 'error' );
bp_core_redirect( wp_get_referer() );
}
add_action( 'wp', 'bp_activity_action_post_update', 3 );
function bp_activity_action_post_comment() {
global $bp;
if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'reply' )
return false;
/* Check the nonce */
check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
$activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
$content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
if ( empty( $content ) ) {
bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
}
$comment_id = bp_activity_new_comment( array(
'content' => $content,
'activity_id' => $activity_id,
'parent_id' => $parent_id
));
if ( !empty( $comment_id ) )
bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
else
bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
}
add_action( 'wp', 'bp_activity_action_post_comment', 3 );
function bp_activity_action_mark_favorite() {
global $bp;
if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'favorite' )
return false;
/* Check the nonce */
check_admin_referer( 'mark_favorite' );
if ( bp_activity_add_user_favorite( $bp->action_variables[0] ) )
bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
else
bp_core_add_message( __( 'There was an error marking that activity as a favorite, please try again.', 'buddypress' ), 'error' );
bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
}
add_action( 'wp', 'bp_activity_action_mark_favorite', 3 );
function bp_activity_action_remove_favorite() {
global $bp;
if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'unfavorite' )
return false;
/* Check the nonce */
check_admin_referer( 'unmark_favorite' );
if ( bp_activity_remove_user_favorite( $bp->action_variables[0] ) )
bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
else
bp_core_add_message( __( 'There was an error removing that activity as a favorite, please try again.', 'buddypress' ), 'error' );
bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
}
add_action( 'wp', 'bp_activity_action_remove_favorite', 3 );
function bp_activity_action_sitewide_feed() {
global $bp, $wp_query;
if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'feed' || $bp->displayed_user->id || $bp->groups->current_group )
return false;
$wp_query->is_404 = false;
status_header( 200 );
include_once( 'bp-activity/feeds/bp-activity-sitewide-feed.php' );
die;
}
add_action( 'wp', 'bp_activity_action_sitewide_feed', 3 );
function bp_activity_action_personal_feed() {
global $bp, $wp_query;
if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'feed' )
return false;
$wp_query->is_404 = false;
status_header( 200 );
include_once( 'bp-activity/feeds/bp-activity-personal-feed.php' );
die;
}
add_action( 'wp', 'bp_activity_action_personal_feed', 3 );
function bp_activity_action_friends_feed() {
global $bp, $wp_query;
if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'friends' || $bp->action_variables[0] != 'feed' )
return false;
$wp_query->is_404 = false;
status_header( 200 );
include_once( 'bp-activity/feeds/bp-activity-friends-feed.php' );