[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/content/ -> advancedsearch.php (source)

   1  <?php
   2  //
   3  // Created on: <23-Jul-2002 17:11:13 bf>
   4  //
   5  // SOFTWARE NAME: eZ publish
   6  // SOFTWARE RELEASE: 3.9.0
   7  // BUILD VERSION: 17785
   8  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   9  // SOFTWARE LICENSE: GNU General Public License v2.0
  10  // NOTICE: >
  11  //   This program is free software; you can redistribute it and/or
  12  //   modify it under the terms of version 2.0  of the GNU General
  13  //   Public License as published by the Free Software Foundation.
  14  //
  15  //   This program is distributed in the hope that it will be useful,
  16  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  //   GNU General Public License for more details.
  19  //
  20  //   You should have received a copy of version 2.0 of the GNU General
  21  //   Public License along with this program; if not, write to the Free
  22  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23  //   MA 02110-1301, USA.
  24  //
  25  //
  26  
  27  include_once ( 'lib/ezutils/classes/ezhttptool.php' );
  28  
  29  include_once ( 'kernel/common/template.php' );
  30  
  31  include_once ( 'kernel/classes/ezsearch.php' );
  32  include_once ( 'kernel/classes/ezcontentclass.php' );
  33  
  34  include_once ( 'kernel/classes/ezsearchlog.php' );
  35  include_once ( 'kernel/classes/ezsection.php' );
  36  
  37  /*!
  38   Get search limit
  39   */
  40  function pageLimit( $searchPageLimit )
  41  {
  42      switch ( $searchPageLimit )
  43      {
  44          case 1:
  45              return 5;
  46  
  47          case 2:
  48          default:
  49              return 10;
  50  
  51          case 3:
  52              return 20;
  53  
  54          case 4:
  55              return 30;
  56  
  57          case 5:
  58              return 50;
  59      }
  60  }
  61  
  62  $http =& eZHTTPTool::instance();
  63  
  64  $Module =& $Params['Module'];
  65  $ViewMode = $Params['ViewMode'];
  66  $Offset = $Params['Offset'];
  67  
  68  if ( $ViewMode == 'offset' )
  69      $ViewMode = '';
  70  
  71  $tpl =& templateInit();
  72  
  73  $ini =& eZINI::instance();
  74  $useSearchCode = $ini->variable( 'SearchSettings', 'SearchViewHandling' ) == 'default';
  75  $logSearchStats = $ini->variable( 'SearchSettings', 'LogSearchStats' ) == 'enabled';
  76  
  77  $searchText = '';
  78  $originalSearchText = '';
  79  $phraseSearchText = '';
  80  
  81  if ( !is_numeric( $Offset ) )
  82      $Offset = 0;
  83  
  84  $searchPageLimit = 2;
  85  if ( $http->hasVariable( 'SearchPageLimit' ) )
  86  {
  87      $searchPageLimit = $http->variable( 'SearchPageLimit' );
  88  }
  89  
  90  $pageLimit = pageLimit( $searchPageLimit );
  91  
  92  $maximumSearchLimit = $ini->variable( 'SearchSettings', 'MaximumSearchLimit' );
  93  if ( $pageLimit > $maximumSearchLimit )
  94      $pageLimit = $maximumSearchLimit;
  95  
  96  if ( $http->hasVariable( 'PhraseSearchText' ) and trim( $http->variable( 'PhraseSearchText' ) ) != '' )
  97  {
  98      $searchText = '"' . $http->variable( 'PhraseSearchText' ) . '"';
  99      $phraseSearchText = $http->variable( 'PhraseSearchText' );
 100  }
 101  
 102  $fullSearchText = '';
 103  if ( $http->hasVariable( 'SearchText' ) )
 104  {
 105      if ( $searchText != '' )
 106          $searchText .= ' ';
 107      $originalSearchText = $http->variable( 'SearchText' );
 108      $searchText .= $originalSearchText;
 109      $fullSearchText = $http->variable( 'SearchText' );
 110  }
 111  
 112  $searchContentClassID = -1;
 113  $searchContentClassAttributes = 0;
 114  $searchContentClassAttributeArray = array();
 115  if ( $http->hasVariable( 'SearchContentClassID' ) and
 116       $http->variable( 'SearchContentClassID' ) != -1 )
 117  {
 118      $searchContentClassID = $http->variable( 'SearchContentClassID' );
 119      if ( (int) $searchContentClassID > 0 )
 120      {
 121          $searchContentClass = eZContentClass::fetch( (int) $searchContentClassID );
 122          if ( is_object( $searchContentClass ) )
 123              $searchContentClassAttributeArray = $searchContentClass->fetchSearchableAttributes();
 124      }
 125  }
 126  
 127  $searchContentClassAttributeID = -1;
 128  if ( $http->hasVariable( 'SearchContentClassAttributeID' ) and
 129       $http->variable( 'SearchContentClassAttributeID' ) != -1 )
 130  {
 131      $searchContentClassAttributeID = $http->variable( 'SearchContentClassAttributeID' );
 132  }
 133  
 134  $searchDate = -1;
 135  if ( $http->hasVariable( 'SearchDate' ) and
 136       $http->variable( 'SearchDate' ) != -1 )
 137  {
 138      $searchDate = $http->variable( 'SearchDate' );
 139  }
 140  
 141  $searchTimestamp = false;
 142  if ( $http->hasVariable( 'SearchTimestamp' ) and
 143       $http->variable( 'SearchTimestamp' ) )
 144  {
 145      $searchTimestamp = $http->variable( 'SearchTimestamp' );
 146  }
 147  
 148  $searchSectionID = -1;
 149  if ( $http->hasVariable( 'SearchSectionID' ) and
 150       $http->variable( 'SearchSectionID' ) != -1 )
 151  {
 152      $searchSectionID = $http->variable( 'SearchSectionID' );
 153  }
 154  
 155  $subTreeArray = array();
 156  if ( $http->hasVariable( 'SubTreeArray' ) )
 157  {
 158      if ( is_array( $http->variable( 'SubTreeArray' ) ) )
 159          $subTreeList = $http->variable( 'SubTreeArray' );
 160      else
 161          $subTreeList = array( $http->variable( 'SubTreeArray' ) );
 162      foreach ( $subTreeList as $subTreeItem )
 163      {
 164          if ( $subTreeItem > 0 )
 165              $subTreeArray[] = $subTreeItem;
 166      }
 167  }
 168  
 169  $Module->setTitle( "Search for: $searchText" );
 170  
 171  $classArray = eZContentClass::fetchList();
 172  
 173  $sectionArray = eZSection::fetchList();
 174  
 175  $searchArray =& eZSearch::buildSearchArray();
 176  
 177  if ( $useSearchCode )
 178  {
 179      $searchResult = eZSearch::search( $searchText, array( 'SearchSectionID' => $searchSectionID,
 180                                                            'SearchContentClassID' => $searchContentClassID,
 181                                                            'SearchContentClassAttributeID' => $searchContentClassAttributeID,
 182                                                            'SearchSubTreeArray' => $subTreeArray,
 183                                                            'SearchDate' => $searchDate,
 184                                                            'SearchTimestamp' => $searchTimestamp,
 185                                                            'SearchLimit' => $pageLimit,
 186                                                            'SearchOffset' => $Offset ),
 187                                         $searchArray );
 188      if ( strlen(trim($searchText)) == 0 && count( $searchArray ) > 0  )
 189      {
 190          $searchText = 'search by additional parameter';
 191      }
 192  }
 193  
 194  $viewParameters = array( 'offset' => $Offset );
 195  
 196  $searchData = false;
 197  $tpl->setVariable( "search_data", $searchData );
 198  $tpl->setVariable( 'search_contentclass_id', $searchContentClassID );
 199  $tpl->setVariable( 'search_contentclass_attribute_id', $searchContentClassAttributeID );
 200  $tpl->setVariable( 'search_section_id', $searchSectionID );
 201  $tpl->setVariable( 'search_date', $searchDate );
 202  $tpl->setVariable( 'search_timestamp', $searchTimestamp );
 203  $tpl->setVariable( 'search_sub_tree', $subTreeArray );
 204  $tpl->setVariable( 'search_text', $searchText );
 205  $tpl->setVariable( 'search_page_limit', $searchPageLimit );
 206  $tpl->setVariable( 'full_search_text', $fullSearchText );
 207  $tpl->setVariable( 'phrase_search_text', $phraseSearchText );
 208  
 209  $tpl->setVariable( "view_parameters", $viewParameters );
 210  $tpl->setVariable( 'use_template_search', !$useSearchCode );
 211  
 212  // --- Compatability code start ---
 213  if ( $useSearchCode )
 214  {
 215      $tpl->setVariable( 'offset', $Offset );
 216      $tpl->setVariable( 'page_limit', $pageLimit );
 217      $tpl->setVariable( 'search_text_enc', urlencode( $originalSearchText ) );
 218      $tpl->setVariable( 'phrase_search_text_enc', urlencode( $phraseSearchText ) );
 219      $tpl->setVariable( 'search_result', $searchResult['SearchResult'] );
 220      $tpl->setVariable( 'search_count', $searchResult['SearchCount'] );
 221      $tpl->setVariable( 'stop_word_array', $searchResult['StopWordArray'] );
 222  }
 223  else
 224  {
 225      $tpl->setVariable( 'offset', false );
 226      $tpl->setVariable( 'page_limit', false );
 227      $tpl->setVariable( 'search_text_enc', false );
 228      $tpl->setVariable( 'phrase_search_text_enc', false );
 229      $tpl->setVariable( 'search_result', false );
 230      $tpl->setVariable( 'search_count', false );
 231      $tpl->setVariable( 'stop_word_array', false );
 232  }
 233  // --- Compatability code end ---
 234  
 235  $tpl->setVariable( 'content_class_array', $classArray );
 236  $tpl->setVariable( 'section_array', $sectionArray );
 237  $tpl->setVariable( 'search_content_class_attribute_array', $searchContentClassAttributeArray );
 238  
 239  // Set template variable containing search terms for attribute-based search.
 240  $searchTermsArray = array();
 241  // BEGIN old code for backwards compatibility
 242  // Set template variable for attribute-based search.
 243  // Make it a hash with classattribute_id as key. If it has an identifier, add that to the key.
 244  $searchArrayByClassAttributeID = array();
 245  // END old code for backwards compatibility
 246  foreach ( $searchArray as $searchItem )
 247  {
 248      foreach ( $searchItem as $searchTerms )
 249      {
 250          if ( isSet( $searchTerms['identifier'] ) )
 251          {
 252              $searchTermsArray[$searchTerms['identifier']] = $searchTerms;
 253              // BEGIN old code for backwards compatibility
 254              $searchArrayByClassAttributeID[$searchTerms['classattribute_id'] . '_' .
 255                                             $searchTerms['identifier']] = $searchTerms;
 256              // END old code for backwards compatibility
 257          }
 258          else
 259          {
 260              $searchTermsArray[$searchTerms['classattribute_id']] = $searchTerms;
 261              // BEGIN old code for backwards compatibility
 262              $searchArrayByClassAttributeID[$searchTerms['classattribute_id']] = $searchTerms;
 263              // END old code for backwards compatibility
 264          }
 265      }
 266  }
 267  $tpl->setVariable( 'search_terms_array', $searchTermsArray );
 268  // BEGIN old code for backwards compatibility
 269  $tpl->setVariable( 'search_array_by_class_attribute_id', $searchArrayByClassAttributeID );
 270  // END old code for backwards compatibility
 271  
 272  if ( $searchSectionID != -1 )
 273  {
 274      include_once ( 'kernel/common/eztemplatedesignresource.php' );
 275      $res =& eZTemplateDesignResource::instance();
 276      $res->setKeys( array( array( 'section', $searchSectionID ) ) );
 277  }
 278  
 279  $Result = array();
 280  
 281  if ( trim( $ViewMode ) != '' )
 282  {
 283      // Fetch override template for viewmode if wanted
 284      $Result['content'] =& $tpl->fetch( "design:content/advancedsearch/$ViewMode.tpl" );
 285  }
 286  else
 287  {
 288      $Result['content'] =& $tpl->fetch( 'design:content/advancedsearch.tpl' );
 289  }
 290  $Result['path'] = array( array( 'text' => ezi18n( 'kernel/content', 'Search' ),
 291                                  'url' => false ),
 292                           array( 'text' => ezi18n( 'kernel/content', 'Advanced' ),
 293                                  'url' => false ) );
 294  
 295  if ( !$useSearchCode )
 296  {
 297      $searchData = $tpl->variable( "search_data" );
 298  }
 299  else
 300  {
 301      $searchData = $searchResult;
 302  }
 303  
 304  if ( $logSearchStats and trim( $searchText ) != "" )
 305      eZSearchLog::addPhrase( $searchText, $searchData['SearchCount'] );
 306  
 307  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7