File size: 4.09Kb
<?php
class gchat
{
var $room;
var $page;
var $clientVersion = '23.02.13';
function __construct ()
{
if (!empty ($_GET['room']))
$this->room = (int) $_GET['room'];
if (empty ($_GET['page']))
$this->page = 1;
else
$this->page = (int) $_GET['page'];
}
function readMsgs ($chatMsgs = null)
{
if (empty ($chatMsgs))
{
echo "<div class='".DIV_SECTION_1."'>GlobalChat временно пуст<br />
Вы можете стать первым :)</div>";
return false;
}
foreach ($chatMsgs AS $post)
{
echo "<div class='".alternDivs (DIV_SECTION_1, DIV_SECTION_2)."'>
<img src='icons/sex_".intval ($post->user_sex).".png' alt='' /> <a href='?room=$this->room&update_mod=2&answer=".filtOut ($post->user_nick)."&answer_user_id=".intval ($post->user_id)."'>".filtOut ($post->user_nick)."</a> ".(intval ($post->user_id) > 0?"[<a href='user_info.php?room=$this->room&user_id=".intval ($post->user_id)."'>ID".intval ($post->user_id)."</a>]":null).' '.processText ($post->msg).'</div>';
}
}
function readRooms ($chatRooms = null)
{
if (empty ($chatRooms))
{
echo "<div class='".DIV_SECTION_1."'>Комнаты временно отсутствуют<br />
Вы можете стать первым :)</div>";
return false;
}
foreach ($chatRooms AS $room)
{
/* print_r ($room); */
echo "<div class='".alternDivs (DIV_SECTION_1, DIV_SECTION_2)."'><a href='?room=$room->id'>
<img src='icons/room.png' alt='' /> $room->name</a><br />";
if (!empty ($room->users))
{
echo "<img src='icons/point.png' alt='' /> ";
foreach ($room->users AS $user)
{
$roomUsers[] = "<a href='?room=$room->id&answer=$user->user_nick'>$user->user_nick</a>";
}
echo implode (', ', $roomUsers).'.';
}
echo '</div>';
}
}
function formMsg ()
{
global $server;
if (empty ($_SESSION['update_mode']))
{
if (USER_ID){
$result = "
<form method='post' action='?room=$this->room'>";
if (!empty ($_GET['answer'])) {
$answerNick = htmlspecialchars ($_GET['answer']);
$result .= "<img src='icons/chat_2.png' alt='' /> Ответ для <a href='user_info.php?room=$this->room&user_id=".intval ($_GET['answer_user_id'])."'>$answerNick</a>:<br />
<input type='hidden' name='answer' value='$answerNick' />";
}
$result .= "<input type='text' name='msg' onclick=\"autoupdate(0)\" onblur=\"autoupdate(1)\" /><input type='submit' name='send' value='Send' onclick=\"autoupdate(0)\" /></form>";
}
else
{
$result = '<div class="'.DIV_MSG.'"> Пожалуйста, зарегистрируйтесь или войдите под своим логином на сайте для использования GlobalChat</div>';
}
return $result;
}
}
function navigation ()
{
$result = null;
$result .= "<a href='?room=$this->room&rand=".rand (1, 3)."&update_mode=2'><img src='icons/update.png' alt='up' /></a> ";
$links = " <a href='?room=$this->room&module=smiles'><img src='icons/smiles.png' alt='' /></a> <a href='?room=$this->room&module=bbcodes'><img src='icons/bbcodes.png' alt='' /></a> ";
if (empty ($_SESSION['update_mode']))
{
$result .= "<a href='?room=$this->room&update_mode=1'><img src='icons/auto_update.png' alt='aup' /></a>$links";
}
else
{
if (!empty ($_GET['update_interval']))
{
if ($_GET['update_interval'] < 3)
$_GET['update_interval'] = 3;
$_SESSION['update_interval'] = (int) $_GET['update_interval'];
}
if (empty ($_SESSION['update_interval']))
$_SESSION['update_interval'] = 10;
header ("Refresh: $_SESSION[update_interval]; url=?room=$this->room&update_mode=1&".rand (1,9));
$result .= "<a href='?room=$this->room&update_mode=2'><img src='icons/auto_update.png' alt='aup' /></a>$links<br />
Интервал обновления: <form method='get' action=''><input type='hidden' name='room' value='$this->room' /><input type='text' size='2' name='update_interval' value='$_SESSION[update_interval]' /> сек <input type='submit' value='Save' /></form>";
}
return $result;
}
}