1*7Syaroslav@ivinco.com<?php 2*7Syaroslav@ivinco.com/* 3*7Syaroslav@ivinco.com * To change this template, choose Tools | Templates 4*7Syaroslav@ivinco.com * and open the template in the editor. 5*7Syaroslav@ivinco.com */ 6*7Syaroslav@ivinco.com 7*7Syaroslav@ivinco.comfunction formatXml($data) 8*7Syaroslav@ivinco.com{ 9*7Syaroslav@ivinco.com $xmlFormat = ' 10*7Syaroslav@ivinco.com<sphinx:document id="{id}"> 11*7Syaroslav@ivinco.com<title><![CDATA[[{title}]]></title> 12*7Syaroslav@ivinco.com<body><![CDATA[[{body}]]></body> 13*7Syaroslav@ivinco.com<categories><![CDATA[[{categories}]]></categories> 14*7Syaroslav@ivinco.com<level>{level}</level> 15*7Syaroslav@ivinco.com<modified>{modified}</modified> 16*7Syaroslav@ivinco.com<creator>{creator}</creator> 17*7Syaroslav@ivinco.com</sphinx:document> 18*7Syaroslav@ivinco.com 19*7Syaroslav@ivinco.com'; 20*7Syaroslav@ivinco.com 21*7Syaroslav@ivinco.com return str_replace( array('{id}', '{title}', '{body}', '{categories}', '{level}', '{modified}', '{creator}'), 22*7Syaroslav@ivinco.com array($data['id'], $data['title'], $data['body'], $data['categories'], 23*7Syaroslav@ivinco.com $data['level'], $data['modified'], $data['creator']), 24*7Syaroslav@ivinco.com $xmlFormat 25*7Syaroslav@ivinco.com ); 26*7Syaroslav@ivinco.com} 27*7Syaroslav@ivinco.com 28*7Syaroslav@ivinco.comfunction getDocumentsByHeadings($id, $metadata) 29*7Syaroslav@ivinco.com{ 30*7Syaroslav@ivinco.com if (empty($metadata) || empty($metadata['description']['tableofcontents'])) return false; 31*7Syaroslav@ivinco.com 32*7Syaroslav@ivinco.com $sections = array(); 33*7Syaroslav@ivinco.com foreach($metadata['description']['tableofcontents'] as $row){ 34*7Syaroslav@ivinco.com $sections[$row['hid']] = array( 35*7Syaroslav@ivinco.com 'section' => getSection($id, $row['title']), 36*7Syaroslav@ivinco.com 'title' => $row['title'], 37*7Syaroslav@ivinco.com 'level' => $row['level'] 38*7Syaroslav@ivinco.com ); 39*7Syaroslav@ivinco.com } 40*7Syaroslav@ivinco.com return $sections; 41*7Syaroslav@ivinco.com} 42*7Syaroslav@ivinco.com 43*7Syaroslav@ivinco.comfunction getSection($id, $header) 44*7Syaroslav@ivinco.com{ 45*7Syaroslav@ivinco.com // Create the parser 46*7Syaroslav@ivinco.com $Parser = & new Doku_Parser(); 47*7Syaroslav@ivinco.com 48*7Syaroslav@ivinco.com // Add the Handler 49*7Syaroslav@ivinco.com $Parser->Handler = & new Doku_Handler(); 50*7Syaroslav@ivinco.com 51*7Syaroslav@ivinco.com // Load the header mode to find headers 52*7Syaroslav@ivinco.com $Parser->addMode('header',new Doku_Parser_Mode_Header()); 53*7Syaroslav@ivinco.com 54*7Syaroslav@ivinco.com // Load the modes which could contain markup that might be 55*7Syaroslav@ivinco.com // mistaken for a header 56*7Syaroslav@ivinco.com $Parser->addMode('listblock',new Doku_Parser_Mode_ListBlock()); 57*7Syaroslav@ivinco.com $Parser->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); 58*7Syaroslav@ivinco.com $Parser->addMode('table',new Doku_Parser_Mode_Table()); 59*7Syaroslav@ivinco.com $Parser->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); 60*7Syaroslav@ivinco.com $Parser->addMode('php',new Doku_Parser_Mode_PHP()); 61*7Syaroslav@ivinco.com $Parser->addMode('html',new Doku_Parser_Mode_HTML()); 62*7Syaroslav@ivinco.com $Parser->addMode('code',new Doku_Parser_Mode_Code()); 63*7Syaroslav@ivinco.com $Parser->addMode('file',new Doku_Parser_Mode_File()); 64*7Syaroslav@ivinco.com $Parser->addMode('quote',new Doku_Parser_Mode_Quote()); 65*7Syaroslav@ivinco.com $Parser->addMode('footnote',new Doku_Parser_Mode_Footnote()); 66*7Syaroslav@ivinco.com $Parser->addMode('internallink',new Doku_Parser_Mode_InternalLink()); 67*7Syaroslav@ivinco.com $Parser->addMode('media',new Doku_Parser_Mode_Media()); 68*7Syaroslav@ivinco.com $Parser->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); 69*7Syaroslav@ivinco.com $Parser->addMode('windowssharelink',new Doku_Parser_Mode_WindowsShareLink()); 70*7Syaroslav@ivinco.com $Parser->addMode('filelink',new Doku_Parser_Mode_FileLink()); 71*7Syaroslav@ivinco.com 72*7Syaroslav@ivinco.com // Loads the raw wiki document 73*7Syaroslav@ivinco.com $doc = io_readFile(wikiFN($id)); 74*7Syaroslav@ivinco.com 75*7Syaroslav@ivinco.com // Get a list of instructions 76*7Syaroslav@ivinco.com $instructions = $Parser->parse($doc); 77*7Syaroslav@ivinco.com 78*7Syaroslav@ivinco.com unset($Parser); 79*7Syaroslav@ivinco.com 80*7Syaroslav@ivinco.com // Use this to watch when we're inside the section we want 81*7Syaroslav@ivinco.com $inSection = FALSE; 82*7Syaroslav@ivinco.com $startPos = 0; 83*7Syaroslav@ivinco.com $endPos = 0; 84*7Syaroslav@ivinco.com 85*7Syaroslav@ivinco.com // Loop through the instructions 86*7Syaroslav@ivinco.com foreach ( $instructions as $instruction ) { 87*7Syaroslav@ivinco.com 88*7Syaroslav@ivinco.com if ( !$inSection ) { 89*7Syaroslav@ivinco.com 90*7Syaroslav@ivinco.com // Look for the header for the "Lists" heading 91*7Syaroslav@ivinco.com if ( $instruction[0] == 'header' && 92*7Syaroslav@ivinco.com trim($instruction[1][0]) == $header ) { 93*7Syaroslav@ivinco.com 94*7Syaroslav@ivinco.com $startPos = $instruction[2]; 95*7Syaroslav@ivinco.com $inSection = TRUE; 96*7Syaroslav@ivinco.com } 97*7Syaroslav@ivinco.com } else { 98*7Syaroslav@ivinco.com 99*7Syaroslav@ivinco.com // Look for the end of the section 100*7Syaroslav@ivinco.com if ( $instruction[0] == 'section_close' ) { 101*7Syaroslav@ivinco.com $endPos = $instruction[2]; 102*7Syaroslav@ivinco.com break; 103*7Syaroslav@ivinco.com } 104*7Syaroslav@ivinco.com } 105*7Syaroslav@ivinco.com } 106*7Syaroslav@ivinco.com 107*7Syaroslav@ivinco.com // Normalize and pad the document in the same way the parse does 108*7Syaroslav@ivinco.com // so that byte indexes with match 109*7Syaroslav@ivinco.com $doc = "\n".str_replace("\r\n","\n",$doc)."\n"; 110*7Syaroslav@ivinco.com $section = substr($doc, $startPos, ($endPos-$startPos)); 111*7Syaroslav@ivinco.com 112*7Syaroslav@ivinco.com return $section; 113*7Syaroslav@ivinco.com} 114*7Syaroslav@ivinco.com 115*7Syaroslav@ivinco.comfunction getCategories($id) 116*7Syaroslav@ivinco.com{ 117*7Syaroslav@ivinco.com if (empty($id)) return ''; 118*7Syaroslav@ivinco.com 119*7Syaroslav@ivinco.com if (false === strpos($id, ":")){ 120*7Syaroslav@ivinco.com return $id; 121*7Syaroslav@ivinco.com } 122*7Syaroslav@ivinco.com 123*7Syaroslav@ivinco.com $ns = explode(":", $id); 124*7Syaroslav@ivinco.com $nsCount = count($ns); 125*7Syaroslav@ivinco.com 126*7Syaroslav@ivinco.com $result = ''; 127*7Syaroslav@ivinco.com do{ 128*7Syaroslav@ivinco.com for($i = 0; $i < $nsCount; $i++){ 129*7Syaroslav@ivinco.com $name = $ns[$i]; 130*7Syaroslav@ivinco.com $result .= $name; 131*7Syaroslav@ivinco.com if ($i < $nsCount - 1){ 132*7Syaroslav@ivinco.com $result .= ':'; 133*7Syaroslav@ivinco.com } 134*7Syaroslav@ivinco.com } 135*7Syaroslav@ivinco.com $result .= ' '; 136*7Syaroslav@ivinco.com }while($nsCount--); 137*7Syaroslav@ivinco.com return $result; 138*7Syaroslav@ivinco.com} 139*7Syaroslav@ivinco.com 140*7Syaroslav@ivinco.com 141*7Syaroslav@ivinco.com /** 142*7Syaroslav@ivinco.com * Method return all wiki page names 143*7Syaroslav@ivinco.com * @global array $conf 144*7Syaroslav@ivinco.com * @return array 145*7Syaroslav@ivinco.com */ 146*7Syaroslav@ivinco.com function getPagesList() 147*7Syaroslav@ivinco.com { 148*7Syaroslav@ivinco.com global $conf; 149*7Syaroslav@ivinco.com 150*7Syaroslav@ivinco.com $data = array(); 151*7Syaroslav@ivinco.com sort($data); 152*7Syaroslav@ivinco.com search($data,$conf['datadir'],'search_allpages','',''); 153*7Syaroslav@ivinco.com 154*7Syaroslav@ivinco.com return $data; 155*7Syaroslav@ivinco.com}