xref: /plugin/siteexport/inc/javahelp.php (revision a8c17ab5b37308343f86651acb8c4a1b3f36f0ae)
17d101cc1SGerry Weißbach<?php
27d101cc1SGerry Weißbach
37d101cc1SGerry Weißbachif (!defined('DOKU_PLUGIN')) die('meh');
47d101cc1SGerry Weißbachrequire_once(DOKU_PLUGIN . 'siteexport/inc/toc.php');
57d101cc1SGerry Weißbach
67d101cc1SGerry Weißbachclass siteexport_javahelp
77d101cc1SGerry Weißbach{
87d101cc1SGerry Weißbach    private $functions = null;
97d101cc1SGerry Weißbach    private $translation = null;
107d101cc1SGerry Weißbach    private $filewriter = null;
11a0726238SGerry Weißbach    private $NS = null;
127d101cc1SGerry Weißbach
137d101cc1SGerry Weißbach    private $tocName = 'toc.xml';
147d101cc1SGerry Weißbach    private $mapName = 'map.xml';
157d101cc1SGerry Weißbach
160571ece2SScrutinizer Auto-Fixer    /**
170571ece2SScrutinizer Auto-Fixer     * @param siteexport_functions $functions
180571ece2SScrutinizer Auto-Fixer     * @param siteexport_zipfilewriter $filewriter
190571ece2SScrutinizer Auto-Fixer     */
20b324a190SMichael Hamann    public function __construct($functions, $filewriter, $NS)
217d101cc1SGerry Weißbach    {
22a0726238SGerry Weißbach        $this->NS = $NS;
237d101cc1SGerry Weißbach        $this->functions = $functions;
247d101cc1SGerry Weißbach        $this->filewriter = $filewriter;
253bda080dSGerry Weißbach        $translation = plugin_load('helper', 'autotranslation');
263bda080dSGerry Weißbach        $this->translation = &$translation;
277d101cc1SGerry Weißbach    }
287d101cc1SGerry Weißbach
297d101cc1SGerry Weißbach    public function createTOCFiles($data)
307d101cc1SGerry Weißbach    {
31c65f2532SGerry Weißbach        global $conf, $ID;
327d101cc1SGerry Weißbach
337d101cc1SGerry Weißbach        // Split Tree for translation
347d101cc1SGerry Weißbach        $translationHSFiles = array();
357d101cc1SGerry Weißbach
36*a8c17ab5Si-net /// software        for ($i = count($data); $i >= 0; $i--)
377d101cc1SGerry Weißbach        {
387d101cc1SGerry Weißbach            $lang = '';
397d101cc1SGerry Weißbach            if ($this->translation)
407d101cc1SGerry Weißbach            {
4176ba6c82SGerry Weißbach                $this->translation->translationsNs = $this->translation->setupTNS($data[$i]['id']);
427d101cc1SGerry Weißbach                $lang = $this->translation->getLangPart($data[$i]['id']);
4376ba6c82SGerry Weißbach                $this->functions->debug->message("Setting up translation:", array(
4476ba6c82SGerry Weißbach                    'id' => $data[$i]['id'],
4576ba6c82SGerry Weißbach                    'tns' => $this->translation->translationsNs,
4676ba6c82SGerry Weißbach                    'lang' => $lang
4776ba6c82SGerry Weißbach                ), 3);
487d101cc1SGerry Weißbach            }
497d101cc1SGerry Weißbach
507d101cc1SGerry Weißbach            // get all the relative URLs
517d101cc1SGerry Weißbach            $translationHSFiles[$lang][] = $data[$i];
527d101cc1SGerry Weißbach        }
537d101cc1SGerry Weißbach
54a0726238SGerry Weißbach        $toc = new siteexport_toc($this->functions, $this->NS);
55a0726238SGerry Weißbach        // +":" at the end becaus this is already a namespace
5676ba6c82SGerry Weißbach        $baseNameSpace = str_replace('/', ':', $this->translation && !empty($this->translation->translationsNs) ? $this->translation->translationsNs : $this->NS . ':');
57a0726238SGerry Weißbach        $translationRoot = curNS($baseNameSpace);
58a0726238SGerry Weißbach        $hsPrename = curNS(getNS($baseNameSpace));
59c65f2532SGerry Weißbach
6013326eabSGerry Weißbach        $this->functions->debug->message("HelpSetPre-Name: {$hsPrename}", null, 3);
6113326eabSGerry Weißbach        $this->functions->debug->message("Translation-Root: {$translationRoot}", null, 3);
6213326eabSGerry Weißbach        $this->functions->debug->message("HSFiles:", $translationHSFiles, 1);
6313326eabSGerry Weißbach
64*a8c17ab5Si-net /// software        $last_key = end((array_keys($translationHSFiles)));
6513326eabSGerry Weißbach
667d101cc1SGerry Weißbach        foreach ($translationHSFiles as $lang => $data)
677d101cc1SGerry Weißbach        {
687d101cc1SGerry Weißbach            // Prepare Translations
6913326eabSGerry Weißbach            if (!empty($lang) && !$this->functions->settings->TOCMapWithoutTranslation)
707d101cc1SGerry Weißbach            {
717d101cc1SGerry Weißbach                $toc->translation = &$this->translation;
7276ba6c82SGerry Weißbach                $rootNode = cleanID($this->translation->translationsNs . $lang) . ':';
737d101cc1SGerry Weißbach            } else {
747d101cc1SGerry Weißbach                $toc->translation = null;
757d101cc1SGerry Weißbach                $rootNode = '';
767d101cc1SGerry Weißbach            }
777d101cc1SGerry Weißbach
78f37dfca9SGerry Weißbach            $tsRootPath = $hsPrename . '/' . $this->translationRootPath($translationRoot);
7913326eabSGerry Weißbach            $this->functions->debug->message("Generating JavaHelpDocZip for language '$lang'", $tsRootPath, 3);
807d101cc1SGerry Weißbach
817d101cc1SGerry Weißbach            // Create toc and map for each lang
82a0726238SGerry Weißbach            list($tocData, $mapData, $startPageID) = $toc->__getJavaHelpTOCXML($data);
83a0726238SGerry Weißbach            $this->filewriter->__moveDataToZip($tocData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->tocName);
84a0726238SGerry Weißbach            $this->filewriter->__moveDataToZip($mapData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->mapName);
857d101cc1SGerry Weißbach
867d101cc1SGerry Weißbach            // Create HS File
877d101cc1SGerry Weißbach            $HS = $this->getHSXML($startPageID, $this->functions->getSiteTitle($rootNode), $lang, $tsRootPath);
88f5fb7cd8SGerry Weißbach            $this->filewriter->__moveDataToZip($HS, $translationRoot . (empty($lang) ? '' : '_' . $lang) . '.hs');
897d101cc1SGerry Weißbach
907d101cc1SGerry Weißbach            // Default Lang
9113326eabSGerry Weißbach            if ($lang == $this->functions->settings->defaultLang || $lang == $last_key)
927d101cc1SGerry Weißbach            {
9313326eabSGerry Weißbach                $this->functions->debug->message("Writing Default HS File for Language:", $lang, 3);
94f37dfca9SGerry Weißbach                $this->filewriter->__moveDataToZip($HS, $translationRoot . '.hs');
95a9052036SGerry Weißbach                $last_key = null;
967d101cc1SGerry Weißbach            }
977d101cc1SGerry Weißbach        }
983bda080dSGerry Weißbach
993bda080dSGerry Weißbach        $toc->debug("THE END", true);
1007d101cc1SGerry Weißbach    }
1017d101cc1SGerry Weißbach
1027d101cc1SGerry Weißbach    private function translationRootPath($translationRoot = '')
1037d101cc1SGerry Weißbach    {
1047d101cc1SGerry Weißbach        if (!empty($translationRoot))
1057d101cc1SGerry Weißbach        {
1067d101cc1SGerry Weißbach            return $translationRoot . '/';
1077d101cc1SGerry Weißbach        }
1087d101cc1SGerry Weißbach
1097d101cc1SGerry Weißbach        return $translationRoot;
1107d101cc1SGerry Weißbach    }
1117d101cc1SGerry Weißbach
1127d101cc1SGerry Weißbach    private function getHSXML($rootID, $title, $lang = '', $translationRoot = '')
1137d101cc1SGerry Weißbach    {
114a0726238SGerry Weißbach        if (empty($lang) && substr($translationRoot, -1) != '/') {
115a0726238SGerry Weißbach            $translationRoot .= '/';
1160d8ab758SGerry Weißbach        } else if (!empty($lang) && substr($lang, -1) != '/') {
11783d0ebf7SGerry Weißbach            $lang .= '/';
118a9052036SGerry Weißbach        }
1190d8ab758SGerry Weißbach
1207d101cc1SGerry Weißbach        return <<<OUTPUT
1217d101cc1SGerry Weißbach<?xml version='1.0' encoding='ISO-8859-1' ?>
1227d101cc1SGerry Weißbach<helpset version="1.0">
1237d101cc1SGerry Weißbach
1247d101cc1SGerry Weißbach    <title>{$title}</title>
1257d101cc1SGerry Weißbach    <maps>
1267d101cc1SGerry Weißbach        <homeID>{$rootID}</homeID>
12783d0ebf7SGerry Weißbach        <mapref location="{$translationRoot}{$lang}{$this->mapName}"/>
1287d101cc1SGerry Weißbach     </maps>
1297d101cc1SGerry Weißbach
1307d101cc1SGerry Weißbach    <view>
1317d101cc1SGerry Weißbach        <name>TOC</name>
1327d101cc1SGerry Weißbach        <label>{$this->functions->getLang('toc')}</label>
1337d101cc1SGerry Weißbach        <type>javax.help.TOCView</type>
13483d0ebf7SGerry Weißbach        <data>{$translationRoot}{$lang}{$this->tocName}</data>
1357d101cc1SGerry Weißbach    </view>
1367d101cc1SGerry Weißbach
1377d101cc1SGerry Weißbach    <view>
1387d101cc1SGerry Weißbach        <name>Search</name>
1397d101cc1SGerry Weißbach        <label>{$this->functions->getLang('search')}</label>
1407d101cc1SGerry Weißbach        <type>javax.help.SearchView</type>
1417d101cc1SGerry Weißbach        <data engine="com.sun.java.help.search.DefaultSearchEngine">
14283d0ebf7SGerry Weißbach            {$translationRoot}{$lang}JavaHelpSearch
1437d101cc1SGerry Weißbach        </data>
1447d101cc1SGerry Weißbach    </view>
1457d101cc1SGerry Weißbach
1467d101cc1SGerry Weißbach    <impl>
1477d101cc1SGerry Weißbach        <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" />
1487d101cc1SGerry Weißbach        <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" />
1497d101cc1SGerry Weißbach    </impl>
1507d101cc1SGerry Weißbach</helpset>
1517d101cc1SGerry WeißbachOUTPUT;
1527d101cc1SGerry Weißbach    }
1537d101cc1SGerry Weißbach}
154