mirror of
https://github.com/danpros/htmly.git
synced 2026-04-21 13:06:22 +05:30
Add theme settings
Adding simple theme settings. We can add the fields available in theme.json.
This commit is contained in:
parent
c18896b2b6
commit
c442f92dde
7 changed files with 284 additions and 14 deletions
104
system/htmly.php
104
system/htmly.php
|
|
@ -22,6 +22,9 @@ if (config('timezone')) {
|
|||
// Publish scheduled post
|
||||
publish_scheduled();
|
||||
|
||||
// Load theme settings
|
||||
theme_settings();
|
||||
|
||||
// The front page of the blog
|
||||
get('/index', function () {
|
||||
|
||||
|
|
@ -3272,6 +3275,107 @@ post('/admin/field/profile', function () {
|
|||
}
|
||||
});
|
||||
|
||||
// Show admin/themes
|
||||
get('/admin/themes', function () {
|
||||
if (login()) {
|
||||
config('views.root', 'system/admin/views');
|
||||
render('theme', array(
|
||||
'title' => generate_title('is_default', i18n('blog_theme')),
|
||||
'description' => safe_html(strip_tags(blog_description())),
|
||||
'canonical' => site_url(),
|
||||
'metatags' => generate_meta(null, null),
|
||||
'type' => 'is_admin-content',
|
||||
'is_admin' => true,
|
||||
'bodyclass' => 'admin-content',
|
||||
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> » ' . i18n('blog_theme')
|
||||
));
|
||||
} else {
|
||||
$login = site_url() . 'login';
|
||||
header("location: $login");
|
||||
}
|
||||
});
|
||||
|
||||
post('/admin/themes', function () {
|
||||
if (login()) {
|
||||
$new_config = array();
|
||||
$new_Keys = array();
|
||||
$user = $_SESSION[site_url()]['user'];
|
||||
$role = user('role', $user);
|
||||
if ($role === 'admin') {
|
||||
$json = $_REQUEST['json'];
|
||||
$new_config['views.root'] = $json;
|
||||
save_config($new_config, $new_Keys);
|
||||
echo json_encode(array(
|
||||
'message' => 'Theme activated!',
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Show admin/themes/:theme
|
||||
get('/admin/themes/:theme', function ($theme) {
|
||||
|
||||
$exp = explode('/', config('views.root'));
|
||||
if ($theme !== $exp[1]) {
|
||||
$redir = site_url() . 'admin/themes';
|
||||
header("location: $redir");
|
||||
}
|
||||
if (login()) {
|
||||
config('views.root', 'system/admin/views');
|
||||
render('theme-settings', array(
|
||||
'title' => generate_title('is_default', $theme),
|
||||
'description' => safe_html(strip_tags(blog_description())),
|
||||
'canonical' => site_url(),
|
||||
'metatags' => generate_meta(null, null),
|
||||
'type' => 'is_admin-content',
|
||||
'theme' => $theme,
|
||||
'is_admin' => true,
|
||||
'bodyclass' => 'admin-content',
|
||||
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> » <a href="'. site_url() .'admin/themes">' . i18n('blog_theme') . '</a> » ' . $theme
|
||||
));
|
||||
} else {
|
||||
$login = site_url() . 'login';
|
||||
header("location: $login");
|
||||
}
|
||||
});
|
||||
|
||||
// Submitted theme settings data
|
||||
post('/admin/themes/:theme', function ($theme) {
|
||||
$exp = explode('/', config('views.root'));
|
||||
if ($theme !== $exp[1]) {
|
||||
$redir = site_url() . 'admin/themes';
|
||||
header("location: $redir");
|
||||
}
|
||||
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
|
||||
if (login() && $proper) {
|
||||
$new_config = array();
|
||||
$new_Keys = array();
|
||||
$user = $_SESSION[site_url()]['user'];
|
||||
$role = user('role', $user);
|
||||
if ($role === 'admin') {
|
||||
foreach ($_POST as $name => $value) {
|
||||
if (substr($name, 0, 8) == "-config-") {
|
||||
$name = substr($name, 8);
|
||||
if(!is_null(theme_config($name))) {
|
||||
$new_config[$name] = $value;
|
||||
} else {
|
||||
$new_Keys[$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
save_theme_config($new_config, $new_Keys, $theme);
|
||||
$redir = site_url() . 'admin/themes/' . $theme;
|
||||
header("location: $redir");
|
||||
} else {
|
||||
$redir = site_url();
|
||||
header("location: $redir");
|
||||
}
|
||||
} else {
|
||||
$login = site_url() . 'login';
|
||||
header("location: $login");
|
||||
}
|
||||
});
|
||||
|
||||
// Show the category page
|
||||
get('/category/:category', function ($category) {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue