$start = filter_var($_REQUEST['start'], FILTER_VALIDATE_INT);
//$pages = $this->_fetchAllPages(PAGES_PER_LOAD, $start);
$pages = $this->_fetchAllPages();
+ //foreach ($pages as $page) {
+ //echo '<pre>' . print_r(htmlspecialchars($page['pageContent']), true) . '</pre>';
+ //}
//echo '<pre>' . print_r($pages, true) . '</pre>';
//return;
//exit;
FROM {$wpdb->prefix}posts
WHERE post_content LIKE '%\{{$page['keyword']}\}%'
AND post_type = 'page'";
+ $currentPostArray = get_option(GLM_WP_IMPORT_POST_OPTION, array());
+ $sql .= " AND ID IN (" . implode(',', $currentPostArray) . ")";
//echo '<pre>' . print_r($sql, true) . '</pre>';
$results = $wpdb->get_results($sql, OBJECT);
$total = count($results);
private function _replaceUrls()
{
global $wpdb;
+ $currentPostArray = get_option(GLM_WP_IMPORT_POST_OPTION, array());
$this->_connect();
echo '<p>Replace page url\'s</p>';
$searchUrl = $this->_options['site_url'];
FROM {$wpdb->prefix}posts
WHERE post_content LIKE '%{$searchUrl}%'
AND post_type = 'page'";
+ $sql .= " AND ID IN (" . implode(',', $currentPostArray) . ")";
$results = $wpdb->get_results($sql, OBJECT);
if (count($results) > 0) {
$pattern = ';http://' . $parsedUrl['host'] . '/([^"]+);si';
private function _updateFilesHref()
{
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());
FROM {$wpdb->prefix}posts
WHERE post_content LIKE '%http://is0.gaslightmedia.com%'
AND post_type = 'page'";
+ $sql .= " AND ID IN (" . implode(',', $currentPostArray) . ")";
$results = $wpdb->get_results($sql, OBJECT);
if (count($results) > 0) {
foreach ($results as $post) {
$content = $post->post_content;
echo '<div style="border: 1px solid green; padding: 9px; margin: 10px;">';
- if (preg_match_all('%href="([^"]+)"%', $content, $isMatch)) {
+ $urlPattern = '%<a href="(' . $this->_options['toolbox_image_url'] . '/[^">]*)" ?[^>]*>([^>]+)</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>';
- $key = array_search(basename($isMatch[1][$index]), $files);
+ $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>';
- $updatePost = array(
- 'ID' => $post->ID,
- 'post_content' => $content
- );
- //wp_update_post($updatePost);
}
}
}
{
global $wpdb;
$images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
+ $currentPostArray = get_option(GLM_WP_IMPORT_POST_OPTION, array());
$sql = "
SELECT *
FROM {$wpdb->prefix}posts
WHERE post_content LIKE '%<img%'
AND post_type = 'page'";
+ $sql .= " AND ID IN (" . implode(',', $currentPostArray) . ")";
$results = $wpdb->get_results($sql, OBJECT);
if (count($results) > 0) {
foreach ($results as $post) {
echo '<pre>Sub Src Match: ' . print_r($srcMatch[1], true) . '</pre>';
$fileName = basename($srcMatch[1]);
echo '<pre>File Name: ' . print_r($fileName, true) . '</pre>';
- if ($imagesKey = array_search($fileName, $images)) {
+ $imagesKey = $this->_getAttachmentByName($fileName);
+ var_dump($imagesKey);
+ if (!$imagesKey) {
+ $imagesKey = $this->_handleMediaFile(
+ $fileName,
+ $fileName,
+ '',
+ $post->ID,
+ $this->_options['toolbox_image_url'] . '/tbs1/'
+ );
+ }
+ if ($imagesKey) {
var_dump($imagesKey);
$newImage = wp_get_attachment_image_src($imagesKey, 'medium');
// need to replace the src tags in content with the new image tags
echo '<pre>Image Match: ' . $imageCount . '</pre>';
echo '<pre>'.htmlspecialchars($matches[0][$index]).'</pre>';
if (preg_match('%src="([^"]+)"%', $matches[1][$index], $srcMatch)) {
- //echo '<pre>Sub Src Match: ' . print_r($srcMatch[1], true) . '</pre>';
+ echo '<pre>Sub Src Match: ' . print_r($srcMatch[1], true) . '</pre>';
$fileName = basename($srcMatch[1]);
- //echo '<pre>File Name: ' . print_r($fileName, true) . '</pre>';
- if ($imagesKey = array_search($fileName, $images)) {
+ echo '<pre>File Name: ' . print_r($fileName, true) . '</pre>';
+ $imagesKey = $this->_getAttachmentByName($fileName);
+ var_dump($imagesKey);
+ if (!$imagesKey) {
+ $imagesKey = $this->_handleMediaFile(
+ $fileName,
+ $fileName,
+ '',
+ $post->ID,
+ $this->_options['toolbox_image_url'] . '/tbs1/'
+ );
+ }
+ if ($imagesKey) {
//var_dump($imagesKey);
$newUrl = wp_get_attachment_url($imagesKey);
// need to replace the src tags in content with the new image tags
WHERE post_type = 'attachment'
AND (post_name = '{$name}' OR post_title = '{$name}')";
$results = $wpdb->get_results($sql, OBJECT);
- return (!empty($results)) ? $results[0] : false;
+ return (!empty($results)) ? $results[0]->ID : false;
+ //return (!empty($results)) ? $results[0] : false;
}
private function _getAttachmentById($id)
switch($step) {
case 0:
$this->_greet();
+ //$this->_post = array(
+ //49 => 5546,
+ //50 => 5547,
+ //51 => 5548,
+ //52 => 5549,
+ //210 => 5550,
+ //388 => 5551,
+ //562 => 5552,
+ //563 => 5553
+ //);
+ //$this->_storePost();
//$this->_readOptions();
//echo '<p><a href="admin.php?import=toolbox&step=5&start=0">CkImages</a></p>';
+ echo '<p><a href="admin.php?import=toolbox&step=1">Begin Import</a></p>';
$currentPostArray = get_option(GLM_WP_IMPORT_POST_OPTION, array());
+ echo '<pre>' . print_r($currentPostArray, true) . '</pre>';
$images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
echo '<pre>' . print_r($images, true) . '</pre>';
$files = get_option(GLM_WP_IMPORT_FILES_OPTION, array());
}
break;
case 1:
+ echo '<p>Reset</p>';
+ $this->_post = $this->_images = $this->_files = array();
+ $this->_storePost();
+ $this->_storeImages();
+ $this->_storeFiles();
$numPagesImported = $this->_import();
- $start = filter_var($_REQUEST['start'], FILTER_VALIDATE_INT);
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>';
+ //echo '<p><a href="admin.php?import=toolbox&step=3">Part 3</a></p>';
+ break;
+ case 'z':
echo '<p>Now processing the images from old database tables</p>';
$this->_images = array();
$this->_storeImages();
case 4:
echo '<p>Phase Four</p>';
echo '<p>Files</p>';
- $this->_updateFilesHref();
+ //$this->_updateFilesHref();
echo '<p>Site Url</p>';
+ // Replace the page Url's
$this->_replaceUrls();
+ // Replace the Keywords
$this->_replaceKeywords();
echo '<p>Done</p>';
break;