/**
  * The main processing method if this class
  *
  * @return string Information of the template status or the taken actions as HTML string
  */
 public function main()
 {
     $lang = $this->getLanguageService();
     $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_info.xlf');
     $this->pObj->MOD_MENU['includeTypoScriptFileContent'] = true;
     $e = $this->pObj->e;
     // Checking for more than one template an if, set a menu...
     $manyTemplatesMenu = $this->pObj->templateMenu();
     $template_uid = 0;
     if ($manyTemplatesMenu) {
         $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
     }
     // Initialize
     $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
     $tplRow = $GLOBALS['tplRow'];
     $saveId = 0;
     if ($existTemplate) {
         $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
     }
     // Create extension template
     $newId = $this->pObj->createTemplate($this->pObj->id, $saveId);
     if ($newId) {
         // Switch to new template
         $urlParameters = ['id' => $this->pObj->id, 'SET[templatesOnPage]' => $newId];
         $url = BackendUtility::getModuleUrl('web_ts', $urlParameters);
         HttpUtility::redirect($url);
     }
     $tce = null;
     $theOutput = '';
     if ($existTemplate) {
         // Update template ?
         $POST = GeneralUtility::_POST();
         if (isset($POST['_savedok']) || isset($POST['_saveandclosedok'])) {
             // Set the data to be saved
             $recData = array();
             $alternativeFileName = array();
             if (is_array($POST['data'])) {
                 foreach ($POST['data'] as $field => $val) {
                     switch ($field) {
                         case 'constants':
                         case 'config':
                             $recData['sys_template'][$saveId][$field] = $val;
                             break;
                     }
                 }
             }
             if (!empty($recData)) {
                 $recData['sys_template'][$saveId] = $this->processTemplateRowBeforeSaving($recData['sys_template'][$saveId]);
                 // Create new  tce-object
                 $tce = GeneralUtility::makeInstance(DataHandler::class);
                 $tce->alternativeFileName = $alternativeFileName;
                 // Initialize
                 $tce->start($recData, array());
                 // Saved the stuff
                 $tce->process_datamap();
                 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
                 $tce->clear_cacheCmd('all');
                 // tce were processed successfully
                 $this->tce_processed = true;
                 // re-read the template ...
                 $this->initialize_editor($this->pObj->id, $template_uid);
                 $tplRow = $GLOBALS['tplRow'];
                 // reload template menu
                 $manyTemplatesMenu = $this->pObj->templateMenu();
             }
         }
         // Hook post updating template/TCE processing
         if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook'])) {
             $postTCEProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook'];
             if (is_array($postTCEProcessingHook)) {
                 $hookParameters = array('POST' => $POST, 'tce' => $tce);
                 foreach ($postTCEProcessingHook as $hookFunction) {
                     GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
                 }
             }
         }
         $content = '<a href="#" class="t3-js-clickmenutrigger" data-table="sys_template" data-uid="' . $tplRow['uid'] . '" data-listframe="1">' . $this->iconFactory->getIconForRecord('sys_template', $tplRow, Icon::SIZE_SMALL)->render() . '</a><strong>' . htmlspecialchars($tplRow['title']) . '</strong>' . (trim($tplRow['sitetitle']) ? htmlspecialchars(' (' . $tplRow['sitetitle'] . ')') : '');
         $theOutput .= '<h2>' . $lang->getLL('templateInformation', true) . '</h2><div>' . $content . '</div>';
         if ($manyTemplatesMenu) {
             $theOutput .= '<div>' . $manyTemplatesMenu . '</div>';
         }
         $theOutput .= '<div style="padding-top: 10px;"></div>';
         $numberOfRows = 35;
         // If abort pressed, nothing should be edited:
         if (isset($POST['_saveandclosedok'])) {
             unset($e);
         }
         if (isset($e['constants'])) {
             $outCode = '<textarea name="data[constants]" rows="' . $numberOfRows . '" wrap="off" class="text-monospace enable-tab" style="width:98%;height:70%" class="text-monospace">' . htmlspecialchars($tplRow['constants']) . '</textarea>';
             $outCode .= '<input type="hidden" name="e[constants]" value="1">';
             // Display "Include TypoScript file content?" checkbox
             $outCode .= '<div class="checkbox"><label for="checkIncludeTypoScriptFileContent">' . BackendUtility::getFuncCheck($this->pObj->id, 'SET[includeTypoScriptFileContent]', $this->pObj->MOD_SETTINGS['includeTypoScriptFileContent'], '', '&e[constants]=1', 'id="checkIncludeTypoScriptFileContent"');
             $outCode .= $lang->getLL('includeTypoScriptFileContent') . '</label></div><br />';
             $theOutput .= '<div style="padding-top: 15px;"></div>';
             $theOutput .= '<h3>' . $lang->getLL('constants', true) . '</h3>';
             $theOutput .= $outCode;
         }
         if (isset($e['config'])) {
             $outCode = '<textarea name="data[config]" rows="' . $numberOfRows . '" wrap="off" class="text-monospace enable-tab" style="width:98%;height:70%" class="text-monospace">' . htmlspecialchars($tplRow['config']) . '</textarea>';
             $outCode .= '<input type="hidden" name="e[config]" value="1">';
             // Display "Include TypoScript file content?" checkbox
             $outCode .= '<div class="checkbox"><label for="checkIncludeTypoScriptFileContent">' . BackendUtility::getFuncCheck($this->pObj->id, 'SET[includeTypoScriptFileContent]', $this->pObj->MOD_SETTINGS['includeTypoScriptFileContent'], '', '&e[config]=1', 'id="checkIncludeTypoScriptFileContent"');
             $outCode .= $lang->getLL('includeTypoScriptFileContent') . '</label></div><br />';
             $theOutput .= '<div style="padding-top: 15px;"></div>';
             $theOutput .= '<h3>' . $lang->getLL('setup', true) . '</h3>';
             $theOutput .= $outCode;
         }
         // Processing:
         $outCode = '';
         $outCode .= $this->tableRow($lang->getLL('title'), htmlspecialchars($tplRow['title']), 'title', $tplRow['uid']);
         $outCode .= $this->tableRow($lang->getLL('sitetitle'), htmlspecialchars($tplRow['sitetitle']), 'sitetitle', $tplRow['uid']);
         $outCode .= $this->tableRow($lang->getLL('description'), nl2br(htmlspecialchars($tplRow['description'])), 'description', $tplRow['uid']);
         $outCode .= $this->tableRow($lang->getLL('constants'), sprintf($lang->getLL('editToView'), trim($tplRow['constants']) ? count(explode(LF, $tplRow['constants'])) : 0), 'constants', $tplRow['uid']);
         $outCode .= $this->tableRow($lang->getLL('setup'), sprintf($lang->getLL('editToView'), trim($tplRow['config']) ? count(explode(LF, $tplRow['config'])) : 0), 'config', $tplRow['uid']);
         $outCode = '<div class="table-fit"><table class="table table-striped table-hover">' . $outCode . '</table></div>';
         // Edit all icon:
         $urlParameters = ['edit' => ['sys_template' => [$tplRow['uid'] => 'edit']], 'createExtension' => 0, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')];
         $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
         $title = $lang->getLL('editTemplateRecord', true);
         $icon = $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render();
         $outCode .= '<br /><a class="btn btn-default" href="' . htmlspecialchars($url) . '"><strong>' . $icon . '&nbsp;' . $title . '</strong></a>';
         $theOutput .= '<div>' . $outCode . '</div>';
         // hook	after compiling the output
         if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'])) {
             $postOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'];
             if (is_array($postOutputProcessingHook)) {
                 $hookParameters = array('theOutput' => &$theOutput, 'POST' => $POST, 'e' => $e, 'tplRow' => $tplRow, 'numberOfRows' => $numberOfRows);
                 foreach ($postOutputProcessingHook as $hookFunction) {
                     GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
                 }
             }
         }
     } else {
         $theOutput .= $this->pObj->noTemplate(1);
     }
     return $theOutput;
 }
 /**
  * Main
  *
  * @return string
  */
 public function main()
 {
     $lang = $this->getLanguageService();
     $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf');
     $theOutput = '';
     // Create extension template
     $this->pObj->createTemplate($this->pObj->id);
     // Checking for more than one template an if, set a menu...
     $manyTemplatesMenu = $this->pObj->templateMenu();
     $template_uid = 0;
     if ($manyTemplatesMenu) {
         $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
     }
     // initialize
     $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
     if ($existTemplate) {
         $templateService = $this->getExtendedTemplateService();
         $tplRow = $this->getTemplateRow();
         $theConstants = $this->getConstants();
         $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Tstemplate/ConstantEditor');
         $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
         // Update template ?
         if (GeneralUtility::_POST('_savedok')) {
             $templateService->changed = 0;
             $templateService->ext_procesInput(GeneralUtility::_POST(), array(), $theConstants, $tplRow);
             if ($templateService->changed) {
                 // Set the data to be saved
                 $recData = array();
                 $recData['sys_template'][$saveId]['constants'] = implode($templateService->raw, LF);
                 // Create new  tce-object
                 $tce = GeneralUtility::makeInstance(DataHandler::class);
                 $tce->stripslashes_values = false;
                 $tce->start($recData, array());
                 $tce->process_datamap();
                 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
                 $tce->clear_cacheCmd('all');
                 // re-read the template ...
                 $this->initialize_editor($this->pObj->id, $template_uid);
                 // re-read the constants as they have changed
                 $templateService = $this->getExtendedTemplateService();
                 $tplRow = $this->getTemplateRow();
                 $theConstants = $this->getConstants();
             }
         }
         // Resetting the menu (start). I wonder if this in any way is a violation of the menu-system. Haven't checked. But need to do it here, because the menu is dependent on the categories available.
         $this->pObj->MOD_MENU['constant_editor_cat'] = $templateService->ext_getCategoryLabelArray();
         $this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
         // Resetting the menu (stop)
         $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
         $content = $iconFactory->getIconForRecord('sys_template', $tplRow, Icon::SIZE_SMALL)->render() . '<strong>' . $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants') . '</strong>' . (trim($tplRow['sitetitle']) ? htmlspecialchars(' (' . $tplRow['sitetitle'] . ')') : '');
         $theOutput .= $this->pObj->doc->section($lang->getLL('editConstants', true), $content, false, true);
         if ($manyTemplatesMenu) {
             $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
         }
         $theOutput .= '<div style="padding-top: 10px;"></div>';
         if (!empty($this->pObj->MOD_MENU['constant_editor_cat'])) {
             $menu = '<div class="form-inline form-inline-spaced">';
             $menu .= BackendUtility::getDropdownMenu($this->pObj->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
             $menu .= '</div>';
             $theOutput .= $this->pObj->doc->section($lang->getLL('category', true), '<span class="text-nowrap">' . $menu . '</span>', false);
         } else {
             $theOutput .= $this->pObj->doc->section($lang->getLL('noConstants', true), $lang->getLL('noConstantsDescription', true), false, false, 1);
         }
         $theOutput .= '<div style="padding-top: 15px;"></div>';
         // Category and constant editor config:
         $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
         $templateService->ext_getTSCE_config($category);
         $printFields = trim($templateService->ext_printFields($theConstants, $category));
         if ($printFields) {
             $theOutput .= $this->pObj->doc->section('', $printFields);
         }
         $BE_USER_modOptions = BackendUtility::getModTSconfig(0, 'mod.' . $this->pObj->MCONF['name']);
         if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
             $theOutput = $this->displayExample($theOutput);
         }
     } else {
         $theOutput .= $this->pObj->noTemplate(1);
     }
     return $theOutput;
 }
