BxBaseFunctions.php 31 KB

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