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

Размер файла: 7.13Kb
<?php

#Реклама вверху
function ads_head(){
$ahs = mysql_fetch_assoc(mysql_query("SELECT `ads_head` FROM `system` WHERE `id` = '1'"));
if (!empty($ahs['ads_head'])) { echo '<div class="content">&raquo; '.out($ahs['ads_head']).'</div>'; }
}

#Реклама внизу
function ads_foot(){
$ahs = mysql_fetch_assoc(mysql_query("SELECT `ads_foot` FROM `system` WHERE `id` = '1'"));
if (!empty($ahs['ads_foot'])) { echo '<div class="content">&raquo; '.out($ahs['ads_foot']).'</div>'; }
}

# Транслит
function trans($str) {
$tr = array(
"А"=>"a","Б"=>"b","В"=>"v","Г"=>"g",
"Д"=>"d","Е"=>"e","Ж"=>"j","З"=>"z","И"=>"i",
"Й"=>"y","К"=>"k","Л"=>"l","М"=>"m","Н"=>"n",
"О"=>"o","П"=>"p","Р"=>"r","С"=>"s","Т"=>"t",
"У"=>"u","Ф"=>"f","Х"=>"h","Ц"=>"ts","Ч"=>"ch",
"Ш"=>"sh","Щ"=>"sch","Ъ"=>"","Ы"=>"yi","Ь"=>"",
"Э"=>"e","Ю"=>"yu","Я"=>"ya","а"=>"a","б"=>"b",
"в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"j",
"з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
"м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
"с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
"ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"y",
"ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya", 
" "=> "_", "."=> "", "/"=> "_"
);
return strtr($str,$tr);
}

# Фильтруем числа
function int($var) {
return abs(intval($var)); 
}

# Фильтруем текст
function txt($text) {
return trim(mysql_real_escape_string(htmlspecialchars($text, ENT_QUOTES, 'utf-8')));
}

# Выводим текст
function out($var) {
return nl2br(code(smile($var))); 
}

# Кодируем пароль
function encrypt($var) {
return md5(base64_encode($var) .'wapexpert'); 
}

# Ф-я для вывода времени
function vtime($var) {
if ($var == NULL) $var = time();
$full_time = date('d.m.Y в H:i', $var);
$date = date('d.m.Y', $var);
$time = date('H:i', $var);
if ($date == date('d.m.Y')) $full_time = date('Сегодня в H:i', $var);
if ($date == date('d.m.Y', time()-60*60*24)) $full_time = date('Вчера в H:i', $var);
return $full_time; 
}

# Ф-я для показа ошибок
function error($var) {
if (!empty($var)) echo '<div class="error">'. $var .'</div>'; 
}

function highlight($php) {
$php = strtr($php, array ('<br />' => '','\\' => 'slash'));
$php = html_entity_decode(trim($php), ENT_QUOTES, 'UTF-8');
$php = substr($php, 0, 2) != "" ? $php = "<?php\n" . $php . "\n?>": $php;
$php = highlight_string(stripslashes($php), true);
$php = strtr($php, array ('slash' => '&#92;',':' => '&#58;','[' => '&#91;'));
return '<div class="code">' . $php . '</div>';
}

# Смайлы
function smile($text){
$text = strtr($text, array(
':D'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/biggrin.gif" alt=":D" />',
'O_o'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/blink.gif" alt="O_o" />',
':cool:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/cool.gif" alt=":cool:" />',
':dry:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/dry.gif" alt=":dry:" />',
':eee:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/eee.gif" alt=":eee:" />',
':huh:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/huh.gif" alt=":huh:" />',
':laugh:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/laugh.gif" alt=":laugh:" />',
':mad:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/mad.gif" alt=":mad:" />',
':ohmy:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/ohmy.gif" alt=":ohmy:" />',
':rolleyes:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/rolleyes.gif" alt=":rolleyes:" />',
':('=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/sad.gif" alt=":(" />',
':)'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/smile.gif" alt=":)" /> ',
':tongue:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/tongue.gif" alt=":tongue:" />',
':unsure:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/unsure.gif" alt=":unsure:" />',
':wink:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/wink.gif" alt=":wink:" />',
':wow:'=>'<img src="http://'.txt($_SERVER['HTTP_HOST']).'/style/smiles/wow.gif" alt=":wow:" />'));
return $text;
}

