if (!isset($data['image'])) {
return false;
}
- $img_url = $this->_options['toolbox_image_url'] . '/tbs1/' . $data['image'];
+ $img_url = $this->_options['toolbox_image_url'] . '/CKImage/' . $data['image'];
$content = '';
if (isset($data['caption']) && $data['caption']) {
$content .= '[caption align="align'.$alignment.'"]<img src="' . $img_url . '"> ' . $data['caption'] . '[/caption]';
$page['pageContent'] = '';
$iterator = 1;
if ($this->_options['toolbox_page_table'] == 'bus_category') {
- $page['pageContent'] .= '<h1>'.$page['category'].'</h1>';
+ //$page['pageContent'] .= '<h1>'.$page['category'].'</h1>';
++$iterator;
if ($page['image']) {
//$page['images'][] = $page['image'];
$content = $post->post_content;
echo '<pre>Updating Media Src\'s: ' . print_r($post->post_title, true) . '</pre>';
echo '<div style="border: 1px solid green; padding: 9px; margin: 10px;">';
- if (preg_match_all('%\[caption [^\]]+\]<img ([^>]+)>([^\[]*)\[/caption\]%', $content, $cMatch)) {
+ if (preg_match_all('%(:?\[caption [^\]]+\])?<img ([^>]+)>(:?([^\[]*)\[/caption\])?%', $content, $cMatch)) {
$captionCount = count($cMatch[0]);
- echo '<p>Matches in Caption ' . $captionCount . '</p>';
- //echo '<pre>' . print_r($cMatch, true) . '</pre>';
+ //echo '<p>Matches in Caption ' . $captionCount . '</p>';
+ //echo '<pre>' . var_export($cMatch, true) . '</pre>';
for ($index = 0; $index < $captionCount; ++$index) {
- //echo '<pre>cMatch: ' . print_r($cMatch, true) . '</pre>';
+ //echo '<pre>cMatch: ' . print_r($cMatch[0][$index], true) . '</pre>';
echo '<pre>'.htmlspecialchars($cMatch[0][$index]).'</pre>';
- echo '<pre>Caption Match: ' . print_r($cMatch[1][$index], true) . '</pre>';
- echo '<pre>Caption Text: ' . print_r($cMatch[2][$index], true) . '</pre>';
- if (preg_match('%src="([^"]+)"%', $cMatch[1][$index], $srcMatch)) {
+ //echo '<pre>Caption Match: ' . print_r($cMatch[1][$index], true) . '</pre>';
+ //echo '<pre>Caption Text: ' . print_r($cMatch[2][$index], true) . '/End Caption Text</pre>';
+ if (preg_match('%src="([^"]+)"%', $cMatch[0][$index], $srcMatch)) {
+ //echo '<pre>' . print_r($srcMatch, true) . '</pre>';
echo '<pre>Sub Src Match: ' . print_r($srcMatch[1], true) . '</pre>';
- $fileInfo = pathinfo($srcMatch[1]);
- $fileName = basename($srcMatch[1]);
- $fileName = $fileInfo['filename'];
+ $fileInfo = pathinfo($srcMatch[1]);
+ $fileName = basename($srcMatch[1]);
+ $fileBaseName = $fileInfo['filename'];
+ echo '<pre>File Info: ' . print_r($fileInfo, true) . '</pre>';
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);
+ $path = $fileInfo['dirname'];
+ //echo '<pre>'.var_dump($path).'</pre>';
+
+ $imagesKey = $this->_getAttachmentByName($fileBaseName);
+ //var_dump($imagesKey);
if (!$imagesKey) {
$imagesKey = $this->_handleMediaFile(
$fileName,
- $fileName,
+ $fileBaseName,
'',
$post->ID,
$path
);
}
+
if ($imagesKey) {
var_dump($imagesKey);
$newImage = wp_get_attachment_image_src($imagesKey, 'medium');
}
}
}
+
// In this next part Have to remember the $content is already processed.
- // Don't edit src if they alrea,dy have an ID
+ // Don't edit src if they already have an ID
if (preg_match_all('%<img ([^>]+)>%', $content, $matches)) {
$imageCount = count($matches[0]);
for ($index = 0; $index < $imageCount; ++$index) {
}
}
}
- echo '<pre>'.htmlspecialchars($content).'</pre>';
+ //echo '<pre>'.htmlspecialchars($content).'</pre>';
echo '</div>';
$updatePost = array(
'ID' => $post->ID,
}
}
+ private function _getBusImages()
+ {
+ global $wpdb;
+ echo '<pre>' . print_r($this->_options['toolbox_schema'], true) . '</pre>';
+ echo '<pre>' . print_r($this->_options['toolbox_paragraphs_table'], true) . '</pre>';
+ if ($this->_options['toolbox_paragraphs_table']) {
+ $this->_images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
+ $this->_connect();
+ $sql = "
+ SELECT image,imagename as caption
+ FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_paragraphs_table']}
+ WHERE image != ''";
+ $stmt = $this->_dbh->query($sql);
+ while ($row = $stmt->fetch()) {
+ echo '<pre>' . print_r($row, true) . '</pre>';
+ $fileName = $row['image'];
+ $fileTitle = ($row['caption']) ? $row['caption'] : $fileName;
+ $wpImage = $this->_handleMediaFile(
+ $fileName,
+ $fileTitle,
+ '',
+ 0,
+ $this->_options['toolbox_image_url'] . '/CKImage/'
+ );
+ echo '<pre>' . print_r($wpImage, true) . '</pre>';
+ $this->_images[$wpImage] = $fileName;
+ }
+ $this->_storeImages();
+ }
+ }
+
+ private function _getBusCategoryImages()
+ {
+ global $wpdb;
+ echo '<pre>' . print_r($this->_options['toolbox_schema'], true) . '</pre>';
+ echo '<pre>' . print_r($this->_options['toolbox_page_table'], true) . '</pre>';
+ if ($this->_options['toolbox_paragraphs_table']) {
+ $this->_images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
+ $this->_connect();
+ $sql = "
+ SELECT image,imagename as caption
+ FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']}
+ WHERE image != ''";
+ $stmt = $this->_dbh->query($sql);
+ while ($row = $stmt->fetch()) {
+ echo '<pre>' . print_r($row, true) . '</pre>';
+ $fileName = $row['image'];
+ $fileTitle = ($row['caption']) ? $row['caption'] : $fileName;
+ $wpImage = $this->_handleMediaFile(
+ $fileName,
+ $fileTitle,
+ '',
+ 0,
+ $this->_options['toolbox_image_url'] . '/CKImage/'
+ );
+ echo '<pre>' . print_r($wpImage, true) . '</pre>';
+ $this->_images[$wpImage] = $fileName;
+ }
+ $this->_storeImages();
+ }
+ }
public function dispatch()
{
$this->_header();
$this->_getParagraphImages();
echo '<p>Done</p>';
} else {
+ $this->_getBusCategoryImages();
+ $this->_getBusImages();
echo '<p>No import from images</p>';
}
echo '<p><a href="admin.php?import=toolbox&step=3">Step Three (Updating Image Ref)</a></p>';