Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.82 KB | None | 0 0
  1. <?php
  2.  
  3. class XenForo_Install_Controller_Install extends XenForo_Install_Controller_Abstract
  4. {
  5. protected function _preDispatch($action)
  6. {
  7. if ($this->_getInstallModel()->isInstalled())
  8. {
  9. throw $this->responseException(
  10. $this->responseError(new XenForo_Phrase('you_have_completed_installation_to_reinstall'))
  11. );
  12. }
  13. }
  14.  
  15. public function actionIndex()
  16. {
  17. $viewParams = array(
  18. 'errors' => $this->_getInstallModel()->getRequirementErrors(),
  19. 'warnings' => $this->_getInstallModel()->getRequirementWarnings()
  20. );
  21.  
  22. return $this->_getInstallWrapper('index',
  23. $this->responseView('XenForo_Install_View_Install_Index', 'install_index', $viewParams)
  24. );
  25. }
  26.  
  27. public function actionStep1()
  28. {
  29. $configFile = XenForo_Application::getInstance()->getConfigDir() . '/config.php';
  30. if (file_exists($configFile))
  31. {
  32. $config = array();
  33. require($configFile);
  34. }
  35. else
  36. {
  37. return $this->actionConfig();
  38. }
  39.  
  40. $viewParams = array(
  41. 'config' => $config,
  42. );
  43.  
  44. return $this->_getInstallWrapper(1,
  45. $this->responseView('XenForo_Install_View_Install_Step1', 'install_step1', $viewParams)
  46. );
  47. }
  48.  
  49. protected function _testConfig(array $config, &$error)
  50. {
  51. $outputConfig = new Zend_Config(array(), true);
  52. $outputConfig
  53. ->merge(XenForo_Application::getInstance()->loadDefaultConfig())
  54. ->merge(new Zend_Config($config));
  55.  
  56. $db = null;
  57.  
  58. try
  59. {
  60. $db = Zend_Db::factory($outputConfig->db->adapter,
  61. array(
  62. 'host' => $outputConfig->db->host,
  63. 'port' => $outputConfig->db->port,
  64. 'username' => $outputConfig->db->username,
  65. 'password' => $outputConfig->db->password,
  66. 'dbname' => $outputConfig->db->dbname,
  67. 'charset' => 'utf8'
  68. )
  69. );
  70. $db->getConnection();
  71. $db->listTables();
  72.  
  73. $error = '';
  74. }
  75. catch (Zend_Db_Exception $e)
  76. {
  77. $error = new XenForo_Phrase('following_error_occurred_while_connecting_database', array('error' => $e->getMessage()));
  78. }
  79.  
  80. return $db;
  81. }
  82.  
  83. public function actionConfig()
  84. {
  85. $config = $this->_input->filterSingle('config', XenForo_Input::JSON_ARRAY);
  86.  
  87. if ($this->_request->isPost())
  88. {
  89. $db = $this->_testConfig($config, $error);
  90. if ($error)
  91. {
  92. return $this->responseError($error);
  93. }
  94.  
  95. $configFile = XenForo_Application::getInstance()->getConfigDir() . '/config.php';
  96. if (!file_exists($configFile) && is_writable(dirname($configFile)))
  97. {
  98. try
  99. {
  100. file_put_contents($configFile, $this->_getInstallModel()->generateConfig($config));
  101. XenForo_Helper_File::makeWritableByFtpUser($configFile);
  102.  
  103. $written = true;
  104. }
  105. catch (Exception $e)
  106. {
  107. $written = false;
  108. }
  109. }
  110. else
  111. {
  112. $written = false;
  113. }
  114.  
  115. $viewParams = array(
  116. 'written' => $written,
  117. 'configFile' => $configFile,
  118. 'config' => $config
  119. );
  120.  
  121. return $this->_getInstallWrapper(1,
  122. $this->responseView('XenForo_Install_View_Install_ConfigGenerated', 'install_config_generated', $viewParams)
  123. );
  124. }
  125. else
  126. {
  127. return $this->_getInstallWrapper(1,
  128. $this->responseView('XenForo_Install_View_Install_Config', 'install_config')
  129. );
  130. }
  131. }
  132.  
  133. public function actionConfigSave()
  134. {
  135. $config = $this->_input->filterSingle('config', XenForo_Input::JSON_ARRAY);
  136.  
  137. $viewParams = array(
  138. 'generated' => $this->_getInstallModel()->generateConfig($config)
  139. );
  140.  
  141. $this->_routeMatch->setResponseType('raw');
  142. return $this->responseView('XenForo_Install_View_Install_ConfigSave', '', $viewParams);
  143. }
  144.  
  145. public function actionStep1b()
  146. {
  147. $configFile = XenForo_Application::getInstance()->getConfigDir() . '/config.php';
  148.  
  149. if (!file_exists($configFile))
  150. {
  151. return $this->responseError(new XenForo_Phrase('config_file_x_could_not_be_found', array('file' => $configFile)));
  152. }
  153.  
  154. $config = array();
  155. require($configFile);
  156.  
  157. $db = $this->_testConfig($config, $error);
  158.  
  159. if ($error)
  160. {
  161. return $this->responseError($error);
  162. }
  163.  
  164. $errors = $this->_getInstallModel()->getRequirementErrors($db);
  165. if ($errors)
  166. {
  167. return $this->responseError($errors);
  168. }
  169.  
  170. if ($db)
  171. {
  172. $db->closeConnection();
  173. $db = XenForo_Application::getDb();
  174. }
  175.  
  176. $viewParams = array(
  177. 'existingInstall' => $this->_getInstallModel()->hasApplicationTables(),
  178. 'warnings' => $this->_getInstallModel()->getRequirementWarnings($db),
  179. 'config' => $config
  180. );
  181.  
  182. return $this->_getInstallWrapper(1,
  183. $this->responseView('XenForo_Install_View_Install_Step1b', 'install_step1b', $viewParams)
  184. );
  185. }
  186.  
  187. public function actionStep2()
  188. {
  189. $this->_assertPostOnly();
  190.  
  191. $installModel = $this->_getInstallModel();
  192.  
  193. $start = $this->_input->filterSingle('start', XenForo_Input::UINT);
  194.  
  195. if (!$start)
  196. {
  197. if ($this->_input->filterSingle('remove', XenForo_Input::UINT))
  198. {
  199. $removed = $installModel->deleteApplicationTables();
  200. }
  201. else
  202. {
  203. if ($installModel->hasApplicationTables())
  204. {
  205. return $this->responseError(new XenForo_Phrase('you_cannot_proceed_unless_tables_removed'));
  206. }
  207.  
  208. $removed = array();
  209. }
  210. }
  211. else
  212. {
  213. $removed = array();
  214. }
  215.  
  216. $installModel->createApplicationTables(5, $start, $endOffset);
  217. if ($endOffset === false)
  218. {
  219. $installModel->insertDefaultData();
  220. $installModel->createDirectories();
  221. }
  222.  
  223. $viewParams = array(
  224. 'removed' => $removed,
  225. 'endOffset' => $endOffset
  226. );
  227.  
  228. return $this->_getInstallWrapper(2,
  229. $this->responseView('XenForo_Install_View_Install_Step2', 'install_step2', $viewParams)
  230. );
  231. }
  232.  
  233. public function actionStep2b()
  234. {
  235. $this->_assertPostOnly();
  236.  
  237. $this->_getInstallModel()->insertDeferredRebuild();
  238.  
  239. return $this->responseReroute(__CLASS__, 'runDeferred');
  240. }
  241.  
  242. public function actionRunDeferred()
  243. {
  244. $output = $this->_manualDeferredRunner('index.php?install/run-deferred', 'index.php?install/step/3');
  245. if ($output instanceof XenForo_ControllerResponse_View)
  246. {
  247. return $this->_getInstallWrapper(2, $output);
  248. }
  249. else
  250. {
  251. return $output;
  252. }
  253. }
  254.  
  255. public function actionStep3()
  256. {
  257. return $this->_getInstallWrapper(3,
  258. $this->responseView('XenForo_Install_View_Install_Step3', 'install_step3')
  259. );
  260. }
  261.  
  262. public function actionStep3b()
  263. {
  264. $this->_assertPostOnly();
  265.  
  266. $input = $this->_input->filter(array(
  267. 'username' => XenForo_Input::STRING,
  268. 'email' => XenForo_Input::STRING,
  269. 'password' => XenForo_Input::STRING,
  270. 'password_confirm' => XenForo_Input::STRING
  271. ));
  272.  
  273. $this->_getInstallModel()->insertAdministrator($input);
  274.  
  275. return $this->responseRedirect(
  276. XenForo_ControllerResponse_Redirect::SUCCESS,
  277. 'index.php?install/step/4'
  278. );
  279. }
  280.  
  281. public function actionStep4()
  282. {
  283. $optionModel = XenForo_Model::create('XenForo_Model_Option');
  284.  
  285. $optionIds = array('boardTitle', 'boardUrl', 'contactEmailAddress', 'homePageUrl');
  286. $optionsRaw = $optionModel->prepareOptions($optionModel->getOptionsByIds($optionIds));
  287. $options = array();
  288. foreach ($optionIds AS $optionId)
  289. {
  290. $options[$optionId] = $optionsRaw[$optionId];
  291. }
  292.  
  293. $paths = XenForo_Application::get('requestPaths');
  294. $options['boardUrl']['option_value'] = preg_replace('#(/install)?/?$#i', '', $paths['fullBasePath']);
  295. $options['homePageUrl']['option_value'] = $paths['protocol'] . '://' . $paths['host'];
  296.  
  297. $user = XenForo_Model::create('XenForo_Model_User')->getUserById(1);
  298. if ($user)
  299. {
  300. $options['contactEmailAddress']['option_value'] = $user['email'];
  301. }
  302.  
  303. $viewParams = array(
  304. 'options' => $options,
  305. 'canEditOptionDefinition' => false
  306. );
  307.  
  308. return $this->_getInstallWrapper(4,
  309. $this->responseView('XenForo_Install_View_Install_Step4', 'install_step4', $viewParams)
  310. );
  311. }
  312.  
  313. public function actionStep4b()
  314. {
  315. $this->_assertPostOnly();
  316.  
  317. $input = $this->_input->filter(array(
  318. 'group_id' => XenForo_Input::STRING,
  319. 'options' => XenForo_Input::ARRAY_SIMPLE,
  320. 'options_listed' => array(XenForo_Input::STRING, array('array' => true))
  321. ));
  322.  
  323. foreach ($input['options_listed'] AS $optionName)
  324. {
  325. if (!isset($input['options'][$optionName]))
  326. {
  327. $input['options'][$optionName] = '';
  328. }
  329. }
  330.  
  331. if (!empty($input['options']['contactEmailAddress']))
  332. {
  333. $input['options']['defaultEmailAddress'] = $input['options']['contactEmailAddress'];
  334. }
  335.  
  336. if (!empty($input['options']['boardUrl']))
  337. {
  338. $input['options']['boardUrl'] = rtrim($input['options']['boardUrl'], '/');
  339. }
  340.  
  341. $xfJsFile = XenForo_Application::getInstance()->getRootDir() . '/js/xenforo/xenforo.js';
  342. if (file_exists($xfJsFile))
  343. {
  344. $xfJs = file_get_contents(XenForo_Application::getInstance()->getRootDir() . '/js/xenforo/xenforo.js');
  345. if (strpos($xfJs, '// _XF_JS_UNCOMPRESSED_TEST_') !== false)
  346. {
  347. $input['options']['uncompressedJs'] = 3;
  348. }
  349. }
  350.  
  351. XenForo_Model::create('XenForo_Model_Option')->updateOptions($input['options']);
  352.  
  353. return $this->responseRedirect(
  354. XenForo_ControllerResponse_Redirect::SUCCESS,
  355. 'index.php?install/complete'
  356. );
  357. }
  358.  
  359. public function actionComplete()
  360. {
  361. $this->_getInstallModel()->completeInstallation();
  362.  
  363. $this->getModelFromCache('XenForo_Model_Deferred')->run(false);
  364.  
  365. return $this->_getInstallWrapper('complete',
  366. $this->responseView('XenForo_Install_View_Install_Complete', 'install_complete')
  367. );
  368. }
  369.  
  370. protected function _getInstallWrapper($step, XenForo_ControllerResponse_View $subView)
  371. {
  372. $params = array(
  373. 'step' => $step
  374. );
  375.  
  376. $view = $this->responseView('XenForo_Install_View_Install_Wrapper', 'install_wrapper', $params);
  377. $view->subView = $subView;
  378.  
  379. return $view;
  380. }
  381.  
  382. protected function _setupSession($action) {}
  383. protected function _handlePost($action) {}
  384.  
  385. /**
  386. * @return XenForo_Install_Model_Install
  387. */
  388. protected function _getInstallModel()
  389. {
  390. return $this->getModelFromCache('XenForo_Install_Model_Install');
  391. }
  392. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement