BxDolInstallSiteConfig.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <?php defined('BX_DOL_INSTALL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaInstall UNA Install
  7. * @{
  8. */
  9. define('BX_INSTALL_ERR_GENERAL', 'general');
  10. class BxDolInstallSiteConfig
  11. {
  12. protected $_sSqlDb;
  13. protected $_sSqlAddon;
  14. protected $_sPatternHeader;
  15. protected $_aDbErrorMap;
  16. protected $_aConfig;
  17. protected $_sServerHttpHost;
  18. protected $_sServerPhpSelf;
  19. protected $_sServerDocumentRoot;
  20. protected $_isAutologin;
  21. public function __construct($sServerHttpHost = false, $sServerPhpSelf = false, $sServerDocumentRoot = false, $isAutologin = true)
  22. {
  23. $this->_sServerHttpHost = false === $sServerHttpHost ? $_SERVER['HTTP_HOST'] : $sServerHttpHost;
  24. $this->_sServerPhpSelf = false === $sServerPhpSelf ? $_SERVER['PHP_SELF'] : $sServerPhpSelf;
  25. $this->_sServerDocumentRoot = false === $sServerDocumentRoot ? $_SERVER['DOCUMENT_ROOT'] : $sServerDocumentRoot;
  26. $this->_isAutologin = $isAutologin;
  27. $this->_sSqlDb = BX_INSTALL_DIR . 'sql/system.sql';
  28. $this->_sSqlAddon = BX_INSTALL_DIR . 'sql/addon.sql';
  29. $this->_sPatternHeader = BX_INSTALL_DIR . 'patterns/header.inc.php';
  30. $this->_aDbErrorMap = array (
  31. 'Database connect failed' => array ('fields' => array('db_host', 'db_user', 'db_password'), 'msg' => _t('_sys_inst_msg_db_err_connect')),
  32. 'Database select failed' => array ('fields' => array('db_name'), 'msg' => _t('_sys_inst_msg_db_err_select')),
  33. );
  34. $this->_aConfig = array (
  35. // path config
  36. 'section_site_paths_open' => array(
  37. 'name' => _t('_sys_inst_conf_section_paths'),
  38. 'func' => 'rowSectionOpen',
  39. ),
  40. 'site_url' => array(
  41. 'name' => _t('_sys_inst_conf_field_site_url'),
  42. 'ex' => 'http://www.mydomain.com/path/',
  43. 'desc' => _t('_sys_inst_conf_desc_site_url'),
  44. 'def' => 'http://',
  45. 'def_exp' => array('defUrl', ''),
  46. 'check' => array('checkLength', 10),
  47. ),
  48. 'root_dir' => array(
  49. 'name' => _t('_sys_inst_conf_field_root_dir'),
  50. 'ex' => '/home/mydomain/public_html/',
  51. 'desc' => _t('_sys_inst_conf_desc_root_dir'),
  52. 'def_exp' => array('defPath', ''),
  53. 'check' => array('checkLength', 1),
  54. ),
  55. 'section_site_paths_close' => array(
  56. 'func' => 'rowSectionClose',
  57. ),
  58. // db config
  59. 'section_db_config_open' => array(
  60. 'name' => _t('_sys_inst_conf_section_db_config'),
  61. 'func' => 'rowSectionOpen',
  62. ),
  63. 'db_host' => array(
  64. 'name' => _t('_sys_inst_conf_field_db_host'),
  65. 'ex' => 'localhost',
  66. 'desc' => _t('_sys_inst_conf_desc_db_host'),
  67. 'def' => 'localhost',
  68. 'check' => array('checkLength', 1),
  69. 'db_conf' => 'host',
  70. ),
  71. 'db_port' => array(
  72. 'name' => _t('_sys_inst_conf_field_db_port'),
  73. 'ex' => '5506',
  74. 'desc' => _t('_sys_inst_conf_desc_db_port'),
  75. 'db_conf' => 'port',
  76. ),
  77. 'db_sock' => array(
  78. 'name' => _t('_sys_inst_conf_field_db_sock'),
  79. 'ex' => '/tmp/mysql.sock',
  80. 'desc' => _t('_sys_inst_conf_desc_db_sock'),
  81. 'db_conf' => 'sock',
  82. ),
  83. 'db_name' => array(
  84. 'name' => _t('_sys_inst_conf_field_db_name'),
  85. 'ex' => 'mydomian_tri',
  86. 'desc' => _t('_sys_inst_conf_desc_db_name'),
  87. 'check' => array('checkLength', 1),
  88. 'db_conf' => 'name',
  89. ),
  90. 'db_user' => array(
  91. 'name' => _t('_sys_inst_conf_field_db_user'),
  92. 'ex' => 'mydomian_tri',
  93. 'desc' => _t('_sys_inst_conf_desc_db_user'),
  94. 'check' => array('checkLength', 1),
  95. 'db_conf' => 'user',
  96. ),
  97. 'db_password' => array(
  98. 'name' => _t('_sys_inst_conf_field_db_pwd'),
  99. 'ex' => 'Super*Secret#Word_1234',
  100. 'desc' => _t('_sys_inst_conf_desc_db_pwd'),
  101. 'db_conf' => 'pwd',
  102. ),
  103. 'db_engine' => array(
  104. 'name' => _t('_sys_inst_conf_field_db_engine'),
  105. 'ex' => 'INNODB',
  106. 'desc' => _t('_sys_inst_conf_desc_db_engine'),
  107. 'def' => 'MYISAM',
  108. ),
  109. 'section_db_config_close' => array(
  110. 'func' => 'rowSectionClose',
  111. ),
  112. // site config
  113. 'section_site_info_open' => array(
  114. 'name' => _t('_sys_inst_conf_section_site_info'),
  115. 'func' => 'rowSectionOpen',
  116. ),
  117. 'site_title' => array(
  118. 'name' => _t('_sys_inst_conf_field_site_title'),
  119. 'ex' => 'The Best Community',
  120. 'desc' => _t('_sys_inst_conf_desc_site_title'),
  121. 'check' => array('checkLength', 1),
  122. ),
  123. 'site_email' => array(
  124. 'name' => _t('_sys_inst_conf_field_site_email'),
  125. 'ex' => 'no-reply@youdomain.here',
  126. 'desc' => _t('_sys_inst_conf_desc_site_email'),
  127. 'check' => array('checkEmail', 3),
  128. ),
  129. 'admin_email' => array(
  130. 'name' => _t('_sys_inst_conf_field_admin_email'),
  131. 'ex' => 'admin@email.here',
  132. 'desc' => _t('_sys_inst_conf_desc_admin_email'),
  133. 'check' => array('checkEmail', 3),
  134. ),
  135. 'admin_username' => array(
  136. 'name' => _t('_sys_inst_conf_field_admin_username'),
  137. 'ex' => 'admin',
  138. 'desc' => _t('_sys_inst_conf_desc_admin_username'),
  139. 'check' => array('checkLength', 1),
  140. ),
  141. 'admin_password' => array(
  142. 'name' => _t('_sys_inst_conf_field_admin_pwd'),
  143. 'ex' => 'Super*Secret#Word_1234',
  144. 'desc' => _t('_sys_inst_conf_desc_admin_pwd'),
  145. 'check' => array('checkLength', 1),
  146. ),
  147. 'section_site_info_close' => array(
  148. 'func' => 'rowSectionClose',
  149. ),
  150. // link with boonex market
  151. 'section_link_to_market_open' => array(
  152. 'name' => _t('_sys_inst_conf_section_link_with_market'),
  153. 'func' => 'rowSectionOpen',
  154. ),
  155. 'oauth_key' => array(
  156. 'name' => _t('_sys_inst_conf_field_oauth_key'),
  157. 'ex' => '123abc4d',
  158. 'desc' => _t('_sys_inst_conf_desc_oauth_key_secret'),
  159. 'check' => array('checkLengthExactOrEmpty', 10),
  160. ),
  161. 'oauth_secret' => array(
  162. 'name' => _t('_sys_inst_conf_field_oauth_secret'),
  163. 'ex' => '45de12368a9b367abc23512a',
  164. 'desc' => _t('_sys_inst_conf_desc_oauth_key_secret'),
  165. 'check' => array('checkLengthExactOrEmpty', 32),
  166. ),
  167. 'section_link_to_market_close' => array(
  168. 'func' => 'rowSectionClose',
  169. ),
  170. // modules
  171. 'section_modules_open' => array(
  172. 'name' => _t('_sys_inst_conf_section_modules'),
  173. 'func' => 'rowSectionOpen',
  174. ),
  175. BX_DOL_MODULE_TYPE_LANGUAGE => array(
  176. 'name' => _t('_sys_inst_conf_field_language'),
  177. 'desc' => _t('_sys_inst_conf_desc_language'),
  178. 'def' => isset($_COOKIE['lang']) ? $_COOKIE['lang'] : (isset($_GET['lang']) ? $_GET['lang'] : 'en'),
  179. 'func' => 'rowSelect',
  180. 'vals' => $this->getSelectValues(BX_DOL_MODULE_TYPE_LANGUAGE),
  181. ),
  182. BX_DOL_MODULE_TYPE_TEMPLATE => array(
  183. 'name' => _t('_sys_inst_conf_field_template'),
  184. 'desc' => _t('_sys_inst_conf_desc_template'),
  185. 'def' => 'artificer',
  186. 'func' => 'rowSelect',
  187. 'vals' => $this->getSelectValues(BX_DOL_MODULE_TYPE_TEMPLATE),
  188. ),
  189. BX_DOL_MODULE_TYPE_MODULE => array(
  190. 'name' => _t('_sys_inst_conf_field_profiles'),
  191. 'desc' => _t('_sys_inst_conf_desc_profiles'),
  192. 'def' => 'persons',
  193. 'func' => 'rowSelect',
  194. 'vals' => $this->getSelectValues(BX_DOL_MODULE_TYPE_MODULE),
  195. ),
  196. 'section_modules_close' => array(
  197. 'func' => 'rowSectionClose',
  198. ),
  199. );
  200. }
  201. public function getAutoValues($aData = array())
  202. {
  203. $aRet = array();
  204. foreach($this->_aConfig as $sKey => $a) {
  205. $sAutoMessage = '';
  206. $aRet[$sKey] = $this->def ($aData, $sKey, $a, $sAutoMessage);
  207. }
  208. return $aRet;
  209. }
  210. public function getFormHtml($aData = false, $bRedirectOnSuccess = true, &$sOutputErrorMessage = null)
  211. {
  212. if (false === $aData)
  213. $aData = $_POST;
  214. $aErrorFields = array();
  215. if (isset($aData['site_config'])) {
  216. $aErrorFields = $this->processConfigData($this->processInputData($aData));
  217. if (empty($aErrorFields)) {
  218. if ($bRedirectOnSuccess) {
  219. $sHost = $this->_sServerHttpHost;
  220. $sUri = rtrim(dirname($this->_sServerPhpSelf), '/\\');
  221. $sPage = 'index.php?action=finish';
  222. $sProto = $this->proto();
  223. header("Location: {$sProto}{$sHost}{$sUri}/{$sPage}");
  224. exit;
  225. } else {
  226. return true;
  227. }
  228. }
  229. }
  230. $sErrorMessage = '';
  231. if (isset($aErrorFields[BX_INSTALL_ERR_GENERAL]) && $aErrorFields[BX_INSTALL_ERR_GENERAL]) {
  232. $sErrorMessage = '<div class="bx-install-error-message bx-def-padding bx-def-margin-bottom">' . $aErrorFields[BX_INSTALL_ERR_GENERAL] . '</div>';
  233. if (null !== $sOutputErrorMessage)
  234. $sOutputErrorMessage = $aErrorFields[BX_INSTALL_ERR_GENERAL] . (empty($aErrorFields) ? '' : ' / Fields: ' . join(',', array_keys($aErrorFields)));
  235. }
  236. $sRows = $this->getFormFields($aErrorFields, $aData);
  237. $sSubmitTitle = _t('_Submit');
  238. return <<<EOF
  239. {$sErrorMessage}
  240. <form method="post">
  241. <div class="bx-form-advanced-wrapper sys_account_wrapper">
  242. {$sRows}
  243. <div class="bx-form-element-wrapper bx-def-margin-top">
  244. <div class="bx-form-value">
  245. <div class="bx-form-input-wrapper bx-form-input-wrapper-submit">
  246. <button class="bx-def-font-inputs bx-form-input-submit bx-btn bx-btn-primary" type="submit" name="site_config" value="1">
  247. {$sSubmitTitle}
  248. </button>
  249. </div>
  250. </div>
  251. </div>
  252. </div>
  253. <form>
  254. EOF;
  255. }
  256. public function processConfigData ($a)
  257. {
  258. $aSteps = array('checkConfig', 'processConfigDataDb', 'processConfigDataHeader', 'processModules');
  259. foreach ($aSteps as $sFunc) {
  260. $aErrors = $this->{$sFunc} ($a);
  261. if (!empty($aErrors))
  262. return $aErrors;
  263. }
  264. return array();
  265. }
  266. protected function checkConfig($a)
  267. {
  268. $aErrorFields = array();
  269. foreach ($this->_aConfig as $sKey => $r) {
  270. if (!$this->check ($sKey, isset($a[$sKey]) ? $a[$sKey] : '', $r))
  271. $aErrorFields[$sKey] = true;
  272. }
  273. if (!empty($aErrorFields))
  274. $aErrorFields[BX_INSTALL_ERR_GENERAL] = _t('_sys_inst_msg_form_error');
  275. return $aErrorFields;
  276. }
  277. public function processConfigDataDb ($a)
  278. {
  279. $aDbConf = array ('error_checking' => false);
  280. foreach ($this->_aConfig as $sKey => $r)
  281. if (isset($this->_aConfig[$sKey]['db_conf']))
  282. $aDbConf[$this->_aConfig[$sKey]['db_conf']] = $a[$sKey];
  283. if ('INNODB' == getenv('UNA_DB_ENGINE'))
  284. $aDbConf['storage_engine'] = 'INNODB';
  285. $sErrorMessage = '';
  286. $oDb = BxDolDb::getInstanceWithConf($aDbConf, $sErrorMessage);
  287. if (!$oDb) {
  288. $aErrorFields = array();
  289. if (isset($this->_aDbErrorMap[$sErrorMessage])) {
  290. foreach ($this->_aDbErrorMap[$sErrorMessage]['fields'] as $sField)
  291. $aErrorFields[$sField] = true;
  292. $aErrorFields[BX_INSTALL_ERR_GENERAL] = $this->_aDbErrorMap[$sErrorMessage]['msg'];
  293. } else {
  294. $aErrorFields[BX_INSTALL_ERR_GENERAL] = $sErrorMessage;
  295. }
  296. return $aErrorFields;
  297. }
  298. $mixedRes = $oDb->executeSQL($this->_sSqlDb);
  299. if (true !== $mixedRes)
  300. return $this->dbErrors2ErrorFields($mixedRes);
  301. $mixedRes = $oDb->executeSQL($this->_sSqlAddon, $this->getMarkersForDb($a, $oDb));
  302. if (true !== $mixedRes)
  303. return $this->dbErrors2ErrorFields($mixedRes);
  304. $aSqlDirs = array(
  305. BX_INSTALL_DIR . 'sql/',
  306. BX_INSTALL_DIR_MODULES . 'system/install/sql/',
  307. );
  308. foreach ($aSqlDirs as $sSqlDir) {
  309. if (!is_dir($sSqlDir))
  310. continue;
  311. $aFiles = scandir($sSqlDir);
  312. foreach ($aFiles as $sFile) {
  313. if ($sFile[0] === '.' || $sFile === 'system.sql' || $sFile === 'addon.sql') {
  314. continue;
  315. }
  316. $sFilePath = $sSqlDir . $sFile;
  317. if (is_file($sFilePath)) {
  318. $mixedRes = $oDb->executeSQL($sFilePath, $this->getMarkersForDb($a, $oDb));
  319. if (true !== $mixedRes) {
  320. return $this->dbErrors2ErrorFields($mixedRes);
  321. }
  322. }
  323. }
  324. }
  325. return array();
  326. }
  327. public function processConfigDataHeader ($a)
  328. {
  329. $aMarkers = $this->getMarkersForPhp($a);
  330. $sFile = $this->_sPatternHeader;
  331. $sHeader = file_get_contents($sFile);
  332. if (false === $sHeader)
  333. return array(BX_INSTALL_ERR_GENERAL => _t('_sys_inst_msg_file_read_failed', $sFile));
  334. $sHeader = str_replace(array_keys($aMarkers), array_values($aMarkers), $sHeader);
  335. if (false === file_put_contents(BX_INSTALL_PATH_HEADER, $sHeader))
  336. return array(BX_INSTALL_ERR_GENERAL => _t('_sys_inst_msg_file_write_failed', BX_INSTALL_PATH_HEADER));
  337. @chmod(BX_INSTALL_PATH_HEADER, 0666);
  338. if (function_exists('opcache_invalidate')) opcache_invalidate(BX_INSTALL_PATH_HEADER);
  339. return array();
  340. }
  341. public function processModules ($a)
  342. {
  343. require_once(BX_INSTALL_PATH_HEADER);
  344. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  345. $aTypes = array (BX_DOL_MODULE_TYPE_LANGUAGE, BX_DOL_MODULE_TYPE_TEMPLATE, BX_DOL_MODULE_TYPE_MODULE);
  346. foreach ($aTypes as $sModuleType) {
  347. if (empty($a[$sModuleType]))
  348. continue;
  349. $sErrorMessage = $this->processModuleByUri ($a[$sModuleType], array ('install', 'enable'), $sModuleType);
  350. if ($sErrorMessage)
  351. return array(BX_INSTALL_ERR_GENERAL => $sErrorMessage);
  352. }
  353. bx_import('BxDolAccount');
  354. $oAccount = BxDolAccount::getInstance($a['admin_email']);
  355. if (!$oAccount)
  356. return array(BX_INSTALL_ERR_GENERAL => _t('_sys_inst_msg_admin_account_not_found', $a['admin_email']));
  357. if ($this->_isAutologin)
  358. bx_login($oAccount->id());
  359. return array();
  360. }
  361. public function processModuleByUri ($sModuleUri, $aActions = array ('install', 'enable'), $sModuleType = null)
  362. {
  363. return $this->processModuleByField('home_uri', $sModuleUri, $aActions, $sModuleType);
  364. }
  365. public function processModuleByName ($sModuleName, $aActions = array ('install', 'enable'), $sModuleType = null)
  366. {
  367. return $this->processModuleByField('name', $sModuleName, $aActions, $sModuleType);
  368. }
  369. protected function processModuleByField ($sField, $sModuleUri, $aActions = array ('install', 'enable'), $sModuleType = null)
  370. {
  371. if (!file_exists(BX_INSTALL_PATH_HEADER))
  372. return _t('_sys_inst_msg_script_isnt_installed');
  373. bx_import('BxDolStudioInstallerUtils');
  374. bx_import('BxDolLanguages');
  375. BxDolLanguages::getInstance();
  376. $oModulesTools = new BxDolInstallModulesTools();
  377. $aModules = $oModulesTools->getModules($sModuleType);
  378. foreach ($aModules as $aConfig) {
  379. if ($sModuleUri != $aConfig[$sField])
  380. continue;
  381. foreach ($aActions as $sAction) {
  382. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aConfig['home_dir'], $sAction);
  383. if ((!isset($aResult['code']) || $aResult['code']) && !empty($aResult['message']))
  384. return _t('_sys_inst_msg_module_error', $aConfig['title'], $aResult['message']);
  385. }
  386. }
  387. return '';
  388. }
  389. protected function dbErrors2ErrorFields ($a)
  390. {
  391. $s = '';
  392. foreach ($a as $r)
  393. $s = $r['error'] . ': <br />' . $r['query'] . '<br />';
  394. return array(BX_INSTALL_ERR_GENERAL => $s);
  395. }
  396. protected function processInputData ($a)
  397. {
  398. foreach ($a as $sKey => $mixedValue)
  399. $a[$sKey] = bx_process_input($mixedValue);
  400. return $a;
  401. }
  402. protected function getMarkers($a)
  403. {
  404. $aMarkers = array();
  405. foreach($this->_aConfig as $sKey => $r)
  406. $aMarkers[$sKey] = isset($a[$sKey]) ? $a[$sKey] : '';
  407. $aMarkers['admin_pwd_salt'] = genRndPwd();
  408. $aMarkers['admin_pwd_hash'] = encryptUserPwd($a['admin_password'], $aMarkers['admin_pwd_salt']);
  409. $aMarkers['current_timestamp'] = time();
  410. $aMarkers['version'] = BX_DOL_VER;
  411. $aMarkers['time'] = time();
  412. $aMarkers['secret'] = genRndPwd(11);
  413. $aMarkers['ffmpeg_path'] = $aMarkers['root_dir'] . 'plugins/ffmpeg/ffmpeg.exe';
  414. $aJava = explode(' ', str_replace('java: ', '', trim(`whereis java`)));
  415. $aMarkers['java_path'] = isset($aJava[0]) && $aJava[0] && !is_dir($aJava[0]) ? $aJava[0] : '';
  416. return $aMarkers;
  417. }
  418. protected function getMarkersForDb($a, $oDb)
  419. {
  420. $a = $this->getMarkers($a);
  421. $aMarkers = array();
  422. foreach ($a as $sKey => $mixedVal) {
  423. $aMarkers['from'][] = '{' . $sKey . '}';
  424. $aMarkers['to'][] = $oDb->escape($mixedVal);
  425. }
  426. return $aMarkers;
  427. }
  428. protected function getMarkersForPhp($a)
  429. {
  430. $a = $this->getMarkers($a);
  431. $aMarkers = array();
  432. foreach ($a as $sKey => $mixedVal)
  433. $aMarkers['%' . strtoupper($sKey) . '%'] = bx_php_string_apos($mixedVal);
  434. return $aMarkers;
  435. }
  436. protected function getFormFields($aErrorFields, $aData)
  437. {
  438. $s = '';
  439. foreach($this->_aConfig as $sKey => $a) {
  440. $sFunc = isset($a['func']) ? $a['func'] : 'rowInput';
  441. $s .= $this->$sFunc($aData, $sKey, $a, isset($aErrorFields[$sKey]) ? $aErrorFields[$sKey] : false);
  442. }
  443. return $s;
  444. }
  445. protected function rowInput ($aData, $sKey, $a, $isError = false)
  446. {
  447. $sAutoMessage = '';
  448. $sValue = bx_html_attribute($this->def ($aData, $sKey, $a, $sAutoMessage));
  449. $sInput = '<input type="text" name="' . $sKey. '" value="' . $sValue . '" class="bx-def-font-inputs bx-form-input-text" />';
  450. return $this->rowWrapper ($aData, $sInput, $sAutoMessage, 'text', $sKey, $a, $isError);
  451. }
  452. protected function rowSelect ($aData, $sKey, $a, $isError = false)
  453. {
  454. $sAutoMessage = '';
  455. $sValue = bx_html_attribute($this->def ($aData, $sKey, $a, $sAutoMessage));
  456. $sValues = '';
  457. foreach ($a['vals'] as $sVal => $sTitle)
  458. $sValues .= '<option value="' . $sVal . '" ' . ($sVal == $sValue ? 'selected="selected"' : '') . '>' . $sTitle . '</option>';
  459. $sInput = '<select name="' . $sKey . '" class="bx-def-font-inputs bx-form-input-select">' . $sValues . '</select>';
  460. return $this->rowWrapper ($aData, $sInput, $sAutoMessage, 'select', $sKey, $a, $isError);
  461. }
  462. protected function rowWrapper ($aData, $sInput, $sAutoMessage, $sType, $sKey, $a, $isError = false)
  463. {
  464. $sDesc = _t('_sys_inst_conf_desc', $sAutoMessage, $a['desc'], isset($a['ex']) ? $a['ex'] : _t('_sys_inst_conf_no_example'));
  465. $sError = '';
  466. if ($isError)
  467. $sError = '<div class="bx-form-warn">' . _t('_sys_inst_conf_error') . '</div>';
  468. $sRequired = '';
  469. if (isset($a['check']) && $a['check'])
  470. $sRequired = '<span class="bx-form-required">*</span>';
  471. return <<<EOF
  472. <div class="bx-form-element-wrapper bx-def-margin-top-auto">
  473. <div class="bx-form-caption">
  474. {$a['name']}
  475. {$sRequired}
  476. </div>
  477. <div class="bx-form-value">
  478. <div class="bx-form-input-wrapper bx-form-input-wrapper-{$sType}">
  479. $sInput
  480. </div>
  481. $sError
  482. <div class="bx-form-info bx-def-font-grayed bx-def-font-small">
  483. {$sDesc}
  484. </div>
  485. </div></div>
  486. EOF;
  487. }
  488. protected function rowSectionOpen ($aData, $sKey, $a)
  489. {
  490. return <<<EOF
  491. <div class="bx-form-section-wrapper bx-def-margin-top">
  492. <fieldset class="bx-form-section bx-def-padding-sec-top bx-def-border-top bx-form-section-header">
  493. <legend class="bx-def-padding-sec-right bx-def-font-grayed bx-def-font-h3">{$a['name']}</legend>
  494. <div class="bx-form-section-content bx-def-padding-top bx-def-padding-bottom">
  495. EOF;
  496. }
  497. protected function rowSectionClose ($aData, $sKey, $a)
  498. {
  499. return <<<EOF
  500. </div>
  501. </fieldset>
  502. </div>
  503. EOF;
  504. }
  505. protected function check ($sKey, $sValue, $a)
  506. {
  507. if (empty($a['check']))
  508. return true;
  509. return $this->{$a['check'][0]}($sValue, $a['check'][1]);
  510. }
  511. protected function checkLength ($s, $i)
  512. {
  513. return mb_strlen($s) >= $i ? true : false;
  514. }
  515. protected function checkLengthExactOrEmpty ($s, $i)
  516. {
  517. return empty($s) || mb_strlen($s) == $i;
  518. }
  519. protected function checkEmail ($s, $i)
  520. {
  521. return mb_strlen($s) > $i && false !== strpos($s, '@') ? true : false;
  522. }
  523. protected function def ($aData, $sKey, $a, &$sAutoMessage)
  524. {
  525. if (isset($aData[$sKey]))
  526. return bx_process_pass($aData[$sKey]);
  527. elseif (false !== getenv('UNA_' . strtoupper($sKey)))
  528. return bx_process_pass(getenv('UNA_' . strtoupper($sKey)));
  529. elseif (!empty($a['def_exp'])) {
  530. $s = $this->{$a['def_exp'][0]}($a['def_exp'][1]);
  531. if ($s) {
  532. $sAutoMessage = _t('_sys_inst_conf_found') . '<br />';
  533. return $s;
  534. } else {
  535. $sAutoMessage = _t('_sys_inst_conf_not_found') . '<br />';
  536. }
  537. }
  538. return isset($a['def']) ? $a['def'] : '';
  539. }
  540. protected function defUrl ($foo)
  541. {
  542. $s = $this->proto() . $this->_sServerHttpHost . $this->_sServerPhpSelf;
  543. return preg_replace("/install\/(index\.php$)/", '', $s);
  544. }
  545. protected function defPath ($foo)
  546. {
  547. $s = rtrim($this->_sServerDocumentRoot, '/') . $this->_sServerPhpSelf;
  548. return preg_replace("/install\/(index\.php$)/", '', $s);
  549. }
  550. protected function getSelectValues($sType)
  551. {
  552. $a = array();
  553. $oModulesTools = new BxDolInstallModulesTools();
  554. $aModules = $oModulesTools->getModules($sType);
  555. foreach ($aModules as $sName => $aConfig)
  556. $a[$aConfig['home_uri']] = $aConfig['title'];
  557. return $a;
  558. }
  559. protected function proto()
  560. {
  561. $sProto = 'http://';
  562. if (
  563. (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) ||
  564. (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == strtolower($_SERVER['HTTP_X_FORWARDED_PROTO'])) ||
  565. getenv('UNA_HTTPS')
  566. )
  567. $sProto = 'https://';
  568. return $sProto;
  569. }
  570. }
  571. /** @} */