Changeset 1753
- Timestamp:
- 10/06/04 05:11:11 (4 years ago)
- Files:
-
- trunk/wp-admin/admin-functions.php (modified) (1 diff)
- trunk/wp-admin/edit-page-form.php (modified) (2 diffs)
- trunk/wp-admin/edit-pages.php (modified) (1 diff)
- trunk/wp-admin/post.php (modified) (3 diffs)
- trunk/wp-blog-header.php (modified) (1 diff)
- trunk/wp-includes/functions.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wp-admin/admin-functions.php
r1752 r1753 756 756 } 757 757 758 function get_page_templates() { 759 $themes = get_themes(); 760 $theme = get_current_theme(); 761 $templates = $themes[$theme]['Template Files']; 762 $page_templates = array(); 763 764 foreach ($templates as $template) { 765 $template_data = implode('', file(ABSPATH . $template)); 766 preg_match("|Template Name:(.*)|i", $template_data, $name); 767 preg_match("|Description:(.*)|i", $template_data, $description); 768 769 $name = $name[1]; 770 $description = $description[1]; 771 772 if (! empty($name)) { 773 $page_templates[trim($name)] = basename($template); 774 } 775 } 776 777 return $page_templates; 778 } 779 780 function page_template_dropdown($default = '') { 781 $templates = get_page_templates(); 782 foreach (array_keys($templates) as $template) : 783 if ($default == $templates[$template]) $selected = " selected='selected'"; 784 else $selected = ''; 785 echo "\n\t<option value='" . $templates[$template] . "' $selected>$template</option>"; 786 endforeach; 787 } 788 758 789 function parent_dropdown($default = 0, $parent = 0, $level = 0) { 759 790 global $wpdb; trunk/wp-admin/edit-page-form.php
r1752 r1753 50 50 </fieldset> 51 51 <fieldset id="pageparent"> 52 <legend><?php _e('Page Parent') ?></ a></legend>52 <legend><?php _e('Page Parent') ?></legend> 53 53 <div><select name="parent_id"> 54 <option value='0'>Main Page (no parent)</option>54 <option value='0'><?php _e('Main Page (no parent)'); ?></option> 55 55 <?php parent_dropdown($post_parent); ?> 56 56 </select> … … 80 80 <input name="referredby" type="hidden" id="referredby" value="<?php if (isset($_SERVER['HTTP_REFERER'])) echo htmlspecialchars($_SERVER['HTTP_REFERER']); ?>" /> 81 81 </p> 82 83 <fieldset id="pageoptions"> 84 <legend><?php _e('Page Options') ?></legend> 85 <table width="100%" cellspacing="2" cellpadding="5" class="editform"> 86 <tr valign="top"> 87 <th scope="row"><?php _e('Page Template:') ?></th> 88 <td><div><select name="page_template"> 89 <option value='default'><?php _e('Default Template'); ?></option> 90 <?php page_template_dropdown($page_template); ?> 91 </select> 92 </div> 93 </td> 94 </tr> 95 </table> 96 </fieldset> 97 82 98 <?php do_action('edit_page_form', ''); ?> 83 99 </form> trunk/wp-admin/edit-pages.php
r1752 r1753 69 69 $post_pingback = get_settings('default_pingback_flag'); 70 70 $post_parent = 0; 71 $page_template = 'default'; 71 72 72 73 include('edit-page-form.php'); trunk/wp-admin/post.php
r1752 r1753 201 201 if ($post_status = 'static') { 202 202 generate_page_rewrite_rules(); 203 204 add_post_meta($post_ID, '_wp_page_template', $_POST['page_template'], true); 203 205 } 204 206 … … 234 236 235 237 if ($post_status == 'static') { 238 $page_template = get_post_meta($post_ID, '_wp_page_template', true); 239 236 240 include('edit-page-form.php'); 237 241 } else { … … 439 443 if ($post_status = 'static') { 440 444 generate_page_rewrite_rules(); 445 446 if ( ! update_post_meta($post_ID, '_wp_page_template', $_POST['page_template'])) { 447 add_post_meta($post_ID, '_wp_page_template', $_POST['page_template'], true); 448 } 441 449 } 442 450 trunk/wp-blog-header.php
r1726 r1753 216 216 include("$wp_template_dir/single.php"); 217 217 exit; 218 } else if (is_page() && 219 file_exists("$wp_template_dir/page.php")) { 220 $wp_did_template_redirect = true; 221 include("$wp_template_dir/page.php"); 218 } else if (is_page() && file_exists(get_page_template())) { 219 $wp_did_template_redirect = true; 220 include(get_page_template()); 222 221 exit; 223 222 } else if (is_category() && trunk/wp-includes/functions.php
r1752 r1753 448 448 } 449 449 450 function get_post_meta($post_id, $key ) {450 function get_post_meta($post_id, $key, $single = false) { 451 451 global $wpdb, $post_meta_cache; 452 452 453 453 if (isset($post_meta_cache[$post_id][$key])) { 454 return $post_meta_cache[$post_id][$key]; 454 if ($single) { 455 return $post_meta_cache[$post_id][$key][0]; 456 } else { 457 return $post_meta_cache[$post_id][$key]; 458 } 455 459 } 456 460 … … 464 468 } 465 469 466 return $values; 470 if ($single) { 471 if (count($values)) { 472 return $values[0]; 473 } else { 474 return ''; 475 } 476 } else { 477 return $values; 478 } 467 479 } 468 480 469 481 function update_post_meta($post_id, $key, $value, $prev_value = '') { 470 482 global $wpdb, $post_meta_cache; 483 484 if(! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key 485 = '$key' AND post_id = '$post_id'") ) { 486 return false; 487 } 471 488 472 489 if (empty($prev_value)) { … … 1821 1838 } 1822 1839 1840 function get_page_template() { 1841 global $wp_query; 1842 1843 $id = $wp_query->post->ID; 1844 $template_dir = get_template_directory(); 1845 $default = "$template_dir/page.php"; 1846 1847 $template = get_post_meta($id, '_wp_page_template', true); 1848 1849 if (empty($template) || ($template == 'default')) { 1850 return $default; 1851 } 1852 1853 if (file_exists("$template_dir/$template")) { 1854 return "$template_dir/$template"; 1855 } 1856 1857 return $default; 1858 } 1859 1823 1860 // Borrowed from the PHP Manual user notes. Convert entities, while 1824 1861 // preserving already-encoded entities:
