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