2015-05-21 17:39:11 +02:00
|
|
|
<?php namespace Todaymade\Daux\Format\Confluence;
|
|
|
|
|
2015-11-06 22:44:34 +01:00
|
|
|
use Todaymade\Daux\Format\Base\EmbedImages;
|
|
|
|
use Todaymade\Daux\Tree\Raw;
|
2015-05-21 17:39:11 +02:00
|
|
|
|
2015-07-28 17:25:03 +02:00
|
|
|
class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
2015-05-21 17:39:11 +02:00
|
|
|
{
|
2015-05-22 14:48:09 +02:00
|
|
|
public $attachments = [];
|
|
|
|
|
2015-05-21 17:39:11 +02:00
|
|
|
protected function generatePage()
|
|
|
|
{
|
2015-11-06 22:44:34 +01:00
|
|
|
$content = parent::generatePage();
|
2015-05-21 17:39:11 +02:00
|
|
|
|
|
|
|
//Embed images
|
2015-05-22 14:48:09 +02:00
|
|
|
// We do it after generation so we can catch the images that were in html already
|
2015-11-06 22:44:34 +01:00
|
|
|
$content = (new EmbedImages($this->params['tree']))
|
|
|
|
->embed(
|
|
|
|
$content,
|
|
|
|
$this->file,
|
|
|
|
function ($src, array $attributes, Raw $file) {
|
|
|
|
$filename = basename($file->getPath());
|
2015-05-22 14:48:09 +02:00
|
|
|
|
2015-11-06 22:44:34 +01:00
|
|
|
//Add the attachment for later upload
|
|
|
|
$this->attachments[] = ['filename' => $filename, 'file' => $file];
|
2015-05-21 17:39:11 +02:00
|
|
|
|
2015-11-06 22:44:34 +01:00
|
|
|
return $this->createImageTag($filename, $attributes);
|
|
|
|
}
|
|
|
|
);
|
2015-05-21 17:39:11 +02:00
|
|
|
|
2015-11-06 22:44:34 +01:00
|
|
|
return $content;
|
2015-05-22 14:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function createImageTag($filename, $attributes)
|
|
|
|
{
|
|
|
|
$img = "<ac:image";
|
|
|
|
|
|
|
|
foreach ($attributes as $name => $value) {
|
2015-07-17 23:38:06 +02:00
|
|
|
$img .= ' ac:' . $name . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8', false) . '"';
|
2015-05-22 14:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$img .= "><ri:attachment ri:filename=\"$filename\" /></ac:image>";
|
|
|
|
|
|
|
|
return $img;
|
2015-05-21 17:39:11 +02:00
|
|
|
}
|
|
|
|
}
|