PageRenderTime 67ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/t3lib/class.t3lib_befunc.php

https://github.com/andreaswolf/typo3-tceforms
PHP | 4629 lines | 2692 code | 403 blank | 1534 comment | 672 complexity | 8efb3461d8131f897237c20fb7866bc0 MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause, LGPL-3.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-2011 Kasper Skårhøj (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. * Standard functions available for the TYPO3 backend.
  29. * You are encouraged to use this class in your own applications (Backend Modules)
  30. *
  31. * Call ALL methods without making an object!
  32. * Eg. to get a page-record 51 do this: 't3lib_BEfunc::getRecord('pages',51)'
  33. *
  34. * $Id$
  35. * Usage counts are based on search 22/2 2003 through whole backend source of typo3/
  36. * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
  37. * XHTML compliant
  38. *
  39. * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  40. */
  41. /**
  42. * [CLASS/FUNCTION INDEX of SCRIPT]
  43. *
  44. *
  45. *
  46. * 185: class t3lib_BEfunc
  47. *
  48. * SECTION: SQL-related, selecting records, searching
  49. * 206: function deleteClause($table,$tableAlias='')
  50. * 230: function getRecord($table,$uid,$fields='*',$where='',$useDeleteClause=true)
  51. * 253: function getRecordWSOL($table,$uid,$fields='*',$where='',$useDeleteClause=true)
  52. * 286: function getRecordRaw($table,$where='',$fields='*')
  53. * 309: function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='',$useDeleteClause=true)
  54. * 342: function searchQuery($searchWords,$fields,$table='')
  55. * 357: function listQuery($field,$value)
  56. * 369: function splitTable_Uid($str)
  57. * 384: function getSQLselectableList($in_list,$tablename,$default_tablename)
  58. * 412: function BEenableFields($table,$inv=0)
  59. *
  60. * SECTION: SQL-related, DEPRECATED functions
  61. * 476: function mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='')
  62. * 498: function DBcompileInsert($table,$fields_values)
  63. * 512: function DBcompileUpdate($table,$where,$fields_values)
  64. *
  65. * SECTION: Page tree, TCA related
  66. * 542: function BEgetRootLine($uid,$clause='',$workspaceOL=FALSE)
  67. * 598: function openPageTree($pid,$clearExpansion)
  68. * 643: function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0)
  69. * 686: function getExcludeFields()
  70. * 716: function getExplicitAuthFieldValues()
  71. * 787: function getSystemLanguages()
  72. * 812: function readPageAccess($id,$perms_clause)
  73. * 843: function getTCAtypes($table,$rec,$useFieldNameAsKey=0)
  74. * 896: function getTCAtypeValue($table,$rec)
  75. * 919: function getSpecConfParts($str, $defaultExtras)
  76. * 950: function getSpecConfParametersFromArray($pArr)
  77. * 978: function getFlexFormDS($conf,$row,$table,$fieldName='',$WSOL=TRUE)
  78. *
  79. * SECTION: Caching related
  80. * 1105: function storeHash($hash,$data,$ident)
  81. * 1125: function getHash($hash)
  82. *
  83. * SECTION: TypoScript related
  84. * 1161: function getPagesTSconfig($id,$rootLine='',$returnPartArray=0)
  85. * 1217: function updatePagesTSconfig($id,$pageTS,$TSconfPrefix,$impParams='')
  86. * 1272: function implodeTSParams($p,$k='')
  87. *
  88. * SECTION: Users / Groups related
  89. * 1309: function getUserNames($fields='username,usergroup,usergroup_cached_list,uid',$where='')
  90. * 1327: function getGroupNames($fields='title,uid', $where='')
  91. * 1344: function getListGroupNames($fields='title,uid')
  92. * 1363: function blindUserNames($usernames,$groupArray,$excludeBlindedFlag=0)
  93. * 1396: function blindGroupNames($groups,$groupArray,$excludeBlindedFlag=0)
  94. *
  95. * SECTION: Output related
  96. * 1437: function daysUntil($tstamp)
  97. * 1449: function date($tstamp)
  98. * 1460: function datetime($value)
  99. * 1472: function time($value)
  100. * 1488: function calcAge($seconds,$labels = 'min|hrs|days|yrs')
  101. * 1514: function dateTimeAge($tstamp,$prefix=1,$date='')
  102. * 1532: function titleAttrib($content='',$hsc=0)
  103. * 1545: function titleAltAttrib($content)
  104. * 1569: function thumbCode($row,$table,$field,$backPath,$thumbScript='',$uploaddir=NULL,$abs=0,$tparams='',$size='')
  105. * 1637: function getThumbNail($thumbScript,$theFile,$tparams='',$size='')
  106. * 1654: function titleAttribForPages($row,$perms_clause='',$includeAttrib=1)
  107. * 1716: function getRecordIconAltText($row,$table='pages')
  108. * 1758: function getLabelFromItemlist($table,$col,$key)
  109. * 1784: function getItemLabel($table,$col,$printAllWrap='')
  110. * 1809: function getRecordTitle($table,$row,$prep=0)
  111. * 1847: function getProcessedValue($table,$col,$value,$fixed_lgd_chars=0,$defaultPassthrough=0,$noRecordLookup=FALSE,$uid=0)
  112. * 2009: function getProcessedValueExtra($table,$fN,$fV,$fixed_lgd_chars=0,$uid=0)
  113. * 2033: function getFileIcon($ext)
  114. * 2047: function getCommonSelectFields($table,$prefix='')
  115. * 2090: function makeConfigForm($configArray,$defaults,$dataPrefix)
  116. *
  117. * SECTION: Backend Modules API functions
  118. * 2165: function helpTextIcon($table,$field,$BACK_PATH,$force=0)
  119. * 2187: function helpText($table,$field,$BACK_PATH,$styleAttrib='')
  120. * 2239: function cshItem($table,$field,$BACK_PATH,$wrap='',$onlyIconMode=FALSE, $styleAttrib='')
  121. * 2277: function editOnClick($params,$backPath='',$requestUri='')
  122. * 2296: function viewOnClick($id,$backPath='',$rootLine='',$anchor='',$altUrl='',$additionalGetVars='',$switchFocus=TRUE)
  123. * 2328: function getModTSconfig($id,$TSref)
  124. * 2349: function getFuncMenu($mainParams,$elementName,$currentValue,$menuItems,$script='',$addparams='')
  125. * 2392: function getFuncCheck($mainParams,$elementName,$currentValue,$script='',$addparams='',$tagParams='')
  126. * 2417: function getFuncInput($mainParams,$elementName,$currentValue,$size=10,$script="",$addparams="")
  127. * 2438: function unsetMenuItems($modTSconfig,$itemArray,$TSref)
  128. * 2461: function getSetUpdateSignal($set='')
  129. * 2512: function getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
  130. *
  131. * SECTION: Core
  132. * 2585: function compilePreviewKeyword($getVarsStr, $beUserUid, $ttl=172800)
  133. * 2613: function lockRecords($table='',$uid=0,$pid=0)
  134. * 2642: function isRecordLocked($table,$uid)
  135. * 2682: function exec_foreign_table_where_query($fieldValue,$field='',$TSconfig=array(),$prefix='')
  136. * 2763: function getTCEFORM_TSconfig($table,$row)
  137. * 2814: function getTSconfig_pidValue($table,$uid,$pid)
  138. * 2844: function getPidForModTSconfig($table,$uid,$pid)
  139. * 2860: function getTSCpid($table,$uid,$pid)
  140. * 2876: function firstDomainRecord($rootLine)
  141. * 2898: function getDomainStartPage($domain, $path='')
  142. * 2928: function RTEsetup($RTEprop,$table,$field,$type='')
  143. * 2947: function &RTEgetObj()
  144. * 2986: function &softRefParserObj($spKey)
  145. * 3018: function explodeSoftRefParserList($parserList)
  146. * 3050: function isModuleSetInTBE_MODULES($modName)
  147. * 3073: function referenceCount($table,$ref,$msg='')
  148. *
  149. * SECTION: Workspaces / Versioning
  150. * 3132: function selectVersionsOfRecord($table, $uid, $fields='*', $workspace=0)
  151. * 3180: function fixVersioningPid($table,&$rr,$ignoreWorkspaceMatch=FALSE)
  152. * 3220: function workspaceOL($table,&$row,$wsid=-99)
  153. * 3268: function getWorkspaceVersionOfRecord($workspace, $table, $uid, $fields='*')
  154. * 3297: function getLiveVersionOfRecord($table,$uid,$fields='*')
  155. * 3319: function isPidInVersionizedBranch($pid, $table='',$returnStage=FALSE)
  156. * 3342: function versioningPlaceholderClause($table)
  157. * 3356: function countVersionsOfRecordsOnPage($workspace,$pageId, $allTables=FALSE)
  158. * 3391: function wsMapId($table,$uid)
  159. *
  160. * SECTION: Miscellaneous
  161. * 3421: function typo3PrintError($header,$text,$js='',$head=1)
  162. * 3465: function TYPO3_copyRightNotice()
  163. * 3489: function displayWarningMessages()
  164. * 3546: function getPathType_web_nonweb($path)
  165. * 3558: function ADMCMD_previewCmds($pageinfo)
  166. * 3580: function processParams($params)
  167. * 3606: function getListOfBackendModules($name,$perms_clause,$backPath='',$script='index.php')
  168. *
  169. * TOTAL FUNCTIONS: 99
  170. * (This index is automatically created/updated by the extension "extdeveval")
  171. *
  172. */
  173. /**
  174. * Standard functions available for the TYPO3 backend.
  175. * Don't instantiate - call functions with "t3lib_BEfunc::" prefixed the function name.
  176. *
  177. * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  178. * @package TYPO3
  179. * @subpackage t3lib
  180. */
  181. final class t3lib_BEfunc {
  182. /*******************************************
  183. *
  184. * SQL-related, selecting records, searching
  185. *
  186. *******************************************/
  187. /**
  188. * Returns the WHERE clause " AND NOT [tablename].[deleted-field]" if a deleted-field is configured in $TCA for the tablename, $table
  189. * This function should ALWAYS be called in the backend for selection on tables which are configured in TCA since it will ensure consistent selection of records, even if they are marked deleted (in which case the system must always treat them as non-existent!)
  190. * In the frontend a function, ->enableFields(), is known to filter hidden-field, start- and endtime and fe_groups as well. But that is a job of the frontend, not the backend. If you need filtering on those fields as well in the backend you can use ->BEenableFields() though.
  191. * Usage: 71
  192. *
  193. * @param string Table name present in $TCA
  194. * @param string Table alias if any
  195. * @return string WHERE clause for filtering out deleted records, eg " AND tablename.deleted=0"
  196. */
  197. public static function deleteClause($table, $tableAlias = '') {
  198. global $TCA;
  199. if ($TCA[$table]['ctrl']['delete']) {
  200. return ' AND ' . ($tableAlias ? $tableAlias : $table) . '.' . $TCA[$table]['ctrl']['delete'] . '=0';
  201. } else {
  202. return '';
  203. }
  204. }
  205. /**
  206. * Gets record with uid = $uid from $table
  207. * You can set $field to a list of fields (default is '*')
  208. * Additional WHERE clauses can be added by $where (fx. ' AND blabla = 1')
  209. * Will automatically check if records has been deleted and if so, not return anything.
  210. * $table must be found in $TCA
  211. * Usage: 99
  212. *
  213. * @param string Table name present in $TCA
  214. * @param integer UID of record
  215. * @param string List of fields to select
  216. * @param string Additional WHERE clause, eg. " AND blablabla = 0"
  217. * @param boolean Use the deleteClause to check if a record is deleted (default true)
  218. * @return array Returns the row if found, otherwise nothing
  219. */
  220. public static function getRecord($table, $uid, $fields = '*', $where = '', $useDeleteClause = TRUE) {
  221. if ($GLOBALS['TCA'][$table]) {
  222. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  223. $fields,
  224. $table,
  225. 'uid=' . intval($uid) . ($useDeleteClause ? self::deleteClause($table) : '') . $where
  226. );
  227. $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
  228. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  229. if ($row) {
  230. return $row;
  231. }
  232. }
  233. }
  234. /**
  235. * Like getRecord(), but overlays workspace version if any.
  236. *
  237. * @param string Table name present in $TCA
  238. * @param integer UID of record
  239. * @param string List of fields to select
  240. * @param string Additional WHERE clause, eg. " AND blablabla = 0"
  241. * @param boolean Use the deleteClause to check if a record is deleted (default true)
  242. * @param boolean If true the function does not return a "pointer" row for moved records in a workspace
  243. * @return array Returns the row if found, otherwise nothing
  244. */
  245. public static function getRecordWSOL($table, $uid, $fields = '*', $where = '', $useDeleteClause = TRUE, $unsetMovePointers = FALSE) {
  246. if ($fields !== '*') {
  247. $internalFields = t3lib_div::uniqueList($fields . ',uid,pid' . ($table == 'pages' ? ',t3ver_swapmode' : ''));
  248. $row = self::getRecord($table, $uid, $internalFields, $where, $useDeleteClause);
  249. self::workspaceOL($table, $row, -99, $unsetMovePointers);
  250. if (is_array($row)) {
  251. foreach (array_keys($row) as $key) {
  252. if (!t3lib_div::inList($fields, $key) && $key{0} !== '_') {
  253. unset ($row[$key]);
  254. }
  255. }
  256. }
  257. } else {
  258. $row = self::getRecord($table, $uid, $fields, $where, $useDeleteClause);
  259. self::workspaceOL($table, $row, -99, $unsetMovePointers);
  260. }
  261. return $row;
  262. }
  263. /**
  264. * Returns the first record found from $table with $where as WHERE clause
  265. * This function does NOT check if a record has the deleted flag set.
  266. * $table does NOT need to be configured in $TCA
  267. * The query used is simply this:
  268. * $query = 'SELECT '.$fields.' FROM '.$table.' WHERE '.$where;
  269. * Usage: 5 (ext: sys_todos)
  270. *
  271. * @param string Table name (not necessarily in TCA)
  272. * @param string WHERE clause
  273. * @param string $fields is a list of fields to select, default is '*'
  274. * @return array First row found, if any, FALSE otherwise
  275. */
  276. public static function getRecordRaw($table, $where = '', $fields = '*') {
  277. $row = FALSE;
  278. if (FALSE !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, '', '', '1'))) {
  279. $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
  280. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  281. }
  282. return $row;
  283. }
  284. /**
  285. * Returns records from table, $theTable, where a field ($theField) equals the value, $theValue
  286. * The records are returned in an array
  287. * If no records were selected, the function returns nothing
  288. * Usage: 8
  289. *
  290. * @param string Table name present in $TCA
  291. * @param string Field to select on
  292. * @param string Value that $theField must match
  293. * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
  294. * @param string Optional GROUP BY field(s), if none, supply blank string.
  295. * @param string Optional ORDER BY field(s), if none, supply blank string.
  296. * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
  297. * @param boolean Use the deleteClause to check if a record is deleted (default true)
  298. * @return mixed Multidimensional array with selected records (if any is selected)
  299. */
  300. public static function getRecordsByField($theTable, $theField, $theValue, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '', $useDeleteClause = TRUE) {
  301. global $TCA;
  302. if (is_array($TCA[$theTable])) {
  303. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  304. '*',
  305. $theTable,
  306. $theField . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable) .
  307. ($useDeleteClause ? self::deleteClause($theTable) . ' ' : '') .
  308. self::versioningPlaceholderClause($theTable) . ' ' .
  309. $whereClause, // whereClauseMightContainGroupOrderBy
  310. $groupBy,
  311. $orderBy,
  312. $limit
  313. );
  314. $rows = array();
  315. while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  316. $rows[] = $row;
  317. }
  318. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  319. if (count($rows)) {
  320. return $rows;
  321. }
  322. }
  323. }
  324. /**
  325. * Makes an backwards explode on the $str and returns an array with ($table, $uid).
  326. * Example: tt_content_45 => array('tt_content', 45)
  327. * Usage: 1
  328. *
  329. * @param string [tablename]_[uid] string to explode
  330. * @return array
  331. */
  332. public static function splitTable_Uid($str) {
  333. list($uid, $table) = explode('_', strrev($str), 2);
  334. return array(strrev($table), strrev($uid));
  335. }
  336. /**
  337. * Returns a list of pure integers based on $in_list being a list of records with table-names prepended.
  338. * Ex: $in_list = "pages_4,tt_content_12,45" would result in a return value of "4,45" if $tablename is "pages" and $default_tablename is 'pages' as well.
  339. * Usage: 1 (t3lib_userauthgroup)
  340. *
  341. * @param string Input list
  342. * @param string Table name from which ids is returned
  343. * @param string $default_tablename denotes what table the number '45' is from (if nothing is prepended on the value)
  344. * @return string List of ids
  345. */
  346. public static function getSQLselectableList($in_list, $tablename, $default_tablename) {
  347. $list = Array();
  348. if ((string) trim($in_list) != '') {
  349. $tempItemArray = explode(',', trim($in_list));
  350. foreach ($tempItemArray as $key => $val) {
  351. $val = strrev($val);
  352. $parts = explode('_', $val, 2);
  353. if ((string) trim($parts[0]) != '') {
  354. $theID = intval(strrev($parts[0]));
  355. $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : $default_tablename;
  356. if ($theTable == $tablename) {
  357. $list[] = $theID;
  358. }
  359. }
  360. }
  361. }
  362. return implode(',', $list);
  363. }
  364. /**
  365. * Backend implementation of enableFields()
  366. * Notice that "fe_groups" is not selected for - only disabled, starttime and endtime.
  367. * Notice that deleted-fields are NOT filtered - you must ALSO call deleteClause in addition.
  368. * $GLOBALS["SIM_ACCESS_TIME"] is used for date.
  369. * Usage: 5
  370. *
  371. * @param string $table is the table from which to return enableFields WHERE clause. Table name must have a 'ctrl' section in $TCA.
  372. * @param boolean $inv means that the query will select all records NOT VISIBLE records (inverted selection)
  373. * @return string WHERE clause part
  374. */
  375. public static function BEenableFields($table, $inv = 0) {
  376. $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
  377. $query = array();
  378. $invQuery = array();
  379. if (is_array($ctrl)) {
  380. if (is_array($ctrl['enablecolumns'])) {
  381. if ($ctrl['enablecolumns']['disabled']) {
  382. $field = $table . '.' . $ctrl['enablecolumns']['disabled'];
  383. $query[] = $field . '=0';
  384. $invQuery[] = $field . '!=0';
  385. }
  386. if ($ctrl['enablecolumns']['starttime']) {
  387. $field = $table . '.' . $ctrl['enablecolumns']['starttime'];
  388. $query[] = '(' . $field . '<=' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
  389. $invQuery[] = '(' . $field . '!=0 AND ' . $field . '>' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
  390. }
  391. if ($ctrl['enablecolumns']['endtime']) {
  392. $field = $table . '.' . $ctrl['enablecolumns']['endtime'];
  393. $query[] = '(' . $field . '=0 OR ' . $field . '>' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
  394. $invQuery[] = '(' . $field . '!=0 AND ' . $field . '<=' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
  395. }
  396. }
  397. }
  398. $outQ = ($inv ? '(' . implode(' OR ', $invQuery) . ')' : implode(' AND ', $query));
  399. return $outQ ? ' AND ' . $outQ : '';
  400. }
  401. /**
  402. * Fetches the localization for a given record.
  403. *
  404. * @param string $table: Table name present in $TCA
  405. * @param integer $uid: The uid of the record
  406. * @param integer $language: The uid of the language record in sys_language
  407. * @param string $andWhereClause: Optional additional WHERE clause (default: '')
  408. * @return mixed Multidimensional array with selected records; if none exist, false is returned
  409. */
  410. public static function getRecordLocalization($table, $uid, $language, $andWhereClause = '') {
  411. $recordLocalization = FALSE;
  412. if (self::isTableLocalizable($table)) {
  413. $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
  414. $recordLocalization = self::getRecordsByField(
  415. $table,
  416. $tcaCtrl['transOrigPointerField'],
  417. $uid,
  418. 'AND ' . $tcaCtrl['languageField'] . '=' . intval($language) . ($andWhereClause ? ' ' . $andWhereClause : ''),
  419. '',
  420. '',
  421. '1'
  422. );
  423. }
  424. return $recordLocalization;
  425. }
  426. /*******************************************
  427. *
  428. * Page tree, TCA related
  429. *
  430. *******************************************/
  431. /**
  432. * Returns what is called the 'RootLine'. That is an array with information about the page records from a page id ($uid) and back to the root.
  433. * By default deleted pages are filtered.
  434. * This RootLine will follow the tree all the way to the root. This is opposite to another kind of root line known from the frontend where the rootline stops when a root-template is found.
  435. * Usage: 1
  436. *
  437. * @param integer Page id for which to create the root line.
  438. * @param string $clause can be used to select other criteria. It would typically be where-clauses that stops the process if we meet a page, the user has no reading access to.
  439. * @param boolean If true, version overlay is applied. This must be requested specifically because it is usually only wanted when the rootline is used for visual output while for permission checking you want the raw thing!
  440. * @return array Root line array, all the way to the page tree root (or as far as $clause allows!)
  441. */
  442. public static function BEgetRootLine($uid, $clause = '', $workspaceOL = FALSE) {
  443. static $BEgetRootLine_cache = array();
  444. $output = array();
  445. $pid = $uid;
  446. $ident = $pid . '-' . $clause . '-' . $workspaceOL;
  447. if (is_array($BEgetRootLine_cache[$ident])) {
  448. $output = $BEgetRootLine_cache[$ident];
  449. } else {
  450. $loopCheck = 100;
  451. $theRowArray = array();
  452. while ($uid != 0 && $loopCheck) {
  453. $loopCheck--;
  454. $row = self::getPageForRootline($uid, $clause, $workspaceOL);
  455. if (is_array($row)) {
  456. $uid = $row['pid'];
  457. $theRowArray[] = $row;
  458. } else {
  459. break;
  460. }
  461. }
  462. if ($uid == 0) {
  463. $theRowArray[] = array('uid' => 0, 'title' => '');
  464. }
  465. $c = count($theRowArray);
  466. foreach ($theRowArray as $val) {
  467. $c--;
  468. $output[$c] = array(
  469. 'uid' => $val['uid'],
  470. 'pid' => $val['pid'],
  471. 'title' => $val['title'],
  472. 'TSconfig' => $val['TSconfig'],
  473. 'is_siteroot' => $val['is_siteroot'],
  474. 'storage_pid' => $val['storage_pid'],
  475. 't3ver_oid' => $val['t3ver_oid'],
  476. 't3ver_wsid' => $val['t3ver_wsid'],
  477. 't3ver_state' => $val['t3ver_state'],
  478. 't3ver_swapmode' => $val['t3ver_swapmode'],
  479. 't3ver_stage' => $val['t3ver_stage'],
  480. 'backend_layout_next_level' => $val['backend_layout_next_level']
  481. );
  482. if (isset($val['_ORIG_pid'])) {
  483. $output[$c]['_ORIG_pid'] = $val['_ORIG_pid'];
  484. }
  485. }
  486. $BEgetRootLine_cache[$ident] = $output;
  487. }
  488. return $output;
  489. }
  490. /**
  491. * Gets the cached page record for the rootline
  492. *
  493. * @param integer $uid: Page id for which to create the root line.
  494. * @param string $clause: can be used to select other criteria. It would typically be where-clauses that stops the process if we meet a page, the user has no reading access to.
  495. * @param boolean $workspaceOL: If true, version overlay is applied. This must be requested specifically because it is usually only wanted when the rootline is used for visual output while for permission checking you want the raw thing!
  496. * @return array Cached page record for the rootline
  497. * @see BEgetRootLine
  498. */
  499. protected static function getPageForRootline($uid, $clause, $workspaceOL) {
  500. static $getPageForRootline_cache = array();
  501. $ident = $uid . '-' . $clause . '-' . $workspaceOL;
  502. if (is_array($getPageForRootline_cache[$ident])) {
  503. $row = $getPageForRootline_cache[$ident];
  504. } else {
  505. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  506. 'pid,uid,title,TSconfig,is_siteroot,storage_pid,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_swapmode,t3ver_stage,backend_layout_next_level',
  507. 'pages',
  508. 'uid=' . intval($uid) . ' ' .
  509. self::deleteClause('pages') . ' ' .
  510. $clause // whereClauseMightContainGroupOrderBy
  511. );
  512. $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
  513. if ($row) {
  514. if ($workspaceOL) {
  515. self::workspaceOL('pages', $row);
  516. }
  517. if (is_array($row)) {
  518. self::fixVersioningPid('pages', $row);
  519. $getPageForRootline_cache[$ident] = $row;
  520. }
  521. }
  522. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  523. }
  524. return $row;
  525. }
  526. /**
  527. * Opens the page tree to the specified page id
  528. *
  529. * @param integer Page id.
  530. * @param boolean If set, then other open branches are closed.
  531. * @return void
  532. */
  533. public static function openPageTree($pid, $clearExpansion) {
  534. global $BE_USER;
  535. // Get current expansion data:
  536. if ($clearExpansion) {
  537. $expandedPages = array();
  538. } else {
  539. $expandedPages = unserialize($BE_USER->uc['browseTrees']['browsePages']);
  540. }
  541. // Get rootline:
  542. $rL = self::BEgetRootLine($pid);
  543. // First, find out what mount index to use (if more than one DB mount exists):
  544. $mountIndex = 0;
  545. $mountKeys = array_flip($BE_USER->returnWebmounts());
  546. foreach ($rL as $rLDat) {
  547. if (isset($mountKeys[$rLDat['uid']])) {
  548. $mountIndex = $mountKeys[$rLDat['uid']];
  549. break;
  550. }
  551. }
  552. // Traverse rootline and open paths:
  553. foreach ($rL as $rLDat) {
  554. $expandedPages[$mountIndex][$rLDat['uid']] = 1;
  555. }
  556. // Write back:
  557. $BE_USER->uc['browseTrees']['browsePages'] = serialize($expandedPages);
  558. $BE_USER->writeUC();
  559. }
  560. /**
  561. * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
  562. * Each part of the path will be limited to $titleLimit characters
  563. * Deleted pages are filtered out.
  564. * Usage: 15
  565. *
  566. * @param integer Page uid for which to create record path
  567. * @param string $clause is additional where clauses, eg. "
  568. * @param integer Title limit
  569. * @param integer Title limit of Full title (typ. set to 1000 or so)
  570. * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
  571. */
  572. public static function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit = 0) {
  573. if (!$titleLimit) {
  574. $titleLimit = 1000;
  575. }
  576. $loopCheck = 100;
  577. $output = $fullOutput = '/';
  578. $clause = trim($clause);
  579. if ($clause !== '' && substr($clause, 0, 3) !== 'AND') {
  580. $clause = 'AND ' . $clause;
  581. }
  582. $data = self::BEgetRootLine($uid, $clause);
  583. foreach ($data as $record) {
  584. if ($record['uid'] === 0) {
  585. continue;
  586. }
  587. if ($record['_ORIG_pid'] && $record['t3ver_swapmode'] > 0) { // Branch points
  588. $output = ' [#VEP#]' . $output; // Adding visual token - Versioning Entry Point - that tells that THIS position was where the versionized branch got connected to the main tree. I will have to find a better name or something...
  589. }
  590. $output = '/' . t3lib_div::fixed_lgd_cs(strip_tags($record['title']), $titleLimit) . $output;
  591. if ($fullTitleLimit) {
  592. $fullOutput = '/' . t3lib_div::fixed_lgd_cs(strip_tags($record['title']), $fullTitleLimit) . $fullOutput;
  593. }
  594. }
  595. if ($fullTitleLimit) {
  596. return array($output, $fullOutput);
  597. } else {
  598. return $output;
  599. }
  600. }
  601. /**
  602. * Returns an array with the exclude-fields as defined in TCA and FlexForms
  603. * Used for listing the exclude-fields in be_groups forms
  604. * Usage: 2 (t3lib_tceforms + t3lib_transferdata)
  605. *
  606. * @return array Array of arrays with excludeFields (fieldname, table:fieldname) from all TCA entries and from FlexForms (fieldname, table:extkey;sheetname;fieldname)
  607. */
  608. public static function getExcludeFields() {
  609. global $TCA;
  610. // All TCA keys:
  611. $theExcludeArray = Array();
  612. $tc_keys = array_keys($TCA);
  613. foreach ($tc_keys as $table) {
  614. // Load table
  615. t3lib_div::loadTCA($table);
  616. // All field names configured:
  617. if (is_array($TCA[$table]['columns'])) {
  618. $f_keys = array_keys($TCA[$table]['columns']);
  619. foreach ($f_keys as $field) {
  620. if ($TCA[$table]['columns'][$field]['exclude']) {
  621. // Get Human Readable names of fields and table:
  622. $Fname = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']) . ': ' . $GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
  623. // add entry:
  624. $theExcludeArray[] = Array($Fname, $table . ':' . $field);
  625. }
  626. }
  627. }
  628. }
  629. // All FlexForm fields
  630. $table = (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']) ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'] : 'tt_content');
  631. $flexFormArray = self::getRegisteredFlexForms($table);
  632. foreach ($flexFormArray as $tableField => $flexForms) {
  633. // Prefix for field label, e.g. "Plugin Options:"
  634. $labelPrefix = '';
  635. if (!empty($GLOBALS['TCA'][$table]['columns'][$tableField]['label'])) {
  636. $labelPrefix = $GLOBALS['LANG']->sl($GLOBALS['TCA'][$table]['columns'][$tableField]['label']);
  637. }
  638. // Get all sheets and title
  639. foreach ($flexForms as $extIdent => $extConf) {
  640. $extTitle = $GLOBALS['LANG']->sl($extConf['title']);
  641. // Get all fields in sheet
  642. foreach ($extConf['ds']['sheets'] as $sheetName => $sheet) {
  643. if (empty($sheet['ROOT']['el']) || !is_array($sheet['ROOT']['el'])) {
  644. continue;
  645. }
  646. foreach ($sheet['ROOT']['el'] as $fieldName => $field) {
  647. // Use only excludeable fields
  648. if (empty($field['TCEforms']['exclude'])) {
  649. continue;
  650. }
  651. $fieldLabel = (!empty($field['TCEforms']['label']) ? $GLOBALS['LANG']->sl($field['TCEforms']['label']) : $fieldName);
  652. $fieldIdent = $table . ':' . $tableField . ';' . $extIdent . ';' . $sheetName . ';' . $fieldName;
  653. $theExcludeArray[] = array(trim($labelPrefix . ' ' . $extTitle, ': ') . ': ' . $fieldLabel, $fieldIdent);
  654. }
  655. }
  656. }
  657. }
  658. // Sort fields by label
  659. usort($theExcludeArray, array(t3lib_TCEforms_Flexforms, 'compareArraysByFirstValue'));
  660. return $theExcludeArray;
  661. }
  662. /**
  663. * Returns an array with explicit Allow/Deny fields.
  664. * Used for listing these field/value pairs in be_groups forms
  665. *
  666. * @return array Array with information from all of $TCA
  667. */
  668. public static function getExplicitAuthFieldValues() {
  669. global $TCA;
  670. // Initialize:
  671. $adLabel = array(
  672. 'ALLOW' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.allow'),
  673. 'DENY' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.deny'),
  674. );
  675. // All TCA keys:
  676. $allowDenyOptions = Array();
  677. $tc_keys = array_keys($TCA);
  678. foreach ($tc_keys as $table) {
  679. // Load table
  680. t3lib_div::loadTCA($table);
  681. // All field names configured:
  682. if (is_array($TCA[$table]['columns'])) {
  683. $f_keys = array_keys($TCA[$table]['columns']);
  684. foreach ($f_keys as $field) {
  685. $fCfg = $TCA[$table]['columns'][$field]['config'];
  686. if ($fCfg['type'] == 'select' && $fCfg['authMode']) {
  687. // Check for items:
  688. if (is_array($fCfg['items'])) {
  689. // Get Human Readable names of fields and table:
  690. $allowDenyOptions[$table . ':' . $field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']) . ': ' . $GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
  691. // Check for items:
  692. foreach ($fCfg['items'] as $iVal) {
  693. if (strcmp($iVal[1], '')) { // Values '' is not controlled by this setting.
  694. // Find iMode:
  695. $iMode = '';
  696. switch ((string) $fCfg['authMode']) {
  697. case 'explicitAllow':
  698. $iMode = 'ALLOW';
  699. break;
  700. case 'explicitDeny':
  701. $iMode = 'DENY';
  702. break;
  703. case 'individual':
  704. if (!strcmp($iVal[4], 'EXPL_ALLOW')) {
  705. $iMode = 'ALLOW';
  706. } elseif (!strcmp($iVal[4], 'EXPL_DENY')) {
  707. $iMode = 'DENY';
  708. }
  709. break;
  710. }
  711. // Set iMode:
  712. if ($iMode) {
  713. $allowDenyOptions[$table . ':' . $field]['items'][$iVal[1]] = array($iMode, $GLOBALS['LANG']->sl($iVal[0]), $adLabel[$iMode]);
  714. }
  715. }
  716. }
  717. }
  718. }
  719. }
  720. }
  721. }
  722. return $allowDenyOptions;
  723. }
  724. /**
  725. * Returns an array with system languages:
  726. *
  727. * Since TYPO3 4.5 the flagIcon is not returned as a filename in "gfx/flags/*" anymore,
  728. * but as a string <flags-xx>. The calling party should call
  729. * t3lib_iconWorks::getSpriteIcon(<flags-xx>) to get an HTML which will represent
  730. * the flag of this language.
  731. *
  732. * @return array Array with languages (title, uid, flagIcon)
  733. */
  734. public static function getSystemLanguages() {
  735. $languages = t3lib_div::makeInstance('t3lib_transl8tools')->getSystemLanguages();
  736. $sysLanguages = array();
  737. foreach ($languages as $language) {
  738. if ($language['uid'] !== -1) {
  739. $sysLanguages[] = array(
  740. 0 => htmlspecialchars($language['title']) . ' [' . $language['uid'] . ']',
  741. 1 => $language['uid'],
  742. 2 => $language['flagIcon']
  743. );
  744. }
  745. }
  746. return $sysLanguages;
  747. }
  748. /**
  749. * Determines whether a table is localizable and has the languageField and transOrigPointerField set in $TCA.
  750. *
  751. * @param string $table: The table to check
  752. * @return boolean Whether a table is localizable
  753. */
  754. public static function isTableLocalizable($table) {
  755. $isLocalizable = FALSE;
  756. if (isset($GLOBALS['TCA'][$table]['ctrl']) && is_array($GLOBALS['TCA'][$table]['ctrl'])) {
  757. $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
  758. $isLocalizable = (isset($tcaCtrl['languageField']) && $tcaCtrl['languageField'] && isset($tcaCtrl['transOrigPointerField']) && $tcaCtrl['transOrigPointerField']);
  759. }
  760. return $isLocalizable;
  761. }
  762. /**
  763. * Returns the value of the property localizationMode in the given $config array ($TCA[<table>]['columns'][<field>]['config']).
  764. * If the table is prepared for localization and no localizationMode is set, 'select' is returned by default.
  765. * If the table is not prepared for localization or not defined at all in $TCA, false is returned.
  766. *
  767. * @param string $table: The name of the table to lookup in TCA
  768. * @param mixed $fieldOrConfig: The fieldname (string) or the configuration of the field to check (array)
  769. * @return mixed If table is localizable, the set localizationMode is returned (if property is not set, 'select' is returned by default); if table is not localizable, false is returned
  770. */
  771. public static function getInlineLocalizationMode($table, $fieldOrConfig) {
  772. $localizationMode = FALSE;
  773. if (is_array($fieldOrConfig) && count($fieldOrConfig)) {
  774. $config = $fieldOrConfig;
  775. } elseif (is_string($fieldOrConfig) && isset($GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'])) {
  776. $config = $GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'];
  777. }
  778. if (is_array($config) && isset($config['type']) && $config['type'] == 'inline' && self::isTableLocalizable($table)) {
  779. $localizationMode = (isset($config['behaviour']['localizationMode']) && $config['behaviour']['localizationMode'] ? $config['behaviour']['localizationMode'] : 'select');
  780. // The mode 'select' is not possible when child table is not localizable at all:
  781. if ($localizationMode == 'select' && !self::isTableLocalizable($config['foreign_table'])) {
  782. $localizationMode = FALSE;
  783. }
  784. }
  785. return $localizationMode;
  786. }
  787. /**
  788. * Returns a page record (of page with $id) with an extra field "_thePath" set to the record path IF the WHERE clause, $perms_clause, selects the record. Thus is works as an access check that returns a page record if access was granted, otherwise not.
  789. * If $id is zero a pseudo root-page with "_thePath" set is returned IF the current BE_USER is admin.
  790. * In any case ->isInWebMount must return true for the user (regardless of $perms_clause)
  791. * Usage: 21
  792. *
  793. * @param integer Page uid for which to check read-access
  794. * @param string $perms_clause is typically a value generated with $BE_USER->getPagePermsClause(1);
  795. * @return array Returns page record if OK, otherwise false.
  796. */
  797. public static function readPageAccess($id, $perms_clause) {
  798. if ((string) $id != '') {
  799. $id = intval($id);
  800. if (!$id) {
  801. if ($GLOBALS['BE_USER']->isAdmin()) {
  802. $path = '/';
  803. $pageinfo['_thePath'] = $path;
  804. return $pageinfo;
  805. }
  806. } else {
  807. $pageinfo = self::getRecord('pages', $id, '*', ($perms_clause ? ' AND ' . $perms_clause : ''));
  808. if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id, $perms_clause)) {
  809. self::workspaceOL('pages', $pageinfo);
  810. if (is_array($pageinfo)) {
  811. self::fixVersioningPid('pages', $pageinfo);
  812. list($pageinfo['_thePath'], $pageinfo['_thePathFull']) = self::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
  813. return $pageinfo;
  814. }
  815. }
  816. }
  817. }
  818. return FALSE;
  819. }
  820. /**
  821. * Returns the "types" configuration parsed into an array for the record, $rec, from table, $table
  822. * Usage: 6
  823. *
  824. * @param string Table name (present in TCA)
  825. * @param array Record from $table
  826. * @param boolean If $useFieldNameAsKey is set, then the fieldname is associative keys in the return array, otherwise just numeric keys.
  827. * @return array
  828. */
  829. public static function getTCAtypes($table, $rec, $useFieldNameAsKey = 0) {
  830. global $TCA;
  831. t3lib_div::loadTCA($table);
  832. if ($TCA[$table]) {
  833. // Get type value:
  834. $fieldValue = self::getTCAtypeValue($table, $rec);
  835. // Get typesConf
  836. $typesConf = $TCA[$table]['types'][$fieldValue];
  837. // Get fields list and traverse it
  838. $fieldList = explode(',', $typesConf['showitem']);
  839. $altFieldList = array();
  840. // Traverse fields in types config and parse the configuration into a nice array:
  841. foreach ($fieldList as $k => $v) {
  842. list($pFieldName, $pAltTitle, $pPalette, $pSpec) = t3lib_div::trimExplode(';', $v);
  843. $defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ? $TCA[$table]['columns'][$pFieldName]['defaultExtras'] : '';
  844. $specConfParts = self::getSpecConfParts($pSpec, $defaultExtras);
  845. $fieldList[$k] = array(
  846. 'field' => $pFieldName,
  847. 'title' => $pAltTitle,
  848. 'palette' => $pPalette,
  849. 'spec' => $specConfParts,
  850. 'origString' => $v
  851. );
  852. if ($useFieldNameAsKey) {
  853. $altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
  854. }
  855. }
  856. if ($useFieldNameAsKey) {
  857. $fieldList = $altFieldList;
  858. }
  859. // Return array:
  860. return $fieldList;
  861. }
  862. }
  863. /**
  864. * Returns the "type" value of $rec from $table which can be used to look up the correct "types" rendering section in $TCA
  865. * If no "type" field is configured in the "ctrl"-section of the $TCA for the table, zero is used.
  866. * If zero is not an index in the "types" section of $TCA for the table, then the $fieldValue returned will default to 1 (no matter if that is an index or not)
  867. * Usage: 7
  868. *
  869. * @param string Table name present in TCA
  870. * @param array Record from $table
  871. * @return string Field value
  872. * @see getTCAtypes()
  873. */
  874. public static function getTCAtypeValue($table, $rec) {
  875. global $TCA;
  876. // If no field-value, set it to zero. If there is no type matching the field-value (which now may be zero...) test field-value '1' as default.
  877. t3lib_div::loadTCA($table);
  878. if ($TCA[$table]) {
  879. $field = $TCA[$table]['ctrl']['type'];
  880. $fieldValue = $field ? ($rec[$field] ? $rec[$field] : 0) : 0;
  881. if (!is_array($TCA[$table]['types'][$fieldValue])) {
  882. $fieldValue = 1;
  883. }
  884. return $fieldValue;
  885. }
  886. }
  887. /**
  888. * Parses a part of the field lists in the "types"-section of $TCA arrays, namely the "special configuration" at index 3 (position 4)
  889. * Elements are splitted by ":" and within those parts, parameters are splitted by "|".
  890. * Everything is returned in an array and you should rather see it visually than listen to me anymore now... Check out example in Inside TYPO3
  891. * Usage: 5
  892. *
  893. * @param string Content from the "types" configuration of TCA (the special configuration) - see description of function
  894. * @param string The ['defaultExtras'] value from field configuration
  895. * @return array
  896. */
  897. public static function getSpecConfParts($str, $defaultExtras) {
  898. // Add defaultExtras:
  899. $specConfParts = t3lib_div::trimExplode(':', $defaultExtras . ':' . $str, 1);
  900. $reg = array();
  901. if (count($specConfParts)) {
  902. foreach ($specConfParts as $k2 => $v2) {
  903. unset($specConfParts[$k2]);
  904. if (preg_match('/(.*)\[(.*)\]/', $v2, $reg)) {
  905. $specConfParts[trim($reg[1])] = array(
  906. 'parameters' => t3lib_div::trimExplode('|', $reg[2], 1)
  907. );
  908. } else {
  909. $specConfParts[trim($v2)] = 1;
  910. }
  911. }
  912. } else {
  913. $specConfParts = array();
  914. }
  915. return $specConfParts;
  916. }
  917. /**
  918. * Takes an array of "[key] = [value]" strings and returns an array with the keys set as keys pointing to the value.
  919. * Better see it in action! Find example in Inside TYPO3
  920. * Usage: 6
  921. *
  922. * @param array Array of "[key] = [value]" strings to convert.
  923. * @return array
  924. */
  925. public static function getSpecConfParametersFromArray($pArr) {
  926. $out = array();
  927. if (is_array($pArr)) {
  928. foreach ($pArr as $k => $v) {
  929. $parts = explode('=', $v, 2);
  930. if (count($parts) == 2) {
  931. $out[trim($parts[0])] = trim($parts[1]);
  932. } else {
  933. $out[$k] = $v;
  934. }
  935. }
  936. }
  937. return $out;
  938. }
  939. /**
  940. * Finds the Data Structure for a FlexForm field
  941. * NOTE ON data structures for deleted records: This function may fail to deliver the data structure for a record for a few reasons: a) The data structure could be deleted (either with deleted-flagged or hard-deleted), b) the data structure is fetched using the ds_pointerField_searchParent in which case any deleted record on the route to the final location of the DS will make it fail. In theory, we can solve the problem in the case where records that are deleted-flagged keeps us from finding the DS - this is done at the markers ###NOTE_A### where we make sure to also select deleted records. However, we generally want the DS lookup to fail for deleted records since for the working website we expect a deleted-flagged record to be as inaccessible as one that is completely deleted from the DB. Any way we look at it, this may lead to integrity problems of the reference index and even lost files if attached. However, that is not really important considering that a single change to a data structure can instantly invalidate large amounts of the reference index which we do accept as a cost for the flexform features. Other than requiring a reference index update, deletion of/changes in data structure or the failure to look them up when completely deleting records may lead to lost files in the uploads/ folders since those are now without a proper reference.
  942. * Usage: 5
  943. *
  944. * @param array Field config array
  945. * @param array Record data
  946. * @param string The table name
  947. * @param string Optional fieldname passed to hook object
  948. * @param boolean Boolean; If set, workspace overlay is applied to records. This is correct behaviour for all presentation and export, but NOT if you want a true reflection of how things are in the live workspace.
  949. * @param integer SPECIAL CASES: Use this, if the DataStructure may come from a parent record and the INPUT row doesn't have a uid yet (hence, the pid cannot be looked up). Then it is necessary to supply a PID value to search recursively in for the DS (used from TCEmain)
  950. * @return mixed If array, the data structure was found and returned as an array. Otherwise (string) it is an error message.
  951. * @see t3lib_TCEforms::getSingleField_typeFlex()
  952. */
  953. public static function getFlexFormDS($conf, $row, $table, $fieldName = '', $WSOL = TRUE, $newRecordPidValue = 0) {
  954. global $TYPO3_CONF_VARS;
  955. // Get pointer field etc from TCA-config:
  956. $ds_pointerField = $conf['ds_pointerField'];
  957. $ds_array = $conf['ds'];
  958. $ds_tableField = $conf['ds_tableField'];
  959. $ds_searchParentField = $conf['ds_pointerField_searchParent'];
  960. // Find source value:
  961. $dataStructArray = '';
  962. if (is_array($ds_array)) { // If there is a data source array, that takes precedence
  963. // If a pointer field is set, take the value from that field in the $row array and use as key.
  964. if ($ds_pointerField) {
  965. // Up to two pointer fields can be specified in a comma separated list.
  966. $pointerFields = t3lib_div::trimExplode(',', $ds_pointerField);
  967. if (count($pointerFields) == 2) { // If we have two pointer fields, the array keys should contain both field values separated by comma. The asterisk "*" catches all values. For backwards compatibility, it's also possible to specify only the value of the first defined ds_pointerField.
  968. if ($ds_array[$row[$pointerFields[0]] . ',' . $row[$pointerFields[1]]]) { // Check if we have a DS for the combination of both pointer fields values
  969. $srcPointer = $row[$pointerFields[0]] . ',' . $row[$pointerFields[1]];
  970. } elseif ($ds_array[$row[$pointerFields[1]] . ',*']) { // Check if we have a DS for the value of the first pointer field suffixed with ",*"
  971. $srcPointer = $row[$pointerFields[1]] . ',*';
  972. } elseif ($ds_array['*,' . $row[$pointerFields[1]]]) { // Check if we have a DS for the value of the second pointer field prefixed with "*,"
  973. $srcPointer = '*,' . $row[$pointerFields[1]];
  974. } elseif ($ds_array[$row[$pointerFields[0]]]) { // Check if we have a DS for just the value of the first pointer field (mainly for backwards compatibility)
  975. $srcPointer = $row[$pointerFields[0]];
  976. }
  977. } else {
  978. $srcPointer = $row[$pointerFields[0]];
  979. }
  980. $srcPointer = isset($ds_array[$srcPointer]) ? $srcPointer : 'default';
  981. } else {
  982. $srcPointer = 'default';
  983. }
  984. // Get Data Source: Detect if it's a file reference and in that case read the file and parse as XML. Otherwise the value is expected to be XML.
  985. if (substr($ds_array[$srcPointer], 0, 5) == 'FILE:') {
  986. $file = t3lib_div::getFileAbsFileName(substr($ds_array[$srcPointer], 5));
  987. if ($file && @is_file($file)) {
  988. $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
  989. } else {
  990. $dataStructArray = 'The file "' . substr($ds_array[$srcPointer], 5) . '" in ds-array key "' . $srcPointer . '" was not found ("' . $file . '")';
  991. } // Error message.
  992. } else {
  993. $dataStructArray = t3lib_div::xml2array($ds_array[$srcPointer]);
  994. }
  995. } elseif ($ds_pointerField) { // If pointer field AND possibly a table/field is set:
  996. // Value of field pointed to:
  997. $srcPointer = $row[$ds_pointerField];
  998. // Searching recursively back if 'ds_pointerField_searchParent' is defined (typ. a page rootline, or maybe a tree-table):
  999. if ($ds_searchParentField && !$srcPointer) {
  1000. $rr = self::getRecord($table, $row['uid'], 'uid,' . $ds_searchParentField); // Get the "pid" field - we cannot know that it is in the input record! ###NOTE_A###
  1001. if ($WSOL) {
  1002. self::workspaceOL($table, $rr);
  1003. self::fixVersioningPid($table, $rr, TRUE); // Added "TRUE" 23/03/06 before 4.0. (Also to similar call below!). Reason: When t3lib_refindex is scanning the system in Live workspace all Pages with FlexForms will not find their inherited datastructure. Thus all references from workspaces are removed! Setting TRUE means that versioning PID doesn't check workspace of the record. I can't see that this should give problems anywhere. See more information inside t3lib_refindex!
  1004. }
  1005. $uidAcc = array(); // Used to avoid looping, if any should happen.
  1006. $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
  1007. while (!$srcPointer) {
  1008. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  1009. 'uid,' . $ds_pointerField . ',' . $ds_searchParentField . ($subFieldPointer ? ',' . $subFieldPointer : ''),
  1010. $table,
  1011. 'uid=' . intval($newRecordPidValue ? $newRecordPidValue : $rr[$ds_searchParentField]) . self::deleteClause($table) ###NOTE_A###
  1012. );
  1013. $newRecordPidValue = 0;
  1014. $rr = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
  1015. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  1016. // break if no result from SQL db or if looping...
  1017. if (!is_array($rr) || isset($uidAcc[$rr['uid']])) {
  1018. break;
  1019. }
  1020. $uidAcc[$rr['uid']] = 1;
  1021. if ($WSOL) {
  1022. self::workspaceOL($table, $rr);
  1023. self::fixVersioningPid($table, $rr, TRUE);
  1024. }
  1025. $srcPointer = ($subFieldPointer && $rr[$subFieldPointer]) ? $rr[$subFieldPointer] : $rr[$ds_pointerField];
  1026. }
  1027. }
  1028. // If there is a srcPointer value:
  1029. if ($srcPointer) {
  1030. if (t3lib_div::testInt($srcPointer)) { // If integer, then its a record we will look up:
  1031. list($tName, $fName) = explode(':', $ds_tableField, 2);
  1032. if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) {
  1033. $dataStructRec = self::getRecord($tName, $srcPointer);
  1034. if ($WSOL) {
  1035. self::workspaceOL($tName, $dataStructRec);
  1036. }
  1037. $dataStructArray = t3lib_div::xml2array($dataStructRec[$fName]);
  1038. } else {
  1039. $dataStructArray = 'No tablename (' . $tName . ') or fieldname (' . $fName . ') was found an valid!';
  1040. }
  1041. } else { // Otherwise expect it to be a file:
  1042. $file = t3lib_div::getFileAbsFileName($srcPointer);
  1043. if ($file && @is_file($file)) {
  1044. $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
  1045. } else {
  1046. $dataStructArray = 'The file "' . $srcPointer . '" was not found ("' . $file . '")';
  1047. } // Error message.
  1048. }
  1049. } else {
  1050. $dataStructArray = 'No source value in fieldname "' . $ds_pointerField . '"';
  1051. } // Error message.
  1052. } else {
  1053. $dataStructArray = 'No proper configuration!';
  1054. }
  1055. // Hook for post-processing the Flexform DS. Introduces the possibility to configure Flexforms via TSConfig
  1056. if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'])) {
  1057. foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'] as $classRef) {
  1058. $hookObj = t3lib_div::getUserObj($classRef);
  1059. if (method_exists($hookObj, 'getFlexFormDS_postProcessDS')) {
  1060. $hookObj->getFlexFormDS_postProcessDS($dataStructArray, $conf, $row, $table, $fieldName);
  1061. }
  1062. }
  1063. }
  1064. return $dataStructArray;
  1065. }
  1066. /**
  1067. * Returns all registered FlexForm definitions with title and fields
  1068. * Usage: 1
  1069. *
  1070. * @param string The content table
  1071. * @return array The data structures with speaking extension title
  1072. * @see t3lib_BEfunc::getExcludeFields()
  1073. */
  1074. public static function getRegisteredFlexForms($table = 'tt_content') {
  1075. if (empty($table) || empty($GLOBALS['TCA'][$table]['columns'])) {
  1076. return array();
  1077. }
  1078. $flexForms = array();
  1079. foreach ($GLOBALS['TCA'][$table]['columns'] as $tableField => $fieldConf) {
  1080. if (!empty($fieldConf['config']['type']) && !empty($fieldConf['config']['ds']) && $fieldConf['config']['type'] == 'flex') {
  1081. $flexForms[$tableField] = array();
  1082. unset($fieldConf['config']['ds']['default']);
  1083. // Get pointer fields
  1084. $pointerFields = (!empty($fieldConf['config']['ds_pointerField']) ? $fieldConf['config']['ds_pointerField'] : 'list_type,CType');
  1085. $pointerFields = t3l

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