lifetype/branches/lifetype-1.0.6/class/action/searchaction.class.php
Go to the documentation of this file.00001 <?php
00002
00008 include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00009 include_once( PLOG_CLASS_PATH."class/dao/searchengine.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/view/blogtemplatedview.class.php" );
00011 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00012 include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
00013 include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00014
00015 define( "VIEW_SEARCH_TEMPLATE", "searchresults" );
00016
00017 class SearchAction extends BlogAction
00018 {
00019 var $_searchTerms;
00020
00021 function SearchAction( $actionInfo, $request )
00022 {
00023 $this->BlogAction( $actionInfo, $request );
00024
00025
00026 $this->registerFieldValidator( "searchTerms", new StringValidator());
00027 $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_incorrect_search_terms" ));
00028 }
00029
00030 function perform()
00031 {
00032
00033 $this->_searchTerms = $this->_request->getValue( "searchTerms" );
00034
00035
00036 $config =& Config::getConfig();
00037 if( !$config->getValue( "search_engine_enabled" )) {
00038 $this->_view = new ErrorView( $this->_blogInfo, "error_search_engine_disabled" );
00039 $this->setCommonData();
00040
00041 return false;
00042 }
00043
00044
00045 $this->_view = new BlogTemplatedView( $this->_blogInfo, VIEW_SEARCH_TEMPLATE, Array( "searchTerms" => $this->_searchTerms ));
00046 if( $this->_view->isCached()) {
00047 return true;
00048 }
00049
00050 $searchEngine = new SearchEngine();
00051 $searchResults = $searchEngine->search( $this->_blogInfo->getId(), $this->_searchTerms );
00052
00053
00054 $searchTerms = $searchEngine->getAdaptSearchTerms( $this->_searchTerms );
00055
00056
00057 if( count($searchResults) == 0 ) {
00058 $this->_view = new ErrorView( $this->_blogInfo, "error_no_search_results" );
00059 $this->setCommonData();
00060
00061 return true;
00062 }
00063
00064
00065 if( count($searchResults) == 1 ) {
00066
00067
00068 $request =& HttpVars::getRequest();
00069 $searchResult = array_pop( $searchResults );
00070 $article = $searchResult->getArticle();
00071 $request["articleId"] = $article->getId();
00072 $request["blogId"] = $this->_blogInfo->getId();
00073 HttpVars::setRequest( $request );
00074
00075
00076
00077
00078 return Controller::setForwardAction( "ViewArticle" );
00079 }
00080
00081
00082
00083 $this->_view->setValue( "searchresults", $searchResults );
00084
00085 $this->_view->setValue( "searchterms", $searchTerms );
00086
00087 $config =& Config::getConfig();
00088 $urlmode = $config->getValue( "request_format_mode" );
00089 $this->_view->setValue( "urlmode", $urlmode );
00090
00091 $this->setCommonData();
00092
00093 return true;
00094 }
00095 }
00096 ?>