Make WordPress Core

Changeset 2044


Ignore:
Timestamp:
01/04/2005 10:46:45 PM (20 years ago)
Author:
rboren
Message:

Recommit disappearing changes.

File:
1 edited

Legend:

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

    r2037 r2044  
    22
    33require_once(dirname(__FILE__) . '/upgrade-schema.php');
     4require_once(dirname(__FILE__) . '/admin-functions.php');
    45// Functions to be called in install and upgrade scripts
    56function upgrade_all() {
     
    528529}
    529530
    530 // Create a site theme from the default theme.
    531 function make_site_theme() {
    532     // Name the theme after the blog.
    533     $site = get_option('blogname');
    534     $template = sanitize_title($site);
     531function make_site_theme_from_oldschool($theme_name, $template) {
     532    $home_path = get_home_path();
    535533    $site_dir = ABSPATH . "wp-content/themes/$template";
    536534
    537     // If the theme already exists, nothing to do.
    538     if ( is_dir($site_dir)) {
    539         return;
    540     }
    541 
    542     // We must be able to write to the themes dir.
    543     if (! is_writable(ABSPATH . "wp-content/themes")) {
    544         return;
    545     }
    546 
    547     if (! mkdir($site_dir, 0777)) {
    548         return;
    549     }
    550 
    551     // Copy files from the default theme to the new site theme.
    552     // TODO: Copy wp-* template files from the blog root when upgrading from
    553     //       pre-theme releases.
     535    if (! file_exists("$home_path/index.php"))
     536        return false;
     537
     538    // Copy files from the old locations to the site theme.
     539    // TODO: This does not copy arbitarary include dependencies.  Only the
     540    // standard WP files are copied.
     541    $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
     542
     543    foreach ($files as $oldfile => $newfile) {
     544        if ($oldfile == 'index.php')
     545            $oldpath = $home_path;
     546        else
     547            $oldpath = ABSPATH;
     548
     549        if (! copy("$oldpath/$oldfile", "$site_dir/$newfile"))
     550            return false;
     551
     552        chmod("$site_dir/$newfile", 0777);
     553
     554        // Update the blog header include in each file.
     555        $lines = explode("\n", implode('', file("$site_dir/$newfile")));
     556        if ($lines) {
     557            $f = fopen("$site_dir/$newfile", 'w');
     558           
     559            foreach ($lines as $line) {
     560                if (preg_match('/require.*wp-blog-header/', $line)) {
     561                    if ($newfile == 'comments-popup.php')
     562                        $line = "require('../../../wp-blog-header.php');";
     563                    else
     564                        $line = '//' . $line;
     565                }
     566                fwrite($f, "{$line}\n");
     567            }
     568            fclose($f);
     569        }
     570    }
     571
     572    // Add a theme header.
     573    $header = "/*\nTheme Name: $theme_name\nTheme URI: " . get_option('siteurl') . "\nDescription: Your theme.\nVersion: 1\nAuthor: You\n*/\n";
     574
     575    $stylelines = file_get_contents("$site_dir/style.css");
     576    if ($stylelines) {
     577        $f = fopen("$site_dir/style.css", 'w');
     578
     579        fwrite($f, $header);
     580        fwrite($f, $stylelines);
     581        fclose($f);
     582    }
     583
     584    return true;
     585}
     586
     587function make_site_theme_from_default($theme_name, $template) {
     588    $site_dir = ABSPATH . "wp-content/themes/$template";
    554589    $default_dir = ABSPATH . 'wp-content/themes/default';
     590
     591// Copy files from the default theme to the site theme.
    555592    $files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
    556593
    557594    foreach ($files as $file) {
    558         if (! copy("$default_dir/$file", "$site_dir/$file")) {
     595        if (! copy("$default_dir/$file", "$site_dir/$file"))
    559596            return;
    560         }
    561597
    562598        chmod("$site_dir/$file", 0777);
     
    569605
    570606        foreach ($stylelines as $line) {
    571             if (strstr($line, "Theme Name:")) $line = "Theme Name: $site";
     607            if (strstr($line, "Theme Name:")) $line = "Theme Name: $theme_name";
    572608            elseif (strstr($line, "Theme URI:")) $line = "Theme URI: " . get_option('siteurl');
    573609            elseif (strstr($line, "Description:")) $line = "Description: Your theme";
     
    578614        fclose($f);
    579615    }
     616}
     617
     618// Create a site theme from the default theme.
     619function make_site_theme() {
     620    // Name the theme after the blog.
     621    $theme_name = get_option('blogname');
     622    $template = sanitize_title($theme_name);
     623    $site_dir = ABSPATH . "wp-content/themes/$template";
     624
     625    // If the theme already exists, nothing to do.
     626    if ( is_dir($site_dir)) {
     627        return false;
     628    }
     629
     630    // We must be able to write to the themes dir.
     631    if (! is_writable(ABSPATH . "wp-content/themes")) {
     632        return false;
     633    }
     634
     635    if (! mkdir($site_dir, 0777)) {
     636        return false;
     637    }
     638
     639    if (file_exists(ABSPATH . 'wp-layout.css')) {
     640        if (! make_site_theme_from_oldschool($theme_name, $template)) {
     641            // TODO:  rm -rf the site theme directory.
     642            return false;
     643        }
     644    } else {
     645        if (! make_site_theme_from_default($theme_name, $template))
     646            // TODO:  rm -rf the site theme directory.
     647            return false;
     648    }
    580649
    581650    // Make the new site theme active.
Note: See TracChangeset for help on using the changeset viewer.