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();
 }
Example #3
0
 /**
  * Calls preComponentLoad-Hooks
  * PreComponentLoad-Hooks are defined in /config/preComponentLoadHooks.yml
  *
  * @throws \Exception
  */
 protected function callPreComponentLoadHooks()
 {
     try {
         $filename = $this->getWebsiteConfigPath() . '/preComponentLoadHooks.yml';
         $objDataSet = \Cx\Core_Modules\Listing\Model\Entity\DataSet::load($filename, false);
         foreach ($objDataSet as $componentDefinition) {
             // check if componentController was already loaded in preInit
             if (array_key_exists($componentDefinition['name'], $this->preLoadedComponents)) {
                 $componentController = $this->preLoadedComponents[$componentDefinition['name']];
             } else {
                 $componentController = $this->getComponentControllerByNameAndType($componentDefinition['name'], $componentDefinition['type']);
                 $this->preLoadedComponents[$componentDefinition['name']] = $componentController;
             }
             $componentController->preComponentLoad();
         }
     } catch (\Cx\Core_Modules\Listing\Model\Entity\DataSetException $e) {
         throw new \Exception('Error in processing preComponentLoad-hooks: ' . $e->getMessage());
     }
 }
Example #4
0
 /**
  * Calls post-init hooks
  * Post-Init hooks are defined in /config/postInitHooks.yml.
  * 
  * @throws \Exception
  */
 protected function callPostInitHooks()
 {
     try {
         $filename = $this->getWebsiteConfigPath() . '/postInitHooks.yml';
         $objDataSet = \Cx\Core_Modules\Listing\Model\Entity\DataSet::load($filename);
         foreach ($objDataSet as $componentDefinition) {
             $this->eventManager->triggerEvent('preComponent', array('componentName' => $componentDefinition['name'], 'component' => null, 'hook' => 'postInit'));
             $componentController = $this->getComponentControllerByNameAndType($componentDefinition['name'], $componentDefinition['type']);
             $componentController->postInit($this);
             $this->eventManager->triggerEvent('postComponent', array('componentName' => $componentDefinition['name'], 'component' => null, 'hook' => 'postInit'));
         }
     } catch (\Cx\Core_Modules\Listing\Model\Entity\DataSetException $e) {
         throw new \Exception('Error in processing postInit-hooks: ' . $e->getMessage());
     }
 }
Example #5
0
 /**
  * Delete one or more records from the File   
  *
  * For maintenance/update purposes only.
  * At least one of the parameter values must be non-empty.
  * It will fail if both are empty.  Mind that in this case,
  * no records will be deleted.
  * Does {@see flush()} the currently loaded settings on success.
  * @param   string    $name     The optional setting name.
  *                              Defaults to null
  * @param   string    $group      The optional group.
  *                              Defaults to null
  * @return  boolean             True on success, false otherwise
  */
 function delete($name = null, $group = null)
 {
     // Fail if both parameter values are empty
     if (empty($name) && empty($group) && empty($this->section)) {
         return false;
     }
     $arrSetting = array();
     $objDataSet = \Cx\Core_Modules\Listing\Model\Entity\DataSet::load($this->filename);
     // if get blank or invalid file
     if (empty($objDataSet)) {
         return false;
     }
     foreach ($objDataSet as $value) {
         if ($value['group'] != $group && $value['name'] != $name) {
             $arrSetting[$value['name']] = $value;
         }
     }
     // if get blank array
     if (empty($arrSetting)) {
         return false;
     }
     $objDataSet = new \Cx\Core_Modules\Listing\Model\Entity\DataSet($arrSetting);
     $objDataSet->exportToFile(new \Cx\Core_Modules\Listing\Model\Entity\YamlInterface(), $this->filename);
     return true;
 }
 protected function loadData()
 {
     $entities = array();
     $repository = \Cx\Core_Modules\Listing\Model\Entity\DataSet::load($this->repositoryPath);
     if (!$repository->entryExists('meta')) {
         throw new YamlRepositoryException("Unable to load repository {$this->repositoryPath}. Repository is missing meta description!");
     }
     $meta = $repository->getEntry('meta');
     if ($repository->entryExists('data')) {
         foreach ($repository->getEntry('data') as $entity) {
             if (!$entity instanceof \Cx\Core\Model\Model\Entity\YamlEntity) {
                 throw new YamlRepositoryException("Unable to load repository {$this->repositoryPath}. Repository contains invalid entity: " . serialize($entity));
             }
             $id = $this->getIdentifierOfEntity($entity, $meta['identifier']);
             $entities[$id] = $entity;
         }
     }
     return array($meta, $entities);
 }