theme = $theme; $this->init(); } function init() { $this->layouts(); $p = $this->get('drupalexp_presets'); $init_presets = 6; if (empty($p)) { $func = $this->theme . '_default_presets'; if (function_exists($func)) { $p = $func(); } } $this->presets = json_decode(base64_decode($p)); $infunc = $this->theme . '_init_presets'; if(function_exists($infunc)){ $init_presets = $infunc(); } $this->presets = array_slice($this->presets, 0, $init_presets); for($i=0; $i<$init_presets; $i++){ if(!isset($this->presets[$i])){ $newpreset = new stdClass(); $newpreset->key = 'Preset '.($i+1); $newpreset->base_color = '#666666'; $newpreset->base_color_opposite = '#666666'; $newpreset->link_color = '#666666'; $newpreset->link_hover_color = '#666666'; $newpreset->text_color = '#666666'; $newpreset->heading_color = '#666666'; $this->presets[] = $newpreset; } } if(module_exists('dexp_quicksettings')){ $this->style = isset($_SESSION['drupalexp_layout']) ? $_SESSION['drupalexp_layout'] : $this->get('drupalexp_layout'); $this->preset = isset($_SESSION['drupalexp_default_preset']) ? $_SESSION['drupalexp_default_preset'] : $this->get('drupalexp_default_preset'); $this->direction = isset($_SESSION['drupalexp_default_direction']) ? $_SESSION['drupalexp_default_direction'] : $this->get('drupalexp_direction'); }else{ $this->style = $this->get('drupalexp_layout'); $this->preset = $this->get('drupalexp_default_preset'); $this->direction = $this->get('drupalexp_direction'); } $this->setPresetVars(); $this->lessc = $this->getThemeInfo('lessc'); } function setPresetVars($preset = null) { if ($preset == null) { $preset = empty($this->preset)?0:$this->preset; } $default_preset = $this->presets[$preset]; if ($default_preset) { $this->lessc_vars['base_color'] = $default_preset->base_color; $this->lessc_vars['base_color_opposite'] = isset($default_preset->base_color_opposite)?$default_preset->base_color_opposite:$default_preset->base_color; $this->lessc_vars['link_color'] = $default_preset->link_color; $this->lessc_vars['link_hover_color'] = $default_preset->link_hover_color; $this->lessc_vars['text_color'] = $default_preset->text_color; $this->lessc_vars['heading_color'] = $default_preset->heading_color; } } function layouts() { $theme_regions = $this->getThemeInfo('regions'); $l = $this->get('drupalexp_layouts'); if (!empty($l)) { $this->layouts = json_decode(base64_decode($l)); $this->__addRegions(); $this->__removeRegions(); } else { $func = $this->theme . '_default_layouts'; if (function_exists($func)) { $default_layout = $func(); $this->layouts = json_decode(base64_decode($default_layout)); $this->__addRegions(); $this->__removeRegions(); return; } $theme_regions = $this->getThemeInfo('regions'); $regions = array(); $weight = 0; foreach ($theme_regions as $key => $title) { $region = new stdClass(); $region->key = $key; $region->title = $title; $region->size = 6; $regions[] = $region; } $unassignedsection = new stdClass(); $unassignedsection->key = 'unassigned'; $unassignedsection->title = 'Unassigned'; $unassignedsection->regions = $regions; $layout = new stdClass(); $layout->key = 'default'; $layout->title = 'Default'; $layout->sections = array($unassignedsection); $this->layouts = array($layout); } } function getRegions() { $themes = list_themes(); if (!empty($themes[$this->theme]->info['regions'])) { return $themes[$this->theme]->info['regions']; } return array(); } function get($key) { return theme_get_setting($key, $this->theme); } /* * * Retrieve content from .info file */ function getThemeInfo($key) { $themes = list_themes(); if (!empty($themes[$this->theme]->info[$key])) { return $themes[$this->theme]->info[$key]; } return array(); } private function __addRegions() { $theme_regions = $this->getThemeInfo('regions'); foreach ($theme_regions as $key => $title) { foreach ($this->layouts as $k => $layout) { $region_exists = false; $unassigned_section = 0; foreach ($layout->sections as $section_index => $section) { if ($section->key == 'unassigned') { $unassigned_section = $section_index; } foreach ($section->regions as $region_index => $region) { if (!isset($region->key)) { unset($section->regions[$region_index]); continue; } if ($region->key == $key) { //Update title $this->layouts[$k]->sections[$section_index]->regions[$region_index]->title = $title; $region_exists = true; } } $section->regions = array_values($section->regions); } if (!$region_exists) { $newregion = new stdClass(); $newregion->key = $key; $newregion->title = $title; $newregion->size = 6; $this->layouts[$k]->sections[$unassigned_section]->regions[] = $newregion; } } } } private function __removeRegions() { $theme_regions = $this->getThemeInfo('regions'); $theme_regions_keys = array(); foreach ($theme_regions as $key => $region) { $theme_regions_keys[] = $key; } foreach ($this->layouts as $k => $layout) { $region_exists = false; foreach ($layout->sections as $section_index => $section) { foreach ($section->regions as $region_index => $region) { if (!in_array($region->key, $theme_regions_keys)) { unset($this->layouts[$k]->sections[$section_index]->regions[$region_index]); } } $this->layouts[$k]->sections[$section_index]->regions = array_values($this->layouts[$k]->sections[$section_index]->regions); } } } function pageRender($ajax = false) { if($ajax){ return render($this->page['page']['content']); } $this->layout = $this->get_layout(); if (!isset($this->layouts[$this->layout])) { $this->layout = 0; } $html = ""; foreach ($this->layouts[$this->layout]->sections as $section) { $html .= $this->sectionRender($section); } return '