_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance(); } /** * 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 getInstance() { if(!isset($GLOBALS['bxDolClasses']['BxTemplFunctions'])) $GLOBALS['bxDolClasses']['BxTemplFunctions'] = new BxTemplFunctions(); return $GLOBALS['bxDolClasses']['BxTemplFunctions']; } 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); 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 = '
' . $sContent . '
'; return $sContent; } function getTemplateIcon($sName) { $sUrl = $this->_oTemplate->getIconUrl($sName); return !empty($sUrl) ? $sUrl : $this->_oTemplate->getIconUrl('spacer.gif'); } function getTemplateImage($sName) { $sUrl = $this->_oTemplate->getImageUrl($sName); return !empty($sUrl) ? $sUrl : $this->_oTemplate->getImageUrl('spacer.gif'); } function sysIcon ($sIcon, $sName, $sUrl = '', $iWidth = 0) { return '
' . ($sUrl ? '' : '') . ''.$sName.'' . ($sUrl ? '' : '') . '
'; } /** * functions for limiting maximal string length */ function getStringWithLimitedLength($sString, $iWidth = 45, $isPopupOnOverflow = false, $bReturnString = true) { if (empty($sString) || mb_strlen($sString, 'UTF-8') <= $iWidth) return $bReturnString ? $sString : array($sString); $sResult = ''; $aWords = mb_split("[\s\r\n]", $sString); $iPosition = 0; $iWidthReal = $iWidth - 3; $iWidthMin = $iWidth - 15; foreach($aWords as $sWord) { $sWord = trim($sWord); $iWord = mb_strlen($sWord, 'UTF-8'); if ($iPosition + $iWord > $iWidthReal) break; // add word and continue $sResult .= ' ' . $sWord; $iPosition += 1 + $iWord; } // last word is too long, cut it if(!$iPosition || $iPosition < $iWidthMin) $sResult .= ' ' . mb_substr($sWord, 0, $iWidthReal - $iPosition - $iWord, 'UTF-8'); $sResult = trim($sResult); // add tripple dot if(!$isPopupOnOverflow) { $sResult .= '...'; return $bReturnString ? $sResult : array($sResult); } // add button width popup $sId = 'bx-str-limit-' . rand(1, PHP_INT_MAX); $sPopup = ''; $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 * @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) { return $this->_oTemplate->parseHtmlByName('designbox_' . (int)$iTemplateNum . '.html', array( 'title' => $sTitle, 'designbox_content' => $sContent, 'caption_item' => $this->designBoxMenu ($mixedMenu, array (array('menu' => 1))), )); } function designBoxMenu ($mixedMenu, $aButtons = array ()) { $sCode = ''; $aButtonMenu = false; if ($mixedMenu) { $sMenu = ''; if (is_string($mixedMenu)) { $oMenu = BxTemplMenu::getObjectInstance($mixedMenu); $sMenu = $oMenu ? $oMenu->getCode () : $mixedMenu; } elseif (is_object($mixedMenu) && is_a($mixedMenu, 'BxTemplMenu')) { $sMenu = $mixedMenu->getCode(); } elseif (is_array($mixedMenu)) { if (isset($mixedMenu['template']) && isset($mixedMenu['menu_items'])) $aMenu = $mixedMenu; else $aMenu = array ('template' => 'menu_vertical.html', 'menu_items' => $mixedMenu); $oMenu = new BxTemplMenu($aMenu, $this->_oTemplate); $sMenu = $oMenu->getCode (); } if ($sMenu) { $sId = 'bx-menu-db-' . time() . rand(0, PHP_INT_MAX); $sCode .= $this->slideBox($sId, $sMenu, true); $aButtonMenu = array ('icon-a' => $this->_sDesignBoxIcon, 'onclick' => "bx_menu_slide('#" . $sId . "', this)"); } } if ($aButtons) { $sCode .= '
'; foreach ($aButtons as $aButton) { if (isset($aButton['menu']) && $aButton['menu']) { if (!$aButtonMenu) continue; $aButton = $aButtonMenu; } $aAttrs = array (); if (!empty($aButton['onclick'])) $aAttrs['onclick'] = $aButton['onclick']; if (!empty($aButton['class'])) $aAttrs['class'] = $aButton['class']; $sAttrs = bx_convert_array2attrs ($aAttrs, 'bx-def-margin-sec-left'); $sCode .= ''; $sCode .= !empty($aButton['icon']) ? '' : ''; $sCode .= !empty($aButton['icon-a']) ? '' : ''; $sCode .= !empty($aButton['title']) ? $aButton['title'] : ''; $sCode .= ''; } $sCode .= '
'; } return $sCode; } /** * Get logo URL. * @return string */ function getMainLogoUrl() { $oDesigns = BxDolDesigns::getInstance(); $iFileId = (int)$oDesigns->getSiteLogo(); if (!$iFileId) return false; $oStorage = BxDolTranscoder::getObjectInstance('sys_custom_images'); $sFileUrl = $oStorage->getFileUrl($iFileId); if (!$sFileUrl) return false; $iLogoWidth = (int)$oDesigns->getSiteLogoWidth(); if($iLogoWidth > 0) $sFileUrl = bx_append_url_params($sFileUrl, array('x' => $iLogoWidth)); $iLogoHeight = (int)$oDesigns->getSiteLogoHeight(); if($iLogoHeight > 0) $sFileUrl = bx_append_url_params($sFileUrl, array('y' => $iLogoHeight)); return $sFileUrl; } /** * Get logo HTML. * @return string */ function getMainLogo() { $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 = ''; } return '' . $sLogo . ''; } /** * Get HTML code for meta icons. * @return HTML string to insert into HEAD section */ function getMetaIcons() { $iId = (int)getParam('sys_site_icon'); $sImageUrlFav = $sImageUrlFcb = $sImageUrlApl = ''; if(!empty($iId)) { // favicon icon $oTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_FAVICON); $sImageUrlFav = $oTranscoder->getFileUrl($iId); // facebook icon $oTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK); $sImageUrlFcb = $oTranscoder->getFileUrl($iId); // apple touch icon $oTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_APPLE); $sImageUrlApl = $oTranscoder->getFileUrl($iId); } if(empty($sImageUrlFav)) $sImageUrlFav = $this->_oTemplate->getIconUrl('favicon.png'); if(empty($sImageUrlFcb)) $sImageUrlFcb = $this->_oTemplate->getIconUrl('facebook-icon.png'); if(empty($sImageUrlApl)) $sImageUrlApl = $this->_oTemplate->getIconUrl('apple-touch-icon.png'); $sRet = ''; $sRet .= ''; $sRet .= ''; $sRet .= ''; return $sRet; } /** * Output time wrapped in