Make WordPress Core

Ticket #2561: 2561f.diff

File 2561f.diff, 55.6 KB (added by mdawaffe, 18 years ago)

fixes some bugs reported by ryan and mark

  • wp-includes/functions-formatting.php

     
    101101        $text = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/', '&$1', $text);-
    102102        $text = str_replace('<', '&lt;', $text);
    103103        $text = str_replace('>', '&gt;', $text);
    104         if ( $quotes ) {
     104        if ( 'double' == $quotes ) {
    105105                $text = str_replace('"', '&quot;', $text);
     106        } elseif ( $quotes ) {
     107                $text = str_replace('"', '&quot;', $text);
    106108                $text = str_replace("'", '&#039;', $text);
    107109        }
    108110        return $text;
  • wp-includes/js/fat.js

     
    1111                b = b.toString(16); if (b.length == 1) b = '0' + b;
    1212                return "#" + r + g + b;
    1313        },
    14         fade_all : function ()
     14        fade_all : function (dur)
    1515        {
    1616                var a = document.getElementsByTagName("*");
    1717                for (var i = 0; i < a.length; i++)
     
    2121                        if (r)
    2222                        {
    2323                                if (!r[1]) r[1] = "";
    24                                 if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
     24                                if (o.id) Fat.fade_element(o.id,null,dur,"#"+r[1]);
    2525                        }
    2626                }
    2727        },
     
    8787
    8888addLoadEvent(function ()  {
    8989        Fat.fade_all();
    90 });
    91  No newline at end of file
     90});
  • wp-admin/custom-fields.js

     
     1addLoadEvent(customFieldsAddIn);
     2function customFieldsAddIn() {
     3        if (!theList.theList) return false;
     4        inputs = theList.theList.getElementsByTagName('input');
     5        for ( var i=0; i < inputs.length; i++ ) {
     6                if ('text' == inputs[i].type) {
     7                        inputs[i].setAttribute('autocomplete', 'off');
     8                        inputs[i].onkeypress = function(e) {return killSubmit('theList.ajaxUpdater("meta", "meta-' + parseInt(this.name.slice(5),10) + '");', e); };
     9                }
     10                if ('updatemeta' == inputs[i].className) {
     11                        inputs[i].onclick = function(e) {return killSubmit('theList.ajaxUpdater("meta", "meta-' + parseInt(this.parentNode.parentNode.id.slice(5),10) + '");', e); };
     12                }
     13        }
     14
     15        document.getElementById('metakeyinput').onkeypress = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta", customFieldsOnComplete);', e); };
     16        document.getElementById('updatemeta').onclick = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta", customFieldsOnComplete);', e); };
     17        theList.clearInputs.push('metakeyselect','metakeyinput','metavalue');
     18}
     19function customFieldsOnComplete() {
     20        var pidEl = document.getElementById('post_ID');
     21        pidEl.name = 'post_ID';
     22        pidEl.value = getNodeValue(theList.ajaxAdd.responseXML, 'postid');
     23        var aEl = document.getElementById('hiddenaction')
     24        if ( aEl.value == 'post' ) aEl.value = 'postajaxpost';
     25}
  • wp-admin/edit-comments.php

     
    133133                         | <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php _e('View Post') ?></a></p>
    134134                </li>
    135135
    136 <?php } // end foreach ?>
     136<?php } // end foreach($comment) ?>
    137137</ol>
    138138
    139139<div id="ajax-response"></div>
    140140
    141141<?php
    142         } else {
     142        } else { //no comments to show
    143143
    144144                ?>
    145145                <p>
     
    162162  </tr>';
    163163                foreach ($comments as $comment) {
    164164                $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
     165                $comment_status = wp_get_comment_status($comment->comment_ID);
    165166                $class = ('alternate' == $class) ? '' : 'alternate';
     167                $class .= ('unapproved' == $comment_status) ? ' unapproved' : '';
    166168?>
    167   <tr class='<?php echo $class; ?>'>
     169  <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
    168170    <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { ?><input type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /><?php } ?></td>
    169171    <td><?php comment_author_link() ?></td>
    170172    <td><?php comment_author_email_link() ?></td>
    171173    <td><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></td>
    172174    <td><?php comment_excerpt(); ?></td>
    173     <td><a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a></td>
     175    <td>
     176        <?php if ('unapproved' == $comment_status) { ?>
     177                (Unapproved)
     178        <?php } else { ?>
     179                <a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a>
     180        <?php } ?>
     181    </td>
    174182    <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
    175183        echo "<a href='comment.php?action=editcomment&amp;comment=$comment->comment_ID' class='edit'>" .  __('Edit') . "</a>"; } ?></td>
    176184    <td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
    177             echo "<a href=\"comment.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return confirm('" . sprintf(__("You are about to delete this comment by \'%s\'\\n  \'Cancel\' to stop, \'OK\' to delete."), $comment->comment_author) . "')\"    class='delete'>" . __('Delete') . "</a>"; } ?></td>
     185                echo "<a href=\"comment.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return deleteSomething( 'comment', $comment->comment_ID, '" . sprintf(__("You are about to delete this comment by &quot;%s&quot;.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete."), wp_specialchars( $comment->comment_author, 1 ))  . "' );\" class='edit'>" . __('Delete') . "</a> ";
     186                } ?></td>
    178187  </tr>
    179188                <?php
    180189                } // end foreach
     
    183192            <p class="submit"><input type="submit" name="delete_button" value="<?php _e('Delete Checked Comments &raquo;') ?>" onclick="var numchecked = getNumChecked(document.getElementById('deletecomments')); if(numchecked < 1) { alert('<?php _e("Please select some comments to delete"); ?>'); return false } return confirm('<?php printf(__("You are about to delete %s comments permanently \\n  \'Cancel\' to stop, \'OK\' to delete."), "' + numchecked + '"); ?>')" />
    184193                        <input type="submit" name="spam_button" value="<?php _e('Mark Checked Comments as Spam &raquo;') ?>" onclick="return confirm('<?php _e("You are about to mark these comments as spam \\n  \'Cancel\' to stop, \'OK\' to mark as spam.") ?>')" /></p>
    185194  </form>
     195<div id="ajax-response"></div>
    186196<?php
    187197        } else {
    188198?>
  • wp-admin/admin-ajax.php

     
     1<?php
     2require_once('../wp-config.php');
     3require_once('admin-functions.php');
     4require_once('admin-db.php');
     5
     6define('DOING_AJAX', true);
     7
     8if ( !is_user_logged_in() )
     9        die('-1');
     10
     11function get_out_now() { exit; }
     12add_action( 'shutdown', 'get_out_now', -1 );
     13
     14function wp_clean_ajax_input( $i ) {
     15        global $wpdb;
     16        $i = is_array($i) ? array_map('wp_clean_ajax_input', $i) : $wpdb->escape( rawurldecode(stripslashes($i)) );
     17        return $i;
     18}
     19
     20function wp_ajax_echo_meta( $pid, $mid, $key, $value ) {
     21        $r  = "<meta><id>$mid</id><postid>$pid</postid><newitem><![CDATA[<table><tbody>";
     22        $r .= "<tr id='meta-$mid'><td valign='top'>";
     23        $r .= "<input name='meta[$mid][key]' tabindex='6' onkeypress='return killSubmit(\"theList.ajaxUpdater(&#039;meta&#039;,&#039;meta-$mid&#039;);\",event);' type='text' size='20' value='$key' />";
     24        $r .= "</td><td><textarea name='meta[$mid][value]' tabindex='6' rows='2' cols='30'>$value</textarea></td><td align='center'>";
     25        $r .= "<input name='updatemeta' type='button' class='updatemeta' tabindex='6' value='Update' onclick='return theList.ajaxUpdater(&#039;meta&#039;,&#039;meta-$mid&#039;);' /><br />";
     26        $r .= "<input name='deletemeta[$mid]' type='submit' onclick='return deleteSomething( \"meta\", $mid);' class='deletemeta' tabindex='6' value='Delete' />";
     27        $r .= "</td></tr></tbody></table>]]></newitem></meta>";
     28        return $r;
     29}
     30
     31//      check_admin_referer();
     32
     33$_POST = wp_clean_ajax_input( $_POST );
     34$id = (int) $_POST['id'];
     35switch ( $_POST['action'] ) :
     36case 'delete-comment' :
     37        if ( !$comment = get_comment( $id ) )
     38                die('0');
     39        if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
     40                die('-1');
     41
     42        if ( wp_delete_comment( $comment->comment_ID ) )
     43                die('1');
     44        else    die('0');
     45        break;
     46case 'delete-comment-as-spam' :
     47        if ( !$comment = get_comment( $id ) )
     48                die('0');
     49        if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
     50                die('-1');
     51
     52        if ( wp_set_comment_status( $comment->comment_ID, 'spam' ) )
     53                die('1');
     54        else    die('0');
     55        break;
     56case 'delete-cat' :
     57        if ( !current_user_can( 'manage_categories' ) )
     58                die('-1');
     59
     60        if ( wp_delete_category( $id ) )
     61                die('1');
     62        else    die('0');
     63        break;
     64case 'delete-link' :
     65        if ( !current_user_can( 'manage_links' ) )
     66                die('-1');
     67
     68        if ( wp_delete_link( $id ) )
     69                die('1');
     70        else    die('0');
     71        break;
     72case 'delete-meta' :
     73        if ( !$meta = get_post_meta_by_id( $id ) )
     74                die('0');
     75        if ( !current_user_can( 'edit_post', $meta->post_id ) )
     76                die('-1');
     77        if ( delete_meta( $meta->meta_id ) )
     78                die('1');
     79        die('0');
     80        break;
     81case 'delete-post' :
     82        if ( !current_user_can( 'delete_post', $id ) )
     83                die('-1');
     84
     85        if ( wp_delete_post( $id ) )
     86                die('1');
     87        else    die('0');
     88        break;
     89case 'delete-page' :
     90        if ( !current_user_can( 'delete_page', $id ) )
     91                die('-1');
     92
     93        if ( wp_delete_post( $id ) )
     94                die('1');
     95        else    die('0');
     96        break;
     97case 'dim-comment' :
     98        if ( !$comment = get_comment( $id ) )
     99                die('0');
     100        if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
     101                die('-1');
     102        if ( !current_user_can( 'moderate_comments' ) )
     103                die('-1');
     104
     105        if ( 'unapproved' == wp_get_comment_status($comment->comment_ID) ) {
     106                if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) )
     107                        die('1');
     108        } else {
     109                if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) )
     110                        die('1');
     111        }
     112        die('0');
     113        break;
     114case 'add-category' : // On the Fly
     115        if ( !current_user_can( 'manage_categories' ) )
     116                die('-1');
     117        $names = explode(',', $_POST['newcat']);
     118        $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
     119        foreach ( $names as $cat_name ) {
     120                $cat_name = trim($cat_name);
     121                if ( !$category_nicename = sanitize_title($cat_name) )
     122                        die('0');
     123                if ( !$cat_id = category_exists( $cat_name ) )
     124                        $cat_id = wp_create_category( $cat_name );
     125                $cat_name = stripslashes($cat_name);
     126                $r .= "<category><id>$cat_id</id><newitem><![CDATA[";
     127                $r .= "<li id='category-$cat_id'><label for='in-category-$cat_id' class='selectit'>";
     128                $r .= "<input value='$cat_id' type='checkbox' checked='checked' name='post_category[]' id='in-category-$cat_id'/> $cat_name</label></li>";
     129                $r .= "]]></newitem></category>";
     130        }
     131        $r .= '</ajaxresponse>';
     132        header('Content-type: text/xml');
     133        die($r);
     134        break;
     135case 'add-cat' : // From Manage->Categories
     136        if ( !current_user_can( 'manage_categories' ) )
     137                die('-1');
     138        if ( !$cat = wp_insert_category( $_POST ) )
     139                die('0');
     140        if ( !$cat = get_category( $cat ) )
     141                die('0');
     142        $pad = 0;
     143        $_cat = $cat;
     144        while ( $_cat->category_parent ) {
     145                $_cat = get_category( $_cat->category_parent );
     146                $pad++;
     147        }
     148        $pad = str_repeat('&#8212; ', $pad);
     149
     150        $r  = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
     151        $r .= "<cat><id>$cat->cat_ID</id><newitem><![CDATA[<table><tbody>";
     152        $r .= "<tr id='cat-$cat->cat_ID'><th scope='row'>$cat->cat_ID</th><td>$pad $cat->cat_name</td>";
     153        $r .= "<td>$cat->category_description</td><td>$cat->category_count</td><td>$cat->link_count</td>";
     154        $r .= "<td><a href='categories.php?action=edit&amp;cat_ID=$cat->cat_ID' class='edit'>" . __('Edit') . "</a></td>";
     155        $r .= "<td><a href='categories.php?action=delete&amp;cat_ID=$cat->cat_ID' onclick='return deleteSomething( \"cat\", $cat->cat_ID, \"";
     156        $r .= sprintf(__('You are about to delete the category \"%s\".  All of its posts and bookmarks will go to the default categories.\\n\"OK\" to delete, \"Cancel\" to stop.'), addslashes($cat->cat_name));
     157        $r .= "\" );' class='delete'>".__('Delete')."</a></td></tr>";
     158        $r .= "</tbody></table>]]></newitem></cat></ajaxresponse>";
     159        header('Content-type: text/xml');
     160        die($r);
     161
     162        break;
     163case 'add-meta' :
     164        if ( !current_user_can( 'edit_post', $id ) )
     165                die('-1');
     166        if ( $id < 0 ) {
     167                if ( $pid = write_post() )
     168                        $meta = has_meta( $pid );
     169                else
     170                        die('0');
     171                $key = wp_specialchars( $meta[0]['meta_key'], true );
     172                $value = wp_specialchars( $meta[0]['meta_value'], true );
     173                $mid = (int) $meta[0]['meta_id'];
     174        } else {
     175                if ( $mid = add_meta( $id ) )
     176                        $meta = get_post_meta_by_id( $mid );
     177                else
     178                        die('0');
     179                $key = wp_specialchars($meta->meta_key, true);
     180                $value = wp_specialchars($meta->meta_value, true);
     181                $pid = (int) $meta->post_id;
     182        }
     183        $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
     184        $r .= wp_ajax_echo_meta( $pid, $mid, $key, $value );
     185        $r .= '</ajaxresponse>';
     186        header('Content-type: text/xml');
     187        die($r);
     188        break;
     189case 'update-meta' :
     190        $mid = (int) array_pop(array_keys($_POST['meta']));
     191        $key = $_POST['meta'][$mid]['key'];
     192        $value = $_POST['meta'][$mid]['value'];
     193        if ( !$meta = get_post_meta_by_id( $mid ) )
     194                die('0');
     195        if ( !current_user_can( 'edit_post', $meta->post_id ) )
     196                die('-1');
     197        $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
     198        if ( $u = update_meta( $mid, $key, $value ) ) {
     199                $key = wp_specialchars(stripslashes($key), true);
     200                $value = wp_specialchars(stripslashes($value), true);
     201                $r .= wp_ajax_echo_meta( $meta->post_id, $mid, $key, $value );
     202        }
     203        $r .= '</ajaxresponse>';
     204        header('Content-type: text/xml');
     205        die($r);
     206        break;
     207default :
     208        die('0');
     209        break;
     210endswitch;
     211?>
  • wp-admin/list-manipulation.php

     
    1 <?php
    2 require_once('../wp-config.php');
    3 require_once('admin-functions.php');
    4 require_once('admin-db.php');
    5 
    6 if ( !is_user_logged_in() )
    7         die('-1');
    8 
    9 function get_out_now() { exit; }
    10 add_action( 'shutdown', 'get_out_now', -1 );
    11 
    12 //      check_admin_referer();
    13 
    14 $id = (int) $_POST['id'];
    15 switch ( $_POST['action'] ) :
    16 case 'delete-link' :
    17         if ( !current_user_can( 'manage_links' ) )
    18                 die('-1');
    19 
    20         if ( wp_delete_link( $id ) )
    21                 die('1');
    22         else    die('0');
    23         break;
    24 case 'delete-post' :
    25         if ( !current_user_can( 'delete_post', $id ) )
    26                 die('-1');
    27 
    28         if ( wp_delete_post( $id ) )
    29                 die('1');
    30         else    die('0');
    31         break;
    32 case 'delete-page' :
    33         if ( !current_user_can( 'delete_page', $id ) )
    34                 die('-1');
    35 
    36         if ( wp_delete_post( $id ) )
    37                 die('1');
    38         else    die('0');
    39         break;
    40 case 'delete-cat' :
    41         if ( !current_user_can( 'manage_categories' ) )
    42                 die('-1');
    43 
    44         if ( wp_delete_category( $id ) )
    45                 die('1');
    46         else    die('0');
    47         break;
    48 case 'delete-comment' :
    49         if ( !$comment = get_comment( $id ) )
    50                 die('0');
    51         if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
    52                 die('-1');
    53 
    54         if ( wp_delete_comment( $comment->comment_ID ) )
    55                 die('1');
    56         else    die('0');
    57         break;
    58 case 'delete-comment-as-spam' :
    59         if ( !$comment = get_comment( $id ) )
    60                 die('0');
    61         if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
    62                 die('-1');
    63 
    64         if ( wp_set_comment_status( $comment->comment_ID, 'spam' ) )
    65                 die('1');
    66         else    die('0');
    67         break;
    68 endswitch;
    69 ?>
  • wp-admin/edit-form-ajax-cat.php

     
    1 <?php
    2 require_once('../wp-config.php');
    3 require_once('admin-functions.php');
    4 require_once('admin-db.php');
    5 
    6 if ( !current_user_can('manage_categories') )
    7         die('-1');
    8 
    9 function get_out_now() { exit; }
    10 
    11 add_action('shutdown', 'get_out_now', -1);
    12 
    13 $names = explode(',', rawurldecode($_GET['ajaxnewcat']) );
    14 $ids   = array();
    15 
    16 foreach ($names as $cat_name) {
    17         $cat_name = trim( $cat_name );
    18 
    19         if ( !$category_nicename = sanitize_title($cat_name) )
    20                 continue;
    21         if ( $already = category_exists($cat_name) ) {
    22                 $ids[] = (string) $already;
    23                 continue;
    24         }
    25 
    26         $new_cat_id = wp_create_category($cat_name);
    27 
    28         $ids[] = (string) $new_cat_id;
    29 }
    30 
    31 $return = join(',', $ids);
    32 
    33 die( (string) $return );
    34 
    35 ?>
    36  No newline at end of file
  • wp-admin/wp-admin.css

     
    9191        padding: .1em .3em;
    9292}
    9393
    94 fieldset span.cat-nest {
    95         display: block;
    96         margin-left: 10px;
    97 }
    98 
    9994fieldset.options {
    10095        padding: 1em;
    10196}
     
    326321        color: #009ef0;
    327322}
    328323
     324.approve {
     325        display: none;
     326}
     327
     328.unapproved .approve {
     329        display: inline;
     330}
     331
     332.unapproved .unapprove {
     333        display: none;
     334}
     335
    329336.updated {
    330337        background: #CFEBF7 url(images/notice.gif) no-repeat 1em ;
    331338        border: 1px solid #2580B2;
     
    804811        margin-top: .5em;
    805812}
    806813
    807 #categorydiv div div {
     814#categorydiv ul {
     815        list-style: none;
     816        padding: 0;
     817        margin-left:10px;
     818}
     819#categorychecklist {
    808820        height: 12em;
    809821        overflow: auto;
     822        margin-top: 8px;
    810823}
    811 
     824#categorychecklist li {
     825        margin: 0;
     826        padding: 0;
     827}
    812828#ajaxcat input {
    813829        border: 1px solid #ccc;
    814830}
     
    951967#jaxcat {
    952968        margin: 0;
    953969        padding: 0;
    954 }
    955  No newline at end of file
     970}
  • wp-admin/post.php

     
    1717                }
    1818        }
    1919}
    20 
    2120if (isset($_POST['deletepost']))
    2221$action = "delete";
    2322
    2423switch($action) {
     24case 'postajaxpost':
    2525case 'post':
    2626        check_admin_referer();
    2727       
    28         $post_ID = write_post();
     28        $post_ID = 'post' == $action ? write_post() : edit_post();
    2929
    3030        // Redirect.
    3131        if (!empty($_POST['mode'])) {
  • wp-admin/admin.php

     
    4040    }
    4141}
    4242
    43 $xfn_js = $sack_js = $list_js = $cat_js = $dbx_js = $editing = false;
     43$xfn_js = $sack_js = $list_js = $cat_js = $dbx_js = $pmeta_js = $editing = false;
    4444
    4545require(ABSPATH . '/wp-admin/menu.php');
    4646
  • wp-admin/admin-functions.php

     
    602602
    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";
     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";
    606606
    607                 if (isset ($category['children'])) {
    608                         echo "\n<span class='cat-nest'>\n";
     607                if ( $category['children'] ) {
     608                        echo "<ul>\n";
    609609                        write_nested_categories($category['children']);
    610                         echo "</span>\n";
     610                        echo "</ul>\n";
    611611                }
    612612        }
    613613}
     
    626626        if ($categories) {
    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') ) {
    632632                                        $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>";
     
    634634                                        $default_link_cat_id = get_option('default_link_category');
    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");
    640640                                }
     
    684684    <td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>
    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
    690690<?php
     
    832832                return;
    833833        $count = 0;
    834834?>
    835 <table id='meta-list' cellpadding="3">
    836835        <tr>
    837836                <th><?php _e('Key') ?></th>
    838837                <th><?php _e('Value') ?></th>
    839838                <th colspan='2'><?php _e('Action') ?></th>
    840839        </tr>
    841840<?php
    842 
    843 
     841        $r ='';
    844842        foreach ($meta as $entry) {
    845843                ++ $count;
    846844                if ($count % 2)
     
    849847                        $style = '';
    850848                if ('_' == $entry['meta_key'] { 0 })
    851849                        $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                 ";
     850                $entry['meta_key'] = wp_specialchars( $entry['meta_key'], true );
     851                $entry['meta_value'] = wp_specialchars( $entry['meta_value'], true );
     852                $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
     853                $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>";
     854                $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
     855                $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__('Update')."' /><br />";
     856                $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick='return deleteSomething( \"meta\", {$entry['meta_id']});' class='deletemeta' tabindex='6' value='".__('Delete')."' /></td>";
     857                $r .= "\n\t</tr>";
    860858        }
    861         echo "
    862                 </table>
    863         ";
     859        echo $r;
    864860}
    865861
    866862// Get a list of previously defined keys
     
    886882                        LIMIT 10");
    887883?>
    888884<h3><?php _e('Add a new custom field:') ?></h3>
    889 <table cellspacing="3" cellpadding="3">
     885<table id="newmeta" cellspacing="3" cellpadding="3">
    890886        <tr>
    891887<th colspan="2"><?php _e('Key') ?></th>
    892888<th><?php _e('Value') ?></th>
     
    910906        </tr>
    911907
    912908</table>
    913 <p class="submit"><input type="submit" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field &raquo;') ?>" /></p>
     909<p class="submit"><input type="submit" id="updatemeta" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field &raquo;') ?>" /></p>
    914910<?php
    915911
    916912}
    917913
    918914function add_meta($post_ID) {
    919915        global $wpdb;
     916        $post_ID = (int) $post_ID;
    920917
    921918        $metakeyselect = $wpdb->escape(stripslashes(trim($_POST['metakeyselect'])));
    922919        $metakeyinput = $wpdb->escape(stripslashes(trim($_POST['metakeyinput'])));
     
    926923                // We have a key/value pair. If both the select and the
    927924                // input for the key have data, the input takes precedence:
    928925
    929                 if ('#NONE#' != $metakeyselect)
     926                if ('#NONE#' != $metakeyselect)
    930927                        $metakey = $metakeyselect;
    931928
    932929                if ($metakeyinput)
     
    937934                                                (post_id,meta_key,meta_value)
    938935                                                VALUES ('$post_ID','$metakey','$metavalue')
    939936                                        ");
     937                return $wpdb->insert_id;
    940938        }
     939        return false;
    941940} // add_meta
    942941
    943942function delete_meta($mid) {
    944943        global $wpdb;
     944        $mid = (int) $mid;
    945945
    946         $result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'");
     946        return $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'");
    947947}
    948948
    949949function update_meta($mid, $mkey, $mvalue) {
    950950        global $wpdb;
     951        $mid = (int) $mid;
    951952
    952953        return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'");
    953954}
    954955
     956function get_post_meta_by_id($mid) {
     957        global $wpdb;
     958        $mid = (int) $mid;
     959
     960        return $wpdb->get_row("SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'");
     961}
     962
    955963function touch_time($edit = 1, $for_post = 1) {
    956964        global $month, $post, $comment;
    957965
  • wp-admin/edit-page-form.php

     
    66if (0 == $post_ID) {
    77        $form_action = 'post';
    88        $temp_ID = -1 * time();
    9         $form_extra = "<input type='hidden' name='temp_ID' value='$temp_ID' />";
     9        $form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />";
    1010} else {
    1111        $form_action = 'editpost';
    12         $form_extra = "<input type='hidden' name='post_ID' value='$post_ID' />";
     12        $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />";
    1313}
    1414
    1515$sendto = $_SERVER['HTTP_REFERER'];
     
    209209<fieldset id="postcustom" class="dbx-box">
    210210<h3 class="dbx-handle"><?php _e('Custom Fields') ?></h3>
    211211<div id="postcustomstuff" class="dbx-content">
     212<table id='the-list-x' cellpadding="3">
    212213<?php
    213214if($metadata = has_meta($post_ID)) {
    214215?>
    215216<?php
    216217        list_meta($metadata);
    217218?>
     219
    218220<?php
    219221}
     222?>
     223</table>
     224<?php
    220225        meta_form();
    221226?>
    222227</div>
  • wp-admin/admin-db.php

     
    174174        $parent = $category->category_parent;
    175175
    176176        // Delete the category.
    177         $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
     177        if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
     178                return 0;
    178179
    179180        // Update children to point to new parent.
    180181        $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'");
  • wp-admin/edit-form-advanced.php

     
    2121if (0 == $post_ID) {
    2222        $form_action = 'post';
    2323        $temp_ID = -1 * time();
    24         $form_extra = "<input type='hidden' name='temp_ID' value='$temp_ID' />";
     24        $form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />";
    2525} else {
    2626        $form_action = 'editpost';
    27         $form_extra = "<input type='hidden' name='post_ID' value='$post_ID' />";
     27        $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />";
    2828}
    2929
    3030$form_pingback = '<input type="hidden" name="post_pingback" value="' . get_option('default_pingback_flag') . '" id="post_pingback" />';
     
    4949?>
    5050
    5151<input type="hidden" name="user_ID" value="<?php echo $user_ID ?>" />
    52 <input type="hidden" name="action" value="<?php echo $form_action ?>" />
     52<input type="hidden" id="hiddenaction" name="action" value="<?php echo $form_action ?>" />
    5353<input type="hidden" name="post_author" value="<?php echo $post->post_author ?>" />
    5454<input type="hidden" name="post_type" value="post" />
    5555
     
    7272<h3 class="dbx-handle"><?php _e('Categories') ?></h3>
    7373<div class="dbx-content">
    7474<p id="jaxcat"></p>
    75 <div id="categorychecklist"><?php dropdown_categories(get_settings('default_category')); ?></div></div>
     75<ul id="categorychecklist"><?php dropdown_categories(get_settings('default_category')); ?></ul></div>
    7676</fieldset>
    7777
    7878<fieldset id="commentstatusdiv" class="dbx-box">
     
    248248<fieldset id="postcustom" class="dbx-box">
    249249<h3 class="dbx-handle"><?php _e('Custom Fields') ?></h3>
    250250<div id="postcustomstuff" class="dbx-content">
     251<table id='the-list-x' cellpadding="3">
    251252<?php
    252253if($metadata = has_meta($post_ID)) {
    253254?>
    254255<?php
    255256        list_meta($metadata);
    256257?>
     258
    257259<?php
    258260}
     261?>
     262</table>
     263<?php
    259264        meta_form();
    260265?>
     266<div id="ajax-response"></div>
    261267</div>
    262268</fieldset>
    263269
  • wp-admin/categories.js

     
     1addLoadEvent(newCategoryAddIn);
     2function newCategoryAddIn() {
     3        if (!theList.theList) return false;
     4        document.forms.addcat.submit.onclick = function(e) {return killSubmit('theList.ajaxAdder("cat", "addcat");', e); };
     5        theList.clearInputs.push('cat_name','category_parent','category_description');
     6}
  • wp-admin/admin-header.php

     
    33if (!isset($_GET["page"])) require_once('admin.php');
    44if ( $editing ) {
    55        $dbx_js = true;
    6         if ( current_user_can('manage_categories') )
     6        $pmeta_js = true;
     7        if ( current_user_can('manage_categories') ) {
     8                $list_js = true;
    79                $cat_js = true;
     10        }
    811}
    9 if ( $list_js || $cat_js )
     12if ( $list_js )
    1013        $sack_js = true;
    1114?>
    1215<?php get_admin_page_title(); ?>
     
    2932<script type="text/javascript" src="../wp-includes/js/tw-sack.js"></script>
    3033<?php } ?>
    3134<?php if ( $list_js ) { ?>
    32 <script type="text/javascript" src="list-manipulation.js"></script>
     35<script type="text/javascript" src="list-manipulation-js.php"></script>
    3336<?php } ?>
     37<?php if ( $pmeta_js ) { ?>
     38<script type="text/javascript" src="custom-fields.js"></script>
     39<?php } ?>
     40<?php if ( 'categories.php' == $pagenow && 'edit' != $action ) { ?>
     41<script type="text/javascript" src="categories.js"></script>
     42<?php } ?>
    3443<?php if ( $dbx_js ) { ?>
    3544<script type="text/javascript" src="../wp-includes/js/dbx.js"></script>
    3645<script type="text/javascript">
  • wp-admin/cat-js.php

     
    22require_once('../wp-config.php');
    33header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true);
    44?>
    5 var ajaxCat = new sack();
    6 var newcat;
    7  
     5addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.clearInputs.push('newcat');});
     6addLoadEvent(newCatAddIn);
    87function newCatAddIn() {
    98        if ( !document.getElementById('jaxcat') ) return false;
    109        var ajaxcat = document.createElement('span');
     
    1615        newcat.id = 'newcat';
    1716        newcat.size = '16';
    1817        newcat.setAttribute('autocomplete', 'off');
    19         newcat.onkeypress = ajaxNewCatKeyPress;
     18        newcat.onkeypress = function(e) { return killSubmit("catList.ajaxAdder('category','categorydiv');", e); };
    2019
    2120        var newcatSub = document.createElement('input');
    2221        newcatSub.type = 'button';
    2322        newcatSub.name = 'Button';
    2423        newcatSub.id = 'catadd';
    25         newcatSub.value = '<?php echo addslashes(__('Add')); ?>';
    26         newcatSub.onclick = ajaxNewCat;
     24        newcatSub.value = 'Add';
     25        newcatSub.onclick = function() { catList.ajaxAdder('category', 'categorydiv'); };
    2726
    2827        ajaxcat.appendChild(newcat);
    2928        ajaxcat.appendChild(newcatSub);
    3029        document.getElementById('jaxcat').appendChild(ajaxcat);
    3130
    3231        howto = document.createElement('span');
    33         howto.innerHTML = '<?php echo addslashes(__('Separate multiple categories with commas.')); ?>';
     32        howto.innerHTML = 'Separate multiple categories with commas.';
    3433        howto.id = 'howto';
    3534        ajaxcat.appendChild(howto);
    3635}
    37 
    38 addLoadEvent(newCatAddIn);
    39 
    40 function getResponseElement() {
    41         var p = document.getElementById('ajaxcatresponse');
    42         if (!p) {
    43                 p = document.createElement('span');
    44                 document.getElementById('jaxcat').appendChild(p);
    45                 p.id = 'ajaxcatresponse';
    46         }
    47         return p;
    48 }
    49 
    50 function newCatLoading() {
    51         var p = getResponseElement();
    52         p.innerHTML = '<?php echo addslashes(__('Sending Data...')); ?>';
    53 }
    54 
    55 function newCatLoaded() {
    56         var p = getResponseElement();
    57         p.innerHTML = '<?php echo addslashes(__('Data Sent...')); ?>';
    58 }
    59 
    60 function newCatInteractive() {
    61         var p = getResponseElement();
    62         p.innerHTML = '<?php echo addslashes(__('Processing Request...')); ?>';
    63 }
    64 
    65 function newCatCompletion() {
    66         var p = getResponseElement();
    67         var id    = 0;
    68         var ids   = new Array();
    69         var names = new Array();
    70 
    71         ids   = myPload( ajaxCat.response );
    72         names = myPload( newcat.value );
    73         for ( i = 0; i < ids.length; i++ ) {
    74                 id = ids[i].replace(/[\n\r]+/g, "");
    75                 if ( id == '-1' ) {
    76                         p.innerHTML = "<?php echo addslashes(__("You don't have permission to do that.")); ?>";
    77                         return;
    78                 }
    79                 if ( id == '0' ) {
    80                         p.innerHTML = "<?php echo addslashes(__('That category name is invalid.  Try something else.')); ?>";
    81                         return;
    82                 }
    83 
    84                 var exists = document.getElementById('category-' + id);
    85 
    86                 if (exists) {
    87                         var moveIt = exists.parentNode;
    88                         var container = moveIt.parentNode;
    89                         container.removeChild(moveIt);
    90                         container.insertBefore(moveIt, container.firstChild);
    91                         moveIt.id = 'new-category-' + id;
    92                         exists.checked = 'checked';
    93                         var nowClass = moveIt.className;
    94                         moveIt.className = nowClass + ' fade';
    95                         Fat.fade_all();
    96                         moveIt.className = nowClass;
    97                 } else {
    98                         var catDiv = document.getElementById('categorychecklist');
    99                         var newLabel = document.createElement('label');
    100                         newLabel.setAttribute('for', 'category-' + id);
    101                         newLabel.id = 'new-category-' + id;
    102                         newLabel.className = 'selectit fade';
    103 
    104                         var newCheck = document.createElement('input');
    105                         newCheck.type = 'checkbox';
    106                         newCheck.value = id;
    107                         newCheck.name = 'post_category[]';
    108                         newCheck.id = 'category-' + id;
    109                         newLabel.appendChild(newCheck);
    110 
    111                         var newLabelText = document.createTextNode(' ' + names[i]);
    112                         newLabel.appendChild(newLabelText);
    113 
    114                         catDiv.insertBefore(newLabel, catDiv.firstChild);
    115                         newCheck.checked = 'checked';
    116 
    117                         Fat.fade_all();
    118                         newLabel.className = 'selectit';
    119                 }
    120                 newcat.value = '';
    121         }
    122         p.parentNode.removeChild(p);
    123 //      var id = parseInt(ajaxCat.response, 10);
    124 }
    125 
    126 function ajaxNewCatKeyPress(e) {
    127         if (!e) {
    128                 if (window.event) {
    129                         e = window.event;
    130                 } else {
    131                         return;
    132                 }
    133         }
    134         if (e.keyCode == 13) {
    135                 ajaxNewCat();
    136                 e.returnValue = false;
    137                 e.cancelBubble = true;
    138                 return false;
    139         }
    140 }
    141 
    142 function ajaxNewCat() {
    143         var newcat = document.getElementById('newcat');
    144         var split_cats = new Array(1);
    145         var catString = '';
    146 
    147         catString = 'ajaxnewcat=' + encodeURIComponent(newcat.value);
    148         ajaxCat.requestFile = 'edit-form-ajax-cat.php';
    149         ajaxCat.method = 'GET';
    150         ajaxCat.onLoading = newCatLoading;
    151         ajaxCat.onLoaded = newCatLoaded;
    152         ajaxCat.onInteractive = newCatInteractive;
    153         ajaxCat.onCompletion = newCatCompletion;
    154         ajaxCat.runAJAX(catString);
    155 }
    156 
    157 function myPload( str ) {
    158         var fixedExplode = new Array();
    159         var comma = new String(',');
    160         var count = 0;
    161         var currentElement = '';
    162 
    163         for( x=0; x < str.length; x++) {
    164                 andy = str.charAt(x);
    165                 if ( comma.indexOf(andy) != -1 ) {
    166                         currentElement = currentElement.replace(new RegExp('^\\s*(.*?)\\s*$', ''), '$1'); // trim
    167                         fixedExplode[count] = currentElement;
    168                         currentElement = "";
    169                         count++;
    170                 } else {
    171                         currentElement += andy;
    172                 }
    173         }
    174 
    175         if ( currentElement != "" )
    176                 fixedExplode[count] = currentElement;
    177         return fixedExplode;
    178 }
    179  No newline at end of file
  • wp-admin/list-manipulation-js.php

     
     1<?php
     2require_once('admin.php');
     3header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true);
     4?>
     5addLoadEvent(function(){theList=new listMan();});
     6function deleteSomething(what,id,message){if(!message)message='Are you sure you want to delete this '+what+'?';if(confirm(message))return theList.ajaxDelete(what,id);else return false;}
     7function dimSomething(what,id,dimClass){return theList.ajaxDimmer(what,id,dimClass);}
     8
     9function WPAjax(file, responseEl){//class WPAjax extends sack
     10        this.getResponseElement=function(r){var p=document.getElementById(r+'-p');if(!p){p=document.createElement('span');p.id=r+'ajax-response-p';document.getElementById(r).appendChild(p);}this.myResponseElement=p; }
     11        this.parseAjaxResponse=function(){
     12                if(isNaN(this.response)){this.myResponseElement.innerHTML='Error: '+this.response;return false;}
     13                this.response=parseInt(this.response,10);
     14                if(-1==this.response){this.myResponseElement.innerHTML="You don't have permission to do that.";return false;}
     15                else if(0==this.response){this.myResponseElement.innerHTML="Something odd happened. Try refreshing the page? Either that or what you tried to change never existed in the first place.";return false;}
     16                return true;
     17        }
     18        this.parseAjaxResponseXML=function(){
     19                if(this.responseXML&&typeof this.responseXML=='object')return true;
     20                if(isNaN(this.response)){this.myResponseElement.innerHTML='Error: '+this.response;return false;}
     21                var r=parseInt(this.response,10);
     22                if(-1==r){this.myResponseElement.innerHTML="You don't have permission to do that.";}
     23                else if(0==r){this.myResponseElement.innerHTML="Invalid Entry.";}
     24                return false;//Anything else need to be caught?
     25        }
     26        this.init(file,responseEl);
     27}       WPAjax.prototype=new sack;
     28        WPAjax.prototype.init=function(f,r){
     29                this.requestFile=f;
     30                this.getResponseElement(r);
     31                this.method='POST';
     32                this.onLoading=function(){this.myResponseElement.innerHTML='Sending Data...';};
     33                this.onLoaded=function(){this.myResponseElement.innerHTML='Data Sent...';};
     34                this.onInteractive=function(){this.myResponseElement.innerHTML='Processing Data...';};
     35        }
     36
     37function listMan(theListId,extraRows){
     38        this.theListId=theListId;
     39        this.extraRows=extraRows;
     40        this.theList=null;
     41        this.ajaxRespEl=null;
     42        this.inputData='';
     43        this.clearInputs=new Array();
     44        var reg_color='#FFFFFF';
     45        var alt_color='#F1F1F1';
     46        var listItems;
     47        var listType;
     48        self.aTrap=0;
     49
     50        this.ajaxAdder=function(what,where,onComplete,update){//if server returns TR, server must wrap it in TABLE TBODY. this.makeEl cleans it
     51                if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300);
     52                this.ajaxAdd=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
     53                if(this.ajaxAdd.failed)return true;
     54                this.grabInputs(where);
     55                var tempObj=this;
     56                this.ajaxAdd.onCompletion=function(){
     57                        if(!this.parseAjaxResponseXML())return;
     58                        var newItems=this.responseXML.getElementsByTagName(what);
     59                        if(newItems){for (c=0;c<newItems.length;c++){
     60                                var id=parseInt(getNodeValue(newItems[c],'id'),10);
     61                                var exists=document.getElementById(what+'-'+id);
     62                                if(exists)tempObj.replaceListItem(exists.id,getNodeValue(newItems[c],'newitem'),update);
     63                                else tempObj.addListItem(getNodeValue(newItems[c],'newitem'));
     64                        }}
     65                        this.myResponseElement.innerHTML='';tempObj.inputData='';
     66                        for(var i=0;i<tempObj.clearInputs.length;i++){try{var theI=document.getElementById(tempObj.clearInputs[i]);if(theI.tagName.match(/select/i))theI.selectedIndex=0;else theI.value='';}catch(e){}}
     67                        if(onComplete&&typeof onComplete=='function')onComplete();
     68                }
     69                this.ajaxAdd.runAJAX('action='+(update?'update-':'add-')+what+this.inputData);
     70                return false;
     71        }
     72        this.ajaxUpdater=function(what,where,onComplete){return this.ajaxAdder(what,where,onComplete,true);}
     73        this.ajaxDelete=function(what,id,onComplete){
     74                if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300);
     75                this.ajaxDel=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
     76                if(this.ajaxDel.failed)return true;
     77                var tempObj=this;
     78                this.ajaxDel.onCompletion=function(){if(this.parseAjaxResponse()){tempObj.removeListItem(what.replace('-as-spam','')+'-'+id,tempObj);this.myResponseElement.innerHTML='';if(onComplete&&typeof onComplete=='function')onComplete();}};
     79                this.ajaxDel.runAJAX('action=delete-'+what+'&id='+id);
     80                return false;
     81        }
     82        this.ajaxDimmer=function(what,id,dimClass,onComplete){
     83                if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300);
     84                this.ajaxDim=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
     85                if(this.ajaxDim.failed)return true;
     86                var tempObj=this;
     87                this.ajaxDim.onCompletion=function(){if(this.parseAjaxResponse()){tempObj.dimItem(what+'-'+id,dimClass);this.myResponseElement.innerHTML='';if(onComplete&&typeof onComplete=='function')onComplete();}};
     88                this.ajaxDim.runAJAX('action=dim-'+what+'&id='+id);
     89                return false;
     90        }
     91        this.makeEl=function(chunk){var fakeItem=document.createElement('div');fakeItem.innerHTML=chunk;var ret=fakeItem.firstChild;while(ret.tagName.match(/(table|tbody)/i)){ret=ret.firstChild;}return ret;}
     92        this.addListItem=function(chunk){
     93                newItem=this.makeEl(chunk);
     94                var firstItem=this.theList.getElementsByTagName('table'==listType?'tr':'li')[this.extraRows];
     95                if(firstItem)firstItem.parentNode.insertBefore(newItem,firstItem);
     96                else this.theList.appendChild(newItem);
     97                listItems.unshift(newItem.id);
     98                Fat.fade_element(newItem.id);
     99        }
     100        this.removeListItem=function(id,listObj,noFade){
     101                if(!listObj)listObj=this;
     102                if(!noFade)Fat.fade_element(id,null,700,'#FF3333');
     103                if(!self.theItem)self.theItem=new Array();//grumble:global
     104                self.theItem[id]=document.getElementById(id);
     105                if(!noFade)setTimeout('theItem["'+id+'"].parentNode.removeChild(theItem["'+id+'"]);delete(theItem["'+id+'"])',705);
     106                else{self.theItem[id].parentNode.removeChild(theItem[id]);delete(theItem[id]);}
     107                var pos=listObj.getListPos(id);
     108                listItems.splice(pos,1);
     109                if(!noFade)listObj.recolorList(pos);
     110        }
     111        this.replaceListItem=function(id,chunk,update){
     112                if(!update){this.removeListItem(id,false,true);this.addListItem(chunk);return;}
     113                var newItem=this.makeEl(chunk);
     114                var oldItem=document.getElementById(id);
     115                oldItem.parentNode.replaceChild(newItem,oldItem);
     116                Fat.fade_element(newItem.id);
     117        }
     118        this.dimItem=function(id,dimClass,noFade){
     119                var theItem=document.getElementById(id);
     120                if(theItem.className.match(dimClass)){if(!noFade)Fat.fade_element(id,null,700,null);theItem.className=theItem.className.replace(dimClass,'');}
     121                else{if(!noFade)Fat.fade_element(id,null,700,'#FF3333');theItem.className=theItem.className+' '+dimClass;}
     122        }
     123        this.grabInputs=function(elId){//text,password,hidden,textarea,select
     124                var theItem=document.getElementById(elId);
     125                var inputs=new Array();
     126                inputs.push(theItem.getElementsByTagName('input'),theItem.getElementsByTagName('textarea'),theItem.getElementsByTagName('select'));
     127                for(var a=0;a<inputs.length;a++){
     128                        for(var i=0;i<inputs[a].length;i++){
     129                                if('action'==inputs[a][i].name)continue;
     130                                if('text'==inputs[a][i].type||'password'==inputs[a][i].type||'hidden'==inputs[a][i].type||inputs[a][i].tagName.match(/textarea/i)){
     131                                        this.inputData+='&'+inputs[a][i].name+'='+encodeURIComponent(inputs[a][i].value);
     132                                }else if(inputs[a][i].tagName.match(/select/i)){
     133                                        this.inputData+='&'+inputs[a][i].name+'='+encodeURIComponent(inputs[a][i].options[inputs[a][i].selectedIndex].value);
     134                                }
     135                        }       
     136                }
     137        }
     138        this.getListPos=function(id){for(var i=0;i<listItems.length;i++){if(id==listItems[i]){var pos=i;break;}}return pos;}
     139        this.getListItems=function(){
     140                if(this.theList)return;
     141                listItems=new Array();
     142                if(isNaN(this.extraRows))this.extraRows=0;
     143                if(this.theListId){this.theList=document.getElementById(this.theListId);if(!this.theList)return false;}
     144                else{this.theList=document.getElementById('the-list');if(this.theList)this.theListId='the-list';}
     145                if(!this.theList){this.theList=document.getElementById('the-list-x');this.extraRows+=1;if(this.theList)this.theListId='the-list-x';}
     146                if(this.theList){
     147                        var items=this.theList.getElementsByTagName('tr');listType='table'
     148                        if(!items[0]){items=this.theList.getElementsByTagName('li');listType='list'}
     149                        for(var i=0;i<items.length;i++){listItems.push(items[i].id);}
     150                        if(this.extraRows){listItems.splice(0,this.extraRows);}
     151                }
     152        }
     153        this.recolorList=function(pos,dur,from){
     154                if(!pos)pos=0;
     155                if(!from){reg_from=alt_color;alt_from=reg_color;}
     156                else{reg_from=from;alt_from=from;}
     157                var listItemsAsString='';
     158                for(var i=pos;i<listItems.length;i++){listItemsAsString+="'"+listItems[i]+"',";var theI=document.getElementById(listItems[i]);if(i%2)theI.className=theI.className.replace('alternate','fade-'+alt_color.slice(1));else theI.className+=' alternate fade-'+reg_color.slice(1);theI.style.backgroundColor='';}
     159                listItemsAsString=listItemsAsString.slice(0,-1);
     160                Fat.fade_all(1000);//fade_all seems to work better when many items in list, but necessitates ugly next line.
     161                setTimeout("var listItems=new Array("+listItemsAsString+");for(var i=0;i<listItems.length;i++){var theI=document.getElementById(listItems[i]);theI.className=theI.className.replace(/fade-[a-f0-9]{6}/i,'');}",1005);
     162        }
     163        this.getListItems();
     164}
     165//Don't submit, eval(code) instead
     166function killSubmit(code,e){if(!e){if(window.event)e=window.event;else return;}var t=e.target?e.target:e.srcElement;if(('text'==t.type&&e.keyCode==13)||('submit'==t.type&&'click'==e.type)){eval(code);e.returnValue=false;e.cancelBubble=true;return false;}}
     167//Pretty function from ALA http://www.alistapart.com/articles/gettingstartedwithajax
     168function getNodeValue(tree,el){return tree.getElementsByTagName(el)[0].firstChild.nodeValue;}
  • wp-admin/edit.php

     
    114114<br style="clear:both;" />
    115115
    116116<?php
    117 
    118117// define the columns to display, the syntax is 'internal name' => 'display name'
    119118$posts_columns = array(
    120119  'id'         => __('ID'),
     
    145144if ($posts) {
    146145$bgcolor = '';
    147146foreach ($posts as $post) { start_wp();
     147add_filter('the_title','wp_specialchars');
    148148$class = ('alternate' == $class) ? '' : 'alternate';
    149149?>
    150150        <tr id='post-<?php echo $id; ?>' class='<?php echo $class; ?>'>
     
    207207
    208208        case 'control_delete':
    209209                ?>
    210                 <td><?php if ( current_user_can('delete_post',$post->ID) ) { echo "<a href='post.php?action=delete&amp;post=$id' class='delete' onclick=\"return deleteSomething( 'post', " . $id . ", '" . sprintf(__("You are about to delete this post &quot;%s&quot;.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars(get_the_title('', ''), 1) ) . "' );\">" . __('Delete') . "</a>"; } ?></td>
     210                <td><?php if ( current_user_can('delete_post',$post->ID) ) { echo "<a href='post.php?action=delete&amp;post=$id' class='delete' onclick=\"return deleteSomething( 'post', " . $id . ", '" . sprintf(__("You are about to delete this post &quot;%s&quot;.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), addslashes(wp_specialchars(get_the_title(),'double')) ) . "' );\">" . __('Delete') . "</a>"; } ?></td>
    211211                <?php
    212212                break;
    213213
     
    246246        if ($comments) {
    247247        ?>
    248248<h3><?php _e('Comments') ?></h3>
    249 <ol id="comments">
     249<ol id="the-list">
    250250<?php
     251$i = 0;
    251252foreach ($comments as $comment) {
    252 $comment_status = wp_get_comment_status($comment->comment_ID);
     253$class = ( ++$i % 2 ) ? array('alternate') : array();
     254if ( 'unapproved' == $comment_status = wp_get_comment_status($comment->comment_ID) )
     255        $class[] = 'unapproved';
    253256?>
    254257
    255 <li <?php if ("unapproved" == $comment_status) echo "class='unapproved'"; ?> >
     258<li id='comment-<?php echo $comment->comment_ID; ?>'<?php if ( $class ) echo " class='" . join(' ', $class) . "'"; ?>>
    256259  <?php comment_date('Y-n-j') ?>
    257260  @
    258261  <?php comment_time('g:m:s a') ?>
    259262  <?php
    260263                        if ( current_user_can('edit_post', $post->ID) ) {
    261                                 echo "[ <a href=\"post.php?action=editcomment&amp;comment=".$comment->comment_ID."\">" .  __('Edit') . "</a>";
    262                                 echo " - <a href=\"post.php?action=deletecomment&amp;p=".$post->ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return confirm('" . sprintf(__("You are about to delete this comment by \'%s\'\\n  \'OK\' to delete, \'Cancel\' to stop."), $comment->comment_author) . "')\">" . __('Delete') . "</a> ";
     264                                echo "[ <a href='post.php?action=editcomment&amp;comment=".$comment->comment_ID."\'>" .  __('Edit') . '</a>';
     265                                echo ' - <a href="post.php?action=deletecomment&amp;p=' . $post->ID . '&amp;comment=' . $comment->comment_ID . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . sprintf(__("You are about to delete this comment by &quot;%s&quot;.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete."), wp_specialchars($comment->comment_author, 1)) . "' );\">" . __('Delete') . '</a> ';
    263266                                if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
    264                                         if ('approved' == wp_get_comment_status($comment->comment_ID)) {
    265                                                 echo " - <a href=\"post.php?action=unapprovecomment&amp;p=".$post->ID."&amp;comment=".$comment->comment_ID."\">" . __('Unapprove') . "</a> ";
    266                                         } else {
    267                                                 echo " - <a href=\"post.php?action=approvecomment&amp;p=".$post->ID."&amp;comment=".$comment->comment_ID."\">" . __('Approve') . "</a> ";
    268                                         }
     267                                        echo '<span class="unapprove"> - <a href="comment.php?action=unapprovecomment&amp;p=' . $post->ID . '&amp;comment=' . $comment->comment_ID . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\' );">' . __('Unapprove') . '</a> </span>';
     268                                        echo '<span class="approve"> - <a href="comment.php?action=approvecomment&amp;p=' . $post->ID . '&amp;comment=' . $comment->comment_ID . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\' );">' . __('Approve') . '</a> </span>';
    269269                                }
    270270                                echo "]";
    271271                        } // end if any comments to show
  • wp-admin/list-manipulation.js

     
    1 var listItems;
    2 var reg_color = '#FFFFFF';
    3 var alt_color = '#F1F1F1';
    4 
    5 addLoadEvent(getListItems);
    6 
    7 function deleteSomething( what, id, message ) {
    8         what.replace('-', ' ');
    9         if (!message) message = 'Are you sure you want to delete this ' + what + '?';
    10         if ( confirm(message) ) {
    11                 return ajaxDelete( what.replace(' ', '-'), id );
    12         } else {
    13                 return false;
    14         }
    15 }
    16 
    17 function getResponseElement() {
    18         var p = document.getElementById('ajax-response-p');
    19         if (!p) {
    20                 p = document.createElement('p');
    21                 p.id = 'ajax-response-p';
    22                 document.getElementById('ajax-response').appendChild(p);
    23                 return p;
    24         }
    25 }
    26 
    27 function ajaxDelete(what, id) {
    28         ajaxDel = new sack('list-manipulation.php');
    29         if ( ajaxDel.failed ) return true;
    30         ajaxDel.myResponseElement = getResponseElement();
    31         ajaxDel.method = 'POST';
    32         ajaxDel.onLoading = function() { ajaxDel.myResponseElement.innerHTML = 'Sending Data...'; };
    33         ajaxDel.onLoaded = function() { ajaxDel.myResponseElement.innerHTML = 'Data Sent...'; };
    34         ajaxDel.onInteractive = function() { ajaxDel.myResponseElement.innerHTML = 'Processing Data...'; };
    35         ajaxDel.onCompletion = function() { removeThisItem( what.replace('-as-spam', '') + '-' + id ); };
    36         ajaxDel.runAJAX('action=delete-' + what + '&id=' + id);
    37         return false;
    38 }
    39 
    40 function removeThisItem(id) {
    41         var response = ajaxDel.response;
    42         if ( isNaN(response) ) { alert(response); }
    43         response = parseInt(response, 10);
    44         if ( -1 == response ) { ajaxDel.myResponseElement.innerHTML = "You don't have permission to do that."; }
    45         else if ( 0 == response ) { ajaxDel.myResponseElement.interHTML = "Something odd happened.  Try refreshing the page? Either that or what you tried to delete never existed in the first place."; }
    46         else if ( 1 == response ) {
    47                 theItem = document.getElementById(id);
    48                 Fat.fade_element(id,null,700,'#FF3333');
    49                 setTimeout('theItem.parentNode.removeChild(theItem)', 705);
    50                 var pos = getListPos(id);
    51                 listItems.splice(pos,1);
    52                 recolorList(pos);
    53                 ajaxDel.myResponseElement.parentNode.removeChild(ajaxDel.myResponseElement);
    54 
    55         }
    56 }
    57 
    58 function getListPos(id) {
    59         for (var i = 0; i < listItems.length; i++) {
    60                 if (id == listItems[i]) {
    61                         var pos = i;
    62                         break;
    63                 }
    64         }
    65         return pos;
    66 }
    67 
    68 function getListItems() {
    69         if (list) return;
    70         listItems = new Array();
    71         var extra = false;
    72         var list = document.getElementById('the-list');
    73         if (!list) { var list = document.getElementById('the-list-x'); extra = true; }
    74         if (list) {
    75                 var items = list.getElementsByTagName('tr');
    76                 if (!items[0]) { items = list.getElementsByTagName('li'); }
    77                 for (var i=0; i<items.length; i++) { listItems.push(items[i].id); }
    78                 if (extra) { listItems.splice(0,1); }
    79         }
    80 }
    81 
    82 function recolorList(pos,dur,from) {
    83         if (!pos) pos = 0;
    84 
    85         if (!from) {
    86                 reg_from = alt_color;
    87                 alt_from = reg_color;
    88         } else {
    89                 reg_from = from;
    90                 alt_from = from;
    91         }
    92         for (var i = pos; i < listItems.length; i++) {
    93                 if (i % 2 == 1) Fat.fade_element(listItems[i],null,dur,reg_from,reg_color);
    94                 else Fat.fade_element(listItems[i],null,dur,alt_from,alt_color);
    95         }
    96 }
  • wp-admin/categories.php

     
    33
    44$title = __('Categories');
    55$parent_file = 'edit.php';
    6 $list_js = true;
    76
    87$wpvarstoreset = array('action','cat');
    98for ($i=0; $i<count($wpvarstoreset); $i += 1) {
     
    104103
    105104default:
    106105
     106$list_js = true;
    107107require_once ('admin-header.php');
    108108
    109109$messages[1] = __('Category added.');
     
    149149    <form name="addcat" id="addcat" action="categories.php" method="post">
    150150       
    151151        <p><?php _e('Name:') ?><br />
    152         <input type="text" name="cat_name" value="" /></p>
     152        <input type="text" name="cat_name" id="cat_name" value="" /></p>
    153153        <p><?php _e('Category parent:') ?><br />
    154         <select name='category_parent' class='postform'>
     154        <select name='category_parent' id='category_parent' class='postform'>
    155155        <option value='0'><?php _e('None') ?></option>
    156156        <?php wp_dropdown_cats(0); ?>
    157157        </select></p>
    158158        <p><?php _e('Description: (optional)') ?> <br />
    159         <textarea name="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p>
     159        <textarea name="category_description" id="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p>
    160160        <p class="submit"><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="<?php _e('Add Category &raquo;') ?>" /></p>
    161161    </form>
    162162</div>