<?php
/* +--------------------------------------------
* |
* | Product: PHPEchoCMS
* | Author: Tigran Abrahamyan
* | License: GPL
* | Last updated: 03.03.07
* | For version: 2.0
* | Desc: News module
* |
* +--------------------------------------------
*/
if( !@$BASE_LOAD )
{
die('Application error.');
}
function show_news()
{
global $root_path, $smarty, $settings, $core;
// -------------------
// Get lang for module
// -------------------
$mlang = $core->getlang("news");
$content = '';
if ( @$_GET['id'] )
{
$news = query ( "SELECT * FROM ".PREFIX."news WHERE id = '".addslashes($_GET['id'])."'", 4);
if ( $news['id'] )
{
//begin if/else of mod_comments
if ( isset($_GET['act']) && $_GET['act'] == 'moderate' && isset($_SESSION['admin_level']) && $_SESSION['admin_level'] == 1)
{
if(@$_GET['del_id'])
{
query("DELETE FROM ".PREFIX."news_comments WHERE id = '".$_GET['del_id']."'", 1);
}
$modComments = query("SELECT * FROM ".PREFIX."news_comments WHERE news_id = '".$news['id']."'", 1);
if(mysql_num_rows($modComments))
{
$content .= "<table width='100%' cellspacing='0'border='1' cellpadding='5' style='margin: 10px 55px 20px; padding: 0px; height: 60px; background-color: #FFF'>";
$content .= "<caption style='margin-top: 10px; text-decoration: underline;'>Moderate News</caption>";
while(@$delComment = mysql_fetch_array($modComments))
{
$delUrl = "<a href='index.php?modules=news&id=".$news['id']."&act=moderate&del_id=".$delComment['id']."'>delete</a>";
$smarty->assign ( "author", $delComment['author']);
$smarty->assign ( "message", $delComment['message']);
$smarty->assign ( "url", $delUrl);
$content .= $smarty->fetch('modules/mod_news_comments.tpl');
}
$content .= "</table>";
}
else
{
echo "<center><font size='3' color='red'>No comments to delete.</font></center>";
}
}
else
{
$smarty->assign ( "title" , $news['title']);
$smarty->assign ( "author" , $mlang['001'].$news['author']);
$smarty->assign ( "text" , $news['text']."<br />".$news['detailtext']);
$smarty->assign ( "views" , $mlang['003'].$news['views']);
$smarty->assign ( "detailed" , "");
$content .= $smarty->fetch ('modules/news.tpl');
// increment a views counter
query ("UPDATE ".PREFIX."news SET views = views + '1' WHERE id = '".addslashes($_GET['id'])."'", 1);
$content .= "<br /><span style='font-weight: bolder; font-size: 18px; font-height: 2em; line-height: 3em; padding-left: 20px; font-variant: small-caps;'>".$mlang['010']."</span>";
if ( @$_SESSION ['username'] )
{
if ( @$_GET['act'] == "newcomment" )
{
if ( strlen (trim($_POST['comment'])) >= 0 )
{
query ("INSERT INTO ".PREFIX."news_comments VALUES (null, '".htmlentities ( str_replace( "\n", "<br>", addslashes ( $_POST['comment'] ) ) )."', '".$_SESSION ['username']."', '".$news['id']."')", 1);
}
}
}
// comments
$comments = query ( "SELECT * FROM `".PREFIX."news_comments` WHERE `news_id` = '".$news['id']."' ORDER BY `id` DESC", 1);
if (!mysql_num_rows($comments))
{
$content .= "<br><center>".$mlang['008']."</center>";
}
else
{
while (@$comment = mysql_fetch_array ($comments) )
{
$smarty->assign ("author", $comment['author']);
$smarty->assign ("message", stripslashes ( $comment['message'] ) );
$content .= $smarty->fetch ("modules/comments.tpl");
}
if ( isset($_SESSION ['admin_level']) && $_SESSION['admin_level'] == 1)
{
$content .= "<span style='padding-left:23px; font-size: 1.2em;'><a href='index.php?module=news&id=".$news['id']."&act=moderate'>moderate comments</a></span>";
}
}
// display comments box if user's logged in.
if ( @$_SESSION ['username'] )
{
$content .= "
<form action='index.php?module=news&id=".$news['id']."&act=newcomment' method='post'>
<table style='margin-top: 20px; padding-left:20px' cellpadding='0' cellspacing='0'>
<tr><td style='text-decoration:underline; font-size:.8em; color:red;'>
Submit comment:
</td></tr>
<tr><td>
<textarea name='comment' rows='7' cols='50'></textarea>
</td></tr>
<tr><td align='center'>
<input type='submit' value=".$mlang['007'].">
</td></tr>
</table>
</form>
";
}
else
{
$content .="
<center>
<h4 style='margin-top: 20px;'>".$mlang['011']."</h3>
</center>
";
}
}//end if/else of mod_comments
}
else
{
$content .= "<font color='red'>".$mlang['005']."</font>";
}
}
else
{
// -------------------
// Get news data
// -------------------
$numnews = query ( "SELECT * FROM ".PREFIX."news ORDER BY id DESC" , 3); // Number of news
if ( $numnews >= 1 ) $total = intval( ( $numnews - 1 ) / $settings ['numnews'] ) + 1;
else $total = 0;
if ( $total <= 0 )
{
$content = $mlang ['006'];
}
else
{
$page = @$_GET["page"];
if ( $page <= 1 )
{
$page = 1;
}
if ( !isset ($_GET["page"] ) )
{
$page = 1;
}
if ( $page > $total)
{
$page = $total;
}
$start = $page * $settings ['numnews'] - $settings ['numnews'];
$allnews = query ( "SELECT * FROM ".PREFIX."news ORDER BY `id` DESC LIMIT $start, ".$settings ['numnews'] , 1); // Get news data
// -------------------
// Show news
// -------------------
while ( $news = mysql_fetch_array ( $allnews ) )
{
$smarty->assign ( "title" , $news['title']);
$smarty->assign ( "author" , $mlang['001'].$news['author']);
$smarty->assign ( "text" , $news['text']);
$smarty->assign ( "views" , $mlang['003'].$news['views']);
$smarty->assign ( "detailed" , "<a href='index.php?module=news&id=".$news['id']."'>".$mlang['004']."</a>");
$content .= $smarty->fetch ('modules/news.tpl');
}
$content .= "<br /><center>";
$temp = $page - 1;
if ( $page >= 2) $content = $content."<a href='index.php?module=news&page=1'><<</a> ";
if ( $temp != 0) $content = $content."<a href='index.php?module=news&page=$temp'><</a> ";
if ( ( $temp - 1 ) > 0) $content = $content."<a href='index.php?module=news&page=".($temp-1)."'>".($temp-1)."</a> ";
if ( $temp > 0 ) $content = $content."<a href='index.php?module=news&page=$temp'>$temp</a> ";
$content = $content."<b>$page</b>";
$temp = $page+1;
if ( $temp <= $total ) $content = $content." <a href='index.php?module=news&page=$temp'>$temp</a> ";
if ( ( $temp + 1 ) <= $total ) $content = $content."<a href='index.php?module=news&page=".($temp+1)."'>".($temp+1)."</a> ";
if ( $page < $total ) $content = $content."<a href='index.php?module=news&page=$temp'>></a>";
if ( $temp < $total ) $content = $content."<a href='index.php?module=news&page=$total'>>></a>";
$content .= "</center>";
}
}
return $content;
}
echo show_news();
?>