Continued work on getter/setters: post file stats
This commit is contained in:
parent
c4bcc4b85b
commit
a619662585
7 changed files with 60 additions and 29 deletions
|
@ -24,7 +24,7 @@ class GetPostContentJob extends AbstractJob
|
||||||
$config->main->title,
|
$config->main->title,
|
||||||
$post->getId(),
|
$post->getId(),
|
||||||
join(',', array_map(function($tag) { return $tag->getName(); }, $post->getTags())),
|
join(',', array_map(function($tag) { return $tag->getName(); }, $post->getTags())),
|
||||||
TextHelper::resolveMimeType($post->mimeType) ?: 'dat');
|
TextHelper::resolveMimeType($post->getMimeType()) ?: 'dat');
|
||||||
$fileName = preg_replace('/[[:^print:]]/', '', $fileName);
|
$fileName = preg_replace('/[[:^print:]]/', '', $fileName);
|
||||||
|
|
||||||
return new ApiFileOutput($path, $fileName);
|
return new ApiFileOutput($path, $fileName);
|
||||||
|
|
|
@ -7,9 +7,9 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
protected $type;
|
protected $type;
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $origName;
|
protected $origName;
|
||||||
public $fileHash;
|
protected $fileHash;
|
||||||
public $fileSize;
|
protected $fileSize;
|
||||||
public $mimeType;
|
protected $mimeType;
|
||||||
protected $safety;
|
protected $safety;
|
||||||
protected $hidden;
|
protected $hidden;
|
||||||
public $uploadDate;
|
public $uploadDate;
|
||||||
|
@ -239,6 +239,36 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
$this->origName = $origName;
|
$this->origName = $origName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFileHash()
|
||||||
|
{
|
||||||
|
return $this->fileHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFileHash($fileHash)
|
||||||
|
{
|
||||||
|
$this->fileHash = $fileHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFileSize()
|
||||||
|
{
|
||||||
|
return $this->fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFileSize($fileSize)
|
||||||
|
{
|
||||||
|
$this->fileSize = $fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMimeType()
|
||||||
|
{
|
||||||
|
return $this->mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMimeType($mimeType)
|
||||||
|
{
|
||||||
|
$this->mimeType = $mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->type;
|
||||||
|
@ -322,7 +352,7 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
if ($this->getType()->toInteger() == PostType::Youtube)
|
if ($this->getType()->toInteger() == PostType::Youtube)
|
||||||
{
|
{
|
||||||
return ThumbnailHelper::generateFromUrl(
|
return ThumbnailHelper::generateFromUrl(
|
||||||
'http://img.youtube.com/vi/' . $this->fileHash . '/mqdefault.jpg',
|
'http://img.youtube.com/vi/' . $this->getFileHash() . '/mqdefault.jpg',
|
||||||
$dstPath,
|
$dstPath,
|
||||||
$width,
|
$width,
|
||||||
$height);
|
$height);
|
||||||
|
@ -335,15 +365,15 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
|
|
||||||
public function setContentFromPath($srcPath, $origName)
|
public function setContentFromPath($srcPath, $origName)
|
||||||
{
|
{
|
||||||
$this->fileSize = filesize($srcPath);
|
$this->setFileSize(filesize($srcPath));
|
||||||
$this->fileHash = md5_file($srcPath);
|
$this->setFileHash(md5_file($srcPath));
|
||||||
$this->setOriginalName($origName);
|
$this->setOriginalName($origName);
|
||||||
|
|
||||||
if ($this->fileSize == 0)
|
if ($this->getFileSize() == 0)
|
||||||
throw new SimpleException('Specified file is empty');
|
throw new SimpleException('Specified file is empty');
|
||||||
|
|
||||||
$this->mimeType = mime_content_type($srcPath);
|
$this->setMimeType(mime_content_type($srcPath));
|
||||||
switch ($this->mimeType)
|
switch ($this->getMimeType())
|
||||||
{
|
{
|
||||||
case 'image/gif':
|
case 'image/gif':
|
||||||
case 'image/png':
|
case 'image/png':
|
||||||
|
@ -371,10 +401,10 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
$this->setImageHeight($imageHeight);
|
$this->setImageHeight($imageHeight);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new SimpleException('Invalid file type "%s"', $this->mimeType);
|
throw new SimpleException('Invalid file type "%s"', $this->getMimeType());
|
||||||
}
|
}
|
||||||
|
|
||||||
$duplicatedPost = PostModel::findByHash($this->fileHash, false);
|
$duplicatedPost = PostModel::findByHash($this->getFileHash(), false);
|
||||||
if ($duplicatedPost !== null and (!$this->getId() or $this->getId() != $duplicatedPost->getId()))
|
if ($duplicatedPost !== null and (!$this->getId() or $this->getId() != $duplicatedPost->getId()))
|
||||||
{
|
{
|
||||||
throw new SimpleException(
|
throw new SimpleException(
|
||||||
|
@ -402,9 +432,9 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
{
|
{
|
||||||
$youtubeId = $matches[1];
|
$youtubeId = $matches[1];
|
||||||
$this->setType(new PostType(PostType::Youtube));
|
$this->setType(new PostType(PostType::Youtube));
|
||||||
$this->mimeType = null;
|
$this->setMimeType(null);
|
||||||
$this->fileSize = null;
|
$this->setFileSize(null);
|
||||||
$this->fileHash = $youtubeId;
|
$this->setFileHash($youtubeId);
|
||||||
$this->setImageWidth(null);
|
$this->setImageWidth(null);
|
||||||
$this->setImageHeight(null);
|
$this->setImageHeight(null);
|
||||||
|
|
||||||
|
@ -451,7 +481,7 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
|
|
||||||
$x []= $this->getSafety()->toInteger();
|
$x []= $this->getSafety()->toInteger();
|
||||||
$x []= $this->getSource();
|
$x []= $this->getSource();
|
||||||
$x []= $this->fileHash;
|
$x []= $this->getFileHash();
|
||||||
|
|
||||||
natcasesort($x);
|
natcasesort($x);
|
||||||
|
|
||||||
|
|
|
@ -48,9 +48,9 @@ class PostModel extends AbstractCrudModel
|
||||||
'type' => $post->getType()->toInteger(),
|
'type' => $post->getType()->toInteger(),
|
||||||
'name' => $post->getName(),
|
'name' => $post->getName(),
|
||||||
'orig_name' => $post->getOriginalName(),
|
'orig_name' => $post->getOriginalName(),
|
||||||
'file_hash' => $post->fileHash,
|
'file_hash' => $post->getFileHash(),
|
||||||
'file_size' => $post->fileSize,
|
'file_size' => $post->getFileSize(),
|
||||||
'mime_type' => $post->mimeType,
|
'mime_type' => $post->getMimeType(),
|
||||||
'safety' => $post->getSafety()->toInteger(),
|
'safety' => $post->getSafety()->toInteger(),
|
||||||
'hidden' => $post->isHidden(),
|
'hidden' => $post->isHidden(),
|
||||||
'upload_date' => $post->uploadDate,
|
'upload_date' => $post->uploadDate,
|
||||||
|
|
|
@ -23,7 +23,7 @@ $post = $this->context->transport->post;
|
||||||
<?php elseif ($post->getType()->toInteger() == PostType::Flash): ?>
|
<?php elseif ($post->getType()->toInteger() == PostType::Flash): ?>
|
||||||
|
|
||||||
<object
|
<object
|
||||||
type="<?= $post->mimeType ?>"
|
type="<?= $post->getMimeType() ?>"
|
||||||
width="<?= $post->getImageWidth() ?>"
|
width="<?= $post->getImageWidth() ?>"
|
||||||
height="<?= $post->getImageHeight() ?>"
|
height="<?= $post->getImageHeight() ?>"
|
||||||
data="<?= \Chibi\Router::linkTo(
|
data="<?= \Chibi\Router::linkTo(
|
||||||
|
@ -41,7 +41,7 @@ $post = $this->context->transport->post;
|
||||||
|
|
||||||
<iframe
|
<iframe
|
||||||
style="width: 800px; height: 600px; border: 0;"
|
style="width: 800px; height: 600px; border: 0;"
|
||||||
src="//www.youtube.com/embed/<?= $post->fileHash ?>?wmode=opaque"
|
src="//www.youtube.com/embed/<?= $post->getFileHash() ?>?wmode=opaque"
|
||||||
allowfullscreen>
|
allowfullscreen>
|
||||||
|
|
||||||
</iframe>
|
</iframe>
|
||||||
|
@ -50,7 +50,7 @@ $post = $this->context->transport->post;
|
||||||
|
|
||||||
<video style="max-width: 100%" controls>
|
<video style="max-width: 100%" controls>
|
||||||
<source
|
<source
|
||||||
type="<?= $post->mimeType ?>"
|
type="<?= $post->getMimeType() ?>"
|
||||||
src="<?= \Chibi\Router::linkTo(
|
src="<?= \Chibi\Router::linkTo(
|
||||||
['PostController', 'fileView'],
|
['PostController', 'fileView'],
|
||||||
['name' => $post->getName()]) ?>">
|
['name' => $post->getName()]) ?>">
|
||||||
|
|
|
@ -5,7 +5,7 @@ $classNames =
|
||||||
[
|
[
|
||||||
'post',
|
'post',
|
||||||
'post-type-' . TextCaseConverter::convert(
|
'post-type-' . TextCaseConverter::convert(
|
||||||
TextHelper::resolveMimeType($this->context->post->mimeType)
|
TextHelper::resolveMimeType($this->context->post->getMimeType())
|
||||||
?: $this->context->post->getType()->toString(),
|
?: $this->context->post->getType()->toString(),
|
||||||
TextCaseConverter::CAMEL_CASE,
|
TextCaseConverter::CAMEL_CASE,
|
||||||
TextCaseConverter::SPINAL_CASE),
|
TextCaseConverter::SPINAL_CASE),
|
||||||
|
|
|
@ -194,8 +194,9 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
||||||
<?php
|
<?php
|
||||||
printf(
|
printf(
|
||||||
'Download %s (%s)',
|
'Download %s (%s)',
|
||||||
strtoupper(TextHelper::resolveMimeType($this->context->transport->post->mimeType)) ?: 'Unknown',
|
strtoupper(TextHelper::resolveMimeType($this->context->transport->post->getMimeType()))
|
||||||
TextHelper::useBytesUnits($this->context->transport->post->fileSize));
|
?: 'Unknown',
|
||||||
|
TextHelper::useBytesUnits($this->context->transport->post->getFileSize()));
|
||||||
?>
|
?>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -17,7 +17,7 @@ class EditPostContentJobTest extends AbstractTest
|
||||||
$this->prepare();
|
$this->prepare();
|
||||||
$this->grantAccess('editPostContent');
|
$this->grantAccess('editPostContent');
|
||||||
$post = $this->uploadFromFile('image.jpg');
|
$post = $this->uploadFromFile('image.jpg');
|
||||||
$this->assert->areEqual('image/jpeg', $post->mimeType);
|
$this->assert->areEqual('image/jpeg', $post->getMimeType());
|
||||||
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
||||||
$this->assert->areEqual(320, $post->getImageWidth());
|
$this->assert->areEqual(320, $post->getImageWidth());
|
||||||
$this->assert->areEqual(240, $post->getImageHeight());
|
$this->assert->areEqual(240, $post->getImageHeight());
|
||||||
|
@ -32,7 +32,7 @@ class EditPostContentJobTest extends AbstractTest
|
||||||
$this->prepare();
|
$this->prepare();
|
||||||
$this->grantAccess('editPostContent');
|
$this->grantAccess('editPostContent');
|
||||||
$post = $this->uploadFromFile('image.png');
|
$post = $this->uploadFromFile('image.png');
|
||||||
$this->assert->areEqual('image/png', $post->mimeType);
|
$this->assert->areEqual('image/png', $post->getMimeType());
|
||||||
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
||||||
$this->assert->areEqual(320, $post->getImageWidth());
|
$this->assert->areEqual(320, $post->getImageWidth());
|
||||||
$this->assert->areEqual(240, $post->getImageHeight());
|
$this->assert->areEqual(240, $post->getImageHeight());
|
||||||
|
@ -47,7 +47,7 @@ class EditPostContentJobTest extends AbstractTest
|
||||||
$this->prepare();
|
$this->prepare();
|
||||||
$this->grantAccess('editPostContent');
|
$this->grantAccess('editPostContent');
|
||||||
$post = $this->uploadFromFile('image.gif');
|
$post = $this->uploadFromFile('image.gif');
|
||||||
$this->assert->areEqual('image/gif', $post->mimeType);
|
$this->assert->areEqual('image/gif', $post->getMimeType());
|
||||||
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
$this->assert->areEqual(PostType::Image, $post->getType()->toInteger());
|
||||||
$this->assert->areEqual(320, $post->getImageWidth());
|
$this->assert->areEqual(320, $post->getImageWidth());
|
||||||
$this->assert->areEqual(240, $post->getImageHeight());
|
$this->assert->areEqual(240, $post->getImageHeight());
|
||||||
|
@ -91,7 +91,7 @@ class EditPostContentJobTest extends AbstractTest
|
||||||
EditPostContentJob::POST_CONTENT_URL => 'http://www.youtube.com/watch?v=qWq_jydCUw4', 'test.jpg',
|
EditPostContentJob::POST_CONTENT_URL => 'http://www.youtube.com/watch?v=qWq_jydCUw4', 'test.jpg',
|
||||||
]);
|
]);
|
||||||
$this->assert->areEqual(PostType::Youtube, $post->getType()->toInteger());
|
$this->assert->areEqual(PostType::Youtube, $post->getType()->toInteger());
|
||||||
$this->assert->areEqual('qWq_jydCUw4', $post->fileHash);
|
$this->assert->areEqual('qWq_jydCUw4', $post->getFileHash());
|
||||||
$this->assert->doesNotThrow(function() use ($post)
|
$this->assert->doesNotThrow(function() use ($post)
|
||||||
{
|
{
|
||||||
$post->generateThumb();
|
$post->generateThumb();
|
||||||
|
|
Loading…
Reference in a new issue