PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/t3lib/class.t3lib_tsparser_ext.php

https://bitbucket.org/linxpinx/mercurial
PHP | 1785 lines | 1208 code | 145 blank | 432 comment | 238 complexity | 25bccb7f147060102fbb699cd2f085a1 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0
  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. * TSParser extension class to t3lib_TStemplate
  29. *
  30. * $Id: class.t3lib_tsparser_ext.php 8298 2010-07-27 21:33:35Z steffenk $
  31. * Contains functions for the TS module in TYPO3 backend
  32. *
  33. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  34. */
  35. /**
  36. * [CLASS/FUNCTION INDEX of SCRIPT]
  37. *
  38. *
  39. *
  40. * 105: class t3lib_tsparser_ext extends t3lib_TStemplate
  41. * 191: function flattenSetup($setupArray, $prefix, $resourceFlag)
  42. * 218: function substituteConstants($all)
  43. * 231: function substituteConstantsCallBack($matches)
  44. * 261: function substituteCMarkers($all)
  45. * 284: function generateConfig_constants()
  46. * 330: function ext_getSetup($theSetup,$theKey)
  47. * 358: function ext_getObjTree($arr, $depth_in, $depthData, $parentType='',$parentValue='', $alphaSort='0')
  48. * 463: function lineNumberToScript($lnArr)
  49. * 494: function makeHtmlspecialchars($theValue)
  50. * 507: function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)
  51. * 562: function ext_getRootlineNumber($pid)
  52. * 580: function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0)
  53. * 639: function ext_process_hierarchyInfo($depthDataArr,&$pointer)
  54. * 670: function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0)
  55. * 697: function ext_fixed_lgd($string,$chars)
  56. * 713: function ext_lnBreakPointWrap($ln,$str)
  57. * 726: function ext_formatTS($input, $ln, $comments=1, $crop=0)
  58. * 765: function ext_getFirstTemplate($id,$template_uid=0)
  59. * 785: function ext_getAllTemplates($id)
  60. * 806: function ext_compareFlatSetups($default)
  61. * 872: function ext_categorizeEditableConstants($editConstArray)
  62. * 895: function ext_getCategoryLabelArray()
  63. * 912: function ext_getTypeData($type)
  64. * 953: function ext_getTSCE_config($category)
  65. * 992: function ext_getKeyImage($key)
  66. * 1002: function ext_getTSCE_config_image($imgConf)
  67. * 1026: function ext_resourceDims()
  68. * 1056: function ext_readDirResources($path)
  69. * 1071: function readDirectory($path,$type='file')
  70. * 1096: function ext_fNandV($params)
  71. * 1114: function ext_printFields($theConstants,$category)
  72. *
  73. * SECTION: Processing input values
  74. * 1408: function ext_regObjectPositions($constants)
  75. * 1423: function ext_regObjects($pre)
  76. * 1468: function ext_putValueInConf($key, $var)
  77. * 1491: function ext_removeValueInConf($key)
  78. * 1507: function ext_depthKeys($arr,$settings)
  79. * 1542: function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow)
  80. * 1666: function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name)
  81. * 1715: function ext_prevPageWithTemplate($id,$perms_clause)
  82. * 1731: function ext_setStar($val)
  83. * 1743: function ext_detectAndFixExtensionPrefix($value)
  84. *
  85. * TOTAL FUNCTIONS: 41
  86. * (This index is automatically created/updated by the extension "extdeveval")
  87. *
  88. */
  89. /**
  90. * TSParser extension class to t3lib_TStemplate
  91. *
  92. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  93. * @package TYPO3
  94. * @subpackage t3lib
  95. */
  96. class t3lib_tsparser_ext extends t3lib_TStemplate {
  97. var $edit_divider = '###MOD_TS:EDITABLE_CONSTANTS###'; // This string is used to indicate the point in a template from where the editable constants are listed. Any vars before this point (if it exists though) is regarded as default values.
  98. var $HTMLcolorList = 'aqua,beige,black,blue,brown,fuchsia,gold,gray,green,lime,maroon,navy,olive,orange,purple,red,silver,tan,teal,turquoise,yellow,white';
  99. // internal
  100. var $categories = array(
  101. 'basic' => array(), // Constants of superior importance for the template-layout. This is dimensions, imagefiles and enabling of various features. The most basic constants, which you would almost always want to configure.
  102. 'menu' => array(), // Menu setup. This includes fontfiles, sizes, background images. Depending on the menutype.
  103. 'content' => array(), // All constants related to the display of pagecontent elements
  104. 'page' => array(), // General configuration like metatags, link targets
  105. 'advanced' => array(), // Advanced functions, which are used very seldomly.
  106. 'all' => array() // All constants are put here also!
  107. ); // This will be filled with the available categories of the current template.
  108. var $subCategories = array(
  109. // Standard categories:
  110. 'enable' => Array('Enable features', 'a'),
  111. 'dims' => Array('Dimensions, widths, heights, pixels', 'b'),
  112. 'file' => Array('Files', 'c'),
  113. 'typo' => Array('Typography', 'd'),
  114. 'color' => Array('Colors', 'e'),
  115. 'links' => Array('Links and targets', 'f'),
  116. 'language' => Array('Language specific constants', 'g'),
  117. // subcategories based on the default content elements
  118. 'cheader' => Array('Content: \'Header\'', 'ma'),
  119. 'cheader_g' => Array('Content: \'Header\', Graphical', 'ma'),
  120. 'ctext' => Array('Content: \'Text\'', 'mb'),
  121. 'cimage' => Array('Content: \'Image\'', 'md'),
  122. 'cbullets' => Array('Content: \'Bullet list\'', 'me'),
  123. 'ctable' => Array('Content: \'Table\'', 'mf'),
  124. 'cuploads' => Array('Content: \'Filelinks\'', 'mg'),
  125. 'cmultimedia' => Array('Content: \'Multimedia\'', 'mh'),
  126. 'cmedia' => Array('Content: \'Media\'', 'mr'),
  127. 'cmailform' => Array('Content: \'Form\'', 'mi'),
  128. 'csearch' => Array('Content: \'Search\'', 'mj'),
  129. 'clogin' => Array('Content: \'Login\'', 'mk'),
  130. 'csplash' => Array('Content: \'Textbox\'', 'ml'),
  131. 'cmenu' => Array('Content: \'Menu/Sitemap\'', 'mm'),
  132. 'cshortcut' => Array('Content: \'Insert records\'', 'mn'),
  133. 'clist' => Array('Content: \'List of records\'', 'mo'),
  134. 'cscript' => Array('Content: \'Script\'', 'mp'),
  135. 'chtml' => Array('Content: \'HTML\'', 'mq')
  136. );
  137. var $resourceDimensions = array();
  138. var $dirResources = array();
  139. var $backend_info=1;
  140. // tsconstanteditor
  141. var $ext_inBrace=0;
  142. // tsbrowser
  143. var $tsbrowser_searchKeys = array();
  144. var $tsbrowser_depthKeys = array();
  145. var $constantMode='';
  146. var $regexMode='';
  147. var $fixedLgd='';
  148. var $resourceCheck=0;
  149. var $ext_lineNumberOffset=0;
  150. var $ext_localGfxPrefix='';
  151. var $ext_localWebGfxPrefix='';
  152. var $ext_expandAllNotes=0;
  153. var $ext_noPMicons=0;
  154. var $ext_noSpecialCharsOnLabels=0;
  155. var $ext_listOfTemplatesArr=array();
  156. var $ext_lineNumberOffset_mode='';
  157. var $ext_dontCheckIssetValues=0; // Dont change...
  158. var $ext_noCEUploadAndCopying=0;
  159. var $ext_printAll=0;
  160. var $ext_CEformName='forms[0]';
  161. var $ext_defaultOnlineResourceFlag=0;
  162. var $doNotSortCategoriesBeforeMakingForm = FALSE;
  163. // ts analyzer
  164. var $templateTitles=array();
  165. /**
  166. * This flattens a hierarchical setuparray to $this->flatSetup
  167. * The original function fetched the resource-file if any ('file.'). This functions doesn't.
  168. *
  169. * @param [type] $setupArray: ...
  170. * @param [type] $prefix: ...
  171. * @param [type] $resourceFlag: ...
  172. * @return [type] ...
  173. */
  174. function flattenSetup($setupArray, $prefix, $resourceFlag) {
  175. if (is_array($setupArray)) {
  176. $this->getFileName_backPath=PATH_site; // Setting absolute prefixed path for relative resources.
  177. foreach ($setupArray as $key => $val) {
  178. if ($prefix || substr($key,0,16)!='TSConstantEditor') { // We don't want 'TSConstantEditor' in the flattend setup.
  179. if (is_array($val)) {
  180. $this->flattenSetup($val,$prefix.$key, ($key=='file.'));
  181. } elseif ($resourceFlag && $this->resourceCheck) {
  182. $this->flatSetup[$prefix.$key] = $this->getFileName($val);
  183. if ($this->removeFromGetFilePath && substr($this->flatSetup[$prefix.$key],0,strlen($this->removeFromGetFilePath))==$this->removeFromGetFilePath) {
  184. $this->flatSetup[$prefix.$key] = substr($this->flatSetup[$prefix.$key],strlen($this->removeFromGetFilePath));
  185. }
  186. } else {
  187. $this->flatSetup[$prefix.$key] = $val;
  188. }
  189. }
  190. }
  191. }
  192. }
  193. /**
  194. * [Describe function...]
  195. *
  196. * @param [type] $all: ...
  197. * @return [type] ...
  198. */
  199. function substituteConstants($all) {
  200. $this->Cmarker = substr(md5(uniqid('')),0,6);
  201. return preg_replace_callback('/\{\$(.[^}]+)\}/', array($this, 'substituteConstantsCallBack'), $all);
  202. }
  203. /**
  204. * Call back method for preg_replace_callback in substituteConstants
  205. *
  206. * @param array Regular expression matches
  207. * @return string Replacement
  208. * @see substituteConstants()
  209. */
  210. function substituteConstantsCallBack($matches) {
  211. switch($this->constantMode) {
  212. case 'const':
  213. $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
  214. '##'.$this->Cmarker.'_B##'.$matches[0].'##'.$this->Cmarker.'_E##' :
  215. $matches[0];
  216. break;
  217. case 'subst':
  218. $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
  219. '##'.$this->Cmarker.'_B##'.$this->flatSetup[$matches[1]].'##'.$this->Cmarker.'_E##' :
  220. $matches[0];
  221. break;
  222. case 'untouched':
  223. $ret_val = $matches[0];
  224. break;
  225. default:
  226. $ret_val = isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ?
  227. $this->flatSetup[$matches[1]] :
  228. $matches[0];
  229. }
  230. return $ret_val;
  231. }
  232. /**
  233. * [Describe function...]
  234. *
  235. * @param [type] $all: ...
  236. * @return [type] ...
  237. */
  238. function substituteCMarkers($all) {
  239. switch($this->constantMode) {
  240. case 'const':
  241. $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><strong>', $all);
  242. $all = str_replace('##'.$this->Cmarker.'_E##', '</strong></font>', $all);
  243. break;
  244. case 'subst':
  245. $all = str_replace('##'.$this->Cmarker.'_B##', '<font color="green"><strong>', $all);
  246. $all = str_replace('##'.$this->Cmarker.'_E##', '</strong></font>', $all);
  247. break;
  248. default:
  249. $all = $all;
  250. break;
  251. }
  252. return $all;
  253. }
  254. /**
  255. * Parses the constants in $this->const with respect to the constant-editor in this module.
  256. * In particular comments in the code are registered and the edit_divider is taken into account.
  257. *
  258. * @return [type] ...
  259. */
  260. function generateConfig_constants() {
  261. // These vars are also set lateron...
  262. $this->setup['resources'] = $this->resources;
  263. $this->setup['sitetitle'] = $this->sitetitle;
  264. // parse constants
  265. $constants = t3lib_div::makeInstance('t3lib_TSparser');
  266. $constants->regComments=1; // Register comments!
  267. $constants->setup = $this->const;
  268. $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
  269. /* @var $matchObj t3lib_matchCondition_frontend */
  270. $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_frontend');
  271. $matchObj->setSimulateMatchResult(true); // Matches ALL conditions in TypoScript
  272. $c=0;
  273. $cc=count($this->constants);
  274. foreach ($this->constants as $str) {
  275. $c++;
  276. if ($c==$cc) {
  277. if (strstr($str,$this->edit_divider)) {
  278. $parts = explode($this->edit_divider,$str,2);
  279. $str=$parts[1];
  280. $constants->parse($parts[0],$matchObj);
  281. }
  282. $this->flatSetup = Array();
  283. $this->flattenSetup($constants->setup,'','');
  284. $defaultConstants=$this->flatSetup;
  285. }
  286. $constants->parse($str,$matchObj);
  287. }
  288. $this->flatSetup = Array();
  289. $this->flattenSetup($constants->setup,'','');
  290. $this->setup['constants'] = $constants->setup;
  291. return $this->ext_compareFlatSetups($defaultConstants);
  292. }
  293. /**
  294. * [Describe function...]
  295. *
  296. * @param [type] $theSetup: ...
  297. * @param [type] $theKey: ...
  298. * @return [type] ...
  299. */
  300. function ext_getSetup($theSetup,$theKey) {
  301. $parts = explode('.',$theKey,2);
  302. if (strcmp($parts[0],'') && is_array($theSetup[$parts[0].'.'])) {
  303. if (strcmp(trim($parts[1]),'')) {
  304. return $this->ext_getSetup($theSetup[$parts[0].'.'],trim($parts[1]));
  305. } else {
  306. return array($theSetup[$parts[0].'.'], $theSetup[$parts[0]]);
  307. }
  308. } else {
  309. if (strcmp(trim($theKey),'')) {
  310. return array(array(),$theSetup[$theKey]);
  311. } else {
  312. return array($theSetup,'');
  313. }
  314. }
  315. }
  316. /**
  317. * [Describe function...]
  318. *
  319. * @param [type] $arr: ...
  320. * @param [type] $depth_in: ...
  321. * @param [type] $depthData: ...
  322. * @param [type] $parentType: ...
  323. * @param [type] $parentValue: ...
  324. * @param boolean $alphaSort sorts the array keys / tree by alphabet when set to 1
  325. * @return [type] ...
  326. */
  327. function ext_getObjTree($arr, $depth_in, $depthData, $parentType='',$parentValue='', $alphaSort='0') {
  328. $HTML='';
  329. $a=0;
  330. if($alphaSort == '1') {
  331. ksort($arr);
  332. }
  333. $keyArr_num=array();
  334. $keyArr_alpha=array();
  335. foreach ($arr as $key => $value) {
  336. if (substr($key,-2)!='..') { // Don't do anything with comments / linenumber registrations...
  337. $key=preg_replace('/\.$/','',$key);
  338. if (substr($key,-1)!='.') {
  339. if (t3lib_div::testInt($key)) {
  340. $keyArr_num[$key]=$arr[$key];
  341. } else {
  342. $keyArr_alpha[$key]=$arr[$key];
  343. }
  344. }
  345. }
  346. }
  347. ksort($keyArr_num);
  348. $keyArr=$keyArr_num+$keyArr_alpha;
  349. $c=count($keyArr);
  350. if ($depth_in) {$depth_in = $depth_in.'.';}
  351. foreach ($keyArr as $key => $value) {
  352. $a++;
  353. $depth=$depth_in.$key;
  354. if ($this->bType!='const' || substr($depth,0,1)!='_') { // this excludes all constants starting with '_' from being shown.
  355. $goto = substr(md5($depth),0,6);
  356. $deeper = (is_array($arr[$key.'.']) && ($this->tsbrowser_depthKeys[$depth] || $this->ext_expandAllNotes)) ? 1 : 0;
  357. $PM = 'join';
  358. $LN = ($a==$c)?'blank':'line';
  359. $BTM = ($a==$c)?'bottom':'';
  360. $PM = is_array($arr[$key.'.']) && !$this->ext_noPMicons ? ($deeper ? 'minus':'plus') : 'join';
  361. $HTML.=$depthData;
  362. $theIcon='<img src="'.$GLOBALS['BACK_PATH'].'gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
  363. if ($PM=='join') {
  364. $HTML.=$theIcon;
  365. } else {
  366. $aHref='index.php?id=' . $GLOBALS['SOBE']->id .
  367. '&tsbr[' . $depth.']=' . ($deeper ? 0 : 1) .
  368. (t3lib_div::_GP("breakPointLN") ? '&breakPointLN=' . t3lib_div::_GP("breakPointLN") : '') .
  369. '#' .$goto;
  370. $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
  371. }
  372. $label = $key;
  373. if (t3lib_div::inList('types,resources,sitetitle',$depth) && $this->bType=='setup') { // Read only...
  374. $label='<font color="#666666">'.$label.'</font>';
  375. } else {
  376. if ($this->linkObjects) {
  377. $aHref = 'index.php?id='.$GLOBALS['SOBE']->id .
  378. '&sObj=' . $depth .
  379. (t3lib_div::_GP("breakPointLN") ? '&breakPointLN=' . t3lib_div::_GP("breakPointLN") : '');
  380. if ($this->bType!='const') {
  381. $ln = is_array($arr[$key.'.ln..']) ? 'Defined in: '.$this->lineNumberToScript($arr[$key.'.ln..']) : 'N/A';
  382. } else {
  383. $ln = '';
  384. }
  385. if ($this->tsbrowser_searchKeys[$depth] & 4) { $label = '<strong><font color="red">'.$label.'</font></strong>'; } // The key has matched the search string
  386. $label = '<a href="'.htmlspecialchars($aHref).'" title="'.htmlspecialchars($ln).'">'.$label.'</a>';
  387. }
  388. }
  389. $HTML.='['.$label.']';
  390. if (isset($arr[$key])) {
  391. $theValue = $arr[$key];
  392. if ($this->fixedLgd) {
  393. $imgBlocks = ceil(1+strlen($depthData)/77);
  394. $lgdChars = 68-ceil(strlen('['.$key.']')*0.8)-$imgBlocks*3;
  395. $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
  396. }
  397. if ($this->tsbrowser_searchKeys[$depth] & 2) { // The value has matched the search string
  398. $HTML.='&nbsp;=&nbsp;<strong><font color="red">'.$this->makeHtmlspecialchars($theValue).'</font></strong>';
  399. } else {
  400. $HTML.='&nbsp;=&nbsp;<strong>'.$this->makeHtmlspecialchars($theValue).'</strong>';
  401. }
  402. if ($this->ext_regComments && isset($arr[$key.'..'])) {
  403. $comment = $arr[$key.'..'];
  404. if (!preg_match('/### <INCLUDE_TYPOSCRIPT:.*/', $comment)) { // Skip INCLUDE_TYPOSCRIPT comments, they are almost useless
  405. $comment = preg_replace('/[\r\n]/', ' ', $comment); // Remove linebreaks, replace with ' '
  406. $comment = preg_replace('/[#\*]{2,}/', '', $comment); // Remove # and * if more than twice in a row
  407. $comment = preg_replace('/^[#\*\s]+/', '# ', $comment); // Replace leading # (just if it exists) and add it again. Result: Every comment should be prefixed by a '#'.
  408. $comment = $this->makeHtmlspecialchars($comment); // Masking HTML Tags: Replace < with &lt; and > with &gt;
  409. $HTML.= ' <span class="comment">'.trim($comment).'</span>';
  410. }
  411. }
  412. }
  413. $HTML.='<br />';
  414. if ($deeper) {
  415. $HTML.=$this->ext_getObjTree($arr[$key.'.'], $depth, $depthData.'<img src="'.$GLOBALS['BACK_PATH'].'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />', '' /* not used: $validate_info[$key] */, $arr[$key], $alphaSort);
  416. }
  417. }
  418. }
  419. return $HTML;
  420. }
  421. /**
  422. * [Describe function...]
  423. *
  424. * @param [type] $lnArr: ...
  425. * @return [type] ...
  426. */
  427. function lineNumberToScript($lnArr) {
  428. if (!is_array($this->lnToScript)) {
  429. $this->lnToScript = array();
  430. $c=1;
  431. $c+=substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'],LF)+2;
  432. $this->lnToScript[$c] = '[Default]';
  433. foreach($this->hierarchyInfoToRoot as $info) {
  434. $c+=$info['configLines']+1;
  435. $this->lnToScript[$c] = $info['title'];
  436. }
  437. }
  438. foreach($lnArr as $k => $ln) {
  439. foreach($this->lnToScript as $endLn => $title) {
  440. if ($endLn >= intval($ln)) {
  441. $lnArr[$k] = '"'.$title.'", '.$ln;
  442. break;
  443. }
  444. }
  445. }
  446. return implode('; ',$lnArr);
  447. }
  448. /**
  449. * [Describe function...]
  450. *
  451. * @param [type] $theValue: ...
  452. * @return [type] ...
  453. */
  454. function makeHtmlspecialchars($theValue){
  455. return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
  456. }
  457. /**
  458. * [Describe function...]
  459. *
  460. * @param [type] $arr: ...
  461. * @param [type] $depth_in: ...
  462. * @param [type] $searchString: ...
  463. * @param [type] $keyArray: ...
  464. * @return [type] ...
  465. */
  466. function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray) {
  467. $keyArr=array();
  468. foreach ($arr as $key => $value) {
  469. $key=preg_replace('/\.$/','',$key);
  470. if (substr($key,-1)!='.') {
  471. $keyArr[$key]=1;
  472. }
  473. }
  474. $c=count($keyArr);
  475. if ($depth_in) { $depth_in = $depth_in.'.'; }
  476. foreach ($keyArr as $key => $value) {
  477. $depth=$depth_in.$key;
  478. $deeper = is_array($arr[$key.'.']);
  479. if ($this->regexMode) {
  480. if (preg_match('/'.$searchString.'/',$arr[$key])) { // The value has matched
  481. $this->tsbrowser_searchKeys[$depth]+=2;
  482. }
  483. if (preg_match('/'.$searchString.'/',$key)) { // The key has matched
  484. $this->tsbrowser_searchKeys[$depth]+=4;
  485. }
  486. if (preg_match('/'.$searchString.'/',$depth_in)) { // Just open this subtree if the parent key has matched the search
  487. $this->tsbrowser_searchKeys[$depth]=1;
  488. }
  489. } else {
  490. if (stristr($arr[$key],$searchString)) { // The value has matched
  491. $this->tsbrowser_searchKeys[$depth]+=2;
  492. }
  493. if (stristr($key,$searchString)) { // The key has matches
  494. $this->tsbrowser_searchKeys[$depth]+=4;
  495. }
  496. if (stristr($depth_in,$searchString)) { // Just open this subtree if the parent key has matched the search
  497. $this->tsbrowser_searchKeys[$depth]=1;
  498. }
  499. }
  500. if ($deeper) {
  501. $cS = count($this->tsbrowser_searchKeys);
  502. $keyArray = $this->ext_getSearchKeys($arr[$key.'.'], $depth, $searchString, $keyArray);
  503. if ($cS != count($this->tsbrowser_searchKeys)) {
  504. $keyArray[$depth]=1;
  505. }
  506. }
  507. }
  508. return $keyArray;
  509. }
  510. /**
  511. * [Describe function...]
  512. *
  513. * @param [type] $pid: ...
  514. * @return [type] ...
  515. */
  516. function ext_getRootlineNumber($pid) {
  517. if ($pid && is_array($GLOBALS['rootLine'])) {
  518. foreach ($GLOBALS['rootLine'] as $key => $val) {
  519. if ($val['uid']==$pid) return $key;
  520. }
  521. }
  522. }
  523. /**
  524. * [Describe function...]
  525. *
  526. * @param [type] $arr: ...
  527. * @param [type] $depthData: ...
  528. * @param [type] $keyArray: ...
  529. * @param [type] $first: ...
  530. * @return [type] ...
  531. */
  532. function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0) {
  533. $keyArr=array();
  534. foreach ($arr as $key => $value) {
  535. $key=preg_replace('/\.$/','',$key);
  536. if (substr($key,-1)!='.') {
  537. $keyArr[$key]=1;
  538. }
  539. }
  540. $a=0;
  541. $c=count($keyArr);
  542. static $i;
  543. foreach ($keyArr as $key => $value) {
  544. $HTML = '';
  545. $a++;
  546. $deeper = is_array($arr[$key . '.']);
  547. $row = $arr[$key];
  548. $PM = 'join';
  549. $LN = ($a==$c) ? 'blank' : 'line';
  550. $BTM = ($a==$c) ? 'top' : '';
  551. $PM = 'join';
  552. $HTML .= $depthData;
  553. $alttext = '[' . $row['templateID'] . ']';
  554. $alttext .= $row['pid'] ? ' - ' . t3lib_BEfunc::getRecordPath($row['pid'], $GLOBALS['SOBE']->perms_clause, 20) : '';
  555. $icon = (substr($row['templateID'],0,3) == 'sys' ?
  556. t3lib_iconWorks::getSpriteIconForRecord('sys_template', $row, array('title' => $alttext))
  557. : t3lib_iconWorks::getSpriteIcon('mimetypes-x-content-template-static', array('title' => $alttext))
  558. );
  559. if (in_array($row['templateID'], $this->clearList_const) || in_array($row['templateID'], $this->clearList_setup)) {
  560. $A_B = '<a href="index.php?id=' . $GLOBALS['SOBE']->id . '&template=' . $row['templateID'] . '">';
  561. $A_E = '</a>';
  562. if (t3lib_div::_GP('template') == $row['templateID']) {
  563. $A_B = '<strong>' . $A_B;
  564. $A_E .= '</strong>';
  565. }
  566. } else {
  567. $A_B = '';
  568. $A_E = '';
  569. }
  570. $HTML .= ($first ? '' : '<img src="' . $GLOBALS['BACK_PATH'] . 'gfx/ol/' . $PM . $BTM . '.gif" width="18" height="16" align="top" border="0" />') .
  571. $icon .
  572. $A_B . t3lib_div::fixed_lgd_cs($row['title'], $GLOBALS['BE_USER']->uc['titleLen']) . $A_E . '&nbsp;&nbsp;';
  573. $RL = $this->ext_getRootlineNumber($row['pid']);
  574. $keyArray[] = '<tr class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '">
  575. <td nowrap>' . $HTML . '</td>
  576. <td align="center">' . ($row['root'] ? t3lib_iconWorks::getSpriteIcon('status-status-checked') : '') . '&nbsp;&nbsp;</td>
  577. <td align="center">' . ($row['clConf'] ? t3lib_iconWorks::getSpriteIcon('status-status-checked') :'') . '&nbsp;&nbsp;' . '</td>
  578. <td align="center">' . ($row['clConst'] ? t3lib_iconWorks::getSpriteIcon('status-status-checked') : '') . '&nbsp;&nbsp;' . '</td>
  579. <td align="center">' . ($row['pid'] ? $row['pid'] : '') . '</td>
  580. <td align="center">' . (strcmp($RL, '') ? $RL : '') . '</td>
  581. <td>' . ($row['next'] ? '&nbsp;' . $row['next'] . '&nbsp;&nbsp;' : '') . '</td>
  582. </tr>';
  583. if ($deeper) {
  584. $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key . '.'], $depthData . ($first ? '' : '<img src="' . $GLOBALS['BACK_PATH'] . 'gfx/ol/' . $LN . '.gif" width="18" height="16" align="top" />'), $keyArray);
  585. }
  586. }
  587. return $keyArray;
  588. }
  589. /**
  590. * [Describe function...]
  591. *
  592. * @param [type] $depthDataArr: ...
  593. * @param [type] $pointer: ...
  594. * @return [type] ...
  595. */
  596. function ext_process_hierarchyInfo($depthDataArr,&$pointer) {
  597. $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
  598. while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent) {
  599. $pointer--;
  600. $row = $this->hierarchyInfo[$pointer];
  601. $depthDataArr[$row['templateID']]=$row;
  602. $depthDataArr[$row['templateID']]['bgcolor_setup'] = isset($this->clearList_setup_temp[$row['templateID']])?' class="bgColor5"':'';
  603. $depthDataArr[$row['templateID']]['bgcolor_const'] = isset($this->clearList_const_temp[$row['templateID']])?' class="bgColor5"':'';
  604. unset($this->clearList_setup_temp[$row['templateID']]);
  605. unset($this->clearList_const_temp[$row['templateID']]);
  606. $this->templateTitles[$row['templateID']]=$row['title'];
  607. if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent']) {
  608. $depthDataArr[$row['templateID'].'.'] = $this->ext_process_hierarchyInfo(array(), $pointer);
  609. }
  610. }
  611. return $depthDataArr;
  612. }
  613. /**
  614. * [Describe function...]
  615. *
  616. * @param [type] $config: ...
  617. * @param [type] $lineNumbers: ...
  618. * @param [type] $comments: ...
  619. * @param [type] $crop: ...
  620. * @param [type] $syntaxHL: ...
  621. * @param [type] $syntaxHLBlockmode: ...
  622. * @return [type] ...
  623. */
  624. function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
  625. $all='';
  626. foreach ($config as $str) {
  627. $all .= LF .'[GLOBAL]' . LF . $str;
  628. }
  629. if ($syntaxHL) {
  630. $all = preg_replace('/^[^'.LF.']*./','',$all);
  631. $all = chop($all);
  632. $tsparser = t3lib_div::makeInstance('t3lib_TSparser');
  633. $tsparser->lineNumberOffset=$this->ext_lineNumberOffset+1;
  634. $tsparser->parentObject = $this;
  635. return $tsparser->doSyntaxHighlight($all,$lineNumbers?array($this->ext_lineNumberOffset+1):'',$syntaxHLBlockmode);
  636. } else {
  637. return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
  638. }
  639. }
  640. /**
  641. * Returns a new string of max. $chars lenght
  642. * If the string is longer, it will be truncated and prepended with '...'
  643. * $chars must be an integer of at least 4
  644. *
  645. * @param [type] $string: ...
  646. * @param [type] $chars: ...
  647. * @return [type] ...
  648. */
  649. function ext_fixed_lgd($string,$chars) {
  650. if ($chars >= 4) {
  651. if(strlen($string)>$chars) {
  652. if(strlen($string)>24 && substr($string,0,12) == '##'.$this->Cmarker.'_B##') {
  653. return '##'.$this->Cmarker.'_B##'.t3lib_div::fixed_lgd_cs(substr($string,12,-12), $chars-3).'##'.$this->Cmarker.'_E##';
  654. } else {
  655. return t3lib_div::fixed_lgd_cs($string, $chars-3);
  656. }
  657. }
  658. }
  659. return $string;
  660. }
  661. /**
  662. * [Describe function...]
  663. *
  664. * @param [type] $ln: ...
  665. * @param [type] $str: ...
  666. * @return [type] ...
  667. */
  668. function ext_lnBreakPointWrap($ln,$str) {
  669. return '<a href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
  670. }
  671. /**
  672. * [Describe function...]
  673. *
  674. * @param [type] $input: ...
  675. * @param [type] $ln: ...
  676. * @param [type] $comments: ...
  677. * @param [type] $crop: ...
  678. * @return [type] ...
  679. */
  680. function ext_formatTS($input, $ln, $comments=1, $crop=0) {
  681. $input = preg_replace('/^[^'.LF.']*./','',$input);
  682. $input = chop($input);
  683. $cArr = explode(LF,$input);
  684. $n = ceil(log10(count($cArr)+$this->ext_lineNumberOffset));
  685. $lineNum='';
  686. foreach ($cArr as $k => $v) {
  687. $lln=$k+$this->ext_lineNumberOffset+1;
  688. if ($ln) $lineNum = $this->ext_lnBreakPointWrap($lln,str_replace(' ','&nbsp;',sprintf('% '.$n.'d',$lln))).': ';
  689. $v=htmlspecialchars($v);
  690. if ($crop) {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
  691. $cArr[$k] = $lineNum.str_replace(' ','&nbsp;',$v);
  692. $firstChar = substr(trim($v),0,1);
  693. if ($firstChar=='[') {
  694. $cArr[$k] = '<font color="green"><strong>'.$cArr[$k].'</strong></font>';
  695. } elseif ($firstChar=='/' || $firstChar=='#') {
  696. if ($comments) {
  697. $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
  698. } else {
  699. unset($cArr[$k]);
  700. }
  701. }
  702. }
  703. $output = implode($cArr, '<br />').'<br />';
  704. return $output;
  705. }
  706. /**
  707. * [Describe function...]
  708. *
  709. * @param [type] $id: ...
  710. * @param [type] $template_uid: ...
  711. * @return [type] ...
  712. */
  713. function ext_getFirstTemplate($id,$template_uid=0) {
  714. // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
  715. if (intval($id)) {
  716. if ($template_uid) {
  717. $addC = ' AND uid='.$template_uid;
  718. }
  719. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause, '', 'sorting', '1');
  720. $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
  721. t3lib_BEfunc::workspaceOL('sys_template',$row);
  722. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  723. return $row; // Returns the template row if found.
  724. }
  725. }
  726. /**
  727. * [Describe function...]
  728. *
  729. * @param [type] $id: ...
  730. * @return [type] ...
  731. */
  732. function ext_getAllTemplates($id) {
  733. // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
  734. if (intval($id)) {
  735. $outRes=array();
  736. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause, '', 'sorting');
  737. while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  738. t3lib_BEfunc::workspaceOL('sys_template',$row);
  739. if (is_array($row)) $outRes[] = $row;
  740. }
  741. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  742. return $outRes; // Returns the template rows in an array.
  743. }
  744. }
  745. /**
  746. * This function compares the flattened constants (default and all).
  747. * Returns an array with the constants from the whole template which may be edited by the module.
  748. *
  749. * @param [type] $default: ...
  750. * @return [type] ...
  751. */
  752. function ext_compareFlatSetups($default) {
  753. $editableComments=array();
  754. reset($this->flatSetup);
  755. foreach ($this->flatSetup as $const => $value) {
  756. if (substr($const,-2)!='..' && isset($this->flatSetup[$const.'..'])) {
  757. $comment = trim($this->flatSetup[$const.'..']);
  758. $c_arr = explode(LF,$comment);
  759. foreach ($c_arr as $k => $v) {
  760. $line=trim(preg_replace('/^[#\/]*/','',$v));
  761. if ($line) {
  762. $parts = explode(';', $line);
  763. foreach ($parts as $par) {
  764. if (strstr($par,'=')) {
  765. $keyValPair =explode('=',$par,2);
  766. switch(trim(strtolower($keyValPair[0]))) {
  767. case 'type':
  768. // Type:
  769. /*
  770. int (range; low-high, list: item,item,item = selector),
  771. boolean (check),
  772. string (default),
  773. wrap,
  774. html-color ...,
  775. file
  776. */
  777. $editableComments[$const]['type'] = trim($keyValPair[1]);
  778. break;
  779. case 'cat':
  780. // list of categories.
  781. $catSplit=explode('/',strtolower($keyValPair[1]));
  782. $editableComments[$const]['cat'] = trim($catSplit[0]);
  783. $catSplit[1]=trim($catSplit[1]); // This is the subcategory. Must be a key in $this->subCategories[]. catSplit[2] represents the search-order within the subcat.
  784. if ($catSplit[1] && isset($this->subCategories[$catSplit[1]])) {
  785. $editableComments[$const]['subcat_name']=$catSplit[1];
  786. $editableComments[$const]['subcat']=$this->subCategories[$catSplit[1]][1].'/'.$catSplit[1].'/'.trim($catSplit[2]).'z';
  787. } else {
  788. $editableComments[$const]['subcat']='x'.'/'.trim($catSplit[2]).'z';
  789. }
  790. break;
  791. case 'label':
  792. // label
  793. $editableComments[$const]['label'] = trim($keyValPair[1]);
  794. break;
  795. case 'customsubcategory':
  796. // custom subCategory label
  797. $customSubcategory = explode('=',$keyValPair[1],2);
  798. if (trim($customSubcategory[0])) {
  799. $subCategoryKey = strtolower($customSubcategory[0]);
  800. $this->subCategories[$subCategoryKey][0] = $GLOBALS['LANG']->sL($customSubcategory[1]);
  801. }
  802. break;
  803. }
  804. }
  805. }
  806. }
  807. }
  808. }
  809. if (isset($editableComments[$const])) {
  810. $editableComments[$const]['name']=$const;
  811. $editableComments[$const]['value']=trim($value);
  812. if (isset($default[$const])) {
  813. $editableComments[$const]['default_value']=trim($default[$const]);
  814. }
  815. }
  816. }
  817. return $editableComments;
  818. }
  819. /**
  820. * [Describe function...]
  821. *
  822. * @param [type] $editConstArray: ...
  823. * @return [type] ...
  824. */
  825. function ext_categorizeEditableConstants($editConstArray) {
  826. // Runs through the available constants and fills the $this->categories array with pointers and priority-info
  827. foreach ($editConstArray as $constName => $constData) {
  828. if (!$constData['type']) {
  829. $constData['type']='string';
  830. }
  831. $cats = explode(',',$constData['cat']);
  832. foreach ($cats as $theCat) { // if = only one category, while allows for many. We have agreed on only one category is the most basic way...
  833. $theCat=trim($theCat);
  834. if ($theCat) {
  835. $this->categories[$theCat][$constName]=$constData['subcat'];
  836. }
  837. }
  838. }
  839. }
  840. /**
  841. * [Describe function...]
  842. *
  843. * @return [type] ...
  844. */
  845. function ext_getCategoryLabelArray() {
  846. // Returns array used for labels in the menu.
  847. $retArr = array();
  848. foreach ($this->categories as $k => $v) {
  849. if (count($v)) {
  850. $retArr[$k]=strtoupper($k).' ('.count($v).')';
  851. }
  852. }
  853. return $retArr;
  854. }
  855. /**
  856. * [Describe function...]
  857. *
  858. * @param [type] $type: ...
  859. * @return [type] ...
  860. */
  861. function ext_getTypeData($type) {
  862. $retArr = array();
  863. $type=trim($type);
  864. if (!$type) {
  865. $retArr['type']='string';
  866. } else {
  867. $m=strcspn ($type,' [');
  868. $retArr['type']=strtolower(substr($type,0,$m));
  869. if (t3lib_div::inList('int,options,file,boolean,offset,user', $retArr['type'])) {
  870. $p=trim(substr($type,$m));
  871. $reg = array();
  872. preg_match('/\[(.*)\]/',$p,$reg);
  873. $p=trim($reg[1]);
  874. if ($p) {
  875. $retArr['paramstr']=$p;
  876. switch($retArr['type']) {
  877. case 'int':
  878. if (substr($retArr['paramstr'],0,1)=='-') {
  879. $retArr['params']=t3lib_div::intExplode('-',substr($retArr['paramstr'],1));
  880. $retArr['params'][0]=intval('-'.$retArr['params'][0]);
  881. } else {
  882. $retArr['params']=t3lib_div::intExplode('-',$retArr['paramstr']);
  883. }
  884. $retArr['paramstr']=$retArr['params'][0].' - '.$retArr['params'][1];
  885. break;
  886. case 'options':
  887. $retArr['params']=explode(',',$retArr['paramstr']);
  888. break;
  889. }
  890. }
  891. }
  892. }
  893. return $retArr;
  894. }
  895. /**
  896. * [Describe function...]
  897. *
  898. * @param [type] $category: ...
  899. * @return [type] ...
  900. */
  901. function ext_getTSCE_config($category) {
  902. $catConf=$this->setup['constants']['TSConstantEditor.'][$category.'.'];
  903. $out=array();
  904. if (is_array($catConf)) {
  905. foreach ($catConf as $key => $val) {
  906. switch($key) {
  907. case 'image':
  908. $out['imagetag'] = $this->ext_getTSCE_config_image($catConf['image']);
  909. break;
  910. case 'description':
  911. case 'bulletlist':
  912. case 'header':
  913. $out[$key] = $val;
  914. break;
  915. default:
  916. if (t3lib_div::testInt($key)) {
  917. $constRefs = explode(',',$val);
  918. foreach ($constRefs as $const) {
  919. $const=trim($const);
  920. if ($const && $const<=20) {
  921. $out['constants'][$const].=$this->ext_getKeyImage($key);
  922. }
  923. }
  924. }
  925. break;
  926. }
  927. }
  928. }
  929. $this->helpConfig=$out;
  930. }
  931. /**
  932. * [Describe function...]
  933. *
  934. * @param [type] $key: ...
  935. * @return [type] ...
  936. */
  937. function ext_getKeyImage($key) {
  938. return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
  939. }
  940. /**
  941. * [Describe function...]
  942. *
  943. * @param [type] $imgConf: ...
  944. * @return [type] ...
  945. */
  946. function ext_getTSCE_config_image($imgConf) {
  947. if (substr($imgConf,0,4)=='gfx/') {
  948. $iFile=$this->ext_localGfxPrefix.$imgConf;
  949. $tFile=$this->ext_localWebGfxPrefix.$imgConf;
  950. } elseif (substr($imgConf,0,4)=='EXT:') {
  951. $iFile = t3lib_div::getFileAbsFileName($imgConf);
  952. if ($iFile) {
  953. $f = substr($iFile,strlen(PATH_site));
  954. $tFile=$GLOBALS['BACK_PATH'].'../'.$f;
  955. }
  956. } else {
  957. $f = 'uploads/tf/'.$this->extractFromResources($this->setup['resources'],$imgConf);
  958. $iFile=PATH_site.$f;
  959. $tFile=$GLOBALS['BACK_PATH'].'../'.$f;
  960. }
  961. $imageInfo=@getImagesize($iFile);
  962. return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
  963. }
  964. /**
  965. * [Describe function...]
  966. *
  967. * @return [type] ...
  968. */
  969. function ext_resourceDims() {
  970. if ($this->setup['resources']) {
  971. $rArr=explode(',',$this->setup['resources']);
  972. foreach ($rArr as $c => $val) {
  973. $val=trim($val);
  974. $theFile = PATH_site.'uploads/tf/'.$val;
  975. if ($val && @is_file($theFile)) {
  976. $imgInfo = @getimagesize($theFile);
  977. }
  978. if (is_array($imgInfo)) {
  979. $this->resourceDimensions[$val]=' ('.$imgInfo[0].'x'.$imgInfo[1].')';
  980. }
  981. }
  982. }
  983. foreach ($this->dirResources as $c => $val) {
  984. $val=trim($val);
  985. $imgInfo = @getimagesize(PATH_site.$val);
  986. if (is_array($imgInfo)) {
  987. $this->resourceDimensions[$val]=' ('.$imgInfo[0].'x'.$imgInfo[1].')';
  988. }
  989. }
  990. }
  991. /**
  992. * [Describe function...]
  993. *
  994. * @param [type] $path: ...
  995. * @return [type] ...
  996. */
  997. function ext_readDirResources($path) {
  998. $path = trim($path);
  999. if ($path && strstr($path, $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'])) {
  1000. $path = rtrim($path, '/');
  1001. $this->readDirectory(PATH_site . $path);
  1002. }
  1003. }
  1004. /**
  1005. * [Describe function...]
  1006. *
  1007. * @param [type] $path: ...
  1008. * @param [type] $type: ...
  1009. * @return [type] ...
  1010. */
  1011. function readDirectory($path,$type='file') {
  1012. if(@is_dir($path)) {
  1013. $d = @dir($path);
  1014. $tempArray=Array();
  1015. if (is_object($d)) {
  1016. while($entry=$d->read()) {
  1017. if ($entry!='.' && $entry!='..') {
  1018. $wholePath = $path.'/'.$entry; // Because of odd PHP-error where <BR>-tag is sometimes placed after a filename!!
  1019. if (file_exists($wholePath) && (!$type || filetype($wholePath)==$type)) {
  1020. $fI = t3lib_div::split_fileref($wholePath);
  1021. $this->dirResources[]=substr($wholePath,strlen(PATH_site));
  1022. }
  1023. }
  1024. }
  1025. $d->close();
  1026. }
  1027. }
  1028. }
  1029. /**
  1030. * [Describe function...]
  1031. *
  1032. * @param [type] $params: ...
  1033. * @return [type] ...
  1034. */
  1035. function ext_fNandV($params) {
  1036. $fN='data['.$params['name'].']';
  1037. $fV=$params['value'];
  1038. if (preg_match('/^{[\$][a-zA-Z0-9\.]*}$/',trim($fV),$reg)) { // Values entered from the constantsedit cannot be constants! 230502; removed \{ and set {
  1039. $fV='';
  1040. }
  1041. $fV=htmlspecialchars($fV);
  1042. return array($fN,$fV,$params);
  1043. }
  1044. /**
  1045. * This functions returns the HTML-code that creates the editor-layout of the module.
  1046. *
  1047. * @param [type] $theConstants: ...
  1048. * @param [type] $category: ...
  1049. * @return [type] ...
  1050. */
  1051. function ext_printFields($theConstants,$category) {
  1052. reset($theConstants);
  1053. $output='<script type="text/javascript" src="'.$GLOBALS['BACK_PATH'].'js/constantEditor.js"></script>
  1054. ';
  1055. $subcat='';
  1056. if (is_array($this->categories[$category])) {
  1057. $help=$this->helpConfig;
  1058. $this->rArr=explode(',',$this->setup['resources'].','.implode($this->dirResources,','));
  1059. if (!$this->doNotSortCategoriesBeforeMakingForm) asort($this->categories[$category]);
  1060. foreach ($this->categories[$category] as $name => $type) {
  1061. $params = $theConstants[$name];
  1062. if (is_array($params)) {
  1063. if ($subcat!=$params['subcat_name']) {
  1064. $subcat=$params['subcat_name'];
  1065. $subcat_name = $params['subcat_name'] ? $this->subCategories[$params['subcat_name']][0] : 'Others';
  1066. $output.='<h2 class="typo3-tstemplate-ceditor-subcat">'.$subcat_name.'</h2>';
  1067. }
  1068. $label=$GLOBALS['LANG']->sL($params['label']);
  1069. $label_parts = explode(':',$label,2);
  1070. if (count($label_parts)==2) {
  1071. $head=trim($label_parts[0]);
  1072. $body=trim($label_parts[1]);
  1073. } else {
  1074. $head=trim($label_parts[0]);
  1075. $body='';
  1076. }
  1077. if (strlen($head)>35) {
  1078. if (!$body) {$body=$head;}
  1079. $head=t3lib_div::fixed_lgd_cs($head,35);
  1080. }
  1081. $typeDat=$this->ext_getTypeData($params['type']);
  1082. $checked='';
  1083. $p_field='';
  1084. $raname = substr(md5($params['name']),0,10);
  1085. $aname='\''.$raname.'\'';
  1086. list($fN,$fV,$params)=$this->ext_fNandV($params);
  1087. switch($typeDat['type']) {
  1088. case 'int':
  1089. case 'int+':
  1090. $p_field='<input id="'.$fN.'" type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).' onChange="uFormUrl('.$aname.')" />';
  1091. if ($typeDat['paramstr']) {
  1092. $p_field.=' Range: '.$typeDat['paramstr'];
  1093. } elseif ($typeDat['type']=='int+') {
  1094. $p_field.=' Range: 0 - ';
  1095. } else {
  1096. $p_field.=' (Integer)';
  1097. }
  1098. break;
  1099. case 'color':
  1100. $colorNames=explode(',',','.$this->HTMLcolorList);
  1101. $p_field='';
  1102. foreach ($colorNames as $val) {
  1103. $sel='';
  1104. if ($val==strtolower($params['value'])) {
  1105. $sel = ' selected';
  1106. }
  1107. $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.'</option>';
  1108. }
  1109. $p_field='<select id="select-'.$fN.'" rel="'.$fN.'" name="C'.$fN.'" class="typo3-tstemplate-ceditor-color-select" onChange="uFormUrl('.$aname.');">'.$p_field.'</select>';
  1110. $p_field.='<input type="text" id="input-'.$fN.'" rel="'.$fN.'" name="'.$fN.'" class="typo3-tstemplate-ceditor-color-input" value="'.$fV.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(7).' onChange="uFormUrl('.$aname.')" />';
  1111. break;
  1112. case 'wrap':
  1113. $wArr = explode('|',$fV);
  1114. $p_field='<input type="text" id="'.$fN.'" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(29).' onChange="uFormUrl('.$aname.')" />';
  1115. $p_field.=' | ';
  1116. $p_field.='<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(15).' onChange="uFormUrl('.$aname.')" />';
  1117. break;
  1118. case 'offset':
  1119. $wArr = explode(',',$fV);
  1120. $labels = t3lib_div::trimExplode(',',$typeDat['paramstr']);
  1121. $p_field=($labels[0]?$labels[0]:'x').':<input type="text" name="'.$fN.'" value="'.$wArr[0].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' onChange="uFormUrl('.$aname.')" />';
  1122. $p_field.=' , ';
  1123. $p_field.=($labels[1]?$labels[1]:'y').':<input type="text" name="W'.$fN.'" value="'.$wArr[1].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' onChange="uFormUrl('.$aname.')" />';
  1124. for ($aa=2;$aa<count($labels);$aa++) {
  1125. if ($labels[$aa]) {
  1126. $p_field.=' , '.$labels[$aa].':<input type="text" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' onChange="uFormUrl('.$aname.')" />';
  1127. } else {
  1128. $p_field.='<input type="hidden" name="W'.$aa.$fN.'" value="'.$wArr[$aa].'" />';
  1129. }
  1130. }
  1131. break;
  1132. case 'options':
  1133. if (is_array($typeDat['params'])) {
  1134. $p_field='';
  1135. foreach ($typeDat['params'] as $val) {
  1136. $vParts = explode('=',$val,2);
  1137. $label = $vParts[0];
  1138. $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
  1139. // option tag:
  1140. $sel='';
  1141. if ($val==$params['value']) {
  1142. $sel=' selected';
  1143. }
  1144. $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$GLOBALS['LANG']->sL($label).'</option>';
  1145. }
  1146. $p_field='<select id="'.$fN.'" name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
  1147. }
  1148. break;
  1149. case 'boolean':
  1150. $p_field='<input type="hidden" name="'.$fN.'" value="0" />';
  1151. $sel='';
  1152. if ($fV) {
  1153. $sel=' checked';
  1154. }
  1155. $p_field.='<input id="'.$fN.'" type="checkbox" name="'.$fN.'" value="'.($typeDat['paramstr']?$typeDat['paramstr']:1).'"'.$sel.' onClick="uFormUrl('.$aname.')" />';
  1156. break;
  1157. case 'comment':
  1158. $p_field='<input type="hidden" name="'.$fN.'" value="#" />';
  1159. $sel='';
  1160. if (!$fV) {
  1161. $sel=' checked';
  1162. }
  1163. $p_field.='<input id="'.$fN.'" type="checkbox" name="'.$fN.'" value=""'.$sel.' onClick="uFormUrl('.$aname.')" />';
  1164. break;
  1165. case 'file':
  1166. $p_field='<option value=""></option>';
  1167. $theImage='';
  1168. $selectThisFile = $this->extractFromResources($this->setup['resources'],$params['value']);
  1169. if ($params['value'] && !$selectThisFile) {
  1170. if (in_array($params['value'],$this->dirResources)) {
  1171. $selectThisFile=$params['value'];
  1172. }
  1173. }
  1174. // extensionlist
  1175. $extList = $typeDat['paramstr'];
  1176. $p_field='<option value="">('.$extList.')</option>';
  1177. if ($extList=='IMAGE_EXT') {
  1178. $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
  1179. }
  1180. reset($this->rArr);
  1181. $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag;
  1182. foreach ($this->rArr as $c => $val) {
  1183. $val=trim($val);
  1184. $fI=t3lib_div::split_fileref($val);
  1185. if ($val && (!$extList || t3lib_div::inList($extList,$fI['fileext']))) {
  1186. if ($onlineResourceFlag <= 0 && strstr($fI['path'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'])) {
  1187. if ($onlineResourceFlag<0) {
  1188. $p_field.='<option value=""></option>';
  1189. }
  1190. $p_field.='<option value="">__'.$fI['path'].'__:</option>';
  1191. $onlineResourceFlag=1;
  1192. }
  1193. $dims=$this->resourceDimensions[$val];
  1194. $sel='';
  1195. // Check if $params['value'] is in the list of resources.
  1196. if ($selectThisFile && $selectThisFile==$val) {
  1197. $sel=' selected';
  1198. if ($onlineResourceFlag<=0) {
  1199. $theImage=t3lib_BEfunc::thumbCode(array('resources'=>$selectThisFile),'sys_template','resources',$GLOBALS['BACK_PATH'],'');
  1200. } else {
  1201. $theImage=t3lib_BEfunc::thumbCode(array('resources'=>$fI['file']),'sys_template','resources',$GLOBALS['BACK_PATH'],'',$fI['path']);
  1202. }
  1203. }
  1204. if ($onlineResourceFlag<=0) {
  1205. $onlineResourceFlag--;
  1206. // Value is set with a *
  1207. $val = $this->ext_setStar($val);
  1208. $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$val.$dims.'</option>';
  1209. } else {
  1210. $p_field.='<option value="'.htmlspecialchars($val).'"'.$sel.'>'.$fI['file'].$dims.'</option>';
  1211. }
  1212. }
  1213. }
  1214. if (trim($params['value']) && !$selectThisFile) {
  1215. $val = $params['value'];
  1216. $p_field.='<option value=""></option>';
  1217. $p_field.='<option value="'.htmlspecialchars($val).'" selected>'.$val.'</option>';
  1218. }
  1219. $p_field='<select id="'.$fN.'" name="'.$fN.'" onChange="uFormUrl('.$aname.')">'.$p_field.'</select>';
  1220. $p_field.=$theImage;
  1221. if (!$this->ext_noCEUploadAndCopying) {
  1222. // Copy a resource
  1223. $copyFile = $this->extractFromResources($this->setup['resources'],$params['value']);
  1224. if (!$copyFile) {
  1225. if ($params['value']) {
  1226. $copyFile=PATH_site.$this->ext_detectAndFixExtensionPrefix($params['value']);
  1227. }
  1228. } else {
  1229. $copyFile='';
  1230. }
  1231. if ($copyFile && @is_file($copyFile)) {
  1232. $p_field .= '<img src="clear.gif" width="20" ' . 'height="1" alt="" />' . t3lib_iconWorks::getSpriteIcon('actions-edit-copy') . '<input type="checkbox" ' . 'name="_copyResource[' . $params['name'] . ']" value="' . htmlspecialchars($copyFile) . '" onclick="uFormUrl(' . $aname . ');if (this.checked && !confirm(\'' . t3lib_div::slashJS(htmlspecialchars(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tsparser.xml:tsparser_ext.make_copy'), $params['value']))) . '\')) this.checked=false;" />';
  1233. }
  1234. // Upload?
  1235. $p_field.='<br />';
  1236. $p_field.='<input id="'.$fN.'" type="file" name="upload_'.$fN.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth().' onChange="uFormUrl('.$aname.')" size="50" />';
  1237. }
  1238. break;
  1239. case 'user':
  1240. $userFunction = $typeDat['paramstr'];
  1241. $userFunctionParams = array('fieldName' => $fN, 'fieldValue' => $fV);
  1242. $p_field = t3lib_div::callUserFunction($userFunction, $userFunctionParams, $this, '');
  1243. break;
  1244. case 'small':
  1245. default:
  1246. $fwidth= $typeDat['type']=='small' ? 10 : 46;
  1247. $p_field='<input id="'.$fN.'" type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth($fwidth).' onChange="uFormUrl('.$aname.')" />';
  1248. break;
  1249. }
  1250. // Define default names and IDs
  1251. $userTyposcriptID = 'userTS-'.$params['name'];
  1252. $defaultTyposcriptID = 'defaultTS-'.$params['name'];
  1253. $checkboxName = 'check['.$params['name'].']';
  1254. $checkboxID = $checkboxName;
  1255. // Handle type=color specially
  1256. if ($typeDat['type']=='color' && substr($params['value'],0,2)!='{$') {
  1257. $color = '<div id="colorbox-'.$fN.'" class="typo3-tstemplate-ceditor-colorblock" style="background-color:'.$params['value'].';">&nbsp;</div>';
  1258. } else {
  1259. $color = '';
  1260. }
  1261. if (!$this->ext_dontCheckIssetValues) {
  1262. /* Set the default styling options */
  1263. if(isset($this->objReg[$params['name']])) {
  1264. $checkboxValue = 'checked';
  1265. $userTyposcriptStyle = '';
  1266. $defaultTyposcriptStyle = 'style="display:none;"';
  1267. } else {
  1268. $checkboxValue = '';
  1269. $userTyposcriptStyle = 'style="display:none;"';
  1270. $defaultTyposcriptStyle = '';
  1271. }
  1272. $deleteIconHTML = t3lib_iconWorks::getSpriteIcon('actions-edit-undo',array('class'=>"typo3-tstemplate-ceditor-control undoIcon",'alt'=>"Revert to default Constant",'title'=>"Revert to default Constant",'rel'=>$params['name']));
  1273. $editIconHTML = t3lib_iconWorks::getSpriteIcon('actions-document-open',array('class'=>"typo3-tstemplate-ceditor-control editIcon",'alt'=>"Edit this Constant",'title'=>"Edit this Constant",'rel'=>$params['name']));
  1274. $constantCheckbox = '<input type="hidden" name="'.$checkboxName.'" id="'.$checkboxID.'" value="'.$checkboxValue.'"/>';
  1275. // If there's no default value for the field, use a static label.
  1276. if(!$params['default_value']) {
  1277. $params['default_value'] = '[Empty]';
  1278. }
  1279. $constantDefaultRow='<div class="typo3-tstemplate-ceditor-row" id="'.$defaultTyposcriptID.'" '.$defaultTyposcriptStyle.'>'.$editIconHTML.htmlspecialchars($params['default_value']).$color.'</div>';
  1280. }
  1281. $constantEditRow = '<div class="typo3-tstemplate-ceditor-row" id="'.$userTyposcriptID.'" '.$userTyposcriptStyle.'>'.$deleteIconHTML.$p_field.$color.'</div>';
  1282. $constantLabel = '<dt class="typo3-tstemplate-ceditor-label">'.htmlspecialchars($head).'</dt>';
  1283. $constantName = '<dt class="typo3-dimmed">['.$params['name'].']</dt>';
  1284. $constantDescription = $body ? '<dd>'.htmlspecialchars($body).'</dd>' : '';
  1285. $constantData = '<dd>'.$constantCheckbox.$constantEditRow.$constantDefaultRow.'</dd>';
  1286. $output.='<a name="'.$raname.'"></a>'.$help['constants'][$params['name']];
  1287. $output.='<dl class="typo3-tstemplate-ceditor-constant">'.$constantLabel.$constantName.$constantDescription.$constantData.'</dl>';
  1288. } else {
  1289. debug('Error. Constant did not exist. Should not happen.');
  1290. }
  1291. }
  1292. }
  1293. return $output;
  1294. }
  1295. /***************************
  1296. *
  1297. * Processing input values
  1298. *
  1299. ***************************/
  1300. /**
  1301. * @param [type] $constants: ...
  1302. * @return [type] ...
  1303. */
  1304. function ext_regObjectPositions($constants) {
  1305. // This runs through the lines of the constants-field of the active template and registers the constants-names and linepositions in an array, $this->objReg
  1306. $this->raw = explode(LF,$constants);
  1307. $this->rawP=0;
  1308. $this->objReg=array(); // resetting the objReg if the divider is found!!
  1309. $this->ext_regObjects('');
  1310. }
  1311. /**
  1312. * [Describe function...]
  1313. *
  1314. * @param [type] $pre: ...
  1315. * @return [type] ...
  1316. */
  1317. function ext_regObjects($pre) {
  1318. // works with regObjectPositions. "expands" the names of the TypoScript objects
  1319. while (isset($this->raw[$this->rawP])) {
  1320. $line = ltrim($this->raw[$this->rawP]);
  1321. if (strstr($line,$this->edit_divider)) {
  1322. $this->objReg=array(); // resetting the objReg if the divider is found!!
  1323. }
  1324. $this->rawP++;
  1325. if ($line) {
  1326. if (substr($line,0,1)=='[') {
  1327. // return $line;
  1328. } elseif (strcspn($line,'}#/')!=0) {
  1329. $varL = strcspn($line,' {=<');
  1330. $var=substr($line,0,$varL);
  1331. $line = ltrim(substr($line,$varL));
  1332. switch(substr($line,0,1)) {
  1333. case '=':
  1334. $this->objReg[$pre.$var]=$this->rawP-1;
  1335. break;
  1336. case '{':
  1337. $this->ext_inBrace++;
  1338. $this->ext_regObjects($pre.$var.'.');
  1339. break;
  1340. }
  1341. $this->lastComment='';
  1342. } elseif (substr($line,0,1)=='}') {
  1343. $this->lastComment='';
  1344. $this->ext_inBrace--;
  1345. if ($this->ext_inBrace<0) {
  1346. $this->ext_inBrace=0;
  1347. } else {
  1348. break;
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. /**
  1355. * [Describe function...]
  1356. *
  1357. * @param [type] $key: ...
  1358. * @param [type] $var: ...
  1359. * @return [type] ...
  1360. */
  1361. function ext_putValueInConf($key, $var) {
  1362. // Puts the value $var to the TypoScript value $key in the current lines of the templates.
  1363. // If the $key is not found in the template constants field, a new line is inserted in the bottom.
  1364. $theValue = ' '.trim($var);
  1365. if (isset($this->objReg[$key])) {
  1366. $lineNum = $this->objReg[$key];
  1367. $parts = explode('=',$this->raw[$lineNum],2);
  1368. if (count($parts)==2) {
  1369. $parts[1]= $theValue;
  1370. }
  1371. $this->raw[$lineNum]=implode($parts,'=');
  1372. } else {
  1373. $this->raw[]=$key.' ='.$theValue;
  1374. }
  1375. $this->changed=1;
  1376. }
  1377. /**
  1378. * [Describe function...]
  1379. *
  1380. * @param [type] $key: ...
  1381. * @return [type] ...
  1382. */
  1383. function ext_removeValueInConf($key) {
  1384. // Removes the value in the configuration
  1385. if (isset($this->objReg[$key])) {
  1386. $lineNum = $this->objReg[$key];
  1387. unset($this->raw[$lineNum]);
  1388. }
  1389. $this->changed=1;
  1390. }
  1391. /**
  1392. * [Describe function...]
  1393. *
  1394. * @param [type] $arr: ...
  1395. * @param [type] $settings: ...
  1396. * @return [type] ...
  1397. */
  1398. function ext_depthKeys($arr,$settings) {
  1399. $tsbrArray=array();
  1400. foreach ($arr as $theK => $theV) {
  1401. $theKeyParts = explode('.',$theK);
  1402. $depth='';
  1403. $c=count($theKeyParts);
  1404. $a=0;
  1405. foreach ($theKeyParts as $p) {
  1406. $a++;
  1407. $depth.=($depth?'.':'').$p;
  1408. $tsbrArray[$depth]= ($c==$a) ? $theV : 1;
  1409. }
  1410. }
  1411. // Modify settings
  1412. foreach ($tsbrArray as $theK => $theV) {
  1413. if ($theV) {
  1414. $settings[$theK] = 1;
  1415. } else {
  1416. unset($settings[$theK]);
  1417. }
  1418. }
  1419. return $settings;
  1420. }
  1421. /**
  1422. * [Describe function...]
  1423. *
  1424. * @param [type] $http_post_vars: ...
  1425. * @param [type] $http_post_files: ...
  1426. * @param [type] $theConstants: ...
  1427. * @param [type] $tplRow: ...
  1428. * @return [type] ...
  1429. */
  1430. function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow) {
  1431. $data=$http_post_vars['data'];
  1432. $check=$http_post_vars['check'];
  1433. $copyResource=$http_post_vars['_copyResource'];
  1434. $Wdata=$http_post_vars['Wdata'];
  1435. $W2data=$http_post_vars['W2data'];
  1436. $W3data=$http_post_vars['W3data'];
  1437. $W4data=$http_post_vars['W4data'];
  1438. $W5data=$http_post_vars['W5data'];
  1439. if (is_array($data)) {
  1440. foreach ($data as $key => $var) {
  1441. if (isset($theConstants[$key])) {
  1442. if ($this->ext_dontCheckIssetValues || isset($check[$key])) { // If checkbox is set, update the value
  1443. list($var) = explode(LF,$var); // exploding with linebreak, just to make sure that no multiline input is given!
  1444. $typeDat=$this->ext_getTypeData($theConstants[$key]['type']);
  1445. switch($typeDat['type']) {
  1446. case 'int':
  1447. if ($typeDat['paramstr']) {
  1448. $var=t3lib_div::intInRange($var,$typeDat['params'][0],$typeDat['params'][1]);
  1449. } else {
  1450. $var=intval($var);
  1451. }
  1452. break;
  1453. case 'int+':
  1454. $var = max(0, intval($var));
  1455. break;
  1456. case 'color':
  1457. $col=array();
  1458. if($var && !t3lib_div::inList($this->HTMLcolorList,strtolower($var))) {
  1459. $var = preg_replace('/[^A-Fa-f0-9]*/','',$var);
  1460. $useFullHex = strlen($var) > 3;
  1461. $col[]=HexDec(substr($var,0,1));
  1462. $col[]=HexDec(substr($var,1,1));
  1463. $col[]=HexDec(substr($var,2,1));
  1464. if($useFullHex) {
  1465. $col[]=HexDec(substr($var,3,1));
  1466. $col[]=HexDec(substr($var,4,1));
  1467. $col[]=HexDec(substr($var,5,1));
  1468. }
  1469. $var = substr('0'.DecHex($col[0]),-1).substr('0'.DecHex($col[1]),-1).substr('0'.DecHex($col[2]),-1);
  1470. if($useFullHex) {
  1471. $var .= substr('0'.DecHex($col[3]),-1).substr('0'.DecHex($col[4]),-1).substr('0'.DecHex($col[5]),-1);
  1472. }
  1473. $var = '#'.strtoupper($var);
  1474. }
  1475. break;
  1476. case 'comment':
  1477. if ($var) {
  1478. $var='#';
  1479. } else {
  1480. $var='';
  1481. }
  1482. break;
  1483. case 'wrap':
  1484. if (isset($Wdata[$key])) {
  1485. $var.='|'.$Wdata[$key];
  1486. }
  1487. break;
  1488. case 'offset':
  1489. if (isset($Wdata[$key])) {
  1490. $var=intval($var).','.intval($Wdata[$key]);
  1491. if (isset($W2data[$key])) {
  1492. $var.=','.intval($W2data[$key]);
  1493. if (isset($W3data[$key])) {
  1494. $var.=','.intval($W3data[$key]);
  1495. if (isset($W4data[$key])) {
  1496. $var.=','.intval($W4data[$key]);
  1497. if (isset($W5data[$key])) {
  1498. $var.=','.intval($W5data[$key]);
  1499. }
  1500. }
  1501. }
  1502. }
  1503. }
  1504. break;
  1505. case 'boolean':
  1506. if ($var) {
  1507. $var = $typeDat['paramstr'] ? $typeDat['paramstr'] : 1;
  1508. }
  1509. break;
  1510. case 'file':
  1511. if (!$this->ext_noCEUploadAndCopying) {
  1512. if ($http_post_files['upload_data']['name'][$key] && $http_post_files['upload_data']['tmp_name'][$key]!='none') {
  1513. $var = $this->upload_copy_file(
  1514. $typeDat,
  1515. $tplRow,
  1516. trim($http_post_files['upload_data']['name'][$key]),
  1517. $http_post_files['upload_data']['tmp_name'][$key]
  1518. );
  1519. }
  1520. if ($copyResource[$key]) {
  1521. $var = $this->upload_copy_file(
  1522. $typeDat,
  1523. $tplRow,
  1524. basename($copyResource[$key]),
  1525. $copyResource[$key]
  1526. );
  1527. }
  1528. }
  1529. break;
  1530. }
  1531. if ($this->ext_printAll || strcmp($theConstants[$key]['value'],$var)) {
  1532. $this->ext_putValueInConf($key, $var); // Put value in, if changed.
  1533. }
  1534. unset($check[$key]); // Remove the entry because it has been "used"
  1535. } else {
  1536. $this->ext_removeValueInConf($key);
  1537. }
  1538. }
  1539. }
  1540. }
  1541. // Remaining keys in $check indicates fields that are just clicked "on" to be edited. Therefore we get the default value and puts that in the template as a start...
  1542. if (!$this->ext_dontCheckIssetValues && is_array($check)) {
  1543. foreach ($check as $key => $var) {
  1544. if (isset($theConstants[$key])) {
  1545. $dValue = $theConstants[$key]['default_value'];
  1546. $this->ext_putValueInConf($key, $dValue);
  1547. }
  1548. }
  1549. }
  1550. }
  1551. /**
  1552. * [Describe function...]
  1553. *
  1554. * @param [type] $typeDat: ...
  1555. * @param [type] $tplRow: ...
  1556. * @param [type] $theRealFileName: ...
  1557. * @param [type] $tmp_name: ...
  1558. * @return [type] ...
  1559. */
  1560. function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
  1561. // extensions
  1562. $extList = $typeDat['paramstr'];
  1563. if ($extList=='IMAGE_EXT') {
  1564. $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
  1565. }
  1566. $fI=t3lib_div::split_fileref($theRealFileName);
  1567. if ($theRealFileName && (!$extList || t3lib_div::inList($extList,$fI['fileext']))) {
  1568. $tmp_upload_name = t3lib_div::upload_to_tempfile($tmp_name); // If there is an uploaded file, move it for the sake of safe_mode.
  1569. // Saving resource
  1570. $alternativeFileName=array();
  1571. $alternativeFileName[$tmp_upload_name] = $theRealFileName;
  1572. // Making list of resources
  1573. $resList = $tplRow['resources'];
  1574. $resList = $tmp_upload_name.','.$resList;
  1575. $resList=implode(t3lib_div::trimExplode(',',$resList,1),',');
  1576. // Making data-array
  1577. $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
  1578. $recData=array();
  1579. $recData['sys_template'][$saveId]['resources'] = $resList;
  1580. // Saving
  1581. $tce = t3lib_div::makeInstance('t3lib_TCEmain');
  1582. $tce->stripslashes_values=0;
  1583. $tce->alternativeFileName = $alternativeFileName;
  1584. $tce->start($recData,Array());
  1585. $tce->process_datamap();
  1586. t3lib_div::unlink_tempfile($tmp_upload_name);
  1587. $tmpRow = t3lib_BEfunc::getRecordWSOL('sys_template',$saveId,'resources');
  1588. $tplRow['resources'] = $tmpRow['resources'];
  1589. // Setting the value
  1590. $var = $this->ext_setStar($theRealFileName);
  1591. }
  1592. return $var;
  1593. }
  1594. /**
  1595. * [Describe function...]
  1596. *
  1597. * @param [type] $id: ...
  1598. * @param [type] $perms_clause: ...
  1599. * @return [type] ...
  1600. */
  1601. function ext_prevPageWithTemplate($id,$perms_clause) {
  1602. $rootLine = t3lib_BEfunc::BEgetRootLine($id,$perms_clause?' AND '.$perms_clause:'');
  1603. foreach ($rootLine as $p) {
  1604. if ($this->ext_getFirstTemplate($p['uid'])) {
  1605. return $p;
  1606. }
  1607. }
  1608. }
  1609. /**
  1610. * [Describe function...]
  1611. *
  1612. * @param [type] $val: ...
  1613. * @return [type] ...
  1614. */
  1615. function ext_setStar($val) {
  1616. $fParts = explode('.',strrev($val),2);
  1617. $val=preg_replace('/_[0-9][0-9]$/','',strrev($fParts[1])).'*.'.strrev($fParts[0]);
  1618. return $val;
  1619. }
  1620. /**
  1621. * [Describe function...]
  1622. *
  1623. * @param [type] $value: ...
  1624. * @return [type] ...
  1625. */
  1626. function ext_detectAndFixExtensionPrefix($value) {
  1627. if (substr($value,0,4)=='EXT:') {
  1628. $parts = explode('/',substr($value,4),2);
  1629. $extPath = t3lib_extMgm::siteRelPath($parts[0]);
  1630. $value = $extPath.$parts[1];
  1631. return $value;
  1632. } else {
  1633. return $value;
  1634. }
  1635. }
  1636. }
  1637. if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']) {
  1638. include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);
  1639. }
  1640. ?>