Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/video/components/category_add.php
Строк: 71
<?php
defined
('_VALID') or die('Restricted Access!');

define('IMG_WIDTH'175);
define('IMG_HEIGHT'215);

class 
VComponent_Admin_video_category_add
{
    public function 
__construct()
    {
    }
    
    public function 
render()
    {
        
$errors        = array();
        
$messages    = array();
        
$db            VF::factory('database');
        
$cat        = array('parent_id' => 0'name' => '''slug' => '',
                            
'description' => '''status' => '1''title' => '',
                            
'meta_title' => '''meta_desc' => '''meta_keys' => '',
                            
'auto_term' => '');
        if (isset(
$_POST['submit_add_category'])) {
            
$filter            VF::factory('filter');
            
$parent_id        = (int) trim($_POST['parent_id']);
            
$name            $filter->get('name');
            
$slug            $filter->get('slug');
            
$description    trim($_POST['description']);
            
$auto_term        $filter->get('auto_term');
            
$status            $filter->get('status''INT');
            
            
// we do not escape these for XSS
            
$title            trim($_POST['title']);
            
            
$meta_title        $filter->get('meta_title');
            
$meta_desc        $filter->get('meta_desc');
            
$meta_keys        $filter->get('meta_keys');
        
            if (
$name == '') {
                
$errors[]    = 'Category name field cannot be left blank!';
            } elseif (!
VValid::length($name1100)) {
                
$errors[]    = 'Category name cat contain maximum 100 characters!';
            } else {
                
$cat['name']    = $name;
            }
            
            if (
$slug == '') {
                
$errors[]     = 'Category slug field cannot be left blank!';
            } elseif (!
VValid::length($slug1100)) {
                
$errors[]    = 'Category slug can contain maximum 100 characters!';
            } elseif (!
VValid::slug($slug)) {
                
$errors[]    = 'Category slug can contain only lower case letters, numbers and dashes!';
            } else {
                
$db->query("SELECT cat_id FROM #__video_categories WHERE slug = '".$db->escape($slug)."' LIMIT 1");
                if (
$db->affected_rows()) {
                    
$errors[]    = 'Category slug is already used for another category!';
                } else {
                    
$cat['slug']    = $slug;
                }
            }
            
            if (
$description != '') {
                
$cat['description'] = $description;
            }
            
            if (isset(
$_FILES['image']['tmp_name'])) {
                if (!
$file VUpload::process('image'2, array('jpg''jpeg''png''gif'))) {
                    
$errors array_merge($errorsVUpload::error());
                }
            } else {
                
$errors[]    = 'Please upload a category image!';
            }
            
            
$cat['status']         = $status;
            
$cat['parent_id']    = $parent_id;
            
$cat['title']        = $title;
            
$cat['meta_title']    = $meta_title;
            
$cat['meta_desc']    = $meta_desc;
            
$cat['meta_keys']    = $meta_keys;
        
            if (!
$errors) {
                
$db->query("INSERT INTO #__video_categories
                              SET parent_id = "
.$parent_id.",
                                  name = '"
.$db->escape($name)."',
                                  description = '"
.$db->escape($description)."',
                                slug = '"
.$db->escape($slug)."',
                                auto_term = '"
.$db->escape($auto_term)."',
                                title = '"
.$db->escape($title)."',
                                meta_title = '"
.$db->escape($meta_title)."',
                                meta_desc = '"
.$db->escape($meta_desc)."',
                                meta_keys = '"
.$db->escape($meta_keys)."',
                                status = '"
.$status."'");
                if (
$db->affected_rows()) {
                    
$cat_id $db->get_last_insert_id('#__video_categories');
                    
$image  VF::factory('image');
                    
$dst    MEDIA_DIR.'/videos/cat/'.$cat_id.'.jpg';
                    if (
$image->load($file['path']) &&
                        
$image->resize(IMG_WIDTHIMG_HEIGHT'EXACT'$dst)) {
                        
$messages[] = 'Category added!';
                    } else {
                        
$errors[] = 'Failed to add category image! Aborting...';
                    }
                } else {
                    
$errors[] = 'Failed to add category! Application Error!?';
                }
            }
        }
        
        
$db->query("SELECT cat_id, name
                    FROM #__video_categories
                    WHERE parent_id = 0
                    ORDER BY slug ASC"
);
        
$categories $db->fetch_rows();
        
        
$tpl    = &VF::factory('template');
        
$tpl->menu            'video';
        
$tpl->submenu        'video_category_add';
        
$tpl->meta_title    'Admin::Video::Category::Add';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->cat            $cat;
        
$tpl->categories    $categories;
        
$tpl->load(array('header''video_category_add''footer'));
        
$tpl->display();
    }
}
?>
Онлайн: 0
Реклама