Просмотр файла sys/functions.php

Размер файла: 4.44Kb
<?php
// coding by Felis

class Func
{
	public function encode($arg)
	{
		$hash = sha1(sha1(sha1($arg)));
	return $hash;
	}
	
	public function smile($arg)
	{
		$file = file('smiles');
		foreach($file as $item)
		{
			$smile = explode('|', $item);
			$arg = str_replace($smile[0], '<img src="temp/smiles/'.$smile[1].'" alt="" />', $arg);
		}
		return $arg;
	}
	
	public function out($arg, $ent = false, $bb = false)
	{
		$arg = ($ent == true) ? htmlentities($arg, ENT_QUOTES, 'UTF-8') : $arg;
		$arg = get_magic_quotes_gpc() ? stripslashes($arg) : $arg;
		$arg = trim($arg);
		if($bb == true)
		{
			$arg = preg_replace("#(https?|ftp)://\S+[^\s.,>)\];'\"!?]#", 'гг', $arg);
			$arg = preg_replace("/[ ]{2,}/",' ', $arg);
			$arg = nl2br($arg);
			$arg = preg_replace('#\[b\](.*?)\[/b\]#si', '<strong>$1</strong>', $arg);
			$arg = preg_replace('#\[i\](.*?)\[/i\]#si', '<em>$1</em>', $arg);
			$arg = preg_replace('#\[u\](.*?)\[/u\]#si', '<u>$1</u>', $arg);
			$arg = preg_replace('#\[s\](.*?)\[/s\]#si', '<s>$1</s>', $arg);
		}
		return $arg;
	}
	
	public function head($arg)
	{
		$arg = '<div class="head">'.$arg.'</div>';
		return $arg;
	}
	
	public function cont($arg)
	{
		$arg = '<div class="cont">'.$arg.'</div>';
		return $arg;
	}
	
	public function cont2($arg)
	{
		$arg = '<div class="cont2">'.$arg.'</div>';
		return $arg;
	}
	
	public function alert($ttl, $msg)
	{
		$arg = self::head($ttl).self::cont($msg);
		return $arg;
	}
	
	public function get_author($aid, $link = false)
	{
		global $db;
		
		$an = $db->query("SELECT `login` FROM `users` WHERE `id`=".$aid);
		if($an->num_rows > 0)
		{
			$an = $an->fetch_assoc();
			if($link == true)
			{
				$res = '<a href="profile.php?u='.$aid.'">'.$an['login'].'</a>';
			}
			else
			{
				$res = $an['login'];
			}
			return $res;
		}
		else
		{
			return AN_USER;
		}
	}
	
	public function get_access($aid)
	{
		global $db;
		
		$aa = $db->query("SELECT `access` FROM `users` WHERE `id`=".$aid);
		if($aa->num_rows > 0)
		{
			$aa = $aa->fetch_assoc();
				return $aa['access'];
		}
		else
		{
			return false;
		}
	}
	
	function nav($rows, $onpage, $cpage, $navkeys = true, $ints = false, $param = false)
	{
		global $p;
		
		$pages = ceil($rows / $onpage);
		$row = 2;
		
		$begin = abs($cpage - $row);
		
		$end = $cpage + $row;
		$end = $end > $pages ? $pages : $end;
		
		if($rows > $onpage)
		{
			echo '<div class="cont2">';
			
			if($navkeys == true)
			{
				echo ($p > 1 ? '<b><a href="'.CFILE.'">Чат</a></b>' : NULL).($p > 1 ? ($p != $pages ? ' | ' : NULL) : NULL).($rows > $p * $onpage ? '<a href="'.CFILE.'?'.$param.'p='.($p + 1).'">Раньше</a>' : NULL);
				echo '<br />';
			}
			
			if($ints == true)
			{
				echo $p > $row + 1 ? '.. ' : NULL;
				for($pg = $begin; $pg <= $end; $pg++)
				{
					if($pg == 0) continue;
					echo ($pg == $cpage) ? '<b>'.$pg.'</b>' : '<a href="'.CFILE.'?'.$param.'p='.$pg.'">'.$pg.'</a>';
					echo ($pg == $end || $pg == $pages) ? NULL : ',';
				}
				echo $pages < ($end + ($row - 1)) ? NULL : ' ..';
			}
			echo '</div>';
		}
	}
	
	public function rm($month)
	{
		$cyph = array('01','02','03','04','05','06','07','08','09','10','11','12');
		$bukph = array('января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря');
		$month = str_replace($cyph, $bukph, $month);
	return $month;
	}
	
	public function trans($tt)
	{
		$tt = strtr($tt, array('A'=>'А','B'=>'Б','C'=>'Ц','D'=>'Д','E'=>'Е','F'=>'Ф','G'=>'Г','H'=>'Х','I'=>'И','J'=>'Й','K'=>'К','L'=>'Л','M'=>'М','N'=>'Н','O'=>'О','P'=>'П','Q'=>'Ку','R'=>'Р','S'=>'С','T'=>'Т','U'=>'У','V'=>'В','W'=>'В','X'=>'Кс','Y'=>'Ы','Z'=>'З','a'=>'а','b'=>'б','c'=>'ц','d'=>'д','e'=>'е','f'=>'ф','g'=>'г','h'=>'х','i'=>'и','j'=>'й','k'=>'к','l'=>'л','m'=>'м','n'=>'н','o'=>'о','p'=>'п','q'=>'ку','r'=>'р','s'=>'с','t'=>'т','u'=>'у','v'=>'в','w'=>'в','x'=>'кс','y'=>'ы','z'=>'з','Sch'=>'Щ','Yu'=>'Ю','Ju'=>'Ю','Ya'=>'Я','Ja'=>'Я','Yo'=>'Ё','Jo'=>'Ё','Zh'=>'Ж','Ch'=>'Ч','Sh'=>'Ш','Ts'=>'Ц','sch'=>'щ','yu'=>'ю','ju'=>'ю','ya'=>'я','ja'=>'я','yo'=>'ё','jo'=>'ё','zh'=>'ж','ch'=>'ч','sh'=>'ш','ts'=>'ц',"E'"=>"Э","e'"=>"э",'``'=>'Ъ','`'=>'ъ'));
	return $tt;
	}
}

$fnc = new Func;

// конец файла ./sys/functions.php