<?php
/*
=====================================================
DataLife Engine - by SoftNews Media Group
-----------------------------------------------------
http://dle-news.ru/
-----------------------------------------------------
Copyright (c) 2004,2008 SoftNews Media Group
=====================================================
Данный код защищен авторскими правами
=====================================================
Файл: show.short.php
-----------------------------------------------------
Назначение: вывод новостей
=====================================================
*/
if(!defined('DATALIFEENGINE'))
{
die("Hacking attempt!");
}
//Disturbed
require_once(ENGINE_DIR.'/modules/show.full.modes.php');
$ProcessFlag = false;
$VideoFlag = false;
$user_query = query_string(strip_tags($_SERVER['QUERY_STRING']), array("cstart", "newsid", "cat", "rndval"));
if($allow_active_news){
if ($config['allow_banner'])
include_once ENGINE_DIR.'/modules/banners.php';
$i = $cstart;
$news_found = FALSE;
if (isset($view_template) AND $view_template == "rss") { }
elseif ($category_id AND $cat_info[$category_id]['short_tpl'] != '') $tpl->load_template($cat_info[$category_id]['short_tpl'].'.tpl');
else $tpl->load_template('shortstory.tpl');
if (strpos ($tpl->copy_template, "[xfvalue_") !== false) $xfound = true; else $xfound = false;
if ($xfound) $xfields = xfieldsload();
if (count($banners) AND $config['allow_banner']) {
$news_c=1;
if (isset($ban_short)) {
//Disturbed
$config['news_number'] = $ColsOnMain*$RowsOnMain;
for($indx=0, $max = sizeof($ban_short['top']), $banners_topz=''; $indx < $max; $indx++)
if ($ban_short['top'][$indx]['zakr']){
$banners_topz.= $ban_short['top'][$indx]['text'];
unset ($ban_short['top'][$indx]);
}
for($indx=0, $max = sizeof($ban_short['cen']), $banners_cenz=''; $indx < $max; $indx++)
if ($ban_short['cen'][$indx]['zakr']){
$banners_cenz.= $ban_short['cen'][$indx]['text'];
unset ($ban_short['cen'][$indx]);
}
for($indx=0, $max = sizeof($ban_short['down']), $banners_downz=''; $indx < $max; $indx++)
if ($ban_short['down'][$indx]['zakr']){
$banners_downz.= $ban_short['down'][$indx]['text'];
unset ($ban_short['down'][$indx]);
}
//Disturbed
//$middle=floor($config['news_number']/2); echo "<!-- $middle -->";
$middle=floor($RowsOnMain/2);
$middle_s= floor(($middle-1)/2);
//$middle_e= floor($middle+(($config['news_number']-$middle)/2)+1); echo "<!-- $middle_e -->";
$middle_e= floor($middle+(($RowsOnMain-$middle)/2)+1);
}
}
$sql_result = $db->query($sql_select);
//Disturbed
$tdflag = 0;
$j = 0;
while($row = $db->get_row($sql_result)){
$news_found = TRUE;
$attachments[] = $row['id'];
$row['date'] = strtotime($row['date']);
//Disturbed
if (isset($middle)) {
if ($news_c==$middle_s*$ColsOnMain){
$tpl->copy_template .= "<tr><td colspan=\"".(2*$ColsOnMain-1)."n\">".bannermass($banners_topz,$ban_short['top'])."</td></tr>";
} else
if ($news_c==$middle*$ColsOnMain){
$tpl->copy_template .= "<tr><td colspan=\"".(2*$ColsOnMain-1)."\">".bannermass($banners_cenz,$ban_short['cen'])."</td></tr>";
}else
if ($news_c==$middle_e*$ColsOnMain){
$tpl->copy_template .= "<tr><td colspan=\"".(2*$ColsOnMain-1)."\">".bannermass($banners_downz,$ban_short['down'])."</td></tr>";
}
$news_c++;
}
//Disturbed
if($j == 0)
$tpl->copy_template = "<tr><td style=\"vertical-align: top;\">".$tpl->copy_template;
$i++;
if (!$row['category']) { $my_cat = "---"; $my_cat_link = "---";} else {
$my_cat = array (); $my_cat_link = array ();
$cat_list = explode (',', $row['category']);
if (count($cat_list) == 1) {
$my_cat[] = $cat_info[$cat_list[0]]['name'];
$my_cat_link = get_categories ($cat_list[0]);
//Disturbed
$ProcessFlag = false;
$VideoFlag = false;
if (in_array($cat_list[0], $ProcessedCategories))
$ProcessFlag = true;
if (in_array($cat_list[0], $VideoCategories))
$VideoFlag = true;
} else {
//Disturbed
$ProcessFlag = false;
$VideoFlag = false;
foreach ($cat_list as $element) {
if ($element) { $my_cat[] = $cat_info[$element]['name']; if ($config['ajax']) $go_page = "onclick=\"DlePage('do=cat&category={$cat_info[$element]['alt_name']}'); return false;\" "; else $go_page = "";
if ($config['allow_alt_url'] == "yes")
$my_cat_link[] = "<a {$go_page}href=\"".$config['http_home_url'].get_url($element)."/\">{$cat_info[$element]['name']}</a>";
else
$my_cat_link[] = "<a {$go_page}href=\"$PHP_SELF?do=cat&category={$cat_info[$element]['alt_name']}\">{$cat_info[$element]['name']}</a>";
}
//Disturbed
if (in_array($element, $ProcessedCategories))
$ProcessFlag = true;
if (in_array($element, $VideoCategories))
$VideoFlag = true;
}
$my_cat_link = implode (', ', $my_cat_link);
}
$my_cat = implode (', ', $my_cat);
}
$row['category'] = intval ($row['category']);
include(ENGINE_DIR.'/tags/tags.story.php');
$news_find = array(
'{news-tags}' => $tags_links,
'{comments-num}' => $row['comm_num'],
'{views}' => $row['news_read'],
'{category}' => $my_cat,
'{link-category}' => $my_cat_link,
'{news-id}' => $row['id'],
'{PAGEBREAK}' => '',
);
$tpl->set('', $news_find);
if ($cat_info[$row['category']]['icon']) {
$tpl->set('{category-icon}', $cat_info[$row['category']]['icon']);
} else {
$tpl->set('{category-icon}', "{THEME}/dleimages/no_icon.gif");
}
if (date(Ymd, $row['date']) == date(Ymd, $_TIME)) {
$tpl->set('{date}', $lang['time_heute'].langdate(", H:i", $row['date']));
} elseif (date(Ymd, $row['date']) == date(Ymd, ($_TIME - 86400))) {
$tpl->set('{date}', $lang['time_gestern'].langdate(", H:i", $row['date']));
} else {
$tpl->set('{date}', langdate($config['timestamp_active'], $row['date']));
}
if ($row['allow_rate']) {
if ($config['short_rating'] AND $user_group[$member_id['user_group']]['allow_rating'])
$tpl->set('{rating}',ShortRating ($row['id'],$row['rating'], $row['vote_num'], 1));
else
$tpl->set('{rating}',ShortRating ($row['id'],$row['rating'], $row['vote_num'], 0));
} else
$tpl->set('{rating}',"");
if ($config['ajax']) {
$go_page = "onclick=\"DlePage(\'subaction=userinfo&user=".urlencode($row['autor'])."\'); return false;\" ";
$news_page = "onclick=\"DlePage(\'subaction=allnews&user=".urlencode($row['autor'])."\'); return false;\" ";
} else { $go_page = ""; $news_page = "";}
if ($config['allow_alt_url'] == "yes") {
$go_page .= "href=\"".$config['http_home_url']."user/".urlencode($row['autor'])."/\"";
$news_page .= "href=\"".$config['http_home_url']."user/".urlencode($row['autor'])."/news/\"";
} else {
$go_page .= "href=\"$PHP_SELF?subaction=userinfo&user=".urlencode($row['autor'])."\"";
$news_page .= "href=\"$PHP_SELF?subaction=allnews&user=".urlencode($row['autor'])."\"";
}
$go_page = "onClick=\"return dropdownmenu(this, event, UserNewsMenu('".htmlspecialchars($go_page)."', '".htmlspecialchars($news_page)."','".urlencode($row['autor'])."', '".$member_id['user_group']."'), '170px')\" onMouseout=\"delayhidemenu()\"";
if ($config['allow_alt_url'] == "yes")
$tpl->set('{author}', "<a {$go_page} href=\"".$config['http_home_url']."user/".urlencode($row['autor'])."/\">".$row['autor']."</a>");
else
$tpl->set('{author}', "<a {$go_page} href=\"$PHP_SELF?subaction=userinfo&user=".urlencode($row['autor'])."\">".$row['autor']."</a>");
if ($allow_userinfo AND !$row['approve'] AND ($member_id['name'] == $row['autor'] AND !$user_group[$member_id['user_group']]['allow_all_edit'])){
$tpl->set('[edit]',"<a href=\"".$config['http_home_url']."index.php?do=addnews&id=".$row['id']."\" >");
$tpl->set('[/edit]',"</a>");
}
elseif ($is_logged AND (($member_id['name'] == $row['autor'] AND $user_group[$member_id['user_group']]['allow_edit']) OR $user_group[$member_id['user_group']]['allow_all_edit'])){
$_SESSION['referrer'] = $_SERVER['REQUEST_URI'];
$tpl->set('[edit]',"<a onClick=\"return dropdownmenu(this, event, MenuNewsBuild('".$row['id']."', 'short'), '170px')\" href=\"".$config['http_home_url'].$config['admin_path']."?mod=editnews&action=editnews&id=".$row['id']."\" target=\"_blank\">");
$tpl->set('[/edit]',"</a>");
}
else $tpl->set_block("'\\[edit\\](.*?)\\[/edit\\]'si","");
$go_page = ($config['ajax']) ? "onclick=\"DlePage('newsid=".$row['id']."'); return false;\" " : "";
if ($config['allow_comments_wysiwyg'] == "yes") $go_page = '';
if ($config['allow_alt_url'] == "yes") {
if ($row['flag']) {
if ($row['category']) {
$full_link = $config['http_home_url'].get_url($row['category'])."/".$row['id']."-".$row['alt_name'].".html";
} else {
$full_link = $config['http_home_url'].$row['id']."-".$row['alt_name'].".html";
}
} else {
$full_link = $config['http_home_url'].date('Y/m/d/', $row['date']).$row['alt_name'].".html";
}
} else {
$full_link = $config['http_home_url']."index.php?newsid=".$row['id'];
}
if ((strlen($row['full_story']) < 10) and $config['hide_full_link'] == "yes")
$tpl->set_block("'\\[full-link\\](.*?)\\[/full-link\\]'si","");
else {
$tpl->set('[full-link]',"<a {$go_page}href=\"".$full_link."\">");
$tpl->set('[/full-link]',"</a>");
}
if ($row['allow_comm']) {
$tpl->set('[com-link]',"<a {$go_page}href=\"".$full_link."#comment\">");
$tpl->set('[/com-link]',"</a>");
} else $tpl->set_block("'\\[com-link\\](.*?)\\[/com-link\\]'si","");
if ( strpos( $tpl->copy_template, "[group=" ) !== false ) {
$tpl->copy_template = preg_replace( "#\\[group=(.+?)\\](.*?)\\[/group\\]#ies","check_group('\\1', '\\2')", $tpl->copy_template);
}
if ( strpos( $tpl->copy_template, "[not-group=" ) !== false) {
$tpl->copy_template = preg_replace( "#\\[not-group=(.+?)\\](.*?)\\[/not-group\\]#ies","check_group('\\1', '\\2', false)", $tpl->copy_template);
}
if ( strpos( $tpl->copy_template, "[category=" ) !== false) {
$tpl->copy_template = preg_replace( "#\\[category=(.+?)\\](.*?)\\[/category\\]#ies","check_category('\\1', '\\2', '{$category_id}')", $tpl->copy_template);
}
if ( strpos( $tpl->copy_template, "[not-category=" ) !== false) {
$tpl->copy_template = preg_replace( "#\\[not-category=(.+?)\\](.*?)\\[/not-category\\]#ies","check_category('\\1', '\\2', '{$category_id}', false)", $tpl->copy_template);
}
if ($is_logged){
if (!strstr ($member_id['favorites'], $row['id']) OR $config['allow_cache'] == "yes")
$tpl->set('{favorites}',"<a id=\"fav-id-".$row['id']."\" href=\"$PHP_SELF?do=favorites&doaction=add&id=".$row['id']."\"><img src=\"".$config['http_home_url']."templates/{$config['skin']}/dleimages/plus_fav.gif\" onclick=\"doFavorites('".$row['id']."', 'plus'); return false;\" title=\"".$lang['news_addfav']."\" align=\"absmiddle\" border=\"0\"></a>");
else
$tpl->set('{favorites}',"<a id=\"fav-id-".$row['id']."\" href=\"$PHP_SELF?do=favorites&doaction=del&id=".$row['id']."\"><img src=\"".$config['http_home_url']."templates/{$config['skin']}/dleimages/minus_fav.gif\" onclick=\"doFavorites('".$row['id']."', 'minus'); return false;\" title=\"".$lang['news_minfav']."\" align=\"absmiddle\" border=\"0\"></a>");
} else $tpl->set('{favorites}',"");
if ($allow_userinfo AND !$row['approve']) {
$tpl->set('{approve}', $lang['approve']);
} else $tpl->set('{approve}',"");
// Обработка дополнительных полей
if ($xfound) {
$xfieldsdata = xfieldsdataload ($row['xfields']);
foreach ($xfields as $value) {
$preg_safe_name = preg_quote($value[0], "'");
if (empty($xfieldsdata[$value[0]])) {
$tpl->copy_template = preg_replace("'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template);
} else {
$tpl->copy_template = preg_replace("'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template);
}
$tpl->copy_template = str_replace("[xfvalue_{$preg_safe_name}]", stripslashes($xfieldsdata[$value[0]]), $tpl->copy_template);
}
}
// Обработка дополнительных полей
if ($view_template == "rss") {
$tpl->set('{rsslink}', $full_link);
$tpl->set('{rssauthor}', $row['autor']);
$tpl->set('{rssdate}', date("r", $row['date']));
$tpl->set('{title}', htmlspecialchars(strip_tags(stripslashes($row['title']))));
if ($config['rss_format'] != 1) {
$row['short_story'] = htmlspecialchars(strip_tags(stripslashes(str_replace("<br />", " ", $row['short_story']))));
} else {
$row['short_story'] = stripslashes($row['short_story']);
}
$tpl->set('{short-story}', $row['short_story']);
if ($config['rss_format'] == 2) {
$row['full_story'] = htmlspecialchars(strip_tags(stripslashes($row['full_story'])));
if ($row['full_story'] == "") $row['full_story'] = $row['short_story'];
$tpl->set('{full-story}', $row['full_story']);
}
} else {
$tpl->set('{title}', stripslashes($row['title']));
//$tpl->set('{title}', "<a href=\"".$full_link."\">".stripslashes($row['title'])."</a>");
//Disturbed
if (!$VideoFlag)
$row['short_story'] = ResizeThumbs($row['short_story']);
if ($ProcessFlag)
{
$tpl->set('{short-story}', stripslashes("<div id='news-id-".$row['id']."'>".$row['short_story']."</div>")."<br/><div align=\"center\">Виды просмотра:<br/>".ShowModes($full_link)."</div>");
}
else
$tpl->set('{short-story}', stripslashes("<div id='news-id-".$row['id']."'>".$row['short_story']."</div>"));
//$tpl->set('{short-story}', stripslashes("<div id='news-id-".$row['id']."'>".$row['short_story']."</div>"));
}
if ($user_group[$member_id['user_group']]['allow_hide']) $tpl->set_block("'\[hide\](.*?)\[/hide\]'si","\\1");
else $tpl->set_block("'\\[hide\\](.*?)\\[/hide\\]'si","<div class=\"quote\">".$lang['news_regus']."</div>");
//Disturbed
if ($j<$ColsOnMain-1)
{
$tpl->copy_template .= "</td><td> </td><td style=\"vertical-align: top;\">";
$j++;
}
else
{
$tpl->copy_template .= "</td></tr>";
$j = 0;
}
$tpl->compile('content');
}
//Disturbed
$tpl->result["content"] = "<table width=\"100%\" cellspasing=\"1\" celpadding=\"1\"><tr><td style=\"vertical-align: top;\">".$tpl->result["content"]."</td></tr></table>";
$tpl->clear();
$db->free($sql_result);
if ($do=="") $do = $subaction;
if ($do=="" AND $year) $do = "date";
$ban_short = array(); unset($ban_short);
if (!$news_found AND $allow_userinfo AND $member_id['name'] == $user AND $user_group[$member_id['user_group']]['allow_adds']) {
$tpl->load_template('info.tpl');
$tpl->set('{error}', $lang['mod_list_f']);
$tpl->set('{title}', $lang['all_info']);
$tpl->compile('content');
$tpl->clear();
}
elseif (!$news_found AND !$allow_userinfo AND $do != '' AND $do != 'favorites') { @header("HTTP/1.0 404 Not Found"); msgbox ($lang['all_err_1'], $lang['news_err_27']); }
elseif (!$news_found AND $catalog != "") { @header("HTTP/1.0 404 Not Found"); msgbox ($lang['all_err_1'], $lang['news_err_27']); }
elseif (!$news_found AND $do == 'favorites') msgbox ($lang['all_info'], $lang['fav_notfound']);
//####################################################################################################################
// Навигация по новостям
//####################################################################################################################
if (!isset($view_template)) $tpl->load_template('navigation.tpl');
//----------------------------------
// Previous link
//----------------------------------
$no_prev = false;
$no_next = false;
if(isset($cstart) and $cstart != "" and $cstart > 0){
$prev = $cstart / $config['news_number'];
if ($config['ajax']) $go_page = "onclick=\"DlePage('cstart=".$prev."&".$user_query."'); return false;\" "; else $go_page = "";
if ($config['allow_alt_url'] == "yes") {
$prev_page = $url_page."/page/".$prev."/";
$tpl->set_block("'\[prev-link\](.*?)\[/prev-link\]'si", "<a {$go_page}href=\"".$prev_page."\">\\1</a>");
} else {
$prev_page = $PHP_SELF."?cstart=".$prev."&".$user_query;
$tpl->set_block("'\[prev-link\](.*?)\[/prev-link\]'si", "<a {$go_page}href=\"".$prev_page."\">\\1</a>");
}
}else{ $tpl->set_block("'\[prev-link\](.*?)\[/prev-link\]'si", "<span>\\1</span>"); $no_prev = TRUE; }
//----------------------------------
// Pages
//----------------------------------
if($config['news_number']){
$row = $db->super_query($sql_count);
$count_all = $row['count'];
$pages_count = @ceil($count_all/$config['news_number']);
$pages_start_from = 0;
$pages = "";
$pages_per_section = 3;
if($pages_count > 10)
{
for($j = 1; $j <= $pages_per_section; $j++)
{
if($pages_start_from != $cstart)
{
if ($config['ajax']) $go_page = "onclick=\"DlePage('cstart=".$j."&".$user_query."'); return false;\" "; else $go_page = "";
if ($config['allow_alt_url'] == "yes")
$pages .= "<a {$go_page}href=\"".$url_page."/page/".$j."/\">$j</a> ";
else
$pages .= "<a {$go_page}href=\"$PHP_SELF?cstart=$j&$user_query\">$j</a> ";
} else
{
$pages .= " <span>$j</span> ";
}
$pages_start_from += $config['news_number'];
}
if(((($cstart / $config['news_number']) + 1) > 1) && ((($cstart / $config['news_number']) + 1) < $pages_count))
{
$pages .= ((($cstart / $config['news_number']) + 1) > ($pages_per_section + 2)) ? '... ' : ' ';
$page_min = ((($cstart / $config['news_number']) + 1) > ($pages_per_section + 1)) ? ($cstart / $config['news_number']) : ($pages_per_section + 1);
$page_max = ((($cstart / $config['news_number']) + 1) < ($pages_count - ($pages_per_section + 1))) ? (($cstart / $config['news_number']) + 1) : $pages_count - ($pages_per_section + 1);
$pages_start_from = ($page_min - 1) * $config['news_number'];
for($j = $page_min; $j < $page_max + ($pages_per_section - 1); $j++)
{
if($pages_start_from != $cstart)
{
if ($config['ajax']) $go_page = "onclick=\"DlePage('cstart=".$j."&".$user_query."'); return false;\" "; else $go_page = "";
if ($config['allow_alt_url'] == "yes")
$pages .= "<a {$go_page}href=\"".$url_page."/page/".$j."/\">$j</a> ";
else
$pages .= "<a {$go_page}href=\"$PHP_SELF?cstart=$j&$user_query\">$j</a> ";
}
else
{
$pages .= " <span>$j</span> ";
}
$pages_start_from += $config['news_number'];
}
$pages .= ((($cstart / $config['news_number']) + 1) < $pages_count - ($pages_per_section + 1)) ? '... ' : ' ';
}
else
{
$pages .= '... ';
}
$pages_start_from = ($pages_count - $pages_per_section) * $config['news_number'];
for($j=($pages_count - ($pages_per_section - 1)); $j <= $pages_count; $j++)
{
if($pages_start_from != $cstart)
{
if ($config['ajax']) $go_page = "onclick=\"DlePage('cstart=".$j."&".$user_query."'); return false;\" "; else $go_page = "";
if ($config['allow_alt_url'] == "yes")
$pages .= "<a {$go_page}href=\"".$url_page."/page/".$j."/\">$j</a> ";
else
$pages .= "<a {$go_page}href=\"$PHP_SELF?cstart=$j&$user_query\">$j</a> ";
}
else
{
$pages .= " <span>$j</span> ";
}
$pages_start_from += $config['news_number'];
}
}
else
{
for($j=1;$j<=$pages_count;$j++)
{
if($pages_start_from != $cstart)
{
if ($config['ajax']) $go_page = "onclick=\"DlePage('cstart=".$j."&".$user_query."'); return false;\" "; else $go_page = "";
if ($config['allow_alt_url'] == "yes")
$pages .= "<a {$go_page}href=\"".$url_page."/page/".$j."/\">$j</a> ";
else
$pages .= "<a {$go_page}href=\"$PHP_SELF?cstart=$j&$user_query\">$j</a> ";
}
else
{
$pages .= " <span>$j</span> ";
}
$pages_start_from += $config['news_number'];
}
}
$tpl->set('{pages}', $pages);
}
//----------------------------------
// Next link
//----------------------------------
if($config['news_number'] < $count_all and $i < $count_all){
$next_page = $i / $config['news_number'] + 1;
if ($config['ajax']) $go_page = "onclick=\"DlePage('cstart=".$next_page."&".$user_query."'); return false;\" "; else $go_page = "";
if ($config['allow_alt_url'] == "yes") {
$next = $url_page.'/page/'.$next_page.'/';
$tpl->set_block("'\[next-link\](.*?)\[/next-link\]'si", "<a {$go_page}href=\"".$next."\">\\1</a>");
} else {
$next = $PHP_SELF."?cstart=".$next_page."&".$user_query;
$tpl->set_block("'\[next-link\](.*?)\[/next-link\]'si", "<a {$go_page}href=\"".$next."\">\\1</a>");
};
}else{ $tpl->set_block("'\[next-link\](.*?)\[/next-link\]'si", "<span>\\1</span>"); $no_next = TRUE;}
if (!$no_prev OR !$no_next){ $tpl->compile('content'); }
$tpl->clear();
}
?>