--- db/prgsrc/drupal/modules/chgk_db/classes/DbField.class.php 2010/03/21 18:06:04 1.6 +++ db/prgsrc/drupal/modules/chgk_db/classes/DbField.class.php 2010/04/24 21:45:50 1.9 @@ -7,18 +7,27 @@ class DbField { protected $value; protected $number; protected $html; - public function __construct($field, $value, $number = false) { + protected $paragraphs; + protected $fb2; + protected $poems; + protected $codes; + protected $searchString; + protected $parent; + + 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; @@ -86,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; } @@ -98,7 +107,7 @@ class DbField { foreach ($lines as $l) { if (preg_match('/^[\s\|]/', $l)) { $this->paragraphs[] = $current; - $current = $l; + $current = $l ."\n"; } else { $current .= $l."\n" ; } @@ -160,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; } @@ -185,4 +213,11 @@ class DbField { $this->images = $matches[1]; return $this->images; } + + public function getSearchString() { + if (!$this->parent) { + return ''; + } + return $this->parent->getSearchString(); + } }