Ejemplo n.º 1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $searchTerm = SpoonFilter::getPostValue('term', null, '');
     $term = SPOON_CHARSET == 'utf-8' ? SpoonFilter::htmlspecialchars($searchTerm) : SpoonFilter::htmlentities($searchTerm);
     // validate
     if ($term == '') {
         $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.');
     }
     // previous search result
     $previousTerm = SpoonSession::exists('searchTerm') ? SpoonSession::get('searchTerm') : '';
     SpoonSession::set('searchTerm', '');
     // save this term?
     if ($previousTerm != $term) {
         // format data
         $this->statistics = array();
         $this->statistics['term'] = $term;
         $this->statistics['language'] = FRONTEND_LANGUAGE;
         $this->statistics['time'] = FrontendModel::getUTCDate();
         $this->statistics['data'] = serialize(array('server' => $_SERVER));
         $this->statistics['num_results'] = FrontendSearchModel::getTotal($term);
         // save data
         FrontendSearchModel::save($this->statistics);
     }
     // save current search term in cookie
     SpoonSession::set('searchTerm', $term);
     // output
     $this->output(self::OK);
 }
Ejemplo n.º 2
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $term = SpoonFilter::getGetValue('term', null, '');
     // validate
     if ($term == '') {
         $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.');
     }
     // previous search result
     $previousTerm = SpoonSession::exists('searchTerm') ? SpoonSession::get('searchTerm') : '';
     SpoonSession::set('searchTerm', '');
     // save this term?
     if ($previousTerm != $term) {
         // format data
         $this->statistics = array();
         $this->statistics['term'] = $term;
         $this->statistics['language'] = FRONTEND_LANGUAGE;
         $this->statistics['time'] = FrontendModel::getUTCDate();
         $this->statistics['data'] = serialize(array('server' => $_SERVER));
         $this->statistics['num_results'] = FrontendSearchModel::getTotal($term);
         // save data
         FrontendSearchModel::save($this->statistics);
     }
     // save current search term in cookie
     SpoonSession::set('searchTerm', $term);
     // output
     $this->output(self::OK);
 }
Ejemplo n.º 3
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $term = SpoonFilter::getGetValue('term', null, '');
     $limit = (int) FrontendModel::getModuleSetting('search', 'autocomplete_num_items', 10);
     // validate
     if ($term == '') {
         $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.');
     }
     // get matches
     $matches = FrontendSearchModel::getStartsWith($term, FRONTEND_LANGUAGE, $limit);
     // get search url
     $url = FrontendNavigation::getURLForBlock('search');
     // loop items and set search url
     foreach ($matches as &$match) {
         $match['url'] = $url . '?form=search&q=' . $match['term'];
     }
     // output
     $this->output(self::OK, $matches);
 }
Ejemplo n.º 4
0
 /**
  * Load the data
  */
 private function getRealData()
 {
     // no search term = no search
     if (!$this->term) {
         return;
     }
     // set url
     $this->pagination['url'] = FrontendNavigation::getURLForBlock('search') . '?form=search&q=' . $this->term;
     $this->pagination['limit'] = FrontendModel::getModuleSetting('search', 'overview_num_items', 20);
     // populate calculated fields in pagination
     $this->pagination['requested_page'] = $this->requestedPage;
     $this->pagination['offset'] = $this->pagination['requested_page'] * $this->pagination['limit'] - $this->pagination['limit'];
     // get items
     $this->items = FrontendSearchModel::search($this->term, $this->pagination['limit'], $this->pagination['offset']);
     // populate count fields in pagination
     // this is done after actual search because some items might be activated/deactivated (getTotal only does rough checking)
     $this->pagination['num_items'] = FrontendSearchModel::getTotal($this->term);
     $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
     // num pages is always equal to at least 1
     if ($this->pagination['num_pages'] == 0) {
         $this->pagination['num_pages'] = 1;
     }
     // redirect if the request page doesn't exist
     if ($this->requestedPage > $this->pagination['num_pages'] || $this->requestedPage < 1) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // debug mode = no cache
     if (!SPOON_DEBUG) {
         // set cache content
         SpoonFile::setContent($this->cacheFile, "<?php\n" . '$pagination = ' . var_export($this->pagination, true) . ";\n" . '$items = ' . var_export($this->items, true) . ";\n?>");
     }
 }
Ejemplo n.º 5
0
 /**
  * Save statistics
  */
 private function saveStatistics()
 {
     // no search term = no search
     if (!$this->term) {
         return;
     }
     // previous search result
     $previousTerm = SpoonSession::exists('searchTerm') ? SpoonSession::get('searchTerm') : '';
     SpoonSession::set('searchTerm', '');
     // save this term?
     if ($previousTerm != $this->term) {
         // format data
         $this->statistics = array();
         $this->statistics['term'] = $this->term;
         $this->statistics['language'] = FRONTEND_LANGUAGE;
         $this->statistics['time'] = FrontendModel::getUTCDate();
         $this->statistics['data'] = serialize(array('server' => $_SERVER));
         $this->statistics['num_results'] = $this->pagination['num_items'];
         // save data
         FrontendSearchModel::save($this->statistics);
     }
     // save current search term in cookie
     SpoonSession::set('searchTerm', $this->term);
 }