summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b4a7e11)
raw | patch | inline | side by side (parent: b4a7e11)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 9 Jun 2005 09:40:56 +0000 (09:40 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 9 Jun 2005 09:40:56 +0000 (09:40 +0000) |
html/helpviewer.php | patch | blob | history |
diff --git a/html/helpviewer.php b/html/helpviewer.php
index 873d79d9ee0dc29ff229e0191b1c8108d7270977..b8915104cd9567344a0250ffe7be0122f43a65f2 100644 (file)
--- a/html/helpviewer.php
+++ b/html/helpviewer.php
<?php
/*
This code is part of GOsa (https://gosa.gonicus.de)
- Copyright (C) 2003 Cajus Pollmeier
+ Copyright (C) 2003 Cajus Pollmeier, Fabian Hickert
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
+
+
/* Basic setup, remove eventually registered sessions */
require_once ("../include/php_setup.inc");
require_once ("../include/functions.inc");
##################
My PART ^^
##################
-
*/
+
//set_error_handler("myone");
$helpdir = "../doc/guide/admin/en/manual_gosa_en/";
$defaultpage = "index.html";
$maxresults = 10;
$minwordlength= 3;
-
+// Only for testing delete this if everything works fine
function myone($par1,$par2,$par3,$par3)
{
print "<br>Seite : ".$par1."<br>Name : ".$par2."<br>Seite : ".$par3."<br>Zeile : ".$par3;
}
/* Define which tags musst be delete, header, navigation, banner */
+#fixme Theres a better method to handle replacment , preg_replace can handle arrays , this, would be little easier
$i=0;
$replacements=array();
$replacements['range'][$i]['from'] = "/<!DOC.*<BODY >/";
/* Get Keyword */
$keyword = $_POST['search_string'];
-
+
/* Save Keyword to be able to show last searched word in template */
$_SESSION['search_string']= $keyword;
/* Create result list */
$smarty->assign("help_contents",searchlist($arr,$res,$maxresults));
-
+
/* Output html ...*/
$header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
$display= $header.$smarty->fetch(get_template_path('help.tpl'));
echo $display;
-/*
- Don't search, only show selected page
-*/
+ /*
+ Don't search, only show selected page
+ */
}else{
/* present last searched word(s)*/
if(isset($_GET['pg'])){
$page = $_GET['pg'];
}
-
+
/* test if this page exists, in our array of files */
if((!isset($helppages[$page]))&&($page!=$defaultpage))
{
- print "Requested helppage is unknown, redirekted to index";
+ //print "Requested helppage is unknown, redirekted to index"; // For debugging only
$page = $defaultpage;
}
echo $display;
}
-
-
-/*
- Only function definition will follow here
-/*
-
-
+/*******************************************
+ Only function definition will follow here
+#fixme Exclude function to seperate file
+/*******************************************
/* Reads all files in specified directory with contents an some inforations about the file */
- /* Read all files with contents*/
- /* |Folder="/var/ww...",
+/* Read all files with contents*/
+/* |Folder="/var/ww...",
| |Fileprefix="node"
| | |Filesuffix=".html"
| | | |WithoutContent=false(This means : read content)
/* While theres is an unreaded file in our resource */
while (($file = readdir($dir)) !== false) {
-
+
/* Filter all files which arn't intressting */
if((strstr($file,$suffix))&&($file!=".")&&($file!="..")&&(strstr($file,$prefix))){
-
+
/* Collect informations */
$str[$file]=array();
$str[$file]['name'] = $file;
$str[$file]['size'] = filesize($basedir.$file);
-
+
/* Readfile conent too ? */
if(!$onlyIndex){
$str[$file]['content']= remove_unwanted_tags(linkwrapper(getcontents($basedir.$file),""),$replacements);
}
}
- /* Only get on file*/
+ /* Only get on file*/
}else{
/* Pages read = 1 */
$cnt = 1;
$str[$file] = array();
$str[$file]['name'] = $file;
$str[$file]['size'] = filesize($basedir.$file);
-
+
/* If onlyIndex == true skip reading content */
if(!$onlyIndex){
$str[$file]['content']= remove_unwanted_tags(linkwrapper(getcontents($basedir.$file),""),$replacements);
}
-
+
/* Include file status, for debugging, not used in script yet */
$str[$file]['stat'] = stat($basedir.$file);
}
{
$str = "" ; // Temporary variable for file contents
$tmp = "" ; // Temporary varibale for partitial file contents
-
+
/* open file and read*/
$fp = fopen($file,"r");
if($fp) {
/*Remove tags */
function remove_unwanted_tags($str,$replacements)
{
- #fixme This solution is ....
+#fixme This solution is ....
$str=str_replace("\n","||WasBr||",$str);
foreach($replacements['range'] as $var)
{
return($str);
}
-
-
+/* Search content */
function search($arr,$word)
{
global $minwordlength;
$word = preg_replace("[^a-z0-9_+% ]","",$word);
$words = split(" ",str_replace("+"," ",$word));
-
-
/* Check all wordlengths */
foreach($words as $tryword){
$tryword = trim($tryword);
}
}
-
-
/* Use words to search the content */
foreach($arr as $key=>$val)
{
/* overallhits counts hits per page */
$overallhits=0;
-
+
/* Search all words */
foreach($useablewords as $word)
{
/* Get all hits for the word in $matches*/
preg_match_all("/".$word."/i",$arr[$key]['content'], $matches,PREG_OFFSET_CAPTURE);
+ /* Filter in Tag results*/
+ if(count($matches[0])){
+ foreach($matches[0] as $num=>$hit){
+ if(is_in_tag($arr[$key]['content'],$hit[1])) {
+ unset($matches[0][$num]);
+ }
+ }
+ }
+
/* Count matches */
$overallhits=$overallhits + count($matches[0]);
if($overallhits > $result['global']['maxhit']){
$result['global']['maxhit']=$overallhits;
}
-
+
/* Add results for word to return value*/
$result[$key]['match'][$word]=array();
$result[$key]['match'][$word]=$matches[0];
}
}
}
-
+
/* Save result in Session, so we can mark words later, or go back to search, without searching again*/
$_SESSION['lastresults'] = $result;
return($result);
/* Detect 10 best Sites */
foreach($res as $key=>$val){
-
+
/* Skip results with no hits */
if($val['hits']['overall']>0){
$topten[$key] = $val['hits']['overall'];
foreach($topten as $name => $hits) {
$ret.= createResultEntry($arr[$name],$res[$name],$name,$global['maxhit']);
}
-
+
/* appending footer message for resultlist */
- $ret.= "<br> ".count($topten)." Results for your search with the keyword <b>".$_SESSION['search_string']."</b> it is interpreted as <b>".$_SESSION['parsed_search_keyword']."</b>";
-
+ $ret.= "<br> ".count($topten)." - "._("Results for your search with the keyword")." <b>".$_SESSION['search_string']."</b>"._(" interpreted as ")."<b>".$_SESSION['parsed_search_keyword']."</b>";
+
return($ret);
}
/* Creates HTML output for a single search result entry */
function createResultEntry($entry,$res,$name,$max)
{
-
$percentage = (int)(($res['hits']['overall'] / $max) * 100) ;
- $str = "<b><a href=\"?pg=".$name."&mark=1\">With ".$percentage."% hit in file ".$name."</a></b><br>" ;
+ $str = "<b><a href=\"?pg=".$name."&mark=1\">".$percentage."% "._("hit rate in following file ").$name."</a></b><br>" ;
$str.= substr(strip_tags($entry['content']),0,200);
$str.= "<hr>";
return($str);
}
+
+/*Simple function to detect if we prepare to change a tag or visible text */
+function is_in_tag($string,$pos)
+{
+ $pos1 = strpos($string,"<",$pos);
+ $pos2 = strpos($string,">",$pos);
+
+ if ($pos1 > $pos2) {
+ return(true);
+ }else{
+ return(false);
+ }
+}
+
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>