Make WordPress Core

Changeset 3375


Ignore:
Timestamp:
12/29/2005 01:25:41 AM (19 years ago)
Author:
ryan
Message:

LJ tweaks.

Location:
trunk
Files:
3 edited

Legend:

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

    r3367 r3375  
    17511751        $number = '';
    17521752        $filename = $file['name'];
    1753         while ( file_exists($uploads['path'] . "/$filename") )
    1754             $filename = str_replace("$number.$ext", ++$number . ".$ext", $filename);
     1753        if ( empty($ext) )
     1754            $ext = '';
     1755        else
     1756            $ext = ".$ext";
     1757        while ( file_exists($uploads['path'] . "/$filename") ) {
     1758            if ( '' == "$number$ext" )
     1759                $filename = $filename . ++$number . $ext;
     1760            else
     1761                $filename = str_replace("$number$ext", ++$number . $ext, $filename);
     1762        }
    17551763    }
    17561764
  • trunk/wp-admin/import/livejournal.php

    r3374 r3375  
    33class LJ_Import {
    44
    5     var $posts = array ();
    65    var $file;
    76
     
    2625    }
    2726
    28     function get_posts() {
     27    function import_posts() {
    2928        global $wpdb, $current_user;
    3029       
    3130        set_magic_quotes_runtime(0);
    32         $datalines = file($this->file); // Read the file into an array
    33         $importdata = implode('', $datalines); // squish it
     31        $importdata = file($this->file); // Read the file into an array
     32        $importdata = implode('', $importdata); // squish it
    3433        $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata);
    3534
    36         preg_match_all('|<entry>(.*?)</entry>|is', $importdata, $this->posts);
    37         $this->posts = $this->posts[1];
    38         $index = 0;
    39         foreach ($this->posts as $post) {
     35        preg_match_all('|<entry>(.*?)</entry>|is', $importdata, $posts);
     36        $posts = $posts[1];
     37        unset($importdata);
     38        echo '<ol>';       
     39        foreach ($posts as $post) {
     40            flush();
    4041            preg_match('|<subject>(.*?)</subject>|is', $post, $post_title);
    4142            $post_title = $wpdb->escape(trim($post_title[1]));
    4243            if ( empty($post_title) ) {
    43                 preg_match('|<eventid>(.*?)</eventid>|is', $post, $post_title);
     44                preg_match('|<itemid>(.*?)</itemid>|is', $post, $post_title);
    4445                $post_title = $wpdb->escape(trim($post_title[1]));
    4546            }
    46    
     47
    4748            preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date);
    48 
    4949            $post_date = strtotime($post_date[1]);
    5050            $post_date = gmdate('Y-m-d H:i:s', $post_date);
    5151
    5252            preg_match('|<event>(.*?)</event>|is', $post, $post_content);
    53             $post_content = str_replace(array ('<![CDATA[', ']]>'), '', $wpdb->escape(trim($post_content[1])));
    54 
    55             if (!$post_content) {
    56                 // This is for feeds that put content in description
    57                 preg_match('|<description>(.*?)</description>|is', $post, $post_content);
    58                 $post_content = $wpdb->escape($this->unhtmlentities(trim($post_content[1])));
    59             }
     53            $post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
     54            $post_content = $this->unhtmlentities($post_content);
    6055
    6156            // Clean up content
     
    6358            $post_content = str_replace('<br>', '<br />', $post_content);
    6459            $post_content = str_replace('<hr>', '<hr />', $post_content);
     60            $post_content = $wpdb->escape($post_content);
    6561
    6662            $post_author = $current_user->ID;
    6763            $post_status = 'publish';
    68             $this->posts[$index] = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
    69             $index++;
    70         }
    71     }
    7264
    73     function import_posts() {
    74         echo '<ol>';
    75 
    76         foreach ($this->posts as $post) {
    77             echo "<li>".__('Importing post...');
    78 
    79             extract($post);
    80 
     65            echo '<li>';
    8166            if ($post_id = post_exists($post_title, $post_content, $post_date)) {
    82                 _e('Post already imported');
     67                printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
    8368            } else {
     69                printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
     70                $post = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
    8471                $post_id = wp_insert_post($post);
    8572                if (!$post_id) {
    8673                    _e("Couldn't get post ID");
    87                     return;
     74                    echo '</li>';
     75                    break;
    8876                }
     77            }
    8978
    90                 _e('Done !');
     79            preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments);
     80            $comments = $comments[1];
     81           
     82            if ( $comments ) {
     83                $comment_post_ID = $post_id;
     84                $num_comments = 0;
     85                foreach ($comments as $comment) {
     86                    preg_match('|<event>(.*?)</event>|is', $comment, $comment_content);
     87                    $comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1]));
     88                    $comment_content = $this->unhtmlentities($comment_content);
     89
     90                    // Clean up content
     91                    $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
     92                    $comment_content = str_replace('<br>', '<br />', $comment_content);
     93                    $comment_content = str_replace('<hr>', '<hr />', $comment_content);
     94                    $comment_content = $wpdb->escape($comment_content);
     95
     96                    preg_match('|<eventtime>(.*?)</eventtime>|is', $comment, $comment_date);
     97                    $comment_date = trim($comment_date[1]);
     98                    $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
     99
     100                    preg_match('|<name>(.*?)</name>|is', $comment, $comment_author);
     101                    $comment_author = $wpdb->escape(trim($comment_author[1]));
     102
     103                    preg_match('|<email>(.*?)</email>|is', $comment, $comment_author_email);
     104                    $comment_author_email = $wpdb->escape(trim($comment_author_email[1]));
     105
     106                    $comment_approved = 1;
     107                    // Check if it's already there
     108                    if (!comment_exists($comment_author, $comment_date)) {
     109                        $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved');
     110                        $commentdata = wp_filter_comment($commentdata);
     111                        wp_insert_comment($commentdata);
     112                        $num_comments++;
     113                    }
     114                }
    91115            }
     116            if ( $num_comments )
     117                printf(__('(%s comments)'), $num_comments);
     118
    92119            echo '</li>';
     120            flush();
     121            ob_flush();
    93122        }
    94 
    95123        echo '</ol>';
    96 
    97124    }
    98125
     
    105132
    106133        $this->file = $file['file'];
    107         $this->get_posts();
    108134        $this->import_posts();
    109135        wp_import_cleanup($file['id']);
     
    141167$livejournal_import = new LJ_Import();
    142168
    143 //register_importer('livejournal', 'LiveJournal', __('Import posts from LiveJournal'), array ($livejournal_import, 'dispatch'));
     169register_importer('livejournal', 'LiveJournal', __('Import posts from LiveJournal'), array ($livejournal_import, 'dispatch'));
    144170?>
  • trunk/wp-includes/comment-functions.php

    r3331 r3375  
    7777    if ( ! isset($comment_parent) )
    7878        $comment_parent = 0;
     79    if ( ! isset($comment_approved) )
     80        $comment_approved = 1;
    7981
    8082    $result = $wpdb->query("INSERT INTO $wpdb->comments
Note: See TracChangeset for help on using the changeset viewer.