예제 #1
0
        } else {
            $next_started_time = TIME - SE_MAX_PROCESSING_TIME + $q['error_count'] * 60;
            db_query("UPDATE ?:se_queue SET status = 'processing', error_count = error_count + 1, started = ?s WHERE queue_id = ?i", $next_started_time, $q['queue_id']);
            break;
            //try later
        }
        fn_echo('.');
    }
    die('OK');
}
if ($mode == 'info') {
    fn_se_check_import_is_done();
    $company_id = fn_se_get_company_id();
    $engines_data = fn_se_get_engines_data($company_id, NULL, true);
    $options = array();
    if (empty($_REQUEST['parent_private_key']) || fn_se_get_parent_private_key($company_id, DEFAULT_LANGUAGE) !== $_REQUEST['parent_private_key']) {
        foreach ($engines_data as $e) {
            $options[$e['company_id']][$e['lang_code']] = $e['api_key'];
        }
    } else {
        if (isset($_REQUEST['product_id'])) {
            $lang_code = DEFAULT_LANGUAGE;
            if (isset($_REQUEST['lang_code'])) {
                $lang_code = $_REQUEST['lang_code'];
            } elseif (isset($_REQUEST['sl'])) {
                $lang_code = $_REQUEST['sl'];
            }
            $options = fn_se_get_products_xml($_REQUEST['product_id'], $company_id, $lang_code, false);
        } elseif (isset($_REQUEST['resync']) && $_REQUEST['resync'] === 'Y') {
            fn_se_signup(NULL, NULL, true);
            fn_se_queue_import(NULL, NULL, true);
예제 #2
0
function fn_se_signup($_company_id = NULL, $_lang_code = NULL, $show_notification = true)
{
    @ignore_user_abort(1);
    @set_time_limit(3600);
    $connected = false;
    $is_showed = false;
    if ((!empty($_company_id) || !empty($_lang_code)) && fn_se_is_registered() == false) {
        return false;
    }
    $email = Registry::ifGet('user_info.email', db_get_field("SELECT email FROM ?:users WHERE user_id = 1"));
    $engines_data = fn_se_get_engines_data($_company_id, $_lang_code);
    foreach ($engines_data as $engine_data) {
        $lang_code = $engine_data['lang_code'];
        $company_id = $engine_data['company_id'];
        $private_key = $engine_data['private_key'];
        $parent_private_key = fn_se_get_parent_private_key($company_id, $lang_code);
        if (!empty($private_key)) {
            continue;
        }
        if ($show_notification == true && empty($is_showed)) {
            fn_se_echo_connect_progress('Connecting to Searchanise..');
            $is_showed = true;
        }
        $response = Http::post(SE_SERVICE_URL . '/api/signup/json', array('url' => $engine_data['url'], 'email' => $email, 'version' => SE_VERSION, 'language' => $lang_code, 'parent_private_key' => $parent_private_key, 'platform' => SE_PLATFORM));
        if ($show_notification == true) {
            fn_se_echo_connect_progress('.');
        }
        if (!empty($response)) {
            $response = fn_se_parse_response($response, true);
            if (!empty($response['keys']['api']) && !empty($response['keys']['private'])) {
                $api_key = (string) $response['keys']['api'];
                $private_key = (string) $response['keys']['private'];
                if (empty($api_key) || empty($private_key)) {
                    return false;
                }
                if (empty($parent_private_key)) {
                    fn_se_set_setting('parent_private_key', $company_id, $lang_code, $private_key);
                }
                fn_se_set_setting('api_key', $company_id, $lang_code, $api_key);
                fn_se_set_setting('private_key', $company_id, $lang_code, $private_key);
                $connected = true;
            } else {
                if (!fn_allowed_for('ULTIMATE')) {
                    if ($show_notification == true) {
                        fn_se_echo_connect_progress(' Error<br />');
                    }
                    return false;
                }
            }
        }
        fn_se_set_import_status('none', $company_id, $lang_code);
        fn_se_set_setting('use_navigation', $company_id, DEFAULT_LANGUAGE, 'N');
    }
    if ($connected == true && $show_notification == true) {
        fn_se_echo_connect_progress(' Done<br />');
        fn_set_notification('N', __('notice'), __('text_se_just_connected'));
    }
    fn_set_hook('searchanise_signup_post', $connected);
    return $connected;
}