Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/menu/components/link_add.php
Строк: 135
<?php
defined
('_VALID') or die('Restricted Acces!');
class 
VComponent_Admin_menu_link_add
{
    public function 
__construct()
    {
    }
    
    public function 
render()
    {
        
$db = VF::factory('database');
    
        
$errors     = array();
        
$messages    = array();
        
$menus        = $db->get_rows("SELECT menu_id, name, title FROM #__menu ORDER BY menu_id ASC");
        
$item         = array('menu_id' => '', 'name' => '', 'title' => '', 'link' => '', 'lang' => '',
                            
'type' => 'internal', 'target' => 'none', 'status' => '1', 'current' => '');
        if (isset(
$_POST['submit_add_link'])) {
            
$filter       = VF::factory('filter');
            
$menu_id      = $filter->get('menu_id', 'INTEGER');
            
$name          = $filter->get('name');
            
$title          = $filter->get('title');
            
$link          = trim($_POST['link']);
            
$type          = $filter->get('type');
            
$target          = $filter->get('target');
            
$lang         = $filter->get('lang');
            
$current      = $filter->get('current');
            
$status          = $filter->get('status', 'INTEGER');
            
            if (
$menu_id === 0) {
                
$errors[] = 'Please select a menu for your link!';
            } else {
                
$item['menu_id'] = $menu_id;
            }
            
            if (
$name == '') {
                
$errors[] = 'Please enter the link name!';
            } elseif (!
VValid::length($name, 1, 99)) {
                
$errors[] = 'Links name can contain maximum 99 characters!';
            } else {
                
$item['name'] = $name;
            }
            
            if (
$title != '') {
                if (!
VValid::length($title, 1, 254)) {
                    
$errors[] = 'Link title can contain maximum 255 characters!';
                } else {
                    
$item['title'] = $title;
                }
            }
            
            if (
$link == '') {
                
$errors[]    = 'Please enter the link url!';
            } elseif (!
VValid::length($link, 1, 255)) {
                
$errors[]    = 'Link url can contain maximum 255 characters!';
            } else {
                if (
$type == 'ext' && !VValid::url($link)) {
                    
$errors[] = 'Link url is not a valid url address!';
                } else {
                    
$item['link'] = $link;
                }
            }
            
            
$item['type']   = ($type == 'int') ? 'int' : 'ext';
            if (!
in_array($target, array('none', 'self', 'blank'))) {
                
$errors[] = 'Invalid link target specified! What exactly did you select!?';
            } else {
                
$item['target'] = $target;
            }
            
            if (
$current != '') {
                if (!
VValid::length($current, 0, 99)) {
                    
$errors[] = 'Current identifier can contain maximum 99 characters!';
                } else {
                    
$item['current'] = $current;
                }
            }
            
            
$item['lang']         = $lang;
            
            if (!
$errors) {
                
$db->query("SELECT pos FROM #__menu_links WHERE menu_id = ".$menu_id." ORDER BY pos DESC LIMIT 1");
                if (
$db->affected_rows()) {
                    
$pos = $db->fetch_field('pos')+1;
                } else {
                    
$pos = 1;
                }
                
                
$db->query("INSERT INTO #__menu_links
                            SET menu_id = "
.$menu_id.",
                                name = '"
.$db->escape($name)."',
                                title = '"
.$db->escape($title)."',
                                link = '"
.$db->escape($link)."',
                                type = '"
.$db->escape($type)."',
                                target = '"
.$db->escape($target)."',
                                lang = '"
.$db->escape($lang)."',
                                current = '"
.$db->escape($current)."',
                                pos = "
.$pos.",
                                status = '"
.$status."'");
                if (
$db->affected_rows()) {
                    foreach (
$menus as $menu) {
                        if (
$menu['menu_id'] == $menu_id) {
                            
VF::factory('cache')->remove($menu['name'].'_links');
                            break;
                        }
                    }
                    
                    
$messages[]    = 'Menu link added!';
                } else {
                    
$errors[] = 'Failed to add menu link!';
                }
            }
        }
    
        
$tpl = &VF::factory('template');
        
$tpl->menu            = 'main';
        
$tpl->submenu        = 'menu_link_add';
        
$tpl->errors        = $errors;
        
$tpl->messages        = $messages;
        
$tpl->meta_title    = 'Admin::Menu::Link::Add';
        
$tpl->menus            = $menus;
        
$tpl->item            = $item;
        
$tpl->load(array('header', 'menu_link_add', 'footer'));
        
$tpl->display();
    }
}
?>
Онлайн: 2
Реклама