Completed
Push — master ( 2e6333...1c8f27 )
by Tim
17:33
created

Classes/Xclass/ContentObjectRenderer.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * ContentObjectRenderer
4
 */
5
6
namespace FRUIT\Popup\Xclass;
7
8
use TYPO3\CMS\Core\Utility\GeneralUtility;
9
use TYPO3\CMS\Frontend\Plugin\AbstractPlugin;
10
11
/**
12
 * ContentObjectRenderer
13
 */
14
class ContentObjectRenderer extends \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
15
{
16
17
18
    /**
19
     * Implements the "typolink" property of stdWrap (and others)
20
     * Basically the input string, $linktext, is (typically) wrapped in a <a>-tag linking to some page, email address, file or URL based on a parameter defined by the configuration array $conf.
21
     * This function is best used from internal functions as is. There are some API functions defined after this function which is more suited for general usage in external applications.
22
     * Generally the concept "typolink" should be used in your own applications as an API for making links to pages with parameters and more. The reason for this is that you will then automatically make links compatible with all the centralized functions for URL simulation and manipulation of parameters into hashes and more.
23
     * For many more details on the parameters and how they are intepreted, please see the link to TSref below.
24
     *
25
     * @param    string        The string (text) to link
26
     * @param    array        TypoScript configuration (see link below)
27
     * @return    string        A link-wrapped string.
28
     * @see stdWrap(), tslib_pibase::pi_linkTP()
29
     * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=321&cHash=59bd727a5e
30
     */
31
    function typoLink($linktxt, $conf)
32
    {
33
        $LD = [];
34
        $finalTagParts = [];
35
        $finalTagParts['aTagParams'] = $this->getATagParams($conf);
36
37
        $link_param = trim($this->stdWrap($conf['parameter'], $conf['parameter.']));
38
39
        $sectionMark = trim($this->stdWrap($conf['section'], $conf['section.']));
40
        $sectionMark = $sectionMark ? (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sectionMark) ? '#c' : '#') . $sectionMark : '';
41
        $initP = '?id=' . $GLOBALS['TSFE']->id . '&type=' . $GLOBALS['TSFE']->type;
42
        $this->lastTypoLinkUrl = '';
43
        $this->lastTypoLinkTarget = '';
44
        if ($link_param) {
45
            $enableLinksAcrossDomains = $GLOBALS['TSFE']->config['config']['typolinkEnableLinksAcrossDomains'];
46
            $link_paramA = GeneralUtility::unQuoteFilenames($link_param, true);
47
48
            // Check for link-handler keyword:
49
            list($linkHandlerKeyword, $linkHandlerValue) = explode(':', trim($link_paramA[0]), 2);
50
            if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler'][$linkHandlerKeyword] && strcmp($linkHandlerValue,
51
                    '')
52
            ) {
53
                $linkHandlerObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler'][$linkHandlerKeyword]);
54
55
                if (method_exists($linkHandlerObj, 'main')) {
56
                    return $linkHandlerObj->main($linktxt, $conf, $linkHandlerKeyword, $linkHandlerValue, $link_param,
57
                        $this);
58
                }
59
            }
60
61
            $link_param = trim($link_paramA[0]);    // Link parameter value
62
            $linkClass = trim($link_paramA[2]);        // Link class
63
            if ($linkClass == '-') {
64
                $linkClass = '';
65
            }    // The '-' character means 'no class'. Necessary in order to specify a title as fourth parameter without setting the target or class!
66
            $forceTarget = trim($link_paramA[1]);    // Target value
67
            $forceTitle = trim($link_paramA[3]);    // Title value
68
            if ($forceTarget == '-') {
69
                $forceTarget = '';
70
            }    // The '-' character means 'no target'. Necessary in order to specify a class as third parameter without setting the target!
71
            // Check, if the target is coded as a JS open window link:
72
            $JSwindowParts = [];
73
            $JSwindowParams = '';
74
            $onClick = '';
