public function rebuild($strContent, $arrData, $arrSet) { global $objPage; $time = \Input::get('time'); $this->import('Database'); $this->Database->prepare("UPDATE tl_page SET glossar = NULL, fallback_glossar = NULL,glossar_time = ? WHERE glossar_time != ?")->execute($time, $time); if (isset($GLOBALS['TL_HOOKS']['clearGlossar']) && is_array($GLOBALS['TL_HOOKS']['clearGlossar'])) { foreach ($GLOBALS['TL_HOOKS']['clearGlossar'] as $type => $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1](\Input::get('time')); } } if (\Config::get('activateGlossarTags') == 1) { if (isset($GLOBALS['TL_HOOKS']['beforeGlossarTags']) && is_array($GLOBALS['TL_HOOKS']['beforeGlossarTags'])) { foreach ($GLOBALS['TL_HOOKS']['beforeGlossarTags'] as $type => $callback) { $this->import($callback[0]); $strContent = $this->{$callback}[0]->{$callback}[1]($strContent, $strTemplate); } } // Strip non-indexable areas while (($intStart = strpos($strContent, '<!-- glossar::stop -->')) !== false) { if (($intEnd = strpos($strContent, '<!-- glossar::continue -->', $intStart)) !== false) { $intCurrent = $intStart; // Handle nested tags while (($intNested = strpos($strContent, '<!-- glossar::stop -->', $intCurrent + 22)) !== false && $intNested < $intEnd) { if (($intNewEnd = strpos($strContent, '<!-- glossar::continue -->', $intEnd + 26)) !== false) { $intEnd = $intNewEnd; $intCurrent = $intNested; } else { break; } } $strContent = substr($strContent, 0, $intStart) . substr($strContent, $intEnd + 26); } else { break; } } if (isset($GLOBALS['TL_HOOKS']['afterGlossarTags']) && is_array($GLOBALS['TL_HOOKS']['afterGlossarTags'])) { foreach ($GLOBALS['TL_HOOKS']['afterGlossarTags'] as $type => $callback) { $this->import($callback[0]); $strContent = $this->{$callback}[0]->{$callback}[1]($strContent, $strTemplate); } } } if (!isset($_GET['items']) && \Config::get('useAutoItem') && isset($_GET['auto_item'])) { \Input::setGet('items', \Input::get('auto_item')); } $Glossar = \GlossarModel::findAll(); if (empty($Glossar)) { $this->clearGlossar(); return; } $arrGlossar = array(); while ($Glossar->next()) { $arrGlossar[$Glossar->id] = $Glossar->language; } $Term = \SwGlossarModel::findAll(array('order' => ' CHAR_LENGTH(title) DESC')); if (empty($Term)) { $this->clearGlossar(); return; } $arrTerms = array('glossar' => array(), 'fallback' => array(), 'both' => array()); while ($Term->next()) { if ($arrGlossar[$Term->pid] == $objPage->language) { $arrTerms['glossar'][] = $Term->title; } else { $arrTerms['fallback'][] = $Term->title; } $arrTerms['both'][] = $Term->title; } foreach ($arrTerms as &$pointer_terms) { $pointer_terms = array_unique($pointer_terms); } // HOOK: take additional pages if (isset($GLOBALS['TL_HOOKS']['cacheGlossarTerms']) && is_array($GLOBALS['TL_HOOKS']['cacheGlossarTerms'])) { foreach ($GLOBALS['TL_HOOKS']['cacheGlossarTerms'] as $type => $callback) { if (\Input::get('rebuild_' . $type . '_glossar') == '1') { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1](\Input::get('items'), $arrTerms, $strContent, $type); } } } if (\Input::get('rebuild_regular_glossar') == 1) { $strFallback = $strGlossar = ''; if (!empty($arrTerms['glossar'])) { $matches = array(); foreach ($arrTerms['glossar'] as $key => $term) { if (preg_match('#' . $term . '#is', $strContent)) { $matches[] = $term; } } $matches = array_unique(array_map("strtolower", $matches[0])); $strGlossar = implode('|', $matches); } if (!empty($arrTerms['fallback'])) { $matches = array(); foreach ($arrTerms['fallback'] as $key => $term) { if (preg_match('#' . $term . '#is', $strContent)) { $matches[] = $term; } } $matches = array_unique(array_map("strtolower", $matches[0])); $strFallback = implode('|', $matches); } $this->Database->prepare("UPDATE tl_page SET glossar = ?, fallback_glossar = ?,glossar_time = ? WHERE id = ?")->execute($strGlossar, $strFallback, $time, $objPage->id); } }
public function compile() { global $objPage; $this->loadLanguageFile('glossar_errors'); $glossarErrors = array(); if (!$this->sortGlossarBy) { $this->sortGlossarBy = 'alias'; } $this->sortGlossarBy = explode('_', $this->sortGlossarBy); $this->sortGlossarBy = $this->sortGlossarBy[0] . ($this->sortGlossarBy[1] ? ' ' . strtoupper($this->sortGlossarBy[1]) : ''); if (\Input::get('items') == '') { if (empty($this->glossar)) { $Glossar = \SwGlossarModel::findAll(array('order' => $this->sortGlossarBy)); } else { $Glossar = \SwGlossarModel::findByPid($this->glossar, array('order' => $this->sortGlossarBy)); } } else { $Glossar = \SwGlossarModel::findByAlias(\Input::get('items'), array(), array('order' => $this->sortGlossarBy)); } /* Gefundene Begriffe durch Links zum Glossar ersetzen */ $arrGlossar = array(); $filledLetters = array(); if ($Glossar) { while ($Glossar->next()) { $initial = substr($Glossar->alias, 0, 1); $filledLetters[] = $initial; if (\Input::get('items') != '' || (!$this->showAfterChoose || !$this->addAlphaPagination) || $this->addAlphaPagination && $this->showAfterChoose && \Input::get('pag') != '') { if (\Input::get('pag') == '' || $initial == \Input::get('pag')) { $newGlossarObj = new \FrontendTemplate('glossar_default'); $newGlossarObj->setData($Glossar->row()); if (\Input::get('items') != '') { $newGlossarObj->teaser = null; } $link = null; $Content = \ContentModel::findPublishedByPidAndTable($newGlossarObj->id, 'tl_sw_glossar'); if (!empty($Content)) { if (!$newGlossarObj->jumpTo) { $newGlossarObj->jumpTo = $GLOBALS['TL_CONFIG']['jumpToGlossar']; } if ($newGlossarObj->jumpTo) { $link = \PageModel::findByPk($newGlossarObj->jumpTo); } if ($link) { $newGlossarObj->link = $this->generateFrontendUrl($link->row(), ($GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/' : '/items/') . $newGlossarObj->alias); } } else { $newGlossarObj->link = false; } if (\Input::get('items') == '') { $arrGlossar[] = $newGlossarObj->parse(); } else { $elements = $this->getGlossarElements($newGlossarObj->id); if (empty($elements) && $Glossar->description) { $descriptionObj = new \FrontendTemplate('glossar_description'); $descriptionObj->content = $Glossar->description; $elements = array($descriptionObj->parse()); } $arrGlossar[] = $elements; } } } } } $letters = array(); if ($this->addAlphaPagination) { for ($c = 65; $c <= 90; $c++) { if ($this->addOnlyTrueLinks && in_array(strtolower(chr($c)), $filledLetters) || !$this->addOnlyTrueLinks) { $letters[] = array('href' => $this->addToUrl('pag=' . strtolower(chr($c)) . '&alpha=&items=&auto_item='), 'initial' => chr($c), 'active' => \Input::get('pag') == strtolower(chr($c)), 'trueLink' => in_array(strtolower(chr($c)), $filledLetters) && !$this->addOnlyTrueLinks); } } } $objPagination = new \FrontendTemplate('glossar_pagination'); if ($objPage) { $objPagination->showAllHref = $this->generateFrontendUrl($objPage->row()); $objPagination->showAllLabel = $GLOBALS['TL_LANG']['glossar']['showAllLabel']; $objPagination->alphaPagination = $letters; $strAlphaPagination = $objPagination->parse(); } $this->Template->alphaPagination = $strAlphaPagination; if (\Input::get('items') != '' || (!$this->showAfterChoose || !$this->addAlphaPagination) || $this->addAlphaPagination && $this->showAfterChoose && \Input::get('pag') != '') { if (!$arrGlossar && $GLOBALS['glossar']['errors']['no_content']) { $glossarErrors[] = $GLOBALS['glossar']['errors']['no_content']; } } $termAsHeadline = false; if (\Input::get('items') != '') { if (($this->termAsHeadline || \Config::get('termAsHeadline')) && !$Glossar->termAsHeadline) { $Headline = new \StdModel(); $Headline->headline = serialize(array('value' => $Glossar->title, 'unit' => $this->headlineUnit)); // $Headline->cssID = serialize(array('','glossar_headline')); $Headline->type = 'glossar_headline'; $objHeadline = new \ContentHeadline($Headline); $termAsHeadline = $objHeadline->generate(); } $this->Template->termAsHeadline = $termAsHeadline; $this->Template->content = 1; $arrGlossar = array_shift($arrGlossar); } $this->Template->ppos = $this->paginationPosition; $this->Template->glossar = $arrGlossar; if ($glossarErrors) { $errorObj = new \FrontendTemplate('glossar_error'); $errorObj->msg = $glossarErrors; $this->Template->errors = $errorObj->parse(); } }
public function exportGlossar() { $objGlossar = new \BackendTemplate('be_glossar_export'); $objGlossar->setData(array('lickey' => true, 'headline' => 'Export', 'glossarMessage' => '', 'glossarSubmit' => 'Export', 'glossarLabel' => 'Format wählen', 'glossarHelp' => 'Bitte wählen Sie das Format aus, mit der der Exporter Ihre Einträge exportieren soll.', 'action' => ampersand(\Environment::get('request'), true))); $lickey = $this->checkLizenz(); if ($lickey) { $objGlossar->lickey = false; return $objGlossar->parse(); } if (\Input::get('glossar_export') != '') { $JSON = array(); $id = \Input::get('id'); $Glossar = \GlossarModel::findAll(); $arrGlossar = array(); if (!empty($Glossar)) { while ($Glossar->next()) { if (empty($id) || $Glossar->id == $id) { $arrGlossar[] = $Glossar->id; $JSON[$Glossar->alias] = array('tl_glossar' => $Glossar->row()); } } $Term = \SwGlossarModel::findByPids($arrGlossar); if (!empty($Term)) { $arrTerms = array(); $term = null; while ($Term->next()) { $arrTerms[] = $Term->id; foreach ($JSON as $key => $glossar) { if ($glossar['tl_glossar']['id'] == $Term->pid) { $JSON[$key]['tl_glossar']['tl_sw_glossar'][] = $Term->row(); } } } $Content = \GlossarContentModel::findByPidsAndTable($arrTerms, 'tl_sw_glossar', \Input::get('glossar_export')); if (!empty($Content)) { while ($Content->next()) { foreach ($JSON as $key => $glossar) { foreach ($glossar['tl_glossar']['tl_sw_glossar'] as $term => $tdata) { if ($tdata['id'] == $Content->pid) { $JSON[$key]['tl_glossar']['tl_sw_glossar'][$term]['tl_content'][] = $Content->row(); } } } } } } } $JSON = $this->encode_array($this->cleanArray($JSON)); $title = $Glossar->alias; if (!$id) { $title = 'complete'; } header("Content-type: application/download"); header('Content-Disposition: attachment; filename="glossar_' . $title . '.json"'); echo json_encode($JSON); die; } return $objGlossar->parse(); }