1
0

splash.php 6.7 KB

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