';
exit;
}
// Domain'i normalize et
$domain = normalize_domain($domain);
// Domain formatını kontrol et (daha esnek regex)
if (!preg_match('/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$/i', $domain)) {
api_log("Error: Invalid domain structure: " . $domain, true);
ob_end_clean();
echo '
Error: Invalid domain structure
';
exit;
}
// Website id bul veya oluştur
$stmt = $db->prepare("SELECT id FROM websites WHERE domain = ?");
$stmt->execute([$domain]);
$website = $stmt->fetch();
if (!$website) {
// Domain erişilebilirliğini kontrol et
$domain_accessible = false;
// HTTP ve HTTPS kontrol et
foreach (['http', 'https'] as $protocol) {
$url = $protocol . '://' . $domain;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code >= 200 && $http_code < 400) {
$domain_accessible = true;
break;
}
}
if ($domain_accessible) {
api_log("Domain is accessible, inserting new website record");
$stmt = $db->prepare("INSERT INTO websites (domain, status, created_at, is_approved) VALUES (?, 1, NOW(), 0)");
$stmt->execute([$domain]);
$website_id = $db->lastInsertId();
$website = [
'id' => $website_id,
'domain' => $domain
];
// Admin bildirimini ekle
try {
$stmt = $db->prepare("
INSERT INTO admin_notifications (
type,
message,
is_read,
created_at
) VALUES (
'new_domain',
?,
0,
NOW()
)
");
$notification_message = "Yeni domain eklendi: " . $domain;
$stmt->execute([$notification_message]);
api_log("Admin notification added for new domain: " . $domain);
} catch (Exception $e) {
api_log("Error adding admin notification: " . $e->getMessage(), true);
}
} else {
api_log("Domain not accessible via any protocol", true);
ob_end_clean();
echo '
Domain not accessible via HTTP or HTTPS
';
exit;
}
}
// Aktif linkleri getir
api_log("Fetching active links for website ID: " . $website['id']);
$sql = "SELECT l.url, l.anchor_text
FROM links l
JOIN orders o ON l.order_id = o.id
WHERE o.website_id = ? AND (o.status = 'completed' OR o.status = 'active') AND l.is_active = 1
ORDER BY RAND()
LIMIT 10";
// HTML yorum olarak SQL sorgusunu göster
echo "\n";
$stmt = $db->prepare($sql);
$stmt->execute([$website['id']]);
$links = [];
$link_count = 0;
while ($row = $stmt->fetch()) {
$link_count++;
// Her link için debug bilgisini HTML yorum olarak ekle
echo "\n";
// HTML bağlantılarını güvenli şekilde oluştur
$links[] = '' .
htmlspecialchars($row['anchor_text'], ENT_QUOTES, 'UTF-8') . '';
}
echo "\n";
if (empty($links)) {
api_log("No active links found for domain: " . $domain . " (Website ID: " . $website['id'] . ")", true);
ob_end_clean();
echo '
No active links found for: ' . htmlspecialchars($domain) . '