b58a7ca9497d153cba0523bb486f1dd201f177c3
[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 /**
28 * General utility.
29 *
30 * @author Xavier Perseguers <xavier@typo3.org>
31 */
32 class GeneralUtility {
33
34 /**
35 * Returns meta-data for a given extension.
36 *
37 * @param string $extensionKey
38 * @return array
39 */
40 static public function getExtensionMetaData($extensionKey) {
41 $_EXTKEY = $extensionKey;
42 $EM_CONF = array();
43 $extPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey);
44 include($extPath . 'ext_emconf.php');
45
46 $release = $EM_CONF[$_EXTKEY]['version'];
47 list($major, $minor, $_) = explode('.', $release, 3);
48 if (($pos = strpos($minor, '-')) !== FALSE) {
49 // $minor ~ '2-dev'
50 $minor = substr($minor, 0, $pos);
51 }
52 $EM_CONF[$_EXTKEY]['version'] = $major . '.' . $minor;
53 $EM_CONF[$_EXTKEY]['release'] = $release;
54 $EM_CONF[$_EXTKEY]['extensionKey'] = $extensionKey;
55
56 return $EM_CONF[$_EXTKEY];
57 }
58
59 /**
60 * Returns the icon associated to a given document key.
61 *
62 * @param string $documentKey
63 * @return string
64 */
65 static public function getIcon($documentKey) {
66 $basePath = 'typo3conf/Documentation/';
67 $documentPath = $basePath . $documentKey . '/';
68
69 // Fallback icon
70 $icon = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('documentation') . 'ext_icon.gif';
71
72 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($documentKey, 'typo3cms.extensions.')) {
73 // Standard extension icon
74 $extensionKey = substr($documentKey, 20);
75 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extensionKey)) {
76 $icon = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($extensionKey) . 'ext_icon.gif';
77 }
78 } elseif (is_file(PATH_site . $documentPath . 'icon.png')) {
79 $icon = $documentPath . 'icon.png';
80 } elseif (is_file(PATH_site . $documentPath . 'icon.gif')) {
81 $icon = $documentPath . 'icon.gif';
82 }
83
84 return $icon;
85 }
86
87 }