[BUGFIX] PHP warning on each Extension Manager invocation
[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 * @author Steffen Kamper <info@sk-typo3.de>
31 */
32
33
34 class tx_em_ExtensionManager {
35
36 /**
37 * Parent module object
38 *
39 * @var SC_mod_tools_em_index
40 */
41 protected $parentObject;
42
43 /**
44 * Page Renderer
45 *
46 * @var t3lib_PageRenderer
47 */
48 protected $pageRenderer;
49
50 /**
51 * Path of res for JS/CSS/resources
52 *
53 * @var string
54 */
55 protected $resPath;
56
57 /**
58 * Debug flag for develop debug=1 will use one uncompressed concatenated file, debug=2 will use single files
59 *
60 * @var int
61 */
62 protected $debug;
63
64 /**
65 * Gzip support - use it if server supports gzipped js files
66 *
67 * @var boolean
68 */
69 protected $gzSupport = FALSE;
70
71
72
73 /**
74 * Constructor
75 *
76 * @param SC_mod_tools_em_index $parentObject
77 */
78 public function __construct(SC_mod_tools_em_index $parentObject) {
79 $this->parentObject = $parentObject;
80 $this->parentObject->doc->setExtDirectStateProvider();
81 $this->pageRenderer = $this->parentObject->doc->getPageRenderer();
82 $this->resPath = $this->parentObject->doc->backPath . t3lib_extMgm::extRelPath('em') . 'res/';
83
84 $userSettings = $this->parentObject->settings->getUserSettings();
85
86 $this->debug = isset($userSettings['debug']) ? intval($userSettings['debug']) : 0;
87 $this->gzSupport = isset($userSettings['jsGzCompressed']) ? TRUE : FALSE;
88
89 $this->checkRepository();
90 }
91
92 /**
93 * Render module content
94 *
95 * @return string $content
96 */
97 public function render() {
98
99 /* Add CSS */
100 $this->pageRenderer->addCssFile($this->resPath . 'js/ux/css/GridFilters.css');
101 $this->pageRenderer->addCssFile($this->resPath . 'js/ux/css/RangeMenu.css');
102 $this->pageRenderer->addCssFile($this->resPath . 'css/t3_em.css');
103
104
105 $iconsGfxPath = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'] . 'gfx/';
106 $this->pageRenderer->addCssInlineBlock('em-t3skin-icons', '
107 .x-tree-node-leaf img.tree-edit { background-image:url(' . $iconsGfxPath . 'edit_file.gif);}
108 .x-btn-edit { background-image:url(' . $iconsGfxPath . 'edit2.gif) !important;}
109 .x-btn-new { background-image:url(' . $iconsGfxPath . 'new_el.gif) !important;}
110 .x-btn-delete { background-image:url(' . $iconsGfxPath . 'garbage.gif) !important;}
111 .x-tree-node-leaf img.tree-unknown { background-image:url(' . $iconsGfxPath . 'default.gif); }
112 .x-btn-save { background-image:url(' . $iconsGfxPath . 'savedok.gif) !important;}
113 .x-btn-upload { background-image:url(' . $iconsGfxPath . 'upload.gif) !important;}
114 .x-btn-download { background-image:url(' . $iconsGfxPath . 'down.gif) !important;}
115 .x-btn-undo { background-image:url(' . $this->resPath . 'icons/arrow_undo.png) !important;}
116 .x-btn-redo { background-image:url(' . $this->resPath . 'icons/arrow_redo.png) !important;}
117 .x-btn-jslint { background-image:url(' . $this->resPath . 'icons/jslint.gif) !important;}
118 .x-btn-indent { background-image:url(' . $this->resPath . 'icons/text_indent.png) !important;}
119 ');
120
121 /* load ExtJS */
122 $this->pageRenderer->loadExtJS();
123 $this->pageRenderer->enableExtJSQuickTips();
124
125 $this->pageRenderer->addExtDirectCode();
126
127
128 // Localization
129 $labels = array();
130 $this->pageRenderer->addInlineLanguageLabelFile(t3lib_extMgm::extPath('em', 'language/locallang.xml'));
131 $labels['yes'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
132 $labels['no'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
133 $this->pageRenderer->addInlineLanguageLabelArray($labels);
134
135 $globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
136 if (!is_array($globalSettings)) {
137 $globalSettings = array(
138 'displayMyExtensions' => 0,
139 'selectedLanguages' => '',
140 'inlineToWindow' => 1,
141 );
142 }
143 $settings = $this->parentObject->MOD_SETTINGS;
144 $mirrors = unserialize($settings['extMirrors']);
145 $settings['extMirrors'] = array(array('Random (recommended)', '', '', '', '', '', ''));
146 if (is_array($mirrors)) {
147 foreach ($mirrors as $mirror) {
148 $settings['extMirrors'][] = array(
149 $mirror['title'], $mirror['country'], $mirror['host'], $mirror['path'],
150 $mirror['sponsor']['name'], $mirror['sponsor']['link'], $mirror['sponsor']['logo']
151 );
152 }
153 }
154
155 $allowRepositoryUpdate = !intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.hideRepositoryUpdate'));
156
157 /* file operations */
158 $fileAllowMove = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowMove'));
159 $fileAllowDelete = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowDelete'));
160 $fileAllowRename = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowRename'));
161 $fileAllowUpload = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowUpload'));
162 $fileAllowCreate = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowCreate'));
163 $fileAllowDownload = intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.fileAllowDownload'));
164
165
166 // add the settings
167 $additionalSettings = array(
168 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
169 'backPath' => $this->parentObject->doc->backPath,
170 'hasCredentials' => (isset($settings['fe_u']) && isset($settings['fe_p']) && $settings['fe_u'] !== '' && $settings['fe_p'] !== ''),
171 'scriptLink' => $this->parentObject->script,
172 'editorCss' => $this->resPath . 'css/editor.css',
173 'codemirrorCssPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/css/',
174 'codemirrorJsPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/js/',
175 'codemirrorContribPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/contrib/',
176 'selectedLanguages' => t3lib_div::trimExplode(',', $globalSettings['selectedLanguages'], TRUE),
177 'inlineToWindow' => $globalSettings['inlineToWindow'],
178 'allowRepositoryUpdate' => $allowRepositoryUpdate,
179 'displayMyExtensions' => $globalSettings['displayMyExtensions'],
180 'debug' => $GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] > 0,
181 //TODO: some are disabled until feater-proofed
182 'fileAllowSave' => $GLOBALS['TYPO3_CONF_VARS']['EXT']['noEdit'] == 0,
183 'fileAllowMove' => 0, //$fileAllowMove,
184 'fileAllowDelete' => 0, //$fileAllowDelete,
185 'fileAllowRename' => 0, //$fileAllowRename,
186 'fileAllowUpload' => 0, //$fileAllowUpload,
187 'fileAllowCreate' => 0, //$fileAllowCreate,
188 'fileAllowDownload' => $fileAllowDownload,
189
190 );
191 $settings = array_merge($settings, $additionalSettings);
192
193 // Add JS
194 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/ux/flashmessages.js');
195 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . 'js/extjs/iframepanel.js');
196 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . 'contrib/codemirror/js/codemirror.js');
197
198 //Plugins
199 $this->pageRenderer->addJsFile($this->resPath . 'js/overrides/ext_overrides.js');
200 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/custom_plugins.js');
201 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/ux/Ext.ux.FitToParent.js');
202 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/notifications.js');
203 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/TreeState.js');
204 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/RowPanelExpander.js');
205 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/searchfield.js');
206 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/fileuploadfield.js');
207 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/menu/RangeMenu.js');
208 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/menu/ListMenu.js');
209 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/GridFilters.js');
210 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/Filter.js');
211 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/BooleanFilter.js');
212 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/DateFilter.js');
213 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/ListFilter.js');
214 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/NumericFilter.js');
215 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/StringFilter.js');
216 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/jslint.js');
217
218 //Scripts
219 $this->pageRenderer->addJsFile($this->resPath . 'js/em_layouts.js');
220
221 $this->pageRenderer->addJsFile($this->resPath . 'js/em_components.js');
222 $this->pageRenderer->addJsFile($this->resPath . 'js/em_files.js');
223 $this->pageRenderer->addJsFile($this->resPath . 'js/em_ter.js');
224 $this->pageRenderer->addJsFile($this->resPath . 'js/em_tools.js');
225
226 $this->pageRenderer->addJsFile($this->resPath . 'js/em_locallist.js');
227 $this->pageRenderer->addJsFile($this->resPath . 'js/em_repositorylist.js');
228 $this->pageRenderer->addJsFile($this->resPath . 'js/em_usertools.js');
229
230 $this->pageRenderer->addJsFile($this->resPath . 'js/em_languages.js');
231 $this->pageRenderer->addJsFile($this->resPath . 'js/em_settings.js');
232 //Application
233 $this->pageRenderer->addJsFile($this->resPath . 'js/em_app.js');
234
235 // clear flashmessages from php
236 t3lib_FlashMessageQueue::getAllMessagesAndFlush();
237
238 $content = '
239 <div id="em-message-area"></div><div id="em-app"></div>
240 <!-- dummy form to make configuration js happy -->
241 <form name="tsStyleConfigForm" action="" method="post"></form>
242 ';
243
244 //hook for the extension manager gui
245 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['em/classes/class.tx_em_extensionamager.php']['renderHook'])) {
246 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['em/classes/class.tx_em_extensionamager.php']['renderHook'] as $classRef) {
247 $hookObject = t3lib_div::getUserObj($classRef);
248 if(!($hookObject instanceof tx_em_renderHook)) {
249 throw new UnexpectedValueException('$hookObject must implement interface tx_em_renderHook', 1298121373);
250 }
251 $hookObject->render(
252 $this->pageRenderer, $settings, $content
253 );
254 }
255 }
256
257 // render settings and labels
258 $this->pageRenderer->addInlineSettingArray('EM', $settings);
259 $this->pageRenderer->addInlineLanguageLabelArray($labels);
260
261 return $content;
262 }
263
264 /**
265 * Check integrity of repository entry in sys_ter
266 *
267 * @return void
268 */
269 protected function checkRepository() {
270 /** @var $repository tx_em_Repository */
271 $repository = t3lib_div::makeInstance('tx_em_Repository');
272 if ($repository->getLastUpdate() == 0) {
273 $extCount = tx_em_Database::getExtensionCountFromRepository($repository);
274 if ($extCount > 0) {
275 $repository->setExtensionCount($extCount);
276 $repository->setLastUpdate(time());
277 tx_em_Database::updateRepository($repository);
278 }
279 }
280 }
281 }
282
283 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/class.tx_em_extensionsmanager.php'])) {
284 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/class.tx_em_extensionsmanager.php']);
285 }
286
287 ?>