diff --git a/libs/Format/Confluence/Api.php b/libs/Format/Confluence/Api.php index eb7f2e1..80d098b 100644 --- a/libs/Format/Confluence/Api.php +++ b/libs/Format/Confluence/Api.php @@ -229,7 +229,8 @@ class Api // Check if an attachment with // this name is uploaded try { - $result = json_decode($this->getClient()->get("content/$id/child/attachment?filename=$attachment[filename]")->getBody(), true); + $url = "content/$id/child/attachment?filename=" . urlencode($attachment['filename']); + $result = json_decode($this->getClient()->get($url)->getBody(), true); } catch (BadResponseException $e) { throw $this->handleError($e); } @@ -242,11 +243,13 @@ class Api $url .= "/{$result['results'][0]['id']}/data"; } + $contents = array_key_exists('file', $attachment) ? fopen($attachment['file']->getPath(), 'r') : $attachment['content']; + try { $this->getClient()->post( $url, [ - 'multipart' => [['name' => 'file', 'contents' => fopen($attachment['file']->getPath(), 'r')]], + 'multipart' => [['name' => 'file', 'contents' => $contents, 'filename' => $attachment['filename']]], 'headers' => ['X-Atlassian-Token' => 'nocheck'], ] ); diff --git a/libs/Format/Confluence/ContentPage.php b/libs/Format/Confluence/ContentPage.php index be492e3..cb29afe 100644 --- a/libs/Format/Confluence/ContentPage.php +++ b/libs/Format/Confluence/ContentPage.php @@ -1,6 +1,8 @@ embed( $content, $this->file, - function ($src, array $attributes, Raw $file) { - $filename = basename($file->getPath()); + function ($src, array $attributes, Entry $file) { //Add the attachment for later upload - $this->attachments[$filename] = ['filename' => $filename, 'file' => $file]; + if ($file instanceof Raw) { + $filename = basename($file->getPath()); + $this->attachments[$filename] = ['filename' => $filename, 'file' => $file]; + } else if ($file instanceof ComputedRaw) { + $filename = $file->getUri(); + $this->attachments[$filename] = ['filename' => $filename, 'content' => $file->getContent()]; + } return $this->createImageTag($filename, $attributes); } @@ -41,6 +48,14 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage $img = ' $value) { + if ($name == 'style') { + $re = '/float:\s*?(left|right);?/'; + if (preg_match($re, $value, $matches)) { + $img .= ' ac:align="' . $matches[1] . '"'; + $value = preg_replace($re, "", $value, 1); + } + } + $img .= ' ac:' . $name . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8', false) . '"'; }