Файл: adultscript-2.0.3-pro/files/templates/defboot/extend/plugins/adv_player.plugin.php
Строк: 76
<?php
defined('_VALID') or die('Restricted Access!');
function template_plugin_adv_player($adv_id, $channel_id, $user_id, $categories)
{
if (VF::cfg_item('ads') === 0) {
return;
}
$db = VF::factory('database');
$cache = VF::factory('cache');
if ($adv_id) {
if (!$adv = $cache->get('adv_'.$adv_id, 0)) {
$db->query("SELECT a.adv_id, a.title, a.description, a.type, a.url, a.blank,
a.code, a.image_type, a.image_url, a.image_ext, a.expire
FROM #__adv AS a
WHERE a.adv_id = ".(int) $adv_id."
AND a.status = '1'
LIMIT 1");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('adv_'.$adv_id, $adv, 0);
}
}
if ($adv) {
return display_adv($adv);
}
}
if ($user_id) {
if (!$adv = $cache->get('user_adv_'.$user_id, 0)) {
$db->query("SELECT a.adv_id, a.title, a.description, a.type, a.url, a.blank,
a.code, a.image_type, a.image_url, a.image_ext, a.expire
FROM #__adv AS a, #__adv_groups AS g
WHERE g.adv_group_slug = 'user-player'
AND a.adv_group_id = g.adv_group_id
AND a.user_id = ".(int) $user_id."
AND a.status = '1'");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('user_adv_'.$user_id, $adv, 0);
}
}
if ($adv) {
return display_adv($adv);
}
}
if ($channel_id) {
if (!$adv = $cache->get('channel_adv_'.$channel_id, 0)) {
$db->query("SELECT a.adv_id, a.title, a.description, a.type, a.url, a.blank,
a.code, a.image_type, a.image_url, a.image_ext, a.expire
FROM #__channel AS c
INNER JOIN #__adv AS a ON (a.adv_id = c.adv_player_id AND a.status = '1')
WHERE c.channel_id = ".$channel_id."
LIMIT 1");
if ($db->affected_rows()) {
$adv = $db->fetch_assoc();
$cache->store('channel_adv_'.$channel_id, $adv, 0);
}
}
if ($adv) {
return display_adv($adv);
}
}
if ($categories) {
if (!$group = $cache->get('group_video-player', 86400)) {
$db->query("SELECT adv_group_id, adv_rotate
FROM #__adv_groups
WHERE adv_group_slug = 'video-player'
LIMIT 1");
if ($db->affected_rows()) {
$group = $db->fetch_assoc();
$cache->store('group_video-player', $group, 86400);
}
}
if ($group) {
$categories = explode(',', $categories);
$limit = ($group['adv_rotate'] == '0') ? ' LIMIT 1' : '';
foreach ($categories as $category) {
$category = (int) $category;
if (!$advs = $cache->get('category_adv_'.$category, 0)) {
$db->query("SELECT a.adv_id, a.title, a.description, a.type, a.url, a.blank,
a.code, a.image_type, a.image_url, a.image_ext, a.expire
FROM #__adv_category AS c
INNER JOIN #__adv AS a ON (a.adv_id = c.adv_id AND a.status = '1')
WHERE c.adv_group_id = ".(int) $group['adv_group_id']."
AND c.cat_id = ".$category.$limit);
if ($db->affected_rows()) {
$advs = $db->fetch_rows();
$cache->store('category_adv_'.$category, $advs, 0);
}
}
if ($advs) {
$count = (count($advs)-1);
$index = ($group['adv_rotate'] == '1') ? rand(0, $count) : 0;
$adv = $advs[$index];
return display_adv($adv);
}
}
}
}
if (!$group = $cache->get('group_video-player-default', 86400)) {
$db->query("SELECT adv_group_id, adv_rotate
FROM #__adv_groups
WHERE adv_group_slug = '".$db->escape('video-player-default')."'
AND status = '1'
LIMIT 1");
if (!$db->affected_rows()) {
return;
}
$group = $db->fetch_assoc();
$cache->store('group_video-player-default', $group, 86400);
}
$limit = ($group['adv_rotate'] == '0') ? ' LIMIT 1' : '';
if (!$advs = $cache->get('video-player-default', 86400)) {
$db->query("SELECT adv_id, title, description, type, url, code,
image_type, image_url, image_ext, expire, blank
FROM #__adv
WHERE adv_group_id = ".(int) $group['adv_group_id']."
AND status = '1'".$limit);
if (!$db->affected_rows()) {
return;
}
$advs = $db->fetch_rows();
$cache->store('video-player-default', $advs, 86400);
}
$count = (count($advs)-1);
$index = ($group['adv_rotate'] == '1') ? rand(0, $count) : 0;
$adv = $advs[$index];
return display_adv($adv);
}
function display_adv($adv)
{
if ($adv['expire'] != '0000-00-00') {
$current_timestamp = time();
$expire_timestamp = strtotime($adv['expire']);
if ($current_timestamp > $expire_timestamp) {
return;
}
}
VF::factory('database')->query("UPDATE #__adv SET views = views+1 WHERE adv_id = ".$adv['adv_id']." LIMIT 1");
$rel = ' rel="nofollow"';
if ($adv['type'] == 'html') {
return '<div class="ads-player">'.$adv['code'].'</div>';
} elseif ($adv['type'] == 'text') {
$title = ($adv['description'] != '') ? 'title="'.htmlspecialchars($adv['description'], ENT_QUOTES, 'UTF-8').'"' : '';
$target = ($adv['blank'] == '1') ? ' target="_blank"' : '';
return '<div class="ads-player"><a href="'.BASE_URL.'/adv/'.$adv['adv_id'].'/"'.$rel.$title.$blank.'>'.htmlspecialchars($adv['title'], ENT_QUOTES, 'UTF-8').'</a></div>';
} elseif ($adv['type'] == 'image') {
$image_url = ($adv['image_type'] == 'url') ? $adv['image_url'] : MEDIA_URL.'/banners/'.$adv['adv_id'].'.'.$adv['image_ext'];
$target = ($adv['blank'] == '1') ? ' target="_blank"' : '';
return '<div class="ads-player"><a href="'.BASE_URL.'/adv/'.$adv['adv_id'].'/"'.$rel.$target.'><img src="'.$image_url.'" alt="" /></a></div>';
}
}