[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

/include/inc_front/content/cnt_functions/ -> cnt13.func.inc.php (source)

   1  <?php
   2  
   3  /*************************************************************************************
   4     Copyright notice
   5     
   6     (c) 2002-2009 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_result_entry    = 0;
 108      var $search_results            = array();
 109      var $search_highlight        = false;
 110      var $search_highlight_words    = false;
 111      var $search_wordlimit        = 0;
 112      var $search_target_url        = '';
 113      var $now                    = 0;
 114      var $search_category        = array();
 115      var $search_language        = array();
 116      var $search_andor            = 'OR';
 117      var $ellipse_sign            = '&#8230;';
 118  
 119  	function search() {
 120      
 121          $this->now = now();
 122      
 123          if(empty($this->search_words)) {
 124              return NULL;
 125          }
 126          
 127          $cnt_ts_livedate = 'IF(UNIX_TIMESTAMP(pc.cnt_livedate) > 0, UNIX_TIMESTAMP(pc.cnt_livedate), pc.cnt_created)';
 128          $cnt_ts_killdate = 'IF(UNIX_TIMESTAMP(pc.cnt_killdate) > 0, UNIX_TIMESTAMP(pc.cnt_killdate), pc.cnt_created + 31536000)';
 129  
 130          $sql        = 'SELECT pc.*, ';
 131          $sql       .= $cnt_ts_livedate . ' AS cnt_ts_livedate, ';
 132          $sql       .= $cnt_ts_killdate . ' AS cnt_ts_killdate ';
 133          $sql       .= 'FROM '.DB_PREPEND.'phpwcms_content pc ';
 134          
 135          $sql_where  = 'WHERE ';
 136          $sql_where .= 'pc.cnt_status=1 AND ';
 137          $sql_where .= "pc.cnt_module='news' AND ";    
 138          $sql_where .= $cnt_ts_livedate . ' < ' . $this->now . ' AND ';
 139          $sql_where .= '(' . $cnt_ts_killdate . ' > ' . $this->now . ' OR cnt_archive_status = 1) ';
 140          
 141          $sql_group  = '';
 142  
 143          // choose by category
 144          if(count($this->search_category)) {
 145          
 146              if(empty($this->search_target_url)) {
 147                  $this->search_target_url = 'index.php' . returnGlobalGET_QueryString('htmlentities', array(), array('newsdetail'));
 148              } else {    
 149                  $this->search_target_url = html_specialchars($this->search_target_url);
 150              }
 151              
 152              $cat_sql = array();
 153          
 154              // and/or/not mode
 155              switch($this->search_andor) {
 156              
 157                  case 'AND': $news_andor        = ' AND ';
 158                              $news_compare    = '=';
 159                              break;
 160                              
 161                  case 'NOT':    $news_andor        = ' AND ';
 162                              $news_compare    = '!=';
 163                              break;
 164                              
 165                  default:    //OR
 166                              $news_andor        = ' OR ';
 167                              $news_compare    = '=';
 168              }
 169              
 170              foreach($this->search_category as $value) {
 171                  
 172                  $cat_sql[] = 'pcat.cat_name' . $news_compare . "'" . aporeplace($value) . "'";
 173                  
 174              }
 175              
 176              $sql       .= "LEFT JOIN ".DB_PREPEND."phpwcms_categories pcat ON (pcat.cat_type='news' AND pcat.cat_pid=pc.cnt_id) ";
 177              
 178              $sql_where .= 'AND (' . implode($news_andor, $cat_sql) . ') ';
 179              
 180              $sql_group  = 'GROUP BY pc.cnt_id ';
 181              
 182          }
 183          
 184          // language selection
 185          if(count($this->search_language)) {
 186          
 187              $sql_where .= "AND pc.cnt_lang IN ('". str_replace('#', "','", aporeplace( implode('#', $this->search_language) ) ) . "') ";
 188          
 189          }
 190          
 191          $sql .= $sql_where;
 192          $sql .= $sql_group;
 193          
 194          $sql  = trim($sql);
 195  
 196          $data = _dbQuery($sql);
 197          
 198          
 199          foreach($data as $value) {
 200          
 201              $s_result = array();
 202                          
 203              $s_text  = $value['cnt_text'] . ', ' . $value['cnt_teasertext'] . ', ' . $value['cnt_place'] . ', ';
 204              $s_text .= $value['cnt_subtitle'] . ', ' . $value['cnt_editor'] . ', ' . $value['cnt_title'];
 205              
 206              $value['cnt_object'] = @unserialize($value['cnt_object']);
 207              
 208              if(isset($value['cnt_object']['cnt_category'])) {
 209              
 210                  $s_text .= ' ' . $value['cnt_object']['cnt_category'];
 211                  $s_text .= ' ' . $value['cnt_object']['cnt_image']['caption'];
 212                  $s_text .= ' ' . $value['cnt_object']['cnt_files']['caption'];
 213              
 214              }
 215              $s_text  = preg_replace('/<script[^>]*>.*?<\/script>/is', '', $s_text); // strip all <script> Tags
 216              $s_text  = str_replace( array('~', '|', ':', 'http', '//', '_blank', '&nbsp;') , ' ', $s_text );
 217              $s_text  = clean_replacement_tags($s_text, '');
 218              $s_text  = remove_unsecure_rptags($s_text);
 219              $s_text  = cleanUpSpecialHtmlEntities($s_text);
 220              
 221              preg_match_all('/'.$this->search_words.'/is', $s_text, $s_result );
 222  
 223              $s_count    = 0; //set search_result to 0
 224              foreach($s_result as $svalue) {
 225                  $s_count += count($svalue);
 226              }
 227              
 228              if($s_count) {
 229              
 230                  $id = $this->search_result_entry;
 231                  
 232                  $s_title  = html_specialchars($value['cnt_title']);
 233  
 234                  $this->search_results[$id]["id"]    = $value['cnt_id'];
 235                  $this->search_results[$id]["cid"]    = 0;
 236                  $this->search_results[$id]["rank"]    = $s_count;
 237                  $this->search_results[$id]["title"]    = $this->search_highlight ? highlightSearchResult($s_title, $this->search_highlight_words) : $s_title;
 238                  $this->search_results[$id]["date"]    = $value['cnt_ts_livedate'];
 239                  $this->search_results[$id]["user"]    = html_specialchars($value['cnt_editor']);
 240                  
 241                  
 242                  $value['detail_link']    = date('Ymd', $value['cnt_ts_livedate']) . '-' . $value['cnt_id'] . '_' ; //$crow['acontent_aid']
 243                  $value['detail_link']  .= empty($value['cnt_alias']) ? $value['cnt_id'] : urlencode( $value['cnt_alias'] );
 244                  
 245                  $this->search_results[$id]['query']    = $this->search_target_url.'&amp;newsdetail='.$value['detail_link'];
 246                  
 247                  $s_text   = trim(trim(str_replace(', ,', ',', $s_text)), ' ,');
 248                  $s_text   = getCleanSubString($s_text, $this->search_wordlimit, $this->ellipse_sign, 'word');
 249                  $s_text   = html_specialchars($s_text);
 250                  
 251                  if($this->search_highlight) {
 252                      $s_text = highlightSearchResult($s_text, $this->search_highlight_words);
 253                  }
 254                  $this->search_results[$id]["text"]    = $s_text;
 255                  
 256                  $this->search_result_entry++;
 257              
 258              }    
 259          }
 260      }
 261  }
 262  
 263  
 264  function clean_search_text($string='') {
 265  
 266      $string = clean_replacement_tags($string);
 267      $string = remove_unsecure_rptags($string);
 268      $string = str_replace('&nbsp;', ' ', $string);
 269      $string = preg_replace('/\s+/i', ' ', $string);
 270      $string = cleanUpSpecialHtmlEntities($string);
 271  
 272      return $string;
 273  }
 274  
 275  
 276  ?>


Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7