praiadeseselle/site/templates/layout/func.php
2023-02-19 18:46:42 +01:00

478 lines
No EOL
15 KiB
PHP

<?php namespace ProcessWire;
/**
* @param Page $paxina
* @return array
*/
function getConfig($paxina)
{
$configuracion = array();
foreach($paxina->configuracion as $config)
{
switch ($config->parametro_tipo->value)
{
case 'texto':
$configuracion[$config->parametro_nome] = $config->parametro_valor;
break;
case 'cor':
list($r, $g, $b) = sscanf($config->parametro_cor, "%02x%02x%02x");
$configuracion[$config->parametro_nome] = $r . ', ' . $g . ', ' . $b;
break;
case 'mantemento':
if($config->parametro_mantemento==1)
{
$configuracion['mantemento'] = array(
'activo' => true,
'titular' => $config->titular,
'artigo' => $config->artigo,
'imaxe' => $config->imaxe
);
}
else
{
$configuracion['mantemento'] = array('activo' => false);
}
break;
case 'logo':
foreach($config->imaxes as $logo)
{
$configuracion['logo'][$logo->tags] = array(
'url' => $logo->url,
'alt' => $logo->description
);
}
break;
}
}
return $configuracion;
}
/**
* @param array|PageArray $seccions
* @return string
*/
function getSeccions($seccions)
{
$saida = '';
$posicion = 0;
foreach($seccions as $seccion)
{
$posicion++;
switch($seccion->template)
{
case 'repeater_seccions':
switch ($seccion->seccion_tipo->value)
{
case 'deslizante':
$saida .= renderDeslizante($seccion);
break;
case 'destacados':
$saida .= renderDestacado($seccion);
break;
case 'columnas':
$saida .= renderColumna($seccion);
break;
case 'imaxe_texto_lateral':
$saida .= renderImaxeTexto($seccion);
break;
case 'opinions':
$saida .= renderOpinions($seccion);
break;
case 'empresas':
$saida .= renderEmpresas($seccion);
break;
case 'texto':
$saida .= renderTexto($seccion);
break;
case 'galeria':
$saida .= renderGaleria($seccion);
break;
case 'reixa':
$saida .= renderReixa($seccion);
break;
}
break;
case 'repeater_deslizante':
$saida .= renderDiapositiva($seccion, $posicion);
break;
case 'repeater_botons':
$saida .= renderBoton($seccion);
break;
case 'repeater_ligazon_imaxe':
$saida .= renderLigazonImaxe($seccion);
break;
case 'repeater_destacados':
case 'repeater_columnas':
$saida .= renderElemento($seccion, $posicion);
break;
case 'repeater_opinions':
$saida .= renderCita($seccion);
break;
}
}
return $saida;
}
/**
* @param PageArray $paxinas
* @param string $clase
* @return string
*/
function renderMenu($paxinas, $clase = 'navbar-nav')
{
$saida = '';
$inicio = wire('pages')->get('/');
$actual = wire('page');
if($paxinas instanceof Page)
{
$paxinas = array($paxinas);
}
$saida .= '<ul class="' . $clase . '">' . "\n";
$saida .= '<li class="nav-item">';
$saida .= '<a class="nav-link text-uppercase link-dark px-2' . (($inicio->id == $actual->id) ? ' active" aria-current="page' : '') . '" href="' . $inicio->url . '">' . mb_strtoupper($inicio->title) . '</a>';
$saida .= '</li>' . "\n";
foreach($paxinas as $paxina)
{
$saida .= '<li class="nav-item">';
$saida .= '<a class="nav-link text-uppercase link-dark px-2' . (($paxina->id == $actual->id) ? ' active" aria-current="page' : '') . '" href="' . $paxina->url . '">' . mb_strtoupper($paxina->title) . '</a>';
$saida .= '</li>' . "\n";
}
$saida .= '</ul>' . "\n";
return $saida;
}
/**
* @param array|PageArray $paxina
* @param string $separador
* @return string
*/
function renderMigasPan($paxina, $separador = '<i class="icon-chevrons-right"></i>')
{
$saida = '';
$icono = '';
switch ($paxina->template)
{
case 'inicio':
$icono = 'home';
break;
case 'paxina':
case 'habitacions':
$icono = 'play';
break;
case 'blogue':
$icono = 'book';
break;
case 'categoria':
$icono = 'folder';
break;
case 'etiqueta':
$icono = 'tag';
break;
case 'publicacion':
$icono = 'book-open';
break;
case 'contacto':
$icono = 'user';
break;
}
$saida .= '<div id="migas_pan" class="container">' . "\n";
$saida .= '<nav style="--bs-breadcrumb-divider: '. "''" . ';" aria-label="breadcrumb">' . "\n";
$saida .= '<ol class="breadcrumb">' . "\n";
foreach($paxina->parents() as $pai)
{
$saida .= '<li class="breadcrumb-item">' . $separador . '<a href="' . $pai->url . '">' . $pai->title . '</a></li>' . "\n";
}
$saida .= '<li class="breadcrumb-item active" aria-current="page">' . $separador . ' ' . (($icono != '')? '<i class="icon-' . $icono . '"></i> ' : '') . '<span>' . $paxina->title . '</span>';
if($paxina->editable()):
$saida .= ' [ <a href="' . $paxina->editURL . '"> <i class="icon-edit"></i> ' . _x('Edit', 'Edit page') . ' </a> ]';
endif;
$saida .= '</li>' . "\n";
$saida .= '</ol>' . "\n";
$saida .= '</nav>' . "\n";
$saida .= '</div>';
return $saida;
}
/**
* @param string $titulo
* @param string $texto
* @param array|PageArray $imaxe
* @return string
*/
function renderTextoMantemento($titulo, $texto, $imaxe)
{
$saida = '';
$saida .= '<section class="container px-4 py-5">' . "\n";
$saida .= '<div class="row p-4 pt-lg-5 text-center">' . "\n";
$saida .= '<h2>' . $titulo . '</h2>' . "\n";
$saida .= '<div class="col-lg-6 mx-auto">' . "\n";
$saida .= $texto . "\n";
$saida .= '</div>' . "\n";
$saida .= '<div>' . "\n";
$saida .= '<div class="container px-5">' . "\n";
$saida .= '<img src="' . $imaxe->url . '" class="img-fluid border rounded-3 shadow-lg p-5 mb-4" alt="' . $imaxe->description . '" loading="lazy" width="700" height="500">' . "\n";
$saida .= '</div>' . "\n";
$saida .= '</div>' . "\n";
$saida .= '</section>' . "\n";
return $saida;
}
/**
* @param array|PageArray $seccion
* @return string
*/
function renderGaleria($seccion)
{
$saida = '';
$saida .= '<section id="galeria" class="galeria contedor columna swiper d-none d-md-block">' . "\n";
$saida .= '<h3 class="visually-hidden">' . (($seccion->titular) ? $seccion->titular : 'Galeria') . '</h3>' . "\n";
$saida .= '<div class="swiper-wrapper">' . "\n";
foreach($seccion->imaxes as $imaxe)
{
$saida .= '<div class="swiper-slide">' . "\n";
$saida .= '<figure>' . "\n";
$saida .= '<img src="' . $imaxe->url . '" alt="' . $imaxe->description . '" loading="lazy">' . "\n";
$saida .= '<figcaption>' . $imaxe->description . '</figcaption>' . "\n";
$saida .= '</figure>' . "\n";
$saida .= '<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>' . "\n";
$saida .= '</div>' . "\n";
}
$saida .= '</div>' . "\n";
$saida .= '<div class="swiper-button-prev"><span class="visually-hidden">Previous</span></div>' . "\n";
$saida .= '<div class="swiper-button-next"><span class="visually-hidden">Next</span></div>' . "\n";
$saida .= '<div class="swiper-pagination"></div>' . "\n";
$saida .= '<script>' . "\n";
$saida .= 'var swiper_galeria' . $seccion->id . ' = new Swiper("#galeria", {' . "\n";
$saida .= ' slidesPerView: 1,' . "\n";
$saida .= ' spaceBetween: 30,' . "\n";
$saida .= ' loop: true,' . "\n";
$saida .= ' lazy: true,' . "\n";
$saida .= ' autoHeight: false,' . "\n";
$saida .= ' keyboard: true,' . "\n";
$saida .= ' centeredSlides: true,' . "\n";
$saida .= ' autoplay: {' . "\n";
$saida .= ' delay: 2500,' . "\n";
$saida .= ' disableOnInteraction: false,' . "\n";
$saida .= ' },' . "\n";
$saida .= ' pagination: {' . "\n";
$saida .= ' el: ".swiper-pagination",' . "\n";
$saida .= ' clickable: true,' . "\n";
$saida .= ' },' . "\n";
$saida .= ' navigation: {' . "\n";
$saida .= ' nextEl: ".swiper-button-next",' . "\n";
$saida .= ' prevEl: ".swiper-button-prev",' . "\n";
$saida .= ' },' . "\n";
$saida .= '});' . "\n";
$saida .= '</script>' . "\n";
$saida .= '</section>';
return $saida;
}
/**
* @param array|PageArray $seccion
* @return string
*/
function renderReixa($seccion)
{
$saida = '';
$saida .= '<section class="container">' . "\n";
$saida .= '<h3 class="visually-hidden">' . (($seccion->titular) ? $seccion->titular : 'Reixa') . '</h3>' . "\n";
$saida .= '<div class="reixa ' . $posicion . '">' . "\n";
foreach($seccion->imaxes as $imaxe)
{
$saida .= '<figure>' . "\n";
$saida .= '<img src="' . $imaxe->url . '" alt="' . $imaxe->description . '">' . "\n";
$saida .= '<figcaption>' . $imaxe->description . '</figcaption>' . "\n";
$saida .= '</figure>' . "\n";
}
$saida .= '</div>' . "\n";
$saida .= '</section>';
return $saida;
}
/**
* @param array|PageArray $seccion
* @return string
*/
function renderImaxeTexto($seccion)
{
$saida = '';
$imaxe = '';
$texto = '';
$botons = '';
if($seccion->imaxe)
{
$imaxe .= renderImaxe($seccion);
}
$texto .= renderTexto($seccion);
if($seccion->botons->isEmpty())
{
$botons .= '<div class="row text-center">' . "\n";
$botons .= getSeccions($seccion->botons) . "\n";
$botons .= '</div>' . "\n";
}
switch ($seccion->imaxe_posicion->value)
{
case 'superior':
$saida .= '<section class="container mb-5 text-center">' . "\n";
$saida .= '<div class="row mb-5">' . "\n";
$saida .= $imaxe . "\n";
$saida .= '</div>' . "\n";
$saida .= '<div class="row text-start mb-5">' . "\n";
$saida .= $texto . "\n";
$saida .= '</div>' . "\n";
$saida .= $botons . "\n";
break;
case 'esquerda':
$saida .= '<section class="container mb-5">' . "\n";
$saida .= '<div class="row align-items-center">' . "\n";
$saida .= '<div class="col col-lg-6 text-center">' . "\n";
$saida .= $imaxe . "\n";
$saida .= '</div>' . "\n";
$saida .= '<div class="col col-lg-6 text-center">' . "\n";
$saida .= $texto . "\n";
$saida .= $botons . "\n";
$saida .= '</div>' . "\n";
$saida .= '</div>' . "\n";
break;
case 'dereita':
$saida .= '<section class="container mb-5">' . "\n";
$saida .= '<div class="row align-items-center">' . "\n";
$saida .= '<div class="col col-lg-6 text-center">' . "\n";
$saida .= $texto . "\n";
$saida .= $botons . "\n";
$saida .= '</div>' . "\n";
$saida .= '<div class="col col-lg-6 text-center">' . "\n";
$saida .= $imaxe . "\n";
$saida .= '</div>' . "\n";
$saida .= '</div>' . "\n";
break;
}
$saida .= '</section>' . "\n";
return $saida;
}
/**
* @param array|PageArray $seccion
* @return string
*/
function renderImaxe($seccion)
{
$saida = '';
$saida .= '<img src="' . $seccion->imaxe->url . '" alt="' . $seccion->imaxe->description . '">' . "\n";
return $saida;
}
/**
* @param array|PageArray $seccion
* @return string
*/
function renderTexto($seccion)
{
$saida = '';
if($seccion->titular)
{
$saida .= '<div>' . "\n";
$saida .= '<h3 class="fw-semibold">' . $seccion->titular . '</h3>' . "\n";
$saida .= '</div>' . "\n";
}
$saida .= '<div>' . "\n";
$saida .= $seccion->artigo . "\n";
$saida .= '</div>' . "\n";
return $saida;
}
/**
* @param array|PageArray $seccion
* @return string
*/
function renderBoton($seccion)
{
$saida = '';
$clases = '';
$sufijo = '';
switch ($seccion->botons_estilo->value)
{
case 'activo':
$clases = 'btn btn-lg btn-primary';
break;
case 'secundario':
$clases = 'btn btn-lg btn-secundary';
break;
case 'inactivo':
$clases = 'btn btn-lg btn-primary disabled';
break;
case 'aviso':
$clases = 'btn btn-lg text-black btn-outline-warning';
break;
case 'ligazon':
$clases = 'd-inline-flex align-items-center link-primary text-decoration-none text-uppercase';
$sufijo = ' <i class="icon-chevrons-right"></i>';
break;
}
$saida .= '<div class="col mx-auto"><a href="' . (($seccion->ligazon_interna) ? $seccion->ligazon_interna->url : '#') . '" class="' . $clases . '">' . (($seccion->parametro_valor)? $seccion->parametro_valor : $seccion->ligazon_interna->title) . $sufijo . '</a></div>';
return $saida;
}
/**
* @param array|PageArray $seccion
* @return string
*/
function renderLigazonImaxe($seccion)
{
$saida = '';
$saida .= '<figure class="col effect-ming">' . "\n";
$saida .= '<img src="' . $seccion->imaxe->url . '" alt="' . $seccion->imaxe->description . '">' . "\n";
$saida .= '<figcaption>' . "\n";
$saida .= '<h3>' . $seccion->titular . '</h3>' . "\n";
$saida .= '<p>' . _x('See details', 'see details') . '</p>' . "\n";
$saida .= '<a href=' . $seccion->ligazon_interna->url . '></a>' . "\n";
$saida .= '</figcaption>' . "\n";
$saida .= '</figure>' . "\n";
return $saida;
}