diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php
index a9aecd0..10f347c 100644
--- a/app/Controllers/AdminController.php
+++ b/app/Controllers/AdminController.php
@@ -90,7 +90,7 @@ class AdminController extends Controller {
$status = $_POST['status'] ?? 'published';
$is_vip = isset($_POST['is_vip']) ? 1 : 0;
- $icon_path = $this->handleUpload('icon_file');
+ $icon_path = $this->handleUpload('icon_file', true);
$db = db_pdo();
$stmt = $db->prepare("INSERT INTO apks (title, slug, description, version, image_url, icon_path, download_url, category_id, status, is_vip, display_order) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)");
@@ -121,7 +121,7 @@ class AdminController extends Controller {
$db = db_pdo();
$apk = $db->query("SELECT * FROM apks WHERE id = " . $params['id'])->fetch();
- $icon_path = $this->handleUpload('icon_file') ?: $apk['icon_path'];
+ $icon_path = $this->handleUpload('icon_file', true) ?: $apk['icon_path'];
$stmt = $db->prepare("UPDATE apks SET title = ?, description = ?, version = ?, image_url = ?, icon_path = ?, download_url = ?, category_id = ?, status = ?, is_vip = ? WHERE id = ?");
$stmt->execute([$title, $description, $version, $image_url, $icon_path, $download_url, $category_id, $status, $is_vip, $params['id']]);
@@ -141,7 +141,7 @@ class AdminController extends Controller {
echo json_encode(['success' => true]);
}
- private function handleUpload($field) {
+ private function handleUpload($field, $compress = false) {
if (!isset($_FILES[$field]) || $_FILES[$field]['error'] !== UPLOAD_ERR_OK) {
return null;
}
@@ -155,13 +155,61 @@ class AdminController extends Controller {
$fileName = uniqid() . '.' . $ext;
$targetPath = $uploadDir . $fileName;
- if (move_uploaded_file($_FILES[$field]['tmp_name'], $targetPath)) {
- return $targetPath;
+ if ($compress) {
+ if (compress_image($_FILES[$field]['tmp_name'], $targetPath, 75)) {
+ return $targetPath;
+ }
+ } else {
+ if (move_uploaded_file($_FILES[$field]['tmp_name'], $targetPath)) {
+ return $targetPath;
+ }
}
return null;
}
+ // Settings Management
+ public function settingsForm() {
+ $this->checkAuth();
+ $settings = [
+ 'site_name' => get_setting('site_name'),
+ 'site_icon' => get_setting('site_icon'),
+ 'site_favicon' => get_setting('site_favicon'),
+ 'meta_description' => get_setting('meta_description'),
+ 'meta_keywords' => get_setting('meta_keywords'),
+ 'head_js' => get_setting('head_js'),
+ 'body_js' => get_setting('body_js'),
+ ];
+ $this->view('admin/settings', ['settings' => $settings]);
+ }
+
+ public function saveSettings() {
+ $this->checkAuth();
+ $db = db_pdo();
+
+ $fields = ['site_name', 'meta_description', 'meta_keywords', 'head_js', 'body_js'];
+ foreach ($fields as $field) {
+ if (isset($_POST[$field])) {
+ $stmt = $db->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = ?");
+ $stmt->execute([$_POST[$field], $field]);
+ }
+ }
+
+ $site_icon = $this->handleUpload('site_icon_file');
+ if ($site_icon) {
+ $stmt = $db->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'site_icon'");
+ $stmt->execute([$site_icon]);
+ }
+
+ $site_favicon = $this->handleUpload('site_favicon_file');
+ if ($site_favicon) {
+ $stmt = $db->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'site_favicon'");
+ $stmt->execute([$site_favicon]);
+ }
+
+ $this->redirect('/admin/settings');
+ }
+
// Category Management
public function categories() {
$this->checkAuth();
@@ -207,7 +255,6 @@ class AdminController extends Controller {
public function rejectWithdrawal($params) {
$this->checkAuth();
$db = db_pdo();
- // Refund balance if rejected? The user didn't specify, but let's do it for fairness
$wd = $db->query("SELECT * FROM withdrawals WHERE id = " . $params['id'])->fetch();
if ($wd && $wd['status'] === 'pending') {
$stmt = $db->prepare("UPDATE users SET balance = balance + ? WHERE id = ?");
diff --git a/app/Controllers/AuthController.php b/app/Controllers/AuthController.php
index c20a9b1..248e4df 100644
--- a/app/Controllers/AuthController.php
+++ b/app/Controllers/AuthController.php
@@ -17,7 +17,8 @@ class AuthController extends Controller {
if (isset($_SESSION['user_id'])) {
$this->redirect('/profile');
}
- $ref = $_GET['ref'] ?? '';
+ // Check GET first, then Session
+ $ref = $_GET['ref'] ?? ($_SESSION['global_ref'] ?? '');
$this->view('auth/register', ['ref' => $ref]);
}
diff --git a/app/Controllers/HomeController.php b/app/Controllers/HomeController.php
index 78eb02b..e3b4db0 100644
--- a/app/Controllers/HomeController.php
+++ b/app/Controllers/HomeController.php
@@ -16,6 +16,11 @@ class HomeController extends Controller {
$db = db_pdo();
$category = $_GET['category'] ?? null;
+ // Store global referral code if present
+ if (isset($_GET['ref'])) {
+ $_SESSION['global_ref'] = $_GET['ref'];
+ }
+
$sql = "SELECT * FROM apks WHERE status = 'published'";
$params = [];
@@ -32,7 +37,7 @@ class HomeController extends Controller {
return $this->view('home', [
'apks' => $apks,
- 'title' => 'ApkNusa - Professional APK Download Portal'
+ 'title' => get_setting('site_name', 'ApkNusa') . ' - Professional APK Download Portal'
]);
}
@@ -47,12 +52,17 @@ class HomeController extends Controller {
$this->redirect('/');
}
- // Store referral code if present
+ // Store referral code if present specifically for this APK
if (isset($_GET['ref'])) {
$_SESSION['ref_download_' . $apk['id']] = $_GET['ref'];
}
- $this->view('apk_detail', ['apk' => $apk]);
+ $this->view('apk_detail', [
+ 'apk' => $apk,
+ 'title' => 'Download ' . $apk['title'] . ' ' . $apk['version'] . ' - ' . get_setting('site_name', 'ApkNusa'),
+ 'meta_description' => 'Download ' . $apk['title'] . ' ' . $apk['version'] . ' APK for free. ' . substr(strip_tags($apk['description']), 0, 150) . '...',
+ 'meta_keywords' => $apk['title'] . ', ' . $apk['title'] . ' apk, download ' . $apk['title']
+ ]);
}
public function download($params) {
@@ -67,7 +77,9 @@ class HomeController extends Controller {
}
// Check for referral earnings
- $ref_code = $_SESSION['ref_download_' . $apk['id']] ?? null;
+ // Try specific APK referral first, then global referral
+ $ref_code = $_SESSION['ref_download_' . $apk['id']] ?? ($_SESSION['global_ref'] ?? null);
+
if ($ref_code) {
$stmt = $db->prepare("SELECT id FROM users WHERE referral_code = ?");
$stmt->execute([$ref_code]);
@@ -91,7 +103,8 @@ class HomeController extends Controller {
$stmt->execute([$referrer_id, $apk['id'], $ip]);
}
}
- // Clear session after processing
+ // Clear session specific to this APK, but maybe keep global_ref?
+ // The user might download other APKs too.
unset($_SESSION['ref_download_' . $apk['id']]);
}
@@ -102,4 +115,4 @@ class HomeController extends Controller {
// Redirect to actual file
$this->redirect($apk['download_url']);
}
-}
\ No newline at end of file
+}
diff --git a/app/Controllers/SitemapController.php b/app/Controllers/SitemapController.php
new file mode 100644
index 0000000..4c8f913
--- /dev/null
+++ b/app/Controllers/SitemapController.php
@@ -0,0 +1,52 @@
+getAllApks();
+
+ $db = db_pdo();
+ $categories = $db->query("SELECT * FROM categories")->fetchAll();
+
+ header("Content-Type: application/xml; charset=utf-8");
+
+ $baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
+
+ echo '';
+ echo '
This wizard will help you install the application on your server.
+ + + + +You can now log in to your admin panel.
+install.php file from your server.
+ | Title | -Version | -Downloads | -Status | +Title | +Version | +Downloads | +Status |
|---|---|---|---|---|---|---|---|
| - - + + | -v | -+ | v | +- + | @@ -117,24 +120,27 @@