PageRenderTime 96ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 2ms

/t3lib/class.t3lib_tcemain.php

https://bitbucket.org/linxpinx/mercurial
PHP | 7828 lines | 4516 code | 1002 blank | 2310 comment | 1277 complexity | e84bb17658713a4bc785c78204eec1be MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
  6. * All rights reserved
  7. *
  8. * This script is part of the TYPO3 project. The TYPO3 project is
  9. * free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * The GNU General Public License can be found at
  15. * http://www.gnu.org/copyleft/gpl.html.
  16. * A copy is found in the textfile GPL.txt and important notices to the license
  17. * from the author is found in LICENSE.txt distributed with these scripts.
  18. *
  19. *
  20. * This script is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * This copyright notice MUST APPEAR in all copies of the script!
  26. ***************************************************************/
  27. /**
  28. * Contains the TYPO3 Core Engine
  29. *
  30. * $Id: class.t3lib_tcemain.php 8157 2010-07-11 12:45:16Z psychomieze $
  31. * Revised for TYPO3 3.9 October 2005 by Kasper Skaarhoj
  32. *
  33. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  34. */
  35. /**
  36. * [CLASS/FUNCTION INDEX of SCRIPT]
  37. *
  38. *
  39. *
  40. * 242: class t3lib_TCEmain
  41. * 367: function start($data,$cmd,$altUserObject='')
  42. * 406: function setMirror($mirror)
  43. * 431: function setDefaultsFromUserTS($userTS)
  44. * 454: function process_uploads($postFiles)
  45. * 492: function process_uploads_traverseArray(&$outputArr,$inputArr,$keyToSet)
  46. *
  47. * SECTION: PROCESSING DATA
  48. * 528: function process_datamap()
  49. * 886: function placeholderShadowing($table,$id)
  50. * 929: function fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$realPid,$status,$tscPID)
  51. *
  52. * SECTION: Evaluation of input values
  53. * 1152: function checkValue($table,$field,$value,$id,$status,$realPid,$tscPID)
  54. * 1212: function checkValue_SW($res,$value,$tcaFieldConf,$table,$id,$curValue,$status,$realPid,$recFID,$field,$uploadedFiles,$tscPID)
  55. * 1261: function checkValue_input($res,$value,$tcaFieldConf,$PP,$field='')
  56. * 1299: function checkValue_check($res,$value,$tcaFieldConf,$PP)
  57. * 1322: function checkValue_radio($res,$value,$tcaFieldConf,$PP)
  58. * 1348: function checkValue_group_select($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field)
  59. * 1458: function checkValue_group_select_file($valueArray,$tcaFieldConf,$curValue,$uploadedFileArray,$status,$table,$id,$recFID)
  60. * 1632: function checkValue_flex($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field)
  61. * 1709: function checkValue_flexArray2Xml($array, $addPrologue=FALSE)
  62. * 1721: function _DELETE_FLEX_FORMdata(&$valueArrayToRemoveFrom,$deleteCMDS)
  63. * 1743: function _MOVE_FLEX_FORMdata(&$valueArrayToMoveIn, $moveCMDS, $direction)
  64. * 1783: function checkValue_inline($res,$value,$tcaFieldConf,$PP,$field)
  65. * 1825: function checkValue_checkMax($tcaFieldConf, $valueArray)
  66. *
  67. * SECTION: Helper functions for evaluation functions.
  68. * 1877: function getUnique($table,$field,$value,$id,$newPid=0)
  69. * 1915: function checkValue_input_Eval($value,$evalArray,$is_in)
  70. * 2012: function checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,$type,$currentTable)
  71. * 2058: function checkValue_group_select_explodeSelectGroupValue($value)
  72. * 2082: function checkValue_flex_procInData($dataPart,$dataPart_current,$uploadedFiles,$dataStructArray,$pParams,$callBackFunc='')
  73. * 2121: function checkValue_flex_procInData_travDS(&$dataValues,$dataValues_current,$uploadedFiles,$DSelements,$pParams,$callBackFunc,$structurePath)
  74. *
  75. * SECTION: PROCESSING COMMANDS
  76. * 2267: function process_cmdmap()
  77. *
  78. * SECTION: Cmd: Copying
  79. * 2407: function copyRecord($table,$uid,$destPid,$first=0,$overrideValues=array(),$excludeFields='')
  80. * 2529: function copyPages($uid,$destPid)
  81. * 2583: function copySpecificPage($uid,$destPid,$copyTablesArray,$first=0)
  82. * 2617: function copyRecord_raw($table,$uid,$pid,$overrideArray=array())
  83. * 2681: function rawCopyPageContent($old_pid,$new_pid,$copyTablesArray)
  84. * 2705: function insertNewCopyVersion($table,$fieldArray,$realPid)
  85. * 2757: function copyRecord_procBasedOnFieldType($table,$uid,$field,$value,$row,$conf,$realDestPid)
  86. * 2836: function copyRecord_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2)
  87. * 2864: function copyRecord_procFilesRefs($conf, $uid, $value)
  88. *
  89. * SECTION: Cmd: Moving, Localizing
  90. * 2933: function moveRecord($table,$uid,$destPid)
  91. * 3128: function moveRecord_procFields($table,$uid,$destPid)
  92. * 3148: function moveRecord_procBasedOnFieldType($table,$uid,$destPid,$field,$value,$conf)
  93. * 3182: function localize($table,$uid,$language)
  94. *
  95. * SECTION: Cmd: Deleting
  96. * 3296: function deleteAction($table, $id)
  97. * 3343: function deleteEl($table, $uid, $noRecordCheck=FALSE, $forceHardDelete=FALSE)
  98. * 3360: function deleteVersionsForRecord($table, $uid, $forceHardDelete)
  99. * 3382: function undeleteRecord($table,$uid)
  100. * 3399: function deleteRecord($table,$uid, $noRecordCheck=FALSE, $forceHardDelete=FALSE,$undeleteRecord=FALSE)
  101. * 3512: function deleteRecord_flexFormCallBack($dsArr, $dataValue, $PA, $structurePath, &$pObj)
  102. * 3539: function deletePages($uid,$force=FALSE,$forceHardDelete=FALSE)
  103. * 3567: function deleteSpecificPage($uid,$forceHardDelete=FALSE)
  104. * 3592: function canDeletePage($uid)
  105. * 3619: function cannotDeleteRecord($table,$id)
  106. * 3638: function deleteRecord_procFields($table, $uid, $undeleteRecord = false)
  107. * 3661: function deleteRecord_procBasedOnFieldType($table, $uid, $field, $value, $conf, $undeleteRecord = false)
  108. *
  109. * SECTION: Cmd: Versioning
  110. * 3722: function versionizeRecord($table,$id,$label,$delete=FALSE,$versionizeTree=-1)
  111. * 3798: function versionizePages($uid,$label,$versionizeTree)
  112. * 3861: function version_swap($table,$id,$swapWith,$swapIntoWS=0)
  113. * 4032: function version_clearWSID($table,$id)
  114. * 4066: function version_setStage($table,$id,$stageId,$comment='')
  115. *
  116. * SECTION: Cmd: Helper functions
  117. * 4111: function remapListedDBRecords()
  118. * 4192: function remapListedDBRecords_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2)
  119. * 4219: function remapListedDBRecords_procDBRefs($conf, $value, $MM_localUid, $table)
  120. * 4265: function remapListedDBRecords_procInline($conf, $value, $uid, $table)
  121. *
  122. * SECTION: Access control / Checking functions
  123. * 4308: function checkModifyAccessList($table)
  124. * 4320: function isRecordInWebMount($table,$id)
  125. * 4334: function isInWebMount($pid)
  126. * 4348: function checkRecordUpdateAccess($table,$id)
  127. * 4372: function checkRecordInsertAccess($insertTable,$pid,$action=1)
  128. * 4406: function isTableAllowedForThisPage($page_uid, $checkTable)
  129. * 4439: function doesRecordExist($table,$id,$perms)
  130. * 4504: function doesRecordExist_pageLookUp($id, $perms)
  131. * 4530: function doesBranchExist($inList,$pid,$perms,$recurse)
  132. * 4564: function tableReadOnly($table)
  133. * 4576: function tableAdminOnly($table)
  134. * 4590: function destNotInsideSelf($dest,$id)
  135. * 4622: function getExcludeListArray()
  136. * 4645: function doesPageHaveUnallowedTables($page_uid,$doktype)
  137. *
  138. * SECTION: Information lookup
  139. * 4694: function pageInfo($id,$field)
  140. * 4714: function recordInfo($table,$id,$fieldList)
  141. * 4735: function getRecordProperties($table,$id,$noWSOL=FALSE)
  142. * 4751: function getRecordPropertiesFromRow($table,$row)
  143. *
  144. * SECTION: Storing data to Database Layer
  145. * 4794: function updateDB($table,$id,$fieldArray)
  146. * 4846: function insertDB($table,$id,$fieldArray,$newVersion=FALSE,$suggestedUid=0,$dontSetNewIdIndex=FALSE)
  147. * 4919: function checkStoredRecord($table,$id,$fieldArray,$action)
  148. * 4956: function setHistory($table,$id,$logId)
  149. * 4989: function clearHistory($maxAgeSeconds=604800,$table)
  150. * 5003: function updateRefIndex($table,$id)
  151. *
  152. * SECTION: Misc functions
  153. * 5035: function getSortNumber($table,$uid,$pid)
  154. * 5108: function resorting($table,$pid,$sortRow, $return_SortNumber_After_This_Uid)
  155. * 5139: function setTSconfigPermissions($fieldArray,$TSConfig_p)
  156. * 5156: function newFieldArray($table)
  157. * 5188: function addDefaultPermittedLanguageIfNotSet($table,&$incomingFieldArray)
  158. * 5212: function overrideFieldArray($table,$data)
  159. * 5228: function compareFieldArrayWithCurrentAndUnset($table,$id,$fieldArray)
  160. * 5274: function assemblePermissions($string)
  161. * 5291: function rmComma($input)
  162. * 5301: function convNumEntityToByteValue($input)
  163. * 5323: function destPathFromUploadFolder($folder)
  164. * 5333: function deleteClause($table)
  165. * 5349: function getTCEMAIN_TSconfig($tscPID)
  166. * 5364: function getTableEntries($table,$TSconfig)
  167. * 5377: function getPID($table,$uid)
  168. * 5390: function dbAnalysisStoreExec()
  169. * 5406: function removeRegisteredFiles()
  170. * 5418: function removeCacheFiles()
  171. * 5432: function int_pageTreeInfo($CPtable,$pid,$counter, $rootID)
  172. * 5453: function compileAdminTables()
  173. * 5470: function fixUniqueInPid($table,$uid)
  174. * 5506: function fixCopyAfterDuplFields($table,$uid,$prevUid,$update, $newData=array())
  175. * 5531: function extFileFields($table)
  176. * 5552: function getUniqueFields($table)
  177. * 5577: function isReferenceField($conf)
  178. * 5588: function getInlineFieldType($conf)
  179. * 5611: function getCopyHeader($table,$pid,$field,$value,$count,$prevTitle='')
  180. * 5640: function prependLabel($table)
  181. * 5657: function resolvePid($table,$pid)
  182. * 5687: function clearPrefixFromValue($table,$value)
  183. * 5702: function extFileFunctions($table,$field,$filelist,$func)
  184. * 5732: function noRecordsFromUnallowedTables($inList)
  185. * 5758: function notifyStageChange($stat,$stageId,$table,$id,$comment)
  186. * 5853: function notifyStageChange_getEmails($listOfUsers,$noTablePrefix=FALSE)
  187. *
  188. * SECTION: Clearing cache
  189. * 5899: function clear_cache($table,$uid)
  190. * 6009: function clear_cacheCmd($cacheCmd)
  191. *
  192. * SECTION: Logging
  193. * 6113: function log($table,$recuid,$action,$recpid,$error,$details,$details_nr=-1,$data=array(),$event_pid=-1,$NEWid='')
  194. * 6130: function newlog($message, $error=0)
  195. * 6140: function printLogErrorMessages($redirect)
  196. *
  197. * SECTION: Internal (do not use outside Core!)
  198. * 6202: function internal_clearPageCache()
  199. *
  200. * TOTAL FUNCTIONS: 126
  201. * (This index is automatically created/updated by the extension "extdeveval")
  202. *
  203. */
  204. /**
  205. * This is the TYPO3 Core Engine class for manipulation of the database
  206. * This class is used by eg. the tce_db.php script which provides an the interface for POST forms to this class.
  207. *
  208. * Dependencies:
  209. * - $GLOBALS['TCA'] must exist
  210. * - $GLOBALS['LANG'] must exist
  211. *
  212. * tce_db.php for further comments and SYNTAX! Also see document 'TYPO3 Core API' for details.
  213. *
  214. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  215. * @package TYPO3
  216. * @subpackage t3lib
  217. */
  218. class t3lib_TCEmain {
  219. // *********************
  220. // Public variables you can configure before using the class:
  221. // *********************
  222. var $storeLogMessages = TRUE; // Boolean: If true, the default log-messages will be stored. This should not be necessary if the locallang-file for the log-display is properly configured. So disabling this will just save some database-space as the default messages are not saved.
  223. var $enableLogging = TRUE; // Boolean: If true, actions are logged to sys_log.
  224. var $reverseOrder = FALSE; // Boolean: If true, the datamap array is reversed in the order, which is a nice thing if you're creating a whole new bunch of records.
  225. var $checkSimilar = TRUE; // Boolean: If true, only fields which are different from the database values are saved! In fact, if a whole input array is similar, it's not saved then.
  226. var $stripslashes_values = TRUE; // Boolean: If true, incoming values in the data-array have their slashes stripped. ALWAYS SET THIS TO ZERO and supply an unescaped data array instead. This switch may totally disappear in future versions of this class!
  227. var $checkStoredRecords = TRUE; // Boolean: This will read the record after having updated or inserted it. If anything is not properly submitted an error is written to the log. This feature consumes extra time by selecting records
  228. var $checkStoredRecords_loose = TRUE; // Boolean: If set, values '' and 0 will equal each other when the stored records are checked.
  229. var $deleteTree = FALSE; // Boolean. If this is set, then a page is deleted by deleting the whole branch under it (user must have deletepermissions to it all). If not set, then the page is deleted ONLY if it has no branch
  230. var $neverHideAtCopy = FALSE; // Boolean. If set, then the 'hideAtCopy' flag for tables will be ignored.
  231. var $dontProcessTransformations = FALSE; // Boolean: If set, then transformations are NOT performed on the input.
  232. var $clear_flexFormData_vDEFbase = FALSE; // Boolean: If set, .vDEFbase values are unset in flexforms.
  233. var $updateModeL10NdiffData = TRUE; // Boolean/Mixed: TRUE: (traditional) Updates when record is saved. For flexforms, updates if change is made to the localized value. FALSE: Will not update anything. "FORCE_FFUPD" (string): Like TRUE, but will force update to the FlexForm Field
  234. var $updateModeL10NdiffDataClear = FALSE; // Boolean: If true, the translation diff. fields will in fact be reset so that they indicate that all needs to change again! It's meant as the opposite of declaring the record translated.
  235. var $bypassWorkspaceRestrictions = FALSE; // Boolean: If true, workspace restrictions are bypassed on edit an create actions (process_datamap()). YOU MUST KNOW what you do if you use this feature!
  236. var $bypassFileHandling = FALSE; // Boolean: If true, file handling of attached files (addition, deletion etc) is bypassed - the value is saved straight away. YOU MUST KNOW what you are doing with this feature!
  237. var $bypassAccessCheckForRecords = FALSE; // Boolean: If true, access check, check for deleted etc. for records is bypassed. YOU MUST KNOW what you are doing if you use this feature!
  238. var $copyWhichTables = '*'; // String. Comma-list. This list of tables decides which tables will be copied. If empty then none will. If '*' then all will (that the user has permission to of course)
  239. var $generalComment = ''; // General comment, eg. for staging in workspaces.
  240. var $copyTree = 0; // Integer. If 0 then branch is NOT copied. If 1 then pages on the 1st level is copied. If 2 then pages on the second level is copied ... and so on
  241. 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)
  242. 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!
  243. 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.
  244. var $alternativeFilePath = array(); // Array [filename]=alternative_filepath: Same as alternativeFileName but with relative path to the file
  245. 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.
  246. 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)
  247. 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.
  248. // *********************
  249. // Internal variables (mapping arrays) which can be used (read-only) from outside
  250. // *********************
  251. var $autoVersionIdMap = Array(); // Contains mapping of auto-versionized records.
  252. 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
  253. var $substNEWwithIDs_table = Array(); // Like $substNEWwithIDs, but where each old "NEW..." id is mapped to the table it was from.
  254. var $newRelatedIDs = Array(); // Holds the tables and there the ids of newly created child records from IRRE
  255. var $copyMappingArray_merged = Array(); // This array is the sum of all copying operations in this class. May be READ from outside, thus partly public.
  256. var $copiedFileMap = Array(); // A map between input file name and final destination for files being attached to records.
  257. 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.
  258. var $errorLog = Array(); // Errors are collected in this variable.
  259. var $accumulateForNotifEmail = Array(); // For accumulating information about workspace stages raised on elements so a single mail is sent as notification.
  260. // *********************
  261. // Internal Variables, do not touch.
  262. // *********************
  263. // Variables set in init() function:
  264. /**
  265. * The user-object the script uses. If not set from outside, this is set to the current global $BE_USER.
  266. *
  267. * @var t3lib_beUserAuth
  268. */
  269. var $BE_USER;
  270. var $userid; // will be set to uid of be_user executing this script
  271. var $username; // will be set to username of be_user executing this script
  272. var $admin; // will be set if user is admin
  273. var $defaultPermissions = array( // Can be overridden from $TYPO3_CONF_VARS
  274. 'user' => 'show,edit,delete,new,editcontent',
  275. 'group' => 'show,edit,new,editcontent',
  276. 'everybody' => ''
  277. );
  278. var $exclude_array; // The list of <table>-<fields> that cannot be edited by user. This is compiled from TCA/exclude-flag combined with non_exclude_fields for the user.
  279. var $datamap = Array(); // Set with incoming data array
  280. var $cmdmap = Array(); // Set with incoming cmd array
  281. // Internal static:
  282. var $pMap = Array( // Permission mapping
  283. 'show' => 1, // 1st bit
  284. 'edit' => 2, // 2nd bit
  285. 'delete' => 4, // 3rd bit
  286. 'new' => 8, // 4th bit
  287. 'editcontent' => 16 // 5th bit
  288. );
  289. var $sortIntervals = 256; // Integer: The interval between sorting numbers used with tables with a 'sorting' field defined. Min 1
  290. // Internal caching arrays
  291. var $recUpdateAccessCache = Array(); // Used by function checkRecordUpdateAccess() to store whether a record is updateable or not.
  292. var $recInsertAccessCache = Array(); // User by function checkRecordInsertAccess() to store whether a record can be inserted on a page id
  293. var $isRecordInWebMount_Cache=array(); // Caching array for check of whether records are in a webmount
  294. var $isInWebMount_Cache=array(); // Caching array for page ids in webmounts
  295. var $cachedTSconfig = array(); // Caching for collecting TSconfig for page ids
  296. var $pageCache = Array(); // Used for caching page records in pageInfo()
  297. var $checkWorkspaceCache = Array(); // Array caching workspace access for BE_USER
  298. // Other arrays:
  299. var $dbAnalysisStore=array(); // For accumulation of MM relations that must be written after new records are created.
  300. var $removeFilesStore=array(); // For accumulation of files which must be deleted after processing of all input content
  301. var $uploadedFileArray = array(); // Uploaded files, set by process_uploads()
  302. var $registerDBList=array(); // Used for tracking references that might need correction after operations
  303. var $registerDBPids=array(); // Used for tracking references that might need correction in pid field after operations (e.g. IRRE)
  304. 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.
  305. var $remapStack = array(); // array used for remapping uids and values at the end of process_datamap
  306. var $remapStackRecords = array(); // array used for remapping uids and values at the end of process_datamap (e.g. $remapStackRecords[<table>][<uid>] = <index in $remapStack>)
  307. var $updateRefIndexStack = array(); // array used for additional calls to $this->updateRefIndex
  308. var $callFromImpExp = false; // tells, that this TCEmain was called from tx_impext - this variable is set by tx_impexp
  309. var $newIndexMap = array(); // Array for new flexform index mapping
  310. // Various
  311. /**
  312. * basicFileFunctions object
  313. *
  314. * @var t3lib_basicFileFunctions
  315. */
  316. var $fileFunc; // For "singleTon" file-manipulation object
  317. var $checkValue_currentRecord=array(); // Set to "currentRecord" during checking of values.
  318. var $autoVersioningUpdate = FALSE; // A signal flag used to tell file processing that autoversioning has happend and hence certain action should be applied.
  319. protected $disableDeleteClause = false; // Disable delete clause
  320. protected $checkModifyAccessListHookObjects;
  321. /**
  322. * Initializing.
  323. * For details, see 'TYPO3 Core API' document.
  324. * This function does not start the processing of data, but merely initializes the object
  325. *
  326. * @param array Data to be modified or inserted in the database
  327. * @param array Commands to copy, move, delete, localize, versionize records.
  328. * @param object An alternative userobject you can set instead of the default, which is $GLOBALS['BE_USER']
  329. * @return void
  330. */
  331. function start($data,$cmd,$altUserObject='') {
  332. // Initializing BE_USER
  333. $this->BE_USER = is_object($altUserObject) ? $altUserObject : $GLOBALS['BE_USER'];
  334. $this->userid = $this->BE_USER->user['uid'];
  335. $this->username = $this->BE_USER->user['username'];
  336. $this->admin = $this->BE_USER->user['admin'];
  337. if ($this->BE_USER->uc['recursiveDelete']) {
  338. $this->deleteTree = 1;
  339. }
  340. if ($GLOBALS['TYPO3_CONF_VARS']['BE']['explicitConfirmationOfTranslation'] && $this->updateModeL10NdiffData===TRUE) {
  341. $this->updateModeL10NdiffData = FALSE;
  342. }
  343. // Initializing default permissions for pages
  344. $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'];
  345. if (isset($defaultPermissions['user'])) {$this->defaultPermissions['user'] = $defaultPermissions['user'];}
  346. if (isset($defaultPermissions['group'])) {$this->defaultPermissions['group'] = $defaultPermissions['group'];}
  347. if (isset($defaultPermissions['everybody'])) {$this->defaultPermissions['everybody'] = $defaultPermissions['everybody'];}
  348. // generates the excludelist, based on TCA/exclude-flag and non_exclude_fields for the user:
  349. $this->exclude_array = $this->admin ? array() : $this->getExcludeListArray();
  350. // Setting the data and cmd arrays
  351. if (is_array($data)) {
  352. reset($data);
  353. $this->datamap = $data;
  354. }
  355. if (is_array($cmd)) {
  356. reset($cmd);
  357. $this->cmdmap = $cmd;
  358. }
  359. }
  360. /**
  361. * Function that can mirror input values in datamap-array to other uid numbers.
  362. * Example: $mirror[table][11] = '22,33' will look for content in $this->datamap[table][11] and copy it to $this->datamap[table][22] and $this->datamap[table][33]
  363. *
  364. * @param array This array has the syntax $mirror[table_name][uid] = [list of uids to copy data-value TO!]
  365. * @return void
  366. */
  367. function setMirror($mirror) {
  368. if (is_array($mirror)) {
  369. foreach ($mirror as $table => $uid_array) {
  370. if (isset($this->datamap[$table])) {
  371. reset($uid_array);
  372. foreach ($uid_array as $id => $uidList) {
  373. if (isset($this->datamap[$table][$id])) {
  374. $theIdsInArray = t3lib_div::trimExplode(',',$uidList,1);
  375. foreach ($theIdsInArray as $copyToUid) {
  376. $this->datamap[$table][$copyToUid] = $this->datamap[$table][$id];
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. }
  384. /**
  385. * Initializes default values coming from User TSconfig
  386. *
  387. * @param array User TSconfig array
  388. * @return void
  389. */
  390. function setDefaultsFromUserTS($userTS) {
  391. global $TCA;
  392. if (is_array($userTS)) {
  393. foreach($userTS as $k => $v) {
  394. $k = substr($k,0,-1);
  395. if ($k && is_array($v) && isset($TCA[$k])) {
  396. if (is_array($this->defaultValues[$k])) {
  397. $this->defaultValues[$k] = array_merge($this->defaultValues[$k],$v);
  398. } else {
  399. $this->defaultValues[$k] = $v;
  400. }
  401. }
  402. }
  403. }
  404. }
  405. /**
  406. * Processing of uploaded files.
  407. * It turns out that some versions of PHP arranges submitted data for files different if sent in an array. This function will unify this so the internal array $this->uploadedFileArray will always contain files arranged in the same structure.
  408. *
  409. * @param array $_FILES array
  410. * @return void
  411. */
  412. function process_uploads($postFiles) {
  413. if (is_array($postFiles)) {
  414. // Editing frozen:
  415. if ($this->BE_USER->workspace!==0 && $this->BE_USER->workspaceRec['freeze']) {
  416. $this->newlog('All editing in this workspace has been frozen!',1);
  417. return FALSE;
  418. }
  419. reset($postFiles);
  420. $subA = current($postFiles);
  421. if (is_array($subA)) {
  422. if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
  423. // Initialize the uploadedFilesArray:
  424. $this->uploadedFileArray=array();
  425. // For each entry:
  426. foreach($subA as $key => $values) {
  427. $this->process_uploads_traverseArray($this->uploadedFileArray,$values,$key);
  428. }
  429. } else {
  430. $this->uploadedFileArray=$subA;
  431. }
  432. }
  433. }
  434. }
  435. /**
  436. * Traverse the upload array if needed to rearrange values.
  437. *
  438. * @param array $this->uploadedFileArray passed by reference
  439. * @param array Input array ($_FILES parts)
  440. * @param string The current $_FILES array key to set on the outermost level.
  441. * @return void
  442. * @access private
  443. * @see process_uploads()
  444. */
  445. function process_uploads_traverseArray(&$outputArr,$inputArr,$keyToSet) {
  446. if (is_array($inputArr)) {
  447. foreach($inputArr as $key => $value) {
  448. $this->process_uploads_traverseArray($outputArr[$key],$inputArr[$key],$keyToSet);
  449. }
  450. } else {
  451. $outputArr[$keyToSet]=$inputArr;
  452. }
  453. }
  454. /*********************************************
  455. *
  456. * HOOKS
  457. *
  458. *********************************************/
  459. /**
  460. * Hook: processDatamap_afterDatabaseOperations
  461. * (calls $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);)
  462. *
  463. * Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
  464. * but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
  465. *
  466. * @param object $hookObjectsArr: (reference) Array with hook objects
  467. * @param string $status: (reference) Status of the current operation, 'new' or 'update
  468. * @param string $table: (refrence) The table currently processing data for
  469. * @param string $id: (reference) The record uid currently processing data for, [integer] or [string] (like 'NEW...')
  470. * @param array $fieldArray: (reference) The field array of a record
  471. * @return void
  472. */
  473. function hook_processDatamap_afterDatabaseOperations(&$hookObjectsArr, &$status, &$table, &$id, &$fieldArray) {
  474. // Process hook directly:
  475. if (!isset($this->remapStackRecords[$table][$id])) {
  476. foreach($hookObjectsArr as $hookObj) {
  477. if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) {
  478. $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);
  479. }
  480. }
  481. // 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:
  482. } else {
  483. $this->remapStackRecords[$table][$id]['processDatamap_afterDatabaseOperations'] = array(
  484. 'status' => $status,
  485. 'fieldArray' => $fieldArray,
  486. 'hookObjectsArr' => $hookObjectsArr,
  487. );
  488. }
  489. }
  490. /**
  491. * Gets the 'checkModifyAccessList' hook objects.
  492. * The first call initializes the accordant objects.
  493. *
  494. * @return array The 'checkModifyAccessList' hook objects (if any)
  495. */
  496. protected function getCheckModifyAccessListHookObjects() {
  497. if (!isset($this->checkModifyAccessListHookObjects)) {
  498. $this->checkModifyAccessListHookObjects = array();
  499. if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'])) {
  500. foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'] as $classData) {
  501. $hookObject = t3lib_div::getUserObj($classData);
  502. if(!($hookObject instanceof t3lib_TCEmain_checkModifyAccessListHook)) {
  503. throw new UnexpectedValueException('$hookObject must implement interface t3lib_TCEmain_checkModifyAccessListHook', 1251892472);
  504. }
  505. $this->checkModifyAccessListHookObjects[] = $hookObject;
  506. }
  507. }
  508. }
  509. return $this->checkModifyAccessListHookObjects;
  510. }
  511. /*********************************************
  512. *
  513. * PROCESSING DATA
  514. *
  515. *********************************************/
  516. /**
  517. * Processing the data-array
  518. * Call this function to process the data-array set by start()
  519. *
  520. * @return void
  521. */
  522. function process_datamap() {
  523. global $TCA, $TYPO3_CONF_VARS;
  524. // Keep versionized(!) relations here locally:
  525. $registerDBList = array();
  526. // Editing frozen:
  527. if ($this->BE_USER->workspace!==0 && $this->BE_USER->workspaceRec['freeze']) {
  528. $this->newlog('All editing in this workspace has been frozen!',1);
  529. return FALSE;
  530. }
  531. // First prepare user defined objects (if any) for hooks which extend this function:
  532. $hookObjectsArr = array();
  533. if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'])) {
  534. foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] as $classRef) {
  535. $hookObjectsArr[] = t3lib_div::getUserObj($classRef);
  536. }
  537. }
  538. // 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.
  539. $orderOfTables = Array();
  540. if (isset($this->datamap['pages'])) { // Set pages first.
  541. $orderOfTables[]='pages';
  542. }
  543. $orderOfTables = array_unique(array_merge($orderOfTables, array_keys($this->datamap)));
  544. // Process the tables...
  545. foreach($orderOfTables as $table) {
  546. /* Check if
  547. - table is set in $TCA,
  548. - table is NOT readOnly
  549. - the table is set with content in the data-array (if not, there's nothing to process...)
  550. - permissions for tableaccess OK
  551. */
  552. $modifyAccessList = $this->checkModifyAccessList($table);
  553. if (!$modifyAccessList) {
  554. $id = 0;
  555. $this->log($table,$id,2,0,1,"Attempt to modify table '%s' without permission",1,array($table));
  556. }
  557. if (isset($TCA[$table]) && !$this->tableReadOnly($table) && is_array($this->datamap[$table]) && $modifyAccessList) {
  558. if ($this->reverseOrder) {
  559. $this->datamap[$table] = array_reverse($this->datamap[$table], 1);
  560. }
  561. // For each record from the table, do:
  562. // $id is the record uid, may be a string if new records...
  563. // $incomingFieldArray is the array of fields
  564. foreach($this->datamap[$table] as $id => $incomingFieldArray) {
  565. if (is_array($incomingFieldArray)) {
  566. // Hook: processDatamap_preProcessFieldArray
  567. foreach($hookObjectsArr as $hookObj) {
  568. if (method_exists($hookObj, 'processDatamap_preProcessFieldArray')) {
  569. $hookObj->processDatamap_preProcessFieldArray($incomingFieldArray, $table, $id, $this);
  570. }
  571. }
  572. // ******************************
  573. // Checking access to the record
  574. // ******************************
  575. $createNewVersion = FALSE;
  576. $recordAccess = FALSE;
  577. $old_pid_value = '';
  578. $this->autoVersioningUpdate = FALSE;
  579. if (!t3lib_div::testInt($id)) { // Is it a new record? (Then Id is a string)
  580. $fieldArray = $this->newFieldArray($table); // Get a fieldArray with default values
  581. if (isset($incomingFieldArray['pid'])) { // A pid must be set for new records.
  582. // $value = the pid
  583. $pid_value = $incomingFieldArray['pid'];
  584. // Checking and finding numerical pid, it may be a string-reference to another value
  585. $OK = 1;
  586. if (strstr($pid_value,'NEW')) { // If a NEW... id
  587. if (substr($pid_value,0,1)=='-') {$negFlag=-1;$pid_value=substr($pid_value,1);} else {$negFlag=1;}
  588. 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.
  589. $old_pid_value = $pid_value;
  590. $pid_value=intval($negFlag*$this->substNEWwithIDs[$pid_value]);
  591. } else {$OK = 0;} // If not found in the substArray we must stop the process...
  592. } 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.
  593. if ($WSdestPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, 'pages', $pid_value, 'uid,t3ver_swapmode')) { // Looks for workspace version of page.
  594. if ($WSdestPage['t3ver_swapmode']==0) { // if swapmode is zero, then change pid value.
  595. $pid_value = $WSdestPage['uid'];
  596. }
  597. }
  598. }
  599. $pid_value = intval($pid_value);
  600. // The $pid_value is now the numerical pid at this point
  601. if ($OK) {
  602. $sortRow = $TCA[$table]['ctrl']['sortby'];
  603. if ($pid_value>=0) { // Points to a page on which to insert the element, possibly in the top of the page
  604. if ($sortRow) { // If this table is sorted we better find the top sorting number
  605. $fieldArray[$sortRow] = $this->getSortNumber($table,0,$pid_value);
  606. }
  607. $fieldArray['pid'] = $pid_value; // The numerical pid is inserted in the data array
  608. } else { // points to another record before ifself
  609. if ($sortRow) { // If this table is sorted we better find the top sorting number
  610. $tempArray=$this->getSortNumber($table,0,$pid_value); // Because $pid_value is < 0, getSortNumber returns an array
  611. $fieldArray['pid'] = $tempArray['pid'];
  612. $fieldArray[$sortRow] = $tempArray['sortNumber'];
  613. } else { // Here we fetch the PID of the record that we point to...
  614. $tempdata = $this->recordInfo($table,abs($pid_value),'pid');
  615. $fieldArray['pid']=$tempdata['pid'];
  616. }
  617. }
  618. }
  619. }
  620. $theRealPid = $fieldArray['pid'];
  621. // Now, check if we may insert records on this pid.
  622. if ($theRealPid>=0) {
  623. $recordAccess = $this->checkRecordInsertAccess($table,$theRealPid); // Checks if records can be inserted on this $pid.
  624. if ($recordAccess) {
  625. $this->addDefaultPermittedLanguageIfNotSet($table,$incomingFieldArray);
  626. $recordAccess = $this->BE_USER->recordEditAccessInternals($table,$incomingFieldArray,TRUE);
  627. if (!$recordAccess) {
  628. $this->newlog("recordEditAccessInternals() check failed. [".$this->BE_USER->errorMsg."]",1);
  629. } elseif(!$this->bypassWorkspaceRestrictions) {
  630. // Workspace related processing:
  631. 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
  632. if ($res<0) {
  633. $recordAccess = FALSE;
  634. $this->newlog('Stage for versioning root point and users access level did not allow for editing',1);
  635. }
  636. } else { // So, if no live records were allowed, we have to create a new version of this record:
  637. if ($TCA[$table]['ctrl']['versioningWS']) {
  638. $createNewVersion = TRUE;
  639. } else {
  640. $recordAccess = FALSE;
  641. $this->newlog('Record could not be created in this workspace in this branch',1);
  642. }
  643. }
  644. }
  645. }
  646. } else {
  647. debug('Internal ERROR: pid should not be less than zero!');
  648. }
  649. $status = 'new'; // Yes new record, change $record_status to 'insert'
  650. } else { // Nope... $id is a number
  651. $fieldArray = array();
  652. $recordAccess = $this->checkRecordUpdateAccess($table, $id, $incomingFieldArray, $hookObjectsArr);
  653. if (!$recordAccess) {
  654. $propArr = $this->getRecordProperties($table,$id);
  655. $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']);
  656. } else { // Next check of the record permissions (internals)
  657. $recordAccess = $this->BE_USER->recordEditAccessInternals($table,$id);
  658. if (!$recordAccess) {
  659. $propArr = $this->getRecordProperties($table,$id);
  660. $this->newlog("recordEditAccessInternals() check failed. [".$this->BE_USER->errorMsg."]",1);
  661. } else { // Here we fetch the PID of the record that we point to...
  662. $tempdata = $this->recordInfo($table,$id,'pid'.($TCA[$table]['ctrl']['versioningWS']?',t3ver_wsid,t3ver_stage':''));
  663. $theRealPid = $tempdata['pid'];
  664. // Use the new id of the versionized record we're trying to write to:
  665. // (This record is a child record of a parent and has already been versionized.)
  666. if ($this->autoVersionIdMap[$table][$id]) {
  667. // For the reason that creating a new version of this record, automatically
  668. // created related child records (e.g. "IRRE"), update the accordant field:
  669. $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
  670. // Use the new id of the copied/versionized record:
  671. $id = $this->autoVersionIdMap[$table][$id];
  672. $recordAccess = TRUE;
  673. $this->autoVersioningUpdate = TRUE;
  674. // Checking access in case of offline workspace:
  675. } elseif (!$this->bypassWorkspaceRestrictions && $errorCode = $this->BE_USER->workspaceCannotEditRecord($table,$tempdata)) {
  676. $recordAccess = FALSE; // Versioning is required and it must be offline version!
  677. // 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.
  678. if ($this->BE_USER->workspaceAllowAutoCreation($table,$id,$theRealPid)) {
  679. $tce = t3lib_div::makeInstance('t3lib_TCEmain');
  680. /* @var $tce t3lib_TCEmain */
  681. $tce->stripslashes_values = 0;
  682. // Setting up command for creating a new version of the record:
  683. $cmd = array();
  684. $cmd[$table][$id]['version'] = array(
  685. 'action' => 'new',
  686. 'treeLevels' => -1, // Default is to create a version of the individual records... element versioning that is.
  687. 'label' => 'Auto-created for WS #'.$this->BE_USER->workspace
  688. );
  689. $tce->start(array(),$cmd);
  690. $tce->process_cmdmap();
  691. $this->errorLog = array_merge($this->errorLog,$tce->errorLog);
  692. // If copying was successful, share the new uids (also of related children):
  693. if ($tce->copyMappingArray[$table][$id]) {
  694. foreach ($tce->copyMappingArray as $origTable => $origIdArray) {
  695. foreach ($origIdArray as $origId => $newId) {
  696. $this->uploadedFileArray[$origTable][$newId] = $this->uploadedFileArray[$origTable][$origId];
  697. $this->autoVersionIdMap[$origTable][$origId] = $newId;
  698. }
  699. }
  700. $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...
  701. // Update registerDBList, that holds the copied relations to child records:
  702. $registerDBList = array_merge($registerDBList, $tce->registerDBList);
  703. // For the reason that creating a new version of this record, automatically
  704. // created related child records (e.g. "IRRE"), update the accordant field:
  705. $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
  706. // Use the new id of the copied/versionized record:
  707. $id = $this->autoVersionIdMap[$table][$id];
  708. $recordAccess = TRUE;
  709. $this->autoVersioningUpdate = TRUE;
  710. } else $this->newlog("Could not be edited in offline workspace in the branch where found (failure state: '".$errorCode."'). Auto-creation of version failed!",1);
  711. } 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);
  712. }
  713. }
  714. }
  715. $status = 'update'; // the default is 'update'
  716. }
  717. // If access was granted above, proceed to create or update record:
  718. if ($recordAccess) {
  719. 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.
  720. $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
  721. if ($status=='new' && $table=='pages' && is_array($TSConfig['permissions.'])) {
  722. $fieldArray = $this->setTSconfigPermissions($fieldArray,$TSConfig['permissions.']);
  723. }
  724. if ($createNewVersion) {
  725. $newVersion_placeholderFieldArray = $fieldArray;
  726. }
  727. // Processing of all fields in incomingFieldArray and setting them in $fieldArray
  728. $fieldArray = $this->fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$theRealPid,$status,$tscPID);
  729. // NOTICE! All manipulation beyond this point bypasses both "excludeFields" AND possible "MM" relations / file uploads to field!
  730. // Forcing some values unto field array:
  731. $fieldArray = $this->overrideFieldArray($table,$fieldArray); // NOTICE: This overriding is potentially dangerous; permissions per field is not checked!!!
  732. if ($createNewVersion) {
  733. $newVersion_placeholderFieldArray = $this->overrideFieldArray($table,$newVersion_placeholderFieldArray);
  734. }
  735. // Setting system fields
  736. if ($status=='new') {
  737. if ($TCA[$table]['ctrl']['crdate']) {
  738. $fieldArray[$TCA[$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
  739. if ($createNewVersion) {
  740. $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
  741. }
  742. }
  743. if ($TCA[$table]['ctrl']['cruser_id']) {
  744. $fieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid;
  745. if ($createNewVersion) $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid;
  746. }
  747. } elseif ($this->checkSimilar) { // Removing fields which are equal to the current value:
  748. $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table,$id,$fieldArray);
  749. }
  750. if ($TCA[$table]['ctrl']['tstamp'] && count($fieldArray)) {
  751. $fieldArray[$TCA[$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
  752. if ($createNewVersion) {
  753. $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
  754. }
  755. }
  756. if ($TCA[$table]['ctrl']['versioningWS']) {
  757. $fieldArray['t3ver_stage'] = 0;
  758. }
  759. // Hook: processDatamap_postProcessFieldArray
  760. foreach($hookObjectsArr as $hookObj) {
  761. if (method_exists($hookObj, 'processDatamap_postProcessFieldArray')) {
  762. $hookObj->processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, $this);
  763. }
  764. }
  765. // Performing insert/update. If fieldArray has been unset by some userfunction (see hook above), don't do anything
  766. // Kasper: Unsetting the fieldArray is dangerous; MM relations might be saved already and files could have been uploaded that are now "lost"
  767. if (is_array($fieldArray)) {
  768. if ($status=='new') {
  769. if ($createNewVersion) { // This creates a new version of the record with online placeholder and offline version
  770. $versioningType = $table==='pages' ? $this->BE_USER->workspaceVersioningTypeGetClosest(t3lib_div::intInRange($TYPO3_CONF_VARS['BE']['newPagesVersioningType'],-1,1)) : -1;
  771. if ($this->BE_USER->workspaceVersioningTypeAccess($versioningType)) {
  772. $newVersion_placeholderFieldArray['t3ver_label'] = 'INITIAL PLACEHOLDER';
  773. $newVersion_placeholderFieldArray['t3ver_state'] = 1; // Setting placeholder state value for temporary record
  774. $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER->workspace; // Setting workspace - only so display of place holders can filter out those from other workspaces.
  775. $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['label']] = '[PLACEHOLDER, WS#'.$this->BE_USER->workspace.']';
  776. $this->insertDB($table,$id,$newVersion_placeholderFieldArray,FALSE); // Saving placeholder as 'original'
  777. // For the actual new offline version, set versioning values to point to placeholder:
  778. $fieldArray['pid'] = -1;
  779. $fieldArray['t3ver_oid'] = $this->substNEWwithIDs[$id];
  780. $fieldArray['t3ver_id'] = 1;
  781. $fieldArray['t3ver_state'] = -1; // Setting placeholder state value for version (so it can know it is currently a new version...)
  782. $fieldArray['t3ver_label'] = 'First draft version';
  783. $fieldArray['t3ver_wsid'] = $this->BE_USER->workspace;
  784. if ($table==='pages') { // Swap mode set to "branch" so we can build branches for pages.
  785. $fieldArray['t3ver_swapmode'] = $versioningType;
  786. }
  787. $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!
  788. if ($phShadowId) {
  789. $this->placeholderShadowing($table,$phShadowId);
  790. // Hold auto-versionized ids of placeholders:
  791. $this->autoVersionIdMap[$table][$this->substNEWwithIDs[$id]] = $phShadowId;
  792. }
  793. } else $this->newlog('Versioning type "'.$versioningType.'" was not allowed, so could not create new record.',1);
  794. } else {
  795. $this->insertDB($table,$id,$fieldArray,FALSE,$incomingFieldArray['uid']);
  796. }
  797. } else {
  798. $this->updateDB($table,$id,$fieldArray);
  799. $this->placeholderShadowing($table,$id);
  800. }
  801. }
  802. /*
  803. * Hook: processDatamap_afterDatabaseOperations
  804. *
  805. * Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
  806. * but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
  807. */
  808. $this->hook_processDatamap_afterDatabaseOperations($hookObjectsArr, $status, $table, $id, $fieldArray);
  809. } // if ($recordAccess) {
  810. } // if (is_array($incomingFieldArray)) {
  811. }
  812. }
  813. }
  814. // Process the stack of relations to remap/correct
  815. $this->processRemapStack();
  816. $this->dbAnalysisStoreExec();
  817. $this->removeRegisteredFiles();
  818. /*
  819. * Hook: processDatamap_afterAllOperations
  820. *
  821. * Note: When this hook gets called, all operations on the submitted data have been finished.
  822. */
  823. foreach($hookObjectsArr as $hookObj) {
  824. if (method_exists($hookObj, 'processDatamap_afterAllOperations')) {
  825. $hookObj->processDatamap_afterAllOperations($this);
  826. }
  827. }
  828. }
  829. /**
  830. * Fix shadowing of data in case we are editing a offline version of a live "New" placeholder record:
  831. *
  832. * @param string Table name
  833. * @param integer Record uid
  834. * @return void
  835. */
  836. function placeholderShadowing($table,$id) {
  837. global $TCA;
  838. t3lib_div::loadTCA($table);
  839. if ($liveRec = t3lib_BEf

Large files files are truncated, but you can click here to view the full file