2016-08-20 14:43:49 +10:00
|
|
|
<?php namespace Cms\Helpers;
|
|
|
|
|
|
|
|
use Url;
|
|
|
|
use Route;
|
2019-12-09 08:05:50 -05:00
|
|
|
use Config;
|
2016-08-20 14:43:49 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CMS Helper
|
|
|
|
*
|
2021-03-10 15:02:53 -06:00
|
|
|
* @package winter\wn-cms-module
|
2016-08-20 14:43:49 +10:00
|
|
|
* @see \Cms\Facades\Cms
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*/
|
|
|
|
class Cms
|
|
|
|
{
|
2018-08-15 18:33:24 +02:00
|
|
|
protected static $actionExists;
|
2016-08-20 14:43:49 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a URL in context of the Frontend
|
|
|
|
*/
|
|
|
|
public function url($path = null)
|
|
|
|
{
|
|
|
|
$routeAction = 'Cms\Classes\CmsController@run';
|
|
|
|
|
|
|
|
if (self::$actionExists === null) {
|
|
|
|
self::$actionExists = Route::getRoutes()->getByAction($routeAction) !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (substr($path, 0, 1) == '/') {
|
|
|
|
$path = substr($path, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self::$actionExists) {
|
|
|
|
return Url::action($routeAction, ['slug' => $path]);
|
|
|
|
}
|
2018-03-22 19:55:13 +03:00
|
|
|
|
|
|
|
return Url::to($path);
|
2016-08-20 14:43:49 +10:00
|
|
|
}
|
2019-12-09 08:05:50 -05:00
|
|
|
|
|
|
|
public static function safeModeEnabled()
|
|
|
|
{
|
|
|
|
$safeMode = Config::get('cms.enableSafeMode', null);
|
|
|
|
if ($safeMode === null) {
|
|
|
|
$safeMode = !Config::get('app.debug', false);
|
|
|
|
}
|
|
|
|
return $safeMode;
|
|
|
|
}
|
2017-04-24 13:38:19 +02:00
|
|
|
}
|