[FEATURE] Allow ext_icon.png as extension icon besides ext_icon.gif
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / List.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012
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 /**
29 * Utility for dealing with extension list related functions
30 *
31 * @author Susanne Moog <typo3@susannemoog.de>
32 * @package Extension Manager
33 * @subpackage Utility
34 */
35 class Tx_Extensionmanager_Utility_List implements t3lib_Singleton {
36
37 /**
38 * @var Tx_Extbase_Object_ObjectManager
39 */
40 public $objectManager;
41
42 /**
43 * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
44 * @return void
45 */
46 public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
47 $this->objectManager = $objectManager;
48 }
49
50 /**
51 * @var Tx_Extensionmanager_Utility_EmConf
52 */
53 public $emConfUtility;
54
55 /**
56 * Inject emConfUtility
57 *
58 * @param Tx_Extensionmanager_Utility_EmConf $emConfUtility
59 * @return void
60 */
61 public function injectEmConfUtility(Tx_Extensionmanager_Utility_EmConf $emConfUtility) {
62 $this->emConfUtility = $emConfUtility;
63 }
64
65 /**
66 * @var Tx_Extensionmanager_Domain_Repository_ExtensionRepository
67 */
68 public $extensionRepository;
69
70 /**
71 * @var Tx_Extensionmanager_Utility_Install
72 */
73 protected $installUtility;
74
75 /**
76 * @param Tx_Extensionmanager_Utility_Install $installUtility
77 * @return void
78 */
79 public function injectInstallUtility(Tx_Extensionmanager_Utility_Install $installUtility) {
80 $this->installUtility = $installUtility;
81 }
82
83 /**
84 * Inject emConfUtility
85 *
86 * @param Tx_Extensionmanager_Domain_Repository_ExtensionRepository $extensionRepository
87 * @return void
88 */
89 public function injectExtensionRepository(Tx_Extensionmanager_Domain_Repository_ExtensionRepository $extensionRepository) {
90 $this->extensionRepository = $extensionRepository;
91 }
92 /**
93 * Returns the list of available (installed) extensions
94 *
95 * @return array Array with two sub-arrays, list array (all extensions with info) and category index
96 * @see getInstExtList()
97 */
98 public function getAvailableExtensions() {
99 $extensions = array();
100 $paths = Tx_Extensionmanager_Domain_Model_Extension::returnInstallPaths();
101 foreach ($paths as $installationType => $path) {
102 try {
103 if (is_dir($path)) {
104 $extList = t3lib_div::get_dirs($path);
105 if (is_array($extList)) {
106 foreach ($extList as $extKey) {
107 $extensions[$extKey] = array(
108 'siteRelPath' => str_replace(PATH_site, '', $path . $extKey),
109 'type' => $installationType,
110 'key' => $extKey,
111 'ext_icon' => t3lib_extMgm::getExtensionIcon( $path . $extKey . '/'),
112 );
113 }
114 }
115 }
116 } catch (Exception $e) {
117 t3lib_div::sysLog($e->getMessage(), 'extensionmanager');
118 }
119 }
120 return $extensions;
121 }
122
123 /**
124 * Reduce the available extensions list to only loaded extensions
125 *
126 * @param array $availableExtensions
127 * @return array
128 */
129 public function getAvailableAndInstalledExtensions(array $availableExtensions) {
130 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $properties) {
131 if (array_key_exists($extKey, $availableExtensions)) {
132 $availableExtensions[$extKey]['installed'] = TRUE;
133 }
134 }
135 return $availableExtensions;
136 }
137
138 /**
139 * Adds the information from the emconf array to the extension information
140 *
141 * @param array $extensions
142 * @return array
143 */
144 public function enrichExtensionsWithEmConfAndTerInformation(array $extensions) {
145 foreach ($extensions as $extensionKey => $properties) {
146 $emconf = $this->emConfUtility->includeEmConf($properties);
147 if ($emconf) {
148 $extensions[$extensionKey] = array_merge($emconf, $properties);
149 $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion(
150 $extensionKey,
151 $extensions[$extensionKey]['version']
152 );
153 if ($terObject instanceof Tx_Extensionmanager_Domain_Model_Extension) {
154 $extensions[$extensionKey]['terObject'] = $terObject;
155 $extensions[$extensionKey]['updateAvailable'] = $this->installUtility->isUpdateAvailable($terObject);
156 }
157
158 } else {
159 unset($extensions[$extensionKey]);
160 }
161 }
162 return $extensions;
163 }
164
165 /**
166 * Gets all available and installed extension with additional information
167 * from em_conf and TER (if available)
168 *
169 * @return array
170 */
171 public function getAvailableAndInstalledExtensionsWithAdditionalInformation() {
172 $availableExtensions = $this->getAvailableExtensions();
173 $availableAndInstalledExtensions = $this->getAvailableAndInstalledExtensions($availableExtensions);
174 return $this->enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
175 }
176 }
177
178 ?>