2 /***************************************************************
5 * (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 * [CLASS/FUNCTION INDEX of SCRIPT]
35 * 49: class tx_tstemplateinfo extends t3lib_extobjbase
36 * 63: function tableRow($label, $data, $field)
37 * 77: function procesResources($resources, $func=false)
38 * 117: function resourceListForCopy($id, $template_uid)
39 * 143: function initialize_editor($pageId, $template_uid=0)
40 * 160: function main()
43 * (This index is automatically created/updated by the extension "extdeveval")
47 require_once(PATH_t3lib
."class.t3lib_extobjbase.php");
49 class tx_tstemplateinfo
extends t3lib_extobjbase
{
51 public $tce_processed = false; // indicator for t3editor, whether data is stored
54 * Creates a row for a HTML table
56 * @param string $label: The label to be shown (e.g. 'Title:', 'Sitetitle:')
57 * @param string $data: The data/information to be shown (e.g. 'Template for my site')
58 * @param string $field: The field/variable to be sent on clicking the edit icon (e.g. 'title', 'sitetitle')
59 * @return string A row for a HTML table
61 function tableRow($label, $data, $field) {
62 $ret = '<tr><td class="bgColor4" width="1%">';
63 $ret.= '<a href="index.php?id='.$this->pObj
->id
.'&e['.$field.']=1"><img '.t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'], 'gfx/edit2.gif').' width=11 height=12 hspace=3 border=0 title="Edit field"></a>';
64 $ret.= '</td><td class="bgColor4" width="1%"><b>'.$label.' </b></td><td class="bgColor4" width="99%">'.$data.' </td></tr>';
69 * Renders HTML table with available template resources/files
71 * @param string $resources: List of resources/files to be shown (e.g. 'file_01.txt,file.txt')
72 * @param boolean $func: Whether to render functions like 'to top' or 'delete' for each resource (default: false)
73 * @return string HTML table with available template resources/files
75 function procesResources($resources, $func=false) {
76 $arr = t3lib_div
::trimExplode(',', $resources.',,', 1);
78 $bgcol = ($func ?
' class="bgColor4"' : '');
79 foreach ($arr as $k => $v) {
80 $path = PATH_site
.$GLOBALS['TCA']['sys_template']['columns']['resources']['config']['uploadfolder'].'/'.$v;
83 $functions = '<td bgcolor=red nowrap>Delete: <input type="Checkbox" name="data[remove_resource]['.$k.']" value="'.htmlspecialchars($v).'"></td>';
84 $functions.= '<td'.$bgcol.' nowrap>To top: <input type="Checkbox" name="data[totop_resource]['.$k.']" value="'.htmlspecialchars($v).'"></td>';
85 $functions.= '<td'.$bgcol.' nowrap>';
86 $fI = t3lib_div
::split_fileref($v);
87 if (t3lib_div
::inList($this->pObj
->textExtensions
,$fI['fileext'])) {
88 $functions.= '<a href="index.php?id='.$this->pObj
->id
.'&e[file]='.rawurlencode($v).'"><img '.t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'], 'gfx/edit2.gif').' width=11 height=12 hspace=3 border=0 title="Edit file"></a>';
92 $thumb = t3lib_BEfunc
::thumbCode(array('resources' => $v), 'sys_template', 'resources', $GLOBALS['BACK_PATH'], '');
93 $out.= '<tr><td'.$bgcol.' nowrap>'.$v.' </td><td'.$bgcol.' nowrap> '.t3lib_div
::formatSize(@filesize
($path)).' </td>'.$functions.'<td'.$bgcol.'>'.trim($thumb).'</td></tr>';
97 $out = '<table border=0 cellpadding=1 cellspacing=1 width="100%">'.$out.'</table>';
98 $out = '<table border=0 cellpadding=0 cellspacing=0>
99 <tr><td class="bgColor2">'.$out.'<img src=clear.gif width=465 height=1></td></tr>
102 $out = '<table border=0 cellpadding=0 cellspacing=0>'.$out.'</table>';
109 * Renders HTML table with all available template resources/files in the current rootline that could be copied
111 * @param integer $id: The uid of the current page
112 * @param integer $template_uid: The uid of the template record to be rendered (only if more than one template on the current page)
113 * @return string HTML table with all available template resources/files in the current rootline that could be copied
115 function resourceListForCopy($id, $template_uid) {
117 $sys_page = t3lib_div
::makeInstance('t3lib_pageSelect');
118 $rootLine = $sys_page->getRootLine($id);
119 $tmpl->runThroughTemplates($rootLine, $template_uid); // This generates the constants/config + hierarchy info for the template.
120 $theResources = t3lib_div
::trimExplode(',', $tmpl->resources
, 1);
121 foreach ($theResources as $k => $v) {
123 if (t3lib_div
::inList($this->pObj
->textExtensions
,strtolower($fI['extension']))) {
124 $path = PATH_site
.$GLOBALS['TCA']['sys_template']['columns']['resources']['config']['uploadfolder'].'/'.$v;
125 $thumb = t3lib_BEfunc
::thumbCode(array('resources' => $v), 'sys_template', 'resources', $GLOBALS['BACK_PATH'], '');
126 $out.= '<tr><td'.$bgcol.' nowrap>'.$v.' </td><td'.$bgcol.' nowrap> '.t3lib_div
::formatSize(@filesize
($path)).' </td><td'.$bgcol.'>'.trim($thumb).'</td><td><input type="Checkbox" name="data[makecopy_resource]['.$k.']" value="'.htmlspecialchars($v).'"></td></tr>';
129 $out = ($out ?
'<table border=0 cellpadding=0 cellspacing=0>'.$out.'</table>' : '');
134 * Create an instance of t3lib_tsparser_ext in $GLOBALS['tmpl'] and looks for the first (visible) template
135 * record. If $template_uid was given and greater than zero, this record will be checked.
137 * @param integer $id: The uid of the current page
138 * @param integer $template_uid: The uid of the template record to be rendered (only if more than one template on the current page)
139 * @return boolean Returns true if a template record was found, otherwise false
141 function initialize_editor($pageId, $template_uid=0) {
142 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
143 global $tmpl,$tplRow,$theConstants;
145 $tmpl = t3lib_div
::makeInstance('t3lib_tsparser_ext'); // Defined global here!
146 $tmpl->tt_track
= 0; // Do not log time-performance information
149 $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid); // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
150 return (is_array($tplRow) ?
true : false);
154 * The main processing method if this class
156 * @return string Information of the template status or the taken actions as HTML string
159 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
160 global $tmpl,$tplRow,$theConstants;
162 $edit = $this->pObj
->edit
;
165 t3lib_div
::loadTCA('sys_template');
167 // **************************
168 // Create extension template
169 // **************************
170 $this->pObj
->createTemplate($this->pObj
->id
);
173 // **************************
174 // Checking for more than one template an if, set a menu...
175 // **************************
176 $manyTemplatesMenu = $this->pObj
->templateMenu();
178 if ($manyTemplatesMenu) {
179 $template_uid = $this->pObj
->MOD_SETTINGS
['templatesOnPage'];
183 // **************************
185 // **************************
186 $existTemplate = $this->initialize_editor($this->pObj
->id
, $template_uid); // initialize
187 if ($existTemplate) {
188 $saveId = ($tplRow['_ORIG_uid'] ?
$tplRow['_ORIG_uid'] : $tplRow['uid']);
191 $POST = t3lib_div
::_POST();
192 if ($POST['submit'] ||
(t3lib_div
::testInt($POST['submit_x']) && t3lib_div
::testInt($POST['submit_y']))) {
193 require_once(PATH_t3lib
.'class.t3lib_tcemain.php');
194 // Set the data to be saved
196 $alternativeFileName = array();
197 $resList = $tplRow['resources'];
199 $tmp_upload_name = '';
200 $tmp_newresource_name = ''; // Set this to blank
202 if (is_array($POST['data'])) {
203 foreach ($POST['data'] as $field => $val) {
210 $recData['sys_template'][$saveId][$field] = $val;
213 $tmp_upload_name = t3lib_div
::upload_to_tempfile($_FILES['resources']['tmp_name']); // If there is an uploaded file, move it for the sake of safe_mode.
214 if ($tmp_upload_name) {
215 if ($tmp_upload_name!='none' && $_FILES['resources']['name']) {
216 $alternativeFileName[$tmp_upload_name] = trim($_FILES['resources']['name']);
217 $resList = $tmp_upload_name.','.$resList;
222 $newName = trim(t3lib_div
::_GP('new_resource'));
224 $newName.= '.'.t3lib_div
::_GP('new_resource_ext');
225 $tmp_newresource_name = t3lib_div
::tempnam('new_resource_');
226 $alternativeFileName[$tmp_newresource_name] = $newName;
227 $resList = $tmp_newresource_name.','.$resList;
230 case 'makecopy_resource':
231 if (is_array($val)) {
232 $resList = ','.$resList.',';
233 foreach ($val as $k => $file) {
234 $tmp_name = PATH_site
.$TCA['sys_template']['columns']['resources']['config']['uploadfolder'].'/'.$file;
235 $resList = $tmp_name.','.$resList;
239 case 'remove_resource':
240 if (is_array($val)) {
241 $resList = ','.$resList.',';
242 foreach ($val as $k => $file) {
243 $resList = str_replace(','.$file.',', ',', $resList);
247 case 'totop_resource':
248 if (is_array($val)) {
249 $resList = ','.$resList.',';
250 foreach ($val as $k => $file) {
251 $resList = str_replace(','.$file.',', ',', $resList);
252 $resList = ','.$file.$resList;
259 $resList=implode(',', t3lib_div
::trimExplode(',', $resList, 1));
260 if (strcmp($resList, $tplRow['resources'])) {
261 $recData['sys_template'][$saveId]['resources'] = $resList;
263 if (count($recData)) {
264 // Create new tce-object
265 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
266 $tce->stripslashes_values
=0;
267 $tce->alternativeFileName
= $alternativeFileName;
269 $tce->start($recData, array());
271 $tce->process_datamap();
272 // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
273 $tce->clear_cacheCmd('all');
275 // tce were processed successfully
276 $this->tce_processed
= true;
278 // re-read the template ...
279 $this->initialize_editor($this->pObj
->id
, $template_uid);
282 // Unlink any uploaded/new temp files there was:
283 t3lib_div
::unlink_tempfile($tmp_upload_name);
284 t3lib_div
::unlink_tempfile($tmp_newresource_name);
286 // If files has been edited:
287 if (is_array($edit)) {
288 if ($edit['filename'] && $tplRow['resources'] && t3lib_div
::inList($tplRow['resources'], $edit['filename'])) { // Check if there are resources, and that the file is in the resourcelist.
289 $path = PATH_site
.$TCA['sys_template']['columns']['resources']['config']['uploadfolder'].'/'.$edit['filename'];
290 $fI = t3lib_div
::split_fileref($edit['filename']);
291 if (@is_file
($path) && t3lib_div
::getFileAbsFileName($path) && t3lib_div
::inList($this->pObj
->textExtensions
, $fI['fileext'])) { // checks that have already been done.. Just to make sure
292 // @TODO: Check if the hardcorded value already has a config member, otherwise create one
293 if (filesize($path) < 30720) { // checks that have already been done.. Just to make sure
294 t3lib_div
::writeFile($path, $edit['file']);
296 $theOutput.= $this->pObj
->doc
->spacer(10);
297 $theOutput.= $this->pObj
->doc
->section('<font color=red>FILE CHANGED</font>', "Resource '".$edit['filename']."' has been updated.", 0, 0, 0, 1);
299 // Clear cache - the file has probably affected the template setup
300 // @TODO: Check if the edited file really had something to do with cached data and prevent this clearing if possible!
301 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
302 $tce->stripslashes_values
= 0;
303 $tce->start(array(), array());
304 $tce->clear_cacheCmd('all');
311 // hook Post updating template/TCE processing
312 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook'])) {
313 $postTCEProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook'];
314 if (is_array($postTCEProcessingHook)) {
315 $hookParameters = array(
319 foreach ($postTCEProcessingHook as $hookFunction) {
320 t3lib_div
::callUserFunction($hookFunction, $hookParameters, $this);
325 $theOutput.= $this->pObj
->doc
->spacer(5);
326 $theOutput.= $this->pObj
->doc
->section('Template information:', '<img '.t3lib_iconWorks
::skinImg($BACK_PATH, t3lib_iconWorks
::getIcon('sys_template', $tplRow)).' align="top" /> <b>'.htmlspecialchars($tplRow['title']).'</b>'.htmlspecialchars(trim($tplRow['sitetitle'])?
' - ('.$tplRow['sitetitle'].')':''), 0, 1);
327 if ($manyTemplatesMenu) {
328 $theOutput.= $this->pObj
->doc
->section('', $manyTemplatesMenu);
329 $theOutput.= $this->pObj
->doc
->divider(5);
332 #$numberOfRows= t3lib_div::intInRange($this->pObj->MOD_SETTINGS["ts_template_editor_TArows"],0,150);
336 // If abort pressed, nothing should be edited:
337 if ($POST['abort'] ||
(t3lib_div
::testInt($POST['abort_x']) && t3lib_div
::testInt($POST['abort_y']))) {
342 $outCode = '<input type="Text" name="data[title]" value="'.htmlspecialchars($tplRow['title']).'"'.$this->pObj
->doc
->formWidth().'>';
343 $outCode.= '<input type="Hidden" name="e[title]" value="1">';
344 $theOutput.= $this->pObj
->doc
->spacer(15);
345 $theOutput.= $this->pObj
->doc
->section('Title:', $outCode);
347 if ($e['sitetitle']) {
348 $outCode = '<input type="Text" name="data[sitetitle]" value="'.htmlspecialchars($tplRow['sitetitle']).'"'.$this->pObj
->doc
->formWidth().'>';
349 $outCode.= '<input type="Hidden" name="e[sitetitle]" value="1">';
350 $theOutput.= $this->pObj
->doc
->spacer(15);
351 $theOutput.= $this->pObj
->doc
->section('Sitetitle:', $outCode);
353 if ($e['description']) {
354 $outCode = '<textarea name="data[description]" rows="5" class="fixed-font enable-tab"'.$this->pObj
->doc
->formWidthText(48, '', '').'>'.t3lib_div
::formatForTextarea($tplRow['description']).'</textarea>';
355 $outCode.= '<input type="Hidden" name="e[description]" value="1">';
356 $theOutput.= $this->pObj
->doc
->spacer(15);
357 $theOutput.= $this->pObj
->doc
->section('Description:', $outCode);
359 if ($e['resources']) {
361 $outCode = '<input type="File" name="resources"'.$this->pObj
->doc
->formWidth().' size="50">';
362 $outCode.= '<input type="Hidden" name="data[resources]" value="1">';
363 $outCode.= '<input type="Hidden" name="e[resources]" value="1">';
364 $outCode.= '<BR>Allowed extensions: <b>'.$TCA['sys_template']['columns']['resources']['config']['allowed'].'</b>';
365 $outCode.= '<BR>Max file size: <b>'.t3lib_div
::formatSize($TCA['sys_template']['columns']['resources']['config']['max_size']*1024).'</b>';
366 $theOutput.= $this->pObj
->doc
->spacer(15);
367 $theOutput.= $this->pObj
->doc
->section('Upload resource:', $outCode);
370 $opt = explode(',', $this->pObj
->textExtensions
);
372 foreach ($opt as $extVal) {
373 $optTags.= '<option value="'.$extVal.'">.'.$extVal.'</option>';
375 $outCode = '<input type="text" name="new_resource"'.$this->pObj
->doc
->formWidth(20).'>
376 <select name="new_resource_ext">'.$optTags.'</select>';
377 $outCode.= '<input type="Hidden" name="data[new_resource]" value="1">';
378 $theOutput.= $this->pObj
->doc
->spacer(15);
379 $theOutput.= $this->pObj
->doc
->section('New text resource (enter name):', $outCode);
382 $rL = $this->resourceListForCopy($this->pObj
->id
, $template_uid);
384 $theOutput.= $this->pObj
->doc
->spacer(20);
385 $theOutput.= $this->pObj
->doc
->section('Make a copy of resource:', $rL);
388 // Update resource list
389 $rL = $this->procesResources($tplRow['resources'], 1);
391 $theOutput.= $this->pObj
->doc
->spacer(20);
392 $theOutput.= $this->pObj
->doc
->section('Update resource list:', $rL);
395 if ($e['constants']) {
396 $outCode = '<textarea name="data[constants]" rows="'.$numberOfRows.'" wrap="off" class="fixed-font enable-tab"'.$this->pObj
->doc
->formWidthText(48, 'width:98%;height:70%', 'off').' class="fixed-font">'.t3lib_div
::formatForTextarea($tplRow['constants']).'</textarea>';
397 $outCode.= '<input type="Hidden" name="e[constants]" value="1">';
398 $theOutput.= $this->pObj
->doc
->spacer(15);
399 $theOutput.= $this->pObj
->doc
->section('Constants:', '');
400 $theOutput.= $this->pObj
->doc
->sectionEnd().$outCode;
403 $path = PATH_site
.$TCA['sys_template']['columns']['resources']['config']['uploadfolder'].'/'.$e[file
];
405 $fI = t3lib_div
::split_fileref($e[file
]);
406 if (@is_file
($path) && t3lib_div
::inList($this->pObj
->textExtensions
, $fI['fileext'])) {
407 if (filesize($path) < $TCA['sys_template']['columns']['resources']['config']['max_size']*1024) {
408 $fileContent = t3lib_div
::getUrl($path);
409 $outCode = 'File: <b>'.$e[file
].'</b><BR>';
410 $outCode.= '<textarea name="edit[file]" rows="'.$numberOfRows.'" wrap="off" class="fixed-font enable-tab"'.$this->pObj
->doc
->formWidthText(48, 'width:98%;height:70%', 'off').' class="fixed-font">'.t3lib_div
::formatForTextarea($fileContent).'</textarea>';
411 $outCode.= '<input type="Hidden" name="edit[filename]" value="'.$e[file
].'">';
412 $outCode.= '<input type="Hidden" name="e[file]" value="'.htmlspecialchars($e[file
]).'">';
413 $theOutput.= $this->pObj
->doc
->spacer(15);
414 $theOutput.= $this->pObj
->doc
->section('Edit Resource:', '');
415 $theOutput.= $this->pObj
->doc
->sectionEnd().$outCode;
417 $theOutput.= $this->pObj
->doc
->spacer(15);
418 $theOutput.= $this->pObj
->doc
->section(
419 '<font color=red>Filesize exceeded '.$TCA['sys_template']['columns']['resources']['config']['max_size'].' Kbytes</font>',
420 'Files larger than '.$TCA['sys_template']['columns']['resources']['config']['max_size'].' KByes are not allowed to be edited.',
427 $outCode='<textarea name="data[config]" rows="'.$numberOfRows.'" wrap="off" class="fixed-font enable-tab"'.$this->pObj
->doc
->formWidthText(48,"width:98%;height:70%","off").' class="fixed-font">'.t3lib_div
::formatForTextarea($tplRow["config"]).'</textarea>';
429 if (t3lib_extMgm
::isLoaded('tsconfig_help')) {
430 $url = $BACK_PATH.'wizard_tsconfig.php?mode=tsref';
432 'formName' => 'editForm',
433 'itemName' => 'data[config]',
435 $outCode.= '<a href="#" onClick="vHWin=window.open(\''.$url.t3lib_div
::implodeArrayForUrl('', array('P' => $params)).'\',\'popUp'.$md5ID.'\',\'height=500,width=780,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;"><img '.t3lib_iconWorks
::skinImg($BACK_PATH, 'gfx/wizard_tsconfig.gif').' width="22" height="27" border="0" title="TSref reference"></a>';
438 $outCode.= '<input type="Hidden" name="e[config]" value="1">';
439 $theOutput.= $this->pObj
->doc
->spacer(15);
440 $theOutput.= $this->pObj
->doc
->section('Setup:', '');
441 $theOutput.= $this->pObj
->doc
->sectionEnd().$outCode;
446 $outCode.= $this->tableRow('Title:', htmlspecialchars($tplRow['title']), 'title');
447 $outCode.= $this->tableRow('Sitetitle:', htmlspecialchars($tplRow['sitetitle']), 'sitetitle');
448 $outCode.= $this->tableRow('Description:', nl2br(htmlspecialchars($tplRow['description'])), 'description');
449 $outCode.= $this->tableRow('Resources:', $this->procesResources($tplRow['resources']), 'resources');
450 $outCode.= $this->tableRow('Constants:', '(edit to view, '.(trim($tplRow[constants
]) ?
count(explode(chr(10), $tplRow[constants
])) : 0).' lines)', 'constants');
451 $outCode.= $this->tableRow('Setup:', '(edit to view, '.(trim($tplRow[config
]) ?
count(explode(chr(10), $tplRow[config
])) : 0).' lines)', 'config');
452 $outCode = '<table border=0 cellpadding=1 cellspacing=1 width="100%">'.$outCode.'</table>';
454 $outCode = '<table border=0 cellpadding=0 cellspacing=0>
455 <tr><td class="bgColor2">'.$outCode.'<img src=clear.gif width=465 height=1></td></tr>
459 $outCode.= '<BR><a href="#" onClick="'.t3lib_BEfunc
::editOnClick(rawurlencode('&createExtension=0').'&edit[sys_template]['.$tplRow['uid'].']=edit', $BACK_PATH, '').'"><strong>Click here to edit whole template record</strong></a>';
461 $theOutput.= $this->pObj
->doc
->spacer(25);
462 $theOutput.= $this->pObj
->doc
->section('', $outCode);
465 // hook after compiling the output
466 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'])) {
467 $postOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'];
468 if (is_array($postOutputProcessingHook)) {
469 $hookParameters = array(
470 'theOutput' => &$theOutput,
474 'numberOfRows' => $numberOfRows
476 foreach ($postOutputProcessingHook as $hookFunction) {
477 t3lib_div
::callUserFunction($hookFunction, $hookParameters, $this);
483 $theOutput.= $this->pObj
->noTemplate(1);
491 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']) {
492 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']);