class.clearcachemenu.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2007-2008 Ingo Renner <ingo@typo3.org>
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 
00029 /**
00030  * class to render the menu for the cache clearing actions
00031  *
00032  * $Id: class.clearcachemenu.php 4432 2008-11-07 03:52:22Z flyguide $
00033  *
00034  * @author  Ingo Renner <ingo@typo3.org>
00035  * @package TYPO3
00036  * @subpackage core
00037  */
00038 class ClearCacheMenu implements backend_toolbarItem {
00039 
00040     protected $cacheActions;
00041 
00042     /**
00043      * reference back to the backend object
00044      *
00045      * @var TYPO3backend
00046      */
00047     protected $backendReference;
00048 
00049     /**
00050      * constructor
00051      *
00052      * @param   TYPO3backend    TYPO3 backend object reference
00053      */
00054     public function __construct(TYPO3backend &$backendReference = null) {
00055         $this->backendReference = $backendReference;
00056         $this->cacheActions     = array();
00057 
00058             // Clear cache for ALL tables!
00059         if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')) {
00060             $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_all', true);
00061             $this->cacheActions[] = array(
00062                 'id'    => 'all',
00063                 'title' => $title,
00064                 'href'  => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=all',
00065                 'icon'  => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning_red.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" />'
00066             );
00067         }
00068 
00069             // Clear cache for either ALL pages
00070         if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')) {
00071             $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_pages', true);
00072             $this->cacheActions[] = array(
00073                 'id'    => 'pages',
00074                 'title' => $title,
00075                 'href'  => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=pages',
00076                 'icon'  => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" />'
00077             );
00078         }
00079 
00080             // Clearing of cache-files in typo3conf/ + menu
00081         if($GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache']) {
00082             $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCacheMenu_allTypo3Conf', true);
00083             $this->cacheActions[] = array(
00084                 'id'    => 'temp_CACHED',
00085                 'title' => $title,
00086                 'href'  => $this->backPath.'tce_db.php?vC='.$GLOBALS['BE_USER']->veriCode().'&cacheCmd=temp_CACHED',
00087                 'icon'  => '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning_green.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" />'
00088             );
00089         }
00090 
00091     }
00092 
00093     /**
00094      * checks whether the user has access to this toolbar item
00095      *
00096      * @return  boolean  true if user has access, false if not
00097      */
00098     public function checkAccess() {
00099         return (
00100             $GLOBALS['BE_USER']->isAdmin()
00101             || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')
00102             || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')
00103         );
00104     }
00105 
00106     /**
00107      * Creates the selector for workspaces
00108      *
00109      * @return  string      workspace selector as HTML select
00110      */
00111     public function render() {
00112         $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.clearCache_clearCache', true);
00113         $this->addJavascriptToBackend();
00114         $cacheMenu = array();
00115 
00116         $cacheMenu[] = '<a href="#" class="toolbar-item"><img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/lightning.png', 'width="16" height="16"').' title="'.$title.'" alt="'.$title.'" /></a>';
00117 
00118         $cacheMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
00119 
00120         foreach($this->cacheActions as $actionKey => $cacheAction) {
00121             $cacheMenu[] = '<li><a href="'.htmlspecialchars($cacheAction['href']).'">'.$cacheAction['icon'].' '.$cacheAction['title'].'</a></li>';
00122         }
00123 
00124         $cacheMenu[] = '</ul>';
00125 
00126         return implode("\n", $cacheMenu);
00127     }
00128 
00129     /**
00130      * adds the necessary JavaScript to the backend
00131      *
00132      * @return  void
00133      */
00134     protected function addJavascriptToBackend() {
00135         $this->backendReference->addJavascriptFile('js/clearcachemenu.js');
00136     }
00137 
00138     /**
00139      * returns additional attributes for the list item in the toolbar
00140      *
00141      * @return  string      list item HTML attibutes
00142      */
00143     public function getAdditionalAttributes() {
00144         return ' id="clear-cache-actions-menu"';
00145     }
00146 
00147 }
00148 
00149 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']) {
00150     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.clearcachemenu.php']);
00151 }
00152 
00153 ?>

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