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