install.php 24 KB

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