2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
2009-07-21 03:18:40 +00:00
|
|
|
* \page themes Themes
|
|
|
|
*
|
|
|
|
* Each extension has a theme with a specific name -- eg. the extension Setup
|
|
|
|
* which is stored in ext/setup/main.php will have a theme called SetupTheme
|
|
|
|
* stored in ext/setup/theme.php. If you want to customise it, create a class
|
|
|
|
* in the file themes/mytheme/setup.theme.php called CustomSetupTheme which
|
|
|
|
* extends SetupTheme and overrides some of its methods.
|
|
|
|
*
|
|
|
|
* Generally an extension should only deal with processing data; whenever it
|
|
|
|
* wants to display something, it should pass the $page data structure along
|
|
|
|
* with the data to be displayed to the theme object, and the theme will add
|
|
|
|
* the data into the page.
|
2009-07-21 06:36:12 +00:00
|
|
|
*
|
|
|
|
* A page should make sure that all the data it outputs is free from dangerous
|
|
|
|
* data by using html_escape(), url_escape(), or int_escape() as appropriate.
|
|
|
|
*
|
|
|
|
* Because some HTML can be placed anywhere according to the theme, coming up
|
|
|
|
* with the correct way to link to a page can be hard -- thus we have the
|
|
|
|
* make_link() function, which will take a path like "post/list" and turn it
|
|
|
|
* into a full and correct link, eg /myboard/post/list, /foo/index.php?q=post/list,
|
|
|
|
* etc depending on how things are set up. This should always be used to link
|
|
|
|
* to pages rather than hardcoding a path.
|
|
|
|
*
|
|
|
|
* Various other common functions are available as part of the Themelet class.
|
2009-07-19 07:38:13 +00:00
|
|
|
*/
|
|
|
|
|
2009-07-21 03:18:40 +00:00
|
|
|
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
|
|
|
* 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,
|
2009-07-21 06:36:12 +00:00
|
|
|
* then Layout turns it into HTML
|
2009-07-19 07:38:13 +00:00
|
|
|
*/
|
2009-07-21 06:36:12 +00:00
|
|
|
class Page {
|
2007-04-16 11:58:25 +00:00
|
|
|
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.
|
|
|
|
*/
|
2007-04-16 11:58:25 +00:00
|
|
|
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
|
|
|
|
*/
|
2007-04-16 11:58:25 +00:00
|
|
|
public function set_type($type) {
|
|
|
|
$this->type = $type;
|
|
|
|
}
|
|
|
|
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
// ==============================================
|
|
|
|
|
|
|
|
// data
|
|
|
|
var $data = "";
|
2008-05-25 23:02:17 +00:00
|
|
|
var $filename = null;
|
2007-04-16 11:58:25 +00:00
|
|
|
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
|
|
|
* If the page is in "data" mode, this will set the data to be sent
|
|
|
|
*/
|
2007-04-16 11:58:25 +00:00
|
|
|
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
|
|
|
|
*/
|
2008-05-25 23:02:17 +00:00
|
|
|
public function set_filename($filename) {
|
|
|
|
$this->filename = $filename;
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ==============================================
|
|
|
|
|
|
|
|
// 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
|
|
|
|
*/
|
2007-04-16 11:58:25 +00:00
|
|
|
public function set_redirect($redirect) {
|
|
|
|
$this->redirect = $redirect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ==============================================
|
|
|
|
|
|
|
|
// page
|
|
|
|
var $title = "";
|
|
|
|
var $heading = "";
|
|
|
|
var $subheading = "";
|
|
|
|
var $quicknav = "";
|
2007-05-01 12:41:44 +00:00
|
|
|
var $headers = array();
|
2007-06-30 01:19:11 +00:00
|
|
|
var $blocks = array();
|
2007-04-16 11:58:25 +00:00
|
|
|
|
2009-07-19 07:38:13 +00:00
|
|
|
/**
|
|
|
|
* If the page is in "page" mode, set the window title
|
|
|
|
*/
|
2007-04-16 11:58:25 +00:00
|
|
|
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
|
|
|
|
*/
|
2007-04-16 11:58:25 +00:00
|
|
|
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
|
|
|
|
*/
|
2007-04-16 11:58:25 +00:00
|
|
|
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
|
|
|
|
*/
|
2007-05-01 12:41:44 +00:00
|
|
|
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
|
|
|
|
*/
|
2007-06-30 01:19:11 +00:00
|
|
|
public function add_block($block) {
|
|
|
|
$this->blocks[] = $block;
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ==============================================
|
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
|
|
|
|
*/
|
2009-05-11 14:04:33 +00:00
|
|
|
public function display() {
|
|
|
|
global $page;
|
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
header("Content-type: {$this->type}");
|
2009-01-04 16:24:06 +00:00
|
|
|
header("X-Powered-By: SCore-".SCORE_VERSION);
|
2007-04-16 11:58:25 +00:00
|
|
|
|
|
|
|
switch($this->mode) {
|
|
|
|
case "page":
|
|
|
|
header("Cache-control: no-cache");
|
2007-06-30 01:19:11 +00:00
|
|
|
usort($this->blocks, "blockcmp");
|
2009-07-19 18:35:46 +00:00
|
|
|
$this->add_auto_headers();
|
2007-06-30 01:19:11 +00:00
|
|
|
$layout = new Layout();
|
2009-05-11 14:04:33 +00:00
|
|
|
$layout->display_page($page);
|
2007-04-16 11:58:25 +00:00
|
|
|
break;
|
|
|
|
case "data":
|
2009-12-26 01:00:38 +00:00
|
|
|
header("Content-Length: ".strlen($this->data));
|
2008-05-25 23:02:17 +00:00
|
|
|
if(!is_null($this->filename)) {
|
|
|
|
header('Content-Disposition: attachment; filename='.$this->filename);
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2009-07-19 18:35:46 +00:00
|
|
|
|
2009-08-24 02:00:42 +00:00
|
|
|
protected function add_auto_headers() {
|
2009-07-19 18:35:46 +00:00
|
|
|
$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>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
?>
|