From f5a1dfb14b162e8159c9ef7ac9dcba2be2488cfe Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 12 Oct 2015 17:01:13 -0400 Subject: [PATCH] Working on the toolbox image Redo and fix the image path for the paragraph toolbox exported images. These were imported with the incorrect image size RESIZED --- controllers/ToolboxImport.php | 67 +++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/controllers/ToolboxImport.php b/controllers/ToolboxImport.php index bb7a767..1e4395f 100644 --- a/controllers/ToolboxImport.php +++ b/controllers/ToolboxImport.php @@ -1252,8 +1252,8 @@ private function _getParagraphImages() { global $wpdb; - echo '
' . print_r($this->_options['toolbox_schema'], true) . '
'; - echo '
' . print_r($this->_options['toolbox_paragraphs_table'], true) . '
'; + //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(); @@ -1273,13 +1273,69 @@ 0, $this->_options['toolbox_image_url'] . '/CKImage/' ); - echo '
' . print_r($wpImage, true) . '
'; + //echo '
' . print_r($wpImage, true) . '
'; $this->_images[$wpImage] = $fileName; } + //echo '
' . print_r($this->_images, true) . '
'; $this->_storeImages(); } } + /** + * Fix the paragraph images + * + * Step 1: Find all the paragraph images + * Step 2: Fetch and store the image with the larger CKImage size + * Step 3: Update the image meta data (this will regerate the thumbnail data) + */ + private function _fixParagraphimages() + { + global $wpdb; + $this->_images = array(); + if ($this->_options['toolbox_paragraphs_table']) { + $this->_images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array()); + $this->_connect(); + $sql = " + SELECT image,caption + FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_paragraphs_table']} + WHERE image != ''"; + $stmt = $this->_dbh->query($sql); + while ($row = $stmt->fetch()) { + echo '
image,caption: ' . print_r($row, true) . '
'; + $fileName = $row['image']; + $fileinfo = pathinfo($fileName); + echo '

filename: ' . print_r($fileinfo['filename'], true) . '

'; + // find the attachment id + $sql = " + SELECT * + FROM {$wpdb->prefix}posts + WHERE post_name = '{$fileinfo['filename']}'"; + $att_results = $wpdb->get_row($sql, ARRAY_A); + if ( count( $att_results ) > 0 ) { + $attachment_id = $att_results['ID']; + $attachment_guid = $att_results['guid']; + echo '
attachment_id: ' . print_r($attachment_id, true) . '
'; + echo '
attachment_guid: ' . print_r($attachment_guid, true) . '
'; + } else { + echo '

WARN: not finding attachment

'; + } + // find the post with that guid in it + $sql = " + SELECT * + FROM {$wpdb->prefix}posts + WHERE post_content like '%{$attachment_guid}%'"; + $page_results = $wpdb->get_row($sql, ARRAY_A); + if ( count( $page_results ) > 0 ) { + $page_id = $page_results['ID']; + echo '
page_id: ' . print_r($page_id, true) . '
'; + } else { + echo '

WARN: not finding guid in any page

'; + } + } + //echo '
' . print_r($this->_images, true) . '
'; + } + } + public function dispatch() { $this->_header(); @@ -1290,6 +1346,10 @@ $step = filter_var($_GET['step'], FILTER_VALIDATE_INT); } switch($step) { + case 6: + //echo '

The walking Dead!!!!!!

'; + $this->_fixParagraphimages(); + break; case 0: $this->_greet(); echo '

Begin Import

'; @@ -1306,6 +1366,7 @@ } else { echo '

Begin Import

'; } + echo '

Fix Paragraph Images

'; break; case 1: echo '

Reset

'; -- 2.17.1