Changeset 810

Show
Ignore:
Timestamp:
11/24/06 16:16:44 (3 years ago)
Author:
donncha
Message:

WP Merge to 4524

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/index.php

    r591 r810  
    1 <?php  
     1<?php 
    22/* Short and sweet */ 
    33define('WP_USE_THEMES', true); 
  • trunk/wp-admin/admin-ajax.php

    r753 r810  
    129129case 'add-cat' : // From Manage->Categories 
    130130        if ( !current_user_can( 'manage_categories' ) ) 
    131                 die('-1'); 
     131               die('-1'); 
    132132        if ( !$cat = wp_insert_category( $_POST ) ) 
    133133                die('0'); 
  • trunk/wp-admin/admin-db.php

    r798 r810  
    4949                if ( $user->has_cap('edit_posts') || $exclude_zeros == false ) 
    5050                        return array($user->id); 
    51                 else  
     51                else 
    5252                        return false; 
    5353        } 
     
    157157 
    158158        $cat_ID = (int) $catarr['cat_ID']; 
     159 
     160        if( $cat_ID == $catarr['category_parent'] ) 
     161                return false; 
    159162 
    160163        // First, get all of the original fields 
     
    202205                else 
    203206                        $cats = array_diff($cats, array($cat_ID)); 
    204                 wp_set_post_categories($post_id, $cats);  
     207                wp_set_post_categories($post_id, $cats); 
    205208        } 
    206209 
     
    213216                else 
    214217                        $cats = array_diff($cats, array($cat_ID)); 
    215                 wp_set_link_cats($link_id, $cats);  
    216         } 
    217          
     218                wp_set_link_cats($link_id, $cats); 
     219        } 
     220 
    218221        wp_cache_delete($cat_ID, 'category'); 
    219222        wp_cache_delete('all_category_ids', 'category'); 
     
    288291function wp_revoke_user($id) { 
    289292        $id = (int) $id; 
    290          
     293 
    291294        $user = new WP_User($id); 
    292         $user->remove_all_caps();       
     295        $user->remove_all_caps(); 
    293296} 
    294297 
     
    388391 
    389392        // Passed link category list overwrites existing category list if not empty. 
    390       if ( isset($linkdata['link_category']) && is_array($linkdata['link_category']) 
     393      if ( isset($linkdata['link_category']) && is_array($linkdata['link_category']) 
    391394                         && 0 != count($linkdata['link_category']) ) 
    392               $link_cats = $linkdata['link_category']; 
    393         else  
    394               $link_cats = $link['link_category']; 
     395              $link_cats = $linkdata['link_category']; 
     396        else 
     397              $link_cats = $link['link_category']; 
    395398 
    396399        // Merge old and new fields with new fields overwriting old ones. 
    397400        $linkdata = array_merge($link, $linkdata); 
    398       $linkdata['link_category'] = $link_cats; 
     401      $linkdata['link_category'] = $link_cats; 
    399402 
    400403        return wp_insert_link($linkdata); 
     
    405408 
    406409        do_action('delete_link', $link_id); 
    407          
     410 
    408411        $categories = wp_get_link_cats($link_id); 
    409412        if( is_array( $categories ) ) { 
     
    421424        global $wpdb; 
    422425 
    423         $sql = "SELECT category_id  
    424                 FROM $wpdb->link2cat  
    425                 WHERE link_id = $link_ID  
     426        $sql = "SELECT category_id 
     427                FROM $wpdb->link2cat 
     428                WHERE link_id = $link_ID 
    426429                ORDER BY category_id"; 
    427430 
     
    444447        // First the old categories 
    445448        $old_categories = $wpdb->get_col(" 
    446                 SELECT category_id  
    447                 FROM $wpdb->link2cat  
     449                SELECT category_id 
     450                FROM $wpdb->link2cat 
    448451                WHERE link_id = $link_ID"); 
    449452 
     
    460463                foreach ($delete_cats as $del) { 
    461464                        $wpdb->query(" 
    462                                 DELETE FROM $wpdb->link2cat  
    463                                 WHERE category_id = $del  
    464                                         AND link_id = $link_ID  
     465                                DELETE FROM $wpdb->link2cat 
     466                                WHERE category_id = $del 
     467                                        AND link_id = $link_ID 
    465468                                "); 
    466469                } 
     
    473476                foreach ($add_cats as $new_cat) { 
    474477                        $wpdb->query(" 
    475                                 INSERT INTO $wpdb->link2cat (link_id, category_id)  
     478                                INSERT INTO $wpdb->link2cat (link_id, category_id) 
    476479                                VALUES ($link_ID, $new_cat)"); 
    477480                } 
    478481        } 
    479          
     482 
    480483        // Update category counts. 
    481484        $all_affected_cats = array_unique(array_merge($link_categories, $old_categories)); 
     
    484487                $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'"); 
    485488                wp_cache_delete($cat_id, 'category'); 
    486         } 
     489                do_action('edit_category', $cat_id); 
     490        } 
     491 
     492        do_action('edit_link', $link_ID); 
    487493}       // wp_set_link_cats() 
    488494 
  • trunk/wp-admin/admin-functions.php

    r804 r810  
    33function write_post() { 
    44        $result = wp_write_post(); 
    5         if( is_wp_error($result) ) 
     5        if( is_wp_error( $result ) ) 
    66                wp_die( $result->get_error_message() ); 
    77        else 
     
    1414 
    1515        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.')); 
     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.' ) ); 
    2121        } 
    2222 
     
    2727        $_POST['to_ping'] = $_POST['trackback_url']; 
    2828 
    29         if (!empty ($_POST['post_author_override'])) { 
     29        if (!empty ( $_POST['post_author_override'] ) ) { 
    3030                $_POST['post_author'] = (int) $_POST['post_author_override']; 
    3131        } else { 
    32                 if (!empty ($_POST['post_author'])) { 
     32                if (!empty ( $_POST['post_author'] ) ) { 
    3333                        $_POST['post_author'] = (int) $_POST['post_author']; 
    3434                } else { 
     
    3838        } 
    3939 
    40         if ($_POST['post_author'] != $_POST['user_ID']) { 
     40        if ( $_POST['post_author'] != $_POST['user_ID'] ) { 
    4141                if ( 'page' == $_POST['post_type'] ) { 
    42                         if ( !current_user_can('edit_others_pages') ) 
    43                                 return new WP_Error('edit_others_pages', __('You cannot create pages as this user.')); 
     42                        if ( !current_user_can( 'edit_others_pages' ) ) 
     43                                return new WP_Error( 'edit_others_pages', __( 'You cannot create pages as this user.' ) ); 
    4444                } else { 
    45                         if ( !current_user_can('edit_others_posts') ) 
    46                                 return new WP_Error('edit_others_posts', __('You cannot post as this user.')); 
     45                        if ( !current_user_can( 'edit_others_posts' ) ) 
     46                                return new WP_Error( 'edit_others_posts', __( 'You cannot post as this user.' ) ); 
    4747 
    4848                } 
     
    5050 
    5151        // What to do based on which button they pressed 
    52         if ('' != $_POST['saveasdraft']
     52        if ('' != $_POST['saveasdraft']
    5353                $_POST['post_status'] = 'draft'; 
    54         if ('' != $_POST['saveasprivate']
     54        if ('' != $_POST['saveasprivate']
    5555                $_POST['post_status'] = 'private'; 
    56         if ('' != $_POST['publish']
     56        if ('' != $_POST['publish']
    5757                $_POST['post_status'] = 'publish'; 
    58         if ('' != $_POST['advanced']
     58        if ('' != $_POST['advanced']
    5959                $_POST['post_status'] = 'draft'; 
    6060 
    6161        if ( 'page' == $_POST['post_type'] ) { 
    62                 if ('publish' == $_POST['post_status'] && !current_user_can('publish_pages')
     62                if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' )
    6363                        $_POST['post_status'] = 'draft'; 
    6464        } else { 
    65                 if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts')
     65                if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' )
    6666                        $_POST['post_status'] = 'draft'; 
    6767        } 
    6868 
    69         if (!isset ($_POST['comment_status'])) 
     69        if (!isset( $_POST['comment_status'] )) 
    7070                $_POST['comment_status'] = 'closed'; 
    7171 
    72         if (!isset ($_POST['ping_status'])) 
     72        if (!isset( $_POST['ping_status'] )) 
    7373                $_POST['ping_status'] = 'closed'; 
    7474 
    75         if (!empty ($_POST['edit_date'])) { 
     75        if (!empty ( $_POST['edit_date'] ) ) { 
    7676                $aa = $_POST['aa']; 
    7777                $mm = $_POST['mm']; 
     
    8080                $mn = $_POST['mn']; 
    8181                $ss = $_POST['ss']; 
    82                 $jj = ($jj > 31) ? 31 : $jj; 
    83                 $hh = ($hh > 23) ? $hh -24 : $hh; 
    84                 $mn = ($mn > 59) ? $mn -60 : $mn; 
    85                 $ss = ($ss > 59) ? $ss -60 : $ss; 
    86                 $_POST['post_date'] = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss); 
    87                 $_POST['post_date_gmt'] = get_gmt_from_date($_POST['post_date']); 
     82                $jj = ($jj > 31 ) ? 31 : $jj; 
     83                $hh = ($hh > 23 ) ? $hh -24 : $hh; 
     84                $mn = ($mn > 59 ) ? $mn -60 : $mn; 
     85                $ss = ($ss > 59 ) ? $ss -60 : $ss; 
     86                $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); 
     87                $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] ); 
    8888        } 
    8989 
    9090        // Create the post. 
    91         $post_ID = wp_insert_post($_POST); 
    92         add_meta($post_ID); 
     91        $post_ID = wp_insert_post( $_POST); 
     92        add_meta( $post_ID ); 
    9393 
    9494        // Reunite any orphaned attachments with their parent 
    9595        if ( $_POST['temp_ID'] ) 
    96                 relocate_children($_POST['temp_ID'], $post_ID); 
     96                relocate_children( $_POST['temp_ID'], $post_ID ); 
    9797 
    9898        // Now that we have an ID we can fix any attachment anchor hrefs 
    99         fix_attachment_links($post_ID); 
     99        fix_attachment_links( $post_ID ); 
    100100 
    101101        return $post_ID; 
     
    103103 
    104104// Move child posts to a new parent 
    105 function relocate_children($old_ID, $new_ID) { 
     105function relocate_children( $old_ID, $new_ID ) { 
    106106        global $wpdb; 
    107107        $old_ID = (int) $old_ID; 
    108108        $new_ID = (int) $new_ID; 
    109         return $wpdb->query("UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID"); 
     109        return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID" ); 
    110110} 
    111111 
    112112// Replace hrefs of attachment anchors with up-to-date permalinks. 
    113 function fix_attachment_links($post_ID) { 
     113function fix_attachment_links( $post_ID ) { 
    114114        global $wp_rewrite; 
    115115 
    116         $post = & get_post($post_ID, ARRAY_A); 
    117  
    118         $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie"; 
     116        $post = & get_post( $post_ID, ARRAY_A ); 
     117 
     118        $search = "#<a[^>]+rel=('|\" )[^'\"]*attachment[^>]*>#ie"; 
    119119 
    120120        // See if we have any rel="attachment" links 
    121         if ( 0 == preg_match_all($search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER) ) 
     121        if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) ) 
    122122                return; 
    123123 
    124124        $i = 0; 
    125         $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i"; 
     125        $search = "#[\s]+rel=(\"|' )(.*? )wp-att-(\d+ )\\1#i"; 
    126126        foreach ( $anchor_matches[0] as $anchor ) { 
    127                 if ( 0 == preg_match($search, $anchor, $id_matches) ) 
     127                if ( 0 == preg_match( $search, $anchor, $id_matches ) ) 
    128128                        continue; 
    129129 
     
    131131 
    132132                // While we have the attachment ID, let's adopt any orphans. 
    133                 $attachment = & get_post($id, ARRAY_A); 
    134                 if ( ! empty($attachment) && ! is_object(get_post($attachment['post_parent'])) ) { 
     133                $attachment = & get_post( $id, ARRAY_A ); 
     134                if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) { 
    135135                        $attachment['post_parent'] = $post_ID; 
    136136                        // Escape data pulled from DB. 
    137                         $attachment = add_magic_quotes($attachment); 
    138                         wp_update_post($attachment); 
     137                        $attachment = add_magic_quotes( $attachment); 
     138                        wp_update_post( $attachment); 
    139139                } 
    140140 
    141141                $post_search[$i] = $anchor; 
    142                 $post_replace[$i] = preg_replace("#href=(\"|')[^'\"]*\\1#e", "stripslashes('href=\\1').get_attachment_link($id).stripslashes('\\1')", $anchor); 
     142                $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor ); 
    143143                ++$i; 
    144144        } 
    145145 
    146         $post['post_content'] = str_replace($post_search, $post_replace, $post['post_content']); 
     146        $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] ); 
    147147 
    148148        // Escape data pulled from DB. 
    149         $post = add_magic_quotes($post); 
    150  
    151         return wp_update_post($post); 
     149        $post = add_magic_quotes( $post); 
     150 
     151        return wp_update_post( $post); 
    152152} 
    153153 
     
    159159 
    160160        if ( 'page' == $_POST['post_type'] ) { 
    161                 if ( !current_user_can('edit_page', $post_ID) ) 
    162                         wp_die(__('You are not allowed to edit this page.')); 
    163         } else { 
    164                 if ( !current_user_can('edit_post', $post_ID) ) 
    165                         wp_die(__('You are not allowed to edit this post.')); 
     161                if ( !current_user_can( 'edit_page', $post_ID ) ) 
     162                        wp_die( __('You are not allowed to edit this page.' )); 
     163        } else { 
     164                if ( !current_user_can( 'edit_post', $post_ID ) ) 
     165                        wp_die( __('You are not allowed to edit this post.' )); 
    166166        } 
    167167 
     
    173173        $_POST['to_ping'] = $_POST['trackback_url']; 
    174174 
    175         if (!empty ($_POST['post_author_override'])) { 
     175        if (!empty ( $_POST['post_author_override'] ) ) { 
    176176                $_POST['post_author'] = (int) $_POST['post_author_override']; 
    177177        } else 
    178                 if (!empty ($_POST['post_author'])) { 
     178                if (!empty ( $_POST['post_author'] ) ) { 
    179179                        $_POST['post_author'] = (int) $_POST['post_author']; 
    180180                } else { 
     
    182182                } 
    183183 
    184         if ($_POST['post_author'] != $_POST['user_ID']) { 
     184        if ( $_POST['post_author'] != $_POST['user_ID'] ) { 
    185185                if ( 'page' == $_POST['post_type'] ) { 
    186                         if ( !current_user_can('edit_others_pages') ) 
    187                                 wp_die(__('You cannot edit pages as this user.')); 
     186                        if ( !current_user_can( 'edit_others_pages' ) ) 
     187                                wp_die( __('You cannot edit pages as this user.' )); 
    188188                } else { 
    189                         if ( !current_user_can('edit_others_posts') ) 
    190                                 wp_die(__('You cannot edit posts as this user.')); 
     189                        if ( !current_user_can( 'edit_others_posts' ) ) 
     190                                wp_die( __('You cannot edit posts as this user.' )); 
    191191 
    192192                } 
     
    194194 
    195195        // What to do based on which button they pressed 
    196         if ('' != $_POST['saveasdraft']
     196        if ('' != $_POST['saveasdraft']
    197197                $_POST['post_status'] = 'draft'; 
    198         if ('' != $_POST['saveasprivate']
     198        if ('' != $_POST['saveasprivate']
    199199                $_POST['post_status'] = 'private'; 
    200         if ('' != $_POST['publish']
     200        if ('' != $_POST['publish']
    201201                $_POST['post_status'] = 'publish'; 
    202         if ('' != $_POST['advanced']
     202        if ('' != $_POST['advanced']
    203203                $_POST['post_status'] = 'draft'; 
    204204 
    205205        if ( 'page' == $_POST['post_type'] ) { 
    206                 if ('publish' == $_POST['post_status'] && !current_user_can('edit_published_pages')) 
     206                if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages' )) 
    207207                        $_POST['post_status'] = 'draft'; 
    208208        } else { 
    209                 if ('publish' == $_POST['post_status'] && !current_user_can('edit_published_posts')) 
     209                if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts' )) 
    210210                        $_POST['post_status'] = 'draft'; 
    211211        } 
    212212 
    213         if (!isset ($_POST['comment_status'])) 
     213        if (!isset( $_POST['comment_status'] )) 
    214214                $_POST['comment_status'] = 'closed'; 
    215215 
    216         if (!isset ($_POST['ping_status'])) 
     216        if (!isset( $_POST['ping_status'] )) 
    217217                $_POST['ping_status'] = 'closed'; 
    218218 
    219         if (!empty ($_POST['edit_date'])) { 
     219        if (!empty ( $_POST['edit_date'] ) ) { 
    220220                $aa = $_POST['aa']; 
    221221                $mm = $_POST['mm']; 
     
    224224                $mn = $_POST['mn']; 
    225225                $ss = $_POST['ss']; 
    226                 $jj = ($jj > 31) ? 31 : $jj; 
    227                 $hh = ($hh > 23) ? $hh -24 : $hh; 
    228                 $mn = ($mn > 59) ? $mn -60 : $mn; 
    229                 $ss = ($ss > 59) ? $ss -60 : $ss; 
     226                $jj = ($jj > 31 ) ? 31 : $jj; 
     227                $hh = ($hh > 23 ) ? $hh -24 : $hh; 
     228                $mn = ($mn > 59 ) ? $mn -60 : $mn; 
     229                $ss = ($ss > 59 ) ? $ss -60 : $ss; 
    230230                $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; 
    231                 $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss"); 
     231                $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" ); 
    232232        } 
    233233 
    234234        // Meta Stuff 
    235         if ($_POST['meta']) { 
    236                 foreach ($_POST['meta'] as $key => $value
    237                         update_meta($key, $value['key'], $value['value']); 
    238         } 
    239  
    240         if ($_POST['deletemeta']) { 
    241                 foreach ($_POST['deletemeta'] as $key => $value
    242                         delete_meta($key); 
    243         } 
    244  
    245         add_meta($post_ID); 
    246  
    247         wp_update_post($_POST); 
     235        if ( $_POST['meta'] ) { 
     236                foreach ( $_POST['meta'] as $key => $value
     237                        update_meta( $key, $value['key'], $value['value'] ); 
     238        } 
     239 
     240        if ( $_POST['deletemeta'] ) { 
     241                foreach ( $_POST['deletemeta'] as $key => $value
     242                        delete_meta( $key ); 
     243        } 
     244 
     245        add_meta( $post_ID ); 
     246 
     247        wp_update_post( $_POST); 
    248248 
    249249        // Now that we have an ID we can fix any attachment anchor hrefs 
    250         fix_attachment_links($post_ID); 
     250        fix_attachment_links( $post_ID ); 
    251251 
    252252        return $post_ID; 
     
    259259        $comment_post_ID = (int) $_POST['comment_post_ID']; 
    260260 
    261         if (!current_user_can('edit_post', $comment_post_ID)) 
    262                 wp_die(__('You are not allowed to edit comments on this post, so you cannot edit this comment.')); 
     261        if (!current_user_can( 'edit_post', $comment_post_ID )) 
     262                wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' )); 
    263263 
    264264        $_POST['comment_author'] = $_POST['newcomment_author']; 
     
    269269        $_POST['comment_ID'] = (int) $_POST['comment_ID']; 
    270270 
    271         if (!empty ($_POST['edit_date'])) { 
     271        if (!empty ( $_POST['edit_date'] ) ) { 
    272272                $aa = $_POST['aa']; 
    273273                $mm = $_POST['mm']; 
     
    276276                $mn = $_POST['mn']; 
    277277                $ss = $_POST['ss']; 
    278                 $jj = ($jj > 31) ? 31 : $jj; 
    279                 $hh = ($hh > 23) ? $hh -24 : $hh; 
    280                 $mn = ($mn > 59) ? $mn -60 : $mn; 
    281                 $ss = ($ss > 59) ? $ss -60 : $ss; 
     278                $jj = ($jj > 31 ) ? 31 : $jj; 
     279                $hh = ($hh > 23 ) ? $hh -24 : $hh; 
     280                $mn = ($mn > 59 ) ? $mn -60 : $mn; 
     281                $ss = ($ss > 59 ) ? $ss -60 : $ss; 
    282282                $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; 
    283283        } 
    284284 
    285         wp_update_comment($_POST); 
     285        wp_update_comment( $_POST); 
    286286} 
    287287 
    288288// Get an existing post and format it for editing. 
    289 function get_post_to_edit($id) { 
    290  
    291         $post = get_post($id); 
    292  
    293         $post->post_content = format_to_edit($post->post_content, user_can_richedit()); 
    294         $post->post_content = apply_filters('content_edit_pre', $post->post_content); 
    295  
    296         $post->post_excerpt = format_to_edit($post->post_excerpt); 
    297         $post->post_excerpt = apply_filters('excerpt_edit_pre', $post->post_excerpt); 
    298  
    299         $post->post_title = format_to_edit($post->post_title); 
    300         $post->post_title = apply_filters('title_edit_pre', $post->post_title); 
    301  
    302         $post->post_password = format_to_edit($post->post_password); 
    303  
    304         if ($post->post_type == 'page'
    305                 $post->page_template = get_post_meta($id, '_wp_page_template', true); 
     289function get_post_to_edit( $id ) { 
     290 
     291        $post = get_post( $id ); 
     292 
     293        $post->post_content = format_to_edit( $post->post_content, user_can_richedit() ); 
     294        $post->post_content = apply_filters( 'content_edit_pre', $post->post_content); 
     295 
     296        $post->post_excerpt = format_to_edit( $post->post_excerpt); 
     297        $post->post_excerpt = apply_filters( 'excerpt_edit_pre', $post->post_excerpt); 
     298 
     299        $post->post_title = format_to_edit( $post->post_title ); 
     300        $post->post_title = apply_filters( 'title_edit_pre', $post->post_title ); 
     301 
     302        $post->post_password = format_to_edit( $post->post_password ); 
     303 
     304        if ( $post->post_type == 'page'
     305                $post->page_template = get_post_meta( $id, '_wp_page_template', true ); 
    306306 
    307307        return $post; 
     
    310310// Default post information to use when populating the "Write Post" form. 
    311311function get_default_post_to_edit() { 
    312         if ( !empty($_REQUEST['post_title']) ) 
    313                 $post_title = wp_specialchars(stripslashes($_REQUEST['post_title'])); 
    314         else if ( !empty($_REQUEST['popuptitle']) ) { 
    315                 $post_title = wp_specialchars(stripslashes($_REQUEST['popuptitle'])); 
    316                 $post_title = funky_javascript_fix($post_title); 
     312        if ( !empty( $_REQUEST['post_title'] ) ) 
     313                $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] )); 
     314        else if ( !empty( $_REQUEST['popuptitle'] ) ) { 
     315                $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] )); 
     316                $post_title = funky_javascript_fix( $post_title ); 
    317317        } else { 
    318318                $post_title = ''; 
    319319        } 
    320320 
    321         if ( !empty($_REQUEST['content']) ) 
    322                 $post_content = wp_specialchars(stripslashes($_REQUEST['content'])); 
    323         else if ( !empty($post_title) ) { 
    324                 $text       = wp_specialchars(stripslashes(urldecode($_REQUEST['text']))); 
    325                 $text       = funky_javascript_fix($text); 
    326                 $popupurl   = wp_specialchars($_REQUEST['popupurl']); 
     321        if ( !empty( $_REQUEST['content'] ) ) 
     322                $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] )); 
     323        else if ( !empty( $post_title ) ) { 
     324                $text       = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) ); 
     325                $text       = funky_javascript_fix( $text); 
     326                $popupurl   = wp_specialchars( $_REQUEST['popupurl'] ); 
    327327        $post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text"; 
    328328    } 
    329329 
    330         if ( !empty($_REQUEST['excerpt']) ) 
    331                 $post_excerpt = wp_specialchars(stripslashes($_REQUEST['excerpt'])); 
     330        if ( !empty( $_REQUEST['excerpt'] ) ) 
     331                $post_excerpt = wp_specialchars( stripslashes( $_REQUEST['excerpt'] )); 
    332332        else 
    333333                $post_excerpt = ''; 
    334334 
    335335        $post->post_status = 'draft'; 
    336         $post->comment_status = get_option('default_comment_status'); 
    337         $post->ping_status = get_option('default_ping_status'); 
    338         $post->post_pingback = get_option('default_pingback_flag'); 
    339         $post->post_category = get_option('default_category'); 
    340         $post->post_content = apply_filters('default_content', $post_content); 
    341         $post->post_title = apply_filters('default_title', $post_title); 
    342         $post->post_excerpt = apply_filters('default_excerpt', $post_excerpt); 
     336        $post->comment_status = get_option( 'default_comment_status' ); 
     337        $post->ping_status = get_option( 'default_ping_status' ); 
     338        $post->post_pingback = get_option( 'default_pingback_flag' ); 
     339        $post->post_category = get_option( 'default_category' ); 
     340        $post->post_content = apply_filters( 'default_content', $post_content); 
     341        $post->post_title = apply_filters( 'default_title', $post_title ); 
     342        $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt); 
    343343        $post->page_template = 'default'; 
    344344        $post->post_parent = 0; 
     
    348348} 
    349349 
    350 function get_comment_to_edit($id) { 
    351         $comment = get_comment($id); 
    352  
    353         $comment->comment_content = format_to_edit($comment->comment_content, user_can_richedit()); 
    354         $comment->comment_content = apply_filters('comment_edit_pre', $comment->comment_content); 
    355  
    356         $comment->comment_author = format_to_edit($comment->comment_author); 
    357         $comment->comment_author_email = format_to_edit($comment->comment_author_email); 
    358         $comment->comment_author_url = format_to_edit($comment->comment_author_url); 
     350function get_comment_to_edit( $id ) { 
     351        $comment = get_comment( $id ); 
     352 
     353        $comment->comment_content = format_to_edit( $comment->comment_content, user_can_richedit() ); 
     354        $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content); 
     355 
     356        $comment->comment_author = format_to_edit( $comment->comment_author ); 
     357        $comment->comment_author_email = format_to_edit( $comment->comment_author_email ); 
     358        $comment->comment_author_url = format_to_edit( $comment->comment_author_url ); 
    359359 
    360360        return $comment; 
    361361} 
    362362 
    363 function get_category_to_edit($id) { 
    364         $category = get_category($id); 
     363function get_category_to_edit( $id ) { 
     364        $category = get_category( $id ); 
    365365 
    366366        return $category; 
     
    370370        global $wp_roles; 
    371371        $r = ''; 
    372         foreach($wp_roles->role_names as $role => $name
     372        foreach( $wp_roles->role_names as $role => $name
    373373                if ( $default == $role ) // Make default first in list 
    374374                        $p = "\n\t<option selected='selected' value='$role'>$name</option>"; 
     
    379379 
    380380 
    381 function get_user_to_edit($user_id) { 
    382         $user = new WP_User($user_id); 
    383         $user->user_login = wp_specialchars($user->user_login, 1); 
    384         $user->user_email = wp_specialchars($user->user_email, 1); 
    385         $user->user_url = wp_specialchars($user->user_url, 1); 
    386         $user->first_name = wp_specialchars($user->first_name, 1); 
    387         $user->last_name = wp_specialchars($user->last_name, 1); 
    388         $user->display_name = wp_specialchars($user->display_name, 1); 
    389         $user->nickname = wp_specialchars($user->nickname, 1); 
    390         $user->aim = wp_specialchars($user->aim, 1); 
    391         $user->yim = wp_specialchars($user->yim, 1); 
    392         $user->jabber = wp_specialchars($user->jabber, 1); 
    393         $user->description = wp_specialchars($user->description); 
     381function get_user_to_edit( $user_id ) { 
     382        $user = new WP_User( $user_id ); 
     383        $user->user_login = wp_specialchars( $user->user_login, 1 ); 
     384        $user->user_email = wp_specialchars( $user->user_email, 1 ); 
     385        $user->user_url = wp_specialchars( $user->user_url, 1 ); 
     386        $user->first_name = wp_specialchars( $user->first_name, 1 ); 
     387        $user->last_name = wp_specialchars( $user->last_name, 1 ); 
     388        $user->display_name = wp_specialchars( $user->display_name, 1 ); 
     389        $user->nickname = wp_specialchars( $user->nickname, 1 ); 
     390        $user->aim = wp_specialchars( $user->aim, 1 ); 
     391        $user->yim = wp_specialchars( $user->yim, 1 ); 
     392        $user->jabber = wp_specialchars( $user->jabber, 1 ); 
     393        $user->description = wp_specialchars( $user->description ); 
    394394 
    395395        return $user; 
     
    401401        if ( func_num_args() ) { // The hackiest hack that ever did hack 
    402402                global $current_user, $wp_roles; 
    403                 $user_id = func_get_arg(0); 
    404  
    405                 if (isset ($_POST['role'])) { 
    406                         if($user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users')) { 
    407                                 $user = new WP_User($user_id); 
    408                                 $user->set_role($_POST['role']); 
     403                $user_id = func_get_arg( 0 ); 
     404 
     405                if ( isset( $_POST['role'] ) ) { 
     406                        if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ) ) { 
     407                                $user = new WP_User( $user_id ); 
     408                                $user->set_role( $_POST['role'] ); 
    409409                        } 
    410410                } 
    411411        } else { 
    412                 add_action('user_register', 'add_user'); // See above 
     412                add_action( 'user_register', 'add_user' ); // See above 
    413413                return edit_user(); 
    414414        } 
    415415} 
    416416 
    417 function edit_user($user_id = 0) { 
     417function edit_user( $user_id = 0 ) { 
    418418        global $current_user, $wp_roles, $wpdb; 
    419         if ($user_id != 0) { 
     419        if ( $user_id != 0 ) { 
    420420                $update = true; 
    421421                $user->ID = $user_id; 
    422                 $userdata = get_userdata($user_id); 
    423                 $user->user_login = $wpdb->escape($userdata->user_login); 
     422                $userdata = get_userdata( $user_id ); 
     423                $user->user_login = $wpdb->escape( $userdata->user_login ); 
    424424        } else { 
    425425                $update = false; 
     
    427427        } 
    428428 
    429         if (isset ($_POST['user_login'])) 
    430                 $user->user_login = wp_specialchars(trim($_POST['user_login'])); 
     429        if ( isset( $_POST['user_login'] )) 
     430                $user->user_login = wp_specialchars( trim( $_POST['user_login'] )); 
    431431 
    432432        $pass1 = $pass2 = ''; 
    433         if (isset ($_POST['pass1'])) 
     433        if ( isset( $_POST['pass1'] )) 
    434434                $pass1 = $_POST['pass1']; 
    435         if (isset ($_POST['pass2'])) 
     435        if ( isset( $_POST['pass2'] )) 
    436436                $pass2 = $_POST['pass2']; 
    437437 
    438         if (isset ($_POST['role']) && current_user_can('edit_users')) {  
    439                 if($user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users')) 
     438        if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) {  
     439                if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' )) 
    440440                        $user->role = $_POST['role']; 
    441441        } 
    442442 
    443         if (isset ($_POST['email'])) 
    444                 $user->user_email = wp_specialchars(trim($_POST['email'])); 
    445         if (isset ($_POST['url'])) { 
    446                 $user->user_url = wp_specialchars(trim($_POST['url'])); 
    447                 $user->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url; 
    448         } 
    449         if (isset ($_POST['first_name'])) 
    450                 $user->first_name = wp_specialchars(trim($_POST['first_name'])); 
    451         if (isset ($_POST['last_name'])) 
    452                 $user->last_name = wp_specialchars(trim($_POST['last_name'])); 
    453         if (isset ($_POST['nickname'])) 
    454                 $user->nickname = wp_specialchars(trim($_POST['nickname'])); 
    455         if (isset ($_POST['display_name'])) 
    456                 $user->display_name = wp_specialchars(trim($_POST['display_name'])); 
    457         if (isset ($_POST['description'])) 
    458                 $user->description = trim($_POST['description']); 
    459         if (isset ($_POST['jabber'])) 
    460                 $user->jabber = wp_specialchars(trim($_POST['jabber'])); 
    461         if (isset ($_POST['aim'])) 
    462                 $user->aim = wp_specialchars(trim($_POST['aim'])); 
    463         if (isset ($_POST['yim'])) 
    464                 $user->yim = wp_specialchars(trim($_POST['yim'])); 
     443        if ( isset( $_POST['email'] )) 
     444                $user->user_email = wp_specialchars( trim( $_POST['email'] )); 
     445        if ( isset( $_POST['url'] ) ) { 
     446                $user->user_url = wp_specialchars( trim( $_POST['url'] )); 
     447                $user->user_url = preg_match( '/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url ) ? $user->user_url : 'http://'.$user->user_url; 
     448        } 
     449        if ( isset( $_POST['first_name'] )) 
     450                $user->first_name = wp_specialchars( trim( $_POST['first_name'] )); 
     451        if ( isset( $_POST['last_name'] )) 
     452                $user->last_name = wp_specialchars( trim( $_POST['last_name'] )); 
     453        if ( isset( $_POST['nickname'] )) 
     454                $user->nickname = wp_specialchars( trim( $_POST['nickname'] )); 
     455        if ( isset( $_POST['display_name'] )) 
     456                $user->display_name = wp_specialchars( trim( $_POST['display_name'] )); 
     457        if ( isset( $_POST['description'] )) 
     458                $user->description = trim( $_POST['description'] ); 
     459        if ( isset( $_POST['jabber'] )) 
     460                $user->jabber = wp_specialchars( trim( $_POST['jabber'] )); 
     461        if ( isset( $_POST['aim'] )) 
     462                $user->aim = wp_specialchars( trim( $_POST['aim'] )); 
     463        if ( isset( $_POST['yim'] )) 
     464                $user->yim = wp_specialchars( trim( $_POST['yim'] )); 
    465465 
    466466        $errors = new WP_Error(); 
    467467 
    468468        /* checking that username has been typed */ 
    469         if ($user->user_login == ''
    470                 $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.')); 
     469        if ( $user->user_login == ''
     470                $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' )); 
    471471 
    472472        /* checking the password has been typed twice */ 
    473         do_action_ref_array('check_passwords', array ($user->user_login, & $pass1, & $pass2)); 
    474  
    475         if (!$update) { 
    476                 if ($pass1 == '' || $pass2 == ''
    477                         $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password twice.')); 
    478         } else { 
    479                 if ((empty ($pass1) && !empty ($pass2)) || (empty ($pass2) && !empty ($pass1))
    480                         $errors->add('pass', __("<strong>ERROR</strong>: you typed your new password only once.")); 
     473        do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 )); 
     474 
     475        if (!$update ) { 
     476                if ( $pass1 == '' || $pass2 == ''
     477                        $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' )); 
     478        } else { 
     479                if ((empty ( $pass1 ) && !empty ( $pass2 ) ) || (empty ( $pass2 ) && !empty ( $pass1 ) )
     480                        $errors->add( 'pass', __( "<strong>ERROR</strong>: you typed your new password only once." )); 
    481481        } 
    482482 
    483483        /* Check for "\" in password */ 
    484484        if( strpos( " ".$pass1, "\\" ) ) 
    485                 $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".')); 
     485                $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' )); 
    486486 
    487487        /* checking the password has been typed twice the same */ 
    488         if ($pass1 != $pass2
    489                 $errors->add('pass', __('<strong>ERROR</strong>: Please type the same password in the two password fields.')); 
    490  
    491         if (!empty ($pass1)) 
     488        if ( $pass1 != $pass2
     489                $errors->add( 'pass', __( '<strong>ERROR</strong>: Please type the same password in the two password fields.' )); 
     490 
     491        if (!empty ( $pass1 )) 
    492492                $user->user_pass = $pass1; 
    493493 
    494         if ( !validate_username($user->user_login) ) 
    495                 $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.')); 
    496  
    497         if (!$update && username_exists($user->user_login)) 
    498                 $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered, please choose another one.')); 
     494        if ( !validate_username( $user->user_login ) ) 
     495                $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.' )); 
     496 
     497        if (!$update && username_exists( $user->user_login )) 
     498                $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' )); 
    499499 
    500500        /* checking e-mail address */ 
    501         if (empty ($user->user_email)) { 
    502                 $errors->add('user_email', __("<strong>ERROR</strong>: please type an e-mail address")); 
     501        if ( empty ( $user->user_email ) ) { 
     502                $errors->add( 'user_email', __( "<strong>ERROR</strong>: please type an e-mail address" )); 
    503503        } else 
    504                 if (!is_email($user->user_email)) { 
    505                         $errors->add('user_email', __("<strong>ERROR</strong>: the email address isn't correct")); 
     504                if (!is_email( $user->user_email ) ) { 
     505                        $errors->add( 'user_email', __( "<strong>ERROR</strong>: the email address isn't correct" )); 
    506506                } 
    507507 
     
    509509                return $errors; 
    510510 
    511         if ($update) { 
    512                 $user_id = wp_update_user(get_object_vars($user)); 
    513         } else { 
    514                 $user_id = wp_insert_user(get_object_vars($user)); 
    515                 wp_new_user_notification($user_id); 
     511        if ( $update ) { 
     512                $user_id = wp_update_user( get_object_vars( $user )); 
     513        } else { 
     514                $user_id = wp_insert_user( get_object_vars( $user )); 
     515                wp_new_user_notification( $user_id ); 
    516516        } 
    517517        return $user_id; 
     
    519519 
    520520 
    521 function get_link_to_edit($link_id) { 
    522         $link = get_link($link_id); 
    523  
    524         $link->link_url = wp_specialchars($link->link_url, 1); 
    525         $link->link_name = wp_specialchars($link->link_name, 1); 
    526         $link->link_image = wp_specialchars($link->link_image, 1); 
    527         $link->link_description = wp_specialchars($link->link_description, 1); 
    528         $link->link_notes = wp_specialchars($link->link_notes); 
    529         $link->link_rss = wp_specialchars($link->link_rss, 1); 
    530         $link->link_rel = wp_specialchars($link->link_rel, 1); 
     521function get_link_to_edit( $link_id ) { 
     522        $link = get_link( $link_id ); 
     523 
     524        $link->link_url = wp_specialchars( $link->link_url, 1 ); 
     525        $link->link_name = wp_specialchars( $link->link_name, 1 ); 
     526        $link->link_image = wp_specialchars( $link->link_image, 1 ); 
     527        $link->link_description = wp_specialchars( $link->link_description, 1 ); 
     528        $link->link_notes = wp_specialchars( $link->link_notes ); 
     529        $link->link_rss = wp_specialchars( $link->link_rss, 1 ); 
     530        $link->link_rel = wp_specialchars( $link->link_rel, 1 ); 
    531531        $link->post_category = $link->link_category; 
    532532 
     
    535535 
    536536function get_default_link_to_edit() { 
    537         if ( isset($_GET['linkurl']) ) 
    538                 $link->link_url = wp_specialchars($_GET['linkurl'], 1); 
     537        if ( isset( $_GET['linkurl'] ) ) 
     538                $link->link_url = wp_specialchars( $_GET['linkurl'], 1 ); 
    539539        else 
    540540                $link->link_url = ''; 
    541541 
    542         if ( isset($_GET['name']) ) 
    543                 $link->link_name = wp_specialchars($_GET['name'], 1); 
     542        if ( isset( $_GET['name'] ) ) 
     543                $link->link_name = wp_specialchars( $_GET['name'], 1 ); 
    544544        else 
    545545                $link->link_name = ''; 
     
    554554} 
    555555 
    556 function edit_link($link_id = '') { 
    557         if (!current_user_can('manage_links')) 
    558                 wp_die(__("Cheatin' uh ?")); 
    559  
    560         $_POST['link_url'] = wp_specialchars($_POST['link_url']); 
    561         $_POST['link_url'] = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $_POST['link_url']) ? $_POST['link_url'] : 'http://' . $_POST['link_url']; 
    562         $_POST['link_name'] = wp_specialchars($_POST['link_name']); 
    563         $_POST['link_image'] = wp_specialchars($_POST['link_image']); 
    564         $_POST['link_rss'] = wp_specialchars($_POST['link_rss']); 
     556function edit_link( $link_id = '' ) { 
     557        if (!current_user_can( 'manage_links' )) 
     558                wp_die( __("Cheatin' uh ?" )); 
     559 
     560        $_POST['link_url'] = wp_specialchars( $_POST['link_url'] ); 
     561        $_POST['link_url'] = preg_match( '/^(https?|ftps?|mailto|news|gopher):/is', $_POST['link_url'] ) ? $_POST['link_url'] : 'http://' . $_POST['link_url']; 
     562        $_POST['link_name'] = wp_specialchars( $_POST['link_name'] ); 
     563        $_POST['link_image'] = wp_specialchars( $_POST['link_image'] ); 
     564        $_POST['link_rss'] = wp_specialchars( $_POST['link_rss'] ); 
    565565        $_POST['link_category'] = $_POST['post_category']; 
    566566 
    567         if ( !empty($link_id) ) { 
     567        if ( !empty( $link_id ) ) { 
    568568                $_POST['link_id'] = $link_id; 
    569                 return wp_update_link($_POST); 
    570         } else { 
    571                 return wp_insert_link($_POST); 
    572         } 
    573 } 
    574  
    575 function url_shorten($url) { 
    576         $short_url = str_replace('http://', '', stripslashes($url)); 
    577         $short_url = str_replace('www.', '', $short_url); 
    578         if ('/' == substr($short_url, -1)) 
    579                 $short_url = substr($short_url, 0, -1); 
    580         if (strlen($short_url) > 35
    581                 $short_url = substr($short_url, 0, 32).'...'; 
     569                return wp_update_link( $_POST); 
     570        } else { 
     571                return wp_insert_link( $_POST); 
     572        } 
     573} 
     574 
     575function url_shorten( $url ) { 
     576        $short_url = str_replace( 'http://', '', stripslashes( $url )); 
     577        $short_url = str_replace( 'www.', '', $short_url ); 
     578        if ('/' == substr( $short_url, -1 )) 
     579                $short_url = substr( $short_url, 0, -1 ); 
     580        if ( strlen( $short_url ) > 35
     581                $short_url = substr( $short_url, 0, 32 ).'...'; 
    582582        return $short_url; 
    583583} 
    584584 
    585 function selected($selected, $current) { 
    586         if ($selected == $current) 
     585function selected( $selected, $current) { 
     586        if ( $selected == $current) 
    587587                echo ' selected="selected"'; 
    588588} 
    589589 
    590 function checked($checked, $current) { 
    591         if ($checked == $current) 
     590function checked( $checked, $current) { 
     591        if ( $checked == $current) 
    592592                echo ' checked="checked"'; 
    593593} 
    594594 
    595 function return_categories_list($parent = 0) { 
     595function return_categories_list( $parent = 0 ) { 
    596596        global $wpdb; 
    597         return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC"); 
    598 } 
    599  
    600 function sort_cats($cat1, $cat2) { 
    601         return strcasecmp($cat1['cat_name'], $cat2['cat_name']); 
    602 } 
    603  
    604 function get_nested_categories($default = 0, $parent = 0) { 
     597        return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC" ); 
     598} 
     599 
     600function sort_cats( $cat1, $cat2 ) { 
     601        return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] ); 
     602} 
     603 
     604function get_nested_categories( $default = 0, $parent = 0 ) { 
    605605        global $post_ID, $link_id, $mode, $wpdb; 
    606606 
    607         if ($post_ID) { 
    608                 $checked_categories = $wpdb->get_col(
     607        if ( $post_ID ) { 
     608                $checked_categories = $wpdb->get_col(
    609609                     SELECT category_id 
    610610                     FROM $wpdb->categories, $wpdb->post2cat 
    611611                     WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' 
    612                      "); 
    613  
    614                 if (count($checked_categories) == 0) { 
     612                     " ); 
     613 
     614                if ( count( $checked_categories ) == 0 ) { 
    615615                        // No selected categories, strange 
    616616                        $checked_categories[] = $default; 
    617617                } 
    618         } else if ($link_id) { 
    619                 $checked_categories = $wpdb->get_col(
     618        } else if ( $link_id ) { 
     619                $checked_categories = $wpdb->get_col(
    620620                     SELECT category_id 
    621621                     FROM $wpdb->categories, $wpdb->link2cat 
    622622                     WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' 
    623                      "); 
    624  
    625                 if (count($checked_categories) == 0) { 
     623                     " ); 
     624 
     625                if ( count( $checked_categories ) == 0 ) { 
    626626                        // No selected categories, strange 
    627627                        $checked_categories[] = $default; 
     
    631631        } 
    632632 
    633         $cats = return_categories_list($parent); 
     633        $cats = return_categories_list( $parent); 
    634634        $result = array (); 
    635635 
    636         if (is_array($cats)) { 
    637                 foreach ($cats as $cat) { 
     636        if ( is_array( $cats ) ) { 
     637                foreach ( $cats as $cat) { 
    638638                        if ( $cat == 0 ) { // HACK, added 2006-05-13 
    639639                                $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); 
    640640                                continue; 
    641641                        } 
    642                         $result[$cat]['children'] = get_nested_categories($default, $cat); 
     642                        $result[$cat]['children'] = get_nested_categories( $default, $cat); 
    643643                        $result[$cat]['cat_ID'] = $cat; 
    644                         $result[$cat]['checked'] = in_array($cat, $checked_categories); 
    645                         $result[$cat]['cat_name'] = get_the_category_by_ID($cat); 
    646                 } 
    647         } 
    648  
    649         usort($result, 'sort_cats'); 
     644                        $result[$cat]['checked'] = in_array( $cat, $checked_categories ); 
     645                        $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); 
     646                } 
     647        } 
     648 
     649        usort( $result, 'sort_cats' ); 
    650650 
    651651        return $result; 
    652652} 
    653653 
    654 function write_nested_categories($categories) { 
    655         foreach ($categories as $category) { 
    656                 echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label></li>\n"; 
     654function write_nested_categories( $categories ) { 
     655        foreach ( $categories as $category ) { 
     656                echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( $category['cat_name'] ), "</label></li>"; 
    657657 
    658658                if ( $category['children'] ) { 
    659659                        echo "<ul>\n"; 
    660                         write_nested_categories($category['children']); 
     660                        write_nested_categories( $category['children'] ); 
    661661                        echo "</ul>\n"; 
    662662                } 
     
    664664} 
    665665 
    666 function dropdown_categories($default = 0) { 
    667         write_nested_categories(get_nested_categories($default)); 
    668 } 
    669  
    670 function return_link_categories_list($parent = 0) { 
     666function dropdown_categories( $default = 0 ) { 
     667        write_nested_categories( get_nested_categories( $default) ); 
     668} 
     669 
     670function return_link_categories_list( $parent = 0 ) { 
    671671        global $wpdb; 
    672         return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY link_count DESC"); 
     672        return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY link_count DESC" ); 
    673673} 
    674674 
     
    676676        global $post_ID, $link_id, $mode, $wpdb; 
    677677 
    678         if ($link_id) { 
    679                 $checked_categories = $wpdb->get_col(
     678        if ( $link_id ) { 
     679                $checked_categories = $wpdb->get_col(
    680680                     SELECT category_id 
    681681                     FROM $wpdb->categories, $wpdb->link2cat 
    682682                     WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' 
    683                      "); 
    684  
    685                 if (count($checked_categories) == 0) { 
     683                     " ); 
     684 
     685                if ( count( $checked_categories ) == 0 ) { 
    686686                        // No selected categories, strange 
    687687                        $checked_categories[] = $default; 
     
    691691        } 
    692692 
    693         $cats = return_link_categories_list($parent); 
     693        $cats = return_link_categories_list( $parent); 
    694694        $result = array (); 
    695695 
    696         if (is_array($cats)) { 
    697                 foreach ($cats as $cat) { 
    698                         $result[$cat]['children'] = get_nested_link_categories($default, $cat); 
     696        if ( is_array( $cats ) ) { 
     697                foreach ( $cats as $cat) { 
     698                        $result[$cat]['children'] = get_nested_link_categories( $default, $cat); 
    699699                        $result[$cat]['cat_ID'] = $cat; 
    700                         $result[$cat]['checked'] = in_array($cat, $checked_categories); 
    701                         $result[$cat]['cat_name'] = get_the_category_by_ID($cat); 
    702                 } 
    703         } 
    704  
    705         usort($result, 'sort_cats'); 
     700                        $result[$cat]['checked'] = in_array( $cat, $checked_categories ); 
     701                        $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); 
     702                } 
     703        } 
     704 
     705        usort( $result, 'sort_cats' ); 
    706706 
    707707        return $result; 
    708708} 
    709709 
    710 function dropdown_link_categories($default = 0) { 
    711         write_nested_categories(get_nested_link_categories($default)); 
     710function dropdown_link_categories( $default = 0 ) { 
     711        write_nested_categories( get_nested_link_categories( $default) ); 
    712712} 
    713713 
    714714// Dandy new recursive multiple category stuff. 
    715 function cat_rows($parent = 0, $level = 0, $categories = 0) { 
     715function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { 
    716716        global $wpdb, $class; 
    717717 
    718         if (!$categories
    719                 $categories = get_categories('hide_empty=0'); 
    720  
    721         if ($categories) { 
    722                 foreach ($categories as $category) { 
     718        if (!$categories
     719                $categories = get_categories( 'hide_empty=0' ); 
     720 
     721        if ( $categories ) { 
     722                foreach ( $categories as $category ) { 
    723723                        if ( $category->cat_ID == 0 ) { // HACK, added 2006-05-13 
    724724                                $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); 
    725725                                continue; 
    726726                        } 
    727                         if ($category->category_parent == $parent) { 
     727                        if ( $category->category_parent == $parent) { 
    728728                                echo "\t" . _cat_row( $category, $level ); 
    729                                 cat_rows($category->cat_ID, $level +1, $categories); 
     729                                cat_rows( $category->cat_ID, $level +1, $categories ); 
    730730                        } 
    731731                } 
     
    738738        global $class; 
    739739 
    740         $pad = str_repeat('&#8212; ', $level); 
    741         if ( current_user_can('manage_categories') ) { 
    742                 $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>"; 
    743                 $default_cat_id = get_option('default_category'); 
    744                 $default_link_cat_id = get_option('default_link_category'); 
    745  
    746                 if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) ) 
    747                         $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, '" . sprintf(__("You are about to delete the category &quot;%s&quot;.\\nAll of its posts will go into the default category of &quot;%s&quot;\\nAll of its bookmarks will go into the default category of &quot;%s&quot;.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), js_escape($category->cat_name), js_escape(get_catname($default_cat_id)), js_escape(get_catname($default_link_cat_id))) . "' );\" class='delete'>".__('Delete')."</a>"; 
     740        $pad = str_repeat( '&#8212; ', $level ); 
     741        if ( current_user_can( 'manage_categories' ) ) { 
     742                $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>".__( 'Edit' )."</a></td>"; 
     743                $default_cat_id = get_option( 'default_category' ); 
     744                $default_link_cat_id = get_option( 'default_link_category' ); 
     745 
     746                if ( ($category->cat_ID != $default_cat_id ) && ($category->cat_ID != $default_link_cat_id ) ) 
     747                        $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, '" . sprintf( __("You are about to delete the category &quot;%s&quot;.\\nAll of its posts will go into the default category of &quot;%s&quot;\\nAll of its bookmarks will go into the default category of &quot;%s&quot;.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop." ), js_escape( $category->cat_name ), js_escape( get_catname( $default_cat_id )), js_escape( get_catname( $default_link_cat_id ) ) ) . "' );\" class='delete'>".__( 'Delete' )."</a>"; 
    748748                else 
    749                         $edit .= "<td style='text-align:center'>".__("Default"); 
     749                        $edit .= "<td style='text-align:center'>".__( "Default" ); 
    750750        } else 
    751751                $edit = ''; 
    752752 
    753         $class = ( ( defined('DOING_AJAX') && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; 
     753        $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; 
    754754 
    755755        $category->category_count = number_format( $category->category_count ); 
     
    764764} 
    765765 
    766 function page_rows($parent = 0, $level = 0, $pages = 0, $hierarchy = true) { 
     766function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) { 
    767767        global $wpdb, $class, $post; 
    768768 
    769         if (!$pages
    770                 $pages = get_pages('sort_column=menu_order'); 
    771  
    772         if (! $pages
     769        if (!$pages
     770                $pages = get_pages( 'sort_column=menu_order' ); 
     771 
     772        if (! $pages
    773773                return false; 
    774774 
    775         foreach ($pages as $post) { 
    776                 setup_postdata($post); 
     775        foreach ( $pages as $post) { 
     776                setup_postdata( $post); 
    777777                if ( $hierarchy && ($post->post_parent != $parent) ) 
    778778                        continue; 
    779779 
    780                 $post->post_title = wp_specialchars($post->post_title); 
    781                 $pad = str_repeat('&#8212; ', $level); 
     780                $post->post_title = wp_specialchars( $post->post_title ); 
     781                $pad = str_repeat( '&#8212; ', $level ); 
    782782                $id = $post->ID; 
    783                 $class = ('alternate' == $class) ? '' : 'alternate'; 
     783                $class = ('alternate' == $class ) ? '' : 'alternate'; 
    784784?> 
    785785  <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>  
     
    787787    <td> 
    788788      <?php echo $pad; ?><?php the_title() ?> 
    789       <?php if ('private' == $post->post_status) _e(' - <strong>Private</strong>'); ?> 
    790789    </td>  
    791790    <td><?php the_author() ?></td> 
    792     <td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>  
    793         <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td> 
    794     <td><?php if ( current_user_can('edit_page', $id) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>  
    795     <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 . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), js_escape(get_the_title()) ) . "' );\">" . __('Delete') . "</a>"; } ?></td>  
     791    <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>  
     792        <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e( 'View' ); ?></a></td> 
     793    <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td>  
     794    <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 . ", '" . sprintf( __("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop." ), js_escape( get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td>  
    796795  </tr>  
    797796 
    798797<?php 
    799                 if ( $hierarchy) page_rows($id, $level + 1, $pages); 
     798                if ( $hierarchy ) page_rows( $id, $level + 1, $pages ); 
    800799        } 
    801800} 
     
    804803        global $current_user; 
    805804 
    806         if ( !(is_object($user_object) && is_a($user_object, 'WP_User')) ) 
     805        if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) ) 
    807806                $user_object = new WP_User( (int) $user_object ); 
    808807        $email = $user_object->user_email; 
    809808        $url = $user_object->user_url; 
    810         $short_url = str_replace('http://', '', $url); 
    811         $short_url = str_replace('www.', '', $short_url); 
    812         if ('/' == substr($short_url, -1)) 
    813                 $short_url = substr($short_url, 0, -1); 
    814         if (strlen($short_url) > 35
    815                 $short_url =  substr($short_url, 0, 32).'...'; 
    816         $numposts = get_usernumposts($user_object->ID); 
     809        $short_url = str_replace( 'http://', '', $url ); 
     810        $short_url = str_replace( 'www.', '', $short_url ); 
     811        if ('/' == substr( $short_url, -1 )) 
     812                $short_url = substr( $short_url, 0, -1 ); 
     813        if ( strlen( $short_url ) > 35
     814                $short_url =  substr( $short_url, 0, 32 ).'...'; 
     815        $numposts = get_usernumposts( $user_object->ID ); 
    817816        $r = "<tr id='user-$user_object->ID'$style> 
    818817                <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> 
    819818                <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td> 
    820819                <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td> 
    821                 <td><a href='mailto:$email' title='" . sprintf(__('e-mail: %s'), $email) . "'>$email</a></td> 
     820                <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td> 
    822821                <td><a href='$url' title='website: $url'>$short_url</a></td>"; 
    823822        $r .= "\n\t\t<td align='center'>"; 
    824         if ($numposts > 0) { 
    825                 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __('View posts by this author') . "' class='edit'>"; 
    826                 $r .= sprintf(__('View %1$s %2$s'), $numposts, __ngettext('post', 'posts', $numposts)); 
     823        if ( $numposts > 0 ) { 
     824                $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>"; 
     825                $r .= sprintf( __('View %1$s %2$s' ), $numposts, __ngettext( 'post', 'posts', $numposts )); 
    827826        } 
    828827        $r .= "</td>\n\t\t<td>"; 
    829         $edit_link = add_query_arg('wp_http_referer', wp_specialchars(urlencode(stripslashes($_SERVER['REQUEST_URI']))), "user-edit.php?user_id=$user_object->ID"); 
     828        $edit_link = add_query_arg( 'wp_http_referer', wp_specialchars( urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ); 
    830829        if ( ( is_site_admin() || $current_user->ID == $user_object->ID ) && current_user_can('edit_user', $user_object->ID) ) 
    831                 $r .= "<a href='$edit_link' class='edit'>".__('Edit')."</a>"; 
     830                $r .= "<a href='$edit_link' class='edit'>".__( 'Edit' )."</a>"; 
    832831        $r .= "</td>\n\t</tr>"; 
    833832        return $r; 
    834833} 
    835834 
    836 function wp_dropdown_cats($currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) { 
     835function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) { 
    837836        global $wpdb; 
    838         if (!$categories
    839                 $categories = get_categories('hide_empty=0'); 
    840  
    841         if ($categories) { 
    842                 foreach ($categories as $category) { 
    843                         if ($currentcat != $category->cat_ID && $parent == $category->category_parent) { 
    844                                 $pad = str_repeat('&#8211; ', $level); 
    845                                 $category->cat_name = wp_specialchars($category->cat_name); 
     837        if (!$categories
     838                $categories = get_categories( 'hide_empty=0' ); 
     839 
     840        if ( $categories ) { 
     841                foreach ( $categories as $category ) { 
     842                        if ( $currentcat != $category->cat_ID && $parent == $category->category_parent) { 
     843                                $pad = str_repeat( '&#8211; ', $level ); 
     844                                $category->cat_name = wp_specialchars( $category->cat_name ); 
    846845                                echo "\n\t<option value='$category->cat_ID'"; 
    847                                 if ($currentparent == $category->cat_ID
     846                                if ( $currentparent == $category->cat_ID
    848847                                        echo " selected='selected'"; 
    849848                                echo ">$pad$category->cat_name</option>"; 
    850                                 wp_dropdown_cats($currentcat, $currentparent, $category->cat_ID, $level +1, $categories); 
     849                                wp_dropdown_cats( $currentcat, $currentparent, $category->cat_ID, $level +1, $categories ); 
    851850                        } 
    852851                } 
     
    856855} 
    857856 
    858 function wp_create_thumbnail($file, $max_side, $effect = '') { 
     857function wp_create_thumbnail( $file, $max_side, $effect = '' ) { 
    859858 
    860859                // 1 = GIF, 2 = JPEG, 3 = PNG 
    861860 
    862         if (file_exists($file)) { 
    863                 $type = getimagesize($file); 
     861        if ( file_exists( $file ) ) { 
     862                $type = getimagesize( $file ); 
    864863 
    865864                // if the associated function doesn't exist - then it's not 
    866865                // handle. duh. i hope. 
    867866 
    868                 if (!function_exists('imagegif') && $type[2] == 1) { 
    869                         $error = __('Filetype not supported. Thumbnail not created.'); 
    870                 } 
    871                 elseif (!function_exists('imagejpeg') && $type[2] == 2) { 
    872                         $error = __('Filetype not supported. Thumbnail not created.'); 
    873                 } 
    874                 elseif (!function_exists('imagepng') && $type[2] == 3) { 
    875                         $error = __('Filetype not supported. Thumbnail not created.'); 
     867                if (!function_exists( 'imagegif' ) && $type[2] == 1 ) { 
     868                        $error = __( 'Filetype not supported. Thumbnail not created.' ); 
     869                } 
     870                elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) { 
     871                        $error = __( 'Filetype not supported. Thumbnail not created.' ); 
     872                } 
     873                elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) { 
     874                        $error = __( 'Filetype not supported. Thumbnail not created.' ); 
    876875                } else { 
    877876 
    878877                        // create the initial copy from the original file 
    879                         if ($type[2] == 1) { 
    880                                 $image = imagecreatefromgif($file); 
     878                        if ( $type[2] == 1 ) { 
     879                                $image = imagecreatefromgif( $file ); 
    881880                        } 
    882                         elseif ($type[2] == 2) { 
    883                                 $image = imagecreatefromjpeg($file); 
     881                        elseif ( $type[2] == 2 ) { 
     882                                $image = imagecreatefromjpeg( $file ); 
    884883                        } 
    885                         elseif ($type[2] == 3) { 
    886                                 $image = imagecreatefrompng($file); 
     884                        elseif ( $type[2] == 3 ) { 
     885                                $image = imagecreatefrompng( $file ); 
    887886                        } 
    888887 
    889                         if (function_exists('imageantialias')) 
    890                                 imageantialias($image, TRUE); 
    891  
    892                         $image_attr = getimagesize($file); 
     888                        if ( function_exists( 'imageantialias' )) 
     889                                imageantialias( $image, TRUE ); 
     890 
     891                        $image_attr = getimagesize( $file ); 
    893892 
    894893                        // figure out the longest side 
    895894 
    896                         if ($image_attr[0] > $image_attr[1]) { 
     895                        if ( $image_attr[0] > $image_attr[1] ) { 
    897896                                $image_width = $image_attr[0]; 
    898897                                $image_height = $image_attr[1]; 
     
    912911                        } 
    913912 
    914                         $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height); 
    915                         @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]); 
     913                        $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height); 
     914                        @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] ); 
    916915 
    917916                        // If no filters change the filename, we'll do a default transformation. 
    918                         if ( basename($file) == $thumb = apply_filters('thumbnail_filename', basename($file)) ) 
    919                                 $thumb = preg_replace('!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1); 
    920  
    921                         $thumbpath = str_replace(basename($file), $thumb, $file); 
     917                        if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) ) 
     918                                $thumb = preg_replace( '!(\.[^.]+)?$!', __( '.thumbnail' ).'$1', basename( $file ), 1 ); 
     919 
     920                        $thumbpath = str_replace( basename( $file ), $thumb, $file ); 
    922921 
    923922                        // move the thumbnail to it's final destination 
    924                         if ($type[2] == 1) { 
    925                                 if (!imagegif($thumbnail, $thumbpath)) { 
    926                                         $error = __("Thumbnail path invalid"); 
     923                        if ( $type[2] == 1 ) { 
     924                                if (!imagegif( $thumbnail, $thumbpath ) ) { 
     925                                        $error = __( "Thumbnail path invalid" ); 
    927926                                } 
    928927                        } 
    929                         elseif ($type[2] == 2) { 
    930                                 if (!imagejpeg($thumbnail, $thumbpath)) { 
    931                                         $error = __("Thumbnail path invalid"); 
     928                        elseif ( $type[2] == 2 ) { 
     929                                if (!imagejpeg( $thumbnail, $thumbpath ) ) { 
     930                                        $error = __( "Thumbnail path invalid" ); 
    932931                                } 
    933932                        } 
    934                         elseif ($type[2] == 3) { 
    935                                 if (!imagepng($thumbnail, $thumbpath)) { 
    936                                         $error = __("Thumbnail path invalid"); 
     933                        elseif ( $type[2] == 3 ) { 
     934                                if (!imagepng( $thumbnail, $thumbpath ) ) { 
     935                                        $error = __( "Thumbnail path invalid" ); 
    937936                                } 
    938937                        } 
     
    940939                } 
    941940        } else { 
    942                 $error = __('File not found'); 
    943         } 
    944  
    945         if (!empty ($error)) { 
     941                $error = __( 'File not found' ); 
     942        } 
     943 
     944        if (!empty ( $error ) ) { 
    946945                return $error; 
    947946        } else { 
     
    952951 
    953952// Some postmeta stuff 
    954 function has_meta($postid) { 
     953function has_meta( $postid ) { 
    955954        global $wpdb; 
    956955 
    957         return $wpdb->get_results(
     956        return $wpdb->get_results(
    958957                        SELECT meta_key, meta_value, meta_id, post_id 
    959958                        FROM $wpdb->postmeta 
    960959                        WHERE post_id = '$postid' 
    961                         ORDER BY meta_key,meta_id", ARRAY_A); 
    962  
    963 } 
    964  
    965 function list_meta($meta) { 
     960                        ORDER BY meta_key,meta_id", ARRAY_A ); 
     961 
     962} 
     963 
     964function list_meta( $meta ) { 
    966965        global $post_ID; 
    967966        // Exit if no meta 
    968         if (!$meta) { 
     967        if (!$meta ) { 
    969968                echo '<tbody id="the-list"><tr style="display: none;"><td>&nbsp;</td></tr></tbody>'; //TBODY needed for list-manipulation JS 
    970969                return; 
     
    974973        <thead> 
    975974        <tr> 
    976                 <th><?php _e('Key') ?></th> 
    977                 <th><?php _e('Value') ?></th> 
    978                 <th colspan='2'><?php _e('Action') ?></th> 
     975                <th><?php _e( 'Key' ) ?></th> 
     976                <th><?php _e( 'Value' ) ?></th> 
     977                <th colspan='2'><?php _e( 'Action' ) ?></th> 
    979978        </tr> 
    980979        </thead> 
    981980<?php 
    982981        $r ="\n\t<tbody id='the-list'>"; 
    983         foreach ($meta as $entry) { 
     982        foreach ( $meta as $entry ) { 
    984983                ++ $count; 
    985                 if ($count % 2
     984                if ( $count % 2
    986985                        $style = 'alternate'; 
    987986                else 
    988987                        $style = ''; 
    989                 if ('_' == $entry['meta_key'] { 0 }
     988                if ('_' == $entry['meta_key'] { 0 }
    990989                        $style .= ' hidden'; 
    991990 
    992                 if ( is_serialized($entry['meta_value']) ) { 
    993                         if ( is_serialized_string($entry['meta_value']) ) { 
     991                if ( is_serialized( $entry['meta_value'] ) ) { 
     992                        if ( is_serialized_string( $entry['meta_value'] ) ) { 
    994993                                // this is a serialized string, so we should display it 
    995                                 $entry['meta_value'] = maybe_unserialize($entry['meta_value']); 
     994                                $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] ); 
    996995                        } else { 
    997996                                // this is a serialized array/object so we should NOT display it 
     
    10011000                } 
    10021001 
    1003                 $key_js = js_escape($entry['meta_key']); 
     1002                $key_js = js_escape( $entry['meta_key'] ); 
    10041003                $entry['meta_key'] = wp_specialchars( $entry['meta_key'], true ); 
    10051004                $entry['meta_value'] = wp_specialchars( $entry['meta_value'], true ); 
     
    10071006                $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>"; 
    10081007                $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>"; 
    1009                 $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__('Update')."' /><br />"; 
     1008                $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__( 'Update' )."' /><br />"; 
    10101009                $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '"; 
    1011                 $r .= sprintf(__("You are about to delete the &quot;%s&quot; custom field on this post.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), $key_js); 
    1012                 $r .= "' );\" class='deletemeta' tabindex='6' value='".__('Delete')."' /></td>"; 
     1010                $r .= sprintf( __("You are about to delete the &quot;%s&quot; custom field on this post.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop." ), $key_js ); 
     1011                $r .= "' );\" class='deletemeta' tabindex='6' value='".__( 'Delete' )."' /></td>"; 
    10131012                $r .= "\n\t</tr>"; 
    10141013        } 
     
    10211020        global $wpdb; 
    10221021 
    1023         $keys = $wpdb->get_col(
     1022        $keys = $wpdb->get_col(
    10241023                        SELECT meta_key 
    10251024                        FROM $wpdb->postmeta 
    10261025                        GROUP BY meta_key 
    1027                         ORDER BY meta_key"); 
     1026                        ORDER BY meta_key" ); 
    10281027 
    10291028        return $keys; 
     
    10321031function meta_form() { 
    10331032        global $wpdb; 
    1034         $limit = (int) apply_filters('postmeta_form_limit', 30); 
    1035         $keys = $wpdb->get_col(
     1033        $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); 
     1034        $keys = $wpdb->get_col(
    10361035                SELECT meta_key 
    10371036                FROM $wpdb->postmeta 
    10381037                GROUP BY meta_key 
    10391038                ORDER BY meta_id DESC 
    1040                 LIMIT $limit"); 
    1041         natcasesort($keys); 
     1039                LIMIT $limit" ); 
     1040        natcasesort( $keys ); 
    10421041?> 
    1043 <h3><?php _e('Add a new custom field:') ?></h3> 
     1042<h3><?php _e( 'Add a new custom field:' ) ?></h3> 
    10441043<table id="newmeta" cellspacing="3" cellpadding="3"> 
    10451044        <tr> 
    1046 <th colspan="2"><?php _e('Key') ?></th> 
    1047 <th><?php _e('Value') ?></th> 
     1045<th colspan="2"><?php _e( 'Key' ) ?></th> 
     1046<th><?php _e( 'Value' ) ?></th> 
    10481047</tr> 
    10491048        <tr valign="top"> 
     
    10511050<?php if ( $keys ) : ?> 
    10521051<select id="metakeyselect" name="metakeyselect" tabindex="7"> 
    1053 <option value="#NONE#"><?php _e('- Select -'); ?></option> 
     1052<option value="#NONE#"><?php _e( '- Select -' ); ?></option> 
    10541053<?php 
    10551054 
    10561055        foreach ( $keys as $key ) { 
    1057                 $key = wp_specialchars($key, 1); 
     1056                $key = wp_specialchars( $key, 1 ); 
    10581057                echo "\n\t<option value='$key'>$key</option>"; 
    10591058        } 
    10601059?> 
    1061 </select> <?php _e('or'); ?> 
     1060</select> <?php _e( 'or' ); ?> 
    10621061<?php endif; ?> 
    10631062</td> 
     
    10671066 
    10681067</table> 
    1069 <p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field &raquo;') ?>" /></p> 
     1068<p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e( 'Add Custom Field &raquo;' ) ?>" /></p> 
    10701069<?php 
    10711070 
    10721071} 
    10731072 
    1074 function add_meta($post_ID) { 
     1073function add_meta( $post_ID ) { 
    10751074        global $wpdb; 
    10761075        $post_ID = (int) $post_ID; 
    10771076 
    1078         $metakeyselect = $wpdb->escape(stripslashes(trim($_POST['metakeyselect']))); 
    1079         $metakeyinput = $wpdb->escape(stripslashes(trim($_POST['metakeyinput']))); 
    1080         $metavalue = maybe_serialize(stripslashes((trim($_POST['metavalue'])))); 
    1081         $metavalue = $wpdb->escape($metavalue); 
    1082  
    1083         if ( ('0' === $metavalue || !empty ($metavalue)) && ((('#NONE#' != $metakeyselect) && !empty ($metakeyselect)) || !empty ($metakeyinput)) ) { 
     1077        $metakeyselect = $wpdb->escape( stripslashes( trim( $_POST['metakeyselect'] ) ) ); 
     1078        $metakeyinput = $wpdb->escape( stripslashes( trim( $_POST['metakeyinput'] ) ) ); 
     1079        $metavalue = maybe_serialize( stripslashes( (trim( $_POST['metavalue'] ) ) )); 
     1080        $metavalue = $wpdb->escape( $metavalue ); 
     1081 
     1082        if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) { 
    10841083                // We have a key/value pair. If both the select and the  
    10851084                // input for the key have data, the input takes precedence: 
     
    10881087                        $metakey = $metakeyselect; 
    10891088 
    1090                 if ($metakeyinput) 
     1089                if ( $metakeyinput) 
    10911090                        $metakey = $metakeyinput; // default 
    10921091 
    1093                 $result = $wpdb->query(
     1092                $result = $wpdb->query(
    10941093                                                INSERT INTO $wpdb->postmeta  
    1095                                                 (post_id,meta_key,meta_value)  
    1096                                                 VALUES ('$post_ID','$metakey','$metavalue'
    1097                                         "); 
     1094                                                (post_id,meta_key,meta_value )  
     1095                                                VALUES ('$post_ID','$metakey','$metavalue'
     1096                                        " ); 
    10981097                return $wpdb->insert_id; 
    10991098        } 
     
    11011100} // add_meta 
    11021101 
    1103 function delete_meta($mid) { 
     1102function delete_meta( $mid ) { 
    11041103        global $wpdb; 
    11051104        $mid = (int) $mid; 
    11061105 
    1107         return $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'"); 
    1108 } 
    1109  
    1110 function update_meta($mid, $mkey, $mvalue) { 
     1106        return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'" ); 
     1107} 
     1108 
     1109function update_meta( $mid, $mkey, $mvalue ) { 
    11111110        global $wpdb; 
    1112         $mvalue = maybe_serialize(stripslashes($mvalue)); 
    1113         $mvalue = $wpdb->escape($mvalue); 
     1111        $mvalue = maybe_serialize( stripslashes( $mvalue )); 
     1112        $mvalue = $wpdb->escape( $mvalue ); 
    11141113        $mid = (int) $mid; 
    1115         return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'"); 
    1116 } 
    1117  
    1118 function get_post_meta_by_id($mid) { 
     1114        return $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'" ); 
     1115} 
     1116 
     1117function get_post_meta_by_id( $mid ) { 
    11191118        global $wpdb; 
    11201119        $mid = (int) $mid; 
    11211120 
    1122         $meta = $wpdb->get_row("SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'"); 
    1123         if ( is_serialized_string($meta->meta_value) ) 
    1124                 $meta->meta_value = maybe_unserialize($meta->meta_value); 
     1121        $meta = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'" ); 
     1122        if ( is_serialized_string( $meta->meta_value ) ) 
     1123                $meta->meta_value = maybe_unserialize( $meta->meta_value ); 
    11251124        return $meta; 
    11261125} 
    11271126 
    1128 function touch_time($edit = 1, $for_post = 1) { 
     1127function touch_time( $edit = 1, $for_post = 1 ) { 
    11291128        global $wp_locale, $post, $comment; 
    11301129 
    11311130        if ( $for_post ) 
    1132                 $edit = ( ('draft' == $post->post_status) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date) ) ? false : true; 
     1131                $edit = ( ('draft' == $post->post_status ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true; 
    11331132  
    1134         echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__('Edit timestamp').'</label></legend>'; 
    1135  
    1136         $time_adj = time() + (get_option('gmt_offset') * 3600); 
     1133        echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>'; 
     1134 
     1135        $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 ); 
    11371136        $post_date = ($for_post) ? $post->post_date : $comment->comment_date; 
    1138         $jj = ($edit) ? mysql2date('d', $post_date) : gmdate('d', $time_adj); 
    1139         $mm = ($edit) ? mysql2date('m', $post_date) : gmdate('m', $time_adj); 
    1140         $aa = ($edit) ? mysql2date('Y', $post_date) : gmdate('Y', $time_adj); 
    1141         $hh = ($edit) ? mysql2date('H', $post_date) : gmdate('H', $time_adj); 
    1142         $mn = ($edit) ? mysql2date('i', $post_date) : gmdate('i', $time_adj); 
    1143         $ss = ($edit) ? mysql2date('s', $post_date) : gmdate('s', $time_adj); 
     1137        $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj ); 
     1138        $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj ); 
     1139        $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj ); 
     1140        $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj ); 
     1141        $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj ); 
     1142        $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj ); 
    11441143 
    11451144        echo "<select name=\"mm\" onchange=\"edit_date.checked=true\">\n"; 
    1146         for ($i = 1; $i < 13; $i = $i +1) { 
     1145        for ( $i = 1; $i < 13; $i = $i +1 ) { 
    11471146                echo "\t\t\t<option value=\"$i\""; 
    1148                 if ($i == $mm
     1147                if ( $i == $mm
    11491148                        echo ' selected="selected"'; 
    1150                 echo '>' . $wp_locale->get_month($i) . "</option>\n"; 
     1149                echo '>' . $wp_locale->get_month( $i ) . "</option>\n"; 
    11511150        } 
    11521151?> 
    11531152</select> 
    11541153<input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" onchange="edit_date.checked=true"/> 
    1155 <input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true" /> @  
    1156 <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> :  
    1157 <input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />  
    1158 <input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />  
     1154<input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true" /> @ 
     1155<input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> : 
     1156<input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> 
     1157<input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> 
    11591158<?php 
    11601159        if ( $edit ) { 
    1161                 _e('Existing timestamp'); 
    1162                 //echo ': ' . $wp_locale->get_month($mm) . "$jj, $aa @ $hh:$mn"; 
    1163                 echo sprintf(__(': %1$s %2$s, %3$s @ %4$s:%5$s'), $wp_locale->get_month($mm), $jj, $aa, $hh, $mn); 
     1160                _e( 'Existing timestamp' ); 
     1161                //echo ': ' . $wp_locale->get_month( $mm ) . "$jj, $aa @ $hh:$mn"; 
     1162                echo sprintf( __(': %1$s %2$s, %3$s @ %4$s:%5$s' ), $wp_locale->get_month( $mm ), $jj, $aa, $hh, $mn ); 
    11641163        } 
    11651164?> 
     
    11701169 
    11711170// insert_with_markers: Owen Winkler, fixed by Eric Anderson 
    1172 // Inserts an array of strings into a file (.htaccess), placing it between 
     1171// Inserts an array of strings into a file (.htaccess ), placing it between 
    11731172// BEGIN and END markers.  Replaces existing marked info.  Retains surrounding 
    11741173// data.  Creates file if none exists. 
    11751174// Returns true on write success, false on failure. 
    1176 function insert_with_markers($filename, $marker, $insertion) { 
     1175function insert_with_markers( $filename, $marker, $insertion ) { 
    11771176        return true; 
    1178         if (!file_exists($filename) || is_writeable($filename)) { 
    1179                 if (!file_exists($filename)) { 
     1177        if (!file_exists( $filename ) || is_writeable( $filename ) ) { 
     1178                if (!file_exists( $filename ) ) { 
    11801179                        $markerdata = ''; 
    11811180                } else { 
    1182                         $markerdata = explode("\n", implode('', file($filename))); 
    1183                 } 
    1184  
    1185                 $f = fopen($filename, 'w'); 
     1181                        $markerdata = explode( "\n", implode( '', file( $filename ) ) ); 
     1182                } 
     1183 
     1184                $f = fopen( $filename, 'w' ); 
    11861185                $foundit = false; 
    1187                 if ($markerdata) { 
     1186                if ( $markerdata ) { 
    11881187                        $state = true; 
    1189                         foreach ($markerdata as $n => $markerline) { 
    1190                                 if (strstr($markerline, "# BEGIN {$marker}")) 
     1188                        foreach ( $markerdata as $n => $markerline ) { 
     1189                                if ( strstr( $markerline, "# BEGIN {$marker}" )) 
    11911190                                        $state = false; 
    1192                                 if ($state) { 
    1193                                         if ( $n + 1 < count($markerdata) ) 
    1194                                                 fwrite($f, "{$markerline}\n"); 
     1191                                if ( $state ) { 
     1192                                        if ( $n + 1 < count( $markerdata ) ) 
     1193                                                fwrite( $f, "{$markerline}\n" ); 
    11951194                                        else 
    1196                                                 fwrite($f, "{$markerline}"); 
     1195                                                fwrite( $f, "{$markerline}" ); 
    11971196                                } 
    1198                                 if (strstr($markerline, "# END {$marker}")) { 
    1199                                         fwrite($f, "# BEGIN {$marker}\n"); 
    1200                                         if (is_array($insertion)) 
    1201                                                 foreach ($insertion as $insertline
    1202                                                         fwrite($f, "{$insertline}\n"); 
    1203                                         fwrite($f, "# END {$marker}\n"); 
     1197                                if ( strstr( $markerline, "# END {$marker}" ) ) { 
     1198                                        fwrite( $f, "# BEGIN {$marker}\n" ); 
     1199                                        if ( is_array( $insertion )) 
     1200                                                foreach ( $insertion as $insertline
     1201                                                        fwrite( $f, "{$insertline}\n" ); 
     1202                                        fwrite( $f, "# END {$marker}\n" ); 
    12041203                                        $state = true; 
    12051204                                        $foundit = true; 
     
    12081207                } 
    12091208                if (!$foundit) { 
    1210                         fwrite($f, "# BEGIN {$marker}\n"); 
    1211                         foreach ($insertion as $insertline
    1212                                 fwrite($f, "{$insertline}\n"); 
    1213                         fwrite($f, "# END {$marker}\n"); 
    1214                 } 
    1215                 fclose($f); 
     1209                        fwrite( $f, "# BEGIN {$marker}\n" ); 
     1210                        foreach ( $insertion as $insertline
     1211                                fwrite( $f, "{$insertline}\n" ); 
     1212                        fwrite( $f, "# END {$marker}\n" ); 
     1213                } 
     1214                fclose( $f ); 
    12161215                return true; 
    12171216        } else { 
     
    12211220 
    12221221// extract_from_markers: Owen Winkler 
    1223 // Returns an array of strings from a file (.htaccess) from between BEGIN 
     1222// Returns an array of strings from a file (.htaccess ) from between BEGIN 
    12241223// and END markers. 
    1225 function extract_from_markers($filename, $marker) { 
     1224function extract_from_markers( $filename, $marker ) { 
    12261225        $result = array (); 
    12271226 
    1228         if (!file_exists($filename)) { 
     1227        if (!file_exists( $filename ) ) { 
    12291228                return $result; 
    12301229        } 
    12311230 
    1232         if ($markerdata = explode("\n", implode('', file($filename)))); 
     1231        if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) )); 
    12331232        { 
    12341233                $state = false; 
    1235                 foreach ($markerdata as $markerline) { 
    1236                         if (strstr($markerline, "# END {$marker}")) 
     1234                foreach ( $markerdata as $markerline ) { 
     1235                        if ( strstr( $markerline, "# END {$marker}" )) 
    12371236                                $state = false; 
    1238                         if ($state
     1237                        if ( $state
    12391238                                $result[] = $markerline; 
    1240                         if (strstr($markerline, "# BEGIN {$marker}")) 
     1239                        if ( strstr( $markerline, "# BEGIN {$marker}" )) 
    12411240                                $state = true; 
    12421241                } 
     
    12531252                return false; 
    12541253 
    1255         if ( function_exists('apache_get_modules') ) { 
    1256                 if ( !in_array('mod_rewrite', apache_get_modules()) ) 
     1254        if ( function_exists( 'apache_get_modules' ) ) { 
     1255                if ( !in_array( 'mod_rewrite', apache_get_modules() ) ) 
    12571256                        return false; 
    12581257        } 
     
    12651264        $home_path = get_home_path(); 
    12661265 
    1267         if (!$wp_rewrite->using_mod_rewrite_permalinks()
     1266        if (!$wp_rewrite->using_mod_rewrite_permalinks()
    12681267                return; 
    12691268 
    1270         if (!((!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess'))
     1269        if (!((!file_exists( $home_path.'.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path.'.htaccess' ) )
    12711270                return; 
    12721271 
    1273         if (! got_mod_rewrite()
     1272        if (! got_mod_rewrite()
    12741273                return; 
    12751274 
    1276         $rules = explode("\n", $wp_rewrite->mod_rewrite_rules()); 
    1277         insert_with_markers($home_path.'.htaccess', 'WordPress', $rules); 
     1275        $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); 
     1276        insert_with_markers( $home_path.'.htaccess', 'WordPress', $rules ); 
    12781277} 
    12791278 
     
    12911290        $page_templates = array (); 
    12921291 
    1293         if (is_array($templates)) { 
    1294                 foreach ($templates as $template) { 
    1295                         $template_data = implode('', file(ABSPATH.$template)); 
    1296                         preg_match("|Template Name:(.*)|i", $template_data, $name); 
    1297                         preg_match("|Description:(.*)|i", $template_data, $description); 
     1292        if ( is_array( $templates ) ) { 
     1293                foreach ( $templates as $template ) { 
     1294                        $template_data = implode( '', file( ABSPATH.$template )); 
     1295                        preg_match( "|Template Name:(.* )|i", $template_data, $name ); 
     1296                        preg_match( "|Description:(.* )|i", $template_data, $description ); 
    12981297 
    12991298                        $name = $name[1]; 
    13001299                        $description = $description[1]; 
    13011300 
    1302                         if (!empty ($name)) { 
    1303                                 $page_templates[trim($name)] = basename($template); 
     1301                        if (!empty ( $name ) ) { 
     1302                                $page_templates[trim( $name )] = basename( $template ); 
    13041303                        } 
    13051304                } 
     
    13091308} 
    13101309 
    1311 function page_template_dropdown($default = '') { 
     1310function page_template_dropdown( $default = '' ) { 
    13121311        $templates = get_page_templates(); 
    1313         foreach (array_keys($templates) as $template
    1314                 : if ($default == $templates[$template]
     1312        foreach (array_keys( $templates ) as $template
     1313                : if ( $default == $templates[$template]
    13151314                        $selected = " selected='selected'"; 
    13161315                else 
     
    13201319} 
    13211320 
    1322 function parent_dropdown($default = 0, $parent = 0, $level = 0) { 
     1321function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { 
    13231322        global $wpdb, $post_ID; 
    1324         $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"); 
    1325  
    1326         if ($items) { 
    1327                 foreach ($items as $item) { 
     1323        $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" ); 
     1324 
     1325        if ( $items ) { 
     1326                foreach ( $items as $item ) { 
    13281327                        // A page cannot be it's own parent. 
    1329                         if (!empty ($post_ID)) { 
    1330                                 if ($item->ID == $post_ID) { 
     1328                        if (!empty ( $post_ID ) ) { 
     1329                                if ( $item->ID == $post_ID ) { 
    13311330                                        continue; 
    13321331                                } 
    13331332                        } 
    1334                         $pad = str_repeat('&nbsp;', $level * 3); 
    1335                         if ($item->ID == $default) 
     1333                        $pad = str_repeat( '&nbsp;', $level * 3 ); 
     1334                        if ( $item->ID == $default) 
    13361335                                $current = ' selected="selected"'; 
    13371336                        else 
     
    13391338 
    13401339                        echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</option>"; 
    1341                         parent_dropdown($default, $item->ID, $level +1); 
     1340                        parent_dropdown( $default, $item->ID, $level +1 ); 
    13421341                } 
    13431342        } else { 
     
    13551354 
    13561355        $parent = get_admin_page_parent(); 
    1357         /*echo "pa: $parent pn: $pagenow pp: $plugin_page<br/>"; 
    1358         echo "<pre>"; 
    1359         print_r($_wp_menu_nopriv); 
    1360         print_r($_wp_submenu_nopriv); 
    1361         echo "</pre>";*/ 
    1362         if ( isset($_wp_submenu_nopriv[$parent][$pagenow]) ) 
     1356 
     1357        if ( isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) 
    13631358                return false; 
    13641359 
    1365         if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$parent][$plugin_page]) ) 
     1360        if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) ) 
    13661361                return false; 
    13671362         
    1368         if ( empty($parent) ) { 
    1369                 if ( isset($_wp_menu_nopriv[$pagenow]) ) 
     1363        if ( empty( $parent) ) { 
     1364                if ( isset( $_wp_menu_nopriv[$pagenow] ) ) 
    13701365                        return false; 
    1371                 if ( isset($_wp_submenu_nopriv[$pagenow][$pagenow]) ) 
     1366                if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) 
    13721367                        return false; 
    1373                 if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page]) ) 
     1368                if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) 
    13741369                        return false; 
    1375                 foreach (array_keys($_wp_submenu_nopriv) as $key) { 
    1376                         if ( isset($_wp_submenu_nopriv[$key][$pagenow]) ) 
     1370                foreach (array_keys( $_wp_submenu_nopriv ) as $key ) { 
     1371                        if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) 
    13771372                                return false; 
    1378                         if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$key][$plugin_page]) ) 
     1373                        if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) 
    13791374                        return false;    
    13801375                } 
     
    13821377        } 
    13831378 
    1384         if (isset ($submenu[$parent])) { 
    1385                 foreach ($submenu[$parent] as $submenu_array) { 
    1386                         if ($submenu_array[2] == $pagenow) { 
    1387                                 if (current_user_can($submenu_array[1])) 
     1379        if ( isset( $submenu[$parent] ) ) { 
     1380                foreach ( $submenu[$parent] as $submenu_array ) { 
     1381                        if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { 
     1382                                if ( current_user_can( $submenu_array[1] )) 
     1383                                        return true; 
     1384                                else 
     1385                                        return false; 
     1386                        } else if ( $submenu_array[2] == $pagenow ) { 
     1387                                if ( current_user_can( $submenu_array[1] )) 
    13881388                                        return true; 
    13891389                                else 
     
    13931393        } 
    13941394 
    1395         foreach ($menu as $menu_array) { 
    1396                 if ($menu_array[2] == $parent) { 
    1397                         if (current_user_can($menu_array[1])) 
     1395        foreach ( $menu as $menu_array ) { 
     1396                if ( $menu_array[2] == $parent) { 
     1397                        if ( current_user_can( $menu_array[1] )) 
    13981398                                return true; 
    13991399                        else 
     
    14011401                } 
    14021402        } 
    1403          
     1403 
    14041404        return true; 
    14051405} 
     
    14121412        global $plugin_page; 
    14131413 
    1414         if (isset ($title) && !empty ($title)) { 
     1414        if ( isset( $title ) && !empty ( $title ) ) { 
    14151415                return $title; 
    14161416        } 
    14171417 
    1418         $hook = get_plugin_page_hook($plugin_page, $pagenow); 
     1418        $hook = get_plugin_page_hook( $plugin_page, $pagenow ); 
    14191419 
    14201420        $parent = $parent1 = get_admin_page_parent(); 
    1421         if (empty ($parent)) { 
    1422                 foreach ($menu as $menu_array) { 
    1423                         if (isset ($menu_array[3])) { 
    1424                                 if ($menu_array[2] == $pagenow) { 
     1421        if ( empty ( $parent) ) { 
     1422                foreach ( $menu as $menu_array ) { 
     1423                        if ( isset( $menu_array[3] ) ) { 
     1424                                if ( $menu_array[2] == $pagenow ) { 
    14251425                                        $title = $menu_array[3]; 
    14261426                                        return $menu_array[3]; 
    14271427                                } else 
    1428                                         if (isset ($plugin_page) && ($plugin_page == $menu_array[2]) && ($hook == $menu_array[3])) { 
     1428                                        if ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) { 
    14291429                                                $title = $menu_array[3]; 
    14301430                                                return $menu_array[3]; 
    14311431                                        } 
     1432                        } else { 
     1433                                $title = $menu_array[0]; 
     1434                                return $title; 
    14321435                        } 
    14331436                } 
    14341437        } else { 
    1435                 foreach (array_keys($submenu) as $parent) { 
    1436                         foreach ($submenu[$parent] as $submenu_array) { 
    1437                                 if (isset ($submenu_array[3])) { 
    1438                                         if ($submenu_array[2] == $pagenow) { 
     1438                foreach (array_keys( $submenu ) as $parent) { 
     1439                        foreach ( $submenu[$parent] as $submenu_array ) { 
     1440                                if ( isset( $plugin_page ) &&  
     1441                                        ($plugin_page == $submenu_array[2] ) &&  
     1442                                        (($parent == $pagenow ) || ($parent == $plugin_page ) || ($plugin_page == $hook ) || (($pagenow == 'admin.php' ) && ($parent1 != $submenu_array[2] ) ) ) 
     1443                                        ) { 
    14391444                                                $title = $submenu_array[3]; 
    14401445                                                return $submenu_array[3]; 
    1441                                         } else 
    1442                                                 if (isset ($plugin_page) && ($plugin_page == $submenu_array[2]) && (($parent == $pagenow) || ($parent == $plugin_page) || ($plugin_page == $hook) || (($pagenow == 'admin.php') && ($parent1 != $submenu_array[2])))) { 
    1443                                                         $title = $submenu_array[3]; 
    1444                                                         return $submenu_array[3]; 
    1445                                                 } 
     1446                                        } 
     1447 
     1448                                if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page 
     1449                                        continue; 
     1450 
     1451                                if ( isset( $submenu_array[3] ) ) { 
     1452                                        $title = $submenu_array[3]; 
     1453                                        return $submenu_array[3]; 
     1454                                } else { 
     1455                                        $title = $submenu_array[0]; 
     1456                                        return $title; 
    14461457                                } 
    14471458                        } 
     
    14491460        } 
    14501461 
    1451         return ''
     1462        return $title
    14521463} 
    14531464 
     
    14621473        global $_wp_submenu_nopriv; 
    14631474 
    1464         if ( !empty ($parent_file) ) { 
    1465                 if ( isset($_wp_real_parent_file[$parent_file]) ) 
     1475        if ( !empty ( $parent_file ) ) { 
     1476                if ( isset( $_wp_real_parent_file[$parent_file] ) ) 
    14661477                        $parent_file = $_wp_real_parent_file[$parent_file]; 
    14671478 
     
    14691480        } 
    14701481 
    1471         if ($pagenow == 'admin.php' && isset ($plugin_page)) { 
    1472                 foreach ($menu as $parent_menu) { 
    1473                         if ($parent_menu[2] == $plugin_page) { 
     1482        if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) { 
     1483                foreach ( $menu as $parent_menu ) { 
     1484                        if ( $parent_menu[2] == $plugin_page ) { 
    14741485                                $parent_file = $plugin_page; 
    1475                                 if ( isset($_wp_real_parent_file[$parent_file]) ) 
     1486                                if ( isset( $_wp_real_parent_file[$parent_file] ) ) 
    14761487                                        $parent_file = $_wp_real_parent_file[$parent_file]; 
    14771488                                return $parent_file; 
    14781489                        } 
    14791490                } 
    1480                 if ( isset($_wp_menu_nopriv[$plugin_page]) ) { 
     1491                if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) { 
    14811492                        $parent_file = $plugin_page; 
    1482                         if ( isset($_wp_real_parent_file[$parent_file]) ) 
     1493                        if ( isset( $_wp_real_parent_file[$parent_file] ) ) 
    14831494                                        $parent_file = $_wp_real_parent_file[$parent_file]; 
    14841495                        return $parent_file; 
     
    14861497        } 
    14871498 
    1488         if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page]) ) { 
     1499        if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) { 
    14891500                $parent_file = $pagenow; 
    1490                 if ( isset($_wp_real_parent_file[$parent_file]) ) 
     1501                if ( isset( $_wp_real_parent_file[$parent_file] ) ) 
    14911502                        $parent_file = $_wp_real_parent_file[$parent_file]; 
    14921503                return $parent_file;             
    14931504        } 
    14941505 
    1495         foreach (array_keys($submenu) as $parent) { 
    1496                 foreach ($submenu[$parent] as $submenu_array) { 
    1497                         if ( isset($_wp_real_parent_file[$parent]) ) 
     1506        foreach (array_keys( $submenu ) as $parent) { 
     1507                foreach ( $submenu[$parent] as $submenu_array ) { 
     1508                        if ( isset( $_wp_real_parent_file[$parent] ) ) 
    14981509                                $parent = $_wp_real_parent_file[$parent]; 
    1499                         if ($submenu_array[2] == $pagenow) { 
     1510                        if ( $submenu_array[2] == $pagenow ) { 
    15001511                                $parent_file = $parent; 
    15011512                                return $parent; 
    15021513                        } else 
    1503                                 if (isset ($plugin_page) && ($plugin_page == $submenu_array[2])) { 
     1514                                if ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) { 
    15041515                                        $parent_file = $parent; 
    15051516                                        return $parent; 
     
    15121523} 
    15131524 
    1514 function add_menu_page($page_title, $menu_title, $access_level, $file, $function = '') { 
     1525function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { 
    15151526        global $menu, $admin_page_hooks; 
    15161527 
    1517         $file = plugin_basename($file); 
    1518  
    1519         $menu[] = array ($menu_title, $access_level, $file, $page_title); 
    1520  
    1521         $admin_page_hooks[$file] = sanitize_title($menu_title); 
    1522  
    1523         $hookname = get_plugin_page_hookname($file, ''); 
    1524         if (!empty ($function) && !empty ($hookname)) 
    1525                 add_action($hookname, $function); 
     1528        $file = plugin_basename( $file ); 
     1529 
     1530        $menu[] = array ( $menu_title, $access_level, $file, $page_title ); 
     1531 
     1532        $admin_page_hooks[$file] = sanitize_title( $menu_title ); 
     1533 
     1534        $hookname = get_plugin_page_hookname( $file, '' ); 
     1535        if (!empty ( $function ) && !empty ( $hookname )) 
     1536                add_action( $hookname, $function ); 
    15261537 
    15271538        return $hookname; 
    15281539} 
    15291540 
    1530 function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '') { 
     1541function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) { 
    15311542        global $submenu; 
    15321543        global $menu; 
     
    15351546        global $_wp_menu_nopriv; 
    15361547 
    1537         $file = plugin_basename($file); 
    1538  
    1539         $parent = plugin_basename($parent); 
    1540         if ( isset($_wp_real_parent_file[$parent]) ) 
     1548        $file = plugin_basename( $file ); 
     1549 
     1550        $parent = plugin_basename( $parent); 
     1551        if ( isset( $_wp_real_parent_file[$parent] ) ) 
    15411552                $parent = $_wp_real_parent_file[$parent]; 
    15421553 
    1543         if ( !current_user_can($access_level) ) { 
     1554        if ( !current_user_can( $access_level ) ) { 
    15441555                $_wp_submenu_nopriv[$parent][$file] = true; 
    15451556                return false; 
     
    15501561        // parent file someone is trying to link back to the parent manually.  In 
    15511562        // this case, don't automatically add a link back to avoid duplication. 
    1552         if (!isset ($submenu[$parent]) && $file != $parent  ) { 
    1553                 foreach ($menu as $parent_menu) { 
    1554                         if ( $parent_menu[2] == $parent && current_user_can($parent_menu[1]) ) { 
     1563        if (!isset( $submenu[$parent] ) && $file != $parent  ) { 
     1564                foreach ( $menu as $parent_menu ) { 
     1565                        if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1] ) ) 
    15551566                                $submenu[$parent][] = $parent_menu; 
    1556                         } 
    1557                 } 
    1558         } 
    1559  
    1560         $submenu[$parent][] = array ($menu_title, $access_level, $file, $page_title); 
    1561  
    1562         $hookname = get_plugin_page_hookname($file, $parent); 
    1563         if (!empty ($function) && !empty ($hookname)) 
    1564                 add_action($hookname, $function); 
     1567                } 
     1568        } 
     1569 
     1570        $submenu[$parent][] = array ( $menu_title, $access_level, $file, $page_title ); 
     1571 
     1572        $hookname = get_plugin_page_hookname( $file, $parent); 
     1573        if (!empty ( $function ) && !empty ( $hookname )) 
     1574                add_action( $hookname, $function ); 
    15651575 
    15661576        return $hookname; 
    15671577} 
    15681578 
    1569 function add_options_page($page_title, $menu_title, $access_level, $file, $function = '') { 
    1570         return add_submenu_page('options-general.php', $page_title, $menu_title, $access_level, $file, $function); 
    1571 } 
    1572  
    1573 function add_management_page($page_title, $menu_title, $access_level, $file, $function = '') { 
    1574         return add_submenu_page('edit.php', $page_title, $menu_title, $access_level, $file, $function); 
    1575 } 
    1576  
    1577 function add_theme_page($page_title, $menu_title, $access_level, $file, $function = '') { 
    1578         return add_submenu_page('themes.php', $page_title, $menu_title, $access_level, $file, $function); 
    1579 } 
    1580  
    1581 function validate_file($file, $allowed_files = '') { 
    1582         if (false !== strpos($file, './')) 
     1579function add_options_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { 
     1580        return add_submenu_page( 'options-general.php', $page_title, $menu_title, $access_level, $file, $function ); 
     1581} 
     1582 
     1583function add_management_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { 
     1584        return add_submenu_page( 'edit.php', $page_title, $menu_title, $access_level, $file, $function ); 
     1585} 
     1586 
     1587function add_theme_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { 
     1588        return add_submenu_page( 'themes.php', $page_title, $menu_title, $access_level, $file, $function ); 
     1589} 
     1590 
     1591function validate_file( $file, $allowed_files = '' ) { 
     1592        if ( false !== strpos( $file, './' )) 
    15831593                return 1; 
    15841594 
    1585         if (':' == substr($file, 1, 1)) 
     1595        if (':' == substr( $file, 1, 1 )) 
    15861596                return 2; 
    15871597 
    1588         if (!empty ($allowed_files) && (!in_array($file, $allowed_files))
     1598        if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) )
    15891599                return 3; 
    15901600 
     
    15921602} 
    15931603 
    1594 function validate_file_to_edit($file, $allowed_files = '') { 
    1595         $file = stripslashes($file); 
    1596  
    1597         $code = validate_file($file, $allowed_files); 
    1598  
    1599         if (!$code
     1604function validate_file_to_edit( $file, $allowed_files = '' ) { 
     1605        $file = stripslashes( $file ); 
     1606 
     1607        $code = validate_file( $file, $allowed_files ); 
     1608 
     1609        if (!$code
    16001610                return $file; 
    16011611 
    1602         switch ($code) { 
     1612        switch ( $code ) { 
    16031613                case 1 : 
    1604                         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.')); 
     1614                        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.' )); 
    16051615 
    16061616                case 2 : 
    1607                         wp_die(__('Sorry, can&#8217;t call files with their real path.')); 
     1617                        wp_die( __('Sorry, can&#8217;t call files with their real path.' )); 
    16081618 
    16091619                case 3 : 
    1610                         wp_die(__('Sorry, that file cannot be edited.')); 
     1620                        wp_die( __('Sorry, that file cannot be edited.' )); 
    16111621        } 
    16121622} 
    16131623 
    16141624function get_home_path() { 
    1615         $home = get_option('home'); 
    1616         if ($home != '' && $home != get_option('siteurl')) { 
    1617                 $home_path = parse_url($home); 
     1625        $home = get_option( 'home' ); 
     1626        if ( $home != '' && $home != get_option( 'siteurl' ) ) { 
     1627                $home_path = parse_url( $home ); 
    16181628                $home_path = $home_path['path']; 
    1619                 $root = str_replace($_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"]); 
    1620                 $home_path = trailingslashit($root.$home_path); 
     1629                $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] ); 
     1630                $home_path = trailingslashit( $root.$home_path ); 
    16211631        } else { 
    16221632                $home_path = ABSPATH; 
     
    16261636} 
    16271637 
    1628 function get_real_file_to_edit($file) { 
    1629         if ('index.php' == $file || '.htaccess' == $file) { 
     1638function get_real_file_to_edit( $file ) { 
     1639        if ('index.php' == $file || '.htaccess' == $file ) { 
    16301640                $real_file = get_home_path().$file; 
    16311641        } else { 
     
    16361646} 
    16371647 
    1638 $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)'), 
     1648$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 )' ), 
    16391649        // Deprecated files 
    1640         'wp-layout.css' => __('Stylesheet'), 'wp-comments.php' => __('Comments Template'), 'wp-comments-popup.php' => __('Popup Comments Template')); 
    1641  
    1642 function get_file_description($file) { 
     1650        'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' )); 
     1651 
     1652function get_file_description( $file ) { 
    16431653        global $wp_file_descriptions; 
    16441654 
    1645         if (isset ($wp_file_descriptions[basename($file)])) { 
    1646                 return $wp_file_descriptions[basename($file)]; 
     1655        if ( isset( $wp_file_descriptions[basename( $file )] ) ) { 
     1656                return $wp_file_descriptions[basename( $file )]; 
    16471657        } 
    16481658        elseif ( file_exists( ABSPATH . $file ) && is_file( ABSPATH . $file ) ) { 
    1649                 $template_data = implode('', file( ABSPATH . $file )); 
    1650                 if (preg_match("|Template Name:(.*)|i", $template_data, $name)) 
     1659                $template_data = implode( '', file( ABSPATH . $file ) ); 
     1660                if ( preg_match( "|Template Name:(.* )|i", $template_data, $name )) 
    16511661                        return $name[1]; 
    16521662        } 
    16531663 
    1654         return basename($file); 
    1655 } 
    1656  
    1657 function update_recently_edited($file) { 
    1658         $oldfiles = (array) get_option('recently_edited'); 
    1659         if ($oldfiles) { 
    1660                 $oldfiles = array_reverse($oldfiles); 
     1664        return basename( $file ); 
     1665} 
     1666 
     1667function update_recently_edited( $file ) { 
     1668        $oldfiles = (array ) get_option( 'recently_edited' ); 
     1669        if ( $oldfiles ) { 
     1670                $oldfiles = array_reverse( $oldfiles ); 
    16611671                $oldfiles[] = $file; 
    1662                 $oldfiles = array_reverse($oldfiles); 
    1663                 $oldfiles = array_unique($oldfiles); 
    1664                 if (5 < count($oldfiles)) 
    1665                         array_pop($oldfiles); 
     1672                $oldfiles = array_reverse( $oldfiles ); 
     1673                $oldfiles = array_unique( $oldfiles ); 
     1674                if ( 5 < count( $oldfiles )) 
     1675                        array_pop( $oldfiles ); 
    16661676        } else { 
    16671677                $oldfiles[] = $file; 
    16681678        } 
    1669         update_option('recently_edited', $oldfiles); 
    1670 } 
    1671  
    1672 function get_plugin_data($plugin_file) { 
    1673         $plugin_data = implode('', file($plugin_file)); 
    1674         preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name); 
    1675         preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri); 
    1676         preg_match("|Description:(.*)|i", $plugin_data, $description); 
    1677         preg_match("|Author:(.*)|i", $plugin_data, $author_name); 
    1678         preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri); 
    1679         if (preg_match("|Version:(.*)|i", $plugin_data, $version)) 
    1680                 $version = trim($version[1]); 
     1679        update_option( 'recently_edited', $oldfiles ); 
     1680} 
     1681 
     1682function get_plugin_data( $plugin_file ) { 
     1683        $plugin_data = implode( '', file( $plugin_file )); 
     1684        preg_match( "|Plugin Name:(.*)|i", $plugin_data, $plugin_name ); 
     1685        preg_match( "|Plugin URI:(.*)|i", $plugin_data, $plugin_uri ); 
     1686        preg_match( "|Description:(.*)|i", $plugin_data, $description ); 
     1687        preg_match( "|Author:(.*)|i", $plugin_data, $author_name ); 
     1688        preg_match( "|Author URI:(.*)|i", $plugin_data, $author_uri ); 
     1689        if ( preg_match( "|Version:(.*)|i", $plugin_data, $version )) 
     1690                $version = trim( $version[1] ); 
    16811691        else 
    16821692                $version = ''; 
    16831693 
    1684         $description = wptexturize(trim($description[1])); 
     1694        $description = wptexturize( trim( $description[1] )); 
    16851695 
    16861696        $name = $plugin_name[1]; 
    1687         $name = trim($name); 
     1697        $name = trim( $name ); 
    16881698        $plugin = $name; 
    1689         if ('' != $plugin_uri[1] && '' != $name) { 
    1690                 $plugin = '<a href="' . trim($plugin_uri[1]) . '" title="'.__('Visit plugin homepage').'">'.$plugin.'</a>'; 
    1691         } 
    1692  
    1693         if ('' == $author_uri[1]) { 
    1694                 $author = trim($author_name[1]); 
    1695         } else { 
    1696                 $author = '<a href="' . trim($author_uri[1]) . '" title="'.__('Visit author homepage').'">' . trim($author_name[1]) . '</a>'; 
    1697         } 
    1698  
    1699         return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]); 
     1699        if ('' != $plugin_uri[1] && '' != $name ) { 
     1700                $plugin = '<a href="' . trim( $plugin_uri[1] ) . '" title="'.__( 'Visit plugin homepage' ).'">'.$plugin.'</a>'; 
     1701        } 
     1702 
     1703        if ('' == $author_uri[1] ) { 
     1704                $author = trim( $author_name[1] ); 
     1705        } else { 
     1706                $author = '<a href="' . trim( $author_uri[1] ) . '" title="'.__( 'Visit author homepage' ).'">' . trim( $author_name[1] ) . '</a>'; 
     1707        } 
     1708 
     1709        return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1] ); 
    17001710} 
    17011711 
     
    17031713        global $wp_plugins; 
    17041714 
    1705         if (isset ($wp_plugins)) { 
     1715        if ( isset( $wp_plugins ) ) { 
    17061716                return $wp_plugins; 
    17071717        } 
     
    17111721 
    17121722        // Files in wp-content/plugins directory 
    1713         $plugins_dir = @ dir($plugin_root); 
    1714         if ($plugins_dir) { 
    1715                 while (($file = $plugins_dir->read()) !== false) { 
    1716                         if (preg_match('|^\.+$|', $file)) 
     1723        $plugins_dir = @ dir( $plugin_root); 
     1724        if ( $plugins_dir ) { 
     1725                while (($file = $plugins_dir->read() ) !== false ) { 
     1726                        if ( preg_match( '|^\.+$|', $file )) 
    17171727                                continue; 
    1718                         if (is_dir($plugin_root.'/'.$file)) { 
    1719                                 $plugins_subdir = @ dir($plugin_root.'/'.$file); 
    1720                                 if ($plugins_subdir) { 
    1721                                         while (($subfile = $plugins_subdir->read()) !== false) { 
    1722                                                 if (preg_match('|^\.+$|', $subfile)) 
     1728                        if ( is_dir( $plugin_root.'/'.$file ) ) { 
     1729                                $plugins_subdir = @ dir( $plugin_root.'/'.$file ); 
     1730                                if ( $plugins_subdir ) { 
     1731                                        while (($subfile = $plugins_subdir->read() ) !== false ) { 
     1732                                                if ( preg_match( '|^\.+$|', $subfile )) 
    17231733                                                        continue; 
    1724                                                 if (preg_match('|\.php$|', $subfile)) 
     1734                                                if ( preg_match( '|\.php$|', $subfile )) 
    17251735                                                        $plugin_files[] = "$file/$subfile"; 
    17261736                                        } 
    17271737                                } 
    17281738                        } else { 
    1729                                 if (preg_match('|\.php$|', $file)) 
     1739                                if ( preg_match( '|\.php$|', $file )) 
    17301740                                        $plugin_files[] = $file; 
    17311741                        } 
     
    17371747 
    17381748        foreach ( $plugin_files as $plugin_file ) { 
    1739                 if ( !is_readable("$plugin_root/$plugin_file") ) 
     1749                if ( !is_readable( "$plugin_root/$plugin_file" ) ) 
    17401750                        continue; 
    17411751 
    1742                 $plugin_data = get_plugin_data("$plugin_root/$plugin_file"); 
    1743  
    1744                 if ( empty ($plugin_data['Name']) ) 
     1752                $plugin_data = get_plugin_data( "$plugin_root/$plugin_file" ); 
     1753 
     1754                if ( empty ( $plugin_data['Name'] ) ) 
    17451755                        continue; 
    17461756 
    1747                 $wp_plugins[plugin_basename($plugin_file)] = $plugin_data; 
    1748         } 
    1749  
    1750         uasort($wp_plugins, create_function('$a, $b', 'return strnatcasecmp($a["Name"], $b["Name"]);')); 
     1757                $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; 
     1758        } 
     1759 
     1760        uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' )); 
    17511761 
    17521762        return $wp_plugins; 
    17531763} 
    17541764 
    1755 function get_plugin_page_hookname($plugin_page, $parent_page) { 
     1765function get_plugin_page_hookname( $plugin_page, $parent_page ) { 
    17561766        global $admin_page_hooks; 
    17571767 
    17581768        $parent = get_admin_page_parent(); 
    17591769 
    1760         if (empty ($parent_page) || 'admin.php' == $parent_page) { 
    1761                 if (isset ($admin_page_hooks[$plugin_page])) 
     1770        if ( empty ( $parent_page ) || 'admin.php' == $parent_page ) { 
     1771                if ( isset( $admin_page_hooks[$plugin_page] )) 
    17621772                        $page_type = 'toplevel'; 
    17631773                else 
    1764                         if (isset ($admin_page_hooks[$parent])) 
     1774                        if ( isset( $admin_page_hooks[$parent] )) 
    17651775                                $page_type = $admin_page_hooks[$parent]; 
    17661776        } else 
    1767                 if (isset ($admin_page_hooks[$parent_page])) { 
     1777                if ( isset( $admin_page_hooks[$parent_page] ) ) { 
    17681778                        $page_type = $admin_page_hooks[$parent_page]; 
    17691779                } else { 
     
    17711781                } 
    17721782 
    1773         $plugin_name = preg_replace('!\.php!', '', $plugin_page); 
     1783        $plugin_name = preg_replace( '!\.php!', '', $plugin_page ); 
    17741784 
    17751785        return $page_type.'_page_'.$plugin_name; 
    17761786} 
    17771787 
    1778 function get_plugin_page_hook($plugin_page, $parent_page) { 
     1788function get_plugin_page_hook( $plugin_page, $parent_page ) { 
    17791789        global $wp_filter; 
    17801790 
    1781         $hook = get_plugin_page_hookname($plugin_page, $parent_page); 
    1782         if (isset ($wp_filter[$hook])) 
     1791        $hook = get_plugin_page_hookname( $plugin_page, $parent_page ); 
     1792        if ( isset( $wp_filter[$hook] )) 
    17831793                return $hook; 
    17841794        else 
     
    17871797 
    17881798function browse_happy() { 
    1789         $getit = __('WordPress recommends a better browser'); 
     1799        $getit = __( 'WordPress recommends a better browser' ); 
    17901800        echo ' 
    17911801                <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> 
    17921802                '; 
    17931803} 
    1794 if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) 
    1795         add_action('admin_footer', 'browse_happy'); 
    1796  
    1797 function documentation_link($for) { 
     1804if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' )) 
     1805        add_action( 'admin_footer', 'browse_happy' ); 
     1806 
     1807function documentation_link( $for ) { 
    17981808        return; 
    17991809} 
    18001810 
    1801 function register_importer($id, $name, $description, $callback) { 
     1811function register_importer( $id, $name, $description, $callback ) { 
    18021812        global $wp_importers; 
    18031813 
    1804         $wp_importers[$id] = array ($name, $description, $callback); 
     1814        $wp_importers[$id] = array ( $name, $description, $callback ); 
    18051815} 
    18061816 
     
    18311841// array wp_handle_upload ( array &file [, array overrides] ) 
    18321842// file: reference to a single element of $_FILES. Call the function once for each uploaded file. 
    1833 // overrides: an associative array of names=>values to override default variables with extract($overrides, EXTR_OVERWRITE). 
     1843// overrides: an associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). 
    18341844// On success, returns an associative array of file attributes. 
    1835 // On failure, returns $overrides['upload_error_handler'](&$file, $message) or array('error'=>$message). 
    1836 function wp_handle_upload(&$file, $overrides = false) { 
     1845// On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). 
     1846function wp_handle_upload( &$file, $overrides = false ) { 
    18371847        // The default error handler. 
    1838         if (! function_exists('wp_handle_upload_error') ) { 
    1839                 function wp_handle_upload_error(&$file, $message) { 
    1840                         return array('error'=>$message); 
     1848        if (! function_exists( 'wp_handle_upload_error' ) ) { 
     1849                function wp_handle_upload_error( &$file, $message ) { 
     1850                        return array( 'error'=>$message ); 
    18411851                } 
    18421852        } 
     
    18491859 
    18501860        // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error']. 
    1851         $upload_error_strings = array(false, 
    1852                 __("The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>."), 
    1853                 __("The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form."), 
    1854                 __("The uploaded file was only partially uploaded."), 
    1855                 __("No file was uploaded."), 
    1856                 __("Missing a temporary folder."), 
    1857                 __("Failed to write file to disk.")); 
     1861        $upload_error_strings = array( false, 
     1862                __( "The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>." ), 
     1863                __( "The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form." ), 
     1864                __( "The uploaded file was only partially uploaded." ), 
     1865                __( "No file was uploaded." ), 
     1866                __( "Missing a temporary folder." ), 
     1867                __( "Failed to write file to disk." )); 
    18581868 
    18591869        // All tests are on by default. Most can be turned off by $override[{test_name}] = false; 
     
    18651875 
    18661876        // Install user overrides. Did we mention that this voids your warranty? 
    1867         if ( is_array($overrides) ) 
    1868                 extract($overrides, EXTR_OVERWRITE); 
     1877        if ( is_array( $overrides ) ) 
     1878                extract( $overrides, EXTR_OVERWRITE ); 
    18691879 
    18701880        // A correct form post will pass this test. 
    1871         if ( $test_form && (!isset($_POST['action']) || ($_POST['action'] != $action)) ) 
    1872                 return $upload_error_handler($file, __('Invalid form submission.')); 
     1881        if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) ) 
     1882                return $upload_error_handler( $file, __( 'Invalid form submission.' )); 
    18731883 
    18741884        // A successful upload will pass this test. It makes no sense to override this one. 
    18751885        if ( $file['error'] > 0 ) 
    1876                 return $upload_error_handler($file, $upload_error_strings[$file['error']]); 
     1886                return $upload_error_handler( $file, $upload_error_strings[$file['error']] ); 
    18771887 
    18781888        // A non-empty file will pass this test. 
    1879         if ( $test_size && !($file['size'] > 0) ) 
    1880                 return $upload_error_handler($file, __('File is empty. Please upload something more substantial.')); 
     1889        if ( $test_size && !($file['size'] > 0 ) ) 
     1890                return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial.' )); 
    18811891 
    18821892        // A properly uploaded file will pass this test. There should be no reason to override this one. 
    1883         if (! @ is_uploaded_file($file['tmp_name']) ) 
    1884                 return $upload_error_handler($file, __('Specified file failed upload test.')); 
     1893        if (! @ is_uploaded_file( $file['tmp_name'] ) ) 
     1894                return $upload_error_handler( $file, __( 'Specified file failed upload test.' )); 
    18851895 
    18861896        // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. 
    18871897        if ( $test_type ) { 
    1888                 $wp_filetype = wp_check_filetype($file['name'], $mimes); 
    1889  
    1890                 extract($wp_filetype); 
     1898                $wp_filetype = wp_check_filetype( $file['name'], $mimes ); 
     1899 
     1900                extract( $wp_filetype ); 
    18911901 
    18921902                if ( !$type || !$ext ) 
    1893                         return $upload_error_handler($file, __('File type does not meet security guidelines. Try another.')); 
    1894         } 
    1895  
    1896         // A writable uploads dir will pass this test. Override with $uploads = array('path'=>$path, 'url'=>$url); 
    1897         if ( ( empty( $uploads['path'] ) || empty( $uploads['url'] ) ) && ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) 
    1898                 return $upload_error_handler($file, $uploads['error']); 
     1903                        return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' )); 
     1904        } 
     1905 
     1906        // A writable uploads dir will pass this test. Again, there's no point overriding this one. 
     1907        if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) 
     1908                return $upload_error_handler( $file, $uploads['error'] ); 
    18991909 
    19001910        // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied. 
    1901         if ( isset($unique_filename_callback) && function_exists($unique_filename_callback) ) { 
    1902                 $filename = $unique_filename_callback($uploads['path'], $file['name']); 
     1911        if ( isset( $unique_filename_callback ) && function_exists( $unique_filename_callback ) ) { 
     1912                $filename = $unique_filename_callback( $uploads['path'], $file['name'] ); 
    19031913        } else { 
    19041914                $number = ''; 
    1905                 $filename = str_replace('#', '_', $file['name']); 
    1906                 $filename = str_replace(array('\\', "'"), '', $filename); 
    1907                 if ( empty($ext) ) 
     1915                $filename = str_replace( '#', '_', $file['name'] ); 
     1916                $filename = str_replace( array( '\\', "'" ), '', $filename ); 
     1917                if ( empty( $ext) ) 
    19081918                        $ext = ''; 
    19091919                else 
    19101920                        $ext = ".$ext"; 
    1911                 while ( file_exists($uploads['path'] . "/$filename") ) { 
     1921                while ( file_exists( $uploads['path'] . "/$filename" ) ) { 
    19121922                        if ( '' == "$number$ext" ) 
    19131923                                $filename = $filename . ++$number . $ext; 
    19141924                        else 
    1915                                 $filename = str_replace("$number$ext", ++$number . $ext, $filename); 
    1916                 } 
    1917                 $filename = str_replace($ext, '', $filename); 
    1918                 $filename = sanitize_title_with_dashes($filename) . $ext; 
     1925                                $filename = str_replace( "$number$ext", ++$number . $ext, $filename ); 
     1926                } 
     1927                $filename = str_replace( $ext, '', $filename ); 
     1928                $filename = sanitize_title_with_dashes( $filename ) . $ext; 
    19191929        } 
    19201930 
    19211931        // Move the file to the uploads dir 
    19221932        $new_file = $uploads['path'] . "/$filename"; 
    1923         if ( false === @ move_uploaded_file($file['tmp_name'], $new_file) ) 
    1924                 wp_die(printf(__('The uploaded file could not be moved to %s.'), $uploads['path'])); 
     1933        if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) 
     1934                wp_die( printf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] )); 
    19251935 
    19261936        // Set correct file permissions 
    1927         $stat = stat(dirname($new_file)); 
     1937        $stat = stat( dirname( $new_file )); 
    19281938        $perms = $stat['mode'] & 0000666; 
    1929         @ chmod($new_file, $perms); 
     1939        @ chmod( $new_file, $perms ); 
    19301940 
    19311941        // Compute the URL 
    19321942        $url = $uploads['url'] . "/$filename"; 
    19331943         
    1934         $return = apply_filters( 'wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $type) ); 
     1944        $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) ); 
    19351945 
    19361946        return $return; 
    19371947} 
    19381948 
    1939 function wp_shrink_dimensions($width, $height, $wmax = 128, $hmax = 96) { 
     1949function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) { 
    19401950        if ( $height <= $hmax && $width <= $wmax ) 
    1941                 return array($width, $height); 
     1951                return array( $width, $height); 
    19421952        elseif ( $width / $height > $wmax / $hmax ) 
    1943                 return array($wmax, (int) ($height / $width * $wmax)); 
     1953                return array( $wmax, (int) ($height / $width * $wmax )); 
    19441954        else 
    1945                 return array((int) ($width / $height * $hmax), $hmax); 
    1946 } 
    1947  
    1948 function wp_import_cleanup($id) { 
    1949         wp_delete_attachment($id); 
    1950 } 
    1951  
    1952 function wp_import_upload_form($action) { 
    1953         $size = strtolower( ini_get('upload_max_filesize') ); 
     1955                return array( (int) ($width / $height * $hmax ), $hmax ); 
     1956} 
     1957 
     1958function wp_import_cleanup( $id ) { 
     1959        wp_delete_attachment( $id ); 
     1960} 
     1961 
     1962function wp_import_upload_form( $action ) { 
     1963        $size = strtolower( ini_get( 'upload_max_filesize' ) ); 
    19541964        $bytes = 0; 
    19551965        if ( strstr( $size, 'k' ) ) 
     
    19621972<form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo $action ?>"> 
    19631973<p> 
    1964 <label for="upload"><?php _e('Choose a file from your computer:'); ?></label> (<?php printf( __('Maximum size: %s'), $size ); ?>
     1974<label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>
    19651975<input type="file" id="upload" name="import" size="25" /> 
    19661976<input type="hidden" name="action" value="save" /> 
     
    19681978</p> 
    19691979<p class="submit"> 
    1970 <input type="submit" value="<?php _e('Upload file and import'); ?> &raquo;" /> 
     1980<input type="submit" value="<?php _e( 'Upload file and import' ); ?> &raquo;" /> 
    19711981</p> 
    19721982</form> 
     
    19751985 
    19761986function wp_import_handle_upload() { 
    1977         $overrides = array('test_form' => false, 'test_type' => false); 
    1978         $file = wp_handle_upload($_FILES['import'], $overrides); 
    1979  
    1980         if ( isset($file['error']) ) 
     1987        $overrides = array( 'test_form' => false, 'test_type' => false ); 
     1988        $file = wp_handle_upload( $_FILES['import'], $overrides ); 
     1989 
     1990        if ( isset( $file['error'] ) ) 
    19811991                return $file; 
    19821992 
    19831993        $url = $file['url']; 
    19841994        $file = addslashes( $file['file'] ); 
    1985         $filename = basename($file); 
     1995        $filename = basename( $file ); 
    19861996 
    19871997        // Construct the object array 
    1988         $object = array( 
    1989                 'post_title' => $filename, 
     1998        $object = array( 'post_title' => $filename, 
    19901999                'post_content' => $url, 
    19912000                'post_mime_type' => 'import', 
     
    19942003 
    19952004        // Save the data 
    1996         $id = wp_insert_attachment($object, $file); 
    1997  
    1998         return array('file' => $file, 'id' => $id); 
    1999 } 
    2000  
    2001 function the_attachment_links($id = false) { 
     2005        $id = wp_insert_attachment( $object, $file ); 
     2006 
     2007        return array( 'file' => $file, 'id' => $id ); 
     2008} 
     2009 
     2010function the_attachment_links( $id = false ) { 
    20022011        $id = (int) $id; 
    2003         $post = & get_post($id); 
     2012        $post = & get_post( $id ); 
    20042013 
    20052014        if ( $post->post_type != 'attachment' ) 
    20062015                return false; 
    20072016 
    2008         $icon = get_attachment_icon($post->ID); 
     2017        $icon = get_attachment_icon( $post->ID ); 
    20092018        $attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true ); 
    2010         $thumb = isset($attachment_data['thumb']); 
     2019        $thumb = isset( $attachment_data['thumb'] ); 
    20112020?> 
    20122021<form id="the-attachment-links"> 
     
    20152024        <col class="widefat" /> 
    20162025        <tr> 
    2017                 <th scope="row"><?php _e('URL') ?></th> 
     2026                <th scope="row"><?php _e( 'URL' ) ?></th> 
    20182027                <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo $post->guid ?></textarea></td> 
    20192028        </tr> 
    20202029<?php if ( $icon ) : ?> 
    20212030        <tr> 
    2022                 <th scope="row"><?php $thumb ? _e('Thumbnail linked to file') : _e('Image linked to file'); ?></th> 
     2031                <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th> 
    20232032                <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid; ?>"><?php echo $icon ?></a></textarea></td> 
    20242033        </tr> 
    20252034        <tr> 
    2026                 <th scope="row"><?php $thumb ? _e('Thumbnail linked to page') : _e('Image linked to file'); ?></th> 
    2027                 <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> 
     2035                <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to file' ); ?></th> 
     2036                <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> 
    20282037        </tr> 
    20292038<?php else : ?> 
    20302039        <tr> 
    2031                 <th scope="row"><?php _e('Link to file') ?></th> 
    2032                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename($post->guid);  ?></a></textarea></td> 
     2040                <th scope="row"><?php _e( 'Link to file' ) ?></th> 
     2041                <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename( $post->guid );  ?></a></textarea></td> 
    20332042        </tr> 
    20342043        <tr> 
    2035                 <th scope="row"><?php _e('Link to page') ?></th> 
    2036                 <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> 
     2044                <th scope="row"><?php _e( 'Link to page' ) ?></th> 
     2045                <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> 
    20372046        </tr> 
    20382047<?php endif; ?> 
     
    20422051} 
    20432052 
    2044 function get_udims($width, $height) { 
     2053function get_udims( $width, $height) { 
    20452054        if ( $height <= 96 && $width <= 128 ) 
    2046                 return array($width, $height); 
     2055                return array( $width, $height); 
    20472056        elseif ( $width / $height > 4 / 3 ) 
    2048                 return array(128, (int) ($height / $width * 128)); 
     2057                return array( 128, (int) ($height / $width * 128 )); 
    20492058        else 
    2050                 return array((int) ($width / $height * 96), 96); 
    2051 } 
    2052  
    2053 function wp_reset_vars($vars) { 
    2054         for ($i=0; $i<count($vars); $i += 1) { 
     2059                return array( (int) ($width / $height * 96 ), 96 ); 
     2060} 
     2061 
     2062function wp_reset_vars( $vars ) { 
     2063        for ( $i=0; $i<count( $vars ); $i += 1 ) { 
    20552064                $var = $vars[$i]; 
    20562065                global $$var; 
    20572066 
    2058                 if (!isset($$var)) { 
    2059                         if (empty($_POST["$var"])) { 
    2060                                 if (empty($_GET["$var"])
     2067                if (!isset( $$var ) ) { 
     2068                        if ( empty( $_POST["$var"] ) ) { 
     2069                                if ( empty( $_GET["$var"] )
    20612070                                        $$var = ''; 
    20622071                                else 
     
    20702079 
    20712080// If siteurl or home changed, reset cookies and flush rewrite rules. 
    2072 function update_home_siteurl($old_value, $value) { 
     2081function update_home_siteurl( $old_value, $value ) { 
    20732082        global $wp_rewrite, $user_login, $user_pass_md5; 
    20742083 
    2075         if ( defined("WP_INSTALLING") ) 
     2084        if ( defined( "WP_INSTALLING" ) ) 
    20762085                return; 
    20772086 
     
    20812090        wp_clearcookie(); 
    20822091        // Set cookies for new paths. 
    2083         wp_setcookie($user_login, $user_pass_md5, true, get_option('home'), get_option('siteurl'));      
    2084 
    2085  
    2086 add_action('update_option_home', 'update_home_siteurl', 10, 2); 
    2087 add_action('update_option_siteurl', 'update_home_siteurl', 10, 2); 
     2092        wp_setcookie( $user_login, $user_pass_md5, true, get_option( 'home' ), get_option( 'siteurl' ));         
     2093
     2094 
     2095add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); 
     2096add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 ); 
     2097 
     2098function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { 
     2099        if ( ctype_digit( $src_file ) ) // Handle int as attachment ID 
     2100                $src_file = get_attached_file( $src_file ); 
     2101 
     2102        $src = wp_load_image( $src_file ); 
     2103 
     2104        if ( !is_resource( $src )) 
     2105                return $src; 
     2106 
     2107        $dst = imagecreatetruecolor( $dst_w, $dst_h ); 
     2108 
     2109        if ( $src_abs ) { 
     2110                $src_w -= $src_x; 
     2111                $src_h -= $src_y; 
     2112        } 
     2113 
     2114        imageantialias( $dst, true ); 
     2115        imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); 
     2116 
     2117        if ( !$dst_file ) 
     2118                $dst_file = str_replace( basename( $src_file ), 'cropped-'.basename( $src_file ), $src_file ); 
     2119 
     2120        $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file ); 
     2121 
     2122        if ( imagejpeg( $dst, $dst_file ) ) 
     2123                return $dst_file; 
     2124        else 
     2125                return false; 
     2126
     2127 
     2128function wp_load_image( $file ) { 
     2129        if ( ctype_digit( $file ) ) 
     2130                $file = get_attached_file( $file ); 
     2131 
     2132        if ( !file_exists( $file ) ) 
     2133                return "File '$file' doesn't exist?"; 
     2134 
     2135        $contents = file_get_contents( $file ); 
     2136 
     2137        $image = imagecreatefromstring( $contents ); 
     2138 
     2139        if ( !is_resource( $image ) ) 
     2140                return "File '$file' is not image?"; 
     2141 
     2142        return $image; 
     2143
    20882144 
    20892145function autocomplete_css() { 
     
    21642220 
    21652221add_action('update_option_new_admin_email', 'update_option_new_admin_email', 10, 2); 
    2166  
    2167 function wp_crop_image($src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false) { 
    2168         if ( ctype_digit($src_file) ) // Handle int as attachment ID 
    2169                 $src_file = get_attached_file($src_file); 
    2170  
    2171         $src = wp_load_image($src_file); 
    2172  
    2173         if ( !is_resource($src) ) 
    2174                 return $src; 
    2175  
    2176         $dst = imagecreatetruecolor($dst_w, $dst_h); 
    2177  
    2178         if ( $src_abs ) { 
    2179                 $src_w -= $src_x; 
    2180                 $src_h -= $src_y; 
    2181         } 
    2182  
    2183         imageantialias($dst, true); 
    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 "File '$file' doesn't exist?"; 
    2203  
    2204         $contents = file_get_contents($file); 
    2205  
    2206         $image = imagecreatefromstring($contents); 
    2207  
    2208         if ( !is_resource($image) ) 
    2209                 return "File '$file' is not image?"; 
    2210  
    2211         return $image; 
    2212 } 
    2213  
    22142222?> 
  • trunk/wp-admin/admin-header.php

    r770 r810  
    1717<head> 
    1818<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> 
    19 <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title; ?> &#8212; WordPress</title> 
     19<title><?php bloginfo('name') ?> &rsaquo; <?php echo wp_specialchars( strip_tags( $title ) ); ?> &#8212; WordPress</title> 
    2020<link rel="stylesheet" href="<?php echo get_option('siteurl') ?>/wp-admin/wp-admin.css?version=<?php bloginfo('version'); ?>" type="text/css" /> 
    2121<?php if ( ('rtl' == $wp_locale->text_direction) ) : ?> 
  • trunk/wp-admin/bookmarklet.php

    r729 r810  
    3636        $post->post_title = $popuptitle; 
    3737 
    38    
     38 
    3939$content  = wp_specialchars($_REQUEST['content']); 
    4040$popupurl = wp_specialchars($_REQUEST['popupurl']); 
    41     if ( !empty($content) ) { 
    42         $post->post_content = wp_specialchars( stripslashes($_REQUEST['content']) ); 
    43     } else { 
    44         $post->post_content = '<a href="'.$popupurl.'">'.$popuptitle.'</a>'."\n$text"; 
    45    
     41if ( !empty($content) ) { 
     42       $post->post_content = wp_specialchars( stripslashes($_REQUEST['content']) ); 
     43} else { 
     44       $post->post_content = '<a href="'.$popupurl.'">'.$popuptitle.'</a>'."\n$text"; 
     45
    4646 
    47     /* /big funky fixes */ 
     47/* /big funky fixes */ 
    4848 
    4949?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    7878 
    7979#wpbookmarklet .wrap { 
    80     border: 0px; 
     80       border: 0px; 
    8181} 
    8282 
    8383#wpbookmarklet #postdiv { 
    84     margin-bottom: 0.5em; 
     84       margin-bottom: 0.5em; 
    8585} 
    8686 
    8787#wpbookmarklet #titlediv { 
    88     margin-bottom: 1em; 
     88       margin-bottom: 1em; 
    8989} 
    9090 
  • trunk/wp-admin/categories.php

    r774 r810  
    2121                wp_redirect('categories.php?message=4#addcat'); 
    2222        } 
     23        exit; 
    2324break; 
    2425 
     
    3738 
    3839    if ( $cat_ID == get_option('default_link_category') ) 
    39