Файл: adultscript-2.0.3-pro/files/admin/modules/content/components/add.php
Строк: 108
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_content_add
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$cfg = VF::cfg('core.config');
$page = array(
'name' => '', 'status' => '1', 'meta_title' => '',
'meta_desc' => '', 'meta_keys' => '', 'title' => '', 'content' => ''
);
$errors = array();
$messages = array();
if (isset($_POST['submit_content_add'])) {
$filter = &VF::factory('filter');
$name = $filter->get('name');
$status = $filter->get('status', 'INT');
$meta_title = $filter->get('meta_title');
$meta_desc = $filter->get('meta_desc');
$meta_keys = $filter->get('meta_keys');
$title = trim($_POST['title']);
$content = trim($_POST['content']);
if ($name == '') {
$errors[] = 'Please enter content name (identifier)!';
} elseif (!VValid::length($name, 1, 100)) {
$errors[] = 'Content name can contain maximum 100 characters!';
} elseif (!VValid::aldash($name)) {
$errors[] = 'Content name can contain only letters, dashes and underscores!';
} else {
$page['name'] = $name;
}
if ($meta_title != '') {
if (!VValid::length($meta_title, 1, 255)) {
$errors[] = 'Content meta title can contain maximum 255 characters!';
} else {
$page['meta_title'] = $meta_title;
}
}
if ($meta_desc != '') {
if (!VValid::length($meta_desc, 1, 255)) {
$errors[] = 'Content meta description can contain maximum 255 characters!';
} else {
$page['meta_desc'] = $meta_desc;
}
}
if ($meta_keys != '') {
if (!VValid::length($meta_keys, 1, 255)) {
$errors[] = 'Content meta keywords can contain maximum 255 characters!';
} else {
$page['meta_keys'] = $meta_keys;
}
}
if ($title == '') {
$errors[] = 'Please enter the content title!';
} elseif (!VValid::length($title, 1, 255)) {
$errors[] = 'Content title can contain maximum 255 characters!';
} else {
$page['title'] = $title;
}
if ($content == '') {
$errors[] = 'Please write a content for this page!';
} else {
$page['content'] = $content;
}
if (!$errors) {
$db->query("INSERT INTO #__static
SET user_id = ".(int) $_SESSION['user_id'].",
name = '".$db->escape($name)."',
title = '".$db->escape($title)."',
content = '".$db->escape($content)."',
meta_title = '".$db->escape($meta_title)."',
meta_desc = '".$db->escape($meta_desc)."',
meta_keys = '".$db->escape($meta_keys)."',
add_date = '".date('Y-m-d h:i:s')."',
status = '".$status."'");
if ($db->affected_rows()) {
$messages[] = 'Content page added!';
} else {
$errors[] = 'Failed to add content page!';
}
}
}
$tpl = &VF::factory('template');
$tpl->menu = 'main';
$tpl->submenu = 'content_add';
$tpl->meta_title = 'Admin::Content::Add';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->page = $page;
$tpl->load(array('header', 'content_add', 'footer'));
$tpl->display();
}
}
?>