17Syaroslav@ivinco.com<?php 27Syaroslav@ivinco.com/* 37Syaroslav@ivinco.com * To change this template, choose Tools | Templates 47Syaroslav@ivinco.com * and open the template in the editor. 57Syaroslav@ivinco.com */ 67Syaroslav@ivinco.com 77Syaroslav@ivinco.comfunction formatXml($data) 87Syaroslav@ivinco.com{ 97Syaroslav@ivinco.com $xmlFormat = ' 107Syaroslav@ivinco.com<sphinx:document id="{id}"> 117Syaroslav@ivinco.com<title><![CDATA[[{title}]]></title> 127Syaroslav@ivinco.com<body><![CDATA[[{body}]]></body> 137Syaroslav@ivinco.com<categories><![CDATA[[{categories}]]></categories> 147Syaroslav@ivinco.com<level>{level}</level> 157Syaroslav@ivinco.com<modified>{modified}</modified> 167Syaroslav@ivinco.com<creator>{creator}</creator> 177Syaroslav@ivinco.com</sphinx:document> 187Syaroslav@ivinco.com 197Syaroslav@ivinco.com'; 207Syaroslav@ivinco.com 217Syaroslav@ivinco.com return str_replace( array('{id}', '{title}', '{body}', '{categories}', '{level}', '{modified}', '{creator}'), 227Syaroslav@ivinco.com array($data['id'], $data['title'], $data['body'], $data['categories'], 237Syaroslav@ivinco.com $data['level'], $data['modified'], $data['creator']), 247Syaroslav@ivinco.com $xmlFormat 257Syaroslav@ivinco.com ); 267Syaroslav@ivinco.com} 277Syaroslav@ivinco.com 287Syaroslav@ivinco.comfunction getDocumentsByHeadings($id, $metadata) 297Syaroslav@ivinco.com{ 307Syaroslav@ivinco.com if (empty($metadata) || empty($metadata['description']['tableofcontents'])) return false; 317Syaroslav@ivinco.com 327Syaroslav@ivinco.com $sections = array(); 337Syaroslav@ivinco.com foreach($metadata['description']['tableofcontents'] as $row){ 347Syaroslav@ivinco.com $sections[$row['hid']] = array( 357Syaroslav@ivinco.com 'section' => getSection($id, $row['title']), 367Syaroslav@ivinco.com 'title' => $row['title'], 377Syaroslav@ivinco.com 'level' => $row['level'] 387Syaroslav@ivinco.com ); 397Syaroslav@ivinco.com } 407Syaroslav@ivinco.com return $sections; 417Syaroslav@ivinco.com} 427Syaroslav@ivinco.com 437Syaroslav@ivinco.comfunction getSection($id, $header) 447Syaroslav@ivinco.com{ 457Syaroslav@ivinco.com // Create the parser 467Syaroslav@ivinco.com $Parser = & new Doku_Parser(); 477Syaroslav@ivinco.com 487Syaroslav@ivinco.com // Add the Handler 497Syaroslav@ivinco.com $Parser->Handler = & new Doku_Handler(); 507Syaroslav@ivinco.com 517Syaroslav@ivinco.com // Load the header mode to find headers 527Syaroslav@ivinco.com $Parser->addMode('header',new Doku_Parser_Mode_Header()); 537Syaroslav@ivinco.com 547Syaroslav@ivinco.com // Load the modes which could contain markup that might be 557Syaroslav@ivinco.com // mistaken for a header 567Syaroslav@ivinco.com $Parser->addMode('listblock',new Doku_Parser_Mode_ListBlock()); 577Syaroslav@ivinco.com $Parser->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); 587Syaroslav@ivinco.com $Parser->addMode('table',new Doku_Parser_Mode_Table()); 597Syaroslav@ivinco.com $Parser->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); 607Syaroslav@ivinco.com $Parser->addMode('php',new Doku_Parser_Mode_PHP()); 617Syaroslav@ivinco.com $Parser->addMode('html',new Doku_Parser_Mode_HTML()); 627Syaroslav@ivinco.com $Parser->addMode('code',new Doku_Parser_Mode_Code()); 637Syaroslav@ivinco.com $Parser->addMode('file',new Doku_Parser_Mode_File()); 647Syaroslav@ivinco.com $Parser->addMode('quote',new Doku_Parser_Mode_Quote()); 657Syaroslav@ivinco.com $Parser->addMode('footnote',new Doku_Parser_Mode_Footnote()); 667Syaroslav@ivinco.com $Parser->addMode('internallink',new Doku_Parser_Mode_InternalLink()); 677Syaroslav@ivinco.com $Parser->addMode('media',new Doku_Parser_Mode_Media()); 687Syaroslav@ivinco.com $Parser->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); 697Syaroslav@ivinco.com $Parser->addMode('windowssharelink',new Doku_Parser_Mode_WindowsShareLink()); 707Syaroslav@ivinco.com $Parser->addMode('filelink',new Doku_Parser_Mode_FileLink()); 717Syaroslav@ivinco.com 727Syaroslav@ivinco.com // Loads the raw wiki document 737Syaroslav@ivinco.com $doc = io_readFile(wikiFN($id)); 747Syaroslav@ivinco.com 757Syaroslav@ivinco.com // Get a list of instructions 767Syaroslav@ivinco.com $instructions = $Parser->parse($doc); 777Syaroslav@ivinco.com 787Syaroslav@ivinco.com unset($Parser); 797Syaroslav@ivinco.com 807Syaroslav@ivinco.com // Use this to watch when we're inside the section we want 817Syaroslav@ivinco.com $inSection = FALSE; 827Syaroslav@ivinco.com $startPos = 0; 837Syaroslav@ivinco.com $endPos = 0; 847Syaroslav@ivinco.com 857Syaroslav@ivinco.com // Loop through the instructions 867Syaroslav@ivinco.com foreach ( $instructions as $instruction ) { 877Syaroslav@ivinco.com 887Syaroslav@ivinco.com if ( !$inSection ) { 897Syaroslav@ivinco.com 907Syaroslav@ivinco.com // Look for the header for the "Lists" heading 917Syaroslav@ivinco.com if ( $instruction[0] == 'header' && 927Syaroslav@ivinco.com trim($instruction[1][0]) == $header ) { 937Syaroslav@ivinco.com 947Syaroslav@ivinco.com $startPos = $instruction[2]; 957Syaroslav@ivinco.com $inSection = TRUE; 967Syaroslav@ivinco.com } 977Syaroslav@ivinco.com } else { 987Syaroslav@ivinco.com 997Syaroslav@ivinco.com // Look for the end of the section 1007Syaroslav@ivinco.com if ( $instruction[0] == 'section_close' ) { 1017Syaroslav@ivinco.com $endPos = $instruction[2]; 1027Syaroslav@ivinco.com break; 1037Syaroslav@ivinco.com } 1047Syaroslav@ivinco.com } 1057Syaroslav@ivinco.com } 1067Syaroslav@ivinco.com 1077Syaroslav@ivinco.com // Normalize and pad the document in the same way the parse does 1087Syaroslav@ivinco.com // so that byte indexes with match 1097Syaroslav@ivinco.com $doc = "\n".str_replace("\r\n","\n",$doc)."\n"; 1107Syaroslav@ivinco.com $section = substr($doc, $startPos, ($endPos-$startPos)); 1117Syaroslav@ivinco.com 1127Syaroslav@ivinco.com return $section; 1137Syaroslav@ivinco.com} 1147Syaroslav@ivinco.com 1157Syaroslav@ivinco.comfunction getCategories($id) 1167Syaroslav@ivinco.com{ 1177Syaroslav@ivinco.com if (empty($id)) return ''; 1187Syaroslav@ivinco.com 1197Syaroslav@ivinco.com if (false === strpos($id, ":")){ 1207Syaroslav@ivinco.com return $id; 1217Syaroslav@ivinco.com } 1227Syaroslav@ivinco.com 1237Syaroslav@ivinco.com $ns = explode(":", $id); 1247Syaroslav@ivinco.com $nsCount = count($ns); 1257Syaroslav@ivinco.com 1267Syaroslav@ivinco.com $result = ''; 1277Syaroslav@ivinco.com do{ 1287Syaroslav@ivinco.com for($i = 0; $i < $nsCount; $i++){ 1297Syaroslav@ivinco.com $name = $ns[$i]; 1307Syaroslav@ivinco.com $result .= $name; 1317Syaroslav@ivinco.com if ($i < $nsCount - 1){ 1327Syaroslav@ivinco.com $result .= ':'; 1337Syaroslav@ivinco.com } 1347Syaroslav@ivinco.com } 1357Syaroslav@ivinco.com $result .= ' '; 1367Syaroslav@ivinco.com }while($nsCount--); 1377Syaroslav@ivinco.com return $result; 1387Syaroslav@ivinco.com} 1397Syaroslav@ivinco.com 1407Syaroslav@ivinco.com 1417Syaroslav@ivinco.com /** 1427Syaroslav@ivinco.com * Method return all wiki page names 1437Syaroslav@ivinco.com * @global array $conf 1447Syaroslav@ivinco.com * @return array 1457Syaroslav@ivinco.com */ 1467Syaroslav@ivinco.com function getPagesList() 1477Syaroslav@ivinco.com { 1487Syaroslav@ivinco.com global $conf; 1497Syaroslav@ivinco.com 1507Syaroslav@ivinco.com $data = array(); 1517Syaroslav@ivinco.com sort($data); 1527Syaroslav@ivinco.com search($data,$conf['datadir'],'search_allpages','',''); 1537Syaroslav@ivinco.com 1547Syaroslav@ivinco.com return $data; 155*8Syaroslav@ivinco.com} 156*8Syaroslav@ivinco.com 157*8Syaroslav@ivinco.comfunction getNsLinks($id) 158*8Syaroslav@ivinco.com{ 159*8Syaroslav@ivinco.com global $conf; 160*8Syaroslav@ivinco.com $parts = explode(':', $id); 161*8Syaroslav@ivinco.com $count = count($parts); 162*8Syaroslav@ivinco.com 163*8Syaroslav@ivinco.com // print intermediate namespace links 164*8Syaroslav@ivinco.com $part = ''; 165*8Syaroslav@ivinco.com $links = array(); 166*8Syaroslav@ivinco.com for($i=0; $i<$count; $i++){ 167*8Syaroslav@ivinco.com $part .= $parts[$i].':'; 168*8Syaroslav@ivinco.com $page = $part; 169*8Syaroslav@ivinco.com resolve_pageid('',$page,$exists); 170*8Syaroslav@ivinco.com if ($page == $conf['start']) continue; // Skip startpage 171*8Syaroslav@ivinco.com 172*8Syaroslav@ivinco.com // output 173*8Syaroslav@ivinco.com if ($exists){ 174*8Syaroslav@ivinco.com $title = useHeading('navigation') ? p_get_first_heading($page) : $page; 175*8Syaroslav@ivinco.com if(!$title) $title = $parts[$i]; 176*8Syaroslav@ivinco.com } else { 177*8Syaroslav@ivinco.com $title = $parts[$i]; 178*8Syaroslav@ivinco.com } 179*8Syaroslav@ivinco.com $links[wl($page)] = $title; 180*8Syaroslav@ivinco.com } 181*8Syaroslav@ivinco.com return $links; 1827Syaroslav@ivinco.com}