getDestinations(); $alojaproWidget = get_option('alojapro_settings'); $alojaproConfig = get_option('alojapro_config'); $maxAdultOptions = $alojaproWidget['maxAdult']; $maxChildOptions = $alojaproWidget['maxChild']; $maxChildAge = $alojaproWidget['maxChildAge']; if (!is_numeric($maxAdultOptions) || $maxAdultOptions == 0) { $maxAdultOptions = 6; } if (!is_numeric($maxChildOptions) || $maxChildOptions == 0) { $maxChildOptions = 4; } if (!is_numeric($maxChildAge) || $maxChildAge == 0) { $maxChildAge = 12; } $adlutDropDown = ""; for ($i = 1; $i <= $maxAdultOptions; $i++) { if ($i == 2) { $adlutDropDown .= ""; } else { $adlutDropDown .= ""; } } $childDropDown = ""; $childDropDown .= ""; for ($i = 1; $i <= $maxChildOptions; $i++) { $childDropDown .= ""; } $childAgeInputs = ""; for ($i = 1; $i <= $maxChildOptions; $i++) { //$childAgeInputs .= "
"; $childAgeInputs .="
"; $childAgeInputs .="
"; } if(!$alojaproWidget) return; $templates = [ 0 => [ 'classic' => "templates/search-form.tpl", ], 1 => [ 'classic' => "templates/search-form-no-discount.tpl", ], 2 => [ 'classic' => "templates/search-form-advanced-filters.tpl", 'modern' => "templates/search-form-modern.tpl", ], 3 => [ 'classic' => "templates/search-form-advanced-filters-no-discount.tpl", 'modern' => "templates/search-form-modern-no-discount.tpl", ], 4 => [ 'modern' => "templates/search-form-modern-destinations.tpl", ], 5 => [ 'modern' => "templates/search-form-modern-destinations-no-discount.tpl", ], 6 => [ 'modern' => "templates/search-form-modern-no-filters.tpl", ] ]; $widgetType = $alojaproWidget['widgetType'] ?? null; $customLayout = $alojaproWidget['customLayout'] ?? 'classic'; $templatePath = $templates[$widgetType][$customLayout] ?? "templates/search-form.tpl"; $template = new Alojapro_TemplateManager(ALOJAPRO_PLUGIN_BASE_PATH . $templatePath); if ($alojaproWidget['widgetPropertyType'] == 1) { $template->set('rooms_label', __('Apartamentos', 'alojapro-widget')); $template->set('room_label', __('Apartamento', 'alojapro-widget')); }else{ $template->set('rooms_label', __('Habitaciones', 'alojapro-widget')); $template->set('room_label', __('Habitación', 'alojapro-widget')); } $template->set('action', $alojaproConfig['action']); $template->set('login', $alojaproConfig['login']); $template->set('password', $alojaproConfig['password']); $template->set('platformId', $alojaproConfig['platformId']); if (get_locale() != 'ca_ES' && get_locale() != 'ca' && get_locale() != 'es_ES' && $alojaproConfig['widgetInternationalId'] != 0){ $template->set('widgetId', $alojaproConfig['widgetInternationalId']); }else{ $template->set('widgetId', $alojaproConfig['widgetId']); } $template->set('widgetMobileId', $alojaproConfig['widgetMobileId']); $template->set('language', $this->getLanguage()); $template->set('ALOJAPRO_PLUGIN_BASE_URL', ALOJAPRO_PLUGIN_BASE_URL); $template->set('info_label', __('Verificar Disponibilidad', 'alojapro-widget')); $template->set('button_search_label', __('Buscar', 'alojapro-widget')); $template->set('button_destinations_label', __('Destinos', 'alojapro-widget')); $template->set('button_discounts_label', __('Descuentos', 'alojapro-widget')); $template->set('button_advanced_filter_label', __('Filtros Avanzados', 'alojapro-widget')); $template->set('checkin_label', __('Llegada', 'alojapro-widget')); $template->set('checkout_label', __('Salida', 'alojapro-widget')); $template->set('modal_email', __('Tienes tu email registrado?', 'alojapro-widget')); $template->set('modal_coupon', __('Tienes código de descuento?', 'alojapro-widget')); $template->set('info_mail_discount', __('Escribe tu correo electrónico y se activarán los descuentos que tienes asociados', 'alojapro-widget')); $template->set('info_code_discount', __('Introduce tu código promocional', 'alojapro-widget')); $template->set('modal_accept', __('Aceptar', 'alojapro-widget')); $template->set('custom_css', $alojaproWidget['customCss']); $template->set('adults_label', __('Adultos', 'alojapro-widget')); $template->set('children_label', __('Niños', 'alojapro-widget')); $template->set('children_ages_label', __('Edades Niños', 'alojapro-widget')); $template->set('occupations', __('Ocupación', 'alojapro-widget')); $template->set('people_label', __('Personas', 'alojapro-widget')); $template->set('adultDropDown', $adlutDropDown); $template->set('childDropDown', $childDropDown); $template->set('childAgeInputs', $childAgeInputs); $template->set('maxAge', $maxChildAge); $template->set('destinations', $destinations); return $template->output(); } function getDestinations() { // URL del servicio web $url = 'https://admin.alojapro.com/api/ws/getDestinationsWithProperties'; // Obteniendo los parametros $alojaproConfig = get_option('alojapro_config'); // Parámetros requeridos para la llamada al servicio $params = array( 'login' => $alojaproConfig['login'], 'password' => $alojaproConfig['password'], 'platformId' => $alojaproConfig['platformId'], 'widgetId' => $alojaproConfig['widgetId'], 'language' => $this->getLanguage() ); // Inicializar cURL $ch = curl_init(); // Configurar las opciones de cURL curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); curl_setopt($ch, CURLOPT_TIMEOUT, 100); // Ejecutar la llamada $response = curl_exec($ch); // Verificar si hubo algún error if($response === false) { $error = curl_error($ch); curl_close($ch); return "Error en la llamada al servicio: $error"; } // Cerrar la conexión cURL curl_close($ch); $responseSelect = ''; // Decodificar el JSON $data = json_decode($response, true); // Comprobar si el campo 'cities' existe y no es null ni vacío if (isset($data['response'][$params['language']]['cities']) && !empty($data['response'][$params['language']]['cities'])) { // Obtener las ciudades $cities = $data['response'][$params['language']]['cities']; // Montar la respuesta foreach ($cities as $city) { $responseSelect .= '

' . $city['city'] . '

'; if (isset($city['properties']) && is_array($city['properties'])) { foreach ($city['properties'] as $hotel) { // Obtener la categoría $category = isset($hotel['category']['code']) ? $hotel['category']['code'] : null; $stars = $category ? $this->getCategoryStars($category) : ''; $responseSelect .= '

'. $hotel['property'] . ' '.$stars.'

'; } } } } else { return "Error: No se encontraron ciudades."; } return $responseSelect; } function getCategoryStars($category){ $typeCat = substr($category, 0, 1); $cat = substr($category, 1, 1); $star = ''; for($c=1; $c<=$cat; $c++) { if($c<=4) { if($typeCat=='E') { $star .= ' '; } else { $star .= ' '; } } } if(($cat==5) || ($cat==7)) { if($typeCat=='E') { $star .= ' '; } else { $star .= ' '; } } if($cat==6) $star .="SUP"; if($cat==7) $star .="GL"; return $star; } private function getLanguage(){ if(!defined('ICL_LANGUAGE_CODE')){ return 'es'; } switch (ICL_LANGUAGE_CODE){ case 'pt-pt': return 'pt'; default: return ICL_LANGUAGE_CODE; } } }