Exemplo n.º 1
0
<?php

$NETCAT_FOLDER = join(strstr(__FILE__, "/") ? "/" : "\\", array_slice(preg_split("/[\\/\\\\]+/", __FILE__), 0, -4)) . (strstr(__FILE__, "/") ? "/" : "\\");
include_once $NETCAT_FOLDER . "vars.inc.php";
//require ($INCLUDE_FOLDER."index.php");
require $ROOT_FOLDER . "connect_io.php";
require_once $MODULE_FOLDER . "captcha/function.inc.php";
if ($_GET['nc_get_new_captcha']) {
    $captcha_hash = nc_captcha_generate_hash();
    nc_captcha_generate_code($captcha_hash);
    $playlist = "{'playlist':[";
    $code = $nc_core->db->get_row("SELECT `Captcha_Code` FROM `Captchas` WHERE `Captcha_Hash` = '" . $captcha_hash . "'");
    $code_hash = $nc_core->db->get_results("SELECT * FROM `Captchas_Settings` WHERE `Key` != 'time'");
    foreach (str_split($code->Captcha_Code) as $letter) {
        $letter = strtolower($letter);
        foreach ($code_hash as $hash) {
            if ($hash->Key == $letter . '.mp3') {
                $h = $hash->Value;
                break;
            }
        }
        $playlist .= "{'file':'" . $nc_core->HTTP_FILES_PATH . "captcha/current_voice/" . $h . "'},";
    }
    $playlist .= "]}";
    $playlist = str_replace('},]}', '}]}', $playlist);
    echo $captcha_hash . '#' . $playlist;
    exit;
}
Exemplo n.º 2
0
/**
 *  Функция для вывода формы с картинкой и скрытым полем
 * @param <type> $attributes атрибуты, которые попадут в тэг img
 * @param string $beg - открывающий html-код кнопки аудиокапчи
 * @param string $mid - текст кнопки аудиокапчи
 * @param string $end - закрывающий html-код кнопки аудиокапчи
 * @param string $btn - текст кнопки обновления капчи
 * @param bool $norefresh - не выводить кнопку обновления
 * @param int|string $id - суффикс для работы нескольких каптч на странице
 * @return string html-код
 */
function nc_captcha_formfield($attributes = '', $beg = '', $mid = '', $end = '', $btn = '', $norefresh = 0, $id = 0)
{
    static $count = 0;
    $id = $id ? $id : $count;
    $beg = $beg ? $beg : "<span class='nc_captcha_voice' style='margin:0 0 0 10px;'><a class='nc_captcha_js' href='#' onclick='nc_captcha{$id}.play();return false;'>&#9834;";
    $mid = $mid ? $mid : NETCAT_MODULE_CAPTCHA_AUDIO_LISTEN;
    $end = $end ? $end : "</a><span id='nc_captcha_player' style='display:none;'></span></span>";
    $btn = $btn ? $btn : NETCAT_MODULE_CAPTCHA_REFRESH;
    $audio_captcha = $beg . $mid . $end;
    $nc_core = nc_Core::get_object();
    // настройки модуля
    $MODULE_VARS = $nc_core->modules->get_module_vars();
    $captcha_hash = nc_captcha_generate_hash();
    nc_captcha_generate_code($captcha_hash);
    $hidden_field_name = $MODULE_VARS['captcha']['HIDDEN_FIELD_NAME'] ? $MODULE_VARS['captcha']['HIDDEN_FIELD_NAME'] : 'nc_captcha_hash';
    $module_path = $nc_core->SUB_FOLDER . $nc_core->HTTP_ROOT_PATH . "modules/captcha/";
    // Аудио каптча
    if ($MODULE_VARS['captcha']['AUDIOCAPTCHA_ENABLED']) {
        $player = "<script type='text/javascript' src='" . $module_path . "player/swfobject.js'></script><script type='text/javascript' src='" . $module_path . "player/uppod_player.js'></script><script type='text/javascript' src='" . $module_path . "nc_audiocaptcha.js'></script>";
        $playlist = "{'playlist':[";
        $code = $nc_core->db->get_row("SELECT `Captcha_Code` FROM `Captchas` WHERE `Captcha_Hash` = '" . $captcha_hash . "'");
        $code_hash = $nc_core->db->get_results("SELECT * FROM `Captchas_Settings` WHERE `Key` != 'time'");
        foreach (str_split($code->Captcha_Code) as $letter) {
            $letter = strtolower($letter);
            foreach ($code_hash as $hash) {
                if ($hash->Key == $letter . '.mp3') {
                    $h = $hash->Value;
                    break;
                }
            }
            $playlist .= "{'file':'" . $nc_core->HTTP_FILES_PATH . "captcha/current_voice/" . $h . "'},";
        }
        $playlist .= "]}";
        $playlist = str_replace('},]}', '}]}', $playlist);
        $player_init = "<script type='text/javascript'>var nc_captcha{$id} = new nc_audiocaptcha(\"" . $module_path . "\", \"" . $playlist . "\");</script>";
        $cap = is_writable($nc_core->FILES_FOLDER) && is_dir($nc_core->MODULE_FOLDER . 'captcha/voice/' . $MODULE_VARS['captcha']['VOICE'] . '/') ? $player . $player_init . $audio_captcha : '';
    }
    $result = (!$_GET['nc_get_new_captcha'] && !$norefresh ? "<div id='nc_captcha_container" . $id . "' style='display:inline-block'>" : "") . "\n              <input type='hidden' name='" . $hidden_field_name . "' value='" . $captcha_hash . "' />\n              <img name='nc_captcha_img' src='" . $nc_core->SUB_FOLDER . $nc_core->HTTP_ROOT_PATH . "modules/captcha/img.php?code=" . $captcha_hash . "'" . ($attributes ? " " . $attributes : "") . " />\n              " . ($MODULE_VARS['captcha']['AUDIOCAPTCHA_ENABLED'] ? $cap : '') . (!$_GET['nc_get_new_captcha'] && !$norefresh ? "</div>\n              <button id='nc_captcha_refresh_button" . $id . "'>" . $btn . "</button>\n              " . nc_ajax_captcha_js('nc_captcha_container' . $id, 'nc_captcha_refresh_button' . $id, 'nc_captcha' . $id) : "");
    $count++;
    return $result;
}