Fixed bug #6561: imgMax and imgStart (IMGTEXT) not working properly
[Packages/TYPO3.CMS.git] / typo3 / sysext / css_styled_content / pi1 / class.tx_cssstyledcontent_pi1.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 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 * Plugin 'Content rendering' for the 'css_styled_content' extension.
29 *
30 * $Id$
31 *
32 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 68: class tx_cssstyledcontent_pi1 extends tslib_pibase
40 *
41 * SECTION: Rendering of Content Elements:
42 * 96: function render_bullets($content,$conf)
43 * 141: function render_table($content,$conf)
44 * 283: function render_uploads($content,$conf)
45 * 395: function render_textpic($content, $conf)
46 *
47 * SECTION: Helper functions
48 * 832: function getTableAttributes($conf,$type)
49 * 861: function &hookRequest($functionName)
50 *
51 * TOTAL FUNCTIONS: 6
52 * (This index is automatically created/updated by the extension "extdeveval")
53 *
54 */
55
56 require_once(PATH_tslib.'class.tslib_pibase.php');
57
58
59
60 /**
61 * Plugin class - instantiated from TypoScript.
62 * Rendering some content elements from tt_content table.
63 *
64 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
65 * @package TYPO3
66 * @subpackage tx_cssstyledcontent
67 */
68 class tx_cssstyledcontent_pi1 extends tslib_pibase {
69
70 // Default plugin variables:
71 var $prefixId = 'tx_cssstyledcontent_pi1'; // Same as class name
72 var $scriptRelPath = 'pi1/class.tx_cssstyledcontent_pi1.php'; // Path to this script relative to the extension dir.
73 var $extKey = 'css_styled_content'; // The extension key.
74 var $conf = array();
75
76
77
78
79
80
81
82 /***********************************
83 *
84 * Rendering of Content Elements:
85 *
86 ***********************************/
87
88 /**
89 * Rendering the "Bulletlist" type content element, called from TypoScript (tt_content.bullets.20)
90 *
91 * @param string Content input. Not used, ignore.
92 * @param array TypoScript configuration
93 * @return string HTML output.
94 * @access private
95 */
96 function render_bullets($content,$conf) {
97
98 // Look for hook before running default code for function
99 if ($hookObj = &$this->hookRequest('render_bullets')) {
100 return $hookObj->render_bullets($content,$conf);
101 } else {
102
103 // Get bodytext field content, returning blank if empty:
104 $content = trim($this->cObj->data['bodytext']);
105 if (!strcmp($content,'')) return '';
106
107 // Split into single lines:
108 $lines = t3lib_div::trimExplode(chr(10),$content);
109 while(list($k)=each($lines)) {
110 $lines[$k]='
111 <li>'.$this->cObj->stdWrap($lines[$k],$conf['innerStdWrap.']).'</li>';
112 }
113
114 // Set header type:
115 $type = intval($this->cObj->data['layout']);
116
117 // Compile list:
118 $out = '
119 <ul class="csc-bulletlist csc-bulletlist-'.$type.'">'.
120 implode('',$lines).'
121 </ul>';
122
123 // Calling stdWrap:
124 if ($conf['stdWrap.']) {
125 $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
126 }
127
128 // Return value
129 return $out;
130 }
131 }
132
133 /**
134 * Rendering the "Table" type content element, called from TypoScript (tt_content.table.20)
135 *
136 * @param string Content input. Not used, ignore.
137 * @param array TypoScript configuration
138 * @return string HTML output.
139 * @access private
140 */
141 function render_table($content,$conf) {
142
143 // Look for hook before running default code for function
144 if ($hookObj = &$this->hookRequest('render_table')) {
145 return $hookObj->render_table($content,$conf);
146 } else {
147 // Init FlexForm configuration
148 $this->pi_initPIflexForm();
149
150 // Get bodytext field content
151 $content = trim($this->cObj->data['bodytext']);
152 if (!strcmp($content,'')) return '';
153
154 // get flexform values
155 $caption = trim(htmlspecialchars($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_caption')));
156 $summary = trim(htmlspecialchars($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_summary')));
157 $useTfoot = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_tfoot'));
158 $headerPos = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_headerpos');
159 $noStyles = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_nostyles');
160 $tableClass = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_tableclass');
161
162 $delimiter = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'tableparsing_delimiter','s_parsing'));
163 if ($delimiter) {
164 $delimiter = chr(intval($delimiter));
165 } else {
166 $delimiter = '|';
167 }
168 $quotedInput = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'tableparsing_quote','s_parsing'));
169 if ($quotedInput) {
170 $quotedInput = chr(intval($quotedInput));
171 } else {
172 $quotedInput = '';
173 }
174
175 // generate id prefix for accessible header
176 $headerScope = ($headerPos=='top'?'col':'row');
177 $headerIdPrefix = $headerScope.$this->cObj->data['uid'].'-';
178
179 // Split into single lines (will become table-rows):
180 $rows = t3lib_div::trimExplode(chr(10),$content);
181
182 // Find number of columns to render:
183 $cols = t3lib_div::intInRange($this->cObj->data['cols']?$this->cObj->data['cols']:count(explode($delimiter,current($rows))),0,100);
184
185 // Traverse rows (rendering the table here)
186 $rCount = count($rows);
187 foreach($rows as $k => $v) {
188 $cells = explode($delimiter,$v);
189 $newCells=array();
190 for($a=0;$a<$cols;$a++) {
191 // remove quotes if needed
192 if ($quotedInput && substr($cells[$a],0,1) == $quotedInput && substr($cells[$a],-1,1) == $quotedInput) {
193 $cells[$a] = substr($cells[$a],1,-1);
194 }
195
196 if (!strcmp(trim($cells[$a]),'')) $cells[$a]='&nbsp;';
197 $cellAttribs = ($noStyles?'':($a>0 && ($cols-1)==$a) ? ' class="td-last td-'.$a.'"' : ' class="td-'.$a.'"');
198 if (($headerPos == 'top' && !$k) || ($headerPos == 'left' && !$a)) {
199 $scope = ' scope="'.$headerScope.'"';
200 $scope .= ' id="'.$headerIdPrefix.(($headerScope=='col')?$a:$k).'"';
201
202 $newCells[$a] = '
203 <th'.$cellAttribs.$scope.'>'.$this->cObj->stdWrap($cells[$a],$conf['innerStdWrap.']).'</th>';
204 } else {
205 if (empty($headerPos)) {
206 $accessibleHeader = '';
207 } else {
208 $accessibleHeader = ' headers="'.$headerIdPrefix.(($headerScope=='col')?$a:$k).'"';
209 }
210 $newCells[$a] = '
211 <td'.$cellAttribs.$accessibleHeader.'>'.$this->cObj->stdWrap($cells[$a],$conf['innerStdWrap.']).'</td>';
212 }
213 }
214 if (!$noStyles) {
215 $oddEven = $k%2 ? 'tr-odd' : 'tr-even';
216 $rowAttribs = ($k>0 && ($rCount-1)==$k) ? ' class="'.$oddEven.' tr-last"' : ' class="'.$oddEven.' tr-'.$k.'"';
217 }
218 $rows[$k]='
219 <tr'.$rowAttribs.'>'.implode('',$newCells).'
220 </tr>';
221 }
222
223 $addTbody = 0;
224 $tableContents = '';
225 if ($caption) {
226 $tableContents .= '
227 <caption>'.$caption.'</caption>';
228 }
229 if ($headerPos == 'top' && $rows[0]) {
230 $tableContents .= '<thead>'. $rows[0] .'
231 </thead>';
232 unset($rows[0]);
233 $addTbody = 1;
234 }
235 if ($useTfoot) {
236 $tableContents .= '
237 <tfoot>'.$rows[$rCount-1].'</tfoot>';
238 unset($rows[$rCount-1]);
239 $addTbody = 1;
240 }
241 $tmpTable = implode('',$rows);
242 if ($addTbody) {
243 $tmpTable = '<tbody>'.$tmpTable.'</tbody>';
244 }
245 $tableContents .= $tmpTable;
246
247 // Set header type:
248 $type = intval($this->cObj->data['layout']);
249
250 // Table tag params.
251 $tableTagParams = $this->getTableAttributes($conf,$type);
252 if (!$noStyles) {
253 $tableTagParams['class'] = 'contenttable contenttable-'.$type.($tableClass?' '.$tableClass:'');
254 } elseif ($tableClass) {
255 $tableTagParams['class'] = $tableClass;
256 }
257
258
259 // Compile table output:
260 $out = '
261 <table '.t3lib_div::implodeAttributes($tableTagParams).($summary?' summary="'.$summary.'"':'').'>'. // Omitted xhtmlSafe argument TRUE - none of the values will be needed to be converted anyways, no need to spend processing time on that.
262 $tableContents.'
263 </table>';
264
265 // Calling stdWrap:
266 if ($conf['stdWrap.']) {
267 $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
268 }
269
270 // Return value
271 return $out;
272 }
273 }
274
275 /**
276 * Rendering the "Filelinks" type content element, called from TypoScript (tt_content.uploads.20)
277 *
278 * @param string Content input. Not used, ignore.
279 * @param array TypoScript configuration
280 * @return string HTML output.
281 * @access private
282 */
283 function render_uploads($content,$conf) {
284
285 // Look for hook before running default code for function
286 if ($hookObj = &$this->hookRequest('render_uploads')) {
287 return $hookObj->render_uploads($content,$conf);
288 } else {
289
290 $out = '';
291
292 // Set layout type:
293 $type = intval($this->cObj->data['layout']);
294
295 // Get the list of files (using stdWrap function since that is easiest)
296 $lConf = array();
297 $lConf['override.']['filelist.']['field'] = 'select_key';
298 $fileList = $this->cObj->stdWrap($this->cObj->data['media'],$lConf);
299
300 // Explode into an array:
301 $fileArray = t3lib_div::trimExplode(',',$fileList,1);
302
303 // If there were files to list...:
304 if (count($fileArray)) {
305
306 // Get the path from which the images came:
307 $selectKeyValues = explode('|',$this->cObj->data['select_key']);
308 $path = trim($selectKeyValues[0]) ? trim($selectKeyValues[0]) : 'uploads/media/';
309
310 // Get the descriptions for the files (if any):
311 $descriptions = t3lib_div::trimExplode(chr(10),$this->cObj->data['imagecaption']);
312
313 // Adding hardcoded TS to linkProc configuration:
314 $conf['linkProc.']['path.']['current'] = 1;
315 $conf['linkProc.']['icon'] = 1; // Always render icon - is inserted by PHP if needed.
316 $conf['linkProc.']['icon.']['wrap'] = ' | //**//'; // Temporary, internal split-token!
317 $conf['linkProc.']['icon_link'] = 1; // ALways link the icon
318 $conf['linkProc.']['icon_image_ext_list'] = ($type==2 || $type==3) ? $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] : ''; // If the layout is type 2 or 3 we will render an image based icon if possible.
319
320 // Traverse the files found:
321 $filesData = array();
322 foreach($fileArray as $key => $fileName) {
323 $absPath = t3lib_div::getFileAbsFileName($path.$fileName);
324 if (@is_file($absPath)) {
325 $fI = pathinfo($fileName);
326 $filesData[$key] = array();
327
328 $filesData[$key]['filename'] = $fileName;
329 $filesData[$key]['path'] = $path;
330 $filesData[$key]['filesize'] = filesize($absPath);
331 $filesData[$key]['fileextension'] = strtolower($fI['extension']);
332 $filesData[$key]['description'] = trim($descriptions[$key]);
333
334 $this->cObj->setCurrentVal($path);
335 $GLOBALS['TSFE']->register['ICON_REL_PATH'] = $path.$fileName;
336 $filesData[$key]['linkedFilenameParts'] = explode('//**//',$this->cObj->filelink($fileName, $conf['linkProc.']));
337 }
338 }
339
340 // Now, lets render the list!
341 $tRows = array();
342 foreach($filesData as $key => $fileD) {
343
344 // Setting class of table row for odd/even rows:
345 $oddEven = $key%2 ? 'tr-odd' : 'tr-even';
346
347 // Render row, based on the "layout" setting
348 $tRows[]='
349 <tr class="'.$oddEven.'">'.($type>0 ? '
350 <td class="csc-uploads-icon">
351 '.$fileD['linkedFilenameParts'][0].'
352 </td>' : '').'
353 <td class="csc-uploads-fileName">
354 <p>'.$fileD['linkedFilenameParts'][1].'</p>'.
355 ($fileD['description'] ? '
356 <p class="csc-uploads-description">'.htmlspecialchars($fileD['description']).'</p>' : '').'
357 </td>'.($this->cObj->data['filelink_size'] ? '
358 <td class="csc-uploads-fileSize">
359 <p>'.t3lib_div::formatSize($fileD['filesize']).'</p>
360 </td>' : '').'
361 </tr>';
362 }
363
364 // Table tag params.
365 $tableTagParams = $this->getTableAttributes($conf,$type);
366 $tableTagParams['class'] = 'csc-uploads csc-uploads-'.$type;
367
368
369 // Compile it all into table tags:
370 $out = '
371 <table '.t3lib_div::implodeAttributes($tableTagParams).'>
372 '.implode('',$tRows).'
373 </table>';
374 }
375
376 // Calling stdWrap:
377 if ($conf['stdWrap.']) {
378 $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
379 }
380
381 // Return value
382 return $out;
383 }
384 }
385
386 /**
387 * Rendering the IMGTEXT content element, called from TypoScript (tt_content.textpic.20)
388 *
389 * @param string Content input. Not used, ignore.
390 * @param array TypoScript configuration. See TSRef "IMGTEXT". This function aims to be compatible.
391 * @return string HTML output.
392 * @access private
393 * @coauthor Ernesto Baschny <ernst@cron-it.de>
394 */
395 function render_textpic($content, $conf) {
396 // Look for hook before running default code for function
397 if (method_exists($this, 'hookRequest') && $hookObj = &$this->hookRequest('render_textpic')) {
398 return $hookObj->render_textpic($content,$conf);
399 }
400
401 $renderMethod = $this->cObj->stdWrap($conf['renderMethod'], $conf['renderMethod.']);
402
403 // Render using the default IMGTEXT code (table-based)
404 if (!$renderMethod || $renderMethod == 'table') {
405 return $this->cObj->IMGTEXT($conf);
406 }
407
408 // Specific configuration for the chosen rendering method
409 if (is_array($conf['rendering.'][$renderMethod . '.'])) {
410 $conf = $this->cObj->joinTSarrays($conf, $conf['rendering.'][$renderMethod . '.']);
411 }
412
413 // Image or Text with Image?
414 if (is_array($conf['text.'])) {
415 $content = $this->cObj->stdWrap($this->cObj->cObjGet($conf['text.'], 'text.'), $conf['text.']);
416 }
417
418 $imgList = trim($this->cObj->stdWrap($conf['imgList'], $conf['imgList.']));
419
420 if (!$imgList) {
421 // No images, that's easy
422 if (is_array($conf['stdWrap.'])) {
423 return $this->cObj->stdWrap($content, $conf['stdWrap.']);
424 }
425 return $content;
426 }
427
428 $imgs = t3lib_div::trimExplode(',', $imgList);
429 $imgStart = intval($this->cObj->stdWrap($conf['imgStart'], $conf['imgStart.']));
430 $imgCount = count($imgs) - $imgStart;
431 $imgMax = intval($this->cObj->stdWrap($conf['imgMax'], $conf['imgMax.']));
432 if ($imgMax) {
433 $imgCount = t3lib_div::intInRange($imgCount, 0, $imgMax); // reduce the number of images.
434 }
435
436 $imgPath = $this->cObj->stdWrap($conf['imgPath'], $conf['imgPath.']);
437
438 // Global caption
439 $caption = '';
440 if (!$conf['captionSplit'] && !$conf['imageTextSplit'] && is_array($conf['caption.'])) {
441 $caption = $this->cObj->stdWrap($this->cObj->cObjGet($conf['caption.'], 'caption.'), $conf['caption.']);
442 }
443
444 // Positioning
445 $position = $this->cObj->stdWrap($conf['textPos'], $conf['textPos.']);
446
447 $imagePosition = $position&7; // 0,1,2 = center,right,left
448 $contentPosition = $position&24; // 0,8,16,24 (above,below,intext,intext-wrap)
449 $align = $this->cObj->align[$imagePosition];
450 $textMargin = intval($this->cObj->stdWrap($conf['textMargin'],$conf['textMargin.']));
451 if (!$conf['textMargin_outOfText'] && $contentPosition < 16) {
452 $textMargin = 0;
453 }
454
455 $colspacing = intval($this->cObj->stdWrap($conf['colSpace'], $conf['colSpace.']));
456 $rowspacing = intval($this->cObj->stdWrap($conf['rowSpace'], $conf['rowSpace.']));
457
458 $border = intval($this->cObj->stdWrap($conf['border'], $conf['border.'])) ? 1:0;
459 $borderColor = $this->cObj->stdWrap($conf['borderCol'], $conf['borderCol.']);
460 $borderThickness = intval($this->cObj->stdWrap($conf['borderThick'], $conf['borderThick.']));
461
462 $borderColor = $borderColor?$borderColor:'black';
463 $borderThickness = $borderThickness?$borderThickness:1;
464 $borderSpace = (($conf['borderSpace']&&$border) ? intval($conf['borderSpace']) : 0);
465
466 // Generate cols
467 $cols = intval($this->cObj->stdWrap($conf['cols'],$conf['cols.']));
468 $colCount = ($cols > 1) ? $cols : 1;
469 if ($colCount > $imgCount) {$colCount = $imgCount;}
470 $rowCount = ceil($imgCount / $colCount);
471
472 // Generate rows
473 $rows = intval($this->cObj->stdWrap($conf['rows'],$conf['rows.']));
474 if ($rows>1) {
475 $rowCount = $rows;
476 if ($rowCount > $imgCount) {$rowCount = $imgCount;}
477 $colCount = ($rowCount>1) ? ceil($imgCount / $rowCount) : $imgCount;
478 }
479
480 // Max Width
481 $maxW = intval($this->cObj->stdWrap($conf['maxW'], $conf['maxW.']));
482
483 if ($contentPosition>=16) { // in Text
484 $maxWInText = intval($this->cObj->stdWrap($conf['maxWInText'],$conf['maxWInText.']));
485 if (!$maxWInText) {
486 // If maxWInText is not set, it's calculated to the 50% of the max
487 $maxW = round($maxW/100*50);
488 } else {
489 $maxW = $maxWInText;
490 }
491 }
492
493 // All columns have the same width:
494 $defaultColumnWidth = ceil(($maxW-$colspacing*($colCount-1)-$colCount*$border*($borderThickness+$borderSpace)*2)/$colCount);
495
496 // Specify the maximum width for each column
497 $columnWidths = array();
498 $colRelations = trim($this->cObj->stdWrap($conf['colRelations'],$conf['colRelations.']));
499 if (!$colRelations) {
500 // Default 1:1-proportion, all columns same width
501 for ($a=0;$a<$colCount;$a++) {
502 $columnWidths[$a] = $defaultColumnWidth;
503 }
504 } else {
505 // We need another proportion
506 $rel_parts = explode(':',$colRelations);
507 $rel_total = 0;
508 for ($a=0;$a<$colCount;$a++) {
509 $rel_parts[$a] = intval($rel_parts[$a]);
510 $rel_total+= $rel_parts[$a];
511 }
512 if ($rel_total) {
513 for ($a=0;$a<$colCount;$a++) {
514 $columnWidths[$a] = round(($defaultColumnWidth*$colCount)/$rel_total*$rel_parts[$a]);
515 }
516 if (min($columnWidths)<=0 || max($rel_parts)/min($rel_parts)>10) {
517 // The difference in size between the largest and smalles must be within a factor of ten.
518 for ($a=0;$a<$colCount;$a++) {
519 $columnWidths[$a] = $defaultColumnWidth;
520 }
521 }
522 }
523 }
524 $image_compression = intval($this->cObj->stdWrap($conf['image_compression'],$conf['image_compression.']));
525 $image_effects = intval($this->cObj->stdWrap($conf['image_effects'],$conf['image_effects.']));
526 $image_frames = intval($this->cObj->stdWrap($conf['image_frames.']['key'],$conf['image_frames.']['key.']));
527
528 // EqualHeight
529 $equalHeight = intval($this->cObj->stdWrap($conf['equalH'],$conf['equalH.']));
530 if ($equalHeight) {
531 // Initiate gifbuilder object in order to get dimensions AND calculate the imageWidth's
532 $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
533 $gifCreator->init();
534 $relations_cols = Array();
535 for ($a=0; $a<$imgCount; $a++) {
536 $imgKey = $a+$imgStart;
537 $imgInfo = $gifCreator->getImageDimensions($imgPath.$imgs[$imgKey]);
538 $rel = $imgInfo[1] / $equalHeight; // relationship between the original height and the wished height
539 if ($rel) { // if relations is zero, then the addition of this value is omitted as the image is not expected to display because of some error.
540 $relations_cols[floor($a/$colCount)] += $imgInfo[0]/$rel; // counts the total width of the row with the new height taken into consideration.
541 }
542 }
543 }
544
545 // Fetches pictures
546 $splitArr = array();
547 $splitArr['imgObjNum'] = $conf['imgObjNum'];
548 $splitArr = $GLOBALS['TSFE']->tmpl->splitConfArray($splitArr, $imgCount);
549
550 $imageRowsFinalWidths = Array(); // contains the width of every image row
551 $imgsTag = array(); // array index 0 will be the first shown image
552 $origImages = array();
553 for ($a=0; $a<$imgCount; $a++) {
554 $imgKey = $a+$imgStart;
555 $totalImagePath = $imgPath.$imgs[$imgKey];
556
557 $GLOBALS['TSFE']->register['IMAGE_NUM'] = $a;
558 $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $a;
559 $GLOBALS['TSFE']->register['ORIG_FILENAME'] = $totalImagePath;
560
561 $this->cObj->data[$this->cObj->currentValKey] = $totalImagePath;
562 $imgObjNum = intval($splitArr[$a]['imgObjNum']);
563 $imgConf = $conf[$imgObjNum.'.'];
564
565 if ($equalHeight) {
566 $scale = 1;
567 $totalMaxW = $defaultColumnWidth*$colCount;
568 $rowTotalMaxW = $relations_cols[floor($a/$colCount)];
569 if ($rowTotalMaxW > $totalMaxW) {
570 $scale = $rowTotalMaxW / $totalMaxW;
571 }
572
573 // transfer info to the imageObject. Please note, that
574 $imgConf['file.']['height'] = round($equalHeight/$scale);
575
576 // other stuff will be calculated accordingly:
577 unset($imgConf['file.']['width']);
578 unset($imgConf['file.']['maxW']);
579 unset($imgConf['file.']['maxH']);
580 unset($imgConf['file.']['minW']);
581 unset($imgConf['file.']['minH']);
582 unset($imgConf['file.']['width.']);
583 unset($imgConf['file.']['maxW.']);
584 unset($imgConf['file.']['maxH.']);
585 unset($imgConf['file.']['minW.']);
586 unset($imgConf['file.']['minH.']);
587 } else {
588 $imgConf['file.']['maxW'] = $columnWidths[($a%$colCount)];
589 }
590
591 $titleInLink = $this->cObj->stdWrap($imgConf['titleInLink'], $imgConf['titleInLink.']);
592 $titleInLinkAndImg = $this->cObj->stdWrap($imgConf['titleInLinkAndImg'], $imgConf['titleInLinkAndImg.']);
593 $oldATagParms = $GLOBALS['TSFE']->ATagParams;
594 if ($titleInLink) {
595 // Title in A-tag instead of IMG-tag
596 $titleText = trim($this->cObj->stdWrap($imgConf['titleText'], $imgConf['titleText.']));
597 if ($titleText) {
598 // This will be used by the IMAGE call later:
599 $GLOBALS['TSFE']->ATagParams .= ' title="'. $titleText .'"';
600 }
601 }
602
603 if ($imgConf || $imgConf['file']) {
604 if ($this->cObj->image_effects[$image_effects]) {
605 $imgConf['file.']['params'] .= ' '.$this->cObj->image_effects[$image_effects];
606 }
607 if ($image_frames) {
608 if (is_array($conf['image_frames.'][$image_frames.'.'])) {
609 $imgConf['file.']['m.'] = $conf['image_frames.'][$image_frames.'.'];
610 }
611 }
612 if ($image_compression && $imgConf['file'] != 'GIFBUILDER') {
613 if ($image_compression == 1) {
614 $tempImport = $imgConf['file.']['import'];
615 $tempImport_dot = $imgConf['file.']['import.'];
616 unset($imgConf['file.']);
617 $imgConf['file.']['import'] = $tempImport;
618 $imgConf['file.']['import.'] = $tempImport_dot;
619 } elseif (isset($this->cObj->image_compression[$image_compression])) {
620 $imgConf['file.']['params'] .= ' '.$this->cObj->image_compression[$image_compression]['params'];
621 $imgConf['file.']['ext'] = $this->cObj->image_compression[$image_compression]['ext'];
622 unset($imgConf['file.']['ext.']);
623 }
624 }
625 if ($titleInLink && ! $titleInLinkAndImg) {
626 // Check if the image will be linked
627 $link = $this->cObj->imageLinkWrap('', $totalImagePath, $imgConf['imageLinkWrap.']);
628 if ($link) {
629 // Title in A-tag only (set above: ATagParams), not in IMG-tag
630 unset($imgConf['titleText']);
631 unset($imgConf['titleText.']);
632 $imgConf['emptyTitleHandling'] = 'removeAttr';
633 }
634 }
635 $imgsTag[$a] = $this->cObj->IMAGE($imgConf);
636 } else {
637 $imgsTag[$a] = $this->cObj->IMAGE(Array('file' => $totalImagePath)); // currentValKey !!!
638 }
639 // Restore our ATagParams
640 $GLOBALS['TSFE']->ATagParams = $oldATagParms;
641 // Store the original filepath
642 $origImages[$a] = $GLOBALS['TSFE']->lastImageInfo;
643
644 $imageRowsFinalWidths[floor($a/$colCount)] += $GLOBALS['TSFE']->lastImageInfo[0];
645 }
646 // How much space will the image-block occupy?
647 $imageBlockWidth = max($imageRowsFinalWidths)+ $colspacing*($colCount-1) + $colCount*$border*($borderSpace+$borderThickness)*2;
648 $GLOBALS['TSFE']->register['rowwidth'] = $imageBlockWidth;
649 $GLOBALS['TSFE']->register['rowWidthPlusTextMargin'] = $imageBlockWidth + $textMargin;
650
651 // noRows is in fact just one ROW, with the amount of columns specified, where the images are placed in.
652 // noCols is just one COLUMN, each images placed side by side on each row
653 $noRows = $this->cObj->stdWrap($conf['noRows'],$conf['noRows.']);
654 $noCols = $this->cObj->stdWrap($conf['noCols'],$conf['noCols.']);
655 if ($noRows) {$noCols=0;} // noRows overrides noCols. They cannot exist at the same time.
656
657 $rowCount_temp = 1;
658 $colCount_temp = $colCount;
659 if ($noRows) {
660 $rowCount_temp = $rowCount;
661 $rowCount = 1;
662 }
663 if ($noCols) {
664 $colCount = 1;
665 $columnWidths = array();
666 }
667
668 // Edit icons:
669 $editIconsHTML = $conf['editIcons']&&$GLOBALS['TSFE']->beUserLogin ? $this->cObj->editIcons('',$conf['editIcons'],$conf['editIcons.']) : '';
670
671 // If noRows, we need multiple imagecolumn wraps
672 $imageWrapCols = 1;
673 if ($noRows) { $imageWrapCols = $colCount; }
674
675 // User wants to separate the rows, but only do that if we do have rows
676 $separateRows = $this->cObj->stdWrap($conf['separateRows'], $conf['separateRows.']);
677 if ($noRows) { $separateRows = 0; }
678 if ($rowCount == 1) { $separateRows = 0; }
679
680 // Apply optionSplit to the list of classes that we want to add to each image
681 $addClassesImage = $conf['addClassesImage'];
682 if ($conf['addClassesImage.']) {
683 $addClassesImage = $this->cObj->stdWrap($addClassesImage, $conf['addClassesImage.']);
684 }
685 $addClassesImageConf = $GLOBALS['TSFE']->tmpl->splitConfArray(array('addClassesImage' => $addClassesImage), $colCount);
686
687 // Render the images
688 $images = '';
689 for ($c = 0; $c < $imageWrapCols; $c++) {
690 $tmpColspacing = $colspacing;
691 if (($c==$imageWrapCols-1 && $imagePosition==2) || ($c==0 && ($imagePosition==1||$imagePosition==0))) {
692 // Do not add spacing after column if we are first column (left) or last column (center/right)
693 $tmpColspacing = 0;
694 }
695
696 $thisImages = '';
697 $allRows = '';
698 $maxImageSpace = 0;
699 for ($i = $c; $i<count($imgsTag); $i=$i+$imageWrapCols) {
700 $colPos = $i%$colCount;
701 if ($separateRows && $colPos == 0) {
702 $thisRow = '';
703 }
704
705 // Render one image
706 $imageSpace = $origImages[$i][0] + $border*($borderSpace+$borderThickness)*2;
707 $GLOBALS['TSFE']->register['IMAGE_NUM'] = $i;
708 $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $i;
709 $GLOBALS['TSFE']->register['ORIG_FILENAME'] = $origImages[$i]['origFile'];
710 $GLOBALS['TSFE']->register['imagewidth'] = $origImages[$i][0];
711 $GLOBALS['TSFE']->register['imagespace'] = $imageSpace;
712 $GLOBALS['TSFE']->register['imageheight'] = $origImages[$i][1];
713 if ($imageSpace > $maxImageSpace) {
714 $maxImageSpace = $imageSpace;
715 }
716 $thisImage = '';
717 $thisImage .= $this->cObj->stdWrap($imgsTag[$i], $conf['imgTagStdWrap.']);
718
719 if ($conf['captionSplit'] || $conf['imageTextSplit']) {
720 $thisImage .= $this->cObj->stdWrap($this->cObj->cObjGet($conf['caption.'], 'caption.'), $conf['caption.']);
721 }
722 if ($editIconsHTML) {
723 $thisImage .= $this->cObj->stdWrap($editIconsHTML, $conf['editIconsStdWrap.']);
724 }
725 $thisImage = $this->cObj->stdWrap($thisImage, $conf['oneImageStdWrap.']);
726 $classes = '';
727 if ($addClassesImageConf[$colPos]['addClassesImage']) {
728 $classes = ' ' . $addClassesImageConf[$colPos]['addClassesImage'];
729 }
730 $thisImage = str_replace('###CLASSES###', $classes, $thisImage);
731
732 if ($separateRows) {
733 $thisRow .= $thisImage;
734 } else {
735 $allRows .= $thisImage;
736 }
737 $GLOBALS['TSFE']->register['columnwidth'] = $maxImageSpace + $tmpColspacing;
738 if ($separateRows && ($colPos == ($colCount-1) || $i+1==count($imgsTag))) {
739 // Close this row at the end (colCount), or the last row at the final end
740 $allRows .= $this->cObj->stdWrap($thisRow, $conf['imageRowStdWrap.']);
741 }
742 }
743 if ($separateRows) {
744 $thisImages .= $allRows;
745 } else {
746 $thisImages .= $this->cObj->stdWrap($allRows, $conf['noRowsStdWrap.']);
747 }
748 if ($noRows) {
749 // Only needed to make columns, rather than rows:
750 $images .= $this->cObj->stdWrap($thisImages, $conf['imageColumnStdWrap.']);
751 } else {
752 $images .= $thisImages;
753 }
754 }
755
756 // Add the global caption, if not split
757 if ($caption) {
758 $images .= $caption;
759 }
760
761 // CSS-classes
762 $captionClass = '';
763 $classCaptionAlign = array(
764 'center' => 'csc-textpic-caption-c',
765 'right' => 'csc-textpic-caption-r',
766 'left' => 'csc-textpic-caption-l',
767 );
768 $captionAlign = $this->cObj->stdWrap($conf['captionAlign'], $conf['captionAlign.']);
769 if ($captionAlign) {
770 $captionClass = $classCaptionAlign[$captionAlign];
771 }
772 $borderClass = '';
773 if ($border) {
774 $borderClass = 'csc-textpic-border';
775 }
776
777 // Multiple classes with all properties, to be styled in CSS
778 $class = '';
779 $class .= ($borderClass? ' '.$borderClass:'');
780 $class .= ($captionClass? ' '.$captionClass:'');
781 $class .= ($equalHeight? ' csc-textpic-equalheight':'');
782 $addClasses = $this->cObj->stdWrap($conf['addClasses'], $conf['addClasses.']);
783 $class .= ($addClasses ? ' '.$addClasses:'');
784
785 // Do we need a width in our wrap around images?
786 $imgWrapWidth = '';
787 if ($position == 0 || $position == 8) {
788 // For 'center' we always need a width: without one, the margin:auto trick won't work
789 $imgWrapWidth = $imageBlockWidth;
790 }
791 if ($rowCount > 1) {
792 // For multiple rows we also need a width, so that the images will wrap
793 $imgWrapWidth = $imageBlockWidth;
794 }
795 if ($caption) {
796 // If we have a global caption, we need the width so that the caption will wrap
797 $imgWrapWidth = $imageBlockWidth;
798 }
799
800 // Wrap around the whole image block
801 $GLOBALS['TSFE']->register['totalwidth'] = $imgWrapWidth;
802 if ($imgWrapWidth) {
803 $images = $this->cObj->stdWrap($images, $conf['imageStdWrap.']);
804 } else {
805 $images = $this->cObj->stdWrap($images, $conf['imageStdWrapNoWidth.']);
806 }
807
808 $output = $this->cObj->cObjGetSingle($conf['layout'], $conf['layout.']);
809 $output = str_replace('###TEXT###', $content, $output);
810 $output = str_replace('###IMAGES###', $images, $output);
811 $output = str_replace('###CLASSES###', $class, $output);
812
813 if ($conf['stdWrap.']) {
814 $output = $this->cObj->stdWrap($output, $conf['stdWrap.']);
815 }
816
817 return $output;
818 }
819
820
821
822
823
824
825
826
827
828
829
830
831 /************************************
832 *
833 * Helper functions
834 *
835 ************************************/
836
837 /**
838 * Returns table attributes for uploads / tables.
839 *
840 * @param array TypoScript configuration array
841 * @param integer The "layout" type
842 * @return array Array with attributes inside.
843 */
844 function getTableAttributes($conf,$type) {
845
846 // Initializing:
847 $tableTagParams_conf = $conf['tableParams_'.$type.'.'];
848
849 $conf['color.'][200] = '';
850 $conf['color.'][240] = 'black';
851 $conf['color.'][241] = 'white';
852 $conf['color.'][242] = '#333333';
853 $conf['color.'][243] = 'gray';
854 $conf['color.'][244] = 'silver';
855
856 // Create table attributes array:
857 $tableTagParams = array();
858 $tableTagParams['border'] = $this->cObj->data['table_border'] ? intval($this->cObj->data['table_border']) : $tableTagParams_conf['border'];
859 $tableTagParams['cellspacing'] = $this->cObj->data['table_cellspacing'] ? intval($this->cObj->data['table_cellspacing']) : $tableTagParams_conf['cellspacing'];
860 $tableTagParams['cellpadding'] = $this->cObj->data['table_cellpadding'] ? intval($this->cObj->data['table_cellpadding']) : $tableTagParams_conf['cellpadding'];
861 $tableTagParams['bgcolor'] = isset($conf['color.'][$this->cObj->data['table_bgColor']]) ? $conf['color.'][$this->cObj->data['table_bgColor']] : $conf['color.']['default'];
862
863 // Return result:
864 return $tableTagParams;
865 }
866
867 /**
868 * Returns an object reference to the hook object if any
869 *
870 * @param string Name of the function you want to call / hook key
871 * @return object Hook object, if any. Otherwise null.
872 */
873 function &hookRequest($functionName) {
874 global $TYPO3_CONF_VARS;
875
876 // Hook: menuConfig_preProcessModMenu
877 if ($TYPO3_CONF_VARS['EXTCONF']['css_styled_content']['pi1_hooks'][$functionName]) {
878 $hookObj = &t3lib_div::getUserObj($TYPO3_CONF_VARS['EXTCONF']['css_styled_content']['pi1_hooks'][$functionName]);
879 if (method_exists ($hookObj, $functionName)) {
880 $hookObj->pObj = &$this;
881 return $hookObj;
882 }
883 }
884 }
885 }
886
887
888
889 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/css_styled_content/pi1/class.tx_cssstyledcontent_pi1.php']) {
890 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/css_styled_content/pi1/class.tx_cssstyledcontent_pi1.php']);
891 }
892 ?>