mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-03-22 13:10:41 +08:00
some optimization
This commit is contained in:
parent
3fa0881c07
commit
c2efe2e609
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
namespace PrivateBin\Data;
|
namespace PrivateBin\Data;
|
||||||
|
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractData
|
* AbstractData
|
||||||
*
|
*
|
||||||
|
|
|
@ -33,39 +33,40 @@ class Paste extends AbstractModel
|
||||||
*/
|
*/
|
||||||
public function get()
|
public function get()
|
||||||
{
|
{
|
||||||
$this->_data = $this->_store->read($this->getId());
|
$data = $this->_store->read($this->getId());
|
||||||
if ($this->_data === false) {
|
if ($data === false) {
|
||||||
throw new Exception(PrivateBin::GENERIC_ERROR, 64);
|
throw new Exception(PrivateBin::GENERIC_ERROR, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if paste has expired and delete it if neccessary.
|
// check if paste has expired and delete it if neccessary.
|
||||||
if (property_exists($this->_data->meta, 'expire_date')) {
|
if (property_exists($data->meta, 'expire_date')) {
|
||||||
if ($this->_data->meta->expire_date < time()) {
|
if ($data->meta->expire_date < time()) {
|
||||||
$this->delete();
|
$this->delete();
|
||||||
throw new Exception(PrivateBin::GENERIC_ERROR, 63);
|
throw new Exception(PrivateBin::GENERIC_ERROR, 63);
|
||||||
}
|
}
|
||||||
// We kindly provide the remaining time before expiration (in seconds)
|
// We kindly provide the remaining time before expiration (in seconds)
|
||||||
$this->_data->meta->remaining_time = $this->_data->meta->expire_date - time();
|
$data->meta->remaining_time = $data->meta->expire_date - time();
|
||||||
}
|
}
|
||||||
|
|
||||||
// set formatter for for the view.
|
// set formatter for for the view.
|
||||||
if (!property_exists($this->_data->meta, 'formatter')) {
|
if (!property_exists($data->meta, 'formatter')) {
|
||||||
// support < 0.21 syntax highlighting
|
// support < 0.21 syntax highlighting
|
||||||
if (property_exists($this->_data->meta, 'syntaxcoloring') && $this->_data->meta->syntaxcoloring === true) {
|
if (property_exists($data->meta, 'syntaxcoloring') && $data->meta->syntaxcoloring === true) {
|
||||||
$this->_data->meta->formatter = 'syntaxhighlighting';
|
$data->meta->formatter = 'syntaxhighlighting';
|
||||||
} else {
|
} else {
|
||||||
$this->_data->meta->formatter = $this->_conf->getKey('defaultformatter');
|
$data->meta->formatter = $this->_conf->getKey('defaultformatter');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// support old paste format with server wide salt
|
// support old paste format with server wide salt
|
||||||
if (!property_exists($this->_data->meta, 'salt')) {
|
if (!property_exists($data->meta, 'salt')) {
|
||||||
$this->_data->meta->salt = serversalt::get();
|
$data->meta->salt = ServerSalt::get();
|
||||||
}
|
}
|
||||||
$this->_data->comments = array_values($this->getComments());
|
$data->comments = array_values($this->getComments());
|
||||||
$this->_data->comment_count = count($this->_data->comments);
|
$data->comment_count = count($data->comments);
|
||||||
$this->_data->comment_offset = 0;
|
$data->comment_offset = 0;
|
||||||
$this->_data->{'@context'} = 'js/paste.jsonld';
|
$data->{'@context'} = 'js/paste.jsonld';
|
||||||
|
$this->_data = $data;
|
||||||
return $this->_data;
|
return $this->_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user