[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /* 3 * Created on 7/05/2006 4 */ 5 6 class Search extends TPage 7 { 8 public function onLoad($param) 9 { 10 if(!$this->IsPostBack && strlen($text = $this->search->getText()) > 0) 11 { 12 $quickstart = $this->getApplication()->getModule("quickstart_search"); 13 $hits_1 = $quickstart->find($text); 14 $this->quickstart_results->setDataSource($hits_1); 15 $this->quickstart_results->dataBind(); 16 17 $this->emptyResult->setVisible(!count($hits_1)); 18 } 19 } 20 21 public function highlightSearch($text) 22 { 23 $words = str_word_count($text, 1); 24 $keys = str_word_count(strtolower($this->search->getText()),1); 25 $where = 0; 26 $t = count($words); 27 for($i = 0; $i<$t; $i++) 28 { 29 if($this->containsKeys(strtolower($words[$i]), $keys)) 30 { 31 $words[$i] = '<span class="searchterm">'.$words[$i].'</span>'; 32 $where = $i; 33 break; 34 } 35 } 36 37 $min = $where - 15 < 0 ? 0 : $where - 15; 38 $max = $where + 15 > $t ? $t : $where + 15; 39 $subtext = array_splice($words, $min, $max-$min); 40 $prefix = $min == 0 ? '' : '...'; 41 $suffix = $max == $t ? '' : '...'; 42 return $prefix.implode(' ', $subtext).$suffix; 43 } 44 45 protected function containsKeys($word, $keys) 46 { 47 foreach($keys as $key) 48 { 49 if(is_int(strpos($word, $key))) 50 return true; 51 } 52 return false; 53 } 54 } 55 56 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |