207852997458505e26699dbe8dcbe273b5bff115
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / classes / class.tx_em_extensionmanager.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Steffen Kamper (info@sk-typo3.de)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Module: Extension manager, developer module
29 *
30 * $Id: class.em_extensionmanager.php 2106 2010-03-24 00:56:22Z steffenk $
31 *
32 * @author Steffen Kamper <info@sk-typo3.de>
33 */
34
35
36 class tx_em_ExtensionManager {
37
38 /**
39 * Parent module object
40 *
41 * @var SC_mod_tools_em_index
42 */
43 protected $parentObject;
44
45 /**
46 * Page Renderer
47 *
48 * @var t3lib_PageRenderer
49 */
50 protected $pageRenderer;
51
52 /**
53 * Path of res for JS/CSS/resources
54 *
55 * @var string
56 */
57 protected $resPath;
58
59 /**
60 * Debug flag for develop debug=1 will use one uncompressed concatenated file, debug=2 will use single files
61 *
62 * @var int
63 */
64 protected $debug;
65
66 /**
67 * Gzip support - use it if server supports gzipped js files
68 *
69 * @var boolean
70 */
71 protected $gzSupport = FALSE;
72
73
74
75 /**
76 * Constructor
77 *
78 * @param SC_mod_tools_em_index $parentObject
79 */
80 public function __construct(SC_mod_tools_em_index $parentObject) {
81 $this->parentObject = $parentObject;
82 $this->parentObject->doc->setExtDirectStateProvider();
83 $this->pageRenderer = $this->parentObject->doc->getPageRenderer();
84 $this->resPath = $this->parentObject->doc->backPath . t3lib_extMgm::extRelPath('em') . 'res/';
85
86 $userSettings = $this->parentObject->settings->getUserSettings();
87
88 $this->debug = isset($userSettings['debug']) ? intval($userSettings['debug']) : 0;
89 $this->gzSupport = isset($userSettings['jsGzCompressed']) ? TRUE : FALSE;
90
91 $this->checkRepository();
92 }
93
94 /**
95 * Render module content
96 *
97 * @return string $content
98 */
99 public function render() {
100
101 /* Add CSS */
102 $this->pageRenderer->addCssFile($this->resPath . 'js/ux/css/GridFilters.css');
103 $this->pageRenderer->addCssFile($this->resPath . 'js/ux/css/RangeMenu.css');
104 $this->pageRenderer->addCssFile($this->resPath . 'css/t3_em.css');
105
106
107 $iconsGfxPath = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'] . 'gfx/';
108 $this->pageRenderer->addCssInlineBlock('em-t3skin-icons', '
109 .x-tree-node-leaf img.tree-edit { background-image:url(' . $iconsGfxPath . 'edit_file.gif);}
110 .x-btn-edit { background-image:url(' . $iconsGfxPath . 'edit2.gif) !important;}
111 .x-btn-new { background-image:url(' . $iconsGfxPath . 'new_el.gif) !important;}
112 .x-btn-delete { background-image:url(' . $iconsGfxPath . 'garbage.gif) !important;}
113 .x-tree-node-leaf img.tree-unknown { background-image:url(' . $iconsGfxPath . 'default.gif); }
114 .x-btn-save { background-image:url(' . $iconsGfxPath . 'savedok.gif) !important;}
115 .x-btn-upload { background-image:url(' . $iconsGfxPath . 'upload.gif) !important;}
116 .x-btn-download { background-image:url(' . $iconsGfxPath . 'down.gif) !important;}
117 .x-btn-undo { background-image:url(' . $this->resPath . 'icons/arrow_undo.png) !important;}
118 .x-btn-redo { background-image:url(' . $this->resPath . 'icons/arrow_redo.png) !important;}
119 .x-btn-jslint { background-image:url(' . $this->resPath . 'icons/jslint.gif) !important;}
120 .x-btn-indent { background-image:url(' . $this->resPath . 'icons/text_indent.png) !important;}
121 ');
122
123 /* load ExtJS */
124 $this->pageRenderer->loadExtJS();
125 $this->pageRenderer->enableExtJSQuickTips();
126
127 // Load JavaScript:
128 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath .
129 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.EM',
130 NULL,
131 FALSE
132 );
133 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath .
134 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.EMSOAP',
135 NULL,
136 FALSE
137 );
138
139 $this->pageRenderer->addExtDirectCode();
140
141
142 // Localization
143 $labels = tx_em_Tools::getArrayFromLocallang(t3lib_extMgm::extPath('em', 'language/locallang.xml'));
144 $labels['yes'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
145 $labels['no'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
146
147
148 $globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
149 if (!isset($globalSettings)) {
150 $globalSettings = array(
151 'displayMyExtensions' => 0,
152 'selectedLanguages' => array()
153 );
154 }
155 $settings = $this->parentObject->MOD_SETTINGS;
156 $mirrors = unserialize($settings['extMirrors']);
157 $settings['extMirrors'] = array(array('Random (recommended)', '', '', '', '', '', ''));
158 if (is_array($mirrors)) {
159 foreach ($mirrors as $mirror) {
160 $settings['extMirrors'][] = array(
161 $mirror['title'], $mirror['country'], $mirror['host'], $mirror['path'],
162 $mirror['sponsor']['name'], $mirror['sponsor']['link'], $mirror['sponsor']['logo']
163 );
164 }
165 }
166
167 $allowRepositoryUpdate = !intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.hideRepositoryUpdate'));
168
169 // add the settings
170 $additionalSettings = array(
171 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
172 'backPath' => $this->parentObject->doc->backPath,
173 'hasCredentials' => (isset($settings['fe_u']) && isset($settings['fe_p']) && $settings['fe_u'] !== '' && $settings['fe_p'] !== ''),
174 'scriptLink' => $this->parentObject->script,
175 'editorCss' => $this->resPath . 'css/editor.css',
176 'codemirrorCssPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/css/',
177 'codemirrorJsPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/js/',
178 'codemirrorContribPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/contrib/',
179 'selectedLanguages' => t3lib_div::trimExplode(',', $globalSettings['selectedLanguages'], TRUE),
180 'state' => $GLOBALS['BE_USER']->uc['moduleData']['tools_em']['States'],
181 'inlineToWindow' => $globalSettings['inlineToWindow'],
182 'allowRepositoryUpdate' => $allowRepositoryUpdate,
183 'displayMyExtensions' => $globalSettings['displayMyExtensions'],
184 'fileSaveAllowed' => $GLOBALS['TYPO3_CONF_VARS']['EXT']['noEdit'] == 0,
185 'debug' => $GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] > 0,
186 );
187 $settings = array_merge($settings, $additionalSettings);
188
189 // Add JS
190 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/ux/flashmessages.js');
191 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . 'js/extjs/iframepanel.js');
192 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . 'contrib/codemirror/js/codemirror.js');
193
194 //Plugins
195 $this->pageRenderer->addJsFile($this->resPath . 'js/overrides/ext_overrides.js');
196 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/custom_plugins.js');
197 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/ux/Ext.ux.FitToParent.js');
198 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/TreeState.js');
199 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/RowPanelExpander.js');
200 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/searchfield.js');
201 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/fileuploadfield.js');
202 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/menu/RangeMenu.js');
203 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/menu/ListMenu.js');
204 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/GridFilters.js');
205 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/Filter.js');
206 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/BooleanFilter.js');
207 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/DateFilter.js');
208 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/ListFilter.js');
209 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/NumericFilter.js');
210 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/StringFilter.js');
211 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/jslint.js');
212
213 //Scripts
214 $this->pageRenderer->addJsFile($this->resPath . 'js/em_layouts.js');
215
216 $this->pageRenderer->addJsFile($this->resPath . 'js/em_components.js');
217 $this->pageRenderer->addJsFile($this->resPath . 'js/em_files.js');
218 $this->pageRenderer->addJsFile($this->resPath . 'js/em_ter.js');
219 $this->pageRenderer->addJsFile($this->resPath . 'js/em_tools.js');
220
221 $this->pageRenderer->addJsFile($this->resPath . 'js/em_locallist.js');
222 $this->pageRenderer->addJsFile($this->resPath . 'js/em_repositorylist.js');
223 $this->pageRenderer->addJsFile($this->resPath . 'js/em_usertools.js');
224
225 $this->pageRenderer->addJsFile($this->resPath . 'js/em_languages.js');
226 $this->pageRenderer->addJsFile($this->resPath . 'js/em_settings.js');
227 //Application
228 $this->pageRenderer->addJsFile($this->resPath . 'js/em_app.js');
229
230 // clear flashmessages from php
231 t3lib_FlashMessageQueue::getAllMessagesAndFlush();
232
233 $content = '
234 <div id="em-message-area"></div><div id="em-app"></div>
235 <!-- dummy form to make configuration js happy -->
236 <form name="tsStyleConfigForm" action="" method="post"></form>
237 ';
238
239 //hook for the extension manager gui
240 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['em/classes/class.tx_em_extensionamager.php']['renderHook'])) {
241 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['em/classes/class.tx_em_extensionamager.php']['renderHook'] as $classRef) {
242 $hookObj = t3lib_div::getUserObj($classRef);
243 if (method_exists($hookObj, 'render')) {
244 $hookObj->render(
245 $this->pageRenderer, $settings, $labels, $content
246 );
247 }
248 }
249 }
250
251 // render settings and labels
252 $this->pageRenderer->addInlineSettingArray('EM', $settings);
253 $this->pageRenderer->addInlineLanguageLabelArray($labels);
254
255 return $content;
256 }
257
258 /**
259 * Check integrity of repository entry in sys_ter
260 *
261 * @return void
262 */
263 protected function checkRepository() {
264 /** @var $repository tx_em_Repository */
265 $repository = t3lib_div::makeInstance('tx_em_Repository');
266 if ($repository->getLastUpdate() == 0) {
267 $extCount = tx_em_Database::getExtensionCountFromRepository($repository);
268 if ($extCount > 0) {
269 $repository->setExtensionCount($extCount);
270 $repository->setLastUpdate(time());
271 tx_em_Database::updateRepository($repository);
272 }
273 }
274 }
275 }
276
277 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/class.tx_em_extensionsmanager.php'])) {
278 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/class.tx_em_extensionsmanager.php']);
279 }
280
281 ?>