From: Steve Sutton Date: Fri, 15 Sep 2017 18:15:01 +0000 (-0400) Subject: Fix the image issues with old toolbox. X-Git-Tag: v1.0.6^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=b6b62e78435521ee97b059b76a4b8e52e0d51c54;p=WP-Plugins%2Fglm-wp-importer.git Fix the image issues with old toolbox. Ran into issue with MiGCSA. This should fix that site if we rerun step 4 ond 5 and 6. --- diff --git a/controllers/ToolboxImport.php b/controllers/ToolboxImport.php index 695f599..819a05b 100644 --- a/controllers/ToolboxImport.php +++ b/controllers/ToolboxImport.php @@ -994,6 +994,7 @@ FROM {$wpdb->prefix}posts WHERE post_content LIKE '%get_results($sql, OBJECT); if (count($results) > 0) { @@ -1001,6 +1002,7 @@ $content = $post->post_content; echo '
Updating Media Src\'s: ' . print_r($post->post_title, true)  . '
'; echo '
'; + //echo '
original: '.htmlspecialchars($content).'
'; if (preg_match_all('%(:?\[caption [^\]]+\])?]+)>(:?([^\[]*)\[/caption\])?%', $content, $cMatch)) { $captionCount = count($cMatch[0]); //echo '

Matches in Caption ' . $captionCount . '

'; @@ -1011,7 +1013,7 @@ //echo '
Caption Match: ' . print_r($cMatch[1][$index], true)  . '
'; //echo '
Caption Text: ' . print_r($cMatch[2][$index], true)  . '/End Caption Text
'; if (preg_match('%src="([^"]+)"%', $cMatch[0][$index], $srcMatch)) { - //echo '
' . print_r($srcMatch, true) . '
'; + echo '
' . print_r($srcMatch, true) . '
'; //echo '
Sub Src Match: ' . print_r($srcMatch[1], true)  . '
'; $fileInfo = pathinfo($srcMatch[1]); $fileName = basename($srcMatch[1]); @@ -1025,24 +1027,32 @@ //echo '
'.var_dump($path).'
'; $imagesKey = $this->_getAttachmentByName($fileBaseName); - //var_dump($imagesKey); + var_dump($imagesKey); +// echo '
+// $fileName: '.$fileName.'
+// $fileBaseName: '.$fileBaseName.'
+// $post->ID: '.$post->ID.'
+// $path: '.$path.'
+// 
'; if (!$imagesKey) { $imagesKey = $this->_handleMediaFile( $fileName, $fileBaseName, '', $post->ID, - $path + $path . '/' ); } + var_dump($imagesKey); + //exit; if ($imagesKey) { var_dump($imagesKey); $newImage = wp_get_attachment_image_src($imagesKey, 'medium'); // need to replace the src tags in content with the new image tags $caption = str_replace( 'src="' . $srcMatch[1] . '"', - 'src="' . $newImage[0] . '" width="' . $newImage[1] . '" height="' . $newImage[1] . '"', + 'src="' . $newImage[0] . '" width="' . $newImage[1] . '" height="' . $newImage[2] . '"', $cMatch[0][$index]); if (preg_match('%class="([^"]+)"%', $caption, $classMatch)) { echo '
First: '.print_r($classMatch).'
';