# BB-code
$home = 'http://'.txt($_SERVER['HTTP_HOST']).'';
function code($var){
$var = preg_replace('#\[php\](.+?)\[\/php\]#e', 'highlight_code("\1")', $var);
//$var  = preg_replace('#\[code\](.*?)\[/code\]#ie', 'highlight("\1")', $var);
$var = preg_replace('#\[b\](.*?)\[/b\]#si', '<b>\1</b>', $var);
$var = preg_replace('#\[i\](.*?)\[/i\]#si', '<i>\1</i>', $var);
$var = preg_replace('#\[u\](.*?)\[/u\]#si', '<u>\1</u>', $var);
$var = preg_replace('#\[s\](.*?)\[/s\]#si', '<s>\1</s>', $var);
$var = preg_replace('#\[red\](.*?)\[/red\]#si', '<span style="color:red">\1</span>', $var);
$var = preg_replace('#\[green\](.*?)\[/green\]#si', '<span style="color:green">\1</span>', $var);
$var = preg_replace('#\[blue\](.*?)\[/blue\]#si', '<span style="color:blue">\1</span>', $var);
$var = preg_replace( "#\[center\](.+?)\[/center\]#is", "<center>\\1</center>", $var);
$var = preg_replace('#\[url\=(http\://.+)\](.+)\[/url\]#i','<a href="\1">\2</a>',$var);
$var = preg_replace( "~\\[img\](.+?)\[/img\]~", "<a href=\"\\1\"><img src=\"".$home."/system/resize.php?image=\\1\" alt=\"Картинка\" /></a>", $var);
$var = preg_replace( "#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $var);
$var = preg_replace( "#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $var);
$var = preg_replace( array ('#\[code\](.*?)\[\/code\]#se'), array ("''.highlight('$1').''"), str_replace("]\n", "]", $var));
return $var;
}

# Навигация
function page($k_page = 1) {
$page = 1;
if (isset($_GET['page'])) {
if ($_GET['page'] == 'end') $page = intval($k_page);
else if (is_numeric($_GET['page'])) $page = intval($_GET['page']);
}
if ($page < 1) $page = 1;
if ($page > $k_page) $page = $k_page;
return $page;
}
function k_page ($k_post = 0, $k_p_str = 10) {
if ($k_post != 0) {
$v_pages = ceil($k_post / $k_p_str);
return $v_pages;
}
else return 1;
}
function str($link = '?', $k_page = 1, $page = 1) {
if ($page < 1) $page = 1;
echo '<div class="content2">Страницы:  ';
if ($page != 1) echo '<a href="'. $link .'page=1">&laquo;</a> ';
if ($page != 1) echo '<a href="'. $link .'page=1">1</a>';
else echo '1';
for ($ot=-3; $ot<=3; $ot++)
{
if ($page + $ot > 1 && $page + $ot < $k_page)
{
if ($ot == -3 && $page + $ot > 2) echo ' ... ';
if ($ot != 0) echo ' <a href="'. $link .'page='. ($page + $ot) .'">'. ($page + $ot) .'</a>';
else echo ' '. ($page + $ot) .'';
if ($ot == 3 && $page + $ot < $k_page - 1) echo '  ...  ';
}
}
if ($page != $k_page) echo ' <a href="'. $link .'page=end">'. $k_page .'</a>';
else if ($k_page > 1) echo ' '. $k_page .'';
if ($page!=$k_page) echo ' <a href="'. $link .'page=end">&raquo;</a>';
echo '</div>';
}
function nav_start($var, $limit) {
global $k_page, $page, $start;
$k_page = k_page($var, $limit);
$page = page($k_page);
$start = $limit * $page - $limit;
}
function view_nav($link = '?') {
global $k_page, $page;
if ($k_page > 1) str($link, $k_page, $page);
}

?>