[TASK] Replace deprecated methods, remove require_once, use namespaced core classes...
[TYPO3CMS/Extensions/contagged.git] / pi1 / class.tx_contagged_pi1.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 * (c) 2007 Jochen Rau <j.rau@web.de>
5 * All rights reserved
6 * This script is part of the TYPO3 project. The TYPO3 project is
7 * free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 * The GNU General Public License can be found at
12 * http://www.gnu.org/copyleft/gpl.html.
13 * This script is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * This copyright notice MUST APPEAR in all copies of the script!
18 ***************************************************************/
19
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * contagged list plugin
24 *
25 * @author Jochen Rau <j.rau@web.de>
26 * @package TYPO3
27 * @subpackage tx_contagged_pi1
28 */
29 class tx_contagged_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
30 var $prefixId = 'tx_contagged'; // same as class name
31 var $scriptRelPath = 'pi1/class.tx_contagged_pi1.php'; // path to this script relative to the extension dir
32 var $extKey = 'contagged'; // the extension key
33 var $templateFile = 'EXT:contagged/pi1/contagged.tmpl';
34
35 var $conf; // the TypoScript configuration array
36 var $templateCode; // template file
37 var $local_cObj;
38
39 var $typolinkConf;
40
41 var $backPid; // pid of the last visited page (from piVars)
42 var $indexChar; // char of the given index the user has clicked on (from piVars)
43
44 /**
45 * main method of the contagged list plugin
46 *
47 * @param string $content: The content of the cObj
48 * @param array $conf: The configuration
49 * @return string a single or list view of terms
50 */
51 function main($content, $conf) {
52 $this->conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->prefixId . '.'];
53 $this->parser = GeneralUtility::makeInstance('tx_contagged');
54 $this->local_cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
55 $this->local_cObj->setCurrentVal($GLOBALS['TSFE']->id);
56 if (is_array($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_contagged.'])) {
57 $this->conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_contagged.'];
58 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->conf, $conf);
59 }
60 $this->pi_loadLL();
61 $this->templateCode = $this->cObj->fileResource($this->conf['templateFile'] ? $this->conf['templateFile'] : $this->templateFile);
62 $this->typolinkConf = is_array($this->conf['typolink.']) ? $this->conf['typolink.'] : array();
63 $this->typolinkConf['parameter.']['current'] = 1;
64 if (!empty($this->typolinkConf['additionalParams'])) {
65 $this->typolinkConf['additionalParams'] = $this->cObj->stdWrap($typolinkConf['additionalParams'], $typolinkConf['additionalParams.']);
66 unset($this->typolinkConf['additionalParams.']);
67 }
68 $this->typolinkConf['useCacheHash'] = 1;
69 $this->backPid = $this->piVars['backPid'] ? intval($this->piVars['backPid']) : NULL;
70 $this->pointer = $this->piVars['pointer'] ? intval($this->piVars['pointer']) : NULL;
71 $this->indexChar = $this->piVars['index'] ? urldecode($this->piVars['index']) : NULL; // TODO The length should be configurable
72 if (!is_null($this->piVars['source']) && !is_null($this->piVars['uid'])) {
73 $dataSource = stripslashes($this->piVars['source']);
74 $uid = intval($this->piVars['uid']);
75 $termKey = stripslashes($this->piVars['source']) . '_' . intval($this->piVars['uid']);
76 }
77 $sword = $this->piVars['sword'] ? htmlspecialchars(urldecode($this->piVars['sword'])) : NULL;
78
79 // get an array of all type configurations
80 $this->typesArray = $this->conf['types.'];
81
82 // get the model (an associated array of terms)
83 $this->mapper = GeneralUtility::makeInstance('tx_contagged_model_mapper', $this);
84 $this->model = GeneralUtility::makeInstance('tx_contagged_model_terms', $this);
85
86 if (!is_null($termKey)) {
87 $content .= $this->renderSingleItemByKey($dataSource, $uid);
88 } elseif ((strtolower($this->conf['layout']) == 'minilist') || (strtolower($this->cObj->data['select_key']) == 'minilist')) {
89 $content .= $this->renderMiniList();
90 } elseif (is_null($termKey) && is_null($sword)) {
91 $content .= $this->renderList();
92 } elseif (is_null($termKey) && !is_null($sword)) {
93 $content .= $this->renderListBySword($sword);
94 }
95
96 // TODO hook "newRenderFunctionName"
97
98 $content = $this->removeUnfilledMarker($content);
99
100 return $this->pi_wrapInBaseClass($content);
101 }
102
103 /**
104 * Renders the list of terms
105 *
106 * @return $string The list as HTML
107 */
108 function renderList() {
109 $markerArray = array();
110 $wrappedSubpartArray = array();
111 $subparts = $this->getSubparts('LIST');
112 $termsArray = $this->model->findAllTermsToListOnPage();
113 $this->renderLinks($markerArray, $wrappedSubpartArray);
114 $this->renderIndex($markerArray, $termsArray);
115 $this->renderSearchBox($markerArray);
116 $indexedTerms = array();
117 foreach ($termsArray as $termKey => $termArray) {
118 if ($this->indexChar == NULL || $termArray['indexChar'] == $this->indexChar) {
119 $indexedTerms[$termKey] = $termArray;
120 }
121 }
122 if ($this->conf['pagebrowser.']['enable'] > 0) {
123 $this->renderPageBrowser($markerArray, count($indexedTerms));
124 $terms = array_slice($indexedTerms, ($this->pointer * $this->internal['results_at_a_time']), $this->internal['results_at_a_time'], TRUE);
125 } else {
126 $terms = $indexedTerms;
127 }
128 foreach ($terms as $termKey => $termArray) {
129 $this->renderSingleItem($termArray, $markerArray, $wrappedSubpartArray);
130 $subpartArray['###LIST###'] .= $this->cObj->substituteMarkerArrayCached($subparts['item'], $markerArray, $subpartArray, $wrappedSubpartArray);
131 }
132 $content = $this->cObj->substituteMarkerArrayCached($subparts['template_list'], $markerArray, $subpartArray, $wrappedSubpartArray);
133
134 return $content;
135 }
136
137 /**
138 * Renders the mini list of terms
139 *
140 * @return $string The list as HTML
141 */
142 function renderMiniList() {
143 $subparts = $this->getSubparts('MINILIST');
144 $terms = $this->model->findAllTermsToListOnPage();
145 foreach ($terms as $termKey => $termArray) {
146 $this->renderSingleItem($termArray, $markerArray, $wrappedSubpartArray);
147 $subpartArray['###LIST###'] .= $this->cObj->substituteMarkerArrayCached($subparts['item'], $markerArray, $subpartArray, $wrappedSubpartArray);
148 }
149 $content = $this->cObj->substituteMarkerArrayCached($subparts['template_list'], $markerArray, $subpartArray, $wrappedSubpartArray);
150
151 return $content;
152 }
153
154 function renderListBySword($sword) {
155 $markerArray = array();
156 $wrappedSubpartArray = array();
157 $swordMatched = FALSE;
158 $subparts = $this->getSubparts('LIST');
159 $termsArray = $this->model->findAllTermsToListOnPage();
160 $this->renderLinks($markerArray, $wrappedSubpartArray);
161 $this->renderIndex($markerArray, $termsArray);
162 $this->renderSearchBox($markerArray);
163 foreach ($termsArray as $termKey => $termArray) {
164 $fieldsToSearch = GeneralUtility::trimExplode(',', $this->conf['searchbox.']['fieldsToSearch']);
165 foreach ($fieldsToSearch as $field) {
166 if (is_array($termArray[$field])) {
167 foreach ($termArray[$field] as $subFieldValue) {
168 if (preg_match('/' . preg_quote($sword, '/') . '/Uis', strip_tags($subFieldValue)) > 0) {
169 $swordMatched = TRUE;
170 break;
171 }
172 }
173 } else {
174 if (preg_match('/' . preg_quote($sword, '/') . '/Uis', strip_tags($termArray[$field])) > 0) {
175 $swordMatched = TRUE;
176 break;
177 }
178 }
179 }
180 if ($swordMatched) {
181 $this->renderSingleItem($termArray, $markerArray, $wrappedSubpartArray);
182 $subpartArray['###LIST###'] .= $this->cObj->substituteMarkerArrayCached($subparts['item'], $markerArray, $subpartArray, $wrappedSubpartArray);
183 $swordMatched = FALSE;
184 }
185 }
186 if ($subpartArray['###LIST###'] == '') {
187 $subpartArray['###LIST###'] = $this->pi_getLL('no_matches');
188 }
189
190 $content = $this->cObj->substituteMarkerArrayCached($subparts['template_list'], $markerArray, $subpartArray, $wrappedSubpartArray);
191
192 return $content;
193 }
194
195 function renderSingleItemByKey($dataSource, $uid) {
196 $markerArray = array();
197 $wrappedSubpartArray = array();
198 $termArray = $this->model->findTermByUid($dataSource, $uid);
199 $subparts = $this->getSubparts('SINGLE');
200 $this->renderLinks($markerArray, $wrappedSubpartArray);
201 $termsArray = $this->model->findAllTermsToListOnPage();
202 $this->renderIndex($markerArray, $termsArray);
203 $this->renderSingleItem($termArray, $markerArray, $wrappedSubpartArray);
204 $subpartArray['###LIST###'] = $this->cObj->substituteMarkerArrayCached($subparts['item'], $markerArray, $subpartArray, $wrappedSubpartArray);
205 $content = $this->cObj->substituteMarkerArrayCached($subparts['template_list'], $markerArray, $subpartArray, $wrappedSubpartArray);
206
207 return $content;
208 }
209
210 // TODO hook "newRenderFunction"
211
212 function getSubparts($templateName = 'LIST') {
213 $subparts['template_list'] = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_' . $templateName . '###');
214 $subparts['item'] = $this->cObj->getSubpart($subparts['template_list'], '###ITEM###');
215
216 return $subparts;
217 }
218
219 function renderLinks(&$markerArray, &$wrappedSubpartArray) {
220 // make "back to..." link
221 if ($this->backPid && $this->conf['addBackLink'] !== '0') {
222 if ($this->conf['addBackLinkDescription'] > 0) {
223 $pageSelectObject = new \TYPO3\CMS\Frontend\Page\PageRepository;
224 $pageSelectObject->init(FALSE);
225 $pageSelectObject->sys_language_uid = $GLOBALS['TSFE']->sys_language_uid;
226 $backPage = $pageSelectObject->getPage($this->backPid);
227 $markerArray['###BACK_TO###'] = $this->pi_getLL('backToPage') . " \"" . $backPage['title'] . "\"";
228 } else {
229 $markerArray['###BACK_TO###'] = $this->pi_getLL('back');
230 }
231 unset($typolinkConf);
232 $typolinkConf['parameter'] = $this->backPid;
233 $wrappedSubpartArray['###LINK_BACK_TO###'] = $this->local_cObj->typolinkWrap($typolinkConf);
234 } else {
235 $markerArray['###LINK_BACK_TO###'] = '';
236 }
237
238 // make "link to all entries"
239 $markerArray['###INDEX_ALL###'] = $this->pi_linkTP($this->pi_getLL('all'));
240
241 // make "to list ..." link
242 unset($typolinkConf);
243 $markerArray['###TO_LIST###'] = $this->pi_getLL('toList');
244 $typolinkConf = $this->typolinkConf;
245 $typolinkConf['parameter.']['wrap'] = "|," . $GLOBALS['TSFE']->type;
246 $wrappedSubpartArray['###LINK_TO_LIST###'] = $this->local_cObj->typolinkWrap($typolinkConf);
247 }
248
249 function renderSingleItem($termArray, &$markerArray, &$wrappedSubpartArray) {
250 $typeConfigArray = $this->conf['types.'][$termArray['term_type'] . '.'];
251
252 $termArray['desc_long'] = $this->cObj->parseFunc($termArray['desc_long'], array(), '< lib.parseFunc_RTE');
253 if (!empty($this->conf['fieldsToParse'])) {
254 $fieldsToParse = GeneralUtility::trimExplode(',', $this->conf['fieldsToParse']);
255 $excludeTerms = $termArray['term_alt'];
256 $excludeTerms[] = $termArray['term_main'];
257 foreach ($fieldsToParse as $fieldName) {
258 $termArray[$fieldName] = $this->parser->parse($termArray[$fieldName], array('excludeTerms' => implode(',', $excludeTerms)));
259 }
260 }
261
262 $markerArray['###TERM_TYPE###'] = $typeConfigArray['label'];
263 $markerArray['###TERM###'] = $termArray['term'];
264 $editIconsConf = array(
265 'styleAttribute' => '',
266 );
267 $markerArray['###TERM_KEY###'] = $termArray['source'] . '_' . $termArray['uid'];
268 $markerArray['###TERM###'] = $this->cObj->editIcons($termArray['term'], 'tx_contagged_terms:term_main,term_alt,term_type,term_lang,term_replace,desc_short,desc_long,image,dam_images,imagecaption,imagealt,imagetitle,related,link,exclude', $editIconsConf, 'tx_contagged_terms:' . $termArray['uid']);
269 $markerArray['###TERM_MAIN###'] = $termArray['term_main'];
270 $markerArray['###TERM_ALT###'] = $termArray['term_alt'] ? implode(', ', $termArray['term_alt']) : $this->pi_getLL('na');
271 $markerArray['###TERM_REPLACE###'] = $termArray['term_replace'] ? $termArray['term_replace'] : $this->pi_getLL('na');
272 $markerArray['###DESC_SHORT###'] = $termArray['desc_short'] ? $termArray['desc_short'] : $this->pi_getLL('na');
273 $markerArray['###DESC_LONG###'] = $termArray['desc_long'] ? $termArray['desc_long'] : $this->pi_getLL('na');
274 $markerArray['###REFERENCE###'] = $termArray['reference'] ? $termArray['reference'] : $this->pi_getLL('na');
275 $markerArray['###PRONUNCIATION###'] = $termArray['pronunciation'] ? $termArray['pronunciation'] : $this->pi_getLL('na');
276 $markerArray['###IMAGES###'] = $this->renderImages($termArray);
277 $multimediaConfiguration = $this->conf['multimedia.'];
278 $multimediaConfiguration['file'] = $termArray['multimedia'];
279 $markerArray['###MULTIMEDIA###'] = $this->cObj->cObjGetSingle('MULTIMEDIA', $multimediaConfiguration);
280 $markerArray['###RELATED###'] = $this->renderRelated($termArray);
281 $markerArray['###TERM_LANG###'] = $this->pi_getLL('lang.' . $termArray['term_lang']) ? $this->pi_getLL('lang.' . $termArray['term_lang']) : $this->pi_getLL('na');
282
283 $labelWrap = array();
284 $labelWrap['wrap'] = $typeConfigArray['labelWrap1'] ? $typeConfigArray['labelWrap1'] : $this->conf['labelWrap1'];
285 $markerArray['###TERM_TYPE_LABEL###'] = $markerArray['###TERM_TYPE###'] ? $this->local_cObj->stdWrap($this->pi_getLL('term_type'), $labelWrap) : '';
286 $markerArray['###TERM_LABEL###'] = $this->local_cObj->stdWrap($this->pi_getLL('term'), $labelWrap);
287 $markerArray['###TERM_MAIN_LABEL###'] = $this->local_cObj->stdWrap($this->pi_getLL('term_main'), $labelWrap);
288 $markerArray['###TERM_ALT_LABEL###'] = $markerArray['###TERM_ALT###'] ? $this->local_cObj->stdWrap($this->pi_getLL('term_alt'), $labelWrap) : '';
289 $markerArray['###TERM_REPLACE_LABEL###'] = $markerArray['###TERM_REPLACE###'] ? $this->local_cObj->stdWrap($this->pi_getLL('term_replace'), $labelWrap) : '';
290 $markerArray['###DESC_SHORT_LABEL###'] = $markerArray['###DESC_SHORT###'] ? $this->local_cObj->stdWrap($this->pi_getLL('desc_short'), $labelWrap) : '';
291 $markerArray['###DESC_LONG_LABEL###'] = $markerArray['###DESC_LONG###'] ? $this->local_cObj->stdWrap($this->pi_getLL('desc_long'), $labelWrap) : '';
292 $markerArray['###REFERENCE_LABEL###'] = $markerArray['###REFERENCE###'] ? $this->local_cObj->stdWrap($this->pi_getLL('reference'), $labelWrap) : '';
293 $markerArray['###PRONUNCIATION_LABEL###'] = $markerArray['###PRONUNCIATION###'] ? $this->local_cObj->stdWrap($this->pi_getLL('pronunciation'), $labelWrap) : '';
294 $markerArray['###MULTIMEDIA_LABEL###'] = $markerArray['###MULTIMEDIA###'] ? $this->local_cObj->stdWrap($this->pi_getLL('multimedia'), $labelWrap) : '';
295 $markerArray['###RELATED_LABEL###'] = $markerArray['###RELATED###'] ? $this->local_cObj->stdWrap($this->pi_getLL('related'), $labelWrap) : '';
296 $markerArray['###IMAGES_LABEL###'] = $markerArray['###IMAGES###'] ? $this->local_cObj->stdWrap($this->pi_getLL('images'), $labelWrap) : '';
297 $markerArray['###TERM_LANG_LABEL###'] = $markerArray['###TERM_LANG###'] ? $this->local_cObj->stdWrap($this->pi_getLL('term_lang'), $labelWrap) : '';
298
299 // make "more..." link
300 $markerArray['###DETAILS###'] = $this->pi_getLL('details');
301 $typolinkConf = $this->typolinkConf;
302 if (!empty($typeConfigArray['typolink.'])) {
303 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($typolinkConf, $typeConfigArray['typolink.']);
304 }
305 $typolinkConf['additionalParams'] .= '&' . $this->prefixId . '[source]=' . $termArray['source'] . '&' . $this->prefixId . '[uid]=' . $termArray['uid'];
306 $typolinkConf['parameter'] = array_shift($this->model->getListPidsArray($termArray['term_type']));
307 $this->typolinkConf['parameter.']['current'] = 0;
308 $typolinkConf['parameter.']['wrap'] = "|," . $GLOBALS['TSFE']->type;
309 $wrappedSubpartArray['###LINK_DETAILS###'] = $this->local_cObj->typolinkWrap($typolinkConf);
310 }
311
312 function renderRelated($term) {
313 $relatedCode = '';
314 if (is_array($term['related'])) {
315 foreach ($term['related'] as $termReference) {
316 $relatedTerm = $this->model->findTermByUid($termReference['source'], $termReference['uid']);
317 $typolinkConf = $this->typolinkConf;
318 if (!empty($typeConfigArray['typolink.'])) {
319 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($typolinkConf, $typeConfigArray['typolink.']);
320 }
321 $typolinkConf['useCacheHash'] = 1;
322 $typolinkConf['additionalParams'] .= '&' . $this->prefixId . '[source]=' . $termReference['source'] . '&' . $this->prefixId . '[uid]=' . $termReference['uid'];
323 $typolinkConf['parameter.']['wrap'] = "|," . $GLOBALS['TSFE']->type;
324 $relatedCode .= $this->local_cObj->stdWrap($this->local_cObj->typoLink($relatedTerm['term'], $typolinkConf), $this->conf['related.']['single.']['stdWrap.']);
325 }
326 return $this->local_cObj->stdWrap(trim($relatedCode), $this->conf['related.']['stdWrap.']);
327 } else {
328 return NULL;
329 }
330 }
331
332 function renderImages($termArray) {
333 $images = array();
334 $imagesCaption = array();
335 $imagesAltText = array();
336 $imagesTitleText = array();
337 $imagesCode = '';
338 $imagesConf = $this->conf['images.']['single.'];
339 $extConfArray = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['contagged']);
340 if ($extConfArray['getImagesFromDAM'] > 0 && t3lib_extMgm::isLoaded('dam')) {
341 $res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
342 'tx_dam.file_path, tx_dam.file_name, tx_dam.alt_text, tx_dam.caption, tx_dam.title',
343 'tx_dam', 'tx_dam_mm_ref', 'tx_contagged_terms',
344 'AND tx_dam_mm_ref.tablenames = "tx_contagged_terms" AND tx_dam_mm_ref.ident="dam_images" ' .
345 'AND tx_dam_mm_ref.uid_foreign = "' . $termArray['uid'] . '"', '', 'tx_dam_mm_ref.sorting_foreign ASC'
346 );
347 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
348 $images[] = $row['file_path'] . $row['file_name'];
349 $imagesCaption[] = str_replace(array(chr(10), chr(13)), ' ', $row['caption'] . ' ');
350 $imagesAltText[] = str_replace(array(chr(10), chr(13)), ' ', $row['alt_text'] . ' ');
351 $imagesTitleText[] = str_replace(array(chr(10), chr(13)), ' ', $row['title'] . ' ');
352 }
353 } else {
354 $images = GeneralUtility::trimExplode(',', $termArray['image'], 1);
355 $imagesWithPath = array();
356 foreach ($images as $image) {
357 $imagesWithPath[] = 'uploads/pics/' . $image;
358 }
359 $images = $imagesWithPath;
360 $imagesCaption = GeneralUtility::trimExplode(chr(10), $termArray['imagecaption']);
361 $imagesAltText = GeneralUtility::trimExplode(chr(10), $termArray['imagealt']);
362 $imagesTitleText = GeneralUtility::trimExplode(chr(10), $termArray['imagetitle']);
363 }
364
365 if (!empty($images)) {
366 foreach ($images as $key => $image) {
367 $imagesConf['image.']['file'] = $image;
368 $imagesConf['image.']['altText'] = $imagesAltText[$key];
369 $imagesConf['image.']['titleText'] = $imagesTitleText[$key];
370 $caption = $imagesCaption[$key] != '' ? $this->local_cObj->stdWrap($imagesCaption[$key], $this->conf['images.']['caption.']['stdWrap.']) : '';
371 $imagesCode .= $this->local_cObj->IMAGE($imagesConf['image.']);
372 $imagesCode .= $caption;
373 }
374 return $this->local_cObj->stdWrap(trim($imagesCode), $this->conf['images.']['stdWrap.']);
375 } else {
376 return NULL;
377 }
378 }
379
380 function renderIndex(&$markerArray, &$terms) {
381 if ($this->conf['index.']['enable'] > 0) {
382 $subparts = array();
383 $subparts['template_index'] = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_INDEX###');
384 $subparts['item'] = $this->cObj->getSubpart($subparts['template_index'], '###ITEM###');
385
386 $indexArray = $this->getIndexArray($terms);
387
388 // wrap index chars and add a class attribute if there is a selected index char.
389 foreach ($indexArray as $indexChar => $link) {
390 $cssClass = '';
391 if ($this->piVars['index'] == $indexChar) {
392 $cssClass = " class='tx-contagged-act'";
393 }
394 if ($link) {
395 $markerArray['###SINGLE_CHAR###'] = '<span' . $cssClass . '>' . $link . '</span>';
396 } elseif ($this->conf['index.']['showOnlyMatchedIndexChars'] == 0) {
397 $markerArray['###SINGLE_CHAR###'] = '<span' . $cssClass . '>' . $indexChar . '</span>';
398 } else {
399 $markerArray['###SINGLE_CHAR###'] = '';
400 }
401 $subpartArray['###INDEX_CONTENT###'] .= $this->cObj->substituteMarkerArrayCached($subparts['item'], $markerArray);
402 }
403 $markerArray['###INDEX###'] = $this->cObj->substituteMarkerArrayCached($subparts['template_index'], $markerArray, $subpartArray);
404 } else {
405 $markerArray['###INDEX###'] = '';
406 }
407 }
408
409 function getIndexArray(&$terms) {
410 $indexArray = array();
411 $reverseIndexArray = array();
412 // Get localized index chars.
413 foreach (GeneralUtility::trimExplode(',', $this->pi_getLL('indexChars')) as $key => $value) {
414 $subCharArray = GeneralUtility::trimExplode('|', $value);
415 $indexArray[$subCharArray[0]] = NULL;
416 foreach ($subCharArray as $subChar) {
417 $reverseIndexArray[$subChar] = $subCharArray[0];
418 }
419 }
420
421 // The configuered subchars like Ö will be linked as O (see documentation and file "locallang.xml").
422 $typolinkConf = $this->typolinkConf;
423 foreach ($terms as $termKey => $termArray) {
424 if ($this->conf['types.'][$termArray['term_type'] . '.']['dontListTerms'] != 1) {
425 foreach ($reverseIndexArray as $subChar => $indexChar) {
426 if (preg_match('/^' . preg_quote($subChar) . '/' . $this->conf['modifier'], $termArray['term']) > 0) {
427 $typolinkConf['additionalParams'] = '&' . $this->prefixId . '[index]=' . $indexChar;
428 $indexArray[$indexChar] = $this->local_cObj->typolink($indexChar, $typolinkConf);
429 $terms[$termKey]['indexChar'] = $indexChar;
430 }
431 }
432 // If the term matches no given index char, crate one if desired and add it to the index
433 if (($terms[$termKey]['indexChar'] == '') && ($this->conf['index.']['autoAddIndexChars'] == 1)) {
434 // get the first char of the term (UTF8)
435 // TODO: Make the RegEx configurable to make ZIP-Codes possible
436 preg_match('/^./' . $this->conf['modifier'], $termArray['term'], $match);
437 $newIndexChar = $match[0];
438 $indexArray[$newIndexChar] = NULL;
439 $typolinkConf['additionalParams'] .= '&' . $this->prefixId . '[index]=' . urlencode($newIndexChar);
440 $indexArray[$newIndexChar] = $this->local_cObj->typolink($newIndexChar, $typolinkConf);
441 $terms[$termKey]['indexChar'] = $newIndexChar;
442 }
443 }
444 }
445
446 // TODO Sorting of the index (UTF8)
447 ksort($indexArray, SORT_LOCALE_STRING);
448
449 return $indexArray;
450 }
451
452 function renderPageBrowser(&$markerArray, $resultCount) {
453 $this->internal['res_count'] = $resultCount;
454 $this->internal['results_at_a_time'] = $this->conf['pagebrowser.']['results_at_a_time'] ? intval($this->conf['pagebrowser.']['results_at_a_time']) : 20;
455 $this->internal['maxPages'] = $this->conf['pagebrowser.']['maxPages'] ? intval($this->conf['pagebrowser.']['maxPages']) : 3;
456 $this->internal['dontLinkActivePage'] = $this->conf['pagebrowser.']['dontLinkActivePage'] === '0' ? FALSE : TRUE;
457 $this->internal['showFirstLast'] = $this->conf['pagebrowser.']['showFirstLast'] === '0' ? FALSE : TRUE;
458 $this->internal['pagefloat'] = strlen($this->conf['pagebrowser.']['pagefloat']) > 0 ? $this->conf['pagebrowser.']['pagefloat'] : 'center';
459 $this->internal['showRange'] = $this->conf['pagebrowser.']['showRange'];
460 $this->pi_alwaysPrev = intval($this->conf['pagebrowser.']['alwaysPrev']);
461
462 if (($this->internal['res_count'] > $this->internal['results_at_a_time']) && ($this->conf['pagebrowser.']['enable'] > 0)) {
463 $wrapArray = is_array($this->conf['pagebrowser.']['wraps.']) ? $this->conf['pagebrowser.']['wraps.'] : array();
464 $pointerName = strlen($this->conf['pagebrowser.']['pointerName']) > 0 ? $this->conf['pagebrowser.']['pointerName'] : 'pointer';
465 $enableHtmlspecialchars = $this->conf['pagebrowser.']['enableHtmlspecialchars'] === '0' ? FALSE : TRUE;
466 $markerArray['###PAGEBROWSER###'] = $this->pi_list_browseresults($this->conf['pagebrowser.']['showResultCount'], $this->conf['pagebrowser.']['tableParams'], $wrapArray, $pointerName, $enableHtmlspecialchars);
467 } else {
468 $markerArray['###PAGEBROWSER###'] = '';
469 }
470 }
471
472 function renderSearchBox(&$markerArray) {
473 if ($this->conf['searchbox.']['enable'] > 0) {
474 $markerArray['###SEARCHBOX###'] = $this->pi_list_searchBox();
475 } else {
476 $markerArray['###SEARCHBOX###'] = '';
477 }
478 }
479
480 protected function removeUnfilledMarker($content) {
481 return preg_replace('/###.*?###/', '', $content);
482 }
483 }
484
485 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/contagged/pi1/class.tx_contagged_pi1.php']) {
486 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/contagged/pi1/class.tx_contagged_pi1.php']);
487 }
488 ?>