download all images function for admin

This commit is contained in:
Daku 2012-02-06 06:52:04 +00:00
parent 1fd565fa87
commit 07e786101d
3 changed files with 30 additions and 1 deletions

4
.gitignore vendored
View file

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

View file

@ -82,6 +82,9 @@ class AdminPage extends SimpleExtension {
$this->reset_imageids(); $this->reset_imageids();
$redirect = true; $redirect = true;
break; break;
case 'image dump':
$this->imgdump($page);
break;
} }
if($redirect) { if($redirect) {
@ -218,5 +221,28 @@ class AdminPage extends SimpleExtension {
$count = (count($image)) + 1; $count = (count($image)) + 1;
$database->execute("ALTER TABLE images AUTO_INCREMENT=".$count); $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

@ -27,6 +27,7 @@ class AdminPageTheme extends Themelet {
<option value='purge unused tags'>Purge unused tags</option> <option value='purge unused tags'>Purge unused tags</option>
<option value='database dump'>Download database contents</option> <option value='database dump'>Download database contents</option>
<option value='reset image ids'>Reset image ids</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>--> <!--<option value='convert to innodb'>Convert database to InnoDB (MySQL only)</option>-->
</select> </select>
<input type='submit' value='Go'> <input type='submit' value='Go'>