BxBaseFunctions.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <?php
  2. /**
  3. * @package Dolphin Core
  4. * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * @license CC-BY - http://creativecommons.org/licenses/by/3.0/
  6. */
  7. defined('BX_DOL') or die('hack attempt');
  8. bx_import('BxDolTemplate');
  9. class BxBaseFunctions extends BxDol {
  10. protected $_aSpecialKeys;
  11. protected $_oTemplate;
  12. function BxBaseFunctions($oTemplate) {
  13. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  14. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  15. parent::BxDol();
  16. if ($oTemplate)
  17. $this->_oTemplate = $oTemplate;
  18. else
  19. $this->_oTemplate = BxDolTemplate::getInstance();
  20. $this->_aSpecialKeys = array('rate' => '', 'rate_cnt' => '');
  21. }
  22. /**
  23. * Prevent cloning the instance
  24. */
  25. public function __clone() {
  26. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  27. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  28. }
  29. public static function getInstance() {
  30. if(!isset($GLOBALS['bxDolClasses']['BxTemplFunctions']))
  31. $GLOBALS['bxDolClasses']['BxTemplFunctions'] = new BxTemplFunctions();
  32. return $GLOBALS['bxDolClasses']['BxTemplFunctions'];
  33. }
  34. function TemplPageAddComponent($sKey) {
  35. switch( $sKey ) {
  36. case 'something':
  37. return false; // return here additional components
  38. default:
  39. return false; // if you have not such component, return false!
  40. }
  41. }
  42. /**
  43. * Function will generate object's action link ;
  44. *
  45. * @param : $aObjectParamaters (array) contain special markers ;
  46. * @param : $aRow (array) links's info ;
  47. * @param : $sCssClass (string) additional css style ;
  48. * @return : Html presentation data ;
  49. */
  50. function genActionLink( &$aObjectParamaters, $aRow, $sCssClass = null ) {
  51. // ** init some needed variables ;
  52. $sOutputHtml = null;
  53. $aUsedTemplate = array (
  54. 'action' => 'action_link.html'
  55. );
  56. // find and replace all special markers ;
  57. foreach( $aRow AS $sKeyName => $sKeyValue ) {
  58. if ( $sKeyName == 'Caption' ) {
  59. $aRow[$sKeyName] = $this -> markerReplace($aObjectParamaters, $sKeyValue, $aRow['Eval'], true);
  60. } else {
  61. $aRow[$sKeyName] = $this -> markerReplace($aObjectParamaters, $sKeyValue, $aRow['Eval']);
  62. }
  63. }
  64. $sKeyValue = trim($sKeyValue, '{}');
  65. if ( array_key_exists($sKeyValue, $this->_aSpecialKeys) ) {
  66. return $aRow['Eval'];
  67. } else {
  68. $sSiteUrl = (preg_match("/^(http|https|ftp|mailto)/", $aRow['Url'])) ? '' : BX_DOL_URL_ROOT;
  69. // build the link components ;
  70. //$sLinkSrc = (!$aRow['Script']) ? $aRow['Url'] : 'javascript:void(0)';
  71. $sScriptAction = ( $aRow['Script'] ) ? ' onclick="' . $aRow['Script'] . '"' : '';
  72. $sScriptAction = ($sScriptAction=='' && $aRow['Url']!='') ? " onclick=\"window.open ('{$sSiteUrl}{$aRow['Url']}','_self');\" " : $sScriptAction;
  73. $sIcon = getTemplateIcon($aRow['Icon']);
  74. if ( $aRow['Caption'] and ($aRow['Url'] or $aRow['Script'] ) ) {
  75. $sCssClass = ( $sCssClass ) ? 'class="' . $sCssClass . '"' : null;
  76. $aTemplateKeys = array (
  77. 'action_img_alt' => $aRow['Caption'],
  78. 'action_img_src' => $sIcon,
  79. 'action_caption' => $aRow['Caption'],
  80. 'extended_css' => $sCssClass,
  81. 'extended_action' => $sScriptAction,
  82. );
  83. $sOutputHtml .= $this->_oTemplate->parseHtmlByName( $aUsedTemplate['action'], $aTemplateKeys );
  84. }
  85. }
  86. return $sOutputHtml;
  87. }
  88. /**
  89. * Function will parse and replace all special markers ;
  90. *
  91. * @param $aMemberSettings (array) : all available member's information
  92. * @param $sTransformText (text) : string that will to parse
  93. * @param $bTranslate (boolean) : if isset this param - script will try to translate it used dolphin language file
  94. * @return (string) : parsed string
  95. */
  96. function markerReplace( &$aMemberSettings, $sTransformText, $sExecuteCode = null, $bTranslate = false ) {
  97. $aMatches = array();
  98. preg_match_all( "/([a-z0-9\-\_ ]{1,})|({([^\}]+)\})/i", $sTransformText, $aMatches );
  99. if ( is_array($aMatches) and !empty($aMatches) ) {
  100. // replace all founded markers ;
  101. foreach( $aMatches[3] as $iMarker => $sMarkerValue ) {
  102. if ( is_array($aMemberSettings) and array_key_exists($sMarkerValue, $aMemberSettings) and !array_key_exists($sMarkerValue, $this->_aSpecialKeys) ){
  103. $sTransformText = str_replace( '{' . $sMarkerValue . '}', $aMemberSettings[$sMarkerValue], $sTransformText);
  104. } else if ( $sMarkerValue == 'evalResult' and $sExecuteCode ) {
  105. //find all special markers into Execute code ;
  106. $sExecuteCode = $this -> markerReplace( $aMemberSettings, $sExecuteCode );
  107. $sTransformText = str_replace( '{' . $sMarkerValue . '}', eval( $sExecuteCode ), $sTransformText);
  108. } else {
  109. // if isset into special keys ;
  110. if ( array_key_exists($sMarkerValue, $this->_aSpecialKeys) ) {
  111. return $aMemberSettings[$sMarkerValue];
  112. } else {
  113. // undefined keys
  114. switch ($sMarkerValue) {
  115. }
  116. }
  117. }
  118. }
  119. // try to translate item ;
  120. if ( $bTranslate ) {
  121. foreach( $aMatches[1] as $iMarker => $sMarkerValue ) if ( $sMarkerValue )
  122. $sTransformText = str_replace( $sMarkerValue , _t( trim($sMarkerValue) ), $sTransformText);
  123. }
  124. }
  125. return $sTransformText;
  126. }
  127. function msgBox($sText, $iTimer = 0, $sOnClose = "") {
  128. $iId = time() . mt_rand(1, 1000);
  129. return $this->_oTemplate->parseHtmlByName('messageBox.html', array(
  130. 'id' => $iId,
  131. 'msgText' => $sText,
  132. 'bx_if:timer' => array(
  133. 'condition' => $iTimer > 0,
  134. 'content' => array(
  135. 'id' => $iId,
  136. 'time' => 1000 * $iTimer,
  137. 'on_close' => $sOnClose,
  138. )
  139. )
  140. ));
  141. }
  142. function loadingBox($sName) {
  143. return $this->_oTemplate->parseHtmlByName('loading.html', array(
  144. 'name' => $sName,
  145. ));
  146. }
  147. /**
  148. * Get standard popup box with title.
  149. *
  150. * @param string $sTitle - translated title
  151. * @param string $sContent - content of the box
  152. * @return HTML string
  153. */
  154. function popupBox($sName, $sTitle, $sContent, $isHiddenByDefault = false) {
  155. $iId = !empty($sName) ? $sName : time();
  156. return $this->_oTemplate->parseHtmlByName('popup_box.html', array(
  157. 'id' => $iId,
  158. 'wrapper_style' => $isHiddenByDefault ? 'display:none;' : '',
  159. 'title' => $sTitle,
  160. 'content' => $sContent
  161. ));
  162. }
  163. /**
  164. * Get popup box without title.
  165. *
  166. * @param string $sContent - content of the box
  167. * @return HTML string
  168. */
  169. function transBox($sContent, $isPlaceInCenter = false) {
  170. return
  171. ($isPlaceInCenter ? '<div class="login_ajax_wrap">' : '') .
  172. $this->_oTemplate->parseHtmlByName('popup_trans.html', array('content' => $sContent)) .
  173. ($isPlaceInCenter ? '</div>' : '');
  174. }
  175. function getTemplateIcon($sName) {
  176. $sUrl = $this->_oTemplate->getIconUrl($sName);
  177. return !empty($sUrl) ? $sUrl : $this->_oTemplate->getIconUrl('spacer.gif');
  178. }
  179. function getTemplateImage($sName) {
  180. $sUrl = $this->_oTemplate->getImageUrl($sName);
  181. return !empty($sUrl) ? $sUrl : $this->_oTemplate->getImageUrl('spacer.gif');
  182. }
  183. /**
  184. * @description : function will generate object's action lists;
  185. * @param : $aKeys (array) - array with all nedded keys;
  186. * @param : $sActionsType (string) - type of actions;
  187. * @param : $iDivider (integer) - number of column;
  188. * @return: HTML presentation data;
  189. */
  190. function genObjectsActions( &$aKeys, $sActionsType, $bSubMenuMode = false ) {
  191. // ** init some needed variables ;
  192. $sActionsList = null;
  193. $sResponceBlock = null;
  194. $aUsedTemplate = array (
  195. 'actions' => 'member_actions_list.html',
  196. 'ajaxy_popup' => 'ajaxy_popup_result.html',
  197. );
  198. // read data from cache file ;
  199. $oCache = BxDolDb::getInstance()->getDbCacheObject();
  200. $aActions = $oCache->getData(BxDolDb::getInstance()->genDbCacheKey('sys_objects_actions'));
  201. // if cache file empty - will read from db ;
  202. if (null === $aActions || empty($aActions[$sActionsType]) ) {
  203. $sQuery = "
  204. SELECT
  205. `Caption`, `Icon`, `Url`, `Script`, `Eval`, `bDisplayInSubMenuHeader`
  206. FROM
  207. `sys_objects_actions`
  208. WHERE
  209. `Type` = '{$sActionsType}'
  210. ORDER BY
  211. `Order`
  212. ";
  213. $rResult = db_res($sQuery);
  214. while ( $aRow = mysql_fetch_assoc($rResult) ) {
  215. $aActions[$sActionsType][] = $aRow;
  216. }
  217. // write data into cache file ;
  218. if ( is_array($aActions[$sActionsType]) and !empty($aActions[$sActionsType]) ) {
  219. $oCache->setData (BxDolDb::getInstance()->genDbCacheKey('sys_objects_actions'), $aActions);
  220. }
  221. }
  222. // ** generate actions block ;
  223. // contain all systems actions that will procces by self function ;
  224. $aCustomActions = array();
  225. if ( is_array($aActions[$sActionsType]) and !empty($aActions[$sActionsType]) ) {
  226. // need for table's divider ;
  227. $iDivider = $iIndex = 0;
  228. foreach( $aActions[$sActionsType] as $aRow ) {
  229. if ($bSubMenuMode && $aRow['bDisplayInSubMenuHeader']==0) continue;
  230. $sOpenTag = $sCloseTag = null;
  231. // generate action's link ;
  232. $sActionLink = $this -> genActionLink( $aKeys, $aRow, 'menuLink') ;
  233. if ( $sActionLink ) {
  234. $iDivider = $iIndex % 2;
  235. if ( !$iDivider ) {
  236. $sOpenTag = '<tr>';
  237. }
  238. if ( $iDivider ) {
  239. $sCloseTag = '</tr>';
  240. }
  241. $aActionsItem[] = array (
  242. 'open_tag' => $sOpenTag,
  243. 'action_link' => $sActionLink,
  244. 'close_tag' => $sCloseTag,
  245. );
  246. $iIndex++;
  247. }
  248. // it's system action ;
  249. if ( !$aRow['Url'] && !$aRow['Script'] ) {
  250. $aCustomActions[] = array (
  251. 'caption' => $aRow['Caption'],
  252. 'code' => $aRow['Eval'],
  253. );
  254. }
  255. }
  256. }
  257. if ($iIndex % 2 == 1) { //fix for ODD menu elements count
  258. $aActionsItem[] = array (
  259. 'open_tag' => '',
  260. 'action_link' => '',
  261. 'close_tag' => ''
  262. );
  263. }
  264. if ( !empty($aActionsItem) ) {
  265. // check what response window use ;
  266. // is there any value to having this template even if the ID is empty?
  267. if ( !empty($aKeys['ID']) ) {
  268. $sResponceBlock = $this->_oTemplate->parseHtmlByName( $aUsedTemplate['ajaxy_popup'], array('object_id' => $aKeys['ID']) );
  269. }
  270. $aTemplateKeys = array (
  271. 'bx_repeat:actions' => $aActionsItem,
  272. 'responce_block' => $sResponceBlock,
  273. );
  274. $sActionsList = $this->_oTemplate->parseHtmlByName( $aUsedTemplate['actions'], $aTemplateKeys );
  275. }
  276. //procces all the custom actions ;
  277. if ($aCustomActions) {
  278. foreach($aCustomActions as $iIndex => $sValue ) {
  279. $sActionsList .= eval( $this -> markerReplace($aKeys, $aCustomActions[$iIndex]['code']) );
  280. }
  281. }
  282. return $sActionsList;
  283. }
  284. /**
  285. * alternative to GenFormWrap
  286. * easy to use but javascript based
  287. * $s - content to be centered
  288. * $sBlockStyle - block's style, jquery selector
  289. *
  290. * see also bx_center_content javascript function, if you need to call this function from javascript
  291. */
  292. function centerContent ($s, $sBlockStyle, $isClearBoth = true) {
  293. $sId = 'id' . time() . rand();
  294. return '<div id="'.$sId.'">' . $s . ($isClearBoth ? '<div class="clear_both"></div>' : '') . '</div><script>
  295. $(document).ready(function() {
  296. var eCenter = $("#'.$sId.'");
  297. var iAll = $("#'.$sId.' '.$sBlockStyle.'").size();
  298. var iWidthUnit = $("#'.$sId.' '.$sBlockStyle.':first").outerWidth({"margin":true});
  299. var iWidthContainer = eCenter.width();
  300. var iPerRow = parseInt(iWidthContainer/iWidthUnit);
  301. var iLeft = (iWidthContainer - (iAll > iPerRow ? iPerRow * iWidthUnit : iAll * iWidthUnit)) / 2;
  302. eCenter.css("padding-left", iLeft);
  303. });
  304. </script>';
  305. }
  306. function genNotifyMessage($sMessage, $sDirection = 'left', $isButton = false, $sScript = '') {
  307. $sDirStyle = ($sDirection == 'left') ? '' : 'notify_message_none';
  308. switch ($sDirection) {
  309. case 'none': break;
  310. case 'left': break;
  311. }
  312. $sPossibleID = ($isButton) ? ' id="isButton" ' : '';
  313. $sOnClick = $sScript ? ' onclick="' . $sScript . '"' : '';
  314. return <<<EOF
  315. <div class="notify_message {$sDirStyle}" {$sPossibleID} {$sOnClick}>
  316. <table class="notify" cellpadding=0 cellspacing=0><tr><td>{$sMessage}</td></tr></table>
  317. <div class="notify_wrapper_close"> </div>
  318. </div>
  319. EOF;
  320. }
  321. function sysIcon ($sIcon, $sName, $sUrl = '', $iWidth = 0) {
  322. return '<div class="sys_icon">' . ($sUrl ? '<a title="'.$sName.'" href="'.$sUrl.'">' : '') . '<img alt="'.$sName.'" src="'.$sIcon.'" '.($iWidth ? 'width='.$iWidth : '').' />' . ($sUrl ? '</a>' : '') . '</div>';
  323. }
  324. /**
  325. * Outputs holder html for dynamically loaded RSS.
  326. * It automatically adds necessary js, css files and make injection into HTML HEAD section.
  327. * @param $mixedRssId - system rss name, or current block id (if inserted into builder page)
  328. * @param $iRssNum - numbr of rss items to disolay
  329. * @param $iMemberId - optional member id
  330. */
  331. function getRssHolder ($mixedRssId, $iRssNum, $iMemberId = 0) {
  332. if (!isset($GLOBALS['gbBxSysIsRssInitialized']) || !$GLOBALS['gbBxSysIsRssInitialized']) {
  333. $this->_oTemplate->addCss(array(
  334. 'rss.css',
  335. ));
  336. $this->_oTemplate->addJs(array(
  337. 'jquery.dolRSSFeed.js',
  338. 'jquery.jfeed.js'
  339. ));
  340. $this->_oTemplate->addInjection ('injection_head', 'text', '
  341. <script type="text/javascript" language="javascript">
  342. $(document).ready( function() {
  343. $("div.RSSAggrCont").dolRSSFeed();
  344. });
  345. </script>');
  346. $GLOBALS['gbBxSysIsRssInitialized'] = true;
  347. }
  348. return $this->_oTemplate->parseHtmlByName('rss_holder.html', array (
  349. 'rss_id' => $mixedRssId,
  350. 'rss_num' => $iRssNum,
  351. 'member_id' => $iMemberId,
  352. ));
  353. }
  354. /**
  355. * Function will generate list of installed languages list;
  356. *
  357. * @return : Html presentation data;
  358. */
  359. function getLangSwitcher() {
  360. bx_import('BxDolLanguagesQuery');
  361. $aLangs = BxDolLanguagesQuery::getInstance()->getLanguages();
  362. if(count($aLangs) < 2)
  363. return '';
  364. $sOutputCode = '';
  365. foreach( $aLangs as $sName => $sLang ) {
  366. $sFlag = $this->_oTemplate->getIconUrl('sys_fl_' . $sName . '.gif');
  367. $aTemplateKeys = array (
  368. 'bx_if:item_img' => array (
  369. 'condition' => ( $sFlag ),
  370. 'content' => array (
  371. 'item_img_src' => $sFlag,
  372. 'item_img_alt' => $sName,
  373. 'item_img_width' => 18,
  374. 'item_img_height' => 12,
  375. ),
  376. ),
  377. 'item_link' => BX_DOL_URL_ROOT . 'index.php?lang=' . $sName,
  378. 'item_onclick' => null,
  379. 'item_title' => $sLang,
  380. 'extra_info' => null,
  381. );
  382. $sOutputCode .= $this->_oTemplate->parseHtmlByName( 'member_menu_sub_item.html', $aTemplateKeys );
  383. }
  384. return $sOutputCode;
  385. }
  386. /**
  387. * functions for limiting maximal string length
  388. */
  389. function getStringWithLimitedLength($sString, $iWidth = 45, $isPopupOnOverflow = false, $bReturnString = true) {
  390. if (empty($sString) || mb_strlen($sString, 'UTF-8') <= $iWidth)
  391. return $bReturnString ? $sString : array($sString);
  392. $sResult = '';
  393. $aWords = mb_split("[\s\r\n]", $sString);
  394. $iPosition = 0;
  395. $iWidthReal = $iWidth - 3;
  396. $iWidthMin = $iWidth - 15;
  397. foreach($aWords as $sWord) {
  398. $sWord = trim($sWord);
  399. $iWord = mb_strlen($sWord, 'UTF-8');
  400. if ($iPosition + $iWord > $iWidthReal)
  401. break;
  402. // add word and continue
  403. $sResult .= ' ' . $sWord;
  404. $iPosition += 1 + $iWord;
  405. }
  406. // last word is too long, cut it
  407. if(!$iPosition || $iPosition < $iWidthMin)
  408. $sResult .= ' ' . mb_substr($sWord, 0, $iWidthReal - $iPosition - $iWord, 'UTF-8');
  409. $sResult = trim($sResult);
  410. // add tripple dot
  411. if(!$isPopupOnOverflow) {
  412. $sResult .= '...';
  413. return $bReturnString ? $sResult : array($sResult);
  414. }
  415. // add button width popup
  416. $sId = 'bx-str-limit-' . rand(1, PHP_INT_MAX);
  417. $sPopup = '<img class="bx-str-limit" onclick="$(\'#' . $sId . '\').dolPopup({pointer:{el:$(this), offset:\'10 1\'}})" src="' . $this->getTemplateImage('str-limit.png') . '"/>';
  418. $sPopup .= '<div id="' . $sId . '" style="display:none;">' . BxTemplFunctions::getInstance()->transBox('<div class="bx-def-padding bx-def-color-bg-block">'.$sString.'</div>') . '</div>';
  419. return $bReturnString ? $sResult . $sPopup : array($sResult, $sPopup);
  420. }
  421. /**
  422. * Display design box with specified title, template, content and menu.
  423. * @param $sTitle - design box title, please note that some templates don't use title.
  424. * @param $sContent - design box content.
  425. * @param $iTemplateNum - number of design box template, use predefined contants only, default is BX_DB_DEF.
  426. * @param $mixedMenu - design box menu, it can be:
  427. * - object: instance of BxTemplMenu class
  428. * - string: menu object identifier
  429. * - array: array of menu links to create menu from
  430. * @return string
  431. *
  432. * @see BX_DB_CONTENT_ONLY
  433. * @see BX_DB_DEF
  434. * @see BX_DB_EMPTY
  435. * @see BX_DB_NO_CAPTION
  436. * @see BX_DB_PADDING_CONTENT_ONLY
  437. * @see BX_DB_PADDING_DEF
  438. * @see BX_DB_PADDING_NO_CAPTION
  439. */
  440. function designBoxContent ($sTitle, $sContent, $iTemplateNum = BX_DB_DEF, $mixedMenu = false) {
  441. return $this->_oTemplate->parseHtmlByName('designbox_' . (int)$iTemplateNum . '.html', array(
  442. 'title' => $sTitle,
  443. 'designbox_content' => $sContent,
  444. 'caption_item' => $this->designBoxMenu ($mixedMenu, array (array('menu' => 1))),
  445. 'bottom_item' => '', // TODO: remove or implement somehow
  446. ));
  447. }
  448. function designBoxMenu ($mixedMenu, $aButtons = array ()) {
  449. $sCode = '';
  450. $aButtonMenu = false;
  451. if ($mixedMenu) {
  452. $sMenu = '';
  453. if (is_string($mixedMenu)) {
  454. bx_import('BxTemplMenu');
  455. $oMenu = BxTemplMenu::getObjectInstance($mixedMenu);
  456. $sMenu = $oMenu ? $oMenu->getCode () : '';
  457. } elseif (is_object($mixedMenu) && is_a($mixedMenu, 'BxTemplMenu')) {
  458. $sMenu = $mixedMenu->getCode();
  459. } elseif (is_array($mixedMenu)) {
  460. if (isset($mixedMenu['template']) && isset($mixedMenu['menu_items']))
  461. $aMenu = $mixedMenu;
  462. else
  463. $aMenu = array ('template' => 'menu_horizontal.html', 'menu_items' => $mixedMenu);
  464. bx_import('BxTemplMenu');
  465. $oMenu = new BxTemplMenu($aMenu, $this->_oTemplate);
  466. $sMenu = $oMenu->getCode ();
  467. }
  468. if ($sMenu) {
  469. $sId = 'bx-menu-db-' . time() . rand(0, PHP_INT_MAX);
  470. $sCode .= '<div id="' . $sId . '" style="display:none;">' . BxTemplFunctions::getInstance()->transBox('<div class="bx-def-padding bx-def-color-bg-block">' . $sMenu . '</div>') . '</div>';
  471. $aButtonMenu = array ('icon' => 'ui-menu-blue.png', 'onclick' => 'if ($(\'#' . $sId . ':visible\').length) $(\'#' . $sId . '\').dolPopupHide(); else $(\'#' . $sId . '\').dolPopup({pointer:{el:$(this)}})');
  472. }
  473. }
  474. if ($aButtons) {
  475. $sCode .= '<div class="bx-db-menu bx-def-padding-right"><div class="bx-db-menu-tab bx-db-menu-tab-btn">';
  476. foreach ($aButtons as $aButton) {
  477. if (isset($aButton['menu']) && $aButton['menu']) {
  478. if (!$aButtonMenu)
  479. continue;
  480. $aButton = $aButtonMenu;
  481. }
  482. $aAttrs = array ();
  483. if (!empty($aButton['onclick']))
  484. $aAttrs['onclick'] = $aButton['onclick'];
  485. if (!empty($aButton['class']))
  486. $aAttrs['class'] = $aButton['class'];
  487. $sAttrs = bx_convert_array2attrs ($aAttrs, 'bx-btn bx-def-margin-sec-left');
  488. $sCode .= '<button ' . $sAttrs . '>';
  489. $sCode .= !empty($aButton['icon']) ? '<i style="background-image:url(' . $this->_oTemplate->getIconUrl($aButton['icon']) . ')"></i>' : '';
  490. $sCode .= !empty($aButton['title']) ? $aButton['title'] : '';
  491. $sCode .= '</button>';
  492. }
  493. $sCode .= '</div></div>';
  494. }
  495. return $sCode;
  496. }
  497. /**
  498. * Get logo HTML.
  499. * @return string
  500. */
  501. function getMainLogo() {
  502. bx_import('BxDolConfig');
  503. $sAlt = getParam('sys_site_logo_alt') ? getParam('sys_site_logo_alt') : getParam('site_title');
  504. $sLogo = $sAlt;
  505. $iFileId = (int)getParam('sys_site_logo');
  506. if ($iFileId) {
  507. bx_import('BxDolStorage');
  508. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  509. $sFileUrl = $oStorage->getFileUrlById($iFileId);
  510. if ($sFileUrl)
  511. $sLogo = '<img src="' . $sFileUrl . '" id="bx-logo" class="bx-def-margin-sec" alt="' . bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE) . '" />';
  512. }
  513. return '<a href="' . BX_DOL_URL_ROOT . '" title="' . bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE) . '">' . $sLogo . '</a>';
  514. }
  515. /**
  516. * Get HTML code for meta icons.
  517. * @return HTML string to insert into HEAD section
  518. */
  519. function getMetaIcons() {
  520. if (!($iId = (int)getParam('sys_site_icon')))
  521. return '';
  522. bx_import('BxDolImageTranscoder');
  523. $sRet = '';
  524. // favicon icon
  525. $oTranscoder = BxDolImageTranscoder::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_FAVICON);
  526. $sImageUrl = $oTranscoder->getImageUrl($iId);
  527. if ($sImageUrl)
  528. $sRet .= '<link rel="icon" type="image/png" href="' . $sImageUrl . '" />';
  529. // apple icon
  530. $oTranscoder = BxDolImageTranscoder::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_APPLE);
  531. $sImageUrl = $oTranscoder->getImageUrl($iId);
  532. if ($sImageUrl)
  533. $sRet .= '<link rel="apple-touch-icon" href="' . $sImageUrl . '" />';
  534. // facebook icon
  535. $oTranscoder = BxDolImageTranscoder::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK);
  536. $sImageUrl = $oTranscoder->getImageUrl($iId);
  537. if ($sImageUrl)
  538. $sRet .= '<link rel="image_src" href="' . $sImageUrl . '" />';
  539. return $sRet;
  540. }
  541. }