Skip to:
Content

BuddyPress.org

Changeset 2158


Ignore:
Timestamp:
11/30/2009 12:27:52 PM (16 years ago)
Author:
apeatling
Message:

Adding activity item permalink support

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2128 r2158  
    8383    bp_core_add_root_component( BP_ACTIVITY_SLUG );
    8484}
    85 add_action( 'plugins_loaded', 'bp_activity_setup_root_component' );
     85add_action( 'plugins_loaded', 'bp_activity_setup_root_component', 2 );
    8686
    8787function bp_activity_setup_nav() {
     
    136136}
    137137
     138function bp_activity_screen_single_activity_permalink() {
     139    global $bp;
     140
     141    if ( !$bp->displayed_user->id || $bp->current_component != $bp->activity->slug )
     142        return false;
     143
     144    if ( empty( $bp->current_action ) || !is_numeric( $bp->current_action ) )
     145        return false;
     146
     147    /* Get the activity details */
     148    $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->current_action ) );
     149
     150    if ( !$activity = $activity['activities'][0] )
     151        bp_core_redirect( $bp->root_domain );
     152
     153    $has_access = true;
     154    /* Redirect based on the type of activity */
     155    if ( $activity->component_name == $bp->groups->id ) {
     156        if ( !function_exists( 'groups_get_group' ) )
     157            bp_core_redirect( $bp->root_domain );
     158
     159        if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
     160            /* Check to see if the group is not public, if so, check the user has access to see this activity */
     161            if ( 'public' != $group->status ) {
     162                if ( !groups_is_user_member( $bp->loggedin_user->id, $group->id ) )
     163                    $has_access = false;
     164            }
     165        }
     166    }
     167
     168    $has_access = apply_filters( 'bp_activity_permalink_access', $has_access, &$activity );
     169
     170    if ( !$has_access ) {
     171        bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
     172        bp_core_redirect( $bp->loggedin_user->domain );
     173    }
     174
     175    bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'activity/single' ) );
     176}
     177/* This screen is not attached to a nav item, so we need to add an action for it. */
     178add_action( 'wp', 'bp_activity_screen_single_activity_permalink', 3 );
    138179
    139180/********************************************************************************
     
    145186 */
    146187
     188function bp_activity_action_permalink_router() {
     189    global $bp;
     190
     191    if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'p' )
     192        return false;
     193
     194    if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
     195        return false;
     196
     197    /* Get the activity details */
     198    $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->action_variables[0] ) );
     199
     200    if ( !$activity = $activity['activities'][0] )
     201        bp_core_redirect( $bp->root_domain );
     202
     203    $redirect = false;
     204    /* Redirect based on the type of activity */
     205    if ( $activity->component_name == $bp->groups->id ) {
     206        if ( $activity->user_id )
     207            $redirect = bp_core_get_userurl( $activity->user_id ) . $bp->activity->slug . '/' . $activity->id;
     208        else {
     209            if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
     210                $redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id;
     211        }
     212    } else
     213        $redirect = bp_core_get_userurl( $activity->user_id ) . $bp->activity->slug . '/' . $activity->id;
     214
     215    if ( !$redirect )
     216        bp_core_redirect( $bp->root_domain );
     217
     218    /* Redirect to the actual activity permalink page */
     219    bp_core_redirect( apply_filters( 'bp_activity_action_permalink_url', $redirect . '/', &$activity ) );
     220}
     221add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
     222
    147223function bp_activity_action_delete_activity() {
    148224    global $bp;
     
    178254}
    179255add_action( 'wp', 'bp_activity_action_delete_activity', 3 );
    180 
    181256
    182257function bp_activity_action_sitewide_feed() {
  • trunk/bp-activity/bp-activity-classes.php

    r2149 r2158  
    188188            $sort = 'DESC';
    189189
     190        /* Hide Hidden Items? */
     191        if ( !$show_hidden )
     192            $hidden_sql = "AND hide_sitewide = 0";
     193
    190194        /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
    191195        if ( !$display_comments || 'threaded' == $display_comments ) {
    192196            if ( $per_page && $page && $max )
    193                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql}", $user_id ) );
     197                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql}", $user_id ) );
    194198            else
    195                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}", $user_id ) );
    196 
    197             $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$max_sql}", $user_id ) );
     199                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}", $user_id ) );
     200
     201            $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$max_sql}", $user_id ) );
    198202
    199203            if ( $activities && $display_comments )
     
    201205        } else {
    202206            if ( $per_page && $page && $max )
    203                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} ORDER BY date_recorded {$sort} {$pag_sql}", $user_id ) );
     207                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} ORDER BY date_recorded {$sort} {$pag_sql}", $user_id ) );
    204208            else
    205                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}", $user_id ) );
    206 
    207             $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} ORDER BY date_recorded {$sort} {$max_sql}", $user_id ) );
     209                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}", $user_id ) );
     210
     211            $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} ORDER BY date_recorded {$sort} {$max_sql}", $user_id ) );
    208212
    209213            if ( $activities )
  • trunk/bp-activity/bp-activity-templatetags.php

    r2147 r2158  
    3232
    3333            if ( $type == 'personal' )
    34                 $this->activities = bp_activity_get_for_user( array( 'user_id' => $user_id, 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter ) );
     34                $this->activities = bp_activity_get_for_user( array( 'user_id' => $user_id, '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 ) );
    3535
    3636            if ( $type == 'friends' && ( bp_is_home() || is_site_admin() || $bp->loggedin_user->id == $user_id ) )
     
    153153    }
    154154
     155    /* Support for permalinks on single item pages: /groups/my-group/activity/124/ */
     156    if ( $bp->current_action == $bp->activity->slug )
     157        $include = $bp->action_variables[0];
     158
    155159    if ( isset( $_GET['afilter'] ) )
    156160        $filter = array( 'object' => $_GET['afilter'] );
     
    348352    }
    349353
     354    if ( 'activity_comment' == $activities_template->activity->component_action )
     355        $meta = '</span> <span class="activity-header-meta"> &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activities_template->activity->item_id . '">' . __( 'View Thread', 'buddypress' ) . '</a>';
     356    else
     357        $meta = '</span> <span class="activity-header-meta"> &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activities_template->activity->id . '">' . __( 'Permalink', 'buddypress' ) . '</a>';
     358
    350359    /* Add the delete link if the user has permission on this item */
    351360    if ( ( $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || is_site_admin() )
    352         $content[1] = '</span> <span class="activity-delete-link">' . bp_get_activity_delete_link() . '</span>' . $content[1];
    353 
     361         $meta .= ' &middot;' . bp_get_activity_delete_link();
     362
     363    $content[1] = $meta . '</span>' . $content[1];
    354364    $content_new = '';
    355365
     
    486496    return apply_filters( 'bp_activity_insert_time_since', @sprintf( $content, @sprintf( __( '&nbsp; %s ago', 'buddypress' ), bp_core_time_since( strtotime( $date ) ) ) ) );
    487497}
     498
     499function bp_activity_permalink_id() {
     500    echo bp_get_activity_permalink_id();
     501}
     502    function bp_get_activity_permalink_id() {
     503        global $bp;
     504
     505        return apply_filters( 'bp_get_activity_permalink_id', $bp->current_action );
     506    }
    488507
    489508function bp_activity_css_class() {
  • trunk/bp-activity/bp-activity-widgets.php

    r2156 r2158  
    4949                    <div id="whats-new-submit">
    5050                        <span class="ajax-loader"></span> &nbsp;
    51                         <input type="submit" name="aw-whats-new-submit" id="aw-whats-new-submit" value="<?php _e( 'Update', 'callisto' ) ?>" />
     51                        <input type="submit" name="aw-whats-new-submit" id="aw-whats-new-submit" value="<?php _e( 'Post Update', 'callisto' ) ?>" />
    5252                    </div>
    5353
  • trunk/bp-groups.php

    r2147 r2158  
    575575}
    576576
    577 
    578577function groups_screen_group_home() {
    579578    global $bp;
    580579
    581580    if ( $bp->is_single_item ) {
    582 
    583581        if ( isset($_GET['new']) ) {
    584582            // Delete group request notifications for the user
     
    975973    }
    976974}
     975
     976function groups_screen_group_activity_permalink() {
     977    global $bp;
     978
     979    if ( !$bp->is_single_item || $bp->current_component != $bp->groups->slug || $bp->current_action != $bp->activity->slug )
     980        return false;
     981
     982    if ( '' != locate_template( array( 'groups/single/home.php' ), false ) )
     983        bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
     984    else
     985        bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/group-home' ) );
     986}
     987add_action( 'wp', 'groups_screen_group_activity_permalink', 3 );
    977988
    978989function groups_screen_group_admin() {
     
    16071618 */
    16081619
     1620function groups_get_group( $args = '' ) {
     1621    $defaults = array(
     1622        'group_id' => false,
     1623        'load_users' => false
     1624    );
     1625
     1626    $args = wp_parse_args( $args, $defaults );
     1627    extract( $args, EXTR_SKIP );
     1628
     1629    return apply_filters( 'groups_get_group', new BP_Groups_Group( $group_id, true, $load_users ) );
     1630}
     1631
    16091632/*** Group Creation, Editing & Deletion *****************************************/
    16101633
  • trunk/bp-groups/bp-groups-templatetags.php

    r2088 r2158  
    484484            $group =& $groups_template->group;
    485485
    486         return apply_filters( 'bp_get_group_permalink', $bp->root_domain . '/' . $bp->groups->slug . '/' . $group->slug );
     486        return apply_filters( 'bp_get_group_permalink', $bp->root_domain . '/' . $bp->groups->slug . '/' . $group->slug . '/' );
    487487    }
    488488
     
    739739}
    740740
     741function bp_group_is_activity_permalink() {
     742    global $bp;
     743
     744    if ( !$bp->is_single_item || $bp->current_component != $bp->groups->slug || $bp->current_action != $bp->activity->slug )
     745        return false;
     746
     747    return true;
     748}
     749
    741750function bp_group_pagination() {
    742751    echo bp_get_group_pagination();
  • trunk/bp-themes/bp-default/_inc/css/screen.css

    r2155 r2158  
    13411341            margin-bottom: 18px;
    13421342        }
     1343
     1344.activity-list li span.activity-header-meta {
     1345    font-size: 0.95em;
     1346}
     1347    .activity-list li span.activity-header-meta a {
     1348        color: #888;
     1349    }
    13431350
    13441351.activity-list li span.time-since {
  • trunk/bp-themes/bp-sn-parent/activity/entry.php

    r2132 r2158  
    2222            <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar( 'width=25&height=25' ) ?></div>
    2323            <div class="ac-reply-content">
    24                 <textarea id="ac-input-<?php bp_activity_id() ?>" class="ac-input" name="ac-input-<?php bp_activity_id() ?>"></textarea>
     24                <div class="ac-textarea">
     25                    <textarea id="ac-input-<?php bp_activity_id() ?>" class="ac-input" name="ac-input-<?php bp_activity_id() ?>"></textarea>
     26                </div>
     27
    2528                <input type="submit" name="ac-form-submit" value="<?php _e( 'Post', 'buddypress' ) ?> &rarr;" />
    2629            </div>
  • trunk/bp-themes/bp-sn-parent/activity/just-me.php

    r2155 r2158  
    5454                    <div class="activity">
    5555
    56                     <?php if ( bp_has_activities( 'type=personal&max=20&per_page=20&display_comments=stream' ) ) : ?>
     56                    <?php if ( bp_has_activities( 'type=personal&max=20&per_page=20&display_comments=stream&show_hidden=' . bp_is_home() ) ) : ?>
    5757
    5858                        <ul id="activity-list" class="activity-list item-list">
  • trunk/bp-themes/bp-sn-parent/groups/single/home.php

    r2155 r2158  
    5959                            <h4><?php _e( 'Group Activity', 'buddypress' ); ?></h4>
    6060
    61                             <?php if ( is_user_logged_in() && bp_group_is_member() ) : ?>
     61                            <?php if ( is_user_logged_in() && bp_group_is_member() && !bp_group_is_activity_permalink() ) : ?>
    6262
    6363                            <form action="" method="post" id="whats-new-form" name="whats-new-form">
Note: See TracChangeset for help on using the changeset viewer.