Файл: adultscript-2.0.3-pro/files/admin/modules/adv/components/player_edit.php
Строк: 167
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_adv_player_edit
{
public function __construct()
{
}
public function render()
{
$errors = array();
$messages = array();
$adv = array();
$adv_id = (isset($_GET['id'])) ? (int) $_GET['id'] : 0;
$db = VF::factory('database');
$db->query("SELECT adv_id, media_ext
FROM #__adv_player
WHERE adv_id = ".$adv_id."
LIMIT 1");
if ($db->affected_rows()) {
$data = $db->fetch_assoc();
$ext = $data['media_ext'];
if (isset($_POST['submit_adv_edit'])) {
$filter = VF::factory('filter');
$name = $filter->get('adv_name');
$desc = $filter->get('adv_desc');
$type = $filter->get('type');
$expire = $filter->get('expire');
$status = (int) trim($_POST['status']);
$url = trim($_POST['url']);
if ($name == '') {
$errors[] = 'Advertising name field cannot be left blank!';
}
if ($desc != '') {
$adv['adv_desc'] = $desc;
}
if ($expire != '' && $expire != '0000-00-00') {
if (strlen($expire) !== 10) {
$errors[] = 'Advertising expire date invalid! Please use: yyyy-mm-dd!';
} elseif ($expire_timestamp = strtotime($expire) === FALSE) {
$errors[] = 'Advertising expire date invalid! Please use: yyyy-mm-dd!';
} else {
$current_timestamp = time();
if ($current_timestamp > $expire_timestamp) {
$errors[] = 'Advertising expire time is in the past!';
}
}
} else {
$expire = '0000-00-00';
}
if ($url == '') {
$errors[] = 'Advertising URL field cannot be left blank!';
} elseif (!VValid::url($url)) {
$errors[] = 'Advertising URL is not a valid URL address!';
}
if ($type == 'text' OR $type == 'image') {
$cuepoint = (int) trim($_POST['cuepoint']);
if ($cuepoint === 0) {
$errors[] = 'Cuepoint field must be a positive integer (seconds)!';
}
}
if ($type == 'text') {
$title = $filter->get('title');
$description = $filter->get('description');
$cuepoint = (int) trim($_POST['cuepoint']);
if ($title == '') {
$errors[] = 'Advertising title field cannot be left blank!';
}
if ($description == '') {
$errors[] = 'Advertising description field cannot be left blank!';
}
} elseif ($type == 'image') {
$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!';
}
} 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[] = 'Invalid image banner type selected! What exactly did you select!?';
}
} elseif ($type == 'video') {
$duration = (int) trim($_POST['duration']);
$position = (int) trim($_POST['position']);
$video_type = $filter->get('video_type');
if ($duration === 0) {
$errors[] = 'Media advertising duration cannot be 0 (positive integer required)!';
}
if ($position < -1) {
$errors[] = 'Media advertising can be 0 (before the main video), positive integer (seconds after) and -1 (at the end of the main video)!';
}
if ($video_type == 'url') {
$video_url = trim($_POST['video_url']);
if ($video_url == '') {
$errors[] = 'Media url cannot be left blank!';
} elseif (!VValid::url($video_url)) {
$errors[] = 'Media url is not a valid url address!';
}
} elseif ($video_type == 'file') {
if ($_FILES['video_file']['tmp_name'] != '') {
if (is_uploaded_file($_FILES['video_file']['tmp_name'])) {
$file = $_FILES['video_file']['tmp_name'];
$filename = $_FILES['video_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);
} elseif ($ext == 'flv' OR $ext == 'mp4') {
$valid = TRUE;
} elseif ($ext == 'swf') {
$value = TRUE;
} else {
$errors[] = 'Invalid media file! Format not supported! Supported formats: flv, mp4, swf, jpg, png and gif!';
}
if (!$valid) {
$errors[] = 'Invalid media file! File is not a valid media (renders incorrectly)!';
}
} else {
$errors[] = 'Image media file is not a valid uploaded file!';
}
}
} else {
$errors[] = 'Invalid media advertising type! What exactly did you select!?';
}
} else {
$errors[] = 'Invalid advertising type! What exactly did you select!?';
}
if (!$errors) {
$ext = (isset($ext)) ? $ext : '';
$media_type = (isset($image_url) OR isset($video_url)) ? 'url' : 'file';
$media_url = (isset($image_url)) ? $image_url : '';
if (isset($video_url)) {
$media_url = $video_url;
}
$title = (isset($title)) ? $title : '';
$description = (isset($description)) ? $description : '';
$cuepoint = (isset($cuepoint)) ? $cuepoint : 0;
$duration = (isset($duration)) ? $duration : 0;
$position = (isset($position)) ? $position : 0;
$db->query("UPDATE #__adv_player
SET adv_name = '".$db->escape($name)."',
adv_desc = '".$db->escape($desc)."',
type = '".$db->escape($type)."',
title = '".$db->escape($title)."',
description = '".$db->escape($description)."',
url = '".$db->escape($url)."',
cuepoint = ".$cuepoint.",
media_type = '".$db->escape($media_type)."',
media_url = '".$db->escape($media_url)."',
media_ext = '".$db->escape($ext)."',
duration = ".$duration.",
position = ".$position.",
expire = '".$db->escape($expire)."',
status = '".$status."'
WHERE adv_id = ".$adv_id."
LIMIT 1");
if (isset($file)) {
if (!move_uploaded_file($file, MEDIA_DIR.'/player/'.$adv_id.'.'.$ext)) {
$errors[] = 'Failed to move uploaded file! Invalid permissions!?';
}
}
if (!$errors) {
$messages[] = 'Player advertising added!';
}
}
}
$db->query("SELECT * FROM #__adv_player WHERE adv_id = ".$adv_id." LIMIT 1");
$adv = $db->fetch_assoc();
}
$tpl = VF::factory('template');
$tpl->menu = 'adv';
$tpl->submenu = 'player';
$tpl->extramenu = 'player_edit';
$tpl->meta_title = 'Advertising::Player::Edit';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->adv = $adv;
$tpl->load(array('header', 'adv_player_edit', 'footer'));
$tpl->display();
}
}