Added an object path in Page TSconfig called "TSFE.constants" which allows developers...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_fe.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skaarhoj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Class for the built TypoScript based Front End
29 *
30 * This class has a lot of functions and internal variable which are use from index_ts.php.
31 * The class is instantiated as $GLOBALS['TSFE'] in index_ts.php.
32 * The use of this class should be inspired by the order of function calls as found in index_ts.php.
33 *
34 * $Id$
35 * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
36 * XHTML compliant
37 *
38 * @author Kasper Skaarhoj <kasper@typo3.com>
39 */
40 /**
41 * [CLASS/FUNCTION INDEX of SCRIPT]
42 *
43 *
44 *
45 * 178: class tslib_fe
46 * 326: function tslib_fe($TYPO3_CONF_VARS, $id, $type, $no_cache='', $cHash='', $jumpurl='',$MP='',$RDCT='')
47 * 348: function connectToMySQL()
48 * 384: function sendRedirect()
49 *
50 * SECTION: Initializing, resolving page id
51 * 424: function initFEuser()
52 * 479: function checkAlternativeIdMethods()
53 * 525: function clear_preview()
54 * 538: function determineId()
55 * 610: function fetch_the_id()
56 * 716: function getPageAndRootline()
57 * 778: function getPageShortcut($SC,$mode,$thisUid,$itera=20,$pageLog=array())
58 * 823: function checkRootlineForIncludeSection()
59 * 857: function checkEnableFields($row)
60 * 875: function checkPagerecordForIncludeSection($row)
61 * 887: function setIDfromArgV()
62 * 903: function getPageAndRootlineWithDomain($domainStartPage)
63 * 931: function findDomainRecord($recursive=0)
64 * 952: function pageNotFoundHandler($code,$header='')
65 * 974: function checkAndSetAlias()
66 * 989: function idPartsAnalyze($str)
67 *
68 * SECTION: Template and caching related functions.
69 * 1044: function makeCacheHash()
70 * 1065: function cHashParams($addQueryParams)
71 * 1084: function initTemplate()
72 * 1096: function getFromCache()
73 * 1151: function getHash()
74 * 1170: function getConfigArray()
75 *
76 * SECTION: Further initialization and data processing
77 * 1280: function getCompressedTCarray()
78 * 1317: function includeTCA($TCAloaded=1)
79 * 1344: function settingLanguage()
80 * 1384: function checkDataSubmission()
81 * 1409: function fe_tce()
82 * 1423: function locDataCheck($locationData)
83 * 1439: function sendFormmail()
84 * 1457: function checkJumpUrl()
85 * 1529: function jumpUrl()
86 * 1572: function setUrlIdToken()
87 *
88 * SECTION: Page generation; cache handling
89 * 1615: function isGeneratePage()
90 * 1625: function tempPageCacheContent()
91 * 1656: function realPageCacheContent()
92 * 1678: function setPageCacheContent($c,$d,$t)
93 * 1690: function clearPageCacheContent()
94 * 1700: function clearPageCacheContent_pidList($pidList)
95 * 1711: function setSysLastChanged()
96 *
97 * SECTION: Page generation; rendering and inclusion
98 * 1748: function generatePage_preProcessing()
99 * 1784: function generatePage_whichScript()
100 * 1796: function generatePage_postProcessing()
101 * 1854: function INTincScript()
102 * 1912: function INTincScript_loadJSCode()
103 * 1953: function isINTincScript()
104 * 1962: function isSearchIndexPage()
105 * 1971: function doXHTML_cleaning()
106 *
107 * SECTION: Finished off; outputting, storing session data, statistics...
108 * 2003: function isOutputting()
109 * 2014: function processOutput()
110 * 2066: function isEXTincScript()
111 * 2075: function storeSessionData()
112 * 2085: function setParseTime()
113 * 2097: function statistics()
114 * 2174: function previewInfo()
115 * 2195: function beLoginLinkIPList()
116 *
117 * SECTION: Various internal API functions
118 * 2250: function makeSimulFileName($inTitle,$page,$type,$addParams='',$no_cache='')
119 * 2292: function simulateStaticDocuments_pEnc_onlyP_proc($linkVars)
120 * 2320: function getSimulFileName()
121 * 2333: function encryptEmail($string,$back=0)
122 * 2350: function checkFileInclude($incFile)
123 * 2365: function newCObj()
124 * 2378: function setAbsRefPrefix()
125 * 2394: function printError($label,$header='Error!')
126 * 2405: function updateMD5paramsRecord($hash)
127 * 2417: function tidyHTML($content)
128 *
129 * SECTION: Various external API functions - for use in plugins etc.
130 * 2478: function getStorageSiterootPids()
131 * 2493: function getPagesTSconfig()
132 * 2526: function setJS($key,$content='')
133 * 2532: function over(name,imgObj)
134 * 2537: function out(name,imgObj)
135 * 2564: function setCSS($key,$content)
136 * 2579: function make_seed()
137 * 2592: function uniqueHash($str='')
138 * 2601: function set_no_cache()
139 * 2611: function set_cache_timeout_default($seconds)
140 * 2627: function plainMailEncoded($email,$subject,$message,$headers='')
141 * 2650: function sL($input)
142 * 2681: function readLLfile($fileRef)
143 * 2696: function getLLL($index,$LOCAL_LANG)
144 * 2710: function initLLvars()
145 *
146 * TOTAL FUNCTIONS: 83
147 * (This index is automatically created/updated by the extension "extdeveval")
148 *
149 */
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171 /**
172 * Main frontend class, instantiated in the index_ts.php script as the global object TSFE
173 *
174 * @author Kasper Skaarhoj <kasper@typo3.com>
175 * @package TYPO3
176 * @subpackage tslib
177 */
178 class tslib_fe {
179
180 // CURRENT PAGE:
181 var $id=''; // The page id (int)
182 var $type=''; // RO The type (int)
183 var $idParts=array(); // Loaded with the id, exploded by ','
184 var $cHash=''; // The submitted cHash
185 var $no_cache=''; // Page will not be cached. Write only true. Never clear value (some other code might have reasons to set it true)
186 var $rootLine=''; // The rootLine (all the way to tree root, not only the current site!) (array)
187 var $page=''; // The pagerecord (array)
188 var $contentPid=0; // 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.
189 var $sys_page=''; // The object with pagefunctions (object)
190 var $jumpurl='';
191 var $pageNotFound=0; // Is set to 1 if a pageNotFound handler could have been called.
192 var $domainStartPage=0; // Domain start page
193 var $MP='';
194 var $RDCT='';
195 var $page_cache_reg1=0; // 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...
196
197 // USER
198 var $fe_user=''; // The user (object)
199 var $loginUser=''; // Global falg 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.
200 var $gr_list=''; // (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...
201 var $beUserLogin=''; // Flag that indicates if a Backend user is logged in!
202
203 // PREVIEW
204 var $fePreview=''; // 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.
205 var $showHiddenPage=''; // Flag indicating that hidden pages should be shown, selected and so on. This goes for almost all selection of pages!
206 var $showHiddenRecords=''; // 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.
207 var $simUserGroup='0'; // Value that contains the simulated usergroup if any
208
209 // CONFIGURATION
210 var $TYPO3_CONF_VARS=array(); // The configuration array as set up in t3lib/config_default.php. Should be an EXACT copy of the global array.
211 var $config=''; // 'CONFIG' object from TypoScript. Array generated based on the TypoScript configuration of the current page. Saved with the cached pages.
212
213 // TEMPLATE / CACHE
214 var $tmpl=''; // The TypoScript template object. Used to parse the TypoScript template
215 var $cacheTimeOutDefault=''; // Is set to the time-to-live time of cached pages. If false, default is 60*60*24, which is 24 hours.
216 var $cacheContentFlag=''; // Set internally if cached content is fetched from the database
217 var $all=''; // $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.
218 var $sPre=''; // toplevel - objArrayName, eg 'page'
219 var $pSetup=''; // TypoScript configuration of the page-object pointed to by sPre. $this->tmpl->setup[$this->sPre.'.']
220 var $newHash=''; // 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
221 var $getMethodUrlIdToken=''; // 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
222 var $noCacheBeforePageGen=''; // 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.
223 var $tempContent=''; // This flag indicates if temporary content went into the cache during page-generation.
224 var $forceTemplateParsing=''; // Boolean, passed to TypoScript template class and tells it to render the template forcibly
225 var $cHash_array=array(); // The array which cHash_calc is based on, see ->makeCacheHash().
226 var $hash_base=''; // Loaded with the serialized array that is used for generating a hashstring for the cache
227 var $pagesTSconfig=''; // May be set to the pagesTSconfig
228 // PAGE-GENERATION / cOBJ
229 /*
230 Eg. insert JS-functions in this array ($additionalHeaderData) to include them once. Use associative keys.
231 Keys in use:
232 JSFormValidate : <script type="text/javascript" src="'.$GLOBALS["TSFE"]->absRefPrefix.'t3lib/jsfunc.validateform.js"></script>
233 JSincludeFormupdate : <script type="text/javascript" src="t3lib/jsfunc.updateform.js"></script>
234 JSMenuCode, JSMenuCode_menu : JavaScript for the JavaScript menu
235 JSCode : reserved
236 JSImgCode : reserved
237 */
238 var $additionalHeaderData=array(); // 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[] = '...')
239 var $additionalJavaScript=array(); // used to accumulate additional JavaScript-code. Works like additionalHeaderData. Reserved keys at 'openPic' and 'mouseOver'
240 var $additionalCSS=array(); // used to accumulate additional Style code. Works like additionalHeaderData.
241 var $JSeventFuncCalls = array( // 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
242 'onmousemove' => array(),
243 'onmouseup' => array(),
244 'onload' => array(),
245 );
246 var $JSCode=''; // Depreciated, use additionalJavaScript instead.
247 var $JSImgCode=''; // Used to accumulate JavaScript loaded images (by menus)
248 var $divSection=''; // Used to accumulate DHTML-layers.
249
250 // RENDERING configuration, settings from TypoScript is loaded into these vars. See pagegen.php
251 var $debug=''; // Debug flag, may output special debug html-code.
252 var $intTarget=''; // Default internal target
253 var $extTarget=''; // Default external target
254 var $MP_defaults=array(); // Keys are page ids and values are default &MP (mount point) values to set when using the linking features...)
255 var $spamProtectEmailAddresses=0; // If set, typolink() function encrypts email addresses. Is set in pagegen-class.
256 var $absRefPrefix=''; // Absolute Reference prefix
257 var $absRefPrefix_force=0; // 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 '/'
258 var $compensateFieldWidth=''; // Factor for form-field widths compensation
259 var $lockFilePath=''; // Lock file path
260 var $ATagParams=''; // <A>-tag parameters
261 var $sWordRegEx=''; // 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.
262 var $sWordList=''; // Is set to the incoming array sword_list in case of a page-view jumped to from a search-result.
263 var $linkVars=''; // 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.
264 var $displayEditIcons=''; // 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.
265 var $displayFieldEditIcons=''; // 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.
266 var $sys_language_uid=0; // Site language, 0 (zero) is default, int+ is uid pointing to a sys_language record.
267 var $sys_language_isocode = ''; // Is set to the iso code of the sys_language if that is properly defined by the sys_language record representing the sys_language_uid. (Requires the extension "static_info_tables")
268
269 // RENDERING data
270 var $applicationData=Array(); // 'Global' Storage for various applications. Keys should be 'tx_'.extKey for extensions.
271 var $register=Array();
272 var $registerStack=Array(); // Stack used for storing array and retrieving register arrays (see LOAD_REGISTER and CLEAR_REGISTER)
273 var $cObjectDepthCounter = 50; // Checking that the function is not called eternally. This is done by interrupting at a depth of 50
274 var $recordRegister = Array(); // used by cObj->RECORDS and cObj->CONTENT to ensure the a records is NOT rendered twice through it!
275 var $currentRecord = ''; // 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
276 var $accessKey =array(); // Used by class tslib_menu to keep track of access-keys.
277 var $imagesOnPage=array(); // Numerical array where image filenames are added if they are referenced in the rendered document. This includes only TYPO3 generated/inserted images.
278 var $lastImageInfo=array(); // 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
279 var $uniqueCounter=0; // 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()
280 var $uniqueString='';
281 var $indexedDocTitle=''; // This value will be used as the title for the page in the indexer (if indexing happens)
282 var $altPageTitle=''; // Alternative page title (normally the title of the page record). Can be set from applications you make.
283 var $pEncAllowedParamNames=array(); // An array that holds parameter names (keys) of GET parameters which MAY be MD5/base64 encoded with simulate_static_documents method.
284
285 // Page content render object
286 var $cObj =''; // is instantiated object of tslib_cObj
287
288 // Character set (charset) conversion object:
289 var $csConvObj; // An instance of the "t3lib_cs" class. May be used by any application.
290
291 // CONTENT accumulation
292 var $content=''; // All page content is accumulated in this variable. See pagegen.php
293
294 // GENERAL
295 var $clientInfo=''; // Set to the browser: net / msie if 4+ browsers
296 var $scriptParseTime=0;
297 var $TCAloaded = 0; // Set ONLY if the full TCA is loaded
298
299 // LANG:
300 var $lang='';
301 var $langSplitIndex=0;
302 var $LL_labels_cache=array();
303 var $LL_files_cache=array();
304
305
306
307
308
309 /**
310 * Class constructor
311 * Takes a number of GET/POST input variable as arguments and stores them internally.
312 * The processing of these variables goes on later in this class.
313 * Also sets internal clientInfo array (browser information) and a unique string (->uniqueString) for this script instance; A md5 hash of the microtime()
314 *
315 * @param array The global $TYPO3_CONF_VARS array. Will be set internally in ->TYPO3_CONF_VARS
316 * @param mixed The value of t3lib_div::GPvar('id')
317 * @param integer The value of t3lib_div::GPvar('type')
318 * @param boolean The value of t3lib_div::GPvar('no_cache'), evaluated to 1/0
319 * @param string The value of t3lib_div::GPvar('cHash')
320 * @param string The value of t3lib_div::GPvar('jumpurl')
321 * @param string The value of t3lib_div::GPvar('MP')
322 * @param string The value of t3lib_div::GPvar('RDCT')
323 * @return void
324 * @see index_ts.php
325 */
326 function tslib_fe($TYPO3_CONF_VARS, $id, $type, $no_cache='', $cHash='', $jumpurl='',$MP='',$RDCT='') {
327 // Setting some variables:
328 $this->id = $id;
329 $this->type = $type;
330 $this->no_cache = $no_cache ? 1 : 0;
331 $this->cHash = $cHash;
332 $this->jumpurl = $jumpurl;
333 $this->MP = $TYPO3_CONF_VARS['FE']['enable_mount_pids']?$MP:'';
334 $this->RDCT = $RDCT;
335 $this->TYPO3_CONF_VARS = $TYPO3_CONF_VARS;
336 $this->clientInfo = t3lib_div::clientInfo();
337 $this->uniqueString=md5(microtime());
338
339 $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
340 }
341
342 /**
343 * Connect to MySQL
344 * May exit after outputting an error message or some JavaScript redirecting to the install tool.
345 *
346 * @return void
347 */
348 function connectToMySQL() {
349 if (@mysql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password)) {
350 if (!TYPO3_db) {
351 $this->printError('No database selected','Database Error');
352 // Redirects to the Install Tool:
353 echo '<script type="text/javascript">
354 /*<![CDATA[*/
355 document.location = "'.TYPO3_mainDir.'install/index.php?mode=123&step=1&password=joh316";
356 /*]]>*/
357 </script>';
358 exit;
359 } elseif (!mysql_select_db(TYPO3_db)) {
360 $this->printError('Cannot connect to the current database, "'.TYPO3_db.'"','Database Error');
361 exit;
362 }
363 } else {
364 if (!TYPO3_db) {
365 // Redirects to the Install Tool:
366 echo '<script type="text/javascript">
367 /*<![CDATA[*/
368 document.location = "'.TYPO3_mainDir.'install/index.php?mode=123&step=1&password=joh316";
369 /*]]>*/
370 </script>';
371 exit;
372 }
373 $this->printError('The current username, password or host was not accepted when the connection to the database was attempted to be established!','Database Error');
374 exit;
375 }
376 }
377
378 /**
379 * Looks up the value of $this->RDCT in the database and if it is found to be associated with a redirect URL then the redirection is carried out with a 'Location:' header
380 * May exit after sending a location-header.
381 *
382 * @return void
383 */
384 function sendRedirect() {
385 $query='SELECT params FROM cache_md5params WHERE md5hash="'.addslashes($this->RDCT).'"';
386 $res=mysql(TYPO3_db,$query);
387 echo mysql_error();
388 if ($row=mysql_fetch_assoc($res)) {
389 $this->updateMD5paramsRecord($this->RDCT);
390 header('Location: '.$row['params']);
391 exit;
392 }
393 }
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412 /********************************************
413 *
414 * Initializing, resolving page id
415 *
416 ********************************************/
417
418
419 /**
420 * Initializes the front-end login user.
421 *
422 * @return void
423 */
424 function initFEuser() {
425 $this->fe_user = t3lib_div::makeInstance('tslib_feUserAuth');
426
427 $this->fe_user->checkPid = $this->TYPO3_CONF_VARS['FE']['checkFeUserPid'];
428 $this->fe_user->checkPid_value = implode(',',t3lib_div::intExplode(',',t3lib_div::GPvar('pid'))); // List of pid's acceptable
429
430 // Check if a session is transferred:
431 if (t3lib_div::GPvar('FE_SESSION_KEY')) {
432 $fe_sParts = explode('-',t3lib_div::GPvar('FE_SESSION_KEY'));
433 if (!strcmp(md5($fe_sParts[0].'/'.$this->TYPO3_CONF_VARS['SYS']['encryptionKey']), $fe_sParts[1])) { // If the session key hash check is OK:
434 $GLOBALS['HTTP_COOKIE_VARS'][$this->fe_user->name]=$fe_sParts[0];
435 $this->fe_user->forceSetCookie=1;
436 }
437 }
438
439 if ($this->TYPO3_CONF_VARS['FE']['dontSetCookie']) {
440 $this->fe_user->dontSetCookie=1;
441 }
442
443 $this->fe_user->start();
444 $this->fe_user->unpack_uc('');
445 $this->fe_user->fetchSessionData(); // Gets session data
446 $recs = t3lib_div::GPvar('recs');
447 if (is_array($recs)) { // If any record registration is submitted, register the record.
448 $this->fe_user->record_registration($recs);
449 }
450
451 // For every 60 seconds the is_online timestamp is updated.
452 if (is_array($this->fe_user->user) && $this->fe_user->user['is_online']<($GLOBALS['EXEC_TIME']-60)) {
453 $query='UPDATE fe_users SET is_online='.intval($GLOBALS['EXEC_TIME']).' WHERE uid='.intval($this->fe_user->user['uid']);
454 $res=mysql(TYPO3_db,$query);
455 echo mysql_error();
456 }
457 }
458
459 /**
460 * Provides ways to bypass the '?id=[xxx]&type=[xx]' format, using either PATH_INFO or virtual HTML-documents (using Apache mod_rewrite)
461 *
462 * Two options:
463 * 1) Apache mod_rewrite: Here a .htaccess file maps all .html-files to index.php and then we extract the id and type from the name of that HTML-file.
464 * 2) Use PATH_INFO (also Apache) to extract id and type from that var. Does not require any special modules compiled with apache.
465 *
466 * Support for RewriteRule to generate (simulateStaticDocuments)
467 * With the mod_rewrite compiled into apache, put these lines into a .htaccess in this directory:
468 * RewriteEngine On
469 * RewriteRule ^[^/]*\.html$ index.php
470 * The url must end with '.html' and the format must comply with either of these:
471 * 1: '[title].[id].[type].html' - title is just for easy recognition in the logfile!; no practical use of the title for TYPO3.
472 * 2: '[id].[type].html' - above, but title is omitted; no practical use of the title for TYPO3.
473 * 3: '[id].html' - only id, type is set to the default, zero!
474 * NOTE: In all case 'id' may be the uid-numer OR the page alias (if any)
475 *
476 * @return void
477 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&cHash=4ad9d7acb4
478 */
479 function checkAlternativeIdMethods() {
480 # IF (TYPO3_OS=='WIN') return; # Commenting out this line will make it work for windows Apache mod_rewrite as well.
481
482 // Redirect by mod_rewrite:
483 if ($GLOBALS['HTTP_SERVER_VARS']['REDIRECT_URL']) { // If there has been a redirect this can happend either due to a CGI-script or because of reWrite rule.
484 $uParts = parse_url($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']);
485 $requestFilename = trim(ereg_replace('.*\/','',$uParts['path'])); // This is the filename of the script/simulated html-file.
486 if ($requestFilename && substr($requestFilename,-4)!='.php') {
487 $parts = explode('.',ereg_replace('.*\/','',$requestFilename));
488 $pCount = count($parts);
489 if ($parts[$pCount-1]='html') {
490 if ($pCount>2) {
491 $this->type = intval($parts[$pCount-2]);
492 $this->id= $parts[$pCount-3];
493 } else {
494 $this->type = 0;
495 $this->id= $parts[0];
496 }
497 }
498 }
499 }
500 // If PATH_INFO
501 if (t3lib_div::getIndpEnv('PATH_INFO')) { // If pathinfo contains stuff...
502 # line below is NOT needed (anymore), because getIndpEnv already filters this out if needed. Only true PATH_INFO gets through.
503 # if (t3lib_div::getIndpEnv('PATH_INFO')!=t3lib_div::getIndpEnv('SCRIPT_NAME') && count(explode('/',t3lib_div::getIndpEnv('PATH_INFO')))>1) { // There must be at least one '/' in the path - else the PATH_INFO value does not make sense., ALSO t3lib_div::getIndpEnv('PATH_INFO')!=t3lib_div::getIndpEnv('SCRIPT_NAME') is necessary because some servers are seen to set pathinfo equal to script_name
504 $parts=t3lib_div::trimExplode('/',t3lib_div::getIndpEnv('PATH_INFO'),1);
505 $parts[]='html';
506 $pCount = count($parts);
507 if ($pCount>2) {
508 $this->type = intval($parts[$pCount-2]);
509 $this->id= $parts[$pCount-3];
510 } else {
511 $this->type = 0;
512 $this->id= $parts[0];
513 }
514 $this->absRefPrefix_force=1;
515 # }
516 }
517 }
518
519 /**
520 * Clears the preview-flags, sets sim_exec_time to current time.
521 * Hidden pages must be hidden as default, $GLOBALS['SIM_EXEC_TIME'] is set to $GLOBALS['EXEC_TIME'] in t3lib/config_default.inc. Alter it by adding or subtracting seconds.
522 *
523 * @return void
524 */
525 function clear_preview() {
526 $this->showHiddenPage = 0;
527 $this->showHiddenRecords = 0;
528 $GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
529 $this->fePreview = 0;
530 }
531
532 /**
533 * Determines the id and evaluates any preview settings
534 * 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.
535 *
536 * @return void
537 */
538 function determineId() {
539 // Getting ARG-v values if some
540 $this->setIDfromArgV();
541
542 // If there is a Backend login we are going to check for any preview settings:
543 $GLOBALS['TT']->push('beUserLogin','');
544 if ($this->beUserLogin) {
545 $this->fePreview = $GLOBALS['BE_USER']->extGetFeAdminValue('preview');
546
547 // If admin panel preview is enabled...
548 if ($this->fePreview) {
549 $fe_user_OLD_USERGROUP = $this->fe_user->user['usergroup'];
550
551 $this->showHiddenPage = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','showHiddenPages');
552 $this->showHiddenRecords = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','showHiddenRecords');
553 // simulate date
554 $simTime = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','simulateDate');
555 if ($simTime) $GLOBALS['SIM_EXEC_TIME']=$simTime;
556 // simulate user
557 $simUserGroup = $GLOBALS['BE_USER']->extGetFeAdminValue('preview','simulateUserGroup');
558 $this->simUserGroup = $simUserGroup;
559 if ($simUserGroup) $this->fe_user->user['usergroup']=$simUserGroup;
560 if (!$simUserGroup && !$simTime && !$this->showHiddenPage && !$this->showHiddenRecords) {
561 $this->fePreview=0;
562 }
563 }
564
565 // Now it's investigated if the raw page-id points to a hidden page and if so, the flag is set.
566 // This does not require the preview flag to be set in the admin panel
567 if ($this->id) {
568 $idQ = t3lib_div::testInt($this->id) ? 'uid="'.intval($this->id).'"' : 'alias="'.addslashes($this->id).'"';
569 $query='SELECT hidden FROM pages WHERE '.$idQ.' AND hidden AND NOT deleted';
570 $GLOBALS['TT']->setTSselectQuery($query,'determineId');
571 $res = mysql(TYPO3_db, $query);
572 if (mysql_num_rows($res)) {
573 $this->fePreview=1; // The preview flag is set only if the current page turns out to actually be hidden!
574 $this->showHiddenPage = 1;
575 }
576 }
577
578 if ($this->fePreview) { // If the front-end is showing a preview, caching MUST be disabled.
579 $this->set_no_cache();
580 }
581 }
582 $GLOBALS['TT']->pull();
583
584 // Now, get the id, validate access etc:
585 $this->fetch_the_id();
586
587 // Check if backend user has read access to this page. If not, recalculate the id.
588 if ($this->beUserLogin && $this->fePreview) {
589 if (!$GLOBALS['BE_USER']->doesUserHaveAccess($this->page,1)) {
590 // Resetting
591 $this->clear_preview();
592 $this->fe_user->user['usergroup'] = $fe_user_OLD_USERGROUP;
593 // Fetching the id again, now with the preview settings reset.
594 $this->fetch_the_id();
595 }
596 }
597 // Final cleaning.
598 $this->id=$this->contentPid=intval($this->id); // Make sure it's an integer
599 $this->type=intval($this->type); // Make sure it's an integer
600 }
601
602 /**
603 * Get The Page ID
604 * This gets the id of the page, checks if the page is in the domain and if the page is accessible
605 * Sets variables such as $this->sys_page, $this->loginUser, $this->gr_list, $this->id, $this->type, $this->domainStartPage, $this->idParts
606 *
607 * @return void
608 * @access private
609 */
610 function fetch_the_id() {
611 $GLOBALS['TT']->push('fetch_the_id initialize/','');
612
613 // Initialize the page-select functions.
614 $this->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
615 $this->sys_page->init($this->showHiddenPage);
616
617 // Sets ->loginUser and ->gr_list based on front-end user status.
618 $this->fe_user->showHiddenRecords = $this->showHiddenRecords; // This affects the hidden-flag selecting the fe_groups for the user!
619 if (is_array($this->fe_user->user) && $this->fe_user->fetchGroupData()) {
620 $this->loginUser=1; // global flag!
621 $this->gr_list = '0,-2'; // 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!
622 $gr_array = $this->fe_user->groupData['uid'];
623 } else {
624 $this->loginUser=0;
625 $this->gr_list = '0,-1'; // 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!
626 $gr_array=array();
627 }
628
629 // ADD group-numbers if the IPmask matches.
630 if (is_array($GLOBALS['TYPO3_CONF_VARS']['FE']['IPmaskMountGroups'])) {
631 reset($GLOBALS['TYPO3_CONF_VARS']['FE']['IPmaskMountGroups']);
632 while(list(,$IPel)=each($GLOBALS['TYPO3_CONF_VARS']['FE']['IPmaskMountGroups'])) {
633 if (t3lib_div::getIndpEnv('REMOTE_ADDR') && $IPel[0] && t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'),$IPel[0])) {$gr_array[]=intval($IPel[1]);}
634 }
635 }
636
637 // Clean up.
638 $gr_array = array_unique($gr_array); // Make unique...
639 sort($gr_array); // sort
640 if (count($gr_array)) {
641 $this->gr_list.=','.implode(',',$gr_array);
642 }
643
644 // Sets sys_page where-clause
645 $this->sys_page->where_hid_del.=' AND doktype<200 AND fe_group IN ('.$this->gr_list.')';
646
647 // Splitting $this->id by a period (.). First part is 'id' and second part - if exists - will overrule the &type param if given
648 $pParts = explode('.',$this->id);
649 $this->id = $pParts[0]; // Set it.
650 if (isset($pParts[1])) {$this->type=$pParts[1];}
651
652 // Splitting $this->id by a comma (,). First part is 'id' and other parts are just stored for use in scripts.
653 $this->idParts = explode(',',$this->id);
654
655 // Splitting by a '+' sign - used for base64/md5 methods of parameter encryption for simulate static documents.
656 list($pgID,$SSD_p)=explode('+',$this->idParts[0],2);
657 if ($SSD_p) { $this->idPartsAnalyze($SSD_p); }
658 $this->id = $pgID; // Set id
659
660 // If $this->id is a string, it's an alias
661 $this->checkAndSetAlias();
662
663 // The id and type is set to the integer-value - just to be sure...
664 $this->id = intval($this->id);
665 $this->type = intval($this->type);
666 $GLOBALS['TT']->pull();
667
668 // We find the first page belonging to the current domain
669 $GLOBALS['TT']->push('fetch_the_id domain/','');
670 $this->domainStartPage = $this->findDomainRecord($GLOBALS['TYPO3_CONF_VARS']['SYS']['recursiveDomainSearch']); // the page_id of the current domain
671 if (!$this->id) {
672 if ($this->domainStartPage) {
673 $this->id = $this->domainStartPage; // If the id was not previously set, set it to the id of the domain.
674 } else {
675 $theFirstPage = $this->sys_page->getFirstWebPage($this->id); // Find the first 'visible' page in that domain
676 if ($theFirstPage) {
677 $this->id = $theFirstPage['uid'];
678 } else {
679 $this->printError('No pages are found on the rootlevel!');
680 exit;
681 }
682 }
683 }
684 $GLOBALS['TT']->pull();
685
686 $GLOBALS['TT']->push('fetch_the_id rootLine/','');
687 $requestedId = $this->id; // We store the originally requested id
688 $this->getPageAndRootlineWithDomain($this->domainStartPage);
689 $GLOBALS['TT']->pull();
690
691 if ($this->pageNotFound && $this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
692 $this->pageNotFoundHandler($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling'],$this->TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader']);
693 }
694
695 // set no_cache if set
696 if ($this->page['no_cache']) {
697 $this->set_no_cache();
698 }
699 // Init SYS_LASTCHANGED
700 $this->register['SYS_LASTCHANGED'] = intval($this->page['tstamp']);
701 }
702
703 /**
704 * Gets the page and rootline arrays based on the id, $this->id
705 *
706 * If the id does not correspond to a proper page, the 'previous' valid page in the rootline is found
707 * If the page is a shortcut (doktype=4), the ->id is loaded with that id
708 *
709 * 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.
710 *
711 * Sets or manipulates internal variables such as: $this->id, $this->page, $this->rootLine, $this->MP, $this->pageNotFound
712 *
713 * @return void
714 * @access private
715 */
716 function getPageAndRootline() {
717 $this->page = $this->sys_page->getPage($this->id);
718 if (!count($this->page)) {
719 // If no page, we try to find the page before in the rootLine.
720 $this->pageNotFound=1; // Page is 'not found' in case the id itself was not an accessible page. code 1
721 $this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
722 if (count($this->rootLine)) {
723 $c=count($this->rootLine)-1;
724 while($c>0) {
725 $c--;
726 $this->id=$this->rootLine[$c]['uid'];
727 $this->page = $this->sys_page->getPage($this->id);
728 if (count($this->page)){break;}
729 }
730 }
731 // If still no page...
732 if (!count($this->page)) {
733 $this->printError('The requested page does not exist!');
734 exit;
735 }
736 }
737 // Is the ID a link to another page??
738 if ($this->page['doktype']==4) {
739 $this->MP=''; // 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.
740 $this->page = $this->getPageShortcut($this->page['shortcut'],$this->page['shortcut_mode'],$this->page['uid']);
741 $this->id = $this->page['uid'];
742 }
743 // Gets the rootLine
744 $this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
745
746 // If not rootline we're off...
747 if (!count($this->rootLine)) {
748 $this->printError('The requested page didn\'t have a proper connection to the tree-root!');
749 exit;
750 }
751
752 // Checking for include section regarding the hidden/starttime/endtime/fe_user (that is access control of a whole subbranch!)
753 if ($this->checkRootlineForIncludeSection()) {
754 if (!count($this->rootLine)) {
755 $this->printError('The requested page was not accessible!');
756 exit;
757 } else {
758 $el = reset($this->rootLine);
759 $this->id = $el['uid'];
760 $this->page = $this->sys_page->getPage($this->id);
761 $this->rootLine = $this->sys_page->getRootLine($this->id,$this->MP);
762 }
763 }
764 }
765
766 /**
767 * Get page shortcut
768 *
769 * @param integer The value of the "shortcut" field from the pages record
770 * @param integer The shortcut mode: 1 and 2 will select either first subpage or random subpage; the default is the page pointed to by $SC
771 * @param integer The current page UID of the page which is a shortcut
772 * @param integer 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...)
773 * @param array An array filled with previous page uids tested by the function - new page uids are evaluated against this to avoid going in circles.
774 * @return mixed Returns the page record of the page that the shortcut pointed to.
775 * @access private
776 * @see getPageAndRootline()
777 */
778 function getPageShortcut($SC,$mode,$thisUid,$itera=20,$pageLog=array()) {
779 $idArray = t3lib_div::intExplode(',',$SC);
780 switch($mode) {
781 case 1:
782 case 2:
783 $pageArray = $this->sys_page->getMenu($idArray[0]?$idArray[0]:$thisUid,'*','sorting','AND pages.doktype<199 AND pages.doktype!=6');
784 $pO=0;
785 if ($mode==2 && count($pageArray)) { // random
786 $this->make_seed();
787 $randval = intval(rand(0,count($pageArray)-1));
788 $pO=$randval;
789 }
790 $c=0;
791 reset($pageArray);
792 while(list(,$pV)=each($pageArray)) {
793 if ($c==$pO) {
794 $page = $pV;
795 break;
796 }
797 $c++;
798 }
799 break;
800 default:
801 $page = $this->sys_page->getPage($idArray[0]);
802 break;
803 }
804 if ($page['doktype']==4) {
805 if (!in_array($page['uid'],$pageLog) && $itera>0) {
806 $pageLog[] = $page['uid'];
807 $page = $this->getPageShortcut($page['shortcut'],$page['shortcut_mode'],$page['uid'],$itera-1,$pageLog);
808 } else {
809 $pageLog[] = $page['uid'];
810 $this->printError('Page shortcuts were looping in uids '.implode(',',$pageLog).'...!');
811 exit;
812 }
813 }
814 return $page;
815 }
816
817 /**
818 * Checks the current rootline for defined sections.
819 *
820 * @return boolean
821 * @access private
822 */
823 function checkRootlineForIncludeSection() {
824 $c=count($this->rootLine);
825 $removeTheRestFlag=0;
826 for ($a=0;$a<$c;$a++) {
827 if (!$this->checkPagerecordForIncludeSection($this->rootLine[$a])) {
828 $removeTheRestFlag=1;
829 }
830 if ($this->rootLine[$a]['doktype']==6) {
831 if ($this->beUserLogin) { // If there is a backend user logged in, check if he has read access to the page:
832 $query = 'SELECT uid FROM pages WHERE uid='.$this->id.' AND '.$GLOBALS['BE_USER']->getPagePermsClause(1);
833 $res=mysql(TYPO3_db,$query);
834 list($isPage)=mysql_fetch_row($res);
835 if (!$isPage) $removeTheRestFlag=1; // 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...
836 } else { // Dont go here, if there is no backend user logged in.
837 $removeTheRestFlag=1;
838 }
839 }
840 if ($removeTheRestFlag) {
841 $this->pageNotFound=2; // Page is 'not found' in case a subsection was found and not accessible, code 2
842 unset($this->rootLine[$a]);
843 }
844 }
845 return $removeTheRestFlag;
846 }
847
848 /**
849 * Checks page record for enableFields
850 * Returns true if enableFields does not disable the page record.
851 * Takes notice of the ->showHiddenPage flag and uses SIM_EXEC_TIME for start/endtime evaluation
852 *
853 * @param array The page record to evaluate (needs fields; hidden, starttime, endtime, fe_group)
854 * @return boolean True, if record is viewable.
855 * @see tslib_cObj::getTreeList(), checkPagerecordForIncludeSection()
856 */
857 function checkEnableFields($row) {
858 if ((!$row['hidden'] || $this->showHiddenPage)
859 && $row['starttime']<=$GLOBALS['SIM_EXEC_TIME']
860 && ($row['endtime']==0 || $row['endtime']>$GLOBALS['SIM_EXEC_TIME'])
861 && t3lib_div::inList($this->gr_list,$row['fe_group'])
862 ) {
863 return 1;
864 }
865 }
866
867 /**
868 * Checks page record for include section
869 *
870 * @param array The page record to evaluate (needs fields;extendToSubpages + hidden, starttime, endtime, fe_group)
871 * @return boolean Returns true if either extendToSubpages is not checked or if the enableFields does not disable the page record.
872 * @access private
873 * @see checkEnableFields(), tslib_cObj::getTreeList(), checkRootlineForIncludeSection()
874 */
875 function checkPagerecordForIncludeSection($row) {
876 return (!$row['extendToSubpages'] || $this->checkEnableFields($row)) ? 1 : 0;
877 }
878
879 /**
880 * This checks if there are ARGV-parameters in the QUERY_STRING and if so, those are used for the id
881 * $this->id must be 'false' in order for any processing to happen in here
882 * If an id/alias value is extracted from the QUERY_STRING it is set in $this->id
883 *
884 * @return void
885 * @access private
886 */
887 function setIDfromArgV() {
888 if (!$this->id) {
889 list($theAlias) = explode('&',t3lib_div::getIndpEnv('QUERY_STRING'));
890 $theAlias = trim($theAlias);
891 $this->id = $theAlias ? $theAlias : 0;
892 }
893 }
894
895 /**
896 * Gets ->page and ->rootline information based on ->id. ->id may change during this operation.
897 * If not inside domain, then default to first page in domain.
898 *
899 * @param integer Page uid of the page where the found domain record is (pid of the domain record)
900 * @return void
901 * @access private
902 */
903 function getPageAndRootlineWithDomain($domainStartPage) {
904 $this->getPageAndRootline();
905
906 // 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.
907 if ($domainStartPage && is_array($this->rootLine)) {
908 reset ($this->rootLine);
909 $idFound = 0;
910 while(list($key,$val)=each($this->rootLine)) {
911 if ($val['uid']==$domainStartPage) {
912 $idFound=1;
913 break;
914 }
915 }
916 if (!$idFound) {
917 $this->pageNotFound=3; // Page is 'not found' in case the id was outside the domain, code 3
918 $this->id = $domainStartPage;
919 $this->getPageAndRootline(); //re-get the page and rootline if the id was not found.
920 }
921 }
922 }
923
924 /**
925 * Looking up a domain record based on HTTP_HOST
926 *
927 * @param boolean 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.
928 * @return integer Returns the page id of the page where the domain record was found.
929 * @access private
930 */
931 function findDomainRecord($recursive=0) {
932 if ($recursive) {
933 $host = explode('.',t3lib_div::getIndpEnv('HTTP_HOST'));
934 while(count($host)) {
935 $pageUid = $this->sys_page->getDomainStartPage(implode('.',$host),t3lib_div::getIndpEnv('SCRIPT_NAME'),t3lib_div::getIndpEnv('REQUEST_URI'));
936 if ($pageUid) return $pageUid; else array_shift($host);
937 }
938 return $pageUid;
939 } else {
940 return $this->sys_page->getDomainStartPage(t3lib_div::getIndpEnv('HTTP_HOST'),t3lib_div::getIndpEnv('SCRIPT_NAME'),t3lib_div::getIndpEnv('REQUEST_URI'));
941 }
942 }
943
944 /**
945 * Page not found handler.
946 * Exits.
947 *
948 * @param mixed Which type of handling; If a true PHP-boolean and TRUE then a ->printError message is outputted. If integer an error message with that number is shown. Otherwise the $code value is expected to be a "Location:" header value.
949 * @param string If set, this is passed directly to the PHP function, header()
950 * @return void (The function exists!)
951 */
952 function pageNotFoundHandler($code,$header='') {
953 if ($header) {header($header);}
954
955 if (gettype($code)=='boolean' || !strcmp($code,1)) {
956 $this->printError('The page did not exist or was inaccessible.');
957 exit;
958 } else if (t3lib_div::testInt($code)) {
959 $this->printError('Error '.$code);
960 exit;
961 } else {
962 header('Location: '.t3lib_div::locationHeaderUrl($code));
963 exit;
964 }
965 }
966
967 /**
968 * Fetches the integer page id for a page alias.
969 * 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
970 *
971 * @return void
972 * @access private
973 */
974 function checkAndSetAlias() {
975 if ($this->id && !t3lib_div::testInt($this->id)) {
976 $aid = $this->sys_page->getPageIdFromAlias($this->id);
977 if ($aid) {$this->id=$aid;}
978 }
979 }
980
981 /**
982 * Analyzes the second part of a id-string (after the "+"), looking for B6 or M5 encoding and if found it will resolve it and restore the variables in global HTTP_GET_VARS (but NOT $_GET - yet)
983 * If values for ->cHash, ->no_cache, ->jumpurl and ->MP is found, they are also loaded into the internal vars of this class.
984 *
985 * @param string String to analyze
986 * @return void
987 * @access private
988 */
989 function idPartsAnalyze($str) {
990 $GET_VARS='';
991 switch(substr($str,0,2)) {
992 case 'B6':
993 $addParams=base64_decode(str_replace('_','=',str_replace('-','/',substr($str,2))));
994 parse_str($addParams,$GET_VARS);
995 break;
996 case 'M5':
997 $query='SELECT params FROM cache_md5params WHERE md5hash="'.addslashes(substr($str,2)).'"';
998 $res=mysql(TYPO3_db,$query);
999 $row=mysql_fetch_assoc($res);
1000 $this->updateMD5paramsRecord(substr($str,2));
1001 parse_str($row['params'],$GET_VARS);
1002 break;
1003 }
1004 if (is_array($GET_VARS)) {
1005 if (!is_array($GLOBALS['HTTP_GET_VARS'])) $GLOBALS['HTTP_GET_VARS']=array();
1006 $GLOBALS['HTTP_GET_VARS']=t3lib_div::array_merge_recursive_overrule($GLOBALS['HTTP_GET_VARS'],$GET_VARS);
1007 // Setting these specifically (like in the init-function):
1008 if (isset($GET_VARS['cHash'])) $this->cHash=$GET_VARS['cHash'];
1009 if (isset($GET_VARS['no_cache'])) $this->no_cache=$GET_VARS['no_cache'] ? 1 : 0;
1010 if (isset($GET_VARS['jumpurl'])) $this->jumpurl=$GET_VARS['jumpurl'];
1011 if (isset($GET_VARS['MP'])) $this->MP=$this->TYPO3_CONF_VARS['FE']['enable_mount_pids'] ? $GET_VARS['MP'] : '';
1012 }
1013 }
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033 /********************************************
1034 *
1035 * Template and caching related functions.
1036 *
1037 *******************************************/
1038
1039 /**
1040 * Calculates a hash string based on additional parameters in the url. This is used to cache pages with more parameters than just id and type
1041 *
1042 * @return void
1043 */
1044 function makeCacheHash() {
1045 if ($this->cHash && is_array($GLOBALS['HTTP_GET_VARS'])) {
1046 $pA = $this->cHashParams(t3lib_div::implodeArrayForUrl('',$GLOBALS['HTTP_GET_VARS']));
1047 $this->cHash_array = $pA;
1048 $cHash_calc = t3lib_div::shortMD5(serialize($this->cHash_array));
1049 if ($cHash_calc!=$this->cHash) {
1050 $this->set_no_cache();
1051 $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($pA),',').'"',2);
1052 }
1053 }
1054 }
1055
1056 /**
1057 * Splits the input query-parameters into an array with certain parameters filtered out.
1058 * Used to create the cHash value
1059 *
1060 * @param string Query-parameters: "&xxx=yyy&zzz=uuu"
1061 * @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
1062 * @access private
1063 * @see makeCacheHash(), tslib_cObj::typoLink()
1064 */
1065 function cHashParams($addQueryParams) {
1066 $params = explode('&',substr($addQueryParams,1)); // Splitting parameters up
1067 $pA=array();
1068 while(list(,$theP)=each($params)) {
1069 $pKV = explode('=',$theP); // SPlitting single param by '=' sign
1070 if (!t3lib_div::inList('id,type,no_cache,cHash,MP,ftu',$pKV[0])) {
1071 $pA[$pKV[0]]=(string)rawurldecode($pKV[1]);
1072 }
1073 }
1074 $pA['encryptionKey']=$this->TYPO3_CONF_VARS['SYS']['encryptionKey'];
1075 ksort($pA);
1076 return $pA;
1077 }
1078
1079 /**
1080 * Initialize the TypoScript template parser
1081 *
1082 * @return void
1083 */
1084 function initTemplate() {
1085 $this->tmpl = t3lib_div::makeInstance('t3lib_TStemplate');
1086 $this->tmpl->init();
1087 $this->tmpl->tt_track= $this->beUserLogin ? 1 : 0;
1088 }
1089
1090 /**
1091 * See if page is in cache and get it if so
1092 * Stores the page content in $this->content if something is found.
1093 *
1094 * @return void
1095 */
1096 function getFromCache() {
1097 $this->tmpl->getCurrentPageData();
1098 $cc=Array();
1099 if (is_array($this->tmpl->currentPageData)) {
1100 // BE CAREFULL 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.
1101 // If this hash is not the same in here in this section and after page-generation the page will not be properly cached!
1102
1103 $cc['all'] = $this->tmpl->currentPageData['all'];
1104 $cc['rowSum'] = $this->tmpl->currentPageData['rowSum'];
1105 $cc['rootLine'] = $this->tmpl->currentPageData['rootLine']; // This rootline is used with templates only (matching()-function)
1106 $this->all = $this->tmpl->matching($cc); // 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.
1107 ksort($this->all);
1108 }
1109
1110 $this->content=''; // clearing the content-variable, which will hold the pagecontent
1111 unset($this->config); // Unsetting the lowlevel config
1112 $this->cacheContentFlag=0;
1113 if ($this->all && !$this->no_cache) {
1114 $this->newHash = $this->getHash();
1115 $query = 'SELECT S.* FROM cache_pages S,pages P
1116 WHERE S.hash="'.$this->newHash.'"
1117 AND S.page_id=P.uid
1118 AND S.expires > '.$GLOBALS['EXEC_TIME'].'
1119 AND NOT P.deleted
1120 AND NOT P.hidden
1121 AND P.starttime<='.$GLOBALS['EXEC_TIME'].'
1122 AND (P.endtime=0 OR P.endtime>'.$GLOBALS['EXEC_TIME'].')';
1123 $GLOBALS['TT']->setTSselectQuery($query,'getFromCache');
1124
1125 $GLOBALS['TT']->push('Cache Query','');
1126 $res = mysql (TYPO3_db, $query); // getting cached page.
1127 $GLOBALS['TT']->pull();
1128 $GLOBALS['TT']->push('Cache Row','');
1129 if ($row = mysql_fetch_assoc($res)) {
1130 $this->config = unserialize($row['cache_data']); // Fetches the lowlevel config stored with the cached data
1131 $this->content = $row['HTML']; // Getting the content
1132 $this->cacheContentFlag=1; // Setting flag, so we know, that some cached content is gotten.
1133
1134 if ($this->TYPO3_CONF_VARS['FE']['debug'] || $this->config['config']['debug']) {
1135 $this->content.=chr(10).'<!-- Cached page generated '.Date('d/m Y H:i', $row['tstamp']).'. Expires '.Date('d/m Y H:i', $row['expires']).' -->';
1136 }
1137 }
1138 $GLOBALS['TT']->pull();
1139 }
1140 }
1141
1142 /**
1143 * Calculates the cache-hash
1144 * This hash is unique to the template, the variables ->id, ->type, ->gr_list (list of groups), ->MP (Mount Points) and cHash array
1145 * Used to get and later store the cached data.
1146 *
1147 * @return string MD5 hash of $this->hash_base which is a serialized version of there variables.
1148 * @access private
1149 * @see getFromCache()
1150 */
1151 function getHash() {
1152 $this->hash_base = serialize(
1153 array(
1154 'all'=>$this->all,
1155 'id'=>intval($this->id),
1156 'type'=>intval($this->type),
1157 'gr_list'=>$this->gr_list,
1158 'MP'=>$this->MP,
1159 'cHash'=>$this->cHash_array
1160 )
1161 );
1162 return md5($this->hash_base);
1163 }
1164
1165 /**
1166 * Checks if config-array exists already but if not, gets it
1167 *
1168 * @return void
1169 */
1170 function getConfigArray() {
1171 if (!is_array($this->config) || is_array($this->config['INTincScript']) || $this->forceTemplateParsing) { // 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
1172 $GLOBALS['TT']->push('Parse template','');
1173
1174 // Force parsing, if set?:
1175 $this->tmpl->forceTemplateParsing = $this->forceTemplateParsing;
1176
1177 // Start parsing the TS template. Might return cached version.
1178 $this->tmpl->start($this->rootLine);
1179 $GLOBALS['TT']->pull();
1180
1181 if ($this->tmpl->loaded) {
1182 $GLOBALS['TT']->push('Setting the config-array','');
1183 // t3lib_div::print_array($this->tmpl->setup);
1184 $this->sPre = $this->tmpl->setup['types.'][$this->type]; // toplevel - objArrayName
1185 $this->pSetup = $this->tmpl->setup[$this->sPre.'.'];
1186
1187 if (!is_array($this->pSetup)) {
1188 $this->printError('The page is not configured! [type= '.$this->type.']['.$this->sPre.']');
1189 exit;
1190 } else {
1191 $this->config['config']=Array();
1192
1193 // Filling the config-array.
1194 if (is_array($this->tmpl->setup['config.'])) {
1195 $this->config['config'] = $this->tmpl->setup['config.'];
1196 }
1197 if (is_array($this->pSetup['config.'])) {
1198 reset($this->pSetup['config.']);
1199 while(list($theK,$theV)=each($this->pSetup['config.'])) {
1200 $this->config['config'][$theK] = $theV;
1201 }
1202 }
1203 // if .simulateStaticDocuments was not present, the default value will rule.
1204 if (!isset($this->config['config']['simulateStaticDocuments'])) {
1205 $this->config['config']['simulateStaticDocuments']=$this->TYPO3_CONF_VARS['FE']['simulateStaticDocuments'];
1206 }
1207
1208 // Processing for the config_array:
1209 $this->config['rootLine'] = $this->tmpl->rootLine;
1210 $this->config['mainScript'] = trim($this->config['config']['mainScript']) ? trim($this->config['config']['mainScript']) : 'index.php';
1211
1212 // STAT:
1213 $theLogFile = $this->TYPO3_CONF_VARS['FE']['logfile_dir'].$this->config['config']['stat_apache_logfile'];
1214 if ($this->config['config']['stat_apache'] &&
1215 $this->config['config']['stat_apache_logfile'] &&
1216 !strstr($this->config['config']['stat_apache_logfile'],'/') &&
1217 @is_dir($this->TYPO3_CONF_VARS['FE']['logfile_dir']) && @is_file($theLogFile) && @is_writeable($theLogFile)) {
1218 $this->config['stat_vars']['logFile'] = $theLogFile;
1219 $shortTitle = substr(ereg_replace('[^\.[:alnum:]_-]','_',$this->page['title']),0,30);
1220 $pageName = $this->config['config']['stat_apache_pagenames'] ? $this->config['config']['stat_apache_pagenames'] : '[path][title]--[uid].html';
1221 $pageName = str_replace('[title]', $shortTitle ,$pageName);
1222 $pageName = str_replace('[uid]',$this->page['uid'],$pageName);
1223 $pageName = str_replace('[alias]',$this->page['alias'],$pageName);
1224 $pageName = str_replace('[type]',$this->page['type'],$pageName);
1225 $temp = $this->config['rootLine'];
1226 array_pop($temp);
1227 $len = t3lib_div::intInRange($this->config['config']['stat_titleLen'],1,100,20);
1228 $pageName = str_replace('[path]', ereg_replace('[^\.[:alnum:]\/_-]','_',$this->sys_page->getPathFromRootline($temp,$len)).'/' ,$pageName);
1229 $this->config['stat_vars']['pageName'] = $pageName;
1230 }
1231 $this->config['FEData'] = $this->tmpl->setup['FEData'];
1232 $this->config['FEData.'] = $this->tmpl->setup['FEData.'];
1233 }
1234 $GLOBALS['TT']->pull();
1235 } else {
1236 $this->printError('No template found!');
1237 exit;
1238 }
1239 }
1240 // No cache
1241 if ($this->config['config']['no_cache']) {$this->set_no_cache();} // Set $this->no_cache true if the config.no_cache value is set!
1242
1243 // Check PATH_INFO url
1244 if ($this->absRefPrefix_force && strcmp($this->config['config']['simulateStaticDocuments'],'PATH_INFO')) {
1245 $redirectUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR').'index.php?id='.$this->id.'&type='.$this->type;
1246 if ($this->config['config']['simulateStaticDocuments_dontRedirectPathInfoError']) {
1247 $this->printError('PATH_INFO was not configured for this website, and the URL tries to find the page by PATH_INFO!<br /><br /><a href="'.htmlspecialchars($redirectUrl).'">Click here to get to the right page.</a>','Error: PATH_INFO not configured');
1248 } else {
1249 header('Location: '.t3lib_div::locationHeaderUrl($redirectUrl));
1250 }
1251 exit;
1252 // $this->set_no_cache(); // Set no_cache if PATH_INFO is NOT used as simulateStaticDoc. and if absRefPrefix_force shows that such an URL has been passed along.
1253 }
1254 }
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269 /********************************************
1270 *
1271 * Further initialization and data processing
1272 * (jumpurl/submission of forms)
1273 *
1274 *******************************************/
1275
1276 /**
1277 * Get the compressed $TCA array for use in the front-end
1278 * A compressed $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.
1279 * Operates on the global variable, $TCA
1280 *
1281 * @return void
1282 * @see includeTCA()
1283 */
1284 function getCompressedTCarray() {
1285 global $TCA;
1286
1287 $GLOBALS['TT']->push('Get Compressed TC array');
1288 if (!$this->TCAloaded) {
1289 $tempHash = md5('tables.php:'.
1290 filemtime(TYPO3_extTableDef_script ? PATH_typo3conf.TYPO3_extTableDef_script : PATH_t3lib.'stddb/tables.php').
1291 (TYPO3_extTableDef_script?filemtime(PATH_typo3conf.TYPO3_extTableDef_script):'').
1292 ($GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] ? filemtime(PATH_typo3conf.$GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'].'_ext_tables.php') : '')
1293 );
1294 $TCA = unserialize($this->sys_page->getHash($tempHash, 0));
1295 if (!$TCA) {
1296 $this->includeTCA(0);
1297 reset($TCA);
1298 $newTc=Array();
1299 while(list($key,$val)=each($TCA)) {
1300 $newTc[$key]['ctrl'] = $val['ctrl'];
1301 $newTc[$key]['feInterface']=$val['feInterface'];
1302 }
1303 $TCA=$newTc;
1304 $this->sys_page->storeHash($tempHash, serialize($newTc), 'SHORT TC');
1305 }
1306 }
1307 $GLOBALS['TT']->pull();
1308 }
1309
1310 /**
1311 * Includes full TCA.
1312 * Normally in the frontend only a part of the global $TCA array is loaded, for instance the "ctrL" part. Thus it doesn't take up too much memory.
1313 * If you need the FULL TCA available for some reason (like plugins using it) you should call this function which will include the FULL TCA.
1314 * Global vars $TCA, $PAGES_TYPES, $LANG_GENERAL_LABELS can/will be affected.
1315 * The flag $this->TCAloaded will make sure that such an inclusion happens only once since; If $this->TCAloaded is set, nothing is included.
1316 *
1317 * @param boolean 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())
1318 * @return void
1319 * @see getCompressedTCarray()
1320 */
1321 function includeTCA($TCAloaded=1) {
1322 global $TCA, $PAGES_TYPES, $LANG_GENERAL_LABELS;
1323
1324 if (!$this->TCAloaded) {
1325 $TCA = Array();
1326 include (TYPO3_tables_script ? PATH_typo3conf.TYPO3_tables_script : PATH_t3lib.'stddb/tables.php');
1327 // Extension additions
1328 if ($GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE']) {
1329 include(PATH_typo3conf.$GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'].'_ext_tables.php');
1330 } else {
1331 include(PATH_t3lib.'stddb/load_ext_tables.php');
1332 }
1333 // ext-script
1334 if (TYPO3_extTableDef_script) {
1335 include (PATH_typo3conf.TYPO3_extTableDef_script);
1336 }
1337 $this->TCAloaded = $TCAloaded;
1338 }
1339 }
1340
1341 /**
1342 * Setting the language key that'll be used by the current page.
1343 * 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.
1344 *
1345 * @return void
1346 * @access private
1347 */
1348 function settingLanguage() {
1349 $this->sys_language_uid = intval($this->config['config']['sys_language_uid']);
1350 $olRec = $this->sys_page->getPageOverlay($this->id,$this->sys_language_uid);
1351
1352 if (!count($olRec)) {
1353 $this->sys_language_uid=0;
1354 } else {
1355 $this->page = $this->sys_page->getPageOverlay($this->page,$this->sys_language_uid);
1356 }
1357 $this->sys_page->sys_language_uid = $this->sys_language_uid;
1358
1359 // Updating content of the two rootLines IF the language key is set!
1360 if ($this->sys_language_uid && is_array($this->tmpl->rootLine)) {
1361 reset($this->tmpl->rootLine);
1362 while(list($rLk)=each($this->tmpl->rootLine)) {
1363 $this->tmpl->rootLine[$rLk] = $this->sys_page->getPageOverlay($this->tmpl->rootLine[$rLk]);
1364 }
1365 }
1366 if ($this->sys_language_uid && is_array($this->rootLine)) {
1367 reset($this->rootLine);
1368 while(list($rLk)=each($this->rootLine)) {
1369 $this->rootLine[$rLk] = $this->sys_page->getPageOverlay($this->rootLine[$rLk]);
1370 }
1371 }
1372
1373 // Finding the ISO code:
1374 if (t3lib_extMgm::isLoaded('static_info_tables') && $this->sys_language_uid) {
1375 $sys_language_row = $this->sys_page->getRawRecord('sys_language',$this->sys_language_uid,'static_lang_isocode');
1376 if (is_array($sys_language_row) && $sys_language_row['static_lang_isocode']) {
1377 $stLrow = $this->sys_page->getRawRecord('static_languages',$sys_language_row['static_lang_isocode'],'lg_iso_2');
1378 $this->sys_language_isocode=$stLrow['lg_iso_2'];
1379 }
1380 }
1381 }
1382
1383 /**
1384 * Checks if any email-submissions or submission via the fe_tce
1385 *
1386 * @return string 'email' if a formmail has been send, 'fe_tce' if front-end data submission (like forums, guestbooks) is send. '' if none.
1387 */
1388 function checkDataSubmission() {
1389 if ($GLOBALS['HTTP_POST_VARS']['formtype_db'] || $GLOBALS['HTTP_POST_VARS']['formtype_mail']) {
1390 $refInfo=parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
1391 if (t3lib_div::getIndpEnv('TYPO3_HOST_ONLY')==$refInfo['host'] || $this->TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) {
1392 if ($this->locDataCheck($GLOBALS['HTTP_POST_VARS']['locationData'])) {
1393 $ret = '';
1394 if ($GLOBALS['HTTP_POST_VARS']['formtype_mail']) {
1395 $ret = 'email';
1396 } elseif ($GLOBALS['HTTP_POST_VARS']['formtype_db'] && is_array($GLOBALS['HTTP_POST_VARS']['data'])) {
1397 $ret = 'fe_tce';
1398 }
1399 $GLOBALS['TT']->setTSlogMessage('"Check Data Submission": Return value: '.$ret,0);
1400 return $ret;
1401 }
1402 } else $GLOBALS['TT']->setTSlogMessage('"Check Data Submission": HTTP_HOST and REFERER HOST did not match when processing submitted formdata!',3);
1403 }
1404 }
1405
1406 /**
1407 * Processes user data
1408 *
1409 * @return void
1410 * @see tslib_feTCE
1411 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=342&cHash=fdf55adb3b
1412 */
1413 function fe_tce() {
1414 $fe_tce = t3lib_div::makeInstance('tslib_feTCE');
1415 $fe_tce->start($GLOBALS['HTTP_POST_VARS']['data'],$this->config['FEData.']);
1416 $fe_tce->includeScripts();
1417 }
1418
1419 /**
1420 * Checks if a formmail submission can be sent as email
1421 *
1422 * @param string The input from $GLOBALS['HTTP_POST_VARS']['locationData']
1423 * @return void
1424 * @access private
1425 * @see checkDataSubmission()
1426 */
1427 function locDataCheck($locationData) {
1428 $locData = explode(':',$locationData);
1429 if (!$locData[1] || $this->sys_page->checkRecord($locData[1],$locData[2],1)) {
1430 if (count($this->sys_page->getPage($locData[0]))) { // $locData[1] -check means that a record is checked only if the locationData has a value for a record else than the page.
1431 return 1;
1432 } else $GLOBALS['TT']->setTSlogMessage('LocationData Error: The page pointed to by location data ('.$locationData.') was not accessible.',2);
1433 } else $GLOBALS['TT']->setTSlogMessage('LocationData Error: Location data ('.$locationData.') record pointed to was not accessible.',2);
1434 }
1435
1436 /**
1437 * Sends the emails from the formmail content object.
1438 *
1439 * @return void
1440 * @access private
1441 * @see checkDataSubmission()
1442 */
1443 function sendFormmail() {
1444 $formmail = t3lib_div::makeInstance('t3lib_formmail');
1445
1446 $EMAIL_VARS = $GLOBALS['HTTP_POST_VARS'];
1447 unset($EMAIL_VARS['locationData']);
1448 unset($EMAIL_VARS['formtype_mail']);
1449
1450 $formmail->start($EMAIL_VARS);
1451 $formmail->sendtheMail();
1452 $GLOBALS['TT']->setTSlogMessage('"Formmail" invoked, sending mail to '.$EMAIL_VARS['recipient'],0);
1453 }
1454
1455 /**
1456 * Checks if jumpurl is set.
1457 * This function also takes care of jumpurl utilized by the Direct Mail module (ext: direct_mail) which may set an integer value for jumpurl which refers to a link in a certain mail-record, mid
1458 *
1459 * @return void
1460 */
1461 function checkJumpUrl() {
1462 global $TCA;
1463
1464 $mid = t3lib_div::GPvar('mid'); // mail id, if direct mail link
1465 $rid = t3lib_div::GPvar('rid'); // recipient id, if direct mail link
1466 if ((strcmp($this->jumpurl,'') && ((t3lib_div::getIndpEnv('HTTP_REFERER') || $this->TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) || $mid)) || ($this->jumpurl = $this->sys_page->getExtURL($this->page,$this->config['config']['disablePageExternalUrl']))) {
1467 if ($mid && is_array($TCA['sys_dmail'])) { // Yes, it's OK if the link comes from a direct mail. AND sys_dmail module has installed the table, sys_dmail (and therefore we expect sys_dmail_maillog as well!)
1468 $temp_recip=explode('_',$rid);
1469 $url_id=0;
1470 if (t3lib_div::testInt($this->jumpurl)) {
1471 $temp_query='SELECT mailContent FROM sys_dmail WHERE uid='.intval($mid);
1472 $temp_res = mysql(TYPO3_db,$temp_query);
1473 if ($row=mysql_fetch_assoc($temp_res)) {
1474 $temp_unpackedMail = unserialize($row['mailContent']);
1475 $url_id=$this->jumpurl;
1476 if ($this->jumpurl>=0) {
1477 $responseType=1; // Link (number)
1478 $this->jumpurl = $temp_unpackedMail['html']['hrefs'][$url_id]['absRef'];
1479 } else {
1480 $responseType=2; // Link (number, plaintext)
1481 $this->jumpurl = $temp_unpackedMail['plain']['link_ids'][abs($url_id)];
1482 }
1483 switch($temp_recip[0]) {
1484 case 't':
1485 $theTable = 'tt_address';
1486 break;
1487 case 'f':
1488 $theTable = 'fe_users';
1489 break;
1490 default:
1491 $theTable='';
1492 break;
1493 }
1494 if ($theTable) {
1495 $recipRow = $this->sys_page->getRawRecord($theTable,$temp_recip[1]);
1496 if (is_array($recipRow)) {
1497 // debug($recipRow);
1498 $authCode = t3lib_div::stdAuthCode($recipRow['uid']);
1499 $rowFieldsArray = explode(',', 'uid,name,title,email,phone,www,address,company,city,zip,country,fax,firstname');
1500 reset($rowFieldsArray);
1501 while(list(,$substField)=each($rowFieldsArray)) {
1502 $this->jumpurl = str_replace('###USER_'.$substField.'###', $recipRow[$substField], $this->jumpurl);
1503 }
1504 $this->jumpurl = str_replace('###SYS_TABLE_NAME###', $tableNameChar, $this->jumpurl); // Put in the tablename of the userinformation
1505 $this->jumpurl = str_replace('###SYS_MAIL_ID###', $mid, $this->jumpurl); // Put in the uid of the mail-record
1506 $this->jumpurl = str_replace('###SYS_AUTHCODE###', $authCode, $this->jumpurl);
1507
1508 // debug($this->jumpurl);
1509 }
1510 }
1511 }
1512 if (!$this->jumpurl) die('Error: No further link. Please report error to the mail sender.');
1513 } else {
1514 $responseType=-1; // received (url, dmailerping)
1515 }
1516 if ($responseType!=0) {
1517 $temp_query='INSERT INTO sys_dmail_maillog (mid,rtbl,rid,tstamp,url,response_type,url_id)
1518 VALUES ("'.intval($mid).'","'.addslashes($temp_recip[0]).'","'.intval($temp_recip[1]).'","'.time().'","'.addslashes($this->jumpurl).'",'.intval($responseType).','.intval($url_id).')';
1519 $temp_res = mysql(TYPO3_db,$temp_query);
1520 }
1521 }
1522 } else {
1523 unset($this->jumpurl);
1524 }
1525 }
1526
1527 /**
1528 * Sends a header 'Location' to jumpurl, if jumpurl is set.
1529 * Will exit if a location header is sent (for instance if JumpUrl was triggered)
1530 *
1531 * @return void
1532 */
1533 function jumpUrl() {
1534 if ($this->jumpurl) {
1535 if (t3lib_div::GPvar('juSecure')) {
1536 $hArr = array(
1537 $this->jumpurl,
1538 t3lib_div::GPvar('locationData'),
1539 $this->TYPO3_CONF_VARS['SYS']['encryptionKey']
1540 );
1541 $calcJuHash=t3lib_div::shortMD5(serialize($hArr));
1542 $locationData = t3lib_div::GPvar('locationData');
1543 $juHash = t3lib_div::GPvar('juHash');
1544 if ($juHash == $calcJuHash) {
1545 if ($this->locDataCheck($locationData)) {
1546 $this->jumpurl = rawurldecode($this->jumpurl); // 211002 - goes with cObj->filelink() rawurlencode() of filenames so spaces can be allowed.
1547 if (@is_file($this->jumpurl)) {
1548 $mimeType = t3lib_div::GPvar('mimeType');
1549 $mimeType = $mimeType ? $mimeType : 'application/octet-stream';
1550 Header('Content-Type: '.$mimeType);
1551 Header('Content-Disposition: attachment; filename='.basename($this->jumpurl));
1552 readfile($this->jumpurl);
1553 exit;
1554 } else die('jumpurl Secure: "'.$this->jumpurl.'" was not a valid file!');
1555 } else die('jumpurl Secure: locationData, '.$locationData.', was not accessible.');
1556 } else die('jumpurl Secure: Calculated juHash, '.$calcJuHash.', did not match the submitted juHash.');
1557 } else {
1558 $TSConf = $this->getPagesTSconfig();
1559 if ($TSConf['TSFE.']['jumpUrl_transferSession']) {
1560 $uParts = parse_url($this->jumpurl);
1561 $params = '&FE_SESSION_KEY='.rawurlencode($this->fe_user->id.'-'.md5($this->fe_user->id.'/'.$this->TYPO3_CONF_VARS['SYS']['encryptionKey']));
1562 $this->jumpurl.=($uParts['query']?'':'?').$params; // Add the session parameter ...
1563 }
1564 Header('Location: '.$this->jumpurl);
1565 exit;
1566 }
1567 }
1568 }
1569
1570 /**
1571 * Sets the URL_ID_TOKEN in the internal var, $this->getMethodUrlIdToken
1572 *
1573 * @return void
1574 * @access private
1575 */
1576 function setUrlIdToken() {
1577 if ($this->config['config']['ftu']) {
1578 $this->getMethodUrlIdToken = $this->TYPO3_CONF_VARS['FE']['get_url_id_token'];
1579 } else {
1580 $this->getMethodUrlIdToken = '';
1581 }
1582 }
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607 /********************************************
1608 *
1609 * Page generation; cache handling
1610 *
1611 *******************************************/
1612
1613 /**
1614 * Returns true if the page should be generated
1615 * That is if jumpurl is not set and the cacheContentFlag is not set.
1616 *
1617 * @return boolean
1618 */
1619 function isGeneratePage() {
1620 return (!$this->cacheContentFlag && !$this->jumpurl);
1621 }
1622
1623 /**
1624 * Temp cache content
1625 * The temporary cache will expire after a few seconds (typ. 30) or will be cleared by the rendered page, which will also clear and rewrite the cache.
1626 *
1627 * @return void
1628 */
1629 function tempPageCacheContent() {
1630 $this->tempContent=0;
1631 if (!$this->no_cache) {
1632 $seconds=30;
1633 $stdMsg = '
1634 <html>
1635 <head>
1636 <title>'.htmlspecialchars($this->tmpl->printTitle($this->page['title'])).'</title>
1637 <meta http-equiv=Refresh Content="3; Url='.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" />
1638 </head>
1639 <body bgcolor="white">
1640 <font size="1" face="VERDANA,ARIAL,HELVETICA" color="#cccccc">
1641 <div align="center">
1642 <b>Page is being generated.</b><br />
1643 If this message does not disappear within '.$seconds.' seconds, please reload.
1644 </div>
1645 </font>
1646 </body>
1647 </html>';
1648 $temp_content = $this->config['config']['message_page_is_being_generated'] ? $this->config['config']['message_page_is_being_generated'] : $stdMsg;
1649
1650 $this->setPageCacheContent($temp_content,'',$GLOBALS['EXEC_TIME']+$seconds);
1651 $this->tempContent=1; // This flag shows that temporary content is put in the cache
1652 }
1653 }
1654
1655 /**
1656 * Set cache content to $this->content
1657 *
1658 * @return void
1659 */
1660 function realPageCacheContent() {
1661 $cache_timeout = $this->page['cache_timeout'] ? $this->page['cache_timeout'] : ($this->cacheTimeOutDefault ? $this->cacheTimeOutDefault : 60*60*24); // seconds until a cached page is too old
1662 $timeOutTime = $GLOBALS['EXEC_TIME']+$cache_timeout;
1663 if ($this->config['config']['cache_clearAtMidnight']) {
1664 $midnightTime = mktime (0,0,0,date('m',$timeOutTime),date('d',$timeOutTime),date('Y',$timeOutTime));
1665 if ($midnightTime > time()) { // If the midnight time of the expire-day is greater than the current time, we may set the timeOutTime to the new midnighttime.
1666 $timeOutTime=$midnightTime;
1667 }
1668 }
1669 $this->config['hash_base'] = $this->hash_base;
1670 $this->setPageCacheContent($this->content,$this->config,$timeOutTime);
1671 }
1672
1673 /**
1674 * Sets cache content
1675 *
1676 * @param string The content to store in the HTML field of the cache table
1677 * @param mixed The additional cache_data array, fx. $this->config
1678 * @param integer Timestamp
1679 * @return string The content of mysql_error()
1680 * @see realPageCacheContent(), tempPageCacheContent()
1681 */
1682 function setPageCacheContent($c,$d,$t) {
1683 $this->clearPageCacheContent();
1684 $res = mysql (TYPO3_db, 'INSERT INTO cache_pages (hash, page_id, HTML, cache_data, expires, tstamp'.($this->page_cache_reg1?', reg1':'').')
1685 VALUES ("'.$this->newHash.'","'.$this->id.'","'.addSlashes($c).'","'.addSlashes(serialize($d)).'","'.$t.'",'.time().($this->page_cache_reg1?','.intval($this->page_cache_reg1):'').')');
1686 echo mysql_error();
1687 }
1688
1689 /**
1690 * Clears cache content (for $this->newHash)
1691 *
1692 * @return void
1693 */
1694 function clearPageCacheContent() {
1695 $res = mysql (TYPO3_db, 'DELETE FROM cache_pages WHERE hash="'.$this->newHash.'"');
1696 }
1697
1698 /**
1699 * Clears cache content for a list of page ids
1700 *
1701 * @param string A list of INTEGER numbers which points to page uids for which to clear entries in the cache_pages table (page content cache)
1702 * @return void
1703 */
1704 function clearPageCacheContent_pidList($pidList) {
1705 $res = mysql (TYPO3_db, 'DELETE FROM cache_pages WHERE page_id IN ('.$pidList.')');
1706 }
1707
1708 /**
1709 * Sets sys last changed
1710 * Setting the SYS_LASTCHANGED value in the pagerecord: This value will thus be set to the highest tstamp of records rendered on the page. This includes all records with no regard to hidden records, userprotection and so on.
1711 *
1712 * @return void
1713 * @see tslib_cObj::lastChanged()
1714 */
1715 function setSysLastChanged() {
1716 if ($this->page['SYS_LASTCHANGED'] < intval($this->register['SYS_LASTCHANGED'])) {
1717 $query = 'UPDATE pages SET SYS_LASTCHANGED='.intval($this->register['SYS_LASTCHANGED']).' WHERE uid="'.$this->id.'"';
1718 $res = mysql (TYPO3_db, $query);
1719 }
1720 }
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741 /********************************************
1742 *
1743 * Page generation; rendering and inclusion
1744 *
1745 *******************************************/
1746
1747 /**
1748 * Does some processing BEFORE the pagegen script is included.
1749 *
1750 * @return void
1751 */
1752 function generatePage_preProcessing() {
1753 ksort($this->all);
1754 // Same codeline as in getFromCache(). BUT $this->all has been set in the meantime, so we can't just skip this line and let it be set above! Keep this line!
1755 $this->newHash = $this->getHash();
1756
1757 // Here we put some temporary stuff in the cache in order to let the first hit generate the page. The temporary cache will expire after a few seconds (typ. 30) or will be cleared by the rendered page, which will also clear and rewrite the cache.
1758 $this->tempPageCacheContent();
1759
1760 // Setting locale
1761 if ($this->config['config']['locale_all']) {
1762 # Change by Rene Fritz, 22/10 2002
1763 # there`s the problem that PHP parses float values in scripts wrong if the locale LC_NUMERIC is set to something with a komma as decimal point
1764 # this does not work in php 4.2.3
1765 #setlocale('LC_ALL',$this->config['config']['locale_all']);
1766 #setlocale('LC_NUMERIC','en_US');
1767
1768 # so we set all except LC_NUMERIC
1769 setlocale(LC_COLLATE,$this->config['config']['locale_all']);
1770 setlocale(LC_CTYPE,$this->config['config']['locale_all']);
1771 setlocale(LC_MONETARY,$this->config['config']['locale_all']);
1772 setlocale(LC_TIME,$this->config['config']['locale_all']);
1773 }
1774
1775 // Setting cache_timeout_default. May be overridden by PHP include scritps.
1776 $this->cacheTimeOutDefault = intval($this->config['config']['cache_period']);
1777
1778 // page is generated
1779 $this->no_cacheBeforePageGen = $this->no_cache;
1780 }
1781
1782 /**
1783 * Determines to include custom or pagegen.php script
1784 * returns script-filename if a TypoScript (config) script is defined and should be include instead of pagegen.php
1785 *
1786 * @return string The relative filepath of "config.pageGenScript" if found and allowed
1787 */
1788 function generatePage_whichScript() {
1789 if (!$this->TYPO3_CONF_VARS['FE']['noPHPscriptInclude'] && $this->config['config']['pageGenScript']) {
1790 return $this->tmpl->getFileName($this->config['config']['pageGenScript']);
1791 }
1792 }
1793
1794 /**
1795 * Does some processing AFTER the pagegen script is included.
1796 * This includes calling tidy (if configured), XHTML cleaning (if configured), caching the page, indexing the page (if configured) and setting sysLastChanged
1797 *
1798 * @return void
1799 */
1800 function generatePage_postProcessing() {
1801 // This is to ensure, that the page is NOT cached if the no_cache parameter was set before the page was generated. This is a safety precaution, as it could have been unset by some script.
1802 if ($this->no_cacheBeforePageGen) $this->set_no_cache();
1803
1804 // Tidy up the code, if flag...
1805 if ($this->TYPO3_CONF_VARS['FE']['tidy_option'] == 'all') {
1806 $GLOBALS['TT']->push('Tidy, all','');
1807 $this->content = $this->tidyHTML($this->content);
1808 $GLOBALS['TT']->pull();
1809 }
1810
1811 // XHTML-clean the code, if flag set
1812 if ($this->doXHTML_cleaning() == 'all') {
1813 $GLOBALS['TT']->push('XHTML clean, all','');
1814 $XHTML_clean = t3lib_div::makeInstance('t3lib_parsehtml');
1815 $this->content = $XHTML_clean->XHTML_clean($this->content);
1816 $GLOBALS['TT']->pull();
1817 }
1818
1819 // Storing page
1820 if (!$this->no_cache) {
1821 // Tidy up the code, if flag...
1822 if ($this->TYPO3_CONF_VARS['FE']['tidy_option'] == 'cached') {
1823 $GLOBALS['TT']->push('Tidy, cached','');
1824 $this->content = $this->tidyHTML($this->content);
1825 $GLOBALS['TT']->pull();
1826 }
1827 // XHTML-clean the code, if flag set
1828 if ($this->doXHTML_cleaning() == 'cached') {
1829 $GLOBALS['TT']->push('XHTML clean, cached','');
1830 $XHTML_clean = t3lib_div::makeInstance('t3lib_parsehtml');
1831 $this->content = $XHTML_clean->XHTML_clean($this->content);
1832 $GLOBALS['TT']->pull();
1833 }
1834 $this->realPageCacheContent();
1835 } elseif ($this->tempContent) { // If there happens to be temporary content in the cache and the cache was not cleared due to new content put in it... ($this->no_cache=0)
1836 $this->clearPageCacheContent();
1837 }
1838
1839 if ($this->isSearchIndexPage()) {
1840 $GLOBALS['TT']->push('Index page','');
1841 $indexer = t3lib_div::makeInstance('tx_indexedsearch_indexer');
1842 $indexer->init($this->content,$this->config['config'],$this->id,$this->type,$this->gr_list,$this->cHash_array,$this->register['SYS_LASTCHANGED'],$this->config['rootLine']);
1843 $indexer->indexTypo3PageContent();
1844 $GLOBALS['TT']->pull();
1845 } elseif ($this->config['config']['index_enable'] && $this->no_cache) {
1846 $GLOBALS['TT']->push('Index page','');
1847 $GLOBALS['TT']->setTSlogMessage('Index page? No, page was set to "no_cache" and so cannot be indexed.');
1848 $GLOBALS['TT']->pull();
1849 }
1850 $this->setSysLastChanged();
1851 }
1852
1853 /**
1854 * Processes the INTinclude-scripts
1855 *
1856 * @return void
1857 */
1858 function INTincScript() {
1859 $GLOBALS['TT']->push('Split content');
1860 $INTiS_splitC = explode('<!--INT_SCRIPT.',$this->content); // Splits content with the key.
1861 $this->content='';
1862 $GLOBALS['TT']->setTSlogMessage('Parts: '.count($INTiS_splitC));
1863 $GLOBALS['TT']->pull();
1864
1865 // Depreciated stuff:
1866 $this->additionalHeaderData = is_array($this->config['INTincScript_ext']['additionalHeaderData']) ? $this->config['INTincScript_ext']['additionalHeaderData'] : array();
1867 $this->additionalJavaScript = $this->config['INTincScript_ext']['additionalJavaScript'];
1868 $this->additionalCSS = $this->config['INTincScript_ext']['additionalCSS'];
1869 $this->JSCode = $this->additionalHeaderData['JSCode'];
1870 $this->JSImgCode = $this->additionalHeaderData['JSImgCode'];
1871 $this->divSection='';
1872
1873 $INTiS_config = $GLOBALS['TSFE']->config['INTincScript'];
1874 reset($INTiS_splitC);
1875 while(list($INTiS_c,$INTiS_cPart)=each($INTiS_splitC)) {
1876 if (substr($INTiS_cPart,32,3)=='-->') { // If the split had a comment-end after 32 characters it's probably a split-string
1877 $GLOBALS['TT']->push('Include '.$INTiS_config[$INTiS_key]['file'],'');
1878 $INTiS_key = 'INT_SCRIPT.'.substr($INTiS_cPart,0,32);
1879 $incContent='';
1880 if (is_array($INTiS_config[$INTiS_key])) {
1881 $INTiS_cObj = unserialize($INTiS_config[$INTiS_key]['cObj']);
1882 $INTiS_cObj->INT_include=1;
1883 switch($INTiS_config[$INTiS_key]['type']) {
1884 case 'SCRIPT':
1885 $incContent=$INTiS_cObj->PHP_SCRIPT($INTiS_config[$INTiS_key]['conf']);
1886 break;
1887 case 'COA':
1888 $incContent=$INTiS_cObj->COBJ_ARRAY($INTiS_config[$INTiS_key]['conf']);
1889 break;
1890 case 'FUNC':
1891 $incContent=$INTiS_cObj->USER($INTiS_config[$INTiS_key]['conf']);
1892 break;
1893 }
1894 }
1895 $this->content.=$incContent;
1896 $this->content.= substr($INTiS_cPart,35);
1897 $GLOBALS['TT']->pull($incContent);
1898 } else {
1899 $this->content.= ($c?'<!--INT_SCRIPT.':'').$INTiS_cPart;
1900 }
1901 }
1902 $GLOBALS['TT']->push('Substitute header section');
1903 $this->INTincScript_loadJSCode();
1904 $this->content = str_replace('<!--HD_'.$this->config['INTincScript_ext']['divKey'].'-->', implode($this->additionalHeaderData,chr(10)), $this->content);
1905 $this->content = str_replace('<!--TDS_'.$this->config['INTincScript_ext']['divKey'].'-->', $this->divSection, $this->content);
1906 $this->setAbsRefPrefix();
1907 $GLOBALS['TT']->pull();
1908 }
1909
1910 /**
1911 * Loads the JavaScript code for INTincScript
1912 *
1913 * @return void
1914 * @access private
1915 */
1916 function INTincScript_loadJSCode() {
1917 if ($this->JSImgCode) { // If any images added, then add them to the javascript section
1918 $this->additionalHeaderData['JSImgCode']='
1919 <script type="text/javascript">
1920 /*<![CDATA[*/
1921 <!--
1922 if (version == "n3") {
1923 '.trim($this->JSImgCode).'
1924 }
1925 // -->
1926 /*]]>*/
1927 </script>';
1928 }
1929 if ($this->JSCode || count($this->additionalJavaScript)) { // Add javascript
1930 $this->additionalHeaderData['JSCode']='
1931 <script type="text/javascript">
1932 /*<![CDATA[*/
1933 <!--
1934 '.implode($this->additionalJavaScript,chr(10)).'
1935 '.trim($this->JSCode).'
1936 // -->
1937 /*]]>*/
1938 </script>';
1939 }
1940 if (count($this->additionalCSS)) { // Add javascript
1941 $this->additionalHeaderData['_CSS']='
1942 <style type="text/css">
1943 /*<![CDATA[*/
1944 <!--
1945 '.implode($this->additionalCSS,chr(10)).'
1946 // -->
1947 /*]]>*/
1948 </style>';
1949 }
1950 }
1951
1952 /**
1953 * Determines if there are any INTincScripts to include
1954 *
1955 * @return boolean Returns true if scripts are found (and not jumpurl)
1956 */
1957 function isINTincScript() {
1958 return (is_array($this->config['INTincScript']) && !$this->jumpurl);
1959 }
1960
1961 /**
1962 * Returns true if page should be indexed.
1963 *
1964 * @return boolean
1965 */
1966 function isSearchIndexPage() {
1967 return t3lib_extMgm::isLoaded('indexed_search') && $this->config['config']['index_enable'] && !$this->no_cache;
1968 }
1969
1970 /**
1971 * Returns true if page XHTML clean flag is set.
1972 *
1973 * @return boolean
1974 */
1975 function doXHTML_cleaning() {
1976 return $this->config['config']['xhtml_cleaning'];
1977 }
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995 /********************************************
1996 *
1997 * Finished off; outputting, storing session data, statistics...
1998 *
1999 *******************************************/
2000
2001 /**
2002 * Determines if content should be outputted.
2003 * Outputting content is done only if jumpurl is NOT set.
2004 *
2005 * @return boolean Returns true if $this->jumpurl is not set.
2006 */
2007 function isOutputting() {
2008 return (!$this->jumpurl);
2009 }
2010
2011 /**
2012 * Processes the output before it's actually outputted. Sends headers also.
2013 * This includes substituting the USERNAME comment, getMethodUrlIdToken, sending additional headers (as defined in the TypoScript "config.additionalheaders" object), tidy'ing content, XHTML cleaning content (if configured)
2014 * Works on $this->content
2015 *
2016 * @return void
2017 */
2018 function processOutput() {
2019 // Substitutes username mark with the username
2020 if ($this->fe_user->user['uid']) {
2021 $token = trim($this->config['config']['USERNAME_substToken']);
2022 $this->content = str_replace($token ? $token : '<!--###USERNAME###-->',$this->fe_user->user['username'],$this->content);
2023 }
2024 // Substitutes get_URL_ID in case of GET-fallback
2025 if ($this->getMethodUrlIdToken) {
2026 $this->content = str_replace($this->getMethodUrlIdToken, $this->fe_user->get_URL_ID, $this->content);
2027 }
2028
2029 // Set header for charset-encoding if set. Added by RL 17.10.03
2030 if ($this->config['config']['metaCharset']) {
2031 $headLine = 'Content-Type:text/html;charset='.trim ($this->config['config']['metaCharset']);
2032 header ($headLine);
2033 }
2034
2035 // Set headers, if any
2036 if ($this->config['config']['additionalHeaders']) {
2037 $headerArray = explode('|', $this->config['config']['additionalHeaders']);
2038 while(list(,$headLine)=each($headerArray)) {
2039 $headLine = trim($headLine);
2040 header($headLine);
2041 }
2042 }
2043
2044 // Tidy up the code, if flag...
2045 if ($this->TYPO3_CONF_VARS['FE']['tidy_option'] == 'output') {
2046 $GLOBALS['TT']->push('Tidy, output','');
2047 $this->content = $this->tidyHTML($this->content);
2048 $GLOBALS['TT']->pull();
2049 }
2050 // XHTML-clean the code, if flag set
2051 if ($this->doXHTML_cleaning() == 'output') {
2052 $GLOBALS['TT']->push('XHTML clean, output','');
2053 $XHTML_clean = t3lib_div::makeInstance('t3lib_parsehtml');
2054 $this->content = $XHTML_clean->XHTML_clean($this->content);
2055 $GLOBALS['TT']->pull();
2056 }
2057
2058 /* if ($this->beUserLogin && t3lib_div::GPvar('ADMCMD_view')) { // This is a try to change target=_top to target=_self if pages are shown in the Web>View module...
2059 $this->content = str_replace('target="_top"','target="_self"',$this->content);
2060 $this->content = str_replace('target=_top','target="_self"',$this->content);
2061 }*/
2062 }
2063
2064 /**
2065 * Determines if any EXTincScripts should be included
2066 *
2067 * @return boolean True, if external php scripts should be included (set by PHP_SCRIPT_EXT cObjects)
2068 * @see tslib_cObj::PHP_SCRIPT
2069 */
2070 function isEXTincScript() {
2071 return is_array($this->config['EXTincScript']);
2072 }
2073
2074 /**
2075 * Stores session data for the front end user
2076 *
2077 * @return void
2078 */
2079 function storeSessionData() {
2080 $this->fe_user->storeSessionData();
2081 }
2082
2083 /**
2084 * Sets the parsetime of the page.
2085 *
2086 * @return void
2087 * @access private
2088 */
2089 function setParseTime() {
2090 // Compensates for the time consumed with Back end user initialization.
2091 $this->scriptParseTime = $GLOBALS['TT']->convertMicrotime($GLOBALS['TYPO3_MISC']['microtime_end'])
2092 - $GLOBALS['TT']->convertMicrotime($GLOBALS['TYPO3_MISC']['microtime_start'])
2093 - ($GLOBALS['TT']->convertMicrotime($GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'])-$GLOBALS['TT']->convertMicrotime($GLOBALS['TYPO3_MISC']['microtime_BE_USER_start']));
2094 }
2095
2096 /**
2097 * Saves hit statistics
2098 *
2099 * @return void
2100 */
2101 function statistics() {
2102 if ($this->config['config']['stat'] &&
2103 (!strcmp('',$this->config['config']['stat_typeNumList']) || t3lib_div::inList(str_replace(' ','',$this->config['config']['stat_typeNumList']), $this->type)) &&
2104 (!$this->config['config']['stat_excludeBEuserHits'] || !$this->beUserLogin) &&
2105 (!$this->config['config']['stat_excludeIPList'] || !t3lib_div::inList(str_replace(' ','',$this->config['config']['stat_excludeIPList']), t3lib_div::getIndpEnv('REMOTE_ADDR')))) {
2106 $GLOBALS['TT']->push('Stat');
2107 if (t3lib_extMgm::isLoaded('sys_stat') && $this->config['config']['stat_mysql']) {
2108 // Jumpurl:
2109 $sword = t3lib_div::GPvar('sword');
2110 if ($sword) {
2111 $jumpurl_msg='sword:'.$sword;
2112 } elseif ($this->jumpurl) {
2113 $jumpurl_msg='jumpurl:'.$this->jumpurl;
2114 } else {
2115 $jumpurl_msg='';
2116 }
2117 // Flags: bits: 0 = BE_user, 1=Cached page?
2118 $flags=0;
2119 if ($this->beUserLogin) {$flags|=1;}
2120 if ($this->cacheContentFlag) {$flags|=2;}
2121 // Ref url:
2122 $refUrl = t3lib_div::getIndpEnv('HTTP_REFERER');
2123 $thisUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR');
2124 if (t3lib_div::isFirstPartOfStr($refUrl,$thisUrl)) {
2125 $refUrl='[LOCAL]';
2126 }
2127
2128 $query ='INSERT INTO sys_stat SET ';
2129 $query.='page_id="'.$this->id.'",'; // id
2130 $query.='page_type="'.$this->type.'",'; // type
2131 $query.='jumpurl="'.addslashes($jumpurl_msg).'",'; // jumpurl message
2132 $query.='feuser_id="'.$this->fe_user->user['uid'].'",'; // fe_user id, integer
2133 $query.='cookie="'.addslashes($this->fe_user->id).'",'; // cookie as set or retrieve. If people has cookies disabled this will vary all the time...
2134 $query.='sureCookie="'.hexdec(substr($this->fe_user->cookieId,0,8)).'",'; // This is the cookie value IF the cookie WAS actually set. However the first hit where the cookie is set will thus NOT be logged here. So this lets you select for a session of at least two clicks...
2135 $query.='rl0="'.$this->config['rootLine'][0]['uid'].'",'; // RootLevel 0 uid
2136 $query.='rl1="'.$this->config['rootLine'][1]['uid'].'",'; // RootLevel 1 uid
2137 $query.='client_browser="'.addslashes($GLOBALS['CLIENT']['BROWSER']).'",'; // Client browser (net, msie, opera)
2138 $query.='client_version="'.addslashes($GLOBALS['CLIENT']['VERSION']).'",'; // Client version (double value)
2139 $query.='client_os="'.addslashes($GLOBALS['CLIENT']['SYSTEM']).'",'; // Client Operating system (win, mac, unix)
2140 $query.='parsetime="'.intval($this->scriptParseTime).'",'; // Parsetime for the page.
2141 $query.='flags="'.$flags.'",'; // Flags: Is be user logged in? Is page cached?
2142 $query.='IP="'.addslashes(t3lib_div::getIndpEnv('REMOTE_ADDR')).'",'; // Remote IP address
2143 $query.='host="'.addslashes(t3lib_div::getIndpEnv('REMOTE_HOST')).'",'; // Remote Host Address
2144 $query.='referer="'.addslashes($refUrl).'",'; // Referer URL
2145 $query.='browser="'.addslashes(t3lib_div::getIndpEnv('HTTP_USER_AGENT')).'",'; // User Agent Info.
2146 $query.='tstamp='.$GLOBALS['EXEC_TIME']; // Time stamp
2147 $GLOBALS['TT']->push('Store SQL');
2148 mysql (TYPO3_db, $query);
2149 $GLOBALS['TT']->pull();
2150 echo mysql_error();
2151 }
2152
2153 // Apache:
2154 if ($this->config['config']['stat_apache'] && $this->config['stat_vars']['pageName']) {
2155 if (@is_file($this->config['stat_vars']['logFile']) && TYPO3_OS!='WIN') {
2156 $LogLine = ((t3lib_div::getIndpEnv('REMOTE_HOST') && !$this->config['config']['stat_apache_noHost']) ? t3lib_div::getIndpEnv('REMOTE_HOST') : t3lib_div::getIndpEnv('REMOTE_ADDR')).' - - '.Date('[d/M/Y:H:i:s +0000]',$GLOBALS['EXEC_TIME']).' "GET '.$this->config['stat_vars']['pageName'].' HTTP/1.1" 200 '.strlen($this->content);
2157 if (!$this->config['config']['stat_apache_notExtended']) {
2158 $LogLine.= ' "'.t3lib_div::getIndpEnv('HTTP_REFERER').'" "'.t3lib_div::getIndpEnv('HTTP_USER_AGENT').'"';
2159 }
2160 $execCmd = 'echo "'.addslashes($LogLine).'" >> '.$this->config['stat_vars']['logFile'];
2161 $GLOBALS['TT']->push('Write to log file');
2162 exec($execCmd);
2163 $GLOBALS['TT']->pull();
2164 $GLOBALS['TT']->setTSlogMessage('Writing to logfile: OK',0);
2165 } else {
2166 $GLOBALS['TT']->setTSlogMessage('Writing to logfile: Error - logFile did not exist or OS is Windows!',3);
2167 }
2168 }
2169 $GLOBALS['TT']->pull();
2170 }
2171 }
2172
2173 /**
2174 * Outputs preview info.
2175 *
2176 * @return void
2177 */
2178 function previewInfo() {
2179 if ($this->fePreview) {
2180 $stdMsg = '
2181 <br />
2182 <div align="center">
2183 <table border="3" bordercolor="black" cellpadding="2" bgcolor="red">
2184 <tr>
2185 <td>&nbsp;&nbsp;<font face="Verdana" size="1"><b>PREVIEW!</b></font>&nbsp;&nbsp;</td>
2186 </tr>
2187 </table>
2188 </div>';
2189 $temp_content = $this->config['config']['message_preview'] ? $this->config['config']['message_preview'] : $stdMsg;
2190 echo $temp_content;
2191 }
2192 }
2193
2194 /**
2195 * Returns a link to the login screen with redirect to the front-end
2196 *
2197 * @return string HTML, a tag for a link to the backend.
2198 */
2199 function beLoginLinkIPList() {
2200 if ($this->config['config']['beLoginLinkIPList']) {
2201 if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $this->config['config']['beLoginLinkIPList'])) {
2202 $label = !$this->beUserLogin ? $this->config['config']['beLoginLinkIPList_login'] : $this->config['config']['beLoginLinkIPList_logout'];
2203 if ($label) {
2204 if (!$this->beUserLogin) {
2205 $link = '<a href="'.htmlspecialchars(TYPO3_mainDir.'index.php?redirect_url='.rawurlencode(t3lib_div::getIndpEnv("REQUEST_URI"))).'">'.$label.'</a>';
2206 } else {
2207 $link = '<a href="'.htmlspecialchars(TYPO3_mainDir.'index.php?L=OUT&redirect_url='.rawurlencode(t3lib_div::getIndpEnv("REQUEST_URI"))).'">'.$label.'</a>';
2208 }
2209 return $link;
2210 }
2211 }
2212 }
2213 }
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236 /********************************************
2237 *
2238 * Various internal API functions
2239 *
2240 *******************************************/
2241
2242
2243 /**
2244 * Make simulation filename (without the ".html" ending, only body of filename)
2245 *
2246 * @param string The page title to use
2247 * @param mixed The page id (integer) or alias (string)
2248 * @param integer The type number
2249 * @param string Query-parameters to encode (will be done only if caching is enabled and TypoScript configured for it. I don't know it this makes much sense in fact...)
2250 * @param boolean The "no_cache" status of the link.
2251 * @return string The body of the filename.
2252 * @see getSimulFileName(), t3lib_tstemplate::linkData(), tslib_frameset::frameParams()
2253 */
2254 function makeSimulFileName($inTitle,$page,$type,$addParams='',$no_cache='') {
2255 $titleChars = intval($this->config['config']['simulateStaticDocuments_addTitle']);
2256 $out='';
2257 if ($titleChars) {
2258 $out = t3lib_div::convUmlauts($inTitle);
2259 $out= ereg_replace('[^[:alnum:]_-]','_',trim(substr($out,0,$titleChars)));
2260 $out= ereg_replace('_*$','',$out);
2261 $out= ereg_replace('^_*','',$out);
2262 if ($out) $out.='.';
2263 }
2264 $enc='';
2265 if (strcmp($addParams,'') && !$no_cache) {
2266 switch ((string)$this->config['config']['simulateStaticDocuments_pEnc']) {
2267 case 'md5':
2268 $md5=substr(md5($addParams),0,10);
2269 $enc='+M5'.$md5;
2270
2271 $query='SELECT md5hash FROM cache_md5params WHERE md5hash="'.$md5.'"';
2272 $res=mysql(TYPO3_db,$query);
2273 if (!mysql_num_rows($res)) {
2274 $query='INSERT INTO cache_md5params (md5hash,tstamp,type,params) VALUES ("'.$md5.'",'.time().',1,"'.addslashes($addParams).'")';
2275 $res=mysql(TYPO3_db,$query);
2276 }
2277 break;
2278 case 'base64':
2279 $enc='+B6'.str_replace('=','_',str_replace('/','-',base64_encode($addParams)));
2280 break;
2281 }
2282 }
2283 // Setting page and type number:
2284 $url = $out.$page.$enc;
2285 $url.= ($type || $out || !$this->config['config']['simulateStaticDocuments_noTypeIfNoTitle']) ? '.'.$type : '';
2286 return $url;
2287 }
2288
2289 /**
2290 * Processes a query-string with GET-parameters and returns two strings, one with the parameters that CAN be encoded and one array with those which can't be encoded (encoded by the M5 or B6 methods)
2291 *
2292 * @param string
2293 * @return array Two num keys returned, first is the parameters that MAY be encoded, second is the non-encodable parameters.
2294 * @see makeSimulFileName(), t3lib_tstemplate::linkData()
2295 */
2296 function simulateStaticDocuments_pEnc_onlyP_proc($linkVars) {
2297 $remainLinkVars='';
2298 if (strcmp($linkVars,'')) {
2299 $p = explode('&',$linkVars);
2300 sort($p); // This sorts the parameters - and may not be needed and further it will generate new MD5 hashes in many cases. Maybe not so smart. Hmm?
2301 $rem=array();
2302 foreach($p as $k => $v) {
2303 if ((string)$v) {
2304 list($pName) = explode('=',$v,2);
2305 if (!$this->pEncAllowedParamNames[$pName]) {
2306 unset($p[$k]);
2307 $rem[]=$v;
2308 }
2309 } else unset($p[$k]);
2310 }
2311
2312 $linkVars = count($p) ? '&'.implode('&',$p) : '';
2313 $remainLinkVars = count($rem) ? '&'.implode('&',$rem) : '';
2314 }
2315 return array($linkVars, $remainLinkVars);
2316 }
2317
2318 /**
2319 * Returns the simulated static file name (*.html) for the current page (using the page record in $this->page)
2320 *
2321 * @return string The filename (without path)
2322 * @see makeSimulFileName(), publish.php
2323 */
2324 function getSimulFileName() {
2325 $url='';
2326 $url.=$this->makeSimulFileName($this->page['title'], $this->page['alias']?$this->page['alias']:$this->id, $this->type).'.html';
2327 return $url;
2328 }
2329
2330 /**
2331 * Encryption of email addresses for <A>-tags See the spam protection setup in TS 'config.'
2332 *
2333 * @param string Input string to en/decode: "mailto:blabla@bla.com"
2334 * @param boolean If set, the process is reversed, effectively decoding, not encoding.
2335 * @return string encoded/decoded version of $string
2336 */
2337 function encryptEmail($string,$back=0) {
2338 $out='';
2339 for ($a=0;$a<strlen($string);$a++) {
2340 $charValue = ord(substr($string,$a,1));
2341 $charValue+=intval($GLOBALS['TSFE']->spamProtectEmailAddresses)*($back?-1:1);
2342 $out.=chr($charValue);
2343 }
2344 return $out;
2345 }
2346
2347 /**
2348 * Checks if a PHPfile may be included.
2349 *
2350 * @param string Relative path to php file
2351 * @return boolean Returns true if $GLOBALS['TYPO3_CONF_VARS']['FE']['noPHPscriptInclude'] is not set OR if the file requested for inclusion is found in one of the allowed paths.
2352 * @see tslib_cObj::PHP_SCRIPT(), tslib_feTCE::includeScripts(), tslib_menu::includeMakeMenu()
2353 */
2354 function checkFileInclude($incFile) {
2355 return !$GLOBALS['TYPO3_CONF_VARS']['FE']['noPHPscriptInclude']
2356 || substr($incFile,0,14)=='media/scripts/'
2357 || substr($incFile,0,4+strlen(TYPO3_mainDir))==TYPO3_mainDir.'ext/'
2358 || substr($incFile,0,7+strlen(TYPO3_mainDir))==TYPO3_mainDir.'sysext/'
2359 || substr($incFile,0,14)=='typo3conf/ext/';
2360 }
2361
2362 /**
2363 * Creates an instance of tslib_cObj in $this->cObj
2364 * This instance is used to start the rendering of the TypoScript template structure
2365 *
2366 * @return void
2367 * @see pagegen.php
2368 */
2369 function newCObj() {
2370 $this->cObj =t3lib_div::makeInstance('tslib_cObj');
2371 $this->cObj->start($this->page,'pages');
2372 }
2373
2374 /**
2375 * Substitute the path's to files in the media/ folder like icons used in static_template of TypoScript
2376 * Works on $this->content
2377 *
2378 * @return void
2379 * @access private
2380 * @see pagegen.php, INTincScript()
2381 */
2382 function setAbsRefPrefix() {
2383 if ($this->absRefPrefix) {
2384 $this->content = str_replace('"media/', '"'.$this->absRefPrefix.'media/', $this->content);
2385 $this->content = str_replace('"fileadmin/', '"'.$this->absRefPrefix.'fileadmin/', $this->content);
2386 }
2387 }
2388
2389 /**
2390 * Prints error msg/header.
2391 * Echoes out the HTML content
2392 *
2393 * @param string Message
2394 * @param string Header
2395 * @return void
2396 * @see t3lib_timeTrack::debug_typo3PrintError()
2397 */
2398 function printError($label,$header='Error!') {
2399 t3lib_timeTrack::debug_typo3PrintError($header,$label,0);
2400 }
2401
2402 /**
2403 * Updates the tstamp field of a cache_md5params record to the current time.
2404 *
2405 * @param string The hash string identifying the cache_md5params record for which to update the "tstamp" field to the current time.
2406 * @return void
2407 * @access private
2408 */
2409 function updateMD5paramsRecord($hash) {
2410 $query='UPDATE cache_md5params SET tstamp='.time().' WHERE md5hash="'.addslashes($hash).'"';
2411 $res=mysql(TYPO3_db,$query);
2412 }
2413
2414 /**
2415 * Pass the content through tidy - a little program that cleans up HTML-code
2416 * Requires $this->TYPO3_CONF_VARS['FE']['tidy'] to be true and $this->TYPO3_CONF_VARS['FE']['tidy_path'] to contain the filename/path of tidy including clean-up arguments for tidy. See default value in TYPO3_CONF_VARS in t3lib/config_default.php
2417 *
2418 * @param string The page content to clean up. Will be written to a temporary file which "tidy" is then asked to clean up. File content is read back and returned.
2419 * @return string Returns the
2420 */
2421 function tidyHTML($content) {
2422 if ($this->TYPO3_CONF_VARS['FE']['tidy'] && $this->TYPO3_CONF_VARS['FE']['tidy_path']) {
2423 $oldContent = $content;
2424 $fname = tempnam('','Typo3_Tidydoc_'); // Create temporary name
2425 @unlink ($fname); // Delete if exists, just to be safe.
2426 $fp = fopen ($fname,'wb'); // Open for writing
2427 fputs ($fp, $content); // Put $content
2428 @fclose ($fp); // Close
2429
2430 exec ($this->TYPO3_CONF_VARS['FE']['tidy_path'].' '.$fname, $output); // run the $content through 'tidy', which formats the HTML to nice code.
2431 @unlink ($fname); // Delete the tempfile again
2432 $content = implode($output,chr(10));
2433 if (!trim($content)) {
2434 $content = $oldContent; // Restore old content due empty return value.
2435 $GLOBALS['TT']->setTSlogMessage('"tidy" returned an empty value!',2);
2436 }
2437 $GLOBALS['TT']->setTSlogMessage('"tidy" content lenght: '.strlen($content),0);
2438 }
2439 return $content;
2440 }
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470 /********************************************
2471 *
2472 * Various external API functions - for use in plugins etc.
2473 *
2474 *******************************************/
2475
2476
2477 /**
2478 * Traverses the ->rootLine and returns an array with the first occurrance of storage pid and siteroot pid
2479 *
2480 * @return array Array with keys '_STORAGE_PID' and '_SITEROOT' set to the first occurances found.
2481 */
2482 function getStorageSiterootPids() {
2483 $res=array();
2484 reset($this->rootLine);
2485 while(list(,$rC)=each($this->rootLine)) {
2486 if (!$res['_STORAGE_PID']) $res['_STORAGE_PID']=intval($rC['storage_pid']);
2487 if (!$res['_SITEROOT']) $res['_SITEROOT']=$rC['is_siteroot']?intval($rC['uid']):0;
2488 }
2489 return $res;
2490 }
2491
2492 /**
2493 * Returns the pages TSconfig array based on the currect ->rootLine
2494 *
2495 * @return array
2496 */
2497 function getPagesTSconfig() {
2498 if (!is_array($this->pagesTSconfig)) {
2499 reset($this->rootLine);
2500 $TSdataArray = array();
2501 $TSdataArray[]=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration:
2502 while(list($k,$v)=each($this->rootLine)) {
2503 $TSdataArray[]=$v['TSconfig'];
2504 }
2505 // Parsing the user TS (or getting from cache)
2506 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
2507 $userTS = implode($TSdataArray,chr(10).'[GLOBAL]'.chr(10));
2508 $hash = md5('pageTS:'.$userTS);
2509 $cachedContent = $this->sys_page->getHash($hash,0);
2510 if (isset($cachedContent)) {
2511 $this->pagesTSconfig = unserialize($cachedContent);
2512 } else {
2513 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
2514 $parseObj->parse($userTS);
2515 $this->pagesTSconfig = $parseObj->setup;
2516 $this->sys_page->storeHash($hash,serialize($this->pagesTSconfig),'PAGES_TSconfig');
2517 }
2518 }
2519 return $this->pagesTSconfig;
2520 }
2521
2522 /**
2523 * Sets JavaScript code in the additionalJavaScript array
2524 *
2525 * @param string $key is the key in the array, for num-key let the value be empty. Note reserved keys 'openPic' and 'mouseOver'
2526 * @param string $content is the content if you want any
2527 * @return void
2528 * @see tslib_gmenu::writeMenu(), tslib_cObj::imageLinkWrap()
2529 */
2530 function setJS($key,$content='') {
2531 if ($key) {
2532 switch($key) {
2533 case 'mouseOver':
2534 $this->additionalJavaScript[$key]=
2535 ' // JS function for mouse-over
2536 function over(name,imgObj) {
2537 if (version == "n3" && document[name]) {document[name].src = eval(name+"_h.src");}
2538 else if (imgObj) {imgObj.src = eval(name+"_h.src");}
2539 }
2540 // JS function for mouse-out
2541 function out(name,imgObj) {
2542 if (version == "n3" && document[name]) {document[name].src = eval(name+"_n.src");}
2543 else if (imgObj) {imgObj.src = eval(name+"_n.src");}
2544 }';
2545 break;
2546 case 'openPic':
2547 $this->additionalJavaScript[$key]=
2548 ' function openPic(url,winName,winParams) {
2549 var theWindow = window.open(url,winName,winParams);
2550 if (theWindow) {theWindow.focus();}
2551 }';
2552 break;
2553 default:
2554 $this->additionalJavaScript[$key]=$content;
2555 break;
2556 }
2557 }
2558 }
2559
2560 /**
2561 * Sets CSS data in the additionalCSS array
2562 *
2563 * @param string $key is the key in the array, for num-key let the value be empty
2564 * @param string $content is the content if you want any
2565 * @return void
2566 * @see setJS(), tslib_pibase::pi_setClassStyle()
2567 */
2568 function setCSS($key,$content) {
2569 if ($key) {
2570 switch($key) {
2571 default:
2572 $this->additionalCSS[$key]=$content;
2573 break;
2574 }
2575 }
2576 }
2577
2578 /**
2579 * Seeds the random number engine.
2580 *
2581 * @return void
2582 */
2583 function make_seed() {
2584 list($usec, $sec) = explode(' ', microtime());
2585 $seedV = (float)$sec + ((float)$usec * 100000);
2586 srand($seedV);
2587 }
2588
2589 /**
2590 * Returns a unique md5 hash.
2591 * There is no special magic in this, the only point is that you don't have to call md5(uniqid()) which is slow and by this you are sure to get a unique string each time in a little faster way.
2592 *
2593 * @param string Some string to include in what is hashed. Not significant at all.
2594 * @return string MD5 hash of ->uniqueString, input string and uniqueCounter
2595 */
2596 function uniqueHash($str='') {
2597 return md5($this->uniqueString.'_'.$str.$this->uniqueCounter++);
2598 }
2599
2600 /**
2601 * Sets the cache-flag to 1. Could be called from user-included php-files in order to ensure that a page is not cached.
2602 *
2603 * @return void
2604 */
2605 function set_no_cache() {
2606 $this->no_cache = 1;
2607 }
2608
2609 /**
2610 * Sets the cache-timeout in seconds
2611 *
2612 * @param integer cache-timeout in seconds
2613 * @return void
2614 */
2615 function set_cache_timeout_default($seconds) {
2616 $this->cacheTimeOutDefault = intval($seconds);
2617 }
2618
2619 /**
2620 * Substitute function for the PHP mail() function.
2621 * It will encode the email with the setting of TS 'config.notification_email_encoding' (base64 or none)
2622 * It will also find all links to http:// in the text and substitute with a shorter link using the redirect feature which stores the long link in the database. Depends on configuration in TS 'config.notification_email_urlmode'
2623 *
2624 * @param string recipient email address (or list of)
2625 * @param string The subject
2626 * @param string The message
2627 * @param string The headers (string with lines)
2628 * @return void
2629 * @see t3lib_div::plainMailEncoded()
2630 */
2631 function plainMailEncoded($email,$subject,$message,$headers='') {
2632 $urlmode=$this->config['config']['notification_email_urlmode']; // '76', 'all', ''
2633
2634 if ($urlmode) {
2635 $message=t3lib_div::substUrlsInPlainText($message,$urlmode);
2636 }
2637
2638 t3lib_div::plainMailEncoded(
2639 $email,
2640 $subject,
2641 $message,
2642 $headers,
2643 $this->config['config']['notification_email_encoding'],
2644 $this->config['config']['notification_email_charset']?$this->config['config']['notification_email_charset']:'ISO-8859-1'
2645 );
2646 }
2647
2648 /**
2649 * Split Label function for front-end applications.
2650 *
2651 * @param string Key string. Accepts the "LLL:" prefix.
2652 * @return string Label value, if any.
2653 */
2654 function sL($input) {
2655 if (!$this->lang) $this->initLLvars();
2656
2657 if (strcmp(substr($input,0,4),'LLL:')) {
2658 $t = explode('|',$input);
2659 return $t[$this->langSplitIndex] ? $t[$this->langSplitIndex] : $t[0];
2660 } else {
2661 if (!isset($this->LL_labels_cache[$this->lang][$input])) { // If cached label
2662 $restStr = trim(substr($input,4));
2663 $extPrfx='';
2664 if (!strcmp(substr($restStr,0,4),'EXT:')) {
2665 $restStr = trim(substr($restStr,4));
2666 $extPrfx='EXT:';
2667 }
2668 $parts = explode(':',$restStr);
2669 $parts[0]=$extPrfx.$parts[0];
2670 if (!isset($this->LL_files_cache[$parts[0]])) { // Getting data if not cached
2671 $this->LL_files_cache[$parts[0]] = $this->readLLfile($parts[0]);
2672 }
2673 $this->LL_labels_cache[$this->lang][$input] = $this->getLLL($parts[1],$this->LL_files_cache[$parts[0]]);
2674 }
2675 return $this->LL_labels_cache[$this->lang][$input];
2676 }
2677 }
2678
2679 /**
2680 * Read locallang files - for frontend applications
2681 *
2682 * @param string Reference to a relative filename to include.
2683 * @return array Returns the $LOCAL_LANG array found in the file. If no array found, returns empty array.
2684 */
2685 function readLLfile($fileRef) {
2686 $file = t3lib_div::getFileAbsFileName($fileRef);
2687 if (@is_file($file)) {
2688 include($file);
2689 }
2690 return is_array($LOCAL_LANG)?$LOCAL_LANG:array();
2691 }
2692
2693 /**
2694 * Returns 'locallang' label - may need initializing by initLLvars
2695 *
2696 * @param string Local_lang key for which to return label (language is determined by $this->lang)
2697 * @param array The locallang array in which to search
2698 * @return string Label value of $index key.
2699 */
2700 function getLLL($index,$LOCAL_LANG) {
2701 if (strcmp($LOCAL_LANG[$this->lang][$index],'')) {
2702 return $LOCAL_LANG[$this->lang][$index];
2703 } else {
2704 return $LOCAL_LANG['default'][$index];
2705 }
2706 }
2707
2708 /**
2709 * Initializing the getLL variables needed.
2710 * Sets $this->langSplitIndex based on $this->config['config']['language']
2711 *
2712 * @return void
2713 */
2714 function initLLvars() {
2715 $this->lang = $this->config['config']['language'] ? $this->config['config']['language'] : 'default';
2716 $ls = explode('|',TYPO3_languages);
2717 while(list($i,$v)=each($ls)) {
2718 if ($v==$this->lang) {$this->langSplitIndex=$i; break;}
2719 }
2720 }
2721 }
2722
2723
2724
2725 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_fe.php']) {
2726 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_fe.php']);
2727 }
2728 ?>