Просмотр файла news.php

Размер файла: 12.01Kb
<?php
/**********************************************/
/* Автор скрипта: Александр Есин              */
/* E-Mail: [email protected] ([email protected]) */
/* ICQ: 6464729                               */
/* Site: http://ticlove.ru                    */
/**********************************************/
?>
<?php define ('SECURED', true); ?>
<?php require (dirname(__FILE__).'/_inc/sql.php'); ?>
<?php require (dirname(__FILE__).'/_inc/config.php'); ?>
<?php require (dirname(__FILE__).'/_inc/function.php'); ?>
<?php $title_page = 'Новости сайта'; ?>
<?php $description_page = 'Новости сайта'; ?>
<?php $keywords_page = 'Новости сайта'; ?>
<?php include (dirname(__FILE__).'/include/header.php'); ?>
<div id="block_left">
<?php include (dirname(__FILE__).'/include/lider.php'); ?>
</div>
<div id="content_page">
<div class="tit_zag">Новости сайта</div>
<div class="clear"></div>
<div class="tit_zag_hr"></div>
<?php
$page = isset($_GET['page']) ? $_GET['page'] : NULL;
switch($page)
{
case 'comments':
$news_id = intval($_GET['news_id']);
$sql = mysql_query("SELECT * FROM `q_news` WHERE `id_news` = '".$news_id."' LIMIT 1;");
if (mysql_num_rows($sql) == 0)
{
?>
<script type="text/javascript">
location="news.php";
</script>
<?php
exit;
}
else
{
?>
<?php $array = mysql_fetch_array($sql); ?>
<div style="font-size: 20px; font-family: Georgia; font-style: italic;"><?php echo htmlspecialchars($array['title'], ENT_QUOTES); ?></div>
<div style="color: #8000e6; font-size: 12px;">[<?php echo htmlspecialchars($array['date'], ENT_QUOTES); ?>]</div>
<div style="padding: 0 15px;"><?php echo nl2br(function_smile(htmlspecialchars($array['news'], ENT_QUOTES))); ?></div>
<div>
<?php
$cool_all = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_news_class` WHERE `id_news` = '".$array['id_news']."';"), 0);
$i_cool = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_news_class` WHERE `id_news` = '".$array['id_news']."' AND `id_user` = '".$_SESSION['auth_id']."';"), 0);
?>
<div class="brnews">
<span class="comm_img"></span> Комментариев: <?php echo $array['comments']; ?>&nbsp;&nbsp;
<span class="class_img"></span>
<span id="coolStatus">
<?php
if (isset($_SESSION['auth_id']))
{
if ($i_cool > 0) echo 'Вы'.($cool_all > 1 ? ' и '.($cool_all - 1) : '');
else if ($cool_all > 0) echo $cool_all;
}
else echo $cool_all;
if (isset($_SESSION['auth_id']) && $i_cool == 0) echo ' <a href="javascript:void(0)" onclick="javascript:CoolNews(); return false;">Класс!</a>';
?>
</span>
</div>
<script type="text/javascript">
function CoolNews()
{
xhttp=new XMLHttpRequest();
xhttp.onreadystatechange=function() {
if (xhttp.readyState==4 && xhttp.status==200) document.getElementById('coolStatus').innerHTML=xhttp.responseText;
}
xhttp.open('POST','moduls/cool_news.php',true);
xhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
var str='user_id=<?php echo $_SESSION['auth_id']; ?>&news_id=<?php echo $array['id_news']; ?>';
xhttp.send(str);
document.getElementById('coolStatus').innerHTML = '<img src="/images/ajax.gif" alt="" />';
return false;
}
</script>
</div>
<?php
$col = COMMENTS_PAGE;
if (isset($_GET['start'])) $start = abs(intval($_GET['start']));
else $start = 0;
$count_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_news_comm` WHERE `id_news` = '".$news_id."';"), 0);
if ($count_p > 0) {
echo '<div style="margin: 20px 0 5px 0; font-size: 16px; color: #ff6633; font-weight: bold;">Комментарии ('.$count_p.'):</div>';
if ($start >= $count_p) $start = 0;
$q = mysql_query("SELECT * FROM `q_news_comm` INNER JOIN `q_users` ON `q_users`.`id_user` = `q_news_comm`.`id_user` WHERE `q_news_comm`.`id_news` = '".$news_id."' ORDER BY `q_news_comm`.`id_news_comm` DESC LIMIT ".$start.", ".$col);
$i = 1;
while ($array = mysql_fetch_array($q)) { ?>
<table width="100%" cellspacing="5" cellpadding="0">
<tr>
<td width="65" valign="top">
<a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/id<?php echo $array['id_user']; ?>">
<?php if (!empty($array['avatar'])) { ?>
<img class="<?php echo ($array['vip_status'] == 1 ? 'photo_bor_vip' : 'photo_bor'); ?>" src="<?php echo DIR_PHOTOS; ?>/<?php echo $array['id_user']; ?>/<?php echo $array['avatar']; ?>" alt="" />
<?php } else { ?>
<img class="<?php echo ($array['vip_status'] == 1 ? 'photo_bor_vip' : 'photo_bor'); ?>" src="/images/no_photo_small.png" alt="" />
<?php } ?>
</a><br/>
<?php if (function_online($array['online']) == TRUE) { ?>
 <img src="/images/on.gif" alt="Онлайн" title="Онлайн" />
<?php } ?>
</td>
<td valign="top">
<?php if ($array['vip_status'] == 1) { ?>
<img src="/images/vip.gif" alt="" width="16" height="16" title="VIP-пользователь" /> 
<?php } ?>
<a class="<?php echo ($array['pol'] == 1 ? 'm_color' : 'zh_color'); ?>" href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/id<?php echo $array['id_user']; ?>"><?php echo htmlspecialchars($array['name'], ENT_QUOTES); ?></a>, <span class="vozrast"><?php echo function_vozrast_n($array['god'].'-'.$array['mes'].'-'.$array['day']); ?></span><br/>
<span class="city"><?php echo htmlspecialchars($array['city'], ENT_QUOTES); ?>, <?php echo htmlspecialchars($array['country'], ENT_QUOTES); ?></span><br/>
<span style="font-size: 11px; color: #069de5;">Написал<?php echo ($array['pol'] == 1 ? '' : 'а'); ?> <?php echo function_vizit($array['date_comm']); ?></span><br/>
<?php echo nl2br(function_smile(htmlspecialchars(function_bigword($array['comments'], 45), ENT_QUOTES))); ?>
</td>
</tr>
</table>
<div style="margin: 10px 0; border-top: 5px dotted #ccc; font-size: 16px; color: #ff6633; width: 100%;"></div>
<?php
$i++;
}
page('/news/'.$news_id.'/comments', $col, $start, $count_p, $end_url = '');
} else echo '<div style="font-size: 18px; text-align: center; padding: 30px 0;">К данной новости комментариев нет</div>';
?>
<?php if (isset($_SESSION['auth_id'])) { ?>
<script type="text/javascript">
var ie=document.all?1:0;
var ns=document.getElementById&&!document.all?1:0;

function InsertSmile(SmileId)
{
	      if(ie)
	      {
	           document.all.message.focus();
	           document.all.message.value+=" "+SmileId+" ";
	      }
	      else if(ns)
	      {
	           document.forms['forma'].elements['message'].focus();
	           document.forms['forma'].elements['message'].value+=" "+SmileId+" ";
	      }
	      else alert("Ваш браузер не поддерживается!");
}
</script>
<script type="text/javascript">
$(document).ready(function() {
	$('#add').click(function() {
		$.ajax({
		type: "POST",
		url: "moduls/add_comm_news.php",
		data: { user_id: <? echo $_SESSION['auth_id']; ?>, news_id: <? echo $news_id; ?>, msg: $('#msg').val() },
		beforeSend: function() {
		     $("#comm-status").html('<span class="green">Ваш запрос обрабатывается...</span>');
		},
		success: function(data) {
		     $("#comm-status").fadeIn(700);
		     $("#comm-status").html(data);
		     $("#comm-status").fadeOut(700);
		}
		});
		return false;
	});
});	
</script>
<script type="text/javascript">
function smiles() {
$(document).ready(function() {
     $.arcticmodal({
     type: 'ajax',
     url: 'moduls/smiles.php',
     ajax: {
          type: 'POST',
          data: { user_id: <?php echo $_SESSION['auth_id']; ?> },
          dataType: 'html',
          success: function(data, el, responce) {
               var h = $(responce);
               $('B', h).html(responce.title);
               $('P:last', h).html(responce.text);
               data.body.html(h);
          }
     }
});
});
};
</script>
<div style="background-color: #eee; padding: 20px 10px;">
<div id="comm-status" style="text-align: center;"></div>
<form action="javascript:void(0)" name="forma">
Добавление нового комментария:
<div style="padding: 5px 0;">
<script type="text/javascript">
jQuery.fn.maxlength = function(options) {
		   var settings = jQuery.extend({
		   maxChars: 1000, // максимальное колличество символов
		   leftChars: "символов" // текст в конце строки информера
		   }, options);
		   return this.each(function() {
		   var me = $(this);
		   var l = settings.maxChars;
		   me.bind('keydown keypress keyup',function(e) {
		   if(me.val().length>settings.maxChars) me.val(me.val().substr(0,settings.maxChars));
		   l = settings.maxChars - me.val().length;
		   me.next('span').html(l + ' ' + settings.leftChars);
		   });
		   me.after('Осталось <span class="maxlen">' + settings.maxChars + ' ' + settings.leftChars + '</span>');
		   });
};
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#msg").maxlength();
});
</script>
<textarea style="width:95%; max-width:95%; min-width:95%; padding: 5px;" name="message" id="msg" rows="4" cols="20"></textarea>
</div>
<input type="submit" class="submit" id="add" value="Добавить комментарий" /> <input type="submit" class="submit_green" onclick="javascript:smiles()" value="Смайлики" />
</form>
</div>
<?php } ?>
<div style="padding-top: 10px;"><a href="news.php">Все новости</a></div>
<?php
}
break;


default:
$col = NEWS_PAGE;
if (isset($_GET['start'])) $start = abs(intval($_GET['start']));
else $start = 0;
$count_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_news`;"), 0);
if ($count_p > 0) {
if ($start >= $count_p) $start = 0;
$q = mysql_query("SELECT * FROM `q_news` ORDER BY `id_news` DESC LIMIT ".$start.", ".$col);
while ($array = mysql_fetch_array($q)) { ?>
<div style="font-size: 20px; font-family: Georgia; font-style: italic;"><?php echo htmlspecialchars($array['title'], ENT_QUOTES); ?></div>
<div style="color: #8000e6; font-size: 12px;">[<?php echo htmlspecialchars($array['date'], ENT_QUOTES); ?>]</div>
<div style="padding: 0 15px;"><?php echo nl2br(function_smile(htmlspecialchars($array['news'], ENT_QUOTES))); ?></div>
<div>
<?php
$cool_all = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_news_class` WHERE `id_news` = '".$array['id_news']."';"), 0);
$i_cool = mysql_result(mysql_query("SELECT COUNT(*) FROM `q_news_class` WHERE `id_news` = '".$array['id_news']."' AND `id_user` = '".$_SESSION['auth_id']."';"), 0);
?>
<div class="brnews">
<span class="comm_img"></span><?php echo $array['comments']; ?> <a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/news/<?php echo $array['id_news']; ?>/comments/">Комментировать</a>&nbsp;&nbsp;
<span class="class_img"></span>
<span id="coolStatus<?php echo $array['id_news']; ?>">
<?php
if (isset($_SESSION['auth_id']))
{
if ($i_cool > 0) echo 'Вы'.($cool_all > 1 ? ' и '.($cool_all - 1) : '');
else if ($cool_all > 0) echo $cool_all;
}
else echo $cool_all;
if (isset($_SESSION['auth_id']) && $i_cool == 0) { ?> <a href="javascript:void(0)" onclick="javascript:CoolNews<?php echo $array['id_news']; ?>(); return false;">Класс!</a><?php } ?>
</span>
</div>
<div style="margin: 20px 0 10px 0; border-top: 5px dotted #eee; font-size: 16px; width: 100%;"></div>
<script type="text/javascript">
function CoolNews<?php echo $array['id_news']; ?>()
{
xhttp=new XMLHttpRequest();
xhttp.onreadystatechange=function() {
if (xhttp.readyState==4 && xhttp.status==200) document.getElementById('coolStatus<?php echo $array['id_news']; ?>').innerHTML=xhttp.responseText;
}
xhttp.open('POST','moduls/cool_news.php',true);
xhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
var str='user_id=<?php echo $_SESSION['auth_id']; ?>&news_id=<?php echo $array['id_news']; ?>';
xhttp.send(str);
document.getElementById('coolStatus<?php echo $array['id_news']; ?>').innerHTML = '<img src="/images/ajax.gif" alt="" />';
}
</script>
</div>
<?php } ?>
<?php page('/news', $col, $start, $count_p, $end_url = ''); ?>
<?php } else echo 'Новостей пока нет';
break;
}
?>
</div>
<div class="clear"></div>
<?php include (dirname(__FILE__).'/include/footer.php'); ?>