1<?php 2/** 3 * XML feed export 4 * 5 * @author Ivinco <opensource@ivinco.com> 6 */ 7 8$deStatus = ini_get('display_errors'); 9ini_set('display_errors', 0); 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 29$dataPath = fullpath($conf['savedir']); 30if (!@file_exists($dataPath)) { 31 $dataPath = fullpath(DOKU_INC . $conf['savedir']); 32 if (!@file_exists($dataPath)) die('invalid DokuWiki savedir'); 33} 34$fullSphinxPath = $dataPath . '/sphinxsearch/'; 35if (!@file_exists($fullSphinxPath)) { 36 mkdir($fullSphinxPath); 37} 38 39$pagesList = getPagesList(); 40 41echo '<?xml version="1.0" encoding="utf-8"?> 42<sphinx:docset> 43 44<sphinx:schema> 45<sphinx:field name="title"/> 46<sphinx:field name="body"/> 47<sphinx:field name="namespace"/> 48<sphinx:field name="pagename"/> 49<sphinx:field name="level"/> 50<sphinx:field name="modified"/> 51<sphinx:attr name="level" type="int" bits="8" default="1"/> 52</sphinx:schema> 53'; 54 55$pageMapper = new PageMapper(); 56foreach($pagesList as $row){ 57 $dokuPageId = $row['id']; 58 resolve_pageid('',$page,$exists); 59 if (empty($dokuPageId) || !$exists){ //do not include not exists page 60 continue; 61 } 62 //get meta data 63 $metadata = p_get_metadata($dokuPageId); 64 65 $sections = getDocumentsByHeadings($dokuPageId, $metadata); 66 67 if (!empty($sections)){ 68 foreach($sections as $hid => $section){ 69 if (empty($section['section'])){ 70 continue; 71 } 72 //parse meta data for headers, abstract, date, authors 73 $data = array(); 74 $data['id'] = sprintf('%u', crc32($dokuPageId.$hid)); 75 $data['namespace'] = getCategories($dokuPageId); 76 $data['pagename'] = getPagename($dokuPageId); 77 $data['level'] = $section['level']; 78 $data['modified'] = $metadata['date']['modified']; 79 $data['title'] = strip_tags($section['title_text']); 80 $data['title_to_index'] = $section['title_to_index']; 81 $data['body'] = $section['section']; //strip_tags(p_render('xhtml',p_get_instructions($section['section']),$info)); 82 83 //convert to utf-8 encoding 84 $data['title_to_index'] = mb_convert_encoding($data['title_to_index'], "UTF-8", mb_detect_encoding($data['title_to_index'], "auto")); 85 $data['body'] = mb_convert_encoding($data['body'], "UTF-8", mb_detect_encoding($data['body'], "auto")); 86 87 echo formatXml($data)."\n"; 88 $pageMapper->add($dokuPageId, $data['title'], $section['title'], $hid); 89 } 90 } else { 91 $data = array(); 92 $data['id'] = sprintf('%u', crc32($dokuPageId.$hid)); 93 $data['namespace'] = getCategories($dokuPageId); 94 $data['pagename'] = getPagename($dokuPageId); 95 $data['level'] = 1; 96 $data['modified'] = $metadata['date']['modified']; 97 $data['title'] = strip_tags($metadata['title']); 98 $data['title_to_index'] = $metadata['title']; 99 $data['body'] = io_readFile(wikiFN($dokuPageId)); //strip_tags(p_wiki_xhtml($dokuPageId,$metadata['date']['modified'],false)); 100 101 if (empty($data['body'])){ 102 continue; 103 } 104 105 //convert to utf-8 encoding 106 $data['title_to_index'] = mb_convert_encoding($data['title_to_index'], "UTF-8", mb_detect_encoding($data['title_to_index'], "auto")); 107 $data['body'] = mb_convert_encoding($data['body'], "UTF-8", mb_detect_encoding($data['body'], "auto")); 108 109 echo formatXml($data)."\n"; 110 $pageMapper->add($dokuPageId, $metadata['title'], $metadata['title']); 111 } 112 113} 114echo '</sphinx:docset>'; 115 116ini_set('display_errors', $deStatus);