xref: /plugin/siteexport/inc/javahelp.php (revision 7d101cc131696cb3a0de345d8044a69fb2ef70e9)
1*7d101cc1SGerry Weißbach<?php
2*7d101cc1SGerry Weißbach
3*7d101cc1SGerry Weißbachif(!defined('DOKU_PLUGIN')) die('meh');
4*7d101cc1SGerry Weißbachrequire_once(DOKU_PLUGIN.'siteexport/inc/toc.php');
5*7d101cc1SGerry Weißbach
6*7d101cc1SGerry Weißbachclass siteexport_javahelp
7*7d101cc1SGerry Weißbach{
8*7d101cc1SGerry Weißbach    private $functions = null;
9*7d101cc1SGerry Weißbach    private $translation = null;
10*7d101cc1SGerry Weißbach    private $filewriter = null;
11*7d101cc1SGerry Weißbach
12*7d101cc1SGerry Weißbach    private $tocName = 'toc.xml';
13*7d101cc1SGerry Weißbach    private $mapName = 'map.xml';
14*7d101cc1SGerry Weißbach
15*7d101cc1SGerry Weißbach    public function siteexport_javahelp($functions, $filewriter)
16*7d101cc1SGerry Weißbach    {
17*7d101cc1SGerry Weißbach        $this->functions = $functions;
18*7d101cc1SGerry Weißbach        $this->filewriter = $filewriter;
19*7d101cc1SGerry Weißbach        $this->translation = & plugin_load('helper', 'translation' );
20*7d101cc1SGerry Weißbach    }
21*7d101cc1SGerry Weißbach
22*7d101cc1SGerry Weißbach    public function createTOCFiles($data)
23*7d101cc1SGerry Weißbach    {
24*7d101cc1SGerry Weißbach        global $conf;
25*7d101cc1SGerry Weißbach
26*7d101cc1SGerry Weißbach        // Split Tree for translation
27*7d101cc1SGerry Weißbach        $translationHSFiles = array();
28*7d101cc1SGerry Weißbach
29*7d101cc1SGerry Weißbach        for ($i=0; $i<count($data); $i++)
30*7d101cc1SGerry Weißbach        {
31*7d101cc1SGerry Weißbach            $lang = '';
32*7d101cc1SGerry Weißbach            if ( $this->translation )
33*7d101cc1SGerry Weißbach            {
34*7d101cc1SGerry Weißbach                $this->translation->tns = $this->translation->setupTNS($data[$i]['id']);
35*7d101cc1SGerry Weißbach                $lang = $this->translation->getLangPart($data[$i]['id']);
36*7d101cc1SGerry Weißbach            }
37*7d101cc1SGerry Weißbach
38*7d101cc1SGerry Weißbach            // get all the relative URLs
39*7d101cc1SGerry Weißbach            $translationHSFiles[$lang][] = $data[$i];
40*7d101cc1SGerry Weißbach        }
41*7d101cc1SGerry Weißbach
42*7d101cc1SGerry Weißbach        $toc = new siteexport_toc($this->functions);
43*7d101cc1SGerry Weißbach        if ( $this->translation )
44*7d101cc1SGerry Weißbach        {
45*7d101cc1SGerry Weißbach            $translationRoot = curNS($this->translation->tns);
46*7d101cc1SGerry Weißbach        }
47*7d101cc1SGerry Weißbach
48*7d101cc1SGerry Weißbach        $hsPrename = curNS(getNS($this->translation->tns)) . '_' . $translationRoot;
49*7d101cc1SGerry Weißbach
50*7d101cc1SGerry Weißbach        $check = array();
51*7d101cc1SGerry Weißbach        foreach( $translationHSFiles as $lang => $data )
52*7d101cc1SGerry Weißbach        {
53*7d101cc1SGerry Weißbach            if ( count($translationHSFiles) == 1 && $lang == $conf['lang'] )
54*7d101cc1SGerry Weißbach            {
55*7d101cc1SGerry Weißbach                // If there is only one language and it is the system language - there is no language
56*7d101cc1SGerry Weißbach                $lang = '';
57*7d101cc1SGerry Weißbach            }
58*7d101cc1SGerry Weißbach
59*7d101cc1SGerry Weißbach            // Prepare Translations
60*7d101cc1SGerry Weißbach            if ( !empty($lang) )
61*7d101cc1SGerry Weißbach            {
62*7d101cc1SGerry Weißbach                $toc->translation = &$this->translation;
63*7d101cc1SGerry Weißbach                $rootNode = cleanID($this->translation->tns . $lang) . ':';
64*7d101cc1SGerry Weißbach            } else {
65*7d101cc1SGerry Weißbach                $toc->translation = null;
66*7d101cc1SGerry Weißbach                $rootNode = '';
67*7d101cc1SGerry Weißbach            }
68*7d101cc1SGerry Weißbach
69*7d101cc1SGerry Weißbach            $tsRootPath = $this->translationRootPath($translationRoot);
70*7d101cc1SGerry Weißbach
71*7d101cc1SGerry Weißbach            // Create toc and map for each lang
72*7d101cc1SGerry Weißbach            list($tocData, $mapData, $startPageID) = $toc->__getJavaHelpTOCXML($data, $tsRootPath);
73*7d101cc1SGerry Weißbach            $this->functions->debug->message("Generating JavaHelpDocZip for language '$lang'", null, 2);
74*7d101cc1SGerry Weißbach            $this->filewriter->__moveDataToZip($tocData, $tsRootPath . $lang . '/' . $this->tocName);
75*7d101cc1SGerry Weißbach            $this->filewriter->__moveDataToZip($mapData, $tsRootPath . $lang . '/' . $this->mapName);
76*7d101cc1SGerry Weißbach
77*7d101cc1SGerry Weißbach            // Create HS File
78*7d101cc1SGerry Weißbach            // array_shift($toc->getMapID($rootNode, &$check))
79*7d101cc1SGerry Weißbach            $HS = $this->getHSXML( $startPageID, $this->functions->getSiteTitle($rootNode), $lang, $tsRootPath );
80*7d101cc1SGerry Weißbach            $this->filewriter->__moveDataToZip($HS, $hsPrename . '_' . $lang . '.hs');
81*7d101cc1SGerry Weißbach
82*7d101cc1SGerry Weißbach            // Default Lang
83*7d101cc1SGerry Weißbach            if ( $lang == $conf['lang'] )
84*7d101cc1SGerry Weißbach            {
85*7d101cc1SGerry Weißbach                $this->filewriter->__moveDataToZip($HS, $hsPrename . '.hs');
86*7d101cc1SGerry Weißbach            }
87*7d101cc1SGerry Weißbach        }
88*7d101cc1SGerry Weißbach    }
89*7d101cc1SGerry Weißbach
90*7d101cc1SGerry Weißbach    private function translationRootPath($translationRoot = '')
91*7d101cc1SGerry Weißbach    {
92*7d101cc1SGerry Weißbach        if ( !empty($translationRoot) )
93*7d101cc1SGerry Weißbach        {
94*7d101cc1SGerry Weißbach            return $translationRoot . '/';
95*7d101cc1SGerry Weißbach        }
96*7d101cc1SGerry Weißbach
97*7d101cc1SGerry Weißbach        return $translationRoot;
98*7d101cc1SGerry Weißbach    }
99*7d101cc1SGerry Weißbach
100*7d101cc1SGerry Weißbach    private function getHSXML($rootID, $title, $lang='', $translationRoot='')
101*7d101cc1SGerry Weißbach    {
102*7d101cc1SGerry Weißbach        return <<<OUTPUT
103*7d101cc1SGerry Weißbach<?xml version='1.0' encoding='ISO-8859-1' ?>
104*7d101cc1SGerry Weißbach<helpset version="1.0">
105*7d101cc1SGerry Weißbach
106*7d101cc1SGerry Weißbach	<title>{$title}</title>
107*7d101cc1SGerry Weißbach    <maps>
108*7d101cc1SGerry Weißbach        <homeID>{$rootID}</homeID>
109*7d101cc1SGerry Weißbach        <mapref location="{$translationRoot}{$lang}/{$this->mapName}"/>
110*7d101cc1SGerry Weißbach     </maps>
111*7d101cc1SGerry Weißbach
112*7d101cc1SGerry Weißbach    <view>
113*7d101cc1SGerry Weißbach        <name>TOC</name>
114*7d101cc1SGerry Weißbach        <label>{$this->functions->getLang('toc')}</label>
115*7d101cc1SGerry Weißbach        <type>javax.help.TOCView</type>
116*7d101cc1SGerry Weißbach        <data>{$translationRoot}{$lang}/{$this->tocName}</data>
117*7d101cc1SGerry Weißbach    </view>
118*7d101cc1SGerry Weißbach
119*7d101cc1SGerry Weißbach    <view>
120*7d101cc1SGerry Weißbach        <name>Search</name>
121*7d101cc1SGerry Weißbach        <label>{$this->functions->getLang('search')}</label>
122*7d101cc1SGerry Weißbach        <type>javax.help.SearchView</type>
123*7d101cc1SGerry Weißbach        <data engine="com.sun.java.help.search.DefaultSearchEngine">
124*7d101cc1SGerry Weißbach            {$translationRoot}{$lang}/JavaHelpSearch
125*7d101cc1SGerry Weißbach        </data>
126*7d101cc1SGerry Weißbach    </view>
127*7d101cc1SGerry Weißbach
128*7d101cc1SGerry Weißbach    <impl>
129*7d101cc1SGerry Weißbach        <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" />
130*7d101cc1SGerry Weißbach        <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" />
131*7d101cc1SGerry Weißbach    </impl>
132*7d101cc1SGerry Weißbach</helpset>
133*7d101cc1SGerry WeißbachOUTPUT;
134*7d101cc1SGerry Weißbach    }
135*7d101cc1SGerry Weißbach}