inital commit

This commit is contained in:
2026-06-24 18:29:01 +06:00
commit f401802bf7
3918 changed files with 553085 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Utility;
class ActionLogCreate
{
public static function logDataCreate($action,$request,$message,$response,$code)
{
$logData=[];
$logData['action'] = $action;
$logData['data']['request'] = $request;
$logData['data']['message'] = $message;
$logData['data']['response'] = $response;
$logData['data']['code'] = $code;
appLog($logData);
}
}

47
app/Utility/Curl.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
namespace App\Utility;
use Illuminate\Support\Facades\Http;
class Curl
{
private array $prepareData;
private static string $url;
private static array $header;
public function __construct($url,$header = ['Content-Type: application/json']){
static::$url = $url;
static::$header = $header;
}
private function prepareRequest($inputData){
return $inputData;
}
public function post($request){
$this->prepareData = $this->prepareRequest($request);
$response = Http::withHeaders(static::$header)
->post(
static::$url,
$this->prepareData
);
return json_decode((string) $response->getBody(), true);
}
public function get($request){
$this->prepareData = $this->prepareRequest($request);
$response = Http::withHeaders(static::$header)
->get(
static::$url,
$this->prepareData
);
return json_decode((string) $response->getBody(), true);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Utility;
class CurlRequest {
public function makeCurlRequest($params,$method,$URL,$header = ['Content-Type: application/json']){
$ch = curl_init();
if ($this->isNonSecureConnection()){
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
}
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if(!empty($header)){
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
private function isNonSecureConnection(){
$host = $_SERVER['REMOTE_ADDR'];
$result = true;
/*if ($host != 'readytogoletters.com') {
$result = true;
}*/
return $result;
}
}

71
app/Utility/Email.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
namespace App\Utility;
use App\Jobs\SendEmailJob;
use App\Mail\SendEmail;
use Illuminate\Support\Facades\Mail;
class Email
{
private bool $is_queue_enable = false;
private array $result = [];
private array $logData = [];
public function __construct()
{
$this->is_queue_enable = config('app.IS_QUEUE_ENABLE');
}
public function send($data, $email_subject, $from, $attachment, $template, $to)
{
if ($this->is_queue_enable == 1) {
dispatch((new SendEmailJob($data, $email_subject, $from, $attachment, $template, $to)));
} else {
$this->sendEmailManually($data, $email_subject, $from, $attachment, $template, $to);
}
}
private function sendEmailManually($data, $email_subject, $from, $attachment, $template, $to) : void
{
try{
if(empty($to)){
throw new \Exception("Recipient email is missing.");
}
Mail::to($to)->send(
new SendEmail(
$data,
$email_subject,
$from,
$attachment,
$template
)
);
$this->result['message'] = 'E-Mail has been send successfully.';
$this->result['status'] = true;
@unlink($attachment);
}catch (\Throwable $ex){
$this->result['message'] = $ex->getMessage();
$this->result['status'] = false;
}
$this->logData['SEND_EMAIL'] = $this->prepareLogData($from,$to,$email_subject);
appLog($this->logData);
}
private function prepareLogData($from_email,$to,$email_subject){
return [
'sending_info' => [
'from' => $from_email,
'to' => $to,
'subject' => $email_subject
],
'response' => $this->result
];
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace App\Utility\HttpRequest;
use Illuminate\Support\Facades\Http;
class HttpAsForm
{
private array $prepareData;
private static string $url;
private static array $header;
const CONTENT_TYPE_JSON = 'application/json';
const CONTENT_TYPE_X_WWW_FORM_URLENCODE = 'application/x-www-form-urlencoded';
public function __construct($url){
static::$url = $url;
}
private function prepareRequest($inputData){
return $inputData;
}
public function post($request, $header = 'application/x-www-form-urlencoded'){
$this->prepareData = $this->prepareRequest($request);
if($header == self::CONTENT_TYPE_X_WWW_FORM_URLENCODE) {
$response = Http::asForm();
}else if($header == self::CONTENT_TYPE_JSON){
$response = Http::asJson();
}
$response = $response->post(
static::$url,
$this->prepareData
);
return json_decode((string) $response->getBody(), true);
}
public function get($request, $header = 'application/x-www-form-urlencoded'){
$this->prepareData = $this->prepareRequest($request);
if($header == self::CONTENT_TYPE_X_WWW_FORM_URLENCODE) {
$response = Http::asForm();
}else if($header == self::CONTENT_TYPE_JSON){
$response = Http::asJson();
}
$response = $response->get(
static::$url,
$this->prepareData
);
return json_decode((string) $response->getBody(), true);
}
public function put($request, $header = 'application/x-www-form-urlencoded'){
$this->prepareData = $this->prepareRequest($request);
if($header == self::CONTENT_TYPE_X_WWW_FORM_URLENCODE) {
$response = Http::asForm();
}else if($header == self::CONTENT_TYPE_JSON){
$response = Http::asJson();
}
$response = $response->put(
static::$url,
$this->prepareData
);
return json_decode((string) $response->getBody(), true);
}
}

206
app/Utility/PdfWriter.php Normal file
View File

@@ -0,0 +1,206 @@
<?php
namespace App\Utility;
use Knp\Snappy\Pdf;
use mysql_xdevapi\Exception;
class PdfWriter {
private $binaryPath;
public function __construct()
{
$this->binaryPath = config('snappy.pdf.binary');
}
public function createPdfWithConfiguration($data,$file_path) {
//require WWW_ROOT.'epicvelocity/vendor/autoload.php';
$html = $data['body_html'];
$cover_html = isset($data['cover_html']) ? $data['cover_html']:"";
$page_no_format = "";//Page [page] of [topage]
if(!empty($data['page_no_format'])){
$page_no_format = $data['page_no_format'];
}
$snappy = new Pdf();
$snappy->setBinary($this->binaryPath);
if(!empty($cover_html)){
$snappy->setOption('cover',$cover_html);
}
if(!empty($data['margin'])){
$snappy->setOption('margin-left', $data['margin']);
$snappy->setOption('margin-right', $data['margin']);
$snappy->setOption('margin-top', $data['margin']);
$snappy->setOption('margin-bottom', $data['margin']);
}else{
if(!empty($data['margin_left'])){
$snappy->setOption('margin-left', $data['margin_left']);
}
if(!empty($data['margin_right'])){
$snappy->setOption('margin-right', $data['margin_right']);
}
if(!empty($data['margin_top'])){
$snappy->setOption('margin-top', $data['margin_top']);
}
if(!empty($data['margin_bottom'])){
$snappy->setOption('margin-bottom', $data['margin_bottom']);
}
}
if(!empty($page_no_format)){
$snappy->setOption('footer-right', $page_no_format);
}
if(!empty($data['footer_left'])){
$snappy->setOption('footer-left', $data['footer_left']);
}
if(!empty($data['header_right'])){
$snappy->setOption('header-right', $data['header_right']);
}
return $snappy->generateFromHtml($html,$file_path,
array(
'encoding' => 'utf-8'
)
);
}
public function write($html,$file_path) {
$snappy = new Pdf();
// dd($this->binaryPath);
$snappy->setBinary($this->binaryPath);
$snappy->setOption('enable-local-file-access', true);
$snappy->setOption('margin-left', 5);
$snappy->setOption('footer-right', "Page [page] of [topage]");
$snappy->generateFromHtml($html,$file_path,array('encoding' => 'utf-8'));
$snappy->setOption('password', true);
chmod($file_path, 0664);
//PDF::loadHTML($html)->setOption('margin-left', 5)->setOption('footer-right', "Page [page] of [topage]")->save($file_path);
//dd($snappy);
return $snappy;
}
public function pdfcreate($html,$file_path){
//require WWW_ROOT.'epicvelocity/vendor/autoload.php';
$snappy = new Pdf();
$snappy->setBinary($this->binaryPath);
$snappy->setOption('margin-left', 5);
$snappy->generateFromHtml($html, $file_path, array('encoding' => 'utf-8'));
$file_url = $file_path;
}
public function download($html,$file_path){
//require WWW_ROOT.'epicvelocity/vendor/autoload.php';
/*$snappy = new Pdf();
$snappy->setBinary($this->binaryPath);
$snappy->setOption('page-size','LETTER');
$snappy->setOption('encoding', 'UTF-8');
$snappy->generateFromHtml($html, $file_path, array('encoding' => 'utf-8'));
*/
PDF::loadHTML($html)->setOption('margin-left', 5)->setOption('footer-right', "Page [page] of [topage]")->save($file_path);
$file_url = $file_path;
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
readfile($file_url);
@unlink($file_path);
//return $file_path;
}
public function mpdfWrite($html,$file_path,$file_name,$extra = []){
// ini_set("pcre.backtrack_limit", "5000000");
// include(WWW_ROOT."../vendor/mpdf_latest_vendor\vendor\autoload.php");
// $html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
$mpdf = new \Mpdf\Mpdf(
[
'default_font_size' => 12,
'default_font' => 'sans-serif',
]
);
$mpdf->SetProtection(array("print"));
$mpdf->defaultfooterline = false;
$mpdf->setFooter("Page {PAGENO} of {nb}");
if(!empty($extra['footer'])){
$mpdf->defaultfooterline = 0;
$mpdf->setFooter($extra['footer']);
}
// $mpdf->SetVisibility('printonly');
// $mpdf->SetVisibility('screenonly');
$html=str_replace('</style>', ' b, strong {font-weight: 700 !important;}.span-ul,.span-blue,.span-large,.cb-br{font-size:14px !important;} .bg-yellow2{font-size:12px !important;} .crTableBackground {font-size:11px !important;} .h1, h1 {font-size:30px !important;}</style>', $html);
$html=str_replace('<body', '<body style="font-size: 14px; margin-top: 120px;font-family: -webkit-body;color: black;margin-left: 50px;
margin-right: 50px;text-align: justify;"', $html);
// echo $html;exit;
$mpdf->WriteHTML(utf8_encode($html));
$mpdf->Output($file_path.$file_name);
//$file_name = "invoice_" . $id . ".pdf"; //file name
//return $file_path;
}
public function mpdfdownload($html,$file_path,$file_name, $extra = []){
ini_set("pcre.backtrack_limit", "5000000");
include(WWW_ROOT."../vendor/mpdf_latest_vendor\vendor\autoload.php");
//$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
$mpdf = new \Mpdf\Mpdf();
$mpdf->SetProtection(array("print"));
//$mpdf->SetDisplayMode('fullpage');
$mpdf->defaultfooterline = 0;
if(!empty($extra['footer'])){
$mpdf->setFooter($extra['footer']);
}
//echo $html;exit;
$mpdf->WriteHTML($html);
//$file_name = "invoice_" . $id . ".pdf"; //file name
$mpdf->Output($file_name, 'D'); // I=preview, D=download
@unlink($file_path);
//return $file_path;
}
public static function pdfDownload($file) {
$file_name = basename($file);
header('Pragma: public');
header('Expires: -1');
header('Cache-Control: public, must-revalidate, post-check=0, pre-check=0');
header('Content-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Type: application/zip");
header("Content-Length: " . filesize($file));
header("Content-Description: File Transfer");
if ($fp = fopen($file, 'rb')) {
ob_end_clean();
while (!feof($fp) and ( connection_status() == 0)) {
print(fread($fp, 8192));
flush();
}
@fclose($fp);
}
@unlink($file);
}
public function snappyImage($html,$file_path) {
// $snappy = new Pdf();
$snappy = \App::make('snappy.image');
// $snappy->setBinary($this->imageBinary);
$snappy->setOption('width', 500);
$nameImage=\Str::random(5).'.jpg';
$snappy->generateFromHtml($html,$file_path.$nameImage);
// dd('yes');
// chmod($file_path, 0664);
// return $snappy;
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Utility;
use ZipArchive;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
class createDirZip {
public function testZip($source, $destination) {
// Get real path for our folder
$rootPath = realpath($source);
// Initialize archive object
$zip = new ZipArchive();
$zip->open($destination, ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file) {
// Skip directories (they would be added automatically)
if (!$file->isDir()) {
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
// Add current file to archive
if(!empty($filePath) && !empty($relativePath)){
$zip->addFile($filePath, $relativePath);
}
}
}
// Zip archive will be created only after closing object
return $zip->close();
}
private function testLog($data){
$data = json_encode($data);
$file = fopen(WWW_ROOT."dropbox/test.txt","w");
echo fwrite($file,$data);
fclose($file);
}
}