[BUGFIX] Don't download language packs of not loaded extensions
[Packages/TYPO3.CMS.git] / typo3 / sysext / lang / Classes / Domain / Repository / ExtensionRepository.php
1 <?php
2 namespace TYPO3\CMS\Lang\Domain\Repository;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Core\Utility\PathUtility;
20 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
21 use TYPO3\CMS\Extensionmanager\Utility\ListUtility;
22 use TYPO3\CMS\Lang\Domain\Model\Extension;
23
24 /**
25 * Extension repository
26 */
27 class ExtensionRepository
28 {
29 /**
30 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
31 */
32 protected $objectManager;
33
34 /**
35 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
36 */
37 protected $listUtility;
38
39 /**
40 * @var array
41 */
42 protected $extensions = [];
43
44 /**
45 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
46 */
47 public function injectObjectManager(ObjectManagerInterface $objectManager)
48 {
49 $this->objectManager = $objectManager;
50 }
51
52 /**
53 * @param \TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility
54 */
55 public function injectListUtility(ListUtility $listUtility)
56 {
57 $this->listUtility = $listUtility;
58 }
59
60 /**
61 * Returns all objects of this repository
62 *
63 * @return array The extensions
64 */
65 public function findAll()
66 {
67 if (empty($this->extensions)) {
68 $extensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
69 foreach ($extensions as $entry) {
70 if (empty($entry['installed']) || $entry['installed'] !== true) {
71 continue;
72 }
73 /** @var $extension \TYPO3\CMS\Lang\Domain\Model\Extension */
74 $extension = $this->objectManager->get(
75 Extension::class,
76 $entry['key'],
77 $entry['title'],
78 $this->getExtensionIconWithPath($entry)
79 );
80 $extension->setVersionFromString($entry['version']);
81 if ($entry['ext_icon_width'] > 0) {
82 $extension->setIconWidth($entry['ext_icon_width']);
83 }
84 if ($entry['ext_icon_height'] > 0) {
85 $extension->setIconHeight($entry['ext_icon_height']);
86 }
87
88 $this->extensions[$entry['key']] = $extension;
89 }
90 ksort($this->extensions);
91 }
92 return $this->extensions;
93 }
94
95 /**
96 * Counts all objects of this repository
97 *
98 * @return int The extension count
99 */
100 public function countAll()
101 {
102 $extensions = $this->findAll();
103 return count($extensions);
104 }
105
106 /**
107 * Find one extension by offset
108 *
109 * @param int $offset The offset
110 * @return \TYPO3\CMS\Lang\Domain\Model\Extension The extension
111 */
112 public function findOneByOffset($offset)
113 {
114 $extensions = $this->findAll();
115 $extensions = array_values($extensions);
116 $offset = (int)$offset;
117 if (!empty($extensions[$offset])) {
118 return $extensions[$offset];
119 }
120 return null;
121 }
122
123 /**
124 * Returns the extension icon
125 *
126 * @param array $extensionEntry
127 * @return string
128 */
129 protected function getExtensionIconWithPath($extensionEntry)
130 {
131 $extensionIcon = $GLOBALS['TYPO3_LOADED_EXT'][$extensionEntry['key']]['ext_icon'];
132 if (empty($extensionIcon)) {
133 $extensionIcon = ExtensionManagementUtility::getExtensionIcon(PATH_site . $extensionEntry['siteRelPath'] . '/');
134 }
135 if (empty($extensionIcon)) {
136 $extensionIcon = GeneralUtility::getFileAbsFileName('EXT:core/Resources/Public/Icons/Extension.png');
137 $extensionIcon = PathUtility::stripPathSitePrefix($extensionIcon);
138 } else {
139 $extensionIcon = '../' . $extensionEntry['siteRelPath'] . '/' . $extensionIcon;
140 }
141 return $extensionIcon;
142 }
143 }