[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/action/ -> searchaction.class.php (source)

   1  <?php
   2  
   3      /**
   4       * @package action
   5       */
   6      lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/dao/searchengine.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/view/blogtemplatedview.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
  10      lt_include( PLOG_CLASS_PATH."class/data/filter/htmlfilter.class.php" );
  11      lt_include( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
  12      lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
  13      lt_include( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
  14  
  15      define( "VIEW_SEARCH_TEMPLATE", "searchresults" );
  16  
  17      class SearchAction extends BlogAction
  18      {
  19          var $_searchTerms;
  20      
  21          function SearchAction( $actionInfo, $request )
  22          {
  23              $this->BlogAction( $actionInfo, $request );
  24              
  25              // data validatdion
  26              $this->registerFieldValidator( "searchTerms", new StringValidator());
  27              $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_incorrect_search_terms" ));
  28          }
  29          
  30          function perform()
  31          {
  32              // get the search terms that have already been validated...
  33              $this->_searchTerms = $this->_request->getFilteredValue( "searchTerms", new HtmlFilter());
  34          
  35              // check if the search feature is disabled in this site...
  36              $config =& Config::getConfig();
  37              if( !$config->getValue( "search_engine_enabled" )) {
  38                  $this->_view = new ErrorView( $this->_blogInfo, "error_search_engine_disabled" );
  39                  $this->setCommonData();
  40                  
  41                  return false;
  42              }
  43              
  44              // create the view and make sure that it hasn't been cached
  45              $this->_view = new BlogTemplatedView( $this->_blogInfo, VIEW_SEARCH_TEMPLATE, Array( "searchTerms" => $this->_searchTerms, "page" => $this->_page ));
  46              if( $this->_view->isCached()) {
  47                  $this->setCommonData();
  48                  return true;
  49              }
  50              
  51              // calculate how many results per page
  52              $blogSettings = $this->_blogInfo->getSettings();
  53              $itemsPerPage = $blogSettings->getValue( "show_posts_max" );
  54              
  55              // get the array with the results
  56              $searchEngine = new SearchEngine();
  57              $searchResults = $searchEngine->search( $this->_blogInfo->getId(), 
  58                                                      $this->_searchTerms,
  59                                                      POST_STATUS_PUBLISHED,
  60                                                      false,
  61                                                      $this->_page,             // page
  62                                                      $itemsPerPage   // items per page
  63                                                     );
  64              // and the total number of items
  65              $numSearchResults = $searchEngine->getNumSearchResults( $this->_blogInfo->getId(),
  66                                                                      $this->_searchTerms,
  67                                                                      POST_STATUS_PUBLISHED,
  68                                                                      false );
  69                                                                          
  70              // if no search results, return an error message
  71              if( count($searchResults) == 0 ) {
  72                  $this->_view = new ErrorView( $this->_blogInfo, "error_no_search_results" );
  73                  $this->setCommonData();
  74                  
  75                  return true;
  76              }
  77              
  78              // if only one search result, we can see it straight away 
  79              if( count($searchResults) == 1 && $numSearchResults == 1 ) {
  80                  // only one search result, we can redirect the view via the URL,
  81                  // so that the right permalink appears in the address bar
  82                  $request = HttpVars::getRequest();
  83                  $searchResult = array_pop( $searchResults );
  84                  $article = $searchResult->getResult();
  85                  $url = $this->_blogInfo->getBlogRequestGenerator();
  86                  // we need to deactivate the XHTML mode of the request generator or else
  87                  // we'll get things escaped twice!
  88                  $url->setXHTML( false );
  89                  $permalink = $url->postPermalink( $article );
  90                  
  91                  // load the view and redirect the flow
  92                  lt_include( PLOG_CLASS_PATH."class/view/redirectview.class.php" );
  93                  $this->_view = new RedirectView( $permalink );
  94                  
  95                  return( true );
  96              }
  97              
  98              // or else, show a list with all the posts that match the requested
  99              // search terms
 100              $this->_view->setValue( "searchresults", $searchResults );
 101              // MARKWU: Now, I can use the searchterms to get the keyword
 102              $this->_view->setValue( "searchterms", $this->_searchTerms );
 103              // MARKWU:
 104              $config =& Config::getConfig();
 105              $urlmode = $config->getValue( "request_format_mode" );            
 106              $this->_view->setValue( "urlmode", $urlmode );
 107                  // set the page title
 108              $this->_view->setPageTitle( $this->_blogInfo->getBlog()." | ".$this->_locale->tr("search_results"));
 109  
 110              // build the pager
 111              $url = $this->_blogInfo->getBlogRequestGenerator();
 112              $basePageUrl = $url->getIndexUrl()."?op=Search&amp;searchTerms=".$this->_searchTerms."&amp;page=";
 113              $pager = new Pager( $basePageUrl,            // url to the next page
 114                                  $this->_page,            // current page
 115                                  $numSearchResults,            // total number of search results
 116                                  $itemsPerPage );
 117      
 118              $this->_view->setValue( 'pager', $pager );
 119  
 120              $this->setCommonData();
 121              
 122              return true;
 123          }
 124      }
 125  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics