public function addBackendAdminMenu($strBuffer, $strTemplate)
 {
     if ($strTemplate != 'be_main' || !\BackendUser::getInstance()->isAdmin) {
         return $strBuffer;
     }
     // replace the scripts before processing -> https://code.google.com/archive/p/phpquery/issues/212
     $arrScripts = StringUtil::replaceScripts($strBuffer);
     $objDoc = \phpQuery::newDocumentHTML($arrScripts['content']);
     $objMenu = new BackendTemplate($this->strTemplate);
     $arrActions = array();
     $arrActiveActions = deserialize(\Config::get('backendAdminMenuActiveActions'), true);
     foreach (empty($arrActiveActions) ? array_keys(\Config::get('backendAdminMenuActions')) : $arrActiveActions as $strAction) {
         $arrActionData = $GLOBALS['TL_CONFIG']['backendAdminMenuActions'][$strAction];
         $objAction = new BackendTemplate($this->strEntryTemplate);
         $objAction->setData($arrActionData);
         // href = callback?
         if (is_array($arrActionData['href']) || is_callable($arrActionData['href'])) {
             $strClass = $arrActionData['href'][0];
             $strMethod = $arrActionData['href'][1];
             $objInstance = \Controller::importStatic($strClass);
             $objAction->href = $objInstance->{$strMethod}();
         }
         $objAction->class = $strAction;
         $arrActions[] = $objAction->parse();
     }
     $objMenu->actions = $arrActions;
     $objDoc['#tmenu']->prepend($objMenu->parse());
     $strBuffer = StringUtil::unreplaceScripts($objDoc->htmlOuter(), $arrScripts['scripts']);
     // avoid double escapings introduced by phpquery :-(
     $strBuffer = preg_replace('@&([^;]{2,4};)@i', '&$1', $strBuffer);
     return $strBuffer;
 }
 /**
  * Validate the user input and set the value
  */
 public static function validateGetAndPost($objWidget, $strMethod, $strFormId, $arrData)
 {
     if ($strMethod == FORMHYBRID_METHOD_GET) {
         $varValue = $objWidget->validator(static::getGet($objWidget, $objWidget->strName));
         $varValue = FormHelper::xssClean($varValue, $objWidget->allowHtml);
     } else {
         // \Widget->validate retrieves submission data form post -> xss related stuff needs to be removed beforehands
         $_POST[$objWidget->name] = FormHelper::xssClean($_POST[$objWidget->name], $objWidget->allowHtml);
         // Captcha needs no value, just simple validation
         if ($objWidget instanceof \FormCaptcha) {
             $varValue = '';
             $objWidget->validate();
         } else {
             $objWidget->validate();
             $varValue = $objWidget->value;
         }
     }
     $objWidget->varValue = $varValue;
     // HOOK: validate form field callback
     if (isset($GLOBALS['TL_HOOKS']['formHybridValidateFormField']) && is_array($GLOBALS['TL_HOOKS']['formHybridValidateFormField'])) {
         foreach ($GLOBALS['TL_HOOKS']['formHybridValidateFormField'] as $callback) {
             $objClass = \Controller::importStatic($callback[0]);
             $objClass->{$callback[1]}($objWidget, $strFormId, $arrData);
         }
     }
     if ($objWidget->hasErrors()) {
         $objWidget->class = 'error';
     }
 }
 public static function initPalette()
 {
     $objEntityImportConfig = \HeimrichHannot\EntityImport\EntityImportConfigModel::findByPk(\Input::get('id'));
     $arrDca =& $GLOBALS['TL_DCA']['tl_entity_import_config'];
     $strParentType = \HeimrichHannot\EntityImport\EntityImportModel::findByPk($objEntityImportConfig->pid)->type;
     // add default palettes
     $arrDca['palettes']['default'] .= $arrDca['typepalettes'][$strParentType];
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['initEntityImportPalettes']) && is_array($GLOBALS['TL_HOOKS']['initEntityImportPalettes'])) {
         foreach ($GLOBALS['TL_HOOKS']['initEntityImportPalettes'] as $arrCallback) {
             if (($objCallback = \Controller::importStatic($arrCallback[0])) !== null) {
                 $objCallback->{$arrCallback[1]}($objEntityImportConfig, $arrDca);
             }
         }
     }
 }
 public static function generateErrorMessage($strTable, $intEntity, $objModule)
 {
     $objLock = EntityLockModel::findActiveLock($strTable, $intEntity, $objModule);
     $objEditor = EntityLockModel::getEditor($objLock->id);
     if ($objModule->addEditorToLockMessage && $objLock !== null && $objEditor !== null) {
         $strName = $objLock->editorType == EntityLock::EDITOR_TYPE_USER ? $objEditor->name : $objEditor->firstname . ' ' . $objEditor->lastname;
         $strMessage = sprintf($GLOBALS['TL_LANG']['MSC']['entity_lock']['entityLockedEditor'], $strName);
     } else {
         $strMessage = $GLOBALS['TL_LANG']['MSC']['entity_lock']['entityLocked'];
     }
     // HOOK: further customize the error message
     if (isset($GLOBALS['TL_HOOKS']['customizeLockErrorMessage']) && is_array($GLOBALS['TL_HOOKS']['customizeLockErrorMessage'])) {
         foreach ($GLOBALS['TL_HOOKS']['customizeLockErrorMessage'] as $callback) {
             $objClass = \Controller::importStatic($callback[0]);
             $strMessage = $objClass->{$callback[1]}($strMessage, $objLock, $objEditor, $objModule);
         }
     }
     return $strMessage;
 }
