Файл: adultscript-2.0.3-pro/files/admin/modules/adv/components/add.php
Строк: 119
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_adv_add
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$errors = array();
$messages = array();
$adv = array(
'adv_group_id' => 0, 'adv_name' => '', 'adv_desc' => '', 'type' => 'image',
'title' => '', 'description' => '', 'url' => '', 'code' => '',
'image_type' => 'url', 'image_url' => '', 'image_ext' => '',
'status' => 1, 'expire' => '', 'blank' => 0);
$groups = $db->get_rows("SELECT adv_group_id, adv_group_name
FROM #__adv_groups
ORDER BY adv_group_name ASC");
if (isset($_POST['submit_adv_add'])) {
$filter = VF::factory('filter');
$group_id = (int) trim($_POST['adv_group_id']);
$name = $filter->get('adv_name');
$desc = $filter->get('adv_desc');
$status = (int) trim($_POST['status']);
$type = $filter->get('type');
$expire = $filter->get('expire');
$blank = (int) trim($_POST['blank']);
if ($name == '') {
$errors[] = 'Please enter the advertising banner name!';
} else {
$adv['adv_name'] = $name;
}
if ($group_id === 0) {
$errors[] = 'Please select a advertising position!';
} else {
$adv['adv_group_id'] = $group_id;
}
if ($type == 'text') {
$title = $filter->get('title');
$description = $filter->get('description');
$url = trim($_POST['url']);
if ($title == '') {
$errors[] = 'Please enter the advertising title (used for the a tag)!';
} else {
$adv['title'] = $title;
}
if ($description != '') {
$adv['description'] = $description;
}
} elseif ($type == 'html') {
$code = trim($_POST['code']);
if ($code == '') {
$errors[] = 'Please enter the advertising html/javascript code!';
} else {
$adv['code'] = $code;
}
} elseif ($type == 'image') {
$url = trim($_POST['url']);
$image_type = $filter->get('image_type');
if ($image_type == 'url') {
$image_url = trim($_POST['image_url']);
if ($image_url == '') {
$errors[] = 'Image banner url cannot be left blank!';
} elseif (!VValid::url($image_url)) {
$errors[] = 'Image banner url is not a valid url address!';
} else {
$adv['image_url'] = $image_url;
}
} elseif ($image_type == 'file') {
if ($_FILES['image_file']['tmp_name'] != '') {
if (is_uploaded_file($_FILES['image_file']['tmp_name'])) {
$file = $_FILES['image_file']['tmp_name'];
$filename = $_FILES['image_file']['name'];
$ext = VFile::ext($filename);
$valid = false;
if ($ext == 'gif') {
$valid = imagecreatefromgif($file);
} elseif ($ext == 'png') {
$valid = imagecreatefrompng($file);
} elseif ($ext == 'jpeg' OR $ext == 'jpg') {
$valid = imagecreatefromjpeg($file);
} else {
$errors[] = 'Invalid image banner file! Format not supported! Supported formats: jpg, png and gif!';
}
if (!$valid) {
$errors[] = 'Invalid image banner file! File is not a valid image (renders incorrectly)!';
}
} else {
$errors[] = 'Image banner file is not a valid uploaded file!';
}
} else {
$errors[] = 'Please upload a image banner file!';
}
} else {
$errors[] = 'Invalid image banner type selected! What exactly did you select!?';
}
} else {
$errors[] = 'Invalid banner type! What exactly did you select!?';
}
if (isset($url)) {
if ($url == '') {
$errors[] = 'Banner url cannot be left blank!';
} elseif (!VValid::url($url)) {
$errors[] = 'Banner url is not a valid url address!';
} else {
$adv['url'] = $url;
}
}
if ($expire == '' OR $expire == '0000-00-00') {
$expire = '0000-00-00';
} else {
if (strlen($expire) !== 10) {
$errors[] = 'Advertising expire date invalid! Please use: yyyy-mm-dd!';
} elseif (strtotime($expire) === FALSE) {
$errors[] = 'Advertising expire date invalid! Please use: yyyy-mm-dd!';
} else {
$current_timestamp = time();
$expire_timestamp = strtotime($expire);
if ($current_timestamp > $expire_timestamp) {
$errors[] = 'Advertising expire time is in the past!';
} else {
$adv['expire'] = $expire;
}
}
}
$adv['adv_desc'] = $desc;
$adv['status'] = $status;
$adv['blank'] = $blank;
$adv['type'] = $type;
$adv['image_type'] = (isset($image_type)) ? $image_type : 'url';
if (!$errors) {
$ext = (isset($ext)) ? $ext : '';
$db->query("INSERT INTO #__adv
SET adv_group_id = ".$group_id.",
adv_name = '".$db->escape($name)."',
adv_desc = '".$db->escape($desc)."',
type = '".$db->escape($type)."',
title = '".$db->escape($adv['title'])."',
description = '".$db->escape($adv['description'])."',
url = '".$db->escape($adv['url'])."',
code = '".$db->escape($adv['code'])."',
image_type = '".$db->escape($adv['image_type'])."',
image_url = '".$db->escape($adv['image_url'])."',
image_ext = '".$db->escape($ext)."',
expire = '".$db->escape($expire)."',
blank = '".$blank."',
status = '".$db->escape($status)."'");
if ($db->affected_rows()) {
$adv_id = $db->get_last_insert_id('#__adv');
$db->query("UPDATE #__adv_groups SET total_ads = total_ads+1 WHERE adv_group_id = ".$group_id." LIMIT 1");
if (isset($file)) {
if (!move_uploaded_file($file, MEDIA_DIR.'/banners/'.$adv_id.'.'.$ext)) {
$errors[] = 'Failed to move uploaded file! Permissions problem!?';
}
}
} else {
$errors[] = 'Failed to create database entry! Application error!?';
}
if (!$errors) {
$messages[] = 'Advertising banner added!';
}
}
}
$tpl = VF::factory('template');
$tpl->menu = 'adv';
$tpl->submenu = 'adv_add';
$tpl->meta_title = 'Admin::Advertising::Add';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->adv = $adv;
$tpl->groups = $groups;
$tpl->load(array('header', 'adv_add', 'footer'));
$tpl->display();
}
}