50 lines
1.2 KiB
PHP
50 lines
1.2 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: $path");
|
|
exit;
|
|
}
|
|
|
|
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;
|
|
} |