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;
 }
 public static function checkPermissionForProtectedHomeDirs($strFile)
 {
     $strUuid = \Config::get('protectedHomeDirRoot');
     if (!$strFile) {
         return;
     }
     if ($strUuid && ($strProtectedHomeDirRootPath = \HeimrichHannot\HastePlus\Files::getPathFromUuid($strUuid)) !== null) {
         // check only if path inside the protected root dir
         if (StringUtil::startsWith($strFile, $strProtectedHomeDirRootPath)) {
             if (FE_USER_LOGGED_IN) {
                 if (($objFrontendUser = \FrontendUser::getInstance()) !== null) {
                     if (\Config::get('allowAccessByMemberId') && $objFrontendUser->assignProtectedDir && $objFrontendUser->protectedHomeDir) {
                         $strProtectedHomeDirMemberRootPath = Files::getPathFromUuid($objFrontendUser->protectedHomeDir);
                         // fe user id = dir owner member id
                         if (StringUtil::startsWith($strFile, $strProtectedHomeDirMemberRootPath)) {
                             return;
                         }
                     }
                     if (\Config::get('allowAccessByMemberGroups')) {
                         $arrAllowedGroups = deserialize(\Config::get('allowedMemberGroups'), true);
                         if (array_intersect(deserialize($objFrontendUser->groups, true), $arrAllowedGroups)) {
                             return;
                         }
                     }
                 }
             }
             $intNoAccessPage = \Config::get('jumpToNoAccess');
             if ($intNoAccessPage && ($objPageJumpTo = \PageModel::findByPk($intNoAccessPage)) !== null) {
                 \Controller::redirect(\Controller::generateFrontendUrl($objPageJumpTo->row()));
             } else {
                 die($GLOBALS['TL_LANG']['MSC']['noAccessDownload']);
             }
         }
     }
 }
 /**
  * Returns all classes in the given namespace
  * @param $strNamespace
  *
  * @return array
  */
 public static function getClassesInNamespace($strNamespace)
 {
     $arrOptions = array();
     foreach (array_keys(ClassLoader::getClasses()) as $strName) {
         if (StringUtil::startsWith($strName, $strNamespace)) {
             $arrOptions[$strName] = $strName;
         }
     }
     asort($arrOptions);
     return $arrOptions;
 }
 public static function generate($intLength = 8, $blnPreventAmbiguous = true, $arrAlphabets = null, $arrRules = null, $strAllowedSpecialChars = null)
 {
     $arrAlphabets = is_array($arrAlphabets) ? $arrAlphabets : static::$arrAlphabets;
     $arrRules = is_array($arrRules) ? $arrRules : static::$arrRules;
     $strAllowedSpecialChars = $strAllowedSpecialChars !== null ? $strAllowedSpecialChars : static::$strAllowedSpecialChars;
     $pwGen = new \PWGen($intLength, false, in_array(CodeGenerator::NUMBERS, $arrAlphabets) && in_array(CodeGenerator::NUMBERS, $arrRules), in_array(CodeGenerator::CAPITAL_LETTERS, $arrAlphabets) && in_array(CodeGenerator::CAPITAL_LETTERS, $arrRules), $blnPreventAmbiguous, false, in_array(CodeGenerator::SPECIAL_CHARS, $arrAlphabets) && in_array(CodeGenerator::SPECIAL_CHARS, $arrRules));
     $strCode = $pwGen->generate();
     // replace remaining ambiguous characters
     if ($blnPreventAmbiguous) {
         $arrCharReplacements = array('y', 'Y', 'z', 'Z', 'o', 'O', 'i', 'I', 'l');
         foreach ($arrCharReplacements as $strChar) {
             $strCode = str_replace($strChar, StringUtil::randomChar(!$blnPreventAmbiguous), $strCode);
         }
     }
     // apply allowed alphabets
     $strForbiddenPattern = '';
     $strAllowedChars = '';
     if (!in_array(CodeGenerator::CAPITAL_LETTERS, $arrAlphabets)) {
         $strForbiddenPattern .= 'A-Z';
     } else {
         $strAllowedChars .= $blnPreventAmbiguous ? StringUtil::CAPITAL_LETTERS_NONAMBIGUOUS : StringUtil::CAPITAL_LETTERS;
     }
     if (!in_array(CodeGenerator::SMALL_LETTERS, $arrAlphabets)) {
         $strForbiddenPattern .= 'a-z';
     } else {
         $strAllowedChars .= $blnPreventAmbiguous ? StringUtil::SMALL_LETTERS_NONAMBIGUOUS : StringUtil::SMALL_LETTERS;
     }
     if (!in_array(CodeGenerator::NUMBERS, $arrAlphabets)) {
         $strForbiddenPattern .= '0-9';
     } else {
         $strAllowedChars .= $blnPreventAmbiguous ? StringUtil::NUMBERS_NONAMBIGUOUS : StringUtil::NUMBERS;
     }
     if ($strForbiddenPattern) {
         $strCode = preg_replace_callback('@[' . $strForbiddenPattern . ']{1}@', function () use($strAllowedChars) {
             return StringUtil::random($strAllowedChars);
         }, $strCode);
     }
     // special chars
     if (!in_array(CodeGenerator::SPECIAL_CHARS, $arrAlphabets)) {
         $strCode = preg_replace_callback('@[^' . $strAllowedChars . ']{1}@', function () use($strAllowedChars) {
             return StringUtil::random($strAllowedChars);
         }, $strCode);
     } else {
         $strCode = preg_replace_callback('@[^' . $strAllowedChars . ']{1}@', function () use($strAllowedSpecialChars) {
             return StringUtil::random($strAllowedSpecialChars);
         }, $strCode);
     }
     return $strCode;
 }
 /**
  * Remove isotope js, as we dont want to use mootools
  *
  * @param $strBuffer
  *
  * @return mixed
  */
 public function hookReplaceDynamicScriptTags($strBuffer)
 {
     if (!is_array($GLOBALS['TL_JAVASCRIPT'])) {
         return $strBuffer;
     }
     $arrJs = $GLOBALS['TL_JAVASCRIPT'];
     foreach ($arrJs as $key => $strValue) {
         $arrData = trimsplit('|', $strValue);
         if (\HeimrichHannot\Haste\Util\StringUtil::endsWith($arrData[0], 'system/modules/isotope/assets/js/isotope.min.js')) {
             unset($GLOBALS['TL_JAVASCRIPT'][$key]);
             break;
         }
     }
     return $strBuffer;
 }
 /**
  * Filter out values from an Array by given prefixes
  *
  * @param array  $arrData
  * @param array  $arrPrefixes
  *
  * @return array the filtered array or $arrData if $strPrefix is empty
  */
 public static function filterOutByPrefixes(array $arrData = array(), $arrPrefixes = array())
 {
     $arrExtract = array();
     if (!is_array($arrPrefixes) || empty($arrPrefixes)) {
         return $arrData;
     }
     foreach ($arrData as $key => $value) {
         foreach ($arrPrefixes as $strPrefix) {
             if (\HeimrichHannot\Haste\Util\StringUtil::startsWith($key, $strPrefix)) {
                 continue;
             }
             $arrExtract[$key] = $value;
         }
     }
     return $arrExtract;
 }
 /**
  * Replace modal inserttags
  *
  * @param $strTag
  * @param $blnCache
  * @param $strCacheTag
  * @param $flags
  * @param $tags
  * @param $arrCache
  * @param $index
  * @param $count
  *
  * @return string
  */
 public function replaceModalInsertTags($strTag, $blnCache, $strCacheTag, $flags, $tags, $arrCache, $index, $count)
 {
     $params = preg_split('/::/', $strTag);
     if (!is_array($params) || empty($params) || !\HeimrichHannot\Haste\Util\StringUtil::startsWith($params[0], 'modal_')) {
         return false;
     }
     switch ($params[0]) {
         case 'modal_link':
             $objModal = ModalModel::findPublishedByIdOrAlias($params[1]);
             if ($objModal === null) {
                 return '';
             }
             return static::generateModalLink($objModal->current(), $params[2], $params[3]);
             break;
         case 'modal_link_open':
             $objModal = ModalModel::findPublishedByIdOrAlias($params[1]);
             if ($objModal === null) {
                 return '';
             }
             $strBuffer = static::generateModalLink($objModal->current(), $params[2], '');
             preg_match('/(?P<start>.*<a[^<]+[^<]+ *[^\\/?]>)(?P<stop>.*)/is', $strBuffer, $matches);
             if (is_array($matches) && isset($matches['start']) && isset($matches['stop'])) {
                 return $matches['start'];
             }
             return false;
             break;
         case 'modal_link_close':
             $objModal = ModalModel::findPublishedByIdOrAlias($params[1]);
             if ($objModal === null) {
                 return '';
             }
             $strBuffer = static::generateModalLink($objModal->current(), $params[2], '');
             preg_match('/(?P<start>.*<a[^<]+[^<]+ *[^\\/?]>)(?P<stop>.*)/is', $strBuffer, $matches);
             if (is_array($matches) && isset($matches['start']) && isset($matches['stop'])) {
                 return $matches['stop'];
             }
             return false;
             break;
         case 'modal_url':
             $objModal = ModalModel::findPublishedByIdOrAlias($params[1]);
             if ($objModal === null) {
                 return '';
             }
             return static::generateModalUrl($objModal->row(), $params[2]);
             break;
     }
 }
 public static function replaceRelation(array $arrRelation, $strTag)
 {
     $params = preg_split('/::/', $strTag);
     if (!isset($arrRelation['insertTagLink']) || !isset($arrRelation['table'])) {
         return false;
     }
     $relParams = str_replace(array('{', '}'), '', $arrRelation['insertTagLink']);
     $relParams = preg_split('/::/', $relParams);
     // check if given relation inserttag is provided
     if ($relParams[0] != $params[0]) {
         return false;
     }
     $pageId = null;
     $moduleId = null;
     $entityId = null;
     if (($pageIdx = array_search('PAGE_ID', $relParams)) !== false) {
         $pageId = $params[$pageIdx];
     }
     if (($entityIdx = array_search('ENTITY_ID', $relParams)) !== false) {
         $entityId = $params[$entityIdx];
     }
     if (($moduleIdx = array_search('MODULE_ID', $relParams)) !== false) {
         $moduleId = $params[$moduleIdx];
     }
     if ($pageId === null || ($objPage = \PageModel::findPublishedByIdOrAlias($pageId)) === null) {
         return false;
     }
     if ($moduleId === null || ($objModule = \ModuleModel::findByPk($moduleId)) === null) {
         return false;
     }
     if ($entityId === null || ($objEntity = SubmissionCreator::findRelatedEntity($entityId, $arrRelation, $objModule->current())) === null) {
         return false;
     }
     if (StringUtil::endsWith($params[0], '_link')) {
         return SubmissionCreator::getRelationLink($objPage->current(), $objEntity->current(), $arrRelation);
     }
     return false;
 }
 public static function findCurrentByPidAndFilter($arrPids, $intStart, $intEnd, array $arrFilter = array(), array $arrFilterOptions = array(), $arrFilterConfig = array(), $arrOptions = array(), $count = false)
 {
     $t = static::$strTable;
     $intStart = intval($intStart);
     $intEnd = intval($intEnd);
     $arrPids = !is_array($arrPids) ? array($arrPids) : $arrPids;
     $arrColumns[] = "({$t}.pid IN (" . implode(',', $arrPids) . "))";
     $arrColumnsOr = array();
     foreach ($arrFilter as $key => $value) {
         $arrValueOptions = isset($arrFilterOptions[$key]) && is_array($arrFilterOptions[$key]) ? $arrFilterOptions[$key] : array();
         switch ($key) {
             case 'startDate':
                 if ($value && $value >= $intStart) {
                     $intStart = $value;
                 }
                 break;
             case 'endDate':
                 if ($value && $value <= $intEnd) {
                     $intEnd = strtotime(date('d.m.Y', $value) . ' 23:59:59');
                     // until last second of the day
                 }
                 break;
             case 'dates':
                 if ($value != '') {
                     $strQuery = '';
                     $valueArray = trimsplit(',', $value);
                     foreach ($valueArray as $key => $strDate) {
                         $intDate = strtotime($strDate);
                         if ($key > 0) {
                             $strQuery .= " OR ((({$t}.endDate IS NULL OR {$t}.endDate = '') AND {$t}.startDate = {$intDate}) OR (({$t}.startDate = '' OR {$t}.startDate <= {$intDate}) AND {$t}.endDate >= {$intDate}))";
                         } else {
                             $strQuery = "((({$t}.endDate IS NULL OR {$t}.endDate = '') AND {$t}.startDate = {$intDate}) OR (({$t}.startDate = '' OR {$t}.startDate <= {$intDate}) AND {$t}.endDate >= {$intDate}))";
                         }
                     }
                     $arrColumns[] = '(' . $strQuery . ')';
                 }
                 break;
             case 'promoter':
             case 'areasoflaw':
                 if ($value != '') {
                     $valueArray = trimsplit(',', $value);
                     // permit intersections only
                     if (!empty($arrValueOptions)) {
                         $valueArray = array_intersect($valueArray, $arrValueOptions);
                     }
                     if (is_array($valueArray) && !empty($valueArray)) {
                         if ($arrFilterConfig['show_related']) {
                             $arrColumnsOr[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.{$key}", $valueArray, EVENTMODEL_CONDITION_OR);
                         } else {
                             $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.{$key}", $valueArray);
                         }
                     }
                 } else {
                     if (!empty($arrValueOptions)) {
                         $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.{$key}", $arrValueOptions);
                     }
                 }
                 break;
             case strrpos($key, 'eventtypes', -strlen($key)) !== FALSE:
                 if ($value != '') {
                     $valueArray = trimsplit(',', $value);
                     // permit intersections only
                     if (!empty($arrValueOptions)) {
                         $valueArray = array_intersect($valueArray, $arrValueOptions);
                     }
                     if (is_array($valueArray) && !empty($valueArray)) {
                         if ($arrFilterConfig['show_related']) {
                             $arrColumnsOr[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.eventtypes", $valueArray, EVENTMODEL_CONDITION_OR);
                         } else {
                             $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.eventtypes", $valueArray, EVENTMODEL_CONDITION_AND);
                         }
                     }
                 } else {
                     if (!empty($arrValueOptions)) {
                         $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.eventtypes", $arrValueOptions);
                     }
                 }
                 break;
             case 'docents':
             case 'hosts':
                 if ($value != '') {
                     $valueArray = trimsplit(',', $value);
                     if (is_array($valueArray) && !empty($valueArray)) {
                         $arrDocents = array();
                         $arrMembers = array();
                         $arrHosts = array();
                         foreach ($valueArray as $id) {
                             // docent
                             if (\HeimrichHannot\Haste\Util\StringUtil::startsWith($id, 'd')) {
                                 $arrDocents[] = substr($id, 1);
                             } else {
                                 if (\HeimrichHannot\Haste\Util\StringUtil::startsWith($id, 'm')) {
                                     $arrMembers[] = substr($id, 1);
                                 } else {
                                     if (\HeimrichHannot\Haste\Util\StringUtil::startsWith($id, 'h')) {
                                         $arrHosts[] = substr($id, 1);
                                     }
                                 }
                             }
                         }
                         if (!empty($arrDocents)) {
                             if (is_array($valueArray) && !empty($valueArray)) {
                                 if ($arrFilterConfig['show_related']) {
                                     $arrColumnsOr[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.docents", $arrDocents, EVENTMODEL_CONDITION_OR);
                                 } else {
                                     $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.docents", $arrDocents);
                                 }
                             }
                         }
                         if (!empty($arrMembers)) {
                             if (is_array($valueArray) && !empty($valueArray)) {
                                 if ($arrFilterConfig['show_related'] || $arrFilterConfig['combine_docents']) {
                                     $arrColumnsOr[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.memberdocents", $arrMembers, EVENTMODEL_CONDITION_OR);
                                     if ($key = 'hosts' || $key == 'docents' && $arrFilterConfig['combine_docents']) {
                                         $arrColumnsOr[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.memberhosts", $arrMembers, EVENTMODEL_CONDITION_OR);
                                     }
                                 } else {
                                     $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.memberdocents", $arrMembers);
                                     if ($key = 'hosts' || $key == 'docents' && $arrFilterConfig['combine_docents']) {
                                         $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.memberhosts", $arrMembers);
                                     }
                                 }
                             }
                         }
                         if (!empty($arrHosts) && ($key = 'hosts' || $key == 'docents' && $arrFilterConfig['cal_docent_combine'])) {
                             if (is_array($valueArray) && !empty($valueArray)) {
                                 if ($arrFilterConfig['show_related']) {
                                     $arrColumnsOr[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.hosts", $arrHosts, EVENTMODEL_CONDITION_OR);
                                 } else {
                                     $arrColumns[] = EventModelHelper::createMySQLRegexpForMultipleIds("{$t}.hosts", $arrHosts);
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 'postal':
                 if ($value != '') {
                     $arrColumns[] = "LEFT({$t}.postal, 1) = ?";
                     $arrValues[] = $value;
                 }
                 break;
             case 'timeHours':
                 if ($value != '') {
                     $arrColumns[] = "({$t}.{$key} >= {$value} AND {$t}.{$key} < ({$value} + 1))";
                 }
                 break;
             case 'q':
                 if ($value != '' && is_array($arrFilterConfig['jumpTo'])) {
                     try {
                         $objSearch = \Search::searchFor($value, $arrFilterConfig['module']['queryType'] == 'or', $arrFilterConfig['jumpTo'], 0, 0, $arrFilterConfig['module']['fuzzy']);
                         // return if keyword not found
                         if ($objSearch->numRows < 1) {
                             return null;
                         }
                         $arrUrls = $objSearch->fetchEach('url');
                         $strKeyWordColumns = "";
                         $n = 0;
                         foreach ($arrUrls as $i => $strAlias) {
                             $strKeyWordColumns .= ($n > 0 ? " OR " : "") . "{$t}.alias = ?";
                             $arrValues[] = basename($strAlias);
                             $n++;
                         }
                         $arrColumns[] = "({$strKeyWordColumns})";
                     } catch (\Exception $e) {
                         \System::log('Website search failed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
                     }
                 }
                 break;
             default:
                 if ($value != '') {
                     $arrColumns[] = "{$t}.{$key}=?";
                     $arrValues[] = $value;
                 }
         }
     }
     $arrColumns[] = "(({$t}.startTime>={$intStart} AND {$t}.startTime<={$intEnd}) OR ({$t}.endTime>={$intStart} AND {$t}.endTime<={$intEnd}) OR ({$t}.startTime<={$intStart} AND {$t}.endTime>={$intEnd}) OR ({$t}.recurring=1 AND ({$t}.recurrences=0 OR {$t}.repeatEnd>={$intStart}) AND {$t}.startTime<={$intEnd}))";
     if (!BE_USER_LOGGED_IN) {
         $time = time();
         $arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.published=1";
     }
     // for related search
     if (!empty($arrColumnsOr)) {
         $arrColumns[] = implode(' OR ', $arrColumnsOr);
     }
     if (!isset($arrOptions['order'])) {
         $arrOptions['order'] = "{$t}.startTime";
     }
     if ($count) {
         return static::countBy($arrColumns, $arrValues, $arrOptions);
     }
     return static::findBy($arrColumns, $arrValues, $arrOptions);
 }
 public static function getSortOptions()
 {
     $ref = new \ReflectionClass(__CLASS__);
     $arrOptions = array();
     foreach ($ref->getConstants() as $key => $value) {
         if (!\HeimrichHannot\Haste\Util\StringUtil::startsWith($key, 'FILECREDIT_SORTBY')) {
             continue;
         }
         $arrOptions[] = $value;
     }
     return $arrOptions;
 }
 /**
  * @dataProvider endsWithProvider
  * @test
  */
 public function testEndsWith($haystack, $needle, $expectedResult)
 {
     $this->assertSame($expectedResult, StringUtil::endsWith($haystack, $needle));
 }
 /**
  * Check if the key starts with 'formHybrid'
  *
  * @param $strKey
  *
  * @return bool
  */
 public static function isLegacyKey($strKey)
 {
     return StringUtil::startsWith($strKey, 'formHybrid');
 }
 public function addTwitterBootstrap()
 {
     $arrJs = $GLOBALS['TL_JAVASCRIPT'];
     // do not include more than once
     if (isset($arrJs['bootstrap'])) {
         return false;
     }
     $in = BOOTSTRAPJSDIR . 'bootstrap' . (!$GLOBALS['TL_CONFIG']['debugMode'] ? '.min' : '') . '.js';
     if (!file_exists(TL_ROOT . '/' . $in)) {
         return false;
     }
     $intJqueryIndex = 0;
     $i = 0;
     // detemine jquery index from file name, as we should append bootstrapper always after jquery
     foreach ($arrJs as $index => $strFile) {
         if (!StringUtil::endsWith($strFile, 'jquery.min.js|static')) {
             $i++;
             continue;
         }
         $intJqueryIndex = $i + 1;
         break;
     }
     array_insert($arrJs, $intJqueryIndex, array('bootstrap' => $in . (!$GLOBALS['TL_CONFIG']['debugMode'] ? '|static' : '')));
     $GLOBALS['TL_JAVASCRIPT'] = $arrJs;
 }
 /**
  * Get relation table, field and model class, from a foreignKey
  *
  * @param $varValue The foreignKey as String (e.g tl_page.id)
  *
  * @return array|bool Return list with relation table, field and model class or false if no valid foreignKey
  */
 protected function getRelationData($varValue)
 {
     $arrRelation = trimsplit('.', $varValue);
     if (is_array($arrRelation) && !$arrRelation[0]) {
         return false;
     }
     $strTable = $arrRelation[0];
     $strField = $arrRelation[1];
     if (\HeimrichHannot\Haste\Util\StringUtil::startsWith($arrRelation[0], '%') && \HeimrichHannot\Haste\Util\StringUtil::endsWith($arrRelation[0], '%')) {
         $strField = str_replace('%', '', $arrRelation[0]);
         if (!$this->activeRecord->{$strField}) {
             return false;
         }
         $strTable = $this->activeRecord->{$strField};
     }
     $strModelClass = \Model::getClassFromTable($strTable);
     if (!class_exists($strModelClass)) {
         return false;
     }
     return array($strTable, $strField, $strModelClass);
 }
 public function moveFiles(\DataContainer $dc)
 {
     $arrPost = Request::getPost();
     foreach ($arrPost as $key => $value) {
         $arrData = $GLOBALS['TL_DCA'][$dc->table]['fields'][$key];
         if ($arrData['inputType'] != MultiFileUpload::NAME) {
             continue;
         }
         $arrFiles = deserialize($dc->activeRecord->{$key});
         $strUploadFolder = Files::getFolderFromDca($arrData['eval']['uploadFolder'], $dc);
         if ($strUploadFolder === null) {
             throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['uploadNoUploadFolderDeclared'], $key, MultiFileUpload::UPLOAD_TMP));
         }
         if (!is_array($arrFiles)) {
             $arrFiles = array($arrFiles);
         }
         $objFileModels = FilesModel::findMultipleByUuids($arrFiles);
         if ($objFileModels === null) {
             continue;
         }
         $arrPaths = $objFileModels->fetchEach('path');
         $arrTargets = array();
         // do not loop over $objFileModels as $objFile->close() will pull models away
         foreach ($arrPaths as $strPath) {
             $objFile = new \File($strPath);
             $strName = $objFile->name;
             $strTarget = $strUploadFolder . '/' . $strName;
             // upload_path_callback
             if (is_array($arrData['upload_path_callback'])) {
                 foreach ($arrData['upload_path_callback'] as $callback) {
                     $strTarget = \System::importStatic($callback[0])->{$callback[1]}($strTarget, $objFile, $dc) ?: $strTarget;
                 }
             }
             if (StringUtil::startsWith($objFile->path, ltrim($strTarget, '/'))) {
                 continue;
             }
             if ($objFile->renameTo($strTarget)) {
                 $arrTargets[] = $strTarget;
                 $objFile->close();
                 continue;
             }
             $arrTargets[] = $strPath;
         }
         // HOOK: post upload callback
         if (isset($GLOBALS['TL_HOOKS']['postUpload']) && is_array($GLOBALS['TL_HOOKS']['postUpload'])) {
             foreach ($GLOBALS['TL_HOOKS']['postUpload'] as $callback) {
                 if (is_array($callback)) {
                     \System::importStatic($callback[0])->{$callback[1]}($arrTargets);
                 } elseif (is_callable($callback)) {
                     $callback($arrTargets);
                 }
             }
         }
     }
 }
 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 static function tokenizeData(array $arrSubmissionData = array(), $strPrefix = 'form')
 {
     $arrTokens = array();
     foreach ($arrSubmissionData as $strName => $arrData) {
         if (!is_array($arrData)) {
             if ($strName != 'submission' && $strName != 'submission_all' && !is_object($arrData)) {
                 $arrTokens[$strName] = $arrData;
                 continue;
             } else {
                 continue;
             }
         }
         foreach ($arrData as $strType => $varValue) {
             switch ($strType) {
                 case 'output':
                     $arrTokens[$strPrefix . '_' . $strName] = $varValue;
                     $arrTokens[$strPrefix . '_plain_' . $strName] = \HeimrichHannot\Haste\Util\StringUtil::convertToText(\StringUtil::decodeEntities($varValue), true);
                     break;
                 case 'value':
                     // check for values causing notification center's json_encode call to fail (unprintable characters like binary!)
                     if (ctype_print($varValue)) {
                         $arrTokens[$strPrefix . '_value_' . $strName] = $varValue;
                     }
                     break;
                 case 'submission':
                     $arrTokens[$strPrefix . '_submission_' . $strName] = rtrim($varValue, "\n");
                     break;
             }
         }
     }
     // token: ##formsubmission_all##
     if (isset($arrSubmissionData['submission_all'])) {
         $arrTokens[$strPrefix . 'submission_all'] = $arrSubmissionData['submission_all'];
     }
     // token: ##formsubmission##
     if (isset($arrSubmissionData['submission'])) {
         $arrTokens[$strPrefix . 'submission'] = $arrSubmissionData['submission'];
     }
     // prepare attachments
     return $arrTokens;
 }
 public function prepareFile($varUuid)
 {
     if (($objFile = Files::getFileFromUuid($varUuid, true)) !== null && $objFile->exists()) {
         static::addAllowedDownload($objFile->value);
         $arrReturn = array('name' => StringUtil::preg_replace_last('@_[a-f0-9]{13}@', $objFile->name), 'uuid' => \StringUtil::binToUuid($objFile->getModel()->uuid), 'size' => $objFile->filesize);
         if (($strImage = $this->getPreviewImage($objFile)) !== null) {
             $arrReturn['url'] = $strImage;
         }
         if (($strInfoUrl = $this->getInfoAction($objFile)) !== null) {
             $arrReturn['info'] = $strInfoUrl;
         }
         return $arrReturn;
     }
     return false;
 }