praiadeseselle/site/templates/_func.php

445 lines
14 KiB
PHP
Raw Normal View History

2022-03-09 18:09:44 +01:00
<?php namespace ProcessWire;
function getConfig($paxina)
{
$configuracion = array();
foreach($paxina->configuracion as $config)
{
2022-10-06 10:54:15 +02:00
switch ($config->parametro_tipo->value)
2022-05-03 12:18:01 +02:00
{
case 'texto':
2022-10-06 10:54:15 +02:00
$configuracion[$config->parametro_nome] = $config->parametro_valor;
2022-05-03 12:18:01 +02:00
break;
case 'cor':
2022-10-06 10:54:15 +02:00
list($r, $g, $b) = sscanf($config->parametro_cor, "%02x%02x%02x");
$configuracion[$config->parametro_nome] = $r . ', ' . $g . ', ' . $b;
2022-05-03 12:18:01 +02:00
break;
}
2022-03-09 18:09:44 +01:00
}
return $configuracion;
}
2022-10-25 14:47:38 +02:00
function getTextoLimpo($texto)
{
$texto = preg_replace ('/<[^>]*>/', ' ', $texto);
$texto = str_replace("\r", '', $texto);
$texto = str_replace("\n", ' ', $texto);
$texto = str_replace("\t", ' ', $texto);
$texto = trim(preg_replace('/ {2,}/', ' ', $texto));
return $texto;
}
function getSeccions($seccions)
2022-03-09 18:09:44 +01:00
{
$saida = '';
foreach($seccions as $seccion)
{
switch($seccion->template)
{
case 'repeater_seccions':
2022-10-06 10:54:15 +02:00
switch ($seccion->seccion_tipo->value)
2022-03-09 18:09:44 +01:00
{
case 'texto':
$saida .= renderTexto($seccion->titular, $seccion->artigo);
2022-03-09 18:09:44 +01:00
break;
case 'galeria':
2022-10-06 10:54:15 +02:00
$saida .= renderGaleria($seccion->titular, $seccion->imaxes_galeria);
2022-03-09 18:09:44 +01:00
break;
2022-04-08 12:32:49 +02:00
case 'reixa':
2022-10-06 10:54:15 +02:00
$saida .= renderReixa($seccion->titular, $seccion->imaxes_reixa);
break;
case 'imaxe_texto_lateral':
$saida .= renderTextoImaxe($seccion->titular, $seccion->artigo, $seccion->imaxe, $seccion->imaxe_posicion->value);
2022-05-03 12:18:01 +02:00
break;
2022-03-09 18:09:44 +01:00
}
break;
2022-10-06 10:54:15 +02:00
case 'repeater_mantemento_mensaxe':
$saida .= renderTextoMantemento($seccion->titular, $seccion->artigo, $seccion->imaxe);
break;
2022-05-03 12:18:01 +02:00
case 'repeater_imaxe_ligazon':
$saida .= renderImaxeLigazon($seccion->titular, $seccion->imaxe, $seccion->ligazon);
2022-03-09 18:09:44 +01:00
break;
}
}
return $saida;
}
2022-03-10 01:47:18 +01:00
function renderMenu($paxinas, $maxDepth = 0, $id = 'nav')
{
if($paxinas instanceof Page)
{
$paxinas = array($paxinas);
}
$saida = '';
foreach($paxinas as $paxina)
{
if($paxina->id == wire('page')->id)
{
2022-10-06 10:54:15 +02:00
$saida .= '<li class="activo">';
2022-03-10 01:47:18 +01:00
}
else
{
2022-10-06 10:54:15 +02:00
$saida .= '<li>';
2022-03-10 01:47:18 +01:00
}
2022-10-27 14:10:14 +02:00
$saida .= '<a href="' . $paxina->url . '">' . mb_strtoupper($paxina->title) . '</a>';
2022-03-10 01:47:18 +01:00
if($paxina->hasChildren() && $maxDepth)
{
if($id == 'nav')
{
$id = 'nav nav-tree';
}
$saida .= renderMenu($paxina->children, $maxDepth-1, $id);
}
$saida .= '</li>' . "\n";
2022-03-10 01:47:18 +01:00
}
if($saida)
{
2022-10-06 10:54:15 +02:00
$saida = '<ul id="' . $id . '">' . "\n" . $saida . '</ul>' . "\n";
2022-03-10 01:47:18 +01:00
}
return $saida;
}
function renderMigasPan($paxina, $separador = '<i class="icon-chevrons-right"></i>')
{
$saida = '';
2022-10-27 14:10:14 +02:00
$icono = '';
switch ($paxina->template)
{
case 'portada':
$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 class="contedor migas_pan" role="navigation" aria-label="' . _x('Current page', 'navigation') . ':">' . "\n";
2022-10-06 10:54:15 +02:00
$saida .= $separador;
foreach($paxina->parents() as $pai)
{
$saida .= '<span><a href="' . $pai->url . '">' . $pai->title . '</a></span> ' . $separador . ' ';
}
2022-10-27 14:10:14 +02:00
$saida .= ($icono != '')? '<i class="icon-' . $icono . '"></i> ' : '';
$saida .= '<span>' . $paxina->title . '</span>';
if($paxina->editable()):
$saida .= ' [ <a href="' . $paxina->editURL . '"> <i class="icon-edit"></i> ' . _x('Edit', 'Edit page') . ' </a> ]';
endif;
$saida .= "\n";
2022-10-06 10:54:15 +02:00
$saida .= '</div>';
return $saida;
}
2022-10-25 14:47:38 +02:00
function renderPaxinacion($artigos, $posicion)
{
$paxinacion = $artigos->renderPager(array(
'listMarkup' => '<nav id="paxinacion-' . $posicion . '" class="paxinacion"><ul>{out}</ul></nav>',
'itemMarkup' => '<li class="{class}">{out}</li>',
'linkMarkup' => '<a href="{url}"><span>{out}</span></a>',
'nextItemLabel' => '<i class="icon-skip-forward"></i>',
'previousItemLabel' => '<i class="icon-skip-back"></i>',
'separatorItemClass' => 'separador',
'nextItemClass' => 'seguinte',
'previousItemClass' => 'anterior',
'lastItemClass' => 'derradeiro',
'currentItemClass' => 'actual'
));
return $paxinacion;
}
function renderTexto($titulo, $texto)
2022-03-09 18:09:44 +01:00
{
$saida = '';
2022-10-06 10:54:15 +02:00
$saida .= '<div class="celda">' . "\n";
$saida .= $texto . "\n";
$saida .= '</div>' . "\n";
2022-04-08 12:32:49 +02:00
if($titulo)
{
2022-10-06 10:54:15 +02:00
$saida = '<section>' . "\n" . '<h3>' . $titulo . '</h3>' . "\n" . $texto . "\n" . '</section>';
2022-04-08 12:32:49 +02:00
}
2022-03-09 18:09:44 +01:00
return $saida;
}
function renderGaleria($titulo, $galeria)
2022-03-09 18:09:44 +01:00
{
$saida = '';
2022-10-06 10:54:15 +02:00
$saida .= '<section class="contedor columna swiper">' . "\n";
$saida .= '<h3 class="visually-hidden">';
if($titulo)
{
$saida .= $titulo;
}
else
{
$saida .= 'Galeria';
}
$saida .= '</h3>' . "\n";
2022-10-06 10:54:15 +02:00
$saida .= '<div class="swiper-wrapper">' . "\n";
foreach($galeria as $imaxe)
2022-03-09 18:09:44 +01:00
{
2022-10-06 10:54:15 +02:00
$saida .= '<div class="swiper-slide">' . "\n";
$saida .= '<figure>' . "\n";
$saida .= '<img src="' . $imaxe->url . '" alt="' . $imaxe->description . '">' . "\n";
$saida .= '<figcaption>' . $imaxe->description . '</figcaption>' . "\n";
$saida .= '</figure>' . "\n";
$saida .= '</div>' . "\n";
2022-03-09 18:09:44 +01:00
}
2022-10-06 10:54:15 +02:00
$saida .= '</div>' . "\n";
$saida .= '<div class="swiper-button-prev"></div>' . "\n";
$saida .= '<div class="swiper-button-next"></div>' . "\n";
$saida .= '<div class="swiper-paxination"></div>' . "\n";
$saida .= '</section>';
2022-03-09 18:09:44 +01:00
return $saida;
}
2022-04-08 12:32:49 +02:00
function renderReixa($titulo, $reixa)
{
$saida = '';
$saida .= '<section class="contedor">' . "\n";
2022-10-06 10:54:15 +02:00
$saida .= '<h3 class="visually-hidden">';
2022-04-08 12:32:49 +02:00
if($titulo)
{
$saida .= $titulo;
}
else
{
$saida .= 'Reixa de imaxes';
}
$saida .= '</h3>' . "\n";
2022-10-06 10:54:15 +02:00
$saida .= '<div class="reixa ' . $posicion . '">' . "\n";
2022-04-08 12:32:49 +02:00
foreach($reixa as $imaxe)
{
2022-10-06 10:54:15 +02:00
$saida .= '<figure>' . "\n";
$saida .= '<img src="' . $imaxe->url . '" alt="' . $imaxe->description . '">' . "\n";
$saida .= '<figcaption>' . $imaxe->description . '</figcaption>' . "\n";
$saida .= '</figure>' . "\n";
2022-04-08 12:32:49 +02:00
}
2022-10-06 10:54:15 +02:00
$saida .= '</div>' . "\n";
$saida .= '</section>';
2022-04-08 12:32:49 +02:00
return $saida;
}
function renderTextoImaxe($titulo, $texto, $imaxe, $posicion)
2022-03-09 18:09:44 +01:00
{
$saida = '';
2022-10-06 10:54:15 +02:00
$saida .= '<div class="celda ' . $posicion . '">' . "\n";
$saida .= '<figure>' . "\n";
$saida .= '<img src="' . $imaxe->url . '" alt="' . $imaxe->description . '">' . "\n";
$saida .= '<figcaption>' . $imaxe->description . '</figcaption>' . "\n";
$saida .= '</figure>' . "\n";
2022-04-08 12:32:49 +02:00
if($texto)
{
2022-10-06 10:54:15 +02:00
$saida .= $texto . "\n";
2022-04-08 12:32:49 +02:00
}
2022-10-06 10:54:15 +02:00
$saida .= '</div>' . "\n";
2022-04-08 12:32:49 +02:00
if($titulo)
{
2022-10-06 10:54:15 +02:00
$saida = '<section>' . "\n" . '<h3>' . $titulo . '</h3>' . "\n" . $saida . '</section>';
2022-03-09 18:09:44 +01:00
}
return $saida;
}
function renderTextoMantemento($titulo, $texto, $imaxe)
{
$saida = '';
$saida .= '<section>' . "\n";
2022-10-06 10:54:15 +02:00
$saida .= '<h3>' . $titulo . '</h3>' . "\n";
if($imaxe)
{
2022-10-06 10:54:15 +02:00
$saida .= '<figure>' . "\n";
$saida .= '<img src="' . $imaxe->url . '" alt="' . $imaxe->description . '">' . "\n";
$saida .= '<figcaption>' . $texto . '</figcaption>' . "\n";
$saida .= '</figure>' . "\n";
}
else
{
2022-10-06 10:54:15 +02:00
$saida .= $texto . "\n";
}
2022-10-06 10:54:15 +02:00
$saida .= '</section>';
2022-05-03 12:18:01 +02:00
return $saida;
}
function renderImaxeLigazon($titular, $imaxe, $ligazon)
{
$saida = '';
2022-10-06 10:54:15 +02:00
$saida .= '<div class="celda">' . "\n";
$saida .= '<figure class="enlace">' . "\n";
$saida .= '<img src="' . $imaxe->url . '" alt="' . $imaxe->description . '">' . "\n";
$saida .= '<figcaption class="columna">' . "\n";
$saida .= '<a href=' . $ligazon->url . '>' . $ligazon->title . '</a>' . "\n";
$saida .= '</figcaption>' . "\n";
$saida .= '</figure>' . "\n";
$saida .= '</div>' . "\n";
2022-05-03 12:18:01 +02:00
2022-03-09 18:09:44 +01:00
return $saida;
2022-10-25 14:47:38 +02:00
}
2022-10-27 14:10:14 +02:00
function renderCategoriasEtiquetas($data)
{
$saida = '';
switch ($data->first()->template->name)
{
case 'categoria':
$icono = 'folder';
$nome = 'categorias';
break;
case 'etiqueta':
$icono = 'tag';
$nome = 'etiquetas';
break;
default:
$icono = 'sn';
$nome = 'sin';
break;
}
$saida .= '<section id="categorias">' . "\n";
$saida .= '<h3>' . pages()->get('/noticias/' . $nome)->title . '</h3>' . "\n";
$saida .= '<ul class="lista">' . "\n";
foreach($data as $item)
{
$numPosts = pages()->count('template=publicacion, ' . $nome . '=' . $item->name);
$saida .= '<li class="info">' . "\n";
$saida .= '<a href="' . $item->url . '"><i class="icon-' . $icono . '"></i> ' . $item->title . '</a>' . "\n";
$saida .= '<span>(' . sprintf(_n('%d post', '%d posts', $numPosts), $numPosts) . ')</span>' . "\n";
$saida .= '</li>' . "\n";
}
$saida .= '</ul>' . "\n";
$saida .= '</section>' . "\n";
return $saida;
}
2022-10-25 14:47:38 +02:00
function renderResumen($texto = '', $limite = 120, $fin = '...')
{
2022-10-27 14:10:14 +02:00
$saida = '';
2022-10-25 14:47:38 +02:00
if($texto == '') return '';
if(strlen($texto) <= $limite) return $texto;
$saida = substr($texto, 0, $limite);
$pos = strrpos($saida, " ");
if($pos>0)
{
$saida = substr($saida, 0, $pos);
}
$saida .= $fin;
return $saida;
}
2022-10-27 14:10:14 +02:00
function renderArtigos($publicacion, $locale, $resumen = true)
{
$saida = '';
$data = strtotime($publicacion->fecha_publicacion);
$dateFormatter = \IntlDateFormatter::create(
$locale,
\IntlDateFormatter::NONE,
\IntlDateFormatter::NONE,
\date_default_timezone_get(),
\IntlDateFormatter::GREGORIAN
);
$saida .= '<article id="' . $publicacion->name .'">' . "\n";
$saida .= '<header class="publicacion-info">' . "\n";
$saida .= '<time datetime="' . $publicacion->fecha_publicacion . '">' ."\n";
$dateFormatter->setPattern('EEEE');
$saida .= '<em>' . ucfirst(datefmt_format($dateFormatter, $data)) . '</em>' . "\n";
$dateFormatter->setPattern('MMMM');
$saida .= '<strong>' . ucfirst(datefmt_format($dateFormatter, $data)) . '</strong>' . "\n";
$dateFormatter->setPattern('dd');
$saida .= '<span>' . datefmt_format($dateFormatter, $data) . '</span>' . "\n";
$saida .= '</time>' . "\n";
$saida .= '<div class="info">' . "\n";
$saida .= '<h3 class="publicacion-titulo">' . "\n";
$saida .= '<a href="' . $publicacion->url . '"><i class="icon-' . (($resumen) ? 'book' : 'book-open') . '"></i> ' . $publicacion->title . '</a>' . "\n";
$saida .= '</h3>' . "\n";
$saida .= '<dl>' . "\n";
$saida .= '<dt title="' . _x('Author', 'Post author') . '"><i class="icon-user"></i><span class="oculto-movil"> ' . _x('Author', 'Post author') . '</span></dt>' . "\n";
$saida .= '<dd>' . ucfirst($publicacion->createdUser->name) . '</dd>' . "\n";
$saida .= '<dt title="' . pages()->get('/noticias/categorias/')->title . '"><i class="icon-folder"></i><span class="oculto-movil"> ' . pages()->get('/noticias/categorias/')->title . '</span></dt>' . "\n";
$saida .= '<dd><a href="' . $publicacion->categorias->url . '">' . $publicacion->categorias->title . '</a></dd>' . "\n";
$saida .= '<dt title="' . pages()->get('/noticias/etiquetas/')->title . '"><i class="icon-tag"></i><span class="oculto-movil"> ' . pages()->get('/noticias/etiquetas/')->title . '</span></dt>' . "\n";
$saida .= '<dd>' . $publicacion->etiquetas->each("<a href='{url}'>{title}</a>") . '</dd>' . "\n";
$saida .= '</dl>' . "\n";
$saida .= '</div>' . "\n";
$saida .= '</header>' . "\n";
2022-11-06 12:54:16 +01:00
2022-10-27 14:10:14 +02:00
if($resumen)
{
2022-11-06 12:54:16 +01:00
if($publicacion->imaxe)
{
$thumb = $publicacion->imaxe->size(466, 260);
$saida .= '<img src="' . $thumb->url . '" alt="' . $publicacion->imaxe->description . '">' . "\n";
}
2022-10-27 14:10:14 +02:00
$saida .= '<div class="resumo">' . "\n";
$saida .= '<p>' . renderResumen(getTextoLimpo(getSeccions($publicacion->seccions))) . '</p>' . "\n";
$saida .= '<p><a href="' . $publicacion->url . '"><i class="icon-arrow-right"></i>' . _x("Read more", "Read more") . '</a></p>' ."\n";
$saida .= '</div>' . "\n";
}
else
{
2022-11-06 12:54:16 +01:00
if($publicacion->imaxe)
{
$thumb = $publicacion->imaxe->size(466, 260);
$saida .= '<a href="' . $publicacion->imaxe->url . '"><img src="' . $thumb->url . '" alt="' . $publicacion->imaxe->description . '"></a>' . "\n";
}
2022-10-27 14:10:14 +02:00
$saida .= '<div class="secciones">' . "\n";
$saida .= getSeccions($publicacion->seccions) . "\n";
$saida .= '</div>' . "\n";
}
$saida .= '</article>' . "\n";
return $saida;
}