xref: /plugin/siteexport/inc/javahelp.php (revision 0d8ab75850c19c8db9c46adfb6238fc03e72f10f)
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
16a0726238SGerry Weißbach    public function siteexport_javahelp($functions, $filewriter, $NS)
177d101cc1SGerry Weißbach    {
18a0726238SGerry Weißbach        $this->NS = $NS;
197d101cc1SGerry Weißbach        $this->functions = $functions;
207d101cc1SGerry Weißbach        $this->filewriter = $filewriter;
217d101cc1SGerry Weißbach        $this->translation = & plugin_load('helper', 'translation' );
227d101cc1SGerry Weißbach    }
237d101cc1SGerry Weißbach
247d101cc1SGerry Weißbach    public function createTOCFiles($data)
257d101cc1SGerry Weißbach    {
26c65f2532SGerry Weißbach        global $conf, $ID;
277d101cc1SGerry Weißbach
287d101cc1SGerry Weißbach        // Split Tree for translation
297d101cc1SGerry Weißbach        $translationHSFiles = array();
307d101cc1SGerry Weißbach
317d101cc1SGerry Weißbach        for ($i=0; $i<count($data); $i++)
327d101cc1SGerry Weißbach        {
337d101cc1SGerry Weißbach            $lang = '';
347d101cc1SGerry Weißbach            if ( $this->translation )
357d101cc1SGerry Weißbach            {
367d101cc1SGerry Weißbach                $this->translation->tns = $this->translation->setupTNS($data[$i]['id']);
377d101cc1SGerry Weißbach                $lang = $this->translation->getLangPart($data[$i]['id']);
387d101cc1SGerry Weißbach            }
397d101cc1SGerry Weißbach
407d101cc1SGerry Weißbach            // get all the relative URLs
417d101cc1SGerry Weißbach            $translationHSFiles[$lang][] = $data[$i];
427d101cc1SGerry Weißbach        }
437d101cc1SGerry Weißbach
44a0726238SGerry Weißbach        $toc = new siteexport_toc($this->functions, $this->NS);
45a0726238SGerry Weißbach        // +":" at the end becaus this is already a namespace
46a0726238SGerry Weißbach        $baseNameSpace = str_replace('/', ':', $this->translation && !empty($this->translation->tns) ? $this->translation->tns : $this->NS . ':' );
47a0726238SGerry Weißbach        $translationRoot = curNS($baseNameSpace);
48a0726238SGerry Weißbach        $hsPrename = curNS(getNS($baseNameSpace));
49c65f2532SGerry Weißbach
5013326eabSGerry Weißbach        $this->functions->debug->message("HelpSetPre-Name: {$hsPrename}", null, 3);
5113326eabSGerry Weißbach        $this->functions->debug->message("Translation-Root: {$translationRoot}", null, 3);
5213326eabSGerry Weißbach        $this->functions->debug->message("HSFiles:", $translationHSFiles, 1);
5313326eabSGerry Weißbach
547d101cc1SGerry Weißbach
557d101cc1SGerry Weißbach        $check = array();
56a9052036SGerry Weißbach        $last_key = end(array_keys($translationHSFiles));
5713326eabSGerry Weißbach
587d101cc1SGerry Weißbach        foreach( $translationHSFiles as $lang => $data )
597d101cc1SGerry Weißbach        {
607d101cc1SGerry Weißbach            // Prepare Translations
6113326eabSGerry Weißbach            if ( !empty($lang) && !$this->functions->settings->TOCMapWithoutTranslation )
627d101cc1SGerry Weißbach            {
637d101cc1SGerry Weißbach                $toc->translation = &$this->translation;
647d101cc1SGerry Weißbach                $rootNode = cleanID($this->translation->tns . $lang) . ':';
657d101cc1SGerry Weißbach            } else {
667d101cc1SGerry Weißbach                $toc->translation = null;
677d101cc1SGerry Weißbach                $rootNode = '';
687d101cc1SGerry Weißbach            }
697d101cc1SGerry Weißbach
70f37dfca9SGerry Weißbach            $tsRootPath = $hsPrename . '/' . $this->translationRootPath($translationRoot);
7113326eabSGerry Weißbach            $this->functions->debug->message("Generating JavaHelpDocZip for language '$lang'", $tsRootPath, 3);
727d101cc1SGerry Weißbach
737d101cc1SGerry Weißbach            // Create toc and map for each lang
74a0726238SGerry Weißbach            list($tocData, $mapData, $startPageID) = $toc->__getJavaHelpTOCXML($data);
75a0726238SGerry Weißbach            $this->filewriter->__moveDataToZip($tocData, $tsRootPath . ( empty($lang) ? '' : $lang . '/') . $this->tocName);
76a0726238SGerry Weißbach            $this->filewriter->__moveDataToZip($mapData, $tsRootPath . ( empty($lang) ? '' : $lang . '/') . $this->mapName);
777d101cc1SGerry Weißbach
787d101cc1SGerry Weißbach            // Create HS File
797d101cc1SGerry Weißbach            // array_shift($toc->getMapID($rootNode, &$check))
807d101cc1SGerry Weißbach            $HS = $this->getHSXML( $startPageID, $this->functions->getSiteTitle($rootNode), $lang, $tsRootPath );
81f5fb7cd8SGerry Weißbach            $this->filewriter->__moveDataToZip($HS, $translationRoot . ( empty($lang) ? '' : '_' . $lang ) . '.hs');
827d101cc1SGerry Weißbach
837d101cc1SGerry Weißbach            // Default Lang
8413326eabSGerry Weißbach            if ( $lang == $this->functions->settings->defaultLang || $lang == $last_key )
857d101cc1SGerry Weißbach            {
8613326eabSGerry Weißbach                $this->functions->debug->message("Writing Default HS File for Language:", $lang, 3);
87f37dfca9SGerry Weißbach                $this->filewriter->__moveDataToZip($HS, $translationRoot . '.hs');
88a9052036SGerry Weißbach                $last_key = null;
897d101cc1SGerry Weißbach            }
907d101cc1SGerry Weißbach        }
917d101cc1SGerry Weißbach    }
927d101cc1SGerry Weißbach
937d101cc1SGerry Weißbach    private function translationRootPath($translationRoot = '')
947d101cc1SGerry Weißbach    {
957d101cc1SGerry Weißbach        if ( !empty($translationRoot) )
967d101cc1SGerry Weißbach        {
977d101cc1SGerry Weißbach            return $translationRoot . '/';
987d101cc1SGerry Weißbach        }
997d101cc1SGerry Weißbach
1007d101cc1SGerry Weißbach        return $translationRoot;
1017d101cc1SGerry Weißbach    }
1027d101cc1SGerry Weißbach
1037d101cc1SGerry Weißbach    private function getHSXML($rootID, $title, $lang='', $translationRoot='')
1047d101cc1SGerry Weißbach    {
105a0726238SGerry Weißbach        if ( empty($lang) && substr($translationRoot, -1) != '/') {
106a0726238SGerry Weißbach            $translationRoot .= '/';
107*0d8ab758SGerry Weißbach        } else if ( !empty($lang) && substr($lang, -1) != '/' ) {
10883d0ebf7SGerry Weißbach            $lang .= '/';
109a9052036SGerry Weißbach        }
110*0d8ab758SGerry Weißbach
1117d101cc1SGerry Weißbach        return <<<OUTPUT
1127d101cc1SGerry Weißbach<?xml version='1.0' encoding='ISO-8859-1' ?>
1137d101cc1SGerry Weißbach<helpset version="1.0">
1147d101cc1SGerry Weißbach
1157d101cc1SGerry Weißbach	<title>{$title}</title>
1167d101cc1SGerry Weißbach    <maps>
1177d101cc1SGerry Weißbach        <homeID>{$rootID}</homeID>
11883d0ebf7SGerry Weißbach        <mapref location="{$translationRoot}{$lang}{$this->mapName}"/>
1197d101cc1SGerry Weißbach     </maps>
1207d101cc1SGerry Weißbach
1217d101cc1SGerry Weißbach    <view>
1227d101cc1SGerry Weißbach        <name>TOC</name>
1237d101cc1SGerry Weißbach        <label>{$this->functions->getLang('toc')}</label>
1247d101cc1SGerry Weißbach        <type>javax.help.TOCView</type>
12583d0ebf7SGerry Weißbach        <data>{$translationRoot}{$lang}{$this->tocName}</data>
1267d101cc1SGerry Weißbach    </view>
1277d101cc1SGerry Weißbach
1287d101cc1SGerry Weißbach    <view>
1297d101cc1SGerry Weißbach        <name>Search</name>
1307d101cc1SGerry Weißbach        <label>{$this->functions->getLang('search')}</label>
1317d101cc1SGerry Weißbach        <type>javax.help.SearchView</type>
1327d101cc1SGerry Weißbach        <data engine="com.sun.java.help.search.DefaultSearchEngine">
13383d0ebf7SGerry Weißbach            {$translationRoot}{$lang}JavaHelpSearch
1347d101cc1SGerry Weißbach        </data>
1357d101cc1SGerry Weißbach    </view>
1367d101cc1SGerry Weißbach
1377d101cc1SGerry Weißbach    <impl>
1387d101cc1SGerry Weißbach        <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" />
1397d101cc1SGerry Weißbach        <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" />
1407d101cc1SGerry Weißbach    </impl>
1417d101cc1SGerry Weißbach</helpset>
1427d101cc1SGerry WeißbachOUTPUT;
1437d101cc1SGerry Weißbach    }
1447d101cc1SGerry Weißbach}