install.php 24 KB

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