Skip to:
Content

BuddyPress.org

Ticket #5926: 5926.03.patch

File 5926.03.patch, 12.6 KB (added by DJPaul, 9 years ago)
  • src/bp-activity/bp-activity-functions.php

    diff --git a/src/bp-activity/bp-activity-functions.php b/src/bp-activity/bp-activity-functions.php
    index d4f2328..a6072bc 100644
    a b function bp_activity_delete_comment( $activity_id, $comment_id ) { 
    25402540 *
    25412541 * @since 1.2.0
    25422542 *
    2543  * @uses bp_get_root_domain()
    2544  * @uses bp_get_activity_root_slug()
    2545  * @uses apply_filters_ref_array() To call the 'bp_activity_get_permalink' hook.
    2546  *
    25472543 * @param int         $activity_id  The unique id of the activity object.
    25482544 * @param object|bool $activity_obj Optional. The activity object.
    25492545 *
    function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 
    25732569
    25742570        if ( false !== array_search( $activity_obj->type, $use_primary_links ) ) {
    25752571                $link = $activity_obj->primary_link;
     2572
    25762573        } else {
    25772574                if ( 'activity_comment' == $activity_obj->type ) {
    2578                         $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->item_id . '/';
     2575                        $id = (int) $activity_obj->item_id;
    25792576                } else {
    2580                         $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->id . '/';
     2577                        $id = (int) $activity_obj->id;
    25812578                }
     2579
     2580                $link = bp_core_get_user_domain( $activity_obj->user_id ) . bp_get_activity_slug() . "/{$id}/";
    25822581        }
    25832582
    25842583        /**
    function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 
    25922591}
    25932592
    25942593/**
     2594 * Get the shortlink for a single activity item.
     2595 *
     2596 * When only the $activity_id param is passed, BP has to instantiate a new
     2597 * BP_Activity_Activity object. To save yourself some processing overhead,
     2598 * be sure to pass the full $activity_obj parameter as well, if you already
     2599 * have it available.
     2600 *
     2601 * @param int $activity_id The unique id of the activity object.
     2602 * @param object $activity_obj Optional. The activity object.
     2603 * @return string $link Permalink for the activity item.
     2604 * @since BuddyPress (2.3.0)
     2605 */
     2606function bp_activity_get_shortlink( $activity_id, $activity_obj = false ) {
     2607        $bp = buddypress();
     2608
     2609        if ( empty( $activity_obj ) ) {
     2610                $activity_obj = new BP_Activity_Activity( $activity_id );
     2611        }
     2612
     2613        if ( isset( $activity_obj->current_comment ) ) {
     2614                $activity_obj = $activity_obj->current_comment;
     2615        }
     2616
     2617        $use_primary_links = array(
     2618                'new_blog_post',
     2619                'new_blog_comment',
     2620                'new_forum_topic',
     2621                'new_forum_post',
     2622        );
     2623
     2624        if ( ! empty( $bp->activity->track ) ) {
     2625                $use_primary_links = array_merge( $use_primary_links, array_keys( $bp->activity->track ) );
     2626        }
     2627
     2628        if ( false !== array_search( $activity_obj->type, $use_primary_links ) ) {
     2629                $link = $activity_obj->primary_link;
     2630
     2631        } else {
     2632                if ( 'activity_comment' == $activity_obj->type ) {
     2633                        $id = (int) $activity_obj->item_id;
     2634                } else {
     2635                        $id = (int) $activity_obj->id;
     2636                }
     2637
     2638                $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . "/p/{$id}/";
     2639        }
     2640
     2641        /**
     2642         * Filters the activity shortlink for the specified activity item.
     2643         *
     2644         * @param array $array Array holding activity shortlink and activity item object.
     2645         * @since BuddyPress (2.3.0)
     2646         */
     2647        return apply_filters_ref_array( 'bp_activity_get_shortlink', array( $link, &$activity_obj ) );
     2648}
     2649
     2650/**
    25952651 * Hide a user's activity.
    25962652 *
    25972653 * @since 1.2.0
  • src/bp-activity/bp-activity-notifications.php

    diff --git a/src/bp-activity/bp-activity-notifications.php b/src/bp-activity/bp-activity-notifications.php
    index 7c05630..0cda8cc 100644
    a b defined( 'ABSPATH' ) || exit; 
    1919 * @uses bp_notifications_add_notification()
    2020 * @uses bp_get_user_meta()
    2121 * @uses bp_core_get_user_displayname()
    22  * @uses bp_activity_get_permalink()
    23  * @uses bp_core_get_user_domain()
    2422 * @uses bp_get_settings_slug()
    2523 * @uses bp_activity_filter_kses()
    2624 * @uses bp_core_get_core_userdata()
    function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) 
    5957        if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
    6058                $poster_name = bp_core_get_user_displayname( $activity->user_id );
    6159
    62                 $message_link  = bp_activity_get_permalink( $activity_id );
     60                $message_link  = bp_activity_get_shortlink( $activity_id );
    6361                $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    6462                $settings_link = bp_core_get_user_domain( $receiver_user_id ) . $settings_slug . '/notifications/';
    6563
    To view and respond to the message, log in and visit: %3$s 
    154152 *
    155153 * @uses bp_get_user_meta()
    156154 * @uses bp_core_get_user_displayname()
    157  * @uses bp_activity_get_permalink()
    158155 * @uses bp_core_get_user_domain()
    159156 * @uses bp_get_settings_slug()
    160157 * @uses bp_activity_filter_kses()
    function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 
    190187
    191188        if ( $original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {
    192189                $poster_name   = bp_core_get_user_displayname( $commenter_id );
    193                 $thread_link   = bp_activity_get_permalink( $activity_id );
     190                $thread_link   = bp_activity_get_shortlink( $activity_id );
    194191                $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    195192                $settings_link = bp_core_get_user_domain( $original_activity->user_id ) . $settings_slug . '/notifications/';
    196193
    To view your original update and all comments, log in and visit: %3$s 
    277274
    278275        if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) {
    279276                $poster_name   = bp_core_get_user_displayname( $commenter_id );
    280                 $thread_link   = bp_activity_get_permalink( $activity_id );
     277                $thread_link   = bp_activity_get_shortlink( $activity_id );
    281278                $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    282279                $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . $settings_slug . '/notifications/';
    283280
  • src/bp-activity/bp-activity-template.php

    diff --git a/src/bp-activity/bp-activity-template.php b/src/bp-activity/bp-activity-template.php
    index 973e72e..9a57bbb 100644
    a b function bp_insert_activity_meta( $content = '' ) { 
    19621962        if ( ! bp_is_single_activity() ) {
    19631963
    19641964                // Setup variables for activity meta
    1965                 $activity_permalink = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
     1965                $activity_permalink = bp_activity_get_shortlink( $activities_template->activity->id, $activities_template->activity );
    19661966                $activity_meta      = sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>',
    19671967                        $new_content,
    19681968                        $activity_permalink,
    function bp_insert_activity_meta( $content = '' ) { 
    19751975                 *
    19761976                 * @since 1.2.0
    19771977                 *
    1978                  * @param array $value Array containing the html markup for the activity permalink, after being parsed by sprintf and current activity component.
     1978                 * @param array $value Array containing the html markup for the activity shortlink, after being parsed by sprintf and current activity component.
    19791979                 */
    19801980                $new_content = apply_filters_ref_array( 'bp_activity_permalink', array(
    19811981                        $activity_meta,
    function bp_activity_thread_permalink() { 
    29342934        }
    29352935
    29362936/**
     2937 * Output the activity thread shortlink.
     2938 *
     2939 * @since BuddyPress (2.3.0)
     2940 */
     2941function bp_activity_thread_shortlink() {
     2942        echo bp_get_activity_thread_shortlink();
     2943}
     2944
     2945        /**
     2946         * Return the activity thread shortlink.
     2947         *
     2948         * @return string $link The activity thread shortlink.
     2949         * @since BuddyPress (2.3.0)
     2950         */
     2951        function bp_get_activity_thread_shortlink() {
     2952                global $activities_template;
     2953
     2954                $link = bp_activity_get_shortlink( $activities_template->activity->id, $activities_template->activity );
     2955                return apply_filters( 'bp_get_activity_thread_shortlink', $link );
     2956        }
     2957
     2958/**
    29372959 * Output the activity comment permalink.
    29382960 *
    29392961 * @since 1.8.0
    function bp_activity_comment_permalink() { 
    29813003        }
    29823004
    29833005/**
     3006 * Output the activity comment shortlink.
     3007 *
     3008 * @since BuddyPress (2.3.0)
     3009 */
     3010function bp_activity_comment_shortlink() {
     3011        echo bp_get_activity_comment_shortlink();
     3012}
     3013        /**
     3014         * Return the activity comment shortlink.
     3015         *
     3016         * @return string $link The activity comment shortlink.
     3017         * @since BuddyPress (2.3.0)
     3018         */
     3019        function bp_get_activity_comment_shortlink() {
     3020                global $activities_template;
     3021
     3022                // Check that comment exists
     3023                $comment_id = isset( $activities_template->activity->current_comment->id )
     3024                        ? $activities_template->activity->current_comment->id
     3025                        : 0;
     3026
     3027                // Append comment ID to end of activity shortlink
     3028                $comment_link = ! empty( $comment_id ) ? '#acomment-' . $comment_id : false;
     3029                $link         = bp_activity_get_shortlink( $activities_template->activity->id, $activities_template->activity );
     3030
     3031                return apply_filters( 'bp_get_activity_comment_shortlink', $link . $comment_link, $comment_id );
     3032        }
     3033
     3034/**
    29843035 * Output the activity favorite link.
    29853036 *
    29863037 * @since 1.2.0
    function bp_activity_latest_update( $user_id = 0 ) { 
    32763327                $latest_update = sprintf(
    32773328                        '%s <a href="%s">%s</a>',
    32783329                        $latest_update,
    3279                         esc_url_raw( bp_activity_get_permalink( $update['id'] ) ),
     3330                        esc_url_raw( bp_activity_get_shortlink( $update['id'] ) ),
    32803331                        esc_attr__( 'View', 'buddypress' )
    32813332                );
    32823333
  • src/bp-blogs/bp-blogs-activity.php

    diff --git a/src/bp-blogs/bp-blogs-activity.php b/src/bp-blogs/bp-blogs-activity.php
    index ddddb06..5bd09c0 100644
    a b function bp_blogs_activity_comment_single_permalink( $retval, $activity ) { 
    10651065        return $retval;
    10661066}
    10671067add_filter( 'bp_activity_get_permalink', 'bp_blogs_activity_comment_single_permalink', 10, 2 );
     1068add_filter( 'bp_activity_get_shortlink', 'bp_blogs_activity_comment_single_permalink', 10, 2 );
    10681069
    10691070/**
    10701071 * Formats single activity comment entries to use the blog comment action.
  • src/bp-core/deprecated/1.5.php

    diff --git a/src/bp-core/deprecated/1.5.php b/src/bp-core/deprecated/1.5.php
    index fca0cd8..848a2d8 100644
    a b function groups_at_message_notification( $content, $poster_user_id, $group_id, $ 
    345345                if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
    346346                        $poster_name = bp_core_get_user_displayname( $poster_user_id );
    347347
    348                         $message_link  = bp_activity_get_permalink( $activity_id );
     348                        $message_link  = bp_activity_get_shortlink( $activity_id );
    349349                        $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    350350                        $settings_link = bp_core_get_user_domain( $receiver_user_id ) . $settings_slug . '/notifications/';
    351351
  • src/bp-members/bp-members-template.php

    diff --git a/src/bp-members/bp-members-template.php b/src/bp-members/bp-members-template.php
    index 920d5af..c74525a 100644
    a b function bp_member_latest_update( $args = '' ) { 
    11881188                if ( $view_link && ( $update_content != $update['content'] ) ) {
    11891189                        $view = __( 'View', 'buddypress' );
    11901190
    1191                         $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_permalink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>';
     1191                        $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_shortlink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>';
    11921192                }
    11931193
    11941194                /**
  • tests/phpunit/testcases/routing/activity.php

    diff --git a/tests/phpunit/testcases/routing/activity.php b/tests/phpunit/testcases/routing/activity.php
    index c76a465..797a9af 100644
    a b class BP_Tests_Routing_Activity extends BP_UnitTestCase { 
    2323                $this->assertEquals( bp_get_activity_root_slug(), bp_current_component() );
    2424        }
    2525
    26         /**
    27          * Can't test using bp_activity_get_permalink(); see bp_activity_action_permalink_router().
    28          */
    2926        function test_activity_permalink() {
    3027                $a = $this->factory->activity->create();
    3128                $activity = $this->factory->activity->get_object_by_id( $a );
    3229
    33                 $url = bp_core_get_user_domain( $activity->user_id ) . bp_get_activity_slug() . '/' . $activity->id . '/';
    34                 $this->go_to( $url );
     30                $this->go_to( bp_activity_get_permalink( $activity->id, $activity ) );
     31                $this->assertTrue( bp_is_single_activity() );
     32        }
     33
     34        function test_activity_shortlink() {
     35                $a = $this->factory->activity->create();
     36                $activity = $this->factory->activity->get_object_by_id( $a );
     37
     38                $this->go_to( bp_activity_get_shortlink( $activity->id, $activity ) );
    3539                $this->assertTrue( bp_is_single_activity() );
    3640        }
    3741