diff --git a/.gitignore b/.gitignore index 6dd0495a..57872564 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ .svn +backup config.php -images -thumbs data +images +imgdump-*.zip +thumbs sql.log shimmie.log !lib/images diff --git a/contrib/admin/main.php b/contrib/admin/main.php index 020d4640..e03cd69d 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -78,6 +78,13 @@ class AdminPage extends Extension { case 'database dump': $this->dbdump($page); break; + case 'reset image ids': + $this->reset_imageids(); + $redirect = true; + break; + case 'image dump': + $this->imgdump($page); + break; } if($redirect) { @@ -175,5 +182,67 @@ class AdminPage extends Extension { } } */ + + private function reset_imageids() { + global $database; + //This might be a bit laggy on boards with lots of images (?) + //Seems to work fine with 1.2k~ images though. + $i = 0; + $image = $database->get_all("SELECT * FROM images ORDER BY images.id ASC"); + /*$score_log = $database->get_all("SELECT message FROM score_log");*/ + foreach($image as $img){ + $xid = $img[0]; + $i = $i + 1; + $table = array( //Might be missing some tables? + "image_tags", "tag_histories", "image_reports", "comments", "user_favorites", "tag_histories", + "numeric_score_votes", "pool_images", "slext_progress_cache", "notes"); + + $sql = + "SET FOREIGN_KEY_CHECKS=0; + UPDATE images + SET id=".$i. + " WHERE id=".$xid.";"; //id for images + + foreach($table as $tbl){ + $sql .= " + UPDATE ".$tbl." + SET image_id=".$i." + WHERE image_id=".$xid.";"; + } + + /*foreach($score_log as $sl){ + //This seems like a bad idea. + //TODO: Might be better for log_info to have an $id option (which would then affix the id to the table?) + preg_replace(".Image \\#[0-9]+.", "Image #".$i, $sl); + }*/ + $sql .= " SET FOREIGN_KEY_CHECKS=1;"; + $database->execute($sql); + } + $count = (count($image)) + 1; + $database->execute("ALTER TABLE images AUTO_INCREMENT=".$count); + } + + private function imgdump($page) { + global $database; + $zip = new ZipArchive; + $images = $database->get_all("SELECT * FROM images"); + $filename = 'imgdump-'.date('Ymd').'.zip'; + + if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE){ + foreach($images as $img){ + $hash = $img["hash"]; + preg_match("^[A-Za-z0-9]{2}^", $hash, $matches); + $img_loc = "images/".$matches[0]."/".$hash; + if(file_exists($img_loc)){ + $zip->addFile($img_loc, $hash.".".$img["ext"]); + } + + } + $zip->close(); + } + $page->set_mode("redirect"); + $page->set_redirect(make_link($filename)); //Fairly sure there is better way to do this.. + //TODO: Delete file after downloaded? + } } ?> diff --git a/contrib/admin/theme.php b/contrib/admin/theme.php index 18cc9687..e72a372a 100644 --- a/contrib/admin/theme.php +++ b/contrib/admin/theme.php @@ -19,13 +19,26 @@ class AdminPageTheme extends Themelet { public function display_form(Page $page) { global $user; - $html = " - ".make_form(make_link("admin_utils"))." - + + diff --git a/contrib/ban_words/main.php b/contrib/ban_words/main.php index e5f42b89..f17b76bf 100644 --- a/contrib/ban_words/main.php +++ b/contrib/ban_words/main.php @@ -2,6 +2,7 @@ /* * Name: Comment Word Ban * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: For stopping spam and other comment abuse * Documentation: diff --git a/contrib/bulk_add/main.php b/contrib/bulk_add/main.php index 21e5a9a3..90f6f96a 100644 --- a/contrib/bulk_add/main.php +++ b/contrib/bulk_add/main.php @@ -2,6 +2,7 @@ /* * Name: Bulk Add * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Bulk add server-side images * Documentation: @@ -30,7 +31,9 @@ class BulkAdd extends Extension { $this->theme->display_admin_block(); } - + /** + * Generate the necessary DataUploadEvent for a given image and tags. + */ private function add_image($tmpname, $filename, $tags) { assert(file_exists($tmpname)); diff --git a/contrib/et/main.php b/contrib/et/main.php index 6a26ec40..63545b08 100644 --- a/contrib/et/main.php +++ b/contrib/et/main.php @@ -29,6 +29,9 @@ class ET extends Extension { } } + /** + * Collect the information and return it in a keyed array. + */ private function get_info() { global $config, $database; global $_event_listeners; // yay for using secret globals \o/ diff --git a/contrib/favorites/theme.php b/contrib/favorites/theme.php index 4bb452ae..14a4fd39 100644 --- a/contrib/favorites/theme.php +++ b/contrib/favorites/theme.php @@ -24,6 +24,8 @@ class FavoritesTheme extends Themelet { $i_favorites = count($username_array); $html = "$i_favorites people:"; + reset($username_array); // rewind to first element in array. + foreach($username_array as $row) { $username = html_escape($row); $html .= "
$username"; diff --git a/contrib/featured/main.php b/contrib/featured/main.php index ee25b121..5dbc41dd 100644 --- a/contrib/featured/main.php +++ b/contrib/featured/main.php @@ -2,6 +2,7 @@ /* * Name: Featured Image * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Bring a specific image to the users' attentions * Documentation: diff --git a/contrib/handle_flash/main.php b/contrib/handle_flash/main.php index 013528ac..21b19b30 100644 --- a/contrib/handle_flash/main.php +++ b/contrib/handle_flash/main.php @@ -2,7 +2,8 @@ /* * Name: Handle Flash * Author: Shish - * Description: Handle Flash files + * Link: http://code.shishnet.org/shimmie2/ + * Description: Handle Flash files. (No thumbnail is generated for flash files) */ class FlashFileHandler extends DataHandlerExtension { diff --git a/contrib/handle_svg/main.php b/contrib/handle_svg/main.php index 0c59f59d..6cc3efe8 100644 --- a/contrib/handle_svg/main.php +++ b/contrib/handle_svg/main.php @@ -2,7 +2,8 @@ /* * Name: Handle SVG * Author: Shish - * Description: Handle SVG files + * Link: http://code.shishnet.org/shimmie2/ + * Description: Handle SVG files. (No thumbnail is generated for SVG files) */ class SVGFileHandler extends Extension { diff --git a/contrib/ipban/main.php b/contrib/ipban/main.php index 4da24231..ceaa0f6a 100644 --- a/contrib/ipban/main.php +++ b/contrib/ipban/main.php @@ -2,6 +2,7 @@ /* * Name: IP Ban * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Ban IP addresses * Documentation: diff --git a/contrib/log_db/main.php b/contrib/log_db/main.php index bba7c996..626b4360 100644 --- a/contrib/log_db/main.php +++ b/contrib/log_db/main.php @@ -1,8 +1,9 @@ + * Link: http://code.shishnet.org/shimmie2/ + * Description: Keep a record of SCore events (in the database). * Visibility: admin */ diff --git a/contrib/log_db/theme.php b/contrib/log_db/theme.php index 6ac2d3a1..1d3d8ccf 100644 --- a/contrib/log_db/theme.php +++ b/contrib/log_db/theme.php @@ -41,6 +41,8 @@ class LogDatabaseTheme extends Themelet { \n"; $n = 0; + reset($events); // rewind to first element in array. + foreach($events as $event) { $oe = ($n++ % 2 == 0) ? "even" : "odd"; $c = $this->pri_to_col($event['priority']); diff --git a/contrib/news/main.php b/contrib/news/main.php index 27765c71..e0b5911d 100644 --- a/contrib/news/main.php +++ b/contrib/news/main.php @@ -2,6 +2,7 @@ /* * Name: News * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Show a short amount of text in a block on the post list * Documentation: diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index 7df72142..5eefa612 100755 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -2,6 +2,7 @@ /* * Name: Image Scores (Numeric) * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Allow users to score images * Documentation: diff --git a/contrib/random_image/main.php b/contrib/random_image/main.php index 11d5daa7..0ff3a1b2 100644 --- a/contrib/random_image/main.php +++ b/contrib/random_image/main.php @@ -2,6 +2,7 @@ /* * Name: Random Image * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Do things with a random image * Documentation: diff --git a/contrib/rating/main.php b/contrib/rating/main.php index 4bcbe3f7..a2a57633 100644 --- a/contrib/rating/main.php +++ b/contrib/rating/main.php @@ -2,6 +2,7 @@ /* * Name: Image Ratings * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Allow users to rate images "safe", "questionable" or "explicit" */ @@ -33,6 +34,9 @@ class Ratings extends Extension { while(true) { $images = Image::find_images($n, 100, Tag::explode($_POST["query"])); if(count($images) == 0) break; + + reset($images); // rewind to first element in array. + foreach($images as $image) { send_event(new RatingSetEvent($image, $user, $_POST['rating'])); } diff --git a/contrib/regen_thumb/main.php b/contrib/regen_thumb/main.php index 11355330..713f6cd5 100644 --- a/contrib/regen_thumb/main.php +++ b/contrib/regen_thumb/main.php @@ -2,6 +2,7 @@ /* * Name: Regen Thumb * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Regenerate a thumbnail image * Documentation: diff --git a/contrib/site_description/main.php b/contrib/site_description/main.php index f2f7f57d..9adaa5d3 100644 --- a/contrib/site_description/main.php +++ b/contrib/site_description/main.php @@ -2,6 +2,7 @@ /* * Name: Site Description * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Visibility: admin * Description: A description for search engines diff --git a/core/config.class.php b/core/config.class.php index 6d85b971..7e76b66c 100644 --- a/core/config.class.php +++ b/core/config.class.php @@ -188,6 +188,7 @@ class DatabaseConfig extends BaseConfig { */ public function save(/*string*/ $name=null) { if(is_null($name)) { + reset($this->values); // rewind the array to the first element foreach($this->values as $name => $value) { $this->save(/*string*/ $name); } diff --git a/core/event.class.php b/core/event.class.php index cbff2fcf..e6511cff 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -39,6 +39,8 @@ class PageRequestEvent extends Event { * Test if the requested path matches a given pattern. * * If it matches, store the remaining path elements in $args + * + * @retval bool */ public function page_matches(/*string*/ $name) { $parts = explode("/", $name); @@ -57,6 +59,11 @@ class PageRequestEvent extends Event { return true; } + /** + * Get the n th argument of the page request (if it exists.) + * @param $n integer + * @retval The argmuent (string) or NULL + */ public function get_arg(/*int*/ $n) { $offset = $this->part_count + $n; if($offset >= 0 && $offset < $this->arg_count) { @@ -67,6 +74,10 @@ class PageRequestEvent extends Event { } } + /** + * Returns the number of arguments the page request has. + * @retval int + */ public function count_args() { return (int)($this->arg_count - $this->part_count); } diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index ca198452..878cfb96 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -106,8 +106,10 @@ class Image { /** * Search for an array of images + * + * @retval Array */ - public static function find_images($start, $limit, $tags=array()) { + public static function find_images(/*int*/ $start, /*int*/ $limit, $tags=array()) { assert(is_numeric($start)); assert(is_numeric($limit)); assert(is_array($tags)); @@ -383,7 +385,7 @@ class Image { /** * Set the image's source URL */ - public function set_source($source) { + public function set_source(/*string*/ $source) { global $database; if(empty($source)) $source = null; if($source != $this->source) { @@ -392,7 +394,10 @@ class Image { } } - + /** + * Check if the image is locked. + * @retval bool + */ public function is_locked() { return ($this->locked === true || $this->locked == "Y" || $this->locked == "t"); } @@ -776,6 +781,8 @@ class Image { } } + reset($terms); // rewind to first element in array. + // turn each term into a specific type of querylet foreach($terms as $term) { $negative = false; @@ -1008,8 +1015,15 @@ class Tag { } } + /** + * This function takes a list (array) of tags and changes any tags that have aliases + * + * @param $tags Array of tags + * @return Array of tags + */ public static function resolve_list($tags) { $tags = Tag::explode($tags); + reset($tags); // rewind array to the first element. $new = array(); foreach($tags as $tag) { $new_set = explode(' ', Tag::resolve_alias($tag)); diff --git a/core/page.class.php b/core/page.class.php index 4060d4f7..3ec8b1d6 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -237,7 +237,7 @@ class Page { protected function add_auto_html_headers() { $data_href = get_base_href(); - $this->add_html_header(""); + $this->add_html_header(""); /* Attempt to cache the CSS & JavaScript files */ if ($this->add_cached_auto_html_headers() === FALSE) { @@ -291,7 +291,11 @@ class Page { { global $config; - if (!$config->get_bool("autocache_css") && !$config->get_bool("autocache_js")) { + // store local copy for speed. + $autocache_css = $config->get_bool("autocache_css"); + $autocache_js = $config->get_bool("autocache_js"); + + if (!$autocache_css && !$autocache_js) { return false; // caching disabled } @@ -309,7 +313,7 @@ class Page { $data_href = get_base_href(); /* ----- CSS Files ----- */ - if ($config->get_bool("autocache_css")) + if ($autocache_css) { // First get all the CSS from the lib directory $contents_from_lib = ''; @@ -376,7 +380,7 @@ class Page { /* ----- JavaScript Files ----- */ - if ($config->get_bool("autocache_js")) + if ($autocache_js) { $data = ''; $js_files = glob("lib/*.js"); @@ -394,7 +398,7 @@ class Page { // Minify the JS if enabled. if ($config->get_bool("autocache_min_js")){ // not supported yet. - // TODO: add support for Minifying CSS files. + // TODO: add support for Minifying JS files. } // compute the MD5 sum of the concatenated JavaScript files diff --git a/core/user.class.php b/core/user.class.php index 0c98597b..843d6c9d 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -216,6 +216,7 @@ class User { /** * Get a snippet of HTML which will render the user's avatar, be that * a local file, a remote file, a gravatar, a something else, etc + * @retval String of HTML */ public function get_avatar_html() { // FIXME: configurable @@ -242,6 +243,8 @@ class User { * authtok = md5(sesskey, salt), presented to the user in web forms, to make sure that * the form was generated within the session. Salted and re-hashed so that * reading a web page from the user's cache doesn't give access to the session key + * + * @retval String containing auth token (MD5sum) */ public function get_auth_token() { global $config; diff --git a/core/util.inc.php b/core/util.inc.php index 43197f5c..1f653574 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -190,12 +190,26 @@ function undb_bool($val) { if($val === false || $val == 'N' || $val == 'n' || $val == 'F' || $val == 'f' || $val === 0) return false; } -function startsWith($haystack, $needle) { +/** + * Checks if a given string contains another at the beginning. + * + * @param $haystack String to examine. + * @param $needle String to look for. + * @retval bool + */ +function startsWith(/*string*/ $haystack, /*string*/ $needle) { $length = strlen($needle); return (substr($haystack, 0, $length) === $needle); } -function endsWith($haystack, $needle) { +/** + * Checks if a given string contains another at the end. + * + * @param $haystack String to examine. + * @param $needle String to look for. + * @retval bool + */ +function endsWith(/*string*/ $haystack, /*string*/ $needle) { $length = strlen($needle); $start = $length * -1; //negative return (substr($haystack, $start) === $needle); @@ -621,6 +635,7 @@ function log_msg($section, $priority, $message) { send_event(new LogEvent($section, $priority, $message)); } +// More shorthand ways of logging function log_debug($section, $message) {log_msg($section, SCORE_LOG_DEBUG, $message);} function log_info($section, $message) {log_msg($section, SCORE_LOG_INFO, $message);} function log_warning($section, $message) {log_msg($section, SCORE_LOG_WARNING, $message);} @@ -848,6 +863,13 @@ function send_event(Event $event) { // string representation of a number, it's two numbers separated by a space. // What the fuck were the PHP developers smoking. $_load_start = microtime(true); + +/** + * Collects some debug information (execution time, memory usage, queries, etc) + * and formats it to stick in the footer of the page. + * + * @retval String of debug info to add to the page. + */ function get_debug_info() { global $config, $_event_count, $database, $_execs, $_load_start; @@ -1045,6 +1067,9 @@ function _load_extensions() { ctx_log_endok(); } +/** + * Used to display fatal errors to the web user. + */ function _fatal_error(Exception $e) { $version = VERSION; $message = $e->getMessage(); diff --git a/ext/comment/theme.php b/ext/comment/theme.php index d594ebe8..472d2daa 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -35,14 +35,17 @@ class CommentListTheme extends Themelet { // parts for each image $position = 10; + + $comment_limit = $config->get_int("comment_list_count", 10); + $comment_captcha = $config->get_bool('comment_captcha'); + foreach($images as $pair) { $image = $pair[0]; $comments = $pair[1]; $thumb_html = $this->build_thumb_html($image); - $comment_html = ""; - $comment_limit = $config->get_int("comment_list_count", 10); + $comment_count = count($comments); if($comment_limit > 0 && $comment_count > $comment_limit) { $hidden = $comment_count - $comment_limit; @@ -59,7 +62,7 @@ class CommentListTheme extends Themelet { } } else { if ($can_post) { - if(!$config->get_bool('comment_captcha')) { + if(!$comment_captcha) { $comment_html .= $this->build_postbox($image->id); } else { diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index d21de882..58d8b24e 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -1,7 +1,8 @@ + * Link: http://code.shishnet.org/shimmie2/ * Description: Show the tags in various ways */ @@ -107,13 +108,18 @@ class TagList extends Extension { return make_link("post/list/$u_tag/1"); } + /** + * Get the minimum number of times a tag needs to be used + * in order to be considered in the tag list. + * @retval int + */ private function get_tags_min() { if(isset($_GET['mincount'])) { return int_escape($_GET['mincount']); } else { global $config; - return $config->get_int('tags_min'); + return $config->get_int('tags_min'); // get the default. } } @@ -170,6 +176,8 @@ class TagList extends Extension { $tags_min = $this->get_tags_min(); $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"; if(file_exists($cache_key)) {return file_get_contents($cache_key);} @@ -205,6 +213,8 @@ class TagList extends Extension { $tags_min = $this->get_tags_min(); $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"; if(file_exists($cache_key)) {return file_get_contents($cache_key);} @@ -239,6 +249,8 @@ class TagList extends Extension { global $database; $tags_min = $this->get_tags_min(); + + // check if we have a cached version $cache_key = "data/tag_popul-" . md5("tp" . $tags_min) . ".html"; if(file_exists($cache_key)) {return file_get_contents($cache_key);} diff --git a/ext/tag_list/theme.php b/ext/tag_list/theme.php index 99d83664..23065572 100644 --- a/ext/tag_list/theme.php +++ b/ext/tag_list/theme.php @@ -69,23 +69,28 @@ class TagListTheme extends Themelet { */ public function display_popular_block(Page $page, $tag_infos) { global $config; + + // store local copies for speed. + $info_link = $config->get_string('info_link'); + $tag_list_num = $config->get_bool("tag_list_numbers"); $html = ""; $n = 0; + foreach($tag_infos as $row) { $tag = $row['tag']; $h_tag = html_escape($tag); $h_tag_no_underscores = str_replace("_", " ", $h_tag); $count = $row['count']; if($n++) $html .= "\n
"; - if(!is_null($config->get_string('info_link'))) { - $link = str_replace('$tag', $tag, $config->get_string('info_link')); - $html .= " ?"; + if(!is_null($info_link)) { + $link = str_replace('$tag', $tag, $info_link); + $html .= ' ?'; } $link = $this->tag_link($row['tag']); - $html .= " $h_tag_no_underscores"; - if($config->get_bool("tag_list_numbers")) { - $html .= " $count"; + $html .= ' '.$h_tag_no_underscores.''; + if($tag_list_num) { + $html .= ' '.$count.''; } } @@ -103,19 +108,23 @@ class TagListTheme extends Themelet { public function display_refine_block(Page $page, $tag_infos, $search) { global $config; + // store local copy for speed. + $info_link = $config->get_string('info_link'); + $html = ""; $n = 0; + foreach($tag_infos as $row) { $tag = $row['tag']; $h_tag = html_escape($tag); $h_tag_no_underscores = str_replace("_", " ", $h_tag); if($n++) $html .= "\n
"; - if(!is_null($config->get_string('info_link'))) { - $link = str_replace('$tag', $tag, $config->get_string('info_link')); - $html .= " ?"; + if(!is_null($info_link)) { + $link = str_replace('$tag', $tag, $info_link); + $html .= ' ?'; } $link = $this->tag_link($row['tag']); - $html .= " $h_tag_no_underscores"; + $html .= ' '.$h_tag_no_underscores.''; $html .= $this->ars($tag, $search); } diff --git a/ext/upgrade/main.php b/ext/upgrade/main.php index 0ddc9401..a61b0860 100644 --- a/ext/upgrade/main.php +++ b/ext/upgrade/main.php @@ -1,7 +1,8 @@ + * Link: http://code.shishnet.org/shimmie2/ * Description: Keeps things happy behind the scenes * Visibility: admin */ diff --git a/ext/upload/bookmarklet.js b/ext/upload/bookmarklet.js index 2838bdca..590adaef 100644 --- a/ext/upload/bookmarklet.js +++ b/ext/upload/bookmarklet.js @@ -4,22 +4,49 @@ var maxsze = (maxsze.match("(?:\.*[0-9])")) * 1024; //This assumes we are only working with MB. var toobig = "The file you are trying to upload is too big to upload!"; var notsup = "The file you are trying to upload is not supported!"; +if (CA === 0 || CA > 2){ //Default + if (confirm("OK = Use Current tags.\nCancel = Use new tags.")==true){ + }else{ + var tag=prompt("Enter Tags",""); + var chk=1; //This makes sure it doesn't use current tags. + } +}else if (CA === 1){ //Current Tags +}else if (CA === 2){ //New Tags + var tag=prompt("Enter Tags",""); + var chk=1; +} -if (confirm("OK = Use Current tags.\nCancel = Use new tags.")==true){}else{var tag=prompt("Enter Tags","");var chk=1;}; - -// Danbooru +// Danbooru | oreno.imouto | konachan | sankakucomplex if(document.getElementById("post_tags") !== null){ if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementById("post_tags").value;} - var rtg=document.getElementById("stats").innerHTML.match("
  • Rating: (.*)<\/li>")[1]; - var srx="http://" + document.location.hostname + document.location.href.match("\/post\/show\/[0-9]+\/"); + var srx="http://" + document.location.hostname + document.location.href.match("\/post\/show\/[0-9]+"); + if(srx.search("oreno\\.imouto") >= 0 || srx.search("konachan\\.com") >= 0){ + var rtg=document.getElementById("stats").innerHTML.match("
  • Rating: (.*) Rating: (.*)<\/li>")[1]; + } if(tag.search(/\bflash\b/)===-1){ - var filesze=document.getElementById("stats").innerHTML.match("[0-9] \\(((?:\.*[0-9])) ([a-zA-Z]+)"); + var hrs=document.getElementById("highres").href; + if(srx.search("oreno\\.imouto") >= 0 || srx.search("konachan\\.com") >= 0){ //oreno's theme seems to have moved the filesize + var filesze = document.getElementById("highres").innerHTML.match("[a-zA-Z0-9]+ \\(+([0-9]+\\.[0-9]+) ([a-zA-Z]+)"); + }else{ + var filesze=document.getElementById("stats").innerHTML.match("[0-9] \\(((?:\.*[0-9])) ([a-zA-Z]+)"); + } if(filesze[2] == "MB"){var filesze = filesze[1] * 1024;}else{var filesze = filesze[2].match("[0-9]+");} - if(supext.search(document.getElementById("highres").href.match("http\:\/\/.*\\.([a-z0-9]+)")[1]) !== -1){ + if(supext.search(hrs.match("http\:\/\/.*\\.([a-z0-9]+)")[1]) !== -1){ if(filesze <= maxsze){ - location.href=ste+document.getElementById("highres").href+"&tags="+tag+"&rating="+rtg+"&source="+srx; + if(srx.search("oreno\\.imouto") >= 0){ + //this regex tends to be a bit picky with tags -_-;; + var hrs=hrs.match("(http\:\/\/[a-z0-9]+\.[a-z]+\.[a-z]\/[a-z0-9]+\/[a-z0-9]+)\/[a-z0-9A-Z%_-]+(\.[a-zA-Z0-9]+)"); + var hrs=hrs[1]+hrs[2]; //this should bypass hotlink protection + }else if(srx.search("konachan\\.com") >= 0){ + //konachan affixs konachan.com to the start of the tags, this requires different regex + var hrs=hrs.match("(http\:\/\/[a-z0-9]+\.[a-z]+\.[a-z]\/[a-z0-9]+\/[a-z0-9]+)\/[a-z0-9A-Z%_]+\.[a-zA-Z0-9%_-]+(\.[a-z0-9A-Z]+)") + var hrs=hrs[1]+hrs[2]; + } + location.href=ste+hrs+"&tags="+tag+"&rating="+rtg+"&source="+srx; }else{alert(toobig);} }else{alert(notsup);} }else{ @@ -29,6 +56,7 @@ if(document.getElementById("post_tags") !== null){ } } /* Shimmie +One problem with shimmie is each theme does not show the same info as other themes (I.E only the danbooru & lite themes show statistics) Shimmie doesn't seem to have any way to grab tags via id unless you have the ability to edit tags. Have to go the round about way of checking the title for tags. This crazy way of checking "should" work with older releases though (Seems to work with 2009~ ver) */ @@ -36,7 +64,6 @@ else if(document.getElementsByTagName("title")[0].innerHTML.search("Image [0-9.- if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementsByTagName("title")[0].innerHTML.match("Image [0-9.-]+\: (.*)")[1];} //TODO: Make rating show in statistics. var srx="http://" + document.location.hostname + document.location.href.match("\/post\/view\/[0-9]+"); - /*TODO: Figure out regex for shortening file link. I.E http://blah.net/_images/1234abcd/everysingletag.png > http://blah.net/_images/1234abcd.png*/ /*TODO: Make file size show on all themes (Only seems to show in lite/Danbooru themes.)*/ if(tag.search(/\bflash\b/)==-1){ var img = document.getElementById("main_image").src; @@ -52,7 +79,6 @@ else if(document.getElementsByTagName("title")[0].innerHTML.search("Image [0-9.- } // Gelbooru else if(document.getElementById("tags") !== null){ - //Gelbooru has an annoying anti-hotlinking thing which doesn't seem to like the bookmarklet. if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementById("tags").value;} var rtg=document.getElementById("stats").innerHTML.match("
  • Rating: (.*)<\/li>")[1]; //Can't seem to grab source due to url containing a & @@ -61,6 +87,6 @@ else if(document.getElementById("tags") !== null){ //Since Gelbooru does not allow flash, no need to search for flash tag. //Gelbooru doesn't show file size in statistics either... if(supext.search(gmi.match("http\:\/\/.*\\.([a-z0-9]+)")[1]) !== -1){ - location.href=ste+gmi+"&tags="+tag+"&rating="+rtg[1];//+"&source="+srx; + location.href=ste+gmi+"&tags="+tag+"&rating="+rtg;//+"&source="+srx; }else{alert(notsup);} } diff --git a/ext/upload/main.php b/ext/upload/main.php index ae719f4e..d438febb 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -1,5 +1,5 @@ is_full = false; } else { + // TODO: This size limit should be configureable by the admin... + // currently set to 100 MB $this->is_full = $free_num < 100*1024*1024; } @@ -150,12 +152,14 @@ class Upload extends Extension { $tags = ''; // Tags aren't changed when uploading. Set to null to stop PHP warnings. if(count($_FILES)) { + reset($_FILES); // rewind to first element in array. foreach($_FILES as $file) { $ok = $this->try_upload($file, $tags, $source, $image_id); break; // leave the foreach loop. } } else { + reset($_POST); // rewind to first element in array. foreach($_POST as $name => $value) { if(substr($name, 0, 3) == "url" && strlen($value) > 0) { $ok = $this->try_transload($value, $tags, $source, $image_id); @@ -186,9 +190,11 @@ class Upload extends Extension { $source = isset($_POST['source']) ? $_POST['source'] : null; $ok = true; foreach($_FILES as $file) { + reset($_FILES); // rewind to first element in array. $ok = $ok & $this->try_upload($file, $tags, $source); } foreach($_POST as $name => $value) { + reset($_POST); // rewind to first element in array. if(substr($name, 0, 3) == "url" && strlen($value) > 0) { $ok = $ok & $this->try_transload($value, $tags, $source); } @@ -218,14 +224,28 @@ class Upload extends Extension { } // }}} // do things {{{ + + /** + * Check if a given user can upload. + * @param $user The user to check. + * @retval bool + */ private function can_upload(User $user) { global $config; return ($config->get_bool("upload_anon") || !$user->is_anonymous()); } - // Helper function based on the one from the online PHP Documentation - // which is licensed under Creative Commons Attribution 3.0 License - // TODO: Make these messages user/admin editable + /** + * Returns a descriptive error message for the specified PHP error code. + * + * This is a helper function based on the one from the online PHP Documentation + * which is licensed under Creative Commons Attribution 3.0 License + * + * TODO: Make these messages user/admin editable + * + * @param $error_code PHP error code (int) + * @retval String + */ private function upload_error_message($error_code) { switch ($error_code) { case UPLOAD_ERR_INI_SIZE: @@ -247,6 +267,10 @@ class Upload extends Extension { } } + /** + * Handle an upload. + * @retval bool TRUE on upload successful. + */ private function try_upload($file, $tags, $source, $replace='') { global $page; global $config; @@ -293,6 +317,10 @@ class Upload extends Extension { return $ok; } + /** + * Handle an transload. + * @retval bool TRUE on transload successful. + */ private function try_transload($url, $tags, $source, $replace='') { global $page; global $config; diff --git a/ext/upload/theme.php b/ext/upload/theme.php index 9e66e457..ecf71c51 100644 --- a/ext/upload/theme.php +++ b/ext/upload/theme.php @@ -18,6 +18,7 @@ class UploadTheme extends Themelet { $upload_list = ""; $upload_count = $config->get_int('upload_count'); + for($i=0; $i<$upload_count; $i++) { $a=$i+1; @@ -53,7 +54,7 @@ class UploadTheme extends Themelet { ". ""; - if($a==$config->get_int('upload_count')){ + if($a == $upload_count){ $upload_list .=""; }else{ $js1 = 'javascript:$(function() { @@ -145,8 +146,7 @@ class UploadTheme extends Themelet { { /* Imageboard > Shimmie Bookmarklet This is more or less, an upgraded version of the "Danbooru>Shimmie" bookmarklet. - At the moment this works with Shimmie & Danbooru. - It would also work with Gelbooru but unless someone can figure out how to bypass their hotlinking..meh. + At the moment this is known to work with Shimmie/Danbooru/Gelbooru/oreno.imouto/konachan/sankakucomplex. The bookmarklet is now also loaded via the .js file in this folder. */ //Bookmarklet checks if shimmie supports ext. If not, won't upload to site/shows alert saying not supported. @@ -156,7 +156,8 @@ class UploadTheme extends Themelet { if(file_exists("ext/handle_mp3")){$supported_ext .= " mp3";} if(file_exists("ext/handle_svg")){$supported_ext .= " svg";} $title = "Booru to " . $config->get_string('title'); - $html .= '

    '. + //CA=0: Ask to use current or new tags | CA=1: Always use current tags | CA=2: Always use new tags + $html .= '

    '. $title . ' (Click when looking at an image page. Works on sites running Shimmie/Danbooru/Gelbooru. (This also grabs the tags/rating/source!))'; } diff --git a/themes/danbooru/comment.theme.php b/themes/danbooru/comment.theme.php index ff728eac..a9ee90e1 100644 --- a/themes/danbooru/comment.theme.php +++ b/themes/danbooru/comment.theme.php @@ -25,6 +25,10 @@ class CustomCommentListTheme extends CommentListTheme { // parts for each image $position = 10; + + $comment_captcha = $config->get_bool('comment_captcha'); + $comment_limit = $config->get_int("comment_list_count", 10); + foreach($images as $pair) { $image = $pair[0]; $comments = $pair[1]; @@ -42,7 +46,7 @@ class CustomCommentListTheme extends CommentListTheme { $r = class_exists("Ratings") ? "Rating ".Ratings::rating_to_human($image->rating) : ""; $comment_html = "Date $p $s User $un $s $r
    Tags $t

     "; - $comment_limit = $config->get_int("comment_list_count", 10); + $comment_count = count($comments); if($comment_limit > 0 && $comment_count > $comment_limit) { $hidden = $comment_count - $comment_limit; @@ -57,7 +61,7 @@ class CustomCommentListTheme extends CommentListTheme { $comment_html .= $this->build_postbox($image->id); } else { - if(!$config->get_bool('comment_captcha')) { + if(!$comment_captcha) { $comment_html .= $this->build_postbox($image->id); } else { diff --git a/themes/danbooru/view.theme.php b/themes/danbooru/view.theme.php index 31c553e9..ae5895e6 100644 --- a/themes/danbooru/view.theme.php +++ b/themes/danbooru/view.theme.php @@ -38,7 +38,7 @@ class CustomViewImageTheme extends ViewImageTheme { $html .= "
    Source: link"; } - if(!is_null($image->rating) && file_exists("ext/rating")) { + if(file_exists("ext/rating")) { if($image->rating == null || $image->rating == "u"){ $image->rating = "u"; } diff --git a/themes/lite/view.theme.php b/themes/lite/view.theme.php index 70fd4583..1327b33a 100644 --- a/themes/lite/view.theme.php +++ b/themes/lite/view.theme.php @@ -44,7 +44,7 @@ class CustomViewImageTheme extends ViewImageTheme { $html .= "
    Source: link"; } - if(!is_null($image->rating) && file_exists("ext/rating")) { + if(file_exists("ext/rating")) { if($image->rating == null || $image->rating == "u"){ $image->rating = "u"; }