1
0

splash.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. require_once('./inc/header.inc.php');
  10. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  11. bx_import('BxDolLanguages');
  12. class BxDolSplashMenuTop extends BxTemplStudioMenuTop implements iBxDolSingleton
  13. {
  14. function __construct()
  15. {
  16. parent::__construct();
  17. $oTemplate = BxDolStudioTemplate::getInstance();
  18. $this->aVisible[BX_DOL_STUDIO_MT_LEFT] = true;
  19. $this->aVisible[BX_DOL_STUDIO_MT_RIGHT] = true;
  20. $this->aItems[BX_DOL_STUDIO_MT_LEFT] = $oTemplate->parseHtmlByName('splash_logo.html', array());
  21. $this->aItems[BX_DOL_STUDIO_MT_RIGHT] = array(
  22. 'site' => array(
  23. 'name' => 'profile',
  24. 'icon' => 'user',
  25. 'link' => BxDolPermalinks::getInstance()->permalink('page.php?i=create-account'),
  26. 'title' => ''
  27. )
  28. );
  29. }
  30. public static function getInstance()
  31. {
  32. if(!isset($GLOBALS['bxDolClasses']['BxDolSplashMenuTop']))
  33. $GLOBALS['bxDolClasses']['BxDolSplashMenuTop'] = new BxDolSplashMenuTop();
  34. return $GLOBALS['bxDolClasses']['BxDolSplashMenuTop'];
  35. }
  36. }
  37. class BxDolSplashForm extends BxTemplFormView
  38. {
  39. function __construct($oTemplate = false)
  40. {
  41. $aInfo = array(
  42. 'form_attrs' => array(
  43. 'id' => 'sys-splash-domain',
  44. ),
  45. 'params' => array(
  46. 'db' => array(
  47. 'submit_name' => 'domain_submit'
  48. )
  49. ),
  50. 'inputs' => array (
  51. 'domain' => array(
  52. 'type' => 'domain',
  53. 'name' => 'domain',
  54. 'value' => '',
  55. 'value_postfix' => _t('_sys_splash_inp_postfix'),
  56. 'value_button' => _t('_sys_splash_btn_start'),
  57. 'attrs' => array(
  58. 'placeholder' => _t('_sys_splash_inp_placeholder'),
  59. ),
  60. 'db' => array (
  61. 'pass' => 'Xss',
  62. ),
  63. 'checker' => array (
  64. 'func' => 'preg',
  65. 'params' => array('/^[a-z0-9-]{3,}$/'),
  66. 'error' => _t('_sys_splash_err_domain_incorrect'),
  67. ),
  68. ),
  69. )
  70. );
  71. parent::__construct($aInfo, $oTemplate);
  72. }
  73. function isSubmittedAndNotValid ()
  74. {
  75. return $this->isSubmitted() && !$this->isValid();
  76. }
  77. function getNotValid()
  78. {
  79. $aResult = array();
  80. if(!$this->isSubmitted() || $this->isSubmittedAndValid())
  81. return $aResult;
  82. foreach ($this->aInputs as $sKey => $aInput)
  83. $aResult[$sKey] = $aInput['error'];
  84. return $aResult;
  85. }
  86. function genCustomRowDomain($aInput)
  87. {
  88. $sClass = 'bx-form-element-wrapper-' . $aInput['name'] . ' ';
  89. if(isset($aInput['tr_attrs']['class']) && !empty($aInput['tr_attrs']['class']))
  90. $aInput['tr_attrs']['class'] .= ' ' . $sClass;
  91. else
  92. $aInput['tr_attrs']['class'] = $sClass;
  93. return $this->genRowStandard($aInput);
  94. }
  95. function genCustomInputDomain($aInput)
  96. {
  97. $sClass = 'bx-form-input-' . $aInput['name'];
  98. $sClassesText = $sClassesButton = '';
  99. if(isset($aInput['attrs']['class']) && !empty($aInput['attrs']['class'])) {
  100. $sClassesText = $aInput['attrs']['class'] . ' ' . $sClass;
  101. $sClassesButton = $aInput['attrs']['class'] . ' ' . $sClass . '-btn';
  102. } else {
  103. $sClassesText = $sClass;
  104. $sClassesButton = $sClass . '-btn';
  105. }
  106. //--- Text input field
  107. $aText = $aInput;
  108. $aText['type'] = 'text';
  109. $aText['attrs']['class'] = $sClassesText;
  110. $sInput = $this->genInputStandard($aText);
  111. //--- Text value
  112. if(isset($aInput['value_postfix']))
  113. $sInput .= '<div class="' . $sClass . '-txt">' . $aInput['value_postfix'] . '</div>';
  114. //--- Button field
  115. $aButton = $aInput;
  116. $aButton['type'] = 'submit';
  117. $aButton['name'] .= '_submit';
  118. $aButton['value'] = isset($aButton['value_button']) ? $aButton['value_button'] : '';
  119. $aButton['attrs']['class'] = $sClassesButton;
  120. $sInput .= $this->genInputButton($aButton);
  121. return $sInput;
  122. }
  123. function _echoResultJson($a, $isAutoWrapForFormFileSubmit = false)
  124. {
  125. header('Content-type: text/html; charset=utf-8');
  126. $s = json_encode($a);
  127. if($isAutoWrapForFormFileSubmit && !empty($_FILES))
  128. $s = '<textarea>' . $s . '</textarea>';
  129. echo $s;
  130. }
  131. }
  132. function getPageMainCode()
  133. {
  134. $oTemplate = BxDolStudioTemplate::getInstance();
  135. $oTemplate->addJs(array('jquery.form.min.js'));
  136. $oTemplate->addCss(array('splash.css'));
  137. $oForm = new BxDolSplashForm($oTemplate);
  138. $oForm->initChecker();
  139. if($oForm->isSubmittedAndNotValid()) {
  140. $oForm->_echoResultJson(array('err' => $oForm->getNotValid()), true);
  141. exit;
  142. }
  143. if($oForm->isSubmittedAndValid()) {
  144. $sDomainKey = 'domain';
  145. $sDomainValue = $oForm->getCleanValue($sDomainKey);
  146. if(!BxDolRequest::serviceExists('bx_sites', 'is_used')) {
  147. $oForm->_echoResultJson(array('msg' => _t('_sys_splash_err_service_not_available')), true);
  148. exit;
  149. }
  150. if(BxDolService::call('bx_sites', 'is_used', array($sDomainValue))) {
  151. $oForm->_echoResultJson(array('err' => array($sDomainKey => _t('_sys_splash_err_domain_is_used'))), true);
  152. exit;
  153. }
  154. bx_import('BxDolSession');
  155. BxDolSession::getInstance()->setValue('bx_sites_domain', $sDomainValue);
  156. bx_import('BxDolPermalinks');
  157. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=create-account');
  158. $oForm->_echoResultJson(array('eval' => 'window.open(\'' . $sUrl . '\', \'_self\');'), true);
  159. exit;
  160. }
  161. return $oTemplate->parseHtmlByName('splash.html', array(
  162. 'form_id' => $oForm->aFormAttrs['id'],
  163. 'form' => $oForm->getCode()
  164. ));
  165. }
  166. check_logged();
  167. $oTemplate = BxDolStudioTemplate::getInstance();
  168. $oTemplate->setPageNameIndex(BX_PAGE_DEFAULT);
  169. $oTemplate->setPageContent ('menu_top', BxDolSplashMenuTop::getInstance()->getCode());
  170. $oTemplate->setPageContent ('page_main_code', getPageMainCode());
  171. $oTemplate->getPageCode();
  172. /** @} */