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