Получилась некоторая доработка Хака Продвинутый вывод рейтинговых новостей....
Немного по другому решен.
Добавлена Возможность вывода topnews из определённых категорий.
Добавлена возможность работы с ЧПУ
адаптировано под 8.х, проверено на 8.2. На других тоже должен пахать.
демо: http://donbass.name
в index.php перед
Добавляем
if ( stristr( $tpl->copy_template, "{topnews" ) ) {
$tpl->copy_template = preg_replace( "#\\{topnews category=['\"](.+?)['\"]\\}#ies", "topnews_print('\\1')", $tpl->copy_template );
}
и в файле engine/modules/functions.php перед
добавляем функцию
function topnews_print ($custom_category){
global $db;
$custom_category = $db->safesql(str_replace(',', '|', $custom_category));
if(!defined('DATALIFEENGINE'))
{
die("Hacking attempt!");
}
$topnews = dle_cache("topnews", $config['skin']);
if (!$topnews) {
$this_month = date ('Y-m-d', time()-(3600*24*27));
$db->query("SELECT id, title, short_story, date, alt_name FROM " . PREFIX . "_post WHERE approve='1' AND category regexp '[[::]]' AND date >= '$this_month'AND date < '$this_month' + INTERVAL 1 MONTH ORDER BY rating DESC, comm_num DESC, news_read DESC, date DESC LIMIT 0,5");
while($row = $db->get_row()){
$row['date'] = strtotime($row['date']);
if (strlen($row['title']) > 55)
$title = substr ($row['title'], 0, 55)." ...";
else
$title = $row['title'];
$go_page = ($config['ajax']) ? "onclick=\"DlePage('newsid=".$row['id']."'); return false;\" " : "";
if ($config['allow_alt_url'] == "yes")
$link = "<a>".stripslashes($title)."</a>";
else
$link = "<a>".stripslashes($title)."</a>";
$topnews .= "» ".$link."
";
preg_match('|]*>|is', $row['short_story'], $pts);
$thumba_parts = pathinfo($pts[2]);
$titla = stripslashes($row['title']);
if($pts[2]){
$pictitle = stripslashes( $row['title'] );
$pic = $thumba_parts['dirname'].'/'.$thumba_parts['basename'];
$wide = str_replace('thumbs/', "", $pic);
if(file_exists($wide)) $preview = "[url=http://$wide][img=|$pictitle]$pic[/img][/url]";
else $preview = "[img=|$pictitle]$pic[/img]";
}
else $preview = "<img style="border: medium none;" src="{THEME}/images/nothumb.gif" width="1px" height="1px" />";
$row['short_story'] = preg_replace("/\[attachment=[[:digit:]]*\]/si","",stripslashes($row['short_story']));
$row['short_story'] = preg_replace("/<!--*-->/si","",$row['short_story']);
$row['short_story'] = strip_tags($row['short_story']);
if( strlen( $row['short_story'] ) > 106 ) $row['short_story'] = substr( $row['short_story'], 0,106 ) . " ... <a style="font-size:12px">Читать далее »</a>";
$topnews .= '<table width="98%" border="0" style="border-bottom: 1px dotted #E1E1E1;">
<td width="1" height="1 align=" valign="top">'.$preview.'</td>
<td width="98%" valign="top" style="padding-left: 1px; padding-bottom: 1px; font-size:13px">
'.stripslashes($row['short_story']).'</td>
</tr>
</table>';
}
$db->free();
create_cache ("topnews", $topnews, $config['skin']);
}
return $topnews;
}
популярные новости выводим тегом {topnews category="ID категории"}
пример: {topnews category="1,2,3"}
Всё
$config['http_home_url'] = explode ( "index.php", strtolower ( $_SERVER['PHP_SELF'] ) );
Добавляем
if ( stristr( $tpl->copy_template, "{topnews" ) ) {
$tpl->copy_template = preg_replace( "#\\{topnews category=['\"](.+?)['\"]\\}#ies", "topnews_print('\\1')", $tpl->copy_template );
}
и в файле engine/modules/functions.php перед
function langdate($format, $stamp) {
добавляем функцию
function topnews_print ($custom_category){
global $db;
$custom_category = $db->safesql(str_replace(',', '|', $custom_category));
if(!defined('DATALIFEENGINE'))
{
die("Hacking attempt!");
}
$topnews = dle_cache("topnews", $config['skin']);
if (!$topnews) {
$this_month = date ('Y-m-d', time()-(3600*24*27));
$db->query("SELECT id, title, short_story, date, alt_name FROM " . PREFIX . "_post WHERE approve='1' AND category regexp '[[::]]' AND date >= '$this_month'AND date < '$this_month' + INTERVAL 1 MONTH ORDER BY rating DESC, comm_num DESC, news_read DESC, date DESC LIMIT 0,5");
while($row = $db->get_row()){
$row['date'] = strtotime($row['date']);
if (strlen($row['title']) > 55)
$title = substr ($row['title'], 0, 55)." ...";
else
$title = $row['title'];
$go_page = ($config['ajax']) ? "onclick=\"DlePage('newsid=".$row['id']."'); return false;\" " : "";
if ($config['allow_alt_url'] == "yes")
$link = "<a>".stripslashes($title)."</a>";
else
$link = "<a>".stripslashes($title)."</a>";
$topnews .= "» ".$link."
";
preg_match('|]*>|is', $row['short_story'], $pts);
$thumba_parts = pathinfo($pts[2]);
$titla = stripslashes($row['title']);
if($pts[2]){
$pictitle = stripslashes( $row['title'] );
$pic = $thumba_parts['dirname'].'/'.$thumba_parts['basename'];
$wide = str_replace('thumbs/', "", $pic);
if(file_exists($wide)) $preview = "[url=http://$wide][img=|$pictitle]$pic[/img][/url]";
else $preview = "[img=|$pictitle]$pic[/img]";
}
else $preview = "<img style="border: medium none;" src="{THEME}/images/nothumb.gif" width="1px" height="1px" />";
$row['short_story'] = preg_replace("/\[attachment=[[:digit:]]*\]/si","",stripslashes($row['short_story']));
$row['short_story'] = preg_replace("/<!--*-->/si","",$row['short_story']);
$row['short_story'] = strip_tags($row['short_story']);
if( strlen( $row['short_story'] ) > 106 ) $row['short_story'] = substr( $row['short_story'], 0,106 ) . " ... <a style="font-size:12px">Читать далее »</a>";
$topnews .= '<table width="98%" border="0" style="border-bottom: 1px dotted #E1E1E1;">
<td width="1" height="1 align=" valign="top">'.$preview.'</td>
<td width="98%" valign="top" style="padding-left: 1px; padding-bottom: 1px; font-size:13px">
'.stripslashes($row['short_story']).'</td>
</tr>
</table>';
}
$db->free();
create_cache ("topnews", $topnews, $config['skin']);
}
return $topnews;
}
популярные новости выводим тегом {topnews category="ID категории"}
пример: {topnews category="1,2,3"}
Всё