Make WordPress Core

Ticket #3290: unfiltered-imports.diff

File unfiltered-imports.diff, 9.1 KB (added by andy, 20 years ago)
  • wp-includes/capabilities.php

     
    454454        return call_user_func_array(array(&$current_user, 'has_cap'), $args);
    455455}
    456456
     457// Capability checker for any user
     458function user_can($user, $capability) {
     459        $user = new WP_User($user);
     460
     461        if ( empty($user) )
     462                return false;
     463
     464        $args = array_slice(func_get_args(), 2);
     465        $args = array_merge(array($capability), $args);
     466
     467        return call_user_func_array(array(&$user, 'has_cap'), $args);
     468}
     469
    457470// Convenience wrappers around $wp_roles.
    458471function get_role($role) {
    459472        global $wp_roles;
  • wp-includes/kses.php

     
    547547        remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
    548548}
    549549
    550 function kses_init() {
     550function kses_init($filtered = null) {
    551551        kses_remove_filters();
    552552
    553         if (current_user_can('unfiltered_html') == false)
     553        if ( isset($filtered) && $filtered == false )
     554                return;
     555        if ( isset($filtered) && $filtered == true )
    554556                kses_init_filters();
     557        if ( current_user_can('unfiltered_html') == false )
     558                kses_init_filters();
    555559}
    556560
    557561add_action('init', 'kses_init');
  • wp-admin/import/livejournal.php

     
    6969                                printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
    7070                        } else {
    7171                                printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
     72
     73                                // Set up kses filters appropriate for the author's caps
     74                                $filtered = ! user_can($post_author, 'unfiltered_html');
     75                                kses_init($filtered);
     76
    7277                                $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
    7378                                $post_id = wp_insert_post($postdata);
    7479                                if (!$post_id) {
     
    8287                        $comments = $comments[1];
    8388
    8489                        if ( $comments ) {
     90                                // Always filter imported comments.
     91                                kses_init(true);
     92
    8593                                $comment_post_ID = $post_id;
    8694                                $num_comments = 0;
    8795                                foreach ($comments as $comment) {
  • wp-admin/import/dotclear.php

     
    366366
    367367                                // Import Post data into WordPress
    368368
     369                                // Set up kses filters appropriate for the author's caps
     370                                $filtered = ! user_can($authorid, 'unfiltered_html');
     371                                kses_init($filtered);
     372
    369373                                if($pinfo = post_exists($Title,$post_content))
    370374                                {
    371375                                        $ret_id = wp_insert_post(array(
     
    427431                $dccm2wpcm = array();
    428432                $postarr = get_option('dcposts2wpposts');
    429433
     434                // Always filter imported comments.
     435                kses_init(true);
     436
    430437                // Magic Mojo
    431438                if(is_array($comments))
    432439                {
  • wp-admin/import/mt.php

     
    287287
    288288                                        $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor
    289289
     290                                        // Set up kses filters appropriate for the author's caps
     291                                        $filtered = ! user_can($post_author, 'unfiltered_html');
     292                                        kses_init($filtered);
     293
    290294                                        $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
    291295                                        $post_id = wp_insert_post($postdata);
    292296                                        // Add categories.
     
    301305                                // Now for comments
    302306                                $comments = explode("-----\nCOMMENT:", $comments[0]);
    303307                                $num_comments = 0;
     308
     309                                // Always filter imported comments.
     310                                kses_init(true);
     311
    304312                                foreach ($comments as $comment) {
    305313                                        if ('' != trim($comment)) {
    306314                                                // Author
  • wp-admin/import/blogger.php

     
    498498                                if ( count($post_array) ) {
    499499                                        krsort($post_array);
    500500                                        foreach($post_array as $post) {
    501                                                 if ( ! $comment_post_ID = $post['ID'] )
     501                                                if ( isset($post['post']) ) {
     502                                                        $filtered = ! user_can($post['post']['post_author'], 'unfiltered_html');
     503                                                        kses_init($filtered);
    502504                                                        $comment_post_ID = wp_insert_post($post['post']);
     505                                                } else {
     506                                                        $comment_post_ID = $post['ID'];
     507                                                }
    503508                                                if ( $post['comments'] ) {
     509                                                        // Always filter imported comments.
     510                                                        kses_init(true);
     511
    504512                                                        foreach ( $post['comments'] as $comment ) {
    505513                                                                $comment['comment_post_ID'] = $comment_post_ID;
    506514                                                                wp_insert_comment($comment);
  • wp-admin/import/blogware.php

     
    9090                        } else {
    9191                                printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
    9292                                $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
     93                                // Set up kses filters appropriate for the author's caps
     94                                $filtered = ! user_can($post_author, 'unfiltered_html');
     95                                kses_init($filtered);
    9396                                $post_id = wp_insert_post($postdata);
    9497                                if (!$post_id) {
    9598                                        _e("Couldn't get post ID");
     
    104107                        $comments = $comments[1];
    105108
    106109                        if ( $comments ) {
     110                                // Always filter imported comments.
     111                                kses_init(true);
     112
    107113                                $comment_post_ID = $post_id;
    108114                                $num_comments = 0;
    109115                                foreach ($comments as $comment) {
  • wp-admin/import/textpattern.php

     
    300300
    301301                                // Import Post data into WordPress
    302302
     303                                // Set up kses filters appropriate for the author's caps
     304                                $filtered = ! user_can($authorid, 'unfiltered_html');
     305                                kses_init($filtered);
     306
    303307                                if($pinfo = post_exists($Title,$Body))
    304308                                {
    305309                                        $ret_id = wp_insert_post(array(
     
    358362                $txpcm2wpcm = array();
    359363                $postarr = get_option('txpposts2wpposts');
    360364
     365                // Always filter imported comments.
     366                kses_init(true);
     367
    361368                // Magic Mojo
    362369                if(is_array($comments))
    363370                {
  • wp-admin/import/greymatter.php

     
    228228                                        $post_author = $user_id;
    229229                                }
    230230                       
     231                                // Set up kses filters appropriate for the author's caps
     232                                $filtered = ! user_can($post_author, 'unfiltered_html');
     233                                kses_init($filtered);
     234
    231235                                $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
    232236                                $post_ID = wp_insert_post($postdata);
    233237                        }
    234238
    235239                        $c=count($entry);
    236240                        if ($c>4) {
     241                                // Always filter imported comments.
     242                                kses_init(true);
     243
    237244                                $numAddedComments = 0;
    238245                                $numComments = 0;
    239246                                for ($j=4;$j<$c;$j++) {
  • wp-admin/import/rss.php

     
    109109                        if ($post_id = post_exists($post_title, $post_content, $post_date)) {
    110110                                _e('Post already imported');
    111111                        } else {
     112                                // Set up kses filters appropriate for the author's caps
     113                                $filtered = ! user_can($post_author, 'unfiltered_html');
     114                                kses_init($filtered);
    112115                                $post_id = wp_insert_post($post);
    113116                                if (!$post_id) {
    114117                                        _e("Couldn't get post ID");
  • wp-admin/import/wordpress.php

     
    251251
    252252                                $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor
    253253
     254                                // Set up kses filters appropriate for the author's caps
     255                                $filtered = ! user_can($post_author, 'unfiltered_html');
     256                                kses_init($filtered);
     257
    254258                                $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'post_type');
    255259                                $comment_post_ID = $post_id = wp_insert_post($postdata);
    256260                                // Add categories.
     
    263267                                preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
    264268                                $comments = $comments[1];
    265269                                $num_comments = 0;
     270
     271                                // Always filter imported comments.
     272                                kses_init(true);
     273
    266274                                if ( $comments) { foreach ($comments as $comment) {
    267275                                        $comment_author       = $this->get_tag( $comment, 'wp:comment_author');
    268276                                        $comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email');