cavepaintingsFork/core/page.class.php

168 lines
3.6 KiB
PHP
Raw Normal View History

<?php
2009-07-19 07:38:13 +00:00
/**
* @package SCore
*/
/**
* A data structure for holding all the bits of data that make up a page.
*
* The various extensions all add whatever they want to this structure,
* then layout.class.php turns it into HTML
*/
class GenericPage {
var $mode = "page";
var $type = "text/html";
2009-07-19 07:38:13 +00:00
/**
* Set what this page should do; page, data, or redirect.
*/
public function set_mode($mode) {
$this->mode = $mode;
}
2009-01-04 19:18:37 +00:00
2009-07-19 07:38:13 +00:00
/**
* Set the page's MIME type
*/
public function set_type($type) {
$this->type = $type;
}
2009-01-04 19:18:37 +00:00
// ==============================================
// data
var $data = "";
var $filename = null;
2009-07-19 07:38:13 +00:00
/**
* If the page is in "data" mode, this will set the data to be sent
*/
public function set_data($data) {
$this->data = $data;
}
2009-01-04 19:18:37 +00:00
2009-07-19 07:38:13 +00:00
/**
* If the page is in "data" mode, this will set the recommended download filename
*/
public function set_filename($filename) {
$this->filename = $filename;
}
// ==============================================
// redirect
var $redirect = "";
2009-07-19 07:38:13 +00:00
/**
* If the page is in "redirect" mode, this will set where to redirect to
*/
public function set_redirect($redirect) {
$this->redirect = $redirect;
}
// ==============================================
// page
var $title = "";
var $heading = "";
var $subheading = "";
var $quicknav = "";
var $headers = array();
var $blocks = array();
2009-07-19 07:38:13 +00:00
/**
* If the page is in "page" mode, set the window title
*/
public function set_title($title) {
$this->title = $title;
}
2009-07-19 07:38:13 +00:00
/**
* If the page is in "page" mode, set the main heading
*/
public function set_heading($heading) {
$this->heading = $heading;
}
2009-07-19 07:38:13 +00:00
/**
* If the page is in "page" mode, set the sub heading
*/
public function set_subheading($subheading) {
$this->subheading = $subheading;
}
2009-07-19 07:38:13 +00:00
/**
* If the page is in "page" mode, add a line to the HTML head section
*/
public function add_header($line, $position=50) {
while(isset($this->headers[$position])) $position++;
$this->headers[$position] = $line;
}
2009-07-19 07:38:13 +00:00
/**
* If the page is in "page" mode, add a block of data
*/
public function add_block($block) {
$this->blocks[] = $block;
}
// ==============================================
2009-01-04 19:18:37 +00:00
2009-07-19 07:38:13 +00:00
/**
* display the page according to the mode and data given
*/
public function display() {
global $page;
header("Content-type: {$this->type}");
2009-01-04 16:24:06 +00:00
header("X-Powered-By: SCore-".SCORE_VERSION);
switch($this->mode) {
case "page":
header("Cache-control: no-cache");
usort($this->blocks, "blockcmp");
$this->add_auto_headers();
$layout = new Layout();
$layout->display_page($page);
break;
case "data":
if(!is_null($this->filename)) {
header('Content-Disposition: attachment; filename='.$this->filename);
}
print $this->data;
break;
case "redirect":
header("Location: {$this->redirect}");
print "You should be redirected to <a href='{$this->redirect}'>{$this->redirect}</a>";
break;
default:
print "Invalid page mode";
break;
}
}
private function add_auto_headers() {
$data_href = get_base_href();
foreach(glob("lib/*.js") as $js) {
$this->add_header("<script src='$data_href/$js' type='text/javascript'></script>");
}
$css_files = glob("ext/*/style.css");
if($css_files) {
foreach($css_files as $css_file) {
$this->add_header("<link rel='stylesheet' href='$data_href/$css_file' type='text/css'>");
}
}
$js_files = glob("ext/*/script.js");
if($js_files) {
foreach($js_files as $js_file) {
$this->add_header("<script src='$data_href/$js_file' type='text/javascript'></script>");
}
}
}
}
?>