Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/20/2010 04:21:20 PM (17 years ago)
Author:
apeatling
Message:

Standardizing activity stream fields and splitting the action from the content for better manageability.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-templatetags.php

    r2375 r2381  
    266266        function bp_get_activity_object_name() {
    267267                global $activities_template;
    268                 return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component_name );
    269         }
    270 
    271 function bp_activity_action_name() {
    272         echo bp_get_activity_action_name();
    273 }
    274         function bp_get_activity_action_name() {
    275                 global $activities_template;
    276                 return apply_filters( 'bp_get_activity_action_name', $activities_template->activity->component_action );
    277         }
     268                return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );
     269        }
     270
     271function bp_activity_type() {
     272        echo bp_get_activity_type();
     273}
     274        function bp_get_activity_type() {
     275                global $activities_template;
     276                return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );
     277        }
     278        function bp_activity_action_name() { echo bp_activity_type(); }
     279        function bp_get_activity_action_name() { return bp_get_activity_type(); }
    278280
    279281function bp_activity_user_id() {
     
    310312
    311313                $object = 'user';
    312                 if ( $bp->groups->id == $activities_template->activity->component_name && !(int) $activities_template->activity->user_id )
     314                if ( $bp->groups->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id )
    313315                        $object = 'group';
    314                 if ( $bp->blogs->id == $activities_template->activity->component_name && !(int) $activities_template->activity->user_id )
     316                if ( $bp->blogs->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id )
    315317                        $object = 'blog';
    316318
    317                 $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component_name, $object );
     319                $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component, $object );
    318320
    319321                /* If this is a user object pass the users' email address for Gravatar so we don't have to refetch it. */
     
    324326        }
    325327
     328function bp_activity_action() {
     329        echo bp_get_activity_action();
     330}
     331        function bp_get_activity_action() {
     332                global $activities_template;
     333
     334                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 );
     335        }
     336
     337function bp_activity_content_body() {
     338        echo bp_get_activity_content_body();
     339}
     340        function bp_get_activity_content_body() {
     341                global $activities_template;
     342
     343                if ( empty( $activities_template->activity->action ) )
     344                        $activities_template->activity->content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded );
     345
     346                return apply_filters( 'bp_get_activity_content_body', $activities_template->activity->content );
     347        }
     348
    326349function bp_activity_content() {
    327350        echo bp_get_activity_content();
    328351}
    329352        function bp_get_activity_content() {
    330                 global $activities_template, $allowed_tags, $bp;
    331 
    332                 if ( bp_is_home() && $activities_template->activity_type == 'personal' )
    333                         $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded, $activities_template->full_name );
    334                 else
    335                         $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded, $activities_template->full_name, true, false, false );
    336 
    337                 return apply_filters( 'bp_get_activity_content', $content, $activities_template->activity->component_name, $activities_template->activity->component_action );
    338         }
    339 
    340 function bp_activity_content_filter( $content, $date_recorded, $full_name, $insert_time = true, $filter_words = true, $filter_you = true ) {
     353                global $activities_template;
     354
     355                if ( empty( $activities_template->activity->action ) )
     356                        $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded );
     357                else {
     358                        $content = bp_activity_content_filter( $activities_template->activity->action, $activities_template->activity->date_recorded );
     359                        $content .= $activities_template->activity->content;
     360                }
     361
     362                return apply_filters( 'bp_get_activity_content', $content, $activities_template->activity->component, $activities_template->activity->type );
     363        }
     364
     365function bp_activity_content_filter( $content, $date_recorded ) {
    341366        global $activities_template, $bp;
    342367
     
    351376
    352377        /* Insert the time since */
    353         if ( $insert_time )
    354                 $content[0] = bp_activity_insert_time_since( $content[0], $date_recorded );
    355 
    356         // The "You" and "Your" conversion is only done in english, if a translation file is present
    357         // then do not translate as it causes problems in other languages.
    358         if ( '' == get_locale() ) {
    359                 /* Switch 'their/your' depending on whether the user is logged in or not and viewing their profile */
    360                 if ( $filter_words ) {
    361                         $content[0] = preg_replace( '/their\s/', 'your ', $content[0] );
    362                 }
    363 
    364                 /* Remove the 'You' and replace if with the persons name */
    365                 if ( $filter_you && $full_name != '' ) {
    366                         $content[0] = preg_replace( "/{$full_name}[<]/", 'You<', $content[0], 1 );
    367                 }
    368         }
     378        $content[0] = bp_activity_insert_time_since( $content[0], $date_recorded );
    369379
    370380        /* Add the permalink */
     
    559569
    560570                $class = '';
    561                 if ( in_array( $activities_template->activity->component_action, (array)$mini_activity_actions ) )
     571                if ( in_array( $activities_template->activity->type, (array)$mini_activity_actions ) )
    562572                        $class = ' mini';
    563573
     
    565575                        $class .= ' has-comments';
    566576
    567                 return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component_name . ' ' . $activities_template->activity->component_action . $class );
     577                return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
    568578        }
    569579
     
    609619
    610620                /* Fetch the names of components that have activity recorded in the DB */
    611                 $component_names = BP_Activity_Activity::get_recorded_component_names();
    612 
    613                 if ( !$component_names )
     621                $components = BP_Activity_Activity::get_recorded_components();
     622
     623                if ( !$components )
    614624                        return false;
    615625
    616                 foreach ( (array) $component_names as $component_name ) {
     626                foreach ( (array) $components as $component ) {
    617627                        /* Skip the activity comment filter */
    618                         if ( 'activity' == $component_name )
     628                        if ( 'activity' == $component )
    619629                                continue;
    620630
    621                         if ( isset( $_GET['afilter'] ) && $component_name == $_GET['afilter'] )
     631                        if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] )
    622632                                $selected = ' class="selected"';
    623633                        else
    624634                                unset($selected);
    625635
    626                         $component_name = attribute_escape( $component_name );
     636                        $component = attribute_escape( $component );
    627637
    628638                        switch ( $style ) {
    629639                                case 'list':
    630640                                        $tag = 'li';
    631                                         $before = '<li id="afilter-' . $component_name . '"' . $selected . '>';
     641                                        $before = '<li id="afilter-' . $component . '"' . $selected . '>';
    632642                                        $after = '</li>';
    633643                                break;
    634644                                case 'paragraph':
    635645                                        $tag = 'p';
    636                                         $before = '<p id="afilter-' . $component_name . '"' . $selected . '>';
     646                                        $before = '<p id="afilter-' . $component . '"' . $selected . '>';
    637647                                        $after = '</p>';
    638648                                break;
    639649                                case 'span':
    640650                                        $tag = 'span';
    641                                         $before = '<span id="afilter-' . $component_name . '"' . $selected . '>';
     651                                        $before = '<span id="afilter-' . $component . '"' . $selected . '>';
    642652                                        $after = '</span>';
    643653                                break;
    644654                        }
    645655
    646                         $link = add_query_arg( 'afilter', $component_name );
     656                        $link = add_query_arg( 'afilter', $component );
    647657                        $link = remove_query_arg( 'acpage' , $link );
    648658
    649                         $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component_name );
     659                        $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
    650660
    651661                        /* Make sure all core internal component names are translatable */
    652                         $translatable_component_names = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) );
    653 
    654                         $component_links[] = $before . '<a href="' . attribute_escape( $link ) . '">' . ucwords( __( $component_name, 'buddypress' ) ) . '</a>' . $after;
     662                        $translatable_components = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) );
     663
     664                        $component_links[] = $before . '<a href="' . attribute_escape( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after;
    655665                }
    656666
     
    745755                global $activities_template;
    746756
    747                 $content = explode( '<span', $activities_template->activity->content );
     757                if ( !empty( $activities_template->activity->action ) )
     758                        $content = $activities_template->activity->action;
     759                else
     760                        $content = $activities_template->activity->content;
     761
     762                $content = explode( '<span', $content );
    748763                $title = trim( strip_tags( html_entity_decode( $content[0] ) ) );
    749764
     
    751766                        $title = substr( $title, 0, -1 );
    752767
    753                 if ( 'activity_update' == $activities_template->activity->component_action ) {
     768                if ( 'activity_update' == $activities_template->activity->type ) {
    754769                        $content = explode( '<div class="activity-inner">', $activities_template->activity->content );
    755770                        $title .= ': ' . strip_tags( bp_create_excerpt( $content[1], 15 ));
     
    783798                global $activities_template;
    784799
    785                 return apply_filters( 'bp_get_activity_feed_item_description', html_entity_decode( str_replace( '%s', '', $activities_template->activity->content ), ENT_COMPAT, 'UTF-8' ) );
     800                if ( empty( $activities_template->activity->action ) )
     801                        $content = $activities_template->activity->content;
     802                else
     803                        $content = $activities_template->activity->action . $activities_template->activity->content;
     804
     805                return apply_filters( 'bp_get_activity_feed_item_description', html_entity_decode( str_replace( '%s', '', $content ), ENT_COMPAT, 'UTF-8' ) );
    786806        }
    787807
Note: See TracChangeset for help on using the changeset viewer.