2017-12-10 11:56:26 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for retrieving a setting value
|
|
|
|
*/
|
2018-01-01 02:55:29 +08:00
|
|
|
if (!function_exists('setting')) {
|
2017-12-10 11:56:26 +08:00
|
|
|
function setting($key, $value = null)
|
|
|
|
{
|
2017-12-13 07:09:26 +08:00
|
|
|
$settingRepo = app('setting'); // defined in AppServiceProvider
|
|
|
|
if($value !== null) {
|
|
|
|
return $settingRepo->store($key, $value);
|
2017-12-10 11:56:26 +08:00
|
|
|
}
|
2017-12-13 07:09:26 +08:00
|
|
|
|
|
|
|
return $settingRepo->retrieve($key);
|
2017-12-10 11:56:26 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-18 06:58:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrap the asset URL in the publicBaseUrl that's been
|
|
|
|
* set
|
|
|
|
*/
|
2018-01-01 02:55:29 +08:00
|
|
|
if (!function_exists('public_asset')) {
|
2017-12-18 06:58:53 +08:00
|
|
|
function public_asset($path, $parameters = [], $secure = null)
|
|
|
|
{
|
|
|
|
$publicBaseUrl = app()->publicUrlPath();
|
|
|
|
$path = $publicBaseUrl . $path;
|
|
|
|
|
2017-12-25 02:10:51 +08:00
|
|
|
$path = str_replace('//', '/', $path);
|
|
|
|
|
2017-12-18 06:58:53 +08:00
|
|
|
return url($path, $parameters, $secure);
|
|
|
|
}
|
|
|
|
}
|
2017-12-24 01:58:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a date/time in the proper timezone for a user
|
|
|
|
*/
|
2018-01-01 02:55:29 +08:00
|
|
|
if(!function_exists('show_datetime')) {
|
2017-12-24 01:58:17 +08:00
|
|
|
/**
|
|
|
|
* Format the a Carbon date into the datetime string
|
|
|
|
* but convert it into the user's timezone
|
|
|
|
* @param \Carbon\Carbon $date
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-01-03 00:59:44 +08:00
|
|
|
function show_datetime(\Carbon\Carbon $date=null)
|
2017-12-24 01:58:17 +08:00
|
|
|
{
|
2018-01-03 00:59:44 +08:00
|
|
|
if(empty($date)) {
|
|
|
|
return '-';
|
|
|
|
}
|
|
|
|
|
2017-12-24 01:58:17 +08:00
|
|
|
$timezone = 'UTC';
|
|
|
|
if (Auth::check()) {
|
|
|
|
$timezone = Auth::user()->timezone ?: $timezone;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $date->timezone($timezone)->toDayDateTimeString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a date/time in the proper timezone for a user
|
|
|
|
*/
|
|
|
|
if (!function_exists('show_date')) {
|
|
|
|
/**
|
|
|
|
* Format the a Carbon date into the datetime string
|
|
|
|
* but convert it into the user's timezone
|
|
|
|
* @param \Carbon\Carbon $date
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function show_date(\Carbon\Carbon $date)
|
|
|
|
{
|
|
|
|
$timezone = 'UTC';
|
|
|
|
if (Auth::check()) {
|
|
|
|
$timezone = Auth::user()->timezone ?: $timezone;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $date->timezone($timezone)->toFormattedDateString();
|
|
|
|
}
|
|
|
|
}
|