diff --git a/system/admin/views/config.html.php b/system/admin/views/config.html.php index d5de3fa..c665ce1 100644 --- a/system/admin/views/config.html.php +++ b/system/admin/views/config.html.php @@ -131,17 +131,6 @@ Please install and enable the INTL extension to format the date format to your l -
- -
- -
-
diff --git a/system/admin/views/theme-settings.html.php b/system/admin/views/theme-settings.html.php new file mode 100644 index 0000000..e957d81 --- /dev/null +++ b/system/admin/views/theme-settings.html.php @@ -0,0 +1,84 @@ + + + +
+
+
+ +
+
+
+
+ Theme: +
+
+ +
+ Version: +
+
+ +
+ Author: +
+
+ +
+ Homepage: +
+
+ +
+ Description: +
+
+ +
+
+

+ +

+
+ + +
+ +
+ + + + + + ' value="1"/> +
+ + + + +
+
+ +
+
+ +
+
+
+ + \ No newline at end of file diff --git a/system/admin/views/theme.html.php b/system/admin/views/theme.html.php new file mode 100644 index 0000000..a0ccad5 --- /dev/null +++ b/system/admin/views/theme.html.php @@ -0,0 +1,43 @@ + + +
+ + + +
+
+
+
+

+ + + + + + + + + +
+
+
+ +
+ diff --git a/system/htmly.php b/system/htmly.php index d9bb9ea..a21d664 100644 --- a/system/htmly.php +++ b/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' => '' . config('breadcrumb.home') . ' » ' . 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' => '' . config('breadcrumb.home') . ' » ' . i18n('blog_theme') . ' » ' . $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) { diff --git a/system/includes/dispatch.php b/system/includes/dispatch.php index c8063e4..7b88b17 100644 --- a/system/includes/dispatch.php +++ b/system/includes/dispatch.php @@ -131,6 +131,56 @@ function save_config($data = array(), $new = array()) return file_put_contents($config_file, $string, LOCK_EX); } +// Set the theme settings +function theme_settings() +{ + $exp = explode('/', config('views.root')); + $settings = 'config/themes/' . $exp[1] . '.ini'; + + if (file_exists($settings)) { + theme_config('source', $settings); + } +} + +function theme_config($key, $value = null) +{ + static $_config = array(); + + if ($key === 'source' && file_exists($value)) + $_config = parse_ini_file($value, true); + elseif ($value == null) + return (isset($_config[$key]) ? $_config[$key] : null); + else + $_config[$key] = $value; +} + +function save_theme_config($data = array(), $new = array(), $theme = null) +{ + $dir = 'config/themes/'; + if (!is_dir($dir)) { + mkdir($dir, 0775, true); + } + $config_file = $dir . $theme . '.ini'; + + $string = file_get_contents($config_file) . "\n"; + + foreach ($data as $word => $value) { + $value = json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + $map = array('\r\n' => ' \n ', '\r' => ' \n '); + $value = trim(strtr($value, $map)); + $string = preg_replace("/^" . $word . " = .+$/m", $word . ' = ' . $value, $string); + } + $string = rtrim($string); + foreach ($new as $word => $value) { + $value = json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + $map = array('\r\n' => ' \n ', '\r' => ' \n '); + $value = trim(strtr($value, $map)); + $string .= "\n" . $word . ' = ' . $value . "\n"; + } + $string = rtrim($string); + return file_put_contents($config_file, $string, LOCK_EX); +} + function get_search_query() { if (isset($_GET['search'])) { diff --git a/system/includes/functions.php b/system/includes/functions.php index b61a3e9..a72076d 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -2388,9 +2388,9 @@ function shorten($string = null, $char = null) $string = ltrim(rtrim($string)); $string = str_replace('', '', $string); if (!empty($char)) { - if (strlen($string) > $char) { - $string = substr($string, 0, $char); - $string = substr($string, 0, strrpos($string, ' ')); + if (mb_strlen($string) > $char) { + $string = mb_substr($string, 0, $char); + $string = mb_substr($string, 0, mb_strrpos($string, ' ')); } } return $string; diff --git a/system/resources/images/default-screenshot.jpg b/system/resources/images/default-screenshot.jpg new file mode 100644 index 0000000..0008f5e Binary files /dev/null and b/system/resources/images/default-screenshot.jpg differ