This commit is contained in:
Pavel Belyaev
2021-07-25 19:19:18 +05:00
parent 175948447b
commit eac6c5ec5d
22 changed files with 1283 additions and 131 deletions

53
CLASSES/core/LE_PHONE.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
class LE_PHONE
{
public static function prepare($inp)
{
$inp = str_replace(";", ",",Preg_replace(".[^0-9,;].", "", $inp));
if (count($arr = explode(',',$inp))>1) $inp=$arr;
if (is_array($inp))
{
for ($i=0;$i<count($inp);$i++) $inp[$i]=self::format($inp[$i]);
return implode(', ', $inp);
}
else
return self::format($inp);
}
public static function clear($num)
{
$num = str_replace(";", ",",Preg_replace(".[^0-9,;].", "", $num));
$arr = explode(',',$num);
$cnt = count($arr);
//print_r($arr);
if ($cnt>1)
{
for ($i=0;$i<$cnt;$i++) $arr[$i] = self::mobile_prepare($arr[$i]); return implode(',',$arr);
}
return self::mobile_prepare($num);
}
public static function mobile_prepare($num)
{
return preg_replace('/^[+]{0,1}[78]{0,1}9/','89',$num);
}
public static function format($num)
{
$num = self::mobile_prepare($num);
$n=strlen($num = Preg_replace(".[^0-9].", "", $num));
if ($n==6) return preg_replace("/([0-9]{2})([0-9]{2})([0-9]{2})/", "$1-$2-$3", $num);
if ($n==7) return preg_replace("/([0-9]{3})([0-9]{2})([0-9]{2})/", "$1-$2-$3", $num);
if ($n==10) return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{2})([0-9]{2})/", "($1)$2-$3-$4", $num);
if ($n==11) return preg_replace("/([0-9])([0-9]{3})([0-9]{3})([0-9]{2})([0-9]{2})/", "$1($2)$3-$4-$5", $num);
return $num;
}
}

6
CLASSES/core/LE_TBL.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
class LE_TBL
{
}

View File

@@ -0,0 +1,117 @@
<?php
/*
Mail v3.1
*/
if(!defined("I")) die;
//статический класс для отправки уведомлений
class LE_MAIL
{
//отправка текстового письма Mail::send("электронный@адрес", "адрес отправителя", "текст письма", "тема_письма")
public static function send($address,$sender,$mail_body,$subject)
{
$headers="";
$text ='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional //EN">
<html><head>
<META http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<body>';
$text.=$mail_body;
$text.='</body></html>';
$text=iconv('UTF-8', 'windows-1251//TRANSLIT', $text);
$subject=iconv('UTF-8', 'windows-1251//TRANSLIT', $subject);
$subject = '=?windows-1251?B?'.base64_encode($subject).'?=';
$headers .= "MIME-Version: 1.0\n";
$headers .="Content-Type: text/html; charset=windows-1251 \n";
$headers .= "From: ".$sender."\r\n";
mail($address, $subject, $text, $headers);
}
//отправка письма с вложением Mail::send("электронный@адрес", "адрес отправителя", "тема письма", "текст письма", "путь до файла", "имя файла(отображаемое в письме)")
public static function send_file($address, $sender, $subject, $text, $path, $filename)
{
$text=iconv('UTF-8', 'windows-1251//TRANSLIT', $text);
$subject=iconv('UTF-8', 'windows-1251//TRANSLIT', $subject);
$subject = '=?windows-1251?B?'.base64_encode($subject).'?=';
$fp = fopen($path,"r"); if (!$fp) {print "Файл $path не может быть прочитан"; exit();}
$file = fread($fp, filesize($path)); fclose($fp);
$boundary = "--".md5(uniqid(time())); // генерируем разделитель
$headers .= "MIME-Version: 1.0\n";
$headers .="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
$headers .= "From: ".$sender."\r\n";
$multipart .= "--$boundary\n";
$multipart .= "Content-Type: text/html; charset=windows-1251\n";
$multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n";
$multipart .= "$text\n\n";
$message_part = "--$boundary\n";
$message_part .= "Content-Type: application/octet-stream\n";
$message_part .= "Content-Transfer-Encoding: base64\n";
$message_part .= "Content-Disposition: attachment; filename = \"".$filename."\"\n\n";
$message_part .= chunk_split(base64_encode($file))."\n";
$multipart .= $message_part."--$boundary--\n";
if(!mail($address, $subject, $multipart, $headers)) {echo "К сожалению, письмо не отправлено"; exit();}
}
public function gen_message($mailfrom,$mailto,$body,$subject,$file=false)
{
$separator = md5(time());
$filename = 'myfile';
$path = 'your path goes here';
$file = $path . "/" . $filename;
$mailto = 'mail@mail.com';
$subject = 'Subject';
$message = 'My message';
$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));
// a random hash will be necessary to send mixed content
// carriage return type (RFC)
$eol = "\r\n";
// main header (multipart mandatory)
$headers = "From: name <test@test.com>" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
$headers .= "This is a MIME encoded message." . $eol;
// message
$body = "--" . $separator . $eol;
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $eol;
$body .= $message . $eol;
// attachment
$body .= "--" . $separator . $eol;
$body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment" . $eol;
$body .= $content . $eol;
$body .= "--" . $separator . "--";
//SEND Mail
if (mail($mailto, $subject, $body, $headers)) {
echo "mail send ... OK"; // or use booleans here
} else {
echo "mail send ... ERROR!";
print_r( error_get_last() );
}
}
}

