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; 256f1c90e9SGerry 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 { 40*76ba6c82SGerry Weißbach $this->translation->translationsNs = $this->translation->setupTNS($data[$i]['id']); 417d101cc1SGerry Weißbach $lang = $this->translation->getLangPart($data[$i]['id']); 42*76ba6c82SGerry Weißbach $this->functions->debug->message("Setting up translation:", array( 43*76ba6c82SGerry Weißbach 'id' => $data[$i]['id'], 44*76ba6c82SGerry Weißbach 'tns' => $this->translation->translationsNs, 45*76ba6c82SGerry Weißbach 'lang' => $lang 46*76ba6c82SGerry Weißbach ), 3); 477d101cc1SGerry Weißbach } 487d101cc1SGerry Weißbach 497d101cc1SGerry Weißbach // get all the relative URLs 507d101cc1SGerry Weißbach $translationHSFiles[$lang][] = $data[$i]; 517d101cc1SGerry Weißbach } 527d101cc1SGerry Weißbach 53a0726238SGerry Weißbach $toc = new siteexport_toc($this->functions, $this->NS); 54a0726238SGerry Weißbach // +":" at the end becaus this is already a namespace 55*76ba6c82SGerry Weißbach $baseNameSpace = str_replace('/', ':', $this->translation && !empty($this->translation->translationsNs) ? $this->translation->translationsNs : $this->NS . ':'); 56a0726238SGerry Weißbach $translationRoot = curNS($baseNameSpace); 57a0726238SGerry Weißbach $hsPrename = curNS(getNS($baseNameSpace)); 58c65f2532SGerry Weißbach 5913326eabSGerry Weißbach $this->functions->debug->message("HelpSetPre-Name: {$hsPrename}", null, 3); 6013326eabSGerry Weißbach $this->functions->debug->message("Translation-Root: {$translationRoot}", null, 3); 6113326eabSGerry Weißbach $this->functions->debug->message("HSFiles:", $translationHSFiles, 1); 6213326eabSGerry Weißbach 637d101cc1SGerry Weißbach $check = array(); 64a9052036SGerry Weißbach $last_key = end(array_keys($translationHSFiles)); 6513326eabSGerry Weißbach 667d101cc1SGerry Weißbach foreach ($translationHSFiles as $lang => $data) 677d101cc1SGerry Weißbach { 687d101cc1SGerry Weißbach // Prepare Translations 6913326eabSGerry Weißbach if (!empty($lang) && !$this->functions->settings->TOCMapWithoutTranslation) 707d101cc1SGerry Weißbach { 717d101cc1SGerry Weißbach $toc->translation = &$this->translation; 72*76ba6c82SGerry Weißbach $rootNode = cleanID($this->translation->translationsNs . $lang) . ':'; 737d101cc1SGerry Weißbach } else { 747d101cc1SGerry Weißbach $toc->translation = null; 757d101cc1SGerry Weißbach $rootNode = ''; 767d101cc1SGerry Weißbach } 777d101cc1SGerry Weißbach 78f37dfca9SGerry Weißbach $tsRootPath = $hsPrename . '/' . $this->translationRootPath($translationRoot); 7913326eabSGerry Weißbach $this->functions->debug->message("Generating JavaHelpDocZip for language '$lang'", $tsRootPath, 3); 807d101cc1SGerry Weißbach 817d101cc1SGerry Weißbach // Create toc and map for each lang 82a0726238SGerry Weißbach list($tocData, $mapData, $startPageID) = $toc->__getJavaHelpTOCXML($data); 83a0726238SGerry Weißbach $this->filewriter->__moveDataToZip($tocData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->tocName); 84a0726238SGerry Weißbach $this->filewriter->__moveDataToZip($mapData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->mapName); 857d101cc1SGerry Weißbach 867d101cc1SGerry Weißbach // Create HS File 877d101cc1SGerry Weißbach // array_shift($toc->getMapID($rootNode, &$check)) 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 } 997d101cc1SGerry Weißbach } 1007d101cc1SGerry Weißbach 1017d101cc1SGerry Weißbach private function translationRootPath($translationRoot = '') 1027d101cc1SGerry Weißbach { 1037d101cc1SGerry Weißbach if (!empty($translationRoot)) 1047d101cc1SGerry Weißbach { 1057d101cc1SGerry Weißbach return $translationRoot . '/'; 1067d101cc1SGerry Weißbach } 1077d101cc1SGerry Weißbach 1087d101cc1SGerry Weißbach return $translationRoot; 1097d101cc1SGerry Weißbach } 1107d101cc1SGerry Weißbach 1117d101cc1SGerry Weißbach private function getHSXML($rootID, $title, $lang = '', $translationRoot = '') 1127d101cc1SGerry Weißbach { 113a0726238SGerry Weißbach if (empty($lang) && substr($translationRoot, -1) != '/') { 114a0726238SGerry Weißbach $translationRoot .= '/'; 1150d8ab758SGerry Weißbach } else if (!empty($lang) && substr($lang, -1) != '/') { 11683d0ebf7SGerry Weißbach $lang .= '/'; 117a9052036SGerry Weißbach } 1180d8ab758SGerry Weißbach 1197d101cc1SGerry Weißbach return <<<OUTPUT 1207d101cc1SGerry Weißbach<?xml version='1.0' encoding='ISO-8859-1' ?> 1217d101cc1SGerry Weißbach<helpset version="1.0"> 1227d101cc1SGerry Weißbach 1237d101cc1SGerry Weißbach <title>{$title}</title> 1247d101cc1SGerry Weißbach <maps> 1257d101cc1SGerry Weißbach <homeID>{$rootID}</homeID> 12683d0ebf7SGerry Weißbach <mapref location="{$translationRoot}{$lang}{$this->mapName}"/> 1277d101cc1SGerry Weißbach </maps> 1287d101cc1SGerry Weißbach 1297d101cc1SGerry Weißbach <view> 1307d101cc1SGerry Weißbach <name>TOC</name> 1317d101cc1SGerry Weißbach <label>{$this->functions->getLang('toc')}</label> 1327d101cc1SGerry Weißbach <type>javax.help.TOCView</type> 13383d0ebf7SGerry Weißbach <data>{$translationRoot}{$lang}{$this->tocName}</data> 1347d101cc1SGerry Weißbach </view> 1357d101cc1SGerry Weißbach 1367d101cc1SGerry Weißbach <view> 1377d101cc1SGerry Weißbach <name>Search</name> 1387d101cc1SGerry Weißbach <label>{$this->functions->getLang('search')}</label> 1397d101cc1SGerry Weißbach <type>javax.help.SearchView</type> 1407d101cc1SGerry Weißbach <data engine="com.sun.java.help.search.DefaultSearchEngine"> 14183d0ebf7SGerry Weißbach {$translationRoot}{$lang}JavaHelpSearch 1427d101cc1SGerry Weißbach </data> 1437d101cc1SGerry Weißbach </view> 1447d101cc1SGerry Weißbach 1457d101cc1SGerry Weißbach <impl> 1467d101cc1SGerry Weißbach <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" /> 1477d101cc1SGerry Weißbach <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" /> 1487d101cc1SGerry Weißbach </impl> 1497d101cc1SGerry Weißbach</helpset> 1507d101cc1SGerry WeißbachOUTPUT; 1517d101cc1SGerry Weißbach } 1527d101cc1SGerry Weißbach} 153