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

git-svn-id: http://svn.automattic.com/wordpress/trunk@3660 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-03-29 01:51:55 +00:00
parent ee60500f1f
commit baa30dd4d8
24 changed files with 595 additions and 445 deletions

216
wp-admin/admin-ajax.php Normal file
View File

@ -0,0 +1,216 @@
<?php
require_once('../wp-config.php');
require_once('admin-functions.php');
require_once('admin-db.php');
define('DOING_AJAX', true);
check_ajax_referer();
if ( !is_user_logged_in() )
die('-1');
function get_out_now() { exit; }
add_action( 'shutdown', 'get_out_now', -1 );
function wp_clean_ajax_input( $i ) {
global $wpdb;
$i = is_array($i) ? array_map('wp_clean_ajax_input', $i) : $wpdb->escape( rawurldecode(stripslashes($i)) );
return $i;
}
function wp_ajax_echo_meta( $pid, $mid, $key, $value ) {
$value = wp_specialchars($value, true);
$key_js = addslashes(wp_specialchars($key, 'double'));
$key = wp_specialchars($key, true);
$r = "<meta><id>$mid</id><postid>$pid</postid><newitem><![CDATA[<table><tbody>";
$r .= "<tr id='meta-$mid'><td valign='top'>";
$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' />";
$r .= "</td><td><textarea name='meta[$mid][value]' tabindex='6' rows='2' cols='30'>$value</textarea></td><td align='center'>";
$r .= "<input name='updatemeta' type='button' class='updatemeta' tabindex='6' value='Update' onclick='return theList.ajaxUpdater(&#039;meta&#039;,&#039;meta-$mid&#039;);' /><br />";
$r .= "<input name='deletemeta[$mid]' type='submit' onclick=\"return deleteSomething( 'meta', $mid, '";
$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);
$r .= "' );\" class='deletemeta' tabindex='6' value='Delete' />";
$r .= "</td></tr></tbody></table>]]></newitem></meta>";
return $r;
}
$_POST = wp_clean_ajax_input( $_POST );
$id = (int) $_POST['id'];
switch ( $_POST['action'] ) :
case 'delete-comment' :
if ( !$comment = get_comment( $id ) )
die('0');
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
die('-1');
if ( wp_delete_comment( $comment->comment_ID ) )
die('1');
else die('0');
break;
case 'delete-comment-as-spam' :
if ( !$comment = get_comment( $id ) )
die('0');
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
die('-1');
if ( wp_set_comment_status( $comment->comment_ID, 'spam' ) )
die('1');
else die('0');
break;
case 'delete-cat' :
if ( !current_user_can( 'manage_categories' ) )
die('-1');
if ( wp_delete_category( $id ) )
die('1');
else die('0');
break;
case 'delete-link' :
if ( !current_user_can( 'manage_links' ) )
die('-1');
if ( wp_delete_link( $id ) )
die('1');
else die('0');
break;
case 'delete-meta' :
if ( !$meta = get_post_meta_by_id( $id ) )
die('0');
if ( !current_user_can( 'edit_post', $meta->post_id ) )
die('-1');
if ( delete_meta( $meta->meta_id ) )
die('1');
die('0');
break;
case 'delete-post' :
if ( !current_user_can( 'delete_post', $id ) )
die('-1');
if ( wp_delete_post( $id ) )
die('1');
else die('0');
break;
case 'delete-page' :
if ( !current_user_can( 'delete_page', $id ) )
die('-1');
if ( wp_delete_post( $id ) )
die('1');
else die('0');
break;
case 'dim-comment' :
if ( !$comment = get_comment( $id ) )
die('0');
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
die('-1');
if ( !current_user_can( 'moderate_comments' ) )
die('-1');
if ( 'unapproved' == wp_get_comment_status($comment->comment_ID) ) {
if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) )
die('1');
} else {
if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) )
die('1');
}
die('0');
break;
case 'add-category' : // On the Fly
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$names = explode(',', $_POST['newcat']);
$r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
foreach ( $names as $cat_name ) {
$cat_name = trim($cat_name);
if ( !$category_nicename = sanitize_title($cat_name) )
die('0');
if ( !$cat_id = category_exists( $cat_name ) )
$cat_id = wp_create_category( $cat_name );
$cat_name = wp_specialchars(stripslashes($cat_name));
$r .= "<category><id>$cat_id</id><newitem><![CDATA[";
$r .= "<li id='category-$cat_id'><label for='in-category-$cat_id' class='selectit'>";
$r .= "<input value='$cat_id' type='checkbox' checked='checked' name='post_category[]' id='in-category-$cat_id'/> $cat_name</label></li>";
$r .= "]]></newitem></category>";
}
$r .= '</ajaxresponse>';
header('Content-type: text/xml');
die($r);
break;
case 'add-cat' : // From Manage->Categories
if ( !current_user_can( 'manage_categories' ) )
die('-1');
if ( !$cat = wp_insert_category( $_POST ) )
die('0');
if ( !$cat = get_category( $cat ) )
die('0');
$pad = 0;
$_cat = $cat;
while ( $_cat->category_parent ) {
$_cat = get_category( $_cat->category_parent );
$pad++;
}
$pad = str_repeat('&#8212; ', $pad);
$r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
$r .= "<cat><id>$cat->cat_ID</id><newitem><![CDATA[<table><tbody>";
$r .= "<tr id='cat-$cat->cat_ID'><th scope='row'>$cat->cat_ID</th><td>$pad $cat->cat_name</td>";
$r .= "<td>$cat->category_description</td><td>$cat->category_count</td><td>$cat->link_count</td>";
$r .= "<td><a href='categories.php?action=edit&amp;cat_ID=$cat->cat_ID' class='edit'>" . __('Edit') . "</a></td>";
$r .= "<td><a href='categories.php?action=delete&amp;cat_ID=$cat->cat_ID' onclick='return deleteSomething( \"cat\", $cat->cat_ID, \"";
$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));
$r .= "\" );' class='delete'>".__('Delete')."</a></td></tr>";
$r .= "</tbody></table>]]></newitem></cat></ajaxresponse>";
header('Content-type: text/xml');
die($r);
break;
case 'add-meta' :
if ( !current_user_can( 'edit_post', $id ) )
die('-1');
if ( $id < 0 ) {
if ( $pid = write_post() )
$meta = has_meta( $pid );
else
die('0');
$key = $meta[0]['meta_key'];
$value = $meta[0]['meta_value'];
$mid = (int) $meta[0]['meta_id'];
} else {
if ( $mid = add_meta( $id ) )
$meta = get_post_meta_by_id( $mid );
else
die('0');
$key = $meta->meta_key;
$value = $meta->meta_value;
$pid = (int) $meta->post_id;
}
$r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
$r .= wp_ajax_echo_meta( $pid, $mid, $key, $value );
$r .= '</ajaxresponse>';
header('Content-type: text/xml');
die($r);
break;
case 'update-meta' :
$mid = (int) array_pop(array_keys($_POST['meta']));
$key = $_POST['meta'][$mid]['key'];
$value = $_POST['meta'][$mid]['value'];
if ( !$meta = get_post_meta_by_id( $mid ) )
die('0');
if ( !current_user_can( 'edit_post', $meta->post_id ) )
die('-1');
$r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
if ( $u = update_meta( $mid, $key, $value ) ) {
$key = stripslashes($key);
$value = stripslashes($value);
$r .= wp_ajax_echo_meta( $meta->post_id, $mid, $key, $value );
}
$r .= '</ajaxresponse>';
header('Content-type: text/xml');
die($r);
break;
default :
die('0');
break;
endswitch;
?>

