Skip to:
Content

BuddyPress.org

Ticket #5926: 5926.01.patch

File 5926.01.patch, 12.7 KB (added by DJPaul, 11 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 7aede79..a59dc9e 100644
    a b function bp_activity_delete_comment( $activity_id, $comment_id ) { 
    17031703 * be sure to pass the full $activity_obj parameter as well, if you already
    17041704 * have it available.
    17051705 *
     1706 * @param int $activity_id The unique id of the activity object.
     1707 * @param object $activity_obj Optional. The activity object.
     1708 * @return string $link Permalink for the activity item.
    17061709 * @since BuddyPress (1.2.0)
     1710 */
     1711function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
     1712        if ( ! $activity_obj ) {
     1713                $activity_obj = new BP_Activity_Activity( $activity_id );
     1714        }
     1715
     1716        if ( isset( $activity_obj->current_comment ) ) {
     1717                $activity_obj = $activity_obj->current_comment;
     1718        }
     1719
     1720        if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type ) {
     1721                $link = $activity_obj->primary_link;
     1722
     1723        } else {
     1724                if ( 'activity_comment' === $activity_obj->type ) {
     1725                        $id = $activity_obj->item_id;
     1726                } else {
     1727                        $id = $activity_obj->id;
     1728                }
     1729
     1730                $link = bp_core_get_user_domain( $activity_obj->user_id ) . bp_get_activity_slug() . "/{$id}/";
     1731        }
     1732
     1733        return apply_filters_ref_array( 'bp_activity_get_permalink', array( $link, &$activity_obj ) );
     1734}
     1735
     1736/**
     1737 * Get the shortlink for a single activity item.
    17071738 *
    1708  * @uses bp_get_root_domain()
    1709  * @uses bp_get_activity_root_slug()
    1710  * @uses apply_filters_ref_array() To call the 'bp_activity_get_permalink' hook.
     1739 * When only the $activity_id param is passed, BP has to instantiate a new
     1740 * BP_Activity_Activity object. To save yourself some processing overhead,
     1741 * be sure to pass the full $activity_obj parameter as well, if you already
     1742 * have it available.
    17111743 *
    17121744 * @param int $activity_id The unique id of the activity object.
    17131745 * @param object $activity_obj Optional. The activity object.
    17141746 * @return string $link Permalink for the activity item.
     1747 * @since BuddyPress (2.2.0)
    17151748 */
    1716 function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
    1717 
    1718         if ( empty( $activity_obj ) ) {
     1749function bp_activity_get_shortlink( $activity_id, $activity_obj = false ) {
     1750        if ( ! $activity_obj ) {
    17191751                $activity_obj = new BP_Activity_Activity( $activity_id );
    17201752        }
    17211753
    function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 
    17251757
    17261758        if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type ) {
    17271759                $link = $activity_obj->primary_link;
     1760
    17281761        } else {
    17291762                if ( 'activity_comment' == $activity_obj->type ) {
    1730                         $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->item_id . '/';
     1763                        $id = $activity_obj->item_id;
    17311764                } else {
    1732                         $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->id . '/';
     1765                        $id = $activity_obj->id;
    17331766                }
     1767
     1768                $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . "/p/{$id}/";
    17341769        }
    17351770
    1736         return apply_filters_ref_array( 'bp_activity_get_permalink', array( $link, &$activity_obj ) );
     1771        return apply_filters_ref_array( 'bp_activity_get_shortlink', array( $link, &$activity_obj ) );
    17371772}
    17381773
    17391774/**
  • 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 005b4c7..ddc1e51 100644
    a b if ( !defined( 'ABSPATH' ) ) exit; 
    2020 * @uses bp_notifications_add_notification()
    2121 * @uses bp_get_user_meta()
    2222 * @uses bp_core_get_user_displayname()
    23  * @uses bp_activity_get_permalink()
    24  * @uses bp_core_get_user_domain()
    2523 * @uses bp_get_settings_slug()
    2624 * @uses bp_activity_filter_kses()
    2725 * @uses bp_core_get_core_userdata()
    function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) 
    6058        if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
    6159                $poster_name = bp_core_get_user_displayname( $activity->user_id );
    6260
    63                 $message_link  = bp_activity_get_permalink( $activity_id );
     61                $message_link  = bp_activity_get_shortlink( $activity_id );
    6462                $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    6563                $settings_link = bp_core_get_user_domain( $receiver_user_id ) . $settings_slug . '/notifications/';
    6664
    To view and respond to the message, log in and visit: %3$s 
    117115 *
    118116 * @uses bp_get_user_meta()
    119117 * @uses bp_core_get_user_displayname()
    120  * @uses bp_activity_get_permalink()
    121118 * @uses bp_core_get_user_domain()
    122119 * @uses bp_get_settings_slug()
    123120 * @uses bp_activity_filter_kses()
    function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 
    151148
    152149        if ( $original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {
    153150                $poster_name   = bp_core_get_user_displayname( $commenter_id );
    154                 $thread_link   = bp_activity_get_permalink( $activity_id );
     151                $thread_link   = bp_activity_get_shortlink( $activity_id );
    155152                $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    156153                $settings_link = bp_core_get_user_domain( $original_activity->user_id ) . $settings_slug . '/notifications/';
    157154
    To view your original update and all comments, log in and visit: %3$s 
    199196
    200197        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 ) ) {
    201198                $poster_name   = bp_core_get_user_displayname( $commenter_id );
    202                 $thread_link   = bp_activity_get_permalink( $activity_id );
     199                $thread_link   = bp_activity_get_shortlink( $activity_id );
    203200                $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    204201                $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . $settings_slug . '/notifications/';
    205202
  • 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 d291b7d..9b21163 100644
    a b function bp_insert_activity_meta( $content ) { 
    16491649
    16501650        // Insert the permalink
    16511651        if ( !bp_is_single_activity() )
    1652                 $content = apply_filters_ref_array( 'bp_activity_permalink', array( sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>', $content, bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ), esc_attr__( 'View Discussion', 'buddypress' ), $time_since ), &$activities_template->activity ) );
     1652                $content = apply_filters_ref_array( 'bp_activity_permalink', array( sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>', $content, bp_activity_get_shortlink( $activities_template->activity->id, $activities_template->activity ), esc_attr__( 'View Discussion', 'buddypress' ), $time_since ), &$activities_template->activity ) );
    16531653        else
    16541654                $content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH );
    16551655
    function bp_activity_thread_permalink() { 
    23972397        }
    23982398
    23992399/**
     2400 * Output the activity thread shortlink.
     2401 *
     2402 * @since BuddyPress (2.2)
     2403 */
     2404function bp_activity_thread_shortlink() {
     2405        echo bp_get_activity_thread_shortlink();
     2406}
     2407
     2408        /**
     2409         * Return the activity thread shortlink.
     2410         *
     2411         * @return string $link The activity thread shortlink.
     2412         * @since BuddyPress (2.2)
     2413         */
     2414        function bp_get_activity_thread_shortlink() {
     2415                global $activities_template;
     2416
     2417                $link = bp_activity_get_shortlink( $activities_template->activity->id, $activities_template->activity );
     2418                return apply_filters( 'bp_get_activity_thread_shortlink', $link );
     2419        }
     2420
     2421/**
    24002422 * Output the activity comment permalink.
    24012423 *
    24022424 * @since BuddyPress (1.8)
    function bp_activity_comment_permalink() { 
    24362458        }
    24372459
    24382460/**
     2461 * Output the activity comment shortlink.
     2462 *
     2463 * @since BuddyPress (2.2)
     2464 */
     2465function bp_activity_comment_shortlink() {
     2466        echo bp_get_activity_comment_shortlink();
     2467}
     2468        /**
     2469         * Return the activity comment shortlink.
     2470         *
     2471         * @return string $link The activity comment shortlink.
     2472         * @since BuddyPress (2.2)
     2473         */
     2474        function bp_get_activity_comment_shortlink() {
     2475                global $activities_template;
     2476
     2477                // Check that comment exists
     2478                $comment_id = isset( $activities_template->activity->current_comment->id )
     2479                        ? $activities_template->activity->current_comment->id
     2480                        : 0;
     2481
     2482                // Setup the comment link
     2483                $comment_link = ! empty( $comment_id )
     2484                        ? '#acomment-' .$comment_id
     2485                        : false;
     2486
     2487                // Append comment ID to end of activity shortlink
     2488                $link = bp_activity_get_shortlink( $activities_template->activity->id, $activities_template->activity ) . $comment_link;
     2489
     2490                return apply_filters( 'bp_get_activity_comment_shortlink', $link, $comment_id );
     2491        }
     2492
     2493/**
    24392494 * Output the activity favorite link.
    24402495 *
    24412496 * @since BuddyPress (1.2)
    function bp_activity_latest_update( $user_id = 0 ) { 
    26752730                $latest_update = sprintf(
    26762731                        '%s <a href="%s">%s</a>',
    26772732                        $latest_update,
    2678                         esc_url_raw( bp_activity_get_permalink( $update['id'] ) ),
     2733                        esc_url_raw( bp_activity_get_shortlink( $update['id'] ) ),
    26792734                        esc_attr__( 'View', 'buddypress' )
    26802735                );
    26812736
  • 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 8b67a16..ad32ad7 100644
    a b function bp_blogs_activity_comment_single_permalink( $retval, $activity ) { 
    952952        return $retval;
    953953}
    954954add_filter( 'bp_activity_get_permalink', 'bp_blogs_activity_comment_single_permalink', 10, 2 );
     955add_filter( 'bp_activity_get_shortlink', 'bp_blogs_activity_comment_single_permalink', 10, 2 );
    955956
    956957/**
    957958 * 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 b1931b5..8466d45 100644
    a b function groups_at_message_notification( $content, $poster_user_id, $group_id, $ 
    339339                if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
    340340                        $poster_name = bp_core_get_user_displayname( $poster_user_id );
    341341
    342                         $message_link  = bp_activity_get_permalink( $activity_id );
     342                        $message_link  = bp_activity_get_shortlink( $activity_id );
    343343                        $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    344344                        $settings_link = bp_core_get_user_domain( $receiver_user_id ) . $settings_slug . '/notifications/';
    345345
  • 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 dbce029..b775cf0 100644
    a b function bp_member_latest_update( $args = '' ) { 
    891891                if ( $view_link && ( $update_content != $update['content'] ) ) {
    892892                        $view = __( 'View', 'buddypress' );
    893893
    894                         $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_permalink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>';
     894                        $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_shortlink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>';
    895895                }
    896896
    897897                return apply_filters( 'bp_get_member_latest_update', $update_content );
  • 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