2012-06-13 13:49:10 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* MiniMVC
|
|
|
|
*
|
|
|
|
* Convention-based micro-framework for PHP
|
|
|
|
*
|
|
|
|
* @package miniMVC
|
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2011 - 2012
|
|
|
|
* @link https://github.com/aviat4ion/miniMVC
|
2012-06-14 16:33:16 -04:00
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
2012-06-13 13:49:10 -04:00
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace miniMVC;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for building pages
|
|
|
|
*
|
|
|
|
* All methods are chainable, with the exception of the constructor,
|
|
|
|
* build_header(), build_footer(), and _headers() methods.
|
|
|
|
*
|
|
|
|
* @package miniMVC
|
|
|
|
* @subpackage System
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
class Page {
|
2012-06-13 13:49:10 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Meta tags
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $meta;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* JS tags for the header
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
private $head_js;
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* JS tags for the footer
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
private $foot_js;
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* CSS tags for the page
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
private $css;
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Page title
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
private $title;
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Additional header tags
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
private $head_tags;
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Class(es) to apply to the main body tag
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
private $body_class;
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Id to apply to the body tag
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
private $body_id;
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Base tag
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $base;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Content for outputting
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $buffer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HTTP headers to send
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $headers;
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Set up the page class
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
public function __construct()
|
2012-06-13 13:49:10 -04:00
|
|
|
{
|
|
|
|
$this->meta = "";
|
|
|
|
$this->head_js = "";
|
|
|
|
$this->foot_js = "";
|
|
|
|
$this->css = "";
|
|
|
|
$this->title = "";
|
|
|
|
$this->head_tags = "";
|
|
|
|
$this->body_class = "";
|
|
|
|
$this->body_id = "";
|
|
|
|
$this->base = "";
|
2012-06-14 16:33:16 -04:00
|
|
|
$this->buffer = "";
|
|
|
|
$this->headers = array();
|
2012-06-13 13:49:10 -04:00
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
2012-06-14 16:33:16 -04:00
|
|
|
* PHP magic method called when ending the script
|
|
|
|
* Used for outputing HTML
|
|
|
|
*
|
|
|
|
* @return void
|
2012-06-13 13:49:10 -04:00
|
|
|
*/
|
|
|
|
public function __destruct()
|
|
|
|
{
|
2012-08-22 21:28:54 -04:00
|
|
|
if (headers_sent())
|
|
|
|
{
|
|
|
|
die();
|
|
|
|
}
|
2015-06-04 15:46:30 -04:00
|
|
|
|
2012-06-14 16:33:16 -04:00
|
|
|
if ( ! empty($this->headers))
|
|
|
|
{
|
|
|
|
// Set headers
|
|
|
|
foreach($this->headers as $key => $val)
|
|
|
|
{
|
|
|
|
if ( ! isset($val))
|
|
|
|
{
|
|
|
|
@header($key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@header("$key: $val");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! empty($this->buffer))
|
|
|
|
{
|
2012-08-31 16:18:23 -04:00
|
|
|
(GZ_COMPRESS) ? ob_start('ob_gzhandler') : ob_start();
|
2012-06-14 16:33:16 -04:00
|
|
|
|
|
|
|
echo $this->buffer;
|
|
|
|
|
|
|
|
// Check if a buffer exists
|
|
|
|
// so that it doesn't throw a notice
|
2012-07-12 10:31:08 -04:00
|
|
|
if (ob_get_level() > 0)
|
2012-06-14 16:33:16 -04:00
|
|
|
{
|
|
|
|
ob_end_flush();
|
|
|
|
}
|
|
|
|
}
|
2012-06-13 13:49:10 -04:00
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets server headers and doctype
|
|
|
|
*
|
|
|
|
* Also sets page mime type, based on if sent as
|
|
|
|
* html or xhtml, and what the target browser
|
|
|
|
* supports
|
|
|
|
*
|
|
|
|
* @param bool $html5
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
private function _headers($html5)
|
|
|
|
{
|
|
|
|
$this->set_header("Cache-Control", "must-revalidate, public");
|
|
|
|
$mime = "";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Variable for accept keyword
|
|
|
|
$accept = ( ! empty($_SERVER['HTTP_ACCEPT'])) ? $_SERVER['HTTP_ACCEPT'] : "";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Predefine doctype
|
|
|
|
$doctype_string = ($html5 == TRUE) ? '<!DOCTYPE html>' : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">';
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Predefine charset
|
|
|
|
$charset = "UTF-8";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
$mime = "text/html";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
if ($html5 == FALSE)
|
|
|
|
{
|
|
|
|
$doctype_string = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">';
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
$doctype_string .= "<html lang='en'>";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// finally, output the mime type and prolog type
|
|
|
|
$this->set_header("Content-Type", "{$mime};charset={$charset}");
|
|
|
|
$this->set_header("X-UA-Compatible", "chrome=1, IE=edge");
|
|
|
|
$this->set_output($doctype_string);
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Set Meta
|
|
|
|
*
|
|
|
|
* Sets meta tags, with codeigniter native meta tag helper
|
2012-06-14 16:33:16 -04:00
|
|
|
*
|
2012-06-13 13:49:10 -04:00
|
|
|
* @param array $meta
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function set_meta($meta)
|
|
|
|
{
|
|
|
|
$this->meta .= $this->_meta($meta);
|
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets minified javascript group in header
|
|
|
|
*
|
|
|
|
* @param string $group
|
|
|
|
* @param bool $debug
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function set_head_js_group($group, $debug = FALSE)
|
|
|
|
{
|
|
|
|
if ($group === FALSE)
|
|
|
|
{
|
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
$file = SCRIPT_PATH . $group;
|
|
|
|
$file .= ($debug == TRUE) ? "/debug/1" : "";
|
|
|
|
$this->head_js .= $this->script_tag($file, FALSE);
|
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets a minified css group
|
|
|
|
* @param string $group
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function set_css_group($group)
|
|
|
|
{
|
2012-06-14 16:33:16 -04:00
|
|
|
$link = array(
|
2012-06-13 13:49:10 -04:00
|
|
|
'href' => STYLE_PATH . $group,
|
|
|
|
'rel' => 'stylesheet',
|
|
|
|
'type' => 'text/css'
|
2012-06-14 16:33:16 -04:00
|
|
|
);
|
2012-06-13 13:49:10 -04:00
|
|
|
$this->css .= $this->_link_tag($link);
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets a minified javascript group for the page footer
|
|
|
|
*
|
|
|
|
* @param string $group
|
|
|
|
* @param bool $debug
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function set_foot_js_group($group, $debug = FALSE)
|
|
|
|
{
|
|
|
|
$file = SCRIPT_PATH . $group;
|
|
|
|
$file .= ($debug == TRUE) ? "/debug/1" : "";
|
|
|
|
$this->foot_js .= $this->script_tag($file, FALSE);
|
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets html title string
|
|
|
|
*
|
|
|
|
* @param string $title
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function set_title($title = "")
|
|
|
|
{
|
|
|
|
$title = ($title == "") ? DEFAULT_TITLE : $title;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
$this->title = $title;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets custom body class
|
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function set_body_class($class = "")
|
|
|
|
{
|
|
|
|
$this->body_class = $class;
|
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets custom body id
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function set_body_id($id = "")
|
|
|
|
{
|
|
|
|
$this->body_id = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets custom base href
|
|
|
|
*
|
|
|
|
* @param string href
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function set_base($href)
|
|
|
|
{
|
|
|
|
$this->base = $href;
|
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets custom css tags
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param bool $domain
|
|
|
|
* @param string $media
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function set_css_tag($name, $domain = TRUE, $media = "all")
|
|
|
|
{
|
|
|
|
$path = CONTENT_DOMAIN;
|
|
|
|
$css_file = "{$path}/css/{$name}.css";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
if ($domain == FALSE)
|
|
|
|
{
|
|
|
|
$css_file = $name;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
|
|
|
$this->css_tags .= $this->_link_tag(array(
|
2012-06-13 13:49:10 -04:00
|
|
|
'rel' => 'stylesheet',
|
|
|
|
'type' => 'text/css',
|
|
|
|
'media' => $media,
|
|
|
|
'href' => $css_file,
|
2012-06-14 16:33:16 -04:00
|
|
|
));
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets a custom tag in the header
|
|
|
|
*
|
|
|
|
* @param string $tag
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function set_head_tag($tag)
|
|
|
|
{
|
|
|
|
$this->head_tags .= $tag;
|
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Sets custom page header
|
|
|
|
*
|
|
|
|
* @param bool $html5
|
|
|
|
* @return Page
|
|
|
|
*/
|
|
|
|
public function build_header($html5 = TRUE)
|
|
|
|
{
|
|
|
|
$data = array();
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Set Meta Tags
|
2012-06-14 16:33:16 -04:00
|
|
|
$this->meta = ($html5 == TRUE)
|
|
|
|
? '<meta charset="utf-8" />'. $this->meta
|
|
|
|
: $this->_meta(array(
|
2012-06-13 13:49:10 -04:00
|
|
|
'http-equiv' => 'Content-Type',
|
|
|
|
'content' => 'text/html; charset=utf-8',
|
2012-06-14 16:33:16 -04:00
|
|
|
)) . $this->meta;
|
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
$data['meta'] = $this->meta;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Set CSS
|
|
|
|
if ($this->css !== "")
|
|
|
|
{
|
|
|
|
$data['css'] = $this->css;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Set default CSS group
|
|
|
|
$this->set_css_group(DEFAULT_CSS_GROUP);
|
|
|
|
$data['css'] = $this->css;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Set head javascript
|
|
|
|
$data['head_js'] = ( ! empty($this->head_js)) ? $this->head_js : "";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Set Page Title
|
|
|
|
$data['title'] = ($this->title !== '') ? $this->title : DEFAULT_TITLE;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Set Body Class
|
|
|
|
$data['body_class'] = $this->body_class;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Set Body Id
|
|
|
|
$data['body_id'] = $this->body_id;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Set Base HREF
|
|
|
|
$data['base'] = $this->base;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Set individual head tags
|
|
|
|
$data['head_tags'] = $this->head_tags;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Set Server Headers and Doctype
|
|
|
|
$this->_headers($html5);
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
//Output Header
|
2015-06-04 14:30:42 -04:00
|
|
|
$this->append_output($this->load_view('header', $data, TRUE));
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
return $this;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Builds common footer with any additional js
|
|
|
|
*/
|
|
|
|
public function build_footer()
|
|
|
|
{
|
|
|
|
$data = array();
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
$data['foot_js'] = ($this->foot_js != "") ? $this->foot_js : '';
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2015-06-04 14:30:42 -04:00
|
|
|
$this->append_output($this->load_view('footer', $data, TRUE));
|
2012-06-13 13:49:10 -04:00
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Script Tag
|
|
|
|
*
|
|
|
|
* Helper function for making script tags
|
|
|
|
*
|
|
|
|
* @param string $js
|
|
|
|
* @param bool $domain
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function script_tag($js, $domain = TRUE)
|
|
|
|
{
|
|
|
|
$path = CONTENT_DOMAIN;
|
|
|
|
$js_file = "{$path}/js/{$js}.js";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
if ($domain == FALSE)
|
|
|
|
{
|
|
|
|
$js_file = $js;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
$tag = '<script src="' . $js_file . '"></script>';
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
return $tag;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Set Message
|
|
|
|
*
|
|
|
|
* Adds a message to the page
|
|
|
|
* @param string $type
|
|
|
|
* @param string $message
|
|
|
|
* @param bool $return
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function set_message($type, $message, $return=FALSE)
|
|
|
|
{
|
|
|
|
$data['stat_class'] = $type;
|
|
|
|
$data['message'] = $message;
|
2012-06-14 16:33:16 -04:00
|
|
|
|
|
|
|
return $this->load_view('message', $data, $return);
|
2012-06-13 13:49:10 -04:00
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Redirect 303
|
|
|
|
*
|
|
|
|
* Shortcut function for 303 redirect
|
|
|
|
* @param string $url
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
public function redirect_303($url)
|
2012-06-13 13:49:10 -04:00
|
|
|
{
|
|
|
|
$this->set_header("HTTP/1.1 303 See Other");
|
|
|
|
$this->set_header("Location:" . $url);
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Render
|
|
|
|
*
|
|
|
|
* Shortcut function for building a page
|
|
|
|
* @param string $view
|
|
|
|
* @param array $data
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
public function render($view, $data=array())
|
2012-06-13 13:49:10 -04:00
|
|
|
{
|
|
|
|
$this->build_header();
|
2012-06-14 16:33:16 -04:00
|
|
|
$this->load_view($view, $data);
|
2015-06-04 14:30:42 -04:00
|
|
|
$this->set_foot_js_group('js');
|
2012-06-13 13:49:10 -04:00
|
|
|
$this->build_footer();
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
/**
|
|
|
|
* Output String
|
|
|
|
*
|
|
|
|
* Similar to render(), this is a shortcut
|
2012-06-14 16:33:16 -04:00
|
|
|
* to output a string in the body of the
|
2012-06-13 13:49:10 -04:00
|
|
|
* page.
|
|
|
|
* @param string $string
|
|
|
|
*/
|
2012-06-14 16:33:16 -04:00
|
|
|
public function output_string($string)
|
2012-06-13 13:49:10 -04:00
|
|
|
{
|
|
|
|
$this->build_header();
|
|
|
|
$this->append_output($string);
|
|
|
|
$this->build_footer();
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private helper function to generate meta tags
|
|
|
|
*
|
|
|
|
* @param array $params
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function _meta($params)
|
|
|
|
{
|
|
|
|
$string = "<meta ";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
foreach ($params as $k => &$v)
|
|
|
|
{
|
|
|
|
$string .= $k.'="'.$v.'" ';
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
$string .= " />";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
return $string;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private helper function to generate link tags
|
|
|
|
*
|
|
|
|
* @param array $params
|
|
|
|
* @return string
|
2012-06-14 16:33:16 -04:00
|
|
|
*/
|
2012-06-13 13:49:10 -04:00
|
|
|
private function _link_tag($params)
|
|
|
|
{
|
|
|
|
$string = "<link ";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
foreach ($params as $k => &$v)
|
|
|
|
{
|
|
|
|
$string .= $k . '="'.$v.'" ';
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
$string .= "/>";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
2012-06-13 13:49:10 -04:00
|
|
|
return $string;
|
|
|
|
}
|
2012-06-14 16:33:16 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function for loading a view
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @param array $data
|
|
|
|
* @param bool $return
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function load_view($file, array $data=array(), $return=FALSE)
|
|
|
|
{
|
2015-06-04 15:46:30 -04:00
|
|
|
$path = MM_APP_PATH . "views/{$file}.php";
|
2012-06-14 16:33:16 -04:00
|
|
|
|
|
|
|
// Contain the content for buffering
|
|
|
|
ob_start();
|
|
|
|
|
|
|
|
// Extract the data array
|
|
|
|
extract($data);
|
|
|
|
|
|
|
|
// Include the file
|
|
|
|
include($path);
|
|
|
|
|
|
|
|
$buffer = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
|
|
|
|
if ($return == TRUE)
|
|
|
|
{
|
|
|
|
return $buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->append_output($buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a header for later output
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @param string $val
|
|
|
|
*/
|
|
|
|
public function set_header($key, $val)
|
|
|
|
{
|
|
|
|
$this->headers[$key] = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds text to the output buffer
|
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
*/
|
|
|
|
public function append_output($string)
|
|
|
|
{
|
|
|
|
$this->buffer .= $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the output buffer
|
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
*/
|
|
|
|
public function set_output($string)
|
|
|
|
{
|
|
|
|
$this->buffer = $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends headers and then removes them
|
|
|
|
*/
|
|
|
|
public function flush_headers()
|
|
|
|
{
|
|
|
|
// Set headers
|
2012-08-09 16:36:27 -04:00
|
|
|
foreach ($this->headers as $key => $val)
|
2012-06-14 16:33:16 -04:00
|
|
|
{
|
|
|
|
if ( ! isset($val))
|
|
|
|
{
|
2012-08-09 16:36:27 -04:00
|
|
|
header($key);
|
2012-06-14 16:33:16 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-09 16:36:27 -04:00
|
|
|
header("{$key}: {$val}");
|
2012-06-14 16:33:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Empty headers
|
|
|
|
$this->headers = array();
|
|
|
|
}
|
2012-06-13 13:49:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// End of page.php
|