Index: t3lib/class.t3lib_tcemain.php =================================================================== --- t3lib/class.t3lib_tcemain.php (revision 9580) +++ t3lib/class.t3lib_tcemain.php (revision ) @@ -1,29 +1,29 @@ setDefaultsFromUserTS is called UserTSconfig default values will overrule existing values in this array (thus UserTSconfig overrules externally set defaults which overrules TCA defaults) + var $defaultValues = array(); // Array [table][fields]=value: New records are created with default values and you can set this array on the form $defaultValues[$table][$field] = $value to override the default values fetched from TCA. If ->setDefaultsFromUserTS is called UserTSconfig default values will overrule existing values in this array (thus UserTSconfig overrules externally set defaults which overrules TCA defaults) - var $overrideValues = array(); // Array [table][fields]=value: You can set this array on the form $overrideValues[$table][$field] = $value to override the incoming data. You must set this externally. You must make sure the fields in this array are also found in the table, because it's not checked. All columns can be set by this array! + var $overrideValues = array(); // Array [table][fields]=value: You can set this array on the form $overrideValues[$table][$field] = $value to override the incoming data. You must set this externally. You must make sure the fields in this array are also found in the table, because it's not checked. All columns can be set by this array! - var $alternativeFileName = array(); // Array [filename]=alternative_filename: Use this array to force another name onto a file. Eg. if you set ['/tmp/blablabal'] = 'my_file.txt' and '/tmp/blablabal' is set for a certain file-field, then 'my_file.txt' will be used as the name instead. + var $alternativeFileName = array(); // Array [filename]=alternative_filename: Use this array to force another name onto a file. Eg. if you set ['/tmp/blablabal'] = 'my_file.txt' and '/tmp/blablabal' is set for a certain file-field, then 'my_file.txt' will be used as the name instead. - var $alternativeFilePath = array(); // Array [filename]=alternative_filepath: Same as alternativeFileName but with relative path to the file + var $alternativeFilePath = array(); // Array [filename]=alternative_filepath: Same as alternativeFileName but with relative path to the file - var $data_disableFields=array(); // If entries are set in this array corresponding to fields for update, they are ignored and thus NOT updated. You could set this array from a series of checkboxes with value=0 and hidden fields before the checkbox with 1. Then an empty checkbox will disable the field. + var $data_disableFields = array(); // If entries are set in this array corresponding to fields for update, they are ignored and thus NOT updated. You could set this array from a series of checkboxes with value=0 and hidden fields before the checkbox with 1. Then an empty checkbox will disable the field. - var $suggestedInsertUids=array(); // Use this array to validate suggested uids for tables by setting [table]:[uid]. This is a dangerous option since it will force the inserted record to have a certain UID. The value just have to be true, but if you set it to "DELETE" it will make sure any record with that UID will be deleted first (raw delete). The option is used for import of T3D files when synchronizing between two mirrored servers. As a security measure this feature is available only for Admin Users (for now) + var $suggestedInsertUids = array(); // Use this array to validate suggested uids for tables by setting [table]:[uid]. This is a dangerous option since it will force the inserted record to have a certain UID. The value just have to be true, but if you set it to "DELETE" it will make sure any record with that UID will be deleted first (raw delete). The option is used for import of T3D files when synchronizing between two mirrored servers. As a security measure this feature is available only for Admin Users (for now) - var $callBackObj; // Object. Call back object for flex form traversation. Useful when external classes wants to use the iteration functions inside tcemain for traversing a FlexForm structure. + var $callBackObj; // Object. Call back object for flex form traversation. Useful when external classes wants to use the iteration functions inside tcemain for traversing a FlexForm structure. - - - // ********************* - // Internal variables (mapping arrays) which can be used (read-only) from outside - // ********************* + // ********************* + // Internal variables (mapping arrays) which can be used (read-only) from outside + // ********************* - var $autoVersionIdMap = Array(); // Contains mapping of auto-versionized records. - var $substNEWwithIDs = Array(); // When new elements are created, this array contains a map between their "NEW..." string IDs and the eventual UID they got when stored in database - var $substNEWwithIDs_table = Array(); // Like $substNEWwithIDs, but where each old "NEW..." id is mapped to the table it was from. - var $newRelatedIDs = Array(); // Holds the tables and there the ids of newly created child records from IRRE - var $copyMappingArray_merged = Array(); // This array is the sum of all copying operations in this class. May be READ from outside, thus partly public. - var $copiedFileMap = Array(); // A map between input file name and final destination for files being attached to records. - var $RTEmagic_copyIndex = Array(); // Contains [table][id][field] of fiels where RTEmagic images was copied. Holds old filename as key and new filename as value. - var $errorLog = Array(); // Errors are collected in this variable. + var $autoVersionIdMap = array(); // Contains mapping of auto-versionized records. + var $substNEWwithIDs = array(); // When new elements are created, this array contains a map between their "NEW..." string IDs and the eventual UID they got when stored in database + var $substNEWwithIDs_table = array(); // Like $substNEWwithIDs, but where each old "NEW..." id is mapped to the table it was from. + var $newRelatedIDs = array(); // Holds the tables and there the ids of newly created child records from IRRE + var $copyMappingArray_merged = array(); // This array is the sum of all copying operations in this class. May be READ from outside, thus partly public. + var $copiedFileMap = array(); // A map between input file name and final destination for files being attached to records. + var $RTEmagic_copyIndex = array(); // Contains [table][id][field] of fiels where RTEmagic images was copied. Holds old filename as key and new filename as value. + var $errorLog = array(); // Errors are collected in this variable. - // ********************* - // Internal Variables, do not touch. - // ********************* + // ********************* + // Internal Variables, do not touch. + // ********************* - // Variables set in init() function: + // Variables set in init() function: /** * The user-object the script uses. If not set from outside, this is set to the current global $BE_USER. * * @var t3lib_beUserAuth */ var $BE_USER; - var $userid; // will be set to uid of be_user executing this script + var $userid; // will be set to uid of be_user executing this script - var $username; // will be set to username of be_user executing this script + var $username; // will be set to username of be_user executing this script - var $admin; // will be set if user is admin + var $admin; // will be set if user is admin - var $defaultPermissions = array( // Can be overridden from $TYPO3_CONF_VARS + var $defaultPermissions = array( // Can be overridden from $TYPO3_CONF_VARS 'user' => 'show,edit,delete,new,editcontent', 'group' => 'show,edit,new,editcontent', 'everybody' => '' ); - var $exclude_array; // The list of - that cannot be edited by user. This is compiled from TCA/exclude-flag combined with non_exclude_fields for the user. + var $exclude_array; // The list of
- that cannot be edited by user. This is compiled from TCA/exclude-flag combined with non_exclude_fields for the user. - var $datamap = Array(); // Set with incoming data array - var $cmdmap = Array(); // Set with incoming cmd array + var $datamap = array(); // Set with incoming data array + var $cmdmap = array(); // Set with incoming cmd array // Internal static: - var $pMap = Array( // Permission mapping + var $pMap = array( // Permission mapping - 'show' => 1, // 1st bit + 'show' => 1, // 1st bit - 'edit' => 2, // 2nd bit + 'edit' => 2, // 2nd bit - 'delete' => 4, // 3rd bit + 'delete' => 4, // 3rd bit - 'new' => 8, // 4th bit + 'new' => 8, // 4th bit - 'editcontent' => 16 // 5th bit + 'editcontent' => 16 // 5th bit ); - var $sortIntervals = 256; // Integer: The interval between sorting numbers used with tables with a 'sorting' field defined. Min 1 + var $sortIntervals = 256; // Integer: The interval between sorting numbers used with tables with a 'sorting' field defined. Min 1 // Internal caching arrays - var $recUpdateAccessCache = Array(); // Used by function checkRecordUpdateAccess() to store whether a record is updateable or not. - var $recInsertAccessCache = Array(); // User by function checkRecordInsertAccess() to store whether a record can be inserted on a page id + var $recUpdateAccessCache = array(); // Used by function checkRecordUpdateAccess() to store whether a record is updateable or not. + var $recInsertAccessCache = array(); // User by function checkRecordInsertAccess() to store whether a record can be inserted on a page id - var $isRecordInWebMount_Cache=array(); // Caching array for check of whether records are in a webmount + var $isRecordInWebMount_Cache = array(); // Caching array for check of whether records are in a webmount - var $isInWebMount_Cache=array(); // Caching array for page ids in webmounts + var $isInWebMount_Cache = array(); // Caching array for page ids in webmounts - var $cachedTSconfig = array(); // Caching for collecting TSconfig for page ids + var $cachedTSconfig = array(); // Caching for collecting TSconfig for page ids - var $pageCache = Array(); // Used for caching page records in pageInfo() - var $checkWorkspaceCache = Array(); // Array caching workspace access for BE_USER + var $pageCache = array(); // Used for caching page records in pageInfo() + var $checkWorkspaceCache = array(); // Array caching workspace access for BE_USER // Other arrays: - var $dbAnalysisStore=array(); // For accumulation of MM relations that must be written after new records are created. + var $dbAnalysisStore = array(); // For accumulation of MM relations that must be written after new records are created. - var $removeFilesStore=array(); // For accumulation of files which must be deleted after processing of all input content + var $removeFilesStore = array(); // For accumulation of files which must be deleted after processing of all input content - var $uploadedFileArray = array(); // Uploaded files, set by process_uploads() + var $uploadedFileArray = array(); // Uploaded files, set by process_uploads() - var $registerDBList=array(); // Used for tracking references that might need correction after operations + var $registerDBList = array(); // Used for tracking references that might need correction after operations - var $registerDBPids=array(); // Used for tracking references that might need correction in pid field after operations (e.g. IRRE) + var $registerDBPids = array(); // Used for tracking references that might need correction in pid field after operations (e.g. IRRE) - var $copyMappingArray = Array(); // Used by the copy action to track the ids of new pages so subpages are correctly inserted! THIS is internally cleared for each executed copy operation! DO NOT USE THIS FROM OUTSIDE! Read from copyMappingArray_merged instead which is accumulating this information. + var $copyMappingArray = array(); // Used by the copy action to track the ids of new pages so subpages are correctly inserted! THIS is internally cleared for each executed copy operation! DO NOT USE THIS FROM OUTSIDE! Read from copyMappingArray_merged instead which is accumulating this information. - var $remapStack = array(); // array used for remapping uids and values at the end of process_datamap + var $remapStack = array(); // array used for remapping uids and values at the end of process_datamap - var $remapStackRecords = array(); // array used for remapping uids and values at the end of process_datamap (e.g. $remapStackRecords[
][] = ) + var $remapStackRecords = array(); // array used for remapping uids and values at the end of process_datamap (e.g. $remapStackRecords[
][] = ) - protected $remapStackChildIds = array(); // array used for checking whether new children need to be remapped + protected $remapStackChildIds = array(); // array used for checking whether new children need to be remapped - protected $remapStackActions = array(); // array used for executing addition actions after remapping happened (sett processRemapStack()) + protected $remapStackActions = array(); // array used for executing addition actions after remapping happened (sett processRemapStack()) - protected $remapStackRefIndex = array(); // array used for executing post-processing on the reference index + protected $remapStackRefIndex = array(); // array used for executing post-processing on the reference index - var $updateRefIndexStack = array(); // array used for additional calls to $this->updateRefIndex + var $updateRefIndexStack = array(); // array used for additional calls to $this->updateRefIndex - var $callFromImpExp = false; // tells, that this TCEmain was called from tx_impext - this variable is set by tx_impexp + var $callFromImpExp = FALSE; // tells, that this TCEmain was called from tx_impext - this variable is set by tx_impexp - var $newIndexMap = array(); // Array for new flexform index mapping + var $newIndexMap = array(); // Array for new flexform index mapping - // Various + // Various /** * basicFileFunctions object * * @var t3lib_basicFileFunctions */ - var $fileFunc; // For "singleTon" file-manipulation object + var $fileFunc; // For "singleTon" file-manipulation object - var $checkValue_currentRecord=array(); // Set to "currentRecord" during checking of values. + var $checkValue_currentRecord = array(); // Set to "currentRecord" during checking of values. - var $autoVersioningUpdate = FALSE; // A signal flag used to tell file processing that autoversioning has happend and hence certain action should be applied. + var $autoVersioningUpdate = FALSE; // A signal flag used to tell file processing that autoversioning has happend and hence certain action should be applied. - protected $disableDeleteClause = false; // Disable delete clause + protected $disableDeleteClause = FALSE; // Disable delete clause protected $checkModifyAccessListHookObjects; - - - - - - - - - /** * Initializing. * For details, see 'TYPO3 Core API' document. @@ -389,15 +365,21 @@ $this->deleteTree = 1; } - if ($GLOBALS['TYPO3_CONF_VARS']['BE']['explicitConfirmationOfTranslation'] && $this->updateModeL10NdiffData===TRUE) { + if ($GLOBALS['TYPO3_CONF_VARS']['BE']['explicitConfirmationOfTranslation'] && $this->updateModeL10NdiffData === TRUE) { $this->updateModeL10NdiffData = FALSE; } // Initializing default permissions for pages $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions']; - if (isset($defaultPermissions['user'])) {$this->defaultPermissions['user'] = $defaultPermissions['user'];} - if (isset($defaultPermissions['group'])) {$this->defaultPermissions['group'] = $defaultPermissions['group'];} - if (isset($defaultPermissions['everybody'])) {$this->defaultPermissions['everybody'] = $defaultPermissions['everybody'];} + if (isset($defaultPermissions['user'])) { + $this->defaultPermissions['user'] = $defaultPermissions['user']; + } + if (isset($defaultPermissions['group'])) { + $this->defaultPermissions['group'] = $defaultPermissions['group']; + } + if (isset($defaultPermissions['everybody'])) { + $this->defaultPermissions['everybody'] = $defaultPermissions['everybody']; + } // generates the excludelist, based on TCA/exclude-flag and non_exclude_fields for the user: $this->exclude_array = $this->admin ? array() : $this->getExcludeListArray(); @@ -407,7 +389,7 @@ reset($data); $this->datamap = $data; } - if (is_array($cmd)) { + if (is_array($cmd)) { reset($cmd); $this->cmdmap = $cmd; } @@ -420,14 +402,14 @@ * @param array This array has the syntax $mirror[table_name][uid] = [list of uids to copy data-value TO!] * @return void */ - function setMirror($mirror) { + function setMirror($mirror) { - if (is_array($mirror)) { + if (is_array($mirror)) { foreach ($mirror as $table => $uid_array) { - if (isset($this->datamap[$table])) { + if (isset($this->datamap[$table])) { reset($uid_array); foreach ($uid_array as $id => $uidList) { - if (isset($this->datamap[$table][$id])) { + if (isset($this->datamap[$table][$id])) { - $theIdsInArray = t3lib_div::trimExplode(',',$uidList,1); + $theIdsInArray = t3lib_div::trimExplode(',', $uidList, 1); foreach ($theIdsInArray as $copyToUid) { $this->datamap[$table][$copyToUid] = $this->datamap[$table][$id]; } @@ -444,14 +426,14 @@ * @param array User TSconfig array * @return void */ - function setDefaultsFromUserTS($userTS) { + function setDefaultsFromUserTS($userTS) { global $TCA; - if (is_array($userTS)) { + if (is_array($userTS)) { - foreach($userTS as $k => $v) { + foreach ($userTS as $k => $v) { - $k = substr($k,0,-1); + $k = substr($k, 0, -1); - if ($k && is_array($v) && isset($TCA[$k])) { + if ($k && is_array($v) && isset($TCA[$k])) { - if (is_array($this->defaultValues[$k])) { + if (is_array($this->defaultValues[$k])) { - $this->defaultValues[$k] = array_merge($this->defaultValues[$k],$v); + $this->defaultValues[$k] = array_merge($this->defaultValues[$k], $v); } else { $this->defaultValues[$k] = $v; } @@ -467,29 +449,29 @@ * @param array $_FILES array * @return void */ - function process_uploads($postFiles) { + function process_uploads($postFiles) { - if (is_array($postFiles)) { + if (is_array($postFiles)) { // Editing frozen: - if ($this->BE_USER->workspace!==0 && $this->BE_USER->workspaceRec['freeze']) { + if ($this->BE_USER->workspace !== 0 && $this->BE_USER->workspaceRec['freeze']) { - $this->newlog('All editing in this workspace has been frozen!',1); + $this->newlog('All editing in this workspace has been frozen!', 1); return FALSE; } reset($postFiles); $subA = current($postFiles); - if (is_array($subA)) { + if (is_array($subA)) { - if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) { + if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) { // Initialize the uploadedFilesArray: - $this->uploadedFileArray=array(); + $this->uploadedFileArray = array(); // For each entry: - foreach($subA as $key => $values) { + foreach ($subA as $key => $values) { - $this->process_uploads_traverseArray($this->uploadedFileArray,$values,$key); + $this->process_uploads_traverseArray($this->uploadedFileArray, $values, $key); } } else { - $this->uploadedFileArray=$subA; + $this->uploadedFileArray = $subA; } } } @@ -505,30 +487,17 @@ * @access private * @see process_uploads() */ - function process_uploads_traverseArray(&$outputArr,$inputArr,$keyToSet) { + function process_uploads_traverseArray(&$outputArr, $inputArr, $keyToSet) { - if (is_array($inputArr)) { + if (is_array($inputArr)) { - foreach($inputArr as $key => $value) { + foreach ($inputArr as $key => $value) { - $this->process_uploads_traverseArray($outputArr[$key],$inputArr[$key],$keyToSet); + $this->process_uploads_traverseArray($outputArr[$key], $inputArr[$key], $keyToSet); } } else { - $outputArr[$keyToSet]=$inputArr; + $outputArr[$keyToSet] = $inputArr; } } - - - - - - - - - - - - - /********************************************* * * HOOKS @@ -552,12 +521,12 @@ function hook_processDatamap_afterDatabaseOperations(&$hookObjectsArr, &$status, &$table, &$id, &$fieldArray) { // Process hook directly: if (!isset($this->remapStackRecords[$table][$id])) { - foreach($hookObjectsArr as $hookObj) { + foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) { $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this); } } - // If this record is in remapStack (e.g. when using IRRE), values will be updated/remapped later on. So the hook will also be called later: + // If this record is in remapStack (e.g. when using IRRE), values will be updated/remapped later on. So the hook will also be called later: } else { $this->remapStackRecords[$table][$id]['processDatamap_afterDatabaseOperations'] = array( 'status' => $status, @@ -577,11 +546,11 @@ if (!isset($this->checkModifyAccessListHookObjects)) { $this->checkModifyAccessListHookObjects = array(); - if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'])) { + if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'])) { - foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'] as $classData) { + foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'] as $classData) { $hookObject = t3lib_div::getUserObj($classData); - if(!($hookObject instanceof t3lib_TCEmain_checkModifyAccessListHook)) { + if (!($hookObject instanceof t3lib_TCEmain_checkModifyAccessListHook)) { throw new UnexpectedValueException('$hookObject must implement interface t3lib_TCEmain_checkModifyAccessListHook', 1251892472); } @@ -594,17 +563,6 @@ } - - - - - - - - - - - /********************************************* * * PROCESSING DATA @@ -623,52 +581,52 @@ $registerDBList = array(); // Editing frozen: - if ($this->BE_USER->workspace!==0 && $this->BE_USER->workspaceRec['freeze']) { + if ($this->BE_USER->workspace !== 0 && $this->BE_USER->workspaceRec['freeze']) { - $this->newlog('All editing in this workspace has been frozen!',1); + $this->newlog('All editing in this workspace has been frozen!', 1); return FALSE; } // First prepare user defined objects (if any) for hooks which extend this function: $hookObjectsArr = array(); - if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'])) { + if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'])) { foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] as $classRef) { $hookObjectsArr[] = t3lib_div::getUserObj($classRef); } } // Organize tables so that the pages-table is always processed first. This is required if you want to make sure that content pointing to a new page will be created. - $orderOfTables = Array(); + $orderOfTables = array(); - if (isset($this->datamap['pages'])) { // Set pages first. + if (isset($this->datamap['pages'])) { // Set pages first. - $orderOfTables[]='pages'; + $orderOfTables[] = 'pages'; } $orderOfTables = array_unique(array_merge($orderOfTables, array_keys($this->datamap))); // Process the tables... - foreach($orderOfTables as $table) { + foreach ($orderOfTables as $table) { - /* Check if - - table is set in $TCA, - - table is NOT readOnly - - the table is set with content in the data-array (if not, there's nothing to process...) - - permissions for tableaccess OK - */ + /* Check if + - table is set in $TCA, + - table is NOT readOnly + - the table is set with content in the data-array (if not, there's nothing to process...) + - permissions for tableaccess OK + */ $modifyAccessList = $this->checkModifyAccessList($table); - if (!$modifyAccessList) { + if (!$modifyAccessList) { $id = 0; - $this->log($table,$id,2,0,1,"Attempt to modify table '%s' without permission",1,array($table)); + $this->log($table, $id, 2, 0, 1, "Attempt to modify table '%s' without permission", 1, array($table)); } - if (isset($TCA[$table]) && !$this->tableReadOnly($table) && is_array($this->datamap[$table]) && $modifyAccessList) { + if (isset($TCA[$table]) && !$this->tableReadOnly($table) && is_array($this->datamap[$table]) && $modifyAccessList) { - if ($this->reverseOrder) { + if ($this->reverseOrder) { $this->datamap[$table] = array_reverse($this->datamap[$table], 1); } // For each record from the table, do: // $id is the record uid, may be a string if new records... // $incomingFieldArray is the array of fields - foreach($this->datamap[$table] as $id => $incomingFieldArray) { + foreach ($this->datamap[$table] as $id => $incomingFieldArray) { - if (is_array($incomingFieldArray)) { + if (is_array($incomingFieldArray)) { // Hook: processDatamap_preProcessFieldArray - foreach($hookObjectsArr as $hookObj) { + foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'processDatamap_preProcessFieldArray')) { $hookObj->processDatamap_preProcessFieldArray($incomingFieldArray, $table, $id, $this); } @@ -682,25 +640,32 @@ $old_pid_value = ''; $this->autoVersioningUpdate = FALSE; - if (!t3lib_div::testInt($id)) { // Is it a new record? (Then Id is a string) + if (!t3lib_div::testInt($id)) { // Is it a new record? (Then Id is a string) - $fieldArray = $this->newFieldArray($table); // Get a fieldArray with default values + $fieldArray = $this->newFieldArray($table); // Get a fieldArray with default values - if (isset($incomingFieldArray['pid'])) { // A pid must be set for new records. + if (isset($incomingFieldArray['pid'])) { // A pid must be set for new records. // $value = the pid $pid_value = $incomingFieldArray['pid']; // Checking and finding numerical pid, it may be a string-reference to another value $OK = 1; - if (strstr($pid_value,'NEW')) { // If a NEW... id + if (strstr($pid_value, 'NEW')) { // If a NEW... id - if (substr($pid_value,0,1)=='-') {$negFlag=-1;$pid_value=substr($pid_value,1);} else {$negFlag=1;} + if (substr($pid_value, 0, 1) == '-') { + $negFlag = -1; + $pid_value = substr($pid_value, 1); + } else { + $negFlag = 1; + } - if (isset($this->substNEWwithIDs[$pid_value])) { // Trying to find the correct numerical value as it should be mapped by earlier processing of another new record. + if (isset($this->substNEWwithIDs[$pid_value])) { // Trying to find the correct numerical value as it should be mapped by earlier processing of another new record. if ($negFlag === 1) { $old_pid_value = $this->substNEWwithIDs[$pid_value]; } - $pid_value=intval($negFlag*$this->substNEWwithIDs[$pid_value]); + $pid_value = intval($negFlag * $this->substNEWwithIDs[$pid_value]); - } else {$OK = 0;} // If not found in the substArray we must stop the process... + } else { + $OK = 0; + } // If not found in the substArray we must stop the process... - } elseif ($pid_value>=0 && $this->BE_USER->workspace!==0 && $TCA[$table]['ctrl']['versioning_followPages']) { // PID points to page, the workspace is an offline space and the table follows page during versioning: This means we must check if the PID page has a version in the workspace with swapmode set to 0 (zero = page+content) and if so, change the pid to the uid of that version. + } elseif ($pid_value >= 0 && $this->BE_USER->workspace !== 0 && $TCA[$table]['ctrl']['versioning_followPages']) { // PID points to page, the workspace is an offline space and the table follows page during versioning: This means we must check if the PID page has a version in the workspace with swapmode set to 0 (zero = page+content) and if so, change the pid to the uid of that version. - if ($WSdestPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, 'pages', $pid_value, 'uid,t3ver_swapmode')) { // Looks for workspace version of page. + if ($WSdestPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, 'pages', $pid_value, 'uid,t3ver_swapmode')) { // Looks for workspace version of page. - if ($WSdestPage['t3ver_swapmode']==0) { // if swapmode is zero, then change pid value. + if ($WSdestPage['t3ver_swapmode'] == 0) { // if swapmode is zero, then change pid value. $pid_value = $WSdestPage['uid']; } } @@ -708,21 +673,21 @@ $pid_value = intval($pid_value); // The $pid_value is now the numerical pid at this point - if ($OK) { + if ($OK) { $sortRow = $TCA[$table]['ctrl']['sortby']; - if ($pid_value>=0) { // Points to a page on which to insert the element, possibly in the top of the page + if ($pid_value >= 0) { // Points to a page on which to insert the element, possibly in the top of the page - if ($sortRow) { // If this table is sorted we better find the top sorting number + if ($sortRow) { // If this table is sorted we better find the top sorting number - $fieldArray[$sortRow] = $this->getSortNumber($table,0,$pid_value); + $fieldArray[$sortRow] = $this->getSortNumber($table, 0, $pid_value); } - $fieldArray['pid'] = $pid_value; // The numerical pid is inserted in the data array + $fieldArray['pid'] = $pid_value; // The numerical pid is inserted in the data array - } else { // points to another record before ifself + } else { // points to another record before ifself - if ($sortRow) { // If this table is sorted we better find the top sorting number + if ($sortRow) { // If this table is sorted we better find the top sorting number - $tempArray=$this->getSortNumber($table,0,$pid_value); // Because $pid_value is < 0, getSortNumber returns an array + $tempArray = $this->getSortNumber($table, 0, $pid_value); // Because $pid_value is < 0, getSortNumber returns an array $fieldArray['pid'] = $tempArray['pid']; $fieldArray[$sortRow] = $tempArray['sortNumber']; - } else { // Here we fetch the PID of the record that we point to... + } else { // Here we fetch the PID of the record that we point to... - $tempdata = $this->recordInfo($table,abs($pid_value),'pid'); + $tempdata = $this->recordInfo($table, abs($pid_value), 'pid'); - $fieldArray['pid']=$tempdata['pid']; + $fieldArray['pid'] = $tempdata['pid']; } } } @@ -730,26 +695,26 @@ $theRealPid = $fieldArray['pid']; // Now, check if we may insert records on this pid. - if ($theRealPid>=0) { + if ($theRealPid >= 0) { - $recordAccess = $this->checkRecordInsertAccess($table,$theRealPid); // Checks if records can be inserted on this $pid. + $recordAccess = $this->checkRecordInsertAccess($table, $theRealPid); // Checks if records can be inserted on this $pid. - if ($recordAccess) { + if ($recordAccess) { - $this->addDefaultPermittedLanguageIfNotSet($table,$incomingFieldArray); + $this->addDefaultPermittedLanguageIfNotSet($table, $incomingFieldArray); - $recordAccess = $this->BE_USER->recordEditAccessInternals($table,$incomingFieldArray,TRUE); + $recordAccess = $this->BE_USER->recordEditAccessInternals($table, $incomingFieldArray, TRUE); - if (!$recordAccess) { + if (!$recordAccess) { - $this->newlog("recordEditAccessInternals() check failed. [".$this->BE_USER->errorMsg."]",1); + $this->newlog("recordEditAccessInternals() check failed. [" . $this->BE_USER->errorMsg . "]", 1); - } elseif(!$this->bypassWorkspaceRestrictions) { + } elseif (!$this->bypassWorkspaceRestrictions) { // Workspace related processing: - if ($res = $this->BE_USER->workspaceAllowLiveRecordsInPID($theRealPid,$table)) { // If LIVE records cannot be created in the current PID due to workspace restrictions, prepare creation of placeholder-record + if ($res = $this->BE_USER->workspaceAllowLiveRecordsInPID($theRealPid, $table)) { // If LIVE records cannot be created in the current PID due to workspace restrictions, prepare creation of placeholder-record - if ($res<0) { + if ($res < 0) { $recordAccess = FALSE; - $this->newlog('Stage for versioning root point and users access level did not allow for editing',1); + $this->newlog('Stage for versioning root point and users access level did not allow for editing', 1); } - } else { // So, if no live records were allowed, we have to create a new version of this record: + } else { // So, if no live records were allowed, we have to create a new version of this record: - if ($TCA[$table]['ctrl']['versioningWS']) { + if ($TCA[$table]['ctrl']['versioningWS']) { $createNewVersion = TRUE; } else { $recordAccess = FALSE; - $this->newlog('Record could not be created in this workspace in this branch',1); + $this->newlog('Record could not be created in this workspace in this branch', 1); } } } @@ -757,23 +722,23 @@ } else { debug('Internal ERROR: pid should not be less than zero!'); } - $status = 'new'; // Yes new record, change $record_status to 'insert' + $status = 'new'; // Yes new record, change $record_status to 'insert' - } else { // Nope... $id is a number + } else { // Nope... $id is a number $fieldArray = array(); $recordAccess = $this->checkRecordUpdateAccess($table, $id, $incomingFieldArray, $hookObjectsArr); - if (!$recordAccess) { + if (!$recordAccess) { - $propArr = $this->getRecordProperties($table,$id); + $propArr = $this->getRecordProperties($table, $id); - $this->log($table,$id,2,0,1,"Attempt to modify record '%s' (%s) without permission. Or non-existing page.",2,array($propArr['header'],$table.':'.$id),$propArr['event_pid']); + $this->log($table, $id, 2, 0, 1, "Attempt to modify record '%s' (%s) without permission. Or non-existing page.", 2, array($propArr['header'], $table . ':' . $id), $propArr['event_pid']); - } else { // Next check of the record permissions (internals) + } else { // Next check of the record permissions (internals) - $recordAccess = $this->BE_USER->recordEditAccessInternals($table,$id); + $recordAccess = $this->BE_USER->recordEditAccessInternals($table, $id); - if (!$recordAccess) { + if (!$recordAccess) { - $propArr = $this->getRecordProperties($table,$id); + $propArr = $this->getRecordProperties($table, $id); - $this->newlog("recordEditAccessInternals() check failed. [".$this->BE_USER->errorMsg."]",1); + $this->newlog("recordEditAccessInternals() check failed. [" . $this->BE_USER->errorMsg . "]", 1); - } else { // Here we fetch the PID of the record that we point to... + } else { // Here we fetch the PID of the record that we point to... - $tempdata = $this->recordInfo($table,$id,'pid'.($TCA[$table]['ctrl']['versioningWS']?',t3ver_wsid,t3ver_stage':'')); + $tempdata = $this->recordInfo($table, $id, 'pid' . ($TCA[$table]['ctrl']['versioningWS'] ? ',t3ver_wsid,t3ver_stage' : '')); $theRealPid = $tempdata['pid']; - // Use the new id of the versionized record we're trying to write to: + // Use the new id of the versionized record we're trying to write to: // (This record is a child record of a parent and has already been versionized.) if ($this->autoVersionIdMap[$table][$id]) { // For the reason that creating a new version of this record, automatically @@ -785,12 +750,12 @@ $recordAccess = TRUE; $this->autoVersioningUpdate = TRUE; - // Checking access in case of offline workspace: + // Checking access in case of offline workspace: - } elseif (!$this->bypassWorkspaceRestrictions && $errorCode = $this->BE_USER->workspaceCannotEditRecord($table,$tempdata)) { + } elseif (!$this->bypassWorkspaceRestrictions && $errorCode = $this->BE_USER->workspaceCannotEditRecord($table, $tempdata)) { - $recordAccess = FALSE; // Versioning is required and it must be offline version! + $recordAccess = FALSE; // Versioning is required and it must be offline version! // Auto-creation of version: In offline workspace, test if versioning is enabled and look for workspace version of input record. If there is no versionized record found we will create one and save to that. - if ($this->BE_USER->workspaceAllowAutoCreation($table,$id,$theRealPid)) { + if ($this->BE_USER->workspaceAllowAutoCreation($table, $id, $theRealPid)) { $tce = t3lib_div::makeInstance('t3lib_TCEmain'); /* @var $tce t3lib_TCEmain */ $tce->stripslashes_values = 0; @@ -799,22 +764,22 @@ $cmd = array(); $cmd[$table][$id]['version'] = array( 'action' => 'new', - 'treeLevels' => -1, // Default is to create a version of the individual records... element versioning that is. + 'treeLevels' => -1, // Default is to create a version of the individual records... element versioning that is. - 'label' => 'Auto-created for WS #'.$this->BE_USER->workspace + 'label' => 'Auto-created for WS #' . $this->BE_USER->workspace ); - $tce->start(array(),$cmd); + $tce->start(array(), $cmd); $tce->process_cmdmap(); - $this->errorLog = array_merge($this->errorLog,$tce->errorLog); + $this->errorLog = array_merge($this->errorLog, $tce->errorLog); // If copying was successful, share the new uids (also of related children): - if ($tce->copyMappingArray[$table][$id]) { + if ($tce->copyMappingArray[$table][$id]) { foreach ($tce->copyMappingArray as $origTable => $origIdArray) { foreach ($origIdArray as $origId => $newId) { $this->uploadedFileArray[$origTable][$newId] = $this->uploadedFileArray[$origTable][$origId]; $this->autoVersionIdMap[$origTable][$origId] = $newId; } } - $this->RTEmagic_copyIndex = t3lib_div::array_merge_recursive_overrule($this->RTEmagic_copyIndex, $tce->RTEmagic_copyIndex); // See where RTEmagic_copyIndex is used inside fillInFieldArray() for more information... + $this->RTEmagic_copyIndex = t3lib_div::array_merge_recursive_overrule($this->RTEmagic_copyIndex, $tce->RTEmagic_copyIndex); // See where RTEmagic_copyIndex is used inside fillInFieldArray() for more information... // Update registerDBList, that holds the copied relations to child records: $registerDBList = array_merge($registerDBList, $tce->registerDBList); @@ -826,53 +791,59 @@ $id = $this->autoVersionIdMap[$table][$id]; $recordAccess = TRUE; $this->autoVersioningUpdate = TRUE; - } else $this->newlog("Could not be edited in offline workspace in the branch where found (failure state: '".$errorCode."'). Auto-creation of version failed!",1); - } else $this->newlog("Could not be edited in offline workspace in the branch where found (failure state: '".$errorCode."'). Auto-creation of version not allowed in workspace!",1); + } else { + $this->newlog("Could not be edited in offline workspace in the branch where found (failure state: '" . $errorCode . "'). Auto-creation of version failed!", 1); - } + } + } else { + $this->newlog("Could not be edited in offline workspace in the branch where found (failure state: '" . $errorCode . "'). Auto-creation of version not allowed in workspace!", 1); - } - } + } + } + } + } - $status = 'update'; // the default is 'update' + $status = 'update'; // the default is 'update' } // If access was granted above, proceed to create or update record: - if ($recordAccess) { + if ($recordAccess) { - list($tscPID) = t3lib_BEfunc::getTSCpid($table,$id,$old_pid_value ? $old_pid_value : $fieldArray['pid']); // Here the "pid" is set IF NOT the old pid was a string pointing to a place in the subst-id array. + list($tscPID) = t3lib_BEfunc::getTSCpid($table, $id, $old_pid_value ? $old_pid_value : $fieldArray['pid']); // Here the "pid" is set IF NOT the old pid was a string pointing to a place in the subst-id array. $TSConfig = $this->getTCEMAIN_TSconfig($tscPID); - if ($status=='new' && $table=='pages' && is_array($TSConfig['permissions.'])) { + if ($status == 'new' && $table == 'pages' && is_array($TSConfig['permissions.'])) { - $fieldArray = $this->setTSconfigPermissions($fieldArray,$TSConfig['permissions.']); + $fieldArray = $this->setTSconfigPermissions($fieldArray, $TSConfig['permissions.']); } - if ($createNewVersion) { + if ($createNewVersion) { $newVersion_placeholderFieldArray = $fieldArray; } // Processing of all fields in incomingFieldArray and setting them in $fieldArray - $fieldArray = $this->fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$theRealPid,$status,$tscPID); + $fieldArray = $this->fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $theRealPid, $status, $tscPID); // NOTICE! All manipulation beyond this point bypasses both "excludeFields" AND possible "MM" relations / file uploads to field! // Forcing some values unto field array: - $fieldArray = $this->overrideFieldArray($table,$fieldArray); // NOTICE: This overriding is potentially dangerous; permissions per field is not checked!!! + $fieldArray = $this->overrideFieldArray($table, $fieldArray); // NOTICE: This overriding is potentially dangerous; permissions per field is not checked!!! - if ($createNewVersion) { + if ($createNewVersion) { - $newVersion_placeholderFieldArray = $this->overrideFieldArray($table,$newVersion_placeholderFieldArray); + $newVersion_placeholderFieldArray = $this->overrideFieldArray($table, $newVersion_placeholderFieldArray); } // Setting system fields - if ($status=='new') { + if ($status == 'new') { - if ($TCA[$table]['ctrl']['crdate']) { + if ($TCA[$table]['ctrl']['crdate']) { $fieldArray[$TCA[$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME']; if ($createNewVersion) { $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME']; } } - if ($TCA[$table]['ctrl']['cruser_id']) { + if ($TCA[$table]['ctrl']['cruser_id']) { - $fieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid; + $fieldArray[$TCA[$table]['ctrl']['cruser_id']] = $this->userid; - if ($createNewVersion) $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid; + if ($createNewVersion) { + $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['cruser_id']] = $this->userid; - } + } + } - } elseif ($this->checkSimilar) { // Removing fields which are equal to the current value: + } elseif ($this->checkSimilar) { // Removing fields which are equal to the current value: - $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table,$id,$fieldArray); + $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table, $id, $fieldArray); } - if ($TCA[$table]['ctrl']['tstamp'] && count($fieldArray)) { + if ($TCA[$table]['ctrl']['tstamp'] && count($fieldArray)) { $fieldArray[$TCA[$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME']; if ($createNewVersion) { $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME']; @@ -883,7 +854,7 @@ } // Hook: processDatamap_postProcessFieldArray - foreach($hookObjectsArr as $hookObj) { + foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'processDatamap_postProcessFieldArray')) { $hookObj->processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, $this); } @@ -892,28 +863,28 @@ // Performing insert/update. If fieldArray has been unset by some userfunction (see hook above), don't do anything // Kasper: Unsetting the fieldArray is dangerous; MM relations might be saved already and files could have been uploaded that are now "lost" if (is_array($fieldArray)) { - if ($status=='new') { + if ($status == 'new') { - if ($createNewVersion) { // This creates a new version of the record with online placeholder and offline version + if ($createNewVersion) { // This creates a new version of the record with online placeholder and offline version - $versioningType = $table==='pages' ? $this->BE_USER->workspaceVersioningTypeGetClosest(t3lib_div::intInRange($TYPO3_CONF_VARS['BE']['newPagesVersioningType'],-1,1)) : -1; + $versioningType = $table === 'pages' ? $this->BE_USER->workspaceVersioningTypeGetClosest(t3lib_div::intInRange($TYPO3_CONF_VARS['BE']['newPagesVersioningType'], -1, 1)) : -1; - if ($this->BE_USER->workspaceVersioningTypeAccess($versioningType)) { + if ($this->BE_USER->workspaceVersioningTypeAccess($versioningType)) { $newVersion_placeholderFieldArray['t3ver_label'] = 'INITIAL PLACEHOLDER'; - $newVersion_placeholderFieldArray['t3ver_state'] = 1; // Setting placeholder state value for temporary record + $newVersion_placeholderFieldArray['t3ver_state'] = 1; // Setting placeholder state value for temporary record - $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER->workspace; // Setting workspace - only so display of place holders can filter out those from other workspaces. + $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER->workspace; // Setting workspace - only so display of place holders can filter out those from other workspaces. - $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['label']] = '[PLACEHOLDER, WS#'.$this->BE_USER->workspace.']'; + $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['label']] = '[PLACEHOLDER, WS#' . $this->BE_USER->workspace . ']'; - $this->insertDB($table,$id,$newVersion_placeholderFieldArray,FALSE); // Saving placeholder as 'original' + $this->insertDB($table, $id, $newVersion_placeholderFieldArray, FALSE); // Saving placeholder as 'original' // For the actual new offline version, set versioning values to point to placeholder: $fieldArray['pid'] = -1; $fieldArray['t3ver_oid'] = $this->substNEWwithIDs[$id]; $fieldArray['t3ver_id'] = 1; - $fieldArray['t3ver_state'] = -1; // Setting placeholder state value for version (so it can know it is currently a new version...) + $fieldArray['t3ver_state'] = -1; // Setting placeholder state value for version (so it can know it is currently a new version...) $fieldArray['t3ver_label'] = 'First draft version'; $fieldArray['t3ver_wsid'] = $this->BE_USER->workspace; - if ($table==='pages') { // Swap mode set to "branch" so we can build branches for pages. + if ($table === 'pages') { // Swap mode set to "branch" so we can build branches for pages. $fieldArray['t3ver_swapmode'] = $versioningType; } - $phShadowId = $this->insertDB($table,$id,$fieldArray,TRUE,0,TRUE); // When inserted, $this->substNEWwithIDs[$id] will be changed to the uid of THIS version and so the interface will pick it up just nice! + $phShadowId = $this->insertDB($table, $id, $fieldArray, TRUE, 0, TRUE); // When inserted, $this->substNEWwithIDs[$id] will be changed to the uid of THIS version and so the interface will pick it up just nice! - if ($phShadowId) { + if ($phShadowId) { // Processes fields of the placeholder record: $this->triggerRemapAction( $table, @@ -924,25 +895,27 @@ // Hold auto-versionized ids of placeholders: $this->autoVersionIdMap[$table][$this->substNEWwithIDs[$id]] = $phShadowId; } - } else $this->newlog('Versioning type "'.$versioningType.'" was not allowed, so could not create new record.',1); - } else { + } else { + $this->newlog('Versioning type "' . $versioningType . '" was not allowed, so could not create new record.', 1); + } + } else { - $this->insertDB($table,$id,$fieldArray,FALSE,$incomingFieldArray['uid']); + $this->insertDB($table, $id, $fieldArray, FALSE, $incomingFieldArray['uid']); } } else { - $this->updateDB($table,$id,$fieldArray); + $this->updateDB($table, $id, $fieldArray); - $this->placeholderShadowing($table,$id); + $this->placeholderShadowing($table, $id); } } - /* - * Hook: processDatamap_afterDatabaseOperations - * - * Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id, - * but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array. - */ + /* + * Hook: processDatamap_afterDatabaseOperations + * + * Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id, + * but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array. + */ $this->hook_processDatamap_afterDatabaseOperations($hookObjectsArr, $status, $table, $id, $fieldArray); - } // if ($recordAccess) { + } // if ($recordAccess) { - } // if (is_array($incomingFieldArray)) { + } // if (is_array($incomingFieldArray)) { } } } @@ -957,7 +930,7 @@ * * Note: When this hook gets called, all operations on the submitted data have been finished. */ - foreach($hookObjectsArr as $hookObj) { + foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'processDatamap_afterAllOperations')) { $hookObj->processDatamap_afterAllOperations($this); } @@ -971,31 +944,31 @@ * @param integer Record uid * @return void */ - function placeholderShadowing($table,$id) { + function placeholderShadowing($table, $id) { global $TCA; t3lib_div::loadTCA($table); - if ($liveRec = t3lib_BEfunc::getLiveVersionOfRecord($table,$id,'*')) { + if ($liveRec = t3lib_BEfunc::getLiveVersionOfRecord($table, $id, '*')) { - if ((int)$liveRec['t3ver_state']>0) { + if ((int) $liveRec['t3ver_state'] > 0) { - $justStoredRecord = t3lib_BEfunc::getRecord($table,$id); + $justStoredRecord = t3lib_BEfunc::getRecord($table, $id); $newRecord = array(); $shadowCols = $TCA[$table]['ctrl']['shadowColumnsForNewPlaceholders']; - $shadowCols.= ','.$TCA[$table]['ctrl']['languageField']; + $shadowCols .= ',' . $TCA[$table]['ctrl']['languageField']; - $shadowCols.= ','.$TCA[$table]['ctrl']['transOrigPointerField']; + $shadowCols .= ',' . $TCA[$table]['ctrl']['transOrigPointerField']; - $shadowCols.= ','.$TCA[$table]['ctrl']['type']; + $shadowCols .= ',' . $TCA[$table]['ctrl']['type']; - $shadowCols.= ','.$TCA[$table]['ctrl']['label']; + $shadowCols .= ',' . $TCA[$table]['ctrl']['label']; - $shadowColumns = array_unique(t3lib_div::trimExplode(',', $shadowCols,1)); + $shadowColumns = array_unique(t3lib_div::trimExplode(',', $shadowCols, 1)); - foreach($shadowColumns as $fieldName) { + foreach ($shadowColumns as $fieldName) { - if (strcmp($justStoredRecord[$fieldName],$liveRec[$fieldName]) && isset($TCA[$table]['columns'][$fieldName]) && $fieldName!=='uid' && $fieldName!=='pid') { + if (strcmp($justStoredRecord[$fieldName], $liveRec[$fieldName]) && isset($TCA[$table]['columns'][$fieldName]) && $fieldName !== 'uid' && $fieldName !== 'pid') { $newRecord[$fieldName] = $justStoredRecord[$fieldName]; } } - if (count($newRecord)) { + if (count($newRecord)) { - $this->newlog2('Shadowing done on fields '.implode(',',array_keys($newRecord)).' in placeholder record '.$table.':'.$liveRec['uid'].' (offline version UID='.$id.')', $table, $liveRec['uid'], $liveRec['pid']); + $this->newlog2('Shadowing done on fields ' . implode(',', array_keys($newRecord)) . ' in placeholder record ' . $table . ':' . $liveRec['uid'] . ' (offline version UID=' . $id . ')', $table, $liveRec['uid'], $liveRec['pid']); - $this->updateDB($table,$liveRec['uid'],$newRecord); + $this->updateDB($table, $liveRec['uid'], $newRecord); } } } @@ -1014,7 +987,7 @@ * @param integer $tscPID: TSconfig PID * @return array Field Array */ - function fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$realPid,$status,$tscPID) { + function fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $realPid, $status, $tscPID) { global $TCA; // Initialize: @@ -1024,59 +997,61 @@ $diffStorageFlag = FALSE; // Setting 'currentRecord' and 'checkValueRecord': - if (strstr($id,'NEW')) { + if (strstr($id, 'NEW')) { - $currentRecord = $checkValueRecord = $fieldArray; // must have the 'current' array - not the values after processing below... + $currentRecord = $checkValueRecord = $fieldArray; // must have the 'current' array - not the values after processing below... // IF $incomingFieldArray is an array, overlay it. // The point is that when new records are created as copies with flex type fields there might be a field containing information about which DataStructure to use and without that information the flexforms cannot be correctly processed.... This should be OK since the $checkValueRecord is used by the flexform evaluation only anyways... - if (is_array($incomingFieldArray) && is_array($checkValueRecord)) { + if (is_array($incomingFieldArray) && is_array($checkValueRecord)) { $checkValueRecord = t3lib_div::array_merge_recursive_overrule($checkValueRecord, $incomingFieldArray); } } else { - $currentRecord = $checkValueRecord = $this->recordInfo($table,$id,'*'); // We must use the current values as basis for this! + $currentRecord = $checkValueRecord = $this->recordInfo($table, $id, '*'); // We must use the current values as basis for this! - t3lib_BEfunc::fixVersioningPid($table,$currentRecord); // This is done to make the pid positive for offline versions; Necessary to have diff-view for pages_language_overlay in workspaces. + t3lib_BEfunc::fixVersioningPid($table, $currentRecord); // This is done to make the pid positive for offline versions; Necessary to have diff-view for pages_language_overlay in workspaces. // Get original language record if available: if (is_array($currentRecord) - && $TCA[$table]['ctrl']['transOrigDiffSourceField'] - && $TCA[$table]['ctrl']['languageField'] - && $currentRecord[$TCA[$table]['ctrl']['languageField']] > 0 - && $TCA[$table]['ctrl']['transOrigPointerField'] + && $TCA[$table]['ctrl']['transOrigDiffSourceField'] + && $TCA[$table]['ctrl']['languageField'] + && $currentRecord[$TCA[$table]['ctrl']['languageField']] > 0 + && $TCA[$table]['ctrl']['transOrigPointerField'] - && intval($currentRecord[$TCA[$table]['ctrl']['transOrigPointerField']]) > 0) { + && intval($currentRecord[$TCA[$table]['ctrl']['transOrigPointerField']]) > 0) { $lookUpTable = $TCA[$table]['ctrl']['transOrigPointerTable'] ? $TCA[$table]['ctrl']['transOrigPointerTable'] : $table; - $originalLanguageRecord = $this->recordInfo($lookUpTable,$currentRecord[$TCA[$table]['ctrl']['transOrigPointerField']],'*'); + $originalLanguageRecord = $this->recordInfo($lookUpTable, $currentRecord[$TCA[$table]['ctrl']['transOrigPointerField']], '*'); - t3lib_BEfunc::workspaceOL($lookUpTable,$originalLanguageRecord); + t3lib_BEfunc::workspaceOL($lookUpTable, $originalLanguageRecord); $originalLanguage_diffStorage = unserialize($currentRecord[$TCA[$table]['ctrl']['transOrigDiffSourceField']]); } } $this->checkValue_currentRecord = $checkValueRecord; - /* - In the following all incoming value-fields are tested: - - Are the user allowed to change the field? - - Is the field uid/pid (which are already set) - - perms-fields for pages-table, then do special things... - - If the field is nothing of the above and the field is configured in TCA, the fieldvalues are evaluated by ->checkValue + /* + In the following all incoming value-fields are tested: + - Are the user allowed to change the field? + - Is the field uid/pid (which are already set) + - perms-fields for pages-table, then do special things... + - If the field is nothing of the above and the field is configured in TCA, the fieldvalues are evaluated by ->checkValue - If everything is OK, the field is entered into $fieldArray[] - */ + If everything is OK, the field is entered into $fieldArray[] + */ - foreach($incomingFieldArray as $field => $fieldValue) { + foreach ($incomingFieldArray as $field => $fieldValue) { - if (!in_array($table.'-'.$field, $this->exclude_array) && !$this->data_disableFields[$table][$id][$field]) { // The field must be editable. + if (!in_array($table . '-' . $field, $this->exclude_array) && !$this->data_disableFields[$table][$id][$field]) { // The field must be editable. // Checking if a value for language can be changed: $languageDeny = $TCA[$table]['ctrl']['languageField'] && !strcmp($TCA[$table]['ctrl']['languageField'], $field) && !$this->BE_USER->checkLanguageAccess($fieldValue); - if (!$languageDeny) { + if (!$languageDeny) { // Stripping slashes - will probably be removed the day $this->stripslashes_values is removed as an option... - if ($this->stripslashes_values) { + if ($this->stripslashes_values) { - if (is_array($fieldValue)) { + if (is_array($fieldValue)) { t3lib_div::stripSlashesOnArray($fieldValue); - } else $fieldValue = stripslashes($fieldValue); + } else { + $fieldValue = stripslashes($fieldValue); - } + } + } - switch ($field) { + switch ($field) { case 'uid': case 'pid': // Nothing happens, already set @@ -1087,18 +1062,18 @@ case 'perms_group': case 'perms_everybody': // Permissions can be edited by the owner or the administrator - if ($table=='pages' && ($this->admin || $status=='new' || $this->pageInfo($id,'perms_userid')==$this->userid) ) { + if ($table == 'pages' && ($this->admin || $status == 'new' || $this->pageInfo($id, 'perms_userid') == $this->userid)) { - $value=intval($fieldValue); + $value = intval($fieldValue); - switch($field) { + switch ($field) { case 'perms_userid': - $fieldArray[$field]=$value; + $fieldArray[$field] = $value; break; case 'perms_groupid': - $fieldArray[$field]=$value; + $fieldArray[$field] = $value; break; default: - if ($value>=0 && $value= 0 && $value < pow(2, 5)) { - $fieldArray[$field]=$value; + $fieldArray[$field] = $value; } break; } @@ -1115,15 +1090,15 @@ // t3ver_label is not here because it CAN be edited as a regular field! break; default: - if (isset($TCA[$table]['columns'][$field])) { + if (isset($TCA[$table]['columns'][$field])) { // Evaluating the value - $res = $this->checkValue($table,$field,$fieldValue,$id,$status,$realPid,$tscPID); + $res = $this->checkValue($table, $field, $fieldValue, $id, $status, $realPid, $tscPID); - if (isset($res['value'])) { + if (isset($res['value'])) { $fieldArray[$field] = $res['value']; } // Add the value of the original record to the diff-storage content: - if ($this->updateModeL10NdiffData && $TCA[$table]['ctrl']['transOrigDiffSourceField']) { + if ($this->updateModeL10NdiffData && $TCA[$table]['ctrl']['transOrigDiffSourceField']) { $originalLanguage_diffStorage[$field] = $this->updateModeL10NdiffDataClear ? '' : $originalLanguageRecord[$field]; $diffStorageFlag = TRUE; } @@ -1132,51 +1107,51 @@ // When a copy or version is made of a record, a search is made for any RTEmagic* images in fields having the "images" soft reference parser applied. That should be true for RTE fields. If any are found they are duplicated to new names and the file reference in the bodytext is updated accordingly. // However, with auto-versioning the submitted content of the field will just overwrite the corrected values. This leaves a) lost RTEmagic files and b) creates a double reference to the old files. // The only solution I can come up with is detecting when auto versioning happens, then see if any RTEmagic images was copied and if so make a stupid string-replace of the content ! - if ($this->autoVersioningUpdate===TRUE) { + if ($this->autoVersioningUpdate === TRUE) { - if (is_array($this->RTEmagic_copyIndex[$table][$id][$field])) { + if (is_array($this->RTEmagic_copyIndex[$table][$id][$field])) { - foreach($this->RTEmagic_copyIndex[$table][$id][$field] as $oldRTEmagicName => $newRTEmagicName) { + foreach ($this->RTEmagic_copyIndex[$table][$id][$field] as $oldRTEmagicName => $newRTEmagicName) { - $fieldArray[$field] = str_replace(' src="'.$oldRTEmagicName.'"',' src="'.$newRTEmagicName.'"',$fieldArray[$field]); + $fieldArray[$field] = str_replace(' src="' . $oldRTEmagicName . '"', ' src="' . $newRTEmagicName . '"', $fieldArray[$field]); } } } - } elseif ($TCA[$table]['ctrl']['origUid']===$field) { // Allow value for original UID to pass by... + } elseif ($TCA[$table]['ctrl']['origUid'] === $field) { // Allow value for original UID to pass by... $fieldArray[$field] = $fieldValue; } break; } - } // Checking language. + } // Checking language. - } // Check exclude fields / disabled fields... + } // Check exclude fields / disabled fields... } // Add diff-storage information: - if ($diffStorageFlag && !isset($fieldArray[$TCA[$table]['ctrl']['transOrigDiffSourceField']])) { // If the field is set it would probably be because of an undo-operation - in which case we should not update the field of course... + if ($diffStorageFlag && !isset($fieldArray[$TCA[$table]['ctrl']['transOrigDiffSourceField']])) { // If the field is set it would probably be because of an undo-operation - in which case we should not update the field of course... - $fieldArray[$TCA[$table]['ctrl']['transOrigDiffSourceField']] = serialize($originalLanguage_diffStorage); + $fieldArray[$TCA[$table]['ctrl']['transOrigDiffSourceField']] = serialize($originalLanguage_diffStorage); } // Checking for RTE-transformations of fields: - $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$currentRecord); + $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table, $currentRecord); - $theTypeString = t3lib_BEfunc::getTCAtypeValue($table,$currentRecord); + $theTypeString = t3lib_BEfunc::getTCAtypeValue($table, $currentRecord); - if (is_array($types_fieldConfig)) { + if (is_array($types_fieldConfig)) { foreach ($types_fieldConfig as $vconf) { // Write file configuration: - $eFile = t3lib_parsehtml_proc::evalWriteFile($vconf['spec']['static_write'],array_merge($currentRecord,$fieldArray)); // inserted array_merge($currentRecord,$fieldArray) 170502 + $eFile = t3lib_parsehtml_proc::evalWriteFile($vconf['spec']['static_write'], array_merge($currentRecord, $fieldArray)); // inserted array_merge($currentRecord,$fieldArray) 170502 // RTE transformations: - if (!$this->dontProcessTransformations) { + if (!$this->dontProcessTransformations) { - if (isset($fieldArray[$vconf['field']])) { + if (isset($fieldArray[$vconf['field']])) { // Look for transformation flag: - switch((string)$incomingFieldArray['_TRANSFORM_'.$vconf['field']]) { + switch ((string) $incomingFieldArray['_TRANSFORM_' . $vconf['field']]) { case 'RTE': - $RTEsetup = $this->BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($tscPID)); + $RTEsetup = $this->BE_USER->getTSConfig('RTE', t3lib_BEfunc::getPagesTSconfig($tscPID)); - $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$table,$vconf['field'],$theTypeString); + $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'], $table, $vconf['field'], $theTypeString); // Set alternative relative path for RTE images/links: $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : ''; // Get RTE object, draw form and set flag: $RTEobj = t3lib_BEfunc::RTEgetObj(); - if (is_object($RTEobj)) { + if (is_object($RTEobj)) { - $fieldArray[$vconf['field']] = $RTEobj->transformContent('db',$fieldArray[$vconf['field']],$table,$vconf['field'],$currentRecord,$vconf['spec'],$thisConfig,$RTErelPath,$currentRecord['pid']); + $fieldArray[$vconf['field']] = $RTEobj->transformContent('db', $fieldArray[$vconf['field']], $table, $vconf['field'], $currentRecord, $vconf['spec'], $thisConfig, $RTErelPath, $currentRecord['pid']); } else { debug('NO RTE OBJECT FOUND!'); } @@ -1186,31 +1161,31 @@ } // Write file configuration: - if (is_array($eFile)) { + if (is_array($eFile)) { - $mixedRec = array_merge($currentRecord,$fieldArray); + $mixedRec = array_merge($currentRecord, $fieldArray); $SW_fileContent = t3lib_div::getUrl($eFile['editFile']); $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc'); /* @var $parseHTML t3lib_parsehtml_proc */ - $parseHTML->init('',''); + $parseHTML->init('', ''); - $eFileMarker = $eFile['markerField']&&trim($mixedRec[$eFile['markerField']]) ? trim($mixedRec[$eFile['markerField']]) : '###TYPO3_STATICFILE_EDIT###'; + $eFileMarker = $eFile['markerField'] && trim($mixedRec[$eFile['markerField']]) ? trim($mixedRec[$eFile['markerField']]) : '###TYPO3_STATICFILE_EDIT###'; - $insertContent = str_replace($eFileMarker,'',$mixedRec[$eFile['contentField']]); // must replace the marker if present in content! + $insertContent = str_replace($eFileMarker, '', $mixedRec[$eFile['contentField']]); // must replace the marker if present in content! - $SW_fileNewContent = $parseHTML->substituteSubpart($SW_fileContent, $eFileMarker, LF.$insertContent.LF, 1, 1); + $SW_fileNewContent = $parseHTML->substituteSubpart($SW_fileContent, $eFileMarker, LF . $insertContent . LF, 1, 1); - t3lib_div::writeFile($eFile['editFile'],$SW_fileNewContent); + t3lib_div::writeFile($eFile['editFile'], $SW_fileNewContent); // Write status: - if (!strstr($id,'NEW') && $eFile['statusField']) { + if (!strstr($id, 'NEW') && $eFile['statusField']) { $GLOBALS['TYPO3_DB']->exec_UPDATEquery( $table, - 'uid='.intval($id), + 'uid=' . intval($id), array( - $eFile['statusField'] => $eFile['relEditFile'].' updated '.date('d-m-Y H:i:s').', bytes '.strlen($mixedRec[$eFile['contentField']]) + $eFile['statusField'] => $eFile['relEditFile'] . ' updated ' . date('d-m-Y H:i:s') . ', bytes ' . strlen($mixedRec[$eFile['contentField']]) ) ); } - } elseif ($eFile && is_string($eFile)) { + } elseif ($eFile && is_string($eFile)) { - $this->log($table,$id,2,0,1,"Write-file error: '%s'",13,array($eFile),$realPid); + $this->log($table, $id, 2, 0, 1, "Write-file error: '%s'", 13, array($eFile), $realPid); } } } @@ -1219,16 +1194,6 @@ } - - - - - - - - - - /********************************************* * * Evaluation of input values @@ -1249,29 +1214,30 @@ * @param integer $tscPID * @return array Returns the evaluated $value as key "value" in this array. Can be checked with isset($res['value']) ... */ - function checkValue($table,$field,$value,$id,$status,$realPid,$tscPID) { + function checkValue($table, $field, $value, $id, $status, $realPid, $tscPID) { global $TCA, $PAGES_TYPES; t3lib_div::loadTCA($table); - $res = Array(); // result array + $res = array(); // result array - $recFID = $table.':'.$id.':'.$field; + $recFID = $table . ':' . $id . ':' . $field; // Processing special case of field pages.doktype if (($table === 'pages' || $table === 'pages_language_overlay') && $field === 'doktype') { // If the user may not use this specific doktype, we issue a warning - if (! ($this->admin || t3lib_div::inList($this->BE_USER->groupData['pagetypes_select'],$value))) { + if (!($this->admin || t3lib_div::inList($this->BE_USER->groupData['pagetypes_select'], $value))) { - $propArr = $this->getRecordProperties($table,$id); + $propArr = $this->getRecordProperties($table, $id); - $this->log($table,$id,5,0,1,"You cannot change the 'doktype' of page '%s' to the desired value.",1,array($propArr['header']),$propArr['event_pid']); + $this->log($table, $id, 5, 0, 1, "You cannot change the 'doktype' of page '%s' to the desired value.", 1, array($propArr['header']), $propArr['event_pid']); return $res; - }; + } + ; - if ($status=='update') { + if ($status == 'update') { // This checks 1) if we should check for disallowed tables and 2) if there are records from disallowed tables on the current page $onlyAllowedTables = isset($PAGES_TYPES[$value]['onlyAllowedTables']) ? $PAGES_TYPES[$value]['onlyAllowedTables'] : $PAGES_TYPES['default']['onlyAllowedTables']; - if ($onlyAllowedTables) { + if ($onlyAllowedTables) { - $theWrongTables = $this->doesPageHaveUnallowedTables($id,$value); + $theWrongTables = $this->doesPageHaveUnallowedTables($id, $value); - if ($theWrongTables) { + if ($theWrongTables) { - $propArr = $this->getRecordProperties($table,$id); + $propArr = $this->getRecordProperties($table, $id); - $this->log($table,$id,5,0,1,"'doktype' of page '%s' could not be changed because the page contains records from disallowed tables; %s",2,array($propArr['header'],$theWrongTables),$propArr['event_pid']); + $this->log($table, $id, 5, 0, 1, "'doktype' of page '%s' could not be changed because the page contains records from disallowed tables; %s", 2, array($propArr['header'], $theWrongTables), $propArr['event_pid']); return $res; } } @@ -1279,14 +1245,14 @@ } // Get current value: - $curValueRec = $this->recordInfo($table,$id,$field); + $curValueRec = $this->recordInfo($table, $id, $field); $curValue = $curValueRec[$field]; // Getting config for the field $tcaFieldConf = $TCA[$table]['columns'][$field]['config']; // Preform processing: - $res = $this->checkValue_SW($res,$value,$tcaFieldConf,$table,$id,$curValue,$status,$realPid,$recFID,$field,$this->uploadedFileArray[$table][$id][$field],$tscPID); + $res = $this->checkValue_SW($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $field, $this->uploadedFileArray[$table][$id][$field], $tscPID); return $res; } @@ -1309,37 +1275,37 @@ * @param [type] $tscPID: ... * @return array Returns the evaluated $value as key "value" in this array. */ - function checkValue_SW($res,$value,$tcaFieldConf,$table,$id,$curValue,$status,$realPid,$recFID,$field,$uploadedFiles,$tscPID) { + function checkValue_SW($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $field, $uploadedFiles, $tscPID) { - $PP = array($table,$id,$curValue,$status,$realPid,$recFID,$tscPID); + $PP = array($table, $id, $curValue, $status, $realPid, $recFID, $tscPID); switch ($tcaFieldConf['type']) { case 'text': - $res = $this->checkValue_text($res,$value,$tcaFieldConf,$PP,$field); + $res = $this->checkValue_text($res, $value, $tcaFieldConf, $PP, $field); break; case 'passthrough': case 'user': $res['value'] = $value; break; case 'input': - $res = $this->checkValue_input($res,$value,$tcaFieldConf,$PP,$field); + $res = $this->checkValue_input($res, $value, $tcaFieldConf, $PP, $field); break; case 'check': - $res = $this->checkValue_check($res,$value,$tcaFieldConf,$PP); + $res = $this->checkValue_check($res, $value, $tcaFieldConf, $PP); break; case 'radio': - $res = $this->checkValue_radio($res,$value,$tcaFieldConf,$PP); + $res = $this->checkValue_radio($res, $value, $tcaFieldConf, $PP); break; case 'group': case 'select': - $res = $this->checkValue_group_select($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field); + $res = $this->checkValue_group_select($res, $value, $tcaFieldConf, $PP, $uploadedFiles, $field); break; case 'inline': - $res = $this->checkValue_inline($res,$value,$tcaFieldConf,$PP,$field); + $res = $this->checkValue_inline($res, $value, $tcaFieldConf, $PP, $field); - break; + break; case 'flex': - if ($field) { // FlexForms are only allowed for real fields. + if ($field) { // FlexForms are only allowed for real fields. - $res = $this->checkValue_flex($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field); + $res = $this->checkValue_flex($res, $value, $tcaFieldConf, $PP, $uploadedFiles, $field); } break; default: @@ -1361,9 +1327,9 @@ * @param string Field name * @return array Modified $res array */ - function checkValue_text($res,$value,$tcaFieldConf,$PP,$field='') { + function checkValue_text($res, $value, $tcaFieldConf, $PP, $field = '') { - $evalCodesArray = t3lib_div::trimExplode(',',$tcaFieldConf['eval'],1); + $evalCodesArray = t3lib_div::trimExplode(',', $tcaFieldConf['eval'], 1); - $res = $this->checkValue_text_Eval($value,$evalCodesArray,$tcaFieldConf['is_in']); + $res = $this->checkValue_text_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']); return $res; } @@ -1377,8 +1343,8 @@ * @param string Field name * @return array Modified $res array */ - function checkValue_input($res,$value,$tcaFieldConf,$PP,$field='') { + function checkValue_input($res, $value, $tcaFieldConf, $PP, $field = '') { - list($table,$id,$curValue,$status,$realPid,$recFID) = $PP; + list($table, $id, $curValue, $status, $realPid, $recFID) = $PP; // Secures the string-length to be less than max. if (intval($tcaFieldConf['max']) > 0) { @@ -1386,22 +1352,26 @@ } // Checking range of value: - if ($tcaFieldConf['range'] && $value!=$tcaFieldConf['checkbox']) { // If value is not set to the allowed checkbox-value then it is checked against the ranges + if ($tcaFieldConf['range'] && $value != $tcaFieldConf['checkbox']) { // If value is not set to the allowed checkbox-value then it is checked against the ranges - if (isset($tcaFieldConf['range']['upper'])&&$value>$tcaFieldConf['range']['upper']) {$value=$tcaFieldConf['range']['upper'];} - if (isset($tcaFieldConf['range']['lower'])&&$value<$tcaFieldConf['range']['lower']) {$value=$tcaFieldConf['range']['lower'];} + if (isset($tcaFieldConf['range']['upper']) && $value > $tcaFieldConf['range']['upper']) { + $value = $tcaFieldConf['range']['upper']; - } + } + if (isset($tcaFieldConf['range']['lower']) && $value < $tcaFieldConf['range']['lower']) { + $value = $tcaFieldConf['range']['lower']; + } + } // Process evaluation settings: - $evalCodesArray = t3lib_div::trimExplode(',',$tcaFieldConf['eval'],1); + $evalCodesArray = t3lib_div::trimExplode(',', $tcaFieldConf['eval'], 1); - $res = $this->checkValue_input_Eval($value,$evalCodesArray,$tcaFieldConf['is_in']); + $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']); // Process UNIQUE settings: - if ($field && $realPid>=0) { // Field is NOT set for flexForms - which also means that uniqueInPid and unique is NOT available for flexForm fields! Also getUnique should not be done for versioning and if PID is -1 ($realPid<0) then versioning is happening... + if ($field && $realPid >= 0) { // Field is NOT set for flexForms - which also means that uniqueInPid and unique is NOT available for flexForm fields! Also getUnique should not be done for versioning and if PID is -1 ($realPid<0) then versioning is happening... - if ($res['value'] && in_array('uniqueInPid',$evalCodesArray)) { + if ($res['value'] && in_array('uniqueInPid', $evalCodesArray)) { - $res['value'] = $this->getUnique($table,$field,$res['value'],$id,$realPid); + $res['value'] = $this->getUnique($table, $field, $res['value'], $id, $realPid); } - if ($res['value'] && in_array('unique',$evalCodesArray)) { + if ($res['value'] && in_array('unique', $evalCodesArray)) { - $res['value'] = $this->getUnique($table,$field,$res['value'],$id); + $res['value'] = $this->getUnique($table, $field, $res['value'], $id); } } @@ -1417,15 +1387,21 @@ * @param array Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID * @return array Modified $res array */ - function checkValue_check($res,$value,$tcaFieldConf,$PP) { + function checkValue_check($res, $value, $tcaFieldConf, $PP) { - list($table,$id,$curValue,$status,$realPid,$recFID) = $PP; + list($table, $id, $curValue, $status, $realPid, $recFID) = $PP; $itemC = count($tcaFieldConf['items']); - if (!$itemC) {$itemC=1;} + if (!$itemC) { + $itemC = 1; + } - $maxV = pow(2,$itemC); + $maxV = pow(2, $itemC); - if ($value<0) {$value=0;} - if ($value>$maxV) {$value=$maxV;} + if ($value < 0) { + $value = 0; + } + if ($value > $maxV) { + $value = $maxV; + } $res['value'] = $value; return $res; @@ -1440,12 +1416,12 @@ * @param array Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID * @return array Modified $res array */ - function checkValue_radio($res,$value,$tcaFieldConf,$PP) { + function checkValue_radio($res, $value, $tcaFieldConf, $PP) { - list($table,$id,$curValue,$status,$realPid,$recFID) = $PP; + list($table, $id, $curValue, $status, $realPid, $recFID) = $PP; - if (is_array($tcaFieldConf['items'])) { + if (is_array($tcaFieldConf['items'])) { - foreach($tcaFieldConf['items'] as $set) { + foreach ($tcaFieldConf['items'] as $set) { - if (!strcmp($set[1],$value)) { + if (!strcmp($set[1], $value)) { $res['value'] = $value; break; } @@ -1466,13 +1442,13 @@ * @param string Field name * @return array Modified $res array */ - function checkValue_group_select($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field) { + function checkValue_group_select($res, $value, $tcaFieldConf, $PP, $uploadedFiles, $field) { - list($table,$id,$curValue,$status,$realPid,$recFID) = $PP; + list($table, $id, $curValue, $status, $realPid, $recFID) = $PP; // Detecting if value sent is an array and if so, implode it around a comma: - if (is_array($value)) { + if (is_array($value)) { - $value = implode(',',$value); + $value = implode(',', $value); } // This converts all occurencies of '{' to the byte 123 in the string - this is needed in very rare cases where filenames with special characters (like ???, umlaud etc) gets sent to the server as HTML entities instead of bytes. The error is done only by MSIE, not Mozilla and Opera. @@ -1483,42 +1459,42 @@ $valueArray = $this->checkValue_group_select_explodeSelectGroupValue($value); // If not multiple is set, then remove duplicates: - if (!$tcaFieldConf['multiple']) { + if (!$tcaFieldConf['multiple']) { $valueArray = array_unique($valueArray); } // If an exclusive key is found, discard all others: - if ($tcaFieldConf['type']=='select' && $tcaFieldConf['exclusiveKeys']) { + if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['exclusiveKeys']) { $exclusiveKeys = t3lib_div::trimExplode(',', $tcaFieldConf['exclusiveKeys']); - foreach($valueArray as $kk => $vv) { + foreach ($valueArray as $kk => $vv) { - if (in_array($vv, $exclusiveKeys)) { // $vv is the item key! + if (in_array($vv, $exclusiveKeys)) { // $vv is the item key! - $valueArray = Array($kk => $vv); + $valueArray = array($kk => $vv); break; } } } - // This could be a good spot for parsing the array through a validation-function which checks if the values are alright (except that database references are not in their final form - but that is the point, isn't it?) - // NOTE!!! Must check max-items of files before the later check because that check would just leave out filenames if there are too many!! + // This could be a good spot for parsing the array through a validation-function which checks if the values are alright (except that database references are not in their final form - but that is the point, isn't it?) + // NOTE!!! Must check max-items of files before the later check because that check would just leave out filenames if there are too many!! // Checking for select / authMode, removing elements from $valueArray if any of them is not allowed! - if ($tcaFieldConf['type']=='select' && $tcaFieldConf['authMode']) { + if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['authMode']) { $preCount = count($valueArray); - foreach($valueArray as $kk => $vv) { + foreach ($valueArray as $kk => $vv) { - if (!$this->BE_USER->checkAuthMode($table,$field,$vv,$tcaFieldConf['authMode'])) { + if (!$this->BE_USER->checkAuthMode($table, $field, $vv, $tcaFieldConf['authMode'])) { unset($valueArray[$kk]); } } // During the check it turns out that the value / all values were removed - we respond by simply returning an empty array so nothing is written to DB for this field. - if ($preCount && !count($valueArray)) { + if ($preCount && !count($valueArray)) { return array(); } } // For group types: - if ($tcaFieldConf['type']=='group') { + if ($tcaFieldConf['type'] == 'group') { - switch($tcaFieldConf['internal_type']) { + switch ($tcaFieldConf['internal_type']) { case 'file_reference': case 'file': $valueArray = $this->checkValue_group_select_file( @@ -1538,9 +1514,9 @@ } } // For select types which has a foreign table attached: - if ($tcaFieldConf['type']=='select' && $tcaFieldConf['foreign_table']) { + if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['foreign_table']) { // check, if there is a NEW... id in the value, that should be substituded later - if (strpos($value, 'NEW') !== false) { + if (strpos($value, 'NEW') !== FALSE) { $this->remapStackRecords[$table][$id] = array('remapStackIndex' => count($this->remapStack)); $this->addNewValuesToRemapStackChildIds($valueArray); $this->remapStack[] = array( @@ -1549,15 +1525,15 @@ 'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 5), 'field' => $field ); - $unsetResult = true; + $unsetResult = TRUE; } else { $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field); } } if (!$unsetResult) { - $newVal=$this->checkValue_checkMax($tcaFieldConf, $valueArray); + $newVal = $this->checkValue_checkMax($tcaFieldConf, $valueArray); - $res['value'] = implode(',',$newVal); + $res['value'] = implode(',', $newVal); } else { unset($res['value']); } @@ -1579,25 +1555,25 @@ * @return array Modified value array * @see checkValue_group_select() */ - function checkValue_group_select_file($valueArray,$tcaFieldConf,$curValue,$uploadedFileArray,$status,$table,$id,$recFID) { + function checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFileArray, $status, $table, $id, $recFID) { - if (!$this->bypassFileHandling) { // If filehandling should NOT be bypassed, do processing: + if (!$this->bypassFileHandling) { // If filehandling should NOT be bypassed, do processing: // If any files are uploaded, add them to value array if (is_array($uploadedFileArray) && $uploadedFileArray['name'] && - strcmp($uploadedFileArray['tmp_name'],'none')) { + strcmp($uploadedFileArray['tmp_name'], 'none')) { - $valueArray[]=$uploadedFileArray['tmp_name']; + $valueArray[] = $uploadedFileArray['tmp_name']; - $this->alternativeFileName[$uploadedFileArray['tmp_name']] = $uploadedFileArray['name']; + $this->alternativeFileName[$uploadedFileArray['tmp_name']] = $uploadedFileArray['name']; } // Creating fileFunc object. - if (!$this->fileFunc) { + if (!$this->fileFunc) { $this->fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions'); - $this->include_filefunctions=1; + $this->include_filefunctions = 1; } // Setting permitted extensions. - $all_files = Array(); + $all_files = array(); $all_files['webspace']['allow'] = $tcaFieldConf['allowed']; $all_files['webspace']['deny'] = $tcaFieldConf['disallowed'] ? $tcaFieldConf['disallowed'] : '*'; $all_files['ftpspace'] = $all_files['webspace']; @@ -1606,15 +1582,15 @@ // If there is an upload folder defined: if ($tcaFieldConf['uploadfolder'] && $tcaFieldConf['internal_type'] == 'file') { - if (!$this->bypassFileHandling) { // If filehandling should NOT be bypassed, do processing: + if (!$this->bypassFileHandling) { // If filehandling should NOT be bypassed, do processing: // For logging.. - $propArr = $this->getRecordProperties($table,$id); + $propArr = $this->getRecordProperties($table, $id); // Get destrination path: $dest = $this->destPathFromUploadFolder($tcaFieldConf['uploadfolder']); // If we are updating: - if ($status=='update') { + if ($status == 'update') { // Traverse the input values and convert to absolute filenames in case the update happens to an autoVersionized record. // Background: This is a horrible workaround! The problem is that when a record is auto-versionized the files of the record get copied and therefore get new names which is overridden with the names from the original record in the incoming data meaning both lost files and double-references! @@ -1625,71 +1601,71 @@ // The versions uid is 456 and the file is copied to "logo_01.gif". But the form data that we sent was based on uid 123 and hence contains the filename "logo.gif" from the original. // The file management code below will do two things: First it will blindly accept "logo.gif" as a file attached to the record (thus creating a double reference) and secondly it will find that "logo_01.gif" was not in the incoming filelist and therefore should be deleted. // If we prefix the incoming file "logo.gif" with its absolute path it will be seen as a new file added. Thus it will be copied to "logo_02.gif". "logo_01.gif" will still be deleted but since the files are the same the difference is zero - only more processing and file copying for no reason. But it will work. - if ($this->autoVersioningUpdate===TRUE) { + if ($this->autoVersioningUpdate === TRUE) { - foreach($valueArray as $key => $theFile) { + foreach ($valueArray as $key => $theFile) { - if ($theFile===basename($theFile)) { // If it is an already attached file... + if ($theFile === basename($theFile)) { // If it is an already attached file... - $valueArray[$key] = PATH_site.$tcaFieldConf['uploadfolder'].'/'.$theFile; + $valueArray[$key] = PATH_site . $tcaFieldConf['uploadfolder'] . '/' . $theFile; } } } // Finding the CURRENT files listed, either from MM or from the current record. - $theFileValues=array(); + $theFileValues = array(); - if ($tcaFieldConf['MM']) { // If MM relations for the files also! + if ($tcaFieldConf['MM']) { // If MM relations for the files also! $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); /* @var $dbAnalysis t3lib_loadDBGroup */ - $dbAnalysis->start('','files',$tcaFieldConf['MM'],$id); + $dbAnalysis->start('', 'files', $tcaFieldConf['MM'], $id); foreach ($dbAnalysis->itemArray as $item) { if ($item['id']) { $theFileValues[] = $item['id']; } } } else { - $theFileValues=t3lib_div::trimExplode(',',$curValue,1); + $theFileValues = t3lib_div::trimExplode(',', $curValue, 1); } $currentFilesForHistory = implode(',', $theFileValues); // DELETE files: If existing files were found, traverse those and register files for deletion which has been removed: - if (count($theFileValues)) { + if (count($theFileValues)) { // Traverse the input values and for all input values which match an EXISTING value, remove the existing from $theFileValues array (this will result in an array of all the existing files which should be deleted!) - foreach($valueArray as $key => $theFile) { + foreach ($valueArray as $key => $theFile) { - if ($theFile && !strstr(t3lib_div::fixWindowsFilePath($theFile),'/')) { + if ($theFile && !strstr(t3lib_div::fixWindowsFilePath($theFile), '/')) { - $theFileValues = t3lib_div::removeArrayEntryByValue($theFileValues,$theFile); + $theFileValues = t3lib_div::removeArrayEntryByValue($theFileValues, $theFile); } } // This array contains the filenames in the uploadfolder that should be deleted: - foreach($theFileValues as $key => $theFile) { + foreach ($theFileValues as $key => $theFile) { $theFile = trim($theFile); - if (@is_file($dest.'/'.$theFile)) { + if (@is_file($dest . '/' . $theFile)) { - $this->removeFilesStore[]=$dest.'/'.$theFile; + $this->removeFilesStore[] = $dest . '/' . $theFile; } elseif ($theFile) { - $this->log($table,$id,5,0,1,"Could not delete file '%s' (does not exist). (%s)",10,array($dest.'/'.$theFile, $recFID),$propArr['event_pid']); + $this->log($table, $id, 5, 0, 1, "Could not delete file '%s' (does not exist). (%s)", 10, array($dest . '/' . $theFile, $recFID), $propArr['event_pid']); } } } } // Traverse the submitted values: - foreach($valueArray as $key => $theFile) { + foreach ($valueArray as $key => $theFile) { // NEW FILES? If the value contains '/' it indicates, that the file is new and should be added to the uploadsdir (whether its absolute or relative does not matter here) - if (strstr(t3lib_div::fixWindowsFilePath($theFile),'/')) { + if (strstr(t3lib_div::fixWindowsFilePath($theFile), '/')) { // Init: $maxSize = intval($tcaFieldConf['max_size']); - $cmd=''; + $cmd = ''; - $theDestFile=''; // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error! + $theDestFile = ''; // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error! // Check various things before copying file: - if (@is_dir($dest) && (@is_file($theFile) || @is_uploaded_file($theFile))) { // File and destination must exist + if (@is_dir($dest) && (@is_file($theFile) || @is_uploaded_file($theFile))) { // File and destination must exist // Finding size. For safe_mode we have to rely on the size in the upload array if the file is uploaded. - if (is_uploaded_file($theFile) && $theFile==$uploadedFileArray['tmp_name']) { + if (is_uploaded_file($theFile) && $theFile == $uploadedFileArray['tmp_name']) { $fileSize = $uploadedFileArray['size']; } else { $fileSize = filesize($theFile); } - if (!$maxSize || $fileSize<=($maxSize*1024)) { // Check file size: + if (!$maxSize || $fileSize <= ($maxSize * 1024)) { // Check file size: // Prepare filename: $theEndFileName = isset($this->alternativeFileName[$theFile]) ? $this->alternativeFileName[$theFile] : $theFile; $fI = t3lib_div::split_fileref($theEndFileName); @@ -1699,8 +1675,8 @@ $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($fI['file']), $dest); // If we have a unique destination filename, then write the file: - if ($theDestFile) { + if ($theDestFile) { - t3lib_div::upload_copy_move($theFile,$theDestFile); + t3lib_div::upload_copy_move($theFile, $theDestFile); // Hook for post-processing the upload action if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processUpload'])) { @@ -1717,37 +1693,47 @@ $this->copiedFileMap[$theFile] = $theDestFile; clearstatcache(); - if (!@is_file($theDestFile)) $this->log($table,$id,5,0,1,"Copying file '%s' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)",16,array($theFile, dirname($theDestFile), $recFID),$propArr['event_pid']); - } else $this->log($table,$id,5,0,1,"Copying file '%s' failed!: No destination file (%s) possible!. (%s)",11,array($theFile, $theDestFile, $recFID),$propArr['event_pid']); - } else $this->log($table,$id,5,0,1,"File extension '%s' not allowed. (%s)",12,array($fI['fileext'], $recFID),$propArr['event_pid']); - } else $this->log($table,$id,5,0,1,"Filesize (%s) of file '%s' exceeds limit (%s). (%s)",13,array(t3lib_div::formatSize($fileSize),$theFile,t3lib_div::formatSize($maxSize*1024),$recFID),$propArr['event_pid']); - } else $this->log($table,$id,5,0,1,'The destination (%s) or the source file (%s) does not exist. (%s)',14,array($dest, $theFile, $recFID),$propArr['event_pid']); + if (!@is_file($theDestFile)) { + $this->log($table, $id, 5, 0, 1, "Copying file '%s' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)", 16, array($theFile, dirname($theDestFile), $recFID), $propArr['event_pid']); + } + } else { + $this->log($table, $id, 5, 0, 1, "Copying file '%s' failed!: No destination file (%s) possible!. (%s)", 11, array($theFile, $theDestFile, $recFID), $propArr['event_pid']); + } + } else { + $this->log($table, $id, 5, 0, 1, "File extension '%s' not allowed. (%s)", 12, array($fI['fileext'], $recFID), $propArr['event_pid']); + } + } else { + $this->log($table, $id, 5, 0, 1, "Filesize (%s) of file '%s' exceeds limit (%s). (%s)", 13, array(t3lib_div::formatSize($fileSize), $theFile, t3lib_div::formatSize($maxSize * 1024), $recFID), $propArr['event_pid']); + } + } else { + $this->log($table, $id, 5, 0, 1, 'The destination (%s) or the source file (%s) does not exist. (%s)', 14, array($dest, $theFile, $recFID), $propArr['event_pid']); + } // If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array! - if (@is_file($theDestFile)) { + if (@is_file($theDestFile)) { $info = t3lib_div::split_fileref($theDestFile); - $valueArray[$key]=$info['file']; // The value is set to the new filename + $valueArray[$key] = $info['file']; // The value is set to the new filename } else { - unset($valueArray[$key]); // The value is set to the new filename + unset($valueArray[$key]); // The value is set to the new filename } } } } // If MM relations for the files, we will set the relations as MM records and change the valuearray to contain a single entry with a count of the number of files! - if ($tcaFieldConf['MM']) { + if ($tcaFieldConf['MM']) { $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); /* @var $dbAnalysis t3lib_loadDBGroup */ - $dbAnalysis->tableArray['files']=array(); // dummy + $dbAnalysis->tableArray['files'] = array(); // dummy foreach ($valueArray as $key => $theFile) { // explode files - $dbAnalysis->itemArray[]['id']=$theFile; + $dbAnalysis->itemArray[]['id'] = $theFile; } - if ($status=='update') { + if ($status == 'update') { - $dbAnalysis->writeMM($tcaFieldConf['MM'],$id,0); + $dbAnalysis->writeMM($tcaFieldConf['MM'], $id, 0); $newFiles = implode(',', $dbAnalysis->getValueArray()); - list(,,$recFieldName) = explode(':', $recFID); + list(, , $recFieldName) = explode(':', $recFID); if ($currentFilesForHistory != $newFiles) { $this->mmHistoryRecords[$table . ':' . $id]['oldRecord'][$recFieldName] = $currentFilesForHistory; $this->mmHistoryRecords[$table . ':' . $id]['newRecord'][$recFieldName] = $newFiles; @@ -1756,26 +1742,26 @@ $this->mmHistoryRecords[$table . ':' . $id]['newRecord'][$recFieldName] = ''; } } else { - $this->dbAnalysisStore[] = array($dbAnalysis, $tcaFieldConf['MM'], $id, 0); // This will be traversed later to execute the actions + $this->dbAnalysisStore[] = array($dbAnalysis, $tcaFieldConf['MM'], $id, 0); // This will be traversed later to execute the actions } $valueArray = $dbAnalysis->countItems(); } //store path relative to site root (if uploadfolder is not set or internal_type is file_reference) } else { - if (count($valueArray)){ + if (count($valueArray)) { - if (!$this->bypassFileHandling) { // If filehandling should NOT be bypassed, do processing: + if (!$this->bypassFileHandling) { // If filehandling should NOT be bypassed, do processing: $propArr = $this->getRecordProperties($table, $id); // For logging.. - foreach($valueArray as &$theFile){ + foreach ($valueArray as &$theFile) { // if alernative File Path is set for the file, then it was an import - if ($this->alternativeFilePath[$theFile]){ + if ($this->alternativeFilePath[$theFile]) { // don't import the file if it already exists if (@is_file(PATH_site . $this->alternativeFilePath[$theFile])) { $theFile = PATH_site . $this->alternativeFilePath[$theFile]; // import the file - } elseif (@is_file($theFile)){ + } elseif (@is_file($theFile)) { $dest = dirname(PATH_site . $this->alternativeFilePath[$theFile]); if (!@is_dir($dest)) { t3lib_div::mkdir_deep(PATH_site, dirname($this->alternativeFilePath[$theFile]) . '/'); @@ -1784,10 +1770,10 @@ // Init: $maxSize = intval($tcaFieldConf['max_size']); $cmd = ''; - $theDestFile = ''; // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error! + $theDestFile = ''; // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error! $fileSize = filesize($theFile); - if (!$maxSize || $fileSize <= ($maxSize * 1024)) { // Check file size: + if (!$maxSize || $fileSize <= ($maxSize * 1024)) { // Check file size: // Prepare filename: $theEndFileName = isset($this->alternativeFileName[$theFile]) ? $this->alternativeFileName[$theFile] : $theFile; $fI = t3lib_div::split_fileref($theEndFileName); @@ -1797,17 +1783,25 @@ $theDestFile = PATH_site . $this->alternativeFilePath[$theFile]; // Write the file: - if ($theDestFile) { + if ($theDestFile) { t3lib_div::upload_copy_move($theFile, $theDestFile); $this->copiedFileMap[$theFile] = $theDestFile; clearstatcache(); - if (!@is_file($theDestFile)) $this->log($table, $id, 5, 0, 1, "Copying file '%s' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)", 16, array($theFile, dirname($theDestFile), $recFID), $propArr['event_pid']); - } else $this->log($table, $id, 5, 0, 1, "Copying file '%s' failed!: No destination file (%s) possible!. (%s)", 11, array($theFile, $theDestFile, $recFID), $propArr['event_pid']); - } else $this->log($table, $id, 5, 0, 1, "File extension '%s' not allowed. (%s)", 12, array($fI['fileext'], $recFID), $propArr['event_pid']); - } else $this->log($table, $id, 5, 0, 1, "Filesize (%s) of file '%s' exceeds limit (%s). (%s)", 13, array(t3lib_div::formatSize($fileSize), $theFile,t3lib_div::formatSize($maxSize * 1024),$recFID), $propArr['event_pid']); + if (!@is_file($theDestFile)) { + $this->log($table, $id, 5, 0, 1, "Copying file '%s' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)", 16, array($theFile, dirname($theDestFile), $recFID), $propArr['event_pid']); + } + } else { + $this->log($table, $id, 5, 0, 1, "Copying file '%s' failed!: No destination file (%s) possible!. (%s)", 11, array($theFile, $theDestFile, $recFID), $propArr['event_pid']); + } + } else { + $this->log($table, $id, 5, 0, 1, "File extension '%s' not allowed. (%s)", 12, array($fI['fileext'], $recFID), $propArr['event_pid']); + } + } else { + $this->log($table, $id, 5, 0, 1, "Filesize (%s) of file '%s' exceeds limit (%s). (%s)", 13, array(t3lib_div::formatSize($fileSize), $theFile, t3lib_div::formatSize($maxSize * 1024), $recFID), $propArr['event_pid']); + } // If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array! - if (@is_file($theDestFile)) { + if (@is_file($theDestFile)) { $theFile = $theDestFile; // The value is set to the new filename } else { unset($theFile); // The value is set to the new filename @@ -1838,55 +1832,59 @@ * @param string Field name * @return array Modified $res array */ - function checkValue_flex($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field) { + function checkValue_flex($res, $value, $tcaFieldConf, $PP, $uploadedFiles, $field) { - list($table,$id,$curValue,$status,$realPid,$recFID) = $PP; + list($table, $id, $curValue, $status, $realPid, $recFID) = $PP; - if (is_array($value)) { + if (is_array($value)) { // This value is necessary for flex form processing to happen on flexform fields in page records when they are copied. // The problem is, that when copying a page, flexfrom XML comes along in the array for the new record - but since $this->checkValue_currentRecord does not have a uid or pid for that sake, the t3lib_BEfunc::getFlexFormDS() function returns no good DS. For new records we do know the expected PID so therefore we send that with this special parameter. Only active when larger than zero. - $newRecordPidValue = $status=='new' ? $realPid : 0; + $newRecordPidValue = $status == 'new' ? $realPid : 0; // Get current value array: - $dataStructArray = t3lib_BEfunc::getFlexFormDS($tcaFieldConf,$this->checkValue_currentRecord,$table,'',TRUE,$newRecordPidValue); + $dataStructArray = t3lib_BEfunc::getFlexFormDS($tcaFieldConf, $this->checkValue_currentRecord, $table, '', TRUE, $newRecordPidValue); $currentValueArray = t3lib_div::xml2array($curValue); - if (!is_array($currentValueArray)) $currentValueArray = array(); - if (is_array($currentValueArray['meta']['currentLangId'])) unset($currentValueArray['meta']['currentLangId']); // Remove all old meta for languages... + if (!is_array($currentValueArray)) { + $currentValueArray = array(); + } + if (is_array($currentValueArray['meta']['currentLangId'])) { + unset($currentValueArray['meta']['currentLangId']); + } // Remove all old meta for languages... // Evaluation of input values: - $value['data'] = $this->checkValue_flex_procInData($value['data'],$currentValueArray['data'],$uploadedFiles['data'],$dataStructArray,$PP); + $value['data'] = $this->checkValue_flex_procInData($value['data'], $currentValueArray['data'], $uploadedFiles['data'], $dataStructArray, $PP); // Create XML and convert charsets from input value: - $xmlValue = $this->checkValue_flexArray2Xml($value,TRUE); + $xmlValue = $this->checkValue_flexArray2Xml($value, TRUE); // If we wanted to set UTF fixed: - // $storeInCharset='utf-8'; - // $currentCharset=$GLOBALS['LANG']->charSet; - // $xmlValue = $GLOBALS['LANG']->csConvObj->conv($xmlValue,$currentCharset,$storeInCharset,1); + // $storeInCharset='utf-8'; + // $currentCharset=$GLOBALS['LANG']->charSet; + // $xmlValue = $GLOBALS['LANG']->csConvObj->conv($xmlValue,$currentCharset,$storeInCharset,1); - $storeInCharset=$GLOBALS['LANG']->charSet; + $storeInCharset = $GLOBALS['LANG']->charSet; // Merge them together IF they are both arrays: // Here we convert the currently submitted values BACK to an array, then merge the two and then BACK to XML again. This is needed to ensure the charsets are the same (provided that the current value was already stored IN the charset that the new value is converted to). - if (is_array($currentValueArray)) { + if (is_array($currentValueArray)) { $arrValue = t3lib_div::xml2array($xmlValue); - $arrValue = t3lib_div::array_merge_recursive_overrule($currentValueArray,$arrValue); + $arrValue = t3lib_div::array_merge_recursive_overrule($currentValueArray, $arrValue); - $xmlValue = $this->checkValue_flexArray2Xml($arrValue,TRUE); + $xmlValue = $this->checkValue_flexArray2Xml($arrValue, TRUE); } // Action commands (sorting order and removals of elements) $actionCMDs = t3lib_div::_GP('_ACTION_FLEX_FORMdata'); - if (is_array($actionCMDs[$table][$id][$field]['data'])) { + if (is_array($actionCMDs[$table][$id][$field]['data'])) { $arrValue = t3lib_div::xml2array($xmlValue); - $this->_ACTION_FLEX_FORMdata($arrValue['data'],$actionCMDs[$table][$id][$field]['data']); + $this->_ACTION_FLEX_FORMdata($arrValue['data'], $actionCMDs[$table][$id][$field]['data']); - $xmlValue = $this->checkValue_flexArray2Xml($arrValue,TRUE); + $xmlValue = $this->checkValue_flexArray2Xml($arrValue, TRUE); } // Create the value XML: - $res['value']=''; + $res['value'] = ''; - $res['value'].=$xmlValue; + $res['value'] .= $xmlValue; - } else { // Passthrough...: + } else { // Passthrough...: - $res['value']=$value; + $res['value'] = $value; } return $res; @@ -1899,7 +1897,7 @@ * @param boolean If set, the XML prologue is returned as well. * @return string Input array converted to XML */ - function checkValue_flexArray2Xml($array, $addPrologue=FALSE) { + function checkValue_flexArray2Xml($array, $addPrologue = FALSE) { $flexObj = t3lib_div::makeInstance('t3lib_flexformtools'); /* @var $flexObj t3lib_flexformtools */ return $flexObj->flexArray2Xml($array, $addPrologue); @@ -1912,27 +1910,27 @@ * @param array $deleteCMDS: ... * * @return void */ - function _ACTION_FLEX_FORMdata(&$valueArray,$actionCMDs) { + function _ACTION_FLEX_FORMdata(&$valueArray, $actionCMDs) { - if (is_array($valueArray) && is_array($actionCMDs)) { + if (is_array($valueArray) && is_array($actionCMDs)) { - foreach($actionCMDs as $key => $value) { + foreach ($actionCMDs as $key => $value) { - if ($key=='_ACTION') { + if ($key == '_ACTION') { // First, check if there are "commands": - if (current($actionCMDs[$key])!=="") { + if (current($actionCMDs[$key]) !== "") { asort($actionCMDs[$key]); $newValueArray = array(); - foreach($actionCMDs[$key] as $idx => $order) { + foreach ($actionCMDs[$key] as $idx => $order) { - if (substr($idx,0,3)=="ID-") { + if (substr($idx, 0, 3) == "ID-") { $idx = $this->newIndexMap[$idx]; } - if ($order!="DELETE") { // Just one reflection here: It is clear that when removing elements from a flexform, then we will get lost files unless we act on this delete operation by traversing and deleting files that were referred to. + if ($order != "DELETE") { // Just one reflection here: It is clear that when removing elements from a flexform, then we will get lost files unless we act on this delete operation by traversing and deleting files that were referred to. $newValueArray[$idx] = $valueArray[$idx]; } unset($valueArray[$idx]); } - $valueArray = t3lib_div::array_merge($newValueArray,$valueArray); + $valueArray = t3lib_div::array_merge($newValueArray, $valueArray); } - } elseif (is_array($actionCMDs[$key]) && isset($valueArray[$key])) { + } elseif (is_array($actionCMDs[$key]) && isset($valueArray[$key])) { - $this->_ACTION_FLEX_FORMdata($valueArray[$key],$actionCMDs[$key]); + $this->_ACTION_FLEX_FORMdata($valueArray[$key], $actionCMDs[$key]); } } } @@ -1949,11 +1947,11 @@ * @param string Field name * @return array Modified $res array */ - function checkValue_inline($res,$value,$tcaFieldConf,$PP,$field) { + function checkValue_inline($res, $value, $tcaFieldConf, $PP, $field) { list($table, $id, $curValue, $status, $realPid, $recFID) = $PP; - if (!$tcaFieldConf['foreign_table']) { + if (!$tcaFieldConf['foreign_table']) { - return false; // Fatal error, inline fields should always have a foreign_table defined + return FALSE; // Fatal error, inline fields should always have a foreign_table defined } // When values are sent they come as comma-separated values which are exploded by this function: @@ -1965,7 +1963,7 @@ // Example for received data: // $value = 45,NEW4555fdf59d154,12,123 // We need to decide whether we use the stack or can save the relation directly. - if(strpos($value, 'NEW') !== false || !t3lib_div::testInt($id)) { + if (strpos($value, 'NEW') !== FALSE || !t3lib_div::testInt($id)) { $this->remapStackRecords[$table][$id] = array('remapStackIndex' => count($this->remapStack)); $this->addNewValuesToRemapStackChildIds($valueArray); $this->remapStack[] = array( @@ -1975,7 +1973,7 @@ 'field' => $field ); unset($res['value']); - } elseif($value || t3lib_div::testInt($id)) { + } elseif ($value || t3lib_div::testInt($id)) { $res['value'] = $this->checkValue_inline_processDBdata($valueArray, $tcaFieldConf, $id, $status, $table, $field); } @@ -1991,41 +1989,30 @@ * @return array The truncated value array of items */ function checkValue_checkMax($tcaFieldConf, $valueArray) { - // BTW, checking for min and max items here does NOT make any sense when MM is used because the above function calls will just return an array with a single item (the count) if MM is used... Why didn't I perform the check before? Probably because we could not evaluate the validity of record uids etc... Hmm... + // BTW, checking for min and max items here does NOT make any sense when MM is used because the above function calls will just return an array with a single item (the count) if MM is used... Why didn't I perform the check before? Probably because we could not evaluate the validity of record uids etc... Hmm... $valueArrayC = count($valueArray); // NOTE to the comment: It's not really possible to check for too few items, because you must then determine first, if the field is actual used regarding the CType. - $maxI = isset($tcaFieldConf['maxitems']) ? intval($tcaFieldConf['maxitems']):1; + $maxI = isset($tcaFieldConf['maxitems']) ? intval($tcaFieldConf['maxitems']) : 1; - if ($valueArrayC > $maxI) {$valueArrayC=$maxI;} // Checking for not too many elements + if ($valueArrayC > $maxI) { + $valueArrayC = $maxI; + } // Checking for not too many elements // Dumping array to list - $newVal=array(); + $newVal = array(); - foreach($valueArray as $nextVal) { + foreach ($valueArray as $nextVal) { - if ($valueArrayC==0) {break;} + if ($valueArrayC == 0) { + break; + } $valueArrayC--; - $newVal[]=$nextVal; + $newVal[] = $nextVal; } return $newVal; } - - - - - - - - - - - - - - - /********************************************* * * Helper functions for evaluation functions. @@ -2042,29 +2029,35 @@ * @param integer If set, the value will be unique for this PID * @return string Modified value (if not-unique). Will be the value appended with a number (until 100, then the function just breaks). */ - function getUnique($table,$field,$value,$id,$newPid=0) { + function getUnique($table, $field, $value, $id, $newPid = 0) { global $TCA; // Initialize: t3lib_div::loadTCA($table); - $whereAdd=''; + $whereAdd = ''; - $newValue=''; + $newValue = ''; - if (intval($newPid)) { $whereAdd.=' AND pid='.intval($newPid); } else { $whereAdd.=' AND pid>=0'; } // "AND pid>=0" for versioning + if (intval($newPid)) { + $whereAdd .= ' AND pid=' . intval($newPid); + } else { + $whereAdd .= ' AND pid>=0'; + } // "AND pid>=0" for versioning - $whereAdd.=$this->deleteClause($table); + $whereAdd .= $this->deleteClause($table); // If the field is configured in TCA, proceed: - if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$field])) { + if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$field])) { // Look for a record which might already have the value: - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, $field.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($value, $table).' AND uid!='.intval($id).$whereAdd); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, $field . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, $table) . ' AND uid!=' . intval($id) . $whereAdd); $counter = 0; // For as long as records with the test-value existing, try again (with incremented numbers appended). - while ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { + while ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { - $newValue = $value.$counter; + $newValue = $value . $counter; - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, $field.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($newValue, $table).' AND uid!='.intval($id).$whereAdd); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, $field . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($newValue, $table) . ' AND uid!=' . intval($id) . $whereAdd); $counter++; - if ($counter>100) { break; } // At "100" it will give up and accept a duplicate - should probably be fixed to a small hash string instead...! + if ($counter > 100) { + break; + } // At "100" it will give up and accept a duplicate - should probably be fixed to a small hash string instead...! } // If the new value is there: $value = strlen($newValue) ? $newValue : $value; @@ -2072,10 +2065,10 @@ return $value; } - function checkValue_text_Eval($value,$evalArray,$is_in) { + function checkValue_text_Eval($value, $evalArray, $is_in) { - $res = Array(); + $res = array(); $newValue = $value; - $set = true; + $set = TRUE; foreach ($evalArray as $func) { switch ($func) { @@ -2083,19 +2076,23 @@ $value = trim($value); break; case 'required': - if (!$value) {$set=0;} + if (!$value) { + $set = 0; + } break; default: - if (substr($func, 0, 3) == 'tx_') { + if (substr($func, 0, 3) == 'tx_') { - $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func].':&'.$func); + $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func); - if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) { + if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) { $value = $evalObj->evaluateFieldValue($value, $is_in, $set); } } break; } } - if ($set) {$res['value'] = $value;} + if ($set) { + $res['value'] = $value; + } return $res; } @@ -2107,13 +2104,13 @@ * @param string Is-in string for 'is_in' evaluation * @return array Modified $value in key 'value' or empty array */ - function checkValue_input_Eval($value,$evalArray,$is_in) { + function checkValue_input_Eval($value, $evalArray, $is_in) { - $res = Array(); + $res = array(); $newValue = $value; - $set = true; + $set = TRUE; - foreach($evalArray as $func) { + foreach ($evalArray as $func) { - switch($func) { + switch ($func) { case 'int': case 'year': case 'time': @@ -2123,7 +2120,7 @@ case 'date': case 'datetime': $value = intval($value); - if ($value>0 && !$this->dontProcessTransformations) { + if ($value > 0 && !$this->dontProcessTransformations) { $value -= date('Z', $value); } break; @@ -2131,7 +2128,7 @@ $value = preg_replace('/[^0-9,\.-]/', '', $value); $negative = substr($value, 0, 1) == '-'; $value = strtr($value, array(',' => '.', '-' => '')); - if (strpos($value, '.') === false) { + if (strpos($value, '.') === FALSE) { $value .= '.0'; } $valueArray = explode('.', $value); @@ -2143,7 +2140,9 @@ $value = number_format($value, 2, '.', ''); break; case 'md5': - if (strlen($value)!=32){$set=false;} + if (strlen($value) != 32) { + $set = FALSE; + } break; case 'trim': $value = trim($value); @@ -2156,48 +2155,50 @@ break; case 'required': if (!isset($value) || $value === '') { - $set = false; + $set = FALSE; } break; case 'is_in': - $c=strlen($value); + $c = strlen($value); - if ($c) { + if ($c) { $newVal = ''; - for ($a=0;$a<$c;$a++) { + for ($a = 0; $a < $c; $a++) { - $char = substr($value,$a,1); + $char = substr($value, $a, 1); - if (strpos($is_in,$char) !== false) { + if (strpos($is_in, $char) !== FALSE) { - $newVal.=$char; + $newVal .= $char; } } $value = $newVal; } break; case 'nospace': - $value = str_replace(' ','',$value); + $value = str_replace(' ', '', $value); break; case 'alpha': - $value = preg_replace('/[^a-zA-Z]/','',$value); + $value = preg_replace('/[^a-zA-Z]/', '', $value); break; case 'num': - $value = preg_replace('/[^0-9]/','',$value); + $value = preg_replace('/[^0-9]/', '', $value); break; case 'alphanum': - $value = preg_replace('/[^a-zA-Z0-9]/','',$value); + $value = preg_replace('/[^a-zA-Z0-9]/', '', $value); break; case 'alphanum_x': - $value = preg_replace('/[^a-zA-Z0-9_-]/','',$value); + $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value); break; default: - if (substr($func, 0, 3) == 'tx_') { + if (substr($func, 0, 3) == 'tx_') { - $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func].':&'.$func); + $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func); - if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) { + if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) { $value = $evalObj->evaluateFieldValue($value, $is_in, $set); } } break; } } - if ($set) {$res['value'] = $value;} + if ($set) { + $res['value'] = $value; + } return $res; } @@ -2214,24 +2215,24 @@ * @return array Modified value array */ function checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, $type, $currentTable, $currentField) { - $tables = $type=='group'?$tcaFieldConf['allowed']:$tcaFieldConf['foreign_table'].','.$tcaFieldConf['neg_foreign_table']; + $tables = $type == 'group' ? $tcaFieldConf['allowed'] : $tcaFieldConf['foreign_table'] . ',' . $tcaFieldConf['neg_foreign_table']; - $prep = $type=='group'?$tcaFieldConf['prepend_tname']:$tcaFieldConf['neg_foreign_table']; + $prep = $type == 'group' ? $tcaFieldConf['prepend_tname'] : $tcaFieldConf['neg_foreign_table']; $newRelations = implode(',', $valueArray); $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); /* @var $dbAnalysis t3lib_loadDBGroup */ - $dbAnalysis->registerNonTableValues=$tcaFieldConf['allowNonIdValues'] ? 1 : 0; + $dbAnalysis->registerNonTableValues = $tcaFieldConf['allowNonIdValues'] ? 1 : 0; $dbAnalysis->start($newRelations, $tables, '', 0, $currentTable, $tcaFieldConf); - if ($tcaFieldConf['MM']) { + if ($tcaFieldConf['MM']) { - if ($status=='update') { + if ($status == 'update') { $oldRelations_dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); /* @var $oldRelations_dbAnalysis t3lib_loadDBGroup */ - $oldRelations_dbAnalysis->registerNonTableValues=$tcaFieldConf['allowNonIdValues'] ? 1 : 0; + $oldRelations_dbAnalysis->registerNonTableValues = $tcaFieldConf['allowNonIdValues'] ? 1 : 0; // db analysis with $id will initialize with the existing relations $oldRelations_dbAnalysis->start('', $tables, $tcaFieldConf['MM'], $id, $currentTable, $tcaFieldConf); $oldRelations = implode(',', $oldRelations_dbAnalysis->getValueArray()); - $dbAnalysis->writeMM($tcaFieldConf['MM'],$id,$prep); + $dbAnalysis->writeMM($tcaFieldConf['MM'], $id, $prep); if ($oldRelations != $newRelations) { $this->mmHistoryRecords[$currentTable . ':' . $id]['oldRecord'][$currentField] = $oldRelations; $this->mmHistoryRecords[$currentTable . ':' . $id]['newRecord'][$currentField] = $newRelations; @@ -2240,13 +2241,13 @@ $this->mmHistoryRecords[$currentTable . ':' . $id]['newRecord'][$currentField] = ''; } } else { - $this->dbAnalysisStore[] = array($dbAnalysis,$tcaFieldConf['MM'],$id,$prep,$currentTable); // This will be traversed later to execute the actions + $this->dbAnalysisStore[] = array($dbAnalysis, $tcaFieldConf['MM'], $id, $prep, $currentTable); // This will be traversed later to execute the actions } $valueArray = $dbAnalysis->countItems(); } else { $valueArray = $dbAnalysis->getValueArray($prep); - if ($type=='select' && $prep) { + if ($type == 'select' && $prep) { - $valueArray = $dbAnalysis->convertPosNeg($valueArray,$tcaFieldConf['foreign_table'],$tcaFieldConf['neg_foreign_table']); + $valueArray = $dbAnalysis->convertPosNeg($valueArray, $tcaFieldConf['foreign_table'], $tcaFieldConf['neg_foreign_table']); } } @@ -2260,10 +2261,10 @@ * @param string Input string, comma separated values. For each part it will also be detected if a '|' is found and the first part will then be used if that is the case. Further the value will be rawurldecoded. * @return array The value array. */ - function checkValue_group_select_explodeSelectGroupValue($value) { + function checkValue_group_select_explodeSelectGroupValue($value) { - $valueArray = t3lib_div::trimExplode(',',$value,1); + $valueArray = t3lib_div::trimExplode(',', $value, 1); foreach ($valueArray as &$newVal) { - $temp=explode('|',$newVal,2); + $temp = explode('|', $newVal, 2); $newVal = str_replace( ',', '', @@ -2287,12 +2288,12 @@ * @return array The modified 'data' part. * @see checkValue_flex_procInData_travDS() */ - function checkValue_flex_procInData($dataPart,$dataPart_current,$uploadedFiles,$dataStructArray,$pParams,$callBackFunc='') { + function checkValue_flex_procInData($dataPart, $dataPart_current, $uploadedFiles, $dataStructArray, $pParams, $callBackFunc = '') { - if (is_array($dataPart)) { + if (is_array($dataPart)) { - foreach($dataPart as $sKey => $sheetDef) { + foreach ($dataPart as $sKey => $sheetDef) { - list ($dataStruct,$actualSheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sKey); + list ($dataStruct, $actualSheet) = t3lib_div::resolveSheetDefInDS($dataStructArray, $sKey); - if (is_array($dataStruct) && $actualSheet==$sKey && is_array($sheetDef)) { + if (is_array($dataStruct) && $actualSheet == $sKey && is_array($sheetDef)) { - foreach($sheetDef as $lKey => $lData) { + foreach ($sheetDef as $lKey => $lData) { $this->checkValue_flex_procInData_travDS( $dataPart[$sKey][$lKey], $dataPart_current[$sKey][$lKey], @@ -2300,7 +2301,7 @@ $dataStruct['ROOT']['el'], $pParams, $callBackFunc, - $sKey.'/'.$lKey.'/' + $sKey . '/' . $lKey . '/' ); } } @@ -2324,123 +2325,127 @@ * @return void * @see checkValue_flex_procInData() */ - function checkValue_flex_procInData_travDS(&$dataValues,$dataValues_current,$uploadedFiles,$DSelements,$pParams,$callBackFunc,$structurePath) { + function checkValue_flex_procInData_travDS(&$dataValues, $dataValues_current, $uploadedFiles, $DSelements, $pParams, $callBackFunc, $structurePath) { - if (is_array($DSelements)) { + if (is_array($DSelements)) { // For each DS element: - foreach($DSelements as $key => $dsConf) { + foreach ($DSelements as $key => $dsConf) { - // Array/Section: + // Array/Section: - if ($DSelements[$key]['type']=='array') { + if ($DSelements[$key]['type'] == 'array') { - if (is_array($dataValues[$key]['el'])) { + if (is_array($dataValues[$key]['el'])) { - if ($DSelements[$key]['section']) { + if ($DSelements[$key]['section']) { - $newIndexCounter=0; + $newIndexCounter = 0; - foreach($dataValues[$key]['el'] as $ik => $el) { + foreach ($dataValues[$key]['el'] as $ik => $el) { - if (is_array($el)) { + if (is_array($el)) { - if (!is_array($dataValues_current[$key]['el'])) $dataValues_current[$key]['el']=array(); + if (!is_array($dataValues_current[$key]['el'])) { + $dataValues_current[$key]['el'] = array(); + } $theKey = key($el); - if (is_array($dataValues[$key]['el'][$ik][$theKey]['el'])) { + if (is_array($dataValues[$key]['el'][$ik][$theKey]['el'])) { $this->checkValue_flex_procInData_travDS( - $dataValues[$key]['el'][$ik][$theKey]['el'], - is_array($dataValues_current[$key]['el'][$ik]) ? $dataValues_current[$key]['el'][$ik][$theKey]['el'] : array(), - $uploadedFiles[$key]['el'][$ik][$theKey]['el'], - $DSelements[$key]['el'][$theKey]['el'], - $pParams, - $callBackFunc, + $dataValues[$key]['el'][$ik][$theKey]['el'], + is_array($dataValues_current[$key]['el'][$ik]) ? $dataValues_current[$key]['el'][$ik][$theKey]['el'] : array(), + $uploadedFiles[$key]['el'][$ik][$theKey]['el'], + $DSelements[$key]['el'][$theKey]['el'], + $pParams, + $callBackFunc, - $structurePath.$key.'/el/'.$ik.'/'.$theKey.'/el/' + $structurePath . $key . '/el/' . $ik . '/' . $theKey . '/el/' - ); + ); // If element is added dynamically in the flexform of TCEforms, we map the ID-string to the next numerical index we can have in that particular section of elements: // The fact that the order changes is not important since order is controlled by a separately submitted index. - if (substr($ik,0,3)=="ID-") { + if (substr($ik, 0, 3) == "ID-") { $newIndexCounter++; - $this->newIndexMap[$ik] = (is_array($dataValues_current[$key]['el'])&&count($dataValues_current[$key]['el'])?max(array_keys($dataValues_current[$key]['el'])):0)+$newIndexCounter; // Set mapping index + $this->newIndexMap[$ik] = (is_array($dataValues_current[$key]['el']) && count($dataValues_current[$key]['el']) ? max(array_keys($dataValues_current[$key]['el'])) : 0) + $newIndexCounter; // Set mapping index - $dataValues[$key]['el'][$this->newIndexMap[$ik]] = $dataValues[$key]['el'][$ik]; // Transfer values + $dataValues[$key]['el'][$this->newIndexMap[$ik]] = $dataValues[$key]['el'][$ik]; // Transfer values - unset($dataValues[$key]['el'][$ik]); // Unset original + unset($dataValues[$key]['el'][$ik]); // Unset original } } } } } else { - if (!isset($dataValues[$key]['el'])) $dataValues[$key]['el']=array(); + if (!isset($dataValues[$key]['el'])) { + $dataValues[$key]['el'] = array(); + } $this->checkValue_flex_procInData_travDS( - $dataValues[$key]['el'], - $dataValues_current[$key]['el'], - $uploadedFiles[$key]['el'], - $DSelements[$key]['el'], - $pParams, - $callBackFunc, + $dataValues[$key]['el'], + $dataValues_current[$key]['el'], + $uploadedFiles[$key]['el'], + $DSelements[$key]['el'], + $pParams, + $callBackFunc, - $structurePath.$key.'/el/' + $structurePath . $key . '/el/' - ); + ); } } } else { - if (is_array($dsConf['TCEforms']['config']) && is_array($dataValues[$key])) { + if (is_array($dsConf['TCEforms']['config']) && is_array($dataValues[$key])) { - foreach($dataValues[$key] as $vKey => $data) { + foreach ($dataValues[$key] as $vKey => $data) { - if ($callBackFunc) { + if ($callBackFunc) { - if (is_object($this->callBackObj)) { + if (is_object($this->callBackObj)) { $res = $this->callBackObj->$callBackFunc( - $pParams, - $dsConf['TCEforms']['config'], - $dataValues[$key][$vKey], - $dataValues_current[$key][$vKey], - $uploadedFiles[$key][$vKey], + $pParams, + $dsConf['TCEforms']['config'], + $dataValues[$key][$vKey], + $dataValues_current[$key][$vKey], + $uploadedFiles[$key][$vKey], - $structurePath.$key.'/'.$vKey.'/' + $structurePath . $key . '/' . $vKey . '/' - ); + ); } else { $res = $this->$callBackFunc( - $pParams, - $dsConf['TCEforms']['config'], - $dataValues[$key][$vKey], - $dataValues_current[$key][$vKey], - $uploadedFiles[$key][$vKey], + $pParams, + $dsConf['TCEforms']['config'], + $dataValues[$key][$vKey], + $dataValues_current[$key][$vKey], + $uploadedFiles[$key][$vKey], - $structurePath.$key.'/'.$vKey.'/' + $structurePath . $key . '/' . $vKey . '/' - ); + ); } - } else { // Default + } else { // Default - list($CVtable,$CVid,$CVcurValue,$CVstatus,$CVrealPid,$CVrecFID,$CVtscPID) = $pParams; + list($CVtable, $CVid, $CVcurValue, $CVstatus, $CVrealPid, $CVrecFID, $CVtscPID) = $pParams; $res = $this->checkValue_SW( - array(), - $dataValues[$key][$vKey], - $dsConf['TCEforms']['config'], - $CVtable, - $CVid, - $dataValues_current[$key][$vKey], - $CVstatus, - $CVrealPid, - $CVrecFID, - '', - $uploadedFiles[$key][$vKey], - array(), - $CVtscPID - ); + array(), + $dataValues[$key][$vKey], + $dsConf['TCEforms']['config'], + $CVtable, + $CVid, + $dataValues_current[$key][$vKey], + $CVstatus, + $CVrealPid, + $CVrecFID, + '', + $uploadedFiles[$key][$vKey], + array(), + $CVtscPID + ); // Look for RTE transformation of field: - if ($dataValues[$key]['_TRANSFORM_'.$vKey] == 'RTE' && !$this->dontProcessTransformations) { + if ($dataValues[$key]['_TRANSFORM_' . $vKey] == 'RTE' && !$this->dontProcessTransformations) { // Unsetting trigger field - we absolutely don't want that into the data storage! - unset($dataValues[$key]['_TRANSFORM_'.$vKey]); + unset($dataValues[$key]['_TRANSFORM_' . $vKey]); - if (isset($res['value'])) { + if (isset($res['value'])) { // Calculating/Retrieving some values here: - list(,,$recFieldName) = explode(':', $CVrecFID); + list(, , $recFieldName) = explode(':', $CVrecFID); - $theTypeString = t3lib_BEfunc::getTCAtypeValue($CVtable,$this->checkValue_currentRecord); + $theTypeString = t3lib_BEfunc::getTCAtypeValue($CVtable, $this->checkValue_currentRecord); - $specConf = t3lib_BEfunc::getSpecConfParts('',$dsConf['TCEforms']['defaultExtras']); + $specConf = t3lib_BEfunc::getSpecConfParts('', $dsConf['TCEforms']['defaultExtras']); // Find, thisConfig: - $RTEsetup = $this->BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($CVtscPID)); + $RTEsetup = $this->BE_USER->getTSConfig('RTE', t3lib_BEfunc::getPagesTSconfig($CVtscPID)); - $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$CVtable,$recFieldName,$theTypeString); + $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'], $CVtable, $recFieldName, $theTypeString); // Get RTE object, draw form and set flag: $RTEobj = t3lib_BEfunc::RTEgetObj(); - if (is_object($RTEobj)) { + if (is_object($RTEobj)) { - $res['value'] = $RTEobj->transformContent('db',$res['value'],$CVtable,$recFieldName,$this->checkValue_currentRecord,$specConf,$thisConfig,'',$CVrealPid); + $res['value'] = $RTEobj->transformContent('db', $res['value'], $CVtable, $recFieldName, $this->checkValue_currentRecord, $specConf, $thisConfig, '', $CVrealPid); } else { debug('NO RTE OBJECT FOUND!'); } @@ -2449,24 +2454,24 @@ } // Adding the value: - if (isset($res['value'])) { + if (isset($res['value'])) { $dataValues[$key][$vKey] = $res['value']; } // Finally, check if new and old values are different (or no .vDEFbase value is found) and if so, we record the vDEF value for diff'ing. // We do this after $dataValues has been updated since I expect that $dataValues_current holds evaluated values from database (so this must be the right value to compare with). - if (substr($vKey,-9)!='.vDEFbase') { + if (substr($vKey, -9) != '.vDEFbase') { - if ($this->clear_flexFormData_vDEFbase) { + if ($this->clear_flexFormData_vDEFbase) { - $dataValues[$key][$vKey.'.vDEFbase'] = ''; + $dataValues[$key][$vKey . '.vDEFbase'] = ''; - } elseif ($this->updateModeL10NdiffData && $GLOBALS['TYPO3_CONF_VARS']['BE']['flexFormXMLincludeDiffBase'] && $vKey!=='vDEF' && (strcmp($dataValues[$key][$vKey],$dataValues_current[$key][$vKey]) || !isset($dataValues_current[$key][$vKey.'.vDEFbase']) || $this->updateModeL10NdiffData==='FORCE_FFUPD')) { + } elseif ($this->updateModeL10NdiffData && $GLOBALS['TYPO3_CONF_VARS']['BE']['flexFormXMLincludeDiffBase'] && $vKey !== 'vDEF' && (strcmp($dataValues[$key][$vKey], $dataValues_current[$key][$vKey]) || !isset($dataValues_current[$key][$vKey . '.vDEFbase']) || $this->updateModeL10NdiffData === 'FORCE_FFUPD')) { // Now, check if a vDEF value is submitted in the input data, if so we expect this has been processed prior to this operation (normally the case since those fields are higher in the form) and we can use that: - if (isset($dataValues[$key]['vDEF'])) { + if (isset($dataValues[$key]['vDEF'])) { $diffValue = $dataValues[$key]['vDEF']; - } else { // If not found (for translators with no access to the default language) we use the one from the current-value data set: + } else { // If not found (for translators with no access to the default language) we use the one from the current-value data set: $diffValue = $dataValues_current[$key]['vDEF']; } // Setting the reference value for vDEF for this translation. This will be used for translation tools to make a diff between the vDEF and vDEFbase to see if an update would be fitting. - $dataValues[$key][$vKey.'.vDEFbase'] = $this->updateModeL10NdiffDataClear ? '' : $diffValue; + $dataValues[$key][$vKey . '.vDEFbase'] = $this->updateModeL10NdiffDataClear ? '' : $diffValue; } } } @@ -2487,7 +2492,7 @@ * @param string The current field the values are modified for * @return string Modified values */ - protected function checkValue_inline_processDBdata($valueArray, $tcaFieldConf, $id, $status, $table, $field) { + protected function checkValue_inline_processDBdata($valueArray, $tcaFieldConf, $id, $status, $table, $field) { $newValue = ''; $foreignTable = $tcaFieldConf['foreign_table']; @@ -2499,63 +2504,52 @@ $dbAnalysis->start(implode(',', $valueArray), $foreignTable, '', 0, $table, $tcaFieldConf); // If the localizationMode is set to 'keep', the children for the localized parent are kept as in the original untranslated record: $localizationMode = t3lib_BEfunc::getInlineLocalizationMode($table, $tcaFieldConf); - if ($localizationMode=='keep' && $status=='update') { + if ($localizationMode == 'keep' && $status == 'update') { // Fetch the current record and determine the original record: $row = t3lib_BEfunc::getRecordWSOL($table, $id); if (is_array($row)) { $language = intval($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]); $transOrigPointer = intval($row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']]); // If language is set (e.g. 1) and also transOrigPointer (e.g. 123), use transOrigPointer as uid: - if ($language>0 && $transOrigPointer) { + if ($language > 0 && $transOrigPointer) { $id = $transOrigPointer; // If we're in active localizationMode 'keep', prevent from writing data to the field of the parent record: // (on removing the localized parent, the original (untranslated) children would then also be removed) - $keepTranslation = true; + $keepTranslation = TRUE; } } } // IRRE with a pointer field (database normalization): if ($tcaFieldConf['foreign_field']) { // if the record was imported, sorting was also imported, so skip this - $skipSorting = ($this->callFromImpExp ? true : false); + $skipSorting = ($this->callFromImpExp ? TRUE : FALSE); // update record in intermediate table (sorting & pointer uid to parent record) $dbAnalysis->writeForeignField($tcaFieldConf, $id, 0, $skipSorting); - $newValue = ($keepTranslation ? 0 : $dbAnalysis->countItems(false)); + $newValue = ($keepTranslation ? 0 : $dbAnalysis->countItems(FALSE)); - // IRRE with MM relation: + // IRRE with MM relation: - } else if ($this->getInlineFieldType($tcaFieldConf) == 'mm') { + } else { + if ($this->getInlineFieldType($tcaFieldConf) == 'mm') { - // in order to fully support all the MM stuff, directly call checkValue_group_select_processDBdata instead of repeating the needed code here - $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field); - $newValue = ($keepTranslation ? 0 : $valueArray[0]); - // IRRE with comma separated values: - } else { - $valueArray = $dbAnalysis->getValueArray(); - // Checking that the number of items is correct: - $valueArray = $this->checkValue_checkMax($tcaFieldConf, $valueArray); - // If a valid translation of the 'keep' mode is active, update relations in the original(!) record: - if ($keepTranslation) { - $this->updateDB($table, $transOrigPointer, array($field => implode(',', $valueArray))); - } else { - $newValue = implode(',', $valueArray); - } - } + // in order to fully support all the MM stuff, directly call checkValue_group_select_processDBdata instead of repeating the needed code here + $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field); + $newValue = ($keepTranslation ? 0 : $valueArray[0]); + // IRRE with comma separated values: + } else { + $valueArray = $dbAnalysis->getValueArray(); + // Checking that the number of items is correct: + $valueArray = $this->checkValue_checkMax($tcaFieldConf, $valueArray); + // If a valid translation of the 'keep' mode is active, update relations in the original(!) record: + if ($keepTranslation) { + $this->updateDB($table, $transOrigPointer, array($field => implode(',', $valueArray))); + } else { + $newValue = implode(',', $valueArray); + } + } + } return $newValue; } - - - - - - - - - - - - - /********************************************* * * PROCESSING COMMANDS @@ -2572,14 +2566,14 @@ global $TCA, $TYPO3_CONF_VARS; // Editing frozen: - if ($this->BE_USER->workspace!==0 && $this->BE_USER->workspaceRec['freeze']) { + if ($this->BE_USER->workspace !== 0 && $this->BE_USER->workspaceRec['freeze']) { - $this->newlog('All editing in this workspace has been frozen!',1); + $this->newlog('All editing in this workspace has been frozen!', 1); return FALSE; } // Hook initialization: $hookObjectsArr = array(); - if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'])) { + if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'])) { foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'] as $classRef) { $hookObj = t3lib_div::getUserObj($classRef); if (method_exists($hookObj, 'processCmdmap_beforeStart')) { @@ -2594,17 +2588,17 @@ // Check if the table may be modified! $modifyAccessList = $this->checkModifyAccessList($table); - if (!$modifyAccessList) { + if (!$modifyAccessList) { $id = 0; - $this->log($table,$id,2,0,1,"Attempt to modify table '%s' without permission",1,array($table)); + $this->log($table, $id, 2, 0, 1, "Attempt to modify table '%s' without permission", 1, array($table)); - } // FIXME: $id not set here (Comment added by Sebastian Kurfürst) + } // FIXME: $id not set here (Comment added by Sebastian Kurfürst) // Check basic permissions and circumstances: - if (isset($TCA[$table]) && !$this->tableReadOnly($table) && is_array($this->cmdmap[$table]) && $modifyAccessList) { + if (isset($TCA[$table]) && !$this->tableReadOnly($table) && is_array($this->cmdmap[$table]) && $modifyAccessList) { // Traverse the command map: - foreach($this->cmdmap[$table] as $id => $incomingCmdArray) { + foreach ($this->cmdmap[$table] as $id => $incomingCmdArray) { - if (is_array($incomingCmdArray)) { // have found a command. + if (is_array($incomingCmdArray)) { // have found a command. // Get command and value (notice, only one command is observed at a time!): reset($incomingCmdArray); @@ -2630,22 +2624,22 @@ } } - // only execute default commands if a hook hasn't been processed the command already + // only execute default commands if a hook hasn't been processed the command already if (!$commandIsProcessed) { // Branch, based on command switch ($command) { case 'move': - $this->moveRecord($table,$id,$value); + $this->moveRecord($table, $id, $value); break; case 'copy': - if ($table === 'pages') { + if ($table === 'pages') { - $this->copyPages($id,$value); + $this->copyPages($id, $value); } else { - $this->copyRecord($table,$id,$value,1); + $this->copyRecord($table, $id, $value, 1); } break; case 'localize': - $this->localize($table,$id,$value); + $this->localize($table, $id, $value); break; case 'inlineLocalizeSynchronize': $this->inlineLocalizeSynchronize($table, $id, $value); @@ -2686,15 +2680,6 @@ } - - - - - - - - - /********************************************* * * Cmd: Copying @@ -2713,38 +2698,38 @@ * @param integer Language ID (from sys_language table) * @return integer ID of new record, if any */ - function copyRecord($table, $uid, $destPid, $first=0, $overrideValues=array(), $excludeFields='', $language=0) { + function copyRecord($table, $uid, $destPid, $first = 0, $overrideValues = array(), $excludeFields = '', $language = 0) { global $TCA; $uid = $origUid = intval($uid); // Only copy if the table is defined in TCA, a uid is given and the record wasn't copied before: - if ($TCA[$table] && $uid && !$this->isRecordCopied($table, $uid)) { + if ($TCA[$table] && $uid && !$this->isRecordCopied($table, $uid)) { t3lib_div::loadTCA($table); -/* - // In case the record to be moved turns out to be an offline version, we have to find the live version and work on that one (this case happens for pages with "branch" versioning type) - if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table,$uid,'uid')) { - $uid = $lookForLiveVersion['uid']; - } - // Get workspace version of the source record, if any: Then we will copy workspace version instead: - if ($WSversion = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, $table, $uid, 'uid,t3ver_oid')) { - $uid = $WSversion['uid']; - } - // Now, the $uid is the actual record we will copy while $origUid is the record we asked to get copied - but that could be a live version. -*/ + /* + // In case the record to be moved turns out to be an offline version, we have to find the live version and work on that one (this case happens for pages with "branch" versioning type) + if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table,$uid,'uid')) { + $uid = $lookForLiveVersion['uid']; + } + // Get workspace version of the source record, if any: Then we will copy workspace version instead: + if ($WSversion = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, $table, $uid, 'uid,t3ver_oid')) { + $uid = $WSversion['uid']; + } + // Now, the $uid is the actual record we will copy while $origUid is the record we asked to get copied - but that could be a live version. + */ - if ($this->doesRecordExist($table,$uid,'show')) { // This checks if the record can be selected which is all that a copy action requires. + if ($this->doesRecordExist($table, $uid, 'show')) { // This checks if the record can be selected which is all that a copy action requires. $fullLanguageCheckNeeded = ($table != 'pages'); - if (($language > 0 && $this->BE_USER->checkLanguageAccess($language) ) || + if (($language > 0 && $this->BE_USER->checkLanguageAccess($language)) || - $this->BE_USER->recordEditAccessInternals( + $this->BE_USER->recordEditAccessInternals( - $table, $uid, false, false, $fullLanguageCheckNeeded + $table, $uid, FALSE, FALSE, $fullLanguageCheckNeeded - ) - ) { //Used to check language and general editing rights + ) + ) { //Used to check language and general editing rights - $data = Array(); + $data = array(); - $nonFields = array_unique(t3lib_div::trimExplode(',','uid,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,t3ver_oid,t3ver_wsid,t3ver_id,t3ver_label,t3ver_state,t3ver_swapmode,t3ver_count,t3ver_stage,t3ver_tstamp,'.$excludeFields,1)); + $nonFields = array_unique(t3lib_div::trimExplode(',', 'uid,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,t3ver_oid,t3ver_wsid,t3ver_id,t3ver_label,t3ver_state,t3ver_swapmode,t3ver_count,t3ver_stage,t3ver_tstamp,' . $excludeFields, 1)); - // $row = $this->recordInfo($table,$uid,'*'); + // $row = $this->recordInfo($table,$uid,'*'); - $row = t3lib_BEfunc::getRecordWSOL($table,$uid); // So it copies (and localized) content from workspace... + $row = t3lib_BEfunc::getRecordWSOL($table, $uid); // So it copies (and localized) content from workspace... - if (is_array($row)) { + if (is_array($row)) { // Initializing: $theNewID = uniqid('NEW'); @@ -2755,28 +2740,28 @@ $defaultData = $this->newFieldArray($table); // Getting "copy-after" fields if applicable: - $copyAfterFields = $destPid<0 ? $this->fixCopyAfterDuplFields($table,$uid,abs($destPid),0) : array(); + $copyAfterFields = $destPid < 0 ? $this->fixCopyAfterDuplFields($table, $uid, abs($destPid), 0) : array(); // Page TSconfig related: - $tscPID = t3lib_BEfunc::getTSconfig_pidValue($table,$uid,$destPid); // NOT using t3lib_BEfunc::getTSCpid() because we need the real pid - not the ID of a page, if the input is a page... + $tscPID = t3lib_BEfunc::getTSconfig_pidValue($table, $uid, $destPid); // NOT using t3lib_BEfunc::getTSCpid() because we need the real pid - not the ID of a page, if the input is a page... $TSConfig = $this->getTCEMAIN_TSconfig($tscPID); - $tE = $this->getTableEntries($table,$TSConfig); + $tE = $this->getTableEntries($table, $TSConfig); // Traverse ALL fields of the selected record: - foreach($row as $field => $value) { + foreach ($row as $field => $value) { - if (!in_array($field,$nonFields)) { + if (!in_array($field, $nonFields)) { // Get TCA configuration for the field: $conf = $TCA[$table]['columns'][$field]['config']; // Preparation/Processing of the value: - if ($field=='pid') { // "pid" is hardcoded of course: + if ($field == 'pid') { // "pid" is hardcoded of course: $value = $destPid; - } elseif (isset($overrideValues[$field])) { // Override value... + } elseif (isset($overrideValues[$field])) { // Override value... $value = $overrideValues[$field]; - } elseif (isset($copyAfterFields[$field])) { // Copy-after value if available: + } elseif (isset($copyAfterFields[$field])) { // Copy-after value if available: $value = $copyAfterFields[$field]; - } elseif ($TCA[$table]['ctrl']['setToDefaultOnCopy'] && t3lib_div::inList($TCA[$table]['ctrl']['setToDefaultOnCopy'],$field)) { // Revert to default for some fields: + } elseif ($TCA[$table]['ctrl']['setToDefaultOnCopy'] && t3lib_div::inList($TCA[$table]['ctrl']['setToDefaultOnCopy'], $field)) { // Revert to default for some fields: $value = $defaultData[$field]; } else { // Hide at copy may override: @@ -2785,7 +2770,7 @@ } // Prepend label on copy: if ($first && $field == $headerField && $TCA[$table]['ctrl']['prependAtCopy'] && !$tE['disablePrependAtCopy']) { - $value = $this->getCopyHeader($table,$this->resolvePid($table,$destPid),$field,$this->clearPrefixFromValue($table,$value),0); + $value = $this->getCopyHeader($table, $this->resolvePid($table, $destPid), $field, $this->clearPrefixFromValue($table, $value), 0); } // Processing based on the TCA config field type (files, references, flexforms...) $value = $this->copyRecord_procBasedOnFieldType($table, $uid, $field, $value, $row, $conf, $tscPID, $language); @@ -2810,10 +2795,10 @@ /* @var $copyTCE t3lib_TCEmain */ $copyTCE->stripslashes_values = 0; $copyTCE->copyTree = $this->copyTree; - $copyTCE->cachedTSconfig = $this->cachedTSconfig; // Copy forth the cached TSconfig + $copyTCE->cachedTSconfig = $this->cachedTSconfig; // Copy forth the cached TSconfig - $copyTCE->dontProcessTransformations=1; // Transformations should NOT be carried out during copy + $copyTCE->dontProcessTransformations = 1; // Transformations should NOT be carried out during copy - $copyTCE->start($data,'',$this->BE_USER); + $copyTCE->start($data, '', $this->BE_USER); $copyTCE->process_datamap(); // Getting the new UID: @@ -2832,18 +2817,24 @@ $this->errorLog = array_merge($this->errorLog, $copyTCE->errorLog); unset($copyTCE); - if($language == 0) { + if ($language == 0) { //repointing the new translation records to the parent record we just created $overrideValues[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] = $theNewSQLID; - $this->copyL10nOverlayRecords($table, $uid, $destPid<0 ? $tscPID : $destPid , $first, $overrideValues, $excludeFields); + $this->copyL10nOverlayRecords($table, $uid, $destPid < 0 ? $tscPID : $destPid, $first, $overrideValues, $excludeFields); } return $theNewSQLID; - } else $this->log($table,$uid,3,0,1,'Attempt to copy record that did not exist!'); - } else $this->log($table,$uid,3,0,1,'Attempt to copy record without having permissions to do so. ['.$this->BE_USER->errorMsg.'].'); - } else $this->log($table,$uid,3,0,1,'Attempt to copy record without permission'); + } else { + $this->log($table, $uid, 3, 0, 1, 'Attempt to copy record that did not exist!'); - } + } + } else { + $this->log($table, $uid, 3, 0, 1, 'Attempt to copy record without having permissions to do so. [' . $this->BE_USER->errorMsg . '].'); - } + } + } else { + $this->log($table, $uid, 3, 0, 1, 'Attempt to copy record without permission'); + } + } + } /** * Copying pages @@ -2853,17 +2844,17 @@ * @param integer Destination PID: >=0 then it points to a page-id on which to insert the record (as the first element). <0 then it points to a uid from its own table after which to insert it (works if * @return void */ - function copyPages($uid,$destPid) { + function copyPages($uid, $destPid) { // Initialize: $uid = intval($uid); $destPid = intval($destPid); // Finding list of tables to copy. - $copyTablesArray = $this->admin ? $this->compileAdminTables() : explode(',',$this->BE_USER->groupData['tables_modify']); // These are the tables, the user may modify + $copyTablesArray = $this->admin ? $this->compileAdminTables() : explode(',', $this->BE_USER->groupData['tables_modify']); // These are the tables, the user may modify - if (!strstr($this->copyWhichTables,'*')) { // If not all tables are allowed then make a list of allowed tables: That is the tables that figure in both allowed tables AND the copyTable-list + if (!strstr($this->copyWhichTables, '*')) { // If not all tables are allowed then make a list of allowed tables: That is the tables that figure in both allowed tables AND the copyTable-list - foreach($copyTablesArray as $k => $table) { + foreach ($copyTablesArray as $k => $table) { - if (!$table || !t3lib_div::inList($this->copyWhichTables.',pages',$table)) { // pages are always going... + if (!$table || !t3lib_div::inList($this->copyWhichTables . ',pages', $table)) { // pages are always going... unset($copyTablesArray[$k]); } } @@ -2871,30 +2862,30 @@ $copyTablesArray = array_unique($copyTablesArray); // Begin to copy pages if we're allowed to: - if ($this->admin || in_array('pages',$copyTablesArray)) { + if ($this->admin || in_array('pages', $copyTablesArray)) { // Copy this page we're on. And set first-flag (this will trigger that the record is hidden if that is configured)! - $theNewRootID = $this->copySpecificPage($uid,$destPid,$copyTablesArray,1); + $theNewRootID = $this->copySpecificPage($uid, $destPid, $copyTablesArray, 1); // If we're going to copy recursively...: - if ($theNewRootID && $this->copyTree) { + if ($theNewRootID && $this->copyTree) { // Get ALL subpages to copy (read-permissions are respected!): - $CPtable = $this->int_pageTreeInfo(Array(), $uid, intval($this->copyTree), $theNewRootID); + $CPtable = $this->int_pageTreeInfo(array(), $uid, intval($this->copyTree), $theNewRootID); // Now copying the subpages: - foreach($CPtable as $thePageUid => $thePagePid) { + foreach ($CPtable as $thePageUid => $thePagePid) { $newPid = $this->copyMappingArray['pages'][$thePagePid]; - if (isset($newPid)) { + if (isset($newPid)) { - $this->copySpecificPage($thePageUid,$newPid,$copyTablesArray); + $this->copySpecificPage($thePageUid, $newPid, $copyTablesArray); } else { - $this->log('pages',$uid,5,0,1,'Something went wrong during copying branch'); + $this->log('pages', $uid, 5, 0, 1, 'Something went wrong during copying branch'); break; } } - } // else the page was not copied. Too bad... + } // else the page was not copied. Too bad... } else { - $this->log('pages',$uid,5,0,1,'Attempt to copy page without permission to this table'); + $this->log('pages', $uid, 5, 0, 1, 'Attempt to copy page without permission to this table'); } } @@ -2907,19 +2898,19 @@ * @param boolean $first is a flag set, if the record copied is NOT a 'slave' to another record copied. That is, if this record was asked to be copied in the cmd-array * @return integer The id of the new page, if applicable. */ - function copySpecificPage($uid,$destPid,$copyTablesArray,$first=0) { + function copySpecificPage($uid, $destPid, $copyTablesArray, $first = 0) { global $TCA; // Copy the page itself: - $theNewRootID = $this->copyRecord('pages',$uid,$destPid,$first); + $theNewRootID = $this->copyRecord('pages', $uid, $destPid, $first); // If a new page was created upon the copy operation we will proceed with all the tables ON that page: - if ($theNewRootID) { + if ($theNewRootID) { - foreach($copyTablesArray as $table) { + foreach ($copyTablesArray as $table) { - if ($table && is_array($TCA[$table]) && $table!='pages') { // all records under the page is copied. + if ($table && is_array($TCA[$table]) && $table != 'pages') { // all records under the page is copied. - $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid='.intval($uid).$this->deleteClause($table), '', ($TCA[$table]['ctrl']['sortby'] ? $TCA[$table]['ctrl']['sortby'].' DESC' : '')); + $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid=' . intval($uid) . $this->deleteClause($table), '', ($TCA[$table]['ctrl']['sortby'] ? $TCA[$table]['ctrl']['sortby'] . ' DESC' : '')); - while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) { + while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) { - $this->copyRecord($table,$row['uid'], $theNewRootID); // Copying each of the underlying records... + $this->copyRecord($table, $row['uid'], $theNewRootID); // Copying each of the underlying records... } $GLOBALS['TYPO3_DB']->sql_free_result($mres); } @@ -2942,34 +2933,34 @@ * @param array Override array - must NOT contain any fields not in the table! * @return integer Returns the new ID of the record (if applicable) */ - function copyRecord_raw($table,$uid,$pid,$overrideArray=array()) { + function copyRecord_raw($table, $uid, $pid, $overrideArray = array()) { global $TCA; $uid = intval($uid); // Only copy if the table is defined in TCA, a uid is given and the record wasn't copied before: - if ($TCA[$table] && $uid && !$this->isRecordCopied($table, $uid)) { + if ($TCA[$table] && $uid && !$this->isRecordCopied($table, $uid)) { t3lib_div::loadTCA($table); - if ($this->doesRecordExist($table,$uid,'show')) { + if ($this->doesRecordExist($table, $uid, 'show')) { // Set up fields which should not be processed. They are still written - just passed through no-questions-asked! - $nonFields = array('uid','pid','t3ver_id','t3ver_oid','t3ver_wsid','t3ver_label','t3ver_state','t3ver_swapmode','t3ver_count','t3ver_stage','t3ver_tstamp','perms_userid','perms_groupid','perms_user','perms_group','perms_everybody'); + $nonFields = array('uid', 'pid', 't3ver_id', 't3ver_oid', 't3ver_wsid', 't3ver_label', 't3ver_state', 't3ver_swapmode', 't3ver_count', 't3ver_stage', 't3ver_tstamp', 'perms_userid', 'perms_groupid', 'perms_user', 'perms_group', 'perms_everybody'); // Select main record: - $row = $this->recordInfo($table,$uid,'*'); + $row = $this->recordInfo($table, $uid, '*'); - if (is_array($row)) { + if (is_array($row)) { // Merge in override array. - $row = array_merge($row,$overrideArray); + $row = array_merge($row, $overrideArray); // Traverse ALL fields of the selected record: - foreach($row as $field => $value) { + foreach ($row as $field => $value) { - if (!in_array($field,$nonFields)) { + if (!in_array($field, $nonFields)) { // Get TCA configuration for the field: $conf = $TCA[$table]['columns'][$field]['config']; - if (is_array($conf)) { + if (is_array($conf)) { // Processing based on the TCA config field type (files, references, flexforms...) - $value = $this->copyRecord_procBasedOnFieldType($table,$uid,$field,$value,$row,$conf,$pid); + $value = $this->copyRecord_procBasedOnFieldType($table, $uid, $field, $value, $row, $conf, $pid); } // Add value to array. @@ -2981,22 +2972,26 @@ $row['pid'] = $pid; // Setting original UID: - if ($TCA[$table]['ctrl']['origUid']) { + if ($TCA[$table]['ctrl']['origUid']) { $row[$TCA[$table]['ctrl']['origUid']] = $uid; } // Do the copy by internal function - $theNewSQLID = $this->insertNewCopyVersion($table,$row,$pid); + $theNewSQLID = $this->insertNewCopyVersion($table, $row, $pid); - if ($theNewSQLID) { + if ($theNewSQLID) { $this->dbAnalysisStoreExec(); $this->dbAnalysisStore = array(); - $this->copyRecord_fixRTEmagicImages($table,t3lib_BEfunc::wsMapId($table,$theNewSQLID)); + $this->copyRecord_fixRTEmagicImages($table, t3lib_BEfunc::wsMapId($table, $theNewSQLID)); return $this->copyMappingArray[$table][$uid] = $theNewSQLID; } - } else $this->log($table,$uid,3,0,1,'Attempt to rawcopy/versionize record that did not exist!'); - } else $this->log($table,$uid,3,0,1,'Attempt to rawcopy/versionize record without copy permission'); + } else { + $this->log($table, $uid, 3, 0, 1, 'Attempt to rawcopy/versionize record that did not exist!'); - } + } + } else { + $this->log($table, $uid, 3, 0, 1, 'Attempt to rawcopy/versionize record without copy permission'); - } + } + } + } /** * Inserts a record in the database, passing TCA configuration values through checkValue() but otherwise does NOTHING and checks nothing regarding permissions. @@ -3007,7 +3002,7 @@ * @param integer The value of PID field. -1 is indication that we are creating a new version! * @return integer Returns the new ID of the record (if applicable) */ - function insertNewCopyVersion($table,$fieldArray,$realPid) { + function insertNewCopyVersion($table, $fieldArray, $realPid) { global $TCA; $id = uniqid('NEW'); @@ -3021,29 +3016,29 @@ $this->dontProcessTransformations = TRUE; // Traverse record and input-process each value: - foreach($fieldArray as $field => $fieldValue) { + foreach ($fieldArray as $field => $fieldValue) { - if (isset($TCA[$table]['columns'][$field])) { + if (isset($TCA[$table]['columns'][$field])) { - // Evaluating the value. + // Evaluating the value. - $res = $this->checkValue($table,$field,$fieldValue,$id,'new',$realPid,0); + $res = $this->checkValue($table, $field, $fieldValue, $id, 'new', $realPid, 0); - if (isset($res['value'])) { + if (isset($res['value'])) { $fieldArray[$field] = $res['value']; } } } // System fields being set: - if ($TCA[$table]['ctrl']['crdate']) { + if ($TCA[$table]['ctrl']['crdate']) { $fieldArray[$TCA[$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME']; } - if ($TCA[$table]['ctrl']['cruser_id']) { + if ($TCA[$table]['ctrl']['cruser_id']) { - $fieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid; + $fieldArray[$TCA[$table]['ctrl']['cruser_id']] = $this->userid; } - if ($TCA[$table]['ctrl']['tstamp']) { + if ($TCA[$table]['ctrl']['tstamp']) { $fieldArray[$TCA[$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME']; } // Finally, insert record: - $this->insertDB($table,$id,$fieldArray, TRUE); + $this->insertDB($table, $id, $fieldArray, TRUE); // Process the remap stack in case we dealed with relations: $this->processRemapStack(); @@ -3069,7 +3064,7 @@ * @access private * @see copyRecord() */ - function copyRecord_procBasedOnFieldType($table, $uid, $field, $value, $row, $conf, $realDestPid, $language=0) { + function copyRecord_procBasedOnFieldType($table, $uid, $field, $value, $row, $conf, $realDestPid, $language = 0) { global $TCA; // Process references and files, currently that means only the files, prepending absolute paths (so the TCEmain engine will detect the file as new and one that should be made into a copy) @@ -3077,11 +3072,11 @@ $inlineSubType = $this->getInlineFieldType($conf); // Register if there are references to take care of or MM is used on an inline field (no change to value): - if ($this->isReferenceField($conf) || $inlineSubType == 'mm') { + if ($this->isReferenceField($conf) || $inlineSubType == 'mm') { - $allowedTables = $conf['type']=='group' ? $conf['allowed'] : $conf['foreign_table'].','.$conf['neg_foreign_table']; + $allowedTables = $conf['type'] == 'group' ? $conf['allowed'] : $conf['foreign_table'] . ',' . $conf['neg_foreign_table']; - $prependName = $conf['type']=='group' ? $conf['prepend_tname'] : $conf['neg_foreign_table']; + $prependName = $conf['type'] == 'group' ? $conf['prepend_tname'] : $conf['neg_foreign_table']; $localizeReferences = (isset($conf['foreign_table']) && t3lib_BEfunc::isTableLocalizable($conf['foreign_table']) && isset($conf['localizeReferencesAtParentLocalization']) && $conf['localizeReferencesAtParentLocalization']); - if ($conf['MM'] || $language>0 && $localizeReferences) { + if ($conf['MM'] || $language > 0 && $localizeReferences) { $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); /* @var $dbAnalysis t3lib_loadDBGroup */ $dbAnalysis->start($value, $allowedTables, $conf['MM'], $uid, $table, $conf); @@ -3097,19 +3092,19 @@ } } } - $value = implode(',',$dbAnalysis->getValueArray($prependName)); + $value = implode(',', $dbAnalysis->getValueArray($prependName)); } - if ($value) { // Setting the value in this array will notify the remapListedDBRecords() function that this field MAY need references to be corrected + if ($value) { // Setting the value in this array will notify the remapListedDBRecords() function that this field MAY need references to be corrected $this->registerDBList[$table][$uid][$field] = $value; } // If another inline subtype is used (comma-separated-values or the foreign_field property): - } elseif ($inlineSubType !== false) { + } elseif ($inlineSubType !== FALSE) { // Get the localization mode for the current (parent) record (keep|select|all): $localizationMode = t3lib_BEfunc::getInlineLocalizationMode($table, $field); // Localization in mode 'keep', isn't a real localization, but keeps the children of the original parent record: - if ($language>0 && $localizationMode=='keep') { + if ($language > 0 && $localizationMode == 'keep') { - $value = ($inlineSubType=='field' ? 0 : ''); + $value = ($inlineSubType == 'field' ? 0 : ''); // Execute copy or localization actions: } else { /* @@ -3124,10 +3119,10 @@ // If language is set and differs from original record, this isn't a copy action but a localization of our parent/ancestor: if ($language > 0 && t3lib_BEfunc::isTableLocalizable($table) && $language != $row[$TCA[$table]['ctrl']['languageField']]) { // If children should be localized when the parent gets localized the first time, just do it: - if ($localizationMode!=false && isset($conf['behaviour']['localizeChildrenAtParentLocalization']) && $conf['behaviour']['localizeChildrenAtParentLocalization']) { + if ($localizationMode != FALSE && isset($conf['behaviour']['localizeChildrenAtParentLocalization']) && $conf['behaviour']['localizeChildrenAtParentLocalization']) { $newId = $this->localize($v['table'], $v['id'], $language); } - // If no language it set, this is a regular copy action: + // If no language it set, this is a regular copy action: } else { if (!t3lib_div::testInt($realDestPid)) { $newId = $this->copyRecord($v['table'], $v['id'], -$v['id']); @@ -3159,29 +3154,29 @@ } // Store the new values, we will set up the uids for the subtype later on (exception keep localization from original record): - $value = implode(',',$dbAnalysis->getValueArray()); + $value = implode(',', $dbAnalysis->getValueArray()); $this->registerDBList[$table][$uid][$field] = $value; } } // For "flex" fieldtypes we need to traverse the structure for two reasons: If there are file references they have to be prepended with absolute paths and if there are database reference they MIGHT need to be remapped (still done in remapListedDBRecords()) - if ($conf['type']=='flex') { + if ($conf['type'] == 'flex') { // Get current value array: $dataStructArray = t3lib_BEfunc::getFlexFormDS($conf, $row, $table); $currentValueArray = t3lib_div::xml2array($value); // Traversing the XML structure, processing files: - if (is_array($currentValueArray)) { + if (is_array($currentValueArray)) { $currentValueArray['data'] = $this->checkValue_flex_procInData( - $currentValueArray['data'], + $currentValueArray['data'], - array(), // Not used. + array(), // Not used. - array(), // Not used. + array(), // Not used. - $dataStructArray, + $dataStructArray, - array($table, $uid, $field, $realDestPid), // Parameters. + array($table, $uid, $field, $realDestPid), // Parameters. - 'copyRecord_flexFormCallBack' - ); + 'copyRecord_flexFormCallBack' + ); - $value = $currentValueArray; // Setting value as an array! -> which means the input will be processed according to the 'flex' type when the new copy is created. + $value = $currentValueArray; // Setting value as an array! -> which means the input will be processed according to the 'flex' type when the new copy is created. } } @@ -3199,7 +3194,7 @@ * @return array Result array with key "value" containing the value of the processing. * @see copyRecord(), checkValue_flex_procInData_travDS() */ - function copyRecord_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2) { + function copyRecord_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2) { // Extract parameters: list($table, $uid, $field, $realDestPid) = $pParams; @@ -3228,26 +3223,26 @@ * @return string The (possibly modified) value * @see copyRecord(), copyRecord_flexFormCallBack() */ - function copyRecord_procFilesRefs($conf, $uid, $value) { + function copyRecord_procFilesRefs($conf, $uid, $value) { // Prepend absolute paths to files: if ($conf['type'] == 'group' && ($conf['internal_type'] == 'file' || $conf['internal_type'] == 'file_reference')) { // Get an array with files as values: - if ($conf['MM']) { + if ($conf['MM']) { $theFileValues = array(); $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); /* @var $dbAnalysis t3lib_loadDBGroup */ $dbAnalysis->start('', 'files', $conf['MM'], $uid); - foreach($dbAnalysis->itemArray as $somekey => $someval) { + foreach ($dbAnalysis->itemArray as $somekey => $someval) { - if ($someval['id']) { + if ($someval['id']) { $theFileValues[] = $someval['id']; } } } else { - $theFileValues = t3lib_div::trimExplode(',',$value,1); + $theFileValues = t3lib_div::trimExplode(',', $value, 1); } // Traverse this array of files: @@ -3255,17 +3250,17 @@ $dest = $this->destPathFromUploadFolder($uploadFolder); $newValue = array(); - foreach($theFileValues as $file) { + foreach ($theFileValues as $file) { - if (trim($file)) { + if (trim($file)) { $realFile = str_replace('//', '/', $dest . '/' . trim($file)); - if (@is_file($realFile)) { + if (@is_file($realFile)) { $newValue[] = $realFile; } } } // Implode the new filelist into the new value (all files have absolute paths now which means they will get copied when entering TCEmain as new values...) - $value = implode(',',$newValue); + $value = implode(',', $newValue); } // Return the new value: @@ -3281,13 +3276,13 @@ * @param integer Record UID * @return void */ - function copyRecord_fixRTEmagicImages($table,$theNewSQLID) { + function copyRecord_fixRTEmagicImages($table, $theNewSQLID) { global $TYPO3_DB; // Creating fileFunc object. - if (!$this->fileFunc) { + if (!$this->fileFunc) { $this->fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions'); - $this->include_filefunctions=1; + $this->include_filefunctions = 1; } // Select all RTEmagic files in the reference table from the table/ID @@ -3295,11 +3290,11 @@ $recs = $TYPO3_DB->exec_SELECTgetRows( '*', 'sys_refindex', - 'ref_table='.$TYPO3_DB->fullQuoteStr('_FILE', 'sys_refindex'). + 'ref_table=' . $TYPO3_DB->fullQuoteStr('_FILE', 'sys_refindex') . - ' AND ref_string LIKE '.$TYPO3_DB->fullQuoteStr('%/RTEmagic%', 'sys_refindex'). + ' AND ref_string LIKE ' . $TYPO3_DB->fullQuoteStr('%/RTEmagic%', 'sys_refindex') . - ' AND softref_key='.$TYPO3_DB->fullQuoteStr('images', 'sys_refindex'). + ' AND softref_key=' . $TYPO3_DB->fullQuoteStr('images', 'sys_refindex') . - ' AND tablename='.$TYPO3_DB->fullQuoteStr($table, 'sys_refindex'). + ' AND tablename=' . $TYPO3_DB->fullQuoteStr($table, 'sys_refindex') . - ' AND recuid='.intval($theNewSQLID), + ' AND recuid=' . intval($theNewSQLID), '', 'sorting DESC' ); @@ -3307,61 +3302,68 @@ // Traverse the files found and copy them: if (is_array($recs)) { - foreach($recs as $rec) { + foreach ($recs as $rec) { $filename = basename($rec['ref_string']); $fileInfo = array(); - if (t3lib_div::isFirstPartOfStr($filename,'RTEmagicC_')) { + if (t3lib_div::isFirstPartOfStr($filename, 'RTEmagicC_')) { - $fileInfo['exists'] = @is_file(PATH_site.$rec['ref_string']); + $fileInfo['exists'] = @is_file(PATH_site . $rec['ref_string']); - $fileInfo['original'] = substr($rec['ref_string'],0,-strlen($filename)).'RTEmagicP_'.preg_replace('/\.[[:alnum:]]+$/','',substr($filename,10)); + $fileInfo['original'] = substr($rec['ref_string'], 0, -strlen($filename)) . 'RTEmagicP_' . preg_replace('/\.[[:alnum:]]+$/', '', substr($filename, 10)); - $fileInfo['original_exists'] = @is_file(PATH_site.$fileInfo['original']); + $fileInfo['original_exists'] = @is_file(PATH_site . $fileInfo['original']); - // CODE from tx_impexp and class.rte_images.php adapted for use here: + // CODE from tx_impexp and class.rte_images.php adapted for use here: - if ($fileInfo['exists'] && $fileInfo['original_exists']) { + if ($fileInfo['exists'] && $fileInfo['original_exists']) { // Initialize; Get directory prefix for file and set the original name: - $dirPrefix = dirname($rec['ref_string']).'/'; + $dirPrefix = dirname($rec['ref_string']) . '/'; $rteOrigName = basename($fileInfo['original']); // If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file! - if ($rteOrigName && t3lib_div::isFirstPartOfStr($dirPrefix,'uploads/') && @is_dir(PATH_site.$dirPrefix)) { // RTE: + if ($rteOrigName && t3lib_div::isFirstPartOfStr($dirPrefix, 'uploads/') && @is_dir(PATH_site . $dirPrefix)) { // RTE: // From the "original" RTE filename, produce a new "original" destination filename which is unused. - $origDestName = $this->fileFunc->getUniqueName($rteOrigName, PATH_site.$dirPrefix); + $origDestName = $this->fileFunc->getUniqueName($rteOrigName, PATH_site . $dirPrefix); // Create copy file name: $pI = pathinfo($rec['ref_string']); - $copyDestName = dirname($origDestName).'/RTEmagicC_'.substr(basename($origDestName),10).'.'.$pI['extension']; + $copyDestName = dirname($origDestName) . '/RTEmagicC_' . substr(basename($origDestName), 10) . '.' . $pI['extension']; if (!@is_file($copyDestName) && !@is_file($origDestName) - && $origDestName===t3lib_div::getFileAbsFileName($origDestName) && $copyDestName===t3lib_div::getFileAbsFileName($copyDestName)) { + && $origDestName === t3lib_div::getFileAbsFileName($origDestName) && $copyDestName === t3lib_div::getFileAbsFileName($copyDestName)) { // Making copies: - t3lib_div::upload_copy_move(PATH_site.$fileInfo['original'],$origDestName); + t3lib_div::upload_copy_move(PATH_site . $fileInfo['original'], $origDestName); - t3lib_div::upload_copy_move(PATH_site.$rec['ref_string'],$copyDestName); + t3lib_div::upload_copy_move(PATH_site . $rec['ref_string'], $copyDestName); clearstatcache(); // Register this: - $this->RTEmagic_copyIndex[$rec['tablename']][$rec['recuid']][$rec['field']][$rec['ref_string']] = substr($copyDestName,strlen(PATH_site)); + $this->RTEmagic_copyIndex[$rec['tablename']][$rec['recuid']][$rec['field']][$rec['ref_string']] = substr($copyDestName, strlen(PATH_site)); // Check and update the record using the t3lib_refindex class: - if (@is_file($copyDestName)) { + if (@is_file($copyDestName)) { $sysRefObj = t3lib_div::makeInstance('t3lib_refindex'); - $error = $sysRefObj->setReferenceValue($rec['hash'],substr($copyDestName,strlen(PATH_site)),FALSE,TRUE); + $error = $sysRefObj->setReferenceValue($rec['hash'], substr($copyDestName, strlen(PATH_site)), FALSE, TRUE); - if ($error) { + if ($error) { - echo $this->newlog('t3lib_refindex::setReferenceValue(): '.$error,1); + echo $this->newlog('t3lib_refindex::setReferenceValue(): ' . $error, 1); } - } else $this->newlog('File "'.$copyDestName.'" was not created!',1); - } else $this->newlog('Could not construct new unique names for file!',1); - } else $this->newlog('Maybe directory of file was not within "uploads/"?',1); - } else $this->newlog('Trying to copy RTEmagic files ('.$rec['ref_string'].' / '.$fileInfo['original'].') but one or both were missing',1); + } else { + $this->newlog('File "' . $copyDestName . '" was not created!', 1); - } + } + } else { + $this->newlog('Could not construct new unique names for file!', 1); - } + } + } else { + $this->newlog('Maybe directory of file was not within "uploads/"?', 1); - } + } + } else { + $this->newlog('Trying to copy RTEmagic files (' . $rec['ref_string'] . ' / ' . $fileInfo['original'] . ') but one or both were missing', 1); - } + } + } + } + } + } - /** * Find l10n-overlay records and perform the requested move action for these records. * @@ -3370,7 +3372,7 @@ * @param string $destPid: Position to move to * @return void */ - function copyL10nOverlayRecords($table, $uid, $destPid, $first=0, $overrideValues=array(), $excludeFields='') { + function copyL10nOverlayRecords($table, $uid, $destPid, $first = 0, $overrideValues = array(), $excludeFields = '') { //there's no need to perform this for page-records if (!t3lib_BEfunc::isTableLocalizable($table) || !empty($GLOBALS['TCA'][$table]['ctrl']['transForeignTable']) || !empty($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'])) { return; @@ -3390,13 +3392,6 @@ } - - - - - - - /********************************************* * * Cmd: Moving, Localizing @@ -3411,55 +3406,55 @@ * @param integer Position to move to: $destPid: >=0 then it points to a page-id on which to insert the record (as the first element). <0 then it points to a uid from its own table after which to insert it (works if * @return void */ - function moveRecord($table,$uid,$destPid) { + function moveRecord($table, $uid, $destPid) { global $TCA, $TYPO3_CONF_VARS; - if ($TCA[$table]) { + if ($TCA[$table]) { // In case the record to be moved turns out to be an offline version, // we have to find the live version and work on that one (this case // happens for pages with "branch" versioning type) // note: as "branch" versioning is deprecated since TYPO3 4.2, this // functionality will be removed in TYPO3 4.7 (note by benni: a hook could replace this) - if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table,$uid,'uid')) { + if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table, $uid, 'uid')) { $uid = $lookForLiveVersion['uid']; } // Initialize: $destPid = intval($destPid); - $propArr = $this->getRecordProperties($table,$uid); // Get this before we change the pid (for logging) + $propArr = $this->getRecordProperties($table, $uid); // Get this before we change the pid (for logging) - $moveRec = $this->getRecordProperties($table,$uid,TRUE); + $moveRec = $this->getRecordProperties($table, $uid, TRUE); - $resolvedPid = $this->resolvePid($table,$destPid); // This is the actual pid of the moving to destination + $resolvedPid = $this->resolvePid($table, $destPid); // This is the actual pid of the moving to destination // Finding out, if the record may be moved from where it is. If the record is a non-page, then it depends on edit-permissions. // If the record is a page, then there are two options: If the page is moved within itself, (same pid) it's edit-perms of the pid. If moved to another place then its both delete-perms of the pid and new-page perms on the destination. - if ($table!='pages' || $resolvedPid==$moveRec['pid']) { + if ($table != 'pages' || $resolvedPid == $moveRec['pid']) { - $mayMoveAccess = $this->checkRecordUpdateAccess($table,$uid); // Edit rights for the record... + $mayMoveAccess = $this->checkRecordUpdateAccess($table, $uid); // Edit rights for the record... } else { - $mayMoveAccess = $this->doesRecordExist($table,$uid,'delete'); + $mayMoveAccess = $this->doesRecordExist($table, $uid, 'delete'); } // Finding out, if the record may be moved TO another place. Here we check insert-rights (non-pages = edit, pages = new), unless the pages are moved on the same pid, then edit-rights are checked - if ($table!='pages' || $resolvedPid!=$moveRec['pid']) { + if ($table != 'pages' || $resolvedPid != $moveRec['pid']) { - $mayInsertAccess = $this->checkRecordInsertAccess($table,$resolvedPid,4); // Insert rights for the record... + $mayInsertAccess = $this->checkRecordInsertAccess($table, $resolvedPid, 4); // Insert rights for the record... } else { - $mayInsertAccess = $this->checkRecordUpdateAccess($table,$uid); + $mayInsertAccess = $this->checkRecordUpdateAccess($table, $uid); } // Checking if there is anything else disallowing moving the record by checking if editing is allowed $fullLanguageCheckNeeded = ($table != 'pages'); - $mayEditAccess = $this->BE_USER->recordEditAccessInternals($table, $uid, false, false, $fullLanguageCheckNeeded); + $mayEditAccess = $this->BE_USER->recordEditAccessInternals($table, $uid, FALSE, FALSE, $fullLanguageCheckNeeded); // If moving is allowed, begin the processing: - if ($mayEditAccess) { + if ($mayEditAccess) { - if ($mayMoveAccess) { + if ($mayMoveAccess) { - if ($mayInsertAccess) { + if ($mayInsertAccess) { $recordWasMoved = FALSE; // move the record via a hook, used e.g. for versioning - if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'])) { + if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'])) { foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'] as $classRef) { $hookObj = t3lib_div::getUserObj($classRef); if (method_exists($hookObj, 'moveRecord')) { @@ -3474,13 +3469,13 @@ } } else { - $this->log($table,$uid,4,0,1,"Attempt to move record '%s' (%s) without having permissions to insert.",14,array($propArr['header'],$table.':'.$uid),$propArr['event_pid']); + $this->log($table, $uid, 4, 0, 1, "Attempt to move record '%s' (%s) without having permissions to insert..", 14, array($propArr['header'], $table . ':' . $uid), $propArr['event_pid']); } } else { - $this->log($table,$uid,4,0,1,"Attempt to move record '%s' (%s) without having permissions to do so.",14,array($propArr['header'],$table.':'.$uid),$propArr['event_pid']); + $this->log($table, $uid, 4, 0, 1, "Attempt to move record '%s' (%s) without having permissions to do so.", 14, array($propArr['header'], $table . ':' . $uid), $propArr['event_pid']); } } else { - $this->log($table,$uid,4,0,1,"Attempt to move record '%s' (%s) without having permissions to do so. [".$this->BE_USER->errorMsg."]",14,array($propArr['header'],$table.':'.$uid),$propArr['event_pid']); + $this->log($table, $uid, 4, 0, 1, "Attempt to move record '%s' (%s) without having permissions to do so. [" . $this->BE_USER->errorMsg . "]", 14, array($propArr['header'], $table . ':' . $uid), $propArr['event_pid']); } } } @@ -3496,24 +3491,24 @@ * @return void * @see moveRecord() */ - function moveRecord_raw($table,$uid,$destPid) { + function moveRecord_raw($table, $uid, $destPid) { global $TCA, $TYPO3_CONF_VARS; $sortRow = $TCA[$table]['ctrl']['sortby']; $origDestPid = $destPid; - $resolvedPid = $this->resolvePid($table,$destPid); // This is the actual pid of the moving to destination + $resolvedPid = $this->resolvePid($table, $destPid); // This is the actual pid of the moving to destination // Checking if the pid is negative, but no sorting row is defined. In that case, find the correct pid. Basically this check make the error message 4-13 meaning less... But you can always remove this check if you prefer the error instead of a no-good action (which is to move the record to its own page...) - if (($destPid<0 && !$sortRow) || $destPid>=0) { // $destPid>=0 because we must correct pid in case of versioning "page" types. + if (($destPid < 0 && !$sortRow) || $destPid >= 0) { // $destPid>=0 because we must correct pid in case of versioning "page" types. $destPid = $resolvedPid; } - $propArr = $this->getRecordProperties($table,$uid); // Get this before we change the pid (for logging) + $propArr = $this->getRecordProperties($table, $uid); // Get this before we change the pid (for logging) - $moveRec = $this->getRecordProperties($table,$uid,TRUE); + $moveRec = $this->getRecordProperties($table, $uid, TRUE); // Prepare user defined objects (if any) for hooks which extend this function: $hookObjectsArr = array(); - if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'])) { + if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'])) { foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'] as $classRef) { $hookObjectsArr[] = t3lib_div::getUserObj($classRef); } @@ -3521,107 +3516,111 @@ // Timestamp field: $updateFields = array(); - if ($TCA[$table]['ctrl']['tstamp']) { + if ($TCA[$table]['ctrl']['tstamp']) { $updateFields[$TCA[$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME']; } - if ($destPid>=0) { // insert as first element on page (where uid = $destPid) + if ($destPid >= 0) { // insert as first element on page (where uid = $destPid) - if ($table!='pages' || $this->destNotInsideSelf($destPid,$uid)) { + if ($table != 'pages' || $this->destNotInsideSelf($destPid, $uid)) { - $this->clear_cache($table,$uid); // clear cache before moving + $this->clear_cache($table, $uid); // clear cache before moving - $updateFields['pid'] = $destPid; // Setting PID + $updateFields['pid'] = $destPid; // Setting PID // table is sorted by 'sortby' - if ($sortRow) { + if ($sortRow) { - $sortNumber = $this->getSortNumber($table,$uid,$destPid); + $sortNumber = $this->getSortNumber($table, $uid, $destPid); $updateFields[$sortRow] = $sortNumber; } // check for child records that have also to be moved - $this->moveRecord_procFields($table,$uid,$destPid); + $this->moveRecord_procFields($table, $uid, $destPid); // Create query for update: - $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $updateFields); + $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($uid), $updateFields); // check for the localizations of that element $this->moveL10nOverlayRecords($table, $uid, $destPid); // Call post processing hooks: - foreach($hookObjectsArr as $hookObj) { + foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'moveRecord_firstElementPostProcess')) { $hookObj->moveRecord_firstElementPostProcess($table, $uid, $destPid, $moveRec, $updateFields, $this); } } // Logging... - $newPropArr = $this->getRecordProperties($table,$uid); + $newPropArr = $this->getRecordProperties($table, $uid); - $oldpagePropArr = $this->getRecordProperties('pages',$propArr['pid']); + $oldpagePropArr = $this->getRecordProperties('pages', $propArr['pid']); - $newpagePropArr = $this->getRecordProperties('pages',$destPid); + $newpagePropArr = $this->getRecordProperties('pages', $destPid); - if ($destPid!=$propArr['pid']) { + if ($destPid != $propArr['pid']) { - $this->log($table,$uid,4,$destPid,0,"Moved record '%s' (%s) to page '%s' (%s)",2,array($propArr['header'],$table.':'.$uid, $newpagePropArr['header'], $newPropArr['pid']),$propArr['pid']); // Logged to old page + $this->log($table, $uid, 4, $destPid, 0, "Moved record '%s' (%s) to page '%s' (%s)", 2, array($propArr['header'], $table . ':' . $uid, $newpagePropArr['header'], $newPropArr['pid']), $propArr['pid']); // Logged to old page - $this->log($table,$uid,4,$destPid,0,"Moved record '%s' (%s) from page '%s' (%s)",3,array($propArr['header'],$table.':'.$uid, $oldpagePropArr['header'], $propArr['pid']),$destPid); // Logged to new page + $this->log($table, $uid, 4, $destPid, 0, "Moved record '%s' (%s) from page '%s' (%s)", 3, array($propArr['header'], $table . ':' . $uid, $oldpagePropArr['header'], $propArr['pid']), $destPid); // Logged to new page } else { - $this->log($table,$uid,4,$destPid,0,"Moved record '%s' (%s) on page '%s' (%s)",4,array($propArr['header'],$table.':'.$uid, $oldpagePropArr['header'], $propArr['pid']),$destPid); // Logged to new page + $this->log($table, $uid, 4, $destPid, 0, "Moved record '%s' (%s) on page '%s' (%s)", 4, array($propArr['header'], $table . ':' . $uid, $oldpagePropArr['header'], $propArr['pid']), $destPid); // Logged to new page } - $this->clear_cache($table,$uid); // clear cache after moving + $this->clear_cache($table, $uid); // clear cache after moving - $this->fixUniqueInPid($table,$uid); + $this->fixUniqueInPid($table, $uid); // fixCopyAfterDuplFields - if ($origDestPid<0) {$this->fixCopyAfterDuplFields($table,$uid,abs($origDestPid),1);} // origDestPid is retrieve before it may possibly be converted to resolvePid if the table is not sorted anyway. In this way, copying records to after another records which are not sorted still lets you use this function in order to copy fields from the one before. + if ($origDestPid < 0) { + $this->fixCopyAfterDuplFields($table, $uid, abs($origDestPid), 1); + } // origDestPid is retrieve before it may possibly be converted to resolvePid if the table is not sorted anyway. In this way, copying records to after another records which are not sorted still lets you use this function in order to copy fields from the one before. } else { - $destPropArr = $this->getRecordProperties('pages',$destPid); + $destPropArr = $this->getRecordProperties('pages', $destPid); - $this->log($table,$uid,4,0,1,"Attempt to move page '%s' (%s) to inside of its own rootline (at page '%s' (%s))",10,array($propArr['header'],$uid, $destPropArr['header'], $destPid),$propArr['pid']); + $this->log($table, $uid, 4, 0, 1, "Attempt to move page '%s' (%s) to inside of its own rootline (at page '%s' (%s))", 10, array($propArr['header'], $uid, $destPropArr['header'], $destPid), $propArr['pid']); } - } else { // Put after another record + } else { // Put after another record - if ($sortRow) { // table is being sorted + if ($sortRow) { // table is being sorted - $sortInfo = $this->getSortNumber($table,$uid,$destPid); + $sortInfo = $this->getSortNumber($table, $uid, $destPid); - $destPid = $sortInfo['pid']; // Setting the destPid to the new pid of the record. + $destPid = $sortInfo['pid']; // Setting the destPid to the new pid of the record. - if (is_array($sortInfo)) { // If not an array, there was an error (which is already logged) + if (is_array($sortInfo)) { // If not an array, there was an error (which is already logged) - if ($table!='pages' || $this->destNotInsideSelf($destPid,$uid)) { + if ($table != 'pages' || $this->destNotInsideSelf($destPid, $uid)) { - $this->clear_cache($table,$uid); // clear cache before moving + $this->clear_cache($table, $uid); // clear cache before moving // We now update the pid and sortnumber $updateFields['pid'] = $destPid; $updateFields[$sortRow] = $sortInfo['sortNumber']; // check for child records that have also to be moved - $this->moveRecord_procFields($table,$uid,$destPid); + $this->moveRecord_procFields($table, $uid, $destPid); // Create query for update: - $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $updateFields); + $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($uid), $updateFields); // check for the localizations of that element $this->moveL10nOverlayRecords($table, $uid, $destPid); // Call post processing hooks: - foreach($hookObjectsArr as $hookObj) { + foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'moveRecord_afterAnotherElementPostProcess')) { $hookObj->moveRecord_afterAnotherElementPostProcess($table, $uid, $destPid, $origDestPid, $moveRec, $updateFields, $this); } } // Logging... - $newPropArr = $this->getRecordProperties($table,$uid); + $newPropArr = $this->getRecordProperties($table, $uid); - $oldpagePropArr = $this->getRecordProperties('pages',$propArr['pid']); + $oldpagePropArr = $this->getRecordProperties('pages', $propArr['pid']); - if ($destPid!=$propArr['pid']) { + if ($destPid != $propArr['pid']) { - $newpagePropArr = $this->getRecordProperties('pages',$destPid); + $newpagePropArr = $this->getRecordProperties('pages', $destPid); - $this->log($table,$uid,4,0,0,"Moved record '%s' (%s) to page '%s' (%s)",2,array($propArr['header'],$table.':'.$uid, $newpagePropArr['header'], $newPropArr['pid']),$propArr['pid']); // Logged to old page + $this->log($table, $uid, 4, 0, 0, "Moved record '%s' (%s) to page '%s' (%s)", 2, array($propArr['header'], $table . ':' . $uid, $newpagePropArr['header'], $newPropArr['pid']), $propArr['pid']); // Logged to old page - $this->log($table,$uid,4,0,0,"Moved record '%s' (%s) from page '%s' (%s)",3,array($propArr['header'],$table.':'.$uid, $oldpagePropArr['header'], $propArr['pid']),$destPid); // Logged to new page + $this->log($table, $uid, 4, 0, 0, "Moved record '%s' (%s) from page '%s' (%s)", 3, array($propArr['header'], $table . ':' . $uid, $oldpagePropArr['header'], $propArr['pid']), $destPid); // Logged to new page } else { - $this->log($table,$uid,4,0,0,"Moved record '%s' (%s) on page '%s' (%s)",4,array($propArr['header'],$table.':'.$uid, $oldpagePropArr['header'], $propArr['pid']),$destPid); // Logged to new page + $this->log($table, $uid, 4, 0, 0, "Moved record '%s' (%s) on page '%s' (%s)", 4, array($propArr['header'], $table . ':' . $uid, $oldpagePropArr['header'], $propArr['pid']), $destPid); // Logged to new page } // clear cache after moving - $this->clear_cache($table,$uid); + $this->clear_cache($table, $uid); // fixUniqueInPid - $this->fixUniqueInPid($table,$uid); + $this->fixUniqueInPid($table, $uid); // fixCopyAfterDuplFields - if ($origDestPid<0) {$this->fixCopyAfterDuplFields($table,$uid,abs($origDestPid),1);} + if ($origDestPid < 0) { + $this->fixCopyAfterDuplFields($table, $uid, abs($origDestPid), 1); + } } else { - $destPropArr = $this->getRecordProperties('pages',$destPid); + $destPropArr = $this->getRecordProperties('pages', $destPid); - $this->log($table,$uid,4,0,1,"Attempt to move page '%s' (%s) to inside of its own rootline (at page '%s' (%s))",10,array($propArr['header'],$uid, $destPropArr['header'], $destPid),$propArr['pid']); + $this->log($table, $uid, 4, 0, 1, "Attempt to move page '%s' (%s) to inside of its own rootline (at page '%s' (%s))", 10, array($propArr['header'], $uid, $destPropArr['header'], $destPid), $propArr['pid']); } } } else { - $this->log($table,$uid,4,0,1,"Attempt to move record '%s' (%s) to after another record, although the table has no sorting row.",13,array($propArr['header'],$table.':'.$uid),$propArr['event_pid']); + $this->log($table, $uid, 4, 0, 1, "Attempt to move record '%s' (%s) to after another record, although the table has no sorting row.", 13, array($propArr['header'], $table . ':' . $uid), $propArr['event_pid']); } } } @@ -3635,13 +3634,13 @@ * @param string $destPid: Position to move to * @return void */ - function moveRecord_procFields($table,$uid,$destPid) { + function moveRecord_procFields($table, $uid, $destPid) { t3lib_div::loadTCA($table); $conf = $GLOBALS['TCA'][$table]['columns']; - $row = t3lib_BEfunc::getRecordWSOL($table,$uid); + $row = t3lib_BEfunc::getRecordWSOL($table, $uid); - if (is_array($row)) { + if (is_array($row)) { foreach ($row as $field => $value) { - $this->moveRecord_procBasedOnFieldType($table,$uid,$destPid,$field,$value,$conf[$field]['config']); + $this->moveRecord_procBasedOnFieldType($table, $uid, $destPid, $field, $value, $conf[$field]['config']); } } } @@ -3728,30 +3727,30 @@ function localize($table, $uid, $language) { global $TCA; - $newId = false; + $newId = FALSE; $uid = intval($uid); - if ($TCA[$table] && $uid) { + if ($TCA[$table] && $uid) { t3lib_div::loadTCA($table); - if (($TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'] && !$TCA[$table]['ctrl']['transOrigPointerTable']) || $table==='pages') { + if (($TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'] && !$TCA[$table]['ctrl']['transOrigPointerTable']) || $table === 'pages') { - if ($langRec = t3lib_BEfunc::getRecord('sys_language',intval($language),'uid,title')) { + if ($langRec = t3lib_BEfunc::getRecord('sys_language', intval($language), 'uid,title')) { - if ($this->doesRecordExist($table,$uid,'show')) { + if ($this->doesRecordExist($table, $uid, 'show')) { - $row = t3lib_BEfunc::getRecordWSOL($table,$uid); // Getting workspace overlay if possible - this will localize versions in workspace if any + $row = t3lib_BEfunc::getRecordWSOL($table, $uid); // Getting workspace overlay if possible - this will localize versions in workspace if any - if (is_array($row)) { + if (is_array($row)) { - if ($row[$TCA[$table]['ctrl']['languageField']] <= 0 || $table==='pages') { + if ($row[$TCA[$table]['ctrl']['languageField']] <= 0 || $table === 'pages') { - if ($row[$TCA[$table]['ctrl']['transOrigPointerField']] == 0 || $table==='pages') { + if ($row[$TCA[$table]['ctrl']['transOrigPointerField']] == 0 || $table === 'pages') { - if ($table==='pages') { + if ($table === 'pages') { - $pass = $TCA[$table]['ctrl']['transForeignTable']==='pages_language_overlay' && !t3lib_BEfunc::getRecordsByField('pages_language_overlay','pid',$uid,' AND '.$TCA['pages_language_overlay']['ctrl']['languageField'].'='.intval($langRec['uid'])); + $pass = $TCA[$table]['ctrl']['transForeignTable'] === 'pages_language_overlay' && !t3lib_BEfunc::getRecordsByField('pages_language_overlay', 'pid', $uid, ' AND ' . $TCA['pages_language_overlay']['ctrl']['languageField'] . '=' . intval($langRec['uid'])); $Ttable = 'pages_language_overlay'; t3lib_div::loadTCA($Ttable); } else { - $pass = !t3lib_BEfunc::getRecordLocalization($table, $uid, $langRec['uid'], 'AND pid='.intval($row['pid'])); + $pass = !t3lib_BEfunc::getRecordLocalization($table, $uid, $langRec['uid'], 'AND pid=' . intval($row['pid'])); $Ttable = $table; } - if ($pass) { + if ($pass) { // Initialize: $overrideValues = array(); @@ -3762,27 +3761,27 @@ $overrideValues[$TCA[$Ttable]['ctrl']['transOrigPointerField']] = $uid; // Set exclude Fields: - foreach($TCA[$Ttable]['columns'] as $fN => $fCfg) { + foreach ($TCA[$Ttable]['columns'] as $fN => $fCfg) { - if ($fCfg['l10n_mode']=='prefixLangTitle') { // Check if we are just prefixing: + if ($fCfg['l10n_mode'] == 'prefixLangTitle') { // Check if we are just prefixing: - if (($fCfg['config']['type']=='text' || $fCfg['config']['type']=='input') && strlen($row[$fN])) { + if (($fCfg['config']['type'] == 'text' || $fCfg['config']['type'] == 'input') && strlen($row[$fN])) { - list($tscPID) = t3lib_BEfunc::getTSCpid($table,$uid,''); + list($tscPID) = t3lib_BEfunc::getTSCpid($table, $uid, ''); $TSConfig = $this->getTCEMAIN_TSconfig($tscPID); - if (isset($TSConfig['translateToMessage']) && strlen($TSConfig['translateToMessage'])) { + if (isset($TSConfig['translateToMessage']) && strlen($TSConfig['translateToMessage'])) { $translateToMsg = @sprintf($TSConfig['translateToMessage'], $langRec['title']); } - if (!strlen($translateToMsg)) { + if (!strlen($translateToMsg)) { - $translateToMsg = 'Translate to '.$langRec['title'].':'; + $translateToMsg = 'Translate to ' . $langRec['title'] . ':'; } - $overrideValues[$fN] = '['.$translateToMsg.'] '.$row[$fN]; + $overrideValues[$fN] = '[' . $translateToMsg . '] ' . $row[$fN]; } - } elseif (t3lib_div::inList('exclude,noCopy,mergeIfNotBlank',$fCfg['l10n_mode']) && $fN!=$TCA[$Ttable]['ctrl']['languageField'] && $fN!=$TCA[$Ttable]['ctrl']['transOrigPointerField']) { // Otherwise, do not copy field (unless it is the language field or pointer to the original language) + } elseif (t3lib_div::inList('exclude,noCopy,mergeIfNotBlank', $fCfg['l10n_mode']) && $fN != $TCA[$Ttable]['ctrl']['languageField'] && $fN != $TCA[$Ttable]['ctrl']['transOrigPointerField']) { // Otherwise, do not copy field (unless it is the language field or pointer to the original language) $excludeFields[] = $fN; } } - if ($Ttable === $table) { + if ($Ttable === $table) { // Execute the copy: $newId = $this->copyRecord($table, $uid, -$uid, 1, $overrideValues, implode(',', $excludeFields), $language); @@ -3802,28 +3801,42 @@ $copyTCE = t3lib_div::makeInstance('t3lib_TCEmain'); /* @var $copyTCE t3lib_TCEmain */ $copyTCE->stripslashes_values = 0; - $copyTCE->cachedTSconfig = $this->cachedTSconfig; // Copy forth the cached TSconfig + $copyTCE->cachedTSconfig = $this->cachedTSconfig; // Copy forth the cached TSconfig - $copyTCE->dontProcessTransformations=1; // Transformations should NOT be carried out during copy + $copyTCE->dontProcessTransformations = 1; // Transformations should NOT be carried out during copy - $copyTCE->start(array($Ttable=>array('NEW'=>$overrideValues)),'',$this->BE_USER); + $copyTCE->start(array($Ttable => array('NEW' => $overrideValues)), '', $this->BE_USER); $copyTCE->process_datamap(); // Getting the new UID as if it had been copied: $theNewSQLID = $copyTCE->substNEWwithIDs['NEW']; - if ($theNewSQLID) { + if ($theNewSQLID) { // If is by design that $Ttable is used and not $table! See "l10nmgr" extension. Could be debated, but this is what I chose for this "pseudo case" $this->copyMappingArray[$Ttable][$uid] = $theNewSQLID; $newId = $theNewSQLID; } } - } else $this->newlog('Localization failed; There already was a localization for this language of the record!',1); - } else $this->newlog('Localization failed; Source record contained a reference to an original default record (which is strange)!',1); - } else $this->newlog('Localization failed; Source record had another language than "Default" or "All" defined!',1); - } else $this->newlog('Attempt to localize record that did not exist!',1); - } else $this->newlog('Attempt to localize record without permission',1); - } else $this->newlog('Sys language UID "'.$language.'" not found valid!',1); - } else $this->newlog('Localization failed; "languageField" and "transOrigPointerField" must be defined for the table!',1); + } else { + $this->newlog('Localization failed; There already was a localization for this language of the record!', 1); - } + } + } else { + $this->newlog('Localization failed; Source record contained a reference to an original default record (which is strange)!', 1); + } + } else { + $this->newlog('Localization failed; Source record had another language than "Default" or "All" defined!', 1); + } + } else { + $this->newlog('Attempt to localize record that did not exist!', 1); + } + } else { + $this->newlog('Attempt to localize record without permission', 1); + } + } else { + $this->newlog('Sys language UID "' . $language . '" not found valid!', 1); + } + } else { + $this->newlog('Localization failed; "languageField" and "transOrigPointerField" must be defined for the table!', 1); + } + } return $newId; } @@ -3847,20 +3860,20 @@ $foreignTable = $config['foreign_table']; $localizationMode = t3lib_BEfunc::getInlineLocalizationMode($table, $config); - if ($localizationMode=='select') { + if ($localizationMode == 'select') { $parentRecord = t3lib_BEfunc::getRecordWSOL($table, $id); $language = intval($parentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']]); $transOrigPointer = intval($parentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']]); $childTransOrigPointerField = $GLOBALS['TCA'][$foreignTable]['ctrl']['transOrigPointerField']; - if ($parentRecord && is_array($parentRecord) && $language>0 && $transOrigPointer) { + if ($parentRecord && is_array($parentRecord) && $language > 0 && $transOrigPointer) { $inlineSubType = $this->getInlineFieldType($config); $transOrigRecord = t3lib_BEfunc::getRecordWSOL($table, $transOrigPointer); - if ($inlineSubType!==false) { + if ($inlineSubType !== FALSE) { $removeArray = array(); // Fetch children from original language parent: - // @var $dbAnalysisOriginal t3lib_loadDBGroup + /** @var $dbAnalysisOriginal t3lib_loadDBGroup */ $dbAnalysisOriginal = t3lib_div::makeInstance('t3lib_loadDBGroup'); $dbAnalysisOriginal->start($transOrigRecord[$field], $foreignTable, '', $transOrigRecord['uid'], $table, $config); $elementsOriginal = array(); @@ -3873,10 +3886,10 @@ $dbAnalysisCurrent = t3lib_div::makeInstance('t3lib_loadDBGroup'); $dbAnalysisCurrent->start($parentRecord[$field], $foreignTable, '', $id, $table, $config); // Perform synchronization: Possibly removal of already localized records: - if ($type=='synchronize') { + if ($type == 'synchronize') { foreach ($dbAnalysisCurrent->itemArray as $index => $item) { $childRecord = t3lib_BEfunc::getRecordWSOL($item['table'], $item['id']); - if (isset($childRecord[$childTransOrigPointerField]) && $childRecord[$childTransOrigPointerField]>0) { + if (isset($childRecord[$childTransOrigPointerField]) && $childRecord[$childTransOrigPointerField] > 0) { $childTransOrigPointer = $childRecord[$childTransOrigPointerField]; // If snychronization is requested, child record was translated once, but original record does not exist anymore, remove it: if (!isset($elementsOriginal[$childTransOrigPointer])) { @@ -3905,17 +3918,17 @@ // Remove child records (if synchronization requested it): if (is_array($removeArray) && count($removeArray)) { $tce = t3lib_div::makeInstance('t3lib_TCEmain'); - $tce->stripslashes_values = false; + $tce->stripslashes_values = FALSE; $tce->start(array(), $removeArray); $tce->process_cmdmap(); unset($tce); } // Handle, reorder and store relations: - if ($inlineSubType=='list') { + if ($inlineSubType == 'list') { $updateFields = array($field => $value); - } elseif ($inlineSubType=='field') { + } elseif ($inlineSubType == 'field') { $dbAnalysisCurrent->writeForeignField($config, $id); - $updateFields = array($field => $dbAnalysisCurrent->countItems(false)); + $updateFields = array($field => $dbAnalysisCurrent->countItems(FALSE)); } // Update field referencing to child records of localized parent record: if (is_array($updateFields) && count($updateFields)) { @@ -3928,14 +3941,6 @@ } - - - - - - - - /********************************************* * * Cmd: Deleting @@ -3949,7 +3954,7 @@ * @param integer Record UID * @return void */ - function deleteAction($table, $id) { + function deleteAction($table, $id) { global $TYPO3_CONF_VARS; $recordToDelete = t3lib_BEfunc::getRecord($table, $id); @@ -3983,11 +3988,11 @@ * @param boolean If TRUE, the "deleted" flag is ignored if applicable for record and the record is deleted COMPLETELY! * @return void */ - function deleteEl($table, $uid, $noRecordCheck=FALSE, $forceHardDelete=FALSE) { + function deleteEl($table, $uid, $noRecordCheck = FALSE, $forceHardDelete = FALSE) { - if ($table == 'pages') { + if ($table == 'pages') { $this->deletePages($uid, $noRecordCheck, $forceHardDelete); } else { - $this->deleteVersionsForRecord($table,$uid,$forceHardDelete); + $this->deleteVersionsForRecord($table, $uid, $forceHardDelete); $this->deleteRecord($table, $uid, $noRecordCheck, $forceHardDelete); } } @@ -4000,12 +4005,12 @@ * @param boolean If TRUE, the "deleted" flag is ignored if applicable for record and the record is deleted COMPLETELY! * @return void */ - function deleteVersionsForRecord($table, $uid, $forceHardDelete) { + function deleteVersionsForRecord($table, $uid, $forceHardDelete) { $versions = t3lib_BEfunc::selectVersionsOfRecord($table, $uid, 'uid,pid'); - if (is_array($versions)) { + if (is_array($versions)) { - foreach($versions as $verRec) { + foreach ($versions as $verRec) { - if (!$verRec['_CURRENT_VERSION']) { + if (!$verRec['_CURRENT_VERSION']) { - if ($table == 'pages') { + if ($table == 'pages') { $this->deletePages($verRec['uid'], TRUE, $forceHardDelete); } else { $this->deleteRecord($table, $verRec['uid'], TRUE, $forceHardDelete); @@ -4022,9 +4027,9 @@ * @param integer Record UID * @return void */ - function undeleteRecord($table,$uid) { + function undeleteRecord($table, $uid) { if ($this->isRecordUndeletable($table, $uid)) { - $this->deleteRecord($table, $uid, true, false, true); + $this->deleteRecord($table, $uid, TRUE, FALSE, TRUE); } } @@ -4041,23 +4046,23 @@ * @param boolean If TRUE, the "deleted" flag is set to 0 again and thus, the item is undeleted. * @return void */ - function deleteRecord($table,$uid, $noRecordCheck = FALSE, $forceHardDelete = FALSE, $undeleteRecord = FALSE) { + function deleteRecord($table, $uid, $noRecordCheck = FALSE, $forceHardDelete = FALSE, $undeleteRecord = FALSE) { global $TCA; // Checking if there is anything else disallowing deleting the record by checking if editing is allowed $mayEditAccess = $this->BE_USER->recordEditAccessInternals($table, $uid, FALSE, $undeleteRecord, TRUE); $uid = intval($uid); - if ($TCA[$table] && $uid) { + if ($TCA[$table] && $uid) { - if ($mayEditAccess) { + if ($mayEditAccess) { - if ($noRecordCheck || $this->doesRecordExist($table,$uid,'delete')) { + if ($noRecordCheck || $this->doesRecordExist($table, $uid, 'delete')) { - $this->clear_cache($table,$uid); // clear cache before deleting the record, else the correct page cannot be identified by clear_cache + $this->clear_cache($table, $uid); // clear cache before deleting the record, else the correct page cannot be identified by clear_cache $propArr = $this->getRecordProperties($table, $uid); $pagePropArr = $this->getRecordProperties('pages', $propArr['pid']); $deleteRow = $TCA[$table]['ctrl']['delete']; - if ($deleteRow && !$forceHardDelete) { + if ($deleteRow && !$forceHardDelete) { $value = $undeleteRecord ? 0 : 1; $updateFields = array( $deleteRow => $value @@ -4068,15 +4073,15 @@ } // If the table is sorted, then the sorting number is set very high - if ($TCA[$table]['ctrl']['sortby'] && !$undeleteRecord) { + if ($TCA[$table]['ctrl']['sortby'] && !$undeleteRecord) { $updateFields[$TCA[$table]['ctrl']['sortby']] = 1000000000; } // before (un-)deleting this record, check for child records or references $this->deleteRecord_procFields($table, $uid, $undeleteRecord); - $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $updateFields); + $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($uid), $updateFields); - // delete all l10n records aswell, impossible during undelete because it might bring too many records back to life + // delete all l10n records aswell, impossible during undelete because it might bring too many records back to life if (!$undeleteRecord) { $this->deleteL10nOverlayRecords($table, $uid); } @@ -4084,63 +4089,63 @@ // Fetches all fields with flexforms and look for files to delete: t3lib_div::loadTCA($table); - foreach($TCA[$table]['columns'] as $fieldName => $cfg) { + foreach ($TCA[$table]['columns'] as $fieldName => $cfg) { $conf = $cfg['config']; - switch($conf['type']) { + switch ($conf['type']) { case 'flex': $flexObj = t3lib_div::makeInstance('t3lib_flexformtools'); - $flexObj->traverseFlexFormXMLData($table,$fieldName,t3lib_BEfunc::getRecordRaw($table,'uid='.intval($uid)),$this,'deleteRecord_flexFormCallBack'); + $flexObj->traverseFlexFormXMLData($table, $fieldName, t3lib_BEfunc::getRecordRaw($table, 'uid=' . intval($uid)), $this, 'deleteRecord_flexFormCallBack'); break; } } // Fetches all fields that holds references to files $fileFieldArr = $this->extFileFields($table); - if (count($fileFieldArr)) { + if (count($fileFieldArr)) { - $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',',$fileFieldArr), $table, 'uid='.intval($uid)); + $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',', $fileFieldArr), $table, 'uid=' . intval($uid)); - if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) { + if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) { $fArray = $fileFieldArr; - foreach($fArray as $theField) { // MISSING: Support for MM file relations! + foreach ($fArray as $theField) { // MISSING: Support for MM file relations! - $this->extFileFunctions($table,$theField,$row[$theField],'deleteAll'); // This deletes files that belonged to this record. + $this->extFileFunctions($table, $theField, $row[$theField], 'deleteAll'); // This deletes files that belonged to this record. } } else { - $this->log($table,$uid,3,0,100,'Delete: Zero rows in result when trying to read filenames from record which should be deleted'); + $this->log($table, $uid, 3, 0, 100, 'Delete: Zero rows in result when trying to read filenames from record which should be deleted'); } } // Delete the hard way...: - $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, 'uid='.intval($uid)); + $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, 'uid=' . intval($uid)); $this->deleteL10nOverlayRecords($table, $uid); } - $state = $undeleteRecord ? 1 : 3; // 1 means insert, 3 means delete + $state = $undeleteRecord ? 1 : 3; // 1 means insert, 3 means delete - if (!$GLOBALS['TYPO3_DB']->sql_error()) { + if (!$GLOBALS['TYPO3_DB']->sql_error()) { if ($forceHardDelete) { $message = "Record '%s' (%s) was deleted unrecoverable from page '%s' (%s)"; } else { $message = $state == 1 ? - "Record '%s' (%s) was restored on page '%s' (%s)" : - "Record '%s' (%s) was deleted from page '%s' (%s)"; + "Record '%s' (%s) was restored on page '%s' (%s)" : + "Record '%s' (%s) was deleted from page '%s' (%s)"; } $this->log($table, $uid, $state, 0, 0, - $message, 0, - array( + $message, 0, + array( $propArr['header'], - $table.':'.$uid, + $table . ':' . $uid, $pagePropArr['header'], $propArr['pid'] - ), - $propArr['event_pid']); + ), + $propArr['event_pid']); } else { - $this->log($table,$uid,$state,0,100,$GLOBALS['TYPO3_DB']->sql_error()); + $this->log($table, $uid, $state, 0, 100, $GLOBALS['TYPO3_DB']->sql_error()); } // Update reference index: - $this->updateRefIndex($table,$uid); + $this->updateRefIndex($table, $uid); // if there are entries in the updateRefIndexStack if (is_array($this->updateRefIndexStack[$table]) && is_array($this->updateRefIndexStack[$table][$uid])) { @@ -4151,10 +4156,14 @@ unset($this->updateRefIndexStack[$table][$uid]); } - } else $this->log($table,$uid,3,0,1,'Attempt to delete record without delete-permissions'); - } else $this->log($table,$uid,3,0,1,'Attempt to delete record without delete-permissions. ['.$this->BE_USER->errorMsg.']'); + } else { + $this->log($table, $uid, 3, 0, 1, 'Attempt to delete record without delete-permissions'); - } + } + } else { + $this->log($table, $uid, 3, 0, 1, 'Attempt to delete record without delete-permissions. [' . $this->BE_USER->errorMsg . ']'); - } + } + } + } /** * Call back function for deleting file relations for flexform fields in records which are being completely deleted. @@ -4173,11 +4182,11 @@ $files = $refIndexObj->getRelations_procFiles($dataValue, $dsArr['TCEforms']['config'], $PA['uid']); // Traverse files and delete them: - if (is_array($files)) { + if (is_array($files)) { - foreach($files as $dat) { + foreach ($files as $dat) { - if (@is_file($dat['ID_absFile'])) { + if (@is_file($dat['ID_absFile'])) { - unlink ($dat['ID_absFile']); + unlink($dat['ID_absFile']); -#echo 'DELETE FlexFormFile:'.$dat['ID_absFile'].LF; + #echo 'DELETE FlexFormFile:'.$dat['ID_absFile'].LF; } else { $this->log('', 0, 3, 0, 100, "Delete: Referenced file '" . $dat['ID_absFile'] . "' that was supposed to be deleted together with its record which didn't exist"); } @@ -4193,22 +4202,22 @@ * @param boolean If TRUE, the "deleted" flag is ignored if applicable for record and the record is deleted COMPLETELY! * @return void */ - function deletePages($uid,$force=FALSE,$forceHardDelete=FALSE) { + function deletePages($uid, $force = FALSE, $forceHardDelete = FALSE) { // Getting list of pages to delete: - if ($force) { + if ($force) { - $brExist = $this->doesBranchExist('',$uid,0,1); // returns the branch WITHOUT permission checks (0 secures that) + $brExist = $this->doesBranchExist('', $uid, 0, 1); // returns the branch WITHOUT permission checks (0 secures that) - $res = t3lib_div::trimExplode(',',$brExist.$uid,1); + $res = t3lib_div::trimExplode(',', $brExist . $uid, 1); } else { $res = $this->canDeletePage($uid); } // Perform deletion if not error: - if (is_array($res)) { + if (is_array($res)) { - foreach($res as $deleteId) { + foreach ($res as $deleteId) { - $this->deleteSpecificPage($deleteId,$forceHardDelete); + $this->deleteSpecificPage($deleteId, $forceHardDelete); } } else { - $this->newlog($res,1); + $this->newlog($res, 1); } } @@ -4221,21 +4230,21 @@ * @access private * @see deletePages() */ - function deleteSpecificPage($uid,$forceHardDelete=FALSE) { + function deleteSpecificPage($uid, $forceHardDelete = FALSE) { $uid = intval($uid); - if ($uid) { + if ($uid) { foreach (array_keys($GLOBALS['TCA']) as $table) { - if ($table!='pages') { + if ($table != 'pages') { - $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid='.intval($uid).$this->deleteClause($table)); + $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid=' . intval($uid) . $this->deleteClause($table)); - while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) { + while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) { - $this->deleteVersionsForRecord($table,$row['uid'],$forceHardDelete); + $this->deleteVersionsForRecord($table, $row['uid'], $forceHardDelete); - $this->deleteRecord($table,$row['uid'], TRUE, $forceHardDelete); + $this->deleteRecord($table, $row['uid'], TRUE, $forceHardDelete); } $GLOBALS['TYPO3_DB']->sql_free_result($mres); } } - $this->deleteVersionsForRecord('pages',$uid,$forceHardDelete); + $this->deleteVersionsForRecord('pages', $uid, $forceHardDelete); - $this->deleteRecord('pages',$uid, TRUE, $forceHardDelete); + $this->deleteRecord('pages', $uid, TRUE, $forceHardDelete); } } @@ -4245,12 +4254,12 @@ * @param integer Page id * @return mixed If array: List of page uids to traverse and delete (means OK), if string: error code. */ - function canDeletePage($uid) { + function canDeletePage($uid) { - if ($this->doesRecordExist('pages',$uid,'delete')) { // If we may at all delete this page + if ($this->doesRecordExist('pages', $uid, 'delete')) { // If we may at all delete this page - if ($this->deleteTree) { + if ($this->deleteTree) { - $brExist = $this->doesBranchExist('',$uid,$this->pMap['delete'],1); // returns the branch + $brExist = $this->doesBranchExist('', $uid, $this->pMap['delete'], 1); // returns the branch - if ($brExist != -1) { // Checks if we had permissions + if ($brExist != -1) { // Checks if we had permissions - if ($this->noRecordsFromUnallowedTables($brExist.$uid)) { + if ($this->noRecordsFromUnallowedTables($brExist . $uid)) { $pagesInBranch = t3lib_div::trimExplode(',', $brExist . $uid, 1); foreach ($pagesInBranch as $pageInBranch) { if (!$this->BE_USER->recordEditAccessInternals('pages', $pageInBranch, FALSE, FALSE, TRUE)) { @@ -4258,20 +4267,32 @@ } } return $pagesInBranch; - } else return 'Attempt to delete records from disallowed tables'; - } else return 'Attempt to delete pages in branch without permissions'; - } else { + } else { + return 'Attempt to delete records from disallowed tables'; + } + } else { + return 'Attempt to delete pages in branch without permissions'; + } + } else { - $brExist = $this->doesBranchExist('',$uid,$this->pMap['delete'],1); // returns the branch + $brExist = $this->doesBranchExist('', $uid, $this->pMap['delete'], 1); // returns the branch - if ($brExist == '') { // Checks if branch exists + if ($brExist == '') { // Checks if branch exists - if ($this->noRecordsFromUnallowedTables($uid)) { + if ($this->noRecordsFromUnallowedTables($uid)) { if ($this->BE_USER->recordEditAccessInternals('pages', $uid, FALSE, FALSE, TRUE)) { return array($uid); - } else return 'Attempt to delete page which has prohibited localizations.'; - } else return 'Attempt to delete records from disallowed tables'; - } else return 'Attempt to delete page which has subpages'; + } else { + return 'Attempt to delete page which has prohibited localizations.'; - } + } - } else return 'Attempt to delete page without permissions'; + } else { + return 'Attempt to delete records from disallowed tables'; - } + } + } else { + return 'Attempt to delete page which has subpages'; + } + } + } else { + return 'Attempt to delete page without permissions'; + } + } /** * Returns true if record CANNOT be deleted, otherwise false. Used to check before the versioning API allows a record to be marked for deletion. @@ -4280,12 +4301,12 @@ * @param integer Record UID * @return string Returns a string IF there is an error (error string explaining). FALSE means record can be deleted */ - function cannotDeleteRecord($table,$id) { + function cannotDeleteRecord($table, $id) { - if ($table==='pages') { + if ($table === 'pages') { $res = $this->canDeletePage($id); return is_array($res) ? FALSE : $res; } else { - return $this->doesRecordExist($table,$id,'delete') ? FALSE : 'No permission to delete record'; + return $this->doesRecordExist($table, $id, 'delete') ? FALSE : 'No permission to delete record'; } } @@ -4309,7 +4330,7 @@ $this->log( $table, $uid, 'isRecordUndeletable', '', 1, 'Record cannot be undeleted since the page containing it is deleted! Undelete page "' . - $page['title'] . ' (UID: ' . $page['uid'] . ')" first' + $page['title'] . ' (UID: ' . $page['uid'] . ')" first' ); } } else { @@ -4327,12 +4348,12 @@ * @param string $uid: Record UID * @param boolean $undeleteRecord: If a record should be undeleted (e.g. from history/undo) * @return void - * @see deleteRecord() + * @see deleteRecord() */ - function deleteRecord_procFields($table, $uid, $undeleteRecord = false) { + function deleteRecord_procFields($table, $uid, $undeleteRecord = FALSE) { t3lib_div::loadTCA($table); $conf = $GLOBALS['TCA'][$table]['columns']; - $row = t3lib_BEfunc::getRecord($table, $uid, '*', '', false); + $row = t3lib_BEfunc::getRecord($table, $uid, '*', '', FALSE); foreach ($row as $field => $value) { $this->deleteRecord_procBasedOnFieldType($table, $uid, $field, $value, $conf[$field]['config'], $undeleteRecord); @@ -4350,10 +4371,10 @@ * @param array $conf: TCA configuration of current field * @param boolean $undeleteRecord: If a record should be undeleted (e.g. from history/undo) * @return void - * @see deleteRecord() + * @see deleteRecord() */ - function deleteRecord_procBasedOnFieldType($table, $uid, $field, $value, $conf, $undeleteRecord = false) { + function deleteRecord_procBasedOnFieldType($table, $uid, $field, $value, $conf, $undeleteRecord = FALSE) { - if ($conf['type'] == 'inline') { + if ($conf['type'] == 'inline') { $foreign_table = $conf['foreign_table']; if ($foreign_table) { @@ -4361,11 +4382,11 @@ if ($inlineType == 'list' || $inlineType == 'field') { $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); $dbAnalysis->start($value, $conf['foreign_table'], '', $uid, $table, $conf); - $dbAnalysis->undeleteRecord = true; + $dbAnalysis->undeleteRecord = TRUE; // walk through the items and remove them foreach ($dbAnalysis->itemArray as $v) { - if (!$undeleteRecord) { + if (!$undeleteRecord) { $this->deleteAction($v['table'], $v['id']); } else { $this->undeleteRecord($v['table'], $v['id']); @@ -4376,8 +4397,8 @@ // no delete action but calls to updateRefIndex *AFTER* this record was deleted } elseif ($this->isReferenceField($conf)) { - $allowedTables = $conf['type']=='group' ? $conf['allowed'] : $conf['foreign_table'].','.$conf['neg_foreign_table']; + $allowedTables = $conf['type'] == 'group' ? $conf['allowed'] : $conf['foreign_table'] . ',' . $conf['neg_foreign_table']; - $prependName = $conf['type']=='group' ? $conf['prepend_tname'] : $conf['neg_foreign_table']; + $prependName = $conf['type'] == 'group' ? $conf['prepend_tname'] : $conf['neg_foreign_table']; $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); $dbAnalysis->start($value, $allowedTables, $conf['MM'], $uid, $table, $conf); @@ -4408,17 +4429,13 @@ $l10nRecords = t3lib_BEfunc::getRecordsByField($table, $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'], $uid, $where); if (is_array($l10nRecords)) { - foreach($l10nRecords as $record) { + foreach ($l10nRecords as $record) { $this->deleteAction($table, intval($record['t3ver_oid']) > 0 ? intval($record['t3ver_oid']) : intval($record['uid'])); } } } - - - - /********************************************* * * Cmd: Versioning @@ -4437,27 +4454,27 @@ * @return integer Returns the id of the new version (if any) * @see copyRecord() */ - function versionizeRecord($table,$id,$label,$delete=FALSE,$versionizeTree=-1) { + function versionizeRecord($table, $id, $label, $delete = FALSE, $versionizeTree = -1) { global $TCA; $id = intval($id); - if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS'] && $id>0) { + if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS'] && $id > 0) { - if ($this->doesRecordExist($table,$id,'show')) { + if ($this->doesRecordExist($table, $id, 'show')) { - if ($this->BE_USER->workspaceVersioningTypeAccess($versionizeTree)) { + if ($this->BE_USER->workspaceVersioningTypeAccess($versionizeTree)) { // Select main record: - $row = $this->recordInfo($table,$id,'pid,t3ver_id,t3ver_state'); + $row = $this->recordInfo($table, $id, 'pid,t3ver_id,t3ver_state'); - if (is_array($row)) { + if (is_array($row)) { - if ($row['pid']>=0) { // record must be online record + if ($row['pid'] >= 0) { // record must be online record - if ($row['t3ver_state']!=3) { // record must not be placeholder for moving. + if ($row['t3ver_state'] != 3) { // record must not be placeholder for moving. - if (!$delete || !$this->cannotDeleteRecord($table,$id)) { + if (!$delete || !$this->cannotDeleteRecord($table, $id)) { // Look for next version number: $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 't3ver_id', $table, - '((pid=-1 && t3ver_oid='.$id.') OR uid='.$id.')'.$this->deleteClause($table), + '((pid=-1 && t3ver_oid=' . $id . ') OR uid=' . $id . ')' . $this->deleteClause($table), '', 't3ver_id DESC', '1' @@ -4466,51 +4483,64 @@ $GLOBALS['TYPO3_DB']->sql_free_result($res); // Look for version number of the current: - $subVer = $row['t3ver_id'].'.'.($highestVerNumber+1); + $subVer = $row['t3ver_id'] . '.' . ($highestVerNumber + 1); // Set up the values to override when making a raw-copy: $overrideArray = array( - 't3ver_id' => $highestVerNumber+1, + 't3ver_id' => $highestVerNumber + 1, 't3ver_oid' => $id, - 't3ver_label' => ($label ? $label : $subVer.' / '.date('d-m-Y H:m:s')), + 't3ver_label' => ($label ? $label : $subVer . ' / ' . date('d-m-Y H:m:s')), 't3ver_wsid' => $this->BE_USER->workspace, 't3ver_state' => $delete ? 2 : 0, 't3ver_count' => 0, 't3ver_stage' => 0, 't3ver_tstamp' => 0 ); - if ($TCA[$table]['ctrl']['editlock']) { + if ($TCA[$table]['ctrl']['editlock']) { $overrideArray[$TCA[$table]['ctrl']['editlock']] = 0; } - if ($table==='pages') { + if ($table === 'pages') { $overrideArray['t3ver_swapmode'] = $versionizeTree; } // Checking if the record already has a version in the current workspace of the backend user $workspaceCheck = TRUE; - if ($this->BE_USER->workspace!==0) { + if ($this->BE_USER->workspace !== 0) { // Look for version already in workspace: - $workspaceCheck = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace,$table,$id,'uid') ? FALSE : TRUE; + $workspaceCheck = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, $table, $id, 'uid') ? FALSE : TRUE; } - if ($workspaceCheck) { + if ($workspaceCheck) { // Create raw-copy and return result: - return $this->copyRecord_raw($table,$id,-1,$overrideArray); + return $this->copyRecord_raw($table, $id, -1, $overrideArray); - } else $this->newlog('Record "'.$table.':'.$id.'" you wanted to versionize was already a version in the workspace (wsid='.$this->BE_USER->workspace.')!',1); - } else $this->newlog('Record cannot be deleted: '.$this->cannotDeleteRecord($table,$id),1); - } else $this->newlog('Record cannot be versioned because it is a placeholder for a moving operation',1); - } else $this->newlog('Record "'.$table.':'.$id.'" you wanted to versionize was already a version in archive (pid=-1)!',1); - } else $this->newlog('Record "'.$table.':'.$id.'" you wanted to versionize did not exist!',1); - } else $this->newlog('The versioning type '.$versionizeTree.' mode you requested was not allowed',1); - } else $this->newlog('You didnt have correct permissions to make a new version (copy) of this record "'.$table.'" / '.$id,1); - } else $this->newlog('Versioning is not supported for this table "'.$table.'" / '.$id,1); + } else { + $this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize was already a version in the workspace (wsid=' . $this->BE_USER->workspace . ')!', 1); - } + } + } else { + $this->newlog('Record cannot be deleted: ' . $this->cannotDeleteRecord($table, $id), 1); + } + } else { + $this->newlog('Record cannot be versioned because it is a placeholder for a moving operation', 1); + } + } else { + $this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize was already a version in archive (pid=-1)!', 1); + } + } else { + $this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize did not exist!', 1); + } + } else { + $this->newlog('The versioning type ' . $versionizeTree . ' mode you requested was not allowed', 1); + } + } else { + $this->newlog('You didnt have correct permissions to make a new version (copy) of this record "' . $table . '" / ' . $id, 1); + } + } else { + $this->newlog('Versioning is not supported for this table "' . $table . '" / ' . $id, 1); + } + } - - - /** * Swaps MM-relations for current/swap record, see version_swap() * @@ -4520,50 +4550,50 @@ * @return void * @see version_swap() */ - function version_remapMMForVersionSwap($table,$id,$swapWith) { + function version_remapMMForVersionSwap($table, $id, $swapWith) { global $TCA; // Actually, selecting the records fully is only need if flexforms are found inside... This could be optimized ... - $currentRec = t3lib_BEfunc::getRecord($table,$id); + $currentRec = t3lib_BEfunc::getRecord($table, $id); - $swapRec = t3lib_BEfunc::getRecord($table,$swapWith); + $swapRec = t3lib_BEfunc::getRecord($table, $swapWith); $this->version_remapMMForVersionSwap_reg = array(); - foreach($TCA[$table]['columns'] as $field => $fConf) { + foreach ($TCA[$table]['columns'] as $field => $fConf) { $conf = $fConf['config']; - if ($this->isReferenceField($conf)) { + if ($this->isReferenceField($conf)) { - $allowedTables = $conf['type']=='group' ? $conf['allowed'] : $conf['foreign_table'].','.$conf['neg_foreign_table']; + $allowedTables = $conf['type'] == 'group' ? $conf['allowed'] : $conf['foreign_table'] . ',' . $conf['neg_foreign_table']; - $prependName = $conf['type']=='group' ? $conf['prepend_tname'] : $conf['neg_foreign_table']; + $prependName = $conf['type'] == 'group' ? $conf['prepend_tname'] : $conf['neg_foreign_table']; - if ($conf['MM']) { + if ($conf['MM']) { $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); /* @var $dbAnalysis t3lib_loadDBGroup */ $dbAnalysis->start('', $allowedTables, $conf['MM'], $id, $table, $conf); - if (count($dbAnalysis->getValueArray($prependName))) { + if (count($dbAnalysis->getValueArray($prependName))) { $this->version_remapMMForVersionSwap_reg[$id][$field] = array($dbAnalysis, $conf['MM'], $prependName); } $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); /* @var $dbAnalysis t3lib_loadDBGroup */ $dbAnalysis->start('', $allowedTables, $conf['MM'], $swapWith, $table, $conf); - if (count($dbAnalysis->getValueArray($prependName))) { + if (count($dbAnalysis->getValueArray($prependName))) { $this->version_remapMMForVersionSwap_reg[$swapWith][$field] = array($dbAnalysis, $conf['MM'], $prependName); } } - } elseif($conf['type']=='flex') { + } elseif ($conf['type'] == 'flex') { // Current record $dataStructArray = t3lib_BEfunc::getFlexFormDS($conf, $currentRec, $table); $currentValueArray = t3lib_div::xml2array($currentRec[$field]); - if (is_array($currentValueArray)) { + if (is_array($currentValueArray)) { $this->checkValue_flex_procInData( $currentValueArray['data'], - array(), // Not used. + array(), // Not used. - array(), // Not used. + array(), // Not used. $dataStructArray, - array($table,$id,$field), // Parameters. + array($table, $id, $field), // Parameters. 'version_remapMMForVersionSwap_flexFormCallBack' ); } @@ -4572,13 +4602,13 @@ $dataStructArray = t3lib_BEfunc::getFlexFormDS($conf, $swapRec, $table); $currentValueArray = t3lib_div::xml2array($swapRec[$field]); - if (is_array($currentValueArray)) { + if (is_array($currentValueArray)) { $this->checkValue_flex_procInData( $currentValueArray['data'], - array(), // Not used. + array(), // Not used. - array(), // Not used. + array(), // Not used. $dataStructArray, - array($table,$swapWith,$field), // Parameters. + array($table, $swapWith, $field), // Parameters. 'version_remapMMForVersionSwap_flexFormCallBack' ); } @@ -4586,7 +4616,7 @@ } // Execute: - $this->version_remapMMForVersionSwap_execSwap($table,$id,$swapWith); + $this->version_remapMMForVersionSwap_execSwap($table, $id, $swapWith); } /** @@ -4601,19 +4631,19 @@ * @return array Result array with key "value" containing the value of the processing. * @see version_remapMMForVersionSwap(), checkValue_flex_procInData_travDS() */ - function version_remapMMForVersionSwap_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2, $path) { + function version_remapMMForVersionSwap_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2, $path) { // Extract parameters: list($table, $uid, $field) = $pParams; if ($this->isReferenceField($dsConf)) { - $allowedTables = $dsConf['type']=='group' ? $dsConf['allowed'] : $dsConf['foreign_table'].','.$dsConf['neg_foreign_table']; + $allowedTables = $dsConf['type'] == 'group' ? $dsConf['allowed'] : $dsConf['foreign_table'] . ',' . $dsConf['neg_foreign_table']; - $prependName = $dsConf['type']=='group' ? $dsConf['prepend_tname'] : $dsConf['neg_foreign_table']; + $prependName = $dsConf['type'] == 'group' ? $dsConf['prepend_tname'] : $dsConf['neg_foreign_table']; - if ($dsConf['MM']) { + if ($dsConf['MM']) { $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); /* @var $dbAnalysis t3lib_loadDBGroup */ $dbAnalysis->start('', $allowedTables, $dsConf['MM'], $uid, $table, $dsConf); - $this->version_remapMMForVersionSwap_reg[$uid][$field.'/'.$path] = array($dbAnalysis, $dsConf['MM'], $prependName); + $this->version_remapMMForVersionSwap_reg[$uid][$field . '/' . $path] = array($dbAnalysis, $dsConf['MM'], $prependName); } } } @@ -4628,37 +4658,28 @@ * @return void * @see version_remapMMForVersionSwap() */ - function version_remapMMForVersionSwap_execSwap($table,$id,$swapWith) { + function version_remapMMForVersionSwap_execSwap($table, $id, $swapWith) { - if (is_array($this->version_remapMMForVersionSwap_reg[$id])) { + if (is_array($this->version_remapMMForVersionSwap_reg[$id])) { - foreach($this->version_remapMMForVersionSwap_reg[$id] as $field => $str) { + foreach ($this->version_remapMMForVersionSwap_reg[$id] as $field => $str) { - $str[0]->remapMM($str[1],$id,-$id,$str[2]); + $str[0]->remapMM($str[1], $id, -$id, $str[2]); } } - if (is_array($this->version_remapMMForVersionSwap_reg[$swapWith])) { + if (is_array($this->version_remapMMForVersionSwap_reg[$swapWith])) { - foreach($this->version_remapMMForVersionSwap_reg[$swapWith] as $field => $str) { + foreach ($this->version_remapMMForVersionSwap_reg[$swapWith] as $field => $str) { - $str[0]->remapMM($str[1],$swapWith,$id,$str[2]); + $str[0]->remapMM($str[1], $swapWith, $id, $str[2]); } } - if (is_array($this->version_remapMMForVersionSwap_reg[$id])) { + if (is_array($this->version_remapMMForVersionSwap_reg[$id])) { - foreach($this->version_remapMMForVersionSwap_reg[$id] as $field => $str) { + foreach ($this->version_remapMMForVersionSwap_reg[$id] as $field => $str) { - $str[0]->remapMM($str[1],-$id,$swapWith,$str[2]); + $str[0]->remapMM($str[1], -$id, $swapWith, $str[2]); } } } - - - - - - - - - /********************************************* * * Cmd: Helper functions @@ -4670,34 +4691,34 @@ * * @return void */ - function remapListedDBRecords() { + function remapListedDBRecords() { global $TCA; - if (count($this->registerDBList)) { + if (count($this->registerDBList)) { foreach ($this->registerDBList as $table => $records) { t3lib_div::loadTCA($table); foreach ($records as $uid => $fields) { $newData = array(); $theUidToUpdate = $this->copyMappingArray_merged[$table][$uid]; - $theUidToUpdate_saveTo = t3lib_BEfunc::wsMapId($table,$theUidToUpdate); + $theUidToUpdate_saveTo = t3lib_BEfunc::wsMapId($table, $theUidToUpdate); - foreach($fields as $fieldName => $value) { + foreach ($fields as $fieldName => $value) { $conf = $TCA[$table]['columns'][$fieldName]['config']; - switch($conf['type']) { + switch ($conf['type']) { case 'group': case 'select': $vArray = $this->remapListedDBRecords_procDBRefs($conf, $value, $theUidToUpdate, $table); - if (is_array($vArray)) { + if (is_array($vArray)) { - $newData[$fieldName] = implode(',',$vArray); + $newData[$fieldName] = implode(',', $vArray); } break; case 'flex': - if ($value=='FlexForm_reference') { + if ($value == 'FlexForm_reference') { - $origRecordRow = $this->recordInfo($table,$theUidToUpdate,'*'); // This will fetch the new row for the element + $origRecordRow = $this->recordInfo($table, $theUidToUpdate, '*'); // This will fetch the new row for the element - if (is_array($origRecordRow)) { + if (is_array($origRecordRow)) { - t3lib_BEfunc::workspaceOL($table,$origRecordRow); + t3lib_BEfunc::workspaceOL($table, $origRecordRow); // Get current data structure and value array: $dataStructArray = t3lib_BEfunc::getFlexFormDS($conf, $origRecordRow, $table); @@ -4705,18 +4726,18 @@ // Do recursive processing of the XML data: $currentValueArray['data'] = $this->checkValue_flex_procInData( - $currentValueArray['data'], + $currentValueArray['data'], - array(), // Not used. + array(), // Not used. - array(), // Not used. + array(), // Not used. - $dataStructArray, + $dataStructArray, - array($table,$theUidToUpdate,$fieldName), // Parameters. + array($table, $theUidToUpdate, $fieldName), // Parameters. - 'remapListedDBRecords_flexFormCallBack' - ); + 'remapListedDBRecords_flexFormCallBack' + ); // The return value should be compiled back into XML, ready to insert directly in the field (as we call updateDB() directly later): - if (is_array($currentValueArray['data'])) { + if (is_array($currentValueArray['data'])) { $newData[$fieldName] = - $this->checkValue_flexArray2Xml($currentValueArray,TRUE); + $this->checkValue_flexArray2Xml($currentValueArray, TRUE); } } } @@ -4725,13 +4746,13 @@ $this->remapListedDBRecords_procInline($conf, $value, $uid, $table); break; default: - debug('Field type should not appear here: '. $conf['type']); + debug('Field type should not appear here: ' . $conf['type']); break; } } - if (count($newData)) { // If any fields were changed, those fields are updated! + if (count($newData)) { // If any fields were changed, those fields are updated! - $this->updateDB($table,$theUidToUpdate_saveTo,$newData); + $this->updateDB($table, $theUidToUpdate_saveTo, $newData); } } } @@ -4749,16 +4770,16 @@ * @return array Array where the "value" key carries the value. * @see checkValue_flex_procInData_travDS(), remapListedDBRecords() */ - function remapListedDBRecords_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2) { + function remapListedDBRecords_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2) { // Extract parameters: - list($table,$uid,$field) = $pParams; + list($table, $uid, $field) = $pParams; // If references are set for this field, set flag so they can be corrected later: if ($this->isReferenceField($dsConf) && strlen($dataValue)) { $vArray = $this->remapListedDBRecords_procDBRefs($dsConf, $dataValue, $uid, $table); - if (is_array($vArray)) { + if (is_array($vArray)) { - $dataValue = implode(',',$vArray); + $dataValue = implode(',', $vArray); } } @@ -4776,35 +4797,35 @@ * @return array Returns array of items ready to implode for field content. * @see remapListedDBRecords() */ - function remapListedDBRecords_procDBRefs($conf, $value, $MM_localUid, $table) { + function remapListedDBRecords_procDBRefs($conf, $value, $MM_localUid, $table) { // Initialize variables - $set = FALSE; // Will be set true if an upgrade should be done... + $set = FALSE; // Will be set true if an upgrade should be done... - $allowedTables = $conf['type']=='group' ? $conf['allowed'] : $conf['foreign_table'].','.$conf['neg_foreign_table']; // Allowed tables for references. + $allowedTables = $conf['type'] == 'group' ? $conf['allowed'] : $conf['foreign_table'] . ',' . $conf['neg_foreign_table']; // Allowed tables for references. - $prependName = $conf['type']=='group' ? $conf['prepend_tname'] : ''; // Table name to prepend the UID + $prependName = $conf['type'] == 'group' ? $conf['prepend_tname'] : ''; // Table name to prepend the UID - $dontRemapTables = t3lib_div::trimExplode(',',$conf['dontRemapTablesOnCopy'],1); // Which tables that should possibly not be remapped + $dontRemapTables = t3lib_div::trimExplode(',', $conf['dontRemapTablesOnCopy'], 1); // Which tables that should possibly not be remapped // Convert value to list of references: $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); - $dbAnalysis->registerNonTableValues = ($conf['type']=='select' && $conf['allowNonIdValues']) ? 1 : 0; + $dbAnalysis->registerNonTableValues = ($conf['type'] == 'select' && $conf['allowNonIdValues']) ? 1 : 0; $dbAnalysis->start($value, $allowedTables, $conf['MM'], $MM_localUid, $table, $conf); // Traverse those references and map IDs: - foreach($dbAnalysis->itemArray as $k => $v) { + foreach ($dbAnalysis->itemArray as $k => $v) { $mapID = $this->copyMappingArray_merged[$v['table']][$v['id']]; - if ($mapID && !in_array($v['table'],$dontRemapTables)) { + if ($mapID && !in_array($v['table'], $dontRemapTables)) { $dbAnalysis->itemArray[$k]['id'] = $mapID; $set = TRUE; } } // If a change has been done, set the new value(s) - if ($set) { + if ($set) { - if ($conf['MM']) { + if ($conf['MM']) { $dbAnalysis->writeMM($conf['MM'], $MM_localUid, $prependName); } else { $vArray = $dbAnalysis->getValueArray($prependName); - if ($conf['type']=='select') { + if ($conf['type'] == 'select') { $vArray = $dbAnalysis->convertPosNeg($vArray, $conf['foreign_table'], $conf['neg_foreign_table']); } return $vArray; @@ -4830,7 +4851,7 @@ if ($inlineType == 'mm') { $this->remapListedDBRecords_procDBRefs($conf, $value, $theUidToUpdate, $table); - } elseif ($inlineType !== false) { + } elseif ($inlineType !== FALSE) { /** @var $dbAnalysis t3lib_loadDBGroup */ $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); $dbAnalysis->start($value, $conf['foreign_table'], '', 0, $table, $conf); @@ -4854,7 +4875,7 @@ $updateValues = array('pid' => $thePidToUpdate); foreach ($dbAnalysis->itemArray as $v) { if ($v['id'] && $v['table'] && is_null(t3lib_BEfunc::getLiveVersionIdOfRecord($v['table'], $v['id']))) { - $GLOBALS['TYPO3_DB']->exec_UPDATEquery($v['table'], 'uid='.intval($v['id']), $updateValues); + $GLOBALS['TYPO3_DB']->exec_UPDATEquery($v['table'], 'uid=' . intval($v['id']), $updateValues); } } } @@ -4870,10 +4891,12 @@ */ function processRemapStack() { // Processes the remap stack: - if(is_array($this->remapStack)) { + if (is_array($this->remapStack)) { - foreach($this->remapStack as $remapAction) { + foreach ($this->remapStack as $remapAction) { // If no position index for the arguments was set, skip this remap action: - if (!is_array($remapAction['pos'])) continue; + if (!is_array($remapAction['pos'])) { + continue; + } // Load values from the argument array in remapAction: $field = $remapAction['field']; @@ -4884,7 +4907,7 @@ $tcaFieldConf = $remapAction['args'][$remapAction['pos']['tcaFieldConf']]; // The record is new and has one or more new ids (in case of versioning/workspaces): - if(strpos($id, 'NEW') !== false) { + if (strpos($id, 'NEW') !== FALSE) { // Replace NEW...-ID with real uid: $id = $this->substNEWwithIDs[$id]; @@ -4896,10 +4919,10 @@ } // Replace relations to NEW...-IDs in field value (uids of child records): - if(is_array($valueArray)) { + if (is_array($valueArray)) { $foreign_table = $tcaFieldConf['foreign_table']; - foreach($valueArray as $key => $value) { + foreach ($valueArray as $key => $value) { - if(strpos($value, 'NEW') !== false) { + if (strpos($value, 'NEW') !== FALSE) { $value = $this->substNEWwithIDs[$value]; // The record is new, but was also auto-versionized and has another new id: if (isset($this->autoVersionIdMap[$foreign_table][$value])) { @@ -4931,7 +4954,7 @@ $hookArgs['fieldArray'][$field] = $newValue; // Process waiting hook objects: $hookObjectsArr = $hookArgs['hookObjectsArr']; - foreach($hookObjectsArr as $hookObj) { + foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) { $hookObj->processDatamap_afterDatabaseOperations($hookArgs['status'], $table, $rawId, $hookArgs['fieldArray'], $this); } @@ -4964,7 +4987,7 @@ $this->remapStackRefIndex = array(); } - /** + /** * Triggers a remap action for a specific record. * * Some records are post-processed by the processRemapStack() method (e.g. IRRE children). @@ -4973,7 +4996,7 @@ * * @param string $table Name of the table * @param string $id Id of the record (can also be a "NEW..." string) - * @param array $callback The method to be called + * @param array $callback The method to be called * @param array $arguments The arguments to be submitted to the callback method * @param boolean $forceRemapStackActions Whether to force to use the stack * @return void @@ -5017,7 +5040,7 @@ * @param integer $id: Uid of the parent record * @param array $incomingFieldArray: Reference to the incominfFieldArray of process_datamap * @param array $registerDBList: Reference to the $registerDBList array that was created/updated by versionizing calls to TCEmain in process_datamap. - * @return void + * @return void */ function getVersionizedIncomingFieldArray($table, $id, &$incomingFieldArray, &$registerDBList) { if (is_array($registerDBList[$table][$id])) { @@ -5029,8 +5052,8 @@ // Update the uids of the copied records, but also take care about new records: foreach ($origValueArray as $childId) { $newValueArray[] = $this->autoVersionIdMap[$foreignTable][$childId] - ? $this->autoVersionIdMap[$foreignTable][$childId] - : $childId; + ? $this->autoVersionIdMap[$foreignTable][$childId] + : $childId; } // Set the changed value to the $incomingFieldArray $incomingFieldArray[$field] = implode(',', $newValueArray); @@ -5038,18 +5061,13 @@ } // Clean up the $registerDBList array: unset($registerDBList[$table][$id]); - if (!count($registerDBList[$table])) unset($registerDBList[$table]); + if (!count($registerDBList[$table])) { + unset($registerDBList[$table]); - } - } + } + } + } - - - - - - - /***************************** * * Access control / Checking functions @@ -5062,11 +5080,11 @@ * @param string Table name * @return boolean Returns true if the user has general access to modify the $table */ - function checkModifyAccessList($table) { + function checkModifyAccessList($table) { - $res = ($this->admin || (!$this->tableAdminOnly($table) && t3lib_div::inList($this->BE_USER->groupData['tables_modify'],$table))); + $res = ($this->admin || (!$this->tableAdminOnly($table) && t3lib_div::inList($this->BE_USER->groupData['tables_modify'], $table))); // Hook 'checkModifyAccessList': Post-processing of the state of access - foreach($this->getCheckModifyAccessListHookObjects() as $hookObject) { + foreach ($this->getCheckModifyAccessListHookObjects() as $hookObject) { /* @var $hookObject t3lib_TCEmain_checkModifyAccessListHook */ $hookObject->checkModifyAccessList($res, $table, $this); } @@ -5081,12 +5099,12 @@ * @param integer UID of record * @return boolean Returns true if OK. Cached results. */ - function isRecordInWebMount($table,$id) { + function isRecordInWebMount($table, $id) { - if (!isset($this->isRecordInWebMount_Cache[$table.':'.$id])) { + if (!isset($this->isRecordInWebMount_Cache[$table . ':' . $id])) { - $recP=$this->getRecordProperties($table,$id); + $recP = $this->getRecordProperties($table, $id); - $this->isRecordInWebMount_Cache[$table.':'.$id]=$this->isInWebMount($recP['event_pid']); + $this->isRecordInWebMount_Cache[$table . ':' . $id] = $this->isInWebMount($recP['event_pid']); } - return $this->isRecordInWebMount_Cache[$table.':'.$id]; + return $this->isRecordInWebMount_Cache[$table . ':' . $id]; } /** @@ -5095,9 +5113,9 @@ * @param integer Page ID to check * @return boolean True if OK. Cached results. */ - function isInWebMount($pid) { + function isInWebMount($pid) { - if (!isset($this->isInWebMount_Cache[$pid])) { + if (!isset($this->isInWebMount_Cache[$pid])) { - $this->isInWebMount_Cache[$pid]=$this->BE_USER->isInWebMount($pid); + $this->isInWebMount_Cache[$pid] = $this->BE_USER->isInWebMount($pid); } return $this->isInWebMount_Cache[$pid]; } @@ -5111,30 +5129,30 @@ * @param array Hook objects * @return boolean Returns true if the user may update the record given by $table and $id */ - function checkRecordUpdateAccess($table, $id, $data=false, &$hookObjectsArr = false) { + function checkRecordUpdateAccess($table, $id, $data = FALSE, &$hookObjectsArr = FALSE) { global $TCA; $res = NULL; if (is_array($hookObjectsArr)) { - foreach($hookObjectsArr as $hookObj) { + foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'checkRecordUpdateAccess')) { $res = $hookObj->checkRecordUpdateAccess($table, $id, $data, $res, $this); } } } - if($res === 1 || $res === 0) { + if ($res === 1 || $res === 0) { return $res; } else { $res = 0; } - if ($TCA[$table] && intval($id)>0) { + if ($TCA[$table] && intval($id) > 0) { - if (isset($this->recUpdateAccessCache[$table][$id])) { // If information is cached, return it + if (isset($this->recUpdateAccessCache[$table][$id])) { // If information is cached, return it return $this->recUpdateAccessCache[$table][$id]; // Check if record exists and 1) if 'pages' the page may be edited, 2) if page-content the page allows for editing - } elseif ($this->doesRecordExist($table,$id,'edit')) { + } elseif ($this->doesRecordExist($table, $id, 'edit')) { $res = 1; } - $this->recUpdateAccessCache[$table][$id]=$res; // Cache the result + $this->recUpdateAccessCache[$table][$id] = $res; // Cache the result } return $res; } @@ -5148,27 +5166,27 @@ * @param integer For logging: Action number. * @return boolean Returns true if the user may insert a record from table $insertTable on page $pid */ - function checkRecordInsertAccess($insertTable,$pid,$action=1) { + function checkRecordInsertAccess($insertTable, $pid, $action = 1) { global $TCA; $res = 0; $pid = intval($pid); - if ($pid>=0) { + if ($pid >= 0) { - if (isset($this->recInsertAccessCache[$insertTable][$pid])) { // If information is cached, return it + if (isset($this->recInsertAccessCache[$insertTable][$pid])) { // If information is cached, return it return $this->recInsertAccessCache[$insertTable][$pid]; } else { // If either admin and root-level or if page record exists and 1) if 'pages' you may create new ones 2) if page-content, new content items may be inserted on the $pid page - if ( (!$pid && $this->admin) || $this->doesRecordExist('pages',$pid,($insertTable=='pages'?$this->pMap['new']:$this->pMap['editcontent'])) ) { // Check permissions + if ((!$pid && $this->admin) || $this->doesRecordExist('pages', $pid, ($insertTable == 'pages' ? $this->pMap['new'] : $this->pMap['editcontent']))) { // Check permissions - if ($this->isTableAllowedForThisPage($pid, $insertTable)) { + if ($this->isTableAllowedForThisPage($pid, $insertTable)) { $res = 1; - $this->recInsertAccessCache[$insertTable][$pid]=$res; // Cache the result + $this->recInsertAccessCache[$insertTable][$pid] = $res; // Cache the result } else { - $propArr = $this->getRecordProperties('pages',$pid); + $propArr = $this->getRecordProperties('pages', $pid); - $this->log($insertTable,$pid,$action,0,1,"Attempt to insert record on page '%s' (%s) where this table, %s, is not allowed",11,array($propArr['header'],$pid,$insertTable),$propArr['event_pid']); + $this->log($insertTable, $pid, $action, 0, 1, "Attempt to insert record on page '%s' (%s) where this table, %s, is not allowed", 11, array($propArr['header'], $pid, $insertTable), $propArr['event_pid']); } } else { - $propArr = $this->getRecordProperties('pages',$pid); + $propArr = $this->getRecordProperties('pages', $pid); - $this->log($insertTable,$pid,$action,0,1,"Attempt to insert a record on page '%s' (%s) from table '%s' without permissions. Or non-existing page.",12,array($propArr['header'],$pid,$insertTable),$propArr['event_pid']); + $this->log($insertTable, $pid, $action, 0, 1, "Attempt to insert a record on page '%s' (%s) from table '%s' without permissions. Or non-existing page.", 12, array($propArr['header'], $pid, $insertTable), $propArr['event_pid']); } } } @@ -5182,27 +5200,27 @@ * @param string Table name to check * @return boolean True if OK */ - function isTableAllowedForThisPage($page_uid, $checkTable) { + function isTableAllowedForThisPage($page_uid, $checkTable) { global $TCA, $PAGES_TYPES; $page_uid = intval($page_uid); // Check if rootLevel flag is set and we're trying to insert on rootLevel - and reversed - and that the table is not "pages" which are allowed anywhere. - if (($TCA[$checkTable]['ctrl']['rootLevel'] xor !$page_uid) && $TCA[$checkTable]['ctrl']['rootLevel']!=-1 && $checkTable!='pages') { + if (($TCA[$checkTable]['ctrl']['rootLevel'] xor !$page_uid) && $TCA[$checkTable]['ctrl']['rootLevel'] != -1 && $checkTable != 'pages') { - return false; + return FALSE; } // Check root-level - if (!$page_uid) { + if (!$page_uid) { - if ($this->admin) { + if ($this->admin) { - return true; + return TRUE; } } else { // Check non-root-level - $doktype = $this->pageInfo($page_uid,'doktype'); + $doktype = $this->pageInfo($page_uid, 'doktype'); $allowedTableList = isset($PAGES_TYPES[$doktype]['allowedTables']) ? $PAGES_TYPES[$doktype]['allowedTables'] : $PAGES_TYPES['default']['allowedTables']; - $allowedArray = t3lib_div::trimExplode(',',$allowedTableList,1); + $allowedArray = t3lib_div::trimExplode(',', $allowedTableList, 1); - if (strstr($allowedTableList,'*') || in_array($checkTable,$allowedArray)) { // If all tables or the table is listed as a allowed type, return true + if (strstr($allowedTableList, '*') || in_array($checkTable, $allowedArray)) { // If all tables or the table is listed as a allowed type, return true - return true; + return TRUE; } } } @@ -5215,24 +5233,24 @@ * @param mixed Permission restrictions to observe: Either an integer that will be bitwise AND'ed or a string, which points to a key in the ->pMap array * @return boolean Returns true if the record given by $table, $id and $perms can be selected */ - function doesRecordExist($table,$id,$perms) { + function doesRecordExist($table, $id, $perms) { global $TCA; - if ($this->bypassAccessCheckForRecords) { + if ($this->bypassAccessCheckForRecords) { - return is_array(t3lib_BEfunc::getRecordRaw($table,'uid='.intval($id),'uid')); + return is_array(t3lib_BEfunc::getRecordRaw($table, 'uid=' . intval($id), 'uid')); } $res = 0; $id = intval($id); // Processing the incoming $perms (from possible string to integer that can be AND'ed) - if (!t3lib_div::testInt($perms)) { + if (!t3lib_div::testInt($perms)) { - if ($table!='pages') { + if ($table != 'pages') { - switch($perms) { + switch ($perms) { case 'edit': case 'delete': case 'new': - $perms = 'editcontent'; // This holds it all in case the record is not page!! + $perms = 'editcontent'; // This holds it all in case the record is not page!! break; } } @@ -5249,22 +5267,22 @@ } // For all tables: Check if record exists: - if (is_array($TCA[$table]) && $id>0 && ($this->isRecordInWebMount($table,$id) || $this->admin)) { + if (is_array($TCA[$table]) && $id > 0 && ($this->isRecordInWebMount($table, $id) || $this->admin)) { - if ($table != 'pages') { + if ($table != 'pages') { // Find record without checking page: - $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid', $table, 'uid='.intval($id).$this->deleteClause($table)); // THIS SHOULD CHECK FOR editlock I think! + $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid', $table, 'uid=' . intval($id) . $this->deleteClause($table)); // THIS SHOULD CHECK FOR editlock I think! $output = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres); - t3lib_BEfunc::fixVersioningPid($table,$output,TRUE); + t3lib_BEfunc::fixVersioningPid($table, $output, TRUE); // If record found, check page as well: - if (is_array($output)) { + if (is_array($output)) { // Looking up the page for record: $mres = $this->doesRecordExist_pageLookUp($output['pid'], $perms); $pageRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres); // Return true if either a page was found OR if the PID is zero AND the user is ADMIN (in which case the record is at root-level): - if (is_array($pageRec) || (!$output['pid'] && $this->admin)) { + if (is_array($pageRec) || (!$output['pid'] && $this->admin)) { return TRUE; } } @@ -5285,16 +5303,16 @@ * @access private * @see doesRecordExist() */ - function doesRecordExist_pageLookUp($id, $perms) { + function doesRecordExist_pageLookUp($id, $perms) { global $TCA; return $GLOBALS['TYPO3_DB']->exec_SELECTquery( 'uid', 'pages', - 'uid='.intval($id). + 'uid=' . intval($id) . - $this->deleteClause('pages'). + $this->deleteClause('pages') . - ($perms && !$this->admin ? ' AND '.$this->BE_USER->getPagePermsClause($perms) : ''). + ($perms && !$this->admin ? ' AND ' . $this->BE_USER->getPagePermsClause($perms) : '') . - (!$this->admin && $TCA['pages']['ctrl']['editlock'] && ($perms & (2+4+16)) ? ' AND '.$TCA['pages']['ctrl']['editlock'].'=0':'') // admin users don't need check + (!$this->admin && $TCA['pages']['ctrl']['editlock'] && ($perms & (2 + 4 + 16)) ? ' AND ' . $TCA['pages']['ctrl']['editlock'] . '=0' : '') // admin users don't need check ); } @@ -5311,28 +5329,30 @@ * @param boolean Recursion flag: If set, it will go out through the branch. * @return string List of integers in branch */ - function doesBranchExist($inList,$pid,$perms,$recurse) { + function doesBranchExist($inList, $pid, $perms, $recurse) { global $TCA; $pid = intval($pid); $perms = intval($perms); - if ($pid>=0) { + if ($pid >= 0) { $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 'uid, perms_userid, perms_groupid, perms_user, perms_group, perms_everybody', 'pages', - 'pid='.intval($pid).$this->deleteClause('pages'), + 'pid=' . intval($pid) . $this->deleteClause('pages'), '', 'sorting' ); - while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) { + while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) { - if ($this->admin || $this->BE_USER->doesUserHaveAccess($row,$perms)) { // IF admin, then it's OK + if ($this->admin || $this->BE_USER->doesUserHaveAccess($row, $perms)) { // IF admin, then it's OK - $inList.=$row['uid'].','; + $inList .= $row['uid'] . ','; - if ($recurse) { // Follow the subpages recursively... + if ($recurse) { // Follow the subpages recursively... $inList = $this->doesBranchExist($inList, $row['uid'], $perms, $recurse); - if ($inList == -1) {return -1;} // No permissions somewhere in the branch + if ($inList == -1) { + return -1; + } // No permissions somewhere in the branch } } else { - return -1; // No permissions + return -1; // No permissions } } $GLOBALS['TYPO3_DB']->sql_free_result($mres); @@ -5346,10 +5366,10 @@ * @param string Table name * @return boolean True, if readonly */ - function tableReadOnly($table) { + function tableReadOnly($table) { // returns true if table is readonly global $TCA; - return ($TCA[$table]['ctrl']['readOnly'] ? 1 : 0); + return ($TCA[$table]['ctrl']['readOnly'] ? TRUE : FALSE); } /** @@ -5358,10 +5378,10 @@ * @param string Table name * @return boolean True, if readonly */ - function tableAdminOnly($table) { + function tableAdminOnly($table) { // returns true if table is admin-only global $TCA; - return ($TCA[$table]['ctrl']['adminOnly'] ? 1 : 0); + return ($TCA[$table]['ctrl']['adminOnly'] ? TRUE : FALSE); } /** @@ -5372,21 +5392,21 @@ * @param integer Page ID to test for presence inside Destination * @return boolean Returns false if ID is inside destination (including equal to) */ - function destNotInsideSelf($dest,$id) { + function destNotInsideSelf($dest, $id) { $loopCheck = 100; $dest = intval($dest); $id = intval($id); - if ($dest==$id) { + if ($dest == $id) { return FALSE; } - while ($dest!=0 && $loopCheck>0) { + while ($dest != 0 && $loopCheck > 0) { $loopCheck--; - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid, uid, t3ver_oid,t3ver_wsid', 'pages', 'uid='.intval($dest).$this->deleteClause('pages')); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid, uid, t3ver_oid,t3ver_wsid', 'pages', 'uid=' . intval($dest) . $this->deleteClause('pages')); - if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { + if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - t3lib_BEfunc::fixVersioningPid('pages',$row); + t3lib_BEfunc::fixVersioningPid('pages', $row); - if ($row['pid']==$id) { + if ($row['pid'] == $id) { return FALSE; } else { $dest = $row['pid']; @@ -5404,13 +5424,13 @@ * * @return array Array of [table]-[field] pairs to exclude from editing. */ - function getExcludeListArray() { + function getExcludeListArray() { $list = array(); foreach (array_keys($GLOBALS['TCA']) as $table) { t3lib_div::loadTCA($table); foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $config) { - if ($config['exclude'] && !t3lib_div::inList($this->BE_USER->groupData['non_exclude_fields'],$table.':'.$field)) { + if ($config['exclude'] && !t3lib_div::inList($this->BE_USER->groupData['non_exclude_fields'], $table . ':' . $field)) { - $list[]=$table.'-'.$field; + $list[] = $table . '-' . $field; } } } @@ -5424,39 +5444,33 @@ * @param integer Page doktype * @return array Returns a list of the tables that are 'present' on the page but not allowed with the page_uid/doktype */ - function doesPageHaveUnallowedTables($page_uid,$doktype) { + function doesPageHaveUnallowedTables($page_uid, $doktype) { global $PAGES_TYPES; $page_uid = intval($page_uid); - if (!$page_uid) { + if (!$page_uid) { - return FALSE; // Not a number. Probably a new page + return FALSE; // Not a number. Probably a new page } $allowedTableList = isset($PAGES_TYPES[$doktype]['allowedTables']) ? $PAGES_TYPES[$doktype]['allowedTables'] : $PAGES_TYPES['default']['allowedTables']; - $allowedArray = t3lib_div::trimExplode(',',$allowedTableList,1); + $allowedArray = t3lib_div::trimExplode(',', $allowedTableList, 1); - if (strstr($allowedTableList,'*')) { // If all tables is OK the return true + if (strstr($allowedTableList, '*')) { // If all tables is OK the return true - return FALSE; // OK... + return FALSE; // OK... } $tableList = array(); foreach (array_keys($GLOBALS['TCA']) as $table) { - if (!in_array($table,$allowedArray)) { // If the table is not in the allowed list, check if there are records... + if (!in_array($table, $allowedArray)) { // If the table is not in the allowed list, check if there are records... $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', $table, 'pid=' . intval($page_uid)); if ($count) { - $tableList[]=$table; + $tableList[] = $table; } } } - return implode(',',$tableList); + return implode(',', $tableList); } - - - - - - /***************************** * * Information lookup @@ -5471,10 +5485,10 @@ * @param string Field name for which to return value * @return string Value of the field. Result is cached in $this->pageCache[$id][$field] and returned from there next time! */ - function pageInfo($id,$field) { + function pageInfo($id, $field) { - if (!isset($this->pageCache[$id])) { + if (!isset($this->pageCache[$id])) { - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($id)); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid=' . intval($id)); - if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { + if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { $this->pageCache[$id] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); } $GLOBALS['TYPO3_DB']->sql_free_result($res); @@ -5491,11 +5505,11 @@ * @param string Field list for the SELECT query, eg. "*" or "uid,pid,..." * @return mixed Returns the selected record on success, otherwise false. */ - function recordInfo($table,$id,$fieldList) { + function recordInfo($table, $id, $fieldList) { global $TCA; - if (is_array($TCA[$table])) { + if (is_array($TCA[$table])) { - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fieldList, $table, 'uid='.intval($id)); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fieldList, $table, 'uid=' . intval($id)); - if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { + if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { $result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $GLOBALS['TYPO3_DB']->sql_free_result($res); return $result; @@ -5514,13 +5528,13 @@ * @param boolean If set, no workspace overlay is performed * @return array Properties of record */ - function getRecordProperties($table,$id,$noWSOL=FALSE) { + function getRecordProperties($table, $id, $noWSOL = FALSE) { - $row = ($table=='pages' && !$id) ? array('title'=>'[root-level]', 'uid' => 0, 'pid' => 0) :$this->recordInfo($table,$id,'*'); + $row = ($table == 'pages' && !$id) ? array('title' => '[root-level]', 'uid' => 0, 'pid' => 0) : $this->recordInfo($table, $id, '*'); - if (!$noWSOL) { + if (!$noWSOL) { - t3lib_BEfunc::workspaceOL($table,$row); + t3lib_BEfunc::workspaceOL($table, $row); } - return $this->getRecordPropertiesFromRow($table,$row); + return $this->getRecordPropertiesFromRow($table, $row); } /** @@ -5530,15 +5544,15 @@ * @param array Input row * @return array Output array */ - function getRecordPropertiesFromRow($table,$row) { + function getRecordPropertiesFromRow($table, $row) { global $TCA; - if ($TCA[$table]) { + if ($TCA[$table]) { - t3lib_BEfunc::fixVersioningPid($table,$row); + t3lib_BEfunc::fixVersioningPid($table, $row); $out = array( 'header' => $row[$TCA[$table]['ctrl']['label']], 'pid' => $row['pid'], - 'event_pid' => $this->eventPid($table,isset($row['_ORIG_pid'])?$row['t3ver_oid']:$row['uid'],$row['pid']), + 'event_pid' => $this->eventPid($table, isset($row['_ORIG_pid']) ? $row['t3ver_oid'] : $row['uid'], $row['pid']), 't3ver_state' => $TCA[$table]['ctrl']['versioningWS'] ? $row['t3ver_state'] : '', '_ORIG_pid' => $row['_ORIG_pid'] ); @@ -5546,24 +5560,11 @@ } } - function eventPid($table,$uid,$pid) { + function eventPid($table, $uid, $pid) { - return $table=='pages' ? $uid : $pid; + return $table == 'pages' ? $uid : $pid; } - - - - - - - - - - - - - /********************************************* * * Storing data to Database Layer @@ -5579,43 +5580,45 @@ * @param array Array of field=>value pairs to insert. FIELDS MUST MATCH the database FIELDS. No check is done. * @return void */ - function updateDB($table,$id,$fieldArray) { + function updateDB($table, $id, $fieldArray) { global $TCA; - if (is_array($fieldArray) && is_array($TCA[$table]) && intval($id)) { + if (is_array($fieldArray) && is_array($TCA[$table]) && intval($id)) { - unset($fieldArray['uid']); // Do NOT update the UID field, ever! + unset($fieldArray['uid']); // Do NOT update the UID field, ever! - if (count($fieldArray)) { + if (count($fieldArray)) { $fieldArray = $this->insertUpdateDB_preprocessBasedOnFieldType($table, $fieldArray); - // Execute the UPDATE query: + // Execute the UPDATE query: - $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($id), $fieldArray); + $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($id), $fieldArray); // If succees, do...: - if (!$GLOBALS['TYPO3_DB']->sql_error()) { + if (!$GLOBALS['TYPO3_DB']->sql_error()) { - if ($this->checkStoredRecords) { + if ($this->checkStoredRecords) { - $newRow = $this->checkStoredRecord($table,$id,$fieldArray,2); + $newRow = $this->checkStoredRecord($table, $id, $fieldArray, 2); } // Update reference index: - $this->updateRefIndex($table,$id); + $this->updateRefIndex($table, $id); // Set log entry: - $propArr = $this->getRecordPropertiesFromRow($table,$newRow); + $propArr = $this->getRecordPropertiesFromRow($table, $newRow); - $theLogId = $this->log($table,$id,2,$propArr['pid'],0,"Record '%s' (%s) was updated.".($propArr['_ORIG_pid']==-1?' (Offline version).':' (Online).'),10,array($propArr['header'],$table.':'.$id),$propArr['event_pid']); + $theLogId = $this->log($table, $id, 2, $propArr['pid'], 0, "Record '%s' (%s) was updated." . ($propArr['_ORIG_pid'] == -1 ? ' (Offline version).' : ' (Online).'), 10, array($propArr['header'], $table . ':' . $id), $propArr['event_pid']); // Set History data: - $this->setHistory($table,$id,$theLogId); + $this->setHistory($table, $id, $theLogId); // Clear cache for relevant pages: - $this->clear_cache($table,$id); + $this->clear_cache($table, $id); // Unset the pageCache for the id if table was page. - if ($table=='pages') unset($this->pageCache[$id]); + if ($table == 'pages') { + unset($this->pageCache[$id]); + } } else { - $this->log($table,$id,2,0,2,"SQL error: '%s' (%s)",12,array($GLOBALS['TYPO3_DB']->sql_error(),$table.':'.$id)); + $this->log($table, $id, 2, 0, 2, "SQL error: '%s' (%s)", 12, array($GLOBALS['TYPO3_DB']->sql_error(), $table . ':' . $id)); } } } @@ -5633,24 +5636,24 @@ * @param boolean If true, the ->substNEWwithIDs array is not updated. Only useful in very rare circumstances! * @return integer Returns ID on success. */ - function insertDB($table,$id,$fieldArray,$newVersion=FALSE,$suggestedUid=0,$dontSetNewIdIndex=FALSE) { + function insertDB($table, $id, $fieldArray, $newVersion = FALSE, $suggestedUid = 0, $dontSetNewIdIndex = FALSE) { global $TCA; - if (is_array($fieldArray) && is_array($TCA[$table]) && isset($fieldArray['pid'])) { + if (is_array($fieldArray) && is_array($TCA[$table]) && isset($fieldArray['pid'])) { - unset($fieldArray['uid']); // Do NOT insert the UID field, ever! + unset($fieldArray['uid']); // Do NOT insert the UID field, ever! - if (count($fieldArray)) { + if (count($fieldArray)) { // Check for "suggestedUid". // This feature is used by the import functionality to force a new record to have a certain UID value. // This is only recommended for use when the destination server is a passive mirrow of another server. // As a security measure this feature is available only for Admin Users (for now) $suggestedUid = intval($suggestedUid); - if ($this->BE_USER->isAdmin() && $suggestedUid && $this->suggestedInsertUids[$table.':'.$suggestedUid]) { + if ($this->BE_USER->isAdmin() && $suggestedUid && $this->suggestedInsertUids[$table . ':' . $suggestedUid]) { // When the value of ->suggestedInsertUids[...] is "DELETE" it will try to remove the previous record - if ($this->suggestedInsertUids[$table.':'.$suggestedUid]==='DELETE') { + if ($this->suggestedInsertUids[$table . ':' . $suggestedUid] === 'DELETE') { // DELETE: - $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, 'uid='.intval($suggestedUid)); + $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, 'uid=' . intval($suggestedUid)); } $fieldArray['uid'] = $suggestedUid; } @@ -5661,39 +5664,39 @@ $GLOBALS['TYPO3_DB']->exec_INSERTquery($table, $fieldArray); // If succees, do...: - if (!$GLOBALS['TYPO3_DB']->sql_error()) { + if (!$GLOBALS['TYPO3_DB']->sql_error()) { // Set mapping for NEW... -> real uid: - $NEW_id = $id; // the NEW_id now holds the 'NEW....' -id + $NEW_id = $id; // the NEW_id now holds the 'NEW....' -id $id = $GLOBALS['TYPO3_DB']->sql_insert_id(); - if (!$dontSetNewIdIndex) { + if (!$dontSetNewIdIndex) { $this->substNEWwithIDs[$NEW_id] = $id; $this->substNEWwithIDs_table[$NEW_id] = $table; } // Checking the record is properly saved and writing to log - if ($this->checkStoredRecords) { + if ($this->checkStoredRecords) { - $newRow = $this->checkStoredRecord($table,$id,$fieldArray,1); + $newRow = $this->checkStoredRecord($table, $id, $fieldArray, 1); } // Update reference index: - $this->updateRefIndex($table,$id); + $this->updateRefIndex($table, $id); - if ($newVersion) { + if ($newVersion) { - $propArr = $this->getRecordPropertiesFromRow($table,$newRow); + $propArr = $this->getRecordPropertiesFromRow($table, $newRow); - $this->log($table,$id,1,0,0,"New version created of table '%s', uid '%s'. UID of new version is '%s'",10,array($table,$fieldArray['t3ver_oid'],$id),$propArr['event_pid'],$NEW_id); + $this->log($table, $id, 1, 0, 0, "New version created of table '%s', uid '%s'. UID of new version is '%s'", 10, array($table, $fieldArray['t3ver_oid'], $id), $propArr['event_pid'], $NEW_id); } else { - $propArr = $this->getRecordPropertiesFromRow($table,$newRow); + $propArr = $this->getRecordPropertiesFromRow($table, $newRow); - $page_propArr = $this->getRecordProperties('pages',$propArr['pid']); + $page_propArr = $this->getRecordProperties('pages', $propArr['pid']); - $this->log($table,$id,1,0,0,"Record '%s' (%s) was inserted on page '%s' (%s)",10,array($propArr['header'],$table.':'.$id,$page_propArr['header'],$newRow['pid']),$newRow['pid'],$NEW_id); + $this->log($table, $id, 1, 0, 0, "Record '%s' (%s) was inserted on page '%s' (%s)", 10, array($propArr['header'], $table . ':' . $id, $page_propArr['header'], $newRow['pid']), $newRow['pid'], $NEW_id); // Clear cache for relavant pages: - $this->clear_cache($table,$id); + $this->clear_cache($table, $id); } return $id; } else { - $this->log($table,$id,1,0,2,"SQL error: '%s' (%s)",12,array($GLOBALS['TYPO3_DB']->sql_error(),$table.':'.$id)); + $this->log($table, $id, 1, 0, 2, "SQL error: '%s' (%s)", 12, array($GLOBALS['TYPO3_DB']->sql_error(), $table . ':' . $id)); } } } @@ -5709,26 +5712,26 @@ * @return array Selected row * @see insertDB(), updateDB() */ - function checkStoredRecord($table,$id,$fieldArray,$action) { + function checkStoredRecord($table, $id, $fieldArray, $action) { global $TCA; $id = intval($id); - if (is_array($TCA[$table]) && $id) { + if (is_array($TCA[$table]) && $id) { - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($id)); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid=' . intval($id)); - if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { + if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - // Traverse array of values that was inserted into the database and compare with the actually stored value: + // Traverse array of values that was inserted into the database and compare with the actually stored value: $errorString = array(); - foreach($fieldArray as $key => $value) { + foreach ($fieldArray as $key => $value) { - if ($this->checkStoredRecords_loose && !$value && !$row[$key]) { + if ($this->checkStoredRecords_loose && !$value && !$row[$key]) { // Nothing... - } elseif (strcmp($value,$row[$key])) { + } elseif (strcmp($value, $row[$key])) { $errorString[] = $key; } } // Set log message if there were fields with unmatching values: - if (count($errorString)) { + if (count($errorString)) { - $this->log($table,$id,$action,0,102,'These fields are not properly updated in database: ('.implode(',',$errorString).') Probably value mismatch with fieldtype.'); + $this->log($table, $id, $action, 0, 102, 'These fields are not properly updated in database: (' . implode(',', $errorString) . ') Probably value mismatch with fieldtype.'); } // Return selected rows: @@ -5746,23 +5749,23 @@ * @param integer Log entry ID, important for linking between log and history views * @return void */ - function setHistory($table,$id,$logId) { + function setHistory($table, $id, $logId) { - if (isset($this->historyRecords[$table.':'.$id])) { + if (isset($this->historyRecords[$table . ':' . $id])) { // Initialize settings: - list($tscPID) = t3lib_BEfunc::getTSCpid($table,$id,''); + list($tscPID) = t3lib_BEfunc::getTSCpid($table, $id, ''); $TSConfig = $this->getTCEMAIN_TSconfig($tscPID); - $tE = $this->getTableEntries($table,$TSConfig); + $tE = $this->getTableEntries($table, $TSConfig); - $maxAgeSeconds = 60*60*24*(strcmp($tE['history.']['maxAgeDays'],'') ? t3lib_div::intInRange($tE['history.']['maxAgeDays'],0,365) : 30); // one month + $maxAgeSeconds = 60 * 60 * 24 * (strcmp($tE['history.']['maxAgeDays'], '') ? t3lib_div::intInRange($tE['history.']['maxAgeDays'], 0, 365) : 30); // one month // Garbage collect old entries: $this->clearHistory($maxAgeSeconds, $table); // Set history data: $fields_values = array(); - $fields_values['history_data'] = serialize($this->historyRecords[$table.':'.$id]); + $fields_values['history_data'] = serialize($this->historyRecords[$table . ':' . $id]); - $fields_values['fieldlist'] = implode(',',array_keys($this->historyRecords[$table.':'.$id]['newRecord'])); + $fields_values['fieldlist'] = implode(',', array_keys($this->historyRecords[$table . ':' . $id]['newRecord'])); $fields_values['tstamp'] = $GLOBALS['EXEC_TIME']; $fields_values['tablename'] = $table; $fields_values['recuid'] = $id; @@ -5779,11 +5782,11 @@ * @param string table where the history should be cleared * @return void */ - function clearHistory($maxAgeSeconds=604800,$table) { + function clearHistory($maxAgeSeconds = 604800, $table) { $tstampLimit = $maxAgeSeconds ? $GLOBALS['EXEC_TIME'] - $maxAgeSeconds : 0; - $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_history', 'tstamp<'.intval($tstampLimit).' AND tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_history')); + $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_history', 'tstamp<' . intval($tstampLimit) . ' AND tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_history')); - } + } /** * Update Reference Index (sys_refindex) for a record @@ -5793,24 +5796,13 @@ * @param integer Record UID * @return void */ - function updateRefIndex($table,$id) { + function updateRefIndex($table, $id) { $refIndexObj = t3lib_div::makeInstance('t3lib_refindex'); /* @var $refIndexObj t3lib_refindex */ - $result = $refIndexObj->updateRefIndexTable($table,$id); + $result = $refIndexObj->updateRefIndexTable($table, $id); } - - - - - - - - - - - /********************************************* * * Misc functions @@ -5826,63 +5818,63 @@ * @param integer Positioning PID, either >=0 (pointing to page in which case we find sorting number for first record in page) or <0 (pointing to record in which case to find next sorting number after this record) * @return mixed Returns integer if PID is >=0, otherwise an array with PID and sorting number. Possibly false in case of error. */ - function getSortNumber($table,$uid,$pid) { + function getSortNumber($table, $uid, $pid) { global $TCA; - if ($TCA[$table] && $TCA[$table]['ctrl']['sortby']) { + if ($TCA[$table] && $TCA[$table]['ctrl']['sortby']) { $sortRow = $TCA[$table]['ctrl']['sortby']; - if ($pid>=0) { // Sorting number is in the top + if ($pid >= 0) { // Sorting number is in the top - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($sortRow.',pid,uid', $table, 'pid='.intval($pid).$this->deleteClause($table), '', $sortRow.' ASC', '1'); // Fetches the first record under this pid + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($sortRow . ',pid,uid', $table, 'pid=' . intval($pid) . $this->deleteClause($table), '', $sortRow . ' ASC', '1'); // Fetches the first record under this pid - if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // There was an element + if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // There was an element - if ($row['uid']==$uid) { // The top record was the record it self, so we return its current sortnumber + if ($row['uid'] == $uid) { // The top record was the record it self, so we return its current sortnumber return $row[$sortRow]; } - if ($row[$sortRow] < 1) { // If the pages sortingnumber < 1 we must resort the records under this pid + if ($row[$sortRow] < 1) { // If the pages sortingnumber < 1 we must resort the records under this pid - $this->resorting($table,$pid,$sortRow,0); + $this->resorting($table, $pid, $sortRow, 0); - return $this->sortIntervals; // First sorting number after resorting + return $this->sortIntervals; // First sorting number after resorting } else { - return floor($row[$sortRow]/2); // Sorting number between current top element and zero + return floor($row[$sortRow] / 2); // Sorting number between current top element and zero } - } else { // No pages, so we choose the default value as sorting-number + } else { // No pages, so we choose the default value as sorting-number - return $this->sortIntervals; // First sorting number if no elements. + return $this->sortIntervals; // First sorting number if no elements. } - } else { // Sorting number is inside the list + } else { // Sorting number is inside the list - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($sortRow.',pid,uid', $table, 'uid='.abs($pid).$this->deleteClause($table)); // Fetches the record which is supposed to be the prev record + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($sortRow . ',pid,uid', $table, 'uid=' . abs($pid) . $this->deleteClause($table)); // Fetches the record which is supposed to be the prev record - if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // There was a record + if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // There was a record // Look, if the record UID happens to be an offline record. If so, find its live version. Offline uids will be used when a page is versionized as "branch" so this is when we must correct - otherwise a pid of "-1" and a wrong sort-row number is returned which we don't want. - if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table,$row['uid'],$sortRow.',pid,uid')) { + if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table, $row['uid'], $sortRow . ',pid,uid')) { - $row = $lookForLiveVersion; + $row = $lookForLiveVersion; } // If the record should be inserted after itself, keep the current sorting information: - if ($row['uid']==$uid) { + if ($row['uid'] == $uid) { $sortNumber = $row[$sortRow]; } else { $subres = $GLOBALS['TYPO3_DB']->exec_SELECTquery( - $sortRow.',pid,uid', + $sortRow . ',pid,uid', $table, - 'pid='.intval($row['pid']).' AND '.$sortRow.'>='.intval($row[$sortRow]).$this->deleteClause($table), + 'pid=' . intval($row['pid']) . ' AND ' . $sortRow . '>=' . intval($row[$sortRow]) . $this->deleteClause($table), '', - $sortRow.' ASC', + $sortRow . ' ASC', '2' - ); // Fetches the next record in order to calculate the in-between sortNumber + ); // Fetches the next record in order to calculate the in-between sortNumber - if ($GLOBALS['TYPO3_DB']->sql_num_rows($subres)==2) { // There was a record afterwards + if ($GLOBALS['TYPO3_DB']->sql_num_rows($subres) == 2) { // There was a record afterwards - $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres); // Forward to the second result... + $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres); // Forward to the second result... - $subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres); // There was a record afterwards + $subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres); // There was a record afterwards - $sortNumber = $row[$sortRow]+ floor(($subrow[$sortRow]-$row[$sortRow])/2); // The sortNumber is found in between these values + $sortNumber = $row[$sortRow] + floor(($subrow[$sortRow] - $row[$sortRow]) / 2); // The sortNumber is found in between these values - if ($sortNumber<=$row[$sortRow] || $sortNumber>=$subrow[$sortRow]) { // The sortNumber happend NOT to be between the two surrounding numbers, so we'll have to resort the list + if ($sortNumber <= $row[$sortRow] || $sortNumber >= $subrow[$sortRow]) { // The sortNumber happend NOT to be between the two surrounding numbers, so we'll have to resort the list - $sortNumber = $this->resorting($table,$row['pid'],$sortRow, $row['uid']); // By this special param, resorting reserves and returns the sortnumber after the uid + $sortNumber = $this->resorting($table, $row['pid'], $sortRow, $row['uid']); // By this special param, resorting reserves and returns the sortnumber after the uid } - } else { // If after the last record in the list, we just add the sortInterval to the last sortvalue + } else { // If after the last record in the list, we just add the sortInterval to the last sortvalue - $sortNumber = $row[$sortRow]+$this->sortIntervals; + $sortNumber = $row[$sortRow] + $this->sortIntervals; } $GLOBALS['TYPO3_DB']->sql_free_result($subres); } - return Array('pid' => $row['pid'], 'sortNumber' => $sortNumber); + return array('pid' => $row['pid'], 'sortNumber' => $sortNumber); } else { - $propArr = $this->getRecordProperties($table,$uid); + $propArr = $this->getRecordProperties($table, $uid); - $this->log($table,$uid,4,0,1,"Attempt to move record '%s' (%s) to after a non-existing record (uid=%s)",1,array($propArr['header'],$table.':'.$uid,abs($pid)),$propArr['pid']); // OK, dont insert $propArr['event_pid'] here... + $this->log($table, $uid, 4, 0, 1, "Attempt to move record '%s' (%s) to after a non-existing record (uid=%s)", 1, array($propArr['header'], $table . ':' . $uid, abs($pid)), $propArr['pid']); // OK, dont insert $propArr['event_pid'] here... - return false; // There MUST be a page or else this cannot work + return FALSE; // There MUST be a page or else this cannot work } } } @@ -5900,24 +5892,26 @@ * @access private * @see getSortNumber() */ - function resorting($table,$pid,$sortRow, $return_SortNumber_After_This_Uid) { + function resorting($table, $pid, $sortRow, $return_SortNumber_After_This_Uid) { global $TCA; - if ($TCA[$table] && $sortRow && $TCA[$table]['ctrl']['sortby']==$sortRow) { + if ($TCA[$table] && $sortRow && $TCA[$table]['ctrl']['sortby'] == $sortRow) { $returnVal = 0; $intervals = $this->sortIntervals; - $i = $intervals*2; + $i = $intervals * 2; - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid='.intval($pid).$this->deleteClause($table), '', $sortRow.' ASC'); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid=' . intval($pid) . $this->deleteClause($table), '', $sortRow . ' ASC'); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - $uid=intval($row['uid']); + $uid = intval($row['uid']); - if ($uid) { + if ($uid) { - $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), array($sortRow=>$i)); + $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($uid), array($sortRow => $i)); - if ($uid==$return_SortNumber_After_This_Uid) { // This is used to return a sortingValue if the list is resorted because of inserting records inside the list and not in the top + if ($uid == $return_SortNumber_After_This_Uid) { // This is used to return a sortingValue if the list is resorted because of inserting records inside the list and not in the top - $i = $i+$intervals; + $i = $i + $intervals; - $returnVal=$i; + $returnVal = $i; } - } else {die ('Fatal ERROR!! No Uid at resorting.');} + } else { + die ('Fatal ERROR!! No Uid at resorting.'); + } - $i = $i+$intervals; + $i = $i + $intervals; } $GLOBALS['TYPO3_DB']->sql_free_result($res); return $returnVal; @@ -5932,12 +5926,22 @@ * @param array TSconfig properties * @return array Modified Field Array */ - function setTSconfigPermissions($fieldArray,$TSConfig_p) { + function setTSconfigPermissions($fieldArray, $TSConfig_p) { - if (strcmp($TSConfig_p['userid'],'')) $fieldArray['perms_userid']=intval($TSConfig_p['userid']); - if (strcmp($TSConfig_p['groupid'],'')) $fieldArray['perms_groupid']=intval($TSConfig_p['groupid']); - if (strcmp($TSConfig_p['user'],'')) $fieldArray['perms_user']=t3lib_div::testInt($TSConfig_p['user']) ? $TSConfig_p['user'] : $this->assemblePermissions($TSConfig_p['user']); - if (strcmp($TSConfig_p['group'],'')) $fieldArray['perms_group']=t3lib_div::testInt($TSConfig_p['group']) ? $TSConfig_p['group'] : $this->assemblePermissions($TSConfig_p['group']); - if (strcmp($TSConfig_p['everybody'],'')) $fieldArray['perms_everybody']=t3lib_div::testInt($TSConfig_p['everybody']) ? $TSConfig_p['everybody'] : $this->assemblePermissions($TSConfig_p['everybody']); + if (strcmp($TSConfig_p['userid'], '')) { + $fieldArray['perms_userid'] = intval($TSConfig_p['userid']); + } + if (strcmp($TSConfig_p['groupid'], '')) { + $fieldArray['perms_groupid'] = intval($TSConfig_p['groupid']); + } + if (strcmp($TSConfig_p['user'], '')) { + $fieldArray['perms_user'] = t3lib_div::testInt($TSConfig_p['user']) ? $TSConfig_p['user'] : $this->assemblePermissions($TSConfig_p['user']); + } + if (strcmp($TSConfig_p['group'], '')) { + $fieldArray['perms_group'] = t3lib_div::testInt($TSConfig_p['group']) ? $TSConfig_p['group'] : $this->assemblePermissions($TSConfig_p['group']); + } + if (strcmp($TSConfig_p['everybody'], '')) { + $fieldArray['perms_everybody'] = t3lib_div::testInt($TSConfig_p['everybody']) ? $TSConfig_p['everybody'] : $this->assemblePermissions($TSConfig_p['everybody']); + } return $fieldArray; } @@ -5949,19 +5953,19 @@ * @param string Table name for which to set default values. * @return array Array with default values. */ - function newFieldArray($table) { + function newFieldArray($table) { t3lib_div::loadTCA($table); - $fieldArray=Array(); + $fieldArray = array(); if (is_array($GLOBALS['TCA'][$table]['columns'])) { foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $content) { - if (isset($this->defaultValues[$table][$field])) { + if (isset($this->defaultValues[$table][$field])) { $fieldArray[$field] = $this->defaultValues[$table][$field]; - } elseif (isset($content['config']['default'])) { + } elseif (isset($content['config']['default'])) { $fieldArray[$field] = $content['config']['default']; } } } - if ($table==='pages') { // Set default permissions for a page. + if ($table === 'pages') { // Set default permissions for a page. $fieldArray['perms_userid'] = $this->userid; $fieldArray['perms_groupid'] = intval($this->BE_USER->firstMainGroup); $fieldArray['perms_user'] = $this->assemblePermissions($this->defaultPermissions['user']); @@ -5978,15 +5982,15 @@ * @param array Incoming array (passed by reference) * @return void */ - function addDefaultPermittedLanguageIfNotSet($table,&$incomingFieldArray) { + function addDefaultPermittedLanguageIfNotSet($table, &$incomingFieldArray) { global $TCA; // Checking languages: - if ($TCA[$table]['ctrl']['languageField']) { + if ($TCA[$table]['ctrl']['languageField']) { - if (!isset($incomingFieldArray[$TCA[$table]['ctrl']['languageField']])) { // Language field must be found in input row - otherwise it does not make sense. + if (!isset($incomingFieldArray[$TCA[$table]['ctrl']['languageField']])) { // Language field must be found in input row - otherwise it does not make sense. - $rows = array_merge(array(array('uid'=>0)),$GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid','sys_language','pid=0'.t3lib_BEfunc::deleteClause('sys_language')),array(array('uid'=>-1))); + $rows = array_merge(array(array('uid' => 0)), $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'sys_language', 'pid=0' . t3lib_BEfunc::deleteClause('sys_language')), array(array('uid' => -1))); - foreach($rows as $r) { + foreach ($rows as $r) { - if ($this->BE_USER->checkLanguageAccess($r['uid'])) { + if ($this->BE_USER->checkLanguageAccess($r['uid'])) { $incomingFieldArray[$TCA[$table]['ctrl']['languageField']] = $r['uid']; break; } @@ -6002,9 +6006,9 @@ * @param array Data array with fields from table. These will be overlaid with values in $this->overrideValues[$table] * @return array Data array, processed. */ - function overrideFieldArray($table,$data) { + function overrideFieldArray($table, $data) { - if (is_array($this->overrideValues[$table])) { + if (is_array($this->overrideValues[$table])) { - $data = array_merge($data,$this->overrideValues[$table]); + $data = array_merge($data, $this->overrideValues[$table]); } return $data; } @@ -6018,20 +6022,20 @@ * @param array Array of field=>value pairs intended to be inserted into the database. All keys with values matching exactly the current value will be unset! * @return array Returns $fieldArray. If the returned array is empty, then the record should not be updated! */ - function compareFieldArrayWithCurrentAndUnset($table,$id,$fieldArray) { + function compareFieldArrayWithCurrentAndUnset($table, $id, $fieldArray) { // Fetch the original record: - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($id)); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid=' . intval($id)); $currentRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); // If the current record exists (which it should...), begin comparison: - if (is_array($currentRecord)) { + if (is_array($currentRecord)) { // Read all field types: $c = 0; $cRecTypes = array(); - foreach($currentRecord as $col => $val) { + foreach ($currentRecord as $col => $val) { - $cRecTypes[$col] = $GLOBALS['TYPO3_DB']->sql_field_type($res,$c); + $cRecTypes[$col] = $GLOBALS['TYPO3_DB']->sql_field_type($res, $c); $c++; } @@ -6039,11 +6043,11 @@ $GLOBALS['TYPO3_DB']->sql_free_result($res); // Unset the fields which are similar: - foreach($fieldArray as $col => $val) { + foreach ($fieldArray as $col => $val) { if ( !$GLOBALS['TCA'][$table]['columns'][$col]['config']['MM'] && // Do not unset MM relation fields, since equality of the MM count doesn't always mean that relations haven't changed. - ( !strcmp($val,$currentRecord[$col]) || // Unset fields which matched exactly. + (!strcmp($val, $currentRecord[$col]) || // Unset fields which matched exactly. - ($cRecTypes[$col]=='int' && $currentRecord[$col]==0 && !strcmp($val,'')) // Now, a situation where TYPO3 tries to put an empty string into an integer field, we should not strcmp the integer-zero and '', but rather accept them to be similar. + ($cRecTypes[$col] == 'int' && $currentRecord[$col] == 0 && !strcmp($val, '')) // Now, a situation where TYPO3 tries to put an empty string into an integer field, we should not strcmp the integer-zero and '', but rather accept them to be similar. ) ) { unset($fieldArray[$col]); @@ -6060,7 +6064,7 @@ } } } - } else { // If the current record does not exist this is an error anyways and we just return an empty array here. + } else { // If the current record does not exist this is an error anyways and we just return an empty array here. $fieldArray = array(); } @@ -6074,11 +6078,11 @@ * @return integer Integer mask * @see setTSconfigPermissions(), newFieldArray() */ - function assemblePermissions($string) { + function assemblePermissions($string) { - $keyArr = t3lib_div::trimExplode(',',$string,1); + $keyArr = t3lib_div::trimExplode(',', $string, 1); - $value=0; + $value = 0; foreach ($keyArr as $key) { - if ($key && isset($this->pMap[$key])) { + if ($key && isset($this->pMap[$key])) { $value |= $this->pMap[$key]; } } @@ -6091,7 +6095,7 @@ * @param string Input string * @return string Output string with any comma in the end removed, if any. */ - function rmComma($input) { + function rmComma($input) { return rtrim($input, ','); } @@ -6101,20 +6105,20 @@ * @param string Input string * @return string Output string */ - function convNumEntityToByteValue($input) { + function convNumEntityToByteValue($input) { $token = md5(microtime()); - $parts = explode($token,preg_replace('/(&#([0-9]+);)/',$token.'\2'.$token,$input)); + $parts = explode($token, preg_replace('/(&#([0-9]+);)/', $token . '\2' . $token, $input)); - foreach($parts as $k => $v) { + foreach ($parts as $k => $v) { - if ($k%2) { + if ($k % 2) { $v = intval($v); - if ($v > 32) { // Just to make sure that control bytes are not converted. + if ($v > 32) { // Just to make sure that control bytes are not converted. - $parts[$k] =chr(intval($v)); + $parts[$k] = chr(intval($v)); } } } - return implode('',$parts); + return implode('', $parts); } /** @@ -6123,8 +6127,8 @@ * @param string Upload folder name, relative to PATH_site * @return string Input string prefixed with PATH_site */ - function destPathFromUploadFolder($folder) { + function destPathFromUploadFolder($folder) { - return PATH_site.$folder; + return PATH_site . $folder; } /** @@ -6135,7 +6139,7 @@ * @return void */ public function disableDeleteClause() { - $this->disableDeleteClause = true; + $this->disableDeleteClause = TRUE; } /** @@ -6144,11 +6148,11 @@ * @param string Table name * @return string Delete clause */ - function deleteClause($table) { + function deleteClause($table) { // Returns the proper delete-clause if any for a table from TCA global $TCA; if (!$this->disableDeleteClause && $TCA[$table]['ctrl']['delete']) { - return ' AND '.$table.'.'.$TCA[$table]['ctrl']['delete'].'=0'; + return ' AND ' . $table . '.' . $TCA[$table]['ctrl']['delete'] . '=0'; } else { return ''; } @@ -6160,9 +6164,9 @@ * @param integer Page id (PID) from which to get configuration. * @return array TSconfig array, if any */ - function getTCEMAIN_TSconfig($tscPID) { + function getTCEMAIN_TSconfig($tscPID) { - if (!isset($this->cachedTSconfig[$tscPID])) { + if (!isset($this->cachedTSconfig[$tscPID])) { - $this->cachedTSconfig[$tscPID] = $this->BE_USER->getTSConfig('TCEMAIN',t3lib_BEfunc::getPagesTSconfig($tscPID)); + $this->cachedTSconfig[$tscPID] = $this->BE_USER->getTSConfig('TCEMAIN', t3lib_BEfunc::getPagesTSconfig($tscPID)); } return $this->cachedTSconfig[$tscPID]['properties']; } @@ -6175,10 +6179,11 @@ * @return array TSconfig merged * @see getTCEMAIN_TSconfig() */ - function getTableEntries($table,$TSconfig) { + function getTableEntries($table, $TSconfig) { - $tA = is_array($TSconfig['table.'][$table.'.']) ? $TSconfig['table.'][$table.'.'] : array();; + $tA = is_array($TSconfig['table.'][$table . '.']) ? $TSconfig['table.'][$table . '.'] : array(); + ; $dA = is_array($TSconfig['default.']) ? $TSconfig['default.'] : array(); - return t3lib_div::array_merge_recursive_overrule($dA,$tA); + return t3lib_div::array_merge_recursive_overrule($dA, $tA); } /** @@ -6188,9 +6193,9 @@ * @param integer Record uid * @return integer PID value (unless the record did not exist in which case FALSE) */ - function getPID($table,$uid) { + function getPID($table, $uid) { - $res_tmp = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid', $table, 'uid='.intval($uid)); + $res_tmp = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid', $table, 'uid=' . intval($uid)); - if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp)) { + if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp)) { return $row['pid']; } } @@ -6201,13 +6206,13 @@ * * @return void */ - function dbAnalysisStoreExec() { + function dbAnalysisStoreExec() { foreach ($this->dbAnalysisStore as $action) { $id = t3lib_BEfunc::wsMapId( $action[4], (t3lib_div::testInt($action[2]) ? $action[2] : $this->substNEWwithIDs[$action[2]]) ); - if ($id) { + if ($id) { $action[0]->writeMM($action[1], $id, $action[3]); } } @@ -6218,7 +6223,7 @@ * * @return void */ - function removeRegisteredFiles() { + function removeRegisteredFiles() { foreach ($this->removeFilesStore as $file) { unlink($file); } @@ -6229,7 +6234,7 @@ * * @return integer The number of files deleted */ - function removeCacheFiles() { + function removeCacheFiles() { return t3lib_extMgm::removeCacheFiles(); } @@ -6243,15 +6248,15 @@ * @param integer ID of root point for new copied branch: The idea seems to be that a copy is not made of the already new page! * @return array Return array. */ - function int_pageTreeInfo($CPtable,$pid,$counter, $rootID) { + function int_pageTreeInfo($CPtable, $pid, $counter, $rootID) { - if ($counter) { + if ($counter) { - $addW = !$this->admin ? ' AND '.$this->BE_USER->getPagePermsClause($this->pMap['show']) : ''; + $addW = !$this->admin ? ' AND ' . $this->BE_USER->getPagePermsClause($this->pMap['show']) : ''; - $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid='.intval($pid).$this->deleteClause('pages').$addW, '', 'sorting DESC'); + $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid=' . intval($pid) . $this->deleteClause('pages') . $addW, '', 'sorting DESC'); - while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) { + while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) { - if ($row['uid']!=$rootID) { + if ($row['uid'] != $rootID) { $CPtable[$row['uid']] = $pid; - if ($counter-1) { // If the uid is NOT the rootID of the copyaction and if we are supposed to walk further down + if ($counter - 1) { // If the uid is NOT the rootID of the copyaction and if we are supposed to walk further down - $CPtable = $this->int_pageTreeInfo($CPtable,$row['uid'],$counter-1, $rootID); + $CPtable = $this->int_pageTreeInfo($CPtable, $row['uid'], $counter - 1, $rootID); } } } @@ -6265,7 +6270,7 @@ * * @return array Array of all TCA table names */ - function compileAdminTables() { + function compileAdminTables() { return array_keys($GLOBALS['TCA']); } @@ -6276,25 +6281,25 @@ * @param integer Record UID * @return void */ - function fixUniqueInPid($table,$uid) { + function fixUniqueInPid($table, $uid) { if ($GLOBALS['TCA'][$table]) { t3lib_div::loadTCA($table); - $curData=$this->recordInfo($table,$uid,'*'); + $curData = $this->recordInfo($table, $uid, '*'); - $newData=array(); + $newData = array(); foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $conf) { - if ($conf['config']['type']=='input') { + if ($conf['config']['type'] == 'input') { - $evalCodesArray = t3lib_div::trimExplode(',',$conf['config']['eval'],1); + $evalCodesArray = t3lib_div::trimExplode(',', $conf['config']['eval'], 1); - if (in_array('uniqueInPid',$evalCodesArray)) { + if (in_array('uniqueInPid', $evalCodesArray)) { - $newV = $this->getUnique($table,$field,$curData[$field],$uid,$curData['pid']); + $newV = $this->getUnique($table, $field, $curData[$field], $uid, $curData['pid']); - if (strcmp($newV,$curData[$field])) { + if (strcmp($newV, $curData[$field])) { - $newData[$field]=$newV; + $newData[$field] = $newV; } } } } // IF there are changed fields, then update the database - if (count($newData)) { + if (count($newData)) { - $this->updateDB($table,$uid,$newData); + $this->updateDB($table, $uid, $newData); } } } @@ -6310,19 +6315,19 @@ * @param array Input array. If fields are already specified AND $update is not set, values are not set in output array. * @return array Output array (For when the copying operation needs to get the information instead of updating the info) */ - function fixCopyAfterDuplFields($table,$uid,$prevUid,$update, $newData=array()) { + function fixCopyAfterDuplFields($table, $uid, $prevUid, $update, $newData = array()) { global $TCA; - if ($TCA[$table] && $TCA[$table]['ctrl']['copyAfterDuplFields']) { + if ($TCA[$table] && $TCA[$table]['ctrl']['copyAfterDuplFields']) { t3lib_div::loadTCA($table); - $prevData=$this->recordInfo($table,$prevUid,'*'); + $prevData = $this->recordInfo($table, $prevUid, '*'); - $theFields = t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['copyAfterDuplFields'],1); + $theFields = t3lib_div::trimExplode(',', $TCA[$table]['ctrl']['copyAfterDuplFields'], 1); foreach ($theFields as $field) { - if ($TCA[$table]['columns'][$field] && ($update || !isset($newData[$field]))) { + if ($TCA[$table]['columns'][$field] && ($update || !isset($newData[$field]))) { - $newData[$field]=$prevData[$field]; + $newData[$field] = $prevData[$field]; } } - if ($update && count($newData)) { + if ($update && count($newData)) { - $this->updateDB($table,$uid,$newData); + $this->updateDB($table, $uid, $newData); } } return $newData; @@ -6334,8 +6339,8 @@ * @param string Table name * @return array Array of fieldnames that are either "group" or "file" types. */ - function extFileFields($table) { + function extFileFields($table) { - $listArr=array(); + $listArr = array(); t3lib_div::loadTCA($table); if (isset($GLOBALS['TCA'][$table]['columns'])) { foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $configArr) { @@ -6343,7 +6348,7 @@ ($configArr['config']['internal_type'] == 'file' || $configArr['config']['internal_type'] == 'file_reference')) { $listArr[] = $field; - } + } } } return $listArr; @@ -6355,15 +6360,15 @@ * @param string Table name * @return array Array of fieldnames */ - function getUniqueFields($table) { + function getUniqueFields($table) { - $listArr=array(); + $listArr = array(); t3lib_div::loadTCA($table); if ($GLOBALS['TCA'][$table]['columns']) { foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $configArr) { - if ($configArr['config']['type']==='input') { + if ($configArr['config']['type'] === 'input') { - $evalCodesArray = t3lib_div::trimExplode(',',$configArr['config']['eval'],1); + $evalCodesArray = t3lib_div::trimExplode(',', $configArr['config']['eval'], 1); - if (in_array('uniqueInPid',$evalCodesArray) || in_array('unique',$evalCodesArray)) { + if (in_array('uniqueInPid', $evalCodesArray) || in_array('unique', $evalCodesArray)) { - $listArr[]=$field; + $listArr[] = $field; } } } @@ -6377,8 +6382,8 @@ * @param array config array for TCA/columns field * @return boolean True if DB reference field (group/db or select with foreign-table) */ - function isReferenceField($conf) { + function isReferenceField($conf) { - return ($conf['type']=='group' && $conf['internal_type']=='db' || $conf['type']=='select' && $conf['foreign_table']); + return ($conf['type'] == 'group' && $conf['internal_type'] == 'db' || $conf['type'] == 'select' && $conf['foreign_table']); } /** @@ -6390,14 +6395,19 @@ */ function getInlineFieldType($conf) { if ($conf['type'] == 'inline' && $conf['foreign_table']) { - if ($conf['foreign_field']) - return 'field'; // the reference to the parent is stored in a pointer field in the child record + if ($conf['foreign_field']) { + return 'field'; + } // the reference to the parent is stored in a pointer field in the child record elseif ($conf['MM']) - return 'mm'; // regular MM intermediate table is used to store data + { + return 'mm'; + } // regular MM intermediate table is used to store data else - return 'list'; // an item list (separated by comma) is stored (like select type is doing) + { + return 'list'; + } // an item list (separated by comma) is stored (like select type is doing) } - return false; + return FALSE; } @@ -6412,27 +6422,27 @@ * @param string Previous title we checked for (in previous recursion) * @return string The field value, possibly appended with a "copy label" */ - function getCopyHeader($table,$pid,$field,$value,$count,$prevTitle='') { + function getCopyHeader($table, $pid, $field, $value, $count, $prevTitle = '') { global $TCA; // Set title value to check for: - if ($count) { + if ($count) { - $checkTitle = $value.rtrim(' '.sprintf($this->prependLabel($table),$count)); + $checkTitle = $value . rtrim(' ' . sprintf($this->prependLabel($table), $count)); - } else { + } else { $checkTitle = $value; } // Do check: - if ($prevTitle != $checkTitle || $count<100) { + if ($prevTitle != $checkTitle || $count < 100) { $rowCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows( 'uid', $table, 'pid=' . intval($pid) . - ' AND ' . $field . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($checkTitle, $table) . - $this->deleteClause($table) + ' AND ' . $field . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($checkTitle, $table) . + $this->deleteClause($table) ); if ($rowCount) { - return $this->getCopyHeader($table,$pid,$field,$value,$count+1,$checkTitle); + return $this->getCopyHeader($table, $pid, $field, $value, $count + 1, $checkTitle); } } @@ -6447,12 +6457,12 @@ * @return string Label to append, containing "%s" for the number * @see getCopyHeader() */ - function prependLabel($table) { + function prependLabel($table) { global $TCA; - if (is_object($GLOBALS['LANG'])) { + if (is_object($GLOBALS['LANG'])) { $label = $GLOBALS['LANG']->sL($TCA[$table]['ctrl']['prependAtCopy']); } else { - list($label) = explode('|',$TCA[$table]['ctrl']['prependAtCopy']); + list($label) = explode('|', $TCA[$table]['ctrl']['prependAtCopy']); } return $label; } @@ -6464,22 +6474,22 @@ * @param integer "Destination pid" : If the value is >= 0 it's just returned directly (through intval() though) but if the value is <0 then the method looks up the record with the uid equal to abs($pid) (positive number) and returns the PID of that record! The idea is that negative numbers point to the record AFTER WHICH the position is supposed to be! * @return integer */ - function resolvePid($table,$pid) { + function resolvePid($table, $pid) { global $TCA; $pid = intval($pid); - if ($pid < 0) { + if ($pid < 0) { - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid', $table, 'uid='.abs($pid)); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid', $table, 'uid=' . abs($pid)); $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); // Look, if the record UID happens to be an offline record. If so, find its live version. Offline uids will be used when a page is versionized as "branch" so this is when we must correct - otherwise a pid of "-1" and a wrong sort-row number is returned which we don't want. - if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table,abs($pid),'pid')) { + if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table, abs($pid), 'pid')) { $row = $lookForLiveVersion; } $pid = intval($row['pid']); - } elseif ($this->BE_USER->workspace!==0 && $TCA[$table]['ctrl']['versioning_followPages']) { // PID points to page, the workspace is an offline space and the table follows page during versioning: This means we must check if the PID page has a version in the workspace with swapmode set to 0 (zero = page+content) and if so, change the pid to the uid of that version. + } elseif ($this->BE_USER->workspace !== 0 && $TCA[$table]['ctrl']['versioning_followPages']) { // PID points to page, the workspace is an offline space and the table follows page during versioning: This means we must check if the PID page has a version in the workspace with swapmode set to 0 (zero = page+content) and if so, change the pid to the uid of that version. - if ($WSdestPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, 'pages', $pid, 'uid,t3ver_swapmode')) { // Looks for workspace version of page. + if ($WSdestPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, 'pages', $pid, 'uid,t3ver_swapmode')) { // Looks for workspace version of page. - if ($WSdestPage['t3ver_swapmode']==0) { // if swapmode is zero, then change pid value. + if ($WSdestPage['t3ver_swapmode'] == 0) { // if swapmode is zero, then change pid value. $pid = $WSdestPage['uid']; } } @@ -6494,10 +6504,10 @@ * @param string The value to fix * @return string Clean name */ - function clearPrefixFromValue($table,$value) { + function clearPrefixFromValue($table, $value) { global $TCA; - $regex = '/'.sprintf(quotemeta($this->prependLabel($table)),'[0-9]*').'$/'; + $regex = '/' . sprintf(quotemeta($this->prependLabel($table)), '[0-9]*') . '$/'; - return @preg_replace($regex,'',$value); + return @preg_replace($regex, '', $value); } /** @@ -6509,22 +6519,22 @@ * @param string Function, eg. "deleteAll" which will delete all files listed. * @return void */ - function extFileFunctions($table,$field,$filelist,$func) { + function extFileFunctions($table, $field, $filelist, $func) { global $TCA; t3lib_div::loadTCA($table); $uploadFolder = $TCA[$table]['columns'][$field]['config']['uploadfolder']; if ($uploadFolder && trim($filelist) && $TCA[$table]['columns'][$field]['config']['internal_type'] == 'file') { $uploadPath = $this->destPathFromUploadFolder($uploadFolder); - $fileArray = explode(',',$filelist); + $fileArray = explode(',', $filelist); foreach ($fileArray as $theFile) { - $theFile=trim($theFile); + $theFile = trim($theFile); - if ($theFile) { + if ($theFile) { - switch($func) { + switch ($func) { case 'deleteAll': - if (@is_file($uploadPath.'/'.$theFile)) { + if (@is_file($uploadPath . '/' . $theFile)) { - unlink ($uploadPath.'/'.$theFile); + unlink($uploadPath . '/' . $theFile); } else { - $this->log($table,0,3,0,100,"Delete: Referenced file that was supposed to be deleted together with it's record didn't exist"); + $this->log($table, 0, 3, 0, 100, "Delete: Referenced file that was supposed to be deleted together with it's record didn't exist"); } break; } @@ -6539,9 +6549,9 @@ * @param string List of page integers * @return boolean Return true, if permission granted */ - function noRecordsFromUnallowedTables($inList) { + function noRecordsFromUnallowedTables($inList) { $inList = trim($this->rmComma(trim($inList))); - if ($inList && !$this->admin) { + if ($inList && !$this->admin) { foreach (array_keys($GLOBALS['TCA']) as $table) { $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows( 'uid', @@ -6567,25 +6577,15 @@ function isRecordCopied($table, $uid) { // If the record was copied: if (isset($this->copyMappingArray[$table][$uid])) { - return true; + return TRUE; // If the record is the result of a copy action: } elseif (isset($this->copyMappingArray[$table]) && in_array($uid, array_values($this->copyMappingArray[$table]))) { - return true; + return TRUE; } - return false; + return FALSE; } - - - - - - - - - - /****************************** * * Clearing cache @@ -6601,37 +6601,37 @@ * @param integer UID of updated / inserted record * @return void */ - function clear_cache($table,$uid) { + function clear_cache($table, $uid) { global $TCA, $TYPO3_CONF_VARS; $uid = intval($uid); $pageUid = 0; - if (is_array($TCA[$table]) && $uid > 0) { + if (is_array($TCA[$table]) && $uid > 0) { // Get Page TSconfig relavant: - list($tscPID) = t3lib_BEfunc::getTSCpid($table,$uid,''); + list($tscPID) = t3lib_BEfunc::getTSCpid($table, $uid, ''); $TSConfig = $this->getTCEMAIN_TSconfig($tscPID); - if (!$TSConfig['clearCache_disable']) { + if (!$TSConfig['clearCache_disable']) { // If table is "pages": - if (t3lib_extMgm::isLoaded('cms')) { + if (t3lib_extMgm::isLoaded('cms')) { $list_cache = array(); - if ($table === 'pages' || $table === 'pages_language_overlay') { + if ($table === 'pages' || $table === 'pages_language_overlay') { - if($table === 'pages_language_overlay') { + if ($table === 'pages_language_overlay') { - $pageUid = $this->getPID($table,$uid); + $pageUid = $this->getPID($table, $uid); } else { $pageUid = $uid; } // Builds list of pages on the SAME level as this page (siblings) $res_tmp = $GLOBALS['TYPO3_DB']->exec_SELECTquery( - 'A.pid AS pid, B.uid AS uid', - 'pages A, pages B', + 'A.pid AS pid, B.uid AS uid', + 'pages A, pages B', - 'A.uid='.intval($pageUid).' AND B.pid=A.pid AND B.deleted=0' + 'A.uid=' . intval($pageUid) . ' AND B.pid=A.pid AND B.deleted=0' - ); + ); $pid_tmp = 0; while ($row_tmp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp)) { @@ -6639,13 +6639,13 @@ $pid_tmp = $row_tmp['pid']; // Add children as well: - if ($TSConfig['clearCache_pageSiblingChildren']) { + if ($TSConfig['clearCache_pageSiblingChildren']) { $res_tmp2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery( - 'uid', - 'pages', + 'uid', + 'pages', - 'pid='.intval($row_tmp['uid']).' AND deleted=0' + 'pid=' . intval($row_tmp['uid']) . ' AND deleted=0' - ); + ); - while ($row_tmp2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp2)) { + while ($row_tmp2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp2)) { $list_cache[] = $row_tmp2['uid']; } $GLOBALS['TYPO3_DB']->sql_free_result($res_tmp2); @@ -6657,31 +6657,31 @@ $list_cache[] = $pid_tmp; // Add grand-parent as well: - if ($TSConfig['clearCache_pageGrandParent']) { + if ($TSConfig['clearCache_pageGrandParent']) { $res_tmp = $GLOBALS['TYPO3_DB']->exec_SELECTquery( - 'pid', - 'pages', + 'pid', + 'pages', - 'uid='.intval($pid_tmp) + 'uid=' . intval($pid_tmp) - ); + ); - if ($row_tmp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp)) { + if ($row_tmp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp)) { $list_cache[] = $row_tmp['pid']; } } - } else { // For other tables than "pages", delete cache for the records "parent page". + } else { // For other tables than "pages", delete cache for the records "parent page". - $list_cache[] = $pageUid = intval($this->getPID($table,$uid)); + $list_cache[] = $pageUid = intval($this->getPID($table, $uid)); } // Call pre-processing function for clearing of cache for page ids: - if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'])) { + if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'])) { - foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'] as $funcName) { + foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'] as $funcName) { $_params = array('pageIdArray' => &$list_cache, 'table' => $table, 'uid' => $uid, 'functionID' => 'clear_cache()'); // Returns the array of ids to clear, false if nothing should be cleared! Never an empty array! - t3lib_div::callUserFunction($funcName,$_params,$this); + t3lib_div::callUserFunction($funcName, $_params, $this); } } // Delete cache for selected pages: - if (is_array($list_cache)) { + if (is_array($list_cache)) { if (TYPO3_UseCachingFramework) { $pageCache = $GLOBALS['typo3CacheManager']->getCache( 'cache_pages' @@ -6696,8 +6696,8 @@ $pageSectionCache->flushByTag('pageId_' . $pageId); } } else { - $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages','page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')'); + $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)) . ')'); - $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')'); + $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)) . ')'); } } @@ -6705,19 +6705,19 @@ } // Clear cache for pages entered in TSconfig: - if ($TSConfig['clearCacheCmd']) { + if ($TSConfig['clearCacheCmd']) { - $Commands = t3lib_div::trimExplode(',',strtolower($TSConfig['clearCacheCmd']),1); + $Commands = t3lib_div::trimExplode(',', strtolower($TSConfig['clearCacheCmd']), 1); $Commands = array_unique($Commands); - foreach($Commands as $cmdPart) { + foreach ($Commands as $cmdPart) { $this->clear_cacheCmd($cmdPart); } } // Call post processing function for clear-cache: - if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'])) { + if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'])) { - $_params = array('table' => $table,'uid' => $uid,'uid_page' => $pageUid,'TSConfig' => $TSConfig); + $_params = array('table' => $table, 'uid' => $uid, 'uid_page' => $pageUid, 'TSConfig' => $TSConfig); - foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'] as $_funcRef) { + foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'] as $_funcRef) { - t3lib_div::callUserFunction($_funcRef,$_params,$this); + t3lib_div::callUserFunction($_funcRef, $_params, $this); } } } @@ -6744,13 +6744,13 @@ * $cacheCmd='all': * * - cache_md5params: Clearing this table would destroy all simulateStatic - * URLs, simulates file name and RDCT redirects. + * URLs, simulates file name and RDCT redirects. * - cache_imagesizes: Clearing this table would cause a lot of unneeded - * Imagemagick calls because the size informations have + * Imagemagick calls because the size informations have - * to be fetched again after clearing. + * to be fetched again after clearing. * - cache_extensions: Clearing this table would make the extension manager - * unusable until a new extension list is fetched from + * unusable until a new extension list is fetched from - * the TER. + * the TER. * * @param string the cache command, see above description * @return void @@ -6761,14 +6761,14 @@ $this->BE_USER->writelog(3, 1, 0, 0, 'User %s has cleared the cache (cacheCmd=%s)', array($this->BE_USER->user['username'], $cacheCmd)); // Clear cache for either ALL pages or ALL tables! - switch($cacheCmd) { + switch ($cacheCmd) { case 'pages': - if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.pages')) { + if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.pages')) { $this->internal_clearPageCache(); } break; case 'all': - if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) { + if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) { // Clear all caching framework caches if it is initialized: // (it could be disabled by initialized by an extension) @@ -6777,11 +6777,11 @@ } if (TYPO3_UseCachingFramework) { - if (t3lib_extMgm::isLoaded('cms')) { + if (t3lib_extMgm::isLoaded('cms')) { $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_treelist'); } } else { - if (t3lib_extMgm::isLoaded('cms')) { + if (t3lib_extMgm::isLoaded('cms')) { $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_treelist'); $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_pagesection'); } @@ -6790,9 +6790,9 @@ } // Clearing additional cache tables: - if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'])) { + if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'])) { - foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'] as $tableName) { + foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'] as $tableName) { - if (!preg_match('/[^[:alnum:]_]/',$tableName) && substr($tableName,-5)=='cache') { + if (!preg_match('/[^[:alnum:]_]/', $tableName) && substr($tableName, -5) == 'cache') { $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery($tableName); } else { throw new RuntimeException( @@ -6815,17 +6815,17 @@ } // Clear cache for a page ID! - if (t3lib_div::testInt($cacheCmd)) { + if (t3lib_div::testInt($cacheCmd)) { - if (t3lib_extMgm::isLoaded('cms')) { + if (t3lib_extMgm::isLoaded('cms')) { $list_cache = array($cacheCmd); // Call pre-processing function for clearing of cache for page ids: - if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'])) { + if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'])) { - foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'] as $funcName) { + foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'] as $funcName) { $_params = array('pageIdArray' => &$list_cache, 'cacheCmd' => $cacheCmd, 'functionID' => 'clear_cacheCmd()'); // Returns the array of ids to clear, false if nothing should be cleared! Never an empty array! - t3lib_div::callUserFunction($funcName,$_params,$this); + t3lib_div::callUserFunction($funcName, $_params, $this); } } @@ -6845,8 +6845,8 @@ $pageSectionCache->flushByTag('pageId_' . (int) $pageId); } } else { - $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages','page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')'); + $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)) . ')'); - $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')'); // Originally, cache_pagesection was not cleared with cache_pages! + $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)) . ')'); // Originally, cache_pagesection was not cleared with cache_pages! } } @@ -6854,27 +6854,15 @@ } // Call post processing function for clear-cache: - if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'])) { + if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'])) { - $_params = array('cacheCmd'=>$cacheCmd); + $_params = array('cacheCmd' => $cacheCmd); - foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'] as $_funcRef) { + foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'] as $_funcRef) { - t3lib_div::callUserFunction($_funcRef,$_params,$this); + t3lib_div::callUserFunction($_funcRef, $_params, $this); } } } - - - - - - - - - - - - /***************************** * * Logging @@ -6897,12 +6885,16 @@ * @return integer Log entry UID * @see class.t3lib_userauthgroup.php */ - function log($table,$recuid,$action,$recpid,$error,$details,$details_nr=-1,$data=array(),$event_pid=-1,$NEWid='') { + function log($table, $recuid, $action, $recpid, $error, $details, $details_nr = -1, $data = array(), $event_pid = -1, $NEWid = '') { - if ($this->enableLogging) { + if ($this->enableLogging) { - $type=1; // Type value for tce_db.php + $type = 1; // Type value for tce_db.php - if (!$this->storeLogMessages) {$details='';} - if ($error>0) $this->errorLog[] = '['.$type.'.'.$action.'.'.$details_nr.']: '.$details; + if (!$this->storeLogMessages) { + $details = ''; + } + if ($error > 0) { + $this->errorLog[] = '[' . $type . '.' . $action . '.' . $details_nr . ']: ' . $details; + } - return $this->BE_USER->writelog($type,$action,$error,$details_nr,$details,$data,$table,$recuid,$recpid,$event_pid,$NEWid); + return $this->BE_USER->writelog($type, $action, $error, $details_nr, $details, $data, $table, $recuid, $recpid, $event_pid, $NEWid); } } @@ -6914,8 +6906,8 @@ * @return integer Log entry UID * @see log() */ - function newlog($message, $error=0) { + function newlog($message, $error = 0) { - return $this->log('',0,0,0,$error,'[newlog()] '.$message,-1); + return $this->log('', 0, 0, 0, $error, '[newlog()] ' . $message, -1); } /** @@ -6929,13 +6921,13 @@ * @return integer Log entry UID * @see log() */ - function newlog2($message,$table,$uid,$pid=FALSE,$error=0) { + function newlog2($message, $table, $uid, $pid = FALSE, $error = 0) { - if ($pid===FALSE) { + if ($pid === FALSE) { $propArr = $this->getRecordProperties($table, $uid); $pid = $propArr['pid']; } - return $this->log($table,$uid,0,0,$error,$message,-1,array(),$this->eventPid($table,$uid,$pid)); + return $this->log($table, $uid, 0, 0, $error, $message, -1, array(), $this->eventPid($table, $uid, $pid)); } /** @@ -6944,21 +6936,21 @@ * @param string Redirect URL (for creating link in message) * @return void (Will exit on error) */ - function printLogErrorMessages($redirect) { + function printLogErrorMessages($redirect) { $res_log = $GLOBALS['TYPO3_DB']->exec_SELECTquery( - '*', - 'sys_log', + '*', + 'sys_log', - 'type=1 AND userid='.intval($this->BE_USER->user['uid']).' AND tstamp='.intval($GLOBALS['EXEC_TIME']).' AND error!=0' + 'type=1 AND userid=' . intval($this->BE_USER->user['uid']) . ' AND tstamp=' . intval($GLOBALS['EXEC_TIME']) . ' AND error!=0' - ); + ); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_log)) { $log_data = unserialize($row['log_data']); $msg = $row['error'] . ': ' . sprintf($row['details'], $log_data[0], $log_data[1], $log_data[2], $log_data[3], $log_data[4]); $flashMessage = t3lib_div::makeInstance('t3lib_FlashMessage', - $msg, - '', - t3lib_FlashMessage::ERROR, - TRUE + $msg, + '', + t3lib_FlashMessage::ERROR, + TRUE ); t3lib_FlashMessageQueue::addMessage($flashMessage); } @@ -6982,12 +6974,12 @@ $GLOBALS['typo3CacheManager']->getCache('cache_pages')->flush(); } } else { - if (t3lib_extMgm::isLoaded('cms')) { + if (t3lib_extMgm::isLoaded('cms')) { if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageCacheToExternalFiles']) { - $cacheDir = PATH_site.'typo3temp/cache_pages'; + $cacheDir = PATH_site . 'typo3temp/cache_pages'; - $retVal = t3lib_div::rmdir($cacheDir,true); + $retVal = t3lib_div::rmdir($cacheDir, TRUE); if (!$retVal) { - t3lib_div::sysLog('Could not remove page cache files in "'.$cacheDir.'"','Core/t3lib_tcemain',2); + t3lib_div::sysLog('Could not remove page cache files in "' . $cacheDir . '"', 'Core/t3lib_tcemain', 2); } } $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_pages'); @@ -7006,7 +6998,7 @@ * @return array Updated field array */ function insertUpdateDB_preprocessBasedOnFieldType($table, $fieldArray) { - global $TCA; + global $TCA; $result = $fieldArray; foreach ($fieldArray as $field => $value) { @@ -7017,7 +7009,7 @@ $result[$field] = count(t3lib_div::trimExplode(',', $value, TRUE)); } } - break; + break; } } return $result; @@ -7073,8 +7065,7 @@ } - -if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tcemain.php']) { +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tcemain.php']) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tcemain.php']); }