Make WordPress Core


Ignore:
Timestamp:
03/29/2006 01:51:55 AM (18 years ago)
Author:
ryan
Message:

AJAX, cause you love it. Props mdawaffe. fixes #2561

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r3653 r3660  
    603603function write_nested_categories($categories) {
    604604    foreach ($categories as $category) {
    605         echo '<label for="category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label>\n";
    606 
    607         if (isset ($category['children'])) {
    608             echo "\n<span class='cat-nest'>\n";
     605        echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label></li>\n";
     606
     607        if ( $category['children'] ) {
     608            echo "<ul>\n";
    609609            write_nested_categories($category['children']);
    610             echo "</span>\n";
     610            echo "</ul>\n";
    611611        }
    612612    }
     
    627627        foreach ($categories as $category) {
    628628            if ($category->category_parent == $parent) {
    629                 $category->cat_name = wp_specialchars($category->cat_name);
     629                $category->cat_name = wp_specialchars($category->cat_name,'double');
    630630                $pad = str_repeat('&#8212; ', $level);
    631631                if ( current_user_can('manage_categories') ) {
     
    635635
    636636                    if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) )
    637                         $edit .= "<td><a href='categories.php?action=delete&amp;cat_ID=$category->cat_ID' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '".sprintf(__("You are about to delete the category &quot;%s&quot;.  All of its posts and bookmarks will go to the default categories.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars($category->cat_name, 1))."' );\" class='delete'>".__('Delete')."</a>";
     637                        $edit .= "<td><a href='categories.php?action=delete&amp;cat_ID=$category->cat_ID' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '".sprintf(__("You are about to delete the category &quot;%s&quot;.  All of its posts and bookmarks will go to the default categories.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), addslashes($category->cat_name))."' );\" class='delete'>".__('Delete')."</a>";
    638638                    else
    639639                        $edit .= "<td style='text-align:center'>".__("Default");
     
    685685    <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td>
    686686    <td><?php if ( current_user_can('edit_page', $id) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>
    687     <td><?php if ( current_user_can('edit_page', $id) ) { echo "<a href='page.php?action=delete&amp;post=$id' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars(get_the_title('','',0), 1)) . "' );\">" . __('Delete') . "</a>"; } ?></td>
     687    <td><?php if ( current_user_can('edit_page', $id) ) { echo "<a href='page.php?action=delete&amp;post=$id' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), addslashes(wp_specialchars(get_the_title(),'double')) ) . "' );\">" . __('Delete') . "</a>"; } ?></td>
    688688  </tr>
    689689
     
    829829    global $post_ID;
    830830    // Exit if no meta
    831     if (!$meta)
     831    if (!$meta) {
     832        echo '<tbody id="the-list"></tbody>'; //TBODY needed for list-manipulation JS
    832833        return;
     834    }
    833835    $count = 0;
    834836?>
    835 <table id='meta-list' cellpadding="3">
     837    <thead>
    836838    <tr>
    837839        <th><?php _e('Key') ?></th>
     
    839841        <th colspan='2'><?php _e('Action') ?></th>
    840842    </tr>
     843    </thead>
    841844<?php
    842 
    843 
     845    $r ="\n\t<tbody id='the-list'>";
    844846    foreach ($meta as $entry) {
    845847        ++ $count;
     
    850852        if ('_' == $entry['meta_key'] { 0 })
    851853            $style .= ' hidden';
    852         echo "
    853             <tr class='$style'>
    854                 <td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>
    855                 <td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>
    856                 <td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__('Update')."' /><br />
    857                 <input name='deletemeta[{$entry['meta_id']}]' type='submit' class='deletemeta' tabindex='6' value='".__('Delete')."' /></td>
    858             </tr>
    859         ";
    860     }
    861     echo "
    862         </table>
    863     ";
     854        $key_js = addslashes(wp_specialchars( $entry['meta_key'], 'double' ));
     855        $entry['meta_key'] = wp_specialchars( $entry['meta_key'], true );
     856        $entry['meta_value'] = wp_specialchars( $entry['meta_value'], true );
     857        $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
     858        $r .= "\n\t\t<td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>";
     859        $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
     860        $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__('Update')."' /><br />";
     861        $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '";
     862        $r .= sprintf(__("You are about to delete the &quot;%s&quot; custom field on this post.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), $key_js);
     863        $r .= "' );\" class='deletemeta' tabindex='6' value='".__('Delete')."' /></td>";
     864        $r .= "\n\t</tr>";
     865    }
     866    echo $r;
     867    echo "\n\t</tbody>";
    864868}
    865869
     
    887891?>
    888892<h3><?php _e('Add a new custom field:') ?></h3>
    889 <table cellspacing="3" cellpadding="3">
     893<table id="newmeta" cellspacing="3" cellpadding="3">
    890894    <tr>
    891895<th colspan="2"><?php _e('Key') ?></th>
     
    911915
    912916</table>
    913 <p class="submit"><input type="submit" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field &raquo;') ?>" /></p>
     917<p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field &raquo;') ?>" /></p>
    914918<?php
    915919
     
    918922function add_meta($post_ID) {
    919923    global $wpdb;
     924    $post_ID = (int) $post_ID;
    920925
    921926    $metakeyselect = $wpdb->escape(stripslashes(trim($_POST['metakeyselect'])));
     
    927932        // input for the key have data, the input takes precedence:
    928933
    929         if ('#NONE#' != $metakeyselect)
     934        if ('#NONE#' != $metakeyselect)
    930935            $metakey = $metakeyselect;
    931936
     
    938943                        VALUES ('$post_ID','$metakey','$metavalue')
    939944                    ");
    940     }
     945        return $wpdb->insert_id;
     946    }
     947    return false;
    941948} // add_meta
    942949
    943950function delete_meta($mid) {
    944951    global $wpdb;
    945 
    946     $result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'");
     952    $mid = (int) $mid;
     953
     954    return $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'");
    947955}
    948956
    949957function update_meta($mid, $mkey, $mvalue) {
    950958    global $wpdb;
     959    $mid = (int) $mid;
    951960
    952961    return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'");
     962}
     963
     964function get_post_meta_by_id($mid) {
     965    global $wpdb;
     966    $mid = (int) $mid;
     967
     968    return $wpdb->get_row("SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'");
    953969}
    954970
Note: See TracChangeset for help on using the changeset viewer.