Файл: adultscript-2.0.3-pro/files/admin/modules/content/components/edit.php
Строк: 113
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_content_edit
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$cfg = VF::cfg('core.config');
$errors = array();
$messages = array();
$page_id = (isset($_GET['id']) && is_numeric($_GET['id'])) ? (int) $_GET['id'] : 0;
$db->query("SELECT static_id FROM #__static WHERE static_id = ".$page_id." LIMIT 1");
if ($db->affected_rows()) {
if (isset($_POST['submit_content_edit'])) {
$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[] = 'Content name cannot be left blank!';
} 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 {
$db->query("SELECT static_id FROM #__static WHERE name = '".$db->escape($name)."' AND static_id != ".$page_id." LIMIT 1");
if ($db->affected_rows()) {
$errors[] = 'Content name is already used for another content page!';
}
}
if ($meta_title != '') {
if (!VValid::length($meta_title, 1, 255)) {
$errors[] = 'Content page meta title can contain maximum 255 characters!';
}
}
if ($meta_desc != '') {
if (!VValid::length($meta_desc, 1, 255)) {
$errors[] = 'Content page meta description can contain maximum 255 characters!';
}
}
if ($meta_keys != '') {
if (!VValid::length($meta_keys, 1, 255)) {
$errors[] = 'Content page meta keywords can contain maximum 255 characters!';
}
}
if ($title == '') {
$errors[] = 'Content title cannot be left blank!';
} elseif (!VValid::length($title, 1, 255)) {
$errors[] = 'Content title can contain maximum 255 characters!';
}
if ($content == '') {
$errors[] = 'Please enter page content!';
}
if (!$errors) {
$db->query("UPDATE #__static
SET 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)."',
edited = '1',
edit_user_id = ".(int) $_SESSION['user_id'].",
edit_date = '".date('Y-m-d h:i:s')."',
status = '".$status."'
WHERE static_id = ".$page_id."
LIMIT 1");
$messages[] = 'Content page updated!';
VF::factory('cache')->remove('static_'.$name);
}
}
$db->query("SELECT * FROM #__static WHERE static_id = ".$page_id." LIMIT 1");
$page = $db->fetch_assoc();
}
$tpl = &VF::factory('template');
$tpl->menu = 'main';
$tpl->submenu = 'content_manage';
$tpl->meta_title = 'Admin::Content::Edit';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->page = $page;
$tpl->load(array('header', 'content_edit', 'footer'));
$tpl->display();
}
}
?>