BxBaseFunctions.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  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. parent::__construct();
  19. $this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
  20. $this->_sDesignBoxMenuTmplDefault = 'menu_block_submenu_ver.html';
  21. $this->_sDesignBoxMenuIcon = 'ellipsis-v';
  22. $this->_sDesignBoxMenuIconType = 'icon';
  23. $this->_sDesignBoxMenuClick = "bx_menu_popup_inline('#{design_box_menu}', this, " . json_encode(array(
  24. 'moveToDocRoot' => false
  25. )) . ")";
  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. $sClassName = 'BxTemplFunctions';
  38. if ($oTemplate){
  39. $sClassName .= get_class($oTemplate);
  40. }
  41. if(!isset($GLOBALS['bxDolClasses'][$sClassName]))
  42. $GLOBALS['bxDolClasses'][$sClassName] = new BxTemplFunctions($oTemplate);
  43. return $GLOBALS['bxDolClasses'][$sClassName];
  44. }
  45. public static function getInstance()
  46. {
  47. return self::getInstanceWithTemplate(null);
  48. }
  49. function TemplPageAddComponent($sKey)
  50. {
  51. $mixedResult = false; // if you have not such component, return false!
  52. switch($sKey) {
  53. case 'sys_header_width':
  54. $mixedResult = 'bx-def-page-width';
  55. break;
  56. }
  57. return $mixedResult;
  58. }
  59. function msgBox($sText, $iTimer = 0, $sOnClose = "")
  60. {
  61. $iId = time() . mt_rand(1, 1000);
  62. if($iTimer > 0)
  63. BxDolTemplate::getInstance()->addJs(array('jquery.anim.js'));
  64. return $this->_oTemplate->parseHtmlByName('messageBox.html', array(
  65. 'id' => $iId,
  66. 'msgText' => $sText,
  67. 'bx_if:timer' => array(
  68. 'condition' => $iTimer > 0,
  69. 'content' => array(
  70. 'id' => $iId,
  71. 'time' => 1000 * $iTimer,
  72. 'on_close' => $sOnClose,
  73. )
  74. )
  75. ));
  76. }
  77. /**
  78. * Get standard popup box with title.
  79. *
  80. * @param string $sName - unique name
  81. * @param string $sTitle - translated title
  82. * @param string $sContent - content of the box
  83. * @return HTML string
  84. */
  85. function popupBox($sName, $sTitle, $sContent, $isHiddenByDefault = false)
  86. {
  87. $iId = !empty($sName) ? $sName : time();
  88. return $this->_oTemplate->parseHtmlByName('popup_box.html', array(
  89. 'id' => $iId,
  90. 'wrapper_style' => $isHiddenByDefault ? 'display:none;' : '',
  91. 'title' => $sTitle,
  92. 'content' => $sContent
  93. ));
  94. }
  95. /**
  96. * Get popup box without title.
  97. *
  98. * @param string $sName - unique name
  99. * @param string $sContent - content of the box
  100. * @return HTML string
  101. */
  102. function transBox($sName, $sContent, $isHiddenByDefault = false, $isPlaceInCenter = false)
  103. {
  104. return $this->simpleBox($sName, $sContent, $isHiddenByDefault, $isPlaceInCenter, 'popup_trans.html');
  105. }
  106. function slideBox($sName, $sContent, $isHiddenByDefault = false)
  107. {
  108. return $this->simpleBox($sName, $sContent, $isHiddenByDefault, false, 'popup_slide.html');
  109. }
  110. function inlineBox($sName, $sContent, $isHiddenByDefault = false)
  111. {
  112. return $this->simpleBox($sName, $sContent, $isHiddenByDefault, false, 'popup_inline.html');
  113. }
  114. protected function simpleBox($sName, $sContent, $isHiddenByDefault, $isPlaceInCenter, $sTemplate)
  115. {
  116. $iId = !empty($sName) ? $sName : time();
  117. if(!is_array($sContent))
  118. $sContent = array('content' => $sContent);
  119. $sContent = $this->_oTemplate->parseHtmlByName($sTemplate, array_merge(array(
  120. 'id' => $iId,
  121. 'wrapper_class' => '',
  122. 'wrapper_style' => $isHiddenByDefault ? 'display:none;' : '',
  123. 'content' => ''
  124. ), $sContent));
  125. if($isPlaceInCenter)
  126. $sContent = '<div class="login_ajax_wrap">' . $sContent . '</div>';
  127. return $sContent;
  128. }
  129. function simpleBoxContent($sContent, $bWithIndent = true)
  130. {
  131. if(!$bWithIndent)
  132. return $sContent;
  133. return $this->_oTemplate->parseHtmlByName('popup_content_indent.html', array(
  134. 'content' => $sContent
  135. ));
  136. }
  137. function getIcon($sCode, $aAttrs = array())
  138. {
  139. $sIconFont = false;
  140. $sIconA = false;
  141. $sIconUrl = false;
  142. $sIconHtml = false;
  143. $sIconFontWithHtml = false;
  144. $sClass = '';
  145. if(!empty($aAttrs['class'])) {
  146. $sClass = ' ' . $aAttrs['class'] .' ';
  147. unset($aAttrs['class']);
  148. }
  149. $sAttrs = '';
  150. foreach($aAttrs as $sKey => $sValue)
  151. $sAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  152. if (!empty($sCode)) {
  153. if (is_numeric($sCode) && (int)$sCode > 0) {
  154. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  155. $sIconUrl = $oStorage ? $oStorage->getFileUrlById((int)$sCode) : false;
  156. }
  157. else {
  158. if (strpos($sCode, '&lt;img') !== false || strpos($sCode, '<img') !== false) {
  159. if(strpos($sCode, '&lt;img') !== false)
  160. $sIconHtml = htmlspecialchars_decode($sCode);
  161. else
  162. $sIconHtml = $sCode;
  163. //--- Process Inline SVG
  164. } else if (strpos($sCode, '&lt;svg') !== false || strpos($sCode, '<svg') !== false) {
  165. if(strpos($sCode, '&lt;svg') !== false)
  166. $sIconHtml = htmlspecialchars_decode($sCode);
  167. else
  168. $sIconHtml = $sCode;
  169. $sClass .= 'sys-icon sys-icon-svg ';
  170. $sIconHtmlClear = strip_tags($sIconHtml, '<svg>');
  171. if ($sClass != '' && strpos($sIconHtmlClear, 'class="') !== false)
  172. $sIconHtml = str_replace('class="', 'class="' . $sClass, $sIconHtml);
  173. else
  174. $sIconHtml = str_replace('<svg', '<svg class="' . $sClass . '" ', $sIconHtml);
  175. if ($sAttrs != '')
  176. $sIconHtml = str_replace('<svg', '<svg ' . $sAttrs . ' ', $sIconHtml);
  177. }
  178. else {
  179. $sEmojIsRegex =
  180. '/[\x{0080}-\x{02AF}'
  181. .'\x{0300}-\x{03FF}'
  182. .'\x{0600}-\x{06FF}'
  183. .'\x{0C00}-\x{0C7F}'
  184. .'\x{1DC0}-\x{1DFF}'
  185. .'\x{1E00}-\x{1EFF}'
  186. .'\x{2000}-\x{209F}'
  187. .'\x{20D0}-\x{214F}'
  188. .'\x{2190}-\x{23FF}'
  189. .'\x{2460}-\x{25FF}'
  190. .'\x{2600}-\x{27EF}'
  191. .'\x{2900}-\x{29FF}'
  192. .'\x{2B00}-\x{2BFF}'
  193. .'\x{2C60}-\x{2C7F}'
  194. .'\x{2E00}-\x{2E7F}'
  195. .'\x{3000}-\x{303F}'
  196. .'\x{A490}-\x{A4CF}'
  197. .'\x{E000}-\x{F8FF}'
  198. .'\x{FE00}-\x{FE0F}'
  199. .'\x{FE30}-\x{FE4F}'
  200. .'\x{1F000}-\x{1F02F}'
  201. .'\x{1F0A0}-\x{1F0FF}'
  202. .'\x{1F100}-\x{1F64F}'
  203. .'\x{1F680}-\x{1F6FF}'
  204. .'\x{1F910}-\x{1F96B}'
  205. .'\x{1F980}-\x{1F9E0}]/u';
  206. //--- Process Emoji
  207. if(preg_match($sEmojIsRegex, $sCode, $aTmp))
  208. $sIconHtml = $this->_oTemplate->parseHtmlByName('icon_emoji.html', array(
  209. 'icon' => $sCode,
  210. 'class' => $sClass,
  211. 'attrs' => $sAttrs
  212. ));
  213. else {
  214. if (strpos($sCode, '.') === false) {
  215. //--- Process animated icon
  216. if (strncmp($sCode, 'a:', 2) === 0)
  217. $sIconA = substr($sCode, 2);
  218. //--- Process font icons
  219. else {
  220. $sIconFont = $sCode;
  221. $sIconFontWithHtml = $this->getFontIconAsHtml($sIconFont, $sClass, $sAttrs);
  222. }
  223. }
  224. else {
  225. //--- Process common image
  226. if((!preg_match('/^https?:\/\//', $sCode)))
  227. $sIconUrl = $this->_oTemplate->getIconUrl($sCode);
  228. else
  229. $sIconUrl = $sCode;
  230. }
  231. }
  232. }
  233. }
  234. }
  235. return array ($sIconFont, $sIconUrl, $sIconA, $sIconHtml, $sIconFontWithHtml);
  236. }
  237. function getFontIconAsHtml($sIconFont, $sClass = '', $sAttrs = '')
  238. {
  239. return '<i class="sys-icon ' . $sIconFont .' ' . $sClass . '"' . $sAttrs . '></i>';
  240. }
  241. function getIconAsHtml($sCode, $aAttrs = array())
  242. {
  243. $aIcons = $this->getIcon($sCode, $aAttrs);
  244. return $aIcons[3] . $aIcons[4];
  245. }
  246. function getTemplateIcon($sName)
  247. {
  248. $sUrl = $this->_oTemplate->getIconUrl($sName);
  249. return !empty($sUrl) ? $sUrl : $this->_oTemplate->getIconUrl('spacer.gif');
  250. }
  251. function getTemplateImage($sName)
  252. {
  253. $sUrl = $this->_oTemplate->getImageUrl($sName);
  254. return !empty($sUrl) ? $sUrl : $this->_oTemplate->getImageUrl('spacer.gif');
  255. }
  256. function sysIcon ($sIcon, $sName, $sUrl = '', $iWidth = 0)
  257. {
  258. return '<div class="sys_icon">' . ($sUrl ? '<a title="'.$sName.'" href="'.$sUrl.'">' : '') . '<img alt="'.$sName.'" src="'.$sIcon.'" '.($iWidth ? 'width='.$iWidth : '').' />' . ($sUrl ? '</a>' : '') . '</div>';
  259. }
  260. /**
  261. * functions for limiting maximal string length
  262. */
  263. function getStringWithLimitedLength($sString, $iWidth = 45, $isPopupOnOverflow = false, $bReturnString = true)
  264. {
  265. if (empty($sString) || mb_strlen($sString, 'UTF-8') <= $iWidth)
  266. return $bReturnString ? $sString : array($sString);
  267. $sResult = '';
  268. $aWords = mb_split("[\s\r\n]", $sString);
  269. $iPosition = 0;
  270. $iWidthReal = $iWidth - 3;
  271. $iWidthMin = $iWidth - 15;
  272. foreach($aWords as $sWord) {
  273. $sWord = trim($sWord);
  274. $iWord = mb_strlen($sWord, 'UTF-8');
  275. if ($iPosition + $iWord > $iWidthReal)
  276. break;
  277. // add word and continue
  278. $sResult .= ' ' . $sWord;
  279. $iPosition += 1 + $iWord;
  280. }
  281. // last word is too long, cut it
  282. if(!$iPosition || $iPosition < $iWidthMin)
  283. $sResult .= ' ' . mb_substr($sWord, 0, $iWidthReal - $iPosition - $iWord, 'UTF-8');
  284. $sResult = trim($sResult);
  285. // add tripple dot
  286. if(!$isPopupOnOverflow) {
  287. $sResult .= '...';
  288. return $bReturnString ? $sResult : array($sResult);
  289. }
  290. // add button width popup
  291. $sId = 'bx-str-limit-' . rand(1, PHP_INT_MAX);
  292. $sPopup = '<span class="bx-str-limit" onclick="$(\'#' . $sId . '\').dolPopup({pointer:{el:$(this), offset:\'10 1\'}})"/><i class="sys-icon ellipsis-h"></i></span>';
  293. $sPopup .= '<div id="' . $sId . '" style="display:none;">' . BxTemplFunctions::getInstance()->transBox('', '<div class="bx-def-padding bx-def-color-bg-block">'.$sString.'</div>') . '</div>';
  294. return $bReturnString ? $sResult . $sPopup : array($sResult, $sPopup);
  295. }
  296. /**
  297. * Display design box with specified title, template, content and menu.
  298. * @param $sTitle - design box title, please note that some templates don't use title.
  299. * @param $sContent - design box content.
  300. * @param $iTemplateNum - number of design box template, use predefined contants only, default is BX_DB_DEF.
  301. * @param $mixedMenu - design box menu, it can be:
  302. * - object: instance of BxTemplMenu class
  303. * - string: menu object identifier
  304. * - array: array of menu links to create menu from
  305. * @param $mixedButtons - design box menu representation, it can be:
  306. * - false: design box menu will be used as horizontal menu (tabs)
  307. * - 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'.
  308. * @return string
  309. *
  310. * @see BX_DB_CONTENT_ONLY
  311. * @see BX_DB_DEF
  312. * @see BX_DB_EMPTY
  313. * @see BX_DB_NO_CAPTION
  314. * @see BX_DB_PADDING_CONTENT_ONLY
  315. * @see BX_DB_PADDING_DEF
  316. * @see BX_DB_PADDING_NO_CAPTION
  317. */
  318. function designBoxContent ($sTitle, $sContent, $iTemplateNum = BX_DB_DEF, $mixedMenu = false, $mixedButtons = array())
  319. {
  320. return $this->_oTemplate->parseHtmlByName('designbox_' . (int)$iTemplateNum . '.html', array(
  321. 'title' => $sTitle,
  322. 'designbox_content' => $sContent,
  323. 'caption_item' => $this->designBoxMenu($mixedMenu, $mixedButtons),
  324. ));
  325. }
  326. function designBoxMenu ($mixedMenu, $mixedButtons = array())
  327. {
  328. $bUseTabs = is_bool($mixedButtons) && $mixedButtons === true;
  329. $sClass = $sMenu = '';
  330. if(!empty($mixedMenu)) {
  331. if(is_string($mixedMenu)) {
  332. if(($oMenu = BxTemplMenu::getObjectInstance($mixedMenu)) !== false) {
  333. $oMenu->setTemplateById($bUseTabs ? BX_DB_MENU_TEMPLATE_TABS : BX_DB_MENU_TEMPLATE_POPUP);
  334. $sMenu = $oMenu->getCode();
  335. }
  336. else
  337. $sMenu = $mixedMenu;
  338. }
  339. else if(is_array($mixedMenu)) {
  340. if(isset($mixedMenu['template']) && isset($mixedMenu['menu_items']))
  341. $aMenu = $mixedMenu;
  342. else
  343. $aMenu = array('template' => $this->_sDesignBoxMenuTmplDefault, 'menu_items' => $mixedMenu);
  344. if(($oMenu = new BxTemplMenu($aMenu, $this->_oTemplate)) !== false) {
  345. $oMenu->setTemplateById($bUseTabs ? BX_DB_MENU_TEMPLATE_TABS : BX_DB_MENU_TEMPLATE_POPUP);
  346. $sMenu = $oMenu->getCode();
  347. }
  348. else
  349. $sMenu = '';
  350. }
  351. else if(is_object($mixedMenu) && is_a($mixedMenu, 'BxTemplMenu')) {
  352. $mixedMenu->setTemplateById($bUseTabs ? BX_DB_MENU_TEMPLATE_TABS : BX_DB_MENU_TEMPLATE_POPUP);
  353. if(($mixedMenu instanceof BxBaseMenuMoreAuto) && $mixedMenu->isMoreAuto())
  354. $sClass = ' bx-db-menu-tab-more-auto';
  355. $sMenu = $mixedMenu->getCode();
  356. }
  357. }
  358. $bMenu = !empty($sMenu);
  359. $sResult = '';
  360. if($bUseTabs && $bMenu)
  361. $sResult = $sMenu;
  362. else if(is_array($mixedButtons)) {
  363. $sPopup = '';
  364. if($bMenu) {
  365. $aButton = array();
  366. if(empty($mixedButtons))
  367. list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu);
  368. //--- For backward compatibility
  369. else if(!empty($mixedButtons['menu']) && is_array($mixedButtons['menu'])) {
  370. list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu, $mixedButtons['menu']);
  371. unset($mixedButtons['menu']);
  372. }
  373. if(!empty($aButton))
  374. $mixedButtons[] = $aButton;
  375. }
  376. foreach($mixedButtons as $aButton) {
  377. if($bMenu && isset($aButton['menu'])) {
  378. if(is_numeric($aButton['menu']) && (int)$aButton['menu'] == 1)
  379. list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu);
  380. else if(is_array($aButton['menu']))
  381. list($aButton, $sPopup) = $this->_designBoxMenuButton($sMenu, $aButton['menu']);
  382. if(isset($aButton['menu']))
  383. continue;
  384. }
  385. $aAttrs = array();
  386. if(!empty($aButton['onclick']))
  387. $aAttrs['onclick'] = $aButton['onclick'];
  388. $aAttrs['class'] = 'bx-btn bx-btn-small';
  389. if(!empty($aButton['class']))
  390. $aAttrs['class'] .= ' ' . trim($aButton['class']);
  391. $bTmplVarsButtonIcon = !empty($aButton['icon']);
  392. $aTmplVarsButtonIcon = !$bTmplVarsButtonIcon ? array() : array(
  393. 'icon' => $aButton['icon']
  394. );
  395. $bTmplVarsButtonIconA = !empty($aButton['icon-a']);
  396. $aTmplVarsButtonIconA = !$bTmplVarsButtonIconA ? array() : array(
  397. 'icon_a' => $aButton['icon-a']
  398. );
  399. $bTmplVarsButtonTitle = !empty($aButton['title']);
  400. $aTmplVarsButtonTitle = !$bTmplVarsButtonTitle ? array() : array(
  401. 'title' => $aButton['title']
  402. );
  403. $sResult .= $this->_oTemplate->parseHtmlByName('designbox_menu_button.html', array(
  404. 'attrs' => bx_convert_array2attrs($aAttrs),
  405. 'bx_if:show_icon' => array(
  406. 'condition' => $bTmplVarsButtonIcon,
  407. 'content' => $aTmplVarsButtonIcon
  408. ),
  409. 'bx_if:show_icon_a' => array(
  410. 'condition' => $bTmplVarsButtonIconA,
  411. 'content' => $aTmplVarsButtonIconA
  412. ),
  413. 'bx_if:show_title' => array(
  414. 'condition' => $bTmplVarsButtonTitle,
  415. 'content' => $aTmplVarsButtonTitle
  416. )
  417. ));
  418. }
  419. $sResult .= $sPopup;
  420. }
  421. if(!empty($sResult))
  422. $sResult = $this->_oTemplate->parseHtmlByName('designbox_menu.html', array(
  423. 'class' => $sClass,
  424. 'content' => $sResult
  425. ));
  426. return $sResult;
  427. }
  428. protected function _designBoxMenuId ()
  429. {
  430. return 'bx-menu-db-' . time() . rand(0, PHP_INT_MAX);
  431. }
  432. protected function _designBoxMenuButton ($sMenu, $aParams = array())
  433. {
  434. $sId = $this->_designBoxMenuId();
  435. $aButton = array($this->_sDesignBoxMenuIconType => $this->_sDesignBoxMenuIcon, 'onclick' => $this->_sDesignBoxMenuClick);
  436. if(!empty($aParams)) {
  437. if(!empty($aParams['id']))
  438. $sId = $aParams['id'];
  439. $aButton = array_merge($aButton, $aParams);
  440. }
  441. $aButton['onclick'] = bx_replace_markers($aButton['onclick'], array(
  442. 'design_box_menu' => $sId
  443. ));
  444. $sMenu = $this->_oTemplate->parseHtmlByName('designbox_menu_popup.html', array(
  445. 'content' => $sMenu
  446. ));
  447. return array($aButton, $this->transBox($sId, $sMenu, true));
  448. }
  449. /**
  450. * Get logo URL.
  451. * @return string
  452. */
  453. function getMainLogoUrl()
  454. {
  455. return BxDolDesigns::getInstance()->getSiteLogoUrl();
  456. }
  457. /**
  458. * Get mark URL.
  459. * @return string
  460. */
  461. function getMainMarkUrl()
  462. {
  463. return BxDolDesigns::getInstance()->getSiteMarkUrl();
  464. }
  465. /**
  466. * Get logo HTML.
  467. * @return string
  468. */
  469. function getMainLogo($aParams = array())
  470. {
  471. $oDesigns = BxDolDesigns::getInstance();
  472. $sAlt = $oDesigns->getSiteLogoAlt();
  473. if(empty($sAlt))
  474. $sAlt = getParam('site_title');
  475. $aLogoImages = [];
  476. if(($mixedFileUrl = $this->getMainLogoUrl()) && !empty($mixedFileUrl)) {
  477. if(!is_array($mixedFileUrl))
  478. $mixedFileUrl = ['light' => $mixedFileUrl];
  479. foreach($mixedFileUrl as $sName => $sFileUrl) {
  480. $iLogoWidth = (int)$oDesigns->getSiteLogoWidth();
  481. $sWidth = $iLogoWidth > 0 ? 'width:' . round($iLogoWidth/16, 3) . 'rem;' : '';
  482. $iLogoHeight = (int)$oDesigns->getSiteLogoHeight();
  483. $sHeight = $iLogoHeight > 0 ? 'height:' . round($iLogoHeight/16, 3) . 'rem;' : '';
  484. $aLogoImages[] = [
  485. 'id' => 'bx-logo',
  486. 'src' => $sFileUrl,
  487. 'alt' => bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE),
  488. 'style' => $sWidth . ' ' . $sHeight
  489. ];
  490. }
  491. }
  492. $bLogoImages = !empty($aLogoImages) && is_array($aLogoImages);
  493. $aAttrs = array(
  494. 'class' => 'bx-def-font-contrasted',
  495. 'href' => BX_DOL_URL_ROOT,
  496. 'title' => bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE)
  497. );
  498. if(!empty($aParams['attrs']) && is_array($aParams['attrs']))
  499. $aAttrs = array_merge($aAttrs, $aParams['attrs']);
  500. $sTmplName = 'logo_main.html';
  501. $aTmplVars = [
  502. 'attrs' => bx_convert_array2attrs($aAttrs),
  503. 'bx_if:show_title' => [
  504. 'condition' => !$bLogoImages,
  505. 'content' => [
  506. 'logo' => $sAlt,
  507. ]
  508. ],
  509. 'bx_if:show_logo' => [
  510. 'condition' => $bLogoImages,
  511. 'content' => [
  512. 'bx_repeat:images' => $aLogoImages,
  513. ]
  514. ],
  515. ];
  516. bx_alert('system', 'get_logo', 0, 0, [
  517. 'tmpl_name' => &$sTmplName,
  518. 'tmpl_vars' => &$aTmplVars
  519. ]);
  520. return $this->_oTemplate->parseHtmlByName($sTmplName, $aTmplVars);
  521. }
  522. /**
  523. * Get HTML code for manifests.
  524. * @return HTML string to insert into HEAD section
  525. */
  526. function getManifests()
  527. {
  528. return '<link rel="manifest" href="' . BX_DOL_URL_ROOT . 'manifest.json.php" crossorigin="use-credentials" />';
  529. }
  530. /**
  531. * Get HTML code for meta icons.
  532. * @return HTML string to insert into HEAD section
  533. */
  534. function getMetaIcons()
  535. {
  536. // favicon icon
  537. $sImageUrlFav = '';
  538. if(($iId = (int)getParam('sys_site_icon')) != 0)
  539. $sImageUrlFav = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_FILES)->getFileUrlById($iId);
  540. // svg icon
  541. $sImageUrlSvg = '';
  542. if(($iId = (int)getParam('sys_site_icon_svg')) != 0)
  543. $sImageUrlSvg = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->getFileUrlById($iId);
  544. if(empty($sImageUrlFav) && empty($sImageUrlSvg))
  545. $sImageUrlFav = $sImageUrlSvg = $this->_oTemplate->getIconUrl('favicon.svg');
  546. // apple device icon
  547. $sImageUrlApl = '';
  548. if(($iId = (int)getParam('sys_site_icon_apple')) != 0)
  549. $sImageUrlApl = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_APPLE)->getFileUrl($iId);
  550. if(empty($sImageUrlApl))
  551. $sImageUrlApl = $this->_oTemplate->getIconUrl('apple-touch-icon.png');
  552. /*
  553. * TODO:
  554. * 1. Remove commented code later if it won't be used.
  555. * 2. Remove 'sys_icon_favicon' and 'sys_icon_facebook' transcoders and related transcoder filters.
  556. *
  557. // facebook icon
  558. $sImageUrlFcb = '';
  559. $oTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK);
  560. $sImageUrlFcb = $oTranscoder->getFileUrl($iId);
  561. if(empty($sImageUrlFcb))
  562. $sImageUrlFcb = $this->_oTemplate->getIconUrl('facebook-icon.png');
  563. */
  564. $sRet = '';
  565. if($sImageUrlFav)
  566. $sRet .= '<link rel="icon" href="' . $sImageUrlFav . '" sizes="any" />';
  567. if($sImageUrlFav)
  568. $sRet .= '<link rel="icon" href="' . $sImageUrlSvg . '" type="image/svg+xml" />';
  569. $sRet .= '<link rel="apple-touch-icon" href="' . $sImageUrlApl . '" />';
  570. /*
  571. $sRet .= '<link rel="image_src" sizes="100x100" href="' . $sImageUrlFcb . '" />';
  572. */
  573. return $sRet;
  574. }
  575. function getInjectionHead()
  576. {
  577. return $this->getInjection('getInjHead');
  578. }
  579. function getInjectionHeader()
  580. {
  581. return $this->getInjection('getInjHeader');
  582. }
  583. function getInjectionFooter()
  584. {
  585. return $this->getInjection('getInjFooter');
  586. }
  587. public function getPopupAlert()
  588. {
  589. return $this->transBox('bx-popup-alert', $this->_oTemplate->parseHtmlByName('popup_trans_alert_cnt.html', array()), true);
  590. }
  591. public function getPopupConfirm()
  592. {
  593. return $this->transBox('bx-popup-confirm', $this->_oTemplate->parseHtmlByName('popup_trans_confirm_cnt.html', array()), true);
  594. }
  595. public function getPopupPrompt()
  596. {
  597. $sInputText = 'bx-popup-prompt-value';
  598. $aInputText = array(
  599. 'type' => 'text',
  600. 'name' => $sInputText,
  601. 'attrs' => array(
  602. 'id' => $sInputText,
  603. ),
  604. 'value' => '',
  605. 'caption' => ''
  606. );
  607. $oForm = new BxTemplFormView(array(), $this->_oTemplate);
  608. return $this->transBox('bx-popup-prompt', $this->_oTemplate->parseHtmlByName('popup_trans_prompt_cnt.html', array(
  609. 'input' => $oForm->genRow($aInputText)
  610. )), true);
  611. }
  612. /**
  613. * Output time wrapped in <time> tag in HTML.
  614. * Then time is autoformatted using JS upon page load, this is aumatically converted to user's timezone and
  615. * updated in realtime in case of short periods of 'from now' time format.
  616. *
  617. * Short version of this function:
  618. * @see bx_time_js
  619. *
  620. * @param $iUnixTimestamp time as unixtimestamp
  621. * @param $sFormatIdentifier output format identifier
  622. * @see BX_FORMAT_DATE
  623. * @see BX_FORMAT_TIME
  624. * @see BX_FORMAT_DATE_TIME
  625. * @param $bForceFormat force provided format and don't use "from now" time autoformat.
  626. */
  627. function timeForJs ($iUnixTimestamp, $sFormatIdentifier = BX_FORMAT_DATE, $bForceFormat = false)
  628. {
  629. $sDateUTC = bx_time_utc ($iUnixTimestamp);
  630. return $this->timeForJsFullDate ($sDateUTC, $sFormatIdentifier, $bForceFormat);
  631. }
  632. /**
  633. * Same as @see timeForJs but instead of unxtimestamp full date format is used (ex: 2005-08-15T15:52:01) as passec date param
  634. */
  635. function timeForJsFullDate ($sDateUTC, $sFormatIdentifier = BX_FORMAT_DATE, $bForceFormat = false, $bUTC = false)
  636. {
  637. return '<time datetime="' . $sDateUTC . '" data-bx-format="' . getParam($sFormatIdentifier) . '" data-bx-autoformat="' . ($bForceFormat ? 0 : getParam('sys_format_timeago')) . '" data-bx-utc="' . ($bUTC ? 1 : 0) . '">' . $sDateUTC . '</time>';
  638. }
  639. function statusOnOff ($mixed, $isMsg = false)
  640. {
  641. if ((is_bool($mixed) && !$mixed) || (is_string($mixed) && 'fail' == $mixed))
  642. return '<i class="sys-icon circle col-red2"></i> ' . ($isMsg ? _t('_sys_off') : '');
  643. elseif (is_string($mixed) && 'warn' == $mixed)
  644. return '<i class="sys-icon circle col-red3"></i> ' . ($isMsg ? _t('_sys_warn') : '');
  645. elseif (is_string($mixed) && 'undef' == $mixed)
  646. return '<i class="sys-icon circle col-gray"></i> ' . ($isMsg ? _t('_undefined') : '');
  647. else
  648. return '<i class="sys-icon circle col-green1"></i> ' . ($isMsg ? _t('_sys_on') : '');
  649. }
  650. /**
  651. * Ouputs HTML5 video player.
  652. * @param $sUrlPoster video poster image
  653. * @param $sUrlMP4 .mp4 video
  654. * @param $sUrlMP4Hd .mp4 video in better quality
  655. * @param $aAttrs custom attributes, defaults are: controls="" preload="none" autobuffer=""
  656. * @param $sStyles custom styles, defaults are: width:100%; height:auto;
  657. */
  658. function videoPlayer ($sUrlPoster, $sUrlMP4, $sUrlMP4Hd = '', $aAttrs = false, $sStyles = false, $bDynamicMode = false)
  659. {
  660. $oPlayer = BxDolPlayer::getObjectInstance();
  661. if(!$oPlayer)
  662. return '';
  663. if($sStyles === false)
  664. $sStyles = 'width:100%; height:auto;';
  665. return $oPlayer->getCodeVideo (BX_PLAYER_STANDARD, array(
  666. 'poster' => $sUrlPoster,
  667. 'mp4' => array('sd' => $sUrlMP4, 'hd' => $sUrlMP4Hd),
  668. 'attrs' => $aAttrs,
  669. 'styles' => $sStyles,
  670. ), $bDynamicMode);
  671. }
  672. protected function getInjection($sPrefix)
  673. {
  674. $sContent = '';
  675. $aMethods = get_class_methods($this);
  676. foreach($aMethods as $sMethod)
  677. if(preg_match("/^(" . $sPrefix . ")[A-Z].+$/", $sMethod))
  678. $sContent .= $this->$sMethod();
  679. return $sContent;
  680. }
  681. protected function getInjHeadLiveUpdates()
  682. {
  683. $sContent = '';
  684. if(($oLiveUpdates = BxDolLiveUpdates::getInstance()) !== false)
  685. $sContent .= $oLiveUpdates->init();
  686. return $sContent;
  687. }
  688. protected function getInjHeaderPushNotifications()
  689. {
  690. $iProfileId = bx_get_logged_profile_id();
  691. if(empty($iProfileId))
  692. return '';
  693. $sAppId = getParam('sys_push_app_id');
  694. if(empty($sAppId))
  695. return '';
  696. $aTags = BxDolPush::getTags($iProfileId);
  697. if (!$aTags)
  698. return '';
  699. $sShortName = getParam('sys_push_short_name');
  700. $sSafariWebId = getParam('sys_push_safari_id');
  701. $sSubfolder = '/plugins_public/onesignal/';
  702. $aUrl = parse_url(BX_DOL_URL_ROOT);
  703. if(!empty($aUrl['path'])) {
  704. $sPath = trim($aUrl['path'], '/');
  705. if(!empty($sPath))
  706. $sSubfolder = '/' . $sPath . $sSubfolder;
  707. }
  708. $this->_oTemplate->addJs(array(
  709. 'https://cdn.onesignal.com/sdks/OneSignalSDK.js',
  710. 'BxDolPush.js',
  711. ));
  712. $sJsClass = 'BxDolPush';
  713. $sJsObject = 'oBxDolPush';
  714. $sContent = "var " . $sJsObject . " = new " . $sJsClass . "(" . json_encode(array(
  715. 'sObjName' => $sJsObject,
  716. 'sSiteName' => getParam('site_title'),
  717. 'aTags' => $aTags,
  718. 'sAppId' => $sAppId,
  719. 'sShortName' => $sShortName,
  720. 'sSafariWebId' => $sSafariWebId,
  721. 'sSubfolder' => $sSubfolder,
  722. 'sNotificationUrl' => BX_DOL_URL_ROOT,
  723. 'sTxtNotificationRequest' => _t('_sys_push_notification_request', getParam('site_title')),
  724. 'sTxtNotificationRequestYes' => _t('_sys_push_notification_request_yes'),
  725. 'sTxtNotificationRequestNo' => _t('_sys_push_notification_request_no'),
  726. )) . ");";
  727. return $this->_oTemplate->_wrapInTagJsCode($sContent);
  728. }
  729. protected function getInjHeaderPopupLoading()
  730. {
  731. return $this->transBox('bx-popup-loading', $this->_oTemplate->parsePageByName('popup_loading.html', array()), true);
  732. }
  733. protected function getInjFooterMenuLoading()
  734. {
  735. return $this->_oTemplate->parsePageByName('menu_loading.html', array());
  736. }
  737. protected function getInjFooterPopupMenus()
  738. {
  739. $sContent = '';
  740. $oSearch = new BxTemplSearch();
  741. $oSearch->setLiveSearch(true);
  742. $sContent .= $this->_oTemplate->parsePageByName('search.html', array(
  743. 'search_form' => $oSearch->getForm(BX_DB_CONTENT_ONLY),
  744. 'results' => $oSearch->getResultsContainer(),
  745. ));
  746. $sContent .= $this->_oTemplate->getMenu ('sys_site');
  747. if(isLogged()) {
  748. $sContent .= $this->_oTemplate->getMenu ('sys_add_content');
  749. $sContent .= $this->_oTemplate->getMenu ('sys_account_popup');
  750. }
  751. return $sContent;
  752. }
  753. protected function getInjFooterPopupApps()
  754. {
  755. if($this->_oTemplate->getPageType() != BX_PAGE_TYPE_APPLICATION)
  756. return '';
  757. $oMenu = BxDolMenu::getObjectInstance('sys_homepage');
  758. if(!$oMenu)
  759. return '';
  760. $this->_oTemplate->addJs(['popper.js']);
  761. return $this->_oTemplate->parsePageByName('menu_apps.html', [
  762. 'name' => 'sys-menu-apps',
  763. 'title' => _t('_apps'),
  764. 'bx_repeat:menu_items' => $oMenu->getMenuItems(),
  765. ]);
  766. }
  767. protected function getInjFooterPopups()
  768. {
  769. $sContent = '';
  770. $sContent .= $this->getPopupAlert();
  771. $sContent .= $this->getPopupConfirm();
  772. $sContent .= $this->getPopupPrompt();
  773. return $sContent;
  774. }
  775. protected function getInjFooterEmbed()
  776. {
  777. // Load embed files
  778. $oEmbed = BxDolEmbed::getObjectInstance(false);
  779. if ($oEmbed)
  780. return $oEmbed->addJsCss() . $oEmbed->addProcessLinkMethod();
  781. return '';
  782. }
  783. }
  784. /** @} */