Example #5
0
 /**
  * Choose the right template
  */
 public function chooseTemplates()
 {
     // do not choose backend templates in the frontend see #27
     if (TL_MODE == "FE") {
         return;
     }
     // check theme for back end user
     /** @var \BackendUser $objUser */
     $objUser = \Controller::importStatic('BackendUser');
     $loggedIn = $this->beUserLoggedIn($objUser);
     $theme = $objUser->backendTheme;
     if ($loggedIn === false && \Config::get('backendTheme') != "sb-admin" || $theme !== null && $theme != "sb-admin") {
         return;
     }
     // modified templates
     $arrTemplate = array('be_changelog', 'be_chart_panel', 'be_confirm', 'be_diff', 'be_error', 'be_forbidden', 'be_help', 'be_incomplete', 'be_install', 'be_login', 'be_main', 'be_navigation', 'be_no_active', 'be_no_forward', 'be_no_layout', 'be_no_page', 'be_no_root', 'be_pagination', 'be_password', 'be_picker', 'be_popup', 'be_purge_data', 'be_referer', 'be_switch', 'be_unavailable', 'be_welcome');
     // Register the template
     foreach ($arrTemplate as $value) {
         \TemplateLoader::addFile($value, 'system/modules/sb-admin/templates/backend');
     }
 }
 public function addTokens(Message $objMessage, &$arrTokens, $strLanguage, $objGatewayModel)
 {
     if (($objNotification = $objMessage->getRelated('pid')) === null || !$objNotification->type) {
         return true;
     }
     // check for submission id
     if (!is_numeric($arrTokens['tl_submission'])) {
         return true;
     }
     if (($objSubmission = SubmissionModel::findByPk($arrTokens['tl_submission'])) === null) {
         return true;
     }
     if (!is_array($GLOBALS['SUBMISSION_RELATIONS'])) {
         return true;
     }
     foreach ($GLOBALS['SUBMISSION_RELATIONS'] as $strKey => $arrRelation) {
         if (!$arrRelation['table'] || !$arrRelation['submissionField']) {
             continue;
         }
         if ($objSubmission->{$arrRelation['submissionField']} < 1) {
             continue;
         }
         if (($objItem = SubmissionCreator::findRelatedEntity($objSubmission->{$arrRelation['submissionField']}, $arrRelation)) === null) {
             continue;
         }
         \Controller::loadDataContainer($arrRelation['table']);
         $objDc = new DC_Hybrid($arrRelation['table']);
         $objDc->activeRecord = $objItem;
         $arrData = SubmissionModel::prepareData($objItem, $arrRelation['table'], $GLOBALS['TL_DCA'][$arrRelation['table']], $objDc);
         $arrTokens = array_merge($arrTokens, SubmissionModel::tokenizeData($arrData, 'event'));
         // Options callback
         if (is_array($arrRelation['addTokens_callback']) && isset($arrCallback[0]) && class_exists($arrCallback[0])) {
             $arrCallback = $arrRelation['addTokens_callback'];
             $arrTokens = \Controller::importStatic($arrCallback[0])->{$arrCallback}[1]($objItem, $arrTokens, $arrRelation, $objNotification, $strLanguage, $objGatewayModel);
         } elseif (is_callable($arrRelation['addTokens_callback'])) {
             $arrTokens = $arrRelation['addTokens_callback']($objItem, $arrTokens, $arrRelation, $objNotification, $strLanguage, $objGatewayModel);
         }
     }
     return true;
 }
 public static function prepareSpecialValueForPrint($varValue, $arrData, $strTable, $objDc, $objItem = null)
 {
     $varValue = deserialize($varValue);
     $arrOpts = $arrData['options'];
     $arrReference = $arrData['reference'];
     $strRegExp = $arrData['eval']['rgxp'];
     // get options
     if ((is_array($arrData['options_callback']) || is_callable($arrData['options_callback'])) && !$arrData['reference']) {
         if (is_array($arrData['options_callback'])) {
             $strClass = $arrData['options_callback'][0];
             $strMethod = $arrData['options_callback'][1];
             $objInstance = \Controller::importStatic($strClass);
             $arrOptionsCallback = @$objInstance->{$strMethod}($objDc);
         } elseif (is_callable($arrData['options_callback'])) {
             $arrOptionsCallback = @$arrData['options_callback']($objDc);
         }
         $arrOptions = !is_array($varValue) ? array($varValue) : $varValue;
         if ($varValue !== null && is_array($arrOptionsCallback)) {
             $varValue = array_intersect_key($arrOptionsCallback, array_flip($arrOptions));
         }
     }
     if ($arrData['inputType'] == 'explanation') {
         $varValue = $arrData['eval']['text'];
     } elseif ($strRegExp == 'date') {
         $varValue = \Date::parse(\Config::get('dateFormat'), $varValue);
     } elseif ($strRegExp == 'time') {
         $varValue = \Date::parse(\Config::get('timeFormat'), $varValue);
     } elseif ($strRegExp == 'datim') {
         $varValue = \Date::parse(\Config::get('datimFormat'), $varValue);
     } elseif ($arrData['inputType'] == 'tag' && in_array('tags_plus', \ModuleLoader::getActive())) {
         if (($arrTags = \HeimrichHannot\TagsPlus\TagsPlus::loadTags($strTable, $objItem->id)) !== null) {
             $varValue = $arrTags;
         }
     } elseif (!is_array($varValue) && \Validator::isBinaryUuid($varValue)) {
         $strPath = Files::getPathFromUuid($varValue);
         $varValue = $strPath ? \Environment::get('url') . '/' . $strPath : \StringUtil::binToUuid($varValue);
     } elseif (is_array($varValue)) {
         $varValue = Arrays::flattenArray($varValue);
         $varValue = array_filter($varValue);
         // remove empty elements
         // transform binary uuids to paths
         $varValue = array_map(function ($varValue) {
             if (\Validator::isBinaryUuid($varValue)) {
                 $strPath = Files::getPathFromUuid($varValue);
                 if ($strPath) {
                     return \Environment::get('url') . '/' . $strPath;
                 }
                 return \StringUtil::binToUuid($varValue);
             }
             return $varValue;
         }, $varValue);
         if (!$arrReference) {
             $varValue = array_map(function ($varValue) use($arrOpts) {
                 return isset($arrOpts[$varValue]) ? $arrOpts[$varValue] : $varValue;
             }, $varValue);
         }
         $varValue = array_map(function ($varValue) use($arrReference) {
             if (is_array($arrReference)) {
                 return isset($arrReference[$varValue]) ? is_array($arrReference[$varValue]) ? $arrReference[$varValue][0] : $arrReference[$varValue] : $varValue;
             } else {
                 return $varValue;
             }
         }, $varValue);
     } else {
         if ($arrData['eval']['isBoolean'] || $arrData['inputType'] == 'checkbox' && !$arrData['eval']['multiple']) {
             $varValue = $varValue != '' ? $GLOBALS['TL_LANG']['MSC']['yes'] : $GLOBALS['TL_LANG']['MSC']['no'];
         } elseif (is_array($arrOpts) && array_is_assoc($arrOpts)) {
             $varValue = isset($arrOpts[$varValue]) ? $arrOpts[$varValue] : $varValue;
         } elseif (is_array($arrReference)) {
             $varValue = isset($arrReference[$varValue]) ? is_array($arrReference[$varValue]) ? $arrReference[$varValue][0] : $arrReference[$varValue] : $varValue;
         }
     }
     if (is_array($varValue)) {
         $varValue = implode(', ', $varValue);
     }
     // Convert special characters (see #1890)
     return specialchars($varValue);
 }
 public function generateFields($ajaxId = null)
 {
     $arrFields = $this->arrEditable;
     $arrSubFields = array();
     $blnAjax = false;
     // subpalettes
     $arrSelectors = $this->dca['palettes']['__selector__'];
     if (is_array($arrSelectors)) {
         $toggleSubpalette = str_replace('sub_', '', $ajaxId);
         foreach ($arrSelectors as $strName) {
             list($blnActive, $strSubPalette, $arrFields, $arrSubPaletteFields, $blnAutoSubmit, $blnToggleSubpalette) = $this->retrieveSubpaletteWithState($strName, $arrFields);
             if (!$blnToggleSubpalette) {
                 continue;
             }
             // active by default
             if ($blnActive) {
                 // selector field is visible
                 if (in_array($strName, $this->arrEditable)) {
                     if (is_array($arrSubPaletteFields) && is_array($arrFields)) {
                         $arrFields = array_diff($arrFields, $arrSubPaletteFields);
                     }
                     $arrSubFields[$strName] = $arrSubPaletteFields;
                 } else {
                     // do nothing, fields should remain in $arrFields
                 }
             } else {
                 // remove permanent subpalette fields from $arrSubPaletteFields
                 if (is_array($arrSubPaletteFields) && is_array($this->arrPermanentFields)) {
                     $arrSubPaletteFields = array_diff($arrSubPaletteFields, $this->arrPermanentFields);
                 }
                 // subpalette fields should not remain in arrFields, they belong to parent field
                 if (is_array($arrSubPaletteFields) && is_array($arrFields)) {
                     $arrFields = array_diff($arrFields, $arrSubPaletteFields);
                 }
             }
             // if subpalette is requested, set state to active, clear parent fields and break
             if ($toggleSubpalette == $strName) {
                 $blnAjax = true;
                 $arrFields = array($strName);
                 $arrSubFields = array($strName => $arrSubPaletteFields);
                 break;
                 // this function can only return one subpalette at once
             }
         }
         // check for active palette from typeselector
         foreach ($arrSelectors as $strSelector) {
             $varValue = $this->getFieldValue($strSelector);
             $strPalette = $this->dca['palettes'][$varValue];
             $arrOptions = deserialize($this->dca['fields'][$strSelector]['options'], true);
             $arrCallback = $this->dca['fields'][$strSelector]['options_callback'];
             if (is_array($arrCallback) && class_exists($arrCallback[0])) {
                 $objInstance = \Controller::importStatic($arrCallback[0]);
                 $arrOptions = $objInstance->{$arrCallback}[1]($this);
             }
             if ($varValue && isset($this->dca['palettes'][$varValue]) && $strPalette && in_array($varValue, $arrOptions)) {
                 // no messages
                 $this->setSilentMode($this->isSkipValidation());
                 $this->dca['fields'][$strSelector]['eval']['skipValidationOnSubmit'] = true;
                 // remove fields not existing in the current palette
                 $arrFields = array_intersect($arrFields, array_merge(FormHelper::getPaletteFields($this->strTable, $strPalette), $this->arrPermanentFields));
                 // only one palette can be active at a time
                 $this->activePalette = $varValue;
                 break;
             }
         }
     }
     // add palette fields
     foreach ($arrFields as $strName) {
         $this->addField($strName);
     }
     // add subpalette fields
     foreach ($arrSubFields as $strParent => $arrFields) {
         // check if subpalette has fields
         if (empty($arrFields)) {
             continue;
         }
         // skip field, if parent selector is not active
         if (!is_array($this->arrFields) || !isset($this->arrFields[$strParent])) {
             continue;
         }
         foreach ($arrFields as $strName) {
             $this->addSubField($strName, $strParent, $blnAjax);
         }
         if (!$blnAjax) {
             $objSubTemplate = $this->generateSubpalette('sub_' . $strParent);
             // parent field must exist
             if (!$this->arrFields[$strParent]) {
                 $this->addField($strParent);
             }
             // append subfields to parent field
             if ($this->arrFields[$strParent]) {
                 $this->arrFields[$strParent]->sub = \Controller::replaceInsertTags($objSubTemplate->parse(), false);
                 $this->arrFields[$strParent]->subName = $strParent;
             }
         }
     }
     // add submit button
     if (!$blnAjax) {
         $this->generateSubmitField();
     }
     if (!$this->async) {
         $this->generateFormIdentifierField();
     }
     return $blnAjax;
 }
 /**
  * Insert the data into the database.
  *
  * @param \FormFieldModel $field The related form field.
  * @param array           $data  The data being stored.
  *
  * @return void
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 private function insertIntoDatabase($field, $data)
 {
     if (!empty($data)) {
         // HOOK: add custom logic
         if (isset($GLOBALS['TL_HOOKS']['modifyLeadsDataOnStore']) && is_array($GLOBALS['TL_HOOKS']['modifyLeadsDataOnStore'])) {
             foreach ($GLOBALS['TL_HOOKS']['modifyLeadsDataOnStore'] as $callback) {
                 $object = \Controller::importStatic($callback[0]);
                 $object->{$callback}[1]($this->postData, $this->form, $this->files, $this->leadId, new Collection([$field], 'tl_form_field'), $data);
             }
         }
         \Database::getInstance()->prepare('INSERT INTO tl_lead_data %s')->set($data)->execute();
     }
 }
Example #10
0
 /**
  * Create separator elements.
  *
  * @param Helper           $wrapper Wrapper helper.
  * @param \Database\Result $record  Database result.
  * @param int              $sorting Sorting index.
  *
  * @return array|int
  */
 private function createSeparators($wrapper, $record, $sorting)
 {
     $config = Bootstrap::getConfigVar(sprintf('wrappers.%s.%s', $wrapper->getGroup(), Helper::TYPE_SEPARATOR));
     $callback = $config['count-existing'];
     $instance = \Controller::importStatic($callback[0]);
     $existing = $instance->{$callback}[1]($record, $wrapper);
     $callback = $config['count-required'];
     $instance = \Controller::importStatic($callback[0]);
     $required = $instance->{$callback}[1]($record, $wrapper);
     if ($existing < $required) {
         if ($this->isTrigger($wrapper->getType(), Helper::TYPE_SEPARATOR)) {
             $count = $required - $existing;
             for ($i = 0; $i < $count; $i++) {
                 $this->createElement($record, $sorting, Helper::TYPE_SEPARATOR);
             }
             $end = $wrapper->findRelatedElement(Helper::TYPE_STOP);
             if ($end && $end->sorting <= $sorting) {
                 $sorting = $sorting + 2;
                 $end->sorting = $sorting;
                 $end->save();
                 return array($sorting, $end);
             }
         }
     } elseif ($required < $existing) {
         if ($this->isTrigger($wrapper->getType(), Helper::TYPE_SEPARATOR, static::TRIGGER_DELETE)) {
             $count = $existing - $required;
             $parentId = $wrapper->isTypeOf(Helper::TYPE_START) ? $record->id : $record->bootstrap_parentId;
             \Database::getInstance()->prepare('DELETE FROM tl_content WHERE bootstrap_parentId=? AND type=? ORDER BY sorting DESC')->limit($count)->execute($parentId, $wrapper->getTypeName(Helper::TYPE_SEPARATOR));
         }
     }
     return $sorting;
 }
 /**
  * call callbacks in after generating output
  *
  * @param string
  * @param string
  *
  * @return string
  */
 public function onParseBackendTemplate($strContent, $strTemplate)
 {
     // check template
     if (!$this->useImprovedTheme() || !in_array($strTemplate, $GLOBALS['TL_CONFIG']['useBackendImprovedOnTemplates'])) {
         return $strContent;
     }
     // run through registered callbacks
     foreach ($this->arrCallbacks as $callback) {
         if (is_string($callback)) {
             $strContent = $this->{$callback}($strContent);
         } else {
             $callback = \Controller::importStatic($callback[0]);
             $strContent = $callback->{$callback}[1]($strContent);
         }
     }
     // add javascript to the body of the page
     if (!empty($this->arrScripts)) {
         ksort($this->arrScripts);
         $strGenerated = implode("\r\n", $this->arrScripts);
         $strContent = preg_replace('/<\\/body>/', '<script>window.addEvent(\'domready\', function (e) {' . "\r\n" . $strGenerated . '});</script>\\0', $strContent, 1);
     }
     return $strContent;
 }
 /**
  * Gets the available subpalettes and subpalettes with options from the palette
  *
  * @param array          $arrSubPalettes
  * @param array          $arrFieldsInPalette
  * @param \DataContainer $dc
  *
  * @return array
  */
 public static function getFilteredSubPalettes(array $arrSubPalettes, array $arrFieldsInPalette, \DataContainer $dc = null)
 {
     $arrFilteredSubPalettes = array();
     foreach ($arrFieldsInPalette as $strField) {
         if (in_array($strField, $arrSubPalettes)) {
             $arrFilteredSubPalettes[] = $strField;
             continue;
         }
         $arrField = $GLOBALS['TL_DCA'][$dc->activeRecord->formHybridDataContainer]['fields'][$strField];
         if (is_array($arrField['options']) && !empty($arrField['options'])) {
             foreach ($arrField['options'] as $strOption) {
                 $strSubPaletteName = $strField . '_' . $strOption;
                 if (in_array($strSubPaletteName, $arrSubPalettes)) {
                     $arrFilteredSubPalettes[] = $strSubPaletteName;
                 }
             }
             continue;
         }
         if (is_array($arrField['options_callback']) && !empty($arrField['options_callback']) && is_callable($arrField['options_callback'])) {
             $strClass = $arrField['options_callback'][0];
             $strMethod = $arrField['options_callback'][1];
             $objInstance = \Controller::importStatic($strClass);
             $arrOptions = $objInstance->{$strMethod}($dc);
             foreach ($arrOptions as $strOption) {
                 $strSubPaletteName = $strField . '_' . $strOption;
                 if (in_array($strSubPaletteName, $arrSubPalettes)) {
                     $arrFilteredSubPalettes[] = $strSubPaletteName;
                 }
             }
             continue;
         }
     }
     return $arrFilteredSubPalettes;
 }