mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-16 01:08:41 +00:00
api rendering
This commit is contained in:
parent
6de9a0c13f
commit
3a4bc10459
|
|
@ -37,6 +37,17 @@ return [
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'^.*/media/export(\?+.*|$)' => [
|
||||||
|
[
|
||||||
|
'dest' => '\Modules\Media\Controller\ApiController:apiMediaExport',
|
||||||
|
'verb' => RouteVerb::GET,
|
||||||
|
'permission' => [
|
||||||
|
'module' => ApiController::MODULE_NAME,
|
||||||
|
'type' => PermissionType::READ,
|
||||||
|
'state' => PermissionState::MEDIA,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
'^.*/media/collection(\?+.*|$)' => [
|
'^.*/media/collection(\?+.*|$)' => [
|
||||||
[
|
[
|
||||||
'dest' => '\Modules\Media\Controller\ApiController:apiCollectionCreate',
|
'dest' => '\Modules\Media\Controller\ApiController:apiCollectionCreate',
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,10 @@ use phpOMS\Model\Message\FormValidation;
|
||||||
use phpOMS\System\File\FileUtils;
|
use phpOMS\System\File\FileUtils;
|
||||||
use phpOMS\System\File\Local\Directory;
|
use phpOMS\System\File\Local\Directory;
|
||||||
use phpOMS\Utils\Parser\Markdown\Markdown;
|
use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||||
|
use phpOMS\Views\View;
|
||||||
|
use phpOMS\System\MimeType;
|
||||||
|
use phpOMS\Model\Html\Head;
|
||||||
|
use phpOMS\Asset\AssetType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Media class.
|
* Media class.
|
||||||
|
|
@ -538,6 +542,52 @@ final class ApiController extends Controller
|
||||||
$response->set('export', $view);
|
$response->set('export', $view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Routing end-point for application behaviour.
|
||||||
|
*
|
||||||
|
* @param Media $media Media
|
||||||
|
* @param HttpRequest $request Request
|
||||||
|
* @param HttpResponse $response Response
|
||||||
|
*
|
||||||
|
* @return View
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function createView(Media $media, RequestAbstract $request, ResponseAbstract $response) : View
|
||||||
|
{
|
||||||
|
$view = new View($this->app->l11nManager, $request, $response);
|
||||||
|
$view->setData('media', $media);
|
||||||
|
|
||||||
|
if (($type = $request->getData('type')) === null) {
|
||||||
|
$view->setTemplate('/Modules/Media/Theme/Api/render');
|
||||||
|
} elseif ($type === 'html') {
|
||||||
|
$head = new Head();
|
||||||
|
$css = \file_get_contents(__DIR__ . '/../../../Web/Backend/css/backend-small.css');
|
||||||
|
if ($css === false) {
|
||||||
|
$css = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$css = \preg_replace('!\s+!', ' ', $css);
|
||||||
|
$head->setStyle('core', $css ?? '');
|
||||||
|
|
||||||
|
$head->addAsset(AssetType::CSS, 'cssOMS/styles.css');
|
||||||
|
$view->setData('head', $head);
|
||||||
|
|
||||||
|
switch (\strtolower($media->extension)) {
|
||||||
|
case 'xls':
|
||||||
|
case 'xlsx':
|
||||||
|
$view->setTemplate('/Modules/Media/Theme/Api/spreadsheetAsHtml');
|
||||||
|
break;
|
||||||
|
case 'doc':
|
||||||
|
case 'docx':
|
||||||
|
$view->setTemplate('/Modules/Media/Theme/Api/wordAsHtml');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $view;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set header for report/template
|
* Set header for report/template
|
||||||
*
|
*
|
||||||
|
|
@ -548,13 +598,15 @@ final class ApiController extends Controller
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function setMediaResponseHeader(View $view, Media $media, RequestAbstract $request, ResponseAbstract $response) : void
|
private function setMediaResponseHeader(View $view, Media $media, RequestAbstract $request, ResponseAbstract $response) : void
|
||||||
{
|
{
|
||||||
switch (\strtolower($media->extension)) {
|
switch ($request->getData('type') ?? \strtolower($media->extension)) {
|
||||||
|
case 'htm':
|
||||||
|
case 'html':
|
||||||
|
$response->header->set('Content-Type', MimeType::M_HTML, true);
|
||||||
|
break;
|
||||||
case 'pdf':
|
case 'pdf':
|
||||||
$response->header->set('Content-Type', MimeType::M_PDF, true);
|
$response->header->set('Content-Type', MimeType::M_PDF, true);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,9 @@
|
||||||
|
|
||||||
// @todo: is this chunked/streamed output or bulk output
|
// @todo: is this chunked/streamed output or bulk output
|
||||||
// if it is streamed it is not working because of ob_* in the actual response rendering
|
// if it is streamed it is not working because of ob_* in the actual response rendering
|
||||||
|
|
||||||
|
$media = $this->getData('media');
|
||||||
|
|
||||||
|
$fp = \fopen(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath(), 'r');
|
||||||
\fpassthru($fp);
|
\fpassthru($fp);
|
||||||
|
\fclose($fp);
|
||||||
|
|
|
||||||
22
Theme/Api/spreadsheetAsCsv.tpl.php
Normal file
22
Theme/Api/spreadsheetAsCsv.tpl.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use phpOMS\Autoloader;
|
||||||
|
Autoloader::addPath(__DIR__ . '/../../../../Resources/');
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Csv;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
$media = $this->getData('media');
|
||||||
|
|
||||||
|
$reader = IOFactory::createReaderforFile(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath());
|
||||||
|
$reader->setReadDataOnly(true);
|
||||||
|
$spreadsheet = $reader->load(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath());
|
||||||
|
|
||||||
|
$writer = new Csv($spreadsheet);
|
||||||
|
$writer->setDelimiter(';');
|
||||||
|
$writer->setEnclosure('"');
|
||||||
|
$writer->setLineEnding("\n");
|
||||||
|
$writer->setUseBOM(true);
|
||||||
|
|
||||||
|
$writer->save('php://output');
|
||||||
21
Theme/Api/spreadsheetAsHtml.tpl.php
Normal file
21
Theme/Api/spreadsheetAsHtml.tpl.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use phpOMS\Autoloader;
|
||||||
|
Autoloader::addPath(__DIR__ . '/../../../../Resources/');
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Html;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
$media = $this->getData('media');
|
||||||
|
|
||||||
|
$reader = IOFactory::createReaderforFile(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath());
|
||||||
|
$reader->setReadDataOnly(true);
|
||||||
|
$spreadsheet = $reader->load(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath());
|
||||||
|
|
||||||
|
$writer = new Html($spreadsheet);
|
||||||
|
$writer->writeAllSheets();
|
||||||
|
|
||||||
|
$writer->save('php://output');
|
||||||
|
|
||||||
|
echo '<style>body { margin: 0; } table { width: 100%; }</style>';
|
||||||
17
Theme/Api/wordAsHtml.tpl.php
Normal file
17
Theme/Api/wordAsHtml.tpl.php
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use phpOMS\Autoloader;
|
||||||
|
Autoloader::addPath(__DIR__ . '/../../../../Resources/');
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\IOFactory;
|
||||||
|
use PhpOffice\PhpWord\Writer\HTML;
|
||||||
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
|
|
||||||
|
$media = $this->getData('media');
|
||||||
|
|
||||||
|
$reader = IOFactory::createReader('Word2007');
|
||||||
|
$doc = $reader->load(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath());
|
||||||
|
|
||||||
|
$writer = new HTML($doc);
|
||||||
|
|
||||||
|
$writer->save('php://output');
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use phpOMS\Uri\UriFactory;
|
||||||
|
?>
|
||||||
<section id="mediaFile" class="portlet">
|
<section id="mediaFile" class="portlet">
|
||||||
<div class="portlet-body">
|
<div class="portlet-body">
|
||||||
<audio width="100%" controls>
|
<audio width="100%" controls>
|
||||||
<source src="<?= $this->media->getPath(); ?>" type="audio/<?= $this->media->extension; ?>">
|
<source src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>" type="audio/<?= $this->media->extension; ?>">
|
||||||
Your browser does not support HTML audio.
|
Your browser does not support HTML audio.
|
||||||
</audio>
|
</audio>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use phpOMS\Uri\UriFactory;
|
||||||
|
?>
|
||||||
<section id="mediaFile" class="portlet">
|
<section id="mediaFile" class="portlet">
|
||||||
<div class="portlet-body">
|
<div class="portlet-body">
|
||||||
<div class="h-overflow centerText">
|
<div class="h-overflow centerText">
|
||||||
<img style="max-width: 100%" src="<?= $this->media->getPath(); ?>" alt="<?= $this->printHtml($this->media->name); ?>">
|
<img style="max-width: 100%" src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>" alt="<?= $this->printHtml($this->media->name); ?>">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$array = \json_decode($this->getFileContent(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath()), true);
|
||||||
|
?>
|
||||||
|
<section id="mediaFile" class="portlet">
|
||||||
|
<div class="portlet-body">
|
||||||
|
<div id="media" class="tabview tab-2 m-editor">
|
||||||
|
<ul class="tab-links">
|
||||||
|
<li><label tabindex="0" for="media-c-tab-1"><?= $this->getHtml('Preview', 'Media'); ?></label>
|
||||||
|
<li><label tabindex="0" for="media-c-tab-2"><?= $this->getHtml('Edit', 'Media'); ?></label>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content">
|
||||||
|
<input type="radio" id="media-c-tab-1" name="tabular-1" checked>
|
||||||
|
<div class="tab">
|
||||||
|
<pre><?= \json_encode($array, \JSON_PRETTY_PRINT); ?></pre>
|
||||||
|
</div>
|
||||||
|
<input type="radio" id="media-c-tab-2" name="tabular-1">
|
||||||
|
<div class="tab">
|
||||||
|
<pre class="textContent" data-tpl-text="/media/content" data-tpl-value="/media/content"><?= $this->printHtml(
|
||||||
|
$this->getFileContent(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath())
|
||||||
|
); ?></pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use phpOMS\Autoloader;
|
||||||
|
Autoloader::addPath(__DIR__ . '/../../../../../../Resources/');
|
||||||
|
|
||||||
|
use PhpOffice\PhpPresentation\IOFactory;
|
||||||
|
use PhpOffice\PhpPresentation\Writer\Html;
|
||||||
|
use PhpOffice\PhpPresentation\Spreadsheet;
|
||||||
|
|
||||||
|
$reader = IOFactory::createReader('PowerPoint2007');
|
||||||
|
$presentation = $reader->load(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath());
|
||||||
|
|
||||||
|
$writer = new Html($presentation);
|
||||||
|
?>
|
||||||
|
<section id="mediaFile" class="portlet">
|
||||||
|
<div class="portlet-body">
|
||||||
|
<?php $writer->save('php://output'); ?>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
@ -1,18 +1,65 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use phpOMS\Autoloader;
|
||||||
|
Autoloader::addPath(__DIR__ . '/../../../../../../Resources/');
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
use PhpOffice\PhpSpreadsheet\Writer\Html;
|
use PhpOffice\PhpSpreadsheet\Writer\Csv;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
$reader = IOFactory::createReaderforFile(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath());
|
use phpOMS\Uri\UriFactory;
|
||||||
$reader->setReadDataOnly(true);
|
use phpOMS\Utils\IO\Csv\CsvSettings;
|
||||||
$spreadsheet = $reader->load(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath());
|
|
||||||
|
|
||||||
$writer = new Html($spreadsheet);
|
|
||||||
$writer->writeAllSheets();
|
|
||||||
?>
|
?>
|
||||||
<section id="mediaFile" class="portlet">
|
<section id="mediaFile" class="portlet">
|
||||||
<div class="portlet-body">
|
<div class="portlet-body">
|
||||||
<?php $writer->save('php://output'); ?>
|
<div id="media" class="tabview tab-2 m-editor">
|
||||||
|
<ul class="tab-links">
|
||||||
|
<li><label tabindex="0" for="media-c-tab-1"><?= $this->getHtml('Preview', 'Media'); ?></label>
|
||||||
|
<li><label tabindex="0" for="media-c-tab-2">CSV</label>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content">
|
||||||
|
<input type="radio" id="media-c-tab-1" name="tabular-1" checked>
|
||||||
|
<div class="tab">
|
||||||
|
<iframe src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>&type=html"></iframe>
|
||||||
|
</div>
|
||||||
|
<input type="radio" id="media-c-tab-2" name="tabular-1" checked>
|
||||||
|
<div class="tab">
|
||||||
|
<?php
|
||||||
|
$reader = IOFactory::createReaderforFile(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath());
|
||||||
|
$reader->setReadDataOnly(true);
|
||||||
|
$spreadsheet = $reader->load(($this->media->isAbsolute ? '' : __DIR__ . '/../../../../../../') . $this->media->getPath());
|
||||||
|
|
||||||
|
$writer = new Csv($spreadsheet);
|
||||||
|
$writer->setDelimiter(';');
|
||||||
|
$writer->setEnclosure('"');
|
||||||
|
$writer->setLineEnding("\n");
|
||||||
|
$writer->setUseBOM(true);
|
||||||
|
|
||||||
|
\ob_start();
|
||||||
|
$writer->save('php://output');
|
||||||
|
$data = \ob_get_clean();
|
||||||
|
$csv = \explode("\n", \trim($data, "\n"));
|
||||||
|
?>
|
||||||
|
<table class="default">
|
||||||
|
<?php
|
||||||
|
foreach ($csv as $line) {
|
||||||
|
$lineCsv = \str_getcsv($line, ';', '"');
|
||||||
|
if ($lineCsv === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<tr>';
|
||||||
|
foreach ($lineCsv as $cell) {
|
||||||
|
if ($cell === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<td>' . \htmlspecialchars($cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use phpOMS\Uri\UriFactory;
|
||||||
|
?>
|
||||||
<section id="mediaFile" class="portlet">
|
<section id="mediaFile" class="portlet">
|
||||||
<div class="portlet-body">
|
<div class="portlet-body">
|
||||||
<video width="100%" controls>
|
<video width="100%" controls>
|
||||||
<source src="<?= $this->media->getPath(); ?>" type="video/<?= $this->media->extension; ?>">
|
<source src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>" type="video/<?= $this->media->extension; ?>">
|
||||||
Your browser does not support HTML video.
|
Your browser does not support HTML video.
|
||||||
</video>
|
</video>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use phpOMS\Uri\UriFactory;
|
||||||
|
?>
|
||||||
|
<section id="mediaFile" class="portlet">
|
||||||
|
<div class="portlet-body">
|
||||||
|
<iframe src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>&type=html"></iframe>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
Loading…
Reference in New Issue
Block a user