A quick search through the Question2Answer code showed that the message was defined via this line in qa-include/app/captcha.php
:
$notehtml = qa_insert_login_links(qa_lang_html('misc/captcha_login_fix'));
so the simplest way would've been to just patch the additional message text into that line:
$notehtml = "My custom message. " . qa_insert_login_links(qa_lang_html('misc/captcha_login_fix'));
However, since I defined my terms and conditions in a custom page (Admin → Pages) and I didn't want to hard-code the link to that page, I decided to dig a little deeper.
The function qa_lang_html()
is looking up message identifiers and returns them as HTML fragments. The message identified by the string "misc/captcha_login_fix" comes from a map data structure defined in the file qa-include/lang/qa-lang-misc.php
.
'captcha_login_fix' => 'To avoid this verification in future, please ^1log in^2 or ^3register^4.',
The function qa_insert_login_links()
then transforms the text between the markers ^1
/^2
and ^3
/^4
respectively into links.
In order to get my desired result, I added another lookup term "captcha_terms_fix" to qa-lang-misc.php
and extended qa_insert_login_links()
(in the file qa-include/app/format.php
) to replace my additional markers ^7
/^8
with the correct link.
function qa_insert_login_links($htmlmessage, $topage = null, $params = null)
{
require_once QA_INCLUDE_DIR . 'app/users.php';
$userlinks = qa_get_login_links(qa_path_to_root(), isset($topage) ? qa_path($topage, $params, '') : null);
return strtr(
$htmlmessage,
array(
'^1' => empty($userlinks['login']) ? '' : '<a href="' . qa_html($userlinks['login']) . '">',
'^2' => empty($userlinks['login']) ? '' : '</a>',
'^3' => empty($userlinks['register']) ? '' : '<a href="' . qa_html($userlinks['register']) . '">',
'^4' => empty($userlinks['register']) ? '' : '</a>',
'^5' => empty($userlinks['confirm']) ? '' : '<a href="' . qa_html($userlinks['confirm']) . '">',
'^6' => empty($userlinks['confirm']) ? '' : '</a>',
'^7' => empty($userlinks['terms']) ? '' : '<a href="' . qa_html($userlinks['terms']) . '">',
'^8' => empty($userlinks['terms']) ? '' : '</a>',
)
);
}
For that to work I had to also patch the function qa_get_login_links()
in qa-include/app/user.php
to produce the correct page reference.
function qa_get_login_links($rooturl, $tourl)
{
return array(
'login' => qa_path('login', isset($tourl) ? array('to' => $tourl) : null, $rooturl),
'register' => qa_path('register', isset($tourl) ? array('to' => $tourl) : null, $rooturl),
'confirm' => qa_path('confirm', null, $rooturl),
'logout' => qa_path('logout', null, $rooturl),
'terms' => qa_path('terms-and-conditions', null, $rooturl),
);
}
And because my terms and conditions are defined in a custom page I wanted the additional message (and link) only displayed if that page actually exists. So I added a conditional that checks if the page slug is defined in the database, and prepends the message only if it is.
$notehtml = qa_insert_login_links(qa_lang_html('misc/captcha_login_fix'));
if (qa_db_num_rows(qa_db_query_sub('SELECT tags FROM ^pages WHERE tags LIKE "%terms-and-conditions%"')) > 0) {
$notehtml = qa_insert_login_links(qa_lang_html('misc/captcha_terms_fix')) . '<br/>' . $notehtml;
}
With those modifications in place, my forum now displays an additional message
By submitting this post you agree to our Terms & Conditions.
along with the captcha for anonymous questions and answers.
If you want this too, a patch for Question2Answer 1.8.4 can be downloaded here.