976 lines
30 KiB
PHP
976 lines
30 KiB
PHP
<?php
|
|
|
|
namespace BRSystems\Core\Library\cView;
|
|
|
|
use BRSystems\Core\App\pubUsers\inc\pubUsersModule;
|
|
use BRSystems\Core\Library\cCore\cCore;
|
|
use BRSystems\Core\Library\cJSON\cJSON;
|
|
use BRSystems\Core\Library\cMinify\cMinify;
|
|
use BRSystems\Core\Library\cSysConsole\cSysConsole;
|
|
use BRSystems\Core\Sys\sysUsersManager\inc\sysUsersManagerController;
|
|
use Twig\Environment;
|
|
use \Twig\TwigFunction;
|
|
use \Twig\Loader\FilesystemLoader;
|
|
|
|
|
|
/**
|
|
* View module
|
|
*
|
|
* @category CMS
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @since Version 1.0
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* PROPERTY DEFINITIONS
|
|
* -------------------------------------------------
|
|
* DASHBOARD DATA PROPERTIES
|
|
* -------------------------------------------------
|
|
* @property mixed FTD
|
|
* @property mixed CONT_TYPE
|
|
* @property int NOW
|
|
* @property mixed QUARTERS
|
|
* @property mixed SEL_QUARTER
|
|
* @property mixed SEL_YEAR
|
|
* @property mixed DASHBOARD_PORTLETS
|
|
* @property mixed DASHBOARD_PORTLETS_2_TPL
|
|
* @property mixed DASHBOARD_PORTLETS_SELECTED
|
|
* @property mixed SYSTEM_NEWS
|
|
* @property bool SYSTEM_NEWS_LOAD_MORE
|
|
* @property bool SYSTEM_LOG
|
|
* @property bool SYSTEM_LOG_LOAD_MORE
|
|
* @property int PAGE
|
|
* @property string TODAY
|
|
* @property string CURRENT_MONTH
|
|
* @property string NAME_DAYS
|
|
* @property string STATUS_DATA
|
|
*
|
|
* -------------------------------------------------
|
|
* VIEW DATA PROPERTIESC
|
|
* -------------------------------------------------
|
|
* @property mixed DIS_NEW_BTN
|
|
* @property mixed DISABLE_TITLE
|
|
* @property mixed SHOW_BTN_LABELS
|
|
* @property mixed CUSTOM_TPL_HEADER_DATA
|
|
* -------------------------------------------------
|
|
* VIEW DATA PROPERTIES
|
|
* -------------------------------------------------
|
|
* @property mixed d
|
|
* @property mixed data
|
|
* @property mixed DATA
|
|
* @property mixed DATE
|
|
* @property mixed CFG
|
|
*
|
|
* -------------------------------------------------
|
|
* USER VIEW DATA PROPERTIES
|
|
* -------------------------------------------------
|
|
* @property mixed U
|
|
* @property mixed SYS_LOGIN
|
|
* @property mixed TODAY_YEAR
|
|
* @property mixed NONE_PAID
|
|
* @property mixed CURRENT_YEAR
|
|
* @property mixed CURRENT_QUARTER
|
|
* @property mixed SUBSCRIPTION_DATA
|
|
* @property mixed DISPLAY_RED_NOTIFICATION
|
|
* @property mixed TRIAL
|
|
* @property mixed TRIAL_EXPIRED
|
|
* @property mixed TRIAL_TILL
|
|
* @property mixed infoData
|
|
* @property mixed NO_HEADER
|
|
* @property mixed GENDER
|
|
* @property mixed USER_ONLY_AUTH
|
|
* @property mixed SESSION_EXPIRED_LOGIN
|
|
* @property mixed SETTINGS_TITLE
|
|
* @property mixed TBL_FIELDS
|
|
* @property mixed PER_PAGE
|
|
* @property mixed URLS2COMPANY
|
|
*
|
|
* -------------------------------------------------
|
|
* PARTNERS DATA PROPERTIES
|
|
* -------------------------------------------------
|
|
* @property mixed P
|
|
* @property mixed bUseNewStructure
|
|
* @property mixed bEdit
|
|
* @property mixed ONLY_BLANK
|
|
* @property mixed EXTERNAL_SECTION
|
|
* @property mixed EXTERNAL_FORM_TITLE
|
|
* @property mixed SLIDER_IFRAME_LOAD
|
|
* @property mixed PUB_FILE_UPLOAD
|
|
* @property mixed TABLE
|
|
* @property mixed SYS
|
|
* @property mixed SYSTEM_GUIDES
|
|
* @property mixed PRE_BODY
|
|
* @property mixed USER_TITLE
|
|
* @property mixed showYears
|
|
* @property mixed DISABLE
|
|
* @property mixed DISABLED
|
|
* @property mixed TPASSWD
|
|
* @property mixed PROP_CLASSES
|
|
* @property mixed SUB
|
|
* @property mixed USER
|
|
* @property mixed CFG_INP
|
|
* @property array LINKS
|
|
* @property boolean PROFILE
|
|
* @property mixed GOOGLE_AUTH
|
|
* @property boolean HIDE_CLOSE
|
|
* @property boolean PW_CHANGE
|
|
* @property boolean FULL_HEADER_LINE
|
|
* @property boolean DISABLE_HEADER_TYPES
|
|
* @property boolean ASSOC_AP
|
|
* @property string DEADLINE
|
|
* @property array PRIORITIES
|
|
* @property array LANGUAGES
|
|
* @property array userCompanies
|
|
* @property mixed TWO_FA_SECRET
|
|
* @property mixed TWO_FA_SECRET_QR
|
|
* @property boolean HIDE_SEARCH
|
|
* @property mixed SHOW_PERSONAL_ON_LOAD
|
|
* @property mixed PERSONALTYPES
|
|
* @property mixed COUNTRYCODES
|
|
* @property mixed ADDRESSES
|
|
* @property mixed SETTINGS
|
|
* @property mixed DEBCRED
|
|
* @property mixed BANK
|
|
* @property mixed REQ
|
|
* @property mixed TRANSACTIONS
|
|
* @property mixed INST_SECTOR
|
|
* @property mixed TYPES_TO_SHOW
|
|
* @property mixed TYPES_TO_SHOW_2
|
|
* @property mixed COMP_STARTING_YEAR
|
|
* @property mixed DISABLE_CHANGE_CP_START_YEAR
|
|
* @property mixed YEARS
|
|
* @property mixed PARTNERS
|
|
* @property mixed AP_METERS
|
|
* @property mixed PROJECTS
|
|
* @property mixed STATUS
|
|
* @property mixed VAT_PAYER_STATUS
|
|
* @property mixed TAX_STATUS
|
|
* @property mixed BODY
|
|
* @property array TBL_SORT
|
|
*
|
|
* -------------------------------------------------
|
|
* OBJECT DATA PROPERTIES
|
|
* -------------------------------------------------
|
|
* @property array SUB_TITLE
|
|
* @property array BILL_TYPES
|
|
* @property array METER_UNITS_M
|
|
* @property array METER_TYPES
|
|
* @property array MEASUREMENT_TYPES
|
|
* @property array CHANGE_NEXT_VER
|
|
* @property array TYPES
|
|
* @property array RP
|
|
* @property array TYPES_OF_FOUNDS
|
|
* @property array bType
|
|
* @property array CODES
|
|
* @property array ROWS
|
|
* @property array LIST_BTN
|
|
* @property array MODULE_TITLE
|
|
* @property array TABLE_LEGEND
|
|
* @property array DISABLED_NAVIGATING_ELEMENTS
|
|
* @property array PRESERVE_BUTTONS
|
|
* @property array DEFAULT_SEARCH_VALUES
|
|
* @property array LIST_HEADER
|
|
* @property array DATA_TABLE_NAME
|
|
* @property array LIST_HEADER_SORTABLE
|
|
* @property array LIST_DATA
|
|
* @property array LIST_ACTIONS
|
|
* @property bool DISABLE_SEARCH_HIDE
|
|
* @property bool JOURNAL_BASED_ACCOUNT
|
|
*
|
|
* -------------------------------------------------
|
|
* OUTGOING MAIL CONTROLLER VIEW PROPERTIES
|
|
* -------------------------------------------------
|
|
* @property mixed vLangs
|
|
* @property mixed vMailTypes
|
|
* @property bool readonly
|
|
* @property int iDefaultLang
|
|
*
|
|
* -------------------------------------------------
|
|
* OTHER CONTROLLER VIEW PROPERTIES
|
|
* -------------------------------------------------
|
|
* @property int OBJECTS
|
|
* @property mixed SECTORS
|
|
* @property mixed SECTOR_TYPES
|
|
* @property mixed USERS
|
|
* @property mixed ERROR_MESSAGE
|
|
* @property mixed ASSIGNMENTS
|
|
* @property mixed BUGS
|
|
* @property mixed BUG_FINISHED
|
|
* @property mixed vCFG
|
|
* @property mixed JOURNAL_COLUMNS
|
|
* @property mixed TABLE_BOTTOM_ADDITIONAL_DATA
|
|
*
|
|
* -------------------------------------------------
|
|
* ACCOUNTING VIEW PROPERTIES
|
|
* -------------------------------------------------
|
|
* @property mixed TABLE_ROWS_CONTAINER
|
|
* @property mixed DEPRECIATION
|
|
* @property mixed MEASUREMENT
|
|
* @property mixed DISABLE_DATES
|
|
* @property mixed ADDITIONAL_STATUS_MSG
|
|
* @property mixed R_ID
|
|
* @property mixed COLUMNS
|
|
* @property mixed CODE
|
|
* @property mixed ASSETS
|
|
* @property mixed PVN
|
|
* @property mixed DIVISIONS
|
|
* @property mixed TRANSPORTS
|
|
* @property mixed REGTYPE
|
|
* @property mixed VAT_PAYER
|
|
*
|
|
*
|
|
* -------------------------------------------------
|
|
* DOCUMENT VIEW PROPERTIES
|
|
* -------------------------------------------------
|
|
* @property mixed APARTMENTS
|
|
*
|
|
*
|
|
* -------------------------------------------------
|
|
* DOCUMENT VIEW PROPERTIES
|
|
* -------------------------------------------------
|
|
* @property mixed LAYOUT
|
|
* @property mixed BILL_CORRECTION
|
|
* @property mixed SHOW_FINAL_AMOUNT
|
|
* @property mixed SHOW_ADVANCED_PAYMENTS
|
|
* @property mixed SHOW_DEBT_OVERPAY
|
|
* @property mixed DEBT_OVERPAY
|
|
* @property array ADVANCED_PAYMENTS
|
|
* @property mixed NO_PAIMENT
|
|
* @property mixed LOCK_STATUS
|
|
* @property mixed DATA_NOT_SAVED
|
|
* @property mixed REGISTER_TYPES
|
|
* @property mixed PAID_STATUS
|
|
* @property mixed LINK
|
|
* @property mixed DATA_ROW_EXISTS_CUSTOM_MSG
|
|
* @property mixed DATA_ROW_EXISTS
|
|
* @property mixed LOGO
|
|
* @property mixed VAT
|
|
* @property mixed TABLE_FIELDS
|
|
* @property mixed SHOW_SUBTOTAL
|
|
* @property mixed SHOW_SIG_FOR_SUP
|
|
* @property mixed SHOW_SIG_FOR_BEN
|
|
* @property mixed CONTENT
|
|
* @property mixed PERSONAL
|
|
* @property mixed PREFIX
|
|
* @property mixed DOC_TYPES
|
|
* @property mixed DOC_SETTINGS
|
|
* @property mixed REQUISITES
|
|
* @property mixed ADDRESS
|
|
* @property mixed TABLE_DATA
|
|
* @property mixed TOTAL_MILEAGE
|
|
* @property mixed CONFIRM_STATUS
|
|
* @property mixed CONFIRM_SETTINGS
|
|
* @property mixed REQUISITES_DATA
|
|
* @property mixed REQUISITES_ADDRESSES
|
|
* @property mixed REQUISITES_PERSONAL
|
|
* @property mixed DRIVERS
|
|
* @property mixed ROWS_FILLED
|
|
* @property mixed TABLE_SUMMARY
|
|
* @property mixed ADDITIONAL_PDF_CSS_FILE
|
|
* @property string DOCUMENT_TPL
|
|
* @property string DOCUMENT_VIEW_TPL
|
|
* @property string DOC_MESSAGES
|
|
* @property string SIGNATURE_DATE_1
|
|
* @property string SIGNATURE_DATE_2
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
class cView
|
|
{
|
|
private $oTwig;
|
|
private $oLoader;
|
|
private $cConsole;
|
|
private $cCoreModule;
|
|
|
|
|
|
public $sTplDirCore;
|
|
public $sTplDirHelpers;
|
|
public $sTplDirLayouts;
|
|
|
|
private $_js = [];
|
|
private $_css = [];
|
|
private $_cache = [];
|
|
private $_params = [];
|
|
private $_json_params = [];
|
|
|
|
private $_fileVersion = 524;
|
|
private $_sContentVarKey = 'CONTENT';
|
|
private $_tplExt = array('twig', 'tpl', 'html', 'htm');
|
|
|
|
public $bIsCms = false;
|
|
public $bIsNew = false;
|
|
public $bPubIsSys = true;
|
|
|
|
|
|
public $template_cfg = [];
|
|
|
|
/**
|
|
* Class constructor
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param cCore|bool|object $cCoreInst
|
|
*/
|
|
public function __construct(&$cCoreInst = false)
|
|
{
|
|
// Define default values
|
|
if (!defined('DEBUG_MODE')) define('DEBUG_MODE', false);
|
|
if (!defined('CUSTOM_SESSION_LIFE')) define('CUSTOM_SESSION_LIFE', 60 * 60 * 24);
|
|
if (!defined('CMS_VERSION')) define('CMS_VERSION', 'X');
|
|
if (!defined('COMPOSER_DIR')) define('COMPOSER_DIR', '/vendor/autoload.php');
|
|
|
|
if (!defined('SYS_LOGIN_MAP_ID')) define('SYS_LOGIN_MAP_ID', 0);
|
|
if (!defined('PUB_LOGIN_MAP_ID')) define('PUB_LOGIN_MAP_ID', 0);
|
|
|
|
// Setup dir path
|
|
$sDir = __DIR__ ? __DIR__ : dirname(__FILE__);
|
|
|
|
// Setup console output object - singleton
|
|
$this->cConsole = cSysConsole::getInstance();
|
|
|
|
// Setup directories
|
|
$this->sTplDirCore = "{$sDir}/tpl/core/";
|
|
$this->sTplDirHelpers = "{$sDir}/tpl/helpers/";
|
|
$this->sTplDirLayouts = "{$sDir}/tpl/layouts/";
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Twig engine
|
|
// ----------------------------------------------------------------------
|
|
// Set loader directories & setup TWIG
|
|
$this->oLoader = new FilesystemLoader(
|
|
[$this->sTplDirCore, $this->sTplDirHelpers, $this->sTplDirLayouts, __IMG__]
|
|
);
|
|
$this->oTwig = new Environment($this->oLoader, [
|
|
'cache' => (DEBUG_MODE ? false : __CACHE__)
|
|
]);
|
|
|
|
// Append custom TWIG functions
|
|
$oFunction = new TwigFunction('callFunction', function ($sFnTitle, $vFnData) {
|
|
return $this->checkAndCallUserFunction($sFnTitle, $vFnData);
|
|
});
|
|
$this->oTwig->addFunction($oFunction);
|
|
$oFunction = new TwigFunction('prepForDisplayHtml', function ($data) {
|
|
return prepForDisplayHtml($data);
|
|
});
|
|
$this->oTwig->addFunction($oFunction);
|
|
$oFunction = new TwigFunction('prepForOriginalHtml', function ($data) {
|
|
return prepForOriginalHtml($data);
|
|
});
|
|
$this->oTwig->addFunction($oFunction);
|
|
$this->oTwig->addGlobal('cookies', $_COOKIE);
|
|
|
|
// ----------------------------------------------------------------------
|
|
// End Twig engine
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
// Set core class instance
|
|
$this->cCoreModule = $cCoreInst;
|
|
}
|
|
|
|
/**
|
|
* Function to set variables to view
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param string $index
|
|
* @param mixed $value
|
|
* @return void
|
|
*/
|
|
public function __set($index, $value)
|
|
{
|
|
if ($index) {
|
|
$this->_params[$index] = $value;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Function to set variables to view
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param mixed $index
|
|
* @return mixed
|
|
*/
|
|
public function __get($index)
|
|
{
|
|
if (isset($this->_params[$index])) {
|
|
return $this->_params[$index];
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to get all variables set to view
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @return mixed
|
|
*/
|
|
public function getAllSetParams()
|
|
{
|
|
if (!!$this->_params) {
|
|
return $this->_params;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to load js file
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param string $file_path - name to file
|
|
* @param bool $cache - cache file name
|
|
* @param array $vExcludeFiles - exclude files in cache mechanism
|
|
* @return bool true
|
|
*/
|
|
public function setJs(
|
|
$file_path,
|
|
$cache = false,
|
|
$vExcludeFiles = [
|
|
'tinymce.min.js',
|
|
'jquery.tinymce.min.js',
|
|
'jquery.fileupload.js',
|
|
'jquery.iframe-transport.js',
|
|
]
|
|
) {
|
|
$file = preg_replace('/\/+/', '/', (($cache ? __CACHE__ : __MDIR__) . $file_path));
|
|
if (file_exists($file) && filesize($file)) {
|
|
if ($cache) {
|
|
$this->_js = [];
|
|
$this->_cache[] = $file_path;
|
|
} else {
|
|
$sBaseName = basename($file_path);
|
|
if (
|
|
!DEBUG_MODE
|
|
&& !empty($this->cCoreModule->uri_data['p_autocache'])
|
|
&& !in_array($sBaseName, $vExcludeFiles)
|
|
) {
|
|
// Check if file is cached - create cache & create copy in cache
|
|
if (!file_exists(__CACHE__ . $sBaseName)) {
|
|
if (!strpos('--' . $sBaseName, '.min.')) {
|
|
$oMin = new cMinify();
|
|
if (!$oMin->minifyCssOrJsFileV2($file, cMinify::FILE_TYPE_JS, true))
|
|
return false;
|
|
} else {
|
|
// Save minified file to cache folder
|
|
copy($file, __CACHE__ . $sBaseName);
|
|
}
|
|
}
|
|
$this->_js[] = __RCACHE__ . $sBaseName;
|
|
} else
|
|
$this->_js[] = $file_path;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to load css file
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param string $file_path - name to file
|
|
* @param bool $cache - cache file name
|
|
* @return bool true
|
|
*/
|
|
public function setCss($file_path, $cache = false)
|
|
{
|
|
$file = preg_replace('/\/+/', '/', (($cache ? __CACHE__ : __MDIR__) . $file_path));
|
|
if (file_exists($file) && filesize($file)) {
|
|
if ($cache) {
|
|
$this->_css = [];
|
|
$this->_cache[] = $file_path;
|
|
} else {
|
|
if (!DEBUG_MODE && !empty($this->cCoreModule->uri_data['p_autocache'])) {
|
|
// Check if file is cached - create cache & create copy in cache
|
|
if (!file_exists(__CACHE__ . basename($file_path))) {
|
|
if (!strpos('--' . basename($file_path), '.min.')) {
|
|
$oMin = new cMinify();
|
|
if (!$oMin->minifyCssOrJsFileV2($file, cMinify::FILE_TYPE_CSS, true))
|
|
return false;
|
|
} else {
|
|
// Save minified file to cache folder
|
|
copy($file, __CACHE__ . basename($file_path));
|
|
}
|
|
}
|
|
$this->_css[] = __RCACHE__ . basename($file_path);
|
|
} else
|
|
$this->_css[] = $file_path;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Function to drop css & js modules
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @return void
|
|
*/
|
|
public function dropCssJs()
|
|
{
|
|
$this->_js = [];
|
|
$this->_css = [];
|
|
$this->_cache = [];
|
|
}
|
|
|
|
/**
|
|
* Helper function to set smarty directory
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param string $dir_path - name to folder
|
|
* @return bool true
|
|
*/
|
|
public function setTemplateDir($dir_path)
|
|
{
|
|
// Add & set loader additional path for Twig
|
|
$this->oLoader->prependPath("{$dir_path}");
|
|
$this->oTwig->setLoader($this->oLoader);
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Function to set variables for JSON encode & js decode
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param string $index
|
|
* @param mixed $value
|
|
* @return void
|
|
*/
|
|
public function setAsJSON($index, $value)
|
|
{
|
|
if ($index) $this->_json_params[$index] = cJSON::encode($value, true);
|
|
}
|
|
|
|
/**
|
|
* Helper function to display template
|
|
*
|
|
* @param bool|string $sTplName - name to template
|
|
* @param bool|string $sSetToVar - set to named variable
|
|
* @param bool $bDirectDisplay - display as base tpl
|
|
* @return void - prints template data
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
*/
|
|
public function display($sTplName = false, $sSetToVar = false, $bDirectDisplay = false)
|
|
{
|
|
// Set variables to view
|
|
$this->setViewVariables();
|
|
|
|
// Check template exists
|
|
if (
|
|
!$bDirectDisplay
|
|
&& isset($this->cCoreModule->uri_data['mod_use_tmpl'])
|
|
&& $this->cCoreModule->uri_data['mod_use_tmpl']
|
|
) {
|
|
// Check and add file extension
|
|
$this->chkTplExt($sTplName);
|
|
$this->chkTplExt($this->cCoreModule->uri_data['mod_use_tmpl']);
|
|
|
|
// Lookup template
|
|
if (!$this->oLoader->exists($this->cCoreModule->uri_data['mod_use_tmpl'])) {
|
|
die($this->cCoreModule->gM('Main Template not found!'));
|
|
}
|
|
|
|
if ($sSetToVar) {
|
|
if ($this->oLoader->exists($sTplName)) {
|
|
$this->_params[$sSetToVar] = $this->renderViewTemplate($sTplName);
|
|
} else {
|
|
$this->_params[$sSetToVar] = $this->cCoreModule->gM('Template not found!');
|
|
}
|
|
}
|
|
|
|
// Set to template body
|
|
$this->_params[$this->_sContentVarKey] = $this->renderViewTemplate(
|
|
$this->cCoreModule->uri_data['mod_use_tmpl']
|
|
);
|
|
} else {
|
|
// Set to template body
|
|
$this->chkTplExt($sTplName);
|
|
if (!$this->oLoader->exists($sTplName)) {
|
|
die($this->cCoreModule->gM('Main Template not found!'));
|
|
}
|
|
$this->_params[$this->_sContentVarKey] = $this->renderViewTemplate($sTplName);
|
|
}
|
|
|
|
// Use cache
|
|
if (!!$this->_cache) {
|
|
foreach ($this->_cache as $v) {
|
|
switch (getExtension($v)) {
|
|
case 'js':
|
|
array_unshift($this->_js, $v);
|
|
break;
|
|
case 'css':
|
|
array_unshift($this->_css, $v);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Setup user theme
|
|
if (!!$this->cCoreModule) {
|
|
|
|
$vThemes = false;
|
|
$sUserThemeTitle = '';
|
|
|
|
if ($this->cCoreModule->is_cms) {
|
|
$vThemes = sysUsersManagerController::$CMS_FORM_THEMES;
|
|
}
|
|
// Get user selected theme - if logged in
|
|
if (!!$this->cCoreModule->oUser && !!$this->cCoreModule->oUser->oCfg) {
|
|
$sUserThemeTitle = $this->cCoreModule->oUser->oCfg->getValueProperty('sThemetitle');
|
|
}
|
|
|
|
// Set default theme
|
|
if (!!$vThemes) {
|
|
if (!isset($vThemes[$sUserThemeTitle])) {
|
|
foreach ($vThemes as $k => $v) {
|
|
if (!empty($v['default'])) {
|
|
$sUserThemeTitle = $k;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add theme
|
|
$this->setCss($vThemes[$sUserThemeTitle]['f']);
|
|
}
|
|
}
|
|
|
|
// Display template
|
|
$this->chkAndGenConsoleDataTpl();
|
|
|
|
// Set js versions
|
|
if (!!$this->_js) {
|
|
foreach ($this->_js as &$v) {
|
|
$v .= "?v={$this->_fileVersion}";
|
|
}
|
|
}
|
|
|
|
// Set css versions
|
|
if (!!$this->_css) {
|
|
foreach ($this->_css as &$v) {
|
|
$v .= "?v={$this->_fileVersion}";
|
|
}
|
|
}
|
|
|
|
|
|
// Setup css & js arrays
|
|
$this->_params['JS'] = str_replace('\\', '/', $this->_js);
|
|
$this->_params['CSS'] = str_replace('\\', '/', $this->_css);
|
|
|
|
// Setup main details of page
|
|
$this->_params['MAP'] = $this->cCoreModule->uri_data;
|
|
|
|
// Switch base template
|
|
$templateToRender = 'body.twig';
|
|
if ($this->bIsCms) {
|
|
$templateToRender = ($this->bIsNew ? 'cms-html-n.twig' : 'cms-body.twig');
|
|
}
|
|
|
|
// Render final template
|
|
echo $this->renderViewTemplate($templateToRender);
|
|
}
|
|
|
|
/**
|
|
* Helper function to get generated template
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param string $sTplName - template name
|
|
* @return string - template data
|
|
*/
|
|
public function genTemplate($sTplName)
|
|
{
|
|
// Set variables
|
|
$this->setViewVariables();
|
|
|
|
// Validate extension
|
|
$this->chkTplExt($sTplName);
|
|
|
|
// Get console template data
|
|
$sConsole = $this->chkAndGenConsoleDataTpl(true);
|
|
|
|
// Return template data
|
|
if ($this->oLoader->exists($sTplName)) {
|
|
return $this->renderViewTemplate($sTplName) . $sConsole;
|
|
} else {
|
|
return $this->cCoreModule->gM('Template not found!');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Function to generate console template with data if DEBUG_MODE enabled
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param bool $bAddInitScript - add initialize script
|
|
* @return string - template data
|
|
*/
|
|
private function chkAndGenConsoleDataTpl($bAddInitScript = false)
|
|
{
|
|
// If debug, setup console data
|
|
if (DEBUG_MODE && $this->cCoreModule->cTimer) {
|
|
|
|
// Stop base timer
|
|
$this->cCoreModule->cTimer->stop();
|
|
|
|
// Set console data
|
|
$this->_params['CONSOLE_SCRIPT'] = $bAddInitScript;
|
|
$this->_params['CONSOLE_DATA'] = $this->cConsole->getLineData();
|
|
|
|
// Return tpl data only on posts - otherwise data included in core tpl
|
|
if ($bAddInitScript) {
|
|
if (file_exists("{$this->sTplDirHelpers}console/console.tpl")) {
|
|
return $this->renderViewTemplate('console/console.tpl');
|
|
}
|
|
} else {
|
|
$this->setJs('/js/brs.console.js');
|
|
$this->setCss('/css/cms-debug-console.css');
|
|
}
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* Helper function to check template extension type and add if necessary
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param string $tplName - name of template
|
|
* @return void
|
|
*/
|
|
public function chkTplExt(&$tplName)
|
|
{
|
|
$ext = getFileExtension($tplName);
|
|
|
|
if ($ext) {
|
|
if (!in_array($ext, $this->_tplExt)) {
|
|
$tplName = substr($tplName, 0, strlen($tplName) - strlen($ext)) . $this->_tplExt[0];
|
|
}
|
|
} else {
|
|
$tplName .= '.' . $this->_tplExt[0];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Helper function to generate template bases on different engine
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param string $sTplName - name of template
|
|
* @return string
|
|
*/
|
|
private function renderViewTemplate($sTplName)
|
|
{
|
|
// Twig case
|
|
$oTemplate = $this->oTwig->load($sTplName);
|
|
$htmlData = $oTemplate->render($this->_params);
|
|
|
|
return $htmlData;
|
|
}
|
|
|
|
/**
|
|
* Helper function to get generated helper view template
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @param string $sTplName - name to helper view
|
|
* @return string - template name
|
|
*/
|
|
public function genHelperView($sTplName)
|
|
{
|
|
// Set variables
|
|
$this->setViewVariables();
|
|
|
|
// Validate extension
|
|
$this->chkTplExt($sTplName);
|
|
|
|
// Get console template data
|
|
$sConsole = $this->chkAndGenConsoleDataTpl(true);
|
|
|
|
// Return template data
|
|
|
|
if ($this->oLoader->exists($sTplName)) {
|
|
return $this->renderViewTemplate($sTplName) . $sConsole;
|
|
} else {
|
|
return $this->cCoreModule->gM('Template not found!');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Function to set view variables
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @return void
|
|
*/
|
|
private function setViewVariables()
|
|
{
|
|
// Directory configuration
|
|
$this->_params['DIR'] = [
|
|
'js' => __JS__,
|
|
'css' => __CSS__,
|
|
'img' => __IMG__,
|
|
'upd' => __FILES__,
|
|
'lib' => __LIB__,
|
|
'thelper' => $this->sTplDirHelpers
|
|
];
|
|
|
|
// Set session life
|
|
$this->_json_params['sessionTime'] = cJSON::encode(CUSTOM_SESSION_LIFE, true);
|
|
|
|
$cartData = [];
|
|
$cartCounter = 0;
|
|
if (!empty($_SESSION['cart']['data']) && is_array($_SESSION['cart']['data'])) {
|
|
$cartData = $_SESSION['cart']['data'];
|
|
|
|
if (isset($cartData['total']) && is_numeric($cartData['total'])) {
|
|
$cartCounter = (int)$cartData['total'];
|
|
} elseif (!empty($cartData['cat']) && is_array($cartData['cat'])) {
|
|
foreach ($cartData['cat'] as $products) {
|
|
if (empty($products) || !is_array($products)) {
|
|
continue;
|
|
}
|
|
foreach ($products as $item) {
|
|
if (!empty($item['count'])) {
|
|
$cartCounter += (int)$item['count'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!isset($cartData['subtotal']) || !is_numeric($cartData['subtotal'])) {
|
|
$cartSubtotal = 0;
|
|
if (!empty($cartData['cat']) && is_array($cartData['cat'])) {
|
|
foreach ($cartData['cat'] as $products) {
|
|
if (empty($products) || !is_array($products)) {
|
|
continue;
|
|
}
|
|
foreach ($products as $item) {
|
|
if (!empty($item['count']) && isset($item['p'])) {
|
|
$cartSubtotal += ((float)$item['count'] * (float)$item['p']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$cartData['subtotal'] = $cartSubtotal;
|
|
}
|
|
|
|
$cartData['total'] = $cartCounter;
|
|
}
|
|
|
|
$this->_params['cart'] = $cartData;
|
|
$this->_params['cart_counter'] = $cartCounter;
|
|
|
|
// Set wishlist counter for logged in public user
|
|
$wishlistCounter = 0;
|
|
if (!$this->bIsCms && !empty($_SESSION['pub-user']['id'])) {
|
|
$userId = (int)$_SESSION['pub-user']['id'];
|
|
if ($userId > 0 && class_exists(pubUsersModule::class)) {
|
|
$wishlistModule = new pubUsersModule();
|
|
$wishlistCounter = $wishlistModule->getWishlistCount($userId);
|
|
}
|
|
}
|
|
$this->_params['wishlist_counter'] = $wishlistCounter;
|
|
|
|
if (!$this->bIsCms && defined('PUB_LOGIN_MAP_ID')) {
|
|
$this->setAsJSON('cartLink', $this->cCoreModule->gL(896));
|
|
$this->setAsJSON('profileLink', $this->cCoreModule->gL(905));
|
|
}
|
|
|
|
// Set session expired login request link
|
|
if ($this->bIsCms) {
|
|
if (defined('SYS_LOGIN_MAP_ID')) {
|
|
$sRequestUrl = $this->cCoreModule->gL(SYS_LOGIN_MAP_ID, 'action:loginf');
|
|
$this->_json_params['sessionLoginLink'] = cJSON::encode($sRequestUrl, true);
|
|
}
|
|
} elseif (defined('PUB_LOGIN_MAP_ID')) {
|
|
if (!empty($this->cCoreModule->selCompId) && $this->cCoreModule->selCompId > 0) {
|
|
$sRequestUrl = $this->cCoreModule->gL(
|
|
PUB_LOGIN_MAP_ID,
|
|
'action:loginf/cp:' . urlencode(
|
|
$this->cCoreModule->oDefuseCrypt->encrypt($this->cCoreModule->selCompId)
|
|
)
|
|
);
|
|
$this->_json_params['sessionLoginLink'] = cJSON::encode($sRequestUrl, true);
|
|
}
|
|
}
|
|
|
|
// Set json encode variables for auto decode in base class
|
|
if (isset($this->_json_params)) {
|
|
$this->_params['JSON_PARAMS'] = $this->_json_params;
|
|
}
|
|
|
|
// Load module for templates
|
|
$this->_params['dt'] = &$this->cCoreModule;
|
|
|
|
// Set constants
|
|
$this->_params['CMS_VERSION'] = CMS_VERSION;
|
|
}
|
|
|
|
/**
|
|
* Function to get template names in array
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @return array of available templates
|
|
*/
|
|
public function getTemplates()
|
|
{
|
|
$templates = [];
|
|
$bannedTemplates = [
|
|
''
|
|
];
|
|
|
|
foreach (scandir($this->sTplDirLayouts) as $v) {
|
|
if (!in_array(strtolower($v), $bannedTemplates)) {
|
|
if (!is_dir($this->sTplDirCore . $v)) {
|
|
$templates[] = substr($v, 0, strrpos($v, '.'));
|
|
}
|
|
}
|
|
}
|
|
|
|
return $templates;
|
|
}
|
|
|
|
/**
|
|
* Function to get indicator whether cache is used
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @return bool true / false
|
|
*/
|
|
public function cacheUsed(): bool
|
|
{
|
|
return !!$this->_cache;
|
|
}
|
|
|
|
/**
|
|
* Function to call user custom function from TWIG
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category View
|
|
* @return bool true / false
|
|
*/
|
|
public function checkAndCallUserFunction($sFnTitle, $vFnData)
|
|
{
|
|
if (is_callable($sFnTitle)) {
|
|
return call_user_func_array($sFnTitle, $vFnData);
|
|
}
|
|
return false;
|
|
}
|
|
}
|