From: Steve Sutton Date: Tue, 15 Sep 2015 15:19:44 +0000 (-0400) Subject: Update for fixing post images X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2Ffeature%2FGovernment;p=WP-Plugins%2Fglm-wp-importer.git Update for fixing post images ht_images and is0 ones --- diff --git a/controllers/Import.php b/controllers/Import.php index 68eba30..fd57ba8 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -233,6 +233,11 @@ return new WP_Error('upload_error', $uploads['error']); } $filename = $this->_fetchRemoteImage($file, $uploads['path'], $baseUrl); + //echo '
file: ' . print_r($file, true) . '
'; + //echo '
path: ' . print_r($uploads['path'], true) . '
'; + //echo '
baseUrl: ' . print_r($baseUrl, true) . '
'; + //echo '
filename: ' . print_r($filename, true) . '
'; + //exit; $new_file = $uploads['path'] . '/' . $filename; $url = $uploads['url'] . '/' . $filename; $return = apply_filters('wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => wp_check_filetype($file, null))); @@ -289,6 +294,7 @@ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $imgData = curl_exec($ch); $httpCode = curl_getinfo($ch); + echo '
' . print_r($httpCode, true) . '
'; curl_close($ch); fclose($fp); // Set correct file permissions @@ -1209,6 +1215,64 @@ return (!empty($results)) ? $results[0] : false; } + private function replaceHtImagesUrls() + { + global $wpdb; + $this->_connect(); + echo '

Replace IS0 url\'s

'; + $searchUrl = 'http://www.emmetcounty.org/images/ht_images'; + // find all pages with links to site pages + $sql = " + SELECT * + FROM {$wpdb->prefix}posts + WHERE post_content LIKE '%{$searchUrl}%' + AND post_type = 'post'"; + echo '
'.$sql.'
'; + $results = $wpdb->get_results($sql, OBJECT); + echo '
Count ' . count($results) . '
'; + //return; + + if (count($results) > 0) { + //echo '
' . print_r($results, true) . '
'; + $pattern = ';(http://www.emmetcounty.org/images/ht_images/[^"]+);si'; + foreach ($results as $post) { + $content = $post->post_content; + preg_match_all($pattern, $post->post_content, $matches); + $matches = array_unique($matches[0]); + echo '
' . print_r($post->ID, true) . '
'; + echo '
' . print_r($matches, true) . '
'; + foreach ($matches as $match) { + // process the file as media library + $parsed = parse_url($match); + $filename = basename($parsed['path']); + $rootUrl = str_replace('/' . $filename, '', $match); + echo '
parsed: ' . print_r($parsed, true) . '
'; + echo '
filename: ' . print_r($filename, true) . '
'; + echo '
RootUrl: ' . print_r($rootUrl, true) . '
'; + $img_id = $this->_handleMediaFile( + $filename, + '', + '', + $post->ID, + $rootUrl . '/' + ); + echo '
Img ID: ' . print_r($img_id, true) . '
'; + $replaceUrl = wp_get_attachment_url($img_id); + echo '
' . print_r($replaceUrl, true) . '
'; + $content = str_replace($match, $replaceUrl, $content); + } + + //return; + //exit; + $updatePost = array( + 'ID' => $post->ID, + 'post_content' => $content + ); + wp_update_post($updatePost); + } + } + } + private function replaceIsoUrls() { global $wpdb; @@ -1220,9 +1284,11 @@ SELECT * FROM {$wpdb->prefix}posts WHERE post_content LIKE '%{$searchUrl}%' - AND post_type = 'page'"; + AND post_type = 'post'"; echo '
'.$sql.'
'; $results = $wpdb->get_results($sql, OBJECT); + echo '
Count ' . count($results) . '
'; + if (count($results) > 0) { //echo '
' . print_r($results, true) . '
'; $pattern = ';(http://is0.gaslightmedia.com/[^"]+);si'; @@ -1237,20 +1303,24 @@ $parsed = parse_url($match); $filename = basename($parsed['path']); $rootUrl = str_replace('/' . $filename, '', $match); - echo '
' . print_r($parsed, true) . '
'; - echo '
' . print_r($filename, true) . '
'; - echo '
' . print_r($rootUrl, true) . '
'; + echo '
parsed: ' . print_r($parsed, true) . '
'; + echo '
filename: ' . print_r($filename, true) . '
'; + echo '
RootUrl: ' . print_r($rootUrl, true) . '
'; $img_id = $this->_handleMediaFile( - basename($parsed['path']), + $filename, + '', '', $post->ID, $rootUrl . '/' ); - echo '
' . print_r($img_id, true) . '
'; + echo '
Img ID: ' . print_r($img_id, true) . '
'; $replaceUrl = wp_get_attachment_url($img_id); - echo '
' . print_r($image, true) . '
'; + echo '
' . print_r($replaceUrl, true) . '
'; $content = str_replace($match, $replaceUrl, $content); } + + //return; + //exit; $updatePost = array( 'ID' => $post->ID, 'post_content' => $content @@ -1394,7 +1464,9 @@ } break; case 1: - echo '

Page to page import

'; + echo '

Updating Posts Images

'; + $this->replaceIsoUrls(); + $this->replaceHtImagesUrls(); // Buildings and grounds //$this->_updatePage(213, 6769); //$this->_importPageFiles(6769);