Файл: adultscript-2.0.3-pro/files/admin/modules/news/components/edit.php
Строк: 67
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_admin_news_edit
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$errors = array();
$messages = array();
$article = array();
$news_id = (isset($_GET['id'])) ? (int) $_GET['id'] : NULL;
$db->query("SELECT news_id FROM #__news WHERE news_id = ".$news_id." LIMIT 1");
if ($db->affected_rows()) {
if (isset($_POST['submit_news_edit'])) {
$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!';
}
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)."' AND news_id != ".$news_id." LIMIT 1");
if ($db->affected_rows()) {
$errors[] = 'News SLUG is already used by another article!';
}
}
if ($content == '') {
$errors[] = 'News content field cannot be left blank!';
}
if (!$errors) {
$user_id = (int) $_SESSION['user_id'];
$db->query("UPDATE #__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."'
WHERE news_id = ".$news_id."
LIMIT 1");
$messages[] = 'Article updated!';
}
}
$db->query("SELECT * FROM #__news WHERE news_id = ".$news_id." LIMIT 1");
$article = $db->fetch_assoc();
}
$tpl = VF::factory('template');
$tpl->meta_title = 'Admin::News:Edit';
$tpl->menu = 'main';
$tpl->submenu = 'news';
$tpl->extramenu = 'news_add';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->article = $article;
$tpl->load(array('header', 'news_edit', 'footer'));
$tpl->display();
}
}