Marc Jauvin 864816f7f2 Make CMS object code editor read-only in safe mode (#4769)
Adds a dismissable message to the CMS object code editor indicating that the PHP code section of a CMS object cannot be edited when `cms.enableSafeMode` is `true` (or when debugging is disabled if `null`).

Credit to @mjauvin.
2019-12-09 21:05:50 +08:00

49 lines
1.0 KiB
PHP

<?php namespace Cms\Helpers;
use Url;
use Route;
use Config;
/**
* CMS Helper
*
* @package october\cms
* @see \Cms\Facades\Cms
* @author Alexey Bobkov, Samuel Georges
*/
class Cms
{
protected static $actionExists;
/**
* 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]);
}
return Url::to($path);
}
public static function safeModeEnabled()
{
$safeMode = Config::get('cms.enableSafeMode', null);
if ($safeMode === null) {
$safeMode = !Config::get('app.debug', false);
}
return $safeMode;
}
}