diff --git a/lib/zerobin.php b/lib/zerobin.php index 206d730..515a57e 100644 --- a/lib/zerobin.php +++ b/lib/zerobin.php @@ -340,10 +340,7 @@ class zerobin if ($paste->exists()) { // The paste itself is the first in the list of encrypted messages. - $messages = array_merge( - array($paste->get()), - $paste->getComments() - ); + $messages = array_merge(array($paste->get()), $paste->getComments()); $this->_data = json_encode($messages); } else diff --git a/lib/zerobin/abstract.php b/lib/zerobin/abstract.php index d6d46a6..5ca481f 100644 --- a/lib/zerobin/abstract.php +++ b/lib/zerobin/abstract.php @@ -138,7 +138,7 @@ abstract class zerobin_abstract $parts = explode('.', $postdate, 2); if (!array_key_exists(1, $parts)) $parts[1] = 0; ++$parts[1]; - return $this->addComment($comments, implode('.', $parts)); + return $this->getOpenSlot($comments, implode('.', $parts)); } return $postdate; } diff --git a/lib/zerobin/db.php b/lib/zerobin/db.php index d6d6249..1e0695a 100644 --- a/lib/zerobin/db.php +++ b/lib/zerobin/db.php @@ -80,6 +80,11 @@ class zerobin_db extends zerobin_abstract array_key_exists('opt', $options) ) { + // set default options + $options['opt'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; + $options['opt'][PDO::ATTR_EMULATE_PREPARES] = false; + $options['opt'][PDO::ATTR_PERSISTENT] = true; + // check if the database contains the required tables self::$_type = strtolower( substr($options['dsn'], 0, strpos($options['dsn'], ':')) @@ -156,12 +161,9 @@ class zerobin_db extends zerobin_abstract else { try { - self::$_db->exec('SELECT meta FROM ' . self::$_prefix . 'paste LIMIT 1;'); + self::_exec('SELECT meta FROM ' . self::$_prefix . 'paste LIMIT 1;', array()); } catch (PDOException $e) { - if ($e->getCode() == 'HY000') - { - self::$_db->exec('ALTER TABLE ' . self::$_prefix . 'paste ADD COLUMN meta TEXT;'); - } + self::$_db->exec('ALTER TABLE ' . self::$_prefix . 'paste ADD COLUMN meta TEXT;'); } } @@ -368,10 +370,6 @@ class zerobin_db extends zerobin_abstract array($pasteid) ); - // create object - $commentTemplate = new stdClass; - $commentTemplate->meta = new stdClass; - // create comment list $comments = array(); if (count($rows)) @@ -379,10 +377,13 @@ class zerobin_db extends zerobin_abstract foreach ($rows as $row) { $i = $this->getOpenSlot($comments, (int) $row['postdate']); - $comments[$i] = clone $commentTemplate; + $comments[$i] = new stdClass; $comments[$i]->data = $row['data']; - $comments[$i]->meta->nickname = $row['nickname']; - $comments[$i]->meta->vizhash = $row['vizhash']; + $comments[$i]->meta = new stdClass; + if (array_key_exists('nickname', $row)) + $comments[$i]->meta->nickname = $row['nickname']; + if (array_key_exists('vizhash', $row)) + $comments[$i]->meta->vizhash = $row['vizhash']; $comments[$i]->meta->postdate = $i; $comments[$i]->meta->commentid = $row['dataid']; $comments[$i]->meta->parentid = $row['parentid'];