Example #1
0
 public function getPage($pos, $page_content)
 {
     global $_CONFIG, $_ARRAYLANG;
     $objTpl = new \Cx\Core\Html\Sigma('.');
     \Cx\Core\Csrf\Controller\Csrf::add_placeholder($objTpl);
     $objTpl->setErrorHandling(PEAR_ERROR_DIE);
     $objTpl->setTemplate($page_content);
     $objTpl->setGlobalVariable($_ARRAYLANG);
     $term = isset($_REQUEST['term']) ? trim(contrexx_input2raw($_REQUEST['term'])) : '';
     if (strlen($term) >= 3) {
         $term = trim(contrexx_input2raw($_REQUEST['term']));
         $this->setTerm($term);
         $eventHandlerInstance = \Env::get('cx')->getEvents();
         $eventHandlerInstance->triggerEvent('SearchFindContent', array($this));
         if ($this->result->size() == 1) {
             $arraySearchResults[] = $this->result->toArray();
         } else {
             $arraySearchResults = $this->result->toArray();
         }
         usort($arraySearchResults, function ($a, $b) {
             if ($a['Score'] == $b['Score']) {
                 if (isset($a['Date'])) {
                     if ($a['Date'] == $b['Date']) {
                         return 0;
                     }
                     if ($a['Date'] > $b['Date']) {
                         return -1;
                     }
                     return 1;
                 }
                 return 0;
             }
             if ($a['Score'] > $b['Score']) {
                 return -1;
             }
             return 1;
         });
         $countResults = sizeof($arraySearchResults);
         if (!is_numeric($pos)) {
             $pos = 0;
         }
         $paging = getPaging($countResults, $pos, '&amp;section=Search&amp;term=' . contrexx_raw2encodedUrl($term), '<b>' . $_ARRAYLANG['TXT_SEARCH_RESULTS'] . '</b>', true);
         $objTpl->setVariable('SEARCH_PAGING', $paging);
         $objTpl->setVariable('SEARCH_TERM', contrexx_raw2xhtml($term));
         if ($countResults > 0) {
             $searchComment = sprintf($_ARRAYLANG['TXT_SEARCH_RESULTS_ORDER_BY_RELEVANCE'], contrexx_raw2xhtml($term), $countResults);
             $objTpl->setVariable('SEARCH_TITLE', $searchComment);
             $arraySearchOut = array_slice($arraySearchResults, $pos, $_CONFIG['corePagingLimit']);
             foreach ($arraySearchOut as $details) {
                 $objTpl->setVariable(array('COUNT_MATCH' => $_ARRAYLANG['TXT_RELEVANCE'] . ' ' . $details['Score'] . '%', 'LINK' => '<b><a href="' . $details['Link'] . '" title="' . contrexx_raw2xhtml($details['Title']) . '">' . contrexx_raw2xhtml($details['Title']) . '</a></b>', 'SHORT_CONTENT' => contrexx_raw2xhtml($details['Content'])));
                 $objTpl->parse('search_result');
             }
             return $objTpl->get();
         }
     }
     $noresult = $term != '' ? sprintf($_ARRAYLANG['TXT_NO_SEARCH_RESULTS'], $term) : $_ARRAYLANG['TXT_PLEASE_ENTER_SEARCHTERM'];
     $objTpl->setVariable('SEARCH_TITLE', $noresult);
     return $objTpl->get();
 }
Example #2
0
 public function getPage($pos, $page_content)
 {
     global $_CONFIG, $_ARRAYLANG;
     $objTpl = new \Cx\Core\Html\Sigma('.');
     \Cx\Core\Csrf\Controller\Csrf::add_placeholder($objTpl);
     $objTpl->setErrorHandling(PEAR_ERROR_DIE);
     $objTpl->setTemplate($page_content);
     $objTpl->setGlobalVariable($_ARRAYLANG);
     // Load main template even if we have a cmd set
     if ($objTpl->placeholderExists('APPLICATION_DATA')) {
         $page = new \Cx\Core\ContentManager\Model\Entity\Page();
         $page->setVirtual(true);
         $page->setType(\Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION);
         $page->setModule('Search');
         // load source code
         $applicationTemplate = \Cx\Core\Core\Controller\Cx::getContentTemplateOfPage($page);
         \LinkGenerator::parseTemplate($applicationTemplate);
         $objTpl->addBlock('APPLICATION_DATA', 'application_data', $applicationTemplate);
     }
     $term = isset($_REQUEST['term']) ? trim(contrexx_input2raw($_REQUEST['term'])) : '';
     if (strlen($term) >= 3) {
         $term = trim(contrexx_input2raw($_REQUEST['term']));
         $this->setTerm($term);
         $eventHandlerInstance = \Env::get('cx')->getEvents();
         $eventHandlerInstance->triggerEvent('SearchFindContent', array($this));
         if ($this->result->size() == 1) {
             $arraySearchResults[] = $this->result->toArray();
         } else {
             $arraySearchResults = $this->result->toArray();
         }
         usort($arraySearchResults, function ($a, $b) {
             if ($a['Score'] == $b['Score']) {
                 if (isset($a['Date'])) {
                     if ($a['Date'] == $b['Date']) {
                         return 0;
                     }
                     if ($a['Date'] > $b['Date']) {
                         return -1;
                     }
                     return 1;
                 }
                 return 0;
             }
             if ($a['Score'] > $b['Score']) {
                 return -1;
             }
             return 1;
         });
         $countResults = sizeof($arraySearchResults);
         if (!is_numeric($pos)) {
             $pos = 0;
         }
         $paging = getPaging($countResults, $pos, '&amp;section=Search&amp;term=' . contrexx_raw2encodedUrl($term), '<b>' . $_ARRAYLANG['TXT_SEARCH_RESULTS'] . '</b>', true);
         $objTpl->setVariable('SEARCH_PAGING', $paging);
         $objTpl->setVariable('SEARCH_TERM', contrexx_raw2xhtml($term));
         if ($countResults > 0) {
             $searchComment = sprintf($_ARRAYLANG['TXT_SEARCH_RESULTS_ORDER_BY_RELEVANCE'], contrexx_raw2xhtml($term), $countResults);
             $objTpl->setVariable('SEARCH_TITLE', $searchComment);
             $arraySearchOut = array_slice($arraySearchResults, $pos, $_CONFIG['corePagingLimit']);
             foreach ($arraySearchOut as $details) {
                 // append search term to result link
                 $link = $details['Link'];
                 if (strpos($link, '?') === false) {
                     $link .= '?';
                 } else {
                     $link .= '&';
                 }
                 $link .= 'searchTerm=' . urlencode($term);
                 // parse result into template
                 $objTpl->setVariable(array('COUNT_MATCH' => $_ARRAYLANG['TXT_RELEVANCE'] . ' ' . $details['Score'] . '%', 'LINK' => '<b><a href="' . $link . '" title="' . contrexx_raw2xhtml($details['Title']) . '">' . contrexx_raw2xhtml($details['Title']) . '</a></b>', 'SHORT_CONTENT' => contrexx_raw2xhtml($details['Content'])));
                 $objTpl->parse('search_result');
             }
             return $objTpl->get();
         }
     }
     $noresult = $term != '' ? sprintf($_ARRAYLANG['TXT_NO_SEARCH_RESULTS'], $term) : $_ARRAYLANG['TXT_PLEASE_ENTER_SEARCHTERM'];
     $objTpl->setVariable('SEARCH_TITLE', $noresult);
     return $objTpl->get();
 }