v1.0 Initial commit of project
This commit is contained in:
117
pub/bin/php/Functions/globalFunctions.php
Normal file
117
pub/bin/php/Functions/globalFunctions.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
function setResponse($type, $text)
|
||||
{
|
||||
$value = json_encode([$type => $text]);
|
||||
$_SESSION['response'] = $value;
|
||||
header('location: ' . $_SERVER['HTTP_REFERER']);
|
||||
exit;
|
||||
}
|
||||
|
||||
function checkIfUser()
|
||||
{
|
||||
if ($_SESSION['user']['user_group_type'] == 'user') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function showTime($timestamp)
|
||||
{
|
||||
if (empty($timestamp)) {
|
||||
echo __('never');
|
||||
return;
|
||||
}
|
||||
|
||||
$dt = new DateTime("@$timestamp");
|
||||
$dt->setTimezone(new DateTimeZone($_SESSION['user']['user_timezone']));
|
||||
|
||||
echo $dt->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
|
||||
function human_filesize($bytes, $decimals = 2)
|
||||
{
|
||||
$sizes = ['B', 'K', 'M', 'G', 'T', 'P']; // Array instead of string
|
||||
$factor = floor((strlen($bytes) - 1) / 3);
|
||||
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $sizes[$factor];
|
||||
}
|
||||
|
||||
function retrieveAvailableLocales()
|
||||
{
|
||||
$availableLocales = array();
|
||||
$localeDir = $_SERVER['DOCUMENT_ROOT'] . "/bin/locales/";
|
||||
|
||||
$localesInDir = array_diff(scandir($localeDir), array('.', '..'));
|
||||
foreach ($localesInDir as $localeFile) {
|
||||
if (pathinfo($localeFile, PATHINFO_EXTENSION) === 'php') {
|
||||
$availableLocales[] = basename($localeFile, '.php'); // Strip .php extension
|
||||
}
|
||||
}
|
||||
|
||||
return $availableLocales;
|
||||
}
|
||||
|
||||
function getPreferredLocale()
|
||||
|
||||
{
|
||||
$availableLocales = retrieveAvailableLocales();
|
||||
$defaultLocale = 'en';
|
||||
|
||||
$selectedLocale = in_array($_SESSION['user']['user_pref_language'], $availableLocales)
|
||||
? $_SESSION['user']['user_pref_language']
|
||||
: $defaultLocale;
|
||||
return $selectedLocale;
|
||||
}
|
||||
|
||||
function __(string $key, array $replacements = [])
|
||||
{
|
||||
global $translations;
|
||||
|
||||
$translation = $translations[$key] ?? $key;
|
||||
|
||||
// Replace placeholders with dynamic values
|
||||
foreach ($replacements as $placeholder => $value) {
|
||||
$translation = str_replace(":{$placeholder}", $value, $translation);
|
||||
}
|
||||
|
||||
return $translation;
|
||||
}
|
||||
|
||||
function get_enabled_platforms($conn)
|
||||
{
|
||||
$platforms_enabled = [];
|
||||
$query = "SELECT * FROM vc_platforms WHERE platform_enabled = 1";
|
||||
|
||||
if ($stmt = $conn->prepare($query)) {
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$platforms_enabled[$row['platform_uuid']] = [
|
||||
'data' => $row,
|
||||
'default_template_uuid' => false
|
||||
];
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
return $platforms_enabled;
|
||||
}
|
||||
|
||||
function getEnabledModules()
|
||||
{
|
||||
$modules_enabled = [];
|
||||
$query = "SELECT * FROM system_modules";
|
||||
|
||||
if ($stmt = $GLOBALS['conn']->prepare($query)) {
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$modules_enabled[$row['module_slugify']] = $row['module_enabled'];
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
return $modules_enabled;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user