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