Themes integrated as part of Template

This commit is contained in:
Gautham Warrier 2014-10-12 12:55:33 +05:30
parent 428e4b2ef8
commit 9ef2f5aee4
32 changed files with 39 additions and 22 deletions

View File

@ -139,7 +139,7 @@
private function recursive_generate_static($tree, $output_dir, $params, $base_url = '') { private function recursive_generate_static($tree, $output_dir, $params, $base_url = '') {
$params['base_url'] = $params['base_page'] = $base_url; $params['base_url'] = $params['base_page'] = $base_url;
$new_params = $params; $new_params = $params;
$params['theme'] = DauxHelper::rebase_theme($params['theme'], $base_url); $params['theme'] = DauxHelper::rebase_theme($params['theme'], $base_url, $params['base_url'] . "themes/" . $params['theme']['name'] . '/');
$params['image'] = str_replace('<base_url>', $base_url, $params['image']); $params['image'] = str_replace('<base_url>', $base_url, $params['image']);
if ($base_url !== '') $params['entry_page'] = $tree->first_page; if ($base_url !== '') $params['entry_page'] = $tree->first_page;
foreach ($tree->value as $key => $node) { foreach ($tree->value as $key => $node) {
@ -220,9 +220,10 @@
$params['piwik_analytics'] = ($p = $this->options['piwik_analytics']) ? $params['piwik_analytics'] = ($p = $this->options['piwik_analytics']) ?
DauxHelper::piwik_analytics($p, $this->options['piwik_analytics_id']) : ''; DauxHelper::piwik_analytics($p, $this->options['piwik_analytics_id']) : '';
$params['theme'] = DauxHelper::configure_theme($this->local_base . DIRECTORY_SEPARATOR . 'themes' . $params['template'] = $this->options['template'];
DIRECTORY_SEPARATOR . $this->options['theme'] . '.thm', $params['base_url'], $params['theme'] = DauxHelper::configure_theme($this->local_base . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR .
$params['local_base']); $this->options['template'] . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $this->options['theme'] . '.thm', $params['base_url'],
$this->local_base, $params['base_url'] . "templates/" . $params['template'] . "/themes/" . $this->options['theme'] . '/');
break; break;
case Daux::LIVE_MODE: case Daux::LIVE_MODE:
@ -249,9 +250,11 @@
$params['piwik_analytics'] = ($p = $this->options['piwik_analytics']) ? $params['piwik_analytics'] = ($p = $this->options['piwik_analytics']) ?
DauxHelper::piwik_analytics($p, $this->options['piwik_analytics_id']) : ''; DauxHelper::piwik_analytics($p, $this->options['piwik_analytics_id']) : '';
$params['theme'] = DauxHelper::configure_theme($this->local_base . DIRECTORY_SEPARATOR . 'themes' . $params['template'] = $this->options['template'];
DIRECTORY_SEPARATOR . $this->options['theme'] . '.thm', $params['base_url'], $params['theme'] = DauxHelper::configure_theme($this->local_base . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR .
$params['local_base'], $mode); $this->options['template'] . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $this->options['theme'] . '.thm', $params['base_url'],
$this->local_base, $params['base_url'] . "templates/" . $params['template'] . "/themes/" . $this->options['theme'] . '/', $mode);
if ($params['breadcrumbs'] = $this->options['breadcrumbs']) if ($params['breadcrumbs'] = $this->options['breadcrumbs'])
$params['breadcrumb_separator'] = $this->options['breadcrumb_separator']; $params['breadcrumb_separator'] = $this->options['breadcrumb_separator'];
@ -291,9 +294,10 @@
$params['piwik_analytics'] = ($p = $this->options['piwik_analytics']) ? $params['piwik_analytics'] = ($p = $this->options['piwik_analytics']) ?
DauxHelper::piwik_analytics($p, $this->options['piwik_analytics_id']) : ''; DauxHelper::piwik_analytics($p, $this->options['piwik_analytics_id']) : '';
$params['theme'] = DauxHelper::configure_theme($this->local_base . DIRECTORY_SEPARATOR . 'themes' . $params['template'] = $this->options['template'];
DIRECTORY_SEPARATOR . $this->options['theme'] . '.thm', $params['base_url'], $params['theme'] = DauxHelper::configure_theme($this->local_base . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR .
$params['local_base'], $mode); $this->options['template'] . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $this->options['theme'] . '.thm', $params['base_url'],
$this->local_base, $params['base_url'] . "templates/" . $params['template'] . "/themes/" . $this->options['theme'] . '/', $mode);
if ($params['breadcrumbs'] = $this->options['breadcrumbs']) if ($params['breadcrumbs'] = $this->options['breadcrumbs'])
$params['breadcrumb_separator'] = $this->options['breadcrumb_separator']; $params['breadcrumb_separator'] = $this->options['breadcrumb_separator'];

View File

@ -72,35 +72,41 @@
return $request; return $request;
} }
public static function configure_theme($theme, $base_url, $local_base, $mode = Daux::LIVE_MODE) { public static function configure_theme($theme, $base_url, $local_base, $theme_url, $mode = Daux::LIVE_MODE) {
$name = static::pathinfo($theme);
if (is_file($theme)) { if (is_file($theme)) {
$theme = file_get_contents($theme); $theme = file_get_contents($theme);
$theme = json_decode($theme, true); $theme = json_decode($theme, true);
if (!$theme) $theme = array(); if (!$theme) $theme = array();
} else $theme = array(); } else $theme = array();
$theme['name'] = $name['filename'];
if ($mode === Daux::LIVE_MODE) { if ($mode === Daux::LIVE_MODE) {
if (!isset($theme['favicon'])) $theme['favicon'] = utf8_encode($base_url . 'img/favicon.png'); if (!isset($theme['favicon'])) $theme['favicon'] = utf8_encode($base_url . 'img/favicon.png');
else { else {
$theme['favicon'] = utf8_encode(str_replace('<base_url>', $base_url, $theme['favicon'])); $theme['favicon'] = utf8_encode(str_replace('<base_url>', $base_url, $theme['favicon']));
$theme['favicon'] = str_replace('<theme_url>', $theme_url, $theme['favicon']);
} }
if (!isset($theme['css'])) $theme['css'] = array(); if (!isset($theme['css'])) $theme['css'] = array();
else { else {
foreach ($theme['css'] as $key => $css) { foreach ($theme['css'] as $key => $css) {
$theme['css'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $css)); $theme['css'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $css));
$theme['css'][$key] = utf8_encode(str_replace('<theme_url>', $theme_url, $css));
} }
} }
if (!isset($theme['fonts'])) $theme['fonts'] = array(); if (!isset($theme['fonts'])) $theme['fonts'] = array();
else { else {
foreach ($theme['fonts'] as $key => $font) { foreach ($theme['fonts'] as $key => $font) {
$theme['fonts'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $font)); $theme['fonts'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $font));
$theme['fonts'][$key] = utf8_encode(str_replace('<theme_url>', $theme_url, $font));
} }
} }
if (!isset($theme['js'])) $theme['js'] = array(); if (!isset($theme['js'])) $theme['js'] = array();
else { else {
foreach ($theme['js'] as $key => $js) { foreach ($theme['js'] as $key => $js) {
$theme['js'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $js)); $theme['js'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $js));
$theme['js'][$key] = utf8_encode(str_replace('<theme_url>', $theme_url, $js));
} }
} }
} else { } else {
@ -111,26 +117,33 @@
} }
if (!isset($theme['template'])) $theme['template'] = $local_base . DIRECTORY_SEPARATOR . 'templates' . if (!isset($theme['template'])) $theme['template'] = $local_base . DIRECTORY_SEPARATOR . 'templates' .
DIRECTORY_SEPARATOR . 'default.tpl'; DIRECTORY_SEPARATOR . 'default/default.tpl';
else $theme['template'] = str_replace('<local_base>', $local_base, $theme['template']); else $theme['template'] = str_replace('<local_base>', $local_base, $theme['template']);
if (!isset($theme['error-template'])) $theme['error-template'] = $local_base . DIRECTORY_SEPARATOR . 'templates' . if (!isset($theme['error-template'])) $theme['error-template'] = $local_base . DIRECTORY_SEPARATOR . 'templates' .
DIRECTORY_SEPARATOR . 'error.tpl'; DIRECTORY_SEPARATOR . 'default/error.tpl';
else $theme['error-template'] = str_replace('<local_base>', $local_base, $theme['error-template']); else $theme['error-template'] = str_replace('<local_base>', $local_base, $theme['error-template']);
if (!isset($theme['require-jquery'])) $theme['require-jquery'] = false; if (!isset($theme['require-jquery'])) $theme['require-jquery'] = false;
if (!isset($theme['bootstrap-js'])) $theme['bootstrap-js'] = false; if (!isset($theme['bootstrap-js'])) $theme['bootstrap-js'] = false;
return $theme; return $theme;
} }
public static function rebase_theme($theme, $base_url) { public static function rebase_theme($theme, $base_url, $theme_url) {
$theme['favicon'] = utf8_encode(str_replace('<base_url>', $base_url, $theme['favicon'])); $theme['favicon'] = utf8_encode(str_replace('<base_url>', $base_url, $theme['favicon']));
$theme['favicon'] = str_replace('<theme_url>', $theme_url, $theme['favicon']);
foreach ($theme['css'] as $key => $css) { foreach ($theme['css'] as $key => $css) {
$theme['css'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $css)); $theme['css'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $css));
$theme['css'][$key] = utf8_encode(str_replace('<theme_url>', $theme_url, $css));
} }
foreach ($theme['fonts'] as $key => $font) { foreach ($theme['fonts'] as $key => $font) {
$theme['fonts'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $font)); $theme['fonts'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $font));
$theme['fonts'][$key] = utf8_encode(str_replace('<theme_url>', $theme_url, $font));
} }
foreach ($theme['js'] as $key => $js) { foreach ($theme['js'] as $key => $js) {
$theme['js'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $js)); $theme['js'][$key] = utf8_encode(str_replace('<base_url>', $base_url, $js));
$theme['js'][$key] = utf8_encode(str_replace('<theme_url>', $theme_url, $js));
} }
return $theme; return $theme;
} }