75
            if ($forceTarget && preg_match('/^([0-9]+)x([0-9]+)(:(.*)|.*)$/', $forceTarget, $JSwindowParts)) {
76
                // Take all pre-configured and inserted parameters and compile parameter list, including width+height:
77
                $JSwindow_tempParamsArr = GeneralUtility::trimExplode(',',
78
                    strtolower($conf['JSwindow_params'] . ',' . $JSwindowParts[4]), 1);
0 ignored issues
show
1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
                $JSwindow_paramsArr = [];
80
                foreach ($JSwindow_tempParamsArr as $JSv) {
81
                    list($JSp, $JSv) = explode('=', $JSv);
82
                    $JSwindow_paramsArr[$JSp] = $JSp . '=' . $JSv;
83
                }
84
                // Add width/height:
85
                $JSwindow_paramsArr['width'] = 'width=' . $JSwindowParts[1];
86
                $JSwindow_paramsArr['height'] = 'height=' . $JSwindowParts[2];
87
                // Imploding into string:
88
                $JSwindowParams = implode(',', $JSwindow_paramsArr);
89
                $forceTarget = '';    // Resetting the target since we will use onClick.
90
            }
91
92
            // Internal target:
93
            $target = isset($conf['target']) ? $conf['target'] : $GLOBALS['TSFE']->intTarget;
94
            if ($conf['target.']) {
95
                $target = $this->stdWrap($target, $conf['target.']);
96
            }
97
98
            // Title tag
99
            $title = $conf['title'];
100
            if ($conf['title.']) {
101
                $title = $this->stdWrap($title, $conf['title.']);
102
            }
103
104
            // Parse URL:
105
            $pU = parse_url($link_param);
106
107
            // Detecting kind of link:
108
            if (strstr($link_param,
109
                    '@') && (!$pU['scheme'] || $pU['scheme'] == 'mailto')
110
            ) {        // If it's a mail address:
111
                $link_param = preg_replace('/^mailto:/i', '', $link_param);
112
                list($this->lastTypoLinkUrl, $linktxt) = $this->getMailTo($link_param, $linktxt, $initP);
113
                $finalTagParts['url'] = $this->lastTypoLinkUrl;
114
                $finalTagParts['TYPE'] = 'mailto';
115
            } else {
116
                $isLocalFile = 0;
117
                $fileChar = intval(strpos($link_param, '/'));
118
                $urlChar = intval(strpos($link_param, '.'));
119
120
                // Firsts, test if $link_param is numeric and page with such id exists. If yes, do not attempt to link to file
121
                if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($link_param) || count($GLOBALS['TSFE']->sys_page->getPage_noCheck($link_param)) == 0) {
122
                    // Detects if a file is found in site-root (or is a 'virtual' simulateStaticDocument file!) and if so it will be treated like a normal file.
123
                    list($rootFileDat) = explode('?', rawurldecode($link_param));
124
                    $containsSlash = strstr($rootFileDat, '/');
125
                    $rFD_fI = pathinfo($rootFileDat);
126
                    if (trim($rootFileDat) && !$containsSlash && (@is_file(PATH_site . $rootFileDat) || GeneralUtility::inList('php,html,htm',
127
                                strtolower($rFD_fI['extension'])))
128
                    ) {
129
                        $isLocalFile = 1;
130
                    } elseif ($containsSlash) {
131
                        $isLocalFile = 2;        // Adding this so realurl directories are linked right (non-existing).
132
                    }
133
                }
