### Eclipse Workspace Patch 1.0
#P wordpress-trunk bare
|
|
|
|
| 1695 | 1695 | |
| 1696 | 1696 | // Copy files from the default theme to the site theme. |
| 1697 | 1697 | //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css'); |
| | 1698 | |
| | 1699 | if( ! @make_directory_file_copy( $default_dir, $site_dir ) ) |
| | 1700 | return; |
| 1698 | 1701 | |
| 1699 | | $theme_dir = @ opendir($default_dir); |
| 1700 | | if ($theme_dir) { |
| 1701 | | while(($theme_file = readdir( $theme_dir )) !== false) { |
| 1702 | | if (is_dir("$default_dir/$theme_file")) |
| 1703 | | continue; |
| 1704 | | if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file")) |
| 1705 | | return; |
| 1706 | | chmod("$site_dir/$theme_file", 0777); |
| 1707 | | } |
| 1708 | | } |
| 1709 | | @closedir($theme_dir); |
| 1710 | | |
| 1711 | 1702 | // Rewrite the theme header. |
| 1712 | | $stylelines = explode("\n", implode('', file("$site_dir/style.css"))); |
| 1713 | | if ($stylelines) { |
| 1714 | | $f = fopen("$site_dir/style.css", 'w'); |
| | 1703 | $stylelines = file( "$site_dir/style.css", FILE_IGNORE_NEW_LINES ); |
| | 1704 | if ( $stylelines ) { |
| | 1705 | $headers = array( |
| | 1706 | 'Theme Name:' => $theme_name, |
| | 1707 | 'Theme URI:' => __get_option( 'url' ), |
| | 1708 | 'Description:' => 'Your theme.', |
| | 1709 | 'Version:' => '1', |
| | 1710 | 'Author:' => 'You' |
| | 1711 | ); |
| 1715 | 1712 | |
| 1716 | | foreach ($stylelines as $line) { |
| 1717 | | if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name; |
| 1718 | | elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url'); |
| 1719 | | elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.'; |
| 1720 | | elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1'; |
| 1721 | | elseif (strpos($line, 'Author:') !== false) $line = 'Author: You'; |
| 1722 | | fwrite($f, $line . "\n"); |
| | 1713 | foreach ( $stylelines as &$line ) { |
| | 1714 | foreach ( $headers as $header => $value ) { |
| | 1715 | if ( false === strpos( $line, $header ) ) |
| | 1716 | continue; |
| | 1717 | $line = $header . ' ' . $value; |
| | 1718 | break; |
| | 1719 | } |
| 1723 | 1720 | } |
| 1724 | | fclose($f); |
| | 1721 | |
| | 1722 | file_put_contents( "$site_dir/style.css", implode( "\n", $stylelines ) ); |
| 1725 | 1723 | } |
| 1726 | 1724 | |
| 1727 | 1725 | // Copy the images. |
| … |
… |
|
| 1730 | 1728 | return false; |
| 1731 | 1729 | } |
| 1732 | 1730 | |
| 1733 | | $images_dir = @ opendir("$default_dir/images"); |
| 1734 | | if ($images_dir) { |
| 1735 | | while(($image = readdir($images_dir)) !== false) { |
| 1736 | | if (is_dir("$default_dir/images/$image")) |
| | 1731 | @make_directory_file_copy( "$default_dir/images", "$site_dir/images" ); |
| | 1732 | } |
| | 1733 | |
| | 1734 | /** |
| | 1735 | * Copy files from origin directory into target directory |
| | 1736 | * and set their mode to 0777. |
| | 1737 | * |
| | 1738 | * @param $origin string Directory to copy files from |
| | 1739 | * @param $target string Directory to copy files to |
| | 1740 | * @return bool false if unable to copy one of the files |
| | 1741 | */ |
| | 1742 | function make_directory_file_copy($origin, $target, $mode = 0777) { |
| | 1743 | if ( $handle = opendir( $origin ) ) { |
| | 1744 | while( $file = readdir( $handle ) ) { |
| | 1745 | $path_from = "$origin/$file"; |
| | 1746 | if ( is_dir( $path_from ) ) |
| 1737 | 1747 | continue; |
| 1738 | | if (! @copy("$default_dir/images/$image", "$site_dir/images/$image")) |
| 1739 | | return; |
| 1740 | | chmod("$site_dir/images/$image", 0777); |
| | 1748 | $path_to = "$target/$file"; |
| | 1749 | if ( ! copy( $path_from, $path_to ) ) |
| | 1750 | return false; |
| | 1751 | chmod( $path_to , $mode ); |
| 1741 | 1752 | } |
| | 1753 | closedir( $handle ); |
| 1742 | 1754 | } |
| 1743 | | @closedir($images_dir); |
| | 1755 | return true; |
| 1744 | 1756 | } |
| 1745 | 1757 | |
| 1746 | 1758 | // Create a site theme from the default theme. |