Fixed saving post original file name to DB
This commit is contained in:
parent
eee6421775
commit
1352aba438
3 changed files with 7 additions and 9 deletions
|
@ -536,6 +536,7 @@ class PostController
|
||||||
|
|
||||||
$srcPath = $suppliedFile['tmp_name'];
|
$srcPath = $suppliedFile['tmp_name'];
|
||||||
$post->setContentFromPath($srcPath);
|
$post->setContentFromPath($srcPath);
|
||||||
|
$post->origName = $suppliedFile['name'];
|
||||||
|
|
||||||
if (!$isNew)
|
if (!$isNew)
|
||||||
LogHelper::log('{user} changed contents of {post}', ['post' => TextHelper::reprPost($post)]);
|
LogHelper::log('{user} changed contents of {post}', ['post' => TextHelper::reprPost($post)]);
|
||||||
|
@ -547,6 +548,7 @@ class PostController
|
||||||
|
|
||||||
$url = InputHelper::get('url');
|
$url = InputHelper::get('url');
|
||||||
$post->setContentFromUrl($url);
|
$post->setContentFromUrl($url);
|
||||||
|
$post->origName = $url;
|
||||||
|
|
||||||
if (!$isNew)
|
if (!$isNew)
|
||||||
LogHelper::log('{user} changed contents of {post}', ['post' => TextHelper::reprPost($post)]);
|
LogHelper::log('{user} changed contents of {post}', ['post' => TextHelper::reprPost($post)]);
|
||||||
|
|
|
@ -234,7 +234,7 @@ class PostEntity extends AbstractEntity
|
||||||
if ($this->type == PostType::Youtube)
|
if ($this->type == PostType::Youtube)
|
||||||
{
|
{
|
||||||
$tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.jpg';
|
$tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.jpg';
|
||||||
$contents = file_get_contents('http://img.youtube.com/vi/' . $this->origName . '/mqdefault.jpg');
|
$contents = file_get_contents('http://img.youtube.com/vi/' . $this->fileHash . '/mqdefault.jpg');
|
||||||
file_put_contents($tmpPath, $contents);
|
file_put_contents($tmpPath, $contents);
|
||||||
if (file_exists($tmpPath))
|
if (file_exists($tmpPath))
|
||||||
$srcImage = imagecreatefromjpeg($tmpPath);
|
$srcImage = imagecreatefromjpeg($tmpPath);
|
||||||
|
@ -333,7 +333,6 @@ class PostEntity extends AbstractEntity
|
||||||
throw new SimpleException('Invalid file type "' . $this->mimeType . '"');
|
throw new SimpleException('Invalid file type "' . $this->mimeType . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->origName = basename($srcPath);
|
|
||||||
$duplicatedPost = PostModel::findByHash($this->fileHash, false);
|
$duplicatedPost = PostModel::findByHash($this->fileHash, false);
|
||||||
if ($duplicatedPost !== null and (!$this->id or $this->id != $duplicatedPost->id))
|
if ($duplicatedPost !== null and (!$this->id or $this->id != $duplicatedPost->id))
|
||||||
throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id);
|
throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id);
|
||||||
|
@ -352,19 +351,16 @@ class PostEntity extends AbstractEntity
|
||||||
|
|
||||||
public function setContentFromUrl($srcUrl)
|
public function setContentFromUrl($srcUrl)
|
||||||
{
|
{
|
||||||
$this->origName = $srcUrl;
|
|
||||||
|
|
||||||
if (!preg_match('/^https?:\/\//', $srcUrl))
|
if (!preg_match('/^https?:\/\//', $srcUrl))
|
||||||
throw new SimpleException('Invalid URL "' . $srcUrl . '"');
|
throw new SimpleException('Invalid URL "' . $srcUrl . '"');
|
||||||
|
|
||||||
if (preg_match('/youtube.com\/watch.*?=([a-zA-Z0-9_-]+)/', $srcUrl, $matches))
|
if (preg_match('/youtube.com\/watch.*?=([a-zA-Z0-9_-]+)/', $srcUrl, $matches))
|
||||||
{
|
{
|
||||||
$origName = $matches[1];
|
$youtubeId = $matches[1];
|
||||||
$this->origName = $origName;
|
|
||||||
$this->type = PostType::Youtube;
|
$this->type = PostType::Youtube;
|
||||||
$this->mimeType = null;
|
$this->mimeType = null;
|
||||||
$this->fileSize = null;
|
$this->fileSize = null;
|
||||||
$this->fileHash = $origName;
|
$this->fileHash = $youtubeId;
|
||||||
$this->imageWidth = null;
|
$this->imageWidth = null;
|
||||||
$this->imageHeight = null;
|
$this->imageHeight = null;
|
||||||
|
|
||||||
|
@ -372,7 +368,7 @@ class PostEntity extends AbstractEntity
|
||||||
if (file_exists($thumbPath))
|
if (file_exists($thumbPath))
|
||||||
unlink($thumbPath);
|
unlink($thumbPath);
|
||||||
|
|
||||||
$duplicatedPost = PostModel::findByHash($origName, false);
|
$duplicatedPost = PostModel::findByHash($youtubeId, false);
|
||||||
if ($duplicatedPost !== null and (!$this->id or $this->id != $duplicatedPost->id))
|
if ($duplicatedPost !== null and (!$this->id or $this->id != $duplicatedPost->id))
|
||||||
throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id);
|
throw new SimpleException('Duplicate upload: @' . $duplicatedPost->id);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -19,6 +19,6 @@
|
||||||
|
|
||||||
<?php elseif ($post->type == PostType::Youtube): ?>
|
<?php elseif ($post->type == PostType::Youtube): ?>
|
||||||
|
|
||||||
<iframe style="width: 800px; height: 600px; border: 0;" src="//www.youtube.com/embed/<?php echo $post->origName ?>" allowfullscreen></iframe>
|
<iframe style="width: 800px; height: 600px; border: 0;" src="//www.youtube.com/embed/<?php echo $post->fileHash ?>" allowfullscreen></iframe>
|
||||||
|
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
Loading…
Reference in a new issue