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 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(); }