Файл: adultscript-2.0.3-pro/files/admin/modules/video/models/video.php
Строк: 111
<?php
class VModel_Admin_video extends VModel
{
public function __construct()
{
parent::__construct();
}
public function add($video)
{
$premium = (isset($video['premium'])) ? (int) $video['premium'] : 0;
$embed = (isset($video['embed_code'])) ? $video['embed_code'] : '';
$url = (isset($video['url'])) ? $video['url'] : '';
$mobile = (isset($video['mobile'])) ? $video['mobile'] : 0;
$mobile_url = (isset($video['mobile_url'])) ? $video['mobile_url'] : '';
$allow_embed = (isset($video['allow_embed'])) ? $video['allow_embed'] : 1;
$allow_rating = (isset($video['allow_rating'])) ? $video['allow_rating'] : 1;
$allow_download = (isset($video['allow_download'])) ? $video['allow_download'] : 1;
$allow_comment = (isset($video['allow_comment'])) ? $video['allow_comment'] : 1;
$channel_id = (isset($video['channel_id'])) ? $video['channel_id'] : 0;
$this->db->query("
INSERT INTO #__video
SET user_id = ".$video['user_id'].",
title = '".$this->db->escape($video['title'])."',
slug = '".$this->db->escape($video['slug'])."',
description = '".$this->db->escape($video['description'])."',
type = '".$this->db->escape($video['type'])."',
embed_code = '".$this->db->escape($embed)."',
allow_embed = '".$allow_embed."',
allow_rating = '".$allow_rating."',
allow_download = '".$allow_download."',
allow_comment = '".$allow_comment."',
url = '".$this->db->escape($url)."',
mobile = '".$mobile."',
mobile_url = '".$this->db->escape($mobile_url)."',
premium = ".$premium.",
channel_id = ".$channel_id.",
add_date = '".date('Y-m-d H:i:s')."',
add_time = ".time().",
status = ".$video['status']
);
if ($this->db->affected_rows()) {
return $this->db->get_last_insert_id('#__video');
}
return false;
}
public function update($video_id, $video)
{
$fields = array();
foreach ($video as $column => $value) {
$value = (ctype_digit($value) or is_int($value)) ? $value : "'".$this->db->escape($value)."'";
$fields[] = $column.' = '.$value;
}
$this->db->query("
UPDATE #__video
SET ".implode(',', $fields)."
WHERE video_id = ".$video_id."
LIMIT 1
");
}
public function add_orig($video)
{
$url = (isset($video['url'])) ? $video['url'] : '';
$this->db->query("
INSERT INTO #__video_orig
SET video_id = ".$video['video_id'].",
user_id = ".$video['user_id'].",
filename = '".$this->db->escape($video['filename'])."',
ext = '".$this->db->escape($video['ext'])."',
size = ".$video['size'].",
method = '".$this->db->escape($video['method'])."',
url = '".$this->db->escape($url)."',
ip = ".VServer::ip(true).",
add_time = ".time()
);
if ($this->db->affected_rows()) {
return true;
}
return false;
}
public function add_category($video_id, $cat_id)
{
$this->db->query("
INSERT INTO #__video_category
SET video_id = ".$video_id.",
cat_id = ".$cat_id
);
$this->db->query("
UPDATE #__video_categories
SET total_videos = total_videos+1
WHERE cat_id = ".$cat_id."
LIMIT 1
");
}
public function add_channel($video_id, $channel_id)
{
$this->db->query("
SELECT network_id
FROM #__channel
WHERE channel_id = ".$channel_id."
LIMIT 1
");
if ($this->db->affected_rows()) {
$network_id = (int) $this->db->fetch_field('network_id');
$this->db->query("
UPDATE #__channel
SET total_videos = total_videos+1,
last_add_time = ".time()."
WHERE channel_id = ".$channel_id."
LIMIT 1
");
$this->db->query("
UPDATE #__channel_networks
SET total_videos = total_videos+1
WHERE network_id = ".$network_id."
LIMIT 1
");
}
}
public function add_tag($video_id, $name)
{
$this->db->query("
INSERT INTO #__video_tags
SET video_id = ".$video_id.",
name = '".$this->db->escape(trim($name))."'
");
return $this->db->affected_rows();
}
public function add_queue($video_id, $status)
{
$this->db->query(
"INSERT INTO #__video_queue
SET video_id = ".$video_id.",
status = ".$status.",
add_time = ".time()
);
}
public function add_model($video_id, $value)
{
if (is_int($value)) {
$model_id = $value;
} else {
$this->db->query("SELECT model_id
FROM #__model
WHERE name = '".$this->db->escape($value)."'
LIMIT 1");
if ($this->db->affected_rows()) {
$model_id = (int) $this->db->fetch_field('model_id');
}
}
if (isset($model_id) && $model_id) {
$this->db->query("INSERT INTO #__model_videos
SET model_id = ".$model_id.",
video_id = ".$video_id);
$this->db->query("UPDATE #__model
SET total_videos = total_videos+1
WHERE model_id = ".$model_id."
LIMIT 1");
}
}
public function add_activity($user_id)
{
$this->db->query("UPDATE #__user_activity
SET total_videos = total_videos+1
WHERE user_id = ".$user_id."
LIMIT 1");
}
public function add_csv($video_id, $unique_id)
{
$this->db->query("INSERT INTO #__video_csv_imported
SET unique_id = '".$this->db->escape($unique_id)."',
video_id = ".$video_id);
}
public function exists($column, $value, $video_id = 0)
{
$value = (ctype_digit($value) or is_int($value)) ? (int) $value : "'".$this->db->escape($value)."'";
$this->db->query("
SELECT video_id
FROM #__video
WHERE ".$column." = ".$value."
AND video_id != ".(int) $video_id."
LIMIT 1"
);
if ($this->db->affected_rows()) {
return (int) $this->db->fetch_field('video_id');
}
return false;
}
}