134
135
                if ($pU['scheme'] || ($isLocalFile != 1 && $urlChar && (!$containsSlash || $urlChar < $fileChar))) {    // url (external): If doubleSlash or if a '.' comes before a '/'.
136
                    $target = isset($conf['extTarget']) ? $conf['extTarget'] : $GLOBALS['TSFE']->extTarget;
137
                    if ($conf['extTarget.']) {
138
                        $target = $this->stdWrap($target, $conf['extTarget.']);
139
                    }
140
                    if ($forceTarget) {
141
                        $target = $forceTarget;
142
                    }
143
                    if ($linktxt == '') {
144
                        $linktxt = $link_param;
145
                    }
146
                    if (!$pU['scheme']) {
147
                        $scheme = 'http://';
148
                    } else {
149
                        $scheme = '';
150
                    }
151
                    if ($GLOBALS['TSFE']->config['config']['jumpurl_enable']) {
152
                        $this->lastTypoLinkUrl = $GLOBALS['TSFE']->absRefPrefix . $GLOBALS['TSFE']->config['mainScript'] . $initP . '&jumpurl=' . rawurlencode($scheme . $link_param) . $GLOBALS['TSFE']->getMethodUrlIdToken;
153
                    } else {
154
                        $this->lastTypoLinkUrl = $scheme . $link_param;
155
                    }
156
                    $this->lastTypoLinkTarget = $target;
157
                    $finalTagParts['url'] = $this->lastTypoLinkUrl;
158
                    $finalTagParts['targetParams'] = $target ? ' target="' . $target . '"' : '';
159
                    $finalTagParts['TYPE'] = 'url';
160
                    $finalTagParts['aTagParams'] .= $this->extLinkATagParams($finalTagParts['url'],
161
                        $finalTagParts['TYPE']);
162
                } elseif ($containsSlash || $isLocalFile) {    // file (internal)
163
                    $splitLinkParam = explode('?', $link_param);
164
                    if (file_exists(rawurldecode($splitLinkParam[0])) || $isLocalFile) {
165
                        if ($linktxt == '') {
166
                            $linktxt = rawurldecode($link_param);
167
                        }
168
                        if ($GLOBALS['TSFE']->config['config']['jumpurl_enable']) {
169
                            $this->lastTypoLinkUrl = $GLOBALS['TSFE']->absRefPrefix . $GLOBALS['TSFE']->config['mainScript'] . $initP . '&jumpurl=' . rawurlencode($link_param) . $GLOBALS['TSFE']->getMethodUrlIdToken;
170
                        } else {
171
                            $this->lastTypoLinkUrl = $GLOBALS['TSFE']->absRefPrefix . $link_param;
172
                        }
173
                        $target = isset($conf['fileTarget']) ? $conf['fileTarget'] : $GLOBALS['TSFE']->fileTarget;
174
                        if ($conf['fileTarget.']) {
175
                            $target = $this->stdWrap($target, $conf['fileTarget.']);
176
                        }
177
                        if ($forceTarget) {
178
                            $target = $forceTarget;
179
                        }
180
                        $this->lastTypoLinkTarget = $target;
181
182
                        $finalTagParts['url'] = $this->lastTypoLinkUrl;
183
                        $finalTagParts['targetParams'] = $target ? ' target="' . $target . '"' : '';
184
                        $finalTagParts['TYPE'] = 'file';
185
                        $finalTagParts['aTagParams'] .= $this->extLinkATagParams($finalTagParts['url'],
186
                            $finalTagParts['TYPE']);
187
                    } else {
188
                        $GLOBALS['TT']->setTSlogMessage("typolink(): File '" . $splitLinkParam[0] . "' did not exist, so '" . $linktxt . "' was not linked.",
189
                            1);
190
                        return $linktxt;
191
                    }
192
                } else {    // integer or alias (alias is without slashes or periods or commas, that is 'nospace,alphanum_x,lower,unique' according to definition in $TCA!)
193
                    if ($conf['no_cache.']) {
194
                        $conf['no_cache'] = $this->stdWrap($conf['no_cache'], $conf['no_cache.']);
195
                    }
196
                    $link_params_parts = explode('#', $link_param);
197
                    $link_param = trim($link_params_parts[0]);        // Link-data del
198
                    if (!strcmp($link_param, '')) {
199
                        $link_param = $GLOBALS['TSFE']->id;
200
                    }    // If no id or alias is given
201
                    if ($link_params_parts[1] && !$sectionMark) {
202
                        $sectionMark = trim($link_params_parts[1]);
203
                        $sectionMark = (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($sectionMark) ? '#c' : '#') . $sectionMark;
204
                    }
205
                    // Splitting the parameter by ',' and if the array counts more than 1 element it's a id/type/? pair
206
                    unset($theTypeP);
207
                    $pairParts = GeneralUtility::trimExplode(',', $link_param);
208
                    if (count($pairParts) > 1) {
209
                        $link_param = $pairParts[0];
210
                        $theTypeP = isset($pairParts[1]) ? $pairParts[1] : 0;        // Overruling 'type'
211
                        $conf['additionalParams'] .= isset($pairParts[2]) ? $pairParts[2] : '';
212
                    }
213
                    // Checking if the id-parameter is an alias.
214
                    if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($link_param)) {
215
                        $link_param = $GLOBALS['TSFE']->sys_page->getPageIdFromAlias($link_param);
216
                    }