View File

@@ -0,0 +1,51 @@
<?
/**
* TEST BETA, need refactoring
*/
class LE_RABBITMQ
{
protected $connection,$channel,$exchange;
function __construct($inp=[])
{
if (!isset($inp['host'])) $inp['host']='127.0.0.1';
$this->connection = $this->connect($inp['host'],$inp['login'],$inp['pass']);
$this->channel = new AMQPChannel($this->connection);
$this->exchange = new AMQPExchange($this->channel);
}
function connect($host,$login,$pass)
{
$connection = new AMQPConnection();
$connection->setHost($host);
$connection->setLogin($login);
$connection->setPassword($pass);
$connection->connect();
return $connection;
}
function get_q($q)
{
$queue = new AMQPQueue($this->channel);
$queue->setName($q);
$queue->setFlags(AMQP_NOPARAM);
$queue->declareQueue();
return $queue;
}
function send_message($m,$q)
{
$qu = $this->get_q($q);
$this->exchange->publish($m, $q);
}
function get_message($q,&$f)
{
$this->get_q($q)->consume($f);
}
}

212
CLASSES/core/TODO/LE_VK.php Normal file
View File

@@ -0,0 +1,212 @@
<?
/**
*
*/
class MP_VK
{
public $web,$api_v,$client_id,$secure_key,$service_key,$token;
public $group_key = "";
public $group_id = "";
public $admin_id = "";
function __construct($i=[])
{
if (isset($i['web'])) $this->web = &$i['web'];
$this->api_v = arr_v($i,'api_v','5.92');
$this->client_id = arr_v($i,'client_id','0');
$this->secure_key = arr_v($i,'secure_key','0');
$this->service_key = arr_v($i,'service_key','0');
}
public function getf_act($cont)
{
return $this->web->reg_find($cont,'<[^>]+action="([^"]+)"',1);
}
public function url2token($url)
{
$url = str_replace('https://oauth.vk.com/blank.html#', '', $url);
parse_str($url, $out);
if (!isset($out['access_token'])) return false;
return $out['access_token'];
}
public function web_auth($login,$pass)
{
$ref = $inp['url'] = "https://m.vk.com";
$html = $this->web->get_cont($inp);
$inp['url'] = $this->getf_act($html);
$inp['ref'] = $ref;
$inp['post'] = ['email'=>$login,'pass'=>$pass];
return true;
}
//тут еще надо доработать на примере ботинка...
public function oauth()
{
$url = 'https://oauth.vk.com/authorize?client_id='.$this->client_id;
$url.='&display=mobile&redirect_uri=https://oauth.vk.com/blank.html';
//https://vk.com/dev/permissions
$url.='&scope='.(2+4+8+16+64+256+1024+8192+65536+262144+524288+1048576);
$url.='&response_type=token&v='.$this->api_v;
$inp['url'] = $url;
//return;
$inp['get_redirect'] =1;
$html = $this->web->get_cont($inp);
echo $html.BR.BR;
//если уже есть доступ
if ($this->web->redirect)
{
$inp['url'] = $this->web->redirect;
$html = $this->web->get_cont($inp);
return $this->url2token($this->web->redirect);
}
//этот момент еще недоработан///
$inp['url'] = $html;
$html = $this->web->get_cont($inp);
var_dump($html); echo BR.BR; return;
$inp['post'] = 1;
//echo $html.BR.BR;
$inp['url'] = $this->getf_act($html);
return;
echo $inp['url'].BR;
$inp['ref'] = $url;
$res = $this->web->get_cont($inp);
var_dump($res);
return true;
}
public function query($method,$data=[],$access_token=1)
{
$inp['url'] = "https://api.vk.com/method/".$method;
if ($access_token) $data['access_token'] = $this->token;
$data['v'] = $this->api_v;
$inp['post'] = $data;
$res = $this->web->get_cont($inp);
$res = json_decode($res,1);
if(isset($res['error']))
{
print_r($res['error']);
return false;
}
print_r($res);
return $res['response'];
}
public function long_pool_init()
{
$par = ['group_id'=>$this->group_id,'access_token'=>$this->group_key];
$c = $this->query("groups.getLongPollServer",$par);
$url = $c['server']."?act=a_check&key=".$c['key'].'&wait=25';
return [$c,$url];
}
public function long_pool(&$f=false,$timeout=0)
{
if ($f===false) $f = function($i){return false;};
list ($c,$url) = $this->long_pool_init();
while ($r=$this->web->get_cont($url.'&ts='.$c['ts']))
{
set_time_limit(0);
$_r = $r; //debug
$r = json_decode($r,1);
if (isset($r['failed']))
{
switch ($r['failed'])
{
case '1':
$c['ts'] = $r['ts'];
break;
case '2':
case '3':
list ($c,$url) = $this->long_pool_init();
echo BR.BR."UPDATE KEY".BR.BR;
break;
}
continue;
}
if (!isset($r['ts']))
{
echo "response hzhz".BR;
var_dump($_r);
echo "try again...".BR.BR;
sleep(3);
continue;
}
$c['ts'] = $r['ts'];
if (is_array($r['updates']) && count($r['updates']))
$f($r['updates']);
}
echo "ERROR GET URL, timeout: ".$timeout.BR;
sleep($timeout);
$timeout+=1;
$timeout*=2;
return $this->long_pool($f,$timeout);
}
public function bot_message($user_id,$message)
{
$data=[];
if (is_string($message))
$data['message'] = $message;
elseif (is_array($message))
$data = $message;
$data['random_id'] = rand(0,99999);
$data['peer_id'] = $this->group_id;
$data['access_token']=$this->group_key;
$data['user_id'] = $user_id;
$this->query("messages.send",$data,0);
}
}

