function search()
 {
     $this->now = now();
     if (empty($this->search_words)) {
         return NULL;
     }
     $cnt_ts_livedate = 'IF(UNIX_TIMESTAMP(pc.cnt_livedate) > 0, UNIX_TIMESTAMP(pc.cnt_livedate), pc.cnt_created)';
     $cnt_ts_killdate = 'IF(UNIX_TIMESTAMP(pc.cnt_killdate) > 0, UNIX_TIMESTAMP(pc.cnt_killdate), pc.cnt_created + 31536000)';
     $sql = 'SELECT pc.*, ';
     $sql .= $cnt_ts_livedate . ' AS cnt_ts_livedate, ';
     $sql .= $cnt_ts_killdate . ' AS cnt_ts_killdate ';
     $sql .= 'FROM ' . DB_PREPEND . 'phpwcms_content pc ';
     $sql_where = 'WHERE ';
     $sql_where .= 'pc.cnt_status=1 AND ';
     $sql_where .= "pc.cnt_module='news' AND ";
     $sql_where .= $cnt_ts_livedate . ' < ' . $this->now . ' AND ';
     $sql_where .= '(' . $cnt_ts_killdate . ' > ' . $this->now . ' OR cnt_archive_status = 1) ';
     $sql_group = '';
     // choose by category
     if (count($this->search_category)) {
         $cat_sql = array();
         // and/or/not mode
         switch ($this->search_andor) {
             case 'AND':
                 $news_andor = ' AND ';
                 $news_compare = '=';
                 break;
             case 'NOT':
                 $news_andor = ' AND ';
                 $news_compare = '!=';
                 break;
             default:
                 //OR
                 $news_andor = ' OR ';
                 $news_compare = '=';
         }
         foreach ($this->search_category as $value) {
             $cat_sql[] = 'pcat.cat_name' . $news_compare . _dbEscape($value);
         }
         $sql .= "LEFT JOIN " . DB_PREPEND . "phpwcms_categories pcat ON (pcat.cat_type='news' AND pcat.cat_pid=pc.cnt_id) ";
         $sql_where .= 'AND (' . implode($news_andor, $cat_sql) . ') ';
         $sql_group = 'GROUP BY pc.cnt_id ';
     }
     // language selection
     if (count($this->search_language)) {
         $sql_where .= "AND pc.cnt_lang IN ('" . str_replace('#', "','", _dbEscape(implode('#', $this->search_language), false)) . "') ";
     }
     $sql .= $sql_where;
     $sql .= $sql_group;
     $sql = trim($sql);
     $data = _dbQuery($sql);
     $search_target_url_test = strtolower(substr($this->search_target_url, 0, 4));
     if ($search_target_url_test !== 'http' && $search_target_url_test !== '{sit') {
         // expected alias here or aid=123 or id=123
         if ($this->search_highlight) {
             $this->search_target_url = rel_url(array('newsdetail' => '___NEWSDETAIL__', 'highlight' => '___HIGHLIGHT__'), array('searchstart', 'searchwords'), $this->search_target_url);
         } else {
             $this->search_target_url = rel_url(array('newsdetail' => '___NEWSDETAIL__'), array('highlight', 'searchstart', 'searchwords'), $this->search_target_url);
         }
         $search_replace_newsdetail = true;
     } else {
         $search_replace_newsdetail = strpos($this->search_target_url, '___NEWSDETAIL__') !== false ? true : false;
         $this->search_target_url = html_specialchars($this->search_target_url);
     }
     if ($this->search_highlight_words && is_array($this->search_highlight_words)) {
         $s_highlight_words = rawurlencode(implode(' ', $this->search_highlight_words));
     } else {
         $s_highlight_words = '';
     }
     foreach ($data as $value) {
         $s_result = array();
         $s_text = $value['cnt_text'] . ', ' . $value['cnt_teasertext'] . ', ' . $value['cnt_place'] . ', ';
         $s_text .= $value['cnt_subtitle'] . ', ' . $value['cnt_title'];
         if ($this->search_username) {
             $s_text .= ', ' . $value['cnt_editor'];
         }
         $value['cnt_object'] = @unserialize($value['cnt_object']);
         if (!empty($value['cnt_object']['cnt_searchoff'])) {
             continue;
         }
         if (isset($value['cnt_object']['cnt_category'])) {
             if ($this->search_keyword) {
                 $s_text .= ' ' . $value['cnt_object']['cnt_category'];
             }
             if ($this->search_caption) {
                 $s_text .= ' ' . $value['cnt_object']['cnt_image']['caption'];
                 $s_text .= ' ' . $value['cnt_object']['cnt_files']['caption'];
             }
         }
         $s_text = preg_replace('/<script[^>]*>.*?<\\/script>/is', '', $s_text);
         // strip all <script> Tags
         $s_text = str_replace(array('~', '|', ':', 'http', '//', '_blank', '&nbsp;'), ' ', $s_text);
         $s_text = clean_search_text($s_text);
         preg_match_all('/' . $this->search_words . '/is', $s_text, $s_result);
         $s_count = count($s_result[0]);
         //set search_result to 0
         if ($s_count && SEARCH_TYPE_AND) {
             $s_and_or = array();
             foreach ($s_result[0] as $svalue) {
                 $s_and_or[strtolower($svalue)] = 1;
             }
             $s_and_or = count($s_and_or);
             if ($s_and_or != $this->search_word_count) {
                 $s_count = 0;
             }
         }
         if ($s_count) {
             $id = $this->search_result_entry;
             $this->search_results[$id]["id"] = $value['cnt_id'];
             $this->search_results[$id]["cid"] = 0;
             $this->search_results[$id]["rank"] = $s_count;
             if ($this->search_highlight) {
                 $this->search_results[$id]["title"] = highlightSearchResult(html($value['cnt_title']), $this->search_highlight_words);
                 $this->search_results[$id]["subtitle"] = highlightSearchResult(html($value['cnt_subtitle']), $this->search_highlight_words);
             } else {
                 $this->search_results[$id]["title"] = html($value['cnt_title']);
                 $this->search_results[$id]["subtitle"] = html($value['cnt_subtitle']);
             }
             $this->search_results[$id]["date"] = $value['cnt_ts_livedate'];
             $this->search_results[$id]["user"] = html($value['cnt_editor']);
             $value['detail_link'] = date('Ymd', $value['cnt_ts_livedate']) . '-' . $value['cnt_id'] . '_';
             //$crow['acontent_aid']
             $value['detail_link'] .= empty($value['cnt_alias']) ? $value['cnt_id'] : urlencode($value['cnt_alias']);
             if (strpos($this->search_target_url, '___NEWSDETAIL__') !== false) {
                 $this->search_results[$id]['link'] = str_replace(array('___NEWSDETAIL__', '___HIGHLIGHT__'), array($value['detail_link'], $s_highlight_words), $this->search_target_url);
             } else {
                 $this->search_results[$id]['link'] = $this->search_target_url . '&amp;newsdetail=' . $value['detail_link'];
                 if ($this->search_highlight) {
                     $this->search_results[$id]['link'] .= '&amp;highlight=' . $s_highlight_words;
                 }
             }
             $s_text = trim(trim(str_replace(', ,', ',', $s_text)), ' ,');
             $s_text = html(getCleanSubString($s_text, $this->search_wordlimit, $this->ellipse_sign, 'word'), false);
             if ($this->search_highlight) {
                 $s_text = highlightSearchResult($s_text, $this->search_highlight_words);
             }
             $this->search_results[$id]["text"] = $s_text;
             $this->search_results[$id]["image"] = false;
             if ($this->image_render && !empty($value['cnt_object']['cnt_image']['id'])) {
                 $value['cnt_object']['cnt_image'] = _dbGet('phpwcms_file', 'f_id AS `id`, f_hash AS `hash`, f_ext AS `ext`, f_name AS `name`', 'f_id=' . _dbEscape($value['cnt_object']['cnt_image']['id']) . ' AND f_trash=0 AND f_aktiv=1 AND f_public=1');
                 if (isset($value['cnt_object']['cnt_image'][0]['id'])) {
                     $this->search_results[$id]["image"] = $value['cnt_object']['cnt_image'][0];
                 }
             }
             $this->search_result_entry++;
         }
     }
 }
 // Search for {SHOW_CONTENT}
 if (strpos($s_text, '{SHOW_CONTENT') !== false) {
     $s_text = preg_replace_callback('/\\{SHOW_CONTENT:(.*?)\\}/', 'showSelectedContent', $s_text);
 }
 $s_text = preg_replace('/<script[^>]*>.*?<\\/script>/is', '', $s_text);
 $s_text = str_replace(array('~', '|', ':', 'http', '//', '_blank'), ' ', $s_text);
 $s_text .= ' --##-';
 if ($content['search']['search_keyword']) {
     $s_text .= $srow["article_keyword"] . ' ';
 }
 $s_text .= $s_title;
 if ($content['search']['search_username']) {
     $s_text .= ' ' . $s_user;
 }
 $s_text .= '-##--';
 $s_text = clean_search_text($s_text);
 $s_result = array();
 preg_match_all('/' . $s_search_words . '/is', $s_text, $s_result);
 //search string
 $s_text = preg_replace("/(<\\/?)(\\w+)([^>]*>)/i", '', $s_text);
 $s_count = count($s_result[0]);
 if ($s_count && SEARCH_TYPE_AND) {
     $s_and_or = array();
     foreach ($s_result[0] as $svalue) {
         $s_and_or[strtolower($svalue)] = 1;
     }
     $s_and_or = count($s_and_or);
     if ($s_and_or != $s_search_words_count) {
         $s_count = 0;
     }
 }
 function search()
 {
     if (!$this->search_word_count) {
         return NULL;
     }
     $shop_url = _getConfig('shop_pref_id_shop', '_shopPref');
     $shop_lang_support = _getConfig('shop_pref_felang') ? true : false;
     if (!is_intval($shop_url) && is_string($shop_url)) {
         $shop_url = trim($shop_url);
     } elseif (is_intval($shop_url) && intval($shop_url)) {
         $shop_url = 'aid=' . intval($shop_url);
     } else {
         $shop_url = $GLOBALS['aktion'][1] ? 'aid=' . $GLOBALS['aktion'][1] : 'id=' . $GLOBALS['aktion'][0];
     }
     if ($this->search_highlight_words && is_array($this->search_highlight_words)) {
         $s_highlight_words = implode(' ', $this->search_highlight_words);
     } else {
         $s_highlight_words = '';
         $this->search_highlight = false;
     }
     $sql = 'SELECT shopprod_id, shopprod_category, shopprod_ordernumber, ';
     $sql .= 'shopprod_name1, shopprod_var, ';
     $sql .= 'UNIX_TIMESTAMP(shopprod_changedate) AS shopprod_date, ';
     $sql .= 'CONCAT(';
     $sql .= "\tshopprod_description0,' ',";
     $sql .= "\tshopprod_description1,' ',";
     $sql .= "\tshopprod_description2,' ',";
     $sql .= "\tshopprod_description3,' ',";
     $sql .= "\tshopprod_color,' ',";
     $sql .= "\tshopprod_size,' ',";
     $sql .= "\tshopprod_ordernumber,' ',";
     $sql .= "\tshopprod_model,' ',";
     $sql .= "\tshopprod_name1,' ',";
     $sql .= "\tshopprod_name2,' '";
     $sql .= ') AS shopprod_search ';
     $sql .= 'FROM ' . DB_PREPEND . 'phpwcms_shop_products WHERE shopprod_status=1';
     if ($shop_lang_support && !empty($GLOBALS['phpwcms']['default_lang'])) {
         $sql .= " AND (shopprod_lang='' OR shopprod_lang=" . _dbEscape($GLOBALS['phpwcms']['default_lang']) . ')';
     }
     $data = _dbQuery($sql);
     foreach ($data as $value) {
         $s_result = array();
         $s_text = $value['shopprod_search'];
         $s_text = str_replace(array('~', '|', ':', 'http', '//', '_blank', '&nbsp;'), ' ', $s_text);
         $s_text = clean_search_text($s_text);
         preg_match_all('/' . $this->search_words . '/is', $s_text, $s_result);
         $s_count = count($s_result[0]);
         if ($s_count && SEARCH_TYPE_AND) {
             $s_and_or = array();
             foreach ($s_result[0] as $svalue) {
                 $s_and_or[strtolower($svalue)] = 1;
             }
             $s_and_or = count($s_and_or);
             if ($s_and_or != $this->search_word_count) {
                 $s_count = 0;
             }
         }
         if ($s_count) {
             $id = $this->search_result_entry;
             $s_title = $value['shopprod_ordernumber'] ? trim($value['shopprod_ordernumber']) . ': ' : '';
             $s_title .= $value['shopprod_name1'];
             $s_title = html($s_title);
             $s_text = trim($s_text);
             if ($this->search_wordlimit) {
                 $s_text = getCleanSubString($s_text, $this->search_wordlimit, $this->ellipse_sign, 'word');
             }
             $s_text = html($s_text);
             $this->search_results[$id]["id"] = $value['shopprod_id'];
             $this->search_results[$id]["cid"] = 0;
             $this->search_results[$id]["rank"] = $s_count;
             $this->search_results[$id]["date"] = $value['shopprod_date'];
             $this->search_results[$id]["user"] = '';
             $this->search_results[$id]["subtitle"] = '';
             $this->search_results[$id]['query'] = $shop_url;
             //.'&amp;shop_cat='.$value['shopprod_category'].'&amp;shop_detail='.$value['shopprod_id'];
             $this->search_results[$id]['image'] = false;
             if ($this->image_render) {
                 $value['shopprod_var'] = unserialize($value['shopprod_var']);
                 if (isset($value['shopprod_var']['images'][0]['f_hash'])) {
                     $this->search_results[$id]['image'] = array('id' => $value['shopprod_var']['images'][0]['f_id'], 'hash' => $value['shopprod_var']['images'][0]['f_hash'], 'ext' => $value['shopprod_var']['images'][0]['f_ext'], 'name' => $value['shopprod_var']['images'][0]['f_name']);
                 }
             }
             if ($this->search_highlight) {
                 $this->search_results[$id]["title"] = highlightSearchResult($s_title, $this->search_highlight_words);
                 $this->search_results[$id]["text"] = highlightSearchResult($s_text, $this->search_highlight_words);
                 $this->search_results[$id]['link'] = rel_url(array('shop_cat' => $value['shopprod_category'], 'shop_detail' => $value['shopprod_id'], 'highlight' => $s_highlight_words), array('searchstart', 'searchwords'), $shop_url);
             } else {
                 $this->search_results[$id]["title"] = $s_title;
                 $this->search_results[$id]["text"] = $s_text;
                 $this->search_results[$id]['link'] = rel_url(array('shop_cat' => $value['shopprod_category'], 'shop_detail' => $value['shopprod_id']), array('highlight', 'searchstart', 'searchwords'), $shop_url);
             }
             $this->search_result_entry++;
         }
     }
 }