Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/10/2012 12:52:16 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Avatars:

  • Clean up avatar code.
  • When uploading a png, use the correct file extension.
  • Fixes #4705.
  • Enqueue Jcrop styling.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-cssjs.php

    r6597 r6600  
    11<?php
     2
    23// Exit if accessed directly
    34if ( !defined( 'ABSPATH' ) ) exit;
    … …  
    2627                });
    2728        </script>
     29
    2830<?php
    2931}
    … …  
    3941 */
    4042function bp_core_add_jquery_cropper() {
     43        wp_enqueue_style( 'jcrop' );
    4144        wp_enqueue_script( 'jcrop', array( 'jquery' ) );
    4245        add_action( 'wp_head', 'bp_core_add_cropper_inline_js' );
    … …  
    5255 */
    5356function bp_core_add_cropper_inline_js() {
    54         global $bp;
    5557
    56         $image = apply_filters( 'bp_inline_cropper_image', getimagesize( bp_core_avatar_upload_path() . $bp->avatar_admin->image->dir ) );
    57         $aspect_ratio = 1;
     58        // Bail if no image was uploaded
     59        $image = apply_filters( 'bp_inline_cropper_image', getimagesize( bp_core_avatar_upload_path() . buddypress()->avatar_admin->image->dir ) );
     60        if ( empty( $image ) )
     61                return;
    5862
     63        //
    5964        $full_height = bp_core_avatar_full_height();
    6065        $full_width  = bp_core_avatar_full_width();
    6166
    6267        // Calculate Aspect Ratio
    63         if ( $full_height && ( $full_width != $full_height ) )
     68        if ( !empty( $full_height ) && ( $full_width != $full_height ) ) {
    6469                $aspect_ratio = $full_width / $full_height;
     70        } else {
     71                $aspect_ratio = 1;
     72        }
    6573
    66                 $width  = $image[0] / 2;
    67                 $height = $image[1] / 2;
    68 ?>
     74        // Default cropper coordinates
     75        $crop_left   = $image[0] / 4;
     76        $crop_top    = $image[1] / 4;
     77        $crop_right  = $image[0] - $crop_left;
     78        $crop_bottom = $image[1] - $crop_top; ?>
    6979
    7080        <script type="text/javascript">
    … …  
    7484                                onSelect: showPreview,
    7585                                onSelect: updateCoords,
    76                                 aspectRatio: <?php echo $aspect_ratio ?>,
    77                                 setSelect: [ 50, 50, <?php echo $width ?>, <?php echo $height ?> ]
     86                                aspectRatio: <?php echo $aspect_ratio; ?>,
     87                                setSelect: [ <?php echo $crop_left; ?>, <?php echo $crop_top; ?>, <?php echo $crop_right; ?>, <?php echo $crop_bottom; ?> ]
    7888                        });
    79                         updateCoords({x: 50, y: 50, w: <?php echo $width ?>, h: <?php echo $height ?>});
     89                        updateCoords({x: <?php echo $crop_left; ?>, y: <?php echo $crop_top; ?>, w: <?php echo $crop_right; ?>, h: <?php echo $crop_bottom; ?>});
    8090                });
    8191
    … …  
    8999                function showPreview(coords) {
    90100                        if ( parseInt(coords.w) > 0 ) {
    91                                 var rx = <?php echo $full_width; ?> / coords.w;
    92                                 var ry = <?php echo $full_height; ?> / coords.h;
     101                                var fw = <?php echo $full_width; ?>;
     102                                var fh = <?php echo $full_height; ?>;
     103                                var rx = fw / coords.w;
     104                                var ry = fh / coords.h;
    93105
    94                                 jQuery('#avatar-crop-preview').css({
    95                                 <?php if ( $image ) : ?>
     106                                jQuery( '#avatar-crop-preview' ).css({
    96107                                        width: Math.round(rx * <?php echo $image[0]; ?>) + 'px',
    97108                                        height: Math.round(ry * <?php echo $image[1]; ?>) + 'px',
    98                                 <?php endif; ?>
    99109                                        marginLeft: '-' + Math.round(rx * coords.x) + 'px',
    100110                                        marginTop: '-' + Math.round(ry * coords.y) + 'px'
    … …  
    119129        <style type="text/css">
    120130                .jcrop-holder { float: left; margin: 0 20px 20px 0; text-align: left; }
    121                 .jcrop-vline, .jcrop-hline { font-size: 0; position: absolute; background: white top left repeat url('<?php echo BP_PLUGIN_URL ?>/bp-core/images/Jcrop.gif'); }
    122                 .jcrop-vline { height: 100%; width: 1px !important; }
    123                 .jcrop-hline { width: 100%; height: 1px !important; }
    124                 .jcrop-handle { font-size: 1px; width: 7px !important; height: 7px !important; border: 1px #eee solid; background-color: #333; *width: 9px; *height: 9px; }
    125                 .jcrop-tracker { width: 100%; height: 100%; }
    126                 .custom .jcrop-vline, .custom .jcrop-hline { background: yellow; }
    127                 .custom .jcrop-handle { border-color: black; background-color: #C7BB00; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
    128131                #avatar-crop-pane { width: <?php echo bp_core_avatar_full_width() ?>px; height: <?php echo bp_core_avatar_full_height() ?>px; overflow: hidden; }
    129132                #avatar-crop-submit { margin: 20px 0; }
    130                 #avatar-upload-form img, #create-group-form img, #group-settings-form img { border: none !important; }
     133                #avatar-upload-form img,
     134                #create-group-form img,
     135                #group-settings-form img { border: none !important; max-width: none !important; }
    131136        </style>
    132137
Note: See TracChangeset for help on using the changeset viewer.