BxBaseFunctions.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxBaseFunctions extends BxDolFactory implements iBxDolSingleton
  10. {
  11. protected $_oTemplate;
  12. protected $_sDesignBoxMenuTmplDefault;
  13. protected $_sDesignBoxMenuIcon;
  14. protected $_sDesignBoxMenuIconType;
  15. protected $_sDesignBoxMenuClick;
  16. protected function __construct($oTemplate)
  17. {
  18. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  19. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  20. parent::__construct();
  21. $this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
  22. $this->_sDesignBoxMenuTmplDefault = 'menu_block_submenu_ver.html';
  23. $this->_sDesignBoxMenuIcon = 'chevron';
  24. $this->_sDesignBoxMenuIconType = 'icon-a';
  25. $this->_sDesignBoxMenuClick = "bx_menu_slide_inline('#{design_box_menu}', this)";
  26. }
  27. /**
  28. * Prevent cloning the instance
  29. */
  30. public function __clone()
  31. {
  32. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  33. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  34. }
  35. public static function getInstanceWithTemplate($oTemplate)
  36. {
  37. if(!isset($GLOBALS['bxDolClasses']['BxTemplFunctions']))
  38. $GLOBALS['bxDolClasses']['BxTemplFunctions'] = new BxTemplFunctions($oTemplate);
  39. return $GLOBALS['bxDolClasses']['BxTemplFunctions'];
  40. }
  41. public static function getInstance()
  42. {
  43. return self::getInstanceWithTemplate(null);
  44. }
  45. function TemplPageAddComponent($sKey)
  46. {
  47. switch( $sKey ) {
  48. case 'something':
  49. return false; // return here additional components
  50. default:
  51. return false; // if you have not such component, return false!
  52. }
  53. }
  54. function msgBox($sText, $iTimer = 0, $sOnClose = "")
  55. {
  56. $iId = time() . mt_rand(1, 1000);
  57. if($iTimer > 0)
  58. BxDolTemplate::getInstance()->addJs(array('jquery.anim.js'));
  59. return $this->_oTemplate->parseHtmlByName('messageBox.html', array(
  60. 'id' => $iId,
  61. 'msgText' => $sText,
  62. 'bx_if:timer' => array(
  63. 'condition' => $iTimer > 0,
  64. 'content' => array(
  65. 'id' => $iId,
  66. 'time' => 1000 * $iTimer,
  67. 'on_close' => $sOnClose,
  68. )
  69. )
  70. ));
  71. }
  72. /**
  73. * Get standard popup box with title.
  74. *
  75. * @param string $sName - unique name
  76. * @param string $sTitle - translated title
  77. * @param string $sContent - content of the box
  78. * @return HTML string
  79. */
  80. function popupBox($sName, $sTitle, $sContent, $isHiddenByDefault = false)
  81. {
  82. $iId = !empty($sName) ? $sName : time();
  83. return $this->_oTemplate->parseHtmlByName('popup_box.html', array(
  84. 'id' => $iId,
  85. 'wrapper_style' => $isHiddenByDefault ? 'display:none;' : '',
  86. 'title' => $sTitle,
  87. 'content' => $sContent
  88. ));
  89. }
  90. /**
  91. * Get popup box without title.
  92. *
  93. * @param string $sName - unique name
  94. * @param string $sContent - content of the box
  95. * @return HTML string
  96. */
  97. function transBox($sName, $sContent, $isHiddenByDefault = false, $isPlaceInCenter = false)
  98. {
  99. return $this->simpleBox($sName, $sContent, $isHiddenByDefault, $isPlaceInCenter, 'popup_trans.html');
  100. }
  101. function slideBox($sName, $sContent, $isHiddenByDefault = false)
  102. {
  103. return $this->simpleBox($sName, $sContent, $isHiddenByDefault, false, 'popup_slide.html');
  104. }
  105. function inlineBox($sName, $sContent, $isHiddenByDefault = false)
  106. {
  107. return $this->simpleBox($sName, $sContent, $isHiddenByDefault, false, 'popup_inline.html');
  108. }
  109. protected function simpleBox($sName, $sContent, $isHiddenByDefault, $isPlaceInCenter, $sTemplate) {
  110. $iId = !empty($sName) ? $sName : time();
  111. $sContent = $this->_oTemplate->parseHtmlByName($sTemplate, array(
  112. 'id' => $iId,
  113. 'wrapper_style' => $isHiddenByDefault ? 'display:none;' : '',
  114. 'content' => $sContent
  115. ));
  116. if($isPlaceInCenter)
  117. $sContent = '<div class="login_ajax_wrap">' . $sContent . '</div>';
  118. return $sContent;
  119. }
  120. function getTemplateIcon($sName)
  121. {
  122. $sUrl = $this->_oTemplate->getIconUrl($sName);
  123. return !empty($sUrl) ? $sUrl : $this->_oTemplate->getIconUrl('spacer.gif');
  124. }
  125. function getTemplateImage($sName)
  126. {
  127. $sUrl = $this->_oTemplate->getImageUrl($sName);
  128. return !empty($sUrl) ? $sUrl : $this->_oTemplate->getImageUrl('spacer.gif');
  129. }
  130. function sysIcon ($sIcon, $sName, $sUrl = '', $iWidth = 0)
  131. {
  132. return '<div class="sys_icon">' . ($sUrl ? '<a title="'.$sName.'" href="'.$sUrl.'">' : '') . '<img alt="'.$sName.'" src="'.$sIcon.'" '.($iWidth ? 'width='.$iWidth : '').' />' . ($sUrl ? '</a>' : '') . '</div>';
  133. }
  134. /**
  135. * functions for limiting maximal string length
  136. */
  137. function getStringWithLimitedLength($sString, $iWidth = 45, $isPopupOnOverflow = false, $bReturnString = true)
  138. {
  139. if (empty($sString) || mb_strlen($sString, 'UTF-8') <= $iWidth)
  140. return $bReturnString ? $sString : array($sString);
  141. $sResult = '';
  142. $aWords = mb_split("[\s\r\n]", $sString);
  143. $iPosition = 0;
  144. $iWidthReal = $iWidth - 3;
  145. $iWidthMin = $iWidth - 15;
  146. foreach($aWords as $sWord) {
  147. $sWord = trim($sWord);
  148. $iWord = mb_strlen($sWord, 'UTF-8');
  149. if ($iPosition + $iWord > $iWidthReal)
  150. break;
  151. // add word and continue
  152. $sResult .= ' ' . $sWord;
  153. $iPosition += 1 + $iWord;
  154. }
  155. // last word is too long, cut it
  156. if(!$iPosition || $iPosition < $iWidthMin)
  157. $sResult .= ' ' . mb_substr($sWord, 0, $iWidthReal - $iPosition - $iWord, 'UTF-8');
  158. $sResult = trim($sResult);
  159. // add tripple dot
  160. if(!$isPopupOnOverflow) {
  161. $sResult .= '...';
  162. return $bReturnString ? $sResult : array($sResult);
  163. }
  164. // add button width popup
  165. $sId = 'bx-str-limit-' . rand(1, PHP_INT_MAX);
  166. $sPopup = '<img class="bx-str-limit" onclick="$(\'#' . $sId . '\').dolPopup({pointer:{el:$(this), offset:\'10 1\'}})" src="' . $this->getTemplateImage('str-limit.png') . '"/>';
  167. $sPopup .= '<div id="' . $sId . '" style="display:none;">' . BxTemplFunctions::getInstance()->transBox('', '<div class="bx-def-padding bx-def-color-bg-block">'.$sString.'</div>') . '</div>';
  168. return $bReturnString ? $sResult . $sPopup : array($sResult, $sPopup);
  169. }
  170. /**
  171. * Display design box with specified title, template, content and menu.
  172. * @param $sTitle - design box title, please note that some templates don't use title.
  173. * @param $sContent - design box content.
  174. * @param $iTemplateNum - number of design box template, use predefined contants only, default is BX_DB_DEF.
  175. * @param $mixedMenu - design box menu, it can be:
  176. * - object: instance of BxTemplMenu class
  177. * - string: menu object identifier
  178. * - array: array of menu links to create menu from
  179. * @param $mixedButtons - design box menu representation, it can be:
  180. * - false: design box menu will be used as horizontal menu (tabs)
  181. * - array: array of menu links to create menu from. If empty array is used and 'design box menu' isn't empty, then 'design box menu' will be added as one of menu items automatically. If non-empty array is used and 'design box menu' isn't empty then it should be added as one of menu items. Use array('menu' => 1) to define menu item for 'design box menu'.
  182. * @return string
  183. *
  184. * @see BX_DB_CONTENT_ONLY
  185. * @see BX_DB_DEF
  186. * @see BX_DB_EMPTY
  187. * @see BX_DB_NO_CAPTION
  188. * @see BX_DB_PADDING_CONTENT_ONLY
  189. * @see BX_DB_PADDING_DEF
  190. * @see BX_DB_PADDING_NO_CAPTION
  191. */
  192. function designBoxContent ($sTitle, $sContent, $iTemplateNum = BX_DB_DEF, $mixedMenu = false, $mixedButtons = array())
  193. {
  194. return $this->_oTemplate->parseHtmlByName('designbox_' . (int)$iTemplateNum . '.html', array(
  195. 'title' => $sTitle,
  196. 'designbox_content' => $sContent,
  197. 'caption_item' => $this->designBoxMenu($mixedMenu, $mixedButtons),
  198. ));
  199. }
  200. function designBoxMenu ($mixedMenu, $mixedButtons = array())
  201. {
  202. $bUseTabs = is_bool($mixedButtons) && $mixedButtons === true;
  203. $sMenu = '';
  204. if(!empty($mixedMenu)) {
  205. if(is_string($mixedMenu)) {
  206. if(($oMenu = BxTemplMenu::getObjectInstance($mixedMenu)) !== false) {
  207. $oMenu->setTemplateById($bUseTabs ? BX_DB_MENU_TEMPLATE_TABS : BX_DB_MENU_TEMPLATE_POPUP);
  208. $sMenu = $oMenu->getCode();
  209. }
  210. else
  211. $sMenu = $mixedMenu;
  212. }
  213. else if(is_array($mixedMenu)) {
  214. if(isset($mixedMenu['template']) && isset($mixedMenu['menu_items']))
  215. $aMenu = $mixedMenu;
  216. else
  217. $aMenu = array('template' => $this->_sDesignBoxMenuTmplDefault, 'menu_items' => $mixedMenu);
  218. if(($oMenu = new BxTemplMenu($aMenu, $this->_oTemplate)) !== false) {
  219. $oMenu->setTemplateById($bUseTabs ? BX_DB_MENU_TEMPLATE_TABS : BX_DB_MENU_TEMPLATE_POPUP);
  220. $sMenu = $oMenu->getCode();
  221. }
  222. else
  223. $sMenu = '';
  224. }
  225. else if(is_object($mixedMenu) && is_a($mixedMenu, 'BxTemplMenu')) {
  226. $mixedMenu->setTemplateById($bUseTabs ? BX_DB_MENU_TEMPLATE_TABS : BX_DB_MENU_TEMPLATE_POPUP);
  227. $sMenu = $mixedMenu->getCode();
  228. }
  229. }
  230. $bMenu = !empty($sMenu);
  231. $sResult = '';
  232. if($bUseTabs && $bMenu)
  233. $sResult = $sMenu;
  234. else if(is_array($mixedButtons)) {
  235. $sPopup = '';
  236. if($bMenu) {
  237. $aButton = array();
  238. if(empty($mixedButtons))
  239. list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu);
  240. //--- For backward compatibility
  241. else if(!empty($mixedButtons['menu']) && is_array($mixedButtons['menu'])) {
  242. list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu, $mixedButtons['menu']);
  243. unset($mixedButtons['menu']);
  244. }
  245. if(!empty($aButton))
  246. $mixedButtons[] = $aButton;
  247. }
  248. foreach($mixedButtons as $aButton) {
  249. if($bMenu && isset($aButton['menu'])) {
  250. if(is_numeric($aButton['menu']) && (int)$aButton['menu'] == 1)
  251. list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu);
  252. else if(is_array($aButton['menu']))
  253. list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu, $aButton['menu']);
  254. if(isset($aButton['menu']))
  255. continue;
  256. }
  257. $aAttrs = array();
  258. if(!empty($aButton['onclick']))
  259. $aAttrs['onclick'] = $aButton['onclick'];
  260. if(!empty($aButton['class']))
  261. $aAttrs['class'] = $aButton['class'];
  262. $bTmplVarsButtonIcon = !empty($aButton['icon']);
  263. $aTmplVarsButtonIcon = !$bTmplVarsButtonIcon ? array() : array(
  264. 'icon' => $aButton['icon']
  265. );
  266. $bTmplVarsButtonIconA = !empty($aButton['icon-a']);
  267. $aTmplVarsButtonIconA = !$bTmplVarsButtonIconA ? array() : array(
  268. 'icon_a' => $aButton['icon-a']
  269. );
  270. $bTmplVarsButtonTitle = !empty($aButton['title']);
  271. $aTmplVarsButtonTitle = !$bTmplVarsButtonTitle ? array() : array(
  272. 'title' => $aButton['title']
  273. );
  274. $sResult .= $this->_oTemplate->parseHtmlByName('designbox_menu_button.html', array(
  275. 'attrs' => bx_convert_array2attrs($aAttrs, 'bx-def-margin-sec-left'),
  276. 'bx_if:show_icon' => array(
  277. 'condition' => $bTmplVarsButtonIcon,
  278. 'content' => $aTmplVarsButtonIcon
  279. ),
  280. 'bx_if:show_icon_a' => array(
  281. 'condition' => $bTmplVarsButtonIconA,
  282. 'content' => $aTmplVarsButtonIconA
  283. ),
  284. 'bx_if:show_title' => array(
  285. 'condition' => $bTmplVarsButtonTitle,
  286. 'content' => $aTmplVarsButtonTitle
  287. )
  288. ));
  289. }
  290. $sResult .= $sPopup;
  291. }
  292. if(!empty($sResult))
  293. $sResult = $this->_oTemplate->parseHtmlByName('designbox_menu.html', array(
  294. 'content' => $sResult
  295. ));
  296. return $sResult;
  297. }
  298. protected function _designBoxMenuId ()
  299. {
  300. return 'bx-menu-db-' . time() . rand(0, PHP_INT_MAX);
  301. }
  302. protected function _designBoxMenuButton ($sMenu, $aParams = array())
  303. {
  304. $sId = $this->_designBoxMenuId();
  305. $aButton = array($this->_sDesignBoxMenuIconType => $this->_sDesignBoxMenuIcon, 'onclick' => $this->_sDesignBoxMenuClick);
  306. if(!empty($aParams)) {
  307. if(!empty($aParams['id']))
  308. $sId = $aParams['id'];
  309. $aButton = array_merge($aButton, $aParams);
  310. }
  311. $aButton['onclick'] = bx_replace_markers($aButton['onclick'], array(
  312. 'design_box_menu' => $sId
  313. ));
  314. return array($aButton, $this->slideBox($sId, $sMenu, true));
  315. }
  316. /**
  317. * Get logo URL.
  318. * @return string
  319. */
  320. function getMainLogoUrl()
  321. {
  322. $oDesigns = BxDolDesigns::getInstance();
  323. $iFileId = (int)$oDesigns->getSiteLogo();
  324. if(!$iFileId)
  325. return false;
  326. $aParams = array();
  327. if(($iLogoWidth = (int)$oDesigns->getSiteLogoWidth()) > 0)
  328. $aParams['x'] = $iLogoWidth;
  329. if(($iLogoHeight = (int)$oDesigns->getSiteLogoHeight()) > 0)
  330. $aParams['y'] = $iLogoHeight;
  331. if(!empty($aParams))
  332. $sFileUrl = BX_DOL_URL_ROOT . bx_append_url_params('image_transcoder.php', array_merge(array('o' => 'sys_custom_images', 'h' => $iFileId), $aParams));
  333. else
  334. $sFileUrl = BxDolTranscoder::getObjectInstance('sys_custom_images')->getFileUrl($iFileId);
  335. return !empty($sFileUrl) ? $sFileUrl : false;
  336. }
  337. /**
  338. * Get logo HTML.
  339. * @return string
  340. */
  341. function getMainLogo($aParams = array())
  342. {
  343. $oDesigns = BxDolDesigns::getInstance();
  344. $sAlt = $oDesigns->getSiteLogoAlt();
  345. if(empty($sAlt))
  346. $sAlt = getParam('site_title');
  347. $sLogo = '<span>' . $sAlt . '</span>';
  348. $sFileUrl = $this->getMainLogoUrl();
  349. if (!empty($sFileUrl)) {
  350. $iLogoWidth = (int)$oDesigns->getSiteLogoWidth();
  351. $sMaxWidth = $iLogoWidth > 0 ? 'max-width:' . round($iLogoWidth/16, 3) . 'rem;' : '';
  352. $iLogoHeight = (int)$oDesigns->getSiteLogoHeight();
  353. $sMaxHeight = $iLogoHeight > 0 ? 'max-height:' . round($iLogoHeight/16, 3) . 'rem;' : '';
  354. $sLogo = '<img style="' . $sMaxWidth . $sMaxHeight . '" src="' . $sFileUrl . '" id="bx-logo" alt="' . bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE) . '" />';
  355. }
  356. $aAttrs = array(
  357. 'class' => 'bx-def-font-contrasted',
  358. 'href' => BX_DOL_URL_ROOT,
  359. 'title' => bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE)
  360. );
  361. if(!empty($aParams['attrs']) && is_array($aParams['attrs']))
  362. $aAttrs = array_merge($aAttrs, $aParams['attrs']);
  363. return '<a' . bx_convert_array2attrs($aAttrs) . '>' . $sLogo . '</a>';
  364. }
  365. /**
  366. * Get HTML code for manifests.
  367. * @return HTML string to insert into HEAD section
  368. */
  369. function getManifests()
  370. {
  371. $sRet = '';
  372. $bLogged = isLogged();
  373. /*
  374. * OneSignal manifest must appear before any other <link rel="manifest" ...> in <head>
  375. */
  376. $sPushAppId = getParam('sys_push_app_id');
  377. if($bLogged && !empty($sPushAppId)) {
  378. $aUrlRoot = parse_url(BX_DOL_URL_ROOT);
  379. $sUrl = BX_DOL_URL_PLUGINS_PUBLIC . 'onesignal/manifest.json.php';
  380. $sUrl = bx_append_url_params($sUrl, array('bx_name' => $aUrlRoot['host']));
  381. $sRet .= '<link rel="manifest" href="' . $sUrl . '" />';
  382. }
  383. return $sRet;
  384. }
  385. /**
  386. * Get HTML code for meta icons.
  387. * @return HTML string to insert into HEAD section
  388. */
  389. function getMetaIcons()
  390. {
  391. $iId = (int)getParam('sys_site_icon');
  392. $sImageUrlFav = $sImageUrlFcb = $sImageUrlApl = '';
  393. if(!empty($iId)) {
  394. // favicon icon
  395. $oTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_FAVICON);
  396. $sImageUrlFav = $oTranscoder->getFileUrl($iId);
  397. // facebook icon
  398. $oTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK);
  399. $sImageUrlFcb = $oTranscoder->getFileUrl($iId);
  400. // apple touch icon
  401. $oTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_APPLE);
  402. $sImageUrlApl = $oTranscoder->getFileUrl($iId);
  403. }
  404. if(empty($sImageUrlFav))
  405. $sImageUrlFav = $this->_oTemplate->getIconUrl('favicon.png');
  406. if(empty($sImageUrlFcb))
  407. $sImageUrlFcb = $this->_oTemplate->getIconUrl('facebook-icon.png');
  408. if(empty($sImageUrlApl))
  409. $sImageUrlApl = $this->_oTemplate->getIconUrl('apple-touch-icon.png');
  410. $sRet = '';
  411. $sRet .= '<link rel="shortcut icon" type="image/x-icon" href="' . $sImageUrlFav . '" />';
  412. $sRet .= '<link rel="image_src" sizes="100x100" href="' . $sImageUrlFcb . '" />';
  413. $sRet .= '<link rel="apple-touch-icon" sizes="152x152" href="' . $sImageUrlApl . '" />';
  414. return $sRet;
  415. }
  416. function getInjectionHead()
  417. {
  418. return $this->getInjection('getInjHead');
  419. }
  420. function getInjectionHeader()
  421. {
  422. return $this->getInjection('getInjHeader');
  423. }
  424. function getInjectionFooter()
  425. {
  426. return $this->getInjection('getInjFooter');
  427. }
  428. public function getPopupAlert()
  429. {
  430. return $this->transBox('bx-popup-alert', $this->_oTemplate->parseHtmlByName('popup_trans_alert_cnt.html', array()), true);
  431. }
  432. public function getPopupConfirm()
  433. {
  434. return $this->transBox('bx-popup-confirm', $this->_oTemplate->parseHtmlByName('popup_trans_confirm_cnt.html', array()), true);
  435. }
  436. public function getPopupPrompt()
  437. {
  438. $sInputText = 'bx-popup-prompt-value';
  439. $aInputText = array(
  440. 'type' => 'text',
  441. 'name' => $sInputText,
  442. 'attrs' => array(
  443. 'id' => $sInputText,
  444. ),
  445. 'value' => '',
  446. 'caption' => ''
  447. );
  448. $oForm = new BxTemplFormView(array(), $this->_oTemplate);
  449. return $this->transBox('bx-popup-prompt', $this->_oTemplate->parseHtmlByName('popup_trans_prompt_cnt.html', array(
  450. 'input' => $oForm->genRow($aInputText)
  451. )), true);
  452. }
  453. /**
  454. * Output time wrapped in <time> tag in HTML.
  455. * Then time is autoformatted using JS upon page load, this is aumatically converted to user's timezone and
  456. * updated in realtime in case of short periods of 'from now' time format.
  457. *
  458. * Short version of this function:
  459. * @see bx_time_js
  460. *
  461. * @param $iUnixTimestamp time as unixtimestamp
  462. * @param $sFormatIdentifier output format identifier
  463. * @see BX_FORMAT_DATE
  464. * @see BX_FORMAT_TIME
  465. * @see BX_FORMAT_DATE_TIME
  466. * @param $bForceFormat force provided format and don't use "from now" time autoformat.
  467. */
  468. function timeForJs ($iUnixTimestamp, $sFormatIdentifier = BX_FORMAT_DATE, $bForceFormat = false)
  469. {
  470. $sDateUTC = bx_time_utc ($iUnixTimestamp);
  471. return $this->timeForJsFullDate ($sDateUTC, $sFormatIdentifier, $bForceFormat);
  472. }
  473. /**
  474. * Same as @see timeForJs but instead of unxtimestamp full date format is used (ex: 2005-08-15T15:52:01) as passec date param
  475. */
  476. function timeForJsFullDate ($sDateUTC, $sFormatIdentifier = BX_FORMAT_DATE, $bForceFormat = false)
  477. {
  478. return '<time datetime="' . $sDateUTC . '" data-bx-format="' . getParam($sFormatIdentifier) . '" data-bx-autoformat="' . ($bForceFormat ? 0 : getParam('sys_format_timeago')) . '">' . $sDateUTC . '</time>';
  479. }
  480. function statusOnOff ($mixed, $isMsg = false)
  481. {
  482. if ((is_bool($mixed) && !$mixed) || (is_string($mixed) && 'fail' == $mixed))
  483. return '<i class="sys-icon circle col-red2"></i> ' . ($isMsg ? _t('_sys_off') : '');
  484. elseif (is_string($mixed) && 'warn' == $mixed)
  485. return '<i class="sys-icon circle col-red3"></i> ' . ($isMsg ? _t('_sys_warn') : '');
  486. elseif (is_string($mixed) && 'undef' == $mixed)
  487. return '<i class="sys-icon circle col-gray"></i> ' . ($isMsg ? _t('_undefined') : '');
  488. else
  489. return '<i class="sys-icon circle col-green1"></i> ' . ($isMsg ? _t('_sys_on') : '');
  490. }
  491. /**
  492. * Ouputs HTML5 video player.
  493. * @param $sUrlPoster video poster image
  494. * @param $sUrlMP4 .mp4 video
  495. * @param $sUrlMP4Hd .mp4 video in better quality
  496. * @param $aAttrs custom attributes, defaults are: controls="" preload="none" autobuffer=""
  497. * @param $sStyles custom styles, defaults are: width:100%; height:auto;
  498. */
  499. function videoPlayer ($sUrlPoster, $sUrlMP4, $sUrlMP4Hd = '', $aAttrs = false, $sStyles = false, $bDynamicMode = false)
  500. {
  501. $oPlayer = BxDolPlayer::getObjectInstance();
  502. if(!$oPlayer)
  503. return '';
  504. if($sStyles === false)
  505. $sStyles = 'width:100%; height:auto;';
  506. return $oPlayer->getCodeVideo (BX_PLAYER_STANDARD, array(
  507. 'poster' => $sUrlPoster,
  508. 'mp4' => array('sd' => $sUrlMP4, 'hd' => $sUrlMP4Hd),
  509. 'attrs' => $aAttrs,
  510. 'styles' => $sStyles,
  511. ), $bDynamicMode);
  512. }
  513. protected function getInjection($sPrefix)
  514. {
  515. $sContent = '';
  516. $aMethods = get_class_methods($this);
  517. foreach($aMethods as $sMethod)
  518. if(preg_match("/^(" . $sPrefix . ")[A-Z].+$/", $sMethod))
  519. $sContent .= $this->$sMethod();
  520. return $sContent;
  521. }
  522. protected function getInjHeadLiveUpdates()
  523. {
  524. return BxDolLiveUpdates::getInstance()->init();
  525. }
  526. protected function getInjHeaderPushNotifications()
  527. {
  528. $iProfileId = bx_get_logged_profile_id();
  529. if(empty($iProfileId))
  530. return '';
  531. $sAppId = getParam('sys_push_app_id');
  532. if(empty($sAppId))
  533. return '';
  534. $aTags = BxDolPush::getTags($iProfileId);
  535. if (!$aTags)
  536. return '';
  537. $sShortName = getParam('sys_push_short_name');
  538. $sSafariWebId = getParam('sys_push_safari_id');
  539. $sSubfolder = '/plugins_public/onesignal/';
  540. $aUrl = parse_url(BX_DOL_URL_ROOT);
  541. if(!empty($aUrl['path'])) {
  542. $sPath = trim($aUrl['path'], '/');
  543. if(!empty($sPath))
  544. $sSubfolder = '/' . $sPath . $sSubfolder;
  545. }
  546. $this->_oTemplate->addJs(array(
  547. 'https://cdn.onesignal.com/sdks/OneSignalSDK.js',
  548. 'BxDolPush.js',
  549. ));
  550. $sJsClass = 'BxDolPush';
  551. $sJsObject = 'oBxDolPush';
  552. $sContent = "var " . $sJsObject . " = new " . $sJsClass . "(" . json_encode(array(
  553. 'sObjName' => $sJsObject,
  554. 'sSiteName' => getParam('site_title'),
  555. 'aTags' => $aTags,
  556. 'sAppId' => $sAppId,
  557. 'sShortName' => $sShortName,
  558. 'sSafariWebId' => $sSafariWebId,
  559. 'sSubfolder' => $sSubfolder,
  560. 'sNotificationUrl' => BX_DOL_URL_ROOT,
  561. 'sTxtNotificationRequest' => _t('_sys_push_notification_request', getParam('site_title')),
  562. 'sTxtNotificationRequestYes' => _t('_sys_push_notification_request_yes'),
  563. 'sTxtNotificationRequestNo' => _t('_sys_push_notification_request_no'),
  564. )) . ");";
  565. return $this->_oTemplate->_wrapInTagJsCode($sContent);
  566. }
  567. protected function getInjHeaderPopupLoading()
  568. {
  569. return $this->transBox('bx-popup-loading', $this->_oTemplate->parsePageByName('popup_loading.html', array()), true);
  570. }
  571. protected function getInjFooterMenuLoading()
  572. {
  573. return $this->_oTemplate->parsePageByName('menu_loading.html', array());
  574. }
  575. protected function getInjFooterPopupMenus()
  576. {
  577. $sContent = '';
  578. $oSearch = new BxTemplSearch();
  579. $oSearch->setLiveSearch(true);
  580. $sContent .= $this->_oTemplate->parsePageByName('search.html', array(
  581. 'search_form' => $oSearch->getForm(BX_DB_CONTENT_ONLY),
  582. 'results' => $oSearch->getResultsContainer(),
  583. ));
  584. $sContent .= $this->_oTemplate->getMenu ('sys_site');
  585. if(isLogged()) {
  586. $sContent .= $this->_oTemplate->getMenu ('sys_add_content');
  587. $sContent .= $this->_oTemplate->getMenu ('sys_account_popup');
  588. }
  589. return $sContent;
  590. }
  591. protected function getInjFooterPopups()
  592. {
  593. $sContent = '';
  594. $sContent .= $this->getPopupAlert();
  595. $sContent .= $this->getPopupConfirm();
  596. $sContent .= $this->getPopupPrompt();
  597. return $sContent;
  598. }
  599. protected function getInjFooterEmbed()
  600. {
  601. // Load embed files
  602. $oEmbed = BxDolEmbed::getObjectInstance(false);
  603. if ($oEmbed)
  604. return $oEmbed->addJsCss();
  605. return '';
  606. }
  607. }
  608. /** @} */