Skip to content

Commit

Permalink
better theme selection
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Jul 7, 2012
1 parent 2d0d180 commit bd00660
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions Core/Themes/Controller/Component/ThemesComponent.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php
/*
/*
* Short Description / title.
*
*
* Overview of what the file does. About a paragraph or two
*
*
* Copyright (c) 2010 Carl Sutton ( dogmatic69 )
*
*
* @filesource
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package {see_below}
* @subpackage {see_below}
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since {check_current_milestone_in_lighthouse}
*
*
* @author {your_name}
*
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*/
Expand All @@ -24,29 +24,33 @@
class ThemesComponent extends InfinitasComponent {
public function beforeRender(Controller $Controller) {
parent::beforeRender($Controller);

if($Controller->layout == 'ajax') {
return;
}

if(!empty($Controller->viewVars['error']) && $Controller->viewVars['error'] instanceof Exception) {
$error = $Controller->viewVars['error'];
unset($Controller->viewVars['error']);
}

$layout = array_values($Controller->viewVars);
$theme = current(Set::extract('/Layout/theme_id', $layout));
$layout = current(Set::extract('/Layout/layout', $layout));

$tmp = current(Set::extract('/Layout/layout', $layout));
if(empty($tmp)) {
$tmp = current(Set::extract('/GlobalLayout/layout', $layout));
}
$layout = $tmp;

if(!empty($error)) {
$Controller->viewVars['error'] = $error;
$layout = 'error';
}

if($layout) {
Configure::write('Themes.default_layout', $layout);
}

$event = $Controller->Event->trigger($Controller->plugin . '.setupThemeStart');
if (isset($event['setupThemeStart'][$Controller->plugin])) {
if (is_string($event['setupThemeStart'][$Controller->plugin])) {
Expand All @@ -58,13 +62,13 @@ public function beforeRender(Controller $Controller) {
return false;
}
}

$Controller->layout = Configure::read('Themes.default_layout');
$theme = Cache::read('currentTheme');
if($theme === false) {
$theme = ClassRegistry::init('Themes.Theme')->getCurrentTheme();
}

if(!empty($theme['Theme']['default_layout'])) {
$Controller->layout = $theme['Theme']['default_layout'];
}
Expand All @@ -80,7 +84,7 @@ public function beforeRender(Controller $Controller) {
'params' => $Controller->request->params
)
);

if (isset($event['setupThemeLayout'][$Controller->plugin]) && is_string($event['setupThemeLayout'][$Controller->plugin])) {
$Controller->layout = $event['setupThemeLayout'][$Controller->plugin];
}
Expand All @@ -96,7 +100,7 @@ public function beforeRender(Controller $Controller) {
'params' => $Controller->request->params
)
);

if (isset($event['setupThemeSelector'][$Controller->plugin])) {
if (is_array($event['setupThemeSelector'][$Controller->plugin])) {
$theme['Theme'] = $event['setupThemeSelector'][$Controller->plugin];
Expand All @@ -106,7 +110,7 @@ public function beforeRender(Controller $Controller) {
}
}
}

$Controller->theme = $theme['Theme']['name'];
Configure::write('Theme', $theme['Theme']);

Expand All @@ -126,7 +130,7 @@ public function beforeRender(Controller $Controller) {
if(!empty($route['Route']['theme'])) {
$Controller->theme = $route['Route']['theme'];
}

if(!empty($route['Route']['layout'])) {
$Controller->layout = $route['Route']['layout'];
}
Expand All @@ -143,12 +147,12 @@ public function beforeRender(Controller $Controller) {

return true;
}

public function actionAdminGetThemeLayouts() {
if(empty($this->Controller->request->data[$this->Controller->modelClass]['theme_id'])) {
$this->Controller->set('json', false);
}

$this->Controller->set('json', InfinitasTheme::layouts($this->Controller->request->data[$this->Controller->modelClass]['theme_id']));
}
}

0 comments on commit bd00660

Please sign in to comment.