Example #1
0
 /**
  * Responsible to output the search layout.
  *
  * @access	public
  * @return	null
  *
  */
 public function display($tpl = null)
 {
     // Check for user profile completeness
     FD::checkCompleteProfile();
     // Get the current logged in user.
     $query = $this->input->get('q', '', 'default');
     $q = $query;
     // Get the search type
     $type = $this->input->get('type', '', 'cmd');
     // Load up the model
     $indexerModel = FD::model('Indexer');
     // Retrieve a list of supported types
     $allowedTypes = $indexerModel->getSupportedType();
     if (!in_array($type, $allowedTypes)) {
         $type = '';
     }
     // Options
     $data = null;
     $types = null;
     $count = 0;
     $next_limit = '';
     $limit = FD::themes()->getConfig()->get('search_limit');
     // Get the search model
     $model = FD::model('Search');
     $searchAdapter = FD::get('Search');
     // Determines if finder is enabled
     $isFinderEnabled = JComponentHelper::isEnabled('com_finder');
     if (!empty($query) && $isFinderEnabled) {
         jimport('joomla.application.component.model');
         $lib = JPATH_ROOT . '/components/com_finder/models/search.php';
         require_once $lib;
         if ($type) {
             JRequest::setVar('t', $type);
         }
         // Load up finder's model
         $finderModel = new FinderModelSearch();
         $state = $finderModel->getState();
         // Get the query
         // this line need to be here. so that the indexer can get the correct value
         $query = $finderModel->getQuery();
         // When there is no terms match, check if smart search suggested any terms or not. if yes, lets use it.
         if (!$query->terms) {
             if (isset($query->included) && count($query->included) > 0) {
                 $suggestion = '';
                 foreach ($query->included as $item) {
                     if (isset($item->suggestion) && !empty($item->suggestion)) {
                         $suggestion = $item->suggestion;
                     }
                 }
                 if ($suggestion) {
                     $app = JFactory::getApplication();
                     $input = $app->input;
                     $input->request->set('q', $suggestion);
                     // Load up the new model
                     $finderModel = new FinderModelSearch();
                     $state = $finderModel->getState();
                     // this line need to be here. so that the indexer can get the correct value
                     $query = $finderModel->getQuery();
                 }
             }
         }
         //reset the pagination state.
         $state->{'list.start'} = 0;
         $state->{'list.limit'} = $limit;
         $results = $finderModel->getResults();
         $count = $finderModel->getTotal();
         $pagination = $finderModel->getPagination();
         if ($results) {
             $data = $searchAdapter->format($results, $query);
             $query = $finderModel->getQuery();
             if (FD::isJoomla30()) {
                 $pagination->{'pages.total'} = $pagination->pagesTotal;
             }
             if ($pagination->{'pages.total'} == 1) {
                 $next_limit = '-1';
             } else {
                 $next_limit = $pagination->limitstart + $pagination->limit;
             }
         }
         // @badge: search.create
         // Assign badge for the person that initiated the friend request.
         $badge = FD::badges();
         $badge->log('com_easysocial', 'search.create', $this->my->id, JText::_('COM_EASYSOCIAL_SEARCH_BADGE_SEARCHED_ITEM'));
         // get types
         $types = $searchAdapter->getTaxonomyTypes();
     }
     // Set the page title
     FD::page()->title(JText::_('COM_EASYSOCIAL_PAGE_TITLE_SEARCH'));
     // Set the page breadcrumb
     FD::page()->breadcrumb(JText::_('COM_EASYSOCIAL_PAGE_TITLE_SEARCH'));
     $this->set('types', $types);
     $this->set('data', $data);
     $this->set('query', $q);
     $this->set('total', $count);
     $this->set('totalcount', $count);
     $this->set('next_limit', $next_limit);
     echo parent::display('site/search/default');
 }
Example #2
0
 /**
  * get activity logs.
  *
  * @since	1.0
  * @access	public
  */
 public function getItems()
 {
     // Check for request forgeries!
     FD::checkToken();
     // search controller do not need to check islogin.
     // Get the current view
     $view = $this->getCurrentView();
     // Get current logged in user
     $my = FD::user();
     // 7:EasyBlog
     $type = JRequest::getInt('type', 0);
     $keywords = JRequest::getVar('q', '');
     $next_limit = JRequest::getVar('next_limit', '');
     $last_type = JRequest::getVar('last_type', '');
     $isloadmore = JRequest::getVar('loadmore', false);
     $ismini = JRequest::getVar('mini', false);
     $highlight = $ismini ? false : true;
     $limit = $ismini ? FD::themes()->getConfig()->get('search_toolbarlimit') : FD::themes()->getConfig()->get('search_limit');
     // @badge: search.create
     // Assign badge for the person that initiated the friend request.
     if (!$isloadmore) {
         $badge = FD::badges();
         $badge->log('com_easysocial', 'search.create', $my->id, JText::_('COM_EASYSOCIAL_SEARCH_BADGE_SEARCHED_ITEM'));
     }
     $results = array();
     $pagination = null;
     $count = 0;
     $data = array();
     $isFinderEnabled = JComponentHelper::isEnabled('com_finder');
     if ($isFinderEnabled) {
         jimport('joomla.application.component.model');
         $searchAdapter = FD::get('Search');
         $path = JPATH_ROOT . '/components/com_finder/models/search.php';
         require_once $path;
         $jModel = new FinderModelSearch();
         $state = $jModel->getState();
         $query = $jModel->getQuery();
         // this line need to be here. so that the indexer can get the correct value
         if (!$query->terms) {
             // if there is no terms match. lets check if smart search suggested any terms or not. if yes, lets use it.
             if (isset($query->included) && count($query->included) > 0) {
                 $suggestion = '';
                 foreach ($query->included as $item) {
                     if (isset($item->suggestion) && !empty($item->suggestion)) {
                         $suggestion = $item->suggestion;
                     }
                 }
                 if ($suggestion) {
                     //reset the query string.
                     $app = JFactory::getApplication();
                     $input = $app->input;
                     $input->request->set('q', $suggestion);
                     //refresh
                     $jModel = new FinderModelSearch();
                     $state = $jModel->getState();
                     $query = $jModel->getQuery();
                     // this line need to be here. so that the indexer can get the correct value
                 }
             }
         }
         //reset the pagination state.
         $state->{'list.start'} = $next_limit;
         $state->{'list.limit'} = $limit;
         if ($type) {
             // 7:EasyBlog
             $typeAlias = JRequest::getVar('type', '');
             $typeAlias = explode(':', $typeAlias);
             $typeAlias = $typeAlias[1];
             $typeArr['Type'] = array($typeAlias => $type);
             $query->filters = $typeArr;
         }
         $results = $jModel->getResults();
         $count = $jModel->getTotal();
         $pagination = $jModel->getPagination();
         if (FD::isJoomla30()) {
             $pagination->{'pages.total'} = $pagination->pagesTotal;
             $pagination->{'pages.current'} = $pagination->pagesCurrent;
         }
         if ($results) {
             $data = $searchAdapter->format($results, $query, $highlight);
             if ($pagination->{'pages.total'} == 1 || $pagination->{'pages.total'} == $pagination->{'pages.current'}) {
                 $next_limit = '-1';
             } else {
                 $next_limit = $pagination->limitstart + $pagination->limit;
             }
         }
     }
     return $view->call(__FUNCTION__, $data, $last_type, $next_limit, $isloadmore, $ismini, $count);
 }