Page Modules
A page module adds one or more new pages to a Q2A installation. In Q2A, every page displayed has a corresponding $request string. For example, the $request for Q2A's page for user John Doe is 'user/John Doe'. Page modules are able to control the output for particular $request strings in the same way. (Depending on the chosen URL structure for a Q2A installation, $request can be represented in different ways on the actual URL - you need not worry about this, nor should you make any assumptions.)
The PHP class for a page module can contain the following functions (all are optional):
-
match_request($request)should returntrueif your page module will respond to Q2A page$request. -
suggest_requests()should return an array of suggested pages for your module. These suggestions will be displayed within the Q2A admin interface. Each element for a page in the array is itself an array, containing the following elements:titlecontains a human-readable title used to describe the page, e.g.'More Stats'.requestcontains the Q2A$requeststring for the page, e.g.'stats/more'. Yourmatch_request()function should of course returntruefor this string.navcontains a suggestion about where this page should be linked in the navigation menus. This is only a hint and can easily be changed by the site's administrator. Use'M'for after the main menu,'B'for before the main menu,'O'for opposite the main menu,'F'for the footer, ornullfor no navigation element.
-
process_request($request)allows your page module to respond for a particular$request. This function should perform any necessary processing based on user inputs, and return information about the page to be displayed in a nested Q2A content array, named$qa_contentby convention. (If your function outputs some special content such as XML, returnnullto prevent Q2A displaying anything further.) It is beyond the scope of this documentation to describe$qa_contentin detail - there are many examples in theqa-page-*.phpfiles and the page plugins that come with Q2A. You can also see how$qa_contentis picked apart at the end ofqa-page.phpand inmain()inqa-theme-base.php. Some particular points to note:- Always start by assigning
$qa_content=qa_content_prepare();to include navigation menus and the like. - All elements within the nested
$qa_contentarray should be made HTML safe - useqa_html()as appropriate. - Use
$qa_content['title']and$qa_content['error']to display a page title or error message respectively. - To add some custom HTML to the page, add an element to
$qa_contentwhose key begins withcustom, e.g.$qa_content['custom']or$qa_content['custom_2']. The value of the element should contain the actual HTML. - To add a Q2A-style form to the page, add an element to
$qa_contentwhose key begins withform, e.g.$qa_content['form']or$qa_content['form_2']. The value of the element should contain a Q2A form array, whose definition is also beyond the scope of this documentation, although see the comments here. - Other possible types of structured content in
$qa_contentare question lists (keys startingq_list), question views (q_view), answer lists (a_list) and rankings (ranking). Look through theqa-page-*.phpfiles for examples. - The elements in
$qa_contentare displayed in array order, with a few exceptions such as page titles and errors.
- Always start by assigning