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 //parse meta data for headers, abstract, date, authors 70 $data = array(); 71 $data['id'] = crc32($dokuPageId.$hid); 72 $data['namespace'] = getCategories($dokuPageId); 73 $data['pagename'] = getPagename($dokuPageId); 74 $data['level'] = $section['level']; 75 $data['modified'] = $metadata['date']['modified']; 76 $data['title'] = strip_tags($section['title_text']); 77 $data['title_to_index'] = $section['title_to_index']; 78 $data['body'] = $section['section']; //strip_tags(p_render('xhtml',p_get_instructions($section['section']),$info)); 79 80 //convert to utf-8 encoding 81 $data['title_to_index'] = mb_convert_encoding($data['title_to_index'], "UTF-8", mb_detect_encoding($data['title_to_index'], "auto")); 82 $data['body'] = mb_convert_encoding($data['body'], "UTF-8", mb_detect_encoding($data['body'], "auto")); 83 84 echo formatXml($data)."\n"; 85 $pageMapper->add($dokuPageId, $data['title'], $section['title'], $hid); 86 } 87 } else { 88 $data = array(); 89 $data['id'] = crc32($dokuPageId); 90 $data['namespace'] = getCategories($dokuPageId); 91 $data['pagename'] = getPagename($dokuPageId); 92 $data['level'] = 1; 93 $data['modified'] = $metadata['date']['modified']; 94 $data['title'] = strip_tags($metadata['title']); 95 $data['title_to_index'] = $metadata['title']; 96 $data['body'] = io_readFile(wikiFN($dokuPageId)); //strip_tags(p_wiki_xhtml($dokuPageId,$metadata['date']['modified'],false)); 97 98 //convert to utf-8 encoding 99 $data['title_to_index'] = mb_convert_encoding($data['title_to_index'], "UTF-8", mb_detect_encoding($data['title_to_index'], "auto")); 100 $data['body'] = mb_convert_encoding($data['body'], "UTF-8", mb_detect_encoding($data['body'], "auto")); 101 102 echo formatXml($data)."\n"; 103 $pageMapper->add($dokuPageId, $metadata['title'], $metadata['title']); 104 } 105 106} 107echo '</sphinx:docset>'; 108 109ini_set('display_errors', $deStatus);