Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/channel/components/add.php
Строк: 220
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_channel_add extends VModule_Admin_channel
{
    public function 
__construct()
    {
        
parent::__construct();
    }
    
    public function 
render()
    {
        
$errors     = array();
        
$messages     = array();
        
$warnings    = array();
        
$cmodel        VModel::load('channel''channel'true);
        
$channel    = array(
            
'username'        => '',
            
'user_id'        => 0,
            
'network_id'    => 0,
            
'name'            => '',
            
'slug'            => '',
            
'description'    => '',
            
'url'            => '',
            
'thumb'            => '',
            
'logo'            => '',
            
'adv_bottom_id'    => 0,
            
'adv_right_id'    => 0,
            
'adv_player_id'    => 0
        
);
        
        if (isset(
$_POST['submit-add-channel'])) {
            
$filter            VF::factory('filter');
            
$username        $filter->get('username');
            
$network_id        = (int) trim($_POST['network_id']);
            
$name            $filter->get('name');
            
$slug            $filter->get('slug');
            
$description    trim($_POST['description']);
            
$url            trim($_POST['url']);
            
$adv_bottom_id    = (int) trim($_POST['adv_bottom_id']);
            
$adv_right_id    = (int) trim($_POST['adv_right_id']);
            
$adv_player_id    = (int) trim($_POST['adv_player_id']);
            
            if (
$username == '') {
                
$errors[]    = 'Channel username field cannot be left blank!';
            } else {
                if (
$user_id VModel::load('user''user'true)->exists('username'$username)) {
                    
$channel['user_id']        = $user_id;
                    
$channel['username']    = $username;
                } else {
                    
$errors[]    = 'Invalid username!';
                }
            }
            
            if (
$network_id === 0) {
                
$errors[]    = 'Please select a network for your channel!';
            } else {
                
$channel['network_id']    = $network_id;
            }

            if (
$name == '') {
                
$errors[] = 'Channel name field cannot be left blank!';
            } elseif (!
VValid::length($name2100)) {
                
$errors[] = 'Channel name can contain maximum 100 characters!';
            } else {
                
$channel['name']    = $name;
            }
            
            if (
$slug == '') {
                
$errors[] = 'Channel SLUG field cannot be left blank!';
            } elseif (!
VValid::length($slug2100)) {
                
$errors[] = 'Channel SLUG can contain maximum 16 characters!';
            } elseif (!
VValid::slug($slug)) {
                
$errors[] = 'Channel SLUG can contain only lowercase letters, numbers and dashes!';
            } else {
                if (
$cmodel->exists('slug'$slug)) {
                    
$errors[]    = 'SLUG is already used for another channel!';
                } else {
                    
$channel['slug']    = $slug;
                }
            }
            
            if (
$url == '') {
                
$errors[]    = 'Channel URL field cannot be left blank!';
            } elseif (!
VValid::url($url)) {
                
$errors[]    = 'Channel URL is not a valid URL Address!';
            } else {
                
$channel['url']    = $url;
            }
            
            if (
$thumb VUpload::process('thumb'5, array('jpg''jpeg''png''gif''tiff'))) {
                
$image    VF::factory('image');
                if (
$image->load($thumb['path'])) {
                    
$thumb['ext']    = $image->src['ext'];
                } else {
                    
$errors[]    = 'Failed to load thumb image!';
                }
            } else {
                
$errors    array_merge($errorsVUpload::error());
            }
            
            if (isset(
$_FILES['logo']) && $_FILES['logo']['tmp_name'] != '') {
                if (
$logo VUpload::process('logo'5, array('jpg''jpeg''png''gif''tiff'))) {
                    
$image    VF::factory('image');
                    if (
$image->load($thumb['path'])) {
                        
$logo['ext']    = $image->src['ext'];
                    } else {
                        
$errors[]    = 'Failed to load thumb image!';
                    }
                } else {
                    
$errors    array_merge($errorsVUpload::error());
                }
            }
            
            if (
$adv_bottom_id === 0) {
                
$warnings[]    = 'You can select a advertising banner for the channel bottom position later!';
            } else {
                
$channel['adv_bottom_id'] = $adv_bottom_id;
            }

            if (
$adv_right_id === 0) {
                
$warnings[]    = 'You can select a advertising banner for the channel right position later!';
            } else {
                
$channel['adv_right_id'] = $adv_right_id;
            }

            if (
$adv_player_id === 0) {
                
$warnings[]    = 'You can select a advertising banner for the channel player position later!';
            } else {
                
$channel['adv_player_id'] = $adv_player_id;
            }
            
            
$channel['description']        = $description;

            if (!
$errors) {
                
$channel['thumb']    = $thumb['ext'];
                
$channel['logo']    = (isset($logo)) ? $logo['ext'] : '';
            
                if (
$channel_id $cmodel->add($channel)) {
                    if (
$thumb) {
                        
$dst    MEDIA_DIR.'/channels/'.$channel_id.'.thumb.'.$thumb['ext'];
                        if (!
move_uploaded_file($thumb['path'], $dst)) {
                            
$errors[] = 'Failed to move uploaded thumb file!';
                        }
                    }

                    if (isset(
$logo) && $logo) {
                        
$dst    MEDIA_DIR.'/channels/'.$channel_id.'.logo.'.$logo['ext'];
                        if (!
move_uploaded_file($logo['path'], $dst)) {
                            
$errors[] = 'Failed to move uploaded logo file!';
                        }
                    }
                
                    if (!
$errors) {
                        
$_SESSION['message'] = 'Channel added! Please crop channel thumb below!';
                        
VF::redirect(ADMIN_URL.'/index.php?q=channel/edit&id='.$channel_id);
                    }
                } else {
                    
$errors[]    = 'Failed to create channel!';
                }            
            }
        }
        
        
$gmodel            VModel::load('group''adv'true);
        
$amodel            VModel::load('adv''adv'true);
        if (
$bottom_group_id $gmodel->exists('adv_group_slug''channel-bottom')) {
            
$advs_bottom    $amodel->advs(array('where' => "a.adv_group_id = ".$bottom_group_id." AND a.status = '1'"));
        }
        
        if (
$right_group_id $gmodel->exists('adv_group_slug''channel-right')) {
            
$advs_right        $amodel->advs(array('where' => "a.adv_group_id = ".$right_group_id." AND a.status = '1'"));
        }

        if (
$player_group_id    $gmodel->exists('adv_group_slug''video-player')) {
            
$advs_player    $amodel->advs(array('where' => "a.adv_group_id = ".$player_group_id." AND a.status = '1'"));
        }
        
        
$tpl                 VF::factory('template');
        
$tpl->menu            'channel';
        
$tpl->submenu        'channel_add';
        
$tpl->meta_title    'Admin::Channel::Add';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->warnings        $warnings;
        
$tpl->channel        $channel;
        
$tpl->networks        VModel::load('network''channel'true)->networks(array(), array('sort' => 'n.name''order' => 'ASC'), 10000);
        
$tpl->advs_bottom    = (isset($advs_bottom)) ? $advs_bottom : array();
        
$tpl->advs_right    = (isset($advs_right)) ? $advs_right : array();
        
$tpl->advs_player    = (isset($advs_player)) ? $advs_player : array();
        
$tpl->load(array('header''channel_add''footer'));
        
$tpl->display();
    }
}
?>
Онлайн: 0
Реклама