make id public, organigram impl. media password/encryption, settings bug fix, Money->FloatInt change, ...

This commit is contained in:
Dennis Eichhorn 2023-05-06 11:42:06 +00:00
parent 744b771463
commit ad687966ff
30 changed files with 220 additions and 214 deletions

View File

@ -122,9 +122,9 @@
"type": "TINYINT",
"null": false
},
"media_nonce": {
"name": "media_nonce",
"type": "VARCHAR(255)",
"media_encrypted": {
"name": "media_encrypted",
"type": "TINYINT(1)",
"null": true,
"default": null
},

View File

@ -57,6 +57,10 @@ final class Installer extends InstallerAbstract
\mkdir(__DIR__ . '/../Files');
}
if (!\is_dir(__DIR__ . '/../../../Temp')) {
\mkdir(__DIR__ . '/../../../Temp');
}
parent::install($app, $info, $cfgHandler);
// Create directory for admin account
@ -69,9 +73,9 @@ final class Installer extends InstallerAbstract
foreach ($accounts as $account) {
$collection = new Collection();
$collection->name = ((string) $account->getId()) . ' ' . $account->login;
$collection->name = ((string) $account->id) . ' ' . $account->login;
$collection->setVirtualPath('/Accounts');
$collection->setPath('/Modules/Media/Files/Accounts/' . ((string) $account->getId()));
$collection->setPath('/Modules/Media/Files/Accounts/' . ((string) $account->id));
// The installation is always run by the admin account since the module is a "base" module which is always installed during the application setup
$collection->createdBy = new NullAccount(1);
@ -261,7 +265,7 @@ final class Installer extends InstallerAbstract
}
$type = $responseData['response'];
$id = $type->getId();
$id = $type->id;
$isFirst = true;
foreach ($data['l11n'] as $l11n) {

View File

@ -69,9 +69,9 @@ echo $this->getData('nav')->render(); ?>
<tbody>
<?php $count = 0;
foreach ($types as $key => $type) : ++$count;
$url = UriFactory::build('{/base}/admin/module/settings?id=Media&type=' . $type->getId()); ?>
$url = UriFactory::build('{/base}/admin/module/settings?id=Media&type=' . $type->id); ?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><?= $type->getId(); ?></a>
<td><a href="<?= $url; ?>"><?= $type->id; ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($type->name); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($type->getL11n()); ?></a>
<?php endforeach; ?>

View File

@ -90,7 +90,7 @@ final class ApiController extends Controller
basePath: __DIR__ . '/../../../Modules/Media/Files' . \urldecode($request->getDataString('path') ?? ''),
virtualPath: \urldecode($request->getDataString('virtualpath') ?? ''),
password: $request->getDataString('password') ?? '',
encryptionKey: $request->getDataString('encrypt') ?? '',
encryptionKey: $request->getDataString('encryption') ?? ($request->getDataBool('isencrypted') === true && !empty($_SERVER['OMS_PRIVATE_KEY_I'] ?? '') ? $_SERVER['OMS_PRIVATE_KEY_I'] : ''),
pathSettings: $request->getDataInt('pathsettings') ?? PathSettings::RANDOM_PATH, // IMPORTANT!!!
hasAccountRelation: $request->getDataBool('link_account') ?? false,
readContent: $request->getDataBool('parse_content') ?? false,
@ -99,7 +99,7 @@ final class ApiController extends Controller
$ids = [];
foreach ($uploads as $file) {
$ids[] = $file->getId();
$ids[] = $file->id;
// add media types
if (!empty($types = $request->getDataJson('types'))) {
@ -123,7 +123,7 @@ final class ApiController extends Controller
$this->createModelRelation(
$request->header->account,
$file->getId(),
$file->id,
$tId,
MediaMapper::class,
'types',
@ -156,7 +156,7 @@ final class ApiController extends Controller
$this->createModelRelation(
$request->header->account,
$file->getId(),
$file->id,
$tId,
MediaMapper::class,
'tags',
@ -321,7 +321,9 @@ final class ApiController extends Controller
$virtualPath,
app: $hasAccountRelation ? $this->app : null,
readContent: $readContent,
unit: $unit
unit: $unit,
password: $password,
isEncrypted: !empty($encryptionKey)
);
}
@ -390,7 +392,9 @@ final class ApiController extends Controller
string $ip = '127.0.0.1',
ApplicationAbstract $app = null,
bool $readContent = false,
int $unit = null
int $unit = null,
string $password = '',
bool $isEncrypted = false
) : Media
{
if (!isset($status['status']) || $status['status'] !== UploadStatus::OK) {
@ -406,6 +410,8 @@ final class ApiController extends Controller
$media->extension = $status['extension'];
$media->unit = $unit;
$media->setVirtualPath($virtualPath);
$media->setPassword($password);
$media->isEncrypted = $isEncrypted;
if ($readContent && \is_file($media->getAbsolutePath())) {
$content = self::loadFileContent($media->getAbsolutePath(), $media->extension);
@ -430,7 +436,7 @@ final class ApiController extends Controller
null, $media,
StringUtils::intHash(MediaMapper::class), 'Media-media-create',
self::NAME,
(string) $media->getId(),
(string) $media->id,
'',
$ip
]
@ -444,7 +450,7 @@ final class ApiController extends Controller
self::NAME,
self::NAME,
PermissionCategory::MEDIA,
$media->getId(),
$media->id,
null,
PermissionType::READ | PermissionType::MODIFY | PermissionType::DELETE | PermissionType::PERMISSION
),
@ -584,7 +590,7 @@ final class ApiController extends Controller
$media->setPath($request->getDataString('path') ?? $media->getPath());
$media->setVirtualPath(\urldecode($request->getDataString('virtualpath') ?? $media->getVirtualPath()));
if ($media instanceof NullMedia
if ($media->id === 0
|| !$this->app->accountManager->get($request->header->account)->hasPermission(
PermissionType::MODIFY,
$this->app->unitId,
@ -646,7 +652,7 @@ final class ApiController extends Controller
->where('name', \basename($request->getDataString('virtualpath') ?? ''))
->execute();
$parentCollectionId = $parentCollection->getId();
$parentCollectionId = $parentCollection->id;
}
if (!$request->hasData('source')) {
@ -656,13 +662,13 @@ final class ApiController extends Controller
->where('name', \basename($request->getDataString('child') ?? ''))
->execute();
$request->setData('source', $child->getId());
$request->setData('source', $child->id);
}
$this->createModelRelation(
$request->header->account,
$parentCollectionId,
$ref->getId(),
$ref->id,
CollectionMapper::class,
'sources',
'',
@ -912,7 +918,7 @@ final class ApiController extends Controller
/** @var Collection $parentCollection */
$parentCollection = CollectionMapper::getParentCollection($temp)->execute();
if ($parentCollection->getId() > 0) {
if ($parentCollection->id > 0) {
break;
}
@ -930,8 +936,8 @@ final class ApiController extends Controller
$this->createModel($account, $childCollection, CollectionMapper::class, 'collection', '127.0.0.1');
$this->createModelRelation(
$account,
$parentCollection->getId(),
$childCollection->getId(),
$parentCollection->id,
$childCollection->id,
CollectionMapper::class,
'sources',
'',
@ -1011,10 +1017,12 @@ final class ApiController extends Controller
$virtualPath,
$request->getOrigin(),
$this->app,
unit: $request->getDataInt('unit')
unit: $request->getDataInt('unit'),
password: $request->getDataString('password') ?? '',
isEncrypted: $request->getDataBool('isencrypted') ?? $request->hasData('encryption')
);
$ids[] = $created->getId();
$ids[] = $created->id;
}
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Media', 'Media successfully created.', $ids);
@ -1057,15 +1065,16 @@ final class ApiController extends Controller
}
}
if (!($media instanceof NullMedia)) {
if ($request->header->account !== $media->createdBy->getId()
if ($media->id > 0) {
if (!($data['ignorePermission'] ?? false)
&& $request->header->account !== $media->createdBy->id
&& !$this->app->accountManager->get($request->header->account)->hasPermission(
PermissionType::READ,
$this->app->unitId,
$this->app->appId,
self::NAME,
PermissionCategory::MEDIA,
$media->getId()
$media->id
)
) {
$this->fillJsonResponse($request, $response, NotificationLevel::HIDDEN, '', '', []);
@ -1095,7 +1104,7 @@ final class ApiController extends Controller
}
if ($media->hasPassword()
&& !$media->comparePassword((string) $request->getData('password'))
&& !$media->comparePassword($request->getDataString('password'))
) {
$view = new View($this->app->l11nManager, $request, $response);
$view->setTemplate('/Modules/Media/Theme/Api/invalidPassword');
@ -1103,6 +1112,17 @@ final class ApiController extends Controller
return;
}
if ($media->isEncrypted) {
$media = $this->prepareEncryptedMedia($media, $request);
if ($media->id === 0) {
$this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Media', 'Media could not be exported. Please try again.', []);
$response->header->status = RequestStatusCode::R_500;
return;
}
}
$this->setMediaResponseHeader($media, $request, $response);
$view = $this->createView($media, $request, $response);
$view->setData('path', __DIR__ . '/../../../');
@ -1110,6 +1130,38 @@ final class ApiController extends Controller
$response->set('export', $view);
}
private function prepareEncryptedMedia(Media $media, RequestAbstract $request) : Media
{
$path = '';
$absolutePath = '';
$counter = 0;
do {
$randomName = \sha1(\random_bytes(32));
$path = '../../../Temp/' . $randomName . '.' . $media->getExtension();
$absolutePath = __DIR__ . '/' . $path;
} while(!\is_file($absolutePath) && $counter < 1000);
if ($counter >= 1000) {
return new NullMedia();
}
$encryptionKey = $request->getDataBool('isencrypted') === true && !empty($_SESSION['OMS_PRIVATE_KEY_I'] ?? '')
? $_SESSION['OMS_PRIVATE_KEY_I']
: $request->getDataString('encrpkey') ?? '';
$decrypted = $media->decrypt($encryptionKey, $absolutePath);
if (!$decrypted) {
return new NullMedia();
}
$media->path = $media->isAbsolute ? $absolutePath : $path;
return $media;
}
/**
* Routing end-point for application behaviour.
*

View File

@ -124,7 +124,7 @@ final class BackendController extends Controller
$collection = $collectionMapper->execute();
if ((\is_array($collection) || $collection instanceof NullCollection) && \is_dir(__DIR__ . '/../Files' . $path)) {
if ((\is_array($collection) || $collection->id === 0) && \is_dir(__DIR__ . '/../Files' . $path)) {
$collection = new Collection();
$collection->name = \basename($path);
$collection->setVirtualPath(\dirname($path));
@ -132,11 +132,11 @@ final class BackendController extends Controller
$collection->isAbsolute = false;
}
if ($collection instanceof Collection && !($collection instanceof NullCollection)) {
if ($collection instanceof Collection && $collection->id > 0) {
$collectionSources = $collection->getSources();
foreach ($collectionSources as $source) {
foreach ($media as $obj) {
if ($obj->getId() === $source->getId()) {
if ($obj->id === $source->id) {
continue 2;
}
}
@ -214,6 +214,7 @@ final class BackendController extends Controller
if ($id === 0) {
$path = \urldecode($request->getDataString('path') ?? '');
$media = new NullMedia();
if (\is_file(__DIR__ . '/../Files' . $path)) {
$name = \explode('.', \basename($path));
@ -236,14 +237,6 @@ final class BackendController extends Controller
->where('tags/title/language', $request->getLanguage())
->execute();
if ($media->hasPassword()
&& !$media->comparePassword((string) $request->getData('password'))
) {
$view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/invalidPassword');
return $view;
}
if ($media->class === MediaClass::COLLECTION) {
/** @var \Modules\Media\Models\Media[] $files */
$files = MediaMapper::getByVirtualPath(
@ -272,7 +265,7 @@ final class BackendController extends Controller
->with('tags')
->with('tags/title')
->with('content')
->where('id', $media->source?->getId() ?? 0)
->where('id', $media->source?->id ?? 0)
->where('tags/title/language', $request->getLanguage())
->execute();
@ -311,6 +304,16 @@ final class BackendController extends Controller
return $view;
}
if ($media->isEncrypted) {
$media = $this->app->moduleManager->get('Media', 'Api')->prepareEncryptedMedia($media, $request);
if ($media->id === 0) {
$view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/invalidPassword');
return $view;
}
}
switch (\strtolower($media->extension)) {
case 'pdf':
$view->setTemplate('/Modules/Media/Theme/Backend/Components/Media/pdf');
@ -395,9 +398,7 @@ final class BackendController extends Controller
$id = $request->getDataString('id') ?? '';
$settings = SettingMapper::getAll()->where('module', $id)->execute();
if (!($settings instanceof NullSetting)) {
$view->setData('settings', !\is_array($settings) ? [$settings] : $settings);
}
$view->setData('settings', $settings);
$types = MediaTypeMapper::getAll()->with('title')->where('title/language', $response->getLanguage())->execute();
$view->setData('types', $types);
@ -434,7 +435,7 @@ final class BackendController extends Controller
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response));
$view->addData('type', $type);
$l11n = MediaTypeL11nMapper::getAll()->where('type', $type->getId())->execute();
$l11n = MediaTypeL11nMapper::getAll()->where('type', $type->id)->execute();
$view->addData('l11n', $l11n);
return $view;

View File

@ -18,6 +18,7 @@ use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
use Modules\Tag\Models\NullTag;
use Modules\Tag\Models\Tag;
use phpOMS\Security\EncryptionHelper;
/**
* Media class.
@ -35,7 +36,7 @@ class Media implements \JsonSerializable
* @var int
* @since 1.0.0
*/
protected int $id = 0;
public int $id = 0;
/**
* Name.
@ -99,7 +100,7 @@ class Media implements \JsonSerializable
* @var string
* @since 1.0.0
*/
protected string $path = '';
public string $path = '';
/**
* Virtual path.
@ -107,7 +108,7 @@ class Media implements \JsonSerializable
* @var string
* @since 1.0.0
*/
protected string $virtualPath = '/';
public string $virtualPath = '/';
/**
* Is path absolute?
@ -150,12 +151,12 @@ class Media implements \JsonSerializable
public ?Media $source = null;
/**
* Media encryption nonce.
* Is encrypted.
*
* @var null|string
* @var bool
* @since 1.0.0
*/
protected ?string $nonce = null;
public bool $isEncrypted = false;
/**
* Media password hash.
@ -163,7 +164,7 @@ class Media implements \JsonSerializable
* @var null|string
* @since 1.0.0
*/
protected ?string $password = null;
public ?string $password = null;
/**
* Media is hidden.
@ -195,7 +196,7 @@ class Media implements \JsonSerializable
* @var Tag[]
* @since 1.0.0
*/
protected array $tags = [];
public array $tags = [];
/**
* Language.
@ -203,7 +204,7 @@ class Media implements \JsonSerializable
* @var null|string
* @since 1.0.0
*/
protected ?string $language = null;
public ?string $language = null;
/**
* Country.
@ -211,7 +212,7 @@ class Media implements \JsonSerializable
* @var null|string
* @since 1.0.0
*/
protected ?string $country = null;
public ?string $country = null;
/**
* Constructor.
@ -237,57 +238,31 @@ class Media implements \JsonSerializable
/**
* Encrypt the media file
*
* @param string $password Password to encrypt the file with
* @param string $key Password to encrypt the file with
* @param null|string $outputPath Output path of the encryption (null = replace file)
*
* @return string
*
* @since 1.0.0
*/
public function encrypt(string $password, string $outputPath = null) : string
{
return '';
}
/**
* Decrypt the media file
*
* @param string $password Password to encrypt the file with
* @param null|string $outputPath Output path of the encryption (null = replace file)
*
* @return string
*
* @since 1.0.0
*/
public function decrypt(string $password, string $outputPath = null) : string
{
return '';
}
/**
* Set encryption nonce
*
* @param null|string $nonce Nonce from encryption password
*
* @return void
*
* @since 1.0.0
*/
public function setNonce(?string $nonce) : void
{
$this->nonce = $nonce;
}
/**
* Is media file encrypted?
*
* @return bool
*
* @since 1.0.0
*/
public function isEncrypted() : bool
public function encrypt(string $key, string $outputPath = null) : bool
{
return $this->nonce !== null;
return EncryptionHelper::encryptFile($this->getAbsolutePath(), $outputPath, $key);
}
/**
* Decrypt the media file
*
* @param string $key Password to encrypt the file with
* @param null|string $outputPath Output path of the encryption (null = replace file)
*
* @return bool
*
* @since 1.0.0
*/
public function decrypt(string $key, string $outputPath = null) : bool
{
return EncryptionHelper::decryptFile($this->getAbsolutePath(), $outputPath, $key);
}
/**
@ -332,20 +307,6 @@ class Media implements \JsonSerializable
return \password_verify($password, $this->password ?? '');
}
/**
* Compare nonce with encryption nonce of the media file
*
* @param string $nonce User nonce
*
* @return bool
*
* @since 1.0.0
*/
public function compareNonce(string $nonce) : bool
{
return $this->nonce === null ? false : \hash_equals($this->nonce, $nonce);
}
/**
* Get the media path
*
@ -358,6 +319,22 @@ class Media implements \JsonSerializable
return $this->isAbsolute ? $this->path : \ltrim($this->path, '\\/');
}
public function getFileName() : string
{
return \basename($this->path);
}
public function getExtension() : string
{
$pos = \strrpos('.', $this->path);
if ($pos === false) {
return '';
}
return \substr($this->path, $pos + 1);
}
/**
* Get the absolute media path
*

View File

@ -30,7 +30,7 @@ class MediaContent implements \JsonSerializable
* @var int
* @since 1.0.0
*/
protected int $id = 0;
public int $id = 0;
public string $content = '';

View File

@ -49,7 +49,7 @@ class MediaMapper extends DataMapperFactory
'media_file' => ['name' => 'media_file', 'type' => 'string', 'internal' => 'path', 'autocomplete' => true],
'media_virtual' => ['name' => 'media_virtual', 'type' => 'string', 'internal' => 'virtualPath', 'autocomplete' => true],
'media_absolute' => ['name' => 'media_absolute', 'type' => 'bool', 'internal' => 'isAbsolute'],
'media_nonce' => ['name' => 'media_nonce', 'type' => 'string', 'internal' => 'nonce'],
'media_encrypted' => ['name' => 'media_encrypted', 'type' => 'bool', 'internal' => 'isEncrypted'],
'media_password' => ['name' => 'media_password', 'type' => 'string', 'internal' => 'password'],
'media_extension' => ['name' => 'media_extension', 'type' => 'string', 'internal' => 'extension'],
'media_size' => ['name' => 'media_size', 'type' => 'int', 'internal' => 'size'],

View File

@ -33,7 +33,7 @@ class MediaType implements \JsonSerializable
* @var int
* @since 1.0.0
*/
protected int $id = 0;
public int $id = 0;
/**
* Name.

View File

@ -17,6 +17,7 @@ declare(strict_types=1);
namespace Modules\Media\Models;
use phpOMS\Log\FileLogger;
use phpOMS\Security\EncryptionHelper;
use phpOMS\System\File\Local\Directory;
use phpOMS\System\File\Local\File;
@ -202,29 +203,13 @@ class UploadFile
}
if ($encryptionKey !== '') {
$nonce = \sodium_randombytes_buf(24);
$isEncrypted = EncryptionHelper::encryptFile($dest, $dest, $encryptionKey);
$fpSource = \fopen($dest, 'r+');
$fpEncoded = \fopen($dest . '.tmp', 'w');
if ($fpSource === false || $fpEncoded === false) {
if (!$isEncrypted) {
$result[$key]['status'] = UploadStatus::NOT_ENCRYPTABLE;
return $result;
}
while (($buffer = \fgets($fpSource, 4096)) !== false) {
$encrypted = \sodium_crypto_secretbox($buffer, $nonce, $encryptionKey);
\fwrite($fpEncoded, $encrypted);
}
\fclose($fpSource);
\fclose($fpEncoded);
\unlink($dest);
\rename($dest . '.tmp', $dest);
$result[$key]['nonce'] = $nonce;
}
/*

View File

@ -68,7 +68,7 @@ class BaseView extends View
* @var bool
* @since 1.0.0
*/
private bool $isRequired = false;
public bool $isRequired = false;
/**
* {@inheritdoc}

View File

@ -1,10 +1,10 @@
<div class="ipt-wrap">
<div class="ipt-first">
<span class="input">
<button type="button" id="<?= $this->getId(); ?>-book-button" data-action='[
<button type="button" id="<?= $this->id; ?>-book-button" data-action='[
{
"key": 1, "listener": "click", "action": [
{"key": 1, "type": "dom.popup", "selector": "#acc-grp-tpl", "aniIn": "fadeIn", "id": "<?= $this->getId(); ?>"},
{"key": 1, "type": "dom.popup", "selector": "#acc-grp-tpl", "aniIn": "fadeIn", "id": "<?= $this->id; ?>"},
{"key": 2, "type": "message.request", "uri": "<?= \phpOMS\Uri\UriFactory::build('{/base}/admin/account?filter=some&limit=10'); ?>", "method": "GET", "request_type": "json"},
{"key": 3, "type": "dom.table.append", "id": "acc-table", "aniIn": "fadeIn", "data": [], "bindings": {"id": "id", "name": "name/0"}, "position": -1},
{"key": 4, "type": "message.request", "uri": "<?= \phpOMS\Uri\UriFactory::build('{/base}/admin/account?filter=some&limit=10'); ?>", "method": "GET", "request_type": "json"},
@ -12,12 +12,12 @@
]
}
]' formaction=""><i class="fa fa-book"></i></button>
<div class="advancedInput wf-100" id="<?= $this->getId(); ?>">
<input autocomplete="off" class="input" type="text" id="i<?= $this->getId(); ?>"
<div class="advancedInput wf-100" id="<?= $this->id; ?>">
<input autocomplete="off" class="input" type="text" id="i<?= $this->id; ?>"
data-emptyAfter="true"
data-autocomplete="off"
data-src="api/media/find?search={!#mediaInput}">
<div id="<?= $this->getId(); ?>-popup" class="popup" data-active="true">
<div id="<?= $this->id; ?>-popup" class="popup" data-active="true">
<table class="default">
<thead>
<tr>
@ -25,7 +25,7 @@
<td>Name<i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<td>Extension<i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<tbody>
<template id="<?= $this->getId(); ?>-rowElement" class="rowTemplate">
<template id="<?= $this->id; ?>-rowElement" class="rowTemplate">
<tr tabindex="-1">
<td data-tpl-text="/id" data-tpl-value="/id" data-value=""></td>
<td data-tpl-text="/name" data-tpl-value="/name" data-value=""></td>
@ -40,8 +40,8 @@
</div>
<div class="ipt-second"><button><?= $this->getHtml('Select', 'Media'); ?></button></div>
</div>
<div class="box" id="<?= $this->getId(); ?>-tags" data-limit="0" data-active="true">
<template id="<?= $this->getId(); ?>-tagTemplate">
<div class="box" id="<?= $this->id; ?>-tags" data-limit="0" data-active="true">
<template id="<?= $this->id; ?>-tagTemplate">
<span class="tag red" data-tpl-value="/id" data-value="" data-uuid="" data-name="<?= $this->printHtml($this->name); ?>">
<i class="fa fa-times close"></i>
<span style="display: none;" data-name="type_prefix" data-tpl-value="/type_prefix" data-value=""></span>

View File

@ -18,7 +18,7 @@ use phpOMS\Uri\UriFactory;
<section id="mediaFile" class="portlet">
<div class="portlet-body">
<audio width="100%" controls>
<source src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>" type="audio/<?= $this->media->extension; ?>">
<source src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->id); ?>" type="audio/<?= $this->media->extension; ?>">
Your browser does not support HTML audio.
</audio>
</div>

View File

@ -18,8 +18,8 @@ use phpOMS\Uri\UriFactory;
<section id="mediaFile" class="portlet">
<div class="portlet-body">
<div class="h-overflow centerText">
<img alt="<?= $this->printHtml($this->media->name); ?>" style="max-width: 100%" src="<?= $this->media->getId() !== 0
? UriFactory::build('{/api}media/export?id=' . $this->media->getId())
<img alt="<?= $this->printHtml($this->media->name); ?>" style="max-width: 100%" src="<?= $this->media->id !== 0
? UriFactory::build('{/api}media/export?id=' . $this->media->id)
: UriFactory::build('{/api}media/export?path=' . \urlencode($this->media->getPath()));
?>">
</div>

View File

@ -19,10 +19,10 @@ include __DIR__ . '/../../template-functions.php';
$previous = empty($this->media)
? '{%}'
: '{%}?{?}&mpivot=' . \reset($this->media)->getId() . '&mptype=p';
: '{%}?{?}&mpivot=' . \reset($this->media)->id . '&mptype=p';
$next = empty($this->media)
? '{%}'
: '{%}?{?}&mpivot=' . \end($this->media)->getId() . '&mptype=n';
: '{%}?{?}&mpivot=' . \end($this->media)->id . '&mptype=n';
?>
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Media', 'Media'); ?><i class="fa fa-download floatRight download btn"></i></div>
@ -38,7 +38,7 @@ $next = empty($this->media)
<td><?= $this->getHtml('Created', 'Media'); ?>
<tbody>
<?php $count = 0; foreach ($this->media as $key => $value) : ++$count;
$url = UriFactory::build('{/base}/media/single?{?}&id=' . $value->getId());
$url = UriFactory::build('{/base}/media/single?{?}&id=' . $value->id);
$icon = '';
$extensionType = FileUtils::getExtensionType($value->extension);

View File

@ -29,7 +29,7 @@ Autoloader::addPath(__DIR__ . '/../../../../../../Resources/');
<div class="tab-content col-simple">
<input type="radio" id="media-c-tab-1" name="tabular-1" checked>
<div class="tab col-simple">
<iframe class="col-simple" src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>&type=html"></iframe>
<iframe class="col-simple" src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->id); ?>&type=html"></iframe>
</div>
<input type="radio" id="media-c-tab-2" name="tabular-1" checked>
<div class="tab col-simple">

View File

@ -18,7 +18,7 @@ use phpOMS\Uri\UriFactory;
<section id="mediaFile" class="portlet">
<div class="portlet-body">
<video width="100%" controls>
<source src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>" type="video/<?= $this->media->extension; ?>">
<source src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->id); ?>" type="video/<?= $this->media->extension; ?>">
Your browser does not support HTML video.
</video>
</div>

View File

@ -17,6 +17,6 @@ use phpOMS\Uri\UriFactory;
?>
<section id="mediaFile" class="portlet col-simple">
<div class="portlet-body col-simple">
<iframe class="col-simple" src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>&type=html"></iframe>
<iframe class="col-simple" src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->id); ?>&type=html"></iframe>
</div>
</section>

View File

@ -28,10 +28,10 @@ $media = $this->getData('media') ?? [];
/** @var \Modules\Admin\Models\Account $account */
$account = $this->getData('account');
$accountDir = $account->getId() . ' ' . $account->login;
$accountDir = $account->id . ' ' . $account->login;
$previous = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id=' . \reset($media)->getId() . '&ptype=p';
$next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id=' . \end($media)->getId() . '&ptype=n';
$previous = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id=' . \reset($media)->id . '&ptype=p';
$next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id=' . \end($media)->id . '&ptype=n';
?>
<div class="row">
@ -187,9 +187,9 @@ $next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id='
$url = $value->extension === 'collection'
? UriFactory::build('{/base}/media/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->name)
: UriFactory::build('{/base}/media/single?id=' . $value->getId()
: UriFactory::build('{/base}/media/single?id=' . $value->id
. '&path={?path}' . (
$value->getId() === 0
$value->id === 0
? '/' . $value->name
: ''
)
@ -220,7 +220,7 @@ $next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id='
$size = FileSizeType::autoFormat($value->size);
echo $this->printHtml($value->extension !== 'collection' ? \number_format($size[0], 1, '.', ',') . $size[1] : ''); ?></a>
<td data-label="<?= $this->getHtml('Creator'); ?>">
<a class="content" href="<?= UriFactory::build('{/base}/profile/single?{?}&for=' . $value->createdBy->getId()); ?>">
<a class="content" href="<?= UriFactory::build('{/base}/profile/single?{?}&for=' . $value->createdBy->id); ?>">
<?= $this->printHtml($this->renderUserName(
'%3$s %2$s %1$s',
[$value->createdBy->name1, $value->createdBy->name2, $value->createdBy->name3, $value->createdBy->login ?? '']

View File

@ -28,7 +28,7 @@ $tags = $media->getTags();
/** @var \Modules\Admin\Models\Account $account */
$account = $this->getData('account');
$accountDir = $account->getId() . ' ' . $account->login;
$accountDir = $account->id . ' ' . $account->login;
$mediaPath = \urldecode($media->getVirtualPath() ?? '/');
@ -40,7 +40,7 @@ echo $this->getData('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->getId() === 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>
<?php endif; ?>
@ -92,7 +92,7 @@ echo $this->getData('nav')->render();
$size = FileSizeType::autoFormat($media->size);
echo $this->printHtml(\number_format($size[0], 1, '.', ',') . $size[1]); ?>
<tr><td><?= $this->getHtml('Created'); ?><td><?= $this->printHtml($media->createdAt->format('Y-m-d')); ?>
<tr><td><?= $this->getHtml('Creator'); ?><td><a href="<?= UriFactory::build('{/base}/profile/single?for=' . $media->createdBy->getId()); ?>"><?= $this->printHtml(
<tr><td><?= $this->getHtml('Creator'); ?><td><a href="<?= UriFactory::build('{/base}/profile/single?for=' . $media->createdBy->id); ?>"><?= $this->printHtml(
\ltrim($media->createdBy->name2 . ', ' . $media->createdBy->name1, ', ')
); ?></a>
<tr><td><?= $this->getHtml('Tags'); ?><td>

View File

@ -145,8 +145,8 @@ trait ApiControllerCollectionTrait
$media->name = 'Media for collection';
$id = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId());
self::assertGreaterThan(0, $media->id);
self::assertEquals($id, $media->id);
$collection = $this->module->createMediaCollectionFromMedia('Collection With Media', '', [$media], 1);

View File

@ -67,8 +67,8 @@ trait ApiControllerMediaTrait
1
);
if ($created->getId() > 0) {
$ids[] = $created->getId();
if ($created->id > 0) {
$ids[] = $created->id;
}
}

View File

@ -39,12 +39,12 @@ final class CollectionMapperTest extends \PHPUnit\Framework\TestCase
$media->name = 'Collection';
$id = CollectionMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId());
self::assertGreaterThan(0, $media->id);
self::assertEquals($id, $media->id);
$mediaR = CollectionMapper::get()->where('id', $media->getId())->execute();
$mediaR = CollectionMapper::get()->where('id', $media->id)->execute();
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
self::assertEquals($media->createdBy->id, $mediaR->createdBy->id);
self::assertEquals($media->description, $mediaR->description);
self::assertEquals($media->descriptionRaw, $mediaR->descriptionRaw);
self::assertEquals($media->getPath(), $mediaR->getPath());

View File

@ -39,8 +39,8 @@ final class CollectionTest extends \PHPUnit\Framework\TestCase
*/
public function testDefault() : void
{
self::assertEquals(0, $this->media->getId());
self::assertEquals(0, $this->media->createdBy->getId());
self::assertEquals(0, $this->media->id);
self::assertEquals(0, $this->media->createdBy->id);
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->media->createdAt->format('Y-m-d'));
self::assertEquals('collection', $this->media->extension);
self::assertEquals('', $this->media->getPath());
@ -59,7 +59,7 @@ final class CollectionTest extends \PHPUnit\Framework\TestCase
public function testCreatedByInputOutput() : void
{
$this->media->createdBy = new NullAccount(1);
self::assertEquals(1, $this->media->createdBy->getId());
self::assertEquals(1, $this->media->createdBy->id);
}
/**
@ -148,8 +148,8 @@ final class CollectionTest extends \PHPUnit\Framework\TestCase
$this->media->setSources([$a = new NullMedia(1), $b = new NullMedia(2), $c = new NullMedia(3)]);
foreach ($this->media as $key => $media) {
if ($media->getId() !== $key + 1) {
self::assertEquals($key + 1, $media->getId());
if ($media->id !== $key + 1) {
self::assertEquals($key + 1, $media->id);
}
}

View File

@ -41,12 +41,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$media->name = 'Image';
$id = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId());
self::assertGreaterThan(0, $media->id);
self::assertEquals($id, $media->id);
$mediaR = MediaMapper::get()->where('id', $media->getId())->execute();
$mediaR = MediaMapper::get()->where('id', $media->id)->execute();
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
self::assertEquals($media->createdBy->id, $mediaR->createdBy->id);
self::assertEquals($media->description, $mediaR->description);
self::assertEquals($media->descriptionRaw, $mediaR->descriptionRaw);
self::assertEquals($media->getPath(), $mediaR->getPath());
@ -72,12 +72,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$media->name = 'Absolute path';
$id = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId());
self::assertGreaterThan(0, $media->id);
self::assertEquals($id, $media->id);
$mediaR = MediaMapper::get()->where('id', $media->getId())->execute();
$mediaR = MediaMapper::get()->where('id', $media->id)->execute();
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
self::assertEquals($media->createdBy->id, $mediaR->createdBy->id);
self::assertEquals($media->description, $mediaR->description);
self::assertEquals($media->getPath(), $mediaR->getPath());
self::assertEquals($media->isAbsolute, $mediaR->isAbsolute);
@ -102,12 +102,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$media->name = 'Directory';
$id = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId());
self::assertGreaterThan(0, $media->id);
self::assertEquals($id, $media->id);
$mediaR = MediaMapper::get()->where('id', $media->getId())->execute();
$mediaR = MediaMapper::get()->where('id', $media->id)->execute();
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
self::assertEquals($media->createdBy->id, $mediaR->createdBy->id);
self::assertEquals($media->description, $mediaR->description);
self::assertEquals($media->getPath(), $mediaR->getPath());
self::assertEquals($media->isAbsolute, $mediaR->isAbsolute);
@ -133,13 +133,13 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$media->name = 'With virtual path';
$id = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId());
self::assertGreaterThan(0, $media->id);
self::assertEquals($id, $media->id);
$found = MediaMapper::getByVirtualPath($media->getVirtualPath())->execute();
$mediaR = \reset($found);
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
self::assertEquals($media->createdBy->id, $mediaR->createdBy->id);
self::assertEquals($media->description, $mediaR->description);
self::assertEquals($media->getPath(), $mediaR->getPath());
self::assertEquals($media->isAbsolute, $mediaR->isAbsolute);
@ -164,8 +164,8 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$collection->name = 'Collection';
$idCollection = CollectionMapper::create()->execute($collection);
self::assertGreaterThan(0, $collection->getId());
self::assertEquals($idCollection, $collection->getId());
self::assertGreaterThan(0, $collection->id);
self::assertEquals($idCollection, $collection->id);
$media = new Media();
$media->createdBy = new NullAccount(1);
@ -178,11 +178,11 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$media->name = 'Absolute path';
$idMedia = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId());
self::assertEquals($idMedia, $media->getId());
self::assertGreaterThan(0, $media->id);
self::assertEquals($idMedia, $media->id);
$collectionR = MediaMapper::getParentCollection($media->getVirtualPath())->execute();
self::assertEquals($idCollection, $collectionR->getId());
self::assertEquals($idCollection, $collectionR->id);
self::assertEquals($collection->name, $collectionR->name);
}
}

View File

@ -40,8 +40,8 @@ final class MediaTest extends \PHPUnit\Framework\TestCase
*/
public function testDefault() : void
{
self::assertEquals(0, $this->media->getId());
self::assertEquals(0, $this->media->createdBy->getId());
self::assertEquals(0, $this->media->id);
self::assertEquals(0, $this->media->createdBy->id);
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->media->createdAt->format('Y-m-d'));
self::assertEquals('', $this->media->extension);
self::assertEquals('', $this->media->getPath());
@ -52,7 +52,6 @@ final class MediaTest extends \PHPUnit\Framework\TestCase
self::assertEquals('/', $this->media->getVirtualPath());
self::assertEquals(0, $this->media->size);
self::assertFalse($this->media->isVersioned);
self::assertFalse($this->media->compareNonce('something'));
self::assertFalse($this->media->isEncrypted());
}
@ -63,7 +62,7 @@ final class MediaTest extends \PHPUnit\Framework\TestCase
public function testCreatedByInputOutput() : void
{
$this->media->createdBy = new NullAccount(1);
self::assertEquals(1, $this->media->createdBy->getId());
self::assertEquals(1, $this->media->createdBy->id);
}
/**
@ -169,18 +168,6 @@ final class MediaTest extends \PHPUnit\Framework\TestCase
self::assertEquals(MediaStatus::HIDDEN, $this->media->status);
}
/**
* @covers Modules\Media\Models\Media
* @group module
*/
public function testNonceInputOutput() : void
{
$this->media->setNonce('test');
self::assertTrue($this->media->compareNonce('test'));
self::assertFalse($this->media->compareNonce('test2'));
self::assertTrue($this->media->isEncrypted());
}
/**
* @covers Modules\Media\Models\Media
* @group module

View File

@ -38,7 +38,7 @@ final class MediaTypeTest extends \PHPUnit\Framework\TestCase
*/
public function testDefault() : void
{
self::assertEquals(0, $this->type->getId());
self::assertEquals(0, $this->type->id);
self::assertEquals('', $this->type->name);
}

View File

@ -37,6 +37,6 @@ final class NullCollectionTest extends \PHPUnit\Framework\TestCase
public function testId() : void
{
$null = new NullCollection(2);
self::assertEquals(2, $null->getId());
self::assertEquals(2, $null->id);
}
}

View File

@ -37,6 +37,6 @@ final class NullMediaTest extends \PHPUnit\Framework\TestCase
public function testId() : void
{
$null = new NullMedia(2);
self::assertEquals(2, $null->getId());
self::assertEquals(2, $null->id);
}
}

View File

@ -37,6 +37,6 @@ final class NullMediaTypeTest extends \PHPUnit\Framework\TestCase
public function testId() : void
{
$null = new NullMediaType(2);
self::assertEquals(2, $null->getId());
self::assertEquals(2, $null->id);
}
}