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

    public function 
render()
    {
        
VAuth::check('Registered');

        
$album_id    = (VUri::request(2)) ? (int) VUri::request(2) : 0;
        
$user_id    = (int) $_SESSION['user_id'];
        
        if (!
VUri::match('photo/edit/'.$album_id.'/')) {
            
VModule::load('404'TRUE);
        }
        
        
VLanguage::load('frontend.photo');
        
        
$this->db->query("SELECT a.locked, a.cover, GROUP_CONCAT(DISTINCT c.cat_id) AS categories,
                                 GROUP_CONCAT(DISTINCT t.name) AS tags
                          FROM #__photo_albums AS a
                          LEFT JOIN #__photo_category AS c ON (c.album_id = a.album_id)
                          LEFT JOIN #__photo_tags AS t ON (t.album_id = a.album_id)
                          WHERE a.album_id = "
.$album_id."
                          AND a.user_id = "
.$user_id."
                          AND a.status = '1'
                          LIMIT 1"
);
        if (!
$this->db->affected_rows()) {
            
$_SESSION['error'] = __('album-invalid');
            
VModule::load('error'TRUE);
        }

        
$errors         = array();
        
$messages       = array();
        
$warnings        = array();
        
$album            $this->db->fetch_assoc();
        
$pcfg            VF::cfg('module.photo');
        
$locked            = (bool) $album['locked'];
        
$ocategories    explode(','$album['categories']);
        
sort($ocategories);
        
$ocover            = (int) $album['cover'];
        
$otags            = (int) $album['tags'];
        
$categories     $this->get_photo_categories();
        
        if (isset(
$_POST['submit-edit']) && !$locked) {
              
$filter            VF::factory('filter');
              
$title            $filter->get('title');
              
$description    $filter->get('description');
              
$type            $filter->get('type');
              
$category        = (array) $_POST['category'];
              
sort($category);
              
$tags            $filter->get('tags');
              
$cover_id        = (int) trim($_POST['cover_id']);
              
$password        = (isset($_POST['password'])) ? trim($_POST['password']) : '';

            if (
$title == '') {
                  
$errors[]       = __('title-empty');
            } elseif (!
VValid::length($title$pcfg['title_min_length'], $pcfg['title_max_length'])) {
                
$errors[]       = __('title-length', array($pcfg['title_min_length'], $pcfg['title_max_length']));
            }

            if (!
$category) {
                  
$errors[]       = __('category-empty');
            } else {
                
$cats = array();
                foreach (
$categories as $cat) {
                    
$cats[$cat['cat_id']] = 1;
                }

                foreach (
$category as $cat) {
                      if (!isset(
$cats[$cat])) {
                          
$error TRUE;
                        break;
                    }
                }

                if (isset(
$error)) {
                    
$errors[] = __('category-invalid');
                }
            }

            if (
$tags == '') {
                  
$errors[] = __('tags-empty');
            } elseif (!
VValid::length($tags$pcfg['tags_min_length'], $pcfg['tags_max_length'])) {
                
$errors[] = __('tags-length', array($pcfg['tags_min_length'],$pcfg['tags_max_length']));
            } else {
                
$tags   prepare_tags($tags);
                if (
$tags == '') {
                      
$errors[] = __('tags-invalid');
                }
            }
            
            if (!
$errors) {
                  
$pass    = ($password) ? VHash::encrypt($password) : '';
                  
$this->db->query("UPDATE #__photo_albums
                                    SET title = '"
.$this->db->escape($title)."',
                                          slug = '"
.$this->db->escape(prepare_string($titleTRUE))."',
                                          description = '"
.$this->db->escape($description)."',
                                          password = '"
.$this->db->escape($pass)."',
                                          type = '"
.$this->db->escape($type)."',
                                          cover = "
.$cover_id."
                                      WHERE album_id = "
.$album_id."
                                      AND user_id = "
.$user_id."
                                      AND locked = '0'
                                      AND status = '1'
                                      LIMIT 1"
);
                  
                  if (
$category != $ocategories) {
                      foreach (
$ocategories as $categ) {
                          if (!
in_array($categ$category)) {
                              
$this->db->query("DELETE FROM #__photo_category WHERE album_id = ".$album_id." AND cat_id = ".$categ." LIMIT 1");
                              
$this->db->query("UPDATE #__photo_categories SET total_albums = total_albums-1 WHERE cat_id = ".$categ." LIMIT 1");
                          }
                      }
                      
                      foreach (
$category as $categ) {
                          if (!
in_array($categ$ocategories)) {
                              
$this->db->query("INSERT INTO #__photo_category SET cat_id = ".$categ.", album_id = ".$album_id);
                              
$this->db->query("UPDATE #__photo_categories SET total_albums = total_albums+1 WHERE cat_id = ".$categ." LIMIT 1");
                          }
                      }
                  }
                  
                  if (
$otags != $tags) {
                      
$this->db->query("DELETE FROM #__photo_tags WHERE album_id = ".$album_id);
                      
                      
$tags explode(','$tags);
                      foreach (
$tags as $tag) {
                          
$this->db->query("INSERT INTO #__photo_tags SET album_id = ".$album_id.", name = '".$this->db->escape($tag));
                      }
                  }
                  
                  if (
$ocover !== $cover_id) {
                      
$src    MEDIA_DIR.'/photos/thumbs/'.$cover_id.'.jpg';
                      
$dst    MEDIA_DIR.'/photos/covers/'.$album_id.'.jpg';
                      
$image    VF::factory('image');
                      
$image->load($src);
                    if (
$image->src['height'] < $pcfg['cover_height']) {
                          
$this->db->query("SELECT ext FROM #__photo WHERE photo_id = ".$cover_id." LIMIT 1");
                          
$ext    $this->db->fetch_field('ext');

                        
$src    MEDIA_DIR.'/photos/orig/'.$cover_id.'.'.$ext;
                        
$image->clear();
                        
$image->load($src);
                        
$cover_max_width    = ($pcfg['cover_width'] + 30);
                        
$cover_max_height   = ($pcfg['cover_height'] + 50);

                        if (
$image->src['width'] > $cover_max_width && $image->src['height'] > $cover_max_height) {
                            
$dst_tmp TMP_DIR.'/images/'.$cover_id.'.jpg';
                            
$image->set_option('jpeg_quality'100);
                            
$image->resize($cover_max_width$cover_max_height'MAX_HEIGHT'$dst_tmp);
                            
$src     $dst_tmp;
                        }
                    }
                    
                    
$image->clear();
                    
$image->load($src);
                    
$image->crop_from_center($pcfg['cover_width'], $pcfg['cover_height'], $dst);
                    
                    if (isset(
$dst_tmp)) {
                        
VFile::delete($dst_tmp);
                    }
                  }
                  
                  
$messages[] = __('edit-success');
            }
        }
        
        
$this->db->query("SELECT a.album_id, a.title, a.slug, a.description, a.type, a.cover, a.password,
                                 GROUP_CONCAT(DISTINCT c.cat_id) AS category,
                                 GROUP_CONCAT(DISTINCT t.name) AS tags
                          FROM #__photo_albums AS a
                          LEFT JOIN #__photo_category AS pc ON (pc.album_id = a.album_id)
                          LEFT JOIN #__photo_categories AS c ON (c.cat_id = pc.cat_id)
                          LEFT JOIN #__photo_tags AS t ON (t.album_id = a.album_id)
                          WHERE a.album_id = "
.$album_id."
                          AND a.user_id = "
.$user_id."
                          AND a.status = '1'
                          LIMIT 1"
);
        if (
$this->db->affected_rows()) {
              
$album                 $this->db->fetch_assoc();
              
$album['category']    = explode(','$album['category']);
        } else {
              
$_SESSION['error'] = __('album-invalid');
              
VModule::load('error'TRUE);
        }

        
$sql            "SELECT photo_id, caption, total_views, total_comments,rating, rated_by
                           FROM #__photo
                           WHERE album_id = "
.$album_id."
                           AND status = '1'
                           ORDER BY photo_id ASC"
;
        if (!
$photos $this->cache->get($sql3600)) {
              
$this->db->query($sql);
            if (
$this->db->affected_rows()) {
                  
$photos $this->db->fetch_rows();
                
$this->cache->store($sql$photos3600);
            } else {
                  
VModule::load('404'TRUE);
            }
        }

        if (
$locked) {
              
$warnings[] = __('edit-locked');
        }

        
$this->tpl->menu        'photo';
        
        
$this->tpl->meta_title    __('edit-meta-title');
        
        
$this->tpl->css            = array(
              
TPL_REL.'/css/style_photo.css',
        );

        
$this->tpl->errors        $errors;
        
$this->tpl->messages    $messages;
        
$this->tpl->warnings    $warnings;
        
$this->tpl->categories    $categories;
        
$this->tpl->album        $album;
        
$this->tpl->photos        $photos;
        
$this->tpl->load(array('header''photo_edit''footer'));
        
$this->tpl->display();
    }
}
?>
Онлайн: 0
Реклама