101 lines
3.0 KiB
PHP
101 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Core\Controller;
|
|
use App\Services\ApkService;
|
|
|
|
class HomeController extends Controller {
|
|
|
|
public function index() {
|
|
$category = $_GET['category'] ?? null;
|
|
$search = $_GET['search'] ?? null;
|
|
|
|
$apkService = new ApkService();
|
|
$apks = $apkService->getAllApks($category, $search);
|
|
|
|
$this->view('home', [
|
|
'apks' => $apks,
|
|
'title' => get_setting('site_name', 'ApkNusa') . __('home_title_suffix')
|
|
]);
|
|
}
|
|
|
|
public function apkDetail($params) {
|
|
$slug = $params['slug'];
|
|
$db = db_pdo();
|
|
$stmt = $db->prepare("SELECT * FROM apks WHERE slug = ?");
|
|
$stmt->execute([$slug]);
|
|
$apk = $stmt->fetch();
|
|
|
|
if (!$apk) {
|
|
$this->redirect('/');
|
|
}
|
|
|
|
// 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,
|
|
'title' => $apk['title'] . ' - ' . get_setting('site_name', 'ApkNusa')
|
|
]);
|
|
}
|
|
|
|
public function download($params) {
|
|
$slug = $params['slug'];
|
|
$db = db_pdo();
|
|
$stmt = $db->prepare("SELECT * FROM apks WHERE slug = ?");
|
|
$stmt->execute([$slug]);
|
|
$apk = $stmt->fetch();
|
|
|
|
if (!$apk) {
|
|
$this->redirect('/');
|
|
}
|
|
|
|
// Increment download count
|
|
$stmt = $db->prepare("UPDATE apks SET total_downloads = total_downloads + 1 WHERE id = ?");
|
|
$stmt->execute([$apk['id']]);
|
|
|
|
// Referral logic
|
|
$ref_key = 'ref_download_' . $apk['id'];
|
|
if (isset($_SESSION['ref_download_' . $apk['id']])) {
|
|
$ref_code = $_SESSION['ref_download_' . $apk['id']];
|
|
|
|
// Find the user who owns this referral code
|
|
$stmt = $db->prepare("SELECT * FROM users WHERE referral_code = ?");
|
|
$stmt->execute([$ref_code]);
|
|
$referrer = $stmt->fetch();
|
|
|
|
if ($referrer) {
|
|
// Award points/money to referrer
|
|
// For example, 100 rupiah per download
|
|
$stmt = $db->prepare("UPDATE users SET balance = balance + 100 WHERE id = ?");
|
|
$stmt->execute([$referrer['id']]);
|
|
}
|
|
|
|
unset($_SESSION[$ref_key]);
|
|
}
|
|
|
|
header('Location: ' . $apk['download_url']);
|
|
exit;
|
|
}
|
|
|
|
public function helpCenter() {
|
|
$this->view('help_center', [
|
|
'title' => __('help_center') . ' - ' . get_setting('site_name', 'ApkNusa')
|
|
]);
|
|
}
|
|
|
|
public function privacyPolicy() {
|
|
$this->view('privacy_policy', [
|
|
'title' => __('privacy_policy') . ' - ' . get_setting('site_name', 'ApkNusa')
|
|
]);
|
|
}
|
|
|
|
public function termsOfService() {
|
|
$this->view('terms_of_service', [
|
|
'title' => __('terms_of_service') . ' - ' . get_setting('site_name', 'ApkNusa')
|
|
]);
|
|
}
|
|
} |