1<?php 2/** 3 * XML feed export 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9 10/* Initialization */ 11 12if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../../'); 13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 14 15require_once(DOKU_INC.'inc/init.php'); 16require_once(DOKU_INC.'inc/common.php'); 17require_once(DOKU_INC.'inc/events.php'); 18require_once(DOKU_INC.'inc/parserutils.php'); 19require_once(DOKU_INC.'inc/feedcreator.class.php'); 20require_once(DOKU_INC.'inc/auth.php'); 21require_once(DOKU_INC.'inc/pageutils.php'); 22require_once(DOKU_INC.'inc/search.php'); 23require_once(DOKU_INC.'inc/parser/parser.php'); 24 25 26require_once(DOKU_PLUGIN.'sphinxsearch/PageMapper.php'); 27require_once(DOKU_PLUGIN.'sphinxsearch/functions.php'); 28 29if (!file_exists(DOKU_INC.$conf['savedir']."/sphinxsearch/")){ 30 mkdir(DOKU_INC.$conf['savedir']."/sphinxsearch/"); 31} 32 33$pagesList = getPagesList(); 34 35echo '<?xml version="1.0" encoding="utf-8"?> 36<sphinx:docset> 37 38<sphinx:schema> 39<sphinx:field name="title"/> 40<sphinx:field name="body"/> 41<sphinx:field name="namespace"/> 42<sphinx:field name="pagename"/> 43<sphinx:field name="level"/> 44<sphinx:field name="modified"/> 45<sphinx:attr name="level" type="int" bits="8" default="1"/> 46</sphinx:schema> 47'; 48 49$pageMapper = new PageMapper(); 50foreach($pagesList as $row){ 51 $dokuPageId = $row['id']; 52 resolve_pageid('',$page,$exists); 53 if (empty($dokuPageId) || !$exists){ //do not include not exists page 54 continue; 55 } 56 //get meta data 57 $metadata = p_get_metadata($dokuPageId); 58 59 $sections = getDocumentsByHeadings($dokuPageId, $metadata); 60 61 if (!empty($sections)){ 62 foreach($sections as $hid => $section){ 63 //parse meta data for headers, abstract, date, authors 64 $data = array(); 65 $data['id'] = crc32($dokuPageId.$hid); 66 $data['namespace'] = getCategories($dokuPageId); 67 $data['pagename'] = getPagename($dokuPageId); 68 $data['level'] = $section['level']; 69 $data['modified'] = $metadata['date']['modified']; 70 $data['title'] = strip_tags($section['title_text']); 71 $data['title_to_index'] = $section['title_to_index']; 72 $data['body'] = $section['section']; //strip_tags(p_render('xhtml',p_get_instructions($section['section']),$info)); 73 74 //convert to utf-8 encoding 75 $data['title_to_index'] = mb_convert_encoding($data['title_to_index'], "UTF-8", mb_detect_encoding($data['title_to_index'], "auto")); 76 $data['body'] = mb_convert_encoding($data['body'], "UTF-8", mb_detect_encoding($data['body'], "auto")); 77 78 echo formatXml($data)."\n"; 79 $pageMapper->add($dokuPageId, $data['title'], $section['title'], $hid); 80 } 81 } else { 82 $data = array(); 83 $data['id'] = crc32($dokuPageId); 84 $data['namespace'] = getCategories($dokuPageId); 85 $data['pagename'] = getPagename($dokuPageId); 86 $data['level'] = 1; 87 $data['modified'] = $metadata['date']['modified']; 88 $data['title'] = strip_tags($metadata['title']); 89 $data['title_to_index'] = $metadata['title']; 90 $data['body'] = io_readFile(wikiFN($dokuPageId)); //strip_tags(p_wiki_xhtml($dokuPageId,$metadata['date']['modified'],false)); 91 92 //convert to utf-8 encoding 93 $data['title_to_index'] = mb_convert_encoding($data['title_to_index'], "UTF-8", mb_detect_encoding($data['title_to_index'], "auto")); 94 $data['body'] = mb_convert_encoding($data['body'], "UTF-8", mb_detect_encoding($data['body'], "auto")); 95 96 echo formatXml($data)."\n"; 97 $pageMapper->add($dokuPageId, $metadata['title'], $metadata['title']); 98 } 99 100} 101echo '</sphinx:docset>'; 102