2016-09-05 15:28:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Helpers;
|
|
|
|
|
|
|
|
use App\Configuration;
|
|
|
|
|
|
|
|
class ConfigHelper
|
|
|
|
{
|
|
|
|
public function allowedDateFormats()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'Y-m-d - H:i',
|
|
|
|
'd/m/Y - H:i',
|
|
|
|
'm/d/Y - H:i',
|
|
|
|
'jS F Y - H:i',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-09-05 15:36:46 +01:00
|
|
|
public function allowedThemeNames()
|
|
|
|
{
|
|
|
|
$results = [];
|
|
|
|
|
|
|
|
$directoryIterator = new \FilesystemIterator(dirname(dirname(__DIR__)) . '/resources/views/themes', \FilesystemIterator::SKIP_DOTS);
|
|
|
|
|
|
|
|
/** @var \SplFileInfo $fileInfo */
|
|
|
|
foreach ($directoryIterator as $fileInfo)
|
|
|
|
{
|
|
|
|
if (!$fileInfo->isDir() || strtolower($fileInfo->getFilename()) == 'base')
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$themeName = strtolower($fileInfo->getFilename());
|
|
|
|
$themeDisplayName = $themeName;
|
|
|
|
|
|
|
|
$themeInfoFilename = sprintf('%s/theme.json', $fileInfo->getPathname());
|
|
|
|
if (file_exists($themeInfoFilename))
|
|
|
|
{
|
|
|
|
$themeInfo = json_decode(file_get_contents($themeInfoFilename));
|
|
|
|
if ($themeInfo !== false && isset($themeInfo->name))
|
|
|
|
{
|
|
|
|
$themeDisplayName = $themeInfo->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$results[$themeName] = $themeDisplayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
2016-09-05 15:28:56 +01:00
|
|
|
public function defaults()
|
|
|
|
{
|
2016-09-06 12:23:14 +01:00
|
|
|
$currentAppName = $this->get('app_name', false);
|
|
|
|
|
2016-09-05 15:28:56 +01:00
|
|
|
return array(
|
2016-09-05 21:43:58 +01:00
|
|
|
'allow_self_registration' => true,
|
2016-09-05 15:28:56 +01:00
|
|
|
'app_name' => trans('global.app_name'),
|
2016-09-05 21:43:58 +01:00
|
|
|
'date_format' => $this->allowedDateFormats()[0],
|
2016-09-11 07:19:11 +01:00
|
|
|
'hotlink_protection' => false,
|
2016-09-07 21:44:28 +01:00
|
|
|
'items_per_page' => 12,
|
|
|
|
'items_per_page_admin' => 10,
|
2016-09-08 11:02:49 +01:00
|
|
|
'recaptcha_enabled_registration' => false,
|
|
|
|
'recaptcha_secret_key' => '',
|
|
|
|
'recaptcha_site_key' => '',
|
2016-09-06 12:23:14 +01:00
|
|
|
'require_email_verification' => true,
|
2016-09-11 07:19:11 +01:00
|
|
|
'restrict_original_download' => true,
|
2016-09-06 12:23:14 +01:00
|
|
|
'sender_address' => sprintf('hostmaster@%s', (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost')),
|
|
|
|
'sender_name' => (is_null($currentAppName) ? trans('global.app_name') : $currentAppName),
|
|
|
|
'smtp_server' => 'localhost',
|
2016-09-21 12:10:37 +01:00
|
|
|
'smtp_port' => 25,
|
|
|
|
'theme' => 'bootstrap3'
|
2016-09-05 15:28:56 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get($key, $defaultIfUnset = true)
|
|
|
|
{
|
|
|
|
$config = Configuration::where('key', $key)->first();
|
|
|
|
|
2016-09-06 12:23:14 +01:00
|
|
|
if (is_null($config))
|
|
|
|
{
|
2016-09-21 12:10:37 +01:00
|
|
|
if ($defaultIfUnset)
|
|
|
|
{
|
|
|
|
$defaults = $this->defaults();
|
|
|
|
return (isset($defaults[$key]) ? $defaults[$key] : null);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2016-09-06 12:23:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $config->value;
|
2016-09-05 15:28:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getAll()
|
|
|
|
{
|
|
|
|
$results = array();
|
|
|
|
|
|
|
|
foreach (Configuration::all() as $config)
|
|
|
|
{
|
|
|
|
$results[$config->key] = $config->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOrCreateModel($key)
|
|
|
|
{
|
|
|
|
$config = Configuration::where('key', $key)->first();
|
|
|
|
if (is_null($config) || $config === false)
|
|
|
|
{
|
|
|
|
$config = new Configuration();
|
|
|
|
$config->key = $key;
|
|
|
|
$config->value = '';
|
|
|
|
$config->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
}
|