1
0

BxBaseStudioFunctions.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioFunctions extends BxBaseFunctions implements iBxDolSingleton
  11. {
  12. function __construct($oTemplate = false)
  13. {
  14. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  15. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  16. parent::__construct($oTemplate ? $oTemplate : BxDolStudioTemplate::getInstance());
  17. }
  18. public static function getInstance()
  19. {
  20. if (!isset($GLOBALS['bxDolClasses']['BxBaseStudioFunctions']))
  21. $GLOBALS['bxDolClasses']['BxBaseStudioFunctions'] = new BxTemplStudioFunctions();
  22. return $GLOBALS['bxDolClasses']['BxBaseStudioFunctions'];
  23. }
  24. public function getLogo()
  25. {
  26. return bx_idn_to_utf8(BX_DOL_URL_ROOT, true);
  27. }
  28. public function getLoginForm()
  29. {
  30. $oTemplate = BxDolStudioTemplate::getInstance();
  31. $sUrlRelocate = bx_get('relocate');
  32. if (empty($sUrlRelocate) || basename($sUrlRelocate) == 'index.php')
  33. $sUrlRelocate = '';
  34. $sHtml = $oTemplate->parseHtmlByName('login_form.html', array (
  35. 'role' => BX_DOL_ROLE_ADMIN,
  36. 'csrf_token' => BxDolForm::getCsrfToken(),
  37. 'relocate_url' => bx_html_attribute($sUrlRelocate),
  38. 'action_url' => BX_DOL_URL_ROOT . 'member.php',
  39. 'forgot_password_url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password')),
  40. ));
  41. $sHtml = $oTemplate->parseHtmlByName('login.html', array (
  42. 'form' => $this->transBox('bx-std-login-form-box', $sHtml, true),
  43. ));
  44. $oTemplate->setPageNameIndex(BX_PAGE_CLEAR);
  45. $oTemplate->setPageParams(array(
  46. 'css_name' => array('forms.css', 'login.css'),
  47. 'js_name' => array('jquery-ui/jquery-ui.min.js', 'jquery.form.min.js', 'jquery.dolPopup.js', 'login.js'),
  48. 'header' => _t('_adm_page_cpt_login'),
  49. ));
  50. $oTemplate->setPageContent ('page_main_code', $sHtml);
  51. $oTemplate->getPageCode();
  52. }
  53. public function getWidget($mixedWidget, $aParams = array())
  54. {
  55. $oTemplate = BxDolStudioTemplate::getInstance();
  56. $bFeatured = isset($aParams['featured']) && $aParams['featured'] === true;
  57. $aNotices = array();
  58. if(!empty($aParams['notices']) && is_array($aParams['notices']))
  59. $aNotices = $aParams['notices'];
  60. $aMarkers = array(
  61. 'url_root' => BX_DOL_URL_ROOT,
  62. 'url_studio' => BX_DOL_URL_STUDIO,
  63. 'url_studio_icons' => BX_DOL_URL_STUDIO_BASE . 'images/icons/'
  64. );
  65. if(!is_array($mixedWidget))
  66. $mixedWidget = BxDolStudioWidgetsQuery::getInstance()->getWidgets(array('type' => 'by_id', 'value' => (int)$mixedWidget));
  67. if(!empty($mixedWidget['type']) && !BxDolStudioRolesUtils::getInstance()->isActionAllowed('use ' . $mixedWidget['type']))
  68. return '';
  69. $aTmplVarsActions = array();
  70. if(!empty($mixedWidget['cnt_actions'])) {
  71. $aService = unserialize($mixedWidget['cnt_actions']);
  72. $aActions = BxDolService::call($aService['module'], $aService['method'], array_merge(array($mixedWidget), $aService['params']), $aService['class']);
  73. foreach($aActions as $iIndex => $aAction) {
  74. if(!empty($aAction['check_func'])) {
  75. $sCheckFunc = bx_gen_method_name($aAction['check_func']);
  76. if(method_exists($this, $sCheckFunc) && !$this->$sCheckFunc($mixedWidget))
  77. continue;
  78. }
  79. $sActionIcon = $aAction['icon'];
  80. $bActionIcon = strpos($sActionIcon, '.') === false;
  81. if(!$bActionIcon)
  82. $sActionIcon = $oTemplate->getIconUrl($sActionIcon);
  83. $sCaption = _t($aAction['caption']);
  84. $aTmplVarsActions[] = array(
  85. 'name' => !empty($aAction['name']) ? $aAction['name'] : $sPage . '-' . $iIndex,
  86. 'caption' => $sCaption,
  87. 'url' => !empty($aAction['url']) ? bx_replace_markers($aAction['url'], $aMarkers) : 'javascript:void(0)',
  88. 'bx_if:show_click' => array(
  89. 'condition' => !empty($aAction['click']),
  90. 'content' => array(
  91. 'content' => 'javascript:' . $aAction['click'],
  92. )
  93. ),
  94. 'bx_if:action_icon' => array (
  95. 'condition' => $bActionIcon,
  96. 'content' => array('icon' => $sActionIcon, 'caption' => $sCaption),
  97. ),
  98. 'bx_if:action_image' => array (
  99. 'condition' => !$bActionIcon,
  100. 'content' => array('icon_url' => $sActionIcon, 'caption' => $sCaption),
  101. ),
  102. );
  103. }
  104. }
  105. $sIcon = BxDolStudioUtils::getWidgetIcon($mixedWidget);
  106. $bIcon = strpos($sIcon, '.') === false && strcmp(substr($sIcon, 0, 10), 'data:image') != 0;
  107. $sNotices = !empty($aNotices[$mixedWidget['id']]) ? $aNotices[$mixedWidget['id']] : '';
  108. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($mixedWidget['module']);
  109. $bEnabled = empty($aModule) || !is_array($aModule) || (int)$aModule['enabled'] == 1;
  110. $sCaption = _t($mixedWidget['caption']);
  111. return $oTemplate->parseHtmlByName('widget.html', array(
  112. 'id' => $mixedWidget['id'],
  113. 'url' => !empty($mixedWidget['url']) ? bx_replace_markers($mixedWidget['url'], $aMarkers) : 'javascript:void(0)',
  114. 'bx_if:show_click_icon' => array(
  115. 'condition' => !empty($mixedWidget['click']),
  116. 'content' => array(
  117. 'content' => 'javascript:' . $mixedWidget['click'],
  118. )
  119. ),
  120. 'bx_if:show_click_link' => array(
  121. 'condition' => !empty($mixedWidget['click']),
  122. 'content' => array(
  123. 'content' => 'javascript:' . $mixedWidget['click'],
  124. )
  125. ),
  126. 'bx_if:show_notice' => array(
  127. 'condition' => !empty($sNotices),
  128. 'content' => array(
  129. 'content' => $sNotices
  130. )
  131. ),
  132. 'bx_if:show_actions' => array(
  133. 'condition' => !empty($aTmplVarsActions),
  134. 'content' => array(
  135. 'bx_repeat:actions' => $aTmplVarsActions,
  136. )
  137. ),
  138. 'bx_if:icon' => array (
  139. 'condition' => $bIcon,
  140. 'content' => array('icon' => $sIcon),
  141. ),
  142. 'bx_if:image' => array (
  143. 'condition' => !$bIcon,
  144. 'content' => array('icon_url' => $sIcon),
  145. ),
  146. 'caption' => $sCaption,
  147. 'caption_attr' => bx_html_attribute($sCaption),
  148. 'widget_disabled_class' => !$bEnabled ? 'bx-std-widget-icon-disabled' : '',
  149. 'widget_featured_class' => (int)$mixedWidget['featured'] == 1 ? 'bx-std-widget-icon-featured' : '',
  150. 'widget_styles' => $bFeatured && (int)$mixedWidget['featured'] != 1 ? 'display:none;' : ''
  151. ));
  152. }
  153. /*
  154. * Note. For multi upload form field add [] at the end of the field name in $mParams parameter.
  155. */
  156. public function getDefaultGhostTemplate($mParams, $sTemplateName = 'form_ghost_template.html')
  157. {
  158. if (!is_array($mParams))
  159. $mParams = ['name' => $mParams];
  160. return BxDolStudioTemplate::getInstance()->parseHtmlByName($sTemplateName, $mParams);
  161. }
  162. protected function getInjHeadLiveUpdates()
  163. {
  164. return '';
  165. }
  166. protected function getInjFooterPopupMenus()
  167. {
  168. $sResult = '';
  169. $oAccounMenu = BxDolMenu::getObjectInstance('sys_studio_account_popup');
  170. if($oAccounMenu)
  171. $sResult .= $this->transBox('bx-std-pcap-menu-popup-account', $oAccounMenu->getCode(), true);
  172. return $sResult;
  173. }
  174. }
  175. /** @} */