From: Steve Sutton Date: Thu, 30 Jul 2015 19:30:32 +0000 (-0400) Subject: Update for replacing is0 urls X-Git-Tag: v0.0.2^2~21 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d65da4e124efcd18aeae2073e22cd83167739cbc;p=WP-Plugins%2Fglm-wp-importer.git Update for replacing is0 urls --- diff --git a/controllers/Import.php b/controllers/Import.php index c60c7ce..0695eeb 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -270,7 +270,7 @@ 0, $rootUrl . '/' ); - $image = wp_get_attachment_image_src($img_id, 'full'); + $image = wp_get_attachment_image_src($img_id, 'medium'); return $image[0]; } @@ -422,8 +422,8 @@ $where[] = "(id = {$this->_options['include_pages']}" . " OR id IN (" . implode(',', $subPageIds) . ") )"; } else { - $where[] = "id = {$this->_options['include_pages']}"; - } + $where[] = "id = {$this->_options['include_pages']}"; + } } else { $where[] = "id IN ({$this->_options['include_pages']})"; @@ -756,16 +756,16 @@ { $this->_connect(); if ($this->_options['toolbox_page_table'] == 'pages') { - $sql = " - SELECT navigation_name - FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} - WHERE id = :id"; - } else { - $sql = " - SELECT category as navigation_name - FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} - WHERE id = :id"; - } + $sql = " + SELECT navigation_name + FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} + WHERE id = :id"; + } else { + $sql = " + SELECT category as navigation_name + FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} + WHERE id = :id"; + } $stmt = $this->_dbh->prepare($sql); $stmt->bindParam(':id', $id, PDO::PARAM_INT); $stmt->execute(); @@ -817,6 +817,57 @@ } } + private function replaceIsoUrls() + { + global $wpdb; + $this->_connect(); + echo '

Replace IS0 url\'s

'; + $searchUrl = 'http://is0.gaslightmedia.com'; + // find all pages with links to site pages + $sql = " + SELECT * + FROM {$wpdb->prefix}posts + WHERE post_content LIKE '%{$searchUrl}%' + AND post_type = 'page'"; + echo '
'.$sql.'
'; + $results = $wpdb->get_results($sql, OBJECT); + if (count($results) > 0) { + //echo '
' . print_r($results, true) . '
'; + $pattern = ';(http://is0.gaslightmedia.com/[^"]+);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 '
' . print_r($parsed, true) . '
'; + echo '
' . print_r($filename, true) . '
'; + echo '
' . print_r($rootUrl, true) . '
'; + $img_id = $this->_handleMediaFile( + basename($parsed['path']), + '', + $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); + } + } + } + /** * dispatch * @@ -863,8 +914,10 @@ echo '

Part 2

'; break; case 2: - $this->_replaceKeywords(); - echo '

Part 3

'; + //$this->_replaceKeywords(); + $this->replaceIsoUrls(); + echo '

Done

'; + //echo '

Part 3

'; break; case 3: $this->_replaceUrls();