Added manual page mode to allow extensions to have direct control of the output

This commit is contained in:
Matthew Barbour 2020-05-28 09:18:09 -05:00 committed by Shish
parent 6145ecc6f8
commit 16c58e266b
2 changed files with 32 additions and 12 deletions

View file

@ -7,6 +7,7 @@ abstract class PageMode
const DATA = 'data';
const PAGE = 'page';
const FILE = 'file';
const MANUAL = 'manual';
}
/**
@ -238,16 +239,13 @@ class BasePage
// ==============================================
/**
* Display the page according to the mode and data given.
*/
public function display(): void
public function send_headers(): void
{
header("HTTP/1.0 {$this->code} Shimmie");
header("Content-type: " . $this->type);
header("X-Powered-By: Shimmie-" . VERSION);
if (!headers_sent()) {
header("HTTP/1.0 {$this->code} Shimmie");
header("Content-type: " . $this->type);
header("X-Powered-By: Shimmie-" . VERSION);
foreach ($this->http_headers as $head) {
header($head);
}
@ -257,8 +255,25 @@ class BasePage
} else {
print "Error: Headers have already been sent to the client.";
}
}
public function flush_output(): void
{
}
/**
* Display the page according to the mode and data given.
*/
public function display(): void
{
if($this->mode!=PageMode::MANUAL) {
$this->send_headers();
}
switch ($this->mode) {
case PageMode::MANUAL:
break;
case PageMode::PAGE:
usort($this->blocks, "blockcmp");
$this->add_auto_html_headers();

View file

@ -150,6 +150,14 @@ function list_files(string $base, string $_sub_dir=""): array
return $file_list;
}
function flush_output(): void
{
if (!defined("UNITTEST")) {
@ob_flush();
}
flush();
}
function stream_file(string $file, int $start, int $end): void
{
$fp = fopen($file, 'r');
@ -162,10 +170,7 @@ function stream_file(string $file, int $start, int $end): void
$buffer = $end - $p + 1;
}
echo fread($fp, $buffer);
if (!defined("UNITTEST")) {
@ob_flush();
}
flush();
flush_output();
// After flush, we can tell if the client browser has disconnected.
// This means we can start sending a large file, and if we detect they disappeared