Fix image embedding for confluence, fixes #439
This commit is contained in:
parent
bde251409f
commit
a0a8cbcfae
@ -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'],
|
||||
]
|
||||
);
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php namespace Todaymade\Daux\Format\Confluence;
|
||||
|
||||
use Todaymade\Daux\Format\Base\EmbedImages;
|
||||
use Todaymade\Daux\Tree\ComputedRaw;
|
||||
use Todaymade\Daux\Tree\Entry;
|
||||
use Todaymade\Daux\Tree\Raw;
|
||||
|
||||
class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
@ -17,11 +19,16 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
->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 = '<ac:image';
|
||||
|
||||
foreach ($attributes as $name => $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) . '"';
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user