Make WordPress Core


Ignore:
Timestamp:
12/05/2003 09:41:27 AM (21 years ago)
Author:
saxmatt
Message:

Beta multiple category support. Major style changes. You can now add, delete, edit categories through the admin interface.

File:
1 edited

Legend:

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

    r560 r572  
    4949            $excerpt = format_to_post($excerpt);
    5050            $post_title = addslashes($HTTP_POST_VARS['post_title']);
    51             $post_category = intval($HTTP_POST_VARS['post_category']);
     51            $post_categories = $HTTP_POST_VARS['post_category'];
    5252            if(get_settings('use_geo_positions')) {
    5353                $latstr = $HTTP_POST_VARS['post_latf'];
     
    8787        if((get_settings('use_geo_positions')) && (strlen($latstr) > 2) && (strlen($lonstr) > 2) ) {
    8888        $postquery ="INSERT INTO $tableposts
    89                 (ID, post_author, post_date, post_content, post_title, post_category, post_lat, post_lon, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name)
     89                (ID, post_author, post_date, post_content, post_title, post_lat, post_lon, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name)
    9090                VALUES
    91                 ('0','$user_ID','$now','$content','$post_title','$post_category',$post_latf,$post_lonf,'$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name')
     91                ('0', '$user_ID', '$now', '$content', '$post_title', $post_latf, $post_lonf,'$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name')
    9292                ";
    9393        } else {
    9494        $postquery ="INSERT INTO $tableposts
    95                 (ID, post_author, post_date, post_content, post_title, post_category,  post_excerpt,  post_status, comment_status, ping_status, post_password, post_name)
     95                (ID, post_author, post_date, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name)
    9696                VALUES
    97                 ('0','$user_ID','$now','$content','$post_title','$post_category','$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name')
     97                ('0', '$user_ID', '$now', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name')
    9898                ";
    9999        }
     
    103103        $post_ID = $wpdb->get_var("SELECT ID FROM $tableposts ORDER BY ID DESC LIMIT 1");
    104104
     105        // Insert categories
     106        foreach ($post_categories as $post_category) {
     107            // Double check it's not there already
     108            $exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $post_category");
     109
     110             if (!$exists && $result) {
     111                $wpdb->query("
     112                INSERT INTO $tablepost2cat
     113                (post_id, category_id)
     114                VALUES
     115                ($post_ID, $post_category)
     116                ");
     117            }
     118        }
     119       
    105120        if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
    106121                sleep($sleep_after_edit);
     
    204219        }
    205220            $post_ID = $HTTP_POST_VARS['post_ID'];
    206             $post_category = intval($HTTP_POST_VARS['post_category']);
     221            $post_categories = $HTTP_POST_VARS['post_category'];
    207222            $post_autobr = intval($HTTP_POST_VARS['post_autobr']);
    208223            $content = balanceTags($HTTP_POST_VARS['content']);
     
    249264                post_content = '$content',
    250265                post_excerpt = '$excerpt',
    251                 post_title = '$post_title',
    252                 post_category = '$post_category'".$datemodif.",
    253                 ".$latlonaddition."
     266                post_title = '$post_title'"
     267                .$datemodif.","
     268                .$latlonaddition."
    254269                post_status = '$post_status',
    255270                comment_status = '$comment_status',
     
    259274            WHERE ID = $post_ID ");
    260275
     276
     277        // Now it's category time!
     278        // First the old categories
     279        $old_categories = $wpdb->get_col("SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID");
     280       
     281        // Delete any?
     282        foreach ($old_categories as $old_cat) {
     283            if (!in_array($old_cat, $post_categories)) // If a category was there before but isn't now
     284                $wpdb->query("DELETE FROM $tablepost2cat WHERE category_id = $old_cat AND post_id = $post_ID LIMIT 1");
     285        }
     286       
     287        // Add any?
     288        foreach ($post_categories as $new_cat) {
     289            if (!in_array($new_cat, $old_categories))
     290                $wpdb->query("INSERT INTO $tablepost2cat (post_id, category_id) VALUES ($post_ID, $new_cat)");
     291        }
     292       
    261293        if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
    262294            sleep($sleep_after_edit);
     
    295327            die ('Cheatin’ uh?');
    296328
    297         $post = $HTTP_GET_VARS['post'];
     329        $post_id = $HTTP_GET_VARS['post'];
    298330        $postdata = get_postdata($post) or die('Oops, no post with this ID. <a href="wp-post.php">Go back</a>!');
    299331        $authordata = get_userdata($postdata['Author_ID']);
     
    303335
    304336        // send geoURL ping to "erase" from their DB
    305         $query = "SELECT post_lat from $tableposts WHERE ID=$post";
     337        $query = "SELECT post_lat from $tableposts WHERE ID=$post_id";
    306338        $rows = $wpdb->query($query);
    307339        $myrow = $rows[0];
     
    311343        }
    312344
    313         $result = $wpdb->query("DELETE FROM $tableposts WHERE ID=$post");
     345        $result = $wpdb->query("DELETE FROM $tableposts WHERE ID=$post_id");
    314346        if (!$result)
    315347            die('Error in deleting... contact the <a href="mailto:$admin_email">webmaster</a>.');
    316348
    317         $result = $wpdb->query("DELETE FROM $tablecomments WHERE comment_post_ID=$post");
     349        $result = $wpdb->query("DELETE FROM $tablecomments WHERE comment_post_ID=$post_id");
     350
     351        $categories = $wpdb->query("DELETE FROM $tablepost2cat WHERE post_id = $post_id");
    318352
    319353        if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
Note: See TracChangeset for help on using the changeset viewer.