updates for mountpleasant
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 18 Aug 2015 16:27:47 +0000 (12:27 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 18 Aug 2015 16:27:47 +0000 (12:27 -0400)
NOTES.md
controllers/Import.php

index ec8e4fb..473d5bb 100644 (file)
--- a/NOTES.md
+++ b/NOTES.md
@@ -77,5 +77,8 @@ Step 2 I have all media being imported.
 Step 3 Updates all media src tags and caption tags
 Step 4 update keywords , site urls links inside, and update file refs
 
-## For 08/11/2015 ##
+### For 08/11/2015 ###
 Need to check the image references against the database and not the files array
+
+### For 08/18/2015 ###
+May need to check for any links to old member profile pages? Or this may be for something the member import has to do.
index a9833c8..43a77fb 100644 (file)
                             echo '<pre>Caption Text: ' . print_r($cMatch[2][$index], true)  . '</pre>';
                             if (preg_match('%src="([^"]+)"%', $cMatch[1][$index], $srcMatch)) {
                                 echo '<pre>Sub Src Match: ' . print_r($srcMatch[1], true)  . '</pre>';
+                                $fileInfo = pathinfo($srcMatch[1]);
                                 $fileName = basename($srcMatch[1]);
+                                $fileName = $fileInfo['filename'];
                                 echo '<pre>File Name: ' . print_r($fileName, true)  . '</pre>';
                                 $path = str_replace($fileName, '', $srcMatch[1]);
+                                $path = $filInfo['dirname'];
                                 $imagesKey = $this->_getAttachmentByName($fileName);
                                 var_dump($imagesKey);
                                 if (!$imagesKey) {
                             }
                         }
                     }
+                    // In this next part Have to remember the $content is already processed.
+                    // Don't edit src if they alrea,dy have an ID
                     if (preg_match_all('%<img ([^>]+)>%', $content, $matches)) {
                         $imageCount = count($matches[0]);
                         for ($index = 0; $index < $imageCount; ++$index) {
                             echo '<pre>Image Match: ' . $imageCount  . '</pre>';
                             echo '<pre>'.htmlspecialchars($matches[0][$index]).'</pre>';
+                            if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) {
+                                return new WP_Error('upload_error', $uploads['error']);
+                            }
+                            echo '<pre>Uploads Url: ' . print_r($uploads['url'], true)  . '</pre>';
+                            if (preg_match('%src="' . $uploads['url'] . '[^"]+"%', $matches[1][$index], $pMatch)) {
+                                continue;
+                            }
                             if (preg_match('%src="([^"]+)"%', $matches[1][$index], $srcMatch)) {
                                 echo '<pre>Sub Src Match: ' . print_r($srcMatch[1], true)  . '</pre>';
-                                $fileName = basename($srcMatch[1]);
+                                $fileInfo = pathinfo($srcMatch[1]);
+                                echo '<pre>' . print_r($fileInfo, true) . '</pre>';
+                                $fileName = $fileInfo['filename'];
                                 echo '<pre>File Url: ' . print_r($srcMatch[1], true)  . '</pre>';
                                 echo '<pre>File Name: ' . print_r($fileName, true)  . '</pre>';
-                                $path = str_replace($fileName, '', $srcMatch[1]);
+                                $path = $filInfo['dirname'];
                                 echo '<pre>File Path: ' . print_r($path, true)  . '</pre>';
                                 $imagesKey = $this->_getAttachmentByName($fileName);
                                 var_dump($imagesKey);
             SELECT *
               FROM {$wpdb->prefix}posts
              WHERE post_type = 'attachment'
-            AND (post_name = '{$name}' OR post_title = '{$name}')";
+            AND (post_name like '{$name}%' OR post_title like '{$name}%')";
             $results = $wpdb->get_results($sql, OBJECT);
             return (!empty($results)) ? $results[0]->ID : false;
             //return (!empty($results)) ? $results[0] : false;
                         echo '<pre>' . print_r($filename, true) . '</pre>';
                         echo '<pre>' . print_r($rootUrl, true) . '</pre>';
                         $img_id = $this->_handleMediaFile(
-                            basename($parsed['path']),
+                            $filename,
                             '',
                             $post->ID,
                             $rootUrl . '/'
                 $this->_updateFilesHref();
                 echo '<p>Done</p>';
                 echo '<p><a href="admin.php?import=toolbox&amp;step=5">Step Five (Updating Url\'s and keywords)</a></p>';
+                break;
             case 5:
                 echo '<p>Phase Five</p>';
                 echo '<p>Site Url</p>';