[BUGFIX] EXT:documentation does not support ext_icon.png
[Packages/TYPO3.CMS.git] / typo3 / sysext / documentation / Classes / Utility / GeneralUtility.php
1 <?php
2 namespace TYPO3\CMS\Documentation\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Xavier Perseguers <xavier@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
28
29 /**
30 * General utility.
31 *
32 * @author Xavier Perseguers <xavier@typo3.org>
33 */
34 class GeneralUtility {
35
36 /**
37 * Returns meta-data for a given extension.
38 *
39 * @param string $extensionKey
40 * @return array
41 */
42 static public function getExtensionMetaData($extensionKey) {
43 $_EXTKEY = $extensionKey;
44 $EM_CONF = array();
45 $extPath = ExtensionManagementUtility::extPath($extensionKey);
46 include($extPath . 'ext_emconf.php');
47
48 $release = $EM_CONF[$_EXTKEY]['version'];
49 list($major, $minor, $_) = explode('.', $release, 3);
50 if (($pos = strpos($minor, '-')) !== FALSE) {
51 // $minor ~ '2-dev'
52 $minor = substr($minor, 0, $pos);
53 }
54 $EM_CONF[$_EXTKEY]['version'] = $major . '.' . $minor;
55 $EM_CONF[$_EXTKEY]['release'] = $release;
56 $EM_CONF[$_EXTKEY]['extensionKey'] = $extensionKey;
57
58 return $EM_CONF[$_EXTKEY];
59 }
60
61 /**
62 * Returns the icon associated to a given document key.
63 *
64 * @param string $documentKey
65 * @return string
66 */
67 static public function getIcon($documentKey) {
68 $basePath = 'typo3conf/Documentation/';
69 $documentPath = $basePath . $documentKey . '/';
70
71 // Fallback icon
72 $icon = ExtensionManagementUtility::siteRelPath('documentation') . 'ext_icon.gif';
73
74 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($documentKey, 'typo3cms.extensions.')) {
75 // Standard extension icon
76 $extensionKey = substr($documentKey, 20);
77 if (ExtensionManagementUtility::isLoaded($extensionKey)) {
78 $extensionPath = ExtensionManagementUtility::extPath($extensionKey);
79 $siteRelativePath = ExtensionManagementUtility::siteRelPath($extensionKey);
80 $icon = $siteRelativePath . ExtensionManagementUtility::getExtensionIcon($extensionPath);
81 }
82 } elseif (is_file(PATH_site . $documentPath . 'icon.png')) {
83 $icon = $documentPath . 'icon.png';
84 } elseif (is_file(PATH_site . $documentPath . 'icon.gif')) {
85 $icon = $documentPath . 'icon.gif';
86 }
87
88 return $icon;
89 }
90
91 }