Viewer Modules

« Back to 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 $content in $format, as retrieved from Q2A's database. You should return 1.0 to indicate perfect ability, and 0.0 for 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 $content in $format and render it as HTML with UTF-8 encoding. The $options parameter 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 to qa_block_words_match_all() or qa_block_words_replace() in qa-util-string.php to 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.)
    • If $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.
    • If $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 $content in $format and 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 get_html().

« Back to modules