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*6f1c90e9SGerry Weißbach $this->translation = & plugin_load('helper', 'autotranslation'); 267d101cc1SGerry Weißbach } 277d101cc1SGerry Weißbach 287d101cc1SGerry Weißbach public function createTOCFiles($data) 297d101cc1SGerry Weißbach { 30c65f2532SGerry Weißbach global $conf, $ID; 317d101cc1SGerry Weißbach 327d101cc1SGerry Weißbach // Split Tree for translation 337d101cc1SGerry Weißbach $translationHSFiles = array(); 347d101cc1SGerry Weißbach 357d101cc1SGerry Weißbach for ($i = 0; $i < count($data); $i++) 367d101cc1SGerry Weißbach { 377d101cc1SGerry Weißbach $lang = ''; 387d101cc1SGerry Weißbach if ($this->translation) 397d101cc1SGerry Weißbach { 407d101cc1SGerry Weißbach $this->translation->tns = $this->translation->setupTNS($data[$i]['id']); 417d101cc1SGerry Weißbach $lang = $this->translation->getLangPart($data[$i]['id']); 427d101cc1SGerry Weißbach } 437d101cc1SGerry Weißbach 447d101cc1SGerry Weißbach // get all the relative URLs 457d101cc1SGerry Weißbach $translationHSFiles[$lang][] = $data[$i]; 467d101cc1SGerry Weißbach } 477d101cc1SGerry Weißbach 48a0726238SGerry Weißbach $toc = new siteexport_toc($this->functions, $this->NS); 49a0726238SGerry Weißbach // +":" at the end becaus this is already a namespace 50a0726238SGerry Weißbach $baseNameSpace = str_replace('/', ':', $this->translation && !empty($this->translation->tns) ? $this->translation->tns : $this->NS . ':'); 51a0726238SGerry Weißbach $translationRoot = curNS($baseNameSpace); 52a0726238SGerry Weißbach $hsPrename = curNS(getNS($baseNameSpace)); 53c65f2532SGerry Weißbach 5413326eabSGerry Weißbach $this->functions->debug->message("HelpSetPre-Name: {$hsPrename}", null, 3); 5513326eabSGerry Weißbach $this->functions->debug->message("Translation-Root: {$translationRoot}", null, 3); 5613326eabSGerry Weißbach $this->functions->debug->message("HSFiles:", $translationHSFiles, 1); 5713326eabSGerry Weißbach 587d101cc1SGerry Weißbach 597d101cc1SGerry Weißbach $check = array(); 60a9052036SGerry Weißbach $last_key = end(array_keys($translationHSFiles)); 6113326eabSGerry Weißbach 627d101cc1SGerry Weißbach foreach ($translationHSFiles as $lang => $data) 637d101cc1SGerry Weißbach { 647d101cc1SGerry Weißbach // Prepare Translations 6513326eabSGerry Weißbach if (!empty($lang) && !$this->functions->settings->TOCMapWithoutTranslation) 667d101cc1SGerry Weißbach { 677d101cc1SGerry Weißbach $toc->translation = &$this->translation; 687d101cc1SGerry Weißbach $rootNode = cleanID($this->translation->tns . $lang) . ':'; 697d101cc1SGerry Weißbach } else { 707d101cc1SGerry Weißbach $toc->translation = null; 717d101cc1SGerry Weißbach $rootNode = ''; 727d101cc1SGerry Weißbach } 737d101cc1SGerry Weißbach 74f37dfca9SGerry Weißbach $tsRootPath = $hsPrename . '/' . $this->translationRootPath($translationRoot); 7513326eabSGerry Weißbach $this->functions->debug->message("Generating JavaHelpDocZip for language '$lang'", $tsRootPath, 3); 767d101cc1SGerry Weißbach 777d101cc1SGerry Weißbach // Create toc and map for each lang 78a0726238SGerry Weißbach list($tocData, $mapData, $startPageID) = $toc->__getJavaHelpTOCXML($data); 79a0726238SGerry Weißbach $this->filewriter->__moveDataToZip($tocData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->tocName); 80a0726238SGerry Weißbach $this->filewriter->__moveDataToZip($mapData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->mapName); 817d101cc1SGerry Weißbach 827d101cc1SGerry Weißbach // Create HS File 837d101cc1SGerry Weißbach // array_shift($toc->getMapID($rootNode, &$check)) 847d101cc1SGerry Weißbach $HS = $this->getHSXML($startPageID, $this->functions->getSiteTitle($rootNode), $lang, $tsRootPath); 85f5fb7cd8SGerry Weißbach $this->filewriter->__moveDataToZip($HS, $translationRoot . (empty($lang) ? '' : '_' . $lang) . '.hs'); 867d101cc1SGerry Weißbach 877d101cc1SGerry Weißbach // Default Lang 8813326eabSGerry Weißbach if ($lang == $this->functions->settings->defaultLang || $lang == $last_key) 897d101cc1SGerry Weißbach { 9013326eabSGerry Weißbach $this->functions->debug->message("Writing Default HS File for Language:", $lang, 3); 91f37dfca9SGerry Weißbach $this->filewriter->__moveDataToZip($HS, $translationRoot . '.hs'); 92a9052036SGerry Weißbach $last_key = null; 937d101cc1SGerry Weißbach } 947d101cc1SGerry Weißbach } 957d101cc1SGerry Weißbach } 967d101cc1SGerry Weißbach 977d101cc1SGerry Weißbach private function translationRootPath($translationRoot = '') 987d101cc1SGerry Weißbach { 997d101cc1SGerry Weißbach if (!empty($translationRoot)) 1007d101cc1SGerry Weißbach { 1017d101cc1SGerry Weißbach return $translationRoot . '/'; 1027d101cc1SGerry Weißbach } 1037d101cc1SGerry Weißbach 1047d101cc1SGerry Weißbach return $translationRoot; 1057d101cc1SGerry Weißbach } 1067d101cc1SGerry Weißbach 1077d101cc1SGerry Weißbach private function getHSXML($rootID, $title, $lang = '', $translationRoot = '') 1087d101cc1SGerry Weißbach { 109a0726238SGerry Weißbach if (empty($lang) && substr($translationRoot, -1) != '/') { 110a0726238SGerry Weißbach $translationRoot .= '/'; 1110d8ab758SGerry Weißbach } else if (!empty($lang) && substr($lang, -1) != '/') { 11283d0ebf7SGerry Weißbach $lang .= '/'; 113a9052036SGerry Weißbach } 1140d8ab758SGerry Weißbach 1157d101cc1SGerry Weißbach return <<<OUTPUT 1167d101cc1SGerry Weißbach<?xml version='1.0' encoding='ISO-8859-1' ?> 1177d101cc1SGerry Weißbach<helpset version="1.0"> 1187d101cc1SGerry Weißbach 1197d101cc1SGerry Weißbach <title>{$title}</title> 1207d101cc1SGerry Weißbach <maps> 1217d101cc1SGerry Weißbach <homeID>{$rootID}</homeID> 12283d0ebf7SGerry Weißbach <mapref location="{$translationRoot}{$lang}{$this->mapName}"/> 1237d101cc1SGerry Weißbach </maps> 1247d101cc1SGerry Weißbach 1257d101cc1SGerry Weißbach <view> 1267d101cc1SGerry Weißbach <name>TOC</name> 1277d101cc1SGerry Weißbach <label>{$this->functions->getLang('toc')}</label> 1287d101cc1SGerry Weißbach <type>javax.help.TOCView</type> 12983d0ebf7SGerry Weißbach <data>{$translationRoot}{$lang}{$this->tocName}</data> 1307d101cc1SGerry Weißbach </view> 1317d101cc1SGerry Weißbach 1327d101cc1SGerry Weißbach <view> 1337d101cc1SGerry Weißbach <name>Search</name> 1347d101cc1SGerry Weißbach <label>{$this->functions->getLang('search')}</label> 1357d101cc1SGerry Weißbach <type>javax.help.SearchView</type> 1367d101cc1SGerry Weißbach <data engine="com.sun.java.help.search.DefaultSearchEngine"> 13783d0ebf7SGerry Weißbach {$translationRoot}{$lang}JavaHelpSearch 1387d101cc1SGerry Weißbach </data> 1397d101cc1SGerry Weißbach </view> 1407d101cc1SGerry Weißbach 1417d101cc1SGerry Weißbach <impl> 1427d101cc1SGerry Weißbach <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" /> 1437d101cc1SGerry Weißbach <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" /> 1447d101cc1SGerry Weißbach </impl> 1457d101cc1SGerry Weißbach</helpset> 1467d101cc1SGerry WeißbachOUTPUT; 1477d101cc1SGerry Weißbach } 1487d101cc1SGerry Weißbach} 149