--- db/prgsrc/drupal/modules/chgk_db/classes/DbField.class.php 2010/04/24 18:04:15 1.8 +++ db/prgsrc/drupal/modules/chgk_db/classes/DbField.class.php 2010/04/24 21:45:50 1.9 @@ -11,19 +11,23 @@ class DbField { protected $fb2; protected $poems; protected $codes; + protected $searchString; + protected $parent; - public function __construct($field, $value, $number = false) { + public function __construct($field, $value, $number = false, $parent = null) { $this->field = $field; $this->value = $value; $this->number = $number; - $this->getHtml(); + $this->parent = $parent; } public function getHtml() { + if ($this->html) { return $this->html; - } + } + $this->html = $this->value; $this->formatHtml(); return $this->html; @@ -91,7 +95,7 @@ class DbField { } $this->fb2 = $result; - $this->fb2 = preg_replace('/ -+(\s+)/',' —$1', $this->fb2); +// $this->fb2 = preg_replace('/ -+(\s+)/',' —$1', $this->fb2); $this->fb2 = preg_replace('/\(pic: ([^\)]*)\)/','', $this->fb2); return $this->fb2; } @@ -165,9 +169,28 @@ class DbField { $this->html = preg_replace('/\s+\–/m',' \–', $this->html); } $this->html = preg_replace('/\(pic: ([^\)]*)\)/','

', $this->html); - + + if ($this->getSearchString()) { + $this->highLight(); + } } + protected function highLight() { + $sstr = $this->getSearchString(); + setlocale(LC_ALL, 'ru_RU.utf8'); + preg_match_all('/[\wа-я]{4,}\*?/iu', $sstr, $matchs); + $terms= $matchs[0]; + foreach ($terms as $term) { + if ( preg_match('/\*$/', $term) ) { + $letters=preg_replace('/\*/', '', $term); + $this->html = preg_replace("/{$letters}[\wа-я]*/iu", + '$0', $this->html); + } else { + $this->html = str_replace($term, ''.$term."", $this->html); + } + } + } + public function getName() { return $this->field; } @@ -190,4 +213,11 @@ class DbField { $this->images = $matches[1]; return $this->images; } + + public function getSearchString() { + if (!$this->parent) { + return ''; + } + return $this->parent->getSearchString(); + } }