BxBaseFunctions.php 26 KB

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