Подсчёт просмотров новости для одного ip в DLE
1. Хак предоставляет возможность прибавлять к просмотрам новости 1 просмотр с одного айпи.
2. Хак снижает общую нагрузку на бд - обновление бд происходит только тогда когда пользователь просматривает новость в первый раз.
Установка:
1. Через phpmyadmin делаем запрос:
ALTER TABLE `*ПРЕФИКС*_post` ADD `ip_views` TEXT CHARACTER SET cp1251 COLLATE cp1251_general_ci NOT NULL;
где *ПРЕФИКС* - ваш префикс таблиц бд.
2. Находим в engine/engine.php:
if (! $newsid) $sql_news = "SELECT id, autor, date, short_story, full_story, xfields, title, category, descr, keywords, alt_name, comm_num, allow_comm, allow_rate, fixed, rating, vote_num, news_read, approve, votes, access, flag, editdate, editor, reason, view_edit, tags, metatitle FROM " . PREFIX . "_post WHERE alt_name ='$news_name' AND date >= '{$year}-{$month}-{$day}' AND date < '{$year}-{$month}-{$day}' + INTERVAL 24 HOUR LIMIT 0,1";
else $sql_news = "SELECT id, autor, date, short_story, full_story, xfields, title, category, descr, keywords, alt_name, comm_num, allow_comm, allow_rate, fixed, rating, vote_num, news_read, approve, votes, access, flag, editdate, editor, reason, view_edit, tags, metatitle FROM " . PREFIX . "_post where id = '$newsid'";
Меняем на:
if (! $newsid) $sql_news = "SELECT id, autor, date, short_story, full_story, xfields, title, category, descr, keywords, alt_name, comm_num, allow_comm, allow_rate, fixed, rating, vote_num, news_read, approve, votes, access, flag, editdate, editor, reason, view_edit, tags, metatitle, ip_views FROM " . PREFIX . "_post WHERE alt_name ='$news_name' AND date >= '{$year}-{$month}-{$day}' AND date < '{$year}-{$month}-{$day}' + INTERVAL 24 HOUR LIMIT 0,1";
else $sql_news = "SELECT id, autor, date, short_story, full_story, xfields, title, category, descr, keywords, alt_name, comm_num, allow_comm, allow_rate, fixed, rating, vote_num, news_read, approve, votes, access, flag, editdate, editor, reason, view_edit, tags, metatitle, ip_views FROM " . PREFIX . "_post where id = '$newsid'";
3. Находим в engine/modules/show.full.php:
$db->query( "UPDATE " . PREFIX . "_post set news_read=news_read+1 where id='{$row['id']}'" );
Меняем на:
{
$_IP = $db->safesql( $_SERVER['REMOTE_ADDR'] );
$ips=explode(",", $row['ip_views']);
if(!in_array($_IP,$ips)){
if($row['ip_views']=="")
$ip_views=$_IP;
else
$ip_views=$row['ip_views'].",".$_IP;
$db->query( "UPDATE " . PREFIX . "_post set news_read=news_read+1 , ip_views='$ip_views' where id='{$row['id']}'" );
}
}
2. Хак снижает общую нагрузку на бд - обновление бд происходит только тогда когда пользователь просматривает новость в первый раз.
Установка:
1. Через phpmyadmin делаем запрос:
ALTER TABLE `*ПРЕФИКС*_post` ADD `ip_views` TEXT CHARACTER SET cp1251 COLLATE cp1251_general_ci NOT NULL;
где *ПРЕФИКС* - ваш префикс таблиц бд.
2. Находим в engine/engine.php:
if (! $newsid) $sql_news = "SELECT id, autor, date, short_story, full_story, xfields, title, category, descr, keywords, alt_name, comm_num, allow_comm, allow_rate, fixed, rating, vote_num, news_read, approve, votes, access, flag, editdate, editor, reason, view_edit, tags, metatitle FROM " . PREFIX . "_post WHERE alt_name ='$news_name' AND date >= '{$year}-{$month}-{$day}' AND date < '{$year}-{$month}-{$day}' + INTERVAL 24 HOUR LIMIT 0,1";
else $sql_news = "SELECT id, autor, date, short_story, full_story, xfields, title, category, descr, keywords, alt_name, comm_num, allow_comm, allow_rate, fixed, rating, vote_num, news_read, approve, votes, access, flag, editdate, editor, reason, view_edit, tags, metatitle FROM " . PREFIX . "_post where id = '$newsid'";
Меняем на:
if (! $newsid) $sql_news = "SELECT id, autor, date, short_story, full_story, xfields, title, category, descr, keywords, alt_name, comm_num, allow_comm, allow_rate, fixed, rating, vote_num, news_read, approve, votes, access, flag, editdate, editor, reason, view_edit, tags, metatitle, ip_views FROM " . PREFIX . "_post WHERE alt_name ='$news_name' AND date >= '{$year}-{$month}-{$day}' AND date < '{$year}-{$month}-{$day}' + INTERVAL 24 HOUR LIMIT 0,1";
else $sql_news = "SELECT id, autor, date, short_story, full_story, xfields, title, category, descr, keywords, alt_name, comm_num, allow_comm, allow_rate, fixed, rating, vote_num, news_read, approve, votes, access, flag, editdate, editor, reason, view_edit, tags, metatitle, ip_views FROM " . PREFIX . "_post where id = '$newsid'";
3. Находим в engine/modules/show.full.php:
$db->query( "UPDATE " . PREFIX . "_post set news_read=news_read+1 where id='{$row['id']}'" );
Меняем на:
{
$_IP = $db->safesql( $_SERVER['REMOTE_ADDR'] );
$ips=explode(",", $row['ip_views']);
if(!in_array($_IP,$ips)){
if($row['ip_views']=="")
$ip_views=$_IP;
else
$ip_views=$row['ip_views'].",".$_IP;
$db->query( "UPDATE " . PREFIX . "_post set news_read=news_read+1 , ip_views='$ip_views' where id='{$row['id']}'" );
}
}