- Patch by Nedjo: block regions were not initiated for newly enabled themes.

4.7.x
Dries Buytaert 2005-08-28 18:17:47 +00:00
parent 8f71d8990e
commit 469fa36420
2 changed files with 48 additions and 40 deletions

View File

@ -373,39 +373,41 @@ function system_theme_data() {
/** /**
* Get a list of available regions from a specified theme. * Get a list of available regions from a specified theme.
* *
* @param $theme * @param $theme_key
* The name of a theme. * The name of a theme.
* @return * @return
* An array of regions in the form $region['name'] = 'description'. * An array of regions in the form $region['name'] = 'description'.
*/ */
function system_region_list($theme) { function system_region_list($theme_key) {
static $list = array(); static $list = array();
if(!array_key_exists($theme, $list)) { if(!array_key_exists($theme_key, $list)) {
$themes = list_themes(); $result = db_query("SELECT * FROM {system} WHERE type = 'theme' AND name = '%s'", $theme_key);
$theme = db_fetch_object($result);
if (strpos($themes[$theme]->filename, '.css')) { if (strpos($theme->filename, '.css')) {
// File is a style, which can't have its own regions; use its theme instead. // File is a style, which can't have its own regions; use its theme instead.
$theme = basename(dirname($themes[$theme]->description)); $list[$theme_key] = system_region_list(basename(dirname($theme->description)));
return $list[$theme_key];
} }
if (file_exists($file = dirname($themes[$theme]->filename) .'/' . $themes[$theme]->name . '.theme')) { if (file_exists($file = dirname($theme->filename) .'/' . $theme_key . '.theme')) {
include_once($file); include_once($file);
} }
$regions = function_exists($theme . '_regions') ? call_user_func($theme . '_regions') : array(); $regions = function_exists($theme_key . '_regions') ? call_user_func($theme_key . '_regions') : array();
if (strpos($themes[$theme]->description, '.engine')) { if (strpos($theme->description, '.engine')) {
// File is a template; include its engine's regions. // File is a template; include its engine's regions.
include_once($themes[$theme]->description); include_once($theme->description);
$theme_engine = basename($themes[$theme]->description, '.engine'); $theme_engine = basename($theme->description, '.engine');
$engine_regions = function_exists($theme_engine . '_regions') ? call_user_func($theme_engine . '_regions') : array(); $engine_regions = function_exists($theme_engine . '_regions') ? call_user_func($theme_engine . '_regions') : array();
$regions = array_merge($engine_regions, $regions); $regions = array_merge($engine_regions, $regions);
} }
$list[$theme] = $regions; $list[$theme_key] = $regions;
} }
return $list[$theme]; return $list[$theme_key];
} }
/** /**
@ -560,7 +562,7 @@ function system_listing_save($edit = array()) {
$status = 1; $status = 1;
} }
// If status is being set to 1 from 0, initialize block data for this theme if necessary. // If status is being set to 1 from 0, initialize block data for this theme if necessary.
if (($status == 1) && db_num_rows(db_query("SELECT status FROM {system} WHERE type = '%s' AND name = '%s' AND status = 0", $edit['type'], $name))) { if (($edit['type'] == 'theme') && ($status == 1) && db_num_rows(db_query("SELECT status FROM {system} WHERE type = '%s' AND name = '%s' AND status = 0", $edit['type'], $name))) {
system_initialize_theme_blocks($name); system_initialize_theme_blocks($name);
} }
@ -578,19 +580,21 @@ function system_listing_save($edit = array()) {
} }
} }
/** /**
* Assign an initial, default set of blocks for a theme. This function is called the first * Assign an initial, default set of blocks for a theme.
* time a new theme is enabled. The new theme gets a copy of the default theme's blocks, *
* with the difference that if a particular region isn't available in the new theme, the block * This function is called the first time a new theme is enabled. The new theme
* is assigned instead to the new theme's default region. * gets a copy of the default theme's blocks, with the difference that if a
* particular region isn't available in the new theme, the block is assigned
* to the new theme's default region.
* *
* @param $theme * @param $theme
* The name of a theme. * The name of a theme.
*/ */
function system_initialize_theme_blocks($theme) { function system_initialize_theme_blocks($theme) {
$default_theme = variable_get('theme_default', 'bluemarine');
$regions = system_region_list($theme);
// Initialize theme's blocks if none already registered. // Initialize theme's blocks if none already registered.
if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) { if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) {
$default_theme = variable_get('theme_default', 'bluemarine');
$regions = system_region_list($theme);
$result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme); $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
while($block = db_fetch_array($result)) { while($block = db_fetch_array($result)) {
// If the region isn't supported by the theme, assign the block to the theme's default region. // If the region isn't supported by the theme, assign the block to the theme's default region.

View File

@ -373,39 +373,41 @@ function system_theme_data() {
/** /**
* Get a list of available regions from a specified theme. * Get a list of available regions from a specified theme.
* *
* @param $theme * @param $theme_key
* The name of a theme. * The name of a theme.
* @return * @return
* An array of regions in the form $region['name'] = 'description'. * An array of regions in the form $region['name'] = 'description'.
*/ */
function system_region_list($theme) { function system_region_list($theme_key) {
static $list = array(); static $list = array();
if(!array_key_exists($theme, $list)) { if(!array_key_exists($theme_key, $list)) {
$themes = list_themes(); $result = db_query("SELECT * FROM {system} WHERE type = 'theme' AND name = '%s'", $theme_key);
$theme = db_fetch_object($result);
if (strpos($themes[$theme]->filename, '.css')) { if (strpos($theme->filename, '.css')) {
// File is a style, which can't have its own regions; use its theme instead. // File is a style, which can't have its own regions; use its theme instead.
$theme = basename(dirname($themes[$theme]->description)); $list[$theme_key] = system_region_list(basename(dirname($theme->description)));
return $list[$theme_key];
} }
if (file_exists($file = dirname($themes[$theme]->filename) .'/' . $themes[$theme]->name . '.theme')) { if (file_exists($file = dirname($theme->filename) .'/' . $theme_key . '.theme')) {
include_once($file); include_once($file);
} }
$regions = function_exists($theme . '_regions') ? call_user_func($theme . '_regions') : array(); $regions = function_exists($theme_key . '_regions') ? call_user_func($theme_key . '_regions') : array();
if (strpos($themes[$theme]->description, '.engine')) { if (strpos($theme->description, '.engine')) {
// File is a template; include its engine's regions. // File is a template; include its engine's regions.
include_once($themes[$theme]->description); include_once($theme->description);
$theme_engine = basename($themes[$theme]->description, '.engine'); $theme_engine = basename($theme->description, '.engine');
$engine_regions = function_exists($theme_engine . '_regions') ? call_user_func($theme_engine . '_regions') : array(); $engine_regions = function_exists($theme_engine . '_regions') ? call_user_func($theme_engine . '_regions') : array();
$regions = array_merge($engine_regions, $regions); $regions = array_merge($engine_regions, $regions);
} }
$list[$theme] = $regions; $list[$theme_key] = $regions;
} }
return $list[$theme]; return $list[$theme_key];
} }
/** /**
@ -560,7 +562,7 @@ function system_listing_save($edit = array()) {
$status = 1; $status = 1;
} }
// If status is being set to 1 from 0, initialize block data for this theme if necessary. // If status is being set to 1 from 0, initialize block data for this theme if necessary.
if (($status == 1) && db_num_rows(db_query("SELECT status FROM {system} WHERE type = '%s' AND name = '%s' AND status = 0", $edit['type'], $name))) { if (($edit['type'] == 'theme') && ($status == 1) && db_num_rows(db_query("SELECT status FROM {system} WHERE type = '%s' AND name = '%s' AND status = 0", $edit['type'], $name))) {
system_initialize_theme_blocks($name); system_initialize_theme_blocks($name);
} }
@ -578,19 +580,21 @@ function system_listing_save($edit = array()) {
} }
} }
/** /**
* Assign an initial, default set of blocks for a theme. This function is called the first * Assign an initial, default set of blocks for a theme.
* time a new theme is enabled. The new theme gets a copy of the default theme's blocks, *
* with the difference that if a particular region isn't available in the new theme, the block * This function is called the first time a new theme is enabled. The new theme
* is assigned instead to the new theme's default region. * gets a copy of the default theme's blocks, with the difference that if a
* particular region isn't available in the new theme, the block is assigned
* to the new theme's default region.
* *
* @param $theme * @param $theme
* The name of a theme. * The name of a theme.
*/ */
function system_initialize_theme_blocks($theme) { function system_initialize_theme_blocks($theme) {
$default_theme = variable_get('theme_default', 'bluemarine');
$regions = system_region_list($theme);
// Initialize theme's blocks if none already registered. // Initialize theme's blocks if none already registered.
if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) { if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) {
$default_theme = variable_get('theme_default', 'bluemarine');
$regions = system_region_list($theme);
$result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme); $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
while($block = db_fetch_array($result)) { while($block = db_fetch_array($result)) {
// If the region isn't supported by the theme, assign the block to the theme's default region. // If the region isn't supported by the theme, assign the block to the theme's default region.