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</sphinx:document> 177Syaroslav@ivinco.com 187Syaroslav@ivinco.com'; 197Syaroslav@ivinco.com 2012Syaroslav@ivinco.com return str_replace( array('{id}', '{title}', '{body}', '{categories}', '{level}', '{modified}'), 217Syaroslav@ivinco.com array($data['id'], $data['title'], $data['body'], $data['categories'], 2212Syaroslav@ivinco.com $data['level'], $data['modified']), 237Syaroslav@ivinco.com $xmlFormat 247Syaroslav@ivinco.com ); 257Syaroslav@ivinco.com} 267Syaroslav@ivinco.com 277Syaroslav@ivinco.comfunction getDocumentsByHeadings($id, $metadata) 287Syaroslav@ivinco.com{ 297Syaroslav@ivinco.com if (empty($metadata) || empty($metadata['description']['tableofcontents'])) return false; 307Syaroslav@ivinco.com 317Syaroslav@ivinco.com $sections = array(); 327Syaroslav@ivinco.com foreach($metadata['description']['tableofcontents'] as $row){ 337Syaroslav@ivinco.com $sections[$row['hid']] = array( 347Syaroslav@ivinco.com 'section' => getSection($id, $row['title']), 357Syaroslav@ivinco.com 'title' => $row['title'], 367Syaroslav@ivinco.com 'level' => $row['level'] 377Syaroslav@ivinco.com ); 387Syaroslav@ivinco.com } 397Syaroslav@ivinco.com return $sections; 407Syaroslav@ivinco.com} 417Syaroslav@ivinco.com 427Syaroslav@ivinco.comfunction getSection($id, $header) 437Syaroslav@ivinco.com{ 447Syaroslav@ivinco.com // Create the parser 457Syaroslav@ivinco.com $Parser = & new Doku_Parser(); 467Syaroslav@ivinco.com 477Syaroslav@ivinco.com // Add the Handler 487Syaroslav@ivinco.com $Parser->Handler = & new Doku_Handler(); 497Syaroslav@ivinco.com 507Syaroslav@ivinco.com // Load the header mode to find headers 517Syaroslav@ivinco.com $Parser->addMode('header',new Doku_Parser_Mode_Header()); 527Syaroslav@ivinco.com 537Syaroslav@ivinco.com // Load the modes which could contain markup that might be 547Syaroslav@ivinco.com // mistaken for a header 557Syaroslav@ivinco.com $Parser->addMode('listblock',new Doku_Parser_Mode_ListBlock()); 567Syaroslav@ivinco.com $Parser->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); 577Syaroslav@ivinco.com $Parser->addMode('table',new Doku_Parser_Mode_Table()); 587Syaroslav@ivinco.com $Parser->addMode('unformatted',new Doku_Parser_Mode_Unformatted()); 597Syaroslav@ivinco.com $Parser->addMode('php',new Doku_Parser_Mode_PHP()); 607Syaroslav@ivinco.com $Parser->addMode('html',new Doku_Parser_Mode_HTML()); 617Syaroslav@ivinco.com $Parser->addMode('code',new Doku_Parser_Mode_Code()); 627Syaroslav@ivinco.com $Parser->addMode('file',new Doku_Parser_Mode_File()); 637Syaroslav@ivinco.com $Parser->addMode('quote',new Doku_Parser_Mode_Quote()); 647Syaroslav@ivinco.com $Parser->addMode('footnote',new Doku_Parser_Mode_Footnote()); 657Syaroslav@ivinco.com $Parser->addMode('internallink',new Doku_Parser_Mode_InternalLink()); 667Syaroslav@ivinco.com $Parser->addMode('media',new Doku_Parser_Mode_Media()); 677Syaroslav@ivinco.com $Parser->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); 687Syaroslav@ivinco.com $Parser->addMode('windowssharelink',new Doku_Parser_Mode_WindowsShareLink()); 697Syaroslav@ivinco.com $Parser->addMode('filelink',new Doku_Parser_Mode_FileLink()); 707Syaroslav@ivinco.com 717Syaroslav@ivinco.com // Loads the raw wiki document 727Syaroslav@ivinco.com $doc = io_readFile(wikiFN($id)); 737Syaroslav@ivinco.com 747Syaroslav@ivinco.com // Get a list of instructions 757Syaroslav@ivinco.com $instructions = $Parser->parse($doc); 767Syaroslav@ivinco.com 777Syaroslav@ivinco.com unset($Parser); 787Syaroslav@ivinco.com 797Syaroslav@ivinco.com // Use this to watch when we're inside the section we want 807Syaroslav@ivinco.com $inSection = FALSE; 817Syaroslav@ivinco.com $startPos = 0; 827Syaroslav@ivinco.com $endPos = 0; 837Syaroslav@ivinco.com 847Syaroslav@ivinco.com // Loop through the instructions 857Syaroslav@ivinco.com foreach ( $instructions as $instruction ) { 867Syaroslav@ivinco.com 877Syaroslav@ivinco.com if ( !$inSection ) { 887Syaroslav@ivinco.com 897Syaroslav@ivinco.com // Look for the header for the "Lists" heading 907Syaroslav@ivinco.com if ( $instruction[0] == 'header' && 917Syaroslav@ivinco.com trim($instruction[1][0]) == $header ) { 927Syaroslav@ivinco.com 937Syaroslav@ivinco.com $startPos = $instruction[2]; 947Syaroslav@ivinco.com $inSection = TRUE; 957Syaroslav@ivinco.com } 967Syaroslav@ivinco.com } else { 977Syaroslav@ivinco.com 987Syaroslav@ivinco.com // Look for the end of the section 997Syaroslav@ivinco.com if ( $instruction[0] == 'section_close' ) { 1007Syaroslav@ivinco.com $endPos = $instruction[2]; 1017Syaroslav@ivinco.com break; 1027Syaroslav@ivinco.com } 1037Syaroslav@ivinco.com } 1047Syaroslav@ivinco.com } 1057Syaroslav@ivinco.com 1067Syaroslav@ivinco.com // Normalize and pad the document in the same way the parse does 1077Syaroslav@ivinco.com // so that byte indexes with match 1087Syaroslav@ivinco.com $doc = "\n".str_replace("\r\n","\n",$doc)."\n"; 1097Syaroslav@ivinco.com $section = substr($doc, $startPos, ($endPos-$startPos)); 1107Syaroslav@ivinco.com 1117Syaroslav@ivinco.com return $section; 1127Syaroslav@ivinco.com} 1137Syaroslav@ivinco.com 1147Syaroslav@ivinco.comfunction getCategories($id) 1157Syaroslav@ivinco.com{ 1167Syaroslav@ivinco.com if (empty($id)) return ''; 1177Syaroslav@ivinco.com 1187Syaroslav@ivinco.com if (false === strpos($id, ":")){ 1197Syaroslav@ivinco.com return $id; 1207Syaroslav@ivinco.com } 1217Syaroslav@ivinco.com 1227Syaroslav@ivinco.com $ns = explode(":", $id); 1237Syaroslav@ivinco.com $nsCount = count($ns); 1247Syaroslav@ivinco.com 1257Syaroslav@ivinco.com $result = ''; 1267Syaroslav@ivinco.com do{ 1277Syaroslav@ivinco.com for($i = 0; $i < $nsCount; $i++){ 1287Syaroslav@ivinco.com $name = $ns[$i]; 1297Syaroslav@ivinco.com $result .= $name; 1307Syaroslav@ivinco.com if ($i < $nsCount - 1){ 1317Syaroslav@ivinco.com $result .= ':'; 1327Syaroslav@ivinco.com } 1337Syaroslav@ivinco.com } 1347Syaroslav@ivinco.com $result .= ' '; 1357Syaroslav@ivinco.com }while($nsCount--); 1367Syaroslav@ivinco.com return $result; 1377Syaroslav@ivinco.com} 1387Syaroslav@ivinco.com 1397Syaroslav@ivinco.com 1407Syaroslav@ivinco.com /** 1417Syaroslav@ivinco.com * Method return all wiki page names 1427Syaroslav@ivinco.com * @global array $conf 1437Syaroslav@ivinco.com * @return array 1447Syaroslav@ivinco.com */ 1457Syaroslav@ivinco.com function getPagesList() 1467Syaroslav@ivinco.com { 1477Syaroslav@ivinco.com global $conf; 1487Syaroslav@ivinco.com 1497Syaroslav@ivinco.com $data = array(); 1507Syaroslav@ivinco.com sort($data); 1517Syaroslav@ivinco.com search($data,$conf['datadir'],'search_allpages','',''); 1527Syaroslav@ivinco.com 1537Syaroslav@ivinco.com return $data; 1548Syaroslav@ivinco.com} 1558Syaroslav@ivinco.com 156*15Syaroslav@ivinco.comfunction getNsLinks($id, $keywords, $search) 1578Syaroslav@ivinco.com{ 1588Syaroslav@ivinco.com global $conf; 1598Syaroslav@ivinco.com $parts = explode(':', $id); 1608Syaroslav@ivinco.com $count = count($parts); 161*15Syaroslav@ivinco.com 1628Syaroslav@ivinco.com // print intermediate namespace links 1638Syaroslav@ivinco.com $part = ''; 16410Syaroslav@ivinco.com $data = array(); 16510Syaroslav@ivinco.com $titles = array(); 1668Syaroslav@ivinco.com for($i=0; $i<$count; $i++){ 1678Syaroslav@ivinco.com $part .= $parts[$i].':'; 1688Syaroslav@ivinco.com $page = $part; 1698Syaroslav@ivinco.com resolve_pageid('',$page,$exists); 170*15Syaroslav@ivinco.com 171*15Syaroslav@ivinco.com if (preg_match("#:start$#", $page) && !preg_match("#:start:$#", $part)) { 17213Syaroslav@ivinco.com $page = substr($page, 0, strpos($page, ":start")); 17313Syaroslav@ivinco.com }; 1748Syaroslav@ivinco.com 1758Syaroslav@ivinco.com // output 1768Syaroslav@ivinco.com if ($exists){ 177*15Syaroslav@ivinco.com $titles[wl($page)] = $parts[$i]; 1788Syaroslav@ivinco.com } else { 17910Syaroslav@ivinco.com continue; //Skip not exists pages 180*15Syaroslav@ivinco.com } 181*15Syaroslav@ivinco.com $data[] = array('link' => "?do=sphinxsearch&id={$keywords}".urlencode(" @categories $page")); 1828Syaroslav@ivinco.com } 183*15Syaroslav@ivinco.com $titleExcerpt = $search->getExcerpt($titles, $search->starQuery($keywords)); 18410Syaroslav@ivinco.com $i = 0; 18510Syaroslav@ivinco.com foreach ($data as $key => $notused){ 18610Syaroslav@ivinco.com $data[$key]['title'] = $titleExcerpt[$i++]; 18710Syaroslav@ivinco.com } 18810Syaroslav@ivinco.com return $data; 1897Syaroslav@ivinco.com}