diff --git a/config/config.php b/config/config.php index 67a86065..b51ed238 100644 --- a/config/config.php +++ b/config/config.php @@ -1,6 +1,6 @@ blnCore) { - $arrReturn['operations'] = ''; - return $arrReturn; } diff --git a/library/alnv/CatalogFieldBuilder.php b/library/alnv/CatalogFieldBuilder.php index 336c4472..22d03847 100644 --- a/library/alnv/CatalogFieldBuilder.php +++ b/library/alnv/CatalogFieldBuilder.php @@ -634,7 +634,7 @@ protected function getCoreFields($blnDcFormat) $arrReturn[$strFieldname]['fileType'] = $strFileType; $arrReturn[$strFieldname]['extensions'] = $strExtensions; - $arrReturn[$strFieldname]['filesOnly'] = $arrField['eval']['filesOnly'] ? '1' : ''; + $arrReturn[$strFieldname]['filesOnly'] = ($arrField['eval']['filesOnly']??'') ? '1' : ''; } } } diff --git a/library/alnv/FrontendEditing.php b/library/alnv/FrontendEditing.php index 7b9ac377..00ad8e6e 100644 --- a/library/alnv/FrontendEditing.php +++ b/library/alnv/FrontendEditing.php @@ -2,7 +2,8 @@ namespace CatalogManager; -class FrontendEditing extends CatalogController { +class FrontendEditing extends CatalogController +{ public $strAct = ''; @@ -26,7 +27,8 @@ class FrontendEditing extends CatalogController { protected $arrValidFormTemplates = []; - public function __construct() { + public function __construct() + { parent::__construct(); @@ -40,12 +42,13 @@ public function __construct() { } - public function initialize() { + public function initialize() + { global $objPage; $this->setOptions(); - + \System::loadLanguageFile('catalog_manager'); $strPalette = 'general_legend'; @@ -56,21 +59,21 @@ public function initialize() { $this->catalogItemOperations = Toolkit::deserialize($this->catalogItemOperations); $this->catalogExcludedFields = Toolkit::deserialize($this->catalogExcludedFields); - $this->CatalogFieldBuilder->initialize( $this->catalogTablename); + $this->CatalogFieldBuilder->initialize($this->catalogTablename); $this->arrCatalog = $this->CatalogFieldBuilder->getCatalog(); $arrCatalogFields = $this->CatalogFieldBuilder->getCatalogFields(true, $this); - if ( !empty($arrCatalogFields) && is_array($arrCatalogFields)) { + if (!empty($arrCatalogFields) && is_array($arrCatalogFields)) { foreach ($arrCatalogFields as $arrField) { - $strPalette = isset($arrField['_palette']) && $arrField['_palette'] && !in_array( $arrField['fieldname'], $this->catalogExcludedFields ) ? $arrField['_palette'] : $strPalette; + $strPalette = isset($arrField['_palette']) && $arrField['_palette'] && !in_array($arrField['fieldname'], $this->catalogExcludedFields) ? $arrField['_palette'] : $strPalette; if (isset($arrField['type']) && $arrField['type'] == 'fieldsetStart') { $strPalette = $arrField['title']; - $this->arrPaletteLabels[ $strPalette ] = $this->I18nCatalogTranslator->get( 'legend', $arrField['title'], [ 'title' => $arrField['label'] ] ); + $this->arrPaletteLabels[$strPalette] = $this->I18nCatalogTranslator->get('legend', $arrField['title'], ['title' => $arrField['label']]); } $arrField['_palette'] = $strPalette; @@ -78,106 +81,101 @@ public function initialize() { if (Toolkit::isEmpty($arrField['type'])) continue; if (Toolkit::isEmpty($arrField['fieldname']) || !Toolkit::isDcConformField($arrField)) continue; - if ( $arrField['type'] == 'hidden' ) $arrField['_dcFormat']['inputType'] = 'hidden'; + if ($arrField['type'] == 'hidden') $arrField['_dcFormat']['inputType'] = 'hidden'; - if ( $arrField['type'] == 'upload' && $arrField['useFineUploader'] ) { + if ($arrField['type'] == 'upload' && $arrField['useFineUploader']) { $arrField['_dcFormat']['inputType'] = 'catalogFineUploader'; $this->CatalogFineUploader->loadAssets(); } - $this->arrCatalogFields[ $arrField['fieldname'] ] = $arrField; + $this->arrCatalogFields[$arrField['fieldname']] = $arrField; } } - if ( $this->strItemID && $this->strAct && in_array( $this->strAct, [ 'copy', 'edit', 'pdf', 'delete' ] ) ) { + if ($this->strItemID && $this->strAct && in_array($this->strAct, ['copy', 'edit', 'pdf', 'delete'])) { $this->setValues(); } - $this->arrPaletteLabels['general_legend'] = $this->I18nCatalogTranslator->get( 'legend', 'general_legend' ); - $this->arrPaletteLabels['invisible_legend'] = $this->I18nCatalogTranslator->get( 'legend', 'invisible_legend' ); + $this->arrPaletteLabels['general_legend'] = $this->I18nCatalogTranslator->get('legend', 'general_legend'); + $this->arrPaletteLabels['invisible_legend'] = $this->I18nCatalogTranslator->get('legend', 'invisible_legend'); $this->setCatalogAttributes(); $this->setPalettes(); - if ( $this->catalogFormRedirect && $this->catalogFormRedirect !== '0' ) { - + if ($this->catalogFormRedirect && $this->catalogFormRedirect !== '0') { $this->strRedirectID = $this->catalogFormRedirect; - } - - else { - + } else { $this->strRedirectID = $objPage->id; } - if ( isset( $GLOBALS['TL_HOOKS']['catalogManagerInitializeFrontendEditing'] ) && is_array( $GLOBALS['TL_HOOKS']['catalogManagerInitializeFrontendEditing'] ) ) { - - foreach ( $GLOBALS['TL_HOOKS']['catalogManagerInitializeFrontendEditing'] as $callback ) { - - $this->import( $callback[0] ); - $this->{$callback[0]}->{$callback[1]}( $this->catalogTablename, $this->arrCatalog, $this->arrCatalogFields, $this->arrValues, $this ); + if (isset($GLOBALS['TL_HOOKS']['catalogManagerInitializeFrontendEditing']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerInitializeFrontendEditing'])) { + foreach ($GLOBALS['TL_HOOKS']['catalogManagerInitializeFrontendEditing'] as $callback) { + $this->import($callback[0]); + $this->{$callback[0]}->{$callback[1]}($this->catalogTablename, $this->arrCatalog, $this->arrCatalogFields, $this->arrValues, $this); } } } - public function render() { + public function render() + { - $this->objTemplate = new \FrontendTemplate( $this->strTemplate ); - $this->objTemplate->setData( $this->arrOptions ); + $this->objTemplate = new \FrontendTemplate($this->strTemplate); + $this->objTemplate->setData($this->arrOptions); $arrCategories = []; - if ( !is_array( $this->catalogExcludedFields ) ) { + if (!is_array($this->catalogExcludedFields)) { $this->catalogExcludedFields = []; } - if ( !empty( $this->arrPalettes ) && is_array( $this->arrPalettes ) ) { + if (!empty($this->arrPalettes) && is_array($this->arrPalettes)) { - foreach ( $this->arrPalettes as $strPalette => $arrFieldNames ) { + foreach ($this->arrPalettes as $strPalette => $arrFieldNames) { - if ( !empty( $arrFieldNames ) && is_array( $arrFieldNames ) ) { + if (!empty($arrFieldNames) && is_array($arrFieldNames)) { - $strLegend = $this->arrPaletteLabels[ $strPalette ]; - $arrCategories[ $strLegend ] = $this->renderFieldsByPalette( $arrFieldNames, $strPalette ); + $strLegend = $this->arrPaletteLabels[$strPalette]; + $arrCategories[$strLegend] = $this->renderFieldsByPalette($arrFieldNames, $strPalette); } } } - if ( !$this->disableCaptcha ) { + if (!$this->disableCaptcha) { $objCaptcha = $this->getCaptcha(); $this->objTemplate->captchaWidget = $objCaptcha->parse(); } - if ( !$this->blnNoSubmit && \Input::post('FORM_DELETE_IMAGE' ) ) { + if (!$this->blnNoSubmit && \Input::post('FORM_DELETE_IMAGE')) { $this->deleteImage(); } - if ( !$this->blnNoSubmit && \Input::post('FORM_SUBMIT') == $this->strFormId ) { + if (!$this->blnNoSubmit && \Input::post('FORM_SUBMIT') == $this->strFormId) { $this->saveEntity(); } - if ( \Input::post('FORM_SUBMIT_BACK') == $this->strFormId ) { + if (\Input::post('FORM_SUBMIT_BACK') == $this->strFormId) { global $objPage; - if ( !$this->catalogFrontendEditingViewPage ) { + if (!$this->catalogFrontendEditingViewPage) { $this->catalogFrontendEditingViewPage = $objPage->id; } $strQuery = ''; - if ( \Input::get( 'pid' ) ) { + if (\Input::get('pid')) { - $strQuery .= '?pid=' . \Input::get( 'pid' ); + $strQuery .= '?pid=' . \Input::get('pid'); } - $this->redirectAfterInsertion( $this->catalogFrontendEditingViewPage, $strQuery ); + $this->redirectAfterInsertion($this->catalogFrontendEditingViewPage, $strQuery); } $this->objTemplate->method = 'POST'; @@ -197,20 +195,21 @@ public function render() { } - protected function deleteImage() { + protected function deleteImage() + { - $this->import( 'SQLBuilder' ); + $this->import('SQLBuilder'); $strTempUuid = ''; - $strFieldname = \Input::post('FORM_DELETE_IMAGE' ); + $strFieldname = \Input::post('FORM_DELETE_IMAGE'); - if ( $strFieldname && isset( $this->arrValues[ $strFieldname ] ) ) { + if ($strFieldname && isset($this->arrValues[$strFieldname])) { - $strTempUuid = $this->arrValues[ $strFieldname ]; - $this->arrValues[ $strFieldname ] = ''; + $strTempUuid = $this->arrValues[$strFieldname]; + $this->arrValues[$strFieldname] = ''; } - switch ( $this->strAct ) { + switch ($this->strAct) { case 'create': @@ -221,14 +220,14 @@ protected function deleteImage() { case 'copy': case 'edit': - $this->SQLBuilder->Database->prepare( sprintf( 'UPDATE %s SET %s = "" WHERE id = ?', $this->catalogTablename, $strFieldname ) )->execute( $this->strItemID ); - $objFile = \FilesModel::findByUuid( $strTempUuid ); + $this->SQLBuilder->Database->prepare(sprintf('UPDATE %s SET %s = "" WHERE id = ?', $this->catalogTablename, $strFieldname))->execute($this->strItemID); + $objFile = \FilesModel::findByUuid($strTempUuid); - if ( $objFile !== null ) { + if ($objFile !== null) { - if ( file_exists( TL_ROOT . '/' . $objFile->path ) ) { + if (file_exists(TL_ROOT . '/' . $objFile->path)) { - unlink( TL_ROOT . '/' . $objFile->path ); + unlink(TL_ROOT . '/' . $objFile->path); } } @@ -239,16 +238,18 @@ protected function deleteImage() { } - protected function setCatalogAttributes() { + protected function setCatalogAttributes() + { - if ( !empty( $this->arrCatalogFields ) && is_array( $this->arrCatalogFields ) ) { + if (!empty($this->arrCatalogFields) && is_array($this->arrCatalogFields)) { - $this->arrCatalogAttributes = Toolkit::parseCatalogValues( $this->arrValues, $this->arrCatalogFields, false ); + $this->arrCatalogAttributes = Toolkit::parseCatalogValues($this->arrValues, $this->arrCatalogFields, false); } } - protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { + protected function renderFieldsByPalette($arrFieldNames, $strPalette = '') + { $arrReturn = []; @@ -263,7 +264,7 @@ protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { if ($strClass === false) continue; - $arrData = $strClass::getAttributesFromDca($arrField, $strFieldname, $arrField['default']??'', '', '' ); + $arrData = $strClass::getAttributesFromDca($arrField, $strFieldname, $arrField['default'] ?? '', '', ''); if (is_bool($arrField['_disableFEE']) && $arrField['_disableFEE'] == true) continue; @@ -276,12 +277,10 @@ protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { ]; } - if ( isset( $GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingField'] ) && is_array( $GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingField'] ) ) { - - foreach ( $GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingField'] as $callback ) { - - $this->import( $callback[0] ); - $this->{$callback[0]}->{$callback[1]}( $strFieldname, $strClass, $arrData, $this->arrCatalogFields[ $strFieldname ], $this->arrCatalog ); + if (isset($GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingField']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingField'])) { + foreach ($GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingField'] as $callback) { + $this->import($callback[0]); + $this->{$callback[0]}->{$callback[1]}($strFieldname, $strClass, $arrData, $this->arrCatalogFields[$strFieldname], $this->arrCatalog); } } @@ -290,7 +289,7 @@ protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { $objWidget->id = 'id_' . $strFieldname; $objWidget->value = $this->arrValues[$strFieldname]; $objWidget->placeholder = $arrField['_placeholder'] ?: ''; - $objWidget->description = is_array( $arrField['label'] ) && isset( $arrField['label'][1] ) ? $arrField['label'][1] : ''; + $objWidget->description = is_array($arrField['label']) && isset($arrField['label'][1]) ? $arrField['label'][1] : ''; if (isset($this->arrCatalogFields[$strFieldname]['template']) && $this->arrCatalogFields[$strFieldname]['template'] && in_array($this->arrCatalogFields[$strFieldname]['type'], $this->arrValidFormTemplates)) $objWidget->template = $this->arrCatalogFields[$strFieldname]['template']; @@ -321,7 +320,7 @@ protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { $objWidget->uploadFolder = $this->catalogUploadFolder; $objWidget->extensions = $arrField['eval']['extensions']; $objWidget->doNotOverwrite = $this->catalogDoNotOverwrite; - $objWidget->preview = $this->arrCatalogAttributes[ $strFieldname ]; + $objWidget->preview = $this->arrCatalogAttributes[$strFieldname]; $objWidget->deleteLabel = $GLOBALS['TL_LANG']['MSC']['CATALOG_MANAGER']['deleteImageButton']; $this->blnHasUpload = true; @@ -346,76 +345,76 @@ protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { $GLOBALS['TL_HEAD'][] = $strScript; } - if (isset($this->arrCatalogFields[ $strFieldname ]['autoCompletionType']) && $this->arrCatalogFields[ $strFieldname ]['autoCompletionType']) { + if (isset($this->arrCatalogFields[$strFieldname]['autoCompletionType']) && $this->arrCatalogFields[$strFieldname]['autoCompletionType']) { $objWidget->class .= ' awesomplete-field'; - $objWidget->class .= ($arrField['multiple']?' multiple':''); + $objWidget->class .= ($arrField['multiple'] ? ' multiple' : ''); if (\Input::get('ctlg_autocomplete_query') && \Input::get('ctlg_fieldname') == $strFieldname) { - $this->sendJsonResponse( $this->arrCatalogFields[$strFieldname], $this->id, \Input::get('ctlg_autocomplete_query')); + $this->sendJsonResponse($this->arrCatalogFields[$strFieldname], $this->id, \Input::get('ctlg_autocomplete_query')); } $objScriptLoader = new CatalogScriptLoader(); - $objScriptLoader->loadScript( 'awesomplete-frontend' ); - $objScriptLoader->loadStyle( 'awesomplete' ); + $objScriptLoader->loadScript('awesomplete-frontend'); + $objScriptLoader->loadStyle('awesomplete'); } $arrField['default'] = $arrField['default'] ?? ''; - - if ( Toolkit::isEmpty( $objWidget->value ) && !Toolkit::isEmpty($arrField['default'])) { + + if (Toolkit::isEmpty($objWidget->value) && !Toolkit::isEmpty($arrField['default'])) { $objWidget->value = $arrField['default']; } if (isset($arrField['eval']['rgxp']) && $arrField['eval']['rgxp'] && in_array($arrField['eval']['rgxp'], ['date', 'time', 'datim'])) { - $strDateFormat = \Date::getFormatFromRgxp( $arrField['eval']['rgxp'] ); - $objWidget->value = $objWidget->value ? \Date::parse( $strDateFormat, $objWidget->value ) : ''; + $strDateFormat = \Date::getFormatFromRgxp($arrField['eval']['rgxp']); + $objWidget->value = $objWidget->value ? \Date::parse($strDateFormat, $objWidget->value) : ''; } $this->arrCatalogFields[$strFieldname]['tstampAsDefault'] = $this->arrCatalogFields[$strFieldname]['tstampAsDefault'] ?? ''; - if (in_array($arrField['_type'], [ 'hidden', 'date' ]) && $this->arrCatalogFields[$strFieldname]['tstampAsDefault']) { - if (Toolkit::isEmpty( $objWidget->value)) { + if (in_array($arrField['_type'], ['hidden', 'date']) && $this->arrCatalogFields[$strFieldname]['tstampAsDefault']) { + if (Toolkit::isEmpty($objWidget->value)) { $objWidget->value = time(); } } - if ( \Input::post('FORM_SUBMIT') == $this->strOnChangeId && !Toolkit::isEmpty( \Input::post( $strFieldname ) ) ) { + if (\Input::post('FORM_SUBMIT') == $this->strOnChangeId && !Toolkit::isEmpty(\Input::post($strFieldname))) { - $objWidget->value = \Input::post( $strFieldname ); + $objWidget->value = \Input::post($strFieldname); } $objWidget->catalogAttributes = $this->arrCatalogAttributes; - if ( isset( $GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingWidgetBeforeParsing'] ) && is_array( $GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingWidgetBeforeParsing'] ) ) { + if (isset($GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingWidgetBeforeParsing']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingWidgetBeforeParsing'])) { - foreach ( $GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingWidgetBeforeParsing'] as $callback ) { + foreach ($GLOBALS['TL_HOOKS']['catalogManagerModifyFrontendEditingWidgetBeforeParsing'] as $callback) { - $this->import( $callback[0] ); - $this->{$callback[0]}->{$callback[1]}( $objWidget, $strFieldname, $this->arrCatalogFields, $this->arrCatalog, $arrData, $this ); + $this->import($callback[0]); + $this->{$callback[0]}->{$callback[1]}($objWidget, $strFieldname, $this->arrCatalogFields, $this->arrCatalog, $arrData, $this); } } - if ( \Input::post('FORM_SUBMIT') == $this->strFormId ) { + if (\Input::post('FORM_SUBMIT') == $this->strFormId) { $objWidget->validate(); $varValue = $objWidget->value; - if ( Toolkit::isEmpty( $varValue ) && $arrField['inputType'] == 'catalogFineUploader' ) { + if (Toolkit::isEmpty($varValue) && $arrField['inputType'] == 'catalogFineUploader') { - $varValue = $this->arrValues[ $strFieldname ]; + $varValue = $this->arrValues[$strFieldname]; } - if ( Toolkit::isEmpty( $varValue ) && !Toolkit::isEmpty( $arrField['default'] ) ) { + if (Toolkit::isEmpty($varValue) && !Toolkit::isEmpty($arrField['default'])) { $varValue = $arrField['default']; } - if ( $varValue && is_string( $varValue ) ) { + if ($varValue && is_string($varValue)) { - $varValue = $this->decodeValue( $varValue ); - $varValue = $this->replaceInsertTags( $varValue ); + $varValue = $this->decodeValue($varValue); + $varValue = $this->replaceInsertTags($varValue); } $arrField['eval']['rgxp'] = $arrField['eval']['rgxp'] ?? ''; @@ -424,25 +423,25 @@ protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { try { - $objDate = new \Date( $varValue, \Date::getFormatFromRgxp( $arrField['eval']['rgxp'] ) ); + $objDate = new \Date($varValue, \Date::getFormatFromRgxp($arrField['eval']['rgxp'])); $varValue = $objDate->tstamp; - } catch ( \OutOfBoundsException $objError ) { + } catch (\OutOfBoundsException $objError) { - $objWidget->addError( sprintf( $GLOBALS['TL_LANG']['ERR']['invalidDate'], $varValue ) ); + $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $varValue)); } } - if ( $arrField['eval']['unique'] && $varValue != '' && !$this->SQLQueryHelper->SQLQueryBuilder->Database->isUniqueValue( $this->catalogTablename, $strFieldname, $varValue, ( $this->strAct == 'edit' ? $this->strItemID : null ) ) ) { + if ($arrField['eval']['unique'] && $varValue != '' && !$this->SQLQueryHelper->SQLQueryBuilder->Database->isUniqueValue($this->catalogTablename, $strFieldname, $varValue, ($this->strAct == 'edit' ? $this->strItemID : null))) { - $objWidget->addError( sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrField['label'][0] ?: $strFieldname ) ); + $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrField['label'][0] ?: $strFieldname)); } if ($objWidget->submitInput() && !$objWidget->hasErrors() && isset($arrField['save_callback']) && is_array($arrField['save_callback'])) { foreach ($arrField['save_callback'] as $arrCallback) { - $objDataContainer = new CatalogDataContainer( $this->catalogTablename ); + $objDataContainer = new CatalogDataContainer($this->catalogTablename); $objDataContainer->value = $varValue; $objDataContainer->id = $this->strItemID; @@ -453,31 +452,25 @@ protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { try { - if ( is_array( $arrCallback ) ) { + if (is_array($arrCallback)) { - $this->import( $arrCallback[0] ); - $varValue = $this->{$arrCallback[0]}->{$arrCallback[1]}( $varValue, $objDataContainer ); - } - - elseif( is_callable( $arrCallback ) ) { + $this->import($arrCallback[0]); + $varValue = $this->{$arrCallback[0]}->{$arrCallback[1]}($varValue, $objDataContainer); + } elseif (is_callable($arrCallback)) { - $varValue = $arrCallback( $varValue, $objDataContainer ); + $varValue = $arrCallback($varValue, $objDataContainer); } - } - - catch ( \Exception $objError ) { + } catch (\Exception $objError) { $objWidget->class = 'error'; - $objWidget->addError( $objError->getMessage() ); + $objWidget->addError($objError->getMessage()); } } } if ($objWidget->hasErrors()) { $this->blnNoSubmit = true; - } - - elseif($objWidget->submitInput()) { + } elseif ($objWidget->submitInput()) { if ($varValue === '') { $varValue = $objWidget->getEmptyValue(); @@ -486,10 +479,10 @@ protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { $arrField['eval']['encrypt'] = $arrField['eval']['encrypt'] ?? ''; if ($arrField['eval']['encrypt']) { - $varValue = \Encryption::encrypt( $varValue ); + $varValue = \Encryption::encrypt($varValue); } - $this->arrValues[ $strFieldname ] = $varValue; + $this->arrValues[$strFieldname] = $varValue; } if (!isset($_SESSION['FILES'])) { @@ -502,27 +495,25 @@ protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { if (!Toolkit::isAssoc($arrFiles[$strFieldname])) { $arrUUIDValues = []; - foreach ($arrFiles[ $strFieldname ] as $arrFile) { + foreach ($arrFiles[$strFieldname] as $arrFile) { $arrUUIDValues[] = $this->getFileUUID($arrFile); } - if (\Config::get( 'catalogMergeMultipleUploads' ) && $arrField['eval']['multiple']) { + if (\Config::get('catalogMergeMultipleUploads') && $arrField['eval']['multiple']) { - $arrUUIDValues = array_merge( \StringUtil::deserialize( $this->arrValues[ $strFieldname ], true ) , $arrUUIDValues ); - $arrUUIDValues = array_unique( $arrUUIDValues ); - $arrUUIDValues = array_values( $arrUUIDValues ); + $arrUUIDValues = array_merge(\StringUtil::deserialize($this->arrValues[$strFieldname], true), $arrUUIDValues); + $arrUUIDValues = array_unique($arrUUIDValues); + $arrUUIDValues = array_values($arrUUIDValues); } - $strUUIDValue = serialize( $arrUUIDValues ); - } - - else { + $strUUIDValue = serialize($arrUUIDValues); + } else { - $strUUIDValue = $this->getFileUUID( $arrFiles[ $strFieldname ] ); + $strUUIDValue = $this->getFileUUID($arrFiles[$strFieldname]); } - $this->arrValues[ $strFieldname ] = $strUUIDValue; - unset( $_SESSION['FILES'][ $strFieldname ] ); + $this->arrValues[$strFieldname] = $strUUIDValue; + unset($_SESSION['FILES'][$strFieldname]); } } @@ -533,9 +524,10 @@ protected function renderFieldsByPalette($arrFieldNames, $strPalette='') { } - public function isVisible() { + public function isVisible() + { - if ( !\Input::get( 'auto_item' ) || !$this->catalogTablename ) { + if (!\Input::get('auto_item') || !$this->catalogTablename) { return false; } @@ -550,19 +542,19 @@ public function isVisible() { [ 'field' => 'id', 'operator' => 'equal', - 'value' => \Input::get( 'auto_item' ) + 'value' => \Input::get('auto_item') ], [ 'field' => 'alias', 'operator' => 'equal', - 'value' => \Input::get( 'auto_item' ) + 'value' => \Input::get('auto_item') ] ] ] ]; - if ( $this->hasVisibility() ) { + if ($this->hasVisibility()) { $dteTime = \Date::floorToMinute(); @@ -592,7 +584,7 @@ public function isVisible() { [ 'field' => 'stop', 'operator' => 'gt', - 'value' => ( $dteTime + 60 ) + 'value' => ($dteTime + 60) ] ]; @@ -604,42 +596,43 @@ public function isVisible() { ]; } - if ( isset( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingQuery'] ) && is_array( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingQuery'] ) ) { + if (isset($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingQuery']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingQuery'])) { - foreach ( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingQuery'] as $arrCallback ) { + foreach ($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingQuery'] as $arrCallback) { - if ( is_array( $arrCallback ) ) { + if (is_array($arrCallback)) { - $this->import( $arrCallback[0] ); - $arrQuery = $this->{$arrCallback[0]}->{$arrCallback[1]}( $arrQuery, $this ); + $this->import($arrCallback[0]); + $arrQuery = $this->{$arrCallback[0]}->{$arrCallback[1]}($arrQuery, $this); } } } - $objEntities = $this->SQLQueryBuilder->execute( $arrQuery ); + $objEntities = $this->SQLQueryBuilder->execute($arrQuery); return $objEntities->numRows ? true : false; } - protected function hasVisibility() { + protected function hasVisibility() + { - if ( $this->catalogIgnoreVisibility && $this->catalogEnableFrontendEditing ) { + if ($this->catalogIgnoreVisibility && $this->catalogEnableFrontendEditing) { return false; } - if ( !is_array( $this->arrCatalog['operations'] ) ) { + if (!is_array($this->arrCatalog['operations'])) { return false; } - if ( !in_array( 'invisible', $this->arrCatalog['operations'] ) ) { + if (!in_array('invisible', $this->arrCatalog['operations'])) { return false; } - if ( BE_USER_LOGGED_IN ) { + if (BE_USER_LOGGED_IN) { return false; } @@ -648,32 +641,34 @@ protected function hasVisibility() { } - public function checkAccess() { + public function checkAccess() + { - $this->import( 'FrontendEditingPermission' ); + $this->import('FrontendEditingPermission'); $this->FrontendEditingPermission->blnDisablePermissions = $this->catalogEnableFrontendPermission ? false : true; $this->FrontendEditingPermission->initialize(); - return $this->FrontendEditingPermission->hasAccess( $this->catalogTablename ); + return $this->FrontendEditingPermission->hasAccess($this->catalogTablename); } - public function checkPermission( $strMode ) { + public function checkPermission($strMode) + { - $this->import( 'FrontendEditingPermission' ); + $this->import('FrontendEditingPermission'); - if ( !is_array( $this->catalogItemOperations ) ) $this->catalogItemOperations = []; - if ( !in_array( $strMode, $this->catalogItemOperations ) ) return false; + if (!is_array($this->catalogItemOperations)) $this->catalogItemOperations = []; + if (!in_array($strMode, $this->catalogItemOperations)) return false; $this->FrontendEditingPermission->blnDisablePermissions = $this->catalogEnableFrontendPermission ? false : true; $this->FrontendEditingPermission->initialize(); - if ( $strMode == 'copy' ) $strMode = 'create'; + if ($strMode == 'copy') $strMode = 'create'; - if ( isset($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingCheckPermission']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingCheckPermission'])) { + if (isset($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingCheckPermission']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingCheckPermission'])) { foreach ($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingCheckPermission'] as $arrCallback) { - if ( is_array( $arrCallback ) ) { + if (is_array($arrCallback)) { $this->import($arrCallback[0]); $varReturn = $this->{$arrCallback[0]}->{$arrCallback[1]}($strMode, $this->strItemID, $this->catalogTablename, $this); if (is_bool($varReturn)) { @@ -683,20 +678,21 @@ public function checkPermission( $strMode ) { } } - return $this->FrontendEditingPermission->hasPermission( $strMode, $this->catalogTablename ); + return $this->FrontendEditingPermission->hasPermission($strMode, $this->catalogTablename); } - public function deleteEntity() { + public function deleteEntity() + { - $this->import( 'SQLBuilder' ); + $this->import('SQLBuilder'); - if ( $this->SQLBuilder->Database->tableExists( $this->catalogTablename ) ) { + if ($this->SQLBuilder->Database->tableExists($this->catalogTablename)) { - if ( $this->catalogNotifyDelete ) { + if ($this->catalogNotifyDelete) { - $objCatalogNotification = new CatalogNotification( $this, $this->strItemID ); - $objCatalogNotification->notifyOnDelete( $this->catalogNotifyDelete, [] ); + $objCatalogNotification = new CatalogNotification($this, $this->strItemID); + $objCatalogNotification->notifyOnDelete($this->catalogNotifyDelete, []); } $arrData = [ @@ -708,72 +704,74 @@ public function deleteEntity() { $this->CatalogMessage->set('deleteMessage', $arrData, $this->id); - $this->CatalogEvents->addEventListener( 'delete', $arrData, $this ); - $this->SQLBuilder->Database->prepare( sprintf( 'DELETE FROM %s WHERE id = ? ', $this->catalogTablename ) )->execute( $this->strItemID ); - \System::log( 'DELETE FROM '. $this->catalogTablename .' WHERE id='. $this->strItemID, __METHOD__, TL_GENERAL ); + $this->CatalogEvents->addEventListener('delete', $arrData, $this); + $this->SQLBuilder->Database->prepare(sprintf('DELETE FROM %s WHERE id = ? ', $this->catalogTablename))->execute($this->strItemID); + \System::log('DELETE FROM ' . $this->catalogTablename . ' WHERE id=' . $this->strItemID, __METHOD__, TL_GENERAL); // $this->deleteChildEntities( $this->catalogTablename, $this->strItemID ); } $strAttributes = ''; - $objPage = \PageModel::findWithDetails( $this->strRedirectID ); - $strUrl = $this->generateFrontendUrl( $objPage->row(), '', $objPage->language, true ); + $objPage = \PageModel::findWithDetails($this->strRedirectID); + $strUrl = $this->generateFrontendUrl($objPage->row(), '', $objPage->language, true); - if ( strncmp( $strUrl, 'http://', 7 ) !== 0 && strncmp( $strUrl, 'https://', 8 ) !== 0 ) $strUrl = \Environment::get( 'base' ) . $strUrl; - if ( \Input::get( 'pid' ) ) $strAttributes .= '?pid=' .\Input::get( 'pid' ); - if ( $strAttributes ) $strUrl .= $strAttributes; + if (strncmp($strUrl, 'http://', 7) !== 0 && strncmp($strUrl, 'https://', 8) !== 0) $strUrl = \Environment::get('base') . $strUrl; + if (\Input::get('pid')) $strAttributes .= '?pid=' . \Input::get('pid'); + if ($strAttributes) $strUrl .= $strAttributes; - if ( isset( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect'] ) && is_array( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect'] ) ) { + if (isset($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect'])) { - foreach ( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect'] as $arrCallback ) { + foreach ($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect'] as $arrCallback) { - if ( is_array( $arrCallback ) ) { + if (is_array($arrCallback)) { - $this->import( $arrCallback[0] ); - $strUrl = $this->{$arrCallback[0]}->{$arrCallback[1]}( $strUrl, $strAttributes, $objPage, $this->arrValues, $this->strAct, $this->id, $this->catalogTablename, $this ); + $this->import($arrCallback[0]); + $strUrl = $this->{$arrCallback[0]}->{$arrCallback[1]}($strUrl, $strAttributes, $objPage, $this->arrValues, $this->strAct, $this->id, $this->catalogTablename, $this); } } } - $this->redirect( $strUrl ); + $this->redirect($strUrl); } - - protected function deleteChildEntities( $strTable, $strID, $strPtable = '' ) { - if ( !isset( $GLOBALS['TL_CATALOG_MANAGER']['CATALOG_EXTENSIONS'][ $strTable ] ) ) return null; + protected function deleteChildEntities($strTable, $strID, $strPtable = '') + { - $arrCatalog = $GLOBALS['TL_CATALOG_MANAGER']['CATALOG_EXTENSIONS'][ $strTable ]; + if (!isset($GLOBALS['TL_CATALOG_MANAGER']['CATALOG_EXTENSIONS'][$strTable])) return null; + + $arrCatalog = $GLOBALS['TL_CATALOG_MANAGER']['CATALOG_EXTENSIONS'][$strTable]; $arrTables = $arrCatalog['cTables']; - if ( is_array( $arrTables ) && !empty( $arrTables ) ) { + if (is_array($arrTables) && !empty($arrTables)) { - foreach ( $arrTables as $strTable ) { + foreach ($arrTables as $strTable) { - $arrValues = [ $strID ]; + $arrValues = [$strID]; - if ( $strTable == 'tl_content' ) $strPtable = $strTable; - if ( $strPtable ) $arrValues[] = $strPtable; + if ($strTable == 'tl_content') $strPtable = $strTable; + if ($strPtable) $arrValues[] = $strPtable; - if ( !$strPtable ) { + if (!$strPtable) { - $objEntity = $this->SQLBuilder->Database->prepare( sprintf( 'SELECT id FROM %s WHERE pid = ?', $strTable ) )->limit(1)->execute( $strID ); + $objEntity = $this->SQLBuilder->Database->prepare(sprintf('SELECT id FROM %s WHERE pid = ?', $strTable))->limit(1)->execute($strID); - $this->deleteChildEntities( $strTable, $objEntity->id ); + $this->deleteChildEntities($strTable, $objEntity->id); } - $this->SQLBuilder->Database->prepare( sprintf( 'DELETE FROM %s WHERE pid = ?' . ( $strPtable ? ' AND ptable = ?' : '' ), $strTable ) )->execute( $arrValues ); + $this->SQLBuilder->Database->prepare(sprintf('DELETE FROM %s WHERE pid = ?' . ($strPtable ? ' AND ptable = ?' : ''), $strTable))->execute($arrValues); } } } - protected function setPalettes() { + protected function setPalettes() + { $this->arrPalettes = [ 'general_legend' => [] ]; - if ( !empty($this->arrCatalogFields) && is_array($this->arrCatalogFields)) { + if (!empty($this->arrCatalogFields) && is_array($this->arrCatalogFields)) { foreach ($this->arrCatalogFields as $strFieldname => $arrField) { $strPalette = $arrField['_palette']; if (Toolkit::isEmpty($strPalette)) continue; @@ -798,11 +796,12 @@ protected function setPalettes() { } - protected function setOptions() { + protected function setOptions() + { - if ( !empty( $this->arrOptions ) && is_array( $this->arrOptions ) ) { + if (!empty($this->arrOptions) && is_array($this->arrOptions)) { - foreach ( $this->arrOptions as $strKey => $varValue ) { + foreach ($this->arrOptions as $strKey => $varValue) { $this->{$strKey} = $varValue; } @@ -810,7 +809,8 @@ protected function setOptions() { } - protected function getCaptcha() { + protected function getCaptcha() + { $arrCaptcha = [ @@ -824,34 +824,35 @@ protected function getCaptcha() { $strClass = $GLOBALS['TL_FFL']['captcha']; - if ( !class_exists( $strClass ) ) $strClass = 'FormCaptcha'; + if (!class_exists($strClass)) $strClass = 'FormCaptcha'; - $objCaptcha = new $strClass( $arrCaptcha ); + $objCaptcha = new $strClass($arrCaptcha); - if ( \Input::post('FORM_SUBMIT') == $this->strFormId ) { + if (\Input::post('FORM_SUBMIT') == $this->strFormId) { $objCaptcha->validate(); - if ( $objCaptcha->hasErrors() ) $this->blnNoSubmit = true; + if ($objCaptcha->hasErrors()) $this->blnNoSubmit = true; } return $objCaptcha; } - protected function convertWidgetToField( $arrField ) { + protected function convertWidgetToField($arrField) + { - if ( $arrField['inputType'] == 'checkboxWizard' ) { + if ($arrField['inputType'] == 'checkboxWizard') { $arrField['inputType'] = 'checkbox'; } - if ( $arrField['inputType'] == 'fileTree' ) { + if ($arrField['inputType'] == 'fileTree') { $arrField['inputType'] = 'upload'; } - if ( $arrField['inputType'] == 'catalogMessageWidget' ) { + if ($arrField['inputType'] == 'catalogMessageWidget') { $arrField['inputType'] = 'catalogMessageForm'; } @@ -863,26 +864,28 @@ protected function convertWidgetToField( $arrField ) { } - protected function fieldClassExist( $strInputType ) { + protected function fieldClassExist($strInputType) + { - $strClass = $GLOBALS['TL_FFL'][ $strInputType ]; - if ( !class_exists( $strClass ) ) return false; + $strClass = $GLOBALS['TL_FFL'][$strInputType]; + if (!class_exists($strClass)) return false; return $strClass; } - protected function setValues() { + protected function setValues() + { - if ( $this->strItemID && $this->catalogTablename ) { + if ($this->strItemID && $this->catalogTablename) { // $arrEntity = $this->SQLQueryHelper->SQLQueryBuilder->Database->prepare( sprintf( 'SELECT * FROM %s WHERE id = ?', $this->catalogTablename ) )->limit( 1 )->execute( $this->strItemID )->row(); - $arrEntity = (new \CatalogManager\Entity($this->strItemID, $this->catalogTablename, ['ignoreVisibility' => (bool) $this->catalogIgnoreVisibility, 'operations' => [], 'noJoins' => true, 'noParentJoin' => true, 'queries' => $this->arrQueries]))->getEntity()['origin']; + $arrEntity = (new \CatalogManager\Entity($this->strItemID, $this->catalogTablename, ['ignoreVisibility' => (bool)$this->catalogIgnoreVisibility, 'operations' => [], 'noJoins' => true, 'noParentJoin' => true, 'queries' => $this->arrQueries]))->getEntity()['origin']; - if ( $this->strAct == 'copy' ) { + if ($this->strAct == 'copy') { - unset( $arrEntity['id'] ); - unset( $arrEntity['alias'] ); + unset($arrEntity['id']); + unset($arrEntity['alias']); } foreach ($this->catalogExcludedFields as $strField) { @@ -892,11 +895,11 @@ protected function setValues() { $this->arrValues = $arrEntity; } - if ( !empty( $this->arrValues ) && is_array( $this->arrValues ) ) { + if (!empty($this->arrValues) && is_array($this->arrValues)) { - foreach ( $this->arrValues as $strFieldname => $varValue ) { + foreach ($this->arrValues as $strFieldname => $varValue) { - $this->arrValues[ $strFieldname ] = \Input::post( $strFieldname ) !== null ? \Input::post( $strFieldname ) : $varValue; + $this->arrValues[$strFieldname] = \Input::post($strFieldname) !== null ? \Input::post($strFieldname) : $varValue; } } @@ -907,20 +910,22 @@ protected function setValues() { } - protected function decodeValue( $varValue ) { + protected function decodeValue($varValue) + { - return \StringUtil::decodeEntities( $varValue ); + return \StringUtil::decodeEntities($varValue); } - protected function getFileUUID( $arrFile ) { + protected function getFileUUID($arrFile) + { $strRoot = TL_ROOT . '/'; $strUuid = $arrFile['uuid']; - $strFile = substr( $arrFile['tmp_name'], strlen( $strRoot ) ); - $objFiles = \FilesModel::findByPath( $strFile ); + $strFile = substr($arrFile['tmp_name'], strlen($strRoot)); + $objFiles = \FilesModel::findByPath($strFile); - if ( $objFiles !== null ) { + if ($objFiles !== null) { $strUuid = $objFiles->uuid; } @@ -929,7 +934,8 @@ protected function getFileUUID( $arrFile ) { } - protected function saveEntity() { + protected function saveEntity() + { $strQuery = ''; $this->import('SQLBuilder'); @@ -944,7 +950,7 @@ protected function saveEntity() { //if (isset($this->arrValues['tstamp'])) { - $this->arrValues['tstamp'] = (string) time(); + $this->arrValues['tstamp'] = (string)time(); //} if (is_array($this->catalogDefaultValues) && $this->catalogDefaultValues[0]) { @@ -969,54 +975,54 @@ protected function saveEntity() { } $objDcCallbacks = new DcCallbacks(); - $this->arrValues['alias'] = $objDcCallbacks->generateFEAlias( $this->arrValues['alias'], $this->arrValues['title'], $this->catalogTablename, $this->arrValues['id'], $this->id ); + $this->arrValues['alias'] = $objDcCallbacks->generateFEAlias($this->arrValues['alias'], $this->arrValues['title'], $this->catalogTablename, $this->arrValues['id'], $this->id); - if ( isset( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingOnSave'] ) && is_array( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingOnSave'] ) ) { + if (isset($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingOnSave']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingOnSave'])) { - foreach ( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingOnSave'] as $arrCallback ) { + foreach ($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingOnSave'] as $arrCallback) { - if ( is_array( $arrCallback ) ) { + if (is_array($arrCallback)) { - $this->import( $arrCallback[0] ); - $this->arrValues = $this->{$arrCallback[0]}->{$arrCallback[1]}( $this->arrValues, $this->strAct, $this->arrCatalog, $this->arrCatalogFields, $this ); + $this->import($arrCallback[0]); + $this->arrValues = $this->{$arrCallback[0]}->{$arrCallback[1]}($this->arrValues, $this->strAct, $this->arrCatalog, $this->arrCatalogFields, $this); } } } $this->prepare(); - switch ( $this->strAct ) { + switch ($this->strAct) { case 'create': - if ( $this->SQLBuilder->Database->fieldExists( 'pid', $this->catalogTablename ) && $this->arrCatalog['pTable'] ) { + if ($this->SQLBuilder->Database->fieldExists('pid', $this->catalogTablename) && $this->arrCatalog['pTable']) { - if ( !\Input::get('pid') ) return null; + if (!\Input::get('pid')) return null; $this->arrValues['pid'] = \Input::get('pid'); } - if ( $this->SQLBuilder->Database->fieldExists( 'sorting', $this->catalogTablename ) ) { + if ($this->SQLBuilder->Database->fieldExists('sorting', $this->catalogTablename)) { - $intSort = $this->SQLBuilder->Database->prepare( sprintf( 'SELECT MAX(sorting) FROM %s;', $this->catalogTablename ) )->execute()->row( 'MAX(sorting)' )[0]; - $this->arrValues['sorting'] = intval( $intSort ) + 100; + $intSort = $this->SQLBuilder->Database->prepare(sprintf('SELECT MAX(sorting) FROM %s;', $this->catalogTablename))->execute()->row('MAX(sorting)')[0]; + $this->arrValues['sorting'] = intval($intSort) + 100; } - if ( $this->SQLBuilder->Database->fieldExists( 'tstamp', $this->catalogTablename ) ) { + if ($this->SQLBuilder->Database->fieldExists('tstamp', $this->catalogTablename)) { $this->arrValues['tstamp'] = \Date::floorToMinute(); } - $strInsertId = $this->SQLBuilder->Database->prepare( 'INSERT INTO '. $this->catalogTablename .' %s' )->set( $this->arrValues )->execute()->insertId; - \System::log( 'A new entry "'. $this->catalogTablename .'='. $strInsertId .'" has been created', __METHOD__, TL_GENERAL ); + $strInsertId = $this->SQLBuilder->Database->prepare('INSERT INTO ' . $this->catalogTablename . ' %s')->set($this->arrValues)->execute()->insertId; + \System::log('A new entry "' . $this->catalogTablename . '=' . $strInsertId . '" has been created', __METHOD__, TL_GENERAL); $this->arrValues['id'] = $strInsertId; - if ( $this->catalogNotifyInsert ) { + if ($this->catalogNotifyInsert) { - $objCatalogNotification = new CatalogNotification( $this ); - $objCatalogNotification->notifyOnInsert( $this->catalogNotifyInsert, $this->arrValues ); + $objCatalogNotification = new CatalogNotification($this); + $objCatalogNotification->notifyOnInsert($this->catalogNotifyInsert, $this->arrValues); } $arrData = [ @@ -1029,24 +1035,24 @@ protected function saveEntity() { $this->CatalogMessage->set('insertMessage', $arrData, $this->id); $this->CatalogEvents->addEventListener('create', $arrData, $this); - $this->redirectAfterInsertion( $this->strRedirectID, $strQuery ); + $this->redirectAfterInsertion($this->strRedirectID, $strQuery); break; case 'edit': $blnReload = true; - $objEntity = $this->SQLBuilder->Database->prepare( 'SELECT * FROM '. $this->catalogTablename .' WHERE id = ?' )->limit(1)->execute( $this->strItemID ); + $objEntity = $this->SQLBuilder->Database->prepare('SELECT * FROM ' . $this->catalogTablename . ' WHERE id = ?')->limit(1)->execute($this->strItemID); - if ( $objEntity->numRows ) { + if ($objEntity->numRows) { - if ( $this->arrValues['alias'] && $this->arrValues['alias'] !== $objEntity->alias ) { + if ($this->arrValues['alias'] && $this->arrValues['alias'] !== $objEntity->alias) { - $blnReload = false; + $blnReload = false; - if ( $objEntity->pid ) { + if ($objEntity->pid) { - $strQuery = sprintf( '?pid=%s', $objEntity->pid ); + $strQuery = sprintf('?pid=%s', $objEntity->pid); } } @@ -1063,22 +1069,20 @@ protected function saveEntity() { ]; $this->CatalogMessage->set('updateMessage', $arrData, $this->id); - $this->CatalogEvents->addEventListener( 'update', $arrData, $this ); - $this->SQLBuilder->Database->prepare( 'UPDATE '. $this->catalogTablename .' %s WHERE id = ?' )->set( $this->arrValues )->execute( $this->strItemID ); + $this->CatalogEvents->addEventListener('update', $arrData, $this); + $this->SQLBuilder->Database->prepare('UPDATE ' . $this->catalogTablename . ' %s WHERE id = ?')->set($this->arrValues)->execute($this->strItemID); - \System::log( 'An entry "'. $this->catalogTablename .'='. $this->strItemID .'" has been updated', __METHOD__, TL_GENERAL ); + \System::log('An entry "' . $this->catalogTablename . '=' . $this->strItemID . '" has been updated', __METHOD__, TL_GENERAL); } - if ( !$this->isVisible() ) $blnReload = false; + if (!$this->isVisible()) $blnReload = false; - if ( $blnReload && ( Toolkit::isEmpty( $this->catalogFormRedirect ) || $this->catalogFormRedirect == '0' ) ) { + if ($blnReload && (Toolkit::isEmpty($this->catalogFormRedirect) || $this->catalogFormRedirect == '0')) { $this->reload(); - } - - else { + } else { - $this->redirectAfterInsertion( $this->strRedirectID, $strQuery ); + $this->redirectAfterInsertion($this->strRedirectID, $strQuery); } break; @@ -1088,9 +1092,9 @@ protected function saveEntity() { $arrSet = $this->arrValues; unset($arrSet['id']); - $objInsert = $this->SQLBuilder->Database->prepare( 'INSERT INTO '. $this->catalogTablename .' %s' )->set($arrSet)->execute(); + $objInsert = $this->SQLBuilder->Database->prepare('INSERT INTO ' . $this->catalogTablename . ' %s')->set($arrSet)->execute(); - \System::log( 'An entry "'. $this->catalogTablename .'='. $objInsert->insertId .'" has been duplicated', __METHOD__, TL_GENERAL ); + \System::log('An entry "' . $this->catalogTablename . '=' . $objInsert->insertId . '" has been duplicated', __METHOD__, TL_GENERAL); if ($this->catalogNotifyDuplicate) { $objCatalogNotification = new CatalogNotification($this, $this->strItemID); @@ -1112,84 +1116,87 @@ protected function saveEntity() { } - protected function redirectAfterInsertion( $intPage, $strAttributes = '', $blnReturn = false ) { + protected function redirectAfterInsertion($intPage, $strAttributes = '', $blnReturn = false) + { - if ( ( $intPage = intval($intPage ) ) <= 0 ) return ''; + if (($intPage = intval($intPage)) <= 0) return ''; - $objPage = \PageModel::findWithDetails( $intPage ); - $strUrl = $this->generateFrontendUrl( $objPage->row(), '', $objPage->language, true ); + $objPage = \PageModel::findWithDetails($intPage); + $strUrl = $this->generateFrontendUrl($objPage->row(), '', $objPage->language, true); - if ( strncmp( $strUrl, 'http://', 7 ) !== 0 && strncmp( $strUrl, 'https://', 8 ) !== 0 ) $strUrl = \Environment::get( 'base' ) . $strUrl; - if ( $strAttributes ) $strUrl .= $strAttributes; + if (strncmp($strUrl, 'http://', 7) !== 0 && strncmp($strUrl, 'https://', 8) !== 0) $strUrl = \Environment::get('base') . $strUrl; + if ($strAttributes) $strUrl .= $strAttributes; - if ( $this->catalogFormRedirectParameter ) { + if ($this->catalogFormRedirectParameter) { - $strParameters = \StringUtil::parseSimpleTokens( $this->catalogFormRedirectParameter, $this->arrValues ); + $strParameters = \StringUtil::parseSimpleTokens($this->catalogFormRedirectParameter, $this->arrValues); $strUrl .= $strAttributes ? '&' . $strParameters : '?' . $strParameters; } - if ( !$blnReturn ) { + if (!$blnReturn) { - if ( isset( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect'] ) && is_array( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect'] ) ) { + if (isset($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect']) && is_array($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect'])) { - foreach ( $GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect'] as $arrCallback ) { + foreach ($GLOBALS['TL_HOOKS']['catalogManagerFrontendEditingRedirect'] as $arrCallback) { - if ( is_array( $arrCallback ) ) { + if (is_array($arrCallback)) { - $this->import( $arrCallback[0] ); - $strUrl = $this->{$arrCallback[0]}->{$arrCallback[1]}( $strUrl, $strAttributes, $objPage, $this->arrValues, $this->strAct, $this->id, $this->catalogTablename, $this ); + $this->import($arrCallback[0]); + $strUrl = $this->{$arrCallback[0]}->{$arrCallback[1]}($strUrl, $strAttributes, $objPage, $this->arrValues, $this->strAct, $this->id, $this->catalogTablename, $this); } } } - $this->redirect( $strUrl ); + $this->redirect($strUrl); } return $strUrl; } - protected function getGeoCordValues() { + protected function getGeoCordValues() + { $arrCords = []; $objGeoCoding = new GeoCoding(); $strGeoInputType = $this->arrCatalog['addressInputType']; - switch ( $strGeoInputType ) { + switch ($strGeoInputType) { case 'useSingleField': - $arrCords = $objGeoCoding->getCords( $this->arrValues[ $this->arrCatalog['geoAddress'] ], 'en', true ); + $arrCords = $objGeoCoding->getCords($this->arrValues[$this->arrCatalog['geoAddress']], 'en', true); break; case 'useMultipleFields': - $objGeoCoding->setCity( $this->arrValues[ $this->arrCatalog['geoCity'] ] ); - $objGeoCoding->setStreet( $this->arrValues[ $this->arrCatalog['geoStreet'] ] ); - $objGeoCoding->setPostal( $this->arrValues[ $this->arrCatalog['geoPostal'] ] ); - $objGeoCoding->setCountry( $this->arrValues[ $this->arrCatalog['geoCountry'] ] ); - $objGeoCoding->setStreetNumber( $this->arrValues[ $this->arrCatalog['geoStreetNumber'] ] ); - $arrCords = $objGeoCoding->getCords( '', 'en', true ); + $objGeoCoding->setCity($this->arrValues[$this->arrCatalog['geoCity']]); + $objGeoCoding->setStreet($this->arrValues[$this->arrCatalog['geoStreet']]); + $objGeoCoding->setPostal($this->arrValues[$this->arrCatalog['geoPostal']]); + $objGeoCoding->setCountry($this->arrValues[$this->arrCatalog['geoCountry']]); + $objGeoCoding->setStreetNumber($this->arrValues[$this->arrCatalog['geoStreetNumber']]); + $arrCords = $objGeoCoding->getCords('', 'en', true); break; } - if ( ( $arrCords['lat'] || $arrCords['lng'] ) && ( $this->arrCatalog['lngField'] && $this->arrCatalog['latField'] ) ) { + if (($arrCords['lat'] || $arrCords['lng']) && ($this->arrCatalog['lngField'] && $this->arrCatalog['latField'])) { - $this->arrValues[ $this->arrCatalog['lngField'] ] = $arrCords['lng']; - $this->arrValues[ $this->arrCatalog['latField'] ] = $arrCords['lat']; + $this->arrValues[$this->arrCatalog['lngField']] = $arrCords['lng']; + $this->arrValues[$this->arrCatalog['latField']] = $arrCords['lat']; } } - protected function prepare() { + protected function prepare() + { - if ( !empty( $this->arrValues ) && is_array( $this->arrValues ) ) { + if (!empty($this->arrValues) && is_array($this->arrValues)) { - foreach ( $this->arrValues as $strFieldname => $varValue ) { + foreach ($this->arrValues as $strFieldname => $varValue) { - $arrField = $this->arrCatalogFields[ $strFieldname ]['_dcFormat'] ?? []; + $arrField = $this->arrCatalogFields[$strFieldname]['_dcFormat'] ?? []; $arrField['eval']['files'] = $arrField['eval']['files'] ?? ''; $arrField['eval']['multiple'] = $arrField['eval']['multiple'] ?? false; @@ -1218,47 +1225,51 @@ protected function prepare() { $varValue = intval($varValue); } - $this->arrValues[ $strFieldname ] = $varValue; + $this->arrValues[$strFieldname] = $varValue; } } } - public function getCatalog() { + public function getCatalog() + { - return is_array( $this->arrCatalog ) && !empty( $this->arrCatalog ) ? $this->arrCatalog : []; + return is_array($this->arrCatalog) && !empty($this->arrCatalog) ? $this->arrCatalog : []; } - public function getRedirectID() { + public function getRedirectID() + { return $this->strRedirectID; } - public function getValues() { + public function getValues() + { return $this->arrValues; } - - - protected function sendJsonResponse( $arrField, $strModuleID, $strKeyword ) { + + + protected function sendJsonResponse($arrField, $strModuleID, $strKeyword) + { $arrField['optionsType'] = 'useActiveDbOptions'; $arrField['dbColumn'] = $arrField['dbTableKey']; $arrField['dbTableValue'] = $arrField['dbTableKey']; - $objOptionGetter = new OptionsGetter( $arrField, $strModuleID, [ $strKeyword ] ); - $arrWords = array_values( $objOptionGetter->getOptions() ); + $objOptionGetter = new OptionsGetter($arrField, $strModuleID, [$strKeyword]); + $arrWords = array_values($objOptionGetter->getOptions()); header('Content-Type: application/json'); - echo json_encode( [ + echo json_encode([ 'word' => $strKeyword, 'words' => $arrWords - ], 12 ); + ], 12); exit; }