Paxina de procura.

This commit is contained in:
Laegnur 2023-03-11 12:53:47 +01:00
parent 03414732d1
commit d4f77bb8da
4 changed files with 1904 additions and 48 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,60 +1,55 @@
<?php namespace ProcessWire;
/** @var Page $page API variable */
$atopar = $sanitizer->text($input->get('q'));
$menu = '';
$contido = '';
$mantemento = $inicio->mantemento;
if($mantemento && !$user->isLoggedin())
if($configuracion['mantemento']['activo'] && !$user->isLoggedin())
{
$session->redirect($inicio->url);
}
else
{
$atopar = $sanitizer->text($input->get('q'));
$menu = renderMenu($inicio->children);
}
$contido .= '<article id="' . $page->name . '">' . "\n";
$contido .= '<h2 class="bloque"><i class="icon-search"></i> ';
$contido .= $atopar ? $page->title . ': ' . $atopar : $page->title;
$contido .= '</h2>' . "\n";
$contido .= renderMigasPan($page) . "\n";
$contido .= '<article id="' . $page->name .'" class="container">' . "\n";
$contido .= '<h2 class="visually-hidden">' . ucfirst($page->title) . '</h2>' . "\n";
if($atopar)
if($atopar)
{
$input->whitelist('q', $atopar);
$atopar = $sanitizer->selectorValue($atopar);
$selector = "";
$selector .= "(title|seccions.titular|seccions.artigo~=$atopar)";
$selector .= ",(seccions.destacados.titular~=$atopar)";
$selector .= ",(seccions.destacados.artigo~=$atopar), limit=50";
if($user->isLoggedin()) $selector .= ", has_parent!=2";
$matches = $pages->find($selector);
$cnt = $matches->count;
if($cnt)
{
$input->whitelist('q', $atopar);
$atopar = $sanitizer->selectorValue($atopar);
$selector = "title|seccions.artigo~=$atopar, limit=50";
if($user->isLoggedin()) $selector .= ", has_parent!=2";
$matches = $pages->find($selector);
$cnt = $matches->count;
if($cnt)
$contido .= '<h3>Resultados para: ' . $atopar . '</h3>' . "\n";
$contido .= '<p>' . sprintf(_n(_x('Atopouse %d páxina', 'Found 1 page'),
_x('Atopáronse %d páxinas', 'Found multiple pages'), $cnt), $cnt) . '</p>' . "\n";
$contido .= '<section>' . "\n";
$contido .= '<h4 class="accesibilidade-oculto">' . _x("Resultados", "Search results") . '</h4>' . "\n";
$contido .= '<ul class="lista">'."\n";
foreach($matches as $paxina)
{
$contido .= '<h3>Resultados para: ' . $atopar . '</h3>' . "\n";
$contido .= '<p>' . sprintf(_n(_x('Atopouse %d páxina', 'Found 1 page'),
_x('Atopáronse %d páxinas', 'Found multiple pages'), $cnt), $cnt) . '</p>' . "\n";
$contido .= '<section>' . "\n";
$contido .= '<h4 class="accesibilidade-oculto">' . _x("Resultados", "Search results") . '</h4>' . "\n";
$contido .= '<ul class="lista">'."\n";
foreach($matches as $paxina)
{
$contido .= '<li class="info">' . "\n";
$contido .= '<a href="' . $paxina->url . '"><i class="icon-play"></i> ' . $paxina->title . '</a>' . "\n";
$contido .= '</li>' . "\n";
}
$contido .= '</ul>'."\n";
$contido .= '</section>';
}
else
{
$contido .= '<h3>' . _x('Mapa do sitio', 'Sitemap') . '</h3>' . "\n";
$contido .= '<p>' . _x('Sentímolo, non se atoparon resultados', 'Sorry, no results were found.') . '</p>' . "\n";
$contido .= '<section>' . "\n";
$contido .= '<h4 class="accesibilidade-oculto">' . _x('Mapa do sitio', 'Sitemap') . '</h4>' . "\n";
$contido .= renderMapaDoSitio($inicio, 3, 'mapa-sitio');
$contido .= '</section>';
$contido .= '<li class="info">' . "\n";
$contido .= '<a href="' . $paxina->url . '"><i class="icon-play"></i> ' . $paxina->title . '</a>' . "\n";
$contido .= '</li>' . "\n";
}
$contido .= '</ul>'."\n";
$contido .= '</section>';
}
else
{
@ -65,5 +60,14 @@ else
$contido .= renderMapaDoSitio($inicio, 3, 'mapa-sitio');
$contido .= '</section>';
}
$contido .= '</article>' . "\n";
}
}
else
{
$contido .= '<h3>' . _x('Mapa do sitio', 'Sitemap') . '</h3>' . "\n";
$contido .= '<p>' . _x('Sentímolo, non se atoparon resultados', 'Sorry, no results were found.') . '</p>' . "\n";
$contido .= '<section>' . "\n";
$contido .= '<h4 class="accesibilidade-oculto">' . _x('Mapa do sitio', 'Sitemap') . '</h4>' . "\n";
$contido .= renderMapaDoSitio($inicio, 3, 'mapa-sitio');
$contido .= '</section>';
}
$contido .= '</article>' . "\n";

View file

@ -7,7 +7,7 @@ $contido = '';
if($configuracion['mantemento']['activo'] && !$user->isLoggedin())
{
$session->redirect($inicio->url);
$session->redirect($inicio->url);
}
else
{

View file

@ -166,9 +166,9 @@ function renderMenu($paxinas, $clase = 'navbar-nav')
/**
* @param array|PageArray $paxina
* @param string $separador
* @return string
*/
* @param string $separador
* @return string
*/
function renderMigasPan($paxina, $separador = '<i class="icon-chevrons-right"></i>')
{
@ -223,6 +223,39 @@ function renderMigasPan($paxina, $separador = '<i class="icon-chevrons-right"></
return $saida;
}
/**
* @param array|PageArray $paxinas
* @param int $maxDepth How many levels of navigation below current should it go?
* @param string $fieldNames Any extra field names to display (separate multiple fields with a space)
* @param string $class CSS class name for containing <ul>
* @return string
*
*/
function renderMapaDoSitio($paxinas, $profundidade = 0, $clase = 'nav')
{
$saida = '';
$actual = wire('page');
if($paxinas instanceof Page) $paxinas = array($paxinas);
foreach($paxinas as $paxina)
{
$saida .= '<li class="'. (($paxina->id == $actual->id) ? ' active' : '') . '">' . "\n";
$saida .= "<a href='$paxina->url'>$paxina->title</a>";
if($paxina->hasChildren() && $profundidade)
{
if($class == 'nav') $class = 'nav nav-tree';
$saida .= renderMapaDoSitio($paxina->children, $profundidade-1, $clase);
}
$saida .= "</li>";
}
if($saida) $saida = '<ul class="' . $class . '">' . $saida . '</ul>' ."\n";
return $saida;
}
/**
* @param string $titulo
* @param string $texto