[TASK] CGL violations "AssignmentArithmeticAndComparisonSpace"
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Controller / TypoScriptFrontendController.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Class for the built TypoScript based Front End
31 *
32 * This class has a lot of functions and internal variable which are use from index_ts.php.
33 * The class is instantiated as $GLOBALS['TSFE'] in index_ts.php.
34 * The use of this class should be inspired by the order of function calls as found in index_ts.php.
35 *
36 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
37 * XHTML compliant
38 *
39 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
40 */
41 /**
42 * Main frontend class, instantiated in the index_ts.php script as the global object TSFE
43 *
44 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
45 * @package TYPO3
46 * @subpackage tslib
47 */
48 class TypoScriptFrontendController {
49
50 // CURRENT PAGE:
51 // The page id (int)
52 /**
53 * @todo Define visibility
54 */
55 public $id = '';
56
57 // RO The type (int)
58 /**
59 * @todo Define visibility
60 */
61 public $type = '';
62
63 // Loaded with the id, exploded by ','
64 /**
65 * @todo Define visibility
66 */
67 public $idParts = array();
68
69 // The submitted cHash
70 /**
71 * @todo Define visibility
72 */
73 public $cHash = '';
74
75 // Page will not be cached. Write only TRUE. Never clear value (some other code might have reasons to set it TRUE)
76 /**
77 * @todo Define visibility
78 */
79 public $no_cache = '';
80
81 // The rootLine (all the way to tree root, not only the current site!) (array)
82 /**
83 * @todo Define visibility
84 */
85 public $rootLine = '';
86
87 // The pagerecord (array)
88 /**
89 * @todo Define visibility
90 */
91 public $page = '';
92
93 // This will normally point to the same value as id, but can be changed to point to another page from which content will then be displayed instead.
94 /**
95 * @todo Define visibility
96 */
97 public $contentPid = 0;
98
99 // Gets set when we are processing a page of type shortcut in the early stages opf init.php when we do not know about languages yet, used later in init.php to determine the correct shortcut in case a translation changes the shortcut target (array)
100 protected $originalShortcutPage = NULL;
101
102 /**
103 * sys_page-object, pagefunctions
104 *
105 * @var \TYPO3\CMS\Frontend\Page\PageRepository
106 * @todo Define visibility
107 */
108 public $sys_page = '';
109
110 /**
111 * @todo Define visibility
112 */
113 public $jumpurl = '';
114
115 // Is set to 1 if a pageNotFound handler could have been called.
116 /**
117 * @todo Define visibility
118 */
119 public $pageNotFound = 0;
120
121 // Domain start page
122 /**
123 * @todo Define visibility
124 */
125 public $domainStartPage = 0;
126
127 // Array containing a history of why a requested page was not accessible.
128 /**
129 * @todo Define visibility
130 */
131 public $pageAccessFailureHistory = array();
132
133 /**
134 * @todo Define visibility
135 */
136 public $MP = '';
137
138 /**
139 * @todo Define visibility
140 */
141 public $RDCT = '';
142
143 // This can be set from applications as a way to tag cached versions of a page and later perform some external cache management, like clearing only a part of the cache of a page...
144 /**
145 * @todo Define visibility
146 */
147 public $page_cache_reg1 = 0;
148
149 // Contains the value of the current script path that activated the frontend. Typically "index.php" but by rewrite rules it could be something else! Used for Speaking Urls / Simulate Static Documents.
150 /**
151 * @todo Define visibility
152 */
153 public $siteScript = '';
154
155 /**
156 * The FE user
157 *
158 * @var \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthtenication
159 * @todo Define visibility
160 */
161 public $fe_user = '';
162
163 // Global flag indicating that a front-end user is logged in. This is set only if a user really IS logged in. The group-list may show other groups (like added by IP filter or so) even though there is no user.
164 /**
165 * @todo Define visibility
166 */
167 public $loginUser = '';
168
169 // (RO=readonly) The group list, sorted numerically. Group '0,-1' is the default group, but other groups may be added by other means than a user being logged in though...
170 /**
171 * @todo Define visibility
172 */
173 public $gr_list = '';
174
175 // Flag that indicates if a Backend user is logged in!
176 /**
177 * @todo Define visibility
178 */
179 public $beUserLogin = '';
180
181 // Integer, that indicates which workspace is being previewed.
182 /**
183 * @todo Define visibility
184 */
185 public $workspacePreview = 0;
186
187 // Shows whether logins are allowed in branch
188 /**
189 * @todo Define visibility
190 */
191 public $loginAllowedInBranch = TRUE;
192
193 // Shows specific mode (all or groups)
194 /**
195 * @todo Define visibility
196 */
197 public $loginAllowedInBranch_mode = '';
198
199 // Integer, set to backend user ID to initialize when keyword-based preview is used.
200 /**
201 * @todo Define visibility
202 */
203 public $ADMCMD_preview_BEUSER_uid = 0;
204
205 // PREVIEW
206 // Flag indication that preview is active. This is based on the login of a backend user and whether the backend user has read access to the current page. A value of 1 means ordinary preview, 2 means preview of a non-live workspace
207 /**
208 * @todo Define visibility
209 */
210 public $fePreview = '';
211
212 // Flag indicating that hidden pages should be shown, selected and so on. This goes for almost all selection of pages!
213 /**
214 * @todo Define visibility
215 */
216 public $showHiddenPage = '';
217
218 // Flag indicating that hidden records should be shown. This includes sys_template, pages_language_overlay and even fe_groups in addition to all other regular content. So in effect, this includes everything except pages.
219 /**
220 * @todo Define visibility
221 */
222 public $showHiddenRecords = '';
223
224 // Value that contains the simulated usergroup if any
225 /**
226 * @todo Define visibility
227 */
228 public $simUserGroup = '0';
229
230 // CONFIGURATION
231 /**
232 * Copy of $GLOBALS['TYPO3_CONF_VARS']
233 *
234 * @var array
235 */
236 public $TYPO3_CONF_VARS = array();
237
238 // "CONFIG" object from TypoScript. Array generated based on the TypoScript configuration of the current page. Saved with the cached pages.
239 /**
240 * @todo Define visibility
241 */
242 public $config = '';
243
244 // Array of cached information from TCA. This is NOT TCA itself!
245 /**
246 * @todo Define visibility
247 */
248 public $TCAcachedExtras = array();
249
250 // TEMPLATE / CACHE
251 /**
252 * The TypoScript template object. Used to parse the TypoScript template
253 *
254 * @var \TYPO3\CMS\Core\TypoScript\TemplateService
255 * @todo Define visibility
256 */
257 public $tmpl = '';
258
259 // Is set to the time-to-live time of cached pages. If FALSE, default is 60*60*24, which is 24 hours.
260 /**
261 * @todo Define visibility
262 */
263 public $cacheTimeOutDefault = FALSE;
264
265 // Set internally if cached content is fetched from the database
266 /**
267 * @todo Define visibility
268 */
269 public $cacheContentFlag = 0;
270
271 // Set to the expire time of cached content
272 /**
273 * @todo Define visibility
274 */
275 public $cacheExpires = 0;
276
277 // Set if cache headers allowing caching are sent.
278 /**
279 * @todo Define visibility
280 */
281 public $isClientCachable = FALSE;
282
283 // $all used by template fetching system. This array is an identification of the template. If $this->all is empty it's because the template-data is not cached, which it must be.
284 /**
285 * @todo Define visibility
286 */
287 public $all = '';
288
289 // toplevel - objArrayName, eg 'page'
290 /**
291 * @todo Define visibility
292 */
293 public $sPre = '';
294
295 // TypoScript configuration of the page-object pointed to by sPre. $this->tmpl->setup[$this->sPre.'.']
296 /**
297 * @todo Define visibility
298 */
299 public $pSetup = '';
300
301 // This hash is unique to the template, the $this->id and $this->type vars and the gr_list (list of groups). Used to get and later store the cached data
302 /**
303 * @todo Define visibility
304 */
305 public $newHash = '';
306
307 // If config.ftu (Frontend Track User) is set in TypoScript for the current page, the string value of this var is substituted in the rendered source-code with the string, '&ftu=[token...]' which enables GET-method usertracking as opposed to cookie based
308 /**
309 * @todo Define visibility
310 */
311 public $getMethodUrlIdToken = '';
312
313 // This flag is set before inclusion of pagegen.php IF no_cache is set. If this flag is set after the inclusion of pagegen.php, no_cache is forced to be set. This is done in order to make sure that php-code from pagegen does not falsely clear the no_cache flag.
314 /**
315 * @todo Define visibility
316 */
317 public $no_CacheBeforePageGen = '';
318
319 // This flag indicates if temporary content went into the cache during page-generation.
320 /**
321 * @todo Define visibility
322 */
323 public $tempContent = FALSE;
324
325 // Boolean, passed to TypoScript template class and tells it to render the template forcibly
326 /**
327 * @todo Define visibility
328 */
329 public $forceTemplateParsing = '';
330
331 // The array which cHash_calc is based on, see ->makeCacheHash().
332 /**
333 * @todo Define visibility
334 */
335 public $cHash_array = array();
336
337 // Loaded with the serialized array that is used for generating a hashstring for the cache
338 /**
339 * @todo Define visibility
340 */
341 public $hash_base = '';
342
343 // May be set to the pagesTSconfig
344 /**
345 * @todo Define visibility
346 */
347 public $pagesTSconfig = '';
348
349 // PAGE-GENERATION / cOBJ
350 /*
351 Eg. insert JS-functions in this array ($additionalHeaderData) to include them once. Use associative keys.
352 Keys in use:
353 JSFormValidate : <script type="text/javascript" src="'.$GLOBALS["TSFE"]->absRefPrefix.'t3lib/jsfunc.validateform.js"></script>
354 JSincludeFormupdate : <script type="text/javascript" src="t3lib/jsfunc.updateform.js"></script>
355 JSMenuCode, JSMenuCode_menu : JavaScript for the JavaScript menu
356 JSCode : reserved
357 JSImgCode : reserved
358 */
359 // used to accumulate additional HTML-code for the header-section, <head>...</head>. Insert either associative keys (like additionalHeaderData['myStyleSheet'], see reserved keys above) or num-keys (like additionalHeaderData[] = '...')
360 /**
361 * @todo Define visibility
362 */
363 public $additionalHeaderData = array();
364
365 // used to accumulate additional HTML-code for the footer-section of the template
366 public $additionalFooterData = array();
367
368 // used to accumulate additional JavaScript-code. Works like additionalHeaderData. Reserved keys at 'openPic' and 'mouseOver'
369 /**
370 * @todo Define visibility
371 */
372 public $additionalJavaScript = array();
373
374 // used to accumulate additional Style code. Works like additionalHeaderData.
375 /**
376 * @todo Define visibility
377 */
378 public $additionalCSS = array();
379
380 // you can add JavaScript functions to each entry in these arrays. Please see how this is done in the GMENU_LAYERS script. The point is that many applications on a page can set handlers for onload, onmouseover and onmouseup
381 /**
382 * @todo Define visibility
383 */
384 public $JSeventFuncCalls = array(
385 'onmousemove' => array(),
386 'onmouseup' => array(),
387 'onkeydown' => array(),
388 'onkeyup' => array(),
389 'onkeypress' => array(),
390 'onload' => array(),
391 'onunload' => array()
392 );
393
394 // Used to accumulate JavaScript loaded images (by menus)
395 /**
396 * @todo Define visibility
397 */
398 public $JSImgCode = '';
399
400 // Used to accumulate DHTML-layers.
401 /**
402 * @todo Define visibility
403 */
404 public $divSection = '';
405
406 // Default bodytag, if nothing else is set. This can be overridden by applications like TemplaVoila.
407 /**
408 * @todo Define visibility
409 */
410 public $defaultBodyTag = '<body>';
411
412 // RENDERING configuration, settings from TypoScript is loaded into these vars. See pagegen.php
413 // Debug flag, may output special debug html-code.
414 /**
415 * @todo Define visibility
416 */
417 public $debug = '';
418
419 // Default internal target
420 /**
421 * @todo Define visibility
422 */
423 public $intTarget = '';
424
425 // Default external target
426 /**
427 * @todo Define visibility
428 */
429 public $extTarget = '';
430
431 // Default file link target
432 /**
433 * @todo Define visibility
434 */
435 public $fileTarget = '';
436
437 // Keys are page ids and values are default &MP (mount point) values to set when using the linking features...)
438 /**
439 * @todo Define visibility
440 */
441 public $MP_defaults = array();
442
443 // If set, typolink() function encrypts email addresses. Is set in pagegen-class.
444 /**
445 * @todo Define visibility
446 */
447 public $spamProtectEmailAddresses = 0;
448
449 // Absolute Reference prefix
450 /**
451 * @todo Define visibility
452 */
453 public $absRefPrefix = '';
454
455 // Absolute Reference prefix force flag. This is set, if the type and id is retrieve from PATH_INFO and thus we NEED to prefix urls with at least '/'
456 /**
457 * @todo Define visibility
458 */
459 public $absRefPrefix_force = 0;
460
461 // Factor for form-field widths compensation
462 /**
463 * @todo Define visibility
464 */
465 public $compensateFieldWidth = '';
466
467 // Lock file path
468 /**
469 * @todo Define visibility
470 */
471 public $lockFilePath = '';
472
473 // <A>-tag parameters
474 /**
475 * @todo Define visibility
476 */
477 public $ATagParams = '';
478
479 // Search word regex, calculated if there has been search-words send. This is used to mark up the found search words on a page when jumped to from a link in a search-result.
480 /**
481 * @todo Define visibility
482 */
483 public $sWordRegEx = '';
484
485 // Is set to the incoming array sword_list in case of a page-view jumped to from a search-result.
486 /**
487 * @todo Define visibility
488 */
489 public $sWordList = '';
490
491 // A string prepared for insertion in all links on the page as url-parameters. Based on configuration in TypoScript where you defined which GET_VARS you would like to pass on.
492 /**
493 * @todo Define visibility
494 */
495 public $linkVars = '';
496
497 // A string set with a comma list of additional GET vars which should NOT be included in the cHash calculation. These vars should otherwise be detected and involved in caching, eg. through a condition in TypoScript.
498 /**
499 * @todo Define visibility
500 */
501 public $excludeCHashVars = '';
502
503 // If set, edit icons are rendered aside content records. Must be set only if the ->beUserLogin flag is set and set_no_cache() must be called as well.
504 /**
505 * @todo Define visibility
506 */
507 public $displayEditIcons = '';
508
509 // If set, edit icons are rendered aside individual fields of content. Must be set only if the ->beUserLogin flag is set and set_no_cache() must be called as well.
510 /**
511 * @todo Define visibility
512 */
513 public $displayFieldEditIcons = '';
514
515 // Site language, 0 (zero) is default, int+ is uid pointing to a sys_language record. Should reflect which language menus, templates etc is displayed in (master language) - but not necessarily the content which could be falling back to default (see sys_language_content)
516 /**
517 * @todo Define visibility
518 */
519 public $sys_language_uid = 0;
520
521 // Site language mode for content fall back.
522 /**
523 * @todo Define visibility
524 */
525 public $sys_language_mode = '';
526
527 // Site content selection uid (can be different from sys_language_uid if content is to be selected from a fall-back language. Depends on sys_language_mode)
528 /**
529 * @todo Define visibility
530 */
531 public $sys_language_content = 0;
532
533 // Site content overlay flag; If set - and sys_language_content is > 0 - , records selected will try to look for a translation pointing to their uid. (If configured in [ctrl][languageField] / [ctrl][transOrigP...]
534 /**
535 * @todo Define visibility
536 */
537 public $sys_language_contentOL = 0;
538
539 // Is set to the iso code of the sys_language_content if that is properly defined by the sys_language record representing the sys_language_uid. (Requires the extension "static_info_tables")
540 /**
541 * @todo Define visibility
542 */
543 public $sys_language_isocode = '';
544
545 // RENDERING data
546 // 'Global' Storage for various applications. Keys should be 'tx_'.extKey for extensions.
547 /**
548 * @todo Define visibility
549 */
550 public $applicationData = array();
551
552 /**
553 * @todo Define visibility
554 */
555 public $register = array();
556
557 // Stack used for storing array and retrieving register arrays (see LOAD_REGISTER and RESTORE_REGISTER)
558 /**
559 * @todo Define visibility
560 */
561 public $registerStack = array();
562
563 // Checking that the function is not called eternally. This is done by interrupting at a depth of 50
564 /**
565 * @todo Define visibility
566 */
567 public $cObjectDepthCounter = 50;
568
569 // used by cObj->RECORDS and cObj->CONTENT to ensure the a records is NOT rendered twice through it!
570 /**
571 * @todo Define visibility
572 */
573 public $recordRegister = array();
574
575 // This is set to the [table]:[uid] of the latest record rendered. Note that class tslib_cObj has an equal value, but that is pointing to the record delivered in the $data-array of the tslib_cObj instance, if the cObjects CONTENT or RECORD created that instance
576 /**
577 * @todo Define visibility
578 */
579 public $currentRecord = '';
580
581 // Used by class tslib_menu to keep track of access-keys.
582 /**
583 * @todo Define visibility
584 */
585 public $accessKey = array();
586
587 // Numerical array where image filenames are added if they are referenced in the rendered document. This includes only TYPO3 generated/inserted images.
588 /**
589 * @todo Define visibility
590 */
591 public $imagesOnPage = array();
592
593 // Is set in tslib_cObj->cImage() function to the info-array of the most recent rendered image. The information is used in tslib_cObj->IMGTEXT
594 /**
595 * @todo Define visibility
596 */
597 public $lastImageInfo = array();
598
599 // Used to generate page-unique keys. Point is that uniqid() functions is very slow, so a unikey key is made based on this, see function uniqueHash()
600 /**
601 * @todo Define visibility
602 */
603 public $uniqueCounter = 0;
604
605 /**
606 * @todo Define visibility
607 */
608 public $uniqueString = '';
609
610 // This value will be used as the title for the page in the indexer (if indexing happens)
611 /**
612 * @todo Define visibility
613 */
614 public $indexedDocTitle = '';
615
616 // Alternative page title (normally the title of the page record). Can be set from applications you make.
617 /**
618 * @todo Define visibility
619 */
620 public $altPageTitle = '';
621
622 // The base URL set for the page header.
623 /**
624 * @todo Define visibility
625 */
626 public $baseUrl = '';
627
628 // The proper anchor prefix needed when using speaking urls. (only set if baseUrl is set)
629 /**
630 * @todo Define visibility
631 */
632 public $anchorPrefix = '';
633
634 /**
635 * Page content render object
636 *
637 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
638 * @todo Define visibility
639 */
640 public $cObj = '';
641
642 // CONTENT accumulation
643 // All page content is accumulated in this variable. See pagegen.php
644 /**
645 * @todo Define visibility
646 */
647 public $content = '';
648
649 // GENERAL
650 // Set to the browser: net / msie if 4+ browsers
651 /**
652 * @todo Define visibility
653 */
654 public $clientInfo = '';
655
656 /**
657 * @todo Define visibility
658 */
659 public $scriptParseTime = 0;
660
661 // Set ONLY if the full TCA is loaded
662 /**
663 * @todo Define visibility
664 */
665 public $TCAloaded = 0;
666
667 // Character set (charset) conversion object:
668 /**
669 * charset conversion class. May be used by any application.
670 *
671 * @var \TYPO3\CMS\Core\Charset\CharsetConverter
672 * @todo Define visibility
673 */
674 public $csConvObj;
675
676 // The default charset used in the frontend if nothing else is set.
677 /**
678 * @todo Define visibility
679 */
680 public $defaultCharSet = 'utf-8';
681
682 // Internal charset of the frontend during rendering. (Default: UTF-8)
683 /**
684 * @todo Define visibility
685 */
686 public $renderCharset = '';
687
688 // Output charset of the websites content. This is the charset found in the header, meta tag etc. If different from $renderCharset a conversion happens before output to browser. Defaults to ->renderCharset if not set.
689 /**
690 * @todo Define visibility
691 */
692 public $metaCharset = '';
693
694 // Assumed charset of locale strings.
695 /**
696 * @todo Define visibility
697 */
698 public $localeCharset = '';
699
700 // LANG:
701 // Set to the system language key (used on the site)
702 /**
703 * @todo Define visibility
704 */
705 public $lang = '';
706
707 /**
708 * @todo Define visibility
709 */
710 public $LL_labels_cache = array();
711
712 /**
713 * @todo Define visibility
714 */
715 public $LL_files_cache = array();
716
717 /**
718 * Locking object for accessing "cache_pagesection"
719 *
720 * @var \TYPO3\CMS\Core\Locking\Locker
721 * @todo Define visibility
722 */
723 public $pagesection_lockObj;
724
725 /**
726 * Locking object for accessing "cache_pages"
727 *
728 * @var \TYPO3\CMS\Core\Locking\Locker
729 * @todo Define visibility
730 */
731 public $pages_lockObj;
732
733 /**
734 * @var \TYPO3\CMS\Core\Page\PageRenderer
735 */
736 protected $pageRenderer;
737
738 /**
739 * the page cache object, use this to save pages to the cache and to
740 * retrieve them again
741 *
742 * @var t3lib_cache_AbstractBackend
743 */
744 protected $pageCache;
745
746 protected $pageCacheTags = array();
747
748 /**
749 * @var t3lib_cacheHash The cHash Service class used for cHash related functionality
750 */
751 protected $cacheHash;
752
753 /**
754 * Class constructor
755 * Takes a number of GET/POST input variable as arguments and stores them internally.
756 * The processing of these variables goes on later in this class.
757 * Also sets internal clientInfo array (browser information) and a unique string (->uniqueString) for this script instance; A md5 hash of the microtime()
758 *
759 * @param array $TYPO3_CONF_VARS The global $TYPO3_CONF_VARS array. Will be set internally in ->TYPO3_CONF_VARS
760 * @param mixed $id The value of t3lib_div::_GP('id')
761 * @param integer $type The value of t3lib_div::_GP('type')
762 * @param boolean $no_cache The value of t3lib_div::_GP('no_cache'), evaluated to 1/0
763 * @param string $cHash The value of t3lib_div::_GP('cHash')
764 * @param string $jumpurl The value of t3lib_div::_GP('jumpurl')
765 * @param string $MP The value of t3lib_div::_GP('MP')
766 * @param string $RDCT The value of t3lib_div::_GP('RDCT')
767 * @see index_ts.php
768 * @todo Define visibility
769 */
770 public function __construct($TYPO3_CONF_VARS, $id, $type, $no_cache = '', $cHash = '', $jumpurl = '', $MP = '', $RDCT = '') {
771 // Setting some variables:
772 $this->TYPO3_CONF_VARS = $TYPO3_CONF_VARS;
773 $this->id = $id;
774 $this->type = $type;
775 if ($no_cache) {
776 if ($this->TYPO3_CONF_VARS['FE']['disableNoCacheParameter']) {
777 $warning = '&no_cache=1 has been ignored because $TYPO3_CONF_VARS[\'FE\'][\'disableNoCacheParameter\'] is set!';
778 $GLOBALS['TT']->setTSlogMessage($warning, 2);
779 } else {
780 $warning = '&no_cache=1 has been supplied, so caching is disabled! URL: "' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '"';
781 $this->disableCache();
782 }
783 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($warning, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_WARNING);
784 }
785 $this->cHash = $cHash;
786 $this->jumpurl = $jumpurl;
787 $this->MP = $this->TYPO3_CONF_VARS['FE']['enable_mount_pids'] ? (string) $MP : '';
788 $this->RDCT = $RDCT;
789 $this->clientInfo = \TYPO3\CMS\Core\Utility\GeneralUtility::clientInfo();
790 $this->uniqueString = md5(microtime());
791 $this->csConvObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
792 // Call post processing function for constructor:
793 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'])) {
794 $_params = array('pObj' => &$this);
795 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'] as $_funcRef) {
796 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
797 }
798 }
799 $this->cacheHash = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator');
800 $this->initCaches();
801 }
802
803 /**
804 * Connect to SQL database. May exit after outputting an error message
805 * or some JavaScript redirecting to the install tool.
806 *
807 * @return void
808 */
809 public function connectToDB() {
810 try {
811 $GLOBALS['TYPO3_DB']->connectDB();
812 } catch (\RuntimeException $exception) {
813 switch ($exception->getCode()) {
814 case 1270853882:
815 // No database selected: Redirect to Install Tool 1-2-3 mode (fresh installation)
816 \TYPO3\CMS\Core\Utility\HttpUtility::redirect(TYPO3_mainDir . 'install/index.php?mode=123&step=1&password=joh316');
817 break;
818 case 1270853883:
819 // Cannot connect to current database
820 $message = 'Cannot connect to the configured database "' . TYPO3_db . '"';
821 if ($this->checkPageUnavailableHandler()) {
822 $this->pageUnavailableAndExit($message);
823 } else {
824 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
825 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message, 1301648782);
826 }
827 break;
828 case 1270853884:
829 // Username / password not accepted
830 $message = 'The current username, password or host was not accepted when' . ' the connection to the database was attempted to be established!';
831 if ($this->checkPageUnavailableHandler()) {
832 $this->pageUnavailableAndExit($message);
833 } else {
834 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
835 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException('Database Error: ' . $message, 1301648945);
836 }
837 break;
838 default:
839 throw $exception;
840 }
841 }
842 // Call post processing function for DB connection:
843 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'])) {
844 $_params = array('pObj' => &$this);
845 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'] as $_funcRef) {
846 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
847 }
848 }
849 }
850
851 /**
852 * Looks up the value of $this->RDCT in the database and if it is
853 * found to be associated with a redirect URL then the redirection
854 * is carried out with a 'Location:' header
855 * May exit after sending a location-header.
856 *
857 * @return void
858 */
859 public function sendRedirect() {
860 if ($this->RDCT) {
861 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('params', 'cache_md5params', 'md5hash=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->RDCT, 'cache_md5params'));
862 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
863 $this->updateMD5paramsRecord($this->RDCT);
864 header('Location: ' . $row['params']);
865 die;
866 }
867 }
868 }
869
870 /**
871 * Gets instance of PageRenderer
872 *
873 * @return \TYPO3\CMS\Core\Page\PageRenderer
874 */
875 public function getPageRenderer() {
876 if (!isset($this->pageRenderer)) {
877 $this->pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Page\\PageRenderer');
878 $this->pageRenderer->setTemplateFile(PATH_tslib . 'templates/tslib_page_frontend.html');
879 $this->pageRenderer->setBackPath(TYPO3_mainDir);
880 }
881 return $this->pageRenderer;
882 }
883
884 /**
885 * This is needed for USER_INT processing
886 *
887 * @param \TYPO3\CMS\Core\Page\PageRenderer $pageRenderer
888 */
889 protected function setPageRenderer(\TYPO3\CMS\Core\Page\PageRenderer $pageRenderer) {
890 $this->pageRenderer = $pageRenderer;
891 }
892
893 /********************************************
894 *
895 * Initializing, resolving page id
896 *
897 ********************************************/
898 /**
899 * Initializes the caching system.
900 *
901 * @return void
902 */
903 protected function initCaches() {
904 $this->pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
905 }
906
907 /**
908 * Initializes the front-end login user.
909 *
910 * @return void
911 * @todo Define visibility
912 */
913 public function initFEuser() {
914 $this->fe_user = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Authentication\\FrontendUserAuthtenication');
915 $this->fe_user->lockIP = $this->TYPO3_CONF_VARS['FE']['lockIP'];
916 $this->fe_user->checkPid = $this->TYPO3_CONF_VARS['FE']['checkFeUserPid'];
917 $this->fe_user->lifetime = intval($this->TYPO3_CONF_VARS['FE']['lifetime']);
918 // List of pid's acceptable
919 $this->fe_user->checkPid_value = $GLOBALS['TYPO3_DB']->cleanIntList(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pid'));
920 // Check if a session is transferred:
921 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('FE_SESSION_KEY')) {
922 $fe_sParts = explode('-', \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('FE_SESSION_KEY'));
923 // If the session key hash check is OK:
924 if (!strcmp(md5(($fe_sParts[0] . '/' . $this->TYPO3_CONF_VARS['SYS']['encryptionKey'])), $fe_sParts[1])) {
925 $cookieName = \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthtenication::getCookieName();
926 $_COOKIE[$cookieName] = $fe_sParts[0];
927 if (isset($_SERVER['HTTP_COOKIE'])) {
928 // See http://forge.typo3.org/issues/27740
929 $_SERVER['HTTP_COOKIE'] .= ';' . $cookieName . '=' . $fe_sParts[0];
930 }
931 $this->fe_user->forceSetCookie = 1;
932 unset($cookieName);
933 }
934 }
935 if ($this->TYPO3_CONF_VARS['FE']['dontSetCookie']) {
936 $this->fe_user->dontSetCookie = 1;
937 }
938 $this->fe_user->start();
939 $this->fe_user->unpack_uc('');
940 // Gets session data
941 $this->fe_user->fetchSessionData();
942 $recs = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('recs');
943 // If any record registration is submitted, register the record.
944 if (is_array($recs)) {
945 $this->fe_user->record_registration($recs, $this->TYPO3_CONF_VARS['FE']['maxSessionDataSize']);
946 }
947 // Call hook for possible manipulation of frontend user object
948 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'])) {
949 $_params = array('pObj' => &$this);
950 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'] as $_funcRef) {
951 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
952 }
953 }
954 // For every 60 seconds the is_online timestamp is updated.
955 if (is_array($this->fe_user->user) && $this->fe_user->user['uid'] && $this->fe_user->user['is_online'] < $GLOBALS['EXEC_TIME'] - 60) {
956 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid=' . intval($this->fe_user->user['uid']), array('is_online' => $GLOBALS['EXEC_TIME']));
957 }
958 }
959
960 /**
961 * Initializes the front-end user groups.
962 * Sets ->loginUser and ->gr_list based on front-end user status.
963 *
964 * @return void
965 * @todo Define visibility
966 */
967 public function initUserGroups() {
968 // This affects the hidden-flag selecting the fe_groups for the user!
969 $this->fe_user->showHiddenRecords = $this->showHiddenRecords;
970 // no matter if we have an active user we try to fetch matching groups which can be set without an user (simulation for instance!)
971 $this->fe_user->fetchGroupData();
972 if (is_array($this->fe_user->user) && count($this->fe_user->groupData['uid'])) {
973 // global flag!
974 $this->loginUser = 1;
975 // group -2 is not an existing group, but denotes a 'default' group when a user IS logged in. This is used to let elements be shown for all logged in users!
976 $this->gr_list = '0,-2';
977 $gr_array = $this->fe_user->groupData['uid'];
978 } else {
979 $this->loginUser = 0;
980 // group -1 is not an existing group, but denotes a 'default' group when not logged in. This is used to let elements be hidden, when a user is logged in!
981 $this->gr_list = '0,-1';
982 if ($this->loginAllowedInBranch) {
983 // For cases where logins are not banned from a branch usergroups can be set based on IP masks so we should add the usergroups uids.
984 $gr_array = $this->fe_user->groupData['uid'];
985 } else {
986 // Set to blank since we will NOT risk any groups being set when no logins are allowed!
987 $gr_array = array();
988 }
989 }
990 // Clean up.
991 // Make unique...
992 $gr_array = array_unique($gr_array);
993 // sort
994 sort($gr_array);
995 if (count($gr_array) && !$this->loginAllowedInBranch_mode) {
996 $this->gr_list .= ',' . implode(',', $gr_array);
997 }
998 if ($this->fe_user->writeDevLog) {
999 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Valid usergroups for TSFE: ' . $this->gr_list, 'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController');
1000 }
1001 }
1002
1003 /**
1004 * Checking if a user is logged in or a group constellation different from "0,-1"
1005 *
1006 * @return boolean TRUE if either a login user is found (array fe_user->user) OR if the gr_list is set to something else than '0,-1' (could be done even without a user being logged in!)
1007 * @todo Define visibility
1008 */
1009 public function isUserOrGroupSet() {
1010 return is_array($this->fe_user->user) || $this->gr_list !== '0,-1';
1011 }
1012
1013 /**
1014 * Provides ways to bypass the '?id=[xxx]&type=[xx]' format, using either PATH_INFO or virtual HTML-documents (using Apache mod_rewrite)
1015 *
1016 * Two options:
1017 * 1) Use PATH_INFO (also Apache) to extract id and type from that var. Does not require any special modules compiled with apache. (less typical)
1018 * 2) Using hook which enables features like those provided from "realurl" extension (AKA "Speaking URLs")
1019 *
1020 * @return void
1021 * @todo Define visibility
1022 */
1023 public function checkAlternativeIdMethods() {
1024 $this->siteScript = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_SCRIPT');
1025 // Call post processing function for custom URL methods.
1026 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'])) {
1027 $_params = array('pObj' => &$this);
1028 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'] as $_funcRef) {
1029 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1030 }
1031 }
1032 }
1033
1034 /**
1035 * Clears the preview-flags, sets sim_exec_time to current time.
1036 * Hidden pages must be hidden as default, $GLOBALS['SIM_EXEC_TIME'] is set to $GLOBALS['EXEC_TIME']
1037 * in bootstrap initializeGlobalTimeVariables(). Alter it by adding or subtracting seconds.
1038 *
1039 * @return void
1040 * @todo Define visibility
1041 */
1042 public function clear_preview() {
1043 $this->showHiddenPage = 0;
1044 $this->showHiddenRecords = 0;
1045 $GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
1046 $GLOBALS['SIM_ACCESS_TIME'] = $GLOBALS['ACCESS_TIME'];
1047 $this->fePreview = 0;
1048 }
1049
1050 /**
1051 * Checks if a backend user is logged in
1052 *
1053 * @return boolean whether a backend user is logged in
1054 */
1055 public function isBackendUserLoggedIn() {
1056 return $this->beUserLogin ? TRUE : FALSE;
1057 }
1058
1059 /**
1060 * Creates the backend user object and returns it.
1061 *
1062 * @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication the backend user object
1063 */
1064 public function initializeBackendUser() {
1065 // PRE BE_USER HOOK
1066 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'])) {
1067 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'] as $_funcRef) {
1068 $_params = array();
1069 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1070 }
1071 }
1072 /** @var $BE_USER \TYPO3\CMS\Backend\FrontendBackendUserAuthentication */
1073 $BE_USER = NULL;
1074 // If the backend cookie is set,
1075 // we proceed and check if a backend user is logged in.
1076 if ($_COOKIE[\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::getCookieName()]) {
1077 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'] = microtime(TRUE);
1078 $GLOBALS['TT']->push('Back End user initialized', '');
1079 // TODO: validate the comment below: is this necessary? if so,
1080 // formfield_status should be set to "" in t3lib_tsfeBeUserAuth
1081 // which is a subclass of t3lib_beUserAuth
1082 // ----
1083 // the value this->formfield_status is set to empty in order to
1084 // disable login-attempts to the backend account through this script
1085 // New backend user object
1086 $BE_USER = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\FrontendBackendUserAuthentication');
1087 $BE_USER->OS = TYPO3_OS;
1088 $BE_USER->lockIP = $this->TYPO3_CONF_VARS['BE']['lockIP'];
1089 // Object is initialized
1090 $BE_USER->start();
1091 $BE_USER->unpack_uc('');
1092 if ($BE_USER->user['uid']) {
1093 $BE_USER->fetchGroupData();
1094 $this->beUserLogin = 1;
1095 }
1096 // Unset the user initialization.
1097 if (!$BE_USER->checkLockToIP() || !$BE_USER->checkBackendAccessSettingsFromInitPhp() || !$BE_USER->user['uid']) {
1098 $BE_USER = NULL;
1099 $this->beUserLogin = 0;
1100 $_SESSION['TYPO3-TT-start'] = FALSE;
1101 }
1102 $GLOBALS['TT']->pull();
1103 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'] = microtime(TRUE);
1104 }
1105 // POST BE_USER HOOK
1106 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['postBeUser'])) {
1107 $_params = array(
1108 'BE_USER' => &$BE_USER
1109 );
1110 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['postBeUser'] as $_funcRef) {
1111 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1112 }
1113 }
1114 return $BE_USER;
1115 }
1116
1117 /**
1118 * Determines the id and evaluates any preview settings
1119 * Basically this function is about determining whether a backend user is logged in, if he has read access to the page and if he's previewing the page. That all determines which id to show and how to initialize the id.
1120 *
1121 * @return void
1122 * @todo Define visibility
1123 */
1124 public function determineId() {
1125 // Call pre processing function for id determination
1126 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PreProcessing'])) {
1127 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PreProcessing'] as $functionReference) {
1128 $parameters = array('parentObject' => $this);
1129 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($functionReference, $parameters, $this);
1130 }
1131 }
1132 // Getting ARG-v values if some
1133 $this->setIDfromArgV();
1134 // If there is a Backend login we are going to check for any preview settings:
1135 $GLOBALS['TT']->push('beUserLogin', '');
1136 if ($this->beUserLogin || $this->doWorkspacePreview()) {
1137 // Backend user preview features:
1138 if ($this->beUserLogin && $GLOBALS['BE_USER']->adminPanel instanceof \TYPO3\CMS\Frontend\View\AdminPanelView) {
1139 $this->fePreview = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview') ? TRUE : FALSE;
1140 // If admin panel preview is enabled...
1141 if ($this->fePreview) {
1142 $fe_user_OLD_USERGROUP = $this->fe_user->user['usergroup'];
1143 $this->showHiddenPage = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'showHiddenPages');
1144 $this->showHiddenRecords = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'showHiddenRecords');
1145 // Simulate date
1146 $simTime = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'simulateDate');
1147 if ($simTime) {
1148 $GLOBALS['SIM_EXEC_TIME'] = $simTime;
1149 $GLOBALS['SIM_ACCESS_TIME'] = $simTime - $simTime % 60;
1150 }
1151 // simulate user
1152 $simUserGroup = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'simulateUserGroup');
1153 $this->simUserGroup = $simUserGroup;
1154 if ($simUserGroup) {
1155 $this->fe_user->user['usergroup'] = $simUserGroup;
1156 }
1157 if (!$simUserGroup && !$simTime && !$this->showHiddenPage && !$this->showHiddenRecords) {
1158 $this->fePreview = 0;
1159 }
1160 }
1161 }
1162 if ($this->id) {
1163 if ($this->determineIdIsHiddenPage()) {
1164 // The preview flag is set only if the current page turns out to actually be hidden!
1165 $this->fePreview = 1;
1166 $this->showHiddenPage = 1;
1167 }
1168 // For Live workspace: Check root line for proper connection to tree root (done because of possible preview of page / branch versions)
1169 if (!$this->fePreview && $this->whichWorkspace() === 0) {
1170 // Initialize the page-select functions to check rootline:
1171 $temp_sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
1172 $temp_sys_page->init($this->showHiddenPage);
1173 // If root line contained NO records and ->error_getRootLine_failPid tells us that it was because of a pid=-1 (indicating a "version" record)...:
1174 if (!count($temp_sys_page->getRootLine($this->id, $this->MP)) && $temp_sys_page->error_getRootLine_failPid == -1) {
1175 // Setting versioningPreview flag and try again:
1176 $temp_sys_page->versioningPreview = TRUE;
1177 if (count($temp_sys_page->getRootLine($this->id, $this->MP))) {
1178 // Finally, we got a root line (meaning that it WAS due to versioning preview of a page somewhere) and we set the fePreview flag which in itself will allow sys_page class to display previews of versionized records.
1179 $this->fePreview = 1;
1180 }
1181 }
1182 }
1183 }
1184 // The preview flag will be set if a backend user is in an offline workspace
1185 if (($GLOBALS['BE_USER']->user['workspace_preview'] || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_view') || $this->doWorkspacePreview()) && ($this->whichWorkspace() === -1 || $this->whichWorkspace() > 0)) {
1186 // Will show special preview message.
1187 $this->fePreview = 2;
1188 }
1189 // If the front-end is showing a preview, caching MUST be disabled.
1190 if ($this->fePreview) {
1191 $this->disableCache();
1192 }
1193 }
1194 $GLOBALS['TT']->pull();
1195 // Now, get the id, validate access etc:
1196 $this->fetch_the_id();
1197 // Check if backend user has read access to this page. If not, recalculate the id.
1198 if ($this->beUserLogin && $this->fePreview) {
1199 if (!$GLOBALS['BE_USER']->doesUserHaveAccess($this->page, 1)) {
1200 // Resetting
1201 $this->clear_preview();
1202 $this->fe_user->user['usergroup'] = $fe_user_OLD_USERGROUP;
1203 // Fetching the id again, now with the preview settings reset.
1204 $this->fetch_the_id();
1205 }
1206 }
1207 // Checks if user logins are blocked for a certain branch and if so, will unset user login and re-fetch ID.
1208 $this->loginAllowedInBranch = $this->checkIfLoginAllowedInBranch();
1209 // Logins are not allowed:
1210 if (!$this->loginAllowedInBranch) {
1211 // Only if there is a login will we run this...
1212 if ($this->isUserOrGroupSet()) {
1213 if ($this->loginAllowedInBranch_mode == 'all') {
1214 // Clear out user and group:
1215 unset($this->fe_user->user);
1216 $this->gr_list = '0,-1';
1217 } else {
1218 $this->gr_list = '0,-2';
1219 }
1220 // Fetching the id again, now with the preview settings reset.
1221 $this->fetch_the_id();
1222 }
1223 }
1224 // Final cleaning.
1225 // Make sure it's an integer
1226 $this->id = ($this->contentPid = intval($this->id));
1227 // Make sure it's an integer
1228 $this->type = intval($this->type);
1229 // Call post processing function for id determination:
1230 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'])) {
1231 $_params = array('pObj' => &$this);
1232 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'] as $_funcRef) {
1233 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1234 }
1235 }
1236 }
1237
1238 /**
1239 * Checks if the page is hidden in the active workspace.
1240 * If it is hidden, preview flags will be set.
1241 *
1242 * @return boolean
1243 */
1244 protected function determineIdIsHiddenPage() {
1245 $field = \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->id) ? 'uid' : 'alias';
1246 $pageSelectCondition = $field . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, 'pages');
1247 $page = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid,hidden,starttime,endtime', 'pages', $pageSelectCondition . ' AND pid>=0 AND deleted=0');
1248 $workspace = $this->whichWorkspace();
1249 if ($workspace !== 0 && $workspace !== FALSE) {
1250 // Fetch overlay of page if in workspace and check if it is hidden
1251 $pageSelectObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
1252 $pageSelectObject->versioningPreview = TRUE;
1253 $pageSelectObject->init(FALSE);
1254 $targetPage = $pageSelectObject->getWorkspaceVersionOfRecord($this->whichWorkspace(), 'pages', $page['uid']);
1255 $result = $targetPage === -1 || $targetPage === -2;
1256 } else {
1257 $result = is_array($page) && ($page['hidden'] || $page['starttime'] > $GLOBALS['SIM_EXEC_TIME'] || $page['endtime'] != 0 && $page['endtime'] <= $GLOBALS['SIM_EXEC_TIME']);
1258 }
1259 return $result;
1260 }
1261
1262 /**
1263 * Get The Page ID
1264 * This gets the id of the page, checks if the page is in the domain and if the page is accessible
1265 * Sets variables such as $this->sys_page, $this->loginUser, $this->gr_list, $this->id, $this->type, $this->domainStartPage, $this->idParts
1266 *
1267 * @return void
1268 * @access private
1269 * @todo Define visibility
1270 */
1271 public function fetch_the_id() {
1272 $GLOBALS['TT']->push('fetch_the_id initialize/', '');
1273 // Initialize the page-select functions.
1274 $this->sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
1275 $this->sys_page->versioningPreview = $this->fePreview === 2 || intval($this->workspacePreview) || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_view') ? TRUE : FALSE;
1276 $this->sys_page->versioningWorkspaceId = $this->whichWorkspace();
1277 $this->sys_page->init($this->showHiddenPage);
1278 // Set the valid usergroups for FE
1279 $this->initUserGroups();
1280 // Sets sys_page where-clause
1281 $this->setSysPageWhereClause();
1282 // Splitting $this->id by a period (.).
1283 // First part is 'id' and second part (if exists) will overrule the &type param
1284 $idParts = explode('.', $this->id, 2);
1285 $this->id = $idParts[0];
1286 if (isset($idParts[1])) {
1287 $this->type = $idParts[1];
1288 }
1289 // Splitting $this->id by a comma (,).
1290 // First part is 'id' and other parts are just stored for use in scripts.
1291 // Still used in the old wapversion.lib files.
1292 $this->idParts = explode(',', $this->id);
1293 $this->id = $this->idParts[0];
1294
1295 // Hook for further id manipulation
1296 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['modifyPageId'])) {
1297 $_params = array('id' => $this->id);
1298 $newId = FALSE;
1299 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['modifyPageId'] as $_funcRef) {
1300 $deprecationMessage = 'Hook $TYPO3_CONF_VARS[SC_OPTIONS][tslib/class.tslib_fe.php][modifyPageId] is ' .
1301 'deprecated since 6.0 and will be removed two versions later';
1302 if (!is_object($_funcRef) || !is_a($_funcRef, 'Closure')) {
1303 $deprecationMessage .= '- used by ' . $_funcRef;
1304 }
1305 \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog($deprecationMessage);
1306 $newIdFromFunc = \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1307 if ($newIdFromFunc !== FALSE) {
1308 $newId = $newIdFromFunc;
1309 }
1310 }
1311 if ($newId !== FALSE) {
1312 $this->id = $newId;
1313 }
1314 }
1315
1316 // If $this->id is a string, it's an alias
1317 $this->checkAndSetAlias();
1318 // The id and type is set to the integer-value - just to be sure...
1319 $this->id = intval($this->id);
1320 $this->type = intval($this->type);
1321 $GLOBALS['TT']->pull();
1322 // We find the first page belonging to the current domain
1323 $GLOBALS['TT']->push('fetch_the_id domain/', '');
1324 // The page_id of the current domain
1325 $this->domainStartPage = $this->findDomainRecord($this->TYPO3_CONF_VARS['SYS']['recursiveDomainSearch']);
1326 if (!$this->id) {
1327 if ($this->domainStartPage) {
1328 // If the id was not previously set, set it to the id of the domain.
1329 $this->id = $this->domainStartPage;
1330 } else {
1331 // Find the first 'visible' page in that domain
1332 $theFirstPage = $this->sys_page->getFirstWebPage($this->id);
1333 if ($theFirstPage) {
1334 $this->id = $theFirstPage['uid'];
1335 } else {
1336 $message = 'No pages are found on the rootlevel!';
1337 if ($this->checkPageUnavailableHandler()) {
1338 $this->pageUnavailableAndExit($message);
1339 } else {
1340 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1341 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message, 1301648975);
1342 }
1343 }
1344 }
1345 }
1346 $GLOBALS['TT']->pull();
1347 $GLOBALS['TT']->push('fetch_the_id rootLine/', '');
1348 // We store the originally requested id
1349 $requestedId = $this->id;
1350 $this->getPageAndRootlineWithDomain($this->domainStartPage);
1351 $GLOBALS['TT']->pull();
1352 if ($this->pageNotFound && $this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
1353 $pNotFoundMsg = array(
1354 1 => 'ID was not an accessible page',
1355 2 => 'Subsection was found and not accessible',
1356 3 => 'ID was outside the domain',
1357 4 => 'The requested page alias does not exist'
1358 );
1359 $this->pageNotFoundAndExit($pNotFoundMsg[$this->pageNotFound]);
1360 }
1361 if ($this->page['url_scheme'] > 0) {
1362 $newUrl = '';
1363 $requestUrlScheme = parse_url(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), PHP_URL_SCHEME);
1364 if ((int) $this->page['url_scheme'] === \t3lib_utility_http::SCHEME_HTTP && $requestUrlScheme == 'https') {
1365 $newUrl = 'http://' . substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 8);
1366 } elseif ((int) $this->page['url_scheme'] === \t3lib_utility_http::SCHEME_HTTPS && $requestUrlScheme == 'http') {
1367 $newUrl = 'https://' . substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 7);
1368 }
1369 if ($newUrl !== '') {
1370 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
1371 $headerCode = \TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_303;
1372 } else {
1373 $headerCode = \TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_301;
1374 }
1375 \t3lib_utility_http::redirect($newUrl, $headerCode);
1376 }
1377 }
1378 // Set no_cache if set
1379 if ($this->page['no_cache']) {
1380 $this->set_no_cache();
1381 }
1382 // Init SYS_LASTCHANGED
1383 $this->register['SYS_LASTCHANGED'] = intval($this->page['tstamp']);
1384 if ($this->register['SYS_LASTCHANGED'] < intval($this->page['SYS_LASTCHANGED'])) {
1385 $this->register['SYS_LASTCHANGED'] = intval($this->page['SYS_LASTCHANGED']);
1386 }
1387 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['fetchPageId-PostProcessing'])) {
1388 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['fetchPageId-PostProcessing'] as $functionReference) {
1389 $parameters = array('parentObject' => $this);
1390 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($functionReference, $parameters, $this);
1391 }
1392 }
1393 }
1394
1395 /**
1396 * Gets the page and rootline arrays based on the id, $this->id
1397 *
1398 * If the id does not correspond to a proper page, the 'previous' valid page in the rootline is found
1399 * If the page is a shortcut (doktype=4), the ->id is loaded with that id
1400 *
1401 * Whether or not the ->id is changed to the shortcut id or the previous id in rootline (eg if a page is hidden), the ->page-array and ->rootline is found and must also be valid.
1402 *
1403 * Sets or manipulates internal variables such as: $this->id, $this->page, $this->rootLine, $this->MP, $this->pageNotFound
1404 *
1405 * @return void
1406 * @access private
1407 * @todo Define visibility
1408 */
1409 public function getPageAndRootline() {
1410 $this->page = $this->sys_page->getPage($this->id);
1411 if (!count($this->page)) {
1412 // If no page, we try to find the page before in the rootLine.
1413 // Page is 'not found' in case the id itself was not an accessible page. code 1
1414 $this->pageNotFound = 1;
1415 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1416 if (count($this->rootLine)) {
1417 $c = count($this->rootLine) - 1;
1418 while ($c > 0) {
1419 // Add to page access failure history:
1420 $this->pageAccessFailureHistory['direct_access'][] = $this->rootLine[$c];
1421 // Decrease to next page in rootline and check the access to that, if OK, set as page record and ID value.
1422 $c--;
1423 $this->id = $this->rootLine[$c]['uid'];
1424 $this->page = $this->sys_page->getPage($this->id);
1425 if (count($this->page)) {
1426 break;
1427 }
1428 }
1429 }
1430 // If still no page...
1431 if (!count($this->page)) {
1432 $message = 'The requested page does not exist!';
1433 if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
1434 $this->pageNotFoundAndExit($message);
1435 } else {
1436 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1437 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648780);
1438 }
1439 }
1440 }
1441 // Spacer is not accessible in frontend
1442 if ($this->page['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SPACER) {
1443 $message = 'The requested page does not exist!';
1444 if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
1445 $this->pageNotFoundAndExit($message);
1446 } else {
1447 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1448 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648781);
1449 }
1450 }
1451 // Is the ID a link to another page??
1452 if ($this->page['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) {
1453 // We need to clear MP if the page is a shortcut. Reason is if the short cut goes to another page, then we LEAVE the rootline which the MP expects.
1454 $this->MP = '';
1455 // saving the page so that we can check later - when we know
1456 // about languages - whether we took the correct shortcut or
1457 // whether a translation of the page overwrites the shortcut
1458 // target and we need to follow the new target
1459 $this->originalShortcutPage = $this->page;
1460 $this->page = $this->getPageShortcut($this->page['shortcut'], $this->page['shortcut_mode'], $this->page['uid']);
1461 $this->id = $this->page['uid'];
1462 }
1463 // Gets the rootLine
1464 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1465 // If not rootline we're off...
1466 if (!count($this->rootLine)) {
1467 $ws = $this->whichWorkspace();
1468 if ($this->sys_page->error_getRootLine_failPid == -1 && $ws) {
1469 $this->sys_page->versioningPreview = TRUE;
1470 $this->versioningWorkspaceId = $ws;
1471 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1472 }
1473 if (!count($this->rootLine)) {
1474 $message = 'The requested page didn\'t have a proper connection to the tree-root!';
1475 if ($this->checkPageUnavailableHandler()) {
1476 $this->pageUnavailableAndExit($message);
1477 } else {
1478 $rootline = '(' . $this->sys_page->error_getRootLine . ')';
1479 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1480 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message . '<br /><br />' . $rootline, 1301648167);
1481 }
1482 }
1483 $this->fePreview = 1;
1484 }
1485 // Checking for include section regarding the hidden/starttime/endtime/fe_user (that is access control of a whole subbranch!)
1486 if ($this->checkRootlineForIncludeSection()) {
1487 if (!count($this->rootLine)) {
1488 $message = 'The requested page was not accessible!';
1489 if ($this->checkPageUnavailableHandler()) {
1490 $this->pageUnavailableAndExit($message);
1491 } else {
1492 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1493 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message, 1301648234);
1494 }
1495 } else {
1496 $el = reset($this->rootLine);
1497 $this->id = $el['uid'];
1498 $this->page = $this->sys_page->getPage($this->id);
1499 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1500 }
1501 }
1502 }
1503
1504 /**
1505 * Get page shortcut; Finds the records pointed to by input value $SC (the shortcut value)
1506 *
1507 * @param integer $SC The value of the "shortcut" field from the pages record
1508 * @param integer $mode The shortcut mode: 1 will select first subpage, 2 a random subpage, 3 the parent page; default is the page pointed to by $SC
1509 * @param integer $thisUid The current page UID of the page which is a shortcut
1510 * @param integer $itera Safety feature which makes sure that the function is calling itself recursively max 20 times (since this function can find shortcuts to other shortcuts to other shortcuts...)
1511 * @param array $pageLog An array filled with previous page uids tested by the function - new page uids are evaluated against this to avoid going in circles.
1512 * @return mixed Returns the page record of the page that the shortcut pointed to.
1513 * @access private
1514 * @see getPageAndRootline()
1515 * @todo Define visibility
1516 */
1517 public function getPageShortcut($SC, $mode, $thisUid, $itera = 20, $pageLog = array()) {
1518 $idArray = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $SC);
1519 // Find $page record depending on shortcut mode:
1520 switch ($mode) {
1521 case \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
1522
1523 case \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE:
1524 $pageArray = $this->sys_page->getMenu($idArray[0] ? $idArray[0] : $thisUid, '*', 'sorting', 'AND pages.doktype<199 AND pages.doktype!=' . \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_BE_USER_SECTION);
1525 $pO = 0;
1526 if ($mode == \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE && count($pageArray)) {
1527 $randval = intval(rand(0, count($pageArray) - 1));
1528 $pO = $randval;
1529 }
1530 $c = 0;
1531 foreach ($pageArray as $pV) {
1532 if ($c == $pO) {
1533 $page = $pV;
1534 break;
1535 }
1536 $c++;
1537 }
1538 if (count($page) == 0) {
1539 $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to a subpage. ' . 'However, this page has no accessible subpages.';
1540 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648328);
1541 }
1542 break;
1543 case \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_PARENT_PAGE:
1544 $parent = $this->sys_page->getPage($thisUid);
1545 $page = $this->sys_page->getPage($parent['pid']);
1546 if (count($page) == 0) {
1547 $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to its parent page. ' . 'However, the parent page is not accessible.';
1548 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648358);
1549 }
1550 break;
1551 default:
1552 $page = $this->sys_page->getPage($idArray[0]);
1553 if (count($page) == 0) {
1554 $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to a page, which is not accessible (ID ' . $idArray[0] . ').';
1555 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648404);
1556 }
1557 break;
1558 }
1559 // Check if short cut page was a shortcut itself, if so look up recursively:
1560 if ($page['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) {
1561 if (!in_array($page['uid'], $pageLog) && $itera > 0) {
1562 $pageLog[] = $page['uid'];
1563 $page = $this->getPageShortcut($page['shortcut'], $page['shortcut_mode'], $page['uid'], $itera - 1, $pageLog);
1564 } else {
1565 $pageLog[] = $page['uid'];
1566 $message = 'Page shortcuts were looping in uids ' . implode(',', $pageLog) . '...!';
1567 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1568 throw new \RuntimeException($message, 1294587212);
1569 }
1570 }
1571 // Return resulting page:
1572 return $page;
1573 }
1574
1575 /**
1576 * Checks the current rootline for defined sections.
1577 *
1578 * @return boolean
1579 * @access private
1580 * @todo Define visibility
1581 */
1582 public function checkRootlineForIncludeSection() {
1583 $c = count($this->rootLine);
1584 $removeTheRestFlag = 0;
1585 for ($a = 0; $a < $c; $a++) {
1586 if (!$this->checkPagerecordForIncludeSection($this->rootLine[$a])) {
1587 // Add to page access failure history:
1588 $this->pageAccessFailureHistory['sub_section'][] = $this->rootLine[$a];
1589 $removeTheRestFlag = 1;
1590 }
1591 if ($this->rootLine[$a]['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_BE_USER_SECTION) {
1592 // If there is a backend user logged in, check if he has read access to the page:
1593 if ($this->beUserLogin) {
1594 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'uid=' . intval($this->id) . ' AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1));
1595 // versionOL()?
1596 list($isPage) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
1597 if (!$isPage) {
1598 // If there was no page selected, the user apparently did not have read access to the current PAGE (not position in rootline) and we set the remove-flag...
1599 $removeTheRestFlag = 1;
1600 }
1601 } else {
1602 // Dont go here, if there is no backend user logged in.
1603 $removeTheRestFlag = 1;
1604 }
1605 }
1606 if ($removeTheRestFlag) {
1607 // Page is 'not found' in case a subsection was found and not accessible, code 2
1608 $this->pageNotFound = 2;
1609 unset($this->rootLine[$a]);
1610 }
1611 }
1612 return $removeTheRestFlag;
1613 }
1614
1615 /**
1616 * Checks page record for enableFields
1617 * Returns TRUE if enableFields does not disable the page record.
1618 * Takes notice of the ->showHiddenPage flag and uses SIM_ACCESS_TIME for start/endtime evaluation
1619 *
1620 * @param array $row The page record to evaluate (needs fields: hidden, starttime, endtime, fe_group)
1621 * @param boolean $bypassGroupCheck Bypass group-check
1622 * @return boolean TRUE, if record is viewable.
1623 * @see tslib_cObj::getTreeList(), checkPagerecordForIncludeSection()
1624 * @todo Define visibility
1625 */
1626 public function checkEnableFields($row, $bypassGroupCheck = FALSE) {
1627 if ((!$row['hidden'] || $this->showHiddenPage) && $row['starttime'] <= $GLOBALS['SIM_ACCESS_TIME'] && ($row['endtime'] == 0 || $row['endtime'] > $GLOBALS['SIM_ACCESS_TIME']) && ($bypassGroupCheck || $this->checkPageGroupAccess($row))) {
1628 return TRUE;
1629 }
1630 }
1631
1632 /**
1633 * Check group access against a page record
1634 *
1635 * @param array $row The page record to evaluate (needs field: fe_group)
1636 * @param mixed $groupList List of group id's (comma list or array). Default is $this->gr_list
1637 * @return boolean TRUE, if group access is granted.
1638 * @access private
1639 * @todo Define visibility
1640 */
1641 public function checkPageGroupAccess($row, $groupList = NULL) {
1642 if (is_null($groupList)) {
1643 $groupList = $this->gr_list;
1644 }
1645 if (!is_array($groupList)) {
1646 $groupList = explode(',', $groupList);
1647 }
1648 $pageGroupList = explode(',', $row['fe_group'] ? $row['fe_group'] : 0);
1649 return count(array_intersect($groupList, $pageGroupList)) > 0;
1650 }
1651
1652 /**
1653 * Checks page record for include section
1654 *
1655 * @param array $row The page record to evaluate (needs fields: extendToSubpages + hidden, starttime, endtime, fe_group)
1656 * @return boolean Returns TRUE if either extendToSubpages is not checked or if the enableFields does not disable the page record.
1657 * @access private
1658 * @see checkEnableFields(), tslib_cObj::getTreeList(), checkRootlineForIncludeSection()
1659 * @todo Define visibility
1660 */
1661 public function checkPagerecordForIncludeSection($row) {
1662 return !$row['extendToSubpages'] || $this->checkEnableFields($row) ? 1 : 0;
1663 }
1664
1665 /**
1666 * Checks if logins are allowed in the current branch of the page tree. Traverses the full root line and returns TRUE if logins are OK, otherwise FALSE (and then the login user must be unset!)
1667 *
1668 * @return boolean returns TRUE if logins are OK, otherwise FALSE (and then the login user must be unset!)
1669 * @todo Define visibility
1670 */
1671 public function checkIfLoginAllowedInBranch() {
1672 // Initialize:
1673 $c = count($this->rootLine);
1674 $disable = FALSE;
1675 // Traverse root line from root and outwards:
1676 for ($a = 0; $a < $c; $a++) {
1677 // If a value is set for login state:
1678 if ($this->rootLine[$a]['fe_login_mode'] > 0) {
1679 // Determine state from value:
1680 if ((int) $this->rootLine[$a]['fe_login_mode'] === 1) {
1681 $disable = TRUE;
1682 $this->loginAllowedInBranch_mode = 'all';
1683 } elseif ((int) $this->rootLine[$a]['fe_login_mode'] === 3) {
1684 $disable = TRUE;
1685 $this->loginAllowedInBranch_mode = 'groups';
1686 } else {
1687 $disable = FALSE;
1688 }
1689 }
1690 }
1691 return !$disable;
1692 }
1693
1694 /**
1695 * Analysing $this->pageAccessFailureHistory into a summary array telling which features disabled display and on which pages and conditions. That data can be used inside a page-not-found handler
1696 *
1697 * @return array Summary of why page access was not allowed.
1698 * @todo Define visibility
1699 */
1700 public function getPageAccessFailureReasons() {
1701 $output = array();
1702 $combinedRecords = array_merge(is_array($this->pageAccessFailureHistory['direct_access']) ? $this->pageAccessFailureHistory['direct_access'] : array(array('fe_group' => 0)), is_array($this->pageAccessFailureHistory['sub_section']) ? $this->pageAccessFailureHistory['sub_section'] : array());
1703 if (count($combinedRecords)) {
1704 foreach ($combinedRecords as $k => $pagerec) {
1705 // If $k=0 then it is the very first page the original ID was pointing at and that will get a full check of course
1706 // If $k>0 it is parent pages being tested. They are only significant for the access to the first page IF they had the extendToSubpages flag set, hence checked only then!
1707 if (!$k || $pagerec['extendToSubpages']) {
1708 if ($pagerec['hidden']) {
1709 $output['hidden'][$pagerec['uid']] = TRUE;
1710 }
1711 if ($pagerec['starttime'] > $GLOBALS['SIM_ACCESS_TIME']) {
1712 $output['starttime'][$pagerec['uid']] = $pagerec['starttime'];
1713 }
1714 if ($pagerec['endtime'] != 0 && $pagerec['endtime'] <= $GLOBALS['SIM_ACCESS_TIME']) {
1715 $output['endtime'][$pagerec['uid']] = $pagerec['endtime'];
1716 }
1717 if (!$this->checkPageGroupAccess($pagerec)) {
1718 $output['fe_group'][$pagerec['uid']] = $pagerec['fe_group'];
1719 }
1720 }
1721 }
1722 }
1723 return $output;
1724 }
1725
1726 /**
1727 * This checks if there are ARGV-parameters in the QUERY_STRING and if so, those are used for the id
1728 * $this->id must be 'FALSE' in order for any processing to happen in here
1729 * If an id/alias value is extracted from the QUERY_STRING it is set in $this->id
1730 *
1731 * @return void
1732 * @access private
1733 * @todo Define visibility
1734 */
1735 public function setIDfromArgV() {
1736 if (!$this->id) {
1737 list($theAlias) = explode('&', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('QUERY_STRING'));
1738 $theAlias = trim($theAlias);
1739 $this->id = $theAlias != '' && strpos($theAlias, '=') === FALSE ? $theAlias : 0;
1740 }
1741 }
1742
1743 /**
1744 * Gets ->page and ->rootline information based on ->id. ->id may change during this operation.
1745 * If not inside domain, then default to first page in domain.
1746 *
1747 * @param integer $domainStartPage Page uid of the page where the found domain record is (pid of the domain record)
1748 * @return void
1749 * @access private
1750 * @todo Define visibility
1751 */
1752 public function getPageAndRootlineWithDomain($domainStartPage) {
1753 $this->getPageAndRootline();
1754 // Checks if the $domain-startpage is in the rootLine. This is necessary so that references to page-id's from other domains are not possible.
1755 if ($domainStartPage && is_array($this->rootLine)) {
1756 $idFound = 0;
1757 foreach ($this->rootLine as $key => $val) {
1758 if ($val['uid'] == $domainStartPage) {
1759 $idFound = 1;
1760 break;
1761 }
1762 }
1763 if (!$idFound) {
1764 // Page is 'not found' in case the id was outside the domain, code 3
1765 $this->pageNotFound = 3;
1766 $this->id = $domainStartPage;
1767 // re-get the page and rootline if the id was not found.
1768 $this->getPageAndRootline();
1769 }
1770 }
1771 }
1772
1773 /**
1774 * Sets sys_page where-clause
1775 *
1776 * @return void
1777 * @access private
1778 * @todo Define visibility
1779 */
1780 public function setSysPageWhereClause() {
1781 $this->sys_page->where_hid_del .= ' AND pages.doktype<200';
1782 $this->sys_page->where_groupAccess = $this->sys_page->getMultipleGroupsWhereClause('pages.fe_group', 'pages');
1783 }
1784
1785 /**
1786 * Looking up a domain record based on HTTP_HOST
1787 *
1788 * @param boolean $recursive If set, it looks "recursively" meaning that a domain like "123.456.typo3.com" would find a domain record like "typo3.com" if "123.456.typo3.com" or "456.typo3.com" did not exist.
1789 * @return integer Returns the page id of the page where the domain record was found.
1790 * @access private
1791 * @todo Define visibility
1792 */
1793 public function findDomainRecord($recursive = 0) {
1794 if ($recursive) {
1795 $host = explode('.', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST'));
1796 while (count($host)) {
1797 $pageUid = $this->sys_page->getDomainStartPage(implode('.', $host), \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_NAME'), \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'));
1798 if ($pageUid) {
1799 return $pageUid;
1800 } else {
1801 array_shift($host);
1802 }
1803 }
1804 return $pageUid;
1805 } else {
1806 return $this->sys_page->getDomainStartPage(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST'), \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_NAME'), \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'));
1807 }
1808 }
1809
1810 /**
1811 * Page unavailable handler for use in frontend plugins from extensions.
1812 *
1813 * @param string $reason Reason text
1814 * @param string $header HTTP header to send
1815 * @return void Function exits.
1816 * @todo Define visibility
1817 */
1818 public function pageUnavailableAndExit($reason = '', $header = '') {
1819 $header = $header ? $header : $this->TYPO3_CONF_VARS['FE']['pageUnavailable_handling_statheader'];
1820 $this->pageUnavailableHandler($this->TYPO3_CONF_VARS['FE']['pageUnavailable_handling'], $header, $reason);
1821 die;
1822 }
1823
1824 /**
1825 * Page-not-found handler for use in frontend plugins from extensions.
1826 *
1827 * @param string $reason Reason text
1828 * @param string $header HTTP header to send
1829 * @return void Function exits.
1830 * @todo Define visibility
1831 */
1832 public function pageNotFoundAndExit($reason = '', $header = '') {
1833 $header = $header ? $header : $this->TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'];
1834 $this->pageNotFoundHandler($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling'], $header, $reason);
1835 die;
1836 }
1837
1838 /**
1839 * Checks whether the pageUnavailableHandler should be used. To be used, pageUnavailable_handling must be set
1840 * and devIPMask must not match the current visitor's IP address.
1841 *
1842 * @return boolean TRUE/FALSE whether the pageUnavailable_handler should be used.
1843 * @todo Define visibility
1844 */
1845 public function checkPageUnavailableHandler() {
1846 if ($this->TYPO3_CONF_VARS['FE']['pageUnavailable_handling'] && !\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $this->TYPO3_CONF_VARS['SYS']['devIPmask'])) {
1847 $checkPageUnavailableHandler = TRUE;
1848 } else {
1849 $checkPageUnavailableHandler = FALSE;
1850 }
1851 return $checkPageUnavailableHandler;
1852 }
1853
1854 /**
1855 * Page unavailable handler. Acts a wrapper for the pageErrorHandler method.
1856 *
1857 * @param mixed $code Which type of handling; If a true PHP-boolean or TRUE then a ->t3lib_message_ErrorPageMessage is outputted. If integer an error message with that number is shown. Otherwise the $code value is expected to be a "Location:" header value.
1858 * @param string $header If set, this is passed directly to the PHP function, header()
1859 * @param string $reason If set, error messages will also mention this as the reason for the page-not-found.
1860 * @return void (The function exits!)
1861 * @todo Define visibility
1862 */
1863 public function pageUnavailableHandler($code, $header, $reason) {
1864 $this->pageErrorHandler($code, $header, $reason);
1865 }
1866
1867 /**
1868 * Page not found handler. Acts a wrapper for the pageErrorHandler method.
1869 *
1870 * @param mixed $code Which type of handling; If a true PHP-boolean or TRUE then a ->t3lib_message_ErrorPageMessage is outputted. If integer an error message with that number is shown. Otherwise the $code value is expected to be a "Location:" header value.
1871 * @param string $header If set, this is passed directly to the PHP function, header()
1872 * @param string $reason If set, error messages will also mention this as the reason for the page-not-found.
1873 * @return void (The function exits!)
1874 * @todo Define visibility
1875 */
1876 public function pageNotFoundHandler($code, $header = '', $reason = '') {
1877 $this->pageErrorHandler($code, $header, $reason);
1878 }
1879
1880 /**
1881 * Generic error page handler.
1882 * Exits.
1883 *
1884 * @param mixed $code Which type of handling; If a true PHP-boolean or TRUE then a ->t3lib_message_ErrorPageMessage is outputted. If integer an error message with that number is shown. Otherwise the $code value is expected to be a "Location:" header value.
1885 * @param string $header If set, this is passed directly to the PHP function, header()
1886 * @param string $reason If set, error messages will also mention this as the reason for the page-not-found.
1887 * @return void (The function exits!)
1888 * @todo Define visibility
1889 */
1890 public function pageErrorHandler($code, $header = '', $reason = '') {
1891 // Issue header in any case:
1892 if ($header) {
1893 $headerArr = preg_split('/\\r|\\n/', $header, -1, PREG_SPLIT_NO_EMPTY);
1894 foreach ($headerArr as $header) {
1895 header($header);
1896 }
1897 }
1898 // Create response:
1899 // Simply boolean; Just shows TYPO3 error page with reason:
1900 if (gettype($code) == 'boolean' || !strcmp($code, 1)) {
1901 $title = 'Page Not Found';
1902 $message = 'The page did not exist or was inaccessible.' . ($reason ? ' Reason: ' . htmlspecialchars($reason) : '');
1903 $messagePage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\ErrorpageMessage', $message, $title);
1904 $messagePage->output();
1905 die;
1906 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($code, 'USER_FUNCTION:')) {
1907 $funcRef = trim(substr($code, 14));
1908 $params = array(
1909 'currentUrl' => \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'),
1910 'reasonText' => $reason,
1911 'pageAccessFailureReasons' => $this->getPageAccessFailureReasons()
1912 );
1913 echo \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
1914 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($code, 'READFILE:')) {
1915 $readFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(trim(substr($code, 9)));
1916 if (@is_file($readFile)) {
1917 $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($readFile);
1918 $fileContent = str_replace('###CURRENT_URL###', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'), $fileContent);
1919 $fileContent = str_replace('###REASON###', htmlspecialchars($reason), $fileContent);
1920 echo $fileContent;
1921 } else {
1922 throw new \RuntimeException('Configuration Error: 404 page "' . $readFile . '" could not be found.', 1294587214);
1923 }
1924 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($code, 'REDIRECT:')) {
1925 \TYPO3\CMS\Core\Utility\HttpUtility::redirect(substr($code, 9));
1926 } elseif (strlen($code)) {
1927 // Check if URL is relative
1928 $url_parts = parse_url($code);
1929 if ($url_parts['host'] == '') {
1930 $url_parts['host'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
1931 if ($code[0] === '/') {
1932 $code = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST') . $code;
1933 } else {
1934 $code = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_DIR') . $code;
1935 }
1936 $checkBaseTag = FALSE;
1937 } else {
1938 $checkBaseTag = TRUE;
1939 }
1940 // Check recursion
1941 if ($code == \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')) {
1942 if ($reason == '') {
1943 $reason = 'Page cannot be found.';
1944 }
1945 $reason .= LF . LF . 'Additionally, ' . $code . ' was not found while trying to retrieve the error document.';
1946 throw new \RuntimeException(nl2br(htmlspecialchars($reason)), 1294587215);
1947 }
1948 // Prepare headers
1949 $headerArr = array(
1950 'User-agent: ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_USER_AGENT'),
1951 'Referer: ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')
1952 );
1953 $res = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($code, 1, $headerArr);
1954 // Header and content are separated by an empty line
1955 list($header, $content) = explode(CRLF . CRLF, $res, 2);
1956 $content .= CRLF;
1957 if (FALSE === $res) {
1958 // Last chance -- redirect
1959 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($code);
1960 } else {
1961 // Forward these response headers to the client
1962 $forwardHeaders = array(
1963 'Content-Type:'
1964 );
1965 $headerArr = preg_split('/\\r|\\n/', $header, -1, PREG_SPLIT_NO_EMPTY);
1966 foreach ($headerArr as $header) {
1967 foreach ($forwardHeaders as $h) {
1968 if (preg_match('/^' . $h . '/', $header)) {
1969 header($header);
1970 }
1971 }
1972 }
1973 // Put <base> if necesary
1974 if ($checkBaseTag) {
1975 // If content already has <base> tag, we do not need to do anything
1976 if (FALSE === stristr($content, '<base ')) {
1977 // Generate href for base tag
1978 $base = $url_parts['scheme'] . '://';
1979 if ($url_parts['user'] != '') {
1980 $base .= $url_parts['user'];
1981 if ($url_parts['pass'] != '') {
1982 $base .= ':' . $url_parts['pass'];
1983 }
1984 $base .= '@';
1985 }
1986 $base .= $url_parts['host'];
1987 // Add path portion skipping possible file name
1988 $base .= preg_replace('/(.*\\/)[^\\/]*/', '${1}', $url_parts['path']);
1989 // Put it into content (generate also <head> if necessary)
1990 $replacement = LF . '<base href="' . htmlentities($base) . '" />' . LF;
1991 if (stristr($content, '<head>')) {
1992 $content = preg_replace('/(<head>)/i', '\\1' . $replacement, $content);
1993 } else {
1994 $content = preg_replace('/(<html[^>]*>)/i', '\\1<head>' . $replacement . '</head>', $content);
1995 }
1996 }
1997 }
1998 // Output the content
1999 echo $content;
2000 }
2001 } else {
2002 $title = 'Page Not Found';
2003 $message = $reason ? 'Reason: ' . htmlspecialchars($reason) : 'Page cannot be found.';
2004 $messagePage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\ErrorpageMessage', $message, $title);
2005 $messagePage->output();
2006 }
2007 die;
2008 }
2009
2010 /**
2011 * Fetches the integer page id for a page alias.
2012 * Looks if ->id is not an integer and if so it will search for a page alias and if found the page uid of that page is stored in $this->id
2013 *
2014 * @return void
2015 * @access private
2016 * @todo Define visibility
2017 */
2018 public function checkAndSetAlias() {
2019 if ($this->id && !\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->id)) {
2020 $aid = $this->sys_page->getPageIdFromAlias($this->id);
2021 if ($aid) {
2022 $this->id = $aid;
2023 } else {
2024 $this->pageNotFound = 4;
2025 }
2026 }
2027 }
2028
2029 /**
2030 * Merging values into the global $_GET
2031 *
2032 * @param array $GET_VARS Array of key/value pairs that will be merged into the current GET-vars. (Non-escaped values)
2033 * @return void
2034 * @todo Define visibility
2035 */
2036 public function mergingWithGetVars($GET_VARS) {
2037 if (is_array($GET_VARS)) {
2038 // Getting $_GET var, unescaped.
2039 $realGet = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET();
2040 if (!is_array($realGet)) {
2041 $realGet = array();
2042 }
2043 // Merge new values on top:
2044 $realGet = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($realGet, $GET_VARS);
2045 // Write values back to $_GET:
2046 \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset($realGet);
2047 // Setting these specifically (like in the init-function):
2048 if (isset($GET_VARS['type'])) {
2049 $this->type = intval($GET_VARS['type']);
2050 }
2051 if (isset($GET_VARS['cHash'])) {
2052 $this->cHash = $GET_VARS['cHash'];
2053 }
2054 if (isset($GET_VARS['jumpurl'])) {
2055 $this->jumpurl = $GET_VARS['jumpurl'];
2056 }
2057 if (isset($GET_VARS['MP'])) {
2058 $this->MP = $this->TYPO3_CONF_VARS['FE']['enable_mount_pids'] ? $GET_VARS['MP'] : '';
2059 }
2060 if (isset($GET_VARS['no_cache']) && $GET_VARS['no_cache']) {
2061 $this->set_no_cache();
2062 }
2063 }
2064 }
2065
2066 /********************************************
2067 *
2068 * Template and caching related functions.
2069 *
2070 *******************************************/
2071 /**
2072 * Calculates a hash string based on additional parameters in the url.
2073 *
2074 * Calculated hash is stored in $this->cHash_array.
2075 * This is used to cache pages with more parameters than just id and type.
2076 *
2077 * @return void
2078 * @see reqCHash()
2079 * @todo Define visibility
2080 */
2081 public function makeCacheHash() {
2082 // No need to test anything if caching was already disabled.
2083 if ($this->no_cache && !$this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
2084 return;
2085 }
2086 $GET = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET();
2087 if ($this->cHash && is_array($GET)) {
2088 $this->cHash_array = $this->cacheHash->getRelevantParameters(\TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $GET));
2089 $cHash_calc = $this->cacheHash->calculateCacheHash($this->cHash_array);
2090 if ($cHash_calc != $this->cHash) {
2091 if ($this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
2092 $this->pageNotFoundAndExit('Request parameters could not be validated (&cHash comparison failed)');
2093 } else {
2094 $this->disableCache();
2095 $GLOBALS['TT']->setTSlogMessage('The incoming cHash "' . $this->cHash . '" and calculated cHash "' . $cHash_calc . '" did not match, so caching was disabled. The fieldlist used was "' . implode(',', array_keys($this->cHash_array)) . '"', 2);
2096 }
2097 }
2098 } elseif (is_array($GET)) {
2099 // No cHash is set, check if that is correct
2100 if ($this->cacheHash->doParametersRequireCacheHash(\TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $GET))) {
2101 $this->reqCHash();
2102 }
2103 }
2104 }
2105
2106 /**
2107 * Will disable caching if the cHash value was not set.
2108 * This function should be called to check the _existence_ of "&cHash" whenever a plugin generating cachable output is using extra GET variables. If there _is_ a cHash value the validation of it automatically takes place in makeCacheHash() (see above)
2109 *
2110 * @return void
2111 * @see makeCacheHash(), tslib_pibase::pi_cHashCheck()
2112 * @todo Define visibility
2113 */
2114 public function reqCHash() {
2115 if (!$this->cHash) {
2116 if ($this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
2117 if ($this->tempContent) {
2118 $this->clearPageCacheContent();
2119 }
2120 $this->pageNotFoundAndExit('Request parameters could not be validated (&cHash empty)');
2121 } else {
2122 $this->disableCache();
2123 $GLOBALS['TT']->setTSlogMessage('TSFE->reqCHash(): No &cHash parameter was sent for GET vars though required so caching is disabled', 2);
2124 }
2125 }
2126 }
2127
2128 /**
2129 * Splits the input query-parameters into an array with certain parameters filtered out.
2130 * Used to create the cHash value
2131 *
2132 * @param string $addQueryParams Query-parameters: "&xxx=yyy&zzz=uuu
2133 * @return array Array with key/value pairs of query-parameters WITHOUT a certain list of variable names (like id, type, no_cache etc) and WITH a variable, encryptionKey, specific for this server/installation
2134 * @access private
2135 * @see makeCacheHash(), tslib_cObj::typoLink()
2136 * @deprecated since TYPO3 4.7 - will be removed in TYPO3 6.1 - use t3lib_cacheHash instead
2137 * @obsolete
2138 * @todo Define visibility
2139 */
2140 public function cHashParams($addQueryParams) {
2141 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
2142 return $this->cacheHash->calculateCacheHash($addQueryParams);
2143 }
2144
2145 /**
2146 * Initialize the TypoScript template parser
2147 *
2148 * @return void
2149 * @todo Define visibility
2150 */
2151 public function initTemplate() {
2152 $this->tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\TemplateService');
2153 $this->tmpl->init();
2154 $this->tmpl->tt_track = $this->beUserLogin ? 1 : 0;
2155 }
2156
2157 /**
2158 * See if page is in cache and get it if so
2159 * Stores the page content in $this->content if something is found.
2160 *
2161 * @return void
2162 * @todo Define visibility
2163 */
2164 public function getFromCache() {
2165 if (!$this->no_cache) {
2166 $cc = $this->tmpl->getCurrentPageData();
2167 if (!is_array($cc)) {
2168 $key = $this->id . '::' . $this->MP;
2169 // Returns TRUE if the lock is active now
2170 $isLocked = $this->acquirePageGenerationLock($this->pagesection_lockObj, $key);
2171 if (!$isLocked) {
2172 // Lock is no longer active, the data in "cache_pagesection" is now ready
2173 $cc = $this->tmpl->getCurrentPageData();
2174 if (is_array($cc)) {
2175 // Release the lock
2176 $this->releasePageGenerationLock($this->pagesection_lockObj);
2177 }
2178 }
2179 }
2180 if (is_array($cc)) {
2181 // BE CAREFUL to change the content of the cc-array. This array is serialized and an md5-hash based on this is used for caching the page.
2182 // If this hash is not the same in here in this section and after page-generation, then the page will not be properly cached!
2183 // This array is an identification of the template. If $this->all is empty it's because the template-data is not cached, which it must be.
2184 $cc = $this->tmpl->matching($cc);
2185 ksort($cc);
2186 $this->all = $cc;
2187 }
2188 unset($cc);
2189 }
2190 // clearing the content-variable, which will hold the pagecontent
2191 $this->content = '';
2192 // Unsetting the lowlevel config
2193 unset($this->config);
2194 $this->cacheContentFlag = 0;
2195 // Look for page in cache only if caching is not disabled and if a shift-reload is not sent to the server.
2196 if (!$this->no_cache && !$this->headerNoCache()) {
2197 $lockHash = $this->getLockHash();
2198 if ($this->all) {
2199 $this->newHash = $this->getHash();
2200 $GLOBALS['TT']->push('Cache Row', '');
2201 $row = $this->getFromCache_queryRow();
2202 if (!is_array($row)) {
2203 $isLocked = $this->acquirePageGenerationLock($this->pages_lockObj, $lockHash);
2204 if (!$isLocked) {
2205 // Lock is no longer active, the data in "cache_pages" is now ready
2206 $row = $this->getFromCache_queryRow();
2207 if (is_array($row)) {
2208 // Release the lock
2209 $this->releasePageGenerationLock($this->pages_lockObj);
2210 }
2211 }
2212 }
2213 if (is_array($row)) {
2214 // Release this lock
2215 $this->releasePageGenerationLock($this->pages_lockObj);
2216 // Call hook when a page is retrieved from cache:
2217 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageLoadedFromCache'])) {
2218 $_params = array('pObj' => &$this, 'cache_pages_row' => &$row);
2219 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageLoadedFromCache'] as $_funcRef) {
2220 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2221 }
2222 }
2223 // Fetches the lowlevel config stored with the cached data
2224 $this->config = (array) unserialize($row['cache_data']);
2225 // Getting the content
2226 $this->content = $row['content'];
2227 // Flag for temp content
2228 $this->tempContent = $row['temp_content'];
2229 // Setting flag, so we know, that some cached content has been loaded
2230 $this->cacheContentFlag = 1;
2231 $this->cacheExpires = $row['expires'];
2232 if ($this->TYPO3_CONF_VARS['FE']['debug'] || isset($this->config['config']['debug']) && $this->config['config']['debug']) {
2233 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
2234 $timeFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
2235 $this->content .= LF . '<!-- Cached page generated ' . date(($dateFormat . ' ' . $timeFormat), $row['tstamp']) . '. Expires ' . Date(($dateFormat . ' ' . $timeFormat), $row['expires']) . ' -->';
2236 }
2237 }
2238 $GLOBALS['TT']->pull();
2239 } else {
2240 $this->acquirePageGenerationLock($this->pages_lockObj, $lockHash);
2241 }
2242 }
2243 }
2244
2245 /**
2246 * Returning the cached version of page with hash = newHash
2247 *
2248 * @return array Cached row, if any. Otherwise void.
2249 * @todo Define visibility
2250 */
2251 public function getFromCache_queryRow() {
2252 $GLOBALS['TT']->push('Cache Query', '');
2253 $row = $this->pageCache->get($this->newHash);
2254 $GLOBALS['TT']->pull();
2255 return $row;
2256 }
2257
2258 /**
2259 * Detecting if shift-reload has been clicked
2260 * Will not be called if re-generation of page happens by other reasons (for instance that the page is not in cache yet!)
2261 * Also, a backend user MUST be logged in for the shift-reload to be detected due to DoS-attack-security reasons.
2262 *
2263 * @return boolean If shift-reload in client browser has been clicked, disable getting cached page (and regenerate it).
2264 * @todo Define visibility
2265 */
2266 public function headerNoCache() {
2267 $disableAcquireCacheData = FALSE;
2268 if ($this->beUserLogin) {
2269 if (strtolower($_SERVER['HTTP_CACHE_CONTROL']) === 'no-cache' || strtolower($_SERVER['HTTP_PRAGMA']) === 'no-cache') {
2270 $disableAcquireCacheData = TRUE;
2271 }
2272 }
2273 // Call hook for possible by-pass of requiring of page cache (for recaching purpose)
2274 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['headerNoCache'])) {
2275 $_params = array('pObj' => &$this, 'disableAcquireCacheData' => &$disableAcquireCacheData);
2276 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['headerNoCache'] as $_funcRef) {
2277 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2278 }
2279 }
2280 return $disableAcquireCacheData;
2281 }
2282
2283 /**
2284 * Calculates the cache-hash
2285 * This hash is unique to the template, the variables ->id, ->type, ->gr_list (list of groups), ->MP (Mount Points) and cHash array
2286 * Used to get and later store the cached data.
2287 *
2288 * @return string MD5 hash of $this->hash_base which is a serialized version of there variables.
2289 * @access private
2290 * @see getFromCache(), getLockHash()
2291 * @todo Define visibility
2292 */
2293 public function getHash() {
2294 $this->hash_base = $this->createHashBase(FALSE);
2295 return md5($this->hash_base);
2296 }
2297
2298 /**
2299 * Calculates the lock-hash
2300 * This hash is unique to the above hash, except that it doesn't contain the template information in $this->all.
2301 *
2302 * @return string MD5 hash
2303 * @access private
2304 * @see getFromCache(), getHash()
2305 * @todo Define visibility
2306 */
2307 public function getLockHash() {
2308 $lockHash = $this->createHashBase(TRUE);
2309 return md5($lockHash);
2310 }
2311
2312 /**
2313 * Calculates the cache-hash (or the lock-hash)
2314 * This hash is unique to the template,
2315 * the variables ->id, ->type, ->gr_list (list of groups),
2316 * ->MP (Mount Points) and cHash array
2317 * Used to get and later store the cached data.
2318 *
2319 * @param boolean $createLockHashBase Whether to create the lock hash, which doesn't contain the "this->all" (the template information)
2320 * @return string the serialized hash base
2321 */
2322 protected function createHashBase($createLockHashBase = FALSE) {
2323 $hashParameters = array(
2324 'id' => intval($this->id),
2325 'type' => intval($this->type),
2326 'gr_list' => (string) $this->gr_list,
2327 'MP' => (string) $this->MP,
2328 'cHash' => $this->cHash_array,
2329 'domainStartPage' => $this->domainStartPage
2330 );
2331 // Include the template information if we shouldn't create a lock hash
2332 if (!$createLockHashBase) {
2333 $hashParameters['all'] = $this->all;
2334 }
2335 // Call hook to influence the hash calculation
2336 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'])) {
2337 $_params = array(
2338 'hashParameters' => &$hashParameters,
2339 'createLockHashBase' => $createLockHashBase
2340 );
2341 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'] as $_funcRef) {
2342 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2343 }
2344 }
2345 return serialize($hashParameters);
2346 }
2347
2348 /**
2349 * Checks if config-array exists already but if not, gets it
2350 *
2351 * @return void
2352 * @todo Define visibility
2353 */
2354 public function getConfigArray() {
2355 $setStatPageName = FALSE;
2356 // If config is not set by the cache (which would be a major mistake somewhere) OR if INTincScripts-include-scripts have been registered, then we must parse the template in order to get it
2357 if (!is_array($this->config) || is_array($this->config['INTincScript']) || $this->forceTemplateParsing) {
2358 $GLOBALS['TT']->push('Parse template', '');
2359 // Force parsing, if set?:
2360 $this->tmpl->forceTemplateParsing = $this->forceTemplateParsing;
2361 // Start parsing the TS template. Might return cached version.
2362 $this->tmpl->start($this->rootLine);
2363 $GLOBALS['TT']->pull();
2364 if ($this->tmpl->loaded) {
2365 $GLOBALS['TT']->push('Setting the config-array', '');
2366 // toplevel - objArrayName
2367 $this->sPre = $this->tmpl->setup['types.'][$this->type];
2368 $this->pSetup = $this->tmpl->setup[$this->sPre . '.'];
2369 if (!is_array($this->pSetup)) {
2370 $message = 'The page is not configured! [type=' . $this->type . '][' . $this->sPre . '].';
2371 if ($this->checkPageUnavailableHandler()) {
2372 $this->pageUnavailableAndExit($message);
2373 } else {
2374 $explanation = 'This means that there is no TypoScript object of type PAGE with typeNum=' . $this->type . ' configured.';
2375 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
2376 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message . ' ' . $explanation, 1294587217);
2377 }
2378 } else {
2379 $this->config['config'] = array();
2380 // Filling the config-array, first with the main "config." part
2381 if (is_array($this->tmpl->setup['config.'])) {
2382 $this->config['config'] = $this->tmpl->setup['config.'];
2383 }
2384 // override it with the page/type-specific "config."
2385 if (is_array($this->pSetup['config.'])) {
2386 $this->config['config'] = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($this->config['config'], $this->pSetup['config.']);
2387 }
2388 if ($this->config['config']['typolinkEnableLinksAcrossDomains']) {
2389 $this->config['config']['typolinkCheckRootline'] = TRUE;
2390 }
2391 // Set default values for removeDefaultJS and inlineStyle2TempFile so CSS and JS are externalized if compatversion is higher than 4.0
2392 if (\TYPO3\CMS\Core\Utility\GeneralUtility::compat_version('4.0')) {
2393 if (!isset($this->config['config']['removeDefaultJS'])) {
2394 $this->config['config']['removeDefaultJS'] = 'external';
2395 }
2396 if (!isset($this->config['config']['inlineStyle2TempFile'])) {
2397 $this->config['config']['inlineStyle2TempFile'] = 1;
2398 }
2399 }
2400 if (!isset($this->config['config']['compressJs'])) {
2401 $this->config['config']['compressJs'] = 0;
2402 }
2403 // Processing for the config_array:
2404 $this->config['rootLine'] = $this->tmpl->rootLine;
2405 $this->config['mainScript'] = trim($this->config['config']['mainScript']) ? trim($this->config['config']['mainScript']) : 'index.php';
2406 // Class for render Header and Footer parts
2407 $template = '';
2408 if ($this->pSetup['pageHeaderFooterTemplateFile']) {
2409 $file = $this->tmpl->getFileName($this->pSetup['pageHeaderFooterTemplateFile']);
2410 if ($file) {
2411 $this->setTemplateFile($file);
2412 }
2413 }
2414 }
2415 $GLOBALS['TT']->pull();
2416 } else {
2417 if ($this->checkPageUnavailableHandler()) {
2418 $this->pageUnavailableAndExit('No TypoScript template found!');
2419 } else {
2420 $message = 'No TypoScript template found!';
2421 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
2422 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message, 1294587218);
2423 }
2424 }
2425 }
2426 // Initialize charset settings etc.
2427 $this->initLLvars();
2428 // No cache
2429 // Set $this->no_cache TRUE if the config.no_cache value is set!
2430 if ($this->config['config']['no_cache']) {
2431 $this->set_no_cache();
2432 }
2433 // Merge GET with defaultGetVars
2434 if (!empty($this->config['config']['defaultGetVars.'])) {
2435 $modifiedGetVars = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule(\TYPO3\CMS\Core\Utility\GeneralUtility::removeDotsFromTS($this->config['config']['defaultGetVars.']), \TYPO3\CMS\Core\Utility\GeneralUtility::_GET());
2436 \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset($modifiedGetVars);
2437 }
2438 // Hook for postProcessing the configuration array
2439 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc'])) {
2440 $params = array('config' => &$this->config['config']);
2441 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc'] as $funcRef) {
2442 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
2443 }
2444 }
2445 }
2446
2447 /********************************************
2448 *
2449 * Further initialization and data processing
2450 * (jumpurl/submission of forms)
2451 *
2452 *******************************************/
2453 /**
2454 * Get the compressed $GLOBALS['TCA'] array for use in the front-end
2455 * A compressed $GLOBALS['TCA'] array holds only the ctrl- and feInterface-part for each table. But the column-definitions are omitted in order to save some memory and be more efficient.
2456 * Operates on the global variable, $TCA
2457 *
2458 * @return void
2459 * @see includeTCA()
2460 * @todo Define visibility
2461 */
2462 public function getCompressedTCarray() {
2463 $GLOBALS['TT']->push('Get Compressed TC array');
2464 if (!$this->TCAloaded) {
2465 // Create hash string for storage / retrieval of cached content:
2466 $tempHash = md5('tables.php:' . filemtime((TYPO3_extTableDef_script ? PATH_typo3conf . TYPO3_extTableDef_script : PATH_t3lib . 'stddb/tables.php')) . (TYPO3_extTableDef_script ? filemtime(PATH_typo3conf . TYPO3_extTableDef_script) : ''));
2467 list($GLOBALS['TCA'], $this->TCAcachedExtras) = unserialize($this->sys_page->getHash($tempHash));
2468 // If no result, create it:
2469 if (!is_array($GLOBALS['TCA'])) {
2470 $this->includeTCA(0);
2471 $newTc = array();
2472 // Collects other information
2473 $this->TCAcachedExtras = array();
2474 foreach ($GLOBALS['TCA'] as $key => $val) {
2475 $newTc[$key]['ctrl'] = $val['ctrl'];
2476 $newTc[$key]['feInterface'] = $val['feInterface'];
2477 // Collect information about localization exclusion of fields:
2478 \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA($key);
2479 if (is_array($GLOBALS['TCA'][$key]['columns'])) {
2480 $this->TCAcachedExtras[$key]['l10n_mode'] = array();
2481 foreach ($GLOBALS['TCA'][$key]['columns'] as $fN => $fV) {
2482 if ($fV['l10n_mode']) {
2483 $this->TCAcachedExtras[$key]['l10n_mode'][$fN] = $fV['l10n_mode'];
2484 }
2485 }
2486 }
2487 }
2488 $GLOBALS['TCA'] = $newTc;
2489 $this->sys_page->storeHash($tempHash, serialize(array($newTc, $this->TCAcachedExtras)), 'SHORT_TC');
2490 }
2491 }
2492 $GLOBALS['TT']->pull();
2493 }
2494
2495 /**
2496 * Includes TCA definitions from loaded extensions (ext_table.php files).
2497 * Normally in the frontend only a part of the global $TCA array is loaded,
2498 * namely the "ctrl" part. Thus it doesn't take up too much memory. To load
2499 * full TCA for the table, use t3lib_div::loadTCA($tableName) after calling
2500 * this function.
2501 *
2502 * @param integer $TCAloaded Probably, keep hands of this value. Just don't set it. (This may affect the first-ever time this function is called since if you set it to zero/FALSE any subsequent call will still trigger the inclusion; In other words, this value will be set in $this->TCAloaded after inclusion and therefore if its FALSE, another inclusion will be possible on the next call. See ->getCompressedTCarray())
2503 * @return void
2504 * @see getCompressedTCarray()
2505 */
2506 public function includeTCA($TCAloaded = 1) {
2507 if (!$this->TCAloaded) {
2508 $GLOBALS['TCA'] = array();
2509 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadExtensionTables(TRUE);
2510 $this->TCAloaded = $TCAloaded;
2511 }
2512 }
2513
2514 /**
2515 * Setting the language key that will be used by the current page.
2516 * In this function it should be checked, 1) that this language exists, 2) that a page_overlay_record exists, .. and if not the default language, 0 (zero), should be set.
2517 *
2518 * @return void
2519 * @access private
2520 * @todo Define visibility
2521 */
2522 public function settingLanguage() {
2523 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_preProcess'])) {
2524 $_params = array();
2525 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_preProcess'] as $_funcRef) {
2526 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2527 }
2528 }
2529 // Get values from TypoScript:
2530 $this->sys_language_uid = ($this->sys_language_content = intval($this->config['config']['sys_language_uid']));
2531 list($this->sys_language_mode, $sys_language_content) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(';', $this->config['config']['sys_language_mode']);
2532 $this->sys_language_contentOL = $this->config['config']['sys_language_overlay'];
2533 // If sys_language_uid is set to another language than default:
2534 if ($this->sys_language_uid > 0) {
2535 // check whether a shortcut is overwritten by a translated page
2536 // we can only do this now, as this is the place where we get
2537 // to know about translations
2538 $this->checkTranslatedShortcut();
2539 // Request the overlay record for the sys_language_uid:
2540 $olRec = $this->sys_page->getPageOverlay($this->id, $this->sys_language_uid);
2541 if (!count($olRec)) {
2542 // If no OL record exists and a foreign language is asked for...
2543 if ($this->sys_language_uid) {
2544 // If requested translation is not available:
2545 if (\TYPO3\CMS\Core\Utility\GeneralUtility::hideIfNotTranslated($this->page['l18n_cfg'])) {
2546 $this->pageNotFoundAndExit('Page is not available in the requested language.');
2547 } else {
2548 switch ((string) $this->sys_language_mode) {
2549 case 'strict':
2550 $this->pageNotFoundAndExit('Page is not available in the requested language (strict).');
2551 break;
2552 case 'content_fallback':
2553 $fallBackOrder = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $sys_language_content);
2554 foreach ($fallBackOrder as $orderValue) {
2555 if (!strcmp($orderValue, '0') || count($this->sys_page->getPageOverlay($this->id, $orderValue))) {
2556 $this->sys_language_content = $orderValue;
2557 // Setting content uid (but leaving the sys_language_uid)
2558 break;
2559 }
2560 }
2561 break;
2562 case 'ignore':
2563 $this->sys_language_content = $this->sys_language_uid;
2564 break;
2565 default:
2566 // Default is that everything defaults to the default language...
2567 $this->sys_language_uid = ($this->sys_language_content = 0);
2568 break;
2569 }
2570 }
2571 }
2572 } else {
2573 // Setting sys_language if an overlay record was found (which it is only if a language is used)
2574 $this->page = $this->sys_page->getPageOverlay($this->page, $this->sys_language_uid);
2575 }
2576 }
2577 // Setting sys_language_uid inside sys-page:
2578 $this->sys_page->sys_language_uid = $this->sys_language_uid;
2579 // If default translation is not available:
2580 if ((!$this->sys_language_uid || !$this->sys_language_content) && $this->page['l18n_cfg'] & 1) {
2581 $message = 'Page is not available in default language.';
2582 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
2583 $this->pageNotFoundAndExit($message);
2584 }
2585 // Updating content of the two rootLines IF the language key is set!
2586 if ($this->sys_language_uid && is_array($this->tmpl->rootLine)) {
2587 foreach ($this->tmpl->rootLine as $rLk => $value) {
2588 $this->tmpl->rootLine[$rLk] = $this->sys_page->getPageOverlay($this->tmpl->rootLine[$rLk]);
2589 }
2590 }
2591 if ($this->sys_language_uid && is_array($this->rootLine)) {
2592 foreach ($this->rootLine as $rLk => $value) {
2593 $this->rootLine[$rLk] = $this->sys_page->getPageOverlay($this->rootLine[$rLk]);
2594 }
2595 }
2596 // Finding the ISO code:
2597 if (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('static_info_tables') && $this->sys_language_content) {
2598 // using sys_language_content because the ISO code only (currently) affect content selection from FlexForms - which should follow "sys_language_content"
2599 $sys_language_row = $this->sys_page->getRawRecord('sys_language', $this->sys_language_content, 'static_lang_isocode');
2600 if (is_array($sys_language_row) && $sys_language_row['static_lang_isocode']) {
2601 $stLrow = $this->sys_page->getRawRecord('static_languages', $sys_language_row['static_lang_isocode'], 'lg_iso_2');
2602 $this->sys_language_isocode = $stLrow['lg_iso_2'];
2603 }
2604 }
2605 // Setting softMergeIfNotBlank:
2606 $table_fields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->config['config']['sys_language_softMergeIfNotBlank'], 1);
2607 foreach ($table_fields as $TF) {
2608 list($tN, $fN) = explode(':', $TF);
2609 $this->TCAcachedExtras[$tN]['l10n_mode'][$fN] = 'mergeIfNotBlank';
2610 }
2611 // Setting softExclude:
2612 $table_fields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->config['config']['sys_language_softExclude'], 1);
2613 foreach ($table_fields as $TF) {
2614 list($tN, $fN) = explode(':', $TF);
2615 $this->TCAcachedExtras[$tN]['l10n_mode'][$fN] = 'exclude';
2616 }
2617 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_postProcess'])) {
2618 $_params = array();
2619 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_postProcess'] as $_funcRef) {
2620 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2621 }
2622 }
2623 }
2624
2625 /**
2626 * Setting locale for frontend rendering
2627 *
2628 * @return void
2629 * @todo Define visibility
2630 */
2631 public function settingLocale() {
2632 // Setting locale
2633 if ($this->config['config']['locale_all']) {
2634 // There's a problem that PHP parses float values in scripts wrong if the
2635 // locale LC_NUMERIC is set to something with a comma as decimal point
2636 // Do we set all except LC_NUMERIC
2637 $locale = setlocale(LC_COLLATE, $this->config['config']['locale_all']);
2638 if ($locale) {
2639 // PHP fatals with uppercase I characters in method names with turkish locale LC_CTYPE
2640 // @see http://bugs.php.net/bug.php?id=35050
2641 if (substr($this->config['config']['locale_all'], 0, 2) != 'tr') {
2642 setlocale(LC_CTYPE, $this->config['config']['locale_all']);
2643 }
2644 setlocale(LC_MONETARY, $this->config['config']['locale_all']);
2645 setlocale(LC_TIME, $this->config['config']['locale_all']);
2646 $this->localeCharset = $this->csConvObj->get_locale_charset($this->config['config']['locale_all']);
2647 } else {
2648 $GLOBALS['TT']->setTSlogMessage('Locale "' . htmlspecialchars($this->config['config']['locale_all']) . '" not found.', 3);
2649 }
2650 }
2651 }
2652
2653 /**
2654 * Checks whether a translated shortcut page has a different shortcut
2655 * target than the original language page.
2656 * If that is the case, things get corrected to follow that alternative
2657 * shortcut
2658 *
2659 * @return void
2660 * @author Ingo Renner <ingo@typo3.org>
2661 */
2662 protected function checkTranslatedShortcut() {
2663 if (!is_null($this->originalShortcutPage)) {
2664 $originalShortcutPageOverlay = $this->sys_page->getPageOverlay($this->originalShortcutPage['uid'], $this->sys_language_uid);
2665 if (!empty($originalShortcutPageOverlay['shortcut']) && $originalShortcutPageOverlay['shortcut'] != $this->id) {
2666 // the translation of the original shortcut page has a different shortcut target!
2667 // set the correct page and id
2668 $shortcut = $this->getPageShortcut($originalShortcutPageOverlay['shortcut'], $originalShortcutPageOverlay['shortcut_mode'], $originalShortcutPageOverlay['uid']);
2669 $this->id = ($this->contentPid = $shortcut['uid']);
2670 $this->page = $this->sys_page->getPage($this->id);
2671 // Fix various effects on things like menus f.e.
2672 $this->fetch_the_id();
2673 $this->tmpl->rootLine = array_reverse($this->rootLine);
2674 }
2675 }
2676 }
2677
2678 /**
2679 * Checks if any email-submissions
2680 *
2681 * @return string "email" if a formmail has been sent, "" if none.
2682 * @todo Define visibility
2683 */
2684 public function checkDataSubmission() {
2685 $ret = '';
2686 $formtype_mail = isset($_POST['formtype_mail']) || isset($_POST['formtype_mail_x']);
2687 if ($formtype_mail) {
2688 $refInfo = parse_url(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_REFERER'));
2689 if (\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') == $refInfo['host'] || $this->TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) {
2690 if ($this->locDataCheck($_POST['locationData'])) {
2691 if ($formtype_mail) {
2692 $ret = 'email';
2693 }
2694 $GLOBALS['TT']->setTSlogMessage('"Check Data Submission": Return value: ' . $ret, 0);
2695 return $ret;
2696 }
2697 } else {
2698 $GLOBALS['TT']->setTSlogMessage('"Check Data Submission": HTTP_HOST and REFERER HOST did not match when processing submitted formdata!', 3);
2699 }
2700 }
2701 // Hook for processing data submission to extensions:
2702 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkDataSubmission'])) {
2703 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkDataSubmission'] as $_classRef) {
2704 $_procObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
2705 $_procObj->checkDataSubmission($this);
2706 }
2707 }
2708 return $ret;
2709 }
2710
2711 /**
2712 * Processes submitted user data (obsolete "Frontend TCE")
2713 *
2714 * @return void
2715 * @see tslib_feTCE
2716 * @deprecated since 6.0, will be removed two versions later
2717 * @todo Define visibility
2718 */
2719 public function fe_tce() {
2720 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
2721 }
2722
2723 /**
2724 * Checks if a formmail submission can be sent as email
2725 *
2726 * @param string $locationData The input from $_POST['locationData']
2727 * @return void
2728 * @access private
2729 * @see checkDataSubmission()
2730 * @todo Define visibility
2731 */
2732 public function locDataCheck($locationData) {
2733 $locData = explode(':', $locationData);
2734 if (!$locData[1] || $this->sys_page->checkRecord($locData[1], $locData[2], 1)) {
2735 // $locData[1] -check means that a record is checked only if the locationData has a value for a record else than the page.
2736 if (count($this->sys_page->getPage($locData[0]))) {
2737 return 1;
2738 } else {
2739 $GLOBALS['TT']->setTSlogMessage('LocationData Error: The page pointed to by location data (' . $locationData . ') was not accessible.', 2);
2740 }
2741 } else {
2742 $GLOBALS['TT']->setTSlogMessage('LocationData Error: Location data (' . $locationData . ') record pointed to was not accessible.', 2);
2743 }
2744 }
2745
2746 /**
2747 * Sends the emails from the formmail content object.
2748 *
2749 * @return void
2750 * @access private
2751 * @see checkDataSubmission()
2752 * @todo Define visibility
2753 */
2754 public function sendFormmail() {
2755 $formmail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_formmail');
2756 $EMAIL_VARS = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST();
2757 $locationData = $EMAIL_VARS['locationData'];
2758 unset($EMAIL_VARS['locationData']);
2759 unset($EMAIL_VARS['formtype_mail'], $EMAIL_VARS['formtype_mail_x'], $EMAIL_VARS['formtype_mail_y']);
2760 $integrityCheck = $this->TYPO3_CONF_VARS['FE']['strictFormmail'];
2761 if (!$this->TYPO3_CONF_VARS['FE']['secureFormmail']) {
2762 // Check recipient field:
2763 // These two fields are the ones which contain recipient addresses that can be misused to send mail from foreign servers.
2764 $encodedFields = explode(',', 'recipient, recipient_copy');
2765 foreach ($encodedFields as $fieldKey) {
2766 if (strlen($EMAIL_VARS[$fieldKey])) {
2767 // Decode...
2768 if ($res = $this->codeString($EMAIL_VARS[$fieldKey], TRUE)) {
2769 $EMAIL_VARS[$fieldKey] = $res;
2770 } elseif ($integrityCheck) {
2771 // Otherwise abort:
2772 $GLOBALS['TT']->setTSlogMessage('"Formmail" discovered a field (' . $fieldKey . ') which could not be decoded to a valid string. Sending formmail aborted due to security reasons!', 3);
2773 return FALSE;
2774 } else {
2775 $GLOBALS['TT']->setTSlogMessage('"Formmail" discovered a field (' . $fieldKey . ') which could not be decoded to a valid string. The security level accepts this, but you should consider a correct coding though!', 2);
2776 }
2777 }
2778 }
2779 } else {
2780 $locData = explode(':', $locationData);
2781 $record = $this->sys_page->checkRecord