From e4e95a3a8540720010c499753221181daedcb840 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 19 Mar 2012 21:19:50 +0000 Subject: [PATCH 01/51] suppress the flood of 'suppressing flood' messages... --- contrib/log_net/main.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/contrib/log_net/main.php b/contrib/log_net/main.php index a9c69b11..4cde7c56 100644 --- a/contrib/log_net/main.php +++ b/contrib/log_net/main.php @@ -13,15 +13,17 @@ class LogNet extends Extension { public function onLog(LogEvent $event) { global $user; - if($this->count < 10 && $event->priority > 10) { - // TODO: colour based on event->priority - $username = ($user && $user->name) ? $user->name : "Anonymous"; - $str = sprintf("%-15s %-10s: %s", $_SERVER['REMOTE_ADDR'], $username, $event->message); - system("echo ".escapeshellarg($str)." | nc -q 0 localhost 5000"); - $this->count++; - } - else { - system("echo 'suppressing flood, check the web log' | nc -q 0 localhost 5000"); + if($event->priority > 10) { + if($this->count < 10) { + // TODO: colour based on event->priority + $username = ($user && $user->name) ? $user->name : "Anonymous"; + $str = sprintf("%-15s %-10s: %s", $_SERVER['REMOTE_ADDR'], $username, $event->message); + system("echo ".escapeshellarg($str)." | nc -q 0 localhost 5000"); + $this->count++; + } + else { + system("echo 'suppressing flood, check the web log' | nc -q 0 localhost 5000"); + } } } } From 033540e6f89acbf51b46badc4ce6bec7b3a56b81 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 19 Mar 2012 22:25:57 +0000 Subject: [PATCH 02/51] if this->count is checked inside event->pri, then checking again for count *is* necessary... --- contrib/log_net/main.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/log_net/main.php b/contrib/log_net/main.php index 4cde7c56..94d9d94c 100644 --- a/contrib/log_net/main.php +++ b/contrib/log_net/main.php @@ -14,14 +14,14 @@ class LogNet extends Extension { global $user; if($event->priority > 10) { + $this->count++; if($this->count < 10) { // TODO: colour based on event->priority $username = ($user && $user->name) ? $user->name : "Anonymous"; $str = sprintf("%-15s %-10s: %s", $_SERVER['REMOTE_ADDR'], $username, $event->message); system("echo ".escapeshellarg($str)." | nc -q 0 localhost 5000"); - $this->count++; } - else { + else if($this->count == 10) { system("echo 'suppressing flood, check the web log' | nc -q 0 localhost 5000"); } } From b156d4f38071b4f51c3c4dd2bf437bd1bf0b73e1 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 21 Mar 2012 15:04:17 +0000 Subject: [PATCH 03/51] no need for 'load files in a good way' to be optional, just do it --- core/page.class.php | 236 ++++++-------------------------------------- core/util.inc.php | 5 + ext/setup/main.php | 19 ---- 3 files changed, 35 insertions(+), 225 deletions(-) diff --git a/core/page.class.php b/core/page.class.php index 6547c3f2..dd28bd75 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -245,222 +245,46 @@ class Page { # 404/static handler will map these to themes/foo/bar.ico or lib/static/bar.ico $this->add_html_header(""); $this->add_html_header(""); - - /* Attempt to cache the CSS & JavaScript files */ - if ($this->add_cached_auto_html_headers() === FALSE) { - // caching failed, add all files to html_headers. - - foreach(glob("lib/*.css") as $css) { - $this->add_html_header(''); - } - $css_files = glob("ext/*/style.css"); - if($css_files) { - foreach($css_files as $css_file) { - $this->add_html_header(''); - } - } - $css_files = glob("themes/$theme_name/style.css"); - if($css_files) { - foreach($css_files as $css_file) { - $this->add_html_header(''); - } - } - - foreach(glob("lib/*.js") as $js) { - $this->add_html_header(''); - } - $js_files = glob("ext/*/script.js"); - if($js_files) { - foreach($js_files as $js_file) { - $this->add_html_header(''); - } - } - } - } - /** - * Automatic caching of CSS and Javascript files - * - * Allows site admins to have Shimmie automatically cache and minify all CSS and JS files. - * This is done to reduce the number of HTTP requests (recommended by the Yahoo high-performance - * guidelines). It combines all of the CSS and JavaScript files into one for each type, and - * stores them in cached files to serve the client. Changes to the CSS or JavaScript files are - * caught by taking the md5sum of the concatenated files. - * - * Note: This can be somewhat problematic, as it edits the links to your CSS files (as well - * as the links to images inside them). - * Also, the directory cache directory needs to be writeable by the php/webserver user. - * PLEASE: Ensure that you test your site out throughly after enabling this module! - * Either that, or don't use this module unless you are sure of what it is doing. - * - * TODO: Add support for minify-ing CSS and Javascript files. (similar to Minify. See: http://code.google.com/p/minify/ or https://github.com/mrclay/minify) - * TODO: For performance reasons: Before performing the regex's, compute the md5 of the CSS & JS files and store somewhere to check later. - * - * @return - * This function returns FALSE if it failed to cache the files, - * and returns TRUE if it was successful. - */ - private function add_cached_auto_html_headers() { - global $config; - - // store local copy for speed. - $autocache_css = $config->get_bool("autocache_css"); - $autocache_js = $config->get_bool("autocache_js"); - $theme_name = $config->get_string('theme', 'default'); - - if (!$autocache_css && !$autocache_js) { - return false; // caching disabled + if(!file_exists("data/cache")) { + mkdir("data/cache"); } - $cache_location = $config->get_string("autocache_location", 'data/cache'); - // Detect is there is a trailing slash, and add one if not. - $cache_location = ((strrpos($cache_location, '/') + 1) == strlen($cache_location)) ? $cache_location : $cache_location.'/'; - - // Create directory if needed. - if(!file_exists($cache_location)) { - if (!mkdir($cache_location, 0750, true)) { - return false; // failed to create directory - } + $css_files = array(); + $css_latest = 0; + foreach(array_merge(zglob("lib/*.css"), zglob("ext/*/style.css"), zglob("themes/$theme_name/style.css")) as $css) { + $css_files[] = $css; + $css_latest = max($css_latest, filemtime($css)); } - - $data_href = get_base_href(); - - /* ----- CSS Files ----- */ - if($autocache_css) { - // First get all the CSS from the lib directory - $contents_from_lib = ''; - $css_files = glob("lib/*.css"); - if($css_files) { - foreach($css_files as $css_file) { - $contents_from_lib .= file_get_contents($css_file); - } - // Can't directly cache the CSS files, as they might have relative locations to images, etc. in them. - // We have to adjust the URLs accordingly before saving the cached file. + $css_cache_file = "data/cache/style.$css_latest.css"; + if(!file_exists($css_cache_file)) { + $css_data = ""; + foreach($css_files as $file) { + $file_data = file_get_contents($file); $pattern = '/url[\s]*\([\s]*["\']?([^"\'\)]+)["\']?[\s]*\)/'; - $replace = 'url("../../lib/${1}")'; - $contents_from_lib = preg_replace($pattern, $replace, $contents_from_lib); - } - // Next get all the CSS from the extensions - $contents_from_extensions = ''; - $css_files = glob("ext/*/style.css"); - if($css_files) { - foreach($css_files as $css_file) { - $contents_from_extensions .= file_get_contents($css_file); - } - // Can't directly cache the CSS files, as they might have relative locations to images, etc. in them. - // We have to adjust the URLs accordingly before saving the cached file. - $pattern = '/url[\s]*\([\s]*["\']?([^"\'\)]+)["\']?[\s]*\)/'; - $replace = 'url("../../${1}")'; - $contents_from_extensions = preg_replace($pattern, $replace, $contents_from_extensions); - } - // Get CSS from theme - $contents_from_theme = ''; - $css_files = glob("themes/$theme_name/style.css"); - if($css_files) { - foreach($css_files as $css_file) { - $contents_from_theme .= file_get_contents($css_file); - } - // Can't directly cache the CSS files, as they might have relative locations to images, etc. in them. - // We have to adjust the URLs accordingly before saving the cached file. - $pattern = '/url[\s]*\([\s]*["\']?([^"\'\)]+)["\']?[\s]*\)/'; - $replace = 'url("../../${1}")'; - $contents_from_theme = preg_replace($pattern, $replace, $contents_from_theme); - } - // Combine the three - $data = $contents_from_lib .' '. $contents_from_extensions .' '. $contents_from_theme; - - // Minify the CSS if enabled. - if($config->get_bool("autocache_min_css")) { - // not supported yet. - // TODO: add support for Minifying CSS files. + $replace = 'url("../../'.dirname($file).'/$1")'; + $file_data = preg_replace($pattern, $replace, $file_data); + $css_data .= $file_data . "\n"; } + file_put_contents($css_cache_file, $css_data) + } + $this->add_html_header(""); - // compute the MD5 sum of the concatenated CSS files - $md5sum = md5($data); - - if(!file_exists($cache_location.$md5sum.'.css')) { - // remove any old cached CSS files. - $mask = '*.css'; - array_map( 'unlink', glob( $mask ) ); - - // output the combined file - if(file_put_contents($cache_location.$md5sum.'.css', $data, LOCK_EX) === FALSE) { - return false; // failed to write the file - } - } - // tell the client where to get the css cache file - $this->add_html_header(''); + $js_files = array(); + $js_latest = 0; + foreach(array_merge(zglob("lib/*.js"), zglob("ext/*/style.js"), zglob("themes/$theme_name/style.js")) as $js) { + $js_files[] = $js; + $js_latest = max($js_latest, filemtime($js)); } - else { - // Caching of CSS disabled. - foreach(glob("lib/*.css") as $css) { - $this->add_html_header(''); - } - $css_files = glob("ext/*/style.css"); - if($css_files) { - foreach($css_files as $css_file) { - $this->add_html_header(''); - } - } - $css_files = glob("themes/$theme_name/style.css"); - if($css_files) { - foreach($css_files as $css_file) { - $this->add_html_header(''); - } + $js_cache_file = "data/cache/style.$js_latest.js"; + if(!file_exists($js_cache_file)) { + $js_data = ""; + foreach($js_files as $file) { + $js_data .= file_get_contents($file) . "\n"; } + file_put_contents($js_cache_file, $js_data) } - - - /* ----- JavaScript Files ----- */ - if($autocache_js) { - $data = ''; - $js_files = glob("lib/*.js"); - if($js_files) { - foreach($js_files as $js_file) { - $data .= file_get_contents($js_file); - } - } - $js_files = glob("ext/*/script.js"); - if($js_files) { - foreach($js_files as $js_file) { - $data .= file_get_contents($js_file); - } - } - // Minify the JS if enabled. - if ($config->get_bool("autocache_min_js")){ - // not supported yet. - // TODO: add support for Minifying JS files. - } - - // compute the MD5 sum of the concatenated JavaScript files - $md5sum = md5($data); - - if (!file_exists($cache_location.$md5sum.'.js')) { - // remove any old cached js files. - $mask = '*.js'; - array_map( 'unlink', glob( $mask ) ); - // output the combined file - if (file_put_contents($cache_location.$md5sum.'.js', $data, LOCK_EX) === FALSE) { - return false; - } - } - // tell the client where to get the js cache file - $this->add_html_header(''); - } - else { - // Caching of Javascript disabled. - foreach(glob("lib/*.js") as $js) { - $this->add_html_header(''); - } - $js_files = glob("ext/*/script.js"); - if($js_files) { - foreach($js_files as $js_file) { - $this->add_html_header(''); - } - } - } - - return true; + $this->add_html_header(""); } } ?> diff --git a/core/util.inc.php b/core/util.inc.php index b9b5e905..5111ff3c 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -361,6 +361,11 @@ function mtimefile($file) { return "$data_href/$file?$mtime"; } +function zglob($pattern) { + $r = glob($pattern); + if($r) return $r; + else return array(); +} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ diff --git a/ext/setup/main.php b/ext/setup/main.php index b20e8b45..195c0904 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -166,12 +166,6 @@ class Setup extends Extension { $config->set_default_string("theme", "default"); $config->set_default_bool("word_wrap", true); $config->set_default_bool("comment_captcha", false); - // Automatic caching is disabled by default - $config->set_default_string("autocache_location", "data/cache"); - $config->set_default_bool("autocache_css", false); - $config->set_default_bool("autocache_jss", false); - $config->set_default_bool("autocache_min_css", false); - $config->set_default_bool("autocache_min_js", false); } public function onPageRequest(PageRequestEvent $event) { @@ -279,19 +273,6 @@ class Setup extends Extension { $sb->add_text_option("api_recaptcha_privkey", "
Private key: "); $sb->add_text_option("api_recaptcha_pubkey", "
Public key: "); $event->panel->add_block($sb); - - - $sb = new SetupBlock("Automatic Caching of CSS & JS"); - // the default is fine for just about everyone - //$sb->add_text_option("autocache_location", "Location: "); - //$sb->add_label("
This location needs to be writeable by the webserver."); - $sb->add_bool_option("autocache_css", "Automatic caching of CSS: "); - $sb->add_bool_option("autocache_js", "
Automatic caching of JS: "); - // if the option does nothing, there's no point showing a - // "hey look, nothing!" message... - //$sb->add_bool_option("autocache_min_css", "
Minimize CSS files: "); - //$sb->add_bool_option("autocache_min_js", "
Minimize JS files: "); - $event->panel->add_block($sb); } public function onConfigSave(ConfigSaveEvent $event) { From 88767b4c9682459a3f28f8706cd49d1dc4fae96e Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 22 Mar 2012 12:15:03 +0000 Subject: [PATCH 04/51] syntax --- core/page.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/page.class.php b/core/page.class.php index dd28bd75..b340d163 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -266,7 +266,7 @@ class Page { $file_data = preg_replace($pattern, $replace, $file_data); $css_data .= $file_data . "\n"; } - file_put_contents($css_cache_file, $css_data) + file_put_contents($css_cache_file, $css_data); } $this->add_html_header(""); @@ -276,13 +276,13 @@ class Page { $js_files[] = $js; $js_latest = max($js_latest, filemtime($js)); } - $js_cache_file = "data/cache/style.$js_latest.js"; + $js_cache_file = "data/cache/script.$js_latest.js"; if(!file_exists($js_cache_file)) { $js_data = ""; foreach($js_files as $file) { $js_data .= file_get_contents($file) . "\n"; } - file_put_contents($js_cache_file, $js_data) + file_put_contents($js_cache_file, $js_data); } $this->add_html_header(""); } From 45beb5a9251dced2f9c5cbbd53570ca8ba623775 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 22 Mar 2012 12:28:32 +0000 Subject: [PATCH 05/51] lack of semicolon breaks script combining --- lib/jquery.lazyload.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jquery.lazyload.min.js b/lib/jquery.lazyload.min.js index e82a9d9d..ac769a99 100644 --- a/lib/jquery.lazyload.min.js +++ b/lib/jquery.lazyload.min.js @@ -12,4 +12,4 @@ * Version: 1.7.2 * */ -(function(a,b){$window=a(b),a.fn.lazyload=function(c){function f(){var b=0;d.each(function(){var c=a(this);if(e.skip_invisible&&!c.is(":visible"))return;if(!a.abovethetop(this,e)&&!a.leftofbegin(this,e))if(!a.belowthefold(this,e)&&!a.rightoffold(this,e))c.trigger("appear");else if(++b>e.failure_limit)return!1})}var d=this,e={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:b,data_attribute:"original",skip_invisible:!0,appear:null,load:null};return c&&(undefined!==c.failurelimit&&(c.failure_limit=c.failurelimit,delete c.failurelimit),undefined!==c.effectspeed&&(c.effect_speed=c.effectspeed,delete c.effectspeed),a.extend(e,c)),$container=e.container===undefined||e.container===b?$window:a(e.container),0===e.event.indexOf("scroll")&&$container.bind(e.event,function(a){return f()}),this.each(function(){var b=this,c=a(b);b.loaded=!1,c.one("appear",function(){if(!this.loaded){if(e.appear){var f=d.length;e.appear.call(b,f,e)}a("").bind("load",function(){c.hide().attr("src",c.data(e.data_attribute))[e.effect](e.effect_speed),b.loaded=!0;var f=a.grep(d,function(a){return!a.loaded});d=a(f);if(e.load){var g=d.length;e.load.call(b,g,e)}}).attr("src",c.data(e.data_attribute))}}),0!==e.event.indexOf("scroll")&&c.bind(e.event,function(a){b.loaded||c.trigger("appear")})}),$window.bind("resize",function(a){f()}),f(),this},a.belowthefold=function(c,d){var e;return d.container===undefined||d.container===b?e=$window.height()+$window.scrollTop():e=$container.offset().top+$container.height(),e<=a(c).offset().top-d.threshold},a.rightoffold=function(c,d){var e;return d.container===undefined||d.container===b?e=$window.width()+$window.scrollLeft():e=$container.offset().left+$container.width(),e<=a(c).offset().left-d.threshold},a.abovethetop=function(c,d){var e;return d.container===undefined||d.container===b?e=$window.scrollTop():e=$container.offset().top,e>=a(c).offset().top+d.threshold+a(c).height()},a.leftofbegin=function(c,d){var e;return d.container===undefined||d.container===b?e=$window.scrollLeft():e=$container.offset().left,e>=a(c).offset().left+d.threshold+a(c).width()},a.inviewport=function(b,c){return!a.rightofscreen(b,c)&&!a.leftofscreen(b,c)&&!a.belowthefold(b,c)&&!a.abovethetop(b,c)},a.extend(a.expr[":"],{"below-the-fold":function(c){return a.belowthefold(c,{threshold:0,container:b})},"above-the-top":function(c){return!a.belowthefold(c,{threshold:0,container:b})},"right-of-screen":function(c){return a.rightoffold(c,{threshold:0,container:b})},"left-of-screen":function(c){return!a.rightoffold(c,{threshold:0,container:b})},"in-viewport":function(c){return!a.inviewport(c,{threshold:0,container:b})},"above-the-fold":function(c){return!a.belowthefold(c,{threshold:0,container:b})},"right-of-fold":function(c){return a.rightoffold(c,{threshold:0,container:b})},"left-of-fold":function(c){return!a.rightoffold(c,{threshold:0,container:b})}})})(jQuery,window) +(function(a,b){$window=a(b),a.fn.lazyload=function(c){function f(){var b=0;d.each(function(){var c=a(this);if(e.skip_invisible&&!c.is(":visible"))return;if(!a.abovethetop(this,e)&&!a.leftofbegin(this,e))if(!a.belowthefold(this,e)&&!a.rightoffold(this,e))c.trigger("appear");else if(++b>e.failure_limit)return!1})}var d=this,e={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:b,data_attribute:"original",skip_invisible:!0,appear:null,load:null};return c&&(undefined!==c.failurelimit&&(c.failure_limit=c.failurelimit,delete c.failurelimit),undefined!==c.effectspeed&&(c.effect_speed=c.effectspeed,delete c.effectspeed),a.extend(e,c)),$container=e.container===undefined||e.container===b?$window:a(e.container),0===e.event.indexOf("scroll")&&$container.bind(e.event,function(a){return f()}),this.each(function(){var b=this,c=a(b);b.loaded=!1,c.one("appear",function(){if(!this.loaded){if(e.appear){var f=d.length;e.appear.call(b,f,e)}a("").bind("load",function(){c.hide().attr("src",c.data(e.data_attribute))[e.effect](e.effect_speed),b.loaded=!0;var f=a.grep(d,function(a){return!a.loaded});d=a(f);if(e.load){var g=d.length;e.load.call(b,g,e)}}).attr("src",c.data(e.data_attribute))}}),0!==e.event.indexOf("scroll")&&c.bind(e.event,function(a){b.loaded||c.trigger("appear")})}),$window.bind("resize",function(a){f()}),f(),this},a.belowthefold=function(c,d){var e;return d.container===undefined||d.container===b?e=$window.height()+$window.scrollTop():e=$container.offset().top+$container.height(),e<=a(c).offset().top-d.threshold},a.rightoffold=function(c,d){var e;return d.container===undefined||d.container===b?e=$window.width()+$window.scrollLeft():e=$container.offset().left+$container.width(),e<=a(c).offset().left-d.threshold},a.abovethetop=function(c,d){var e;return d.container===undefined||d.container===b?e=$window.scrollTop():e=$container.offset().top,e>=a(c).offset().top+d.threshold+a(c).height()},a.leftofbegin=function(c,d){var e;return d.container===undefined||d.container===b?e=$window.scrollLeft():e=$container.offset().left,e>=a(c).offset().left+d.threshold+a(c).width()},a.inviewport=function(b,c){return!a.rightofscreen(b,c)&&!a.leftofscreen(b,c)&&!a.belowthefold(b,c)&&!a.abovethetop(b,c)},a.extend(a.expr[":"],{"below-the-fold":function(c){return a.belowthefold(c,{threshold:0,container:b})},"above-the-top":function(c){return!a.belowthefold(c,{threshold:0,container:b})},"right-of-screen":function(c){return a.rightoffold(c,{threshold:0,container:b})},"left-of-screen":function(c){return!a.rightoffold(c,{threshold:0,container:b})},"in-viewport":function(c){return!a.inviewport(c,{threshold:0,container:b})},"above-the-fold":function(c){return!a.belowthefold(c,{threshold:0,container:b})},"right-of-fold":function(c){return a.rightoffold(c,{threshold:0,container:b})},"left-of-fold":function(c){return!a.rightoffold(c,{threshold:0,container:b})}})})(jQuery,window); From 10859255040c9caa1ab4a15729b88c75211c10ab Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 22 Mar 2012 12:30:02 +0000 Subject: [PATCH 06/51] css=style, js=script --- 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 b340d163..dae6dd9b 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -272,7 +272,7 @@ class Page { $js_files = array(); $js_latest = 0; - foreach(array_merge(zglob("lib/*.js"), zglob("ext/*/style.js"), zglob("themes/$theme_name/style.js")) as $js) { + foreach(array_merge(zglob("lib/*.js"), zglob("ext/*/script.js"), zglob("themes/$theme_name/script.js")) as $js) { $js_files[] = $js; $js_latest = max($js_latest, filemtime($js)); } From da786ee3c174784f1956d74d7b1ae09056753b76 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 22 Mar 2012 13:18:15 +0000 Subject: [PATCH 07/51] tags on thumb element --- core/basethemelet.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index aa07045a..075122fa 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -34,6 +34,7 @@ class BaseThemelet { $h_view_link = make_link('post/view/'.$i_id, $query); $h_thumb_link = $image->get_thumb_link(); $h_tip = html_escape($image->get_tooltip()); + $h_tags = strtolower($image->get_tag_list()); $base = get_base_href(); // If file is flash or svg then sets thumbnail to max size. @@ -44,7 +45,7 @@ class BaseThemelet { $tsize = get_thumbnail_size($image->width, $image->height); } - return ''. + return ''. ''.$h_tip.''. ''. "\n"; From 2226bc9f156afa5eed774573df9a0af076573e86 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 22 Mar 2012 13:40:13 +0000 Subject: [PATCH 08/51] hide thumbnails with given tags --- ext/index/script.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 ext/index/script.js diff --git a/ext/index/script.js b/ext/index/script.js new file mode 100644 index 00000000..98d997ea --- /dev/null +++ b/ext/index/script.js @@ -0,0 +1,10 @@ +$(function() { + var blocked_tags = ($.cookie("blocked-tags") || "").split(" "); + for(i in blocked_tags) { + var tag = blocked_tags[i]; + if(tag) $(".thumb[data-tags~='"+tag+"']").hide(); + } + // FIXME: need to trigger a reflow in opera, because opera implements + // text-align: justify with element margins and doesn't recalculate + // these margins when part of the line disappears... +}); From 898df24dd94e03c6c571af45d2c30a4a1bc2d0e9 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 22 Mar 2012 14:19:46 +0000 Subject: [PATCH 09/51] function for selecting blocks --- ext/index/script.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ext/index/script.js b/ext/index/script.js index 98d997ea..f49c3b95 100644 --- a/ext/index/script.js +++ b/ext/index/script.js @@ -8,3 +8,11 @@ $(function() { // text-align: justify with element margins and doesn't recalculate // these margins when part of the line disappears... }); + +function select_blocked_tags() { + var blocked_tags = prompt("Enter tags to ignore", $.cookie("blocked-tags") || "My_Little_Pony"); + if(blocked_tags) { + $.cookie("blocked-tags", blocked_tags.toLowerCase(), {path: '/'}); + location.reload(true); + } +} From cfe054775552d0ac57203eb4b50d69f082af3896 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 22 Mar 2012 15:44:04 +0000 Subject: [PATCH 10/51] force reflow after hiding some thumbs --- ext/index/script.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/index/script.js b/ext/index/script.js index f49c3b95..b4a6776f 100644 --- a/ext/index/script.js +++ b/ext/index/script.js @@ -4,9 +4,11 @@ $(function() { var tag = blocked_tags[i]; if(tag) $(".thumb[data-tags~='"+tag+"']").hide(); } - // FIXME: need to trigger a reflow in opera, because opera implements + // need to trigger a reflow in opera, because opera implements // text-align: justify with element margins and doesn't recalculate // these margins when part of the line disappears... + $('#image-list').hide(); + $('#image-list').show(); }); function select_blocked_tags() { From f993b3c19d9cbf6bebe9794dde709a19d987bf5c Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 22 Mar 2012 16:28:57 +0000 Subject: [PATCH 11/51] js cookie expires --- ext/index/script.js | 2 +- lib/shimmie.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/index/script.js b/ext/index/script.js index b4a6776f..b446f72b 100644 --- a/ext/index/script.js +++ b/ext/index/script.js @@ -14,7 +14,7 @@ $(function() { function select_blocked_tags() { var blocked_tags = prompt("Enter tags to ignore", $.cookie("blocked-tags") || "My_Little_Pony"); if(blocked_tags) { - $.cookie("blocked-tags", blocked_tags.toLowerCase(), {path: '/'}); + $.cookie("blocked-tags", blocked_tags.toLowerCase(), {path: '/', expires: 365}); location.reload(true); } } diff --git a/lib/shimmie.js b/lib/shimmie.js index 8eb6f616..e33d779a 100644 --- a/lib/shimmie.js +++ b/lib/shimmie.js @@ -63,7 +63,7 @@ $(document).ready(function() { } } } - $.cookie("sidebar-hidden", sidebar_hidden.join("|"), {path: '/'}); + $.cookie("sidebar-hidden", sidebar_hidden.join("|"), {path: '/', expires: 365}); }) }); From ecad3b9891d14933e0edc8e4c98e5bbbf4a31a9d Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 22 Mar 2012 16:35:44 +0000 Subject: [PATCH 12/51] only refresh if needed --- ext/index/script.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ext/index/script.js b/ext/index/script.js index b446f72b..605d32d5 100644 --- a/ext/index/script.js +++ b/ext/index/script.js @@ -1,14 +1,20 @@ $(function() { var blocked_tags = ($.cookie("blocked-tags") || "").split(" "); + var needs_refresh = false; for(i in blocked_tags) { var tag = blocked_tags[i]; - if(tag) $(".thumb[data-tags~='"+tag+"']").hide(); + if(tag) { + $(".thumb[data-tags~='"+tag+"']").hide(); + needs_refresh = true; + } } // need to trigger a reflow in opera, because opera implements // text-align: justify with element margins and doesn't recalculate // these margins when part of the line disappears... - $('#image-list').hide(); - $('#image-list').show(); + if(needs_refresh) { + $('#image-list').hide(); + $('#image-list').show(); + } }); function select_blocked_tags() { From eb705d29f57efdfc97c76372e62f19d8a701d2ec Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Mar 2012 11:16:59 +0000 Subject: [PATCH 13/51] image scaling cookie --- ext/handle_pixel/main.php | 13 +++++++++++++ ext/handle_pixel/script.js | 30 ++++++++++++++++++++++++++++++ ext/handle_pixel/theme.php | 36 ++---------------------------------- 3 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 ext/handle_pixel/script.js diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 36dbef25..061a155a 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -75,6 +75,19 @@ class PixelFileHandler extends DataHandlerExtension { return $ok; } + + public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) { + $event->add_part(" +
+ +
+ ", 20); + } // IM thumber {{{ private function make_thumb_convert(/*string*/ $inname, /*string*/ $outname) { diff --git a/ext/handle_pixel/script.js b/ext/handle_pixel/script.js new file mode 100644 index 00000000..796d55c8 --- /dev/null +++ b/ext/handle_pixel/script.js @@ -0,0 +1,30 @@ +$(function() { + $("#zoomer").change(function(e) { + zoom(this.options[this.selectedIndex].value); + $.cookie("ui-image-zoom", this.options[this.selectedIndex].value, {path: '/', expires: 365}); + }); + + if($.cookie("ui-image-zoom")) { + zoom($.cookie("ui-image-zoom")); + } +}); + +function zoom(zoom) { + var img = $('#main_image'); + if(zoom == "full") { + img.css('max-width', img.data('width') + 'px'); + img.css('max-height', img.data('height') + 'px'); + } + if(zoom == "width") { + img.css('max-width', '90%'); + img.css('max-height', img.data('height') + 'px'); + } + if(zoom == "height") { + img.css('max-width', img.data('width') + 'px'); + img.css('max-height', (window.innerHeight * 0.9) + 'px'); + } + if(zoom == "both") { + img.css('max-width', '90%'); + img.css('max-height', (window.innerHeight * 0.9) + 'px'); + } +} diff --git a/ext/handle_pixel/theme.php b/ext/handle_pixel/theme.php index 88c14d63..03e6c99f 100644 --- a/ext/handle_pixel/theme.php +++ b/ext/handle_pixel/theme.php @@ -5,7 +5,6 @@ class PixelFileHandlerTheme extends Themelet { global $config; $u_ilink = $image->get_image_link(); - $html = "main image"; if($config->get_bool("image_show_meta") && function_exists("exif_read_data")) { # FIXME: only read from jpegs? $exif = @exif_read_data($image->get_image_filename(), 0, true); @@ -24,39 +23,8 @@ class PixelFileHandlerTheme extends Themelet { } } - $zoom_default = $config->get_bool("image_zoom", false) ? "scale(img);" : ""; - $zoom = ""; - - $page->add_block(new Block("Image", $html.$zoom, "main", 10)); + $html = "main image"; + $page->add_block(new Block("Image", $html, "main", 10)); } } ?> From 31b3113d496c8a41962812743b233632ba4d70f3 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Mar 2012 11:19:24 +0000 Subject: [PATCH 14/51] ui cookie --- lib/shimmie.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/shimmie.js b/lib/shimmie.js index e33d779a..b41d41de 100644 --- a/lib/shimmie.js +++ b/lib/shimmie.js @@ -38,7 +38,7 @@ $(document).ready(function() { }); try { - var sidebar_hidden = ($.cookie("sidebar-hidden") || "").split("|"); + var sidebar_hidden = ($.cookie("ui-sidebar-hidden") || "").split("|"); for(var i in sidebar_hidden) { if(sidebar_hidden[i].length > 0) { $(sidebar_hidden[i]+" .blockbody").hide(); @@ -63,7 +63,7 @@ $(document).ready(function() { } } } - $.cookie("sidebar-hidden", sidebar_hidden.join("|"), {path: '/', expires: 365}); + $.cookie("ui-sidebar-hidden", sidebar_hidden.join("|"), {path: '/', expires: 365}); }) }); From 0b45042161632c633eef9bf10c8fda5f759c54ad Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Mar 2012 11:23:06 +0000 Subject: [PATCH 15/51] ui- prefix for UI cookies --- ext/index/script.js | 6 +++--- lib/shimmie.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/index/script.js b/ext/index/script.js index 605d32d5..61a840f9 100644 --- a/ext/index/script.js +++ b/ext/index/script.js @@ -1,5 +1,5 @@ $(function() { - var blocked_tags = ($.cookie("blocked-tags") || "").split(" "); + var blocked_tags = ($.cookie("ui-blocked-tags") || $.cookie("blocked-tags") || "").split(" "); var needs_refresh = false; for(i in blocked_tags) { var tag = blocked_tags[i]; @@ -18,9 +18,9 @@ $(function() { }); function select_blocked_tags() { - var blocked_tags = prompt("Enter tags to ignore", $.cookie("blocked-tags") || "My_Little_Pony"); + var blocked_tags = prompt("Enter tags to ignore", $.cookie("ui-blocked-tags") || "My_Little_Pony"); if(blocked_tags) { - $.cookie("blocked-tags", blocked_tags.toLowerCase(), {path: '/', expires: 365}); + $.cookie("ui-blocked-tags", blocked_tags.toLowerCase(), {path: '/', expires: 365}); location.reload(true); } } diff --git a/lib/shimmie.js b/lib/shimmie.js index b41d41de..7bc91bff 100644 --- a/lib/shimmie.js +++ b/lib/shimmie.js @@ -38,7 +38,7 @@ $(document).ready(function() { }); try { - var sidebar_hidden = ($.cookie("ui-sidebar-hidden") || "").split("|"); + var sidebar_hidden = ($.cookie("ui-sidebar-hidden") || $.cookie("sidebar-hidden") || "").split("|"); for(var i in sidebar_hidden) { if(sidebar_hidden[i].length > 0) { $(sidebar_hidden[i]+" .blockbody").hide(); From 8336fbfce5f26d47c86a868c1c006c6eb369624e Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Mar 2012 11:48:44 +0000 Subject: [PATCH 16/51] and update the select box from cookie --- ext/handle_pixel/script.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/handle_pixel/script.js b/ext/handle_pixel/script.js index 796d55c8..b0dc126b 100644 --- a/ext/handle_pixel/script.js +++ b/ext/handle_pixel/script.js @@ -5,6 +5,7 @@ $(function() { }); if($.cookie("ui-image-zoom")) { + $("#zoomer").val($.cookie("ui-image-zoom")); zoom($.cookie("ui-image-zoom")); } }); From 1d4836e6c4d488d84a87f8beab213e70e93277e3 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Mar 2012 23:30:19 +0000 Subject: [PATCH 17/51] toggle zoom on click --- ext/handle_pixel/script.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ext/handle_pixel/script.js b/ext/handle_pixel/script.js index b0dc126b..c264f6e4 100644 --- a/ext/handle_pixel/script.js +++ b/ext/handle_pixel/script.js @@ -1,7 +1,13 @@ $(function() { $("#zoomer").change(function(e) { zoom(this.options[this.selectedIndex].value); - $.cookie("ui-image-zoom", this.options[this.selectedIndex].value, {path: '/', expires: 365}); + }); + + $("#main_image").click(function(e) { + switch($.cookie("ui-image-zoom")) { + case "full": zoom("width"); break; + default: zoom("full"); break; + } }); if($.cookie("ui-image-zoom")) { @@ -17,15 +23,16 @@ function zoom(zoom) { img.css('max-height', img.data('height') + 'px'); } if(zoom == "width") { - img.css('max-width', '90%'); + img.css('max-width', '95%'); img.css('max-height', img.data('height') + 'px'); } if(zoom == "height") { img.css('max-width', img.data('width') + 'px'); - img.css('max-height', (window.innerHeight * 0.9) + 'px'); + img.css('max-height', (window.innerHeight * 0.95) + 'px'); } if(zoom == "both") { - img.css('max-width', '90%'); - img.css('max-height', (window.innerHeight * 0.9) + 'px'); + img.css('max-width', '95%'); + img.css('max-height', (window.innerHeight * 0.95) + 'px'); } + $.cookie("ui-image-zoom", zoom, {path: '/', expires: 365}); } From 5efdbdeb91d1153782c9c2348699e6914e56275f Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Mar 2012 23:34:00 +0000 Subject: [PATCH 18/51] set zoomer val on shotcut too --- ext/handle_pixel/script.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/handle_pixel/script.js b/ext/handle_pixel/script.js index c264f6e4..c95bc3e0 100644 --- a/ext/handle_pixel/script.js +++ b/ext/handle_pixel/script.js @@ -11,7 +11,6 @@ $(function() { }); if($.cookie("ui-image-zoom")) { - $("#zoomer").val($.cookie("ui-image-zoom")); zoom($.cookie("ui-image-zoom")); } }); @@ -34,5 +33,8 @@ function zoom(zoom) { img.css('max-width', '95%'); img.css('max-height', (window.innerHeight * 0.95) + 'px'); } + + $("#zoomer").val(zoom); + $.cookie("ui-image-zoom", zoom, {path: '/', expires: 365}); } From 266f3c4a9a87dbe938151ae83a3a73e8768b8604 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Mar 2012 02:20:51 +0100 Subject: [PATCH 19/51] quotes on single lines --- 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 eb5acf05..8b613af7 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -33,7 +33,7 @@ class BBCode extends FormatterExtension { ) as $el) { $text = preg_replace("!\[$el\](.*?)\[/$el\]!s", "<$el>$1", $text); } - $text = preg_replace('!>>([^\d].+)!s', '
$1
', $text); + $text = preg_replace('!>>([^\d].+)!', '
$1
', $text); $text = preg_replace('!>>(\d+)(#c?\d+)?!s', '>>$1$2', $text); $text = preg_replace('!\[url=site://(.*?)(#c\d+)?\](.*?)\[/url\]!s', '$3', $text); $text = preg_replace('!\[url\]site://(.*?)(#c\d+)?\[/url\]!s', '$1$2', $text); From ed4dc632e6eb80772f39d8de8981e44167fceb8f Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Mar 2012 02:29:45 +0100 Subject: [PATCH 20/51] Ugh, PDO doesn't support arrays... --- contrib/numeric_score/main.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index c9811538..78b0f83a 100644 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -97,11 +97,10 @@ class NumericScore extends Extension { $image_ids = $database->get_col("SELECT image_id FROM numeric_score_votes WHERE user_id=?", array($user_id)); $database->execute( - "DELETE FROM numeric_score_votes WHERE user_id=? AND image_id IN ?", - array($user_id, $image_ids)); + "DELETE FROM numeric_score_votes WHERE user_id=? AND image_id IN (".implode(",", $image_ids).")", + array($user_id)); $database->execute( - "UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=images.id) WHERE images.id IN ?", - array($image_ids)); + "UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=images.id) WHERE images.id IN (".implode(",", $image_ids).")"); $page->set_mode("redirect"); $page->set_redirect(make_link()); } From b628bcfa86e72a99c89dcdbe26ae65cbcc6d22d6 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Mar 2012 02:41:33 +0100 Subject: [PATCH 21/51] user deletion event, with vote deletion --- contrib/numeric_score/main.php | 25 +++++++++++++++++-------- ext/user/main.php | 10 ++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index 78b0f83a..19f820e2 100644 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -93,14 +93,7 @@ class NumericScore extends Extension { } if($event->page_matches("numeric_score/remove_votes_by") && $user->check_auth_token()) { if($user->is_admin()) { - $user_id = int_escape($_POST['user_id']); - $image_ids = $database->get_col("SELECT image_id FROM numeric_score_votes WHERE user_id=?", array($user_id)); - - $database->execute( - "DELETE FROM numeric_score_votes WHERE user_id=? AND image_id IN (".implode(",", $image_ids).")", - array($user_id)); - $database->execute( - "UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=images.id) WHERE images.id IN (".implode(",", $image_ids).")"); + $this->delete_votes_by(int_escape($_POST['user_id'])); $page->set_mode("redirect"); $page->set_redirect(make_link()); } @@ -190,6 +183,22 @@ class NumericScore extends Extension { $database->execute("DELETE FROM numeric_score_votes WHERE image_id=:id", array("id" => $event->image->id)); } + public function onUserDeletion(UserDeletionEvent $event) { + $this->delete_votes_by($event->id); + } + + public function delete_votes_by(/*int*/ $user_id) { + global $database; + + $image_ids = $database->get_col("SELECT image_id FROM numeric_score_votes WHERE user_id=?", array($user_id)); + + $database->execute( + "DELETE FROM numeric_score_votes WHERE user_id=? AND image_id IN (".implode(",", $image_ids).")", + array($user_id)); + $database->execute( + "UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=images.id) WHERE images.id IN (".implode(",", $image_ids).")"); + } + // FIXME: on user deletion // FIXME: on user vote nuke diff --git a/ext/user/main.php b/ext/user/main.php index 57288c27..4277fbef 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -40,6 +40,14 @@ class UserCreationEvent extends Event { } } +class UserDeletionEvent extends Event { + var $id; + + public function __construct($id) { + $this->id = $id; + } +} + class UserCreationException extends SCoreException {} class UserPage extends Extension { @@ -511,6 +519,8 @@ class UserPage extends Extension { ); } + send_event(new UserDeletionEvent($_POST['id'])); + $database->execute( "DELETE FROM users WHERE id = :id", array("id" => $_POST['id']) From cd8ec7bf41c331c709874a6a9087dc6ea6b9950a Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Mar 2012 03:32:32 +0100 Subject: [PATCH 22/51] sort alias CSV file the same way as the table --- ext/alias_editor/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 ext/alias_editor/main.php diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php old mode 100755 new mode 100644 index f03f0bac..8fc18a30 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -122,7 +122,7 @@ class AliasEditor extends Extension { private function get_alias_csv(Database $database) { $csv = ""; - $aliases = $database->get_pairs("SELECT oldtag, newtag FROM aliases"); + $aliases = $database->get_pairs("SELECT oldtag, newtag FROM aliases ORDER BY newtag"); foreach($aliases as $old => $new) { $csv .= "$old,$new\n"; } From f2f5ec720db30a507da371e5fa5cc4e38fc12676 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Mar 2012 04:11:40 +0100 Subject: [PATCH 23/51] debugging --- ext/image/main.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/image/main.php b/ext/image/main.php index d991a674..a43ffcf7 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -433,7 +433,8 @@ class ImageIO extends Extension { } if(!empty($image->source)) { if(!preg_match("#^(https?|ftp)://#", $image->source)) { - throw new ImageReplaceException("Image's source isn't a valid URL"); + $h_url = html_escape($image->source); + throw new ImageReplaceException("Image's source isn't a valid URL ($h_url)"); } } From 7a6ef551147553ee2af34fe2f3ae4a025e52863b Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Mar 2012 04:45:47 +0100 Subject: [PATCH 24/51] bleh, source validation. Anything is allowed and it's only linked on output if appropriate --- ext/image/main.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/ext/image/main.php b/ext/image/main.php index a43ffcf7..ca902f4c 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -298,11 +298,6 @@ class ImageIO extends Extension { if(strlen(trim($image->source)) == 0) { $image->source = null; } - if(!empty($image->source)) { - if(!preg_match("#^(https?|ftp)://#", $image->source)) { - throw new ImageAdditionException("Image's source isn't a valid URL"); - } - } /* * Check for an existing image @@ -431,12 +426,6 @@ class ImageIO extends Extension { if(strlen(trim($image->source)) == 0) { $image->source = $existing->get_source(); } - if(!empty($image->source)) { - if(!preg_match("#^(https?|ftp)://#", $image->source)) { - $h_url = html_escape($image->source); - throw new ImageReplaceException("Image's source isn't a valid URL ($h_url)"); - } - } /* This step could be optional, ie: perhaps move the image somewhere From 761c733c57616964fd33858b011b62da53220613 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 29 Mar 2012 19:18:00 +0100 Subject: [PATCH 25/51] coalsce when cleaning votes --- contrib/numeric_score/main.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index 19f820e2..2efddc3a 100644 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -195,8 +195,17 @@ class NumericScore extends Extension { $database->execute( "DELETE FROM numeric_score_votes WHERE user_id=? AND image_id IN (".implode(",", $image_ids).")", array($user_id)); - $database->execute( - "UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=images.id) WHERE images.id IN (".implode(",", $image_ids).")"); + $database->execute(" + UPDATE images + SET numeric_score=COALESCE( + ( + SELECT SUM(score) + FROM numeric_score_votes + WHERE image_id=images.id + ), + 0 + ) + WHERE images.id IN (".implode(",", $image_ids).")"); } // FIXME: on user deletion From d7578e754fa386b16b0d40cdc735c5725505c659 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 29 Mar 2012 21:12:24 +0100 Subject: [PATCH 26/51] test for mass tag edit --- ext/tag_edit/test.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ext/tag_edit/test.php b/ext/tag_edit/test.php index f620b42b..79ac50fb 100644 --- a/ext/tag_edit/test.php +++ b/ext/tag_edit/test.php @@ -45,11 +45,23 @@ class TagEditTest extends ShimmieWebTestCase { function testMassEdit() { $this->log_in_as_admin(); + + $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); + $this->get_page("post/view/$image_id"); + $this->assert_title("Image $image_id: pbx"); + $this->get_page("admin"); $this->assert_text("Mass Tag Edit"); // just test it exists - $this->log_out(); + $this->set_field("search", "pbx"); + $this->set_field("replace", "pox"); + $this->click("Set"); - # FIXME: test mass tag editor + $this->get_page("post/view/$image_id"); + $this->assert_title("Image $image_id: pox"); + + $this->delete_image($image_id); + + $this->log_out(); } } ?> From e7fc084f445ee48fbb97201e2414d37d2089d634 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 29 Mar 2012 21:31:04 +0100 Subject: [PATCH 27/51] log mass tag edits --- ext/tag_edit/main.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index 6364b404..ffb70982 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -187,6 +187,8 @@ class TagEdit extends Extension { $search_set = Tag::explode($search); $replace_set = Tag::explode($replace); + log_info("tag_edit", "Mass editing tags: '$search' -> '$replace'"); + $last_id = -1; while(true) { // make sure we don't look at the same images twice. From 60666f9300a208d75d9557b32634505ccd791584 Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 12 Mar 2012 07:50:20 +0000 Subject: [PATCH 28/51] getuser now returns latest 5 images --- contrib/shimmie_api/main.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/contrib/shimmie_api/main.php b/contrib/shimmie_api/main.php index e7ddc59e..84f3b0ba 100644 --- a/contrib/shimmie_api/main.php +++ b/contrib/shimmie_api/main.php @@ -120,6 +120,25 @@ class ShimmieApi extends Extension { "SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id", array("owner_id"=>$all['id'])); $all['commentperday'] = sprintf("%.1f", ($all['commentcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1))); + + if(isset($_GET['recent'])){ + $recent = $database->get_all( + "SELECT * FROM images WHERE owner_id=? ORDER BY id DESC LIMIT 0, 5", + array($all['id'])); + + $i = 0; + foreach($recent as $all['recentposts'][$i]){ + unset($all['recentposts'][$i]['owner_id']); //We already know the owners id.. + unset($all['recentposts'][$i]['owner_ip']); + + for($x=0; $x<14; $x++) unset($all['recentposts'][$i][$x]); + if(empty($all['recentposts'][$i]['author'])) unset($all['recentposts'][$i]['author']); + if($all['recentposts'][$i]['notes'] > 0) $all['recentposts'][$i]['has_notes'] = "Y"; + else $all['recentposts'][$i]['has_notes'] = "N"; + unset($all['recentposts'][$i]['notes']); + $i += 1; + } + } $page->set_data(json_encode($all)); } } From 45365f7eb54a6b4d8ecbc12e37d98f66f260817f Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 12 Mar 2012 08:10:36 +0000 Subject: [PATCH 29/51] less errors --- contrib/shimmie_api/main.php | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/contrib/shimmie_api/main.php b/contrib/shimmie_api/main.php index 84f3b0ba..18652442 100644 --- a/contrib/shimmie_api/main.php +++ b/contrib/shimmie_api/main.php @@ -97,31 +97,34 @@ class ShimmieApi extends Extension { if($event->page_matches("api/shimmie/get_user")) { $query = $user->id; + $type = "id"; if($event->count_args() == 1) { $query = $event->get_arg(0); } - if(isset($_GET['name'])) { - $query = $_GET['name']; - } - if(isset($_GET['id'])) { + elseif(isset($_GET['id'])) { $query = $_GET['id']; } + elseif(isset($_GET['name'])) { + $query = $_GET['name']; + $type = "name"; + } $all = $database->get_row( - "SELECT id,name,joindate,class FROM users WHERE name=? OR id=?", - array($_GET['name'], int_escape($_GET['id']))); + "SELECT id,name,joindate,class FROM users WHERE ".$type."=?", + array($query)); - //FIXME?: For some weird reason, get_all seems to return twice. Unsetting second value to make things look nice.. - // - it returns data as eg array(0=>1234, 'id'=>1234, 1=>'bob', 'name'=>bob, ...); - for($i=0; $i<4; $i++) unset($all[$i]); - $all['uploadcount'] = Image::count_images(array("user_id=".$all['id'])); - $all['uploadperday'] = sprintf("%.1f", ($all['uploadcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1))); - $all['commentcount'] = $database->get_one( - "SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id", - array("owner_id"=>$all['id'])); - $all['commentperday'] = sprintf("%.1f", ($all['commentcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1))); + if(!empty($all)){ + //FIXME?: For some weird reason, get_all seems to return twice. Unsetting second value to make things look nice.. + // - it returns data as eg array(0=>1234, 'id'=>1234, 1=>'bob', 'name'=>bob, ...); + for($i=0; $i<4; $i++) unset($all[$i]); + $all['uploadcount'] = Image::count_images(array("user_id=".$all['id'])); + $all['uploadperday'] = sprintf("%.1f", ($all['uploadcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1))); + $all['commentcount'] = $database->get_one( + "SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id", + array("owner_id"=>$all['id'])); + $all['commentperday'] = sprintf("%.1f", ($all['commentcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1))); - if(isset($_GET['recent'])){ + if(isset($_GET['recent'])){ $recent = $database->get_all( "SELECT * FROM images WHERE owner_id=? ORDER BY id DESC LIMIT 0, 5", array($all['id'])); @@ -138,6 +141,7 @@ class ShimmieApi extends Extension { unset($all['recentposts'][$i]['notes']); $i += 1; } + } } $page->set_data(json_encode($all)); } From 44ce23208a504b94233bf3eba1b6460f456cd4d9 Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 17 Mar 2012 12:23:44 +0000 Subject: [PATCH 30/51] tags in tag history now have links to search --- contrib/tag_history/theme.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/tag_history/theme.php b/contrib/tag_history/theme.php index e88a2b81..eaa8761e 100644 --- a/contrib/tag_history/theme.php +++ b/contrib/tag_history/theme.php @@ -27,6 +27,14 @@ class Tag_HistoryTheme extends Themelet { $setter = "".html_escape($name)."$h_ip"; $selected = ($n == 2) ? " checked" : ""; + + $current_tags = explode(" ", $current_tags); + $taglinks = array(); + foreach($current_tags as $tag){ + $taglinks[] = "".$tag.""; + } + $current_tags = implode(" ", $taglinks); + $history_list .= "
  • From 2d22887c341ee0ff4aab61af027c74c6e8797a79 Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 17 Mar 2012 20:03:48 +0000 Subject: [PATCH 31/51] user should be able to calculate uploads/comments perday with data provided, so no need to include in api --- contrib/shimmie_api/main.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/contrib/shimmie_api/main.php b/contrib/shimmie_api/main.php index 18652442..da65a2d6 100644 --- a/contrib/shimmie_api/main.php +++ b/contrib/shimmie_api/main.php @@ -118,11 +118,9 @@ class ShimmieApi extends Extension { // - it returns data as eg array(0=>1234, 'id'=>1234, 1=>'bob', 'name'=>bob, ...); for($i=0; $i<4; $i++) unset($all[$i]); $all['uploadcount'] = Image::count_images(array("user_id=".$all['id'])); - $all['uploadperday'] = sprintf("%.1f", ($all['uploadcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1))); $all['commentcount'] = $database->get_one( "SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id", array("owner_id"=>$all['id'])); - $all['commentperday'] = sprintf("%.1f", ($all['commentcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1))); if(isset($_GET['recent'])){ $recent = $database->get_all( From 7bb769917f46086aa1dfd7a4e3a855794d13ecfe Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 30 Mar 2012 05:04:40 +0100 Subject: [PATCH 32/51] lite should now work a bit better with blocked tags --- themes/lite/style.css | 2 +- themes/lite/themelet.class.php | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/themes/lite/style.css b/themes/lite/style.css index 1560e7d0..fe519214 100644 --- a/themes/lite/style.css +++ b/themes/lite/style.css @@ -70,7 +70,7 @@ a.tab:hover, a.tab:active, .tab-selected { -moz-border-radius:4px; -webkit-border-radius:4px; } -.highlighted { +.lazy{ background:none repeat scroll 0 0 #CEDFF0; padding:4px; border:1px solid #C3D2E0; diff --git a/themes/lite/themelet.class.php b/themes/lite/themelet.class.php index 8afa7754..3633860b 100644 --- a/themes/lite/themelet.class.php +++ b/themes/lite/themelet.class.php @@ -6,28 +6,26 @@ class Themelet extends BaseThemelet { */ 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(); $h_tip = html_escape($image->get_tooltip()); + $h_tags = strtolower($image->get_tag_list()); + $base = get_base_href(); // 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 { + else{ $tsize = get_thumbnail_size($image->width, $image->height); } - return " -
    - - - $h_tip - - -
    - "; + return '
    \n"; } From 546b7ea21ecf572ed618b5d43928c9bee8b4c477 Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 30 Mar 2012 05:05:16 +0100 Subject: [PATCH 33/51] blocked tags will also set thumbblock div to 0 if theme is lite --- ext/index/script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/index/script.js b/ext/index/script.js index 61a840f9..459118fb 100644 --- a/ext/index/script.js +++ b/ext/index/script.js @@ -1,10 +1,14 @@ $(function() { var blocked_tags = ($.cookie("ui-blocked-tags") || $.cookie("blocked-tags") || "").split(" "); + var themecheck = $(".thumb[data-tags~='tagme']").parent().attr('class'); var needs_refresh = false; for(i in blocked_tags) { var tag = blocked_tags[i]; if(tag) { $(".thumb[data-tags~='"+tag+"']").hide(); + if(themecheck == "thumbblock") { + $(".thumb[data-tags~='tagme']").parent().height(0); //required for lite theme + } needs_refresh = true; } } From a825c1cd460569de323d2a02c5538738f456f4e6 Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 30 Mar 2012 05:18:08 +0100 Subject: [PATCH 34/51] this seemed to cause the info block to move above the image.. --- themes/lite/view.theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/lite/view.theme.php b/themes/lite/view.theme.php index 1d075041..f54d45b1 100644 --- a/themes/lite/view.theme.php +++ b/themes/lite/view.theme.php @@ -13,7 +13,7 @@ class CustomViewImageTheme extends ViewImageTheme { $page->add_html_header("id}"))."\">"); $page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0)); $page->add_block(new Block("Statistics", $this->build_stats($image), "left", 15)); - $page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 10)); + $page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 11)); $page->add_block(new Block(null, $this->build_pin($image), "main", 11)); } From 51a59fef077d71c2dcd56a7c2e4b7a8e3ed04207 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 16:29:52 +0100 Subject: [PATCH 35/51] Tag::implode / explode --- contrib/tag_history/theme.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/tag_history/theme.php b/contrib/tag_history/theme.php index eaa8761e..a889e748 100644 --- a/contrib/tag_history/theme.php +++ b/contrib/tag_history/theme.php @@ -28,12 +28,12 @@ class Tag_HistoryTheme extends Themelet { $selected = ($n == 2) ? " checked" : ""; - $current_tags = explode(" ", $current_tags); + $current_tags = Tag::explode($current_tags); $taglinks = array(); foreach($current_tags as $tag){ $taglinks[] = "".$tag.""; } - $current_tags = implode(" ", $taglinks); + $current_tags = Tag::implode($taglinks); $history_list .= "
  • From e538181fa1008f3c725b8652ce68b22f2527e07e Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 16:40:14 +0100 Subject: [PATCH 36/51] add alias after finishing the mass tag edit --- ext/alias_editor/main.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 8fc18a30..539bafde 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -138,5 +138,10 @@ class AliasEditor extends Extension { } } } + + // add alias *after* mass tag editing, else the MTE will + // search for the images and be redirected to the alias, + // missing out the images tagged with the oldtag + public function get_priority() {return 60;} } ?> From e210fe739b1f04a7ef45b84b59443f80f6922412 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 16:41:25 +0100 Subject: [PATCH 37/51] more spaced out priorities --- core/util.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/util.inc.php b/core/util.inc.php index 5111ff3c..e749d0a3 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -884,9 +884,10 @@ $_event_listeners = array(); */ function add_event_listener(Extension $extension, $pos=50, $events=array()) { global $_event_listeners; + $pos *= 100; foreach($events as $event) { while(isset($_event_listeners[$event][$pos])) { - $pos++; + $pos += 1; } $_event_listeners[$event][$pos] = $extension; } From 7bf273a1ee65a6d044e2ea238fe68e2c460c8d35 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 17:18:01 +0100 Subject: [PATCH 38/51] event log layout --- contrib/log_db/theme.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/log_db/theme.php b/contrib/log_db/theme.php index 5f387d39..e5fd8b87 100644 --- a/contrib/log_db/theme.php +++ b/contrib/log_db/theme.php @@ -20,7 +20,7 @@ class LogDatabaseTheme extends Themelet { - + @@ -34,8 +34,8 @@ class LogDatabaseTheme extends Themelet { - + @@ -56,7 +56,7 @@ class LogDatabaseTheme extends Themelet { "".html_escape($event['username'])."". ""; } - $table .= ""; + $table .= ""; $table .= "\n"; } $table .= "
    TimeModuleUserMessage
    TimeModuleUserMessage
    ".$this->scan_entities(html_escape($event['message']))."".$this->scan_entities(html_escape($event['message']))."
    "; From 447d42d4540a7550627716dd0f071afdfa44f88d Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 17:20:15 +0100 Subject: [PATCH 39/51] more layout bits --- contrib/image_hash_ban/theme.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/contrib/image_hash_ban/theme.php b/contrib/image_hash_ban/theme.php index d23721f7..d09cad2b 100644 --- a/contrib/image_hash_ban/theme.php +++ b/contrib/image_hash_ban/theme.php @@ -26,24 +26,19 @@ class ImageBanTheme extends Themelet { foreach($bans as $ban) { $h_bans .= " - {$ban['hash']} - {$ban['reason']} - - ".make_form(make_link("image_hash_ban/remove"))." + ".make_form(make_link("image_hash_ban/remove"))." + {$ban['hash']} + {$ban['reason']} + - - + + "; } $html = " - - +
    From 094002c442da2d0ff71611b2e77f1667de158c31 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 17:44:59 +0100 Subject: [PATCH 40/51] remove blank lines --- README.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.txt b/README.txt index 796317cc..6429f172 100644 --- a/README.txt +++ b/README.txt @@ -111,6 +111,3 @@ someone else, you have to give them the source (which should be easy, as PHP is an interpreted language...). If you want to add customisations to your own site, then those customisations belong to you, and you can do what you want with them. - - - From bf39c8f09fb7798c4f18a457bab2a7689421fcfd Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 17:48:03 +0100 Subject: [PATCH 41/51] coalesce on remove individual vote too --- contrib/numeric_score/main.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index 2efddc3a..70ac2379 100644 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -291,7 +291,12 @@ class NumericScore extends Extension { 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=:imageid) WHERE id=:id", + "UPDATE images SET numeric_score=( + COALESCE( + (SELECT SUM(score) FROM numeric_score_votes WHERE image_id=:imageid), + 0 + ) + ) WHERE id=:id", array("imageid" => $image_id, "id" => $image_id)); } } From fd094050fcb4fbe1f4001b50ffc405e8813edceb Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 18:03:55 +0100 Subject: [PATCH 42/51] move config file to data --- .gitignore | 1 - README.txt | 2 ++ contrib/update/main.php | 2 +- core/database.class.php | 2 +- core/default_config.inc.php | 2 +- core/userclass.class.php | 2 +- doxygen.conf | 4 ++-- index.php | 4 ++-- install.php | 15 ++++++++------- 9 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index e88558e9..14b3ad2c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .svn backup -config.php data images imgdump-*.zip diff --git a/README.txt b/README.txt index 6429f172..df6d7f26 100644 --- a/README.txt +++ b/README.txt @@ -42,6 +42,8 @@ Installation Upgrade from 2.3.X ~~~~~~~~~~~~~~~~~~ +config.php has been moved from /config.php to /data/config/shimmie.conf.php + The database connection setting in config.php has changed; now using PDO DSN format rather than ADODB URI: diff --git a/contrib/update/main.php b/contrib/update/main.php index 8e7b2133..90372e42 100644 --- a/contrib/update/main.php +++ b/contrib/update/main.php @@ -103,7 +103,7 @@ class Update extends Extension { reset($objects); $html .= "
    data folder emptied!"; } - copy ("./config.php", "./backup/config.php");//Although this stays the same, will keep backup just incase. + copy ("./data/config/shimmie.conf.php", "./backup/shimmie.conf.php");//Although this stays the same, will keep backup just incase. $folders = array("./core", "./lib", "./themes", "./.htaccess", "./doxygen.conf", "./index.php", "./install.php", "./ext", "./contrib"); foreach($folders as $folder){ //TODO: Check MD5 of each file, don't rename if same. diff --git a/core/database.class.php b/core/database.class.php index 2f63ab1a..fc93269f 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -273,7 +273,7 @@ class Database { /** * Create a new database object using connection info - * stored in config.php in the root shimmie folder + * stored in the config file */ public function Database() { # FIXME: detect ADODB URI, automatically translate PDO DSN diff --git a/core/default_config.inc.php b/core/default_config.inc.php index f2ddfcda..3f6b6e50 100644 --- a/core/default_config.inc.php +++ b/core/default_config.inc.php @@ -2,7 +2,7 @@ /** * These are the default configuration options for Shimmie. * - * All of these can be over-ridden by placing a 'define' in config.php + * All of these can be over-ridden by placing a 'define' in data/config/shimmie.conf.php * * Do NOT change them in this file. These are the defaults only! * diff --git a/core/userclass.class.php b/core/userclass.class.php index e342040b..5dcf1dd6 100644 --- a/core/userclass.class.php +++ b/core/userclass.class.php @@ -40,7 +40,7 @@ class UserClass { // object = image / user / tag / setting new UserClass("base", null, array( "change_setting" => False, # modify web-level settings, eg the config table - "override_config" => False, # modify sys-level settings, eg config.php + "override_config" => False, # modify sys-level settings, eg shimmie.conf.php "big_search" => False, # search for more than 3 tags at once (speed mode only) "manage_extension_list" => False, diff --git a/doxygen.conf b/doxygen.conf index c934f615..085ca149 100644 --- a/doxygen.conf +++ b/doxygen.conf @@ -640,11 +640,11 @@ RECURSIVE = YES # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. -EXCLUDE = config.php \ - install.php \ +EXCLUDE = install.php \ phpinfo.php \ contrib/simpletest/simpletest \ lib \ + data \ images \ thumbs \ .git \ diff --git a/index.php b/index.php index 9895d7c7..3ef60456 100644 --- a/index.php +++ b/index.php @@ -43,11 +43,11 @@ * Each of these can be imported at the start of a function with eg "global $page, $user;" */ -if(!file_exists("config.php")) { +if(!file_exists("data/config/shimmie.conf.php")) { header("Location: install.php"); exit; } -require_once "config.php"; +require_once "data/config/shimmie.conf.php"; require_once "core/default_config.inc.php"; require_once "core/util.inc.php"; require_once "lib/context.php"; diff --git a/install.php b/install.php index 142fa9f5..795bc5e5 100644 --- a/install.php +++ b/install.php @@ -64,13 +64,13 @@ require_once __SHIMMIE_ROOT__."core/database.class.php"; * This file lets anyone destroy the database -- disable it * as soon as the admin is done installing for the first time */ -if(is_readable("config.php")) { +if(is_readable("data/config/shimmie.conf.php")) { session_start(); echo '
    '; echo '

    Shimmie Repair Console

    '; // Load the config - require_once __SHIMMIE_ROOT__."config.php"; // Load user/site specifics First + require_once __SHIMMIE_ROOT__."data/config/shimmie.conf.php"; // Load user/site specifics First require_once __SHIMMIE_ROOT__."core/default_config.inc.php"; // Defaults for the rest. if( @@ -120,7 +120,7 @@ if(is_readable("config.php")) { else { echo "

    Login

    -

    Enter the database DSN exactly as in config.php (ie, as originally installed) to access advanced recovery tools:

    +

    Enter the database DSN exactly as in shimmie.conf.php (ie, as originally installed) to access advanced recovery tools:

    @@ -403,14 +403,15 @@ function write_config() { // {{{ "define('DATABASE_DSN', '".DATABASE_DSN."');\n" . '?' . '>'; - if(is_writable("./") && file_put_contents("config.php", $file_content)) { - assert(file_exists("config.php")); + if(!file_exists("data/config")) { + mkdir("data/config", 0755, true); } - else { + + if(!file_put_contents("data/config/shimmie.conf.php", $file_content)) { $h_file_content = htmlentities($file_content); print << Date: Fri, 30 Mar 2012 18:05:02 +0100 Subject: [PATCH 43/51] unignore bits, these should be in data --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index 14b3ad2c..48f0bfcf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,7 @@ -.svn backup data images -imgdump-*.zip thumbs -sql.log -shimmie.log !lib/images ext/admin ext/amazon_s3 From a989743849343bc998d2528cef575157a0a357b2 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 18:05:59 +0100 Subject: [PATCH 44/51] put imgdump in a writable folder --- contrib/admin/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/admin/main.php b/contrib/admin/main.php index a799a571..88cfb9d1 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -167,7 +167,7 @@ class AdminPage extends Extension { $zip = new ZipArchive; $images = $database->get_all("SELECT * FROM images"); - $filename = 'imgdump-'.date('Ymd').'.zip'; + $filename = 'data/imgdump-'.date('Ymd').'.zip'; if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE) === TRUE){ foreach($images as $img){ From 29cebb44f9a3bbd27aba6cbf9e6d9db4a9c1d9a9 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 18:07:40 +0100 Subject: [PATCH 45/51] event_listeners is a bit of cached data --- 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 e749d0a3..2de968e1 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -1030,8 +1030,8 @@ function _load_extensions() { ctx_log_start("Loading extensions"); - if(COMPILE_ELS && file_exists("data/event_listeners.php")) { - require_once("data/event_listeners.php"); + if(COMPILE_ELS && file_exists("data/cache/event_listeners.php")) { + require_once("data/cache/event_listeners.php"); } else { foreach(get_declared_classes() as $class) { @@ -1075,7 +1075,10 @@ function _load_extensions() { $p .= ");\n"; $p .= "?".">"; - file_put_contents("data/event_listeners.php", $p); + if(!file_exists("data/cache")) { + mkdir("data/cache", 755, true); + } + file_put_contents("data/cache/event_listeners.php", $p); } } From 7cbb62c8cc0a9fa0c35020de77b3117dde27bfae Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 18:21:35 +0100 Subject: [PATCH 46/51] move data to data folder --- contrib/admin/main.php | 2 +- contrib/oekaki/main.php | 6 ++---- contrib/resize/main.php | 1 - contrib/update/main.php | 2 +- core/imageboard.pack.php | 1 - core/page.class.php | 8 ++------ core/util.inc.php | 17 +++++++++-------- 7 files changed, 15 insertions(+), 22 deletions(-) diff --git a/contrib/admin/main.php b/contrib/admin/main.php index 88cfb9d1..ab902603 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -167,7 +167,7 @@ class AdminPage extends Extension { $zip = new ZipArchive; $images = $database->get_all("SELECT * FROM images"); - $filename = 'data/imgdump-'.date('Ymd').'.zip'; + $filename = data_path('imgdump-'.date('Ymd').'.zip'); if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE) === TRUE){ foreach($images as $img){ diff --git a/contrib/oekaki/main.php b/contrib/oekaki/main.php index 2c534889..49e1e2cc 100644 --- a/contrib/oekaki/main.php +++ b/contrib/oekaki/main.php @@ -24,12 +24,10 @@ class Oekaki extends Extension { if(isset($_FILES["picture"])) { header('Content-type: text/plain'); - $uploaddir = './data/oekaki_unclaimed/'; - if(!file_exists($uploaddir)) mkdir($uploaddir, 0755, true); $file = $_FILES['picture']['name']; $ext = (strpos($file, '.') === FALSE) ? '' : substr($file, strrpos($file, '.')); $uploadname = $_SERVER['REMOTE_ADDR'] . "." . time(); - $uploadfile = $uploaddir . $uploadname; + $uploadfile = data_path('oekaki_unclaimed/'.$uploadname); log_info("oekaki", "Uploading file [$uploadname]"); @@ -53,7 +51,7 @@ class Oekaki extends Extension { // FIXME: move .chi to data/oekaki/$ha/$hash mirroring images and thumbs // FIXME: .chi viewer? // FIXME: clean out old unclaimed images? - $pattern = './data/oekaki_unclaimed/' . $_SERVER['REMOTE_ADDR'] . ".*.png"; + $pattern = data_path('oekaki_unclaimed/' . $_SERVER['REMOTE_ADDR'] . ".*.png"); foreach(glob($pattern) as $tmpname) { assert(file_exists($tmpname)); diff --git a/contrib/resize/main.php b/contrib/resize/main.php index caba3ed4..139f3ca8 100644 --- a/contrib/resize/main.php +++ b/contrib/resize/main.php @@ -265,7 +265,6 @@ class ResizeImage extends Extension { $new_hash = md5_file($tmp_filename); $new_size = filesize($tmp_filename); $target = warehouse_path("images", $new_hash); - if(!file_exists(dirname($target))) mkdir(dirname($target), 0755, true); if(!@copy($tmp_filename, $target)) { throw new ImageResizeException("Failed to copy new image file from temporary location ({$tmp_filename}) to archive ($target)"); } diff --git a/contrib/update/main.php b/contrib/update/main.php index 90372e42..9aad4c2c 100644 --- a/contrib/update/main.php +++ b/contrib/update/main.php @@ -91,7 +91,7 @@ class Update extends Extension { $commit = $matches[2]; mkdir("./backup"); $html .= "
    backup folder created!"; - $d_dir = "data/cache"; + $d_dir = data_path("cache"); //This should empty the /data/cache/ folder. if (is_dir($d_dir)) { $objects = scandir($d_dir); diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 83a30d3a..e562de10 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -1080,7 +1080,6 @@ class Tag { */ function move_upload_to_archive(DataUploadEvent $event) { $target = warehouse_path("images", $event->hash); - if(!file_exists(dirname($target))) mkdir(dirname($target), 0755, true); if(!@copy($event->tmpname, $target)) { $errors = error_get_last(); // note: requires php 5.2 throw new UploadException("Failed to copy file from uploads ({$event->tmpname}) to archive ($target): {$errors['type']} / {$errors['message']}"); diff --git a/core/page.class.php b/core/page.class.php index dae6dd9b..6a562f38 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -246,17 +246,13 @@ class Page { $this->add_html_header(""); $this->add_html_header(""); - if(!file_exists("data/cache")) { - mkdir("data/cache"); - } - $css_files = array(); $css_latest = 0; foreach(array_merge(zglob("lib/*.css"), zglob("ext/*/style.css"), zglob("themes/$theme_name/style.css")) as $css) { $css_files[] = $css; $css_latest = max($css_latest, filemtime($css)); } - $css_cache_file = "data/cache/style.$css_latest.css"; + $css_cache_file = data_path("cache/style.$css_latest.css"); if(!file_exists($css_cache_file)) { $css_data = ""; foreach($css_files as $file) { @@ -276,7 +272,7 @@ class Page { $js_files[] = $js; $js_latest = max($js_latest, filemtime($js)); } - $js_cache_file = "data/cache/script.$js_latest.js"; + $js_cache_file = data_path("cache/script.$js_latest.js"); if(!file_exists($js_cache_file)) { $js_data = ""; foreach($js_files as $file) { diff --git a/core/util.inc.php b/core/util.inc.php index 2de968e1..8dff786e 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -645,6 +645,12 @@ function warehouse_path(/*string*/ $base, /*string*/ $hash, /*bool*/ $create=tru return $pa; } +function data_path($filename) { + $filename = "data/" . $filename; + if($create && !file_exists(dirname($filename))) mkdir(dirname($filename), 0755, true); + return $filename; +} + function transload($url, $mfile) { global $config; @@ -1075,10 +1081,7 @@ function _load_extensions() { $p .= ");\n"; $p .= "?".">"; - if(!file_exists("data/cache")) { - mkdir("data/cache", 755, true); - } - file_put_contents("data/cache/event_listeners.php", $p); + file_put_contents(data_path("cache/event_listeners.php"), $p); } } @@ -1232,11 +1235,9 @@ function _start_cache() { $_cache_hash = md5($_SERVER["QUERY_STRING"]); $ab = substr($_cache_hash, 0, 2); $cd = substr($_cache_hash, 2, 2); - $_cache_filename = "data/http_cache/$ab/$cd/$_cache_hash"; + $_cache_filename = data_path("http_cache/$ab/$cd/$_cache_hash"); + @chmod(data_path('http_cache'), 750); - if(!file_exists(dirname($_cache_filename))) { - mkdir(dirname($_cache_filename), 0750, true); - } if(file_exists($_cache_filename) && (filemtime($_cache_filename) > time() - 3600)) { $gmdate_mod = gmdate('D, d M Y H:i:s', filemtime($_cache_filename)) . ' GMT'; From c2de49c248bafa2cc96255213b301dc8a53dbe1a Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 18:35:05 +0100 Subject: [PATCH 47/51] tag list caches in data/cache --- ext/tag_list/main.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 20fcdfd7..8f36345f 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -188,7 +188,7 @@ class TagList extends Extension { $starts_with = $this->get_starts_with(); // check if we have a cached version - $cache_key = "data/tag_cloud-" . md5("tc" . $tags_min . $starts_with) . ".html"; + $cache_key = data_path("cache/tag_cloud-" . md5("tc" . $tags_min . $starts_with) . ".html"); if(file_exists($cache_key)) {return file_get_contents($cache_key);} // SHIT: PDO/pgsql has problems using the same named param twice -_-;; @@ -225,7 +225,7 @@ class TagList extends Extension { $starts_with = $this->get_starts_with(); // check if we have a cached version - $cache_key = "data/tag_alpha-" . md5("ta" . $tags_min . $starts_with) . ".html"; + $cache_key = data_path("cache/tag_alpha-" . md5("ta" . $tags_min . $starts_with) . ".html"); if(file_exists($cache_key)) {return file_get_contents($cache_key);} $tag_data = $database->get_all($database->engine->scoreql_to_sql(" @@ -261,7 +261,7 @@ class TagList extends Extension { $tags_min = $this->get_tags_min(); // check if we have a cached version - $cache_key = "data/tag_popul-" . md5("tp" . $tags_min) . ".html"; + $cache_key = data_path("cache/tag_popul-" . md5("tp" . $tags_min) . ".html"); if(file_exists($cache_key)) {return file_get_contents($cache_key);} $tag_data = $database->get_all(" From 62e13eda96ebd213318d97686b4a8b749d848432 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 20:28:09 +0100 Subject: [PATCH 48/51] always create --- 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 8dff786e..9fce4dda 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -647,7 +647,7 @@ function warehouse_path(/*string*/ $base, /*string*/ $hash, /*bool*/ $create=tru function data_path($filename) { $filename = "data/" . $filename; - if($create && !file_exists(dirname($filename))) mkdir(dirname($filename), 0755, true); + if(!file_exists(dirname($filename))) mkdir(dirname($filename), 0755, true); return $filename; } From f7f70b8600b82035008fe5d0d8b1e6f032c5b1c3 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 30 Mar 2012 20:54:33 +0100 Subject: [PATCH 49/51] more perms --- contrib/admin/main.php | 6 +++--- contrib/image_hash_ban/main.php | 6 +++--- contrib/ipban/main.php | 2 +- contrib/log_db/main.php | 4 ++-- core/userclass.class.php | 9 +++++++++ 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/contrib/admin/main.php b/contrib/admin/main.php index ab902603..f70e77bf 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -43,7 +43,7 @@ class AdminPage extends Extension { global $page, $user; if($event->page_matches("admin")) { - if(!$user->is_admin()) { + if(!$user->can("manage_admintools")) { $this->theme->display_permission_denied(); } else { @@ -76,7 +76,7 @@ class AdminPage extends Extension { public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; - if($user->is_admin()) { + if($user->can("manage_admintools")) { $event->add_link("Board Admin", make_link("admin")); } } @@ -90,7 +90,7 @@ class AdminPage extends Extension { public function onPostListBuilding(PostListBuildingEvent $event) { global $user; - if($user->is_admin() && !empty($event->search_terms)) { + if($user->can("manage_admintools") && !empty($event->search_terms)) { $this->theme->display_dbq(implode(" ", $event->search_terms)); } } diff --git a/contrib/image_hash_ban/main.php b/contrib/image_hash_ban/main.php index f68c7205..cf20fb37 100644 --- a/contrib/image_hash_ban/main.php +++ b/contrib/image_hash_ban/main.php @@ -56,7 +56,7 @@ class ImageBan extends Extension { global $config, $database, $page, $user; if($event->page_matches("image_hash_ban")) { - if($user->is_admin()) { + if($user->can("ban_image")) { if($event->get_arg(0) == "dnp") { $image = Image::by_id(int_escape($event->get_arg(1))); if($image) { @@ -105,7 +105,7 @@ class ImageBan extends Extension { public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; - if($user->is_admin()) { + if($user->can("ban_image")) { $event->add_link("Image Bans", make_link("image_hash_ban/list/1")); } } @@ -120,7 +120,7 @@ class ImageBan extends Extension { public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) { global $user; - if($user->is_admin()) { + if($user->can("ban_image")) { $event->add_part($this->theme->get_buttons_html($event->image)); } } diff --git a/contrib/ipban/main.php b/contrib/ipban/main.php index 4dd485ed..4e50c3de 100644 --- a/contrib/ipban/main.php +++ b/contrib/ipban/main.php @@ -80,7 +80,7 @@ class IPBan extends Extension { public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; - if($user->is_admin()) { + if($user->can("ban_ip")) { $event->add_link("IP Bans", make_link("ip_ban/list")); } } diff --git a/contrib/log_db/main.php b/contrib/log_db/main.php index 8399720a..39a58f36 100644 --- a/contrib/log_db/main.php +++ b/contrib/log_db/main.php @@ -44,7 +44,7 @@ class LogDatabase extends Extension { public function onPageRequest(PageRequestEvent $event) { global $database, $user; if($event->page_matches("log/view")) { - if($user->is_admin()) { + if($user->can("view_eventlog")) { $wheres = array(); $args = array(); $page_num = int_escape($event->get_arg(0)); @@ -111,7 +111,7 @@ class LogDatabase extends Extension { public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; - if($user->is_admin()) { + if($user->can("view_eventlog")) { $event->add_link("Event Log", make_link("log/view")); } } diff --git a/core/userclass.class.php b/core/userclass.class.php index 5dcf1dd6..e6b219f4 100644 --- a/core/userclass.class.php +++ b/core/userclass.class.php @@ -65,6 +65,10 @@ new UserClass("base", null, array( "edit_image_lock" => False, "delete_image" => False, + "ban_image" => False, + + "view_eventlog" => False, + "create_image_report" => False, "view_image_report" => False, # deal with reported images @@ -73,6 +77,8 @@ new UserClass("base", null, array( "manage_blocks" => False, + "manage_admintools" => False, + "protected" => False, # only admins can modify protected users (stops a moderator changing an admin's password) )); @@ -100,6 +106,7 @@ new UserClass("admin", "base", array( "delete_user" => True, "create_image" => True, "delete_image" => True, + "ban_image" => True, "create_comment" => True, "delete_comment" => True, "replace_image" => True, @@ -113,7 +120,9 @@ new UserClass("admin", "base", array( "view_image_report" => True, "edit_wiki_page" => True, "delete_wiki_page" => True, + "view_eventlog" => True, "manage_blocks" => True, + "manage_admintools" => True, "protected" => True, )); From 7ef52c853f25b4ddb6634fa06ccb74403c9795b1 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 31 Mar 2012 12:28:34 +0100 Subject: [PATCH 50/51] more perms --- contrib/downtime/main.php | 2 +- contrib/featured/main.php | 4 ++-- contrib/ipban/main.php | 2 +- contrib/numeric_score/main.php | 6 +++--- contrib/numeric_score/theme.php | 2 +- contrib/pm/main.php | 6 +++--- core/userclass.class.php | 11 +++++++++++ 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/contrib/downtime/main.php b/contrib/downtime/main.php index 462e530f..63421db8 100644 --- a/contrib/downtime/main.php +++ b/contrib/downtime/main.php @@ -26,7 +26,7 @@ class Downtime extends Extension { global $config, $page, $user; if($config->get_bool("downtime")) { - if(!$user->is_admin() && !$this->is_safe_page($event)) { + if(!$user->can("ignore_downtime") && !$this->is_safe_page($event)) { $msg = $config->get_string("downtime_message"); $this->theme->display_message($msg); exit; diff --git a/contrib/featured/main.php b/contrib/featured/main.php index 5dbc41dd..dda66100 100644 --- a/contrib/featured/main.php +++ b/contrib/featured/main.php @@ -29,7 +29,7 @@ class Featured extends Extension { global $config, $page, $user; if($event->page_matches("featured_image")) { if($event->get_arg(0) == "set" && $user->check_auth_token()) { - if($user->is_admin() && isset($_POST['image_id'])) { + if($user->can("edit_feature") && isset($_POST['image_id'])) { $id = int_escape($_POST['image_id']); if($id > 0) { $config->set_int("featured_id", $id); @@ -77,7 +77,7 @@ class Featured extends Extension { public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) { global $user; - if($user->is_admin()) { + if($user->can("edit_feature")) { $event->add_part($this->theme->get_buttons_html($event->image->id)); } } diff --git a/contrib/ipban/main.php b/contrib/ipban/main.php index 4e50c3de..f3346a6c 100644 --- a/contrib/ipban/main.php +++ b/contrib/ipban/main.php @@ -49,7 +49,7 @@ class IPBan extends Extension { public function onPageRequest(PageRequestEvent $event) { if($event->page_matches("ip_ban")) { global $config, $database, $page, $user; - if($user->is_admin()) { + if($user->can("ban_ip")) { if($event->get_arg(0) == "add" && $user->check_auth_token()) { if(isset($_POST['ip']) && isset($_POST['reason']) && isset($_POST['end'])) { if(empty($_POST['end'])) $end = null; diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index 70ac2379..98aaf45d 100644 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -38,7 +38,7 @@ class NumericScore extends Extension { public function onUserPageBuilding(UserPageBuildingEvent $event) { global $page, $user; - if($user->is_admin()) { + if($user->can("edit_other_votes")) { $html = $this->theme->get_nuller_html($event->display_user); $page->add_block(new Block("Votes", $html, "main", 60)); } @@ -79,7 +79,7 @@ class NumericScore extends Extension { } } if($event->page_matches("numeric_score/remove_votes_on") && $user->check_auth_token()) { - if($user->is_admin()) { + if($user->can("edit_other_vote")) { $image_id = int_escape($_POST['image_id']); $database->execute( "DELETE FROM numeric_score_votes WHERE image_id=?", @@ -92,7 +92,7 @@ class NumericScore extends Extension { } } if($event->page_matches("numeric_score/remove_votes_by") && $user->check_auth_token()) { - if($user->is_admin()) { + if($user->can("edit_other_vote")) { $this->delete_votes_by(int_escape($_POST['user_id'])); $page->set_mode("redirect"); $page->set_redirect(make_link()); diff --git a/contrib/numeric_score/theme.php b/contrib/numeric_score/theme.php index b33043e0..fdd2fa90 100644 --- a/contrib/numeric_score/theme.php +++ b/contrib/numeric_score/theme.php @@ -30,7 +30,7 @@ class NumericScoreTheme extends Themelet { "; - if($user->is_admin()) { + if($user->can("edit_other_vote")) { $html .= "
    ".$user->get_auth_html()." diff --git a/contrib/pm/main.php b/contrib/pm/main.php index b1b6f81b..d33c975d 100644 --- a/contrib/pm/main.php +++ b/contrib/pm/main.php @@ -90,7 +90,7 @@ class PrivMsg extends Extension { global $page, $user; $duser = $event->display_user; if(!$user->is_anonymous() && !$duser->is_anonymous()) { - if(($user->id == $duser->id) || $user->is_admin()) { + if(($user->id == $duser->id) || $user->can("view_other_pms")) { $this->theme->display_pms($page, $this->get_pms($duser)); } if($user->id != $duser->id) { @@ -110,7 +110,7 @@ class PrivMsg extends Extension { if(is_null($pm)) { $this->theme->display_error(404, "No such PM", "There is no PM #$pm_id"); } - else if(($pm["to_id"] == $user->id) || $user->is_admin()) { + else if(($pm["to_id"] == $user->id) || $user->can("view_other_pms")) { $from_user = User::by_id(int_escape($pm["from_id"])); $database->execute("UPDATE private_message SET is_read='Y' WHERE id = :id", array("id" => $pm_id)); $database->cache->delete("pm-count-{$user->id}"); @@ -127,7 +127,7 @@ class PrivMsg extends Extension { if(is_null($pm)) { $this->theme->display_error(404, "No such PM", "There is no PM #$pm_id"); } - else if(($pm["to_id"] == $user->id) || $user->is_admin()) { + else if(($pm["to_id"] == $user->id) || $user->can("view_other_pms")) { $database->execute("DELETE FROM private_message WHERE id = :id", array("id" => $pm_id)); $database->cache->delete("pm-count-{$user->id}"); log_info("pm", "Deleted PM #$pm_id"); diff --git a/core/userclass.class.php b/core/userclass.class.php index e6b219f4..be8acb16 100644 --- a/core/userclass.class.php +++ b/core/userclass.class.php @@ -68,6 +68,7 @@ new UserClass("base", null, array( "ban_image" => False, "view_eventlog" => False, + "ignore_downtime" => False, "create_image_report" => False, "view_image_report" => False, # deal with reported images @@ -79,6 +80,11 @@ new UserClass("base", null, array( "manage_admintools" => False, + "view_other_pms" => False, + "edit_feature" => False, + "bulk_edit_vote" => False, + "edit_other_vote" => False, + "protected" => False, # only admins can modify protected users (stops a moderator changing an admin's password) )); @@ -123,6 +129,11 @@ new UserClass("admin", "base", array( "view_eventlog" => True, "manage_blocks" => True, "manage_admintools" => True, + "ignore_downtime" => True, + "view_other_pms" => True, + "edit_feature" => True, + "bulk_edit_vote" => True, + "edit_other_vote" => True, "protected" => True, )); From 4856af9c490cdd1cd5eb79f2052d164a6af70b1d Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 31 Mar 2012 12:33:55 +0100 Subject: [PATCH 51/51] more perms --- contrib/tag_history/main.php | 4 ++-- core/userclass.class.php | 2 ++ themes/danbooru/user.theme.php | 42 ---------------------------------- themes/lite/user.theme.php | 42 ---------------------------------- 4 files changed, 4 insertions(+), 86 deletions(-) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 7bcddbd3..b6fe5cea 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -35,7 +35,7 @@ class Tag_History extends Extension { } } else if($event->page_matches("tag_history/bulk_revert")) { - if($user->is_admin() && $user->check_auth_token()) { + if($user->can("bulk_edit_image_tag") && $user->check_auth_token()) { $this->process_bulk_revert_request(); } } @@ -78,7 +78,7 @@ class Tag_History extends Extension { public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; - if($user->is_admin()) { + if($user->can("bulk_edit_image_tag")) { $event->add_link("Tag Changes", make_link("tag_history/all/1")); } } diff --git a/core/userclass.class.php b/core/userclass.class.php index be8acb16..8b12d9af 100644 --- a/core/userclass.class.php +++ b/core/userclass.class.php @@ -63,6 +63,7 @@ new UserClass("base", null, array( "edit_image_source" => False, "edit_image_owner" => False, "edit_image_lock" => False, + "bulk_edit_image_tag" => False, "delete_image" => False, "ban_image" => False, @@ -121,6 +122,7 @@ new UserClass("admin", "base", array( "edit_image_tag" => True, "edit_image_source" => True, "edit_image_owner" => True, + "bulk_edit_image_tag" => True, "mass_tag_edit" => True, "create_image_report" => True, "view_image_report" => True, diff --git a/themes/danbooru/user.theme.php b/themes/danbooru/user.theme.php index a3329c80..51e3b32b 100644 --- a/themes/danbooru/user.theme.php +++ b/themes/danbooru/user.theme.php @@ -98,47 +98,5 @@ class CustomUserPageTheme extends UserPageTheme { $page->disable_left(); parent::display_user_page($duser, $stats); } - - protected function build_options($duser) { - global $database; - global $config; - global $user; - - $html = ""; - $html .= " - - - -
    HashReasonAction
    - - - - -
    Change Password
    Password
    Repeat Password
    - -

    - - - - - -
    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: - - - "; - } - - return $html; - } } ?> diff --git a/themes/lite/user.theme.php b/themes/lite/user.theme.php index 7f6d6440..9aa476ab 100644 --- a/themes/lite/user.theme.php +++ b/themes/lite/user.theme.php @@ -95,47 +95,5 @@ class CustomUserPageTheme extends UserPageTheme { $page->disable_left(); parent::display_user_page($duser, $stats); } - - protected function build_options($duser) { - global $database; - global $config; - global $user; - - $html = ""; - $html .= " -

    - - - - - - - -
    Change Password
    Password
    Repeat Password
    -
    -

    - - - - - -
    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: - - - "; - } - - return $html; - } } ?>