/**
  * Loads Page TSconfig until the outermost template record and parses the configuration - if TSFE.constants object path is found it is merged with the default data in here!
  *
  * @param	array		Constants array, default input.
  * @return	array		Constants array, modified
  * @todo	Apply caching to the parsed Page TSconfig. This is done in the other similar functions for both frontend and backend. However, since this functions works for BOTH frontend and backend we will have to either write our own local caching function or (more likely) detect if we are in FE or BE and use caching functions accordingly. Not having caching affects mostly the backend modules inside the "Template" module since the overhead in the frontend is only seen when TypoScript templates are parsed anyways (after which point they are cached anyways...)
  */
 function mergeConstantsFromPageTSconfig($constArray)
 {
     $TSdataArray = array();
     $TSdataArray[] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
     // Setting default configuration:
     for ($a = 0; $a <= $this->outermostRootlineIndexWithTemplate; $a++) {
         $TSdataArray[] = $this->absoluteRootLine[$a]['TSconfig'];
     }
     // Parsing the user TS (or getting from cache)
     $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
     $userTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
     $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
     $parseObj->parse($userTS);
     if (is_array($parseObj->setup['TSFE.']['constants.'])) {
         $constArray = t3lib_div::array_merge_recursive_overrule($constArray, $parseObj->setup['TSFE.']['constants.']);
     }
     return $constArray;
 }
 /**
  * Returns the parsed TSconfig for the fe_user
  * First time this function is called it will parse the TSconfig and store it in $this->userTS. Subsequent requests will not re-parse the TSconfig but simply return what is already in $this->userTS
  *
  * @return	array		TSconfig array for the fe_user
  */
 function getUserTSconf()
 {
     if (!$this->userTSUpdated) {
         // Parsing the user TS (or getting from cache)
         $this->TSdataArray = t3lib_TSparser::checkIncludeLines_array($this->TSdataArray);
         $userTS = implode(LF . '[GLOBAL]' . LF, $this->TSdataArray);
         $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
         $parseObj->parse($userTS);
         $this->userTS = $parseObj->setup;
         $this->userTSUpdated = 1;
     }
     return $this->userTS;
 }
 /**
  * Returns the Page TSconfig for page with id, $id
  * Requires class "t3lib_TSparser"
  * Usage: 26 (spec. in ext info_pagetsconfig)
  *
  * @param	integer		Page uid for which to create Page TSconfig
  * @param	array		If $rootLine is an array, that is used as rootline, otherwise rootline is just calculated
  * @param	boolean		If $returnPartArray is set, then the array with accumulated Page TSconfig is returned non-parsed. Otherwise the output will be parsed by the TypoScript parser.
  * @return	array		Page TSconfig
  * @see t3lib_TSparser
  */
 public static function getPagesTSconfig($id, $rootLine = '', $returnPartArray = 0)
 {
     $id = intval($id);
     if (!is_array($rootLine)) {
         $rootLine = self::BEgetRootLine($id, '', TRUE);
     }
     ksort($rootLine);
     // Order correctly
     $TSdataArray = array();
     $TSdataArray['defaultPageTSconfig'] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
     // Setting default configuration:
     foreach ($rootLine as $k => $v) {
         $TSdataArray['uid_' . $v['uid']] = $v['TSconfig'];
     }
     $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
     if ($returnPartArray) {
         return $TSdataArray;
     }
     // Parsing the page TS-Config (or getting from cache)
     $pageTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
     if ($GLOBALS['TYPO3_CONF_VARS']['BE']['TSconfigConditions']) {
         /* @var $parseObj t3lib_TSparser_TSconfig */
         $parseObj = t3lib_div::makeInstance('t3lib_TSparser_TSconfig');
         $res = $parseObj->parseTSconfig($pageTS, 'PAGES', $id, $rootLine);
         if ($res) {
             $TSconfig = $res['TSconfig'];
         }
     } else {
         $hash = md5('pageTS:' . $pageTS);
         $cachedContent = self::getHash($hash);
         $TSconfig = array();
         if (isset($cachedContent)) {
             $TSconfig = unserialize($cachedContent);
         } else {
             $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
             $parseObj->parse($pageTS);
             $TSconfig = $parseObj->setup;
             self::storeHash($hash, serialize($TSconfig), 'PAGES_TSconfig');
         }
     }
     // get User TSconfig overlay
     $userTSconfig = $GLOBALS['BE_USER']->userTS['page.'];
     if (is_array($userTSconfig)) {
         $TSconfig = t3lib_div::array_merge_recursive_overrule($TSconfig, $userTSconfig);
     }
     return $TSconfig;
 }
 /**
  * Returns the pages TSconfig array based on the currect ->rootLine
  *
  * @return	array
  */
 function getPagesTSconfig()
 {
     if (!is_array($this->pagesTSconfig)) {
         $TSdataArray = array();
         $TSdataArray[] = $this->TYPO3_CONF_VARS['BE']['defaultPageTSconfig'];
         // Setting default configuration:
         foreach ($this->rootLine as $k => $v) {
             $TSdataArray[] = $v['TSconfig'];
         }
         // Parsing the user TS (or getting from cache)
         $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
         $userTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
         $hash = md5('pageTS:' . $userTS);
         $cachedContent = $this->sys_page->getHash($hash);
         if (isset($cachedContent)) {
             $this->pagesTSconfig = unserialize($cachedContent);
         } else {
             $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
             $parseObj->parse($userTS);
             $this->pagesTSconfig = $parseObj->setup;
             $this->sys_page->storeHash($hash, serialize($this->pagesTSconfig), 'PAGES_TSconfig');
         }
     }
     return $this->pagesTSconfig;
 }
    /**
     * Initializes a lot of stuff like the access-lists, database-mountpoints and filemountpoints
     * This method is called by ->backendCheckLogin() (from extending class t3lib_beuserauth) if the backend user login has verified OK.
     * Generally this is required initialization of a backend user.
     *
     * @return	void
     * @access private
     * @see t3lib_TSparser
     */
    function fetchGroupData()
    {
        if ($this->user['uid']) {
            // Get lists for the be_user record and set them as default/primary values.
            $this->dataLists['modList'] = $this->user['userMods'];
            // Enabled Backend Modules
            $this->dataLists['allowed_languages'] = $this->user['allowed_languages'];
            // Add Allowed Languages
            $this->dataLists['workspace_perms'] = $this->user['workspace_perms'];
            // Set user value for workspace permissions.
            $this->dataLists['webmount_list'] = $this->user['db_mountpoints'];
            // Database mountpoints
            $this->dataLists['filemount_list'] = $this->user['file_mountpoints'];
            // File mountpoints
            $this->dataLists['fileoper_perms'] = (int) $this->user['fileoper_perms'];
            // Fileoperation permissions
            // Setting default User TSconfig:
            $this->TSdataArray[] = $this->addTScomment('From $GLOBALS["TYPO3_CONF_VARS"]["BE"]["defaultUserTSconfig"]:') . $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'];
            // Default TSconfig for admin-users
            if ($this->isAdmin()) {
                $this->TSdataArray[] = $this->addTScomment('"admin" user presets:') . '
					admPanel.enable.all = 1
				';
                if (t3lib_extMgm::isLoaded('sys_note')) {
                    $this->TSdataArray[] = '
						// Setting defaults for sys_note author / email...
						TCAdefaults.sys_note.author = ' . $this->user['realName'] . '
						TCAdefaults.sys_note.email = ' . $this->user['email'] . '
					';
                }
            }
            // FILE MOUNTS:
            // Admin users has the base fileadmin dir mounted
            if ($this->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) {
                $this->addFileMount($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '', PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], 0, '');
            }
            // If userHomePath is set, we attempt to mount it
            if ($GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath']) {
                // First try and mount with [uid]_[username]
                $didMount = $this->addFileMount($this->user['username'], '', $GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath'] . $this->user['uid'] . '_' . $this->user['username'] . $GLOBALS['TYPO3_CONF_VARS']['BE']['userUploadDir'], 0, 'user');
                if (!$didMount) {
                    // If that failed, try and mount with only [uid]
                    $this->addFileMount($this->user['username'], '', $GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath'] . $this->user['uid'] . $GLOBALS['TYPO3_CONF_VARS']['BE']['userUploadDir'], 0, 'user');
                }
            }
            // BE_GROUPS:
            // Get the groups...
            #			$grList = t3lib_BEfunc::getSQLselectableList($this->user[$this->usergroup_column],$this->usergroup_table,$this->usergroup_table);
            $grList = $GLOBALS['TYPO3_DB']->cleanIntList($this->user[$this->usergroup_column]);
            // 240203: Since the group-field never contains any references to groups with a prepended table name we think it's safe to just intExplode and re-implode - which should be much faster than the other function call.
            if ($grList) {
                // Fetch groups will add a lot of information to the internal arrays: modules, accesslists, TSconfig etc. Refer to fetchGroups() function.
                $this->fetchGroups($grList);
            }
            // Add the TSconfig for this specific user:
            $this->TSdataArray[] = $this->addTScomment('USER TSconfig field') . $this->user['TSconfig'];
            // Check include lines.
            $this->TSdataArray = t3lib_TSparser::checkIncludeLines_array($this->TSdataArray);
            $this->userTS_text = implode(LF . '[GLOBAL]' . LF, $this->TSdataArray);
            // Imploding with "[global]" will make sure that non-ended confinements with braces are ignored.
            if ($GLOBALS['TYPO3_CONF_VARS']['BE']['TSconfigConditions'] && !$this->userTS_dontGetCached) {
                // Perform TS-Config parsing with condition matching
                $parseObj = t3lib_div::makeInstance('t3lib_TSparser_TSconfig');
                $res = $parseObj->parseTSconfig($this->userTS_text, 'userTS');
                if ($res) {
                    $this->userTS = $res['TSconfig'];
                    $this->userTSUpdated = $res['cached'] ? 0 : 1;
                }
            } else {
                // Parsing the user TSconfig (or getting from cache)
                $hash = md5('userTS:' . $this->userTS_text);
                $cachedContent = t3lib_BEfunc::getHash($hash);
                if (isset($cachedContent) && !$this->userTS_dontGetCached) {
                    $this->userTS = unserialize($cachedContent);
                } else {
                    $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
                    $parseObj->parse($this->userTS_text);
                    $this->userTS = $parseObj->setup;
                    t3lib_BEfunc::storeHash($hash, serialize($this->userTS), 'BE_USER_TSconfig');
                    // Update UC:
                    $this->userTSUpdated = 1;
                }
            }
            // Processing webmounts
            if ($this->isAdmin() && !$this->getTSConfigVal('options.dontMountAdminMounts')) {
                // Admin's always have the root mounted
                $this->dataLists['webmount_list'] = '0,' . $this->dataLists['webmount_list'];
            }
            // Processing filemounts
            t3lib_div::loadTCA('sys_filemounts');
            $orderBy = $GLOBALS['TCA']['sys_filemounts']['ctrl']['default_sortby'] ? $GLOBALS['TYPO3_DB']->stripOrderBy($GLOBALS['TCA']['sys_filemounts']['ctrl']['default_sortby']) : 'sorting';
            $this->dataLists['filemount_list'] = t3lib_div::uniqueList($this->dataLists['filemount_list']);
            if ($this->dataLists['filemount_list']) {
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_filemounts', 'deleted=0 AND hidden=0 AND pid=0 AND uid IN (' . $this->dataLists['filemount_list'] . ')', '', $orderBy);
                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                    $this->addFileMount($row['title'], $row['path'], $row['path'], $row['base'] ? 1 : 0, '');
                }
            }
            // The lists are cleaned for duplicates
            $this->groupData['webmounts'] = t3lib_div::uniqueList($this->dataLists['webmount_list']);
            $this->groupData['pagetypes_select'] = t3lib_div::uniqueList($this->dataLists['pagetypes_select']);
            $this->groupData['tables_select'] = t3lib_div::uniqueList($this->dataLists['tables_modify'] . ',' . $this->dataLists['tables_select']);
            $this->groupData['tables_modify'] = t3lib_div::uniqueList($this->dataLists['tables_modify']);
            $this->groupData['non_exclude_fields'] = t3lib_div::uniqueList($this->dataLists['non_exclude_fields']);
            $this->groupData['explicit_allowdeny'] = t3lib_div::uniqueList($this->dataLists['explicit_allowdeny']);
            $this->groupData['allowed_languages'] = t3lib_div::uniqueList($this->dataLists['allowed_languages']);
            $this->groupData['custom_options'] = t3lib_div::uniqueList($this->dataLists['custom_options']);
            $this->groupData['modules'] = t3lib_div::uniqueList($this->dataLists['modList']);
            $this->groupData['fileoper_perms'] = $this->dataLists['fileoper_perms'];
            $this->groupData['workspace_perms'] = $this->dataLists['workspace_perms'];
            // populating the $this->userGroupsUID -array with the groups in the order in which they were LAST included.!!
            $this->userGroupsUID = array_reverse(array_unique(array_reverse($this->includeGroupArray)));
            // Finally this is the list of group_uid's in the order they are parsed (including subgroups!) and without duplicates (duplicates are presented with their last entrance in the list, which thus reflects the order of the TypoScript in TSconfig)
            $this->groupList = implode(',', $this->userGroupsUID);
            $this->setCachedList($this->groupList);
            // Checking read access to webmounts:
            if (trim($this->groupData['webmounts']) !== '') {
                $webmounts = explode(',', $this->groupData['webmounts']);
                // Explode mounts
                $MProws = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND uid IN (' . $this->groupData['webmounts'] . ') AND ' . $this->getPagePermsClause(1), '', '', '', 'uid');
                // Selecting all webmounts with permission clause for reading
                foreach ($webmounts as $idx => $mountPointUid) {
                    if ($mountPointUid > 0 && !isset($MProws[$mountPointUid])) {
                        // If the mount ID is NOT found among selected pages, unset it:
                        unset($webmounts[$idx]);
                    }
                }
                $this->groupData['webmounts'] = implode(',', $webmounts);
                // Implode mounts in the end.
            }
            // Setting up workspace situation (after webmounts are processed!):
            $this->workspaceInit();
        }
    }