xref: /plugin/siteexport/inc/toc.php (revision 045da2c863ad2aef55497247220ff31938c60293)
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
206fcbda1dSGerry Weißbach    private function isNotEmpty( $val ) {
216fcbda1dSGerry Weißbach        return !empty($val);
226fcbda1dSGerry Weißbach    }
236fcbda1dSGerry Weißbach
247d101cc1SGerry Weißbach    private function shortenByTranslation(&$inputURL, $deepSearch = false)
257d101cc1SGerry Weißbach    {
2627464f82SGerry Weißbach        // Mandatory: we allways want '/' insteadf of ':' here
2727464f82SGerry Weißbach        $inputURL = str_replace(':', '/', $inputURL);
28a8c17ab5Si-net /// software
29a8c17ab5Si-net /// software        $checkArray = $this->translation ? $this->translation->translations : array(noNS($this->NS));
30a0726238SGerry Weißbach
317d101cc1SGerry Weißbach        $url = explode('/', $inputURL);
327d101cc1SGerry Weißbach
33cbb6b50eSi-net /// software        $URLcount = count($url);
34cbb6b50eSi-net /// software        for ($i = 0; $i < $URLcount ; $i++)
357d101cc1SGerry Weißbach        {
36a0726238SGerry Weißbach            if (in_array($url[$i], $checkArray))
377d101cc1SGerry Weißbach            {
387d101cc1SGerry Weißbach                // Rauswerfen und weg
397d101cc1SGerry Weißbach                $url[$i] = '';
407d101cc1SGerry Weißbach                break;
417d101cc1SGerry Weißbach            }
427d101cc1SGerry Weißbach
437d101cc1SGerry Weißbach            if (!$deepSearch)
447d101cc1SGerry Weißbach            {
457d101cc1SGerry Weißbach                break;
467d101cc1SGerry Weißbach            }
477d101cc1SGerry Weißbach
487d101cc1SGerry Weißbach            // Ok, remove anyway
497d101cc1SGerry Weißbach            $url[$i] = '';
507d101cc1SGerry Weißbach        }
517d101cc1SGerry Weißbach
527d101cc1SGerry Weißbach        $inputURL = implode('/', $url);
537d101cc1SGerry Weißbach        $inputURL = preg_replace("$\/+$", "/", $inputURL);
547d101cc1SGerry Weißbach
557d101cc1SGerry Weißbach        if (strlen($inputURL) > 0 && substr($inputURL, 0, 1) == '/')
567d101cc1SGerry Weißbach        {
577d101cc1SGerry Weißbach            $inputURL = substr($inputURL, 1);
587d101cc1SGerry Weißbach        }
597d101cc1SGerry Weißbach
607d101cc1SGerry Weißbach        return $inputURL;
617d101cc1SGerry Weißbach    }
627d101cc1SGerry Weißbach
637d101cc1SGerry Weißbach    /**
647d101cc1SGerry Weißbach     * Build the Java Documentation TOC XML
657d101cc1SGerry Weißbach     **/
667d101cc1SGerry Weißbach    public function __getJavaHelpTOCXML($DATA) {
677d101cc1SGerry Weißbach
687d101cc1SGerry Weißbach        if (count($DATA) == 0) {
697d101cc1SGerry Weißbach            return false;
707d101cc1SGerry Weißbach        }
717d101cc1SGerry Weißbach
72e9b60a63SGerry Weißbach        $this->debug("#### STARTING ####");
737d101cc1SGerry Weißbach        $TOCXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<toc>";
747d101cc1SGerry Weißbach        $MAPXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<map version=\"1.0\">";
757d101cc1SGerry Weißbach
767d101cc1SGerry Weißbach        // Go through the pages
777d101cc1SGerry Weißbach        $CHECKDATA = array();
787d101cc1SGerry Weißbach        $nData = $DATA;
797d101cc1SGerry Weißbach        $DATA = array();
807d101cc1SGerry Weißbach        $check = array();
817d101cc1SGerry Weißbach        $startPageID = null;
827d101cc1SGerry Weißbach
837d101cc1SGerry Weißbach        foreach ( $nData as $elem )
847d101cc1SGerry Weißbach        {
857d101cc1SGerry Weißbach            // Check if available
867d101cc1SGerry Weißbach            $anchor = ( !empty($elem['anchor']) ? '#' . $elem['anchor'] : '' );
87d9cefbd9SGerry Weißbach            $elem['url'] = $this->functions->getSiteName($elem['id'], true); // Override - we need a clean name
887d101cc1SGerry Weißbach            $elem['mapURL'] = $elem['url'];
897d101cc1SGerry Weißbach            $this->shortenByTranslation($elem['url']);
907d101cc1SGerry Weißbach
917d101cc1SGerry Weißbach            // only add an url once
927d101cc1SGerry Weißbach            if ( in_array($elem['url'], $CHECKDATA) ) { continue; }
937d101cc1SGerry Weißbach
94dfb6ef8fSGerry Weißbach            if ( !isset($elem['exists']) ) {
95dfb6ef8fSGerry Weißbach                resolve_pageid(getNS($elem['id']),$elem['id'],$elem['exists']);
96dfb6ef8fSGerry Weißbach                $this->functions->debug->message("EXISTS previously not set.", $elem, 1);
97dfb6ef8fSGerry Weißbach            }
98dfb6ef8fSGerry Weißbach
997d101cc1SGerry Weißbach            // if not there, no map ids will be generated
1008a20a4b4SGerry Weißbach            $elem['mapID'] = intval($elem['exists']) == 1 ? $this->functions->getMapID($elem['id'], $elem['anchor'], $check) : array();
1016fcbda1dSGerry Weißbach            $elem['tags'] = explode(' ', p_get_metadata($elem['id'], 'context tags', true)); // thats from the tag plugin
1026fcbda1dSGerry Weißbach            $elem['tags'] = array_filter($elem['tags'], array($this, 'isNotEmpty'));
1036fcbda1dSGerry Weißbach            $elem['tags'] = array_map(array($this->functions, 'cleanId'), $elem['tags']);
1047d101cc1SGerry Weißbach
1050571ece2SScrutinizer Auto-Fixer            if ( empty($elem['depth']) ) {
1060571ece2SScrutinizer Auto-Fixer                $elem['depth'] = count(explode('/', $elem['url']));
1070571ece2SScrutinizer Auto-Fixer            }
1087d101cc1SGerry Weißbach            $CHECKDATA[] = $elem['url'];
1097d101cc1SGerry Weißbach
1107d101cc1SGerry Weißbach            if ( $startPageID == null )
1117d101cc1SGerry Weißbach            {
1127d101cc1SGerry Weißbach                $startPageID = $elem['mapID'][0];
1137d101cc1SGerry Weißbach            }
1147d101cc1SGerry Weißbach
1156f66113cSGerry Weißbach            if ( empty( $elem['name'] ) || $elem['name'] == noNs($elem['id']) ) {
1166ba764b8SGerry Weißbach                $elem['name'] = $this->functions->getSiteTitle($elem['id']);
11713aaf300SGerry Weißbach                $this->debug($elem);
1186ba764b8SGerry Weißbach            }
1196ba764b8SGerry Weißbach
1207d101cc1SGerry Weißbach            // Go on building mapXML
1217d101cc1SGerry Weißbach            $this->shortenByTranslation($elem['mapURL'], true); // true to already remove all language stuff - false if not
1227d101cc1SGerry Weißbach            foreach ( $elem['mapID'] as $VIEWID ) {
1236fcbda1dSGerry Weißbach                $MAPXML .= "\n\t<mapID target=\"" . $VIEWID . "\" url=\"" . $elem['mapURL'] . $anchor . "\"/>";
1247d101cc1SGerry Weißbach            }
1257d101cc1SGerry Weißbach
1267d101cc1SGerry Weißbach            $elem['tocNS'] = getNS(cleanID($elem['url']));
1272c9ab2bbSGerry Weißbach            $elem['tocNS'] = $this->shortenByTranslation($elem['tocNS'], true);
1282c9ab2bbSGerry Weißbach            $elem['tocNS'] = strlen($elem['tocNS']) > 0 ? explode('/', $elem['tocNS']) : array();
1296ba764b8SGerry Weißbach            $this->functions->debug->message("This will be the TOC elements data:", $elem, 1);
1307d101cc1SGerry Weißbach
1317d101cc1SGerry Weißbach            $this->__buildTOCTree($DATA, $elem['tocNS'], $elem);
1327d101cc1SGerry Weißbach        }
1337d101cc1SGerry Weißbach
13413aaf300SGerry Weißbach        $this->debug("#### Writing TOC Tree ####");
1357d101cc1SGerry Weißbach        $TOCXML .= $this->__writeTOCTree($DATA) . "\n</toc>";
13613aaf300SGerry Weißbach        $this->debug("#### DONE: Writing TOC Tree ####");
1377d101cc1SGerry Weißbach        $MAPXML .= "\n</map>";
13801a1f586SGerry Weißbach
1392c9ab2bbSGerry Weißbach        $this->debug($DATA);
1402c9ab2bbSGerry Weißbach        $this->debug($TOCXML);
1413bda080dSGerry Weißbach        $this->debug($MAPXML);
1427d101cc1SGerry Weißbach
1437d101cc1SGerry Weißbach        return array($TOCXML, $MAPXML, $startPageID);
1447d101cc1SGerry Weißbach    }
1457d101cc1SGerry Weißbach
1467d101cc1SGerry Weißbach    /**
1477d101cc1SGerry Weißbach     * Prepare the TOC Tree
1487d101cc1SGerry Weißbach     **/
1497d101cc1SGerry Weißbach    private function __buildTOCTree(&$DATA, $currentNSArray, $elemToAdd)
1507d101cc1SGerry Weißbach    {
1517d101cc1SGerry Weißbach        global $conf;
1527d101cc1SGerry Weißbach
1532c9ab2bbSGerry Weißbach        // Actual level
1542c9ab2bbSGerry Weißbach        if (empty($currentNSArray)) {
15524b1b4baSGerry Weißbach            $elemToAdd['isStartPage'] = noNS($elemToAdd['id']) == $conf['start'];
15651917f25SGerry Weißbach            // $key = empty($elemToAdd['name']) || 1==1 ? noNS($elemToAdd['id']) : $elemToAdd['name'];
1570965d97cSGerry Weißbach            $key = noNS($elemToAdd['id']);
1580965d97cSGerry Weißbach            $DATA[$key] = $elemToAdd;
1597d101cc1SGerry Weißbach            return;
1607d101cc1SGerry Weißbach        }
1617d101cc1SGerry Weißbach
1627d101cc1SGerry Weißbach        $currentLevel = array_shift($currentNSArray);
16301a1f586SGerry Weißbach        $nextLevel = &$DATA[$currentLevel];
16401a1f586SGerry Weißbach        if (empty($nextLevel)) {
1652c9ab2bbSGerry Weißbach            $nextLevel = array('pages' => array());
16601a1f586SGerry Weißbach        } else {
16701a1f586SGerry Weißbach            $nextLevel = &$DATA[$currentLevel]['pages'];
1687d101cc1SGerry Weißbach        }
1697d101cc1SGerry Weißbach
17001a1f586SGerry Weißbach        $this->__buildTOCTree($nextLevel, $currentNSArray, $elemToAdd);
1717d101cc1SGerry Weißbach    }
1727d101cc1SGerry Weißbach
1737d101cc1SGerry Weißbach    /**
1747d101cc1SGerry Weißbach     * Create a single TOC Item
1757d101cc1SGerry Weißbach     **/
1767d101cc1SGerry Weißbach    private function __TOCItem($item, $depth, $selfClosed = true)
1777d101cc1SGerry Weißbach    {
17813aaf300SGerry Weißbach        $this->debug($item);
1797d101cc1SGerry Weißbach        $targetID = $item['mapID'][0];
1807d101cc1SGerry Weißbach        if (empty($targetID)) {
181*045da2c8SGerry Weißbach            $targetID = $this->functions->cleanID($item['name']);
1827d101cc1SGerry Weißbach        }
183dbc4346dSGerry Weißbach        return "\n" . str_repeat("\t", max($depth, 0)+1) . "<tocitem target=\"" . $targetID . "\"" . (intval($item['exists']) == 1 ? " text=\"" . $item['name'] . "\"" : "") . ( array_key_exists('tags', $item) && !empty($item['tags']) ? " tags=\"" . implode(' ', $item['tags']) . "\"": "")  . ($selfClosed ? '/' : '') . ">";
1847d101cc1SGerry Weißbach    }
1857d101cc1SGerry Weißbach
1867d101cc1SGerry Weißbach    /**
1877d101cc1SGerry Weißbach     * Create a single TOC Item
1887d101cc1SGerry Weißbach     **/
1897d101cc1SGerry Weißbach    private function __TOCItemClose($depth)
1907d101cc1SGerry Weißbach    {
1917d101cc1SGerry Weißbach        return "\n" . str_repeat("\t", max($depth, 0)+1) . "</tocitem>";
1927d101cc1SGerry Weißbach    }
1937d101cc1SGerry Weißbach
1947d101cc1SGerry Weißbach    /**
1957d101cc1SGerry Weißbach     * Write the whole TOC TREE
1967d101cc1SGerry Weißbach     **/
1977d101cc1SGerry Weißbach    private function __writeTOCTree($CURRENTNODE, $CURRENTNODENAME = null, $DEPTH = 0) {
1987d101cc1SGerry Weißbach        global $conf;
1997d101cc1SGerry Weißbach
2007d101cc1SGerry Weißbach        $XML = '';
2017d101cc1SGerry Weißbach        $didOpenItem = false;
2027d101cc1SGerry Weißbach        if (!is_array($CURRENTNODE) || empty($CURRENTNODE))
2037d101cc1SGerry Weißbach        {
2047d101cc1SGerry Weißbach            // errr … no.
2057d101cc1SGerry Weißbach            return $XML;
2067d101cc1SGerry Weißbach        }
2077d101cc1SGerry Weißbach
2087d101cc1SGerry Weißbach        // This is an element!
209f3b52d8fSGerry Weißbach        if (!empty($CURRENTNODE['id']) && empty($CURRENTNODE['pages']))
2107d101cc1SGerry Weißbach        {
211f3b52d8fSGerry Weißbach            // This has to be an item - only -!
2127d101cc1SGerry Weißbach            return $this->__TOCItem($CURRENTNODE, $DEPTH);
2137d101cc1SGerry Weißbach        }
2147d101cc1SGerry Weißbach
2157d101cc1SGerry Weißbach        // Look for start page
2167d101cc1SGerry Weißbach        if (!empty($CURRENTNODE[$conf['start']]))
2177d101cc1SGerry Weißbach        {
2187d101cc1SGerry Weißbach            // YAY! StartPage found.
21901a1f586SGerry Weißbach            $didOpenItem = !(count(empty($CURRENTNODE['pages']) ? $CURRENTNODE : $CURRENTNODE['pages']) == 0);
2207d101cc1SGerry Weißbach            $XML .= $this->__TOCItem($CURRENTNODE[$conf['start']], $DEPTH, !$didOpenItem);
2217d101cc1SGerry Weißbach            unset($CURRENTNODE[$conf['start']]);
22201a1f586SGerry Weißbach        } else if (!empty($CURRENTNODE['element'])) {
22301a1f586SGerry Weißbach            $didOpenItem = !(count($CURRENTNODE['pages']) == 0);
22401a1f586SGerry Weißbach            $XML .= $this->__TOCItem($CURRENTNODE['element'], $DEPTH, !$didOpenItem);
22501a1f586SGerry Weißbach            unset($CURRENTNODE['element']);
2267d101cc1SGerry Weißbach        } else if ($CURRENTNODENAME != null) {
2277d101cc1SGerry Weißbach            // We have a parent node for what is comming … lets honor that
2287d101cc1SGerry Weißbach            $didOpenItem = !(count($CURRENTNODE) == 0);
2297d101cc1SGerry Weißbach            $XML .= $this->__TOCItem(array('name' => ucwords($CURRENTNODENAME)), $DEPTH, !$didOpenItem);
2307d101cc1SGerry Weißbach        } else {
2317d101cc1SGerry Weißbach            // Woohoo … empty node? do not count up!
2327d101cc1SGerry Weißbach            $DEPTH--;
2337d101cc1SGerry Weißbach        }
2347d101cc1SGerry Weißbach
2353bda080dSGerry Weißbach        $this->debug("-- This is the current node --");
2363bda080dSGerry Weißbach        $this->debug($CURRENTNODE);
2373bda080dSGerry Weißbach
2387d101cc1SGerry Weißbach        // Circle through the entries
23901a1f586SGerry Weißbach        foreach (empty($CURRENTNODE['pages']) ? $CURRENTNODE : $CURRENTNODE['pages'] as $NODENAME => $ELEM)
2407d101cc1SGerry Weißbach        {
2417d101cc1SGerry Weißbach            // a node should have more than only one entry … otherwise we will not tell our name!
24213aaf300SGerry Weißbach            $XML .= $this->__writeTOCTree($ELEM, count($ELEM) >= 1 ? ( !empty($ELEM['name']) ? $ELEM['name'] : $NODENAME ) : null, $DEPTH+1);
2437d101cc1SGerry Weißbach        }
2447d101cc1SGerry Weißbach
2457d101cc1SGerry Weißbach        // Close and return
2467d101cc1SGerry Weißbach        return $XML . ($didOpenItem ? $this->__TOCItemClose($DEPTH) : '');
2477d101cc1SGerry Weißbach    }
2487d101cc1SGerry Weißbach
2497d101cc1SGerry Weißbach    /**
2507d101cc1SGerry Weißbach     * Build the Eclipse Documentation TOC XML
2517d101cc1SGerry Weißbach     **/
2527d101cc1SGerry Weißbach    public function __getTOCXML($DATA, $XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?NLS TYPE=\"org.eclipse.help.toc\"?>\n") {
2537d101cc1SGerry Weißbach
2547d101cc1SGerry Weißbach        $pagesArray = array();
2557d101cc1SGerry Weißbach
2567d101cc1SGerry Weißbach        // Go through the pages
2577d101cc1SGerry Weißbach        foreach ($DATA as $elem) {
2587d101cc1SGerry Weißbach
2597d101cc1SGerry Weißbach            $site = $elem['id'];
2607d101cc1SGerry Weißbach            $elems = explode('/', $this->functions->getSiteName($site));
2617d101cc1SGerry Weißbach
2627d101cc1SGerry Weißbach            // Strip Site
2637d101cc1SGerry Weißbach            array_pop($elems);
2647d101cc1SGerry Weißbach
2657d101cc1SGerry Weißbach            // build the topic Tree
2667d101cc1SGerry Weißbach            $this->__buildTopicTree($pagesArray, $elems, $site);
2677d101cc1SGerry Weißbach        }
2687d101cc1SGerry Weißbach
2697d101cc1SGerry Weißbach        $XML .= $this->__addXMLTopic($pagesArray, 'toc');
2707d101cc1SGerry Weißbach
2717d101cc1SGerry Weißbach        return $XML;
2727d101cc1SGerry Weißbach
2737d101cc1SGerry Weißbach    }
2747d101cc1SGerry Weißbach
2757d101cc1SGerry Weißbach    /**
2767d101cc1SGerry Weißbach     * Load the topic Tree for the TOC - recursive
2777d101cc1SGerry Weißbach     **/
2787d101cc1SGerry Weißbach    private function __buildTopicTree(&$PAGES, $DATA, $SITE, $INSERTDATA = null) {
2797d101cc1SGerry Weißbach
2807d101cc1SGerry Weißbach        if (empty($DATA) || !is_array($DATA)) {
2817d101cc1SGerry Weißbach
2827d101cc1SGerry Weißbach            if ($INSERTDATA == null)
2837d101cc1SGerry Weißbach            {
2847d101cc1SGerry Weißbach                $INSERTDATA = $SITE;
2857d101cc1SGerry Weißbach            }
2867d101cc1SGerry Weißbach
2877d101cc1SGerry Weißbach            // This is already a namespace
2887d101cc1SGerry Weißbach            if (is_array($PAGES[noNS($SITE)])) {
2897d101cc1SGerry Weißbach                // The root already exists!
2907d101cc1SGerry Weißbach                if (!empty($PAGES[noNS($SITE)][noNS($SITE)])) {
2917d101cc1SGerry Weißbach                    if (strstr($PAGES[noNS($SITE)][noNS($SITE)], $SITE)) {
2927d101cc1SGerry Weißbach                        // The SITE is in the parent Namespace, and the current Namespace has an index with same name
2937d101cc1SGerry Weißbach                        $PAGES['__' . noNS($SITE)] = $INSERTDATA;
2947d101cc1SGerry Weißbach                    } else {
2957d101cc1SGerry Weißbach                        $PAGES['__' . noNS($SITE)] = $PAGES[noNS($SITE)][noNS($SITE)];
2967d101cc1SGerry Weißbach                        $PAGES[noNS($SITE)][noNS($SITE)] = $INSERTDATA;
2977d101cc1SGerry Weißbach                    }
2987d101cc1SGerry Weißbach                } else {
2997d101cc1SGerry Weißbach                    $PAGES[noNS($SITE)][noNS($SITE)] = $INSERTDATA;
3007d101cc1SGerry Weißbach                }
3017d101cc1SGerry Weißbach            } else {
3027d101cc1SGerry Weißbach                // just a Page
3037d101cc1SGerry Weißbach                $PAGES[noNS($SITE)] = $INSERTDATA;
3047d101cc1SGerry Weißbach            }
3057d101cc1SGerry Weißbach            return;
3067d101cc1SGerry Weißbach        }
3077d101cc1SGerry Weißbach
3087d101cc1SGerry Weißbach        $NS = array_shift($DATA);
3097d101cc1SGerry Weißbach        if (!is_array($PAGES[$NS])) $PAGES[$NS] = empty($PAGES[$NS]) ? array() : array($PAGES[$NS]);
3107d101cc1SGerry Weißbach        $this->__buildTopicTree($PAGES[$NS], $DATA, $SITE, $INSERTDATA);
3117d101cc1SGerry Weißbach
3127d101cc1SGerry Weißbach        return;
3137d101cc1SGerry Weißbach    }
3147d101cc1SGerry Weißbach
3157d101cc1SGerry Weißbach    /**
3167d101cc1SGerry Weißbach     * Build the Topic Tree for TOC.xml
3177d101cc1SGerry Weißbach     **/
3187d101cc1SGerry Weißbach    private function __addXMLTopic($DATA, $ITEM = 'topic', $LEVEL = 0, $NODENAME = '') {
3197d101cc1SGerry Weißbach        global $conf;
3207d101cc1SGerry Weißbach
3217d101cc1SGerry Weißbach        $DEPTH = str_repeat("\t", $LEVEL);
3227d101cc1SGerry Weißbach
3237d101cc1SGerry Weißbach        if (!is_array($DATA)) {
3247d101cc1SGerry Weißbach            return $DEPTH . '<' . $ITEM . ' label="' . $this->functions->getSiteTitle($DATA) . '" ' . ($ITEM != 'topic' ? 'topic' : 'href') . '="' . $this->functions->getSiteName($DATA) . "\" />\n";
3257d101cc1SGerry Weißbach        }
3267d101cc1SGerry Weißbach        // Is array from this point on
3277d101cc1SGerry Weißbach        list($indexTitle, $indexFile) = $this->__getIndexItem($DATA, $NODENAME);
3287d101cc1SGerry Weißbach
3297d101cc1SGerry Weißbach        if (empty($indexTitle)) $indexTitle = $this->functions->getSiteTitle($conf['start']);
3307d101cc1SGerry Weißbach        if (!empty($indexFile)) $indexFile = ($ITEM != 'topic' ? 'topic' : 'href') . "=\"$indexFile\"";
3317d101cc1SGerry Weißbach
3327d101cc1SGerry Weißbach        $isEmptyNode = count($DATA) == 1 && empty($indexFile);
3337d101cc1SGerry Weißbach
334a8c17ab5Si-net /// software        if (!$isEmptyNode && ($this->emptyNSToc || count($DATA) > 0)) {
3357d101cc1SGerry Weißbach            $XML = "$DEPTH<$ITEM label=\"$indexTitle\" $indexFile>";
336a8c17ab5Si-net /// software        } else {
337a8c17ab5Si-net /// software            $XML = "";
338a8c17ab5Si-net /// software        }
3397d101cc1SGerry Weißbach
3407d101cc1SGerry Weißbach        if (!$isEmptyNode && count($DATA) > 0) $XML .= "\n";
3417d101cc1SGerry Weißbach
3427d101cc1SGerry Weißbach        foreach ($DATA as $NODENAME => $NS) {
3437d101cc1SGerry Weißbach            $XML .= $this->__addXMLTopic($NS, (!($this->emptyNSToc || count($DATA) > 1) && $ITEM != 'topic' ? $ITEM : 'topic'), $LEVEL+(!$isEmptyNode ? 1 : 0), $NODENAME);
3447d101cc1SGerry Weißbach        }
3457d101cc1SGerry Weißbach
3467d101cc1SGerry Weißbach        if (!$isEmptyNode && count($DATA) > 0) $XML .= "$DEPTH";
3477d101cc1SGerry Weißbach        if (!$isEmptyNode && ($this->emptyNSToc || count($DATA) > 0)) {
3487d101cc1SGerry Weißbach            $XML .= "</$ITEM>\n";
3497d101cc1SGerry Weißbach        }
3507d101cc1SGerry Weißbach
3517d101cc1SGerry Weißbach        return $XML;
3527d101cc1SGerry Weißbach    }
3537d101cc1SGerry Weißbach
3547d101cc1SGerry Weißbach
3557d101cc1SGerry Weißbach    /**
3567d101cc1SGerry Weißbach     * Get the context XML
3577d101cc1SGerry Weißbach     **/
3587d101cc1SGerry Weißbach    public function __getContextXML($DATA) {
3597d101cc1SGerry Weißbach
3607d101cc1SGerry Weißbach        $XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?NLS TYPE=\"org.eclipse.help.context\"?>\n<contexts>\n";
3617d101cc1SGerry Weißbach
3627d101cc1SGerry Weißbach        $check = array();
3637d101cc1SGerry Weißbach        foreach ($DATA as $elem)
3647d101cc1SGerry Weißbach        {
3657d101cc1SGerry Weißbach            $ID = $elem['id'];
3667d101cc1SGerry Weißbach            $meta = p_get_metadata($ID, 'context', true);
3677d101cc1SGerry Weißbach            if (empty($meta['id'])) { continue; }
3687d101cc1SGerry Weißbach
3697d101cc1SGerry Weißbach            $TITLE = empty($meta['title']) ? $this->functions->getSiteTitle($ID) : $meta['title'];
3707d101cc1SGerry Weißbach
3717d101cc1SGerry Weißbach            // support more than one view IDs ... for more than one reference
3728a20a4b4SGerry Weißbach            $VIEWIDs = $this->functions->getMapID($elem['id'], $elem['anchor'], $check);
3737d101cc1SGerry Weißbach
3747d101cc1SGerry Weißbach            $DESCRIPTION = $this->functions->xmlEntities(p_get_metadata($ID, 'description abstract'));
3757d101cc1SGerry Weißbach
3767d101cc1SGerry Weißbach            // Build topic Links
3777d101cc1SGerry Weißbach            $url = $this->functions->getSiteName($ID);
3787d101cc1SGerry Weißbach            $this->shortenByTranslation($url);
3797d101cc1SGerry Weißbach
3807d101cc1SGerry Weißbach            $TOPICS = array($url => $TITLE . " (Details)");
3817d101cc1SGerry Weißbach            $REFS = p_get_metadata($ID, 'relation references', true);
3827d101cc1SGerry Weißbach            if (is_array($REFS))
3837d101cc1SGerry Weißbach            foreach ($REFS as $REL => $EXISTS) {
3847d101cc1SGerry Weißbach                if (!$EXISTS) { continue; }
3857d101cc1SGerry Weißbach                $TOPICS[$this->functions->getSiteName($REL)] = $this->functions->getSiteTitle($REL);
3867d101cc1SGerry Weißbach            }
3877d101cc1SGerry Weißbach
3887d101cc1SGerry Weißbach            // build XML - include multi view IDs
3897d101cc1SGerry Weißbach            foreach ($VIEWIDs as $VIEWID) {
3907d101cc1SGerry Weißbach                $XML .= "\t<context id=\"$VIEWID\" title=\"$TITLE\">\n";
3917d101cc1SGerry Weißbach                $XML .= "\t\t<description>$DESCRIPTION</description>\n";
3927d101cc1SGerry Weißbach
3937d101cc1SGerry Weißbach                foreach ($TOPICS as $URL => $LABEL) {
3947d101cc1SGerry Weißbach                    $XML .= "\t\t<topic label=\"$LABEL\" href=\"$URL\" />\n";
3957d101cc1SGerry Weißbach                }
3967d101cc1SGerry Weißbach
3977d101cc1SGerry Weißbach                $XML .= "\t</context>\n";
3987d101cc1SGerry Weißbach            }
3997d101cc1SGerry Weißbach        }
4007d101cc1SGerry Weißbach
4017d101cc1SGerry Weißbach        $XML .= "</contexts>";
4027d101cc1SGerry Weißbach        return $XML;
4037d101cc1SGerry Weißbach
4047d101cc1SGerry Weißbach    }
4057d101cc1SGerry Weißbach
4067d101cc1SGerry Weißbach    /**
4077d101cc1SGerry Weißbach     * Determine if this is an index - and if so, find its Title
4087d101cc1SGerry Weißbach     **/
4097d101cc1SGerry Weißbach    private function __getIndexItem(&$DATA, $NODENAME = '') {
4107d101cc1SGerry Weißbach        global $conf;
4117d101cc1SGerry Weißbach
4127d101cc1SGerry Weißbach        if (!is_array($DATA)) { return; }
4137d101cc1SGerry Weißbach
4147d101cc1SGerry Weißbach        $indexTitle = '';
4157d101cc1SGerry Weißbach        $indexFile = '';
4167d101cc1SGerry Weißbach        foreach ($DATA as $NODE => $indexSearch) {
4177d101cc1SGerry Weißbach            // Skip next Namespaces
4187d101cc1SGerry Weißbach            if (is_array($indexSearch)) { continue; }
4197d101cc1SGerry Weißbach
4207d101cc1SGerry Weißbach            // Skip if this is not a start
4217d101cc1SGerry Weißbach            if ($NODE != $conf['start']) { continue; }
4227d101cc1SGerry Weißbach
4237d101cc1SGerry Weißbach            $indexTitle = $this->functions->getSiteTitle($indexSearch);
4247d101cc1SGerry Weißbach            $indexFile = $indexSearch;
4257d101cc1SGerry Weißbach            unset($DATA[$NODE]);
4267d101cc1SGerry Weißbach            break;
4277d101cc1SGerry Weißbach        }
4287d101cc1SGerry Weißbach
4297d101cc1SGerry Weißbach        if (empty($indexFile) && !empty($DATA[$NODENAME])) {
4307d101cc1SGerry Weißbach            $indexTitle = $this->functions->getSiteTitle($DATA[$NODENAME]);
4317d101cc1SGerry Weißbach            $indexFile = $DATA[$NODENAME];
4327d101cc1SGerry Weißbach            unset($DATA[$NODENAME]);
4337d101cc1SGerry Weißbach        }
4347d101cc1SGerry Weißbach
4357d101cc1SGerry Weißbach        return array($indexTitle, $this->functions->getSiteName($indexFile));
4367d101cc1SGerry Weißbach    }
4372c9ab2bbSGerry Weißbach
4382c9ab2bbSGerry Weißbach    private $doDebug = false;
4392c9ab2bbSGerry Weißbach    private static $didDebug = false;
4403bda080dSGerry Weißbach    public function debug($data, $final = false) {
4412c9ab2bbSGerry Weißbach        if ( ! $this->doDebug ) { return; }
4422c9ab2bbSGerry Weißbach
4432c9ab2bbSGerry Weißbach        if ( !$this->didDebug ) {
4442c9ab2bbSGerry Weißbach            print "<html><pre>";
4452c9ab2bbSGerry Weißbach            $this->didDebug = true;
4467d101cc1SGerry Weißbach        }
4477d101cc1SGerry Weißbach
4482c9ab2bbSGerry Weißbach        if ( is_array($data) ) {
4492c9ab2bbSGerry Weißbach            print_r($data);
4502c9ab2bbSGerry Weißbach        } else {
4512c9ab2bbSGerry Weißbach            print str_replace("<", "&lt;", str_replace(">", "&gt;", $data));;
4522c9ab2bbSGerry Weißbach        }
4532c9ab2bbSGerry Weißbach
4542c9ab2bbSGerry Weißbach        print "\n\n";
4552c9ab2bbSGerry Weißbach
4562c9ab2bbSGerry Weißbach        if ( $final ) {
4572c9ab2bbSGerry Weißbach            print "</pre></html>";
4582c9ab2bbSGerry Weißbach            exit;
4592c9ab2bbSGerry Weißbach        }
4602c9ab2bbSGerry Weißbach    }
4612c9ab2bbSGerry Weißbach}
462