mirror of
https://github.com/fruithost/Panel.git
synced 2026-11-07 04:22:35 +09:00
201 lines
6.5 KiB
PHP
201 lines
6.5 KiB
PHP
<?php
|
|
namespace fruithost;
|
|
use \fruithost\I18N;
|
|
use \fruithost\Database;
|
|
|
|
class Template extends TemplateDefaults {
|
|
private $core;
|
|
private $theme = null;
|
|
private $assigns = [];
|
|
private $files = null;
|
|
private $navigation = null;
|
|
|
|
public function __construct($core) {
|
|
$this->core = $core;
|
|
$this->files = new TemplateFiles();
|
|
$this->navigation = new TemplateNavigation($this->core);
|
|
$this->theme = $this->core->getHooks()->applyFilter('theme_name', 'default');
|
|
$this->assigns = [
|
|
'project_name' => $this->core->getSettings('PROJECT_NAME', 'fruithost'),
|
|
'project_copyright' => $this->core->getSettings('PROJECT_COPYRIGHT', true)
|
|
];
|
|
|
|
ob_start('ob_gzhandler');
|
|
|
|
$this->core->getHooks()->addAction('html_head', [ $this, 'head_robots' ], 10, false);
|
|
$this->core->getHooks()->addAction('html_head', [ $this, 'head_scripts' ], 10, false);
|
|
$this->core->getHooks()->addAction('html_head', [ $this, 'theme_color' ], 10, false);
|
|
$this->core->getHooks()->addAction('html_head', [ $this, 'favicon' ], 10, false);
|
|
$this->core->getHooks()->addAction('html_foot', [ $this, 'foot_modals' ], 10, false);
|
|
$this->core->getHooks()->addAction('html_foot', [ $this, 'foot_scripts' ], 10, false);
|
|
|
|
$this->files->addStylesheet('bootstrap', $this->url('css/bootstrap/bootstrap.min.css'), '4.3.1');
|
|
$this->files->addStylesheet('jquery-ui', $this->url('css/jquery-ui/jquery-ui.css'), '1.12.1');
|
|
$this->files->addStylesheet('material-icons', $this->url('fonts/material-icons/material-icons.css'), '3.0.1', [ 'bootstrap' ]);
|
|
$this->files->addStylesheet('cascadia-mono', $this->url('fonts/cascadia-mono/cascadia-mono.css'), '2111.01', [ 'bootstrap' ]);
|
|
$this->files->addJavascript('popper', $this->url('js/popper/popper.min.js'), '3.3.1', [ 'jquery' ], TemplateFiles::FOOTER);
|
|
$this->files->addJavascript('jquery', $this->url('js/jquery/jquery-3.3.1.min.js'), '3.3.1', [], TemplateFiles::FOOTER);
|
|
$this->files->addJavascript('bootstrap', $this->url('js/bootstrap/bootstrap.bundle.min.js'), '4.3.1', [ 'jquery', 'popper' ], TemplateFiles::FOOTER);
|
|
|
|
$this->navigation->addCategory('account', I18N::get('Account'));
|
|
$this->navigation->addCategory('database', I18N::get('Databases'));
|
|
$this->navigation->addCategory('domain', I18N::get('Domains'));
|
|
$this->navigation->addCategory('mail', I18N::get('E-Mails'));
|
|
$this->navigation->addCategory('ftp', I18N::get('FTP'));
|
|
$this->navigation->addCategory('hosting', I18N::get('Hosting'));
|
|
$this->navigation->addCategory('extended', I18N::get('Extended'));
|
|
$this->navigation->addCategory('support', I18N::get('Support'));
|
|
$this->navigation->addCategory('admin', I18N::get('Administration'));
|
|
$this->navigation->addCategory('server', I18N::get('Server'));
|
|
|
|
$this->assign('topbar', $this->navigation->getCategory('account'));
|
|
$this->assign('navigation', $this->navigation);
|
|
}
|
|
|
|
public function getCore() {
|
|
return $this->core;
|
|
}
|
|
|
|
public function getAssigns() {
|
|
return $this->assigns;
|
|
}
|
|
|
|
public function getFiles() {
|
|
return $this->files;
|
|
}
|
|
|
|
public function assign($name, $value) {
|
|
$this->assigns[$name] = $value;
|
|
}
|
|
|
|
public function display($file, $arguments = [], $basedir = true) {
|
|
$template = $this;
|
|
|
|
foreach($arguments AS $name => $value) {
|
|
$this->assigns[$name] = $value;
|
|
}
|
|
|
|
if($basedir) {
|
|
$path = sprintf('%1$sthemes%2$s%4$s%2$s%3$s.php', dirname(PATH), DS, $file, $this->theme);
|
|
} else {
|
|
$path = $file;
|
|
}
|
|
|
|
$handler = sprintf('%1$shandler%2$s%3$s.php', PATH, DS, $file);
|
|
|
|
foreach($this->assigns AS $name => $value) {
|
|
${$name} = $value;
|
|
}
|
|
|
|
if(file_exists($handler)) {
|
|
require_once($handler);
|
|
|
|
foreach($this->assigns AS $name => $value) {
|
|
${$name} = $value;
|
|
}
|
|
}
|
|
|
|
if(file_exists($path) && is_readable($path)) {
|
|
require_once($path);
|
|
} else {
|
|
if(!Auth::isLoggedIn()) {
|
|
$this->getFiles()->addStylesheet('login', $this->url('css/login.css'), '1.0.0', [ 'bootstrap', 'material-icons' ]);
|
|
} else {
|
|
$this->getFiles()->addStylesheet('style', $this->url('css/style.css'), '1.0.0', [ 'bootstrap', 'material-icons' ]);
|
|
$this->getFiles()->addJavascript('jquery-ui', $this->url('js/jquery-ui/jquery-ui.min.js'), '1.12.1', [ 'jquery' ], TemplateFiles::FOOTER);
|
|
$this->getFiles()->addJavascript('ui', $template->url('js/ui.js'), '1.0.0', [ 'jquery', 'jquery-ui', 'popper', 'bootstrap' ], TemplateFiles::FOOTER);
|
|
}
|
|
|
|
$path = sprintf('%1$s%2$sdefault%2$s%3$s.php', PATH, DS, $file);
|
|
|
|
if(file_exists($path) && is_readable($path)) {
|
|
require_once($path);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function header() {
|
|
$template = $this;
|
|
$path = sprintf('%1$s%2$sthemes%2$s%4$s%2$s%3$s.php', dirname(PATH), DS, 'header', $this->theme);
|
|
|
|
foreach($this->assigns AS $name => $value) {
|
|
${$name} = $value;
|
|
}
|
|
|
|
if(file_exists($path)) {
|
|
@require_once($path);
|
|
} else {
|
|
$path = sprintf('%1$s%2$sdefault%2$s%3$s.php', PATH, DS, 'header');
|
|
|
|
if(file_exists($path)) {
|
|
@require_once($path);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function footer() {
|
|
$template = $this;
|
|
$path = sprintf('%1$s%2$sthemes%2$s%4$s%2$s%3$s.php', dirname(PATH), DS, 'footer', $this->theme);
|
|
|
|
foreach($this->assigns AS $name => $value) {
|
|
${$name} = $value;
|
|
}
|
|
|
|
if(file_exists($path)) {
|
|
require_once($path);
|
|
} else {
|
|
$path = sprintf('%1$s%2$sdefault%2$s%3$s.php', PATH, DS, 'footer');
|
|
|
|
if(file_exists($path)) {
|
|
@require_once($path);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getLanguage($short = false) {
|
|
// @ToDo
|
|
if($short) {
|
|
return 'en';
|
|
}
|
|
|
|
return 'en_US';
|
|
}
|
|
|
|
public function head() {
|
|
$this->core->getHooks()->runAction('html_head');
|
|
}
|
|
|
|
public function foot() {
|
|
$this->core->getHooks()->runAction('html_foot');
|
|
}
|
|
|
|
public function url($path = null, $parameters = null) {
|
|
$scheme = 'http';
|
|
|
|
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
|
$scheme = 'https';
|
|
}
|
|
|
|
if($path === true || $path === null) {
|
|
$path = $_SERVER['REQUEST_URI'];
|
|
}
|
|
|
|
if(substr($path, 0, 1) === '/') {
|
|
$path = substr($path, 1);
|
|
}
|
|
|
|
if(!empty($parameters)) {
|
|
if(strpos($path, '?')) {
|
|
$path = explode('?', $path);
|
|
$path = $path[0];
|
|
}
|
|
|
|
$path .= '?' . http_build_query(array_merge($_GET, $parameters));
|
|
} else if(Request::has('lang') && !strpos($path, '?')) {
|
|
$path .= '?lang=' . Request::get('lang');
|
|
}
|
|
|
|
return $scheme . '://' . $_SERVER['HTTP_HOST'] . '/' . $path;
|
|
}
|
|
}
|
|
?>
|