2017-12-10 11:56:26 +08:00
|
|
|
<?php
|
|
|
|
|
2018-01-22 02:43:32 +08:00
|
|
|
if(!function_exists('get_truth_state')) {
|
|
|
|
/**
|
|
|
|
* Check if the passed state matches any of the states that
|
|
|
|
* we regard as being true or false
|
|
|
|
* @param $state
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function get_truth_state($state)
|
|
|
|
{
|
|
|
|
$enabledStates = [
|
2018-01-22 02:52:55 +08:00
|
|
|
'yes',
|
|
|
|
'y',
|
2018-01-22 02:43:32 +08:00
|
|
|
'on',
|
|
|
|
'true',
|
|
|
|
'1',
|
|
|
|
true,
|
|
|
|
];
|
|
|
|
|
2018-01-22 02:52:55 +08:00
|
|
|
if(is_string($state)) {
|
|
|
|
$state = strtolower($state);
|
|
|
|
}
|
|
|
|
|
2018-01-22 02:43:32 +08:00
|
|
|
return \in_array($state, $enabledStates, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-22 02:36:03 +08:00
|
|
|
if(!function_exists('list_to_assoc')) {
|
|
|
|
/**
|
|
|
|
* Converts a straight list into an assoc array with
|
|
|
|
* key and value being the same. Mainly for a select box
|
|
|
|
*
|
|
|
|
* e.g.:
|
|
|
|
* [ 0 => 'item1', 1 => 'item2']
|
|
|
|
* to:
|
|
|
|
* ['item1' => 'item1', 'item2' => 'item2']
|
|
|
|
*
|
|
|
|
* @param array $list
|
2018-01-22 02:59:51 +08:00
|
|
|
* @return array
|
2018-01-22 02:36:03 +08:00
|
|
|
*/
|
|
|
|
function list_to_assoc(array $list)
|
|
|
|
{
|
2018-01-22 02:59:51 +08:00
|
|
|
$ret = [];
|
|
|
|
foreach($list as $item) {
|
|
|
|
$ret[$item] = $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
2018-01-22 02:36:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-12 11:21:33 +08:00
|
|
|
if (!function_exists('skin_view')) {
|
|
|
|
/**
|
|
|
|
* Render a skin
|
|
|
|
* @param $template
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
function skin_view($template, array $vars = [], $merge_data = [])
|
|
|
|
{
|
|
|
|
$tpl = 'layouts/' . config('phpvms.skin') . '/' . $template;
|
|
|
|
return view($tpl, $vars, $merge_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 11:56:26 +08:00
|
|
|
/**
|
|
|
|
* Shortcut for retrieving a setting value
|
|
|
|
*/
|
2018-01-01 02:55:29 +08:00
|
|
|
if (!function_exists('setting')) {
|
2018-01-03 03:17:22 +08:00
|
|
|
function setting($key, $default = null)
|
2017-12-10 11:56:26 +08:00
|
|
|
{
|
2018-01-20 01:46:30 +08:00
|
|
|
$settingRepo = app('setting');
|
|
|
|
try {
|
|
|
|
$value = $settingRepo->retrieve($key);
|
|
|
|
} catch (\App\Exceptions\SettingNotFound $e) {
|
|
|
|
return $default;
|
|
|
|
}
|
2017-12-13 07:09:26 +08:00
|
|
|
|
2018-01-20 01:46:30 +08:00
|
|
|
return $value;
|
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();
|
|
|
|
}
|
|
|
|
}
|