diff --git a/Model/Import/Wordpress.php b/Model/Import/Wordpress.php index 3cfd3282..36ec608c 100644 --- a/Model/Import/Wordpress.php +++ b/Model/Import/Wordpress.php @@ -249,10 +249,13 @@ public function execute() $content = str_replace('', '', $content); $content = preg_replace( - '/((http:\/\/|https:\/\/|\/\/)(.*)|(\s|"|\')|(\/[\d\w_\-\.]*))\/wp-content\/uploads(.*)((\.jpg|\.jpeg|\.gif|\.png|\.tiff|\.tif|\.svg)|(\s|"|\'))/Ui', - '$4{{media url="magefan_blog$6$8"}}$9', + '/src=[\'"]((http:\/\/|https:\/\/|\/\/)(.*)|(\s|"|\')|(\/[\d\w_\-\.]*))\/wp-content\/uploads(.*)((\.jpg|\.jpeg|\.gif|\.png|\.tiff|\.tif|\.svg)|(\s|"|\'))[\'"\s]/Ui', + 'src="$4{{media url="magefan_blog$6$8"}}$9"', $content ); + + $content = $this->wordpressOutoutWrap($content); + $wordpressPostId = $data['ID']; $data = [ 'store_ids' => [$this->getStoreId()], @@ -329,4 +332,161 @@ public function execute() mysqli_close($con); } + + + protected function wordpressOutoutWrap( $pee, $br = true ) + { + $pre_tags = array(); + + if ( trim( $pee ) === '' ) { + return ''; + } + + // Just to make things a little easier, pad the end. + $pee = $pee . "\n"; + + /* + * Pre tags shouldn't be touched by autop. + * Replace pre tags with placeholders and bring them back after autop. + */ + if ( strpos( $pee, '', $pee ); + $last_pee = array_pop( $pee_parts ); + $pee = ''; + $i = 0; + + foreach ( $pee_parts as $pee_part ) { + $start = strpos( $pee_part, ''; + + $pee .= substr( $pee_part, 0, $start ) . $name; + $i++; + } + + $pee .= $last_pee; + } + // Change multiple
s into two line breaks, which will turn into paragraphs. + $pee = preg_replace( '|\s*|', "\n\n", $pee ); + + $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; + + // Add a double line break above block-level opening tags. + $pee = preg_replace( '!(<' . $allblocks . '[\s/>])!', "\n\n$1", $pee ); + + // Add a double line break below block-level closing tags. + $pee = preg_replace( '!()!', "$1\n\n", $pee ); + + // Standardize newline characters to "\n". + $pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); + + // Collapse line breaks before and after ', $pee ); + } + + /* + * Collapse line breaks inside elements, before and elements + * so they don't get autop'd. + */ + if ( strpos( $pee, '' ) !== false ) { + $pee = preg_replace( '|(]*>)\s*|', '$1', $pee ); + $pee = preg_replace( '|\s*|', '', $pee ); + $pee = preg_replace( '%\s*(]*>)\s*%', '$1', $pee ); + } + + /* + * Collapse line breaks inside