BxBaseFunctions.php 25 KB

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