= 86400) {
if (1) { //debugging
$theme_default= variable_get('theme_default', 'bluemarine');
$res = db_query('SELECT * FROM {blocks} WHERE theme LIKE \'%s\'', $theme_default);
db_query('DELETE FROM {blocks}');
while ($block = db_fetch_object($res)) {
$defaults[$block->module .'-'. $block->delta] = $block;
}
foreach (list_themes() as $key => $theme) {
foreach ($defaults as $block) {
db_query("INSERT INTO {blocks} (
module,
delta,
theme,
status,
weight,
region,
custom,
throttle,
visibility,
pages
) VALUES (
'%s',
'%s',
'%s',
%d,
%d,
'%s',
%d,
%d,
%d,
'%s')",
$block->module,
$block->delta,
$key,
$block->status,
$block->weight,
$block->region,
$block->custom,
$block->throttle,
$block->visibility,
$block->pages
);
}
}
variable_set('statistics_day_timestamp', time());
}
}
function themeswitcher_block($op = 'list', $delta = 0) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Random theme');
$blocks[1]['info'] = t('Theme browser');
return $blocks;
break;
case 'view':
if ($delta == 0) {
$block['subject'] = t('Random theme');
$block['content'] = themeswitcher_display_random_block();
}
elseif ($delta == 1) {
$block['subject'] = t('Browse themes');
$block['content'] = themeswitcher_display_nextprev_block();
}
return $block;
break;
case 'default':
break;
}
}
function themeswitcher_display_random_block() {
$themes = list_themes();
shuffle($themes);
foreach ($themes as $key => $theme) {
$theme->screenshot = dirname($theme->filename) . '/screenshot.png';
if (file_exists($theme->screenshot)) { //return the first one with a screenie
$output = l("screenshot\" alt=\"preview of $theme->name\"/>", $_GET['q'], NULL, 'theme='.$theme->name, NULL, FALSE, TRUE);
return $output;
}
}
}
function themeswitcher_display_nextprev_block() {
global $custom_theme, $user;
$themes = list_themes();
ksort($themes);
$i = 0;
foreach ($themes as $key => $theme) {
$themes[$key]->screenshot = dirname($theme->filename) . '/screenshot.png';
// I need both a numerical and an associative array
$sort[$i] = $themes[$key];
$themes[$key]->order = $i;
$i++;
}
$count = count($themes) - 1; // offest for starting at zero
// assign the current theme as value of $custom_theme
if (!empty($custom_theme)) {
$current = $themes[$custom_theme];
}
else {
// if no theme, use the user default
if (empty($user->theme)) {
$conf = $GLOBALS['conf']['theme_default'];
}
else {
$conf = $user->theme;
}
$current = $themes[$conf];
}
// derive the next and previous from the order of $current
$pos = $current->order;
$next = $pos + 1;
$prev = $pos - 1;
if ($pos == $count) {
$next = 0;
$prev = $pos - 1;
}
elseif ($pos == 0) {
$next = $pos + 1;
$prev = $count;
}
$next_theme = $sort[$next];
$prev_theme = $sort[$prev];
// add the themes to the output
if (file_exists($prev_theme->screenshot)) {
$output = '
' . t('Previous theme') . '
';
$output .= l("screenshot\" alt=\"preview of $prev_theme->name\" />", $_GET['q'], NULL, 'theme='. $prev_theme->name, NULL, FALSE, TRUE);
}
$output .= '
' . l('‹ '. $prev_theme->name, $_GET['q'], NULL, 'theme='. $prev_theme->name) . '
' . t('Next theme') . '
';
if (file_exists($next_theme->screenshot)) {
$output .= l("screenshot\" alt=\"preview of $next_theme->name\" />", $_GET['q'], NULL, 'theme='. $next_theme->name, NULL, FALSE, TRUE);
}
$output .= '
' . l($next_theme->name . ' ›', $_GET['q'], NULL, 'theme='. $next_theme->name) . '