Changeset 3711
- Timestamp:
- 04/18/2006 04:44:33 AM (19 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r3704 r3711 1485 1485 } 1486 1486 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 too1520 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 else1549 $version ='';1550 if ( preg_match("|Status:(.*)|i", $theme_data, $status) )1551 $status = $status[1];1552 else1553 $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 directory1583 $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 to1682 // a new theme directory and the theme header is not updated. Whichever1683 // 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, move1689 // 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 else1810 $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 else1837 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 else1844 $template = get_theme_root() . '/default/comments-popup.php';1845 1846 return apply_filters('comments_popup_template', $template);1847 }1848 1849 1487 // Borrowed from the PHP Manual user notes. Convert entities, while 1850 1488 // preserving already-encoded entities: … … 1918 1556 function remove_query_arg($key, $query) { 1919 1557 return add_query_arg($key, '', $query); 1920 }1921 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 1558 } 1930 1559 -
trunk/wp-settings.php
r3685 r3711 133 133 require (ABSPATH . WPINC . '/classes.php'); 134 134 require (ABSPATH . WPINC . '/query.php'); 135 require (ABSPATH . WPINC . '/theme.php'); 135 136 require (ABSPATH . WPINC . '/template-functions-general.php'); 136 137 require (ABSPATH . WPINC . '/template-functions-links.php');
Note: See TracChangeset
for help on using the changeset viewer.