2016-09-05 15:28:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Helpers;
|
|
|
|
|
2016-11-03 13:33:35 +00:00
|
|
|
use App\AlbumSources\AmazonS3Source;
|
2016-09-24 09:34:08 +01:00
|
|
|
use App\AlbumSources\IAlbumSource;
|
|
|
|
use App\AlbumSources\LocalFilesystemSource;
|
2016-10-28 04:54:38 +01:00
|
|
|
use App\AlbumSources\OpenStackSource;
|
2016-11-05 09:41:07 +00:00
|
|
|
use App\AlbumSources\RackspaceSource;
|
2016-09-05 15:28:56 +01:00
|
|
|
use App\Configuration;
|
2019-07-11 09:01:20 +01:00
|
|
|
use App\Storage;
|
2016-09-05 15:28:56 +01:00
|
|
|
|
|
|
|
class ConfigHelper
|
|
|
|
{
|
2018-10-15 13:59:14 +01:00
|
|
|
/** @var mixed Cache of configuration values */
|
|
|
|
private $cache;
|
|
|
|
|
2016-10-05 14:49:44 +01:00
|
|
|
public function allowedAlbumViews()
|
|
|
|
{
|
|
|
|
return ['default', 'slideshow'];
|
|
|
|
}
|
|
|
|
|
2016-09-05 15:28:56 +01:00
|
|
|
public function allowedDateFormats()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'Y-m-d - H:i',
|
|
|
|
'd/m/Y - H:i',
|
2018-08-06 17:00:43 +01:00
|
|
|
'd-m-Y - H:i',
|
|
|
|
'd.m.Y - H:i',
|
|
|
|
'd/M/Y - H:i',
|
|
|
|
'd-M-Y - H:i',
|
2016-09-05 15:28:56 +01:00
|
|
|
'm/d/Y - H:i',
|
2018-08-06 17:00:43 +01:00
|
|
|
'm-d-Y - H:i',
|
|
|
|
'm.d.Y - H:i',
|
2016-09-05 15:28:56 +01:00
|
|
|
'jS F Y - H:i',
|
2018-08-06 17:00:43 +01:00
|
|
|
'jS M. Y - H:i',
|
|
|
|
'F jS Y - H:i',
|
|
|
|
'M. jS Y - H:i'
|
2016-09-05 15:28:56 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-09-24 09:34:08 +01:00
|
|
|
public function albumSources()
|
|
|
|
{
|
|
|
|
$results = [];
|
|
|
|
|
|
|
|
$classes = [
|
2016-10-28 04:54:38 +01:00
|
|
|
LocalFilesystemSource::class,
|
2016-11-03 13:33:35 +00:00
|
|
|
AmazonS3Source::class,
|
2016-11-05 09:41:07 +00:00
|
|
|
OpenStackSource::class,
|
|
|
|
RackspaceSource::class
|
2016-09-24 09:34:08 +01:00
|
|
|
];
|
|
|
|
foreach ($classes as $class)
|
|
|
|
{
|
|
|
|
/** @var IAlbumSource $instance */
|
|
|
|
$instance = new $class;
|
|
|
|
$key = basename(str_replace('\\', '/', $class));
|
|
|
|
$results[$key] = trans($instance->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
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(
|
2018-07-12 22:52:50 +01:00
|
|
|
'albums_menu_parents_only' => false,
|
|
|
|
'albums_menu_number_items' => 10,
|
2018-09-17 09:29:09 +01:00
|
|
|
'allow_photo_comments' => false,
|
2018-09-19 20:23:02 +01:00
|
|
|
'allow_photo_comments_anonymous' => true,
|
2016-09-05 21:43:58 +01:00
|
|
|
'allow_self_registration' => true,
|
2019-07-11 09:01:20 +01:00
|
|
|
'analysis_queue_storage_location' => Storage::where('is_default', true)->first()->id,
|
2016-10-28 16:07:24 +01:00
|
|
|
'analytics_code' => '',
|
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-10-05 14:49:44 +01:00
|
|
|
'default_album_view' => $this->allowedAlbumViews()[0],
|
2017-04-17 15:45:25 +01:00
|
|
|
'enable_visitor_hits' => false,
|
2018-08-14 09:12:28 +01:00
|
|
|
'facebook_app_id' => '',
|
|
|
|
'facebook_app_secret' => '',
|
2018-08-17 13:37:58 +01:00
|
|
|
'google_app_id' => '',
|
|
|
|
'google_app_secret' => '',
|
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,
|
2018-09-19 20:35:43 +01:00
|
|
|
'moderate_anonymous_users' => true,
|
|
|
|
'moderate_known_users' => true,
|
2018-09-24 09:12:07 +01:00
|
|
|
'photo_comments_allowed_html' => 'p,div,span,a,b,i,u',
|
2018-09-18 10:19:47 +01:00
|
|
|
'photo_comments_thread_depth' => 3,
|
2017-09-10 17:02:15 +01:00
|
|
|
'public_statistics' => true,
|
2019-07-13 21:40:13 +01:00
|
|
|
'queue_emails' => false,
|
2019-07-09 13:08:57 +01:00
|
|
|
'rabbitmq_enabled' => false,
|
|
|
|
'rabbitmq_server' => 'localhost',
|
|
|
|
'rabbitmq_password' => encrypt('guest'),
|
|
|
|
'rabbitmq_port' => 5672,
|
2019-07-09 22:03:54 +01:00
|
|
|
'rabbitmq_queue' => 'blue_twilight',
|
2019-07-09 13:08:57 +01:00
|
|
|
'rabbitmq_username' => 'guest',
|
2016-09-08 11:02:49 +01:00
|
|
|
'recaptcha_enabled_registration' => false,
|
|
|
|
'recaptcha_secret_key' => '',
|
|
|
|
'recaptcha_site_key' => '',
|
2016-10-05 16:31:37 +01:00
|
|
|
'remove_copyright' => false,
|
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',
|
2017-03-24 14:43:53 +00:00
|
|
|
'smtp_password' => '',
|
2016-09-21 12:10:37 +01:00
|
|
|
'smtp_port' => 25,
|
2017-03-24 14:43:53 +00:00
|
|
|
'smtp_username' => '',
|
2018-08-14 09:12:28 +01:00
|
|
|
'social_facebook_login' => false,
|
2018-08-17 13:37:58 +01:00
|
|
|
'social_google_login' => false,
|
2018-08-16 09:18:54 +01:00
|
|
|
'social_twitter_login' => false,
|
2018-10-09 22:16:43 +01:00
|
|
|
'social_user_feeds' => false,
|
2018-07-16 06:04:44 +01:00
|
|
|
'social_user_profiles' => false,
|
2018-08-16 09:18:54 +01:00
|
|
|
'theme' => 'default',
|
|
|
|
'twitter_app_id' => '',
|
|
|
|
'twitter_app_secret' => '',
|
2016-09-05 15:28:56 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get($key, $defaultIfUnset = true)
|
|
|
|
{
|
2018-10-15 13:59:14 +01:00
|
|
|
if (is_null($this->cache))
|
|
|
|
{
|
|
|
|
$this->loadCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
$config = isset($this->cache[$key]) ? $this->cache[$key] : null;
|
2016-09-05 15:28:56 +01:00
|
|
|
|
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();
|
|
|
|
|
2018-10-15 13:59:14 +01:00
|
|
|
/** @var Configuration $config */
|
2016-09-05 15:28:56 +01:00
|
|
|
foreach (Configuration::all() as $config)
|
|
|
|
{
|
|
|
|
$results[$config->key] = $config->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOrCreateModel($key)
|
|
|
|
{
|
2018-10-15 13:59:14 +01:00
|
|
|
$config = isset($this->cache[$key]) ? $this->cache[$key] : null;
|
2016-09-05 15:28:56 +01:00
|
|
|
if (is_null($config) || $config === false)
|
|
|
|
{
|
|
|
|
$config = new Configuration();
|
|
|
|
$config->key = $key;
|
|
|
|
$config->value = '';
|
|
|
|
$config->save();
|
2018-10-15 13:59:14 +01:00
|
|
|
|
2018-11-17 15:30:56 +00:00
|
|
|
$this->loadCache();
|
2016-09-05 15:28:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
}
|
2018-08-16 09:18:54 +01:00
|
|
|
|
2019-07-09 22:03:54 +01:00
|
|
|
public function isImageProcessingQueueEnabled()
|
|
|
|
{
|
|
|
|
return $this->get('rabbitmq_enabled') &&
|
|
|
|
!empty($this->get('rabbitmq_server')) &&
|
|
|
|
!empty($this->get('rabbitmq_port')) &&
|
|
|
|
!empty($this->get('rabbitmq_username')) &&
|
|
|
|
!empty($this->get('rabbitmq_password')) &&
|
|
|
|
!empty($this->get('rabbitmq_queue'));
|
|
|
|
}
|
|
|
|
|
2018-08-16 09:18:54 +01:00
|
|
|
public function isSocialMediaLoginEnabled()
|
|
|
|
{
|
|
|
|
return $this->get('social_facebook_login') ||
|
2018-10-09 22:16:43 +01:00
|
|
|
$this->get('social_twitter_login') ||
|
|
|
|
$this->get('social_google_login');
|
2018-08-16 09:18:54 +01:00
|
|
|
}
|
2018-10-15 13:59:14 +01:00
|
|
|
|
|
|
|
private function loadCache()
|
|
|
|
{
|
|
|
|
$this->cache = null;
|
|
|
|
|
|
|
|
/** @var Configuration $config */
|
|
|
|
foreach (Configuration::all() as $config)
|
|
|
|
{
|
|
|
|
$this->cache[$config->key] = $config;
|
|
|
|
}
|
|
|
|
}
|
2016-09-05 15:28:56 +01:00
|
|
|
}
|