Added $Id$ keywords, cleaned up comment tags
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / publish.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 * Publishing pages to static
29 *
30 * Is included from index_ts.php
31 * $Id$
32 *
33 * @author Kasper Skaarhoj <kasper@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 $INTiS_config = $GLOBALS['TSFE']->config['INTincScript'];
100
101 // Special feature: Include libraries
102 $TT->push('Include libraries');
103 reset($INTiS_config);
104 while(list(,$INTiS_cPart)=each($INTiS_config)) {
105 if ($INTiS_cPart['conf']['includeLibs']) {
106 $INTiS_resourceList = t3lib_div::trimExplode(',',$INTiS_cPart['conf']['includeLibs'],1);
107 reset($INTiS_resourceList);
108 while(list(,$INTiS_theLib)=each($INTiS_resourceList)) {
109 $INTiS_incFile=$GLOBALS['TSFE']->tmpl->getFileName($INTiS_theLib);
110 if ($INTiS_incFile) {
111 include_once('./'.$INTiS_incFile);
112 }
113 }
114 }
115 }
116 $TT->pull();
117 $TSFE->INTincScript();
118 $TT->pull();
119 }
120
121 // Get filename
122 $temp_fileName = $TSFE->getSimulFileName();
123
124 if (!isset($temp_publish_array[$temp_fileName])) { // If the page is not rendered allready, which will happen if a hidden page is 'published'
125 // Images file
126 // $temp_publish_row = $TSFE->getSearchCache();
127 // $temp_publish_imagesOnPage= unserialize($temp_publish_row['tempFile_data']);
128 // $temp_publish_imagesTotal = array_merge($temp_publish_imagesTotal, $temp_publish_imagesOnPage);
129 // Store the data for this page:
130 $temp_publish_array[$temp_fileName]= array($temp_publish_id, $temp_publish_imagesOnPage, $TSFE->content);
131 }
132 $TT->pull();
133 }
134 //debug($HTTP_POST_VARS);
135 //debug($temp_publish_imagesTotal);
136 //debug(array_unique($temp_publish_imagesTotal));
137
138
139 // ***************************
140 // Publishing, writing files
141 // ***************************
142 $publishDir = $TYPO3_CONF_VARS['FE']['publish_dir'];
143 if ($publishDir && @is_dir($publishDir)) {
144 $publishDir = ereg_replace('/*$','',$publishDir).'/';
145 debug('Publishing in: '.$publishDir,1);
146 reset($temp_publish_array);
147 while(list($key,$val)=each($temp_publish_array)) {
148 $file = $publishDir.$key;
149 t3lib_div::writeFile($file,$val[2]);
150 debug('Writing: '.$file,1);
151 }
152 // debug($temp_publish_array);
153 } else {
154 debug('No publish_dir specified...');
155 }
156
157
158 $TT->pull();
159 // Restoring the TSFE object
160 $TSFE = $temp_publish_TSFE;
161
162 ?>