/** * action list * * @return void */ public function listAction() { $terms = 'character' === $this->settings['listmode'] ? $this->termRepository->findAllGroupedByFirstCharacter() : $this->termRepository->findAll(); $this->view->assign('detailPage', $this->settings['detailPage']); $this->view->assign('listmode', $this->settings['listmode']); $this->view->assign('terms', $terms); }
/** * Main function called by hook 'contentPostProc-all' * * @return void */ public function contentParser() { // extract Pids which should be parsed $parsingPids = GeneralUtility::trimExplode(',', $this->settings['parsingPids']); // extract Pids which should NOT be parsed $excludePids = GeneralUtility::trimExplode(',', $this->settings['parsingExcludePidList']); // Get Tags which content should be parsed $tags = GeneralUtility::trimExplode(',', $this->settings['parsingTags']); // Remove "a" from parsingTags if it was added unknowingly if (TRUE === in_array('a', $tags)) { $tags = array_diff($tags, array('a')); } /* * Abort if: * - Parsing tags are empty * - Page type is not 0 * - tsConfig is empty * - no storagePid is set * - parsingPids doesn't contains 0 and * + current page is excluded * + current page is not whitelisted * - current page is the glossary detailpage * - current page is the glossary listpage */ if (TRUE === empty($tags) || 0 !== $GLOBALS['TSFE']->type || TRUE === empty($this->tsConfig) || TRUE === empty($this->tsConfig['persistence.']['storagePid']) || FALSE === in_array('0', $parsingPids) && (TRUE === in_array($GLOBALS['TSFE']->id, $excludePids) || FALSE === in_array($GLOBALS['TSFE']->id, $parsingPids)) || $GLOBALS['TSFE']->id === intval($this->settings['detailPage']) || $GLOBALS['TSFE']->id === intval($this->settings['listPage'])) { return; } // Get max number of replacements per page and term $this->maxReplacementPerPage = (int) $this->settings['maxReplacementPerPage']; // Tags which are not allowed as direct parent for a parsingTag $forbiddenParentTags = array_filter(GeneralUtility::trimExplode(',', $this->settings['forbiddenParentTags'])); // Add "a" if unknowingly deleted to prevent errors if (FALSE === in_array('a', $forbiddenParentTags)) { $forbiddenParentTags[] = 'a'; } //Find all terms $this->terms = $terms = $this->termRepository->findByNameLength(); //Create new DOMDocument $DOM = new \DOMDocument(); // Prevent crashes caused by HTML5 entities with internal errors libxml_use_internal_errors(true); // Load Page HTML in DOM and check if HTML is valid else abort // use XHTML tag for avoiding UTF-8 encoding problems if (FALSE === $DOM->loadHTML('<?xml encoding="UTF-8">' . $GLOBALS['TSFE']->content)) { return; } // remove unnecessary whitespaces in nodes (no visible whitespace) $DOM->preserveWhiteSpace = false; /** @var \DOMElement $DOMBody */ $DOMBody = $DOM->getElementsByTagName('body')->item(0); // iterate over tags which are defined to be parsed foreach ($tags as $tag) { // extract the tags $DOMTags = $DOMBody->getElementsByTagName($tag); // call the nodereplacer for each node to parse its content /** @var \DOMNode $DOMTag */ foreach ($DOMTags as $DOMTag) { // get parent tags from root tree string $parentTags = explode('/', preg_replace('#\\[([^\\]]*)\\]#i', '', substr($DOMTag->parentNode->getNodePath(), 1))); // check if element is children of a forbidden parent if (FALSE === in_array($parentTags, $forbiddenParentTags)) { $this->nodeReplacer($DOMTag); } } } // set the parsed html page and remove XHTML tag which is not needed anymore $GLOBALS['TSFE']->content = str_replace('<?xml encoding="UTF-8">', '', $DOM->saveHTML()); }