Added manual page mode to allow extensions to have direct control of the output
This commit is contained in:
parent
6145ecc6f8
commit
16c58e266b
2 changed files with 32 additions and 12 deletions
|
@ -7,6 +7,7 @@ abstract class PageMode
|
||||||
const DATA = 'data';
|
const DATA = 'data';
|
||||||
const PAGE = 'page';
|
const PAGE = 'page';
|
||||||
const FILE = 'file';
|
const FILE = 'file';
|
||||||
|
const MANUAL = 'manual';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -238,16 +239,13 @@ class BasePage
|
||||||
|
|
||||||
// ==============================================
|
// ==============================================
|
||||||
|
|
||||||
/**
|
public function send_headers(): void
|
||||||
* Display the page according to the mode and data given.
|
|
||||||
*/
|
|
||||||
public function display(): void
|
|
||||||
{
|
{
|
||||||
header("HTTP/1.0 {$this->code} Shimmie");
|
|
||||||
header("Content-type: " . $this->type);
|
|
||||||
header("X-Powered-By: Shimmie-" . VERSION);
|
|
||||||
|
|
||||||
if (!headers_sent()) {
|
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) {
|
foreach ($this->http_headers as $head) {
|
||||||
header($head);
|
header($head);
|
||||||
}
|
}
|
||||||
|
@ -257,8 +255,25 @@ class BasePage
|
||||||
} else {
|
} else {
|
||||||
print "Error: Headers have already been sent to the client.";
|
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) {
|
switch ($this->mode) {
|
||||||
|
case PageMode::MANUAL:
|
||||||
|
break;
|
||||||
case PageMode::PAGE:
|
case PageMode::PAGE:
|
||||||
usort($this->blocks, "blockcmp");
|
usort($this->blocks, "blockcmp");
|
||||||
$this->add_auto_html_headers();
|
$this->add_auto_html_headers();
|
||||||
|
|
|
@ -150,6 +150,14 @@ function list_files(string $base, string $_sub_dir=""): array
|
||||||
return $file_list;
|
return $file_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function flush_output(): void
|
||||||
|
{
|
||||||
|
if (!defined("UNITTEST")) {
|
||||||
|
@ob_flush();
|
||||||
|
}
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
function stream_file(string $file, int $start, int $end): void
|
function stream_file(string $file, int $start, int $end): void
|
||||||
{
|
{
|
||||||
$fp = fopen($file, 'r');
|
$fp = fopen($file, 'r');
|
||||||
|
@ -162,10 +170,7 @@ function stream_file(string $file, int $start, int $end): void
|
||||||
$buffer = $end - $p + 1;
|
$buffer = $end - $p + 1;
|
||||||
}
|
}
|
||||||
echo fread($fp, $buffer);
|
echo fread($fp, $buffer);
|
||||||
if (!defined("UNITTEST")) {
|
flush_output();
|
||||||
@ob_flush();
|
|
||||||
}
|
|
||||||
flush();
|
|
||||||
|
|
||||||
// After flush, we can tell if the client browser has disconnected.
|
// 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
|
// This means we can start sending a large file, and if we detect they disappeared
|
||||||
|
|
Reference in a new issue