Viewer Modules
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.
The PHP 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$contentin$format, as retrieved from Q2A's database. You should return1.0to indicate perfect ability, and0.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$contentin$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:- If
$options['blockwordspreg']is set, it contains a regular expression fragment which represents censored word patterns. You can pass it toqa_block_words_match_all()orqa_block_words_replace()inqa-util-string.phpto retrieve or replace censored word matches in a target string. (You should not use this regular expression directly inpreg_*functions since it makes some assumptions about word separators that Q2A's own functions take care of.) - If
$options['showurllinks']is set andtrue, your viewer should detect URLs within the content and replace them with HTML links. The functionqa_html_convert_urls(), defined inqa-app-format.php, might be helpful here. - If
$options['linksnewwindow']is set andtrue, your viewer should open any links in a new window, i.e. useTARGET="_blank". This applies to links detected by your module as well as any pre-existing in$content. The functionqa_sanitize_html(), defined inqa-base.php, might be helpful here.
- If
-
get_text($content, $format, $options)should take the supplied$contentin$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 forget_html().
