Documentation TYPO3 par Ameos

publish.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 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 ***************************************************************/
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 
00083         function init() {
00084                 // Setting module configuration:
00085                 $this->MCONF = $GLOBALS['MCONF'];
00086 
00087                 $this->isSwap = t3lib_div::_GP('swap');
00088                 $this->nextRecordNumber = t3lib_div::_GP('continue_publish');
00089 
00090                 // Initialize Document Template object:
00091                 $this->doc = t3lib_div::makeInstance('mediumDoc');
00092                 $this->doc->backPath = $GLOBALS['BACK_PATH'];
00093                 $this->doc->docType = 'xhtml_trans';
00094                 $this->doc->JScode = '<script type="text/javascript">/*<![CDATA[*/
00095                         function closeAndReload() {
00096                                 //window.opener.location.reload(); window.close();
00097                                 window.location.href = \'index.php\';
00098                         }
00099 
00100                         function nextPortion(val) {
00101                                 setTimeout(\'window.location.href = "publish.php?continue_publish=\' + val + \'&swap=' . ($this->isSwap ? 1 : 0) . '"\', 750);
00102                         }
00103                 /*]]>*/</script>
00104                 ';
00105                 $this->doc->inDocStyles = '
00106                 #progress-block { width: 450px; margin: 50px auto; text-align: center; }
00107                 H3 { margin-bottom: 20px; }
00108                 P, IMG { margin-bottom: 20px; }
00109                 #progress-block A { text-decoration: underline; }
00110 ';
00111 
00112                 // Parent initialization:
00113                 t3lib_SCbase::init();
00114         }
00115 
00121         function main() {
00122                 $this->title = $GLOBALS['LANG']->getLL($this->isSwap ? 'swap_title' : 'publish_title');
00123 
00124                 $content = $this->getContent(); // sets body parts to doc!
00125 
00126                 $this->content .= $this->doc->startPage($this->title);
00127                 $this->content .= $content;
00128                 $this->content .= $this->doc->endPage();
00129         }
00130 
00136         function printContent() {
00137                 echo $this->content;
00138         }
00139 
00145         function getContent() {
00146                 $content = '';
00147                 if ($this->nextRecordNumber) {
00148                         // Prepare limited set of records
00149                         $this->publishData = $GLOBALS['BE_USER']->getSessionData('workspacePublisher');
00150                         $this->recordCount = $GLOBALS['BE_USER']->getSessionData('workspacePublisher_count');
00151                         $limitedCmd = array(); $numRecs = 0;
00152                         foreach ($this->publishData as $table => $recs) {
00153                                 foreach ($recs as $key => $value) {
00154                                         $numRecs++;
00155                                         $limitedCmd[$table][$key] = $value;
00156                                         //$this->content .= $table.':'.$key.'<br />';
00157                                         if ($numRecs == MAX_RECORDS_TO_PUBLISH) {
00158                                                 break;
00159                                         }
00160                                 }
00161                                 if ($numRecs == MAX_RECORDS_TO_PUBLISH) {
00162                                         break;
00163                                 }
00164                         }
00165 
00166                         if ($numRecs == 0) {
00167                                 // All done
00168                                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', null);
00169                                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher_count', 0);
00170                                 $content .= '<div id="progress-block"><h3>' . $this->title . '</h3><p>';
00171                                 $content .= $GLOBALS['LANG']->getLL($this->isSwap ? 'workspace_swapped' : 'workspace_published');
00172                                 $content .= '</p><p><a href="index.php">' . $GLOBALS['LANG']->getLL('return_to_index') . '</a>';
00173                                 $content .= '</p></div>';
00174                         }
00175                         else {
00176                                 // Execute the commands:
00177                                 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00178                                 $tce->stripslashes_values = 0;
00179                                 $tce->start(array(), $limitedCmd);
00180                                 $tce->process_cmdmap();
00181 
00182                                 $errors = $tce->errorLog;
00183                                 if (count($errors) > 0) {
00184                                         $content .= '<h3>' . $LANG->getLL('label_errors') . '</h3><br/>' . implode('<br/>',$errors);
00185                                         $content .= '<br /><br /><a href="index.php">' . $GLOBALS['LANG']->getLL('return_to_index') . '</a>';
00186                                 }
00187                                 else {
00188 
00189                                         // Unset processed records
00190                                         foreach ($limitedCmd as $table => $recs) {
00191                                                 foreach ($recs as $key => $value) {
00192                                                         unset($this->publishData[$table][$key]);
00193                                                 }
00194                                         }
00195                                         $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', $this->publishData);
00196                                         $content .= $this->formatProgressBlock($this->isSwap ? 'swap_status' : 'publish_status');
00197                                         $this->doc->bodyTagAdditions = 'onload="nextPortion(' . ($this->nextRecordNumber + MAX_RECORDS_TO_PUBLISH) . ')"';
00198                                 }
00199                         }
00200                 }
00201                 else {
00202                         $this->getRecords();
00203                         if ($this->recordCount > 0) {
00204                                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher', $this->publishData);
00205                                 $GLOBALS['BE_USER']->setAndSaveSessionData('workspacePublisher_count', $this->recordCount);
00206                                 $content .= $this->formatProgressBlock($this->isSwap ? 'swap_prepare' : 'publish_prepare');
00207                                 $this->doc->bodyTagAdditions = 'onload="nextPortion(1)"';
00208                         }
00209                         else {
00210                                 $this->doc->bodyTagAdditions = 'onload="closeAndReload()"';
00211                         }
00212                 }
00213                 return $content;
00214         }
00215 
00221         function getRecords() {
00222                 $wslibObj = t3lib_div::makeInstance('wslib');
00223                 $this->publishData = $wslibObj->getCmdArrayForPublishWS($GLOBALS['BE_USER']->workspace, $this->isSwap);
00224 
00225                 $this->recordCount = 0;
00226                 foreach ($this->publishData as $table => $recs) {
00227                         $this->recordCount += count($recs);
00228                 }
00229         }
00230 
00237         function formatProgressBlock($messageLabel) {
00238                 return '<div id="progress-block"><h3>' . $this->title . '</h3><p>' .
00239                                 sprintf($GLOBALS['LANG']->getLL($messageLabel),
00240                                 $this->nextRecordNumber,
00241                                 min($this->recordCount, $this->nextRecordNumber - 1 + MAX_RECORDS_TO_PUBLISH),
00242                                 $this->recordCount) . '<br />' .
00243                                 $GLOBALS['LANG']->getLL('please_wait') .
00244                                 '</p><img src="progress.gif" width="225" height="20" alt="" />' .
00245                                 '<p>' .
00246                                 $GLOBALS['LANG']->getLL('do_not_interrupt_publishing_1') .
00247                                 '<br />' .
00248                                 $GLOBALS['LANG']->getLL('do_not_interrupt_publishing_2') .
00249                                 '</p></div>';
00250         }
00251 }
00252 
00253 
00254 // Include extension?
00255 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/publish.php'])   {
00256         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/publish.php']);
00257 }
00258 
00259 // Make instance:
00260 $SOBE = t3lib_div::makeInstance('SC_mod_user_ws_publish');
00261 $SOBE->init();
00262 $SOBE->main();
00263 $SOBE->printContent();
00264 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6