Skip to:
Content

BuddyPress.org

Ticket #5926: 5926.02.patch

File 5926.02.patch, 12.8 KB (added by DJPaul, 10 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 1444c89..622efa1 100644
    a b function bp_activity_delete_comment( $activity_id, $comment_id ) { 
    25152515 *
    25162516 * @since BuddyPress (1.2.0)
    25172517 *
    2518  * @uses bp_get_root_domain()
    2519  * @uses bp_get_activity_root_slug()
    2520  * @uses apply_filters_ref_array() To call the 'bp_activity_get_permalink' hook.
    2521  *
    25222518 * @param int $activity_id The unique id of the activity object.
    25232519 * @param object $activity_obj Optional. The activity object.
    25242520 * @return string $link Permalink for the activity item.
    function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 
    25472543
    25482544        if ( false !== array_search( $activity_obj->type, $use_primary_links ) ) {
    25492545                $link = $activity_obj->primary_link;
     2546
    25502547        } else {
    25512548                if ( 'activity_comment' == $activity_obj->type ) {
    2552                         $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->item_id . '/';
     2549                        $id = (int) $activity_obj->item_id;
    25532550                } else {
    2554                         $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->id . '/';
     2551                        $id = (int) $activity_obj->id;
    25552552                }
     2553
     2554                $link = bp_core_get_user_domain( $activity_obj->user_id ) . bp_get_activity_slug() . "/{$id}/";
    25562555        }
    25572556
    25582557        /**
    function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 
    25662565}
    25672566
    25682567/**
     2568 * Get the shortlink for a single activity item.
     2569 *
     2570 * When only the $activity_id param is passed, BP has to instantiate a new
     2571 * BP_Activity_Activity object. To save yourself some processing overhead,
     2572 * be sure to pass the full $activity_obj parameter as well, if you already
     2573 * have it available.
     2574 *
     2575 * @param int $activity_id The unique id of the activity object.
     2576 * @param object $activity_obj Optional. The activity object.
     2577 * @return string $link Permalink for the activity item.
     2578 * @since BuddyPress (2.3.0)
     2579 */
     2580function bp_activity_get_shortlink( $activity_id, $activity_obj = false ) {
     2581        $bp = buddypress();
     2582
     2583        if ( empty( $activity_obj ) ) {
     2584                $activity_obj = new BP_Activity_Activity( $activity_id );
     2585        }
     2586
     2587        if ( isset( $activity_obj->current_comment ) ) {
     2588                $activity_obj = $activity_obj->current_comment;
     2589        }
     2590
     2591        $use_primary_links = array(
     2592                'new_blog_post',
     2593                'new_blog_comment',
     2594                'new_forum_topic',
     2595                'new_forum_post',
     2596        );
     2597
     2598        if ( ! empty( $bp->activity->track ) ) {
     2599                $use_primary_links = array_merge( $use_primary_links, array_keys( $bp->activity->track ) );
     2600        }
     2601
     2602        if ( false !== array_search( $activity_obj->type, $use_primary_links ) ) {
     2603                $link = $activity_obj->primary_link;
     2604
     2605        } else {
     2606                if ( 'activity_comment' == $activity_obj->type ) {
     2607                        $id = (int) $activity_obj->item_id;
     2608                } else {
     2609                        $id = (int) $activity_obj->id;
     2610                }
     2611
     2612                $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . "/p/{$id}/";
     2613        }
     2614
     2615        /**
     2616         * Filters the activity shortlink for the specified activity item.
     2617         *
     2618         * @param array $array Array holding activity shortlink and activity item object.
     2619         * @since BuddyPress (2.3.0)
     2620         */
     2621        return apply_filters_ref_array( 'bp_activity_get_shortlink', array( $link, &$activity_obj ) );
     2622}
     2623
     2624/**
    25692625 * Hide a user's activity.
    25702626 *
    25712627 * @since BuddyPress (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 0ace28f..f0fd222 100644
    a b 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 
    155153 *
    156154 * @uses bp_get_user_meta()
    157155 * @uses bp_core_get_user_displayname()
    158  * @uses bp_activity_get_permalink()
    159156 * @uses bp_core_get_user_domain()
    160157 * @uses bp_get_settings_slug()
    161158 * @uses bp_activity_filter_kses()
    function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 
    189186
    190187        if ( $original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {
    191188                $poster_name   = bp_core_get_user_displayname( $commenter_id );
    192                 $thread_link   = bp_activity_get_permalink( $activity_id );
     189                $thread_link   = bp_activity_get_shortlink( $activity_id );
    193190                $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    194191                $settings_link = bp_core_get_user_domain( $original_activity->user_id ) . $settings_slug . '/notifications/';
    195192
    To view your original update and all comments, log in and visit: %3$s 
    276273
    277274        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 ) ) {
    278275                $poster_name   = bp_core_get_user_displayname( $commenter_id );
    279                 $thread_link   = bp_activity_get_permalink( $activity_id );
     276                $thread_link   = bp_activity_get_shortlink( $activity_id );
    280277                $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
    281278                $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . $settings_slug . '/notifications/';
    282279
  • 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 e4a8cc7..58b600a 100644
    a b function bp_insert_activity_meta( $content ) { 
    18521852                 *
    18531853                 * @since BuddyPress (1.2.0)
    18541854                 *
    1855                  * @param array $value Array containing the html markup for the activity permalink, after being parsed by sprintf and current activity component.
     1855                 * @param array $value Array containing the html markup for the activity shortlink, after being parsed by sprintf and current activity component.
    18561856                 */
    1857                 $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 ) );
     1857                $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 ) );
    18581858        } else {
    18591859                $content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH );
    18601860        }
    function bp_activity_thread_permalink() { 
    27672767        }
    27682768
    27692769/**
     2770 * Output the activity thread shortlink.
     2771 *
     2772 * @since BuddyPress (2.3.0)
     2773 */
     2774function bp_activity_thread_shortlink() {
     2775        echo bp_get_activity_thread_shortlink();
     2776}
     2777
     2778        /**
     2779         * Return the activity thread shortlink.
     2780         *
     2781         * @return string $link The activity thread shortlink.
     2782         * @since BuddyPress (2.3.0)
     2783         */
     2784        function bp_get_activity_thread_shortlink() {
     2785                global $activities_template;
     2786
     2787                $link = bp_activity_get_shortlink( $activities_template->activity->id, $activities_template->activity );
     2788                return apply_filters( 'bp_get_activity_thread_shortlink', $link );
     2789        }
     2790
     2791/**
    27702792 * Output the activity comment permalink.
    27712793 *
    27722794 * @since BuddyPress (1.8.0)
    function bp_activity_comment_permalink() { 
    28142836        }
    28152837
    28162838/**
     2839 * Output the activity comment shortlink.
     2840 *
     2841 * @since BuddyPress (2.3.0)
     2842 */
     2843function bp_activity_comment_shortlink() {
     2844        echo bp_get_activity_comment_shortlink();
     2845}
     2846        /**
     2847         * Return the activity comment shortlink.
     2848         *
     2849         * @return string $link The activity comment shortlink.
     2850         * @since BuddyPress (2.3.0)
     2851         */
     2852        function bp_get_activity_comment_shortlink() {
     2853                global $activities_template;
     2854
     2855                // Check that comment exists
     2856                $comment_id = isset( $activities_template->activity->current_comment->id )
     2857                        ? $activities_template->activity->current_comment->id
     2858                        : 0;
     2859
     2860                // Append comment ID to end of activity shortlink
     2861                $comment_link = ! empty( $comment_id ) ? '#acomment-' . $comment_id : false;
     2862                $link         = bp_activity_get_shortlink( $activities_template->activity->id, $activities_template->activity );
     2863
     2864                return apply_filters( 'bp_get_activity_comment_shortlink', $link . $comment_link, $comment_id );
     2865        }
     2866
     2867/**
    28172868 * Output the activity favorite link.
    28182869 *
    28192870 * @since BuddyPress (1.2.0)
    function bp_activity_latest_update( $user_id = 0 ) { 
    31043155                $latest_update = sprintf(
    31053156                        '%s <a href="%s">%s</a>',
    31063157                        $latest_update,
    3107                         esc_url_raw( bp_activity_get_permalink( $update['id'] ) ),
     3158                        esc_url_raw( bp_activity_get_shortlink( $update['id'] ) ),
    31083159                        esc_attr__( 'View', 'buddypress' )
    31093160                );
    31103161
  • 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 030507f..2003cb5 100644
    a b function bp_blogs_activity_comment_single_permalink( $retval, $activity ) { 
    10461046        return $retval;
    10471047}
    10481048add_filter( 'bp_activity_get_permalink', 'bp_blogs_activity_comment_single_permalink', 10, 2 );
     1049add_filter( 'bp_activity_get_shortlink', 'bp_blogs_activity_comment_single_permalink', 10, 2 );
    10491050
    10501051/**
    10511052 * 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 7eda78c..f848247 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 85929e5..9666746 100644
    a b function bp_member_latest_update( $args = '' ) { 
    10851085                if ( $view_link && ( $update_content != $update['content'] ) ) {
    10861086                        $view = __( 'View', 'buddypress' );
    10871087
    1088                         $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_permalink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>';
     1088                        $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_shortlink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>';
    10891089                }
    10901090
    10911091                /**
  • 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