1<?php
2/**
3 * Partial Search Plugin
4 *
5 * @author David Roy <davidroyapp@gmail.com>
6 */
7
8if(!defined('DOKU_INC')) die();
9
10if(!defined('DOKU_LF')) define ('DOKU_LF', "\n");
11require_once DOKU_INC.'inc/parser/renderer.php';
12require_once DOKU_INC.'inc/parser/xhtml.php';
13
14class renderer_plugin_partialsearch extends Doku_Renderer_xhtml {
15
16    function getFormat(){
17        return 'xhtml';
18    }
19
20    function canRender($format){
21        return ($format=='xhtml');
22    }
23
24    function _simpleTitle($name) {
25        global $conf;
26        $name= parent::_simpleTitle($name);
27
28        if ($this->getConf('replaceunderscores')) {
29            return $this->_replaceChars($name);
30        } else {
31            return $name;
32        }
33    }
34
35    function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') {
36        global $conf;
37        $title= parent::_getLinkTitle($title, $default, $isImage, $id, $linktype);
38
39        if ($this->getConf('replaceunderscores') && $id) {
40            $ns= $this->_replaceChars(getNS($id));
41            if (isset($ns) && $ns !== ''){
42                return '[' . ucwords($ns) . '] ' . ucfirst($title);
43            }else{
44                return ucfirst($title);
45            }
46        }else{
47            return $title;
48        }
49    }
50
51    /**
52     * Similar to XBR Plugin: Replaces \n in .txt files with <br/>
53     * Needed because there can be only 1 xhtml renderer (cannot use XBR plugin with this one)
54     */
55    function cdata($text) {
56        global $conf;
57
58        if ($this->getConf('userawreturns')) {
59            $this->doc .= str_replace(DOKU_LF,"<br />".DOKU_LF,$this->_xmlEntities($text));
60        } else {
61            parent::cdata($text);
62        }
63    }
64
65    function _replaceChars($text) {
66        $text = strtr($text, '_', ' ');
67        return $text;
68    }
69
70}
71