mirror of
https://github.com/danielbrendel/hortusfox-web.git
synced 2026-01-03 03:10:16 -06:00
119 lines
2.7 KiB
PHP
119 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Class AppModel
|
|
*
|
|
* Management of app environment settings
|
|
*/
|
|
class AppModel extends \Asatru\Database\Model {
|
|
/**
|
|
* @param $name
|
|
* @param $fallback
|
|
* @param $profile
|
|
* @return mixed
|
|
* @throws \Exception
|
|
*/
|
|
public static function query($name, $fallback = null, $profile = 1)
|
|
{
|
|
try {
|
|
$item = static::raw('SELECT * FROM `@THIS` WHERE id = ?', [$profile])->first();
|
|
if (!$item) {
|
|
return $fallback;
|
|
}
|
|
|
|
return $item->get($name);
|
|
} catch (\Exception $e) {
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $name
|
|
* @param $value
|
|
* @return void
|
|
* @throws \Exception
|
|
*/
|
|
public static function updateSingle($name, $value)
|
|
{
|
|
try {
|
|
static::raw('UPDATE `@THIS` SET ' . $name . ' = ?', [$value]);
|
|
} catch (\Exception $e) {
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $set
|
|
* @return void
|
|
* @throws \Exception
|
|
*/
|
|
public static function updateSet($set)
|
|
{
|
|
try {
|
|
foreach ($set as $key => $value) {
|
|
static::raw('UPDATE `@THIS` SET ' . $key . ' = ?', [$value]);
|
|
}
|
|
} catch (\Exception $e) {
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
* @throws \Exception
|
|
*/
|
|
public static function generateCronjobToken()
|
|
{
|
|
try {
|
|
$token = md5(random_bytes(55) . date('Y-m-d H:i:s'));
|
|
|
|
static::updateSingle('cronjob_pw', $token);
|
|
|
|
return $token;
|
|
} catch (\Exception $e) {
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $workspace
|
|
* @return void
|
|
* @throws \Exception
|
|
*/
|
|
public static function writeManifest($workspace)
|
|
{
|
|
try {
|
|
$manifest = [
|
|
'name' => $workspace,
|
|
'short_name' => $workspace,
|
|
'icons' => [
|
|
[
|
|
'src' => '/logo.png',
|
|
'sizes' => '256x256',
|
|
'type' => 'image/png'
|
|
]
|
|
],
|
|
'start_url' => '/',
|
|
'display' => 'standalone',
|
|
'background_color' => '#323232',
|
|
'theme_color' => '#323232'
|
|
];
|
|
|
|
file_put_contents(public_path() . '/manifest.json', json_encode($manifest));
|
|
} catch (\Exception $e) {
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public static function getMailEncryptionTypes()
|
|
{
|
|
return [
|
|
'none' => 'N/A',
|
|
'tls' => 'STARTTLS',
|
|
'smtps' => 'SMTPS'
|
|
];
|
|
}
|
|
} |