Просмотр файла gchat/inc/system.php

Размер файла: 7.4Kb
<?php
set_time_limit (3);
ini_set ('error_reporting', E_ALL); 
ini_set ('display_errors', true);
if (empty ($_GET['page']))
$_GET['page'] = 1;
function filtIn ($text = null)
{
return mysql_real_escape_string (strip_tags ($text));
}

function filtOut ($text = null)
{
return htmlspecialchars (strip_tags ($text));
}


/* Форматор времени	 */
function timer ($time, $text = false)
{
if ($time < 60)
	{
	$type = 'секунд(а)';
	}
	elseif ($time < 3540)
	{
	$time = $time/60;
	$type = 'минут(а)';
	}
	elseif ($time < 86340)
	{
	$time = $time / 3600;
	$type = 'час(а)';
	}
	else
	{
	$time = $time/86400;
	$type = 'день';
	}
if ($time < 0)
	$time = 0;
if ($time == 0 && $text == true)
	{
	return 'только что';
	$text = false;
	}
return round ($time).' '.$type.($text?' назад':null);
}

function gBBCodes ($text = null)
{
$BBCodes['/\[i\](.+)\[\/i\]/isU']='<em>$1</em>';
$BBCodes['/\[b\](.+)\[\/b\]/isU']='<strong>$1</strong>';
$BBCodes['/\[u\](.+)\[\/u\]/isU']='<span style="text-decoration:underline;">$1</span>';
$BBCodes['/\[small\](.+)\[\/small\]/isU']='<span style="font-size:small;">$1</span>';
$BBCodes['/\[red\](.+)\[\/red\]/isU']='<span style="color: darkred">$1</span>';
$BBCodes['/\[green\](.+)\[\/green\]/isU']='<span style="color: darkgreen">$1</span>';
$BBCodes['/\[blue\](.+)\[\/blue\]/isU']='<span style="color: darkblue">$1</span>';
$BBCodes['/\[orange\](.+)\[\/orange\]/isU']='<span style="color: darkorange">$1</span>';

return preg_replace (array_keys ($BBCodes), array_values ($BBCodes), $text);
}

function gSmiles ($text)
{
if (!file_exists ('smiles/smile.gif'))
	return $text;
$smiles['<img src="smiles/angry.gif" alt="" />'] = '/(\.angry\.)/i';
$smiles['<img src="smiles/idiot.gif" alt="" />'] = '/(\.idiot\.)/i';
$smiles['<img src="smiles/beat.gif" alt="" />'] = '/(\.beat\.)/i';
$smiles['<img src="smiles/beer.gif" alt="" />'] = '/(\.beer\.)/i';
$smiles['<img src="smiles/blind.gif" alt="" />'] = '/(\.blind\.)|(8\))/i';
$smiles['<img src="smiles/bravo.gif" alt="" />'] = '/(\.bravo\.)/i';
$smiles['<img src="smiles/burum.gif" alt="" />'] = '/(\.burum\.)|(:\|)/i';
$smiles['<img src="smiles/call.gif" alt="" />'] = '/(\.call\.)/i';
$smiles['<img src="smiles/cry.gif" alt="" />'] = '/(\.cry\.)/i';
$smiles['<img src="smiles/sure.gif" alt="" />'] = '/(\.sure\.)/i';
$smiles['<img src="smiles/death.gif" alt="" />'] = '/(\.death\.)/i';
$smiles['<img src="smiles/devil.gif" alt="" />'] = '/(\.devil\.)/i';
$smiles['<img src="smiles/tease.gif" alt="" />'] = '/(\.tease\.)/i';
$smiles['<img src="smiles/drink.gif" alt="" />'] = '/(\.drink\.)/i';
$smiles['<img src="smiles/drunk.gif" alt="" />'] = '/(\.drunk\.)/i';
$smiles['<img src="smiles/foo.gif" alt="" />'] = '/(\.foo\.)/i';
$smiles['<img src="smiles/hammer.gif" alt="" />'] = '/(\.hammer\.)/i';
$smiles['<img src="smiles/heart.gif" alt="" />'] = '/(\.heart\.)/i';
$smiles['<img src="smiles/help.gif" alt="" />'] = '/(\.help\.)/i';
$smiles['<img src="smiles/huh.gif" alt="" />'] = '/(\.huh\.)/i';
$smiles['<img src="smiles/hypnosis.gif" alt="" />'] = '/(\.hypnosis\.)|(\%\))/i';
$smiles['<img src="smiles/kill.gif" alt="" />'] = '/(\.kill\.)/i';
$smiles['<img src="smiles/kiss.gif" alt="" />'] = '/(\.kiss\.)|(:\*)/i';
$smiles['<img src="smiles/music.gif" alt="" />'] = '/(\.music\.)|(\[:\))/i';
$smiles['<img src="smiles/lol.gif" alt="" />'] = '/(\.lol\.)|(:D)/i';
$smiles['<img src="smiles/look.gif" alt="" />'] = '/(\.look\.)/i';
$smiles['<img src="smiles/love.gif" alt="" />'] = '/(\.love\.)/i';
$smiles['<img src="smiles/money.gif" alt="" />'] = '/(\.money\.)/i';
$smiles['<img src="smiles/nono.gif" alt="" />'] = '/(\.nono\.)|(:\/)/i';
$smiles['<img src="smiles/omg.gif" alt="" />'] = '/(\.omg\.)|(=0)/i';
$smiles['<img src="smiles/phone.gif" alt="" />'] = '/(\.phone\.)/i';
$smiles['<img src="smiles/wink.gif" alt="" />'] = '/(\.wink\.)|(;\))/i';
$smiles['<img src="smiles/booty.gif" alt="" />'] = '/(\.booty\.)/i';
$smiles['<img src="smiles/prey.gif" alt="" />'] = '/(\.prey\.)/i';
$smiles['<img src="smiles/sleepy.gif" alt="" />'] = '/(\.sleepy\.)/i';
$smiles['<img src="smiles/laugh.gif" alt="" />'] = '/(\.laugh\.)|(:\)\))/i';
$smiles['<img src="smiles/smoke.gif" alt="" />'] = '/(\.smoke\.)|(:\)-)/i';
$smiles['<img src="smiles/smile.gif" alt="" />'] = '/(\.smile\.)|(:\))/i';
$smiles['<img src="smiles/confuse.gif" alt="" />'] = '/(\.confuse\.)|(:\[)/i';
$smiles['<img src="smiles/wall.gif" alt="" />'] = '/(\.wall\.)/i';
$smiles['<img src="smiles/stop.gif" alt="" />'] = '/(\.stop\.)/i';
$smiles['<img src="smiles/tears.gif" alt="" />'] = '/(\.tears\.)|(:\'\()/i';
$smiles['<img src="smiles/smirk.gif" alt="" />'] = '/(\.smirk\.)/i';
$smiles['<img src="smiles/umnik.gif" alt="" />'] = '/(\.umnik\.)/i';
$smiles['<img src="smiles/unsmile.gif" alt="" />'] = '/(\.unsmile\.)|(:\()/i';
$smiles['<img src="smiles/wakeup.gif" alt="" />'] = '/(\.wakeup\.)/i';
$smiles['<img src="smiles/tongue.gif" alt="" />'] = '/(\.tongue\.)|(:p)/i';
$smiles['<img src="smiles/evil.gif" alt="" />'] = '/(\.evil\.)/i';

return preg_replace (array_values ($smiles), array_keys ($smiles), $text);
}

