lifetype-1.1.6/class/action/searchaction.class.php
Go to the documentation of this file.00001 <?php
00002
00006 include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00007 include_once( PLOG_CLASS_PATH."class/dao/searchengine.class.php" );
00008 include_once( PLOG_CLASS_PATH."class/view/blogtemplatedview.class.php" );
00009 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00011 include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
00012 include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00013 include_once( PLOG_CLASS_PATH."class/data/pager/pager.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 $tf = new Textfilter();
00034 $this->_searchTerms = $tf->filterAllHTML( $this->_request->getValue( "searchTerms" ));
00035
00036
00037 $config =& Config::getConfig();
00038 if( !$config->getValue( "search_engine_enabled" )) {
00039 $this->_view = new ErrorView( $this->_blogInfo, "error_search_engine_disabled" );
00040 $this->setCommonData();
00041
00042 return false;
00043 }
00044
00045
00046 $this->_view = new BlogTemplatedView( $this->_blogInfo, VIEW_SEARCH_TEMPLATE, Array( "searchTerms" => $this->_searchTerms, "page" => $this->_page ));
00047 if( $this->_view->isCached()) {
00048 return true;
00049 }
00050
00051
00052 $blogSettings = $this->_blogInfo->getSettings();
00053 $itemsPerPage = $blogSettings->getValue( 'show_posts_max' );
00054
00055
00056 $searchEngine = new SearchEngine();
00057 $searchResults = $searchEngine->search( $this->_blogInfo->getId(),
00058 $this->_searchTerms,
00059 POST_STATUS_PUBLISHED,
00060 false,
00061 $this->_page,
00062 $itemsPerPage
00063 );
00064
00065 $numSearchResults = $searchEngine->getNumSearchResults( $this->_blogInfo->getId(),
00066 $this->_searchTerms,
00067 POST_STATUS_PUBLISHED,
00068 false );
00069
00070
00071 $searchTerms = $searchEngine->getAdaptSearchTerms( $this->_searchTerms );
00072
00073
00074 if( count($searchResults) == 0 ) {
00075 $this->_view = new ErrorView( $this->_blogInfo, "error_no_search_results" );
00076 $this->setCommonData();
00077
00078 return true;
00079 }
00080
00081
00082 if( count($searchResults) == 1 && $numSearchResults == 1 ) {
00083
00084
00085 $request = HttpVars::getRequest();
00086 $searchResult = array_pop( $searchResults );
00087 $article = $searchResult->getResult();
00088 $url = $this->_blogInfo->getBlogRequestGenerator();
00089
00090
00091 $url->setXHTML( false );
00092 $permalink = $url->postPermalink( $article );
00093
00094
00095 include_once( PLOG_CLASS_PATH."class/view/redirectview.class.php" );
00096 $this->_view = new RedirectView( $permalink );
00097
00098 return( true );
00099 }
00100
00101
00102
00103 $this->_view->setValue( "searchresults", $searchResults );
00104
00105 $this->_view->setValue( "searchterms", $searchTerms );
00106
00107 $config =& Config::getConfig();
00108 $urlmode = $config->getValue( "request_format_mode" );
00109 $this->_view->setValue( "urlmode", $urlmode );
00110
00111
00112 $url = $this->_blogInfo->getBlogRequestGenerator();
00113 $basePageUrl = $url->getIndexUrl()."?op=Search&searchTerms=".$this->_searchTerms."&page=";
00114 $pager = new Pager( $basePageUrl,
00115 $this->_page,
00116 $numSearchResults,
00117 $itemsPerPage );
00118
00119 $this->_view->setValue( 'pager', $pager );
00120
00121 $this->setCommonData();
00122
00123 return true;
00124 }
00125 }
00126 ?>