install.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. /*
  3. @nom: install
  4. @auteur: Idleman (http://blog.idleman.fr)
  5. @description: Page d'installation du script (a supprimer après installation)
  6. */
  7. require_once('Functions.class.php');
  8. require_once('Install.class.php');
  9. require_once('i18n.php');
  10. global $i18n;
  11. $install = new Install();
  12. /* Prend le choix de langue de l'utilisateur, soit :
  13. * - lorsqu'il vient de changer la langue du sélecteur ($lang)
  14. * - lorsqu'il vient de lancer l'installeur ($install_changeLngLeed)
  15. */
  16. $lang = '';
  17. if (isset($_GET['lang'])) $lang = $_GET['lang'];
  18. elseif (isset($_POST['install_changeLngLeed'])) $lang = $_POST['install_changeLngLeed'];
  19. $installDirectory = dirname(__FILE__).'/install';
  20. // N'affiche que les langues du navigateur
  21. // @TODO: il faut afficher toutes les langues disponibles
  22. // avec le choix par défaut de la langue préférée
  23. $languageList = Functions::getBrowserLanguages();
  24. if (!empty($lang)) {
  25. // L'utilisateur a choisi une langue, qu'on incorpore dans la liste
  26. array_unshift($languageList, $lang);
  27. $liste = array_unique($languageList);
  28. }
  29. unset($i18n); //@TODO: gérer un singleton et le choix de langue / liste de langue
  30. $currentLanguage = i18n_init($languageList, $installDirectory);
  31. $languageList = array_unique($i18n->languages);
  32. if (file_exists('constant.php')) {
  33. die(_t('ALREADY_INSTALLED'));
  34. }
  35. define('DEFAULT_TEMPLATE', 'marigolds');
  36. $templates = scandir('templates');
  37. if (!in_array(DEFAULT_TEMPLATE, $templates)) die('Missing default template : '.DEFAULT_TEMPLATE);
  38. $templates = array_diff($templates, array(DEFAULT_TEMPLATE, '.', '..')); // Répertoires non voulus sous Linux
  39. sort($templates);
  40. $templates = array_merge(array(DEFAULT_TEMPLATE), $templates); // le thème par défaut en premier
  41. // Cookie de la session
  42. $cookiedir = '';
  43. if(dirname($_SERVER['SCRIPT_NAME'])!='/') $cookiedir=dirname($_SERVER["SCRIPT_NAME"]).'/';
  44. session_set_cookie_params(0, $cookiedir);
  45. session_start();
  46. // Protection des variables
  47. $_ = array_merge($_GET, $_POST);
  48. $installActionName = 'installButton';
  49. $install->launch($_, $installActionName);
  50. ?>
  51. <!doctype html>
  52. <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="<?php echo $currentLanguage;?>"> <![endif]-->
  53. <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="<?php echo $currentLanguage;?>"> <![endif]-->
  54. <!--[if IE 8]> <html class="no-js lt-ie9" lang="<?php echo $currentLanguage;?>"> <![endif]-->
  55. <!--[if gt IE 8]><!--> <html class="no-js" lang="<?php echo $currentLanguage;?>"> <!--<![endif]-->
  56. <head>
  57. <meta charset="utf-8">
  58. <meta name="referrer" content="no-referrer" />
  59. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  60. <title><?php echo _t('INSTALL_TITLE') ?></title>
  61. <meta name="viewport" content="width=device-width">
  62. <link rel="stylesheet" href="templates/marigolds/css/style.css">
  63. <style>
  64. code {
  65. color:#000;
  66. font-size: 1em;
  67. }
  68. .install h1 {
  69. margin-bottom: 1.3em;
  70. }
  71. .install h2 {
  72. margin-bottom: 0.1em;
  73. font-size: 1.5em;
  74. }
  75. .install ul {
  76. margin: 0;
  77. padding: 0;
  78. }
  79. .install li {
  80. list-style: none outside none;
  81. }
  82. .install span {
  83. display: inline-block;
  84. width: 8em;
  85. padding-right: 1em;
  86. }
  87. button#installButton {
  88. margin-top: 1em;
  89. font-size: 2em;
  90. }
  91. .message {
  92. color: #ffffff;
  93. margin-bottom: 2em;
  94. }
  95. .message li {
  96. border:1px solid #212121
  97. }
  98. .messageError {
  99. background-color: #F16529;
  100. }
  101. .messageSuccess {
  102. background-color: #008000;
  103. }
  104. </style>
  105. </head>
  106. <body>
  107. <div class="global-wrapper">
  108. <div id="header-container">
  109. <header class="wrapper clearfix">
  110. <h1 class="logo" id="title"><a href="./index.php">L<i>eed</i></a></h1>
  111. <nav>
  112. </nav>
  113. </header>
  114. </div>
  115. <?php
  116. if ($install->getFinished()){
  117. echo '<div id="main-container">
  118. <div id="main" class="wrapper clearfix">
  119. <div id="menuBar"></div>
  120. <h1>'._t('INSTALL_TITLE_END').'</h1>
  121. <span>'._t('INSTALL_END').'</span>
  122. <hr>
  123. <button id="installButton" name="<?php echo $installActionName; ?>" onclick="document.location.href=\'settings.php#preferenceBloc\'">'._t('INSTALL_BTN_END').'</button>
  124. ';
  125. // écriture des balises de fin et ne pas faire la suite
  126. echo '</div>
  127. <div id="footer-container">
  128. <footer class="wrapper">
  129. <p>Leed "Light Feed" by <a target="_blank" rel="noopener noreferrer" href="http://blog.idleman.fr">Idleman</a></p>
  130. </footer>
  131. </div>
  132. </body>
  133. </html>';
  134. exit();
  135. }
  136. ?>
  137. <div id="main-container">
  138. <div id="main" class="wrapper clearfix">
  139. <div id="menuBar">
  140. <aside>
  141. <h3 class="left"><?php echo _t('INSTALL_PRE_REQUIS') ?></h3>
  142. <ul class="clear" style="margin:0">
  143. <?php
  144. foreach($install->logs as $type => $messages){
  145. if(empty($messages)) {
  146. continue;
  147. }
  148. $class = 'message ';
  149. $class .= $type === 'errors' ? 'messageError':'messageSuccess';
  150. $label = $type === 'errors' ? _t('ERROR') : _t('SUCCESS');
  151. echo "<li class='$class'>$label&nbsp;:<ul>";
  152. foreach ($messages as $message){
  153. echo "<li>$message</li>";
  154. }
  155. echo "</ul></li>";
  156. }
  157. ?>
  158. </ul>
  159. </aside>
  160. </div>
  161. <form action="install.php" method="POST" class="install">
  162. <h1><?php echo _t('INSTALL_TITLE') ?></h1>
  163. <h2><?php echo _t('INSTALL_TAB_GENERAL') ?></h2>
  164. <ul>
  165. <li>
  166. <span><?php echo _t('INSTALL_LANGUAGE') ?></span>
  167. <select name="install_changeLngLeed" onchange="window.location.href='install.php?lang='+this[this.selectedIndex].value">
  168. <?php
  169. foreach($languageList as $lang){
  170. $sel = $lang==$currentLanguage?'selected=selected':'';
  171. echo "<option $sel value='$lang'>$lang</option>";
  172. }
  173. ?>
  174. </select>
  175. </li>
  176. <li>
  177. <span><?php echo _t('INSTALL_TEMPLATE') ?></span>
  178. <?php
  179. $disabled = count($templates)<2 ? "disabled" : "";
  180. echo "<select name='template' $disabled>\n";
  181. foreach($templates as $name){
  182. echo "<option value='$name'>$name</option>";
  183. }
  184. ?>
  185. </select>
  186. </li>
  187. <li>
  188. <span><?php echo _t('PROJECT_ROOT') ?></span>
  189. <input type="text" name="root" value="<?php echo $install->getDefaultRoot(); ?>">
  190. </li>
  191. </ul>
  192. <h2><?php echo _t('INSTALL_TAB_BDD') ?></h2>
  193. <ul>
  194. <li>
  195. <span><?php echo _t('INSTALL_HOST') ?></span>
  196. <input type="text" name="mysqlHost" value="<?php echo $install->options['db']['mysqlHost']; ?>" placeholder="<?php echo _t('INSTALL_COMMENT_HOST') ?>">
  197. </li>
  198. <li>
  199. <span><?php echo _t('LOGIN') ?></span>
  200. <input type="text" name="mysqlLogin" value="<?php echo $install->options['db']['mysqlLogin']; ?>">
  201. </li>
  202. <li>
  203. <span><?php echo _t('PASSWORD') ?></span>
  204. <input type="text" autocomplete="off" name="mysqlMdp" value="<?php echo $install->options['db']['mysqlMdp']; ?>" placeholder="<?php echo _t('INSTALL_DISPLAY_CLEAR') ?>">
  205. </li>
  206. <li>
  207. <span><?php echo _t('INSTALL_BDD') ?></span>
  208. <input type="text" name="mysqlBase" value="<?php echo $install->options['db']['mysqlBase']; ?>" placeholder="<?php echo _t('INSTALL_COMMENT_BDD') ?>">
  209. </li>
  210. <li>
  211. <span><?php echo _t('INSTALL_PREFIX_TABLE') ?></span>
  212. <input type="text" name="mysqlPrefix" value="<?php echo $install->options['db']['mysqlPrefix']; ?>">
  213. </li>
  214. </ul>
  215. <h2><?php echo _t('INSTALL_TAB_ADMIN') ?></h2>
  216. <ul>
  217. <li>
  218. <span><?php echo _t('LOGIN') ?></span>
  219. <input type="text" name="login" value="<?php echo $install->options['user']['login']; ?>" placeholder="<?php echo _t('LOGIN') ?>">
  220. </li>
  221. <li>
  222. <span><?php echo _t('PASSWORD') ?></span>
  223. <input type="text" autocomplete="off" name="password" value="<?php echo $install->options['user']['password']; ?>" placeholder="<?php echo _t('INSTALL_DISPLAY_CLEAR') ?>">
  224. </li>
  225. </ul>
  226. <button id="installButton" name="<?php echo $installActionName; ?>"><?php echo _t('INSTALL_BTN') ?></button>
  227. </form>
  228. </div>
  229. <div id="footer-container">
  230. <footer class="wrapper">
  231. <p>Leed "Light Feed" by <a target="_blank" rel="noopener noreferrer" href="http://blog.idleman.fr">Idleman</a></p>
  232. </footer>
  233. </div>
  234. </body>
  235. </html>