[TASK] Re-work/simplify copyright header in PHP files - Part 2
[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
19 /**
20 * Misc utility.
21 *
22 * @author Xavier Perseguers <xavier@typo3.org>
23 */
24 class MiscUtility {
25
26 /**
27 * Returns meta-data for a given extension.
28 *
29 * @param string $extensionKey
30 * @return array
31 */
32 static public function getExtensionMetaData($extensionKey) {
33 $_EXTKEY = $extensionKey;
34 $EM_CONF = array();
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 static public function getIcon($documentKey) {
58 $basePath = 'typo3conf/Documentation/';
59 $documentPath = $basePath . $documentKey . '/';
60
61 // Fallback icon
62 $icon = ExtensionManagementUtility::siteRelPath('documentation') . 'ext_icon.gif';
63
64 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($documentKey, 'typo3cms.extensions.')) {
65 // Standard extension icon
66 $extensionKey = substr($documentKey, 20);
67 if (ExtensionManagementUtility::isLoaded($extensionKey)) {
68 $extensionPath = ExtensionManagementUtility::extPath($extensionKey);
69 $siteRelativePath = ExtensionManagementUtility::siteRelPath($extensionKey);
70 $icon = $siteRelativePath . ExtensionManagementUtility::getExtensionIcon($extensionPath);
71 }
72 } elseif (is_file(PATH_site . $documentPath . 'icon.png')) {
73 $icon = $documentPath . 'icon.png';
74 } elseif (is_file(PATH_site . $documentPath . 'icon.gif')) {
75 $icon = $documentPath . 'icon.gif';
76 }
77
78 return $icon;
79 }
80
81 }