58f142f4209f8c90c75be169421a7f8af37fdd17
[TYPO3CMS/Extensions/dam_ttcontent.git] / pi_cssstyledcontent / class.tx_damttcontent_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: class.tx_cssstyledcontent_pi1.php 1618 2006-07-10 17:24:44Z baschny $
31 *
32 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
33 */
34 /**
35 *
36 * TOTAL FUNCTIONS: 6
37 * (This index is automatically created/updated by the extension "extdeveval")
38 *
39 */
40
41 require_once(t3lib_extMgm::extPath('css_styled_content').'pi1/class.tx_cssstyledcontent_pi1.php');
42
43
44
45 /**
46 * Plugin class - instantiated from TypoScript.
47 * Rendering some content elements from tt_content table.
48 *
49 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
50 * @package TYPO3
51 * @subpackage tx_cssstyledcontent
52 */
53 class tx_damttcontent_pi1 extends tx_cssstyledcontent_pi1 {
54
55
56 function addMetaToData ($meta) {
57 foreach ($meta as $key => $value) {
58 $this->pObj->cObj->data['txdam_' . $key] = $value;
59 }
60 }
61
62 function removeMetaFromData () {
63 foreach ($this->pObj->cObj->data as $key => $value) {
64 if (substr($key, 0, 6) == 'txdam_') {
65 unset($this->pObj->cObj->data[$key]);
66 }
67 }
68 }
69
70 /**
71 * returns an array containing width relations for $colCount columns.
72 *
73 * tries to use "colRelations" setting given by TS.
74 * uses "1:1" column relations by default.
75 *
76 * @param array $conf TS configuration for img
77 * @param int $colCount number of columns
78 * @return array
79 */
80 protected function getImgColumnRelations($conf, $colCount) {
81 $relations = array();
82 $equalRelations= array_fill(0, $colCount, 1);
83 $colRelationsTypoScript = trim($this->pObj->cObj->stdWrap($conf['colRelations'], $conf['colRelations.']));
84
85 if ($colRelationsTypoScript) {
86 // try to use column width relations given by TS
87 $relationParts = explode(':', $colRelationsTypoScript);
88 // enough columns defined?
89 if (count($relationParts) >= $colCount) {
90 $out = array();
91 for ($a = 0; $a < $colCount; $a++) {
92 $currentRelationValue = intval($relationParts[$a]);
93 if ($currentRelationValue >= 1) {
94 $out[$a] = $currentRelationValue;
95 } else {
96 t3lib_div::devLog('colRelations used with a value smaller than 1 therefore colRelations setting is ignored.', $this->extKey, 2);
97 unset($out);
98 break;
99 }
100 }
101 if (max($out) / min($out) <= 10) {
102 $relations = $out;
103 } else {
104 t3lib_div::devLog('The difference in size between the largest and smallest colRelation was not within a factor of ten therefore colRelations setting is ignored..', $this->extKey, 2);
105 }
106 }
107 }
108 return $relations ? $relations : $equalRelations;
109 }
110
111 /**
112 * Rendering the IMGTEXT content element, called from TypoScript (tt_content.textpic.20)
113 *
114 * @param string Content input. Not used, ignore.
115 * @param array TypoScript configuration. See TSRef "IMGTEXT". This function aims to be compatible.
116 * @return string HTML output.
117 * @access private
118 * @coauthor Ernesto Baschny <ernst@cron-it.de>
119 * @coauthor Patrick Broens <patrick@patrickbroens.nl>
120 */
121 function render_textpic($content, $conf) {
122 // Look for hook before running default code for function
123 if (method_exists($this, 'hookRequest') && $hookObj = $this->hookRequest('render_textpic')) {
124 return $hookObj->render_textpic($content,$conf);
125 }
126
127 $renderMethod = $this->pObj->cObj->stdWrap($conf['renderMethod'], $conf['renderMethod.']);
128
129 // Render using the default IMGTEXT code (table-based)
130 if (!$renderMethod || $renderMethod == 'table') {
131 return $this->pObj->cObj->IMGTEXT($conf);
132 }
133
134 // Specific configuration for the chosen rendering method
135 if (is_array($conf['rendering.'][$renderMethod . '.'])) {
136 $conf = $this->pObj->cObj->joinTSarrays($conf, $conf['rendering.'][$renderMethod . '.']);
137 }
138
139 // Image or Text with Image?
140 if (is_array($conf['text.'])) {
141 $content = $this->pObj->cObj->stdWrap($this->pObj->cObj->cObjGet($conf['text.'], 'text.'), $conf['text.']);
142 }
143
144 $imgList = trim($this->pObj->cObj->stdWrap($conf['imgList'], $conf['imgList.']));
145
146 if (!$imgList) {
147 // No images, that's easy
148 if (is_array($conf['stdWrap.'])) {
149 return $this->pObj->cObj->stdWrap($content, $conf['stdWrap.']);
150 }
151 return $content;
152 }
153
154 $imgs = t3lib_div::trimExplode(',', $imgList);
155 $imgStart = intval($this->pObj->cObj->stdWrap($conf['imgStart'], $conf['imgStart.']));
156 $imgCount = count($imgs) - $imgStart;
157 $imgMax = intval($this->pObj->cObj->stdWrap($conf['imgMax'], $conf['imgMax.']));
158 if ($imgMax) {
159 $imgCount = tx_dam::forceIntegerInRange($imgCount, 0, $imgMax); // reduce the number of images.
160 }
161
162 $imgPath = $this->pObj->cObj->stdWrap($conf['imgPath'], $conf['imgPath.']);
163
164 // Does we need to render a "global caption" (below the whole image block)?
165 $renderGlobalCaption = !$conf['captionEach'] && !$conf['captionSplit'] && !$conf['imageTextSplit'] && is_array($conf['caption.']);
166 if ($imgCount == 1) {
167 // If we just have one image, the caption relates to the image, so it is not "global"
168 $renderGlobalCaption = FALSE;
169 }
170
171 // Use the calculated information (amount of images, if global caption is wanted) to choose a different rendering method for the images-block
172 $GLOBALS['TSFE']->register['imageCount'] = $imgCount;
173 $GLOBALS['TSFE']->register['renderGlobalCaption'] = $renderGlobalCaption;
174 $fallbackRenderMethod = $this->pObj->cObj->cObjGetSingle($conf['fallbackRendering'], $conf['fallbackRendering.']);
175
176 // Set the accessibility mode which uses a different type of markup, used 4.7+
177 $accessibilityMode = FALSE;
178 if (strpos(strtolower($renderMethod), 'caption') || strpos(strtolower($fallbackRenderMethod), 'caption')) {
179 $accessibilityMode = TRUE;
180 }
181
182 // Global caption
183 $globalCaption = '';
184 if ($renderGlobalCaption) {
185 $globalCaption = $this->pObj->cObj->stdWrap($this->pObj->cObj->cObjGet($conf['caption.'], 'caption.'), $conf['caption.']);
186 }
187
188 // Positioning
189 $position = $this->pObj->cObj->stdWrap($conf['textPos'], $conf['textPos.']);
190
191 $imagePosition = $position&7; // 0,1,2 = center,right,left
192 $contentPosition = $position&24; // 0,8,16,24 (above,below,intext,intext-wrap)
193 $align = $this->pObj->cObj->align[$imagePosition];
194 $textMargin = intval($this->pObj->cObj->stdWrap($conf['textMargin'],$conf['textMargin.']));
195 if (!$conf['textMargin_outOfText'] && $contentPosition < 16) {
196 $textMargin = 0;
197 }
198
199 $colspacing = intval($this->pObj->cObj->stdWrap($conf['colSpace'], $conf['colSpace.']));
200 $rowspacing = intval($this->pObj->cObj->stdWrap($conf['rowSpace'], $conf['rowSpace.']));
201
202 $border = intval($this->pObj->cObj->stdWrap($conf['border'], $conf['border.'])) ? 1:0;
203 $borderColor = $this->pObj->cObj->stdWrap($conf['borderCol'], $conf['borderCol.']);
204 $borderThickness = intval($this->pObj->cObj->stdWrap($conf['borderThick'], $conf['borderThick.']));
205
206 $borderColor = $borderColor?$borderColor:'black';
207 $borderThickness = $borderThickness?$borderThickness:1;
208 $borderSpace = (($conf['borderSpace']&&$border) ? intval($conf['borderSpace']) : 0);
209
210 // Generate cols
211 $cols = intval($this->pObj->cObj->stdWrap($conf['cols'],$conf['cols.']));
212 $colCount = ($cols > 1) ? $cols : 1;
213 if ($colCount > $imgCount) {$colCount = $imgCount;}
214 $rowCount = ceil($imgCount / $colCount);
215
216 // Generate rows
217 $rows = intval($this->pObj->cObj->stdWrap($conf['rows'],$conf['rows.']));
218 if ($rows>1) {
219 $rowCount = $rows;
220 if ($rowCount > $imgCount) {$rowCount = $imgCount;}
221 $colCount = ($rowCount>1) ? ceil($imgCount / $rowCount) : $imgCount;
222 }
223
224 // Max Width
225 $maxW = intval($this->pObj->cObj->stdWrap($conf['maxW'], $conf['maxW.']));
226 $maxWInText = intval($this->pObj->cObj->stdWrap($conf['maxWInText'], $conf['maxWInText.']));
227 $fiftyPercentWidthInText = round($maxW / 100 * 50);
228
229 if ($contentPosition>=16) { // in Text
230 if (!$maxWInText) {
231 // If maxWInText is not set, it's calculated to the 50% of the max
232 $maxW = $fiftyPercentWidthInText;
233 } else {
234 $maxW = $maxWInText;
235 }
236 }
237
238 // Set the margin for image + text, no wrap always to avoid multiple stylesheets
239 if ($accessibilityMode) {
240 $noWrapMargin = (integer) (($maxWInText ? $maxWInText : $fiftyPercentWidthInText) +
241 intval($this->pObj->cObj->stdWrap($conf['textMargin'],$conf['textMargin.'])));
242
243 $this->addPageStyle(
244 '.csc-textpic-intext-right-nowrap .csc-textpic-text',
245 'margin-right: ' . $noWrapMargin . 'px;'
246 );
247
248 $this->addPageStyle(
249 '.csc-textpic-intext-left-nowrap .csc-textpic-text',
250 'margin-left: ' . $noWrapMargin . 'px;'
251 );
252 }
253
254 // max usuable width for images (without spacers and borders)
255 $netW = $maxW - $colspacing * ($colCount - 1) - $colCount * $border * ($borderThickness + $borderSpace) * 2;
256
257 // Specify the maximum width for each column
258 $columnWidths = $this->getImgColumnWidths($conf, $colCount, $netW);
259
260 $image_compression = intval($this->pObj->cObj->stdWrap($conf['image_compression'],$conf['image_compression.']));
261 $image_effects = intval($this->pObj->cObj->stdWrap($conf['image_effects'],$conf['image_effects.']));
262 $image_frames = intval($this->pObj->cObj->stdWrap($conf['image_frames.']['key'],$conf['image_frames.']['key.']));
263
264 // EqualHeight
265 $equalHeight = intval($this->pObj->cObj->stdWrap($conf['equalH'],$conf['equalH.']));
266 if ($equalHeight) {
267 // Initiate gifbuilder object in order to get dimensions AND calculate the imageWidth's
268 $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
269 $gifCreator->init();
270 $relations_cols = Array();
271 $imgWidths = array(); // contains the individual width of all images after scaling to $equalHeight
272 for ($a=0; $a<$imgCount; $a++) {
273 $imgKey = $a+$imgStart;
274 $imgInfo = $gifCreator->getImageDimensions($imgPath.$imgs[$imgKey]);
275 $rel = $imgInfo[1] / $equalHeight; // relationship between the original height and the wished height
276 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.
277 $imgWidths[$a] = $imgInfo[0] / $rel;
278 $relations_cols[floor($a/$colCount)] += $imgWidths[$a]; // counts the total width of the row with the new height taken into consideration.
279 }
280 }
281 }
282
283 // Fetches pictures
284 $splitArr = array();
285 $splitArr['imgObjNum'] = $conf['imgObjNum'];
286 $splitArr = $GLOBALS['TSFE']->tmpl->splitConfArray($splitArr, $imgCount);
287
288 $imageRowsFinalWidths = Array(); // contains the width of every image row
289 $imgsTag = array(); // array index of $imgsTag will be the same as in $imgs, but $imgsTag only contains the images that are actually shown
290 $origImages = array();
291 $rowIdx = 0;
292 for ($a=0; $a<$imgCount; $a++) {
293 $imgKey = $a+$imgStart;
294 $totalImagePath = $imgPath.$imgs[$imgKey];
295
296 $GLOBALS['TSFE']->register['IMAGE_NUM'] = $imgKey; // register IMG_NUM is kept for backwards compatibility
297 $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $imgKey;
298 $GLOBALS['TSFE']->register['ORIG_FILENAME'] = $totalImagePath;
299
300 $this->pObj->cObj->data[$this->pObj->cObj->currentValKey] = $totalImagePath;
301
302 // fetch DAM data and provide it as field data prefixed with txdam_
303 $media = tx_dam::media_getForFile($totalImagePath, '*');
304 if ($media->isAvailable) {
305 $this->addMetaToData ($media->getMetaArray());
306 $imgsExtraData[$imgKey] = $media->getMetaArray();
307 } else {
308 $this->removeMetaFromData();
309 $imgsExtraData[$imgKey] = array();
310 }
311 unset($media);
312
313 $imgObjNum = intval($splitArr[$a]['imgObjNum']);
314 $imgConf = $conf[$imgObjNum.'.'];
315
316 if ($equalHeight) {
317
318 if ($a % $colCount == 0) {
319 // a new row startsS
320 $accumWidth = 0; // reset accumulated net width
321 $accumDesiredWidth = 0; // reset accumulated desired width
322 $rowTotalMaxW = $relations_cols[$rowIdx];
323 if ($rowTotalMaxW > $netW) {
324 $scale = $rowTotalMaxW / $netW;
325 } else {
326 $scale = 1;
327 }
328 $desiredHeight = $equalHeight / $scale;
329 $rowIdx++;
330 }
331
332 $availableWidth= $netW - $accumWidth; // this much width is available for the remaining images in this row (int)
333 $desiredWidth= $imgWidths[$a] / $scale; // theoretical width of resized image. (float)
334 $accumDesiredWidth += $desiredWidth; // add this width. $accumDesiredWidth becomes the desired horizontal position
335 // calculate width by comparing actual and desired horizontal position.
336 // this evenly distributes rounding errors across all images in this row.
337 $suggestedWidth = round($accumDesiredWidth - $accumWidth);
338 $finalImgWidth = (int) min($availableWidth, $suggestedWidth); // finalImgWidth may not exceed $availableWidth
339 $accumWidth += $finalImgWidth;
340 $imgConf['file.']['width'] = $finalImgWidth;
341 $imgConf['file.']['height'] = round($desiredHeight);
342
343 // other stuff will be calculated accordingly:
344 unset($imgConf['file.']['maxW']);
345 unset($imgConf['file.']['maxH']);
346 unset($imgConf['file.']['minW']);
347 unset($imgConf['file.']['minH']);
348 unset($imgConf['file.']['width.']);
349 unset($imgConf['file.']['maxW.']);
350 unset($imgConf['file.']['maxH.']);
351 unset($imgConf['file.']['minW.']);
352 unset($imgConf['file.']['minH.']);
353 } else {
354 $imgConf['file.']['maxW'] = $columnWidths[($a%$colCount)];
355 }
356
357 $titleInLink = $this->pObj->cObj->stdWrap($imgConf['titleInLink'], $imgConf['titleInLink.']);
358 $titleInLinkAndImg = $this->pObj->cObj->stdWrap($imgConf['titleInLinkAndImg'], $imgConf['titleInLinkAndImg.']);
359 $oldATagParms = $GLOBALS['TSFE']->ATagParams;
360 if ($titleInLink) {
361 // Title in A-tag instead of IMG-tag
362 $titleText = trim($this->pObj->cObj->stdWrap($imgConf['titleText'], $imgConf['titleText.']));
363 if ($titleText) {
364 // This will be used by the IMAGE call later:
365 $GLOBALS['TSFE']->ATagParams .= ' title="'. $titleText .'"';
366 }
367 }
368
369 if ($imgConf || $imgConf['file']) {
370 if ($this->pObj->cObj->image_effects[$image_effects]) {
371 $imgConf['file.']['params'] .= ' '.$this->pObj->cObj->image_effects[$image_effects];
372 }
373 if ($image_frames) {
374 if (is_array($conf['image_frames.'][$image_frames.'.'])) {
375 $imgConf['file.']['m.'] = $conf['image_frames.'][$image_frames.'.'];
376 }
377 }
378 if ($image_compression && $imgConf['file'] != 'GIFBUILDER') {
379 if ($image_compression == 1) {
380 $tempImport = $imgConf['file.']['import'];
381 $tempImport_dot = $imgConf['file.']['import.'];
382 unset($imgConf['file.']);
383 $imgConf['file.']['import'] = $tempImport;
384 $imgConf['file.']['import.'] = $tempImport_dot;
385 } elseif (isset($this->pObj->cObj->image_compression[$image_compression])) {
386 $imgConf['file.']['params'] .= ' '.$this->pObj->cObj->image_compression[$image_compression]['params'];
387 $imgConf['file.']['ext'] = $this->pObj->cObj->image_compression[$image_compression]['ext'];
388 unset($imgConf['file.']['ext.']);
389 }
390 }
391 if ($titleInLink && ! $titleInLinkAndImg) {
392 // Check if the image will be linked
393 $link = $this->pObj->cObj->imageLinkWrap('', $totalImagePath, $imgConf['imageLinkWrap.']);
394 if ($link) {
395 // Title in A-tag only (set above: ATagParams), not in IMG-tag
396 unset($imgConf['titleText']);
397 unset($imgConf['titleText.']);
398 $imgConf['emptyTitleHandling'] = 'removeAttr';
399 }
400 }
401 $imgsTag[$imgKey] = $this->pObj->cObj->IMAGE($imgConf);
402 } else {
403 $imgsTag[$imgKey] = $this->pObj->cObj->IMAGE(Array('file' => $totalImagePath)); // currentValKey !!!
404 }
405 // Restore our ATagParams
406 $GLOBALS['TSFE']->ATagParams = $oldATagParms;
407 // Store the original filepath
408 $origImages[$imgKey] = $GLOBALS['TSFE']->lastImageInfo;
409
410 if ($GLOBALS['TSFE']->lastImageInfo[0]==0) {
411 $imageRowsFinalWidths[floor($a/$colCount)] += $this->pObj->cObj->data['imagewidth'];
412 } else {
413 $imageRowsFinalWidths[floor($a/$colCount)] += $GLOBALS['TSFE']->lastImageInfo[0];
414 }
415
416 }
417 // How much space will the image-block occupy?
418 $imageBlockWidth = max($imageRowsFinalWidths)+ $colspacing*($colCount-1) + $colCount*$border*($borderSpace+$borderThickness)*2;
419 $GLOBALS['TSFE']->register['rowwidth'] = $imageBlockWidth;
420 $GLOBALS['TSFE']->register['rowWidthPlusTextMargin'] = $imageBlockWidth + $textMargin;
421
422 // noRows is in fact just one ROW, with the amount of columns specified, where the images are placed in.
423 // noCols is just one COLUMN, each images placed side by side on each row
424 $noRows = $this->pObj->cObj->stdWrap($conf['noRows'],$conf['noRows.']);
425 $noCols = $this->pObj->cObj->stdWrap($conf['noCols'],$conf['noCols.']);
426 if ($noRows) {$noCols=0;} // noRows overrides noCols. They cannot exist at the same time.
427
428 $rowCount_temp = 1;
429 $colCount_temp = $colCount;
430 if ($noRows) {
431 $rowCount_temp = $rowCount;
432 $rowCount = 1;
433 }
434 if ($noCols) {
435 $colCount = 1;
436 $columnWidths = array();
437 }
438
439 // Edit icons:
440 if (!is_array($conf['editIcons.'])) {
441 $conf['editIcons.'] = array();
442 }
443 $editIconsHTML = $conf['editIcons']&&$GLOBALS['TSFE']->beUserLogin ? $this->pObj->cObj->editIcons('',$conf['editIcons'],$conf['editIcons.']) : '';
444
445 // If noRows, we need multiple imagecolumn wraps
446 $imageWrapCols = 1;
447 if ($noRows) { $imageWrapCols = $colCount; }
448
449 // User wants to separate the rows, but only do that if we do have rows
450 $separateRows = $this->pObj->cObj->stdWrap($conf['separateRows'], $conf['separateRows.']);
451 if ($noRows) { $separateRows = 0; }
452 if ($rowCount == 1) { $separateRows = 0; }
453
454 if ($accessibilityMode) {
455 $imagesInColumns = round(($imgCount / ($rowCount * $colCount)), 0 , PHP_ROUND_HALF_UP);
456
457 // Apply optionSplit to the list of classes that we want to add to each column
458 $addClassesCol = $conf['addClassesCol'];
459 if (isset($conf['addClassesCol.'])) {
460 $addClassesCol = $this->pObj->cObj->stdWrap($addClassesCol, $conf['addClassesCol.']);
461 }
462 $addClassesColConf = $GLOBALS['TSFE']->tmpl->splitConfArray(array('addClassesCol' => $addClassesCol), $colCount);
463
464 // Apply optionSplit to the list of classes that we want to add to each image
465 $addClassesImage = $conf['addClassesImage'];
466 if (isset($conf['addClassesImage.'])) {
467 $addClassesImage = $this->pObj->cObj->stdWrap($addClassesImage, $conf['addClassesImage.']);
468 }
469 $addClassesImageConf = $GLOBALS['TSFE']->tmpl->splitConfArray(array('addClassesImage' => $addClassesImage), $imagesInColumns);
470
471 $rows = array();
472 $currentImage = 0;
473
474 // Set the class for the caption (split or global)
475 $classCaptionAlign = array(
476 'center' => 'csc-textpic-caption-c',
477 'right' => 'csc-textpic-caption-r',
478 'left' => 'csc-textpic-caption-l',
479 );
480
481 $captionAlign = $this->pObj->cObj->stdWrap($conf['captionAlign'], $conf['captionAlign.']);
482
483 // Iterate over the rows
484 for ($rowCounter = 1; $rowCounter <= $rowCount; $rowCounter++) {
485 $rowColumns = array();
486 // Iterate over the columns
487 for ($columnCounter = 1; $columnCounter <= $colCount; $columnCounter++) {
488 $columnImages = array();
489 // Iterate over the amount of images allowed in a column
490 for ($imagesCounter = 1; $imagesCounter <= $imagesInColumns; $imagesCounter++) {
491 $image = NULL;
492 $splitCaption = NULL;
493
494 // add DAM metadata to current object
495 $this->addMetaToData($imgsExtraData[$currentImage]);
496
497 $imageMarkers = $captionMarkers = array();
498 $single = '&nbsp;';
499
500 // Set the key of the current image
501 $imageKey = $currentImage + $imgStart;
502
503 // Register IMAGE_NUM_CURRENT for the caption
504 $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $imageKey;
505 $this->pObj->cObj->data[$this->pObj->cObj->currentValKey] = $origImages[$imageKey]['origFile'];
506
507 // Get the image if not an empty cell
508 if (isset($imgsTag[$imageKey])) {
509 $image = $this->pObj->cObj->stdWrap($imgsTag[$imageKey], $conf['imgTagStdWrap.']);
510
511 // Add the edit icons
512 if ($editIconsHTML) {
513 $image .= $this->pObj->cObj->stdWrap($editIconsHTML, $conf['editIconsStdWrap.']);
514 }
515
516 // Wrap the single image
517 $single = $this->pObj->cObj->stdWrap($image, $conf['singleStdWrap.']);
518
519 // Get the caption
520 if (!$renderGlobalCaption) {
521 $imageMarkers['caption'] = $this->pObj->cObj->stdWrap(
522 $this->pObj->cObj->cObjGet($conf['caption.'], 'caption.'), $conf['caption.']
523 );
524
525 if ($captionAlign) {
526 $captionMarkers['classes'] = ' ' . $classCaptionAlign[$captionAlign];
527 }
528
529 $imageMarkers['caption'] = $this->pObj->cObj->substituteMarkerArray(
530 $imageMarkers['caption'],
531 $captionMarkers,
532 '###|###',
533 1,
534 1
535 );
536 }
537
538 if ($addClassesImageConf[$imagesCounter - 1]['addClassesImage']) {
539 $imageMarkers['classes'] = ' ' . $addClassesImageConf[$imagesCounter - 1]['addClassesImage'];
540 }
541 }
542
543 $columnImages[] = $this->pObj->cObj->substituteMarkerArray(
544 $single,
545 $imageMarkers,
546 '###|###',
547 1,
548 1
549 );
550
551 $currentImage++;
552 }
553
554 $rowColumn = $this->pObj->cObj->stdWrap(
555 implode(LF, $columnImages),
556 $conf['columnStdWrap.']
557 );
558
559 // Start filling the markers for columnStdWrap
560 $columnMarkers = array();
561
562 if ($addClassesColConf[$columnCounter - 1]['addClassesCol']) {
563 $columnMarkers['classes'] = ' ' . $addClassesColConf[$columnCounter - 1]['addClassesCol'];
564 }
565
566 $rowColumns[] = $this->pObj->cObj->substituteMarkerArray(
567 $rowColumn,
568 $columnMarkers,
569 '###|###',
570 1,
571 1
572 );
573 }
574 if ($noRows) {
575 $rowConfiguration = $conf['noRowsStdWrap.'];
576 } elseif ($rowCounter == $rowCount) {
577 $rowConfiguration = $conf['lastRowStdWrap.'];
578 } else {
579 $rowConfiguration = $conf['rowStdWrap.'];
580 }
581
582 $row = $this->pObj->cObj->stdWrap(
583 implode(LF, $rowColumns),
584 $rowConfiguration
585 );
586
587 // Start filling the markers for columnStdWrap
588 $rowMarkers = array();
589
590 $rows[] = $this->pObj->cObj->substituteMarkerArray(
591 $row,
592 $rowMarkers,
593 '###|###',
594 1,
595 1
596 );
597 }
598
599 $images = $this->pObj->cObj->stdWrap(
600 implode(LF, $rows),
601 $conf['allStdWrap.']
602 );
603 // Start filling the markers for allStdWrap
604 $allMarkers = array();
605 $classes = array();
606
607 // Add the global caption to the allStdWrap marker array if set
608 if ($globalCaption) {
609 $allMarkers['caption'] = $globalCaption;
610 if ($captionAlign) {
611 $classes[] = $classCaptionAlign[$captionAlign];
612 }
613 }
614
615 // Add the border class if needed
616 if ($border){
617 $classes[] = $conf['borderClass'] ? $conf['borderClass'] : 'csc-textpic-border';
618 }
619
620 // Add the class for equal height if needed
621 if ($equalHeight) {
622 $classes[] = 'csc-textpic-equalheight';
623 }
624
625 $addClasses = $this->pObj->cObj->stdWrap($conf['addClasses'], $conf['addClasses.']);
626 if ($addClasses) {
627 $classes[] = $addClasses;
628 }
629
630 if ($classes) {
631 $class = ' ' . implode(' ', $classes);
632 }
633
634 // Fill the markers for the allStdWrap
635 $images = $this->pObj->cObj->substituteMarkerArray(
636 $images,
637 $allMarkers,
638 '###|###',
639 1,
640 1
641 );
642 } else {
643 // Apply optionSplit to the list of classes that we want to add to each image
644 $addClassesImage = $conf['addClassesImage'];
645 if (isset($conf['addClassesImage.'])) {
646 $addClassesImage = $this->pObj->cObj->stdWrap($addClassesImage, $conf['addClassesImage.']);
647 }
648 $addClassesImageConf = $GLOBALS['TSFE']->tmpl->splitConfArray(array('addClassesImage' => $addClassesImage), $colCount);
649
650 // Render the images
651 $images = '';
652 for ($c = 0; $c < $imageWrapCols; $c++) {
653 $tmpColspacing = $colspacing;
654 if (($c == $imageWrapCols - 1 && $imagePosition == 2) || ($c == 0 && ($imagePosition == 1 || $imagePosition == 0))) {
655 // Do not add spacing after column if we are first column (left) or last column (center/right)
656 $tmpColspacing = 0;
657 }
658
659 $thisImages = '';
660 $allRows = '';
661 $maxImageSpace = 0;
662 for ($i = $c; $i < count($imgsTag); $i = $i + $imageWrapCols) {
663 $imgKey = $i + $imgStart;
664 $colPos = $i % $colCount;
665 if ($separateRows && $colPos == 0) {
666 $thisRow = '';
667 }
668
669 // add DAM metadata to current object
670 $this->addMetaToData($imgsExtraData[$i]);
671
672 // Render one image
673 if($origImages[$imgKey][0]==0) {
674 $imageSpace = $this->pObj->cObj->data['imagewidth'] + $border * ($borderSpace + $borderThickness) * 2;
675 } else {
676 $imageSpace = $origImages[$imgKey][0] + $border * ($borderSpace + $borderThickness) * 2;
677 }
678
679 $GLOBALS['TSFE']->register['IMAGE_NUM'] = $imgKey;
680 $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $imgKey;
681 $GLOBALS['TSFE']->register['ORIG_FILENAME'] = $origImages[$imgKey]['origFile'];
682 $GLOBALS['TSFE']->register['imagewidth'] = $origImages[$imgKey][0];
683 $GLOBALS['TSFE']->register['imagespace'] = $imageSpace;
684 $GLOBALS['TSFE']->register['imageheight'] = $origImages[$imgKey][1];
685 if ($imageSpace > $maxImageSpace) {
686 $maxImageSpace = $imageSpace;
687 }
688 $thisImage = '';
689 $thisImage .= $this->pObj->cObj->stdWrap($imgsTag[$imgKey], $conf['imgTagStdWrap.']);
690
691 if (!$renderGlobalCaption) {
692 $thisImage .= $this->pObj->cObj->stdWrap($this->pObj->cObj->cObjGet($conf['caption.'], 'caption.'), $conf['caption.']);
693 }
694 if ($editIconsHTML) {
695 $thisImage .= $this->pObj->cObj->stdWrap($editIconsHTML, $conf['editIconsStdWrap.']);
696 }
697 $thisImage = $this->pObj->cObj->stdWrap($thisImage, $conf['oneImageStdWrap.']);
698 $classes = '';
699 if ($addClassesImageConf[$colPos]['addClassesImage']) {
700 $classes = ' ' . $addClassesImageConf[$colPos]['addClassesImage'];
701 }
702 $thisImage = str_replace('###CLASSES###', $classes, $thisImage);
703
704 if ($separateRows) {
705 $thisRow .= $thisImage;
706 } else {
707 $allRows .= $thisImage;
708 }
709 $GLOBALS['TSFE']->register['columnwidth'] = $maxImageSpace + $tmpColspacing;
710
711
712 // Close this row at the end (colCount), or the last row at the final end
713 if ($separateRows && ($i + 1 == count($imgsTag))) {
714 // Close the very last row with either normal configuration or lastRow stdWrap
715 $allRows .= $this->pObj->cObj->stdWrap($thisRow, (is_array($conf['imageLastRowStdWrap.']) ? $conf['imageLastRowStdWrap.'] : $conf['imageRowStdWrap.']));
716 } elseif ($separateRows && $colPos == $colCount - 1) {
717 $allRows .= $this->pObj->cObj->stdWrap($thisRow, $conf['imageRowStdWrap.']);
718 }
719 }
720 if ($separateRows) {
721 $thisImages .= $allRows;
722 } else {
723 $thisImages .= $this->pObj->cObj->stdWrap($allRows, $conf['noRowsStdWrap.']);
724 }
725 if ($noRows) {
726 // Only needed to make columns, rather than rows:
727 $images .= $this->pObj->cObj->stdWrap($thisImages, $conf['imageColumnStdWrap.']);
728 } else {
729 $images .= $thisImages;
730 }
731 }
732
733 // Add the global caption, if not split
734 if ($globalCaption) {
735 $images .= $globalCaption;
736 }
737
738 // CSS-classes
739 $captionClass = '';
740 $classCaptionAlign = array(
741 'center' => 'csc-textpic-caption-c',
742 'right' => 'csc-textpic-caption-r',
743 'left' => 'csc-textpic-caption-l',
744 );
745 $captionAlign = $this->pObj->cObj->stdWrap($conf['captionAlign'], $conf['captionAlign.']);
746 if ($captionAlign) {
747 $captionClass = $classCaptionAlign[$captionAlign];
748 }
749 $borderClass = '';
750 if ($border) {
751 $borderClass = $conf['borderClass'] ? $conf['borderClass'] : 'csc-textpic-border';
752 }
753
754 // Multiple classes with all properties, to be styled in CSS
755 $class = '';
756 $class .= ($borderClass ? ' ' . $borderClass : '');
757 $class .= ($captionClass ? ' ' . $captionClass : '');
758 $class .= ($equalHeight ? ' csc-textpic-equalheight' : '');
759 $addClasses = $this->pObj->cObj->stdWrap($conf['addClasses'], $conf['addClasses.']);
760 $class .= ($addClasses ? ' ' . $addClasses : '');
761
762 // Do we need a width in our wrap around images?
763 $imgWrapWidth = '';
764 if ($position == 0 || $position == 8) {
765 // For 'center' we always need a width: without one, the margin:auto trick won't work
766 $imgWrapWidth = $imageBlockWidth;
767 }
768 if ($rowCount > 1) {
769 // For multiple rows we also need a width, so that the images will wrap
770 $imgWrapWidth = $imageBlockWidth;
771 }
772 if ($globalCaption) {
773 // If we have a global caption, we need the width so that the caption will wrap
774 $imgWrapWidth = $imageBlockWidth;
775 }
776
777 // Wrap around the whole image block
778 $GLOBALS['TSFE']->register['totalwidth'] = $imgWrapWidth;
779 if ($imgWrapWidth) {
780 $images = $this->pObj->cObj->stdWrap($images, $conf['imageStdWrap.']);
781 } else {
782 $images = $this->pObj->cObj->stdWrap($images, $conf['imageStdWrapNoWidth.']);
783 }
784 }
785
786 $output = $this->pObj->cObj->cObjGetSingle($conf['layout'], $conf['layout.']);
787 $output = str_replace('###TEXT###', $content, $output);
788 $output = str_replace('###IMAGES###', $images, $output);
789 $output = str_replace('###CLASSES###', $class, $output);
790
791 if ($conf['stdWrap.']) {
792 $output = $this->pObj->cObj->stdWrap($output, $conf['stdWrap.']);
793 }
794
795 $this->removeMetaFromData();
796
797 return $output;
798 }
799
800
801
802
803 /**
804 * Returns an object reference to the hook object if any
805 *
806 * @param string Name of the function you want to call / hook key
807 * @return object Hook object, if any. Otherwise null.
808 */
809 function &hookRequest($functionName) {
810 global $TYPO3_CONF_VARS;
811
812 // Hook: menuConfig_preProcessModMenu
813 if ($TYPO3_CONF_VARS['EXTCONF']['dam_ttcontent']['pi1_hooks'][$functionName]) {
814 $hookObj = &t3lib_div::getUserObj($TYPO3_CONF_VARS['EXTCONF']['dam_ttcontent']['pi1_hooks'][$functionName]);
815 if (method_exists ($hookObj, $functionName)) {
816 $hookObj->pObj = &$this;
817 return $hookObj;
818 }
819 }
820 }
821 }
822
823
824
825 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dam_ttcontent/pi_cssstyledcontent/class.tx_damttcontent_pi1.php']) {
826 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dam_ttcontent/pi_cssstyledcontent/class.tx_damttcontent_pi1.php']);
827 }
828 ?>