PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Backend/Core/Installer/CoreInstaller.php

http://github.com/forkcms/forkcms
PHP | 209 lines | 174 code | 17 blank | 18 comment | 6 complexity | 07836b8d7570f00d5e586d1364caaf0d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, MIT, AGPL-3.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. namespace Backend\Core\Installer;
  3. /**
  4. * Installer for the core
  5. */
  6. class CoreInstaller extends ModuleInstaller
  7. {
  8. public function install(): void
  9. {
  10. // validate variables
  11. if ($this->getVariable('default_language') === null) {
  12. throw new \SpoonException('Default frontend language is not provided.');
  13. }
  14. if ($this->getVariable('default_interface_language') === null) {
  15. throw new \SpoonException('Default backend language is not provided.');
  16. }
  17. if ($this->getVariable('site_domain') === null) {
  18. throw new \SpoonException('Site domain is not provided.');
  19. }
  20. if ($this->getVariable('spoon_debug_email') === null) {
  21. throw new \SpoonException('Spoon debug email is not provided.');
  22. }
  23. if ($this->getVariable('site_title') === null) {
  24. throw new \SpoonException('Site title is not provided.');
  25. }
  26. // import SQL
  27. $this->importSQL(__DIR__ . '/Data/install.sql');
  28. // add core modules
  29. $this->addModule('Core');
  30. $this->addModule('Authentication');
  31. $this->addModule('Dashboard');
  32. $this->addModule('Error');
  33. $this->setRights();
  34. $this->configureDefaultSettings();
  35. // add core navigation
  36. $this->setNavigation(null, 'Dashboard', 'dashboard/index', null, 1);
  37. $this->setNavigation(null, 'Modules', null, null, 4);
  38. }
  39. private function setRights(): void
  40. {
  41. $this->setModuleRights(1, 'Dashboard');
  42. $this->setActionRights(1, 'Dashboard', 'Index');
  43. }
  44. private function configureDefaultSettings(): void
  45. {
  46. // languages settings
  47. $this->setSetting('Core', 'languages', $this->getLanguages(), true);
  48. $this->setSetting('Core', 'active_languages', $this->getLanguages(), true);
  49. $this->setSetting('Core', 'redirect_languages', $this->getLanguages(), true);
  50. $this->setSetting('Core', 'default_language', $this->getVariable('default_language'), true);
  51. $this->setSetting('Core', 'interface_languages', $this->getInterfaceLanguages(), true);
  52. $this->setSetting('Core', 'default_interface_language', $this->getVariable('default_interface_language'), true);
  53. // other settings
  54. $this->setSetting('Core', 'theme');
  55. $this->setSetting('Core', 'akismet_key', '');
  56. $this->setSetting('Core', 'google_maps_key', '');
  57. $this->setSetting('Core', 'max_num_revisions', 20);
  58. $this->setSetting('Core', 'site_domains', [$this->getVariable('site_domain')]);
  59. $this->setSetting('Core', 'site_html_header', '');
  60. $this->setSetting('Core', 'site_html_footer', '');
  61. // date & time
  62. $this->setSetting('Core', 'date_format_short', 'j.n.Y');
  63. $this->setSetting(
  64. 'Core',
  65. 'date_formats_short',
  66. [
  67. 'j/n/Y',
  68. 'j-n-Y',
  69. 'j.n.Y',
  70. 'n/j/Y',
  71. 'n/j/Y',
  72. 'n/j/Y',
  73. 'd/m/Y',
  74. 'd-m-Y',
  75. 'd.m.Y',
  76. 'm/d/Y',
  77. 'm-d-Y',
  78. 'm.d.Y',
  79. 'j/n/y',
  80. 'j-n-y',
  81. 'j.n.y',
  82. 'n/j/y',
  83. 'n-j-y',
  84. 'n.j.y',
  85. 'd/m/y',
  86. 'd-m-y',
  87. 'd.m.y',
  88. 'm/d/y',
  89. 'm-d-y',
  90. 'm.d.y',
  91. ]
  92. );
  93. $this->setSetting('Core', 'date_format_long', 'l j F Y');
  94. $this->setSetting(
  95. 'Core',
  96. 'date_formats_long',
  97. [
  98. 'j F Y',
  99. 'D j F Y',
  100. 'l j F Y',
  101. 'j F, Y',
  102. 'D j F, Y',
  103. 'l j F, Y',
  104. 'd F Y',
  105. 'd F, Y',
  106. 'F j Y',
  107. 'D F j Y',
  108. 'l F j Y',
  109. 'F d, Y',
  110. 'D F d, Y',
  111. 'l F d, Y',
  112. ]
  113. );
  114. $this->setSetting('Core', 'time_format', 'H:i');
  115. $this->setSetting('Core', 'time_formats', ['H:i', 'H:i:s', 'g:i a', 'g:i A']);
  116. // number formats
  117. $this->setSetting('Core', 'number_format', 'dot_nothing');
  118. $this->setSetting(
  119. 'Core',
  120. 'number_formats',
  121. [
  122. 'comma_nothing' => '10000,25',
  123. 'dot_nothing' => '10000.25',
  124. 'dot_comma' => '10,000.25',
  125. 'comma_dot' => '10.000,25',
  126. 'dot_space' => '10000.25',
  127. 'comma_space' => '10 000,25',
  128. ]
  129. );
  130. // e-mail settings
  131. $this->setSetting(
  132. 'Core',
  133. 'mailer_from',
  134. ['name' => 'Fork CMS', 'email' => $this->getVariable('spoon_debug_email')]
  135. );
  136. $this->setSetting(
  137. 'Core',
  138. 'mailer_to',
  139. ['name' => 'Fork CMS', 'email' => $this->getVariable('spoon_debug_email')]
  140. );
  141. $this->setSetting(
  142. 'Core',
  143. 'mailer_reply_to',
  144. ['name' => 'Fork CMS', 'email' => $this->getVariable('spoon_debug_email')]
  145. );
  146. // smtp settings
  147. $this->setSetting('Core', 'smtp_server', $this->getVariable('smtp_server'));
  148. $this->setSetting('Core', 'smtp_port', $this->getVariable('smtp_port'));
  149. $this->setSetting('Core', 'smtp_username', $this->getVariable('smtp_username'));
  150. $this->setSetting('Core', 'smtp_password', $this->getVariable('smtp_password'));
  151. // default titles
  152. $siteTitles = [
  153. 'en' => 'My website',
  154. 'bg' => 'уебсайта си',
  155. 'zh' => '我的网站',
  156. 'cs' => 'můj web',
  157. 'nl' => 'Mijn website',
  158. 'fr' => 'Mon site web',
  159. 'de' => 'Meine Webseite',
  160. 'el' => 'ιστοσελίδα μου',
  161. 'hu' => 'Hhonlapom',
  162. 'it' => 'Il mio sito web',
  163. 'ja' => '私のウェブサイト',
  164. 'lt' => 'mano svetainė',
  165. 'pl' => 'moja strona',
  166. 'ro' => 'site-ul meu',
  167. 'ru' => 'мой сайт',
  168. 'es' => 'Mi sitio web',
  169. 'sv' => 'min hemsida',
  170. 'tr' => 'web siteme',
  171. 'uk' => 'мій сайт',
  172. ];
  173. // language specific
  174. foreach ($this->getLanguages() as $language) {
  175. // set title
  176. $this->setSetting(
  177. 'Core',
  178. 'site_title_' . $language,
  179. (isset($siteTitles[$language])) ? $siteTitles[$language] : $this->getVariable('site_title')
  180. );
  181. }
  182. // ckfinder
  183. $this->setSetting('Core', 'ckfinder_license_name', 'Fork CMS');
  184. $this->setSetting('Core', 'ckfinder_license_key', 'QFKH-MNCN-19A8-32XW-35GK-Q58G-UPMC');
  185. // Enable the cookie bar by default when the timezone is in europe
  186. $this->setSetting(
  187. 'Core',
  188. 'show_cookie_bar',
  189. date_default_timezone_get() && strpos(mb_strtolower(date_default_timezone_get()), 'europe') === 0
  190. );
  191. }
  192. }