From: Steve Sutton Date: Wed, 5 Aug 2015 13:53:11 +0000 (-0400) Subject: updates for just showing duplicate files X-Git-Tag: v0.0.2^2~15 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=2d74db2abd08c86f4cddebff0093d1ba46c4acb6;p=WP-Plugins%2Fglm-wp-importer.git updates for just showing duplicate files --- diff --git a/controllers/Import.php b/controllers/Import.php index 81a4053..7d6476e 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -840,16 +840,16 @@ private function _replaceSrc() { global $wpdb; + $files = $filesFound = $filesMissing = $fileDuplicates = array(); $this->_connect(); - echo '

Replace page src\'s

'; - // find all pages with links to site pages + echo '

Replace Src\'s

'; $sql = " SELECT * FROM {$wpdb->prefix}posts WHERE post_content LIKE '%get_results($sql, OBJECT); echo '

Number of Pages'.count($results).'

'; @@ -861,30 +861,31 @@ //var_dump($test); $images = $dom->getElementsByTagName('img'); foreach ($images as $image) { + $files[] = $image->getAttribute('src'); $width = $height = null; - echo '
'; + //echo '
'; //echo '
' . print_r($image, true)  . '
'; if ($image->hasAttribute('class')) { - echo '
' . print_r($image->getAttribute('class'), true)  . '
'; + //echo '
' . print_r($image->getAttribute('class'), true)  . '
'; if (preg_match('%wp-image-\d+%', $image->getAttribute('class'))) { //echo 'Continue'; //echo '
'; - //continue; + continue; } } if ($image->hasAttribute('style')) { $style = $image->getAttribute('style'); - var_dump($style); - echo '
' . print_r($style, true)  . '
'; + //var_dump($style); + //echo '
' . print_r($style, true)  . '
'; if (preg_match('%[^-]width[: ]+(\d+)%', $style, $wMatch)) { $width = $wMatch[1]; - echo '
wMatch: ' . print_r($wMatch, true)  . '
'; + //echo '
wMatch: ' . print_r($wMatch, true)  . '
'; } if (preg_match('%[^-]height[: ]+(\d+)%', $style, $hMatch)) { $height = $hMatch[1]; } - echo '
width: ' . print_r($width, true)  . '
'; - echo '
height: ' . print_r($height, true)  . '
'; + //echo '
width: ' . print_r($width, true)  . '
'; + //echo '
height: ' . print_r($height, true)  . '
'; } if ($image->hasAttribute('width')) { $width = $image->getAttribute('width'); @@ -895,37 +896,40 @@ if ($image->hasAttribute('src')) { //echo '
' . print_r($image->getAttribute('src'), true)  . '
'; $imgName = basename($image->getAttribute('src')); - echo '
' . print_r($imgName, true)  . '
'; + //echo '
' . print_r($imgName, true)  . '
'; $imgPathInfo = pathinfo($imgName); - echo '
' . print_r($imgPathInfo, true) . '
'; + //echo '
' . print_r($imgPathInfo, true) . '
'; $wpImage = $this->_getAttachmentByName($imgPathInfo['filename']); //echo '
' . print_r($wpImage, true) . '
'; //exit; if (!$wpImage) { - echo '

Image not found as attachment

'; - echo '
' . print_r($imgPathInfo, true) . '
'; + //echo '

Image not found as attachment

'; + //echo '
' . print_r($imgPathInfo, true) . '
'; if (preg_match(';(is\d{2}-\d{10}-\d{5})(\d{1}|[-]\d+x\d+);', $imgPathInfo['filename'], $matches)) { - echo '

Duplicate Image found

'; - echo '
' . print_r($matches, true) . '
'; + //echo '

Duplicate Image found

'; + //echo '
' . print_r($matches, true) . '
'; $wpImage = $this->_getAttachmentByName($matches[1]); if ($wpImage) { - echo '

Found Image

'; + //echo '

Found Image

'; + $fileDuplicates[] = $image->getAttribute('src'); } else { - echo '

Image still not found

'; + //echo '

Image still not found

'; + //echo '
'; + $filesMissing[] = $image->getAttribute('src'); continue; } } } if (!$wpImage) { - echo '

Image not found as attachment 2

'; + //echo '

Image not found as attachment 2

'; //echo '
' . print_r($image->getAttribute('src'), true) . '
'; $parsed = parse_url($image->getAttribute('src')); $filename = basename($parsed['path']); if (preg_match(';is\d{2,}-\d{10,}-\d{5,};', $filename)) { $rootUrl = str_replace('/' . $filename, '', $image->getAttribute('src')); - echo '
' . print_r($parsed, true) . '
'; - echo '
' . print_r($filename, true) . '
'; - echo '
' . print_r($rootUrl, true) . '
'; + //echo '
' . print_r($parsed, true) . '
'; + //echo '
' . print_r($filename, true) . '
'; + //echo '
' . print_r($rootUrl, true) . '
'; //if (preg_match('/(\d{4})\/(\d{2})$/', $rootUrl, $matches)) { //echo '
' . print_r($matches, true) . '
'; //$uploadDir = wp_upload_dir(); @@ -945,14 +949,15 @@ } } if ($wpImage) { + $filesFound[] = $image->getAttribute('src'); //$strToReplace = $dom->saveHTML($image); //echo '
'.htmlspecialchars($strToReplace).'
'; - echo '

Image found: id '.$wpImage->ID.'

'; + //echo '

Image found: id '.$wpImage->ID.'

'; if ($width && $height) { - echo '

width: ' . $width . '

'; - echo '

height: ' . $height . '

'; + //echo '

width: ' . $width . '

'; + //echo '

height: ' . $height . '

'; if ($width > 300 || $height > 300) { - echo '

Found Large

'; + //echo '

Found Large

'; $size = 'large'; $newImage = wp_get_attachment_image_src($wpImage->ID, $size); $image->setAttribute('class', 'alignnone wp-image-' . $wpImage->ID); @@ -960,7 +965,7 @@ $image->setAttribute('src', $newImage[0]); } } else if ($width < 150 && $height < 150) { - echo '

Found Thumbnail

'; + //echo '

Found Thumbnail

'; $size = 'thumbnail'; $newImage = wp_get_attachment_image_src($wpImage->ID, $size); $image->setAttribute('class', 'alignnone size-' . $size . ' wp-image-' . $wpImage->ID); @@ -968,7 +973,7 @@ $image->setAttribute('src', $newImage[0]); } } else { - echo '

Found Medium

'; + //echo '

Found Medium

'; $size = 'medium'; $newImage = wp_get_attachment_image_src($wpImage->ID, $size); $image->setAttribute('class', 'alignnone size-' . $size . ' wp-image-' . $wpImage->ID); @@ -991,10 +996,11 @@ $image->setAttribute('height', $height); //echo htmlspecialchars($dom->saveHTML($image)); } else { - echo '

no media found

'; + //echo '

no media found

'; + $filesMissing[] = $image->getAttribute('src'); } } - echo ''; + //echo ''; } // remove the extra stuff Dom put in $content = preg_replace( @@ -1006,13 +1012,17 @@ $dom->saveHTML() ) ); - echo '
'.print_r(htmlspecialchars($content), true).'
'; + //echo '
'.print_r(htmlspecialchars($content), true).'
'; $updatePost = array( 'ID' => $post->ID, 'post_content' => $content ); - wp_update_post($updatePost); + //wp_update_post($updatePost); } + //echo '
Files: ' . print_r($files, true) . '
'; + echo '
Files Found: ' . print_r($filesFound, true) . '
'; + echo '
Duplicate Files: ' . print_r($fileDuplicates, true) . '
'; + echo '
Files Missing: ' . print_r($filesMissing, true) . '
'; } } @@ -1023,7 +1033,7 @@ SELECT * FROM {$wpdb->prefix}posts WHERE post_type = 'attachment' - AND post_name = '{$name}'"; + AND (post_name = '{$name}' OR post_title = '{$name}')"; $results = $wpdb->get_results($sql, OBJECT); return (!empty($results)) ? $results[0] : false; }