TYPO3 API  SVNRelease
class.tx_em_settings.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010 Steffen Kamper (info@sk-typo3.de)
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 /**
00028  * Module: Extension manager, developer module
00029  *
00030  * $Id: class.tx_em_settings.php 2089 2010-03-22 12:03:25Z steffenk $
00031  *
00032  * @author  Steffen Kamper <info@sk-typo3.de>
00033  */
00034 
00035 
00036 $GLOBALS['LANG']->includeLLFile(t3lib_extMgm::extPath('em', 'language/locallang.xml'));
00037 
00038 
00039 class tx_em_Settings implements t3lib_Singleton {
00040 
00041     public $MOD_MENU = array(); // Module menu items
00042 
00043 
00044     /**
00045      * Settings array
00046      *
00047      * @var array
00048      */
00049     protected $settings;
00050 
00051 
00052     /**
00053      * Constructor
00054      *
00055      */
00056     public function __construct() {
00057         $this->readSettings();
00058     }
00059 
00060     /**
00061      * Get settings
00062      */
00063     public function getSettings() {
00064         return $this->settings;
00065     }
00066 
00067     /**
00068      * Get user Settings
00069      */
00070     public function getUserSettings() {
00071         $userSettings = t3lib_beFunc::getModTSconfig(0, 'mod.tools_em');
00072         return $userSettings['properties'];
00073     }
00074 
00075     /**
00076      * Save user settings
00077      *
00078      * @param array $settings
00079      */
00080     public function saveSettings($settings) {
00081         $this->settings = t3lib_BEfunc::getModuleData($this->MOD_MENU, $settings, 'tools_em');
00082         return $this->settings;
00083     }
00084 
00085     /**
00086      * Save single value in session settings
00087      *
00088      * @param string $name
00089      * @param string $value
00090      */
00091     public function saveSetting($name, $value) {
00092         t3lib_BEfunc::getModuleData($this->MOD_MENU, array($name => $value), 'tools_em');
00093     }
00094 
00095     /**
00096      * Initial settings for extension manager module data
00097      *
00098      * @return void
00099      */
00100     protected function readSettings() {
00101         $globalSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
00102         if (!is_array($globalSettings)) {
00103             $globalSettings = array(
00104                 'displayMyExtensions' => 0,
00105                 'selectedLanguages' => array(),
00106                 'inlineToWindow' => 1,
00107             );
00108         }
00109         $this->MOD_MENU = array(
00110             'function' => array(
00111                 'loaded_list' => $GLOBALS['LANG']->getLL('menu_loaded_extensions'),
00112                 'installed_list' => $GLOBALS['LANG']->getLL('menu_install_extensions'),
00113                 'import' => $GLOBALS['LANG']->getLL('menu_import_extensions'),
00114                 'translations' => $GLOBALS['LANG']->getLL('menu_translation_handling'),
00115                 'settings' => $GLOBALS['LANG']->getLL('menu_settings'),
00116                 'extensionmanager' => $GLOBALS['LANG']->getLL('header'),
00117                 'updates' => $GLOBALS['LANG']->getLL('menu_extension_updates'),
00118             ),
00119             'listOrder' => array(
00120                 'cat' => $GLOBALS['LANG']->getLL('list_order_category'),
00121                 'author_company' => $GLOBALS['LANG']->getLL('list_order_author'),
00122                 'state' => $GLOBALS['LANG']->getLL('list_order_state'),
00123                 'type' => $GLOBALS['LANG']->getLL('list_order_type'),
00124             ),
00125             'display_details' => array(
00126                 1 => $GLOBALS['LANG']->getLL('show_details'),
00127                 0 => $GLOBALS['LANG']->getLL('show_description'),
00128                 2 => $GLOBALS['LANG']->getLL('show_more_details'),
00129 
00130                 3 => $GLOBALS['LANG']->getLL('show_technical'),
00131                 4 => $GLOBALS['LANG']->getLL('show_validating'),
00132                 5 => $GLOBALS['LANG']->getLL('show_changed'),
00133             ),
00134             'display_shy' => '',
00135             'display_own' => '',
00136             'display_obsolete' => '',
00137             'display_installed' => '',
00138             'display_files' => '',
00139             'hide_shy' => 0,
00140             'hide_obsolete' => 0,
00141 
00142 
00143             'singleDetails' => array(
00144                 'info' => $GLOBALS['LANG']->getLL('details_info'),
00145                 'edit' => $GLOBALS['LANG']->getLL('details_edit'),
00146                 'backup' => $GLOBALS['LANG']->getLL('details_backup_delete'),
00147                 'dump' => $GLOBALS['LANG']->getLL('details_dump_db'),
00148                 'upload' => $GLOBALS['LANG']->getLL('details_upload'),
00149                 'updateModule' => $GLOBALS['LANG']->getLL('details_update'),
00150             ),
00151             'fe_u' => '',
00152             'fe_p' => '',
00153 
00154             'mirrorListURL' => '',
00155             'rep_url' => '',
00156             'extMirrors' => '',
00157 
00158             // returns uid of currently selected repository
00159             // default and hardcoded: 1 = TYPO3.org
00160             'selectedRepository' => '1',
00161             'selectedMirror' => '0',
00162 
00163             'selectedLanguages' => '',
00164 
00165             'mainTab' => '0',
00166         );
00167         $this->settings = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), 'tools_em');
00168         $this->settings = array_merge($this->settings, $globalSettings);
00169     }
00170 
00171     /**
00172      * Gets url for mirror
00173      *
00174      * @return string
00175      */
00176     public function getMirrorURL() {
00177         if (strlen($this->settings['rep_url'])) {
00178             return $this->settings['rep_url'];
00179         }
00180 
00181         $mirrors = unserialize($this->settings['extMirrors']);
00182 
00183         if(!is_array($mirrors)) {
00184             if ($this->settings['selectedRepository'] < 1) {
00185                 $this->settings['selectedRepository'] = 1;
00186             }
00187         }
00188             /** @var $repository tx_em_Repository */
00189             $repository = t3lib_div::makeInstance('tx_em_Repository', $this->settings['selectedRepository']);
00190             if ($repository->getMirrorListUrl()) {
00191             $objRepositoryUtility = t3lib_div::makeInstance('tx_em_Repository_Utility', $repository);
00192             $mirrors = $objRepositoryUtility->getMirrors(TRUE)->getMirrors();
00193             if(!is_array($mirrors)) {
00194                 return FALSE;
00195             } else {
00196                 $this->settings['extMirrors'] = serialize($mirrors);
00197                 $this->saveSetting('extMirrors', $this->settings['extMirrors']);
00198             }
00199         }
00200         if (!$this->settings['selectedMirror']) {
00201             $rand = array_rand($mirrors);
00202             $url = 'http://' . $mirrors[$rand]['host'] . $mirrors[$rand]['path'];
00203         }
00204         else {
00205             $url = 'http://' . $mirrors[$this->settings['selectedMirror']]['host'] . $mirrors[$this->settings['selectedMirror']]['path'];
00206         }
00207 
00208         return $url;
00209     }
00210 
00211     /**
00212      * Method returns registered extension repositories.
00213      *
00214      * Registered repositories are global (per installation) settings.
00215      *
00216      * @access  public
00217      * @return  array of {@link em_repository em_repository} instances
00218      * @see  registerDefaultRepository(), setRegisteredRepositories()
00219      */
00220     public function getRegisteredRepositories() {
00221         $registry = t3lib_div::makeInstance('t3lib_Registry');
00222         $regRepos = $registry->get('core', 'em.repositories.registered');
00223 
00224         // create default entry if there wasn't one
00225         if (empty($regRepos)) {
00226             $this->registerDefaultRepository();
00227             $regRepos = $registry->get('core', 'em.repositories.registered');
00228         }
00229 
00230         return $regRepos;
00231     }
00232 
00233     /**
00234      * Method creates default registered repositories entry.
00235      *
00236      * @access  protected
00237      * @return  void
00238      * @see  getRegisteredRepository(), setRegisteredRepositories()
00239      */
00240     protected function registerDefaultRepository() {
00241         $registry = t3lib_div::makeInstance('t3lib_Registry');
00242         $defaultRepo = t3lib_div::makeInstance('tx_em_Repository');
00243         $registry->set('core', 'em.repositories.registered', array($defaultRepo));
00244     }
00245 
00246     /**
00247      * Method sets (persists) registered repositories.
00248      *
00249      * Registered repositories are global (per installation) settings.
00250      *
00251      * @access  public
00252      * @param   array  $repositories  array of {@link em_repository em_repository} instances
00253      * @see  registerDefaultRepository(), setRegisteredRepositories()
00254      * @throws  InvalidArgumentException in case argument contains no instances of {@link em_repository em_repository}
00255      */
00256     public function setRegisteredRepositories(array $repositories) {
00257         // removing mirror instances
00258         foreach ($repositories as $repository) {
00259             if ($repository instanceof em_repository) {
00260                 $repository->removeMirrors();
00261             } else {
00262                 throw new InvalidArgumentException(get_class($this) . ': ' . 'No valid instances of em_repository given.');
00263             }
00264         }
00265         if (count($repositories)) {
00266             $registry = t3lib_div::makeInstance('t3lib_Registry');
00267             $registry->set('core', 'em.repositories.registered', $repositories);
00268         }
00269     }
00270 
00271     /**
00272      * Method returns currently selected repository
00273      *
00274      * Selected repository is local (per user) settings.
00275      *
00276      * @access  public
00277      * @return  em_repository  repository instance that is currently selected by a BE user
00278      * @see  setSelectedRepository()
00279      */
00280     public function getSelectedRepository() {
00281         return t3lib_div::makeInstance('tx_em_Repository', $this->settings['selectedRepository']);
00282     }
00283 
00284     /**
00285      * Method sets currently selected repository.
00286      *
00287      * Selected repository is local (per user) settings.
00288      *
00289      * @todo    STUB, implementation missing
00290      * @access  public
00291      * @param   em_repository  $repository  repository instance that is currently selected by a BE user
00292      * @see  getSelectedRepository()
00293      */
00294     public function setSelectedRepository(em_repository $repository) {
00295         // this method would set sth. like "REPOSITORY_TITLE:INT" in a setting field
00296         // REPOSITORY_TITLE = example: main
00297         // INT = 0 means randomly selected mirror, >0 selects specific mirror
00298     }
00299 
00300 }
00301 
00302 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/settings/class.tx_em_settings.php'])) {
00303     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/repository/class.tx_em_settings.php']);
00304 }
00305 
00306 ?>