install.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <?php
  2. session_start ();
  3. if (isset ($_GET['step'])) {
  4. define ('STEP', $_GET['step']);
  5. } else {
  6. define ('STEP', 1);
  7. }
  8. define ('SQL_REQ_CREATE_DB', 'CREATE DATABASE %s DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
  9. define ('SQL_REQ_CAT', 'CREATE TABLE IF NOT EXISTS `%scategory` (
  10. `id` varchar(6) NOT NULL,
  11. `name` varchar(255) NOT NULL,
  12. `color` varchar(7) NOT NULL,
  13. PRIMARY KEY (`id`)
  14. );');
  15. define ('SQL_REQ_FEED', 'CREATE TABLE IF NOT EXISTS `%sfeed` (
  16. `id` varchar(6) NOT NULL,
  17. `url` text NOT NULL,
  18. `category` varchar(6) DEFAULT \'000000\',
  19. `name` varchar(255) NOT NULL,
  20. `website` text NOT NULL,
  21. `description` text NOT NULL,
  22. `lastUpdate` int(11) NOT NULL,
  23. `priority` int(2) NOT NULL DEFAULT \'10\',
  24. `pathEntries` varchar(500) DEFAULT NULL,
  25. `httpAuth` varchar(500) DEFAULT NULL,
  26. `error` int(1) NOT NULL DEFAULT \'0\',
  27. `keep_history` int(1) NOT NULL DEFAULT \'0\',
  28. PRIMARY KEY (`id`),
  29. FOREIGN KEY (`category`) REFERENCES %scategory(id) ON DELETE SET NULL ON UPDATE CASCADE
  30. );');
  31. define ('SQL_REQ_ENTRY', 'CREATE TABLE IF NOT EXISTS `%sentry` (
  32. `id` varchar(6) NOT NULL,
  33. `guid` text NOT NULL,
  34. `title` varchar(255) NOT NULL,
  35. `author` varchar(255) NOT NULL,
  36. `content` text NOT NULL,
  37. `link` text NOT NULL,
  38. `date` int(11) NOT NULL,
  39. `is_read` int(11) NOT NULL DEFAULT \'0\',
  40. `is_favorite` int(11) NOT NULL DEFAULT \'0\',
  41. `id_feed` varchar(6) NOT NULL,
  42. `tags` text NOT NULL,
  43. PRIMARY KEY (`id`),
  44. FOREIGN KEY (`id_feed`) REFERENCES %sfeed(id) ON DELETE CASCADE ON UPDATE CASCADE
  45. );');
  46. function writeLine ($f, $line) {
  47. fwrite ($f, $line . "\n");
  48. }
  49. function writeArray ($f, $array) {
  50. foreach ($array as $key => $val) {
  51. if (is_array ($val)) {
  52. writeLine ($f, '\'' . $key . '\' => array (');
  53. writeArray ($f, $val);
  54. writeLine ($f, '),');
  55. } else {
  56. writeLine ($f, '\'' . $key . '\' => \'' . $val . '\',');
  57. }
  58. }
  59. }
  60. // tiré de Shaarli de Seb Sauvage //Format RFC 4648 base64url
  61. function small_hash ($txt) {
  62. $t = rtrim (base64_encode (hash ('crc32', $txt, true)), '=');
  63. return strtr ($t, '+/', '-_');
  64. }
  65. // gestion internationalisation
  66. $translates = array ();
  67. $actual = 'en';
  68. function initTranslate () {
  69. global $translates;
  70. global $actual;
  71. $l = getBetterLanguage ('en');
  72. if (isset ($_SESSION['language'])) {
  73. $l = $_SESSION['language'];
  74. }
  75. $actual = $l;
  76. $file = APP_PATH . '/i18n/' . $actual . '.php';
  77. if (file_exists ($file)) {
  78. $translates = include ($file);
  79. }
  80. }
  81. function getBetterLanguage ($fallback) {
  82. $available = availableLanguages ();
  83. $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  84. $language = strtolower (substr ($accept, 0, 2));
  85. if (isset ($available[$language])) {
  86. return $language;
  87. } else {
  88. return $fallback;
  89. }
  90. }
  91. function availableLanguages () {
  92. return array (
  93. 'en' => 'English',
  94. 'fr' => 'Français'
  95. );
  96. }
  97. function _t ($key) {
  98. global $translates;
  99. $translate = $key;
  100. if (isset ($translates[$key])) {
  101. $translate = $translates[$key];
  102. }
  103. $args = func_get_args ();
  104. unset($args[0]);
  105. return vsprintf ($translate, $args);
  106. }
  107. /*** SAUVEGARDES ***/
  108. function saveLanguage () {
  109. if (!empty ($_POST)) {
  110. if (!isset ($_POST['language'])) {
  111. return false;
  112. }
  113. $_SESSION['language'] = $_POST['language'];
  114. header ('Location: index.php?step=1');
  115. }
  116. }
  117. function saveStep2 () {
  118. if (!empty ($_POST)) {
  119. if (empty ($_POST['sel']) ||
  120. empty ($_POST['title']) ||
  121. empty ($_POST['old_entries'])) {
  122. return false;
  123. }
  124. $_SESSION['sel'] = addslashes ($_POST['sel']);
  125. $_SESSION['base_url'] = addslashes ($_POST['base_url']);
  126. $_SESSION['title'] = addslashes ($_POST['title']);
  127. $_SESSION['old_entries'] = $_POST['old_entries'];
  128. if (!is_int (intval ($_SESSION['old_entries'])) ||
  129. $_SESSION['old_entries'] < 1) {
  130. $_SESSION['old_entries'] = 3;
  131. }
  132. $_SESSION['mail_login'] = addslashes ($_POST['mail_login']);
  133. $token = '';
  134. if ($_SESSION['mail_login']) {
  135. $token = small_hash (time () . $_SESSION['sel'])
  136. . small_hash ($_SESSION['base_url'] . $_SESSION['sel']);
  137. }
  138. $file_data = PUBLIC_PATH . '/data/Configuration.array.php';
  139. $f = fopen ($file_data, 'w');
  140. writeLine ($f, '<?php');
  141. writeLine ($f, 'return array (');
  142. writeArray ($f, array (
  143. 'language' => $_SESSION['language'],
  144. 'old_entries' => $_SESSION['old_entries'],
  145. 'mail_login' => $_SESSION['mail_login'],
  146. 'token' => $token
  147. ));
  148. writeLine ($f, ');');
  149. fclose ($f);
  150. header ('Location: index.php?step=3');
  151. }
  152. }
  153. function saveStep3 () {
  154. if (!empty ($_POST)) {
  155. if (empty ($_POST['type']) ||
  156. empty ($_POST['host']) ||
  157. empty ($_POST['user']) ||
  158. empty ($_POST['base'])) {
  159. $_SESSION['bd_error'] = true;
  160. }
  161. $_SESSION['bd_type'] = isset ($_POST['type']) ? $_POST['type'] : 'mysql';
  162. $_SESSION['bd_host'] = addslashes ($_POST['host']);
  163. $_SESSION['bd_user'] = addslashes ($_POST['user']);
  164. $_SESSION['bd_pass'] = addslashes ($_POST['pass']);
  165. $_SESSION['bd_name'] = addslashes ($_POST['base']);
  166. $_SESSION['bd_prefix'] = addslashes ($_POST['prefix']);
  167. $file_conf = APP_PATH . '/configuration/application.ini';
  168. $f = fopen ($file_conf, 'w');
  169. writeLine ($f, '[general]');
  170. writeLine ($f, 'environment = "production"');
  171. writeLine ($f, 'use_url_rewriting = false');
  172. writeLine ($f, 'sel_application = "' . $_SESSION['sel'] . '"');
  173. writeLine ($f, 'base_url = "' . $_SESSION['base_url'] . '"');
  174. writeLine ($f, 'title = "' . $_SESSION['title'] . '"');
  175. writeLine ($f, '[db]');
  176. writeLine ($f, 'type = "' . $_SESSION['bd_type'] . '"');
  177. writeLine ($f, 'host = "' . $_SESSION['bd_host'] . '"');
  178. writeLine ($f, 'user = "' . $_SESSION['bd_user'] . '"');
  179. writeLine ($f, 'password = "' . $_SESSION['bd_pass'] . '"');
  180. writeLine ($f, 'base = "' . $_SESSION['bd_name'] . '"');
  181. writeLine ($f, 'prefix = "' . $_SESSION['bd_prefix'] . '"');
  182. fclose ($f);
  183. $res = checkBD ();
  184. if ($res) {
  185. $_SESSION['bd_error'] = false;
  186. header ('Location: index.php?step=4');
  187. } else {
  188. $_SESSION['bd_error'] = true;
  189. }
  190. }
  191. }
  192. function deleteInstall () {
  193. $res = unlink (PUBLIC_PATH . '/install.php');
  194. if ($res) {
  195. header ('Location: index.php');
  196. }
  197. }
  198. /*** VÉRIFICATIONS ***/
  199. function checkStep () {
  200. $s0 = checkStep0 ();
  201. $s1 = checkStep1 ();
  202. $s2 = checkStep2 ();
  203. $s3 = checkStep3 ();
  204. if (STEP > 0 && $s0['all'] != 'ok') {
  205. header ('Location: index.php?step=0');
  206. } elseif (STEP > 1 && $s1['all'] != 'ok') {
  207. header ('Location: index.php?step=1');
  208. } elseif (STEP > 2 && $s2['all'] != 'ok') {
  209. header ('Location: index.php?step=2');
  210. } elseif (STEP > 3 && $s3['all'] != 'ok') {
  211. header ('Location: index.php?step=3');
  212. }
  213. }
  214. function checkStep0 () {
  215. $languages = availableLanguages ();
  216. $language = isset ($_SESSION['language']) &&
  217. isset ($languages[$_SESSION['language']]);
  218. return array (
  219. 'language' => $language ? 'ok' : 'ko',
  220. 'all' => $language ? 'ok' : 'ko'
  221. );
  222. }
  223. function checkStep1 () {
  224. $php = version_compare (PHP_VERSION, '5.1.0') >= 0;
  225. $minz = file_exists (LIB_PATH . '/minz');
  226. $curl = extension_loaded ('curl');
  227. $pdo = extension_loaded ('pdo_mysql');
  228. $dom = class_exists('DOMDocument');
  229. $cache = CACHE_PATH && is_writable (CACHE_PATH);
  230. $log = LOG_PATH && is_writable (LOG_PATH);
  231. $conf = APP_PATH && is_writable (APP_PATH . '/configuration');
  232. $data = is_writable (PUBLIC_PATH . '/data');
  233. return array (
  234. 'php' => $php ? 'ok' : 'ko',
  235. 'minz' => $minz ? 'ok' : 'ko',
  236. 'curl' => $curl ? 'ok' : 'ko',
  237. 'pdo-mysql' => $pdo ? 'ok' : 'ko',
  238. 'dom' => $dom ? 'ok' : 'ko',
  239. 'cache' => $cache ? 'ok' : 'ko',
  240. 'log' => $log ? 'ok' : 'ko',
  241. 'configuration' => $conf ? 'ok' : 'ko',
  242. 'data' => $data ? 'ok' : 'ko',
  243. 'all' => $php && $minz && $curl && $pdo && $dom && $cache && $log && $conf && $data ? 'ok' : 'ko'
  244. );
  245. }
  246. function checkStep2 () {
  247. $conf = isset ($_SESSION['sel']) &&
  248. isset ($_SESSION['base_url']) &&
  249. isset ($_SESSION['title']) &&
  250. isset ($_SESSION['old_entries']) &&
  251. isset ($_SESSION['mail_login']);
  252. $data = file_exists (PUBLIC_PATH . '/data/Configuration.array.php');
  253. return array (
  254. 'conf' => $conf ? 'ok' : 'ko',
  255. 'data' => $data ? 'ok' : 'ko',
  256. 'all' => $conf && $data ? 'ok' : 'ko'
  257. );
  258. }
  259. function checkStep3 () {
  260. $conf = file_exists (APP_PATH . '/configuration/application.ini');
  261. $bd = isset ($_SESSION['bd_type']) &&
  262. isset ($_SESSION['bd_host']) &&
  263. isset ($_SESSION['bd_user']) &&
  264. isset ($_SESSION['bd_pass']) &&
  265. isset ($_SESSION['bd_name']);
  266. $conn = !isset ($_SESSION['bd_error']) || !$_SESSION['bd_error'];
  267. return array (
  268. 'bd' => $bd ? 'ok' : 'ko',
  269. 'conn' => $conn ? 'ok' : 'ko',
  270. 'conf' => $conf ? 'ok' : 'ko',
  271. 'all' => $bd && $conn && $conf ? 'ok' : 'ko'
  272. );
  273. }
  274. function checkBD () {
  275. $error = false;
  276. try {
  277. $str = '';
  278. $driver_options = null;
  279. if($_SESSION['bd_type'] == 'mysql') {
  280. $driver_options = array(
  281. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  282. );
  283. // on ouvre une connexion juste pour créer la base si elle n'existe pas
  284. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';';
  285. $c = new PDO ($str,
  286. $_SESSION['bd_user'],
  287. $_SESSION['bd_pass'],
  288. $driver_options);
  289. $sql = sprintf (SQL_REQ_CREATE_DB, $_SESSION['bd_name']);
  290. $res = $c->query ($sql);
  291. // on écrase la précédente connexion en sélectionnant la nouvelle BDD
  292. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_name'];
  293. } elseif($_SESSION['bd_type'] == 'sqlite') {
  294. $str = 'sqlite:' . PUBLIC_PATH
  295. . '/data/' . $_SESSION['bd_name'] . '.sqlite';
  296. }
  297. $c = new PDO ($str,
  298. $_SESSION['bd_user'],
  299. $_SESSION['bd_pass'],
  300. $driver_options);
  301. $sql = sprintf (SQL_REQ_CAT, $_SESSION['bd_prefix']);
  302. $res = $c->query ($sql);
  303. if (!$res) {
  304. $error = true;
  305. }
  306. $sql = sprintf (SQL_REQ_FEED, $_SESSION['bd_prefix'], $_SESSION['bd_prefix']);
  307. $res = $c->query ($sql);
  308. if (!$res) {
  309. $error = true;
  310. }
  311. $sql = sprintf (SQL_REQ_ENTRY, $_SESSION['bd_prefix'], $_SESSION['bd_prefix']);
  312. $res = $c->query ($sql);
  313. if (!$res) {
  314. $error = true;
  315. }
  316. } catch (PDOException $e) {
  317. $error = true;
  318. }
  319. if ($error && file_exists (APP_PATH . '/configuration/application.ini')) {
  320. unlink (APP_PATH . '/configuration/application.ini');
  321. }
  322. return !$error;
  323. }
  324. /*** AFFICHAGE ***/
  325. function printStep0 () {
  326. global $actual;
  327. ?>
  328. <?php $s0 = checkStep0 (); if ($s0['all'] == 'ok') { ?>
  329. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('language_defined'); ?></p>
  330. <?php } ?>
  331. <form action="index.php?step=0" method="post">
  332. <legend><?php echo _t ('choose_language'); ?></legend>
  333. <div class="form-group">
  334. <label class="group-name" for="language"><?php echo _t ('language'); ?></label>
  335. <div class="group-controls">
  336. <select name="language" id="language">
  337. <?php $languages = availableLanguages (); ?>
  338. <?php foreach ($languages as $short => $lib) { ?>
  339. <option value="<?php echo $short; ?>"<?php echo $actual == $short ? ' selected="selected"' : ''; ?>><?php echo $lib; ?></option>
  340. <?php } ?>
  341. </select>
  342. </div>
  343. </div>
  344. <div class="form-group form-actions">
  345. <div class="group-controls">
  346. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  347. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  348. <?php if ($s0['all'] == 'ok') { ?>
  349. <a class="btn btn-important next-step" href="?step=1"><?php echo _t ('next_step'); ?></a>
  350. <?php } ?>
  351. </div>
  352. </div>
  353. </form>
  354. <?php
  355. }
  356. function printStep1 () {
  357. $res = checkStep1 ();
  358. ?>
  359. <noscript><p class="alert alert-warn"><span class="alert-head"><?php echo _t ('attention'); ?></span> <?php echo _t ('javascript_is_better'); ?></p></noscript>
  360. <?php if ($res['php'] == 'ok') { ?>
  361. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('php_is_ok', PHP_VERSION); ?></p>
  362. <?php } else { ?>
  363. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('php_is_nok', PHP_VERSION, '5.1.0'); ?></p>
  364. <?php } ?>
  365. <?php if ($res['minz'] == 'ok') { ?>
  366. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('minz_is_ok'); ?></p>
  367. <?php } else { ?>
  368. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('minz_is_nok', LIB_PATH . '/minz'); ?></p>
  369. <?php } ?>
  370. <?php if ($res['curl'] == 'ok') { ?>
  371. <?php $version = curl_version(); ?>
  372. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('curl_is_ok', $version['version']); ?></p>
  373. <?php } else { ?>
  374. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('curl_is_nok'); ?></p>
  375. <?php } ?>
  376. <?php if ($res['pdo-mysql'] == 'ok') { ?>
  377. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('pdomysql_is_ok'); ?></p>
  378. <?php } else { ?>
  379. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('pdomysql_is_nok'); ?></p>
  380. <?php } ?>
  381. <?php if ($res['dom'] == 'ok') { ?>
  382. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('dom_is_ok'); ?></p>
  383. <?php } else { ?>
  384. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('dom_is_nok'); ?></p>
  385. <?php } ?>
  386. <?php if ($res['cache'] == 'ok') { ?>
  387. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('cache_is_ok'); ?></p>
  388. <?php } else { ?>
  389. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', PUBLIC_PATH . '/../cache'); ?></p>
  390. <?php } ?>
  391. <?php if ($res['log'] == 'ok') { ?>
  392. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('log_is_ok'); ?></p>
  393. <?php } else { ?>
  394. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', PUBLIC_PATH . '/../log'); ?></p>
  395. <?php } ?>
  396. <?php if ($res['configuration'] == 'ok') { ?>
  397. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('conf_is_ok'); ?></p>
  398. <?php } else { ?>
  399. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', APP_PATH . '/configuration'); ?></p>
  400. <?php } ?>
  401. <?php if ($res['data'] == 'ok') { ?>
  402. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('data_is_ok'); ?></p>
  403. <?php } else { ?>
  404. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', PUBLIC_PATH . '/data'); ?></p>
  405. <?php } ?>
  406. <?php if ($res['all'] == 'ok') { ?>
  407. <a class="btn btn-important next-step" href="?step=2"><?php echo _t ('next_step'); ?></a>
  408. <?php } else { ?>
  409. <p class="alert alert-error"><?php echo _t ('fix_errors_before'); ?></p>
  410. <?php } ?>
  411. <?php
  412. }
  413. function printStep2 () {
  414. ?>
  415. <?php $s2 = checkStep2 (); if ($s2['all'] == 'ok') { ?>
  416. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('general_conf_is_ok'); ?></p>
  417. <?php } ?>
  418. <form action="index.php?step=2" method="post">
  419. <legend><?php echo _t ('general_configuration'); ?></legend>
  420. <div class="form-group">
  421. <label class="group-name" for="sel"><?php echo _t ('random_string'); ?></label>
  422. <div class="group-controls">
  423. <input type="text" id="sel" name="sel" value="<?php echo isset ($_SESSION['sel']) ? $_SESSION['sel'] : '123~abcdefghijklmnopqrstuvwxyz~321'; ?>" /> <i class="icon i_help"></i> <?php echo _t ('change_value'); ?>
  424. </div>
  425. </div>
  426. <?php
  427. $url = substr ($_SERVER['PHP_SELF'], 0, -10);
  428. ?>
  429. <div class="form-group" style="display:none">
  430. <label class="group-name" for="base_url"><?php echo _t ('base_url'); ?></label>
  431. <div class="group-controls">
  432. <input type="text" id="base_url" name="base_url" value="<?php echo isset ($_SESSION['base_url']) ? $_SESSION['base_url'] : $url; ?>" /> <i class="icon i_help"></i> <?php echo _t ('do_not_change_if_doubt'); ?>
  433. </div>
  434. </div>
  435. <div class="form-group">
  436. <label class="group-name" for="title"><?php echo _t ('title'); ?></label>
  437. <div class="group-controls">
  438. <input type="text" id="title" name="title" value="<?php echo isset ($_SESSION['title']) ? $_SESSION['title'] : _t ('freshrss'); ?>" />
  439. </div>
  440. </div>
  441. <div class="form-group">
  442. <label class="group-name" for="old_entries"><?php echo _t ('delete_articles_every'); ?></label>
  443. <div class="group-controls">
  444. <input type="number" id="old_entries" name="old_entries" value="<?php echo isset ($_SESSION['old_entries']) ? $_SESSION['old_entries'] : '3'; ?>" /> <?php echo _t ('month'); ?>
  445. </div>
  446. </div>
  447. <div class="form-group">
  448. <label class="group-name" for="mail_login"><?php echo _t ('persona_connection_email'); ?></label>
  449. <div class="group-controls">
  450. <input type="email" id="mail_login" name="mail_login" value="<?php echo isset ($_SESSION['mail_login']) ? $_SESSION['mail_login'] : ''; ?>" placeholder="<?php echo _t ('blank_to_disable'); ?>" />
  451. <noscript><b><?php echo _t ('javascript_should_be_activated'); ?></b></noscript>
  452. </div>
  453. </div>
  454. <div class="form-group form-actions">
  455. <div class="group-controls">
  456. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  457. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  458. <?php if ($s2['all'] == 'ok') { ?>
  459. <a class="btn btn-important next-step" href="?step=3"><?php echo _t ('next_step'); ?></a>
  460. <?php } ?>
  461. </div>
  462. </div>
  463. </form>
  464. <?php
  465. }
  466. function printStep3 () {
  467. ?>
  468. <?php $s3 = checkStep3 (); if ($s3['all'] == 'ok') { ?>
  469. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('bdd_conf_is_ok'); ?></p>
  470. <?php } elseif ($s3['conn'] == 'ko') { ?>
  471. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('bdd_conf_is_ko'); ?></p>
  472. <?php } ?>
  473. <form action="index.php?step=3" method="post">
  474. <legend><?php echo _t ('bdd_configuration'); ?></legend>
  475. <!--
  476. TODO : l'utilisation de SQLite n'est pas encore possible. Pour tester tout de même, décommentez ce bloc
  477. <div class="form-group">
  478. <label class="group-name" for="type"><?php echo _t ('bdd_type'); ?></label>
  479. <div class="group-controls">
  480. <select name="type" id="type">
  481. <option value="mysql"
  482. <?php echo $_SESSION['bd_type'] && $_SESSION['bd_type'] == 'mysql' ? 'selected="selected"' : ''; ?>>
  483. MySQL
  484. </option>
  485. <option value="sqlite"
  486. <?php echo $_SESSION['bd_type'] && $_SESSION['bd_type'] == 'sqlite' ? 'selected="selected"' : ''; ?>>
  487. SQLite
  488. </option>
  489. </select>
  490. </div>
  491. </div>
  492. -->
  493. <div class="form-group">
  494. <label class="group-name" for="host"><?php echo _t ('host'); ?></label>
  495. <div class="group-controls">
  496. <input type="text" id="host" name="host" value="<?php echo isset ($_SESSION['bd_host']) ? $_SESSION['bd_host'] : 'localhost'; ?>" />
  497. </div>
  498. </div>
  499. <div class="form-group">
  500. <label class="group-name" for="user"><?php echo _t ('username'); ?></label>
  501. <div class="group-controls">
  502. <input type="text" id="user" name="user" value="<?php echo isset ($_SESSION['bd_user']) ? $_SESSION['bd_user'] : ''; ?>" />
  503. </div>
  504. </div>
  505. <div class="form-group">
  506. <label class="group-name" for="pass"><?php echo _t ('password'); ?></label>
  507. <div class="group-controls">
  508. <input type="password" id="pass" name="pass" value="<?php echo isset ($_SESSION['bd_pass']) ? $_SESSION['bd_pass'] : ''; ?>" />
  509. </div>
  510. </div>
  511. <div class="form-group">
  512. <label class="group-name" for="base"><?php echo _t ('bdd'); ?></label>
  513. <div class="group-controls">
  514. <input type="text" id="base" name="base" value="<?php echo isset ($_SESSION['bd_name']) ? $_SESSION['bd_name'] : ''; ?>" />
  515. </div>
  516. </div>
  517. <div class="form-group">
  518. <label class="group-name" for="prefix"><?php echo _t ('prefix'); ?></label>
  519. <div class="group-controls">
  520. <input type="text" id="prefix" name="prefix" value="<?php echo isset ($_SESSION['bd_prefix']) ? $_SESSION['bd_prefix'] : 'freshrss_'; ?>" />
  521. </div>
  522. </div>
  523. <div class="form-group form-actions">
  524. <div class="group-controls">
  525. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  526. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  527. <?php if ($s3['all'] == 'ok') { ?>
  528. <a class="btn btn-important next-step" href="?step=4"><?php echo _t ('next_step'); ?></a>
  529. <?php } ?>
  530. </div>
  531. </div>
  532. </form>
  533. <?php
  534. }
  535. function printStep4 () {
  536. ?>
  537. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('congratulations'); ?></span> <?php echo _t ('installation_is_ok'); ?></p>
  538. <a class="btn btn-important next-step" href="?step=5"><?php echo _t ('finish_installation'); ?></a>
  539. <?php
  540. }
  541. function printStep5 () {
  542. ?>
  543. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('oops'); ?></span> <?php echo _t ('install_not_deleted', PUBLIC_PATH . '/install.php'); ?></p>
  544. <?php
  545. }
  546. initTranslate ();
  547. checkStep ();
  548. switch (STEP) {
  549. case 0:
  550. default:
  551. saveLanguage ();
  552. break;
  553. case 1:
  554. break;
  555. case 2:
  556. saveStep2 ();
  557. break;
  558. case 3:
  559. saveStep3 ();
  560. break;
  561. case 4:
  562. break;
  563. case 5:
  564. deleteInstall ();
  565. break;
  566. }
  567. ?>
  568. <!DOCTYPE html>
  569. <html lang="fr">
  570. <head>
  571. <meta charset="utf-8">
  572. <meta name="viewport" content="initial-scale=1.0">
  573. <title><?php echo _t ('freshrss_installation'); ?></title>
  574. <link rel="stylesheet" type="text/css" media="all" href="themes/default/global.css" />
  575. <link rel="stylesheet" type="text/css" media="all" href="themes/default/freshrss.css" />
  576. </head>
  577. <body>
  578. <div class="header">
  579. <div class="item title">
  580. <h1><a href="index.php"><?php echo _t ('freshrss'); ?></a></h1>
  581. <h2><?php echo _t ('installation_step', STEP); ?></h2>
  582. </div>
  583. </div>
  584. <div id="global">
  585. <ul class="nav nav-list aside">
  586. <li class="nav-header"><?php echo _t ('steps'); ?></li>
  587. <li class="item<?php echo STEP == 0 ? ' active' : ''; ?>"><a href="?step=0"><?php echo _t ('language'); ?></a></li>
  588. <li class="item<?php echo STEP == 1 ? ' active' : ''; ?>"><a href="?step=1"><?php echo _t ('checks'); ?></a></li>
  589. <li class="item<?php echo STEP == 2 ? ' active' : ''; ?>"><a href="?step=2"><?php echo _t ('general_configuration'); ?></a></li>
  590. <li class="item<?php echo STEP == 3 ? ' active' : ''; ?>"><a href="?step=3"><?php echo _t ('bdd_configuration'); ?></a></li>
  591. <li class="item<?php echo STEP == 4 ? ' active' : ''; ?>"><a href="?step=4"><?php echo _t ('this_is_the_end'); ?></a></li>
  592. </ul>
  593. <div class="post">
  594. <?php
  595. switch (STEP) {
  596. case 0:
  597. default:
  598. printStep0 ();
  599. break;
  600. case 1:
  601. printStep1 ();
  602. break;
  603. case 2:
  604. printStep2 ();
  605. break;
  606. case 3:
  607. printStep3 ();
  608. break;
  609. case 4:
  610. printStep4 ();
  611. break;
  612. case 5:
  613. printStep5 ();
  614. break;
  615. }
  616. ?>
  617. </div>
  618. </div>
  619. </body>
  620. </html>