WordPress.org

Make WordPress Core


Ignore:
Files:
46 added
17 deleted
62 edited

Legend:

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

    r6163 r6163  
    11<?php
    22require_once('../wp-config.php');
    3 require_once('admin-functions.php');
    4 require_once('admin-db.php');
     3require_once('includes/admin.php');
    54
    65define('DOING_AJAX', true);
     
    127126    $x->send();
    128127    break;
     128case 'add-link-category' : // On the Fly
     129    if ( !current_user_can( 'manage_categories' ) )
     130        die('-1');
     131    $names = explode(',', $_POST['newcat']);
     132    $x = new WP_Ajax_Response();
     133    foreach ( $names as $cat_name ) {
     134        $cat_name = trim($cat_name);
     135        if ( !$slug = sanitize_title($cat_name) )
     136            die('0');
     137        if ( !$cat_id = is_term( $cat_name, 'link_category' ) ) {
     138            $cat_id = wp_insert_term( $cat_name, 'link_category' );
     139            $cat_id = $cat_id['term_id'];
     140        }
     141        $cat_name = wp_specialchars(stripslashes($cat_name));
     142        $x->add( array(
     143            'what' => 'link-category',
     144            'id' => $cat_id,
     145            'data' => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>"
     146        ) );
     147    }
     148    $x->send();
     149    break;
    129150case 'add-cat' : // From Manage->Categories
    130151    if ( !current_user_can( 'manage_categories' ) )
     
    184205        if ( $pid = wp_insert_post( array(
    185206            'post_title' => sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now))
    186         ) ) )
     207        ) ) ) {
     208            if ( is_wp_error( $pid ) )
     209                return $pid;
    187210            $mid = add_meta( $pid );
     211        }
    188212        else
    189213            die('0');
  • trunk/wp-admin/admin-footer.php

    r6163 r6163  
    11
    22<div id="footer">
    3 <p class="logo"><a href="http://wordpress.org/" id="wordpress-logo"><img src="images/wordpress-logo.png" alt="WordPress" /></a></p>
    4 <p class="docs"><?php _e('<a href="http://codex.wordpress.org/">Documentation</a>'); ?> &#8212; <?php _e('<a href="http://wordpress.org/support/">Support Forums</a>'); ?><br />
    5 <?php bloginfo('version'); ?> &#8212; <?php printf(__('%s seconds'), timer_stop(0, 2)); ?></p>
     3<p><?php
     4
     5$upgrade = apply_filters( 'update_footer', '' );
     6echo __('Thank you for creating with <a href="http://wordpress.org/">WordPress</a>').' | '.__('<a href="http://codex.wordpress.org/">Documentation</a>').' | '.__('<a href="http://wordpress.org/support/forum/4">Feedback</a>').' '.$upgrade;
     7
     8?></p>
    69</div>
    710<?php do_action('admin_footer', ''); ?>
  • trunk/wp-admin/admin-functions.php

    • Property svn:keywords deleted
    r6163 r6163  
    11<?php
    2 
    3 function write_post() {
    4     $result = wp_write_post();
    5     if( is_wp_error( $result ) )
    6         wp_die( $result->get_error_message() );
    7     else
    8         return $result;
    9 }
    10 
    11 // Creates a new post from the "Write Post" form using $_POST information.
    12 function wp_write_post() {
    13     global $user_ID;
    14 
    15     if ( 'page' == $_POST['post_type'] ) {
    16         if ( !current_user_can( 'edit_pages' ) )
    17             return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this blog.' ) );
    18     } else {
    19         if ( !current_user_can( 'edit_posts' ) )
    20             return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) );
    21     }
    22 
    23 
    24     // Check for autosave collisions
    25     $temp_id = false;
    26     if ( isset($_POST['temp_ID']) ) {
    27         $temp_id = (int) $_POST['temp_ID'];
    28         if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
    29             $draft_ids = array();
    30         foreach ( $draft_ids as $temp => $real )
    31             if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then )
    32                 unset($draft_ids[$temp]);
    33 
    34         if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
    35             $_POST['post_ID'] = $draft_ids[$temp_id];
    36             unset($_POST['temp_ID']);
    37             update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
    38             return edit_post();
    39         }
    40     }
    41 
    42     // Rename.
    43     $_POST['post_content'] = $_POST['content'];
    44     $_POST['post_excerpt'] = $_POST['excerpt'];
    45     $_POST['post_parent'] = $_POST['parent_id'];
    46     $_POST['to_ping'] = $_POST['trackback_url'];
    47 
    48     if (!empty ( $_POST['post_author_override'] ) ) {
    49         $_POST['post_author'] = (int) $_POST['post_author_override'];
    50     } else {
    51         if (!empty ( $_POST['post_author'] ) ) {
    52             $_POST['post_author'] = (int) $_POST['post_author'];
    53         } else {
    54             $_POST['post_author'] = (int) $_POST['user_ID'];
    55         }
    56 
    57     }
    58 
    59     if ( $_POST['post_author'] != $_POST['user_ID'] ) {
    60         if ( 'page' == $_POST['post_type'] ) {
    61             if ( !current_user_can( 'edit_others_pages' ) )
    62                 return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );
    63         } else {
    64             if ( !current_user_can( 'edit_others_posts' ) )
    65                 return new WP_Error( 'edit_others_posts', __( 'You are not allowed to post as this user.' ) );
    66 
    67         }
    68     }
    69 
    70     // What to do based on which button they pressed
    71     if ('' != $_POST['saveasdraft'] )
    72         $_POST['post_status'] = 'draft';
    73     if ('' != $_POST['saveasprivate'] )
    74         $_POST['post_status'] = 'private';
    75     if ('' != $_POST['publish'] )
    76         $_POST['post_status'] = 'publish';
    77     if ('' != $_POST['advanced'] )
    78         $_POST['post_status'] = 'draft';
    79 
    80     if ( 'page' == $_POST['post_type'] ) {
    81         if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) )
    82             $_POST['post_status'] = 'draft';
    83     } else {
    84         if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) )
    85             $_POST['post_status'] = 'draft';
    86     }
    87 
    88     if (!isset( $_POST['comment_status'] ))
    89         $_POST['comment_status'] = 'closed';
    90 
    91     if (!isset( $_POST['ping_status'] ))
    92         $_POST['ping_status'] = 'closed';
    93 
    94     if (!empty ( $_POST['edit_date'] ) ) {
    95         $aa = $_POST['aa'];
    96         $mm = $_POST['mm'];
    97         $jj = $_POST['jj'];
    98         $hh = $_POST['hh'];
    99         $mn = $_POST['mn'];
    100         $ss = $_POST['ss'];
    101         $jj = ($jj > 31 ) ? 31 : $jj;
    102         $hh = ($hh > 23 ) ? $hh -24 : $hh;
    103         $mn = ($mn > 59 ) ? $mn -60 : $mn;
    104         $ss = ($ss > 59 ) ? $ss -60 : $ss;
    105         $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
    106         $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
    107     }
    108    
    109     unset($_POST['no_filter']);
    110 
    111     // Create the post.
    112     $post_ID = wp_insert_post( $_POST );
    113 
    114     add_meta( $post_ID );
    115 
    116     // Reunite any orphaned attachments with their parent
    117     if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
    118         $draft_ids = array();
    119     if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
    120         relocate_children( $draft_temp_id, $post_ID );
    121     if ( $temp_id && $temp_id != $draft_temp_id )
    122         relocate_children( $temp_id, $post_ID );
    123 
    124     // Update autosave collision detection
    125     if ( $temp_id ) {
    126         $draft_ids[$temp_id] = $post_ID;
    127         update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
    128     }
    129 
    130     // Now that we have an ID we can fix any attachment anchor hrefs
    131     fix_attachment_links( $post_ID );
    132 
    133     return $post_ID;
    134 }
    135 
    136 // Move child posts to a new parent
    137 function relocate_children( $old_ID, $new_ID ) {
    138     global $wpdb;
    139     $old_ID = (int) $old_ID;
    140     $new_ID = (int) $new_ID;
    141     return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID" );
    142 }
    143 
    144 // Replace hrefs of attachment anchors with up-to-date permalinks.
    145 function fix_attachment_links( $post_ID ) {
    146     global $wp_rewrite;
    147 
    148     $post = & get_post( $post_ID, ARRAY_A );
    149 
    150     $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie";
    151 
    152     // See if we have any rel="attachment" links
    153     if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) )
    154         return;
    155 
    156     $i = 0;
    157     $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i";
    158     foreach ( $anchor_matches[0] as $anchor ) {
    159         if ( 0 == preg_match( $search, $anchor, $id_matches ) )
    160             continue;
    161 
    162         $id = (int) $id_matches[3];
    163 
    164         // While we have the attachment ID, let's adopt any orphans.
    165         $attachment = & get_post( $id, ARRAY_A );
    166         if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) {
    167             $attachment['post_parent'] = $post_ID;
    168             // Escape data pulled from DB.
    169             $attachment = add_magic_quotes( $attachment);
    170             wp_update_post( $attachment);
    171         }
    172 
    173         $post_search[$i] = $anchor;
    174         $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor );
    175         ++$i;
    176     }
    177 
    178     $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] );
    179 
    180     // Escape data pulled from DB.
    181     $post = add_magic_quotes( $post);
    182 
    183     return wp_update_post( $post);
    184 }
    185 
    186 // Update an existing post with values provided in $_POST.
    187 function edit_post() {
    188     global $user_ID;
    189 
    190     $post_ID = (int) $_POST['post_ID'];
    191 
    192     if ( 'page' == $_POST['post_type'] ) {
    193         if ( !current_user_can( 'edit_page', $post_ID ) )
    194             wp_die( __('You are not allowed to edit this page.' ));
    195     } else {
    196         if ( !current_user_can( 'edit_post', $post_ID ) )
    197             wp_die( __('You are not allowed to edit this post.' ));
    198     }
    199 
    200     // Autosave shouldn't save too soon after a real save
    201     if ( 'autosave' == $_POST['action'] ) {
    202         $post =& get_post( $post_ID );
    203         $now = time();
    204         $then = strtotime($post->post_date_gmt . ' +0000');
    205         // Keep autosave_interval in sync with autosave-js.php.
    206         $delta = apply_filters( 'autosave_interval', 120 ) / 2;
    207         if ( ($now - $then) < $delta )
    208             return $post_ID;
    209     }
    210 
    211     // Rename.
    212     $_POST['ID'] = (int) $_POST['post_ID'];
    213     $_POST['post_content'] = $_POST['content'];
    214     $_POST['post_excerpt'] = $_POST['excerpt'];
    215     $_POST['post_parent'] = $_POST['parent_id'];
    216     $_POST['to_ping'] = $_POST['trackback_url'];
    217 
    218     if (!empty ( $_POST['post_author_override'] ) ) {
    219         $_POST['post_author'] = (int) $_POST['post_author_override'];
    220     } else
    221         if (!empty ( $_POST['post_author'] ) ) {
    222             $_POST['post_author'] = (int) $_POST['post_author'];
    223         } else {
    224             $_POST['post_author'] = (int) $_POST['user_ID'];
    225         }
    226 
    227     if ( $_POST['post_author'] != $_POST['user_ID'] ) {
    228         if ( 'page' == $_POST['post_type'] ) {
    229             if ( !current_user_can( 'edit_others_pages' ) )
    230                 wp_die( __('You are not allowed to edit pages as this user.' ));
    231         } else {
    232             if ( !current_user_can( 'edit_others_posts' ) )
    233                 wp_die( __('You are not allowed to edit posts as this user.' ));
    234 
    235         }
    236     }
    237 
    238     // What to do based on which button they pressed
    239     if ('' != $_POST['saveasdraft'] )
    240         $_POST['post_status'] = 'draft';
    241     if ('' != $_POST['saveasprivate'] )
    242         $_POST['post_status'] = 'private';
    243     if ('' != $_POST['publish'] )
    244         $_POST['post_status'] = 'publish';
    245     if ('' != $_POST['advanced'] )
    246         $_POST['post_status'] = 'draft';
    247 
    248     if ( 'page' == $_POST['post_type'] ) {
    249         if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages' ))
    250             $_POST['post_status'] = 'draft';
    251     } else {
    252         if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts' ))
    253             $_POST['post_status'] = 'draft';
    254     }
    255 
    256     if (!isset( $_POST['comment_status'] ))
    257         $_POST['comment_status'] = 'closed';
    258 
    259     if (!isset( $_POST['ping_status'] ))
    260         $_POST['ping_status'] = 'closed';
    261 
    262     if (!empty ( $_POST['edit_date'] ) ) {
    263         $aa = $_POST['aa'];
    264         $mm = $_POST['mm'];
    265         $jj = $_POST['jj'];
    266         $hh = $_POST['hh'];
    267         $mn = $_POST['mn'];
    268         $ss = $_POST['ss'];
    269         $jj = ($jj > 31 ) ? 31 : $jj;
    270         $hh = ($hh > 23 ) ? $hh -24 : $hh;
    271         $mn = ($mn > 59 ) ? $mn -60 : $mn;
    272         $ss = ($ss > 59 ) ? $ss -60 : $ss;
    273         $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    274         $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" );
    275     }
    276 
    277     // Meta Stuff
    278     if ( $_POST['meta'] ) {
    279         foreach ( $_POST['meta'] as $key => $value )
    280             update_meta( $key, $value['key'], $value['value'] );
    281     }
    282 
    283     if ( $_POST['deletemeta'] ) {
    284         foreach ( $_POST['deletemeta'] as $key => $value )
    285             delete_meta( $key );
    286     }
    287 
    288     unset($_POST['no_filter']);
    289    
    290     add_meta( $post_ID );
    291 
    292     wp_update_post( $_POST );
    293 
    294     // Reunite any orphaned attachments with their parent
    295     if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
    296         $draft_ids = array();
    297     if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
    298         relocate_children( $draft_temp_id, $post_ID );
    299 
    300     // Now that we have an ID we can fix any attachment anchor hrefs
    301     fix_attachment_links( $post_ID );
    302 
    303     return $post_ID;
    304 }
    305 
    306 function edit_comment() {
    307     global $user_ID;
    308 
    309     $comment_ID = (int) $_POST['comment_ID'];
    310     $comment_post_ID = (int) $_POST['comment_post_ID'];
    311 
    312     if (!current_user_can( 'edit_post', $comment_post_ID ))
    313         wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' ));
    314 
    315     $_POST['comment_author'] = $_POST['newcomment_author'];
    316     $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
    317     $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
    318     $_POST['comment_approved'] = $_POST['comment_status'];
    319     $_POST['comment_content'] = $_POST['content'];
    320     $_POST['comment_ID'] = (int) $_POST['comment_ID'];
    321 
    322     if (!empty ( $_POST['edit_date'] ) ) {
    323         $aa = $_POST['aa'];
    324         $mm = $_POST['mm'];
    325         $jj = $_POST['jj'];
    326         $hh = $_POST['hh'];
    327         $mn = $_POST['mn'];
    328         $ss = $_POST['ss'];
    329         $jj = ($jj > 31 ) ? 31 : $jj;
    330         $hh = ($hh > 23 ) ? $hh -24 : $hh;
    331         $mn = ($mn > 59 ) ? $mn -60 : $mn;
    332         $ss = ($ss > 59 ) ? $ss -60 : $ss;
    333         $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    334     }
    335 
    336     wp_update_comment( $_POST);
    337 }
    338 
    339 // Get an existing post and format it for editing.
    340 function get_post_to_edit( $id ) {
    341 
    342     $post = get_post( $id );
    343 
    344     $post->post_content = format_to_edit( $post->post_content, user_can_richedit() );
    345     $post->post_content = apply_filters( 'content_edit_pre', $post->post_content);
    346 
    347     $post->post_excerpt = format_to_edit( $post->post_excerpt);
    348     $post->post_excerpt = apply_filters( 'excerpt_edit_pre', $post->post_excerpt);
    349 
    350     $post->post_title = format_to_edit( $post->post_title );
    351     $post->post_title = apply_filters( 'title_edit_pre', $post->post_title );
    352 
    353     $post->post_password = format_to_edit( $post->post_password );
    354    
    355     $post->menu_order = (int) $post->menu_order;
    356 
    357     if ( $post->post_type == 'page' )
    358         $post->page_template = get_post_meta( $id, '_wp_page_template', true );
    359 
    360     return $post;
    361 }
    362 
    363 // Default post information to use when populating the "Write Post" form.
    364 function get_default_post_to_edit() {
    365     if ( !empty( $_REQUEST['post_title'] ) )
    366         $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] ));
    367     else if ( !empty( $_REQUEST['popuptitle'] ) ) {
    368         $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] ));
    369         $post_title = funky_javascript_fix( $post_title );
    370     } else {
    371         $post_title = '';
    372     }
    373 
    374     if ( !empty( $_REQUEST['content'] ) )
    375         $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] ));
    376     else if ( !empty( $post_title ) ) {
    377         $text       = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) );
    378         $text       = funky_javascript_fix( $text);
    379         $popupurl   = clean_url($_REQUEST['popupurl']);
    380         $post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text";
    381     }
    382 
    383     if ( !empty( $_REQUEST['excerpt'] ) )
    384         $post_excerpt = wp_specialchars( stripslashes( $_REQUEST['excerpt'] ));
    385     else
    386         $post_excerpt = '';
    387 
    388     $post->post_status = 'draft';
    389     $post->comment_status = get_option( 'default_comment_status' );
    390     $post->ping_status = get_option( 'default_ping_status' );
    391     $post->post_pingback = get_option( 'default_pingback_flag' );
    392     $post->post_category = get_option( 'default_category' );
    393     $post->post_content = apply_filters( 'default_content', $post_content);
    394     $post->post_title = apply_filters( 'default_title', $post_title );
    395     $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt);
    396     $post->page_template = 'default';
    397     $post->post_parent = 0;
    398     $post->menu_order = 0;
    399 
    400     return $post;
    401 }
    402 
    403 function get_comment_to_edit( $id ) {
    404     $comment = get_comment( $id );
    405    
    406     $comment->comment_ID = (int) $comment->comment_ID;
    407     $comment->comment_post_ID = (int) $comment->comment_post_ID;
    408 
    409     $comment->comment_content = format_to_edit( $comment->comment_content );
    410     $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content);
    411 
    412     $comment->comment_author = format_to_edit( $comment->comment_author );
    413     $comment->comment_author_email = format_to_edit( $comment->comment_author_email );
    414     $comment->comment_author_url = clean_url($comment->comment_author_url);
    415     $comment->comment_author_url = format_to_edit( $comment->comment_author_url );
    416 
    417     return $comment;
    418 }
    419 
    420 function get_category_to_edit( $id ) {
    421     $category = get_category( $id );
    422    
    423     $category->term_id = (int) $category->term_id;
    424     $category->parent = (int) $category->parent;
    425 
    426     return $category;
    427 }
    428 
    429 function wp_dropdown_roles( $default = false ) {
    430     global $wp_roles;
    431     $r = '';
    432     foreach( $wp_roles->role_names as $role => $name )
    433         if ( $default == $role ) // Make default first in list
    434             $p = "\n\t<option selected='selected' value='$role'>$name</option>";
    435         else
    436             $r .= "\n\t<option value='$role'>$name</option>";
    437     echo $p . $r;
    438 }
    439 
    440 
    441 function get_user_to_edit( $user_id ) {
    442     $user = new WP_User( $user_id );
    443     $user->user_login   = attribute_escape($user->user_login);
    444     $user->user_email   = attribute_escape($user->user_email);
    445     $user->user_url     = clean_url($user->user_url);
    446     $user->first_name   = attribute_escape($user->first_name);
    447     $user->last_name    = attribute_escape($user->last_name);
    448     $user->display_name = attribute_escape($user->display_name);
    449     $user->nickname     = attribute_escape($user->nickname);
    450     $user->aim          = attribute_escape($user->aim);
    451     $user->yim          = attribute_escape($user->yim);
    452     $user->jabber       = attribute_escape($user->jabber);
    453     $user->description  =  wp_specialchars($user->description);
    454 
    455     return $user;
    456 }
    457 
    458 // Creates a new user from the "Users" form using $_POST information.
    459 
    460 function add_user() {
    461     if ( func_num_args() ) { // The hackiest hack that ever did hack
    462         global $current_user, $wp_roles;
    463         $user_id = (int) func_get_arg( 0 );
    464 
    465         if ( isset( $_POST['role'] ) ) {
    466             if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ) ) {
    467                 $user = new WP_User( $user_id );
    468                 $user->set_role( $_POST['role'] );
    469             }
    470         }
    471     } else {
    472         add_action( 'user_register', 'add_user' ); // See above
    473         return edit_user();
    474     }
    475 }
    476 
    477 function edit_user( $user_id = 0 ) {
    478     global $current_user, $wp_roles, $wpdb;
    479     if ( $user_id != 0 ) {
    480         $update = true;
    481         $user->ID = (int) $user_id;
    482         $userdata = get_userdata( $user_id );
    483         $user->user_login = $wpdb->escape( $userdata->user_login );
    484     } else {
    485         $update = false;
    486         $user = '';
    487     }
    488 
    489     if ( isset( $_POST['user_login'] ))
    490         $user->user_login = wp_specialchars( trim( $_POST['user_login'] ));
    491 
    492     $pass1 = $pass2 = '';
    493     if ( isset( $_POST['pass1'] ))
    494         $pass1 = $_POST['pass1'];
    495     if ( isset( $_POST['pass2'] ))
    496         $pass2 = $_POST['pass2'];
    497 
    498     if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) {
    499         if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ))
    500             $user->role = $_POST['role'];
    501     }
    502 
    503     if ( isset( $_POST['email'] ))
    504         $user->user_email = wp_specialchars( trim( $_POST['email'] ));
    505     if ( isset( $_POST['url'] ) ) {
    506         $user->user_url = clean_url( trim( $_POST['url'] ));
    507         $user->user_url = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url;
    508     }
    509     if ( isset( $_POST['first_name'] ))
    510         $user->first_name = wp_specialchars( trim( $_POST['first_name'] ));
    511     if ( isset( $_POST['last_name'] ))
    512         $user->last_name = wp_specialchars( trim( $_POST['last_name'] ));
    513     if ( isset( $_POST['nickname'] ))
    514         $user->nickname = wp_specialchars( trim( $_POST['nickname'] ));
    515     if ( isset( $_POST['display_name'] ))
    516         $user->display_name = wp_specialchars( trim( $_POST['display_name'] ));
    517     if ( isset( $_POST['description'] ))
    518         $user->description = trim( $_POST['description'] );
    519     if ( isset( $_POST['jabber'] ))
    520         $user->jabber = wp_specialchars( trim( $_POST['jabber'] ));
    521     if ( isset( $_POST['aim'] ))
    522         $user->aim = wp_specialchars( trim( $_POST['aim'] ));
    523     if ( isset( $_POST['yim'] ))
    524         $user->yim = wp_specialchars( trim( $_POST['yim'] ));
    525     if ( !$update )
    526         $user->rich_editing = 'true';  // Default to true for new users.
    527     else if ( isset( $_POST['rich_editing'] ) )
    528         $user->rich_editing = $_POST['rich_editing'];
    529     else
    530         $user->rich_editing = 'false';
    531 
    532     $errors = new WP_Error();
    533 
    534     /* checking that username has been typed */
    535     if ( $user->user_login == '' )
    536         $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' ));
    537 
    538     /* checking the password has been typed twice */
    539     do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 ));
    540 
    541     if (!$update ) {
    542         if ( $pass1 == '' || $pass2 == '' )
    543             $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' ));
    544     } else {
    545         if ((empty ( $pass1 ) && !empty ( $pass2 ) ) || (empty ( $pass2 ) && !empty ( $pass1 ) ) )
    546             $errors->add( 'pass', __( "<strong>ERROR</strong>: you typed your new password only once." ));
    547     }
    548 
    549     /* Check for "\" in password */
    550     if( strpos( " ".$pass1, "\\" ) )
    551         $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ));
    552 
    553     /* checking the password has been typed twice the same */
    554     if ( $pass1 != $pass2 )
    555         $errors->add( 'pass', __( '<strong>ERROR</strong>: Please type the same password in the two password fields.' ));
    556 
    557     if (!empty ( $pass1 ))
    558         $user->user_pass = $pass1;
    559 
    560     if ( !$update && !validate_username( $user->user_login ) )
    561         $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.' ));
    562 
    563     if (!$update && username_exists( $user->user_login ))
    564         $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' ));
    565 
    566     /* checking e-mail address */
    567     if ( empty ( $user->user_email ) ) {
    568         $errors->add( 'user_email', __( "<strong>ERROR</strong>: please type an e-mail address" ));
    569     } else
    570         if (!is_email( $user->user_email ) ) {
    571             $errors->add( 'user_email', __( "<strong>ERROR</strong>: the email address isn't correct" ));
    572         }
    573 
    574     if ( $errors->get_error_codes() )
    575         return $errors;
    576 
    577     if ( $update ) {
    578         $user_id = wp_update_user( get_object_vars( $user ));
    579     } else {
    580         $user_id = wp_insert_user( get_object_vars( $user ));
    581         wp_new_user_notification( $user_id );
    582     }
    583     return $user_id;
    584 }
    585 
    586 
    587 function get_link_to_edit( $link_id ) {
    588     $link = get_link( $link_id );
    589 
    590     $link->link_url         = clean_url($link->link_url);
    591     $link->link_name        = attribute_escape($link->link_name);
    592     $link->link_image       = attribute_escape($link->link_image);
    593     $link->link_description = attribute_escape($link->link_description);
    594     $link->link_rss         = clean_url($link->link_rss);
    595     $link->link_rel         = attribute_escape($link->link_rel);
    596     $link->link_notes       =  wp_specialchars($link->link_notes);
    597     $link->post_category    = $link->link_category;
    598 
    599     return $link;
    600 }
    601 
    602 function get_default_link_to_edit() {
    603     if ( isset( $_GET['linkurl'] ) )
    604         $link->link_url = clean_url( $_GET['linkurl']);
    605     else
    606         $link->link_url = '';
    607 
    608     if ( isset( $_GET['name'] ) )
    609         $link->link_name = attribute_escape( $_GET['name']);
    610     else
    611         $link->link_name = '';
    612 
    613     $link->link_visible = 'Y';
    614 
    615     return $link;
    616 }
    617 
    618 function add_link() {
    619     return edit_link();
    620 }
    621 
    622 function edit_link( $link_id = '' ) {
    623     if (!current_user_can( 'manage_links' ))
    624         wp_die( __( 'Cheatin&#8217; uh?' ));
    625 
    626     $_POST['link_url'] = wp_specialchars( $_POST['link_url'] );
    627     $_POST['link_url'] = clean_url($_POST['link_url']);
    628     $_POST['link_name'] = wp_specialchars( $_POST['link_name'] );
    629     $_POST['link_image'] = wp_specialchars( $_POST['link_image'] );
    630     $_POST['link_rss'] = clean_url($_POST['link_rss']);
    631     $_POST['link_category'] = $_POST['post_category'];
    632 
    633     if ( !empty( $link_id ) ) {
    634         $_POST['link_id'] = $link_id;
    635         return wp_update_link( $_POST);
    636     } else {
    637         return wp_insert_link( $_POST);
    638     }
    639 }
    640 
    641 function url_shorten( $url ) {
    642     $short_url = str_replace( 'http://', '', stripslashes( $url ));
    643     $short_url = str_replace( 'www.', '', $short_url );
    644     if ('/' == substr( $short_url, -1 ))
    645         $short_url = substr( $short_url, 0, -1 );
    646     if ( strlen( $short_url ) > 35 )
    647         $short_url = substr( $short_url, 0, 32 ).'...';
    648     return $short_url;
    649 }
    650 
    651 function selected( $selected, $current) {
    652     if ( $selected == $current)
    653         echo ' selected="selected"';
    654 }
    655 
    656 function checked( $checked, $current) {
    657     if ( $checked == $current)
    658         echo ' checked="checked"';
    659 }
    660 
    661 function return_categories_list( $parent = 0 ) {
    662     global $wpdb;
    663     return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( link_count = 0 OR category_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY category_count DESC" );
    664 }
    665 
    666 function sort_cats( $cat1, $cat2 ) {
    667     if ( $cat1['checked'] || $cat2['checked'] )
    668         return ( $cat1['checked'] && !$cat2['checked'] ) ? -1 : 1;
    669     else
    670         return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] );
    671 }
    672 
    673 function get_nested_categories( $default = 0, $parent = 0 ) {
    674     global $post_ID, $link_id, $mode, $wpdb;
    675 
    676     if ( $post_ID ) {
    677         $checked_categories = $wpdb->get_col( "
    678              SELECT category_id
    679              FROM $wpdb->categories, $wpdb->post2cat
    680              WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID'
    681              " );
    682 
    683         if ( count( $checked_categories ) == 0 ) {
    684             // No selected categories, strange
    685             $checked_categories[] = $default;
    686         }
    687     } else if ( $link_id ) {
    688         $checked_categories = $wpdb->get_col( "
    689              SELECT category_id
    690              FROM $wpdb->categories, $wpdb->link2cat
    691              WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id'
    692              " );
    693 
    694         if ( count( $checked_categories ) == 0 ) {
    695             // No selected categories, strange
    696             $checked_categories[] = $default;
    697         }
    698     } else {
    699         $checked_categories[] = $default;
    700     }
    701 
    702     $cats = return_categories_list( $parent);
    703     $result = array ();
    704 
    705     if ( is_array( $cats ) ) {
    706         foreach ( $cats as $cat) {
    707             $result[$cat]['children'] = get_nested_categories( $default, $cat);
    708             $result[$cat]['cat_ID'] = $cat;
    709             $result[$cat]['checked'] = in_array( $cat, $checked_categories );
    710             $result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
    711         }
    712     }
    713 
    714     usort( $result, 'sort_cats' );
    715 
    716     return $result;
    717 }
    718 
    719 function write_nested_categories( $categories ) {
    720     foreach ( $categories as $category ) {
    721         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( apply_filters('the_category', $category['cat_name'] )), "</label></li>";
    722 
    723         if ( $category['children'] ) {
    724             echo "<ul>\n";
    725             write_nested_categories( $category['children'] );
    726             echo "</ul>\n";
    727         }
    728     }
    729 }
    730 
    731 function dropdown_categories( $default = 0 ) {
    732     write_nested_categories( get_nested_categories( $default) );
    733 }
    734 
    735 function return_link_categories_list( $parent = 0 ) {
    736     global $wpdb;
    737     return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( category_count = 0  OR link_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY link_count DESC" );
    738 }
    739 
    740 function get_nested_link_categories( $default = 0, $parent = 0 ) {
    741     global $post_ID, $link_id, $mode, $wpdb;
    742 
    743     if ( $link_id ) {
    744         $checked_categories = $wpdb->get_col( "
    745              SELECT category_id
    746              FROM $wpdb->categories, $wpdb->link2cat
    747              WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id'
    748              " );
    749 
    750         if ( count( $checked_categories ) == 0 ) {
    751             // No selected categories, strange
    752             $checked_categories[] = $default;
    753         }
    754     } else {
    755         $checked_categories[] = $default;
    756     }
    757 
    758     $cats = return_link_categories_list( $parent);
    759     $result = array ();
    760 
    761     if ( is_array( $cats ) ) {
    762         foreach ( $cats as $cat) {
    763             $result[$cat]['children'] = get_nested_link_categories( $default, $cat);
    764             $result[$cat]['cat_ID'] = $cat;
    765             $result[$cat]['checked'] = in_array( $cat, $checked_categories );
    766             $result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
    767         }
    768     }
    769 
    770     usort( $result, 'sort_cats' );
    771 
    772     return $result;
    773 }
    774 
    775 function dropdown_link_categories( $default = 0 ) {
    776     write_nested_categories( get_nested_link_categories( $default) );
    777 }
    778 
    779 // Dandy new recursive multiple category stuff.
    780 function cat_rows( $parent = 0, $level = 0, $categories = 0 ) {
    781     if (!$categories )
    782         $categories = get_categories( 'hide_empty=0' );
    783 
    784     $children = _get_category_hierarchy();
    785 
    786     if ( $categories ) {
    787         ob_start();
    788         foreach ( $categories as $category ) {
    789             if ( $category->category_parent == $parent) {
    790                 echo "\t" . _cat_row( $category, $level );
    791                 if ( isset($children[$category->cat_ID]) )
    792                     cat_rows( $category->cat_ID, $level +1, $categories );
    793             }
    794         }
    795         $output = ob_get_contents();
    796         ob_end_clean();
    797 
    798         $output = apply_filters('cat_rows', $output);
    799 
    800         echo $output;
    801     } else {
    802         return false;
    803     }
    804 }
    805 
    806 function _cat_row( $category, $level, $name_override = false ) {
    807     global $class;
    808 
    809     $pad = str_repeat( '&#8212; ', $level );
    810     if ( current_user_can( 'manage_categories' ) ) {
    811         $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>".__( 'Edit' )."</a></td>";
    812         $default_cat_id = (int) get_option( 'default_category' );
    813         $default_link_cat_id = (int) get_option( 'default_link_category' );
    814 
    815         if ( ($category->cat_ID != $default_cat_id ) && ($category->cat_ID != $default_link_cat_id ) )
    816             $edit .= "<td><a href='" . wp_nonce_url( "categories.php?action=delete&amp;cat_ID=$category->cat_ID", 'delete-category_' . $category->cat_ID ) . "' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . js_escape(sprintf( __("You are about to delete the category '%s'.\nAll posts that were only assigned to this category will be assigned to the '%s' category.\nAll links that were only assigned to this category will be assigned to the '%s' category.\n'OK' to delete, 'Cancel' to stop." ), $category->cat_name, get_catname( $default_cat_id ), get_catname( $default_link_cat_id ) )) . "' );\" class='delete'>".__( 'Delete' )."</a>";
    817         else
    818             $edit .= "<td style='text-align:center'>".__( "Default" );
    819     } else
    820         $edit = '';
    821 
    822     $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
    823 
    824     $category->category_count = number_format( $category->category_count );
    825     $category->link_count = number_format( $category->link_count );
    826     $posts_count = ( $category->category_count > 0 ) ? "<a href='edit.php?cat=$category->cat_ID'>$category->category_count</a>" : $category->category_count;
    827     return "<tr id='cat-$category->cat_ID'$class>
    828         <th scope='row' style='text-align: center'>$category->cat_ID</th>
    829         <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->cat_name ) . "</td>
    830         <td>$category->category_description</td>
    831         <td align='center'>$posts_count</td>
    832         <td align='center'>$category->link_count</td>
    833         <td>$edit</td>\n\t</tr>\n";
    834 }
    835 
    836 function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) {
    837     global $wpdb, $class, $post;
    838 
    839     if (!$pages )
    840         $pages = get_pages( 'sort_column=menu_order' );
    841 
    842     if (! $pages )
    843         return false;
    844 
    845     foreach ( $pages as $post) {
    846         setup_postdata( $post);
    847         if ( $hierarchy && ($post->post_parent != $parent) )
    848             continue;
    849 
    850         $post->post_title = wp_specialchars( $post->post_title );
    851         $pad = str_repeat( '&#8212; ', $level );
    852         $id = (int) $post->ID;
    853         $class = ('alternate' == $class ) ? '' : 'alternate';
     2// Deprecated.  Use includes/admin.php.
     3require_once(ABSPATH . 'wp-admin/includes/admin.php');
    8544?>
    855   <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
    856     <th scope="row" style="text-align: center"><?php echo $post->ID; ?></th>
    857     <td>
    858       <?php echo $pad; ?><?php the_title() ?>
    859     </td>
    860     <td><?php the_author() ?></td>
    861     <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?></td>
    862     <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e( 'View' ); ?></a></td>
    863     <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td>
    864     <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&amp;post=$id", 'delete-page_' . $id ) .  "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td>
    865   </tr>
    866 
    867 <?php
    868         if ( $hierarchy ) page_rows( $id, $level + 1, $pages );
    869     }
    870 }
    871 
    872 function user_row( $user_object, $style = '' ) {
    873     if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
    874         $user_object = new WP_User( (int) $user_object );
    875     $email = $user_object->user_email;
    876     $url = $user_object->user_url;
    877     $short_url = str_replace( 'http://', '', $url );
    878     $short_url = str_replace( 'www.', '', $short_url );
    879     if ('/' == substr( $short_url, -1 ))
    880         $short_url = substr( $short_url, 0, -1 );
    881     if ( strlen( $short_url ) > 35 )
    882         $short_url =  substr( $short_url, 0, 32 ).'...';
    883     $numposts = get_usernumposts( $user_object->ID );
    884     $r = "<tr id='user-$user_object->ID'$style>
    885         <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td>
    886         <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td>
    887         <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td>
    888         <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
    889         <td><a href='$url' title='website: $url'>$short_url</a></td>";
    890     $r .= "\n\t\t<td align='center'>";
    891     if ( $numposts > 0 ) {
    892         $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
    893         $r .= sprintf(__ngettext( 'View %s post', 'View %s posts', $numposts ), $numposts);
    894         $r .= '</a>';
    895     }
    896     $r .= "</td>\n\t\t<td>";
    897     if ( current_user_can( 'edit_user', $user_object->ID ) ) {
    898         $edit_link = add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" );
    899         $r .= "<a href='$edit_link' class='edit'>".__( 'Edit' )."</a>";
    900     }
    901     $r .= "</td>\n\t</tr>";
    902     return $r;
    903 }
    904 
    905 function _wp_get_comment_list( $s = false, $start, $num ) {
    906     global $wpdb;
    907 
    908     $start = abs( (int) $start );
    909     $num = (int) $num;
    910 
    911     if ( $s ) {
    912         $s = $wpdb->escape($s);
    913         $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
    914             (comment_author LIKE '%$s%' OR
    915             comment_author_email LIKE '%$s%' OR
    916             comment_author_url LIKE ('%$s%') OR
    917             comment_author_IP LIKE ('%$s%') OR
    918             comment_content LIKE ('%$s%') ) AND
    919             comment_approved != 'spam'
    920             ORDER BY comment_date DESC LIMIT $start, $num");
    921     } else {
    922         $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $num" );
    923     }
    924 
    925     $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
    926 
    927     return array($comments, $total);
    928 }
    929 
    930 function _wp_comment_list_item( $id, $alt = 0 ) {
    931     global $authordata, $comment, $wpdb;
    932     $id = (int) $id;
    933     $comment =& get_comment( $id );
    934     $class = '';
    935     $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
    936     $comment_status = wp_get_comment_status($comment->comment_ID);
    937     if ( 'unapproved' == $comment_status )
    938         $class .= ' unapproved';
    939     if ( $alt % 2 )
    940         $class .= ' alternate';
    941     echo "<li id='comment-$comment->comment_ID' class='$class'>";
    942 ?>
    943 <p><strong><?php comment_author(); ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
    944 
    945 <?php comment_text() ?>
    946 
    947 <p><?php comment_date(__('M j, g:i A'));  ?> &#8212; [
    948 <?php
    949 if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
    950     echo " <a href='comment.php?action=editcomment&amp;c=".$comment->comment_ID."'>" .  __('Edit') . '</a>';
    951     echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
    952     if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
    953         echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
    954         echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
    955     }
    956     echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author))  . "', theCommentList );\">" . __('Spam') . "</a> ";
    957 }
    958 $post = get_post($comment->comment_post_ID);
    959 $post_title = wp_specialchars( $post->post_title, 'double' );
    960 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
    961 ?>
    962  ] &#8212; <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo $post_title; ?></a></p>
    963         </li>
    964 <?php
    965 }
    966 
    967 function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
    968     global $wpdb;
    969     if (!$categories )
    970         $categories = get_categories( 'hide_empty=0' );
    971 
    972     if ( $categories ) {
    973         foreach ( $categories as $category ) {
    974             if ( $currentcat != $category->cat_ID && $parent == $category->category_parent) {
    975                 $pad = str_repeat( '&#8211; ', $level );
    976                 $category->cat_name = wp_specialchars( $category->cat_name );
    977                 echo "\n\t<option value='$category->cat_ID'";
    978                 if ( $currentparent == $category->cat_ID )
    979                     echo " selected='selected'";
    980                 echo ">$pad$category->cat_name</option>";
    981                 wp_dropdown_cats( $currentcat, $currentparent, $category->cat_ID, $level +1, $categories );
    982             }
    983         }
    984     } else {
    985         return false;
    986     }
    987 }
    988 
    989 // Some postmeta stuff
    990 function has_meta( $postid ) {
    991     global $wpdb;
    992 
    993     return $wpdb->get_results( "
    994             SELECT meta_key, meta_value, meta_id, post_id
    995             FROM $wpdb->postmeta
    996             WHERE post_id = '$postid'
    997             ORDER BY meta_key,meta_id", ARRAY_A );
    998 
    999 }
    1000 
    1001 function list_meta( $meta ) {
    1002     global $post_ID;
    1003     // Exit if no meta
    1004     if (!$meta ) {
    1005         echo '<tbody id="the-list"><tr style="display: none;"><td>&nbsp;</td></tr></tbody>'; //TBODY needed for list-manipulation JS
    1006         return;
    1007     }
    1008     $count = 0;
    1009 ?>
    1010     <thead>
    1011     <tr>
    1012         <th><?php _e( 'Key' ) ?></th>
    1013         <th><?php _e( 'Value' ) ?></th>
    1014         <th colspan='2'><?php _e( 'Action' ) ?></th>
    1015     </tr>
    1016     </thead>
    1017 <?php
    1018     $r ="\n\t<tbody id='the-list'>";
    1019     foreach ( $meta as $entry ) {
    1020         ++ $count;
    1021         if ( $count % 2 )
    1022             $style = 'alternate';
    1023         else
    1024             $style = '';
    1025         if ('_' == $entry['meta_key'] { 0 } )
    1026             $style .= ' hidden';
    1027 
    1028         if ( is_serialized( $entry['meta_value'] ) ) {
    1029             if ( is_serialized_string( $entry['meta_value'] ) ) {
    1030                 // this is a serialized string, so we should display it
    1031                 $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
    1032             } else {
    1033                 // this is a serialized array/object so we should NOT display it
    1034                 --$count;
    1035                 continue;
    1036             }
    1037         }
    1038 
    1039         $key_js = js_escape( $entry['meta_key'] );
    1040         $entry['meta_key']   = attribute_escape($entry['meta_key']);
    1041         $entry['meta_value'] = attribute_escape($entry['meta_value']);
    1042         $entry['meta_id'] = (int) $entry['meta_id'];
    1043         $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
    1044         $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>";
    1045         $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
    1046         $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".attribute_escape(__( 'Update' ))."' /><br />";
    1047         $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '";
    1048         $r .= js_escape(sprintf( __("You are about to delete the '%s' custom field on this post.\n'OK' to delete, 'Cancel' to stop." ), $key_js ) );
    1049         $r .= "' );\" class='deletemeta' tabindex='6' value='".attribute_escape(__( 'Delete' ))."' /></td>";
    1050         $r .= "\n\t</tr>";
    1051     }
    1052     echo $r;
    1053     echo "\n\t</tbody>";
    1054 }
    1055 
    1056 // Get a list of previously defined keys
    1057 function get_meta_keys() {
    1058     global $wpdb;
    1059 
    1060     $keys = $wpdb->get_col( "
    1061             SELECT meta_key
    1062             FROM $wpdb->postmeta
    1063             GROUP BY meta_key
    1064             ORDER BY meta_key" );
    1065 
    1066     return $keys;
    1067 }
    1068 
    1069 function meta_form() {
    1070     global $wpdb;
    1071     $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
    1072     $keys = $wpdb->get_col( "
    1073         SELECT meta_key
    1074         FROM $wpdb->postmeta
    1075         GROUP BY meta_key
    1076         ORDER BY meta_id DESC
    1077         LIMIT $limit" );
    1078     if ( $keys )
    1079         natcasesort($keys);
    1080 ?>
    1081 <h3><?php _e( 'Add a new custom field:' ) ?></h3>
    1082 <table id="newmeta" cellspacing="3" cellpadding="3">
    1083     <tr>
    1084 <th colspan="2"><?php _e( 'Key' ) ?></th>
    1085 <th><?php _e( 'Value' ) ?></th>
    1086 </tr>
    1087     <tr valign="top">
    1088         <td align="right" width="18%">
    1089 <?php if ( $keys ) : ?>
    1090 <select id="metakeyselect" name="metakeyselect" tabindex="7">
    1091 <option value="#NONE#"><?php _e( '- Select -' ); ?></option>
    1092 <?php
    1093 
    1094     foreach ( $keys as $key ) {
    1095         $key = attribute_escape( $key );
    1096         echo "\n\t<option value='$key'>$key</option>";
    1097     }
    1098 ?>
    1099 </select> <?php _e( 'or' ); ?>
    1100 <?php endif; ?>
    1101 </td>
    1102 <td><input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" /></td>
    1103         <td><textarea id="metavalue" name="metavalue" rows="3" cols="25" tabindex="8"></textarea></td>
    1104     </tr>
    1105 
    1106 </table>
    1107 <p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e( 'Add Custom Field &raquo;' ) ?>" /></p>
    1108 <?php
    1109 
    1110 }
    1111 
    1112 function add_meta( $post_ID ) {
    1113     global $wpdb;
    1114     $post_ID = (int) $post_ID;
    1115 
    1116     $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' );
    1117 
    1118     $metakeyselect = $wpdb->escape( stripslashes( trim( $_POST['metakeyselect'] ) ) );
    1119     $metakeyinput = $wpdb->escape( stripslashes( trim( $_POST['metakeyinput'] ) ) );
    1120     $metavalue = maybe_serialize( stripslashes( (trim( $_POST['metavalue'] ) ) ));
    1121     $metavalue = $wpdb->escape( $metavalue );
    1122 
    1123     if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
    1124         // We have a key/value pair. If both the select and the
    1125         // input for the key have data, the input takes precedence:
    1126 
    1127         if ('#NONE#' != $metakeyselect)
    1128             $metakey = $metakeyselect;
    1129 
    1130         if ( $metakeyinput)
    1131             $metakey = $metakeyinput; // default
    1132 
    1133         if ( in_array($metakey, $protected) )
    1134             return false;
    1135 
    1136         $result = $wpdb->query( "
    1137                         INSERT INTO $wpdb->postmeta
    1138                         (post_id,meta_key,meta_value )
    1139                         VALUES ('$post_ID','$metakey','$metavalue' )
    1140                     " );
    1141         return $wpdb->insert_id;
    1142     }
    1143     return false;
    1144 } // add_meta
    1145 
    1146 function delete_meta( $mid ) {
    1147     global $wpdb;
    1148     $mid = (int) $mid;
    1149 
    1150     return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'" );
    1151 }
    1152 
    1153 function update_meta( $mid, $mkey, $mvalue ) {
    1154     global $wpdb;
    1155 
    1156     $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' );
    1157 
    1158     if ( in_array($mkey, $protected) )
    1159         return false;
    1160 
    1161     $mvalue = maybe_serialize( stripslashes( $mvalue ));
    1162     $mvalue = $wpdb->escape( $mvalue );
    1163     $mid = (int) $mid;
    1164     return $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'" );
    1165 }
    1166 
    1167 function get_post_meta_by_id( $mid ) {
    1168     global $wpdb;
    1169     $mid = (int) $mid;
    1170 
    1171     $meta = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'" );
    1172     if ( is_serialized_string( $meta->meta_value ) )
    1173         $meta->meta_value = maybe_unserialize( $meta->meta_value );
    1174     return $meta;
    1175 }
    1176 
    1177 function touch_time( $edit = 1, $for_post = 1 ) {
    1178     global $wp_locale, $post, $comment;
    1179 
    1180     if ( $for_post )
    1181         $edit = ( ('draft' == $post->post_status ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true;
    1182  
    1183     echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>';
    1184 
    1185     $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
    1186     $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
    1187     $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj );
    1188     $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj );
    1189     $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj );
    1190     $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj );
    1191     $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
    1192     $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
    1193 
    1194     echo "<select name=\"mm\" onchange=\"edit_date.checked=true\">\n";
    1195     for ( $i = 1; $i < 13; $i = $i +1 ) {
    1196         echo "\t\t\t<option value=\"$i\"";
    1197         if ( $i == $mm )
    1198             echo ' selected="selected"';
    1199         echo '>' . $wp_locale->get_month( $i ) . "</option>\n";
    1200     }
    1201 ?>
    1202 </select>
    1203 <input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" onchange="edit_date.checked=true"/>
    1204 <input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true" /> @
    1205 <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> :
    1206 <input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />
    1207 <input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />
    1208 <?php
    1209     if ( $edit ) {
    1210         printf( __('Existing timestamp: %1$s %2$s, %3$s @ %4$s:%5$s' ), $wp_locale->get_month( $mm ), $jj, $aa, $hh, $mn );
    1211     }
    1212 ?>
    1213 </fieldset>
    1214     <?php
    1215 
    1216 }
    1217 
    1218 // insert_with_markers: Owen Winkler, fixed by Eric Anderson
    1219 // Inserts an array of strings into a file (.htaccess ), placing it between
    1220 // BEGIN and END markers.  Replaces existing marked info.  Retains surrounding
    1221 // data.  Creates file if none exists.
    1222 // Returns true on write success, false on failure.
    1223 function insert_with_markers( $filename, $marker, $insertion ) {
    1224     if (!file_exists( $filename ) || is_writeable( $filename ) ) {
    1225         if (!file_exists( $filename ) ) {
    1226             $markerdata = '';
    1227         } else {
    1228             $markerdata = explode( "\n", implode( '', file( $filename ) ) );
    1229         }
    1230 
    1231         $f = fopen( $filename, 'w' );
    1232         $foundit = false;
    1233         if ( $markerdata ) {
    1234             $state = true;
    1235             foreach ( $markerdata as $n => $markerline ) {
    1236                 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
    1237                     $state = false;
    1238                 if ( $state ) {
    1239                     if ( $n + 1 < count( $markerdata ) )
    1240                         fwrite( $f, "{$markerline}\n" );
    1241                     else
    1242                         fwrite( $f, "{$markerline}" );
    1243                 }
    1244                 if (strpos($markerline, '# END ' . $marker) !== false) {
    1245                     fwrite( $f, "# BEGIN {$marker}\n" );
    1246                     if ( is_array( $insertion ))
    1247                         foreach ( $insertion as $insertline )
    1248                             fwrite( $f, "{$insertline}\n" );
    1249                     fwrite( $f, "# END {$marker}\n" );
    1250                     $state = true;
    1251                     $foundit = true;
    1252                 }
    1253             }
    1254         }
    1255         if (!$foundit) {
    1256             fwrite( $f, "# BEGIN {$marker}\n" );
    1257             foreach ( $insertion as $insertline )
    1258                 fwrite( $f, "{$insertline}\n" );
    1259             fwrite( $f, "# END {$marker}\n" );
    1260         }
    1261         fclose( $f );
    1262         return true;
    1263     } else {
    1264         return false;
    1265     }
    1266 }
    1267 
    1268 // extract_from_markers: Owen Winkler
    1269 // Returns an array of strings from a file (.htaccess ) from between BEGIN
    1270 // and END markers.
    1271 function extract_from_markers( $filename, $marker ) {
    1272     $result = array ();
    1273 
    1274     if (!file_exists( $filename ) ) {
    1275         return $result;
    1276     }
    1277 
    1278     if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) ));
    1279     {
    1280         $state = false;
    1281         foreach ( $markerdata as $markerline ) {
    1282             if (strpos($markerline, '# END ' . $marker) !== false)
    1283                 $state = false;
    1284             if ( $state )
    1285                 $result[] = $markerline;
    1286             if (strpos($markerline, '# BEGIN ' . $marker) !== false)
    1287                 $state = true;
    1288         }
    1289     }
    1290 
    1291     return $result;
    1292 }
    1293 
    1294 function got_mod_rewrite() {
    1295     global $is_apache;
    1296 
    1297     // take 3 educated guesses as to whether or not mod_rewrite is available
    1298     if ( !$is_apache )
    1299         return false;
    1300 
    1301     if ( function_exists( 'apache_get_modules' ) ) {
    1302         if ( !in_array( 'mod_rewrite', apache_get_modules() ) )
    1303             return false;
    1304     }
    1305 
    1306     return true;
    1307 }
    1308 
    1309 function save_mod_rewrite_rules() {
    1310     global $is_apache, $wp_rewrite;
    1311     $home_path = get_home_path();
    1312 
    1313     if (!$wp_rewrite->using_mod_rewrite_permalinks() )
    1314         return false;
    1315 
    1316     if (!((!file_exists( $home_path.'.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path.'.htaccess' ) ) )
    1317         return false;
    1318 
    1319     if (! got_mod_rewrite() )
    1320         return false;
    1321 
    1322     $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
    1323     return insert_with_markers( $home_path.'.htaccess', 'WordPress', $rules );
    1324 }
    1325 
    1326 function get_broken_themes() {
    1327     global $wp_broken_themes;
    1328 
    1329     get_themes();
    1330     return $wp_broken_themes;
    1331 }
    1332 
    1333 function get_page_templates() {
    1334     $themes = get_themes();
    1335     $theme = get_current_theme();
    1336     $templates = $themes[$theme]['Template Files'];
    1337     $page_templates = array ();
    1338 
    1339     if ( is_array( $templates ) ) {
    1340         foreach ( $templates as $template ) {
    1341             $template_data = implode( '', file( ABSPATH.$template ));
    1342             preg_match( "|Template Name:(.*)|i", $template_data, $name );
    1343             preg_match( "|Description:(.*)|i", $template_data, $description );
    1344 
    1345             $name = $name[1];
    1346             $description = $description[1];
    1347 
    1348             if (!empty ( $name ) ) {
    1349                 $page_templates[trim( $name )] = basename( $template );
    1350             }
    1351         }
    1352     }
    1353 
    1354     return $page_templates;
    1355 }
    1356 
    1357 function page_template_dropdown( $default = '' ) {
    1358     $templates = get_page_templates();
    1359     foreach (array_keys( $templates ) as $template )
    1360         : if ( $default == $templates[$template] )
    1361             $selected = " selected='selected'";
    1362         else
    1363             $selected = '';
    1364     echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
    1365     endforeach;
    1366 }
    1367 
    1368 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
    1369     global $wpdb, $post_ID;
    1370     $items = $wpdb->get_results( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order" );
    1371 
    1372     if ( $items ) {
    1373         foreach ( $items as $item ) {
    1374             // A page cannot be its own parent.
    1375             if (!empty ( $post_ID ) ) {
    1376                 if ( $item->ID == $post_ID ) {
    1377                     continue;
    1378                 }
    1379             }
    1380             $pad = str_repeat( '&nbsp;', $level * 3 );
    1381             if ( $item->ID == $default)
    1382                 $current = ' selected="selected"';
    1383             else
    1384                 $current = '';
    1385 
    1386             echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</option>";
    1387             parent_dropdown( $default, $item->ID, $level +1 );
    1388         }
    1389     } else {
    1390         return false;
    1391     }
    1392 }
    1393 
    1394 function user_can_access_admin_page() {
    1395     global $pagenow;
    1396     global $menu;
    1397     global $submenu;
    1398     global $_wp_menu_nopriv;
    1399     global $_wp_submenu_nopriv;
    1400     global $plugin_page;
    1401 
    1402     $parent = get_admin_page_parent();
    1403 
    1404     if ( isset( $_wp_submenu_nopriv[$parent][$pagenow] ) )
    1405         return false;
    1406 
    1407     if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) )
    1408         return false;
    1409 
    1410     if ( empty( $parent) ) {
    1411         if ( isset( $_wp_menu_nopriv[$pagenow] ) )
    1412             return false;
    1413         if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) )
    1414             return false;
    1415         if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) )
    1416             return false;
    1417         foreach (array_keys( $_wp_submenu_nopriv ) as $key ) {
    1418             if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) )
    1419                 return false;
    1420             if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) )
    1421             return false;
    1422         }
    1423         return true;
    1424     }
    1425 
    1426     if ( isset( $submenu[$parent] ) ) {
    1427         foreach ( $submenu[$parent] as $submenu_array ) {
    1428             if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) {
    1429                 if ( current_user_can( $submenu_array[1] ))
    1430                     return true;
    1431                 else
    1432                     return false;
    1433             } else if ( $submenu_array[2] == $pagenow ) {
    1434                 if ( current_user_can( $submenu_array[1] ))
    1435                     return true;
    1436                 else
    1437                     return false;
    1438             }
    1439         }
    1440     }
    1441 
    1442     foreach ( $menu as $menu_array ) {
    1443         if ( $menu_array[2] == $parent) {
    1444             if ( current_user_can( $menu_array[1] ))
    1445                 return true;
    1446             else
    1447                 return false;
    1448         }
    1449     }
    1450 
    1451     return true;
    1452 }
    1453 
    1454 function get_admin_page_title() {
    1455     global $title;
    1456     global $menu;
    1457     global $submenu;
    1458     global $pagenow;
    1459     global $plugin_page;
    1460 
    1461     if ( isset( $title ) && !empty ( $title ) ) {
    1462         return $title;
    1463     }
    1464 
    1465     $hook = get_plugin_page_hook( $plugin_page, $pagenow );
    1466 
    1467     $parent = $parent1 = get_admin_page_parent();
    1468     if ( empty ( $parent) ) {
    1469         foreach ( $menu as $menu_array ) {
    1470             if ( isset( $menu_array[3] ) ) {
    1471                 if ( $menu_array[2] == $pagenow ) {
    1472                     $title = $menu_array[3];
    1473                     return $menu_array[3];
    1474                 } else
    1475                     if ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) {
    1476                         $title = $menu_array[3];
    1477                         return $menu_array[3];
    1478                     }
    1479             } else {
    1480                 $title = $menu_array[0];
    1481                 return $title;
    1482             }
    1483         }
    1484     } else {
    1485         foreach (array_keys( $submenu ) as $parent) {
    1486             foreach ( $submenu[$parent] as $submenu_array ) {
    1487                 if ( isset( $plugin_page ) &&
    1488                     ($plugin_page == $submenu_array[2] ) &&
    1489                     (($parent == $pagenow ) || ($parent == $plugin_page ) || ($plugin_page == $hook ) || (($pagenow == 'admin.php' ) && ($parent1 != $submenu_array[2] ) ) )
    1490                     ) {
    1491                         $title = $submenu_array[3];
    1492                         return $submenu_array[3];
    1493                     }
    1494 
    1495                 if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page
    1496                     continue;
    1497 
    1498                 if ( isset( $submenu_array[3] ) ) {
    1499                     $title = $submenu_array[3];
    1500                     return $submenu_array[3];
    1501                 } else {
    1502                     $title = $submenu_array[0];
    1503                     return $title;
    1504                 }
    1505             }
    1506         }
    1507     }
    1508 
    1509     return $title;
    1510 }
    1511 
    1512 function get_admin_page_parent() {
    1513     global $parent_file;
    1514     global $menu;
    1515     global $submenu;
    1516     global $pagenow;
    1517     global $plugin_page;
    1518     global $_wp_real_parent_file;
    1519     global $_wp_menu_nopriv;
    1520     global $_wp_submenu_nopriv;
    1521 
    1522     if ( !empty ( $parent_file ) ) {
    1523         if ( isset( $_wp_real_parent_file[$parent_file] ) )
    1524             $parent_file = $_wp_real_parent_file[$parent_file];
    1525 
    1526         return $parent_file;
    1527     }
    1528 
    1529     if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) {
    1530         foreach ( $menu as $parent_menu ) {
    1531             if ( $parent_menu[2] == $plugin_page ) {
    1532                 $parent_file = $plugin_page;
    1533                 if ( isset( $_wp_real_parent_file[$parent_file] ) )
    1534                     $parent_file = $_wp_real_parent_file[$parent_file];
    1535                 return $parent_file;
    1536             }
    1537         }
    1538         if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) {
    1539             $parent_file = $plugin_page;
    1540             if ( isset( $_wp_real_parent_file[$parent_file] ) )
    1541                     $parent_file = $_wp_real_parent_file[$parent_file];
    1542             return $parent_file;
    1543         }
    1544     }
    1545 
    1546     if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) {
    1547         $parent_file = $pagenow;
    1548         if ( isset( $_wp_real_parent_file[$parent_file] ) )
    1549             $parent_file = $_wp_real_parent_file[$parent_file];
    1550         return $parent_file;
    1551     }
    1552 
    1553     foreach (array_keys( $submenu ) as $parent) {
    1554         foreach ( $submenu[$parent] as $submenu_array ) {
    1555             if ( isset( $_wp_real_parent_file[$parent] ) )
    1556                 $parent = $_wp_real_parent_file[$parent];
    1557             if ( $submenu_array[2] == $pagenow ) {
    1558                 $parent_file = $parent;
    1559                 return $parent;
    1560             } else
    1561                 if ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) {
    1562                     $parent_file = $parent;
    1563                     return $parent;
    1564                 }
    1565         }
    1566     }
    1567 
    1568     $parent_file = '';
    1569     return '';
    1570 }
    1571 
    1572 function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
    1573     global $menu, $admin_page_hooks;
    1574 
    1575     $file = plugin_basename( $file );
    1576 
    1577     $menu[] = array ( $menu_title, $access_level, $file, $page_title );
    1578 
    1579     $admin_page_hooks[$file] = sanitize_title( $menu_title );
    1580 
    1581     $hookname = get_plugin_page_hookname( $file, '' );
    1582     if (!empty ( $function ) && !empty ( $hookname ))
    1583         add_action( $hookname, $function );
    1584 
    1585     return $hookname;
    1586 }
    1587 
    1588 function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) {
    1589     global $submenu;
    1590     global $menu;
    1591     global $_wp_real_parent_file;
    1592     global $_wp_submenu_nopriv;
    1593     global $_wp_menu_nopriv;
    1594 
    1595     $file = plugin_basename( $file );
    1596 
    1597     $parent = plugin_basename( $parent);
    1598     if ( isset( $_wp_real_parent_file[$parent] ) )
    1599         $parent = $_wp_real_parent_file[$parent];
    1600 
    1601     if ( !current_user_can( $access_level ) ) {
    1602         $_wp_submenu_nopriv[$parent][$file] = true;
    1603         return false;
    1604     }
    1605 
    1606     // If the parent doesn't already have a submenu, add a link to the parent
    1607     // as the first item in the submenu.  If the submenu file is the same as the
    1608     // parent file someone is trying to link back to the parent manually.  In
    1609     // this case, don't automatically add a link back to avoid duplication.
    1610     if (!isset( $submenu[$parent] ) && $file != $parent  ) {
    1611         foreach ( $menu as $parent_menu ) {
    1612             if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1] ) )
    1613                 $submenu[$parent][] = $parent_menu;
    1614         }
    1615     }
    1616 
    1617     $submenu[$parent][] = array ( $menu_title, $access_level, $file, $page_title );
    1618 
    1619     $hookname = get_plugin_page_hookname( $file, $parent);
    1620     if (!empty ( $function ) && !empty ( $hookname ))
    1621         add_action( $hookname, $function );
    1622 
    1623     return $hookname;
    1624 }
    1625 
    1626 function add_options_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
    1627     return add_submenu_page( 'options-general.php', $page_title, $menu_title, $access_level, $file, $function );
    1628 }
    1629 
    1630 function add_management_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
    1631     return add_submenu_page( 'edit.php', $page_title, $menu_title, $access_level, $file, $function );
    1632 }
    1633 
    1634 function add_theme_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
    1635     return add_submenu_page( 'themes.php', $page_title, $menu_title, $access_level, $file, $function );
    1636 }
    1637 
    1638 function add_users_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
    1639     if ( current_user_can('edit_users') )
    1640         $parent = 'users.php';
    1641     else
    1642         $parent = 'profile.php';
    1643     return add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function );
    1644 }
    1645 
    1646 function validate_file( $file, $allowed_files = '' ) {
    1647     if ( false !== strpos( $file, './' ))
    1648         return 1;
    1649 
    1650     if (':' == substr( $file, 1, 1 ))
    1651         return 2;
    1652 
    1653     if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) )
    1654         return 3;
    1655 
    1656     return 0;
    1657 }
    1658 
    1659 function validate_file_to_edit( $file, $allowed_files = '' ) {
    1660     $file = stripslashes( $file );
    1661 
    1662     $code = validate_file( $file, $allowed_files );
    1663 
    1664     if (!$code )
    1665         return $file;
    1666 
    1667     switch ( $code ) {
    1668         case 1 :
    1669             wp_die( __('Sorry, can&#8217;t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.' ));
    1670 
    1671         case 2 :
    1672             wp_die( __('Sorry, can&#8217;t call files with their real path.' ));
    1673 
    1674         case 3 :
    1675             wp_die( __('Sorry, that file cannot be edited.' ));
    1676     }
    1677 }
    1678 
    1679 function get_home_path() {
    1680     $home = get_option( 'home' );
    1681     if ( $home != '' && $home != get_option( 'siteurl' ) ) {
    1682         $home_path = parse_url( $home );
    1683         $home_path = $home_path['path'];
    1684         $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] );
    1685         $home_path = trailingslashit( $root.$home_path );
    1686     } else {
    1687         $home_path = ABSPATH;
    1688     }
    1689 
    1690     return $home_path;
    1691 }
    1692 
    1693 function get_real_file_to_edit( $file ) {
    1694     if ('index.php' == $file || '.htaccess' == $file ) {
    1695         $real_file = get_home_path().$file;
    1696     } else {
    1697         $real_file = ABSPATH.$file;
    1698     }
    1699 
    1700     return $real_file;
    1701 }
    1702 
    1703 $wp_file_descriptions = array ('index.php' => __( 'Main Index Template' ), 'style.css' => __( 'Stylesheet' ), 'comments.php' => __( 'Comments' ), 'comments-popup.php' => __( 'Popup Comments' ), 'footer.php' => __( 'Footer' ), 'header.php' => __( 'Header' ), 'sidebar.php' => __( 'Sidebar' ), 'archive.php' => __( 'Archives' ), 'category.php' => __( 'Category Template' ), 'page.php' => __( 'Page Template' ), 'search.php' => __( 'Search Results' ), 'single.php' => __( 'Single Post' ), '404.php' => __( '404 Template' ), 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ), '.htaccess' => __( '.htaccess (for rewrite rules )' ),
    1704     // Deprecated files
    1705     'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' ));
    1706 
    1707 function get_file_description( $file ) {
    1708     global $wp_file_descriptions;
    1709 
    1710     if ( isset( $wp_file_descriptions[basename( $file )] ) ) {
    1711         return $wp_file_descriptions[basename( $file )];
    1712     }
    1713     elseif ( file_exists( ABSPATH . $file ) && is_file( ABSPATH . $file ) ) {
    1714         $template_data = implode( '', file( ABSPATH . $file ) );
    1715         if ( preg_match( "|Template Name:(.*)|i", $template_data, $name ))
    1716             return $name[1];
    1717     }
    1718 
    1719     return basename( $file );
    1720 }
    1721 
    1722 function update_recently_edited( $file ) {
    1723     $oldfiles = (array ) get_option( 'recently_edited' );
    1724     if ( $oldfiles ) {
    1725         $oldfiles = array_reverse( $oldfiles );
    1726         $oldfiles[] = $file;
    1727         $oldfiles = array_reverse( $oldfiles );
    1728         $oldfiles = array_unique( $oldfiles );
    1729         if ( 5 < count( $oldfiles ))
    1730             array_pop( $oldfiles );
    1731     } else {
    1732         $oldfiles[] = $file;
    1733     }
    1734     update_option( 'recently_edited', $oldfiles );
    1735 }
    1736 
    1737 function get_plugin_data( $plugin_file ) {
    1738     $plugin_data = implode( '', file( $plugin_file ));
    1739     preg_match( "|Plugin Name:(.*)|i", $plugin_data, $plugin_name );
    1740     preg_match( "|Plugin URI:(.*)|i", $plugin_data, $plugin_uri );
    1741     preg_match( "|Description:(.*)|i", $plugin_data, $description );
    1742     preg_match( "|Author:(.*)|i", $plugin_data, $author_name );
    1743     preg_match( "|Author URI:(.*)|i", $plugin_data, $author_uri );
    1744     if ( preg_match( "|Version:(.*)|i", $plugin_data, $version ))
    1745         $version = trim( $version[1] );
    1746     else
    1747         $version = '';
    1748 
    1749     $description = wptexturize( trim( $description[1] ));
    1750 
    1751     $name = $plugin_name[1];
    1752     $name = trim( $name );
    1753     $plugin = $name;
    1754     if ('' != $plugin_uri[1] && '' != $name ) {
    1755         $plugin = '<a href="' . trim( $plugin_uri[1] ) . '" title="'.__( 'Visit plugin homepage' ).'">'.$plugin.'</a>';
    1756     }
    1757 
    1758     if ('' == $author_uri[1] ) {
    1759         $author = trim( $author_name[1] );
    1760     } else {
    1761         $author = '<a href="' . trim( $author_uri[1] ) . '" title="'.__( 'Visit author homepage' ).'">' . trim( $author_name[1] ) . '</a>';
    1762     }
    1763 
    1764     return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version);
    1765 }
    1766 
    1767 function get_plugins() {
    1768     global $wp_plugins;
    1769 
    1770     if ( isset( $wp_plugins ) ) {
    1771         return $wp_plugins;
    1772     }
    1773 
    1774     $wp_plugins = array ();
    1775     $plugin_root = ABSPATH . PLUGINDIR;
    1776 
    1777     // Files in wp-content/plugins directory
    1778     $plugins_dir = @ dir( $plugin_root);
    1779     if ( $plugins_dir ) {
    1780         while (($file = $plugins_dir->read() ) !== false ) {
    1781             if ( substr($file, 0, 1) == '.' )
    1782                 continue;
    1783             if ( is_dir( $plugin_root.'/'.$file ) ) {
    1784                 $plugins_subdir = @ dir( $plugin_root.'/'.$file );
    1785                 if ( $plugins_subdir ) {
    1786                     while (($subfile = $plugins_subdir->read() ) !== false ) {
    1787                         if ( substr($subfile, 0, 1) == '.' )
    1788                             continue;
    1789                         if ( substr($subfile, -4) == '.php' )
    1790                             $plugin_files[] = "$file/$subfile";
    1791                     }
    1792                 }
    1793             } else {
    1794                 if ( substr($file, -4) == '.php' )
    1795                     $plugin_files[] = $file;
    1796             }
    1797         }
    1798     }
    1799 
    1800     if ( !$plugins_dir || !$plugin_files )
    1801         return $wp_plugins;
    1802 
    1803     foreach ( $plugin_files as $plugin_file ) {
    1804         if ( !is_readable( "$plugin_root/$plugin_file" ) )
    1805             continue;
    1806 
    1807         $plugin_data = get_plugin_data( "$plugin_root/$plugin_file" );
    1808 
    1809         if ( empty ( $plugin_data['Name'] ) )
    1810             continue;
    1811 
    1812         $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data;
    1813     }
    1814 
    1815     uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
    1816 
    1817     return $wp_plugins;
    1818 }
    1819 
    1820 function get_plugin_page_hookname( $plugin_page, $parent_page ) {
    1821     global $admin_page_hooks;
    1822 
    1823     $parent = get_admin_page_parent();
    1824 
    1825     if ( empty ( $parent_page ) || 'admin.php' == $parent_page ) {
    1826         if ( isset( $admin_page_hooks[$plugin_page] ))
    1827             $page_type = 'toplevel';
    1828         else
    1829             if ( isset( $admin_page_hooks[$parent] ))
    1830                 $page_type = $admin_page_hooks[$parent];
    1831     } else
    1832         if ( isset( $admin_page_hooks[$parent_page] ) ) {
    1833             $page_type = $admin_page_hooks[$parent_page];
    1834         } else {
    1835             $page_type = 'admin';
    1836         }
    1837 
    1838     $plugin_name = preg_replace( '!\.php!', '', $plugin_page );
    1839 
    1840     return $page_type.'_page_'.$plugin_name;
    1841 }
    1842 
    1843 function get_plugin_page_hook( $plugin_page, $parent_page ) {
    1844     global $wp_filter;
    1845 
    1846     $hook = get_plugin_page_hookname( $plugin_page, $parent_page );
    1847     if ( isset( $wp_filter[$hook] ))
    1848         return $hook;
    1849     else
    1850         return '';
    1851 }
    1852 
    1853 function browse_happy() {
    1854     $getit = __( 'WordPress recommends a better browser' );
    1855     echo '
    1856         <p id="bh" style="text-align: center;"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></p>
    1857         ';
    1858 }
    1859 
    1860 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
    1861     add_action( 'admin_footer', 'browse_happy' );
    1862 
    1863 function documentation_link( $for ) {
    1864     return;
    1865 }
    1866 
    1867 function register_importer( $id, $name, $description, $callback ) {
    1868     global $wp_importers;
    1869 
    1870     $wp_importers[$id] = array ( $name, $description, $callback );
    1871 }
    1872 
    1873 function get_importers() {
    1874     global $wp_importers;
    1875     uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
    1876     return $wp_importers;
    1877 }
    1878 
    1879 function current_theme_info() {
    1880     $themes = get_themes();
    1881     $current_theme = get_current_theme();
    1882     $ct->name = $current_theme;
    1883     $ct->title = $themes[$current_theme]['Title'];
    1884     $ct->version = $themes[$current_theme]['Version'];
    1885     $ct->parent_theme = $themes[$current_theme]['Parent Theme'];
    1886     $ct->template_dir = $themes[$current_theme]['Template Dir'];
    1887     $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir'];
    1888     $ct->template = $themes[$current_theme]['Template'];
    1889     $ct->stylesheet = $themes[$current_theme]['Stylesheet'];
    1890     $ct->screenshot = $themes[$current_theme]['Screenshot'];
    1891     $ct->description = $themes[$current_theme]['Description'];
    1892     $ct->author = $themes[$current_theme]['Author'];
    1893     return $ct;
    1894 }
    1895 
    1896 
    1897 // array wp_handle_upload ( array &file [, array overrides] )
    1898 // file: reference to a single element of $_FILES. Call the function once for each uploaded file.
    1899 // overrides: an associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ).
    1900 // On success, returns an associative array of file attributes.
    1901 // On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
    1902 function wp_handle_upload( &$file, $overrides = false ) {
    1903     // The default error handler.
    1904     if (! function_exists( 'wp_handle_upload_error' ) ) {
    1905         function wp_handle_upload_error( &$file, $message ) {
    1906             return array( 'error'=>$message );
    1907         }
    1908     }
    1909 
    1910     // You may define your own function and pass the name in $overrides['upload_error_handler']
    1911     $upload_error_handler = 'wp_handle_upload_error';
    1912 
    1913     // $_POST['action'] must be set and its value must equal $overrides['action'] or this:
    1914     $action = 'wp_handle_upload';
    1915 
    1916     // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
    1917     $upload_error_strings = array( false,
    1918         __( "The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>." ),
    1919         __( "The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form." ),
    1920         __( "The uploaded file was only partially uploaded." ),
    1921         __( "No file was uploaded." ),
    1922         __( "Missing a temporary folder." ),
    1923         __( "Failed to write file to disk." ));
    1924 
    1925     // All tests are on by default. Most can be turned off by $override[{test_name}] = false;
    1926     $test_form = true;
    1927     $test_size = true;
    1928 
    1929     // If you override this, you must provide $ext and $type!!!!
    1930     $test_type = true;
    1931 
    1932     // Install user overrides. Did we mention that this voids your warranty?
    1933     if ( is_array( $overrides ) )
    1934         extract( $overrides, EXTR_OVERWRITE );
    1935 
    1936     // A correct form post will pass this test.
    1937     if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) )
    1938         return $upload_error_handler( $file, __( 'Invalid form submission.' ));
    1939 
    1940     // A successful upload will pass this test. It makes no sense to override this one.
    1941     if ( $file['error'] > 0 )
    1942         return $upload_error_handler( $file, $upload_error_strings[$file['error']] );
    1943 
    1944     // A non-empty file will pass this test.
    1945     if ( $test_size && !($file['size'] > 0 ) )
    1946         return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial.' ));
    1947 
    1948     // A properly uploaded file will pass this test. There should be no reason to override this one.
    1949     if (! @ is_uploaded_file( $file['tmp_name'] ) )
    1950         return $upload_error_handler( $file, __( 'Specified file failed upload test.' ));
    1951 
    1952     // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
    1953     if ( $test_type ) {
    1954         $wp_filetype = wp_check_filetype( $file['name'], $mimes );
    1955 
    1956         extract( $wp_filetype );
    1957 
    1958         if ( !$type || !$ext )
    1959             return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' ));
    1960     }
    1961 
    1962     // A writable uploads dir will pass this test. Again, there's no point overriding this one.
    1963     if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
    1964         return $upload_error_handler( $file, $uploads['error'] );
    1965 
    1966     // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
    1967     if ( isset( $unique_filename_callback ) && function_exists( $unique_filename_callback ) ) {
    1968         $filename = $unique_filename_callback( $uploads['path'], $file['name'] );
    1969     } else {
    1970         $number = '';
    1971         $filename = str_replace( '#', '_', $file['name'] );
    1972         $filename = str_replace( array( '\\', "'" ), '', $filename );
    1973         if ( empty( $ext) )
    1974             $ext = '';
    1975         else
    1976             $ext = ".$ext";
    1977         while ( file_exists( $uploads['path'] . "/$filename" ) ) {
    1978             if ( '' == "$number$ext" )
    1979                 $filename = $filename . ++$number . $ext;
    1980             else
    1981                 $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
    1982         }
    1983         $filename = str_replace( $ext, '', $filename );
    1984         $filename = sanitize_title_with_dashes( $filename ) . $ext;
    1985     }
    1986 
    1987     // Move the file to the uploads dir
    1988     $new_file = $uploads['path'] . "/$filename";
    1989     if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
    1990         wp_die( printf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ));
    1991 
    1992     // Set correct file permissions
    1993     $stat = stat( dirname( $new_file ));
    1994     $perms = $stat['mode'] & 0000666;
    1995     @ chmod( $new_file, $perms );
    1996 
    1997     // Compute the URL
    1998     $url = $uploads['url'] . "/$filename";
    1999 
    2000     $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) );
    2001 
    2002     return $return;
    2003 }
    2004 
    2005 function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) {
    2006     if ( $height <= $hmax && $width <= $wmax )
    2007         return array( $width, $height);
    2008     elseif ( $width / $height > $wmax / $hmax )
    2009         return array( $wmax, (int) ($height / $width * $wmax ));
    2010     else
    2011         return array( (int) ($width / $height * $hmax ), $hmax );
    2012 }
    2013 
    2014 function wp_import_cleanup( $id ) {
    2015     wp_delete_attachment( $id );
    2016 }
    2017 
    2018 function wp_import_upload_form( $action ) {
    2019     $size = strtolower( ini_get( 'upload_max_filesize' ) );
    2020     $bytes = 0;
    2021     if (strpos($size, 'k') !== false)
    2022         $bytes = $size * 1024;
    2023     if (strpos($size, 'm') !== false)
    2024         $bytes = $size * 1024 * 1024;
    2025     if (strpos($size, 'g') !== false)
    2026         $bytes = $size * 1024 * 1024 * 1024;
    2027 ?>
    2028 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo attribute_escape($action) ?>">
    2029 <p>
    2030 <?php wp_nonce_field('import-upload'); ?>
    2031 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?> )
    2032 <input type="file" id="upload" name="import" size="25" />
    2033 <input type="hidden" name="action" value="save" />
    2034 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
    2035 </p>
    2036 <p class="submit">
    2037 <input type="submit" value="<?php _e( 'Upload file and import' ); ?> &raquo;" />
    2038 </p>
    2039 </form>
    2040 <?php
    2041 }
    2042 
    2043 function wp_import_handle_upload() {
    2044     $overrides = array( 'test_form' => false, 'test_type' => false );
    2045     $file = wp_handle_upload( $_FILES['import'], $overrides );
    2046 
    2047     if ( isset( $file['error'] ) )
    2048         return $file;
    2049 
    2050     $url = $file['url'];
    2051     $type = $file['type'];
    2052     $file = addslashes( $file['file'] );
    2053     $filename = basename( $file );
    2054 
    2055     // Construct the object array
    2056     $object = array( 'post_title' => $filename,
    2057         'post_content' => $url,
    2058         'post_mime_type' => $type,
    2059         'guid' => $url
    2060     );
    2061 
    2062     // Save the data
    2063     $id = wp_insert_attachment( $object, $file );
    2064 
    2065     return array( 'file' => $file, 'id' => $id );
    2066 }
    2067 
    2068 function the_attachment_links( $id = false ) {
    2069     $id = (int) $id;
    2070     $post = & get_post( $id );
    2071 
    2072     if ( $post->post_type != 'attachment' )
    2073         return false;
    2074 
    2075     $icon = get_attachment_icon( $post->ID );
    2076     $attachment_data = wp_get_attachment_metadata( $id );
    2077     $thumb = isset( $attachment_data['thumb'] );
    2078 ?>
    2079 <form id="the-attachment-links">
    2080 <table>
    2081     <col />
    2082     <col class="widefat" />
    2083     <tr>
    2084         <th scope="row"><?php _e( 'URL' ) ?></th>
    2085         <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td>
    2086     </tr>
    2087 <?php if ( $icon ) : ?>
    2088     <tr>
    2089         <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
    2090         <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>"><?php echo $icon ?></a></textarea></td>
    2091     </tr>
    2092     <tr>
    2093         <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
    2094         <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td>
    2095     </tr>
    2096 <?php else : ?>
    2097     <tr>
    2098         <th scope="row"><?php _e( 'Link to file' ) ?></th>
    2099         <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>" class="attachmentlink"><?php echo basename( wp_get_attachment_url() );  ?></a></textarea></td>
    2100     </tr>
    2101     <tr>
    2102         <th scope="row"><?php _e( 'Link to page' ) ?></th>
    2103         <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td>
    2104     </tr>
    2105 <?php endif; ?>
    2106 </table>
    2107 </form>
    2108 <?php
    2109 }
    2110 
    2111 function get_udims( $width, $height) {
    2112     if ( $height <= 96 && $width <= 128 )
    2113         return array( $width, $height);
    2114     elseif ( $width / $height > 4 / 3 )
    2115         return array( 128, (int) ($height / $width * 128 ));
    2116     else
    2117         return array( (int) ($width / $height * 96 ), 96 );
    2118 }
    2119 
    2120 function wp_reset_vars( $vars ) {
    2121     for ( $i=0; $i<count( $vars ); $i += 1 ) {
    2122         $var = $vars[$i];
    2123         global $$var;
    2124 
    2125         if (!isset( $$var ) ) {
    2126             if ( empty( $_POST["$var"] ) ) {
    2127                 if ( empty( $_GET["$var"] ) )
    2128                     $$var = '';
    2129                 else
    2130                     $$var = $_GET["$var"];
    2131             } else {
    2132                 $$var = $_POST["$var"];
    2133             }
    2134         }
    2135     }
    2136 }
    2137 
    2138 
    2139 function wp_remember_old_slug() {
    2140     global $post;
    2141     $name = attribute_escape($post->post_name); // just in case
    2142     if ( strlen($name) )
    2143         echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
    2144 }
    2145 
    2146 
    2147 // If siteurl or home changed, reset cookies and flush rewrite rules.
    2148 function update_home_siteurl( $old_value, $value ) {
    2149     global $wp_rewrite, $user_login, $user_pass_md5;
    2150 
    2151     if ( defined( "WP_INSTALLING" ) )
    2152         return;
    2153 
    2154     // If home changed, write rewrite rules to new location.
    2155     $wp_rewrite->flush_rules();
    2156     // Clear cookies for old paths.
    2157     wp_clearcookie();
    2158     // Set cookies for new paths.
    2159     wp_setcookie( $user_login, $user_pass_md5, true, get_option( 'home' ), get_option( 'siteurl' ));
    2160 }
    2161 
    2162 add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
    2163 add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
    2164 
    2165 function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
    2166     if ( ctype_digit( $src_file ) ) // Handle int as attachment ID
    2167         $src_file = get_attached_file( $src_file );
    2168 
    2169     $src = wp_load_image( $src_file );
    2170 
    2171     if ( !is_resource( $src ))
    2172         return $src;
    2173 
    2174     $dst = imagecreatetruecolor( $dst_w, $dst_h );
    2175 
    2176     if ( $src_abs ) {
    2177         $src_w -= $src_x;
    2178         $src_h -= $src_y;
    2179     }
    2180 
    2181     if (function_exists('imageantialias'))
    2182         imageantialias( $dst, true );
    2183    
    2184     imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
    2185 
    2186     if ( !$dst_file )
    2187         $dst_file = str_replace( basename( $src_file ), 'cropped-'.basename( $src_file ), $src_file );
    2188 
    2189     $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
    2190 
    2191     if ( imagejpeg( $dst, $dst_file ) )
    2192         return $dst_file;
    2193     else
    2194         return false;
    2195 }
    2196 
    2197 function wp_load_image( $file ) {
    2198     if ( ctype_digit( $file ) )
    2199         $file = get_attached_file( $file );
    2200 
    2201     if ( !file_exists( $file ) )
    2202         return sprintf(__("File '%s' doesn't exist?"), $file);
    2203 
    2204     if ( ! function_exists('imagecreatefromstring') )
    2205         return __('The GD image library is not installed.');
    2206 
    2207     $contents = file_get_contents( $file );
    2208 
    2209     $image = imagecreatefromstring( $contents );
    2210 
    2211     if ( !is_resource( $image ) )
    2212         return sprintf(__("File '%s' is not an image."), $file);
    2213 
    2214     return $image;
    2215 }
    2216 
    2217 function wp_generate_attachment_metadata( $attachment_id, $file ) {
    2218     $attachment = get_post( $attachment_id );
    2219 
    2220     $metadata = array();
    2221     if ( preg_match('!^image/!', get_post_mime_type( $attachment )) ) {
    2222         $imagesize = getimagesize($file);
    2223         $metadata['width'] = $imagesize['0'];
    2224         $metadata['height'] = $imagesize['1'];
    2225         list($uwidth, $uheight) = get_udims($metadata['width'], $metadata['height']);
    2226         $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
    2227         $metadata['file'] = $file;
    2228 
    2229         $max = apply_filters( 'wp_thumbnail_creation_size_limit', 3 * 1024 * 1024, $attachment_id, $file );
    2230 
    2231         if ( $max < 0 || $metadata['width'] * $metadata['height'] < $max ) {
    2232             $max_side = apply_filters( 'wp_thumbnail_max_side_length', 128, $attachment_id, $file );
    2233             $thumb = wp_create_thumbnail( $file, $max_side );
    2234 
    2235             if ( @file_exists($thumb) )
    2236                 $metadata['thumb'] = basename($thumb);
    2237         }
    2238     }
    2239     return apply_filters( 'wp_generate_attachment_metadata', $metadata );
    2240 }
    2241 
    2242 function wp_create_thumbnail( $file, $max_side, $effect = '' ) {
    2243 
    2244         // 1 = GIF, 2 = JPEG, 3 = PNG
    2245 
    2246     if ( file_exists( $file ) ) {
    2247         $type = getimagesize( $file );
    2248 
    2249         // if the associated function doesn't exist - then it's not
    2250         // handle. duh. i hope.
    2251 
    2252         if (!function_exists( 'imagegif' ) && $type[2] == 1 ) {
    2253             $error = __( 'Filetype not supported. Thumbnail not created.' );
    2254         }
    2255         elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) {
    2256             $error = __( 'Filetype not supported. Thumbnail not created.' );
    2257         }
    2258         elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) {
    2259             $error = __( 'Filetype not supported. Thumbnail not created.' );
    2260         } else {
    2261 
    2262             // create the initial copy from the original file
    2263             if ( $type[2] == 1 ) {
    2264                 $image = imagecreatefromgif( $file );
    2265             }
    2266             elseif ( $type[2] == 2 ) {
    2267                 $image = imagecreatefromjpeg( $file );
    2268             }
    2269             elseif ( $type[2] == 3 ) {
    2270                 $image = imagecreatefrompng( $file );
    2271             }
    2272 
    2273             if ( function_exists( 'imageantialias' ))
    2274                 imageantialias( $image, TRUE );
    2275 
    2276             $image_attr = getimagesize( $file );
    2277 
    2278             // figure out the longest side
    2279 
    2280             if ( $image_attr[0] > $image_attr[1] ) {
    2281                 $image_width = $image_attr[0];
    2282                 $image_height = $image_attr[1];
    2283                 $image_new_width = $max_side;
    2284 
    2285                 $image_ratio = $image_width / $image_new_width;
    2286                 $image_new_height = $image_height / $image_ratio;
    2287                 //width is > height
    2288             } else {
    2289                 $image_width = $image_attr[0];
    2290                 $image_height = $image_attr[1];
    2291                 $image_new_height = $max_side;
    2292 
    2293                 $image_ratio = $image_height / $image_new_height;
    2294                 $image_new_width = $image_width / $image_ratio;
    2295                 //height > width
    2296             }
    2297 
    2298             $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height);
    2299             @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] );
    2300 
    2301             // If no filters change the filename, we'll do a default transformation.
    2302             if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) )
    2303                 $thumb = preg_replace( '!(\.[^.]+)?$!', '.thumbnail' . '$1', basename( $file ), 1 );
    2304 
    2305             $thumbpath = str_replace( basename( $file ), $thumb, $file );
    2306 
    2307             // move the thumbnail to its final destination
    2308             if ( $type[2] == 1 ) {
    2309                 if (!imagegif( $thumbnail, $thumbpath ) ) {
    2310                     $error = __( "Thumbnail path invalid" );
    2311                 }
    2312             }
    2313             elseif ( $type[2] == 2 ) {
    2314                 if (!imagejpeg( $thumbnail, $thumbpath ) ) {
    2315                     $error = __( "Thumbnail path invalid" );
    2316                 }
    2317             }
    2318             elseif ( $type[2] == 3 ) {
    2319                 if (!imagepng( $thumbnail, $thumbpath ) ) {
    2320                     $error = __( "Thumbnail path invalid" );
    2321                 }
    2322             }
    2323 
    2324         }
    2325     } else {
    2326         $error = __( 'File not found' );
    2327     }
    2328 
    2329     if (!empty ( $error ) ) {
    2330         return $error;
    2331     } else {
    2332         return apply_filters( 'wp_create_thumbnail', $thumbpath );
    2333     }
    2334 }
    2335 
    2336 ?>
  • trunk/wp-admin/admin-header.php

    r6163 r6163  
    11<?php
    2 @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
     2@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
    33if (!isset($_GET["page"])) require_once('admin.php');
    44if ( $editing ) {
     
    1818<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
    1919<title><?php bloginfo('name') ?> &rsaquo; <?php echo wp_specialchars( strip_tags( $title ) ); ?> &#8212; WordPress</title>
    20 <link rel="stylesheet" href="<?php echo get_option('siteurl') ?>/wp-admin/wp-admin.css?version=<?php bloginfo('version'); ?>" type="text/css" />
    21 <?php if ( ('rtl' == $wp_locale->text_direction) ) : ?>
    22 <link rel="stylesheet" href="<?php echo get_option('siteurl') ?>/wp-admin/rtl.css?version=<?php bloginfo('version'); ?>" type="text/css" />
    23 <?php endif; ?>
     20<?php wp_admin_css(); ?>
    2421<script type="text/javascript">
    2522//<![CDATA[
     
    4340?>
    4441</head>
    45 <body>
     42<body class="wp-admin <?php echo apply_filters( 'admin_body_class', '' ); ?>">
    4643<div id="wphead">
    47 <h1><?php bloginfo('name'); ?> <span>(<a href="<?php echo get_option('home') . '/'; ?>"><?php _e('View site &raquo;') ?></a>)</span></h1>
     44<h1><?php bloginfo('name'); ?> <span id="viewsite">(<a href="<?php echo get_option('home') . '/'; ?>"><?php _e('View site &raquo;') ?></a>)</span></h1>
    4845</div>
    4946<div id="user_info"><p><?php printf(__('Howdy, <strong>%s</strong>.'), $user_identity) ?> [<a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="<?php _e('Log out of this account') ?>"><?php _e('Sign Out'); ?></a>, <a href="profile.php"><?php _e('My Profile'); ?></a>] </p></div>
    5047
    5148<?php
    52 require(ABSPATH . '/wp-admin/menu-header.php');
     49require(ABSPATH . 'wp-admin/menu-header.php');
    5350
    5451if ( $parent_file == 'options-general.php' ) {
    55     require(ABSPATH . '/wp-admin/options-head.php');
     52    require(ABSPATH . 'wp-admin/options-head.php');
    5653}
    5754?>
  • trunk/wp-admin/admin.php

    r6163 r6163  
    1010}
    1111
    12 require_once(ABSPATH . 'wp-admin/admin-functions.php');
    13 require_once(ABSPATH . 'wp-admin/admin-db.php');
    14 require_once(ABSPATH . WPINC . '/registration.php');
     12require_once(ABSPATH . 'wp-admin/includes/admin.php');
    1513
    1614auth_redirect();
     
    3836}
    3937
    40 require(ABSPATH . '/wp-admin/menu.php');
     38require(ABSPATH . 'wp-admin/menu.php');
    4139
    4240// Handle plugin admin pages.
     
    4745        do_action('load-' . $page_hook);
    4846        if (! isset($_GET['noheader']))
    49             require_once(ABSPATH . '/wp-admin/admin-header.php');
     47            require_once(ABSPATH . 'wp-admin/admin-header.php');
    5048
    5149        do_action($page_hook);
     
    6159
    6260        if (! isset($_GET['noheader']))
    63             require_once(ABSPATH . '/wp-admin/admin-header.php');
     61            require_once(ABSPATH . 'wp-admin/admin-header.php');
    6462
    6563        include(ABSPATH . PLUGINDIR . "/$plugin_page");
     
    8078    }
    8179
    82     if (! file_exists(ABSPATH . "wp-admin/import/$importer.php"))
    83         wp_die(__('Cannot load importer.'));
    84 
    85     include(ABSPATH . "wp-admin/import/$importer.php");
     80    // Allow plugins to define importers as well
     81    if (! is_callable($wp_importers[$importer][2]))
     82    {
     83        if (! file_exists(ABSPATH . "wp-admin/import/$importer.php"))
     84        {
     85            wp_die(__('Cannot load importer.'));
     86        }
     87        include(ABSPATH . "wp-admin/import/$importer.php");
     88    }
    8689
    8790    $parent_file = 'edit.php';
     
    9295        require_once(ABSPATH . 'wp-admin/admin-header.php');
    9396
    94     require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
     97    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    9598
    9699    define('WP_IMPORTING', true);
  • trunk/wp-admin/bookmarklet.php

    r6163 r6163  
    5252<title><?php bloginfo('name') ?> &rsaquo; Bookmarklet &#8212; WordPress</title>
    5353<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
    54 <link rel="stylesheet" href="wp-admin.css" type="text/css" />
     54<?php wp_admin_css(); ?>
    5555
    5656<style type="text/css">
  • trunk/wp-admin/categories.php

    r6163 r6163  
    3737        wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
    3838
    39     if ( $cat_ID == get_option('default_link_category') )
    40         wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one for links"), $cat_name));
    41 
    4239    wp_delete_category($cat_ID);
    4340
     
    6461
    6562    if ( wp_update_category($_POST) )
    66         wp_redirect('categories.php?message=3'); 
     63        wp_redirect('categories.php?message=3');
    6764    else
    68         wp_redirect('categories.php?message=5'); 
     65        wp_redirect('categories.php?message=5');
    6966
    7067    exit;
     
    10097        <th scope="col"><?php _e('Description') ?></th>
    10198        <th scope="col" width="90" style="text-align: center"><?php _e('Posts') ?></th>
    102         <th scope="col" width="90" style="text-align: center"><?php _e('Links') ?></th>
    10399        <th colspan="2" style="text-align: center"><?php _e('Action') ?></th>
    104100    </tr>
     
    115111<?php if ( current_user_can('manage_categories') ) : ?>
    116112<div class="wrap">
    117 <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts and links in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong> and links that were only assigned to the deleted category are set to <strong>%s</strong>.'), apply_filters('the_category', get_catname(get_option('default_category'))), apply_filters('the_category', get_catname(get_option('default_link_category')))) ?></p>
     113<p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), apply_filters('the_category', get_catname(get_option('default_category')))) ?></p>
     114<p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'admin.php?import=wp-cat2tag') ?></p>
    118115</div>
    119116
    120117<?php include('edit-category-form.php'); ?>
     118
    121119<?php endif; ?>
    122120
  • trunk/wp-admin/comment.php

    r6163 r6163  
    9292<tr>
    9393<th scope="row"><?php _e('URL:'); ?></th>
    94 <td><?php echo $comment->comment_author_url; ?></td>
     94<td><a href='<?php echo $comment->comment_author_url; ?>'><?php echo $comment->comment_author_url; ?></a></td>
    9595</tr>
    9696<?php } ?>
     
    156156        wp_redirect(wp_get_referer());
    157157    } else {
    158         wp_redirect(get_option('siteurl') .'/wp-admin/edit.php?p='. (int) $comment->comment_post_ID.'&c=1#comments');
     158        wp_redirect(get_option('siteurl') .'/wp-admin/edit.php?p=' . (int) $comment->comment_post_ID.'&c=1#comments');
    159159    }
    160160    exit();
     
    186186        wp_redirect(wp_get_referer());
    187187    } else {
    188         wp_redirect(get_option('siteurl') .'/wp-admin/edit.php?p='. (int) $comment->comment_post_ID.'&c=1#comments');
     188        wp_redirect(get_option('siteurl') .'/wp-admin/edit.php?p=' . (int) $comment->comment_post_ID.'&c=1#comments');
    189189    }
    190190    exit();
  • trunk/wp-admin/custom-header.php

    r6163 r6163  
    161161<p><?php _e('This is your header image. You can change the text color or upload and crop a new image.'); ?></p>
    162162
    163 <div id="headimg" style="background: url(<?php clean_url(header_image()) ?>) no-repeat;">
     163<div id="headimg" style="background-image: url(<?php clean_url(header_image()) ?>);">
    164164<h1><a onclick="return false;" href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?>" id="name"><?php bloginfo('name'); ?></a></h1>
    165165<div id="desc"><?php bloginfo('description');?></div>
     
    170170<input type="button" value="<?php _e('Select a Text Color'); ?>" onclick="colorSelect($('textcolor'), 'pickcolor')" id="pickcolor" /><input type="button" value="<?php _e('Use Original Color'); ?>" onclick="colorDefault()" id="defaultcolor" />
    171171<?php wp_nonce_field('custom-header') ?>
    172 <input type="hidden" name="textcolor" id="textcolor" value="#<?php attribute_escape(header_textcolor()) ?>" /><input name="submit" type="submit" value="<?php _e('Save Changes'); ?> &raquo;" /></form>
     172<input type="hidden" name="textcolor" id="textcolor" value="#<?php attribute_escape(header_textcolor()) ?>" /><input name="submit" type="submit" value="<?php _e('Save Changes &raquo;'); ?>" /></form>
    173173<?php } ?>
    174174
     
    184184<?php wp_nonce_field('custom-header') ?>
    185185<p class="submit">
    186 <input type="submit" value="<?php _e('Upload'); ?> &raquo;" />
     186<input type="submit" value="<?php _e('Upload &raquo;'); ?>" />
    187187</p>
    188188</form>
  • trunk/wp-admin/edit-category-form.php

    r6163 r6163  
    2222<?php echo $form ?>
    2323<input type="hidden" name="action" value="<?php echo $action ?>" />
    24 <input type="hidden" name="cat_ID" value="<?php echo $category->cat_ID ?>" />
     24<input type="hidden" name="cat_ID" value="<?php echo $category->term_id ?>" />
    2525<?php wp_nonce_field($nonce_action); ?>
    2626    <table class="editform" width="100%" cellspacing="2" cellpadding="5">
    2727        <tr>
    2828            <th width="33%" scope="row" valign="top"><label for="cat_name"><?php _e('Category name:') ?></label></th>
    29             <td width="67%"><input name="cat_name" id="cat_name" type="text" value="<?php echo attribute_escape($category->cat_name); ?>" size="40" /></td>
     29            <td width="67%"><input name="cat_name" id="cat_name" type="text" value="<?php echo attribute_escape($category->name); ?>" size="40" /></td>
    3030        </tr>
    3131        <tr>
    3232            <th scope="row" valign="top"><label for="category_nicename"><?php _e('Category slug:') ?></label></th>
    33             <td><input name="category_nicename" id="category_nicename" type="text" value="<?php echo attribute_escape($category->category_nicename); ?>" size="40" /></td>
     33            <td><input name="category_nicename" id="category_nicename" type="text" value="<?php echo attribute_escape($category->slug); ?>" size="40" /></td>
    3434        </tr>
    3535        <tr>
    3636            <th scope="row" valign="top"><label for="category_parent"><?php _e('Category parent:') ?></label></th>
    37             <td>       
    38                 <?php wp_dropdown_categories('hide_empty=0&name=category_parent&orderby=name&selected=' . $category->category_parent . '&hierarchical=1&show_option_none=' . __('None')); ?>
     37            <td>
     38                <?php wp_dropdown_categories('hide_empty=0&name=category_parent&orderby=name&selected=' . $category->parent . '&hierarchical=1&show_option_none=' . __('None')); ?>
    3939            </td>
    4040        </tr>
    4141        <tr>
    4242            <th scope="row" valign="top"><label for="category_description"><?php _e('Description: (optional)') ?></label></th>
    43             <td><textarea name="category_description" id="category_description" rows="5" cols="50" style="width: 97%;"><?php echo wp_specialchars($category->category_description); ?></textarea></td>
     43            <td><textarea name="category_description" id="category_description" rows="5" cols="50" style="width: 97%;"><?php echo wp_specialchars($category->description); ?></textarea></td>
    4444        </tr>
    4545    </table>
  • trunk/wp-admin/edit-comments.php

    r6163 r6163  
    4040<div class="wrap">
    4141<h2><?php _e('Comments'); ?></h2>
    42 <form name="searchform" action="" method="get" id="editcomments"> 
    43   <fieldset> 
    44   <legend><?php _e('Show Comments That Contain...') ?></legend> 
    45   <input type="text" name="s" value="<?php if (isset($_GET['s'])) echo attribute_escape($_GET['s']); ?>" size="17" /> 
    46   <input type="submit" name="submit" value="<?php _e('Search') ?>"  /> 
     42<form name="searchform" action="" method="get" id="editcomments">
     43  <fieldset>
     44  <legend><?php _e('Show Comments That Contain...') ?></legend>
     45  <input type="text" name="s" value="<?php if (isset($_GET['s'])) echo attribute_escape($_GET['s']); ?>" size="17" />
     46  <input type="submit" name="submit" value="<?php _e('Search') ?>"  />
    4747  <input type="hidden" name="mode" value="<?php echo $mode; ?>" />
    4848  <?php _e('(Searches within comment text, e-mail, URL, and IP address.)') ?>
    49   </fieldset> 
     49  </fieldset>
    5050</form>
    5151<p><a href="?mode=view"><?php _e('View Mode') ?></a> | <a href="?mode=edit"><?php _e('Mass Edit Mode') ?></a></p>
     
    8989
    9090$page_links = paginate_links( array(
    91     'base' => add_query_arg( 'apage', '%#%' ), 
     91    'base' => add_query_arg( 'apage', '%#%' ),
    9292    'format' => '',
    9393    'total' => ceil($total / 20),
     
    152152</thead>';
    153153        foreach ($comments as $comment) {
    154         $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
     154        $post = get_post($comment->comment_post_ID);
     155        $authordata = get_userdata($post->post_author);
    155156        $comment_status = wp_get_comment_status($comment->comment_ID);
    156157        $class = ('alternate' == $class) ? '' : 'alternate';
     
    158159?>
    159160  <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
    160     <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>
     161    <td style="text-align: center"><?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>
    161162    <td><?php comment_author_link() ?></td>
    162163    <td><?php comment_author_email_link() ?></td>
    163     <td><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></td>
     164    <td><a href="edit-comments.php?s=<?php comment_author_IP() ?>&amp;mode=edit"><?php comment_author_IP() ?></a></td>
    164165    <td><?php comment_excerpt(); ?></td>
    165166    <td>
    166         <?php if ('unapproved' == $comment_status) { ?>
    167             (Unapproved)
    168         <?php } else { ?>
     167        <?php if ('unapproved' == $comment_status) {
     168            _e('Unapproved');
     169        } else { ?>
    169170            <a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php comment_ID() ?>" class="edit"><?php _e('View') ?></a>
    170171        <?php } ?>
     
    176177        } ?></td>
    177178  </tr>
    178         <?php 
     179        <?php
    179180        } // end foreach
    180181    ?></table>
  • trunk/wp-admin/edit-form-advanced.php

    r6163 r6163  
    11<?php
    22if ( isset($_GET['message']) )
    3       $_GET['message'] = (int) $_GET['message'];
     3    $_GET['message'] = (int) $_GET['message'];
    44$messages[1] = __('Post updated');
    55$messages[2] = __('Custom field updated');
     
    5858
    5959<?php echo $form_extra ?>
    60 <?php if (isset($_GET['message']) && 2 > $_GET['message']) : ?>
     60<?php if ((isset($post->post_title) && '' == $post->post_title) || (isset($_GET['message']) && 2 > $_GET['message'])) : ?>
    6161<script type="text/javascript">
    6262function focusit() {
     
    8585<label for="comment_status" class="selectit">
    8686<input name="comment_status" type="checkbox" id="comment_status" value="open" <?php checked($post->comment_status, 'open'); ?> />
    87 <?php _e('Allow Comments') ?></label> 
     87<?php _e('Allow Comments') ?></label>
    8888<label for="ping_status" class="selectit"><input name="ping_status" type="checkbox" id="ping_status" value="open" <?php checked($post->ping_status, 'open'); ?> /> <?php _e('Allow Pings') ?></label>
    8989</div>
     
    9191
    9292<fieldset id="passworddiv" class="dbx-box">
    93 <h3 class="dbx-handle"><?php _e('Post Password') ?></h3> 
     93<h3 class="dbx-handle"><?php _e('Post Password') ?></h3>
    9494<div class="dbx-content"><input name="post_password" type="text" size="13" id="post_password" value="<?php echo attribute_escape( $post->post_password ); ?>" /></div>
    9595</fieldset>
    9696
    9797<fieldset id="slugdiv" class="dbx-box">
    98 <h3 class="dbx-handle"><?php _e('Post Slug') ?></h3> 
     98<h3 class="dbx-handle"><?php _e('Post Slug') ?></h3>
    9999<div class="dbx-content"><input name="post_name" type="text" size="13" id="post_name" value="<?php echo attribute_escape( $post->post_name ); ?>" /></div>
    100100</fieldset>
    101101
    102102<fieldset id="poststatusdiv" class="dbx-box">
    103 <h3 class="dbx-handle"><?php _e('Post Status') ?></h3>
    104 <div class="dbx-content"><?php if ( current_user_can('publish_posts') ) : ?>
    105 <label for="post_status_publish" class="selectit"><input id="post_status_publish" name="post_status" type="radio" value="publish" <?php checked($post->post_status, 'publish'); checked($post->post_status, 'future'); ?> /> <?php _e('Published') ?></label>
    106 <?php endif; ?>
     103<h3 class="dbx-handle"><?php _e('Post Status') ?></h3>
     104<div class="dbx-content">
     105<?php if ( current_user_can('publish_posts') ) : ?>
     106    <label for="post_status_publish" class="selectit"><input id="post_status_publish" name="post_status" type="radio" value="publish" <?php checked($post->post_status, 'publish'); checked($post->post_status, 'future'); ?> /> <?php _e('Published') ?></label>
     107<?php endif; ?>
     108    <label for="post_status_pending" class="selectit"><input id="post_status_pending" name="post_status" type="radio" value="pending" <?php checked($post->post_status, 'pending'); ?> /> <?php _e('Pending Review') ?></label>
    107109      <label for="post_status_draft" class="selectit"><input id="post_status_draft" name="post_status" type="radio" value="draft" <?php checked($post->post_status, 'draft'); ?> /> <?php _e('Draft') ?></label>
    108110      <label for="post_status_private" class="selectit"><input id="post_status_private" name="post_status" type="radio" value="private" <?php checked($post->post_status, 'private'); ?> /> <?php _e('Private') ?></label></div>
     
    116118<?php endif; ?>
    117119
    118 <?php
    119 $authors = get_editable_authors( $current_user->id ); // TODO: ROLE SYSTEM
     120<?php
     121$authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
     122if ( $post->post_author && !in_array($post->post_author, $authors) )
     123    $authors[] = $post->post_author;
    120124if ( $authors && count( $authors ) > 1 ) :
    121125?>
     
    123127<h3 class="dbx-handle"><?php _e('Post Author'); ?></h3>
    124128<div class="dbx-content">
    125 <select name="post_author_override" id="post_author_override">
    126 <?php
    127 foreach ($authors as $o) :
    128 $o = get_userdata( $o->ID );
    129 if ( $post->post_author == $o->ID || ( empty($post_ID) && $user_ID == $o->ID ) ) $selected = 'selected="selected"';
    130 else $selected = '';
    131 echo "<option value='" . (int) $o->ID . "' $selected>" . wp_specialchars( $o->display_name ) . "</option>";
    132 endforeach;
    133 ?>
    134 </select>
     129<?php wp_dropdown_users( array('include' => $authors, 'name' => 'post_author_override', 'selected' => empty($post_ID) ? $user_ID : $post->post_author) ); ?>
    135130</div>
    136131</fieldset>
     
    163158<?php echo $form_prevstatus ?>
    164159
     160<fieldset id="tagdiv">
     161    <legend><?php _e('Tags (separate multiple tags with commas: cats, pet food, dogs)'); ?></legend>
     162    <div><input type="text" name="tags_input" class="tags-input" id="tags-input" size="30" tabindex="3" value="<?php echo get_tags_to_edit( $post_ID ); ?>" /></div>
     163</fieldset>
    165164
    166165<p class="submit">
    167166<span id="autosave"></span>
    168167<?php echo $saveasdraft; ?>
    169 <input type="submit" name="submit" value="<?php _e('Save') ?>" style="font-weight: bold;" tabindex="4" />
    170 <?php 
    171 if ('publish' != $post->post_status || 0 == $post_ID) {
     168<input type="submit" name="submit" value="<?php _e('Save'); ?>" style="font-weight: bold;" tabindex="4" />
     169<?php
     170if ( !in_array( $post->post_status, array('publish', 'future') ) || 0 == $post_ID ) {
    172171?>
    173172<?php if ( current_user_can('publish_posts') ) : ?>
    174     <input name="publish" type="submit" id="publish" tabindex="5" accesskey="p" value="<?php _e('Publish'); ?>" />
    175 <?php endif; ?>
    176 <?php
    177 }
    178 ?>
    179 <input name="referredby" type="hidden" id="referredby" value="<?php
     173    <input name="publish" type="submit" id="publish" tabindex="5" accesskey="p" value="<?php _e('Publish') ?>" />
     174<?php else : ?>
     175    <input name="publish" type="submit" id="publish" tabindex="5" accesskey="p" value="<?php _e('Submit for Review') ?>" />
     176<?php endif; ?>
     177<?php
     178}
     179?>
     180<input name="referredby" type="hidden" id="referredby" value="<?php
    180181if ( !empty($_REQUEST['popupurl']) )
    181182    echo clean_url(stripslashes($_REQUEST['popupurl']));
     
    194195    $uploading_iframe_src = apply_filters('uploading_iframe_src', $uploading_iframe_src);
    195196    if ( false != $uploading_iframe_src )
    196         echo '<iframe id="uploading" frameborder="0" src="' . $uploading_iframe_src . '">' . __('This feature requires iframe support.') . '</iframe>';
     197        echo '<iframe id="uploading" name="uploading" frameborder="0" src="' . $uploading_iframe_src . '">' . __('This feature requires iframe support.') . '</iframe>';
    197198}
    198199?>
  • trunk/wp-admin/edit-form-comment.php

    r6163 r6163  
    77
    88<form name="post" action="comment.php" method="post" id="post">
     9<h2><?php echo $toprow_title; ?></h2>
    910<?php wp_nonce_field('update-comment_' . $comment->comment_ID) ?>
    1011<div class="wrap">
     
    3334        <legend><label for="newcomment_author_url"><?php _e('URL:') ?></label></legend>
    3435        <div>
    35           <input type="text" id="newcomment_author_url" name="newcomment_author_url" size="35" value="<?php echo attribute_escape( $comment->comment_author_url ); ?>" tabindex="3" />
     36          <input type="text" id="newcomment_author_url" name="newcomment_author_url" size="35" value="<?php echo attribute_escape( $comment->comment_author_url ); ?>" tabindex="2" />
    3637    </div>
    3738</fieldset>
     
    5455    <tr>
    5556        <th scope="row" valign="top"><?php _e('Comment Status') ?>:</th>
    56         <td><label for="comment_status_approved" class="selectit"><input id="comment_status_approved" name="comment_status" type="radio" value="1" <?php checked($comment->comment_approved, '1'); ?> /> <?php _e('Approved') ?></label><br />
    57         <label for="comment_status_moderated" class="selectit"><input id="comment_status_moderated" name="comment_status" type="radio" value="0" <?php checked($comment->comment_approved, '0'); ?> /> <?php _e('Moderated') ?></label><br />
    58         <label for="comment_status_spam" class="selectit"><input id="comment_status_spam" name="comment_status" type="radio" value="spam" <?php checked($comment->comment_approved, 'spam'); ?> /> <?php _e('Spam') ?></label></td>
     57        <td><label for="comment_status_approved" class="selectit"><input id="comment_status_approved" name="comment_status" type="radio" value="1" <?php checked($comment->comment_approved, '1'); ?> tabindex="4" /> <?php _e('Approved') ?></label> &nbsp;
     58        <label for="comment_status_moderated" class="selectit"><input id="comment_status_moderated" name="comment_status" type="radio" value="0" <?php checked($comment->comment_approved, '0'); ?> tabindex="4" /> <?php _e('Moderated') ?></label> &nbsp;
     59        <label for="comment_status_spam" class="selectit"><input id="comment_status_spam" name="comment_status" type="radio" value="spam" <?php checked($comment->comment_approved, 'spam'); ?> tabindex="4" /> <?php _e('Spam') ?></label></td>
    5960    </tr>
    6061
     
    6263    <tr>
    6364        <th scope="row" valign="top"><?php _e('Edit time'); ?>:</th>
    64         <td><?php touch_time(('editcomment' == $action), 0); ?> </td>
     65        <td><?php touch_time(('editcomment' == $action), 0, 5); ?> </td>
    6566    </tr>
    6667<?php endif; ?>
    6768
    6869    <tr>
    69         <th scope="row" valign="top"><?php _e('Delete'); $delete_nonce = wp_create_nonce( 'delete-comment_' . $comment->comment_ID ); ?>:</th>
    70         <td><input name="deletecomment" class="button delete" type="submit" id="deletecomment" tabindex="10" value="<?php _e('Delete this comment') ?>" <?php echo "onclick=\"if ( confirm('" . js_escape(__("You are about to delete this comment. \n  'Cancel' to stop, 'OK' to delete.")) . "') ) { document.forms.post._wpnonce.value = '$delete_nonce'; return true; } return false;\""; ?> />
     70        <th scope="row" valign="top">&nbsp;</th>
     71        <td><input name="deletecomment" class="button delete" type="submit" id="deletecomment" tabindex="10" value="<?php _e('Delete this comment') ?>" <?php echo "onclick=\"if ( confirm('" . js_escape(__("You are about to delete this comment. \n  'Cancel' to stop, 'OK' to delete.")) . "') ) { document.forms.post._wpnonce.value = '" . wp_create_nonce( 'delete-comment_' . $comment->comment_ID ) . "'; return true; } return false;\""; ?> />
    7172        <input type="hidden" name="c" value="<?php echo $comment->comment_ID ?>" />
    7273        <input type="hidden" name="p" value="<?php echo $comment->comment_post_ID ?>" />
  • trunk/wp-admin/edit-form.php

    r6163 r6163  
    2121<div id="poststuff">
    2222    <fieldset id="titlediv">
    23       <legend><a href="http://wordpress.org/docs/reference/post/#title" title="<?php _e('Help on titles') ?>"><?php _e('Title') ?></a></legend> 
     23      <legend><a href="http://wordpress.org/docs/reference/post/#title" title="<?php _e('Help on titles') ?>"><?php _e('Title') ?></a></legend>
    2424      <div><input type="text" name="post_title" size="30" tabindex="1" value="<?php echo attribute_escape( $post->post_title ); ?>" id="title" /></div>
    2525    </fieldset>
    2626
    2727    <fieldset id="categorydiv">
    28       <legend><a href="http://wordpress.org/docs/reference/post/#category" title="<?php _e('Help on categories') ?>"><?php _e('Categories') ?></a></legend> 
     28      <legend><a href="http://wordpress.org/docs/reference/post/#category" title="<?php _e('Help on categories') ?>"><?php _e('Categories') ?></a></legend>
    2929      <div><?php dropdown_categories($post->post_category); ?></div>
    3030    </fieldset>
     
    3333<fieldset id="postdiv">
    3434    <legend><a href="http://wordpress.org/docs/reference/post/#post" title="<?php _e('Help with post field') ?>"><?php _e('Post') ?></a></legend>
    35 <?php the_quicktags(); ?>
    3635<?php
    3736 $rows = get_option('default_post_edit_rows');
  • trunk/wp-admin/edit-link-form.php

    r6163 r6163  
    4444<div class="dbx-content">
    4545<p id="jaxcat"></p>
    46 <ul id="categorychecklist"><?php dropdown_link_categories(get_option('default_link_category')); ?></ul>
     46<ul id="linkcategorychecklist"><?php dropdown_link_categories(get_option('default_link_category')); ?></ul>
    4747</div>
    4848</fieldset>
     
    8181<tr>
    8282<th scope="row" valign="top"><label for="link_name"><?php _e('Name:') ?></label></th>
    83 <td><input type="text" name="link_name" value="<?php echo $link->link_name; ?>" style="width: 95%" /></td>
     83<td><input type="text" name="link_name" id="link_name" value="<?php echo $link->link_name; ?>" style="width: 95%" /></td>
    8484</tr>
    8585<tr>
    8686<th width="20%" scope="row" valign="top"><label for="link_url"><?php _e('Address:') ?></label></th>
    87 <td width="80%"><input type="text" name="link_url" value="<?php echo $link->link_url; if ( empty( $link->link_url ) ) echo 'http://'; ?>" style="width: 95%" /></td>
     87<td width="80%"><input type="text" name="link_url" id="link_url" value="<?php echo $link->link_url; if ( empty( $link->link_url ) ) echo 'http://'; ?>" style="width: 95%" /></td>
    8888</tr>
    8989<tr>
    9090<th scope="row" valign="top"><label for="link_description"><?php _e('Description:') ?></label></th>
    91 <td><input type="text" name="link_description" value="<?php echo $link->link_description; ?>" style="width: 95%" /></td>
     91<td><input type="text" name="link_description" id="link_description" value="<?php echo $link->link_description; ?>" style="width: 95%" /></td>
    9292</tr>
    9393</table>
     
    242242    </tr>
    243243</table>
     244</div>
    244245</fieldset>
    245246</div>
  • trunk/wp-admin/edit-page-form.php

    r6163 r6163  
    171171    $uploading_iframe_src = apply_filters('uploading_iframe_src', $uploading_iframe_src);
    172172    if ( false != $uploading_iframe_src )
    173         echo '<iframe id="uploading" frameborder="0" src="' . $uploading_iframe_src . '">' . __('This feature requires iframe support.') . '</iframe>';
     173        echo '<iframe id="uploading" name="uploading" frameborder="0" src="' . $uploading_iframe_src . '">' . __('This feature requires iframe support.') . '</iframe>';
    174174}
    175175?>
  • trunk/wp-admin/edit-pages.php

    r6163 r6163  
    55wp_enqueue_script( 'listman' );
    66require_once('admin-header.php');
     7
     8$post_stati  = array(   //  array( adj, noun )
     9            'publish' => array(__('Published'), __('Published pages')),
     10            'draft'   => array(__('Draft'), __('Draft pages')),
     11            'private' => array(__('Private'), __('Private pages'))
     12        );
     13
     14
     15$post_status_label = __('Pages');
     16$post_status_q = '';
     17if ( isset($_GET['post_status']) && in_array( $_GET['post_status'], array_keys($post_stati) ) ) {
     18    $post_status_label = $post_stati[$_GET['post_status']][1];
     19    $post_status_q = '&post_status=' . $_GET['post_status'];
     20}
     21
    722?>
    823
    924<div class="wrap">
    10 <h2><?php _e('Page Management'); ?></h2>
     25
     26<h2><?php
     27// Use $_GET instead of is_ since they can override each other
     28$h2_search = isset($_GET['s']) && $_GET['s'] ? ' ' . sprintf(__('matching &#8220;%s&#8221;'), wp_specialchars( stripslashes( $_GET['s'] ) ) ) : '';
     29$h2_author = '';
     30if ( isset($_GET['author']) && $_GET['author'] ) {
     31    $author_user = get_userdata( (int) $_GET['author'] );
     32    $h2_author = ' ' . sprintf(__('by %s'), wp_specialchars( $author_user->display_name ));
     33}
     34printf( _c( '%1$s%2$s%3$s|You can reorder these: 1: Pages, 2: by {s}, 3: matching {s}' ), $post_status_label, $h2_author, $h2_search );
     35?></h2>
     36
    1137<p><?php _e('Pages are like posts except they live outside of the normal blog chronology and can be hierarchical. You can use pages to organize and manage any amount of content.'); ?> <a href="page-new.php"><?php _e('Create a new page &raquo;'); ?></a></p>
    1238
    13 <form name="searchform" action="" method="get">
    14     <fieldset>
    15     <legend><?php _e('Search Pages&hellip;') ?></legend>
    16     <input type="text" name="s" value="<?php if (isset($_GET['s'])) echo attribute_escape($_GET['s']); ?>" size="17" />
    17     <input type="submit" name="submit" value="<?php _e('Search') ?>"  />
     39<form name="searchform" id="searchform" action="" method="get">
     40    <fieldset><legend><?php _e('Search Terms&hellip;') ?></legend>
     41        <input type="text" name="s" id="s" value="<?php echo attribute_escape( stripslashes( $_GET['s'] ) ); ?>" size="17" />
    1842    </fieldset>
     43
     44
     45    <fieldset><legend><?php _e('Page Type&hellip;'); ?></legend>
     46        <select name='post_status'>
     47            <option<?php selected( @$_GET['post_status'], 0 ); ?> value='0'><?php _e('Any'); ?></option>
     48<?php   foreach ( $post_stati as $status => $label ) : ?>
     49            <option<?php selected( @$_GET['post_status'], $status ); ?> value='<?php echo $status; ?>'><?php echo $label[0]; ?></option>
     50<?php   endforeach; ?>
     51        </select>
     52    </fieldset>
     53
     54<?php $editable_ids = get_editable_user_ids( $user_ID ); if ( $editable_ids && count( $editable_ids ) > 1 ) : ?>
     55
     56    <fieldset><legend><?php _e('Author&hellip;'); ?></legend>
     57        <?php wp_dropdown_users( array('include' => $editable_ids, 'show_option_all' => __('Any'), 'name' => 'author', 'selected' => isset($_GET['author']) ? $_GET['author'] : 0) ); ?>
     58    </fieldset>
     59
     60<?php endif; ?>
     61
     62    <input type="submit" id="post-query-submit" value="<?php _e('Filter &#187;'); ?>" class="button" />
    1963</form>
    2064
     65<br style="clear:both;" />
     66
    2167<?php
    22 wp('post_type=page&orderby=menu_order&what_to_show=posts&posts_per_page=-1&posts_per_archive_page=-1&order=asc');
     68wp("post_type=page&orderby=menu_order&what_to_show=posts$post_status_q&posts_per_page=-1&posts_per_archive_page=-1&order=asc");
    2369
    24 if ( $_GET['s'] )
    25     $all = false;
    26 else
    27     $all = true;
     70$all = !( $h2_search || $post_status_q );
    2871
    2972if ($posts) {
    3073?>
    31 <table class="widefat"> 
     74<table class="widefat">
    3275  <thead>
    3376  <tr>
     
    4083  </thead>
    4184  <tbody id="the-list">
    42 <?php
    43 page_rows(0, 0, $posts, $all);
    44 ?>
     85<?php page_rows(0, 0, $posts, $all); ?>
    4586  </tbody>
    4687</table>
     
    5192} else {
    5293?>
    53 <p><?php _e('No pages yet.') ?></p>
     94<p><?php _e('No pages found.') ?></p>
    5495<?php
    5596} // end if ($posts)
  • trunk/wp-admin/edit.php

    r6163 r6163  
    77require_once('admin-header.php');
    88
    9 $_GET['m'] = (int) $_GET['m'];
    10 
    11 $drafts = get_users_drafts( $user_ID );
    12 $other_drafts = get_others_drafts( $user_ID);
    13 
    14 if ($drafts || $other_drafts) {
    15 ?>
     9$_GET['m']   = (int) $_GET['m'];
     10$_GET['cat'] = (int) $_GET['cat'];
     11$post_stati  = array(   //  array( adj, noun )
     12            'publish' => array(__('Published'), __('Published posts')),
     13            'future' => array(__('Scheduled'), __('Scheduled posts')),
     14            'pending' => array(__('Pending Review'), __('Pending posts')),
     15            'draft' => array(__('Draft'), _c('Drafts|manage posts header')),
     16            'private' => array(__('Private'), __('Private posts'))
     17        );
     18
     19$avail_post_stati = $wpdb->get_col("SELECT DISTINCT post_status FROM $wpdb->posts WHERE post_type = 'post'");
     20
     21$post_status_q = '';
     22$post_status_label = __('Posts');
     23if ( isset($_GET['post_status']) && in_array( $_GET['post_status'], array_keys($post_stati) ) ) {
     24    $post_status_label = $post_stati[$_GET['post_status']][1];
     25    $post_status_q = '&post_status=' . $_GET['post_status'];
     26}
     27?>
     28
    1629<div class="wrap">
    17 <?php if ($drafts) { ?>
    18     <p><strong><?php _e('Your Drafts:') ?></strong>
    19     <?php
    20     $i = 0;
    21     foreach ($drafts as $draft) {
    22         if (0 != $i)
    23             echo ', ';
    24         $draft->post_title = apply_filters('the_title', stripslashes($draft->post_title));
    25         if ($draft->post_title == '')
    26             $draft->post_title = sprintf(__('Post #%s'), $draft->ID);
    27         echo "<a href='post.php?action=edit&amp;post=$draft->ID' title='" . __('Edit this draft') . "'>$draft->post_title</a>";
    28         ++$i;
     30
     31<?php
     32
     33if ( 'pending' === $_GET['post_status'] ) {
     34    $order = 'ASC';
     35    $orderby = 'modified';
     36} elseif ( 'draft' === $_GET['post_status'] ) {
     37    $order = 'DESC';
     38    $orderby = 'modified';
     39} else {
     40    $order = 'DESC';
     41    $orderby = 'date';
     42}
     43
     44wp("what_to_show=posts$post_status_q&posts_per_page=15&order=$order&orderby=$orderby");
     45
     46// define the columns to display, the syntax is 'internal name' => 'display name'
     47$posts_columns = array();
     48$posts_columns['id'] = '<div style="text-align: center">' . __('ID') . '</div>';
     49if ( 'draft' === $_GET['post_status'] )
     50    $posts_columns['modified'] = __('Modified');
     51elseif ( 'pending' === $_GET['post_status'] )
     52    $posts_columns['modified'] = __('Submitted');
     53else
     54    $posts_columns['date'] = __('When');
     55$posts_columns['title'] = __('Title');
     56$posts_columns['categories'] = __('Categories');
     57if ( !in_array($_GET['post_status'], array('pending', 'draft', 'future')) )
     58    $posts_columns['comments'] = '<div style="text-align: center">' . __('Comments') . '</div>';
     59$posts_columns['author'] = __('Author');
     60
     61$posts_columns = apply_filters('manage_posts_columns', $posts_columns);
     62
     63// you can not edit these at the moment
     64$posts_columns['control_view']   = '';
     65$posts_columns['control_edit']   = '';
     66$posts_columns['control_delete'] = '';
     67
     68?>
     69
     70<h2><?php
     71if ( is_single() ) {
     72    printf(__('Comments on %s'), apply_filters( "the_title", $post->post_title));
     73} else {
     74    if ( $post_listing_pageable && !is_archive() && !is_search() )
     75        $h2_noun = is_paged() ? sprintf(__( 'Previous %s' ), $post_status_label) : sprintf(__('Latest %s'), $post_status_label);
     76    else
     77        $h2_noun = $post_status_label;
     78    // Use $_GET instead of is_ since they can override each other
     79    $h2_author = '';
     80    $_GET['author'] = (int) $_GET['author'];
     81    if ( $_GET['author'] != 0 ) {
     82        if ( $_GET['author'] == '-' . $user_ID ) { // author exclusion
     83            $h2_author = ' ' . __('by other authors');
     84        } else {
     85            $author_user = get_userdata( get_query_var( 'author' ) );
     86            $h2_author = ' ' . sprintf(__('by %s'), wp_specialchars( $author_user->display_name ));
    2987        }
    30     ?>
    31 .</p>
    32 <?php } ?>
    33 
    34 <?php if ($other_drafts) { ?>
    35     <p><strong><?php _e('Other&#8217;s Drafts:') ?></strong>
    36     <?php
    37     $i = 0;
    38     foreach ($other_drafts as $draft) {
    39         if (0 != $i)
    40             echo ', ';
    41         $draft->post_title = apply_filters('the_title', stripslashes($draft->post_title));
    42         if ($draft->post_title == '')
    43             $draft->post_title = sprintf(__('Post #%s'), $draft->ID);
    44         echo "<a href='post.php?action=edit&amp;post=$draft->ID' title='" . __('Edit this draft') . "'>$draft->post_title</a>";
    45         ++$i;
    46         }
    47     ?>
    48     .</p>
    49 
    50 <?php } ?>
    51 
    52 </div>
    53 <?php } ?>
    54 
    55 <div class="wrap">
    56 <h2>
    57 <?php
    58 
    59 wp('what_to_show=posts&posts_per_page=15&posts_per_archive_page=-1');
    60 
    61 if ( is_month() ) {
    62     single_month_title(' ');
    63 } elseif ( is_search() ) {
    64     printf(__('Search for &#8220;%s&#8221;'), wp_specialchars($_GET['s']) );
    65 } else {
    66     if ( is_single() )
    67         printf(__('Comments on %s'), apply_filters( "the_title", $post->post_title));
    68     elseif ( ! is_paged() || get_query_var('paged') == 1 )
    69         _e('Last 15 Posts');
    70     else
    71         _e('Previous Posts');
    72 }
    73 ?>
    74 </h2>
     88    }
     89    $h2_search = isset($_GET['s'])   && $_GET['s']   ? ' ' . sprintf(__('matching &#8220;%s&#8221;'), wp_specialchars( get_search_query() ) ) : '';
     90    $h2_cat    = isset($_GET['cat']) && $_GET['cat'] ? ' ' . sprintf( __('in &#8220;%s&#8221;'), single_cat_title('', false) ) : '';
     91    $h2_month  = isset($_GET['m'])   && $_GET['m']   ? ' ' . sprintf( __('during %s'), single_month_title(' ', false) ) : '';
     92    printf( _c( '%1$s%2$s%3$s%4$s%5$s|You can reorder these: 1: Posts, 2: by {s}, 3: matching {s}, 4: in {s}, 5: during {s}' ), $h2_noun, $h2_author, $h2_search, $h2_cat, $h2_month );
     93}
     94?></h2>
    7595
    7696<form name="searchform" id="searchform" action="" method="get">
    77   <fieldset>
    78   <legend><?php _e('Search Posts&hellip;') ?></legend>
    79   <input type="text" name="s" value="<?php if (isset($s)) echo attribute_escape($s); ?>" size="17" />
    80   <input type="submit" name="submit" value="<?php _e('Search') ?>" class="button" />
    81   </fieldset>
    82 </form>
    83 
    84 <?php $arc_result = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC");
    85 
    86 if ( count($arc_result) ) { ?>
    87 
    88 <form name="viewarc" id="viewarc" action="" method="get">
    89     <fieldset>
    90     <legend><?php _e('Browse Month&hellip;') ?></legend>
    91     <select name='m'>
    92     <?php
     97    <fieldset><legend><?php _e('Search terms&hellip;'); ?></legend>
     98        <input type="text" name="s" id="s" value="<?php the_search_query(); ?>" size="17" />
     99    </fieldset>
     100
     101    <fieldset><legend><?php _e('Status&hellip;'); ?></legend>
     102        <select name='post_status'>
     103            <option<?php selected( @$_GET['post_status'], 0 ); ?> value='0'><?php _e('Any'); ?></option>
     104<?php   foreach ( $post_stati as $status => $label ) : if ( !in_array($status, $avail_post_stati) ) continue; ?>
     105            <option<?php selected( @$_GET['post_status'], $status ); ?> value='<?php echo $status; ?>'><?php echo $label[0]; ?></option>
     106<?php   endforeach; ?>
     107        </select>
     108    </fieldset>
     109
     110<?php
     111$editable_ids = get_editable_user_ids( $user_ID );
     112if ( $editable_ids && count( $editable_ids ) > 1 ) :
     113?>
     114    <fieldset><legend><?php _e('Author&hellip;'); ?></legend>
     115        <?php wp_dropdown_users( array('include' => $editable_ids, 'show_option_all' => __('Any'), 'name' => 'author', 'selected' => isset($_GET['author']) ? $_GET['author'] : 0) ); ?>
     116    </fieldset>
     117
     118<?php
     119endif;
     120
     121$arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC";
     122
     123$arc_result = $wpdb->get_results( $arc_query );
     124
     125$month_count = count($arc_result);
     126
     127if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
     128
     129    <fieldset><legend><?php _e('Month&hellip;') ?></legend>
     130        <select name='m'>
     131            <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Any'); ?></option>
     132        <?php
    93133        foreach ($arc_result as $arc_row) {
    94134            if ( $arc_row->yyear == 0 )
     
    96136            $arc_row->mmonth = zeroise($arc_row->mmonth, 2);
    97137
    98             if( isset($_GET['m']) && $arc_row->yyear . $arc_row->mmonth == (int) $_GET['m'] )
    99                 $default = 'selected="selected"';
     138            if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
     139                $default = ' selected="selected"';
    100140            else
    101                 $default = null;
    102 
    103             echo "<option $default value='$arc_row->yyear$arc_row->mmonth'>";
     141                $default = '';
     142
     143            echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>";
    104144            echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
    105145            echo "</option>\n";
    106146        }
    107     ?>
    108     </select>
    109         <input type="submit" name="submit" value="<?php _e('Show Month') ?>" class="button" />
    110     </fieldset>
     147        ?>
     148        </select>
     149    </fieldset>
     150
     151<?php } ?>
     152
     153    <fieldset><legend><?php _e('Category&hellip;') ?></legend>
     154        <?php wp_dropdown_categories('show_option_all='.__('All').'&hide_empty=1&hierarchical=1&show_count=1&selected='.$cat);?>
     155    </fieldset>
     156    <input type="submit" id="post-query-submit" value="<?php _e('Filter &#187;'); ?>" class="button" />
    111157</form>
    112158
    113 <?php } ?>
    114 
    115 <form name="viewcat" id="viewcat" action="" method="get">
    116     <fieldset>
    117     <legend><?php _e('Browse Category&hellip;') ?></legend>
    118     <?php wp_dropdown_categories('show_option_all='.__('All').'&hide_empty=1&hierarchical=1&show_count=1&selected='.$cat);?>
    119     <input type="submit" name="submit" value="<?php _e('Show Category') ?>" class="button" />
    120     </fieldset>
    121 </form>
    122 
    123159<?php do_action('restrict_manage_posts'); ?>
    124160
    125161<br style="clear:both;" />
    126162
    127 <?php
    128 // define the columns to display, the syntax is 'internal name' => 'display name'
    129 $posts_columns = array(
    130     'id'         => '<div style="text-align: center">' . __('ID') . '</div>',
    131     'date'       => __('When'),
    132     'title'      => __('Title'),
    133     'categories' => __('Categories'),
    134     'comments'   => '<div style="text-align: center">' . __('Comments') . '</div>',
    135     'author'     => __('Author')
    136 );
    137 $posts_columns = apply_filters('manage_posts_columns', $posts_columns);
    138 
    139 // you can not edit these at the moment
    140 $posts_columns['control_view']   = '';
    141 $posts_columns['control_edit']   = '';
    142 $posts_columns['control_delete'] = '';
    143 
    144 ?>
    145 
    146 <table class="widefat">
    147     <thead>
    148     <tr>
    149 
    150 <?php foreach($posts_columns as $column_display_name) { ?>
    151     <th scope="col"><?php echo $column_display_name; ?></th>
    152 <?php } ?>
    153 
    154     </tr>
    155     </thead>
    156     <tbody id="the-list">
    157 <?php
    158 if ($posts) {
    159 $bgcolor = '';
    160 while (have_posts()) : the_post();
    161 add_filter('the_title','wp_specialchars');
    162 $class = ('alternate' == $class) ? '' : 'alternate';
    163 ?>
    164     <tr id='post-<?php echo $id; ?>' class='<?php echo $class; ?>'>
    165 
    166 <?php
    167 
    168 foreach($posts_columns as $column_name=>$column_display_name) {
    169 
    170     switch($column_name) {
    171 
    172     case 'id':
    173         ?>
    174         <th scope="row" style="text-align: center"><?php echo $id ?></th>
    175         <?php
    176         break;
    177 
    178     case 'date':
    179         ?>
    180         <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else the_time(__('Y-m-d \<\b\r \/\> g:i:s a')); ?></td>
    181         <?php
    182         break;
    183     case 'title':
    184         ?>
    185         <td><?php the_title() ?>
    186         <?php if ('private' == $post->post_status) _e(' - <strong>Private</strong>'); ?></td>
    187         <?php
    188         break;
    189 
    190     case 'categories':
    191         ?>
    192         <td><?php the_category(','); ?></td>
    193         <?php
    194         break;
    195 
    196     case 'comments':
    197         ?>
    198         <td style="text-align: center">
    199             <?php comments_number(__('0'), "<a href='edit.php?p=$id&amp;c=1'>" . __('1') . '</a>', "<a href='edit.php?p=$id&amp;c=1'>" . __('%') . '</a>') ?>
    200             </td>
    201         <?php
    202         break;
    203 
    204     case 'author':
    205         ?>
    206         <td><?php the_author() ?></td>
    207         <?php
    208         break;
    209 
    210     case 'control_view':
    211         ?>
    212         <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td>
    213         <?php
    214         break;
    215 
    216     case 'control_edit':
    217         ?>
    218         <td><?php if ( current_user_can('edit_post',$post->ID) ) { echo "<a href='post.php?action=edit&amp;post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>
    219         <?php
    220         break;
    221 
    222     case 'control_delete':
    223         ?>
    224         <td><?php if ( current_user_can('delete_post',$post->ID) ) { echo "<a href='" . wp_nonce_url("post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "' class='delete' onclick=\"return deleteSomething( 'post', " . $id . ", '" . js_escape(sprintf(__("You are about to delete this post '%s'.\n'OK' to delete, 'Cancel' to stop."), get_the_title())) . "' );\">" . __('Delete') . "</a>"; } ?></td>
    225         <?php
    226         break;
    227 
    228     default:
    229         ?>
    230         <td><?php do_action('manage_posts_custom_column', $column_name, $id); ?></td>
    231         <?php
    232         break;
    233     }
    234 }
    235 ?>
    236     </tr>
    237 <?php
    238 endwhile;
    239 } else {
    240 ?>
    241   <tr style='background-color: <?php echo $bgcolor; ?>'>
    242     <td colspan="8"><?php _e('No posts found.') ?></td>
    243   </tr>
    244 <?php
    245 } // end if ($posts)
    246 ?>
    247     </tbody>
    248 </table>
     163<?php include( 'edit-post-rows.php' ); ?>
    249164
    250165<div id="ajax-response"></div>
     
    256171
    257172<?php
     173
    258174if ( 1 == count($posts) ) {
    259175
    260176    $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved != 'spam' ORDER BY comment_date");
    261177    if ($comments) {
     178        update_comment_cache($comments);
    262179    ?>
    263180<h3 id="comments"><?php _e('Comments') ?></h3>
     
    268185
    269186        ++$i; $class = '';
    270         $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
     187        $post = get_post($comment->comment_post_ID);
     188        $authordata = get_userdata($post->post_author);
    271189            $comment_status = wp_get_comment_status($comment->comment_ID);
    272190            if ('unapproved' == $comment_status)
     
    276194            echo "<li id='comment-$comment->comment_ID' class='$class'>";
    277195?>
    278 <p><strong><?php comment_author() ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
     196<p><strong><?php comment_author() ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="edit-comments.php?s=<?php comment_author_IP() ?>&amp;mode=edit"><?php comment_author_IP() ?></a></p>
    279197
    280198<?php comment_text() ?>
    281199
    282 <p><?php comment_date(__('M j, g:i A'));  ?> &#8212; [
     200<p><?php comment_date(__('M j, g:i A')); ?> &#8212; [
    283201<?php
    284202if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
    285     echo " <a href='comment.php?action=editcomment&amp;c=".$comment->comment_ID."'>" .  __('Edit') . '</a>';
     203    echo " <a href='comment.php?action=editcomment&amp;c=".$comment->comment_ID."'>" . __('Edit') . '</a>';
    286204    echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
    287205    if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
     
    289207        echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
    290208    }
    291     echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author))  . "', theCommentList );\">" . __('Spam') . "</a> ";
    292 }
    293 ?>
     209    echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . "</a> ";
     210}
     211?> ]
    294212</p>
    295213        </li>
     
    302220<?php } ?>
    303221</div>
    304 <?php
    305  include('admin-footer.php');
    306 ?>
     222
     223<?php include('admin-footer.php'); ?>
  • trunk/wp-admin/export.php

    r6163 r6163  
    2626<option value="all" selected="selected"><?php _e('All'); ?></option>
    2727<?php
    28 $authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" ); 
     28$authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );
    2929foreach ( $authors as $id ) {
    3030    $o = get_userdata( $id );
     
    4646
    4747function export_wp() {
    48 global $wpdb, $posts, $post;
     48global $wpdb, $post_ids, $post;
     49
     50do_action('export_wp');
    4951
    5052$filename = 'wordpress.' . date('Y-m-d') . '.xml';
     
    5254header('Content-Description: File Transfer');
    5355header("Content-Disposition: attachment; filename=$filename");
    54 header('Content-type: text/xml; charset=' . get_option('blog_charset'), true);
     56header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
    5557
    5658$where = '';
     
    6062}
    6163
    62 $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
    63 
    64 $categories = (array) $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (category_id = cat_id) LEFT JOIN $wpdb->posts ON (post_id <=> id) $where GROUP BY cat_id");
     64// grab a snapshot of post IDs, just in case it changes during the export
     65$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
     66
     67$categories = (array) get_categories('get=all');
     68$tags = (array) get_tags('get=all');
    6569
    6670function wxr_missing_parents($categories) {
     
    6973
    7074    foreach ( $categories as $category )
    71         $parents[$category->cat_ID] = $category->category_parent;
     75        $parents[$category->term_id] = $category->parent;
    7276
    7377    $parents = array_unique(array_diff($parents, array_keys($parents)));
     
    8084
    8185while ( $parents = wxr_missing_parents($categories) ) {
    82     $found_parents = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories WHERE cat_ID IN (" . join(', ', $parents) . ")");
     86    $found_parents = get_categories("include=" . join(', ', $parents));
    8387    if ( is_array($found_parents) && count($found_parents) )
    8488        $categories = array_merge($categories, $found_parents);
     
    9195$passes = 1000 + count($categories);
    9296while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
    93     if ( $cat->category_parent == 0 || isset($cats[$cat->category_parent]) ) {
    94         $cats[$cat->cat_ID] = $cat;
     97    if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
     98        $cats[$cat->term_id] = $cat;
    9599    } else {
    96100        $categories[] = $cat;
     
    111115
    112116function wxr_cat_name($c) {
    113     if ( empty($c->cat_name) )
    114         return;
    115 
    116     echo '<wp:cat_name>' . wxr_cdata($c->cat_name) . '</wp:cat_name>';
     117    if ( empty($c->name) )
     118        return;
     119
     120    echo '<wp:cat_name>' . wxr_cdata($c->name) . '</wp:cat_name>';
    117121}
    118122
    119123function wxr_category_description($c) {
    120     if ( empty($c->category_description) )
    121         return;
    122 
    123     echo '<wp:category_description>' . wxr_cdata($c->category_description) . '</wp:category_description>';
    124 }
    125 
    126 print '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
    127 
    128 ?>
    129 
    130 <!--
    131     This is a WordPress eXtended RSS file generated by WordPress as an export of
    132     your blog. It contains information about your blog's posts, comments, and
    133     categories. You may use this file to transfer that content from one site to
    134     another. This file is not intended to serve as a complete backup of your
    135     blog.
    136    
    137     To import this information into a WordPress blog follow these steps:
    138    
    139     1.  Log into that blog as an administrator.
    140     2.  Go to Manage > Import in the blog's admin.
    141     3.  Choose "WordPress" from the list of importers.
    142     4.  Upload this file using the form provided on that page.
    143     5.  You will first be asked to map the authors in this export file to users
    144         on the blog. For each author, you may choose to map an existing user on
    145         the blog or to create a new user.
    146     6.  WordPress will then import each of the posts, comments, and categories
    147         contained in this file onto your blog.
    148 -->
     124    if ( empty($c->description) )
     125        return;
     126
     127    echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>';
     128}
     129
     130function wxr_tag_name($t) {
     131    if ( empty($t->name) )
     132        return;
     133
     134    echo '<wp:tag_name>' . wxr_cdata($t->name) . '</wp:tag_name>';
     135}
     136
     137function wxr_tag_description($t) {
     138    if ( empty($t->description) )
     139        return;
     140
     141    echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
     142}
     143
     144function wxr_post_taxonomy() {
     145    $categories = get_the_category();
     146    $tags = get_the_tags();
     147    $cat_names = array();
     148    $tag_names = array();
     149    $the_list = '';
     150    $filter = 'rss';
     151
     152    if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
     153        $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
     154        $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
     155    }
     156
     157    if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
     158        $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
     159        $the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n";
     160    }
     161
     162    echo $the_list;
     163}
     164
     165echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
     166
     167?>
     168<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
     169<!-- It contains information about your blog's posts, comments, and categories. -->
     170<!-- You may use this file to transfer that content from one site to another. -->
     171<!-- This file is not intended to serve as a complete backup of your blog. -->
     172
     173<!-- To import this information into a WordPress blog follow these steps. -->
     174<!-- 1. Log into that blog as an administrator. -->
     175<!-- 2. Go to Manage: Import in the blog's admin panels. -->
     176<!-- 3. Choose "WordPress" from the list. -->
     177<!-- 4. Upload this file using the form provided on that page. -->
     178<!-- 5. You will first be asked to map the authors in this export file to users -->
     179<!--    on the blog.  For each author, you may choose to map to an -->
     180<!--    existing user on the blog or to create a new user -->
     181<!-- 6. WordPress will then import each of the posts, comments, and categories -->
     182<!--    contained in this file into your blog -->
    149183
    150184<!-- generator="wordpress/<?php bloginfo_rss('version') ?>" created="<?php echo date('Y-m-d H:i'); ?>"-->
     
    164198    <language><?php echo get_option('rss_language'); ?></language>
    165199<?php if ( $cats ) : foreach ( $cats as $c ) : ?>
    166     <wp:category><wp:category_nicename><?php echo $c->category_nicename; ?></wp:category_nicename><wp:category_parent><?php echo $c->category_parent ? $cats[$c->category_parent]->cat_name : ''; ?></wp:category_parent><wp:posts_private><?php echo $c->posts_private ? '1' : '0'; ?></wp:posts_private><wp:links_private><?php echo $c->links_private ? '1' : '0'; ?></wp:links_private><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category>
     200    <wp:category><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->name : ''; ?></wp:category_parent><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category>
     201<?php endforeach; endif; ?>
     202<?php if ( $tags ) : foreach ( $tags as $t ) : ?>
     203    <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag>
    167204<?php endforeach; endif; ?>
    168205    <?php do_action('rss2_head'); ?>
    169     <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
     206    <?php if ($post_ids) {
     207        global $wp_query;
     208        $wp_query->in_the_loop = true;  // Fake being in the loop.
     209        // fetch 20 posts at a time rather than loading the entire table into memory
     210        while ( $next_posts = array_splice($post_ids, 0, 20) ) {
     211            $where = "WHERE ID IN (".join(',', $next_posts).")";
     212            $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
     213                foreach ($posts as $post) {
     214            setup_postdata($post); ?>
    170215<item>
    171216<title><?php the_title_rss() ?></title>
    172 <link><?php permalink_single_rss() ?></link>
     217<link><?php the_permalink_rss() ?></link>
    173218<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
    174219<dc:creator><?php the_author() ?></dc:creator>
    175 <?php the_category_rss() ?>
     220<?php wxr_post_taxonomy() ?>
    176221
    177222<guid isPermaLink="false"><?php the_guid(); ?></guid>
     
    204249<wp:comment>
    205250<wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
    206 <wp:comment_author><?php echo $c->comment_author; ?></wp:comment_author>
     251<wp:comment_author><?php echo wxr_cdata($c->comment_author); ?></wp:comment_author>
    207252<wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
    208253<wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
     
    217262<?php } } ?>
    218263    </item>
    219 <?php } } ?>
     264<?php } } } ?>
    220265</channel>
    221266</rss>
  • trunk/wp-admin/import.php

    r6163 r6163  
    1515$import_loc = 'wp-admin/import';
    1616$import_root = ABSPATH.$import_loc;
    17 $imports_dir = @ dir($import_root);
     17$imports_dir = @ opendir($import_root);
    1818if ($imports_dir) {
    19     while (($file = $imports_dir->read()) !== false) {
     19    while (($file = readdir($imports_dir)) !== false) {
    2020        if ($file{0} == '.') {
    2121            continue;
     
    2525    }
    2626}
     27@closedir($imports_dir);
    2728
    2829$importers = get_importers();
  • trunk/wp-admin/import/blogger.php

    r6163 r6163  
    8585            $headers = array(
    8686                "GET /feeds/default/blogs HTTP/1.0",
    87                 "Host: www2.blogger.com",
     87                "Host: www.blogger.com",
    8888                "Authorization: AuthSub token=\"$this->token\""
    8989            );
     
    381381                        $AtomParser = new AtomParser();
    382382                        $AtomParser->parse( $entry );
    383                         $this->import_post($AtomParser->entry);
     383                        $result = $this->import_post($AtomParser->entry);
     384                        if ( is_wp_error( $result ) )
     385                            return $result;
    384386                        unset($AtomParser);
    385387                    }
     
    510512
    511513        // Checks for duplicates
    512         if (
    513             isset( $this->blogs[$importing_blog]['posts'][$entry->old_permalink] ) ||
    514             post_exists( $post_title, $post_content, $post_date )
    515         ) {
     514        if ( isset( $this->blogs[$importing_blog]['posts'][$entry->old_permalink] ) ) {
     515            ++$this->blogs[$importing_blog]['posts_skipped'];
     516        } elseif ( $post_id = post_exists( $post_title, $post_content, $post_date ) ) {
     517            $this->blogs[$importing_blog]['posts'][$entry->old_permalink] = $post_id;
    516518            ++$this->blogs[$importing_blog]['posts_skipped'];
    517519        } else {
     
    519521
    520522            $post_id = wp_insert_post($post);
     523            if ( is_wp_error( $post_id ) )
     524                return $post_id;
    521525
    522526            wp_create_categories( array_map( 'addslashes', $entry->categories ), $post_id );
     
    532536        }
    533537        $this->save_vars();
     538        return;
    534539    }
    535540
     
    768773            $blog = is_array($_REQUEST['blog']) ? array_shift( array_keys( $_REQUEST['blog'] ) ) : $_REQUEST['blog'];
    769774            $blog = (int) $blog;
    770             $this->import_blog( $blog );
     775            $result = $this->import_blog( $blog );
     776            if ( is_wp_error( $result ) )
     777                echo $result->get_error_message();
    771778        } elseif ( isset($_GET['token']) )
    772779            $this->auth();
     
    916923                array_push($this->in_content, ">");
    917924            }
    918          
     925
    919926            array_push($this->in_content, "<". $this->ns_to_prefix($name) ."{$xmlns_str}{$attrs_str}");
    920927        } else if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS) || in_array($tag, $this->ATOM_SIMPLE_ELEMENTS)) {
    921928            $this->in_content = array();
    922             $this->is_xhtml = $attrs['type'] == 'xhtml'; 
     929            $this->is_xhtml = $attrs['type'] == 'xhtml';
    923930            array_push($this->in_content, array($tag,$this->depth));
    924931        } else if($tag == 'link') {
     
    936943
    937944        if(!empty($this->in_content)) {
    938             if($this->in_content[0][0] == $tag && 
     945            if($this->in_content[0][0] == $tag &&
    939946            $this->in_content[0][1] == $this->depth) {
    940947                array_shift($this->in_content);
     
    9991006                }
    10001007            }
    1001         } 
     1008        }
    10021009        return $name;
    10031010    }
     
    10051012    function xml_escape($string)
    10061013    {
    1007              return str_replace(array('&','"',"'",'<','>'), 
    1008                 array('&amp;','&quot;','&apos;','&lt;','&gt;'), 
     1014             return str_replace(array('&','"',"'",'<','>'),
     1015                array('&amp;','&quot;','&apos;','&lt;','&gt;'),
    10091016                $string );
    10101017    }
  • trunk/wp-admin/import/blogware.php

    r6163 r6163  
    9292                $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
    9393                $post_id = wp_insert_post($postdata);
     94                if ( is_wp_error( $post_id ) ) {
     95                    return $post_id;
     96                }
    9497                if (!$post_id) {
    9598                    _e("Couldn't get post ID");
     
    156159
    157160        $this->file = $file['file'];
    158         $this->import_posts();
     161        $result = $this->import_posts();
     162        if ( is_wp_error( $result ) )
     163            return $result;
    159164        wp_import_cleanup($file['id']);
    160165
     
    177182                break;
    178183            case 1 :
    179                 $this->import();
     184                $result = $this->import();
     185                if ( is_wp_error( $result ) )
     186                    $result->get_error_message();
    180187                break;
    181188        }
  • trunk/wp-admin/import/dotclear.php

    r6163 r6163  
    88    Add These Functions to make our lives easier
    99**/
    10 if(!function_exists('get_catbynicename'))
    11 {
    12     function get_catbynicename($category_nicename)
    13     {
    14     global $wpdb;
    15 
    16     $cat_id -= 0;   // force numeric
    17     $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"');
    18 
    19     return $name;
    20     }
    21 }
    2210
    2311if(!function_exists('get_comment_count'))
     
    2715        global $wpdb;
    2816        return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID);
    29     }
    30 }
    31 
    32 if(!function_exists('link_cat_exists'))
    33 {
    34     function link_cat_exists($catname)
    35     {
    36         global $wpdb;
    37         return $wpdb->get_var('SELECT cat_id FROM '.$wpdb->linkcategories.' WHERE cat_name = "'.$wpdb->escape($catname).'"');
    3817    }
    3918}
     
    131110class Dotclear_Import {
    132111
    133     function header() 
     112    function header()
    134113    {
    135114        echo '<div class="wrap">';
     
    138117    }
    139118
    140     function footer() 
     119    function footer()
    141120    {
    142121        echo '</div>';
    143122    }
    144123
    145     function greet() 
     124    function greet()
    146125    {
    147126        echo '<div class="narrow"><p>'.__('Howdy! This importer allows you to extract posts from a DotClear database into your blog.  Mileage may vary.').'</p>';
     
    386365                            'comment_count'     => $post_nb_comment + $post_nb_trackback)
    387366                            );
     367                    if ( is_wp_error( $ret_id ) )
     368                        return $ret_id;
    388369                }
    389370                else
     
    404385                            'comment_count'     => $post_nb_comment + $post_nb_trackback)
    405386                            );
     387                    if ( is_wp_error( $ret_id ) )
     388                        return $ret_id;
    406389                }
    407390                $dcposts2wpposts[$post_id] = $ret_id;
     
    409392                // Make Post-to-Category associations
    410393                $cats = array();
    411                 if($cat1 = get_catbynicename($post_cat_name)) { $cats[1] = $cat1; }
     394                $category1 = get_category_by_slug($post_cat_name);
     395                $category1 = $category1->term_id;
     396
     397                if($cat1 = $category1) { $cats[1] = $cat1; }
    412398
    413399                if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); }
     
    510496
    511497                if ($title != "") {
    512                     if ($cinfo = link_cat_exists (csc ($title))) {
    513                         $category = $cinfo;
     498                    if ($cinfo = is_term(csc ($title), 'link_category')) {
     499                        $category = $cinfo['term_id'];
    514500                    } else {
    515                         $wpdb->query ("INSERT INTO $wpdb->linkcategories (cat_name) VALUES ('".
    516                             $wpdb->escape (csc ($title))."')");
    517                         $category = $wpdb->insert_id;
     501                        $category = wp_insert_term($wpdb->escape (csc ($title)), 'link_category');
     502                        $category = $category['term_id'];
    518503                    }
    519504                } else {
     
    582567        // Post Import
    583568        $posts = $this->get_dc_posts();
    584         $this->posts2wp($posts);
     569        $result = $this->posts2wp($posts);
     570        if ( is_wp_error( $result ) )
     571            return $result;
    585572
    586573        echo '<form action="admin.php?import=dotclear&amp;step=4" method="post">';
     
    730717                break;
    731718            case 3 :
    732                 $this->import_posts();
     719                $result = $this->import_posts();
     720                if ( is_wp_error( $result ) )
     721                    echo $result->get_error_message();
    733722                break;
    734723            case 4 :
  • trunk/wp-admin/import/greymatter.php

    r6163 r6163  
    234234                $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
    235235                $post_ID = wp_insert_post($postdata);
     236                if ( is_wp_error( $post_ID ) )
     237                    return $post_ID;
    236238            }
    237239
     
    288290<?php
    289291    $this->footer();
     292    return;
    290293    }
    291294
     
    302305            case 1:
    303306                check_admin_referer('import-greymatter');
    304                 $this->import();
     307                $result = $this->import();
     308                if ( is_wp_error( $result ) )
     309                    echo $result->get_error_message();
    305310                break;
    306311        }
  • trunk/wp-admin/import/livejournal.php

    r6163 r6163  
    5050            preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date);
    5151            $post_date = strtotime($post_date[1]);
    52             $post_date = gmdate('Y-m-d H:i:s', $post_date);
     52            $post_date = date('Y-m-d H:i:s', $post_date);
    5353
    5454            preg_match('|<event>(.*?)</event>|is', $post, $post_content);
     
    7272                $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
    7373                $post_id = wp_insert_post($postdata);
     74                if ( is_wp_error( $post_id ) )
     75                    return $post_id;
    7476                if (!$post_id) {
    7577                    _e("Couldn't get post ID");
     
    133135
    134136        $this->file = $file['file'];
    135         $this->import_posts();
     137        $result = $this->import_posts();
     138        if ( is_wp_error( $result ) )
     139            return $result;
    136140        wp_import_cleanup($file['id']);
    137141
     
    155159            case 1 :
    156160                check_admin_referer('import-upload');
    157                 $this->import();
     161                $result = $this->import();
     162                if ( is_wp_error( $result ) )
     163                    echo $result->get_error_message();
    158164                break;
    159165        }
  • trunk/wp-admin/import/mt.php

    r6163 r6163  
    2323?>
    2424<div class="narrow">
    25 <p><?php _e('Howdy! We&#8217;re about to begin importing all of your Movable Type or Typepad entries into WordPress. To begin, choose a file to upload and click Upload file and import.'); ?></p>
     25<p><?php _e('Howdy! We&#8217;re about to begin importing all of your Movable Type or Typepad entries into WordPress. To begin, either choose a file to upload and click "Upload file and import," or use FTP to upload your MT export file as <code>mt-export.txt</code> in your <code>/wp-content/</code> directory and then click "Import mt-export.txt"'); ?></p>
    2626<?php wp_import_upload_form( add_query_arg('step', 1) ); ?>
    27     <p><?php _e('The importer is smart enough not to import duplicates, so you can run this multiple times without worry if&#8212;for whatever reason&#8212;it doesn\'t finish. If you get an <strong>out of memory</strong> error try splitting up the import file into pieces.'); ?> </p>
     27<form method="post" action="<?php echo add_query_arg('step', 1); ?>" class="import-upload-form">
     28<?php wp_nonce_field('import-upload'); ?>
     29<p>
     30    <input type="hidden" name="upload_type" value="ftp" />
     31<?php _e('Or use <code>mt-export.txt</code> in your <code>/wp-content/</code> directory'); ?></p>
     32<p class="submit">
     33<input type="submit" value="<?php _e(sprintf('Import %s', 'mt-export.txt &raquo;')); ?>" />
     34</p>
     35</form>
     36<p><?php _e('The importer is smart enough not to import duplicates, so you can run this multiple times without worry if&#8212;for whatever reason&#8212;it doesn\'t finish. If you get an <strong>out of memory</strong> error try splitting up the import file into pieces.'); ?> </p>
    2837</div>
    2938<?php
     
    7685    }
    7786
    78     function get_entries() {
    79         set_magic_quotes_runtime(0);
    80         $importdata = file($this->file); // Read the file into an array
    81         $importdata = implode('', $importdata); // squish it
    82         $importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata);
    83         $importdata = preg_replace("/\n--------\n/", "--MT-ENTRY--\n", $importdata);
    84         $this->posts = explode("--MT-ENTRY--", $importdata);
    85     }
    86 
    8787    function get_mt_authors() {
    88         $temp = array ();
    89         $i = -1;
    90         foreach ($this->posts as $post) {
    91             if ('' != trim($post)) {
    92                 ++ $i;
    93                 preg_match("|AUTHOR:(.*)|", $post, $thematch);
    94                 $thematch = trim($thematch[1]);
    95                 array_push($temp, "$thematch"); //store the extracted author names in a temporary array
    96             }
     88        $temp = array();
     89        $authors = array();
     90
     91        $handle = fopen($this->file, 'r');
     92        if ( $handle == null )
     93            return false;
     94
     95        $in_comment = false;
     96        while ( $line = fgets($handle) ) {
     97            $line = trim($line);
     98
     99            if ( 'COMMENT:' == $line )
     100                $in_comment = true;
     101            else if ( '-----' == $line )
     102                $in_comment = false;
     103
     104            if ( $in_comment || 0 !== strpos($line,"AUTHOR:") )
     105                continue;
     106
     107            $temp[] = trim( substr($line, strlen("AUTHOR:")) );
    97108        }
    98109
     
    106117        }
    107118
     119        fclose($handle);
     120
    108121        return $authors;
    109122    }
     
    139152<div class="wrap">
    140153<h2><?php _e('Assign Authors'); ?></h2>
    141 <p><?php _e('To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.'); ?></p>
     154<p><?php _e('To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as admin\'s entries.'); ?></p>
    142155<p><?php _e('Below, you can see the names of the authors of the MovableType posts in <i>italics</i>. For each of these names, you can either pick an author in your WordPress installation from the menu, or enter a name for the author in the textbox.'); ?></p>
    143156<p><?php _e('If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)'); ?></p>
     
    157170        }
    158171
    159         echo '<input type="submit" value="'.__('Submit').'">'.'<br/>';
     172        echo '<input type="submit" value="'.__('Submit').'">'.'<br />';
    160173        echo '</form>';
    161174        echo '</ol></div>';
     
    164177
    165178    function select_authors() {
    166         $file = wp_import_handle_upload();
     179        if ( $_POST['upload_type'] === 'ftp' ) {
     180            $file['file'] = ABSPATH . 'wp-content/mt-export.txt';
     181            if ( !file_exists($file['file']) )
     182                $file['error'] = __('<code>mt-export.txt</code> does not exist');
     183        } else {
     184            $file = wp_import_handle_upload();
     185        }
    167186        if ( isset($file['error']) ) {
    168187            $this->header();
     
    175194        $this->id = (int) $file['id'];
    176195
    177         $this->get_entries();
    178196        $this->mt_authors_form();
     197    }
     198
     199    function save_post(&$post, &$comments, &$pings) {
     200        // Reset the counter
     201        set_time_limit(30);
     202        $post = get_object_vars($post);
     203        $post = add_magic_quotes($post);
     204        $post = (object) $post;
     205
     206        if ( $post_id = post_exists($post->post_title, '', $post->post_date) ) {
     207            echo '<li>';
     208            printf(__('Post <i>%s</i> already exists.'), stripslashes($post->post_title));
     209        } else {
     210            echo '<li>';
     211            printf(__('Importing post <i>%s</i>...'), stripslashes($post->post_title));
     212
     213            if ( '' != trim( $post->extended ) )
     214                    $post->post_content .= "\n<!--more-->\n$post->extended";
     215
     216            $post->post_author = $this->checkauthor($post->post_author); //just so that if a post already exists, new users are not created by checkauthor
     217            $post_id = wp_insert_post($post);
     218            if ( is_wp_error( $post_id ) )
     219                return $post_id;
     220
     221            // Add categories.
     222            if ( 0 != count($post->categories) ) {
     223                wp_create_categories($post->categories, $post_id);
     224            }
     225        }
     226
     227        $num_comments = 0;
     228        foreach ( $comments as $comment ) {
     229            $comment = get_object_vars($comment);
     230            $comment = add_magic_quotes($comment);
     231
     232            if ( !comment_exists($comment['comment_author'], $comment['comment_date'])) {
     233                $comment['comment_post_ID'] = $post_id;
     234                $comment = wp_filter_comment($comment);
     235                wp_insert_comment($comment);
     236                $num_comments++;
     237            }
     238        }
     239
     240        if ( $num_comments )
     241            printf(' '.__('(%s comments)'), $num_comments);
     242
     243        $num_pings = 0;
     244        foreach ( $pings as $ping ) {
     245            $ping = get_object_vars($ping);
     246            $ping = add_magic_quotes($ping);
     247
     248            if ( !comment_exists($ping['comment_author'], $ping['comment_date'])) {
     249                $ping['comment_content'] = "<strong>{$ping['title']}</strong>\n\n{$ping['comment_content']}";
     250                $ping['comment_post_ID'] = $post_id;
     251                $ping = wp_filter_comment($ping);
     252                wp_insert_comment($ping);
     253                $num_pings++;
     254            }
     255        }
     256
     257        if ( $num_pings )
     258            printf(' '.__('(%s pings)'), $num_pings);
     259
     260        echo "</li>";
     261        //ob_flush();flush();
    179262    }
    180263
    181264    function process_posts() {
    182265        global $wpdb;
    183         $i = -1;
     266
     267        $handle = fopen($this->file, 'r');
     268        if ( $handle == null )
     269            return false;
     270
     271        $context = '';
     272        $post = new StdClass();
     273        $comment = new StdClass();
     274        $comments = array();
     275        $ping = new StdClass();
     276        $pings = array();
     277
    184278        echo "<div class='wrap'><ol>";
    185         foreach ($this->posts as $post) {
    186             if ('' != trim($post)) {
    187                 ++ $i;
    188                 unset ($post_categories);
    189 
    190                 // Take the pings out first
    191                 preg_match("|(-----\n\nPING:.*)|s", $post, $pings);
    192                 $post = preg_replace("|(-----\n\nPING:.*)|s", '', $post);
    193 
    194                 // Then take the comments out
    195                 preg_match("|(-----\nCOMMENT:.*)|s", $post, $comments);
    196                 $post = preg_replace("|(-----\nCOMMENT:.*)|s", '', $post);
    197 
    198                 // We ignore the keywords
    199                 $post = preg_replace("|(-----\nKEYWORDS:.*)|s", '', $post);
    200 
    201                 // We want the excerpt
    202                 preg_match("|-----\nEXCERPT:(.*)|s", $post, $excerpt);
    203                 $post_excerpt = $wpdb->escape(trim($excerpt[1]));
    204                 $post = preg_replace("|(-----\nEXCERPT:.*)|s", '', $post);
    205 
    206                 // We're going to put extended body into main body with a more tag
    207                 preg_match("|-----\nEXTENDED BODY:(.*)|s", $post, $extended);
    208                 $extended = trim($extended[1]);
    209                 if ('' != $extended)
    210                     $extended = "\n<!--more-->\n$extended";
    211                 $post = preg_replace("|(-----\nEXTENDED BODY:.*)|s", '', $post);
    212 
    213                 // Now for the main body
    214                 preg_match("|-----\nBODY:(.*)|s", $post, $body);
    215                 $body = trim($body[1]);
    216                 $post_content = $wpdb->escape($body.$extended);
    217                 $post = preg_replace("|(-----\nBODY:.*)|s", '', $post);
    218 
    219                 // Grab the metadata from what's left
    220                 $metadata = explode("\n", $post);
    221                 foreach ($metadata as $line) {
    222                     preg_match("/^(.*?):(.*)/", $line, $token);
    223                     $key = trim($token[1]);
    224                     $value = trim($token[2]);
    225                     // Now we decide what it is and what to do with it
    226                     switch ($key) {
    227                         case '' :
    228                             break;
    229                         case 'AUTHOR' :
    230                             $post_author = $value;
    231                             break;
    232                         case 'TITLE' :
    233                             $post_title = $wpdb->escape($value);
    234                             break;
    235                         case 'STATUS' :
    236                             // "publish" and "draft" enumeration items match up; no change required
    237                             $post_status = $value;
    238                             if (empty ($post_status))
    239                                 $post_status = 'publish';
    240                             break;
    241                         case 'ALLOW COMMENTS' :
    242                             $post_allow_comments = $value;
    243                             if ($post_allow_comments == 1) {
    244                                 $comment_status = 'open';
    245                             } else {
    246                                 $comment_status = 'closed';
    247                             }
    248                             break;
    249                         case 'CONVERT BREAKS' :
    250                             $post_convert_breaks = $value;
    251                             break;
    252                         case 'ALLOW PINGS' :
    253                             $ping_status = trim($meta[2][0]);
    254                             if ($ping_status == 1) {
    255                                 $ping_status = 'open';
    256                             } else {
    257                                 $ping_status = 'closed';
    258                             }
    259                             break;
    260                         case 'PRIMARY CATEGORY' :
    261                             if (! empty ($value) )
    262                                 $post_categories[] = $wpdb->escape($value);
    263                             break;
    264                         case 'CATEGORY' :
    265                             if (! empty ($value) )
    266                                 $post_categories[] = $wpdb->escape($value);
    267                             break;
    268                         case 'DATE' :
    269                             $post_modified = strtotime($value);
    270                             $post_modified = date('Y-m-d H:i:s', $post_modified);
    271                             $post_modified_gmt = get_gmt_from_date("$post_modified");
    272                             $post_date = $post_modified;
    273                             $post_date_gmt = $post_modified_gmt;
    274                             break;
    275                         default :
    276                             // echo "\n$key: $value";
    277                             break;
    278                     } // end switch
    279                 } // End foreach
    280 
    281                 // Let's check to see if it's in already
    282                 if ($post_id = post_exists($post_title, '', $post_date)) {
    283                     echo '<li>';
    284                     printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
    285                 } else {
    286                     echo '<li>';
    287                     printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
    288 
    289                     $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor
    290 
    291                     $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
    292                     $post_id = wp_insert_post($postdata);
    293                     // Add categories.
    294                     if (0 != count($post_categories)) {
    295                         wp_create_categories($post_categories, $post_id);
    296                     }
     279
     280        while ( $line = fgets($handle) ) {
     281            $line = trim($line);
     282
     283            if ( '-----' == $line ) {
     284                // Finishing a multi-line field
     285                if ( 'comment' == $context ) {
     286                    $comments[] = $comment;
     287                    $comment = new StdClass();
     288                } else if ( 'ping' == $context ) {
     289                    $pings[] = $ping;
     290                    $ping = new StdClass();
    297291                }
    298 
    299                 $comment_post_ID = (int) $post_id;
    300                 $comment_approved = 1;
    301 
    302                 // Now for comments
    303                 $comments = explode("-----\nCOMMENT:", $comments[0]);
    304                 $num_comments = 0;
    305                 foreach ($comments as $comment) {
    306                     if ('' != trim($comment)) {
    307                         // Author
    308                         preg_match("|AUTHOR:(.*)|", $comment, $comment_author);
    309                         $comment_author = $wpdb->escape(trim($comment_author[1]));
    310                         $comment = preg_replace('|(\n?AUTHOR:.*)|', '', $comment);
    311                         preg_match("|EMAIL:(.*)|", $comment, $comment_author_email);
    312                         $comment_author_email = $wpdb->escape(trim($comment_author_email[1]));
    313                         $comment = preg_replace('|(\n?EMAIL:.*)|', '', $comment);
    314 
    315                         preg_match("|IP:(.*)|", $comment, $comment_author_IP);
    316                         $comment_author_IP = trim($comment_author_IP[1]);
    317                         $comment = preg_replace('|(\n?IP:.*)|', '', $comment);
    318 
    319                         preg_match("|URL:(.*)|", $comment, $comment_author_url);
    320                         $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
    321                         $comment = preg_replace('|(\n?URL:.*)|', '', $comment);
    322 
    323                         preg_match("|DATE:(.*)|", $comment, $comment_date);
    324                         $comment_date = trim($comment_date[1]);
    325                         $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
    326                         $comment = preg_replace('|(\n?DATE:.*)|', '', $comment);
    327 
    328                         $comment_content = $wpdb->escape(trim($comment));
    329                         $comment_content = str_replace('-----', '', $comment_content);
    330                         // Check if it's already there
    331                         if (!comment_exists($comment_author, $comment_date)) {
    332                             $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved');
    333                             $commentdata = wp_filter_comment($commentdata);
    334                             wp_insert_comment($commentdata);
    335                             $num_comments++;
    336                         }
    337                     }
     292                $context = '';
     293            } else if ( '--------' == $line ) {
     294                // Finishing a post.
     295                $context = '';
     296                $result = $this->save_post($post, $comments, $pings);
     297                if ( is_wp_error( $result ) )
     298                    return $result;
     299                $post = new StdClass;
     300                $comment = new StdClass();
     301                $ping = new StdClass();
     302                $comments = array();
     303                $pings = array();
     304            } else if ( 'BODY:' == $line ) {
     305                $context = 'body';
     306            } else if ( 'EXTENDED BODY:' == $line ) {
     307                $context = 'extended';
     308            } else if ( 'EXCERPT:' == $line ) {
     309                $context = 'excerpt';
     310            } else if ( 'KEYWORDS:' == $line ) {
     311                $context = 'keywords';
     312            } else if ( 'COMMENT:' == $line ) {
     313                $context = 'comment';
     314            } else if ( 'PING:' == $line ) {
     315                $context = 'ping';
     316            } else if ( 0 === strpos($line, "AUTHOR:") ) {
     317                $author = trim( substr($line, strlen("AUTHOR:")) );
     318                if ( '' == $context )
     319                    $post->post_author = $author;
     320                else if ( 'comment' == $context )
     321                     $comment->comment_author = $author;
     322            } else if ( 0 === strpos($line, "TITLE:") ) {
     323                $title = trim( substr($line, strlen("TITLE:")) );
     324                if ( '' == $context )
     325                    $post->post_title = $title;
     326                else if ( 'ping' == $context )
     327                    $ping->title = $title;
     328            } else if ( 0 === strpos($line, "STATUS:") ) {
     329                $status = trim( substr($line, strlen("STATUS:")) );
     330                if ( empty($status) )
     331                    $status = 'publish';
     332                $post->post_status = $status;
     333            } else if ( 0 === strpos($line, "ALLOW COMMENTS:") ) {
     334                $allow = trim( substr($line, strlen("ALLOW COMMENTS:")) );
     335                if ( $allow == 1 )
     336                    $post->comment_status = 'open';
     337                else
     338                    $post->comment_status = 'closed';
     339            } else if ( 0 === strpos($line, "ALLOW PINGS:") ) {
     340                $allow = trim( substr($line, strlen("ALLOW PINGS:")) );
     341                if ( $allow == 1 )
     342                    $post->ping_status = 'open';
     343                else
     344                    $post->ping_status = 'closed';
     345            } else if ( 0 === strpos($line, "CATEGORY:") ) {
     346                $category = trim( substr($line, strlen("CATEGORY:")) );
     347                if ( '' != $category )
     348                    $post->categories[] = $category;
     349            } else if ( 0 === strpos($line, "PRIMARY CATEGORY:") ) {
     350                $category = trim( substr($line, strlen("PRIMARY CATEGORY:")) );
     351                if ( '' != $category )
     352                    $post->categories[] = $category;
     353            } else if ( 0 === strpos($line, "DATE:") ) {
     354                $date = trim( substr($line, strlen("DATE:")) );
     355                $date = strtotime($date);
     356                $date = date('Y-m-d H:i:s', $date);
     357                $date_gmt = get_gmt_from_date($date);
     358                if ( '' == $context ) {
     359                    $post->post_modified = $date;
     360                    $post->post_modified_gmt = $date_gmt;
     361                    $post->post_date = $date;
     362                    $post->post_date_gmt = $date_gmt;
     363                } else if ( 'comment' == $context ) {
     364                    $comment->comment_date = $date;
     365                } else if ( 'ping' == $context ) {
     366                    $ping->comment_date = $date;
    338367                }
    339                 if ( $num_comments )
    340                     printf(' '.__('(%s comments)'), $num_comments);
    341 
    342                 // Finally the pings
    343                 // fix the double newline on the first one
    344                 $pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]);
    345                 $pings = explode("-----\nPING:", $pings[0]);
    346                 $num_pings = 0;
    347                 foreach ($pings as $ping) {
    348                     if ('' != trim($ping)) {
    349                         // 'Author'
    350                         preg_match("|BLOG NAME:(.*)|", $ping, $comment_author);
    351                         $comment_author = $wpdb->escape(trim($comment_author[1]));
    352                         $ping = preg_replace('|(\n?BLOG NAME:.*)|', '', $ping);
    353 
    354                         preg_match("|IP:(.*)|", $ping, $comment_author_IP);
    355                         $comment_author_IP = trim($comment_author_IP[1]);
    356                         $ping = preg_replace('|(\n?IP:.*)|', '', $ping);
    357 
    358                         preg_match("|URL:(.*)|", $ping, $comment_author_url);
    359                         $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
    360                         $ping = preg_replace('|(\n?URL:.*)|', '', $ping);
    361 
    362                         preg_match("|DATE:(.*)|", $ping, $comment_date);
    363                         $comment_date = trim($comment_date[1]);
    364                         $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
    365                         $ping = preg_replace('|(\n?DATE:.*)|', '', $ping);
    366 
    367                         preg_match("|TITLE:(.*)|", $ping, $ping_title);
    368                         $ping_title = $wpdb->escape(trim($ping_title[1]));
    369                         $ping = preg_replace('|(\n?TITLE:.*)|', '', $ping);
    370 
    371                         $comment_content = $wpdb->escape(trim($ping));
    372                         $comment_content = str_replace('-----', '', $comment_content);
    373 
    374                         $comment_content = "<strong>$ping_title</strong>\n\n$comment_content";
    375 
    376                         $comment_type = 'trackback';
    377 
    378                         // Check if it's already there
    379                         if (!comment_exists($comment_author, $comment_date)) {
    380                             $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type', 'comment_approved');
    381                             $commentdata = wp_filter_comment($commentdata);
    382                             wp_insert_comment($commentdata);
    383                             $num_pings++;
    384                         }
    385                     }
     368            } else if ( 0 === strpos($line, "EMAIL:") ) {
     369                $email = trim( substr($line, strlen("EMAIL:")) );
     370                if ( 'comment' == $context )
     371                    $comment->comment_author_email = $email;
     372                else
     373                    $ping->comment_author_email = '';
     374            } else if ( 0 === strpos($line, "IP:") ) {
     375                $ip = trim( substr($line, strlen("IP:")) );
     376                if ( 'comment' == $context )
     377                    $comment->comment_author_IP = $ip;
     378                else
     379                    $ping->comment_author_IP = $ip;
     380            } else if ( 0 === strpos($line, "URL:") ) {
     381                $url = trim( substr($line, strlen("URL:")) );
     382                if ( 'comment' == $context )
     383                    $comment->comment_author_url = $url;
     384                else
     385                    $ping->comment_author_url = $url;
     386            } else if ( 0 === strpos($line, "BLOG NAME:") ) {
     387                $blog = trim( substr($line, strlen("BLOG NAME:")) );
     388                $ping->comment_author = $blog;
     389            } else {
     390                // Processing multi-line field, check context.
     391
     392                $line .= "\n";
     393                if ( 'body' == $context ) {
     394                    $post->post_content .= $line;
     395                } else if ( 'extended' ==  $context ) {
     396                    $post->extended .= $line;
     397                } else if ( 'excerpt' == $context ) {
     398                    $post->post_excerpt .= $line;
     399                } else if ( 'comment' == $context ) {
     400                    $comment->comment_content .= $line;
     401                } else if ( 'ping' == $context ) {
     402                    $ping->comment_content .= $line;
    386403                }
    387                 if ( $num_pings )
    388                     printf(' '.__('(%s pings)'), $num_pings);
    389 
    390                 echo "</li>";
    391404            }
    392405        }
     
    395408
    396409        wp_import_cleanup($this->id);
     410        do_action('import_done', 'mt');
    397411
    398412        echo '<h3>'.sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')).'</h3></div>';
     
    401415    function import() {
    402416        $this->id = (int) $_GET['id'];
    403 
    404         $this->file = get_attached_file($this->id);
     417        if ( $this->id == 0 )
     418            $this->file = ABSPATH . 'wp-content/mt-export.txt';
     419        else
     420            $this->file = get_attached_file($this->id);
    405421        $this->get_authors_from_post();
    406         $this->get_entries();
    407         $this->process_posts();
     422        $result = $this->process_posts();
     423        if ( is_wp_error( $result ) )
     424            return $result;
    408425    }
    409426
     
    424441            case 2:
    425442                check_admin_referer('import-mt');
    426                 $this->import();
     443                $result = $this->import();
     444                if ( is_wp_error( $result ) )
     445                    echo $result->get_error_message();
    427446                break;
    428447        }
  • trunk/wp-admin/import/rss.php

    r6163 r6163  
    111111            } else {
    112112                $post_id = wp_insert_post($post);
     113                if ( is_wp_error( $post_id ) )
     114                    return $post_id;
    113115                if (!$post_id) {
    114116                    _e("Couldn't get post ID");
     
    136138        $this->file = $file['file'];
    137139        $this->get_posts();
    138         $this->import_posts();
     140        $result = $this->import_posts();
     141        if ( is_wp_error( $result ) )
     142            return $result;
    139143        wp_import_cleanup($file['id']);
    140144
     
    158162            case 1 :
    159163                check_admin_referer('import-upload');
    160                 $this->import();
     164                $result = $this->import();
     165                if ( is_wp_error( $result ) )
     166                    echo $result->get_error_message();
    161167                break;
    162168        }
  • trunk/wp-admin/import/textpattern.php

    r6163 r6163  
    33    Add These Functions to make our lives easier
    44**/
    5 if(!function_exists('get_catbynicename'))
    6 {
    7     function get_catbynicename($category_nicename)
    8     {
    9     global $wpdb;
    10 
    11     $cat_id -= 0;   // force numeric
    12     $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"');
    13 
    14     return $name;
    15     }
    16 }
    175
    186if(!function_exists('get_comment_count'))
     
    3927class Textpattern_Import {
    4028
    41     function header() 
     29    function header()
    4230    {
    4331        echo '<div class="wrap">';
     
    4634    }
    4735
    48     function footer() 
     36    function footer()
    4937    {
    5038        echo '</div>';
     
    318306                        'comment_count'     => $comments_count)
    319307                        );
     308                    if ( is_wp_error( $ret_id ) )
     309                        return $ret_id;
    320310                }
    321311                else
     
    334324                        'comment_count'     => $comments_count)
    335325                        );
     326                    if ( is_wp_error( $ret_id ) )
     327                        return $ret_id;
    336328                }
    337329                $txpposts2wpposts[$ID] = $ret_id;
     
    339331                // Make Post-to-Category associations
    340332                $cats = array();
    341                 if($cat1 = get_catbynicename($Category1)) { $cats[1] = $cat1; }
    342                 if($cat2 = get_catbynicename($Category2)) { $cats[2] = $cat2; }
     333                $category1 = get_category_by_slug($Category1);
     334                $category1 = $category1->term_id;
     335                $category2 = get_category_by_slug($Category2);
     336                $category2 = $category1->term_id;
     337                if($cat1 = $category1) { $cats[1] = $cat1; }
     338                if($cat2 = $category2) { $cats[2] = $cat2; }
    343339
    344340                if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); }
     
    507503        // Post Import
    508504        $posts = $this->get_txp_posts();
    509         $this->posts2wp($posts);
     505        $result = $this->posts2wp($posts);
     506        if ( is_wp_error( $result ) )
     507            return $result;
    510508
    511509        echo '<form action="admin.php?import=textpattern&amp;step=4" method="post">';
     
    560558        echo '<p>'.__('Welcome to WordPress.  We hope (and expect!) that you will find this platform incredibly rewarding!  As a new WordPress user coming from Textpattern, there are some things that we would like to point out.  Hopefully, they will help your transition go as smoothly as possible.').'</p>';
    561559        echo '<h3>'.__('Users').'</h3>';
    562         echo '<p>'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password.  Forget it.  You didn\'t have that login in Textpattern, why should you have it here?  Instead we have taken care to import all of your users into our system.  Unfortunately there is one downside.  Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users.  <strong>Every user has the same username, but their passwords are reset to password123.</strong>  So <a href="%1$s">Login</a> and change it.'), '/wp-login.php').'</p>';
     560        echo '<p>'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password.  Forget it.  You didn&#8217;t have that login in Textpattern, why should you have it here?  Instead we have taken care to import all of your users into our system.  Unfortunately there is one downside.  Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users.  <strong>Every user has the same username, but their passwords are reset to password123.</strong>  So <a href="%1$s">Login</a> and change it.'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'</p>';
    563561        echo '<h3>'.__('Preserving Authors').'</h3>';
    564562        echo '<p>'.__('Secondly, we have attempted to preserve post authors.  If you are the only author or contributor to your blog, then you are safe.  In most cases, we are successful in this preservation endeavor.  However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'</p>';
    565563        echo '<h3>'.__('Textile').'</h3>';
    566         echo '<p>'.__('Also, since you\'re coming from Textpattern, you probably have been using Textile to format your comments and posts.  If this is the case, we recommend downloading and installing <a href="http://www.huddledmasses.org/category/development/wordpress/textile/">Textile for WordPress</a>.  Trust me... You\'ll want it.').'</p>';
     564        echo '<p>'.__('Also, since you&#8217;re coming from Textpattern, you probably have been using Textile to format your comments and posts.  If this is the case, we recommend downloading and installing <a href="http://www.huddledmasses.org/category/development/wordpress/textile/">Textile for WordPress</a>.  Trust me... You&#8217;ll want it.').'</p>';
    567565        echo '<h3>'.__('WordPress Resources').'</h3>';
    568566        echo '<p>'.__('Finally, there are numerous WordPress resources around the internet.  Some of them are:').'</p>';
     
    572570        echo '<li>'.__('<a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a>').'</li>';
    573571        echo '</ul>';
    574         echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '/wp-login.php').'</p>';
     572        echo '<p>'.sprintf(__('That&#8217;s it! What are you waiting for? Go <a href="%1$s">login</a>!'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'</p>';
    575573    }
    576574
     
    647645                break;
    648646            case 3 :
    649                 $this->import_posts();
     647                $result = $this->import_posts();
     648                if ( is_wp_error( $result ) )
     649                    echo $result->get_error_message();
    650650                break;
    651651            case 4 :
  • trunk/wp-admin/import/wordpress.php

    r6163 r6163  
    4545    function users_form($n) {
    4646        global $wpdb, $testing;
    47         $users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY ID");
     47        $users = $wpdb->get_results("SELECT user_login FROM $wpdb->users ORDER BY user_login");
    4848?><select name="userselect[<?php echo $n; ?>]">
    4949    <option value="#NONE#">- Select -</option>
     
    8686    function get_entries() {
    8787        set_magic_quotes_runtime(0);
    88         $importdata = array_map('rtrim', file($this->file)); // Read the file into an array
    8988
    9089        $this->posts = array();
    9190        $this->categories = array();
     91        $this->tags = array();
    9292        $num = 0;
    9393        $doing_entry = false;
    94         foreach ($importdata as $importline) {
    95             if ( false !== strpos($importline, '<wp:category>') ) {
    96                 preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category);
    97                 $this->categories[] = $category[1];
    98                 continue;
    99             }
    100             if ( false !== strpos($importline, '<item>') ) {
    101                 $this->posts[$num] = '';
    102                 $doing_entry = true;
    103                 continue;   
    104             }
    105             if ( false !== strpos($importline, '</item>') ) {
    106                 $num++;
    107                 $doing_entry = false;
    108                 continue;   
    109             }
    110             if ( $doing_entry ) {
    111                 $this->posts[$num] .= $importline . "\n";
    112             }
    113         }
    114 
    115         foreach ($this->posts as $post) {
    116             $post_ID = (int) $this->get_tag( $post, 'wp:post_id' );
    117             if ($post_ID) {
    118                 $this->posts_processed[$post_ID][0] = &$post;
    119                 $this->posts_processed[$post_ID][1] = 0;
    120             }
     94
     95        $fp = fopen($this->file, 'r');
     96        if ($fp) {
     97            while ( !feof($fp) ) {
     98                $importline = rtrim(fgets($fp));
     99
     100                if ( false !== strpos($importline, '<wp:category>') ) {
     101                    preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category);
     102                    $this->categories[] = $category[1];
     103                    continue;
     104                }
     105                if ( false !== strpos($importline, '<wp:tag>') ) {
     106                    preg_match('|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag);
     107                    $this->tags[] = $tag[1];
     108                    continue;
     109                }
     110                if ( false !== strpos($importline, '<item>') ) {
     111                    $this->posts[$num] = '';
     112                    $doing_entry = true;
     113                    continue;
     114                }
     115                if ( false !== strpos($importline, '</item>') ) {
     116                    $num++;
     117                    $doing_entry = false;
     118                    continue;
     119                }
     120                if ( $doing_entry ) {
     121                    $this->posts[$num] .= $importline . "\n";
     122                }
     123            }
     124
     125            foreach ($this->posts as $post) {
     126                $post_ID = (int) $this->get_tag( $post, 'wp:post_id' );
     127                if ($post_ID) {
     128                    $this->posts_processed[$post_ID][0] = &$post;
     129                    $this->posts_processed[$post_ID][1] = 0;
     130                }
     131            }
     132
     133            fclose($fp);
    121134        }
    122135    }
     
    191204        }
    192205
    193         echo '<input type="submit" value="Submit">'.'<br/>';
     206        echo '<input type="submit" value="Submit">'.'<br />';
    194207        echo '</form>';
    195208        echo '</ol>';
     
    214227        global $wpdb;
    215228
    216         $cat_names = (array) $wpdb->get_col("SELECT cat_name FROM $wpdb->categories");
     229        $cat_names = (array) get_terms('category', 'fields=names');
    217230
    218231        while ( $c = array_shift($this->categories) ) {
     
    240253    }
    241254
     255    function process_tags() {
     256        global $wpdb;
     257
     258        $tag_names = (array) get_terms('post_tag', 'fields=names');
     259
     260        while ( $c = array_shift($this->tags) ) {
     261            $tag_name = trim($this->get_tag( $c, 'wp:tag_name' ));
     262
     263            // If the category exists we leave it alone
     264            if ( in_array($tag_name, $tag_names) )
     265                continue;
     266
     267            $slug = $this->get_tag( $c, 'wp:tag_slug' );
     268            $description = $this->get_tag( $c, 'wp:tag_description' );
     269
     270            $tagarr = compact('slug', 'description');
     271
     272            $tag_ID = wp_insert_term($tag_name, 'post_tag', $tagarr);
     273        }
     274    }
     275
    242276    function process_posts() {
    243277        $i = -1;
    244278        echo '<ol>';
    245279
    246         foreach ($this->posts as $post)
    247             $this->process_post($post);
     280        foreach ($this->posts as $post) {
     281            $result = $this->process_post($post);
     282            if ( is_wp_error( $result ) )
     283                return $result;
     284        }
    248285
    249286        echo '</ol>';
     
    253290        echo '<h3>'.sprintf(__('All done.').' <a href="%s">'.__('Have fun!').'</a>', get_option('home')).'</h3>';
    254291    }
    255  
     292
    256293    function process_post($post) {
    257294        global $wpdb;
     
    260297        if ( $post_ID && !empty($this->posts_processed[$post_ID][1]) ) // Processed already
    261298            return 0;
    262      
     299
    263300        // There are only ever one of these
    264301        $post_title     = $this->get_tag( $post, 'title' );
     
    280317        $post_content = str_replace('<hr>', '<hr />', $post_content);
    281318
     319        preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags);
     320        $tags = $tags[1];
     321
     322        $tag_index = 0;
     323        foreach ($tags as $tag) {
     324            $tags[$tag_index] = $wpdb->escape($this->unhtmlentities(str_replace(array ('<![CDATA[', ']]>'), '', $tag)));
     325            $tag_index++;
     326        }
     327
    282328        preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
    283329        $categories = $categories[1];
     
    297343            $post_parent = (int) $post_parent;
    298344            if ($parent = $this->posts_processed[$post_parent]) {
    299                 if (!$parent[1]) $this->process_post($parent[0]); // If not yet, process the parent first.
     345                if (!$parent[1]) {
     346                    $result = $this->process_post($parent[0]); // If not yet, process the parent first.
     347                    if ( is_wp_error( $result ) )
     348                        return $result;
     349                }
    300350                $post_parent = $parent[1]; // New ID of the parent;
    301351            }
     
    308358            $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'post_name', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'menu_order', 'post_type');
    309359            $comment_post_ID = $post_id = wp_insert_post($postdata);
     360            if ( is_wp_error( $post_id ) )
     361                return $post_id;
    310362
    311363            // Memorize old and new ID.
    312364            if ( $post_id && $post_ID && $this->posts_processed[$post_ID] )
    313365                $this->posts_processed[$post_ID][1] = $post_id; // New ID.
    314            
     366
    315367            // Add categories.
    316368            if (count($categories) > 0) {
    317369                $post_cats = array();
    318370                foreach ($categories as $category) {
    319                     $cat_ID = (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name = '$category'");
     371                    $slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
     372                    $cat = get_term_by('slug', $slug, 'category');
     373                    $cat_ID = 0;
     374                    if ( ! empty($cat) )
     375                        $cat_ID = $cat->term_id;
    320376                    if ($cat_ID == 0) {
     377                        $category = $wpdb->escape($category);
    321378                        $cat_ID = wp_insert_category(array('cat_name' => $category));
    322379                    }
     
    324381                }
    325382                wp_set_post_categories($post_id, $post_cats);
    326             }   
     383            }
     384
     385            // Add tags.
     386            if (count($tags) > 0) {
     387                $post_tags = array();
     388                foreach ($tags as $tag) {
     389                    $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
     390                    $tag_obj = get_term_by('slug', $slug, 'post_tag');
     391                    $tag_id = 0;
     392                    if ( ! empty($tag_obj) )
     393                        $tag_id = $tag_obj->term_id;
     394                    if ( $tag_id == 0 ) {
     395                        $tag = $wpdb->escape($tag);
     396                        $tag_id = wp_insert_term($tag, 'post_tag');
     397                        $tag_id = $tag_id['term_id'];
     398                    }
     399                    $post_tags[] = $tag_id;
     400                }
     401                wp_set_post_tags($post_id, $post_tags);
     402            }
    327403        }
    328404
     
    371447        $this->get_entries();
    372448        $this->process_categories();
    373         $this->process_posts();
     449        $this->process_tags();
     450        $result = $this->process_posts();
     451        if ( is_wp_error( $result ) )
     452            return $result;
    374453    }
    375454
     
    391470            case 2:
    392471                check_admin_referer('import-wordpress');
    393                 $this->import();
     472                $result = $this->import();
     473                if ( is_wp_error( $result ) )
     474                    echo $result->get_error_message();
    394475                break;
    395476        }
  • trunk/wp-admin/index-extra.php

    r6163 r6163  
    33require_once (ABSPATH . WPINC . '/rss.php');
    44
    5 @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
     5@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
    66
    77switch ( $_GET['jax'] ) {
    88
    99case 'incominglinks' :
    10 $rss = @fetch_rss('http://feeds.technorati.com/cosmos/rss/?url='. trailingslashit(get_option('home')) .'&partner=wordpress');
     10
     11$rss_feed = apply_filters( 'dashboard_incoming_links_feed', 'http://blogsearch.google.com/blogsearch_feeds?hl=en&scoring=d&ie=utf-8&num=10&output=rss&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) );
     12$more_link = apply_filters( 'dashboard_incoming_links_link', 'http://blogsearch.google.com/blogsearch?hl=en&scoring=d&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) );
     13
     14$rss = @fetch_rss( $rss_feed );
    1115if ( isset($rss->items) && 1 < count($rss->items) ) { // Technorati returns a 1-item feed when it has no results
    1216?>
    13 <h3><?php _e('Incoming Links'); ?> <cite><a href="http://www.technorati.com/search/<?php echo trailingslashit(get_option('home')); ?>?partner=wordpress"><?php _e('More &raquo;'); ?></a></cite></h3>
     17<h3><?php _e('Incoming Links'); ?> <cite><a href="<?php echo htmlspecialchars( $more_link ); ?>"><?php _e('More &raquo;'); ?></a></cite></h3>
    1418<ul>
    1519<?php
     
    2529
    2630case 'devnews' :
    27 $rss = @fetch_rss('http://wordpress.org/development/feed/');
     31$rss = @fetch_rss(apply_filters( 'dashboard_primary_feed', 'http://wordpress.org/development/feed/' ));
    2832if ( isset($rss->items) && 0 != count($rss->items) ) {
    2933?>
    30 <h3><?php _e('WordPress Development Blog'); ?></h3>
     34<h3><?php echo apply_filters( 'dashboard_primary_title', __('WordPress Development Blog') ); ?></h3>
    3135<?php
    3236$rss->items = array_slice($rss->items, 0, 3);
     
    4448
    4549case 'planetnews' :
    46 $rss = @fetch_rss('http://planet.wordpress.org/feed/');
     50$rss = @fetch_rss(apply_filters( 'dashboard_secondary_feed', 'http://planet.wordpress.org/feed/' ));
    4751if ( isset($rss->items) && 0 != count($rss->items) ) {
    4852?>
    49 <h3><?php _e('Other WordPress News'); ?></h3>
     53<h3><?php echo apply_filters( 'dashboard_secondary_title', __('Other WordPress News') ); ?></h3>
    5054<ul>
    5155<?php
     
    6165?>
    6266</ul>
    63 <p class="readmore"><a href="http://planet.wordpress.org/"><?php _e('Read more'); ?> &raquo;</a></p>
     67<p class="readmore"><a href="<?php echo apply_filters( 'dashboard_secondary_link', 'http://planet.wordpress.org/' ); ?>"><?php _e('Read more &raquo;'); ?></a></p>
    6468<?php
    6569}
  • trunk/wp-admin/index.php

    r6163 r6163  
    11<?php
    2 require_once('admin.php'); 
     2require_once('admin.php');
    33
    44function index_js() {
    55?>
    66<script type="text/javascript">
    7 Event.observe( window, 'load', dashboard_init, false );
    8 function dashboard_init() {
    9     var update1 = new Ajax.Updater( 'incominglinks', 'index-extra.php?jax=incominglinks' );
    10     var update2 = new Ajax.Updater( 'devnews', 'index-extra.php?jax=devnews' );
    11     var update3 = new Ajax.Updater( 'planetnews', 'index-extra.php?jax=planetnews'  );
    12 }
     7    jQuery(function() {
     8        jQuery('#incominglinks').load('index-extra.php?jax=incominglinks');
     9        jQuery('#devnews').load('index-extra.php?jax=devnews');
     10        jQuery('#planetnews').load('index-extra.php?jax=planetnews');
     11    });
    1312</script>
    1413<?php
    1514}
    1615add_action( 'admin_head', 'index_js' );
    17 wp_enqueue_script('prototype');
    18 wp_enqueue_script('interface');
    1916
    20 $title = __('Dashboard');
     17wp_enqueue_script( 'jquery' );
     18
     19$title = __('Dashboard');
    2120$parent_file = 'index.php';
    2221require_once('admin-header.php');
     
    4140?>
    4241<div>
    43 <h3><?php _e('Comments'); ?> <a href="edit-comments.php" title="<?php _e('More comments...'); ?>">&raquo;</a></h3>
     42<h3><?php printf( __( 'Comments <a href="%s" title="More comments&#8230;">&raquo;</a>' ), 'edit-comments.php' ); ?></h3>
    4443
    4544<?php if ( $numcomments ) : ?>
    46 <p><strong><a href="moderation.php"><?php echo sprintf(__('Comments in moderation (%s)'), number_format($numcomments) ); ?> &raquo;</a></strong></p>
     45<p><strong><a href="moderation.php"><?php echo sprintf(__('Comments in moderation (%s) &raquo;'), number_format_i18n($numcomments) ); ?></a></strong></p>
    4746<?php endif; ?>
    4847
     
    5150if ( $comments ) {
    5251foreach ($comments as $comment) {
    53     echo '<li>' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . apply_filters('the_title', get_the_title($comment->comment_post_ID)) . '</a>');
     52    echo '<li>' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>');
    5453    edit_comment_link(__("Edit"), ' <small>(', ')</small>');
    5554    echo '</li>';
     
    6564?>
    6665<div>
    67 <h3><?php _e('Posts'); ?> <a href="edit.php" title="<?php _e('More posts...'); ?>">&raquo;</a></h3>
     66<h3><?php printf( __( 'Posts <a href="%s" title="More posts&#8230;">&raquo;</a>' ), 'edit.php' ); ?></h3>
    6867<ul>
    6968<?php
     
    102101$numposts = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
    103102$numcomms = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
    104 $numcats  = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories");
     103$numcats  = wp_count_terms('category');
     104$numtags = wp_count_terms('post_tag');
    105105
    106 $post_str = sprintf(__ngettext('%1$s <a href="%2$s" title="Posts">post</a>', '%1$s <a href="%2$s" title="Posts">posts</a>', $numposts), number_format($numposts), 'edit.php');
    107 $comm_str = sprintf(__ngettext('%1$s <a href="%2$s" title="Comments">comment</a>', '%1$s <a href="%2$s" title="Comments">comments</a>', $numcomms), number_format($numcomms), 'edit-comments.php');
    108 $cat_str  = sprintf(__ngettext('%1$s <a href="%2$s" title="Categories">category</a>', '%1$s <a href="%2$s" title="Categories">categories</a>', $numcats), number_format($numcats), 'categories.php');
     106$post_str = sprintf(__ngettext('%1$s <a href="%2$s" title="Posts">post</a>', '%1$s <a href="%2$s" title="Posts">posts</a>', $numposts), number_format_i18n($numposts), 'edit.php');
     107$comm_str = sprintf(__ngettext('%1$s <a href="%2$s" title="Comments">comment</a>', '%1$s <a href="%2$s" title="Comments">comments</a>', $numcomms), number_format_i18n($numcomms), 'edit-comments.php');
     108$cat_str  = sprintf(__ngettext('%1$s <a href="%2$s" title="Categories">category</a>', '%1$s <a href="%2$s" title="Categories">categories</a>', $numcats), number_format_i18n($numcats), 'categories.php');
     109$tag_str  = sprintf(__ngettext('%1$s tag', '%1$s tags', $numtags), number_format_i18n($numtags));
    109110?>
    110111
    111 <p><?php printf(__('There are currently %1$s and %2$s, contained within %3$s.'), $post_str, $comm_str, $cat_str); ?></p>
     112<p><?php printf(__('There are currently %1$s and %2$s, contained within %3$s and %4$s.'), $post_str, $comm_str, $cat_str, $tag_str); ?></p>
    112113</div>
    113114
  • trunk/wp-admin/install.php

    r6163 r6163  
    22define('WP_INSTALLING', true);
    33if (!file_exists('../wp-config.php')) {
     4  require_once('../wp-includes/compat.php');
    45  require_once('../wp-includes/functions.php');
    56  wp_die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can <a href='setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.", "WordPress &rsaquo; Error");
     
    78
    89require_once('../wp-config.php');
    9 require_once('./upgrade-functions.php');
     10require_once('./includes/upgrade.php');
    1011
    1112if (isset($_GET['step']))
     
    2021    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    2122    <title><?php _e('WordPress &rsaquo; Installation'); ?></title>
    22     <link rel="stylesheet" href="install.css?version=<?php bloginfo('version'); ?>" type="text/css" />
    23     <?php if ( ('rtl' == $wp_locale->text_direction) ) : ?>
    24     <link rel="stylesheet" href="install-rtl.css?version=<?php bloginfo('version'); ?>" type="text/css" />
    25     <?php endif; ?>
     23    <?php wp_admin_css( 'css/install' ); ?>
    2624</head>
    2725<body>
     
    3331switch($step) {
    3432    case 0:
     33    case 1: // in case people are directly linking to this
    3534?>
    36 <p><?php printf(__('Welcome to WordPress installation. We&#8217;re now going to go through a few steps to get you up and running with the latest in personal publishing platforms. You may want to peruse the <a href="%s">ReadMe documentation</a> at your leisure.'), '../readme.html'); ?></p>
    37 <h2 class="step"><a href="install.php?step=1"><?php _e('First Step &raquo;'); ?></a></h2>
    38 <?php
    39         break;
    40     case 1:
    41 ?>
    42 <h1><?php _e('First Step'); ?></h1>
    43 <p><?php _e("Before we begin we need a little bit of information. Don't worry, you can always change these later."); ?></p>
     35<h1><?php _e('Welcome'); ?></h1>
     36<p><?php printf(__('Welcome to the famous five minute WordPress installation process! You may want to browse the <a href="%s">ReadMe documentation</a> at your leisure.  Otherwise, just fill in the information below and you\'ll be on your way to using the most extendable and powerful personal publishing platform in the world.'), '../readme.html'); ?></p>
     37<!--<h2 class="step"><a href="install.php?step=1"><?php _e('First Step &raquo;'); ?></a></h2>-->
     38
     39<h1><?php _e('Information needed'); ?></h1>
     40<p><?php _e("Please provide the following information.  Don't worry, you can always change these settings later."); ?></p>
    4441
    4542<form id="setup" method="post" action="install.php?step=2">
    4643    <table width="100%">
    4744        <tr>
    48             <th width="33%"><?php _e('Weblog title:'); ?></th>
     45            <th width="33%"><?php _e('Blog title:'); ?></th>
    4946            <td><input name="weblog_title" type="text" id="weblog_title" size="25" /></td>
    5047        </tr>
     
    5451        </tr>
    5552        <tr>
    56             <th scope="row"  valign="top"> <?php __('Privacy:'); ?></th>
    57             <td><label><input type="checkbox" name="blog_public" value="1" checked="checked" /> <?php _e('I would like my blog to appear in search engines like Google and Technorati.'); ?></label></td>
     53            <td>&nbsp;</td>
     54            <td><label><input type="checkbox" name="blog_public" value="1" checked="checked" /> <?php _e('Allow my blog to appear in search engines like Google and Technorati.'); ?></label></td>
    5855        </tr>
    5956    </table>
    60     <p><em><?php _e('Double-check that email address before continuing.'); ?></em></p>
    61     <h2 class="step"><input type="submit" name="Submit" value="<?php _e('Continue to Second Step &raquo;'); ?>" /></h2>
     57    <p><em><?php _e('Double-check your email address before continuing.'); ?></em></p>
     58    <h2 class="step"><input type="submit" name="Submit" value="<?php _e('Install WordPress &raquo;'); ?>" /></h2>
    6259</form>
    6360
     
    7168        // check e-mail address
    7269        if (empty($admin_email)) {
    73             die(__("<strong>ERROR</strong>: please type your e-mail address"));
     70            // TODO: poka-yoke
     71            die(__("<strong>ERROR</strong>: you must provide an e-mail address"));
    7472        } else if (!is_email($admin_email)) {
    75             die(__("<strong>ERROR</strong>: the e-mail address isn't correct"));
     73            // TODO: poka-yoke
     74            die(__('<strong>ERROR</strong>: that isn\'t a valid e-mail address.  E-mail addresses look like: <code>username@example.com</code>'));
    7675        }
    7776
    78 ?>
    79 <h1><?php _e('Second Step'); ?></h1>
    80 <p><?php _e('Now we&#8217;re going to create the database tables and fill them with some default data.'); ?></p>
    81 
    82 
    83 <?php
    8477    $result = wp_install($weblog_title, 'admin', $admin_email, $public);
    8578    extract($result, EXTR_SKIP);
    8679?>
    8780
    88 <p><em><?php _e('Finished!'); ?></em></p>
     81<h1><?php _e('Success!'); ?></h1>
    8982
    90 <p><?php printf(__('Now you can <a href="%1$s">log in</a> with the <strong>username</strong> "<code>admin</code>" and <strong>password</strong> "<code>%2$s</code>".'), '../wp-login.php', $password); ?></p>
    91 <p><?php _e('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you. If you lose it, you will have to delete the tables from the database yourself, and re-install WordPress. So to review:'); ?></p>
     83<p><?php printf(__('WordPress has been installed.  Now you can <a href="%1$s">log in</a> with the <strong>username</strong> "<code>admin</code>" and <strong>password</strong> "<code>%2$s</code>".'), '../wp-login.php', $password); ?></p>
     84<p><?php _e('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.'); ?></p>
    9285
    9386<dl>
     
    9992        <dd><a href="../wp-login.php">wp-login.php</a></dd>
    10093</dl>
    101 <p><?php _e('Were you expecting more steps? Sorry to disappoint. All done! :)'); ?></p>
     94<p><?php _e('Were you expecting more steps? Sorry to disappoint. :)'); ?></p>
    10295
    10396<?php
  • trunk/wp-admin/link-add.php

    r6163 r6163  
    1414wp_enqueue_script( array('xfn', 'dbx-admin-key?pagenow=link.php') );
    1515if ( current_user_can( 'manage_categories' ) )
    16     wp_enqueue_script( 'ajaxcat' );
     16    wp_enqueue_script( 'ajaxlinkcat' );
    1717require('admin-header.php');
    1818?>
  • trunk/wp-admin/link-import.php

    r6163 r6163  
    9999                $opml = file_get_contents($opml_url);
    100100            }
    101            
     101
    102102            include_once('link-parse-opml.php');
    103103
     
    124124
    125125if ( ! $blogrolling )
    126     apply_filters( 'wp_delete_file', $opml_url); 
     126    apply_filters( 'wp_delete_file', $opml_url);
    127127    @unlink($opml_url);
    128128?>
  • trunk/wp-admin/link-manager.php

    r6163 r6163  
    7777<form id="cats" method="get" action="">
    7878<p><?php
    79 $categories = get_categories("hide_empty=1&type=link");
     79$categories = get_terms('link_category', "hide_empty=1");
    8080$select_cat = "<select name=\"cat_id\">\n";
    8181$select_cat .= '<option value="all"'  . (($cat_id == 'all') ? " selected='selected'" : '') . '>' . __('All') . "</option>\n";
    8282foreach ((array) $categories as $cat)
    83     $select_cat .= '<option value="' . $cat->cat_ID . '"' . (($cat->cat_ID == $cat_id) ? " selected='selected'" : '') . '>' . wp_specialchars(apply_filters('link_category', $cat->cat_name)) . "</option>\n";
     83    $select_cat .= '<option value="' . $cat->term_id . '"' . (($cat->term_id == $cat_id) ? " selected='selected'" : '') . '>' . sanitize_term_field('name', $cat->name, $cat->term_id, 'link_category', 'display') . "</option>\n";
    8484$select_cat .= "</select>\n";
    8585
     
    132132<?php
    133133    foreach ($links as $link) {
    134         $link->link_name = attribute_escape(apply_filters('link_title', $link->link_name));
    135         $link->link_description = wp_specialchars(apply_filters('link_description', $link->link_description));
    136         $link->link_url = clean_url($link->link_url);
     134        $link = sanitize_bookmark($link);
     135        $link->link_name = attribute_escape($link->link_name);
    137136        $link->link_category = wp_get_link_cats($link->link_id);
    138137        $short_url = str_replace('http://', '', $link->link_url);
     
    160159                    $cat_names = array();
    161160                    foreach ($link->link_category as $category) {
    162                         $cat_name = get_the_category_by_ID($category);
    163                         $cat_name = wp_specialchars(apply_filters('link_category', $cat_name));
     161                        $cat = get_term($category, 'link_category', OBJECT, 'display');
     162                        if ( is_wp_error( $cat ) )
     163                            echo $cat->get_error_message();
     164                        $cat_name = $cat->name;
    164165                        if ( $cat_id != $category )
    165166                            $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
     
    196197<div id="ajax-response"></div>
    197198
    198 <p class="submit"><input type="submit" class="button" name="deletebookmarks" id="deletebookmarks" value="<?php _e('Delete Checked Links') ?> &raquo;" onclick="return confirm('<?php echo js_escape(__("You are about to delete these links permanently.\n'Cancel' to stop, 'OK' to delete.")); ?>')" /></p>
     199<p class="submit"><input type="submit" class="button" name="deletebookmarks" id="deletebookmarks" value="<?php _e('Delete Checked Links &raquo;') ?>" onclick="return confirm('<?php echo js_escape(__("You are about to delete these links permanently.\n'Cancel' to stop, 'OK' to delete.")); ?>')" /></p>
    199200</form>
    200201
  • trunk/wp-admin/link.php

    r6163 r6163  
    9494        wp_enqueue_script( array('xfn', 'dbx-admin-key?pagenow=link.php') );
    9595        if ( current_user_can( 'manage_categories' ) )
    96             wp_enqueue_script( 'ajaxcat' );
     96            wp_enqueue_script( 'ajaxlinkcat' );
    9797        $parent_file = 'link-manager.php';
    9898        $submenu_file = 'link-manager.php';
  • trunk/wp-admin/menu.php

    r6163 r6163  
    4747$submenu['link-manager.php'][10] = array(__('Add Link'), 'manage_links', 'link-add.php');
    4848$submenu['link-manager.php'][20] = array(__('Import Links'), 'manage_links', 'link-import.php');
     49$submenu['link-manager.php'][30] = array(__('Categories'), 'manage_links', 'edit-link-categories.php');
    4950
    5051if ( current_user_can('edit_users') ) {
     
    9697// submenu in line be assigned as the new menu parent.
    9798foreach ( $menu as $id => $data ) {
    98     if ( empty($submenu[$data[2]]) ) 
     99    if ( empty($submenu[$data[2]]) )
    99100  &nb