removed leftovers from submodule uglifyjs, added credits file,

cleaned up CSS, changed template to output clean XHTML 5,
added unit tests for 60% of the code, found a few bugs by doing
that and fixed them
This commit is contained in:
Simon Rupf
2012-08-26 00:49:11 +02:00
parent f37303d858
commit 907538875b
32 changed files with 961 additions and 511 deletions

View File

@@ -51,7 +51,7 @@ abstract class zerobin_abstract
* @static
* @return zerobin_abstract
*/
abstract public static function getInstance($options);
public static function getInstance($options) {}
/**
* Create a paste.

View File

@@ -37,13 +37,13 @@ class zerobin_data extends zerobin_abstract
if (
is_array($options) &&
array_key_exists('dir', $options)
) self::$_dir = $options['dir'] . '/';
) self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR;
// if needed initialize the singleton
if(null === parent::$_instance) {
parent::$_instance = new self;
if(!(self::$_instance instanceof zerobin_data)) {
self::$_instance = new self;
self::_init();
}
return parent::$_instance;
return self::$_instance;
}
/**
@@ -59,7 +59,7 @@ class zerobin_data extends zerobin_abstract
$storagedir = self::_dataid2path($pasteid);
if (is_file($storagedir . $pasteid)) return false;
if (!is_dir($storagedir)) mkdir($storagedir, 0705, true);
return file_put_contents($storagedir . $pasteid, json_encode($paste));
return (bool) file_put_contents($storagedir . $pasteid, json_encode($paste));
}
/**
@@ -67,13 +67,11 @@ class zerobin_data extends zerobin_abstract
*
* @access public
* @param string $pasteid
* @return string
* @return stdClass|false
*/
public function read($pasteid)
{
if(!$this->exists($pasteid)) return json_decode(
'{"data":"","meta":{"burnafterreading":true,"postdate":0}}'
);
if(!$this->exists($pasteid)) return false;
return json_decode(
file_get_contents(self::_dataid2path($pasteid) . $pasteid)
);
@@ -193,7 +191,7 @@ class zerobin_data extends zerobin_abstract
{
return is_file(
self::_dataid2discussionpath($pasteid) .
$pasteid . '.' . $dataid . '.' . $parentid
$pasteid . '.' . $commentid . '.' . $parentid
);
}

View File

@@ -56,8 +56,8 @@ class zerobin_db extends zerobin_abstract
public static function getInstance($options = null)
{
// if needed initialize the singleton
if(null === self::$_instance) {
parent::$_instance = new self;
if(!(self::$_instance instanceof zerobin_db)) {
self::$_instance = new self;
}
if (is_array($options))
@@ -175,6 +175,16 @@ class zerobin_db extends zerobin_abstract
*/
public function create($pasteid, $paste)
{
if (
array_key_exists($pasteid, self::$_cache)
) {
if(false !== self::$_cache[$pasteid]) {
return false;
} else {
unset(self::$_cache[$pasteid]);
}
}
if (
!array_key_exists('opendiscussion', $paste['meta'])
) $paste['meta']['opendiscussion'] = false;
@@ -199,31 +209,36 @@ class zerobin_db extends zerobin_abstract
*
* @access public
* @param string $pasteid
* @return string
* @return stdClass|false
*/
public function read($pasteid)
{
if (
!array_key_exists($pasteid, self::$_cache)
) self::$_cache[$pasteid] = self::_select(
'SELECT * FROM ' . self::$_prefix . 'paste WHERE dataid = ?',
array($pasteid), true
);
) {
self::$_cache[$pasteid] = false;
$paste = self::_select(
'SELECT * FROM ' . self::$_prefix . 'paste WHERE dataid = ?',
array($pasteid), true
);
// create object
$paste = new stdClass;
$paste->data = self::$_cache[$pasteid]['data'];
$paste->meta = new stdClass;
$paste->meta->postdate = (int) self::$_cache[$pasteid]['postdate'];
$paste->meta->expire_date = (int) self::$_cache[$pasteid]['expiredate'];
if (
self::$_cache[$pasteid]['opendiscussion']
) $paste->meta->opendiscussion = true;
if (
self::$_cache[$pasteid]['burnafterreading']
) $paste->meta->burnafterreading = true;
if(false !== $paste) {
// create object
self::$_cache[$pasteid] = new stdClass;
self::$_cache[$pasteid]->data = $paste['data'];
self::$_cache[$pasteid]->meta = new stdClass;
self::$_cache[$pasteid]->meta->postdate = (int) $paste['postdate'];
self::$_cache[$pasteid]->meta->expire_date = (int) $paste['expiredate'];
if (
$paste['opendiscussion']
) self::$_cache[$pasteid]->meta->opendiscussion = true;
if (
$paste['burnafterreading']
) self::$_cache[$pasteid]->meta->burnafterreading = true;
}
}
return $paste;
return self::$_cache[$pasteid];
}
/**
@@ -243,6 +258,9 @@ class zerobin_db extends zerobin_abstract
'DELETE FROM ' . self::$_prefix . 'comment WHERE pasteid = ?',
array($pasteid)
);
if (
array_key_exists($pasteid, self::$_cache)
) unset(self::$_cache[$pasteid]);
}
/**
@@ -256,10 +274,7 @@ class zerobin_db extends zerobin_abstract
{
if (
!array_key_exists($pasteid, self::$_cache)
) self::$_cache[$pasteid] = self::_select(
'SELECT * FROM ' . self::$_prefix . 'paste WHERE dataid = ?',
array($pasteid), true
);
) self::$_cache[$pasteid] = $this->read($pasteid);
return (bool) self::$_cache[$pasteid];
}
@@ -278,9 +293,9 @@ class zerobin_db extends zerobin_abstract
return self::_exec(
'INSERT INTO ' . self::$_prefix . 'comment VALUES(?,?,?,?,?,?,?)',
array(
$commentid,
$pasteid,
$parentid,
$commentid,
$comment['data'],
$comment['meta']['nickname'],
$comment['meta']['vizhash'],