/install/actions/action_options.php

https://github.com/dmi3yy/modx.evo.custom · PHP · 265 lines · 217 code · 15 blank · 33 comment · 40 complexity · 95887fa0db805c3295816077a52d6738 MD5 · raw file

  1. <?php
  2. $installMode = isset($_POST['installmode']) ? (int)$_POST['installmode'] : 0;
  3. if( ! function_exists('getTemplates')) {
  4. /**
  5. * @param array $presets
  6. * @return string
  7. */
  8. function getTemplates($presets = array())
  9. {
  10. if (empty($presets)) {
  11. return '';
  12. }
  13. $selectedTemplates = isset ($_POST['template']) ? $_POST['template'] : array();
  14. $tpl = '<label><input type="checkbox" name="template[]" value="[+i+]" class="[+class+]" [+checked+] />[%install_update%] <span class="comname">[+name+]</span> - [+desc+]</label><hr />';
  15. $_ = array();
  16. $i = 0;
  17. $ph = array();
  18. foreach ($presets as $preset) {
  19. $ph['i'] = $i;
  20. $ph['name'] = isset($preset[0]) ? $preset[0] : '';
  21. $ph['desc'] = isset($preset[1]) ? $preset[1] : '';
  22. $ph['class'] = !in_array('sample', $preset[6]) ? 'toggle' : 'toggle demo';
  23. $ph['checked'] = in_array($i, $selectedTemplates) || (!isset($_POST['options_selected'])) ? 'checked' : '';
  24. $_[] = parse($tpl, $ph);
  25. $i++;
  26. }
  27. return (0 < count($_)) ? '<h3>[%templates%]</h3>' . implode("\n", $_) : '';
  28. }
  29. }
  30. if( ! function_exists('getTVs')) {
  31. /**
  32. * @param array $presets
  33. * @return string
  34. */
  35. function getTVs($presets = array())
  36. {
  37. if (empty($presets)) {
  38. return '';
  39. }
  40. $selectedTvs = isset ($_POST['tv']) ? $_POST['tv'] : array();
  41. $tpl = '<label><input type="checkbox" name="tv[]" value="[+i+]" class="[+class+]" [+checked+] />[%install_update%] <span class="comname">[+name+]</span> - [+alterName+] <span class="description">([+desc+])</span></label><hr />';
  42. $_ = array();
  43. $i = 0;
  44. $ph = array();
  45. foreach ($presets as $preset) {
  46. $ph['i'] = $i;
  47. $ph['name'] = $preset[0];
  48. $ph['alterName'] = $preset[1];
  49. $ph['desc'] = $preset[2];
  50. $ph['class'] = !in_array('sample', $preset[12]) ? 'toggle' : 'toggle demo';
  51. $ph['checked'] = in_array($i, $selectedTvs) || (!isset($_POST['options_selected'])) ? 'checked' : '';
  52. $_[] = parse($tpl, $ph);
  53. $i++;
  54. }
  55. return (0 < count($_)) ? '<h3>[%tvs%]</h3>' . implode("\n", $_) : '';
  56. }
  57. }
  58. if( ! function_exists('getChunks')) {
  59. /**
  60. * display chunks
  61. *
  62. * @param array $presets
  63. * @return string
  64. */
  65. function getChunks($presets = array())
  66. {
  67. if (empty($presets)) {
  68. return '';
  69. }
  70. $selected = isset ($_POST['chunk']) ? $_POST['chunk'] : array();
  71. $tpl = '<label><input type="checkbox" name="chunk[]" value="[+i+]" class="[+class+]" [+checked+] />[%install_update%] <span class="comname">[+name+]</span> - [+desc+]</label><hr />';
  72. $_ = array();
  73. $i = 0;
  74. $ph = array();
  75. foreach ($presets as $preset) {
  76. $ph['i'] = $i;
  77. $ph['name'] = $preset[0];
  78. $ph['desc'] = $preset[1];
  79. $ph['class'] = !in_array('sample', $preset[5]) ? 'toggle' : 'toggle demo';
  80. $ph['checked'] = in_array($i, $selected) || (!isset($_POST['options_selected'])) ? 'checked' : '';
  81. $_[] = parse($tpl, $ph);
  82. $i++;
  83. }
  84. return (0 < count($_)) ? '<h3>[%chunks%]</h3>' . implode("\n", $_) : '';
  85. }
  86. }
  87. if( ! function_exists('getModules')) {
  88. /**
  89. * display modules
  90. *
  91. * @param array $presets
  92. * @return string
  93. */
  94. function getModules($presets = array())
  95. {
  96. if (empty($presets)) {
  97. return '';
  98. }
  99. $selected = isset ($_POST['module']) ? $_POST['module'] : array();
  100. $tpl = '<label><input type="checkbox" name="module[]" value="[+i+]" class="[+class+]" [+checked+] />[%install_update%] <span class="comname">[+name+]</span> - [+desc+]</label><hr />';
  101. $_ = array();
  102. $i = 0;
  103. $ph = array();
  104. foreach ($presets as $preset) {
  105. $ph['i'] = $i;
  106. $ph['name'] = $preset[0];
  107. $ph['desc'] = $preset[1];
  108. $ph['class'] = !in_array('sample', $preset[7]) ? 'toggle' : 'toggle demo';
  109. $ph['checked'] = in_array($i, $selected) || (!isset($_POST['options_selected'])) ? 'checked' : '';
  110. $_[] = parse($tpl, $ph);
  111. $i++;
  112. }
  113. return (0 < count($_)) ? '<h3>[%modules%]</h3>' . implode("\n", $_) : '';
  114. }
  115. }
  116. if( ! function_exists('getPlugins')) {
  117. /**
  118. * display plugins
  119. *
  120. * @param array $presets
  121. * @return string
  122. */
  123. function getPlugins($presets = array())
  124. {
  125. if (!count($presets)) {
  126. return '';
  127. }
  128. $selected = isset ($_POST['plugin']) ? $_POST['plugin'] : array();
  129. $tpl = '<label><input type="checkbox" name="plugin[]" value="[+i+]" class="[+class+]" [+checked+] />[%install_update%] <span class="comname">[+name+]</span> - [+desc+]</label><hr />';
  130. $_ = array();
  131. $i = 0;
  132. $ph = array();
  133. foreach ($presets as $preset) {
  134. $ph['i'] = $i;
  135. $ph['name'] = $preset[0];
  136. $ph['desc'] = $preset[1];
  137. if (is_array($preset[8])) {
  138. $ph['class'] = !in_array('sample', $preset[8]) ? 'toggle' : 'toggle demo';
  139. } else {
  140. $ph['class'] = 'toggle demo';
  141. }
  142. $ph['checked'] = in_array($i, $selected) || (!isset($_POST['options_selected'])) ? 'checked' : '';
  143. $_[] = parse($tpl, $ph);
  144. $i++;
  145. }
  146. return (0 < count($_)) ? '<h3>[%plugins%]</h3>' . implode("\n", $_) : '';
  147. }
  148. }
  149. if( ! function_exists('getSnippets')) {
  150. /**
  151. * display snippets
  152. *
  153. * @param array $presets
  154. * @return string
  155. */
  156. function getSnippets($presets = array())
  157. {
  158. if (!count($presets)) {
  159. return '';
  160. }
  161. $selected = isset ($_POST['snippet']) ? $_POST['snippet'] : array();
  162. $tpl = '<label><input type="checkbox" name="snippet[]" value="[+i+]" class="[+class+]" [+checked+] />[%install_update%] <span class="comname">[+name+]</span> - [+desc+]</label><hr />';
  163. $_ = array();
  164. $i = 0;
  165. $ph = array();
  166. foreach ($presets as $preset) {
  167. $ph['i'] = $i;
  168. $ph['name'] = $preset[0];
  169. $ph['desc'] = $preset[1];
  170. $ph['class'] = !in_array('sample', $preset[5]) ? 'toggle' : 'toggle demo';
  171. $ph['checked'] = in_array($i, $selected) || (!isset($_POST['options_selected'])) ? 'checked' : '';
  172. $_[] = parse($tpl, $ph);
  173. $i++;
  174. }
  175. return (0 < count($_)) ? '<h3>[%snippets%]</h3>' . implode("\n", $_) : '';
  176. }
  177. }
  178. switch($installMode){
  179. case 0:
  180. case 2:
  181. $database_collation = isset($_POST['database_collation']) ? $_POST['database_collation'] : 'utf8_general_ci';
  182. $database_charset = substr($database_collation, 0, strpos($database_collation, '_'));
  183. $_POST['database_connection_charset'] = $database_charset;
  184. if(!empty($_POST['databaseloginpassword']))
  185. $_SESSION['databaseloginpassword'] = $_POST['databaseloginpassword'];
  186. if(!empty($_POST['databaseloginname']))
  187. $_SESSION['databaseloginname'] = $_POST['databaseloginname'];
  188. break;
  189. case 1:
  190. include $base_path . MGR_DIR . '/includes/config.inc.php';
  191. $host = explode(':', $database_server, 2);
  192. if (@ $conn = mysqli_connect($host[0], $database_user, $database_password,'', isset($host[1]) ? $host[1] : null)) {
  193. if (@ mysqli_query($conn, "USE {$dbase}")) {
  194. if (!$rs = mysqli_query($conn, "show session variables like 'collation_database'")) {
  195. $rs = mysqli_query($conn, "show session variables like 'collation_server'");
  196. }
  197. if ($rs && $collation = mysqli_fetch_row($rs)) {
  198. $database_collation = trim($collation[1]);
  199. }
  200. }
  201. }
  202. if (empty ($database_collation)) $database_collation = 'utf8_general_ci';
  203. $database_charset = substr($database_collation, 0, strpos($database_collation, '_'));
  204. if (!isset ($database_connection_charset) || empty ($database_connection_charset)) {
  205. $database_connection_charset = $database_charset;
  206. }
  207. if (!isset ($database_connection_method) || empty ($database_connection_method)) {
  208. $database_connection_method = 'SET CHARACTER SET';
  209. if (function_exists('mysqli_set_charset')) mysqli_set_charset($conn, $database_connection_charset);
  210. }
  211. if ($database_connection_method != 'SET NAMES' && $database_connection_charset != $database_charset) {
  212. $database_connection_method = 'SET NAMES';
  213. }
  214. $_POST['database_name'] = $dbase;
  215. $_POST['tableprefix'] = $table_prefix;
  216. $_POST['database_connection_charset'] = $database_connection_charset;
  217. $_POST['database_connection_method'] = $database_connection_method;
  218. $_POST['databasehost'] = $database_server;
  219. $_SESSION['databaseloginname'] = $database_user;
  220. $_SESSION['databaseloginpassword'] = $database_password;
  221. break;
  222. default:
  223. throw new Exception('installmode is undefined');
  224. }
  225. $ph['install_language'] = $install_language;
  226. $ph['manager_language'] = $manager_language;
  227. $ph['installMode'] = $installMode;
  228. $ph['database_name'] = trim($_POST['database_name'], '`');
  229. $ph['tableprefix'] = $_POST['tableprefix'];
  230. $ph['database_collation'] = $_POST['database_collation'];
  231. $ph['database_connection_charset'] = $_POST['database_connection_charset'];
  232. $ph['database_connection_method'] = $_POST['database_connection_method'];
  233. $ph['databasehost'] = $_POST['databasehost'];
  234. $ph['cmsadmin'] = trim($_POST['cmsadmin']);
  235. $ph['cmsadminemail'] = trim($_POST['cmsadminemail']);
  236. $ph['cmspassword'] = trim($_POST['cmspassword']);
  237. $ph['cmspasswordconfirm'] = trim($_POST['cmspasswordconfirm']);
  238. $ph['checked'] = isset ($_POST['installdata']) && $_POST['installdata'] == "1" ? 'checked' : '';
  239. # load setup information file
  240. include($base_path . 'install/setup.info.php');
  241. $ph['templates'] = getTemplates($moduleTemplates);
  242. $ph['tvs'] = getTVs($moduleTVs);
  243. $ph['chunks'] = getChunks($moduleChunks);
  244. $ph['modules'] = getModules($moduleModules);
  245. $ph['plugins'] = getPlugins($modulePlugins);
  246. $ph['snippets'] = getSnippets($moduleSnippets);
  247. $ph['action'] = ($installMode == 1) ? 'mode' : 'connection';
  248. $tpl = file_get_contents($base_path . 'install/actions/tpl_options.html');
  249. $content = parse($tpl,$ph);
  250. echo parse($content,$_lang,'[%','%]');