Modifications sur le cms - search

Pour accomplir cette rectification, sur les recherches, il vous faudra forker deux fichiers.
  1. search.php
  2. lang


<?php
#  ………  adHoc CMS ©
#  ………  by Penanders 2013-2017
#  ………  Licence: GNU-GPL V3
#  ………  Modification Le Babelleir (CréaSite)
require_once("include/config.inc");
include_once("include/functions.inc");
(isset($_GET['q'])) ? $q = decode_gpc($_GET['q']) : $q = ""; //search string
(isset($_GET['c'])) ? $c = 1 : $c = 0;  // caps 
(isset($_GET['w'])) ? $w = 1 : $w = 1;  // word
(isset($_GET['p'])) ? $p = decode_gpc($_GET['p']) : $p = 1;  // page
require_once(PATH."extensions/pagination/".$cfg['ext_pagination']."/extension".INCEXT);
include("include/hpage.inc");
htable($msg_pub['search'], "100%");
echo '<div>
';
//configuration du script
# nombre maximum de mots dans une phrase pour une recherche
$SRC_maxwords=10;
# nombre de résultats à afficher par page
$SRC_maxresults=3;
# Nombre maximum de caractères à afficher pour la description de la page
$SRC_maxdescr=500;
# Nombre maximum de caractères à afficher pour les autres mots compris dans la page
$SRC_maxchars=80;
$p--;
$q=trim(stripslashes(strip_tags($q)));
if ($c==0) {$q=strtolower($q); }
$q=str_replace(" ","+",$q);
# effacement des virgules lors de la recherche
$SRC_templist=array(); 
$SRC_list=array();
$SRC_templist=explode("+",$q);
# effacement des espaces lors de la recherche
foreach ($SRC_templist as $val){
	if ((trim($val) !="") && (count($SRC_list)<=($SRC_maxwords-1)) && (!in_array($val,$SRC_list))) $SRC_list[] = $val;
}
$q=implode(" ",$SRC_list);?>
<fieldset>
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="get">
<div class="search-form" >
<div class="w33">
<?php echo '<input type="text" name="q" style="width:75%;"';
// $browser=$HTTP_USER_AGENT;
// if (1*strpos(strtolower($browser),"msie")>0) { echo "25"; } else { echo "14"; }
echo " value=\"".$q."\"/>";
echo ' <input class="btn btn-default" type="submit" value="'.$msg_pub['searching'].'" style="width:20%" />';
?>
  </div>
  <div>
      <input type="checkbox" name="c" <?php if ($c) echo 'checked'; ?>/> <?php echo $msg_pub['uppercase_lowercase']; ?><br />
      <input type="checkbox" name="w" <?php if ($w) echo 'checked'; ?>/> <?php echo $msg_pub['complete_word']; ?><br />
  </div>