View File

@ -1,6 +1,6 @@
{ {
"favicon": "<base_url>themes/daux-blue/img/favicon-blue.png", "favicon": "<theme_url>img/favicon-blue.png",
"css": ["<base_url>themes/daux-blue/css/daux-blue.css"], "css": ["<theme_url>css/daux-blue.css"],
"fonts": ["//fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,cyrillic-ext,cyrillic"], "fonts": ["//fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,cyrillic-ext,cyrillic"],
"js": [], "js": [],
"require-jquery": true, "require-jquery": true,

View File

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,6 +1,6 @@
{ {
"favicon": "<base_url>themes/daux-green/img/favicon-green.png", "favicon": "<theme_url>img/favicon-green.png",
"css": ["<base_url>themes/daux-green/css/daux-green.css"], "css": ["<theme_url>css/daux-green.css"],
"fonts": ["//fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,cyrillic-ext,cyrillic"], "fonts": ["//fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,cyrillic-ext,cyrillic"],
"js": [], "js": [],
"require-jquery": true, "require-jquery": true,

View File

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,6 +1,6 @@
{ {
"favicon": "<base_url>themes/daux-navy/img/favicon-navy.png", "favicon": "<theme_url>img/favicon-navy.png",
"css": ["<base_url>themes/daux-navy/css/daux-navy.css"], "css": ["<theme_url>css/daux-navy.css"],
"fonts": ["//fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,cyrillic-ext,cyrillic"], "fonts": ["//fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,cyrillic-ext,cyrillic"],
"js": [], "js": [],
"require-jquery": true, "require-jquery": true,

View File

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,6 +1,6 @@
{ {
"favicon": "<base_url>themes/daux-red/img/favicon-red.png", "favicon": "<theme_url>img/favicon-red.png",
"css": ["<base_url>themes/daux-red/css/daux-red.css"], "css": ["<theme_url>css/daux-red.css"],
"fonts": ["//fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,cyrillic-ext,cyrillic"], "fonts": ["//fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700&subset=latin,cyrillic-ext,cyrillic"],
"js": [], "js": [],
"require-jquery": true, "require-jquery": true,

View File

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB