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 36cbb6b50eSi-net /// software $count = count($data); 37cbb6b50eSi-net /// software for ($i = 0; $i < $count ; $i++) 387d101cc1SGerry Weißbach { 397d101cc1SGerry Weißbach $lang = ''; 407d101cc1SGerry Weißbach if ($this->translation) 417d101cc1SGerry Weißbach { 42*6ca395bdSi-net /// software $this->translation->translationsNs = $this->translation->setupTNS($data[$i]['id'], true); 437d101cc1SGerry Weißbach $lang = $this->translation->getLangPart($data[$i]['id']); 4476ba6c82SGerry Weißbach $this->functions->debug->message("Setting up translation:", array( 4576ba6c82SGerry Weißbach 'id' => $data[$i]['id'], 4676ba6c82SGerry Weißbach 'tns' => $this->translation->translationsNs, 4776ba6c82SGerry Weißbach 'lang' => $lang 4876ba6c82SGerry Weißbach ), 3); 497d101cc1SGerry Weißbach } 507d101cc1SGerry Weißbach 517d101cc1SGerry Weißbach // get all the relative URLs 527d101cc1SGerry Weißbach $translationHSFiles[$lang][] = $data[$i]; 537d101cc1SGerry Weißbach } 547d101cc1SGerry Weißbach 55a0726238SGerry Weißbach $toc = new siteexport_toc($this->functions, $this->NS); 56a0726238SGerry Weißbach // +":" at the end becaus this is already a namespace 5776ba6c82SGerry Weißbach $baseNameSpace = str_replace('/', ':', $this->translation && !empty($this->translation->translationsNs) ? $this->translation->translationsNs : $this->NS . ':'); 58a0726238SGerry Weißbach $translationRoot = curNS($baseNameSpace); 59a0726238SGerry Weißbach $hsPrename = curNS(getNS($baseNameSpace)); 60c65f2532SGerry Weißbach 6113326eabSGerry Weißbach $this->functions->debug->message("HelpSetPre-Name: {$hsPrename}", null, 3); 6213326eabSGerry Weißbach $this->functions->debug->message("Translation-Root: {$translationRoot}", null, 3); 6313326eabSGerry Weißbach $this->functions->debug->message("HSFiles:", $translationHSFiles, 1); 6413326eabSGerry Weißbach 65a8c17ab5Si-net /// software $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 $HS = $this->getHSXML($startPageID, $this->functions->getSiteTitle($rootNode), $lang, $tsRootPath); 89f5fb7cd8SGerry Weißbach $this->filewriter->__moveDataToZip($HS, $translationRoot . (empty($lang) ? '' : '_' . $lang) . '.hs'); 907d101cc1SGerry Weißbach 917d101cc1SGerry Weißbach // Default Lang 9213326eabSGerry Weißbach if ($lang == $this->functions->settings->defaultLang || $lang == $last_key) 937d101cc1SGerry Weißbach { 9413326eabSGerry Weißbach $this->functions->debug->message("Writing Default HS File for Language:", $lang, 3); 95f37dfca9SGerry Weißbach $this->filewriter->__moveDataToZip($HS, $translationRoot . '.hs'); 96a9052036SGerry Weißbach $last_key = null; 977d101cc1SGerry Weißbach } 987d101cc1SGerry Weißbach } 993bda080dSGerry Weißbach 1003bda080dSGerry Weißbach $toc->debug("THE END", true); 1017d101cc1SGerry Weißbach } 1027d101cc1SGerry Weißbach 1037d101cc1SGerry Weißbach private function translationRootPath($translationRoot = '') 1047d101cc1SGerry Weißbach { 1057d101cc1SGerry Weißbach if (!empty($translationRoot)) 1067d101cc1SGerry Weißbach { 1077d101cc1SGerry Weißbach return $translationRoot . '/'; 1087d101cc1SGerry Weißbach } 1097d101cc1SGerry Weißbach 1107d101cc1SGerry Weißbach return $translationRoot; 1117d101cc1SGerry Weißbach } 1127d101cc1SGerry Weißbach 1137d101cc1SGerry Weißbach private function getHSXML($rootID, $title, $lang = '', $translationRoot = '') 1147d101cc1SGerry Weißbach { 115a0726238SGerry Weißbach if (empty($lang) && substr($translationRoot, -1) != '/') { 116a0726238SGerry Weißbach $translationRoot .= '/'; 1170d8ab758SGerry Weißbach } else if (!empty($lang) && substr($lang, -1) != '/') { 11883d0ebf7SGerry Weißbach $lang .= '/'; 119a9052036SGerry Weißbach } 1200d8ab758SGerry Weißbach 1217d101cc1SGerry Weißbach return <<<OUTPUT 1227d101cc1SGerry Weißbach<?xml version='1.0' encoding='ISO-8859-1' ?> 1237d101cc1SGerry Weißbach<helpset version="1.0"> 1247d101cc1SGerry Weißbach 1257d101cc1SGerry Weißbach <title>{$title}</title> 1267d101cc1SGerry Weißbach <maps> 1277d101cc1SGerry Weißbach <homeID>{$rootID}</homeID> 12883d0ebf7SGerry Weißbach <mapref location="{$translationRoot}{$lang}{$this->mapName}"/> 1297d101cc1SGerry Weißbach </maps> 1307d101cc1SGerry Weißbach 1317d101cc1SGerry Weißbach <view> 1327d101cc1SGerry Weißbach <name>TOC</name> 1337d101cc1SGerry Weißbach <label>{$this->functions->getLang('toc')}</label> 1347d101cc1SGerry Weißbach <type>javax.help.TOCView</type> 13583d0ebf7SGerry Weißbach <data>{$translationRoot}{$lang}{$this->tocName}</data> 1367d101cc1SGerry Weißbach </view> 1377d101cc1SGerry Weißbach 1387d101cc1SGerry Weißbach <view> 1397d101cc1SGerry Weißbach <name>Search</name> 1407d101cc1SGerry Weißbach <label>{$this->functions->getLang('search')}</label> 1417d101cc1SGerry Weißbach <type>javax.help.SearchView</type> 1427d101cc1SGerry Weißbach <data engine="com.sun.java.help.search.DefaultSearchEngine"> 14383d0ebf7SGerry Weißbach {$translationRoot}{$lang}JavaHelpSearch 1447d101cc1SGerry Weißbach </data> 1457d101cc1SGerry Weißbach </view> 1467d101cc1SGerry Weißbach 1477d101cc1SGerry Weißbach <impl> 1487d101cc1SGerry Weißbach <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" /> 1497d101cc1SGerry Weißbach <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" /> 1507d101cc1SGerry Weißbach </impl> 1517d101cc1SGerry Weißbach</helpset> 1527d101cc1SGerry WeißbachOUTPUT; 1537d101cc1SGerry Weißbach } 1547d101cc1SGerry Weißbach} 155