BxDolInstallSiteConfig.php 23 KB

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