BxBaseFunctions.php 22 KB

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