2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class BulkAddEvent extends Event
|
|
|
|
{
|
|
|
|
public $dir;
|
|
|
|
public $results;
|
2015-08-23 15:09:52 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function __construct(string $dir)
|
|
|
|
{
|
|
|
|
$this->dir = $dir;
|
|
|
|
$this->results = [];
|
|
|
|
}
|
2015-08-23 15:09:52 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class BulkAdd extends Extension
|
|
|
|
{
|
|
|
|
public function onPageRequest(PageRequestEvent $event)
|
|
|
|
{
|
|
|
|
global $page, $user;
|
|
|
|
if ($event->page_matches("bulk_add")) {
|
2019-09-29 18:00:51 +00:00
|
|
|
if ($user->can(Permissions::BULK_ADD) && $user->check_auth_token() && isset($_POST['dir'])) {
|
2019-05-28 16:59:38 +00:00
|
|
|
set_time_limit(0);
|
|
|
|
$bae = new BulkAddEvent($_POST['dir']);
|
|
|
|
send_event($bae);
|
2019-06-14 12:16:58 +00:00
|
|
|
foreach ($bae->results as $result) {
|
|
|
|
$this->theme->add_status("Adding files", $result);
|
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->theme->display_upload_results($page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onCommand(CommandEvent $event)
|
|
|
|
{
|
|
|
|
if ($event->cmd == "help") {
|
|
|
|
print "\tbulk-add [directory]\n";
|
|
|
|
print "\t\tImport this directory\n\n";
|
|
|
|
}
|
|
|
|
if ($event->cmd == "bulk-add") {
|
|
|
|
if (count($event->args) == 1) {
|
|
|
|
$bae = new BulkAddEvent($event->args[0]);
|
|
|
|
send_event($bae);
|
|
|
|
print(implode("\n", $bae->results));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-17 19:05:16 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onAdminBuilding(AdminBuildingEvent $event)
|
|
|
|
{
|
|
|
|
$this->theme->display_admin_block();
|
|
|
|
}
|
2014-04-26 02:54:51 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onBulkAdd(BulkAddEvent $event)
|
|
|
|
{
|
|
|
|
if (is_dir($event->dir) && is_readable($event->dir)) {
|
|
|
|
$event->results = add_dir($event->dir);
|
|
|
|
} else {
|
|
|
|
$h_dir = html_escape($event->dir);
|
|
|
|
$event->results[] = "Error, $h_dir is not a readable directory";
|
|
|
|
}
|
|
|
|
}
|
2015-08-23 15:09:52 +00:00
|
|
|
}
|