Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
248 jpm 1
<?php
2
 
3
class Text_Wiki_Render {
4
 
5
 
6
    /**
7
    *
8
    * Configuration options for this render rule.
9
    *
10
    * @access public
11
    *
12
    * @var string
13
    *
14
    */
15
 
16
    var $conf = array();
17
 
18
 
19
    /**
20
    *
21
    * The name of this rule's format.
22
    *
23
    * @access public
24
    *
25
    * @var string
26
    *
27
    */
28
 
29
    var $format = null;
30
 
31
 
32
    /**
33
    *
34
    * The name of this rule's token array elements.
35
    *
36
    * @access public
37
    *
38
    * @var string
39
    *
40
    */
41
 
42
    var $rule = null;
43
 
44
 
45
    /**
46
    *
47
    * A reference to the calling Text_Wiki object.
48
    *
49
    * This is needed so that each rule has access to the same source
50
    * text, token set, URLs, interwiki maps, page names, etc.
51
    *
52
    * @access public
53
    *
54
    * @var object
55
    */
56
 
57
    var $wiki = null;
58
 
59
 
60
    /**
61
    *
62
    * Constructor for this render format or rule.
63
    *
64
    * @access public
65
    *
66
    * @param object &$obj The calling "parent" Text_Wiki object.
67
    *
68
    */
69
 
70
    function Text_Wiki_Render(&$obj)
71
    {
72
        // keep a reference to the calling Text_Wiki object
73
        $this->wiki =& $obj;
74
 
75
        // get the config-key-name for this object,
76
        // strip the Text_Wiki_Render_ part
77
        //           01234567890123456
78
        $tmp = get_class($this);
79
        $tmp = substr($tmp, 17);
80
 
81
        // split into pieces at the _ mark.
82
        // first part is format, second part is rule.
83
        $part   = explode('_', $tmp);
84
        $this->format = isset($part[0]) ? ucwords(strtolower($part[0])) : null;
85
        $this->rule   = isset($part[1]) ? ucwords(strtolower($part[1])) : null;
86
 
87
        // is there a format but no rule?
88
        // then this is the "main" render object, with
89
        // pre() and post() methods.
90
        if ($this->format && ! $this->rule &&
91
            isset($this->wiki->formatConf[$this->format]) &&
92
            is_array($this->wiki->formatConf[$this->format])) {
93
 
94
            // this is a format render object
95
            $this->conf = array_merge(
96
                $this->conf,
97
                $this->wiki->formatConf[$this->format]
98
            );
99
 
100
        }
101
 
102
        // is there a format and a rule?
103
        if ($this->format && $this->rule &&
104
            isset($this->wiki->renderConf[$this->format][$this->rule]) &&
105
            is_array($this->wiki->renderConf[$this->format][$this->rule])) {
106
 
107
            // this is a rule render object
108
            $this->conf = array_merge(
109
                $this->conf,
110
                $this->wiki->renderConf[$this->format][$this->rule]
111
            );
112
        }
113
    }
114
 
115
 
116
    /**
117
    *
118
    * Simple method to safely get configuration key values.
119
    *
120
    * @access public
121
    *
122
    * @param string $key The configuration key.
123
    *
124
    * @param mixed $default If the key does not exist, return this value
125
    * instead.
126
    *
127
    * @return mixed The configuration key value (if it exists) or the
128
    * default value (if not).
129
    *
130
    */
131
 
132
    function getConf($key, $default = null)
133
    {
134
        if (isset($this->conf[$key])) {
135
            return $this->conf[$key];
136
        } else {
137
            return $default;
138
        }
139
    }
140
 
141
 
142
    /**
143
    *
144
    * Simple method to wrap a configuration in an sprintf() format.
145
    *
146
    * @access public
147
    *
148
    * @param string $key The configuration key.
149
    *
150
    * @param string $format The sprintf() format string.
151
    *
152
    * @return mixed The formatted configuration key value (if it exists)
153
    * or null (if it does not).
154
    *
155
    */
156
 
157
    function formatConf($format, $key)
158
    {
159
        if (isset($this->conf[$key])) {
160
            return sprintf($format, $this->conf[$key]);
161
        } else {
162
            return null;
163
        }
164
    }
165
 
166
}
167
?>