Add PHP Media API scaffold and Docker configs

Initial project scaffold for a PHP Media API including routing, controllers, models and services under api/ (Router, Media/Cast/Image/Settings controllers, models, database/bootstrap files and automatic docs service). Adds Docker support (Dockerfile, docker-compose.yml, DOCKER_README.md, php-custom.ini), .htaccess for pretty URLs, API documentation and example payloads (API_EXAMPLES.md, api/README.md, api_examples/*.json), image handling service and logging, plus a comprehensive .gitignore. This commit provides a runnable development environment and example requests to get the API up and tested quickly.
This commit is contained in:
Lars Behrends
2026-04-12 00:46:30 +02:00
commit 66f69bc90d
54 changed files with 6035 additions and 0 deletions

82
api/models/Settings.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
require_once __DIR__ . '/BaseModel.php';
class Settings extends BaseModel {
protected $table = 'settings';
public function __construct($pdo) {
parent::__construct($pdo);
}
public function getSettings() {
$stmt = $this->pdo->prepare("SELECT * FROM {$this->table} WHERE id = 1");
$stmt->execute();
$settings = $stmt->fetch();
if ($settings) {
// Decode enabled_categories from JSON
$settings['enabled_categories'] = $settings['enabled_categories'] ? json_decode($settings['enabled_categories'], true) : [];
// Convert boolean fields from tinyint to boolean
$settings['show_adult_content'] = (bool)$settings['show_adult_content'];
$settings['auto_play_trailers'] = (bool)$settings['auto_play_trailers'];
}
return $settings;
}
public function updateSettings($data) {
$updateData = [];
if (isset($data['enabled_categories']) && is_array($data['enabled_categories'])) {
$updateData['enabled_categories'] = json_encode($data['enabled_categories']);
}
if (isset($data['items_per_page'])) {
$updateData['items_per_page'] = (int)$data['items_per_page'];
}
if (isset($data['default_view'])) {
$updateData['default_view'] = $data['default_view'];
}
if (isset($data['show_adult_content'])) {
$updateData['show_adult_content'] = $data['show_adult_content'] ? 1 : 0;
}
if (isset($data['auto_play_trailers'])) {
$updateData['auto_play_trailers'] = $data['auto_play_trailers'] ? 1 : 0;
}
if (isset($data['language'])) {
$updateData['language'] = $data['language'];
}
if (isset($data['theme'])) {
$updateData['theme'] = $data['theme'];
}
// Check if settings row exists
$existing = $this->findById(1);
if ($existing) {
$this->update(1, $updateData);
return $this->getSettings();
} else {
// Create default settings if not exists
$defaultData = [
'enabled_categories' => json_encode(['Anime', 'Movies', 'TV Series', 'Music', 'Books', 'Consoles', 'Games', 'Adult']),
'items_per_page' => 20,
'default_view' => 'grid',
'show_adult_content' => 0,
'auto_play_trailers' => 0,
'language' => 'en',
'theme' => 'system',
'theme' => 'system'
];
$mergedData = array_merge($defaultData, $updateData);
$this->create($mergedData);
return $this->getSettings();
}
}
}