Файл: adultscript-2.0.3-pro/files/templates/defboot/extend/plugins/adv_category.plugin.php
Строк: 46
<?php
defined('_VALID') or die('Restricted Access!');
function template_plugin_adv_category($slug, $categories, $square=FALSE)
{
if (VF::cfg_item('ads') === 0) {
return;
}
if (is_string($categories) OR is_numeric($categories)) {
$categories = explode(',', $categories);
}
$db = VF::factory('database');
$cache = VF::factory('cache');
if (!$group = $cache->get('group_'.$slug, 86400)) {
$db->query("SELECT adv_group_id, adv_rotate
FROM #__adv_groups
WHERE adv_group_slug = '".$db->escape($slug)."'
AND status = '1'
LIMIT 1");
if (!$db->affected_rows()) {
return;
}
$group = $db->fetch_assoc();
$cache->store('group_'.$slug, $group, 86400);
}
$limit = ($group['adv_rotate'] == '0') ? ' LIMIT 1' : '';
foreach ($categories as $category) {
if (!$advs = $cache->get($slug.'_'.$category, 86400)) {
$db->query("SELECT a.adv_id, a.title, a.description, a.type, a.url, a.code,
a.image_type, a.image_url, a.image_ext, a.expire, a.blank
FROM #__adv_category AS c
INNER JOIN #__adv AS a ON (a.adv_id = c.adv_id)
WHERE c.adv_group_id = ".(int) $group['adv_group_id']."
AND c.cat_id = ".(int) $category.$limit);
if ($db->affected_rows()) {
$advs = $db->fetch_rows();
$cache->store($slug.'_'.$category, $advs, 86400);
}
}
if ($advs) {
$count = (count($advs)-1);
$index = ($group['adv_rotate'] == '1') ? rand(0, $count) : 0;
$adv = $advs[$index];
if ($adv['expire'] === '0000-00-00' OR
time() < strtotime($adv['expire'])) {
$db->query("UPDATE #__adv SET views = views+1 WHERE adv_id = ".(int) $adv['adv_id']." LIMIT 1");
return display_adv_category($adv, $square);
}
}
}
if (!$advs = $cache->get($slug, 86400)) {
$db->query("SELECT a.adv_id, a.title, a.description, a.type, a.url, a.code,
a.image_type, a.image_url, a.image_ext, a.expire
FROM #__adv_groups AS g
INNER JOIN #__adv AS a ON (a.adv_group_id = g.adv_group_id AND a.status = '1')
WHERE g.adv_group_id = ".(int) $group['adv_group_id'].$limit);
if ($db->affected_rows()) {
$advs = $db->fetch_rows();
$cache->store($slug, $advs, 86400);
}
if ($advs) {
$count = (count($advs)-1);
$index = ($group['adv_rotate'] == '1') ? rand(0, $count) : 0;
$adv = $advs[$index];
if ($adv['expire'] === '0000-00-00' OR
time() < strtotime($adv['expire'])) {
$db->query("UPDATE #__adv SET views = views+1 WHERE adv_id = ".(int) $adv['adv_id']." LIMIT 1");
return display_adv_category($adv, $square);
}
}
}
}
function display_adv_category($adv, $square=FALSE)
{
$rel = ' rel="nofollow"';
$class = ($square !== FALSE) ? 'ads-square' : 'ads';
if ($adv['type'] == 'html') {
return '<div class="'.$class.'">'.$adv['code'].'</div>';
} elseif ($adv['type'] == 'text') {
$title = ($adv['description'] != '') ? ' title="'.e($adv['description']).'"' : '';
$target = ($adv['blank'] == '1') ? ' target="_blank"' : '';
return '<div class="'.$class.'"><a href="'.BASE_URL.'/adv/'.$adv['adv_id'].'/"'.$rel.$title.$blank.'>'.e($adv['title']).'</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="'.$class.'"><a href="'.BASE_URL.'/adv/'.$adv['adv_id'].'/"'.$rel.$target.'><img src="'.$image_url.'" alt="" /></a></div>';
}
}