publish.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2008 Kasper Skaarhoj (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 4433 2008-11-07 04:13:12Z flyguide $
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(PATH_t3lib . 'class.t3lib_scbase.php');
00065 require_once(PATH_typo3 . 'mod/user/ws/class.wslib.php');
00066 require_once(PATH_t3lib . 'class.t3lib_tcemain.php');
00067 
00068 define('MAX_RECORDS_TO_PUBLISH', 30);
00069 
00070 class SC_mod_user_ws_publish extends t3lib_SCbase {
00071 
00072     var $isSwap;
00073     var $title;
00074     var $nextRecordNumber;
00075     var $publishData;
00076     var $recordCount;
00077 
00078     /**
00079      * Document Template Object
00080      *
00081      * @var mediumDoc
00082      */
00083     var $doc;
00084 
00085     /**
00086      * Initializes the module. See <code>t3lib_SCbase::init()</code> for more information.
00087      *
00088      * @return  void
00089      */
00090     function init() {
00091         // Setting module configuration:
00092         $this->MCONF = $GLOBALS['MCONF'];
00093 
00094         $this->isSwap = t3lib_div::_GP('swap');
00095         $this->nextRecordNumber = t3lib_div::_GP('continue_publish');
00096 
00097         // Initialize Document Template object:
00098         $this->doc = t3lib_div::makeInstance('mediumDoc');
00099         $this->doc->backPath = $GLOBALS['BACK_PATH'];
00100         $this->doc->JScode = '<script type="text/javascript">/*<![CDATA[*/
00101             function closeAndReload() {
00102                 //window.opener.location.reload(); window.close();
00103                 window.location.href = \'index.php\';
00104             }
00105 
00106             function nextPortion(val) {
00107                 setTimeout(\'window.location.href = "publish.php?continue_publish=\' + val + \'&swap=' . ($this->isSwap ? 1 : 0) . '"\', 750);
00108             }
00109         /*]]>*/</script>
00110         ';
00111         $this->doc->inDocStyles = '
00112         #progress-block { width: 450px; margin: 50px auto; text-align: center; }
00113         H3 { margin-bottom: 20px; }
00114         P, IMG { margin-bottom: 20px; }
00115         #progress-block A { text-decoration: underline; }
00116 ';
00117 
00118         // Parent initialization:
00119         t3lib_SCbase::init();
00120     }
00121 
00122     /**
00123      * Creates module content.
00124      *
00125      * @return  void
00126      */
00127     function main() {
00128         $this->title = $GLOBALS['LANG']->getLL($this->isSwap ? 'swap_title' : 'publish_title');
00129 
00130         $content = $this->getContent(); // sets body parts to doc!
00131 
00132         $this->content .= $this->doc->startPage($this->title);
00133         $this->content .= $content;
00134         $this->content .= $this->doc->endPage();
00135     }
00136 
00137     /**
00138      * Outputs content.
00139      *
00140      * @return  void
00141      */
00142     function printContent() {
00143         echo $this->content;
00144     }
00145 
00146     /**
00147      * Performs action and generates content.
00148      *
00149      * @return  string      Generated content
00150      */
00151     function getContent() {
00152         $content = '';
00153         if ($this->nextRecordNumber) {
00154             // Prepare limited set of records
00155             $this->publishData = $GLOBALS['BE_USER']->getSessionData('workspacePublisher');
00156             $this->recordCount = $GLOBALS['BE_USER']->getSessionData('workspacePublisher_count');
00157             $limitedCmd = array(); $numRecs = 0;
00158             foreach ($this->publishData as $table => $recs) {
00159                 foreach ($recs as $key => $value) {
00160                     $numRecs++;
00161                     $limitedCmd[$table][$key] = $value;
00162                     //$this->content .= $table.':'.$key.'<br />';
00163                     if ($numRecs == MAX_RECORDS_TO_PUBLISH) {
00164                         break;
00165                     }
00166                 }
00167                 if ($numRecs == MAX_RECORDS_TO_PUBLISH) {
00168                     break;
00169                 }
00170             }
00171 
00172             if ($numRecs == 0) {
00173                 // All done
00174                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', null);
00175                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher_count', 0);
00176                 $content .= '<div id="progress-block"><h3>' . $this->title . '</h3><p>';
00177                 $content .= $GLOBALS['LANG']->getLL($this->isSwap ? 'workspace_swapped' : 'workspace_published');
00178                 $content .= '</p><p><a href="index.php">' . $GLOBALS['LANG']->getLL('return_to_index') . '</a>';
00179                 $content .= '</p></div>';
00180             }
00181             else {
00182                 // Execute the commands:
00183                 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00184                 $tce->stripslashes_values = 0;
00185                 $tce->start(array(), $limitedCmd);
00186                 $tce->process_cmdmap();
00187 
00188                 $errors = $tce->errorLog;
00189                 if (count($errors) > 0) {
00190                     $content .= '<h3>' . $GLOBALS['LANG']->getLL('label_errors') . '</h3><br/>' . implode('<br/>',$errors);
00191                     $content .= '<br /><br /><a href="index.php">' . $GLOBALS['LANG']->getLL('return_to_index') . '</a>';
00192                 }
00193                 else {
00194 
00195                     // Unset processed records
00196                     foreach ($limitedCmd as $table => $recs) {
00197                         foreach ($recs as $key => $value) {
00198                             unset($this->publishData[$table][$key]);
00199                         }
00200                     }
00201                     $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', $this->publishData);
00202                     $content .= $this->formatProgressBlock($this->isSwap ? 'swap_status' : 'publish_status');
00203                     $this->doc->bodyTagAdditions = 'onload="nextPortion(' . ($this->nextRecordNumber + MAX_RECORDS_TO_PUBLISH) . ')"';
00204                 }
00205             }
00206         }
00207         else {
00208             $this->getRecords();
00209             if ($this->recordCount > 0) {
00210                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', $this->publishData);
00211                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher_count', $this->recordCount);
00212                 $content .= $this->formatProgressBlock($this->isSwap ? 'swap_prepare' : 'publish_prepare');
00213                 $this->doc->bodyTagAdditions = 'onload="nextPortion(1)"';
00214             }
00215             else {
00216                 $this->doc->bodyTagAdditions = 'onload="closeAndReload()"';
00217             }
00218         }
00219         return $content;
00220     }
00221 
00222     /**
00223      * Fetches command array for publishing and calculates number of records in it. Sets class members accordingly.
00224      *
00225      * @return  void
00226      */
00227     function getRecords() {
00228         $wslibObj = t3lib_div::makeInstance('wslib');
00229         $this->publishData = $wslibObj->getCmdArrayForPublishWS($GLOBALS['BE_USER']->workspace, $this->isSwap);
00230 
00231         $this->recordCount = 0;
00232         foreach ($this->publishData as $table => $recs) {
00233             $this->recordCount += count($recs);
00234         }
00235     }
00236 
00237     /**
00238      * Creates block with progress bar
00239      *
00240      * @param   string      $messageLabel Message label to display
00241      * @return  string      Generated content
00242      */
00243     function formatProgressBlock($messageLabel) {
00244         return '<div id="progress-block"><h3>' . $this->title . '</h3><p>' .
00245                 sprintf($GLOBALS['LANG']->getLL($messageLabel),
00246                 $this->nextRecordNumber,
00247                 min($this->recordCount, $this->nextRecordNumber - 1 + MAX_RECORDS_TO_PUBLISH),
00248                 $this->recordCount) . '<br />' .
00249                 $GLOBALS['LANG']->getLL('please_wait') .
00250                 '</p><img src="progress.gif" width="225" height="20" alt="" />' .
00251                 '<p>' .
00252                 $GLOBALS['LANG']->getLL('do_not_interrupt_publishing_1') .
00253                 '<br />' .
00254                 $GLOBALS['LANG']->getLL('do_not_interrupt_publishing_2') .
00255                 '</p></div>';
00256     }
00257 }
00258 
00259 
00260 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/publish.php'])   {
00261     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/publish.php']);
00262 }
00263 
00264 // Make instance:
00265 $SOBE = t3lib_div::makeInstance('SC_mod_user_ws_publish');
00266 $SOBE->init();
00267 $SOBE->main();
00268 $SOBE->printContent();
00269 
00270 ?>

Generated on Sat Jan 3 04:23:29 2009 for TYPO3 API by  doxygen 1.4.7