1
0

BxBaseStudioFunctions.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. if(!$bActionIcon)
  83. $sActionIcon = $oTemplate->getIconUrl($sActionIcon);
  84. $sCaption = _t($aAction['caption']);
  85. $aTmplVarsAction = array(
  86. 'name' => !empty($aAction['name']) ? $aAction['name'] : $sPage . '-' . $iIndex,
  87. 'caption' => $sCaption,
  88. 'url' => !empty($aAction['url']) ? bx_replace_markers($aAction['url'], $aMarkers) : 'javascript:void(0)',
  89. 'bx_if:show_click' => array(
  90. 'condition' => !empty($aAction['click']),
  91. 'content' => array(
  92. 'content' => 'javascript:' . $aAction['click'],
  93. )
  94. ),
  95. 'bx_if:action_icon' => array (
  96. 'condition' => $bActionIcon,
  97. 'content' => array('icon' => $sActionIcon, 'caption' => $sCaption),
  98. ),
  99. 'bx_if:action_image' => array (
  100. 'condition' => !$bActionIcon,
  101. 'content' => array('icon_url' => $sActionIcon, 'caption' => $sCaption),
  102. ),
  103. );
  104. if(in_array($aAction['name'], ['settings']))
  105. $aTmplVarsActionsLeft[] = $aTmplVarsAction;
  106. else
  107. $aTmplVarsActionsRight[] = $aTmplVarsAction;
  108. }
  109. }
  110. $sIcon = BxDolStudioUtils::getWidgetIcon($mixedWidget);
  111. $bIcon = strpos($sIcon, '.') === false && strcmp(substr($sIcon, 0, 10), 'data:image') != 0;
  112. $sNotices = !empty($aNotices[$mixedWidget['id']]) ? $aNotices[$mixedWidget['id']] : '';
  113. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($mixedWidget['module']);
  114. $bEnabled = empty($aModule) || !is_array($aModule) || (int)$aModule['enabled'] == 1;
  115. $sCaption = _t($mixedWidget['caption']);
  116. $sStyles = 'animation-delay: -.' . rand(1 , 75) . 's; animation-duration: .' . rand(15 , 20) . 's';
  117. if($bFeatured && (int)$mixedWidget['featured'] != 1)
  118. $sStyles .= ' display:none;';
  119. return $oTemplate->parseHtmlByName('widget.html', array(
  120. 'id' => $mixedWidget['id'],
  121. 'name' => strtolower($sCaption),
  122. 'url' => !empty($mixedWidget['url']) ? bx_replace_markers($mixedWidget['url'], $aMarkers) : 'javascript:void(0)',
  123. 'bx_if:show_click_icon' => array(
  124. 'condition' => !empty($mixedWidget['click']),
  125. 'content' => array(
  126. 'content' => 'javascript:' . $mixedWidget['click'],
  127. )
  128. ),
  129. 'bx_if:show_click_link' => array(
  130. 'condition' => !empty($mixedWidget['click']),
  131. 'content' => array(
  132. 'content' => 'javascript:' . $mixedWidget['click'],
  133. )
  134. ),
  135. 'bx_if:show_notice' => array(
  136. 'condition' => !empty($sNotices),
  137. 'content' => array(
  138. 'content' => $sNotices
  139. )
  140. ),
  141. 'bx_if:show_actions_left' => array(
  142. 'condition' => !empty($aTmplVarsActionsLeft),
  143. 'content' => array(
  144. 'bx_repeat:actions' => $aTmplVarsActionsLeft,
  145. )
  146. ),
  147. 'bx_if:show_actions_right' => array(
  148. 'condition' => !empty($aTmplVarsActionsRight),
  149. 'content' => array(
  150. 'bx_repeat:actions' => $aTmplVarsActionsRight,
  151. )
  152. ),
  153. 'bx_if:icon' => array (
  154. 'condition' => $bIcon,
  155. 'content' => array('icon' => $sIcon),
  156. ),
  157. 'bx_if:image' => array (
  158. 'condition' => !$bIcon,
  159. 'content' => array('icon_url' => $sIcon),
  160. ),
  161. 'caption' => $sCaption,
  162. 'caption_attr' => bx_html_attribute($sCaption),
  163. 'widget_disabled_class' => !$bEnabled ? 'bx-std-widget-icon-disabled' : '',
  164. 'widget_featured_class' => (int)$mixedWidget['featured'] == 1 ? 'bx-std-widget-icon-featured' : '',
  165. 'widget_styles' => $sStyles
  166. ));
  167. }
  168. /*
  169. * Note. For multi upload form field add [] at the end of the field name in $mParams parameter.
  170. */
  171. public function getDefaultGhostTemplate($mParams, $sTemplateName = 'form_ghost_template.html')
  172. {
  173. if (!is_array($mParams))
  174. $mParams = ['name' => $mParams];
  175. return BxDolStudioTemplate::getInstance()->parseHtmlByName($sTemplateName, $mParams);
  176. }
  177. protected function getInjHeadLiveUpdates()
  178. {
  179. return '';
  180. }
  181. protected function getInjFooterPopupMenus()
  182. {
  183. $sResult = '';
  184. $oAccounMenu = BxDolMenu::getObjectInstance('sys_studio_account_popup');
  185. if($oAccounMenu)
  186. $sResult .= $this->transBox('bx-std-pcap-menu-popup-account', $oAccounMenu->getCode(), true);
  187. return $sResult;
  188. }
  189. }
  190. /** @} */