File size: 13,757 Bytes
6966756 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | <?php
use App\Constants\Status;
use App\Lib\GoogleAuthenticator;
use App\Models\Extension;
use App\Models\Frontend;
use App\Models\GeneralSetting;
use Carbon\Carbon;
use App\Lib\Captcha;
use App\Lib\ClientInfo;
use App\Lib\CurlRequest;
use App\Lib\FileManager;
use App\Models\Language;
use App\Notify\Notify;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Cache;
use Laramin\Utility\VugiChugi;
function systemDetails()
{
$system['name'] = 'promptlab';
$system['version'] = '1.0';
$system['build_version'] = '5.0.10';
return $system;
}
function slug($string)
{
return Str::slug($string);
}
function verificationCode($length)
{
if ($length == 0) return 0;
$min = pow(10, $length - 1);
$max = (int) ($min - 1) . '9';
return random_int($min, $max);
}
function getNumber($length = 8)
{
$characters = '1234567890';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function activeTemplate($asset = false)
{
$template = session('template') ?? gs('active_template');
if ($asset) return 'assets/templates/' . $template . '/';
return 'templates.' . $template . '.';
}
function activeTemplateName()
{
$template = session('template') ?? gs('active_template');
return $template;
}
function siteLogo($type = null)
{
$name = $type ? "/logo_$type.png" : '/logo.png';
return getImage(getFilePath('logoIcon') . $name);
}
function siteFavicon()
{
return getImage(getFilePath('logoIcon') . '/favicon.png');
}
function loadReCaptcha()
{
return Captcha::reCaptcha();
}
function loadCustomCaptcha($width = '100%', $height = 46, $bgColor = '#003')
{
return Captcha::customCaptcha($width, $height, $bgColor);
}
function verifyCaptcha()
{
return Captcha::verify();
}
function loadExtension($key)
{
$extension = Extension::where('act', $key)->where('status', Status::ENABLE)->first();
return $extension ? $extension->generateScript() : '';
}
function getTrx($length = 12)
{
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function getAmount($amount, $length = 2)
{
$amount = round($amount ?? 0, $length);
return $amount + 0;
}
function showAmount($amount, $decimal = 2, $separate = true, $exceptZeros = false, $currencyFormat = true)
{
$separator = '';
if ($separate) {
$separator = ',';
}
$printAmount = number_format($amount, $decimal, '.', $separator);
if ($exceptZeros) {
$exp = explode('.', $printAmount);
if ($exp[1] * 1 == 0) {
$printAmount = $exp[0];
} else {
$printAmount = rtrim($printAmount, '0');
}
}
if ($currencyFormat) {
if (gs('currency_format') == Status::CUR_BOTH) {
return gs('cur_sym') . $printAmount . ' ' . __(gs('cur_text'));
} elseif (gs('currency_format') == Status::CUR_TEXT) {
return $printAmount . ' ' . __(gs('cur_text'));
} else {
return gs('cur_sym') . $printAmount;
}
}
return $printAmount;
}
function removeElement($array, $value)
{
return array_diff($array, (is_array($value) ? $value : array($value)));
}
function cryptoQR($wallet)
{
return "https://api.qrserver.com/v1/create-qr-code/?data=$wallet&size=300x300&ecc=m";
}
function keyToTitle($text)
{
return ucfirst(preg_replace("/[^A-Za-z0-9 ]/", ' ', $text));
}
function titleToKey($text)
{
return strtolower(str_replace(' ', '_', $text));
}
function strLimit($title = null, $length = 10)
{
return Str::limit($title, $length);
}
function getIpInfo()
{
$ipInfo = ClientInfo::ipInfo();
return $ipInfo;
}
function osBrowser()
{
$osBrowser = ClientInfo::osBrowser();
return $osBrowser;
}
function getTemplates()
{
$param['purchasecode'] = env("PURCHASECODE");
$param['website'] = @$_SERVER['HTTP_HOST'] . @$_SERVER['REQUEST_URI'] . ' - ' . env("APP_URL");
$url = VugiChugi::gttmp() . systemDetails()['name'];
$response = CurlRequest::curlPostContent($url, $param);
if ($response) {
return $response;
} else {
return null;
}
}
function getPageSections($arr = false)
{
$jsonUrl = resource_path('views/') . str_replace('.', '/', activeTemplate()) . 'sections.json';
$sections = json_decode(file_get_contents($jsonUrl));
if ($arr) {
$sections = json_decode(file_get_contents($jsonUrl), true);
ksort($sections);
}
return $sections;
}
function getImage($image, $size = null, $avatar = false, $cover = false)
{
$clean = '';
if (file_exists($image) && is_file($image)) {
return asset($image) . $clean;
}
if ($size) {
return route('placeholder.image', $size);
}
if ($avatar) {
return asset('assets/images/avatar.png');
}
if ($cover) {
return asset('assets/images/cover.png');
}
return asset('assets/images/default.png');
}
function notify($user, $templateName, $shortCodes = null, $sendVia = null, $createLog = true, $pushImage = null)
{
$globalShortCodes = [
'site_name' => gs('site_name'),
'site_currency' => gs('cur_text'),
'currency_symbol' => gs('cur_sym'),
];
if (gettype($user) == 'array') {
$user = (object) $user;
}
$shortCodes = array_merge($shortCodes ?? [], $globalShortCodes);
$notify = new Notify($sendVia);
$notify->templateName = $templateName;
$notify->shortCodes = $shortCodes;
$notify->user = $user;
$notify->createLog = $createLog;
$notify->pushImage = $pushImage;
$notify->userColumn = isset($user->id) ? $user->getForeignKey() : 'user_id';
$notify->send();
}
function getPaginate($paginate = null)
{
if (!$paginate) {
$paginate = gs('paginate_number');
}
return $paginate;
}
function paginateLinks($data, $view = null)
{
return $data->appends(request()->all())->links($view);
}
function menuActive($routeName, $type = null, $param = null)
{
if ($type == 3) $class = 'side-menu--open';
elseif ($type == 2) $class = 'sidebar-submenu__open';
else $class = 'active';
if (is_array($routeName)) {
foreach ($routeName as $key => $value) {
if (request()->routeIs($value)) return $class;
}
} elseif (request()->routeIs($routeName)) {
if ($param) {
$routeParam = array_values(@request()->route()->parameters ?? []);
if (strtolower(@$routeParam[0]) == strtolower($param)) return $class;
else return;
}
return $class;
}
}
function fileUploader($file, $location, $size = null, $old = null, $thumb = null, $filename = null)
{
$fileManager = new FileManager($file);
$fileManager->path = $location;
$fileManager->size = $size;
$fileManager->old = $old;
$fileManager->thumb = $thumb;
$fileManager->filename = $filename;
$fileManager->upload();
return $fileManager->filename;
}
function fileManager()
{
return new FileManager();
}
function getFilePath($key)
{
return fileManager()->$key()->path;
}
function getFileSize($key)
{
return fileManager()->$key()->size;
}
function getThumbSize($key)
{
return fileManager()->$key()->thumb;
}
function getFileExt($key)
{
return fileManager()->$key()->extensions;
}
function diffForHumans($date)
{
$lang = session()->get('lang');
if (!$lang) {
$lang = getDefaultLang();
}
Carbon::setlocale($lang);
return Carbon::parse($date)->diffForHumans();
}
function showDateTime($date, $format = 'd M Y h:i A')
{
if (!$date) {
return '-';
}
$lang = session()->get('lang');
if (!$lang) {
$lang = getDefaultLang();
}
Carbon::setlocale($lang);
return Carbon::parse($date)->translatedFormat($format);
}
function getDefaultLang()
{
return Language::where('is_default', Status::YES)->first()->code ?? 'en';
}
function getContent($dataKeys, $singleQuery = false, $limit = null, $orderById = false)
{
$templateName = activeTemplateName();
if ($singleQuery) {
$content = Frontend::where('tempname', $templateName)->where('data_keys', $dataKeys)->orderBy('id', 'desc')->first();
} else {
$article = Frontend::where('tempname', $templateName);
$article->when($limit != null, function ($q) use ($limit) {
return $q->limit($limit);
});
if ($orderById) {
$content = $article->where('data_keys', $dataKeys)->orderBy('id')->get();
} else {
$content = $article->where('data_keys', $dataKeys)->orderBy('id', 'desc')->get();
}
}
return $content;
}
function verifyG2fa($user, $code, $secret = null)
{
$authenticator = new GoogleAuthenticator();
if (!$secret) {
$secret = $user->tsc;
}
$oneCode = $authenticator->getCode($secret);
$userCode = $code;
if ($oneCode == $userCode) {
$user->tv = Status::YES;
$user->save();
return true;
} else {
return false;
}
}
function urlPath($routeName, $routeParam = null)
{
if ($routeParam == null) {
$url = route($routeName);
} else {
$url = route($routeName, $routeParam);
}
$basePath = route('home');
$path = str_replace($basePath, '', $url);
return $path;
}
function showMobileNumber($number)
{
$length = strlen($number);
return substr_replace($number, '***', 2, $length - 4);
}
function showEmailAddress($email)
{
$endPosition = strpos($email, '@') - 1;
return substr_replace($email, '***', 1, $endPosition);
}
function getRealIP()
{
$ip = $_SERVER["REMOTE_ADDR"];
//Deep detect ip
if (filter_var(@$_SERVER['HTTP_FORWARDED'], FILTER_VALIDATE_IP)) {
$ip = $_SERVER['HTTP_FORWARDED'];
}
if (filter_var(@$_SERVER['HTTP_FORWARDED_FOR'], FILTER_VALIDATE_IP)) {
$ip = $_SERVER['HTTP_FORWARDED_FOR'];
}
if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
if (filter_var(@$_SERVER['HTTP_X_REAL_IP'], FILTER_VALIDATE_IP)) {
$ip = $_SERVER['HTTP_X_REAL_IP'];
}
if (filter_var(@$_SERVER['HTTP_CF_CONNECTING_IP'], FILTER_VALIDATE_IP)) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
if ($ip == '::1') {
$ip = '127.0.0.1';
}
return $ip;
}
function appendQuery($key, $value)
{
return request()->fullUrlWithQuery([$key => $value]);
}
function dateSort($a, $b)
{
return strtotime($a) - strtotime($b);
}
function dateSorting($arr)
{
usort($arr, "dateSort");
return $arr;
}
function gs($key = null)
{
$general = Cache::get('GeneralSetting');
if (!$general) {
$general = GeneralSetting::first();
Cache::put('GeneralSetting', $general);
}
if ($key) return @$general->$key;
return $general;
}
function isImage($string)
{
$allowedExtensions = array('jpg', 'jpeg', 'png', 'gif');
$fileExtension = pathinfo($string, PATHINFO_EXTENSION);
if (in_array($fileExtension, $allowedExtensions)) {
return true;
} else {
return false;
}
}
function isHtml($string)
{
if (preg_match('/<.*?>/', $string)) {
return true;
} else {
return false;
}
}
function convertToReadableSize($size)
{
preg_match('/^(\d+)([KMG])$/', $size, $matches);
$size = (int)$matches[1];
$unit = $matches[2];
if ($unit == 'G') {
return $size . 'GB';
}
if ($unit == 'M') {
return $size . 'MB';
}
if ($unit == 'K') {
return $size . 'KB';
}
return $size . $unit;
}
function formatProfileViewCount($count)
{
if ($count >= 1000000) {
return number_format($count / 1000000, 1) . 'M';
} elseif ($count >= 1000) {
return number_format($count / 1000, 1) . 'k';
} else {
return $count;
}
}
function frontendImage($sectionName, $image, $size = null, $seo = false, $thumb = false)
{
if ($seo) {
return getImage('assets/images/frontend/' . $sectionName . '/seo/' . $image, $size);
}
if ($thumb) {
return getImage('assets/images/frontend/' . $sectionName . '/thumb_' . $image, $size);
}
return getImage('assets/images/frontend/' . $sectionName . '/' . $image, $size);
}
function discountAmount($subtotal, $coupon)
{
if ($coupon->discount_type == Status::FIXED) {
$discount = $coupon->amount;
} else {
$discount = $subtotal * $coupon->amount / 100;
}
return $discount;
}
function calculateCommission($price)
{
$sellerFixedCharge = gs('seller_fixed_charge');
$sellerPercentCharge = gs('seller_percent_charge');
return $sellerFixedCharge + ($price * $sellerPercentCharge / 100);
}
function displayRating(float $val)
{
$result = '';
$fullStars = floor($val);
$fraction = $val - $fullStars;
$halfStar = $fraction >= 0.25 && $fraction < 0.75;
$emptyStars = 5 - $fullStars - ($halfStar ? 1 : 0);
for ($i = 0; $i < $fullStars; $i++) {
$result .= '<i class="fas fa-star"></i>';
}
if ($halfStar) {
$result .= '<i class="fas fa-star-half-alt"></i>';
}
for ($i = 0; $i < $emptyStars; $i++) {
$result .= '<i class="far fa-star"></i>';
}
return $result;
}
|