diff -r 4629ad98ee88 -r 9cdfe82c56cd includes/output.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/includes/output.php Sat Jan 03 18:11:18 2009 -0500 @@ -0,0 +1,262 @@ +header(). + * @access public + */ + + abstract public function header(); + + /** + * Call this to send extra stuff after the content (equivalent of $template->footer()). + * @access public + */ + + abstract public function footer(); + + /** + * Add some code just before the header. + * @access public + */ + + public function add_before_header($code) + { + $this->before_header .= $code; + } + + /** + * Add some code just after the header. + * @access public + */ + + public function add_after_header($code) + { + $this->after_header .= $code; + } + + /** + * Add some code just before the footer. + * @access public + */ + + public function add_before_footer($code) + { + $this->before_footer .= $code; + } + + /** + * Add some code just after the footer. + * @access public + */ + + public function add_after_footer($code) + { + $this->after_footer .= $code; + } + + /** + * Send any required HTML headers through, e.g. Content-type. + * @access public + */ + + public function http_headers() + { + header('Content-type: text/html'); + } + + /** + * Set the title of the page being output. + * @param string Page name + */ + + public function set_title($title) + { + $this->title = $title; + } + + /** + * Avoid sending things out of order. + * @var bool + * @var bool + */ + + public $headers_sent = false, $footers_sent = false; +} + +/** + * HTML outputter. + */ + +class Output_HTML extends Output_Base +{ + public function header() + { + if ( $this->headers_sent ) + return; + + $this->headers_sent = true; + + ob_start(); + } + + public function footer() + { + global $template; + if ( !$this->headers_sent ) + return; + + $this->headers_sent = false; + $content = ob_get_contents(); + ob_end_clean(); + + ob_start(); + echo $this->before_header; + echo $template->getHeader(); + echo $this->after_header; + echo $content; + echo $this->before_footer; + echo $template->getFooter(); + echo $this->after_footer; + + } + + public function set_title($title) + { + global $template; + $template->assign_vars(array( + 'PAGE_NAME' => $title + )); + } +} + +/** + * Outputter that bypasses $template->header() and $template->footer(), but still shows HTML added via {before,after}_{header,footer}. + */ + +class Output_Striptease extends Output_HTML +{ + public function header() + { + echo $this->before_header; + echo $this->after_header; + } + + public function footer() + { + echo $this->before_footer; + echo $this->after_footer; + } +} + +/** + * Outputter that bypasses $template->header() and $template->footer(). + */ + +class Output_Naked extends Output_HTML +{ + public $naked = true; + + public function header() + { + } + + public function footer() + { + } +} + +/** + * Safe template outputter + */ + +class Output_Safe +{ + protected $template; + protected $headers_sent = false; + public function __construct() + { + $this->template = new template_nodb(); + $theme = ( defined('ENANO_CONFIG_FETCHED') ) ? getConfig('theme_default') : 'oxygen'; + $style = ( defined('ENANO_CONFIG_FETCHED') ) ? '__foo__' : 'bleu'; + + $this->template->load_theme($theme, $style); + $this->template->tpl_strings['SITE_NAME'] = getConfig('site_name'); + $this->template->tpl_strings['SITE_DESC'] = getConfig('site_desc'); + $this->template->tpl_strings['COPYRIGHT'] = getConfig('copyright_notice'); + $this->template->tpl_strings['PAGE_NAME'] = 'Untitled'; + } + public function header() + { + if ( $this->headers_sent ) + return; + + $this->headers_sent = true; + + $this->template->header(); + } + + public function footer() + { + global $template; + if ( !$this->headers_sent ) + { + $this->template->header(); + } + + $this->headers_sent = false; + $this->template->footer(); + + } + + public function set_title($title) + { + $this->template->tpl_strings['PAGE_NAME'] = $title; + } +} + +?>