Skip to:
Content

bbPress.org

Ticket #2794: 2794.04.patch

File 2794.04.patch, 6.4 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 20bff29..e2a030e 100644
    class BBP_BuddyPress_Activity { 
    103103         */
    104104        private function setup_globals() {
    105105
    106                 // The name of the BuddyPress component, used in activity streams
    107                 $this->component    = 'bbpress';
     106                // The name of the BuddyPress component, used in activity streams.
     107                $this->component = 'bbpress';
     108
     109                // Groups.
     110                if ( bp_is_active( 'groups' ) ) {
     111                        $this->groups_component = buddypress()->groups->id;
     112                }
    108113
    109114                // Forums
    110115                $this->forum_create = 'bbp_forum_create';
    class BBP_BuddyPress_Activity { 
    195200         */
    196201        public function register_activity_actions() {
    197202
    198                 // Sitewide activity stream items
    199                 bp_activity_set_action( $this->component, $this->topic_create, esc_html__( 'New forum topic', 'bbpress' ) );
    200                 bp_activity_set_action( $this->component, $this->reply_create, esc_html__( 'New forum reply', 'bbpress' ) );
     203                // Sitewide activity stream items.
     204                bp_activity_set_action(
     205                        $this->component,
     206                        $this->topic_create,
     207                        esc_html__( 'New forum topic', 'bbpress' ),
     208                        'bbp_bp_format_activity_action_new_topic',
     209                        __( 'Topics', 'bbpress' ),
     210                        array( 'activity', 'member', 'member_groups', 'group' )
     211                );
     212
     213                bp_activity_set_action(
     214                        $this->component,
     215                        $this->reply_create,
     216                        esc_html__( 'New forum reply', 'bbpress' ),
     217                        'bbp_bp_format_activity_action_new_reply',
     218                        __( 'Replies', 'bbpress' ),
     219                        array( 'activity', 'member', 'member_groups', 'group' )
     220                );
     221
     222                // Group forum activity stream items.
     223                if ( bp_is_active( 'groups' ) ) {
     224                        bp_activity_set_action(
     225                                $this->groups_component,
     226                                $this->topic_create,
     227                                esc_html__( 'New forum topic', 'bbpress' ),
     228                                'bbp_bp_format_activity_action_new_topic',
     229                                __( 'Topics', 'bbpress' ),
     230                                array( 'activity', 'member', 'member_groups', 'group' )
     231                        );
     232
     233                        bp_activity_set_action(
     234                                $this->groups_component,
     235                                $this->reply_create,
     236                                esc_html__( 'New forum reply', 'bbpress' ),
     237                                'bbp_bp_format_activity_action_new_reply',
     238                                __( 'Replies', 'bbpress' ),
     239                                array( 'activity', 'member', 'member_groups', 'group' )
     240                        );
     241                }
    201242        }
    202243
    203244        /**
  • src/includes/extend/buddypress/functions.php

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