From: Steve Sutton Date: Tue, 14 Jul 2015 20:40:43 +0000 (-0400) Subject: Update notes and add method for keyword replacement X-Git-Tag: v0.0.2^2~36 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=ad7cb1644007d554826f8378d77ea607e66374e3;p=WP-Plugins%2Fglm-wp-importer.git Update notes and add method for keyword replacement --- diff --git a/NOTES.md b/NOTES.md index 6b693f9..7338740 100644 --- a/NOTES.md +++ b/NOTES.md @@ -51,9 +51,12 @@ $post = array( ``` ## Todo -Need to import all the paragraph images into Media Library and assign them to their page. -Getting Errors on some of the images -Also need to fix the file permissions for the fetched images. -Need to pull all image url’s out of the post_content sections and replace them with images that are imported into the Media Library. -Need to replace any ‘keywords’ with the correct url’s. +ac|todo item +-|----- +X|Need to import all the paragraph images into Media Library and assign them to their page. +X|Getting Errors on some of the images +X|Also need to fix the file permissions for the fetched images. +X|Need to pull all image url’s out of the post_content sections and replace them with images that are imported into the Media Library. + |Need to replace any ‘keywords’ with the correct url’s. + |Need to replace any of the old site url's from their name-number/ to the correct wordpress ones. diff --git a/controllers/Import.php b/controllers/Import.php index 7db6030..4ba6360 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -203,7 +203,8 @@ $sql = "SELECT * FROM toolbox.pages"; $data = $this->_dbh->query($sql)->fetchAll(); printf('

Found %d Pages

', count($data)); - echo 'Start the Import Now'; + echo '

Start the Import Now

'; + echo '

Part 2

'; } } @@ -503,6 +504,50 @@ echo '
' . print_r($this->_options, true) . '
'; } + /** + * _findAndReplace + * + * Find and Replace all the 'keyword' + * + * @param mixed $haystack String for replacement + * + * @access private + * @return void + */ + private function _findAndReplace($haystack) + { + if (strstr($haystack, '{') !== false) { + $pattern = '/\{([A-Z0-9\&\-\,\'\" ]*)\}/i'; + if (preg_match_all($pattern, $haystack, $needle) != 0) { + $total = count($needle[0]); + for ($iter = 0; $iter < $total; $iter++) { + // replace this with the real post + $page = $this->_pageGateway->findByKeyword($needle[1][$iter]); + if ($page == false) { + //return $haystack; + } else { + // need to get the page url for this from wp + $seoUrl = Toolkit_Template_Page::getSeoUrl( + $this->_pageGateway, + $page['id'] + ); + $anchor = ''.$page['navigation_name'].''; + $haystack = str_replace($needle[0][$iter], $anchor, $haystack); + } + } + return $haystack; + } else { + return $haystack; + } + + if (strstr($haystack, '{') !== false) { + return $this->_findAndReplace($haystack); + } + } + + return $haystack; + } + /** * _import * @@ -561,6 +606,22 @@ } } + private function _replaceUrls() + { + $this->_connect(); + echo '

Replace keywords

'; + $sql = " + SELECT id,navigation_name,keyword + FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} + WHERE keyword != '' + ORDER BY parent,pos"; + $stmt = $this->_dbh->query($sql); + while ($page = $stmt->fetch()) { + echo '
' . print_r($page, true) .  '
'; + } + echo '

Replace page url\'s

'; + } + /** * dispatch * @@ -587,6 +648,9 @@ case 1: $this->_import(); break; + case 2: + $this->_replaceUrls(); + break; } $this->_footer();