Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/09/2012 10:10:47 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Remove unneeded globals and clean up some code in Activity component. See #3989.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-functions.php

    r5612 r5684  
    240240 * @param int $user_id
    241241 *
    242  * @global object $bp BuddyPress global settings
    243242 * @uses bp_get_user_meta()
    244243 * @uses apply_filters() To call the 'bp_activity_get_user_favorites' hook
     
    247246 */
    248247function bp_activity_get_user_favorites( $user_id = 0 ) {
    249     global $bp;
    250248
    251249    // Fallback to logged in user if no user_id is passed
     
    267265 * @param int $user_id
    268266 *
    269  * @global object $bp BuddyPress global settings
    270267 * @uses is_user_logged_in()
    271268 * @uses bp_get_user_meta()
     
    279276 */
    280277function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
    281     global $bp;
    282278
    283279    // Favorite activity stream items are for logged in users only
     
    326322 * @param int $user_id
    327323 *
    328  * @global object $bp BuddyPress global settings
    329324 * @uses is_user_logged_in()
    330325 * @uses bp_get_user_meta()
     
    337332 */
    338333function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
    339     global $bp;
    340334
    341335    // Favorite activity stream items are for logged in users only
     
    421415 * @param int $user_id
    422416 *
    423  * @global object $bp BuddyPress global settings
    424417 * @uses BP_Activity_Activity::total_favorite_count() {@link BP_Activity_Activity}
    425418 *
     
    427420 */
    428421function bp_activity_total_favorites_for_user( $user_id = 0 ) {
    429     global $bp;
    430422
    431423    // Fallback on displayed user, and then logged in user
     
    879871 * @param array $args See docs for $defaults for details
    880872 *
    881  * @global object $bp BuddyPress global settings
    882873 * @uses wp_parse_args()
    883874 * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
     
    889880 */
    890881function bp_activity_add( $args = '' ) {
    891     global $bp;
    892882
    893883    $defaults = array(
     
    10381028    extract( $params, EXTR_SKIP );
    10391029
    1040     if ( empty($content) || empty($user_id) || empty($activity_id) )
    1041         return false;
    1042 
    1043     if ( empty($parent_id) )
     1030    if ( empty( $content ) || empty( $user_id ) || empty( $activity_id ) )
     1031        return false;
     1032
     1033    if ( empty( $parent_id ) )
    10441034        $parent_id = $activity_id;
    10451035
     
    10501040    // Insert the activity comment
    10511041    $comment_id = bp_activity_add( array(
    1052         'id' => $id,
    1053         'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
    1054         'content' => apply_filters( 'bp_activity_comment_content', $content ),
    1055         'component' => $bp->activity->id,
    1056         'type' => 'activity_comment',
    1057         'user_id' => $user_id,
    1058         'item_id' => $activity_id,
     1042        'id'                => $id,
     1043        'action'            => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
     1044        'content'           => apply_filters( 'bp_activity_comment_content', $content ),
     1045        'component'         => $bp->activity->id,
     1046        'type'              => 'activity_comment',
     1047        'user_id'           => $user_id,
     1048        'item_id'           => $activity_id,
    10591049        'secondary_item_id' => $parent_id,
    1060         'hide_sitewide' => $is_hidden
     1050        'hide_sitewide'     => $is_hidden
    10611051    ) );
    10621052
     
    11201110 * @param array $args See docs for $defaults for details
    11211111 *
    1122  * @global object $bp BuddyPress global settings
    11231112 * @uses wp_parse_args()
    11241113 * @uses bp_activity_adjust_mention_count()
     
    11341123 */
    11351124function bp_activity_delete( $args = '' ) {
    1136     global $bp;
    11371125
    11381126    // Pass one or more the of following variables to delete by those variables
     
    11691157    $latest_update = bp_get_user_meta( $user_id, 'bp_latest_update', true );
    11701158    if ( !empty( $latest_update ) ) {
    1171         if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) )
     1159        if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) ) {
    11721160            bp_delete_user_meta( $user_id, 'bp_latest_update' );
     1161        }
    11731162    }
    11741163
     
    11911180     * @param array $args See docs for $defaults for details
    11921181     *
    1193      * @global object $bp BuddyPress global settings
    11941182     * @uses wp_parse_args()
    11951183     * @uses bp_activity_delete()
     
    11981186     */
    11991187    function bp_activity_delete_by_item_id( $args = '' ) {
    1200         global $bp;
    1201 
    1202         $defaults = array( 'item_id' => false, 'component' => false, 'type' => false, 'user_id' => false, 'secondary_item_id' => false );
     1188
     1189        $defaults = array(
     1190            'item_id'           => false,
     1191            'component'         => false,
     1192            'type'              => false,
     1193            'user_id'           => false,
     1194            'secondary_item_id' => false
     1195        );
    12031196        $r = wp_parse_args( $args, $defaults );
    12041197        extract( $r, EXTR_SKIP );
     
    13371330 * @param object $activity_obj (optional) The activity object
    13381331 *
    1339  * @global object $bp BuddyPress global settings
    13401332 * @uses bp_get_root_domain()
    13411333 * @uses bp_get_activity_root_slug()
     
    13451337 */
    13461338function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
    1347     global $bp;
    1348 
    1349     if ( !$activity_obj )
     1339
     1340    if ( empty( $activity_obj ) )
    13501341        $activity_obj = new BP_Activity_Activity( $activity_id );
    13511342
     
    13541345    }
    13551346
    1356     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 )
     1347    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 ) {
    13571348        $link = $activity_obj->primary_link;
    1358     else {
    1359         if ( 'activity_comment' == $activity_obj->type )
     1349    } else {
     1350        if ( 'activity_comment' == $activity_obj->type ) {
    13601351            $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->item_id . '/';
    1361         else
     1352        } else {
    13621353            $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->id . '/';
     1354        }
    13631355    }
    13641356
     
    13951387 */
    13961388function bp_activity_thumbnail_content_images( $content, $link = false ) {
    1397     global $post;
    13981389
    13991390    preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
     
    14061397        // Get the width and height
    14071398        preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
    1408         preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
     1399        preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i',  $matches[0][0], $width );
    14091400
    14101401        if ( !empty( $src ) ) {
    1411             $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
     1402            $src    = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
    14121403            $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
    1413             $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
     1404            $width  = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
    14141405
    14151406            if ( empty( $width ) || empty( $height ) ) {
    1416                 $width = 100;
     1407                $width  = 100;
    14171408                $height = 100;
    14181409            }
    14191410
    1420             $ratio = (int)$width / (int)$height;
     1411            $ratio      = (int)$width / (int)$height;
    14211412            $new_height = (int)$height >= 100 ? 100 : $height;
    1422             $new_width = $new_height * $ratio;
     1413            $new_width  = $new_height * $ratio;
    14231414
    14241415            $image = '<img src="' . esc_attr( $src ) . '" width="' . $new_width . '" height="' . $new_height . '" alt="' . __( 'Thumbnail', 'buddypress' ) . '" class="align-left thumbnail" />';
     
    14381429 * Convenience function to control whether the current user is allowed to mark activity items as spam
    14391430 *
    1440  * @global object $bp BuddyPress global settings
    14411431 * @return bool True if user is allowed to mark activity items as spam
    14421432 * @since 1.6
     
    14441434 */
    14451435function bp_activity_user_can_mark_spam() {
    1446     global $bp;
    14471436    return apply_filters( 'bp_activity_user_can_mark_spam', bp_current_user_can( 'bp_moderate' ) );
    14481437}
Note: See TracChangeset for help on using the changeset viewer.