Beispiel #1
0
function spamhurdle_captcha_build_form($data)
{
    if (!isset($data['captcha']['html_form'])) {
        return $data;
    }
    global $PHORUM;
    $config = $PHORUM['mod_spamhurdles']['captcha'];
    $captcha = $data['captcha'];
    $form = $captcha['html_form'];
    // The actual value in the captcha is named {FIELDVALUE} in the
    // generated captcha HTML code. Replace it with the actual value.
    $fn = $captcha["input_fieldname"];
    $fieldvalue = isset($_POST[$fn]) ? $_POST[$fn] : "";
    $form = str_replace("{FIELDVALUE}", htmlspecialchars($fieldvalue), $form);
    // Replace SPOKENURL with the URL for the spoken captcha code.
    if ($config["spoken_captcha"] && file_exists($config["flite_location"])) {
        $url = phorum_get_url(PHORUM_ADDON_URL, 'module=spamhurdles', 'hurdle=captcha', 'spokencaptcha=' . rawurlencode(spamhurdles_encrypt($captcha['spoken_text'])));
        $form = str_replace('{SPOKENURL}', htmlspecialchars($url), $form);
    }
    // Replace IMAGE with the URL for the captcha image.
    $url = phorum_get_url(PHORUM_ADDON_URL, 'module=spamhurdles', 'hurdle=captcha', 'imagecaptcha=' . rawurlencode(spamhurdles_encrypt(array('question' => $captcha['question'], 'type' => $captcha['type']))));
    $form = str_replace('{IMAGEURL}', htmlspecialchars($url), $form);
    if (!empty($data['use_editor_block'])) {
        $PHORUM['DATA']['CONTENT'] = $form;
        $PHORUM['DATA']['EDITOR'] = $data['use_editor_block'];
        include phorum_get_template('spamhurdles::editor_block');
    } else {
        print $form;
    }
    return $data;
}
Beispiel #2
0
/**
 * Each time that the form has to be displayed, this function can be used
 * to build the HTML code that needs to be added to the protected form.
 *
 * @param array $data
 *     An array containing the spam hurdles data for the form.
 *     This data can be initialized for a new form by means of
 *     the {@link spamhurdles_api_init()} function.
 *
 * @return string
 *     The data that has to be added to the form.
 */
function spamhurdles_api_build_form($data)
{
    global $PHORUM;
    ob_start();
    // Add the spam hurdles data encrypted to the form.
    // Remove work data. This data is only used for storing data
    // during a request. Also, update the TTL for the data.
    $send_data = $data;
    unset($send_data['work']);
    $send_data['ttl'] = time() + $PHORUM['mod_spamhurdles']['key_max_ttl'];
    $crypted = htmlspecialchars(spamhurdles_encrypt($send_data));
    print '<input type="hidden" name="spamhurdles_' . $data['id'] . '" ' . 'id="spamhurdles_' . $data['id'] . '" value="' . $crypted . '"/>';
    // Let hurdles add their required data.
    spamhurdles_hurdle_call('build_form', $data, $data['hurdles']);
    $form = ob_get_contents();
    ob_end_clean();
    return $form;
}