Post edit: post content can now be replaced
This commit is contained in:
parent
ee224b84db
commit
3b532532d1
3 changed files with 23 additions and 3 deletions
|
@ -572,7 +572,7 @@ class PostController
|
||||||
private function doEdit($post, $isNew)
|
private function doEdit($post, $isNew)
|
||||||
{
|
{
|
||||||
/* file contents */
|
/* file contents */
|
||||||
if (isset($_FILES['file']))
|
if (!empty($_FILES['file']['name']))
|
||||||
{
|
{
|
||||||
if (!$isNew)
|
if (!$isNew)
|
||||||
PrivilegesHelper::confirmWithException(Privilege::EditPostFile, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
PrivilegesHelper::confirmWithException(Privilege::EditPostFile, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
|
||||||
|
|
|
@ -267,7 +267,7 @@ class Model_Post extends AbstractModel
|
||||||
|
|
||||||
$this->orig_name = basename($srcPath);
|
$this->orig_name = basename($srcPath);
|
||||||
$duplicatedPost = R::findOne('post', 'file_hash = ?', [$this->file_hash]);
|
$duplicatedPost = R::findOne('post', 'file_hash = ?', [$this->file_hash]);
|
||||||
if ($duplicatedPost !== null)
|
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);
|
||||||
|
|
||||||
$dstPath = $this->getFullPath($this->name);
|
$dstPath = $this->getFullPath($this->name);
|
||||||
|
@ -276,6 +276,10 @@ class Model_Post extends AbstractModel
|
||||||
move_uploaded_file($srcPath, $dstPath);
|
move_uploaded_file($srcPath, $dstPath);
|
||||||
else
|
else
|
||||||
rename($srcPath, $dstPath);
|
rename($srcPath, $dstPath);
|
||||||
|
|
||||||
|
$thumbPath = self::getThumbDefaultPath($this->name);
|
||||||
|
if (file_exists($thumbPath))
|
||||||
|
unlink($thumbPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -298,8 +302,12 @@ class Model_Post extends AbstractModel
|
||||||
$this->image_width = null;
|
$this->image_width = null;
|
||||||
$this->image_height = null;
|
$this->image_height = null;
|
||||||
|
|
||||||
|
$thumbPath = self::getThumbDefaultPath($this->name);
|
||||||
|
if (file_exists($thumbPath))
|
||||||
|
unlink($thumbPath);
|
||||||
|
|
||||||
$duplicatedPost = R::findOne('post', 'orig_name = ?', [$origName]);
|
$duplicatedPost = R::findOne('post', 'orig_name = ?', [$origName]);
|
||||||
if ($duplicatedPost !== null)
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,18 @@
|
||||||
</div>
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
|
<?php if (PrivilegesHelper::confirm(Privilege::EditPostFile, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader))): ?>
|
||||||
|
<div class="url">
|
||||||
|
<label class="left" for="url">File:</label>
|
||||||
|
<div class="input-wrapper"><input type="text" name="url" id="url" placeholder="Some url…"/></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="file">
|
||||||
|
<label class="left" for="file"></label>
|
||||||
|
<div class="input-wrapper"><input type="file" name="file" id="file"/></div>
|
||||||
|
</div>
|
||||||
|
<?php endif ?>
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::EditPostThumb, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader))): ?>
|
<?php if (PrivilegesHelper::confirm(Privilege::EditPostThumb, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->uploader))): ?>
|
||||||
<div class="thumb">
|
<div class="thumb">
|
||||||
<label class="left" for="thumb">Thumb:</label>
|
<label class="left" for="thumb">Thumb:</label>
|
||||||
|
|
Loading…
Reference in a new issue