Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / classes / class.tx_em_extensionmanager.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 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 if ($this->debug == 2 || 1) {
103 $this->pageRenderer->addCssFile($this->resPath . 'js/ux/css/GridFilters.css');
104 $this->pageRenderer->addCssFile($this->resPath . 'js/ux/css/RangeMenu.css');
105 $this->pageRenderer->addCssFile($this->resPath . 'css/t3_em.css');
106 } elseif($this->debug == 1) {
107
108 } else {
109
110 }
111
112
113 $iconsGfxPath = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'] . 'gfx/';
114 $this->pageRenderer->addCssInlineBlock('em-t3skin-icons', '
115 .x-tree-node-leaf img.tree-edit { background-image:url(' . $iconsGfxPath . 'edit_file.gif);}
116 .x-btn-edit { background-image:url(' . $iconsGfxPath . 'edit2.gif) !important;}
117 .x-btn-new { background-image:url(' . $iconsGfxPath . 'new_el.gif) !important;}
118 .x-btn-delete { background-image:url(' . $iconsGfxPath . 'garbage.gif) !important;}
119 .x-tree-node-leaf img.tree-unknown { background-image:url(' . $iconsGfxPath . 'default.gif); }
120 .x-btn-save { background-image:url(' . $iconsGfxPath . 'savedok.gif) !important;}
121 .x-btn-upload { background-image:url(' . $iconsGfxPath . 'upload.gif) !important;}
122 .x-btn-download { background-image:url(' . $iconsGfxPath . 'down.gif) !important;}
123 .x-btn-undo { background-image:url(' . $this->resPath . 'icons/arrow_undo.png) !important;}
124 .x-btn-redo { background-image:url(' . $this->resPath . 'icons/arrow_redo.png) !important;}
125 .x-btn-jslint { background-image:url(' . $this->resPath . 'icons/jslint.gif) !important;}
126 .x-btn-indent { background-image:url(' . $this->resPath . 'icons/text_indent.png) !important;}
127 ');
128
129 /* load ExtJS */
130 $this->pageRenderer->loadExtJS();
131 $this->pageRenderer->enableExtJsDebug();
132
133 // Load JavaScript:
134 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath .
135 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.EM',
136 NULL,
137 FALSE
138 );
139 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath .
140 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.EMSOAP',
141 NULL,
142 FALSE
143 );
144
145 $this->pageRenderer->addExtDirectCode();
146
147
148 // Localization
149 $labels = tx_em_Tools::getArrayFromLocallang(t3lib_extMgm::extPath('em', 'language/locallang.xml'));
150 $this->pageRenderer->addInlineLanguageLabelArray($labels);
151
152 $globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
153
154 $settings = $this->parentObject->MOD_SETTINGS;
155 $mirrors = unserialize($settings['extMirrors']);
156 $settings['extMirrors'] = array(array('Random (recommended)', '', '', '', '', '', ''));
157 if (is_array($mirrors)) {
158 foreach ($mirrors as $mirror) {
159 $settings['extMirrors'][] = array(
160 $mirror['title'], $mirror['country'], $mirror['host'], $mirror['path'],
161 $mirror['sponsor']['name'], $mirror['sponsor']['link'], $mirror['sponsor']['logo']
162 );
163 }
164 }
165
166 $allowRepositoryUpdate = !intval($GLOBALS['BE_USER']->getTSConfigVal('mod.tools_em.hideRepositoryUpdate'));
167
168 // add the settings
169 $additionalSettings = array(
170 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
171 'backPath' => $this->parentObject->doc->backPath,
172 'hasCredentials' => (isset($settings['fe_u']) && isset($settings['fe_p']) && $settings['fe_u'] !== '' && $settings['fe_p'] !== ''),
173 'scriptLink' => $this->parentObject->script,
174 'editorCss' => $this->resPath . 'css/editor.css',
175 'codemirrorCssPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/css/',
176 'codemirrorJsPath' => $this->parentObject->doc->backPath . 'contrib/codemirror/js/',
177 'selectedLanguages' => t3lib_div::trimExplode(',', $globalSettings['selectedLanguages'], TRUE),
178 'state' => $GLOBALS['BE_USER']->uc['moduleData']['tools_em']['States'],
179 'inlineToWindow' => $globalSettings['inlineToWindow'],
180 'allowRepositoryUpdate' => $allowRepositoryUpdate
181 );
182 $settings = array_merge($settings, $additionalSettings);
183
184 $this->pageRenderer->addInlineSettingArray('EM', $settings);
185
186
187 // Add JS
188 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/ux/flashmessages.js');
189 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . 'js/extjs/iframepanel.js');
190 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . 'contrib/codemirror/js/codemirror.js');
191
192 //Plugins
193 $this->pageRenderer->addJsFile($this->resPath . 'js/overrides/ext_overrides.js');
194 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/custom_plugins.js');
195 $this->pageRenderer->addJsFile($this->parentObject->doc->backPath . '../t3lib/js/extjs/ux/Ext.ux.FitToParent.js');
196 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/RowPanelExpander.js');
197 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/searchfield.js');
198 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/fileuploadfield.js');
199 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/menu/RangeMenu.js');
200 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/menu/ListMenu.js');
201 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/GridFilters.js');
202 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/Filter.js');
203 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/BooleanFilter.js');
204 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/DateFilter.js');
205 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/ListFilter.js');
206 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/NumericFilter.js');
207 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/filter/StringFilter.js');
208 $this->pageRenderer->addJsFile($this->resPath . 'js/ux/jslint.js');
209
210 //Scripts
211 $this->pageRenderer->addJsFile($this->resPath . 'js/em_layouts.js');
212
213 $this->pageRenderer->addJsFile($this->resPath . 'js/em_components.js');
214 $this->pageRenderer->addJsFile($this->resPath . 'js/em_files.js');
215 $this->pageRenderer->addJsFile($this->resPath . 'js/em_ter.js');
216 $this->pageRenderer->addJsFile($this->resPath . 'js/em_tools.js');
217
218 $this->pageRenderer->addJsFile($this->resPath . 'js/em_locallist.js');
219 $this->pageRenderer->addJsFile($this->resPath . 'js/em_repositorylist.js');
220 $this->pageRenderer->addJsFile($this->resPath . 'js/em_usertools.js');
221
222 $this->pageRenderer->addJsFile($this->resPath . 'js/em_languages.js');
223 $this->pageRenderer->addJsFile($this->resPath . 'js/em_settings.js');
224 //Application
225 $this->pageRenderer->addJsFile($this->resPath . 'js/em_app.js');
226
227 // clear flashmessages from php
228 t3lib_FlashMessageQueue::getAllMessagesAndFlush();
229
230 //Update from repository - box
231 //$content = $this->parentObject->showRepositoryUpdateForm(0);
232
233 $content .= '
234
235 <div id="em-message-area"></div><div id="em-app"></div>
236 <!-- dummy form to make configuration js happy -->
237 <form name="tsStyleConfigForm" action="" method="post"></form>
238 ';
239 return $content;
240 }
241
242 /**
243 * Check integrity of repository entry in sys_ter
244 *
245 * @return void
246 */
247 protected function checkRepository() {
248 /** @var $repository tx_em_Repository */
249 $repository = t3lib_div::makeInstance('tx_em_Repository');
250 if ($repository->getLastUpdate() == 0) {
251 $extCount = tx_em_Database::getExtensionCountFromRepository($repository);
252 if ($extCount > 0) {
253 $repository->setExtensionCount($extCount);
254 $repository->setLastUpdate(time());
255 tx_em_Database::updateRepository($repository);
256 }
257 }
258 }
259 }
260
261 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/class.tx_em_extensionsmanager.php'])) {
262 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/class.tx_em_extensionsmanager.php']);
263 }
264
265 ?>