forked from MaxServ/t3ext-fal_ttnews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageMarkerFunc.php
179 lines (159 loc) · 6.21 KB
/
imageMarkerFunc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/***************************************************************
* Copyright notice
*
* (c) 2015 Chritian Jürges <[email protected]>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* FAL Support
*
* @param array $paramArray : $markerArray and $config of the current news
* item in an array
* @param [type] $conf: ...
*
* @return array the processed markerArray
*/
function user_imageMarkerFunc($paramArray, $conf) {
$markerArray = $paramArray[0];
// return $markerArray;
$lConf = $paramArray[1];
$pObj = &$conf['parentObj']; // make a reference to the parent-object
$row = $pObj->local_cObj->data;
$mode = (int)$GLOBALS['TSFE']->tmpl->setup['plugin.']['fal_ttnews.']['mode'];
$imageNum = isset($lConf['imageCount']) ? $lConf['imageCount'] : 1;
// $imageNum = \TYPO3\CMS\Core\Utility\GeneralUtility::intInRange($imageNum, 0, 100);
$imageNum = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($imageNum, 0, 100);
$theImgCode = '';
$imgsCaptions = explode(chr(10), $row['imagecaption']);
$imgsAltTexts = explode(chr(10), $row['imagealttext']);
$imgsTitleTexts = explode(chr(10), $row['imagetitletext']);
// to get correct DAM files, set uid
// workspaces
if (isset($row['_ORIG_uid']) && ($row['_ORIG_uid'] > 0)) {
// draft workspace
$uid = $row['_ORIG_uid'];
} else {
// live workspace
$uid = $row['uid'];
}
// translations - i10n mode
if ($row['_LOCALIZED_UID']) {
//i10n mode = exclude -> do nothing
//i10n mode = mergeIfNotBlank
$confArr_ttnews = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['tt_news']);
if (!$confArr_ttnews['l10n_mode_imageExclude']) {
if ($row['tx_damnews_dam_images']) {
$uid = $row['_LOCALIZED_UID'];
}
}
}
$cc = 0;
$shift = FALSE;
// get FAL data
// $infoFields = tx_dam_db::getMetaInfoFieldList(true,array('alt_text'=>'alt_text','caption'=>'caption'));
// $damData = tx_dam_db::getReferencedFiles('tt_news', $uid, 'tx_damnews_dam_images','tx_dam_mm_ref',$infoFields);
$fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
$fileObjects = $fileRepository->findByRelation('tt_news', 'tx_falttnews_fal_images', $uid);
// $damFiles = $damData['files'];
// $damRows = $damData['rows'];
// localisation of DAM data
// while (list($key, $val) = each($damRows)) {
// $damRows[$key] = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dam', $val, $GLOBALS['TSFE']->sys_language_uid, '');
// }
// remove first img from the image array in single view if the TSvar firstImageIsPreview is set
if (((count($fileObjects) > 1 && $pObj->config['firstImageIsPreview']) || (count($fileObjects) >= 1 && $pObj->config['forceFirstImageIsPreview'])) && $pObj->theCode == 'SINGLE') {
array_shift($fileObjects);
// array_shift($damRows);
array_shift($imgsCaptions);
array_shift($imgsAltTexts);
array_shift($imgsTitleTexts);
$shift = TRUE;
}
// get img array parts for single view pages
if ($pObj->piVars[$pObj->pObj['singleViewPointerName']]) {
$spage = $pObj->piVars[$pObj->config['singleViewPointerName']];
$astart = $imageNum * $spage;
$fileObjects = array_slice($fileObjects, $astart, $imageNum);
// $damRows = array_slice($damRows, $astart, $imageNum);
$imgsCaptions = array_slice($imgsCaptions, $astart, $imageNum);
$imgsAltTexts = array_slice($imgsAltTexts, $astart, $imageNum);
$imgsTitleTexts = array_slice($imgsTitleTexts, $astart, $imageNum);
}
while (list($key, $val) = each($fileObjects)) {
if ($cc == $imageNum) {
break;
}
if ($val) {
$reference = $val->getReferenceProperties();
//set Caption, Alt-text and Title Tag
switch ($mode) {
//take data form tt_news record
case 0:
$lConf['image.']['altText'] = $imgsAltTexts[$cc];
$lConf['image.']['titleText'] = $imgsTitleTexts[$cc];
$caption = $imgsCaptions[$cc];
break;
//if fields are empty in news record, take data from FAL fields
case 1:
if ($imgsAltTexts[$cc]) {
$lConf['image.']['altText'] = $imgsAltTexts[$cc];
} else {
$lConf['image.']['altText'] = $reference['alternative'];
}
if ($imgsTitleTexts[$cc]) {
$lConf['image.']['titleText'] = $imgsTitleTexts[$cc];
} else {
$lConf['image.']['titleText'] = $reference['title'];
}
if ($imgsCaptions[$cc]) {
$caption = $imgsCaptions[$cc];
} else {
$caption = $reference['description'];
}
break;
//take data from FAL fields
case 2:
$lConf['image.']['altText'] = $reference['alternative'];
$lConf['image.']['titleText'] = $reference['title'];
$caption = $reference['description'];
break;
}
$lConf['image.']['file'] = $val;
}
$pObj->local_cObj->setCurrentVal($val);
// enables correct use of extension perfectlightbox
if ($shift) {
$GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $cc + 1;
} else {
$GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $cc;
}
$theImgCode .= $pObj->local_cObj->wrap($pObj->local_cObj->IMAGE($lConf['image.']) . $pObj->local_cObj->stdWrap($caption, $lConf['caption_stdWrap.']), $lConf['imageWrapIfAny_' . $cc]);
$cc++;
}
// fill marker
$markerArray['###NEWS_IMAGE###'] = '';
if ($cc) {
$markerArray['###NEWS_IMAGE###'] = $pObj->local_cObj->wrap(trim($theImgCode), $lConf['imageWrapIfAny']);
} // noImage_stdWrap
else {
$markerArray['###NEWS_IMAGE###'] = $pObj->local_cObj->stdWrap($markerArray['###NEWS_IMAGE###'], $lConf['image.']['noImage_stdWrap.']);
}
return $markerArray;
}