[ Index ] |
PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /************************************************************************************* 4 Copyright notice 5 6 (c) 2002-2012 Oliver Georgi <oliver@phpwcms.de> // All rights reserved. 7 8 This script is part of PHPWCMS. The PHPWCMS web content management system is 9 free software; you can redistribute it and/or modify it under the terms of 10 the GNU General Public License as published by the Free Software Foundation; 11 either version 2 of the License, or (at your option) any later version. 12 13 The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html 14 A copy is found in the textfile GPL.txt and important notices to the license 15 from the author is found in LICENSE.txt distributed with these scripts. 16 17 This script is distributed in the hope that it will be useful, but WITHOUT ANY 18 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 19 PARTICULAR PURPOSE. See the GNU General Public License for more details. 20 21 This copyright notice MUST APPEAR in all copies of the script! 22 *************************************************************************************/ 23 24 // neccessary frontend functions for search 25 26 function get_SearchForStructureID($search_at) { 27 28 $k = array(); 29 30 if(is_array($search_at) && count($search_at)) { 31 32 if(in_array(0, $search_at)) { 33 return $k; 34 } 35 36 $m = search_buildMenuPathStructure(); 37 $m = explode(LF, $m); 38 $m = array_unique($m); 39 $m = array_diff($m, array('')); 40 $k = $m; 41 $d = implode(LF, $m); 42 $c = 0; 43 foreach($m as $key => $value) { 44 preg_match_all('/'.trim($value).'/', $d, $match); 45 if(count($match[0]) > 1) { 46 unset($k[$key]); 47 } 48 $c++; 49 } 50 51 $_search_at_this = ''; 52 53 foreach($search_at as $_search_start_ID) { 54 55 foreach($k as $_search_path) { 56 57 $_search_path = ' '.$_search_path.' '; 58 $_this_pos = strpos($_search_path, ' '.$_search_start_ID.' '); 59 60 if($_this_pos) { 61 $_search_at_this .= ' '.trim(substr($_search_path, $_this_pos)); 62 } 63 64 } 65 } 66 67 if($_search_at_this) { 68 69 $k = explode(' ', trim($_search_at_this)); 70 $k = array_unique($k); 71 72 } else { 73 $k = array(); 74 } 75 76 77 } 78 79 return $k; 80 } 81 82 83 84 function search_buildMenuPathStructure($start_id=0, $counter=0, $pre = '') { 85 86 global $content; 87 88 $li = ''; 89 90 foreach($content['struct'] as $key => $value) { 91 92 if($key && $content['struct'][$key]['acat_struct'] == $start_id && empty($content['struct'][$key]['acat_nosearch'])) { 93 94 $g = $pre.$key.' ' ; 95 $li .= $g; 96 $li .= search_buildMenuPathStructure($key, $counter+1, LF.$g); 97 98 } 99 } 100 101 return $li . LF; 102 } 103 104 class search_News { 105 106 var $search_words = ''; 107 var $search_word_count = 0; 108 var $search_result_entry = 0; 109 var $search_results = array(); 110 var $search_highlight = false; 111 var $search_highlight_words = false; 112 var $search_wordlimit = 0; 113 var $search_target_url = ''; 114 var $now = 0; 115 var $search_category = array(); 116 var $search_language = array(); 117 var $search_andor = 'OR'; 118 var $ellipse_sign = '…'; 119 120 function search() { 121 122 $this->now = now(); 123 124 if(empty($this->search_words)) { 125 return NULL; 126 } 127 128 $cnt_ts_livedate = 'IF(UNIX_TIMESTAMP(pc.cnt_livedate) > 0, UNIX_TIMESTAMP(pc.cnt_livedate), pc.cnt_created)'; 129 $cnt_ts_killdate = 'IF(UNIX_TIMESTAMP(pc.cnt_killdate) > 0, UNIX_TIMESTAMP(pc.cnt_killdate), pc.cnt_created + 31536000)'; 130 131 $sql = 'SELECT pc.*, '; 132 $sql .= $cnt_ts_livedate . ' AS cnt_ts_livedate, '; 133 $sql .= $cnt_ts_killdate . ' AS cnt_ts_killdate '; 134 $sql .= 'FROM '.DB_PREPEND.'phpwcms_content pc '; 135 136 $sql_where = 'WHERE '; 137 $sql_where .= 'pc.cnt_status=1 AND '; 138 $sql_where .= "pc.cnt_module='news' AND "; 139 $sql_where .= $cnt_ts_livedate . ' < ' . $this->now . ' AND '; 140 $sql_where .= '(' . $cnt_ts_killdate . ' > ' . $this->now . ' OR cnt_archive_status = 1) '; 141 142 $sql_group = ''; 143 144 // choose by category 145 if(count($this->search_category)) { 146 147 if(empty($this->search_target_url)) { 148 $this->search_target_url = 'index.php' . returnGlobalGET_QueryString('htmlentities', array(), array('newsdetail')); 149 } else { 150 $this->search_target_url = html_specialchars($this->search_target_url); 151 } 152 153 $cat_sql = array(); 154 155 // and/or/not mode 156 switch($this->search_andor) { 157 158 case 'AND': $news_andor = ' AND '; 159 $news_compare = '='; 160 break; 161 162 case 'NOT': $news_andor = ' AND '; 163 $news_compare = '!='; 164 break; 165 166 default: //OR 167 $news_andor = ' OR '; 168 $news_compare = '='; 169 } 170 171 foreach($this->search_category as $value) { 172 173 $cat_sql[] = 'pcat.cat_name' . $news_compare . "'" . aporeplace($value) . "'"; 174 175 } 176 177 $sql .= "LEFT JOIN ".DB_PREPEND."phpwcms_categories pcat ON (pcat.cat_type='news' AND pcat.cat_pid=pc.cnt_id) "; 178 179 $sql_where .= 'AND (' . implode($news_andor, $cat_sql) . ') '; 180 181 $sql_group = 'GROUP BY pc.cnt_id '; 182 183 } 184 185 // language selection 186 if(count($this->search_language)) { 187 188 $sql_where .= "AND pc.cnt_lang IN ('". str_replace('#', "','", aporeplace( implode('#', $this->search_language) ) ) . "') "; 189 190 } 191 192 $sql .= $sql_where; 193 $sql .= $sql_group; 194 195 $sql = trim($sql); 196 197 $data = _dbQuery($sql); 198 199 200 foreach($data as $value) { 201 202 $s_result = array(); 203 204 $s_text = $value['cnt_text'] . ', ' . $value['cnt_teasertext'] . ', ' . $value['cnt_place'] . ', '; 205 $s_text .= $value['cnt_subtitle'] . ', ' . $value['cnt_editor'] . ', ' . $value['cnt_title']; 206 207 $value['cnt_object'] = @unserialize($value['cnt_object']); 208 209 if(isset($value['cnt_object']['cnt_category'])) { 210 211 $s_text .= ' ' . $value['cnt_object']['cnt_category']; 212 $s_text .= ' ' . $value['cnt_object']['cnt_image']['caption']; 213 $s_text .= ' ' . $value['cnt_object']['cnt_files']['caption']; 214 215 } 216 $s_text = preg_replace('/<script[^>]*>.*?<\/script>/is', '', $s_text); // strip all <script> Tags 217 $s_text = str_replace( array('~', '|', ':', 'http', '//', '_blank', ' ') , ' ', $s_text ); 218 $s_text = clean_replacement_tags($s_text, ''); 219 $s_text = remove_unsecure_rptags($s_text); 220 $s_text = cleanUpSpecialHtmlEntities($s_text); 221 222 preg_match_all('/'.$this->search_words.'/is', $s_text, $s_result ); 223 224 $s_count = count($s_result[0]); //set search_result to 0 225 226 if($s_count && SEARCH_TYPE_AND) { 227 $s_and_or = array(); 228 foreach($s_result[0] as $svalue) { 229 $s_and_or[strtolower($svalue)] = 1; 230 } 231 $s_and_or = count($s_and_or); 232 233 if($s_and_or != $this->search_word_count) { 234 $s_count = 0; 235 } 236 } 237 238 if($s_count) { 239 240 $id = $this->search_result_entry; 241 242 $s_title = html_specialchars($value['cnt_title']); 243 244 $this->search_results[$id]["id"] = $value['cnt_id']; 245 $this->search_results[$id]["cid"] = 0; 246 $this->search_results[$id]["rank"] = $s_count; 247 $this->search_results[$id]["title"] = $this->search_highlight ? highlightSearchResult($s_title, $this->search_highlight_words) : $s_title; 248 $this->search_results[$id]["date"] = $value['cnt_ts_livedate']; 249 $this->search_results[$id]["user"] = html_specialchars($value['cnt_editor']); 250 251 252 $value['detail_link'] = date('Ymd', $value['cnt_ts_livedate']) . '-' . $value['cnt_id'] . '_' ; //$crow['acontent_aid'] 253 $value['detail_link'] .= empty($value['cnt_alias']) ? $value['cnt_id'] : urlencode( $value['cnt_alias'] ); 254 255 $this->search_results[$id]['query'] = $this->search_target_url.'&newsdetail='.$value['detail_link']; 256 257 $s_text = trim(trim(str_replace(', ,', ',', $s_text)), ' ,'); 258 $s_text = getCleanSubString($s_text, $this->search_wordlimit, $this->ellipse_sign, 'word'); 259 $s_text = html_specialchars($s_text); 260 261 if($this->search_highlight) { 262 $s_text = highlightSearchResult($s_text, $this->search_highlight_words); 263 } 264 $this->search_results[$id]["text"] = $s_text; 265 266 $this->search_result_entry++; 267 268 } 269 } 270 } 271 } 272 273 274 function clean_search_text($string='') { 275 276 $string = clean_replacement_tags($string); 277 $string = remove_unsecure_rptags($string); 278 $string = str_replace(' ', ' ', $string); 279 $string = preg_replace('/\s+/i', ' ', $string); 280 $string = cleanUpSpecialHtmlEntities($string); 281 282 return $string; 283 } 284 285 286 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Jan 29 16:31:14 2012 | Cross-referenced by PHPXref 0.7.1 |