web/wp-admin/import/blogger.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
   195 		$stop     = esc_js( __('Importing...') );
   195 		$stop     = esc_js( __('Importing...') );
   196 		$authors  = esc_js( __('Set Authors') );
   196 		$authors  = esc_js( __('Set Authors') );
   197 		$loadauth = esc_js( __('Preparing author mapping form...') );
   197 		$loadauth = esc_js( __('Preparing author mapping form...') );
   198 		$authhead = esc_js( __('Final Step: Author Mapping') );
   198 		$authhead = esc_js( __('Final Step: Author Mapping') );
   199 		$nothing  = esc_js( __('Nothing was imported. Had you already imported this blog?') );
   199 		$nothing  = esc_js( __('Nothing was imported. Had you already imported this blog?') );
       
   200 		$stopping = ''; //Missing String used below.
   200 		$title    = __('Blogger Blogs');
   201 		$title    = __('Blogger Blogs');
   201 		$name     = __('Blog Name');
   202 		$name     = __('Blog Name');
   202 		$url      = __('Blog URL');
   203 		$url      = __('Blog URL');
   203 		$action   = __('The Magic Button');
   204 		$action   = __('The Magic Button');
   204 		$posts    = __('Posts');
   205 		$posts    = __('Posts');
   527 
   528 
   528 	function min_whitespace( $string ) {
   529 	function min_whitespace( $string ) {
   529 		return preg_replace( '|\s+|', ' ', $string );
   530 		return preg_replace( '|\s+|', ' ', $string );
   530 	}
   531 	}
   531 
   532 
       
   533 	function _normalize_tag( $matches ) {
       
   534 		return '<' . strtolower( $matches[1] );
       
   535 	}
       
   536 
   532 	function import_post( $entry ) {
   537 	function import_post( $entry ) {
   533 		global $importing_blog;
   538 		global $importing_blog;
   534 
   539 
   535 		// The old permalink is all Blogger gives us to link comments to their posts.
   540 		// The old permalink is all Blogger gives us to link comments to their posts.
   536 		if ( isset( $entry->draft ) )
   541 		if ( isset( $entry->draft ) )
   549 		$post_content = trim( addslashes( $this->no_apos( @html_entity_decode( $entry->content, ENT_COMPAT, get_option('blog_charset') ) ) ) );
   554 		$post_content = trim( addslashes( $this->no_apos( @html_entity_decode( $entry->content, ENT_COMPAT, get_option('blog_charset') ) ) ) );
   550 		$post_title   = trim( addslashes( $this->no_apos( $this->min_whitespace( $entry->title ) ) ) );
   555 		$post_title   = trim( addslashes( $this->no_apos( $this->min_whitespace( $entry->title ) ) ) );
   551 		$post_status  = isset( $entry->draft ) ? 'draft' : 'publish';
   556 		$post_status  = isset( $entry->draft ) ? 'draft' : 'publish';
   552 
   557 
   553 		// Clean up content
   558 		// Clean up content
   554 		$post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
   559 		$post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
   555 		$post_content = str_replace('<br>', '<br />', $post_content);
   560 		$post_content = str_replace('<br>', '<br />', $post_content);
   556 		$post_content = str_replace('<hr>', '<hr />', $post_content);
   561 		$post_content = str_replace('<hr>', '<hr />', $post_content);
   557 
   562 
   558 		// Checks for duplicates
   563 		// Checks for duplicates
   559 		if ( isset( $this->blogs[$importing_blog]['posts'][$entry->old_permalink] ) ) {
   564 		if ( isset( $this->blogs[$importing_blog]['posts'][$entry->old_permalink] ) ) {
   602 		$comment_author_url = addslashes( $this->no_apos( strip_tags( (string) $matches[2] ) ) );
   607 		$comment_author_url = addslashes( $this->no_apos( strip_tags( (string) $matches[2] ) ) );
   603 		$comment_date    = $this->convert_date( $entry->updated );
   608 		$comment_date    = $this->convert_date( $entry->updated );
   604 		$comment_content = addslashes( $this->no_apos( @html_entity_decode( $entry->content, ENT_COMPAT, get_option('blog_charset') ) ) );
   609 		$comment_content = addslashes( $this->no_apos( @html_entity_decode( $entry->content, ENT_COMPAT, get_option('blog_charset') ) ) );
   605 
   610 
   606 		// Clean up content
   611 		// Clean up content
   607 		$comment_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $comment_content);
   612 		$comment_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content);
   608 		$comment_content = str_replace('<br>', '<br />', $comment_content);
   613 		$comment_content = str_replace('<br>', '<br />', $comment_content);
   609 		$comment_content = str_replace('<hr>', '<hr />', $comment_content);
   614 		$comment_content = str_replace('<hr>', '<hr />', $comment_content);
   610 
   615 
   611 		// Checks for duplicates
   616 		// Checks for duplicates
   612 		if (
   617 		if (
   615 		) {
   620 		) {
   616 			++$this->blogs[$importing_blog]['comments_skipped'];
   621 			++$this->blogs[$importing_blog]['comments_skipped'];
   617 		} else {
   622 		} else {
   618 			$comment = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_date', 'comment_content');
   623 			$comment = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_date', 'comment_content');
   619 
   624 
       
   625 			$comment = wp_filter_comment($comment);
   620 			$comment_id = wp_insert_comment($comment);
   626 			$comment_id = wp_insert_comment($comment);
   621 
   627 
   622 			$this->blogs[$importing_blog]['comments'][$entry->old_permalink] = $comment_id;
   628 			$this->blogs[$importing_blog]['comments'][$entry->old_permalink] = $comment_id;
   623 
   629 
   624 			++$this->blogs[$importing_blog]['comments_done'];
   630 			++$this->blogs[$importing_blog]['comments_done'];
   903 	var $skipped_div = false;
   909 	var $skipped_div = false;
   904 
   910 
   905 	var $entry;
   911 	var $entry;
   906 
   912 
   907 	function AtomParser() {
   913 	function AtomParser() {
   908 
       
   909 		$this->entry = new AtomEntry();
   914 		$this->entry = new AtomEntry();
   910 		$this->map_attrs_func = create_function('$k,$v', 'return "$k=\"$v\"";');
   915 	}
   911 		$this->map_xmlns_func = create_function('$p,$n', '$xd = "xmlns"; if(strlen($n[0])>0) $xd .= ":{$n[0]}"; return "{$xd}=\"{$n[1]}\"";');
   916 
       
   917 	function _map_attrs_func( $k, $v ) {
       
   918 		return "$k=\"$v\"";
       
   919 	}
       
   920 
       
   921 	function _map_xmlns_func( $p, $n ) {
       
   922 		$xd = "xmlns";
       
   923 		if ( strlen( $n[0] ) > 0 )
       
   924 			$xd .= ":{$n[0]}";
       
   925 
       
   926 		return "{$xd}=\"{$n[1]}\"";
   912 	}
   927 	}
   913 
   928 
   914 	function parse($xml) {
   929 	function parse($xml) {
   915 
   930 
   916 		global $app_logging;
   931 		global $app_logging;
   948 
   963 
   949 			// resolve prefixes for attributes
   964 			// resolve prefixes for attributes
   950 			foreach($attrs as $key => $value) {
   965 			foreach($attrs as $key => $value) {
   951 				$attrs_prefix[$this->ns_to_prefix($key)] = $this->xml_escape($value);
   966 				$attrs_prefix[$this->ns_to_prefix($key)] = $this->xml_escape($value);
   952 			}
   967 			}
   953 			$attrs_str = join(' ', array_map($this->map_attrs_func, array_keys($attrs_prefix), array_values($attrs_prefix)));
   968 			$attrs_str = join(' ', array_map( array( &$this, '_map_attrs_func' ), array_keys($attrs_prefix), array_values($attrs_prefix)));
   954 			if(strlen($attrs_str) > 0) {
   969 			if(strlen($attrs_str) > 0) {
   955 				$attrs_str = " " . $attrs_str;
   970 				$attrs_str = " " . $attrs_str;
   956 			}
   971 			}
   957 
   972 
   958 			$xmlns_str = join(' ', array_map($this->map_xmlns_func, array_keys($this->ns_contexts[0]), array_values($this->ns_contexts[0])));
   973 			$xmlns_str = join(' ', array_map( array( &$this, '_map_xmlns_func' ), array_keys($this->ns_contexts[0]), array_values($this->ns_contexts[0])));
   959 			if(strlen($xmlns_str) > 0) {
   974 			if(strlen($xmlns_str) > 0) {
   960 				$xmlns_str = " " . $xmlns_str;
   975 				$xmlns_str = " " . $xmlns_str;
   961 			}
   976 			}
   962 
   977 
   963 			// handle self-closing tags (case: a new child found right-away, no text node)
   978 			// handle self-closing tags (case: a new child found right-away, no text node)