Files
Hamza-AyedandClaude Opus 5 92dc6b3641 chore: استيراد أولي من سيرو (ecfe7568) — بلا أي تعديل
نسخة كاملة من مستودع سيرو عند ecfe7568 لتكون أساس تطبيق «انطلق».
نُسخ المتعقَّب في git فقط (12,509 ملفاً / 302 م.ب) بـ git archive، لا
`cp -r` — فاستُثنيت تلقائياً مخلفات البناء (build · node_modules ·
.dart_tool · .gradle · Pods ≈ 10.7 غ.ب) وكل ما يستثنيه .gitignore.

هذا الكوميت **بلا أي تعديل عمداً** حتى يكون كل ما يليه فرقاً مقروءاً
مقابل سيرو الأصلي. سيرو نفسه لم يُمسّ.

⚠️ لا يبني بعد: `.env` و`lib/env/env.g.dart` غير متعقَّبين في سيرو (وهذا
صحيح — أسرار لكل مستأجر). كل تطبيق فلاتر هنا يحتاج .env خاصاً بانطلق ثم
توليد env.g.dart عبر build_runner. لا تُنسخ أسرار سيرو.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:10:29 +03:00

68 lines
2.4 KiB
PHP

<?php
// ============================================================
// account_manager.php
// Handles rotation and selection of social media accounts
// ============================================================
require_once __DIR__ . '/../core/bootstrap.php';
class AccountManager {
private $con;
public function __construct() {
$this->con = Database::get('main');
}
/**
* Get an available account for a specific platform that hasn't been used too recently.
*
* @param string $platform 'facebook' or 'instagram'
* @param int $cooldownMinutes Minimum minutes since last active
* @return array|null Account details or null if none available
*/
public function getAvailableAccount($platform, $cooldownMinutes = 30) {
// Select an active account that was last active more than X minutes ago,
// or has never been active (last_active is NULL).
// Order by last_active ascending to rotate through them (least recently used first).
$stmt = $this->con->prepare("
SELECT id, username, total_posts, total_comments, proxy_ip, proxy_port, proxy_username, proxy_password
FROM social_accounts
WHERE platform = ?
AND status = 'active'
AND (last_active IS NULL OR last_active <= DATE_SUB(NOW(), INTERVAL ? MINUTE))
ORDER BY last_active ASC, id ASC
LIMIT 1
");
$stmt->execute([$platform, $cooldownMinutes]);
return $stmt->fetch(PDO::FETCH_ASSOC);
}
/**
* Update the last active timestamp for an account
*/
public function markAccountActive($accountId) {
$stmt = $this->con->prepare("UPDATE social_accounts SET last_active = NOW() WHERE id = ?");
$stmt->execute([$accountId]);
}
/**
* Increment comment count
*/
public function incrementCommentCount($accountId) {
$stmt = $this->con->prepare("UPDATE social_accounts SET total_comments = total_comments + 1, last_active = NOW() WHERE id = ?");
$stmt->execute([$accountId]);
}
/**
* Mark an account as restricted or banned
*/
public function markAccountStatus($accountId, $status) {
if (!in_array($status, ['active', 'restricted', 'banned'])) return false;
$stmt = $this->con->prepare("UPDATE social_accounts SET status = ? WHERE id = ?");
return $stmt->execute([$status, $accountId]);
}
}