2015-11-06 22:44:34 +01:00
|
|
|
<?php namespace Todaymade\Daux\Format\HTMLFile;
|
|
|
|
|
|
|
|
use Todaymade\Daux\Format\Base\EmbedImages;
|
|
|
|
use Todaymade\Daux\Tree\Raw;
|
|
|
|
|
|
|
|
class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
|
|
|
{
|
|
|
|
public $attachments = [];
|
|
|
|
|
|
|
|
protected function generatePage()
|
|
|
|
{
|
|
|
|
$content = parent::generatePage();
|
|
|
|
|
2019-11-30 22:24:10 +01:00
|
|
|
// Embed images
|
2015-11-06 22:44:34 +01:00
|
|
|
// We do it after generation so we can catch the images that were in html already
|
|
|
|
$content = (new EmbedImages($this->params['tree']))
|
|
|
|
->embed(
|
|
|
|
$content,
|
|
|
|
$this->file,
|
2018-05-05 18:16:24 +02:00
|
|
|
function($src, array $attributes, Raw $file) {
|
2019-11-30 22:24:10 +01:00
|
|
|
// TODO :: ignore absolute paths
|
|
|
|
$content = base64_encode(file_get_contents($file->getPath()));
|
2015-11-06 22:44:34 +01:00
|
|
|
$attr = '';
|
|
|
|
foreach ($attributes as $name => $value) {
|
2016-07-27 21:32:51 +02:00
|
|
|
$attr .= ' ' . $name . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8', false) . '"';
|
2015-11-06 22:44:34 +01:00
|
|
|
}
|
|
|
|
|
2019-11-30 22:24:10 +01:00
|
|
|
// TODO :: handle other formats than PNG as well
|
2015-11-06 22:44:34 +01:00
|
|
|
return "<img $attr src=\"data:image/png;base64,$content\"/>";
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
}
|