Exemplo n.º 1
0
 /**
  *Performs the search and does not need any parameters as they are already initialized
  *in the constructor. The template parsed output is assigned to
  *the private class variable $output. For output use method output()
  *
  *@access		public	 	  
  */
 public function perform_search()
 {
     //split query words in array
     $this->searcharray = preg_split('/[ +\\"\\x2D*~]+/', $this->searchstring);
     //walk array with auto_sw_replace
     foreach ($this->searcharray as $value) {
         if (strlen($value) < 4 and strlen($value) > 0) {
             $this->auto_sw_replace();
             break;
         }
     }
     //formulate main query to database
     $query = "SELECT id, text, match text against('{$this->searchstring}') as relevance FROM article ";
     $query .= "WHERE MATCH text AGAINST('{$this->searchstring}' IN BOOLEAN MODE) order by relevance desc;";
     //send query to database
     $result = mysql_query($query, $this->link_identifier);
     //compile template for appropriate case and parse it with the according values
     include_once "parser/templ_parser.php";
     switch (mysql_num_rows($result)) {
         case 0:
             $parser = new templ_parser("search.html");
             if (strlen($this->searchstring) > 3) {
                 $parser->compile_templ("if none");
             } else {
                 $parser->compile_templ("if too short");
             }
             $this->output = $parser->parse();
             break;
         default:
             //init templ_parser
             $parser = new templ_parser("searchresults.html");
             //format the results
             while ($row = mysql_fetch_assoc($result)) {
                 //strp the html and maybe php tags
                 $row['text'] = strip_tags($row['text']);
                 //center the searched words in the abstract
                 $row['text'] = $this->center_abstract($row['text']);
                 //bold the searchwords
                 $row['text'] = $this->bold_it($row['text']);
                 //generate the link to searchresult
                 include "include/tools.php";
                 $row['URL'] = tools::generateURL($row['id'], NULL, $this->link_identifier);
                 //calculate the MySQL Relevance in percent
                 $row['relevance'] = $this->rel_to_per($row['relevance']);
                 //put the formatted results in an output variable
                 $searchresults .= $parser->parse($row);
             }
             //destroy templ_parser and create new one
             $parser = new templ_parser("search.html");
             //compile the template for the case of searchresults
             $parser->compile_templ("if searchresults");
             //parse template
             $placeholders = array("searchresults" => $searchresults);
             $this->output = $parser->parse($placeholders);
             break;
     }
 }
Exemplo n.º 2
0
 /**
  *Handles the output for an article with db querying and template parsing
  *
  *@access	private
  */
 private function article()
 {
     $query = "SELECT title, synopsis, text, author, lastupdated, keyword ";
     $query .= "FROM article WHERE title='{$this->article}' AND cat_id={$this->cat}";
     $result = mysql_query($query, $this->link_identifier);
     if (mysql_num_rows($result) == 1) {
         //load template class
         include_once "parser/templ_parser.php";
         //instatiate a new object
         $parser = new templ_parser("article.html");
         $placeholder = mysql_fetch_assoc($result);
         //set timezone to gmt
         putenv("TZ=Europe/Berlin");
         $placeholder["lastupdated"] = date("d.m.y", $placeholder["lastupdated"]);
         $this->output = $parser->parse($placeholder);
     }
 }
Exemplo n.º 3
0
if (file_exists(BASEDIR . $uri) and strpos(array_pop($uri_array), ".") !== FALSE) {
    include BASEDIR . $uri;
    exit;
}
//open link to database server and select right database
$link_identifier = mysql_connect(SERVER, USER, PASS) or die("Keine Verbindung zur Datenbank!!!!");
mysql_select_db(DATABASE, $link_identifier);
//check, what's the request for...
switch ($uri_array[0]) {
    case "suche":
        require_once "search/search.php";
        if (isset($_GET)) {
            $module = new search($link_identifier);
            $module->perform_search();
        }
        break;
    default:
        require_once "articles/view.php";
        $module = new view($uri_array, $link_identifier);
        $module->generate();
        break;
}
//parse the navigational contents
include_once "parser/templ_parser.php";
$parser = new templ_parser("nav.html");
$nav = $parser->parse();
//main parse, include of content
$parser = new templ_parser("main.html");
$output = $parser->parse(array("navigation" => $nav, "content" => $module->output()));
//print to page
print $output;