66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
<?php
|
|
|
|
use App\Services\LanguageService;
|
|
|
|
function db_pdo() {
|
|
return db();
|
|
}
|
|
|
|
function view($view, $data = []) {
|
|
extract($data);
|
|
$viewPath = __DIR__ . '/../../views/' . $view . '.php';
|
|
if (file_exists($viewPath)) {
|
|
require $viewPath;
|
|
} else {
|
|
echo "View $view not found";
|
|
}
|
|
}
|
|
|
|
function redirect($path) {
|
|
header("Location: " . url($path));
|
|
exit;
|
|
}
|
|
|
|
function url($path = '') {
|
|
$base = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'];
|
|
|
|
// Detect subdirectory
|
|
$scriptName = $_SERVER['SCRIPT_NAME'];
|
|
$basePath = str_replace('/index.php', '', $scriptName);
|
|
|
|
$path = ltrim($path, '/');
|
|
return $base . $basePath . '/' . $path;
|
|
}
|
|
|
|
function asset($path) {
|
|
return url('assets/' . ltrim($path, '/'));
|
|
}
|
|
|
|
function __($key, $default = null) {
|
|
return LanguageService::translate($key, $default);
|
|
}
|
|
|
|
function get_setting($key, $default = '') {
|
|
$db = db();
|
|
$stmt = $db->prepare("SELECT setting_value FROM settings WHERE setting_key = ?");
|
|
$stmt->execute([$key]);
|
|
$result = $stmt->fetch();
|
|
return $result ? $result['setting_value'] : $default;
|
|
}
|
|
|
|
function compress_image($source, $destination, $quality) {
|
|
$info = getimagesize($source);
|
|
if ($info['mime'] == 'image/jpeg') {
|
|
$image = imagecreatefromjpeg($source);
|
|
} elseif ($info['mime'] == 'image/gif') {
|
|
$image = imagecreatefromgif($source);
|
|
} elseif ($info['mime'] == 'image/png') {
|
|
$image = imagecreatefrompng($source);
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
imagejpeg($image, $destination, $quality);
|
|
return $destination;
|
|
}
|