217
218
                    // Link to page even if access is missing?
219
                    if (strlen($conf['linkAccessRestrictedPages'])) {
220
                        $disableGroupAccessCheck = ($conf['linkAccessRestrictedPages'] ? true : false);
221
                    } else {
222
                        $disableGroupAccessCheck = ($GLOBALS['TSFE']->config['config']['typolinkLinkAccessRestrictedPages'] ? true : false);
223
                    }
224
225
                    // Looking up the page record to verify its existence:
226
                    $page = $GLOBALS['TSFE']->sys_page->getPage($link_param, $disableGroupAccessCheck);
227
228
                    if (count($page)) {
229
                        // MointPoints, look for closest MPvar:
230
                        $MPvarAcc = [];
231
                        if (!$GLOBALS['TSFE']->config['config']['MP_disableTypolinkClosestMPvalue']) {
232
                            $temp_MP = $this->getClosestMPvalueForPage($page['uid'], true);
233
                            if ($temp_MP) {
234
                                $MPvarAcc['closest'] = $temp_MP;
235
                            }
236
                        }
237
                        // Look for overlay Mount Point:
238
                        $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($page['uid'], $page);
239
                        if (is_array($mount_info) && $mount_info['overlay']) {
240
                            $page = $GLOBALS['TSFE']->sys_page->getPage($mount_info['mount_pid'],
241
                                $disableGroupAccessCheck);
242
                            if (!count($page)) {
243
                                $GLOBALS['TT']->setTSlogMessage("typolink(): Mount point '" . $mount_info['mount_pid'] . "' was not available, so '" . $linktxt . "' was not linked.",
244
                                    1);
245
                                return $linktxt;
246
                            }
247
                            $MPvarAcc['re-map'] = $mount_info['MPvar'];
248
                        }
249
250
251
                        // -----------------------
252
                        // Popup Hook
253
                        // -----------------------
254
                        $popup = AbstractPlugin::pi_getRecord('pages', $page['uid']);
255
                        $popup_configuration = $popup['tx_popup_configuration'];
256
257
258
                        // Setting title if blank value to link:
259
                        if ($linktxt == '') {
260
                            $linktxt = $page['title'];
261
                        }
262
263
                        // Query Params:
264
                        $addQueryParams = $conf['addQueryString'] ? $this->getQueryArguments($conf['addQueryString.']) : '';
265
                        $addQueryParams .= trim($this->stdWrap($conf['additionalParams'], $conf['additionalParams.']));
266
                        if (substr($addQueryParams, 0, 1) != '&') {
267
                            $addQueryParams = '';
268
                        } elseif ($conf['useCacheHash']) {    // cache hashing:
269
                            // Added '.$this->linkVars' dec 2003: The need for adding the linkVars is that they will be included in the link, but not the cHash. Thus the linkVars will always be the problem that prevents the cHash from working. I cannot see what negative implications in terms of incompatibilities this could bring, but for now I hope there are none. So here we go... (- kasper);
270
                            $addQueryParams .= '&cHash=' . GeneralUtility::generateCHash($addQueryParams . $GLOBALS['TSFE']->linkVars);
271
                        }
272
273
                        $tCR_domain = '';
274
                        // Mount pages are always local and never link to another domain
275
                        if (count($MPvarAcc)) {
276
                            // Add "&MP" var:
277
                            $addQueryParams .= '&MP=' . rawurlencode(implode(',', $MPvarAcc));
278
                        } elseif (strpos($addQueryParams,
279
                                '&MP=') === false && $GLOBALS['TSFE']->config['config']['typolinkCheckRootline']
280
                        ) {
281
282
                            // We do not come here if additionalParams had '&MP='. This happens when typoLink is called from
283
                            // menu. Mount points always work in the content of the current domain and we must not change
284
                            // domain if MP variables exist.
285
286
                            // If we link across domains and page is free type shortcut, we must resolve the shortcut first!
287
                            // If we do not do it, TYPO3 will fail to (1) link proper page in RealURL/CoolURI because
288
                            // they return relative links and (2) show proper page if no RealURL/CoolURI exists when link is clicked
289
                            if ($enableLinksAcrossDomains && $page['doktype'] == 4 && $page['shortcut_mode'] == 0) {
290
                                $page2 = $page;    // Save in case of broken destination or endless loop
291
                                $maxLoopCount = 20;    // Same as in RealURL, seems enough
292
                                while ($maxLoopCount && is_array($page) && $page['doktype'] == 4 && $page['shortcut_mode'] == 0) {
293
                                    $page = $GLOBALS['TSFE']->sys_page->getPage($page['shortcut'],
294
                                        $disableGroupAccessCheck);
295
                                    $maxLoopCount--;
296
                                }
297
                                if (count($page) == 0 || $maxLoopCount == 0) {
298
                                    // We revert if shortcut is broken or maximum number of loops is exceeded (indicates endless loop)
299
                                    $page = $page2;
300
                                }
301
                            }
302
303
                            // This checks if the linked id is in the rootline of this site and if not it will find the domain for that ID and prefix it:
304
                            $tCR_rootline = $GLOBALS['TSFE']->sys_page->getRootLine($page['uid']);    // Gets rootline of linked-to page
305
                            $tCR_flag = 0;
306
                            foreach ($tCR_rootline as $tCR_data) {
307
                                if ($tCR_data['uid'] == $GLOBALS['TSFE']->tmpl->rootLine[0]['uid']) {
308
                                    $tCR_flag = 1;    // OK, it was in rootline!
309
                                    break;
310
                                }
311
                                if ($tCR_data['is_siteroot']) {
312
                                    // Possibly subdomain inside main domain. In any case we must stop now because site root is reached.
313
                                    break;
314
                                }
315
                            }
316
                            if (!$tCR_flag) {
317
                                foreach ($tCR_rootline as $tCR_data) {
318
                                    $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('domainName', 'sys_domain',
319
                                        'pid=' . intval($tCR_data['uid']) . ' AND redirectTo=\'\'' . $this->enableFields('sys_domain'),
320
                                        '', 'sorting');
321
                                    $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
322
                                    $GLOBALS['TYPO3_DB']->sql_free_result($res);
323
                                    if ($row) {
324
                                        $tCR_domain = preg_replace('/\/$/', '', $row['domainName']);
325
                                        break;
326
                                    }
327
                                }
328
                            }
329
                        }
330
                        // If other domain, overwrite
331
                        if (strlen($tCR_domain) && !$enableLinksAcrossDomains) {
332
                            $target = isset($conf['extTarget']) ? $conf['extTarget'] : $GLOBALS['TSFE']->extTarget;
333
                            if ($conf['extTarget.']) {
334
                                $target = $this->stdWrap($target, $conf['extTarget.']);
335
                            }
336
                            if ($forceTarget) {
337
                                $target = $forceTarget;
338
                            }
339
                            $LD['target'] = $target;
340
                            $this->lastTypoLinkUrl = $this->URLqMark('http://' . $tCR_domain . '/index.php?id=' . $page['uid'],
341
                                    $addQueryParams) . $sectionMark;
342
                        } else {    // Internal link:
343
                            if ($forceTarget) {
344
                                $target = $forceTarget;
345
                            }
346
                            $LD = $GLOBALS['TSFE']->tmpl->linkData($page, $target, $conf['no_cache'], '', '',
347
                                $addQueryParams, $theTypeP, $tCR_domain);
348
                            if (strlen($tCR_domain)) {
349
                                // We will add domain only if URL does not have it already.
350
351
                                if ($enableLinksAcrossDomains) {
352
                                    // Get rid of the absRefPrefix if necessary. absRefPrefix is applicable only
353
                                    // to the current web site. If we have domain here it means we link across
354
                                    // domains. absRefPrefix can contain domain name, which will screw up
355
                                    // the link to the external domain.
356
                                    $prefixLength = strlen($GLOBALS['TSFE']->config['config']['absRefPrefix']);
357
                                    if (substr($LD['totalURL'], 0,
358
                                            $prefixLength) == $GLOBALS['TSFE']->config['config']['absRefPrefix']
359
                                    ) {
360
                                        $LD['totalURL'] = substr($LD['totalURL'], $prefixLength);
361
                                    }
362
                                }
363
                                $urlParts = parse_url($LD['totalURL']);
364
                                if ($urlParts['host'] == '') {
365
                                    $LD['totalURL'] = 'http://' . $tCR_domain . ($LD['totalURL']{0} == '/' ? '' : '/') . $LD['totalURL'];
366
                                }
367
                            }
368
                            $this->lastTypoLinkUrl = $this->URLqMark($LD['totalURL'], '') . $sectionMark;
369
                        }
370
371
                        $this->lastTypoLinkTarget = $LD['target'];
372
                        $targetPart = $LD['target'] ? ' target="' . $LD['target'] . '"' : '';
373
374
                        // If sectionMark is set, there is no baseURL AND the current page is the page the link is to, check if there are any additional parameters and is not, drop the url.
375
                        if ($sectionMark && !trim($addQueryParams) && $page['uid'] == $GLOBALS['TSFE']->id && !$GLOBALS['TSFE']->config['config']['baseURL']) {
376
                            list(, $URLparams) = explode('?', $this->lastTypoLinkUrl);
377
                            list($URLparams) = explode('#', $URLparams);
378
                            parse_str($URLparams . $LD['orig_type'], $URLparamsArray);
379
                            if (intval($URLparamsArray['type']) == $GLOBALS['TSFE']->type) {    // type nums must match as well as page ids
380
                                unset($URLparamsArray['id']);
381
                                unset($URLparamsArray['type']);
382
                                if (!count($URLparamsArray)) {    // If there are no parameters left.... set the new url.
383
                                    $this->lastTypoLinkUrl = $sectionMark;
384
                                }
385
                            }
386
                        }
387
388
                        // If link is to a access restricted page which should be redirected, then find new URL:
389
                        if ($GLOBALS['TSFE']->config['config']['typolinkLinkAccessRestrictedPages'] &&
390
                            $GLOBALS['TSFE']->config['config']['typolinkLinkAccessRestrictedPages'] !== 'NONE' &&
391
                            !$GLOBALS['TSFE']->checkPageGroupAccess($page)
392
                        ) {
393
                            $thePage = $GLOBALS['TSFE']->sys_page->getPage($GLOBALS['TSFE']->config['config']['typolinkLinkAccessRestrictedPages']);
394
395
                            $addParams = $GLOBALS['TSFE']->config['config']['typolinkLinkAccessRestrictedPages_addParams'];
396
                            $addParams = str_replace('###RETURN_URL###', rawurlencode($this->lastTypoLinkUrl),
397
                                $addParams);
398
                            $addParams = str_replace('###PAGE_ID###', $page['uid'], $addParams);
399
                            $this->lastTypoLinkUrl = $this->getTypoLink_URL(
400
                                $thePage['uid'] . ($theTypeP ? ',' . $theTypeP : ''),
401
                                $addParams,
402
                                $target
403
                            );
404
                            $LD = $this->lastTypoLinkLD;
405
                        }
406
407
                        // Rendering the tag.
408
                        $finalTagParts['url'] = $this->lastTypoLinkUrl;
409
                        $finalTagParts['targetParams'] = $targetPart;
410
                        $finalTagParts['TYPE'] = 'page';
411
                    } else {
412
                        $GLOBALS['TT']->setTSlogMessage("typolink(): Page id '" . $link_param . "' was not found, so '" . $linktxt . "' was not linked.",
413
                            1);
414
                        return $linktxt;
415
                    }
