diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php index f40fec8..18a1e6a 100644 --- a/app/Controllers/AdminController.php +++ b/app/Controllers/AdminController.php @@ -87,7 +87,7 @@ class AdminController extends Controller { $version = $_POST['version']; $image_url = $_POST['image_url']; $download_url = $_POST['download_url']; - $category_id = $_POST['category_id'] ?? null; + $category_id = !empty($_POST['category_id']) ? $_POST['category_id'] : null; $status = $_POST['status'] ?? 'published'; $is_vip = isset($_POST['is_vip']) ? 1 : 0; @@ -100,6 +100,66 @@ class AdminController extends Controller { $this->redirect('/admin/apks'); } + public function massUploadForm() { + $this->checkAuth(); + $db = db_pdo(); + $categories = $db->query("SELECT * FROM categories")->fetchAll(); + $this->view('admin/apks/mass_upload', ['categories' => $categories]); + } + + public function massUpload() { + $this->checkAuth(); + $titles = $_POST['titles'] ?? []; + $versions = $_POST['versions'] ?? []; + $download_urls = $_POST['download_urls'] ?? []; + $category_id = !empty($_POST['category_id']) ? $_POST['category_id'] : null; + $status = $_POST['status'] ?? 'published'; + + $db = db_pdo(); + $stmt = $db->prepare("INSERT INTO apks (title, slug, description, version, icon_path, download_url, category_id, status, is_vip, display_order) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0, 0)"); + + foreach ($titles as $index => $title) { + if (empty($title)) continue; + $slug = $this->slugify($title); + $version = $versions[$index] ?? ''; + $download_url = $download_urls[$index] ?? ''; + $description = $title; // Default description to title for mass upload + + $icon_path = $this->handleMassUploadFile('icon_files', $index, true); + + $stmt->execute([$title, $slug, $description, $version, $icon_path, $download_url, $category_id, $status]); + } + + $this->redirect('/admin/apks'); + } + + private function handleMassUploadFile($field, $index, $compress = false) { + if (!isset($_FILES[$field]['name'][$index]) || $_FILES[$field]['error'][$index] !== UPLOAD_ERR_OK) { + return null; + } + + $uploadDir = 'assets/uploads/icons/'; + if (!is_dir($uploadDir)) { + mkdir($uploadDir, 0775, true); + } + + $ext = pathinfo($_FILES[$field]['name'][$index], PATHINFO_EXTENSION); + $fileName = uniqid() . '.' . $ext; + $targetPath = $uploadDir . $fileName; + + if ($compress) { + if (compress_image($_FILES[$field]['tmp_name'][$index], $targetPath, 75)) { + return $targetPath; + } + } else { + if (move_uploaded_file($_FILES[$field]['tmp_name'][$index], $targetPath)) { + return $targetPath; + } + } + + return null; + } + public function editApkForm($params) { $this->checkAuth(); $apkService = new ApkService(); @@ -116,7 +176,7 @@ class AdminController extends Controller { $version = $_POST['version']; $image_url = $_POST['image_url']; $download_url = $_POST['download_url']; - $category_id = $_POST['category_id'] ?? null; + $category_id = !empty($_POST['category_id']) ? $_POST['category_id'] : null; $status = $_POST['status']; $is_vip = isset($_POST['is_vip']) ? 1 : 0; @@ -284,4 +344,4 @@ class AdminController extends Controller { $text = strtolower($text); return empty($text) ? 'n-a' : $text; } -} \ No newline at end of file +} diff --git a/assets/uploads/icons/699e4457a8386.jpg b/assets/uploads/icons/699e4457a8386.jpg new file mode 100644 index 0000000..d4e527b Binary files /dev/null and b/assets/uploads/icons/699e4457a8386.jpg differ diff --git a/assets/uploads/icons/699e46a5c9940.jpg b/assets/uploads/icons/699e46a5c9940.jpg new file mode 100644 index 0000000..cbf5c96 Binary files /dev/null and b/assets/uploads/icons/699e46a5c9940.jpg differ diff --git a/assets/uploads/icons/699e46a5cb3a2.jpg b/assets/uploads/icons/699e46a5cb3a2.jpg new file mode 100644 index 0000000..cbf5c96 Binary files /dev/null and b/assets/uploads/icons/699e46a5cb3a2.jpg differ diff --git a/index.php b/index.php index 9ee36e7..6b92362 100644 --- a/index.php +++ b/index.php @@ -74,6 +74,8 @@ $router->post('/admin/settings', 'AdminController@saveSettings'); // Admin APKs $router->get('/admin/apks', 'AdminController@apks'); +$router->get('/admin/apks/mass-upload', 'AdminController@massUploadForm'); +$router->post('/admin/apks/mass-upload', 'AdminController@massUpload'); $router->get('/admin/apks/add', 'AdminController@addApkForm'); $router->post('/admin/apks/add', 'AdminController@addApk'); $router->get('/admin/apks/edit/:id', 'AdminController@editApkForm'); diff --git a/views/admin/apks/mass_upload.php b/views/admin/apks/mass_upload.php new file mode 100644 index 0000000..86a507d --- /dev/null +++ b/views/admin/apks/mass_upload.php @@ -0,0 +1,96 @@ + + +
+
+
+
+
+
Mass Upload APKs
+ +
+
+
+
+
+ + +
+
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + + +
TitleVersionIcon FileDownload URL
+
+ +
+ Cancel + +
+
+
+
+
+
+
+ + + + diff --git a/views/admin/header.php b/views/admin/header.php index 0c901ab..3ee897d 100644 --- a/views/admin/header.php +++ b/views/admin/header.php @@ -59,6 +59,9 @@ +