File size: 3.55Kb
<?php
class gchat
{
var $room;
var $page;
var $clientVersion = 2109;
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)."'>".filtOut ($post->user_nick)."</a> ".(intval ($post->user_id) > 0?'[ID'.intval ($post->user_id).']':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 (defined ('USER_ID'))
$result = "
<form method='post' action='?room=$this->room'>
<input type='text' name='msg' ".(isset ($_GET['answer'])?'value="[b]'.filtOut (@$_GET['answer']).'[/b], "':null)." autofocus='1' /><input type='submit' name='send' value='Send' /></form>";
else
$result = '<img src="icons/error.png" alt="" /> Писать могут только зарегистрированные пользователи';
return $result;
}
}
function navigation ()
{
$result = null;
$result .= "<a href='?room=$this->room&u=".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;
}
}