TYPO3 API  SVNRelease
class.tx_wizardcrpages_webfunc_2.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  * Contains class for "Create pages" wizard
00029  *
00030  * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
00031  * XHTML compliant
00032  *
00033  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00034  */
00035 /**
00036  * [CLASS/FUNCTION INDEX of SCRIPT]
00037  *
00038  *
00039  *
00040  *   70: class tx_wizardcrpages_webfunc_2 extends t3lib_extobjbase
00041  *   78:     function modMenu()
00042  *   95:     function main()
00043  *  179:     function helpBubble()
00044  *
00045  * TOTAL FUNCTIONS: 3
00046  * (This index is automatically created/updated by the extension "extdeveval")
00047  *
00048  */
00049 
00050 /**
00051  * Creates the "Create pages" wizard
00052  *
00053  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00054  * @package TYPO3
00055  * @subpackage tx_wizardcrpages
00056  */
00057 class tx_wizardcrpages_webfunc_2 extends t3lib_extobjbase {
00058 
00059     /**
00060      * Holds reference of lorem ipsum class
00061      *
00062      * @var tx_loremipsum_wiz
00063      */
00064     protected $loremIpsumObject = NULL;
00065 
00066     /**
00067     * Complete tsConfig
00068     *
00069     * @var array
00070     */
00071     protected $tsConfig = array();
00072 
00073     /**
00074     * Part of tsConfig with TCEFORM.pages. settings
00075     *
00076     * @var array
00077     */
00078     protected $pagesTsConfig = array();
00079 
00080 
00081     /**
00082      * Adds menu items... but I think this is not used at all. Looks very much like some testing code. If anyone cares to check it we can remove it some day...
00083      *
00084      * @return  array
00085      * @ignore
00086      */
00087     function modMenu()  {
00088         global $LANG;
00089 
00090         $modMenuAdd = array(
00091             'cr_333' => array(
00092                 '0' => 'nul',
00093                 '1' => 'et'
00094             )
00095         );
00096         return $modMenuAdd;
00097     }
00098 
00099     /**
00100      * Main function creating the content for the module.
00101      *
00102      * @return  string      HTML content for the module, actually a "section" made through the parent object in $this->pObj
00103      */
00104     function main() {
00105         global $SOBE,$LANG;
00106 
00107         $theCode='';
00108 
00109         $this->tsConfig = t3lib_BEfunc::getPagesTSconfig($this->pObj->id);
00110         $this->pagesTsConfig = isset($this->tsConfig['TCEFORM.']['pages.']) ? $this->tsConfig['TCEFORM.']['pages.'] : array();
00111 
00112 
00113             // Create loremIpsum code:
00114         if (t3lib_extMgm::isLoaded('lorem_ipsum')) {
00115             $this->loremIpsumObject = t3lib_div::getUserObj('EXT:lorem_ipsum/class.tx_loremipsum_wiz.php:tx_loremipsum_wiz');
00116         }
00117 
00118         $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(8);   // create new pages here?
00119         $pRec = t3lib_BEfunc::getRecord('pages',$this->pObj->id,'uid',' AND '.$m_perms_clause);
00120         $sys_pages = t3lib_div::makeInstance('t3lib_pageSelect');
00121         $menuItems = $sys_pages->getMenu($this->pObj->id,'*','sorting','',0);
00122         if (is_array($pRec)) {
00123             $data = t3lib_div::_GP('data');
00124             if (is_array($data['pages'])) {
00125                 if (t3lib_div::_GP('createInListEnd')) {
00126                     $endI = end($menuItems);
00127                     $thePid = -intval($endI['uid']);
00128                     if (!$thePid)   $thePid = $this->pObj->id;
00129                 } else {
00130                     $thePid = $this->pObj->id;
00131                 }
00132 
00133                 $firstRecord = true;
00134                 $previousIdentifier = '';
00135 
00136                 foreach ($data['pages'] as $identifier => $dat) {
00137                     if (!trim($dat['title'])) {
00138                         unset($data['pages'][$identifier]);
00139                     } else {
00140                         $data['pages'][$identifier]['hidden'] = t3lib_div::_GP('hidePages') ? 1 : 0;
00141                         if ($firstRecord) {
00142                             $firstRecord = false;
00143                             $data['pages'][$identifier]['pid'] = $thePid;
00144                         } else {
00145                             $data['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
00146                         }
00147                         $previousIdentifier = $identifier;
00148                     }
00149                 }
00150 
00151                 if (count($data['pages']))  {
00152                     reset($data);
00153                     $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00154                     $tce->stripslashes_values=0;
00155 
00156                         // set default TCA values specific for the user
00157                     $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
00158                     if (is_array($TCAdefaultOverride))  {
00159                         $tce->setDefaultsFromUserTS($TCAdefaultOverride);
00160                     }
00161 
00162                     $tce->start($data,array());
00163                     $tce->process_datamap();
00164                     t3lib_BEfunc::setUpdateSignal('updatePageTree');
00165 
00166                     $flashMessage = t3lib_div::makeInstance(
00167                         't3lib_FlashMessage',
00168                         '',
00169                         $GLOBALS['LANG']->getLL('wiz_newPages_create')
00170                     );
00171                 } else {
00172                     $flashMessage = t3lib_div::makeInstance(
00173                         't3lib_FlashMessage',
00174                         '',
00175                         $GLOBALS['LANG']->getLL('wiz_newPages_noCreate'),
00176                         t3lib_FlashMessage::ERROR
00177                     );
00178                 }
00179 
00180                 $theCode.= $flashMessage->render();
00181 
00182                     // Display result:
00183                 $menuItems = $sys_pages->getMenu($this->pObj->id,'*','sorting','',0);
00184                 $lines=array();
00185                 foreach ($menuItems as $rec) {
00186                     t3lib_BEfunc::workspaceOL('pages',$rec);
00187                     if (is_array($rec)) {
00188                         $lines[] = '<nobr>' . t3lib_iconWorks::getSpriteIconForRecord('pages', $rec, array('title' => t3lib_BEfunc::titleAttribForPages($rec , '', FALSE))) .
00189                             htmlspecialchars(t3lib_div::fixed_lgd_cs($rec['title'],$GLOBALS['BE_USER']->uc['titleLen'])).'</nobr>';
00190                     }
00191                 }
00192                 $theCode.= '<h4>' . $LANG->getLL('wiz_newPages_currentMenu') . '</h4>' . implode('<br />', $lines);
00193             } else {
00194 
00195                     // Display create form
00196                 $lines = array();
00197                 for ($a = 0; $a < 9; $a++) {
00198                     $lines[] = $this->getFormLine($a);
00199                 }
00200 
00201                 $theCode .= '<h4>' . $LANG->getLL('wiz_newPages') . ':</h4>' .
00202                 '<div id="formFieldContainer">' . implode('', $lines) . '</div>' .
00203                 '<br class="clearLeft" />' .
00204                 '<input type="button" id="createNewFormFields" value="' . $LANG->getLL('wiz_newPages_addMoreLines') . '" />' .
00205 
00206                 '<br /><br />
00207                 <input type="checkbox" name="createInListEnd" id="createInListEnd" value="1" /> <label for="createInListEnd">'.$LANG->getLL('wiz_newPages_listEnd').'</label><br />
00208                 <input type="checkbox" name="hidePages" id="hidePages" value="1" /> <label for="hidePages">'.$LANG->getLL('wiz_newPages_hidePages').'</label><br /><br />
00209                 <input type="submit" name="create" value="' . $LANG->getLL('wiz_newPages_lCreate') . '" onclick="return confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->getLL('wiz_newPages_lCreate_msg1')) . ')" />&nbsp;<input type="reset" value="' . $LANG->getLL('wiz_newPages_lReset') . '" /><br />';
00210 
00211                 // Add ExtJS inline code
00212                 $extCode = '
00213                     var tpl = "' . addslashes(str_replace(
00214                         array(LF, TAB),
00215                         array('', ''),
00216                         $this->getFormLine('#')
00217                     )) . '", i, line, div, bg, label;
00218                     var lineCounter = 9;
00219                     Ext.get("createNewFormFields").on("click", function() {
00220                         div = Ext.get("formFieldContainer");
00221                         for (i = 0; i < 5; i++) {
00222                             label = lineCounter + i + 1;
00223                             bg = label % 2 === 0 ? 6 : 4;
00224                             line = String.format(tpl, (lineCounter + i), label, bg);
00225                             div.insertHtml("beforeEnd", line);
00226                         }
00227                         lineCounter += 5;
00228                     });
00229                 ';
00230 
00231                 /** @var t3lib_pageRenderer **/
00232                 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
00233 
00234                 $pageRenderer->loadExtJS();
00235                 $pageRenderer->addExtOnReadyCode($extCode);
00236                 $pageRenderer->addCssInlineBlock('tx_wizardcrpages_webfunc_2', '
00237                 #formFieldContainer {float: left; margin: 0 0 10px 0;}
00238                 .clearLeft {clear: left;}
00239                 #formFieldContainer label {width: 70px; display: inline-block;}
00240                 #formFieldContainer input {margin:4px 2px; padding:1px; vertical-align:middle}
00241                 #formFieldContainer span {padding: 0 3px;}
00242                 ');
00243             }
00244         } else {
00245             $theCode.=$GLOBALS['TBE_TEMPLATE']->rfw($LANG->getLL('wiz_newPages_errorMsg1'));
00246         }
00247 
00248             // CSH
00249         $theCode.= t3lib_BEfunc::cshItem('_MOD_web_func', 'tx_wizardcrpages', $GLOBALS['BACK_PATH'], '<br />|');
00250 
00251         $out=$this->pObj->doc->section($LANG->getLL('wiz_crMany'),$theCode,0,1);
00252         return $out;
00253     }
00254 
00255     /**
00256      * Return the helpbubble image tag.
00257      *
00258      * @return  string      HTML code for a help-bubble image.
00259      */
00260     function helpBubble()   {
00261         return '<img src="'.$GLOBALS['BACK_PATH'].'gfx/helpbubble.gif" width="14" height="14" hspace="2" align="top" alt="" />';
00262     }
00263 
00264     /**
00265      * Return one line in the form
00266      *
00267      * @param   mixed   $index An integer: the line counter for which to create the line. Use "#" to create an template for javascript (used by ExtJS)
00268      * @return  string  HTML code for one input line for one new page
00269      */
00270     protected function getFormLine($index) {
00271         $backPath = $GLOBALS['BACK_PATH'];
00272 
00273         if (is_numeric(($index))) {
00274             $backgroundClass = ($index % 2 === 0 ? 'bgColor4' : 'bgColor6');
00275             $label = $index + 1;
00276         } else {
00277                 // used as template for ExtJS
00278             $index = '{0}';
00279             $backgroundClass = 'bgColor{2}';
00280             $label = '{1}';
00281         }
00282 
00283         $content = '<label for="page_new_' . $index . '"> ' . $GLOBALS['LANG']->getLL('wiz_newPages_page') .' '. $label;
00284         $content .= ':&nbsp;</label>';
00285 
00286             // title
00287         $content .= '<input type="text" id="page_new_' . $index . '" name="data[pages][NEW' . $index . '][title]"' . $this->pObj->doc->formWidth(35) . ' />&nbsp';
00288 
00289             // lorem ipsum link, if available
00290         $content .= (is_object($this->loremIpsumObject) ?
00291             '<a href="#" onclick="' . htmlspecialchars($this->loremIpsumObject->getHeaderTitleJS('document.forms[0][\'data[pages][NEW' .
00292             $index . '][title]\'].value', 'title')) . '">' . $this->loremIpsumObject->getIcon('', $this->pObj->doc->backPath) . '</a>'
00293             : '');
00294 
00295             // type selector
00296         $content .= '<span>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.php:LGL.type') . '</span>';
00297         $content .= '<select onchange="this.style.backgroundImage=this.options[this.selectedIndex].style.backgroundImage;if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=1;}" ';
00298         $content .= 'class="select icon-select" name="data[pages][NEW' . $index . '][doktype]" style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); padding: 1px 1px 1px 24px;">';
00299 
00300             // dokType
00301         $types = $GLOBALS['PAGES_TYPES'];
00302         unset($types['default']);
00303         $types = array_keys($types);
00304         $types[] = 1;
00305         if (!$GLOBALS['BE_USER']->isAdmin() && isset($GLOBALS['BE_USER']->groupData['pagetypes_select'])) {
00306             $types = t3lib_div::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select'], TRUE);
00307         }
00308 
00309         $removeItems = isset($this->pagesTsConfig['doktype.']['removeItems']) ? t3lib_div::trimExplode(',', $this->pagesTsConfig['doktype.']['removeItems'], TRUE) : array();
00310 
00311         $group = '';
00312         if (in_array(1, $types) && !in_array(1, $removeItems)) {
00313             $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" selected="selected" value="1">Standard</option>';
00314         }
00315         if (in_array(6, $types) && !in_array(6, $removeItems)) {
00316             $group .= '<option style="background: url(&quot;' . $backPath . 'gfx/i/be_users_section.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="6">Backend User Section</option>';
00317         }
00318         $content .= $group ? '<optgroup class="c-divider" label="Page">' . $group . '</optgroup>' : '';
00319 
00320         $group = '';
00321         if (in_array(4, $types) && !in_array(4, $removeItems)) {
00322             $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages_shortcut.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="4">Shortcut</option>';
00323         }
00324         if (in_array(7, $types) && !in_array(7, $removeItems)) {
00325             $group .= '<option style="background: url(&quot;' . $backPath . 'gfx/i/pages_mountpoint.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="7">Mount Point</option>';
00326         }
00327         if (in_array(3, $types) && !in_array(3, $removeItems)) {
00328             $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages_link.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="3">Link to external URL</option>';
00329         }
00330         $content .= $group ? '<optgroup class="c-divider" label="Link">' . $group . '</optgroup>' : '';
00331 
00332         $group = '';
00333         if (in_array(254, $types) && !in_array(254, $removeItems)) {
00334             $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/sysf.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="254">Folder</option>';
00335         }
00336         if (in_array(255, $types) && !in_array(255, $removeItems)) {
00337             $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/recycler.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="255">Recycler</option>';
00338         }
00339         if (in_array(199, $types) && !in_array(199, $removeItems)) {
00340             $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/spacer_icon.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="199">Visual menu separator</option>';
00341         }
00342         $content .= $group ? '<optgroup class="c-divider" label="Special">' . $group . '</optgroup>' : '';
00343         $content .= '</select>';
00344 
00345         return '<div id="form-line-' . $index . '" class="' . $backgroundClass . '">' . $content . '</div>';
00346     }
00347 }
00348 
00349 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/wizard_crpages/class.tx_wizardcrpages_webfunc_2.php'])) {
00350     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/wizard_crpages/class.tx_wizardcrpages_webfunc_2.php']);
00351 }
00352 ?>