416
                }
417
            }
418
419
            $this->lastTypoLinkLD = $LD;
420
421
            if ($forceTitle) {
422
                $title = $forceTitle;
423
            }
424
425
            if ($JSwindowParams) {
426
427
                // Create TARGET-attribute only if the right doctype is used
428
                if (!GeneralUtility::inList('xhtml_strict,xhtml_11,xhtml_2', $GLOBALS['TSFE']->xhtmlDoctype)) {
429
                    $target = ' target="FEopenLink"';
430
                } else {
431
                    $target = '';
432
                }
433
434
                $onClick = "vHWin=window.open('" . $GLOBALS['TSFE']->baseUrlWrap($finalTagParts['url']) . "','FEopenLink','" . $JSwindowParams . "');vHWin.focus();return false;";
435
                $res = '<a href="' . htmlspecialchars($finalTagParts['url']) . '"' . $target . ' onclick="' . htmlspecialchars($onClick) . '"' . ($title ? ' title="' . $title . '"' : '') . ($linkClass ? ' class="' . $linkClass . '"' : '') . $finalTagParts['aTagParams'] . '>';
436
            } else {
437
                if ($GLOBALS['TSFE']->spamProtectEmailAddresses === 'ascii' && $finalTagParts['TYPE'] === 'mailto') {
438
                    $res = '<a href="' . $finalTagParts['url'] . '"' . ($title ? ' title="' . $title . '"' : '') . $finalTagParts['targetParams'] . ($linkClass ? ' class="' . $linkClass . '"' : '') . $finalTagParts['aTagParams'] . '>';
439
                } else {
440
441
442
                    // -----------------------
443
                    // Popup Hook
444
                    // -----------------------
445
                    if (isset($popup_configuration) && strlen($popup_configuration)) {
446
                        $popup = GeneralUtility::makeInstance('FRUIT\\Popup\\Popup');
447
                        $popup_configuration = $popup->convertCfg2Js($popup_configuration);
448
                        $res = '<a href="' . htmlspecialchars($finalTagParts['url']) . '"' . ($title ? ' title="' . $title . '"' : '') . $finalTagParts['targetParams'] . ($linkClass ? ' class="' . $linkClass . '"' : '') . $finalTagParts['aTagParams'] . ' onclick="window.open(this.href,\'\',\'' . $popup_configuration . '\'); return false;">';
449
                    } else {
450
                        $res = '<a href="' . htmlspecialchars($finalTagParts['url']) . '"' . ($title ? ' title="' . $title . '"' : '') . $finalTagParts['targetParams'] . ($linkClass ? ' class="' . $linkClass . '"' : '') . $finalTagParts['aTagParams'] . '>';
451
                    }
452
453
454
                }
455
            }
