Файл: adultscript-2.0.3-pro/files/admin/modules/video/components/mass_edit.php
Строк: 130
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_video_mass_edit extends VModule_Admin_video
{
private $db;
public function __construct()
{
$this->db = VF::factory('database');
}
public function render()
{
$errors = array();
$messages = array();
$ids = array();
if (isset($_POST['videos']) && is_array($_POST['videos'])) {
$ids = $_POST['videos'];
}
if (isset($_POST['submit-edit'])) {
$filter = VF::factory('filter');
foreach ($_POST['items'] as $video_id => $video) {
$errs = array();
$this->db->query("SELECT v.video_id, v.user_id, u.username,
GROUP_CONCAT(DISTINCT c.cat_id) AS categories,
GROUP_CONCAT(DISTINCT t.name) AS tags
FROM #__video AS v
LEFT JOIN #__video_category AS c ON (c.video_id = v.video_id)
LEFT JOIN #__video_tags AS t ON (t.video_id = v.video_id)
LEFT JOIN #__user AS u ON (u.user_id = v.user_id)
WHERE v.video_id = ".$video_id."
GROUP BY v.video_id
LIMIT 1");
if ($this->db->affected_rows()) {
$ovideo = $this->db->fetch_assoc();
$ouser_id = (int) $ovideo['user_id'];
$otags = $ovideo['tags'];
$ocategories = explode(',', $ovideo['categories']);
sort($ocategories);
$username = $filter->clean($video['username']);
$title = $filter->clean($video['title']);
$description = $filter->clean($video['description']);
$tags = $filter->clean($video['tags']);
$categories = (isset($video['categories'])) ? $video['categories'] : array();
sort($categories);
$thumb = (int) $video['thumb'];
$allow_embed = (int) $video['allow_embed'];
$allow_rating = (int) $video['allow_rating'];
$allow_comment = (int) $video['allow_comment'];
$allow_download = (int) $video['allow_download'];
$mobile = (int) $video['mobile'];
$premium = (int) $video['premium'];
$locked = (int) $video['locked'];
$flagged = (int) $video['flagged'];
$status = (int) $video['status'];
$ext = $filter->clean($video['ext']);
$duration = (float) $video['duration'];
$ext = $filter->clean($video['ext']);
if ($username == '') {
$errs[] = $video_id.' : Video username field cannot be left blank!';
} elseif ($username != $ovideo['username']) {
$this->db->query("SELECT user_id
FROM #__user
WHERE username = '".$this->db->escape($username)."'
LIMIT 1");
if ($this->db->affected_rows()) {
$user_id = (int) $this->db->fetch_field('user_id');
} else {
$errs[] = $video_id.' : Invalid username '.$username.' entered!';
}
} else {
$user_id = $ouser_id;
}
if ($title == '') {
$errs[] = $video_id.' : Video title field cannot be left blank!';
}
if ($tags == '') {
$errs[] = $video_id.' : Video tags field cannot be left blank!';
} else {
$tags = prepare_tags($tags);
}
if (empty($categories)) {
$errs[] = $video_id.' : Please select at least one category for this video!';
}
if (!$errs) {
$vcfg = VF::cfg('module.video');
$slug = prepare_string($title, TRUE, $vcfg['slug_max_length']);
$this->db->query("UPDATE #__video
SET user_id = ".$user_id.",
title = '".$this->db->escape($title)."',
slug = '".$this->db->escape($slug)."',
description = '".$this->db->escape($description)."',
allow_embed = '".$allow_embed."',
allow_rating = '".$allow_rating."',
allow_comment = '".$allow_comment."',
allow_download = '".$allow_download."',
thumb = ".$thumb.",
ext = '".$this->db->escape($ext)."',
duration = ".$duration.",
premium = '".$premium."',
mobile = '".$mobile."',
flagged = '".$flagged."',
status = ".$status."
WHERE video_id = ".$video_id."
LIMIT 1");
if ($user_id !== $ouser_id) {
$this->db->query("UPDATE #__user_activity
SET total_videos = total_videos-1
WHERE user_id = ".$ouser_id."
LIMIT 1");
$this->db->query("UPDATE #__user_activity
SET total_videos = total_videos+1
WHERE user_id = ".$user_id."
LIMIT 1");
}
if ($categories != $ocategories) {
foreach ($ocategories as $category) {
if (!in_array($category, $categories)) {
$category = (int) $category;
$this->db->query("DELETE FROM #__video_category WHERE video_id = ".$video_id." AND cat_id = ".$category." LIMIT 1");
$this->db->query("UPDATE #__video_categories SET total_videos = total_videos-1 WHERE cat_id = ".$category." LIMIT 1");
}
}
foreach ($categories as $category) {
if (!in_array($category, $ocategories)) {
$category = (int) $category;
$this->db->query("INSERT INTO #__video_category SET video_id = ".$video_id.", cat_id = ".$category);
$this->db->query("UPDATE #__video_categories SET total_videos = total_videos+1 WHERE cat_id = ".$category." LIMIT 1");
}
}
}
$otags = explode(',', $otags);
sort($otags);
$tags = explode(',', $tags);
sort($tags);
if ($otags != $tags) {
$this->db->query("DELETE FROM #__video_tags WHERE video_id = ".$video_id);
foreach ($tags as $tag) {
$this->db->query("INSERT INTO #__video_tags SET video_id = ".$video_id.", name = '".$this->db->escape(trim($tag))."'");
}
}
$messages[] = $video_id.' : Video updated!';
}
} else {
$errs[] = $video_id.' : failed to fetch old data! aborting...';
}
$errors = array_merge($errors, $errs);
}
}
if ($ids) {
$sql = "SELECT v.video_id, v.user_id, v.title, v.description, v.allow_embed,
v.allow_rating, v.allow_download, v.allow_comment, v.rating,
v.rated_by, v.total_views, v.total_downloads, v.total_comments,
v.total_favorites, v.type, v.embed_code, v.add_date, v.view_date,
v.channel_id, v.flagged, v.locked, v.status, v.adv, v.url, v.premium,
v.price, v.mobile, v.mobile_url, v.thumb, v.thumbs, u.username,
v.duration, v.ext,
GROUP_CONCAT(DISTINCT t.name) AS tags,
GROUP_CONCAT(DISTINCT c.cat_id) AS categories
FROM #__video AS v
LEFT JOIN #__video_tags AS t ON (t.video_id = v.video_id)
LEFT JOIN #__video_category AS c ON (c.video_id = v.video_id)
LEFT JOIN #__user AS u ON (u.user_id = v.user_id)
WHERE v.video_id IN (".implode(',', array_values($ids)).")
GROUP BY v.video_id";
$videos = $this->db->get_rows($sql);
} else {
$videos = array();
$errors[] = 'Please select at least one video!';
}
$tpl = VF::factory('template');
$tpl->menu = 'video';
$tpl->submenu = 'video_manage';
$tpl->meta_title = 'Admin::Video::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->statuses = array(
'0' => 'Suspended',
'1' => 'Published',
'2' => 'Waiting Approval',
'3' => 'Uploading',
'4' => 'Converting',
'5' => 'Grabbing',
'6' => 'Queued',
'7' => 'Error'
);
$tpl->videos = $videos;
$tpl->categories = $this->get_video_categories();
$tpl->sponsors = $this->get_video_sponsors();
$tpl->advertising = $this->get_video_advertising();
$tpl->load(array('header', 'video_mass_edit', 'footer'));
$tpl->display();
}
private function get_video_categories()
{
$this->db->query("SELECT cat_id, name
FROM #__video_categories
ORDER BY slug ASC");
return $this->db->fetch_rows();
}
private function get_video_sponsors()
{
$this->db->query("SELECT sponsor_id, sponsor_name
FROM #__video_sponsors");
return $this->db->fetch_rows();
}
private function get_video_advertising()
{
$this->db->query("SELECT adv_group_id
FROM #__adv_groups
WHERE adv_group_slug = 'video-player'
LIMIT 1");
if ($this->db->affected_rows()) {
$adv_group_id = (int) $this->db->fetch_field('adv_group_id');
$this->db->query("SELECT adv_id, adv_name
FROM #__adv
WHERE adv_group_id = ".$adv_group_id);
return $this->db->fetch_rows();
}
return array();
}
}