From: Steve Sutton Date: Mon, 12 Oct 2015 21:00:55 +0000 (-0400) Subject: Working on blog images X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=b839952fd427a9ac0f71bc89434a4b20afa28d29;p=WP-Plugins%2Fglm-wp-importer.git Working on blog images --- diff --git a/controllers/BlogImageImport.php b/controllers/BlogImageImport.php index 55430ff..3897754 100644 --- a/controllers/BlogImageImport.php +++ b/controllers/BlogImageImport.php @@ -203,6 +203,62 @@ return $filename; } + private function checkImageUrls() + { + global $wpdb; + echo '

Replace Blog url\'s

'; + $searchUrl = 'uploads/'; + // 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($results) . '
'; + //echo '
' . print_r($results, true) . '
'; + $upload_dir = wp_upload_dir(); +// echo '
' . print_r($upload_dir, true) . '
'; + + if (count($results) > 0) { + $pattern = ';src="(' . $upload_dir['baseurl'] . '/[^"]+);si'; + foreach ($results as $post) { + $content = $post->post_content; + preg_match_all($pattern, $post->post_content, $matches); +// echo '
'.print_r($matches, true).'
'; + $matches = array_unique($matches[1]); + 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 '
' . print_r($img_id, true) . '
'; + //$replaceUrl = wp_get_attachment_url($img_id); + //echo '
' . print_r($image, true) . '
'; + //$content = str_replace($match, $replaceUrl, $content); + } + //$updatePost = array( + //'ID' => $post->ID, + //'post_content' => $content + //); + //wp_update_post($updatePost); + } + } + } + private function replaceBlogUrls() { if (!$this->_options['blog_url']) { @@ -277,7 +333,8 @@ break; case 1: echo '

Updating Blog Images

'; - $this->replaceBlogUrls(); + //$this->replaceBlogUrls(); + $this->checkImageUrls(); break; }