pag_page = isset( $_REQUEST['acpage'] ) ? intval( $_REQUEST['acpage'] ) : $page;
$this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
if ( !empty( $include ) ) {
/* Fetch specific activity items based on ID's */
$this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments ) );
} else {
$this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden ) );
}
if ( !$max || $max >= (int)$this->activities['total'] )
$this->total_activity_count = (int)$this->activities['total'];
else
$this->total_activity_count = (int)$max;
$this->activities = $this->activities['activities'];
if ( $max ) {
if ( $max >= count($this->activities) )
$this->activity_count = count($this->activities);
else
$this->activity_count = (int)$max;
} else {
$this->activity_count = count($this->activities);
}
$this->full_name = $bp->displayed_user->fullname;
if ( (int) $this->total_activity_count && (int) $this->pag_num ) {
$this->pag_links = paginate_links( array(
'base' => add_query_arg( 'acpage', '%#%' ),
'format' => '',
'total' => ceil( (int)$this->total_activity_count / (int)$this->pag_num ),
'current' => (int)$this->pag_page,
'prev_text' => '←',
'next_text' => '→',
'mid_size' => 1
));
}
}
function has_activities() {
if ( $this->activity_count )
return true;
return false;
}
function next_activity() {
$this->current_activity++;
$this->activity = $this->activities[$this->current_activity];
return $this->activity;
}
function rewind_activities() {
$this->current_activity = -1;
if ( $this->activity_count > 0 ) {
$this->activity = $this->activities[0];
}
}
function user_activities() {
if ( $this->current_activity + 1 < $this->activity_count ) {
return true;
} elseif ( $this->current_activity + 1 == $this->activity_count ) {
do_action('activity_loop_end');
// Do some cleaning up after the loop
$this->rewind_activities();
}
$this->in_the_loop = false;
return false;
}
function the_activity() {
global $activity;
$this->in_the_loop = true;
$this->activity = $this->next_activity();
if ( is_array( $this->activity ) )
$this->activity = (object) $this->activity;
if ( $this->current_activity == 0 ) // loop has just started
do_action('activity_loop_start');
}
}
function bp_has_activities( $args = '' ) {
global $bp, $activities_template;
/* Note: any params used for filtering can be a single value, or multiple values comma separated. */
$defaults = array(
'display_comments' => false, // false for none, stream/threaded - show comments in the stream or threaded under items
'include' => false, // pass an activity_id or string of ID's comma separated
'sort' => 'DESC', // sort DESC or ASC
'page' => 1, // which page to load
'per_page' => 25, // number of items per page
'max' => false, // max number to return
'show_hidden' => false, // Show activity items that are hidden site-wide?
/* Filtering */
'user_id' => false, // user_id to filter on
'object' => false, // object to filter on e.g. groups, profile, status, friends
'action' => false, // action to filter on e.g. activity_update, new_forum_post, profile_updated
'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
/* Searching */
'search_terms' => false // specify terms to search on
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
if ( ( 'personal' == $type || 'friends' == $type ) && !$user_id )
$user_id = (int)$bp->displayed_user->id;
if ( $max ) {
if ( $per_page > $max )
$per_page = $max;
}
/* Support for permalinks on single item pages: /groups/my-group/activity/124/ */
if ( $bp->current_action == $bp->activity->slug )
$include = $bp->action_variables[0];
/* Support for basic filters in earlier BP versions. */
if ( isset( $_GET['afilter'] ) )
$filter = array( 'object' => $_GET['afilter'] );
else
$filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
$activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
return apply_filters( 'bp_has_activities', $activities_template->has_activities(), &$activities_template );
}
function bp_activities() {
global $activities_template;
return $activities_template->user_activities();
}
function bp_the_activity() {
global $activities_template;
return $activities_template->the_activity();
}
function bp_activity_pagination_count() {
global $bp, $activities_template;
$from_num = bp_core_number_format( intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1 );
$to_num = bp_core_number_format( ( $from_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $from_num + ( $activities_template->pag_num - 1 ) );
$total = bp_core_number_format( $activities_template->total_activity_count );
echo sprintf( __( 'Viewing item %s to %s (of %s items)', 'buddypress' ), $from_num, $to_num, $total ); ?>
pag_links );
}
function bp_activity_count() {
echo bp_get_activity_count();
}
function bp_get_activity_count() {
global $activities_template;
return apply_filters( 'bp_get_activity_count', (int)$activities_template->activity_count );
}
function bp_activity_per_page() {
echo bp_get_activity_per_page();
}
function bp_get_activity_per_page() {
global $activities_template;
return apply_filters( 'bp_get_activity_per_page', (int)$activities_template->pag_num );
}
function bp_activities_title() {
global $bp_activity_title;
echo bp_get_activities_title();
}
function bp_get_activities_title() {
global $bp_activity_title;
return apply_filters( 'bp_get_activities_title', $bp_activity_title );
}
function bp_activities_no_activity() {
global $bp_activity_no_activity;
echo bp_get_activities_no_activity();
}
function bp_get_activities_no_activity() {
global $bp_activity_no_activity;
return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
}
function bp_activity_id() {
echo bp_get_activity_id();
}
function bp_get_activity_id() {
global $activities_template;
return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );
}
function bp_activity_item_id() {
echo bp_get_activity_item_id();
}
function bp_get_activity_item_id() {
global $activities_template;
return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );
}
function bp_activity_secondary_item_id() {
echo bp_get_activity_secondary_item_id();
}
function bp_get_activity_secondary_item_id() {
global $activities_template;
return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );
}
function bp_activity_date_recorded() {
echo bp_get_activity_date_recorded();
}
function bp_get_activity_date_recorded() {
global $activities_template;
return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );
}
function bp_activity_object_name() {
echo bp_get_activity_object_name();
}
function bp_get_activity_object_name() {
global $activities_template;
return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );
}
function bp_activity_type() {
echo bp_get_activity_type();
}
function bp_get_activity_type() {
global $activities_template;
return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );
}
function bp_activity_action_name() { echo bp_activity_type(); }
function bp_get_activity_action_name() { return bp_get_activity_type(); }
function bp_activity_user_id() {
echo bp_get_activity_user_id();
}
function bp_get_activity_user_id() {
global $activities_template;
return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );
}
function bp_activity_user_link() {
echo bp_get_activity_user_link();
}
function bp_get_activity_user_link() {
global $activities_template;
return apply_filters( 'bp_get_activity_user_link', bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login ) );
}
function bp_activity_avatar( $args = '' ) {
echo bp_get_activity_avatar( $args );
}
function bp_get_activity_avatar( $args = '' ) {
global $bp, $activities_template;
$defaults = array(
'type' => 'thumb',
'width' => 20,
'height' => 20,
'class' => 'avatar',
'alt' => __( 'Avatar', 'buddypress' ),
'email' => false
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$item_id = false;
if ( (int)$activities_template->activity->user_id )
$item_id = $activities_template->activity->user_id;
else if ( $activities_template->activity->item_id )
$item_id = $activities_template->activity->item_id;
$object = 'user';
if ( $bp->groups->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id )
$object = 'group';
if ( $bp->blogs->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id )
$object = 'blog';
$object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component, $object );
/* If this is a user object pass the users' email address for Gravatar so we don't have to refetch it. */
if ( 'user' == $object && empty($email) )
$email = $activities_template->activity->user_email;
return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
}
function bp_activity_action() {
echo bp_get_activity_action();
}
function bp_get_activity_action() {
global $activities_template;
return apply_filters( 'bp_get_activity_action', bp_activity_content_filter( $activities_template->activity->action, $activities_template->activity->date_recorded ), $activities_template->activity->component, $activities_template->activity->type );
}
function bp_activity_content_body() {
echo bp_get_activity_content_body();
}
function bp_get_activity_content_body() {
global $activities_template;
if ( empty( $activities_template->activity->action ) )
$activities_template->activity->content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded );
return apply_filters( 'bp_get_activity_content_body', $activities_template->activity->content );
}
function bp_activity_content() {
echo bp_get_activity_content();
}
function bp_get_activity_content() {
global $activities_template;
if ( empty( $activities_template->activity->action ) )
$content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded );
else {
$content = bp_activity_content_filter( $activities_template->activity->action, $activities_template->activity->date_recorded );
$content .= $activities_template->activity->content;
}
return apply_filters( 'bp_get_activity_content', $content, $activities_template->activity->component, $activities_template->activity->type );
}
function bp_activity_content_filter( $content, $date_recorded ) {
global $activities_template, $bp;
if ( !$content )
return false;
/* Split the content so we don't evaluate and replace text on content we don't want to */
$content = explode( '%s', $content );
/* Re-add the exploded %s */
$content[0] .= '%s';
/* Insert the time since */
$content[0] = bp_activity_insert_time_since( $content[0], $date_recorded );
/* Add the permalink */
$meta = ' · ' . __( 'View', 'buddypress' ) . '';
/* Add the delete link if the user has permission on this item */
if ( ( $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || is_site_admin() )
$meta .= ' · ' . bp_get_activity_delete_link();
$content[1] = $meta . '' . $content[1];
$content_new = '';
for ( $i = 0; $i < count($content); $i++ )
$content_new .= $content[$i];
return apply_filters( 'bp_activity_content_filter', $content_new );
}
function bp_activity_parent_content( $args = '' ) {
echo bp_get_activity_parent_content($args);
}
function bp_get_activity_parent_content( $args = '' ) {
global $bp, $activities_template;
$defaults = array(
'hide_user' => false
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
/* Get the ID of the parent activity content */
if ( !$parent_id = $activities_template->activity->item_id )
return false;
/* Get the content of the parent by first checking to see if we already have it */
$parent_activity = false;
foreach( $activities_template->activities as $activity ) {
if ( $parent_id == $activity->id ) {
/* Need a copy not a reference, this was the only PHP4 compat way I could find. */
$parent_activity = (array)$activity;
$parent_activity = (object)$parent_activity;
}
}
/* We didn't find it, so let's get it from the DB */
if ( !$parent_activity ) {
$parent_activity = bp_activity_get_specific( array( 'activity_ids' => $parent_id ) );
$parent_activity = $parent_activity['activities'][0];
}
if ( !$parent_activity )
return false;
/* Remove the time since content */
$parent_activity->content = str_replace( '%s', '', $parent_activity->content );
/* Remove images */
$parent_activity->content = preg_replace( '/]*>/Ui', '', $parent_activity->content );
return apply_filters( 'bp_get_activity_parent_content', $parent_activity->content );
}
function bp_activity_is_favorite() {
echo bp_get_is_activity_favorite();
}
function bp_get_activity_is_favorite() {
global $bp, $activities_template;
$my_favs = maybe_unserialize( get_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities' ) );
return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array)$my_favs ) );
}
function bp_activity_comments( $args = '' ) {
echo bp_activity_get_comments( $args );
}
function bp_activity_get_comments( $args = '' ) {
global $activities_template, $bp;
if ( !$activities_template->activity->children )
return false;
$comments_html = bp_activity_recurse_comments( $activities_template->activity );
return apply_filters( 'bp_activity_get_comments', $comments_html );
}
/* TODO: The HTML in this function is temporary and will be moved to the template in a future version. */
function bp_activity_recurse_comments( $comment ) {
global $activities_template, $bp;
if ( !$comment->children )
return false;
$content .= '
'; $after = '
'; break; case 'span': $tag = 'span'; $before = ''; $after = ''; break; } $link = add_query_arg( 'afilter', $component ); $link = remove_query_arg( 'acpage' , $link ); $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component ); /* Make sure all core internal component names are translatable */ $translatable_components = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) ); $component_links[] = $before . '' . ucwords( __( $component, 'buddypress' ) ) . '' . $after; } $link = remove_query_arg( 'afilter' , $link ); if ( isset( $_GET['afilter'] ) ) $component_links[] = '<' . $tag . ' id="afilter-clear">' . __( 'Clear Filter', 'buddypress' ) . '' . $tag . '>'; return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) ); } function bp_activity_can_comment() { global $bp; if ( false === get_site_option( 'bp-disable-blogforum-comments' ) || (int)get_site_option( 'bp-disable-blogforum-comments' ) ) { if ( 'new_blog_post' == bp_get_activity_action_name() || 'new_blog_comment' == bp_get_activity_action_name() || 'new_forum_topic' == bp_get_activity_action_name() || 'new_forum_post' == bp_get_activity_action_name() ) return false; } if ( 'activity_comment' == bp_get_activity_action_name() ) return false; return true; } function bp_total_favorite_count_for_user( $user_id = false ) { echo bp_get_total_favorite_count_for_user( $user_id ); } function bp_get_total_favorite_count_for_user( $user_id = false ) { return apply_filters( 'bp_get_total_favorite_count_for_user', bp_activity_total_favorites_for_user( $user_id ) ); } function bp_total_mention_count_for_user( $user_id = false ) { echo bp_get_total_favorite_count_for_user( $user_id ); } function bp_get_total_mention_count_for_user( $user_id = false ) { return apply_filters( 'bp_get_total_mention_count_for_user', get_usermeta( $user_id, 'bp_new_mention_count' ) ); } function bp_send_public_message_link() { echo bp_get_send_public_message_link(); } function bp_get_send_public_message_link() { global $bp; return apply_filters( 'bp_get_send_public_message_link', $bp->loggedin_user->domain . $bp->activity->slug . '/?r=' . bp_core_get_username( $bp->displayed_user->user_id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ) ); } /* RSS Feed Template Tags ***************************/ function bp_sitewide_activity_feed_link() { echo bp_get_sitewide_activity_feed_link(); } function bp_get_sitewide_activity_feed_link() { global $bp; return apply_filters( 'bp_get_sitewide_activity_feed_link', site_url( $bp->activity->slug . '/feed/' ) ); } function bp_member_activity_feed_link() { echo bp_get_member_activity_feed_link(); } function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link(); } function bp_get_member_activity_feed_link() { global $bp; if ( ( $bp->current_component == $bp->profile->slug ) || 'just-me' == $bp->current_action ) return apply_filters( 'bp_get_activities_member_rss_link', $bp->displayed_user->domain . $bp->activity->slug . '/feed/' ); else return apply_filters( 'bp_get_activities_member_rss_link', $bp->displayed_user->domain . $bp->activity->slug . '/my-friends/feed/' ); } function bp_get_activities_member_rss_link() { return bp_get_member_activity_feed_link(); } /* Template tags for RSS feed output */ function bp_activity_feed_item_guid() { echo bp_get_activity_feed_item_guid(); } function bp_get_activity_feed_item_guid() { global $activities_template; return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) ); } function bp_activity_feed_item_title() { echo bp_get_activity_feed_item_title(); } function bp_get_activity_feed_item_title() { global $activities_template; if ( !empty( $activities_template->activity->action ) ) $content = $activities_template->activity->action; else $content = $activities_template->activity->content; $content = explode( 'activity->type ) { $content = explode( '