mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-01-11 17:08:40 +00:00
bump
This commit is contained in:
parent
374e22ca15
commit
38565605f7
|
|
@ -29,4 +29,14 @@ return [
|
|||
],
|
||||
],
|
||||
],
|
||||
'^:tag (\?.*$|$)' => [
|
||||
[
|
||||
'dest' => '\Modules\Media\Controller\SearchController:searchTag',
|
||||
'verb' => RouteVerb::ANY,
|
||||
'permission' => [
|
||||
'module' => SearchController::NAME,
|
||||
'type' => PermissionType::READ,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ use Modules\Media\Models\PathSettings;
|
|||
use Modules\Media\Models\PermissionCategory;
|
||||
use Modules\Media\Models\Reference;
|
||||
use Modules\Media\Models\ReferenceMapper;
|
||||
use Modules\Media\Models\Report;
|
||||
use Modules\Media\Models\UploadFile;
|
||||
use Modules\Media\Models\UploadStatus;
|
||||
use Modules\Media\Theme\Backend\Components\Media\ElementView;
|
||||
use Modules\Messages\Models\EmailMapper;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use phpOMS\Ai\Ocr\Tesseract\TesseractOcr;
|
||||
use phpOMS\Application\ApplicationAbstract;
|
||||
|
|
@ -67,6 +67,63 @@ use phpOMS\Views\View;
|
|||
*/
|
||||
final class ApiController extends Controller
|
||||
{
|
||||
/**
|
||||
* Api method to create tag
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param array $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiMediaEmailSend(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
|
||||
{
|
||||
$email = $request->getDataString('email');
|
||||
|
||||
$media = $data['media'] ?? MediaMapper::get()
|
||||
->where('id', (int) $request->getData('id'))
|
||||
->execute();
|
||||
|
||||
/** @var \Model\Setting $template */
|
||||
$template = $this->app->appSettings->get(
|
||||
names: (string) $request->getDataString('template')
|
||||
);
|
||||
|
||||
$handler = $this->app->moduleManager->get('Admin', 'Api')->setUpServerMailHandler();
|
||||
|
||||
$mail = EmailMapper::get()
|
||||
->with('l11n')
|
||||
->where('id', $template)
|
||||
->where('l11n/language', $response->header->l11n->language)
|
||||
->execute();
|
||||
|
||||
$status = false;
|
||||
if ($mail->id !== 0) {
|
||||
$status = $this->app->moduleManager->get('Admin', 'Api')->setupEmailDefaults($mail, $response->header->l11n->language);
|
||||
}
|
||||
|
||||
$mail->addTo($email);
|
||||
$mail->addAttachment($media->getAbsolutePath(), $media->name);
|
||||
|
||||
if ($status) {
|
||||
$status = $handler->send($mail);
|
||||
}
|
||||
|
||||
if (!$status) {
|
||||
\phpOMS\Log\FileLogger::getInstance()->error(
|
||||
\phpOMS\Log\FileLogger::MSG_FULL, [
|
||||
'message' => 'Couldn\'t send bill media: ' . $media->id,
|
||||
'line' => __LINE__,
|
||||
'file' => self::class,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to upload media file.
|
||||
*
|
||||
|
|
@ -920,34 +977,42 @@ final class ApiController extends Controller
|
|||
$status = \is_dir($physicalPath) ? true : \mkdir($physicalPath, 0755, true);
|
||||
}
|
||||
|
||||
$path = \trim($path, '/');
|
||||
$paths = \explode('/', $path);
|
||||
$tempPaths = $paths;
|
||||
$length = \count($paths);
|
||||
$virtualPath = \trim($path, '/');
|
||||
$virtualPaths = \explode('/', $virtualPath);
|
||||
$tempVirtualPaths = $virtualPaths;
|
||||
$length = \count($virtualPaths);
|
||||
|
||||
/** @var Collection $parentCollection */
|
||||
$parentCollection = null;
|
||||
|
||||
$temp = '';
|
||||
$virtual = '';
|
||||
$real = '';
|
||||
$newVirtual = '';
|
||||
|
||||
for ($i = $length; $i > 0; --$i) {
|
||||
$temp = '/' . \implode('/', $tempPaths);
|
||||
$virtual = '/' . \implode('/', $tempVirtualPaths);
|
||||
|
||||
/** @var Collection $parentCollection */
|
||||
$parentCollection = CollectionMapper::getParentCollection($temp)->execute();
|
||||
$parentCollection = CollectionMapper::getParentCollection($virtual)->execute();
|
||||
|
||||
if ($parentCollection->id > 0) {
|
||||
$real = $parentCollection->getPath();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
\array_pop($tempPaths);
|
||||
$newVirtual = \array_pop($tempVirtualPaths) . '/' . $newVirtual;
|
||||
}
|
||||
|
||||
for (; $i < $length; ++$i) {
|
||||
/* Create collection */
|
||||
$childCollection = new Collection();
|
||||
$childCollection->name = $paths[$i];
|
||||
$childCollection->name = $virtualPaths[$i];
|
||||
$childCollection->createdBy = new NullAccount($account);
|
||||
$childCollection->setVirtualPath('/'. \ltrim($temp, '/'));
|
||||
$childCollection->setPath('/Modules/Media/Files' . $temp);
|
||||
$childCollection->setVirtualPath('/'. \ltrim($virtual, '/'));
|
||||
|
||||
// We assume that the new path is real path of the first found parent directory + the new virtual path
|
||||
$childCollection->setPath($real . '/' . \ltrim($newVirtual, '/'));
|
||||
|
||||
$this->createModel($account, $childCollection, CollectionMapper::class, 'collection', '127.0.0.1');
|
||||
$this->createModelRelation(
|
||||
|
|
@ -961,7 +1026,7 @@ final class ApiController extends Controller
|
|||
);
|
||||
|
||||
$parentCollection = $childCollection;
|
||||
$temp .= '/' . $paths[$i];
|
||||
$virtual .= '/' . $virtualPaths[$i];
|
||||
}
|
||||
|
||||
return $parentCollection;
|
||||
|
|
@ -1077,6 +1142,13 @@ final class ApiController extends Controller
|
|||
$media->isAbsolute = false;
|
||||
$media->setVirtualPath(\dirname($path));
|
||||
$media->setPath('/' . \ltrim($path, '\\/'));
|
||||
} else {
|
||||
$media = MediaMapper::getAll()
|
||||
->where('virtualPath', $path)
|
||||
->limit(1)
|
||||
->execute();
|
||||
|
||||
$filePath = $media->getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1210,7 +1282,7 @@ final class ApiController extends Controller
|
|||
$response->endAllOutputBuffering(); // for large files
|
||||
}
|
||||
|
||||
if (($type = $request->getDataString('type')) === null) {
|
||||
if (\in_array($type = $request->getDataString('type'), [null, 'download', 'raw', 'bin'])) {
|
||||
$view->setTemplate('/Modules/Media/Theme/Api/render');
|
||||
} elseif ($type === 'html') {
|
||||
$head = new Head();
|
||||
|
|
|
|||
|
|
@ -30,6 +30,59 @@ use phpOMS\System\MimeType;
|
|||
*/
|
||||
final class SearchController extends Controller
|
||||
{
|
||||
/**
|
||||
* Api method to search for tags
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param array $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function searchTag(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
|
||||
{
|
||||
$search = $request->getDataString('search') ?? '';
|
||||
|
||||
$searchIdStartPos = \stripos($search, ':');
|
||||
$patternStartPos = $searchIdStartPos === false
|
||||
? -1
|
||||
: \stripos($search, ' ', $searchIdStartPos);
|
||||
|
||||
$pattern = \substr($search, $patternStartPos + 1);
|
||||
|
||||
/** @var \Modules\Media\Models\Media[] $media */
|
||||
$media = MediaMapper::getAll()
|
||||
->with('tags')
|
||||
->with('tags/title')
|
||||
->where('tags/title/language', $response->header->l11n->language)
|
||||
->where('tags/title/content', $pattern)
|
||||
->sort('createdAt', OrderType::DESC)
|
||||
->limit(8)
|
||||
->execute();
|
||||
|
||||
$results = [];
|
||||
foreach ($media as $file) {
|
||||
$results[] = [
|
||||
'title' => $file->name . ' (' . $file->extension . ')',
|
||||
'summary' => '',
|
||||
'link' => '{/base}/media/view?id=' . $file->id,
|
||||
'account' => '',
|
||||
'createdAt' => $file->createdAt,
|
||||
'image' => '',
|
||||
'tags' => $file->tags,
|
||||
'type' => 'list_links',
|
||||
'module' => 'Media',
|
||||
];
|
||||
}
|
||||
|
||||
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
|
||||
$response->add($request->uri->__toString(), $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to search for tags
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,6 +17,23 @@ use Modules\Media\Models\NullMedia;
|
|||
/** @var \Modules\Media\Models\Media $media */
|
||||
$media = $this->media ?? new NullMedia();
|
||||
|
||||
$fp = \fopen(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath(), 'r');
|
||||
\fpassthru($fp);
|
||||
\fclose($fp);
|
||||
if (\is_file($media->getAbsolutePath())) {
|
||||
$fp = \fopen($media->getAbsolutePath(), 'r');
|
||||
if ($fp !== false) {
|
||||
\fpassthru($fp);
|
||||
\fclose($fp);
|
||||
}
|
||||
} elseif (\is_dir($media->getAbsolutePath())) {
|
||||
\phpOMS\Utils\IO\Zip\Zip::pack(
|
||||
$media->getAbsolutePath(),
|
||||
$tmp = \tempnam(\sys_get_temp_dir(), 'oms_tmp_')
|
||||
);
|
||||
|
||||
$fp = \fopen($tmp, 'r');
|
||||
if ($fp !== false) {
|
||||
\fpassthru($fp);
|
||||
\fclose($fp);
|
||||
|
||||
\unlink($tmp);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,21 +33,29 @@ use phpOMS\Uri\UriFactory;
|
|||
<div class="portlet">
|
||||
<div class="portlet-head"><?= $this->getHtml('CreateCollection'); ?></div>
|
||||
<div class="portlet-body">
|
||||
<table class="layout wf-100">
|
||||
<tr><td><label for="iVirtualPath"><?= $this->getHtml('VirtualPath'); ?></label>
|
||||
<tr><td><input type="text" id="iVirtualPath" name="virtualPath" value="<?= empty($this->request->uri->getQuery('path')) ? '/' : $this->request->uri->getQuery('path'); ?>" disabled>
|
||||
<tr><td><label for="iPath"><?= $this->getHtml('Path'); ?></label>
|
||||
<tr><td><input type="text" id="iPath" name="path" value="<?= empty($this->request->uri->getQuery('path')) ? '/' : $this->request->uri->getQuery('path'); ?>">
|
||||
<tr><td><label><?= $this->getHtml('Settings'); ?></label>
|
||||
<tr><td>
|
||||
<div class="form-group">
|
||||
<label for="iVirtualPath"><?= $this->getHtml('VirtualPath'); ?></label>
|
||||
<input type="text" id="iVirtualPath" name="virtualPath" value="<?= empty($this->request->uri->getQuery('path')) ? '/' : $this->request->uri->getQuery('path'); ?>" disabled>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="iPath"><?= $this->getHtml('Path'); ?></label>
|
||||
<input type="text" id="iPath" name="path" value="<?= empty($this->request->uri->getQuery('path')) ? '/' : $this->request->uri->getQuery('path'); ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label><?= $this->getHtml('Settings'); ?></label>
|
||||
<label class="checkbox" for="iAddCollection">
|
||||
<input type="checkbox" id="iAddCollection" name="addcollection" checked>
|
||||
<span class="checkmark"></span>
|
||||
<?= $this->getHtml('AddToCollection'); ?>
|
||||
</label>
|
||||
<tr><td><label for="iName"><?= $this->getHtml('Name'); ?></label>
|
||||
<tr><td><input type="text" id="iName" name="name" multiple>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="iName"><?= $this->getHtml('Name'); ?></label>
|
||||
<input type="text" id="iName" name="name" multiple>
|
||||
</div>
|
||||
</div>
|
||||
<div class="portlet-foot">
|
||||
<input type="submit" id="iMediaCreate" name="mediaCreateButton" value="<?= $this->getHtml('Create', '0', '0'); ?>">
|
||||
|
|
|
|||
|
|
@ -40,9 +40,11 @@ $next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id='
|
|||
<a tabindex="0" class="button" href="<?= UriFactory::build('{/base}/media/upload?path={?path}'); ?>">
|
||||
<?= $this->getHtml('Upload'); ?>
|
||||
</a>
|
||||
<!--
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build('{/base}/media/file/create?path={?path}'); ?>">
|
||||
<?= $this->getHtml('CreateFile'); ?>
|
||||
</a>
|
||||
-->
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build('{/base}/media/collection/create?path={?path}'); ?>">
|
||||
<?= $this->getHtml('CreateCollection'); ?>
|
||||
</a>
|
||||
|
|
@ -210,7 +212,7 @@ $next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id='
|
|||
<?php foreach ($value->tags as $tag) : ?>
|
||||
<a href="<?= $url; ?>">
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>">
|
||||
<?= empty($tag->icon) ? '' : ''; ?>
|
||||
<?= empty($tag->icon) ? '' : '<i class="g-icon">' . $this->printHtml($tag->icon) . '</i>'; ?>
|
||||
<?= $this->printHtml($tag->getL11n()); ?>
|
||||
</span>
|
||||
</a>
|
||||
|
|
@ -238,7 +240,7 @@ $next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id='
|
|||
<div class="portlet-foot">
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build($previous); ?>"><?= $this->getHtml('Previous', '0', '0'); ?></a>
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build($next); ?>"><?= $this->getHtml('Next', '0', '0'); ?></a>
|
||||
<a tabindex="0" class="button rf" href="<?= UriFactory::build('api/media/download'); ?>">
|
||||
<a tabindex="0" class="button rf" href="<?= UriFactory::build('{/api}media/export?path={?path}&type=download'); ?>">
|
||||
<?= $this->getHtml('Download'); ?>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -33,21 +33,29 @@ use phpOMS\Uri\UriFactory;
|
|||
<div class="portlet">
|
||||
<div class="portlet-head"><?= $this->getHtml('Upload'); ?></div>
|
||||
<div class="portlet-body">
|
||||
<table class="layout wf-100">
|
||||
<tr><td><label for="iVirtualPath"><?= $this->getHtml('VirtualPath'); ?></label>
|
||||
<tr><td><input type="text" id="iVirtualPath" name="virtualPath" value="<?= empty($this->request->uri->getQuery('path')) ? '/' : $this->request->uri->getQuery('path'); ?>" disabled>
|
||||
<tr><td><label for="iPath"><?= $this->getHtml('Path'); ?></label>
|
||||
<tr><td><input type="text" id="iPath" name="path" value="<?= empty($this->request->uri->getQuery('path')) ? '/' : $this->request->uri->getQuery('path'); ?>">
|
||||
<tr><td><label><?= $this->getHtml('Settings'); ?></label>
|
||||
<tr><td>
|
||||
<div class="form-group">
|
||||
<label for="iVirtualPath"><?= $this->getHtml('VirtualPath'); ?></label>
|
||||
<input type="text" id="iVirtualPath" name="virtualPath" value="<?= empty($this->request->uri->getQuery('path')) ? '/' : $this->request->uri->getQuery('path'); ?>" disabled>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="iPath"><?= $this->getHtml('Path'); ?></label>
|
||||
<input type="text" id="iPath" name="path" value="<?= empty($this->request->uri->getQuery('path')) ? '/' : $this->request->uri->getQuery('path'); ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label><?= $this->getHtml('Settings'); ?></label>
|
||||
<label class="checkbox" for="iAddCollection">
|
||||
<input type="checkbox" id="iAddCollection" name="addcollection" checked>
|
||||
<span class="checkmark"></span>
|
||||
<?= $this->getHtml('AddToCollection'); ?>
|
||||
</label>
|
||||
<tr><td><label for="iFiles"><?= $this->getHtml('Files'); ?></label>
|
||||
<tr><td><input type="file" id="iFiles" name="files" multiple>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="iFiles"><?= $this->getHtml('Files'); ?></label>
|
||||
<input type="file" id="iFiles" name="files" multiple>
|
||||
</div>
|
||||
</div>
|
||||
<div class="portlet-foot">
|
||||
<input type="submit" id="iMediaCreate" name="mediaCreateButton" value="<?= $this->getHtml('Create', '0', '0'); ?>">
|
||||
|
|
|
|||
|
|
@ -37,9 +37,15 @@ echo $this->data['nav']->render();
|
|||
<div class="col-xs-12">
|
||||
<div class="box">
|
||||
<?php if ($this->request->getData('path') !== null) : ?>
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build('{/base}/media/list?path=' . ($media->id === 0 ? $media->getVirtualPath() : '{?path}')); ?>"><?= $this->getHtml('Back'); ?></a>
|
||||
<a tabindex="0" class="button"
|
||||
href="<?= UriFactory::build('{/base}/media/list?path=' . ($media->id === 0 ? $media->getVirtualPath() : '{?path}')); ?>">
|
||||
<?= $this->getHtml('Back'); ?>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<a tabindex="0" class="button" href="<?= $this->request->getReferer() !== '' ? $this->request->getReferer() : UriFactory::build('{/base}/media/list'); ?>"><?= $this->getHtml('Back'); ?></a>
|
||||
<a tabindex="0" class="button"
|
||||
href="<?= $this->request->getReferer() !== '' ? $this->request->getReferer() : UriFactory::build('{/base}/media/list'); ?>">
|
||||
<?= $this->getHtml('Back'); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -94,15 +100,15 @@ echo $this->data['nav']->render();
|
|||
); ?></a>
|
||||
<tr><td><?= $this->getHtml('Tags'); ?><td>
|
||||
<?php foreach ($media->tags as $tag) : ?>
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= empty($tag->icon) ? '' : ''; ?><?= $this->printHtml($tag->getL11n()); ?></span>
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>">
|
||||
<?= empty($tag->icon) ? '' : '<i class="g-icon">' . $this->printHtml($tag->icon) . '</i>'; ?>
|
||||
<?= $this->printHtml($tag->getL11n()); ?>
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
<tr><td colspan="2"><?= $this->getHtml('Description'); ?>
|
||||
<tr><td colspan="2"><?= $media->description; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
|
||||
if ($this->isTextFile($media, $path)) : ?>
|
||||
<div id="iMediaFileUpdate" class="portlet-foot"
|
||||
data-update-content="#mediaFile .portlet-body"
|
||||
data-update-element="#mediaFile .textContent"
|
||||
|
|
@ -110,17 +116,25 @@ echo $this->data['nav']->render();
|
|||
data-tag="form"
|
||||
data-method="POST"
|
||||
data-uri="<?= UriFactory::build('{/api}media?{?}&csrf={$CSRF}'); ?>">
|
||||
<a tabindex="0"
|
||||
class="button"
|
||||
href="<?= UriFactory::build('{/api}media/export?id=' . $media->id . '&type=download'); ?>"
|
||||
><?= $this->getHtml('Download'); ?></a>
|
||||
<?php
|
||||
$path = $this->filePathFunction($media, $this->request->getData('sub') ?? '');
|
||||
if ($this->isTextFile($media, $path)) :
|
||||
?>
|
||||
<button class="save vh"><?= $this->getHtml('Save', '0', '0'); ?></button>
|
||||
<button class="cancel vh"><?= $this->getHtml('Cancel', '0', '0'); ?></button>
|
||||
<button class="update"><?= $this->getHtml('Edit', '0', '0'); ?></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$media = $media->class === MediaClass::REFERENCE ? $media->source : $media;
|
||||
$media = $media->class === MediaClass::REFERENCE ? $media->source : $media;
|
||||
?>
|
||||
|
||||
<div class="row col-simple">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user