Merge branch 'dev' into binarity.cz
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
|
||||
class Date
|
||||
{
|
||||
/**
|
||||
* Print date in configured format
|
||||
*
|
||||
* @param $datestamp
|
||||
* @param bool $withTime
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public static function date($datestamp, $withTime = true)
|
||||
{
|
||||
$timestamp = strtotime($datestamp);
|
||||
|
||||
if ($timestamp <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$format = $withTime ? config('app.datetime_format') : config('app.date_format');
|
||||
|
||||
return date($format, $timestamp);
|
||||
}
|
||||
|
||||
public static function dateFormatted($format, $datestamp)
|
||||
{
|
||||
$timestamp = strtotime($datestamp);
|
||||
|
||||
if ($timestamp <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return date($format, $timestamp);
|
||||
}
|
||||
|
||||
public static function monthName($datestamp) {
|
||||
$timestamp = strtotime($datestamp);
|
||||
|
||||
if ($timestamp <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$months = [
|
||||
trans('common.months.january'),
|
||||
trans('common.months.february'),
|
||||
trans('common.months.march'),
|
||||
trans('common.months.april'),
|
||||
trans('common.months.may'),
|
||||
trans('common.months.june'),
|
||||
trans('common.months.july'),
|
||||
trans('common.months.august'),
|
||||
trans('common.months.semptember'),
|
||||
trans('common.months.october'),
|
||||
trans('common.months.november'),
|
||||
trans('common.months.december'),
|
||||
];
|
||||
|
||||
$monthNumber = date('n', $timestamp);
|
||||
|
||||
return $months[$monthNumber - 1];
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ class GlobalViewDataProvider extends ServiceProvider
|
||||
}
|
||||
|
||||
view()->share('currentUrl', \Request::url());
|
||||
view()->share('loggedUser', \Auth::user());
|
||||
|
||||
$this->extendBlade();
|
||||
}
|
||||
@@ -100,6 +101,21 @@ class GlobalViewDataProvider extends ServiceProvider
|
||||
return preg_replace($pattern, $code, $view);
|
||||
});
|
||||
|
||||
Blade::extend(function ($view) {
|
||||
$pattern = $this->createPattern('customDate');
|
||||
$code = '<?php echo \App\Helpers\Date::dateFormatted($2); ?>';
|
||||
|
||||
return preg_replace($pattern, $code, $view);
|
||||
});
|
||||
|
||||
Blade::extend(function ($view) {
|
||||
$pattern = $this->createPattern('monthName');
|
||||
$code = '<?php echo \App\Helpers\Date::monthName($2); ?>';
|
||||
|
||||
return preg_replace($pattern, $code, $view);
|
||||
});
|
||||
|
||||
|
||||
// register extension for rendering widget areas
|
||||
Blade::extend(function ($view) {
|
||||
$pattern = $this->createPattern('widgetArea');
|
||||
|
||||
Reference in New Issue
Block a user