fix: add fallback value for setting variables

This commit is contained in:
idevakk
2025-11-28 05:59:25 -08:00
parent a33c0dfa95
commit d4de074161
7 changed files with 88 additions and 50 deletions

View File

@@ -2,13 +2,13 @@
namespace App\Livewire\Frontend;
use Illuminate\Routing\Redirector;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Date;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use App\Models\Log;
use App\Models\ZEmail;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Date;
use Livewire\Component;
class Action extends Component
@@ -27,9 +27,12 @@ class Action extends Component
public $initial;
private $configSettings;
public function mount(): void
{
$this->domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
$this->configSettings = json_decode(config('app.settings.configuration_settings') ?: '{}');
$this->domains = $this->configSettings->domains ?? [];
$this->email = ZEmail::getEmail();
$this->emails = ZEmail::getEmails();
$this->validateDomainInEmail();
@@ -41,17 +44,17 @@ class Action extends Component
return $this->showAlert('error', __('Please enter Username'));
}
$this->checkDomainInUsername();
if (strlen((string) $this->username) < json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_min || strlen((string) $this->username) > json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_max) {
return $this->showAlert('error', __('Username length cannot be less than').' '.json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_min.' '.__('and greater than').' '.json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_max);
if (strlen((string) $this->username) < ($this->configSettings->custom_username_length_min ?? 3) || strlen((string) $this->username) > ($this->configSettings->custom_username_length_max ?? 30)) {
return $this->showAlert('error', __('Username length cannot be less than').' '.($this->configSettings->custom_username_length_min ?? 3).' '.__('and greater than').' '.($this->configSettings->custom_username_length_max ?? 30));
}
if (! $this->domain) {
return $this->showAlert('error', __('Please Select a Domain'));
}
if (in_array($this->username, json_decode((string) config('app.settings.configuration_settings'))->forbidden_ids)) {
if (in_array($this->username, $this->configSettings->forbidden_ids ?? [])) {
return $this->showAlert('error', __('Username not allowed'));
}
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of MAX ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail'));
return $this->showAlert('error', __('You have reached daily limit of MAX ').($this->configSettings->email_limit ?? 10).__(' temp mail'));
}
if (! $this->checkUsedEmail()) {
return $this->showAlert('error', __('Sorry! That email is already been used by someone else. Please try a different email address.'));
@@ -66,7 +69,7 @@ class Action extends Component
public function random()
{
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
return $this->showAlert('error', __('You have reached daily limit of maximum ').($this->configSettings->email_limit ?? 10).__(' temp mail addresses.'));
}
$this->email = ZEmail::generateRandomEmail();
@@ -76,7 +79,7 @@ class Action extends Component
public function gmail()
{
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
return $this->showAlert('error', __('You have reached daily limit of maximum ').($this->configSettings->email_limit ?? 10).__(' temp mail addresses.'));
}
$this->email = ZEmail::generateRandomGmail();
@@ -86,7 +89,7 @@ class Action extends Component
public function outlook()
{
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
return $this->showAlert('error', __('You have reached daily limit of maximum ').($this->configSettings->email_limit ?? 10).__(' temp mail addresses.'));
}
$this->email = ZEmail::generateRandomOutlook();
@@ -100,7 +103,7 @@ class Action extends Component
private function showAlert(string $type, $message): void
{
$check = json_decode((string) config('app.settings.configuration_settings'))->email_limit;
$check = $this->configSettings->email_limit ?? 10;
if (str_contains((string) $message, (string) $check)) {
$this->dispatch('promotePremium');
}
@@ -110,13 +113,15 @@ class Action extends Component
private function checkEmailLimit(): bool
{
$logs = Log::query()->select('ip', 'email')->where('ip', request()->ip())->where('created_at', '>', Date::now()->subDay())->groupBy('email')->groupBy('ip')->get();
return count($logs) < json_decode((string) config('app.settings.configuration_settings'))->email_limit;
return count($logs) < ($this->configSettings->email_limit ?? 10);
}
private function checkUsedEmail(): bool
{
if (json_decode((string) config('app.settings.configuration_settings'))->disable_used_email) {
if ($this->configSettings->disable_used_email ?? false) {
$check = Log::query()->where('email', $this->user.'@'.$this->domain)->where('ip', '<>', request()->ip())->count();
return $check <= 0;
}
@@ -139,11 +144,11 @@ class Action extends Component
$data = explode('@', (string) $this->email);
if (isset($data[1])) {
$domain = $data[1];
$domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
$domains = $this->configSettings->domains ?? [];
if (! in_array($domain, $domains)) {
$key = array_search($this->email, $this->emails);
ZEmail::removeEmail($this->email);
if ($key == 0 && count($this->emails) === 1 && json_decode((string) config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
if ($key == 0 && count($this->emails) === 1 && ($this->configSettings->after_last_email_delete ?? '') == 'redirect_to_homepage') {
to_route('home');
} else {
to_route('mailbox');

View File

@@ -3,7 +3,7 @@
// 1. Bootstrap Laravel
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$app = require __DIR__.'/bootstrap/app.php';
// 2. Start Laravel container
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
@@ -14,12 +14,12 @@ set_time_limit(0);
$newTimezone = 'Europe/London';
date_default_timezone_set($newTimezone);
$imapDB = json_decode(config('app.settings.imap_settings'), true);
$imapDB = json_decode(config('app.settings.imap_settings') ?: '{}', true);
// Mailbox credentials
$hostname = '{'.$imapDB['host'].':'.$imapDB['port'].'/ssl}INBOX';
$username = $imapDB['username'];
$password = $imapDB['password'];
$hostname = '{'.($imapDB['host'] ?? 'localhost').':'.($imapDB['port'] ?? '993').'/ssl}INBOX';
$username = $imapDB['username'] ?? '';
$password = $imapDB['password'] ?? '';
// Connect to mailbox
$inbox = imap_open($hostname, $username, $password);

View File

@@ -3,7 +3,7 @@
// 1. Bootstrap Laravel
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$app = require __DIR__.'/bootstrap/app.php';
// 2. Start Laravel container
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
@@ -14,12 +14,12 @@ set_time_limit(0);
$newTimezone = 'Europe/London';
date_default_timezone_set($newTimezone);
$imapDB = json_decode(config('app.settings.imap_settings'), true);
$imapDB = json_decode(config('app.settings.imap_settings') ?: '{}', true);
// Mailbox credentials
$hostname = '{'.$imapDB['premium_host'].':'.$imapDB['premium_port'].'/ssl}INBOX';
$username = $imapDB['premium_username'];
$password = $imapDB['premium_password'];
$hostname = '{'.($imapDB['premium_host'] ?? 'localhost').':'.($imapDB['premium_port'] ?? '993').'/ssl}INBOX';
$username = $imapDB['premium_username'] ?? '';
$password = $imapDB['premium_password'] ?? '';
// Connect to mailbox
$inbox = imap_open($hostname, $username, $password);

View File

@@ -8,12 +8,16 @@
<title>@yield('title', config('app.settings.app_title'))</title>
<meta name="description" content="@yield('description', config('app.settings.app_description'))">
<meta name="keywords" content="@yield('keywords', config('app.settings.app_keyword'))">
@forelse (json_decode(config('app.settings.app_meta')) as $key => $value)
@if ($value)
<meta name="{{ $key }}" content="{{ $value }}">
@endif
@empty
@endforelse
@php
$appMeta = json_decode(config('app.settings.app_meta') ?: '{}');
if (is_array($appMeta) || is_object($appMeta)) {
foreach ($appMeta as $key => $value) {
if ($value) {
echo '<meta name="' . e($key) . '" content="' . e($value) . '">';
}
}
}
@endphp
@yield('metas')
@@ -59,7 +63,10 @@
<p class="px-6 py-4 text-sm dark:bg-zinc-900 bg-zinc-100 dark:text-white accent-zinc-700">Support us by disabling ad blockеrs on our site 🙏</p>
</div>
<div class="magic-box">
{!! json_decode(config('app.settings.ads_settings'))->one !!}
@php
$adsSettings = json_decode(config('app.settings.ads_settings') ?: '{}');
echo $adsSettings->one ?? '';
@endphp
</div>
<flux:spacer />
<flux:navlist variant="outline">
@@ -200,7 +207,7 @@
Looks like you have reached the daily email generation limit, consider subscribing and access to premium features
</p>
</div>
<!-- From Uiverse.io by themrsami -->
<div class="w-full pt-5 px-5 pb-4 bg-zinc-100 dark:bg-zinc-900 rounded-3xl">
<div class="text-center mb-6">
<h5 class="text-2xl font-semibold text-gray-500 mb-3">Zemail Premium</h5>
@@ -263,7 +270,10 @@
<flux:main class="dark:bg-gray-900 bg-gray-100">
{{ $slot }}
<div class="magic-box mt-3">
{!! json_decode(config('app.settings.ads_settings'))->two !!}
@php
$adsSettings = json_decode(config('app.settings.ads_settings') ?: '{}');
echo $adsSettings->two ?? '';
@endphp
</div>
</flux:main>
<!-- Toast Container -->
@@ -276,7 +286,11 @@
setTimeout(() => {
const email = '{{ App\Models\ZEmail::getEmail(true) }}';
const add_mail_in_title = "{{ json_decode(config('app.settings.configuration_settings'))->add_mail_in_title ? 'yes' : 'no' }}"
@php
$configSettings = json_decode(config('app.settings.configuration_settings') ?: '{}');
$addMailInTitle = $configSettings->add_mail_in_title ?? false;
@endphp
const add_mail_in_title = "{{ $addMailInTitle ? 'yes' : 'no' }}"
if(add_mail_in_title === 'yes') {
document.title += ` - ${email}`;
}
@@ -291,14 +305,18 @@
});
});
let counter = parseInt({{ json_decode(config('app.settings.configuration_settings'))->fetch_seconds }});
@php
$configSettings = json_decode(config('app.settings.configuration_settings') ?: '{}');
$fetchSeconds = $configSettings->fetch_seconds ?? 5;
@endphp
let counter = parseInt({{ $fetchSeconds }});
setInterval(() => {
if (counter === 0 && document.getElementById('imap-error') === null && !document.hidden) {
document.querySelectorAll('#refresh-icon').forEach(el => {
el.classList.add('animate-spin');
});
Livewire.dispatch('fetchMessages');
counter = parseInt({{ json_decode(config('app.settings.configuration_settings'))->fetch_seconds }});
counter = parseInt({{ $fetchSeconds }});
}
counter--;
if(document.hidden) {

View File

@@ -8,12 +8,16 @@
<title>@yield('title', config('app.settings.app_title'))</title>
<meta name="description" content="@yield('description', config('app.settings.app_description'))">
<meta name="keywords" content="@yield('keywords', config('app.settings.app_keyword'))">
@forelse (json_decode(config('app.settings.app_meta')) as $key => $value)
@if ($value)
<meta name="{{ $key }}" content="{{ $value }}">
@endif
@empty
@endforelse
@php
$appMeta = json_decode(config('app.settings.app_meta') ?: '{}');
if (is_array($appMeta) || is_object($appMeta)) {
foreach ($appMeta as $key => $value) {
if ($value) {
echo '<meta name="' . e($key) . '" content="' . e($value) . '">';
}
}
}
@endphp
@yield('metas')
@@ -158,14 +162,18 @@
});
});
let counter = parseInt({{ json_decode(config('app.settings.configuration_settings'))->fetch_seconds }});
@php
$configSettings = json_decode(config('app.settings.configuration_settings') ?: '{}');
$fetchSeconds = $configSettings->fetch_seconds ?? 5;
@endphp
let counter = parseInt({{ $fetchSeconds }});
setInterval(() => {
if (counter === 0 && document.getElementById('imap-error') === null && !document.hidden) {
document.querySelectorAll('#refresh-icon').forEach(el => {
el.classList.add('animate-spin');
});
Livewire.dispatch('fetchMessages');
counter = parseInt({{ json_decode(config('app.settings.configuration_settings'))->fetch_seconds }});
counter = parseInt({{ $fetchSeconds }});
}
counter--;
if(document.hidden) {

View File

@@ -20,7 +20,10 @@
<img class="min-w-full px-4 pt-4 sm:pt-6 sm:px-6 rounded-tl-4xl rounded-tr-4xl rounded-bl-3xl rounded-br-3xl" src="{{ asset('storage/'.$postDetail->post_image) }}" alt="{{ $postDetail->post }}" />
</span>
<div class="magic-box my-2 px-4 sm:px-6 min-w-full flex flex-col items-center overflow-auto">
{!! json_decode(config('app.settings.ads_settings'))->two !!}
@php
$adsSettings = json_decode(config('app.settings.ads_settings') ?: '{}');
echo $adsSettings->two ?? '';
@endphp
</div>
<div class="flex w-full items-center justify-center px-4 py-2 sm:px-6">
<flux:text>{!! $postDetail->content !!}</flux:text>

View File

@@ -7,7 +7,11 @@
<flux:heading class="mb-3" size="xl" level="1">Inbox</flux:heading>
<div class="mb-3"></div>
@foreach(array_reverse($messages) as $i => $message)
@if($i % 5 == 0 && json_decode(config('app.settings.ads_settings'))->five)
@php
$adsSettings = json_decode(config('app.settings.ads_settings') ?: '{}');
$showAdFive = $adsSettings->five ?? false;
@endphp
@if($i % 5 === 0 && $showAdFive)
@endif
<div class="inbox-list cursor-pointer" x-on:click="show = true; id = {{ $message['id'] }};" data-id="{{ $message['id'] }}">