From bdf274074c0f8bd8e52847c1170c4c14e9dc33b4 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 18 Jan 2012 03:13:27 +0000 Subject: [PATCH 01/30] some people like heading to the image after an image that isn't there (mostly robots with old URLs) --- ext/view/main.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ext/view/main.php b/ext/view/main.php index fc495cbc..56105a8e 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -87,6 +87,10 @@ class ViewImage extends SimpleExtension { } $image = Image::by_id($image_id); + if(is_null($image)) { + $this->theme->display_error($page, "Image not found", "Couldn't find image $image_id"); + } + if($event->page_matches("post/next")) { $image = $image->get_next($search_terms); } @@ -94,13 +98,12 @@ class ViewImage extends SimpleExtension { $image = $image->get_prev($search_terms); } - if(!is_null($image)) { - $page->set_mode("redirect"); - $page->set_redirect(make_link("post/view/{$image->id}", $query)); - } - else { + if(is_null($image)) { $this->theme->display_error($page, "Image not found", "No more images"); } + + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/view/{$image->id}", $query)); } if($event->page_matches("post/view")) { From b52651c5582d1445248983ee57bf0908ebddaf4f Mon Sep 17 00:00:00 2001 From: NaGeL Date: Tue, 17 Jan 2012 22:45:24 +0100 Subject: [PATCH 02/30] added [align=(left|center|right)] BBcode which aligns text naturally. --- ext/bbcode/main.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php index bddda8c5..328d9dba 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -63,6 +63,7 @@ class BBCode extends FormatterExtension { $text = preg_replace("/\[li\](.*?)\[\/li\]/s", "
  • \\1
  • ", $text); $text = preg_replace("#\[\*\]#s", "
  • ", $text); $text = preg_replace("#
    <(li|ul|ol|/ul|/ol)>#s", "<\\1>", $text); + $text = preg_replace("#\[align=(left|center|right)\](.*?)\[\/align\]#s", "
    \\2
    ", $text); $text = $this->filter_spoiler($text); $text = $this->insert_code($text); return $text; From b1d1d71093066a7b55eea622fc96328d36b1a88c Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 18 Jan 2012 17:53:52 +0000 Subject: [PATCH 03/30] author search from nagel --- contrib/artists/main.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/artists/main.php b/contrib/artists/main.php index e4a5a803..c86a8e10 100644 --- a/contrib/artists/main.php +++ b/contrib/artists/main.php @@ -43,6 +43,14 @@ class Artists implements Extension { if ($event instanceof PageRequestEvent) $this->handle_commands($event); + + if ($event instanceof SearchTermParseEvent) { + $matches = array(); + if(preg_match("/^author=(.*)$/", $event->term, $matches)) { + $char = $matches[1]; + $event->add_querylet(new Querylet("Author = :author_char", array("author_char"=>$char))); + } + } } public function try_install() { From 760810723286e04bd96defd5d90e6beae64992f2 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 19 Jan 2012 15:20:32 +0000 Subject: [PATCH 04/30] lib/askismet expects the referrer to either be set manually, or exist; if it doesn't exist we need to set it manually --- ext/comment/main.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ext/comment/main.php b/ext/comment/main.php index 6e165d03..0c54ad06 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -405,6 +405,13 @@ class CommentList extends SimpleExtension { 'permalink' => '', ); + # akismet breaks if there's no referrer in the environment; so if there + # isn't, supply one manually + if(!isset($_SERVER['HTTP_REFERER'])) { + $comment['referrer'] = ''; + log_warning("comment", "User '{$user->name}' commented with no referrer: $text"); + } + $akismet = new Akismet( $_SERVER['SERVER_NAME'], $config->get_string('comment_wordpress_key'), From b8bdbd3533fb917d7ee27fceb97d90bbc9b4986f Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 19 Jan 2012 15:23:44 +0000 Subject: [PATCH 05/30] after detecting an error, don't carry on processing the bad data... --- ext/view/main.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/view/main.php b/ext/view/main.php index 56105a8e..01df30ee 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -89,6 +89,7 @@ class ViewImage extends SimpleExtension { $image = Image::by_id($image_id); if(is_null($image)) { $this->theme->display_error($page, "Image not found", "Couldn't find image $image_id"); + return; } if($event->page_matches("post/next")) { From 8ba22d8fbcf1434fbef81d21cec6bdecc2e5aae1 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 19 Jan 2012 15:28:55 +0000 Subject: [PATCH 06/30] same for user-agent --- ext/comment/main.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index 0c54ad06..6f082a76 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -408,9 +408,13 @@ class CommentList extends SimpleExtension { # akismet breaks if there's no referrer in the environment; so if there # isn't, supply one manually if(!isset($_SERVER['HTTP_REFERER'])) { - $comment['referrer'] = ''; + $comment['referrer'] = 'none'; log_warning("comment", "User '{$user->name}' commented with no referrer: $text"); } + if(!isset($_SERVER['HTTP_USER_AGENT'])) { + $comment['user_agent'] = 'none'; + log_warning("comment", "User '{$user->name}' commented with no user-agent: $text"); + } $akismet = new Akismet( $_SERVER['SERVER_NAME'], From 36e443e07d360f777c2848122645db8b30873e66 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 20 Jan 2012 03:12:48 +0000 Subject: [PATCH 07/30] the algorithm for listing old comments pages is *really* inefficient; the first few pages are quick, page 100 can take a few seconds to generate... rule34 has over 100,000 pages of comments. Limit to the first few pages for now, as I don't know anyone who even goes past the front page. --- ext/comment/main.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ext/comment/main.php b/ext/comment/main.php index 6f082a76..c71ebc2a 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -146,7 +146,18 @@ class CommentList extends SimpleExtension { } } else if($event->get_arg(0) == "list") { - $this->build_page($event->get_arg(1)); + $page_num = int_escape($event->get_arg(1)); + if($page_num <= 5) { + $this->build_page($page_num); + } + else { + header("HTTP/1.0 403 Blocked"); + $this->theme->display_error($page, + "This page is history~", + "Only the first 5 pages of comments are visible ". + "- 99% of the traffic to older pages was bots, and ". + "they were hammering the database o.o"); + } } } } From 18e36f9b31863a18d349a13962d975fc8a6c7a9b Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 20 Jan 2012 03:15:58 +0000 Subject: [PATCH 08/30] Rather than three levels of configuration, let's have two (define()'d values in config.php for system-level stuff, the web-editable config table for user-level stuff). Basically switches database_dsn from a global variable to a defined constant. --- README.txt | 6 +++--- core/database.class.php | 13 +++++-------- core/util.inc.php | 2 +- index.php | 29 +++++++++++++++++------------ install.php | 6 ++++-- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/README.txt b/README.txt index 97d8955a..622d90a9 100644 --- a/README.txt +++ b/README.txt @@ -40,10 +40,10 @@ Installation Upgrade from 2.3.X ~~~~~~~~~~~~~~~~~~ The database connection setting in config.php has changed; now using -PDO DSN format [1] rather than ADODB URI [2] +PDO DSN format rather than ADODB URI: - [1] :user=;password=;host=;dbname= - [2] ://:@/ + OLD: $database_dsn = "://:@/"; + NEW: define("DATABASE_DSN", ":user=;password=;host=;dbname="); The rest should be automatic, just unzip into a clean folder and copy across config.php, images and thumbs folders from the old version. This diff --git a/core/database.class.php b/core/database.class.php index 53ed4b4d..64123180 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -274,8 +274,6 @@ class Database { * stored in config.php in the root shimmie folder */ public function Database() { - global $database_dsn, $cache_dsn; - # FIXME: detect ADODB URI, automatically translate PDO DSN /* @@ -285,10 +283,10 @@ class Database { * http://stackoverflow.com/questions/237367 */ $matches = array(); $db_user=null; $db_pass=null; - if(preg_match("/user=([^;]*)/", $database_dsn, $matches)) $db_user=$matches[1]; - if(preg_match("/password=([^;]*)/", $database_dsn, $matches)) $db_pass=$matches[1]; + if(preg_match("/user=([^;]*)/", DATABASE_DSN, $matches)) $db_user=$matches[1]; + if(preg_match("/password=([^;]*)/", DATABASE_DSN, $matches)) $db_pass=$matches[1]; - $this->db = new PDO($database_dsn, $db_user, $db_pass); + $this->db = new PDO(DATABASE_DSN, $db_user, $db_pass); $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db_proto = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME); @@ -305,9 +303,8 @@ class Database { die("Unknown PDO driver: $db_proto"); } - if(isset($cache_dsn) && !empty($cache_dsn)) { - $matches = array(); - preg_match("#(memcache|apc)://(.*)#", $cache_dsn, $matches); + $matches = array(); + if(CACHE_DSN && preg_match("#(memcache|apc)://(.*)#", CACHE_DSN, $matches)) { if($matches[1] == "memcache") { $this->cache = new MemcacheCache($matches[2]); } diff --git a/core/util.inc.php b/core/util.inc.php index 97146d25..21343497 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -204,7 +204,7 @@ function make_link($page=null, $query=null) { if(is_null($page)) $page = $config->get_string('main_page'); - if(FORCE_NICE_URLS || $config->get_bool('nice_urls', false)) { + if(NICE_URLS || $config->get_bool('nice_urls', false)) { #$full = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"]; $full = $_SERVER["PHP_SELF"]; $base = str_replace("/index.php", "", $full); diff --git a/index.php b/index.php index 63c3b52c..29cbecca 100644 --- a/index.php +++ b/index.php @@ -57,18 +57,23 @@ if(empty($database_dsn) && !file_exists("config.php")) { require_once "config.php"; // set up and purify the environment -if(!defined("DEBUG")) define("DEBUG", false); -if(!defined("COVERAGE")) define("COVERAGE", false); -if(!defined("CONTEXT")) define("CONTEXT", false); -if(!defined("CACHE_MEMCACHE")) define("CACHE_MEMCACHE", false); -if(!defined("CACHE_DIR")) define("CACHE_DIR", false); -if(!defined("CACHE_HTTP")) define("CACHE_HTTP", false); -if(!defined("VERSION")) define("VERSION", 'trunk'); -if(!defined("SCORE_VERSION")) define("SCORE_VERSION", 's2hack/'.VERSION); -if(!defined("COOKIE_PREFIX")) define("COOKIE_PREFIX", 'shm'); -if(!defined("SPEED_HAX")) define("SPEED_HAX", false); -if(!defined("FORCE_NICE_URLS")) define("FORCE_NICE_URLS", false); -if(!defined("WH_SPLITS")) define("WH_SPLITS", 1); +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("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 +_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("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 +_d("SCORE_VERSION", 's2hack/'.VERSION); // string SCore version require_once "core/util.inc.php"; require_once "lib/context.php"; diff --git a/install.php b/install.php index 83a1f2f3..e5f2e5cc 100755 --- a/install.php +++ b/install.php @@ -52,7 +52,7 @@ if(is_readable("config.php")) {

    Shimmie Repair Console

    "; + $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 49e7bfa1b229546b4ee480e52e120c9b62199695 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 20 Jan 2012 03:29:29 +0000 Subject: [PATCH 09/30] tidy up some ancient base_href / data_href messes; base_href as a config variable is no longer used --- contrib/browser_search/main.php | 1 - contrib/forum/theme.php | 2 -- contrib/home/main.php | 10 ++++------ contrib/home/theme.php | 4 ++-- contrib/rss_comments/main.php | 2 +- contrib/rss_images/main.php | 2 +- contrib/tagger/theme.php | 2 +- core/util.inc.php | 5 ++++- ext/setup/main.php | 1 - 9 files changed, 13 insertions(+), 16 deletions(-) diff --git a/contrib/browser_search/main.php b/contrib/browser_search/main.php index 0b458a64..fc113121 100755 --- a/contrib/browser_search/main.php +++ b/contrib/browser_search/main.php @@ -36,7 +36,6 @@ class BrowserSearch implements Extension { // First, we need to build all the variables we'll need $search_title = $config->get_string('title'); - //$search_form_url = $config->get_string('base_href'); //make_link('post/list'); $search_form_url = make_link('post/list/{searchTerms}'); $suggenton_url = make_link('browser_search/')."{searchTerms}"; $icon_b64 = base64_encode(file_get_contents("favicon.ico")); diff --git a/contrib/forum/theme.php b/contrib/forum/theme.php index ea460b47..40b015d9 100644 --- a/contrib/forum/theme.php +++ b/contrib/forum/theme.php @@ -83,8 +83,6 @@ class ForumTheme extends Themelet { global $config, $page/*, $user*/; $theme_name = $config->get_string('theme'); - $data_href = $config->get_string('base_href'); - $base_href = $config->get_string('base_href'); $html = ""; $n = 0; diff --git a/contrib/home/main.php b/contrib/home/main.php index f46c6238..b6172016 100644 --- a/contrib/home/main.php +++ b/contrib/home/main.php @@ -28,14 +28,13 @@ class Home extends SimpleExtension { public function onPageRequest(PageRequestEvent $event) { global $config, $page; if($event->page_matches("home")) { - $base_href = $config->get_string('base_href'); - $data_href = get_base_href(); + $base_href = get_base_href(); $sitename = $config->get_string('title'); $theme_name = $config->get_string('theme'); $body = $this->get_body(); - $this->theme->display_page($page, $sitename, $data_href, $theme_name, $body); + $this->theme->display_page($page, $sitename, $base_href, $theme_name, $body); } } @@ -58,8 +57,7 @@ class Home extends SimpleExtension { // returns just the contents of the body global $database; global $config; - $base_href = $config->get_string('base_href'); - $data_href = get_base_href(); + $base_href = get_base_href(); $sitename = $config->get_string('title'); $contact_link = $config->get_string('contact_link'); $counter_dir = $config->get_string('home_counter', 'default'); @@ -71,7 +69,7 @@ class Home extends SimpleExtension { $counter_text = ""; for($n=0; $nset_mode("data"); $page->set_data(<< $sitename - +