TYPO3 API  SVNRelease
class.tx_em_extensionmanager.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2010 Steffen Kamper (info@sk-typo3.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 *  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  * Module: Extension manager, developer module
00029  *
00030  * $Id: class.em_extensionmanager.php 2106 2010-03-24 00:56:22Z steffenk $
00031  *
00032  * @author  Steffen Kamper <info@sk-typo3.de>
00033  */
00034 
00035 
00036 class tx_em_ExtensionManager {
00037 
00038     /**
00039      * Parent module object
00040      *
00041      * @var SC_mod_tools_em_index
00042      */
00043     protected $parentObject;
00044 
00045     /**
00046      * Page Renderer
00047      *
00048      * @var t3lib_PageRenderer
00049      */
00050     protected $pageRenderer;
00051 
00052     /**
00053      * Path of res for JS/CSS/resources
00054      *
00055      * @var string
00056      */
00057     protected $resPath;
00058 
00059     /**
00060      * Debug flag for develop debug=1 will use one uncompressed concatenated file, debug=2 will use single files
00061      *
00062      * @var int
00063      */
00064     protected $debug;
00065 
00066     /**
00067      * Gzip support - use it if server supports gzipped js files
00068      *
00069      * @var boolean
00070      */
00071     protected $gzSupport = FALSE;
00072 
00073 
00074 
00075     /**
00076      * Constructor
00077      *
00078      * @param SC_mod_tools_em_index $parentObject
00079      */
00080     public function __construct(SC_mod_tools_em_index $parentObject) {
00081         $this->parentObject = $parentObject;
00082         $this->parentObject->doc->setExtDirectStateProvider();
00083         $this->pageRenderer = $this->parentObject->doc->getPageRenderer();
00084         $this->resPath = $this->parentObject->doc->backPath . t3lib_extMgm::extRelPath('em') . 'res/';
00085 
00086         $userSettings = $this->parentObject->settings->getUserSettings();
00087 
00088         $this->debug = isset($userSettings['debug']) ? intval($userSettings['debug']) : 0;
00089         $this->gzSupport = isset($userSettings['jsGzCompressed']) ? TRUE : FALSE;
00090 
00091         $this->checkRepository();
00092     }
00093 
00094     /**
00095      * Render module content
00096      *
00097      * @return string $content
00098      */
00099     public function render() {
00100 
00101         /* Add CSS */
00102         $this->pageRenderer->addCssFile($this->resPath . 'js/ux/css/GridFilters.css');
00103         $this->pageRenderer->addCssFile($this->resPath . 'js/ux/css/RangeMenu.css');
00104         $this->pageRenderer->addCssFile($this->resPath . 'css/t3_em.css');
00105 
00106 
00107         $iconsGfxPath = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'] . 'gfx/';
00108         $this->pageRenderer->addCssInlineBlock('em-t3skin-icons', '
00109             .x-tree-node-leaf img.tree-edit { background-image:url(' . $iconsGfxPath . 'edit_file.gif);}
00110             .x-btn-edit { background-image:url(' . $iconsGfxPath . 'edit2.gif) !important;}
00111             .x-btn-new { background-image:url(' . $iconsGfxPath . 'new_el.gif) !important;}
00112             .x-btn-delete { background-image:url(' . $iconsGfxPath . 'garbage.gif) !important;}
00113             .x-tree-node-leaf img.tree-unknown { background-image:url(' . $iconsGfxPath . 'default.gif); }
00114             .x-btn-save { background-image:url(' . $iconsGfxPath . 'savedok.gif) !important;}
00115             .x-btn-upload { background-image:url(' . $iconsGfxPath . 'upload.gif) !important;}
00116             .x-btn-download { background-image:url(' . $iconsGfxPath . 'down.gif) !important;}
00117             .x-btn-undo { background-image:url(' . $this->resPath . 'icons/arrow_undo.png) !important;}
00118             .x-btn-redo { background-image:url(' . $this->resPath . 'icons/arrow_redo.png) !important;}
00119             .x-btn-jslint { background-image:url(' . $this->resPath . 'icons/jslint.gif) !important;}
00120             .x-btn-indent { background-image:url(' . $this->resPath . 'icons/text_indent.png) !important;}
00121         ');
00122 
00123         /* load ExtJS */
00124         $this->pageRenderer->loadExtJS();
00125         $this->pageRenderer->enableExtJSQuickTips();
00126 
00127             // Load  JavaScript:
00128         $this->pageRenderer->addJsFile($this->parentObject->doc->backPath .
00129             'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.EM',
00130             NULL,
00131             FALSE
00132         );
00133         $this->pageRenderer->addJsFile($this->parentObject->doc->backPath .
00134             'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.EMSOAP',
00135             NULL,
00136             FALSE
00137         );
00138 
00139         $this->pageRenderer->addExtDirectCode();
00140 
00141 
00142             // Localization
00143         $labels = array();
00144         $this->pageRenderer->addInlineLanguageLabelFile(t3lib_extMgm::extPath('em', 'language/locallang.xml'));
00145         $labels['yes'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
00146         $labels['no'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
00147         $this->pageRenderer->addInlineLanguageLabelArray($labels);
00148 
00149         $globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
00150         if (!is_array($globalSettings)) {
00151             $globalSettings = array(
00152                 'displayMyExtensions' => 0,
00153                 'selectedLanguages' => array(),
00154                 'inlineToWindow' => 1,
00155             );
00156         }
00157         $settings = $this->parentObject->MOD_SETTINGS;
00158         $mirrors = unserialize($settings['extMirrors']);
00159         $settings['extMirrors'] = array(array('Random (recommended)', '', '', '', '', '', ''));
00160         if (is_array($mirrors)) {
00161             foreach ($mirrors as $mirror) {
00162                 $settings['extMirrors'][] = array(
00163                     $mirror['title'], $mirror['country'], $mirror['host'], $mirror['path'],
00164                     $mirror['sponsor']['name'], $mirror['sponsor']['link'], $mirror['sponsor']['logo']
00165                 );
00166             }
00167         }
00168 
00169         $allowRepositoryUpdate = !intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.hideRepositoryUpdate'));
00170 
00171         /* file operations */
00172         $fileAllowMove = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowMove'));
00173         $fileAllowDelete = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowDelete'));
00174         $fileAllowRename = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowRename'));
00175         $fileAllowUpload = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowUpload'));
00176         $fileAllowCreate = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowCreate'));
00177         $fileAllowDownload = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowDownload'));
00178 
00179 
00180             // add the settings
00181         $additionalSettings = array(
00182             'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
00183             'backPath' => $this->parentObject->doc->backPath,
00184             'hasCredentials' => (isset($settings['fe_u']) && isset($settings['fe_p']) && $settings['fe_u'] !== '' && $settings['fe_p'] !== ''),
00185             'scriptLink' => $this->parentObject->script,
00186             'editorCss' => $this->resPath . 'css/editor.css',
00187             'codemirrorCssPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/css/',
00188             'codemirrorJsPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/js/',
00189             'codemirrorContribPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/contrib/',
00190             'selectedLanguages' => t3lib_div::trimExplode(',', $globalSettings['selectedLanguages'], TRUE),
00191             'state' => $GLOBALS['BE_USER']->uc['moduleData']['tools_em']['States'],
00192             'inlineToWindow' => $globalSettings['inlineToWindow'],
00193             'allowRepositoryUpdate' => $allowRepositoryUpdate,
00194             'displayMyExtensions' => $globalSettings['displayMyExtensions'],
00195             'debug' => $GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] > 0,
00196             //TODO: some are disabled until feater-proofed
00197             'fileAllowSave' => $GLOBALS['TYPO3_CONF_VARS']['EXT']['noEdit'] == 0,
00198             'fileAllowMove' => 0, //$fileAllowMove,
00199             'fileAllowDelete' => 0, //$fileAllowDelete,
00200             'fileAllowRename' => 0, //$fileAllowRename,
00201             'fileAllowUpload' => 0, //$fileAllowUpload,
00202             'fileAllowCreate' => 0, //$fileAllowCreate,
00203             'fileAllowDownload' => $fileAllowDownload,
00204 
00205         );
00206         $settings = array_merge($settings, $additionalSettings);
00207 
00208         // Add JS
00209         $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/ux/flashmessages.js');
00210         $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . 'js/extjs/iframepanel.js');
00211         $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . 'contrib/codemirror/js/codemirror.js');
00212 
00213         //Plugins
00214         $this->pageRenderer->addJsFile($this->resPath . 'js/overrides/ext_overrides.js');
00215         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/custom_plugins.js');
00216         $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/ux/Ext.ux.FitToParent.js');
00217         $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/notifications.js');
00218         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/TreeState.js');
00219         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/RowPanelExpander.js');
00220         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/searchfield.js');
00221         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/fileuploadfield.js');
00222         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/menu/RangeMenu.js');
00223         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/menu/ListMenu.js');
00224         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/GridFilters.js');
00225         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/Filter.js');
00226         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/BooleanFilter.js');
00227         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/DateFilter.js');
00228         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/ListFilter.js');
00229         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/NumericFilter.js');
00230         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/StringFilter.js');
00231         $this->pageRenderer->addJsFile($this->resPath . 'js/ux/jslint.js');
00232 
00233         //Scripts
00234         $this->pageRenderer->addJsFile($this->resPath . 'js/em_layouts.js');
00235 
00236         $this->pageRenderer->addJsFile($this->resPath . 'js/em_components.js');
00237         $this->pageRenderer->addJsFile($this->resPath . 'js/em_files.js');
00238         $this->pageRenderer->addJsFile($this->resPath . 'js/em_ter.js');
00239         $this->pageRenderer->addJsFile($this->resPath . 'js/em_tools.js');
00240 
00241         $this->pageRenderer->addJsFile($this->resPath . 'js/em_locallist.js');
00242         $this->pageRenderer->addJsFile($this->resPath . 'js/em_repositorylist.js');
00243         $this->pageRenderer->addJsFile($this->resPath . 'js/em_usertools.js');
00244 
00245         $this->pageRenderer->addJsFile($this->resPath . 'js/em_languages.js');
00246         $this->pageRenderer->addJsFile($this->resPath . 'js/em_settings.js');
00247         //Application
00248         $this->pageRenderer->addJsFile($this->resPath . 'js/em_app.js');
00249 
00250         // clear flashmessages from php
00251         t3lib_FlashMessageQueue::getAllMessagesAndFlush();
00252 
00253         $content =  '
00254             <div id="em-message-area"></div><div id="em-app"></div>
00255             <!-- dummy form to make configuration js happy -->
00256             <form name="tsStyleConfigForm" action="" method="post"></form>
00257         ';
00258 
00259             //hook for the extension manager gui
00260         if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['em/classes/class.tx_em_extensionamager.php']['renderHook'])) {
00261             foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['em/classes/class.tx_em_extensionamager.php']['renderHook'] as $classRef) {
00262                 $hookObject = t3lib_div::getUserObj($classRef);
00263                 if(!($hookObject instanceof tx_em_renderHook)) {
00264                     throw new UnexpectedValueException('$hookObject must implement interface tx_em_renderHook', 1298121373);
00265                 }
00266                 $hookObject->render(
00267                     $this->pageRenderer, $settings, $content
00268                 );
00269             }
00270         }
00271 
00272             // render settings and labels
00273         $this->pageRenderer->addInlineSettingArray('EM', $settings);
00274         $this->pageRenderer->addInlineLanguageLabelArray($labels);
00275 
00276         return $content;
00277     }
00278 
00279     /**
00280      * Check integrity of repository entry in sys_ter
00281      *
00282      * @return void
00283      */
00284     protected function checkRepository() {
00285         /** @var $repository tx_em_Repository  */
00286         $repository = t3lib_div::makeInstance('tx_em_Repository');
00287         if ($repository->getLastUpdate() == 0) {
00288             $extCount = tx_em_Database::getExtensionCountFromRepository($repository);
00289             if ($extCount > 0) {
00290                 $repository->setExtensionCount($extCount);
00291                 $repository->setLastUpdate(time());
00292                 tx_em_Database::updateRepository($repository);
00293             }
00294         }
00295     }
00296 }
00297 
00298 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/class.tx_em_extensionsmanager.php'])) {
00299     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/class.tx_em_extensionsmanager.php']);
00300 }
00301 
00302 ?>