Prepare modules
This commit is contained in:
292
Services/WebsiteSettingsService.php
Normal file
292
Services/WebsiteSettingsService.php
Normal file
@ -0,0 +1,292 @@
|
||||
<?php
|
||||
|
||||
namespace Koneko\VuexyWebsiteAdmin\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Koneko\VuexyAdmin\Models\Setting;
|
||||
use Koneko\VuexyAdmin\Services\SettingsService;
|
||||
|
||||
/**
|
||||
* Servicio para gestionar la configuración del template del website.
|
||||
*
|
||||
* Este servicio maneja el procesamiento y almacenamiento de imágenes del favicon
|
||||
* y logos del website, incluyendo diferentes versiones y tamaños.
|
||||
*
|
||||
* @package Koneko\VuexyWebsiteAdmin\Services
|
||||
*/
|
||||
class WebsiteSettingsService
|
||||
{
|
||||
/** @var string Driver de procesamiento de imágenes */
|
||||
private $driver;
|
||||
|
||||
/** @var string Disco de almacenamiento para imágenes */
|
||||
private $imageDisk = 'public';
|
||||
|
||||
/** @var string Ruta base para favicons */
|
||||
private $favicon_basePath = 'favicon/';
|
||||
|
||||
/** @var string Ruta base para logos */
|
||||
private $image_logo_basePath = 'images/logo/';
|
||||
|
||||
/** @var array<string,array<int>> Tamaños predefinidos para favicons */
|
||||
private $faviconsSizes = [
|
||||
'180x180' => [180, 180],
|
||||
'192x192' => [192, 192],
|
||||
'152x152' => [152, 152],
|
||||
'120x120' => [120, 120],
|
||||
'76x76' => [76, 76],
|
||||
'16x16' => [16, 16],
|
||||
];
|
||||
|
||||
/** @var int Área máxima en píxeles para la primera versión del logo */
|
||||
private $imageLogoMaxPixels1 = 22500;
|
||||
|
||||
/** @var int Área máxima en píxeles para la segunda versión del logo */
|
||||
private $imageLogoMaxPixels2 = 75625;
|
||||
|
||||
/** @var int Área máxima en píxeles para la tercera versión del logo */
|
||||
private $imageLogoMaxPixels3 = 262144;
|
||||
|
||||
/** @var int Área máxima en píxeles para la versión base64 del logo */
|
||||
private $imageLogoMaxPixels4 = 230400;
|
||||
|
||||
/** @var int Tiempo de vida en caché en minutos */
|
||||
protected $cacheTTL = 60 * 24 * 30;
|
||||
|
||||
/**
|
||||
* Constructor del servicio
|
||||
*
|
||||
* Inicializa el driver de procesamiento de imágenes desde la configuración
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->driver = config('image.driver', 'gd');
|
||||
}
|
||||
|
||||
/**
|
||||
* Procesa y guarda un nuevo favicon
|
||||
*
|
||||
* Genera múltiples versiones del favicon en diferentes tamaños predefinidos,
|
||||
* elimina las versiones anteriores y actualiza la configuración.
|
||||
*
|
||||
* @param \Illuminate\Http\UploadedFile $image Archivo de imagen subido
|
||||
* @return void
|
||||
*/
|
||||
public function processAndSaveFavicon($image): void
|
||||
{
|
||||
Storage::makeDirectory($this->imageDisk . '/' . $this->favicon_basePath);
|
||||
|
||||
// Eliminar favicons antiguos
|
||||
$this->deleteOldFavicons();
|
||||
|
||||
// Guardar imagen original
|
||||
$imageManager = new ImageManager($this->driver);
|
||||
|
||||
$imageName = uniqid('website_favicon_');
|
||||
|
||||
$image = $imageManager->read($image->getRealPath());
|
||||
|
||||
foreach ($this->faviconsSizes as $size => [$width, $height]) {
|
||||
$resizedPath = $this->favicon_basePath . $imageName . "_{$size}.png";
|
||||
|
||||
$image->cover($width, $height);
|
||||
|
||||
Storage::disk($this->imageDisk)->put($resizedPath, $image->toPng(indexed: true));
|
||||
}
|
||||
|
||||
// Actualizar configuración utilizando SettingService
|
||||
$SettingsService = app(SettingsService::class);
|
||||
$SettingsService->set('website.favicon_ns', $this->favicon_basePath . $imageName, null, 'vuexy-website-admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina los favicons antiguos del almacenamiento
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteOldFavicons(): void
|
||||
{
|
||||
// Obtener el favicon actual desde la base de datos
|
||||
$currentFavicon = Setting::where('key', 'website.favicon_ns')->value('value');
|
||||
|
||||
if ($currentFavicon) {
|
||||
$filePaths = [
|
||||
$this->imageDisk . '/' . $currentFavicon,
|
||||
$this->imageDisk . '/' . $currentFavicon . '_16x16.png',
|
||||
$this->imageDisk . '/' . $currentFavicon . '_76x76.png',
|
||||
$this->imageDisk . '/' . $currentFavicon . '_120x120.png',
|
||||
$this->imageDisk . '/' . $currentFavicon . '_152x152.png',
|
||||
$this->imageDisk . '/' . $currentFavicon . '_180x180.png',
|
||||
$this->imageDisk . '/' . $currentFavicon . '_192x192.png',
|
||||
];
|
||||
|
||||
foreach ($filePaths as $filePath) {
|
||||
if (Storage::exists($filePath)) {
|
||||
Storage::delete($filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Procesa y guarda un nuevo logo
|
||||
*
|
||||
* Genera múltiples versiones del logo con diferentes tamaños máximos,
|
||||
* incluyendo una versión en base64, y actualiza la configuración.
|
||||
*
|
||||
* @param \Illuminate\Http\UploadedFile $image Archivo de imagen subido
|
||||
* @param string $type Tipo de logo ('dark' para modo oscuro, '' para normal)
|
||||
* @return void
|
||||
*/
|
||||
public function processAndSaveImageLogo($image, string $type = ''): void
|
||||
{
|
||||
// Crear directorio si no existe
|
||||
Storage::makeDirectory($this->imageDisk . '/' . $this->image_logo_basePath);
|
||||
|
||||
// Eliminar imágenes antiguas
|
||||
$this->deleteOldImageWebapp($type);
|
||||
|
||||
// Leer imagen original
|
||||
$imageManager = new ImageManager($this->driver);
|
||||
$image = $imageManager->read($image->getRealPath());
|
||||
|
||||
// Generar tres versiones con diferentes áreas máximas
|
||||
$this->generateAndSaveImage($image, $type, $this->imageLogoMaxPixels1, 'small'); // Versión 1
|
||||
$this->generateAndSaveImage($image, $type, $this->imageLogoMaxPixels2, 'medium'); // Versión 2
|
||||
$this->generateAndSaveImage($image, $type, $this->imageLogoMaxPixels3); // Versión 3
|
||||
$this->generateAndSaveImageAsBase64($image, $type, $this->imageLogoMaxPixels4); // Versión 3
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera y guarda una versión del logo
|
||||
*
|
||||
* @param \Intervention\Image\Interfaces\ImageInterface $image Imagen a procesar
|
||||
* @param string $type Tipo de logo ('dark' para modo oscuro, '' para normal)
|
||||
* @param int $maxPixels Área máxima en píxeles
|
||||
* @param string $suffix Sufijo para el nombre del archivo
|
||||
* @return void
|
||||
*/
|
||||
private function generateAndSaveImage($image, string $type, int $maxPixels, string $suffix = ''): void
|
||||
{
|
||||
$imageClone = clone $image;
|
||||
|
||||
// Escalar imagen conservando aspecto
|
||||
$this->resizeImageToMaxPixels($imageClone, $maxPixels);
|
||||
|
||||
$imageName = 'website_image_logo' . ($suffix ? '_' . $suffix : '') . ($type == 'dark' ? '_dark' : '');
|
||||
$keyValue = 'website.image.logo' . ($suffix ? '_' . $suffix : '') . ($type == 'dark' ? '_dark' : '');
|
||||
|
||||
// Generar nombre y ruta
|
||||
$imageNameUid = uniqid($imageName . '_', ".png");
|
||||
$resizedPath = $this->image_logo_basePath . $imageNameUid;
|
||||
|
||||
// Guardar imagen en PNG
|
||||
Storage::disk($this->imageDisk)->put($resizedPath, $imageClone->toPng(indexed: true));
|
||||
|
||||
// Actualizar configuración
|
||||
$SettingsService = app(SettingsService::class);
|
||||
$SettingsService->set($keyValue, $resizedPath, null, 'vuexy-website-admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Redimensiona una imagen manteniendo su proporción
|
||||
*
|
||||
* @param \Intervention\Image\Interfaces\ImageInterface $image Imagen a redimensionar
|
||||
* @param int $maxPixels Área máxima en píxeles
|
||||
* @return \Intervention\Image\Interfaces\ImageInterface
|
||||
*/
|
||||
private function resizeImageToMaxPixels($image, int $maxPixels)
|
||||
{
|
||||
// Obtener dimensiones originales de la imagen
|
||||
$originalWidth = $image->width(); // Método para obtener el ancho
|
||||
$originalHeight = $image->height(); // Método para obtener el alto
|
||||
|
||||
// Calcular el aspecto
|
||||
$aspectRatio = $originalWidth / $originalHeight;
|
||||
|
||||
// Calcular dimensiones redimensionadas conservando aspecto
|
||||
if ($aspectRatio > 1) { // Ancho es dominante
|
||||
$newWidth = sqrt($maxPixels * $aspectRatio);
|
||||
$newHeight = $newWidth / $aspectRatio;
|
||||
|
||||
} else { // Alto es dominante
|
||||
$newHeight = sqrt($maxPixels / $aspectRatio);
|
||||
$newWidth = $newHeight * $aspectRatio;
|
||||
}
|
||||
|
||||
// Redimensionar la imagen
|
||||
$image->resize(
|
||||
round($newWidth), // Redondear para evitar problemas con números decimales
|
||||
round($newHeight),
|
||||
function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
}
|
||||
);
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera y guarda una versión del logo en formato base64
|
||||
*
|
||||
* @param \Intervention\Image\Interfaces\ImageInterface $image Imagen a procesar
|
||||
* @param string $type Tipo de logo ('dark' para modo oscuro, '' para normal)
|
||||
* @param int $maxPixels Área máxima en píxeles
|
||||
* @return void
|
||||
*/
|
||||
private function generateAndSaveImageAsBase64($image, string $type, int $maxPixels): void
|
||||
{
|
||||
$imageClone = clone $image;
|
||||
|
||||
// Redimensionar imagen conservando el aspecto
|
||||
$this->resizeImageToMaxPixels($imageClone, $maxPixels);
|
||||
|
||||
// Convertir a Base64
|
||||
$base64Image = (string) $imageClone->toJpg(40)->toDataUri();
|
||||
|
||||
// Guardar como configuración
|
||||
$SettingsService = app(SettingsService::class);
|
||||
$SettingsService->set("website.image.logo_base64" . ($type === 'dark' ? '_dark' : ''), $base64Image, null, 'vuexy-website-admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina las imágenes antiguas del logo
|
||||
*
|
||||
* @param string $type Tipo de logo ('dark' para modo oscuro, '' para normal)
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteOldImageWebapp(string $type = ''): void
|
||||
{
|
||||
// Determinar prefijo según el tipo (normal o dark)
|
||||
$suffix = $type === 'dark' ? '_dark' : '';
|
||||
|
||||
// Claves relacionadas con las imágenes que queremos limpiar
|
||||
$imageKeys = [
|
||||
"website.image_logo{$suffix}",
|
||||
"website.image_logo_small{$suffix}",
|
||||
"website.image_logo_medium{$suffix}",
|
||||
];
|
||||
|
||||
// Recuperar las imágenes actuales en una sola consulta
|
||||
$settings = Setting::whereIn('key', $imageKeys)->pluck('value', 'key');
|
||||
|
||||
foreach ($imageKeys as $key) {
|
||||
// Obtener la imagen correspondiente
|
||||
$currentImage = $settings[$key] ?? null;
|
||||
|
||||
if ($currentImage) {
|
||||
// Construir la ruta del archivo y eliminarlo si existe
|
||||
$filePath = $this->imageDisk . '/' . $currentImage;
|
||||
|
||||
if (Storage::exists($filePath)) {
|
||||
Storage::delete($filePath);
|
||||
}
|
||||
|
||||
// Eliminar la configuración de la base de datos
|
||||
Setting::where('key', $key)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
395
Services/WebsiteTemplateService.php
Normal file
395
Services/WebsiteTemplateService.php
Normal file
@ -0,0 +1,395 @@
|
||||
<?php
|
||||
|
||||
namespace Koneko\VuexyWebsiteAdmin\Services;
|
||||
|
||||
use Illuminate\Support\Facades\{Cache,Schema};
|
||||
use Koneko\VuexyAdmin\Models\Setting;
|
||||
|
||||
/**
|
||||
* Servicio para gestionar la configuración y personalización del template del Website.
|
||||
*
|
||||
* Esta clase maneja las configuraciones del template del website, incluyendo variables
|
||||
* de personalización, logos, favicons y otras configuraciones de la interfaz.
|
||||
* Implementa un sistema de caché para optimizar el rendimiento.
|
||||
*/
|
||||
class WebsiteTemplateService
|
||||
{
|
||||
/** @var int Tiempo de vida del caché en minutos (60 * 24 * 30 = 30 días) */
|
||||
protected $cacheTTL = 60 * 24 * 30;
|
||||
|
||||
/**
|
||||
* Obtiene las variables del template del website.
|
||||
*
|
||||
* @param string $setting Clave de la configuración a obtener
|
||||
* @return array Array con las variables del template
|
||||
*/
|
||||
public function getWebsiteVars(string $setting = ''): array
|
||||
{
|
||||
try {
|
||||
// Verifica si la base de datos está inicializada
|
||||
if (!Schema::hasTable('migrations')) {
|
||||
return $this->getDefaultWebsiteVars($setting);
|
||||
}
|
||||
|
||||
$webVars = Cache::remember('website_settings', $this->cacheTTL, function () {
|
||||
$settings = Setting::withVirtualValue()
|
||||
->where(function ($query) {
|
||||
$query->where('key', 'LIKE', 'website.%')
|
||||
->orWhere('key', 'LIKE', 'google.%')
|
||||
->orWhere('key', 'LIKE', 'chat.%');
|
||||
})
|
||||
->pluck('value', 'key')
|
||||
->toArray();
|
||||
|
||||
return $this->buildWebsiteVars($settings);
|
||||
});
|
||||
|
||||
return $setting ? ($webVars[$setting] ?? []) : $webVars;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Manejo de excepciones: devolver valores predeterminados
|
||||
return $this->getDefaultWebsiteVars($setting);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construye las variables del template del website.
|
||||
*
|
||||
* @param array $settings Array asociativo de configuraciones
|
||||
* @return array Array con las variables del template
|
||||
*/
|
||||
private function buildWebsiteVars(array $settings): array
|
||||
{
|
||||
return [
|
||||
'title' => $settings['website.title'] ?? config('_var.appTitle'),
|
||||
'author' => config('_var.author'),
|
||||
'description' => $settings['website.description'] ?? config('_var.appDescription'),
|
||||
'favicon' => $this->getFaviconPaths($settings),
|
||||
'app_name' => $settings['website.app_name'] ?? config('_var.appName'),
|
||||
'image_logo' => $this->getImageLogoPaths($settings),
|
||||
//'template' => $this->getTemplateVars($settings),
|
||||
'google' => $this->getGoogleVars($settings),
|
||||
'chat' => $this->getChatVars($settings),
|
||||
'contact' => $this->getContactVars(),
|
||||
'social' => $this->getSocialVars(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene las variables del template del website por defecto.
|
||||
*
|
||||
* @param string $setting Clave de la configuración a obtener
|
||||
* @return array Array con las variables del template
|
||||
*/
|
||||
private function getDefaultWebsiteVars(string $setting = ''): array
|
||||
{
|
||||
$defaultVars = [
|
||||
'title' => config('_var.appTitle', 'Default Title'),
|
||||
'author' => config('_var.author', 'Default Author'),
|
||||
'description' => config('_var.appDescription', 'Default Description'),
|
||||
'favicon' => $this->getFaviconPaths([]),
|
||||
'image_logo' => $this->getImageLogoPaths([]),
|
||||
//'template' => $this->getTemplateVars([]),
|
||||
'google' => $this->getGoogleVars([]),
|
||||
'chat' => $this->getChatVars([]),
|
||||
'contact' => [],
|
||||
'social' => [],
|
||||
];
|
||||
|
||||
return $setting ? ($defaultVars[$setting] ?? []) : $defaultVars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera las rutas para los diferentes tamaños de favicon.
|
||||
*
|
||||
* @param array $settings Array asociativo de configuraciones
|
||||
* @return array Array con las rutas de los favicons en diferentes tamaños
|
||||
*/
|
||||
private function getFaviconPaths(array $settings): array
|
||||
{
|
||||
$defaultFavicon = config('koneko.appFavicon');
|
||||
$namespace = $settings['website.favicon_ns'] ?? null;
|
||||
|
||||
return [
|
||||
'namespace' => $namespace,
|
||||
'16x16' => $namespace ? "{$namespace}_16x16.png" : $defaultFavicon,
|
||||
'76x76' => $namespace ? "{$namespace}_76x76.png" : $defaultFavicon,
|
||||
'120x120' => $namespace ? "{$namespace}_120x120.png" : $defaultFavicon,
|
||||
'152x152' => $namespace ? "{$namespace}_152x152.png" : $defaultFavicon,
|
||||
'180x180' => $namespace ? "{$namespace}_180x180.png" : $defaultFavicon,
|
||||
'192x192' => $namespace ? "{$namespace}_192x192.png" : $defaultFavicon,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera las rutas para los diferentes tamaños y versiones del logo.
|
||||
*
|
||||
* @param array $settings Array asociativo de configuraciones
|
||||
* @return array Array con las rutas de los logos en diferentes tamaños y modos
|
||||
*/
|
||||
private function getImageLogoPaths(array $settings): array
|
||||
{
|
||||
$defaultLogo = config('koneko.appLogo');
|
||||
|
||||
return [
|
||||
'small' => $this->getImagePath($settings, 'website.image.logo_small', $defaultLogo),
|
||||
'medium' => $this->getImagePath($settings, 'website.image.logo_medium', $defaultLogo),
|
||||
'large' => $this->getImagePath($settings, 'website.image.logo', $defaultLogo),
|
||||
'small_dark' => $this->getImagePath($settings, 'website.image.logo_small_dark', $defaultLogo),
|
||||
'medium_dark' => $this->getImagePath($settings, 'website.image.logo_medium_dark', $defaultLogo),
|
||||
'large_dark' => $this->getImagePath($settings, 'website.image.logo_dark', $defaultLogo),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene la ruta de una imagen específica desde las configuraciones.
|
||||
*
|
||||
* @param array $settings Array asociativo de configuraciones
|
||||
* @param string $key Clave de la configuración
|
||||
* @param string $default Valor predeterminado si no se encuentra la configuración
|
||||
* @return string Ruta de la imagen
|
||||
*/
|
||||
private function getImagePath(array $settings, string $key, string $default): string
|
||||
{
|
||||
return $settings[$key] ?? $default;
|
||||
}
|
||||
|
||||
/*
|
||||
private function getTemplateVars(array $settings): array
|
||||
{
|
||||
return [
|
||||
'style_switcher' => (bool)($settings['website.tpl_style_switcher'] ?? false),
|
||||
'footer_text' => $settings['website.tpl_footer_text'] ?? '',
|
||||
];
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obtiene las variables de Google Analytics.
|
||||
*
|
||||
* @param array $settings Array asociativo de configuraciones
|
||||
* @return array Array con las variables de Google Analytics
|
||||
*/
|
||||
private function getGoogleVars(array $settings): array
|
||||
{
|
||||
return [
|
||||
'analytics' => [
|
||||
'enabled' => (bool)($settings['google.analytics_enabled'] ?? false),
|
||||
'id' => $settings['google.analytics_id'] ?? '',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene las variables de chat.
|
||||
*
|
||||
* @param array $settings Array asociativo de configuraciones
|
||||
* @return array Array con las variables de chat
|
||||
*/
|
||||
private function getChatVars(array $settings): array
|
||||
{
|
||||
return [
|
||||
'provider' => $settings['chat.provider'] ?? '',
|
||||
'whatsapp_number' => $settings['chat.whatsapp_number'] ?? '',
|
||||
'whatsapp_message' => $settings['chat.whatsapp_message'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene las variables de contacto.
|
||||
*
|
||||
* @return array Array con las variables de contacto
|
||||
*/
|
||||
public function getContactVars(): array
|
||||
{
|
||||
$settings = Setting::withVirtualValue()
|
||||
->where('key', 'LIKE', 'contact.%')
|
||||
->pluck('value', 'key')
|
||||
->toArray();
|
||||
|
||||
return [
|
||||
'phone_number' => isset($settings['contact.phone_number'])
|
||||
? preg_replace('/\D/', '', $settings['contact.phone_number']) // Elimina todo lo que no sea un número
|
||||
: '',
|
||||
'phone_number_text' => $settings['contact.phone_number'] ?? '',
|
||||
'phone_number_ext' => $settings['contact.phone_number_ext'] ?? '',
|
||||
'phone_number_2' => isset($settings['contact.phone_number_2'])
|
||||
? preg_replace('/\D/', '', $settings['contact.phone_number_2']) // Elimina todo lo que no sea un número
|
||||
: '',
|
||||
'phone_number_2_text' => $settings['contact.phone_number_2'] ?? '',
|
||||
'phone_number_2_ext' => $settings['contact.phone_number_2_ext'] ?? '',
|
||||
'email' => $settings['contact.email'] ?? '',
|
||||
'direccion' => $settings['contact.direccion'] ?? '',
|
||||
'horario' => $settings['contact.horario'] ?? '',
|
||||
'location' => [
|
||||
'lat' => $settings['contact.location.lat'] ?? '',
|
||||
'lng' => $settings['contact.location.lng'] ?? '',
|
||||
],
|
||||
'form' => [
|
||||
'to_email' => $settings['contact.form.to_email'] ?? '',
|
||||
'to_email_cc' => $settings['contact.form.to_email_cc'] ?? '',
|
||||
'subject' => $settings['contact.form.subject'] ?? '',
|
||||
'submit_message' => $settings['contact.form.submit_message'] ?? '',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene las variables de redes sociales.
|
||||
*
|
||||
* @return array Array con las variables de redes sociales
|
||||
*/
|
||||
public function getSocialVars(): array
|
||||
{
|
||||
$social = Setting::withVirtualValue()
|
||||
->where('key', 'LIKE', 'social.%')
|
||||
->pluck('value', 'key')
|
||||
->toArray();
|
||||
|
||||
return [
|
||||
'whatsapp' => $social['social.whatsapp'] ?? '',
|
||||
'whatsapp_message' => $social['social.whatsapp_message'] ?? '',
|
||||
'facebook' => $social['social.facebook'] ?? '',
|
||||
'instagram' => $social['social.instagram'] ?? '',
|
||||
'linkedin' => $social['social.linkedin'] ?? '',
|
||||
'tiktok' => $social['social.tiktok'] ?? '',
|
||||
'x_twitter' => $social['social.x_twitter'] ?? '',
|
||||
'google' => $social['social.google'] ?? '',
|
||||
'pinterest' => $social['social.pinterest'] ?? '',
|
||||
'youtube' => $social['social.youtube'] ?? '',
|
||||
'vimeo' => $social['social.vimeo'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Limpia el caché de las variables del website.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function clearWebsiteVarsCache()
|
||||
{
|
||||
Cache::forget("website_settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene las variables de legal notice.
|
||||
*
|
||||
* @param string $legalDocument Documento legal a obtener
|
||||
* @return array Array con las variables de legal notice
|
||||
*/
|
||||
public function getLegalVars($legalDocument = false)
|
||||
{
|
||||
$legal = Setting::withVirtualValue()
|
||||
->where('key', 'LIKE', 'legal_notice.%')
|
||||
->pluck('value', 'key')
|
||||
->toArray();
|
||||
|
||||
$legalDocuments = [
|
||||
'legal_notice.terminos_y_condiciones' => [
|
||||
'title' => 'Términos y condiciones',
|
||||
'enabled' => (bool)($legal['legal_notice.terminos_y_condiciones_enabled'] ?? false),
|
||||
'content' => $legal['legal_notice.terminos_y_condiciones_content'] ?? '',
|
||||
],
|
||||
'legal_notice.aviso_de_privacidad' => [
|
||||
'title' => 'Aviso de privacidad',
|
||||
'enabled' => (bool)($legal['legal_notice.aviso_de_privacidad_enabled'] ?? false),
|
||||
'content' => $legal['legal_notice.aviso_de_privacidad_content'] ?? '',
|
||||
],
|
||||
'legal_notice.politica_de_devoluciones' => [
|
||||
'title' => 'Política de devoluciones y reembolsos',
|
||||
'enabled' => (bool)($legal['legal_notice.politica_de_devoluciones_enabled'] ?? false),
|
||||
'content' => $legal['legal_notice.politica_de_devoluciones_content'] ?? '',
|
||||
],
|
||||
'legal_notice.politica_de_envios' => [
|
||||
'title' => 'Política de envíos',
|
||||
'enabled' => (bool)($legal['legal_notice.politica_de_envios_enabled'] ?? false),
|
||||
'content' => $legal['legal_notice.politica_de_envios_content'] ?? '',
|
||||
],
|
||||
'legal_notice.politica_de_cookies' => [
|
||||
'title' => 'Política de cookies',
|
||||
'enabled' => (bool)($legal['legal_notice.politica_de_cookies_enabled'] ?? false),
|
||||
'content' => $legal['legal_notice.politica_de_cookies_content'] ?? '',
|
||||
],
|
||||
'legal_notice.autorizaciones_y_licencias' => [
|
||||
'title' => 'Autorizaciones y licencias',
|
||||
'enabled' => (bool)($legal['legal_notice.autorizaciones_y_licencias_enabled'] ?? false),
|
||||
'content' => $legal['legal_notice.autorizaciones_y_licencias_content'] ?? '',
|
||||
],
|
||||
'legal_notice.informacion_comercial' => [
|
||||
'title' => 'Información comercial',
|
||||
'enabled' => (bool)($legal['legal_notice.informacion_comercial_enabled'] ?? false),
|
||||
'content' => $legal['legal_notice.informacion_comercial_content'] ?? '',
|
||||
],
|
||||
'legal_notice.consentimiento_para_el_login_de_terceros' => [
|
||||
'title' => 'Consentimiento para el login de terceros',
|
||||
'enabled' => (bool)($legal['legal_notice.consentimiento_para_el_login_de_terceros_enabled'] ?? false),
|
||||
'content' => $legal['legal_notice.consentimiento_para_el_login_de_terceros_content'] ?? '',
|
||||
],
|
||||
'legal_notice.leyendas_de_responsabilidad' => [
|
||||
'title' => 'Leyendas de responsabilidad',
|
||||
'enabled' => (bool)($legal['legal_notice.leyendas_de_responsabilidad_enabled'] ?? false),
|
||||
'content' => $legal['legal_notice.leyendas_de_responsabilidad_content'] ?? '',
|
||||
],
|
||||
];
|
||||
|
||||
return $legalDocument
|
||||
? $legalDocuments[$legalDocument]
|
||||
: $legalDocuments;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user