2014-05-14 23:24:20 +10:00
|
|
|
<?php namespace Backend\Classes;
|
|
|
|
|
2014-09-20 11:25:57 +10:00
|
|
|
use Str;
|
|
|
|
use File;
|
2014-05-14 23:24:20 +10:00
|
|
|
use Config;
|
2014-09-20 11:25:57 +10:00
|
|
|
use October\Rain\Router\Helper as RouterHelper;
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Skin Base class
|
|
|
|
* Used for defining skins.
|
|
|
|
*
|
|
|
|
* @package october\backend
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*/
|
|
|
|
abstract class Skin
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns information about this skin, including name and description.
|
|
|
|
*/
|
|
|
|
abstract public function skinDetails();
|
|
|
|
|
2014-09-20 11:25:57 +10:00
|
|
|
/**
|
|
|
|
* @var string The absolute path to this skin.
|
|
|
|
*/
|
2014-05-14 23:24:20 +10:00
|
|
|
public $skinPath;
|
|
|
|
|
2014-09-20 11:25:57 +10:00
|
|
|
/**
|
|
|
|
* @var string The public path to this skin.
|
|
|
|
*/
|
|
|
|
public $publicSkinPath;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string The default skin path, usually the root level of modules/backend.
|
|
|
|
*/
|
|
|
|
public $defaultSkinPath;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string The default public skin path.
|
|
|
|
*/
|
|
|
|
public $defaultPublicSkinPath;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Self Cache of the active skin.
|
|
|
|
*/
|
2014-05-14 23:24:20 +10:00
|
|
|
private static $skinCache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2014-09-20 11:25:57 +10:00
|
|
|
$this->defaultSkinPath = PATH_BASE . '/modules/backend';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Guess the skin path
|
|
|
|
*/
|
|
|
|
$class = get_called_class();
|
|
|
|
$classFolder = strtolower(Str::getRealClass($class));
|
|
|
|
$classFile = realpath(dirname(File::fromClass($class)));
|
|
|
|
$this->skinPath = $classFile
|
|
|
|
? $classFile . '/' . $classFolder
|
|
|
|
: $this->defaultSkinPath;
|
|
|
|
|
|
|
|
$this->publicSkinPath = File::localToPublic($this->skinPath);
|
|
|
|
$this->defaultPublicSkinPath = File::localToPublic($this->defaultSkinPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Looks up a path to a skin-based file, if it doesn't exist, the default path is used.
|
|
|
|
* @param string $path
|
|
|
|
* @param boolean $isPublic
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPath($path = null, $isPublic = false)
|
|
|
|
{
|
|
|
|
$path = RouterHelper::normalizeUrl($path);
|
|
|
|
$assetFile = $this->skinPath . $path;
|
|
|
|
|
|
|
|
if (File::isFile($assetFile)) {
|
|
|
|
return $isPublic
|
|
|
|
? $this->publicSkinPath . $path
|
|
|
|
: $this->skinPath . $path;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $isPublic
|
|
|
|
? $this->defaultPublicSkinPath . $path
|
|
|
|
: $this->defaultSkinPath . $path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of paths where skin layouts can be found.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getLayoutPaths()
|
|
|
|
{
|
|
|
|
return [$this->skinPath.'/layouts', $this->defaultSkinPath.'/layouts'];
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the active skin.
|
|
|
|
*/
|
|
|
|
public static function getActive()
|
|
|
|
{
|
|
|
|
if (self::$skinCache !== null)
|
|
|
|
return self::$skinCache;
|
|
|
|
|
|
|
|
$skinClass = Config::get('cms.backendSkin');
|
|
|
|
$skinObject = new $skinClass();
|
|
|
|
return self::$skinCache = $skinObject;
|
|
|
|
}
|
|
|
|
}
|