Файл: incfiles/func.php
Строк: 349
<?php
function SendEmail($toEmail, $fromEmail, $subject, $content, $from){
$subject = "=?utf-8?b?" . base64_encode($subject) . "?=";
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=utf-8rn";
$headers .= "From: =?utf-8?b?" . base64_encode($from) . "?= <" . $fromEmail . ">";
return (mail($toEmail, $subject,$content, $headers));
}
function checkout($var)
{
return strip_tags(addslashes(html_entity_decode($var,ENT_QUOTES, 'utf-8')));
}
function parse_url_if_valid($url)
{
$arUrl = parse_url($url);
$ret = null;
if (!array_key_exists("scheme", $arUrl)
|| !in_array($arUrl["scheme"], array("http", "https")))
$arUrl["scheme"] = "http";
if (array_key_exists("host", $arUrl) &&
!empty($arUrl["host"]))
$ret = sprintf("%s://%s%s", $arUrl["scheme"],
$arUrl["host"], $arUrl["path"]);
else if (preg_match("/^w+.[w.]+(/.*)?$/", $arUrl["path"]))
$ret = sprintf("%s://%s", $arUrl["scheme"], $arUrl["path"]);
if ($ret && empty($ret["query"]))
$ret .= sprintf("?%s", $arUrl["query"]);
return $ret;
}
function text($mes)
{
$mes = nl2br($mes);
return $mes;
}
function no_tags($mes)
{
$mes = str_replace("<br />", "rn", $mes);
return $mes;
}
// Ретранслит русских букв на латинницу
function retranslit($in)
{
$trans1= array("'",'`',',',' ',"Ё","Ж","Ч","Ш","Щ","Э","Ю","Я","ё","ж","ч","ш","щ","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ь","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ы");
$trans2= array('_','_','_','_',"JO","ZH","CH","SH","SCH","Je","Jy","Ja","jo","zh","ch","sh","sch","je","jy","ja","A","B","V","G","D","E","Z","I","J","K","L","M","N","O","P","R","S","T","U","F","H","C","","Y","a","b","v","g","d","e","z","i","j","k","l","m","n","o","p","r","s","t","u","f","h","c","","y");
return str_replace($trans1,$trans2,$in);
}
// Ретранслит латинских букв на русские
function translit($in)
{
$trans1= array("w","yu","W","YU","JO","ZH","CH","SH","SCH","JE","JY","JA","jo","zh","ch","sh","sch","je","jy","ja","A","B","V","G","D","E","Z","I","J","K","L","M","N","O","P","R","S","T","U","F","H","C","'","Y","a","b","v","g","d","e","z","i","j","k","l","m","n","o","p","r","s","t","u","f","h","c","'","y");
$trans2= array("ш","ю","Ш","Ю","Ё","Ж","Ч","Ш","Щ","Э","Ю","Я","ё","ж","ч","ш","щ","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ь","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ы");
return str_replace($trans1,$trans2,$in);
}
// Проверка длины русских символов
function strlen_rus($var)
{
$rus_symbols = array('а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'І', 'і', 'Ї', 'ї', 'Є', 'є');
return strlen(str_replace($rus_symbols, '0', $var));
}
function generate($number){
$arr = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','R','S','T','U','V','X','Y','Z','1','2','3','4','5','6','7','8','9','0');
// Генерируем пароль
$pass = '';
for($i = 0; $i < $number; $i++){
// Вычисляем случайный индекс массива
$index = rand(0, count($arr) - 1);
$pass .= $arr[$index];
}
return $pass;
}
function utfwin($str) {
$str = strtr($str, array("Р°" => "а", "Р±" => "б", "РІ" => "в", "Рі" => "г", "Рґ" => "д", "Рµ" => "е", "С‘" => "ё", "Р¶" => "ж", "Р·" => "з", "Рё" => "и", "Р№" => "й", "Рє" => "к", "Р»" => "л", "Рј" => "м", "РЅ" => "н", "Рѕ" => "о",
"Рї" => "п", "СЂ" => "р", "СЃ" => "с", "С‚" => "т", "Сѓ" => "у", "С„" => "ф", "С…" => "х", "С†" => "ц", "С‡" => "ч", "С€" => "ш", "С‰" => "щ", "СЉ" => "ъ", "С‹" => "ы", "СЊ" => "ь", "СЌ" => "э", "СЋ" => "ю", "СЏ" => "я", "Рђ" => "А",
"Р‘" => "Б", "Р’" => "В", "Р“" => "Г", "Р”" => "Д", "Р•" => "Е", "РЃ" => "Ё", "Р–" => "Ж", "Р—" => "З", "Р" => "И", "Р™" => "Й", "Рљ" => "К", "Р›" => "Л", "Рњ" => "М", "Рќ" => "Н", "Рћ" => "О", "Рџ" => "П", "Р " => "Р", "РЎ" => "С",
"Рў" => "Т", "РЈ" => "У", "Р¤" => "Ф", "РҐ" => "Х", "Р¦" => "Ц", "Р§" => "Ч", "РЁ" => "Ш", "Р©" => "Щ", "РЄ" => "Ъ", "Р«" => "Ы", "Р¬" => "Ь", "Р" => "Э", "Р®" => "Ю", "РЇ" => "Я"));
return $str;
}
function winutf($str) {
$str = strtr($str, array("а" => "Р°", "б" => "Р±", "в" => "РІ", "г" => "Рі", "д" => "Рґ", "е" => "Рµ", "ё" => "С‘", "ж" => "Р¶", "з" => "Р·", "и" => "Рё", "й" => "Р№", "к" => "Рє", "л" => "Р»", "м" => "Рј", "н" => "РЅ", "о" => "Рѕ", "п"
=> "Рї", "р" => "СЂ", "с" => "СЃ", "т" => "С‚", "у" => "Сѓ", "ф" => "С„", "х" => "С…", "ц" => "С†", "ч" => "С‡", "ш" => "С€", "щ" => "С‰", "ъ" => "СЉ", "ы" => "С‹", "ь" => "СЊ", "э" => "СЌ", "ю" => "СЋ", "я" => "СЏ", "А" => "Рђ", "Б" =>
"Р‘", "В" => "Р’", "Г" => "Р“", "Д" => "Р”", "Е" => "Р•", "Ё" => "РЃ", "Ж" => "Р–", "З" => "Р—", "И" => "Р", "Й" => "Р™", "К" => "Рљ", "Л" => "Р›", "М" => "Рњ", "Н" => "Рќ", "О" => "Рћ", "П" => "Рџ", "Р" => "Р ", "С" => "РЎ", "Т" =>
"Рў", "У" => "РЈ", "Ф" => "Р¤", "Х" => "РҐ", "Ц" => "Р¦", "Ч" => "Р§", "Ш" => "РЁ", "Щ" => "Р©", "Ъ" => "РЄ", "Ы" => "Р«", "Ь" => "Р¬", "Э" => "Р", "Ю" => "Р®", "Я" => "РЇ"));
return $str;
}
$dir = opendir(HOME.'/autoload/');
while ($file = readdir($dir))
{
if (preg_match('/.php$/i', $file)) require_once(HOME.'/autoload/'. $file);
}
// Обработка времени
function vtime($var, $title=false)
{
# Если время не задано берем текущее
if ($var == NULL) $var = time();
# Время + Дата
$full_time = date('d.m.Y '.lang('в','о').' H:i', $var);
# Дата
$date = date('d.m.Y', $var);
# Время
$time = date('H:i', $var);
# Если текущаяя дата совпадает с заданной
if ($date == date('d.m.Y'))
{
$full_time = date(''.lang('Сегодня в','Сьогодні о').' H:i', $var);
$h = date('H', $var);
$i = date('i', $var);
if ($h == date('H'))
{
if ($i == date('i')) $full_time = lang('только что','тільки що');
else $full_time = (date('i') - $i).' '.lang('мин. назад','хв. тому');
}
else
{
$full_time = $time;
}
}
# Вчерашняя дата
if ($date == date('d.m.Y', time()-60*60*24)) $full_time = date(''.lang('Вчера в','Вчора о').' H:i', $var);
if ($title == false) $full_time = '<font class="time"><small>'.$full_time.'</small></font>';
return $full_time;
}
// Вывод ошибок
function err($err) {
if ($err == true) $err = '<div class="err">'.$err.'</div>';
else $err = '';
return $err;
}
function ok($text) {
if (!empty($text))
{
$text = '<div class="ok">'.$text.'</div>';
}
return $text;
}
// рекурсивное удаление папки
function delete_dir($dir){
if (is_dir($dir)){$od=opendir($dir);
while ($rd=readdir($od)){
if ($rd == '.' || $rd == '..') continue;
if (is_dir("$dir/$rd")){
@chmod("$dir/$rd", 0777);
delete_dir("$dir/$rd");}
else{
@chmod("$dir/$rd", 0777);
@unlink("$dir/$rd");}}
closedir($od);
@chmod("$dir", 0777);
return @rmdir("$dir");}
else{
@chmod("$dir", 0777);
@unlink("$dir");}}
function getYoutubeVideoID($url){
// допустимые доменые имена в ссылке
$names = array('www.youtube.com','youtube.com');
// разбор адреса
$up = parse_url($url);
// проверка параметров
if (isset($up['host']) && in_array($up['host'],$names) &&
isset($up['query']) && strpos($up['query'],'v=') !== false){
// достаем параметр ID
$lp = explode('v=',$url);
// отсекаем лишние параметры
$rp = explode('&',$lp[1]);
// возвращаем строку, либо false
return (!empty ($rp[0]) ? $rp[0] : false);
}
return false;
}
/*
function check_youtube($text){
filter_var($text,FILTER_VALIDATE_URL,FILTER_FLAG_PATH_REQUIRED){
$videoID = getYoutubeVideoID($text);
} else {
$videoID = false;
}
$findme = 'https://www.youtube.com/watch?v=';
$pos = strpos($text, $findme);
// Заметьте, что используется ===. Использование == не даст верного
// результата, так как 'a' в нулевой позиции.
if ($pos !== false) {
$text = "[youtube]$findme[/youtube]";
}
return $text;
}
*/
function youtube_title($id) {
// $id = 'YOUTUBE_ID';
// returns a single line of JSON that contains the video title. Not a giant request.
$videoTitle = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id=".$id."&key=AIzaSyBfA6iMvBmb1o2fFqwijv76A2MBkGh4has&fields=items(id,snippet(title),statistics)&part=snippet,statistics");
// despite @ suppress, it will be false if it fails
if ($videoTitle) {
$json = json_decode($videoTitle, true);
return $json['items'][0]['snippet']['title'];
} else {
return false;
}
}
function youtube_about($id) {
// $id = 'YOUTUBE_ID';
// returns a single line of JSON that contains the video title. Not a giant request.
$videoTitle = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id=".$id."&key=AIzaSyBfA6iMvBmb1o2fFqwijv76A2MBkGh4has&fields=items(id,snippet(description),statistics)&part=snippet,statistics");
// despite @ suppress, it will be false if it fails
if ($videoTitle) {
$json = json_decode($videoTitle, true);
$about = $json['items'][0]['snippet']['description'];
$about = mb_convert_encoding($about, "EUC-JP", "auto");
return $about;
} else {
return false;
}
}
function yt_exists($videoID) {
$theURL = "http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=$videoID&format=json";
$headers = get_headers($theURL);
if (substr($headers[0], 9, 3) !== "404") {
return true;
} else {
return false;
}
}
function gethashtags($text)
{
//Match the hashtags
preg_match_all('/(^|[^0-9A-Za-zА-Яа-яҐІЇЄґіїєЁё_])#([0-9A-Za-zА-Яа-яҐІЇЄґіїєЁё_]+)/u', $text, $matchedHashtags);
$hashtag = '';
// For each hashtag, strip all characters but alpha numeric
if(!empty($matchedHashtags[0])) {
foreach($matchedHashtags[0] as $match) {
$hashtag .= preg_replace("/[^0-9A-Za-zА-Яа-яҐІЇЄґіїєЁё_]+/u", "", $match).',';
}
}
//to remove last comma in a string
return rtrim($hashtag, ',');
}
function convert_clickable_links($message)
{
$vowels = array("'");//заміняємо апострофф))
$message = str_replace($vowels, "'", $message);
$parsedMessage = preg_replace(array('/(?i)b((?:https?://|wwwd{0,3}[.]|[0-9A-Za-zА-Яа-яҐІЇЄґіїє.-]+[.][a-z0-9A-ZА-Яа-яҐІЇЄґіїє]{2,4}/)(?:[^s()<>]+|(([^s()<>]+|(([^s()<>]+)))*))+(?:(([^s()<>]+|(([^s()<>]+)))*)|[^s`!()[]{};:'".,<>?«»“”‘’]))/', '/(^|[^0-9A-Za-zА-Яа-яҐІЇЄґіїє_])@([0-9A-Za-zА-Яа-яҐІЇЄґіїє_]+)/u', '/(^|[^0-9A-Za-zА-Яа-яҐІЇЄґіїє_])#([0-9A-Za-zА-Яа-яҐІЇЄґіїє_]+)/u'), array('<a href="$1" target="_blank">$1</a>', '$1<a href="">@$2</a>', '$1<a href="'.URL.'/modules/hashtag?hashtag=$2" onclick="Page.Go(this.href); return false">#$2</a>'), $message);
return $parsedMessage;
}
function cut($str,$href,$num=300) {
if (mb_strlen($str) > $num)
{
$str = str_replace("|", "<br />", mb_substr(str_replace("<br />", "|", $str), 0, $num, 'UTF-8')).'...<br/><a class="for_pc" style="font-weight:bold;" href="'.$href.'" onclick="Window.Open(this.href); return false">'.lang('Читать делее...','Читати далі...').'</a><a class="for_mobile" style="font-weight:bold;" href="'.$href.'" onclick="Page.Go(this.href); return false">'.lang('Читать делее...','Читати далі...').'</a>';
}else{
$str = $str;
}
return $str;
}
function convertHashtags($str){
$vowels = array("'");//заміняємо апострофф))
$str = str_replace($vowels, "'", $str);
$regex = "/#+([[^0-9A-Za-zА-Яа-яҐІЇЄґіїє_]+)/u";
$str = preg_replace($regex, '<a href="'.URL.'/modules/hashtag?hashtag=$1" onclick="Page.Go(this.href); return false">$0</a>', $str);
return($str);
//$str = str_replace($vowels, "'", $str);
//$str = preg_replace('/#(w+)/u', ' <a href="'.URL.'/modules/hashtag?hashtag=$1" onclick="Page.Go(this.href); return false">$1</a>', $str);
return($str);
}
function text_view($text){
//mb_convert_encoding($text, "UTF-8", "HTML-ENTITIES");
$text = BBCode::parse(smiles(links(convertHashtags($text))));
return $text;
}
// -------------- Функция "быстрого" ресайза -------------//
function showgift($var, $size, $size1)
{
return '<img src="'.URL.'/'.$var.'" width="'.$size.'" height="'.$size1.'" alt="*">
';
}
function headMenu(){
echo'<style>
.container{
overflow:hidden;
width:200px
text-align right;
}
.box{white-space:nowrap}
.box div{width:90px;display:inline-block;border:1px solid black}
</style>
<div class="head_player for_pc" style="width:850px; margin: auto;">
<div class="sm2-bar-ui playlist-close full-width flat" style="text-align: left;width: 600px; margin-left:125px;">
<div class="sm2-inline-element sm2-button-element sm2-menu">
<div class="sm2-button-bd3">
<div class="box">
<div>content1</div>
<div>content2</div>
<div>content3</div>
</div>
</div>
</div>
</div>
</div>
';
}
function right_menu(){
global $user_id , $device , $user ;
if (!empty($user_id) && $device == 'Computer')
{
?>
<div id='snav' class='en'>
<ul>
<li>
<a href="<?=URL?>/?id=<?=$user_id?>" onclick="Page.Go(this.href); return false">
<i class="fa fa-home"></i>
<span><?=lang('Моя Стр.','Моя Стор.')?></span>
</a>
</li>
<li>
<a href="<?=URL?>/mail/" onclick="Page.Go(this.href); return false">
<i class="fa fa-envelope"><font size="2" color="red" face="Arial"><?=($user['notifications_mail']>0?'+<b>'.$user['notifications_mail'].'</b>':'')?></font></i>
<span><?=lang('Сообщения','Повідомлення')?></span>
</a>
</li>
<li>
<a href="<?=URL?>/friends?id=<?=$user_id?>" onclick="Page.Go(this.href); return false">
<i class="fa fa-users"><font size="2" color="red" face="Arial"><?=($user['notifications_friends']>0?'+<b>'.$user['notifications_friends'].'</b>':'')?></font></i>
<span><?=lang('Друзья','Друзі')?></span>
</a>
</li>
<li>
<a href="<?=URL?>/user/journal.php" onclick="Page.Go(this.href); return false">
<i class="fa fa-bell"><font size="2" color="red" face="Arial"><?=($user['notifications_journal']>0?'+<b>'.$user['notifications_journal'].'</b>':'')?></font></i>
<span><?=lang('Ответы','Відповіді')?></span>
</a>
</li>
<li>
<a href="<?=URL?>/feed/" onclick="Page.Go(this.href); return false">
<i class="fa fa-rss"></i>
<span><?=lang('Новости','Новини')?></span>
</a>
</li>
<li>
<a href="<?=URL?>/photos/?id=<?=$user_id?>" onclick="Page.Go(this.href); return false">
<i class="fa fa-camera"></i>
<span><?=lang('Фото','Фото')?></span>
</a>
</li>
<li>
<a href="<?=URL?>/audio/?id=<?=$user_id?>" onclick="Page.Go(this.href); return false">
<i class="fa fa-music"></i>
<span><?=lang('Музыка','Музика')?></span>
</a>
</li>
<li>
<a href="<?=URL?>/video/index::default/" onclick="Page.Go(this.href); return false">
<i class="fa fa-video-camera"></i>
<span><?=lang('Видео','Відео')?></span>
</a>
</li>
<li>
<a href="<?=URL?>/groups/my.php?id=<?=$user_id?>" onclick="Page.Go(this.href); return false">
<i class="fa fa-comments-o"></i>
<span><?=lang('Группы','Спільноти')?></span>
</a>
</li>
<li>
<a href="<?=URL?>/user/settings.php" onclick="Page.Go(this.href); return false">
<i class="fa fa-cogs"></i>
<span><?=lang('Настройки','Налаштування')?></span>
</a>
</li>
<li>
<a href="<?=URL?>/exit.php" onclick="Page.Go(this.href); return false">
<i class="fa fa-sign-out"></i>
<span><?=lang('Выход','Вихід')?></span>
</a>
</li>
<?
if ($user['level'] > 0) {
?>
<li>
<a href="<?=URL?>/adm" onclick="Page.Go(this.href); return false">
<i class="fa fa-lock"></i>
<span><?=lang('Admin','admin')?></span>
</a>
</li>
<?
}
?>
</ul>
</div>
<?
}
}
function timeSpam($stime,$table,$collumb){
global $id;
$timeSpam =(time()-$stime);
if (DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".$table." WHERE `".$collumb."` = ? AND `time` > ?", array($id,$timeSpam)) == TRUE)
return true;else return false;
/* echo $err1;
return $err1;*/
}
?>