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(); 35*e9b60a63SGerry Weißbach $toc = new siteexport_toc($this->functions, $this->NS); 36*e9b60a63SGerry Weißbach $toc->debug("### Starting to create TOC Files ###"); 377d101cc1SGerry Weißbach 38cbb6b50eSi-net /// software $count = count($data); 39cbb6b50eSi-net /// software for ($i = 0; $i < $count ; $i++) 407d101cc1SGerry Weißbach { 417d101cc1SGerry Weißbach $lang = ''; 427d101cc1SGerry Weißbach if ($this->translation) 437d101cc1SGerry Weißbach { 446ca395bdSi-net /// software $this->translation->translationsNs = $this->translation->setupTNS($data[$i]['id'], true); 457d101cc1SGerry Weißbach $lang = $this->translation->getLangPart($data[$i]['id']); 4676ba6c82SGerry Weißbach $this->functions->debug->message("Setting up translation:", array( 4776ba6c82SGerry Weißbach 'id' => $data[$i]['id'], 4876ba6c82SGerry Weißbach 'tns' => $this->translation->translationsNs, 4976ba6c82SGerry Weißbach 'lang' => $lang 5076ba6c82SGerry Weißbach ), 3); 517d101cc1SGerry Weißbach } 527d101cc1SGerry Weißbach 53*e9b60a63SGerry Weißbach $toc->debug($lang . " -> " . $data[$i]['id'] ); 547d101cc1SGerry Weißbach // get all the relative URLs 557d101cc1SGerry Weißbach $translationHSFiles[$lang][] = $data[$i]; 567d101cc1SGerry Weißbach } 577d101cc1SGerry Weißbach 58a0726238SGerry Weißbach // +":" at the end becaus this is already a namespace 5976ba6c82SGerry Weißbach $baseNameSpace = str_replace('/', ':', $this->translation && !empty($this->translation->translationsNs) ? $this->translation->translationsNs : $this->NS . ':'); 60a0726238SGerry Weißbach $translationRoot = curNS($baseNameSpace); 61a0726238SGerry Weißbach $hsPrename = curNS(getNS($baseNameSpace)); 62c65f2532SGerry Weißbach 6313326eabSGerry Weißbach $this->functions->debug->message("HelpSetPre-Name: {$hsPrename}", null, 3); 6413326eabSGerry Weißbach $this->functions->debug->message("Translation-Root: {$translationRoot}", null, 3); 6513326eabSGerry Weißbach $this->functions->debug->message("HSFiles:", $translationHSFiles, 1); 6613326eabSGerry Weißbach 67a8c17ab5Si-net /// software $last_key = end((array_keys($translationHSFiles))); 6813326eabSGerry Weißbach 697d101cc1SGerry Weißbach foreach ($translationHSFiles as $lang => $data) 707d101cc1SGerry Weißbach { 717d101cc1SGerry Weißbach // Prepare Translations 7213326eabSGerry Weißbach if (!empty($lang) && !$this->functions->settings->TOCMapWithoutTranslation) 737d101cc1SGerry Weißbach { 747d101cc1SGerry Weißbach $toc->translation = &$this->translation; 7576ba6c82SGerry Weißbach $rootNode = cleanID($this->translation->translationsNs . $lang) . ':'; 767d101cc1SGerry Weißbach } else { 777d101cc1SGerry Weißbach $toc->translation = null; 787d101cc1SGerry Weißbach $rootNode = ''; 797d101cc1SGerry Weißbach } 807d101cc1SGerry Weißbach 81*e9b60a63SGerry Weißbach $toc->debug("*** Writing for Language rootNode: '".$rootNode."'***"); 82*e9b60a63SGerry Weißbach 83f37dfca9SGerry Weißbach $tsRootPath = $hsPrename . '/' . $this->translationRootPath($translationRoot); 8413326eabSGerry Weißbach $this->functions->debug->message("Generating JavaHelpDocZip for language '$lang'", $tsRootPath, 3); 857d101cc1SGerry Weißbach 867d101cc1SGerry Weißbach // Create toc and map for each lang 87a0726238SGerry Weißbach list($tocData, $mapData, $startPageID) = $toc->__getJavaHelpTOCXML($data); 88a0726238SGerry Weißbach $this->filewriter->__moveDataToZip($tocData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->tocName); 89a0726238SGerry Weißbach $this->filewriter->__moveDataToZip($mapData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->mapName); 907d101cc1SGerry Weißbach 917d101cc1SGerry Weißbach // Create HS File 927d101cc1SGerry Weißbach $HS = $this->getHSXML($startPageID, $this->functions->getSiteTitle($rootNode), $lang, $tsRootPath); 93f5fb7cd8SGerry Weißbach $this->filewriter->__moveDataToZip($HS, $translationRoot . (empty($lang) ? '' : '_' . $lang) . '.hs'); 947d101cc1SGerry Weißbach 957d101cc1SGerry Weißbach // Default Lang 9613326eabSGerry Weißbach if ($lang == $this->functions->settings->defaultLang || $lang == $last_key) 977d101cc1SGerry Weißbach { 9813326eabSGerry Weißbach $this->functions->debug->message("Writing Default HS File for Language:", $lang, 3); 99f37dfca9SGerry Weißbach $this->filewriter->__moveDataToZip($HS, $translationRoot . '.hs'); 100a9052036SGerry Weißbach $last_key = null; 1017d101cc1SGerry Weißbach } 1027d101cc1SGerry Weißbach } 1033bda080dSGerry Weißbach 1043bda080dSGerry Weißbach $toc->debug("THE END", true); 1057d101cc1SGerry Weißbach } 1067d101cc1SGerry Weißbach 1077d101cc1SGerry Weißbach private function translationRootPath($translationRoot = '') 1087d101cc1SGerry Weißbach { 1097d101cc1SGerry Weißbach if (!empty($translationRoot)) 1107d101cc1SGerry Weißbach { 1117d101cc1SGerry Weißbach return $translationRoot . '/'; 1127d101cc1SGerry Weißbach } 1137d101cc1SGerry Weißbach 1147d101cc1SGerry Weißbach return $translationRoot; 1157d101cc1SGerry Weißbach } 1167d101cc1SGerry Weißbach 1177d101cc1SGerry Weißbach private function getHSXML($rootID, $title, $lang = '', $translationRoot = '') 1187d101cc1SGerry Weißbach { 119a0726238SGerry Weißbach if (empty($lang) && substr($translationRoot, -1) != '/') { 120a0726238SGerry Weißbach $translationRoot .= '/'; 1210d8ab758SGerry Weißbach } else if (!empty($lang) && substr($lang, -1) != '/') { 12283d0ebf7SGerry Weißbach $lang .= '/'; 123a9052036SGerry Weißbach } 1240d8ab758SGerry Weißbach 1257d101cc1SGerry Weißbach return <<<OUTPUT 1267d101cc1SGerry Weißbach<?xml version='1.0' encoding='ISO-8859-1' ?> 1277d101cc1SGerry Weißbach<helpset version="1.0"> 1287d101cc1SGerry Weißbach 1297d101cc1SGerry Weißbach <title>{$title}</title> 1307d101cc1SGerry Weißbach <maps> 1317d101cc1SGerry Weißbach <homeID>{$rootID}</homeID> 13283d0ebf7SGerry Weißbach <mapref location="{$translationRoot}{$lang}{$this->mapName}"/> 1337d101cc1SGerry Weißbach </maps> 1347d101cc1SGerry Weißbach 1357d101cc1SGerry Weißbach <view> 1367d101cc1SGerry Weißbach <name>TOC</name> 1377d101cc1SGerry Weißbach <label>{$this->functions->getLang('toc')}</label> 1387d101cc1SGerry Weißbach <type>javax.help.TOCView</type> 13983d0ebf7SGerry Weißbach <data>{$translationRoot}{$lang}{$this->tocName}</data> 1407d101cc1SGerry Weißbach </view> 1417d101cc1SGerry Weißbach 1427d101cc1SGerry Weißbach <view> 1437d101cc1SGerry Weißbach <name>Search</name> 1447d101cc1SGerry Weißbach <label>{$this->functions->getLang('search')}</label> 1457d101cc1SGerry Weißbach <type>javax.help.SearchView</type> 1467d101cc1SGerry Weißbach <data engine="com.sun.java.help.search.DefaultSearchEngine"> 14783d0ebf7SGerry Weißbach {$translationRoot}{$lang}JavaHelpSearch 1487d101cc1SGerry Weißbach </data> 1497d101cc1SGerry Weißbach </view> 1507d101cc1SGerry Weißbach 1517d101cc1SGerry Weißbach <impl> 1527d101cc1SGerry Weißbach <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" /> 1537d101cc1SGerry Weißbach <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" /> 1547d101cc1SGerry Weißbach </impl> 1557d101cc1SGerry Weißbach</helpset> 1567d101cc1SGerry WeißbachOUTPUT; 1577d101cc1SGerry Weißbach } 1587d101cc1SGerry Weißbach} 159