2 /***************************************************************
5 * (c) 2010 Steffen Kamper (info@sk-typo3.de)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Module: Extension manager, developer module
30 * $Id: class.tx_em_settings.php 2089 2010-03-22 12:03:25Z steffenk $
32 * @author Steffen Kamper <info@sk-typo3.de>
36 $GLOBALS['LANG']->includeLLFile(t3lib_extMgm
::extPath('em', 'language/locallang.xml'));
39 class tx_em_Settings
implements t3lib_Singleton
{
41 public $MOD_MENU = array(); // Module menu items
55 public function __construct() {
56 $this->readSettings();
62 public function getSettings() {
63 return $this->settings
;
69 public function getUserSettings() {
70 $userSettings = t3lib_beFunc
::getModTSconfig(0, 'mod.tools_em');
71 return $userSettings['properties'];
77 * @param array $settings
79 public function saveSettings($settings) {
80 $this->settings
= t3lib_BEfunc
::getModuleData($this->MOD_MENU
, $settings, 'tools_em');
81 return $this->settings
;
85 * Save single value in session settings
88 * @param string $value
90 public function saveSetting($name, $value) {
91 t3lib_BEfunc
::getModuleData($this->MOD_MENU
, array($name => $value), 'tools_em');
95 * Initial settings for extension manager module data
99 protected function readSettings() {
100 $this->MOD_MENU
= 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',
109 'develop' => $GLOBALS['LANG']->getLL('menu_extension_develop'),
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'),
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'),
122 3 => $GLOBALS['LANG']->getLL('show_technical'),
123 4 => $GLOBALS['LANG']->getLL('show_validating'),
124 5 => $GLOBALS['LANG']->getLL('show_changed'),
128 'display_obsolete' => '',
129 'display_installed' => '',
130 'display_files' => '',
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'),
144 'mirrorListURL' => '',
148 // returns uid of currently selected repository
149 // default and hardcoded: 1 = TYPO3.org
150 'selectedRepository' => '1',
151 'selectedMirror' => '0',
153 'selectedLanguages' => '',
157 $this->settings
= t3lib_BEfunc
::getModuleData($this->MOD_MENU
, t3lib_div
::_GP('SET'), 'tools_em');
161 * Gets url for mirror
165 public function getMirrorURL() {
166 if (strlen($this->settings
['rep_url'])) {
167 return $this->settings
['rep_url'];
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;
176 if (!$this->settings
['selectedMirror']) {
177 $rand = array_rand($mirrors);
178 $url = 'http://' . $mirrors[$rand]['host'] . $mirrors[$rand]['path'];
181 $url = 'http://' . $mirrors[$this->settings
['selectedMirror']]['host'] . $mirrors[$this->settings
['selectedMirror']]['path'];
188 * Method returns registered extension repositories.
190 * Registered repositories are global (per installation) settings.
193 * @return array of {@link em_repository em_repository} instances
194 * @see registerDefaultRepository(), setRegisteredRepositories()
196 public function getRegisteredRepositories() {
197 $registry = t3lib_div
::makeInstance('t3lib_Registry');
198 $regRepos = $registry->get('core', 'em.repositories.registered');
200 // create default entry if there wasn't one
201 if (empty($regRepos)) {
202 $this->registerDefaultRepository();
203 $regRepos = $registry->get('core', 'em.repositories.registered');
210 * Method creates default registered repositories entry.
214 * @see getRegisteredRepository(), setRegisteredRepositories()
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));
223 * Method sets (persists) registered repositories.
225 * Registered repositories are global (per installation) settings.
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}
232 public function setRegisteredRepositories(array $repositories) {
233 // removing mirror instances
234 foreach ($repositories as $repository) {
235 if ($repository instanceof em_repository
) {
236 $repository->removeMirrors();
238 throw new InvalidArgumentException(get_class($this) . ': ' . 'No valid instances of em_repository given.');
241 if (count($repositories)) {
242 $registry = t3lib_div
::makeInstance('t3lib_Registry');
243 $registry->set('core', 'em.repositories.registered', $repositories);
248 * Method returns currently selected repository
250 * Selected repository is local (per user) settings.
253 * @return em_repository repository instance that is currently selected by a BE user
254 * @see setSelectedRepository()
256 public function getSelectedRepository() {
257 return t3lib_div
::makeInstance('tx_em_Repository', $this->settings
['selectedRepository']);
261 * Method sets currently selected repository.
263 * Selected repository is local (per user) settings.
265 * @todo STUB, implementation missing
267 * @param em_repository $repository repository instance that is currently selected by a BE user
268 * @see getSelectedRepository()
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