PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/t3lib/class.t3lib_befunc.php

https://bitbucket.org/linxpinx/mercurial
PHP | 4447 lines | 2453 code | 476 blank | 1518 comment | 563 complexity | 3c9c968c5339b22b1bbd0b09e7a917f7 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. * 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: class.t3lib_befunc.php 8415 2010-07-28 09:15:10Z ohader $
  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 Skaarhoj
  37. * XHTML compliant
  38. *
  39. * @author Kasper Skaarhoj <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='',$addGetVars='',$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 Skaarhoj <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. * @return array Returns the row if found, otherwise nothing
  243. */
  244. public static function getRecordWSOL($table, $uid, $fields = '*', $where = '', $useDeleteClause = true) {
  245. if ($fields !== '*') {
  246. $internalFields = t3lib_div::uniqueList($fields.',uid,pid'.($table == 'pages' ? ',t3ver_swapmode' : ''));
  247. $row = self::getRecord($table, $uid, $internalFields, $where, $useDeleteClause);
  248. self::workspaceOL($table, $row);
  249. if (is_array ($row)) {
  250. foreach (array_keys($row) as $key) {
  251. if (!t3lib_div::inList($fields, $key) && $key{0} !== '_') {
  252. unset ($row[$key]);
  253. }
  254. }
  255. }
  256. } else {
  257. $row = self::getRecord($table, $uid, $fields, $where);
  258. self::workspaceOL($table, $row);
  259. }
  260. return $row;
  261. }
  262. /**
  263. * Returns the first record found from $table with $where as WHERE clause
  264. * This function does NOT check if a record has the deleted flag set.
  265. * $table does NOT need to be configured in $TCA
  266. * The query used is simply this:
  267. * $query = 'SELECT '.$fields.' FROM '.$table.' WHERE '.$where;
  268. * Usage: 5 (ext: sys_todos)
  269. *
  270. * @param string Table name (not necessarily in TCA)
  271. * @param string WHERE clause
  272. * @param string $fields is a list of fields to select, default is '*'
  273. * @return array First row found, if any, FALSE otherwise
  274. */
  275. public static function getRecordRaw($table, $where = '', $fields = '*') {
  276. $row = FALSE;
  277. if (FALSE !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, '', '', '1'))) {
  278. $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
  279. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  280. }
  281. return $row;
  282. }
  283. /**
  284. * Returns records from table, $theTable, where a field ($theField) equals the value, $theValue
  285. * The records are returned in an array
  286. * If no records were selected, the function returns nothing
  287. * Usage: 8
  288. *
  289. * @param string Table name present in $TCA
  290. * @param string Field to select on
  291. * @param string Value that $theField must match
  292. * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
  293. * @param string Optional GROUP BY field(s), if none, supply blank string.
  294. * @param string Optional ORDER BY field(s), if none, supply blank string.
  295. * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
  296. * @param boolean Use the deleteClause to check if a record is deleted (default true)
  297. * @return mixed Multidimensional array with selected records (if any is selected)
  298. */
  299. public static function getRecordsByField($theTable, $theField, $theValue, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '', $useDeleteClause = true) {
  300. global $TCA;
  301. if (is_array($TCA[$theTable])) {
  302. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  303. '*',
  304. $theTable,
  305. $theField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable).
  306. ($useDeleteClause ? self::deleteClause($theTable).' ' : '').
  307. self::versioningPlaceholderClause($theTable) . ' ' .
  308. $whereClause, // whereClauseMightContainGroupOrderBy
  309. $groupBy,
  310. $orderBy,
  311. $limit
  312. );
  313. $rows = array();
  314. while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  315. $rows[] = $row;
  316. }
  317. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  318. if (count($rows)) return $rows;
  319. }
  320. }
  321. /**
  322. * Returns a WHERE clause which will make an AND search for the words in the $searchWords array in any of the fields in array $fields.
  323. * Usage: 0
  324. *
  325. * @param array Array of search words
  326. * @param array Array of fields
  327. * @param string Table in which we are searching (for DBAL detection of quoteStr() method)
  328. * @return string WHERE clause for search
  329. * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, use $GLOBALS['TYPO3_DB']->searchQuery() directly!
  330. */
  331. public static function searchQuery($searchWords, $fields, $table = '') {
  332. t3lib_div::logDeprecatedFunction();
  333. return $GLOBALS['TYPO3_DB']->searchQuery($searchWords, $fields, $table);
  334. }
  335. /**
  336. * Returns a WHERE clause that can find a value ($value) in a list field ($field)
  337. * For instance a record in the database might contain a list of numbers, "34,234,5" (with no spaces between). This query would be able to select that record based on the value "34", "234" or "5" regardless of their positioni in the list (left, middle or right).
  338. * Is nice to look up list-relations to records or files in TYPO3 database tables.
  339. * Usage: 0
  340. *
  341. * @param string Table field name
  342. * @param string Value to find in list
  343. * @return string WHERE clause for a query
  344. * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, use $GLOBALS['TYPO3_DB']->listQuery() directly!
  345. */
  346. public static function listQuery($field, $value) {
  347. t3lib_div::logDeprecatedFunction();
  348. return $GLOBALS['TYPO3_DB']->listQuery($field, $value, '');
  349. }
  350. /**
  351. * Makes an backwards explode on the $str and returns an array with ($table, $uid).
  352. * Example: tt_content_45 => array('tt_content', 45)
  353. * Usage: 1
  354. *
  355. * @param string [tablename]_[uid] string to explode
  356. * @return array
  357. */
  358. public static function splitTable_Uid($str) {
  359. list($uid, $table) = explode('_', strrev($str), 2);
  360. return array(strrev($table), strrev($uid));
  361. }
  362. /**
  363. * Returns a list of pure integers based on $in_list being a list of records with table-names prepended.
  364. * 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.
  365. * Usage: 1 (t3lib_userauthgroup)
  366. *
  367. * @param string Input list
  368. * @param string Table name from which ids is returned
  369. * @param string $default_tablename denotes what table the number '45' is from (if nothing is prepended on the value)
  370. * @return string List of ids
  371. */
  372. public static function getSQLselectableList($in_list, $tablename, $default_tablename) {
  373. $list = Array();
  374. if ((string)trim($in_list)!='') {
  375. $tempItemArray = explode(',', trim($in_list));
  376. foreach ($tempItemArray as $key => $val) {
  377. $val = strrev($val);
  378. $parts = explode('_', $val, 2);
  379. if ((string)trim($parts[0])!='') {
  380. $theID = intval(strrev($parts[0]));
  381. $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : $default_tablename;
  382. if ($theTable==$tablename) {$list[] = $theID;}
  383. }
  384. }
  385. }
  386. return implode(',', $list);
  387. }
  388. /**
  389. * Backend implementation of enableFields()
  390. * Notice that "fe_groups" is not selected for - only disabled, starttime and endtime.
  391. * Notice that deleted-fields are NOT filtered - you must ALSO call deleteClause in addition.
  392. * $GLOBALS["SIM_ACCESS_TIME"] is used for date.
  393. * Usage: 5
  394. *
  395. * @param string $table is the table from which to return enableFields WHERE clause. Table name must have a 'ctrl' section in $TCA.
  396. * @param boolean $inv means that the query will select all records NOT VISIBLE records (inverted selection)
  397. * @return string WHERE clause part
  398. */
  399. public static function BEenableFields($table, $inv = 0) {
  400. $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
  401. $query = array();
  402. $invQuery = array();
  403. if (is_array($ctrl)) {
  404. if (is_array($ctrl['enablecolumns'])) {
  405. if ($ctrl['enablecolumns']['disabled']) {
  406. $field = $table.'.'.$ctrl['enablecolumns']['disabled'];
  407. $query[] = $field.'=0';
  408. $invQuery[] = $field.'!=0';
  409. }
  410. if ($ctrl['enablecolumns']['starttime']) {
  411. $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
  412. $query[] = '('.$field.'<='.$GLOBALS['SIM_ACCESS_TIME'].')';
  413. $invQuery[] = '('.$field.'!=0 AND '.$field.'>'.$GLOBALS['SIM_ACCESS_TIME'].')';
  414. }
  415. if ($ctrl['enablecolumns']['endtime']) {
  416. $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
  417. $query[] = '('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_ACCESS_TIME'].')';
  418. $invQuery[] = '('.$field.'!=0 AND '.$field.'<='.$GLOBALS['SIM_ACCESS_TIME'].')';
  419. }
  420. }
  421. }
  422. $outQ = ($inv ? '(' . implode(' OR ', $invQuery) . ')' : implode(' AND ', $query));
  423. return $outQ ? ' AND ' . $outQ : '';
  424. }
  425. /**
  426. * Fetches the localization for a given record.
  427. *
  428. * @param string $table: Table name present in $TCA
  429. * @param integer $uid: The uid of the record
  430. * @param integer $language: The uid of the language record in sys_language
  431. * @param string $andWhereClause: Optional additional WHERE clause (default: '')
  432. * @return mixed Multidimensional array with selected records; if none exist, false is returned
  433. */
  434. public static function getRecordLocalization($table, $uid, $language, $andWhereClause = '') {
  435. $recordLocalization = false;
  436. if (self::isTableLocalizable($table)) {
  437. $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
  438. $recordLocalization = self::getRecordsByField(
  439. $table,
  440. $tcaCtrl['transOrigPointerField'],
  441. $uid,
  442. 'AND '.$tcaCtrl['languageField'].'='.intval($language).($andWhereClause ? ' '.$andWhereClause : ''),
  443. '',
  444. '',
  445. '1'
  446. );
  447. }
  448. return $recordLocalization;
  449. }
  450. /*******************************************
  451. *
  452. * SQL-related, DEPRECATED functions
  453. * (use t3lib_DB functions instead)
  454. *
  455. *******************************************/
  456. /**
  457. * Returns a SELECT query, selecting fields ($select) from two/three tables joined
  458. * $local_table and $mm_table is mandatory. $foreign_table is optional.
  459. * The JOIN is done with [$local_table].uid <--> [$mm_table].uid_local / [$mm_table].uid_foreign <--> [$foreign_table].uid
  460. * The function is very useful for selecting MM-relations between tables adhering to the MM-format used by TCE (TYPO3 Core Engine). See the section on $TCA in Inside TYPO3 for more details.
  461. *
  462. * @param string Field list for SELECT
  463. * @param string Tablename, local table
  464. * @param string Tablename, relation table
  465. * @param string Tablename, foreign table
  466. * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
  467. * @param string Optional GROUP BY field(s), if none, supply blank string.
  468. * @param string Optional ORDER BY field(s), if none, supply blank string.
  469. * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
  470. * @return string Full SQL query
  471. * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, use $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query() instead since that will return the result pointer while this returns the query. Using this function may make your application less fitted for DBAL later.
  472. * @see t3lib_DB::exec_SELECT_mm_query()
  473. */
  474. public static function mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '') {
  475. t3lib_div::logDeprecatedFunction();
  476. $query = $GLOBALS['TYPO3_DB']->SELECTquery(
  477. $select,
  478. $local_table.','.$mm_table.($foreign_table?','.$foreign_table:''),
  479. $local_table.'.uid='.$mm_table.'.uid_local'.($foreign_table?' AND '.$foreign_table.'.uid='.$mm_table.'.uid_foreign':'').' '.
  480. $whereClause, // whereClauseMightContainGroupOrderBy
  481. $groupBy,
  482. $orderBy,
  483. $limit
  484. );
  485. return $query;
  486. }
  487. /**
  488. * Creates an INSERT SQL-statement for $table from the array with field/value pairs $fields_values.
  489. * DEPRECATED - $GLOBALS['TYPO3_DB']->INSERTquery() directly instead! But better yet, use $GLOBALS['TYPO3_DB']->exec_INSERTquery()
  490. *
  491. * @param string Table name
  492. * @param array Field values as key=>value pairs.
  493. * @return string Full SQL query for INSERT
  494. * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, use $GLOBALS['TYPO3_DB']->exec_INSERTquery() directly!
  495. */
  496. public static function DBcompileInsert($table, $fields_values) {
  497. t3lib_div::logDeprecatedFunction();
  498. return $GLOBALS['TYPO3_DB']->INSERTquery($table, $fields_values);
  499. }
  500. /**
  501. * Creates an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values.
  502. * DEPRECATED - $GLOBALS['TYPO3_DB']->UPDATEquery() directly instead! But better yet, use $GLOBALS['TYPO3_DB']->exec_UPDATEquery()
  503. *
  504. * @param string Database tablename
  505. * @param string WHERE clause, eg. "uid=1"
  506. * @param array Field values as key=>value pairs.
  507. * @return string Full SQL query for UPDATE
  508. * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, use $GLOBALS['TYPO3_DB']->exec_UPDATEquery() directly!
  509. */
  510. public static function DBcompileUpdate($table, $where, $fields_values) {
  511. t3lib_div::logDeprecatedFunction();
  512. return $GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fields_values);
  513. }
  514. /*******************************************
  515. *
  516. * Page tree, TCA related
  517. *
  518. *******************************************/
  519. /**
  520. * 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.
  521. * By default deleted pages are filtered.
  522. * 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.
  523. * Usage: 1
  524. *
  525. * @param integer Page id for which to create the root line.
  526. * @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.
  527. * @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!
  528. * @return array Root line array, all the way to the page tree root (or as far as $clause allows!)
  529. */
  530. public static function BEgetRootLine($uid, $clause = '', $workspaceOL = FALSE) {
  531. static $BEgetRootLine_cache = array();
  532. $output = array();
  533. $pid = $uid;
  534. $ident = $pid . '-' . $clause . '-' . $workspaceOL;
  535. if (is_array($BEgetRootLine_cache[$ident])) {
  536. $output = $BEgetRootLine_cache[$ident];
  537. } else {
  538. $loopCheck = 100;
  539. $theRowArray = array();
  540. while ($uid != 0 && $loopCheck) {
  541. $loopCheck--;
  542. $row = self::getPageForRootline($uid, $clause, $workspaceOL);
  543. if (is_array($row)) {
  544. $uid = $row['pid'];
  545. $theRowArray[] = $row;
  546. } else {
  547. break;
  548. }
  549. }
  550. if ($uid == 0) {
  551. $theRowArray[] = array('uid' => 0, 'title' => '');
  552. }
  553. $c = count($theRowArray);
  554. foreach ($theRowArray as $val) {
  555. $c--;
  556. $output[$c] = array(
  557. 'uid' => $val['uid'],
  558. 'pid' => $val['pid'],
  559. 'title' => $val['title'],
  560. 'TSconfig' => $val['TSconfig'],
  561. 'is_siteroot' => $val['is_siteroot'],
  562. 'storage_pid' => $val['storage_pid'],
  563. 't3ver_oid' => $val['t3ver_oid'],
  564. 't3ver_wsid' => $val['t3ver_wsid'],
  565. 't3ver_state' => $val['t3ver_state'],
  566. 't3ver_swapmode' => $val['t3ver_swapmode'],
  567. 't3ver_stage' => $val['t3ver_stage']
  568. );
  569. if (isset($val['_ORIG_pid'])) {
  570. $output[$c]['_ORIG_pid'] = $val['_ORIG_pid'];
  571. }
  572. }
  573. $BEgetRootLine_cache[$ident] = $output;
  574. }
  575. return $output;
  576. }
  577. /**
  578. * Gets the cached page record for the rootline
  579. *
  580. * @param integer $uid: Page id for which to create the root line.
  581. * @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.
  582. * @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!
  583. * @return array Cached page record for the rootline
  584. * @see BEgetRootLine
  585. */
  586. protected static function getPageForRootline($uid, $clause, $workspaceOL) {
  587. static $getPageForRootline_cache = array();
  588. $ident = $uid . '-' . $clause . '-' . $workspaceOL;
  589. if (is_array($getPageForRootline_cache[$ident])) {
  590. $row = $getPageForRootline_cache[$ident];
  591. } else {
  592. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  593. 'pid,uid,title,TSconfig,is_siteroot,storage_pid,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_swapmode,t3ver_stage',
  594. 'pages',
  595. 'uid=' . intval($uid) . ' ' .
  596. self::deleteClause('pages') . ' ' .
  597. $clause // whereClauseMightContainGroupOrderBy
  598. );
  599. $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
  600. if ($row) {
  601. if ($workspaceOL) {
  602. self::workspaceOL('pages', $row);
  603. }
  604. if (is_array($row)) {
  605. self::fixVersioningPid('pages', $row);
  606. $getPageForRootline_cache[$ident] = $row;
  607. }
  608. }
  609. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  610. }
  611. return $row;
  612. }
  613. /**
  614. * Opens the page tree to the specified page id
  615. *
  616. * @param integer Page id.
  617. * @param boolean If set, then other open branches are closed.
  618. * @return void
  619. */
  620. public static function openPageTree($pid, $clearExpansion) {
  621. global $BE_USER;
  622. // Get current expansion data:
  623. if ($clearExpansion) {
  624. $expandedPages = array();
  625. } else {
  626. $expandedPages = unserialize($BE_USER->uc['browseTrees']['browsePages']);
  627. }
  628. // Get rootline:
  629. $rL = self::BEgetRootLine($pid);
  630. // First, find out what mount index to use (if more than one DB mount exists):
  631. $mountIndex = 0;
  632. $mountKeys = array_flip($BE_USER->returnWebmounts());
  633. foreach($rL as $rLDat) {
  634. if (isset($mountKeys[$rLDat['uid']])) {
  635. $mountIndex = $mountKeys[$rLDat['uid']];
  636. break;
  637. }
  638. }
  639. // Traverse rootline and open paths:
  640. foreach($rL as $rLDat) {
  641. $expandedPages[$mountIndex][$rLDat['uid']] = 1;
  642. }
  643. // Write back:
  644. $BE_USER->uc['browseTrees']['browsePages'] = serialize($expandedPages);
  645. $BE_USER->writeUC();
  646. }
  647. /**
  648. * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
  649. * Each part of the path will be limited to $titleLimit characters
  650. * Deleted pages are filtered out.
  651. * Usage: 15
  652. *
  653. * @param integer Page uid for which to create record path
  654. * @param string $clause is additional where clauses, eg. "
  655. * @param integer Title limit
  656. * @param integer Title limit of Full title (typ. set to 1000 or so)
  657. * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
  658. */
  659. public static function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit = 0) {
  660. if (!$titleLimit) { $titleLimit = 1000; }
  661. $loopCheck = 100;
  662. $output = $fullOutput = '/';
  663. $clause = trim($clause);
  664. if ($clause !== '' && substr($clause, 0, 3) !== 'AND') {
  665. $clause = 'AND ' . $clause;
  666. }
  667. $data = self::BEgetRootLine($uid, $clause);
  668. foreach ($data as $record) {
  669. if ($record['uid'] === 0) {
  670. continue;
  671. }
  672. if ($record['_ORIG_pid'] && $record['t3ver_swapmode'] > 0) { // Branch points
  673. $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...
  674. }
  675. $output = '/' . t3lib_div::fixed_lgd_cs(strip_tags($record['title']), $titleLimit) . $output;
  676. if ($fullTitleLimit) {
  677. $fullOutput = '/' . t3lib_div::fixed_lgd_cs(strip_tags($record['title']), $fullTitleLimit) . $fullOutput;
  678. }
  679. }
  680. if ($fullTitleLimit) {
  681. return array($output, $fullOutput);
  682. } else {
  683. return $output;
  684. }
  685. }
  686. /**
  687. * Returns an array with the exclude-fields as defined in TCA
  688. * Used for listing the exclude-fields in be_groups forms
  689. * Usage: 2 (t3lib_tceforms + t3lib_transferdata)
  690. *
  691. * @return array Array of arrays with excludeFields (fieldname, table:fieldname) from all TCA entries
  692. */
  693. public static function getExcludeFields() {
  694. global $TCA;
  695. // All TCA keys:
  696. $theExcludeArray = Array();
  697. $tc_keys = array_keys($TCA);
  698. foreach($tc_keys as $table) {
  699. // Load table
  700. t3lib_div::loadTCA($table);
  701. // All field names configured:
  702. if (is_array($TCA[$table]['columns'])) {
  703. $f_keys = array_keys($TCA[$table]['columns']);
  704. foreach($f_keys as $field) {
  705. if ($TCA[$table]['columns'][$field]['exclude']) {
  706. // Get Human Readable names of fields and table:
  707. $Fname = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
  708. // add entry:
  709. $theExcludeArray[] = Array($Fname, $table.':'.$field);
  710. }
  711. }
  712. }
  713. }
  714. return $theExcludeArray;
  715. }
  716. /**
  717. * Returns an array with explicit Allow/Deny fields.
  718. * Used for listing these field/value pairs in be_groups forms
  719. *
  720. * @return array Array with information from all of $TCA
  721. */
  722. public static function getExplicitAuthFieldValues() {
  723. global $TCA;
  724. // Initialize:
  725. $adLabel = array(
  726. 'ALLOW' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.allow'),
  727. 'DENY' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.deny'),
  728. );
  729. // All TCA keys:
  730. $allowDenyOptions = Array();
  731. $tc_keys = array_keys($TCA);
  732. foreach($tc_keys as $table) {
  733. // Load table
  734. t3lib_div::loadTCA($table);
  735. // All field names configured:
  736. if (is_array($TCA[$table]['columns'])) {
  737. $f_keys = array_keys($TCA[$table]['columns']);
  738. foreach($f_keys as $field) {
  739. $fCfg = $TCA[$table]['columns'][$field]['config'];
  740. if ($fCfg['type']=='select' && $fCfg['authMode']) {
  741. // Check for items:
  742. if (is_array($fCfg['items'])) {
  743. // Get Human Readable names of fields and table:
  744. $allowDenyOptions[$table.':'.$field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
  745. // Check for items:
  746. foreach($fCfg['items'] as $iVal) {
  747. if (strcmp($iVal[1], '')) { // Values '' is not controlled by this setting.
  748. // Find iMode:
  749. $iMode = '';
  750. switch((string)$fCfg['authMode']) {
  751. case 'explicitAllow':
  752. $iMode = 'ALLOW';
  753. break;
  754. case 'explicitDeny':
  755. $iMode = 'DENY';
  756. break;
  757. case 'individual':
  758. if (!strcmp($iVal[4], 'EXPL_ALLOW')) {
  759. $iMode = 'ALLOW';
  760. } elseif (!strcmp($iVal[4], 'EXPL_DENY')) {
  761. $iMode = 'DENY';
  762. }
  763. break;
  764. }
  765. // Set iMode:
  766. if ($iMode) {
  767. $allowDenyOptions[$table.':'.$field]['items'][$iVal[1]] = array($iMode, $GLOBALS['LANG']->sl($iVal[0]), $adLabel[$iMode]);
  768. }
  769. }
  770. }
  771. }
  772. }
  773. }
  774. }
  775. }
  776. return $allowDenyOptions;
  777. }
  778. /**
  779. * Returns an array with system languages:
  780. *
  781. * @return array Array with languages
  782. */
  783. public static function getSystemLanguages() {
  784. // Initialize, add default language:
  785. $sysLanguages = array();
  786. $sysLanguages[] = array('Default language', 0);
  787. // Traverse languages
  788. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,flag', 'sys_language', 'pid=0' . self::deleteClause('sys_language'));
  789. while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  790. $sysLanguages[] = array(
  791. htmlspecialchars($row['title']) . ' [' . $row['uid'] . ']',
  792. $row['uid'],
  793. ($row['flag'] ? 'flags/' . $row['flag'] : '')
  794. );
  795. }
  796. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  797. return $sysLanguages;
  798. }
  799. /**
  800. * Determines whether a table is localizable and has the languageField and transOrigPointerField set in $TCA.
  801. *
  802. * @param string $table: The table to check
  803. * @return boolean Whether a table is localizable
  804. */
  805. public static function isTableLocalizable($table) {
  806. $isLocalizable = false;
  807. if (isset($GLOBALS['TCA'][$table]['ctrl']) && is_array($GLOBALS['TCA'][$table]['ctrl'])) {
  808. $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
  809. $isLocalizable = (isset($tcaCtrl['languageField']) && $tcaCtrl['languageField'] && isset($tcaCtrl['transOrigPointerField']) && $tcaCtrl['transOrigPointerField']);
  810. }
  811. return $isLocalizable;
  812. }
  813. /**
  814. * Returns the value of the property localizationMode in the given $config array ($TCA[<table>]['columns'][<field>]['config']).
  815. * If the table is prepared for localization and no localizationMode is set, 'select' is returned by default.
  816. * If the table is not prepared for localization or not defined at all in $TCA, false is returned.
  817. *
  818. * @param string $table: The name of the table to lookup in TCA
  819. * @param mixed $fieldOrConfig: The fieldname (string) or the configuration of the field to check (array)
  820. * @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
  821. */
  822. public static function getInlineLocalizationMode($table, $fieldOrConfig) {
  823. $localizationMode = false;
  824. if (is_array($fieldOrConfig) && count($fieldOrConfig)) {
  825. $config = $fieldOrConfig;
  826. } elseif (is_string($fieldOrConfig) && isset($GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'])) {
  827. $config = $GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'];
  828. }
  829. if (is_array($config) && isset($config['type']) && $config['type']=='inline' && self::isTableLocalizable($table)) {
  830. $localizationMode = (isset($config['behaviour']['localizationMode']) && $config['behaviour']['localizationMode'] ? $config['behaviour']['localizationMode'] : 'select');
  831. // The mode 'select' is not possible when child table is not localizable at all:
  832. if ($localizationMode=='select' && !self::isTableLocalizable($config['foreign_table'])) {
  833. $localizationMode = false;
  834. }
  835. }
  836. return $localizationMode;
  837. }
  838. /**
  839. * 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.
  840. * If $id is zero a pseudo root-page with "_thePath" set is returned IF the current BE_USER is admin.
  841. * In any case ->isInWebMount must return true for the user (regardless of $perms_clause)
  842. * Usage: 21
  843. *
  844. * @param integer Page uid for which to check read-access
  845. * @param string $perms_clause is typically a value generated with $BE_USER->getPagePermsClause(1);
  846. * @return array Returns page record if OK, otherwise false.
  847. */
  848. public static function readPageAccess($id, $perms_clause) {
  849. if ((string)$id!='') {
  850. $id = intval($id);
  851. if (!$id) {
  852. if ($GLOBALS['BE_USER']->isAdmin()) {
  853. $path = '/';
  854. $pageinfo['_thePath'] = $path;
  855. return $pageinfo;
  856. }
  857. } else {
  858. $pageinfo = self::getRecord('pages', $id, '*', ($perms_clause ? ' AND ' . $perms_clause : ''));
  859. if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id, $perms_clause)) {
  860. self::workspaceOL('pages', $pageinfo);
  861. if (is_array($pageinfo)) {
  862. self::fixVersioningPid('pages', $pageinfo);
  863. list($pageinfo['_thePath'], $pageinfo['_thePathFull']) = self::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
  864. return $pageinfo;
  865. }
  866. }
  867. }
  868. }
  869. return false;
  870. }
  871. /**
  872. * Returns the "types" configuration parsed into an array for the record, $rec, from table, $table
  873. * Usage: 6
  874. *
  875. * @param string Table name (present in TCA)
  876. * @param array Record from $table
  877. * @param boolean If $useFieldNameAsKey is set, then the fieldname is associative keys in the return array, otherwise just numeric keys.
  878. * @return array
  879. */
  880. public static function getTCAtypes($table, $rec, $useFieldNameAsKey = 0) {
  881. global $TCA;
  882. t3lib_div::loadTCA($table);
  883. if ($TCA[$table]) {
  884. // Get type value:
  885. $fieldValue = self::getTCAtypeValue($table, $rec);
  886. // Get typesConf
  887. $typesConf = $TCA[$table]['types'][$fieldValue];
  888. // Get fields list and traverse it
  889. $fieldList = explode(',', $typesConf['showitem']);
  890. $altFieldList = array();
  891. // Traverse fields in types config and parse the configuration into a nice array:
  892. foreach($fieldList as $k => $v) {
  893. list($pFieldName, $pAltTitle, $pPalette, $pSpec) = t3lib_div::trimExplode(';', $v);
  894. $defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ? $TCA[$table]['columns'][$pFieldName]['defaultExtras'] : '';
  895. $specConfParts = self::getSpecConfParts($pSpec, $defaultExtras);
  896. $fieldList[$k] = array(
  897. 'field' => $pFieldName,
  898. 'title' => $pAltTitle,
  899. 'palette' => $pPalette,
  900. 'spec' => $specConfParts,
  901. 'origString' => $v
  902. );
  903. if ($useFieldNameAsKey) {
  904. $altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
  905. }
  906. }
  907. if ($useFieldNameAsKey) {
  908. $fieldList = $altFieldList;
  909. }
  910. // Return array:
  911. return $fieldList;
  912. }
  913. }
  914. /**
  915. * Returns the "type" value of $rec from $table which can be used to look up the correct "types" rendering section in $TCA
  916. * If no "type" field is configured in the "ctrl"-section of the $TCA for the table, zero is used.
  917. * 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)
  918. * Usage: 7
  919. *
  920. * @param string Table name present in TCA
  921. * @param array Record from $table
  922. * @return string Field value
  923. * @see getTCAtypes()
  924. */
  925. public static function getTCAtypeValue($table, $rec) {
  926. global $TCA;
  927. // 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.
  928. t3lib_div::loadTCA($table);
  929. if ($TCA[$table]) {
  930. $field = $TCA[$table]['ctrl']['type'];
  931. $fieldValue = $field ? ($rec[$field] ? $rec[$field] : 0) : 0;
  932. if (!is_array($TCA[$table]['types'][$fieldValue])) $fieldValue = 1;
  933. return $fieldValue;
  934. }
  935. }
  936. /**
  937. * Parses a part of the field lists in the "types"-section of $TCA arrays, namely the "special configuration" at index 3 (position 4)
  938. * Elements are splitted by ":" and within those parts, parameters are splitted by "|".
  939. * 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
  940. * Usage: 5
  941. *
  942. * @param string Content from the "types" configuration of TCA (the special configuration) - see description of function
  943. * @param string The ['defaultExtras'] value from field configuration
  944. * @return array
  945. */
  946. public static function getSpecConfParts($str, $defaultExtras) {
  947. // Add defaultExtras:
  948. $specConfParts = t3lib_div::trimExplode(':', $defaultExtras.':'.$str, 1);
  949. $reg = array();
  950. if (count($specConfParts)) {
  951. foreach($specConfParts as $k2 => $v2) {
  952. unset($specConfParts[$k2]);
  953. if (preg_match('/(.*)\[(.*)\]/', $v2, $reg)) {
  954. $specConfParts[trim($reg[1])] = array(
  955. 'parameters' => t3lib_div::trimExplode('|', $reg[2], 1)
  956. );
  957. } else {
  958. $specConfParts[trim($v2)] = 1;
  959. }
  960. }
  961. } else {
  962. $specConfParts = array();
  963. }
  964. return $specConfParts;
  965. }
  966. /**
  967. * Takes an array of "[key] = [value]" strings and returns an array with the keys set as keys pointing to the value.
  968. * Better see it in action! Find example in Inside TYPO3
  969. * Usage: 6
  970. *
  971. * @param array Array of "[key] = [value]" strings to convert.
  972. * @return array
  973. */
  974. public static function getSpecConfParametersFromArray($pArr) {
  975. $out = array();
  976. if (is_array($pArr)) {
  977. foreach ($pArr as $k => $v) {
  978. $parts = explode('=', $v, 2);
  979. if (count($parts)==2) {
  980. $out[trim($parts[0])] = trim($parts[1]);
  981. } else {
  982. $out[$k] = $v;
  983. }
  984. }
  985. }
  986. return $out;
  987. }
  988. /**
  989. * Finds the Data Structure for a FlexForm field
  990. * 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.
  991. * Usage: 5
  992. *
  993. * @param array Field config array
  994. * @param array Record data
  995. * @param string The table name
  996. * @param string Optional fieldname passed to hook object
  997. * @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.
  998. * @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)
  999. * @return mixed If array, the data structure was found and returned as an array. Otherwise (string) it is an error message.
  1000. * @see t3lib_TCEforms::getSingleField_typeFlex()
  1001. */
  1002. public static function getFlexFormDS($conf, $row, $table, $fieldName = '', $WSOL = TRUE, $newRecordPidValue = 0) {
  1003. global $TYPO3_CONF_VARS;
  1004. // Get pointer field etc from TCA-config:
  1005. $ds_pointerField = $conf['ds_pointerField'];
  1006. $ds_array = $conf['ds'];
  1007. $ds_tableField = $conf['ds_tableField'];
  1008. $ds_searchParentField = $conf['ds_pointerField_searchParent'];
  1009. // Find source value:
  1010. $dataStructArray = '';
  1011. if (is_array($ds_array)) { // If there is a data source array, that takes precedence
  1012. // If a pointer field is set, take the value from that field in the $row array and use as key.
  1013. if ($ds_pointerField) {
  1014. // Up to two pointer fields can be specified in a comma separated list.
  1015. $pointerFields = t3lib_div::trimExplode(',', $ds_pointerField);
  1016. 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.
  1017. if($ds_array[$row[$pointerFields[0]].','.$row[$pointerFields[1]]]) { // Check if we have a DS for the combination of both pointer fields values
  1018. $srcPointer = $row[$pointerFields[0]].','.$row[$pointerFields[1]];
  1019. } elseif($ds_array[$row[$pointerFields[1]].',*']) { // Check if we have a DS for the value of the first pointer field suffixed with ",*"
  1020. $srcPointer = $row[$pointerFields[1]].',*';
  1021. } elseif($ds_array['*,'.$row[$pointerFields[1]]]) { // Check if we have a DS for the value of the second pointer field prefixed with "*,"
  1022. $srcPointer = '*,'.$row[$pointerFields[1]];
  1023. } 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)
  1024. $srcPointer = $row[$pointerFields[0]];
  1025. }
  1026. } else {
  1027. $srcPointer = $row[$pointerFields[0]];
  1028. }
  1029. $srcPointer = isset($ds_array[$srcPointer]) ? $srcPointer : 'default';
  1030. } else $srcPointer = 'default';
  1031. // 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.
  1032. if (substr($ds_array[$srcPointer], 0, 5)=='FILE:') {
  1033. $file = t3lib_div::getFileAbsFileName(substr($ds_array[$srcPointer], 5));
  1034. if ($file && @is_file($file)) {
  1035. $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
  1036. } else $dataStructArray = 'The file "'.substr($ds_array[$srcPointer], 5).'" in ds-array key "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message.
  1037. } else {
  1038. $dataStructArray = t3lib_div::xml2array($ds_array[$srcPointer]);
  1039. }
  1040. } elseif ($ds_pointerField) { // If pointer field AND possibly a table/field is set:
  1041. // Value of field pointed to:
  1042. $srcPointer = $row[$ds_pointerField];
  1043. // Searching recursively back if 'ds_pointerField_searchParent' is defined (typ. a page rootline, or maybe a tree-table):
  1044. if ($ds_searchParentField && !$srcPointer) {
  1045. $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###
  1046. if ($WSOL) {
  1047. self::workspaceOL($table, $rr);
  1048. 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!
  1049. }
  1050. $uidAcc = array(); // Used to avoid looping, if any should happen.
  1051. $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
  1052. while(!$srcPointer) {
  1053. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  1054. 'uid,'.$ds_pointerField.','.$ds_searchParentField.($subFieldPointer?','.$subFieldPointer:''),

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