308 lines
8.4 KiB
PHP
308 lines
8.4 KiB
PHP
<?php namespace ProcessWire;
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
return $configuracion;
|
|
}
|
|
|
|
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)
|
|
{
|
|
$saida = '';
|
|
|
|
foreach($seccions as $seccion)
|
|
{
|
|
switch($seccion->template)
|
|
{
|
|
case 'repeater_seccions':
|
|
switch ($seccion->seccion_tipo->value)
|
|
{
|
|
case 'texto':
|
|
$saida .= renderTexto($seccion->titular, $seccion->artigo);
|
|
break;
|
|
case 'galeria':
|
|
$saida .= renderGaleria($seccion->titular, $seccion->imaxes_galeria);
|
|
break;
|
|
case 'reixa':
|
|
$saida .= renderReixa($seccion->titular, $seccion->imaxes_reixa);
|
|
break;
|
|
case 'imaxe_texto_lateral':
|
|
$saida .= renderTextoImaxe($seccion->titular, $seccion->artigo, $seccion->imaxe, $seccion->imaxe_posicion->value);
|
|
break;
|
|
}
|
|
break;
|
|
case 'repeater_mantemento_mensaxe':
|
|
$saida .= renderTextoMantemento($seccion->titular, $seccion->artigo, $seccion->imaxe);
|
|
break;
|
|
case 'repeater_imaxe_ligazon':
|
|
$saida .= renderImaxeLigazon($seccion->titular, $seccion->imaxe, $seccion->ligazon);
|
|
break;
|
|
}
|
|
}
|
|
return $saida;
|
|
}
|
|
|
|
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)
|
|
{
|
|
$saida .= '<li class="activo">';
|
|
}
|
|
else
|
|
{
|
|
$saida .= '<li>';
|
|
}
|
|
|
|
$saida .= '<a href="' . $paxina->url . '">' . $paxina->title . '</a>';
|
|
|
|
if($paxina->hasChildren() && $maxDepth)
|
|
{
|
|
if($id == 'nav')
|
|
{
|
|
$id = 'nav nav-tree';
|
|
}
|
|
$saida .= renderMenu($paxina->children, $maxDepth-1, $id);
|
|
}
|
|
|
|
$saida .= '</li>' . "\n";
|
|
}
|
|
|
|
if($saida)
|
|
{
|
|
$saida = '<ul id="' . $id . '">' . "\n" . $saida . '</ul>' . "\n";
|
|
}
|
|
|
|
return $saida;
|
|
}
|
|
|
|
function renderMigasPan($paxina, $separador = '<i class="icon-chevrons-right"></i>')
|
|
{
|
|
$saida = '';
|
|
|
|
$saida .= '<div class="contedor migas_pan" role="navigation" aria-label="' . _x('Current page', 'navigation') . ':">' . "\n";
|
|
$saida .= $separador;
|
|
foreach($paxina->parents() as $pai)
|
|
{
|
|
$saida .= '<span><a href="' . $pai->url . '">' . $pai->title . '</a></span> ' . $separador . ' ';
|
|
}
|
|
$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";
|
|
$saida .= '</div>';
|
|
|
|
return $saida;
|
|
}
|
|
|
|
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)
|
|
{
|
|
$saida = '';
|
|
|
|
$saida .= '<div class="celda">' . "\n";
|
|
$saida .= $texto . "\n";
|
|
$saida .= '</div>' . "\n";
|
|
|
|
if($titulo)
|
|
{
|
|
$saida = '<section>' . "\n" . '<h3>' . $titulo . '</h3>' . "\n" . $texto . "\n" . '</section>';
|
|
}
|
|
|
|
return $saida;
|
|
}
|
|
|
|
function renderGaleria($titulo, $galeria)
|
|
{
|
|
$saida = '';
|
|
|
|
$saida .= '<section class="contedor columna swiper">' . "\n";
|
|
$saida .= '<h3 class="visually-hidden">';
|
|
if($titulo)
|
|
{
|
|
$saida .= $titulo;
|
|
}
|
|
else
|
|
{
|
|
$saida .= 'Galeria';
|
|
}
|
|
$saida .= '</h3>' . "\n";
|
|
$saida .= '<div class="swiper-wrapper">' . "\n";
|
|
foreach($galeria as $imaxe)
|
|
{
|
|
$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";
|
|
}
|
|
$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>';
|
|
|
|
return $saida;
|
|
}
|
|
|
|
function renderReixa($titulo, $reixa)
|
|
{
|
|
$saida = '';
|
|
|
|
$saida .= '<section class="contedor">' . "\n";
|
|
$saida .= '<h3 class="visually-hidden">';
|
|
if($titulo)
|
|
{
|
|
$saida .= $titulo;
|
|
}
|
|
else
|
|
{
|
|
$saida .= 'Reixa de imaxes';
|
|
}
|
|
$saida .= '</h3>' . "\n";
|
|
$saida .= '<div class="reixa ' . $posicion . '">' . "\n";
|
|
foreach($reixa 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;
|
|
}
|
|
|
|
function renderTextoImaxe($titulo, $texto, $imaxe, $posicion)
|
|
{
|
|
$saida = '';
|
|
|
|
$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";
|
|
if($texto)
|
|
{
|
|
$saida .= $texto . "\n";
|
|
}
|
|
$saida .= '</div>' . "\n";
|
|
|
|
if($titulo)
|
|
{
|
|
$saida = '<section>' . "\n" . '<h3>' . $titulo . '</h3>' . "\n" . $saida . '</section>';
|
|
}
|
|
|
|
return $saida;
|
|
}
|
|
|
|
function renderTextoMantemento($titulo, $texto, $imaxe)
|
|
{
|
|
$saida = '';
|
|
|
|
$saida .= '<section>' . "\n";
|
|
$saida .= '<h3>' . $titulo . '</h3>' . "\n";
|
|
if($imaxe)
|
|
{
|
|
$saida .= '<figure>' . "\n";
|
|
$saida .= '<img src="' . $imaxe->url . '" alt="' . $imaxe->description . '">' . "\n";
|
|
$saida .= '<figcaption>' . $texto . '</figcaption>' . "\n";
|
|
$saida .= '</figure>' . "\n";
|
|
}
|
|
else
|
|
{
|
|
$saida .= $texto . "\n";
|
|
}
|
|
$saida .= '</section>';
|
|
|
|
return $saida;
|
|
}
|
|
|
|
function renderImaxeLigazon($titular, $imaxe, $ligazon)
|
|
{
|
|
$saida = '';
|
|
|
|
$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";
|
|
|
|
return $saida;
|
|
}
|
|
|
|
function renderResumen($texto = '', $limite = 120, $fin = '...')
|
|
{
|
|
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;
|
|
|
|
}
|