From f3216e2c639bc7b50fd32423373cb5a13d269308 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 21 Jan 2016 12:27:40 -0500 Subject: [PATCH] Update the plugin for image alignment Found an area where the images had two sets of class attributes and they didn't get aligned properly. --- controllers/ToolboxImport.php | 85 ++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/controllers/ToolboxImport.php b/controllers/ToolboxImport.php index 6398cbc..b208169 100644 --- a/controllers/ToolboxImport.php +++ b/controllers/ToolboxImport.php @@ -358,7 +358,7 @@ $where[] = "id NOT IN ({$this->_options['exclude_pages']}) AND parent NOT IN ({$this->_options['exclude_pages']}) "; } - $where[] = "active = true"; + //$where[] = "active = true"; if (!empty($where)) { $WHERE = ' WHERE ' . implode(' AND ', $where); } @@ -1013,17 +1013,17 @@ //echo '
' . var_export($cMatch, true)  . '
'; for ($index = 0; $index < $captionCount; ++$index) { //echo '
cMatch: ' . print_r($cMatch[0][$index], true)  . '
'; - echo '
'.htmlspecialchars($cMatch[0][$index]).'
'; + //echo '
'.htmlspecialchars($cMatch[0][$index]).'
'; //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 '
Sub Src Match: ' . print_r($srcMatch[1], true)  . '
'; + //echo '
Sub Src Match: ' . print_r($srcMatch[1], true)  . '
'; $fileInfo = pathinfo($srcMatch[1]); $fileName = basename($srcMatch[1]); $fileBaseName = $fileInfo['filename']; - echo '
File Info: ' . print_r($fileInfo, true)  . '
'; - echo '
File Name: ' . print_r($fileName, true)  . '
'; + //echo '
File Info: ' . print_r($fileInfo, true)  . '
'; + //echo '
File Name: ' . print_r($fileName, true)  . '
'; $path = str_replace($fileName, '', $srcMatch[1]); $path = $fileInfo['dirname']; //echo '
'.var_dump($path).'
'; @@ -1048,11 +1048,19 @@ 'src="' . $srcMatch[1] . '"', 'src="' . $newImage[0] . '" width="' . $newImage[1] . '" height="' . $newImage[1] . '"', $cMatch[0][$index]); - $caption = str_replace('First: '.print_r($classMatch).''; + echo '

Matching with preg_match

'; + $caption = preg_replace('%class="([^"]+)"%', 'class="wp-image-' . $imagesKey . ' size-medium ' . $classMatch[1] . '"', $caption); + } else { + echo '

Matching with str_replace

'; + $caption = str_replace(''.htmlspecialchars($caption).''; + echo '
First: '.htmlspecialchars($caption).'
'; $content = str_replace($cMatch[0][$index], $caption, $content); } } @@ -1064,24 +1072,24 @@ if (preg_match_all('%]+)>%', $content, $matches)) { $imageCount = count($matches[0]); for ($index = 0; $index < $imageCount; ++$index) { - echo '
Image Match: ' . $imageCount  . '
'; - echo '
'.htmlspecialchars($matches[0][$index]).'
'; + //echo '
Image Match: ' . $imageCount  . '
'; + //echo '
'.htmlspecialchars($matches[0][$index]).'
'; if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) { return new WP_Error('upload_error', $uploads['error']); } - echo '
Uploads Url: ' . print_r($uploads['url'], true)  . '
'; + //echo '
Uploads Url: ' . print_r($uploads['url'], true)  . '
'; if (preg_match('%src="' . $uploads['url'] . '[^"]+"%', $matches[1][$index], $pMatch)) { continue; } if (preg_match('%src="([^"]+)"%', $matches[1][$index], $srcMatch)) { - echo '
Sub Src Match: ' . print_r($srcMatch[1], true)  . '
'; + //echo '
Sub Src Match: ' . print_r($srcMatch[1], true)  . '
'; $fileInfo = pathinfo($srcMatch[1]); - echo '
' . print_r($fileInfo, true) . '
'; + //echo '
' . print_r($fileInfo, true) . '
'; $fileName = $fileInfo['filename']; - echo '
File Url: ' . print_r($srcMatch[1], true)  . '
'; - echo '
File Name: ' . print_r($fileName, true)  . '
'; + //echo '
File Url: ' . print_r($srcMatch[1], true)  . '
'; + //echo '
File Name: ' . print_r($fileName, true)  . '
'; $path = $filInfo['dirname']; - echo '
File Path: ' . print_r($path, true)  . '
'; + //echo '
File Path: ' . print_r($path, true)  . '
'; $imagesKey = $this->_getAttachmentByName($fileName); var_dump($imagesKey); if (!$imagesKey) { @@ -1099,8 +1107,10 @@ // need to replace the src tags in content with the new image tags $imageTag = str_replace($srcMatch[1], $newUrl, $matches[0][$index]); if (preg_match('%class="([^"]+)"%', $matches[1][$index], $classMatch)) { + echo '

