From 7ce08429684f59ea6cd3db361269e1d41d458b57 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 14 Sep 2015 15:39:38 -0400 Subject: [PATCH] Update for government options Setting up this one to import into already crea,ted pages --- controllers/Import.php | 200 +++++++++++++++++++++++++++++++++-------- 1 file changed, 161 insertions(+), 39 deletions(-) diff --git a/controllers/Import.php b/controllers/Import.php index 18abce9..68eba30 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -191,22 +191,8 @@ private function _displayFile($data) { - //if ($this->_options['toolbox_paragraphs_table'] == 'pages') { - //$file_id = $this->_handleMediaFile($data['filename']); - //} else { - //$file_id = $this->_handleMediaFile( - //$data['filename'], - //'', - //0, - //$this->_options['site_url'] . 'uploads/' - //); - //} - - //if (!$file_id) { - //return false; - //} - //$fileUrl = wp_get_attachment_url($file_id); - $fileUrl =$this->_options['toolbox_image_url'] . '/original/' . $data['filename']; + //$fileUrl =$this->_options['toolbox_image_url'] . '/original/' . $data['filename']; + $fileUrl = 'http://www.emmetcounty.org/uploads/' . $data['filename']; $fileName = ($data['urltext']) ? $data['urltext'] : $data['filename']; return "\n".''.$fileName.''; } @@ -362,10 +348,12 @@ return $WHERE; } - private function _fetchAllPages($limit = null, $offset = 0) + private function _fetchAllPages($postID = null) { $this->_connect(); - $WHERE = $this->_getWhereSql(); + $WHERE = (isset($postID)) + ? "WHERE id = {$postID}" + : $this->_getWhereSql(); $pageSql = " SELECT * FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} @@ -527,6 +515,40 @@ echo '
' . print_r(get_option(GLM_WP_IMPORT_POST_OPTION, array()), true) . '
'; } + private function _updatePage($oldId, $postID) + { + $pages = $this->_fetchAllPages($oldId); + //echo '
' . print_r($pages, true) . '
'; + + $page = $pages[0]; + if ($page['parent']) { + + } + $pageName = (isset($page['navigation_name'])) + ? $page['navigation_name'] + : $page['category']; + // if you don't find the parent page id then use the default given or 0 + $parent = isset($this->_post[$page['parent']]) + ? $this->_post[$page['parent']] + : (($this->_options['parent_page']) ? $this->_options['parent_page'] : 0); + $updatePost = array( + 'ID' => $postID, + 'post_content' => $page['pageContent'], + 'post_name' => $pageName,// slug ? + 'post_title' => $pageName, + 'post_status' => 'publish', + 'post_type' => 'page', + 'post_author' => 'steve', + 'ping_status' => 'closed', + 'post_parent' => $parent, + 'menu_order' => $page['pos'], + 'comment_status' => 'closed', + ); + wp_update_post($updatePost); + $this->_post[$page['id']] = $postID; + $this->_storePost(); + } + private function _import() { echo '

Fetching Pages

'; @@ -924,30 +946,27 @@ } } - private function _updateFilesHref() + private function _importPageFiles($postID) { global $wpdb; - $currentPostArray = get_option(GLM_WP_IMPORT_POST_OPTION, array()); - $files = get_option(GLM_WP_IMPORT_FILES_OPTION, array()); - echo '
' . print_r($files, true) . '
'; - //$images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array()); - //$media = array_merge($images, $files); - //echo '
' . print_r($media, true) . '
'; $sql = " SELECT * FROM {$wpdb->prefix}posts - WHERE post_content LIKE '%http://is0.gaslightmedia.com%' - AND post_type = 'page'"; - $sql .= " AND ID IN (" . implode(',', $currentPostArray) . ")"; + WHERE post_type = 'page'"; + $sql .= ($postID) + ? " AND ID = {$postID} " + :" AND ID IN (" . implode(',', $currentPostArray) . ")"; + echo '
' . print_r($sql) . '
'; $results = $wpdb->get_results($sql, OBJECT); + var_dump(count($results)); if (count($results) > 0) { foreach ($results as $post) { $content = $post->post_content; echo '
'; - $urlPattern = '%]*)" ?[^>]*>([^>]+)%s'; + $urlPattern = '%]*)" ?[^>]*>([^>]+)%s'; if (preg_match_all($urlPattern, $content, $isMatch)) { $isMatchCount = count($isMatch[0]); - echo '

Matches is0 ' . $isMatchCount . '

'; + echo '

Matches uploads ' . $isMatchCount . '

