From cd6015203e7b3d3af5dfa349ee689d0b37f4ad66 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Fri, 30 Jul 2010 22:28:31 +0200 Subject: [PATCH 01/83] replaced deprecated split with explode --- contrib/simpletest/simpletest/http.php | 8 ++++---- contrib/simpletest/simpletest/url.php | 6 +++--- contrib/simpletest/simpletest/web_tester.php | 6 +++--- contrib/word_filter/main.php | 2 +- core/database.class.php | 2 +- core/util.inc.php | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/contrib/simpletest/simpletest/http.php b/contrib/simpletest/simpletest/http.php index e6c6e89d..f20dde92 100644 --- a/contrib/simpletest/simpletest/http.php +++ b/contrib/simpletest/simpletest/http.php @@ -316,7 +316,7 @@ class SimpleHttpHeaders { $this->_cookies = array(); $this->_authentication = false; $this->_realm = false; - foreach (split("\r\n", $headers) as $header_line) { + foreach (explode("\r\n", $headers) as $header_line) { $this->_parseHeaderLine($header_line); } } @@ -457,7 +457,7 @@ class SimpleHttpHeaders { * @access private */ function _parseCookie($cookie_line) { - $parts = split(";", $cookie_line); + $parts = explode(";", $cookie_line); $cookie = array(); preg_match('/\s*(.*?)\s*=(.*)/', array_shift($parts), $cookie); foreach ($parts as $part) { @@ -521,7 +521,7 @@ class SimpleHttpResponse extends SimpleStickyError { $this->_setError('Could not split headers from content'); $this->_headers = &new SimpleHttpHeaders($raw); } else { - list($headers, $this->_content) = split("\r\n\r\n", $raw, 2); + list($headers, $this->_content) = explode("\r\n\r\n", $raw, 2); $this->_headers = &new SimpleHttpHeaders($headers); } } @@ -621,4 +621,4 @@ class SimpleHttpResponse extends SimpleStickyError { return ! $packet; } } -?> \ No newline at end of file +?> diff --git a/contrib/simpletest/simpletest/url.php b/contrib/simpletest/simpletest/url.php index 0ea22040..def0aa40 100644 --- a/contrib/simpletest/simpletest/url.php +++ b/contrib/simpletest/simpletest/url.php @@ -106,7 +106,7 @@ class SimpleUrl { } if (preg_match('/^([^\/]*)@(.*)/', $url, $matches)) { $url = $prefix . $matches[2]; - $parts = split(":", $matches[1]); + $parts = explode(":", $matches[1]); return array( urldecode($parts[0]), isset($parts[1]) ? urldecode($parts[1]) : false); @@ -184,7 +184,7 @@ class SimpleUrl { function _parseRequest($raw) { $this->_raw = $raw; $request = new SimpleGetEncoding(); - foreach (split("&", $raw) as $pair) { + foreach (explode("&", $raw) as $pair) { if (preg_match('/(.*?)=(.*)/', $pair, $matches)) { $request->add($matches[1], urldecode($matches[2])); } elseif ($pair) { @@ -525,4 +525,4 @@ class SimpleUrl { return 'com|edu|net|org|gov|mil|int|biz|info|name|pro|aero|coop|museum'; } } -?> \ No newline at end of file +?> diff --git a/contrib/simpletest/simpletest/web_tester.php b/contrib/simpletest/simpletest/web_tester.php index 40b16129..90544bdb 100644 --- a/contrib/simpletest/simpletest/web_tester.php +++ b/contrib/simpletest/simpletest/web_tester.php @@ -190,7 +190,7 @@ class HttpHeaderExpectation extends SimpleExpectation { * @access protected */ function _findHeader($compare) { - $lines = split("\r\n", $compare); + $lines = explode("\r\n", $compare); foreach ($lines as $line) { if ($this->_testHeaderLine($line)) { return $line; @@ -206,7 +206,7 @@ class HttpHeaderExpectation extends SimpleExpectation { * @access private */ function _testHeaderLine($line) { - if (count($parsed = split(':', $line, 2)) < 2) { + if (count($parsed = explode(':', $line, 2)) < 2) { return false; } list($header, $value) = $parsed; @@ -1538,4 +1538,4 @@ class WebTestCase extends SimpleTestCase { return $trace->traceMethod(); } } -?> \ No newline at end of file +?> diff --git a/contrib/word_filter/main.php b/contrib/word_filter/main.php index 2cfef471..d3c58293 100644 --- a/contrib/word_filter/main.php +++ b/contrib/word_filter/main.php @@ -37,7 +37,7 @@ class WordFilter implements Extension { $lines = explode("\n", $raw); $map = array(); foreach($lines as $line) { - $parts = split(",", $line); + $parts = explode(",", $line); if(count($parts) == 2) { $map[$parts[0]] = $parts[1]; } diff --git a/core/database.class.php b/core/database.class.php index 3e7bcaf3..8dc0f0fa 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -183,7 +183,7 @@ class MemcacheCache implements CacheEngine { var $memcache=null, $hits=0, $misses=0; public function __construct($args) { - $hp = split(":", $args); + $hp = explode(":", $args); if(class_exists("Memcache")) { $this->memcache = new Memcache; @$this->memcache->pconnect($hp[0], $hp[1]); diff --git a/core/util.inc.php b/core/util.inc.php index 64bf3a23..d6848538 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -859,7 +859,7 @@ function _get_page_request() { $args = _get_query_parts(); if(count($args) == 0 || strlen($args[0]) == 0) { - $args = split('/', $config->get_string('front_page')); + $args = explode('/', $config->get_string('front_page')); } return new PageRequestEvent($args); From e9cabb30b3e4b1b07bdfd0a27271ef077c37dbf3 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Fri, 30 Jul 2010 22:28:54 +0200 Subject: [PATCH 02/83] simplified install logic --- install.php | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/install.php b/install.php index 938d8493..e084cf59 100644 --- a/install.php +++ b/install.php @@ -224,19 +224,7 @@ function install_process($database_dsn) { // {{{ header("Location: index.php"); } // }}} function create_tables($dsn) { // {{{ - if(substr($dsn, 0, 5) == "mysql") { - $engine = new MySQL(); - } - else if(substr($dsn, 0, 5) == "pgsql") { - $engine = new PostgreSQL(); - } - else if(substr($dsn, 0, 6) == "sqlite") { - $engine = new SQLite(); - } - else { - die("Unknown database engine; Shimmie currently officially supports MySQL - (mysql://), with hacks for Postgres (pgsql://) and SQLite (sqlite://)"); - } + $engine = select_db_engine($dsn); $db = NewADOConnection($dsn); if(!$db) { @@ -304,19 +292,7 @@ function insert_defaults($dsn) { // {{{ die("Couldn't connect to \"$dsn\""); } else { - if(substr($dsn, 0, 5) == "mysql") { - $engine = new MySQL(); - } - else if(substr($dsn, 0, 5) == "pgsql") { - $engine = new PostgreSQL(); - } - else if(substr($dsn, 0, 6) == "sqlite") { - $engine = new SQLite(); - } - else { - die("Unknown database engine; Shimmie currently officially supports MySQL - (mysql://), with hacks for Postgres (pgsql://) and SQLite (sqlite://)"); - } + $engine = select_db_engine($dsn); $engine->init($db); $config_insert = $db->Prepare("INSERT INTO config(name, value) VALUES(?, ?)"); @@ -332,6 +308,13 @@ function insert_defaults($dsn) { // {{{ $db->Close(); } } // }}} +function select_db_engine($dsn) { // {{{ + if(substr($dsn, 0, 5) == "mysql") return new MySQL(); + if(substr($dsn, 0, 5) == "pgsql") return new PostgreSQL(); + if(substr($dsn, 0, 6) == "sqlite") return new SQLite(); + die("Unknown database engine; Shimmie currently officially supports MySQL + (mysql://), with hacks for Postgres (pgsql://) and SQLite (sqlite://)"); +} // }}} function build_dirs() { // {{{ // *try* and make default dirs. Ignore any errors -- // if something is amiss, we'll tell the user later From e5b3afb31ceb33157db58f56e67a4759d0e57e01 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Fri, 30 Jul 2010 22:48:32 +0200 Subject: [PATCH 03/83] this makes coverage dumping work on windows; on windows the cwd is changed to the apache executable's path by the time the coverage end is reached, changing the coverage end function to a closure that gives back a function with the actual shimmie cwd stored fixes this --- core/util.inc.php | 14 +++++++++----- index.php | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/util.inc.php b/core/util.inc.php index d6848538..4138965d 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -991,11 +991,15 @@ function _start_coverage() { function _end_coverage() { if(function_exists("xdebug_get_code_coverage")) { - if(!file_exists("data/coverage")) mkdir("data/coverage"); - $n = 0; - $t = time(); - while(file_exists("data/coverage/$t.$n.log")) $n++; - file_put_contents("data/coverage/$t.$n.log", serialize(xdebug_get_code_coverage())); + $dir = getcwd(); + $end_cov = function() use ( $dir ) { + if(!file_exists("$dir/data/coverage")) mkdir("$dir/data/coverage"); + $n = 0; + $t = time(); + while(file_exists("$dir/data/coverage/$t.$n.log")) $n++; + file_put_contents("$dir/data/coverage/$t.$n.log", serialize(xdebug_get_code_coverage())); + }; + return $end_cov; } } ?> diff --git a/index.php b/index.php index 15a4e2c0..22137809 100644 --- a/index.php +++ b/index.php @@ -68,7 +68,7 @@ require_once "config.php"; require_once "core/util.inc.php"; if(COVERAGE) { _start_coverage(); - register_shutdown_function("_end_coverage"); + register_shutdown_function(_end_coverage()); } _version_check(); _sanitise_environment(); From 52f5a265fa6f9e517fe533e9e951690b6579a057 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Sat, 31 Jul 2010 17:09:28 +0200 Subject: [PATCH 04/83] changed the windows coverage fix from closure to parameter passing, since older phps can't do that --- core/util.inc.php | 16 ++++++---------- index.php | 3 ++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/core/util.inc.php b/core/util.inc.php index 4138965d..b0f5e935 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -989,17 +989,13 @@ function _start_coverage() { } } -function _end_coverage() { +function _end_coverage( $dir ) { if(function_exists("xdebug_get_code_coverage")) { - $dir = getcwd(); - $end_cov = function() use ( $dir ) { - if(!file_exists("$dir/data/coverage")) mkdir("$dir/data/coverage"); - $n = 0; - $t = time(); - while(file_exists("$dir/data/coverage/$t.$n.log")) $n++; - file_put_contents("$dir/data/coverage/$t.$n.log", serialize(xdebug_get_code_coverage())); - }; - return $end_cov; + if(!file_exists("$dir/data/coverage")) mkdir("$dir/data/coverage"); + $n = 0; + $t = time(); + while(file_exists("$dir/data/coverage/$t.$n.log")) $n++; + file_put_contents("$dir/data/coverage/$t.$n.log", serialize(xdebug_get_code_coverage())); } } ?> diff --git a/index.php b/index.php index 22137809..7e7ce810 100644 --- a/index.php +++ b/index.php @@ -68,7 +68,8 @@ require_once "config.php"; require_once "core/util.inc.php"; if(COVERAGE) { _start_coverage(); - register_shutdown_function(_end_coverage()); + $dir = getcwd(); + register_shutdown_function( "_end_coverage", $dir ); } _version_check(); _sanitise_environment(); From 0396ec5283dea34a5d03fc400687dda3ad3e7ffd Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Thu, 9 Sep 2010 01:35:38 +0200 Subject: [PATCH 05/83] added jquery helper function file --- lib/helpers.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 lib/helpers.js diff --git a/lib/helpers.js b/lib/helpers.js new file mode 100644 index 00000000..0c165e4a --- /dev/null +++ b/lib/helpers.js @@ -0,0 +1,9 @@ +function find_thumb_link_containers () { + + var post_link = "a[href*='/post/view/']"; + var has_thumb_img = ":has(img[src*='/thumb/'])"; + + var list = $( post_link + has_thumb_img ).parent(); + + return list; +} From 49d4f36071a1bdea5ed6adc313a18317e30c08e0 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Sat, 31 Jul 2010 16:41:13 +0200 Subject: [PATCH 06/83] added first version of mass tagger --- .gitignore | 1 + contrib/mass_tagger/main.php | 60 ++++++++++++++++++++++++++ contrib/mass_tagger/mass_tagger.css | 8 ++++ contrib/mass_tagger/mass_tagger.js | 64 ++++++++++++++++++++++++++++ contrib/mass_tagger/theme.php | 28 ++++++++++++ contrib/mass_tagger/toggle.gif | Bin 0 -> 3455 bytes 6 files changed, 161 insertions(+) create mode 100644 contrib/mass_tagger/main.php create mode 100644 contrib/mass_tagger/mass_tagger.css create mode 100644 contrib/mass_tagger/mass_tagger.js create mode 100644 contrib/mass_tagger/theme.php create mode 100644 contrib/mass_tagger/toggle.gif diff --git a/.gitignore b/.gitignore index 182c8212..000cecbd 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ ext/image_hash_ban ext/ipban ext/link_image ext/log_db +ext/mass_tagger ext/news ext/notes ext/notes diff --git a/contrib/mass_tagger/main.php b/contrib/mass_tagger/main.php new file mode 100644 index 00000000..65276e20 --- /dev/null +++ b/contrib/mass_tagger/main.php @@ -0,0 +1,60 @@ + + * License: WTFPL + * Description: Tag a bunch of images at once + * Documentation: + * Once enabled, a new "Mass Tagger" box will appear on the left hand side of + * post listings, with a button to enable the mass tagger. Once clicked JS will + * add buttons to each image to mark them for tagging, and a field for + * inputting tags will appear. Once the "Tag" button is clicked, the tags in + * the text field will be added to marked images. + * + * As of now only compatible with the lite theme. + */ + +class MassTagger extends SimpleExtension { + public function onInitExt($event) { + return; + } + + public function onPostListBuilding($event) { + global $config, $page, $user; + + if( !$user->is_admin() ) return; + + $this->theme->display_mass_tagger( $page, $event, $config ); + } + + public function onPageRequest($event) { + global $config, $page, $user; + if( !$event->page_matches("mass_tagger") ) return; + if( !$user->is_admin() ) return; + + if($event->get_arg(0) == "tag") $this->_apply_mass_tags( $config, $page, $user, $event ); + } + + private function _apply_mass_tags( $config, $page, $user, $event ) { + + if( !isset($_POST['ids']) or !isset($_POST['tag']) ) return; + + $tag = $_POST['tag']; + $ids = explode( ':', $_POST['ids'] ); + $ids = array_filter ( $ids , 'is_numeric' ); + + $ids = array_map( "Image::by_id", $ids ); + + $func = function( $image ) use ( $tag ) { + $tag .= " " . $image->get_tag_list(); + $image->set_tags( $tag ); + }; + array_walk( $ids, $func ); + + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list")); + + } + +} +?> diff --git a/contrib/mass_tagger/mass_tagger.css b/contrib/mass_tagger/mass_tagger.css new file mode 100644 index 00000000..13467ae1 --- /dev/null +++ b/contrib/mass_tagger/mass_tagger.css @@ -0,0 +1,8 @@ + +.zoom{ position:absolute;display:none;margin:-110px 27px; } +.thumbblock:hover .zoom{ display:block; } +.zoom:hover{ border: 3px solid blue; } +/*.zoom img:hover{ background:url(/contrib/simpletest/data/pbx_screenshot.jpg) no-repeat;}*/ + +.zoom img { width: 100px; height: 100px; } +#mass_tagger_controls { display:none; } diff --git a/contrib/mass_tagger/mass_tagger.js b/contrib/mass_tagger/mass_tagger.js new file mode 100644 index 00000000..2461fa8b --- /dev/null +++ b/contrib/mass_tagger/mass_tagger.js @@ -0,0 +1,64 @@ + +function toggle_tag( button, id ) { + id += ":"; + var list = $('#mass_tagger_ids'); + var string = list.val(); + + if( string.indexOf( id ) > -1 ) return remove_mass_tag_id( button, list, id, string ); + + return add_mass_tag_id( button, list, id, string ); +} + +function add_mass_tag_id( button, list, id, string ) { + $(button).attr( 'style', 'display:block;border: 3px solid blue;' ); + string += id; + list.val( string ); + return false; +} + +function remove_mass_tag_id( button, list, id, string ) { + $(button).attr( 'style', '' ); + string = string.replace( id, '' ); + list.val( string ); + return false; +} + +function activate_mass_tagger () { + + $('.thumbblock').each(add_mass_tag_button); + $('#mass_tagger_controls').attr( 'style', 'display:block' ); + $('#mass_tagger_activate').attr( 'style', 'display:none' ); + + return false; +} + +function add_mass_tag_button ( index, block ) { + + var id = get_image_id( block ); + + var button = create_mass_tag_button( id ); + $(block).append( button ); + + return; +} + +function get_image_id ( block ) { + var link = $(block).children(":first").attr('href'); + var id = link.split('/').pop(); + + return id; +} + +function create_mass_tag_button ( id ) { + var img = $(''); + img.attr("src",'/ext/mass_tagger/toggle.gif'); + + var link = $(''); + link.attr("class",'zoom'); + link.attr("onclick",'return toggle_tag( this, "'+id+'")'); + link.attr("href",'#'); + + link.append( img ); + + return link; +} diff --git a/contrib/mass_tagger/theme.php b/contrib/mass_tagger/theme.php new file mode 100644 index 00000000..3d28f344 --- /dev/null +++ b/contrib/mass_tagger/theme.php @@ -0,0 +1,28 @@ +get_string('base_href'); + $page->add_header(""); + $page->add_header(""); + $body = " +
+ +
+ Click on images to mark them. Use the 'Index Options' in the Board Config to increase the amount of shown images. +
+ + + + +
+
+ "; + $block = new Block("Mass Tagger", $body, "left", 50); + $page->add_block( $block ); + } +} +?> diff --git a/contrib/mass_tagger/toggle.gif b/contrib/mass_tagger/toggle.gif new file mode 100644 index 0000000000000000000000000000000000000000..64c3c765f29bb025b1f3e883504848cfbf629b07 GIT binary patch literal 3455 zcmdUx`#;l<;V4?1OoB#@j)OE zetv#IK|vuQAs7q>hr>lgL_|eJkw~PtxHt-hLZi`AQc}{=(lRnK7z{>MR#r|5_+s2aQJa^z`)d^78if z_VMw#di5%uPWSco{rm5~{rvp={rv+10s;dAgM))ZLPEmA!otJDBO)RqBO{}tqN1at zV`5?$3`SyNVsdhFN=nN0>(`k~W?EX>jT<*IGBR%7yqTGqnVp@To12@TpI=y5SX^9O z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31 Jul 2010 18:09:18 +0200 Subject: [PATCH 07/83] mass tagger now loads the correct base directories for its static components --- contrib/mass_tagger/mass_tagger.js | 14 +++++++++----- contrib/mass_tagger/theme.php | 8 ++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/contrib/mass_tagger/mass_tagger.js b/contrib/mass_tagger/mass_tagger.js index 2461fa8b..e13d6a4b 100644 --- a/contrib/mass_tagger/mass_tagger.js +++ b/contrib/mass_tagger/mass_tagger.js @@ -23,20 +23,24 @@ function remove_mass_tag_id( button, list, id, string ) { return false; } -function activate_mass_tagger () { +function activate_mass_tagger ( image_link ) { - $('.thumbblock').each(add_mass_tag_button); + $('.thumbblock').each( + function ( index, block ) { + add_mass_tag_button( block, image_link ); + } + ); $('#mass_tagger_controls').attr( 'style', 'display:block' ); $('#mass_tagger_activate').attr( 'style', 'display:none' ); return false; } -function add_mass_tag_button ( index, block ) { +function add_mass_tag_button ( block, image_link ) { var id = get_image_id( block ); - var button = create_mass_tag_button( id ); + var button = create_mass_tag_button( id, image_link ); $(block).append( button ); return; @@ -51,7 +55,7 @@ function get_image_id ( block ) { function create_mass_tag_button ( id ) { var img = $(''); - img.attr("src",'/ext/mass_tagger/toggle.gif'); + img.attr( "src", image_link+'/ext/mass_tagger/toggle.gif' ); var link = $('
'); link.attr("class",'zoom'); diff --git a/contrib/mass_tagger/theme.php b/contrib/mass_tagger/theme.php index 3d28f344..ff74d6c8 100644 --- a/contrib/mass_tagger/theme.php +++ b/contrib/mass_tagger/theme.php @@ -5,12 +5,12 @@ class MassTaggerTheme extends Themelet { * Show $text on the $page */ public function display_mass_tagger( Page $page, Event $event, $config ) { - $base_href = $config->get_string('base_href'); - $page->add_header(""); - $page->add_header(""); + $data_href = get_base_href(); + $page->add_header(""); + $page->add_header(""); $body = "
- +
Click on images to mark them. Use the 'Index Options' in the Board Config to increase the amount of shown images.
From 02e738d3847b7690cb3730008788121e807b0d19 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Sat, 31 Jul 2010 18:15:40 +0200 Subject: [PATCH 08/83] amended parameter passing --- contrib/mass_tagger/mass_tagger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/mass_tagger/mass_tagger.js b/contrib/mass_tagger/mass_tagger.js index e13d6a4b..2f34fac6 100644 --- a/contrib/mass_tagger/mass_tagger.js +++ b/contrib/mass_tagger/mass_tagger.js @@ -53,7 +53,7 @@ function get_image_id ( block ) { return id; } -function create_mass_tag_button ( id ) { +function create_mass_tag_button ( id, image_link ) { var img = $(''); img.attr( "src", image_link+'/ext/mass_tagger/toggle.gif' ); From 3fdcddcdd052c3a3b60c1d516b6094d5fc2f7617 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Thu, 9 Sep 2010 01:38:24 +0200 Subject: [PATCH 09/83] mass tagger js makes use of new helper function --- contrib/mass_tagger/mass_tagger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/mass_tagger/mass_tagger.js b/contrib/mass_tagger/mass_tagger.js index 2f34fac6..e2ee466e 100644 --- a/contrib/mass_tagger/mass_tagger.js +++ b/contrib/mass_tagger/mass_tagger.js @@ -25,7 +25,7 @@ function remove_mass_tag_id( button, list, id, string ) { function activate_mass_tagger ( image_link ) { - $('.thumbblock').each( + find_thumb_link_containers().each( function ( index, block ) { add_mass_tag_button( block, image_link ); } From d41370d854867f58e44cc845df0b72564cd829b8 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Thu, 9 Sep 2010 02:58:52 +0200 Subject: [PATCH 10/83] renamed mass tagger files so shimmie recognizes them automatically --- contrib/mass_tagger/{mass_tagger.js => script.js} | 0 contrib/mass_tagger/{mass_tagger.css => style.css} | 0 contrib/mass_tagger/theme.php | 4 +--- 3 files changed, 1 insertion(+), 3 deletions(-) rename contrib/mass_tagger/{mass_tagger.js => script.js} (100%) rename contrib/mass_tagger/{mass_tagger.css => style.css} (100%) diff --git a/contrib/mass_tagger/mass_tagger.js b/contrib/mass_tagger/script.js similarity index 100% rename from contrib/mass_tagger/mass_tagger.js rename to contrib/mass_tagger/script.js diff --git a/contrib/mass_tagger/mass_tagger.css b/contrib/mass_tagger/style.css similarity index 100% rename from contrib/mass_tagger/mass_tagger.css rename to contrib/mass_tagger/style.css diff --git a/contrib/mass_tagger/theme.php b/contrib/mass_tagger/theme.php index ff74d6c8..28197b3e 100644 --- a/contrib/mass_tagger/theme.php +++ b/contrib/mass_tagger/theme.php @@ -6,8 +6,6 @@ class MassTaggerTheme extends Themelet { */ public function display_mass_tagger( Page $page, Event $event, $config ) { $data_href = get_base_href(); - $page->add_header(""); - $page->add_header(""); $body = " @@ -16,7 +14,7 @@ class MassTaggerTheme extends Themelet {
- +
From cc6b9753bb7b8276876fc6eedfe5200a2554903e Mon Sep 17 00:00:00 2001 From: zshall Date: Fri, 11 Feb 2011 17:43:18 -0500 Subject: [PATCH 11/83] Added email extension. --- core/email.class.php | 119 +++++++++++++++++++++++++++++++++++++++++++ ext/mail/banner.png | Bin 0 -> 16364 bytes ext/mail/mail.css | 9 ++++ ext/mail/main.php | 45 ++++++++++++++++ 4 files changed, 173 insertions(+) create mode 100644 core/email.class.php create mode 100644 ext/mail/banner.png create mode 100644 ext/mail/mail.css create mode 100644 ext/mail/main.php diff --git a/core/email.class.php b/core/email.class.php new file mode 100644 index 00000000..a3e9f555 --- /dev/null +++ b/core/email.class.php @@ -0,0 +1,119 @@ +to = $to; + + $sub_prefix = $config->get_string("mail_sub"); + + if(!isset($sub_prefix)){ + $this->subject = $subject; + } + else{ + $this->subject = $sub_prefix." ".$subject; + } + + $this->style = $config->get_string("mail_style"); + + $this->header = html_escape($header); + $this->header_img = $config->get_string("mail_img"); + $this->sitename = $config->get_string("site_title"); + $this->sitedomain = make_http(make_link("")); + $this->siteemail = $config->get_string("site_email"); + $this->date = date("F j, Y"); + $this->body = $body; + $this->footer = $config->get_string("mail_fot"); + } + + public function send() { + $headers = "From: ".$this->sitename." <".$this->siteemail.">\r\n"; + $headers .= "Reply-To: ".$this->siteemail."\r\n"; + $headers .= "X-Mailer: PHP/" . phpversion(). "\r\n"; + $headers .= "errors-to: ".$this->siteemail."\r\n"; + $headers .= "Date: " . date(DATE_RFC2822); + $headers .= 'MIME-Version: 1.0' . "\r\n"; + $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; + $message = ' + + + + + + + + + + + +
+ + + + + + + + +
'.$this->sitename.' +
+ + + + + + + + + + +
+ +

+'.$this->header.'
+'.$this->date.'
+

+

'.$this->body.'

+

'.$this->footer.'

+
+ +This email was sent to you since you are a member of '.$this->sitename.'. To change your email preferences, visit your Account preferences.
+ +
+Contact us:
+'.$this->siteemail.'

+Copyright (C) '.$this->sitename.'
+
+ +
+ + + + '; + $sent = mail($this->to, $this->subject, $message, $headers); + if($sent){ + log_info("mail", "Sent message '$this->subject' to '$this->to'"); + } + else{ + log_info("mail", "Error sending message '$this->subject' to '$this->to'"); + } + + return $sent; + } +} +?> \ No newline at end of file diff --git a/ext/mail/banner.png b/ext/mail/banner.png new file mode 100644 index 0000000000000000000000000000000000000000..08303fe5c93b63c4f495cf990ad2898a16e935ba GIT binary patch literal 16364 zcmYjYWmKD8v&G#ViWe{LF2&uUxVuxlI20>Z+}*Vl*Wg;*-6d#)6YN6Y@5lW?NY+Zu zGiPLWhB%fAfRa8-a8_|y}e@VE;+vagZ!!{{TZTWf*APr z0me#9Q49j2E)Mz01orJSqO*+7R|p7X?Ds!Nh>R=(2ndlNSqU)>FT*oGn--FJ_u_2c zzm);*GqI%vw2r&z=snz|zp#g51#-@KfqT-gBXN!b9)i9?zDivl-88_ZNX!ILEFwbF zZevl?_4ZF3Dec+xDcs-fq1^J;Xh;uU`Uc-~WkAB~(;Qjp8 zPYhEHuQC?*_8V*c9PF}JpNvwbe*+#e0et7Xna6%ytJCneeRn-^k}UEAQLDJ(JBKbz zB&9<<*|{?whO}kaC+o+ge{(fZL@*Fwpn`HRycCtCClf+!%&oW3h^ zD=Ub8zJ?B&Q+&zc2lkfI_5K8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FUsZ6+9_Cb`8?l?4W-Gg(PPrCh}h#b!qyz-Kh&nJ z;M-c>Vy@|Od8P=SXG+OeevG4{`Gex=06O5|6bxhW-kMczgA2FY66Bx@t0(roSbqr z=IpF7O569G^&c3Oz`xUsUlf0vl~Wv_Q +* Link: http://seemslegit.com +* License: GPLv2 +* Description: Provides an interface for sending and receiving mail. +*/ + +class Mail extends SimpleExtension { + public function onSetupBuilding($event) { + $sb = new SetupBlock("Mailing Options"); + $sb->add_text_option("mail_sub", "
Subject prefix: "); + $sb->add_text_option("mail_img", "
Banner Image URL: "); + $sb->add_text_option("mail_style", "
Style URL: "); + $sb->add_longtext_option("mail_fot", "
Footer (Use HTML)"); + $sb->add_label("
Should measure 550x110px. Use an absolute URL"); + $event->panel->add_block($sb); + } + + public function onInitExt($event) { + global $config; + $config->set_default_string("mail_sub", $config->get_string("site_title")." - "); + $config->set_default_string("mail_img", make_http("ext/mail/banner.png")); + $config->set_default_string("mail_style", make_http("ext/mail/mail.css")); + $config->set_default_string("mail_fot", "
".$config->get_string("site_title").""); + } +} +class MailTest extends SimpleExtension { + public function onPageRequest($event) { + if($event->page_matches("mail/test")) { + global $page; + $page->set_mode("data"); + echo "Alert: uncomment this page's code on /ext/mail/main.php starting on line 33, and change the email address. Make sure you're using a server with a domain, not localhost."; + /* + echo "Preparing to send message:
"; + echo "created new mail object. sending now... "; + $email = new Email("example@localhost.com", "hello", "hello world", "this is a test message."); + $email->send(); + echo "sent."; + */ + } + } +} +?> \ No newline at end of file From 39778db1b51365b68b1267ac7808c72a689e7e76 Mon Sep 17 00:00:00 2001 From: zshall Date: Fri, 11 Feb 2011 19:02:44 -0500 Subject: [PATCH 12/83] Added admin setting ability back where it belongs in lite and danbooru themes. --- themes/danbooru/user.theme.php | 13 +++++++++++++ themes/lite/user.theme.php | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/themes/danbooru/user.theme.php b/themes/danbooru/user.theme.php index d3e658a4..3e179e09 100644 --- a/themes/danbooru/user.theme.php +++ b/themes/danbooru/user.theme.php @@ -124,6 +124,19 @@ class CustomUserPageTheme extends UserPageTheme {

"; + + if($user->is_admin()) { + $i_user_id = int_escape($duser->id); + $h_is_admin = $duser->is_admin() ? " checked" : ""; + $html .= " +

".make_form(make_link("user_admin/set_more"))." + + Admin: + + + "; + } + return $html; } } diff --git a/themes/lite/user.theme.php b/themes/lite/user.theme.php index 0f102c15..5c1b0be8 100644 --- a/themes/lite/user.theme.php +++ b/themes/lite/user.theme.php @@ -113,6 +113,19 @@ class CustomUserPageTheme extends UserPageTheme { "; + + if($user->is_admin()) { + $i_user_id = int_escape($duser->id); + $h_is_admin = $duser->is_admin() ? " checked" : ""; + $html .= " +

".make_form(make_link("user_admin/set_more"))." + + Admin: + + + "; + } + return $html; } } From 0661f95fbb4771c438e0b3ecbd6d51c2eb3991a6 Mon Sep 17 00:00:00 2001 From: Josh Sutinen Date: Tue, 22 Feb 2011 17:24:00 -0500 Subject: [PATCH 13/83] numeric_score: PDO compatibility --- contrib/numeric_score/main.php | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) mode change 100644 => 100755 contrib/numeric_score/main.php diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php old mode 100644 new mode 100755 index 982b42f0..b24cd014 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -58,7 +58,7 @@ class NumericScore implements Extension { } if($event instanceof ImageDeletionEvent) { - $database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($event->image->id)); + $database->execute("DELETE FROM numeric_score_votes WHERE image_id=:id", array("id" => $event->image->id)); } if($event instanceof ParseLinkTemplateEvent) { @@ -79,8 +79,8 @@ class NumericScore implements Extension { "Can't find the user named ".html_escape($matches[1])); } $event->add_querylet(new Querylet( - "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", - array($duser->id))); + "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=1)", + array("userid" => $duser->id))); } if(preg_match("/^downvoted_by=(.*)$/", $event->term, $matches)) { $duser = User::by_name($matches[1]); @@ -89,20 +89,20 @@ class NumericScore implements Extension { "Can't find the user named ".html_escape($matches[1])); } $event->add_querylet(new Querylet( - "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)", - array($duser->id))); + "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=-1)", + array("userid" => $duser->id))); } if(preg_match("/^upvoted_by_id=(\d+)$/", $event->term, $matches)) { $iid = int_escape($matches[1]); $event->add_querylet(new Querylet( - "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", - array($iid))); + "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=1)", + array("userid" => $iid))); } if(preg_match("/^downvoted_by_id=(\d+)$/", $event->term, $matches)) { $iid = int_escape($matches[1]); $event->add_querylet(new Querylet( - "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)", - array($iid))); + "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:userid AND score=-1)", + array("userid" => $iid))); } } } @@ -112,8 +112,8 @@ class NumericScore implements Extension { global $config; if($config->get_int("ext_numeric_score_version") < 1) { - $database->Execute("ALTER TABLE images ADD COLUMN numeric_score INTEGER NOT NULL DEFAULT 0"); - $database->Execute("CREATE INDEX images__numeric_score ON images(numeric_score)"); + $database->execute("ALTER TABLE images ADD COLUMN numeric_score INTEGER NOT NULL DEFAULT 0"); + $database->execute("CREATE INDEX images__numeric_score ON images(numeric_score)"); $database->create_table("numeric_score_votes", " image_id INTEGER NOT NULL, user_id INTEGER NOT NULL, @@ -126,24 +126,24 @@ class NumericScore implements Extension { $config->set_int("ext_numeric_score_version", 1); } if($config->get_int("ext_numeric_score_version") < 2) { - $database->Execute("CREATE INDEX numeric_score_votes__user_votes ON numeric_score_votes(user_id, score)"); + $database->execute("CREATE INDEX numeric_score_votes__user_votes ON numeric_score_votes(user_id, score)"); $config->set_int("ext_numeric_score_version", 2); } } private function add_vote($image_id, $user_id, $score) { global $database; - $database->Execute( - "DELETE FROM numeric_score_votes WHERE image_id=? AND user_id=?", - array($image_id, $user_id)); + $database->execute( + "DELETE FROM numeric_score_votes WHERE image_id=:imageid AND user_id=:userid", + array("imageid" => $image_id, "userid" => $user_id)); if($score != 0) { - $database->Execute( - "INSERT INTO numeric_score_votes(image_id, user_id, score) VALUES(?, ?, ?)", - array($image_id, $user_id, $score)); + $database->execute( + "INSERT INTO numeric_score_votes(image_id, user_id, score) VALUES(:imageid, :userid, :score)", + array("imageid" => $image_id, "userid" => $user_id, "score" => $score)); } $database->Execute( - "UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=?) WHERE id=?", - array($image_id, $image_id)); + "UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=:imageid) WHERE id=:id", + array("imageid" => $image_id, "id" => $image_id)); } } add_event_listener(new NumericScore()); From f66dd4f089aa429b3309b63bbd428d6827c5f46e Mon Sep 17 00:00:00 2001 From: Josh Sutinen Date: Tue, 22 Feb 2011 17:29:31 -0500 Subject: [PATCH 14/83] pm: PDO compatibility --- contrib/pm/main.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) mode change 100644 => 100755 contrib/pm/main.php diff --git a/contrib/pm/main.php b/contrib/pm/main.php old mode 100644 new mode 100755 index f8599057..e0190f1a --- a/contrib/pm/main.php +++ b/contrib/pm/main.php @@ -93,13 +93,13 @@ class PrivMsg extends SimpleExtension { switch($event->get_arg(0)) { case "read": $pm_id = int_escape($event->get_arg(1)); - $pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id)); + $pm = $database->get_row("SELECT * FROM private_message WHERE id = :id", array("id" => $pm_id)); if(is_null($pm)) { $this->theme->display_error($page, "No such PM", "There is no PM #$pm_id"); } else if(($pm["to_id"] == $user->id) || $user->is_admin()) { $from_user = User::by_id(int_escape($pm["from_id"])); - $database->get_row("UPDATE private_message SET is_read='Y' WHERE id = ?", array($pm_id)); + $database->get_row("UPDATE private_message SET is_read='Y' WHERE id = :id", array("id" => $pm_id)); $this->theme->display_message($page, $from_user, $user, new PM($pm)); } else { @@ -109,12 +109,12 @@ class PrivMsg extends SimpleExtension { case "delete": if($user->check_auth_token()) { $pm_id = int_escape($_POST["pm_id"]); - $pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id)); + $pm = $database->get_row("SELECT * FROM private_message WHERE id = :id", array("id" => $pm_id)); if(is_null($pm)) { $this->theme->display_error($page, "No such PM", "There is no PM #$pm_id"); } else if(($pm["to_id"] == $user->id) || $user->is_admin()) { - $database->execute("DELETE FROM private_message WHERE id = ?", array($pm_id)); + $database->execute("DELETE FROM private_message WHERE id = :id", array("id" => $pm_id)); log_info("pm", "Deleted PM #$pm_id"); $page->set_mode("redirect"); $page->set_redirect($_SERVER["HTTP_REFERER"]); @@ -146,9 +146,9 @@ class PrivMsg extends SimpleExtension { INSERT INTO private_message( from_id, from_ip, to_id, sent_date, subject, message) - VALUES(?, ?, ?, now(), ?, ?)", - array($event->pm->from_id, $event->pm->from_ip, - $event->pm->to_id, $event->pm->subject, $event->pm->message) + VALUES(:fromid, :fromip, :toid, now(), :subject, :message)", + array("fromid" => $event->pm->from_id, "fromip" => $event->pm->from_ip, + "toid" => $event->pm->to_id, "subject" => $event->pm->subject, "message" => $event->pm->message) ); log_info("pm", "Sent PM to User #{$event->pm->to_id}"); } @@ -158,11 +158,11 @@ class PrivMsg extends SimpleExtension { global $database; $arr = $database->get_all(" - SELECT private_message.*,user_from.name AS from_name - FROM private_message - JOIN users AS user_from ON user_from.id=from_id - WHERE to_id = ? - ", array($user->id)); + SELECT private_message.*,user_from.name AS from_name + FROM private_message + JOIN users AS user_from ON user_from.id=from_id + WHERE to_id = :toid", + array("toid" => $user->id)); $pms = array(); foreach($arr as $pm) { $pms[] = new PM($pm); From c89eb46800c931acb9ede8020652e6a44440f63b Mon Sep 17 00:00:00 2001 From: Josh Sutinen Date: Tue, 22 Feb 2011 17:35:07 -0500 Subject: [PATCH 15/83] alias_editor: More PDO compatibility --- ext/alias_editor/main.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) mode change 100644 => 100755 ext/alias_editor/main.php diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php old mode 100644 new mode 100755 index 88e22433..8986ac0b --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -45,7 +45,7 @@ class AliasEditor extends SimpleExtension { else if($event->get_arg(0) == "remove") { if($user->is_admin()) { if(isset($_POST['oldtag'])) { - $database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag'])); + $database->execute("DELETE FROM aliases WHERE oldtag=:oldtag", array("oldtag" => $_POST['oldtag'])); log_info("alias_editor", "Deleted alias for ".$_POST['oldtag']); $page->set_mode("redirect"); @@ -103,12 +103,12 @@ class AliasEditor extends SimpleExtension { public function onAddAlias(AddAliasEvent $event) { global $database; - $pair = array($event->oldtag, $event->newtag); - if($database->get_row("SELECT * FROM aliases WHERE oldtag=? AND lower(newtag)=lower(?)", $pair)) { + $pair = array("oldtag" => $event->oldtag, "newtag" => $event->newtag); + if($database->get_row("SELECT * FROM aliases WHERE oldtag=:oldtag AND lower(newtag)=lower(:newtag)", $pair)) { throw new AddAliasException("That alias already exists"); } else { - $database->Execute("INSERT INTO aliases(oldtag, newtag) VALUES(?, ?)", $pair); + $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", $pair); log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}"); } } @@ -134,7 +134,7 @@ class AliasEditor extends SimpleExtension { foreach(explode("\n", $csv) as $line) { $parts = explode(",", $line); if(count($parts) == 2) { - $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(?, ?)", $parts); + $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", array("oldtag" => $parts[0], "newtag" => $parts[1]); } } } From 9e2522f86ffe05df5dbe57ac14150a40cb7fe59e Mon Sep 17 00:00:00 2001 From: Yaro Date: Tue, 4 Oct 2011 17:03:53 +0400 Subject: [PATCH 16/83] fixed unpredictable working directory inside register_shutdown_function --- core/util.inc.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/util.inc.php b/core/util.inc.php index 7b51be91..e855e673 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -1030,11 +1030,14 @@ function _start_coverage() { function _end_coverage() { if(function_exists("xdebug_get_code_coverage")) { - if(!file_exists("data/coverage")) mkdir("data/coverage"); + // Absolute path is necessary because working directory + // inside register_shutdown_function is unpredictable. + $absolute_path = dirname(dirname(__FILE__)) . "/data/coverage"; + if(!file_exists($absolute_path)) mkdir($absolute_path); $n = 0; $t = time(); - while(file_exists("data/coverage/$t.$n.log")) $n++; - file_put_contents("data/coverage/$t.$n.log", serialize(xdebug_get_code_coverage())); + while(file_exists("$absolute_path/$t.$n.log")) $n++; + file_put_contents("$absolute_path/$t.$n.log", serialize(xdebug_get_code_coverage())); } } ?> From ea15574226bee467a3ce1b92bc2240c3f4e46913 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Wed, 11 Jan 2012 15:08:27 -0500 Subject: [PATCH 17/83] Changes and tweaks for speed. Because every microsecond counts! :P These changes are based on information from: http://phpbench.com/ http://stackoverflow.com/questions/482202/is-there-a-performance-benefit-single-quote-vs-double-quote-in-php --- core/database.class.php | 12 ++++---- core/imageboard.pack.php | 11 ++++--- core/util.inc.php | 66 +++++++++++++++++++++------------------- 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index 53ed4b4d..6e8a0213 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -292,17 +292,17 @@ class Database { $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db_proto = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME); - if($db_proto == "mysql") { + if($db_proto === "mysql") { $this->engine = new MySQL(); } - else if($db_proto == "pgsql") { + else if($db_proto === "pgsql") { $this->engine = new PostgreSQL(); } - else if($db_proto == "sqlite") { + else if($db_proto === "sqlite") { $this->engine = new SQLite(); } else { - die("Unknown PDO driver: $db_proto"); + die('Unknown PDO driver: '.$db_proto); } if(isset($cache_dsn) && !empty($cache_dsn)) { @@ -345,8 +345,8 @@ class Database { return $stmt; } catch(PDOException $pdoe) { - print "Message: ".$pdoe->getMessage(); - print "

Error: $query"; + print 'Message: '.$pdoe->getMessage(); + print '

Error: '.$query; exit; } } diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 5f110f07..d07a571b 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -194,12 +194,12 @@ class Image { } if(count($tags) == 0) { - $row = $database->get_row("SELECT images.* FROM images WHERE images.id $gtlt {$this->id} ORDER BY images.id $dir LIMIT 1"); + $row = $database->get_row('SELECT images.* FROM images WHERE images.id '.$gtlt.' '.$this->id.' ORDER BY images.id '.$dir.' LIMIT 1'); } else { - $tags[] = "id$gtlt{$this->id}"; + $tags[] = 'id'. $gtlt . $this->id; $querylet = Image::build_search_querylet($tags); - $querylet->append_sql(" ORDER BY images.id $dir LIMIT 1"); + $querylet->append_sql(' ORDER BY images.id '.$dir.' LIMIT 1'); $row = $database->get_row($querylet->sql, $querylet->variables); } @@ -229,14 +229,15 @@ class Image { */ public function get_tag_array() { global $database; - $cached = $database->cache->get("image-{$this->id}-tags"); + $tmp = 'image-'.$this->id.'-tags'; + $cached = $database->cache->get($tmp); if($cached) return $cached; if(!isset($this->tag_array)) { $this->tag_array = $database->get_col("SELECT tag FROM image_tags JOIN tags ON image_tags.tag_id = tags.id WHERE image_id=:id ORDER BY tag", array("id"=>$this->id)); } - $database->cache->set("image-{$this->id}-tags", $this->tag_array); + $database->cache->set($tmp, $this->tag_array); return $this->tag_array; } diff --git a/core/util.inc.php b/core/util.inc.php index 25e020f9..27ad46f2 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -21,6 +21,10 @@ function html_escape($input) { * @retval int */ function int_escape($input) { + /* + Side note, Casting to an integer is FASTER than using intval. + http://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/ + */ return (int)$input; } @@ -56,13 +60,13 @@ function sql_escape($input) { function bool_escape($input) { $input = strtolower($input); return ( - $input == "y" || - $input == "yes" || - $input == "t" || - $input == "true" || - $input == "on" || - $input == 1 || - $input == true + $input === "y" || + $input === "yes" || + $input === "t" || + $input === "true" || + $input === "on" || + $input === 1 || + $input === true ); } @@ -86,7 +90,7 @@ function parse_shorthand_int($limit) { return (int)$limit; } - if(preg_match('/^([\d\.]+)([gmk])?b?$/i', "$limit", $m)) { + if(preg_match('/^([\d\.]+)([gmk])?b?$/i', (string)$limit, $m)) { $value = $m[1]; if (isset($m[2])) { switch(strtolower($m[2])) { @@ -118,7 +122,7 @@ function to_shorthand_int($int) { return sprintf("%.1fKB", $int / 1024); } else { - return "$int"; + return (string)$int; } } @@ -131,7 +135,7 @@ function to_shorthand_int($int) { function autodate($date, $html=true) { $cpu = date('c', strtotime($date)); $hum = date('F j, Y', strtotime($date)); - return ($html ? "" : $hum); + return ($html ? '' : $hum); } @@ -182,17 +186,17 @@ function make_link($page=null, $query=null) { } if(is_null($query)) { - return str_replace("//", "/", "$base/$page"); + return str_replace("//", "/", $base.'/'.$page ); } else { if(strpos($base, "?")) { - return "$base/$page&$query"; + return $base .'/'. $page .'&'. $query; } else if(strpos($query, "#") === 0) { - return "$base/$page$query"; + return $base .'/'. $page . $query; } else { - return "$base/$page?$query"; + return $base .'/'. $page .'?'. $query; } } } @@ -261,14 +265,14 @@ function make_http($link) { function make_form($target, $method="POST", $multipart=False, $form_id="", $onsubmit="") { global $user; $auth = $user->get_auth_html(); - $extra = empty($form_id) ? '' : " id='$form_id'"; + $extra = empty($form_id) ? '' : 'id="'. $form_id .'"'; if($multipart) { $extra .= " enctype='multipart/form-data'"; } if($onsubmit) { - $extra .= " onsubmit='$onsubmit'"; + $extra .= ' onsubmit="'.$onsubmit.'"'; } - return "

$auth"; + return ''.$auth; } /** @@ -278,7 +282,7 @@ function make_form($target, $method="POST", $multipart=False, $form_id="", $onsu function theme_file($filepath) { global $config; $theme = $config->get_string("theme","default"); - return make_link("themes/$theme/$filepath"); + return make_link('themes/'.$theme.'/'.$filepath); } @@ -411,12 +415,12 @@ function _count_execs($db, $sql, $inputarray) { */ function get_theme_object(Extension $class, $fatal=true) { $base = get_class($class); - if(class_exists("Custom{$base}Theme")) { - $class = "Custom{$base}Theme"; + if(class_exists('Custom'.$base.'Theme')) { + $class = 'Custom'.$base.'Theme'; return new $class(); } - elseif ($fatal || class_exists("{$base}Theme")) { - $class = "{$base}Theme"; + elseif ($fatal || class_exists($base.'Theme')) { + $class = $base.'Theme'; return new $class(); } else { return false; @@ -517,14 +521,14 @@ function get_base_href() { $possible_vars = array('SCRIPT_NAME', 'PHP_SELF', 'PATH_INFO', 'ORIG_PATH_INFO'); $ok_var = null; foreach($possible_vars as $var) { - if(substr($_SERVER[$var], -4) == '.php') { + if(substr($_SERVER[$var], -4) === '.php') { $ok_var = $_SERVER[$var]; break; } } assert(!empty($ok_var)); $dir = dirname($ok_var); - if($dir == "/" || $dir == "\\") $dir = ""; + if($dir === "/" || $dir === "\\") $dir = ""; return $dir; } @@ -544,10 +548,10 @@ function warehouse_path($base, $hash, $create=true) { $ab = substr($hash, 0, 2); $cd = substr($hash, 2, 2); if(WH_SPLITS == 2) { - $pa = "$base/$ab/$cd/$hash"; + $pa = $base.'/'.$ab.'/'.$cd.'/'.$hash; } else { - $pa = "$base/$ab/$hash"; + $pa = $base.'/'.$ab.'/'.$hash; } if($create && !file_exists(dirname($pa))) mkdir(dirname($pa), 0755, true); return $pa; @@ -949,7 +953,7 @@ function _get_page_request() { global $config; $args = _get_query_parts(); - if(count($args) == 0 || strlen($args[0]) == 0) { + if( empty($args) || strlen($args[0]) === 0) { $args = explode('/', $config->get_string('front_page')); } @@ -1019,7 +1023,7 @@ function _start_cache() { $_cache_hash = md5($_SERVER["QUERY_STRING"]); $ab = substr($_cache_hash, 0, 2); $cd = substr($_cache_hash, 2, 2); - $_cache_filename = "data/$ab/$cd/$_cache_hash"; + $_cache_filename = 'data/'.$ab.'/'.$cd.'/'.$_cache_hash; if(!file_exists(dirname($_cache_filename))) { mkdir(dirname($_cache_filename), 0750, true); @@ -1038,7 +1042,7 @@ function _start_cache() { } else { header("Content-type: text/html"); - header("Last-Modified: $gmdate_mod"); + header('Last-Modified: '.$gmdate_mod); $zdata = @file_get_contents($_cache_filename); if(CACHE_MEMCACHE) { $_cache_memcache->set($_cache_hash, $zdata, 0, 600); @@ -1086,8 +1090,8 @@ function _end_coverage() { if(!file_exists("data/coverage")) mkdir("data/coverage"); $n = 0; $t = time(); - while(file_exists("data/coverage/$t.$n.log")) $n++; - file_put_contents("data/coverage/$t.$n.log", serialize(xdebug_get_code_coverage())); + while(file_exists('data/coverage/'.$t.'.'.$n.'.log')) $n++; + file_put_contents('data/coverage/'.$t.'.'.$n.'.log', serialize(xdebug_get_code_coverage())); } } ?> From 26d383198a39abbdf00d9238802e77160e42c9bb Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Wed, 11 Jan 2012 15:57:00 -0500 Subject: [PATCH 18/83] More small changes for speed. --- core/database.class.php | 14 +++++++------- core/event.class.php | 10 +++++----- core/imageboard.pack.php | 36 +++++++++++++++++++----------------- core/page.class.php | 16 ++++++++-------- core/user.class.php | 12 ++++++------ 5 files changed, 45 insertions(+), 43 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index 6e8a0213..bd97af19 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -56,7 +56,7 @@ class DBEngine { } public function create_table_sql($name, $data) { - return "CREATE TABLE $name ($data)"; + return 'CREATE TABLE '.$name.' ('.$data.')'; } } class MySQL extends DBEngine { @@ -82,7 +82,7 @@ class MySQL extends DBEngine { public function create_table_sql($name, $data) { $data = $this->scoreql_to_sql($data); $ctes = "ENGINE=InnoDB DEFAULT CHARSET='utf8'"; - return "CREATE TABLE $name ($data) $ctes"; + return 'CREATE TABLE '.$name.' ('.$data.') '.$ctes; } } class PostgreSQL extends DBEngine { @@ -103,7 +103,7 @@ class PostgreSQL extends DBEngine { public function create_table_sql($name, $data) { $data = $this->scoreql_to_sql($data); - return "CREATE TABLE $name ($data)"; + return 'CREATE TABLE '.$name.' ('.$data.')'; } } @@ -151,14 +151,14 @@ class SQLite extends DBEngine { $matches = array(); if(preg_match("/INDEX\s*\((.*)\)/", $bit, $matches)) { $col = $matches[1]; - $extras .= "CREATE INDEX {$name}_{$col} on $name($col);"; + $extras .= 'CREATE INDEX '.$name.'_'.$col.' on '.$name($col).';'; } else { $cols[] = $bit; } } $cols_redone = implode(", ", $cols); - return "CREATE TABLE $name ($cols_redone); $extras"; + return 'CREATE TABLE '.$name.' ('.$cols_redone.'); '.$extras; } } // }}} @@ -331,10 +331,10 @@ class Database { if (!array_key_exists(0, $args)) { foreach($args as $name=>$value) { if(is_numeric($value)) { - $stmt->bindValue(":$name", $value, PDO::PARAM_INT); + $stmt->bindValue(':'.$name, $value, PDO::PARAM_INT); } else { - $stmt->bindValue(":$name", $value, PDO::PARAM_STR); + $stmt->bindValue(':'.$name, $value, PDO::PARAM_STR); } } $stmt->execute(); diff --git a/core/event.class.php b/core/event.class.php index 14043de4..69a93175 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -68,7 +68,7 @@ class PageRequestEvent extends Event { } public function count_args() { - return $this->arg_count - $this->part_count; + return (int)($this->arg_count - $this->part_count); } /* @@ -76,20 +76,20 @@ class PageRequestEvent extends Event { */ public function get_search_terms() { $search_terms = array(); - if($this->count_args() == 2) { + if($this->count_args() === 2) { $search_terms = explode(' ', $this->get_arg(0)); } return $search_terms; } public function get_page_number() { $page_number = 1; - if($this->count_args() == 1) { + if($this->count_args() === 1) { $page_number = int_escape($this->get_arg(0)); } - else if($this->count_args() == 2) { + else if($this->count_args() === 2) { $page_number = int_escape($this->get_arg(1)); } - if($page_number == 0) $page_number = 1; // invalid -> 0 + if($page_number === 0) $page_number = 1; // invalid -> 0 return $page_number; } public function get_page_size() { diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index d07a571b..81ac9674 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -514,7 +514,7 @@ class Image { private static function build_search_querylet($terms) { assert(is_array($terms)); global $database; - if($database->engine->name == "mysql") + if($database->engine->name === "mysql") return Image::build_ugly_search_querylet($terms); else return Image::build_accurate_search_querylet($terms); @@ -750,11 +750,13 @@ class Image { foreach($tag_querylets as $tq) { global $tag_n; $sign = $tq->positive ? "+" : "-"; - $sql .= " $sign (tag LIKE :tag$tag_n)"; - $terms["tag$tag_n"] = $tq->tag; + //$sql .= " $sign (tag LIKE :tag$tag_n)"; + $sql .= ' '.$sign.' (tag LIKE :tag'.$tag_n.')'; + //$terms["tag$tag_n"] = $tq->tag; + $terms['tag'.$tag_n] = $tq->tag; $tag_n++; - if($sign == "+") $positive_tag_count++; + if($sign === "+") $positive_tag_count++; else $negative_tag_count++; } $tag_search = new Querylet($sql, $terms); @@ -783,7 +785,7 @@ class Image { } // one positive tag (a common case), do an optimised search - else if($positive_tag_count == 1 && $negative_tag_count == 0) { + else if($positive_tag_count === 1 && $negative_tag_count === 0) { $query = new Querylet( // MySQL is braindead, and does a full table scan on images, running the subquery once for each row -_- // "{$this->get_images} WHERE images.id IN (SELECT image_id FROM tags WHERE tag LIKE ?) ", @@ -819,22 +821,22 @@ class Image { if($tags_ok) { $tag_id_list = join(', ', $tag_id_array); - $subquery = new Querylet(" - SELECT images.*, SUM({$tag_search->sql}) AS score + $subquery = new Querylet(' + SELECT images.*, SUM('.$tag_search->sql.') AS score FROM images LEFT JOIN image_tags ON image_tags.image_id = images.id JOIN tags ON image_tags.tag_id = tags.id - WHERE tags.id IN ({$tag_id_list}) + WHERE tags.id IN ('.$tag_id_list.') GROUP BY images.id - HAVING score = :score", + HAVING score = :score', array_merge( $tag_search->variables, array("score"=>$positive_tag_count) ) ); - $query = new Querylet(" + $query = new Querylet(' SELECT *, UNIX_TIMESTAMP(posted) AS posted_timestamp - FROM ({$subquery->sql}) AS images ", $subquery->variables); + FROM ('.$subquery->sql.') AS images ', $subquery->variables); if(strlen($img_search->sql) > 0) { $query->append_sql(" WHERE "); @@ -882,9 +884,9 @@ class Tag { if(is_string($tags)) { $tags = explode(' ', $tags); } - else if(is_array($tags)) { + //else if(is_array($tags)) { // do nothing - } + //} $tags = array_map("trim", $tags); @@ -907,13 +909,13 @@ class Tag { public static function implode($tags) { assert(is_string($tags) || is_array($tags)); - if(is_string($tags)) { - // do nothing - } - else if(is_array($tags)) { + if(is_array($tags)) { sort($tags); $tags = implode(' ', $tags); } + //else if(is_string($tags)) { + // do nothing + //} return $tags; } diff --git a/core/page.class.php b/core/page.class.php index d382caf2..398fb10d 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -242,22 +242,22 @@ class Page { // caching failed, add all files to html_headers. foreach(glob("lib/*.css") as $css) { - $this->add_html_header(""); + $this->add_html_header(''); } $css_files = glob("ext/*/style.css"); if($css_files) { foreach($css_files as $css_file) { - $this->add_html_header(""); + $this->add_html_header(''); } } foreach(glob("lib/*.js") as $js) { - $this->add_html_header(""); + $this->add_html_header(''); } $js_files = glob("ext/*/script.js"); if($js_files) { foreach($js_files as $js_file) { - $this->add_html_header(""); + $this->add_html_header(''); } } } @@ -362,12 +362,12 @@ class Page { } else { // Caching of CSS disabled. foreach(glob("lib/*.css") as $css) { - $this->add_html_header(""); + $this->add_html_header(''); } $css_files = glob("ext/*/style.css"); if($css_files) { foreach($css_files as $css_file) { - $this->add_html_header(""); + $this->add_html_header(''); } } } @@ -412,12 +412,12 @@ class Page { } else { // Caching of Javascript disabled. foreach(glob("lib/*.js") as $js) { - $this->add_html_header(""); + $this->add_html_header(''); } $js_files = glob("ext/*/script.js"); if($js_files) { foreach($js_files as $js_file) { - $this->add_html_header(""); + $this->add_html_header(''); } } } diff --git a/core/user.class.php b/core/user.class.php index 7352122b..b5779020 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -40,7 +40,7 @@ class User { public static function by_session($name, $session) { global $config, $database; - if($database->engine->name == "mysql") { + if($database->engine->name === "mysql") { $query = "SELECT * FROM users WHERE name = :name AND md5(concat(pass, :ip)) = :sess"; } else { @@ -53,12 +53,12 @@ class User { public static function by_id($id) { assert(is_numeric($id)); global $database; - if($id == 1) { - $cached = $database->cache->get("user-id:$id"); + if($id === 1) { + $cached = $database->cache->get('user-id:'.$id); if($cached) return new User($cached); } $row = $database->get_row("SELECT * FROM users WHERE id = :id", array("id"=>$id)); - if($id == 1) $database->cache->set("user-id:$id", $row, 300); + if($id === 1) $database->cache->set('user-id:'.$id, $row, 300); return is_null($row) ? null : new User($row); } @@ -148,7 +148,7 @@ class User { public function get_avatar_html() { // FIXME: configurable global $config; - if($config->get_string("avatar_host") == "gravatar") { + if($config->get_string("avatar_host") === "gravatar") { if(!empty($this->email)) { $hash = md5(strtolower($this->email)); $s = $config->get_string("avatar_gravatar_size"); @@ -180,7 +180,7 @@ class User { public function get_auth_html() { $at = $this->get_auth_token(); - return ""; + return ''; } public function check_auth_token() { From 2e0e8475a1aee3ea2a1f58a74c38ce75704bd822 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Thu, 12 Jan 2012 14:46:58 -0500 Subject: [PATCH 19/83] A few more small changes for speed. --- core/imageboard.pack.php | 14 +++++++------- core/user.class.php | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 81ac9674..9628b318 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -342,8 +342,8 @@ class Image { */ public function get_mime_type() { $type = strtolower($this->ext); - if($type == "jpg") $type = "jpeg"; - return "image/$type"; + if($type === "jpg") $type = "jpeg"; + return 'image/'.$type; } /** @@ -380,7 +380,7 @@ class Image { public function set_locked($tf) { global $database; $ln = $tf ? "Y" : "N"; - $sln = $database->engine->scoreql_to_sql("SCORE_BOOL_$ln"); + $sln = $database->engine->scoreql_to_sql('SCORE_BOOL_'.$ln); $sln = str_replace("'", "", $sln); $sln = str_replace('"', "", $sln); $database->execute("UPDATE images SET locked=:yn WHERE id=:id", array("yn"=>$sln, "id"=>$this->id)); @@ -442,8 +442,8 @@ class Image { array("tag"=>$tag)); } - log_info("core-image", "Tags for Image #{$this->id} set to: ".implode(" ", $tags)); - $database->cache->delete("image-{$this->id}-tags"); + log_info("core-image", 'Tags for Image #'.$this->id.' set to: '.implode(" ", $tags)); + $database->cache->delete('image-'.$this->id.'-tags'); } /** @@ -453,7 +453,7 @@ class Image { global $database; $this->delete_tags_from_image(); $database->execute("DELETE FROM images WHERE id=:id", array("id"=>$this->id)); - log_info("core-image", "Deleted Image #{$this->id} ({$this->hash})"); + log_info("core-image", 'Deleted Image #'.$this->id.' ('.$this->hash.')'); unlink($this->get_image_filename()); unlink($this->get_thumb_filename()); @@ -464,7 +464,7 @@ class Image { * It DOES NOT remove anything from the database. */ public function remove_image_only() { - log_info("core-image", "Removed Image File ({$this->hash})"); + log_info("core-image", 'Removed Image File ('.$this->hash.')'); @unlink($this->get_image_filename()); @unlink($this->get_thumb_filename()); } diff --git a/core/user.class.php b/core/user.class.php index b5779020..79b8483c 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -98,7 +98,7 @@ class User { */ public function is_anonymous() { global $config; - return ($this->id == $config->get_int('anon_id')); + return ($this->id === $config->get_int('anon_id')); } /** @@ -108,7 +108,7 @@ class User { */ public function is_logged_in() { global $config; - return ($this->id != $config->get_int('anon_id')); + return ($this->id !== $config->get_int('anon_id')); } /** @@ -125,20 +125,20 @@ class User { global $database; $yn = $admin ? 'Y' : 'N'; $database->Execute("UPDATE users SET admin=:yn WHERE id=:id", array("yn"=>$yn, "id"=>$this->id)); - log_info("core-user", "Made {$this->name} admin=$yn"); + log_info("core-user", 'Made '.$this->name.' admin='.$yn); } public function set_password($password) { global $database; $hash = md5(strtolower($this->name) . $password); $database->Execute("UPDATE users SET pass=:hash WHERE id=:id", array("hash"=>$hash, "id"=>$this->id)); - log_info("core-user", "Set password for {$this->name}"); + log_info("core-user", 'Set password for '.$this->name); } public function set_email($address) { global $database; $database->Execute("UPDATE users SET email=:email WHERE id=:id", array("email"=>$address, "id"=>$this->id)); - log_info("core-user", "Set email for {$this->name}"); + log_info("core-user", 'Set email for '.$this->name); } /** From ea6f853891d19f3a539ebe5ace2eeb5d35e7c0cb Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Thu, 12 Jan 2012 14:47:24 -0500 Subject: [PATCH 20/83] Changes to the index file as well. --- index.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index 41e28b47..fb939ed1 100644 --- a/index.php +++ b/index.php @@ -107,22 +107,22 @@ try { ctx_log_start("Loading themelets"); // load the theme parts $_theme = $config->get_string("theme", "default"); - if(!file_exists("themes/$_theme")) $_theme = "default"; - if(file_exists("themes/$_theme/custompage.class.php")) require_once "themes/$_theme/custompage.class.php"; - require_once "themes/$_theme/layout.class.php"; - require_once "themes/$_theme/themelet.class.php"; + if(!file_exists('themes/'.$_theme)) $_theme = "default"; + if(file_exists('themes/'.$_theme.'/custompage.class.php')) require_once 'themes/'.$_theme.'/custompage.class.php'; + require_once 'themes/'.$_theme.'/layout.class.php'; + require_once 'themes/'.$_theme.'/themelet.class.php'; $themelets = glob("ext/*/theme.php"); foreach($themelets as $filename) { require_once $filename; } - $custom_themelets = glob("themes/$_theme/*.theme.php"); + $custom_themelets = glob('themes/'.$_theme.'/*.theme.php'); if($custom_themelets) { $m = array(); foreach($custom_themelets as $filename) { - if(preg_match("/themes\/$_theme\/(.*)\.theme\.php/",$filename,$m) - && in_array("ext/{$m[1]}/theme.php", $themelets)) { + if(preg_match('/themes\/'.$_theme.'\/(.*)\.theme\.php/',$filename,$m) + && in_array('ext/'.$m[1].'/theme.php', $themelets)) { require_once $filename; } } From c739e5b2e84fe835bfff7f638d36410ba51fe813 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Thu, 12 Jan 2012 15:06:32 -0500 Subject: [PATCH 21/83] Silly typo. --- core/page.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/page.class.php b/core/page.class.php index 398fb10d..e813285b 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -417,7 +417,7 @@ class Page { $js_files = glob("ext/*/script.js"); if($js_files) { foreach($js_files as $js_file) { - $this->add_html_header(''); + $this->add_html_header(''); } } } From d7ff1b96abb258d3896fb64090bdfbb0ed137c03 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Thu, 12 Jan 2012 15:13:38 -0500 Subject: [PATCH 22/83] More stupid typos. Gah. --- core/page.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/page.class.php b/core/page.class.php index e813285b..e6be9c33 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -252,12 +252,12 @@ class Page { } foreach(glob("lib/*.js") as $js) { - $this->add_html_header(''); + $this->add_html_header(''); } $js_files = glob("ext/*/script.js"); if($js_files) { foreach($js_files as $js_file) { - $this->add_html_header(''); + $this->add_html_header(''); } } } @@ -358,7 +358,7 @@ class Page { } } // tell the client where to get the css cache file - $this->add_html_header(''); + $this->add_html_header(''); } else { // Caching of CSS disabled. foreach(glob("lib/*.css") as $css) { @@ -408,11 +408,11 @@ class Page { } } // tell the client where to get the js cache file - $this->add_html_header(''); + $this->add_html_header(''); } else { // Caching of Javascript disabled. foreach(glob("lib/*.js") as $js) { - $this->add_html_header(''); + $this->add_html_header(''); } $js_files = glob("ext/*/script.js"); if($js_files) { From fc12bbbfe524cd6808bc3a841b0d64b9f1c7d91f Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Thu, 12 Jan 2012 15:46:34 -0500 Subject: [PATCH 23/83] More small changes to help save a few microseconds. --- core/page.class.php | 4 +-- core/util.inc.php | 2 +- ext/comment/theme.php | 70 +++++++++++++++++++++---------------------- ext/user/theme.php | 66 ++++++++++++++++++++-------------------- 4 files changed, 71 insertions(+), 71 deletions(-) diff --git a/core/page.class.php b/core/page.class.php index e6be9c33..514a1cfd 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -225,8 +225,8 @@ class Page { print $this->data; break; case "redirect": - header("Location: {$this->redirect}"); - print "You should be redirected to {$this->redirect}"; + header('Location: '.$this->redirect); + print 'You should be redirected to '.$this->redirect.''; break; default: print "Invalid page mode"; diff --git a/core/util.inc.php b/core/util.inc.php index 27ad46f2..b8883bb5 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -384,7 +384,7 @@ function _count_execs($db, $sql, $inputarray) { if(DEBUG) { $fp = @fopen("data/sql.log", "a"); if($fp) { - if(is_array($inputarray)) { + if(isset($inputarray) && is_array($inputarray)) { fwrite($fp, preg_replace('/\s+/msi', ' ', $sql)." -- ".join(", ", $inputarray)."\n"); } else { diff --git a/ext/comment/theme.php b/ext/comment/theme.php index 3e2f9138..93936d8b 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -21,12 +21,12 @@ class CommentListTheme extends Themelet { $next = $page_number + 1; $h_prev = ($page_number <= 1) ? "Prev" : - "Prev"; + 'Prev'; $h_index = "Index"; $h_next = ($page_number >= $total_pages) ? "Next" : - "Next"; + 'Next'; - $nav = "$h_prev | $h_index | $h_next"; + $nav = $h_prev.' | '.$h_index.' | '.$h_next; $page->set_title("Comments"); $page->set_heading("Comments"); @@ -46,7 +46,7 @@ class CommentListTheme extends Themelet { $comment_count = count($comments); if($comment_limit > 0 && $comment_count > $comment_limit) { $hidden = $comment_count - $comment_limit; - $comment_html .= "

showing $comment_limit of $comment_count comments

"; + $comment_html .= '

showing '.$comment_limit.' of '.$comment_count.' comments

'; $comments = array_slice($comments, -$comment_limit); } $this->anon_id = 1; @@ -68,14 +68,14 @@ class CommentListTheme extends Themelet { } } - $html = " - - - + $html = ' +
$thumb_html$comment_html
+ +
'.$thumb_html.''.$comment_html.'
- "; + '; - $page->add_block(new Block("{$image->id}: ".($image->get_tag_list()), $html, "main", $position++)); + $page->add_block(new Block( $image->id.': '.$image->get_tag_list(), $html, "main", $position++)); } } @@ -154,23 +154,23 @@ class CommentListTheme extends Themelet { $anoncode = ""; if($h_name == "Anonymous" && $this->anon_id >= 0) { - $anoncode = "{$this->anon_id}"; + $anoncode = ''.$this->anon_id.''; $this->anon_id++; } - $h_userlink = "$h_name$anoncode"; + $h_userlink = ''.$h_name.''.$anoncode; $stripped_nonl = str_replace("\n", "\\n", substr($tfe->stripped, 0, 50)); $stripped_nonl = str_replace("\r", "\\r", $stripped_nonl); $h_dellink = $user->is_admin() ? - "
($h_poster_ip, $h_timestamp, Del)" : ""; + '
('.$h_poster_ip.', '.$h_timestamp.', Del)' : ''; if($trim) { - return " - $h_userlink: $h_comment - >>> - $h_dellink - "; + return ' + '.$h_userlink.': '.$h_comment.' + >>> + '.$h_dellink.' + '; } else { //$avatar = ""; @@ -179,14 +179,14 @@ class CommentListTheme extends Themelet { // $avatar = "
"; //} $oe = ($this->comments_shown++ % 2 == 0) ? "even" : "odd"; - return " - -
- - $h_userlink: $h_comment - $h_dellink + return ' + +
+ + '.$h_userlink.': '.$h_comment.' + '.$h_dellink.'
- "; + '; } } @@ -197,15 +197,15 @@ class CommentListTheme extends Themelet { $hash = CommentList::get_hash(); $captcha = $config->get_bool("comment_captcha") ? captcha_get_html() : ""; - return " - ".make_form(make_link("comment/add"))." - - - - $captcha -
+ return ' + '.make_form(make_link("comment/add")).' + + + + '.$captcha.' +
- "; + '; } } ?> diff --git a/ext/user/theme.php b/ext/user/theme.php index 5f1491e1..3e0fe990 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -30,9 +30,9 @@ class UserPageTheme extends Themelet { public function display_user_block(Page $page, User $user, $parts) { $h_name = html_escape($user->name); - $html = "Logged in as $h_name"; + $html = 'Logged in as '.$h_name; foreach($parts as $part) { - $html .= "
{$part["name"]}"; + $html .= '
'.$part["name"].''; } $page->add_block(new Block("User Links", $html, "left", 90)); } @@ -48,12 +48,12 @@ class UserPageTheme extends Themelet { } if(empty($tac)) {$html = "";} - else {$html = "

$tac

";} + else {$html = '

'.$tac.'

';} $reca = "".captcha_get_html().""; - $html .= " - ".make_form(make_link("user_admin/create"))." + $html .= ' + '.make_form(make_link("user_admin/create"))." @@ -81,8 +81,8 @@ class UserPageTheme extends Themelet { public function display_login_block(Page $page) { global $config; - $html = " - ".make_form(make_link("user_admin/login"))." + $html = ' + '.make_form(make_link("user_admin/login"))."
Name
Password
@@ -107,7 +107,7 @@ class UserPageTheme extends Themelet { $html .= "
Uploaded from: "; $n = 0; foreach($uploads as $ip => $count) { - $html .= "
$ip ($count)"; + $html .= '
'.$ip.' ('.$count.')'; if(++$n >= 20) { $html .= "
..."; break; @@ -117,7 +117,7 @@ class UserPageTheme extends Themelet { $html .= "
Commented from:"; $n = 0; foreach($comments as $ip => $count) { - $html .= "
$ip ($count)"; + $html .= '
'.$ip.' ('.$count.')'; if(++$n >= 20) { $html .= "
..."; break; @@ -133,10 +133,10 @@ class UserPageTheme extends Themelet { public function display_user_page(User $duser, $stats) { global $page, $user; assert(is_array($stats)); - $stats[] = "User ID: {$duser->id}"; + $stats[] = 'User ID: '.$duser->id; - $page->set_title("{$duser->name}'s Page"); - $page->set_heading("{$duser->name}'s Page"); + $page->set_title($duser->name."'s Page"); + $page->set_heading($duser->name."'s Page"); $page->add_block(new NavBlock()); $page->add_block(new Block("Stats", join("
", $stats), "main", 0)); @@ -150,37 +150,37 @@ class UserPageTheme extends Themelet { protected function build_options(User $duser) { global $config, $database, $user; - $html = " - ".make_form(make_link("user_admin/change_pass"))." - - - - - - + $html = ' + '.make_form(make_link("user_admin/change_pass")).' + +
Change Password
Password
Repeat Password
+ + + +
Change Password
Password
Repeat Password
-

".make_form(make_link("user_admin/change_email"))." - - - - - +

'.make_form(make_link("user_admin/change_email")).' + +

Change Email
Address
+ + +
Change Email
Address
- "; + '; if($user->is_admin()) { $i_user_id = int_escape($duser->id); $h_is_admin = $duser->is_admin() ? " checked" : ""; - $html .= " -

".make_form(make_link("user_admin/set_more"))." - - Admin: - + $html .= ' +

'.make_form(make_link("user_admin/set_more")).' + + Admin: + - "; + '; } return $html; } From aa9c8c2097b9e3231ae9a4371b389a20850a734e Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Thu, 12 Jan 2012 20:28:16 -0500 Subject: [PATCH 24/83] Small change to index. --- index.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index fb939ed1..9de7fb73 100644 --- a/index.php +++ b/index.php @@ -159,17 +159,17 @@ catch(Exception $e) { $message = $e->getMessage(); //$trace = var_dump($e->getTrace()); header("HTTP/1.0 500 Internal Error"); - print << - Internal error - SCore-$version + Internal error - SCore-'.$version.'

Internal Error

-

$message +

'.$message.' -EOD; +'; $database->db->rollback(); ctx_log_ender(); } From 3f7646bc8bbb5f4f68eed24184e03596189374a4 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Thu, 12 Jan 2012 20:30:26 -0500 Subject: [PATCH 25/83] typo --- core/page.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/page.class.php b/core/page.class.php index 514a1cfd..2718fcd0 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -226,7 +226,7 @@ class Page { break; case "redirect": header('Location: '.$this->redirect); - print 'You should be redirected to '.$this->redirect.''; + print 'You should be redirected to '.$this->redirect.''; break; default: print "Invalid page mode"; From 2c6b5128c67317cbdb4d503fec7e52a711c572d9 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Thu, 12 Jan 2012 21:17:37 -0500 Subject: [PATCH 26/83] More tweaks for minor speed gains. --- core/imageboard.pack.php | 7 +++++-- ext/index/theme.php | 8 ++++---- themes/default/themelet.class.php | 32 +++++++++++++++---------------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 9628b318..fcd23954 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -284,8 +284,11 @@ class Image { */ public function get_thumb_link() { global $config; - if(strlen($config->get_string('image_tlink')) > 0) { - return $this->parse_link_template($config->get_string('image_tlink')); + + $image_tlink = $config->get_string('image_tlink'); // store a copy for speed. + + if( !empty($image_tlink) ) { /* empty is faster than strlen */ + return $this->parse_link_template($image_tlink); } else if($config->get_bool('nice_urls', false)) { return $this->parse_link_template(make_link('_thumbs/$hash/thumb.jpg')); diff --git a/ext/index/theme.php b/ext/index/theme.php index 56775736..2263d3db 100644 --- a/ext/index/theme.php +++ b/ext/index/theme.php @@ -69,12 +69,12 @@ EOD; $next = $page_number + 1; $u_tags = url_escape(implode(" ", $search_terms)); - $query = empty($u_tags) ? "" : "/$u_tags"; + $query = empty($u_tags) ? "" : '/'.$u_tags; - $h_prev = ($page_number <= 1) ? "Prev" : "Prev"; + $h_prev = ($page_number <= 1) ? "Prev" : 'Prev'; $h_index = "Index"; - $h_next = ($page_number >= $total_pages) ? "Next" : "Next"; + $h_next = ($page_number >= $total_pages) ? "Next" : 'Next'; $h_search_string = html_escape(implode(" ", $search_terms)); $h_search_link = make_link(); @@ -102,7 +102,7 @@ EOD;

"; - return "$h_prev | $h_index | $h_next
$h_search"; + return $h_prev.' | '.$h_index.' | '.$h_next.'
'.$h_search; } protected function build_table($images, $query) { diff --git a/themes/default/themelet.class.php b/themes/default/themelet.class.php index 08b4b694..27a6a280 100644 --- a/themes/default/themelet.class.php +++ b/themes/default/themelet.class.php @@ -29,13 +29,13 @@ class Themelet { */ public function build_thumb_html(Image $image, $query=null) { global $config; - $i_id = int_escape($image->id); - $h_view_link = make_link("post/view/$i_id", $query); + $i_id = (int) $image->id; + $h_view_link = make_link('post/view/'.$i_id, $query); $h_thumb_link = $image->get_thumb_link(); // Removes the size tag if the file is an mp3 - if($image->ext == 'mp3'){ + if($image->ext === 'mp3'){ $iitip = $image->get_tooltip(); $mp3tip = array("0x0"); $h_tip = str_replace($mp3tip, " ", $iitip); @@ -45,29 +45,29 @@ class Themelet { if(strstr($h_tip, " ")){ $h_tip = html_escape(str_replace($justincase, "", $h_tip)); }else{ - $h_tip = html_escape($h_tip); + $h_tip = html_escape($h_tip); } }else{ - $h_tip = html_escape($image->get_tooltip()); + $h_tip = html_escape($image->get_tooltip()); } // If file is flash or svg then sets thumbnail to max size. - if($image->ext == 'swf' || $image->ext == 'svg'){ + if($image->ext === 'swf' || $image->ext === 'svg'){ $tsize = get_thumbnail_size($config->get_int('thumb_width'), $config->get_int('thumb_height')); } else{ $tsize = get_thumbnail_size($image->width, $image->height); } - return " + return ' -
-
- - $h_tip + - "; + '; } @@ -81,8 +81,8 @@ class Themelet { } private function gen_page_link($base_url, $query, $page, $name) { - $link = make_link("$base_url/$page", $query); - return "$name"; + $link = make_link($base_url.'/'.$page, $query); + return ''.$name.''; } private function gen_page_link_block($base_url, $query, $page, $current_page, $name) { @@ -116,8 +116,8 @@ class Themelet { } $pages_html = implode(" | ", $pages); - return "

$first_html | $prev_html | $random_html | $next_html | $last_html". - "
<< $pages_html >>

"; + return '

'.$first_html.' | '.$prev_html.' | '.$random_html.' | '.$next_html.' | '.$last_html + .'
<< '.$pages_html.' >>

'; } } ?> From 7195d3d1f3fd418b21ca19f7b4a84335cb9205d7 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Thu, 12 Jan 2012 23:07:14 -0500 Subject: [PATCH 27/83] Changes using empty instead of strlen. --- core/imageboard.pack.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index fcd23954..c6f8048c 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -255,8 +255,11 @@ class Image { */ public function get_image_link() { global $config; - if(strlen($config->get_string('image_ilink')) > 0) { - return $this->parse_link_template($config->get_string('image_ilink')); + + $image_ilink = $config->get_string('image_ilink'); // store a copy for speed. + + if( !empty($image_ilink) ) { /* empty is faster than strlen */ + return $this->parse_link_template($image_ilink); } else if($config->get_bool('nice_urls', false)) { return $this->parse_link_template(make_link('_images/$hash/$id - $tags.$ext')); @@ -560,7 +563,7 @@ class Image { // various types of querylet foreach($terms as $term) { $positive = true; - if((strlen($term) > 0) && ($term[0] == '-')) { + if( is_string($term) && !empty($term) && ($term[0] == '-')) { $positive = false; $term = substr($term, 1); } @@ -605,7 +608,7 @@ class Image { if(count($tag_querylets) == 0) { $query = new Querylet("SELECT images.* FROM images "); - if(strlen($img_search->sql) > 0) { + if(!empty($img_search->sql)) { $query->append_sql(" WHERE "); $query->append($img_search); } @@ -622,7 +625,7 @@ class Image { ) "), array("tag"=>$tag_querylets[0]->tag)); - if(strlen($img_search->sql) > 0) { + if(!empty($img_search->sql)) { $query->append_sql(" AND "); $query->append($img_search); } @@ -724,7 +727,7 @@ class Image { // turn each term into a specific type of querylet foreach($terms as $term) { $negative = false; - if((strlen($term) > 0) && ($term[0] == '-')) { + if( !empty($term) && ($term[0] == '-')) { $negative = true; $term = substr($term, 1); } @@ -781,7 +784,7 @@ class Image { if($positive_tag_count + $negative_tag_count == 0) { $query = new Querylet("SELECT images.*,UNIX_TIMESTAMP(posted) AS posted_timestamp FROM images "); - if(strlen($img_search->sql) > 0) { + if(!empty($img_search->sql)) { $query->append_sql(" WHERE "); $query->append($img_search); } @@ -802,7 +805,7 @@ class Image { ", $tag_search->variables); - if(strlen($img_search->sql) > 0) { + if(!empty($img_search->sql)) { $query->append_sql(" AND "); $query->append($img_search); } @@ -841,7 +844,7 @@ class Image { SELECT *, UNIX_TIMESTAMP(posted) AS posted_timestamp FROM ('.$subquery->sql.') AS images ', $subquery->variables); - if(strlen($img_search->sql) > 0) { + if(!empty($img_search->sql)) { $query->append_sql(" WHERE "); $query->append($img_search); } @@ -895,7 +898,7 @@ class Tag { $tag_array = array(); foreach($tags as $tag) { - if(is_string($tag) && strlen($tag) > 0) { + if(is_string($tag) && !empty($tag)) { $tag_array[] = $tag; } } From daf51d54771e2d2e56383d0c0cb527f396b21406 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Sun, 15 Jan 2012 11:57:32 -0500 Subject: [PATCH 28/83] Feature to Revert Tag changes by IP address. Allows you to revert all edits made by a specific ip during a specified timeframe. --- contrib/tag_history/main.php | 134 ++++++++++++++++++++++++++++++---- contrib/tag_history/theme.php | 69 ++++++++++++++--- core/util.inc.php | 32 ++++++++ 3 files changed, 209 insertions(+), 26 deletions(-) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index ce2b9249..fcb23d8e 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -1,8 +1,8 @@ - * Description: Keep a record of tag changes + * Author: Bzchan , modified by jgen + * Description: Keep a record of tag changes, and allows you to revert changes. */ class Tag_History implements Extension { @@ -20,8 +20,44 @@ class Tag_History implements Extension { $this->install(); } } - - if(($event instanceof PageRequestEvent) && $event->page_matches("tag_history")) + + if(($event instanceof AdminBuildingEvent)) + { + if(isset($_POST['revert_ip']) && $user->is_admin() && $user->check_auth_token()) + { + $revert_ip = filter_var($_POST['revert_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE); + + if ($revert_ip === false) { + // invalid ip given. + $this->theme->display_admin_block('Invalid IP'); + return; + } + + if (isset($_POST['revert_date']) && !empty($_POST['revert_date'])) { + if (isValidDate($_POST['revert_date'])){ + $revert_date = addslashes($_POST['revert_date']); // addslashes is really unnecessary since we just checked if valid, but better safe. + } else { + $this->theme->display_admin_block('Invalid Date'); + return; + } + } else { + $revert_date = null; + } + + set_time_limit(0); // reverting changes can take a long time, disable php's timelimit if possible. + + // Call the revert function. + $this->process_revert_all_changes_by_ip($revert_ip, $revert_date); + // output results + $this->theme->display_revert_ip_results(); + } + else + { + $this->theme->display_admin_block(); // add a block to the admin panel + } + } + + if (($event instanceof PageRequestEvent) && ($event->page_matches("tag_history"))) { if($event->get_arg(0) == "revert") { @@ -40,6 +76,7 @@ class Tag_History implements Extension { $this->theme->display_global_page($page, $this->get_global_tag_history()); } } + if(($event instanceof DisplayingImageEvent)) { // handle displaying a link on the view page @@ -107,7 +144,7 @@ class Tag_History implements Extension { { global $page; // check for the nothing case - if($revert_id=="nothing") + if(empty($revert_id) || $revert_id=="nothing") { // tried to set it too the same thing so ignore it (might be a bot) // go back to the index page with you @@ -121,7 +158,7 @@ class Tag_History implements Extension { // lets get this revert id assuming it exists $result = $this->get_tag_history_from_revert($revert_id); - if($result==null) + if(empty($result)) { // there is no history entry with that id so either the image was deleted // while the user was viewing the history, someone is playing with form @@ -135,13 +172,43 @@ class Tag_History implements Extension { $stored_image_id = $result['image_id']; $stored_tags = $result['tags']; - log_debug("tag_history", "Reverting tags of $stored_image_id to [$stored_tags]"); + log_debug("tag_history", 'Reverting tags of Image #'.$stored_image_id.' to ['.$stored_tags.']'); // all should be ok so we can revert by firing the SetUserTags event. send_event(new TagSetEvent(Image::by_id($stored_image_id), $stored_tags)); // all should be done now so redirect the user back to the image $page->set_mode("redirect"); - $page->set_redirect(make_link("post/view/$stored_image_id")); + $page->set_redirect(make_link('post/view/'.$stored_image_id)); + } + + /* + * This function is used by process_revert_all_changes_by_ip() + * to just revert an image's tag history. + */ + private function process_revert_request_only($revert_id) + { + if(empty($revert_id)) { + return; + } + $id = (int) $revert_id; + $result = $this->get_tag_history_from_revert($id); + + if(empty($result)) { + // there is no history entry with that id so either the image was deleted + // while the user was viewing the history, or something messed up + /* calling die() is probably not a good idea, we should throw an Exception */ + die('Error: No tag history with specified id ('.$id.') was found in the database.'."\n\n". + 'Perhaps the image was deleted while processing this request.'); + } + + // lets get the values out of the result + $stored_result_id = $result['id']; + $stored_image_id = $result['image_id']; + $stored_tags = $result['tags']; + + log_debug("tag_history", 'Reverting tags of Image #'.$stored_image_id.' to ['.$stored_tags.']'); + // all should be ok so we can revert by firing the SetUserTags event. + send_event(new TagSetEvent(Image::by_id($stored_image_id), $stored_tags)); } public function get_tag_history_from_revert($revert_id) @@ -192,16 +259,54 @@ class Tag_History implements Extension { return ($row ? $row : array()); } - public function process_revert_all_changes_by_ip($ip) + /* + * This function attempts to revert all changes by a given IP within an (optional) timeframe. + */ + public function process_revert_all_changes_by_ip($ip, $date=null) { global $database; - /* + $date_select = ''; -SELECT * FROM `tag_histories` WHERE image_id IN -( select image_id from `tag_histories` where user_ip="216.240.14.185" and date_set >= 2011-10-23) -ORDER BY image_id, date_set + if (!empty($date)) { + $date_select = 'and date_set >= '.$date; + } else { + $date = 'forever'; + } - */ + log_info("tag_history", 'Attempting to revert edits by ip='.$ip.' (from '.$date.' to now).'); + + // Get all the images that the given IP has changed tags on (within the timeframe) that were last editied by the given IP + $result = $database->get_all(' + SELECT t1.image_id FROM tag_histories t1 LEFT JOIN tag_histories t2 + ON (t1.image_id = t2.image_id AND t1.date_set < t2.date_set) + WHERE t2.image_id IS NULL AND t1.user_ip="'.$ip.'" AND t1.image_id IN + ( select image_id from `tag_histories` where user_ip="'.$ip.'" '.$date_select.') + ORDER BY t1.image_id;'); + + if (empty($result)) { + log_info("tag_history", 'Nothing to revert! for ip='.$ip.' (from '.$date.' to now).'); + $this->theme->add_status('Nothing to Revert','Nothing to revert for ip='.$ip.' (from '.$date.' to now)'); + return; // nothing to do. + } + + for ($i = 0 ; $i < count($result) ; $i++) + { + $image_id = (int) $result[$i]['image_id']; + + // Get the first tag history that was done before the given IP edit + $row = $database->get_row(' + SELECT id,tags FROM `tag_histories` WHERE image_id="'.$image_id.'" AND user_ip!="'.$ip.'" '.$date_select.' ORDER BY date_set DESC LIMIT 1'); + + if (empty($row)) { + // we can not revert this image based on the date restriction. + // Output a message perhaps? + } else { + $id = (int) $row['id']; + $this->process_revert_request_only($id); + $this->theme->add_status('Reverted Change','Reverted Image #'.$image_id.' to Tag History #'.$id.' ('.$row['tags'].')'); + } + } + log_info("tag_history", 'Reverted '.count($result).' edits by ip='.$ip.' (from '.$date.' to now).'); } /* @@ -232,6 +337,7 @@ ORDER BY image_id, date_set // if the image has no history, make one with the old tags $entries = $database->get_one("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id)); if($entries == 0){ + /* these two queries could probably be combined */ $database->execute(" INSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set) VALUES (?, ?, ?, ?, now())", diff --git a/contrib/tag_history/theme.php b/contrib/tag_history/theme.php index 46ed3564..842ed8bd 100644 --- a/contrib/tag_history/theme.php +++ b/contrib/tag_history/theme.php @@ -1,6 +1,12 @@ , modified by jgen + */ class Tag_HistoryTheme extends Themelet { + var $messages = array(); + public function display_history_page(Page $page, $image_id, $history) { global $user; $start_string = " @@ -22,11 +28,12 @@ class Tag_HistoryTheme extends Themelet { $setter .= " / " . $fields['user_ip']; } $selected = ($n == 2) ? " checked" : ""; - $history_list .= " + $history_list .= '
  • - - -
  • \n"; + + + + '; } $end_string = " @@ -37,8 +44,8 @@ class Tag_HistoryTheme extends Themelet { "; $history_html = $start_string . $history_list . $end_string; - $page->set_title("Image $image_id Tag History"); - $page->set_heading("Tag History: $image_id"); + $page->set_title('Image '.$image_id.' Tag History'); + $page->set_heading('Tag History: '.$image_id); $page->add_block(new NavBlock()); $page->add_block(new Block("Tag History", $history_html, "main", 10)); } @@ -68,13 +75,13 @@ class Tag_HistoryTheme extends Themelet { if($user->is_admin()) { $setter .= " / " . $fields['user_ip']; } - $history_list .= " + $history_list .= '
  • - - $image_id: - $current_tags (Set by $setter) + + '.$image_id.': + '.$current_tags.' (Set by '.$setter.')
  • - "; + '; } $history_html = $start_string . $history_list . $end_string; @@ -85,8 +92,46 @@ class Tag_HistoryTheme extends Themelet { } public function display_history_link(Page $page, $image_id) { - $link = "Tag History\n"; + $link = 'Tag History'; $page->add_block(new Block(null, $link, "main", 5)); } + + /* + * Add a section to the admin page. + */ + public function display_admin_block($validation_msg='') { + global $page; + + if (!empty($validation_msg)) { + $validation_msg = '
    '. $validation_msg .''; + } + + $html = ' + Revert tag changes/edit by a specific IP address.
    + You can restrict the time frame to revert these edits as well. +
    (Date format: 2011-10-23) + '.$validation_msg.' + +

    '.make_form(make_link("admin/revert_ip"),'POST',false,'revert_ip_form')." + IP Address:
    + Date range:

    + +
    + "; + $page->add_block(new Block("Revert By IP", $html)); + } + + /* + * Show a standard page for results to be put into + */ + public function display_revert_ip_results() { + global $page; + $html = implode($this->messages, "\n"); + $page->add_block(new Block("Revert by IP", $html)); + } + + public function add_status($title, $body) { + $this->messages[] = '

    '. $title .'
    '. $body .'

    '; + } } ?> diff --git a/core/util.inc.php b/core/util.inc.php index 25e020f9..97146d25 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -134,6 +134,38 @@ function autodate($date, $html=true) { return ($html ? "" : $hum); } +/** + * Check if a given string is a valid date-time. ( Format: yyyy-mm-dd hh:mm:ss ) + * + * @retval boolean + */ +function isValidDateTime($dateTime) +{ + if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) { + if (checkdate($matches[2], $matches[3], $matches[1])) { + return true; + } + } + + return false; +} + +/** + * Check if a given string is a valid date. ( Format: yyyy-mm-dd ) + * + * @retval boolean + */ +function isValidDate($date) +{ + if (preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $date, $matches)) { + // checkdate wants (month, day, year) + if (checkdate($matches[2], $matches[3], $matches[1])) { + return true; + } + } + + return false; +} /** * Return a pluraliser if necessary From 8252534cff10c3f8fc03733263487b606a12dba1 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Sun, 15 Jan 2012 23:03:27 -0500 Subject: [PATCH 29/83] Small changes with quotes. --- ext/index/main.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/ext/index/main.php b/ext/index/main.php index 5bf46d98..5e2dc5cd 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -147,7 +147,7 @@ class Index extends SimpleExtension { } else { $page->set_mode("redirect"); - $page->set_redirect(make_link("post/list/$search/1")); + $page->set_redirect(make_link('post/list/'.$search.'/1')); } return; } @@ -171,7 +171,7 @@ class Index extends SimpleExtension { } else if(count($search_terms) > 0 && count($images) == 1 && $page_number == 1) { $page->set_mode("redirect"); - $page->set_redirect(make_link("post/view/{$images[0]->id}")); + $page->set_redirect(make_link('post/view/'.$images[0]->id)); } else { send_event(new PostListBuildingEvent($search_terms)); @@ -197,15 +197,16 @@ class Index extends SimpleExtension { public function onSearchTermParse($event) { $matches = array(); - if(preg_match("/^size(<|>|<=|>=|=)(\d+)x(\d+)$/", $event->term, $matches)) { + // check for tags first as tag based searches are more common. + if(preg_match("/tags(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) { $cmp = $matches[1]; - $args = array("width"=>int_escape($matches[2]), "height"=>int_escape($matches[3])); - $event->add_querylet(new Querylet("width $cmp :width AND height $cmp :height", $args)); + $tags = $matches[2]; + $event->add_querylet(new Querylet('images.id IN (SELECT DISTINCT image_id FROM image_tags GROUP BY image_id HAVING count(image_id) '.$cmp.' '.$tags.')')); } else if(preg_match("/^ratio(<|>|<=|>=|=)(\d+):(\d+)$/", $event->term, $matches)) { $cmp = $matches[1]; $args = array("width"=>int_escape($matches[2]), "height"=>int_escape($matches[3])); - $event->add_querylet(new Querylet("width / height $cmp :width / :height", $args)); + $event->add_querylet(new Querylet('width / height '.$cmp.' :width / :height', $args)); } else if(preg_match("/^(filesize|id)(<|>|<=|>=|=)(\d+[kmg]?b?)$/i", $event->term, $matches)) { $col = $matches[1]; @@ -215,24 +216,24 @@ class Index extends SimpleExtension { } else if(preg_match("/^(hash|md5)=([0-9a-fA-F]*)$/i", $event->term, $matches)) { $hash = strtolower($matches[2]); - $event->add_querylet(new Querylet("images.hash = '$hash'")); + $event->add_querylet(new Querylet('images.hash = "'.$hash.'"')); } else if(preg_match("/^(filetype|ext)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) { $ext = strtolower($matches[2]); - $event->add_querylet(new Querylet("images.ext = '$ext'")); + $event->add_querylet(new Querylet('images.ext = "'.$ext.'"')); } else if(preg_match("/^(filename|name)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) { $filename = strtolower($matches[2]); - $event->add_querylet(new Querylet("images.filename LIKE '%$filename%'")); + $event->add_querylet(new Querylet('images.filename LIKE "%'.$filename.'%"')); } else if(preg_match("/^posted=(([0-9\*]*)?(-[0-9\*]*)?(-[0-9\*]*)?)$/", $event->term, $matches)) { $val = str_replace("*", "%", $matches[1]); - $event->add_querylet(new Querylet("images.posted LIKE '%$val%'")); + $event->add_querylet(new Querylet('images.posted LIKE "%'.$val.'%"')); } - else if(preg_match("/tags(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) { + else if(preg_match("/^size(<|>|<=|>=|=)(\d+)x(\d+)$/", $event->term, $matches)) { $cmp = $matches[1]; - $tags = $matches[2]; - $event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM image_tags GROUP BY image_id HAVING count(image_id) $cmp $tags)")); + $args = array("width"=>int_escape($matches[2]), "height"=>int_escape($matches[3])); + $event->add_querylet(new Querylet('width '.$cmp.' :width AND height '.$cmp.' :height', $args)); } } } From cd7de93a0aa040f377aa4bd515cb9335ecfca85b Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Mon, 16 Jan 2012 00:07:04 -0500 Subject: [PATCH 30/83] Changing for-loops to use pre-calculated values. Rather than calculating the value each time. --- contrib/artists/main.php | 14 ++++++++++---- contrib/blotter/theme.php | 13 ++++++++----- contrib/handle_flash/main.php | 3 ++- contrib/home/main.php | 3 ++- contrib/rating/main.php | 6 ++++-- core/util.inc.php | 3 ++- ext/comment/main.php | 10 +++++----- ext/ext_manager/main.php | 3 ++- ext/upload/theme.php | 8 ++++++-- lib/securimage/securimage.php | 4 +++- 10 files changed, 44 insertions(+), 23 deletions(-) diff --git a/contrib/artists/main.php b/contrib/artists/main.php index f035224a..9f057bc6 100644 --- a/contrib/artists/main.php +++ b/contrib/artists/main.php @@ -904,8 +904,10 @@ class Artists implements Extension { , array( $artistID )); - - for ($i = 0 ; $i < count($result) ; $i++) + + $num = count($result); + + for ($i = 0 ; $i < $num ; $i++) { $result[$i]["name"] = stripslashes($result[$i]["name"]); } @@ -921,8 +923,10 @@ class Artists implements Extension { , array( $artistID )); + + $num = count($result); - for ($i = 0 ; $i < count($result) ; $i++) + for ($i = 0 ; $i < $num ; $i++) { $result[$i]["url"] = stripslashes($result[$i]["url"]); } @@ -1038,8 +1042,10 @@ class Artists implements Extension { $pageNumber * $artistsPerPage , $artistsPerPage )); + + $number_of_listings = count($listing); - for ($i = 0 ; $i < count($listing) ; $i++) + for ($i = 0 ; $i < $number_of_listings ; $i++) { $listing[$i]["name"] = stripslashes($listing[$i]["name"]); $listing[$i]["user_name"] = stripslashes($listing[$i]["user_name"]); diff --git a/contrib/blotter/theme.php b/contrib/blotter/theme.php index e8d82860..fd78b467 100644 --- a/contrib/blotter/theme.php +++ b/contrib/blotter/theme.php @@ -55,7 +55,8 @@ class BlotterTheme extends Themelet { // Now, time for entries list. $table_rows = ""; - for ($i = 0 ; $i < count($entries) ; $i++) + $num_entries = count($entries); + for ($i = 0 ; $i < $num_entries ; $i++) { /** * Add table rows @@ -106,7 +107,8 @@ class BlotterTheme extends Themelet { $html .= "Blotter
    ";
     
    -		for ($i = 0 ; $i < count($entries) ; $i++)
    +		$num_entries = count($entries);
    +		for ($i = 0 ; $i < $num_entries ; $i++)
     		{
     			/**
     			 * Blotter entries
    @@ -156,7 +158,8 @@ $(document).ready(function() {
     });
     //-->";
     		$entries_list = "";
    -		for ($i = 0 ; $i < count($entries) ; $i++)
    +		$num_entries = count($entries);
    +		for ($i = 0 ; $i < $num_entries ; $i++)
     		{
     			/**
     			 * Blotter entries
    @@ -175,8 +178,8 @@ $(document).ready(function() {
     		$in_text = "";
     		$pos_break = "";
     		$pos_align = "text-align: right; position: absolute; right: 0px;";
    -		if($position == "left") { $pos_break = "
    "; $pos_align = ""; } - if(count($entries) == 0) { $out_text = "No blotter entries yet."; $in_text = "Empty.";} + if($position === "left") { $pos_break = "
    "; $pos_align = ""; } + if(count($entries) === 0) { $out_text = "No blotter entries yet."; $in_text = "Empty.";} else { $clean_date = date("m/d/y",strtotime($entries[0]['entry_date'])); $out_text = "Blotter updated: {$clean_date}"; $in_text = "
      $entries_list
    "; diff --git a/contrib/handle_flash/main.php b/contrib/handle_flash/main.php index 8ee32fc0..eec6b1c1 100644 --- a/contrib/handle_flash/main.php +++ b/contrib/handle_flash/main.php @@ -56,7 +56,8 @@ class FlashFileHandler extends DataHandlerExtension { private function str_to_binarray($string) { $binary = array(); - for($j=0; $j=0; $i--) { $binary[] = ($c >> $i) & 0x01; diff --git a/contrib/home/main.php b/contrib/home/main.php index f46c6238..855bc0ab 100644 --- a/contrib/home/main.php +++ b/contrib/home/main.php @@ -69,7 +69,8 @@ class Home extends SimpleExtension { $num_comma = number_format($total); $counter_text = ""; - for($n=0; $nterm, $matches)) { $sqes = $matches[1]; $arr = array(); - for($i=0; $ipage_matches("comment")) { - if($event->get_arg(0) == "add") { + if($event->get_arg(0) === "add") { if(isset($_POST['image_id']) && isset($_POST['comment'])) { try { $cpe = new CommentPostingEvent($_POST['image_id'], $user, $_POST['comment']); @@ -127,10 +127,10 @@ class CommentList extends SimpleExtension { } } } - else if($event->get_arg(0) == "delete") { + else if($event->get_arg(0) === "delete") { if($user->is_admin()) { // FIXME: post, not args - if($event->count_args() == 3) { + if($event->count_args() === 3) { send_event(new CommentDeletionEvent($event->get_arg(1))); $page->set_mode("redirect"); if(!empty($_SERVER['HTTP_REFERER'])) { @@ -145,7 +145,7 @@ class CommentList extends SimpleExtension { $this->theme->display_permission_denied($page); } } - else if($event->get_arg(0) == "list") { + else if($event->get_arg(0) === "list") { $this->build_page($event->get_arg(1)); } } @@ -367,7 +367,7 @@ class CommentList extends SimpleExtension { global $database; // sqlite fails at intervals - if($database->engine->name == "sqlite") return false; + if($database->engine->name === "sqlite") return false; $window = int_escape($config->get_int('comment_window')); $max = int_escape($config->get_int('comment_limit')); diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php index b1763f2a..1e24b794 100644 --- a/ext/ext_manager/main.php +++ b/ext/ext_manager/main.php @@ -25,12 +25,13 @@ class ExtensionInfo { function ExtensionInfo($main) { $matches = array(); $lines = file($main); + $number_of_lines = count($lines); preg_match("#(ext|contrib)/(.*)/main.php#", $main, $matches); $this->ext_name = $matches[2]; $this->name = $this->ext_name; $this->enabled = $this->is_enabled($this->ext_name); - for($i=0; $iname = $matches[1]; diff --git a/ext/upload/theme.php b/ext/upload/theme.php index 1b13bf9e..25c22242 100644 --- a/ext/upload/theme.php +++ b/ext/upload/theme.php @@ -15,7 +15,9 @@ class UploadTheme extends Themelet { // Uploader 2.0! $upload_list = ""; - for($i=0; $i<$config->get_int('upload_count'); $i++) + $upload_count = $config->get_int('upload_count'); + + for($i=0; $i<$upload_count; $i++) { $a=$i+1; $s=$i-1; @@ -244,7 +246,9 @@ class UploadTheme extends Themelet { global $config; $upload_list = ""; - for($i=0; $i<$config->get_int('upload_count'); $i++) { + $upload_count = $config->get_int('upload_count'); + + for($i=0; $i<$upload_count; $i++) { if($i == 0) $style = ""; // "style='display:visible'"; else $style = "style='display:none'"; $upload_list .= " Date: Fri, 27 Jan 2012 18:17:55 +0000 Subject: [PATCH 31/83] missing a bit --- contrib/tag_history/main.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index d6f00845..5cfd2ac1 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -63,7 +63,9 @@ class Tag_History implements Extension { { // this is a request to revert to a previous version of the tags if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) { - $this->process_revert_request($_POST['revert']); + if(isset($_POST['revert'])) { + $this->process_revert_request($_POST['revert']); + } } } else if($event->count_args() == 1) From 66a5bc2d9e6b965aa269b197329e9c6b3bbfd1e1 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 27 Jan 2012 18:53:59 +0000 Subject: [PATCH 32/83] compile event listener table --- index.php | 80 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/index.php b/index.php index 226be790..54194b10 100644 --- a/index.php +++ b/index.php @@ -68,6 +68,7 @@ _d("CACHE_DIR", false); // boolean store complete rendered pages on disk _d("CACHE_HTTP", false); // boolean output explicit HTTP caching headers _d("COOKIE_PREFIX", 'shm'); // string if you run multiple galleries with non-shared logins, give them different prefixes _d("SPEED_HAX", false); // boolean do some questionable things in the name of performance +_d("COMPILE_ELS", false); // boolean pre-build the list of event listeners _d("NICE_URLS", false); // boolean force niceurl mode _d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse _d("VERSION", 'trunk'); // string shimmie version @@ -137,34 +138,71 @@ try { ctx_log_endok(); + ctx_log_start("Loading extensions"); // initialise the extensions - $all_events = array(); - foreach(get_declared_classes() as $class) { - if(is_subclass_of($class, "Event")) { - $all_events[] = $class; - } + global $_event_listeners; + if(COMPILE_ELS && file_exists("data/event_listeners.php")) { + require_once("data/event_listeners.php"); } - foreach(get_declared_classes() as $class) { - $rclass = new ReflectionClass($class); - if($rclass->isAbstract()) { - // don't do anything + else { + $all_events = array(); + foreach(get_declared_classes() as $class) { + if(is_subclass_of($class, "Event")) { + $all_events[] = $class; + } } - elseif(is_subclass_of($class, "SimpleExtension")) { - $c = new $class(); - $c->i_am($c); - $my_events = array(); - foreach(get_class_methods($c) as $method) { - if(substr($method, 0, 2) == "on") { - $my_events[] = substr($method, 2) . "Event"; + foreach(get_declared_classes() as $class) { + $rclass = new ReflectionClass($class); + if($rclass->isAbstract()) { + // don't do anything + } + elseif(is_subclass_of($class, "SimpleExtension")) { + $c = new $class(); + $c->i_am($c); + $my_events = array(); + foreach(get_class_methods($c) as $method) { + if(substr($method, 0, 2) == "on") { + $my_events[] = substr($method, 2) . "Event"; + } + } + add_event_listener($c, $c->get_priority(), $my_events); + } + elseif(is_subclass_of($class, "Extension")) { + $c = new $class(); + add_event_listener($c, $c->get_priority(), $all_events); + } + } + + if(COMPILE_ELS) { + $p = "<"."?php\n"; + + foreach(get_declared_classes() as $class) { + $rclass = new ReflectionClass($class); + if($rclass->isAbstract()) {} + elseif(is_subclass_of($class, "SimpleExtension")) { + $p .= "\$$class = new $class(); "; + $p .= "\${$class}->i_am(\$$class);\n"; + } + elseif(is_subclass_of($class, "Extension")) { + $p .= "\$$class = new $class();\n"; } } - add_event_listener($c, $c->get_priority(), $my_events); - } - elseif(is_subclass_of($class, "Extension")) { - $c = new $class(); - add_event_listener($c, $c->get_priority(), $all_events); + + $p .= "\$_event_listeners = array(\n"; + foreach($_event_listeners as $event => $listeners) { + $p .= "\t'$event' => array(\n"; + foreach($listeners as $id => $listener) { + $p .= "\t\t$id => \$".get_class($listener).",\n"; + } + $p .= "\t),\n"; + } + $p .= ");\n"; + + $p .= "?".">"; + file_put_contents("data/event_listeners.php", $p); } } + ctx_log_endok(); ctx_log_endok("Initialisation"); From 3d582dc0d92e591ce9e01c09ca9f31ec178111e8 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 27 Jan 2012 19:08:17 +0000 Subject: [PATCH 33/83] protip: don't break everything --- core/extension.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/extension.class.php b/core/extension.class.php index e02df376..98d6bc15 100644 --- a/core/extension.class.php +++ b/core/extension.class.php @@ -188,7 +188,7 @@ abstract class DataHandlerExtension extends SimpleExtension { } } - public function onThumnbnailGeneration($event) { + public function onThumbnailGeneration($event) { if($this->supported_ext($event->type)) { if (method_exists($this, 'create_thumb_force') && $event->force == true) { $this->create_thumb_force($event->hash); From 112fb0841d057f2b6b8a50814db6133f95c70d00 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 02:03:15 +0000 Subject: [PATCH 34/83] named placeholders for numeric score --- contrib/numeric_score/main.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index 963953d9..124265d2 100644 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -206,8 +206,8 @@ class NumericScore implements Extension { "Can't find the user named ".html_escape($matches[1])); } $event->add_querylet(new Querylet( - "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", - array($duser->id))); + "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=1)", + array("ns_user_id"=>$duser->id))); } if(preg_match("/^downvoted_by=(.*)$/", $event->term, $matches)) { $duser = User::by_name($matches[1]); @@ -216,20 +216,20 @@ class NumericScore implements Extension { "Can't find the user named ".html_escape($matches[1])); } $event->add_querylet(new Querylet( - "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)", - array($duser->id))); + "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)", + array("ns_user_id"=>$duser->id))); } if(preg_match("/^upvoted_by_id=(\d+)$/", $event->term, $matches)) { $iid = int_escape($matches[1]); $event->add_querylet(new Querylet( - "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", - array($iid))); + "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=1)", + array("ns_user_id"=>$iid))); } if(preg_match("/^downvoted_by_id=(\d+)$/", $event->term, $matches)) { $iid = int_escape($matches[1]); $event->add_querylet(new Querylet( - "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)", - array($iid))); + "images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)", + array("ns_user_id"=>$iid))); } } } From 7af442855d83e8fa1d1a2d1c4c07a5921346d088 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 02:18:16 +0000 Subject: [PATCH 35/83] this isn't so necessary with latest upstream changes --- ext/comment/theme.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/ext/comment/theme.php b/ext/comment/theme.php index 3e2f9138..2fabf9c6 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -134,15 +134,7 @@ class CommentListTheme extends Themelet { global $user; $tfe = new TextFormattingEvent($comment->comment); - - // sending this event to all ~50 exts has a lot of overhead - if(SPEED_HAX) { - $bb = new BBCode(); - $bb->receive_event($tfe); - } - else { - send_event($tfe); - } + send_event($tfe); $i_uid = int_escape($comment->owner_id); $h_name = html_escape($comment->owner_name); From 39e8e8b7333c0e3d4906bb5f5a6a0563a7a92d64 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 02:24:17 +0000 Subject: [PATCH 36/83] downtime -> simpleext --- contrib/downtime/main.php | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/contrib/downtime/main.php b/contrib/downtime/main.php index 5dc57690..8c9ced34 100644 --- a/contrib/downtime/main.php +++ b/contrib/downtime/main.php @@ -11,31 +11,26 @@ * message specified in the box. */ -class Downtime implements Extension { - var $theme; - +class Downtime extends SimpleExtension { public function get_priority() {return 10;} - public function receive_event(Event $event) { - global $config, $database, $page, $user; - if(is_null($this->theme)) $this->theme = get_theme_object($this); + public function onSetupBuilding($event) { + $sb = new SetupBlock("Downtime"); + $sb->add_bool_option("downtime", "Disable non-admin access: "); + $sb->add_longtext_option("downtime_message", "
    "); + $event->panel->add_block($sb); + } - if($event instanceof SetupBuildingEvent) { - $sb = new SetupBlock("Downtime"); - $sb->add_bool_option("downtime", "Disable non-admin access: "); - $sb->add_longtext_option("downtime_message", "
    "); - $event->panel->add_block($sb); - } + public function onPageRequest($event) { + global $config, $page, $user; - if($event instanceof PageRequestEvent) { - if($config->get_bool("downtime")) { - if(!$user->is_admin() && !$this->is_safe_page($event)) { - $msg = $config->get_string("downtime_message"); - $this->theme->display_message($msg); - exit; - } - $this->theme->display_notification($page); + if($config->get_bool("downtime")) { + if(!$user->is_admin() && !$this->is_safe_page($event)) { + $msg = $config->get_string("downtime_message"); + $this->theme->display_message($msg); + exit; } + $this->theme->display_notification($page); } } From 47bfbd7102926062190c4a717497ac0ac27825f1 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 02:24:22 +0000 Subject: [PATCH 37/83] downtime -> simpleext --- contrib/ipban/main.php | 55 +++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/contrib/ipban/main.php b/contrib/ipban/main.php index cb9abded..04126619 100644 --- a/contrib/ipban/main.php +++ b/contrib/ipban/main.php @@ -34,24 +34,20 @@ class AddIPBanEvent extends Event { } // }}} -class IPBan implements Extension { - var $theme; -// event handler {{{ +class IPBan extends SimpleExtension { public function get_priority() {return 10;} - public function receive_event(Event $event) { - global $config, $database, $page, $user; - if(is_null($this->theme)) $this->theme = get_theme_object($this); - - if($event instanceof InitExtEvent) { - if($config->get_int("ext_ipban_version") < 5) { - $this->install(); - } - - $this->check_ip_ban(); + public function onInitExt($event) { + global $config; + if($config->get_int("ext_ipban_version") < 5) { + $this->install(); } + $this->check_ip_ban(); + } - if(($event instanceof PageRequestEvent) && $event->page_matches("ip_ban")) { + public function onPageRequest($event) { + if($event->page_matches("ip_ban")) { + global $config, $database, $page, $user; if($user->is_admin()) { if($event->get_arg(0) == "add" && $user->check_auth_token()) { if(isset($_POST['ip']) && isset($_POST['reason']) && isset($_POST['end'])) { @@ -79,23 +75,26 @@ class IPBan implements Extension { $this->theme->display_permission_denied($page); } } + } - if($event instanceof UserBlockBuildingEvent) { - if($user->is_admin()) { - $event->add_link("IP Bans", make_link("ip_ban/list")); - } - } - - if($event instanceof AddIPBanEvent) { - $this->add_ip_ban($event->ip, $event->reason, $event->end, $user); - } - - if($event instanceof RemoveIPBanEvent) { - $database->Execute("DELETE FROM bans WHERE id = :id", array("id"=>$event->id)); - $database->cache->delete("ip_bans"); + public function onUserBlockBuilding($event) { + global $user; + if($user->is_admin()) { + $event->add_link("IP Bans", make_link("ip_ban/list")); } } -// }}} + + public function onAddIPBan($event) { + global $user; + $this->add_ip_ban($event->ip, $event->reason, $event->end, $user); + } + + public function onRemoveIPBan($event) { + global $database; + $database->Execute("DELETE FROM bans WHERE id = :id", array("id"=>$event->id)); + $database->cache->delete("ip_bans"); + } + // installer {{{ protected function install() { global $database; From 18d6fa317c54363e3eb8bfed657ab771a5611201 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 03:22:41 +0000 Subject: [PATCH 38/83] adminpage -> simpleext --- contrib/admin/main.php | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/contrib/admin/main.php b/contrib/admin/main.php index c099b066..64298022 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -35,16 +35,11 @@ class AdminBuildingEvent extends Event { } } -class AdminPage implements Extension { - var $theme; +class AdminPage extends SimpleExtension { + public function onPageRequest($event) { + global $page, $user; - public function get_priority() {return 50;} - - public function receive_event(Event $event) { - global $config, $database, $page, $user; - if(is_null($this->theme)) $this->theme = get_theme_object($this); - - if(($event instanceof PageRequestEvent) && $event->page_matches("admin")) { + if($event->page_matches("admin")) { if(!$user->is_admin()) { $this->theme->display_permission_denied($page); } @@ -53,7 +48,7 @@ class AdminPage implements Extension { } } - if(($event instanceof PageRequestEvent) && $event->page_matches("admin_utils")) { + if($event->page_matches("admin_utils")) { if($user->is_admin() && $user->check_auth_token()) { log_info("admin", "Util: {$_POST['action']}"); set_time_limit(0); @@ -91,16 +86,18 @@ class AdminPage implements Extension { } } } + } - if($event instanceof AdminBuildingEvent) { - $this->theme->display_page($page); - $this->theme->display_form($page); - } + public function onAdminBuilding($event) { + global $page; + $this->theme->display_page($page); + $this->theme->display_form($page); + } - if($event instanceof UserBlockBuildingEvent) { - if($user->is_admin()) { - $event->add_link("Board Admin", make_link("admin")); - } + public function onUserBlockBuilding($event) { + global $user; + if($user->is_admin()) { + $event->add_link("Board Admin", make_link("admin")); } } From 0ea3ff5af39e1183ad13738be71cf157f4a1f831 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 03:39:00 +0000 Subject: [PATCH 39/83] wordfilter -> simpleext --- contrib/word_filter/main.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/contrib/word_filter/main.php b/contrib/word_filter/main.php index 5e4cddd2..1ce8e259 100644 --- a/contrib/word_filter/main.php +++ b/contrib/word_filter/main.php @@ -6,21 +6,20 @@ * Description: Simple search and replace */ -class WordFilter implements Extension { +class WordFilter extends SimpleExtension { // before emoticon filter public function get_priority() {return 40;} - public function receive_event(Event $event) { - if($event instanceof TextFormattingEvent) { - $event->formatted = $this->filter($event->formatted); - $event->stripped = $this->filter($event->stripped); - } - if(($event instanceof SetupBuildingEvent)) { - $sb = new SetupBlock("Word Filter"); - $sb->add_longtext_option("word_filter"); - $sb->add_label("
    (each line should be search term and replace term, separated by a comma)"); - $event->panel->add_block($sb); - } + public function onTextFormatting($event) { + $event->formatted = $this->filter($event->formatted); + $event->stripped = $this->filter($event->stripped); + } + + public function onSetupBuilding($event) { + $sb = new SetupBlock("Word Filter"); + $sb->add_longtext_option("word_filter"); + $sb->add_label("
    (each line should be search term and replace term, separated by a comma)"); + $event->panel->add_block($sb); } private function filter($text) { From 444fdb1f04db9033ba2c4d44b49ca8add7340f1d Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 03:46:38 +0000 Subject: [PATCH 40/83] tag history -> simpleext --- contrib/tag_history/main.php | 149 +++++++++++++++++------------------ 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index a1464323..6b6205af 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -5,65 +5,61 @@ * Description: Keep a record of tag changes, and allows you to revert changes. */ -class Tag_History implements Extension { - var $theme; - +class Tag_History extends SimpleExtension { // in before tags are actually set, so that "get current tags" works public function get_priority() {return 40;} - public function receive_event(Event $event) { - global $config, $database, $page, $user; - if(is_null($this->theme)) $this->theme = get_theme_object($this); + public function onInitExtEvent($event) { + global $config; + $config->set_default_int("history_limit", -1); - if(($event instanceof InitExtEvent)) { - $config->set_default_int("history_limit", -1); - - // shimmie is being installed so call install to create the table. - if($config->get_int("ext_tag_history_version") < 3) { - $this->install(); - } + // shimmie is being installed so call install to create the table. + if($config->get_int("ext_tag_history_version") < 3) { + $this->install(); } + } - if(($event instanceof AdminBuildingEvent)) - { - if(isset($_POST['revert_ip']) && $user->is_admin() && $user->check_auth_token()) - { - $revert_ip = filter_var($_POST['revert_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE); - - if ($revert_ip === false) { - // invalid ip given. - $this->theme->display_admin_block('Invalid IP'); + public function onAdminBuildingEvent($event) { + global $user; + + if(isset($_POST['revert_ip']) && $user->is_admin() && $user->check_auth_token()) { + $revert_ip = filter_var($_POST['revert_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE); + + if ($revert_ip === false) { + // invalid ip given. + $this->theme->display_admin_block('Invalid IP'); + return; + } + + if (isset($_POST['revert_date']) && !empty($_POST['revert_date'])) { + if (isValidDate($_POST['revert_date'])){ + $revert_date = addslashes($_POST['revert_date']); // addslashes is really unnecessary since we just checked if valid, but better safe. + } else { + $this->theme->display_admin_block('Invalid Date'); return; } - - if (isset($_POST['revert_date']) && !empty($_POST['revert_date'])) { - if (isValidDate($_POST['revert_date'])){ - $revert_date = addslashes($_POST['revert_date']); // addslashes is really unnecessary since we just checked if valid, but better safe. - } else { - $this->theme->display_admin_block('Invalid Date'); - return; - } - } else { - $revert_date = null; - } - - set_time_limit(0); // reverting changes can take a long time, disable php's timelimit if possible. - - // Call the revert function. - $this->process_revert_all_changes_by_ip($revert_ip, $revert_date); - // output results - $this->theme->display_revert_ip_results(); } - else - { - $this->theme->display_admin_block(); // add a block to the admin panel + else { + $revert_date = null; } + + set_time_limit(0); // reverting changes can take a long time, disable php's timelimit if possible. + + // Call the revert function. + $this->process_revert_all_changes_by_ip($revert_ip, $revert_date); + // output results + $this->theme->display_revert_ip_results(); } + else { + $this->theme->display_admin_block(); // add a block to the admin panel + } + } - if (($event instanceof PageRequestEvent) && ($event->page_matches("tag_history"))) - { - if($event->get_arg(0) == "revert") - { + public function onPageRequest($event) { + global $config, $page; + + if ($event->page_matches("tag_history")) { + if($event->get_arg(0) == "revert") { // this is a request to revert to a previous version of the tags if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) { if(isset($_POST['revert'])) { @@ -71,8 +67,7 @@ class Tag_History implements Extension { } } } - else if($event->count_args() == 1) - { + else if($event->count_args() == 1) { // must be an attempt to view a tag history $image_id = int_escape($event->get_arg(0)); $this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id)); @@ -81,32 +76,36 @@ class Tag_History implements Extension { $this->theme->display_global_page($page, $this->get_global_tag_history()); } } - - if(($event instanceof DisplayingImageEvent)) - { - // handle displaying a link on the view page - $this->theme->display_history_link($page, $event->image->id); - } - if(($event instanceof ImageDeletionEvent)) - { - // handle removing of history when an image is deleted - $this->delete_all_tag_history($event->image->id); - } - if(($event instanceof SetupBuildingEvent)) { - $sb = new SetupBlock("Tag History"); - $sb->add_label("Limit to "); - $sb->add_int_option("history_limit"); - $sb->add_label(" entires per image"); - $sb->add_label("
    (-1 for unlimited)"); - $event->panel->add_block($sb); - } - if(($event instanceof TagSetEvent)) { - $this->add_tag_history($event->image, $event->tags); - } - if($event instanceof UserBlockBuildingEvent) { - if($user->is_admin()) { - $event->add_link("Tag Changes", make_link("tag_history")); - } + } + + public function onDisplayingImage($event) { + global $page; + // handle displaying a link on the view page + $this->theme->display_history_link($page, $event->image->id); + } + + public function onImageDeletion($event) { + // handle removing of history when an image is deleted + $this->delete_all_tag_history($event->image->id); + } + + public function onSetupBuilding($event) { + $sb = new SetupBlock("Tag History"); + $sb->add_label("Limit to "); + $sb->add_int_option("history_limit"); + $sb->add_label(" entires per image"); + $sb->add_label("
    (-1 for unlimited)"); + $event->panel->add_block($sb); + } + + public function onTagSetEvent($event) { + $this->add_tag_history($event->image, $event->tags); + } + + public function onUserBlockBuilding($event) { + global $user; + if($user->is_admin()) { + $event->add_link("Tag Changes", make_link("tag_history")); } } From 8623ab291736c61721ae3b21435564b56c69be26 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 04:56:08 +0000 Subject: [PATCH 41/83] _count_execs actually works nicely for PDO, if called... --- core/database.class.php | 1 + index.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/core/database.class.php b/core/database.class.php index c42ce366..b17a8625 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -326,6 +326,7 @@ class Database { */ public function execute($query, $args=array()) { try { + _count_execs($this->db, $query, $args); $stmt = $this->db->prepare($query); if (!array_key_exists(0, $args)) { foreach($args as $name=>$value) { diff --git a/index.php b/index.php index 54194b10..9df65aeb 100644 --- a/index.php +++ b/index.php @@ -106,7 +106,6 @@ try { ctx_log_start("Connecting to DB"); // connect to the database $database = new Database(); - //$database->db->fnExecute = '_count_execs'; // FIXME: PDO equivalent $database->db->beginTransaction(); $config = new DatabaseConfig($database); ctx_log_endok(); From 55447d1aa84f449662a3beeac421a5e04d22961d Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 05:00:21 +0000 Subject: [PATCH 42/83] toggle for sql debugging --- core/util.inc.php | 2 +- index.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/util.inc.php b/core/util.inc.php index 7005d840..1def3356 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -409,7 +409,7 @@ function check_cli() { */ function _count_execs($db, $sql, $inputarray) { global $_execs; - if(DEBUG) { + if(DEBUG_SQL) { $fp = @fopen("data/sql.log", "a"); if($fp) { if(is_array($inputarray)) { diff --git a/index.php b/index.php index 9df65aeb..5a60f335 100644 --- a/index.php +++ b/index.php @@ -61,6 +61,7 @@ function _d($name, $value) {if(!defined($name)) define($name, $value);} _d("DATABASE_DSN", null); // string PDO database connection details _d("CACHE_DSN", null); // string cache connection details _d("DEBUG", false); // boolean print various debugging details +_d("DEBUG_SQL", false); // boolean dump SQL queries to data/sql.log _d("COVERAGE", false); // boolean activate xdebug coverage monitor _d("CONTEXT", null); // string file to log performance data into _d("CACHE_MEMCACHE", false); // boolean store complete rendered pages in memcache From 5a63ad05b50c69a5f292cad2352b4c2db6646789 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Tue, 31 Jan 2012 00:35:20 -0500 Subject: [PATCH 43/83] Fix for installer failing with new DSN define. --- install.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/install.php b/install.php index 78d85065..09da4d33 100755 --- a/install.php +++ b/install.php @@ -119,6 +119,7 @@ if(is_readable("config.php")) { exit; } require_once "core/compat.inc.php"; +require_once "core/util.inc.php"; require_once "core/database.class.php"; do_install(); @@ -160,6 +161,7 @@ function do_install() { // {{{ if(isset($_POST['database_type']) && isset($_POST['database_host']) && isset($_POST['database_user']) && isset($_POST['database_name'])) { global $database_dsn; $database_dsn = "{$_POST['database_type']}:user={$_POST['database_user']};password={$_POST['database_password']};host={$_POST['database_host']};dbname={$_POST['database_name']}"; + define('DATABASE_DSN', $database_dsn); install_process(); } else if(file_exists("auto_install.conf")) { @@ -362,9 +364,10 @@ function build_dirs() { // {{{ } // }}} function write_config() { // {{{ global $database_dsn; - $file_content = "<"+"?php\n"+ - "define('DATABASE_DSN', '$database_dsn');\n"+ - "?"+">"; + + $file_content = '<' . '?php' . "\n" . + "define('DATABASE_DSN', '$database_dsn');\n" . + '?' . '>'; if(is_writable("./") && file_put_contents("config.php", $file_content)) { assert(file_exists("config.php")); From 8192f278d57e262df114d62bee635dc52cc5be3e Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 31 Jan 2012 12:15:25 +0000 Subject: [PATCH 44/83] different sql for different databases :( --- ext/comment/main.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index 0c364d57..43556f05 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -374,9 +374,12 @@ class CommentList extends SimpleExtension { $window = int_escape($config->get_int('comment_window')); $max = int_escape($config->get_int('comment_limit')); + if($database->engine->name == "mysql") $window_sql = "interval $window minute"; + else $window_sql = "interval '$window minute'"; + // window doesn't work as an SQL param because it's inside quotes >_< $result = $database->get_all("SELECT * FROM comments WHERE owner_ip = :remote_ip ". - "AND posted > now() - interval '$window minute'", + "AND posted > now() - $window_sql", Array("remote_ip"=>$_SERVER['REMOTE_ADDR'])); return (count($result) >= $max); From c2689ba519a0504f2e1c5e134408d7faf3006644 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 31 Jan 2012 12:16:19 +0000 Subject: [PATCH 45/83] set remote addr in postgres connection --- core/database.class.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/database.class.php b/core/database.class.php index b17a8625..532e0fcd 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -88,6 +88,10 @@ class MySQL extends DBEngine { class PostgreSQL extends DBEngine { var $name = "pgsql"; + public function init($db) { + $db->query("SET application_name TO 'shimmie [{$_SERVER['REMOTE_ADDR']}]';"); + } + public function scoreql_to_sql($data) { $data = str_replace("SCORE_AIPK", "SERIAL PRIMARY KEY", $data); $data = str_replace("SCORE_INET", "INET", $data); From 4da56c12dbc71240642dfcc15f95783ed3af6680 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 31 Jan 2012 12:16:34 +0000 Subject: [PATCH 46/83] missed a var --- contrib/tag_history/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 6b6205af..6bfa1928 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -56,7 +56,7 @@ class Tag_History extends SimpleExtension { } public function onPageRequest($event) { - global $config, $page; + global $config, $page, $user; if ($event->page_matches("tag_history")) { if($event->get_arg(0) == "revert") { From 6e6138793b86d6860fbc14c92a2d986c169fcc1d Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 31 Jan 2012 12:16:47 +0000 Subject: [PATCH 47/83] DEBUG_SQL can be null for user-defined --- core/util.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/util.inc.php b/core/util.inc.php index 1def3356..53212c26 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -409,7 +409,7 @@ function check_cli() { */ function _count_execs($db, $sql, $inputarray) { global $_execs; - if(DEBUG_SQL) { + if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { $fp = @fopen("data/sql.log", "a"); if($fp) { if(is_array($inputarray)) { From 1cd4f867b5251f166cbe19798e66ae49159c496d Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 31 Jan 2012 12:24:29 +0000 Subject: [PATCH 48/83] don't die if [/code] comes before [code] --- ext/bbcode/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php index 72eec4e8..732d3b35 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -142,7 +142,7 @@ class BBCode extends FormatterExtension { $start = strpos($text, "[code]"); if($start === false) break; - $end = strpos($text, "[/code]"); + $end = strpos($text, "[/code]", $start); if($end === false) break; $beginning = substr($text, 0, $start); From 41ccdfb499c9e4a0dff8e70313bced1cd6d9c357 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 31 Jan 2012 14:29:53 +0000 Subject: [PATCH 49/83] remove some blanks --- contrib/mass_tagger/main.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/contrib/mass_tagger/main.php b/contrib/mass_tagger/main.php index 65276e20..a83dda44 100644 --- a/contrib/mass_tagger/main.php +++ b/contrib/mass_tagger/main.php @@ -15,10 +15,6 @@ */ class MassTagger extends SimpleExtension { - public function onInitExt($event) { - return; - } - public function onPostListBuilding($event) { global $config, $page, $user; @@ -36,7 +32,6 @@ class MassTagger extends SimpleExtension { } private function _apply_mass_tags( $config, $page, $user, $event ) { - if( !isset($_POST['ids']) or !isset($_POST['tag']) ) return; $tag = $_POST['tag']; @@ -53,8 +48,6 @@ class MassTagger extends SimpleExtension { $page->set_mode("redirect"); $page->set_redirect(make_link("post/list")); - } - } ?> From 75b9bc265014f538811dbea98ce391e578aa048b Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 31 Jan 2012 14:46:19 +0000 Subject: [PATCH 50/83] typo in merged code --- ext/alias_editor/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 8986ac0b..6ef31bee 100755 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -134,7 +134,7 @@ class AliasEditor extends SimpleExtension { foreach(explode("\n", $csv) as $line) { $parts = explode(",", $line); if(count($parts) == 2) { - $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", array("oldtag" => $parts[0], "newtag" => $parts[1]); + $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(:oldtag, :newtag)", array("oldtag" => $parts[0], "newtag" => $parts[1])); } } } From a5de1fd9f013768d3ea78bc5eea3302206ce798e Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 27 Jan 2012 00:03:26 +0000 Subject: [PATCH 51/83] fixes popular_by_month/year not working due to "number of bound variables does not match number of tokens" error --- contrib/numeric_score/main.php | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index 97c81bd8..5c61fa49 100755 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -112,9 +112,6 @@ class NumericScore implements Extension { //TODO: Somehow make popular_by_#/2012/12/31 > popular_by_#?day=31&month=12&year=2012 (So no problems with date formats) //TODO: Add Popular_by_week. - $sql = "SELECT * FROM images "; - $args = array(); - //year if(int_escape($event->get_arg(0)) == 0){ $year = date("Y"); @@ -135,40 +132,45 @@ class NumericScore implements Extension { } $totaldate = $year."/".$month."/".$day; + $sql = + "SELECT * FROM images + WHERE EXTRACT(YEAR FROM posted) = :year + "; + + $agrs = array("limit" => $t_images, "year" => $year); + if($event->page_matches("popular_by_day")){ $sql .= - "WHERE EXTRACT(YEAR FROM posted) = :year - AND EXTRACT(MONTH FROM posted) = :month + "AND EXTRACT(MONTH FROM posted) = :month AND EXTRACT(DAY FROM posted) = :day AND NOT numeric_score=0 "; + //array_push doesn't seem to like using double arrows + //this requires us to instead create two arrays and merge + $sgra = array("month" => $month, "day" => $day); + $args = array_merge($agrs, $sgra); + $dte = array($totaldate, date("F jS, Y", (strtotime($totaldate))), "Y/m/d", "day"); } if($event->page_matches("popular_by_month")){ $sql .= - "WHERE EXTRACT(YEAR FROM posted) = :year - AND EXTRACT(MONTH FROM posted) = :month + "AND EXTRACT(MONTH FROM posted) = :month AND NOT numeric_score=0 "; + $sgra = array("month" => $month); + $args = array_merge($agrs, $sgra); + $title = date("F Y", (strtotime($totaldate))); $dte = array($totaldate, $title, "Y/m", "month"); } if($event->page_matches("popular_by_year")){ - $sql .= - "WHERE EXTRACT(YEAR FROM posted) = :year - AND NOT numeric_score=0 - "; + $sql .= "AND NOT numeric_score=0"; $dte = array($totaldate, $year, "Y", "year"); + $args = $agrs; } $sql .= " ORDER BY numeric_score DESC LIMIT :limit OFFSET 0"; //filter images by year/score != 0 > limit to max images on one page > order from highest to lowest score - $args = array( - "year" => $year, - "month" => $month, - "day" => $day, - "limit" => $t_images - ); $result = $database->get_all($sql, $args); $images = array(); From c5468bd93888dfc81920dcd7bfde521be14cfb1d Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 27 Jan 2012 03:47:27 +0000 Subject: [PATCH 52/83] centering downtime text --- contrib/downtime/theme.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/downtime/theme.php b/contrib/downtime/theme.php index 0003c2af..e529209e 100644 --- a/contrib/downtime/theme.php +++ b/contrib/downtime/theme.php @@ -6,7 +6,7 @@ class DowntimeTheme extends Themelet { */ public function display_notification(Page $page) { $page->add_block(new Block("Downtime", - "DOWNTIME MODE IS ON!", "left", 0)); + "
    DOWNTIME MODE IS ON!
    ", "left", 0)); } /** @@ -28,7 +28,7 @@ class DowntimeTheme extends Themelet {
    -

    Down for Maintenance

    +

    Down for Maintenance

    $message
    From 56f3ca6c109d2f0d3bfe63f7951281d8ffcd08a4 Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 27 Jan 2012 05:19:47 +0000 Subject: [PATCH 53/83] fixes the featured block not keeping the image in the sidebar on certain themes --- contrib/featured/theme.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/contrib/featured/theme.php b/contrib/featured/theme.php index e4a3ab78..74a4134e 100644 --- a/contrib/featured/theme.php +++ b/contrib/featured/theme.php @@ -5,7 +5,7 @@ class FeaturedTheme extends Themelet { * Show $text on the $page */ public function display_featured(Page $page, Image $image) { - $page->add_block(new Block("Featured Image", $this->build_thumb_html($image), "left", 3)); + $page->add_block(new Block("Featured Image", $this->build_featured_html($image), "left", 3)); } public function get_buttons_html($image_id) { @@ -18,5 +18,25 @@ class FeaturedTheme extends Themelet { "; } + + public function build_featured_html(Image $image, $query=null) { + global $config; + $i_id = int_escape($image->id); + $h_view_link = make_link("post/view/$i_id", $query); + $h_thumb_link = $image->get_thumb_link(); + $h_tip = html_escape($image->get_tooltip()); + $tsize = get_thumbnail_size($image->width, $image->height); + + + return " +
    + + + $h_tip + + +
    + "; + } } ?> From 2c1a94c734146aa9a851e5f4d226ca75fe960e86 Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 27 Jan 2012 05:42:46 +0000 Subject: [PATCH 54/83] xspf_player now uses filename as song title --- contrib/handle_mp3/theme.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/handle_mp3/theme.php b/contrib/handle_mp3/theme.php index 7844f595..0239b522 100644 --- a/contrib/handle_mp3/theme.php +++ b/contrib/handle_mp3/theme.php @@ -4,13 +4,14 @@ class MP3FileHandlerTheme extends Themelet { public function display_image(Page $page, Image $image) { $data_href = get_base_href(); $ilink = $image->get_image_link(); + $fname = $image->filename; //Most of the time this will be the title/artist of the song. $html = " - From 74478297f287891895502f7fe377669210affe55 Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 27 Jan 2012 06:08:37 +0000 Subject: [PATCH 55/83] contact link only shows if set --- contrib/home/theme.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/home/theme.php b/contrib/home/theme.php index eda5e815..da3c80a8 100644 --- a/contrib/home/theme.php +++ b/contrib/home/theme.php @@ -29,6 +29,7 @@ EOD $main_links_html = empty($main_links) ? "" : ""; $message_html = empty($main_text) ? "" : "
    $main_text
    "; $counter_html = empty($counter_text) ? "" : "
    $counter_text
    "; + $contact_link = empty($contact_link) ? "" : "
    Contact –"; $search_html = "