2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class BulkAdd extends Extension {
|
2007-06-30 01:19:11 +00:00
|
|
|
var $theme;
|
2007-04-16 11:58:25 +00:00
|
|
|
// event handler {{{
|
|
|
|
public function receive_event($event) {
|
2007-06-30 01:19:11 +00:00
|
|
|
if(is_null($this->theme)) $this->theme = get_theme_object("bulk_add", "BulkAddTheme");
|
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "bulk_add")) {
|
|
|
|
global $user;
|
|
|
|
if($user->is_admin() && isset($_POST['dir'])) {
|
2007-05-04 23:31:30 +00:00
|
|
|
set_time_limit(0);
|
|
|
|
|
2007-06-30 01:19:11 +00:00
|
|
|
$this->theme->display_upload_results($event->page_object);
|
2007-04-16 11:58:25 +00:00
|
|
|
$this->add_dir($_POST['dir']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_a($event, 'AdminBuildingEvent')) {
|
|
|
|
global $page;
|
2007-06-30 01:19:11 +00:00
|
|
|
$this->theme->display_admin_block($page);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
// do the adding {{{
|
|
|
|
private function add_image($tmpname, $filename, $tags) {
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$ok = false;
|
|
|
|
|
|
|
|
if(filesize($tmpname) > $config->get_int('upload_size')) {
|
2007-06-30 01:19:11 +00:00
|
|
|
// $page->add_block(new Block("Error with ".html_escape($filename),
|
2007-04-16 11:58:25 +00:00
|
|
|
// "File too large (".filesize($file['tmp_name'])." > ".
|
|
|
|
// ($config->get_int('upload_size')).")"));
|
|
|
|
}
|
|
|
|
else if(!($info = getimagesize($tmpname))) {
|
2007-06-30 01:19:11 +00:00
|
|
|
// $page->add_block(new Block("Error with ".html_escape($file['name']),
|
2007-04-16 11:58:25 +00:00
|
|
|
// "PHP doesn't recognise this as an image file"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$image = new Image($tmpname, $filename, $tags);
|
|
|
|
|
|
|
|
if($image->is_ok()) {
|
|
|
|
send_event(new UploadingImageEvent($image));
|
|
|
|
$ok = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function add_dir($base, $subdir="") {
|
|
|
|
global $page;
|
|
|
|
|
|
|
|
if(!is_dir($base)) {
|
2007-06-30 01:19:11 +00:00
|
|
|
$this->theme->add_status("Error", "$base is not a directory");
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$list = "";
|
|
|
|
|
|
|
|
$dir = opendir("$base/$subdir");
|
|
|
|
while($filename = readdir($dir)) {
|
|
|
|
$fullpath = "$base/$subdir/$filename";
|
|
|
|
|
|
|
|
if(is_dir($fullpath)) {
|
|
|
|
if($filename[0] != ".") {
|
|
|
|
$this->add_dir($base, "$subdir/$filename");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$tmpfile = $fullpath;
|
|
|
|
$list .= "<br>".html_escape("$subdir/$filename (".str_replace("/", ",", $subdir).")...");
|
|
|
|
if($this->add_image($tmpfile, $filename, str_replace("/", " ", $subdir))) {
|
|
|
|
$list .= "ok\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$list .= "failed\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir);
|
|
|
|
|
2007-06-30 01:19:11 +00:00
|
|
|
$this->theme->add_status("Adding $subdir", $list);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
}
|
|
|
|
add_event_listener(new BulkAdd());
|
|
|
|
?>
|