WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/14/2004 06:19:50 AM (17 years ago)
Author:
rboren
Message:

Refactor some theme code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r1638 r1643  
    566566   
    567567    // The default theme always exists.
    568     $themes['Default'] = array('Name' => 'Default', 'Title' => 'Default', 'Description' => 'The default theme', 'Author' => '', 'Version' => '1.3', 'Template' => 'default', 'Stylesheet' => 'default', 'Template Files' => $default_template_files, 'Stylesheet Files' => $default_stylesheet_files);
     568    $themes['Default'] = array('Name' => 'Default', 'Title' => 'Default', 'Description' => 'The default theme', 'Author' => '', 'Version' => '1.3', 'Template' => 'default', 'Stylesheet' => 'default', 'Template Files' => $default_template_files, 'Stylesheet Files' => $default_stylesheet_files, 'Template Dir' => '/', 'Stylesheet Dir' => '/', 'Parent Theme' => '');
    569569
    570570    if (!$themes_dir || !$theme_files) {
     
    630630        }
    631631
    632         $themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files);
     632        $template_dir = dirname($template_files[0]);
     633        $stylesheet_dir = dirname($stylesheet_files[0]);
     634
     635        if (empty($template_dir)) $template_dir = '/';
     636        if (empty($stylesheet_dir)) $stylesheet_dir = '/';
     637       
     638        $themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files, 'Template Dir' => $template_dir, 'Stylesheet Dir' => $stylesheet_dir);
     639    }
     640
     641    // Resolve theme dependencies.
     642    $theme_names = array_keys($themes);
     643
     644    foreach ($theme_names as $theme_name) {
     645        $themes[$theme_name]['Parent Theme'] = '';
     646        if ($themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template']) {
     647            foreach ($theme_names as $parent_theme_name) {
     648                if (($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template'])) {
     649                    $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
     650                    break;
     651                }
     652            }
     653        }
    633654    }
    634655
     
    636657}
    637658
     659function get_current_theme() {
     660    $themes = get_themes();
     661    $theme_names = array_keys($themes);
     662    $current_template = get_settings('template');
     663    $current_stylesheet = get_settings('stylesheet');
     664    $current_theme = 'Default';
     665
     666    if ($themes) {
     667        foreach ($theme_names as $theme_name) {
     668            if ($themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
     669                    $themes[$theme_name]['Template'] == $current_template) {
     670                $current_theme = $themes[$theme_name]['Name'];
     671            }
     672        }
     673    }
     674
     675    return $current_theme;
     676}
     677
    638678?>
Note: See TracChangeset for help on using the changeset viewer.