1
0

BxBaseStudioFunctions.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 = bx_srv_ii($aService['module'], $aService['method'], array_merge(array($mixedWidget), $aService['params']), $aService['class']);
  73. $aTmplVarsActionsLeft = $aTmplVarsActionsRight = [];
  74. foreach($aActions as $iIndex => $aAction) {
  75. if(!empty($aAction['check_func'])) {
  76. $sCheckFunc = bx_gen_method_name($aAction['check_func']);
  77. if(method_exists($this, $sCheckFunc) && !$this->$sCheckFunc($mixedWidget))
  78. continue;
  79. }
  80. $sActionIcon = $aAction['icon'];
  81. $bActionIcon = strpos($sActionIcon, '.') === false;
  82. $bActionIconInline = !$bActionIcon;
  83. if($bActionIconInline && ($sActionIcon = $oTemplate->getIconContent($sActionIcon)) === false) {
  84. $sActionIcon = $oTemplate->getIconUrl($sActionIcon);
  85. $bActionIconInline = false;
  86. }
  87. $sCaption = _t($aAction['caption']);
  88. $aTmplVarsAction = [
  89. 'name' => !empty($aAction['name']) ? $aAction['name'] : $sPage . '-' . $iIndex,
  90. 'caption' => $sCaption,
  91. 'url' => !empty($aAction['url']) ? bx_replace_markers($aAction['url'], $aMarkers) : 'javascript:void(0)',
  92. 'bx_if:show_click' => [
  93. 'condition' => !empty($aAction['click']),
  94. 'content' => [
  95. 'content' => 'javascript:' . $aAction['click'],
  96. ]
  97. ],
  98. 'bx_if:action_icon' => [
  99. 'condition' => $bActionIcon,
  100. 'content' => ['name' => $sActionIcon, 'caption' => $sCaption],
  101. ],
  102. 'bx_if:action_image' => [
  103. 'condition' => !$bActionIcon && !$bActionIconInline,
  104. 'content' => ['url' => $sActionIcon, 'caption' => $sCaption],
  105. ],
  106. 'bx_if:action_image_inline' => [
  107. 'condition' => !$bActionIcon && $bActionIconInline,
  108. 'content' => ['content' => $sActionIcon],
  109. ],
  110. ];
  111. if(in_array($aAction['name'], ['settings']))
  112. $aTmplVarsActionsLeft[] = $aTmplVarsAction;
  113. else
  114. $aTmplVarsActionsRight[] = $aTmplVarsAction;
  115. }
  116. }
  117. $sIcon = BxDolStudioUtils::getWidgetIcon($mixedWidget);
  118. $bIcon = strpos($sIcon, '.') === false && strcmp(substr($sIcon, 0, 10), 'data:image') != 0;
  119. $sNotices = !empty($aNotices[$mixedWidget['id']]) ? $aNotices[$mixedWidget['id']] : '';
  120. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($mixedWidget['module']);
  121. $bEnabled = empty($aModule) || !is_array($aModule) || (int)$aModule['enabled'] == 1;
  122. $sCaption = _t($mixedWidget['caption']);
  123. $sStyles = 'animation-delay: -.' . rand(1 , 75) . 's; animation-duration: .' . rand(15 , 20) . 's';
  124. if($bFeatured && (int)$mixedWidget['featured'] != 1)
  125. $sStyles .= ' display:none;';
  126. return $oTemplate->parseHtmlByName('widget.html', array(
  127. 'id' => $mixedWidget['id'],
  128. 'name' => strtolower($sCaption),
  129. 'url' => !empty($mixedWidget['url']) ? bx_replace_markers($mixedWidget['url'], $aMarkers) : 'javascript:void(0)',
  130. 'bx_if:show_click_icon' => array(
  131. 'condition' => !empty($mixedWidget['click']),
  132. 'content' => array(
  133. 'content' => 'javascript:' . $mixedWidget['click'],
  134. )
  135. ),
  136. 'bx_if:show_click_link' => array(
  137. 'condition' => !empty($mixedWidget['click']),
  138. 'content' => array(
  139. 'content' => 'javascript:' . $mixedWidget['click'],
  140. )
  141. ),
  142. 'bx_if:show_notice' => array(
  143. 'condition' => !empty($sNotices),
  144. 'content' => array(
  145. 'content' => $sNotices
  146. )
  147. ),
  148. 'bx_if:show_actions_left' => array(
  149. 'condition' => !empty($aTmplVarsActionsLeft),
  150. 'content' => array(
  151. 'bx_repeat:actions' => $aTmplVarsActionsLeft,
  152. )
  153. ),
  154. 'bx_if:show_actions_right' => array(
  155. 'condition' => !empty($aTmplVarsActionsRight),
  156. 'content' => array(
  157. 'bx_repeat:actions' => $aTmplVarsActionsRight,
  158. )
  159. ),
  160. 'bx_if:icon' => array (
  161. 'condition' => $bIcon,
  162. 'content' => array('icon' => $sIcon),
  163. ),
  164. 'bx_if:image' => array (
  165. 'condition' => !$bIcon,
  166. 'content' => array('icon_url' => $sIcon),
  167. ),
  168. 'caption' => $sCaption,
  169. 'caption_attr' => bx_html_attribute($sCaption),
  170. 'widget_disabled_class' => !$bEnabled ? 'bx-std-widget-icon-disabled' : '',
  171. 'widget_featured_class' => (int)$mixedWidget['featured'] == 1 ? 'bx-std-widget-icon-featured' : '',
  172. 'widget_styles' => $sStyles
  173. ));
  174. }
  175. /*
  176. * Note. For multi upload form field add [] at the end of the field name in $mParams parameter.
  177. */
  178. public function getDefaultGhostTemplate($mParams, $sTemplateName = 'form_ghost_template.html')
  179. {
  180. if (!is_array($mParams))
  181. $mParams = ['name' => $mParams];
  182. return BxDolStudioTemplate::getInstance()->parseHtmlByName($sTemplateName, $mParams);
  183. }
  184. protected function getInjHeadLiveUpdates()
  185. {
  186. return '';
  187. }
  188. protected function getInjFooterPopupMenus()
  189. {
  190. $sResult = '';
  191. $oMenuScheme = new BxTemplStudioMenu(['template' => 'menu_vertical_lite.html', 'menu_items' => [
  192. ['name' => 'scheme-auto', 'class' => 'auto', 'icon' => 'tmi-scheme-auto.svg', 'link' => 'javascript:void(0)', 'onclick' => '{js_object}.setColorScheme(this, 0);', 'title' => _t('_sys_menu_item_title_sa_scheme_auto')],
  193. ['name' => 'scheme-light', 'class' => 'light', 'icon' => 'tmi-scheme-light.svg', 'link' => 'javascript:void(0)', 'onclick' => '{js_object}.setColorScheme(this, 1);', 'title' => _t('_sys_menu_item_title_sa_scheme_light')],
  194. ['name' => 'scheme-dark', 'class' => 'dark', 'icon' => 'tmi-scheme-dark.svg', 'link' => 'javascript:void(0)', 'onclick' => '{js_object}.setColorScheme(this, 2);', 'title' => _t('_sys_menu_item_title_sa_scheme_dark')]
  195. ]]);
  196. $oMenuScheme->setInlineIcons(true);
  197. $oMenuScheme->addMarkers([
  198. 'js_object' => BxTemplStudioMenuTop::getInstance()->getJsObject()
  199. ]);
  200. $sResult .= $this->transBox('bx-std-pcap-menu-popup-scheme', $oMenuScheme->getCode(), true);
  201. $oAccounMenu = BxDolMenu::getObjectInstance('sys_studio_account_popup');
  202. if($oAccounMenu)
  203. $sResult .= $this->transBox('bx-std-pcap-menu-popup-account', $oAccounMenu->getCode(), true);
  204. return $sResult;
  205. }
  206. }
  207. /** @} */