BxBaseFunctions.php 26 KB

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