mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-10-11 12:58:44 -04:00
refactoring how attachments are stored
This commit is contained in:
parent
22b4c89227
commit
d04eab52c9
8 changed files with 92 additions and 13 deletions
|
@ -75,9 +75,20 @@ class zerobin_data extends zerobin_abstract
|
|||
public function read($pasteid)
|
||||
{
|
||||
if(!$this->exists($pasteid)) return false;
|
||||
return json_decode(
|
||||
$paste = json_decode(
|
||||
file_get_contents(self::_dataid2path($pasteid) . $pasteid)
|
||||
);
|
||||
if (property_exists($paste->meta, 'attachment'))
|
||||
{
|
||||
$paste->attachment = $paste->meta->attachment;
|
||||
unset($paste->meta->attachment);
|
||||
if (property_exists($paste->meta, 'attachmentname'))
|
||||
{
|
||||
$paste->attachmentname = $paste->meta->attachmentname;
|
||||
unset($paste->meta->attachmentname);
|
||||
}
|
||||
}
|
||||
return $paste;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,7 +101,7 @@ class zerobin_data extends zerobin_abstract
|
|||
public function delete($pasteid)
|
||||
{
|
||||
// Delete the paste itself.
|
||||
unlink(self::_dataid2path($pasteid) . $pasteid);
|
||||
@unlink(self::_dataid2path($pasteid) . $pasteid);
|
||||
|
||||
// Delete discussion if it exists.
|
||||
$discdir = self::_dataid2discussionpath($pasteid);
|
||||
|
@ -100,7 +111,7 @@ class zerobin_data extends zerobin_abstract
|
|||
$dir = dir($discdir);
|
||||
while (false !== ($filename = $dir->read()))
|
||||
{
|
||||
if (is_file($discdir.$filename)) unlink($discdir.$filename);
|
||||
if (is_file($discdir.$filename)) @unlink($discdir.$filename);
|
||||
}
|
||||
$dir->close();
|
||||
|
||||
|
|
|
@ -264,6 +264,24 @@ class zerobin_db extends zerobin_abstract
|
|||
if (
|
||||
$paste['burnafterreading']
|
||||
) self::$_cache[$pasteid]->meta->burnafterreading = true;
|
||||
if (property_exists(self::$_cache[$pasteid]->meta, 'attachment'))
|
||||
{
|
||||
self::$_cache[$pasteid]->attachment = self::$_cache[$pasteid]->meta->attachment;
|
||||
unset(self::$_cache[$pasteid]->meta->attachment);
|
||||
if (property_exists(self::$_cache[$pasteid]->meta, 'attachmentname'))
|
||||
{
|
||||
self::$_cache[$pasteid]->attachmentname = self::$_cache[$pasteid]->meta->attachmentname;
|
||||
unset(self::$_cache[$pasteid]->meta->attachmentname);
|
||||
}
|
||||
}
|
||||
elseif (array_key_exists('attachment', $paste))
|
||||
{
|
||||
self::$_cache[$pasteid]->attachment = $paste['attachment'];
|
||||
if (array_key_exists('attachmentname', $paste))
|
||||
{
|
||||
self::$_cache[$pasteid]->attachmentname = $paste['attachmentname'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue