Файл: adultscript-2.0.3-pro/files/admin/modules/channel/components/edit.php
Строк: 239
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_channel_edit extends VModule_Admin_channel
{
public function __construct()
{
parent::__construct();
}
public function render()
{
$errors = array();
$messages = array();
$warnings = array();
$channel = array();
$cmodel = VModel::load('channel', 'channel', true);
$channel_id = (isset($_GET['id'])) ? (int) trim($_GET['id']) : 0;
if ($old = $cmodel->get($channel_id, array('c.network_id', 'c.thumb', 'c.logo'))) {
$old_network_id = (int) $old['network_id'];
$old_thumb = $old['thumb'];
$old_logo = $old['logo'];
if (isset($_POST['scale'])) {
$filter = VF::factory('filter');
$username = $filter->get('username');
$network_id = (int) trim($_POST['network_id']);
$name = $filter->get('name');
$slug = $filter->get('slug');
$description = trim($_POST['description']);
$url = trim($_POST['url']);
$total_videos = (int) trim($_POST['total_videos']);
$total_views = (int) trim($_POST['total_views']);
$total_likes = (int) trim($_POST['total_likes']);
$total_votes = (int) trim($_POST['total_votes']);
$total_duration = (int) trim($_POST['total_duration']);
$total_size = (int) trim($_POST['total_size']);
$total_subscribers = (int) trim($_POST['total_subscribers']);
$add_date = $filter->get('add_date');
$last_add_date = $filter->get('last_add_date');
$adv_bottom_id = (int) trim($_POST['adv_bottom_id']);
$adv_right_id = (int) trim($_POST['adv_right_id']);
$adv_player_id = (int) trim($_POST['adv_player_id']);
if ($username == '') {
$errors[] = 'Channel username field cannot be left blank!';
} else {
if (!$user_id = VModel::load('user', 'user', true)->exists('username', $username)) {
$errors[] = 'Invalid username!';
}
}
if ($network_id === 0) {
$errors[] = 'Please select a network for your channel!';
}
if ($name == '') {
$errors[] = 'Channel name field cannot be left blank!';
} elseif (!VValid::length($name, 2, 100)) {
$errors[] = 'Channel name can contain maximum 100 characters!';
}
if ($slug == '') {
$errors[] = 'Channel SLUG field cannot be left blank!';
} elseif (!VValid::length($slug, 2, 100)) {
$errors[] = 'Channel SLUG can contain maximum 16 characters!';
} elseif (!VValid::slug($slug)) {
$errors[] = 'Channel SLUG can contain only lowercase letters, numbers and dashes!';
} else {
if ($cmodel->exists('slug', $slug, $channel_id)) {
$errors[] = 'SLUG is already used for another channel!';
}
}
if ($url == '') {
$errors[] = 'Channel URL field cannot be left blank!';
} elseif (!VValid::url($url)) {
$errors[] = 'Channel URL is not a valid URL Address!';
}
if (isset($_FILES['thumb']) && isset($_FILES['thumb']['tmp_name']) &&
$_FILES['thumb']['tmp_name'] != '') {
if ($thumb = VUpload::process('thumb', 5, array('jpg', 'jpeg', 'png', 'gif', 'tiff'))) {
$image = VF::factory('image');
$image->set_option('jpeg_quality', 100);
if ($image->load($thumb['path'])) {
$thumb['ext'] = $image->src['ext'];
} else {
$errors[] = 'Failed to load thumb image!';
}
} else {
$errors = array_merge($errors, VUpload::error());
}
}
if (isset($_FILES['logo']) && isset($_FILES['logo']['tmp_name']) &&
$_FILES['logo']['tmp_name'] != '') {
if ($logo = VUpload::process('logo', 5, array('jpg', 'jpeg', 'png', 'gif', 'tiff'))) {
$image = VF::factory('image');
if ($image->load($logo['path'])) {
$logo['ext'] = $image->src['ext'];
} else {
$errors[] = 'Failed to load logo image!';
}
} else {
$errors = array_merge($errors, VUpload::error());
}
}
if ($adv_bottom_id === 0) {
$warnings[] = 'You can select a advertising banner for the channel bottom position later!';
}
if ($adv_right_id === 0) {
$warnings[] = 'You can select a advertising banner for the channel right position later!';
}
if ($adv_player_id === 0) {
$warnings[] = 'You can select a advertising banner for the channel player position later!';
}
if (!strtotime($add_date) OR strlen($add_date) !== 19) {
$errors[] = 'Channel add date is not a valid date (valid format: yyyy-mm-dd h:i:s)!';
}
if ($last_add_date != '0000-00-00 00:00:00') {
if (!strtotime($last_add_date) OR strlen($last_add_date) != 19) {
$errors[] = 'Channel last add date is not a valid date (valid format: yyyy-mm-dd h:i:s)!';
}
}
if (!$errors) {
$channel = array(
'user_id' => $user_id,
'network_id' => $network_id,
'name' => $name,
'slug' => $slug,
'description' => $description,
'url' => $url,
'adv_bottom_id' => $adv_bottom_id,
'adv_right_id' => $adv_right_id,
'adv_player_id' => $adv_player_id,
'total_videos' => $total_videos,
'total_views' => $total_views,
'total_duration' => $total_duration,
'total_likes' => $total_likes,
'total_votes' => $total_votes,
'total_subscribers' => $total_subscribers,
'total_size' => $total_size,
'add_time' => strtotime($add_date),
'last_add_time' => strtotime($last_add_date)
);
$channel['thumb'] = (isset($thumb) && $thumb) ? $thumb['ext'] : $old['thumb'];
$channel['logo'] = (isset($logo) && $logo) ? $logo['ext'] : $old['logo'];
if ($cmodel->update($channel_id, $channel)) {
if (isset($_POST['c']) && $_POST['c'] == 'submitted') {
$scale = (float) $_POST['scale'];
$x = (int) $_POST['x'];
$y = (int) $_POST['y'];
$w = (int) $_POST['w'];
$h = (int) $_POST['h'];
$current = MEDIA_DIR.'/channels/'.$channel_id.'.thumb.'.$old['thumb'];
$dst_tmp = $current.'.'.VText::random().'.'.$old['thumb'];
$image = VF::factory('image');
if ($image->load($current)) {
if ($image->zoom($scale) &&
$image->crop($x, $y, $w, $h, $dst_tmp)) {
rename($dst_tmp, $current);
} else {
$errors[] = $image->get_error();
}
} else {
$errors[] = $image->get_error();
}
}
if (isset($thumb) && $thumb) {
$dst = MEDIA_DIR.'/channels/'.$channel_id.'.thumb.'.$thumb['ext'];
if (!move_uploaded_file($thumb['path'], $dst)) {
$errors[] = 'Failed to move uploaded thumb file!';
}
}
if (isset($logo) && $logo) {
$dst = MEDIA_DIR.'/channels/'.$channel_id.'.logo.'.$logo['ext'];
if (!move_uploaded_file($logo['path'], $dst)) {
$errors[] = 'Failed to move uploaded logo file!';
}
}
if (!$errors) {
$messages[] = 'Channel updated!';
}
} else {
$errors[] = 'Failed to update channel!';
}
}
}
$channel = $cmodel->get($channel_id);
}
$gmodel = VModel::load('group', 'adv', true);
$amodel = VModel::load('adv', 'adv', true);
if ($bottom_group_id = $gmodel->exists('adv_group_slug', 'channel-bottom')) {
$advs_bottom = $amodel->advs(array('where' => "a.adv_group_id = ".$bottom_group_id." AND a.status = '1'"));
}
if ($right_group_id = $gmodel->exists('adv_group_slug', 'channel-right')) {
$advs_right = $amodel->advs(array('where' => "a.adv_group_id = ".$right_group_id." AND a.status = '1'"));
}
if ($player_group_id = $gmodel->exists('adv_group_slug', 'video-player')) {
$advs_player = $amodel->advs(array('where' => "a.adv_group_id = ".$player_group_id." AND a.status = '1'"));
}
$tpl = VF::factory('template');
$tpl->menu = 'channel';
$tpl->submenu = 'channel_edit';
$tpl->meta_title = 'Admin::Channel::Edit';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->warnings = $warnings;
$tpl->channel = $channel;
$tpl->networks = VModel::load('network', 'channel', true)->networks(array(), array('sort' => 'n.name', 'order' => 'ASC'), 10000);
$tpl->advs_bottom = (isset($advs_bottom)) ? $advs_bottom : array();
$tpl->advs_right = (isset($advs_right)) ? $advs_right : array();
$tpl->advs_player = (isset($advs_player)) ? $advs_player : array();
$tpl->load(array('header', 'channel_edit', 'footer'));
$tpl->display();
}
}
?>