function _buildQuery() { $q = new DBQuery(); if ($this->table_alias) { $q->addTable($this->table, $this->table_alias); } else { $q->addTable($this->table); } $q->addQuery($this->table_key); if (isset($this->table_key2)) { $q->addQuery($this->table_key2); } //--MSy-- foreach ($this->table_joins as $join) { $q->addJoin($join['table'], $join['alias'], $join['join']); } foreach ($this->display_fields as $fld) { $q->addQuery($fld); } $q->addOrder($this->table_orderby); if ($this->table_extra) { $q->addWhere($this->table_extra); } $sql = ''; foreach (array_keys($this->keywords) as $keyword) { $sql .= '('; foreach ($this->search_fields as $field) { //OR treatment to each keyword // Search for semi-colons, commas or spaces and allow any to be separators $or_keywords = preg_split('/[\\s,;]+/', $keyword); foreach ($or_keywords as $or_keyword) { if ($this->search_options['ignore_specchar'] == "on") { $tmppattern = recode2regexp_utf8($or_keyword); if ($this->search_options['ignore_case'] == "on") { $sql .= " {$field} REGEXP '{$tmppattern}' or "; } else { $sql .= " {$field} REGEXP BINARY '{$tmppattern}' or "; } } else { if ($this->search_options['ignore_case'] == "on") { $sql .= " {$field} LIKE '%{$or_keyword}%' or "; } else { $sql .= " {$field} LIKE BINARY '%{$or_keyword}%' or "; } } } } // foreach $field $sql = substr($sql, 0, -4); if ($this->search_options['all_words'] == "on") { $sql .= ') and '; } else { $sql .= ') or '; } } // foreach $keyword //--MSy-- $sql = substr($sql, 0, -4); if ($sql) { $q->addWhere($sql); return $q->prepare(true); } else { return '/* */'; } }
function highlight($text, $keyval) { global $ssearch; $txt = $text; $hicolor = array('#FFFF66', '#ADD8E6', '#90EE8A', '#FF99FF', '#FFA500', '#ADFF2F', '#00FFFF', '#FF69B4'); $keys = array(); $keys = !is_array($keyval) ? array($keyval) : $keyval; foreach ($keys as $key_idx => $key) { if (mb_strlen($key) > 0) { $key = stripslashes($key); $metacharacters = array('\\', '(', ')', '$', '[', '*', '+', '|', '.', '^', '?'); $metareplacement = array('\\\\', '\\(', '\\)', '\\$', '\\[', '\\*', '\\+', '\\|', '\\.', '\\^', '\\?'); $key = mb_str_replace($metacharacters, $metareplacement, $key); if (isset($ssearch['ignore_specchar']) && $ssearch['ignore_specchar'] == 'on') { if ($ssearch['ignore_case'] == 'on') { $txt = preg_replace('/' . recode2regexp_utf8($key) . '/i', '<span style="background:' . $hicolor[$key_idx] . '" >\\0</span>', $txt); } else { $txt = preg_replace('/' . recode2regexp_utf8($key) . '/', '<span style="background:' . $hicolor[$key_idx] . '" >\\0</span>', $txt); } } elseif (!isset($ssearch['ignore_specchar']) || $ssearch['ignore_specchar'] == '') { if ($ssearch['ignore_case'] == 'on') { $txt = preg_replace('/' . $key . '/i', '<span style="background:' . $hicolor[$key_idx] . '" >\\0</span>', $txt); } else { $txt = preg_replace('/' . $key . '/', '<span style="background:' . $hicolor[$key_idx] . '" >\\0</span>', $txt); } } else { $txt = preg_replace('/' . $key . '/i', '<span style="background:' . $hicolor[$key_idx] . '" >\\0</span>', $txt); } } } return $txt; }
function _searchResults() { global $AppUI, $locale_char_set; $q = new DBQuery(); $dPObj = new CDpObject($this->table, $this->table_key); $q->addTable($this->table, $this->table_alias); foreach ($this->table_joins as $join) { $q->addJoin($join['table'], $join['alias'], $join['join']); } $q->addQuery($this->table_key); if (isset($this->table_key2)) { $q->addQuery($this->table_key2); } foreach ($this->display_fields as $fld) { $q->addQuery($fld); } $q->addOrder($this->table_orderby); $dPObj->setAllowedSQL($AppUI->user_id, $q, null, null, $this->table_module); if ($this->table_extra) { $q->addWhere($this->table_extra); } $keys = ''; $keys2 = ''; foreach (array_keys($this->keywords) as $keyword) { if ($keys2) { $keys .= $this->search_options['all_words'] == 'on' ? ' AND ' : ' OR '; $keys2 = ''; } foreach ($this->search_fields as $field) { // OR treatment to each keyword // Search for semi-colons, commas or spaces and allow any to be separators $or_keywords = preg_split('/[\\s,;]+/', $keyword); foreach ($or_keywords as $or_keyword) { $search_pattern = $this->search_options['ignore_specchar'] == 'on' ? recode2regexp_utf8($or_keyword) : '(' . $or_keyword . ')'; $keys2 .= $keys2 ? ' OR ' : ''; $keys2 .= '(' . $field . ' REGEXP ' . ($this->search_options['ignore_case'] == 'on' ? '' : ' BINARY ') . "'.*" . $search_pattern . ".*'" . ($this->search_options['ignore_specchar'] == 'on' ? ' COLLATE utf8_general_ci' : '') . ')'; } } $keys .= $keys2 ? '(' . $keys2 . ')' : ''; } if ($keys) { $q->addWhere($keys); } $results = $q->loadList(); return $results; }
public function _buildQuery() { $q = new w2p_Database_Query(); if ($this->table_alias) { $q->addTable($this->table, $this->table_alias); } else { $q->addTable($this->table); } $q->addQuery('DISTINCT(' . $this->table_key . ')'); if (isset($this->table_key2)) { $q->addQuery($this->table_key2); } //--MSy-- foreach ($this->table_joins as $join) { $q->addJoin($join['table'], $join['alias'], $join['join']); } foreach ($this->display_fields as $fld) { $q->addQuery($fld); } $q->addOrder($this->table_orderby); if ($this->table_groupby) { $q->addGroup($this->table_groupby); } if ($this->table_extra) { $q->addWhere($this->table_extra); } $ignore = w2PgetSysVal('FileIndexIgnoreWords'); $ignore = explode(',', $ignore['FileIndexIgnoreWords']); $this->keywords = array_diff(array_keys($this->keywords), $ignore); $sql = ''; foreach ($this->keywords as $keyword) { $sql .= '('; foreach ($this->search_fields as $field) { //OR treatment to each keyword // Search for semi-colons, commas or spaces and allow any to be separators $or_keywords = preg_split('/[\\s,;]+/', $keyword); foreach ($or_keywords as $or_keyword) { if ($this->search_options['ignore_specchar'] == 'on') { $tmppattern = recode2regexp_utf8($or_keyword); if ($this->search_options['ignore_case'] == 'on') { $sql .= ' ' . $field . ' REGEXP \'' . $tmppattern . '\' or '; } else { $sql .= ' ' . $field . ' REGEXP BINARY \'' . $tmppattern . '\' or '; } } else { if ($this->search_options['ignore_case'] == 'on') { $sql .= ' ' . $field . ' LIKE "%' . $or_keyword . '%" or '; } else { $sql .= ' ' . $field . ' LIKE BINARY "%' . $or_keyword . '%" or '; } } } } // foreach $field $sql = substr($sql, 0, -4); if ($this->search_options['all_words'] == 'on') { $sql .= ') and '; } else { $sql .= ') or '; } } // foreach $keyword //--MSy-- $sql = substr($sql, 0, -4); if ($sql) { $q->addWhere($sql); return $q; } else { return null; } }
function highlight($text, $keyval) { global $ssearch; $txt = $text; $keys = !is_array($keyval) ? array($keyval) : $keyval; foreach ($keys as $key_idx => $key) { if (mb_strlen($key) > 0) { $key = stripslashes($key); $metacharacters = array('\\', '(', ')', '$', '[', '*', '+', '|', '.', '^', '?'); $metareplacement = array('\\\\', '\\(', '\\)', '\\$', '\\[', '\\*', '\\+', '\\|', '\\.', '\\^', '\\?'); $key = mb_str_replace($metacharacters, $metareplacement, $key); if (isset($ssearch['ignore_specchar']) && $ssearch['ignore_specchar'] == 'on') { if ($ssearch['ignore_case'] == 'on') { $txt = preg_replace('/' . recode2regexp_utf8($key) . '/i', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt); } else { $txt = preg_replace('/' . recode2regexp_utf8($key) . '/', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt); } } elseif (!isset($ssearch['ignore_specchar']) || $ssearch['ignore_specchar'] == '') { if ($ssearch['ignore_case'] == 'on') { $txt = preg_replace('/' . $key . '/i', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt); } else { $txt = preg_replace('/' . $key . '/', '<span class="highlight' . $key_idx . '" >\\0</span>', $txt); } } else { $txt = preg_replace('/' . $key . '/i', '<span class="highlight:' . $key_idx . '" >\\0</span>', $txt); } } } return $txt; }