Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/adv/components/player_add.php
Строк: 174
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_adv_player_add
{
    public function 
__construct()
    {
    }
    
    public function 
render()
    {
        
$errors        = array();
        
$messages    = array();
        
$adv        = array(
            
'adv_name' => '''adv_desc' => '''type' => 'image''status' => 1'expire' => '',
            
'title' => '''description' => '''url' => '''code' => '',
            
'image_type' => 'file''image_url' => '',
            
'video_type' => 'file''video_url' => '',
            
'cuepoint' => 3'position' => 5'duration' => 10
        
);
        
        if (isset(
$_POST['submit_adv_add'])) {
            
$filter            VF::factory('filter');
            
$name            $filter->get('adv_name');
            
$desc            $filter->get('adv_desc');
            
$type            $filter->get('type');
            
$expire            $filter->get('expire');
            
$status            = (int) trim($_POST['status']);
            
$url            trim($_POST['url']);
            
            if (
$name == '') {
                
$errors[]    = 'Advertising name field cannot be left blank!';
            } else {
                
$adv['adv_name']    = $name;
            }
            
            if (
$desc != '') {
                
$adv['adv_desc']    = $desc;
            }
            
            if (
$expire != '' && $expire != '0000-00-00') {
                if (
strlen($expire) !== 10) {
                    
$errors[]   = 'Advertising expire date invalid! Please use: yyyy-mm-dd!';
                } elseif (
$expire_timestamp strtotime($expire) === FALSE) {
                    
$errors[]   = 'Advertising expire date invalid! Please use: yyyy-mm-dd!';
                } else {
                    
$current_timestamp  time();
                    if (
$current_timestamp $expire_timestamp) {
                        
$errors[] = 'Advertising expire time is in the past!';
                    } else {
                        
$adv['expire'] = $expire;
                    }
                }
            } else {
                
$adv['expire'] = '0000-00-00';
            }
            
            if (
$url == '') {
                  
$errors[]        = 'Advertising URL field cannot be left blank!';
            } elseif (!
VValid::url($url)) {
                  
$errors[]        = 'Advertising URL is not a valid URL address!';
            } else {
                  
$adv['url']     = $url;
            }
            
            if (
$type == 'text' OR $type == 'image') {
                
$cuepoint        = (int) trim($_POST['cuepoint']);

                  if (
$cuepoint === 0) {
                      
$errors[]    = 'Cuepoint field must be a positive integer (seconds)!';
                  } else {
                      
$adv['cuepoint'] = $cuepoint;
                  }
              }            
            
            if (
$type == 'text') {
                  
$title            $filter->get('title');
                  
$description    $filter->get('description');
                  
$cuepoint        = (int) trim($_POST['cuepoint']);
                  
                  if (
$title == '') {
                      
$errors[]    = 'Advertising title field cannot be left blank!';
                  } else {
                      
$adv['title'] = $title;
                  }
                  
                  if (
$description == '') {
                      
$errors[]     = 'Advertising description field cannot be left blank!';
                  } else {
                      
$adv['description'] = $description;
                  }                  
            } elseif (
$type == 'image') {
                  
$image_type        $filter->get('image_type');

                  if (
$image_type == 'url') {
                      
$image_url      trim($_POST['image_url']);
                    if (
$image_url == '') {
                          
$errors[]       = 'Image banner url cannot be left blank!';
                    } elseif (!
VValid::url($image_url)) {
                          
$errors[]       = 'Image banner url is not a valid url address!';
                    } else {
                        
$adv['image_url'] = $image_url;
                    }
                } elseif (
$image_type == 'file') {
                      if (
$_FILES['image_file']['tmp_name'] != '') {
                          if (
is_uploaded_file($_FILES['image_file']['tmp_name'])) {
                              
$file           $_FILES['image_file']['tmp_name'];
                            
$filename       $_FILES['image_file']['name'];
                            
$ext            VFile::ext($filename);

                            
$valid          false;
                            if (
$ext == 'gif') {
                                  
$valid  imagecreatefromgif($file);
                            } elseif (
$ext == 'png') {
                                
$valid  imagecreatefrompng($file);
                            } elseif (
$ext == 'jpeg' OR $ext == 'jpg') {
                                
$valid  imagecreatefromjpeg($file);
                            } else {
                                  
$errors[]       = 'Invalid image banner file! Format not supported! Supported formats: jpg, png and gif!';
                            }

                            if (!
$valid) {
                                  
$errors[]       = 'Invalid image banner file! File is not a valid image (renders incorrectly)!';
                            }
                        } else {
                            
$errors[] = 'Image banner file is not a valid uploaded file!';
                        }
                    } else {
                        
$errors[] = 'Please upload a image banner file!';
                    }
                } else {
                      
$errors[] = 'Invalid image banner type selected! What exactly did you select!?';
                }    
            } elseif (
$type == 'video') {
                  
$duration        = (int) trim($_POST['duration']);
                  
$position        = (int) trim($_POST['position']);
                  
$video_type        $filter->get('video_type');
                  
                  if (
$duration === 0) {
                      
$errors[]     = 'Media advertising duration cannot be 0 (positive integer required)!';
                  } else {
                      
$adv['duration'] = $duration;
                  }
                  
                  if (
$position < -1) {
                      
$errors[] = 'Media advertising can be 0 (before the main video), positive integer (seconds after) and -1 (at the end of the main video)!';
                  } else {
                      
$adv['position'] = $position;
                  }
                  
                  if (
$video_type == 'url') {
                      
$video_url      trim($_POST['video_url']);
                    if (
$video_url == '') {
                          
$errors[]       = 'Media url cannot be left blank!';
                    } elseif (!
VValid::url($video_url)) {
                          
$errors[]       = 'Media url is not a valid url address!';
                    } else {
                        
$adv['video_url'] = $video_url;
                    }
                  } elseif (
$video_type == 'file') {
                      if (
$_FILES['video_file']['tmp_name'] != '') {
                          if (
is_uploaded_file($_FILES['video_file']['tmp_name'])) {
                              
$file           $_FILES['video_file']['tmp_name'];
                            
$filename       $_FILES['video_file']['name'];
                            
$ext            VFile::ext($filename);

                            
$valid          false;
                            if (
$ext == 'gif') {
                                  
$valid  imagecreatefromgif($file);
                            } elseif (
$ext == 'png') {
                                
$valid  imagecreatefrompng($file);
                            } elseif (
$ext == 'jpeg' OR $ext == 'jpg') {
                                
$valid  imagecreatefromjpeg($file);
                            } elseif (
$ext == 'flv' OR $ext == 'mp4') {
                                  
$valid    TRUE;
                              } elseif (
$ext == 'swf') {
                                  
$value     TRUE;
                            } else {
                                  
$errors[]       = 'Invalid media file! Format not supported! Supported formats: flv, mp4, swf, jpg, png and gif!';
                            }

                            if (!
$valid) {
                                  
$errors[]       = 'Invalid media file! File is not a valid media (renders incorrectly)!';
                            }
                        } else {
                            
$errors[] = 'Image media file is not a valid uploaded file!';
                        }
                    } else {
                        
$errors[] = 'Please upload a media file!';
                    }
                  } else {
                      
$errors[]    = 'Invalid media advertising type! What exactly did you select!?';
                  }
            } else {
                  
$errors[]    = 'Invalid advertising type! What exactly did you select!?';
            }
            
            
$adv['type']        = $type;
            
$adv['status']        = $status;
            
$adv['image_type']    = (isset($image_type)) ? $image_type 'url';
            
$adv['video_type']    = (isset($video_type)) ? $video_type 'url';
            
            if (!
$errors) {
                
$ext        = (isset($ext)) ? $ext '';
                
$media_type    = (isset($image_url) OR isset($video_url)) ? 'url' 'file';
                
$media_url    = (isset($image_url)) ? $image_url '';
                if (isset(
$video_url)) {
                    
$media_url    $video_url;
                }
            
                
$db    VF::factory('database');
                
$db->query("INSERT INTO #__adv_player
                            SET adv_name = '"
.$db->escape($name)."',
                                adv_desc = '"
.$db->escape($desc)."',
                                type = '"
.$db->escape($type)."',
                                title = '"
.$db->escape($adv['title'])."',
                                description = '"
.$db->escape($adv['description'])."',
                                url = '"
.$db->escape($url)."',
                                cuepoint = "
.$adv['cuepoint'].",
                                media_type     = '"
.$db->escape($media_type)."',
                                media_url    = '"
.$db->escape($media_url)."',
                                media_ext    = '"
.$db->escape($ext)."',
                                duration = "
.$adv['duration'].",
                                position = "
.$adv['position'].",
                                expire = '"
.$db->escape($expire)."',
                                status = '"
.$status."'");
                if (
$db->affected_rows()) {
                    
$adv_id    $db->get_last_insert_id('#__adv_player');
                    if (isset(
$file)) {
                        if (!
move_uploaded_file($fileMEDIA_DIR.'/player/'.$adv_id.'.'.$ext)) {
                            
$errors[] = 'Failed to move uploaded file! Invalid permissions!?';
                        }
                    }
                } else {
                    
$errors[] = 'Failed to add database entry! Application error!?';
                }
                
                if (!
$errors) {
                    
$messages[] = 'Player advertising added!';
                }
            }
        }
    
        
$tpl    VF::factory('template');
        
$tpl->menu            'adv';
        
$tpl->submenu        'player';
        
$tpl->extramenu        'player_add';
        
$tpl->meta_title    'Advertising::Player::Add';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->adv            $adv;
        
$tpl->load(array('header''adv_player_add''footer'));
        
$tpl->display();
    }
}
Онлайн: 1
Реклама