A viewer module takes content stored in the database, as generated by an editor module, and renders it for display by Q2A. The default viewer module in
qa-viewer-basic.php takes care of rendering stored text or HTML, so you will only need to create a viewer module if you have an editor module which stores content in a different format.
class for a viewer module must contain the following functions (all are required):
calc_quality($content, $format)should return a numerical value indicating your viewer’s ability to render the supplied
$format, as retrieved from Q2A’s database. You should return
1.0to indicate perfect ability, and
0.0for complete inability. For each piece of content, the viewer module returning the highest value will be used.
get_html($content, $format, $options)should take the supplied
$formatand render it as HTML with UTF-8 encoding. The
$optionsparameter may contain some extra information about how the rendering should take place, although you can choose to ignore this if the module is only used on your own site:
$options['blockwordspreg']is set, it contains a regular expression fragment which represents censored word patterns. You can pass it to
qa-util-string.phpto retrieve or replace censored word matches in a target string. (You should not use this regular expression directly in
preg_*functions since it makes some assumptions about word separators that Q2A’s own functions take care of.)
$options['showurllinks']is set and
true, your viewer should detect URLs within the content and replace them with HTML links. The function
qa_html_convert_urls(), defined in
qa-app-format.php, might be helpful here.
$options['linksnewwindow']is set and
true, your viewer should open any links in a new window, i.e. use
TARGET="_blank". This applies to links detected by your module as well as any pre-existing in
$content. The function
qa_sanitize_html(), defined in
qa-base.php, might be helpful here.
get_text($content, $format, $options)should take the supplied
$formatand render it as plain text with UTF-8 encoding. The text is primarily used in notification emails and for search indexing.
$options['blockwordspreg']should be treated in the same way as for