TYPO3 API  SVNRelease
publish.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * Module: Workspace publisher
00029  *
00030  * $Id: publish.php 10222 2011-01-21 18:22:24Z tolleiv $
00031  *
00032  * @author  Dmitry Dulepov <typo3@accio.lv>
00033  */
00034 /**
00035  * [CLASS/FUNCTION INDEX of SCRIPT]
00036  *
00037  *
00038  *
00039  *   70: class SC_mod_user_ws_publish extends t3lib_SCbase
00040  *   83:     function init()
00041  *   95:     function closeAndReload()
00042  *  106:     function nextPortion(val)
00043  *  127:     function main()
00044  *  142:     function printContent()
00045  *  151:     function getContent()
00046  *  227:     function getRecords()
00047  *  243:     function formatProgressBlock($messageLabel)
00048  *
00049  * TOTAL FUNCTIONS: 8
00050  * (This index is automatically created/updated by the extension "extdeveval")
00051  *
00052  */
00053 
00054 
00055 // Initialize module:
00056 unset($MCONF);
00057 require('conf.php');
00058 require($BACK_PATH . 'init.php');
00059 require($BACK_PATH . 'template.php');
00060 $BE_USER->modAccess($MCONF, 1);
00061 
00062 // Include libraries of various kinds used inside:
00063 $LANG->includeLLFile('EXT:lang/locallang_mod_user_ws.xml');
00064 require_once('class.wslib.php');
00065 
00066 define('MAX_RECORDS_TO_PUBLISH', 30);
00067 
00068 class SC_mod_user_ws_publish extends t3lib_SCbase {
00069 
00070     var $isSwap;
00071     var $title;
00072     var $nextRecordNumber;
00073     var $publishData;
00074     var $recordCount;
00075 
00076     /**
00077      * Document Template Object
00078      *
00079      * @var mediumDoc
00080      */
00081     var $doc;
00082 
00083     /**
00084      * Initializes the module. See <code>t3lib_SCbase::init()</code> for more information.
00085      *
00086      * @return  void
00087      */
00088     function init() {
00089         // Setting module configuration:
00090         $this->MCONF = $GLOBALS['MCONF'];
00091 
00092         $this->isSwap = t3lib_div::_GP('swap');
00093         $this->nextRecordNumber = t3lib_div::_GP('continue_publish');
00094 
00095         // Initialize Document Template object:
00096         $this->doc = t3lib_div::makeInstance('mediumDoc');
00097         $this->doc->backPath = $GLOBALS['BACK_PATH'];
00098         $this->doc->JScode = '<script type="text/javascript">/*<![CDATA[*/
00099             function closeAndReload() {
00100                 //window.opener.location.reload(); window.close();
00101                 window.location.href = \'index.php\';
00102             }
00103 
00104             function nextPortion(val) {
00105                 setTimeout(\'window.location.href = "publish.php?continue_publish=\' + val + \'&swap=' . ($this->isSwap ? 1 : 0) . '"\', 750);
00106             }
00107         /*]]>*/</script>
00108         ';
00109         $this->doc->inDocStyles = '
00110         #progress-block { width: 450px; margin: 50px auto; text-align: center; }
00111         H3 { margin-bottom: 20px; }
00112         P, IMG { margin-bottom: 20px; }
00113         #progress-block A { text-decoration: underline; }
00114 ';
00115 
00116         // Parent initialization:
00117         t3lib_SCbase::init();
00118     }
00119 
00120     /**
00121      * Creates module content.
00122      *
00123      * @return  void
00124      */
00125     function main() {
00126         $this->title = $GLOBALS['LANG']->getLL($this->isSwap ? 'swap_title' : 'publish_title');
00127 
00128         $content = $this->getContent(); // sets body parts to doc!
00129 
00130         $this->content .= $this->doc->startPage($this->title);
00131         $this->content .= $content;
00132         $this->content .= $this->doc->endPage();
00133     }
00134 
00135     /**
00136      * Outputs content.
00137      *
00138      * @return  void
00139      */
00140     function printContent() {
00141         echo $this->content;
00142     }
00143 
00144     /**
00145      * Performs action and generates content.
00146      *
00147      * @return  string      Generated content
00148      */
00149     function getContent() {
00150         $content = '';
00151         if ($this->nextRecordNumber) {
00152             // Prepare limited set of records
00153             $this->publishData = $GLOBALS['BE_USER']->getSessionData('workspacePublisher');
00154             $this->recordCount = $GLOBALS['BE_USER']->getSessionData('workspacePublisher_count');
00155             $limitedCmd = array(); $numRecs = 0;
00156             foreach ($this->publishData as $table => $recs) {
00157                 foreach ($recs as $key => $value) {
00158                     $numRecs++;
00159                     $limitedCmd[$table][$key] = $value;
00160                     //$this->content .= $table.':'.$key.'<br />';
00161                     if ($numRecs == MAX_RECORDS_TO_PUBLISH) {
00162                         break;
00163                     }
00164                 }
00165                 if ($numRecs == MAX_RECORDS_TO_PUBLISH) {
00166                     break;
00167                 }
00168             }
00169 
00170             if ($numRecs == 0) {
00171                 // All done
00172                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', null);
00173                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher_count', 0);
00174                 $content .= '<div id="progress-block"><h3>' . $this->title . '</h3><p>';
00175                 $content .= $GLOBALS['LANG']->getLL($this->isSwap ? 'workspace_swapped' : 'workspace_published');
00176                 $content .= '</p><p><a href="index.php">' . $GLOBALS['LANG']->getLL('return_to_index') . '</a>';
00177                 $content .= '</p></div>';
00178             }
00179             else {
00180                 // Execute the commands:
00181                 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00182                 $tce->stripslashes_values = 0;
00183                 $tce->start(array(), $limitedCmd);
00184                 $tce->process_cmdmap();
00185 
00186                 $errors = $tce->errorLog;
00187                 if (count($errors) > 0) {
00188                     $content .= '<h3>' . $GLOBALS['LANG']->getLL('label_errors') . '</h3><br />' . implode('<br />', $errors);
00189                     $content .= '<br /><br /><a href="index.php">' . $GLOBALS['LANG']->getLL('return_to_index') . '</a>';
00190                 }
00191                 else {
00192 
00193                     // Unset processed records
00194                     foreach ($limitedCmd as $table => $recs) {
00195                         foreach ($recs as $key => $value) {
00196                             unset($this->publishData[$table][$key]);
00197                         }
00198                     }
00199                     $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', $this->publishData);
00200                     $content .= $this->formatProgressBlock($this->isSwap ? 'swap_status' : 'publish_status');
00201                     $this->doc->bodyTagAdditions = 'onload="nextPortion(' . ($this->nextRecordNumber + MAX_RECORDS_TO_PUBLISH) . ')"';
00202                 }
00203             }
00204         }
00205         else {
00206             $this->getRecords();
00207             if ($this->recordCount > 0) {
00208                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', $this->publishData);
00209                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher_count', $this->recordCount);
00210                 $content .= $this->formatProgressBlock($this->isSwap ? 'swap_prepare' : 'publish_prepare');
00211                 $this->doc->bodyTagAdditions = 'onload="nextPortion(1)"';
00212             }
00213             else {
00214                 $this->doc->bodyTagAdditions = 'onload="closeAndReload()"';
00215             }
00216         }
00217         return $content;
00218     }
00219 
00220     /**
00221      * Fetches command array for publishing and calculates number of records in it. Sets class members accordingly.
00222      *
00223      * @return  void
00224      */
00225     function getRecords() {
00226         $wslibObj = t3lib_div::makeInstance('wslib');
00227         $this->publishData = $wslibObj->getCmdArrayForPublishWS($GLOBALS['BE_USER']->workspace, $this->isSwap);
00228 
00229         $this->recordCount = 0;
00230         foreach ($this->publishData as $table => $recs) {
00231             $this->recordCount += count($recs);
00232         }
00233     }
00234 
00235     /**
00236      * Creates block with progress bar
00237      *
00238      * @param   string      $messageLabel Message label to display
00239      * @return  string      Generated content
00240      */
00241     function formatProgressBlock($messageLabel) {
00242         return '<div id="progress-block"><h3>' . $this->title . '</h3><p>' .
00243                 sprintf($GLOBALS['LANG']->getLL($messageLabel),
00244                 $this->nextRecordNumber,
00245                 min($this->recordCount, $this->nextRecordNumber - 1 + MAX_RECORDS_TO_PUBLISH),
00246                 $this->recordCount) . '<br />' .
00247                 $GLOBALS['LANG']->getLL('please_wait') .
00248                 '</p><img src="progress.gif" width="225" height="20" alt="" />' .
00249                 '<p>' .
00250                 $GLOBALS['LANG']->getLL('do_not_interrupt_publishing_1') .
00251                 '<br />' .
00252                 $GLOBALS['LANG']->getLL('do_not_interrupt_publishing_2') .
00253                 '</p></div>';
00254     }
00255 }
00256 
00257 
00258 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/publish.php'])) {
00259     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/publish.php']);
00260 }
00261 
00262 // Make instance:
00263 $SOBE = t3lib_div::makeInstance('SC_mod_user_ws_publish');
00264 $SOBE->init();
00265 $SOBE->main();
00266 $SOBE->printContent();
00267 
00268 ?>