BxBaseFunctions.php 30 KB

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