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 3d03915d..c7e5b1a1 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -78,6 +78,13 @@ class AdminPage extends SimpleExtension { 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 SimpleExtension { } } */ + + 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/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/theme.php b/ext/upload/theme.php index 9e66e457..17410a96 100644 --- a/ext/upload/theme.php +++ b/ext/upload/theme.php @@ -145,8 +145,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 +155,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/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"; }