Файл: adultscript-2.0.3-pro/files/modules/video/helpers/jw.php
Строк: 175
<?php
defined('_VALID') or die('Restricted Access!');
class VHelper_video_jw
{
private static $config = array();
public static function get_config($name)
{
if (isset(self::$config['autoPlay'])) {
return self::$config;
}
$cache = VF::factory('cache');
if (!self::$config = $cache->get($name, 86400)) {
$db = VF::factory('database');
$db->query("SELECT player_id, config_cache
FROM #__player
WHERE name = '".$db->escape($name)."'
AND status = '1'
LIMIT 1");
if ($db->affected_rows()) {
self::$config = unserialize($db->fetch_field('config_cache'));
self::$config['player_id'] = (int) $db->fetch_field('player_id');
self::$config = array_merge(self::$config, VF::cfg('library.player'));
$cache->store($name, self::$config, 86400);
}
}
return self::$config;
}
public static function get_logo($top, $left, $bottom, $right)
{
$output = array();
if ($top != '0') {
$output[] = "'top': ".$top;
}
if ($left != '0') {
$output[] = "'left': ".$left;
}
if ($bottom != '0') {
$output[] = "'bottom': ".$bottom;
}
if ($right != '0') {
$output[] = "'right': ".$right;
}
if (!empty($output)) {
return ','.implode(',', $output);
}
}
public static function get_image_adv($video_id, $user_id, $sponsor_id, $categories=array())
{
if (!isset(self::$config['autoPlay'])) {
return;
}
if (self::$config['adv'] === 0 OR self::$config['adv_image'] === 0) {
return;
}
$cache = VF::factory('cache');
$db = VF::factory('database');
if (!empty(self::$config['image']['video'])) {
if (!$adv = $cache->get('player_img_adv_video_'.$video_id, 86400)) {
$db->query("SELECT av.adv_id, a.url, a.media_type, a.media_url,
a.media_ext, a.cuepoint, a.expire
FROM #__adv_player_video AS av
INNER JOIN #__adv_player AS a ON (a.adv_id = av.adv_id AND a.type = 'image' AND a.status = '1')
WHERE av.video_id = ".$video_id."
LIMIT 1");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('player_img_adv_video_'.$video_id, $adv, 86400);
}
}
if ($adv) {
return self::image_adv($adv);
}
}
if (!empty(self::$config['image']['sponsor']) && $sponsor_id) {
if (!$adv = $cache->get('player_img_adv_sponsor_'.$sponsor_id, 86400)) {
$db->query("SELECT a.adv_id, a.url, a.media_type, a.media_url,
a.media_ext, a.cuepoint, a.expire
FROM #__video_sponsors AS s
INNER JOIN #__adv_player AS a ON (a.adv_id = s.adv_image_id AND a.type = 'image' AND a.status = '1')
WHERE s.sponsor_id = ".$sponsor_id."
LIMIT 1");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('player_img_adv_sponsor_'.$sponsor_id, $adv, 86400);
}
}
if ($adv) {
return self::image_adv($adv);
}
}
if (!empty(self::$config['image']['category']) && $categories) {
$categories = explode(',', $categories);
foreach ($categories as $category) {
if (!$adv = $cache->get('player_img_adv_category_'.$category, 86400)) {
$db->query("SELECT a.adv_id, a.url, a.media_type, a.media_url,
a.media_ext, a.cuepoint, a.expire
FROM #__video_categories AS c
INNER JOIN #__adv_player AS a ON (a.adv_id = c.adv_image_id AND a.type = 'image' AND a.status = '1')
WHERE c.cat_id = ".(int) $category."
LIMIT 1");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('player_img_adv_category_'.$category, $adv, 86400);
}
}
if ($adv) {
return self::image_adv($adv);
}
}
}
if (!empty(self::$config['image']['default'])) {
if (!$adv = $cache->get('player_img_adv', 86400)) {
$db->query("SELECT a.adv_id, a.url, a.media_type, a.media_url,
a.media_ext, a.cuepoint, a.expire
FROM #__adv_player_default AS d
INNER JOIN #__adv_player AS a ON (a.adv_id = d.adv_id AND a.type = 'image' AND a.status = '1')
WHERE d.player_id = ".self::$config['player_id']."
LIMIT 1");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('player_img_adv', $adv, 86400);
}
if ($adv) {
return self::image_adv($adv);
}
}
}
return;
}
public static function image_adv($adv)
{
if ($adv['expire'] != '0000-00-00') {
$current_timestamp = time();
$expire_timestamp = strtotime($adv['expire']);
if ($current_timestamp > $expire_timestamp) {
return;
}
}
$db = VF::factory('database');
$db->query("UPDATE #__adv_player
SET views = views+1
WHERE adv_id = ".$adv['adv_id']."
LIMIT 1");
$image_url = ($adv['media_type'] == 'file')
? BASE_URL.'/media/player/'.$adv['adv_id'].'.'.$adv['media_ext']
: $adv['media_url'];
return array(
'cuepoint' => "{'time': ".($adv['cuepoint']*1000).", 'image': true},",
'code' => "'html': '<a href="".BASE_URL."/adv/".$adv['adv_id']."/?type=player" target="_blank"><img src="".$image_url."" width="300" height="250" align="center"></a>',"
);
}
public static function get_text_adv($video_id, $user_id, $sponsor_id, $categories=array())
{
if (!isset(self::$config['autoPlay'])) {
return;
}
if (self::$config['adv'] === 0 OR self::$config['adv_text'] === 0) {
return;
}
$cache = VF::factory('cache');
$db = VF::factory('database');
if (!empty(self::$config['text']['video'])) {
if (!$adv = $cache->get('player_txt_adv_video_'.$video_id, 86400)) {
$db->query("SELECT av.adv_id, a.url, a.title, a.description, a.cuepoint, a.expire
FROM #__adv_player_video AS av
INNER JOIN #__adv_player AS a ON (a.adv_id = av.adv_id AND a.type = 'text' AND a.status = '1')
WHERE av.video_id = ".$video_id."
LIMIT 1");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('player_txt_adv_video_'.$video_id, $adv, 86400);
}
}
if ($adv) {
return self::text_adv($adv);
}
}
if (!empty(self::$config['text']['sponsor']) && $sponsor_id) {
if (!$adv = $cache->get('player_txt_adv_sponsor_'.$sponsor_id, 86400)) {
$db->query("SELECT a.adv_id, a.url, a.title, a.description, a.cuepoint, a.expire
FROM #__video_sponsors AS s
INNER JOIN #__adv_player AS a ON (a.adv_id = s.adv_text_id AND a.type = 'text' AND a.status = '1')
WHERE s.sponsor_id = ".$sponsor_id."
LIMIT 1");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('player_txt_adv_sponsor_'.$sponsor_id, $adv, 86400);
}
}
if ($adv) {
return self::text_adv($adv);
}
}
if (!empty(self::$config['text']['category']) && $categories) {
$categories = explode(',', $categories);
foreach ($categories as $category) {
if (!$adv = $cache->get('player_txt_adv_category_'.$category, 86400)) {
$db->query("SELECT a.adv_id, a.url, a.title, a.description, a.cuepoint, a.expire
FROM #__video_categories AS c
INNER JOIN #__adv_player AS a ON (a.adv_id = c.adv_image_id AND a.type = 'text' AND a.status = '1')
WHERE c.cat_id = ".(int) $category."
LIMIT 1");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('player_txt_adv_category_'.$category, $adv, 86400);
}
}
if ($adv) {
return self::text_adv($adv);
}
}
}
if (!empty(self::$config['text']['default'])) {
if (!$adv = $cache->get('player_txt_adv', 86400)) {
$db->query("SELECT a.adv_id, a.url, a.title, a.description, a.cuepoint, a.expire
FROM #__adv_player_default AS d
INNER JOIN #__adv_player AS a ON (a.adv_id = d.adv_id AND a.type = 'text' AND a.status = '1')
WHERE d.player_id = ".self::$config['player_id']."
LIMIT 1");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('player_img_adv', $adv, 86400);
}
if ($adv) {
return self::text_adv($adv);
}
}
}
return;
}
public static function text_adv($adv)
{
if ($adv['expire'] != '0000-00-00') {
$current_timestamp = time();
$expire_timestamp = strtotime($adv['expire']);
if ($current_timestamp > $expire_timestamp) {
return;
}
}
return array(
'cuepoint' => "{'time': ".($adv['cuepoint']*1000).", 'text': true},",
'code' => "'html': '<a href="".BASE_URL."/adv/".$adv['adv_id']."/?type=player" target="_blank" class="title">".urlencode($adv['title'])."</a><br />".urlencode($adv['description'])."<br /><a href="".BASE_URL."/adv/".$adv['adv_id']."/?type=player" target="_blank" class="link">".urlencode($adv['url'])."</a>',"
);
}
public static function get_media_adv($video_id, $user_id, $sponsor_id, $categories=array())
{
if (!isset(self::$config['autoPlay'])) {
return;
}
if (self::$config['adv'] === 0 OR self::$config['adv_media'] === 0) {
return;
}
$cache = VF::factory('cache');
$db = VF::factory('database');
if (!empty(self::$config['media']['video'])) {
if (!$advs = $cache->get('player_media_adv_video_'.$video_id, 86400)) {
$db->query("SELECT av.adv_id, a.url, a.media_type, a.media_url,
a.media_ext, a.duration, a.position, a.expire
FROM #__adv_player_video AS av
INNER JOIN #__adv_player AS a ON (a.adv_id = av.adv_id AND a.type = 'video' AND a.status = '1')
WHERE av.video_id = ".$video_id);
if ($db->affected_rows()) {
$advs = $db->fetch_rows();
$cache->store('player_media_adv_video_'.$video_id, $advs, 86400);
}
}
if ($advs) {
return self::media_adv($advs);
}
}
if (!empty(self::$config['media']['sponsor']) && $sponsor_id) {
if (!$advs = $cache->get('player_media_adv_sponsor_'.$sponsor_id, 86400)) {
$db->query("SELECT adv_video
FROM #__video_sponsors
WHERE sponsor_id = ".$sponsor_id."
AND adv_video != ''
LIMIT 1");
if ($db->affected_rows()) {
$row = $db->fetch_assoc();
$ids = unserialize($row['adv_video']);
if (!empty($ids)) {
$db->query("SELECT a.adv_id, a.url, a.media_type, a.media_url,
a.media_ext, a.duration, a.position, a.expire
FROM #__adv_player AS a
WHERE a.adv_id IN (".implode(',', array_keys($ids)).")");
if ($db->affected_rows()) {
$advs = $db->fetch_rows();
$cache->store('player_media_adv_sponsor_'.$sponsor_id, $advs, 86400);
}
}
}
}
if ($advs) {
return self::media_adv($advs);
}
}
if (!empty(self::$config['media']['category']) && $categories) {
$categories = explode(',', $categories);
foreach ($categories as $category) {
if (!$advs = $cache->get('player_media_adv_category_'.$category, 86400)) {
$db->query("SELECT a.adv_id, a.url, a.media_type, a.media_url,
a.media_ext, a.duration, a.position, a.expire
FROM #__video_categories AS c
INNER JOIN #__adv_player AS a ON (a.adv_id = c.adv_image_id AND a.type = 'video' AND a.status = '1')
WHERE c.cat_id = ".(int) $category);
if ($db->affected_rows()) {
$advs = $db->fetch_rows();
$cache->store('player_media_adv_category_'.$category, $advs, 86400);
}
}
if ($advs) {
return self::media_adv($advs);
}
}
}
if (!empty(self::$config['media']['default'])) {
if (!$advs = $cache->get('player_media_adv', 86400)) {
$db->query("SELECT a.adv_id, a.url, a.media_type, a.media_url,
a.media_ext, a.duration, a.position, a.expire
FROM #__adv_player_default AS d
INNER JOIN #__adv_player AS a ON (a.adv_id = d.adv_id AND a.type = 'video' AND a.status = '1')
WHERE d.player_id = ".self::$config['player_id']);
if ($db->affected_rows()) {
$advs = $db->fetch_rows();
$cache->store('player_media_adv', $advs, 86400);
}
if ($advs) {
return self::media_adv($advs);
}
}
}
return;
}
private static function media_adv($advs)
{
$playlist = array();
$current_timestamp = time();
foreach ($advs as $adv) {
$expire_timestamp = strtotime($adv['expire']);
if ($adv['expire'] == '0000-00-00' OR $current_timestamp < $expire_timestamp) {
$media_url = ($adv['media_type'] == 'file') ? BASE_URL.'/media/player/'.$adv['adv_id'].'.'.$adv['media_ext'] : $adv['media_url'];
$playlist[] = "{'url': '".$media_url."', 'linkUrl': '".urlencode($adv['url'])."', 'duration': ".$adv['duration'].", 'position': ".$adv['position']."},";
}
}
return ($playlist) ? "'playlist': [".implode("n", $playlist)."]," : NULL;
}
private static function escape($text)
{
return $text;
}
}