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