* Fixed bug #11125: Validation issue: End tag for "br" omitted, but OMITTAG NO was...
[Packages/TYPO3.CMS.git] / typo3 / mod / user / ws / publish.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 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 * Module: Workspace publisher
29 *
30 * $Id$
31 *
32 * @author Dmitry Dulepov <typo3@accio.lv>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 70: class SC_mod_user_ws_publish extends t3lib_SCbase
40 * 83: function init()
41 * 95: function closeAndReload()
42 * 106: function nextPortion(val)
43 * 127: function main()
44 * 142: function printContent()
45 * 151: function getContent()
46 * 227: function getRecords()
47 * 243: function formatProgressBlock($messageLabel)
48 *
49 * TOTAL FUNCTIONS: 8
50 * (This index is automatically created/updated by the extension "extdeveval")
51 *
52 */
53
54
55 // Initialize module:
56 unset($MCONF);
57 require('conf.php');
58 require($BACK_PATH . 'init.php');
59 require($BACK_PATH . 'template.php');
60 $BE_USER->modAccess($MCONF, 1);
61
62 // Include libraries of various kinds used inside:
63 $LANG->includeLLFile('EXT:lang/locallang_mod_user_ws.xml');
64 require_once(PATH_t3lib . 'class.t3lib_scbase.php');
65 require_once(PATH_typo3 . 'mod/user/ws/class.wslib.php');
66 require_once(PATH_t3lib . 'class.t3lib_tcemain.php');
67
68 define('MAX_RECORDS_TO_PUBLISH', 30);
69
70 class SC_mod_user_ws_publish extends t3lib_SCbase {
71
72 var $isSwap;
73 var $title;
74 var $nextRecordNumber;
75 var $publishData;
76 var $recordCount;
77
78 /**
79 * Document Template Object
80 *
81 * @var mediumDoc
82 */
83 var $doc;
84
85 /**
86 * Initializes the module. See <code>t3lib_SCbase::init()</code> for more information.
87 *
88 * @return void
89 */
90 function init() {
91 // Setting module configuration:
92 $this->MCONF = $GLOBALS['MCONF'];
93
94 $this->isSwap = t3lib_div::_GP('swap');
95 $this->nextRecordNumber = t3lib_div::_GP('continue_publish');
96
97 // Initialize Document Template object:
98 $this->doc = t3lib_div::makeInstance('mediumDoc');
99 $this->doc->backPath = $GLOBALS['BACK_PATH'];
100 $this->doc->JScode = '<script type="text/javascript">/*<![CDATA[*/
101 function closeAndReload() {
102 //window.opener.location.reload(); window.close();
103 window.location.href = \'index.php\';
104 }
105
106 function nextPortion(val) {
107 setTimeout(\'window.location.href = "publish.php?continue_publish=\' + val + \'&swap=' . ($this->isSwap ? 1 : 0) . '"\', 750);
108 }
109 /*]]>*/</script>
110 ';
111 $this->doc->inDocStyles = '
112 #progress-block { width: 450px; margin: 50px auto; text-align: center; }
113 H3 { margin-bottom: 20px; }
114 P, IMG { margin-bottom: 20px; }
115 #progress-block A { text-decoration: underline; }
116 ';
117
118 // Parent initialization:
119 t3lib_SCbase::init();
120 }
121
122 /**
123 * Creates module content.
124 *
125 * @return void
126 */
127 function main() {
128 $this->title = $GLOBALS['LANG']->getLL($this->isSwap ? 'swap_title' : 'publish_title');
129
130 $content = $this->getContent(); // sets body parts to doc!
131
132 $this->content .= $this->doc->startPage($this->title);
133 $this->content .= $content;
134 $this->content .= $this->doc->endPage();
135 }
136
137 /**
138 * Outputs content.
139 *
140 * @return void
141 */
142 function printContent() {
143 echo $this->content;
144 }
145
146 /**
147 * Performs action and generates content.
148 *
149 * @return string Generated content
150 */
151 function getContent() {
152 $content = '';
153 if ($this->nextRecordNumber) {
154 // Prepare limited set of records
155 $this->publishData = $GLOBALS['BE_USER']->getSessionData('workspacePublisher');
156 $this->recordCount = $GLOBALS['BE_USER']->getSessionData('workspacePublisher_count');
157 $limitedCmd = array(); $numRecs = 0;
158 foreach ($this->publishData as $table => $recs) {
159 foreach ($recs as $key => $value) {
160 $numRecs++;
161 $limitedCmd[$table][$key] = $value;
162 //$this->content .= $table.':'.$key.'<br />';
163 if ($numRecs == MAX_RECORDS_TO_PUBLISH) {
164 break;
165 }
166 }
167 if ($numRecs == MAX_RECORDS_TO_PUBLISH) {
168 break;
169 }
170 }
171
172 if ($numRecs == 0) {
173 // All done
174 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', null);
175 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher_count', 0);
176 $content .= '<div id="progress-block"><h3>' . $this->title . '</h3><p>';
177 $content .= $GLOBALS['LANG']->getLL($this->isSwap ? 'workspace_swapped' : 'workspace_published');
178 $content .= '</p><p><a href="index.php">' . $GLOBALS['LANG']->getLL('return_to_index') . '</a>';
179 $content .= '</p></div>';
180 }
181 else {
182 // Execute the commands:
183 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
184 $tce->stripslashes_values = 0;
185 $tce->start(array(), $limitedCmd);
186 $tce->process_cmdmap();
187
188 $errors = $tce->errorLog;
189 if (count($errors) > 0) {
190 $content .= '<h3>' . $GLOBALS['LANG']->getLL('label_errors') . '</h3><br />' . implode('<br />', $errors);
191 $content .= '<br /><br /><a href="index.php">' . $GLOBALS['LANG']->getLL('return_to_index') . '</a>';
192 }
193 else {
194
195 // Unset processed records
196 foreach ($limitedCmd as $table => $recs) {
197 foreach ($recs as $key => $value) {
198 unset($this->publishData[$table][$key]);
199 }
200 }
201 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', $this->publishData);
202 $content .= $this->formatProgressBlock($this->isSwap ? 'swap_status' : 'publish_status');
203 $this->doc->bodyTagAdditions = 'onload="nextPortion(' . ($this->nextRecordNumber + MAX_RECORDS_TO_PUBLISH) . ')"';
204 }
205 }
206 }
207 else {
208 $this->getRecords();
209 if ($this->recordCount > 0) {
210 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', $this->publishData);
211 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher_count', $this->recordCount);
212 $content .= $this->formatProgressBlock($this->isSwap ? 'swap_prepare' : 'publish_prepare');
213 $this->doc->bodyTagAdditions = 'onload="nextPortion(1)"';
214 }
215 else {
216 $this->doc->bodyTagAdditions = 'onload="closeAndReload()"';
217 }
218 }
219 return $content;
220 }
221
222 /**
223 * Fetches command array for publishing and calculates number of records in it. Sets class members accordingly.
224 *
225 * @return void
226 */
227 function getRecords() {
228 $wslibObj = t3lib_div::makeInstance('wslib');
229 $this->publishData = $wslibObj->getCmdArrayForPublishWS($GLOBALS['BE_USER']->workspace, $this->isSwap);
230
231 $this->recordCount = 0;
232 foreach ($this->publishData as $table => $recs) {
233 $this->recordCount += count($recs);
234 }
235 }
236
237 /**
238 * Creates block with progress bar
239 *
240 * @param string $messageLabel Message label to display
241 * @return string Generated content
242 */
243 function formatProgressBlock($messageLabel) {
244 return '<div id="progress-block"><h3>' . $this->title . '</h3><p>' .
245 sprintf($GLOBALS['LANG']->getLL($messageLabel),
246 $this->nextRecordNumber,
247 min($this->recordCount, $this->nextRecordNumber - 1 + MAX_RECORDS_TO_PUBLISH),
248 $this->recordCount) . '<br />' .
249 $GLOBALS['LANG']->getLL('please_wait') .
250 '</p><img src="progress.gif" width="225" height="20" alt="" />' .
251 '<p>' .
252 $GLOBALS['LANG']->getLL('do_not_interrupt_publishing_1') .
253 '<br />' .
254 $GLOBALS['LANG']->getLL('do_not_interrupt_publishing_2') .
255 '</p></div>';
256 }
257 }
258
259
260 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/publish.php']) {
261 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/publish.php']);
262 }
263
264 // Make instance:
265 $SOBE = t3lib_div::makeInstance('SC_mod_user_ws_publish');
266 $SOBE->init();
267 $SOBE->main();
268 $SOBE->printContent();
269
270 ?>