xref: /plugin/siteexport/inc/toc.php (revision a8c17ab5b37308343f86651acb8c4a1b3f36f0ae)
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);
24*a8c17ab5Si-net /// software
25*a8c17ab5Si-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*a8c17ab5Si-net /// software        for ($i = count($url); $i >=0 ; $i--)
307d101cc1SGerry Weißbach        {
31a0726238SGerry Weißbach            if (in_array($url[$i], $checkArray))
327d101cc1SGerry Weißbach            {
337d101cc1SGerry Weißbach                // Rauswerfen und weg
347d101cc1SGerry Weißbach                $url[$i] = '';
357d101cc1SGerry Weißbach                break;
367d101cc1SGerry Weißbach            }
377d101cc1SGerry Weißbach
387d101cc1SGerry Weißbach            if (!$deepSearch)
397d101cc1SGerry Weißbach            {
407d101cc1SGerry Weißbach                break;
417d101cc1SGerry Weißbach            }
427d101cc1SGerry Weißbach
437d101cc1SGerry Weißbach            // Ok, remove anyway
447d101cc1SGerry Weißbach            $url[$i] = '';
457d101cc1SGerry Weißbach        }
467d101cc1SGerry Weißbach
477d101cc1SGerry Weißbach        $inputURL = implode('/', $url);
487d101cc1SGerry Weißbach        $inputURL = preg_replace("$\/+$", "/", $inputURL);
497d101cc1SGerry Weißbach
507d101cc1SGerry Weißbach        if (strlen($inputURL) > 0 && substr($inputURL, 0, 1) == '/')
517d101cc1SGerry Weißbach        {
527d101cc1SGerry Weißbach            $inputURL = substr($inputURL, 1);
537d101cc1SGerry Weißbach        }
547d101cc1SGerry Weißbach
557d101cc1SGerry Weißbach        return $inputURL;
567d101cc1SGerry Weißbach    }
577d101cc1SGerry Weißbach
587d101cc1SGerry Weißbach    /**
597d101cc1SGerry Weißbach     * Build the Java Documentation TOC XML
607d101cc1SGerry Weißbach     **/
617d101cc1SGerry Weißbach    public function __getJavaHelpTOCXML($DATA) {
627d101cc1SGerry Weißbach
637d101cc1SGerry Weißbach        if (count($DATA) == 0) {
647d101cc1SGerry Weißbach            return false;
657d101cc1SGerry Weißbach        }
667d101cc1SGerry Weißbach
677d101cc1SGerry Weißbach        $TOCXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<toc>";
687d101cc1SGerry Weißbach        $MAPXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<map version=\"1.0\">";
697d101cc1SGerry Weißbach
707d101cc1SGerry Weißbach        // Go through the pages
717d101cc1SGerry Weißbach        $CHECKDATA = array();
727d101cc1SGerry Weißbach        $nData = $DATA;
737d101cc1SGerry Weißbach        $DATA = array();
747d101cc1SGerry Weißbach        $check = array();
757d101cc1SGerry Weißbach        $startPageID = null;
767d101cc1SGerry Weißbach
777d101cc1SGerry Weißbach        foreach ( $nData as $elem )
787d101cc1SGerry Weißbach        {
797d101cc1SGerry Weißbach            // Check if available
807d101cc1SGerry Weißbach            $anchor = ( !empty($elem['anchor']) ? '#' . $elem['anchor'] : '' );
81d9cefbd9SGerry Weißbach            $elem['url'] = $this->functions->getSiteName($elem['id'], true); // Override - we need a clean name
827d101cc1SGerry Weißbach            $elem['mapURL'] = $elem['url'];
837d101cc1SGerry Weißbach            $this->shortenByTranslation($elem['url']);
847d101cc1SGerry Weißbach
857d101cc1SGerry Weißbach            // only add an url once
867d101cc1SGerry Weißbach            if ( in_array($elem['url'], $CHECKDATA) ) { continue; }
877d101cc1SGerry Weißbach
88dfb6ef8fSGerry Weißbach            if ( !isset($elem['exists']) ) {
89dfb6ef8fSGerry Weißbach                resolve_pageid(getNS($elem['id']),$elem['id'],$elem['exists']);
90dfb6ef8fSGerry Weißbach                $this->functions->debug->message("EXISTS previously not set.", $elem, 1);
91dfb6ef8fSGerry Weißbach            }
92dfb6ef8fSGerry Weißbach
937d101cc1SGerry Weißbach            // if not there, no map ids will be generated
948a20a4b4SGerry Weißbach            $elem['mapID'] = intval($elem['exists']) == 1 ? $this->functions->getMapID($elem['id'], $elem['anchor'], $check) : array();
957d101cc1SGerry Weißbach
960571ece2SScrutinizer Auto-Fixer            if ( empty($elem['depth']) ) {
970571ece2SScrutinizer Auto-Fixer                $elem['depth'] = count(explode('/', $elem['url']));
980571ece2SScrutinizer Auto-Fixer            }
997d101cc1SGerry Weißbach            $CHECKDATA[] = $elem['url'];
1007d101cc1SGerry Weißbach
1017d101cc1SGerry Weißbach            if ( $startPageID == null )
1027d101cc1SGerry Weißbach            {
1037d101cc1SGerry Weißbach                $startPageID = $elem['mapID'][0];
1047d101cc1SGerry Weißbach            }
1057d101cc1SGerry Weißbach
1066f66113cSGerry Weißbach            if ( empty( $elem['name'] ) || $elem['name'] == noNs($elem['id']) ) {
1076ba764b8SGerry Weißbach                $elem['name'] = $this->functions->getSiteTitle($elem['id']);
10813aaf300SGerry Weißbach                $this->debug($elem);
1096ba764b8SGerry Weißbach            }
1106ba764b8SGerry Weißbach
1117d101cc1SGerry Weißbach            // Go on building mapXML
1127d101cc1SGerry Weißbach            $this->shortenByTranslation($elem['mapURL'], true); // true to already remove all language stuff - false if not
1137d101cc1SGerry Weißbach            foreach ( $elem['mapID'] as $VIEWID ) {
1147d101cc1SGerry Weißbach                $MAPXML .= "\n\t<mapID target=\"$VIEWID\" url=\"" . $elem['mapURL'] . $anchor . "\"/>";
1157d101cc1SGerry Weißbach            }
1167d101cc1SGerry Weißbach
1177d101cc1SGerry Weißbach            $elem['tocNS'] = getNS(cleanID($elem['url']));
1182c9ab2bbSGerry Weißbach            $elem['tocNS'] = $this->shortenByTranslation($elem['tocNS'], true);
1192c9ab2bbSGerry Weißbach            $elem['tocNS'] = strlen($elem['tocNS']) > 0 ? explode('/', $elem['tocNS']) : array();
1206ba764b8SGerry Weißbach            $this->functions->debug->message("This will be the TOC elements data:", $elem, 1);
1217d101cc1SGerry Weißbach
1227d101cc1SGerry Weißbach            $this->__buildTOCTree($DATA, $elem['tocNS'], $elem);
1237d101cc1SGerry Weißbach        }
1247d101cc1SGerry Weißbach
12513aaf300SGerry Weißbach        $this->debug("#### Writing TOC Tree ####");
1267d101cc1SGerry Weißbach        $TOCXML .= $this->__writeTOCTree($DATA) . "\n</toc>";
12713aaf300SGerry Weißbach        $this->debug("#### DONE: Writing TOC Tree ####");
1287d101cc1SGerry Weißbach        $MAPXML .= "\n</map>";
12901a1f586SGerry Weißbach
1302c9ab2bbSGerry Weißbach        $this->debug($DATA);
1312c9ab2bbSGerry Weißbach        $this->debug($TOCXML);
1323bda080dSGerry Weißbach        $this->debug($MAPXML);
1337d101cc1SGerry Weißbach
1347d101cc1SGerry Weißbach        return array($TOCXML, $MAPXML, $startPageID);
1357d101cc1SGerry Weißbach    }
1367d101cc1SGerry Weißbach
1377d101cc1SGerry Weißbach    /**
1387d101cc1SGerry Weißbach     * Prepare the TOC Tree
1397d101cc1SGerry Weißbach     **/
1407d101cc1SGerry Weißbach    private function __buildTOCTree(&$DATA, $currentNSArray, $elemToAdd)
1417d101cc1SGerry Weißbach    {
1427d101cc1SGerry Weißbach        global $conf;
1437d101cc1SGerry Weißbach
1442c9ab2bbSGerry Weißbach        // Actual level
1452c9ab2bbSGerry Weißbach        if (empty($currentNSArray)) {
14624b1b4baSGerry Weißbach            $elemToAdd['isStartPage'] = noNS($elemToAdd['id']) == $conf['start'];
14751917f25SGerry Weißbach            // $key = empty($elemToAdd['name']) || 1==1 ? noNS($elemToAdd['id']) : $elemToAdd['name'];
1480965d97cSGerry Weißbach            $key = noNS($elemToAdd['id']);
1490965d97cSGerry Weißbach            $DATA[$key] = $elemToAdd;
1507d101cc1SGerry Weißbach            return;
1517d101cc1SGerry Weißbach        }
1527d101cc1SGerry Weißbach
1537d101cc1SGerry Weißbach        $currentLevel = array_shift($currentNSArray);
15401a1f586SGerry Weißbach        $nextLevel = &$DATA[$currentLevel];
15501a1f586SGerry Weißbach        if (empty($nextLevel)) {
1562c9ab2bbSGerry Weißbach            $nextLevel = array('pages' => array());
15701a1f586SGerry Weißbach        } else {
15801a1f586SGerry Weißbach            $nextLevel = &$DATA[$currentLevel]['pages'];
1597d101cc1SGerry Weißbach        }
1607d101cc1SGerry Weißbach
16101a1f586SGerry Weißbach        $this->__buildTOCTree($nextLevel, $currentNSArray, $elemToAdd);
1627d101cc1SGerry Weißbach    }
1637d101cc1SGerry Weißbach
1647d101cc1SGerry Weißbach    /**
1657d101cc1SGerry Weißbach     * Create a single TOC Item
1667d101cc1SGerry Weißbach     **/
1677d101cc1SGerry Weißbach    private function __TOCItem($item, $depth, $selfClosed = true)
1687d101cc1SGerry Weißbach    {
16913aaf300SGerry Weißbach        $this->debug($item);
1707d101cc1SGerry Weißbach        $targetID = $item['mapID'][0];
1717d101cc1SGerry Weißbach        if (empty($targetID)) {
1727d101cc1SGerry Weißbach            $targetID = strtolower($item['name']);
1737d101cc1SGerry Weißbach        }
1747d101cc1SGerry Weißbach        return "\n" . str_repeat("\t", max($depth, 0)+1) . "<tocitem target=\"$targetID\"" . (intval($item['exists']) == 1 ? " text=\"" . $item['name'] . "\"" : "") . ($selfClosed ? '/' : '') . ">";
1757d101cc1SGerry Weißbach    }
1767d101cc1SGerry Weißbach
1777d101cc1SGerry Weißbach    /**
1787d101cc1SGerry Weißbach     * Create a single TOC Item
1797d101cc1SGerry Weißbach     **/
1807d101cc1SGerry Weißbach    private function __TOCItemClose($depth)
1817d101cc1SGerry Weißbach    {
1827d101cc1SGerry Weißbach        return "\n" . str_repeat("\t", max($depth, 0)+1) . "</tocitem>";
1837d101cc1SGerry Weißbach    }
1847d101cc1SGerry Weißbach
1857d101cc1SGerry Weißbach    /**
1867d101cc1SGerry Weißbach     * Write the whole TOC TREE
1877d101cc1SGerry Weißbach     **/
1887d101cc1SGerry Weißbach    private function __writeTOCTree($CURRENTNODE, $CURRENTNODENAME = null, $DEPTH = 0) {
1897d101cc1SGerry Weißbach        global $conf;
1907d101cc1SGerry Weißbach
1917d101cc1SGerry Weißbach        $XML = '';
1927d101cc1SGerry Weißbach        $didOpenItem = false;
1937d101cc1SGerry Weißbach        if (!is_array($CURRENTNODE) || empty($CURRENTNODE))
1947d101cc1SGerry Weißbach        {
1957d101cc1SGerry Weißbach            // errr … no.
1967d101cc1SGerry Weißbach            return $XML;
1977d101cc1SGerry Weißbach        }
1987d101cc1SGerry Weißbach
1997d101cc1SGerry Weißbach        // This is an element!
200f3b52d8fSGerry Weißbach        if (!empty($CURRENTNODE['id']) && empty($CURRENTNODE['pages']))
2017d101cc1SGerry Weißbach        {
202f3b52d8fSGerry Weißbach            // This has to be an item - only -!
2037d101cc1SGerry Weißbach            return $this->__TOCItem($CURRENTNODE, $DEPTH);
2047d101cc1SGerry Weißbach        }
2057d101cc1SGerry Weißbach
2067d101cc1SGerry Weißbach        // Look for start page
2077d101cc1SGerry Weißbach        if (!empty($CURRENTNODE[$conf['start']]))
2087d101cc1SGerry Weißbach        {
2097d101cc1SGerry Weißbach            // YAY! StartPage found.
21001a1f586SGerry Weißbach            $didOpenItem = !(count(empty($CURRENTNODE['pages']) ? $CURRENTNODE : $CURRENTNODE['pages']) == 0);
2117d101cc1SGerry Weißbach            $XML .= $this->__TOCItem($CURRENTNODE[$conf['start']], $DEPTH, !$didOpenItem);
2127d101cc1SGerry Weißbach            unset($CURRENTNODE[$conf['start']]);
21301a1f586SGerry Weißbach        } else if (!empty($CURRENTNODE['element'])) {
21401a1f586SGerry Weißbach            $didOpenItem = !(count($CURRENTNODE['pages']) == 0);
21501a1f586SGerry Weißbach            $XML .= $this->__TOCItem($CURRENTNODE['element'], $DEPTH, !$didOpenItem);
21601a1f586SGerry Weißbach            unset($CURRENTNODE['element']);
2177d101cc1SGerry Weißbach        } else if ($CURRENTNODENAME != null) {
2187d101cc1SGerry Weißbach            // We have a parent node for what is comming … lets honor that
2197d101cc1SGerry Weißbach            $didOpenItem = !(count($CURRENTNODE) == 0);
2207d101cc1SGerry Weißbach            $XML .= $this->__TOCItem(array('name' => ucwords($CURRENTNODENAME)), $DEPTH, !$didOpenItem);
2217d101cc1SGerry Weißbach        } else {
2227d101cc1SGerry Weißbach            // Woohoo … empty node? do not count up!
2237d101cc1SGerry Weißbach            $DEPTH--;
2247d101cc1SGerry Weißbach        }
2257d101cc1SGerry Weißbach
2263bda080dSGerry Weißbach        $this->debug("-- This is the current node --");
2273bda080dSGerry Weißbach        $this->debug($CURRENTNODE);
2283bda080dSGerry Weißbach
2297d101cc1SGerry Weißbach        // Circle through the entries
23001a1f586SGerry Weißbach        foreach (empty($CURRENTNODE['pages']) ? $CURRENTNODE : $CURRENTNODE['pages'] as $NODENAME => $ELEM)
2317d101cc1SGerry Weißbach        {
2327d101cc1SGerry Weißbach            // a node should have more than only one entry … otherwise we will not tell our name!
23313aaf300SGerry Weißbach            $XML .= $this->__writeTOCTree($ELEM, count($ELEM) >= 1 ? ( !empty($ELEM['name']) ? $ELEM['name'] : $NODENAME ) : null, $DEPTH+1);
2347d101cc1SGerry Weißbach        }
2357d101cc1SGerry Weißbach
2367d101cc1SGerry Weißbach        // Close and return
2377d101cc1SGerry Weißbach        return $XML . ($didOpenItem ? $this->__TOCItemClose($DEPTH) : '');
2387d101cc1SGerry Weißbach    }
2397d101cc1SGerry Weißbach
2407d101cc1SGerry Weißbach    /**
2417d101cc1SGerry Weißbach     * Build the Eclipse Documentation TOC XML
2427d101cc1SGerry Weißbach     **/
2437d101cc1SGerry Weißbach    public function __getTOCXML($DATA, $XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?NLS TYPE=\"org.eclipse.help.toc\"?>\n") {
2447d101cc1SGerry Weißbach
2457d101cc1SGerry Weißbach        $pagesArray = array();
2467d101cc1SGerry Weißbach
2477d101cc1SGerry Weißbach        // Go through the pages
2487d101cc1SGerry Weißbach        foreach ($DATA as $elem) {
2497d101cc1SGerry Weißbach
2507d101cc1SGerry Weißbach            $site = $elem['id'];
2517d101cc1SGerry Weißbach            $elems = explode('/', $this->functions->getSiteName($site));
2527d101cc1SGerry Weißbach
2537d101cc1SGerry Weißbach            // Strip Site
2547d101cc1SGerry Weißbach            array_pop($elems);
2557d101cc1SGerry Weißbach
2567d101cc1SGerry Weißbach            // build the topic Tree
2577d101cc1SGerry Weißbach            $this->__buildTopicTree($pagesArray, $elems, $site);
2587d101cc1SGerry Weißbach        }
2597d101cc1SGerry Weißbach
2607d101cc1SGerry Weißbach        $XML .= $this->__addXMLTopic($pagesArray, 'toc');
2617d101cc1SGerry Weißbach
2627d101cc1SGerry Weißbach        return $XML;
2637d101cc1SGerry Weißbach
2647d101cc1SGerry Weißbach    }
2657d101cc1SGerry Weißbach
2667d101cc1SGerry Weißbach    /**
2677d101cc1SGerry Weißbach     * Load the topic Tree for the TOC - recursive
2687d101cc1SGerry Weißbach     **/
2697d101cc1SGerry Weißbach    private function __buildTopicTree(&$PAGES, $DATA, $SITE, $INSERTDATA = null) {
2707d101cc1SGerry Weißbach
2717d101cc1SGerry Weißbach        if (empty($DATA) || !is_array($DATA)) {
2727d101cc1SGerry Weißbach
2737d101cc1SGerry Weißbach            if ($INSERTDATA == null)
2747d101cc1SGerry Weißbach            {
2757d101cc1SGerry Weißbach                $INSERTDATA = $SITE;
2767d101cc1SGerry Weißbach            }
2777d101cc1SGerry Weißbach
2787d101cc1SGerry Weißbach            // This is already a namespace
2797d101cc1SGerry Weißbach            if (is_array($PAGES[noNS($SITE)])) {
2807d101cc1SGerry Weißbach                // The root already exists!
2817d101cc1SGerry Weißbach                if (!empty($PAGES[noNS($SITE)][noNS($SITE)])) {
2827d101cc1SGerry Weißbach                    if (strstr($PAGES[noNS($SITE)][noNS($SITE)], $SITE)) {
2837d101cc1SGerry Weißbach                        // The SITE is in the parent Namespace, and the current Namespace has an index with same name
2847d101cc1SGerry Weißbach                        $PAGES['__' . noNS($SITE)] = $INSERTDATA;
2857d101cc1SGerry Weißbach                    } else {
2867d101cc1SGerry Weißbach                        $PAGES['__' . noNS($SITE)] = $PAGES[noNS($SITE)][noNS($SITE)];
2877d101cc1SGerry Weißbach                        $PAGES[noNS($SITE)][noNS($SITE)] = $INSERTDATA;
2887d101cc1SGerry Weißbach                    }
2897d101cc1SGerry Weißbach                } else {
2907d101cc1SGerry Weißbach                    $PAGES[noNS($SITE)][noNS($SITE)] = $INSERTDATA;
2917d101cc1SGerry Weißbach                }
2927d101cc1SGerry Weißbach            } else {
2937d101cc1SGerry Weißbach                // just a Page
2947d101cc1SGerry Weißbach                $PAGES[noNS($SITE)] = $INSERTDATA;
2957d101cc1SGerry Weißbach            }
2967d101cc1SGerry Weißbach            return;
2977d101cc1SGerry Weißbach        }
2987d101cc1SGerry Weißbach
2997d101cc1SGerry Weißbach        $NS = array_shift($DATA);
3007d101cc1SGerry Weißbach        if (!is_array($PAGES[$NS])) $PAGES[$NS] = empty($PAGES[$NS]) ? array() : array($PAGES[$NS]);
3017d101cc1SGerry Weißbach        $this->__buildTopicTree($PAGES[$NS], $DATA, $SITE, $INSERTDATA);
3027d101cc1SGerry Weißbach
3037d101cc1SGerry Weißbach        return;
3047d101cc1SGerry Weißbach    }
3057d101cc1SGerry Weißbach
3067d101cc1SGerry Weißbach    /**
3077d101cc1SGerry Weißbach     * Build the Topic Tree for TOC.xml
3087d101cc1SGerry Weißbach     **/
3097d101cc1SGerry Weißbach    private function __addXMLTopic($DATA, $ITEM = 'topic', $LEVEL = 0, $NODENAME = '') {
3107d101cc1SGerry Weißbach        global $conf;
3117d101cc1SGerry Weißbach
3127d101cc1SGerry Weißbach        $DEPTH = str_repeat("\t", $LEVEL);
3137d101cc1SGerry Weißbach
3147d101cc1SGerry Weißbach        if (!is_array($DATA)) {
3157d101cc1SGerry Weißbach            return $DEPTH . '<' . $ITEM . ' label="' . $this->functions->getSiteTitle($DATA) . '" ' . ($ITEM != 'topic' ? 'topic' : 'href') . '="' . $this->functions->getSiteName($DATA) . "\" />\n";
3167d101cc1SGerry Weißbach        }
3177d101cc1SGerry Weißbach        // Is array from this point on
3187d101cc1SGerry Weißbach        list($indexTitle, $indexFile) = $this->__getIndexItem($DATA, $NODENAME);
3197d101cc1SGerry Weißbach
3207d101cc1SGerry Weißbach        if (empty($indexTitle)) $indexTitle = $this->functions->getSiteTitle($conf['start']);
3217d101cc1SGerry Weißbach        if (!empty($indexFile)) $indexFile = ($ITEM != 'topic' ? 'topic' : 'href') . "=\"$indexFile\"";
3227d101cc1SGerry Weißbach
3237d101cc1SGerry Weißbach        $isEmptyNode = count($DATA) == 1 && empty($indexFile);
3247d101cc1SGerry Weißbach
325*a8c17ab5Si-net /// software        if (!$isEmptyNode && ($this->emptyNSToc || count($DATA) > 0)) {
3267d101cc1SGerry Weißbach            $XML = "$DEPTH<$ITEM label=\"$indexTitle\" $indexFile>";
327*a8c17ab5Si-net /// software        } else {
328*a8c17ab5Si-net /// software            $XML = "";
329*a8c17ab5Si-net /// software        }
3307d101cc1SGerry Weißbach
3317d101cc1SGerry Weißbach        if (!$isEmptyNode && count($DATA) > 0) $XML .= "\n";
3327d101cc1SGerry Weißbach
3337d101cc1SGerry Weißbach        foreach ($DATA as $NODENAME => $NS) {
3347d101cc1SGerry Weißbach            $XML .= $this->__addXMLTopic($NS, (!($this->emptyNSToc || count($DATA) > 1) && $ITEM != 'topic' ? $ITEM : 'topic'), $LEVEL+(!$isEmptyNode ? 1 : 0), $NODENAME);
3357d101cc1SGerry Weißbach        }
3367d101cc1SGerry Weißbach
3377d101cc1SGerry Weißbach        if (!$isEmptyNode && count($DATA) > 0) $XML .= "$DEPTH";
3387d101cc1SGerry Weißbach        if (!$isEmptyNode && ($this->emptyNSToc || count($DATA) > 0)) {
3397d101cc1SGerry Weißbach            $XML .= "</$ITEM>\n";
3407d101cc1SGerry Weißbach        }
3417d101cc1SGerry Weißbach
3427d101cc1SGerry Weißbach        return $XML;
3437d101cc1SGerry Weißbach    }
3447d101cc1SGerry Weißbach
3457d101cc1SGerry Weißbach
3467d101cc1SGerry Weißbach    /**
3477d101cc1SGerry Weißbach     * Get the context XML
3487d101cc1SGerry Weißbach     **/
3497d101cc1SGerry Weißbach    public function __getContextXML($DATA) {
3507d101cc1SGerry Weißbach
3517d101cc1SGerry Weißbach        $XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?NLS TYPE=\"org.eclipse.help.context\"?>\n<contexts>\n";
3527d101cc1SGerry Weißbach
3537d101cc1SGerry Weißbach        $check = array();
3547d101cc1SGerry Weißbach        foreach ($DATA as $elem)
3557d101cc1SGerry Weißbach        {
3567d101cc1SGerry Weißbach            $ID = $elem['id'];
3577d101cc1SGerry Weißbach            $meta = p_get_metadata($ID, 'context', true);
3587d101cc1SGerry Weißbach            if (empty($meta['id'])) { continue; }
3597d101cc1SGerry Weißbach
3607d101cc1SGerry Weißbach            $TITLE = empty($meta['title']) ? $this->functions->getSiteTitle($ID) : $meta['title'];
3617d101cc1SGerry Weißbach
3627d101cc1SGerry Weißbach            // support more than one view IDs ... for more than one reference
3638a20a4b4SGerry Weißbach            $VIEWIDs = $this->functions->getMapID($elem['id'], $elem['anchor'], $check);
3647d101cc1SGerry Weißbach
3657d101cc1SGerry Weißbach            $DESCRIPTION = $this->functions->xmlEntities(p_get_metadata($ID, 'description abstract'));
3667d101cc1SGerry Weißbach
3677d101cc1SGerry Weißbach            // Build topic Links
3687d101cc1SGerry Weißbach            $url = $this->functions->getSiteName($ID);
3697d101cc1SGerry Weißbach            $this->shortenByTranslation($url);
3707d101cc1SGerry Weißbach
3717d101cc1SGerry Weißbach            $TOPICS = array($url => $TITLE . " (Details)");
3727d101cc1SGerry Weißbach            $REFS = p_get_metadata($ID, 'relation references', true);
3737d101cc1SGerry Weißbach            if (is_array($REFS))
3747d101cc1SGerry Weißbach            foreach ($REFS as $REL => $EXISTS) {
3757d101cc1SGerry Weißbach                if (!$EXISTS) { continue; }
3767d101cc1SGerry Weißbach                $TOPICS[$this->functions->getSiteName($REL)] = $this->functions->getSiteTitle($REL);
3777d101cc1SGerry Weißbach            }
3787d101cc1SGerry Weißbach
3797d101cc1SGerry Weißbach            // build XML - include multi view IDs
3807d101cc1SGerry Weißbach            foreach ($VIEWIDs as $VIEWID) {
3817d101cc1SGerry Weißbach                $XML .= "\t<context id=\"$VIEWID\" title=\"$TITLE\">\n";
3827d101cc1SGerry Weißbach                $XML .= "\t\t<description>$DESCRIPTION</description>\n";
3837d101cc1SGerry Weißbach
3847d101cc1SGerry Weißbach                foreach ($TOPICS as $URL => $LABEL) {
3857d101cc1SGerry Weißbach                    $XML .= "\t\t<topic label=\"$LABEL\" href=\"$URL\" />\n";
3867d101cc1SGerry Weißbach                }
3877d101cc1SGerry Weißbach
3887d101cc1SGerry Weißbach                $XML .= "\t</context>\n";
3897d101cc1SGerry Weißbach            }
3907d101cc1SGerry Weißbach        }
3917d101cc1SGerry Weißbach
3927d101cc1SGerry Weißbach        $XML .= "</contexts>";
3937d101cc1SGerry Weißbach        return $XML;
3947d101cc1SGerry Weißbach
3957d101cc1SGerry Weißbach    }
3967d101cc1SGerry Weißbach
3977d101cc1SGerry Weißbach    /**
3987d101cc1SGerry Weißbach     * Determine if this is an index - and if so, find its Title
3997d101cc1SGerry Weißbach     **/
4007d101cc1SGerry Weißbach    private function __getIndexItem(&$DATA, $NODENAME = '') {
4017d101cc1SGerry Weißbach        global $conf;
4027d101cc1SGerry Weißbach
4037d101cc1SGerry Weißbach        if (!is_array($DATA)) { return; }
4047d101cc1SGerry Weißbach
4057d101cc1SGerry Weißbach        $indexTitle = '';
4067d101cc1SGerry Weißbach        $indexFile = '';
4077d101cc1SGerry Weißbach        foreach ($DATA as $NODE => $indexSearch) {
4087d101cc1SGerry Weißbach            // Skip next Namespaces
4097d101cc1SGerry Weißbach            if (is_array($indexSearch)) { continue; }
4107d101cc1SGerry Weißbach
4117d101cc1SGerry Weißbach            // Skip if this is not a start
4127d101cc1SGerry Weißbach            if ($NODE != $conf['start']) { continue; }
4137d101cc1SGerry Weißbach
4147d101cc1SGerry Weißbach            $indexTitle = $this->functions->getSiteTitle($indexSearch);
4157d101cc1SGerry Weißbach            $indexFile = $indexSearch;
4167d101cc1SGerry Weißbach            unset($DATA[$NODE]);
4177d101cc1SGerry Weißbach            break;
4187d101cc1SGerry Weißbach        }
4197d101cc1SGerry Weißbach
4207d101cc1SGerry Weißbach        if (empty($indexFile) && !empty($DATA[$NODENAME])) {
4217d101cc1SGerry Weißbach            $indexTitle = $this->functions->getSiteTitle($DATA[$NODENAME]);
4227d101cc1SGerry Weißbach            $indexFile = $DATA[$NODENAME];
4237d101cc1SGerry Weißbach            unset($DATA[$NODENAME]);
4247d101cc1SGerry Weißbach        }
4257d101cc1SGerry Weißbach
4267d101cc1SGerry Weißbach        return array($indexTitle, $this->functions->getSiteName($indexFile));
4277d101cc1SGerry Weißbach    }
4282c9ab2bbSGerry Weißbach
4292c9ab2bbSGerry Weißbach    private $doDebug = false;
4302c9ab2bbSGerry Weißbach    private static $didDebug = false;
4313bda080dSGerry Weißbach    public function debug($data, $final = false) {
4322c9ab2bbSGerry Weißbach        if ( ! $this->doDebug ) { return; }
4332c9ab2bbSGerry Weißbach
4342c9ab2bbSGerry Weißbach        if ( !$this->didDebug ) {
4352c9ab2bbSGerry Weißbach            print "<html><pre>";
4362c9ab2bbSGerry Weißbach            $this->didDebug = true;
4377d101cc1SGerry Weißbach        }
4387d101cc1SGerry Weißbach
4392c9ab2bbSGerry Weißbach        if ( is_array($data) ) {
4402c9ab2bbSGerry Weißbach            print_r($data);
4412c9ab2bbSGerry Weißbach        } else {
4422c9ab2bbSGerry Weißbach            print str_replace("<", "&lt;", str_replace(">", "&gt;", $data));;
4432c9ab2bbSGerry Weißbach        }
4442c9ab2bbSGerry Weißbach
4452c9ab2bbSGerry Weißbach        print "\n\n";
4462c9ab2bbSGerry Weißbach
4472c9ab2bbSGerry Weißbach        if ( $final ) {
4482c9ab2bbSGerry Weißbach            print "</pre></html>";
4492c9ab2bbSGerry Weißbach            exit;
4502c9ab2bbSGerry Weißbach        }
4512c9ab2bbSGerry Weißbach    }
4522c9ab2bbSGerry Weißbach}
453