Skip to:
Content

BuddyPress.org

Changeset 373 for trunk/bp-groups.php


Ignore:
Timestamp:
10/07/2008 07:16:51 AM (18 years ago)
Author:
apeatling
Message:

Bug fixes:

  • Fixed group avatar upload issues
  • Fixed validation on group name/desc/news
  • Fixed support for https://
  • Base support for upcoming home theme and widgets
  • Re-factored JS and CSS inclusion with wp_enqueue_script/styles
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups.php

    r359 r373  
    33
    44define ( 'BP_GROUPS_IS_INSTALLED', 1 );
    5 define ( 'BP_GROUPS_VERSION', '0.1.5' );
     5define ( 'BP_GROUPS_VERSION', '0.1.6' );
    66
    77include_once( 'bp-groups/bp-groups-classes.php' );
    88include_once( 'bp-groups/bp-groups-ajax.php' );
    99include_once( 'bp-groups/bp-groups-cssjs.php' );
     10include_once( 'bp-groups/bp-groups-templatetags.php' );
     11include_once( 'bp-groups/bp-groups-widgets.php' );
    1012/*include_once( 'bp-messages/bp-groups-admin.php' );*/
    11 include_once( 'bp-groups/bp-groups-templatetags.php' );
    12 
    1313
    1414/**************************************************************************
     
    9292                'table_name' => $wpdb->base_prefix . 'bp_groups',
    9393                'table_name_members' => $wpdb->base_prefix . 'bp_groups_members',
    94                 'image_base' => get_option('siteurl') . '/wp-content/mu-plugins/bp-groups/images',
     94                'image_base' => site_url() . '/wp-content/mu-plugins/bp-groups/images',
    9595                'format_activity_function' => 'groups_format_activity',
    9696                'slug'           => 'groups'
     
    552552        $avatar_error = false;
    553553
    554         if ( bp_core_check_avatar_upload($file) ) {
    555                 if ( !bp_core_check_avatar_upload($file) ) {
    556                         $avatar_error = true;
    557                         $avatar_error_msg = __('Your group avatar upload failed, please try again.');
    558                 }
    559 
    560                 if ( !bp_core_check_avatar_size($file) ) {
    561                         $avatar_error = true;
    562                         $avatar_size = size_format(1024 * CORE_MAX_FILE_SIZE);
    563                         $avatar_error_msg = sprintf( __('The file you uploaded is too big. Please upload a file under %d'), $avatar_size);
    564                 }
    565 
    566                 if ( !bp_core_check_avatar_type($file) ) {
    567                         $avatar_error = true;
    568                         $avatar_error_msg = __('Please upload only JPG, GIF or PNG photos.');           
    569                 }
    570 
    571                 // "Handle" upload into temporary location
    572                 if ( !$original = bp_core_handle_avatar_upload($file) ) {
    573                         $avatar_error = true;
    574                         $avatar_error_msg = __('Upload Failed! Your photo dimensions are likely too big.');                                             
    575                 }
    576 
    577                 if ( !bp_core_check_avatar_dimensions($original) ) {
    578                         $avatar_error = true;
    579                         $avatar_error_msg = sprintf( __('The image you upload must have dimensions of %d x %d pixels or larger.'), CORE_CROPPING_CANVAS_MAX, CORE_CROPPING_CANVAS_MAX );
    580                 }
    581                
    582                 if ( !$canvas = bp_core_resize_avatar($original) ) {
    583                         $avatar_error = true;
    584                         $avatar_error_msg = __('Could not create thumbnail, try another photo.');
    585                 }
    586                
    587                 if ( $avatar_error ) { ?>
    588                         <div id="message" class="error">
    589                                 <p><?php echo $avatar_error_msg ?></p>
    590                         </div>
    591                         <?php
    592                         bp_core_render_avatar_upload_form( '', true );
    593                 } else {
    594                         bp_core_render_avatar_cropper( $original, $canvas, null, null, false, $bp['loggedin_domain'] );
    595                 }
     554        // Set friendly error feedback.
     555        $uploadErrors = array(
     556                0 => __("There is no error, the file uploaded with success"),
     557                1 => __("The uploaded file exceeds the upload_max_filesize directive in php.ini"),
     558                2 => __("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
     559                3 => __("The uploaded file was only partially uploaded"),
     560                4 => __("No file was uploaded"),
     561                6 => __("Missing a temporary folder")
     562        );
     563
     564        if ( !bp_core_check_avatar_upload($file) ) {
     565                $avatar_error = true;
     566                $avatar_error_msg = __('Your group avatar upload failed, please try again. Error was: ' . $uploadErrors[$file['file']['error']] );
     567        }
     568
     569        else if ( !bp_core_check_avatar_size($file) ) {
     570                $avatar_error = true;
     571                $avatar_size = size_format(1024 * CORE_MAX_FILE_SIZE);
     572                $avatar_error_msg = __('The file you uploaded is too big. Please upload a file under') . size_format(1024 * CORE_MAX_FILE_SIZE);
     573        }
     574       
     575        else if ( !bp_core_check_avatar_type($file) ) {
     576                $avatar_error = true;
     577                $avatar_error_msg = __('Please upload only JPG, GIF or PNG photos.');           
     578        }
     579
     580        // "Handle" upload into temporary location
     581        else if ( !$original = bp_core_handle_avatar_upload($file) ) {
     582                $avatar_error = true;
     583                $avatar_error_msg = __('Upload Failed! Your photo dimensions are likely too big.');                                             
     584        }
     585
     586        else if ( !bp_core_check_avatar_dimensions($original) ) {
     587                $avatar_error = true;
     588                $avatar_error_msg = sprintf( __('The image you upload must have dimensions of %d x %d pixels or larger.'), CORE_CROPPING_CANVAS_MAX, CORE_CROPPING_CANVAS_MAX );
     589        }
     590       
     591        if ( !$canvas = bp_core_resize_avatar($original) )
     592                $canvas = $original;
     593       
     594        if ( $avatar_error ) { ?>
     595                <div id="message" class="error">
     596                        <p><?php echo $avatar_error_msg ?></p>
     597                </div>
     598                <?php
     599                bp_core_render_avatar_upload_form( '', true );
     600        } else {
     601                bp_core_render_avatar_cropper( $original, $canvas, null, null, false, $bp['loggedin_domain'] );
    596602        }
    597603}
     
    623629
    624630function groups_manage_group( $step, $group_id ) {
    625         global $bp;
     631        global $bp, $create_group_step;
    626632       
    627633        if ( is_numeric( $step ) && ( $step == '1' || $step == '2' || $step == '3' || $step == '4' ) ) {
    628                 // If this is the group avatar step, load in the JS.
    629                 if ( $create_group_step == '3' )
    630                         add_action( 'wp_head', 'bp_core_add_cropper_js' );
    631                
    632634                $group = new BP_Groups_Group( $group_id );             
    633635               
    634636                switch ( $step ) {
    635637                        case '1':
    636                                 if ( isset($_POST['group-name']) && isset($_POST['group-desc']) ) {
     638                                if ( $_POST['group-name'] != '' && $_POST['group-desc'] != '' && $_POST['group-news'] != '' ) {
    637639                                        $group->creator_id = $bp['loggedin_userid'];
    638640                                        $group->name = stripslashes($_POST['group-name']);
     
    667669                                        return $group->id;
    668670                                }
     671                               
     672                                return false;
    669673                        break;
    670674                       
     
    703707                       
    704708                        case '3':
     709                                                               
    705710                                // Image already cropped and uploaded, lets store a reference in the DB.
    706711                                if ( !wp_verify_nonce($_POST['nonce'], 'slick_avatars') || !$result = bp_core_avatar_cropstore( $_POST['orig'], $_POST['canvas'], $_POST['v1_x1'], $_POST['v1_y1'], $_POST['v1_w'], $_POST['v1_h'], $_POST['v2_x1'], $_POST['v2_y1'], $_POST['v2_w'], $_POST['v2_h'], false, 'groupavatar', $group_id ) )
     
    869874}
    870875
     876function groups_remove_data( $user_id ) {
     877        BP_Groups_Member::delete_all_for_user($user_id);
     878}
     879add_action( 'wpmu_delete_user', 'bp_core_remove_data', 1 );
     880add_action( 'delete_user', 'bp_core_remove_data', 1 );
     881
    871882
    872883?>
Note: See TracChangeset for help on using the changeset viewer.