Skip to:
Content

bbPress.org

Ticket #2794: 2794.03.patch

File 2794.03.patch, 6.8 KB (added by netweb, 9 years ago)

Refresh of 2794.02.patch against /trunk

  • src/includes/extend/buddypress/activity.php

     
    104104        private function setup_globals() {
    105105
    106106                // The name of the BuddyPress component, used in activity streams
    107                 $this->component    = 'bbpress';
     107                $this->component = 'bbpress';
    108108
     109                // Groups
     110                if ( bp_is_active( 'groups' ) ) {
     111                        $this->groups_component = buddypress()->groups->id;
     112                }
     113
    109114                // Forums
    110115                $this->forum_create = 'bbp_forum_create';
    111116
     
    196201        public function register_activity_actions() {
    197202
    198203                // 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' ) );
     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

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