Notice: require(): Read of 60808 bytes failed with errno=14 Bad address in /home/mazadatland/public_html/vendor/composer/autoload_real.php on line 78
Notice: require(): Read of 60808 bytes failed with errno=12 Cannot allocate memory in /home/mazadatland/public_html/vendor/composer/autoload_real.php on line 78
Notice: require(): Read of 60808 bytes failed with errno=14 Bad address in /home/mazadatland/public_html/vendor/composer/autoload_real.php on line 78
anel(string $url = null): bool
{
if (empty($url)) {
$isValid = (
request()->segment(1) == admin_uri()
|| request()->segment(1) == 'impersonate'
|| str_contains(currentRouteAction(), '\Admin\\')
);
} else {
try {
$urlPath = '/' . ltrim(parse_url($url, PHP_URL_PATH), '/');
$adminUri = '/' . ltrim(admin_uri(), '/');
$isValid = (
str_starts_with($urlPath, $adminUri)
|| str_starts_with($urlPath, '/impersonate')
);
} catch (\Throwable $e) {
$isValid = false;
}
}
return $isValid;
}
/**
* Check dev environment
*
* @param string|null $url
* @return bool
*/
function isDevEnv(string $url = null): bool
{
if (empty($url)) {
$url = config('app.url');
}
$domain = getDomain($url);
return (
str_contains($domain, 'bedigit.local')
|| str_contains($domain, 'laraclassifier.local')
);
}
/**
* Check demo environment
*
* @param string|null $url
* @return bool
*/
function isDemoEnv(string $url = null): bool
{
if (empty($url)) {
$url = config('app.url');
}
return (
getDomain($url) == config('larapen.core.demo.domain')
|| in_array(getHost($url), (array)config('larapen.core.demo.hosts'))
);
}
/**
* Check the demo website domain
*
* @param string|null $url
* @return bool
*/
function isDemoDomain(string $url = null): bool
{
$isDemoDomain = isDemoEnv($url);
if (!$isDemoDomain) {
return false;
}
if (auth()->check()) {
if (
auth()->user()->can(Permission::getStaffPermissions())
&& md5(auth()->user()->id) == 'c4ca4238a0b923820dcc509a6f75849b'
) {
$isDemoDomain = false;
}
}
return $isDemoDomain;
}
/**
* Get the Country Code from URI Path
*
* @return string|null
*/
function getCountryCodeFromPath(): ?string
{
$countryCode = null;
// With these URLs, the language code and the country code can be available in the segments
// (If the "Multi-countries URLs Optimization" is enabled)
if (isFromUrlThatCanContainCountryCode()) {
$countryCode = request()->segment(1);
}
// With these URLs, the language code and the country code are available in the segments
if (isFromUrlAlwaysContainingCountryCode()) {
$countryCode = request()->segment(2);
}
return $countryCode;
}
/**
* Check if user is coming from a URL that can contain the country code
* With these URLs, the language code and the country code can be available in the segments
* (If the "Multi-countries URLs Optimization" is enabled)
*
* @return bool
*/
function isFromUrlThatCanContainCountryCode(): bool
{
if (config('settings.seo.multi_country_urls')) {
if (
str_contains(currentRouteAction(), 'SearchController')
|| str_contains(currentRouteAction(), 'CategoryController')
|| str_contains(currentRouteAction(), 'CityController')
|| str_contains(currentRouteAction(), 'UserController')
|| str_contains(currentRouteAction(), 'TagController')
|| str_contains(currentRouteAction(), 'CompanyController')
|| str_contains(currentRouteAction(), 'SitemapController')
) {
return true;
}
}
return false;
}
/**
* Check if called page can always have the country code
* With these URLs, the language code and the country code are available in the segments
*
* @param string|null $url
* @return bool
*/
function isFromUrlAlwaysContainingCountryCode(string $url = null): bool
{
if (empty($url)) {
$isValid = (
str_ends_with(request()->url(), '.xml')
|| str_contains(currentRouteAction(), 'SitemapsController')
);
} else {
$isValid = (str_ends_with($url, '.xml'));
}
return $isValid;
}
/**
* Transform Description column before displaying it
*
* @param $string
* @return string
*/
function transformDescription($string)
{
if (config('settings.single.wysiwyg_editor') != 'none') {
try {
$string = \Mews\Purifier\Facades\Purifier::clean($string);
} catch (\Throwable $e) {
// Nothing.
}
$string = urls_to_links($string);
} else {
$string = nl2br(urls_to_links(mb_str_cleaner($string)));
}
return $string;
}
/**
* Tags Cleaner
* Prevent problem with the #hashtags when they are only numeric
*
* @param $tagString
* @param bool $forceArrayReturn
* @return array|string|null
*/
function tagCleaner($tagString, bool $forceArrayReturn = false)
{
$limit = (int)config('settings.single.tags_limit', 15);
return taggable($tagString, $limit, $forceArrayReturn);
}
/**
* Return an array of spoken languages in the selected country
*
* @return array
*/
function getCountrySpokenLanguages(): array
{
$supportedLanguages = getSupportedLanguages();
$spokenLanguages = config('country.languages');
$spokenLanguages = explode(',', $spokenLanguages);
if (config('settings.localization.show_country_spoken_languages') == 'active_with_en') {
$spokenLanguages[] = 'en';
}
if (config('settings.localization.show_country_spoken_languages') == 'active_with_main') {
$spokenLanguages[] = strtolower(config('appLang.code'));
}
if (empty($spokenLanguages)) return [];
return collect($spokenLanguages)
->unique()
->map(function ($item) use ($supportedLanguages) {
if (empty($supportedLanguages)) return $item;
foreach ($supportedLanguages as $code => $lang) {
if (str_starts_with($code, $item)) {
$item = $lang;
break; // Important
}
}
return $item;
})
->filter(fn ($item) => is_array($item))
->keyBy('code')
->toArray();
}
/**
* Return an array of all supported languages
*
* @return array
*/
function getSupportedLanguages(): array
{
$cacheExpiration = (int)config('settings.optimization.cache_expiration', 86400);
// Get supported languages from database
try {
// Get all DB Languages
$cacheId = 'languages.active.array';
$supportedLanguages = cache()->remember($cacheId, $cacheExpiration, function () {
return \App\Models\Language::where('active', 1)->orderBy('lft')->get();
});
$supportedLanguages = collect($supportedLanguages->toArray());
if ($supportedLanguages->isNotEmpty()) {
$supportedLanguages = $supportedLanguages->keyBy('code');
}
} catch (\Throwable $e) {
/*
* Database or tables don't exist.
* The script will display an error or will start the installation.
* Please don't change anything here.
*/
$supportedLanguages = collect();
}
return $supportedLanguages->toArray();
}
/**
* Check if language code is available
*
* @param string|null $code
* @return bool
*/
function isAvailableLang(?string $code): bool
{
$cacheExpiration = (int)config('settings.optimization.cache_expiration', 86400);
$cacheId = 'language.' . $code;
$lang = cache()->remember($cacheId, $cacheExpiration, function () use ($code) {
return \App\Models\Language::where('code', $code)->first();
});
return !empty($lang);
}
/**
* @return string
*/
function detectLocale(): string
{
$lang = detectLanguage();
$defaultLocale = 'en_US';
$locale = !$lang->isEmpty() ? $lang->get('locale') : $defaultLocale;
return getAsString($locale, $defaultLocale);
}
/**
* @return \Illuminate\Support\Collection
*/
function detectLanguage(): \Illuminate\Support\Collection
{
$obj = new App\Helpers\Localization\Language();
return $obj->find();
}
/**
* Get all countries from PHP array (umpirsky)
*
* @return array|null
*/
function getCountriesFromArray(): ?array
{
$countries = new App\Helpers\Localization\Helpers\Country();
$countries = $countries->all();
if (empty($countries)) return null;
$arr = [];
foreach ($countries as $code => $value) {
if (!file_exists(storage_path('database/geonames/countries/' . strtolower($code) . '.sql'))) {
continue;
}
$row = ['value' => $code, 'text' => $value];
$arr[] = $row;
}
return $arr;
}
/**
* Get all countries from DB (Geonames) & Translate them
*
* @param bool $includeNonActive
* @return array
*/
function getCountries(bool $includeNonActive = false): array
{
$arr = [];
// Get installed countries list
$countries = CountryHelper::getCountries($includeNonActive);
if ($countries->count() > 0) {
foreach ($countries as $code => $country) {
// The country entry must be a Laravel Collection object
if (!$country instanceof \Illuminate\Support\Collection) {
$country = collect($country);
}
// Get the country data
$code = ($country->has('code')) ? $country->get('code') : $code;
$name = ($country->has('name')) ? $country->get('name') : '';
$arr[$code] = $name;
}
}
return $arr;
}
/**
* Pluralization
*
* @param $number
* @return int
*/
function getPlural($number)
{
return number_plural($number, config('lang.russian_pluralization'));
}
/**
* Get URL of Page by page's type
*
* @param string|null $type
* @param string|null $locale
* @return string
*/
function getUrlPageByType(?string $type, string $locale = null): string
{
if (is_null($locale)) {
$locale = config('app.locale');
}
$cacheExpiration = (int)config('settings.optimization.cache_expiration', 86400);
$cacheId = 'page.' . $locale . '.type.' . $type;
$page = cache()->remember($cacheId, $cacheExpiration, function () use ($type, $locale) {
$page = \App\Models\Page::type($type)->first();
if (!empty($page)) {
$page->setLocale($locale);
}
return $page;
});
$linkTarget = '';
$linkRel = '';
if (!empty($page)) {
if ($page->target_blank == 1) {
$linkTarget = ' target="_blank"';
}
if (!empty($page->external_link)) {
$linkRel = ' rel="nofollow"';
$url = $page->external_link;
} else {
$url = \App\Helpers\UrlGen::page($page);
}
} else {
$url = '#';
}
// Get attributes
return 'href="' . $url . '"' . $linkRel . $linkTarget;
}
/**
* @param string|null $uploadType
* @param bool $jsFormat
* @return array|false|\Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed|string|string[]
*/
function getUploadFileTypes(?string $uploadType = 'file', bool $jsFormat = false)
{
if ($uploadType == 'image') {
$types = config('settings.upload.image_types', 'jpg,jpeg,gif,png');
} else {
$types = config('settings.upload.file_types', 'pdf,doc,docx,word,rtf,rtx,ppt,pptx,odt,odp,wps,jpeg,jpg,bmp,png');
}
$separators = ['|', '-', ';', '.', '/', '_', ' '];
$types = str_replace($separators, ',', $types);
if ($jsFormat) {
$types = explode(',', $types);
$types = array_filter($types, function ($value) {
return $value !== '';
});
$types = json_encode($types);
}
return $types;
}
/**
* @param string|null $uploadType
* @return array|mixed|string
*/
function showValidFileTypes(?string $uploadType = 'file')
{
$formats = getUploadFileTypes($uploadType);
return str_replace(',', ', ', $formats);
}
/**
* Get Public File's URL
*
* @param string|null $filePath
* @return \Illuminate\Contracts\Routing\UrlGenerator|string
*/
function fileUrl(?string $filePath)
{
// Storage Disk Init.
$disk = \App\Helpers\Files\Storage\StorageDisk::getDisk();
try {
return $disk->url($filePath);
} catch (\Throwable $e) {
return url('common/file?path=' . $filePath);
}
}
/**
* Get Private File's URL
*
* @param string|null $filePath
* @param string|null $diskName
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\UrlGenerator|string
*/
function privateFileUrl(?string $filePath, ?string $diskName = 'private')
{
$queryString = 'path=' . $filePath;
// For JC
if (str_starts_with($filePath, 'resumes/')) {
$diskName = 'private';
}
if (!empty($diskName)) {
$queryString = 'disk=' . $diskName . '&' . $queryString;
}
return url('common/file?' . $queryString);
}
/**
* @param string|null $filePath
* @param string|null $preConfigSize
* @param array|null $attr
* @return string
*/
function imgTag(?string $filePath, ?string $preConfigSize = 'big', ?array $attr = []): string
{
$src = imgUrl($filePath, $preConfigSize);
$attr = buildAttributes($attr);
$out = '';
if (config('settings.optimization.webp_format')) {
$srcWebp = imgUrl($filePath, $preConfigSize, true);
if (!str_ends_with($srcWebp, '.webp')) {
$out .= '';
} else {
$out .= '';
}
} else {
$out .= '';
}
return $out;
}
/**
* @param string|null $filePath
* @param string|null $preConfigSize
* @param bool $webpFormat
* @return string
*/
function imgUrl(?string $filePath, ?string $preConfigSize = 'big', bool $webpFormat = false): string
{
// Storage Disk Init.
$disk = \App\Helpers\Files\Storage\StorageDisk::getDisk();
// Check if this is the default picture
if (
str_contains($filePath, config('larapen.core.logo'))
|| str_contains($filePath, config('larapen.core.favicon'))
|| str_contains($filePath, config('larapen.core.picture.default'))
|| str_contains($filePath, config('larapen.core.avatar.default'))
|| str_contains($filePath, config('larapen.admin.logo.dark'))
|| str_contains($filePath, config('larapen.admin.logo.light'))
) {
return $disk->url($filePath) . getPictureVersion();
}
// Get pre-resized picture URL
$picTypesAdmin = ['logo', 'cat', 'small', 'medium', 'big'];
$picTypesOther = array_keys((array)config('larapen.core.picture.otherTypes'));
$picTypesGlobal = array_merge($picTypesAdmin, $picTypesOther);
if (!in_array($preConfigSize, $picTypesGlobal)) {
try {
return $disk->url($filePath) . getPictureVersion();
} catch (\Throwable $e) {
return url('common/file?path=' . $filePath) . getPictureVersion(true);
}
}
// Check, Create thumbnail and Get its URL
if ($webpFormat) {
return resizeWebp($disk, $filePath, $preConfigSize);
} else {
return resize($disk, $filePath, $preConfigSize);
}
}
/**
* @param $disk
* @param string|null $filePath
* @param string|null $preConfigSize
* @param bool $webpFormat
* @return string
*/
function resize($disk, ?string $filePath, ?string $preConfigSize = 'big', bool $webpFormat = false): string
{
// Image Quality
$imageQuality = config('settings.upload.image_quality', 90);
// Get Dimensions
$defaultWidth = config('larapen.core.picture.otherTypes.' . $preConfigSize . '.width', 816);
$defaultHeight = config('larapen.core.picture.otherTypes.' . $preConfigSize . '.height', 460);
$width = (int)config('settings.upload.img_resize_' . $preConfigSize . '_width', $defaultWidth);
$height = (int)config('settings.upload.img_resize_' . $preConfigSize . '_height', $defaultHeight);
$filename = (!str_ends_with($filePath, DIRECTORY_SEPARATOR)) ? basename($filePath) : '';
$fileDir = str_replace($filename, '', $filePath);
$fileDir = rtrim($fileDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
// WebP
$filenameWithoutExtension = substr($filename, 0, strrpos($filename, '.'));
$webpFilename = $filenameWithoutExtension . '.webp';
if ($webpFormat) {
$filename = $webpFilename;
}
// Thumb file name
$sizeLabel = $width . 'x' . $height;
$thumbFilename = 'thumb-' . $sizeLabel . '-' . $filename;
$thumbFilePath = $fileDir . $thumbFilename;
// Check if thumb image exists
if (!$disk->exists($thumbFilePath)) {
// Create thumb image if it not exists
try {
// Get file extension
if ($webpFormat) {
$extension = 'webp';
} else {
$extension = (is_png($disk->get($filePath))) ? 'png' : 'jpg';
}
// Init. Intervention
$image = \Intervention\Image\Facades\Image::make($disk->get($filePath));
// Get the image original dimensions
$imgWidth = $image->width();
$imgHeight = $image->height();
// Manage Image By Type
// Get Other Types Parameters
if (in_array($preConfigSize, array_keys((array)config('larapen.core.picture.otherTypes')))) {
// Get image manipulation settings
$width = (int)config('larapen.core.picture.otherTypes.' . $preConfigSize . '.width', 900);
$height = (int)config('larapen.core.picture.otherTypes.' . $preConfigSize . '.height', 900);
$ratio = config('larapen.core.picture.otherTypes.' . $preConfigSize . '.ratio', '1');
$upSize = config('larapen.core.picture.otherTypes.' . $preConfigSize . '.upsize', '0');
// If the original dimensions are higher than the resize dimensions
// OR the 'upsize' option is enable, then resize the image
if ($imgWidth > $width || $imgHeight > $height) {
// Resize
$image = $image->resize($width, $height, function ($constraint) use ($ratio, $upSize) {
if ($ratio == '1') {
$constraint->aspectRatio();
}
if ($upSize == '1') {
$constraint->upsize();
}
});
}
} else if (in_array($preConfigSize, ['logo', 'cat'])) {
// Get image manipulation settings
$ratio = config('settings.upload.img_resize_' . $preConfigSize . '_ratio', '1');
$upSize = config('settings.upload.img_resize_' . $preConfigSize . '_upsize', '0');
// If the original dimensions are higher than the resize dimensions
// OR the 'upsize' option is enable, then resize the image
if ($imgWidth > $width || $imgHeight > $height || $upSize == '1') {
// Resize
$image = $image->resize($width, $height, function ($constraint) use ($ratio, $upSize) {
if ($ratio == '1') {
$constraint->aspectRatio();
}
if ($upSize == '1') {
$constraint->upsize();
}
});
}
} else if (in_array($preConfigSize, ['large', 'big', 'medium', 'small'])) {
// Get image manipulation settings
$resizeType = config('settings.upload.img_resize_' . $preConfigSize . '_resize_type', '0');
$ratio = config('settings.upload.img_resize_' . $preConfigSize . '_ratio', '1');
$upSize = config('settings.upload.img_resize_' . $preConfigSize . '_upsize', '0');
$position = config('settings.upload.img_resize_' . $preConfigSize . '_position', 'center');
$relative = config('settings.upload.img_resize_' . $preConfigSize . '_relative', false);
$bgColor = config('settings.upload.img_resize_' . $preConfigSize . '_bg_color', 'ffffff');
if ($resizeType == '0') {
if ($imgWidth > $width || $imgHeight > $height || $upSize == '1') {
// Resize
$image = $image->resize($width, $height, function ($constraint) use ($ratio, $upSize) {
if ($ratio == '1') {
$constraint->aspectRatio();
}
if ($upSize == '1') {
$constraint->upsize();
}
});
}
} else if ($resizeType == '1') {
// Fit
$image = $image->fit($width, $height, function ($constraint) use ($ratio, $upSize) {
if ($ratio == '1') {
$constraint->aspectRatio();
}
if ($upSize == '1') {
$constraint->upsize();
}
});
} else if ($resizeType == '2') {
if ($imgWidth > $width || $imgHeight > $height || $upSize == '1') {
// Resize (for ResizeCanvas)
$image = $image->resize($width, $height, function ($constraint) use ($ratio, $upSize) {
if ($ratio == '1') {
$constraint->aspectRatio();
}
if ($upSize == '1') {
$constraint->upsize();
}
});
}
// ResizeCanvas
$image = $image->resizeCanvas($width, $height, $position, $relative, $bgColor)->resize($width, $height);
} else {
if ($imgWidth > $width || $imgHeight > $height) {
// Resize (with hard parameters)
$image = $image->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
}
}
} else {
if ($imgWidth > $width || $imgHeight > $height) {
// Resize (with hard parameters)
$image = $image->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
}
}
// Encode the Image!
$image = $image->encode($extension, $imageQuality);
} catch (\Throwable $e) {
$storageDisk = \Illuminate\Support\Facades\Storage::disk(config('filesystems.default'));
return $storageDisk->url($filePath) . getPictureVersion();
}
// Store the image on disk.
$disk->put($thumbFilePath, $image->stream()->__toString());
// Now delete temporary intervention image as we have moved it to Storage folder with Laravel filesystem.
$image->destroy();
}
// Get the image URL
try {
return $disk->url($thumbFilePath) . getPictureVersion();
} catch (\Throwable $e) {
return url('common/file?path=' . $thumbFilePath) . getPictureVersion();
}
}
/**
* @param $disk
* @param string|null $filePath
* @param string|null $type
* @return string
*/
function resizeWebp($disk, ?string $filePath, ?string $type = 'big'): string
{
return resize($disk, $filePath, $type, true);
}
/**
* Get pictures version
*
* @param bool $queryStringExists
* @return string
*/
function getPictureVersion(bool $queryStringExists = false): string
{
$pictureVersion = '';
if (config('larapen.core.picture.versioned') && !empty(config('larapen.core.picture.version'))) {
$pictureVersion .= ($queryStringExists) ? '&' : '?';
$pictureVersion .= 'v=' . config('larapen.core.picture.version');
}
return $pictureVersion;
}
/**
* List of auth fields | List of notification channels
*
* @param bool $asChannel
* @return array
*/
function getAuthFields(bool $asChannel = false): array
{
$authFields = [
'email' => $asChannel ? trans('settings.mail') : trans('global.email_address'),
];
$phoneIsEnabledAsAuthField = (config('settings.sms.enable_phone_as_auth_field') == '1');
if ($phoneIsEnabledAsAuthField) {
$authFields['phone'] = $asChannel ? trans('settings.sms') : trans('global.phone_number');
}
return $authFields;
}
/**
* Get the auth field
*
* @param $entity
* @return string
*/
function getAuthField($entity = null): string
{
$authFields = array_keys(getAuthFields());
$defaultAuthField = config('settings.sms.default_auth_field', 'email');
// From default value
$authField = $defaultAuthField;
// From authenticated user's data
$guard = isFromApi() ? 'sanctum' : null;
if (auth($guard)->check()) {
$savedValue = auth($guard)->user()->auth_field ?? $authField;
$authField = (!empty($savedValue)) ? $savedValue : $authField;
}
// From a database table
// '$entity' can be any table object that has 'auth_field' column
if (!empty($entity)) {
$savedValue = (is_array($entity))
? ($entity['auth_field'] ?? $defaultAuthField)
: ($entity->auth_field ?? $defaultAuthField);
$authField = (!empty($savedValue)) ? $savedValue : $defaultAuthField;
}
// From form
if (request()->filled('auth_field')) {
$authField = request()->input('auth_field');
}
$authField = (in_array($authField, $authFields)) ? $authField : $defaultAuthField;
$phoneIsEnabledAsAuthField = (config('settings.sms.enable_phone_as_auth_field') == '1');
return ($phoneIsEnabledAsAuthField) ? $authField : 'email';
}
/**
* Get the auth field name from its value
*
* @param string|null $value
* @return string
*/
function getAuthFieldFromItsValue(?string $value = null): string
{
$field = 'username';
if (filter_var($value, FILTER_VALIDATE_EMAIL)) {
$field = 'email';
} else if (preg_match('/^((\+|00)\d{1,3})?[\s\d]+$/', $value)) {
$field = 'phone';
}
return $field;
}
/**
* Get the auth field from the Token page
*
* @return string|null
*/
function getAuthFieldOnTokenPage(): ?string
{
$authFields = array_keys(getAuthFields());
// Get the right auth field
$authField = null;
if (request()->segment(2) == 'verify') {
if (
!empty(request()->segment(3))
&& in_array(request()->segment(3), $authFields)
) {
$authField = request()->segment(3);
}
}
return $authField;
}
/**
* @param $defaultCountryCode
* @return mixed
*/
function getPhoneCountry($defaultCountryCode = null)
{
$countryCode = isFromApi() ? config('country.code') : session('countryCode');
$countryCode = $defaultCountryCode ?? $countryCode;
$countryCode = request()->input('country_code', $countryCode);
return request()->input('phone_country', $countryCode);
}
/**
* @param bool $allowUserToChoose
* @return bool
*/
function isUsersCanChooseNotifyChannel(bool $allowUserToChoose = false): bool
{
$usersCanChooseNotifyChannel = (config('settings.sms.enable_phone_as_auth_field') == '1');
if ($allowUserToChoose) {
return $usersCanChooseNotifyChannel;
}
if (auth()->check()) {
$usersCanChooseNotifyChannel = (
$usersCanChooseNotifyChannel
&& config('settings.sms.messenger_notifications') == '1'
);
}
return $usersCanChooseNotifyChannel;
}
/**
* @return bool
*/
function isBothAuthFieldsCanBeDisplayed(): bool
{
$emailNeedToBeVerified = (config('settings.mail.email_verification') == '1');
$phoneNeedToBeVerified = (config('settings.sms.phone_verification') == '1');
$isBothAuthFieldNeedToBeVerified = ($emailNeedToBeVerified && $phoneNeedToBeVerified);
$isBothAuthFieldsCanBeDisplayed = (bool)config('larapen.core.displayBothAuthFields');
if ($isBothAuthFieldNeedToBeVerified) {
return false;
}
return $isBothAuthFieldsCanBeDisplayed;
}
/**
* @return array|\Illuminate\Contracts\Translation\Translator|string|null
*/
function getTokenLabel()
{
$authField = getAuthFieldOnTokenPage();
if ($authField == 'email') {
return t('Code received by Email');
}
if ($authField == 'phone') {
return t('Code received by SMS');
}
return t('Code received by SMS or Email');
}
/**
* @return array|\Illuminate\Contracts\Translation\Translator|string|null
*/
function getTokenMessage()
{
$authField = getAuthFieldOnTokenPage();
if ($authField == 'email') {
return t('Enter the code you received by Email in the field below');
}
if ($authField == 'phone') {
return t('Enter the code you received by SMS in the field below');
}
return t('Enter the code you received by SMS or Email in the field below');
}
/**
* Replace global variables patterns from string
*
* @param string|null $string
* @param bool $removeUnmatchedPatterns
* @return string|string[]
*/
function replaceGlobalPatterns(?string $string, bool $removeUnmatchedPatterns = true)
{
$string = str_replace('{app.name}', config('app.name'), $string);
$string = str_replace('{country.name}', config('country.name'), $string);
$string = str_replace('{country}', config('country.name'), $string);
if (config('settings.app.slogan')) {
$string = str_replace('{app.slogan}', config('settings.app.slogan'), $string);
}
if (str_contains($string, '{count.listings}')) {
try {
$countPosts = Post::query()->inCountry()->has('country')->unarchived()->count();
} catch (\Throwable $e) {
$countPosts = 0;
}
$string = str_replace('{count.listings}', $countPosts, $string);
}
if (str_contains($string, '{count.users}')) {
try {
$countUsers = User::query()->count();
} catch (\Throwable $e) {
$countUsers = 0;
}
$string = str_replace('{count.users}', $countUsers, $string);
}
if ($removeUnmatchedPatterns) {
$string = removeUnmatchedPatterns($string);
}
return $string;
}
/**
* Get meta tag from settings
*
* @param string|null $page
* @return array
*/
function getMetaTag(?string $page): array
{
$metaTag = ['title' => '', 'description' => '', 'keywords' => ''];
// Check if the Domain Mapping plugin is available
if (config('plugins.domainmapping.installed')) {
$metaTag = \extras\plugins\domainmapping\Domainmapping::getMetaTag($page);
if (!empty($metaTag) && !arrayItemsAreEmpty($metaTag)) {
return $metaTag;
}
}
// Get the current Language
$languageCode = config('lang.code', config('app.locale'));
// Get the Page's MetaTag
$model = null;
try {
$cacheExpiration = (int)config('settings.optimization.cache_expiration', 86400);
$cacheId = 'metaTag.' . $languageCode . '.' . $page;
$model = cache()->remember($cacheId, $cacheExpiration, function () use ($languageCode, $page) {
$model = \App\Models\MetaTag::where('page', $page)->first(['title', 'description', 'keywords']);
if (!empty($model)) {
$model->setLocale($languageCode);
$model = $model->toArray();
}
return $model;
});
} catch (\Throwable $e) {
}
if (!empty($model)) {
$metaTag = $model;
$metaTag['title'] = getColumnTranslation($metaTag['title'], $languageCode);
$metaTag['description'] = getColumnTranslation($metaTag['description'], $languageCode);
$metaTag['keywords'] = getColumnTranslation($metaTag['keywords'], $languageCode);
$metaTag['title'] = replaceGlobalPatterns($metaTag['title'], false);
$metaTag['description'] = replaceGlobalPatterns($metaTag['description'], false);
$metaTag['keywords'] = mb_strtolower(replaceGlobalPatterns($metaTag['keywords'], false));
return array_values($metaTag);
}
$pagesThatHaveTheirOwnDefaultMetaTags = [
'search',
'searchCategory',
'searchLocation',
'searchProfile',
'searchTag',
'listingDetails',
'staticPage',
];
if (!in_array($page, $pagesThatHaveTheirOwnDefaultMetaTags)) {
if (config('settings.app.slogan')) {
$metaTag['title'] = config('app.name') . ' - ' . config('settings.app.slogan');
} else {
$metaTag['title'] = config('app.name') . ' - ' . config('country.name');
}
$metaTag['description'] = $metaTag['title'];
}
if (!is_array($metaTag)) {
$metaTag = [];
}
$metaTag['title'] = $metaTag['title'] ?? null;
$metaTag['description'] = $metaTag['description'] ?? null;
$metaTag['keywords'] = $metaTag['keywords'] ?? null;
return is_array($metaTag) ? array_values($metaTag) : [];
}
/**
* Get the Distance Calculation Unit
*
* @param string|null $countryCode
* @return string
*/
function getDistanceUnit(string $countryCode = null)
{
if (empty($countryCode)) {
$countryCode = config('country.code');
}
$unit = \Larapen\LaravelDistance\Helper::getDistanceUnit($countryCode);
return t($unit);
}
/**
* Get Front Skin
*
* @param string|null $skin
* @return \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed
*/
function getFrontSkin(string $skin = null)
{
$savedSkin = config('settings.style.skin', 'default');
if (!empty($skin)) {
$skinsArray = config('larapen.core.skins');
if (!is_array($skinsArray) || !array_key_exists($skin, $skinsArray)) {
$skin = $savedSkin;
}
} else {
$skin = $savedSkin;
}
return $skin;
}
/**
* Hashids is a small PHP library to generate YouTube-like ids from numbers.
* Use it when you don't want to expose your database numeric ids to users
*
* @param $in
* @param bool $toNum
* @param bool $withPrefix
* @param int $minHashLength
* @param string $salt
* @return array|mixed|string|null
*/
function hashId($in, bool $toNum = false, bool $withPrefix = true, int $minHashLength = 11, string $salt = '')
{
if (!config('settings.seo.listing_hashed_id_enabled') && !isHashedId($in)) {
return $in;
}
$hidPrefix = $withPrefix ? config('larapen.core.hashableIdPrefix') : '';
$hidPrefix = is_string($hidPrefix) ? $hidPrefix : '';
$hashIds = new \Hashids\Hashids($salt, $minHashLength);
if (!$toNum) {
$out = $hidPrefix . $hashIds->encode($in);
} else {
$in = ltrim($in, $hidPrefix);
$out = $hashIds->decode($in);
if (isset($out[0])) {
$out = $out[0];
}
}
return !empty($out) ? $out : null;
}
/**
* @param $in
* @param int $minHashLength
* @return bool
*/
function isHashedId($in, int $minHashLength = 11): bool
{
$hidPrefix = config('larapen.core.hashableIdPrefix');
$hidPrefixLength = is_string($hidPrefix) ? strlen($hidPrefix) : 0;
return (
preg_match('/[a-z0-9A-Z]+/', $in)
&& (strlen($in) == ($minHashLength + $hidPrefixLength))
);
}
/**
* Get routes prefixes to ban to match listing route's path
*
* @return array
*/
function regexSimilarRoutesPrefixes(): array
{
$routes = (array)config('routes');
$prefixes = [];
foreach ($routes as $route) {
$prefix = head(explode('/', $route));
if (!str_starts_with($prefix, '{')) {
$prefixes[] = $prefix;
}
}
return array_unique($prefixes);
}
/**
* Check if the user browser is the given value.
* The given value can be:
* 'Firefox', 'Chrome', 'Safari', 'Opera', 'MSIE', 'Trident', 'Edge'
*
* Usage: doesUserBrowserIs('Chrome') or doesUserBrowserIs() == 'Chrome'
*
* @param string|null $browser
* @return bool
*/
function doesUserBrowserIs(string $browser = null): bool
{
if (!empty($browser)) {
return (str_contains(request()->server('HTTP_USER_AGENT'), $browser));
} else {
$browsers = ['Firefox', 'Chrome', 'Safari', 'Opera', 'MSIE', 'Trident', 'Edge'];
$agent = request()->server('HTTP_USER_AGENT');
$userBrowser = null;
foreach ($browsers as $browser) {
if (str_contains($agent, $browser)) {
$userBrowser = $browser;
break;
}
}
return !empty($userBrowser);
}
}
/**
* Get sitemaps indexes
*
* @param bool $htmlFormat
* @return string
*/
function getSitemapsIndexes(bool $htmlFormat = false): string
{
$out = '';
$countries = \App\Helpers\Localization\Helpers\Country::transAll(CountryHelper::getCountries());
if (!$countries->isEmpty()) {
if ($htmlFormat) {
$cmFieldStyle = ($countries->count() > 10) ? ' style="height: 205px; overflow-y: scroll;"' : '';
$out .= '
';
}
foreach ($countries as $country) {
if (!$country instanceof Collection) {
continue;
}
$country = CountryHelper::getCountryInfo($country->get('code'));
if ($country->isEmpty()) {
continue;
}
/*
// Get the Country's Language Code
$countryLang = $country->has('lang') ? $country->get('lang') : collect();
$countryLang = ($countryLang instanceof Collection) ? $countryLang : collect();
$countryLangCode = $countryLang->has('code') ? $countryLang->get('code') : config('app.locale');
*/
// Add the Sitemap Index
if ($htmlFormat) {
$out .= '