Ajouter un moteur de recherche


Pour ajouter un moteur de recherche à partir d'une page statique:

            1. créer une page statique
            2. copier le code ci-dessous dans la page statique
            3. sauvegarder

Pour PluXml 5.0+

Code :


<?php
# Page statique Pluxml : moteur de recherche
# révision 1.0 par Stephane :
#	- paramétrage du format de la date
# révision 1.1 par Amaury :
#   - Compatibilité PluXml 5.0
# révision 1.2 par Amaury :
#   - Fix : recherche des articles multi-catégorisés

if(!defined('PLX_ROOT')) exit;

# Renseignez ici le format de la date
$format_date = '#num_day/#num_month/#num_year(4)';

global $plxShow;

if (!empty($_POST['searchfield'])) {

	$plxGlob_arts = plxGlob::getInstance(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles']);
	$aFiles = $plxGlob_arts->query('/[0-9]{4}.[home|0-9,]*.[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/','search','rsort');

	if(is_array($aFiles)) { # On a des fichiers
    
		$searchword = strtolower(htmlspecialchars($_POST['searchfield']));
		ob_start();
		while(list($k,$v) = each($aFiles)) { # On parcourt tous les fichiers
	
			$art = $plxShow->plxMotor->parseArticle(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles'].$v);

			$searchstring  = strtolower(addslashes($art['title'].$art['chapo'].$art['content'])); 
		
			if (strpos($searchstring,$searchword) !== false) {
				$searchresults = true;
				$art_num = intval($art['numero']);
				$art_url = plxUtils::strCheck($art['url']);
				$art_title = plxUtils::strCheck($art['title']);
				$art_date = plxDate::dateIsoToHum($art['date'], $format_date);
				echo '<li>'.$art_date.': <a href="'.$plxShow->plxMotor->aConf['racine'].'?article'.$art_num.'/'.$art_url.'">'.$art_title.'</a></li>'; 
			}
		}
		$content = ob_get_clean(); 
		if ($content!='')
			echo '<p>Résultats de la recherche.<br /><ol class="search_results">'.$content.'</ol></p>';
		else
			echo '<p>Aucun résultat pour <strong>'.$searchword.'</strong></p>';
	}
}
?>

<form method="post" id="searchform" action="<?php echo PLX_ROOT ?>?<?php $plxShow->get() ?>">
<p class="searchform">
	<input type="hidden" name="search" value="search"  />
	<input type="text" class="searchfield" name="searchfield" value="Rechercher..." onblur="if(this.value=='') this.value='Rechercher...';" onfocus="if(this.value=='Rechercher...') this.value='';" /> 
	<input type="submit" class="searchbutton" value="Go" />
</p>
</form>

Pour intégrer le formulaire dans la sidebar, enlevez-le de votre page statique et coller le code suivant dans le fichier sidebar.php de votre thème:

Code :


<form method="post" id="searchform" action="<?php $plxShow->urlRewrite('static1/rechercher') ?>">
<p class="searchform">
	<input type="hidden" name="search" value="search"  />
	<input type="text" class="searchfield" name="searchfield" value="Rechercher..." onblur="if(this.value=='') this.value='Rechercher...';" onfocus="if(this.value=='Rechercher...') this.value='';" /> 
	<input type="submit" class="searchbutton" value="Go" />
</p>
</form>


Remplacer ensuite static1/rechercher par l'ID de votre page ainsi que son nom.


Pour PluXml 4.2

Code :


<?php
# Page statique Pluxml : moteur de recherche
# revision 1.0 par Stephane :
#	- compatibilité pluxml 4.2 
#	- paramètrage du format de la date

if(!defined('PLX_ROOT')) exit;

# Renseignez ici le format de la date
$format_date = '#num_day/#num_month/#num_year(4)';

global $plxShow;

if (!empty($_POST['searchfield'])) {

	$plxGlob_arts = new plxGlob(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles']);
	$aFiles = $plxGlob_arts->query('/[0-9]{4}.([0-9]{3}|home).[0-9]{12}.[a-z0-9-]+.xml$/','search','rsort');

	if(is_array($aFiles)) { # On a des fichiers
    
		$searchword = strtolower(htmlspecialchars($_POST['searchfield']));
		ob_start();
		while(list($k,$v) = each($aFiles)) { # On parcourt tous les fichiers
	
			$art = $plxShow->plxMotor->parseArticle(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles'].$v);

			$searchstring  = strtolower(addslashes($art['title'].$art['chapo'].$art['content'])); 
		
			if (strpos($searchstring,$searchword) !== false) {
				$searchresults = true;
				$art_num = intval($art['numero']);
				$art_url = plxUtils::strCheck($art['url']);
				$art_title = plxUtils::strCheck($art['title']);
				$art_date = plxDate::dateIsoToHum($art['date'], $format_date);
				echo '<li>'.$art_date.': <a href="'.$plxShow->plxMotor->aConf['racine'].'?article'.$art_num.'/'.$art_url.'">'.$art_title.'</a></li>'; 
			}
		}
		$content = ob_get_clean(); 
		if ($content!='')
			echo '<p>Résultats de la recherche.<br /><ol class="search_results">'.$content.'</ol></p>';
		else
			echo '<p>Aucun résultat pour <strong>'.$searchword.'</strong></p>';
	}
}
?>

<form method="post" id="searchform" action="<?php echo PLX_ROOT ?>?<?php $plxShow->get() ?>">
<p class="searchform">
	<input type="hidden" name="search" value="search"  />
	<input type="text" class="searchfield" name="searchfield" value="Rechercher..." onblur="if(this.value=='') this.value='Rechercher...';" onfocus="if(this.value=='Rechercher...') this.value='';" /> 
	<input type="submit" class="searchbutton" value="Go" />
</p>
</form>


Pour Pluxml 4.1.x

Code :


<?php
if(!defined('PLX_ROOT')) exit;

global $plxShow;

if (!empty($_POST['searchfield'])) {

	$plxGlob_arts = & new plxGlob(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles']);
	$aFiles = $plxGlob_arts->query('/[0-9]{4}.([0-9]{3}|home).[0-9]{12}.[a-z0-9-]+.xml$/','search','rsort');

	if(is_array($aFiles)) { # On a des fichiers
    
		$searchword = strtolower(addslashes($_POST['searchfield']));
		ob_start();
		while(list($k,$v) = each($aFiles)) { # On parcourt tous les fichiers
	
			$art = $plxShow->plxMotor->parseArticle(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles'].$v);

			$searchstring  = strtolower(addslashes($art['title'].$art['chapo'].$art['content'])); 
		
			if (strpos($searchstring,$searchword) !== false) {
				$searchresults = true;
				$art_num = intval($art['numero']);
				$art_url = htmlspecialchars($art['url'],ENT_QUOTES,PLX_CHARSET);
				$art_title = htmlspecialchars($art['title'],ENT_QUOTES,PLX_CHARSET);
				$art_date = substr($art['date'], 8, 2).'/'.substr($art['date'], 5, 2).'/'.substr($art['date'], 0, 4);
				echo '<li>'.$art_date.': <a href="'.$plxShow->plxMotor->aConf['racine'].'?article'.$art_num.'/'.$art_url.'">'.$art_title.'</a></li>'; 
			}
		}
		$content = ob_get_clean(); 
		if ($content!='')
			echo '<p>Résultats de la recherche.<br /><ol class="search_results">'.$content.'</ol></p>';
		else
			echo '<p>Aucun résultat pour <strong>'.$searchword.'</strong></p>';
	}
}
?>

<form method="post" id="searchform" action="<?php echo PLX_ROOT ?>?<?php $plxShow->get() ?>">
<p class="searchform">
	<input type="hidden" name="search" value="search"  />
	<input type="text" class="searchfield" name="searchfield" value="Rechercher..." onblur="if(this.value=='') this.value='Rechercher...';" onfocus="if(this.value=='Rechercher...') this.value='';" /> 
	<input type="submit" class="searchbutton" value="Go" />
</p>
</form>