2012-10-11 08:00:15 +00:00
|
|
|
<?
|
2013-05-21 08:01:09 +00:00
|
|
|
class View {
|
2012-10-27 08:00:09 +00:00
|
|
|
/**
|
|
|
|
* @var string Path relative to where (P)HTML templates reside
|
|
|
|
*/
|
|
|
|
const IncludePath = './design/views/';
|
|
|
|
|
2012-10-11 08:00:15 +00:00
|
|
|
/**
|
|
|
|
* This function is to include the header file on a page.
|
|
|
|
*
|
|
|
|
* @param $PageTitle the title of the page
|
2013-03-23 08:00:43 +00:00
|
|
|
* @param $JSIncludes is a comma-separated list of JS files to be included on
|
|
|
|
* the page. ONLY PUT THE RELATIVE LOCATION WITHOUT '.js'
|
|
|
|
* example: 'somefile,somedir/somefile'
|
2012-10-11 08:00:15 +00:00
|
|
|
*/
|
2013-08-28 23:08:41 +00:00
|
|
|
public static function show_header($PageTitle = '', $JSIncludes = '', $CSSIncludes = '') {
|
|
|
|
global $Document, $Mobile, $Classes;
|
2012-10-11 08:00:15 +00:00
|
|
|
|
2012-11-18 08:00:19 +00:00
|
|
|
if ($PageTitle != '') {
|
|
|
|
$PageTitle .= ' :: ';
|
|
|
|
}
|
2012-10-11 08:00:15 +00:00
|
|
|
$PageTitle .= SITE_NAME;
|
2012-11-18 08:00:19 +00:00
|
|
|
$PageID = array(
|
|
|
|
$Document, // Document
|
|
|
|
empty($_REQUEST['action']) ? false : $_REQUEST['action'], // Action
|
|
|
|
empty($_REQUEST['type']) ? false : $_REQUEST['type'] // Type
|
|
|
|
);
|
2012-10-11 08:00:15 +00:00
|
|
|
|
2013-08-28 23:08:41 +00:00
|
|
|
if (!is_array(G::$LoggedUser) || empty(G::$LoggedUser['ID'])) {
|
2012-10-11 08:00:15 +00:00
|
|
|
require(SERVER_ROOT.'/design/publicheader.php');
|
|
|
|
} else {
|
|
|
|
require(SERVER_ROOT.'/design/privateheader.php');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is to include the footer file on a page.
|
|
|
|
*
|
|
|
|
* @param $Options an optional array that you can pass information to the
|
|
|
|
* header through as well as setup certain limitations
|
|
|
|
* Here is a list of parameters that work in the $Options array:
|
|
|
|
* ['disclaimer'] = [boolean] (False) Displays the disclaimer in the footer
|
|
|
|
*/
|
2013-09-08 08:00:57 +00:00
|
|
|
public static function show_footer($Options = array()) {
|
2013-10-17 08:00:50 +00:00
|
|
|
global $ScriptStartTime, $SessionID, $UserSessions, $Debug, $Time, $Mobile;
|
2013-08-28 23:08:41 +00:00
|
|
|
if (!is_array(G::$LoggedUser)) {
|
2013-05-21 08:01:09 +00:00
|
|
|
require(SERVER_ROOT.'/design/publicfooter.php');
|
|
|
|
} else {
|
|
|
|
require(SERVER_ROOT.'/design/privatefooter.php');
|
|
|
|
}
|
2012-10-11 08:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a generic function to load a template fromm /design and render it.
|
|
|
|
* The template should be in /design/my_template_name.php, and have a class
|
|
|
|
* in it called MyTemplateNameTemplate (my_template_name transformed to
|
|
|
|
* MixedCase, with the word 'Template' appended).
|
|
|
|
* This class should have a public static function render($Args), where
|
|
|
|
* $Args is an associative array of the template variables.
|
|
|
|
* You should note that by "Template", we mean "php file that outputs stuff".
|
|
|
|
*
|
|
|
|
* This function loads /design/$TemplateName.php, and then calls
|
|
|
|
* render($Args) on the class.
|
|
|
|
*
|
|
|
|
* @param string $TemplateName The name of the template, in underscore_format
|
|
|
|
* @param array $Args the arguments passed to the template.
|
|
|
|
*/
|
2013-09-08 08:00:57 +00:00
|
|
|
public static function render_template($TemplateName, $Args) {
|
2012-10-11 08:00:15 +00:00
|
|
|
static $LoadedTemplates; // Keep track of templates we've already loaded.
|
|
|
|
$ClassName = '';
|
|
|
|
if (isset($LoadedTemplates[$TemplateName])) {
|
|
|
|
$ClassName = $LoadedTemplates[$TemplateName];
|
|
|
|
} else {
|
|
|
|
include(SERVER_ROOT.'/design/' . $TemplateName . '.php');
|
|
|
|
|
|
|
|
// Turn template_name into TemplateName
|
|
|
|
$ClassNameParts = explode('_', $TemplateName);
|
|
|
|
foreach ($ClassNameParts as $Index => $Part) {
|
|
|
|
$ClassNameParts[$Index] = ucfirst($Part);
|
|
|
|
}
|
|
|
|
$ClassName = implode($ClassNameParts). 'Template';
|
|
|
|
$LoadedTemplates[$TemplateName] = $ClassName;
|
|
|
|
}
|
|
|
|
$ClassName::render($Args);
|
|
|
|
}
|
2012-10-27 08:00:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is similar to render_template, but does not require a
|
|
|
|
* template class.
|
|
|
|
*
|
|
|
|
* Instead, this method simply renders a PHP file (PHTML) with the supplied
|
|
|
|
* variables.
|
|
|
|
*
|
|
|
|
* All files must be placed within {self::IncludePath}. Create and organize
|
2013-03-23 08:00:43 +00:00
|
|
|
* new paths and files. (e.g.: /design/views/artist/, design/view/forums/, etc.)
|
2012-10-27 08:00:09 +00:00
|
|
|
*
|
|
|
|
* @static
|
2013-01-23 08:00:38 +00:00
|
|
|
* @param string $TemplateFile A relative path to a PHTML file
|
|
|
|
* @param array $Variables Assoc. array of variables to extract for the template
|
|
|
|
* @param boolean $Buffer enables Output Buffer
|
|
|
|
* @return boolean|string
|
|
|
|
*
|
2012-10-27 08:00:09 +00:00
|
|
|
* @example <pre><?php
|
2013-01-23 08:00:38 +00:00
|
|
|
* // box.phtml
|
|
|
|
* <p id="<?=$id?>">Data</p>
|
2013-02-22 08:00:24 +00:00
|
|
|
*
|
2012-10-27 08:00:09 +00:00
|
|
|
* // The variable $id within box.phtml will be filled by $some_id
|
|
|
|
* View::parse('section/box.phtml', array('id' => $some_id));
|
2013-01-23 08:00:38 +00:00
|
|
|
*
|
|
|
|
* // Parse a template without outputing it
|
|
|
|
* $SavedTemplate = View::parse('sec/tion/eg.php', $DataArray, true);
|
|
|
|
* // later . . .
|
|
|
|
* echo $SavedTemplate; // Output the buffer
|
2012-10-27 08:00:09 +00:00
|
|
|
* </pre>
|
|
|
|
*/
|
2013-09-08 08:00:57 +00:00
|
|
|
public static function parse($TemplateFile, array $Variables = array(), $Buffer = false) {
|
2012-10-27 08:00:09 +00:00
|
|
|
$Template = self::IncludePath . $TemplateFile;
|
|
|
|
if (file_exists($Template)) {
|
|
|
|
extract($Variables);
|
2013-01-23 08:00:38 +00:00
|
|
|
if ($Buffer) {
|
|
|
|
ob_start();
|
|
|
|
include $Template;
|
|
|
|
$Content = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
return $Content;
|
|
|
|
}
|
|
|
|
return include $Template;
|
2012-10-27 08:00:09 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-23 08:00:43 +00:00
|
|
|
}
|