Make WordPress Core

Ticket #2525: theme-funcs.diff

File theme-funcs.diff, 24.1 KB (added by ryan, 19 years ago)

Moves template, stylesheet, theme fxns to theme.php

  • wp-includes/theme.php

     
     1<?php
     2/*
     3 * Theme/template/stylesheet functions. 
     4 */
     5
     6function get_stylesheet() {
     7        return apply_filters('stylesheet', get_settings('stylesheet'));
     8}
     9
     10function get_stylesheet_directory() {
     11        $stylesheet = get_stylesheet();
     12        $stylesheet_dir = get_theme_root() . "/$stylesheet";
     13        return apply_filters('stylesheet_directory', $stylesheet_dir, $stylesheet);
     14}
     15
     16function get_stylesheet_directory_uri() {
     17        $stylesheet = rawurlencode( get_stylesheet() );
     18        $stylesheet_dir_uri = get_theme_root_uri() . "/$stylesheet";
     19        return apply_filters('stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet);
     20}
     21
     22function get_stylesheet_uri() {
     23        $stylesheet_dir_uri = get_stylesheet_directory_uri();
     24        $stylesheet_uri = $stylesheet_dir_uri . "/style.css";
     25        return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
     26}
     27
     28function get_template() {
     29        $template = get_settings('template');
     30        if (!file_exists(get_theme_root() . "/$template")) { //works for dirs too
     31                update_option('template', 'default');
     32                update_option('stylesheet', 'default');
     33        }
     34        return apply_filters('template', get_settings('template'));
     35}
     36
     37function get_template_directory() {
     38        $template = get_template();
     39        $template_dir = get_theme_root() . "/$template";
     40        return apply_filters('template_directory', $template_dir, $template);
     41}
     42
     43function get_template_directory_uri() {
     44        $template = get_template();
     45        $template_dir_uri = get_theme_root_uri() . "/$template";
     46        return apply_filters('template_directory_uri', $template_dir_uri, $template);
     47}
     48
     49function get_theme_data($theme_file) {
     50        $theme_data = implode('', file($theme_file));
     51        preg_match("|Theme Name:(.*)|i", $theme_data, $theme_name);
     52        preg_match("|Theme URI:(.*)|i", $theme_data, $theme_uri);
     53        preg_match("|Description:(.*)|i", $theme_data, $description);
     54        preg_match("|Author:(.*)|i", $theme_data, $author_name);
     55        preg_match("|Author URI:(.*)|i", $theme_data, $author_uri);
     56        preg_match("|Template:(.*)|i", $theme_data, $template);
     57        if ( preg_match("|Version:(.*)|i", $theme_data, $version) )
     58                $version = $version[1];
     59        else
     60                $version ='';
     61        if ( preg_match("|Status:(.*)|i", $theme_data, $status) )
     62                $status = $status[1];
     63        else
     64                $status ='publish';
     65
     66        $description = wptexturize($description[1]);
     67
     68        $name = $theme_name[1];
     69        $name = trim($name);
     70        $theme = $name;
     71
     72        if ( '' == $author_uri[1] ) {
     73                $author = $author_name[1];
     74        } else {
     75                $author = '<a href="' . $author_uri[1] . '" title="' . __('Visit author homepage') . '">' . $author_name[1] . '</a>';
     76        }
     77
     78        return array('Name' => $name, 'Title' => $theme, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1], 'Status' => $status);
     79}
     80
     81function get_themes() {
     82        global $wp_themes;
     83        global $wp_broken_themes;
     84
     85        if ( isset($wp_themes) )
     86                return $wp_themes;
     87
     88        $themes = array();
     89        $wp_broken_themes = array();
     90        $theme_root = get_theme_root();
     91        $theme_loc = str_replace(ABSPATH, '', $theme_root);
     92
     93        // Files in wp-content/themes directory
     94        $themes_dir = @ dir($theme_root);
     95        if ( $themes_dir ) {
     96                while(($theme_dir = $themes_dir->read()) !== false) {
     97                        if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
     98                                if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) {
     99                                        continue;
     100                                }
     101                                $stylish_dir = @ dir($theme_root . '/' . $theme_dir);
     102                                $found_stylesheet = false;
     103                                while (($theme_file = $stylish_dir->read()) !== false) {
     104                                        if ( $theme_file == 'style.css' ) {
     105                                                $theme_files[] = $theme_dir . '/' . $theme_file;
     106                                                $found_stylesheet = true;
     107                                                break;
     108                                        }
     109                                }
     110                                if ( !$found_stylesheet ) {
     111                                        $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
     112                                }
     113                        }
     114                }
     115        }
     116
     117        if ( !$themes_dir || !$theme_files ) {
     118                return $themes;
     119        }
     120
     121        sort($theme_files);
     122
     123        foreach($theme_files as $theme_file) {
     124                if ( ! is_readable("$theme_root/$theme_file") ) {
     125                        $wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
     126                        continue;
     127                }
     128
     129                $theme_data = get_theme_data("$theme_root/$theme_file");
     130
     131                $name = $theme_data['Name'];
     132                $title = $theme_data['Title'];
     133                $description = wptexturize($theme_data['Description']);
     134                $version = $theme_data['Version'];
     135                $author = $theme_data['Author'];
     136                $template = $theme_data['Template'];
     137                $stylesheet = dirname($theme_file);
     138
     139                foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) {
     140                        if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
     141                                $screenshot = "screenshot.$ext";
     142                                break;
     143                        }
     144                }
     145
     146                if ( empty($name) ) {
     147                        $name = dirname($theme_file);
     148                        $title = $name;
     149                }
     150
     151                if ( empty($template) ) {
     152                        if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) {
     153                                $template = dirname($theme_file);
     154                        } else {
     155                                continue;
     156                        }
     157                }
     158
     159                $template = trim($template);
     160
     161                if ( !file_exists("$theme_root/$template/index.php") ) {
     162                        $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
     163                        continue;
     164                }
     165
     166                $stylesheet_files = array();
     167                $stylesheet_dir = @ dir("$theme_root/$stylesheet");
     168                if ( $stylesheet_dir ) {
     169                        while(($file = $stylesheet_dir->read()) !== false) {
     170                                if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )
     171                                        $stylesheet_files[] = "$theme_loc/$stylesheet/$file";
     172                        }
     173                }
     174
     175                $template_files = array();
     176                $template_dir = @ dir("$theme_root/$template");
     177                if ( $template_dir ) {
     178                        while(($file = $template_dir->read()) !== false) {
     179                                if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
     180                                        $template_files[] = "$theme_loc/$template/$file";
     181                        }
     182                }
     183
     184                $template_dir = dirname($template_files[0]);
     185                $stylesheet_dir = dirname($stylesheet_files[0]);
     186
     187                if ( empty($template_dir) )
     188                        $template_dir = '/';
     189                if ( empty($stylesheet_dir) )
     190                        $stylesheet_dir = '/';
     191
     192                // Check for theme name collision.  This occurs if a theme is copied to
     193                // a new theme directory and the theme header is not updated.  Whichever
     194                // theme is first keeps the name.  Subsequent themes get a suffix applied.
     195                // The Default and Classic themes always trump their pretenders.
     196                if ( isset($themes[$name]) ) {
     197                        if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) &&
     198                                         ('default' == $stylesheet || 'classic' == $stylesheet) ) {
     199                                // If another theme has claimed to be one of our default themes, move
     200                                // them aside.
     201                                $suffix = $themes[$name]['Stylesheet'];
     202                                $new_name = "$name/$suffix";
     203                                $themes[$new_name] = $themes[$name];
     204                                $themes[$new_name]['Name'] = $new_name;
     205                        } else {
     206                                $name = "$name/$stylesheet";
     207                        }
     208                }
     209
     210                $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, 'Status' => $theme_data['Status'], 'Screenshot' => $screenshot);
     211        }
     212
     213        // Resolve theme dependencies.
     214        $theme_names = array_keys($themes);
     215
     216        foreach ($theme_names as $theme_name) {
     217                $themes[$theme_name]['Parent Theme'] = '';
     218                if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
     219                        foreach ($theme_names as $parent_theme_name) {
     220                                if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
     221                                        $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
     222                                        break;
     223                                }
     224                        }
     225                }
     226        }
     227
     228        $wp_themes = $themes;
     229
     230        return $themes;
     231}
     232
     233function get_theme($theme) {
     234        $themes = get_themes();
     235
     236        if ( array_key_exists($theme, $themes) )
     237                return $themes[$theme];
     238
     239        return NULL;
     240}
     241
     242function get_current_theme() {
     243        $themes = get_themes();
     244        $theme_names = array_keys($themes);
     245        $current_template = get_settings('template');
     246        $current_stylesheet = get_settings('stylesheet');
     247        $current_theme = 'WordPress Default';
     248
     249        if ( $themes ) {
     250                foreach ($theme_names as $theme_name) {
     251                        if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
     252                                        $themes[$theme_name]['Template'] == $current_template ) {
     253                                $current_theme = $themes[$theme_name]['Name'];
     254                                break;
     255                        }
     256                }
     257        }
     258
     259        return $current_theme;
     260}
     261
     262function get_theme_root() {
     263        return apply_filters('theme_root', ABSPATH . "wp-content/themes");
     264}
     265
     266function get_theme_root_uri() {
     267        return apply_filters('theme_root_uri', get_settings('siteurl') . "/wp-content/themes", get_settings('siteurl'));
     268}
     269
     270function get_query_template($type) {
     271        $template = '';
     272        if ( file_exists(TEMPLATEPATH . "/{$type}.php") )
     273                $template = TEMPLATEPATH . "/{$type}.php";
     274
     275        return apply_filters("{$type}_template", $template);
     276}
     277
     278function get_404_template() {
     279        return get_query_template('404');
     280}
     281
     282function get_archive_template() {
     283        return get_query_template('archive');
     284}
     285
     286function get_author_template() {
     287        return get_query_template('author');
     288}
     289
     290function get_category_template() {
     291        $template = '';
     292        if ( file_exists(TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php') )
     293                $template = TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php';
     294        else if ( file_exists(TEMPLATEPATH . "/category.php") )
     295                $template = TEMPLATEPATH . "/category.php";
     296
     297        return apply_filters('category_template', $template);
     298}
     299
     300function get_date_template() {
     301        return get_query_template('date');
     302}
     303
     304function get_home_template() {
     305        $template = '';
     306
     307        if ( file_exists(TEMPLATEPATH . "/home.php") )
     308                $template = TEMPLATEPATH . "/home.php";
     309        else if ( file_exists(TEMPLATEPATH . "/index.php") )
     310                $template = TEMPLATEPATH . "/index.php";
     311
     312        return apply_filters('home_template', $template);
     313}
     314
     315function get_page_template() {
     316        global $wp_query;
     317
     318        $id = $wp_query->post->ID;
     319        $template = get_post_meta($id, '_wp_page_template', true);
     320
     321        if ( 'default' == $template )
     322                $template = '';
     323
     324        if ( ! empty($template) && file_exists(TEMPLATEPATH . "/$template") )
     325                $template = TEMPLATEPATH . "/$template";
     326        else if ( file_exists(TEMPLATEPATH . "/page.php") )
     327                $template = TEMPLATEPATH . "/page.php";
     328        else
     329                $template = '';
     330
     331        return apply_filters('page_template', $template);
     332}
     333
     334function get_paged_template() {
     335        return get_query_template('paged');
     336}
     337
     338function get_search_template() {
     339        return get_query_template('search');
     340}
     341
     342function get_single_template() {
     343        return get_query_template('single');
     344}
     345
     346function get_attachment_template() {
     347        global $posts;
     348        $type = explode('/', $posts[0]->post_mime_type);
     349        if ( $template = get_query_template($type[0]) )
     350                return $template;
     351        elseif ( $template = get_query_template($type[1]) )
     352                return $template;
     353        elseif ( $template = get_query_template("$type[0]_$type[1]") )
     354                return $template;
     355        else
     356                return get_query_template('attachment');
     357}
     358
     359function get_comments_popup_template() {
     360        if ( file_exists( TEMPLATEPATH . '/comments-popup.php') )
     361                $template = TEMPLATEPATH . '/comments-popup.php';
     362        else
     363                $template = get_theme_root() . '/default/comments-popup.php';
     364
     365        return apply_filters('comments_popup_template', $template);
     366}
     367
     368function load_template($file) {
     369        global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query,
     370                $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment;
     371
     372        extract($wp_query->query_vars);
     373
     374        require_once($file);
     375}
     376
     377?>
  • wp-includes/functions.php

     
    14841484        do_action('wp_footer');
    14851485}
    14861486
    1487 function get_theme_root() {
    1488         return apply_filters('theme_root', ABSPATH . "wp-content/themes");
    1489 }
    1490 
    1491 function get_theme_root_uri() {
    1492         return apply_filters('theme_root_uri', get_settings('siteurl') . "/wp-content/themes", get_settings('siteurl'));
    1493 }
    1494 
    1495 function get_stylesheet() {
    1496         return apply_filters('stylesheet', get_settings('stylesheet'));
    1497 }
    1498 
    1499 function get_stylesheet_directory() {
    1500         $stylesheet = get_stylesheet();
    1501         $stylesheet_dir = get_theme_root() . "/$stylesheet";
    1502         return apply_filters('stylesheet_directory', $stylesheet_dir, $stylesheet);
    1503 }
    1504 
    1505 function get_stylesheet_directory_uri() {
    1506         $stylesheet = rawurlencode( get_stylesheet() );
    1507         $stylesheet_dir_uri = get_theme_root_uri() . "/$stylesheet";
    1508         return apply_filters('stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet);
    1509 }
    1510 
    1511 function get_stylesheet_uri() {
    1512         $stylesheet_dir_uri = get_stylesheet_directory_uri();
    1513         $stylesheet_uri = $stylesheet_dir_uri . "/style.css";
    1514         return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
    1515 }
    1516 
    1517 function get_template() {
    1518         $template = get_settings('template');
    1519         if (!file_exists(get_theme_root() . "/$template")) { //works for dirs too
    1520                 update_option('template', 'default');
    1521                 update_option('stylesheet', 'default');
    1522         }
    1523         return apply_filters('template', get_settings('template'));
    1524 }
    1525 
    1526 function get_template_directory() {
    1527         $template = get_template();
    1528         $template_dir = get_theme_root() . "/$template";
    1529         return apply_filters('template_directory', $template_dir, $template);
    1530 }
    1531 
    1532 function get_template_directory_uri() {
    1533         $template = get_template();
    1534         $template_dir_uri = get_theme_root_uri() . "/$template";
    1535         return apply_filters('template_directory_uri', $template_dir_uri, $template);
    1536 }
    1537 
    1538 function get_theme_data($theme_file) {
    1539         $theme_data = implode('', file($theme_file));
    1540         preg_match("|Theme Name:(.*)|i", $theme_data, $theme_name);
    1541         preg_match("|Theme URI:(.*)|i", $theme_data, $theme_uri);
    1542         preg_match("|Description:(.*)|i", $theme_data, $description);
    1543         preg_match("|Author:(.*)|i", $theme_data, $author_name);
    1544         preg_match("|Author URI:(.*)|i", $theme_data, $author_uri);
    1545         preg_match("|Template:(.*)|i", $theme_data, $template);
    1546         if ( preg_match("|Version:(.*)|i", $theme_data, $version) )
    1547                 $version = $version[1];
    1548         else
    1549                 $version ='';
    1550         if ( preg_match("|Status:(.*)|i", $theme_data, $status) )
    1551                 $status = $status[1];
    1552         else
    1553                 $status ='publish';
    1554 
    1555         $description = wptexturize($description[1]);
    1556 
    1557         $name = $theme_name[1];
    1558         $name = trim($name);
    1559         $theme = $name;
    1560 
    1561         if ( '' == $author_uri[1] ) {
    1562                 $author = $author_name[1];
    1563         } else {
    1564                 $author = '<a href="' . $author_uri[1] . '" title="' . __('Visit author homepage') . '">' . $author_name[1] . '</a>';
    1565         }
    1566 
    1567         return array('Name' => $name, 'Title' => $theme, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1], 'Status' => $status);
    1568 }
    1569 
    1570 function get_themes() {
    1571         global $wp_themes;
    1572         global $wp_broken_themes;
    1573 
    1574         if ( isset($wp_themes) )
    1575                 return $wp_themes;
    1576 
    1577         $themes = array();
    1578         $wp_broken_themes = array();
    1579         $theme_root = get_theme_root();
    1580         $theme_loc = str_replace(ABSPATH, '', $theme_root);
    1581 
    1582         // Files in wp-content/themes directory
    1583         $themes_dir = @ dir($theme_root);
    1584         if ( $themes_dir ) {
    1585                 while(($theme_dir = $themes_dir->read()) !== false) {
    1586                         if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
    1587                                 if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) {
    1588                                         continue;
    1589                                 }
    1590                                 $stylish_dir = @ dir($theme_root . '/' . $theme_dir);
    1591                                 $found_stylesheet = false;
    1592                                 while (($theme_file = $stylish_dir->read()) !== false) {
    1593                                         if ( $theme_file == 'style.css' ) {
    1594                                                 $theme_files[] = $theme_dir . '/' . $theme_file;
    1595                                                 $found_stylesheet = true;
    1596                                                 break;
    1597                                         }
    1598                                 }
    1599                                 if ( !$found_stylesheet ) {
    1600                                         $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
    1601                                 }
    1602                         }
    1603                 }
    1604         }
    1605 
    1606         if ( !$themes_dir || !$theme_files ) {
    1607                 return $themes;
    1608         }
    1609 
    1610         sort($theme_files);
    1611 
    1612         foreach($theme_files as $theme_file) {
    1613                 if ( ! is_readable("$theme_root/$theme_file") ) {
    1614                         $wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
    1615                         continue;
    1616                 }
    1617 
    1618                 $theme_data = get_theme_data("$theme_root/$theme_file");
    1619 
    1620                 $name = $theme_data['Name'];
    1621                 $title = $theme_data['Title'];
    1622                 $description = wptexturize($theme_data['Description']);
    1623                 $version = $theme_data['Version'];
    1624                 $author = $theme_data['Author'];
    1625                 $template = $theme_data['Template'];
    1626                 $stylesheet = dirname($theme_file);
    1627 
    1628                 foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) {
    1629                         if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
    1630                                 $screenshot = "screenshot.$ext";
    1631                                 break;
    1632                         }
    1633                 }
    1634 
    1635                 if ( empty($name) ) {
    1636                         $name = dirname($theme_file);
    1637                         $title = $name;
    1638                 }
    1639 
    1640                 if ( empty($template) ) {
    1641                         if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) {
    1642                                 $template = dirname($theme_file);
    1643                         } else {
    1644                                 continue;
    1645                         }
    1646                 }
    1647 
    1648                 $template = trim($template);
    1649 
    1650                 if ( !file_exists("$theme_root/$template/index.php") ) {
    1651                         $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
    1652                         continue;
    1653                 }
    1654 
    1655                 $stylesheet_files = array();
    1656                 $stylesheet_dir = @ dir("$theme_root/$stylesheet");
    1657                 if ( $stylesheet_dir ) {
    1658                         while(($file = $stylesheet_dir->read()) !== false) {
    1659                                 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )
    1660                                         $stylesheet_files[] = "$theme_loc/$stylesheet/$file";
    1661                         }
    1662                 }
    1663 
    1664                 $template_files = array();
    1665                 $template_dir = @ dir("$theme_root/$template");
    1666                 if ( $template_dir ) {
    1667                         while(($file = $template_dir->read()) !== false) {
    1668                                 if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
    1669                                         $template_files[] = "$theme_loc/$template/$file";
    1670                         }
    1671                 }
    1672 
    1673                 $template_dir = dirname($template_files[0]);
    1674                 $stylesheet_dir = dirname($stylesheet_files[0]);
    1675 
    1676                 if ( empty($template_dir) )
    1677                         $template_dir = '/';
    1678                 if ( empty($stylesheet_dir) )
    1679                         $stylesheet_dir = '/';
    1680 
    1681                 // Check for theme name collision.  This occurs if a theme is copied to
    1682                 // a new theme directory and the theme header is not updated.  Whichever
    1683                 // theme is first keeps the name.  Subsequent themes get a suffix applied.
    1684                 // The Default and Classic themes always trump their pretenders.
    1685                 if ( isset($themes[$name]) ) {
    1686                         if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) &&
    1687                                          ('default' == $stylesheet || 'classic' == $stylesheet) ) {
    1688                                 // If another theme has claimed to be one of our default themes, move
    1689                                 // them aside.
    1690                                 $suffix = $themes[$name]['Stylesheet'];
    1691                                 $new_name = "$name/$suffix";
    1692                                 $themes[$new_name] = $themes[$name];
    1693                                 $themes[$new_name]['Name'] = $new_name;
    1694                         } else {
    1695                                 $name = "$name/$stylesheet";
    1696                         }
    1697                 }
    1698 
    1699                 $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, 'Status' => $theme_data['Status'], 'Screenshot' => $screenshot);
    1700         }
    1701 
    1702         // Resolve theme dependencies.
    1703         $theme_names = array_keys($themes);
    1704 
    1705         foreach ($theme_names as $theme_name) {
    1706                 $themes[$theme_name]['Parent Theme'] = '';
    1707                 if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
    1708                         foreach ($theme_names as $parent_theme_name) {
    1709                                 if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
    1710                                         $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
    1711                                         break;
    1712                                 }
    1713                         }
    1714                 }
    1715         }
    1716 
    1717         $wp_themes = $themes;
    1718 
    1719         return $themes;
    1720 }
    1721 
    1722 function get_theme($theme) {
    1723         $themes = get_themes();
    1724 
    1725         if ( array_key_exists($theme, $themes) )
    1726                 return $themes[$theme];
    1727 
    1728         return NULL;
    1729 }
    1730 
    1731 function get_current_theme() {
    1732         $themes = get_themes();
    1733         $theme_names = array_keys($themes);
    1734         $current_template = get_settings('template');
    1735         $current_stylesheet = get_settings('stylesheet');
    1736         $current_theme = 'WordPress Default';
    1737 
    1738         if ( $themes ) {
    1739                 foreach ($theme_names as $theme_name) {
    1740                         if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
    1741                                         $themes[$theme_name]['Template'] == $current_template ) {
    1742                                 $current_theme = $themes[$theme_name]['Name'];
    1743                                 break;
    1744                         }
    1745                 }
    1746         }
    1747 
    1748         return $current_theme;
    1749 }
    1750 
    1751 function get_query_template($type) {
    1752         $template = '';
    1753         if ( file_exists(TEMPLATEPATH . "/{$type}.php") )
    1754                 $template = TEMPLATEPATH . "/{$type}.php";
    1755 
    1756         return apply_filters("{$type}_template", $template);
    1757 }
    1758 
    1759 function get_404_template() {
    1760         return get_query_template('404');
    1761 }
    1762 
    1763 function get_archive_template() {
    1764         return get_query_template('archive');
    1765 }
    1766 
    1767 function get_author_template() {
    1768         return get_query_template('author');
    1769 }
    1770 
    1771 function get_category_template() {
    1772         $template = '';
    1773         if ( file_exists(TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php') )
    1774                 $template = TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php';
    1775         else if ( file_exists(TEMPLATEPATH . "/category.php") )
    1776                 $template = TEMPLATEPATH . "/category.php";
    1777 
    1778         return apply_filters('category_template', $template);
    1779 }
    1780 
    1781 function get_date_template() {
    1782         return get_query_template('date');
    1783 }
    1784 
    1785 function get_home_template() {
    1786         $template = '';
    1787 
    1788         if ( file_exists(TEMPLATEPATH . "/home.php") )
    1789                 $template = TEMPLATEPATH . "/home.php";
    1790         else if ( file_exists(TEMPLATEPATH . "/index.php") )
    1791                 $template = TEMPLATEPATH . "/index.php";
    1792 
    1793         return apply_filters('home_template', $template);
    1794 }
    1795 
    1796 function get_page_template() {
    1797         global $wp_query;
    1798 
    1799         $id = $wp_query->post->ID;
    1800         $template = get_post_meta($id, '_wp_page_template', true);
    1801 
    1802         if ( 'default' == $template )
    1803                 $template = '';
    1804 
    1805         if ( ! empty($template) && file_exists(TEMPLATEPATH . "/$template") )
    1806                 $template = TEMPLATEPATH . "/$template";
    1807         else if ( file_exists(TEMPLATEPATH . "/page.php") )
    1808                 $template = TEMPLATEPATH . "/page.php";
    1809         else
    1810                 $template = '';
    1811 
    1812         return apply_filters('page_template', $template);
    1813 }
    1814 
    1815 function get_paged_template() {
    1816         return get_query_template('paged');
    1817 }
    1818 
    1819 function get_search_template() {
    1820         return get_query_template('search');
    1821 }
    1822 
    1823 function get_single_template() {
    1824         return get_query_template('single');
    1825 }
    1826 
    1827 function get_attachment_template() {
    1828         global $posts;
    1829         $type = explode('/', $posts[0]->post_mime_type);
    1830         if ( $template = get_query_template($type[0]) )
    1831                 return $template;
    1832         elseif ( $template = get_query_template($type[1]) )
    1833                 return $template;
    1834         elseif ( $template = get_query_template("$type[0]_$type[1]") )
    1835                 return $template;
    1836         else
    1837                 return get_query_template('attachment');
    1838 }
    1839 
    1840 function get_comments_popup_template() {
    1841         if ( file_exists( TEMPLATEPATH . '/comments-popup.php') )
    1842                 $template = TEMPLATEPATH . '/comments-popup.php';
    1843         else
    1844                 $template = get_theme_root() . '/default/comments-popup.php';
    1845 
    1846         return apply_filters('comments_popup_template', $template);
    1847 }
    1848 
    18491487// Borrowed from the PHP Manual user notes. Convert entities, while
    18501488// preserving already-encoded entities:
    18511489function htmlentities2($myHTML) {
     
    19191557        return add_query_arg($key, '', $query);
    19201558}
    19211559
    1922 function load_template($file) {
    1923         global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query,
    1924                 $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment;
    1925 
    1926         extract($wp_query->query_vars);
    1927 
    1928         require_once($file);
    1929 }
    1930 
    19311560function add_magic_quotes($array) {
    19321561        global $wpdb;
    19331562
  • wp-settings.php

     
    132132require (ABSPATH . WPINC . '/capabilities.php');
    133133require (ABSPATH . WPINC . '/classes.php');
    134134require (ABSPATH . WPINC . '/query.php');
     135require (ABSPATH . WPINC . '/theme.php');
    135136require (ABSPATH . WPINC . '/template-functions-general.php');
    136137require (ABSPATH . WPINC . '/template-functions-links.php');
    137138require (ABSPATH . WPINC . '/template-functions-author.php');