Вход Регистрация
Файл: adultscript-2.0.3-pro/files/mobile/components/video_edit.php
Строк: 92
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_mobile_video_edit extends VComponent_mobile_video
{
    public function 
__construct()
    {
        
parent::__construct();
    }
    
    public function 
render()
    {
        
VAuth::check('Registered'MOBILE_URL.'/user/login/');
    
        
$video_id    = (int) VUri::request(1);
        
$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
                          AND v.mobile = '1'
                          GROUP BY v.video_id
                          LIMIT 1"
);
        if (!
$this->db->affected_rows()) {
            
$this->notfound(__('video-invalid'));
        }
        
        
$data           $this->db->fetch_assoc();
        
$locked         = (bool) $data['locked'];
        
$ocategories    = ($data['category']) ? explode(','$data['category']) : array();
        
sort($ocategories);
        
$opornstars     = ($data['pornstars']) ? explode(','$data['pornstars']) : array();
        
sort($opornstars);
        
$errors         = array();
        
$messages       = array();
        
$categories     $this->get_video_categories();

        if (isset(
$_POST['submit_edit_video']) && !$locked) {
              echo 
VF::debug($_POST);
        
            
$filter         VF::factory('filter');
            
$title          $filter->get('title');
            
$description    $filter->get('description');
            
$category       = (isset($_POST['category'])) ? (array) $_POST['category'] : array();
            
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($titleTRUEVF::cfg_item('module.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);
                    
                    if (
$ocategories) {
                          foreach (
$ocategories as $index => $cat_id) {
                              
$this->db->query("UPDATE #__video_categories
                                                SET total_videos = total_videos-1
                                                WHERE cat_id = "
.$cat_id."
                                                LIMIT 1"
);
                          }
                    }
                    
                    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 = "
.$cat_id."
                                              LIMIT 1"
);
                    }
                }
               
                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 {
            
$this->notfound(__('video-invalid'));
        }        

        
$this->tpl->menu        'video';
        
$this->tpl->title        __('edit-video-title');
        
$this->tpl->meta_title    __('edit-video-meta-title');
        
$this->tpl->errors      $errors;
        
$this->tpl->messages    $messages;        
        
$this->tpl->video        $video;
        
$this->tpl->models        $models;
        
$this->tpl->pornstars    $this->get_pornstars('a');
        
$this->tpl->categories    $categories;
        
$this->tpl->load(array('header''video_edit''footer'));
        
$this->tpl->display();
    }
    
    private function 
get_video_categories()
    {
        if (!
$categories $this->cache->get('categories'86400)) {
            
$this->db->query("SELECT cat_id, parent_id, name, slug, description, total_videos,
                                     title, meta_title, meta_desc, meta_keys
                              FROM #__video_categories
                              WHERE status = '1'
                              ORDER BY slug, parent_id ASC"
);
            if (
$this->db->affected_rows()) {
                
$categories $this->db->fetch_rows();
                
$this->cache->store('categories'$categories86400);
            }
        }

        return 
$categories;
    }

    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
Реклама