install.php 24 KB

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