Merge pull request #107 from DakuTree/master

Reset Image ids & Download all images
This commit is contained in:
Shish Moom 2012-02-07 20:32:28 -08:00
commit 1b5f1dcafb
7 changed files with 131 additions and 21 deletions

6
.gitignore vendored
View File

@ -1,8 +1,10 @@
.svn
backup
config.php
images
thumbs
data
images
imgdump-*.zip
thumbs
sql.log
shimmie.log
!lib/images

View File

@ -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?
}
}
?>

View File

@ -19,13 +19,26 @@ class AdminPageTheme extends Themelet {
public function display_form(Page $page) {
global $user;
$html = "
".make_form(make_link("admin_utils"))."
<select name='action'>
$html = '
<script type="text/javascript">
function imgidconfirm(){
if(document.getElementById("misc").selectedIndex == 4){
if(confirm("This function WILL break any bookmarks & links.\n The event log will also not be updated with new ids. \n Are you sure you wish to continue?")){
return true;
}else{
return false;
}
}
}
</script>
'.make_form(make_link("admin_utils"),"post", false, false, "return imgidconfirm()")."
<select name='action' id='misc'>
<option value='lowercase all tags'>All tags to lowercase</option>
<option value='recount tag use'>Recount tag use</option>
<option value='purge unused tags'>Purge unused tags</option>
<option value='database dump'>Download database contents</option>
<option value='reset image ids'>Reset image ids</option>
<option value='image dump'>Download all images</option>
<!--<option value='convert to innodb'>Convert database to InnoDB (MySQL only)</option>-->
</select>
<input type='submit' value='Go'>

View File

@ -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 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("<li>Rating: (.*) <span")[1];
}else{
var rtg=document.getElementById("stats").innerHTML.match("<li>Rating: (.*)<\/li>")[1];
var srx="http://" + document.location.hostname + document.location.href.match("\/post\/show\/[0-9]+\/");
}
if(tag.search(/\bflash\b/)===-1){
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("<li>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);}
}

View File

@ -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 .= '<p><a href="javascript:var ste=&quot;'. $link . $delimiter .'url=&quot;; var supext=&quot;'.$supported_ext.'&quot;; var maxsze=&quot;'.$max_kb.'&quot;; void(document.body.appendChild(document.createElement(&quot;script&quot;)).src=&quot;'.make_http(make_link("ext/upload/bookmarklet.js")).'&quot;)">'.
//CA=0: Ask to use current or new tags | CA=1: Always use current tags | CA=2: Always use new tags
$html .= '<p><a href="javascript:var ste=&quot;'. $link . $delimiter .'url=&quot;; var supext=&quot;'.$supported_ext.'&quot;; var maxsze=&quot;'.$max_kb.'&quot;; var CA=0; void(document.body.appendChild(document.createElement(&quot;script&quot;)).src=&quot;'.make_http(get_base_href())."/ext/upload/bookmarklet.js".'&quot;)">'.
$title . '</a> (Click when looking at an image page. Works on sites running Shimmie/Danbooru/Gelbooru. (This also grabs the tags/rating/source!))';
}

View File

@ -38,7 +38,7 @@ class CustomViewImageTheme extends ViewImageTheme {
$html .= "<br>Source: <a href='$h_source'>link</a>";
}
if(!is_null($image->rating) && file_exists("ext/rating")) {
if(file_exists("ext/rating")) {
if($image->rating == null || $image->rating == "u"){
$image->rating = "u";
}

View File

@ -44,7 +44,7 @@ class CustomViewImageTheme extends ViewImageTheme {
$html .= "<br>Source: <a href='$h_source'>link</a>";
}
if(!is_null($image->rating) && file_exists("ext/rating")) {
if(file_exists("ext/rating")) {
if($image->rating == null || $image->rating == "u"){
$image->rating = "u";
}