Вход Регистрация
Файл: adultscript-2.0.3-pro/files/modules/photo/components/add.php
Строк: 56
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_photo_add extends VModule_photo
{
    public function 
__construct()
    {
        
parent::__construct();
    }
    
    public function 
render()
    {
        
VLanguage::load('frontend.photo');

        if (!
$this->pcfg['upload_enabled']) {
            
$_SESSION['error'] = __('upload-disabled');
            
VModule::load('error', TRUE);
        }
        
        
VAuth::check('Registered');
        
        
$errors        = array();
        
$messages    = array();
        
$warnings    = array();
        
$unique     = time().'_'.mt_rand();
        
$user_id    = (int) $_SESSION['user_id'];
        
$album        = array();
        
$album_id    = (int) VUri::request(2);

        
$this->db->query("SELECT album_id, title, locked
                          FROM #__photo_albums
                          WHERE album_id = "
.$album_id."
                          AND user_id = "
.$user_id."
                          AND status = '1'
                          LIMIT 1"
);
        if (
$this->db->affected_rows()) {
              
$album    = $this->db->fetch_assoc();
        }
        
        if (isset(
$_POST['upload-submitted'])) {
            if (!
$file = VUpload::process('image_1', $this->pcfg['photo_max_size'], $this->pcfg['photo_allowed_ext'])) {
                  
$errors = array_merge($errors, VUpload::error());
            }
            
            if (!
$errors) {
                  
$filter        = VF::factory('filter');
                  
$image        = VF::factory('image');
                  
$images        = 0;
                  
$ids        = array();
                  foreach (
$_FILES as $key => $value) {
                      if (!empty(
$value['tmp_name'])) {
                          if (!
$file = VUpload::process($key, $this->pcfg['photo_max_size'], $this->pcfg['photo_allowed_ext'])) {
                              continue;
                        }
                                
                        if (!
$image->load($file['path'])) {
                            continue;
                        }

                        
$arr        = explode('_', $key);
                        
$id            = $arr['1'];
                        
$caption    = $filter->get('caption_'.$id);
                        
$this->db->query("INSERT INTO #__photo
                                          SET album_id = "
.$album_id.",
                                              caption = '"
.$this->db->escape($caption)."',
                                              ext = '"
.$this->db->escape($image->src['ext'])."',
                                              size = "
.$file['size'].",
                                              add_date = '"
.date('Y-m-d h:i:s')."',
                                              status = '0'"
);
                        if (!
$this->db->affected_rows()) {
                            continue;
                        }
                        
                        
$photo_id    = $this->db->get_last_insert_id('#__photo');
                        
$ext_orig   = $image->src['ext'];
                        
$dst_orig   = MEDIA_DIR.'/photos/orig/'.$photo_id.'.'.$ext_orig;
                        if (!
copy($file['path'], $dst_orig)) {
                              continue;
                        }
                        
                        
$dst            = MEDIA_DIR.'/photos/'.$photo_id.'.'.$image->src['ext'];
                        
$dst_thumb      = MEDIA_DIR.'/photos/thumbs/'.$photo_id.'.jpg';
                        
$dst_thumb_tmp  = TMP_DIR.'/images/'.$photo_id.'.thumb.jpg';
                        if (
$image->src['width'] < $this->pcfg['photo_width']) {
                            
copy($file['path'], $dst);
                        } else {
                            if (!
$image->resize($this->pcfg['photo_width'], $this->pcfg['photo_height'], 'MAX_WIDTH', $dst)) {
                                continue;
                            }
                        }

                        if (!empty(
$this->pcfg['mobile'])) {
                              
$dst_mobile = MEDIA_DIR.'/photos/mobile/'.$photo_id.'.'.$image->src['ext'];
                            if (
$image->src['width'] < $this->pcfg['mobile_width']) {
                                
copy($file['path'], $dst_mobile);
                            } else {
                                if (!
$image->resize($this->pcfg['mobile_width'], $this->pcfg['mobile_height'], 'MAX_WIDTH', $dst_mobile)) {
                                    continue;
                                }
                            }
                        }
                        
                        
$thumb_width    = $this->pcfg['thumb_width']+30;
                        
$thumb_height   = $this->pcfg['thumb_height']+100;
                        
$image->set_option('jpeg_quality', 100);
                        if (!
$image->resize($thumb_width, $thumb_height, 'MAX_HEIGHT', $dst_thumb_tmp)) {
                            continue;
                        }

                        
$image->clear();
                        
$image->load($dst_thumb_tmp);
                            
                        if (!
$image->crop_from_center($this->pcfg['thumb_width'], $this->pcfg['thumb_height'], $dst_thumb)) {
                              continue;
                        }
                            
                        ++
$images;
                        
$ids[]    = $photo_id;
                        
                        
$image->clear();

                        
VFile::delete($dst_thumb_tmp);
                      }
                  }
                  
                  if (
$images === 0) {
                      
$errors[]    = __('add-failed');
                  } else {
                      
$this->db->query("UPDATE #__photo_albums
                                        SET total_photos = total_photos+"
.$images."
                                        WHERE album_id = "
.$album_id."
                                        LIMIT 1"
);
                      
$this->db->query("UPDATE #__photo
                                        SET status = '1'
                                        WHERE album_id = "
.$album_id."
                                        AND photo_id IN ("
.implode(',', array_values($ids)).")");
                      
$messages[] = __('add-success');
                  }
            }
        }
        
        
$tpl                = VF::factory('template');
        
$tpl->menu          = 'photo';
        
$tpl->pcfg          = $this->pcfg;
        
$tpl->errors        = $errors;
        
$tpl->messages      = $messages;
        
$tpl->warnings      = $warnings;
        
$tpl->css           = array(TPL_REL.'/css/style_photo.css');
        
$tpl->album         = $album;
        
$tpl->unique        = $unique;
        
$tpl->extensions    = $this->pcfg['photo_allowed_ext'];
        
$tpl->max_size      = ($this->pcfg['photo_max_size']*1024*1024);
        
$tpl->load(array('header', 'photo_add', 'footer'));
        
$tpl->display();    
    }
}
Онлайн: 0
Реклама