Файл: adultscript-2.0.3-pro/files/admin/modules/rss/components/add.php
Строк: 123
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_rss_add
{
private $db;
public function __construct()
{
$this->db = VF::factory('database');
}
public function render()
{
$errors = array();
$messages = array();
$warnings = array();
$rss = array(
'channel_id' => 0,
'username' => '',
'name' => '',
'url' => '',
'method' => 'host',
'method_thumb' => 'generate',
'block_duplicates' => 1,
'update_limit' => 10,
'type' => 'public',
'premium' => 0,
'allow_embed' => 1,
'allow_comment' => 1,
'allow_download' => 1,
'allow_rating' => 1,
'mobile' => 0,
'categ_method' => 'auto',
'categories' => array(),
'status' => 1,
'queue' => 1
);
if (isset($_POST['submit_rss'])) {
$filter = VF::factory('filter');
$name = $filter->get('name');
$url = trim($_POST['url']);
$method = $filter->get('method');
$method_thumb = $filter->get('method_thumb');
$block_duplicates = (int) trim($_POST['block_duplicates']);
$update_limit = (int) trim($_POST['update_limit']);
$channel_id = (int) trim($_POST['channel_id']);
$username = $filter->get('username');
$type = $filter->get('type');
$premium = (int) trim($_POST['premium']);
$allow_comment = (int) trim($_POST['allow_comment']);
$allow_download = (int) trim($_POST['allow_download']);
$allow_rating = (int) trim($_POST['allow_rating']);
$allow_embed = (int) trim($_POST['allow_embed']);
$mobile = (int) trim($_POST['mobile']);
$categ_method = $filter->get('category_method');
$categories = (isset($_POST['category'])) ? (array) $_POST['category'] : array();
$status = (int) trim($_POST['status']);
$queue = (int) trim($_POST['queue']);
if ($name == '') {
$errors[] = 'Feed name field cannot be left blank!';
} else {
$rss['name'] = $name;
}
if ($url == '') {
$errors[] = 'Feed URL field cannot be left blank!';
} elseif (!VValid::url($url)) {
$errors[] = 'Feed URL is not a valid URL address!';
} else {
$rss['url'] = $url;
}
if ($update_limit > 20) {
$warnings[] = 'It is recommended that you set the Feed Update Limit to 10 for server resources balancing!';
}
if ($categ_method == 'select') {
if (empty($categories)) {
$errors[] = 'You need to select at least one category for your imported videos!';
}
} else {
$categ_method = 'auto';
$categories = array();
}
if ($username == '') {
$errors[] = 'Username field cannot be left blank!';
} else {
$this->db->query("SELECT user_id
FROM #__user
WHERE username = '".$this->db->escape($username)."'
AND status = '1'
LIMIT 1");
if ($this->db->affected_rows()) {
$user_id = (int) $this->db->fetch_field('user_id');
$rss['username'] = $username;
} else {
$errors[] = 'Username was not found on this system (or not active)!';
}
}
$rss['method'] = $method;
$rss['method_thumb'] = $method_thumb;
$rss['block_duplicates'] = $block_duplicates;
$rss['update_limit'] = $update_limit;
$rss['type'] = ($type == 'private') ? 'private' : 'public';
$rss['premium'] = $premium;
$rss['mobile'] = $mobile;
$rss['allow_embed'] = $allow_embed;
$rss['allow_rating'] = $allow_rating;
$rss['allow_comment'] = $allow_comment;
$rss['allow_download'] = $allow_download;
$rss['status'] = $status;
$rss['categ_method'] = $categ_method;
$rss['categories'] = $categories;
$rss['queue'] = $queue;
if (!$errors) {
$feed = VHelper::load('admin.rss.feed', true);
$feed->set_options($rss);
if ($error = $feed->test()) {
$errors[] = $error;
} else {
// if feed is big then database server runs away :-)
VF::factory_remove('database');
$this->db = VF::factory('database');
$this->db->query("INSERT INTO #__video_feeds
SET user_id = ".$user_id.",
channel_id = ".$channel_id.",
name = '".$this->db->escape($name)."',
url = '".$this->db->escape($url)."',
method = '".$this->db->escape($method)."',
method_thumb = '".$this->db->escape($method_thumb)."',
block_duplicates = '".$block_duplicates."',
update_limit = '".$update_limit."',
type = '".$rss['type']."',
premium = '".$premium."',
mobile = '".$mobile."',
allow_embed = '".$allow_embed."',
allow_comment = '".$allow_comment."',
allow_download = '".$allow_download."',
allow_rating = '".$allow_rating."',
categories = '".$this->db->escape(serialize($categories))."',
queue = ".$queue.",
status = '".$status."'");
$messages[] = 'Feed added!';
}
}
}
$tpl = VF::factory('template');
$tpl->menu = 'video';
$tpl->submenu = 'video_add';
$tpl->extramenu = 'video_rss';
$tpl->meta_title = 'Admin::Video::Feed';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->warnings = $warnings;
$tpl->rss = $rss;
$tpl->channels = VModel::load('channel', 'channel', true)->channels(
array('c.channel_id', 'c.name'),
array('sort' => 'c.name', 'order' => 'ASC')
);
$tpl->categories = VModel::load('category', 'video', true)->categories(
array('c.cat_id', 'c.name', 'c.auto_term'),
array('sort' => 'c.name', 'order' => 'ASC')
);
$tpl->load(array('header', 'rss_add', 'footer'));
$tpl->display();
}
}