install.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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']) ? $_SESSION['default_user'] : $_POST['default_user'];
  267. $data = file_exists (DATA_PATH . '/' . $defaultUser . '_user.php');
  268. return array (
  269. 'conf' => $conf ? 'ok' : 'ko',
  270. 'data' => $data ? 'ok' : 'ko',
  271. 'all' => $conf && $data ? 'ok' : 'ko'
  272. );
  273. }
  274. function checkStep3 () {
  275. $conf = file_exists (DATA_PATH . '/application.ini');
  276. $bd = isset ($_SESSION['bd_type']) &&
  277. isset ($_SESSION['bd_host']) &&
  278. isset ($_SESSION['bd_user']) &&
  279. isset ($_SESSION['bd_pass']) &&
  280. isset ($_SESSION['bd_name']);
  281. $conn = !isset ($_SESSION['bd_error']) || !$_SESSION['bd_error'];
  282. return array (
  283. 'bd' => $bd ? 'ok' : 'ko',
  284. 'conn' => $conn ? 'ok' : 'ko',
  285. 'conf' => $conf ? 'ok' : 'ko',
  286. 'all' => $bd && $conn && $conf ? 'ok' : 'ko'
  287. );
  288. }
  289. function checkBD () {
  290. $error = false;
  291. try {
  292. $str = '';
  293. $driver_options = null;
  294. if($_SESSION['bd_type'] == 'mysql') {
  295. $driver_options = array(
  296. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  297. );
  298. // on ouvre une connexion juste pour créer la base si elle n'existe pas
  299. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';';
  300. $c = new PDO ($str,
  301. $_SESSION['bd_user'],
  302. $_SESSION['bd_pass'],
  303. $driver_options);
  304. $sql = sprintf (SQL_REQ_CREATE_DB, $_SESSION['bd_name']);
  305. $res = $c->query ($sql);
  306. // on écrase la précédente connexion en sélectionnant la nouvelle BDD
  307. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_name'];
  308. } elseif($_SESSION['bd_type'] == 'sqlite') {
  309. $str = 'sqlite:' . DATA_PATH . $_SESSION['bd_name'] . '.sqlite';
  310. }
  311. $c = new PDO ($str,
  312. $_SESSION['bd_user'],
  313. $_SESSION['bd_pass'],
  314. $driver_options);
  315. $sql = sprintf (SQL_REQ_CAT, $_SESSION['bd_prefix']);
  316. $res = $c->query ($sql);
  317. if (!$res) {
  318. $error = true;
  319. }
  320. $sql = sprintf (SQL_REQ_FEED, $_SESSION['bd_prefix'], $_SESSION['bd_prefix']);
  321. $res = $c->query ($sql);
  322. if (!$res) {
  323. $error = true;
  324. }
  325. $sql = sprintf (SQL_REQ_ENTRY, $_SESSION['bd_prefix'], $_SESSION['bd_prefix']);
  326. $res = $c->query ($sql);
  327. if (!$res) {
  328. $error = true;
  329. }
  330. } catch (PDOException $e) {
  331. $error = true;
  332. }
  333. if ($error && file_exists (DATA_PATH . '/application.ini')) {
  334. unlink (DATA_PATH . '/application.ini');
  335. }
  336. return !$error;
  337. }
  338. /*** AFFICHAGE ***/
  339. function printStep0 () {
  340. global $actual;
  341. ?>
  342. <?php $s0 = checkStep0 (); if ($s0['all'] == 'ok') { ?>
  343. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('language_defined'); ?></p>
  344. <?php } ?>
  345. <form action="index.php?step=0" method="post">
  346. <legend><?php echo _t ('choose_language'); ?></legend>
  347. <div class="form-group">
  348. <label class="group-name" for="language"><?php echo _t ('language'); ?></label>
  349. <div class="group-controls">
  350. <select name="language" id="language">
  351. <?php $languages = availableLanguages (); ?>
  352. <?php foreach ($languages as $short => $lib) { ?>
  353. <option value="<?php echo $short; ?>"<?php echo $actual == $short ? ' selected="selected"' : ''; ?>><?php echo $lib; ?></option>
  354. <?php } ?>
  355. </select>
  356. </div>
  357. </div>
  358. <div class="form-group form-actions">
  359. <div class="group-controls">
  360. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  361. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  362. <?php if ($s0['all'] == 'ok') { ?>
  363. <a class="btn btn-important next-step" href="?step=1"><?php echo _t ('next_step'); ?></a>
  364. <?php } ?>
  365. </div>
  366. </div>
  367. </form>
  368. <?php
  369. }
  370. function printStep1 () {
  371. $res = checkStep1 ();
  372. ?>
  373. <noscript><p class="alert alert-warn"><span class="alert-head"><?php echo _t ('attention'); ?></span> <?php echo _t ('javascript_is_better'); ?></p></noscript>
  374. <?php if ($res['php'] == 'ok') { ?>
  375. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('php_is_ok', PHP_VERSION); ?></p>
  376. <?php } else { ?>
  377. <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>
  378. <?php } ?>
  379. <?php if ($res['minz'] == 'ok') { ?>
  380. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('minz_is_ok'); ?></p>
  381. <?php } else { ?>
  382. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('minz_is_nok', LIB_PATH . '/minz'); ?></p>
  383. <?php } ?>
  384. <?php if ($res['curl'] == 'ok') { ?>
  385. <?php $version = curl_version(); ?>
  386. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('curl_is_ok', $version['version']); ?></p>
  387. <?php } else { ?>
  388. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('curl_is_nok'); ?></p>
  389. <?php } ?>
  390. <?php if ($res['pdo-mysql'] == 'ok') { ?>
  391. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('pdomysql_is_ok'); ?></p>
  392. <?php } else { ?>
  393. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('pdomysql_is_nok'); ?></p>
  394. <?php } ?>
  395. <?php if ($res['dom'] == 'ok') { ?>
  396. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('dom_is_ok'); ?></p>
  397. <?php } else { ?>
  398. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('dom_is_nok'); ?></p>
  399. <?php } ?>
  400. <?php if ($res['data'] == 'ok') { ?>
  401. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('data_is_ok'); ?></p>
  402. <?php } else { ?>
  403. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', DATA_PATH); ?></p>
  404. <?php } ?>
  405. <?php if ($res['cache'] == 'ok') { ?>
  406. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('cache_is_ok'); ?></p>
  407. <?php } else { ?>
  408. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', CACHE_PATH); ?></p>
  409. <?php } ?>
  410. <?php if ($res['log'] == 'ok') { ?>
  411. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('log_is_ok'); ?></p>
  412. <?php } else { ?>
  413. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', LOG_PATH); ?></p>
  414. <?php } ?>
  415. <?php if ($res['favicons'] == 'ok') { ?>
  416. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('favicons_is_ok'); ?></p>
  417. <?php } else { ?>
  418. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', PUBLIC_PATH . '/favicons'); ?></p>
  419. <?php } ?>
  420. <?php if ($res['all'] == 'ok') { ?>
  421. <a class="btn btn-important next-step" href="?step=2"><?php echo _t ('next_step'); ?></a>
  422. <?php } else { ?>
  423. <p class="alert alert-error"><?php echo _t ('fix_errors_before'); ?></p>
  424. <?php } ?>
  425. <?php
  426. }
  427. function printStep2 () {
  428. ?>
  429. <?php $s2 = checkStep2 (); if ($s2['all'] == 'ok') { ?>
  430. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('general_conf_is_ok'); ?></p>
  431. <?php } ?>
  432. <form action="index.php?step=2" method="post">
  433. <legend><?php echo _t ('general_configuration'); ?></legend>
  434. <?php
  435. $url = substr ($_SERVER['PHP_SELF'], 0, -10);
  436. ?>
  437. <div class="form-group" style="display:none">
  438. <!-- TODO: if no problem during version 0.6, remove for version 0.7 -->
  439. <label class="group-name" for="base_url"><?php echo _t ('base_url'); ?></label>
  440. <div class="group-controls">
  441. <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'); ?>
  442. </div>
  443. </div>
  444. <div class="form-group">
  445. <label class="group-name" for="title"><?php echo _t ('title'); ?></label>
  446. <div class="group-controls">
  447. <input type="text" id="title" name="title" value="<?php echo isset ($_SESSION['title']) ? $_SESSION['title'] : _t ('freshrss'); ?>" />
  448. </div>
  449. </div>
  450. <div class="form-group">
  451. <label class="group-name" for="old_entries"><?php echo _t ('delete_articles_every'); ?></label>
  452. <div class="group-controls">
  453. <input type="number" id="old_entries" name="old_entries" value="<?php echo isset ($_SESSION['old_entries']) ? $_SESSION['old_entries'] : '3'; ?>" /> <?php echo _t ('month'); ?>
  454. </div>
  455. </div>
  456. <div class="form-group">
  457. <label class="group-name" for="default_user"><?php echo _t ('default_user'); ?></label>
  458. <div class="group-controls">
  459. <input type="text" id="default_user" name="default_user" maxlength="16" value="<?php echo isset ($_SESSION['default_user']) ? $_SESSION['default_user'] : ''; ?>" placeholder="user1" />
  460. </div>
  461. </div>
  462. <div class="form-group">
  463. <label class="group-name" for="mail_login"><?php echo _t ('persona_connection_email'); ?></label>
  464. <div class="group-controls">
  465. <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'); ?>" />
  466. <noscript><b><?php echo _t ('javascript_should_be_activated'); ?></b></noscript>
  467. </div>
  468. </div>
  469. <div class="form-group form-actions">
  470. <div class="group-controls">
  471. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  472. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  473. <?php if ($s2['all'] == 'ok') { ?>
  474. <a class="btn btn-important next-step" href="?step=3"><?php echo _t ('next_step'); ?></a>
  475. <?php } ?>
  476. </div>
  477. </div>
  478. </form>
  479. <?php
  480. }
  481. function printStep3 () {
  482. ?>
  483. <?php $s3 = checkStep3 (); if ($s3['all'] == 'ok') { ?>
  484. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('bdd_conf_is_ok'); ?></p>
  485. <?php } elseif ($s3['conn'] == 'ko') { ?>
  486. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('bdd_conf_is_ko'); ?></p>
  487. <?php } ?>
  488. <form action="index.php?step=3" method="post">
  489. <legend><?php echo _t ('bdd_configuration'); ?></legend>
  490. <!--
  491. TODO : l'utilisation de SQLite n'est pas encore possible. Pour tester tout de même, décommentez ce bloc
  492. <div class="form-group">
  493. <label class="group-name" for="type"><?php echo _t ('bdd_type'); ?></label>
  494. <div class="group-controls">
  495. <select name="type" id="type">
  496. <option value="mysql"
  497. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql') ? 'selected="selected"' : ''; ?>>
  498. MySQL
  499. </option>
  500. <option value="sqlite"
  501. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'sqlite') ? 'selected="selected"' : ''; ?>>
  502. SQLite
  503. </option>
  504. </select>
  505. </div>
  506. </div>
  507. -->
  508. <div class="form-group">
  509. <label class="group-name" for="host"><?php echo _t ('host'); ?></label>
  510. <div class="group-controls">
  511. <input type="text" id="host" name="host" value="<?php echo isset ($_SESSION['bd_host']) ? $_SESSION['bd_host'] : 'localhost'; ?>" />
  512. </div>
  513. </div>
  514. <div class="form-group">
  515. <label class="group-name" for="user"><?php echo _t ('username'); ?></label>
  516. <div class="group-controls">
  517. <input type="text" id="user" name="user" value="<?php echo isset ($_SESSION['bd_user']) ? $_SESSION['bd_user'] : ''; ?>" />
  518. </div>
  519. </div>
  520. <div class="form-group">
  521. <label class="group-name" for="pass"><?php echo _t ('password'); ?></label>
  522. <div class="group-controls">
  523. <input type="password" id="pass" name="pass" value="<?php echo isset ($_SESSION['bd_pass']) ? $_SESSION['bd_pass'] : ''; ?>" />
  524. </div>
  525. </div>
  526. <div class="form-group">
  527. <label class="group-name" for="base"><?php echo _t ('bdd'); ?></label>
  528. <div class="group-controls">
  529. <input type="text" id="base" name="base" maxlength="64" value="<?php echo isset ($_SESSION['bd_name']) ? $_SESSION['bd_name'] : ''; ?>" />
  530. </div>
  531. </div>
  532. <div class="form-group">
  533. <label class="group-name" for="prefix"><?php echo _t ('prefix'); ?></label>
  534. <div class="group-controls">
  535. <input type="text" id="prefix" name="prefix" maxlength="16" value="<?php echo isset ($_SESSION['bd_prefix']) ? $_SESSION['bd_prefix'] : 'freshrss_'; ?>" />
  536. </div>
  537. </div>
  538. <div class="form-group form-actions">
  539. <div class="group-controls">
  540. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  541. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  542. <?php if ($s3['all'] == 'ok') { ?>
  543. <a class="btn btn-important next-step" href="?step=4"><?php echo _t ('next_step'); ?></a>
  544. <?php } ?>
  545. </div>
  546. </div>
  547. </form>
  548. <?php
  549. }
  550. function printStep4 () {
  551. ?>
  552. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('congratulations'); ?></span> <?php echo _t ('installation_is_ok'); ?></p>
  553. <a class="btn btn-important next-step" href="?step=5"><?php echo _t ('finish_installation'); ?></a>
  554. <?php
  555. }
  556. function printStep5 () {
  557. ?>
  558. <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>
  559. <?php
  560. }
  561. initTranslate ();
  562. checkStep ();
  563. switch (STEP) {
  564. case 0:
  565. default:
  566. saveLanguage ();
  567. break;
  568. case 1:
  569. break;
  570. case 2:
  571. saveStep2 ();
  572. break;
  573. case 3:
  574. saveStep3 ();
  575. break;
  576. case 4:
  577. break;
  578. case 5:
  579. deleteInstall ();
  580. break;
  581. }
  582. ?>
  583. <!DOCTYPE html>
  584. <html lang="fr">
  585. <head>
  586. <meta charset="utf-8">
  587. <meta name="viewport" content="initial-scale=1.0">
  588. <title><?php echo _t ('freshrss_installation'); ?></title>
  589. <link rel="stylesheet" type="text/css" media="all" href="themes/default/global.css" />
  590. <link rel="stylesheet" type="text/css" media="all" href="themes/default/freshrss.css" />
  591. </head>
  592. <body>
  593. <div class="header">
  594. <div class="item title">
  595. <h1><a href="index.php"><?php echo _t ('freshrss'); ?></a></h1>
  596. <h2><?php echo _t ('installation_step', STEP); ?></h2>
  597. </div>
  598. </div>
  599. <div id="global">
  600. <ul class="nav nav-list aside">
  601. <li class="nav-header"><?php echo _t ('steps'); ?></li>
  602. <li class="item<?php echo STEP == 0 ? ' active' : ''; ?>"><a href="?step=0"><?php echo _t ('language'); ?></a></li>
  603. <li class="item<?php echo STEP == 1 ? ' active' : ''; ?>"><a href="?step=1"><?php echo _t ('checks'); ?></a></li>
  604. <li class="item<?php echo STEP == 2 ? ' active' : ''; ?>"><a href="?step=2"><?php echo _t ('general_configuration'); ?></a></li>
  605. <li class="item<?php echo STEP == 3 ? ' active' : ''; ?>"><a href="?step=3"><?php echo _t ('bdd_configuration'); ?></a></li>
  606. <li class="item<?php echo STEP == 4 ? ' active' : ''; ?>"><a href="?step=4"><?php echo _t ('this_is_the_end'); ?></a></li>
  607. </ul>
  608. <div class="post">
  609. <?php
  610. switch (STEP) {
  611. case 0:
  612. default:
  613. printStep0 ();
  614. break;
  615. case 1:
  616. printStep1 ();
  617. break;
  618. case 2:
  619. printStep2 ();
  620. break;
  621. case 3:
  622. printStep3 ();
  623. break;
  624. case 4:
  625. printStep4 ();
  626. break;
  627. case 5:
  628. printStep5 ();
  629. break;
  630. }
  631. ?>
  632. </div>
  633. </div>
  634. </body>
  635. </html>