From a9eb91d6434eb0dbbed078d8fbf9e12f789537bf Mon Sep 17 00:00:00 2001
From: Steve Sutton Pages have been imported Step Three (Updating Image Ref) Start: ' . $start . ' ' . $numPagesImported . ' Pages Imported
- ' . $data['caption'] . '[/caption]';
+ $content .= '[caption align="align'.$alignment.'"]
' . $data['caption'] . '[/caption]';
} else if (isset($data['imagename']) && $data['imagename']) {
- $content .= '[caption align="align'.$alignment.'"]
' . $data['imagename'] . '[/caption]';
+ $content .= '[caption align="align'.$alignment.'"]
' . $data['imagename'] . '[/caption]';
} else {
$content .= '
';
}
@@ -917,6 +917,71 @@
}
}
+ private function _updateMediaSrc()
+ {
+ global $wpdb;
+ $images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
+ $sql = "
+ SELECT *
+ FROM {$wpdb->prefix}posts
+ WHERE post_content LIKE '%
get_results($sql, OBJECT);
+ if (count($results) > 0) {
+ foreach ($results as $post) {
+ $content = $post->post_content;
+ echo '
Page Title: ' . print_r($post->post_title, true) . '
';
+ echo ']+)>([^\[]*)\[/caption\]%', $post->post_content, $cMatch)) {
+ echo '
'.htmlspecialchars($cMatch[0]).'
';
+ echo 'Caption Match: ' . print_r($cMatch[1], true) . '
';
+ echo 'Caption Text: ' . print_r($cMatch[2], true) . '
';
+ if (preg_match('%src="([^"]+)"%', $cMatch[1], $srcMatch)) {
+ echo 'Sub Src Match: ' . print_r($srcMatch[1], true) . '
';
+ $fileName = basename($srcMatch[1]);
+ echo 'File Name: ' . print_r($fileName, true) . '
';
+ if ($imagesKey = array_search($fileName, $images)) {
+ 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($srcMatch[1], $newImage[0], $cMatch[0]);
+ $caption = str_replace(''.htmlspecialchars($caption).'';
+ $content = str_replace($cMatch[0], $caption, $content);
+ }
+ }
+ } else if (preg_match('%
]+)>%', $post->post_content, $matches)) {
+ echo '
Image Match: ' . print_r($matches[1], true) . '
';
+ echo ''.htmlspecialchars($matches[0]).'
';
+ if (preg_match('%src="([^"]+)"%', $matches[1], $srcMatch)) {
+ echo 'Sub Src Match: ' . print_r($srcMatch[1], true) . '
';
+ $fileName = basename($srcMatch[1]);
+ echo 'File Name: ' . print_r($fileName, true) . '
';
+ if ($imagesKey = array_search($fileName, $images)) {
+ var_dump($imagesKey);
+ $newUrl = wp_get_attachment_url($imagesKey);
+ // need to replace the src tags in content with the new image tags
+ $imageTag = str_replace($srcMatch[1], $newUrl, $matches[0]);
+ $imageTag = str_replace(''.htmlspecialchars($imageTag).'';
+ $content = str_replace($matches[0], $imageTag, $content);
+ }
+ }
+ }
+ echo '
'.htmlspecialchars($content).'
';
+ echo '' . print_r($files, true) . '
';
if (count($currentPostArray) > 0) {
echo '
' . $numPagesImported . ' Pages Imported
'; echo ''; break; case 2: @@ -1148,15 +1199,26 @@ //echo ''; break; case 3: - $this->_replaceUrls(); + echo 'Phase Three
'; + $this->_updateMediaSrc(); + //$images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array()); + //echo '' . print_r($images, true) . ''; + //$files = get_option(GLM_WP_IMPORT_FILES_OPTION, array()); + //echo '
' . print_r($files, true) . ''; + echo '
Done
'; break; case 4: + echo 'Phase Four
'; echo 'Test getting page sub ids
'; $subPageIds = $this->_getSubPageIds($this->_options['include_pages']); echo ''.print_r($subPageIds, true).''; break; case 5: - $this->_getCkImages(); + echo '
Reset
'; + $this->_post = $this->_images = $this->_files = array(); + $this->_storePost(); + $this->_storeImages(); + $this->_storeFiles(); break; } -- 2.17.1