5 * Base rendering class for parsed and tokenized text.
11 * @author Paul M. Jones <pmjones@php.net>
15 * @version $Id: Render.php,v 1.5 2005/02/23 17:38:29 pmjones Exp $
21 * Base rendering class for parsed and tokenized text.
27 * @author Paul M. Jones <pmjones@php.net>
33 class Text_Wiki_Render
{
38 * Configuration options for this render rule.
51 * The name of this rule's format.
64 * The name of this rule's token array elements.
77 * A reference to the calling Text_Wiki object.
79 * This is needed so that each rule has access to the same source
80 * text, token set, URLs, interwiki maps, page names, etc.
92 * Constructor for this render format or rule.
96 * @param object &$obj The calling "parent" Text_Wiki object.
100 function Text_Wiki_Render(&$obj)
102 // keep a reference to the calling Text_Wiki object
105 // get the config-key-name for this object,
106 // strip the Text_Wiki_Render_ part
108 $tmp = get_class($this);
109 $tmp = substr($tmp, 17);
111 // split into pieces at the _ mark.
112 // first part is format, second part is rule.
113 $part = explode('_', $tmp);
114 $this->format
= isset($part[0]) ?
ucwords(strtolower($part[0])) : null
;
115 $this->rule
= isset($part[1]) ?
ucwords(strtolower($part[1])) : null
;
117 // is there a format but no rule?
118 // then this is the "main" render object, with
119 // pre() and post() methods.
120 if ($this->format
&& ! $this->rule
&&
121 isset($this->wiki
->formatConf
[$this->format
]) &&
122 is_array($this->wiki
->formatConf
[$this->format
])) {
124 // this is a format render object
125 $this->conf
= array_merge(
127 $this->wiki
->formatConf
[$this->format
]
132 // is there a format and a rule?
133 if ($this->format
&& $this->rule
&&
134 isset($this->wiki
->renderConf
[$this->format
][$this->rule
]) &&
135 is_array($this->wiki
->renderConf
[$this->format
][$this->rule
])) {
137 // this is a rule render object
138 $this->conf
= array_merge(
140 $this->wiki
->renderConf
[$this->format
][$this->rule
]
148 * Simple method to safely get configuration key values.
152 * @param string $key The configuration key.
154 * @param mixed $default If the key does not exist, return this value
157 * @return mixed The configuration key value (if it exists) or the
158 * default value (if not).
162 function getConf($key, $default = null
)
164 if (isset($this->conf
[$key])) {
165 return $this->conf
[$key];
174 * Simple method to wrap a configuration in an sprintf() format.
178 * @param string $key The configuration key.
180 * @param string $format The sprintf() format string.
182 * @return mixed The formatted configuration key value (if it exists)
183 * or null (if it does not).
187 function formatConf($format, $key)
189 if (isset($this->conf
[$key])) {
190 return sprintf($format, $this->conf
[$key]);