BxBaseStudioFunctions.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_DOL_URL_ROOT . 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.position.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, $aNotices = array())
  54. {
  55. $oTemplate = BxDolStudioTemplate::getInstance();
  56. $aMarkers = array(
  57. 'url_root' => BX_DOL_URL_ROOT,
  58. 'url_studio' => BX_DOL_URL_STUDIO,
  59. 'url_studio_icons' => BX_DOL_URL_STUDIO_BASE . 'images/icons/'
  60. );
  61. if(!is_array($mixedWidget))
  62. $mixedWidget = BxDolStudioWidgetsQuery::getInstance()->getWidgets(array('type' => 'by_id', 'value' => (int)$mixedWidget));
  63. if(!empty($mixedWidget['type']) && !BxDolStudioRolesUtils::getInstance()->isActionAllowed('use ' . $mixedWidget['type']))
  64. return '';
  65. $aTmplVarsActions = array();
  66. if(!empty($mixedWidget['cnt_actions'])) {
  67. $aService = unserialize($mixedWidget['cnt_actions']);
  68. $aActions = BxDolService::call($aService['module'], $aService['method'], array_merge(array($mixedWidget), $aService['params']), $aService['class']);
  69. foreach($aActions as $iIndex => $aAction) {
  70. if(!empty($aAction['check_func'])) {
  71. $sCheckFunc = bx_gen_method_name($aAction['check_func']);
  72. if(method_exists($this, $sCheckFunc) && !$this->$sCheckFunc($mixedWidget))
  73. continue;
  74. }
  75. $sActionIcon = $aAction['icon'];
  76. $bActionIcon = strpos($sActionIcon, '.') === false;
  77. if(!$bActionIcon)
  78. $sActionIcon = $oTemplate->getIconUrl($sActionIcon);
  79. $sCaption = _t($aAction['caption']);
  80. $aTmplVarsActions[] = array(
  81. 'name' => !empty($aAction['name']) ? $aAction['name'] : $sPage . '-' . $iIndex,
  82. 'caption' => $sCaption,
  83. 'url' => !empty($aAction['url']) ? bx_replace_markers($aAction['url'], $aMarkers) : 'javascript:void(0)',
  84. 'bx_if:show_click' => array(
  85. 'condition' => !empty($aAction['click']),
  86. 'content' => array(
  87. 'content' => 'javascript:' . $aAction['click'],
  88. )
  89. ),
  90. 'bx_if:action_icon' => array (
  91. 'condition' => $bActionIcon,
  92. 'content' => array('icon' => $sActionIcon, 'caption' => $sCaption),
  93. ),
  94. 'bx_if:action_image' => array (
  95. 'condition' => !$bActionIcon,
  96. 'content' => array('icon_url' => $sActionIcon, 'caption' => $sCaption),
  97. ),
  98. );
  99. }
  100. }
  101. $sIcon = BxDolStudioUtils::getWidgetIcon($mixedWidget);
  102. $bIcon = strpos($sIcon, '.') === false && strcmp(substr($sIcon, 0, 10), 'data:image') != 0;
  103. $sNotices = !empty($aNotices[$mixedWidget['id']]) ? $aNotices[$mixedWidget['id']] : '';
  104. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($mixedWidget['module']);
  105. $bEnabled = empty($aModule) || !is_array($aModule) || (int)$aModule['enabled'] == 1;
  106. return $oTemplate->parseHtmlByName('widget.html', array(
  107. 'id' => $mixedWidget['id'],
  108. 'url' => !empty($mixedWidget['url']) ? bx_replace_markers($mixedWidget['url'], $aMarkers) : 'javascript:void(0)',
  109. 'bx_if:show_click_icon' => array(
  110. 'condition' => !empty($mixedWidget['click']),
  111. 'content' => array(
  112. 'content' => 'javascript:' . $mixedWidget['click'],
  113. )
  114. ),
  115. 'bx_if:show_click_link' => array(
  116. 'condition' => !empty($mixedWidget['click']),
  117. 'content' => array(
  118. 'content' => 'javascript:' . $mixedWidget['click'],
  119. )
  120. ),
  121. 'bx_if:show_notice' => array(
  122. 'condition' => !empty($sNotices),
  123. 'content' => array(
  124. 'content' => $sNotices
  125. )
  126. ),
  127. 'bx_if:show_actions' => array(
  128. 'condition' => !empty($aTmplVarsActions),
  129. 'content' => array(
  130. 'bx_repeat:actions' => $aTmplVarsActions,
  131. )
  132. ),
  133. 'bx_if:icon' => array (
  134. 'condition' => $bIcon,
  135. 'content' => array('icon' => $sIcon),
  136. ),
  137. 'bx_if:image' => array (
  138. 'condition' => !$bIcon,
  139. 'content' => array('icon_url' => $sIcon),
  140. ),
  141. 'caption' => _t($mixedWidget['caption']),
  142. 'widget_disabled_class' => !$bEnabled ? 'bx-std-widget-icon-disabled' : '',
  143. 'widget_featured_class' => (int)$mixedWidget['featured'] == 1 ? 'bx-std-widget-icon-featured' : '',
  144. 'widget_styles' => isset($_COOKIE['bx_studio_featured']) && (int)$_COOKIE['bx_studio_featured'] == 1 && (int)$mixedWidget['featured'] != 1 ? 'display:none;' : ''
  145. ));
  146. }
  147. protected function getInjHeadLiveUpdates()
  148. {
  149. return '';
  150. }
  151. protected function getInjFooterPopupMenus()
  152. {
  153. return '';
  154. }
  155. }
  156. /** @} */