/** * Searches the content and returns an array that is built as needed by the search module. * * @param string $searchTerm * * @return array */ public function searchResultsForSearchModule($searchTerm) { $em = \Env::get('cx')->getDb()->getEntityManager(); $pageRepo = $em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); // only list results in case the associated page of the module is active $page = $pageRepo->findOneBy(array('module' => 'MediaDir', 'lang' => FRONTEND_LANG_ID, 'type' => \Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION)); //If page is not exists or page is inactive then return empty result if (!$page || !$page->isActive()) { return array(); } //get the config site values \Cx\Core\Setting\Controller\Setting::init('Config', 'site', 'Yaml'); $coreListProtectedPages = \Cx\Core\Setting\Controller\Setting::getValue('coreListProtectedPages', 'Config'); $searchVisibleContentOnly = \Cx\Core\Setting\Controller\Setting::getValue('searchVisibleContentOnly', 'Config'); //get the config otherConfigurations value \Cx\Core\Setting\Controller\Setting::init('Config', 'otherConfigurations', 'Yaml'); $searchDescriptionLength = \Cx\Core\Setting\Controller\Setting::getValue('searchDescriptionLength', 'Config'); $hasPageAccess = true; $isNotVisible = $searchVisibleContentOnly == 'on' && !$page->isVisible(); if ($coreListProtectedPages == 'off' && $page->isFrontendProtected()) { $hasPageAccess = \Permission::checkAccess($page->getFrontendAccessId(), 'dynamic', true); } //If the page is invisible and frontend access is denied then return empty result if ($isNotVisible || !$hasPageAccess) { return array(); } //get the media directory entry by the search term $entries = new \Cx\Modules\MediaDir\Controller\MediaDirectoryEntry($this->moduleName); $entries->getEntries(null, null, null, $searchTerm); //if no entries found then return empty result if (empty($entries->arrEntries)) { return array(); } $results = array(); $formEntries = array(); $defaultEntries = null; $objForm = new \Cx\Modules\MediaDir\Controller\MediaDirectoryForm(null, $this->moduleName); $numOfEntries = intval($entries->arrSettings['settingsPagingNumEntries']); foreach ($entries->arrEntries as $entry) { $pageUrlResult = null; $entryForm = $objForm->arrForms[$entry['entryFormId']]; //Get the entry's link url //check the entry's form detail view exists if not, //check the entry's form overview exists if not, //check the default overview exists if not, dont show the corresponding entry in entry switch (true) { case $entries->checkPageCmd('detail' . $entry['entryFormId']): $pageUrlResult = \Cx\Core\Routing\Url::fromModuleAndCmd($entries->moduleName, 'detail' . $entry['entryFormId'], FRONTEND_LANG_ID, array('eid' => $entry['entryId'])); break; case $pageCmdExists = $entries->checkPageCmd($entryForm['formCmd']): case $entries->checkPageCmd(''): if ($pageCmdExists && !isset($formEntries[$entryForm['formCmd']])) { $formEntries[$entryForm['formCmd']] = new \Cx\Modules\MediaDir\Controller\MediaDirectoryEntry($entries->moduleName); $formEntries[$entryForm['formCmd']]->getEntries(null, null, null, null, null, null, 1, null, 'n', null, null, $entryForm['formId']); } if (!$pageCmdExists && !isset($defaultEntries)) { $defaultEntries = new \Cx\Modules\MediaDir\Controller\MediaDirectoryEntry($entries->moduleName); $defaultEntries->getEntries(); } //get entry's form overview / default page paging position $entriesPerPage = $numOfEntries; if ($pageCmdExists) { $entriesPerPage = !empty($entryForm['formEntriesPerPage']) ? $entryForm['formEntriesPerPage'] : $numOfEntries; } $pageCmd = $pageCmdExists ? $entryForm['formCmd'] : ''; $entryKeys = $pageCmdExists ? array_keys($formEntries[$entryForm['formCmd']]->arrEntries) : array_keys($defaultEntries->arrEntries); $entryPos = array_search($entry['entryId'], $entryKeys); $position = floor($entryPos / $entriesPerPage); $pageUrlResult = \Cx\Core\Routing\Url::fromModuleAndCmd($entries->moduleName, $pageCmd, FRONTEND_LANG_ID, array('pos' => $position * $entriesPerPage)); break; default: break; } //If page url is empty then dont show it in the result if (!$pageUrlResult) { continue; } //Get the search results title and content from the form context field 'title' and 'content' $title = current($entry['entryFields']); $content = ''; $objInputfields = new MediaDirectoryInputfield($entry['entryFormId'], false, $entry['entryTranslationStatus'], $this->moduleName); $inputFields = $objInputfields->getInputfields(); foreach ($inputFields as $arrInputfield) { $contextType = isset($arrInputfield['context_type']) ? $arrInputfield['context_type'] : ''; if (!in_array($contextType, array('title', 'content'))) { continue; } $strType = isset($arrInputfield['type_name']) ? $arrInputfield['type_name'] : ''; $strInputfieldClass = "\\Cx\\Modules\\MediaDir\\Model\\Entity\\MediaDirectoryInputfield" . ucfirst($strType); try { $objInputfield = safeNew($strInputfieldClass, $this->moduleName); $arrTranslationStatus = contrexx_input2int($arrInputfield['type_multi_lang']) == 1 ? $entry['entryTranslationStatus'] : null; $arrInputfieldContent = $objInputfield->getContent($entry['entryId'], $arrInputfield, $arrTranslationStatus); if (\Cx\Core\Core\Controller\Cx::instanciate()->getMode() == \Cx\Core\Core\Controller\Cx::MODE_FRONTEND && \Cx\Core\Setting\Controller\Setting::getValue('blockStatus', 'Config')) { $arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE'] = preg_replace('/\\[\\[(BLOCK_[A-Z0-9_-]+)\\]\\]/', '{\\1}', $arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE']); \Cx\Modules\Block\Controller\Block::setBlocks($arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE'], \Cx\Core\Core\Controller\Cx::instanciate()->getPage()); } } catch (\Exception $e) { \DBG::log($e->getMessage()); continue; } $inputFieldValue = $arrInputfieldContent[$this->moduleConstVar . '_INPUTFIELD_VALUE']; if (empty($inputFieldValue)) { continue; } if ($contextType == 'title') { $title = $inputFieldValue; } elseif ($contextType == 'content') { $content = \Cx\Core_Modules\Search\Controller\Search::shortenSearchContent($inputFieldValue, $searchDescriptionLength); } } $results[] = array('Score' => 100, 'Title' => html_entity_decode(contrexx_strip_tags($title), ENT_QUOTES, CONTREXX_CHARSET), 'Content' => $content, 'Link' => $pageUrlResult->toString()); } return $results; }
function deleteEntry($intEntryId) { global $_ARRAYLANG, $_CORELANG, $objDatabase; $objMail = new MediaDirectoryMail(5, $intEntryId, $this->moduleName); //delete entry $objDeleteEntry = $objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_entries WHERE `id`='" . intval($intEntryId) . "'"); if ($objDeleteEntry !== false) { //delete inputfields foreach ($this->getInputfields() as $key => $arrInputfield) { if ($arrInputfield['id'] != 1 && $arrInputfield['id'] != 2) { $strType = $arrInputfield['type_name']; $strInputfieldClass = "\\Cx\\Modules\\MediaDir\\Model\\Entity\\MediaDirectoryInputfield" . ucfirst($strType); try { $objInputfield = safeNew($strInputfieldClass, $this->moduleName); if (!$objInputfield->deleteContent(intval($intEntryId), intval($arrInputfield['id']))) { return false; } } catch (Exception $e) { echo "Error: " . $e->getMessage(); } } } //delete categories $objDeleteCategories = $objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_rel_entry_categories WHERE `entry_id`='" . intval($intEntryId) . "'"); //delete levels $objDeleteLevels = $objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_rel_entry_levels WHERE `entry_id`='" . intval($intEntryId) . "'"); } else { return false; } return true; }
function listPlaceholders($objTpl) { global $_ARRAYLANG, $_CORELANG, $objDatabase, $objTemplate; foreach ($this->arrInputfields as $key => $arrInputfield) { if ($arrInputfield['id'] != 1 && $arrInputfield['id'] != 2 && $arrInputfield['type'] != 16 && $arrInputfield['type'] != 18) { $strType = $arrInputfield['type_name']; $strInputfieldClass = "\\Cx\\Modules\\MediaDir\\Model\\Entity\\MediaDirectoryInputfield" . ucfirst($strType); try { $objInputfield = safeNew($strInputfieldClass, $this->moduleName); } catch (Exception $e) { echo "Error: " . $e->getMessage(); } $objTpl->setGlobalVariable(array($this->moduleLangVar . '_SETTINGS_INPUTFIELD_ID' => $arrInputfield['id'])); $arrPlaceholders = $objInputfield->arrPlaceholders; $strPlaceholders = null; foreach ($arrPlaceholders as $key => $strPlaceholder) { $strPlaceholders .= '[[' . strtoupper($strPlaceholder) . ']] '; } $strBlockDescription = str_replace('%i', $arrInputfield['name'][0], $_ARRAYLANG['TXT_MEDIADIR_SETTINGS_PLACEHOLDER_DESCRIPTION']); $objTpl->setVariable(array($this->moduleLangVar . '_SETTINGS_INPUTFIELD_DESCRIPTION' => $strBlockDescription, $this->moduleLangVar . '_SETTINGS_INPUTFIELD_PLACEHOLDERS' => $strPlaceholders)); $objTpl->parse($this->moduleNameLC . 'InputfieldPlaceholderList'); } } }
function showEntry() { global $_ARRAYLANG, $_CORELANG; $this->_objTpl->setTemplate($this->pageContent, true, true); //get ids $intCategoryId = isset($_GET['cid']) ? intval($_GET['cid']) : 0; $intLevelId = isset($_GET['lid']) ? intval($_GET['lid']) : 0; $intEntryId = isset($_GET['eid']) ? intval($_GET['eid']) : 0; // load source code if cmd value is integer if ($this->_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('MediaDir'); $page->setCmd('detail'); // load source code $applicationTemplate = \Cx\Core\Core\Controller\Cx::getContentTemplateOfPage($page); \LinkGenerator::parseTemplate($applicationTemplate); $this->_objTpl->addBlock('APPLICATION_DATA', 'application_data', $applicationTemplate); } //get navtree if ($this->_objTpl->blockExists($this->moduleNameLC . 'Navtree') && ($intCategoryId != 0 || $intLevelId != 0)) { $this->getNavtree($intCategoryId, $intLevelId); } if ($intEntryId != 0 && $this->_objTpl->blockExists($this->moduleNameLC . 'EntryList')) { $objEntry = new MediaDirectoryEntry($this->moduleName); $objEntry->getEntries($intEntryId, $intLevelId, $intCategoryId, null, null, null, 1, null, 1); $objEntry->listEntries($this->_objTpl, 2); $objEntry->updateHits($intEntryId); //set meta attributes $entries = new MediaDirectoryEntry($this->moduleName); $entries->getEntries($intEntryId, $intLevelId, $intCategoryId, null, null, null, 1, null, 1); $entry = $entries->arrEntries[$intEntryId]; $objInputfields = new MediaDirectoryInputfield($entry['entryFormId'], false, $entry['entryTranslationStatus'], $this->moduleName); $inputFields = $objInputfields->getInputfields(); $titleChanged = false; $contentChanged = false; foreach ($inputFields as $arrInputfield) { $contextType = isset($arrInputfield['context_type']) ? $arrInputfield['context_type'] : ''; if (!in_array($contextType, array('title', 'content', 'image'))) { continue; } $strType = isset($arrInputfield['type_name']) ? $arrInputfield['type_name'] : ''; $strInputfieldClass = "\\Cx\\Modules\\MediaDir\\Model\\Entity\\MediaDirectoryInputfield" . ucfirst($strType); try { $objInputfield = safeNew($strInputfieldClass, $this->moduleName); $arrTranslationStatus = contrexx_input2int($arrInputfield['type_multi_lang']) == 1 ? $entry['entryTranslationStatus'] : null; $arrInputfieldContent = $objInputfield->getContent($entry['entryId'], $arrInputfield, $arrTranslationStatus); switch ($contextType) { case 'title': $inputfieldValue = $arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE']; if ($inputfieldValue) { $this->metaTitle .= ' - ' . $inputfieldValue; $this->pageTitle = $inputfieldValue; } $titleChanged = true; break; case 'content': $inputfieldValue = $arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE']; if ($inputfieldValue) { $this->metaDescription = $inputfieldValue; } $contentChanged = true; break; case 'image': $inputfieldValue = $arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE_SRC']; if ($inputfieldValue) { $this->metaImage = $inputfieldValue; } break; default: break; } } catch (\Exception $e) { \DBG::log($e->getMessage()); continue; } } $firstInputfieldValue = $entries->arrEntries[$intEntryId]['entryFields'][0]; if (!$titleChanged && $firstInputfieldValue) { $this->pageTitle = $firstInputfieldValue; $this->metaTitle = $firstInputfieldValue; } if (!$contentChanged && $firstInputfieldValue) { $this->metaDescription = $firstInputfieldValue; } if (empty($objEntry->arrEntries)) { $this->_objTpl->hideBlock($this->moduleNameLC . 'EntryList'); $this->_objTpl->clearVariables(); header("Location: index.php?section=" . $this->moduleName); exit; } } else { header("Location: index.php?section=" . $this->moduleName); exit; } }