This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/core/theme.inc.php

205 lines
5.3 KiB
PHP
Raw Normal View History

<?php
/**
* AgileBill - Open Billing Software
*
* This body of work is free software; you can redistribute it and/or
* modify it under the terms of the Open AgileBill License
* License as published at http://www.agileco.com/agilebill/license1-4.txt
2009-08-03 04:10:16 +00:00
*
* Originally authored by Tony Landis, AgileBill LLC
*
* Recent modifications by Deon George
*
* @author Deon George <deonATleenooksDOTnet>
* @copyright 2009 Deon George
* @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
2009-08-03 04:10:16 +00:00
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
* @subpackage Core
*/
/**
* The main AgileBill CORE Theme Class
*
* @package AgileBill
2009-08-03 04:10:16 +00:00
* @subpackage Core
* @uses CORE_block
*/
2009-08-03 04:10:16 +00:00
class CORE_theme {
public $id;
2009-08-03 04:10:16 +00:00
function __construct() {
global $VAR,$C_debug,$C_translate,$smarty;
# Get the cuurent session theme:
2009-08-03 04:10:16 +00:00
if(defined('SESS_THEME') && file_exists(PATH_THEMES.SESS_THEME.'/template.tpl')) {
if (SESS_THEME == 'default_admin' && SESS_LOGGED != true )
define ('THEME_NAME',DEF_THEME_N);
elseif (defined('ADMIN_FORCE'))
define ('THEME_NAME','default_admin');
elseif (! defined('ADMIN_FORCE') && SESS_THEME != 'default_admin')
define ('THEME_NAME',SESS_THEME);
else
2009-08-03 04:10:16 +00:00
define ('THEME_NAME',DEF_THEME_N);
} elseif(file_exists(PATH_THEMES.DEFAULT_THEME.'/template.tpl')) {
define ('THEME_NAME',DEFAULT_THEME);
} else {
define ('THEME_NAME',DEF_THEME_N);
}
# load the block class
$block = new CORE_block;
2009-08-03 04:10:16 +00:00
# Set smarty vars
if (isset($smarty->template_dir))
unset($smarty->template_dir);
$smarty->use_sub_dirs = false;
$smarty->template_dir = PATH_THEMES.THEME_NAME.'/';
$smarty->compile_dir = PATH_SMARTY.'templates/';
$smarty->config_dir = PATH_SMARTY.'configs/';
$smarty->cache_dir = PATH_SMARTY.'cache/';
$this->caching = false;
$this->compile_check = true;
$smarty->assign('THEME_NAME',THEME_NAME);
# Frame Theme Escape
if (THEME_NAME == 'default_admin') {
if (! empty($VAR['tid']) && empty($VAR['_escape'])) {
# Get URL string to pass to mainFrame
$url = '';
$i = 0;
while (list($key,$val) = each($VAR)) {
if ($key != 'tid') {
if ($i==0)
$url .= '?';
else
$url .= '&';
$url .= sprintf('%s=%s',$key,$val);
$i++;
}
}
2009-08-03 04:10:16 +00:00
$url = preg_replace('/tid=default_admin/','',$url);
$smarty->assign('mainFrameUrl',$url);
$this_template = sprintf('file:%s%s/template.tpl',PATH_THEMES,THEME_NAME);
$smarty->display($this_template);
2009-08-03 04:10:16 +00:00
exit;
2009-08-03 04:10:16 +00:00
}
if (empty($VAR['_escape']))
2009-08-03 04:10:16 +00:00
$block->display('core:top_frame');
2009-08-03 04:10:16 +00:00
# Force or define page set?
if (defined('FORCE_PAGE')) {
$block->display(FORCE_PAGE);
2009-08-03 04:10:16 +00:00
} elseif (@$VAR['_page']) {
$block->display($VAR['_page']);
2009-08-03 04:10:16 +00:00
} else {
$block->display('core:admin');
}
2009-08-03 04:10:16 +00:00
if (empty($VAR['_escape']))
$block->display('core:bottom_frame');
exit();
}
# Standard themes
2009-08-03 04:10:16 +00:00
if (isset($VAR['_escape'])) {
if (isset($VAR['_print'])) {
# Load printer friendly version
$block->display('core:top_frame');
$block->display($VAR['_page']);
$block->display('core:bottom_print');
exit();
2009-08-03 04:10:16 +00:00
} else {
# Check for force page:
if(defined('FORCE_PAGE'))
$block->display(FORCE_PAGE);
else
2009-08-03 04:10:16 +00:00
$block->display($VAR['_page']);
exit();
}
2009-08-03 04:10:16 +00:00
} else {
if (defined('FORCE_PAGE')) {
define('THEME_PAGE',FORCE_PAGE);
} else {
2009-08-03 04:10:16 +00:00
if (isset($VAR['_page']))
define('THEME_PAGE',$VAR['_page']);
else
2009-08-03 04:10:16 +00:00
define('THEME_PAGE','core:main');
}
2009-08-03 04:10:16 +00:00
# Load the block normally
$this_template = sprintf('file:%s%s/template.tpl',PATH_THEMES,THEME_NAME);
$smarty->display($this_template);
}
}
}
2009-08-03 04:10:16 +00:00
class CORE_block {
public function display($block_r) {
global $smarty;
2009-08-03 04:10:16 +00:00
$savedir = '';
# If we are in a module, we need to preserve our template path
if (isset($smarty->_tpl_vars['meth'][0]) && $smarty->_tpl_vars['meth'][0] != 'core')
$savedir = $smarty->template_dir;
@$resource = explode(':',$block_r);
@$module = $resource[0];
2009-08-03 04:10:16 +00:00
@$block = $resource[1];
$displayBlock = false;
if ($module == 'TEMPLATE') {
$smarty->template_dir = PATH_THEMES.THEME_NAME.'/';
$displayBlock = true;
} else {
2009-08-03 04:10:16 +00:00
if (is_file(sprintf('%s%s/blocks/%s/%s.tpl',PATH_THEMES,THEME_NAME,$module,$block))) {
$smarty->template_dir = sprintf('%s%s/blocks/%s/',PATH_THEMES,THEME_NAME,$module);
$displayBlock = true;
} elseif (is_file(sprintf('%s%s/blocks/%s/%s.tpl',PATH_THEMES,DEF_THEME_N,$module,$block))) {
$smarty->template_dir = sprintf('%s%s/blocks/%s/',PATH_THEMES,DEF_THEME_N,$module);
$displayBlock = true;
} elseif (is_file(sprintf('%s%s/blocks/%s/%s.tpl',PATH_THEMES,'default',$module,$block))) {
$smarty->template_dir = sprintf('%s%s/blocks/%s/',PATH_THEMES,'default',$module);
$displayBlock = true;
} else {
$smarty->display(sprintf('file:%s%s/blocks/core/invalid_page.tpl',PATH_THEMES,DEF_THEME_N));
}
}
if ($displayBlock) {
if (! isset($smarty->_tpl_vars['VAR']['_page']) || ! $smarty->_tpl_vars['VAR']['_page'])
$smarty->_tpl_vars['VAR']['_page'] = $block_r;
$smarty->display(sprintf('file:%s%s.tpl',$smarty->template_dir,$block));
}
if ($savedir)
$smarty->template_dir = $savedir;
}
}
2009-08-03 04:10:16 +00:00
?>