Make WordPress Core

Changeset 6299


Ignore:
Timestamp:
10/31/2007 03:53:32 AM (18 years ago)
Author:
ryan
Message:

AJAX for link category add and delete. Props mdawaffe. fixes #5291

Location:
trunk
Files:
7 edited

Legend:

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

    r6287 r6299  
    5252        die('1');
    5353    else    die('0');
     54    break;
     55case 'delete-link-cat' :
     56    check_ajax_referer( "delete-link-category_$id" );
     57    if ( !current_user_can( 'manage_categories' ) )
     58        die('-1');
     59
     60    $cat_name = get_term_field('name', $id, 'link_category');
     61
     62    // Don't delete the default cats.
     63    if ( $id == get_option('default_link_category') ) {
     64        $x = new WP_AJAX_Response( array(
     65            'what' => 'link-cat',
     66            'id' => $id,
     67            'data' => new WP_Error( 'default-link-cat', sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name) )
     68        ) );
     69        $x->send();
     70    }
     71
     72    $r = wp_delete_term($id, 'link_category');
     73    if ( !$r )
     74        die('0');
     75    if ( is_wp_error($r) ) {
     76        $x = new WP_AJAX_Response( array(
     77            'what' => 'link-cat',
     78            'id' => $id,
     79            'data' => $r
     80        ) );
     81        $x->send();
     82    }
     83    die('1');
    5484    break;
    5585case 'delete-link' :
     
    179209        'data' => _cat_row( $cat, $level, $cat_full_name ),
    180210        'supplemental' => array('name' => $cat_full_name, 'show-link' => sprintf(__( 'Category <a href="#%s">%s</a> added' ), "cat-$cat->term_id", $cat_full_name))
     211    ) );
     212    $x->send();
     213    break;
     214case 'add-link-cat' : // From Blogroll -> Categories
     215    check_ajax_referer( 'add-link-category' );
     216    if ( !current_user_can( 'manage_categories' ) )
     217        die('-1');
     218
     219    $r = wp_insert_term($_POST['name'], 'link_category', $_POST );
     220    if ( is_wp_error( $r ) ) {
     221        $x = new WP_AJAX_Response( array(
     222            'what' => 'link-cat',
     223            'id' => $r
     224        ) );
     225        $x->send();
     226    }
     227
     228    extract($r, EXTR_SKIP);
     229
     230    if ( !$link_cat = link_cat_row( $term_id ) )
     231        die('0');
     232       
     233    $x = new WP_Ajax_Response( array(
     234        'what' => 'link-cat',
     235        'id' => $term_id,
     236        'data' => $link_cat
    181237    ) );
    182238    $x->send();
  • trunk/wp-admin/edit-link-categories.php

    r6118 r6299  
    55$parent_file = 'link-manager.php';
    66
    7 //wp_enqueue_script( 'admin-categories' );  TODO: Fix AJAX
     7wp_enqueue_script( 'admin-categories' );
    88require_once ('admin-header.php');
    99
     
    1414$messages[5] = __('Category not updated.');
    1515
    16 function link_cat_row($category) {
    17     global $class;
     16if (isset($_GET['message'])) : ?>
    1817
    19     if ( current_user_can( 'manage_categories' ) ) {
    20         $edit = "<a href='link-category.php?action=edit&amp;cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>";
    21         $default_cat_id = (int) get_option( 'default_link_category' );
    22 
    23         if ( $category->term_id != $default_cat_id )
    24             $edit .= "<td><a href='" . wp_nonce_url( "link-category.php?action=delete&amp;cat_ID=$category->term_id", 'delete-link-category_' . $category->term_id ) . "' onclick=\"return deleteSomething( 'cat', $category->term_id, '" . js_escape(sprintf( __("You are about to delete the category '%s'.\nAll links that were only assigned to this category will be assigned to the '%s' category.\n'OK' to delete, 'Cancel' to stop." ), $category->name, get_term_field( 'name', $default_cat_id,  'link_category' ))) . "' );\" class='delete'>".__( 'Delete' )."</a>";
    25         else
    26             $edit .= "<td style='text-align:center'>".__( "Default" );
    27     } else {
    28         $edit = '';
    29     }
    30 
    31     $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
    32 
    33     $category->count = number_format_i18n( $category->count );
    34     $count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
    35     return "<tr id='cat-$category->term_id'$class>
    36         <th scope='row' style='text-align: center'>$category->term_id</th>
    37         <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . "</td>
    38         <td>$category->description</td>
    39         <td align='center'>$count</td>
    40         <td>$edit</td>\n\t</tr>\n";
    41 }
    42 ?>
    43 
    44 <?php if (isset($_GET['message'])) : ?>
    4518<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
    4619<?php endif; ?>
     
    6235    </tr>
    6336    </thead>
    64     <tbody id="the-list">
     37    <tbody id="the-list" class="list:link-cat">
    6538<?php
    6639$categories = get_terms( 'link_category', 'hide_empty=0' );
  • trunk/wp-admin/edit-link-category-form.php

    r6118 r6299  
    1010    $heading = __('Add Category');
    1111    $submit_text = __('Add Category &raquo;');
    12     $form = '<form name="addcat" id="addcat" method="post" action="link-category.php">';
     12    $form = '<form name="addcat" id="addcat" class="add:the-list:" method="post" action="link-category.php">';
    1313    $action = 'addcat';
    1414    $nonce_action = 'add-link-category';
  • trunk/wp-admin/includes/template.php

    r6277 r6299  
    3535    global $class;
    3636
     37    $category = get_category( $category );
     38
    3739    $pad = str_repeat( '&#8212; ', $level );
    3840    if ( current_user_can( 'manage_categories' ) ) {
     
    4850        $edit = '';
    4951
    50     $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
     52    $class = " class='alternate'" == $class ? '' : " class='alternate'";
    5153
    5254    $category->count = number_format_i18n( $category->count );
     
    6062
    6163    return apply_filters('cat_row', $output);
     64}
     65
     66function link_cat_row( $category ) {
     67    global $class;
     68
     69    if ( !$category = get_term( $category, 'link_category' ) )
     70        return false;
     71    if ( is_wp_error( $category ) )
     72        return $category;
     73
     74    if ( current_user_can( 'manage_categories' ) ) {
     75        $edit = "<a href='link-category.php?action=edit&amp;cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>";
     76        $default_cat_id = (int) get_option( 'default_link_category' );
     77
     78        $delete_url = wp_nonce_url( "link-category.php?action=delete&amp;cat_ID=$category->term_id", "delete-link-category_$category->term_id" );
     79        if ( $category->term_id != $default_cat_id )
     80            $edit .= "<td><a href='$delete_url' class='delete:the-list:link-cat-$category->term_id delete'>" . __( 'Delete' ) . "</a>";
     81        else
     82            $edit .= "<td style='text-align:center'>" . __( "Default" );
     83    } else {
     84        $edit = '';
     85    }
     86
     87    $class = " class='alternate'" == $class ? '' : " class='alternate'";
     88
     89    $category->count = number_format_i18n( $category->count );
     90    $count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
     91    $output = "<tr id='link-cat-$category->term_id'$class>
     92        <th scope='row' style='text-align: center'>$category->term_id</th>
     93        <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . "</td>
     94        <td>$category->description</td>
     95        <td align='center'>$count</td>
     96        <td>$edit</td>\n\t</tr>\n";
     97
     98    return apply_filters( 'link_cat_row', $output );
    6299}
    63100
  • trunk/wp-admin/js/categories.js

    r6213 r6299  
    11jQuery(function($) {
    2     var options = document.forms['addcat'].category_parent.options;
     2    var options = false
     3    if ( document.forms['addcat'].category_parent )
     4        options = document.forms['addcat'].category_parent.options;
    35
    46    var addAfter = function( r, settings ) {
     
    1517    }
    1618
    17     var a = $('#the-list').wpList( { addAfter: addAfter, delAfter: delAfter } );
     19    if ( options )
     20        $('#the-list').wpList( { addAfter: addAfter, delAfter: delAfter } );
     21    else
     22        $('#the-list').wpList();
    1823});
  • trunk/wp-includes/script-loader.php

    r6287 r6299  
    116116                'how' => __('Separate multiple categories with commas.')
    117117            ) );
    118             $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20070823' );
     118            $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' );
    119119            $this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' );
    120120            $this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20070822' );
  • trunk/wp-settings.php

    r6260 r6299  
    119119require (ABSPATH . WPINC . '/compat.php');
    120120require (ABSPATH . WPINC . '/functions.php');
     121require (ABSPATH . WPINC . '/classes.php');
    121122
    122123require_wp_db();
    123 // $table_prefix is deprecated as of 2.1
    124 $wpdb->prefix = $table_prefix;
    125 
    126 if ( preg_match('|[^a-z0-9_]|i', $wpdb->prefix) && !file_exists(ABSPATH . 'wp-content/db.php') )
     124$prefix = $wpdb->set_prefix($table_prefix);
     125
     126if ( is_wp_error($prefix) )
    127127    wp_die("<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.");
    128 
    129 // Table names
    130 $wpdb->posts          = $wpdb->prefix . 'posts';
    131 $wpdb->users          = $wpdb->prefix . 'users';
    132 $wpdb->categories     = $wpdb->prefix . 'categories';
    133 $wpdb->post2cat       = $wpdb->prefix . 'post2cat';
    134 $wpdb->comments       = $wpdb->prefix . 'comments';
    135 $wpdb->link2cat       = $wpdb->prefix . 'link2cat';
    136 $wpdb->links          = $wpdb->prefix . 'links';
    137 $wpdb->options        = $wpdb->prefix . 'options';
    138 $wpdb->postmeta       = $wpdb->prefix . 'postmeta';
    139 $wpdb->usermeta       = $wpdb->prefix . 'usermeta';
    140 $wpdb->terms          = $wpdb->prefix . 'terms';
    141 $wpdb->term_taxonomy  = $wpdb->prefix . 'term_taxonomy';
    142 $wpdb->term_relationships = $wpdb->prefix . 'term_relationships';
    143 
    144 if ( defined('CUSTOM_USER_TABLE') )
    145     $wpdb->users = CUSTOM_USER_TABLE;
    146 if ( defined('CUSTOM_USER_META_TABLE') )
    147     $wpdb->usermeta = CUSTOM_USER_META_TABLE;
    148128
    149129if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
     
    154134wp_cache_init();
    155135
    156 require (ABSPATH . WPINC . '/classes.php');
    157136require (ABSPATH . WPINC . '/plugin.php');
    158137require (ABSPATH . WPINC . '/default-filters.php');
Note: See TracChangeset for help on using the changeset viewer.