Пример #1
0
function spamhurdle_block_replay_after_post($data)
{
    global $PHORUM;
    // Register the used key in the database.
    if (!spamhurdles_db_init()) {
        return $data;
    }
    spamhurdles_db_put($data['key'], TRUE, $PHORUM['mod_spamhurdles']['key_max_ttl']);
    return $data;
}
Пример #2
0
function phorum_mod_spamhurdles_init($type, $extrafields = NULL)
{
    global $PHORUM;
    // Retrieve the module configuration.
    $conf = $PHORUM["mod_spamhurdles"];
    // Keep track if we want to save new spamhurdles info to the database.
    $store = FALSE;
    // Generate a spamhurdles key for the posting if this wasn't done yet.
    if (!isset($PHORUM["SPAMHURDLES"]["key"])) {
        // Generate a random spamhurdle key. The chance that we make
        // up an already existing key is ehh... about zero, but since
        // it's not hard to check for duplicates, a check is run for
        // that very special occasion.
        while (TRUE) {
            $key = phorum_mod_spamhurdles_keygen();
            if (!spamhurdles_db_get($key)) {
                break;
            }
        }
        $PHORUM["SPAMHURDLES"] = array("create_time" => time(), "key" => $key, "form_type" => $type, "prev_key_expired" => FALSE);
        $store = TRUE;
    }
    // Generate a CAPTCHA, if required.
    if (!isset($PHORUM["SPAMHURDLES"]["captcha"]) && ($type == "posting" && do_spamhurdle("posting_captcha") || $type == "register" && do_spamhurdle("register_captcha") || $type == "external_captcha")) {
        $class = "captcha_" . $conf["captcha_type"];
        require_once "./mods/spamhurdles/captcha/class.{$class}.php";
        $captcha = new $class();
        $captcha = $captcha->generate_captcha();
        $PHORUM["SPAMHURDLES"]["captcha_class"] = $class;
        $PHORUM["SPAMHURDLES"]["captcha"] = $captcha;
        $store = TRUE;
    }
    // Only for posting messages:
    // Generate a signkey for the MD5 javascript signing check.
    if (!isset($PHORUM["SPAMHURDLES"]["signkey"]) && do_spamhurdle("jsmd5check") && $type == "posting") {
        $signkey = phorum_mod_spamhurdles_keygen();
        $PHORUM["SPAMHURDLES"]["signkey"] = $signkey;
        $store = TRUE;
    }
    // If we encountered an expired key, then keep track of this
    // in the new spamhurdles data.
    if ($PHORUM["SPAMHURDLES_KEY_STATUS"] == KEY_EXPIRED) {
        $PHORUM["SPAMHURDLES"]["prev_key_expired"] = TRUE;
        $store = TRUE;
    }
    // Add fields that were passed in the $extrafields argument.
    if (is_array($extrafields)) {
        foreach ($extrafields as $k => $v) {
            $PHORUM["SPAMHURDLES"][$k] = $v;
        }
        $store = TRUE;
    }
    // Store new spamhurdles information in the database.
    if ($store) {
        spamhurdles_db_put($PHORUM["SPAMHURDLES"]["key"], $PHORUM["SPAMHURDLES"], $conf["key_max_ttl"]);
        spamhurdles_db_put($PHORUM["SPAMHURDLES"]["key"], $PHORUM["SPAMHURDLES"], $conf["key_max_ttl"]);
    }
    return $PHORUM["SPAMHURDLES"];
}