Merge of extension manager for RC1
[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 'extensionmanager' => $GLOBALS['LANG']->getLL('header'),
108 'updates' => $GLOBALS['LANG']->getLL('menu_extension_updates'),
109 ),
110 'listOrder' => array(
111 'cat' => $GLOBALS['LANG']->getLL('list_order_category'),
112 'author_company' => $GLOBALS['LANG']->getLL('list_order_author'),
113 'state' => $GLOBALS['LANG']->getLL('list_order_state'),
114 'type' => $GLOBALS['LANG']->getLL('list_order_type'),
115 ),
116 'display_details' => array(
117 1 => $GLOBALS['LANG']->getLL('show_details'),
118 0 => $GLOBALS['LANG']->getLL('show_description'),
119 2 => $GLOBALS['LANG']->getLL('show_more_details'),
120
121 3 => $GLOBALS['LANG']->getLL('show_technical'),
122 4 => $GLOBALS['LANG']->getLL('show_validating'),
123 5 => $GLOBALS['LANG']->getLL('show_changed'),
124 ),
125 'display_shy' => '',
126 'display_own' => '',
127 'display_obsolete' => '',
128 'display_installed' => '',
129 'display_files' => '',
130 'hide_shy' => 0,
131 'hide_obsolete' => 0,
132
133
134 'singleDetails' => array(
135 'info' => $GLOBALS['LANG']->getLL('details_info'),
136 'edit' => $GLOBALS['LANG']->getLL('details_edit'),
137 'backup' => $GLOBALS['LANG']->getLL('details_backup_delete'),
138 'dump' => $GLOBALS['LANG']->getLL('details_dump_db'),
139 'upload' => $GLOBALS['LANG']->getLL('details_upload'),
140 'updateModule' => $GLOBALS['LANG']->getLL('details_update'),
141 ),
142 'fe_u' => '',
143 'fe_p' => '',
144
145 'mirrorListURL' => '',
146 'rep_url' => '',
147 'extMirrors' => '',
148
149 // returns uid of currently selected repository
150 // default and hardcoded: 1 = TYPO3.org
151 'selectedRepository' => '1',
152 'selectedMirror' => '0',
153
154 'selectedLanguages' => '',
155
156 'mainTab' => '0',
157 );
158 $this->settings = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), 'tools_em');
159 }
160
161 /**
162 * Gets url for mirror
163 *
164 * @return string
165 */
166 public function getMirrorURL() {
167 if (strlen($this->settings['rep_url'])) {
168 return $this->settings['rep_url'];
169 }
170
171 $mirrors = unserialize($this->settings['extMirrors']);
172
173 if(!is_array($mirrors)) {
174 if ($this->settings['selectedRepository'] < 1) {
175 $this->settings['selectedRepository'] = 1;
176 }
177 }
178 /** @var $repository tx_em_Repository */
179 $repository = t3lib_div::makeInstance('tx_em_Repository', $this->settings['selectedRepository']);
180 if ($repository->getMirrorListUrl()) {
181 $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $repository);
182 $mirrors = $objRepositoryUtility->getMirrors(TRUE)->getMirrors();
183 if(!is_array($mirrors)) {
184 return FALSE;
185 } else {
186 $this->settings['extMirrors'] = serialize($mirrors);
187 $this->saveSetting('extMirrors', $this->settings['extMirrors']);
188 }
189 }
190 if (!$this->settings['selectedMirror']) {
191 $rand = array_rand($mirrors);
192 $url = 'http://' . $mirrors[$rand]['host'] . $mirrors[$rand]['path'];
193 }
194 else {
195 $url = 'http://' . $mirrors[$this->settings['selectedMirror']]['host'] . $mirrors[$this->settings['selectedMirror']]['path'];
196 }
197
198 return $url;
199 }
200
201 /**
202 * Method returns registered extension repositories.
203 *
204 * Registered repositories are global (per installation) settings.
205 *
206 * @access public
207 * @return array of {@link em_repository em_repository} instances
208 * @see registerDefaultRepository(), setRegisteredRepositories()
209 */
210 public function getRegisteredRepositories() {
211 $registry = t3lib_div::makeInstance('t3lib_Registry');
212 $regRepos = $registry->get('core', 'em.repositories.registered');
213
214 // create default entry if there wasn't one
215 if (empty($regRepos)) {
216 $this->registerDefaultRepository();
217 $regRepos = $registry->get('core', 'em.repositories.registered');
218 }
219
220 return $regRepos;
221 }
222
223 /**
224 * Method creates default registered repositories entry.
225 *
226 * @access protected
227 * @return void
228 * @see getRegisteredRepository(), setRegisteredRepositories()
229 */
230 protected function registerDefaultRepository() {
231 $registry = t3lib_div::makeInstance('t3lib_Registry');
232 $defaultRepo = t3lib_div::makeInstance('tx_em_Repository');
233 $registry->set('core', 'em.repositories.registered', array($defaultRepo));
234 }
235
236 /**
237 * Method sets (persists) registered repositories.
238 *
239 * Registered repositories are global (per installation) settings.
240 *
241 * @access public
242 * @param array $repositories array of {@link em_repository em_repository} instances
243 * @see registerDefaultRepository(), setRegisteredRepositories()
244 * @throws InvalidArgumentException in case argument contains no instances of {@link em_repository em_repository}
245 */
246 public function setRegisteredRepositories(array $repositories) {
247 // removing mirror instances
248 foreach ($repositories as $repository) {
249 if ($repository instanceof em_repository) {
250 $repository->removeMirrors();
251 } else {
252 throw new InvalidArgumentException(get_class($this) . ': ' . 'No valid instances of em_repository given.');
253 }
254 }
255 if (count($repositories)) {
256 $registry = t3lib_div::makeInstance('t3lib_Registry');
257 $registry->set('core', 'em.repositories.registered', $repositories);
258 }
259 }
260
261 /**
262 * Method returns currently selected repository
263 *
264 * Selected repository is local (per user) settings.
265 *
266 * @access public
267 * @return em_repository repository instance that is currently selected by a BE user
268 * @see setSelectedRepository()
269 */
270 public function getSelectedRepository() {
271 return t3lib_div::makeInstance('tx_em_Repository', $this->settings['selectedRepository']);
272 }
273
274 /**
275 * Method sets currently selected repository.
276 *
277 * Selected repository is local (per user) settings.
278 *
279 * @todo STUB, implementation missing
280 * @access public
281 * @param em_repository $repository repository instance that is currently selected by a BE user
282 * @see getSelectedRepository()
283 */
284 public function setSelectedRepository(em_repository $repository) {
285 // this method would set sth. like "REPOSITORY_TITLE:INT" in a setting field
286 // REPOSITORY_TITLE = example: main
287 // INT = 0 means randomly selected mirror, >0 selects specific mirror
288 }
289
290 }
291
292 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/settings/class.tx_em_settings.php'])) {
293 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/repository/class.tx_em_settings.php']);
294 }
295
296 ?>