_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)
{
$iId = !empty($sName) ? $sName : time();
return
($isPlaceInCenter ? '
' : '') .
$this->_oTemplate->parseHtmlByName('popup_trans.html', array(
'id' => $iId,
'wrapper_style' => $isHiddenByDefault ? 'display:none;' : '',
'content' => $sContent
)) .
($isPlaceInCenter ? '
' : '');
}
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 '';
}
/**
* Outputs holder html for dynamically loaded RSS.
* It automatically adds necessary js, css files and make injection into HTML HEAD section.
* @param $mixedRssId - system rss name, or current block id (if inserted into builder page)
* @param $iRssNum - numbr of rss items to disolay
* @param $iMemberId - optional member id
*/
function getRssHolder ($mixedRssId, $iRssNum, $iMemberId = 0)
{
if (!isset($GLOBALS['gbBxSysIsRssInitialized']) || !$GLOBALS['gbBxSysIsRssInitialized']) {
$this->_oTemplate->addCss(array(
'rss.css',
));
$this->_oTemplate->addJs(array(
'jquery.dolRSSFeed.js',
'jquery.jfeed.js'
));
$this->_oTemplate->addInjection ('injection_head', 'text', '
');
$GLOBALS['gbBxSysIsRssInitialized'] = true;
}
return $this->_oTemplate->parseHtmlByName('rss_holder.html', array (
'rss_id' => $mixedRssId,
'rss_num' => $iRssNum,
'member_id' => $iMemberId,
));
}
/**
* 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 .= '' . BxTemplFunctions::getInstance()->transBox('', '
'.$sString.'
') . '
';
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)) {
bx_import('BxTemplMenu');
$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);
bx_import('BxTemplMenu');
$oMenu = new BxTemplMenu($aMenu, $this->_oTemplate);
$sMenu = $oMenu->getCode ();
}
if ($sMenu) {
$sId = 'bx-menu-db-' . time() . rand(0, PHP_INT_MAX);
$sCode .= BxTemplFunctions::getInstance()->transBox($sId, '' . $sMenu . '
', true);
$aButtonMenu = array ('icon' => 'reorder', 'onclick' => "bx_menu_popup_inline('#" . $sId . "', this)");
}
}
if ($aButtons) {
$sCode .= '';
}
return $sCode;
}
/**
* Get logo HTML.
* @return string
*/
function getMainLogo()
{
bx_import('BxDolConfig');
$sAlt = getParam('sys_site_logo_alt') ? getParam('sys_site_logo_alt') : getParam('site_title');
$sLogo = $sAlt;
$iFileId = (int)getParam('sys_site_logo');
if ($iFileId) {
bx_import('BxDolStorage');
$oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
$sFileUrl = $oStorage->getFileUrlById($iFileId);
if ($sFileUrl)
$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)) {
bx_import('BxDolImageTranscoder');
// favicon icon
$oTranscoder = BxDolImageTranscoder::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_FAVICON);
$sImageUrlFav = $oTranscoder->getImageUrl($iId);
// facebook icon
$oTranscoder = BxDolImageTranscoder::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK);
$sImageUrlFcb = $oTranscoder->getImageUrl($iId);
// apple touch icon
$oTranscoder = BxDolImageTranscoder::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_APPLE);
$sImageUrlApl = $oTranscoder->getImageUrl($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