View File

@ -174,7 +174,8 @@ function wp_delete_category($cat_ID) {
$parent = $category->category_parent;
// Delete the category.
$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") )
return 0;
// Update children to point to new parent.
$wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'");

View File

@ -602,12 +602,12 @@ function get_nested_categories($default = 0, $parent = 0) {
function write_nested_categories($categories) {
foreach ($categories as $category) {
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";
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";
if (isset ($category['children'])) {
echo "\n<span class='cat-nest'>\n";
if ( $category['children'] ) {
echo "<ul>\n";
write_nested_categories($category['children']);
echo "</span>\n";
echo "</ul>\n";
}
}
}
@ -626,7 +626,7 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) {
if ($categories) {
foreach ($categories as $category) {
if ($category->category_parent == $parent) {
$category->cat_name = wp_specialchars($category->cat_name);
$category->cat_name = wp_specialchars($category->cat_name,'double');
$pad = str_repeat('&#8212; ', $level);
if ( current_user_can('manage_categories') ) {
$edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>";
@ -634,7 +634,7 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) {
$default_link_cat_id = get_option('default_link_category');
if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) )
$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>";
$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>";
else
$edit .= "<td style='text-align:center'>".__("Default");
}
@ -684,7 +684,7 @@ function page_rows($parent = 0, $level = 0, $pages = 0, $hierarchy = true) {
<td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>
<td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td>
<td><?php if ( current_user_can('edit_page', $id) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>
<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>
<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>
</tr>
<?php
@ -828,19 +828,21 @@ function has_meta($postid) {
function list_meta($meta) {
global $post_ID;
// Exit if no meta
if (!$meta)
if (!$meta) {
echo '<tbody id="the-list"></tbody>'; //TBODY needed for list-manipulation JS
return;
}
$count = 0;
?>
<table id='meta-list' cellpadding="3">
<thead>
<tr>
<th><?php _e('Key') ?></th>
<th><?php _e('Value') ?></th>
<th colspan='2'><?php _e('Action') ?></th>
</tr>
</thead>
<?php
$r ="\n\t<tbody id='the-list'>";
foreach ($meta as $entry) {
++ $count;
if ($count % 2)
@ -849,18 +851,20 @@ function list_meta($meta) {
$style = '';
if ('_' == $entry['meta_key'] { 0 })
$style .= ' hidden';
echo "
<tr class='$style'>
<td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>
<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>
<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__('Update')."' /><br />
<input name='deletemeta[{$entry['meta_id']}]' type='submit' class='deletemeta' tabindex='6' value='".__('Delete')."' /></td>
</tr>
";
$key_js = addslashes(wp_specialchars( $entry['meta_key'], 'double' ));
$entry['meta_key'] = wp_specialchars( $entry['meta_key'], true );
$entry['meta_value'] = wp_specialchars( $entry['meta_value'], true );
$r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
$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>";
$r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
$r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__('Update')."' /><br />";
$r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '";
$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);
$r .= "' );\" class='deletemeta' tabindex='6' value='".__('Delete')."' /></td>";
$r .= "\n\t</tr>";
}
echo "
</table>
";
echo $r;
echo "\n\t</tbody>";
}
// Get a list of previously defined keys
@ -886,7 +890,7 @@ function meta_form() {
LIMIT 10");
?>
<h3><?php _e('Add a new custom field:') ?></h3>
<table cellspacing="3" cellpadding="3">
<table id="newmeta" cellspacing="3" cellpadding="3">
<tr>
<th colspan="2"><?php _e('Key') ?></th>
<th><?php _e('Value') ?></th>
@ -910,13 +914,14 @@ function meta_form() {
</tr>
</table>
<p class="submit"><input type="submit" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field &raquo;') ?>" /></p>
<p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field &raquo;') ?>" /></p>
<?php
}
function add_meta($post_ID) {
global $wpdb;
$post_ID = (int) $post_ID;
$metakeyselect = $wpdb->escape(stripslashes(trim($_POST['metakeyselect'])));
$metakeyinput = $wpdb->escape(stripslashes(trim($_POST['metakeyinput'])));
@ -926,7 +931,7 @@ function add_meta($post_ID) {
// We have a key/value pair. If both the select and the
// input for the key have data, the input takes precedence:
if ('#NONE#' != $metakeyselect)
if ('#NONE#' != $metakeyselect)
$metakey = $metakeyselect;
if ($metakeyinput)
@ -937,21 +942,32 @@ function add_meta($post_ID) {
(post_id,meta_key,meta_value)
VALUES ('$post_ID','$metakey','$metavalue')
");
return $wpdb->insert_id;
}
return false;
} // add_meta
function delete_meta($mid) {
global $wpdb;
$mid = (int) $mid;
$result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'");
return $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'");
}
function update_meta($mid, $mkey, $mvalue) {
global $wpdb;
$mid = (int) $mid;
return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'");
}
function get_post_meta_by_id($mid) {
global $wpdb;
$mid = (int) $mid;
return $wpdb->get_row("SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'");
}
function touch_time($edit = 1, $for_post = 1) {
global $month, $post, $comment;

View File

@ -3,10 +3,13 @@
if (!isset($_GET["page"])) require_once('admin.php');
if ( $editing ) {
$dbx_js = true;
if ( current_user_can('manage_categories') )
$pmeta_js = true;
if ( current_user_can('manage_categories') ) {
$list_js = true;
$cat_js = true;
}
}
if ( $list_js || $cat_js )
if ( $list_js )
$sack_js = true;
?>
<?php get_admin_page_title(); ?>
@ -29,7 +32,13 @@ function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}el
<script type="text/javascript" src="../wp-includes/js/tw-sack.js"></script>
<?php } ?>
<?php if ( $list_js ) { ?>
<script type="text/javascript" src="list-manipulation.js"></script>
<script type="text/javascript" src="list-manipulation-js.php"></script>
<?php } ?>
<?php if ( $pmeta_js ) { ?>
<script type="text/javascript" src="custom-fields.js"></script>
<?php } ?>
<?php if ( 'categories.php' == $pagenow && 'edit' != $action ) { ?>
<script type="text/javascript" src="categories.js"></script>
<?php } ?>
<?php if ( $dbx_js ) { ?>
<script type="text/javascript" src="../wp-includes/js/dbx.js"></script>

View File

@ -40,7 +40,7 @@ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
}
}
$xfn_js = $sack_js = $list_js = $cat_js = $dbx_js = $editing = false;
$xfn_js = $sack_js = $list_js = $cat_js = $dbx_js = $pmeta_js = $editing = false;
require(ABSPATH . '/wp-admin/menu.php');

View File

@ -2,9 +2,8 @@
require_once('../wp-config.php');
header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true);
?>
var ajaxCat = new sack();
var newcat;
addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.clearInputs.push('newcat');});
addLoadEvent(newCatAddIn);
function newCatAddIn() {
if ( !document.getElementById('jaxcat') ) return false;
var ajaxcat = document.createElement('span');
@ -16,163 +15,21 @@ function newCatAddIn() {
newcat.id = 'newcat';
newcat.size = '16';
newcat.setAttribute('autocomplete', 'off');
newcat.onkeypress = ajaxNewCatKeyPress;
newcat.onkeypress = function(e) { return killSubmit("catList.ajaxAdder('category','categorydiv');", e); };
var newcatSub = document.createElement('input');
newcatSub.type = 'button';
newcatSub.name = 'Button';
newcatSub.id = 'catadd';
newcatSub.value = '<?php echo addslashes(__('Add')); ?>';
newcatSub.onclick = ajaxNewCat;
newcatSub.value = 'Add';
newcatSub.onclick = function() { catList.ajaxAdder('category', 'categorydiv'); };
ajaxcat.appendChild(newcat);
ajaxcat.appendChild(newcatSub);
document.getElementById('jaxcat').appendChild(ajaxcat);
howto = document.createElement('span');
howto.innerHTML = '<?php echo addslashes(__('Separate multiple categories with commas.')); ?>';
howto.innerHTML = "<?php _e('Separate multiple categories with commas.'); ?>";
howto.id = 'howto';
ajaxcat.appendChild(howto);
}
addLoadEvent(newCatAddIn);
function getResponseElement() {
var p = document.getElementById('ajaxcatresponse');
if (!p) {
p = document.createElement('span');
document.getElementById('jaxcat').appendChild(p);
p.id = 'ajaxcatresponse';
}
return p;
}
function newCatLoading() {
var p = getResponseElement();
p.innerHTML = '<?php echo addslashes(__('Sending Data...')); ?>';
}
function newCatLoaded() {
var p = getResponseElement();
p.innerHTML = '<?php echo addslashes(__('Data Sent...')); ?>';
}
function newCatInteractive() {
var p = getResponseElement();
p.innerHTML = '<?php echo addslashes(__('Processing Request...')); ?>';
}
function newCatCompletion() {
var p = getResponseElement();
var id = 0;
var ids = new Array();
var names = new Array();
ids = myPload( ajaxCat.response );
names = myPload( newcat.value );
for ( i = 0; i < ids.length; i++ ) {
id = ids[i].replace(/[\n\r]+/g, "");
if ( id == '-1' ) {
p.innerHTML = "<?php echo addslashes(__("You don't have permission to do that.")); ?>";
return;
}
if ( id == '0' ) {
p.innerHTML = "<?php echo addslashes(__('That category name is invalid. Try something else.')); ?>";
return;
}
var exists = document.getElementById('category-' + id);
if (exists) {
var moveIt = exists.parentNode;
var container = moveIt.parentNode;
container.removeChild(moveIt);
container.insertBefore(moveIt, container.firstChild);
moveIt.id = 'new-category-' + id;
exists.checked = 'checked';
var nowClass = moveIt.className;
moveIt.className = nowClass + ' fade';
Fat.fade_all();
moveIt.className = nowClass;
} else {
var catDiv = document.getElementById('categorychecklist');
var newLabel = document.createElement('label');
newLabel.setAttribute('for', 'category-' + id);
newLabel.id = 'new-category-' + id;
newLabel.className = 'selectit fade';
var newCheck = document.createElement('input');
newCheck.type = 'checkbox';
newCheck.value = id;
newCheck.name = 'post_category[]';
newCheck.id = 'category-' + id;
newLabel.appendChild(newCheck);
var newLabelText = document.createTextNode(' ' + names[i]);
newLabel.appendChild(newLabelText);
catDiv.insertBefore(newLabel, catDiv.firstChild);
newCheck.checked = 'checked';
Fat.fade_all();
newLabel.className = 'selectit';
}
newcat.value = '';
}
p.parentNode.removeChild(p);
// var id = parseInt(ajaxCat.response, 10);
}
function ajaxNewCatKeyPress(e) {
if (!e) {
if (window.event) {
e = window.event;
} else {
return;
}
}
if (e.keyCode == 13) {
ajaxNewCat();
e.returnValue = false;
e.cancelBubble = true;
return false;
}
}
function ajaxNewCat() {
var newcat = document.getElementById('newcat');
var split_cats = new Array(1);
var catString = '';
catString = 'ajaxnewcat=' + encodeURIComponent(newcat.value);
ajaxCat.requestFile = 'edit-form-ajax-cat.php';
ajaxCat.method = 'GET';
ajaxCat.onLoading = newCatLoading;
ajaxCat.onLoaded = newCatLoaded;
ajaxCat.onInteractive = newCatInteractive;
ajaxCat.onCompletion = newCatCompletion;
ajaxCat.runAJAX(catString);
}
function myPload( str ) {
var fixedExplode = new Array();
var comma = new String(',');
var count = 0;
var currentElement = '';
for( x=0; x < str.length; x++) {
andy = str.charAt(x);
if ( comma.indexOf(andy) != -1 ) {
currentElement = currentElement.replace(new RegExp('^\\s*(.*?)\\s*$', ''), '$1'); // trim
fixedExplode[count] = currentElement;
currentElement = "";
count++;
} else {
currentElement += andy;
}
}
if ( currentElement != "" )
fixedExplode[count] = currentElement;
return fixedExplode;
}

6
wp-admin/categories.js Normal file
View File

@ -0,0 +1,6 @@
addLoadEvent(newCategoryAddIn);
function newCategoryAddIn() {
if (!theList.theList) return false;
document.forms.addcat.submit.onclick = function(e) {return killSubmit('theList.ajaxAdder("cat", "addcat");', e); };
theList.clearInputs.push('cat_name','category_parent','category_description');
}

View File

@ -3,7 +3,6 @@ require_once('admin.php');
$title = __('Categories');
$parent_file = 'edit.php';
$list_js = true;
$wpvarstoreset = array('action','cat');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
@ -104,6 +103,7 @@ break;
default:
$list_js = true;
require_once ('admin-header.php');
$messages[1] = __('Category added.');
@ -121,7 +121,8 @@ $messages[3] = __('Category updated.');
<?php else : ?>
<h2><?php _e('Categories') ?> </h2>
<?php endif; ?>
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
<table width="100%" cellpadding="3" cellspacing="3">
<thead>
<tr>
<th scope="col"><?php _e('ID') ?></th>
<th scope="col"><?php _e('Name') ?></th>
@ -130,9 +131,12 @@ $messages[3] = __('Category updated.');
<th scope="col"><?php _e('# Bookmarks') ?></th>
<th colspan="2"><?php _e('Action') ?></th>
</tr>
</thead>
<tbody id="the-list">
<?php
cat_rows();
?>
</tbody>
</table>
<div id="ajax-response"></div>
@ -149,14 +153,14 @@ cat_rows();
<form name="addcat" id="addcat" action="categories.php" method="post">
<p><?php _e('Name:') ?><br />
<input type="text" name="cat_name" value="" /></p>
<input type="text" name="cat_name" id="cat_name" value="" /></p>
<p><?php _e('Category parent:') ?><br />
<select name='category_parent' class='postform'>
<select name='category_parent' id='category_parent' class='postform'>
<option value='0'><?php _e('None') ?></option>
<?php wp_dropdown_cats(0); ?>
</select></p>
<p><?php _e('Description: (optional)') ?> <br />
<textarea name="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p>
<textarea name="category_description" id="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p>
<p class="submit"><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="<?php _e('Add Category &raquo;') ?>" /></p>
</form>
</div>

25
wp-admin/custom-fields.js Normal file
View File

@ -0,0 +1,25 @@
addLoadEvent(customFieldsAddIn);
function customFieldsAddIn() {
if (!theList.theList) return false;
inputs = theList.theList.getElementsByTagName('input');
for ( var i=0; i < inputs.length; i++ ) {
if ('text' == inputs[i].type) {
inputs[i].setAttribute('autocomplete', 'off');
inputs[i].onkeypress = function(e) {return killSubmit('theList.ajaxUpdater("meta", "meta-' + parseInt(this.name.slice(5),10) + '");', e); };
}
if ('updatemeta' == inputs[i].className) {
inputs[i].onclick = function(e) {return killSubmit('theList.ajaxUpdater("meta", "meta-' + parseInt(this.parentNode.parentNode.id.slice(5),10) + '");', e); };
}
}
document.getElementById('metakeyinput').onkeypress = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta", customFieldsOnComplete);', e); };
document.getElementById('updatemetasub').onclick = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta", customFieldsOnComplete);', e); };
theList.clearInputs.push('metakeyselect','metakeyinput','metavalue');
}
function customFieldsOnComplete() {
var pidEl = document.getElementById('post_ID');
pidEl.name = 'post_ID';
pidEl.value = getNodeValue(theList.ajaxAdd.responseXML, 'postid');
var aEl = document.getElementById('hiddenaction')
if ( aEl.value == 'post' ) aEl.value = 'postajaxpost';
}

View File

@ -133,13 +133,13 @@ if ('view' == $mode) {
| <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php _e('View Post') ?></a></p>
</li>
<?php } // end foreach ?>
<?php } // end foreach($comment) ?>
</ol>
<div id="ajax-response"></div>
<?php
} else {
} else { //no comments to show
?>
<p>
@ -162,19 +162,28 @@ if ('view' == $mode) {
</tr>';
foreach ($comments as $comment) {
$authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
$comment_status = wp_get_comment_status($comment->comment_ID);
$class = ('alternate' == $class) ? '' : 'alternate';
$class .= ('unapproved' == $comment_status) ? ' unapproved' : '';
?>
<tr class='<?php echo $class; ?>'>
<tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
<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>
<td><?php comment_author_link() ?></td>
<td><?php comment_author_email_link() ?></td>
<td><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></td>
<td><?php comment_excerpt(); ?></td>
<td><a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a></td>
<td>
<?php if ('unapproved' == $comment_status) { ?>
(Unapproved)
<?php } else { ?>
<a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a>
<?php } ?>
</td>
<td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
echo "<a href='comment.php?action=editcomment&amp;comment=$comment->comment_ID' class='edit'>" . __('Edit') . "</a>"; } ?></td>
<td><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
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>
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> ";
} ?></td>
</tr>
<?php
} // end foreach
@ -183,6 +192,7 @@ if ('view' == $mode) {
<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 + '"); ?>')" />
<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>
</form>
<div id="ajax-response"></div>
<?php
} else {
?>

View File

@ -21,10 +21,10 @@ $messages[3] = __('Custom field deleted.');
if (0 == $post_ID) {
$form_action = 'post';
$temp_ID = -1 * time();
$form_extra = "<input type='hidden' name='temp_ID' value='$temp_ID' />";
$form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />";
} else {
$form_action = 'editpost';
$form_extra = "<input type='hidden' name='post_ID' value='$post_ID' />";
$form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />";
}
$form_pingback = '<input type="hidden" name="post_pingback" value="' . get_option('default_pingback_flag') . '" id="post_pingback" />';
@ -49,7 +49,7 @@ if (empty($post->post_status)) $post->post_status = 'draft';
?>
<input type="hidden" name="user_ID" value="<?php echo $user_ID ?>" />
<input type="hidden" name="action" value="<?php echo $form_action ?>" />
<input type="hidden" id="hiddenaction" name="action" value="<?php echo $form_action ?>" />
<input type="hidden" name="post_author" value="<?php echo $post->post_author ?>" />
<input type="hidden" name="post_type" value="post" />
@ -72,7 +72,7 @@ addLoadEvent(focusit);
<h3 class="dbx-handle"><?php _e('Categories') ?></h3>
<div class="dbx-content">
<p id="jaxcat"></p>
<div id="categorychecklist"><?php dropdown_categories(get_settings('default_category')); ?></div></div>
<ul id="categorychecklist"><?php dropdown_categories(get_settings('default_category')); ?></ul></div>
</fieldset>
<fieldset id="commentstatusdiv" class="dbx-box">
@ -248,16 +248,17 @@ if ( ! empty($pings) )
<fieldset id="postcustom" class="dbx-box">
<h3 class="dbx-handle"><?php _e('Custom Fields') ?></h3>
<div id="postcustomstuff" class="dbx-content">
<?php
if($metadata = has_meta($post_ID)) {
?>
<table cellpadding="3">
<?php
list_meta($metadata);
$metadata = has_meta($post_ID);
list_meta($metadata);
?>
</table>
<?php
}
meta_form();
?>
<div id="ajax-response"></div>
</div>
</fieldset>

View File

@ -1,35 +0,0 @@
<?php
require_once('../wp-config.php');
require_once('admin-functions.php');
require_once('admin-db.php');
if ( !current_user_can('manage_categories') )
die('-1');
function get_out_now() { exit; }
add_action('shutdown', 'get_out_now', -1);
$names = explode(',', rawurldecode($_GET['ajaxnewcat']) );
$ids = array();
foreach ($names as $cat_name) {
$cat_name = trim( $cat_name );
if ( !$category_nicename = sanitize_title($cat_name) )
continue;
if ( $already = category_exists($cat_name) ) {
$ids[] = (string) $already;
continue;
}
$new_cat_id = wp_create_category($cat_name);
$ids[] = (string) $new_cat_id;
}
$return = join(',', $ids);
die( (string) $return );
?>

View File

@ -6,10 +6,10 @@
if (0 == $post_ID) {
$form_action = 'post';
$temp_ID = -1 * time();
$form_extra = "<input type='hidden' name='temp_ID' value='$temp_ID' />";
$form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />";
} else {
$form_action = 'editpost';
$form_extra = "<input type='hidden' name='post_ID' value='$post_ID' />";
$form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />";
}
$sendto = $_SERVER['HTTP_REFERER'];
@ -209,14 +209,14 @@ if (current_user_can('upload_files')) {
<fieldset id="postcustom" class="dbx-box">
<h3 class="dbx-handle"><?php _e('Custom Fields') ?></h3>
<div id="postcustomstuff" class="dbx-content">
<table cellpadding="3">
<?php
if($metadata = has_meta($post_ID)) {
$metadata = has_meta($post_ID);
list_meta($metadata);
?>
</table>
<?php
list_meta($metadata);
?>
<?php
}
meta_form();
?>
</div>

View File

@ -28,20 +28,24 @@ else
if ($posts) {
?>
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
<tr>
<th scope="col"><?php _e('ID') ?></th>
<th scope="col"><?php _e('Title') ?></th>
<table width="100%" cellpadding="3" cellspacing="3">
<thead>
<tr>
<th scope="col"><?php _e('ID') ?></th>
<th scope="col"><?php _e('Title') ?></th>
<th scope="col"><?php _e('Owner') ?></th>
<th scope="col"><?php _e('Updated') ?></th>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody id="the-list">
<?php
page_rows(0, 0, $posts, $all);
?>
</table>
</tbody>
</table>
<div id="ajax-response"></div>

View File

@ -114,7 +114,6 @@ if ( count($arc_result) ) { ?>
<br style="clear:both;" />
<?php
// define the columns to display, the syntax is 'internal name' => 'display name'
$posts_columns = array(
'id' => __('ID'),
@ -133,7 +132,8 @@ $posts_columns['control_delete'] = '';
?>
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
<table width="100%" cellpadding="3" cellspacing="3">
<thead>
<tr>
<?php foreach($posts_columns as $column_display_name) { ?>
@ -141,10 +141,13 @@ $posts_columns['control_delete'] = '';
<?php } ?>
</tr>
</thead>
<tbody id="the-list">
<?php
if ($posts) {
$bgcolor = '';
foreach ($posts as $post) { start_wp();
add_filter('the_title','wp_specialchars');
$class = ('alternate' == $class) ? '' : 'alternate';
?>
<tr id='post-<?php echo $id; ?>' class='<?php echo $class; ?>'>
@ -207,7 +210,7 @@ foreach($posts_columns as $column_name=>$column_display_name) {
case 'control_delete':
?>
<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>
<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>
<?php
break;
@ -229,7 +232,8 @@ foreach($posts_columns as $column_name=>$column_display_name) {
</tr>
<?php
} // end if ($posts)
?>
?>
</tbody>
</table>
<div id="ajax-response"></div>
@ -246,26 +250,26 @@ if ( 1 == count($posts) ) {
if ($comments) {
?>
<h3><?php _e('Comments') ?></h3>
<ol id="comments">
<ol id="the-list">
<?php
$i = 0;
foreach ($comments as $comment) {
$comment_status = wp_get_comment_status($comment->comment_ID);
$class = ( ++$i % 2 ) ? array('alternate') : array();
if ( 'unapproved' == $comment_status = wp_get_comment_status($comment->comment_ID) )
$class[] = 'unapproved';
?>
<li <?php if ("unapproved" == $comment_status) echo "class='unapproved'"; ?> >
<li id='comment-<?php echo $comment->comment_ID; ?>'<?php if ( $class ) echo " class='" . join(' ', $class) . "'"; ?>>
<?php comment_date('Y-n-j') ?>
@
<?php comment_time('g:m:s a') ?>
<?php
if ( current_user_can('edit_post', $post->ID) ) {
echo "[ <a href=\"post.php?action=editcomment&amp;comment=".$comment->comment_ID."\">" . __('Edit') . "</a>";
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> ";
echo "[ <a href='post.php?action=editcomment&amp;comment=".$comment->comment_ID."\'>" . __('Edit') . '</a>';
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> ';
if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
if ('approved' == wp_get_comment_status($comment->comment_ID)) {
echo " - <a href=\"post.php?action=unapprovecomment&amp;p=".$post->ID."&amp;comment=".$comment->comment_ID."\">" . __('Unapprove') . "</a> ";
} else {
echo " - <a href=\"post.php?action=approvecomment&amp;p=".$post->ID."&amp;comment=".$comment->comment_ID."\">" . __('Approve') . "</a> ";
}
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>';
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>';
}
echo "]";
} // end if any comments to show

View File

@ -114,7 +114,8 @@ bookmarks ordered by
<input type="hidden" name="action" value="" />
<input type="hidden" name="order_by" value="<?php echo wp_specialchars($order_by, 1); ?>" />
<input type="hidden" name="cat_id" value="<?php echo (int) $cat_id ?>" />
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
<table width="100%" cellpadding="3" cellspacing="3">
<thead>
<tr>
<th width="15%"><?php _e('Name') ?></th>
<th><?php _e('URI') ?></th>
@ -124,6 +125,8 @@ bookmarks ordered by
<th colspan="2"><?php _e('Action') ?></th>
<th><input type="checkbox" onclick="checkAll(document.getElementById('links'));" /></th>
</tr>
</thead>
<tbody id="the-list">
<?php
if ( 'all' == $cat_id )
$cat_id = '';
@ -174,6 +177,7 @@ if ($links)
echo "\n </tr>\n";
}
?>
</tbody>
</table>
<div id="ajax-response"></div>
@ -182,4 +186,4 @@ if ($links)
</div>
</form>
<?php include('admin-footer.php'); ?>
<?php include('admin-footer.php'); ?>

View File

@ -0,0 +1,160 @@
<?php
require_once('admin.php');
header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true);
?>
addLoadEvent(function(){theList=new listMan();});
function deleteSomething(what,id,message){if(!message)message="<?php printf(__('Are you sure you want to delete this %s?'),"'+what+'"); ?>";if(confirm(message))return theList.ajaxDelete(what,id);else return false;}
function dimSomething(what,id,dimClass){return theList.ajaxDimmer(what,id,dimClass);}
function WPAjax(file, responseEl){//class WPAjax extends sack
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; }
this.parseAjaxResponse=function(){
if(isNaN(this.response)){this.myResponseElement.innerHTML="<?php _e('Error: '); ?>"+this.response;return false;}
this.response=parseInt(this.response,10);
if(-1==this.response){this.myResponseElement.innerHTML="<?php _e("You don't have permission to do that."); ?>";return false;}
else if(0==this.response){this.myResponseElement.innerHTML="<?php _e("Something odd happened. Try refreshing the page? Either that or what you tried to change never existed in the first place."); ?>";return false;}
return true;
}
this.parseAjaxResponseXML=function(){
if(this.responseXML&&typeof this.responseXML=='object')return true;
if(isNaN(this.response)){this.myResponseElement.innerHTML="<?php _e('Error: '); ?>"+this.response;return false;}
var r=parseInt(this.response,10);
if(-1==r){this.myResponseElement.innerHTML="<?php _e("You don't have permission to do that."); ?>";}
else if(0==r){this.myResponseElement.innerHTML="<?php _e("Invalid Entry."); ?>";}
return false;
}
this.init(file,responseEl);
} WPAjax.prototype=new sack;
WPAjax.prototype.init=function(f,r){
this.URLString=this.encVar('cookie', document.cookie);
this.requestFile=f;this.getResponseElement(r);this.method='POST';
this.onLoading=function(){this.myResponseElement.innerHTML="<?php _e('Sending Data...'); ?>";};
this.onLoaded=function(){this.myResponseElement.innerHTML="<?php _e('Data Sent...'); ?>";};
this.onInteractive=function(){this.myResponseElement.innerHTML="<?php _e('Processing Data...'); ?>";};
}
function listMan(theListId){
this.theList=null;
this.ajaxRespEl=null;
this.inputData='';
this.clearInputs=new Array();
var reg_color='#FFFFFF';
var alt_color='#F1F1F1';
var listItems;
var listType;
self.aTrap=0;
this.ajaxAdder=function(what,where,onComplete,update){//for TR, server must wrap TR in TABLE TBODY. this.makeEl cleans it
if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300);
this.ajaxAdd=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
if(this.ajaxAdd.failed)return true;
this.grabInputs(where);
var tempObj=this;
this.ajaxAdd.onCompletion=function(){
if(!this.parseAjaxResponseXML())return;
var newItems=this.responseXML.getElementsByTagName(what);
if(newItems){for (c=0;c<newItems.length;c++){
var id=parseInt(getNodeValue(newItems[c],'id'),10);
var exists=document.getElementById(what+'-'+id);
if(exists)tempObj.replaceListItem(exists.id,getNodeValue(newItems[c],'newitem'),update);
else tempObj.addListItem(getNodeValue(newItems[c],'newitem'));
}}
this.myResponseElement.innerHTML='';tempObj.inputData='';
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){}}
if(onComplete&&typeof onComplete=='function')onComplete();
}
this.ajaxAdd.runAJAX('action='+(update?'update-':'add-')+what+this.inputData);
return false;
}
this.ajaxUpdater=function(what,where,onComplete){return this.ajaxAdder(what,where,onComplete,true);}
this.ajaxDelete=function(what,id,onComplete){
if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300);
this.ajaxDel=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
if(this.ajaxDel.failed)return true;
var tempObj=this;
this.ajaxDel.onCompletion=function(){if(this.parseAjaxResponse()){tempObj.removeListItem(what.replace('-as-spam','')+'-'+id,tempObj);this.myResponseElement.innerHTML='';if(onComplete&&typeof onComplete=='function')onComplete();}};
this.ajaxDel.runAJAX('action=delete-'+what+'&id='+id);
return false;
}
this.ajaxDimmer=function(what,id,dimClass,onComplete){
if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300);
this.ajaxDim=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');
if(this.ajaxDim.failed)return true;
var tempObj=this;
this.ajaxDim.onCompletion=function(){if(this.parseAjaxResponse()){tempObj.dimItem(what+'-'+id,dimClass);this.myResponseElement.innerHTML='';if(onComplete&&typeof onComplete=='function')onComplete();}};
this.ajaxDim.runAJAX('action=dim-'+what+'&id='+id);
return false;
}
this.makeEl=function(h){var fakeItem=document.createElement('div');fakeItem.innerHTML=h;var r=fakeItem.firstChild;while(r.tagName.match(/(table|tbody)/i)){r=r.firstChild;}return r;}
this.addListItem=function(h){
newItem=this.makeEl(h);
var firstItem=this.theList.getElementsByTagName('table'==listType?'tr':'li')[0];
if(firstItem)firstItem.parentNode.insertBefore(newItem,firstItem);
else this.theList.appendChild(newItem);
listItems.unshift(newItem.id);
Fat.fade_element(newItem.id);
}
this.removeListItem=function(id,listObj,noFade){
if(!listObj)listObj=this;
if(!noFade)Fat.fade_element(id,null,700,'#FF3333');
var theItem=document.getElementById(id);
if(!noFade){var func=encloseFunc(function(a){a.parentNode.removeChild(a);},theItem);setTimeout(func,705);}
else{theItem.parentNode.removeChild(theItem);}
var pos=listObj.getListPos(id);
listItems.splice(pos,1);
if(!noFade)listObj.recolorList(pos,1000);
}
this.replaceListItem=function(id,h,update){
if(!update){this.removeListItem(id,false,true);this.addListItem(h);return;}
var newItem=this.makeEl(h);
var oldItem=document.getElementById(id);
oldItem.parentNode.replaceChild(newItem,oldItem);
Fat.fade_element(newItem.id);
}
this.dimItem=function(id,dimClass,noFade){
var theItem=document.getElementById(id);
if(theItem.className.match(dimClass)){if(!noFade)Fat.fade_element(id,null,700,null);theItem.className=theItem.className.replace(dimClass,'');}
else{if(!noFade)Fat.fade_element(id,null,700,'#FF3333');theItem.className=theItem.className+' '+dimClass;}
}
this.grabInputs=function(elId){//text,password,hidden,textarea,select
var theItem=document.getElementById(elId);
var inputs=new Array();
inputs.push(theItem.getElementsByTagName('input'),theItem.getElementsByTagName('textarea'),theItem.getElementsByTagName('select'));
for(var a=0;a<inputs.length;a++){
for(var i=0;i<inputs[a].length;i++){
if('action'==inputs[a][i].name)continue;
if('text'==inputs[a][i].type||'password'==inputs[a][i].type||'hidden'==inputs[a][i].type||inputs[a][i].tagName.match(/textarea/i)){
this.inputData+='&'+inputs[a][i].name+'='+encodeURIComponent(inputs[a][i].value);
}else if(inputs[a][i].tagName.match(/select/i)){
this.inputData+='&'+inputs[a][i].name+'='+encodeURIComponent(inputs[a][i].options[inputs[a][i].selectedIndex].value);
}
}
}
}
this.getListPos=function(id){for(var i=0;i<listItems.length;i++){if(id==listItems[i]){var pos=i;break;}}return pos;}
this.getListItems=function(){
if(this.theList)return;
listItems=new Array();
if(theListId){this.theList=document.getElementById(theListId);if(!this.theList)return false;}
else{this.theList=document.getElementById('the-list');if(this.theList)theListId='the-list';}
if(this.theList){
var items=this.theList.getElementsByTagName('tr');listType='table'
if(!items[0]){items=this.theList.getElementsByTagName('li');listType='list'}
for(var i=0;i<items.length;i++){listItems.push(items[i].id);}
}
}
this.recolorList=function(pos,dur){
if(!pos)pos=0;
for(var i=pos;i<listItems.length;i++){var e=document.getElementById(listItems[i]);if(i%2)e.className=e.className.replace('alternate','fade-'+alt_color.slice(1));else e.className+=' alternate fade-'+reg_color.slice(1);e.style.backgroundColor='';}
Fat.fade_all(dur);
var func=encloseFunc(function(l){for(var i=0;i<l.length;i++){var e=document.getElementById(l[i]);e.className=e.className.replace(/fade-[a-f0-9]{6}/i,'');}},listItems);
setTimeout(func,dur+5);
}
this.getListItems();
}
//No submit unless eval(code) returns true.
function 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)){if(!eval(code));e.returnValue=false;e.cancelBubble=true;return false;}}
//Pretty func from ALA http://www.alistapart.com/articles/gettingstartedwithajax
function getNodeValue(tree,el){return tree.getElementsByTagName(el)[0].firstChild.nodeValue;}
//Generic but lame JS closure
function encloseFunc(f){var a=arguments[1];return function(){f(a);}}

View File

@ -1,96 +0,0 @@
var listItems;
var reg_color = '#FFFFFF';
var alt_color = '#F1F1F1';
addLoadEvent(getListItems);
function deleteSomething( what, id, message ) {
what.replace('-', ' ');
if (!message) message = 'Are you sure you want to delete this ' + what + '?';
if ( confirm(message) ) {
return ajaxDelete( what.replace(' ', '-'), id );
} else {
return false;
}
}
function getResponseElement() {
var p = document.getElementById('ajax-response-p');
if (!p) {
p = document.createElement('p');
p.id = 'ajax-response-p';
document.getElementById('ajax-response').appendChild(p);
return p;
}
}
function ajaxDelete(what, id) {
ajaxDel = new sack('list-manipulation.php');
if ( ajaxDel.failed ) return true;
ajaxDel.myResponseElement = getResponseElement();
ajaxDel.method = 'POST';
ajaxDel.onLoading = function() { ajaxDel.myResponseElement.innerHTML = 'Sending Data...'; };
ajaxDel.onLoaded = function() { ajaxDel.myResponseElement.innerHTML = 'Data Sent...'; };
ajaxDel.onInteractive = function() { ajaxDel.myResponseElement.innerHTML = 'Processing Data...'; };
ajaxDel.onCompletion = function() { removeThisItem( what.replace('-as-spam', '') + '-' + id ); };
ajaxDel.runAJAX('action=delete-' + what + '&id=' + id);
return false;
}
function removeThisItem(id) {
var response = ajaxDel.response;
if ( isNaN(response) ) { alert(response); }
response = parseInt(response, 10);
if ( -1 == response ) { ajaxDel.myResponseElement.innerHTML = "You don't have permission to do that."; }
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."; }
else if ( 1 == response ) {
theItem = document.getElementById(id);
Fat.fade_element(id,null,700,'#FF3333');
setTimeout('theItem.parentNode.removeChild(theItem)', 705);
var pos = getListPos(id);
listItems.splice(pos,1);
recolorList(pos);
ajaxDel.myResponseElement.parentNode.removeChild(ajaxDel.myResponseElement);
}
}
function getListPos(id) {
for (var i = 0; i < listItems.length; i++) {
if (id == listItems[i]) {
var pos = i;
break;
}
}
return pos;
}
function getListItems() {
if (list) return;
listItems = new Array();
var extra = false;
var list = document.getElementById('the-list');
if (!list) { var list = document.getElementById('the-list-x'); extra = true; }
if (list) {
var items = list.getElementsByTagName('tr');
if (!items[0]) { items = list.getElementsByTagName('li'); }
for (var i=0; i<items.length; i++) { listItems.push(items[i].id); }
if (extra) { listItems.splice(0,1); }
}
}
function recolorList(pos,dur,from) {
if (!pos) pos = 0;
if (!from) {
reg_from = alt_color;
alt_from = reg_color;
} else {
reg_from = from;
alt_from = from;
}
for (var i = pos; i < listItems.length; i++) {
if (i % 2 == 1) Fat.fade_element(listItems[i],null,dur,reg_from,reg_color);
else Fat.fade_element(listItems[i],null,dur,alt_from,alt_color);
}
}

View File

@ -1,69 +0,0 @@
<?php
require_once('../wp-config.php');
require_once('admin-functions.php');
require_once('admin-db.php');
if ( !is_user_logged_in() )
die('-1');
function get_out_now() { exit; }
add_action( 'shutdown', 'get_out_now', -1 );
// check_admin_referer();
$id = (int) $_POST['id'];
switch ( $_POST['action'] ) :
case 'delete-link' :
if ( !current_user_can( 'manage_links' ) )
die('-1');
if ( wp_delete_link( $id ) )
die('1');
else die('0');
break;
case 'delete-post' :
if ( !current_user_can( 'delete_post', $id ) )
die('-1');
if ( wp_delete_post( $id ) )
die('1');
else die('0');
break;
case 'delete-page' :
if ( !current_user_can( 'delete_page', $id ) )
die('-1');
if ( wp_delete_post( $id ) )
die('1');
else die('0');
break;
case 'delete-cat' :
if ( !current_user_can( 'manage_categories' ) )
die('-1');
if ( wp_delete_category( $id ) )
die('1');
else die('0');
break;
case 'delete-comment' :
if ( !$comment = get_comment( $id ) )
die('0');
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
die('-1');
if ( wp_delete_comment( $comment->comment_ID ) )
die('1');
else die('0');
break;
case 'delete-comment-as-spam' :
if ( !$comment = get_comment( $id ) )
die('0');
if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
die('-1');
if ( wp_set_comment_status( $comment->comment_ID, 'spam' ) )
die('1');
else die('0');
break;
endswitch;
?>

View File

@ -17,15 +17,15 @@ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
}
}
}
if (isset($_POST['deletepost']))
$action = "delete";
switch($action) {
case 'postajaxpost':
case 'post':
check_admin_referer();
$post_ID = write_post();
$post_ID = 'post' == $action ? write_post() : edit_post();
// Redirect.
if (!empty($_POST['mode'])) {

View File

@ -91,11 +91,6 @@ fieldset legend {
padding: .1em .3em;
}
fieldset span.cat-nest {
display: block;
margin-left: 10px;
}
fieldset.options {
padding: 1em;
}
@ -326,6 +321,18 @@ form#upload #post_content {
color: #009ef0;
}
.approve {
display: none;
}
.unapproved .approve {
display: inline;
}
.unapproved .unapprove {
display: none;
}
.updated {
background: #CFEBF7 url(images/notice.gif) no-repeat 1em ;
border: 1px solid #2580B2;
@ -804,11 +811,20 @@ table .vers, table .name {
margin-top: .5em;
}
#categorydiv div div {
#categorydiv ul {
list-style: none;
padding: 0;
margin-left:10px;
}
#categorychecklist {
height: 12em;
overflow: auto;
margin-top: 8px;
}
#categorychecklist li {
margin: 0;
padding: 0;
}
#ajaxcat input {
border: 1px solid #ccc;
}
@ -951,4 +967,4 @@ input#catadd { background: #a4a4a4;
#jaxcat {
margin: 0;
padding: 0;
}
}

