From: Steve Sutton Date: Wed, 5 Aug 2015 18:35:32 +0000 (-0400) Subject: Updates for NLEA X-Git-Tag: v0.0.2^2~14 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=42a8883ece4c69e82eac3c01988457afbb9256d8;p=WP-Plugins%2Fglm-wp-importer.git Updates for NLEA --- diff --git a/controllers/Import.php b/controllers/Import.php index 7d6476e..45a7286 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -837,6 +837,24 @@ } } + function handle_accents($content) { + // from: http://www.php.net/manual/en/domdocument.loadhtml.php#91513 + if ( !empty( $content ) && function_exists( 'mb_convert_encoding' ) ) { + mb_detect_order( "ASCII,UTF-8,ISO-8859-1,windows-1252,iso-8859-15" ); + if ( empty( $encod ) ) + $encod = mb_detect_encoding( $content ); + $headpos = mb_strpos( $content,'' ); + if ( FALSE === $headpos ) + $headpos= mb_strpos( $content,'' ); + if ( FALSE !== $headpos ) { + $headpos+=6; + $content = mb_substr( $content,0,$headpos ) . '' .mb_substr( $content,$headpos ); + } + $content = mb_convert_encoding( $content, 'HTML-ENTITIES', $encod ); + } + return $content; + } + private function _replaceSrc() { global $wpdb; @@ -848,7 +866,7 @@ FROM {$wpdb->prefix}posts WHERE post_content LIKE '%get_results($sql, OBJECT); @@ -856,8 +874,10 @@ if (count($results) > 0) { $pattern = ';(]>);si'; foreach ($results as $post) { - $dom = new DOMDocument(); - $test = $dom->loadHTML($post->post_content); + $dom = new DOMDocument('1.0', 'UTF-8'); + $content = $this->handle_accents($post->post_content); + $dom->encoding = 'UTF-8'; + $test = $dom->loadHTML($content); //var_dump($test); $images = $dom->getElementsByTagName('img'); foreach ($images as $image) { @@ -1017,7 +1037,7 @@ 'ID' => $post->ID, 'post_content' => $content ); - //wp_update_post($updatePost); + wp_update_post($updatePost); } //echo '
Files: ' . print_r($files, true) . '
'; echo '
Files Found: ' . print_r($filesFound, true) . '
';