<?PHP
/*
=====================================================
Count Field News
-----------------------------------------------------
Author : PunPun
-----------------------------------------------------
Site : https://punpun.name/
-----------------------------------------------------
Copyright (c) 2018 PunPun
=====================================================
Данный код защищен авторскими правами
*/
defined("DATALIFEENGINE") || die("go your way stalker");
$xfield = $db->safesql(strip_tags(stripslashes(trim($xfield))));
$value = $value ? $db->safesql(strip_tags(stripslashes(trim($value)))) : false;
if (!$value) {
return;
}
$is_change = false;
if (!$config['allow_cache']) {
$config['allow_cache'] = 1;
$is_change = true;
}
$cache_count_xfield = dle_cache("news_count_xfield", $config['skin'] . $xfield . $value);
if ($cache_count_xfield) {
echo $cache_count_xfield;
} else {
$thisdate = date("Y-m-d H:i:s", time());
if ($config['no_date'] AND !$config['news_future']) {
$where_date = " AND date < '" . $thisdate . "'";
} else {
$where_date = '';
}
$xf_sql = "SUBSTRING_INDEX(SUBSTRING_INDEX(xfields, '{$xfield}|', -1), '||', 1) LIKE '%{$value}%'";
$count = $db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_post WHERE {$xf_sql} AND SUBSTRING_INDEX(SUBSTRING_INDEX(xfields, '{$xfield}|', -1), '||', 1) NOT LIKE '%|%' AND approve='1'" . $where_date);
echo $count['count'];
create_cache("news_count_xfield", $count['count'], $config['skin'] . $xfield . $value);
}
if ($is_change) {
$config['allow_cache'] = false;
}