BxBaseFunctions.php 31 KB

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