View File

@@ -0,0 +1,49 @@
<?php
class YA_CL
{
public $iam,$folder,$token,$web;
public $tts_lang="ru-RU",$tts_speed="1.12",$tts_voice="filipp",$tts_emo="neutral";
// read more on
// https://cloud.yandex.ru/docs/iam/operations/iam-token/create
public function get_iam()
{
$inp['url'] = "https://iam.api.cloud.yandex.net/iam/v1/tokens";
$inp['raw'] = '{"yandexPassportOauthToken":"'.$this->token.'"}';
$res = $this->web->get_cont($inp);
$res = json_decode($res,1);
//print_r($res);
$this->iam = $res['iamToken'];
return $this->iam;
}
public function speech($text,$file="./out.ogg",$p=[])
{
$post = [];
$post['lang'] = arr_v($p,'lang',$this->tts_lang);
$post['speed'] = arr_v($p,'speed',$this->tts_speed);
$post['voice'] = arr_v($p,'voice',$this->tts_voice);
$post['emotion'] = arr_v($p,'emo',$this->tts_emo);
$post['format'] = arr_v($p,'format','oggopus');
$post['folderId']=$this->folder;
$post['text'] = $text;
$inp['url'] = "https://tts.api.cloud.yandex.net/speech/v1/tts:synthesize";
$inp['post'] = $post;
$inp['headers'] = ['Authorization: Bearer '.$this->iam];
$res = $this->web->get_cont($inp);
file_put_contents($file, $res);
chmod($file, 0777);
}
}