1
0

BxBaseFunctions.php 33 KB

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