ddcccd42c7cdbf56718406fa3a3ac6bd0a8b74ca
[Packages/TYPO3.CMS.git] / typo3 / sysext / documentation / Classes / Utility / MiscUtility.php
1 <?php
2 namespace TYPO3\CMS\Documentation\Utility;
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\PathUtility;
19
20 /**
21 * Misc utility.
22 */
23 class MiscUtility
24 {
25 /**
26 * Returns meta-data for a given extension.
27 *
28 * @param string $extensionKey
29 * @return array
30 */
31 public static function getExtensionMetaData($extensionKey)
32 {
33 $_EXTKEY = $extensionKey;
34 $EM_CONF = [];
35 $extPath = ExtensionManagementUtility::extPath($extensionKey);
36 include $extPath . 'ext_emconf.php';
37
38 $release = $EM_CONF[$_EXTKEY]['version'];
39 list($major, $minor, $_) = explode('.', $release, 3);
40 if (($pos = strpos($minor, '-')) !== false) {
41 // $minor ~ '2-dev'
42 $minor = substr($minor, 0, $pos);
43 }
44 $EM_CONF[$_EXTKEY]['version'] = $major . '.' . $minor;
45 $EM_CONF[$_EXTKEY]['release'] = $release;
46 $EM_CONF[$_EXTKEY]['extensionKey'] = $extensionKey;
47
48 return $EM_CONF[$_EXTKEY];
49 }
50
51 /**
52 * Returns the icon associated to a given document key.
53 *
54 * @param string $documentKey
55 * @return string
56 */
57 public static function getIcon($documentKey)
58 {
59 $basePath = 'typo3conf/Documentation/';
60 $documentPath = $basePath . $documentKey . '/';
61
62 // Fallback icon
63 $icon = ExtensionManagementUtility::getExtensionIcon(ExtensionManagementUtility::extPath('documentation'), true);
64 $icon = PathUtility::stripPathSitePrefix($icon);
65
66 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($documentKey, 'typo3cms.extensions.')) {
67 // Standard extension icon
68 $extensionKey = substr($documentKey, 20);
69 if (ExtensionManagementUtility::isLoaded($extensionKey)) {
70 $extensionPath = ExtensionManagementUtility::extPath($extensionKey);
71 $icon = ExtensionManagementUtility::getExtensionIcon($extensionPath, true);
72 $icon = PathUtility::stripPathSitePrefix($icon);
73 }
74 } elseif (is_file(PATH_site . $documentPath . 'icon.png')) {
75 $icon = $documentPath . 'icon.png';
76 } elseif (is_file(PATH_site . $documentPath . 'icon.gif')) {
77 $icon = $documentPath . 'icon.gif';
78 }
79
80 return $icon;
81 }
82 }