View File

@ -101,7 +101,9 @@ function wp_specialchars( $text, $quotes = 0 ) {
$text = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/', '&#038;$1', $text);-
$text = str_replace('<', '&lt;', $text);
$text = str_replace('>', '&gt;', $text);
if ( $quotes ) {
if ( 'double' === $quotes ) {
$text = str_replace('"', '&quot;', $text);
} elseif ( $quotes ) {
$text = str_replace('"', '&quot;', $text);
$text = str_replace("'", '&#039;', $text);
}

View File

@ -11,7 +11,7 @@ var Fat = {
b = b.toString(16); if (b.length == 1) b = '0' + b;
return "#" + r + g + b;
},
fade_all : function ()
fade_all : function (dur)
{
var a = document.getElementsByTagName("*");
for (var i = 0; i < a.length; i++)
@ -21,7 +21,7 @@ var Fat = {
if (r)
{
if (!r[1]) r[1] = "";
if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
if (o.id) Fat.fade_element(o.id,null,dur,"#"+r[1]);
}
}
},
@ -87,4 +87,4 @@ var Fat = {
addLoadEvent(function () {
Fat.fade_all();
});
});

View File

@ -237,6 +237,21 @@ function check_admin_referer() {
}
endif;
if ( !function_exists('check_ajax_referer') ) :
function check_ajax_referer() {
$cookie = explode(';', urldecode(empty($_POST['cookie']) ? $_GET['cookie'] : $_POST['cookie'])); // AJAX scripts must pass cookie=document.cookie
foreach ( $cookie as $tasty ) {
if ( false !== strpos($tasty, USER_COOKIE) )
$user = substr(strstr($tasty, '='), 1);
if ( false !== strpos($tasty, PASS_COOKIE) )
$pass = substr(strstr($tasty, '='), 1);
}
if ( !wp_login( $user, $pass, true ) )
die('-1');
do_action('check_ajax_referer');
}
endif;
// Cookie safe redirect. Works around IIS Set-Cookie bug.
// http://support.microsoft.com/kb/q176113/
if ( !function_exists('wp_redirect') ) :