</div>
</form></fieldset><br />
<?php 
if ($q!="") { 
	function SRCFind($content){
		global $msg_pub, $SRC_list, $c, $w, $id, $SRC_result,$SRC_maxdescr,$SRC_maxchars;
      $j=0;
      $k=0;
      $foundlist=array();
      if ($c==0) $content=strtolower($content);
      /* $content=preg_replace("@<[/!]*?[^<>]*?>@si", " ", $content);  */
      $content=str_replace("&nbsp;", " ",$content);
      $content_list=preg_split('/[.x20:;,?!]+/',$content);
      foreach ($content_list as $word){
         foreach ($SRC_list as $SRC_word){
            if ($w==0){
               if (strpos($word,$SRC_word) !== false){
                  if (!in_array($SRC_word,$foundlist)) $foundlist[] = $SRC_word;
                  $j++;
                  $SRC_result['occurence'][$id]++;
                  if ($j==1){  
                     $wordpos=strpos($content,$word);
                     $wordlen=mb_strlen($word);
                     $contentlen=mb_strlen($content);
                     if ($contentlen>$SRC_maxdescr){
                        $from=$wordpos-ceil(($SRC_maxdescr-$wordlen)/2);
                        $to=$from+$SRC_maxdescr;
                        if ($from<0) { 
                           $to=$to-$from;
                           $from=0; 
                        }
                        if ($to>$contentlen) $to=$contentlen;
                     } else {
                        $from=0; 
                        $to=$contentlen;
                     }
                     $SRC_text=substr($content, $from,$to-$from);
                     $SRC_text="...".$SRC_text."...";
                     $found=$word;
                  } elseif ($j>1) { 
                     if (strlen($found)<$SRC_maxchars) { 
                        $word=str_replace(",","", $word);
                        $found.= ", ".$word; 
                     } else { 
                        if ($k!=1) {
                           $found=$found." ...";
                           $k=1;
                        } 
                     }
                  }
                  $SRC_text=str_replace($word,'<span class="evidence">'.$word."</span>",$SRC_text);
                  $SRC_result['text'][$id]=$SRC_text;									
               }
            } else{
               if (preg_match("/b".$SRC_word.'b/', $word)) {
                  if (!in_array($SRC_word,$foundlist)) { 
                     $foundlist[] = $SRC_word; 
                  }
                  $j++;
                  $SRC_result['occurence'][$id]++;
                  if ($j==1){
                     $wordpos=strpos($content,$word);
                     $wordlen=strlen($word);
                     $contentlen=strlen($content);
                     if ($contentlen>$SRC_maxdescr){
                        $from=$wordpos-(($SRC_maxdescr-$wordlen)/2);
                        $to=$from+$SRC_maxdescr;
                        if ($from<0) { 
                           $to=$to-$from; 
                           $from=0; 
                        }
                        if ($to>$contentlen) $to=$contentlen;
                     } else { 
                        $from=0;
                        $to=$contentlen; 
                     }
                     $SRC_text=substr($content, $from,$to-$from);
                     $SRC_text="...".$SRC_text."...";
                     $SRC_result['text'][$id]=$SRC_text;
                     $found=$word;
                  } elseif ($j>1) { 
                     if (strlen($found)<$SRC_maxchars) { 
                        $word=str_replace(",","", $word);
                        $found.= ", ".$word; 
                     } else { 
                        if ($k!=1) {
                           $found=$found." ...";
                           $k=1;
                        } 
                     }
                  }
                  $SRC_text=preg_replace("/b".$SRC_word.'b/',' <span class="evidence">'.$word."</span>",$SRC_text);
                  $SRC_result['text'][$id]=$SRC_text;	
               }
            }
         }
      }
      $SRC_result['content_list'][$id]=count($foundlist);
      //$SRC_result['found'][$id]=$found;
      $SRC_result['found'][$id]=implode (", ", $foundlist);
      if ($SRC_result['content_list'][$id]) $id++; 
	}
	
	function SRCDisplayResult(){
		global $msg_pub, $SRC_result, $SRC_maxresults, $SRC_list, $p, $q,$c,$w;
		echo '<fieldset><div class="w11">
    <h3><p style="text-align:center;font-weight:bold;margin-bottom:1rem;">  '.$msg_pub['search_result'].'</p></h3>
  ';
  		
		$SRC_countresults=count($SRC_result['file_url']);
		if ($SRC_countresults==0) { 
			echo "<br /><br />".$msg_pnl['no_result']."<br /><br /></div>n";
		}  else {
			@array_multisort($SRC_result['content_list'], SORT_DESC,
								  $SRC_result['occurence'],SORT_DESC, 
								  $SRC_result['file_url'],
								  $SRC_result['text'],
								  $SRC_result['found'],
								  $SRC_result['title']
								  );
			$q=str_replace(" ",", ",$q);
			if (count($SRC_list)>1) echo '<p>'.$msg_pub['these_words'];
			else echo '<p>'.$msg_pub['this_word'];
			echo '&nbsp;<span class="label label-success">'.$q."</span></p>n".PHP_EOL;
			$SRC_pgfrom=$p*$SRC_maxresults+1;
			$SRC_pgto=$SRC_pgfrom+$SRC_maxresults-1;
			if ($SRC_pgto>$SRC_countresults) $SRC_pgto=$SRC_countresults;
			echo '<p>'
	.$SRC_countresults.' '.$msg_pub['pages'].' '.$msg_pub['result_ranked']."</p></fieldset><br />
	n";
			for ($i=0;$i<$SRC_maxresults;$i++){
				$curr=$p*$SRC_maxresults+$i;
				$k=$curr+1;
				if ($k<=$SRC_pgto) {
					echo '<div class="w11">'.PHP_EOL;
					$SRC_result['file_url'][$curr]=str_replace("./","",$SRC_result['file_url'][$curr]);
					
					//$file=fopen($SRC_result['file_url'][$curr],"r");
					//while ($SRC_43<7){
						// $content=fgetss($file,1000,"");
						// $content=trim($content);
						// if ($content!=""){
							echo '<div>
	<span class="box-color-2" style="padding:4px">'.$k.'.</span>
	<a class="btn btn-default" href="//creasite.babelleir.be/'.PATH_LNK.$SRC_result['file_url'][$curr].'"><span class="glyphicon glyphicon glyphicon-hand-right" aria-hidden="true">&nbsp;</span>
	'.$SRC_result['title'][$curr].'</a><br />';
					if ($SRC_result['content_list'][$curr]==1) $content_list='</span>'.$msg_pub['occurence'].'<span style="color:#5E94ca">';
					else $content_list="</span>".$msg_pub['occurences'].'<span style="color:#5E94ca">';
					if ($SRC_result['occurence'][$curr]==1) $occurence='</span>'.$msg_pub['occurence'];
					else $occurence="</span>".$msg_pub['words_in_text'];
					echo"n";
					echo $SRC_result['text'][$curr]."<br />n";
					echo '<br />'.$msg_pub['same_words'].' <strong>'.$SRC_result['found'][$curr].'</strong><br />'.$SRC_result['content_list'][$curr].'&nbsp;'.$content_list.' | <span class="badge">'.$SRC_result['occurence'][$curr].'</span>&nbsp;'.$occurence.'</div><hr>';
#					echo '<div><br /><p><a href="//creasite.babelleir.be/'.PATH_LNK.$SRC_result['file_url'][$curr].'" target="_self">'.$SRC_result['file_url'][$curr].'</a></p></div>'.PHP_EOL;
					echo "</div>n<br />n";
				}
			}
		}
		if ($SRC_countresults>$SRC_maxresults) {
         $SRC_url = "search.php?q=".implode('+', $SRC_list);
         if ($c) $SRC_url.="&amp;c=".$c;
         if ($w) $SRC_url.="&amp;w=".$w;
         $SRC_url .="&amp;p=";
         $p++;
         echo DisplayPagerByID($SRC_url, $p, $SRC_countresults, $SRC_maxresults);
		}
	}	
	$SRC_modules = array();
	$SRC_modules[] ='pages';
	$SRC_result = array();
	$id=0;
	foreach ($SRC_modules as $module) {
		if (file_exists("modules/".$module."/search/search.inc")) {
			include("modules/".$module."/search/search.inc");
		}
	}
	//$SRC_step = "";
	SRCDisplayResult(); 
} //fine if ricerca 
?>
</div>
<?php
btable();
include("include/bpage.inc");



Info | Imprimer | Permalien