_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance(); $this->_sDesignBoxMenuTmplDefault = 'menu_block_submenu_ver.html'; $this->_sDesignBoxMenuIcon = 'chevron'; $this->_sDesignBoxMenuIconType = 'icon-a'; $this->_sDesignBoxMenuClick = "bx_menu_slide_inline('#{design_box_menu}', this)"; } /** * Prevent cloning the instance */ public function __clone() { if (isset($GLOBALS['bxDolClasses'][get_class($this)])) trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR); } public static function getInstanceWithTemplate($oTemplate) { if(!isset($GLOBALS['bxDolClasses']['BxTemplFunctions'])) $GLOBALS['bxDolClasses']['BxTemplFunctions'] = new BxTemplFunctions($oTemplate); return $GLOBALS['bxDolClasses']['BxTemplFunctions']; } public static function getInstance() { return self::getInstanceWithTemplate(null); } function TemplPageAddComponent($sKey) { switch( $sKey ) { case 'something': return false; // return here additional components default: return false; // if you have not such component, return false! } } function msgBox($sText, $iTimer = 0, $sOnClose = "") { $iId = time() . mt_rand(1, 1000); if($iTimer > 0) BxDolTemplate::getInstance()->addJs(array('jquery.anim.js')); return $this->_oTemplate->parseHtmlByName('messageBox.html', array( 'id' => $iId, 'msgText' => $sText, 'bx_if:timer' => array( 'condition' => $iTimer > 0, 'content' => array( 'id' => $iId, 'time' => 1000 * $iTimer, 'on_close' => $sOnClose, ) ) )); } /** * Get standard popup box with title. * * @param string $sName - unique name * @param string $sTitle - translated title * @param string $sContent - content of the box * @return HTML string */ function popupBox($sName, $sTitle, $sContent, $isHiddenByDefault = false) { $iId = !empty($sName) ? $sName : time(); return $this->_oTemplate->parseHtmlByName('popup_box.html', array( 'id' => $iId, 'wrapper_style' => $isHiddenByDefault ? 'display:none;' : '', 'title' => $sTitle, 'content' => $sContent )); } /** * Get popup box without title. * * @param string $sName - unique name * @param string $sContent - content of the box * @return HTML string */ function transBox($sName, $sContent, $isHiddenByDefault = false, $isPlaceInCenter = false) { return $this->simpleBox($sName, $sContent, $isHiddenByDefault, $isPlaceInCenter, 'popup_trans.html'); } function slideBox($sName, $sContent, $isHiddenByDefault = false) { return $this->simpleBox($sName, $sContent, $isHiddenByDefault, false, 'popup_slide.html'); } function inlineBox($sName, $sContent, $isHiddenByDefault = false) { return $this->simpleBox($sName, $sContent, $isHiddenByDefault, false, 'popup_inline.html'); } protected function simpleBox($sName, $sContent, $isHiddenByDefault, $isPlaceInCenter, $sTemplate) { $iId = !empty($sName) ? $sName : time(); $sContent = $this->_oTemplate->parseHtmlByName($sTemplate, array( 'id' => $iId, 'wrapper_style' => $isHiddenByDefault ? 'display:none;' : '', 'content' => $sContent )); if($isPlaceInCenter) $sContent = '
';
$sPopup .= '';
return $bReturnString ? $sResult . $sPopup : array($sResult, $sPopup);
}
/**
* Display design box with specified title, template, content and menu.
* @param $sTitle - design box title, please note that some templates don't use title.
* @param $sContent - design box content.
* @param $iTemplateNum - number of design box template, use predefined contants only, default is BX_DB_DEF.
* @param $mixedMenu - design box menu, it can be:
* - object: instance of BxTemplMenu class
* - string: menu object identifier
* - array: array of menu links to create menu from
* @param $mixedButtons - design box menu representation, it can be:
* - false: design box menu will be used as horizontal menu (tabs)
* - array: array of menu links to create menu from. If empty array is used and 'design box menu' isn't empty, then 'design box menu' will be added as one of menu items automatically. If non-empty array is used and 'design box menu' isn't empty then it should be added as one of menu items. Use array('menu' => 1) to define menu item for 'design box menu'.
* @return string
*
* @see BX_DB_CONTENT_ONLY
* @see BX_DB_DEF
* @see BX_DB_EMPTY
* @see BX_DB_NO_CAPTION
* @see BX_DB_PADDING_CONTENT_ONLY
* @see BX_DB_PADDING_DEF
* @see BX_DB_PADDING_NO_CAPTION
*/
function designBoxContent ($sTitle, $sContent, $iTemplateNum = BX_DB_DEF, $mixedMenu = false, $mixedButtons = array())
{
return $this->_oTemplate->parseHtmlByName('designbox_' . (int)$iTemplateNum . '.html', array(
'title' => $sTitle,
'designbox_content' => $sContent,
'caption_item' => $this->designBoxMenu($mixedMenu, $mixedButtons),
));
}
function designBoxMenu ($mixedMenu, $mixedButtons = array())
{
$bUseTabs = is_bool($mixedButtons) && $mixedButtons === true;
$sMenu = '';
if(!empty($mixedMenu)) {
if(is_string($mixedMenu)) {
if(($oMenu = BxTemplMenu::getObjectInstance($mixedMenu)) !== false) {
$oMenu->setTemplateById($bUseTabs ? BX_DB_MENU_TEMPLATE_TABS : BX_DB_MENU_TEMPLATE_POPUP);
$sMenu = $oMenu->getCode();
}
else
$sMenu = $mixedMenu;
}
else if(is_array($mixedMenu)) {
if(isset($mixedMenu['template']) && isset($mixedMenu['menu_items']))
$aMenu = $mixedMenu;
else
$aMenu = array('template' => $this->_sDesignBoxMenuTmplDefault, 'menu_items' => $mixedMenu);
if(($oMenu = new BxTemplMenu($aMenu, $this->_oTemplate)) !== false) {
$oMenu->setTemplateById($bUseTabs ? BX_DB_MENU_TEMPLATE_TABS : BX_DB_MENU_TEMPLATE_POPUP);
$sMenu = $oMenu->getCode();
}
else
$sMenu = '';
}
else if(is_object($mixedMenu) && is_a($mixedMenu, 'BxTemplMenu')) {
$mixedMenu->setTemplateById($bUseTabs ? BX_DB_MENU_TEMPLATE_TABS : BX_DB_MENU_TEMPLATE_POPUP);
$sMenu = $mixedMenu->getCode();
}
}
$bMenu = !empty($sMenu);
$sResult = '';
if($bUseTabs && $bMenu)
$sResult = $sMenu;
else if(is_array($mixedButtons)) {
$sPopup = '';
if($bMenu) {
$aButton = array();
if(empty($mixedButtons))
list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu);
//--- For backward compatibility
else if(!empty($mixedButtons['menu']) && is_array($mixedButtons['menu'])) {
list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu, $mixedButtons['menu']);
unset($mixedButtons['menu']);
}
if(!empty($aButton))
$mixedButtons[] = $aButton;
}
foreach($mixedButtons as $aButton) {
if($bMenu && isset($aButton['menu'])) {
if(is_numeric($aButton['menu']) && (int)$aButton['menu'] == 1)
list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu);
else if(is_array($aButton['menu']))
list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu, $aButton['menu']);
if(isset($aButton['menu']))
continue;
}
$aAttrs = array();
if(!empty($aButton['onclick']))
$aAttrs['onclick'] = $aButton['onclick'];
if(!empty($aButton['class']))
$aAttrs['class'] = $aButton['class'];
$bTmplVarsButtonIcon = !empty($aButton['icon']);
$aTmplVarsButtonIcon = !$bTmplVarsButtonIcon ? array() : array(
'icon' => $aButton['icon']
);
$bTmplVarsButtonIconA = !empty($aButton['icon-a']);
$aTmplVarsButtonIconA = !$bTmplVarsButtonIconA ? array() : array(
'icon_a' => $aButton['icon-a']
);
$bTmplVarsButtonTitle = !empty($aButton['title']);
$aTmplVarsButtonTitle = !$bTmplVarsButtonTitle ? array() : array(
'title' => $aButton['title']
);
$sResult .= $this->_oTemplate->parseHtmlByName('designbox_menu_button.html', array(
'attrs' => bx_convert_array2attrs($aAttrs, 'bx-def-margin-sec-left'),
'bx_if:show_icon' => array(
'condition' => $bTmplVarsButtonIcon,
'content' => $aTmplVarsButtonIcon
),
'bx_if:show_icon_a' => array(
'condition' => $bTmplVarsButtonIconA,
'content' => $aTmplVarsButtonIconA
),
'bx_if:show_title' => array(
'condition' => $bTmplVarsButtonTitle,
'content' => $aTmplVarsButtonTitle
)
));
}
$sResult .= $sPopup;
}
if(!empty($sResult))
$sResult = $this->_oTemplate->parseHtmlByName('designbox_menu.html', array(
'content' => $sResult
));
return $sResult;
}
protected function _designBoxMenuId ()
{
return 'bx-menu-db-' . time() . rand(0, PHP_INT_MAX);
}
protected function _designBoxMenuButton ($sMenu, $aParams = array())
{
$sId = $this->_designBoxMenuId();
$aButton = array($this->_sDesignBoxMenuIconType => $this->_sDesignBoxMenuIcon, 'onclick' => $this->_sDesignBoxMenuClick);
if(!empty($aParams)) {
if(!empty($aParams['id']))
$sId = $aParams['id'];
$aButton = array_merge($aButton, $aParams);
}
$aButton['onclick'] = bx_replace_markers($aButton['onclick'], array(
'design_box_menu' => $sId
));
return array($aButton, $this->slideBox($sId, $sMenu, true));
}
/**
* Get logo URL.
* @return string
*/
function getMainLogoUrl()
{
$oDesigns = BxDolDesigns::getInstance();
$iFileId = (int)$oDesigns->getSiteLogo();
if(!$iFileId)
return false;
$aParams = array();
if(($iLogoWidth = (int)$oDesigns->getSiteLogoWidth()) > 0)
$aParams['x'] = $iLogoWidth;
if(($iLogoHeight = (int)$oDesigns->getSiteLogoHeight()) > 0)
$aParams['y'] = $iLogoHeight;
if(!empty($aParams))
$sFileUrl = BX_DOL_URL_ROOT . bx_append_url_params('image_transcoder.php', array_merge(array('o' => 'sys_custom_images', 'h' => $iFileId), $aParams));
else
$sFileUrl = BxDolTranscoder::getObjectInstance('sys_custom_images')->getFileUrl($iFileId);
return !empty($sFileUrl) ? $sFileUrl : false;
}
/**
* Get logo HTML.
* @return string
*/
function getMainLogo($aParams = array())
{
$oDesigns = BxDolDesigns::getInstance();
$sAlt = $oDesigns->getSiteLogoAlt();
if(empty($sAlt))
$sAlt = getParam('site_title');
$sLogo = '' . $sAlt . '';
$sFileUrl = $this->getMainLogoUrl();
if (!empty($sFileUrl)) {
$iLogoWidth = (int)$oDesigns->getSiteLogoWidth();
$sMaxWidth = $iLogoWidth > 0 ? 'max-width:' . round($iLogoWidth/16, 3) . 'rem;' : '';
$iLogoHeight = (int)$oDesigns->getSiteLogoHeight();
$sMaxHeight = $iLogoHeight > 0 ? 'max-height:' . round($iLogoHeight/16, 3) . 'rem;' : '';
$sLogo = '