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".'<a href="'.$fileUrl.'">'.$fileName.'</a>';
}
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']}
echo '<pre>' . print_r(get_option(GLM_WP_IMPORT_POST_OPTION, array()), true) . '</pre>';
}
+ private function _updatePage($oldId, $postID)
+ {
+ $pages = $this->_fetchAllPages($oldId);
+ //echo '<pre>' . print_r($pages, true) . '</pre>';
+
+ $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 '<p>Fetching Pages</p>';
}
}
- 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 '<pre>' . print_r($files, true) . '</pre>';
- //$images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
- //$media = array_merge($images, $files);
- //echo '<pre>' . print_r($media, true) . '</pre>';
$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 '<pre>' . print_r($sql) . '</pre>';
$results = $wpdb->get_results($sql, OBJECT);
+ var_dump(count($results));
if (count($results) > 0) {
foreach ($results as $post) {
$content = $post->post_content;
echo '<div style="border: 1px solid green; padding: 9px; margin: 10px;">';
- $urlPattern = '%<a href="(' . $this->_options['toolbox_image_url'] . '/[^">]*)" ?[^>]*>([^>]+)</a>%s';
+ $urlPattern = '%<a href="(http://www.emmetcounty.org/uploads/[^">]*)" ?[^>]*>([^>]+)</a>%s';
if (preg_match_all($urlPattern, $content, $isMatch)) {
$isMatchCount = count($isMatch[0]);
- echo '<p>Matches is0 ' . $isMatchCount . '</p>';
+ echo '<p>Matches uploads ' . $isMatchCount . '</p>';
for ($index = 0; $index < $isMatchCount; ++$index) {
echo '<pre>'.htmlspecialchars($isMatch[1][$index]).'</pre>';
//echo '<pre>'.htmlspecialchars(basename($isMatch[1][$index])).'</pre>';
$fileName,
$fileTitle,
'',
- $post->ID,
+ $postID,
$this->_options['site_url'] . '/uploads/'
);
}
}
}
+
+ 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 '<pre>' . print_r($files, true) . '</pre>';
+ //$images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
+ //$media = array_merge($images, $files);
+ //echo '<pre>' . print_r($media, true) . '</pre>';
+ $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 '<pre>' . print_r($sql) . '</pre>';
+ $results = $wpdb->get_results($sql, OBJECT);
+ var_dump(count($results));
+ if (count($results) > 0) {
+ foreach ($results as $post) {
+ $content = $post->post_content;
+ echo '<div style="border: 1px solid green; padding: 9px; margin: 10px;">';
+ //$urlPattern = '%<a href="(' . $this->_options['toolbox_image_url'] . '/[^">]*)" ?[^>]*>([^>]+)</a>%s';
+ $urlPattern = '%<a href="(http://www.emmetcounty.org/uploads/[^">]*)" ?[^>]*>([^>]+)</a>%s';
+ if (preg_match_all($urlPattern, $content, $isMatch)) {
+ $isMatchCount = count($isMatch[0]);
+ echo '<p>Matches is0 ' . $isMatchCount . '</p>';
+ for ($index = 0; $index < $isMatchCount; ++$index) {
+ echo '<pre>'.htmlspecialchars($isMatch[1][$index]).'</pre>';
+ //echo '<pre>'.htmlspecialchars(basename($isMatch[1][$index])).'</pre>';
+ //echo '<pre>'.print_r(pathinfo($isMatch[1][$index]), true).'</pre>';
+ $fileName = basename($isMatch[1][$index]);
+ echo '<pre>File Name: ' . print_r($fileName, true) . '</pre>';
+ $fileTitle = $isMatch[2][$index];
+ echo '<pre>File Title: ' . print_r($fileTitle, true) . '</pre>';
+ $key = $this->_getAttachmentByName($fileName);
+ echo '<pre>Key: ' . print_r($key, true) . '</pre>';
+ // 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 '<pre>'.htmlspecialchars($content).'</pre>';
+ echo '</div>';
+ }
+ }
+ }
+
+
private function _updateMediaSrc()
{
global $wpdb;
}
break;
case 1:
- echo '<p>Reset</p>';
- $this->_post = $this->_images = $this->_files = array();
- $this->_storePost();
- $this->_storeImages();
- $this->_storeFiles();
- $numPagesImported = $this->_import();
- echo '<p>' . $numPagesImported . ' Pages Imported</p>';
- echo '<p><a href="admin.php?import=toolbox&step=2">Step Two (Importing Images)</a></p>';
+ echo '<p>Page to page import</p>';
+ // 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 '<p>Reset</p>';
+ //$this->_post = $this->_images = $this->_files = array();
+ //$this->_storePost();
+ //$this->_storeImages();
+ //$this->_storeFiles();
+ //$numPagesImported = $this->_import();
+ //echo '<p>' . $numPagesImported . ' Pages Imported</p>';
+ //echo '<p><a href="admin.php?import=toolbox&step=2">Step Two (Importing Images)</a></p>';
+ //break;
case 2:
echo '<p>Done</p>';
echo '<p><a href="admin.php?import=toolbox&step=3">Step Three (Updating Image Ref)</a></p>';