Skip to:
Content

bbPress.org

Ticket #2794: 2794.02.patch

File 2794.02.patch, 6.8 KB (added by thebrandonallen, 9 years ago)
  • src/includes/extend/buddypress/activity.php

    diff --git src/includes/extend/buddypress/activity.php src/includes/extend/buddypress/activity.php
    index 9366f30..f5027f5 100644
    class BBP_BuddyPress_Activity { 
    103103        private function setup_globals() {
    104104
    105105                // The name of the BuddyPress component, used in activity streams
    106                 $this->component    = 'bbpress';
     106                $this->component = 'bbpress';
     107
     108                // Groups
     109                if ( bp_is_active( 'groups' ) ) {
     110                        $this->groups_component = buddypress()->groups->id;
     111                }
    107112
    108113                // Forums
    109114                $this->forum_create = 'bbp_forum_create';
    class BBP_BuddyPress_Activity { 
    192197        public function register_activity_actions() {
    193198
    194199                // Sitewide activity stream items
    195                 bp_activity_set_action( $this->component, $this->topic_create, esc_html__( 'New forum topic', 'bbpress' ) );
    196                 bp_activity_set_action( $this->component, $this->reply_create, esc_html__( 'New forum reply', 'bbpress' ) );
     200                bp_activity_set_action(
     201                        $this->component,
     202                        $this->topic_create,
     203                        esc_html__( 'New forum topic', 'bbpress' ),
     204                        'bbp_bp_format_activity_action_new_topic',
     205                        __( 'Topics', 'bbpress' ),
     206                        array( 'activity', 'member', 'member_groups', 'group' )
     207                );
     208
     209                bp_activity_set_action(
     210                        $this->component,
     211                        $this->reply_create,
     212                        esc_html__( 'New forum reply', 'bbpress' ),
     213                        'bbp_bp_format_activity_action_new_reply',
     214                        __( 'Replies', 'bbpress' ),
     215                        array( 'activity', 'member', 'member_groups', 'group' )
     216                );
     217
     218                // Group forum activity stream items
     219                if ( bp_is_active( 'groups' ) ) {
     220                        bp_activity_set_action(
     221                                $this->groups_component,
     222                                $this->topic_create,
     223                                esc_html__( 'New forum topic', 'bbpress' ),
     224                                'bbp_bp_format_activity_action_new_topic',
     225                                __( 'Topics', 'bbpress' ),
     226                                array( 'activity', 'member', 'member_groups', 'group' )
     227                        );
     228
     229                        bp_activity_set_action(
     230                                $this->groups_component,
     231                                $this->reply_create,
     232                                esc_html__( 'New forum reply', 'bbpress' ),
     233                                'bbp_bp_format_activity_action_new_reply',
     234                                __( 'Replies', 'bbpress' ),
     235                                array( 'activity', 'member', 'member_groups', 'group' )
     236                        );
     237                }
    197238        }
    198239
    199240        /**
  • src/includes/extend/buddypress/functions.php

    diff --git src/includes/extend/buddypress/functions.php src/includes/extend/buddypress/functions.php
    index 14c0fec..e31a1b9 100644
    function bbp_group_is_creator() { 
    710710        // Return the value
    711711        return (bool) $bbp->current_user->is_group_creator;
    712712}
     713
     714/** BuddyPress Activity Action Callbacks **************************************/
     715
     716/**
     717 * Genereic function to format the dynamic BuddyPress activity action for new
     718 * topics/replies.
     719 *
     720 * @since 2.6.0 bbPress (rXXXX)
     721 *
     722 * @param null|string $type     The type of post. Currently `topic` or `reply`.
     723 * @param string      $action   The current action string.
     724 * @param object      $activity The BuddyPress activity object.
     725 *
     726 * @uses bbp_get_topic_id() To get the topic id of the activity.
     727 * @uses bbp_get_forum_id() To get the forum id of the activity item.
     728 * @uses bbp_get_topic_forum_id() To get the forum id of the activity item.
     729 * @uses bbp_get_user_profile_link() To get the user profile link.
     730 * @uses bbp_get_topic_permalink() To get the topic permalink.
     731 * @uses get_post_field() To get the post title.
     732 * @uses bbp_get_forum_permalink() To get the forum permalink.
     733 *
     734 * @return string The formatted activity action.
     735 */
     736function bbp_bp_format_activity_action_new_post( $type = null, $action, $activity ) {
     737
     738        // Bail early if we don't have a valid type.
     739        if ( ! in_array( $type, array( 'topic', 'reply' ) ) ) {
     740                return $action;
     741        }
     742
     743        if ( 'groups' === $activity->component ) {
     744                if ( 'topic' === $type ) {
     745                        $topic_id = bbp_get_topic_id( $activity->secondary_item_id );
     746                        $forum_id = bbp_get_topic_forum_id( $topic_id );
     747                } else {
     748                        $topic_id = bbp_get_reply_topic_id( $activity->secondary_item_id );
     749                        $forum_id = bbp_get_topic_forum_id( $topic_id );
     750                }
     751        } else {
     752                if ( 'topic' === $type ) {
     753                        $topic_id = bbp_get_topic_id( $activity->item_id );
     754                        $forum_id = bbp_get_forum_id( $activity->secondary_item_id );
     755                } else {
     756                        $topic_id = bbp_get_topic_id( $activity->secondary_item_id );
     757                        $forum_id = bbp_get_topic_forum_id( $topic_id );
     758                }
     759        }
     760
     761        // Setup our post type args.
     762        $actions = array(
     763                'topic' => __( '%1$s started the topic %2$s in the forum %3$s', 'bbpress' ),
     764                'reply' => __( '%1$s replied to the topic %2$s in the forum %3$s', 'bbpress' ),
     765        );
     766
     767        // User link for topic author.
     768        $user_link = bbp_get_user_profile_link( $activity->user_id );
     769
     770        // Topic link.
     771        $topic_permalink = bbp_get_topic_permalink( $topic_id );
     772        $topic_title     = get_post_field( 'post_title', $topic_id, 'raw' );
     773        $topic_link      = '<a href="' . $topic_permalink . '">' . $topic_title . '</a>';
     774
     775        // Forum link.
     776        $forum_permalink = bbp_get_forum_permalink( $forum_id );
     777        $forum_title     = get_post_field( 'post_title', $forum_id, 'raw' );
     778        $forum_link      = '<a href="' . $forum_permalink . '">' . $forum_title . '</a>';
     779
     780        return sprintf( $actions[ $type ], $user_link, $topic_link, $forum_link );
     781}
     782
     783/**
     784 * Formats the dynamic BuddyPress activity action for new topics.
     785 *
     786 * @since 2.6.0 bbPress (rXXXX)
     787 *
     788 * @param string $action   The current action string.
     789 * @param object $activity The BuddyPress activity object.
     790 *
     791 * @uses bbp_bp_format_activity_action_new_post() To get the formatted action string.
     792 *
     793 * @return string The formatted activity action.
     794 */
     795function bbp_bp_format_activity_action_new_topic( $action, $activity ) {
     796
     797        $action = bbp_bp_format_activity_action_new_post( 'topic', $action, $activity );
     798
     799        /**
     800         * Filters the formatted activity action new topic string.
     801         *
     802         * @since 2.6.0 bbPress (rXXXX)
     803         *
     804         * @param string               $action   Activity action string value.
     805         * @param BP_Activity_Activity $activity Activity item object.
     806         */
     807        return apply_filters( 'bbp_bp_format_activity_action_new_topic', $action, $activity );
     808}
     809
     810/**
     811 * Formats the dynamic BuddyPress activity action for new replies.
     812 *
     813 * @since 2.6.0 bbPress (rXXXX)
     814 *
     815 * @param string $action   The current action string.
     816 * @param object $activity The BuddyPress activity object.
     817 *
     818 * @uses bbp_bp_format_activity_action_new_post() To get the formatted action string.
     819 *
     820 * @return string The formatted activity action.
     821 */
     822function bbp_bp_format_activity_action_new_reply( $action, $activity ) {
     823
     824        $action = bbp_bp_format_activity_action_new_post( 'reply', $action, $activity );
     825
     826        /**
     827         * Filters the formatted activity action new reply string.
     828         *
     829         * @since 2.6.0 bbPress (rXXXX)
     830         *
     831         * @param string               $action   Activity action string value.
     832         * @param BP_Activity_Activity $activity Activity item object.
     833         */
     834        return apply_filters( 'bbp_bp_format_activity_action_new_reply', $action, $activity );
     835}