Вход Регистрация
Файл: adultscript-2.0.3-pro/files/modules/video/components/edit.php
Строк: 81
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_video_edit extends VModule_video
{
    public function 
__construct()
    {
        
parent::__construct();
    }
    
    public function 
render()
    {
        
VAuth::check('Registered');
        
VLanguage::load('frontend.video');
    
        
$video_id     = (VUri::request(1)) ? (int) VUri::request(1) : 0;
        
$user_id    = (int) $_SESSION['user_id'];
        
$this->db->query("SELECT v.locked, GROUP_CONCAT(DISTINCT c.cat_id) AS category,
                                 GROUP_CONCAT(DISTINCT m.model_id) AS pornstars
                          FROM #__video AS v
                          LEFT JOIN #__video_category AS c ON (c.video_id = v.video_id)
                          LEFT JOIN #__model_videos AS m ON (m.video_id = v.video_id)
                          WHERE v.video_id = "
.$video_id."
                          AND v.user_id = "
.$user_id."
                          AND v.status = 1
                          GROUP BY v.video_id
                          LIMIT 1"
);
        if (!
$this->db->affected_rows()) {
            
$_SESSION['error'] = __('video-invalid');
            
VModule::load('error'true);
        }

        
$data           $this->db->fetch_assoc();
        
$locked         = (bool) $data['locked'];
        
$ocategories    explode(','$data['category']);
        
sort($ocategories);
        
$opornstars     explode(','$data['pornstars']);
        
sort($opornstars);        
        
$errors            = array();
        
$messages        = array();
        
$categories        $this->get_video_categories();

        if (isset(
$_POST['submit_edit_video']) && !$locked) {
            
$filter            VF::factory('filter');
            
$title            $filter->get('title');
            
$description    $filter->get('description');
            
$category        = (array) $_POST['category'];
            
sort($category);
            
$tags            $filter->get('tags');
            
$type            $filter->get('type');
            
$allow_embed    = (int) trim($_POST['allow_embed']);
            
$allow_rating    = (int) trim($_POST['allow_rating']);
            
$allow_comment    = (int) trim($_POST['allow_comment']);
            
$allow_download    = (isset($_POST['allow_download'])) ? (int) trim($_POST['allow_download']) : 0;
            
$thumb            = (int) trim($_POST['thumb']);
            
$pornstars        = (isset($_POST['pornstars'])) ? (array) $_POST['pornstars'] : array();
            
sort($pornstars);
            
            if (
$title == '') {
                
$errors[] = __('title-empty');
            } elseif (!
VValid::length($title1100)) {
                
$errors[] = __('title-length');
            }
            
            if (!
$category) {
                  
$errors[] = __('category-empty');
            } 

            if (
$tags == '') {
                
$errors[] = __('tags-empty');
            } else {
                
$tags prepare_tags($tags);
                if (
$tags == '') {
                    
$errors[] = __('tags-invalid');
                }
            }
            
            if (!
$errors) {
                  
$slug prepare_string($titletrueVCfg::get('video.slug_max_length'));
                  
$this->db->query("UPDATE #__video
                                    SET title = '"
.$this->db->escape($title)."',
                                        slug = '"
.$this->db->escape($slug)."',
                                        description = '"
.$this->db->escape($description)."',
                                        type = '"
.$this->db->escape($type)."',
                                        allow_embed = '"
.$allow_embed."',
                                        allow_rating = '"
.$allow_rating."',
                                        allow_comment = '"
.$allow_comment."',
                                        allow_download = '"
.$allow_download."',
                                        thumb = "
.$thumb."
                                    WHERE video_id = "
.$video_id."
                                    AND user_id = "
.$user_id."
                                    AND status = 1
                                    LIMIT 1"
);
                  
                  
$this->db->query("DELETE FROM #__video_tags WHERE video_id = ".$video_id);
                  
$tags explode(','$tags);
                  foreach (
$tags as $tag) {
                      
$this->db->query("INSERT INTO #__video_tags
                                        SET video_id = "
.$video_id.",
                                            name = '"
.$this->db->escape(trim($tag))."'");
                  }
                  
                  if (
$category != $ocategories) {
                      
$this->db->query("DELETE FROM #__video_category WHERE video_id = ".$video_id);
                      
$this->db->query("UPDATE #__video_categories
                                        SET total_videos = total_videos-1
                                        WHERE cat_id IN ("
.implode(','array_values($ocategories)).")");
                      foreach (
$category as $cat_id) {
                          
$this->db->query("INSERT INTO #__video_category
                                            SET video_id = "
.$video_id.",
                                                cat_id = "
.$cat_id);
                      }
                      
$this->db->query("UPDATE #__video_categories
                                        SET total_videos = total_videos+1
                                        WHERE cat_id IN ("
.implode(','array_values($category)).")");
                  }
                  
                  if (
$pornstars != $opornstars) {
                      foreach (
$opornstars as $model_id) {
                          
$model_id = (int) $model_id;
                          
$this->db->query("DELETE FROM #__model_videos WHERE model_id = ".$model_id." AND video_id = ".$video_id." LIMIT 1");
                          
$this->db->query("UPDATE #__model SET total_videos = total_videos-1 WHERE model_id = ".$model_id." LIMIT 1");
                      }

                      foreach (
$pornstars as $model_id) {
                          
$model_id = (int) $model_id;
                          
$this->db->query("INSERT INTO #__model_videos SET model_id = ".$model_id.", video_id = ".$video_id);
                          
$this->db->query("UPDATE #__model SET total_videos = total_videos+1 WHERE model_id = ".$model_id." LIMIT 1");
                      }
                  }
                  
                  
$messages[] = __('edit-success');
            }
        }
        
        
$this->db->query('SELECT v.video_id, v.title, v.description, v.thumb, v.thumbs, v.allow_embed,
                                 v.allow_rating, v.allow_comment, v.allow_download, v.embed_code, v.type,
                                 GROUP_CONCAT(DISTINCT c.cat_id) AS category,
                                 GROUP_CONCAT(DISTINCT t.name) AS tags
                          FROM #__video AS v
                          LEFT JOIN #__video_category AS vc ON (vc.video_id = v.video_id)
                          LEFT JOIN #__video_categories AS c ON (vc.cat_id = c.cat_id)
                          LEFT JOIN #__video_tags AS t ON (t.video_id = v.video_id)
                          WHERE v.video_id = '
.$video_id.'
                          AND v.user_id = '
.$user_id.'
                          AND v.status = 1
                          LIMIT 1'
);
        if (
$this->db->affected_rows()) {
            
$video     $this->db->fetch_assoc();
            
$models    = array();
            if (
VModule::enabled('pornstar')) {
                
$this->db->query("SELECT mv.model_id, m.name
                                  FROM #__model_videos AS mv
                                  INNER JOIN #__model AS m ON (m.model_id = mv.model_id AND m.status = '1')
                                  WHERE mv.video_id = "
.$video_id."
                                  ORDER BY m.name ASC"
);
                if (
$this->db->affected_rows()) {
                    
$models $this->db->fetch_rows();
                }                  
            }
        } else {
            
$_SESSION['error'] = 'Invalid video! Are you sure this video exists!';
            
VModule::load('error'true);
        }
        
        
$this->tpl->menu        'video';
        
$this->tpl->meta_title    __('edit-title');
        
$this->tpl->errors        $errors;
        
$this->tpl->messages    $messages;
        
$this->tpl->pornstars    = (VModule::enabled('pornstar')) ? $this->get_pornstars('a') : NULL;
        
$this->tpl->video        $video;
        
$this->tpl->models        $models;
        
$this->tpl->categories    $categories;
        
$this->tpl->load(array('header''video_edit''footer'));
        
$this->tpl->display();
    }
    
    private function 
get_pornstars($letter='a')
    {
        
$this->db->query("SELECT model_id, name
                          FROM #__model
                          WHERE slug LIKE '"
.$letter."%'
                          AND status = '1'"
);

        return 
$this->db->fetch_rows();
    }    
}
Онлайн: 1
Реклама