Files
ahrommag/app/helper.php
2025-11-16 12:43:07 +03:30

468 lines
20 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use Carbon\Carbon;
use App\Models\User;
use App\Models\Package;
use App\Models\Setting;
use App\Models\Inventory;
use App\Models\Discountcode;
use App\Models\SignedDocument;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Process;
use Morilog\Jalali\Jalalian;
if (!function_exists('generateRandomToken')) {
function generateRandomToken($length = 64)
{
if ($length % 2 != 0) {
$length++;
}
$bytes = openssl_random_pseudo_bytes($length / 2);
$token = bin2hex($bytes);
return $token;
};
}
if (!function_exists('convertPersianToEnglishNumber')) {
function convertPersianToEnglishNumber($number)
{
$number = str_replace('۰', '0', $number);
$number = str_replace('۱', '1', $number);
$number = str_replace('۲', '2', $number);
$number = str_replace('۳', '3', $number);
$number = str_replace('۴', '4', $number);
$number = str_replace('۵', '5', $number);
$number = str_replace('۶', '6', $number);
$number = str_replace('۷', '7', $number);
$number = str_replace('۸', '8', $number);
$number = str_replace('۹', '9', $number);
return $number;
}
function convertEnglishToPersianNumber($number)
{
$number = str_replace('0', '۰', $number);
$number = str_replace('1', '۱', $number);
$number = str_replace('2', '۲', $number);
$number = str_replace('3', '۳', $number);
$number = str_replace('4', '۴', $number);
$number = str_replace('5', '۵', $number);
$number = str_replace('6', '۶', $number);
$number = str_replace('7', '۷', $number);
$number = str_replace('8', '۸', $number);
$number = str_replace('9', '۹', $number);
return $number;
}
function priceFormat($price)
{
$price = number_format($price, 0, '.', ','); // 1,000,000/00
$price = convertEnglishToPersianNumber($price);
return $price;
}
}
if (!function_exists('generatefilename')) {
function generatefilename($name)
{
$year = Carbon::now()->year;
$month = Carbon::now()->month;
$day = Carbon::now()->day;
$hour = Carbon::now()->hour;
$minute = Carbon::now()->minute;
$second = Carbon::now()->second;
$microsecond = Carbon::now()->microsecond;
return $year . '_' . $month . '_' . $day . '_' . $hour . '_' . $minute . '_' . $second . '_' . $microsecond . '_' . $name;
};
}
if(!function_exists('priceFormat')){
function priceFormat($price)
{
$price = number_format($price, 0, '.', ','); // 1,000,000/00
$price = convertEnglishToPersianNumber($price);
return $price;
}
}
if(!function_exists('last_of_route_name')){
function last_of_route_name($route_name)
{
$route=explode('.',$route_name);
return end($route);
}}
if(!function_exists('image_name')){
function image_name($original_name)
{
return time().str_shuffle(random_int(1000000000000000,9999999999999999).str()->random(16)).'_'.$original_name;
}}
if(!function_exists('runPython')){
function runPython($file_name,$input)
{
// code with laravel process
$process = Process::input($input)->env( ['SYSTEMROOT' => getenv('SYSTEMROOT'),'PATH' => getenv("PATH")])->run('python '.base_path('Python/'.$file_name));
$process->exitCode();
if (!$process->successful()){
return -1;
// $error=$process->errorOutput();
// dd($error);
}
return $process->output();
}}
if(!function_exists('status')){
function status($status)
{
if($status==1){
return '<span class="text-red-500">ناموفق</span>';
}
if($status==2){
return '<span class="text-green-500">موفق</span>';
}
if($status==0){
return '<span style="color: #facc15 !important;">نامشخص</span>';
}
return '';
}}
if(!function_exists('jalaliDate')){
function jalaliDate($date, $format = '%A - %Y/%m/%d',$fa=true)
{
$result = Jalalian::forge($date)->format($format);
if(!$fa){
return $result;
}
return convertEnglishToPersianNumber($result);
}}
if(!function_exists('convertPersianToEnglishNumber')){
function convertPersianToEnglishNumber($number)
{
$number = str_replace('۰', '0', $number);
$number = str_replace('۱', '1', $number);
$number = str_replace('۲', '2', $number);
$number = str_replace('۳', '3', $number);
$number = str_replace('۴', '4', $number);
$number = str_replace('۵', '5', $number);
$number = str_replace('۶', '6', $number);
$number = str_replace('۷', '7', $number);
$number = str_replace('۸', '8', $number);
$number = str_replace('۹', '9', $number);
return $number;
}}
if(!function_exists('convertArabicToEnglishNumber')){
function convertArabicToEnglishNumber($number)
{
$number = str_replace('۰', '0', $number);
$number = str_replace('۱', '1', $number);
$number = str_replace('۲', '2', $number);
$number = str_replace('۳', '3', $number);
$number = str_replace('۴', '4', $number);
$number = str_replace('۵', '5', $number);
$number = str_replace('۶', '6', $number);
$number = str_replace('۷', '7', $number);
$number = str_replace('۸', '8', $number);
$number = str_replace('۹', '9', $number);
return $number;
}}
if(!function_exists('convertEnglishToPersianNumber')){
function convertEnglishToPersianNumber($number)
{
$number = str_replace('0', '۰', $number);
$number = str_replace('1', '۱', $number);
$number = str_replace('2', '۲', $number);
$number = str_replace('3', '۳', $number);
$number = str_replace('4', '۴', $number);
$number = str_replace('5', '۵', $number);
$number = str_replace('6', '۶', $number);
$number = str_replace('7', '۷', $number);
$number = str_replace('8', '۸', $number);
$number = str_replace('9', '۹', $number);
return $number;
}}
if(!function_exists('priceFormat')){
function priceFormat($price)
{
$price = number_format($price, 0, '/', ','); // 1,000,000/00
$price = convertEnglishToPersianNumber($price);
return $price;
}}
if(!function_exists('fa2en')){
function fa2en($str) {
return strtr($str, array('۰'=>'0', '۱'=>'1', '۲'=>'2', '۳'=>'3', '۴'=>'4', '۵'=>'5', '۶'=>'6', '۷'=>'7', '۸'=>'8', '۹'=>'9'));
}}
if(!function_exists('home_comments')){
function home_comments($comments,$comment,$blog_id)
{
$result=null;
foreach ($comments->other as $other_comment) {
$result .= '
<div style="margin-right: 40px" class="mr-10 relative" >
<div class="" >
';
if ($other_comment->status==1) {
$result.='
<div class="">
<div >
<div class=" flex flex-col gap-3 m-3">
<div x-data="{reply_id:0}">
<div class="relative rounded-xl p-5 flex gap-4 ">
<div class="flex ">
<img style="width: 40px; height: 40px" wire:ignore alt="" class="size-10 rounded-full"
src="' . profile($other_comment->type == 1) . '">
</div>
<div class="flex flex-col gap-5">
<div class="flex gap-1">
<span class=" text_class font-bold text-[#E1EAF9]"> '.$other_comment->name.'</span>
<span class=" text_class font-bold text-[#E1EAF9]"> |</span>
<span class=" text_class font-bold text-[#E1EAF9]"> '.how_long($other_comment->created_at).'</span>
</div>
<p class="text-[#B4BBC7]"> ' . $other_comment->message . '</p>
<div class="flex gap-10">
<div class="flex flex-col justify-end">
<button type="button" @click="reply_id=' . $other_comment->id . '">
<div class="flex gap-1 items-center content-center">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="16" height="16"
viewBox="0 0 16.000000 16.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,16.000000) scale(0.100000,-0.100000)"
fill="#E1EAF9" stroke="none">
<path d="M131 123 c-2 -29 -27 -53 -56 -53 -18 0 -23 4 -18 16 8 21 -16 14
-31 -8 -7 -12 -6 -21 3 -32 17 -20 32 -21 25 -1 -5 12 2 15 29 15 42 0 60 19
54 57 -3 21 -4 22 -6 6z"/>
</g>
</svg>
<span class="text-xs text-[#E1EAF9]">پاسخ</span>
</div>
</button>
</div>
<div wire:ignore.self x-data="{like_color:like_color_session(\''.session()->get('comment-'.$other_comment->id).'\')}" class="flex flex-col justify-end">
<button @click="like_color=comment_like_color(like_color)" wire:click="like_comment(' . $other_comment->id . ')" type="button" >
<div class="flex gap-1 items-center content-center">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="16" height="12" viewBox="0 0 512.000000 512.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
:fill="like_color" fill="#E1EAF9" stroke="none">
<path d="M1262 4830 c-319 -40 -586 -171 -812 -399 -203 -204 -325 -420 -395
-701 -124 -487 -34 -967 264 -1418 191 -289 438 -554 891 -958 288 -257 1167
-1007 1210 -1032 40 -24 55 -27 140 -27 85 0 100 3 140 27 43 25 924 776 1210
1032 455 406 700 670 891 958 298 451 388 931 264 1418 -70 281 -192 497 -395
701 -202 203 -418 320 -701 380 -142 30 -404 33 -528 5 -346 -75 -611 -248
-853 -556 l-28 -35 -27 35 c-239 302 -500 475 -833 551 -99 23 -327 33 -438
19z m334 -305 c284 -50 529 -214 723 -485 33 -47 74 -103 90 -126 74 -104 228
-104 302 0 16 23 57 79 90 126 265 370 634 544 1036 489 446 -61 794 -373 927
-832 105 -363 59 -744 -132 -1087 -160 -287 -427 -588 -892 -1005 -225 -201
-1171 -1015 -1180 -1015 -10 0 -952 811 -1180 1015 -715 641 -997 1041 -1065
1510 -44 303 19 629 172 886 230 387 678 599 1109 524z"/>
</g>
</svg>
<span :style="`color:${like_color}`" class="text-xs text-[#E1EAF9] ">پسندیدم</span>
</div>
</button>
</div>
</div>
</div>
<div class="absolute top-1/2 left-2 flex gap-1 items-center content-center">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="16" height="12" viewBox="0 0 512.000000 512.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
fill="#E1EAF9" stroke="none">
<path d="M1262 4830 c-319 -40 -586 -171 -812 -399 -203 -204 -325 -420 -395
-701 -124 -487 -34 -967 264 -1418 191 -289 438 -554 891 -958 288 -257 1167
-1007 1210 -1032 40 -24 55 -27 140 -27 85 0 100 3 140 27 43 25 924 776 1210
1032 455 406 700 670 891 958 298 451 388 931 264 1418 -70 281 -192 497 -395
701 -202 203 -418 320 -701 380 -142 30 -404 33 -528 5 -346 -75 -611 -248
-853 -556 l-28 -35 -27 35 c-239 302 -500 475 -833 551 -99 23 -327 33 -438
19z m334 -305 c284 -50 529 -214 723 -485 33 -47 74 -103 90 -126 74 -104 228
-104 302 0 16 23 57 79 90 126 265 370 634 544 1036 489 446 -61 794 -373 927
-832 105 -363 59 -744 -132 -1087 -160 -287 -427 -588 -892 -1005 -225 -201
-1171 -1015 -1180 -1015 -10 0 -952 811 -1180 1015 -715 641 -997 1041 -1065
1510 -44 303 19 629 172 886 230 387 678 599 1109 524z"/>
</g>
</svg>
<span class="text-[#E1EAF9]">' . $other_comment->likes . '</span>
</div>
</div>
<div x-cloak @click.outside="reply_id=0" x-show="reply_id==' . $other_comment->id . '" class="mt-5">
<form >
<div class="border-2 border-black flex flex-col h-60 p-3 rounded-xl">
<input style="border-color: transparent; box-shadow: none;" x-model="name_reply" wire:model="comment_name_reply" class="bg-transparent border border-black focus-ring focus:outline-none focus:ring-0 my-3 p-3 resize-none ring-0 rounded-2xl text-black "
placeholder="نام شما">
<textarea style="border-color: transparent; box-shadow: none;" x-model="message_reply" wire:model="comment_message_reply"
class="bg-transparent border border-black focus-ring focus:outline-none focus:ring-0 my-3 p-3 resize-none ring-0 rounded-2xl text-black"
placeholder="نظر شما"></textarea>
<div class="flex justify-end gap-3">
<button @click="reply_id=0"
type="button"
class="text-white p-2 px-4 w-max text-sm rounded"> لغو پاسخ
</button>
<button @click="show_notif(name_reply.length>0 && message_reply.length>0),reply_id=0"
wire:click="reply(' . $other_comment->id . ',' . $comment->id . ')"
:disabled="!(name_reply.length>0 && message_reply.length>0)"
class="bg-[#F47A53] p-2 text-white text-sm px-4 w-max rounded-xl"> ارسال نظر
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
';
}
$result.='
</div>';
if ($other_comment->status==1) {
$result.='<hr>';
}
$result.='
<div>
'.home_comments($other_comment,$comment,$blog_id).'
</div>
</div>
';
}
return $result;
}}
if (!function_exists('panel_comments')) {
function panel_comments($comments, $comment, $blog_id) {
$result = '';
foreach ($comments->other as $another_comment) {
$result .= '
<div class="mx-10 relative ">
<div class="before:h-full before:absolute before:right-[-10px] before:top-[0] before:z-0 before:w-[3px] before:bg-gray-500 before:block ">
<div class="p-5 rounded ' . ($another_comment->type == 1 ? 'bg-gray-400' : 'bg-gray-200') . ' flex flex-col gap-3 m-3">
<div>
<h4> اسم : ' . $another_comment->name . '</h4>
<p> پیام : ' . $another_comment->message . '</p>
<p> نوع : ' . $another_comment->type_check . '</p>
'
;
$result .= '
</div>
<div>
<a @click="modalshow2 = true , id = {{ $comment->id }} , $wire.id = {{ $comment->id }} , $wire.blog_id = {{ $comment->blog->id }} " class=" w-[140px] text-center bg-gray-500 text-white rounded-xl px-4 py-1"> تایین وضعیت</a>
<a @click="modalshow = true , id = {{ $comment->id }} , $wire.id = {{ $comment->id }} , $wire.blog_id = {{ $comment->blog->id }} " class=" w-[120px] text-center bg-blue-500 text-white rounded-xl px-4 py-1">کامنت گذاری</a>
';
$result .= '
</div>
</div>
</div>
<div class="ps-3 ">
' . panel_comments($another_comment, $comment, $blog_id) . '
</div>
</div>';
}
return $result;
}
}
if(!function_exists('profile')){
function profile($admin=false)
{
if($admin){
return asset('images/profile/admin.png');
}
$num=random_int(1,7);
return asset('images/profile/'.$num.'.png');
}}
if(!function_exists('how_long')){
function how_long($time)
{
Carbon::setLocale('fa');
$res=Carbon::parse($time)->diffForHumans();
return $res;
}}
if (!function_exists('cleanRouteUrl')) {
function cleanRouteUrl($routeName, $parameters = [], $absolute = true)
{
$url = route($routeName, $parameters, $absolute);
$url = preg_replace('/([^:])\/\//', '$1/', $url);
return $url;
}
}