190 lines
No EOL
5 KiB
PHP
190 lines
No EOL
5 KiB
PHP
<?php
|
|
|
|
use App\Services\AboHelper;
|
|
use App\Domain\DomainContext;
|
|
use App\Services\DomainService;
|
|
|
|
if (! function_exists('make_old_url')) {
|
|
function make_old_url($path)
|
|
{
|
|
return config('app.old_url').$path;
|
|
}
|
|
}
|
|
|
|
|
|
if (! function_exists('make_old_url')) {
|
|
function make_old_url($path)
|
|
{
|
|
return config('app.old_url').$path;
|
|
}
|
|
}
|
|
|
|
if (! function_exists('get_file_last_time')) {
|
|
function get_file_last_time($value)
|
|
{
|
|
if (file_exists($value)) {
|
|
return filemtime($value);
|
|
}
|
|
return date("Ymd-is", time());
|
|
}
|
|
}
|
|
|
|
if (! function_exists('get_user_attr')) {
|
|
function get_user_attr($key){
|
|
if ($user = Auth::user()) {
|
|
return $user->getSetting($key);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
if (! function_exists('set_user_attr')) {
|
|
function set_user_attr($key, $value){
|
|
if ($user = Auth::user()) {
|
|
return $user->setSetting([$key => $value]);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
if (! function_exists('get_active_badge')) {
|
|
function get_active_badge($active, $tooltip = false, $pos = "top")
|
|
{
|
|
if($tooltip){
|
|
$tooltip = 'data-toggle="tooltip" data-placement="top" data-original-title="'.$tooltip.'"';
|
|
}
|
|
return $active ? '<span class="badge badge-pill badge-success" '.$tooltip.'><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger" '.$tooltip.'><i class="fa fa-times"></i></span>';
|
|
}
|
|
}
|
|
|
|
if (! function_exists('formatNumber')) {
|
|
function formatNumber($number, $dec=2)
|
|
{
|
|
return !$number ? $number : Util::formatNumber($number, $dec);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('reFormatNumber')) {
|
|
function reFormatNumber($number)
|
|
{
|
|
return !$number ? $number : Util::reFormatNumber($number);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('cleanNumberFormat')) {
|
|
function cleanNumberFormat($number)
|
|
{
|
|
return !$number ? $number : Util::cleanNumberFormat($number);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('formatDate')) {
|
|
function formatDate($date)
|
|
{
|
|
return Carbon::parse($date)->format(\Util::formatDateDB());
|
|
}
|
|
}
|
|
|
|
if (! function_exists('maxStrLength')) {
|
|
function maxStrLength($str, $lenght = 40)
|
|
{
|
|
return !$str ? $str : Util::maxStrLength($str, $lenght); }
|
|
}
|
|
|
|
if (! function_exists('get_abo_type_badge_by_product')) {
|
|
function get_abo_type_badge_by_product($product){
|
|
return AboHelper::getAboTypeBadge(AboHelper::getAboShowOn($product));
|
|
}
|
|
}
|
|
|
|
if (! function_exists('get_abo_type_badge')) {
|
|
function get_abo_type_badge($type){
|
|
return AboHelper::getAboTypeBadge($type);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('cleanIntegerFromString')) {
|
|
function cleanIntegerFromString($value) {
|
|
return Util::cleanIntegerFromString($value);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('legal_url')) {
|
|
/**
|
|
* Generate URL for legal pages that should always point to shop domain from checkout
|
|
*/
|
|
function legal_url($path) {
|
|
try {
|
|
$context = app(DomainContext::class);
|
|
// If we're on checkout domain, redirect legal links to shop domain
|
|
if ($context->type === 'checkout') {
|
|
$domainService = app(DomainService::class);
|
|
return $domainService->buildUrl('main', $path);
|
|
}
|
|
|
|
// For all other domains, use normal URL generation
|
|
return url($path);
|
|
} catch (Exception $e) {
|
|
// Fallback to normal URL if something goes wrong
|
|
return url($path);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (! function_exists('main_asset')) {
|
|
/**
|
|
* Generate an asset URL using the main domain to avoid CORS issues.
|
|
* This ensures all assets are loaded from the main domain regardless of subdomain.
|
|
*/
|
|
function main_asset($path)
|
|
{
|
|
// Entferne führende Slashes
|
|
$path = ltrim($path, '/');
|
|
|
|
// Baue die Hauptdomain-URL
|
|
$protocol = config('app.protocol', 'https://');
|
|
$domain = config('app.domain', 'mivita');
|
|
$tld = config('app.tld_care', '.care');
|
|
|
|
return $protocol . $domain . $tld . '/' . $path;
|
|
}
|
|
}
|
|
|
|
if (! function_exists('cors_asset')) {
|
|
/**
|
|
* Alias for main_asset for backward compatibility and clarity.
|
|
*/
|
|
function cors_asset($path)
|
|
{
|
|
return main_asset($path);
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('route')) {
|
|
/**
|
|
* Route auf Hauptdomain generieren
|
|
*/
|
|
function route($name, $parameters = [], $absolute = true)
|
|
{
|
|
$url = route($name, $parameters, $absolute);
|
|
|
|
// Ersetze Subdomain mit Hauptdomain
|
|
if (request()->hasHeader('X-Subdomain')) {
|
|
$currentHost = request()->getHost();
|
|
$url = str_replace($currentHost, config('app.domain').config('app.tld_care'), $url);
|
|
}
|
|
|
|
return $url;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('asset_route')) {
|
|
/**
|
|
* Asset/Storage Route immer auf Hauptdomain
|
|
*/
|
|
function asset_route($name, $parameters = [])
|
|
{
|
|
return 'https://' . config('app.domain') . config('app.tld_care') . route($name, $parameters, false);
|
|
}
|
|
} |