FROM {$wpdb->prefix}posts
WHERE post_content LIKE '%<img%'
AND post_type = 'page'";
- //$sql .= " AND post_title = 'Business Assistance'";
+ $sql .= " AND post_title = 'Agriculture'";
$results = $wpdb->get_results($sql, OBJECT);
echo '<p>'.count($results).'</p>';
if (count($results) > 0) {
}
if ($image->hasAttribute('style')) {
$style = $image->getAttribute('style');
- //echo '<pre>' . print_r($style, true) . '</pre>';
- if (preg_match(';width[: ]+(\d+)px;', $style, $wMatch)) {
+ echo '<pre>' . print_r($style, true) . '</pre>';
+ if (preg_match(';[^-]width[: ]+(\d+)px;', $style, $wMatch)) {
$width = $wMatch[1];
}
- if (preg_match(';height[: ]+(\d+)px;', $style, $hMatch)) {
+ if (preg_match(';[^-]height[: ]+(\d+)px;', $style, $hMatch)) {
$height = $hMatch[1];
}
- //echo '<pre>' . print_r($width, true) . '</pre>';
- //echo '<pre>' . print_r($height, true) . '</pre>';
+ echo '<pre>' . print_r($width, true) . '</pre>';
+ echo '<pre>' . print_r($height, true) . '</pre>';
}
if ($image->hasAttribute('src')) {
//echo '<pre>' . print_r($image->getAttribute('src'), true) . '</pre>';
$imgName = basename($image->getAttribute('src'));
- //echo '<pre>' . print_r($imgName, true) . '</pre>';
+ echo '<pre>' . print_r($imgName, true) . '</pre>';
$imgPathInfo = pathinfo($imgName);
$wpImage = $this->_getAttachmentByName($imgPathInfo['filename']);
- //echo '<pre>' . print_r($wpImage, true) . '</pre>';
+ if (!$wpImage) {
+ echo '<pre>' . print_r($image->getAttribute('src'), true) . '</pre>';
+ $parsed = parse_url($image->getAttribute('src'));
+ $filename = basename($parsed['path']);
+ if (preg_match(';is\d{2,}-\d{10,}-\d{5,};', $filename)) {
+ $rootUrl = str_replace('/' . $filename, '', $image->getAttribute('src'));
+ echo '<pre>' . print_r($parsed, true) . '</pre>';
+ echo '<pre>' . print_r($filename, true) . '</pre>';
+ echo '<pre>' . print_r($rootUrl, true) . '</pre>';
+ $wpImage = $this->_handleMediaFile(
+ basename($parsed['path']),
+ '',
+ $post->ID,
+ $rootUrl . '/'
+ );
+ }
+ }
if ($wpImage) {
//$strToReplace = $dom->saveHTML($image);
//echo '<pre>'.htmlspecialchars($strToReplace).'</pre>';
$dom->saveHTML()
)
);
- //echo '<pre>'.print_r(htmlspecialchars($content), true).'</pre>';
+ echo '<pre>'.print_r(htmlspecialchars($content), true).'</pre>';
$updatePost = array(
'ID' => $post->ID,
'post_content' => $content