forked from pluspol-interactive/contagged
-
Notifications
You must be signed in to change notification settings - Fork 1
/
class.tx_contagged.php
694 lines (632 loc) · 29.4 KB
/
class.tx_contagged.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
<?php
/***************************************************************
* Copyright notice
* (c) 2007 Jochen Rau <j.rau@web.de>
* 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!
***************************************************************/
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* The main class to parse,tag and replace specific terms of the content.
*
* @author Jochen Rau <j.rau@web.de>
* @package TYPO3
* @subpackage tx_contagged
*/
class tx_contagged extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
{
public $prefixId = 'tx_contagged';
public $scriptRelPath = 'class.tx_contagged.php'; // path to this script relative to the extension dir
public $extKey = 'contagged'; // the extension key
public $conf; // the TypoScript configuration array
protected $typolinkConf;
/**
* The main method. It instantly delegates the process to the parse function.
*
* @param string $content: The content
* @param array $conf: The configuration array
* @return string The parsed and tagged content that is displayed on the website
*/
public function main($content, $conf = null)
{
return $this->parse($content, $conf);
}
/**
* This method is to parse, tag and link specific terms in the given content.
*
* @param string $content: The content
* @param array $conf: The configuration array
* @return string The parsed and tagged content that is displayed on the website
*/
public function parse($content, $conf)
{
if (!is_array($conf)) {
$conf = [];
}
$this->conf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->prefixId . '.'];
ArrayUtility::mergeRecursiveWithOverrule($this->conf, $conf);
$this->pi_setPiVarDefaults();
if (!is_object($this->cObj)) {
$this->cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
$this->cObj->setCurrentVal($GLOBALS['TSFE']->id);
}
$this->typolinkConf = is_array($this->conf['typolink.']) ? $this->conf['typolink.'] : [];
if (!empty($this->typolinkConf['additionalParams'])) {
$this->typolinkConf['additionalParams'] = $this->cObj->stdWrap($typolinkConf['additionalParams'], $typolinkConf['additionalParams.']);
unset($this->typolinkConf['additionalParams.']);
}
$this->typolinkConf['useCacheHash'] = 1;
// exit if the content should be skipped
if ($this->isContentToSkip()) {
return $content;
}
// get an array of all type configurations
$this->typesArray = $this->conf['types.'];
// get the model (an associated array of terms)
$model = GeneralUtility::makeInstance('tx_contagged_model_terms', $this);
$this->termsArray = $model->findAllTerms();
$excludeTerms = explode(',', $this->conf['excludeTerms']);
$sortedTerms = [];
foreach ($this->termsArray as $termKey => $termArray) {
if ($this->conf['autoExcludeTerms'] == 1 && in_array($termArray['term_main'], $excludeTerms)) {
continue;
}
$sortedTerms[] = array('term' => $termArray['term_main'], 'key' => $termKey);
if (is_array($termArray['term_alt'])) {
foreach ($termArray['term_alt'] as $term) {
if ($this->conf['autoExcludeTerms'] == 1 && in_array($term, $excludeTerms)) {
continue;
}
$sortedTerms[] = array('term' => $term, 'key' => $termKey);
}
}
}
// sort the array descending by length of the value, so the longest term will match
usort($sortedTerms, array($this, 'sortTermsByDescendingLength'));
// get a comma separated list of all tags which should be omitted
$tagsToOmitt = $this->getTagsToOmitt();
// TODO split recursively
$parseObj = GeneralUtility::makeInstance('TYPO3\CMS\Core\Html\HtmlParser');
$splittedContent = $parseObj->splitIntoBlock($tagsToOmitt, $content);
foreach ((array)$splittedContent as $intKey => $HTMLvalue) {
if (!($intKey % 2)) {
$positionsArray = [];
foreach ($sortedTerms as $termAndKey) {
if (empty($termAndKey['term'])) {
continue;
}
$this->getPositions($splittedContent[$intKey], $positionsArray, $termAndKey['term'], $termAndKey['key']);
}
ksort($positionsArray);
$splittedContent[$intKey] = $this->doReplace($splittedContent[$intKey], $positionsArray);
}
}
$parsedContent = implode('', $splittedContent);
// update the keywords (field "tx_contagged_keywords" in table "page")
if ($this->conf['updateKeywords'] > 0) {
$this->updatePageKeywords();
}
$this->addJavaScript();
return $parsedContent;
}
/**
* Utility method to sort array items according to the (string) length of their "term" item
*
* Note: the sorting is descending
*
* @param array $a
* @param array $b
* @return integer +1 if term from a is shorter than b, -1 for the contrary, 0 in case of equality
*/
public function sortTermsByDescendingLength($a, $b)
{
// Calculate length correctly by relying on \TYPO3\CMS\Core\Charset\CharsetConverter
$aTermLength = mb_strlen($a['term'], 'UTF-8');
$bTermLength = mb_strlen($b['term'], 'UTF-8');
if ($aTermLength == $bTermLength) {
return 0;
} else {
return ($aTermLength < $bTermLength) ? +1 : -1;
}
}
protected function getPositions($content, &$positionsArray, $term, $termKey)
{
$termArray = $this->termsArray[$termKey];
$typeConfigArray = $this->typesArray[$termArray['term_type'] . '.'];
if ($typeConfigArray['termIsRegEx'] > 0) {
$regEx = $termArray['term_main'] . $this->conf['modifier'];
} else {
$term = $this->cObj->stdWrap($term, $typeConfigArray['termStdWrap.']);
if (strstr($this->conf['modifier'], 'u') !== false) {
$regEx = '/(?<=\P{L}|^)' . preg_quote($term, '/') . '(?=\P{L}|$)/' . $this->conf['modifier'];
} else {
$regEx = '/(?<=\W|^)' . preg_quote($term, '/') . '(?=\W|$)/' . $this->conf['modifier'];
}
}
preg_match_all($regEx, $content, $matchesArray, PREG_OFFSET_CAPTURE);
$matchesArray = $matchesArray[0]; // only take the full pattern matches of the regEx
// determine the maximum of recurrences of the same term to be tagged
$maxRecurrences = (!empty($this->conf['maxRecurrences'])) ? min($this->conf['maxRecurrences'], count($matchesArray)) : count($matchesArray);
$step = $maxRecurrences != 0 ? ceil(count($matchesArray) / $maxRecurrences) : 1;
for ($i = 0; $i < count($matchesArray); $i = $i + $step) {
if (!empty($this->conf['maxRecurrencesPerPage'])
&& $GLOBALS['contagged']['occurences'][$termKey] > (int)$this->conf['maxRecurrencesPerPage']
) {
break;
}
$preContent = substr($content, 0, $matchesArray[$i][1]);
$postContent = substr($content, strlen($matchesArray[$i][0]) + $matchesArray[$i][1]);
// Flag: $inTag=true if we are inside a tag < here we are >
$inTag = false;
if (preg_match('/<[^<>]*$/' . $this->conf['modifier'], $preContent) > 0 && preg_match('/^[^<>]*>/' . $this->conf['modifier'], $postContent) > 0) {
$inTag = true;
}
if (!$inTag) {
// support for joined words (with a dashes)
$preMatch = '';
$postMatch = '';
if ($this->checkLocalGlobal($typeConfigArray, 'checkPreAndPostMatches') > 0) {
if (strstr($this->conf['modifier'], 'u') !== false) {
preg_match('/(?<=\P{L})\p{L}*-$/' . $this->conf['modifier'], $preContent, $preMatch);
preg_match('/^-\p{L}*(?=\P{L})/' . $this->conf['modifier'], $postContent, $postMatch);
} else {
preg_match('/(?<=\W)\w*-$/' . $this->conf['modifier'], $preContent, $preMatch);
preg_match('/^-\w*(?=\W)/' . $this->conf['modifier'], $postContent, $postMatch);
}
}
$matchedTerm = $preMatch[0] . $matchesArray[$i][0] . $postMatch[0];
$matchStart = $matchesArray[$i][1] - strlen($preMatch[0]);
$matchEnd = $matchStart + strlen($matchedTerm);
// check for nested matches
$isNested = false;
$checkArray = $positionsArray;
foreach ($checkArray as $start => $value) {
$length = strlen($value['matchedTerm']);
$end = $start + $length;
if ((($matchStart >= $start) && ($matchStart < $end)) || (($matchEnd > $start) && ($matchEnd <= $end))) {
$isNested = true;
}
}
if (!$isNested) {
$positionsArray[$matchStart] = array(
'termKey' => $termKey,
'matchedTerm' => $matchedTerm,
'preMatch' => $preMatch[0],
'postMatch' => $postMatch[0]
);
$GLOBALS['contagged']['occurences'][$termKey]++;
}
}
}
}
protected function doReplace($content, $positionsArray)
{
$posStart = 0;
$newContent = '';
if ($positionsArray) {
foreach ($positionsArray as $matchStart => $matchArray) {
$matchLength = strlen($matchArray['matchedTerm']);
$termKey = $matchArray['termKey'];
$replacement = $this->getReplacement($termKey, $matchArray['matchedTerm'], $matchArray['preMatch'], $matchArray['postMatch']);
$replacementLength = strlen($replacement);
$newContent = $newContent . substr($content, $posStart, $matchStart - $posStart) . $replacement;
$posStart = $matchStart + $matchLength;
}
$newContent = $newContent . substr($content, $posStart);
} else {
$newContent = $content;
}
return $newContent;
}
/**
* Do something with the matched term (replace, stdWrap, link, tag)
*
* @param int $termKey: the internal "uid" of the term (not related to the database uid)
* @param string $matchedTerm: The matched term including pre and post matches
* @return string The replaced, linked and tagged term
* @author Jochen Rau
*/
protected function getReplacement($termKey, $matchedTerm, $preMatch, $postMatch)
{
$termArray = $this->termsArray[$termKey];
$typeConfigArray = $this->typesArray[$termArray['term_type'] . '.'];
// register the term array
$this->registerFields($typeConfigArray, $termKey);
// build the tag enclosing the term
if (!empty($typeConfigArray['tag'])) {
// get the attributes
$langAttribute = $this->getLangAttribute($typeConfigArray, $termArray);
$titleAttribute = $this->getTitleAttribute($typeConfigArray, $termArray);
$cssClassAttribute = $this->getCssClassAttribute($typeConfigArray, $termArray);
// concatenate the tag
$before = '<' . $typeConfigArray['tag'] . $titleAttribute . $cssClassAttribute . $langAttribute . '>';
$after = '</' . $typeConfigArray['tag'] . '>';
}
// replace matched term
if ($this->checkLocalGlobal($typeConfigArray, 'replaceTerm') && $termArray['term_replace']) {
// if the first letter of the matched term is upper case
// make the first letter of the replacing term also upper case
// (\p{Lu} stands for "unicode letter uppercase")
$GLOBALS['TSFE']->register['contagged_matchedTerm'] = $termArray['term_replace'];
$this->updateIndex($termKey, $termArray['term_replace']);
if (preg_match('/^\p{Lu}/u', $matchedTerm) > 0 && ($this->checkLocalGlobal($typeConfigArray, 'respectCase') > 0)) {
$matchedTerm = $preMatch . ucfirst($termArray['term_replace']) . $postMatch;
// TODO ucfirst is not UTF8 safe; it depends on the locale settings (they could be ASCII)
} else {
$matchedTerm = $preMatch . $termArray['term_replace'] . $postMatch;
}
} else {
$GLOBALS['TSFE']->register['contagged_matchedTerm'] = $matchedTerm;
$this->updateIndex($termKey, $termArray['term']);
}
// call stdWrap to handle the matched term via TS BEFORE it is wraped with a-tags
if ($typeConfigArray['preStdWrap.']) {
$matchedTerm = $this->cObj->stdWrap($matchedTerm, $typeConfigArray['preStdWrap.']);
}
$matchedTerm = $this->linkMatchedTerm($matchedTerm, $typeConfigArray, $termKey);
// call stdWrap to handle the matched term via TS AFTER it was wrapped with a-tags
if ($typeConfigArray['postStdWrap.'] or $typeConfigArray['stdWrap.']) {
$matchedTerm = $this->cObj->stdWrap($matchedTerm, $typeConfigArray['postStdWrap.']);
$matchedTerm = $this->cObj->stdWrap($matchedTerm, $typeConfigArray['stdWrap.']); // for compatibility with < v0.0.5
}
if (!empty($typeConfigArray['tag'])) {
$matchedTerm = $before . $matchedTerm . $after;
}
// TODO Edit Icons
// $editIconsConf = array(
// 'styleAttribute' => '',
// );
// $matchedTerm = $this->cObj->editIcons($matchedTerm, 'tx_contagged_terms:sys_language_uid,hidden,starttime,endtime,fe_group,term_main,term_alt,term_type,term_lang,term_replace,desc_short,desc_long,image,imagecaption,imagealt,imagetitle,related,link,exclude', $editIconsConf, 'tx_contagged_terms:' . $termArray['uid'], NULL, '&defVals[tx_contagged_terms][desc_short]=TEST');
return $matchedTerm;
}
protected function updateIndex($termKey, $matchedTerm)
{
$currentRecord = GeneralUtility::trimExplode(':', $this->cObj->currentRecord);
$GLOBALS['T3_VAR']['ext']['contagged']['index'][$GLOBALS['TSFE']->id][$termKey] = array(
'matchedTerm' => $matchedTerm,
'source' => $this->termsArray[$termKey]['source'],
'uid' => $this->termsArray[$termKey]['uid'],
'currentRecordSource' => $currentRecord[0],
'currentRecordUid' => $currentRecord[1],
'currentPid' => $GLOBALS['TSFE']->id
);
}
/**
* Some content tagged by configured tags could be prevented from beeing parsed.
* This function collects all the tags which should be considered.
*
* @return string Comma separated list of tags
*/
protected function getTagsToOmitt()
{
$tagArray = [];
// if there are tags to exclude: add them to the list
if ($this->conf['excludeTags']) {
$tagArray = GeneralUtility::trimExplode(',', $this->conf['excludeTags'], 1);
}
// if configured: add tags used by the term definitions
if ($this->conf['autoExcludeTags'] > 0) {
;
foreach ($this->conf['types.'] as $key => $type) {
if (!empty($type['tag']) && !in_array($type['tag'], $tagArray)) {
$tagArray[] = $type['tag'];
}
}
}
$tagList = implode(',', $tagArray);
return $tagList;
}
protected function updatePageKeywords()
{
$terms = [];
if (is_array($GLOBALS['T3_VAR']['ext']['contagged']['index'][$GLOBALS['TSFE']->id])) {
foreach ($GLOBALS['T3_VAR']['ext']['contagged']['index'][$GLOBALS['TSFE']->id] as $termKey => $indexArray) {
$terms[] = $indexArray['matchedTerm'];
}
}
$termsList = implode(',', $terms);
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
$connection->update(
'pages', // table
[$this->prefixId . '_keywords' => $termsList], // value array
[ 'uid' => $GLOBALS['TSFE']->id ] // where
);
}
/**
* Register the fields in $GLOBALS['TSFE] to be used in the TS Setup
*
* @param array $typeConfigArray: Configuration array of the term
* @param array $this->termsArray: Array of terms
* @param int $termKey: Internal key of the term
*/
protected function registerFields($typeConfigArray, $termKey)
{
if ($typeConfigArray['stripBlockTags'] > 0) {
$this->termsArray[$termKey]['desc_short_inline'] = $this->stripBlockTags($this->termsArray[$termKey]['desc_short']);
$text = $this->cObj->parseFunc($this->termsArray[$termKey]['desc_long'], [], '< lib.parseFunc_RTE');
$this->termsArray[$termKey]['desc_long_inline'] = $this->stripBlockTags($text);
}
$GLOBALS['TSFE']->register['contagged_key'] = $termKey;
// register all fields to be handled by the TS Setup
foreach ($this->termsArray[$termKey] as $label => $value) {
$GLOBALS['TSFE']->register['contagged_' . $label] = $value;
}
}
/**
* Wrap the matched term in a link tag - as configured
*
* @param string $matchedTerm
* @param string $typeConfigArray
* @param string $this->termsArray
* @param string $termKey
* @return void
* @author Jochen Rau
*/
protected function linkMatchedTerm($matchedTerm, $typeConfigArray, $termKey)
{
$termArray = $this->termsArray[$termKey];
// check conditions if the term should be linked to a list page
$makeLink = $this->checkLocalGlobal($typeConfigArray, 'linkToListPage');
if ($termArray['exclude'] > 0) {
$makeLink = false;
}
if ($termArray['link']) {
$makeLink = true;
}
// link the matched term to the front-end list page
if ($makeLink) {
unset($typolinkConf);
$typolinkConf = $this->typolinkConf;
if (!empty($typeConfigArray['typolink.'])) {
ArrayUtility::mergeRecursiveWithOverrule($typolinkConf, $typeConfigArray['typolink.']);
}
if ($termArray['link']) {
$typolinkConf['parameter'] = $termArray['link'];
$typolinkConf['additionalParams'] = $termArray['link.']['additionalParams'];
} else {
if ($typeConfigArray['listPages']) {
$typolinkConf['parameter'] = array_shift(GeneralUtility::trimExplode(',', $typeConfigArray['listPages'], 1));
} else {
$typolinkConf['parameter'] = array_shift(GeneralUtility::trimExplode(',', $this->conf['listPages'], 1));
}
$GLOBALS['TSFE']->register['contagged_list_page'] = $typolinkConf['parameter'];
$additionalParams['source'] = $termArray['source'];
$additionalParams['uid'] = $termArray['uid'];
if ($this->checkLocalGlobal($typeConfigArray, 'addBackLink')) {
$additionalParams['backPid'] = $GLOBALS['TSFE']->id;
}
$typolinkConf['additionalParams'] = GeneralUtility::implodeArrayForUrl('tx_contagged', $additionalParams, '', 1);
}
$GLOBALS['TSFE']->register['contagged_link_url'] = $this->cObj->typoLink_URL($typolinkConf);
$matchedTerm = $this->cObj->typolink($matchedTerm, $typolinkConf);
}
return $matchedTerm;
}
/**
* Overwrite global settings with settings of the type configuration.
*
* @param string $typeConfigArray
* @param string $attributeName
* @return void
* @author Jochen Rau
*/
protected function checkLocalGlobal($typeConfigArray, $attributeName)
{
if (isset($typeConfigArray[$attributeName])) {
$addAttribute = ($typeConfigArray[$attributeName] > 0) ? true : false;
} else {
$addAttribute = ($this->conf[$attributeName] > 0) ? true : false;
}
return $addAttribute;
}
/**
* If the language of the term is undefined, or the page language is the same as language of the term,
* then the lang attribute will not be shown.
* If the terms language is defined and different from the page language, then the language attribute is added.
*
* @param string $typeConfigArray
* @param string $termArray
* @return void
* @author Jochen Rau
*/
protected function getLangAttribute($typeConfigArray, $termArray)
{
// get page language
if ($GLOBALS['TSFE']->config['config']['language']) {
$pageLanguage = $GLOBALS['TSFE']->config['config']['language'];
} else {
$pageLanguage = substr($GLOBALS['TSFE']->config['config']['htmlTag_langKey'], 0, 2);
}
// build language attribute if the page language is different from the terms language
if ($this->checkLocalGlobal($typeConfigArray, 'addLangAttribute') && !empty($termArray['term_lang']) && ($pageLanguage != $termArray['term_lang'])) {
$langAttribute = ' lang="' . $termArray['term_lang'] . '"';
$langAttribute .= ' xml:lang="' . $termArray['term_lang'] . '"';
}
return $langAttribute;
}
/**
* Renders the title attribute of the tag.
*
* @param string $typeConfigArray
* @param string $termArray
* @return void
* @author Jochen Rau
*/
protected function getTitleAttribute($typeConfigArray, $termArray)
{
if ($this->checkLocalGlobal($typeConfigArray, 'addTitleAttribute') && !empty($termArray['desc_short'])) {
$titleAttribute = ' title="' . $termArray['desc_short'] . '"';
}
return $titleAttribute;
}
/**
* Renders the class attribute of the tag.
*
* @param [type] $typeConfigArray: ...
* @param [type] $termArray: ...
* @return [type] ...
*/
protected function getCssClassAttribute($typeConfigArray, $termArray)
{
if ($this->checkLocalGlobal($typeConfigArray, 'addCssClassAttribute')) {
if ($typeConfigArray['cssClass']) {
$cssClassAttribute = $this->pi_classParam($typeConfigArray['cssClass']);
} else {
$cssClassAttribute = $this->pi_classParam($termArray['term_type']);
}
}
return $cssClassAttribute;
}
/**
* Test, if the current page should be skipped
*
* @return boolean True if the page should be skipped
*/
protected function isContentToSkip()
{
$result = true; // true, if the page should be skipped
$currentPageUid = $GLOBALS['TSFE']->id;
$pageUidsInRootline = [];
// get rootline of the current page
$rootline = $GLOBALS['TSFE']->sys_page->getRootline($currentPageUid);
// build an array of uids of pages the rootline
for ($i = count($rootline) - 1; $i >= 0; $i--) {
$pageUidsInRootline[] = (int) $rootline[$i]['uid'];
}
// check if the root page is in the rootline of the current page
$includeRootPagesUids = GeneralUtility::intExplode(',', $this->conf['includeRootPages'], 1);
foreach ($includeRootPagesUids as $includeRootPageUid) {
if (in_array($includeRootPageUid, $pageUidsInRootline)) {
$result = false;
}
}
$excludeRootPagesUids = GeneralUtility::intExplode(',', $this->conf['excludeRootPages'], 1);
foreach ($excludeRootPagesUids as $excludeRootPageUid) {
if (in_array($excludeRootPageUid, $pageUidsInRootline)) {
$result = true;
}
}
if (GeneralUtility::inList($this->conf['includePages'], $currentPageUid)) {
$result = false;
}
if (GeneralUtility::inList($this->conf['excludePages'], $currentPageUid)) {
$result = true;
}
if ($GLOBALS['TSFE']->page['tx_contagged_dont_parse'] == 1) {
$result = true;
}
if (!empty($this->cObj)) {
if ($this->cObj->getFieldVal('tx_contagged_dont_parse') == 1) {
$result = true;
}
}
return $result;
}
/**
* Replaces block elements with inline versions (if possible)
*
* @param string $text
* @return string The reformatted text
*/
protected function stripBlockTags($text)
{
$blockElements = 'address|blockquote|center|del|dir|div|dl|fieldset|form|h[1-6]|hr|ins|isindex|menu|noframes|noscript|ol|p|pre|table|ul|center|dir|isindex|menu|noframes';
$text = preg_replace('%' . $this->getOpeningTag('li|dd') . '%xs', ' * ', $text);
$text = preg_replace('%' . $this->getClosingTag('li|dt') . '%xs', '<br />', $text);
$text = preg_replace('%' . $this->getClosingTag('ol|ul|dl') . '%xs', '', $text);
$text = preg_replace('%' . $this->getOpeningTag($blockElements) . '%xs', '', $text);
$text = preg_replace('%' . $this->getClosingTag($blockElements) . '%xs', '<br />', $text);
$text = preg_replace('%' . $this->getOpeningTag('br') . '{2,2}%xs', '<br />', $text);
return $text;
}
/**
* Returns an opening tag of the allowed elements.
*
* @param string $allowedElements The allowed elements ("a|b|c")
* @return void
*/
protected function getOpeningTag($allowedElements)
{
$tag = "
(
<(?:" . $allowedElements . ") # opening tag ('<tag') or closing tag ('</tag')
(?:
(?:
\s+\w+ # EITHER spaces, followed by word characters (attribute names)
(?:
\s*=?\s* # equals
(?>
\".*?\" # attribute values in double-quotes
|
'.*?' # attribute values in single-quotes
|
[^'\">\s]+ # plain attribute values
)
)?
)+\s*
| # OR only spaces
\s*
)
/?> # closing the tag with '>' or '/>'
)";
return $tag;
}
/**
* Returns a closing tag of the allowed elements.
*
* @param string $allowedElements The allowed elements ("a|b|c")
* @return void
*/
protected function getClosingTag($allowedElements)
{
$tag = "
(
</(?:" . $allowedElements . ") # opening tag ('<tag') or closing tag ('</tag')
(?:
(?:
\s+\w+ # EITHER spaces, followed by word characters (attribute names)
(?:
\s*=?\s* # equals
(?>
\".*?\" # attribute values in double-quotes
|
'.*?' # attribute values in single-quotes
|
[^'\">\s]+ # plain attribute values
)
)?
)+\s*
| # OR only spaces
\s*
)
> # closing the tag with '>' or '/>'
)";
return $tag;
}
/**
* Adds the qTip plugin script (jQuery). You can call this function in you TS setup if necessary.
*
* @return void
*/
protected function addJavaScript()
{
$extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['contagged']);
$javaScriptPathAndFilename = $extensionConfiguration['javaScriptPathAndFilename'];
if (is_string($javaScriptPathAndFilename) && $javaScriptPathAndFilename !== '') {
$GLOBALS['TSFE']->additionalHeaderData['contagged'] .= '<script src="' . $javaScriptPathAndFilename . '" type="text/javascript"></script>';
}
}
}