Documentation.php 2.92 KB
Newer Older
1
<?php
2
3
namespace T3o\TerFe2\Service;

flyguide's avatar
flyguide committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*******************************************************************
 *  Copyright notice
 *
 *  (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
 *
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ******************************************************************/

/**
 * Service to handle documentations
30
31
32
 *
 * @package TerFe2
 * @author Thomas Löffler <thomas.loeffler@typo3.org>
flyguide's avatar
flyguide committed
33
 */
34
class Documentation implements \TYPO3\CMS\Core\SingletonInterface
35
{
36

37
38
39
40
    /**
     * @var string
     */
    protected $baseUrl = '';
41

42
43
44
45
    /**
     * @var array
     */
    protected $availableFormats = array();
46

47
48
49
50
    /**
     * @var string
     */
    protected $docsInformation = NULL;
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    /**
     * Initialize the service
     */
    public function __construct()
    {
        $this->baseUrl = 'https://docs.typo3.org/typo3cms/extensions/';
        $this->availableFormats = array(
            'sxw',
            'html',
            'rst',
            'pdf'
        );
        $documentationFile = PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentdocumentationdata.json';
        $this->docsInformation = json_decode(file_get_contents($documentationFile));
    }
67
68


69
70
71
72
73
74
75
76
77
78
79
    /**
     * Get documentation link
     *
     * @throws Exception
     * @param string $extensionKey Extension key
     * @param string $versionString Version string
     * @return string|NULL HTML link to the documentation
     */
    public function getDocumentationLink($extensionKey, $versionString)
    {
        if (empty($extensionKey) || empty($versionString)) {
80
            throw new \Exception('Extension key and version string are required to build a documentation url');
81
        }
82

83
84
        $manualExists = isset($this->docsInformation->$extensionKey);
        $documentationLink = NULL;
85

86
87
88
89
        if ($manualExists) {
            // link to extension to get the latest manual
            $url = $this->baseUrl . $extensionKey . '/';
            // check if link is not broken
90
            if (strpos(\TYPO3\CMS\Core\Utility\GeneralUtility::getURL($url, 2), 'HTTP/1.1 200 OK') !== FALSE) {
91
92
93
                $documentationLink = '<a href="' . $url . '">Extension Manual</a>';
            }
        }
94

95
96
        return $documentationLink;
    }
flyguide's avatar
flyguide committed
97
}