From d8e3ba6f4d6ccb9053616d706aa94797f7d64e1f Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Jan 2009 03:59:51 -0800 Subject: [PATCH 01/11] preliminary work for image locking --- ext/upgrade/main.php | 14 +++++++++----- install.php | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ext/upgrade/main.php b/ext/upgrade/main.php index 6eb5147b..ef963489 100644 --- a/ext/upgrade/main.php +++ b/ext/upgrade/main.php @@ -3,20 +3,24 @@ class Upgrade implements Extension { public function receive_event(Event $event) { if($event instanceof InitExtEvent) { - $this->do_things(); + $this->do_things($event->context); } } - private function do_things() { - global $config; - global $database; + private function do_things($context) { + $config = $context->config; + $database = $context->database; if(!is_numeric($config->get_string("db_version"))) { $config->set_int("db_version", 2); } if($config->get_int("db_version") < 6) { - $database->upgrade_schema("ext/upgrade/schema.xml"); + // cry :S + } + + if($config->get_int("db_version") < 6) { // 7 + // add column image->locked } } } diff --git a/install.php b/install.php index 3c5cd064..445afa44 100644 --- a/install.php +++ b/install.php @@ -187,6 +187,7 @@ function create_tables($dsn) { // {{{ width INTEGER NOT NULL, height INTEGER NOT NULL, posted TIMESTAMP NOT NULL DEFAULT SCORE_NOW, + locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, INDEX(owner_id), INDEX(width), INDEX(height), From 5600e00de9061f91141e6c30f378e446a9ac9710 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Jan 2009 10:59:00 -0800 Subject: [PATCH 02/11] fixes --- core/imageboard.pack.php | 2 +- ext/tag_list/main.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 371380a6..e1b58dae 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -489,7 +489,7 @@ class Tag { // do nothing } else { - die("tag_explode only takes strings or arrays"); + die("Tag::explode() only takes strings or arrays"); } $tags = array_map("trim", $tags); diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index bb7f138b..47699966 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -242,11 +242,11 @@ class TagList implements Extension { global $config; $query = " - SELECT tags.tag, tags.count + SELECT tags.tag, tags.count as calc_count FROM tags, image_tags WHERE tags.id = image_tags.tag_id AND image_tags.image_id = ? - ORDER BY count DESC + ORDER BY calc_count DESC LIMIT ? "; $args = array($image->id, $config->get_int('tag_list_length')); @@ -280,7 +280,7 @@ class TagList implements Extension { global $database; global $config; - $wild_tags = tag_explode($search); + $wild_tags = Tag::explode($search); // $search_tags = array(); $tag_id_array = array(); From bb752d6fd16c08b14eb1e4afc271c5dccd2150f6 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Jan 2009 11:05:07 -0800 Subject: [PATCH 03/11] tag_explode -> Tag::explode --- contrib/danbooru_api/main.php | 6 +++--- contrib/handle_flash/main.php | 2 +- contrib/handle_ico/main.php | 2 +- contrib/handle_mp3/main.php | 2 +- contrib/handle_svg/main.php | 2 +- ext/handle_pixel/main.php | 2 +- ext/upload/main.php | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/contrib/danbooru_api/main.php b/contrib/danbooru_api/main.php index 1f1fc5cb..6cf011f0 100644 --- a/contrib/danbooru_api/main.php +++ b/contrib/danbooru_api/main.php @@ -192,7 +192,7 @@ class DanbooruApi implements Extension } // Get tags out of url - $posttags = tag_explode(isset($_REQUEST['tags']) ? $_REQUEST['tags'] : $_REQUEST['post']['tags']); + $posttags = Tag::explode(isset($_REQUEST['tags']) ? $_REQUEST['tags'] : $_REQUEST['post']['tags']); $hash = md5_file($file); // Was an md5 supplied? Does it match the file hash? if(isset($_REQUEST['md5'])) @@ -282,7 +282,7 @@ class DanbooruApi implements Extension { $limit = isset($_GET['limit']) ? int_escape($_GET['limit']) : 100; $start = isset($_GET['offset']) ? int_escape($_GET['offset']) : 0; - $tags = isset($_GET['tags']) ? tag_explode($_GET['tags']) : array(); + $tags = isset($_GET['tags']) ? Tag::explode($_GET['tags']) : array(); $results = Image::find_images($config,$database,$start,$limit,$tags); } @@ -340,7 +340,7 @@ class DanbooruApi implements Extension elseif(isset($_GET['tags'])) { $start = isset($_GET['after_id']) ? int_escape($_GET['offset']) : 0; - $tags = tag_explode($_GET['tags']); + $tags = Tag::explode($_GET['tags']); } */ diff --git a/contrib/handle_flash/main.php b/contrib/handle_flash/main.php index ec1fe485..408b3578 100644 --- a/contrib/handle_flash/main.php +++ b/contrib/handle_flash/main.php @@ -51,7 +51,7 @@ class FlashFileHandler implements Extension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = tag_explode($metadata['tags']); + $image->tag_array = Tag::explode($metadata['tags']); $image->source = $metadata['source']; // redundant, since getimagesize() works on SWF o_O diff --git a/contrib/handle_ico/main.php b/contrib/handle_ico/main.php index 182f8d43..532b23b3 100644 --- a/contrib/handle_ico/main.php +++ b/contrib/handle_ico/main.php @@ -69,7 +69,7 @@ class IcoFileHandler implements Extension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = tag_explode($metadata['tags']); + $image->tag_array = Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/contrib/handle_mp3/main.php b/contrib/handle_mp3/main.php index a0e1fcb3..7d0715f4 100644 --- a/contrib/handle_mp3/main.php +++ b/contrib/handle_mp3/main.php @@ -53,7 +53,7 @@ class MP3FileHandler implements Extension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = tag_explode($metadata['tags']); + $image->tag_array = Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/contrib/handle_svg/main.php b/contrib/handle_svg/main.php index 4859f93b..d9548a0a 100644 --- a/contrib/handle_svg/main.php +++ b/contrib/handle_svg/main.php @@ -79,7 +79,7 @@ class SVGFileHandler implements Extension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = tag_explode($metadata['tags']); + $image->tag_array = Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 16912456..489d0d4e 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -54,7 +54,7 @@ class PixelFileHandler implements Extension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = tag_explode($metadata['tags']); + $image->tag_array = Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/upload/main.php b/ext/upload/main.php index 44c8fca1..ad5c704b 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -55,7 +55,7 @@ class Upload implements Extension { if(($event instanceof PageRequestEvent) && $event->page_matches("upload")) { if(count($_FILES) + count($_POST) > 0) { - $tags = tag_explode($_POST['tags']); + $tags = Tag::explode($_POST['tags']); $source = isset($_POST['source']) ? $_POST['source'] : null; global $user; if($this->can_upload($user)) { @@ -81,7 +81,7 @@ class Upload implements Extension { $url = $_GET['url']; $tags = array('tagme'); if(!empty($_GET['tags']) && $_GET['tags'] != "null") { - $tags = tag_explode($_GET['tags']); + $tags = Tag::explode($_GET['tags']); } $ok = $this->try_transload($url, $tags, $url); $this->theme->display_upload_status($event->page, $ok); From 24ea454f2e1a1fa3e80be9294c41b445fb550959 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Jan 2009 12:02:58 -0800 Subject: [PATCH 04/11] easier to read logic --- ext/index/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/index/main.php b/ext/index/main.php index aed557ca..f120d057 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -86,7 +86,7 @@ class Index implements Extension { send_event(new PostListBuildingEvent($event->context, $search_terms)); - if(!(count($search_terms) == 0 && count($images) == 0)) { + if(count($search_terms) > 0 || count($images) > 0 || $page_number > 0) { $this->theme->set_page($page_number, $total_pages, $search_terms); $this->theme->display_page($event->page, $images); } From 171d7d3a29565fb1d9f017aff3ad0f22d1d72302 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Jan 2009 17:16:02 +0000 Subject: [PATCH 05/11] strip metadata from thumbnails --- ext/handle_pixel/main.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 489d0d4e..29081a3b 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -99,8 +99,10 @@ class PixelFileHandler implements Extension { $q = $config->get_int("thumb_quality"); $mem = $config->get_int("thumb_max_memory") / 1024 / 1024; // IM takes memory in MB + // convert to bitmap & back to strip metadata -- otherwise we + // can end up with 3KB of jpg data and 200KB of misc extra... // "-limit memory $mem" broken? - exec("convert {$inname}[0] -geometry {$w}x{$h} -quality {$q} jpg:$outname"); + exec("convert {$inname}[0] -geometry {$w}x{$h} bmp:- | convert bmp:- -quality {$q} jpg:$outname"); return true; } From 4af20a3cb5c76223f68bed09b09a83a95868fd51 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Jan 2009 12:42:37 +0000 Subject: [PATCH 06/11] basic word filter test --- contrib/word_filter/test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 contrib/word_filter/test.php diff --git a/contrib/word_filter/test.php b/contrib/word_filter/test.php new file mode 100644 index 00000000..f1795773 --- /dev/null +++ b/contrib/word_filter/test.php @@ -0,0 +1,16 @@ +assertEqual( + $this->filter("whore"), + "nice lady"); + } + + private function filter($in) { + $bb = new WordFilter(); + $tfe = new TextFormattingEvent($in); + $bb->receive_event($tfe); + return $tfe->formatted; + } +} +?> From 2d46a5c26951ca491cfe9a76e229490de5bbedf3 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Jan 2009 11:49:58 +0000 Subject: [PATCH 07/11] more functions that sqlite needs --- core/database.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/database.class.php b/core/database.class.php index 19615404..b7a36733 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -97,6 +97,8 @@ class SQLite extends DBEngine { // TODO: add functions: // now() // unix_timestamp() + // lower() + // log(base, number) } public function create_table_sql($name, $data) { From 4e551cf9c528f3aa7116c8f2414aa410b8084814 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Jan 2009 12:10:10 +0000 Subject: [PATCH 08/11] move shimmie-specific sqlite things out of adodb and into shimmie's database engine --- core/database.class.php | 27 +++++++++++++++++++++----- lib/adodb/drivers/adodb-sqlite.inc.php | 20 ------------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index b7a36733..3b7b3ed1 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -90,15 +90,32 @@ class PostgreSQL extends DBEngine { return "CREATE TABLE $name ($data)"; } } + +// shimmie functions for export to sqlite +function _unix_timestamp($date) { return strtotime($date); } +function _now() { return date("Y-m-d h:i:s"); } +function _floor($a) { return floor($a); } +function _log1($a) { return log($a); } +function _log2($a, $b) { return log($a, $b); } +function _isnull($a) { return is_null($a); } +function _md5($a) { return md5($a); } +function _concat($a, $b) { return $a . $b; } +function _lower($a) { return strtolower($a); } + class SQLite extends DBEngine { var $name = "sqlite"; public function init($db) { - // TODO: add functions: - // now() - // unix_timestamp() - // lower() - // log(base, number) + ini_set('sqlite.assoc_case', 0); + @sqlite_create_function($db->_connectionID, 'UNIX_TIMESTAMP', '_unix_timestamp', 1); + @sqlite_create_function($db->_connectionID, 'now', '_now', 0); + @sqlite_create_function($db->_connectionID, 'floor', '_floor', 1); + @sqlite_create_function($db->_connectionID, 'log', '_log1', 1); + @sqlite_create_function($db->_connectionID, 'log', '_log2', 2); + @sqlite_create_function($db->_connectionID, 'isnull', '_isnull', 1); + @sqlite_create_function($db->_connectionID, 'md5', '_md5', 1); + @sqlite_create_function($db->_connectionID, 'concat', '_concat', 2); + @sqlite_create_function($db->_connectionID, 'lower', '_lower', 1); } public function create_table_sql($name, $data) { diff --git a/lib/adodb/drivers/adodb-sqlite.inc.php b/lib/adodb/drivers/adodb-sqlite.inc.php index 64fbf496..f756c3cd 100644 --- a/lib/adodb/drivers/adodb-sqlite.inc.php +++ b/lib/adodb/drivers/adodb-sqlite.inc.php @@ -152,15 +152,6 @@ class ADODB_sqlite extends ADOConnection { { @sqlite_create_function($this->_connectionID, 'adodb_date', 'adodb_date', 1); @sqlite_create_function($this->_connectionID, 'adodb_date2', 'adodb_date2', 2); - - // XXX: shimmie customisation, as suggested by naikoto on the forums - @sqlite_create_function($this->_connectionID, 'UNIX_TIMESTAMP', 'UNIX_TIMESTAMP', 1); - @sqlite_create_function($this->_connectionID, 'now', 'now', 0); - @sqlite_create_function($this->_connectionID, 'floor', 'mfloor', 1); - @sqlite_create_function($this->_connectionID, 'log', 'mlog', 1); - @sqlite_create_function($this->_connectionID, 'isnull', 'fisnull', 1); - @sqlite_create_function($this->_connectionID, 'md5', 'fmd5', 1); - @sqlite_create_function($this->_connectionID, 'concat', 'fconcat', 2); } @@ -402,16 +393,5 @@ class ADORecordset_sqlite extends ADORecordSet { function _close() { } - } - -// shimmie functions -ini_set ( 'sqlite.assoc_case' , 0 ); -function UNIX_TIMESTAMP($date) { return strtotime($date); } -function now() { return date("Y-m-d h:i:s"); } -function mfloor($a) { return floor($a); } -function mlog($a) { return log($a); } -function fisnull($a) { return is_null($a); } -function fmd5($a) { return md5($a); } -function fconcat($a, $b) { return $a . $b; } ?> From 68967b0fa20d229a189736b8e3bff4dd85cce3c8 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Jan 2009 12:26:07 +0000 Subject: [PATCH 09/11] more bbcode tests --- ext/bbcode/test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ext/bbcode/test.php b/ext/bbcode/test.php index 18348440..76c809c7 100644 --- a/ext/bbcode/test.php +++ b/ext/bbcode/test.php @@ -13,6 +13,16 @@ class BBCodeUnitTest extends UnitTestCase { $this->template("[b]bold[i]italic", "[b]bold[i]italic"); } + public function testCode() { + $this->template("[code][b]bold[/b][/code]", "
[b]bold[/b]
"); + } + + public function testNestedList() { + $this->template( + "[list][*]a[list][*]a[*]b[/list][*]b[/list]", + "
  • a
    • a
    • b
  • b
"); + } + public function testURL() { $this->template( "[url]http://shishnet.org[/url]", From 63a4ca2587daaf98f1ad2f12efb0f023958a28d7 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Jan 2009 12:37:45 +0000 Subject: [PATCH 10/11] preliminary hash ban testing --- contrib/image_hash_ban/test.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 contrib/image_hash_ban/test.php diff --git a/contrib/image_hash_ban/test.php b/contrib/image_hash_ban/test.php new file mode 100644 index 00000000..a1b1e889 --- /dev/null +++ b/contrib/image_hash_ban/test.php @@ -0,0 +1,19 @@ +receive_event($due); + $this->assertTrue(false); // shouldn't work + } + catch(DataUploadException $ex) { + $this->assertTrue(true); // should fail + } + catch(Exception $ex) { + $this->assertTrue(false); // but not with any other error + } + } +} +?> From a9ca976afd1297d212a117395425e0ce059ab2bc Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Jan 2009 12:42:21 +0000 Subject: [PATCH 11/11] call assert() from the right place --- ext/bbcode/test.php | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/ext/bbcode/test.php b/ext/bbcode/test.php index 76c809c7..016a428d 100644 --- a/ext/bbcode/test.php +++ b/ext/bbcode/test.php @@ -1,45 +1,55 @@ template("[b]bold[/b][i]italic[/i]", "bolditalic"); + $this->assertEqual( + $this->filter("[b]bold[/b][i]italic[/i]"), + "bolditalic"); } public function testStacking() { - $this->template("[b]B[/b][i]I[/i][b]B[/b]", "BIB"); - $this->template("[b]bold[i]bolditalic[/i]bold[/b]", "boldbolditalicbold"); + $this->assertEqual( + $this->filter("[b]B[/b][i]I[/i][b]B[/b]"), + "BIB"); + $this->assertEqual( + $this->filter("[b]bold[i]bolditalic[/i]bold[/b]"), + "boldbolditalicbold"); } public function testFailure() { - $this->template("[b]bold[i]italic", "[b]bold[i]italic"); + $this->assertEqual( + $this->filter("[b]bold[i]italic"), + "[b]bold[i]italic"); } public function testCode() { - $this->template("[code][b]bold[/b][/code]", "
[b]bold[/b]
"); + $this->assertEqual( + $this->filter("[code][b]bold[/b][/code]"), + "
[b]bold[/b]
"); } public function testNestedList() { - $this->template( - "[list][*]a[list][*]a[*]b[/list][*]b[/list]", + $this->assertEqual( + $this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]"), "
  • a
    • a
    • b
  • b
"); } public function testURL() { - $this->template( - "[url]http://shishnet.org[/url]", + $this->assertEqual( + $this->filter("[url]http://shishnet.org[/url]"), "http://shishnet.org"); - $this->template( - "[url=http://shishnet.org]ShishNet[/url]", + $this->assertEqual( + $this->filter("[url=http://shishnet.org]ShishNet[/url]"), "ShishNet"); - $this->template( - "[url=javascript:alert(\"owned\")]click to fail[/url]", + $this->assertEqual( + $this->filter("[url=javascript:alert(\"owned\")]click to fail[/url]"), "[url=javascript:alert("owned")]click to fail[/url]"); } - private function template($in, $out) { - $bb = new BBCode(); + private function filter($in) { + $bb = new WordFilter(); $tfe = new TextFormattingEvent($in); $bb->receive_event($tfe); - $this->assertEqual($tfe->formatted, $out); + return $tfe->formatted; } } ?>