xref: /plugin/siteexport/inc/toc.php (revision cbb6b50ef00aab5dc836e0ee91d910739f5338ba)
17d101cc1SGerry Weißbach<?php
27d101cc1SGerry Weißbach
37d101cc1SGerry Weißbachif (!defined('DOKU_PLUGIN')) die('meh');
47d101cc1SGerry Weißbach
57d101cc1SGerry Weißbachclass siteexport_toc
67d101cc1SGerry Weißbach{
77d101cc1SGerry Weißbach    private $emptyNSToc = true;
87d101cc1SGerry Weißbach    private $functions = null;
9a0726238SGerry Weißbach    private $NS = null;
107d101cc1SGerry Weißbach    public $translation = null;
117d101cc1SGerry Weißbach
12b324a190SMichael Hamann    public function __construct($functions, $NS)
137d101cc1SGerry Weißbach    {
142c9ab2bbSGerry Weißbach        $this->doDebug = !empty($_REQUEST['tocDebug']);
157d101cc1SGerry Weißbach        $this->emptyNSToc = !empty($_REQUEST['emptyTocElem']);
167d101cc1SGerry Weißbach        $this->functions = $functions;
17a0726238SGerry Weißbach        $this->NS = $NS;
187d101cc1SGerry Weißbach    }
197d101cc1SGerry Weißbach
207d101cc1SGerry Weißbach    private function shortenByTranslation(&$inputURL, $deepSearch = false)
217d101cc1SGerry Weißbach    {
2227464f82SGerry Weißbach        // Mandatory: we allways want '/' insteadf of ':' here
2327464f82SGerry Weißbach        $inputURL = str_replace(':', '/', $inputURL);
24a8c17ab5Si-net /// software
25a8c17ab5Si-net /// software        $checkArray = $this->translation ? $this->translation->translations : array(noNS($this->NS));
26a0726238SGerry Weißbach
277d101cc1SGerry Weißbach        $url = explode('/', $inputURL);
287d101cc1SGerry Weißbach
29*cbb6b50eSi-net /// software        $URLcount = count($url);
30*cbb6b50eSi-net /// software        for ($i = 0; $i < $URLcount ; $i++)
317d101cc1SGerry Weißbach        {
32a0726238SGerry Weißbach            if (in_array($url[$i], $checkArray))
337d101cc1SGerry Weißbach            {
347d101cc1SGerry Weißbach                // Rauswerfen und weg
357d101cc1SGerry Weißbach                $url[$i] = '';
367d101cc1SGerry Weißbach                break;
377d101cc1SGerry Weißbach            }
387d101cc1SGerry Weißbach
397d101cc1SGerry Weißbach            if (!$deepSearch)
407d101cc1SGerry Weißbach            {
417d101cc1SGerry Weißbach                break;
427d101cc1SGerry Weißbach            }
437d101cc1SGerry Weißbach
447d101cc1SGerry Weißbach            // Ok, remove anyway
457d101cc1SGerry Weißbach            $url[$i] = '';
467d101cc1SGerry Weißbach        }
477d101cc1SGerry Weißbach
487d101cc1SGerry Weißbach        $inputURL = implode('/', $url);
497d101cc1SGerry Weißbach        $inputURL = preg_replace("$\/+$", "/", $inputURL);
507d101cc1SGerry Weißbach
517d101cc1SGerry Weißbach        if (strlen($inputURL) > 0 && substr($inputURL, 0, 1) == '/')
527d101cc1SGerry Weißbach        {
537d101cc1SGerry Weißbach            $inputURL = substr($inputURL, 1);
547d101cc1SGerry Weißbach        }
557d101cc1SGerry Weißbach
567d101cc1SGerry Weißbach        return $inputURL;
577d101cc1SGerry Weißbach    }
587d101cc1SGerry Weißbach
597d101cc1SGerry Weißbach    /**
607d101cc1SGerry Weißbach     * Build the Java Documentation TOC XML
617d101cc1SGerry Weißbach     **/
627d101cc1SGerry Weißbach    public function __getJavaHelpTOCXML($DATA) {
637d101cc1SGerry Weißbach
647d101cc1SGerry Weißbach        if (count($DATA) == 0) {
657d101cc1SGerry Weißbach            return false;
667d101cc1SGerry Weißbach        }
677d101cc1SGerry Weißbach
687d101cc1SGerry Weißbach        $TOCXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<toc>";
697d101cc1SGerry Weißbach        $MAPXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<map version=\"1.0\">";
707d101cc1SGerry Weißbach
717d101cc1SGerry Weißbach        // Go through the pages
727d101cc1SGerry Weißbach        $CHECKDATA = array();
737d101cc1SGerry Weißbach        $nData = $DATA;
747d101cc1SGerry Weißbach        $DATA = array();
757d101cc1SGerry Weißbach        $check = array();
767d101cc1SGerry Weißbach        $startPageID = null;
777d101cc1SGerry Weißbach
787d101cc1SGerry Weißbach        foreach ( $nData as $elem )
797d101cc1SGerry Weißbach        {
807d101cc1SGerry Weißbach            // Check if available
817d101cc1SGerry Weißbach            $anchor = ( !empty($elem['anchor']) ? '#' . $elem['anchor'] : '' );
82d9cefbd9SGerry Weißbach            $elem['url'] = $this->functions->getSiteName($elem['id'], true); // Override - we need a clean name
837d101cc1SGerry Weißbach            $elem['mapURL'] = $elem['url'];
847d101cc1SGerry Weißbach            $this->shortenByTranslation($elem['url']);
857d101cc1SGerry Weißbach
867d101cc1SGerry Weißbach            // only add an url once
877d101cc1SGerry Weißbach            if ( in_array($elem['url'], $CHECKDATA) ) { continue; }
887d101cc1SGerry Weißbach
89dfb6ef8fSGerry Weißbach            if ( !isset($elem['exists']) ) {
90dfb6ef8fSGerry Weißbach                resolve_pageid(getNS($elem['id']),$elem['id'],$elem['exists']);
91dfb6ef8fSGerry Weißbach                $this->functions->debug->message("EXISTS previously not set.", $elem, 1);
92dfb6ef8fSGerry Weißbach            }
93dfb6ef8fSGerry Weißbach
947d101cc1SGerry Weißbach            // if not there, no map ids will be generated
958a20a4b4SGerry Weißbach            $elem['mapID'] = intval($elem['exists']) == 1 ? $this->functions->getMapID($elem['id'], $elem['anchor'], $check) : array();
967d101cc1SGerry Weißbach
970571ece2SScrutinizer Auto-Fixer            if ( empty($elem['depth']) ) {
980571ece2SScrutinizer Auto-Fixer                $elem['depth'] = count(explode('/', $elem['url']));
990571ece2SScrutinizer Auto-Fixer            }
1007d101cc1SGerry Weißbach            $CHECKDATA[] = $elem['url'];
1017d101cc1SGerry Weißbach
1027d101cc1SGerry Weißbach            if ( $startPageID == null )
1037d101cc1SGerry Weißbach            {
1047d101cc1SGerry Weißbach                $startPageID = $elem['mapID'][0];
1057d101cc1SGerry Weißbach            }
1067d101cc1SGerry Weißbach
1076f66113cSGerry Weißbach            if ( empty( $elem['name'] ) || $elem['name'] == noNs($elem['id']) ) {
1086ba764b8SGerry Weißbach                $elem['name'] = $this->functions->getSiteTitle($elem['id']);
10913aaf300SGerry Weißbach                $this->debug($elem);
1106ba764b8SGerry Weißbach            }
1116ba764b8SGerry Weißbach
1127d101cc1SGerry Weißbach            // Go on building mapXML
1137d101cc1SGerry Weißbach            $this->shortenByTranslation($elem['mapURL'], true); // true to already remove all language stuff - false if not
1147d101cc1SGerry Weißbach            foreach ( $elem['mapID'] as $VIEWID ) {
1157d101cc1SGerry Weißbach                $MAPXML .= "\n\t<mapID target=\"$VIEWID\" url=\"" . $elem['mapURL'] . $anchor . "\"/>";
1167d101cc1SGerry Weißbach            }
1177d101cc1SGerry Weißbach
1187d101cc1SGerry Weißbach            $elem['tocNS'] = getNS(cleanID($elem['url']));
1192c9ab2bbSGerry Weißbach            $elem['tocNS'] = $this->shortenByTranslation($elem['tocNS'], true);
1202c9ab2bbSGerry Weißbach            $elem['tocNS'] = strlen($elem['tocNS']) > 0 ? explode('/', $elem['tocNS']) : array();
1216ba764b8SGerry Weißbach            $this->functions->debug->message("This will be the TOC elements data:", $elem, 1);
1227d101cc1SGerry Weißbach
1237d101cc1SGerry Weißbach            $this->__buildTOCTree($DATA, $elem['tocNS'], $elem);
1247d101cc1SGerry Weißbach        }
1257d101cc1SGerry Weißbach
12613aaf300SGerry Weißbach        $this->debug("#### Writing TOC Tree ####");
1277d101cc1SGerry Weißbach        $TOCXML .= $this->__writeTOCTree($DATA) . "\n</toc>";
12813aaf300SGerry Weißbach        $this->debug("#### DONE: Writing TOC Tree ####");
1297d101cc1SGerry Weißbach        $MAPXML .= "\n</map>";
13001a1f586SGerry Weißbach
1312c9ab2bbSGerry Weißbach        $this->debug($DATA);
1322c9ab2bbSGerry Weißbach        $this->debug($TOCXML);
1333bda080dSGerry Weißbach        $this->debug($MAPXML);
1347d101cc1SGerry Weißbach
1357d101cc1SGerry Weißbach        return array($TOCXML, $MAPXML, $startPageID);
1367d101cc1SGerry Weißbach    }
1377d101cc1SGerry Weißbach
1387d101cc1SGerry Weißbach    /**
1397d101cc1SGerry Weißbach     * Prepare the TOC Tree
1407d101cc1SGerry Weißbach     **/
1417d101cc1SGerry Weißbach    private function __buildTOCTree(&$DATA, $currentNSArray, $elemToAdd)
1427d101cc1SGerry Weißbach    {
1437d101cc1SGerry Weißbach        global $conf;
1447d101cc1SGerry Weißbach
1452c9ab2bbSGerry Weißbach        // Actual level
1462c9ab2bbSGerry Weißbach        if (empty($currentNSArray)) {
14724b1b4baSGerry Weißbach            $elemToAdd['isStartPage'] = noNS($elemToAdd['id']) == $conf['start'];
14851917f25SGerry Weißbach            // $key = empty($elemToAdd['name']) || 1==1 ? noNS($elemToAdd['id']) : $elemToAdd['name'];
1490965d97cSGerry Weißbach            $key = noNS($elemToAdd['id']);
1500965d97cSGerry Weißbach            $DATA[$key] = $elemToAdd;
1517d101cc1SGerry Weißbach            return;
1527d101cc1SGerry Weißbach        }
1537d101cc1SGerry Weißbach
1547d101cc1SGerry Weißbach        $currentLevel = array_shift($currentNSArray);
15501a1f586SGerry Weißbach        $nextLevel = &$DATA[$currentLevel];
15601a1f586SGerry Weißbach        if (empty($nextLevel)) {
1572c9ab2bbSGerry Weißbach            $nextLevel = array('pages' => array());
15801a1f586SGerry Weißbach        } else {
15901a1f586SGerry Weißbach            $nextLevel = &$DATA[$currentLevel]['pages'];
1607d101cc1SGerry Weißbach        }
1617d101cc1SGerry Weißbach
16201a1f586SGerry Weißbach        $this->__buildTOCTree($nextLevel, $currentNSArray, $elemToAdd);
1637d101cc1SGerry Weißbach    }
1647d101cc1SGerry Weißbach
1657d101cc1SGerry Weißbach    /**
1667d101cc1SGerry Weißbach     * Create a single TOC Item
1677d101cc1SGerry Weißbach     **/
1687d101cc1SGerry Weißbach    private function __TOCItem($item, $depth, $selfClosed = true)
1697d101cc1SGerry Weißbach    {
17013aaf300SGerry Weißbach        $this->debug($item);
1717d101cc1SGerry Weißbach        $targetID = $item['mapID'][0];
1727d101cc1SGerry Weißbach        if (empty($targetID)) {
1737d101cc1SGerry Weißbach            $targetID = strtolower($item['name']);
1747d101cc1SGerry Weißbach        }
1757d101cc1SGerry Weißbach        return "\n" . str_repeat("\t", max($depth, 0)+1) . "<tocitem target=\"$targetID\"" . (intval($item['exists']) == 1 ? " text=\"" . $item['name'] . "\"" : "") . ($selfClosed ? '/' : '') . ">";
1767d101cc1SGerry Weißbach    }
1777d101cc1SGerry Weißbach
1787d101cc1SGerry Weißbach    /**
1797d101cc1SGerry Weißbach     * Create a single TOC Item
1807d101cc1SGerry Weißbach     **/
1817d101cc1SGerry Weißbach    private function __TOCItemClose($depth)
1827d101cc1SGerry Weißbach    {
1837d101cc1SGerry Weißbach        return "\n" . str_repeat("\t", max($depth, 0)+1) . "</tocitem>";
1847d101cc1SGerry Weißbach    }
1857d101cc1SGerry Weißbach
1867d101cc1SGerry Weißbach    /**
1877d101cc1SGerry Weißbach     * Write the whole TOC TREE
1887d101cc1SGerry Weißbach     **/
1897d101cc1SGerry Weißbach    private function __writeTOCTree($CURRENTNODE, $CURRENTNODENAME = null, $DEPTH = 0) {
1907d101cc1SGerry Weißbach        global $conf;
1917d101cc1SGerry Weißbach
1927d101cc1SGerry Weißbach        $XML = '';
1937d101cc1SGerry Weißbach        $didOpenItem = false;
1947d101cc1SGerry Weißbach        if (!is_array($CURRENTNODE) || empty($CURRENTNODE))
1957d101cc1SGerry Weißbach        {
1967d101cc1SGerry Weißbach            // errr … no.
1977d101cc1SGerry Weißbach            return $XML;
1987d101cc1SGerry Weißbach        }
1997d101cc1SGerry Weißbach
2007d101cc1SGerry Weißbach        // This is an element!
201f3b52d8fSGerry Weißbach        if (!empty($CURRENTNODE['id']) && empty($CURRENTNODE['pages']))
2027d101cc1SGerry Weißbach        {
203f3b52d8fSGerry Weißbach            // This has to be an item - only -!
2047d101cc1SGerry Weißbach            return $this->__TOCItem($CURRENTNODE, $DEPTH);
2057d101cc1SGerry Weißbach        }
2067d101cc1SGerry Weißbach
2077d101cc1SGerry Weißbach        // Look for start page
2087d101cc1SGerry Weißbach        if (!empty($CURRENTNODE[$conf['start']]))
2097d101cc1SGerry Weißbach        {
2107d101cc1SGerry Weißbach            // YAY! StartPage found.
21101a1f586SGerry Weißbach            $didOpenItem = !(count(empty($CURRENTNODE['pages']) ? $CURRENTNODE : $CURRENTNODE['pages']) == 0);
2127d101cc1SGerry Weißbach            $XML .= $this->__TOCItem($CURRENTNODE[$conf['start']], $DEPTH, !$didOpenItem);
2137d101cc1SGerry Weißbach            unset($CURRENTNODE[$conf['start']]);
21401a1f586SGerry Weißbach        } else if (!empty($CURRENTNODE['element'])) {
21501a1f586SGerry Weißbach            $didOpenItem = !(count($CURRENTNODE['pages']) == 0);
21601a1f586SGerry Weißbach            $XML .= $this->__TOCItem($CURRENTNODE['element'], $DEPTH, !$didOpenItem);
21701a1f586SGerry Weißbach            unset($CURRENTNODE['element']);
2187d101cc1SGerry Weißbach        } else if ($CURRENTNODENAME != null) {
2197d101cc1SGerry Weißbach            // We have a parent node for what is comming … lets honor that
2207d101cc1SGerry Weißbach            $didOpenItem = !(count($CURRENTNODE) == 0);
2217d101cc1SGerry Weißbach            $XML .= $this->__TOCItem(array('name' => ucwords($CURRENTNODENAME)), $DEPTH, !$didOpenItem);
2227d101cc1SGerry Weißbach        } else {
2237d101cc1SGerry Weißbach            // Woohoo … empty node? do not count up!
2247d101cc1SGerry Weißbach            $DEPTH--;
2257d101cc1SGerry Weißbach        }
2267d101cc1SGerry Weißbach
2273bda080dSGerry Weißbach        $this->debug("-- This is the current node --");
2283bda080dSGerry Weißbach        $this->debug($CURRENTNODE);
2293bda080dSGerry Weißbach
2307d101cc1SGerry Weißbach        // Circle through the entries
23101a1f586SGerry Weißbach        foreach (empty($CURRENTNODE['pages']) ? $CURRENTNODE : $CURRENTNODE['pages'] as $NODENAME => $ELEM)
2327d101cc1SGerry Weißbach        {
2337d101cc1SGerry Weißbach            // a node should have more than only one entry … otherwise we will not tell our name!
23413aaf300SGerry Weißbach            $XML .= $this->__writeTOCTree($ELEM, count($ELEM) >= 1 ? ( !empty($ELEM['name']) ? $ELEM['name'] : $NODENAME ) : null, $DEPTH+1);
2357d101cc1SGerry Weißbach        }
2367d101cc1SGerry Weißbach
2377d101cc1SGerry Weißbach        // Close and return
2387d101cc1SGerry Weißbach        return $XML . ($didOpenItem ? $this->__TOCItemClose($DEPTH) : '');
2397d101cc1SGerry Weißbach    }
2407d101cc1SGerry Weißbach
2417d101cc1SGerry Weißbach    /**
2427d101cc1SGerry Weißbach     * Build the Eclipse Documentation TOC XML
2437d101cc1SGerry Weißbach     **/
2447d101cc1SGerry Weißbach    public function __getTOCXML($DATA, $XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?NLS TYPE=\"org.eclipse.help.toc\"?>\n") {
2457d101cc1SGerry Weißbach
2467d101cc1SGerry Weißbach        $pagesArray = array();
2477d101cc1SGerry Weißbach
2487d101cc1SGerry Weißbach        // Go through the pages
2497d101cc1SGerry Weißbach        foreach ($DATA as $elem) {
2507d101cc1SGerry Weißbach
2517d101cc1SGerry Weißbach            $site = $elem['id'];
2527d101cc1SGerry Weißbach            $elems = explode('/', $this->functions->getSiteName($site));
2537d101cc1SGerry Weißbach
2547d101cc1SGerry Weißbach            // Strip Site
2557d101cc1SGerry Weißbach            array_pop($elems);
2567d101cc1SGerry Weißbach
2577d101cc1SGerry Weißbach            // build the topic Tree
2587d101cc1SGerry Weißbach            $this->__buildTopicTree($pagesArray, $elems, $site);
2597d101cc1SGerry Weißbach        }
2607d101cc1SGerry Weißbach
2617d101cc1SGerry Weißbach        $XML .= $this->__addXMLTopic($pagesArray, 'toc');
2627d101cc1SGerry Weißbach
2637d101cc1SGerry Weißbach        return $XML;
2647d101cc1SGerry Weißbach
2657d101cc1SGerry Weißbach    }
2667d101cc1SGerry Weißbach
2677d101cc1SGerry Weißbach    /**
2687d101cc1SGerry Weißbach     * Load the topic Tree for the TOC - recursive
2697d101cc1SGerry Weißbach     **/
2707d101cc1SGerry Weißbach    private function __buildTopicTree(&$PAGES, $DATA, $SITE, $INSERTDATA = null) {
2717d101cc1SGerry Weißbach
2727d101cc1SGerry Weißbach        if (empty($DATA) || !is_array($DATA)) {
2737d101cc1SGerry Weißbach
2747d101cc1SGerry Weißbach            if ($INSERTDATA == null)
2757d101cc1SGerry Weißbach            {
2767d101cc1SGerry Weißbach                $INSERTDATA = $SITE;
2777d101cc1SGerry Weißbach            }
2787d101cc1SGerry Weißbach
2797d101cc1SGerry Weißbach            // This is already a namespace
2807d101cc1SGerry Weißbach            if (is_array($PAGES[noNS($SITE)])) {
2817d101cc1SGerry Weißbach                // The root already exists!
2827d101cc1SGerry Weißbach                if (!empty($PAGES[noNS($SITE)][noNS($SITE)])) {
2837d101cc1SGerry Weißbach                    if (strstr($PAGES[noNS($SITE)][noNS($SITE)], $SITE)) {
2847d101cc1SGerry Weißbach                        // The SITE is in the parent Namespace, and the current Namespace has an index with same name
2857d101cc1SGerry Weißbach                        $PAGES['__' . noNS($SITE)] = $INSERTDATA;
2867d101cc1SGerry Weißbach                    } else {
2877d101cc1SGerry Weißbach                        $PAGES['__' . noNS($SITE)] = $PAGES[noNS($SITE)][noNS($SITE)];
2887d101cc1SGerry Weißbach                        $PAGES[noNS($SITE)][noNS($SITE)] = $INSERTDATA;
2897d101cc1SGerry Weißbach                    }
2907d101cc1SGerry Weißbach                } else {
2917d101cc1SGerry Weißbach                    $PAGES[noNS($SITE)][noNS($SITE)] = $INSERTDATA;
2927d101cc1SGerry Weißbach                }
2937d101cc1SGerry Weißbach            } else {
2947d101cc1SGerry Weißbach                // just a Page
2957d101cc1SGerry Weißbach                $PAGES[noNS($SITE)] = $INSERTDATA;
2967d101cc1SGerry Weißbach            }
2977d101cc1SGerry Weißbach            return;
2987d101cc1SGerry Weißbach        }
2997d101cc1SGerry Weißbach
3007d101cc1SGerry Weißbach        $NS = array_shift($DATA);
3017d101cc1SGerry Weißbach        if (!is_array($PAGES[$NS])) $PAGES[$NS] = empty($PAGES[$NS]) ? array() : array($PAGES[$NS]);
3027d101cc1SGerry Weißbach        $this->__buildTopicTree($PAGES[$NS], $DATA, $SITE, $INSERTDATA);
3037d101cc1SGerry Weißbach
3047d101cc1SGerry Weißbach        return;
3057d101cc1SGerry Weißbach    }
3067d101cc1SGerry Weißbach
3077d101cc1SGerry Weißbach    /**
3087d101cc1SGerry Weißbach     * Build the Topic Tree for TOC.xml
3097d101cc1SGerry Weißbach     **/
3107d101cc1SGerry Weißbach    private function __addXMLTopic($DATA, $ITEM = 'topic', $LEVEL = 0, $NODENAME = '') {
3117d101cc1SGerry Weißbach        global $conf;
3127d101cc1SGerry Weißbach
3137d101cc1SGerry Weißbach        $DEPTH = str_repeat("\t", $LEVEL);
3147d101cc1SGerry Weißbach
3157d101cc1SGerry Weißbach        if (!is_array($DATA)) {
3167d101cc1SGerry Weißbach            return $DEPTH . '<' . $ITEM . ' label="' . $this->functions->getSiteTitle($DATA) . '" ' . ($ITEM != 'topic' ? 'topic' : 'href') . '="' . $this->functions->getSiteName($DATA) . "\" />\n";
3177d101cc1SGerry Weißbach        }
3187d101cc1SGerry Weißbach        // Is array from this point on
3197d101cc1SGerry Weißbach        list($indexTitle, $indexFile) = $this->__getIndexItem($DATA, $NODENAME);
3207d101cc1SGerry Weißbach
3217d101cc1SGerry Weißbach        if (empty($indexTitle)) $indexTitle = $this->functions->getSiteTitle($conf['start']);
3227d101cc1SGerry Weißbach        if (!empty($indexFile)) $indexFile = ($ITEM != 'topic' ? 'topic' : 'href') . "=\"$indexFile\"";
3237d101cc1SGerry Weißbach
3247d101cc1SGerry Weißbach        $isEmptyNode = count($DATA) == 1 && empty($indexFile);
3257d101cc1SGerry Weißbach
326a8c17ab5Si-net /// software        if (!$isEmptyNode && ($this->emptyNSToc || count($DATA) > 0)) {
3277d101cc1SGerry Weißbach            $XML = "$DEPTH<$ITEM label=\"$indexTitle\" $indexFile>";
328a8c17ab5Si-net /// software        } else {
329a8c17ab5Si-net /// software            $XML = "";
330a8c17ab5Si-net /// software        }
3317d101cc1SGerry Weißbach
3327d101cc1SGerry Weißbach        if (!$isEmptyNode && count($DATA) > 0) $XML .= "\n";
3337d101cc1SGerry Weißbach
3347d101cc1SGerry Weißbach        foreach ($DATA as $NODENAME => $NS) {
3357d101cc1SGerry Weißbach            $XML .= $this->__addXMLTopic($NS, (!($this->emptyNSToc || count($DATA) > 1) && $ITEM != 'topic' ? $ITEM : 'topic'), $LEVEL+(!$isEmptyNode ? 1 : 0), $NODENAME);
3367d101cc1SGerry Weißbach        }
3377d101cc1SGerry Weißbach
3387d101cc1SGerry Weißbach        if (!$isEmptyNode && count($DATA) > 0) $XML .= "$DEPTH";
3397d101cc1SGerry Weißbach        if (!$isEmptyNode && ($this->emptyNSToc || count($DATA) > 0)) {
3407d101cc1SGerry Weißbach            $XML .= "</$ITEM>\n";
3417d101cc1SGerry Weißbach        }
3427d101cc1SGerry Weißbach
3437d101cc1SGerry Weißbach        return $XML;
3447d101cc1SGerry Weißbach    }
3457d101cc1SGerry Weißbach
3467d101cc1SGerry Weißbach
3477d101cc1SGerry Weißbach    /**
3487d101cc1SGerry Weißbach     * Get the context XML
3497d101cc1SGerry Weißbach     **/
3507d101cc1SGerry Weißbach    public function __getContextXML($DATA) {
3517d101cc1SGerry Weißbach
3527d101cc1SGerry Weißbach        $XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?NLS TYPE=\"org.eclipse.help.context\"?>\n<contexts>\n";
3537d101cc1SGerry Weißbach
3547d101cc1SGerry Weißbach        $check = array();
3557d101cc1SGerry Weißbach        foreach ($DATA as $elem)
3567d101cc1SGerry Weißbach        {
3577d101cc1SGerry Weißbach            $ID = $elem['id'];
3587d101cc1SGerry Weißbach            $meta = p_get_metadata($ID, 'context', true);
3597d101cc1SGerry Weißbach            if (empty($meta['id'])) { continue; }
3607d101cc1SGerry Weißbach
3617d101cc1SGerry Weißbach            $TITLE = empty($meta['title']) ? $this->functions->getSiteTitle($ID) : $meta['title'];
3627d101cc1SGerry Weißbach
3637d101cc1SGerry Weißbach            // support more than one view IDs ... for more than one reference
3648a20a4b4SGerry Weißbach            $VIEWIDs = $this->functions->getMapID($elem['id'], $elem['anchor'], $check);
3657d101cc1SGerry Weißbach
3667d101cc1SGerry Weißbach            $DESCRIPTION = $this->functions->xmlEntities(p_get_metadata($ID, 'description abstract'));
3677d101cc1SGerry Weißbach
3687d101cc1SGerry Weißbach            // Build topic Links
3697d101cc1SGerry Weißbach            $url = $this->functions->getSiteName($ID);
3707d101cc1SGerry Weißbach            $this->shortenByTranslation($url);
3717d101cc1SGerry Weißbach
3727d101cc1SGerry Weißbach            $TOPICS = array($url => $TITLE . " (Details)");
3737d101cc1SGerry Weißbach            $REFS = p_get_metadata($ID, 'relation references', true);
3747d101cc1SGerry Weißbach            if (is_array($REFS))
3757d101cc1SGerry Weißbach            foreach ($REFS as $REL => $EXISTS) {
3767d101cc1SGerry Weißbach                if (!$EXISTS) { continue; }
3777d101cc1SGerry Weißbach                $TOPICS[$this->functions->getSiteName($REL)] = $this->functions->getSiteTitle($REL);
3787d101cc1SGerry Weißbach            }
3797d101cc1SGerry Weißbach
3807d101cc1SGerry Weißbach            // build XML - include multi view IDs
3817d101cc1SGerry Weißbach            foreach ($VIEWIDs as $VIEWID) {
3827d101cc1SGerry Weißbach                $XML .= "\t<context id=\"$VIEWID\" title=\"$TITLE\">\n";
3837d101cc1SGerry Weißbach                $XML .= "\t\t<description>$DESCRIPTION</description>\n";
3847d101cc1SGerry Weißbach
3857d101cc1SGerry Weißbach                foreach ($TOPICS as $URL => $LABEL) {
3867d101cc1SGerry Weißbach                    $XML .= "\t\t<topic label=\"$LABEL\" href=\"$URL\" />\n";
3877d101cc1SGerry Weißbach                }
3887d101cc1SGerry Weißbach
3897d101cc1SGerry Weißbach                $XML .= "\t</context>\n";
3907d101cc1SGerry Weißbach            }
3917d101cc1SGerry Weißbach        }
3927d101cc1SGerry Weißbach
3937d101cc1SGerry Weißbach        $XML .= "</contexts>";
3947d101cc1SGerry Weißbach        return $XML;
3957d101cc1SGerry Weißbach
3967d101cc1SGerry Weißbach    }
3977d101cc1SGerry Weißbach
3987d101cc1SGerry Weißbach    /**
3997d101cc1SGerry Weißbach     * Determine if this is an index - and if so, find its Title
4007d101cc1SGerry Weißbach     **/
4017d101cc1SGerry Weißbach    private function __getIndexItem(&$DATA, $NODENAME = '') {
4027d101cc1SGerry Weißbach        global $conf;
4037d101cc1SGerry Weißbach
4047d101cc1SGerry Weißbach        if (!is_array($DATA)) { return; }
4057d101cc1SGerry Weißbach
4067d101cc1SGerry Weißbach        $indexTitle = '';
4077d101cc1SGerry Weißbach        $indexFile = '';
4087d101cc1SGerry Weißbach        foreach ($DATA as $NODE => $indexSearch) {
4097d101cc1SGerry Weißbach            // Skip next Namespaces
4107d101cc1SGerry Weißbach            if (is_array($indexSearch)) { continue; }
4117d101cc1SGerry Weißbach
4127d101cc1SGerry Weißbach            // Skip if this is not a start
4137d101cc1SGerry Weißbach            if ($NODE != $conf['start']) { continue; }
4147d101cc1SGerry Weißbach
4157d101cc1SGerry Weißbach            $indexTitle = $this->functions->getSiteTitle($indexSearch);
4167d101cc1SGerry Weißbach            $indexFile = $indexSearch;
4177d101cc1SGerry Weißbach            unset($DATA[$NODE]);
4187d101cc1SGerry Weißbach            break;
4197d101cc1SGerry Weißbach        }
4207d101cc1SGerry Weißbach
4217d101cc1SGerry Weißbach        if (empty($indexFile) && !empty($DATA[$NODENAME])) {
4227d101cc1SGerry Weißbach            $indexTitle = $this->functions->getSiteTitle($DATA[$NODENAME]);
4237d101cc1SGerry Weißbach            $indexFile = $DATA[$NODENAME];
4247d101cc1SGerry Weißbach            unset($DATA[$NODENAME]);
4257d101cc1SGerry Weißbach        }
4267d101cc1SGerry Weißbach
4277d101cc1SGerry Weißbach        return array($indexTitle, $this->functions->getSiteName($indexFile));
4287d101cc1SGerry Weißbach    }
4292c9ab2bbSGerry Weißbach
4302c9ab2bbSGerry Weißbach    private $doDebug = false;
4312c9ab2bbSGerry Weißbach    private static $didDebug = false;
4323bda080dSGerry Weißbach    public function debug($data, $final = false) {
4332c9ab2bbSGerry Weißbach        if ( ! $this->doDebug ) { return; }
4342c9ab2bbSGerry Weißbach
4352c9ab2bbSGerry Weißbach        if ( !$this->didDebug ) {
4362c9ab2bbSGerry Weißbach            print "<html><pre>";
4372c9ab2bbSGerry Weißbach            $this->didDebug = true;
4387d101cc1SGerry Weißbach        }
4397d101cc1SGerry Weißbach
4402c9ab2bbSGerry Weißbach        if ( is_array($data) ) {
4412c9ab2bbSGerry Weißbach            print_r($data);
4422c9ab2bbSGerry Weißbach        } else {
4432c9ab2bbSGerry Weißbach            print str_replace("<", "&lt;", str_replace(">", "&gt;", $data));;
4442c9ab2bbSGerry Weißbach        }
4452c9ab2bbSGerry Weißbach
4462c9ab2bbSGerry Weißbach        print "\n\n";
4472c9ab2bbSGerry Weißbach
4482c9ab2bbSGerry Weißbach        if ( $final ) {
4492c9ab2bbSGerry Weißbach            print "</pre></html>";
4502c9ab2bbSGerry Weißbach            exit;
4512c9ab2bbSGerry Weißbach        }
4522c9ab2bbSGerry Weißbach    }
4532c9ab2bbSGerry Weißbach}
454