xref: /plugin/siteexport/inc/javahelp.php (revision 3bda080d2216a97ca639125c1aac190a8201d0ce)
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;
25*3bda080dSGerry Weißbach        $translation = plugin_load('helper', 'autotranslation');
26*3bda080dSGerry 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
367d101cc1SGerry Weißbach        for ($i = 0; $i < count($data); $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
647d101cc1SGerry Weißbach        $check = array();
65a9052036SGerry Weißbach        $last_key = end(array_keys($translationHSFiles));
6613326eabSGerry Weißbach
677d101cc1SGerry Weißbach        foreach ($translationHSFiles as $lang => $data)
687d101cc1SGerry Weißbach        {
697d101cc1SGerry Weißbach            // Prepare Translations
7013326eabSGerry Weißbach            if (!empty($lang) && !$this->functions->settings->TOCMapWithoutTranslation)
717d101cc1SGerry Weißbach            {
727d101cc1SGerry Weißbach                $toc->translation = &$this->translation;
7376ba6c82SGerry Weißbach                $rootNode = cleanID($this->translation->translationsNs . $lang) . ':';
747d101cc1SGerry Weißbach            } else {
757d101cc1SGerry Weißbach                $toc->translation = null;
767d101cc1SGerry Weißbach                $rootNode = '';
777d101cc1SGerry Weißbach            }
787d101cc1SGerry Weißbach
79f37dfca9SGerry Weißbach            $tsRootPath = $hsPrename . '/' . $this->translationRootPath($translationRoot);
8013326eabSGerry Weißbach            $this->functions->debug->message("Generating JavaHelpDocZip for language '$lang'", $tsRootPath, 3);
817d101cc1SGerry Weißbach
827d101cc1SGerry Weißbach            // Create toc and map for each lang
83a0726238SGerry Weißbach            list($tocData, $mapData, $startPageID) = $toc->__getJavaHelpTOCXML($data);
84a0726238SGerry Weißbach            $this->filewriter->__moveDataToZip($tocData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->tocName);
85a0726238SGerry Weißbach            $this->filewriter->__moveDataToZip($mapData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->mapName);
867d101cc1SGerry Weißbach
877d101cc1SGerry Weißbach            // Create HS File
887d101cc1SGerry Weißbach            // array_shift($toc->getMapID($rootNode, &$check))
897d101cc1SGerry Weißbach            $HS = $this->getHSXML($startPageID, $this->functions->getSiteTitle($rootNode), $lang, $tsRootPath);
90f5fb7cd8SGerry Weißbach            $this->filewriter->__moveDataToZip($HS, $translationRoot . (empty($lang) ? '' : '_' . $lang) . '.hs');
917d101cc1SGerry Weißbach
927d101cc1SGerry Weißbach            // Default Lang
9313326eabSGerry Weißbach            if ($lang == $this->functions->settings->defaultLang || $lang == $last_key)
947d101cc1SGerry Weißbach            {
9513326eabSGerry Weißbach                $this->functions->debug->message("Writing Default HS File for Language:", $lang, 3);
96f37dfca9SGerry Weißbach                $this->filewriter->__moveDataToZip($HS, $translationRoot . '.hs');
97a9052036SGerry Weißbach                $last_key = null;
987d101cc1SGerry Weißbach            }
997d101cc1SGerry Weißbach        }
100*3bda080dSGerry Weißbach
101*3bda080dSGerry Weißbach        $toc->debug("THE END", true);
1027d101cc1SGerry Weißbach    }
1037d101cc1SGerry Weißbach
1047d101cc1SGerry Weißbach    private function translationRootPath($translationRoot = '')
1057d101cc1SGerry Weißbach    {
1067d101cc1SGerry Weißbach        if (!empty($translationRoot))
1077d101cc1SGerry Weißbach        {
1087d101cc1SGerry Weißbach            return $translationRoot . '/';
1097d101cc1SGerry Weißbach        }
1107d101cc1SGerry Weißbach
1117d101cc1SGerry Weißbach        return $translationRoot;
1127d101cc1SGerry Weißbach    }
1137d101cc1SGerry Weißbach
1147d101cc1SGerry Weißbach    private function getHSXML($rootID, $title, $lang = '', $translationRoot = '')
1157d101cc1SGerry Weißbach    {
116a0726238SGerry Weißbach        if (empty($lang) && substr($translationRoot, -1) != '/') {
117a0726238SGerry Weißbach            $translationRoot .= '/';
1180d8ab758SGerry Weißbach        } else if (!empty($lang) && substr($lang, -1) != '/') {
11983d0ebf7SGerry Weißbach            $lang .= '/';
120a9052036SGerry Weißbach        }
1210d8ab758SGerry Weißbach
1227d101cc1SGerry Weißbach        return <<<OUTPUT
1237d101cc1SGerry Weißbach<?xml version='1.0' encoding='ISO-8859-1' ?>
1247d101cc1SGerry Weißbach<helpset version="1.0">
1257d101cc1SGerry Weißbach
1267d101cc1SGerry Weißbach	<title>{$title}</title>
1277d101cc1SGerry Weißbach    <maps>
1287d101cc1SGerry Weißbach        <homeID>{$rootID}</homeID>
12983d0ebf7SGerry Weißbach        <mapref location="{$translationRoot}{$lang}{$this->mapName}"/>
1307d101cc1SGerry Weißbach     </maps>
1317d101cc1SGerry Weißbach
1327d101cc1SGerry Weißbach    <view>
1337d101cc1SGerry Weißbach        <name>TOC</name>
1347d101cc1SGerry Weißbach        <label>{$this->functions->getLang('toc')}</label>
1357d101cc1SGerry Weißbach        <type>javax.help.TOCView</type>
13683d0ebf7SGerry Weißbach        <data>{$translationRoot}{$lang}{$this->tocName}</data>
1377d101cc1SGerry Weißbach    </view>
1387d101cc1SGerry Weißbach
1397d101cc1SGerry Weißbach    <view>
1407d101cc1SGerry Weißbach        <name>Search</name>
1417d101cc1SGerry Weißbach        <label>{$this->functions->getLang('search')}</label>
1427d101cc1SGerry Weißbach        <type>javax.help.SearchView</type>
1437d101cc1SGerry Weißbach        <data engine="com.sun.java.help.search.DefaultSearchEngine">
14483d0ebf7SGerry Weißbach            {$translationRoot}{$lang}JavaHelpSearch
1457d101cc1SGerry Weißbach        </data>
1467d101cc1SGerry Weißbach    </view>
1477d101cc1SGerry Weißbach
1487d101cc1SGerry Weißbach    <impl>
1497d101cc1SGerry Weißbach        <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" />
1507d101cc1SGerry Weißbach        <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" />
1517d101cc1SGerry Weißbach    </impl>
1527d101cc1SGerry Weißbach</helpset>
1537d101cc1SGerry WeißbachOUTPUT;
1547d101cc1SGerry Weißbach    }
1557d101cc1SGerry Weißbach}
156