Make WordPress Core

Changeset 2889


Ignore:
Timestamp:
09/18/2005 07:44:14 PM (21 years ago)
Author:
ryan
Message:

Link love. Add get_link(), get_link_to_edit(), add_link(), edit_link(), wp_insert_link(), wp_update_link(), wp_delete_link()

Location:
trunk/wp-admin
Files:
5 edited

Legend:

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

    r2886 r2889  
    11<?php
     2
    23
    34// Creates a new post from the "Write Post" form using $_POST information.
     
    56        global $user_ID;
    67
    7         if ( ! current_user_can('edit_posts') )
    8                 die( __('You are not allowed to create posts or drafts on this blog.') );
     8        if (!current_user_can('edit_posts'))
     9                die(__('You are not allowed to create posts or drafts on this blog.'));
    910
    1011        // Rename.
    11         $_POST['post_content']  = $_POST['content'];
    12         $_POST['post_excerpt']  = $_POST['excerpt'];
     12        $_POST['post_content'] = $_POST['content'];
     13        $_POST['post_excerpt'] = $_POST['excerpt'];
    1314        $_POST['post_parent'] = $_POST['parent_id'];
    1415        $_POST['to_ping'] = $_POST['trackback_url'];
    1516
    16         if (! empty($_POST['post_author_override'])) {
     17        if (!empty ($_POST['post_author_override'])) {
    1718                $_POST['$post_author'] = (int) $_POST['post_author_override'];
    18         } else if (! empty($_POST['post_author'])) {
    19                 $_POST['post_author'] = (int) $_POST['post_author'];
    20         } else {
    21                 $_POST['post_author'] = (int) $_POST['user_ID'];
    22         }
    23 
    24         if ( ($_POST['post_author'] != $_POST['user_ID']) && ! current_user_can('edit_others_posts') )
    25                 die( __('You cannot post as this user.') );
    26        
     19        } else
     20                if (!empty ($_POST['post_author'])) {
     21                        $_POST['post_author'] = (int) $_POST['post_author'];
     22                } else {
     23                        $_POST['post_author'] = (int) $_POST['user_ID'];
     24                }
     25
     26        if (($_POST['post_author'] != $_POST['user_ID']) && !current_user_can('edit_others_posts'))
     27                die(__('You cannot post as this user.'));
     28
    2729        // What to do based on which button they pressed
    28         if ('' != $_POST['saveasdraft']) $_POST['post_status'] = 'draft';
    29         if ('' != $_POST['saveasprivate']) $_POST['post_status'] = 'private';
    30         if ('' != $_POST['publish']) $_POST['post_status'] = 'publish';
    31         if ('' != $_POST['advanced']) $_POST['post_status'] = 'draft';
    32         if ('' != $_POST['savepage']) $_POST['post_status'] = 'static';
    33 
    34         if ( 'publish' == $_POST['post_status'] && ! current_user_can('publish_posts') )
     30        if ('' != $_POST['saveasdraft'])
    3531                $_POST['post_status'] = 'draft';
    36 
    37         if ( !empty($_POST['edit_date']) ) {
     32        if ('' != $_POST['saveasprivate'])
     33                $_POST['post_status'] = 'private';
     34        if ('' != $_POST['publish'])
     35                $_POST['post_status'] = 'publish';
     36        if ('' != $_POST['advanced'])
     37                $_POST['post_status'] = 'draft';
     38        if ('' != $_POST['savepage'])
     39                $_POST['post_status'] = 'static';
     40
     41        if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts'))
     42                $_POST['post_status'] = 'draft';
     43
     44        if (!empty ($_POST['edit_date'])) {
    3845                $aa = $_POST['aa'];
    3946                $mm = $_POST['mm'];
     
    4350                $ss = $_POST['ss'];
    4451                $jj = ($jj > 31) ? 31 : $jj;
    45                 $hh = ($hh > 23) ? $hh - 24 : $hh;
    46                 $mn = ($mn > 59) ? $mn - 60 : $mn;
    47                 $ss = ($ss > 59) ? $ss - 60 : $ss;
     52                $hh = ($hh > 23) ? $hh -24 : $hh;
     53                $mn = ($mn > 59) ? $mn -60 : $mn;
     54                $ss = ($ss > 59) ? $ss -60 : $ss;
    4855                $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    4956                $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
    50         } 
     57        }
    5158
    5259        // Create the post.
     
    6370        $post_ID = (int) $_POST['post_ID'];
    6471
    65         if ( ! current_user_can('edit_post', $post_ID) )
    66                 die( __('You are not allowed to edit this post.') );
     72        if (!current_user_can('edit_post', $post_ID))
     73                die(__('You are not allowed to edit this post.'));
    6774
    6875        // Rename.
    6976        $_POST['ID'] = (int) $_POST['post_ID'];
    70         $_POST['post_content']  = $_POST['content'];
    71         $_POST['post_excerpt']  = $_POST['excerpt'];
     77        $_POST['post_content'] = $_POST['content'];
     78        $_POST['post_excerpt'] = $_POST['excerpt'];
    7279        $_POST['post_parent'] = $_POST['parent_id'];
    7380        $_POST['to_ping'] = $_POST['trackback_url'];
    7481
    75         if (! empty($_POST['post_author_override'])) {
     82        if (!empty ($_POST['post_author_override'])) {
    7683                $_POST['$post_author'] = (int) $_POST['post_author_override'];
    77         } else if (! empty($_POST['post_author'])) {
    78                 $_POST['post_author'] = (int) $_POST['post_author'];
    79         } else {
    80                 $_POST['post_author'] = (int) $_POST['user_ID'];
    81         }
    82 
    83         if ( ($_POST['post_author'] != $_POST['user_ID']) && ! current_user_can('edit_others_posts') )
    84                 die( __('You cannot post as this user.') );
     84        } else
     85                if (!empty ($_POST['post_author'])) {
     86                        $_POST['post_author'] = (int) $_POST['post_author'];
     87                } else {
     88                        $_POST['post_author'] = (int) $_POST['user_ID'];
     89                }
     90
     91        if (($_POST['post_author'] != $_POST['user_ID']) && !current_user_can('edit_others_posts'))
     92                die(__('You cannot post as this user.'));
    8593
    8694        // What to do based on which button they pressed
    87         if ('' != $_POST['saveasdraft']) $_POST['post_status'] = 'draft';
    88         if ('' != $_POST['saveasprivate']) $_POST['post_status'] = 'private';
    89         if ('' != $_POST['publish']) $_POST['post_status'] = 'publish';
    90         if ('' != $_POST['advanced']) $_POST['post_status'] = 'draft';
    91         if ('' != $_POST['savepage']) $_POST['post_status'] = 'static';
    92 
    93         if ( 'publish' == $_POST['post_status'] && ! current_user_can('publish_posts') )
     95        if ('' != $_POST['saveasdraft'])
    9496                $_POST['post_status'] = 'draft';
    95        
    96         if ( !isset($_POST['comment_status']) )
     97        if ('' != $_POST['saveasprivate'])
     98                $_POST['post_status'] = 'private';
     99        if ('' != $_POST['publish'])
     100                $_POST['post_status'] = 'publish';
     101        if ('' != $_POST['advanced'])
     102                $_POST['post_status'] = 'draft';
     103        if ('' != $_POST['savepage'])
     104                $_POST['post_status'] = 'static';
     105
     106        if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts'))
     107                $_POST['post_status'] = 'draft';
     108
     109        if (!isset ($_POST['comment_status']))
    97110                $_POST['comment_status'] = 'closed';
    98111
    99         if ( !isset($_POST['ping_status']) )
     112        if (!isset ($_POST['ping_status']))
    100113                $_POST['ping_status'] = 'closed';
    101        
    102         if ( !empty($_POST['edit_date']) ) {
     114
     115        if (!empty ($_POST['edit_date'])) {
    103116                $aa = $_POST['aa'];
    104117                $mm = $_POST['mm'];
     
    108121                $ss = $_POST['ss'];
    109122                $jj = ($jj > 31) ? 31 : $jj;
    110                 $hh = ($hh > 23) ? $hh - 24 : $hh;
    111                 $mn = ($mn > 59) ? $mn - 60 : $mn;
    112                 $ss = ($ss > 59) ? $ss - 60 : $ss;
     123                $hh = ($hh > 23) ? $hh -24 : $hh;
     124                $mn = ($mn > 59) ? $mn -60 : $mn;
     125                $ss = ($ss > 59) ? $ss -60 : $ss;
    113126                $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    114127                $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
    115         } 
     128        }
    116129
    117130        wp_update_post($_POST);
    118131
    119132        // Meta Stuff
    120         if ($_POST['meta']) :
    121                 foreach ($_POST['meta'] as $key => $value) :
    122                         update_meta($key, $value['key'], $value['value']);
    123                 endforeach;
     133        if ($_POST['meta'])
     134                : foreach ($_POST['meta'] as $key => $value)
     135                        : update_meta($key, $value['key'], $value['value']);
     136        endforeach;
    124137        endif;
    125138
    126         if ($_POST['deletemeta']) :
    127                 foreach ($_POST['deletemeta'] as $key => $value) :
    128                         delete_meta($key);
    129                 endforeach;
     139        if ($_POST['deletemeta'])
     140                : foreach ($_POST['deletemeta'] as $key => $value)
     141                        : delete_meta($key);
     142        endforeach;
    130143        endif;
    131144
    132145        add_meta($post_ID);
    133        
     146
    134147        return $post_ID;
    135148}
     
    141154        $comment_post_ID = (int) $_POST['comment_post_ID'];
    142155
    143         if ( ! current_user_can('edit_post', $comment_post_ID) )
    144                 die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.') );
     156        if (!current_user_can('edit_post', $comment_post_ID))
     157                die(__('You are not allowed to edit comments on this post, so you cannot edit this comment.'));
    145158
    146159        $_POST['comment_author'] = $_POST['newcomment_author'];
    147         $_POST['comment_author_email']  = $_POST['newcomment_author_email'];
     160        $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
    148161        $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
    149162        $_POST['comment_approved'] = $_POST['comment_status'];
    150163        $_POST['comment_content'] = $_POST['content'];
    151164        $_POST['comment_ID'] = (int) $_POST['comment_ID'];
    152  
    153         if ( !empty($_POST['edit_date']) ) {
     165
     166        if (!empty ($_POST['edit_date'])) {
    154167                $aa = $_POST['aa'];
    155168                $mm = $_POST['mm'];
     
    159172                $ss = $_POST['ss'];
    160173                $jj = ($jj > 31) ? 31 : $jj;
    161                 $hh = ($hh > 23) ? $hh - 24 : $hh;
    162                 $mn = ($mn > 59) ? $mn - 60 : $mn;
    163                 $ss = ($ss > 59) ? $ss - 60 : $ss;
     174                $hh = ($hh > 23) ? $hh -24 : $hh;
     175                $mn = ($mn > 59) ? $mn -60 : $mn;
     176                $ss = ($ss > 59) ? $ss -60 : $ss;
    164177                $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    165178        }
     
    182195
    183196        if ($post->post_status == 'static')
    184                 $post->page_template = get_post_meta($id, '_wp_page_template', true);   
     197                $post->page_template = get_post_meta($id, '_wp_page_template', true);
    185198
    186199        return $post;
     
    234247
    235248        // Are we updating or creating?
    236         if ( !empty($cat_ID) ) {
     249        if (!empty ($cat_ID)) {
    237250                $update = true;
    238251        } else {
     
    244257        $cat_name = wp_specialchars($cat_name);
    245258
    246         if ( empty($category_nicename) )
     259        if (empty ($category_nicename))
    247260                $category_nicename = sanitize_title($cat_name, $cat_ID);
    248261        else
    249262                $category_nicename = sanitize_title($category_nicename, $cat_ID);
    250263
    251         if ( empty($category_description) )
     264        if (empty ($category_description))
    252265                $category_description = '';
    253266
    254         if ( empty($category_parent) )
     267        if (empty ($category_parent))
    255268                $category_parent = 0;
    256269
    257         if ( !$update)
     270        if (!$update)
    258271                $query = "INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$cat')";
    259272        else
     
    262275        $result = $wpdb->query($query);
    263276
    264         if ( $update ) {
     277        if ($update) {
    265278                do_action('edit_category', $cat_ID);
    266279        } else {
     
    276289
    277290        $cat_ID = (int) $catarr['cat_ID'];
    278        
     291
    279292        // First, get all of the original fields
    280         $category = get_category($cat_ID, ARRAY_A);     
     293        $category = get_category($cat_ID, ARRAY_A);
    281294
    282295        // Escape data pulled from DB.
     
    295308
    296309        // Don't delete the default cat.
    297         if ( 1 == $cat_ID )
     310        if (1 == $cat_ID)
    298311                return 0;
    299312
     
    321334}
    322335
    323 
    324336function wp_create_categories($categories, $post_id = '') {
    325         $cat_ids = array();
     337        $cat_ids = array ();
    326338        foreach ($categories as $category) {
    327                 if ( $id = category_exists($category) )
     339                if ($id = category_exists($category))
    328340                        $cat_ids[] = $id;
    329                 else if ( $id = wp_create_category($category) )
    330                         $cat_ids[] = $id;                               
    331         }
    332        
    333         if ( $post_id )
     341                else
     342                        if ($id = wp_create_category($category))
     343                                $cat_ids[] = $id;
     344        }
     345
     346        if ($post_id)
    334347                wp_set_post_cats('', $post_id, $cat_ids);
    335                
     348
    336349        return $cat_ids;
    337350}
     
    339352function category_exists($cat_name) {
    340353        global $wpdb;
    341         if ( !$category_nicename = sanitize_title($cat_name) )
     354        if (!$category_nicename = sanitize_title($cat_name))
    342355                return 0;
    343                
     356
    344357        return $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'");
    345358}
     
    348361
    349362function add_user() {
    350         return update_user();   
    351 }
    352 
    353 function update_user($user_id = 0) {
    354        
    355         if ( $user_id != 0 ) {
     363        return edit_user();
     364}
     365
     366function edit_user($user_id = 0) {
     367
     368        if ($user_id != 0) {
    356369                $update = true;
    357370                $user->ID = $user_id;
     
    362375                $user = '';
    363376        }
    364        
    365         if ( isset($_POST['user_login']) )
     377
     378        if (isset ($_POST['user_login']))
    366379                $user->user_login = wp_specialchars(trim($_POST['user_login']));
    367380
    368381        $pass1 = $pass2 = '';
    369         if ( isset($_POST['pass1']) )
     382        if (isset ($_POST['pass1']))
    370383                $pass1 = $_POST['pass1'];
    371         if ( isset($_POST['pass2']) )
     384        if (isset ($_POST['pass2']))
    372385                $pass2 = $_POST['pass2'];
    373386
    374         if ( isset($_POST['email']) )
     387        if (isset ($_POST['email']))
    375388                $user->user_email = wp_specialchars(trim($_POST['email']));
    376         if ( isset($_POST['url']) ) {
     389        if (isset ($_POST['url'])) {
    377390                $user->user_url = wp_specialchars(trim($_POST['url']));
    378                 $user->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url;
    379         }
    380         if ( isset($_POST['first_name']) )
     391                $user->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url;
     392        }
     393        if (isset ($_POST['first_name']))
    381394                $user->first_name = wp_specialchars(trim($_POST['first_name']));
    382         if ( isset($_POST['last_name']) )
     395        if (isset ($_POST['last_name']))
    383396                $user->last_name = wp_specialchars(trim($_POST['last_name']));
    384         if ( isset($_POST['nickname']) )
     397        if (isset ($_POST['nickname']))
    385398                $user->nickname = wp_specialchars(trim($_POST['nickname']));
    386         if ( isset($_POST['display_name']) )
     399        if (isset ($_POST['display_name']))
    387400                $user->display_name = wp_specialchars(trim($_POST['display_name']));
    388         if ( isset($_POST['description']) )
     401        if (isset ($_POST['description']))
    389402                $user->description = wp_specialchars(trim($_POST['description']));
    390         if ( isset($_POST['jabber']) )
     403        if (isset ($_POST['jabber']))
    391404                $user->jabber = wp_specialchars(trim($_POST['jabber']));
    392         if ( isset($_POST['aim']) )
     405        if (isset ($_POST['aim']))
    393406                $user->aim = wp_specialchars(trim($_POST['aim']));
    394         if ( isset($_POST['yim']) )
     407        if (isset ($_POST['yim']))
    395408                $user->yim = wp_specialchars(trim($_POST['yim']));
    396409
    397         $errors = array();
    398                
     410        $errors = array ();
     411
    399412        /* checking that username has been typed */
    400413        if ($user->user_login == '')
     
    402415
    403416        /* checking the password has been typed twice */
    404         do_action('check_passwords', array($user->user_login, &$pass1, &$pass2));
    405        
    406         if ( !$update ) {
    407                 if ( $pass1 == '' || $pass2 == '' )
     417        do_action('check_passwords', array ($user->user_login, & $pass1, & $pass2));
     418
     419        if (!$update) {
     420                if ($pass1 == '' || $pass2 == '')
    408421                        $errors['pass'] = __('<strong>ERROR</strong>: Please enter your password twice.');
    409422        } else {
    410                 if ( ( empty($pass1) && !empty($pass2) ) || ( empty($pass2) && !empty($pass1) ) )
     423                if ((empty ($pass1) && !empty ($pass2)) || (empty ($pass2) && !empty ($pass1)))
    411424                        $errors['pass'] = __("<strong>ERROR</strong>: you typed your new password only once.");
    412425        }
    413        
     426
    414427        /* checking the password has been typed twice the same */
    415428        if ($pass1 != $pass2)
    416429                $errors['pass'] = __('<strong>ERROR</strong>: Please type the same password in the two password fields.');
    417430
    418         if ( !empty($pass1) )
     431        if (!empty ($pass1))
    419432                $user->user_pass = $pass1;
    420        
    421         if ( !$update && username_exists( $user_login ) )
     433
     434        if (!$update && username_exists($user_login))
    422435                $errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
    423436
    424437        /* checking e-mail address */
    425         if (empty($user->user_email)) {
     438        if (empty ($user->user_email)) {
    426439                $errors['user_email'] = __("<strong>ERROR</strong>: please type an e-mail address");
    427         } else if (!is_email($user->user_email)) {
    428                 $errors['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct");
    429         }
    430 
    431         if ( count($errors) != 0 )
     440        } else
     441                if (!is_email($user->user_email)) {
     442                        $errors['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct");
     443                }
     444
     445        if (count($errors) != 0)
    432446                return $errors;
    433        
    434         if ( $update ) {
     447
     448        if ($update) {
    435449                $user_id = wp_update_user(get_object_vars($user));
    436450        } else {
     
    438452                wp_new_user_notification($user_id);
    439453        }
    440        
     454
    441455        return $errors;
    442456}
     
    446460
    447461        $id = (int) $id;
    448        
    449         if($reassign == 'novalue') {
     462
     463        if ($reassign == 'novalue') {
    450464                $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
    451        
     465
    452466                if ($post_ids) {
    453467                        $post_ids = implode(',', $post_ids);
    454                        
     468
    455469                        // Delete comments, *backs
    456470                        $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($post_ids)");
     
    462476                        $wpdb->query("DELETE FROM $wpdb->posts WHERE post_author = $id");
    463477                }
    464        
     478
    465479                // Clean links
    466480                $wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id");
    467481        } else {
    468                 $reassign = (int)$reassign;
     482                $reassign = (int) $reassign;
    469483                $wpdb->query("UPDATE $wpdb->posts SET post_author = {$reassign} WHERE post_author = {$id}");
    470484                $wpdb->query("UPDATE $wpdb->links SET link_owner = {$reassign} WHERE link_owner = {$id}");
     
    479493}
    480494
     495function get_link($link_id, $output = OBJECT) {
     496        global $wpdb;
     497       
     498        $link = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = '$link_id'");
     499
     500        if ( $output == OBJECT ) {
     501                return $link;
     502        } elseif ( $output == ARRAY_A ) {
     503                return get_object_vars($link);
     504        } elseif ( $output == ARRAY_N ) {
     505                return array_values(get_object_vars($link));
     506        } else {
     507                return $link;
     508        }
     509}
     510
     511function get_link_to_edit($link_id) {
     512        $link = get_link($link_id);
     513       
     514        $link->link_url = wp_specialchars($link->link_url, 1);
     515        $link->link_name = wp_specialchars($link->link_name, 1);
     516        $link->link_description = wp_specialchars($link->link_description);
     517        $link->link_notes = wp_specialchars($link->link_notes);
     518        $link->link_rss = wp_specialchars($link->link_rss);
     519       
     520        return $link;
     521}
     522
     523function add_link() {
     524        return edit_link();     
     525}
     526
     527function edit_link($link_id = '') {
     528        if (!current_user_can('manage_links'))
     529                die(__("Cheatin' uh ?"));
     530
     531        $_POST['link_url'] = wp_specialchars($_POST['link_url']);
     532        //$link_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $link_url) ? $link_url : 'http://'.$link_url;
     533        $_POST['link_name'] = wp_specialchars($_POST['link_name']);
     534        $_POST['link_image'] = wp_specialchars($_POST['link_image']);
     535        $_POST['link_rss'] = wp_specialchars($_POST['link_rss']);
     536        $auto_toggle = get_autotoggle($_POST['link_category']);
     537       
     538        // if we are in an auto toggle category and this one is visible then we
     539        // need to make the others invisible before we add this new one.
     540        // FIXME Add category toggle func.
     541        //if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
     542        //      $wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category");
     543        //}
     544
     545        if ( !empty($link_id) ) {
     546                $_POST['link_id'] = $link_id;
     547                return wp_update_link($_POST);
     548        } else {
     549                return wp_insert_link($_POST);
     550        }
     551}
     552
     553function wp_insert_link($linkdata) {
     554        global $wpdb;
     555       
     556        extract($linkdata);
     557
     558        $update = false;
     559        if ( !empty($link_id) )
     560                $update = true;
     561
     562        if ( empty($link_rating) )
     563                $link_rating = 0;       
     564
     565        if ( empty($link_target) )
     566                $link_target = '';     
     567
     568        if ( empty($link_visible) )
     569                $link_visible = 'Y';   
     570       
     571        if ( $update ) {
     572                $wpdb->query("UPDATE $wpdb->links SET link_url='$link_url',
     573                        link_name='$link_name', link_image='$link_image',
     574                        link_target='$link_target', link_category='$link_category',
     575                        link_visible='$link_visible', link_description='$link_description',
     576                        link_rating='$link_rating', link_rel='$link_rel',
     577                        link_notes='$link_notes', link_rss = '$link_rss'
     578                        WHERE link_id='$link_id'");
     579        } else {
     580                $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('$link_url','$link_name', '$link_image', '$link_target', '$link_category', '$link_description', '$link_visible', '$link_owner', '$link_rating', '$link_rel', '$link_notes', '$link_rss')");
     581                $link_id = $wpdb->insert_id;
     582        }
     583       
     584        if ( $update )
     585                do_action('edit_link', $link_id);
     586        else
     587                do_action('add_link', $link_id);
     588
     589        return $link_id;
     590}
     591
     592function wp_update_link($linkdata) {
     593        global $wpdb;
     594
     595        $link_id = (int) $linkdata['link_id'];
     596       
     597        $link = get_link($link_id, ARRAY_A);
     598       
     599        // Escape data pulled from DB.
     600        $link = add_magic_quotes($link);
     601       
     602        // Merge old and new fields with new fields overwriting old ones.
     603        $linkdata = array_merge($link, $linkdata);
     604
     605        return wp_insert_link($linkdata);
     606}
     607
     608function wp_delete_link($link_id) {
     609        global $wpdb;
     610
     611    return $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$link_id'");
     612}
     613
    481614function post_exists($title, $content = '', $post_date = '') {
    482615        global $wpdb;
    483        
    484         if ( !empty($post_date) )
     616
     617        if (!empty ($post_date))
    485618                $post_date = "AND post_date = '$post_date'";
    486619
    487         if ( ! empty($title) )
     620        if (!empty ($title))
    488621                return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$title' $post_date");
    489         else if ( ! empty($content) )
    490                 return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_content = '$content' $post_date");
     622        else
     623                if (!empty ($content))
     624                        return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_content = '$content' $post_date");
    491625
    492626        return 0;
     
    497631
    498632        return $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments
    499                 WHERE comment_author = '$comment_author' AND comment_date = '$comment_date'");
    500 }
    501 
    502 function url_shorten ($url) {
     633                        WHERE comment_author = '$comment_author' AND comment_date = '$comment_date'");
     634}
     635
     636function url_shorten($url) {
    503637        $short_url = str_replace('http://', '', stripslashes($url));
    504638        $short_url = str_replace('www.', '', $short_url);
     
    506640                $short_url = substr($short_url, 0, -1);
    507641        if (strlen($short_url) > 35)
    508                 $short_url =  substr($short_url, 0, 32).'...';
     642                $short_url = substr($short_url, 0, 32).'...';
    509643        return $short_url;
    510644}
    511645
    512646function selected($selected, $current) {
    513         if ($selected == $current) echo ' selected="selected"';
     647        if ($selected == $current)
     648                echo ' selected="selected"';
    514649}
    515650
    516651function checked($checked, $current) {
    517         if ($checked == $current) echo ' checked="checked"';
    518 }
    519 
    520 function return_categories_list( $parent = 0 ) {
     652        if ($checked == $current)
     653                echo ' checked="checked"';
     654}
     655
     656function return_categories_list($parent = 0) {
    521657        global $wpdb;
    522658        return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC");
     
    524660
    525661function get_nested_categories($default = 0, $parent = 0) {
    526  global $post_ID, $mode, $wpdb;
    527 
    528  if ($post_ID) {
    529    $checked_categories = $wpdb->get_col("
    530      SELECT category_id
    531      FROM $wpdb->categories, $wpdb->post2cat
    532      WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID'
    533      ");
    534 
    535    if(count($checked_categories) == 0)
    536    {
    537      // No selected categories, strange
    538      $checked_categories[] = $default;
    539    }
    540 
    541  } else {
    542    $checked_categories[] = $default;
    543  }
    544 
    545  $cats = return_categories_list($parent);
    546  $result = array();
    547 
    548         if ( is_array( $cats ) ) {
    549                 foreach($cats as $cat) {
     662        global $post_ID, $mode, $wpdb;
     663
     664        if ($post_ID) {
     665                $checked_categories = $wpdb->get_col("
     666                     SELECT category_id
     667                     FROM $wpdb->categories, $wpdb->post2cat
     668                     WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID'
     669                     ");
     670
     671                if (count($checked_categories) == 0) {
     672                        // No selected categories, strange
     673                        $checked_categories[] = $default;
     674                }
     675
     676        } else {
     677                $checked_categories[] = $default;
     678        }
     679
     680        $cats = return_categories_list($parent);
     681        $result = array ();
     682
     683        if (is_array($cats)) {
     684                foreach ($cats as $cat) {
    550685                        $result[$cat]['children'] = get_nested_categories($default, $cat);
    551686                        $result[$cat]['cat_ID'] = $cat;
     
    559694
    560695function write_nested_categories($categories) {
    561  foreach($categories as $category) {
    562    echo '<label for="category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'],
    563      '" type="checkbox" name="post_category[]" id="category-', $category['cat_ID'], '"',
    564      ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label>\n";
    565 
    566    if(isset($category['children'])) {
    567      echo "\n<span class='cat-nest'>\n";
    568      write_nested_categories($category['children']);
    569      echo "</span>\n";
    570    }
    571  }
     696        foreach ($categories as $category) {
     697                echo '<label for="category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label>\n";
     698
     699                if (isset ($category['children'])) {
     700                        echo "\n<span class='cat-nest'>\n";
     701                        write_nested_categories($category['children']);
     702                        echo "</span>\n";
     703                }
     704        }
    572705}
    573706
    574707function dropdown_categories($default = 0) {
    575  write_nested_categories(get_nested_categories($default));
    576 } 
     708        write_nested_categories(get_nested_categories($default));
     709}
    577710
    578711// Dandy new recursive multiple category stuff.
     
    580713        global $wpdb, $class;
    581714
    582         if ( !$categories )
     715        if (!$categories)
    583716                $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");
    584717
     
    589722                                $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");
    590723                                $pad = str_repeat('&#8212; ', $level);
    591                                 if ( current_user_can('manage_categories') )
    592                                         $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>" . __('Edit') . "</a></td><td><a href='categories.php?action=delete&amp;cat_ID=$category->cat_ID' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . sprintf(__("You are about to delete the category &quot;%s&quot;.  All of its posts will go to the default category.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars($category->cat_name, 1))  . "' );\" class='delete'>" .  __('Delete') . "</a>";
     724                                if (current_user_can('manage_categories'))
     725                                        $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td><td><a href='categories.php?action=delete&amp;cat_ID=$category->cat_ID' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '".sprintf(__("You are about to delete the category &quot;%s&quot;.  All of its posts will go to the default category.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars($category->cat_name, 1))."' );\" class='delete'>".__('Delete')."</a>";
    593726                                else
    594727                                        $edit = '';
    595                                
     728
    596729                                $class = ('alternate' == $class) ? '' : 'alternate';
    597730                                echo "<tr id='cat-$category->cat_ID' class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td>
    598                                 <td>$category->category_description</td>
    599                                 <td>$count</td>
    600                                 <td>$edit</td>
    601                                 </tr>";
    602                                 cat_rows($category->cat_ID, $level + 1, $categories);
     731                                                                <td>$category->category_description</td>
     732                                                                <td>$count</td>
     733                                                                <td>$edit</td>
     734                                                                </tr>";
     735                                cat_rows($category->cat_ID, $level +1, $categories);
    603736                        }
    604737                }
     
    608741}
    609742
    610 function page_rows( $parent = 0, $level = 0, $pages = 0 ) {
     743function page_rows($parent = 0, $level = 0, $pages = 0) {
    611744        global $wpdb, $class, $post;
    612745        if (!$pages)
     
    614747
    615748        if ($pages) {
    616                 foreach ($pages as $post) { start_wp();
     749                foreach ($pages as $post) {
     750                        start_wp();
    617751                        if ($post->post_parent == $parent) {
    618752                                $post->post_title = wp_specialchars($post->post_title);
     
    634768
    635769<?php
    636                                 page_rows($id, $level + 1, $pages);
     770
     771                                page_rows($id, $level +1, $pages);
    637772                        }
    638773                }
     
    648783        }
    649784        if ($categories) {
    650                 foreach ($categories as $category) { if ($currentcat != $category->cat_ID && $parent == $category->category_parent) {
    651                         $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");
    652                         $pad = str_repeat('&#8211; ', $level);
    653                         $category->cat_name = wp_specialchars($category->cat_name);
    654                         echo "\n\t<option value='$category->cat_ID'";
    655                         if ($currentparent == $category->cat_ID)
    656                                 echo " selected='selected'";
    657                         echo ">$pad$category->cat_name</option>";
    658                         wp_dropdown_cats($currentcat, $currentparent, $category->cat_ID, $level + 1, $categories);
    659                 } }
     785                foreach ($categories as $category) {
     786                        if ($currentcat != $category->cat_ID && $parent == $category->category_parent) {
     787                                $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");
     788                                $pad = str_repeat('&#8211; ', $level);
     789                                $category->cat_name = wp_specialchars($category->cat_name);
     790                                echo "\n\t<option value='$category->cat_ID'";
     791                                if ($currentparent == $category->cat_ID)
     792                                        echo " selected='selected'";
     793                                echo ">$pad$category->cat_name</option>";
     794                                wp_dropdown_cats($currentcat, $currentparent, $category->cat_ID, $level +1, $categories);
     795                        }
     796                }
    660797        } else {
    661798                return false;
     
    665802function wp_create_thumbnail($file, $max_side, $effect = '') {
    666803
    667     // 1 = GIF, 2 = JPEG, 3 = PNG
    668 
    669     if(file_exists($file)) {
    670         $type = getimagesize($file);
    671        
    672         // if the associated function doesn't exist - then it's not
    673         // handle. duh. i hope.
    674        
    675         if(!function_exists('imagegif') && $type[2] == 1) {
    676             $error = __('Filetype not supported. Thumbnail not created.');
    677         }elseif(!function_exists('imagejpeg') && $type[2] == 2) {
    678             $error = __('Filetype not supported. Thumbnail not created.');
    679         }elseif(!function_exists('imagepng') && $type[2] == 3) {
    680             $error = __('Filetype not supported. Thumbnail not created.');
    681         } else {
    682        
    683             // create the initial copy from the original file
    684             if($type[2] == 1) {
    685                 $image = imagecreatefromgif($file);
    686             } elseif($type[2] == 2) {
    687                 $image = imagecreatefromjpeg($file);
    688             } elseif($type[2] == 3) {
    689                 $image = imagecreatefrompng($file);
    690             }
    691            
     804                // 1 = GIF, 2 = JPEG, 3 = PNG
     805
     806        if (file_exists($file)) {
     807                $type = getimagesize($file);
     808
     809                // if the associated function doesn't exist - then it's not
     810                // handle. duh. i hope.
     811
     812                if (!function_exists('imagegif') && $type[2] == 1) {
     813                        $error = __('Filetype not supported. Thumbnail not created.');
     814                }
     815                elseif (!function_exists('imagejpeg') && $type[2] == 2) {
     816                        $error = __('Filetype not supported. Thumbnail not created.');
     817                }
     818                elseif (!function_exists('imagepng') && $type[2] == 3) {
     819                        $error = __('Filetype not supported. Thumbnail not created.');
     820                } else {
     821
     822                        // create the initial copy from the original file
     823                        if ($type[2] == 1) {
     824                                $image = imagecreatefromgif($file);
     825                        }
     826                        elseif ($type[2] == 2) {
     827                                $image = imagecreatefromjpeg($file);
     828                        }
     829                        elseif ($type[2] == 3) {
     830                                $image = imagecreatefrompng($file);
     831                        }
     832
    692833                        if (function_exists('imageantialias'))
    693                     imageantialias($image, TRUE);
    694            
    695             $image_attr = getimagesize($file);
    696            
    697             // figure out the longest side
    698            
    699             if($image_attr[0] > $image_attr[1]) {
    700                 $image_width = $image_attr[0];
    701                 $image_height = $image_attr[1];
    702                 $image_new_width = $max_side;
    703                
    704                 $image_ratio = $image_width/$image_new_width;
    705                 $image_new_height = $image_height/$image_ratio;
    706                 //width is > height
    707             } else {
    708                 $image_width = $image_attr[0];
    709                 $image_height = $image_attr[1];
    710                 $image_new_height = $max_side;
    711                
    712                 $image_ratio = $image_height/$image_new_height;
    713                 $image_new_width = $image_width/$image_ratio;
    714                 //height > width
    715             }
    716            
    717             $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
    718             @imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
    719            
    720             // move the thumbnail to it's final destination
    721            
    722             $path = explode('/', $file);
    723             $thumbpath = substr($file, 0, strrpos($file, '/')) . '/thumb-' . $path[count($path)-1];
    724            
    725             if($type[2] == 1) {
    726                 if(!imagegif($thumbnail, $thumbpath)) {
    727                     $error = __("Thumbnail path invalid");
    728                 }
    729             } elseif($type[2] == 2) {
    730                 if(!imagejpeg($thumbnail, $thumbpath)) {
    731                     $error = __("Thumbnail path invalid");
    732                 }
    733             } elseif($type[2] == 3) {
    734                 if(!imagepng($thumbnail, $thumbpath)) {
    735                     $error = __("Thumbnail path invalid");
    736                 }
    737             }
    738            
    739         }
    740     }
    741    
    742     if(!empty($error))
    743     {
    744         return $error;
    745     }
    746     else
    747     {
    748         return 1;
    749     }
     834                                imageantialias($image, TRUE);
     835
     836                        $image_attr = getimagesize($file);
     837
     838                        // figure out the longest side
     839
     840                        if ($image_attr[0] > $image_attr[1]) {
     841                                $image_width = $image_attr[0];
     842                                $image_height = $image_attr[1];
     843                                $image_new_width = $max_side;
     844
     845                                $image_ratio = $image_width / $image_new_width;
     846                                $image_new_height = $image_height / $image_ratio;
     847                                //width is > height
     848                        } else {
     849                                $image_width = $image_attr[0];
     850                                $image_height = $image_attr[1];
     851                                $image_new_height = $max_side;
     852
     853                                $image_ratio = $image_height / $image_new_height;
     854                                $image_new_width = $image_width / $image_ratio;
     855                                //height > width
     856                        }
     857
     858                        $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
     859                        @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
     860
     861                        // move the thumbnail to it's final destination
     862
     863                        $path = explode('/', $file);
     864                        $thumbpath = substr($file, 0, strrpos($file, '/')).'/thumb-'.$path[count($path) - 1];
     865
     866                        if ($type[2] == 1) {
     867                                if (!imagegif($thumbnail, $thumbpath)) {
     868                                        $error = __("Thumbnail path invalid");
     869                                }
     870                        }
     871                        elseif ($type[2] == 2) {
     872                                if (!imagejpeg($thumbnail, $thumbpath)) {
     873                                        $error = __("Thumbnail path invalid");
     874                                }
     875                        }
     876                        elseif ($type[2] == 3) {
     877                                if (!imagepng($thumbnail, $thumbpath)) {
     878                                        $error = __("Thumbnail path invalid");
     879                                }
     880                        }
     881
     882                }
     883        }
     884
     885        if (!empty ($error)) {
     886                return $error;
     887        } else {
     888                return 1;
     889        }
    750890}
    751891
     
    755895
    756896        return $wpdb->get_results("
    757                 SELECT meta_key, meta_value, meta_id, post_id
    758                 FROM $wpdb->postmeta
    759                 WHERE post_id = '$postid'
    760                 ORDER BY meta_key,meta_id",ARRAY_A);
     897                        SELECT meta_key, meta_value, meta_id, post_id
     898                        FROM $wpdb->postmeta
     899                        WHERE post_id = '$postid'
     900                        ORDER BY meta_key,meta_id", ARRAY_A);
    761901
    762902}
    763903
    764904function list_meta($meta) {
    765         global $post_ID;       
     905        global $post_ID;
    766906        // Exit if no meta
    767         if (!$meta) return;
     907        if (!$meta)
     908                return;
    768909        $count = 0;
    769910?>
     
    775916        </tr>
    776917<?php
    777                
     918
     919
    778920        foreach ($meta as $entry) {
    779                 ++$count;
    780                 if ( $count % 2 ) $style = 'alternate';
    781                 else $style = '';
    782                 if ( '_' == $entry['meta_key']{0} ) $style .= ' hidden';
     921                ++ $count;
     922                if ($count % 2)
     923                        $style = 'alternate';
     924                else
     925                        $style = '';
     926                if ('_' == $entry['meta_key'] { 0 })
     927                        $style .= ' hidden';
    783928                echo "
    784         <tr class='$style'>
    785                 <td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>
    786                 <td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>
    787                 <td align='center' width='10%'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='" . __('Update') ."' /></td>
    788                 <td align='center' width='10%'><input name='deletemeta[{$entry['meta_id']}]' type='submit' class='deletemeta' tabindex='6' value='" . __('Delete') ."' /></td>
    789         </tr>
    790 ";
     929                        <tr class='$style'>
     930                                <td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>
     931                                <td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>
     932                                <td align='center' width='10%'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__('Update')."' /></td>
     933                                <td align='center' width='10%'><input name='deletemeta[{$entry['meta_id']}]' type='submit' class='deletemeta' tabindex='6' value='".__('Delete')."' /></td>
     934                        </tr>
     935                ";
    791936        }
    792937        echo "
    793         </table>
    794 ";
     938                </table>
     939        ";
    795940}
    796941
     
    798943function get_meta_keys() {
    799944        global $wpdb;
    800        
     945
    801946        $keys = $wpdb->get_col("
    802                 SELECT meta_key
    803                 FROM $wpdb->postmeta
    804                 GROUP BY meta_key
    805                 ORDER BY meta_key");
    806        
     947                        SELECT meta_key
     948                        FROM $wpdb->postmeta
     949                        GROUP BY meta_key
     950                        ORDER BY meta_key");
     951
    807952        return $keys;
    808953}
     
    811956        global $wpdb;
    812957        $keys = $wpdb->get_col("
    813                 SELECT meta_key
    814                 FROM $wpdb->postmeta
    815                 GROUP BY meta_key
    816                 ORDER BY meta_id DESC
    817                 LIMIT 10");
     958                        SELECT meta_key
     959                        FROM $wpdb->postmeta
     960                        GROUP BY meta_key
     961                        ORDER BY meta_id DESC
     962                        LIMIT 10");
    818963?>
    819964<h3><?php _e('Add a new custom field:') ?></h3>
     
    829974<option value="#NONE#"><?php _e('- Select -'); ?></option>
    830975<?php
    831         foreach($keys as $key) {
     976
     977        foreach ($keys as $key) {
    832978                echo "\n\t<option value='$key'>$key</option>";
    833979        }
     
    843989<p class="submit"><input type="submit" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field &raquo;') ?>" /></p>
    844990<?php
     991
    845992}
    846993
    847994function add_meta($post_ID) {
    848995        global $wpdb;
    849        
    850         $metakeyselect = $wpdb->escape( stripslashes( trim($_POST['metakeyselect']) ) );
    851         $metakeyinput  = $wpdb->escape( stripslashes( trim($_POST['metakeyinput']) ) );
    852         $metavalue     = $wpdb->escape( stripslashes( trim($_POST['metavalue']) ) );
    853 
    854         if (!empty($metavalue) && ((('#NONE#' != $metakeyselect) && !empty($metakeyselect)) || !empty($metakeyinput))) {
     996
     997        $metakeyselect = $wpdb->escape(stripslashes(trim($_POST['metakeyselect'])));
     998        $metakeyinput = $wpdb->escape(stripslashes(trim($_POST['metakeyinput'])));
     999        $metavalue = $wpdb->escape(stripslashes(trim($_POST['metavalue'])));
     1000
     1001        if (!empty ($metavalue) && ((('#NONE#' != $metakeyselect) && !empty ($metakeyselect)) || !empty ($metakeyinput))) {
    8551002                // We have a key/value pair. If both the select and the
    8561003                // input for the key have data, the input takes precedence:
     
    8581005                if ('#NONE#' != $metakeyselect)
    8591006                        $metakey = $metakeyselect;
    860                                
     1007
    8611008                if ($metakeyinput)
    8621009                        $metakey = $metakeyinput; // default
    8631010
    8641011                $result = $wpdb->query("
    865                                 INSERT INTO $wpdb->postmeta
    866                                 (post_id,meta_key,meta_value)
    867                                 VALUES ('$post_ID','$metakey','$metavalue')
    868                         ");
     1012                                                INSERT INTO $wpdb->postmeta
     1013                                                (post_id,meta_key,meta_value)
     1014                                                VALUES ('$post_ID','$metakey','$metavalue')
     1015                                        ");
    8691016        }
    8701017} // add_meta
     
    8841031function touch_time($edit = 1, $for_post = 1) {
    8851032        global $month, $post, $comment;
    886         if ( $for_post && ('draft' == $post->post_status) ) {
     1033        if ($for_post && ('draft' == $post->post_status)) {
    8871034                $checked = 'checked="checked" ';
    8881035                $edit = false;
     
    8911038        }
    8921039
    893         echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" '.$checked.'/> <label for="timestamp">' . __('Edit timestamp') . '</label></legend>';
    894        
     1040        echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" '.$checked.'/> <label for="timestamp">'.__('Edit timestamp').'</label></legend>';
     1041
    8951042        $time_adj = time() + (get_settings('gmt_offset') * 3600);
    8961043        $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
     
    9031050
    9041051        echo "<select name=\"mm\">\n";
    905         for ($i=1; $i < 13; $i=$i+1) {
     1052        for ($i = 1; $i < 13; $i = $i +1) {
    9061053                echo "\t\t\t<option value=\"$i\"";
    9071054                if ($i == $mm)
    908                 echo " selected='selected'";
     1055                        echo " selected='selected'";
    9091056                if ($i < 10) {
    9101057                        $ii = "0".$i;
     
    9131060                }
    9141061                echo ">".$month["$ii"]."</option>\n";
    915         }
    916 
     1062        }
    9171063?>
    9181064</select>
     
    9241070<?php _e('Existing timestamp'); ?>:
    9251071        <?php
    926                 // We might need to readjust to display proper existing timestamp
    927                 if ( $for_post && ('draft' == $post->post_status) ) {
    928                         $jj = mysql2date('d', $post_date);
    929                         $mm = mysql2date('m', $post_date);
    930                         $aa = mysql2date('Y', $post_date);
    931                         $hh = mysql2date('H', $post_date);
    932                         $mn = mysql2date('i', $post_date);
    933                         $ss = mysql2date('s', $post_date);
    934                 }
    935                 echo "{$month[$mm]} $jj, $aa @ $hh:$mn"; ?>
     1072
     1073        // We might need to readjust to display proper existing timestamp
     1074        if ($for_post && ('draft' == $post->post_status)) {
     1075                $jj = mysql2date('d', $post_date);
     1076                $mm = mysql2date('m', $post_date);
     1077                $aa = mysql2date('Y', $post_date);
     1078                $hh = mysql2date('H', $post_date);
     1079                $mn = mysql2date('i', $post_date);
     1080                $ss = mysql2date('s', $post_date);
     1081        }
     1082        echo "{$month[$mm]} $jj, $aa @ $hh:$mn";
     1083?>
    9361084</fieldset>
    9371085        <?php
     1086
    9381087}
    9391088
    9401089function check_admin_referer() {
    941         $adminurl = strtolower( get_settings('siteurl') ) . '/wp-admin';
    942         $referer = strtolower( $_SERVER['HTTP_REFERER'] );
    943         if ( !strstr($referer, $adminurl) )
     1090        $adminurl = strtolower(get_settings('siteurl')).'/wp-admin';
     1091        $referer = strtolower($_SERVER['HTTP_REFERER']);
     1092        if (!strstr($referer, $adminurl))
    9441093                die(__('Sorry, you need to <a href="http://codex.wordpress.org/Enable_Sending_Referrers">enable sending referrers</a> for this feature to work.'));
    9451094        do_action('check_admin_referer');
     
    9631112                if ($markerdata) {
    9641113                        $state = true;
    965                         foreach($markerdata as $markerline) {
    966                                 if (strstr($markerline, "# BEGIN {$marker}")) $state = false;
    967                                 if ($state) fwrite($f, "{$markerline}\n");
     1114                        foreach ($markerdata as $markerline) {
     1115                                if (strstr($markerline, "# BEGIN {$marker}"))
     1116                                        $state = false;
     1117                                if ($state)
     1118                                        fwrite($f, "{$markerline}\n");
    9681119                                if (strstr($markerline, "# END {$marker}")) {
    9691120                                        fwrite($f, "# BEGIN {$marker}\n");
    970                                         if(is_array($insertion)) foreach($insertion as $insertline) fwrite($f, "{$insertline}\n");
     1121                                        if (is_array($insertion))
     1122                                                foreach ($insertion as $insertline)
     1123                                                        fwrite($f, "{$insertline}\n");
    9711124                                        fwrite($f, "# END {$marker}\n");
    9721125                                        $state = true;
     
    9771130                if (!$foundit) {
    9781131                        fwrite($f, "# BEGIN {$marker}\n");
    979                         foreach($insertion as $insertline) fwrite($f, "{$insertline}\n");
     1132                        foreach ($insertion as $insertline)
     1133                                fwrite($f, "{$insertline}\n");
    9801134                        fwrite($f, "# END {$marker}\n");
    9811135                }
     
    9911145// and END markers.
    9921146function extract_from_markers($filename, $marker) {
    993         $result = array();
     1147        $result = array ();
    9941148
    9951149        if (!file_exists($filename)) {
     
    9971151        }
    9981152
    999         if($markerdata = explode("\n", implode('', file($filename))));
     1153        if ($markerdata = explode("\n", implode('', file($filename))));
    10001154        {
    10011155                $state = false;
    1002                 foreach($markerdata as $markerline) {
    1003                         if(strstr($markerline, "# END {$marker}"))      $state = false;
    1004                         if($state) $result[] = $markerline;
    1005                         if(strstr($markerline, "# BEGIN {$marker}")) $state = true;
     1156                foreach ($markerdata as $markerline) {
     1157                        if (strstr($markerline, "# END {$marker}"))
     1158                                $state = false;
     1159                        if ($state)
     1160                                $result[] = $markerline;
     1161                        if (strstr($markerline, "# BEGIN {$marker}"))
     1162                                $state = true;
    10061163                }
    10071164        }
     
    10141171        $home_path = get_home_path();
    10151172
    1016         if (! $wp_rewrite->using_mod_rewrite_permalinks())
     1173        if (!$wp_rewrite->using_mod_rewrite_permalinks())
    10171174                return;
    10181175
    1019         if ( ! ((!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess')) )
     1176        if (!((!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess')))
    10201177                return;
    10211178
    1022         if (! $is_apache)
     1179        if (!$is_apache)
    10231180                return;
    10241181
     
    10271184}
    10281185
    1029 function the_quicktags () {
    1030 // Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP
    1031 if ( !strstr($_SERVER['HTTP_USER_AGENT'], 'Safari') ) :
    1032         echo '
    1033         <div id="quicktags">
    1034         <script src="../wp-includes/js/quicktags.js" type="text/javascript"></script>
    1035         <script type="text/javascript">edToolbar();</script>
    1036 ';
     1186function the_quicktags() {
     1187        // Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP
     1188        if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Safari'))
     1189                : echo '
     1190                        <div id="quicktags">
     1191                        <script src="../wp-includes/js/quicktags.js" type="text/javascript"></script>
     1192                        <script type="text/javascript">edToolbar();</script>
     1193                ';
    10371194        echo '</div>';
    1038 endif;
     1195        endif;
    10391196}
    10401197
    10411198function validate_current_theme() {
    10421199        $theme_loc = 'wp-content/themes';
    1043         $theme_root = ABSPATH . $theme_loc;
     1200        $theme_root = ABSPATH.$theme_loc;
    10441201
    10451202        $template = get_settings('template');
    10461203        $stylesheet = get_settings('stylesheet');
    10471204
    1048         if (($template != 'default') && (! file_exists("$theme_root/$template/index.php"))) {
     1205        if (($template != 'default') && (!file_exists("$theme_root/$template/index.php"))) {
    10491206                update_option('template', 'default');
    10501207                update_option('stylesheet', 'default');
     
    10531210        }
    10541211
    1055         if (($stylesheet != 'default') && (! file_exists("$theme_root/$stylesheet/style.css"))) {
     1212        if (($stylesheet != 'default') && (!file_exists("$theme_root/$stylesheet/style.css"))) {
    10561213                update_option('template', 'default');
    10571214                update_option('stylesheet', 'default');
     
    10741231        $theme = get_current_theme();
    10751232        $templates = $themes[$theme]['Template Files'];
    1076         $page_templates = array();
    1077 
    1078         if( is_array( $templates ) ) {
     1233        $page_templates = array ();
     1234
     1235        if (is_array($templates)) {
    10791236                foreach ($templates as $template) {
    1080                         $template_data = implode('', file(ABSPATH . $template));
     1237                        $template_data = implode('', file(ABSPATH.$template));
    10811238                        preg_match("|Template Name:(.*)|i", $template_data, $name);
    10821239                        preg_match("|Description:(.*)|i", $template_data, $description);
     
    10851242                        $description = $description[1];
    10861243
    1087                         if (! empty($name)) {
     1244                        if (!empty ($name)) {
    10881245                                $page_templates[trim($name)] = basename($template);
    10891246                        }
     
    10961253function page_template_dropdown($default = '') {
    10971254        $templates = get_page_templates();
    1098         foreach (array_keys($templates) as $template) :
    1099                 if ($default == $templates[$template]) $selected = " selected='selected'";
    1100                 else $selected = '';
    1101                 echo "\n\t<option value='" . $templates[$template] . "' $selected>$template</option>";
    1102                 endforeach;
     1255        foreach (array_keys($templates) as $template)
     1256                : if ($default == $templates[$template])
     1257                        $selected = " selected='selected'";
     1258                else
     1259                        $selected = '';
     1260        echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
     1261        endforeach;
    11031262}
    11041263
     
    11101269                foreach ($items as $item) {
    11111270                        // A page cannot be it's own parent.
    1112                         if (!empty($post_ID)) {
     1271                        if (!empty ($post_ID)) {
    11131272                                if ($item->ID == $post_ID) {
    11141273                                        continue;
     
    11221281
    11231282                        echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</option>";
    1124                         parent_dropdown($default, $item->ID, $level + 1);
     1283                        parent_dropdown($default, $item->ID, $level +1);
    11251284                }
    11261285        } else {
     
    11391298                //echo "parent array: " . $menu_array[2];
    11401299                if ($menu_array[2] == $parent) {
    1141                         if ( !current_user_can($menu_array[1]) ) {
     1300                        if (!current_user_can($menu_array[1])) {
    11421301                                return false;
    11431302                        } else {
     
    11471306        }
    11481307
    1149         if (isset($submenu[$parent])) {
     1308        if (isset ($submenu[$parent])) {
    11501309                foreach ($submenu[$parent] as $submenu_array) {
    11511310                        if ($submenu_array[2] == $pagenow) {
    1152                                 if ( !current_user_can($submenu_array[1]) ) {
     1311                                if (!current_user_can($submenu_array[1])) {
    11531312                                        return false;
    11541313                                } else {
     
    11581317                }
    11591318        }
    1160        
     1319
    11611320        return true;
    11621321}
     
    11691328        global $plugin_page;
    11701329
    1171         if (isset($title) && ! empty($title)) {
     1330        if (isset ($title) && !empty ($title)) {
    11721331                return $title;
    11731332        }
    11741333
    11751334        $parent = get_admin_page_parent();
    1176         if (empty($parent)) {
     1335        if (empty ($parent)) {
    11771336                foreach ($menu as $menu_array) {
    1178                         if (isset($menu_array[3])) {
     1337                        if (isset ($menu_array[3])) {
    11791338                                if ($menu_array[2] == $pagenow) {
    11801339                                        $title = $menu_array[3];
    11811340                                        return $menu_array[3];
    1182                                 } else if (isset($plugin_page) && ($plugin_page == $menu_array[2])) {
    1183                                         $title = $menu_array[3];
    1184                                         return $menu_array[3];
    1185                                 }
     1341                                } else
     1342                                        if (isset ($plugin_page) && ($plugin_page == $menu_array[2])) {
     1343                                                $title = $menu_array[3];
     1344                                                return $menu_array[3];
     1345                                        }
    11861346                        }
    11871347                }
     
    11891349                foreach (array_keys($submenu) as $parent) {
    11901350                        foreach ($submenu[$parent] as $submenu_array) {
    1191                                 if (isset($submenu_array[3])) {
     1351                                if (isset ($submenu_array[3])) {
    11921352                                        if ($submenu_array[2] == $pagenow) {
    11931353                                                $title = $submenu_array[3];
    11941354                                                return $submenu_array[3];
    1195                                         } else if (isset($plugin_page) && ($plugin_page == $submenu_array[2])) {
    1196                                                 $title = $submenu_array[3];
    1197                                                 return $submenu_array[3];
    1198                                         }
     1355                                        } else
     1356                                                if (isset ($plugin_page) && ($plugin_page == $submenu_array[2])) {
     1357                                                        $title = $submenu_array[3];
     1358                                                        return $submenu_array[3];
     1359                                                }
    11991360                                }
    12001361                        }
     
    12121373        global $plugin_page;
    12131374
    1214         if (isset($parent_file) && ! empty($parent_file)) {
     1375        if (isset ($parent_file) && !empty ($parent_file)) {
    12151376                return $parent_file;
    12161377        }
    12171378
    1218         if ($pagenow == 'admin.php' && isset($plugin_page)) {
     1379        if ($pagenow == 'admin.php' && isset ($plugin_page)) {
    12191380                foreach ($menu as $parent_menu) {
    12201381                        if ($parent_menu[2] == $plugin_page) {
     
    12241385                }
    12251386        }
    1226                
     1387
    12271388        foreach (array_keys($submenu) as $parent) {
    12281389                foreach ($submenu[$parent] as $submenu_array) {
     
    12301391                                $parent_file = $parent;
    12311392                                return $parent;
    1232                         } else if (isset($plugin_page) && ($plugin_page == $submenu_array[2])) {
    1233                                 $parent_file = $parent;
    1234                                 return $parent;
    1235                         }
     1393                        } else
     1394                                if (isset ($plugin_page) && ($plugin_page == $submenu_array[2])) {
     1395                                        $parent_file = $parent;
     1396                                        return $parent;
     1397                                }
    12361398                }
    12371399        }
     
    12461408        $file = plugin_basename($file);
    12471409
    1248         $menu[] = array($menu_title, $access_level, $file, $page_title);
     1410        $menu[] = array ($menu_title, $access_level, $file, $page_title);
    12491411
    12501412        $admin_page_hooks[$file] = sanitize_title($menu_title);
    12511413
    12521414        $hookname = get_plugin_page_hookname($file, '');
    1253         if ( !empty($function) && !empty($hookname) )
     1415        if (!empty ($function) && !empty ($hookname))
    12541416                add_action($hookname, $function);
    12551417
     
    12681430        // parent file someone is trying to link back to the parent manually.  In
    12691431        // this case, don't automatically add a link back to avoid duplication.
    1270         if (! isset($submenu[$parent]) && $file != $parent) {
     1432        if (!isset ($submenu[$parent]) && $file != $parent) {
    12711433                foreach ($menu as $parent_menu) {
    12721434                        if ($parent_menu[2] == $parent) {
     
    12751437                }
    12761438        }
    1277        
    1278         $submenu[$parent][] = array($menu_title, $access_level, $file, $page_title);
     1439
     1440        $submenu[$parent][] = array ($menu_title, $access_level, $file, $page_title);
    12791441
    12801442        $hookname = get_plugin_page_hookname($file, $parent);
    1281         if ( !empty($function) && !empty($hookname) )
     1443        if (!empty ($function) && !empty ($hookname))
    12821444                add_action($hookname, $function);
    12831445
     
    12941456
    12951457function add_theme_page($page_title, $menu_title, $access_level, $file, $function = '') {
    1296         return add_submenu_page('themes.php', $page_title, $menu_title, $access_level, $file, $function);
    1297 }
    1298 
     1458        return add_submenu_page('themes.php', $page_title, $menu_title, $access_level, $file, $function);
     1459}
    12991460
    13001461function validate_file($file, $allowed_files = '') {
    1301         if ( false !== strpos($file, './'))
     1462        if (false !== strpos($file, './'))
    13021463                return 1;
    1303        
    1304         if (':' == substr($file,1,1))
     1464
     1465        if (':' == substr($file, 1, 1))
    13051466                return 2;
    13061467
    1307         if ( !empty($allowed_files) && (! in_array($file, $allowed_files)) )
     1468        if (!empty ($allowed_files) && (!in_array($file, $allowed_files)))
    13081469                return 3;
    13091470
     
    13161477        $code = validate_file($file, $allowed_files);
    13171478
    1318         if (! $code)
     1479        if (!$code)
    13191480                return $file;
    13201481
    13211482        switch ($code) {
    1322         case 1:
    1323                 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.'));
    1324        
    1325         case 2:
    1326                 die (__('Sorry, can&#8217;t call files with their real path.'));
    1327 
    1328         case 3:
    1329                 die (__('Sorry, that file cannot be edited.'));
     1483                case 1 :
     1484                        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.'));
     1485
     1486                case 2 :
     1487                        die(__('Sorry, can&#8217;t call files with their real path.'));
     1488
     1489                case 3 :
     1490                        die(__('Sorry, that file cannot be edited.'));
    13301491        }
    13311492}
     
    13331494function get_home_path() {
    13341495        $home = get_settings('home');
    1335         if ( $home != '' && $home != get_settings('siteurl') ) {
     1496        if ($home != '' && $home != get_settings('siteurl')) {
    13361497                $home_path = parse_url($home);
    13371498                $home_path = $home_path['path'];
    13381499                $root = str_replace($_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"]);
    1339                 $home_path = trailingslashit($root . $home_path);
     1500                $home_path = trailingslashit($root.$home_path);
    13401501        } else {
    13411502                $home_path = ABSPATH;
     
    13461507
    13471508function get_real_file_to_edit($file) {
    1348         if ('index.php' == $file ||
    1349                          '.htaccess' == $file) {
    1350                 $real_file = get_home_path() . $file;
    1351         } else {
    1352                 $real_file = ABSPATH . $file;
     1509        if ('index.php' == $file || '.htaccess' == $file) {
     1510                $real_file = get_home_path().$file;
     1511        } else {
     1512                $real_file = ABSPATH.$file;
    13531513        }
    13541514
     
    13561516}
    13571517
    1358 $wp_file_descriptions =
    1359         array(
    1360         'index.php' => __('Main Index Template'),
    1361         'style.css' => __('Stylesheet'),
    1362         'comments.php' => __('Comments'),
    1363         'comments-popup.php' => __('Popup Comments'),
    1364         'footer.php' => __('Footer'),
    1365         'header.php' => __('Header'),
    1366         'sidebar.php' => __('Sidebar'),
    1367         'archive.php' => __('Archives'),
    1368         'category.php' => __('Category Template'),
    1369         'page.php' => __('Page Template'),
    1370         'search.php' => __('Search Results'),
    1371         'single.php' => __('Single Post'),
    1372         '404.php' => __('404 Template'),
    1373         'my-hacks.php' => __('my-hacks.php (legacy hacks support)'),
    1374         '.htaccess' => __('.htaccess (for rewrite rules)'),
     1518$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)'),
    13751519        // Deprecated files
    1376         'wp-layout.css' => __('Stylesheet'),
    1377         'wp-comments.php' => __('Comments Template'),
    1378         'wp-comments-popup.php' => __('Popup Comments Template')
    1379         );
     1520        'wp-layout.css' => __('Stylesheet'), 'wp-comments.php' => __('Comments Template'), 'wp-comments-popup.php' => __('Popup Comments Template'));
    13801521
    13811522function get_file_description($file) {
    13821523        global $wp_file_descriptions;
    13831524
    1384         if ( isset($wp_file_descriptions[basename($file)] ) ) {
     1525        if (isset ($wp_file_descriptions[basename($file)])) {
    13851526                return $wp_file_descriptions[basename($file)];
    1386         } elseif ( file_exists( ABSPATH . $file ) ) {
    1387                 $template_data = implode('', file(ABSPATH . $file));
    1388                 if ( preg_match("|Template Name:(.*)|i", $template_data, $name) )
     1527        }
     1528        elseif (file_exists(ABSPATH.$file)) {
     1529                $template_data = implode('', file(ABSPATH.$file));
     1530                if (preg_match("|Template Name:(.*)|i", $template_data, $name))
    13891531                        return $name[1];
    13901532        }
    13911533
    1392         return basename( $file );
     1534        return basename($file);
    13931535}
    13941536
     
    14001542                $oldfiles = array_reverse($oldfiles);
    14011543                $oldfiles = array_unique($oldfiles);
    1402                 if ( 5 < count($oldfiles) )
     1544                if (5 < count($oldfiles))
    14031545                        array_pop($oldfiles);
    14041546        } else {
     
    14151557        preg_match("|Author:(.*)|i", $plugin_data, $author_name);
    14161558        preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri);
    1417         if ( preg_match("|Version:(.*)|i", $plugin_data, $version) )
     1559        if (preg_match("|Version:(.*)|i", $plugin_data, $version))
    14181560                $version = $version[1];
    14191561        else
    1420                 $version ='';
     1562                $version = '';
    14211563
    14221564        $description = wptexturize($description[1]);
     
    14261568        $plugin = $name;
    14271569        if ('' != $plugin_uri[1] && '' != $name) {
    1428                 $plugin = '<a href="' . $plugin_uri[1] . '" title="' . __('Visit plugin homepage') . '">' . $plugin . '</a>';
     1570                $plugin = '<a href="'.$plugin_uri[1].'" title="'.__('Visit plugin homepage').'">'.$plugin.'</a>';
    14291571        }
    14301572
     
    14321574                $author = $author_name[1];
    14331575        } else {
    1434                 $author = '<a href="' . $author_uri[1] . '" title="' . __('Visit author homepage') . '">' . $author_name[1] . '</a>';
    1435         }
    1436 
    1437         return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]);
     1576                $author = '<a href="'.$author_uri[1].'" title="'.__('Visit author homepage').'">'.$author_name[1].'</a>';
     1577        }
     1578
     1579        return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]);
    14381580}
    14391581
     
    14411583        global $wp_plugins;
    14421584
    1443         if (isset($wp_plugins)) {
     1585        if (isset ($wp_plugins)) {
    14441586                return $wp_plugins;
    14451587        }
    14461588
    1447         $wp_plugins = array();
     1589        $wp_plugins = array ();
    14481590        $plugin_loc = 'wp-content/plugins';
    1449         $plugin_root = ABSPATH . $plugin_loc;
     1591        $plugin_root = ABSPATH.$plugin_loc;
    14501592
    14511593        // Files in wp-content/plugins directory
    14521594        $plugins_dir = @ dir($plugin_root);
    14531595        if ($plugins_dir) {
    1454                 while(($file = $plugins_dir->read()) !== false) {
    1455                         if ( preg_match('|^\.+$|', $file) )
     1596                while (($file = $plugins_dir->read()) !== false) {
     1597                        if (preg_match('|^\.+$|', $file))
    14561598                                continue;
    1457                         if (is_dir($plugin_root . '/' . $file)) {
    1458                                 $plugins_subdir = @ dir($plugin_root . '/' . $file);
     1599                        if (is_dir($plugin_root.'/'.$file)) {
     1600                                $plugins_subdir = @ dir($plugin_root.'/'.$file);
    14591601                                if ($plugins_subdir) {
    1460                                         while(($subfile = $plugins_subdir->read()) !== false) {
    1461                                                 if ( preg_match('|^\.+$|', $subfile) )
     1602                                        while (($subfile = $plugins_subdir->read()) !== false) {
     1603                                                if (preg_match('|^\.+$|', $subfile))
    14621604                                                        continue;
    1463                                                 if ( preg_match('|\.php$|', $subfile) )
     1605                                                if (preg_match('|\.php$|', $subfile))
    14641606                                                        $plugin_files[] = "$file/$subfile";
    14651607                                        }
    14661608                                }
    14671609                        } else {
    1468                                 if ( preg_match('|\.php$|', $file) )
     1610                                if (preg_match('|\.php$|', $file))
    14691611                                        $plugin_files[] = $file;
    14701612                        }
     
    14781620        sort($plugin_files);
    14791621
    1480         foreach($plugin_files as $plugin_file) {
     1622        foreach ($plugin_files as $plugin_file) {
    14811623                $plugin_data = get_plugin_data("$plugin_root/$plugin_file");
    1482          
    1483                 if (empty($plugin_data['Name'])) {
     1624
     1625                if (empty ($plugin_data['Name'])) {
    14841626                        continue;
    14851627                }
     
    14961638        $parent = get_admin_page_parent();
    14971639
    1498         if ( empty($parent_page) || 'admin.php' == $parent_page ) {
    1499                 if ( isset($admin_page_hooks[$plugin_page]) )
     1640        if (empty ($parent_page) || 'admin.php' == $parent_page) {
     1641                if (isset ($admin_page_hooks[$plugin_page]))
    15001642                        $page_type = 'toplevel';
    1501                 else if ( isset($admin_page_hooks[$parent]) )
    1502                         $page_type = $admin_page_hooks[$parent];
    1503         } else if ( isset($admin_page_hooks[$parent_page]) ) {
    1504                 $page_type = $admin_page_hooks[$parent_page];
    1505         } else {
    1506                 $page_type = 'admin';
    1507         }
     1643                else
     1644                        if (isset ($admin_page_hooks[$parent]))
     1645                                $page_type = $admin_page_hooks[$parent];
     1646        } else
     1647                if (isset ($admin_page_hooks[$parent_page])) {
     1648                        $page_type = $admin_page_hooks[$parent_page];
     1649                } else {
     1650                        $page_type = 'admin';
     1651                }
    15081652
    15091653        $plugin_name = preg_replace('!\.php!', '', $plugin_page);
    15101654
    1511         return $page_type . '_page_' . $plugin_name;
     1655        return $page_type.'_page_'.$plugin_name;
    15121656}
    15131657
    15141658function get_plugin_page_hook($plugin_page, $parent_page) {
    15151659        global $wp_filter;
    1516        
     1660
    15171661        $hook = get_plugin_page_hookname($plugin_page, $parent_page);
    1518         if ( isset($wp_filter[$hook]) )
     1662        if (isset ($wp_filter[$hook]))
    15191663                return $hook;
    15201664        else
     
    15251669        $getit = __('WordPress recommends a better browser');
    15261670        echo '
    1527         <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>
    1528         ';
    1529 }
    1530 if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) )
     1671                <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>
     1672                ';
     1673}
     1674if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
    15311675        add_action('admin_footer', 'browse_happy');
    15321676
    1533 function documentation_link( $for ) {
     1677function documentation_link($for) {
    15341678        return;
    15351679}
     
    15371681function register_importer($id, $name, $description, $callback) {
    15381682        global $wp_importers;
    1539        
    1540         $wp_importers[$id] = array($name, $description, $callback);
     1683
     1684        $wp_importers[$id] = array ($name, $description, $callback);
    15411685}
    15421686
     
    15621706        return $ct;
    15631707}
    1564 
    15651708?>
  • trunk/wp-admin/link-add.php

    r2762 r2889  
    7676         <tr>
    7777           <th width="33%" scope="row"><?php _e('URI:') ?></th>
    78            <td width="67%"><input type="text" name="linkurl" value="<?php echo wp_specialchars($_GET['linkurl'], 1); ?>" style="width: 95%;" /></td>
     78           <td width="67%"><input type="text" name="link_url" value="<?php echo wp_specialchars($_GET['linkurl'], 1); ?>" style="width: 95%;" /></td>
    7979         </tr>
    8080         <tr>
    8181           <th scope="row"><?php _e('Link Name:') ?></th>
    82            <td><input type="text" name="name" value="<?php echo wp_specialchars( urldecode($_GET['name']), 1 ); ?>" style="width: 95%" /></td>
     82           <td><input type="text" name="link_name" value="<?php echo wp_specialchars( urldecode($_GET['name']), 1 ); ?>" style="width: 95%" /></td>
    8383         </tr>
    8484         <tr>
    8585                <th scope="row"><?php _e('Short description:') ?></th>
    86                 <td><input type="text" name="description" value="" style="width: 95%" /></td>
     86                <td><input type="text" name="link_description" value="" style="width: 95%" /></td>
    8787                </tr>
    8888        <tr>
    8989           <th scope="row"><?php _e('Category:') ?></th>
    90            <td><?php category_dropdown('category'); ?></td>
     90           <td><?php category_dropdown('link_category'); ?></td>
    9191         </tr>
    9292</table>
     
    100100            <tr>
    101101                <th width="33%" scope="row"><?php _e('rel:') ?></th>
    102                 <td width="67%"><input type="text" name="rel" id="rel" size="50" value="<?php echo $link_rel; ?>" /></td>
     102                <td width="67%"><input type="text" name="link_rel" id="rel" size="50" value="<?php echo $link_rel; ?>" /></td>
    103103                </tr>
    104104            <tr>
     
    213213         <tr>
    214214           <th width="33%" scope="row"><?php _e('Image URI:') ?></th>
    215            <td width="67%"><input type="text" name="image" size="50" value="" style="width: 95%" /></td>
     215           <td width="67%"><input type="text" name="link_image" size="50" value="" style="width: 95%" /></td>
    216216         </tr>
    217217<tr>
    218218           <th scope="row"><?php _e('RSS URI:') ?> </th>
    219            <td><input name="rss_uri" type="text" id="rss_uri" value="" size="50" style="width: 95%" /></td>
     219           <td><input name="link_rss" type="text" id="rss_uri" value="" size="50" style="width: 95%" /></td>
    220220         </tr>
    221221         <tr>
    222222           <th scope="row"><?php _e('Notes:') ?></th>
    223            <td><textarea name="notes" cols="50" rows="10" style="width: 95%"></textarea></td>
     223           <td><textarea name="link_notes" cols="50" rows="10" style="width: 95%"></textarea></td>
    224224         </tr>
    225225         <tr>
    226226           <th scope="row"><?php _e('Rating:') ?></th>
    227            <td><select name="rating" size="1">
     227           <td><select name="link_rating" size="1">
    228228             <?php
    229229    for ($r = 0; $r < 10; $r++) {
     
    237237           <th scope="row"><?php _e('Target') ?></th>
    238238           <td><label>
    239              <input type="radio" name="target" value="_blank" />
     239             <input type="radio" name="link_target" value="_blank" />
    240240             <code>_blank</code></label>
    241241<br />
    242 <label><input type="radio" name="target" value="_top" />
     242<label><input type="radio" name="link_target" value="_top" />
    243243<code>_top</code></label>
    244244<br />
    245 <label><input type="radio" name="target" value="" checked="checked" />
     245<label><input type="radio" name="link_target" value="" checked="checked" />
    246246<?php _e('none') ?></label>
    247247<?php _e('(Note that the <code>target</code> attribute is illegal in XHTML 1.1 and 1.0 Strict.)') ?></td>
     
    250250           <th scope="row"><?php _e('Visible:') ?></th>
    251251           <td><label>
    252              <input type="radio" name="visible" checked="checked" value="Y" />
     252             <input type="radio" name="link_visible" checked="checked" value="Y" />
    253253<?php _e('Yes') ?></label><br />
    254 <label><input type="radio" name="visible" value="N" /> <input type="hidden" name="action" value="Add" />
     254<label><input type="radio" name="link_visible" value="N" /> <input type="hidden" name="action" value="Add" />
    255255<?php _e('No') ?></label></td>
    256256         </tr>
  • trunk/wp-admin/link-manager.php

    r2832 r2889  
    160160    check_admin_referer();
    161161
    162     $link_url = wp_specialchars($_POST['linkurl']);
    163     $link_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $link_url) ? $link_url : 'http://' . $link_url;
    164     $link_name = wp_specialchars($_POST['name']);
    165     $link_image = wp_specialchars($_POST['image']);
    166     $link_target = $_POST['target'];
    167     $link_category = $_POST['category'];
    168     $link_description = $_POST['description'];
    169     $link_visible = $_POST['visible'];
    170     $link_rating = $_POST['rating'];
    171     $link_rel = $_POST['rel'];
    172     $link_notes = $_POST['notes'];
    173         $link_rss_uri =  wp_specialchars($_POST['rss_uri']);
    174     $auto_toggle = get_autotoggle($link_category);
     162        add_link();
     163       
     164    header('Location: ' . $_SERVER['HTTP_REFERER'] . '?added=true');
     165    break;
     166  } // end Add
     167
     168  case 'editlink':
     169  {
     170 
     171        check_admin_referer();
     172       
     173        if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
     174                $cat_id = $links_show_cat_id;
     175
     176        if (!isset($cat_id) || ($cat_id == '')) {
     177                if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
     178                        $cat_id = 'All';
     179        }
     180        $links_show_cat_id = $cat_id;
     181
     182        $link_id = (int) $_POST['link_id'];
     183        edit_link($link_id);
     184       
     185    setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
     186    wp_redirect($this_file);
     187    break;
     188  } // end Save
     189
     190  case 'Delete':
     191  {
     192    check_admin_referer();
    175193
    176194    if ( !current_user_can('manage_links') )
    177195      die (__("Cheatin' uh ?"));
    178196
    179     // if we are in an auto toggle category and this one is visible then we
    180     // need to make the others invisible before we add this new one.
    181     if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
    182       $wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category");
    183     }
    184     $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) " .
    185       " VALUES('" . $link_url . "','"
    186            . $link_name . "', '"
    187            . $link_image . "', '$link_target', $link_category, '"
    188            . $link_description . "', '$link_visible', $user_ID, $link_rating, '" . $link_rel . "', '" . $link_notes . "', '$link_rss_uri')");
    189 
    190     header('Location: ' . $_SERVER['HTTP_REFERER'] . '?added=true');
    191     break;
    192   } // end Add
    193 
    194   case 'editlink':
    195   {
    196     if (isset($submit)) {
    197 
    198       if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
    199         $cat_id = $links_show_cat_id;
    200 
    201       if (!isset($cat_id) || ($cat_id == '')) {
    202         if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
    203           $cat_id = 'All';
    204       }
    205       $links_show_cat_id = $cat_id;
    206 
    207       check_admin_referer();
    208 
    209       $link_id = (int) $_POST['link_id'];
    210       $link_url = wp_specialchars($_POST['linkurl']);
    211       $link_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $link_url) ? $link_url : 'http://' . $link_url;
    212       $link_name = wp_specialchars($_POST['name']);
    213       $link_image = wp_specialchars($_POST['image']);
    214       $link_target = wp_specialchars($_POST['target']);
    215       $link_category = $_POST['category'];
    216       $link_description = $_POST['description'];
    217       $link_visible = $_POST['visible'];
    218       $link_rating = $_POST['rating'];
    219       $link_rel = $_POST['rel'];
    220       $link_notes = $_POST['notes'];
    221           $link_rss_uri =  $_POST['rss_uri'];
    222       $auto_toggle = get_autotoggle($link_category);
    223 
    224       if ( !current_user_can('manage_links') )
    225         die (__("Cheatin' uh ?"));
    226 
    227       // if we are in an auto toggle category and this one is visible then we
    228       // need to make the others invisible before we update this one.
    229       if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
    230         $wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category");
    231       }
    232 
    233       $wpdb->query("UPDATE $wpdb->links SET link_url='" . $link_url . "',
    234           link_name='" . $link_name . "',\n link_image='" . $link_image . "',
    235           link_target='$link_target',\n link_category=$link_category,
    236           link_visible='$link_visible',\n link_description='" . $link_description . "',
    237           link_rating=$link_rating,
    238           link_rel='" . $link_rel . "',
    239           link_notes='" . $link_notes . "',
    240           link_rss = '$link_rss_uri'
    241           WHERE link_id=$link_id");
    242     } // end if save
    243     setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
    244     wp_redirect($this_file);
    245     break;
    246   } // end Save
    247 
    248   case 'Delete':
    249   {
    250     check_admin_referer();
    251 
    252197    $link_id = (int) $_GET['link_id'];
    253198
    254     if ( !current_user_can('manage_links') )
    255       die (__("Cheatin' uh ?"));
    256 
    257     $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = $link_id");
    258 
     199        wp_delete_link($link_id);
     200       
    259201    if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
    260202        $cat_id = $links_show_cat_id;
     
    277219
    278220    $link_id = (int) $_GET['link_id'];
    279     $row = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = $link_id");
    280 
    281     if ($row) {
    282       $link_url = wp_specialchars($row->link_url, 1);
    283       $link_name = wp_specialchars($row->link_name, 1);
    284       $link_image = $row->link_image;
    285       $link_target = $row->link_target;
    286       $link_category = $row->link_category;
    287       $link_description = wp_specialchars($row->link_description);
    288       $link_visible = $row->link_visible;
    289       $link_rating = $row->link_rating;
    290       $link_rel = $row->link_rel;
    291       $link_notes = wp_specialchars($row->link_notes);
    292           $link_rss_uri = wp_specialchars($row->link_rss);
    293     } else {
    294                 die( __('Link not found.') );
    295         }
    296 
     221 
     222        if ( !$link = get_link_to_edit($link_id) )
     223                die( __('Link not found.') );
    297224?>
    298225
     
    305232         <tr>
    306233           <th width="33%" scope="row"><?php _e('URI:') ?></th>
    307            <td width="67%"><input type="text" name="linkurl" value="<?php echo $link_url; ?>" style="width: 95%;" /></td>
     234           <td width="67%"><input type="text" name="link_url" value="<?php echo $link->link_url; ?>" style="width: 95%;" /></td>
    308235         </tr>
    309236         <tr>
    310237           <th scope="row"><?php _e('Link Name:') ?></th>
    311            <td><input type="text" name="name" value="<?php echo $link_name; ?>" style="width: 95%" /></td>
     238           <td><input type="text" name="link_name" value="<?php echo $link->link_name; ?>" style="width: 95%" /></td>
    312239         </tr>
    313240         <tr>
    314241            <th scope="row"><?php _e('Short description:') ?></th>
    315                 <td><input type="text" name="description" value="<?php echo $link_description; ?>" style="width: 95%" /></td>
     242                <td><input type="text" name="link_description" value="<?php echo $link->link_description; ?>" style="width: 95%" /></td>
    316243                </tr>
    317244        <tr>
    318245           <th scope="row"><?php _e('Category:') ?></th>
    319            <td><?php category_dropdown('category', $link_category); ?></td>
     246           <td><?php category_dropdown('link_category', $link->link_category); ?></td>
    320247         </tr>
    321248</table>
     
    329256            <tr>
    330257                <th width="33%" scope="row"><?php _e('rel:') ?></th>
    331                 <td width="67%"><input type="text" name="rel" id="rel" size="50" value="<?php echo $link_rel; ?>" /></td>
     258                <td width="67%"><input type="text" name="link_rel" id="rel" size="50" value="<?php echo $link->link_rel; ?>" /></td>
    332259                </tr>
    333260            <tr>
     
    442369         <tr>
    443370           <th width="33%" scope="row"><?php _e('Image URI:') ?></th>
    444            <td width="67%"><input type="text" name="image" size="50" value="<?php echo $link_image; ?>" style="width: 95%" /></td>
     371           <td width="67%"><input type="text" name="link_image" size="50" value="<?php echo $link->link_image; ?>" style="width: 95%" /></td>
    445372         </tr>
    446373<tr>
    447374           <th scope="row"><?php _e('RSS URI:') ?> </th>
    448            <td><input name="rss_uri" type="text" id="rss_uri" value="<?php echo $link_rss_uri; ?>" size="50" style="width: 95%" /></td>
     375           <td><input name="link_rss" type="text" id="rss_uri" value="<?php echo $link->link_rss; ?>" size="50" style="width: 95%" /></td>
    449376         </tr>
    450377         <tr>
    451378           <th scope="row"><?php _e('Notes:') ?></th>
    452            <td><textarea name="notes" cols="50" rows="10" style="width: 95%"><?php echo $link_notes; ?></textarea></td>
     379           <td><textarea name="link_notes" cols="50" rows="10" style="width: 95%"><?php echo $link->link_notes; ?></textarea></td>
    453380         </tr>
    454381         <tr>
    455382           <th scope="row"><?php _e('Rating:') ?></th>
    456            <td><select name="rating" size="1">
     383           <td><select name="link_rating" size="1">
    457384<?php
    458385    for ($r = 0; $r < 10; $r++) {
    459386      echo('            <option value="'.$r.'" ');
    460       if ($link_rating == $r)
     387      if ($link->link_rating == $r)
    461388        echo 'selected="selected"';
    462389      echo('>'.$r.'</option>');
     
    469396           <th scope="row"><?php _e('Target') ?></th>
    470397           <td><label>
    471           <input type="radio" name="target" value="_blank"   <?php echo(($link_target == '_blank') ? 'checked="checked"' : ''); ?> />
     398          <input type="radio" name="target" value="_blank"   <?php echo(($link->link_target == '_blank') ? 'checked="checked"' : ''); ?> />
    472399          <code>_blank</code></label><br />
    473400<label>
    474 <input type="radio" name="target" value="_top" <?php echo(($link_target == '_top') ? 'checked="checked"' : ''); ?> />
     401<input type="radio" name="target" value="_top" <?php echo(($link->link_target == '_top') ? 'checked="checked"' : ''); ?> />
    475402<code>_top</code></label><br />
    476403<label>
    477 <input type="radio" name="target" value=""     <?php echo(($link_target == '') ? 'checked="checked"' : ''); ?> />
     404<input type="radio" name="link_target" value=""     <?php echo(($link->link_target == '') ? 'checked="checked"' : ''); ?> />
    478405<?php _e('none') ?></label><br />
    479406<?php _e('(Note that the <code>target</code> attribute is illegal in XHTML 1.1 and 1.0 Strict.)') ?></td>
     
    482409           <th scope="row"><?php _e('Visible:') ?></th>
    483410           <td><label>
    484              <input type="radio" name="visible" <?php if ($link_visible == 'Y') echo "checked='checked'"; ?> value="Y" />
     411             <input type="radio" name="link_visible" <?php if ($link->link_visible == 'Y') echo "checked='checked'"; ?> value="Y" />
    485412<?php _e('Yes') ?></label><br /><label>
    486 <input type="radio" name="visible" <?php if ($link_visible == 'N') echo "checked='checked'"; ?> value="N" />
     413<input type="radio" name="visible" <?php if ($link->link_visible == 'N') echo "checked='checked'"; ?> value="N" />
    487414<?php _e('No') ?></label></td>
    488415         </tr>
  • trunk/wp-admin/profile-update.php

    r2872 r2889  
    55check_admin_referer();
    66
    7 $errors = update_user($user_ID);
     7$errors = edit_user($user_ID);
    88
    99if (count($errors) != 0) {
  • trunk/wp-admin/user-edit.php

    r2872 r2889  
    3838        $errors['head'] = __('You do not have permission to edit this user.');
    3939else
    40         $errors = update_user($user_id);
     40        $errors = edit_user($user_id);
    4141
    4242if(count($errors) == 0) {
Note: See TracChangeset for help on using the changeset viewer.