Matching with preg_match

'; $imageTag = preg_replace('%class="([^"]+)"%', 'class="wp-image-' . $imagesKey . ' size-medium $1"', $imageTag); } else { + echo '

Matching with str_replace

'; $imageTag = str_replace(''.htmlspecialchars($imageTag).''; @@ -1109,7 +1119,7 @@ } } } - //echo '
'.htmlspecialchars($content).'
'; + echo '
Second: '.htmlspecialchars($content).'
'; echo ''; $updatePost = array( 'ID' => $post->ID, @@ -1372,17 +1382,20 @@ if (count($currentPostArray) > 0) { echo '

Pages have been imported

'; echo '

Step Two (Importing Images)

'; - echo '

Step Three (Updating Image Ref)

'; + echo '

Step Three (Importing Files)

'; + echo '

Step Four (Updating Image Ref)

'; + echo '

Step Five (Updating Files Ref)

'; + echo '

Step Six (Updating Url\'s and keywords)

'; } else { echo '

Begin Import

'; } break; case 1: echo '

Reset

'; - $this->_post = $this->_images = $this->_files = array(); - $this->_storePost(); - $this->_storeImages(); - $this->_storeFiles(); + //$this->_post = $this->_images = $this->_files = array(); + //$this->_storePost(); + //$this->_storeImages(); + //$this->_storeFiles(); $numPagesImported = $this->_import(); echo '

' . $numPagesImported . ' Pages Imported

'; echo '

Step Two (Importing Images)

'; @@ -1392,11 +1405,8 @@ echo '

Now processing the images from old database tables

'; $this->_images = array(); $this->_storeImages(); - $this->_files = array(); - $this->_storeFiles(); if ($this->_options['toolbox_page_table'] == 'pages') { $this->_getCkImages(); - $this->_getToolboxFiles(); $this->_getParagraphImages(); echo '

Done

'; } else { @@ -1404,23 +1414,36 @@ $this->_getBusImages(); echo '

No import from images

'; } - echo '

Step Three (Updating Image Ref)

'; + echo '

Step Three (Importing Files)

'; break; case 3: + echo '

Done

'; + echo '

Now processing the files from old database tables

'; + $this->_files = array(); + $this->_storeFiles(); + if ($this->_options['toolbox_page_table'] == 'pages') { + $this->_getToolboxFiles(); + echo '

Done

'; + } else { + echo '

No import from images

'; + } + echo '

Step Four (Updating Image Ref)

'; + break; + case 4: echo '

Phase Three

'; $this->_updateMediaSrc(); echo '

Done

'; - echo '

Step Four (Updating Files Ref)

'; + echo '

Step Five (Updating Files Ref)

'; break; - case 4: - echo '

Phase Four

'; + case 5: + echo '

Phase Five

'; echo '

Files

'; $this->_updateFilesHref(); echo '

Done

'; - echo '

Step Five (Updating Url\'s and keywords)

'; + echo '

Step Six (Updating Url\'s and keywords)

'; break; - case 5: - echo '

Phase Five

'; + case 6: + echo '

Phase Six

'; echo '

Site Url

'; // Replace the page Url's $this->_replaceUrls(); -- 2.17.1