Updated Copyright notices
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / publish.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@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 * Publishing pages to static
29 *
30 * Is included from index_ts.php
31 * $Id$
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 * @package TYPO3
35 * @subpackage tslib
36 */
37
38
39 /*
40
41 TODO:
42
43 - Show publish-dir in interface
44 - enabled checkboxes to select pages / frames
45 - which-frames selecteble by TS
46 - disable publishing of hidden/starttime/endtime/fe_group pages.
47 - remove published files option
48 - enable writing of images
49 - Policy: HTML-files overridden always, mediafiles are only overwritten if mtime is different.
50
51 */
52
53
54
55 if (!is_object($TSFE)) {die('You cannot execute this file directly. It\'s meant to be included from index_ts.php');}
56
57
58 // Storing the TSFE object
59 $temp_publish_TSFE = $TSFE;
60 $TT->push('Publishing','');
61 $temp_publish_pages = explode(',',$BE_USER->extPublishList);
62 $temp_publish_imagesTotal = array();
63 $temp_publish_array = array(); // Collects the rendered pages.
64
65 while(list(,$temp_publish_id)=each($temp_publish_pages)) {
66 $TT->push('Page '.$temp_publish_id,'');
67 //debug($temp_publish_id,1);
68 $temp_TSFEclassName=t3lib_div::makeInstanceClassName('tslib_fe');
69 $TSFE = new $temp_TSFEclassName($TYPO3_CONF_VARS,$temp_publish_id,0);
70
71 $TSFE->initFEuser();
72 $TSFE->clear_preview();
73 $TSFE->determineId();
74 $TSFE->initTemplate();
75 $TSFE->getFromCache();
76
77 $TSFE->getConfigArray();
78 $TSFE->setUrlIdToken();
79 if ($TSFE->isGeneratePage()) {
80 $TSFE->generatePage_preProcessing();
81 $temp_theScript=$TSFE->generatePage_whichScript();
82 if ($temp_theScript) {
83 include($temp_theScript);
84 } else {
85 require_once (PATH_tslib.'class.tslib_pagegen.php'); // Just formal, this is already included from index_ts.php
86 include(PATH_tslib.'pagegen.php');
87 }
88 $TSFE->generatePage_postProcessing();
89 } elseif ($TSFE->isINTincScript()) {
90 require_once (PATH_tslib.'class.tslib_pagegen.php'); // Just formal, this is already included from index_ts.php
91 include(PATH_tslib.'pagegen.php');
92 }
93
94 // ********************************
95 // $GLOBALS['TSFE']->config['INTincScript']
96 // *******************************
97 if ($TSFE->isINTincScript()) {
98 $TT->push('Internal PHP-scripts','');
99 $TSFE->INTincScript();
100 $TT->pull();
101 }
102
103 // Get filename
104 $temp_fileName = $TSFE->getSimulFileName();
105
106 if (!isset($temp_publish_array[$temp_fileName])) { // If the page is not rendered allready, which will happen if a hidden page is 'published'
107 // Images file
108 // $temp_publish_row = $TSFE->getSearchCache();
109 // $temp_publish_imagesOnPage= unserialize($temp_publish_row['tempFile_data']);
110 // $temp_publish_imagesTotal = array_merge($temp_publish_imagesTotal, $temp_publish_imagesOnPage);
111 // Store the data for this page:
112 $temp_publish_array[$temp_fileName]= array($temp_publish_id, $temp_publish_imagesOnPage, $TSFE->content);
113 }
114 $TT->pull();
115 }
116 //debug($temp_publish_imagesTotal);
117 //debug(array_unique($temp_publish_imagesTotal));
118
119
120 // ***************************
121 // Publishing, writing files
122 // ***************************
123 $publishDir = $TYPO3_CONF_VARS['FE']['publish_dir'];
124 if ($publishDir && @is_dir($publishDir)) {
125 $publishDir = ereg_replace('/*$','',$publishDir).'/';
126 debug('Publishing in: '.$publishDir,1);
127 reset($temp_publish_array);
128 while(list($key,$val)=each($temp_publish_array)) {
129 $file = $publishDir.$key;
130 t3lib_div::writeFile($file,$val[2]);
131 debug('Writing: '.$file,1);
132 }
133 // debug($temp_publish_array);
134 } else {
135 debug('No publish_dir specified...');
136 }
137
138
139 $TT->pull();
140 // Restoring the TSFE object
141 $TSFE = $temp_publish_TSFE;
142
143 ?>