add_action('wp_ajax_imbo_check', 'imbo_proxy_handler');
add_action('wp_ajax_nopriv_imbo_check', 'imbo_proxy_handler');

function imbo_proxy_handler() {
    // Rate limit: 5 per day per IP
    $ip    = $_SERVER['REMOTE_ADDR'];
    $key   = 'imbo_rate_' . md5($ip);
    $limit = 5;
    $count = (int) get_transient($key);

    if ($count >= $limit) {
        wp_send_json_error(['message' => 'Daily limit reached.'], 429);
        return;
    }

    // Get and sanitize the prompt
    $body   = json_decode(file_get_contents('php://input'), true);
    $prompt = isset($body['prompt']) ? sanitize_textarea_field($body['prompt']) : '';

    if (empty($prompt)) {
        wp_send_json_error(['message' => 'No prompt provided.'], 400);
        return;
    }

    $keys   = json_decode(IMBO_GEMINI_KEYS, true);
    $models = json_decode(IMBO_GEMINI_MODELS, true);

    $result = null;

    foreach ($models as $model) {
        foreach ($keys as $api_key) {
            $url      = "https://generativelanguage.googleapis.com/v1beta/models/{$model}:generateContent?key={$api_key}";
            $payload  = json_encode(['contents' => [['parts' => [['text' => $prompt]]]]]);

            $response = wp_remote_post($url, [
                'headers' => ['Content-Type' => 'application/json'],
                'body'    => $payload,
                'timeout' => 20,
            ]);

            if (is_wp_error($response)) continue;

            $code = wp_remote_retrieve_response_code($response);
            if ($code !== 200) continue;

            $data = json_decode(wp_remote_retrieve_body($response), true);
            $text = $data['candidates'][0]['content']['parts'][0]['text'] ?? '';

            if (!empty($text)) {
                $result = $text;
                break 2; // exit both loops
            }
        }
    }

    if ($result) {
        // Increment rate limit counter (resets after 24 hours)
        set_transient($key, $count + 1, DAY_IN_SECONDS);
        wp_send_json_success(['text' => $result]);
    } else {
        wp_send_json_error(['message' => 'All API keys failed.'], 503);
    }
}<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//blessedcutebabies.com/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://blessedcutebabies.com/post-sitemap.xml</loc>
		<lastmod>2026-03-30T15:40:13+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://blessedcutebabies.com/page-sitemap.xml</loc>
		<lastmod>2026-06-22T11:52:37+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://blessedcutebabies.com/category-sitemap.xml</loc>
		<lastmod>2026-03-30T15:40:13+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->