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,
|
||||
$post->getId(),
|
||||
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);
|
||||
|
||||
return new ApiFileOutput($path, $fileName);
|
||||
|
|
|
@ -7,9 +7,9 @@ class PostEntity extends AbstractEntity implements IValidatable
|
|||
protected $type;
|
||||
protected $name;
|
||||
protected $origName;
|
||||
public $fileHash;
|
||||
public $fileSize;
|
||||
public $mimeType;
|
||||
protected $fileHash;
|
||||
protected $fileSize;
|
||||
protected $mimeType;
|
||||
protected $safety;
|
||||
protected $hidden;
|
||||
public $uploadDate;
|
||||
|
@ -239,6 +239,36 @@ class PostEntity extends AbstractEntity implements IValidatable
|
|||
$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()
|
||||
{
|
||||
return $this->type;
|
||||
|
@ -322,7 +352,7 @@ class PostEntity extends AbstractEntity implements IValidatable
|
|||
if ($this->getType()->toInteger() == PostType::Youtube)
|
||||
{
|
||||
return ThumbnailHelper::generateFromUrl(
|
||||
'http://img.youtube.com/vi/' . $this->fileHash . '/mqdefault.jpg',
|
||||
'http://img.youtube.com/vi/' . $this->getFileHash() . '/mqdefault.jpg',
|
||||
$dstPath,
|
||||
$width,
|
||||
$height);
|
||||
|
@ -335,15 +365,15 @@ class PostEntity extends AbstractEntity implements IValidatable
|
|||
|
||||
public function setContentFromPath($srcPath, $origName)
|
||||
{
|
||||
$this->fileSize = filesize($srcPath);
|
||||
$this->fileHash = md5_file($srcPath);
|
||||
$this->setFileSize(filesize($srcPath));
|
||||
$this->setFileHash(md5_file($srcPath));
|
||||
$this->setOriginalName($origName);
|
||||
|
||||
if ($this->fileSize == 0)
|
||||
if ($this->getFileSize() == 0)
|
||||
throw new SimpleException('Specified file is empty');
|
||||
|
||||
$this->mimeType = mime_content_type($srcPath);
|
||||
switch ($this->mimeType)
|
||||
$this->setMimeType(mime_content_type($srcPath));
|
||||
switch ($this->getMimeType())
|
||||
{
|
||||
case 'image/gif':
|
||||
case 'image/png':
|
||||
|
@ -371,10 +401,10 @@ class PostEntity extends AbstractEntity implements IValidatable
|
|||
$this->setImageHeight($imageHeight);
|
||||
break;
|
||||
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()))
|
||||
{
|
||||
throw new SimpleException(
|
||||
|
@ -402,9 +432,9 @@ class PostEntity extends AbstractEntity implements IValidatable
|
|||
{
|
||||
$youtubeId = $matches[1];
|
||||
$this->setType(new PostType(PostType::Youtube));
|
||||
$this->mimeType = null;
|
||||
$this->fileSize = null;
|
||||
$this->fileHash = $youtubeId;
|
||||
$this->setMimeType(null);
|
||||
$this->setFileSize(null);
|
||||
$this->setFileHash($youtubeId);
|
||||
$this->setImageWidth(null);
|
||||
$this->setImageHeight(null);
|
||||
|
||||
|
@ -451,7 +481,7 @@ class PostEntity extends AbstractEntity implements IValidatable
|
|||
|
||||
$x []= $this->getSafety()->toInteger();
|
||||
$x []= $this->getSource();
|
||||
$x []= $this->fileHash;
|
||||
$x []= $this->getFileHash();
|
||||
|
||||
natcasesort($x);
|
||||
|
||||
|
|
|
@ -48,9 +48,9 @@ class PostModel extends AbstractCrudModel
|
|||
'type' => $post->getType()->toInteger(),
|
||||
'name' => $post->getName(),
|
||||
'orig_name' => $post->getOriginalName(),
|
||||
'file_hash' => $post->fileHash,
|
||||
'file_size' => $post->fileSize,
|
||||
'mime_type' => $post->mimeType,
|
||||
'file_hash' => $post->getFileHash(),
|
||||
'file_size' => $post->getFileSize(),
|
||||
'mime_type' => $post->getMimeType(),
|
||||
'safety' => $post->getSafety()->toInteger(),
|
||||
'hidden' => $post->isHidden(),
|
||||
'upload_date' => $post->uploadDate,
|
||||
|
|
|
@ -23,7 +23,7 @@ $post = $this->context->transport->post;
|
|||
<?php elseif ($post->getType()->toInteger() == PostType::Flash): ?>
|
||||
|
||||
<object
|
||||
type="<?= $post->mimeType ?>"
|
||||
type="<?= $post->getMimeType() ?>"
|
||||
width="<?= $post->getImageWidth() ?>"
|
||||
height="<?= $post->getImageHeight() ?>"
|
||||
data="<?= \Chibi\Router::linkTo(
|
||||
|
@ -41,7 +41,7 @@ $post = $this->context->transport->post;
|
|||
|
||||
<iframe
|
||||
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>
|
||||
|
||||
</iframe>
|
||||
|
@ -50,7 +50,7 @@ $post = $this->context->transport->post;
|
|||
|
||||
<video style="max-width: 100%" controls>
|
||||
<source
|
||||
type="<?= $post->mimeType ?>"
|
||||
type="<?= $post->getMimeType() ?>"
|
||||
src="<?= \Chibi\Router::linkTo(
|
||||
['PostController', 'fileView'],
|
||||
['name' => $post->getName()]) ?>">
|
||||
|
|
|
@ -5,7 +5,7 @@ $classNames =
|
|||
[
|
||||
'post',
|
||||
'post-type-' . TextCaseConverter::convert(
|
||||
TextHelper::resolveMimeType($this->context->post->mimeType)
|
||||
TextHelper::resolveMimeType($this->context->post->getMimeType())
|
||||
?: $this->context->post->getType()->toString(),
|
||||
TextCaseConverter::CAMEL_CASE,
|
||||
TextCaseConverter::SPINAL_CASE),
|
||||
|
|
|
@ -194,8 +194,9 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
|||
<?php
|
||||
printf(
|
||||
'Download %s (%s)',
|
||||
strtoupper(TextHelper::resolveMimeType($this->context->transport->post->mimeType)) ?: 'Unknown',
|
||||
TextHelper::useBytesUnits($this->context->transport->post->fileSize));
|
||||
strtoupper(TextHelper::resolveMimeType($this->context->transport->post->getMimeType()))
|
||||
?: 'Unknown',
|
||||
TextHelper::useBytesUnits($this->context->transport->post->getFileSize()));
|
||||
?>
|
||||
</span>
|
||||
</a>
|
||||
|
|
|
@ -17,7 +17,7 @@ class EditPostContentJobTest extends AbstractTest
|
|||
$this->prepare();
|
||||
$this->grantAccess('editPostContent');
|
||||
$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(320, $post->getImageWidth());
|
||||
$this->assert->areEqual(240, $post->getImageHeight());
|
||||
|
@ -32,7 +32,7 @@ class EditPostContentJobTest extends AbstractTest
|
|||
$this->prepare();
|
||||
$this->grantAccess('editPostContent');
|
||||
$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(320, $post->getImageWidth());
|
||||
$this->assert->areEqual(240, $post->getImageHeight());
|
||||
|
@ -47,7 +47,7 @@ class EditPostContentJobTest extends AbstractTest
|
|||
$this->prepare();
|
||||
$this->grantAccess('editPostContent');
|
||||
$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(320, $post->getImageWidth());
|
||||
$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',
|
||||
]);
|
||||
$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)
|
||||
{
|
||||
$post->generateThumb();
|
||||
|
|
Loading…
Reference in a new issue