1
0

BxBaseFunctions.php 27 KB

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