Вход Регистрация
Файл: adultscript-2.0.3-pro/files/mobile/components/photo_edit.php
Строк: 104
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_mobile_photo_edit extends VComponent_mobile_photo
{
    private 
$pcfg;
    public function 
__construct()
    {
        
parent::__construct();
        
        
$this->pcfg    VF::cfg('module.photo');
    }
    
    public function 
render()
    {
        
VAuth::check('Registered'MOBILE_URL.'/user/login/');
        
        
$album_id    = (VUri::request(2)) ? (int) VUri::request(2) : 0;
        
$user_id    = (int) $_SESSION['user_id'];
        
        if (!
VUri::match('photo/edit/'.$album_id.'/')) {
            
$this->notfound();
        }

        
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()) {
              
$this->notfound(__('album-invalid'));
        }
        
        
$errors         = array();
        
$messages       = array();
        
$warnings       = array();
        
$album          $this->db->fetch_assoc();
        
$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$this->pcfg['title_min_length'], $this->pcfg['title_max_length'])) {
                
$errors[]       = __('title-length', array($this->pcfg['title_min_length'], $this->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$this->pcfg['tags_min_length'], $this->pcfg['tags_max_length'])) {
                
$errors[] = __('tags-length', array($this->pcfg['tags_min_length'],$this->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'] < $this->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    = ($this->pcfg['cover_width'] + 30);
                        
$cover_max_height   = ($this->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($this->pcfg['cover_width'], $this->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 {
              
$this->notfound(__('album-invalid'));
        }

        
$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 {
                  
$this->notfound();
            }
        }
        
        if (
$locked) {
            
$warnings[] = __('edit-locked');
        }

        
    
        
$this->tpl->menu        'photo';

        
$this->tpl->meta_title    __('photo-edit-meta-title', array($this->mcfg['site_name']));

        
$this->tpl->canonical    BASE_URL.'/photo/edit/'.$album_id.'/';

        
$this->tpl->errors        $errors;
        
$this->tpl->messages    $messages;
        
$this->tpl->warnings    $warnings;
        
$this->tpl->album       $album;
        
$this->tpl->photos      $photos;
        
$this->tpl->categories    $categories;        
        
$this->tpl->load(array('header''photo_edit''footer'));
        
$this->tpl->display();
    }
    
    private function 
get_photo_categories()
    {
        if (!
$categories $this->cache->get('photo_categories'86400)) {
            
$this->db->query('SELECT cat_id, name, slug, description, total_albums FROM #__photo_categories ORDER BY name ASC');
            if (
$this->db->affected_rows()) {
                
$categories $this->db->fetch_rows();
                
$this->cache->store('photo_categories'$categories86400);
            }
        }
            
        return (
$categories) ? $categories : array();    
    }
    
    private function 
get_anonymous_id()
    {
        
$this->db->query("SELECT user_id FROM #__user WHERE username = 'anonymous' LIMIT 1");
        if (
$this->db->affected_rows()) {
            return (int) 
$this->db->fetch_field('user_id');
        }
        
        throw new 
VException('Failed to get anonymous id! Application error!?');
    }    
    
    private function 
get_files($unique)
    {
    }
}
Онлайн: 1
Реклама