fix WSP-41

This commit is contained in:
Filip Penkava
2017-04-25 14:49:39 +02:00
parent ebf9905b8c
commit d7cec58124
2 changed files with 14 additions and 12 deletions

View File

@@ -232,7 +232,7 @@ if ($obj['type'] == 'text') {
if ($fileExist) { if ($fileExist) {
set_post_thumbnail($post_ID, $fileExist->post_id); set_post_thumbnail($post_ID, $fileExist->post_id);
} else { } else {
savePicture($image->src, $post_ID, $image->oldSrc, $obj['associations']); savePicture($image->src, $post_ID, $image->oldSrc, isset($obj['associations']) ? $obj['associations'] : array(), $image->alt);
} }
} }
} elseif ($obj['pubstatus'] == 'canceled') { } elseif ($obj['pubstatus'] == 'canceled') {

View File

@@ -109,14 +109,13 @@ function saveAttachment($picture, $post_ID, $caption, $alt) {
update_post_meta($attach_id, '_wp_attachment_image_alt', wp_slash($alt)); update_post_meta($attach_id, '_wp_attachment_image_alt', wp_slash($alt));
} }
function savePicture($localPath, $postId, $oldSrc, $associations) { function savePicture($localPath, $postId, $oldSrc, $associations, $alt) {
$filenameQ = explode("/", $localPath); $filenameQ = explode("/", $localPath);
$filename = $filenameQ[count($filenameQ) - 1]; $filename = $filenameQ[count($filenameQ) - 1];
$name = null; $name = null;
$mimeType = null; $mimeType = null;
foreach ($associations as $key => $value) { foreach ($associations as $key => $value) {
var_dump($value);
if (isset($value['renditions'])) { if (isset($value['renditions'])) {
foreach ($value['renditions'] as $value2) { foreach ($value['renditions'] as $value2) {
if ($value2['href'] === $oldSrc) { if ($value2['href'] === $oldSrc) {
@@ -127,15 +126,16 @@ function savePicture($localPath, $postId, $oldSrc, $associations) {
} }
} }
} }
if ($name == null) if ($name == null) {
return; $caption = wp_strip_all_tags($alt);
$alt = wp_strip_all_tags($alt);
} else {
$caption = generate_caption_image($associations[$name]); $caption = generate_caption_image($associations[$name]);
$alt = (!empty($associations[$name]['body_text'])) ? wp_strip_all_tags($associations[$name]['body_text']) : ''; $alt = (!empty($associations[$name]['body_text'])) ? wp_strip_all_tags($associations[$name]['body_text']) : '';
}
$attachment = array( $attachment = array(
'guid' => $localPath, 'guid' => $localPath,
'post_mime_type' => $mimeType, 'post_mime_type' => $mimeType == null ? mime_content_type(wp_upload_dir()['path'] . "/" . $filename) : $mimeType,
'post_title' => $caption, 'post_title' => $caption,
'post_content' => '', 'post_content' => '',
'post_excerpt' => $caption, 'post_excerpt' => $caption,
@@ -204,12 +204,14 @@ function embed_src($src) {
class Image { class Image {
public $src, $oldSrc; public $src, $alt, $oldSrc;
public function __construct(array $attrs, $oldSrc) { public function __construct(array $attrs, $oldSrc) {
$this->src = $attrs['src']; $this->src = $attrs['src'];
$this->alt = isset($attrs['alt']) ? $attrs['alt'] : '';
$this->oldSrc = $oldSrc; $this->oldSrc = $oldSrc;
stripQuotes($this->src); stripQuotes($this->src);
stripQuotes($this->alt);
} }
} }
@@ -247,7 +249,7 @@ function embed_images($html, &$image) {
$attrs[$attr] = $value; $attrs[$attr] = $value;
} }
if ($image === null) { if ($image == null) {
$image = new Image($attrs, $oldSrc); $image = new Image($attrs, $oldSrc);
} }