Merge of extension manager for 4.5.0 - see ChangeLog in em for details
[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 = array();
144 $this->pageRenderer->addInlineLanguageLabelFile(t3lib_extMgm::extPath('em', 'language/locallang.xml'));
145 $labels['yes'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
146 $labels['no'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
147 $this->pageRenderer->addInlineLanguageLabelArray($labels);
148
149 $globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
150 if (!is_array($globalSettings)) {
151 $globalSettings = array(
152 'displayMyExtensions' => 0,
153 'selectedLanguages' => array(),
154 'inlineToWindow' => 1,
155 );
156 }
157 $settings = $this->parentObject->MOD_SETTINGS;
158 $mirrors = unserialize($settings['extMirrors']);
159 $settings['extMirrors'] = array(array('Random (recommended)', '', '', '', '', '', ''));
160 if (is_array($mirrors)) {
161 foreach ($mirrors as $mirror) {
162 $settings['extMirrors'][] = array(
163 $mirror['title'], $mirror['country'], $mirror['host'], $mirror['path'],
164 $mirror['sponsor']['name'], $mirror['sponsor']['link'], $mirror['sponsor']['logo']
165 );
166 }
167 }
168
169 $allowRepositoryUpdate = !intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.hideRepositoryUpdate'));
170
171 /* file operations */
172 $fileAllowMove = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowMove'));
173 $fileAllowDelete = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowDelete'));
174 $fileAllowRename = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowRename'));
175 $fileAllowUpload = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowUpload'));
176 $fileAllowCreate = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowCreate'));
177 $fileAllowDownload = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowDownload'));
178
179
180 // add the settings
181 $additionalSettings = array(
182 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
183 'backPath' => $this->parentObject->doc->backPath,
184 'hasCredentials' => (isset($settings['fe_u']) && isset($settings['fe_p']) && $settings['fe_u'] !== '' && $settings['fe_p'] !== ''),
185 'scriptLink' => $this->parentObject->script,
186 'editorCss' => $this->resPath . 'css/editor.css',
187 'codemirrorCssPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/css/',
188 'codemirrorJsPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/js/',
189 'codemirrorContribPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/contrib/',
190 'selectedLanguages' => t3lib_div::trimExplode(',', $globalSettings['selectedLanguages'], TRUE),
191 'state' => $GLOBALS['BE_USER']->uc['moduleData']['tools_em']['States'],
192 'inlineToWindow' => $globalSettings['inlineToWindow'],
193 'allowRepositoryUpdate' => $allowRepositoryUpdate,
194 'displayMyExtensions' => $globalSettings['displayMyExtensions'],
195 'debug' => $GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] > 0,
196 //TODO: some are disabled until feater-proofed
197 'fileAllowSave' => $GLOBALS['TYPO3_CONF_VARS']['EXT']['noEdit'] == 0,
198 'fileAllowMove' => 0, //$fileAllowMove,
199 'fileAllowDelete' => 0, //$fileAllowDelete,
200 'fileAllowRename' => 0, //$fileAllowRename,
201 'fileAllowUpload' => 0, //$fileAllowUpload,
202 'fileAllowCreate' => 0, //$fileAllowCreate,
203 'fileAllowDownload' => $fileAllowDownload,
204
205 );
206 $settings = array_merge($settings, $additionalSettings);
207
208 // Add JS
209 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/ux/flashmessages.js');
210 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . 'js/extjs/iframepanel.js');
211 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . 'contrib/codemirror/js/codemirror.js');
212
213 //Plugins
214 $this->pageRenderer->addJsFile($this->resPath . 'js/overrides/ext_overrides.js');
215 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/custom_plugins.js');
216 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/ux/Ext.ux.FitToParent.js');
217 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/notifications.js');
218 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/TreeState.js');
219 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/RowPanelExpander.js');
220 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/searchfield.js');
221 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/fileuploadfield.js');
222 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/menu/RangeMenu.js');
223 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/menu/ListMenu.js');
224 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/GridFilters.js');
225 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/Filter.js');
226 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/BooleanFilter.js');
227 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/DateFilter.js');
228 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/ListFilter.js');
229 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/NumericFilter.js');
230 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/StringFilter.js');
231 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/jslint.js');
232
233 //Scripts
234 $this->pageRenderer->addJsFile($this->resPath . 'js/em_layouts.js');
235
236 $this->pageRenderer->addJsFile($this->resPath . 'js/em_components.js');
237 $this->pageRenderer->addJsFile($this->resPath . 'js/em_files.js');
238 $this->pageRenderer->addJsFile($this->resPath . 'js/em_ter.js');
239 $this->pageRenderer->addJsFile($this->resPath . 'js/em_tools.js');
240
241 $this->pageRenderer->addJsFile($this->resPath . 'js/em_locallist.js');
242 $this->pageRenderer->addJsFile($this->resPath . 'js/em_repositorylist.js');
243 $this->pageRenderer->addJsFile($this->resPath . 'js/em_usertools.js');
244
245 $this->pageRenderer->addJsFile($this->resPath . 'js/em_languages.js');
246 $this->pageRenderer->addJsFile($this->resPath . 'js/em_settings.js');
247 //Application
248 $this->pageRenderer->addJsFile($this->resPath . 'js/em_app.js');
249
250 // clear flashmessages from php
251 t3lib_FlashMessageQueue::getAllMessagesAndFlush();
252
253 $content = '
254 <div id="em-message-area"></div><div id="em-app"></div>
255 <!-- dummy form to make configuration js happy -->
256 <form name="tsStyleConfigForm" action="" method="post"></form>
257 ';
258
259 //hook for the extension manager gui
260 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['em/classes/class.tx_em_extensionamager.php']['renderHook'])) {
261 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['em/classes/class.tx_em_extensionamager.php']['renderHook'] as $classRef) {
262 $hookObject = t3lib_div::getUserObj($classRef);
263 if(!($hookObject instanceof tx_em_renderHook)) {
264 throw new UnexpectedValueException('$hookObject must implement interface tx_em_renderHook', 1298121373);
265 }
266 $hookObject->render(
267 $this->pageRenderer, $settings, $content
268 );
269 }
270 }
271
272 // render settings and labels
273 $this->pageRenderer->addInlineSettingArray('EM', $settings);
274 $this->pageRenderer->addInlineLanguageLabelArray($labels);
275
276 return $content;
277 }
278
279 /**
280 * Check integrity of repository entry in sys_ter
281 *
282 * @return void
283 */
284 protected function checkRepository() {
285 /** @var $repository tx_em_Repository */
286 $repository = t3lib_div::makeInstance('tx_em_Repository');
287 if ($repository->getLastUpdate() == 0) {
288 $extCount = tx_em_Database::getExtensionCountFromRepository($repository);
289 if ($extCount > 0) {
290 $repository->setExtensionCount($extCount);
291 $repository->setLastUpdate(time());
292 tx_em_Database::updateRepository($repository);
293 }
294 }
295 }
296 }
297
298 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/class.tx_em_extensionsmanager.php'])) {
299 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/class.tx_em_extensionsmanager.php']);
300 }
301
302 ?>