This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/bulk_add/main.php

63 lines
1.7 KiB
PHP
Raw Normal View History

<?php
class BulkAddEvent extends Event
{
public $dir;
public $results;
2015-08-23 15:09:52 +00:00
public function __construct(string $dir)
{
$this->dir = $dir;
$this->results = [];
}
2015-08-23 15:09:52 +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'])) {
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);
}
$this->theme->display_upload_results($page);
}
}
}
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));
}
}
}
public function onAdminBuilding(AdminBuildingEvent $event)
{
$this->theme->display_admin_block();
}
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
}