diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php
index 9c4bf2ac..985c9b25 100644
--- a/core/imageboard.pack.php
+++ b/core/imageboard.pack.php
@@ -1282,27 +1282,28 @@ function move_upload_to_archive(DataUploadEvent $event) {
* Add a directory full of images
*
* @param $base string
- * @return string
+ * @return array
*/
function add_dir(/*string*/ $base) {
- $list = "";
+ $results = array();
foreach(list_files($base) as $full_path) {
$short_path = str_replace($base, "", $full_path);
$filename = basename($full_path);
$tags = path_to_tags($short_path);
- $list .= "
".html_escape("$short_path (".str_replace(" ", ", ", $tags).")... ");
+ $result = "$short_path (".str_replace(" ", ", ", $tags).")... ";
try {
add_image($full_path, $filename, $tags);
- $list .= "ok\n";
+ $result .= "ok";
}
catch(UploadException $ex) {
- $list .= "failed: ".$ex->getMessage()."\n";
+ $result .= "failed: ".$ex->getMessage();
}
+ $results[] = $result;
}
- return $list;
+ return $results;
}
/**
diff --git a/core/page.class.php b/core/page.class.php
index 03db3bae..3d35fee5 100644
--- a/core/page.class.php
+++ b/core/page.class.php
@@ -1,13 +1,13 @@
code} Shimmie");
header("Content-type: ".$this->type);
header("X-Powered-By: SCore-".SCORE_VERSION);
@@ -268,7 +269,6 @@ class Page {
switch($this->mode) {
case "page":
- header("HTTP/1.0 {$this->code} Shimmie");
if(CACHE_HTTP) {
header("Vary: Cookie, Accept-Encoding");
if($user->is_anonymous() && $_SERVER["REQUEST_METHOD"] == "GET") {
@@ -309,16 +309,16 @@ class Page {
break;
}
}
-
+
/**
* This function grabs all the CSS and JavaScript files sprinkled throughout Shimmie's folders,
* concatenates them together into two large files (one for CSS and one for JS) and then stores
* them in the /cache/ directory for serving to the user.
- *
+ *
* Why do this? Two reasons:
* 1. Reduces the number of files the user's browser needs to download.
* 2. Allows these cached files to be compressed/minified by the admin.
- *
+ *
* TODO: This should really be configurable somehow...
*/
public function add_auto_html_headers() {
@@ -378,4 +378,3 @@ class Page {
class MockPage extends Page {
}
-
diff --git a/ext/bulk_add/main.php b/ext/bulk_add/main.php
index c0c0a50c..bb0d73b7 100644
--- a/ext/bulk_add/main.php
+++ b/ext/bulk_add/main.php
@@ -15,21 +15,25 @@
*
Note: requires the "admin" extension to be enabled
*/
+class BulkAddEvent extends Event {
+ public $dir, $results;
+
+ public function __construct($dir) {
+ $this->dir = $dir;
+ $this->results = array();
+ }
+}
+
class BulkAdd extends Extension {
public function onPageRequest(PageRequestEvent $event) {
global $page, $user;
if($event->page_matches("bulk_add")) {
if($user->is_admin() && $user->check_auth_token() && isset($_POST['dir'])) {
set_time_limit(0);
- $list = add_dir($_POST['dir']);
- if(strlen($list) > 0) {
- $this->theme->add_status("Adding files", $list);
- } else {
- if(is_dir($_POST['dir'])) {
- $this->theme->add_status("No files in directory", "No files exists in specified directory ({$_POST['dir']}).");
- } else {
- $this->theme->add_status("Directory does not exist", "Specified directory does not exist ({$_POST['dir']}).");
- }
+ $bae = new BulkAddEvent($_POST['dir']);
+ send_event($bae);
+ if(strlen($bae->results) > 0) {
+ $this->theme->add_status("Adding files", $bae->results);
}
$this->theme->display_upload_results($page);
}
@@ -38,15 +42,14 @@ class BulkAdd extends Extension {
public function onCommand(CommandEvent $event) {
if($event->cmd == "help") {
- print " bulk-add [directory]\n";
- print " Import this directory\n\n";
+ print "\tbulk-add [directory]\n";
+ print "\t\tImport this directory\n\n";
}
if($event->cmd == "bulk-add") {
if(count($event->args) == 1) {
- $list = add_dir($event->args[0]);
- if(strlen($list) > 0) {
- $this->theme->add_status("Adding files", $list);
- }
+ $bae = new BulkAddEvent($event->args[0]);
+ send_event($bae);
+ print(implode("\n", $bae->results));
}
}
}
@@ -54,5 +57,14 @@ class BulkAdd extends Extension {
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";
+ }
+ }
+}
diff --git a/ext/bulk_add/test.php b/ext/bulk_add/test.php
index 84d639ee..e9fabb75 100644
--- a/ext/bulk_add/test.php
+++ b/ext/bulk_add/test.php
@@ -1,18 +1,21 @@
log_in_as_admin();
$this->get_page('admin');
$this->assert_title("Admin Tools");
- $this->set_field('dir', "asdf");
- $this->click("Add");
- $this->assert_text("is not a directory");
+
+ $bae = new BulkAddEvent('asdf');
+ send_event($bae);
+ $this->assertContains("Error, asdf is not a readable directory",
+ $bae->results, implode("\n", $bae->results));
+
+ return; // FIXME: have BAE return a list of successes as well as errors?
$this->get_page('admin');
$this->assert_title("Admin Tools");
- $this->set_field('dir', "tests");
- $this->click("Add");
+ send_event(new BulkAddEvent('tests'));
# FIXME: test that the output here makes sense, no "adding foo.php ... ok"
@@ -31,4 +34,3 @@ class BulkAddTest {
$this->log_out();
}
}
-
diff --git a/ext/bulk_add/theme.php b/ext/bulk_add/theme.php
index 787a4532..02a31d13 100644
--- a/ext/bulk_add/theme.php
+++ b/ext/bulk_add/theme.php
@@ -10,9 +10,11 @@ class BulkAddTheme extends Themelet {
$page->set_title("Adding folder");
$page->set_heading("Adding folder");
$page->add_block(new NavBlock());
+ $html = "";
foreach($this->messages as $block) {
- $page->add_block($block);
+ $html .= "
" . html_escape($html);
}
+ $page->add_block(new Block("Results", $block));
}
/*
@@ -21,7 +23,7 @@ class BulkAddTheme extends Themelet {
* directory full of images
*/
public function display_admin_block() {
- global $page, $user;
+ global $page;
$html = "
Add a folder full of images; any subfolders will have their names
used as tags for the images within.
@@ -42,4 +44,3 @@ class BulkAddTheme extends Themelet {
$this->messages[] = new Block($title, $body);
}
}
-
diff --git a/ext/downtime/main.php b/ext/downtime/main.php
index 2c857fba..3eb44164 100644
--- a/ext/downtime/main.php
+++ b/ext/downtime/main.php
@@ -29,7 +29,11 @@ class Downtime extends Extension {
if(!$user->can("ignore_downtime") && !$this->is_safe_page($event)) {
$msg = $config->get_string("downtime_message");
$this->theme->display_message($msg);
- exit;
+ if(!defined("UNITTEST")) { // hax D:
+ header("HTTP/1.0 {$page->code} Downtime");
+ print($page->data);
+ exit;
+ }
}
$this->theme->display_notification($page);
}
@@ -40,4 +44,3 @@ class Downtime extends Extension {
else return false;
}
}
-
diff --git a/ext/downtime/test.php b/ext/downtime/test.php
index 37850ef2..561e0018 100644
--- a/ext/downtime/test.php
+++ b/ext/downtime/test.php
@@ -1,23 +1,39 @@
set_bool("downtime", false);
+ }
+
function testDowntime() {
- $this->log_in_as_admin();
- $this->get_page("setup");
- $this->set_field("_config_downtime", true);
- $this->set_field("_config_downtime_message", "brb, unit testing");
- $this->click("Save Settings");
- $this->assert_text("DOWNTIME MODE IS ON!");
- $this->log_out();
+ global $config;
+ $config->set_string("downtime_message", "brb, unit testing");
+
+ // downtime on
+ $config->set_bool("downtime", true);
+
+ $this->log_in_as_admin();
$this->get_page("post/list");
- $this->assert_text("brb, unit testing");
+ $this->assert_text("DOWNTIME MODE IS ON!");
+ $this->assert_response(200);
+
+ $this->log_in_as_user();
+ $this->get_page("post/list");
+ $this->assert_content("brb, unit testing");
+ $this->assert_response(503);
+
+ // downtime off
+ $config->set_bool("downtime", false);
$this->log_in_as_admin();
- $this->get_page("setup");
- $this->set_field("_config_downtime", false);
- $this->click("Save Settings");
+ $this->get_page("post/list");
$this->assert_no_text("DOWNTIME MODE IS ON!");
- $this->log_out();
+ $this->assert_response(200);
+
+ $this->log_in_as_user();
+ $this->get_page("post/list");
+ $this->assert_no_content("brb, unit testing");
+ $this->assert_response(200);
}
}
-
diff --git a/ext/downtime/theme.php b/ext/downtime/theme.php
index c61123b6..965b10b2 100644
--- a/ext/downtime/theme.php
+++ b/ext/downtime/theme.php
@@ -17,14 +17,15 @@ class DowntimeTheme extends Themelet {
* @param string $message
*/
public function display_message(/*string*/ $message) {
- global $config, $user;
+ global $config, $user, $page;
$theme_name = $config->get_string('theme');
$data_href = get_base_href();
$login_link = make_link("user_admin/login");
- header("HTTP/1.0 503 Service Temporarily Unavailable");
-
$auth = $user->get_auth_html();
- print <<