Файл: adultscript-2.0.3-pro/files/admin/modules/news/components/add.php
Строк: 61
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_admin_news_add
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$errors = array();
$messages = array();
$article = array(
'title' => '', 'slug' => '', 'content' => '', 'status' => 1,
'meta_title' => '', 'meta_desc' => '', 'meta_keys' => ''
);
if (isset($_POST['submit_news_add'])) {
$filter = VF::factory('filter');
$title = $filter->get('title');
$slug = $filter->get('slug');
$content = trim($_POST['content']);
$status = (int) trim($_POST['status']);
$meta_title = $filter->get('meta_title');
$meta_desc = trim($_POST['meta_desc']);
$meta_keys = $filter->get('meta_keys');
if ($title == '') {
$errors[] = 'News title field cannot be left blank!';
} else {
$article['title'] = $title;
}
if ($slug == '') {
$errors[] = 'News SLUG field cannot be left blank!';
} elseif (!VValid::aldash($slug)) {
$errors[] = 'News SLUG field can contain only letters, numbers and dashes!';
} else {
$db->query("SELECT news_id FROM #__news WHERE slug = '".$db->escape($slug)."' LIMIT 1");
if ($db->affected_rows()) {
$errors[] = 'News SLUG is already used by another article!';
} else {
$article['slug'] = $slug;
}
}
if ($content == '') {
$errors[] = 'News content field cannot be left blank!';
} else {
$article['content'] = $content;
}
$article['status'] = $status;
$article['meta_title'] = $meta_title;
$article['meta_desc'] = $meta_desc;
$article['meta_keys'] = $meta_keys;
if (!$errors) {
$user_id = (int) $_SESSION['user_id'];
$db->query("INSERT INTO #__news
SET user_id = ".$user_id.",
title = '".$db->escape($title)."',
slug = '".$db->escape($slug)."',
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[] = 'Article added!';
} else {
$errors[] = 'Failed to add article! Application error!?';
}
}
}
$tpl = VF::factory('template');
$tpl->meta_title = 'Admin::News:Add';
$tpl->menu = 'main';
$tpl->submenu = 'news';
$tpl->extramenu = 'news_add';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->article = $article;
$tpl->load(array('header', 'news_add', 'footer'));
$tpl->display();
}
}