index.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009-2010 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 7905 2010-06-13 14:42:33Z 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      * Initializes the Module
00051      *
00052      * @return  void
00053      */
00054     public function initialize() {
00055         parent::init();
00056         $this->doc = t3lib_div::makeInstance('template');
00057         $this->doc->setModuleTemplate(t3lib_extMgm::extPath('recycler') . 'mod1/mod_template.html');
00058         $this->doc->backPath = $GLOBALS['BACK_PATH'];
00059 
00060         $this->relativePath = t3lib_extMgm::extRelPath('recycler');
00061         $this->pageRecord = t3lib_BEfunc::readPageAccess($this->id, $this->perms_clause);
00062         $this->isAccessibleForCurrentUser = (
00063             $this->id && is_array($this->pageRecord) || !$this->id && $this->isCurrentUserAdmin()
00064         );
00065 
00066         //don't access in workspace
00067         if ($GLOBALS['BE_USER']->workspace !== 0) {
00068             $this->isAccessibleForCurrentUser = false;
00069         }
00070 
00071         //read configuration
00072         $modTS = $GLOBALS['BE_USER']->getTSConfig('mod.recycler');
00073         if ($this->isCurrentUserAdmin()) {
00074             $this->allowDelete = true;
00075         } else {
00076             $this->allowDelete = ($modTS['properties']['allowDelete'] == '1');
00077         }
00078         if (isset($modTS['properties']['recordsPageLimit']) && intval($modTS['properties']['recordsPageLimit']) > 0) {
00079             $this->recordsPageLimit = intval($modTS['properties']['recordsPageLimit']);
00080         }
00081     }
00082 
00083     /**
00084      * Renders the contente of the module.
00085      *
00086      * @return  void
00087      */
00088     public function render() {
00089         global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
00090 
00091         $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('title'), $GLOBALS['LANG']->getLL('description'));
00092         if ($this->isAccessibleForCurrentUser) {
00093             $this->loadHeaderData();
00094                 // div container for renderTo
00095             $this->content .= '<div id="recyclerContent"></div>';
00096         } else {
00097             // If no access or if ID == zero
00098             $this->content .= $this->doc->spacer(10);
00099         }
00100     }
00101 
00102     /**
00103      * Flushes the rendered content to browser.
00104      *
00105      * @return  void
00106      */
00107     public function flush() {
00108         $content = $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
00109         $content.= $this->doc->moduleBody(
00110             $this->pageRecord,
00111             $this->getDocHeaderButtons(),
00112             $this->getTemplateMarkers()
00113         );
00114         $content.= $this->doc->endPage();
00115 
00116         $this->content = null;
00117         $this->doc = null;
00118 
00119         echo $content;
00120     }
00121 
00122     /**
00123      * Determines whether the current user is admin.
00124      *
00125      * @return  boolean     Whether the current user is admin
00126      */
00127     protected function isCurrentUserAdmin() {
00128         return (bool)$GLOBALS['BE_USER']->user['admin'];
00129     }
00130 
00131     /**
00132      * Loads data in the HTML head section (e.g. JavaScript or stylesheet information).
00133      *
00134      * @return  void
00135      */
00136     protected function loadHeaderData() {
00137             // Load CSS Stylesheets:
00138         $this->loadStylesheet($this->relativePath . 'res/css/customExtJs.css');
00139             // Load Ext JS:
00140         $this->doc->getPageRenderer()->loadExtJS();
00141             // Integrate dynamic JavaScript such as configuration or lables:
00142         $this->doc->JScode.= t3lib_div::wrapJS('
00143             Ext.namespace("Recycler");
00144             Recycler.statics = ' . json_encode($this->getJavaScriptConfiguration()) . ';
00145             Recycler.lang = ' . json_encode($this->getJavaScriptLabels()) . ';'
00146         );
00147             // Load Recycler JavaScript:
00148         $this->loadJavaScript($this->relativePath . 'res/js/ext_expander.js');
00149         $this->loadJavaScript($this->relativePath . 'res/js/search_field.js');
00150         $this->loadJavaScript($this->relativePath . 'res/js/t3_recycler.js');
00151     }
00152 
00153     /**
00154      * Loads a stylesheet by adding it to the HTML head section.
00155      *
00156      * @param   string      $fileName: Name of the file to be loaded
00157      * @return  void
00158      */
00159     protected function loadStylesheet($fileName) {
00160         $fileName = t3lib_div::resolveBackPath($this->doc->backPath . $fileName);
00161         $this->doc->JScode .= TAB . '<link rel="stylesheet" type="text/css" href="' . t3lib_div::createVersionNumberedFilename($fileName) . '" />' . LF;
00162     }
00163 
00164     /**
00165      * Loads a JavaScript file.
00166      *
00167      * @param   string      $fileName: Name of the file to be loaded
00168      * @return  void
00169      */
00170     protected function loadJavaScript($fileName) {
00171         $fileName = t3lib_div::resolveBackPath($this->doc->backPath . $fileName);
00172         $this->doc->JScode .= TAB . '<script language="javascript" type="text/javascript" src="' . t3lib_div::createVersionNumberedFilename($fileName) . '"></script>' . LF;
00173     }
00174 
00175     /**
00176      * Gets the JavaScript configuration for the Ext JS interface.
00177      *
00178      * @return  array       The JavaScript configuration
00179      */
00180     protected function getJavaScriptConfiguration() {
00181         $configuration = array(
00182             'pagingSize' => $this->recordsPageLimit,
00183             'showDepthMenu' => 1,
00184             'startUid' => $this->id,
00185             'tableDefault' => 'pages',
00186             'renderTo' => 'recyclerContent',
00187             'isSSL' => t3lib_div::getIndpEnv('TYPO3_SSL'),
00188             'ajaxController' => $this->doc->backPath . 'ajax.php?ajaxID=tx_recycler::controller',
00189             'deleteDisable' => $this->allowDelete ? 0 : 1,
00190             'depthSelection' => $this->getDataFromSession('depthSelection', 0),
00191             'tableSelection' => $this->getDataFromSession('tableSelection', 'pages'),
00192         );
00193         return $configuration;
00194     }
00195 
00196     /**
00197      * Gets the labels to be used in JavaScript in the Ext JS interface.
00198      *
00199      * @return  array       The labels to be used in JavaScript
00200      */
00201     protected function getJavaScriptLabels() {
00202         $coreLabels = array(
00203             'title'         => $GLOBALS['LANG']->getLL('title'),
00204             'path'          => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.path'),
00205             'table'         => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.table'),
00206             'depth'         => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_perm.xml:Depth'),
00207             'depth_0'       => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_0'),
00208             'depth_1'       => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_1'),
00209             'depth_2'       => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_2'),
00210             'depth_3'       => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_3'),
00211             'depth_4'       => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_4'),
00212             'depth_infi'    => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_infi'),
00213         );
00214 
00215         $extensionLabels = $this->getJavaScriptLabelsFromLocallang('js.', 'label_');
00216         $javaScriptLabels = array_merge($coreLabels, $extensionLabels);
00217 
00218             // Convert labels back to UTF-8 since json_encode() only works with UTF-8:
00219         if ($GLOBALS['LANG']->charSet !== 'utf-8') {
00220             $GLOBALS['LANG']->csConvObj->convArray($javaScriptLabels, $GLOBALS['LANG']->charSet, 'utf-8');
00221         }
00222 
00223         return $javaScriptLabels;
00224     }
00225 
00226     /**
00227      * Gets labels to be used in JavaScript fetched from the current locallang file.
00228      *
00229      * @param   string      $selectionPrefix: Prefix to select the correct labels (default: 'js.')
00230      * @param   string      $stripFromSelectionName: Sub-prefix to be removed from label names in the result (default: '')
00231      * @return  array       Lables to be used in JavaScript of the current locallang file
00232      * @todo    Check, whether this method can be moved in a generic way to $GLOBALS['LANG']
00233      */
00234     protected function getJavaScriptLabelsFromLocallang($selectionPrefix = 'js.', $stripFromSelectionName = '') {
00235         $extraction = array();
00236         $labels = array_merge(
00237             (array)$GLOBALS['LOCAL_LANG']['default'],
00238             (array)$GLOBALS['LOCAL_LANG'][$GLOBALS['LANG']->lang]
00239         );
00240             // Regular expression to strip the selection prefix and possibly something from the label name:
00241         $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
00242             // Iterate throuh all locallang lables:
00243         foreach ($labels as $label => $value) {
00244             if (strpos($label, $selectionPrefix) === 0) {
00245                 $key = preg_replace($labelPattern, '', $label);
00246                 $extraction[$key] = $value;
00247             }
00248         }
00249         return $extraction;
00250     }
00251 
00252     /**
00253      * Gets the buttons that shall be rendered in the docHeader.
00254      *
00255      * @return  array       Available buttons for the docHeader
00256      */
00257     protected function getDocHeaderButtons() {
00258         $buttons = array(
00259             'csh'       => t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
00260             'shortcut'  => $this->getShortcutButton(),
00261             'save'      => ''
00262         );
00263 
00264             // SAVE button
00265         $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) . '" />';
00266 
00267         return $buttons;
00268     }
00269 
00270     /**
00271      * Gets the button to set a new shortcut in the backend (if current user is allowed to).
00272      *
00273      * @return  string      HTML representiation of the shortcut button
00274      */
00275     protected function getShortcutButton() {
00276         $result = '';
00277         if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
00278             $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
00279         }
00280         return $result;
00281     }
00282 
00283     /**
00284      * Gets the filled markers that are used in the HTML template.
00285      *
00286      * @return  array       The filled marker array
00287      */
00288     protected function getTemplateMarkers() {
00289         $markers = array(
00290             'FUNC_MENU' => $this->getFunctionMenu(),
00291             'CONTENT'   => $this->content,
00292             'TITLE'     => $GLOBALS['LANG']->getLL('title'),
00293         );
00294         return $markers;
00295     }
00296 
00297     /**
00298      * Gets the function menu selector for this backend module.
00299      *
00300      * @return  string      The HTML representation of the function menu selector
00301      */
00302     protected function getFunctionMenu() {
00303         return t3lib_BEfunc::getFuncMenu(
00304             0,
00305             'SET[function]',
00306             $this->MOD_SETTINGS['function'],
00307             $this->MOD_MENU['function']
00308         );
00309     }
00310 
00311     /**
00312      * Gets data from the session of the current backend user.
00313      *
00314      * @param   string      $identifier: The identifier to be used to get the data
00315      * @param   string      $default: The default date to be used if nothing was found in the session
00316      * @return  string      The accordant data in the session of the current backend user
00317      */
00318     protected function getDataFromSession($identifier, $default = NULL) {
00319         $sessionData =& $GLOBALS['BE_USER']->uc['tx_recycler'];
00320         if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
00321             $data = $sessionData[$identifier];
00322         } else {
00323             $data = $default;
00324         }
00325         return $data;
00326     }
00327 }
00328 
00329 
00330 
00331 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/recycler/mod1/index.php']) {
00332     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/recycler/mod1/index.php']);
00333 }
00334 
00335 
00336 
00337 // Make instance:
00338 $SOBE = t3lib_div::makeInstance('tx_recycler_module1');
00339 $SOBE->initialize();
00340 
00341 // Include files?
00342 foreach($SOBE->include_once as $INC_FILE) {
00343     include_once($INC_FILE);
00344 }
00345 
00346 $SOBE->render();
00347 $SOBE->flush();
00348 ?>

Generated on Sat Jul 24 04:17:16 2010 for TYPO3 API by  doxygen 1.4.7