TYPO3 API  SVNRelease
index.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009-2011 Julian Kleinhans <typo3@kj187.de>
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 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 $LANG->includeLLFile('EXT:recycler/mod1/locallang.xml');
00026 $BE_USER->modAccess($MCONF, 1); // This checks permissions and exits if the users has no permission for entry.
00027 
00028 /**
00029  * Module 'Recycler' for the 'recycler' extension.
00030  *
00031  * @author  Julian Kleinhans <typo3@kj187.de>
00032  * @package TYPO3
00033  * @subpackage  tx_recycler
00034  * @version $Id: index.php 10120 2011-01-18 20:03:36Z ohader $
00035  */
00036 class  tx_recycler_module1 extends t3lib_SCbase {
00037     /**
00038      * @var template
00039      */
00040     public $doc;
00041 
00042     protected $relativePath;
00043     protected $pageRecord = array();
00044     protected $isAccessibleForCurrentUser = false;
00045 
00046     protected $allowDelete = false;
00047     protected $recordsPageLimit = 50;
00048 
00049     /**
00050      * @var t3lib_pageRenderer
00051      */
00052     protected $pageRenderer;
00053 
00054     /**
00055      * Initializes the Module
00056      *
00057      * @return  void
00058      */
00059     public function initialize() {
00060         parent::init();
00061         $this->doc = t3lib_div::makeInstance('template');
00062         $this->doc->setModuleTemplate(t3lib_extMgm::extPath('recycler') . 'mod1/mod_template.html');
00063         $this->doc->backPath = $GLOBALS['BACK_PATH'];
00064         $this->doc->setExtDirectStateProvider();
00065 
00066         $this->pageRenderer = $this->doc->getPageRenderer();
00067 
00068         $this->relativePath = t3lib_extMgm::extRelPath('recycler');
00069         $this->pageRecord = t3lib_BEfunc::readPageAccess($this->id, $this->perms_clause);
00070         $this->isAccessibleForCurrentUser = (
00071             $this->id && is_array($this->pageRecord) || !$this->id && $this->isCurrentUserAdmin()
00072         );
00073 
00074         //don't access in workspace
00075         if ($GLOBALS['BE_USER']->workspace !== 0) {
00076             $this->isAccessibleForCurrentUser = false;
00077         }
00078 
00079         //read configuration
00080         $modTS = $GLOBALS['BE_USER']->getTSConfig('mod.recycler');
00081         if ($this->isCurrentUserAdmin()) {
00082             $this->allowDelete = true;
00083         } else {
00084             $this->allowDelete = ($modTS['properties']['allowDelete'] == '1');
00085         }
00086         if (isset($modTS['properties']['recordsPageLimit']) && intval($modTS['properties']['recordsPageLimit']) > 0) {
00087             $this->recordsPageLimit = intval($modTS['properties']['recordsPageLimit']);
00088         }
00089     }
00090 
00091     /**
00092      * Renders the contente of the module.
00093      *
00094      * @return  void
00095      */
00096     public function render() {
00097         global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
00098 
00099         $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('title'), $GLOBALS['LANG']->getLL('description'));
00100         if ($this->isAccessibleForCurrentUser) {
00101             $this->loadHeaderData();
00102                 // div container for renderTo
00103             $this->content .= '<div id="recyclerContent"></div>';
00104         } else {
00105             // If no access or if ID == zero
00106             $this->content .= $this->doc->spacer(10);
00107         }
00108     }
00109 
00110     /**
00111      * Flushes the rendered content to browser.
00112      *
00113      * @return  void
00114      */
00115     public function flush() {
00116         $content = $this->doc->moduleBody(
00117             $this->pageRecord,
00118             $this->getDocHeaderButtons(),
00119             $this->getTemplateMarkers()
00120         );
00121             // Renders the module page
00122         $content = $this->doc->render(
00123             $GLOBALS['LANG']->getLL('title'),
00124             $content
00125         );
00126 
00127         $this->content = null;
00128         $this->doc = null;
00129 
00130         echo $content;
00131     }
00132 
00133     /**
00134      * Determines whether the current user is admin.
00135      *
00136      * @return  boolean     Whether the current user is admin
00137      */
00138     protected function isCurrentUserAdmin() {
00139         return (bool)$GLOBALS['BE_USER']->user['admin'];
00140     }
00141 
00142     /**
00143      * Loads data in the HTML head section (e.g. JavaScript or stylesheet information).
00144      *
00145      * @return  void
00146      */
00147     protected function loadHeaderData() {
00148             // Load CSS Stylesheets:
00149         $this->pageRenderer->addCssFile($this->relativePath . 'res/css/customExtJs.css');
00150 
00151             // Load Ext JS:
00152         $this->pageRenderer->loadExtJS();
00153         $this->pageRenderer->enableExtJSQuickTips();
00154 
00155             // Integrate dynamic JavaScript such as configuration or lables:
00156         $this->pageRenderer->addInlineSettingArray(
00157             'Recycler',
00158             $this->getJavaScriptConfiguration()
00159         );
00160         $this->pageRenderer->addInlineLanguageLabelArray(
00161             $this->getJavaScriptLabels()
00162         );
00163 
00164 
00165             // Load Recycler JavaScript:
00166 
00167             // Load Plugins
00168         $uxPath = $this->doc->backpath . '../t3lib/js/extjs/ux/';
00169         $this->pageRenderer->addJsFile($uxPath . 'Ext.grid.RowExpander.js');
00170         $this->pageRenderer->addJsFile($uxPath . 'Ext.app.SearchField.js');
00171         $this->pageRenderer->addJsFile($uxPath . 'Ext.ux.FitToParent.js');
00172             // Load main script
00173         $this->pageRenderer->addJsFile($this->relativePath . 'res/js/t3_recycler.js');
00174     }
00175 
00176     /**
00177      * Gets the JavaScript configuration for the Ext JS interface.
00178      *
00179      * @return  array       The JavaScript configuration
00180      */
00181     protected function getJavaScriptConfiguration() {
00182         $configuration = array(
00183             'pagingSize' => $this->recordsPageLimit,
00184             'showDepthMenu' => 1,
00185             'startUid' => $this->id,
00186             'tableDefault' => 'pages',
00187             'renderTo' => 'recyclerContent',
00188             'isSSL' => t3lib_div::getIndpEnv('TYPO3_SSL'),
00189             'ajaxController' => $this->doc->backPath . 'ajax.php?ajaxID=tx_recycler::controller',
00190             'deleteDisable' => $this->allowDelete ? 0 : 1,
00191             'depthSelection' => $this->getDataFromSession('depthSelection', 0),
00192             'tableSelection' => $this->getDataFromSession('tableSelection', 'pages'),
00193             'States' => $GLOBALS['BE_USER']->uc['moduleData']['web_recycler']['States'],
00194         );
00195         return $configuration;
00196     }
00197 
00198     /**
00199      * Gets the labels to be used in JavaScript in the Ext JS interface.
00200      *
00201      * @return  array       The labels to be used in JavaScript
00202      */
00203     protected function getJavaScriptLabels() {
00204         $coreLabels = array(
00205             'title'         => $GLOBALS['LANG']->getLL('title'),
00206             'path'          => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.path'),
00207             'table'         => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.table'),
00208             'depth'         => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_perm.xml:Depth'),
00209             'depth_0'       => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_0'),
00210             'depth_1'       => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_1'),
00211             'depth_2'       => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_2'),
00212             'depth_3'       => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_3'),
00213             'depth_4'       => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_4'),
00214             'depth_infi'    => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_infi'),
00215         );
00216 
00217         $extensionLabels = $this->getJavaScriptLabelsFromLocallang('js.', 'label_');
00218         $javaScriptLabels = array_merge($coreLabels, $extensionLabels);
00219 
00220             // Convert labels back to UTF-8 since json_encode() only works with UTF-8:
00221         if ($GLOBALS['LANG']->charSet !== 'utf-8') {
00222             $GLOBALS['LANG']->csConvObj->convArray($javaScriptLabels, $GLOBALS['LANG']->charSet, 'utf-8');
00223         }
00224 
00225         return $javaScriptLabels;
00226     }
00227 
00228     /**
00229      * Gets labels to be used in JavaScript fetched from the current locallang file.
00230      *
00231      * @param   string      $selectionPrefix: Prefix to select the correct labels (default: 'js.')
00232      * @param   string      $stripFromSelectionName: Sub-prefix to be removed from label names in the result (default: '')
00233      * @return  array       Lables to be used in JavaScript of the current locallang file
00234      * @todo    Check, whether this method can be moved in a generic way to $GLOBALS['LANG']
00235      */
00236     protected function getJavaScriptLabelsFromLocallang($selectionPrefix = 'js.', $stripFromSelectionName = '') {
00237         $extraction = array();
00238         $labels = array_merge(
00239             (array)$GLOBALS['LOCAL_LANG']['default'],
00240             (array)$GLOBALS['LOCAL_LANG'][$GLOBALS['LANG']->lang]
00241         );
00242             // Regular expression to strip the selection prefix and possibly something from the label name:
00243         $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
00244             // Iterate throuh all locallang lables:
00245         foreach ($labels as $label => $value) {
00246             if (strpos($label, $selectionPrefix) === 0) {
00247                 $key = preg_replace($labelPattern, '', $label);
00248                 $extraction[$key] = $value;
00249             }
00250         }
00251         return $extraction;
00252     }
00253 
00254     /**
00255      * Gets the buttons that shall be rendered in the docHeader.
00256      *
00257      * @return  array       Available buttons for the docHeader
00258      */
00259     protected function getDocHeaderButtons() {
00260         $buttons = array(
00261             'csh'       => t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
00262             'shortcut'  => $this->getShortcutButton(),
00263             'save'      => ''
00264         );
00265 
00266             // SAVE button
00267         $buttons['save'] = ''; //<input type="image" class="c-inputButton" name="submit" value="Update"' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/savedok.gif', '') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc', 1) . '" />';
00268 
00269         return $buttons;
00270     }
00271 
00272     /**
00273      * Gets the button to set a new shortcut in the backend (if current user is allowed to).
00274      *
00275      * @return  string      HTML representiation of the shortcut button
00276      */
00277     protected function getShortcutButton() {
00278         $result = '';
00279         if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
00280             $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
00281         }
00282         return $result;
00283     }
00284 
00285     /**
00286      * Gets the filled markers that are used in the HTML template.
00287      *
00288      * @return  array       The filled marker array
00289      */
00290     protected function getTemplateMarkers() {
00291         $markers = array(
00292             'FUNC_MENU' => $this->getFunctionMenu(),
00293             'CONTENT'   => $this->content,
00294             'TITLE'     => $GLOBALS['LANG']->getLL('title'),
00295         );
00296         return $markers;
00297     }
00298 
00299     /**
00300      * Gets the function menu selector for this backend module.
00301      *
00302      * @return  string      The HTML representation of the function menu selector
00303      */
00304     protected function getFunctionMenu() {
00305         return t3lib_BEfunc::getFuncMenu(
00306             0,
00307             'SET[function]',
00308             $this->MOD_SETTINGS['function'],
00309             $this->MOD_MENU['function']
00310         );
00311     }
00312 
00313     /**
00314      * Gets data from the session of the current backend user.
00315      *
00316      * @param   string      $identifier: The identifier to be used to get the data
00317      * @param   string      $default: The default date to be used if nothing was found in the session
00318      * @return  string      The accordant data in the session of the current backend user
00319      */
00320     protected function getDataFromSession($identifier, $default = NULL) {
00321         $sessionData =& $GLOBALS['BE_USER']->uc['tx_recycler'];
00322         if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
00323             $data = $sessionData[$identifier];
00324         } else {
00325             $data = $default;
00326         }
00327         return $data;
00328     }
00329 }
00330 
00331 
00332 
00333 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/mod1/index.php'])) {
00334     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/mod1/index.php']);
00335 }
00336 
00337 
00338 
00339 // Make instance:
00340 $SOBE = t3lib_div::makeInstance('tx_recycler_module1');
00341 $SOBE->initialize();
00342 
00343 // Include files?
00344 foreach($SOBE->include_once as $INC_FILE) {
00345     include_once($INC_FILE);
00346 }
00347 
00348 $SOBE->render();
00349 $SOBE->flush();
00350 ?>