Beispiel #1
0
 public function search($text, $page = 1, $num = 10, $format = true)
 {
     global $scdb;
     $this->search->page = (int) $page;
     $this->search->num = (int) $num;
     $this->search->start = (int) ($page - 1) * $num;
     $s = strtr($text, array("%" => "%"));
     $s = safe_text(strip_tags($s));
     $this->search->term = $s;
     $s = strtolower($s);
     $items = $scdb->get_results("\n\t\t\t\tSELECT transcript as text, PID, title FROM `{$scdb->comics}` WHERE `transcript` LIKE '%" . $s . "%'\n\t\t\t\tUNION SELECT title as text, PID, title FROM `{$scdb->comics}` WHERE `title` LIKE '%" . $s . "%'\n\t\t\t\tUNION SELECT info as text, PID, title FROM `{$scdb->comics}` WHERE `info` LIKE '%" . $s . "%'\n\t\t\t\t");
     $this->search->num_results = $scdb->num_rows;
     if ($scdb->num_rows == 0) {
         return false;
     }
     $results = array();
     $i = 0;
     $max = 0;
     foreach ($items as $item) {
         $n = substr_count(strtolower(strip_tags($item->text)), $s);
         $results[$i] = $item;
         $results[$i]->num = $n;
         $results[$i]->text = str_replace(array("\n", "\t", "\r"), ' ', $item->text);
         if ($n > $max) {
             $max = $n;
         }
         ++$i;
     }
     // an attempt at ordering by relevance
     function compare($x, $y)
     {
         $x = $x->num;
         $y = $y->num;
         if ($x == $y) {
             return 0;
         } elseif ($x > $y) {
             return -1;
         } else {
             return 1;
         }
     }
     usort($results, 'compare');
     $count = count($results);
     if ($count > $num) {
         $results = array_slice($results, $this->search->page * $num - 1, $num, true);
     }
     if ($format === true) {
         $i = 0;
         foreach ($results as $result) {
             $small = smalltext($this->search->term, $result->text);
             $results[$i]->text = highlight_text($this->search->term, $small);
             ++$i;
         }
     }
     $this->search->results = $results;
     return $results;
 }
Beispiel #2
0
<div class="post">

  	<div class="title"><h5>Search Results For &quot;<?php 
echo $comic->search->term;
?>
&quot;</h5></div>

	<div class="blog">
	
	<div class="search-results">

<?php 
if ($comic->search->num_results > 0) {
    $i = $comic->search->start;
    foreach ($comic->search->results as $result) {
        $smalltext = smalltext($comic->search->term, $result->text);
        ?>
		
		<div>
			<a href="<?php 
        echo $comic->get_permalink($result->PID);
        ?>
">
				<?php 
        echo ++$i;
        ?>
. <?php 
        echo $result->title;
        ?>
				<div><img src="<?php 
        echo $comic->get_image_by_permalink($result->PID);