[ Index ]

PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12)

title

Body

[close]

/include/inc_module/mod_shop/inc/ -> frontend.search.inc.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2012 Oliver Georgi <oliver@phpwcms.de> // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // Module/Plug-in Shop & Products search class
  24  class ModuleShopSearch {
  25  
  26      var $search_words            = array();
  27      var $search_word_count        = 0;
  28      var $search_result_entry    = 0;
  29      var $search_results            = array();
  30      var $search_highlight        = false;
  31      var $search_highlight_words    = false;
  32      var $search_wordlimit        = 0;
  33      var $ellipse_sign            = '&#8230;';
  34  
  35  	function search() {
  36      
  37          if(!$this->search_word_count) {
  38              return NULL;
  39          }
  40          
  41          $shop_url            = _getConfig( 'shop_pref_id_shop', '_shopPref' );
  42          $shop_lang_support    = _getConfig( 'shop_pref_felang' ) ? true : false;
  43          
  44          if(!is_numeric($shop_url) && is_string($shop_url)) {
  45              $shop_url    = trim($shop_url);
  46          } elseif(is_numeric($shop_url) && intval($shop_url)) {
  47              $shop_url    = 'aid='.intval($shop_url);
  48          } else {
  49              $shop_url    = $GLOBALS['aktion'][1] ? 'aid='.$GLOBALS['aktion'][1] : 'id='.$GLOBALS['aktion'][0];
  50          }
  51      
  52          $sql  = 'SELECT shopprod_id, shopprod_category, shopprod_ordernumber, ';
  53          $sql .= 'shopprod_name1, ';
  54          $sql .= 'UNIX_TIMESTAMP(shopprod_changedate) AS shopprod_date, ';
  55          $sql .= 'CONCAT(';
  56          $sql .= "    shopprod_description0,' ',";
  57          $sql .= "    shopprod_description1,' ',";
  58          $sql .= "    shopprod_description2,' ',";
  59          $sql .= "    shopprod_description3,' ',";
  60          $sql .= "    shopprod_color,' ',";
  61          $sql .= "    shopprod_size,' ',";
  62          $sql .= "    shopprod_ordernumber,' ',";
  63          $sql .= "    shopprod_model,' ',";
  64          $sql .= "    shopprod_name1,' ',";
  65          $sql .= "    shopprod_name2,' '";
  66          $sql .= ') AS shopprod_search ';
  67          $sql .= 'FROM '.DB_PREPEND.'phpwcms_shop_products WHERE shopprod_status=1';
  68          if($shop_lang_support && !empty($GLOBALS['phpwcms']['default_lang'])) {
  69              $sql .= " AND (shopprod_lang='' OR shopprod_lang="._dbEscape($GLOBALS['phpwcms']['default_lang']).')';
  70          }
  71          $data = _dbQuery($sql);
  72          
  73          foreach($data as $value) {
  74          
  75              $s_result    = array();
  76          
  77              $s_text        = $value['shopprod_search'];
  78              $s_text        = str_replace( array('~', '|', ':', 'http', '//', '_blank', '&nbsp;') , ' ', $s_text );
  79              $s_text        = clean_replacement_tags($s_text, '');
  80              $s_text        = remove_unsecure_rptags($s_text);
  81              $s_text        = cleanUpSpecialHtmlEntities($s_text);
  82              
  83              preg_match_all('/'.$this->search_words.'/is', $s_text, $s_result );
  84  
  85              $s_count    = count($s_result[0]);
  86              
  87              if($s_count && SEARCH_TYPE_AND) {
  88                  $s_and_or = array();
  89                  foreach($s_result[0] as $svalue) {
  90                      $s_and_or[strtolower($svalue)] = 1;
  91                  }
  92                  $s_and_or = count($s_and_or);
  93                  
  94                  if($s_and_or != $this->search_word_count) {
  95                      $s_count = 0;
  96                  }
  97              }
  98              
  99              if($s_count) {
 100  
 101                  $id = $this->search_result_entry;
 102                  
 103                  $s_title  = $value['shopprod_ordernumber'] ? trim($value['shopprod_ordernumber']).': ' : '';
 104                  $s_title .= $value['shopprod_name1'];
 105                  $s_title  = html_specialchars($s_title);
 106  
 107                  $s_text   = trim($s_text);
 108                  $s_text   = getCleanSubString($s_text, $this->search_wordlimit, $this->ellipse_sign, 'word');
 109                  $s_text   = html_specialchars($s_text);
 110                  
 111                  $this->search_results[$id]["id"]    = $value['shopprod_id'];
 112                  $this->search_results[$id]["cid"]    = 0;
 113                  $this->search_results[$id]["rank"]    = $s_count;
 114                  $this->search_results[$id]["title"]    = $this->search_highlight ? highlightSearchResult($s_title, $this->search_highlight_words) : $s_title;
 115                  $this->search_results[$id]["date"]    = $value['shopprod_date'];
 116                  $this->search_results[$id]["user"]    = '';
 117                  $this->search_results[$id]['query']    = $shop_url.'&amp;shop_cat='.$value['shopprod_category'].'&amp;shop_detail='.$value['shopprod_id'];
 118                  
 119                  if($this->search_highlight) {
 120                      $s_text = highlightSearchResult($s_text, $this->search_highlight_words);
 121                  }
 122                  $this->search_results[$id]["text"]    = $s_text;
 123                  
 124                  $this->search_result_entry++;
 125              }
 126          }
 127      }
 128  
 129  }
 130  
 131  
 132  ?>


Generated: Sun Jan 29 16:31:14 2012 Cross-referenced by PHPXref 0.7.1