Added Feature #16642: New extension manager part 2: Add ExtJs Module
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / classes / settings / class.tx_em_settings.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.tx_em_settings.php 2089 2010-03-22 12:03:25Z steffenk $
31 *
32 * @author Steffen Kamper <info@sk-typo3.de>
33 */
34
35
36 $GLOBALS['LANG']->includeLLFile(t3lib_extMgm::extPath('em', 'language/locallang.xml'));
37
38
39 class tx_em_Settings implements t3lib_Singleton {
40
41 public $MOD_MENU = array(); // Module menu items
42
43
44 /**
45 * Develop commands
46 *
47 * @var string
48 */
49 protected $settings;
50
51 /**
52 * Constructor
53 *
54 */
55 public function __construct() {
56 $this->readSettings();
57 }
58
59 /**
60 * Get settings
61 */
62 public function getSettings() {
63 return $this->settings;
64 }
65
66 /**
67 * Get user Settings
68 */
69 public function getUserSettings() {
70 $userSettings = t3lib_beFunc::getModTSconfig(0, 'mod.tools_em');
71 return $userSettings['properties'];
72 }
73
74 /**
75 * Save user settings
76 *
77 * @param array $settings
78 */
79 public function saveSettings($settings) {
80 $this->settings = t3lib_BEfunc::getModuleData($this->MOD_MENU, $settings, 'tools_em');
81 return $this->settings;
82 }
83
84 /**
85 * Save single value in session settings
86 *
87 * @param string $name
88 * @param string $value
89 */
90 public function saveSetting($name, $value) {
91 t3lib_BEfunc::getModuleData($this->MOD_MENU, array($name => $value), 'tools_em');
92 }
93
94 /**
95 * Initial settings for extension manager module data
96 *
97 * @return void
98 */
99 protected function readSettings() {
100 $this->MOD_MENU = array(
101 'function' => array(
102 'loaded_list' => $GLOBALS['LANG']->getLL('menu_loaded_extensions'),
103 'installed_list' => $GLOBALS['LANG']->getLL('menu_install_extensions'),
104 'import' => $GLOBALS['LANG']->getLL('menu_import_extensions'),
105 'translations' => $GLOBALS['LANG']->getLL('menu_translation_handling'),
106 'settings' => $GLOBALS['LANG']->getLL('menu_settings'),
107 'updates' => $GLOBALS['LANG']->getLL('menu_extension_updates'),
108 'extensionmanager' => 'New Extension manager (beta2)', //$GLOBALS['LANG']->getLL('header'),
109 'develop' => $GLOBALS['LANG']->getLL('menu_extension_develop'),
110 ),
111 'listOrder' => array(
112 'cat' => $GLOBALS['LANG']->getLL('list_order_category'),
113 'author_company' => $GLOBALS['LANG']->getLL('list_order_author'),
114 'state' => $GLOBALS['LANG']->getLL('list_order_state'),
115 'type' => $GLOBALS['LANG']->getLL('list_order_type'),
116 ),
117 'display_details' => array(
118 1 => $GLOBALS['LANG']->getLL('show_details'),
119 0 => $GLOBALS['LANG']->getLL('show_description'),
120 2 => $GLOBALS['LANG']->getLL('show_more_details'),
121
122 3 => $GLOBALS['LANG']->getLL('show_technical'),
123 4 => $GLOBALS['LANG']->getLL('show_validating'),
124 5 => $GLOBALS['LANG']->getLL('show_changed'),
125 ),
126 'display_shy' => '',
127 'display_own' => '',
128 'display_obsolete' => '',
129 'display_installed' => '',
130 'display_files' => '',
131
132
133 'singleDetails' => array(
134 'info' => $GLOBALS['LANG']->getLL('details_info'),
135 'edit' => $GLOBALS['LANG']->getLL('details_edit'),
136 'backup' => $GLOBALS['LANG']->getLL('details_backup_delete'),
137 'dump' => $GLOBALS['LANG']->getLL('details_dump_db'),
138 'upload' => $GLOBALS['LANG']->getLL('details_upload'),
139 'updateModule' => $GLOBALS['LANG']->getLL('details_update'),
140 ),
141 'fe_u' => '',
142 'fe_p' => '',
143
144 'mirrorListURL' => '',
145 'rep_url' => '',
146 'extMirrors' => '',
147
148 // returns uid of currently selected repository
149 // default and hardcoded: 1 = TYPO3.org
150 'selectedRepository' => '1',
151 'selectedMirror' => '0',
152
153 'selectedLanguages' => '',
154
155 'mainTab' => '0',
156 );
157 $this->settings = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), 'tools_em');
158 }
159
160 /**
161 * Gets url for mirror
162 *
163 * @return string
164 */
165 public function getMirrorURL() {
166 if (strlen($this->settings['rep_url'])) {
167 return $this->settings['rep_url'];
168 }
169
170 $mirrors = unserialize($this->settings['extMirrors']);
171 /*if(!is_array($mirrors)) {
172 $this->fetchMetaData('mirrors');
173 $mirrors = unserialize($this->MOD_SETTINGS['extMirrors']);
174 if(!is_array($mirrors)) return false;
175 }*/
176 if (!$this->settings['selectedMirror']) {
177 $rand = array_rand($mirrors);
178 $url = 'http://' . $mirrors[$rand]['host'] . $mirrors[$rand]['path'];
179 }
180 else {
181 $url = 'http://' . $mirrors[$this->settings['selectedMirror']]['host'] . $mirrors[$this->settings['selectedMirror']]['path'];
182 }
183
184 return $url;
185 }
186
187 /**
188 * Method returns registered extension repositories.
189 *
190 * Registered repositories are global (per installation) settings.
191 *
192 * @access public
193 * @return array of {@link em_repository em_repository} instances
194 * @see registerDefaultRepository(), setRegisteredRepositories()
195 */
196 public function getRegisteredRepositories() {
197 $registry = t3lib_div::makeInstance('t3lib_Registry');
198 $regRepos = $registry->get('core', 'em.repositories.registered');
199
200 // create default entry if there wasn't one
201 if (empty($regRepos)) {
202 $this->registerDefaultRepository();
203 $regRepos = $registry->get('core', 'em.repositories.registered');
204 }
205
206 return $regRepos;
207 }
208
209 /**
210 * Method creates default registered repositories entry.
211 *
212 * @access protected
213 * @return void
214 * @see getRegisteredRepository(), setRegisteredRepositories()
215 */
216 protected function registerDefaultRepository() {
217 $registry = t3lib_div::makeInstance('t3lib_Registry');
218 $defaultRepo = t3lib_div::makeInstance('tx_em_Repository');
219 $registry->set('core', 'em.repositories.registered', array($defaultRepo));
220 }
221
222 /**
223 * Method sets (persists) registered repositories.
224 *
225 * Registered repositories are global (per installation) settings.
226 *
227 * @access public
228 * @param array $repositories array of {@link em_repository em_repository} instances
229 * @see registerDefaultRepository(), setRegisteredRepositories()
230 * @throws InvalidArgumentException in case argument contains no instances of {@link em_repository em_repository}
231 */
232 public function setRegisteredRepositories(array $repositories) {
233 // removing mirror instances
234 foreach ($repositories as $repository) {
235 if ($repository instanceof em_repository) {
236 $repository->removeMirrors();
237 } else {
238 throw new InvalidArgumentException(get_class($this) . ': ' . 'No valid instances of em_repository given.');
239 }
240 }
241 if (count($repositories)) {
242 $registry = t3lib_div::makeInstance('t3lib_Registry');
243 $registry->set('core', 'em.repositories.registered', $repositories);
244 }
245 }
246
247 /**
248 * Method returns currently selected repository
249 *
250 * Selected repository is local (per user) settings.
251 *
252 * @access public
253 * @return em_repository repository instance that is currently selected by a BE user
254 * @see setSelectedRepository()
255 */
256 public function getSelectedRepository() {
257 return t3lib_div::makeInstance('tx_em_Repository', $this->settings['selectedRepository']);
258 }
259
260 /**
261 * Method sets currently selected repository.
262 *
263 * Selected repository is local (per user) settings.
264 *
265 * @todo STUB, implementation missing
266 * @access public
267 * @param em_repository $repository repository instance that is currently selected by a BE user
268 * @see getSelectedRepository()
269 */
270 public function setSelectedRepository(em_repository $repository) {
271 // this method would set sth. like "REPOSITORY_TITLE:INT" in a setting field
272 // REPOSITORY_TITLE = example: main
273 // INT = 0 means randomly selected mirror, >0 selects specific mirror
274 }
275
276 }
277
278 ?>