BxBaseFunctions.php 29 KB

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