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