'; for ($index = 0; $index < $isMatchCount; ++$index) { echo '
'.htmlspecialchars($isMatch[1][$index]).'
'; //echo '
'.htmlspecialchars(basename($isMatch[1][$index])).'
'; @@ -964,7 +983,7 @@ $fileName, $fileTitle, '', - $post->ID, + $postID, $this->_options['site_url'] . '/uploads/' ); } @@ -986,6 +1005,75 @@ } } + + private function _updateFilesHref($postID) + { + global $wpdb; + $currentPostArray = get_option(GLM_WP_IMPORT_POST_OPTION, array()); + $files = get_option(GLM_WP_IMPORT_FILES_OPTION, array()); + //echo '
' . print_r($files, true) . '
'; + //$images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array()); + //$media = array_merge($images, $files); + //echo '
' . print_r($media, true) . '
'; + $sql = " + SELECT * + FROM {$wpdb->prefix}posts + -- WHERE post_content LIKE '%http://is0.gaslightmedia.com%' + WHERE post_type = 'page'"; + $sql .= ($postID) + ? " AND ID = {$postID} " + :" AND ID IN (" . implode(',', $currentPostArray) . ")"; + echo '
' . print_r($sql) . '
'; + $results = $wpdb->get_results($sql, OBJECT); + var_dump(count($results)); + if (count($results) > 0) { + foreach ($results as $post) { + $content = $post->post_content; + echo '
'; + //$urlPattern = '%]*)" ?[^>]*>([^>]+)%s'; + $urlPattern = '%]*)" ?[^>]*>([^>]+)%s'; + if (preg_match_all($urlPattern, $content, $isMatch)) { + $isMatchCount = count($isMatch[0]); + echo '

Matches is0 ' . $isMatchCount . '

'; + for ($index = 0; $index < $isMatchCount; ++$index) { + echo '
'.htmlspecialchars($isMatch[1][$index]).'
'; + //echo '
'.htmlspecialchars(basename($isMatch[1][$index])).'
'; + //echo '
'.print_r(pathinfo($isMatch[1][$index]), true).'
'; + $fileName = basename($isMatch[1][$index]); + echo '
File Name: ' . print_r($fileName, true)  . '
'; + $fileTitle = $isMatch[2][$index]; + echo '
File Title: ' . print_r($fileTitle, true)  . '
'; + $key = $this->_getAttachmentByName($fileName); + echo '
Key: ' . print_r($key, true)  . '
'; + // check on format of filename + if (!$key && ($fileName && $fileTitle)) { + //$key = $this->_handleMediaFile( + //$fileName, + //$fileTitle, + //'', + //$post->ID, + //$this->_options['site_url'] . '/uploads/' + //); + } + if ($key !== false) { + var_dump($key); + $newSrc = wp_get_attachment_url($key); + $content = str_replace($isMatch[1][$index], $newSrc, $content); + } + } + $updatePost = array( + 'ID' => $post->ID, + 'post_content' => $content + ); + //wp_update_post($updatePost); + } + echo '
'.htmlspecialchars($content).'
'; + echo '
'; + } + } + } + + private function _updateMediaSrc() { global $wpdb; @@ -1306,15 +1394,49 @@ } break; case 1: - echo '

Reset

'; - $this->_post = $this->_images = $this->_files = array(); - $this->_storePost(); - $this->_storeImages(); - $this->_storeFiles(); - $numPagesImported = $this->_import(); - echo '

' . $numPagesImported . ' Pages Imported

'; - echo '

Step Two (Importing Images)

'; + echo '

Page to page import

'; + // Buildings and grounds + //$this->_updatePage(213, 6769); + //$this->_importPageFiles(6769); + + // transportation committee + //$this->_updatePage(229, 6771); + //$this->_importPageFiles(6771); + + // Airport Board + //$this->_updatePage(212, 6775); + //$this->_importPageFiles(6775); + + // Ambulance Advisory + //$this->_updatePage(601, 6767); + //$this->_importPageFiles(6767); + + // Sanitary Code + //$this->_updatePage(236, 6773); + //$this->_importPageFiles(6773); + + // Past Columns from the VA Director + //$this->_updatePage(633, 7108); + //$this->_importPageFiles(7108); + + // Parks and recreation minutes + //$this->_updatePage(218, 7252); + //$this->_importPageFiles(7252); + + // Cell phone tour + //$this->_updatePage(448, 7254); + //$this->_importPageFiles(7254); break; + //case 1: + //echo '

Reset

'; + //$this->_post = $this->_images = $this->_files = array(); + //$this->_storePost(); + //$this->_storeImages(); + //$this->_storeFiles(); + //$numPagesImported = $this->_import(); + //echo '

' . $numPagesImported . ' Pages Imported

'; + //echo '

Step Two (Importing Images)

'; + //break; case 2: echo '

Done

'; echo '

Step Three (Updating Image Ref)

'; -- 2.17.1