Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/templates/default/extend/ajax/avatar.plugin.php
Строк: 17
<?php
defined
('_VALID') or die('Restricted Access!');
function 
ajax_plugin_avatar()
{
    
$data = array('status' => 0'msg' => '''code' => '''debug' => '''width' => 0'height' => 0);
    if (isset(
$_POST['user_id']) && isset($_FILES['userfile'])) {
        
$ucfg         VF::cfg('module.user');
        
$user_id    = (int) trim($_POST['user_id']);
        if (
$avatar VUpload::process('userfile'$ucfg['avatar_max_size'], $ucfg['avatar_allowed_ext'])) {
            
$photo      $user_id.'.'.$avatar['ext'];
            
$dst_orig   MEDIA_DIR.'/users/orig/'.$photo;
            
$dwidth     $ucfg['avatar_width'];
            
$dheight    $ucfg['avatar_height'];
            if (
move_uploaded_file($avatar['path'], $dst_orig)) {
                  
$dst_tmp    TMP_DIR.'/uploads/'.$photo;
                
$dst_thumb  MEDIA_DIR.'/users/'.$photo;
                
$image      VF::factory('image');
                if (!
$image->load($dst_orig)) {
                      
$data['msg'] = $image->get_error();
                } else {
                      
$img        getimagesize($dst_orig);
                    
$width      $img['0'];
                    
$height     $img['1'];
                    if (
$ucfg['avatar_method'] == 'canvas' OR
                          
$width $dwidth OR $height $dheight) {
                        if (
$image->canvas($dwidth$dheight'000000') &&
                              
$image->resize($dwidth$dheight'ASPECT_RATIO'$dst_tmp)) {
                            if (
$image->load($dst_tmp) &&
                                  
$image->crop_from_center($dwidth$dheight$dst_thumb)) {
                                
$processed TRUE;
                            } else {
                                
$data['msg'] = $image->get_error();
                            } 
                        } else {
                            
$data['msg'] = $image->get_error();
                        }
                    } else {
                        
$twidth     $dwidth*3;
                        
$theight    $dheight*3;
                        if (
$width $twidth OR $height $height) {
                              if (!
$image->resize($twidth$theight'TO_ASPECT_RATIO'$dst_tmp)) {
                                  
$data['msg'] = $image->get_error();
                            }
                        } else {
                            
copy($dst_orig$dst_tmp);
                        } 
                    
                          if (
$data['msg'] == '') {
                              
$data['width']         = $dwidth;
                              
$data['height']     = $dheight;
                        }
                    }
                    
                    if (isset(
$processed) && $processed === true) {
                        
$db VF::factory('database');
                        
$db->query("UPDATE #__user SET avatar = '".$db->escape($avatar['ext'])."' WHERE user_id = ".$user_id." LIMIT 1");
                        
$data['status'] = 1;
                        
$data['msg']     = 'Avatar uploaded!';
                        
$data['code']    = MEDIA_URL.'/users/'.$user_id.'.'.$avatar['ext'].'?'.rand(1100);
                    } else {
                        
$data['status'] = 2;
                        
$data['code']    = TMP_URL.'/uploads/'.$photo.'?'.rand(1100);
                        
$data['msg']    = 'Avatar uploaded! Please crop below!';
                    }
                }
            } else {
                
$data['msg'] = 'Failed to move uploaded file! Invalid permissions!?';
            }
        } else {
              
$error          VUpload::error();
              
$data['msg'] = $error['0'];
        }
    } else {
        
$data['msg'] = 'Invalid ajax request!';
    }
    
    return 
json_encode($data);
}
Онлайн: 0
Реклама