BxBaseFunctions.php 26 KB

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