Changeset 1792 for trunk/wp-admin/admin-functions.php
- Timestamp:
- 10/14/2004 03:54:57 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-functions.php
r1758 r1792 549 549 } 550 550 551 function get_theme_data($theme_file) {552 $theme_data = implode('', file($theme_file));553 preg_match("|Theme Name:(.*)|i", $theme_data, $theme_name);554 preg_match("|Theme URI:(.*)|i", $theme_data, $theme_uri);555 preg_match("|Description:(.*)|i", $theme_data, $description);556 preg_match("|Author:(.*)|i", $theme_data, $author_name);557 preg_match("|Author URI:(.*)|i", $theme_data, $author_uri);558 preg_match("|Template:(.*)|i", $theme_data, $template);559 if ( preg_match("|Version:(.*)|i", $theme_data, $version) )560 $version = $version[1];561 else562 $version ='';563 564 $description = wptexturize($description[1]);565 566 $name = $theme_name[1];567 $name = trim($name);568 $theme = $name;569 if ('' != $theme_uri[1] && '' != $name) {570 $theme = __("<a href='{$theme_uri[1]}' title='Visit theme homepage'>{$theme}</a>");571 }572 573 if ('' == $author_uri[1]) {574 $author = $author_name[1];575 } else {576 $author = __("<a href='{$author_uri[1]}' title='Visit author homepage'>{$author_name[1]}</a>");577 }578 579 return array('Name' => $name, 'Title' => $theme, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]);580 }581 582 function get_themes() {583 $themes = array();584 $theme_loc = 'wp-content/themes';585 $theme_root = ABSPATH . $theme_loc;586 587 // Files in wp-content/themes directory588 $themes_dir = @ dir($theme_root);589 if ($themes_dir) {590 while(($theme_dir = $themes_dir->read()) !== false) {591 if (is_dir($theme_root . '/' . $theme_dir)) {592 $stylish_dir = @ dir($theme_root . '/' . $theme_dir);593 while(($theme_file = $stylish_dir->read()) !== false) {594 if ( $theme_file == 'style.css' ) {595 $theme_files[] = $theme_dir . '/' . $theme_file;596 }597 }598 }599 }600 }601 602 $default_files = array(get_settings('blogfilename'), 'wp-comments.php', 'wp-comments-popup.php', 'wp-comments-post.php', 'wp-footer.php', 'wp-header.php', 'wp-sidebar.php', 'footer.php', 'header.php', 'sidebar.php');603 604 // Get the files for the default template.605 $default_template_files = array();606 {607 $dirs = array('', 'wp-content');608 foreach ($dirs as $dir) {609 $template_dir = @ dir(ABSPATH . $dir);610 while(($file = $template_dir->read()) !== false) {611 if ( !preg_match('|^\.+$|', $file) && in_array($file, $default_files))612 $default_template_files[] = trim("$dir/$file", '/');613 }614 }615 }616 617 // Get the files for the default stylesheet.618 $default_stylesheet_files = array();619 {620 $stylesheet_dir = @ dir(ABSPATH);621 while(($file = $stylesheet_dir->read()) !== false) {622 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file))623 $default_stylesheet_files[] = "$file";624 }625 }626 627 // The default theme always exists.628 $themes['Default'] = array('Name' => 'Default', 'Title' => 'WordPress Default', 'Description' => 'The default theme included with WordPress.', 'Author' => 'Dave Shea', 'Version' => '1.3', 'Template' => 'default', 'Stylesheet' => 'default', 'Template Files' => $default_template_files, 'Stylesheet Files' => $default_stylesheet_files, 'Template Dir' => '/', 'Stylesheet Dir' => '/', 'Parent Theme' => '');629 630 if (!$themes_dir || !$theme_files) {631 return $themes;632 }633 634 sort($theme_files);635 636 foreach($theme_files as $theme_file) {637 $theme_data = get_theme_data("$theme_root/$theme_file");638 639 $name = $theme_data['Name'];640 $title = $theme_data['Title'];641 $description = wptexturize($theme_data['Description']);642 $version = $theme_data['Version'];643 $author = $theme_data['Author'];644 $template = $theme_data['Template'];645 $stylesheet = dirname($theme_file);646 647 if (empty($template)) {648 if (file_exists(dirname("$theme_root/$theme_file/index.php"))) {649 $template = dirname($theme_file);650 } else {651 continue;652 }653 }654 655 $template = trim($template);656 657 if (($template != 'default') && (! file_exists("$theme_root/$template/index.php"))) {658 continue;659 }660 661 if (empty($name)) {662 $name = dirname($theme_file);663 $title = $name;664 }665 666 $stylesheet_files = array();667 if ($stylesheet != 'default') {668 $stylesheet_dir = @ dir("$theme_root/$stylesheet");669 if ($stylesheet_dir) {670 while(($file = $stylesheet_dir->read()) !== false) {671 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )672 $stylesheet_files[] = "$theme_loc/$stylesheet/$file";673 }674 }675 } else {676 $stylesheet_files = $default_stylesheet_files;677 }678 679 $template_files = array();680 if ($template != 'default') {681 $template_dir = @ dir("$theme_root/$template");682 if ($template_dir) {683 while(($file = $template_dir->read()) !== false) {684 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )685 $template_files[] = "$theme_loc/$template/$file";686 }687 }688 } else {689 $template_files = $default_template_files;690 }691 692 $template_dir = dirname($template_files[0]);693 $stylesheet_dir = dirname($stylesheet_files[0]);694 695 if (empty($template_dir)) $template_dir = '/';696 if (empty($stylesheet_dir)) $stylesheet_dir = '/';697 698 $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);699 }700 701 // Resolve theme dependencies.702 $theme_names = array_keys($themes);703 704 foreach ($theme_names as $theme_name) {705 $themes[$theme_name]['Parent Theme'] = '';706 if ($themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template']) {707 foreach ($theme_names as $parent_theme_name) {708 if (($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template'])) {709 $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];710 break;711 }712 }713 }714 }715 716 return $themes;717 }718 719 function get_current_theme() {720 $themes = get_themes();721 $theme_names = array_keys($themes);722 $current_template = get_settings('template');723 $current_stylesheet = get_settings('stylesheet');724 $current_theme = 'Default';725 726 if ($themes) {727 foreach ($theme_names as $theme_name) {728 if ($themes[$theme_name]['Stylesheet'] == $current_stylesheet &&729 $themes[$theme_name]['Template'] == $current_template) {730 $current_theme = $themes[$theme_name]['Name'];731 }732 }733 }734 735 return $current_theme;736 }737 738 551 function validate_current_theme() { 739 552 $theme_loc = 'wp-content/themes';
Note: See TracChangeset
for help on using the changeset viewer.