*** empty log message ***
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_page.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 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 * Contains a class with "Page functions" mainly for the frontend
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
32 * XHTML-trans compliant
33 *
34 * @author Kasper Skaarhoj <kasper@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 101: class t3lib_pageSelect
42 * 117: function init($show_hidden)
43 *
44 * SECTION: Selecting page records
45 * 156: function getPage($uid)
46 * 171: function getPage_noCheck($uid)
47 * 186: function getFirstWebPage($uid)
48 * 203: function getPageIdFromAlias($alias)
49 * 219: function getPageOverlay($pageInput,$lUid=-1)
50 *
51 * SECTION: Page related: Menu, Domain record, Root line
52 * 296: function getMenu($uid,$fields='*',$sortField='sorting',$addWhere='')
53 * 315: function getDomainStartPage($domain, $path='',$request_uri='')
54 * 362: function getRootLine($uid, $MP='')
55 * 422: function getPathFromRootline($rl,$len=20)
56 * 443: function getExtURL($pagerow,$disable=0)
57 *
58 * SECTION: Selecting records in general
59 * 491: function checkRecord($table,$uid,$checkPage=0)
60 * 521: function getRawRecord($table,$uid,$fields='*')
61 * 544: function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='')
62 *
63 * SECTION: Caching and standard clauses
64 * 595: function getHash($hash,$expTime=0)
65 * 618: function storeHash($hash,$data,$ident)
66 * 636: function deleteClause($table)
67 * 651: function enableFields($table,$show_hidden=-1,$ignore_array=array())
68 *
69 * TOTAL FUNCTIONS: 18
70 * (This index is automatically created/updated by the extension "extdeveval")
71 *
72 */
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 /**
92 * Page functions, a lot of sql/pages-related functions
93 * Mainly used in the frontend but also in some cases in the backend.
94 * It's important to set the right $where_hid_del in the object so that the functions operate properly
95 *
96 * @author Kasper Skaarhoj <kasper@typo3.com>
97 * @package TYPO3
98 * @subpackage t3lib
99 * @see tslib_fe::fetch_the_id()
100 */
101 class t3lib_pageSelect {
102 var $urltypes = Array('','http://','ftp://','mailto:');
103 var $where_hid_del = ' AND NOT pages.deleted'; // This is not the final clauses. There will normally be conditions for the hidden,starttime and endtime fields as well. You MUST initialize the object by the init() function
104 var $sys_language_uid=0;
105
106
107
108
109 /**
110 * init() MUST be run directly after creating a new template-object
111 * This sets the internal variable $this->where_hid_del to the correct where clause for page records taking deleted/hidden/starttime/endtime into account
112 *
113 * @param boolean If $show_hidden is true, the hidden-field is ignored!! Normally this should be false. Is used for previewing.
114 * @return void
115 * @see tslib_fe::fetch_the_id(), tx_tstemplateanalyzer::initialize_editor()
116 */
117 function init($show_hidden) {
118 $this->where_hid_del = ' AND NOT pages.deleted ';
119 if (!$show_hidden) {
120 $this->where_hid_del.= 'AND NOT pages.hidden ';
121 }
122 $this->where_hid_del.= 'AND (pages.starttime<='.$GLOBALS['SIM_EXEC_TIME'].') AND (pages.endtime=0 OR pages.endtime>'.$GLOBALS['SIM_EXEC_TIME'].') ';
123 }
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141 /*******************************************
142 *
143 * Selecting page records
144 *
145 ******************************************/
146
147 /**
148 * Returns the $row for the page with uid = $uid (observing ->where_hid_del)
149 * Any pages_language_overlay will be applied before the result is returned.
150 * If no page is found an empty array is returned.
151 *
152 * @param integer The page id to look up.
153 * @return array The page row with overlayed localized fields. Empty it no page.
154 * @see getPage_noCheck()
155 */
156 function getPage($uid) {
157 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($uid).$this->where_hid_del);
158 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
159 return $this->getPageOverlay($row);
160 }
161 return Array();
162 }
163
164 /**
165 * Return the $row for the page with uid = $uid WITHOUT checking for ->where_hid_del (start- and endtime or hidden). Only "deleted" is checked!
166 *
167 * @param integer The page id to look up
168 * @return array The page row with overlayed localized fields. Empty it no page.
169 * @see getPage()
170 */
171 function getPage_noCheck($uid) {
172 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($uid).$this->deleteClause('pages'));
173 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
174 return $this->getPageOverlay($row);
175 }
176 return Array();
177 }
178
179 /**
180 * Returns the $row of the first web-page in the tree (for the default menu...)
181 *
182 * @param integer The page id for which to fetch first subpages (PID)
183 * @return mixed If found: The page record (with overlayed localized fields, if any). If NOT found: blank value (not array!)
184 * @see tslib_fe::fetch_the_id()
185 */
186 function getFirstWebPage($uid) {
187 $output = '';
188 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'pid='.intval($uid).$this->where_hid_del, '', 'sorting', '1');
189 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
190 $output = $this->getPageOverlay($row);
191 }
192 $GLOBALS['TYPO3_DB']->sql_free_result($res);
193 return $output;
194 }
195
196 /**
197 * Returns a pagerow for the page with alias $alias
198 *
199 * @param string The alias to look up the page uid for.
200 * @return integer Returns page uid (integer) if found, otherwise 0 (zero)
201 * @see tslib_fe::checkAndSetAlias(), tslib_cObj::typoLink()
202 */
203 function getPageIdFromAlias($alias) {
204 $alias = strtolower($alias);
205 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'alias="'.$GLOBALS['TYPO3_DB']->quoteStr($alias, 'pages').'" AND NOT pages.deleted');
206 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
207 return $row['uid'];
208 }
209 return 0;
210 }
211
212 /**
213 * Returns the relevant page overlay record fields
214 *
215 * @param mixed If $pageInput is an integer, it's the pid of the pageOverlay record and thus the page overlay record is returned. If $pageInput is an array, it's a page-record and based on this page record the language record is found and OVERLAYED before the page record is returned.
216 * @param integer Language UID if you want to set an alternative value to $this->sys_language_uid which is default. Should be >=0
217 * @return array Page row which is overlayed with language_overlay record (or the overlay record alone)
218 */
219 function getPageOverlay($pageInput,$lUid=-1) {
220
221 // Initialize:
222 if ($lUid<0) $lUid = $this->sys_language_uid;
223 unset($row);
224
225 // If language UID is different from zero, do overlay:
226 if ($lUid) {
227 $fieldArr = explode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']);
228 if (is_array($pageInput)) {
229 $page_id = $pageInput['uid']; // Was the whole record
230 $fieldArr = array_intersect($fieldArr,array_keys($pageInput)); // Make sure that only fields which exist in the incoming record are overlaid!
231 } else {
232 $page_id = $pageInput; // Was the id
233 }
234
235 if (count($fieldArr)) {
236 /*
237 NOTE to enabledFields('pages_language_overlay'):
238 Currently the showHiddenRecords of TSFE set will allow pages_language_overlay records to be selected as they are child-records of a page.
239 However you may argue that the showHiddenField flag should determine this. But that's not how it's done right now.
240 */
241 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
242 implode(',',$fieldArr),
243 'pages_language_overlay',
244 'pid='.intval($page_id).'
245 AND sys_language_uid='.intval($lUid).
246 $this->enableFields('pages_language_overlay'),
247 '',
248 '',
249 '1'
250 );
251 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
252 }
253 }
254
255 // Create output:
256 if (is_array($pageInput)) {
257 return is_array($row) ? array_merge($pageInput,$row) : $pageInput; // If the input was an array, simply overlay the newfound array and return...
258 } else {
259 return is_array($row) ? $row : array(); // always an array in return
260 }
261 }
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280 /*******************************************
281 *
282 * Page related: Menu, Domain record, Root line
283 *
284 ******************************************/
285
286 /**
287 * Returns an array with pagerows for subpages with pid=$uid (which is pid here!). This is used for menus.
288 *
289 * @param integer The page id for which to fetch subpages (PID)
290 * @param string List of fields to select. Default is "*" = all
291 * @param string The field to sort by. Default is "sorting"
292 * @param string Optional additional where clauses. Like "AND title like '%blabla%'" for instance.
293 * @return array Array with key/value pairs; keys are page-uid numbers. values are the corresponding page records (with overlayed localized fields, if any)
294 * @see tslib_fe::getPageShortcut(), tslib_menu::makeMenu(), tx_wizardcrpages_webfunc_2, tx_wizardsortpages_webfunc_2
295 */
296 function getMenu($uid,$fields='*',$sortField='sorting',$addWhere='') {
297 $output = Array();
298 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'pages', 'pid='.intval($uid).$this->where_hid_del.' '.$addWhere, '', $sortField);
299 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
300 $output[$row['uid']]=$this->getPageOverlay($row);
301 }
302 return $output;
303 }
304
305 /**
306 * Will find the page carrying the domain record matching the input domain.
307 * Might exit after sending a redirect-header IF a found domain record instructs to do so.
308 *
309 * @param string Domain name to search for. Eg. "www.typo3.com". Typical the HTTP_HOST value.
310 * @param string Path for the current script in domain. Eg. "/somedir/subdir". Typ. supplied by t3lib_div::getIndpEnv('SCRIPT_NAME')
311 * @param string Request URI: Used to get parameters from if they should be appended. Typ. supplied by t3lib_div::getIndpEnv('REQUEST_URI')
312 * @return mixed If found, returns integer with page UID where found. Otherwise blank. Might exit if location-header is sent, see description.
313 * @see tslib_fe::findDomainRecord()
314 */
315 function getDomainStartPage($domain, $path='',$request_uri='') {
316 $domain = explode(':',$domain);
317 $domain = strtolower(ereg_replace('\.$','',$domain[0]));
318 // Removing extra trailing slashes
319 $path = trim(ereg_replace('\/[^\/]*$','',$path));
320 // Appending to domain string
321 $domain.= $path;
322 $domain = ereg_replace('\/*$','',$domain);
323
324 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
325 'pages.uid,sys_domain.redirectTo,sys_domain.prepend_params',
326 'pages,sys_domain',
327 'pages.uid=sys_domain.pid
328 AND NOT sys_domain.hidden
329 AND (sys_domain.domainName="'.$GLOBALS['TYPO3_DB']->quoteStr($domain, 'sys_domain').'" OR sys_domain.domainName="'.$GLOBALS['TYPO3_DB']->quoteStr($domain.'/', 'sys_domain').'") '.
330 $this->where_hid_del,
331 '',
332 '',
333 1
334 );
335 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
336 if ($row['redirectTo']) {
337 $rURL = $row['redirectTo'];
338 if ($row['prepend_params']) {
339 $rURL = ereg_replace('\/$','',$rURL);
340 $prependStr = ereg_replace('^\/','',substr($request_uri,strlen($path)));
341 $rURL.='/'.$prependStr;
342 }
343 Header('Location: '.t3lib_div::locationHeaderUrl($rURL));
344 exit;
345 } else {
346 return $row['uid'];
347 }
348 }
349 }
350
351 /**
352 * Returns array with fields of the pages from here ($uid) and back to the root
353 * NOTICE: This function only takes deleted pages into account! So hidden, starttime and endtime restricted pages are included no matter what.
354 * Further: If any "recycler" page is found (doktype=255) then it will also block for the rootline)
355 * If you want more fields in the rootline records than default such can be added by listing them in $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields']
356 *
357 * @param integer The page uid for which to seek back to the page tree root.
358 * @param string Commalist of MountPoint parameters, eg. "1-2,3-4" etc. Normally this value comes from the GET var, MP
359 * @return array Array with page records from the root line as values. The array is ordered with the outer records first and root record in the bottom. The keys are numeric but in reverse order. So if you traverse/sort the array by the numeric keys order you will get the order from root and out. If an error is found (like eternal looping or invalid mountpoint) it will return an empty array.
360 * @see tslib_fe::getPageAndRootline()
361 */
362 function getRootLine($uid, $MP='') {
363 $selFields = t3lib_div::uniqueList('pid,uid,title,alias,nav_title,media,layout,hidden,starttime,endtime,fe_group,extendToSubpages,doktype,TSconfig,storage_pid,is_siteroot,mount_pid,'.$GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields']);
364
365 // Splitting the $MP parameters if present
366 $MPA = array();
367 if ($MP) {
368 $MPA = explode(',',$MP);
369 reset($MPA);
370 while(list($MPAk) = each($MPA)) {
371 $MPA[$MPAk] = explode('-', $MPA[$MPAk]);
372 }
373 }
374
375 // Max 20 levels in the page tree.
376 $loopCheck = 20;
377 $theRowArray = Array();
378 $uid = intval($uid);
379 while ($uid!=0 && $loopCheck>0) {
380 $loopCheck--;
381 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selFields, 'pages', 'uid='.intval($uid).' AND NOT pages.deleted AND pages.doktype!=255');
382 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
383 if (count($MPA)) {
384 $curMP = end($MPA);
385 if (!strcmp($row['uid'],$curMP[0])) {
386 array_pop($MPA);
387 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selFields, 'pages', 'uid='.intval($curMP[1]).' AND NOT pages.deleted AND pages.doktype!=255');
388 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
389 $row['_MOUNTED_FROM'] = $curMP[0];
390 if (!is_array($row)) return array(); // error - no page...
391 }
392 }
393 $uid = $row['pid'];
394 $theRowArray[] = $this->getPageOverlay($row);
395 } else {
396 $theRowArray = '';
397 break;
398 }
399 }
400
401 // Create output array (with reversed order of numeric keys):
402 $output = Array();
403 if (is_array($theRowArray) && !count($MPA)) {
404 $c = count($theRowArray);
405 foreach($theRowArray as $key => $val) {
406 $c--;
407 $output[$c] = $val;
408 }
409 }
410 return $output;
411 }
412
413 /**
414 * Creates a "path" string for the input root line array titles.
415 * Used for writing statistics.
416 *
417 * @param array A rootline array!
418 * @param integer The max length of each title from the rootline.
419 * @return string The path in the form "/page title/This is another pageti.../Another page"
420 * @see tslib_fe::getConfigArray()
421 */
422 function getPathFromRootline($rl,$len=20) {
423 if (is_array($rl)) {
424 $c=count($rl);
425 $path = '';
426 for ($a=0;$a<$c;$a++) {
427 if ($rl[$a]['uid']) {
428 $path.='/'.t3lib_div::fixed_lgd(strip_tags($rl[$a]['title']),$len);
429 }
430 }
431 return $path;
432 }
433 }
434
435 /**
436 * Returns the URL type for the input page row IF the doktype is 3 and not disabled.
437 *
438 * @param array The page row to return URL type for
439 * @param boolean A flag to simply disable any output from here.
440 * @return string The URL type from $this->urltypes array. False if not found or disabled.
441 * @see tslib_fe::checkJumpUrl()
442 */
443 function getExtURL($pagerow,$disable=0) {
444 if ($pagerow['doktype']==3 && !$disable) {
445 $redirectTo = $this->urltypes[$pagerow['urltype']].$pagerow['url'];
446
447 // If relative path, prefix Site URL:
448 $uI = parse_url($redirectTo);
449 if (!$uI['scheme'] && substr($redirectTo,0,1)!='/') { // relative path assumed now...
450 $redirectTo = t3lib_div::getIndpEnv('TYPO3_SITE_URL').$redirectTo;
451 }
452 return $redirectTo;
453 }
454 }
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476 /*********************************
477 *
478 * Selecting records in general
479 *
480 **********************************/
481
482 /**
483 * Checks if a record exists and is accessible.
484 * The row is returned if everything's OK.
485 *
486 * @param string The table name to search
487 * @param integer The uid to look up in $table
488 * @param boolean If checkPage is set, it's also required that the page on which the record resides is accessible
489 * @return mixed Returns array (the record) if OK, otherwise blank/0 (zero)
490 */
491 function checkRecord($table,$uid,$checkPage=0) {
492 global $TCA;
493 $uid=intval($uid);
494 if (is_array($TCA[$table])) {
495 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($uid).$this->enableFields($table));
496 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
497 $GLOBALS['TYPO3_DB']->sql_free_result($res);
498 if ($checkPage) {
499 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'uid='.intval($row['pid']).$this->enableFields('pages'));
500 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
501 return $row;
502 } else {
503 return 0;
504 }
505 } else {
506 return $row;
507 }
508 }
509 }
510 }
511
512 /**
513 * Returns record no matter what - except if record is deleted
514 *
515 * @param string The table name to search
516 * @param integer The uid to look up in $table
517 * @param string The fields to select, default is "*"
518 * @return mixed Returns array (the record) if found, otherwise blank/0 (zero)
519 * @see getPage_noCheck()
520 */
521 function getRawRecord($table,$uid,$fields='*') {
522 global $TCA;
523 $uid=intval($uid);
524 if (is_array($TCA[$table])) {
525 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid='.intval($uid).$this->deleteClause($table));
526 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
527 return $row;
528 }
529 }
530 }
531
532 /**
533 * Selects records based on matching a field (ei. other than UID) with a value
534 *
535 * @param string The table name to search, eg. "pages" or "tt_content"
536 * @param string The fieldname to match, eg. "uid" or "alias"
537 * @param string The value that fieldname must match, eg. "123" or "frontpage"
538 * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
539 * @param string Optional GROUP BY field(s), if none, supply blank string.
540 * @param string Optional ORDER BY field(s), if none, supply blank string.
541 * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
542 * @return mixed Returns array (the record) if found, otherwise blank/0 (zero)
543 */
544 function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='') {
545 global $TCA;
546 if (is_array($TCA[$theTable])) {
547 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
548 '*',
549 $theTable,
550 $theField.'="'.$GLOBALS['TYPO3_DB']->quoteStr($theValue, $theTable).'"'.
551 $this->deleteClause($theTable).' '.
552 $whereClause, // whereClauseMightContainGroupOrderBy
553 $groupBy,
554 $orderBy,
555 $limit
556 );
557 $rows = array();
558 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
559 $rows[] = $row;
560 }
561 $GLOBALS['TYPO3_DB']->sql_free_result($res);
562 if (count($rows)) return $rows;
563 }
564 }
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579 /*********************************
580 *
581 * Caching and standard clauses
582 *
583 **********************************/
584
585 /**
586 * Returns string value stored for the hash string in the table "cache_hash"
587 * Can be used to retrieved a cached value
588 * Can be used from your frontend plugins if you like. Is also used to store the parsed TypoScript template structures. You can call it directly like t3lib_pageSelect::getHash()
589 *
590 * @param string The hash-string which was used to store the data value
591 * @param integer Allowed expiretime in seconds. Basically a record is selected only if it is not older than this value in seconds. If expTime is not set, the hashed value will never expire.
592 * @return string The "content" field of the "cache_hash" table row.
593 * @see tslib_TStemplate::start(), storeHash()
594 */
595 function getHash($hash,$expTime=0) {
596 //
597 $expTime = intval($expTime);
598 if ($expTime) {
599 $whereAdd = ' AND tstamp > '.(time()-$expTime);
600 }
601 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash="'.$GLOBALS['TYPO3_DB']->quoteStr($hash, 'cache_hash').'"'.$whereAdd);
602 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
603 $GLOBALS['TYPO3_DB']->sql_free_result($res);
604 return $row['content'];
605 }
606 }
607
608 /**
609 * Stores a string value in the cache_hash table identified by $hash.
610 * Can be used from your frontend plugins if you like. You can call it directly like t3lib_pageSelect::storeHash()
611 *
612 * @param string 32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored)
613 * @param string The data string. If you want to store an array, then just serialize it first.
614 * @param string $ident is just a textual identification in order to inform about the content! May be 20 characters long.
615 * @return void
616 * @see tslib_TStemplate::start(), getHash()
617 */
618 function storeHash($hash,$data,$ident) {
619 $insertFields = array(
620 'hash' => $hash,
621 'content' => $data,
622 'ident' => $ident,
623 'tstamp' => time()
624 );
625 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash="'.$GLOBALS['TYPO3_DB']->quoteStr($hash, 'cache_hash').'"');
626 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
627 }
628
629 /**
630 * Returns the "AND NOT deleted" clause for the tablename given IF $TCA configuration points to such a field.
631 *
632 * @param string Tablename
633 * @return string
634 * @see enableFields()
635 */
636 function deleteClause($table) {
637 global $TCA;
638 return $TCA[$table]['ctrl']['delete'] ? ' AND NOT '.$TCA[$table]['ctrl']['delete'] : '';
639 }
640
641 /**
642 * Returns a part of a WHERE clause which will filter out records with start/end times or hidden/fe_groups fields set to values that should de-select them according to the current time, preview settings or user login. Definitely a frontend function.
643 * Is using the $TCA arrays "ctrl" part where the key "enablefields" determines for each table which of these features applies to that table.
644 *
645 * @param string Table name found in the $TCA array
646 * @param integer If $show_hidden is set (0/1), any hidden-fields in records are ignored. NOTICE: If you call this function, consider what to do with the show_hidden parameter. Maybe it should be set? See tslib_cObj->enableFields where it's implemented correctly.
647 * @param array Array you can pass where keys can be "disabled", "starttime", "endtime", "fe_group" (keys from "enablefields" in TCA) and if set they will make sure that part of the clause is not added. Thus disables the specific part of the clause. For previewing etc.
648 * @return string The clause starting like " AND ...=... AND ...=..."
649 * @see tslib_cObj::enableFields(), deleteClause()
650 */
651 function enableFields($table,$show_hidden=-1,$ignore_array=array()) {
652 if ($show_hidden==-1 && is_object($GLOBALS['TSFE'])) { // If show_hidden was not set from outside and if TSFE is an object, set it based on showHiddenPage and showHiddenRecords from TSFE
653 $show_hidden = $table=='pages' ? $GLOBALS['TSFE']->showHiddenPage : $GLOBALS['TSFE']->showHiddenRecords;
654 }
655 if ($show_hidden==-1) $show_hidden=0; // If show_hidden was not changed during the previous evaluation, do it here.
656
657 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
658 $query='';
659 if (is_array($ctrl)) {
660 if ($ctrl['delete']) {
661 $query.=' AND NOT '.$table.'.'.$ctrl['delete'];
662 }
663 if (is_array($ctrl['enablecolumns'])) {
664 if ($ctrl['enablecolumns']['disabled'] && !$show_hidden && !$ignore_array['disabled']) {
665 $field = $table.'.'.$ctrl['enablecolumns']['disabled'];
666 $query.=' AND NOT '.$field;
667 }
668 if ($ctrl['enablecolumns']['starttime'] && !$ignore_array['starttime']) {
669 $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
670 $query.=' AND ('.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
671 }
672 if ($ctrl['enablecolumns']['endtime'] && !$ignore_array['endtime']) {
673 $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
674 $query.=' AND ('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
675 }
676 if ($ctrl['enablecolumns']['fe_group'] && !$ignore_array['fe_group']) {
677 $field = $table.'.'.$ctrl['enablecolumns']['fe_group'];
678 $gr_list = $GLOBALS['TSFE']->gr_list;
679 if (!strcmp($gr_list,'')) $gr_list=0;
680 $query.=' AND '.$field.' IN ('.$gr_list.')';
681 }
682 }
683 } else {
684 die ('NO entry in the $TCA-array for the table "'.$table.'". This means that the function enableFields() is called with an invalid table name as argument.');
685 }
686
687 return $query;
688 }
689 }
690
691
692
693 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_page.php']) {
694 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_page.php']);
695 }
696 ?>