Ejemplo n.º 3
0
 /**
  * Main
  *
  * @return string
  */
 public function main()
 {
     $assigns = [];
     $assigns['LLPrefix'] = 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:';
     // Create extension template
     $this->pObj->createTemplate($this->pObj->id);
     // Checking for more than one template an if, set a menu...
     $manyTemplatesMenu = $this->pObj->templateMenu();
     $template_uid = 0;
     if ($manyTemplatesMenu) {
         $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
     }
     // initialize
     $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
     if ($existTemplate) {
         $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
         $assigns['templateRecord'] = $this->templateRow;
         if ($manyTemplatesMenu) {
             $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
         }
         $this->getPageRenderer();
         $saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid'];
         // Update template ?
         if (GeneralUtility::_POST('_savedok')) {
             $this->templateService->changed = 0;
             $this->templateService->ext_procesInput(GeneralUtility::_POST(), [], $this->constants, $this->templateRow);
             if ($this->templateService->changed) {
                 // Set the data to be saved
                 $recData = [];
                 $recData['sys_template'][$saveId]['constants'] = implode($this->templateService->raw, LF);
                 // Create new  tce-object
                 $tce = GeneralUtility::makeInstance(DataHandler::class);
                 $tce->start($recData, []);
                 $tce->process_datamap();
                 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
                 $tce->clear_cacheCmd('all');
                 // re-read the template ...
                 // re-read the constants as they have changed
                 $this->initialize_editor($this->pObj->id, $template_uid);
             }
         }
         // Resetting the menu (start). I wonder if this in any way is a violation of the menu-system. Haven't checked. But need to do it here, because the menu is dependent on the categories available.
         $this->pObj->MOD_MENU['constant_editor_cat'] = $this->templateService->ext_getCategoryLabelArray();
         $this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
         // Resetting the menu (stop)
         $assigns['title'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title'], 'constants');
         if (!empty($this->pObj->MOD_MENU['constant_editor_cat'])) {
             $assigns['constantsMenu'] = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
         }
         // Category and constant editor config:
         $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
         $this->templateService->ext_getTSCE_config($category);
         $printFields = trim($this->templateService->ext_printFields($this->constants, $category));
         foreach ($this->templateService->getInlineJavaScript() as $name => $inlineJavaScript) {
             $this->pageRenderer->addJsInlineCode($name, $inlineJavaScript);
         }
         if ($printFields) {
             $assigns['printFields'] = $printFields;
         }
         $BE_USER_modOptions = BackendUtility::getModTSconfig(0, 'mod.' . $this->pObj->MCONF['name']);
         if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
             $assigns['helpConfig'] = $this->getHelpConfig();
         }
         // Rendering of the output via fluid
         $view = GeneralUtility::makeInstance(StandaloneView::class);
         $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:tstemplate/Resources/Private/Templates/ConstantEditor.html'));
         $view->assignMultiple($assigns);
         $theOutput = $view->render();
     } else {
         $theOutput = $this->pObj->noTemplate(1);
     }
     return $theOutput;
 }