From: Steve Sutton Date: Thu, 22 Oct 2015 15:44:21 +0000 (-0400) Subject: Updates for image sizes X-Git-Tag: v0.0.2^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=8b27506ecc47d14923eecbc6ffe6a5eb1d84786b;p=WP-Plugins%2Fglm-wp-importer.git Updates for image sizes This was done on Shipwreck site that has an old toolbox. and images in siteurl/images/ht_images directory. --- diff --git a/controllers/ToolboxImport.php b/controllers/ToolboxImport.php index bb7a767..54ef057 100644 --- a/controllers/ToolboxImport.php +++ b/controllers/ToolboxImport.php @@ -162,7 +162,7 @@ if (!isset($data['image'])) { return false; } - $img_url = $this->_options['toolbox_image_url'] . '/tbs1/' . $data['image']; + $img_url = $this->_options['toolbox_image_url'] . '/CKImage/' . $data['image']; $content = ''; if (isset($data['caption']) && $data['caption']) { $content .= '[caption align="align'.$alignment.'"] ' . $data['caption'] . '[/caption]'; @@ -441,7 +441,7 @@ $page['pageContent'] = ''; $iterator = 1; if ($this->_options['toolbox_page_table'] == 'bus_category') { - $page['pageContent'] .= '

'.$page['category'].'

'; + //$page['pageContent'] .= '

'.$page['category'].'

'; ++$iterator; if ($page['image']) { //$page['images'][] = $page['image']; @@ -1004,34 +1004,39 @@ $content = $post->post_content; echo '
Updating Media Src\'s: ' . print_r($post->post_title, true)  . '
'; echo '
'; - if (preg_match_all('%\[caption [^\]]+\]]+)>([^\[]*)\[/caption\]%', $content, $cMatch)) { + if (preg_match_all('%(:?\[caption [^\]]+\])?]+)>(:?([^\[]*)\[/caption\])?%', $content, $cMatch)) { $captionCount = count($cMatch[0]); - echo '

Matches in Caption ' . $captionCount . '

'; - //echo '
' . print_r($cMatch, true)  . '
'; + //echo '

Matches in Caption ' . $captionCount . '

'; + //echo '
' . var_export($cMatch, true)  . '
'; for ($index = 0; $index < $captionCount; ++$index) { - //echo '
cMatch: ' . print_r($cMatch, true)  . '
'; + //echo '
cMatch: ' . print_r($cMatch[0][$index], true)  . '
'; echo '
'.htmlspecialchars($cMatch[0][$index]).'
'; - echo '
Caption Match: ' . print_r($cMatch[1][$index], true)  . '
'; - echo '
Caption Text: ' . print_r($cMatch[2][$index], true)  . '
'; - if (preg_match('%src="([^"]+)"%', $cMatch[1][$index], $srcMatch)) { + //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)  . '
'; - $fileInfo = pathinfo($srcMatch[1]); - $fileName = basename($srcMatch[1]); - $fileName = $fileInfo['filename']; + $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)  . '
'; $path = str_replace($fileName, '', $srcMatch[1]); - $path = $filInfo['dirname']; - $imagesKey = $this->_getAttachmentByName($fileName); - var_dump($imagesKey); + $path = $fileInfo['dirname']; + //echo '
'.var_dump($path).'
'; + + $imagesKey = $this->_getAttachmentByName($fileBaseName); + //var_dump($imagesKey); if (!$imagesKey) { $imagesKey = $this->_handleMediaFile( $fileName, - $fileName, + $fileBaseName, '', $post->ID, $path ); } + if ($imagesKey) { var_dump($imagesKey); $newImage = wp_get_attachment_image_src($imagesKey, 'medium'); @@ -1050,8 +1055,9 @@ } } } + // In this next part Have to remember the $content is already processed. - // Don't edit src if they alrea,dy have an ID + // Don't edit src if they already have an ID if (preg_match_all('%]+)>%', $content, $matches)) { $imageCount = count($matches[0]); for ($index = 0; $index < $imageCount; ++$index) { @@ -1100,7 +1106,7 @@ } } } - echo '
'.htmlspecialchars($content).'
'; + //echo '
'.htmlspecialchars($content).'
'; echo '
'; $updatePost = array( 'ID' => $post->ID, @@ -1280,6 +1286,67 @@ } } + private function _getBusImages() + { + global $wpdb; + echo '
' . print_r($this->_options['toolbox_schema'], true) . '
'; + echo '
' . print_r($this->_options['toolbox_paragraphs_table'], true) . '
'; + if ($this->_options['toolbox_paragraphs_table']) { + $this->_images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array()); + $this->_connect(); + $sql = " + SELECT image,imagename as caption + FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_paragraphs_table']} + WHERE image != ''"; + $stmt = $this->_dbh->query($sql); + while ($row = $stmt->fetch()) { + echo '
' . print_r($row, true) . '
'; + $fileName = $row['image']; + $fileTitle = ($row['caption']) ? $row['caption'] : $fileName; + $wpImage = $this->_handleMediaFile( + $fileName, + $fileTitle, + '', + 0, + $this->_options['toolbox_image_url'] . '/CKImage/' + ); + echo '
' . print_r($wpImage, true) . '
'; + $this->_images[$wpImage] = $fileName; + } + $this->_storeImages(); + } + } + + private function _getBusCategoryImages() + { + global $wpdb; + echo '
' . print_r($this->_options['toolbox_schema'], true) . '
'; + echo '
' . print_r($this->_options['toolbox_page_table'], true) . '
'; + if ($this->_options['toolbox_paragraphs_table']) { + $this->_images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array()); + $this->_connect(); + $sql = " + SELECT image,imagename as caption + FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} + WHERE image != ''"; + $stmt = $this->_dbh->query($sql); + while ($row = $stmt->fetch()) { + echo '
' . print_r($row, true) . '
'; + $fileName = $row['image']; + $fileTitle = ($row['caption']) ? $row['caption'] : $fileName; + $wpImage = $this->_handleMediaFile( + $fileName, + $fileTitle, + '', + 0, + $this->_options['toolbox_image_url'] . '/CKImage/' + ); + echo '
' . print_r($wpImage, true) . '
'; + $this->_images[$wpImage] = $fileName; + } + $this->_storeImages(); + } + } public function dispatch() { $this->_header(); @@ -1330,6 +1397,8 @@ $this->_getParagraphImages(); echo '

Done

'; } else { + $this->_getBusCategoryImages(); + $this->_getBusImages(); echo '

No import from images

'; } echo '

Step Three (Updating Image Ref)

';