$fields) { if (!is_string($table)) { $table = ''; } if($fields instanceof Zend_Db_Expr) { $matchFields[] = $fields->__toString(); } else { $fields = (array) $fields; foreach ($fields as $field) { if($field instanceof Zend_Db_Expr) { $matchFields[] = $field->__toString(); } else { $matchFields[] = (($table) ? "`{$table}`." : '') . "`{$field}`"; } } } } $matchWord = array(); $filterString = stripslashes($filterString); foreach (self::getWords($filterString) as $searchLine) { foreach (explode(' ', $searchLine) as $word) { $matchWord[] = ((true === $everyWord) ? '+' : '') . addslashes(stripslashes($word)) . '*'; } } $sql = " MATCH (" . implode(', ', $matchFields) . ") AGAINST ('" . implode(' ', $matchWord) . "' IN BOOLEAN MODE)"; return $sql; } public static function match(Zend_Db_Select $select, array $filterFields, $filterString, $everyWord = false) { $sql = Qs_Db_Filter::matchSql($select, $filterFields, $filterString, $everyWord); $select->where($sql); return true; } public static function where(Zend_Db_Select $select, array $filterFields, $filterString, $equation = 'LIKE', $wordRule = 'OR', $fieldRule = 'OR') { if (empty($filterFields) || empty($filterString)) { return false; } $wordRule = strtolower($wordRule); $fieldRule = strtolower($fieldRule); $where = array(); $regexpSql = array(); foreach (self::getWords($filterString) as $searchLine) { foreach (explode(' ', $searchLine) as $word) { $regexpWord = $select->getAdapter()->quote($word); if (false !== stripos($equation, 'LIKE')) { //$word = str_replace(array('\\', '_', '%'), array('\\\\', '\_', '\%'), $word); $word = "%{$word}%"; } $whereFields = array(); $word = $select->getAdapter()->quote($word); foreach ($filterFields as $table => $fields) { if (!is_string($table)) { $table = ''; } if($fields instanceof Zend_Db_Expr) { $whereFields[] = $fields->__toString() . " {$equation} {$word}"; } else if (is_string($fields) && strpos($fields, '(') !== false && strpos($fields, ')') !== false) { $whereFields[] = "{$fields} {$equation} {$word}"; } else { $fields = (array) $fields; foreach ($fields as $field) { if($field instanceof Zend_Db_Expr) { $whereFields[] = $field->__toString() . " {$equation} {$word}"; } else if (is_string($field) && strpos($field, '(') !== false && strpos($field, ')') !== false) { $whereFields[] = "{$field} {$equation} {$word}"; } else { $whereFields[] = (($table) ? "`{$table}`." : '') . "`{$field}` {$equation} {$word}"; } } } } $where[] = '(' . implode((($fieldRule == 'and') ? ' AND ' : ' OR '), $whereFields) . ')'; $regexpSql[] = $regexpWord . " NOT REGEXP '&#?[a-z0-9]{2,8};'"; //$word quoted at 57 line } } $sql = implode((($wordRule == 'and') ? ' AND ' : ' OR '), $where); $select->where($sql); $select->where(implode(' AND ', $regexpSql)); return true; } }