function processText ($text)
{
return gSmiles (gBBCodes (preg_replace ('/\n+/', '', nl2br (filtOut ($text)))));
}

function pagination ($link = '?', $k_page = 1, $page = 1)
{
global $pagination;
if (empty ($pagination))
	$pagination = null;
	else
	return $pagination;
$pagination .= "<div class='".DIV_PAGINATION."'>";
if ($page < 1)
	$page = 1;
if ($page > 2)
	$pagination .= "<a href=\"".$link."page=1\">&lt;&lt;</a> ";
if ($page > 1)
	$pagination .= "<a href=\"".$link."page=".($page-1)."\">&lt;</a> ";
$pagination .= " ";

if ($page != 1)
	$pagination .= "<a href=\"".$link."page=1\">1</a>";else $pagination .= "<b>1</b>";
for ($ot = -3; $ot<=3; $ot++)
	{
	if ($page+$ot>1 && $page+$ot<$k_page)
		{
		if ($ot==-3 && $page+$ot>2)
			$pagination .= " ..";
		if ($ot!=0)
			$pagination .= " <a href=\"".$link."page=".($page+$ot)."\">".($page+$ot)."</a>";
			else
			$pagination .= " <b>".($page+$ot)."</b>";
		if ($ot==3 && $page + $ot < $k_page - 1)
			$pagination .= " ..";
		}
	}
if ($page != $k_page)
	$pagination .= " <a href=\"".$link."page=$k_page\">$k_page</a>";
	elseif ($k_page > 1)
	$pagination .= " <b>$k_page</b>";
if ($page < $k_page)
	$pagination .= " <a href=\"".$link."page=".($page+1)."\">&gt;</a>";
if ($page < ($k_page - 1))
	$pagination .= " <a href=\"".$link."page=$k_page\">&gt;&gt;</a>";
$pagination .= '</div>';
if ($k_page > 1)
	return $pagination;
	else
	return null;
}

function alternDivs ($div1 = null, $div2 = null)
{ 
static $divs; 
if (empty ($div1) || empty ($div2))
	{
	$div1 = DIV_SECTION_1;
	$div2 = DIV_SECTION_2;
	}
if (!isset ($divs) || $divs != func_get_args ())
	$divs = func_get_args (); 
$div = current ($divs); 
if (next ($divs) === false)
	reset ($divs); 
return $div; 
}

require 'cache.class.php';
require 'chat.class.php';
require 'users.class.php';
require 'server.class.php';

$cms = @file_get_contents ('dat/cms.dat');
if (!$cms)
	header ('Location: install/?step=1') AND exit ();
require 'cms/'.$cms.'/head.php';

if (is_dir ('install'))
{
echo "<div class='".DIV_MSG."'><h3>Удалите папку /папка_чата/install/ для начала использования GlobalChat</h3></div>";
require 'cms/'.$cms.'/foot.php';
exit ();
}

$cache = new gcache;
$chat = new gchat;
$server = new gserver;