456
457
            // Call user function:
458
            if ($conf['userFunc']) {
459
                $finalTagParts['TAG'] = $res;
460
                $res = $this->callUserFunction($conf['userFunc'], $conf['userFunc.'], $finalTagParts);
461
            }
462
463
            // Hook: Call post processing function for link rendering:
464
            if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc'])) {
465
                $_params = [
466
                    'conf' => &$conf,
467
                    'linktxt' => &$linktxt,
468
                    'finalTag' => &$res,
469
                    'finalTagParts' => &$finalTagParts,
470
                ];
471
                foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc'] as $_funcRef) {
472
                    GeneralUtility::callUserFunction($_funcRef, $_params, $this);
473
                }
474
            }
475
476
            // If flag "returnLastTypoLinkUrl" set, then just return the latest URL made:
477
            if ($conf['returnLast']) {
478
                switch ($conf['returnLast']) {
479
                    case 'url':
480
                        return $this->lastTypoLinkUrl;
481
                        break;
482
                    case 'target':
483
                        return $this->lastTypoLinkTarget;
484
                        break;
485
                }
486
            }
487
488
            if ($conf['ATagBeforeWrap']) {
489
                return $res . $this->wrap($linktxt, $conf['wrap']) . '</a>';
490
            } else {
491
                return $this->wrap($res . $linktxt . '</a>', $conf['wrap']);
492
            }
493
        } else {
494
            return $linktxt;
495
        }
496
    }
497
498
}